feat: import from logseq edn

feat: import edn with provided uuid

feat: overwrite page uuid; use properties in content

feat: error handling for importing

feat: support json import

chore: fix lint by splitting setup ui
This commit is contained in:
Junyi Du
2022-05-10 22:10:12 +08:00
parent 459262cd24
commit 0cdacc35e2
8 changed files with 294 additions and 75 deletions

View File

@@ -942,14 +942,16 @@
(state/set-edit-content! input-id new-content)
(save-block-if-changed! block new-content))))))))
(defn- set-blocks-id!
(defn set-blocks-id!
"Persist block uuid to file if not exists"
[block-ids]
(let [block-ids (remove nil? block-ids)
col (map (fn [block-id]
(let [block (db/entity [:block/uuid 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)]
block-ids)
col (remove nil? col)]
(batch-set-block-property! col)))
(defn copy-block-ref!
@@ -1915,10 +1917,13 @@
0))
(defn paste-blocks
"Given a vec of blocks, insert them into the target page.
keep-uuid?: if true, keep the uuid provided in the block structure."
[blocks {:keys [content-update-fn
exclude-properties
target-block
sibling?]
sibling?
keep-uuid?]
:or {exclude-properties []}}]
(let [editing-block (when-let [editing-block (state/get-edit-block)]
(some-> (db/pull (:db/id editing-block))
@@ -1945,10 +1950,11 @@
(let [format (or (:block/format target-block) (state/get-preferred-format))
blocks' (map (fn [block]
(paste-block-cleanup block page exclude-properties format content-update-fn))
blocks)
blocks)
result (outliner-core/insert-blocks! blocks' target-block {:sibling? sibling?
:outliner-op :paste
:replace-empty-target? true})]
:replace-empty-target? true
:keep-uuid? keep-uuid?})]
(edit-last-block-after-inserted! result))))))
(defn- block-tree->blocks
@@ -1965,18 +1971,24 @@
(assert fst-block "fst-block shouldn't be nil")
(assoc fst-block :block/level (:block/level block)))))))
(defn insert-block-tree-after-target
(defn insert-block-tree
"`tree-vec`: a vector of blocks.
Block element: {:content :properties :children [block-1, block-2, ...]}"
[target-block-id sibling? tree-vec format]
A block element: {:content :properties :children [block-1, block-2, ...]}"
[tree-vec format {:keys [target-block] :as opts}]
(let [blocks (block-tree->blocks tree-vec format)
target-block (db/pull target-block-id)
page-id (:db/id (:block/page target-block))
blocks (gp-block/with-parent-and-left page-id blocks)]
(paste-blocks
blocks
{:target-block target-block
:sibling? sibling?})))
opts)))
(defn insert-block-tree-after-target
"`tree-vec`: a vector of blocks.
A block element: {:content :properties :children [block-1, block-2, ...]}"
[target-block-id sibling? tree-vec format]
(insert-block-tree tree-vec format
{:target-block (db/pull target-block-id)
:sibling? sibling?}))
(defn insert-template!
([element-id db-id]