mirror of https://github.com/logseq/logseq
enhance(api): compatible block properties for the db graph
parent
2528317e04
commit
61b158fd7f
|
@ -6,8 +6,16 @@
|
|||
|
||||
(defn get-property-name
|
||||
"Get a property's name given its id"
|
||||
[id]
|
||||
(:block/original-name (db-utils/entity id)))
|
||||
[e]
|
||||
(:block/original-name (if (number? e) (db-utils/pull e) e)))
|
||||
|
||||
(defn get-property-value
|
||||
"Get a property's name given its id"
|
||||
[e]
|
||||
(if-let [e (if (number? e) (db-utils/pull e) e)]
|
||||
(or (:block/content e)
|
||||
(:block/original-name e))
|
||||
e))
|
||||
|
||||
(defn all-hidden-properties?
|
||||
"Checks if the given properties are all hidden properties"
|
||||
|
@ -19,12 +27,22 @@
|
|||
"Given a DB graph's properties, returns a readable properties map with keys as
|
||||
property names and property values dereferenced where possible. A property's
|
||||
value will only be a uuid if it's a page or a block"
|
||||
[properties]
|
||||
([properties] (readable-properties properties true))
|
||||
([properties original-key?]
|
||||
(->> properties
|
||||
(map (fn [[k v]]
|
||||
(let [prop-ent (db-utils/entity k)]
|
||||
[(-> prop-ent :block/original-name keyword)
|
||||
(if (set? v)
|
||||
[(if original-key? k (-> prop-ent :block/original-name keyword))
|
||||
(cond
|
||||
(set? v)
|
||||
(set (map db-property/get-property-value-name v))
|
||||
(db-property/get-property-value-name v))])))
|
||||
(into {})))
|
||||
|
||||
(sequential? v)
|
||||
(map #(get-property-value (or (:db/id %) %)) v)
|
||||
|
||||
(:db/id v)
|
||||
(get-property-value (or (:db/id v) v))
|
||||
|
||||
:else
|
||||
v)])))
|
||||
(into {}))))
|
||||
|
|
|
@ -4,10 +4,25 @@
|
|||
[frontend.db.utils :as db-utils]
|
||||
[cljs-bean.core :as bean]
|
||||
[frontend.state :as state]
|
||||
[frontend.config :as config]
|
||||
[frontend.modules.outliner.tree :as outliner-tree]
|
||||
[frontend.db :as db]
|
||||
[logseq.db.frontend.property :as db-property]
|
||||
[frontend.handler.db-based.property.util :as db-pu]
|
||||
[logseq.sdk.utils :as sdk-utils]))
|
||||
|
||||
(defn- into-properties
|
||||
[repo block]
|
||||
(if (some-> repo (config/db-based-graph?))
|
||||
(let [props (some->> block
|
||||
(filter (fn [[k _]] (db-property/property? k)))
|
||||
(into {})
|
||||
(db-pu/readable-properties))
|
||||
block (update block :block/properties merge props)
|
||||
block (apply dissoc (concat [block] (keys props)))]
|
||||
block)
|
||||
block))
|
||||
|
||||
(defn get_block
|
||||
[id-or-uuid ^js opts]
|
||||
(when-let [block (if (number? id-or-uuid)
|
||||
|
@ -24,5 +39,6 @@
|
|||
;; attached shallow children
|
||||
(assoc block :block/children
|
||||
(map #(list :uuid (:block/uuid %))
|
||||
(db/get-block-immediate-children repo uuid))))]
|
||||
(db/get-block-immediate-children repo uuid))))
|
||||
block (into-properties repo block)]
|
||||
(bean/->js (sdk-utils/normalize-keyword-for-json block)))))))
|
||||
|
|
Loading…
Reference in New Issue