Skip to content

Commit

Permalink
improve(plugin): add sibling block api & types
Browse files Browse the repository at this point in the history
  • Loading branch information
xyhp915 committed Jun 3, 2021
1 parent ba1cc8f commit 166561d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/logseq/api.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[frontend.handler.block :as block-handler]
[frontend.handler.editor :as editor-handler]
[frontend.handler.dnd :as editor-dnd-handler]
[frontend.modules.outliner.core :as outliner]
[frontend.modules.outliner.tree :as outliner-tree]
[frontend.util :as util]
[electron.ipc :as ipc]
Expand Down Expand Up @@ -245,6 +246,19 @@
block (if (not includeChildren) block (first (outliner-tree/blocks->vec-tree [block] uuid)))]
(bean/->js (normalize-keyword-for-json block)))))))

(def ^:export get_previous_sibling_block
(fn [uuid]
(when-let [block (db-model/query-block-by-uuid uuid)]
(let [{:block/keys [parent left]} block
block (if-not (= parent left) (db-utils/pull (:db/id left)))]
(and block (bean/->js (normalize-keyword-for-json block)))))))

(def ^:export get_next_sibling_block
(fn [uuid]
(when-let [block (db-model/query-block-by-uuid uuid)]
(when-let [right-siblings (outliner/get-right-siblings (outliner/->Block block))]
(bean/->js (normalize-keyword-for-json (:data (first right-siblings))))))))

(def ^:export upsert_block_property
(fn [block-uuid key value]
(editor-handler/set-block-property! (medley/uuid block-uuid) key value)))
Expand Down

0 comments on commit 166561d

Please sign in to comment.