浏览代码

improve(plugin): api to create block uuid

charlie 3 年之前
父节点
当前提交
eb72f2e3c7
共有 3 个文件被更改,包括 12 次插入2 次删除
  1. 1 1
      libs/package.json
  2. 6 0
      libs/src/LSPlugin.ts
  3. 5 1
      libs/src/LSPlugin.user.ts

+ 1 - 1
libs/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@logseq/libs",
-  "version": "0.0.7",
+  "version": "0.0.8",
   "description": "Logseq SDK libraries",
   "main": "dist/lsplugin.user.js",
   "typings": "index.d.ts",

+ 6 - 0
libs/src/LSPlugin.ts

@@ -551,6 +551,12 @@ export interface IEditorProxy extends Record<string, any> {
     namespace: BlockPageName
   ) => Promise<Array<PageEntity> | null>
 
+  /**
+   * Create an uuid string for specific block id(uuid)
+   * @added 0.0.8
+   */
+  newBlockUUID: () => Promise<string>
+
   /**
    * @example https://github.com/logseq/logseq-plugin-samples/tree/master/logseq-reddit-hot-news
    *

+ 5 - 1
libs/src/LSPlugin.user.ts

@@ -189,6 +189,10 @@ const app: Partial<IAppProxy> = {
 let registeredCmdUid = 0
 
 const editor: Partial<IEditorProxy> = {
+  newBlockUUID(this: LSPluginUser): Promise<string> {
+    return this._execCallableAPIAsync('new_block_uuid')
+  },
+
   registerSlashCommand(
     this: LSPluginUser,
     tag: string,
@@ -273,7 +277,7 @@ const editor: Partial<IEditorProxy> = {
     } else {
       this.App.pushState('page', { name: pageName }, { anchor })
     }
-  },
+  }
 }
 
 const db: Partial<IDBProxy> = {