Skip to content

Commit

Permalink
improve(plugin): api of get_block with shallow children uuid results
Browse files Browse the repository at this point in the history
  • Loading branch information
xyhp915 authored and tiensonqin committed Jan 28, 2022
1 parent 7d01d5d commit 67c99e0
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/main/logseq/api.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -369,16 +369,6 @@
(fn []
(state/get-edit-content)))

(def ^:export get_current_block
(fn []
(let [block (state/get-edit-block)
block (or block (some-> (first (:selection/blocks @state/state))
(.getAttribute "blockid")
(db-model/get-block-by-uuid)))
block (or block (state/get-last-edit-block))
block (and block (db-utils/pull (:db/id block)))]
(bean/->js (normalize-keyword-for-json block)))))

(def ^:export get_selected_blocks
(fn []
(when-let [blocks (and (state/in-selection-mode?)
Expand Down Expand Up @@ -510,11 +500,25 @@
(when-let [uuid (:block/uuid block)]
(let [{:keys [includeChildren]} (bean/->clj opts)
repo (state/get-current-repo)
block (if (not includeChildren)
block (first (outliner-tree/blocks->vec-tree
(db-model/get-block-and-children repo uuid) uuid)))]
block (if includeChildren
;; nested children results
(first (outliner-tree/blocks->vec-tree
(db-model/get-block-and-children repo uuid) uuid))
;; attached shallow children
(assoc block :block/children
(map #(list :uuid (get-in % [:data :block/uuid]))
(outliner/get-children uuid))))]
(bean/->js (normalize-keyword-for-json block))))))))

(def ^:export get_current_block
(fn [^js opts]
(let [block (state/get-edit-block)
block (or block (some-> (first (:selection/blocks @state/state))
(.getAttribute "blockid")
(db-model/get-block-by-uuid)))
block (or block (state/get-last-edit-block))]
(get_block (:db/id block) opts))))

(def ^:export get_previous_sibling_block
(fn [uuid]
(when-let [block (db-model/query-block-by-uuid uuid)]
Expand Down

0 comments on commit 67c99e0

Please sign in to comment.