diff --git a/deps/graph-parser/src/logseq/graph_parser/extract.cljc b/deps/graph-parser/src/logseq/graph_parser/extract.cljc index fe7e7b695..c8171ca3d 100644 --- a/deps/graph-parser/src/logseq/graph_parser/extract.cljc +++ b/deps/graph-parser/src/logseq/graph_parser/extract.cljc @@ -178,6 +178,25 @@ :blocks blocks :ast ast})))) +(defn get-shape-refs [shape] + (when (= "logseq-portal" (:type shape)) + [{:block/name (:pageId shape)}])) + +(defn- with-whiteboard-block-refs + [shape] + (let [refs (get-shape-refs shape)] + (when refs {:block/refs refs}))) + +(defn- with-whiteboard-content + [shape] + {:block/content (or (:text shape) "")}) + +(defn with-whiteboard-block-props + [shape] + (merge {} + (with-whiteboard-block-refs shape) + (with-whiteboard-content shape))) + (defn extract-whiteboard-edn "Extracts whiteboard page from given edn file Whiteboard page edn is a subset of page schema @@ -192,7 +211,9 @@ page-block (merge page-block page-entity (when-not (:block/uuid page-block) {:block/uuid (d/squuid)})) blocks (->> blocks (map #(merge % {:block/level 1 - :block/uuid (or (:block/uuid %) (gp-block/get-custom-id-or-new-id (:block/properties %)))})) + :block/uuid (or (:block/uuid %) + (gp-block/get-custom-id-or-new-id (:block/properties %)))} + (with-whiteboard-block-props (:block/properties %)))) (gp-block/with-parent-and-left {:block/name page-name})) _ (when verbose (println "Parsing finished: " file))] {:pages [page-block] diff --git a/src/main/frontend/handler/whiteboard.cljs b/src/main/frontend/handler/whiteboard.cljs index cb5baa095..0e8b20664 100644 --- a/src/main/frontend/handler/whiteboard.cljs +++ b/src/main/frontend/handler/whiteboard.cljs @@ -4,7 +4,8 @@ [frontend.db.model :as model] [frontend.db.utils :as db-utils] [frontend.modules.outliner.file :as outliner-file] - [frontend.state :as state])) + [frontend.state :as state] + [logseq.graph-parser.extract :refer [with-whiteboard-block-props]])) ;; (defn set-linked-page-or-block! ;; [page-or-block-id] @@ -38,24 +39,13 @@ ;; Use the block's id as the shape's id. {:id uuid}))) -(defn- get-shape-refs [shape] - (when (= "logseq-portal" (:type shape)) - [(select-keys (model/get-page (:pageId shape)) [:db/id])])) - -(defn- get-shape-text [shape] - (:text shape)) - (defn- shape->block [shape page-name] (let [properties shape block {:block/uuid (uuid (:id properties)) :block/page {:block/name page-name} - :block/content "" ;; give it empty string since some block utility requires it :block/properties properties} - refs (get-shape-refs shape) - content (get-shape-text shape)] - (merge block - (when refs {:block/refs refs}) - (when content {:block/content content})))) + additional-props (with-whiteboard-block-props shape)] + (merge block additional-props))) (defn- tldr-page->blocks-tx [page-name tldr-data] (let [page-block {:block/name page-name @@ -89,7 +79,7 @@ :name "page" :shapes shapes})]}))) -(defn page-name->tldr +(defn page-name->tldr ([page-name] (page-name->tldr page-name nil)) ([page-name shape-id] diff --git a/src/main/frontend/modules/outliner/file.cljs b/src/main/frontend/modules/outliner/file.cljs index e82c72acb..a7ccbc7fa 100644 --- a/src/main/frontend/modules/outliner/file.cljs +++ b/src/main/frontend/modules/outliner/file.cljs @@ -22,7 +22,7 @@ (empty? @write-chan-batch-buf)) (def blocks-pull-keys-with-persisted-ids - '[* + '[:block/properties {:block/page [:block/name :block/uuid]} {:block/left [:block/name :block/uuid]} {:block/parent [:block/name :block/uuid]}