From 59c3ca7438f2b287b29b15db70e2e84dc79f7ac7 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Wed, 21 Jun 2023 16:25:27 +0800 Subject: [PATCH] fix: remove properties from block content when importing --- src/main/frontend/handler/editor.cljs | 11 +++++++++- src/main/frontend/handler/editor/impl/db.cljs | 2 +- src/main/frontend/handler/import.cljs | 7 ++++--- .../frontend/modules/outliner/datascript.cljs | 21 +++++++++++-------- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index bb8cf580dd..41414df575 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -40,6 +40,7 @@ [frontend.util.list :as list] [frontend.util.marker :as marker] [frontend.util.property-edit :as property-edit] + [frontend.util.property :as property] [frontend.util.text :as text-util] [frontend.util.thingatpt :as thingatpt] [frontend.handler.editor.impl :as editor-impl] @@ -1958,7 +1959,8 @@ content* (str (if (= :markdown format) "- " "* ") (property-edit/insert-properties-when-file-based repo format content props)) ast (mldoc/->edn content* (gp-mldoc/default-config format)) - blocks (block/extract-blocks ast content* format {:page-name page-name}) + blocks (->> (block/extract-blocks ast content* format {:page-name page-name}) + (map editor-impl/wrap-parse-block)) fst-block (first blocks) fst-block (if (and keep-uuid? (uuid? (:uuid block))) (assoc fst-block :block/uuid (:uuid block)) @@ -1974,6 +1976,13 @@ page-id (:db/id (:block/page target-block)) page-name (some-> page-id (db/entity) :block/name) blocks (block-tree->blocks repo tree-vec format keep-uuid? page-name) + blocks (if (config/db-based-graph? (state/get-current-repo)) + ;; Remove properties from content + (map (fn [b] + (cond-> b + (:content b) + (update :content #(property/remove-properties format %)))) blocks) + blocks) blocks (gp-block/with-parent-and-left page-id blocks) block-refs (->> (mapcat :block/refs blocks) (set) diff --git a/src/main/frontend/handler/editor/impl/db.cljs b/src/main/frontend/handler/editor/impl/db.cljs index 3510cc32d4..2e8aa54e7b 100644 --- a/src/main/frontend/handler/editor/impl/db.cljs +++ b/src/main/frontend/handler/editor/impl/db.cljs @@ -77,7 +77,7 @@ :block.temp/top? :block.temp/bottom? :block/pre-block? - :block/unordered?) + :block/unordered) (assoc :block/content content) (merge (if level {:block/level level} {})) (replace-page-refs-with-ids))] diff --git a/src/main/frontend/handler/import.cljs b/src/main/frontend/handler/import.cljs index b6f85662ee..0c1685c2aa 100644 --- a/src/main/frontend/handler/import.cljs +++ b/src/main/frontend/handler/import.cljs @@ -71,6 +71,7 @@ (when (seq journal-pages-tx) (db/transact! repo journal-pages-tx))))) +;; TODO: replace files with page blocks transaction (defn import-from-roam-json! [data finished-ok-handler] (when-let [repo (state/get-current-repo)] @@ -147,9 +148,9 @@ (map #(merge % (gp-whiteboard/with-whiteboard-block-props % page-name))))] (db/transact! blocks)) (editor/insert-block-tree children page-format - {:target-block page-block - :sibling? false - :keep-uuid? true})) + {:target-block page-block + :sibling? false + :keep-uuid? true})) (catch :default e (js/console.error e) (prn {:tree tree}) diff --git a/src/main/frontend/modules/outliner/datascript.cljs b/src/main/frontend/modules/outliner/datascript.cljs index fa9b38a232..44a4a065be 100644 --- a/src/main/frontend/modules/outliner/datascript.cljs +++ b/src/main/frontend/modules/outliner/datascript.cljs @@ -140,13 +140,17 @@ (defn transact! [txs opts before-editor-cursor] (let [repo (state/get-current-repo) - txs (remove-nil-from-transaction txs) + db-based? (config/db-based-graph? repo) txs (map (fn [m] (if (map? m) - (dissoc m - :block/children :block/meta :block/top? :block/bottom? :block/anchor - :block/title :block/body :block/level :block/container :db/other-tx - :block/additional-properties) + (cond-> m + true + (dissoc :block/children :block/meta :block/top? :block/bottom? :block/anchor + :block/title :block/body :block/level :block/container :db/other-tx + :block/additional-properties :block/unordered) + db-based? + (update :block/properties dissoc :id)) m)) txs) + txs (remove-nil-from-transaction txs) txs (cond-> txs (:uuid-changed opts) (update-block-refs opts) @@ -159,10 +163,9 @@ (distinct))] (when (and (seq txs) (not (:skip-transact? opts)) - (if (react/db-graph? repo) - true - (not (contains? (:file/unlinked-dirs @state/state) - (config/get-repo-dir repo))))) + (or db-based? + (not (contains? (:file/unlinked-dirs @state/state) + (config/get-repo-dir repo))))) ;; (prn :debug "Outliner transact:") ;; (frontend.util/pprint {:txs txs :opts opts})