Browse Source

remove handler.editor.property

Tienson Qin 2 years ago
parent
commit
3ec4c6bedd

+ 84 - 82
src/main/frontend/components/content.cljs

@@ -11,7 +11,6 @@
             [frontend.extensions.srs :as srs]
             [frontend.handler.common :as common-handler]
             [frontend.handler.editor :as editor-handler]
-            [frontend.handler.editor.property :as editor-property]
             [frontend.handler.image :as image-handler]
             [frontend.handler.notification :as notification]
             [frontend.handler.page :as page-handler]
@@ -33,85 +32,86 @@
 
 (rum/defc custom-context-menu-content
   []
-  [:.menu-links-wrapper
-   (ui/menu-background-color #(editor-property/batch-add-block-property! (state/get-selection-block-ids) :background-color %)
-                             #(editor-property/batch-remove-block-property! (state/get-selection-block-ids) :background-color))
-
-   (ui/menu-heading #(editor-handler/batch-set-heading! (state/get-selection-block-ids) %)
-                    #(editor-handler/batch-set-heading! (state/get-selection-block-ids) true)
-                    #(editor-handler/batch-remove-heading! (state/get-selection-block-ids)))
-
-   [:hr.menu-separator]
-
-   (ui/menu-link
-    {:key "cut"
-     :on-click #(editor-handler/cut-selection-blocks true)}
-    (t :editor/cut)
-    (ui/keyboard-shortcut-from-config :editor/cut))
-   (ui/menu-link
-    {:key "delete"
-     :on-click #(do (editor-handler/delete-selection %)
-                    (state/hide-custom-context-menu!))}
-    (t :editor/delete-selection)
-    (ui/keyboard-shortcut-from-config :editor/delete))
-   (ui/menu-link
-    {:key "copy"
-     :on-click editor-handler/copy-selection-blocks}
-    (t :editor/copy)
-    (ui/keyboard-shortcut-from-config :editor/copy))
-   (ui/menu-link
-    {:key "copy as"
-     :on-click (fn [_]
-                 (let [block-uuids (editor-handler/get-selected-toplevel-block-uuids)]
-                   (state/set-modal!
-                    #(export/export-blocks block-uuids {:whiteboard? false}))))}
-    (t :content/copy-export-as)
-    nil)
-   (ui/menu-link
-    {:key "copy block refs"
-     :on-click editor-handler/copy-block-refs}
-    (t :content/copy-block-ref)
-    nil)
-   (ui/menu-link
-    {:key "copy block embeds"
-     :on-click editor-handler/copy-block-embeds}
-    (t :content/copy-block-emebed)
-    nil)
-
-   [:hr.menu-separator]
-
-   (when (state/enable-flashcards?)
+  (let [repo (state/get-current-repo)]
+    [:.menu-links-wrapper
+     (ui/menu-background-color #(property-handler/batch-add-block-property! repo (state/get-selection-block-ids) :background-color %)
+                               #(property-handler/batch-remove-block-property! repo (state/get-selection-block-ids) :background-color))
+
+     (ui/menu-heading #(editor-handler/batch-set-heading! (state/get-selection-block-ids) %)
+                      #(editor-handler/batch-set-heading! (state/get-selection-block-ids) true)
+                      #(editor-handler/batch-remove-heading! (state/get-selection-block-ids)))
+
+     [:hr.menu-separator]
+
      (ui/menu-link
-      {:key "Make a Card"
-       :on-click #(srs/batch-make-cards!)}
-      (t :context-menu/make-a-flashcard)
-      nil))
-
-   (ui/menu-link
-     {:key "Toggle number list"
-      :on-click #(state/pub-event! [:editor/toggle-own-number-list (state/get-selection-block-ids)])}
-     (t :context-menu/toggle-number-list)
-     nil)
+      {:key "cut"
+       :on-click #(editor-handler/cut-selection-blocks true)}
+      (t :editor/cut)
+      (ui/keyboard-shortcut-from-config :editor/cut))
+     (ui/menu-link
+      {:key "delete"
+       :on-click #(do (editor-handler/delete-selection %)
+                      (state/hide-custom-context-menu!))}
+      (t :editor/delete-selection)
+      (ui/keyboard-shortcut-from-config :editor/delete))
+     (ui/menu-link
+      {:key "copy"
+       :on-click editor-handler/copy-selection-blocks}
+      (t :editor/copy)
+      (ui/keyboard-shortcut-from-config :editor/copy))
+     (ui/menu-link
+      {:key "copy as"
+       :on-click (fn [_]
+                   (let [block-uuids (editor-handler/get-selected-toplevel-block-uuids)]
+                     (state/set-modal!
+                      #(export/export-blocks block-uuids {:whiteboard? false}))))}
+      (t :content/copy-export-as)
+      nil)
+     (ui/menu-link
+      {:key "copy block refs"
+       :on-click editor-handler/copy-block-refs}
+      (t :content/copy-block-ref)
+      nil)
+     (ui/menu-link
+      {:key "copy block embeds"
+       :on-click editor-handler/copy-block-embeds}
+      (t :content/copy-block-emebed)
+      nil)
+
+     [:hr.menu-separator]
+
+     (when (state/enable-flashcards?)
+       (ui/menu-link
+        {:key "Make a Card"
+         :on-click #(srs/batch-make-cards!)}
+        (t :context-menu/make-a-flashcard)
+        nil))
 
-   (ui/menu-link
-    {:key "cycle todos"
-     :on-click editor-handler/cycle-todos!}
-    (t :editor/cycle-todo)
-    (ui/keyboard-shortcut-from-config :editor/cycle-todo))
+     (ui/menu-link
+      {:key "Toggle number list"
+       :on-click #(state/pub-event! [:editor/toggle-own-number-list (state/get-selection-block-ids)])}
+      (t :context-menu/toggle-number-list)
+      nil)
+
+     (ui/menu-link
+      {:key "cycle todos"
+       :on-click editor-handler/cycle-todos!}
+      (t :editor/cycle-todo)
+      (ui/keyboard-shortcut-from-config :editor/cycle-todo))
 
-   [:hr.menu-separator]
+     [:hr.menu-separator]
 
-   (ui/menu-link
-    {:key "Expand all"
-     :on-click editor-handler/expand-all-selection!}
-    (t :editor/expand-block-children)
-    (ui/keyboard-shortcut-from-config :editor/expand-block-children))
+     (ui/menu-link
+      {:key "Expand all"
+       :on-click editor-handler/expand-all-selection!}
+      (t :editor/expand-block-children)
+      (ui/keyboard-shortcut-from-config :editor/expand-block-children))
 
-   (ui/menu-link
-    {:key "Collapse all"
-     :on-click editor-handler/collapse-all-selection!}
-    (t :editor/collapse-block-children)
-    (ui/keyboard-shortcut-from-config :editor/collapse-block-children))])
+     (ui/menu-link
+      {:key "Collapse all"
+       :on-click editor-handler/collapse-all-selection!}
+      (t :editor/collapse-block-children)
+      (ui/keyboard-shortcut-from-config :editor/collapse-block-children))]))
 
 (defonce *template-including-parent? (atom nil))
 
@@ -135,7 +135,8 @@
         template-including-parent? (rum/react *template-including-parent?)
         block-id (if (string? block-id) (uuid block-id) block-id)
         block (db/entity [:block/uuid block-id])
-        has-children? (seq (:block/_parent block))]
+        has-children? (seq (:block/_parent block))
+        repo (state/get-current-repo)]
     (when (and (nil? template-including-parent?) has-children?)
       (reset! *template-including-parent? true))
 
@@ -160,9 +161,9 @@
                                         [:p (t :context-menu/template-exists-warning)]
                                         :error)
                                        (do
-                                         (editor-property/set-block-property! block-id :template title)
+                                         (property-handler/set-block-property! repo block-id :template title)
                                          (when (false? template-including-parent?)
-                                           (editor-property/set-block-property! block-id :template-including-parent false))
+                                           (property-handler/set-block-property! repo block-id :template-including-parent false))
                                          (state/hide-custom-context-menu!)))))))]
          [:hr.menu-separator]])
       (ui/menu-link
@@ -177,10 +178,11 @@
   shortcut/disable-all-shortcuts
   [_target block-id]
     (when-let [block (db/entity [:block/uuid block-id])]
-      (let [heading (-> block :block/properties :heading (or false))]
+      (let [heading (-> block :block/properties :heading (or false))
+            repo (state/get-current-repo)]
         [:.menu-links-wrapper
-         (ui/menu-background-color #(editor-property/set-block-property! block-id :background-color %)
-                                   #(editor-property/remove-block-property! block-id :background-color))
+         (ui/menu-background-color #(property-handler/set-block-property! repo block-id :background-color %)
+                                   #(property-handler/remove-block-property! repo block-id :background-color))
 
          (ui/menu-heading heading
                           #(editor-handler/set-heading! block-id %)
@@ -373,7 +375,7 @@
                   (let [class? (= "class" (:block/type block))
                         f (if (and class? class-schema?)
                             property-handler/class-remove-property!
-                            property-handler/remove-property!)]
+                            property-handler/remove-block-property!)]
                     (f repo block (:block/uuid property))))}
      (t :context-menu/delete-property)
      nil)]))

+ 7 - 7
src/main/frontend/components/property.cljs

@@ -110,7 +110,7 @@
      (when property-key
        (if (and class? class-schema?)
          (property-handler/class-add-property! repo block property-key)
-         (property-handler/add-property! repo block property-key property-value)))
+         (property-handler/set-block-property! repo (:block/uuid block) property-key property-value)))
      (when exit-edit?
        (exit-edit-property)))))
 
@@ -125,7 +125,7 @@
                       (state/set-modal!
                        #(ui/datepicker value' {:on-change (fn [_e date]
                                                             (let [repo (state/get-current-repo)]
-                                                              (property-handler/add-property! repo block
+                                                              (property-handler/set-block-property! repo (:block/uuid block)
                                                                                               (:block/name property)
                                                                                               date)
                                                               (exit-edit-property)
@@ -280,10 +280,10 @@
                                (when (and (contains? #{"Enter" "Escape"} (util/ekey e))
                                           (not (state/get-editor-action)))
                                  (util/stop e)
-                                 (property-handler/add-property! repo block
-                                                                 (:block/original-name property)
-                                                                 (util/evalue e)
-                                                                 :old-value value)
+                                 (property-handler/set-block-property! repo (:block/uuid block)
+                                                                       (:block/original-name property)
+                                                                       (util/evalue e)
+                                                                       :old-value value)
                                  (exit-edit-property)
 
                                  (when (and enter? multiple-values?)
@@ -324,7 +324,7 @@
                                      :editor-box editor-box})]
                  (if multiple-values?
                    (property-handler/delete-property-value! repo block (:block/uuid property) value)
-                   (property-handler/remove-property! repo block (:block/uuid property))))
+                   (property-handler/remove-block-property! repo (:block/uuid block) (:block/uuid property))))
 
                (inline-text {} :markdown (str value)))))])))))
 

+ 3 - 3
src/main/frontend/components/query.cljs

@@ -13,7 +13,7 @@
             [lambdaisland.glogi :as log]
             [frontend.extensions.sci :as sci]
             [frontend.handler.editor :as editor-handler]
-            [frontend.handler.editor.property :as editor-property]
+            [frontend.handler.property :as property-handler]
             [logseq.graph-parser.util :as gp-util]))
 
 (defn built-in-custom-query?
@@ -207,12 +207,12 @@
                (when (and current-block (not view-f) (nil? table-view?) (not page-list?))
                  (if table?
                    [:a.flex.ml-1.fade-link {:title "Switch to list view"
-                                            :on-click (fn [] (editor-property/set-block-property! current-block-uuid
+                                            :on-click (fn [] (property-handler/set-block-property! (state/get-current-repo) current-block-uuid
                                                                                                   "query-table"
                                                                                                   false))}
                     (ui/icon "list" {:style {:font-size 20}})]
                    [:a.flex.ml-1.fade-link {:title "Switch to table view"
-                                            :on-click (fn [] (editor-property/set-block-property! current-block-uuid
+                                            :on-click (fn [] (property-handler/set-block-property! (state/get-current-repo) current-block-uuid
                                                                                                   "query-table"
                                                                                                   true))}
                     (ui/icon "table" {:style {:font-size 20}})]))

+ 12 - 11
src/main/frontend/components/query_table.cljs

@@ -7,7 +7,7 @@
             [frontend.db.utils :as db-utils]
             [frontend.format.block :as block]
             [frontend.handler.common :as common-handler]
-            [frontend.handler.editor.property :as editor-property]
+            [frontend.handler.property :as property-handler]
             [frontend.shui :refer [get-shui-component-version make-shui-context]]
             [frontend.state :as state]
             [frontend.util :as util]
@@ -82,15 +82,16 @@
 ;; ==========
 (rum/defc sortable-title
   [title column {:keys [sort-by-column sort-desc?]} block-id]
-  [:th.whitespace-nowrap
-   [:a {:on-click (fn []
-                    (editor-property/set-block-property! block-id :query-sort-by (name column))
-                    (editor-property/set-block-property! block-id :query-sort-desc (not sort-desc?)))}
-    [:div.flex.items-center
-     [:span.mr-1 title]
-     (when (= sort-by-column column)
-       [:span
-        (if sort-desc? (svg/caret-down) (svg/caret-up))])]]])
+  (let [repo (state/get-current-repo)]
+    [:th.whitespace-nowrap
+     [:a {:on-click (fn []
+                      (property-handler/set-block-property! repo block-id :query-sort-by (name column))
+                      (property-handler/set-block-property! repo block-id :query-sort-desc (not sort-desc?)))}
+      [:div.flex.items-center
+       [:span.mr-1 title]
+       (when (= sort-by-column column)
+         [:span
+          (if sort-desc? (svg/caret-down) (svg/caret-up))])]]]))
 
 (defn get-keys
   "Get keys for a query table result, which are the columns in a table"
@@ -279,4 +280,4 @@
                                    (build-column-text row column)))]
             (shui/table-v2 {:data (conj [[columns]] result-as-text)}
                            (make-shui-context config inline)))
-        1 (result-table-v1 config current-block sort-result sort-state columns options map-inline page-cp ->elem inline-text)))))
+        1 (result-table-v1 config current-block sort-result sort-state columns options map-inline page-cp ->elem inline-text)))))

+ 2 - 2
src/main/frontend/extensions/pdf/assets.cljs

@@ -6,7 +6,7 @@
             [frontend.db.utils :as db-utils]
             [frontend.fs :as fs]
             [frontend.handler.editor :as editor-handler]
-            [frontend.handler.editor.property :as editor-property]
+            [frontend.handler.property :as property-handler]
             [frontend.handler.page :as page-handler]
             [frontend.handler.assets :as assets-handler]
             [frontend.handler.notification :as notification]
@@ -133,7 +133,7 @@
                                (get-in highlight [:content :image])
                                (js/Date.now))
                    :hl-color (get-in highlight [:properties :color])}]
-      (editor-property/set-block-property! (:block/uuid block) k v))))
+      (property-handler/set-block-property! (state/get-current-repo) (:block/uuid block) k v))))
 
 (defn unlink-hl-area-image$
   [^js _viewer current hl]

+ 2 - 2
src/main/frontend/extensions/srs.cljs

@@ -13,7 +13,7 @@
             [frontend.db-mixins :as db-mixins]
             [frontend.state :as state]
             [frontend.handler.editor :as editor-handler]
-            [frontend.handler.editor.property :as editor-property]
+            [frontend.handler.property :as property-handler]
             [frontend.components.block :as component-block]
             [frontend.components.macro :as component-macro]
             [frontend.components.select :as component-select]
@@ -486,7 +486,7 @@
                                    :on-click   (fn []
                                                  (score-and-next-card 1 card card-index finished? phase review-records cb)
                                                  (let [tomorrow (tc/to-string (t/plus (t/today) (t/days 1)))]
-                                                   (editor-property/set-block-property! root-block-id card-next-schedule-property tomorrow)))})
+                                                   (property-handler/set-block-property! (state/get-current-repo) root-block-id card-next-schedule-property tomorrow)))})
 
                (btn-with-shortcut {:btn-text (if (util/mobile?) "Hard" (t :flashcards/modal-btn-recall))
                                    :shortcut "t"

+ 2 - 2
src/main/frontend/fs/watcher_handler.cljs

@@ -7,7 +7,7 @@
             [frontend.db.model :as model]
             [frontend.fs :as fs]
             [logseq.common.path :as path]
-            [frontend.handler.editor.property :as editor-property]
+            [frontend.handler.property :as property-handler]
             [frontend.handler.file :as file-handler]
             [frontend.handler.page :as page-handler]
             [frontend.handler.ui :as ui-handler]
@@ -33,7 +33,7 @@
                            nil))]
         (let [id-property (:id (:block/properties block))]
           (when-not (= (str id-property) (str block-id))
-            (editor-property/set-block-property! block-id "id" block-id)))))))
+            (property-handler/file-persist-block-id! (state/get-current-repo) block-id)))))))
 
 (defn- handle-add-and-change!
   [repo path content db-content mtime backup?]

+ 71 - 1
src/main/frontend/handler/block.cljs

@@ -11,7 +11,12 @@
    [frontend.state :as state]
    [frontend.util :as util]
    [goog.dom :as gdom]
-   [logseq.graph-parser.block :as gp-block]))
+   [goog.object :as gobj]
+   [logseq.graph-parser.block :as gp-block]
+   [frontend.config :as config]
+   [frontend.db.listener :as db-listener]
+   [frontend.util.drawer :as drawer]
+   [frontend.handler.file-based.property.util :as property-util]))
 
 ;;  Fns
 
@@ -295,3 +300,68 @@
     (assoc config :own-order-list-type own-order-list-type
                   :own-order-list-index own-order-list-index
                   :own-order-number-list? (= own-order-list-type "number"))))
+
+(defn- get-edit-input-id-with-block-id
+  [block-id]
+  (when-let [first-block (util/get-first-block-by-id block-id)]
+    (string/replace (gobj/get first-block "id")
+                    "ls-block"
+                    "edit-block")))
+
+(defn- text-range-by-lst-fst-line [content [direction pos]]
+  (case direction
+    :up
+    (let [last-new-line (or (string/last-index-of content \newline) -1)
+          end (+ last-new-line pos 1)]
+      (subs content 0 end))
+    :down
+    (-> (string/split-lines content)
+        first
+        (or "")
+        (subs 0 pos))))
+
+(defn mark-last-input-time!
+  [repo]
+  (when repo
+    (state/set-editor-last-input-time! repo (util/time-ms))
+    (db-listener/clear-repo-persistent-job! repo)))
+
+(defn edit-block!
+  ([block pos id]
+   (edit-block! block pos id nil))
+  ([block pos id {:keys [custom-content tail-len retry-times]
+                  :or {tail-len 0
+                       retry-times 0}
+                  :as opts}]
+   (when-not (> retry-times 2)
+     (when-not config/publishing?
+       (when-let [block-id (:block/uuid block)]
+         (let [repo (state/get-current-repo)
+               block (or (db/pull [:block/uuid block-id]) block)
+               edit-input-id (if (uuid? id)
+                               (get-edit-input-id-with-block-id id)
+                               (-> (str (subs id 0 (- (count id) 36)) block-id)
+                                   (string/replace "ls-block" "edit-block")))
+               content (or custom-content (:block/content block) "")
+               content-length (count content)
+               text-range (cond
+                            (vector? pos)
+                            (text-range-by-lst-fst-line content pos)
+
+                            (and (> tail-len 0) (>= (count content) tail-len))
+                            (subs content 0 (- (count content) tail-len))
+
+                            (or (= :max pos) (<= content-length pos))
+                            content
+
+                            :else
+                            (subs content 0 pos))
+               content (-> (property-util/remove-built-in-properties (:block/format block) content)
+                           (drawer/remove-logbook))]
+           (state/clear-selection!)
+           (if edit-input-id
+             (do
+               (state/set-editing! edit-input-id content block text-range)
+               (mark-last-input-time! (state/get-current-repo)))
+             ;; Block may not be rendered yet
+             (js/setTimeout (fn [] (edit-block! block pos id (update opts :retry-times inc))) 10))))))))

+ 61 - 18
src/main/frontend/handler/db_based/property.cljs

@@ -126,9 +126,10 @@
                             :block/type "property"})]
         {:outliner-op :create-new-property}))))
 
-(defn add-property!
-  [repo block k-name v {:keys [old-value]}]
-  (let [k-name (name k-name)
+(defn set-block-property!
+  [repo block-id k-name v {:keys [old-value]}]
+  (let [block (db/entity repo [:block/uuid block-id])
+        k-name (name k-name)
         property (db/pull repo '[*] [:block/name (gp-util/page-name-sanity-lc k-name)])
         v (if property v (or v ""))]
     (when (some? v)
@@ -180,21 +181,6 @@
                     :block/refs refs}]
                   {:outliner-op :add-property})))))))))
 
-(defn remove-property!
-  [repo block property-uuid]
-  {:pre (string? property-uuid)}
-  (let [origin-properties (:block/properties block)]
-    (when (contains? (set (keys origin-properties)) property-uuid)
-      (let [properties' (dissoc origin-properties property-uuid)
-            refs (outliner-core/rebuild-block-refs block properties')]
-        (db/transact!
-         repo
-          [[:db/retract (:db/id block) :block/refs]
-           {:block/uuid (:block/uuid block)
-            :block/properties properties'
-            :block/refs refs}]
-          {:outliner-op :remove-property})))))
-
 (defn- fix-cardinality-many-values!
   [repo property-uuid]
   (let [ev (->> (model/get-block-property-values property-uuid)
@@ -273,3 +259,60 @@
         (db/transact! repo [{:db/id (:db/id class)
                              :block/schema class-new-schema}]
           {:outliner-op :class-remove-property})))))
+
+(defn batch-add-property!
+  "Notice that this works only for properties with cardinality equals to `one`."
+  [repo block-ids k-name v]
+  (let [k-name (name k-name)
+        property (db/entity repo '[*] [:block/name (gp-util/page-name-sanity-lc k-name)])
+        property-uuid (or (:block/uuid property) (random-uuid))
+        type (:type (:block/schema property))
+        infer-schema (when-not type (infer-schema-from-input-string v))
+        property-type (or type infer-schema :default)
+        _ (when (nil? property)
+            (upsert-property! repo property k-name property-uuid property-type))
+        {:keys [type cardinality]} (:block/schema property)
+        property (db/entity repo '[*] [:block/name (gp-util/page-name-sanity-lc k-name)])
+        txs (mapcat
+             (fn [id]
+               (when-let [block (db/entity [:block/uuid id])]
+                 (when (and (some? v) (not= cardinality :many))
+                   (let [schema (get builtin-schema-types property-type)
+                         v* (try
+                              (convert-property-input-string property-type v)
+                              (catch :default e
+                                (notification/show! (str e) :error false)
+                                nil))
+                         properties (:block/properties block)
+                         block-properties (assoc properties property-uuid v*)
+                         refs (outliner-core/rebuild-block-refs block block-properties)]
+                     [[:db/retract (:db/id block) :block/refs]
+                      {:block/uuid (:block/uuid block)
+                       :block/properties block-properties
+                       :block/refs refs}]))))
+             block-ids)]
+    (when (seq txs)
+      (db/transact! repo txs {:outliner-op :batch-add-property}))))
+
+(defn batch-remove-property!
+  [repo block-ids property-uuid]
+  {:pre (string? property-uuid)}
+  (let [txs (mapcat
+             (fn [id]
+               (when-let [block (db/entity [:block/uuid id])]
+                 (let [origin-properties (:block/properties block)]
+                   (when (contains? (set (keys origin-properties)) property-uuid)
+                     (let [properties' (dissoc origin-properties property-uuid)
+                           refs (outliner-core/rebuild-block-refs block properties')]
+                       [[:db/retract (:db/id block) :block/refs]
+                        {:block/uuid (:block/uuid block)
+                         :block/properties properties'
+                         :block/refs refs}])))))
+             block-ids)]
+    (when (seq txs)
+      (db/transact! repo txs {:outliner-op :remove-property}))))
+
+(defn remove-block-property!
+  [repo block-id property-uuid]
+  {:pre (string? property-uuid)}
+  (batch-remove-property! repo [block-id] property-uuid))

+ 2 - 4
src/main/frontend/handler/dnd.cljs

@@ -1,7 +1,7 @@
 (ns frontend.handler.dnd
   "Provides fns for drag n drop"
   (:require [frontend.handler.editor :as editor-handler]
-            [frontend.handler.editor.property :as editor-property]
+            [frontend.handler.property :as property-handler]
             [frontend.modules.outliner.core :as outliner-core]
             [frontend.modules.outliner.tree :as tree]
             [frontend.modules.outliner.transaction :as outliner-tx]
@@ -22,9 +22,7 @@
       ;; alt pressed, make a block-ref
       (and alt-key? (= (count blocks) 1))
       (do
-        (editor-property/set-block-property! (:block/uuid first-block)
-                                            :id
-                                            (str (:block/uuid first-block)))
+        (property-handler/file-persist-block-id! (state/get-current-repo) (:block/uuid first-block))
         (editor-handler/api-insert-new-block!
          (block-ref/->block-ref (:block/uuid first-block))
          {:block-uuid (:block/uuid target-block)

+ 26 - 25
src/main/frontend/handler/editor.cljs

@@ -19,7 +19,7 @@
             [frontend.handler.assets :as assets-handler]
             [frontend.handler.block :as block-handler]
             [frontend.handler.common :as common-handler]
-            [frontend.handler.editor.property :as editor-property]
+            [frontend.handler.property :as property-handler]
             [frontend.handler.export.html :as export-html]
             [frontend.handler.export.text :as export-text]
             [frontend.handler.notification :as notification]
@@ -65,8 +65,8 @@
 (defonce *asset-uploading? (atom false))
 (defonce *asset-uploading-process (atom 0))
 
-(def clear-selection! editor-property/clear-selection!)
-(def edit-block! editor-property/edit-block!)
+(def clear-selection! state/clear-selection!)
+(def edit-block! block-handler/edit-block!)
 
 (defn get-block-own-order-list-type
   [block]
@@ -75,12 +75,12 @@
 (defn set-block-own-order-list-type!
   [block type]
   (when-let [uuid (:block/uuid block)]
-    (editor-property/set-block-property! uuid :logseq.order-list-type (name type))))
+    (property-handler/set-block-property! (state/get-current-repo) uuid :logseq.order-list-type (name type))))
 
 (defn remove-block-own-order-list-type!
   [block]
   (when-let [uuid (:block/uuid block)]
-    (editor-property/remove-block-property! uuid :logseq.order-list-type)))
+    (property-handler/remove-block-property! (state/get-current-repo) uuid :logseq.order-list-type)))
 
 (defn own-order-number-list?
   [block]
@@ -95,10 +95,11 @@
   (when (seq blocks)
     (let [has-ordered?    (some own-order-number-list? blocks)
           blocks-uuids    (some->> blocks (map :block/uuid) (remove nil?))
-          order-list-prop :logseq.order-list-type]
+          order-list-prop :logseq.order-list-type
+          repo (state/get-current-repo)]
       (if has-ordered?
-        (editor-property/batch-remove-block-property! blocks-uuids order-list-prop)
-        (editor-property/batch-add-block-property! blocks-uuids order-list-prop "number")))))
+        (property-handler/batch-remove-block-property! repo blocks-uuids order-list-prop)
+        (property-handler/batch-add-block-property! repo blocks-uuids order-list-prop "number")))))
 
 (defn get-selection-and-format
   []
@@ -804,10 +805,11 @@
           query-properties (if add?
                              (distinct (conj query-properties key))
                              (remove #{key} query-properties))
-          query-properties (vec query-properties)]
+          query-properties (vec query-properties)
+          repo (state/get-current-repo)]
       (if (seq query-properties)
-        (editor-property/set-block-property! block-id :query-properties (str query-properties))
-        (editor-property/remove-block-property! block-id :query-properties)))))
+        (property-handler/set-block-property! repo block-id :query-properties (str query-properties))
+        (property-handler/remove-block-property! repo block-id :query-properties)))))
 
 (defn set-block-timestamp!
   [block-id key value]
@@ -844,15 +846,16 @@
   "Persist block uuid to file if the uuid is valid, and it's not persisted in file.
    Accepts a list of uuids."
   [block-ids]
-  (when-not (config/db-based-graph? (state/get-current-repo))
-    (let [block-ids (remove nil? block-ids)
-          col (map (fn [block-id]
-                     (when-let [block (db/entity [:block/uuid block-id])]
-                       (when-not (:block/pre-block? block)
-                         [block-id :id (str block-id)])))
-                block-ids)
-          col (remove nil? col)]
-      (editor-property/batch-set-block-property! col))))
+  (let [repo (state/get-current-repo)]
+    (when-not (config/db-based-graph? repo)
+      (let [block-ids (remove nil? block-ids)
+            col (map (fn [block-id]
+                       (when-let [block (db/entity [:block/uuid block-id])]
+                         (when-not (:block/pre-block? block)
+                           [block-id :id (str block-id)])))
+                  block-ids)
+            col (remove nil? col)]
+        (property-handler/file-batch-set-property! repo col)))))
 
 (defn copy-block-ref!
   ([block-id]
@@ -1751,7 +1754,7 @@
     (state/set-edit-content! id value false)
     (when @*auto-save-timeout
       (js/clearTimeout @*auto-save-timeout))
-    (editor-property/mark-last-input-time! repo)
+    (block-handler/mark-last-input-time! repo)
     (reset! *auto-save-timeout
             (js/setTimeout
              (fn []
@@ -1858,9 +1861,7 @@
                         :command :block-ref})
 
       ;; Save it so it'll be parsed correctly in the future
-      (editor-property/set-block-property! (:block/uuid chosen)
-                                           :id
-                                           uuid-string)
+      (property-handler/file-persist-block-id! (state/get-current-repo) (:block/uuid chosen))
 
       (when-let [input (gdom/getElement id)]
         (.focus input)))))
@@ -2623,7 +2624,7 @@
         top-block? (= (:block/left block) (:block/page block))
         single-block? (inside-of-single-block (.-target e))
         root-block? (= (:block.temp/container block) (str (:block/uuid block)))]
-    (editor-property/mark-last-input-time! repo)
+    (block-handler/mark-last-input-time! repo)
     (cond
       (not= selected-start selected-end)
       (do

+ 2 - 2
src/main/frontend/handler/editor/lifecycle.cljs

@@ -53,8 +53,8 @@
               property (:block/name block)
               old-value (:property-value (last (state/get-editor-args)))]
           (when (and parent-block property)
-            (property-handler/add-property! repo parent-block property value
-                                            :old-value old-value)))
+            (property-handler/set-block-property! repo (:block/uuid parent-block) property value
+                                                  :old-value old-value)))
         (editor-handler/save-block! (get-state) value))))
   state)
 

+ 0 - 152
src/main/frontend/handler/editor/property.cljs

@@ -1,152 +0,0 @@
-(ns frontend.handler.editor.property
-  "Property related fns for the editor"
-  (:require [clojure.string :as string]
-            [frontend.config :as config]
-            [frontend.db :as db]
-            [frontend.modules.outliner.core :as outliner-core]
-            [frontend.modules.outliner.transaction :as outliner-tx]
-            [frontend.state :as state]
-            [frontend.util :as util]
-            [frontend.util.drawer :as drawer]
-            [frontend.handler.file-based.property :as file-property]
-            [goog.object :as gobj]
-            [logseq.graph-parser.util :as gp-util]
-            [frontend.db.listener :as db-listener]))
-
-;; FIXME: db-version properties
-
-(defn clear-selection!
-  []
-  (state/clear-selection!))
-
-(defn- get-edit-input-id-with-block-id
-  [block-id]
-  (when-let [first-block (util/get-first-block-by-id block-id)]
-    (string/replace (gobj/get first-block "id")
-                    "ls-block"
-                    "edit-block")))
-
-(defn- text-range-by-lst-fst-line [content [direction pos]]
-  (case direction
-    :up
-    (let [last-new-line (or (string/last-index-of content \newline) -1)
-          end (+ last-new-line pos 1)]
-      (subs content 0 end))
-    :down
-    (-> (string/split-lines content)
-        first
-        (or "")
-        (subs 0 pos))))
-
-(defn mark-last-input-time!
-  [repo]
-  (when repo
-    (state/set-editor-last-input-time! repo (util/time-ms))
-    (db-listener/clear-repo-persistent-job! repo)))
-
-(defn edit-block!
-  ([block pos id]
-   (edit-block! block pos id nil))
-  ([block pos id {:keys [custom-content tail-len retry-times]
-                  :or {tail-len 0
-                       retry-times 0}
-                  :as opts}]
-   (when-not (> retry-times 2)
-     (when-not config/publishing?
-       (when-let [block-id (:block/uuid block)]
-         (let [repo (state/get-current-repo)
-               block (or (db/pull [:block/uuid block-id]) block)
-               edit-input-id (if (uuid? id)
-                               (get-edit-input-id-with-block-id id)
-                               (-> (str (subs id 0 (- (count id) 36)) block-id)
-                                   (string/replace "ls-block" "edit-block")))
-               content (or custom-content (:block/content block) "")
-               content-length (count content)
-               text-range (cond
-                            (vector? pos)
-                            (text-range-by-lst-fst-line content pos)
-
-                            (and (> tail-len 0) (>= (count content) tail-len))
-                            (subs content 0 (- (count content) tail-len))
-
-                            (or (= :max pos) (<= content-length pos))
-                            content
-
-                            :else
-                            (subs content 0 pos))
-               content (-> (file-property/remove-built-in-properties-when-file-based
-                            repo (:block/format block) content)
-                           (drawer/remove-logbook))]
-           (clear-selection!)
-           (if edit-input-id
-             (do
-               (state/set-editing! edit-input-id content block text-range)
-               (mark-last-input-time! (state/get-current-repo)))
-             ;; Block may not be rendered yet
-             (js/setTimeout (fn [] (edit-block! block pos id (update opts :retry-times inc))) 10))))))))
-
-(defn batch-set-block-property!
-  "col: a collection of [block-id property-key property-value]."
-  [col]
-  #_:clj-kondo/ignore
-  (when-let [repo (state/get-current-repo)]
-    (let [col' (group-by first col)]
-      (outliner-tx/transact!
-       {:outliner-op :save-block}
-       (doseq [[block-id items] col']
-         (let [block-id (if (string? block-id) (uuid block-id) block-id)
-               new-properties (zipmap (map second items)
-                                      (map last items))]
-           (when-let [block (db/entity [:block/uuid block-id])]
-             (let [format (:block/format block)
-                   content (:block/content block)
-                   properties (:block/properties block)
-                   properties-text-values (:block/properties-text-values block)
-                   properties (-> (merge properties new-properties)
-                                  gp-util/remove-nils-non-nested)
-                   properties-text-values (-> (merge properties-text-values new-properties)
-                                              gp-util/remove-nils-non-nested)
-                   property-ks (->> (concat (:block/properties-order block)
-                                            (map second items))
-                                    (filter (set (keys properties)))
-                                    distinct
-                                    vec)
-                   content (file-property/remove-properties-when-file-based repo format content)
-                   kvs (for [key property-ks] [key (or (get properties-text-values key)
-                                                       (get properties key))])
-                   content (file-property/insert-properties-when-file-based repo format content kvs)
-                   content (file-property/remove-empty-properties-when-file-based repo content)
-                   block {:block/uuid block-id
-                          :block/properties properties
-                          :block/properties-order property-ks
-                          :block/properties-text-values properties-text-values
-                          :block/content content}]
-               (outliner-core/save-block! block)))))))
-
-    (let [block-id (ffirst col)
-          block-id (if (string? block-id) (uuid block-id) block-id)
-          input-pos (or (state/get-edit-pos) :max)]
-      ;; update editing input content
-      (when-let [editing-block (state/get-edit-block)]
-        (when (= (:block/uuid editing-block) block-id)
-          (edit-block! editing-block
-                       input-pos
-                       (state/get-edit-input-id)))))))
-
-(defn batch-add-block-property!
-  [block-ids property-key property-value]
-  (batch-set-block-property! (map #(vector % property-key property-value) block-ids)))
-
-(defn batch-remove-block-property!
-  [block-ids property-key]
-  (batch-set-block-property! (map #(vector % property-key nil) block-ids)))
-
-(defn remove-block-property!
-  [block-id key]
-  (let [key (keyword key)]
-    (batch-set-block-property! [[block-id key nil]])))
-
-(defn set-block-property!
-  [block-id key value]
-  (let [key (keyword key)]
-    (batch-set-block-property! [[block-id key value]])))

+ 76 - 1
src/main/frontend/handler/file_based/property.cljs

@@ -1,7 +1,15 @@
 (ns frontend.handler.file-based.property
   "Properties handler for file graphs and file graph specific feature implementations"
   (:require [frontend.handler.file-based.property.util :as property]
-            [frontend.config :as config]))
+            [frontend.config :as config]
+            [clojure.string :as string]
+            [frontend.db :as db]
+            [frontend.modules.outliner.core :as outliner-core]
+            [frontend.modules.outliner.transaction :as outliner-tx]
+            [frontend.state :as state]
+            [frontend.util :as util]
+            [logseq.graph-parser.util :as gp-util]
+            [frontend.handler.block :as block-handler]))
 
 ;; Why need these XXX-when-file-based fns?
 ;; there're a lot of usages of property-related fns(e.g. property/insert-property) in the whole codebase.
@@ -40,6 +48,7 @@
   (if (config/db-based-graph? repo)
     content
     (property/remove-built-in-properties format content)))
+
 (defn remove-empty-properties-when-file-based
   [repo content]
   (if (config/db-based-graph? repo)
@@ -59,3 +68,69 @@
 (def property-key-exist?-when-file-based property/property-key-exist?)
 (def goto-properties-end-when-file-based property/goto-properties-end)
 (def front-matter?-when-file-based property/front-matter?)
+
+(defn batch-set-block-property!
+  "col: a collection of [block-id property-key property-value]."
+  [col]
+  #_:clj-kondo/ignore
+  (when-let [repo (state/get-current-repo)]
+    (let [col' (group-by first col)]
+      (outliner-tx/transact!
+       {:outliner-op :save-block}
+       (doseq [[block-id items] col']
+         (let [block-id (if (string? block-id) (uuid block-id) block-id)
+               new-properties (zipmap (map second items)
+                                      (map last items))]
+           (when-let [block (db/entity [:block/uuid block-id])]
+             (let [format (:block/format block)
+                   content (:block/content block)
+                   properties (:block/properties block)
+                   properties-text-values (:block/properties-text-values block)
+                   properties (-> (merge properties new-properties)
+                                  gp-util/remove-nils-non-nested)
+                   properties-text-values (-> (merge properties-text-values new-properties)
+                                              gp-util/remove-nils-non-nested)
+                   property-ks (->> (concat (:block/properties-order block)
+                                            (map second items))
+                                    (filter (set (keys properties)))
+                                    distinct
+                                    vec)
+                   content (remove-properties-when-file-based repo format content)
+                   kvs (for [key property-ks] [key (or (get properties-text-values key)
+                                                       (get properties key))])
+                   content (insert-properties-when-file-based repo format content kvs)
+                   content (remove-empty-properties-when-file-based repo content)
+                   block {:block/uuid block-id
+                          :block/properties properties
+                          :block/properties-order property-ks
+                          :block/properties-text-values properties-text-values
+                          :block/content content}]
+               (outliner-core/save-block! block)))))))
+
+    (let [block-id (ffirst col)
+          block-id (if (string? block-id) (uuid block-id) block-id)
+          input-pos (or (state/get-edit-pos) :max)]
+      ;; update editing input content
+      (when-let [editing-block (state/get-edit-block)]
+        (when (= (:block/uuid editing-block) block-id)
+          (block-handler/edit-block! editing-block
+                                     input-pos
+                                     (state/get-edit-input-id)))))))
+
+(defn batch-add-block-property!
+  [block-ids property-key property-value]
+  (batch-set-block-property! (map #(vector % property-key property-value) block-ids)))
+
+(defn batch-remove-block-property!
+  [block-ids property-key]
+  (batch-set-block-property! (map #(vector % property-key nil) block-ids)))
+
+(defn remove-block-property!
+  [block-id key]
+  (let [key (keyword key)]
+    (batch-set-block-property! [[block-id key nil]])))
+
+(defn set-block-property!
+  [block-id key value]
+  (let [key (keyword key)]
+    (batch-set-block-property! [[block-id key value]])))

+ 30 - 10
src/main/frontend/handler/property.cljs

@@ -7,19 +7,17 @@
 
 (def builtin-schema-types db-property/builtin-schema-types)
 
-(defn add-property!
-  [repo block k-name v & opts]
-  ;; TODO: Remove ignores when finished
-  #_:clj-kondo/ignore
+(defn set-block-property!
+  [repo block-id key v & opts]
   (if (config/db-based-graph? repo)
-    (db-property/add-property! repo block k-name v opts)))
+    (db-property/set-block-property! repo block-id key v opts)
+    (file-property/set-block-property! block-id key v)))
 
-(defn remove-property!
-  [repo block property-uuid]
-  {:pre (uuid? property-uuid)}
-  #_:clj-kondo/ignore
+(defn remove-block-property!
+  [repo block-id key]
   (if (config/db-based-graph? repo)
-    (db-property/remove-property! repo block property-uuid)))
+    (db-property/remove-block-property! repo block-id key)
+    (file-property/remove-block-property! block-id key)))
 
 (defn update-property!
   [repo property-uuid opts]
@@ -59,3 +57,25 @@
   (if (config/db-based-graph? repo)
     content
     (file-property/remove-id-property format content)))
+
+(defn file-persist-block-id!
+  [repo block-id]
+  (when-not (config/db-based-graph? repo)
+    (file-property/set-block-property! block-id :id (str block-id))))
+
+(defn batch-add-block-property!
+  [repo block-ids key value]
+  (if (config/db-based-graph? repo)
+    (db-property/batch-add-property! repo block-ids key value)
+    (file-property/batch-add-block-property! block-ids key value)))
+
+(defn batch-remove-block-property!
+  [repo block-ids key]
+  (if (config/db-based-graph? repo)
+    (db-property/batch-remove-property! repo block-ids key)
+    (file-property/batch-remove-block-property! block-ids key)))
+
+(defn file-batch-set-property!
+  [repo col]
+  (when-not (config/db-based-graph? repo)
+    (file-property/batch-set-block-property! col)))

+ 2 - 3
src/main/frontend/modules/editor/undo_redo.cljs

@@ -9,7 +9,7 @@
             [clojure.set :as set]
             [medley.core :as medley]
             [frontend.util.drawer :as drawer]
-            [frontend.handler.file-based.property :as file-property]))
+            [frontend.handler.file-based.property.util :as property-util]))
 
 ;;;; APIs
 
@@ -160,8 +160,7 @@
   []
   (when-let [block (state/get-edit-block)]
     (when-let [content (:block/content (db/entity (:db/id block)))]
-      (let [repo (state/get-current-repo)
-            content' (-> (file-property/remove-built-in-properties-when-file-based repo (:block/format block) content)
+      (let [content' (-> (property-util/remove-built-in-properties (:block/format block) content)
                          (drawer/remove-logbook))]
         (state/set-edit-content! (state/get-edit-input-id) content')))))
 

+ 5 - 5
src/main/frontend/modules/file/core.cljs

@@ -9,7 +9,7 @@
             [frontend.modules.file.uprint :as up]
             [frontend.state :as state]
             [frontend.util.fs :as fs-util]
-            [frontend.handler.file-based.property :as file-property]
+            [frontend.handler.file-based.property.util :as property-util]
             [logseq.common.path :as path]))
 
 (defn- indented-block-content
@@ -19,14 +19,14 @@
 
 (defn- content-with-collapsed-state
   "Only accept nake content (without any indentation)"
-  [repo format content collapsed?]
+  [_repo format content collapsed?]
   (cond
     collapsed?
-    (file-property/insert-property format content :collapsed true)
+    (property-util/insert-property format content :collapsed true)
 
     ;; Don't check properties. Collapsed is an internal state log as property in file, but not counted into properties
     (false? collapsed?)
-    (file-property/remove-property-when-file-based repo format :collapsed content)
+    (property-util/remove-property format :collapsed content)
 
     :else
     content))
@@ -84,7 +84,7 @@
                               " ")]
                     (str prefix sep new-content)))
         content (if block-ref-not-saved?
-                  (file-property/insert-property format content :id (str (:block/uuid b)))
+                  (property-util/insert-property format content :id (str (:block/uuid b)))
                   content)]
     content))
 

+ 3 - 3
src/main/frontend/modules/outliner/core.cljs

@@ -12,11 +12,11 @@
             [frontend.modules.outliner.utils :as outliner-u]
             [frontend.state :as state]
             [frontend.util :as util]
-            [frontend.handler.file-based.property :as file-property]
             [frontend.config :as config]
             [logseq.graph-parser.util :as gp-util]
             [cljs.spec.alpha :as s]
-            [frontend.format.block :as block]))
+            [frontend.format.block :as block]
+            [frontend.handler.file-based.property.util :as property-util]))
 
 (s/def ::block-map (s/keys :opt [:db/id :block/uuid :block/page :block/left :block/parent]))
 
@@ -521,7 +521,7 @@
               (update :block/properties #(assoc % :logseq.order-list-type list-type))
 
               (not (config/db-based-graph? (state/get-current-repo)))
-              (assoc :block/content (file-property/insert-property format content :logseq.order-list-type list-type))))
+              (assoc :block/content (property-util/insert-property format content :logseq.order-list-type list-type))))
           blocks)
         blocks))))
 

+ 4 - 4
src/main/frontend/modules/outliner/datascript.cljs

@@ -11,9 +11,9 @@
             [frontend.search :as search]
             [clojure.string :as string]
             [frontend.util :as util]
-            [frontend.handler.file-based.property :as file-property]
             [logseq.graph-parser.util.block-ref :as block-ref]
-            [frontend.db.validate :as db-validate]))
+            [frontend.db.validate :as db-validate]
+            [frontend.handler.file-based.property.util :as property-util]))
 
 (defn new-outliner-txs-state [] (atom []))
 
@@ -90,8 +90,8 @@
                               (let [refs (:block/_refs block)]
                                 (map (fn [ref]
                                        (let [id (:db/id ref)
-                                             block-content (file-property/remove-properties-when-file-based
-                                                            repo (:block/format block) (:block/content block))
+                                             block-content (property-util/remove-properties
+                                                            (:block/format block) (:block/content block))
                                              new-content (-> (:block/content ref)
                                                              (string/replace (re-pattern (util/format "(?i){{embed \\(\\(%s\\)\\)\\s?}}" (str (:block/uuid block))))
                                                                              block-content)

+ 3 - 3
src/main/frontend/search.cljs

@@ -12,11 +12,11 @@
             [frontend.search.protocol :as protocol]
             [frontend.state :as state]
             [frontend.util :as util]
-            [frontend.handler.file-based.property :as file-property]
             [goog.object :as gobj]
             [promesa.core :as p]
             [clojure.set :as set]
-            [datascript.core :as d]))
+            [datascript.core :as d]
+            [frontend.handler.file-based.property.util :as property-util]))
 
 (defn get-engine
   [repo]
@@ -184,7 +184,7 @@
 (defn get-all-properties
   []
   (->> (db-model/get-all-properties)
-       (remove (file-property/hidden-properties))
+       (remove (property-util/hidden-properties))
        ;; Complete full keyword except the ':'
        (map (fn [property]
               (if (keyword? property)

+ 14 - 7
src/main/logseq/api.cljs

@@ -22,11 +22,11 @@
             [frontend.fs :as fs]
             [frontend.handler.dnd :as editor-dnd-handler]
             [frontend.handler.editor :as editor-handler]
-            [frontend.handler.editor.property :as editor-property]
             [frontend.handler.export :as export-handler]
             [frontend.handler.page :as page-handler]
             [frontend.handler.plugin :as plugin-handler]
             [frontend.handler.common.plugin :as plugin-common-handler]
+            [frontend.handler.property :as property-handler]
             [frontend.modules.outliner.core :as outliner]
             [frontend.modules.outliner.tree :as outliner-tree]
             [frontend.handler.command-palette :as palette-handler]
@@ -718,11 +718,15 @@
 
 (def ^:export upsert_block_property
   (fn [block-uuid key value]
-    (editor-property/set-block-property! (sdk-utils/uuid-or-throw-error block-uuid) key value)))
+    (property-handler/set-block-property!
+     (state/get-current-repo)
+     (sdk-utils/uuid-or-throw-error block-uuid) key value)))
 
 (def ^:export remove_block_property
   (fn [block-uuid key]
-    (editor-property/remove-block-property! (sdk-utils/uuid-or-throw-error block-uuid) key)))
+    (property-handler/remove-block-property!
+     (state/get-current-repo)
+     (sdk-utils/uuid-or-throw-error block-uuid) key)))
 
 (def ^:export get_block_property
   (fn [block-uuid key]
@@ -968,17 +972,20 @@
   [target-uuid template-name ^js opts]
   (when (and template-name (db-model/get-block-by-uuid target-uuid))
     (let [{:keys [overwrite]} (bean/->clj opts)
-          exist? (page-handler/template-exists? template-name)]
+          exist? (page-handler/template-exists? template-name)
+          repo (state/get-current-repo)]
       (if (or (not exist?) (true? overwrite))
         (do (when-let [old-target (and exist? (db-model/get-template-by-name template-name))]
-              (editor-property/remove-block-property! (:block/uuid old-target) :template))
-            (editor-property/set-block-property! target-uuid :template template-name))
+              (property-handler/remove-block-property! repo (:block/uuid old-target) :template))
+            (property-handler/set-block-property! repo target-uuid :template template-name))
         (throw (js/Error. "Template already exists!"))))))
 
 (defn ^:export remove_template
   [name]
   (when-let [target (db-model/get-template-by-name name)]
-    (editor-property/remove-block-property! (:block/uuid target) :template)))
+    (property-handler/remove-block-property!
+     (state/get-current-repo)
+     (:block/uuid target) :template)))
 
 ;; search
 (defn ^:export search