fix: display class properties

This commit is contained in:
Tienson Qin
2024-03-29 10:02:29 +08:00
parent 9115ca72ad
commit cda9ac3e26
18 changed files with 67 additions and 107 deletions

View File

@@ -10,52 +10,21 @@
[frontend.state :as state]
[logseq.graph-parser.block :as gp-block]
[logseq.graph-parser.property :as gp-property]
[frontend.handler.db-based.property.util :as db-pu]
[lambdaisland.glogi :as log]
[datascript.core :as d]
[logseq.db.frontend.property :as db-property]
[frontend.format.mldoc :as mldoc]))
(defn- update-extracted-block-properties
"Updates DB graph blocks to ensure that built-in properties are using uuids
for property ids"
[blocks]
(let [repo (state/get-current-repo)
update-properties (fn [props]
(update-keys props #(if (contains? db-property/built-in-properties-keys %)
(db-pu/get-built-in-property-uuid repo %)
%)))]
(if (config/db-based-graph? repo)
(->> blocks
(map (fn [b]
(if (:block/properties b)
(-> b
(dissoc :block/properties-order)
(update :block/properties update-properties))
b)))
(map (fn [b]
(if (:block/macros b)
(update b :block/macros
(fn [macros]
(map #(-> %
(assoc :block/uuid (d/squuid))
(update :block/properties update-properties)) macros)))
b))))
blocks)))
(defn extract-blocks
"Wrapper around logseq.graph-parser.block/extract-blocks that adds in system state
and handles unexpected failure."
[blocks content format {:keys [with-id? page-name]
:or {with-id? true}}]
(try
(update-extracted-block-properties
(gp-block/extract-blocks blocks content with-id? format
{:user-config (state/get-config)
:block-pattern (config/get-block-pattern format)
:db (db/get-db (state/get-current-repo))
:date-formatter (state/get-date-formatter)
:page-name page-name}))
(gp-block/extract-blocks blocks content with-id? format
{:user-config (state/get-config)
:block-pattern (config/get-block-pattern format)
:db (db/get-db (state/get-current-repo))
:date-formatter (state/get-date-formatter)
:page-name page-name})
(catch :default e
(log/error :exception e)
(state/pub-event! [:capture-error {:error e