Răsfoiți Sursa

enhance(api): block related types

charlie 1 an în urmă
părinte
comite
bdfda0b9db
2 a modificat fișierele cu 18 adăugiri și 13 ștergeri
  1. 9 4
      libs/src/LSPlugin.ts
  2. 9 9
      src/main/logseq/api.cljs

+ 9 - 4
libs/src/LSPlugin.ts

@@ -180,14 +180,17 @@ export interface AppGraphInfo {
 export interface BlockEntity {
 export interface BlockEntity {
   id: EntityID // db id
   id: EntityID // db id
   uuid: BlockUUID
   uuid: BlockUUID
-  left: IEntityID
+  order: string
   format: 'markdown' | 'org'
   format: 'markdown' | 'org'
   parent: IEntityID
   parent: IEntityID
   content: string
   content: string
   page: IEntityID
   page: IEntityID
+  createdAt: number
+  updatedAt: number
   properties?: Record<string, any>
   properties?: Record<string, any>
 
 
   // optional fields in dummy page
   // optional fields in dummy page
+  left?: IEntityID
   anchor?: string
   anchor?: string
   body?: any
   body?: any
   children?: Array<BlockEntity | BlockUUIDTuple>
   children?: Array<BlockEntity | BlockUUIDTuple>
@@ -770,7 +773,9 @@ export interface IEditorProxy extends Record<string, any> {
     srcBlock: BlockIdentity
     srcBlock: BlockIdentity
   ) => Promise<BlockEntity | null>
   ) => Promise<BlockEntity | null>
 
 
-  getNextSiblingBlock: (srcBlock: BlockIdentity) => Promise<BlockEntity | null>
+  getNextSiblingBlock: (
+    srcBlock: BlockIdentity
+  ) => Promise<BlockEntity | null>
 
 
   moveBlock: (
   moveBlock: (
     srcBlock: BlockIdentity,
     srcBlock: BlockIdentity,
@@ -791,9 +796,9 @@ export interface IEditorProxy extends Record<string, any> {
 
 
   removeBlockProperty: (block: BlockIdentity, key: string) => Promise<void>
   removeBlockProperty: (block: BlockIdentity, key: string) => Promise<void>
 
 
-  getBlockProperty: (block: BlockIdentity, key: string) => Promise<any>
+  getBlockProperty: (block: BlockIdentity, key: string) => Promise<BlockEntity | string| null>
 
 
-  getBlockProperties: (block: BlockIdentity) => Promise<any>
+  getBlockProperties: (block: BlockIdentity) => Promise<Record<string, any> | null>
 
 
   scrollToBlockInPage: (
   scrollToBlockInPage: (
     pageName: BlockPageName,
     pageName: BlockPageName,

+ 9 - 9
src/main/logseq/api.cljs

@@ -755,24 +755,24 @@
       (get_block (:block/uuid block) opts))))
       (get_block (:block/uuid block) opts))))
 
 
 (def ^:export get_previous_sibling_block
 (def ^:export get_previous_sibling_block
-  (fn [block-uuid]
+  (fn [block-uuid ^js opts]
     (p/let [id (sdk-utils/uuid-or-throw-error block-uuid)
     (p/let [id (sdk-utils/uuid-or-throw-error block-uuid)
             block (<pull-block id)
             block (<pull-block id)
             ;; Load all children blocks
             ;; Load all children blocks
             _ (db-async/<get-block (state/get-current-repo) (:block/uuid (:block/parent block)) {:children? true})]
             _ (db-async/<get-block (state/get-current-repo) (:block/uuid (:block/parent block)) {:children? true})]
       (when block
       (when block
-        (when-let [left-sibling (ldb/get-left-sibling (db/entity (:db/id block)))]
-          (let [block (db/pull (:db/id left-sibling))]
-            (bean/->js (sdk-utils/normalize-keyword-for-json block))))))))
+        (when-let [sibling (ldb/get-left-sibling (db/entity (:db/id block)))]
+          (get_block (:block/uuid sibling) opts))))))
 
 
 (def ^:export get_next_sibling_block
 (def ^:export get_next_sibling_block
-  (fn [block-uuid]
+  (fn [block-uuid ^js opts]
     (p/let [id (sdk-utils/uuid-or-throw-error block-uuid)
     (p/let [id (sdk-utils/uuid-or-throw-error block-uuid)
-            block (<pull-block id)]
+            block (<pull-block id)
+            ;; Load all children blocks
+            _ (db-async/<get-block (state/get-current-repo) (:block/uuid (:block/parent block)) {:children? true})]
       (when block
       (when block
-        (p/let [sibling (db-async/<get-right-sibling (state/get-current-repo) (:db/id block))]
-          (when sibling
-            (bean/->js (sdk-utils/normalize-keyword-for-json sibling))))))))
+        (p/let [sibling (ldb/get-right-sibling (db/entity (:db/id block)))]
+          (get_block (:block/uuid sibling) opts))))))
 
 
 (def ^:export set_block_collapsed
 (def ^:export set_block_collapsed
   (fn [block-uuid ^js opts]
   (fn [block-uuid ^js opts]