|
|
@@ -6,7 +6,8 @@
|
|
|
[logseq.outliner.core :as outliner-core]
|
|
|
[frontend.modules.outliner.ui :as ui-outliner-tx]
|
|
|
[frontend.state :as state]
|
|
|
- [logseq.common.util :as common-util]))
|
|
|
+ [logseq.common.util :as common-util]
|
|
|
+ [promesa.core :as p]))
|
|
|
|
|
|
(defn insert-property
|
|
|
[format content key value & args]
|
|
|
@@ -23,48 +24,49 @@
|
|
|
"col: a collection of [block-id property-key property-value]."
|
|
|
[col]
|
|
|
(let [col' (group-by first col)]
|
|
|
- (ui-outliner-tx/transact!
|
|
|
- {:outliner-op :save-block}
|
|
|
- (doseq [[block-id items] col']
|
|
|
- (let [block-id (if (string? block-id) (uuid block-id) block-id)
|
|
|
- new-properties (zipmap (map second items)
|
|
|
- (map last items))]
|
|
|
- (when-let [block (db/entity [:block/uuid block-id])]
|
|
|
- (let [format (:block/format block)
|
|
|
- content (:block/content block)
|
|
|
- properties (:block/properties block)
|
|
|
- properties-text-values (:block/properties-text-values block)
|
|
|
- properties (-> (merge properties new-properties)
|
|
|
- common-util/remove-nils-non-nested)
|
|
|
- properties-text-values (-> (merge properties-text-values new-properties)
|
|
|
- common-util/remove-nils-non-nested)
|
|
|
- property-ks (->> (concat (:block/properties-order block)
|
|
|
- (map second items))
|
|
|
- (filter (set (keys properties)))
|
|
|
- distinct
|
|
|
- vec)
|
|
|
- content (property-util/remove-properties format content)
|
|
|
- kvs (for [key property-ks] [key (or (get properties-text-values key)
|
|
|
- (get properties key))])
|
|
|
- content (property-util/insert-properties format content kvs)
|
|
|
- content (property-util/remove-empty-properties content)
|
|
|
- block {:block/uuid block-id
|
|
|
- :block/properties properties
|
|
|
- :block/properties-order property-ks
|
|
|
- :block/properties-text-values properties-text-values
|
|
|
- :block/content content}]
|
|
|
- (outliner-core/save-block! (state/get-current-repo) (db/get-db false)
|
|
|
- (state/get-date-formatter)
|
|
|
- block)))))))
|
|
|
- (let [block-id (ffirst col)
|
|
|
- block-id (if (string? block-id) (uuid block-id) block-id)
|
|
|
- input-pos (or (state/get-edit-pos) :max)]
|
|
|
+ (p/do!
|
|
|
+ (ui-outliner-tx/transact!
|
|
|
+ {:outliner-op :save-block}
|
|
|
+ (doseq [[block-id items] col']
|
|
|
+ (let [block-id (if (string? block-id) (uuid block-id) block-id)
|
|
|
+ new-properties (zipmap (map second items)
|
|
|
+ (map last items))]
|
|
|
+ (when-let [block (db/entity [:block/uuid block-id])]
|
|
|
+ (let [format (:block/format block)
|
|
|
+ content (:block/content block)
|
|
|
+ properties (:block/properties block)
|
|
|
+ properties-text-values (:block/properties-text-values block)
|
|
|
+ properties (-> (merge properties new-properties)
|
|
|
+ common-util/remove-nils-non-nested)
|
|
|
+ properties-text-values (-> (merge properties-text-values new-properties)
|
|
|
+ common-util/remove-nils-non-nested)
|
|
|
+ property-ks (->> (concat (:block/properties-order block)
|
|
|
+ (map second items))
|
|
|
+ (filter (set (keys properties)))
|
|
|
+ distinct
|
|
|
+ vec)
|
|
|
+ content (property-util/remove-properties format content)
|
|
|
+ kvs (for [key property-ks] [key (or (get properties-text-values key)
|
|
|
+ (get properties key))])
|
|
|
+ content (property-util/insert-properties format content kvs)
|
|
|
+ content (property-util/remove-empty-properties content)
|
|
|
+ block {:block/uuid block-id
|
|
|
+ :block/properties properties
|
|
|
+ :block/properties-order property-ks
|
|
|
+ :block/properties-text-values properties-text-values
|
|
|
+ :block/content content}]
|
|
|
+ (outliner-core/save-block! (state/get-current-repo) (db/get-db false)
|
|
|
+ (state/get-date-formatter)
|
|
|
+ block))))))
|
|
|
+ (let [block-id (ffirst col)
|
|
|
+ block-id (if (string? block-id) (uuid block-id) block-id)
|
|
|
+ input-pos (or (state/get-edit-pos) :max)]
|
|
|
;; update editing input content
|
|
|
- (when-let [editing-block (state/get-edit-block)]
|
|
|
- (when (= (:block/uuid editing-block) block-id)
|
|
|
- (block-handler/edit-block! editing-block
|
|
|
- input-pos
|
|
|
- (state/get-edit-input-id))))))
|
|
|
+ (when-let [editing-block (state/get-edit-block)]
|
|
|
+ (when (= (:block/uuid editing-block) block-id)
|
|
|
+ (block-handler/edit-block! editing-block
|
|
|
+ input-pos
|
|
|
+ (state/get-edit-input-id))))))))
|
|
|
|
|
|
(defn batch-set-block-property!
|
|
|
[block-ids property-key property-value]
|