|
@@ -24,7 +24,7 @@
|
|
|
(defn convert?to-built-in-property-name
|
|
(defn convert?to-built-in-property-name
|
|
|
[property-name]
|
|
[property-name]
|
|
|
(if (and (not (qualified-keyword? property-name))
|
|
(if (and (not (qualified-keyword? property-name))
|
|
|
- (contains? #{:background-color} property-name))
|
|
|
|
|
|
|
+ (contains? #{:background-color} property-name))
|
|
|
(keyword :logseq.property property-name)
|
|
(keyword :logseq.property property-name)
|
|
|
property-name))
|
|
property-name))
|
|
|
|
|
|
|
@@ -32,19 +32,19 @@
|
|
|
[k]
|
|
[k]
|
|
|
(if (string? k)
|
|
(if (string? k)
|
|
|
(-> k (string/trim)
|
|
(-> k (string/trim)
|
|
|
- (string/replace " " "")
|
|
|
|
|
- (string/replace #"^[:_\s]+" "")
|
|
|
|
|
- (#(cond-> %
|
|
|
|
|
- (not (string/includes? % "/"))
|
|
|
|
|
- (string/lower-case))))
|
|
|
|
|
|
|
+ (string/replace " " "")
|
|
|
|
|
+ (string/replace #"^[:_\s]+" "")
|
|
|
|
|
+ (#(cond-> %
|
|
|
|
|
+ (not (string/includes? % "/"))
|
|
|
|
|
+ (string/lower-case))))
|
|
|
k))
|
|
k))
|
|
|
|
|
|
|
|
(defn resolve-property-prefix-for-db
|
|
(defn resolve-property-prefix-for-db
|
|
|
[^js plugin]
|
|
[^js plugin]
|
|
|
(->> (when (some-> js/window.LSPlugin (.-PluginLocal))
|
|
(->> (when (some-> js/window.LSPlugin (.-PluginLocal))
|
|
|
(or (some->> plugin (.-id) (sanitize-user-property-name) (str "."))
|
|
(or (some->> plugin (.-id) (sanitize-user-property-name) (str "."))
|
|
|
- "._api"))
|
|
|
|
|
- (str "plugin.property")))
|
|
|
|
|
|
|
+ "._api"))
|
|
|
|
|
+ (str "plugin.property")))
|
|
|
|
|
|
|
|
;; FIXME: This ns should not be creating idents. This allows for ident conflicts
|
|
;; FIXME: This ns should not be creating idents. This allows for ident conflicts
|
|
|
;; and assumes that names directly map to idents which is incorrect and breaks for multiple
|
|
;; and assumes that names directly map to idents which is incorrect and breaks for multiple
|
|
@@ -58,27 +58,27 @@
|
|
|
(keyword property-name) property-name)
|
|
(keyword property-name) property-name)
|
|
|
property-name' (convert?to-built-in-property-name property-name')]
|
|
property-name' (convert?to-built-in-property-name property-name')]
|
|
|
(if (qualified-keyword? property-name') property-name'
|
|
(if (qualified-keyword? property-name') property-name'
|
|
|
- (db-ident/create-db-ident-from-name prefix (name property-name) false)))))
|
|
|
|
|
|
|
+ (db-ident/create-db-ident-from-name prefix (name property-name) false)))))
|
|
|
|
|
|
|
|
(defn plugin-property-key?
|
|
(defn plugin-property-key?
|
|
|
[ident]
|
|
[ident]
|
|
|
(some-> ident (str)
|
|
(some-> ident (str)
|
|
|
- (string/starts-with? ":plugin.property.")))
|
|
|
|
|
|
|
+ (string/starts-with? ":plugin.property.")))
|
|
|
|
|
|
|
|
(defn into-readable-db-properties
|
|
(defn into-readable-db-properties
|
|
|
[properties]
|
|
[properties]
|
|
|
(some-> properties
|
|
(some-> properties
|
|
|
- (db-pu/readable-properties
|
|
|
|
|
- {:original-key? true :key-fn str})))
|
|
|
|
|
|
|
+ (db-pu/readable-properties
|
|
|
|
|
+ {:original-key? true :key-fn str})))
|
|
|
|
|
|
|
|
(defn into-properties
|
|
(defn into-properties
|
|
|
([block] (into-properties (state/get-current-repo) block))
|
|
([block] (into-properties (state/get-current-repo) block))
|
|
|
([repo block]
|
|
([repo block]
|
|
|
(if (some-> repo (config/db-based-graph?))
|
|
(if (some-> repo (config/db-based-graph?))
|
|
|
(let [props (some->> block
|
|
(let [props (some->> block
|
|
|
- (filter (fn [[k _]] (db-property/property? k)))
|
|
|
|
|
- (into {})
|
|
|
|
|
- (into-readable-db-properties))
|
|
|
|
|
|
|
+ (filter (fn [[k _]] (db-property/property? k)))
|
|
|
|
|
+ (into {})
|
|
|
|
|
+ (into-readable-db-properties))
|
|
|
block (update block :block/properties merge props)
|
|
block (update block :block/properties merge props)
|
|
|
block (apply dissoc (concat [block] (keys props)))]
|
|
block (apply dissoc (concat [block] (keys props)))]
|
|
|
block)
|
|
block)
|
|
@@ -87,8 +87,8 @@
|
|
|
(defn parse-property-json-value-if-need
|
|
(defn parse-property-json-value-if-need
|
|
|
[ident property-value]
|
|
[ident property-value]
|
|
|
(when-let [prop (and (string? property-value)
|
|
(when-let [prop (and (string? property-value)
|
|
|
- (plugin-property-key? ident)
|
|
|
|
|
- (some-> ident (db-utils/entity)))]
|
|
|
|
|
|
|
+ (plugin-property-key? ident)
|
|
|
|
|
+ (some-> ident (db-utils/entity)))]
|
|
|
(if (= (:logseq.property/type prop) :string)
|
|
(if (= (:logseq.property/type prop) :string)
|
|
|
(try
|
|
(try
|
|
|
(js/JSON.parse property-value)
|
|
(js/JSON.parse property-value)
|
|
@@ -108,10 +108,10 @@
|
|
|
(let [id (:db/id (ldb/get-case-page (conn/get-db) page))]
|
|
(let [id (:db/id (ldb/get-case-page (conn/get-db) page))]
|
|
|
(if (nil? id)
|
|
(if (nil? id)
|
|
|
(-> (page-handler/<create! page {:redirect? false})
|
|
(-> (page-handler/<create! page {:redirect? false})
|
|
|
- (p/then #(:db/id %)))
|
|
|
|
|
|
|
+ (p/then #(:db/id %)))
|
|
|
id))))
|
|
id))))
|
|
|
- (p/all)
|
|
|
|
|
- (p/then (fn [vs] [ident :logseq.property/empty-placeholder vs true])))
|
|
|
|
|
|
|
+ (p/all)
|
|
|
|
|
+ (p/then (fn [vs] [ident :logseq.property/empty-placeholder vs true])))
|
|
|
(let [value (if as-json? (js/JSON.stringify (bean/->js value)) value)]
|
|
(let [value (if as-json? (js/JSON.stringify (bean/->js value)) value)]
|
|
|
[ident value nil false]))))
|
|
[ident value nil false]))))
|
|
|
ent (db-utils/entity ident)]
|
|
ent (db-utils/entity ident)]
|
|
@@ -124,8 +124,8 @@
|
|
|
schema {:logseq.property/type type
|
|
schema {:logseq.property/type type
|
|
|
:db/cardinality :one}]
|
|
:db/cardinality :one}]
|
|
|
(p/chain
|
|
(p/chain
|
|
|
- (db-property-handler/upsert-property! ident schema {})
|
|
|
|
|
- (fn [] (value-handle type false))))
|
|
|
|
|
|
|
+ (db-property-handler/upsert-property! ident schema {})
|
|
|
|
|
+ (fn [] (value-handle type false))))
|
|
|
(let [value-multi? (vector? value)
|
|
(let [value-multi? (vector? value)
|
|
|
ident (:db/ident ent)
|
|
ident (:db/ident ent)
|
|
|
ent-type (:logseq.property/type ent)
|
|
ent-type (:logseq.property/type ent)
|
|
@@ -135,54 +135,54 @@
|
|
|
(when cardinality-want-illegal-changed?
|
|
(when cardinality-want-illegal-changed?
|
|
|
(throw (js/Error. "Multiple property type can not be changed.")))
|
|
(throw (js/Error. "Multiple property type can not be changed.")))
|
|
|
(p/chain
|
|
(p/chain
|
|
|
- (db-property-handler/upsert-property! ident
|
|
|
|
|
- {:logseq.property/type ent-type
|
|
|
|
|
- :db/cardinality (if (and (not ent-type-str?) value-multi?) :many :one)}
|
|
|
|
|
- {})
|
|
|
|
|
- #(value-handle ent-type ent-multi?))))))
|
|
|
|
|
|
|
+ (db-property-handler/upsert-property! ident
|
|
|
|
|
+ {:logseq.property/type ent-type
|
|
|
|
|
+ :db/cardinality (if (and (not ent-type-str?) value-multi?) :many :one)}
|
|
|
|
|
+ {})
|
|
|
|
|
+ #(value-handle ent-type ent-multi?))))))
|
|
|
|
|
|
|
|
(defn save-db-based-block-properties!
|
|
(defn save-db-based-block-properties!
|
|
|
([block properties] (save-db-based-block-properties! block properties nil))
|
|
([block properties] (save-db-based-block-properties! block properties nil))
|
|
|
([block properties ^js plugin]
|
|
([block properties ^js plugin]
|
|
|
(when-let [block-id (and (seq properties) (:db/id block))]
|
|
(when-let [block-id (and (seq properties) (:db/id block))]
|
|
|
(let [properties (update-keys properties
|
|
(let [properties (update-keys properties
|
|
|
- (fn [k]
|
|
|
|
|
- (let [prefix (resolve-property-prefix-for-db plugin)]
|
|
|
|
|
- (get-db-ident-for-user-property-name k prefix))))
|
|
|
|
|
|
|
+ (fn [k]
|
|
|
|
|
+ (let [prefix (resolve-property-prefix-for-db plugin)]
|
|
|
|
|
+ (get-db-ident-for-user-property-name k prefix))))
|
|
|
*properties-page-refs (volatile! {})]
|
|
*properties-page-refs (volatile! {})]
|
|
|
(-> (for [ident (keys properties)]
|
|
(-> (for [ident (keys properties)]
|
|
|
(p/let [ret (infer-property-value-type-to-save! ident (get properties ident))]
|
|
(p/let [ret (infer-property-value-type-to-save! ident (get properties ident))]
|
|
|
ret))
|
|
ret))
|
|
|
- (p/all)
|
|
|
|
|
- (p/chain
|
|
|
|
|
- (fn [props]
|
|
|
|
|
- (->> props
|
|
|
|
|
- (reduce (fn [a [k v vs multi?]]
|
|
|
|
|
- (if multi?
|
|
|
|
|
- (do (vswap! *properties-page-refs assoc k vs) a)
|
|
|
|
|
- (assoc a k v))) {})
|
|
|
|
|
- (db-property-handler/set-block-properties! block-id)))
|
|
|
|
|
|
|
+ (p/all)
|
|
|
|
|
+ (p/chain
|
|
|
|
|
+ (fn [props]
|
|
|
|
|
+ (->> props
|
|
|
|
|
+ (reduce (fn [a [k v vs multi?]]
|
|
|
|
|
+ (if multi?
|
|
|
|
|
+ (do (vswap! *properties-page-refs assoc k vs) a)
|
|
|
|
|
+ (assoc a k v))) {})
|
|
|
|
|
+ (db-property-handler/set-block-properties! block-id)))
|
|
|
;; handle page refs
|
|
;; handle page refs
|
|
|
- (fn []
|
|
|
|
|
- (when (seq @*properties-page-refs)
|
|
|
|
|
- (doseq [[ident refs] @*properties-page-refs]
|
|
|
|
|
- (-> (property-handler/remove-block-property! (state/get-current-repo) block-id ident)
|
|
|
|
|
- (p/then
|
|
|
|
|
- (fn []
|
|
|
|
|
- (if (seq refs)
|
|
|
|
|
- (ui-outliner-tx/transact!
|
|
|
|
|
- {:outliner-op :set-block-properties}
|
|
|
|
|
- (doseq [eid refs]
|
|
|
|
|
- (when (number? eid)
|
|
|
|
|
- (property-handler/set-block-property!
|
|
|
|
|
|
|
+ (fn []
|
|
|
|
|
+ (when (seq @*properties-page-refs)
|
|
|
|
|
+ (doseq [[ident refs] @*properties-page-refs]
|
|
|
|
|
+ (-> (property-handler/remove-block-property! (state/get-current-repo) block-id ident)
|
|
|
|
|
+ (p/then
|
|
|
|
|
+ (fn []
|
|
|
|
|
+ (if (seq refs)
|
|
|
|
|
+ (ui-outliner-tx/transact!
|
|
|
|
|
+ {:outliner-op :set-block-properties}
|
|
|
|
|
+ (doseq [eid refs]
|
|
|
|
|
+ (when (number? eid)
|
|
|
|
|
+ (property-handler/set-block-property!
|
|
|
(state/get-current-repo) block-id ident eid))))
|
|
(state/get-current-repo) block-id ident eid))))
|
|
|
- (db-property-handler/set-block-property! block-id ident :logseq.property/empty-placeholder))))))))))))))
|
|
|
|
|
|
|
+ (db-property-handler/set-block-property! block-id ident :logseq.property/empty-placeholder))))))))))))))
|
|
|
|
|
|
|
|
(defn <sync-children-blocks!
|
|
(defn <sync-children-blocks!
|
|
|
[block]
|
|
[block]
|
|
|
(when block
|
|
(when block
|
|
|
(db-async/<get-block (state/get-current-repo)
|
|
(db-async/<get-block (state/get-current-repo)
|
|
|
- (:block/uuid (:block/parent block)) {:children? true})))
|
|
|
|
|
|
|
+ (:block/uuid (:block/parent block)) {:children? true})))
|
|
|
|
|
|
|
|
(defn get_block
|
|
(defn get_block
|
|
|
[id-or-uuid ^js opts]
|
|
[id-or-uuid ^js opts]
|
|
@@ -190,19 +190,19 @@
|
|
|
(db-utils/pull id-or-uuid)
|
|
(db-utils/pull id-or-uuid)
|
|
|
(and id-or-uuid (db-model/query-block-by-uuid (sdk-utils/uuid-or-throw-error id-or-uuid))))]
|
|
(and id-or-uuid (db-model/query-block-by-uuid (sdk-utils/uuid-or-throw-error id-or-uuid))))]
|
|
|
(when (or (true? (some-> opts (.-includePage)))
|
|
(when (or (true? (some-> opts (.-includePage)))
|
|
|
- (not (contains? block :block/name)))
|
|
|
|
|
|
|
+ (not (contains? block :block/name)))
|
|
|
(when-let [uuid (:block/uuid block)]
|
|
(when-let [uuid (:block/uuid block)]
|
|
|
(let [{:keys [includeChildren]} (bean/->clj opts)
|
|
(let [{:keys [includeChildren]} (bean/->clj opts)
|
|
|
repo (state/get-current-repo)
|
|
repo (state/get-current-repo)
|
|
|
block (if includeChildren
|
|
block (if includeChildren
|
|
|
;; nested children results
|
|
;; nested children results
|
|
|
(let [blocks (->> (db-model/get-block-and-children repo uuid)
|
|
(let [blocks (->> (db-model/get-block-and-children repo uuid)
|
|
|
- (map (fn [b]
|
|
|
|
|
- (dissoc (db-utils/pull (:db/id b)) :block.temp/load-status))))]
|
|
|
|
|
|
|
+ (map (fn [b]
|
|
|
|
|
+ (dissoc (db-utils/pull (:db/id b)) :block.temp/load-status))))]
|
|
|
(first (outliner-tree/blocks->vec-tree blocks uuid)))
|
|
(first (outliner-tree/blocks->vec-tree blocks uuid)))
|
|
|
;; attached shallow children
|
|
;; attached shallow children
|
|
|
(assoc block :block/children
|
|
(assoc block :block/children
|
|
|
- (map #(list :uuid (:block/uuid %))
|
|
|
|
|
- (db/get-block-immediate-children repo uuid))))
|
|
|
|
|
|
|
+ (map #(list :uuid (:block/uuid %))
|
|
|
|
|
+ (db/get-block-immediate-children repo uuid))))
|
|
|
block (into-properties repo block)]
|
|
block (into-properties repo block)]
|
|
|
(bean/->js (sdk-utils/normalize-keyword-for-json block)))))))
|
|
(bean/->js (sdk-utils/normalize-keyword-for-json block)))))))
|