소스 검색

improve(plugin): add sibling block api & types

charlie 4 년 전
부모
커밋
166561d98f
1개의 변경된 파일14개의 추가작업 그리고 0개의 파일을 삭제
  1. 14 0
      src/main/logseq/api.cljs

+ 14 - 0
src/main/logseq/api.cljs

@@ -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]
@@ -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)))