fix: remove properties from block content when importing

This commit is contained in:
Tienson Qin
2023-06-21 16:25:27 +08:00
parent 442f40c0b9
commit 59c3ca7438
4 changed files with 27 additions and 14 deletions

View File

@@ -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)

View File

@@ -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))]

View File

@@ -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})

View File

@@ -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})