handle whiteboard built-in properties

pull/10016/head
Tienson Qin 2023-08-01 21:48:36 +08:00
parent db5e0a6571
commit 8e9a189ba1
6 changed files with 41 additions and 29 deletions

View File

@ -61,7 +61,7 @@
[]
(set/union #{:title :icon :template :template-including-parent :public :filters :exclude-from-graph-view
:logseq.query/nlp-date
;; org-mode only
;; org-mode only
:macro :filetags}
editable-linkable-built-in-properties
editable-view-and-table-properties))

View File

@ -21,8 +21,8 @@
[frontend.ui :as ui]
[logseq.common.path :as path]
[logseq.graph-parser.util :as gp-util]
[logseq.graph-parser.whiteboard :as gp-whiteboard]
[promesa.core :as p]))
[promesa.core :as p]
[frontend.handler.property.util :as pu]))
(defn- safe-api-call
"Force the callback result to be nil, otherwise, ipc calls could lead to
@ -113,7 +113,7 @@
block-id
(if-let [block (db-model/get-block-by-uuid block-id)]
(if (gp-whiteboard/shape-block? block)
(if (pu/shape-block? block)
(route-handler/redirect-to-whiteboard! (get-in block [:block/page :block/name]) {:block-id block-id})
(route-handler/redirect-to-page! block-id))
(notification/show! (str "Open link failed. Block-id `" block-id "` doesn't exist in the graph.") :error false))

View File

@ -1677,7 +1677,7 @@
(defn- bullet-on-click
[e block uuid]
(cond
(gp-whiteboard/shape-block? block)
(pu/shape-block? block)
(route-handler/redirect-to-whiteboard! (get-in block [:block/page :block/name]) {:block-id uuid})
(gobj/get e "shiftKey")
@ -2788,7 +2788,7 @@
doc-mode? (:document/mode? config)
embed? (:embed? config)
reference? (:reference? config)
whiteboard-block? (gp-whiteboard/shape-block? block)
whiteboard-block? (pu/shape-block? block)
block-id (str "ls-block-" blocks-container-id "-" uuid)
has-child? (first (:block/_parent (db/entity (:db/id block))))
attrs (on-drag-and-mouse-attrs block uuid top? block-id *move-to)

View File

@ -22,4 +22,13 @@
[block key]
(let [block (db/entity (:db/id block))]
(when-let [properties (:block/properties block)]
(lookup properties key))))
(lookup properties key))))
(defn block->shape [block]
(get-property block :logseq.tldraw.shape))
(defn page-block->tldr-page [block]
(get-property block :logseq.tldraw.page))
(defn shape-block? [block]
(= :whiteboard-shape (get-property block :ls-type)))

View File

@ -8,6 +8,7 @@
[frontend.handler.editor :as editor-handler]
[frontend.handler.route :as route-handler]
[frontend.handler.property.util :as pu]
[frontend.handler.property :as property-handler]
[frontend.modules.editor.undo-redo :as history]
[frontend.modules.outliner.core :as outliner]
[frontend.modules.outliner.file :as outliner-file]
@ -51,14 +52,14 @@
(->> blocks
(map (fn [block]
(assoc block :index (get shape-id->index (str (:block/uuid block)) 0))))
(filter gp-whiteboard/shape-block?)
(map gp-whiteboard/block->shape)
(filter pu/shape-block?)
(map pu/block->shape)
(sort-by :index))))
(defn- whiteboard-clj->tldr [page-block blocks]
(let [id (str (:block/uuid page-block))
shapes (build-shapes page-block blocks)
tldr-page (gp-whiteboard/page-block->tldr-page page-block)
tldr-page (pu/page-block->tldr-page page-block)
assets (:assets tldr-page)
tldr-page (dissoc tldr-page :assets)]
(clj->js {:currentPageId id
@ -188,21 +189,23 @@
(defn get-default-new-whiteboard-tx
[page-name id]
[#:block{:uuid id
:name (util/page-name-sanity-lc page-name),
:original-name page-name
:type "whiteboard",
:properties
{:ls-type :whiteboard-page,
:logseq.tldraw.page
{:id id,
:name page-name,
:ls-type :whiteboard-page,
:bindings {},
:nonce 1,
:assets []}},
:updated-at (util/time-ms),
:created-at (util/time-ms)}])
(let [properties (->>
{:ls-type :whiteboard-page,
:logseq.tldraw.page
{:id id,
:name page-name,
:ls-type :whiteboard-page,
:bindings {},
:nonce 1,
:assets []}}
(property-handler/replace-key-with-id! (state/get-current-repo)))]
[#:block{:uuid id
:name (util/page-name-sanity-lc page-name),
:original-name page-name
:type "whiteboard",
:properties properties,
:updated-at (util/time-ms),
:created-at (util/time-ms)}]))
(defn get-whiteboard-entity [page-name]
(db-utils/entity [:block/name (util/page-name-sanity-lc page-name)]))
@ -268,7 +271,7 @@
"Given a page, return all the logseq blocks (exclude all shapes)"
[page-name]
(let [blocks (model/get-page-blocks-no-cache page-name)]
(remove gp-whiteboard/shape-block? blocks)))
(remove pu/shape-block? blocks)))
(defn- get-last-root-block
"Get the last root Logseq block in the page. Main purpose is to calculate the new :block/left id"
@ -323,7 +326,7 @@
(let [page-block (first pages)
;; FIXME: should also clone normal blocks
shapes (build-shapes page-block blocks)
tldr-page (gp-whiteboard/page-block->tldr-page page-block)
tldr-page (pu/page-block->tldr-page page-block)
assets (:assets tldr-page)
bindings (:bindings tldr-page)]
(.cloneShapesIntoCurrentPage ^js api (clj->js {:shapes shapes

View File

@ -3,7 +3,7 @@
[frontend.db.model :as model]
[clojure.string :as string]
[frontend.state :as state]
[logseq.graph-parser.whiteboard :as gp-whiteboard]))
[frontend.handler.property.util :as pu]))
(defprotocol INode
(-get-id [this])
@ -28,7 +28,7 @@
(defn- blocks->vec-tree-aux
[blocks root]
(let [root-id (:db/id root)
blocks (remove gp-whiteboard/shape-block? blocks)
blocks (remove pu/shape-block? blocks)
parent-blocks (group-by #(get-in % [:block/parent :db/id]) blocks) ;; exclude whiteboard shapes
sort-fn (fn [parent]
(db/sort-by-left (get parent-blocks parent) {:db/id parent}))