mirror of
https://github.com/logseq/logseq.git
synced 2026-05-21 11:22:44 +00:00
enhance(api): set-block-properties! defaults not reset :many values
This commit is contained in:
@@ -116,7 +116,7 @@
|
||||
:else :default))
|
||||
|
||||
(defn- set-block-properties!
|
||||
[plugin block-id properties]
|
||||
[plugin block-id properties {:keys [reset-property-values]}]
|
||||
(ui-outliner-tx/transact!
|
||||
{:outliner-op :set-block-properties}
|
||||
(doseq [[property-id property-ident value schema] properties]
|
||||
@@ -164,7 +164,7 @@
|
||||
(ensure-property-upsert-control plugin property-ident property-id)
|
||||
(outliner-op/upsert-property! property-ident schema' {:property-name property-id}))
|
||||
|
||||
(when (and property (or many? (nil? value'))) ; delete property from this block
|
||||
(when (and property (or (and many? reset-property-values) (nil? value'))) ; delete property from this block
|
||||
(outliner-op/remove-block-property! block-id property-ident))
|
||||
|
||||
(let [set-property! (fn [value]
|
||||
@@ -175,14 +175,14 @@
|
||||
(set-property! value)))))))
|
||||
|
||||
(defn db-based-save-block-properties!
|
||||
[block properties & {:keys [plugin schema]}]
|
||||
[block properties & {:keys [plugin schema reset-property-values]}]
|
||||
(when-let [block-id (and (seq properties) (:db/id block))]
|
||||
(let [properties (->> properties
|
||||
(map (fn [[k v]]
|
||||
(let [ident (get-db-ident-from-property-name k plugin)
|
||||
property-schema (get schema k)]
|
||||
[k ident v property-schema]))))]
|
||||
(set-block-properties! plugin block-id properties))))
|
||||
(set-block-properties! plugin block-id properties {:reset-property-values reset-property-values}))))
|
||||
|
||||
(defn <sync-children-blocks!
|
||||
[block]
|
||||
|
||||
@@ -85,7 +85,8 @@
|
||||
(when (seq (:properties opts))
|
||||
(api-block/db-based-save-block-properties! block (:properties opts)
|
||||
{:plugin this
|
||||
:schema (:schema opts)}))
|
||||
:schema (:schema opts)
|
||||
:reset-property-values (:reset-property-values opts)}))
|
||||
(editor-handler/save-block! repo
|
||||
(sdk-utils/uuid-or-throw-error block-uuid) content
|
||||
(dissoc opts :properties))))))
|
||||
@@ -168,10 +169,11 @@
|
||||
(page-common-handler/<delete! uuid nil nil)))))
|
||||
|
||||
(defn upsert-block-property
|
||||
[this block key' value schema]
|
||||
[this block key' value {:keys [schema reset-property-values]}]
|
||||
(let [opts {:plugin this
|
||||
:schema (when schema
|
||||
{key schema})}]
|
||||
{key schema})
|
||||
:reset-property-values reset-property-values}]
|
||||
(api-block/db-based-save-block-properties! block {key' value} opts)))
|
||||
|
||||
(defn get-all-tags
|
||||
|
||||
@@ -133,10 +133,10 @@
|
||||
:journal? journal
|
||||
:class? class
|
||||
:format format}
|
||||
(string? customUUID)
|
||||
(assoc :uuid (uuid customUUID))
|
||||
(not db-based?)
|
||||
(assoc :properties properties))))
|
||||
(string? customUUID)
|
||||
(assoc :uuid (uuid customUUID))
|
||||
(not db-based?)
|
||||
(assoc :properties properties))))
|
||||
_ (when (and db-based? (seq properties))
|
||||
(api-block/db-based-save-block-properties! new-page properties {:plugin this
|
||||
:schema schema}))]
|
||||
@@ -479,7 +479,7 @@
|
||||
value (bean/->clj value)]
|
||||
(when block
|
||||
(if db-based?
|
||||
(db-based-api/upsert-block-property this block key' value (:schema opts))
|
||||
(db-based-api/upsert-block-property this block key' value opts)
|
||||
(property-handler/set-block-property! repo block-uuid key' value))))))
|
||||
|
||||
(defn remove_block_property
|
||||
|
||||
Reference in New Issue
Block a user