소스 검색

Enhance: APIs related issues (#10782)

* fix(plugins): load unpacked package for the existed plugin

* enhance(plugin): increase timeout time for the plugin handshake

* enhance(api): support option to insert block with auto ordered list

* fix(api): skip empty target for the batch insertion blocks

* fix(api): before option for the batch blocks insertion

* enhance(api): types

* chore: bump minor version

* fix(apis): Empty `payload.uuid` when executing onMacroRendererSlotted inside query table
Charlie 1 년 전
부모
커밋
7db164ab47

+ 1 - 1
libs/package.json

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

+ 1 - 1
libs/src/LSPlugin.caller.ts

@@ -286,7 +286,7 @@ class LSPluginCaller extends EventEmitter {
       timer = setTimeout(() => {
         reject(new Error(`handshake Timeout`))
         pt.destroy()
-      }, 4 * 1000) // 4 secs
+      }, 8 * 1000) // 8 secs
 
       handshake
         .then((refChild: ParentAPI) => {

+ 4 - 6
libs/src/LSPlugin.core.ts

@@ -384,14 +384,14 @@ function convertToLSPResource(fullUrl: string, dotPluginRoot: string) {
 class IllegalPluginPackageError extends Error {
   constructor(message: string) {
     super(message)
-    this.name = IllegalPluginPackageError.name
+    this.name = 'IllegalPluginPackageError'
   }
 }
 
 class ExistedImportedPluginPackageError extends Error {
   constructor(message: string) {
     super(message)
-    this.name = ExistedImportedPluginPackageError.name
+    this.name = 'ExistedImportedPluginPackageError'
   }
 }
 
@@ -409,7 +409,7 @@ class PluginLocal extends EventEmitter<
   private _localRoot?: string
   private _dotSettingsFile?: string
   private _caller?: LSPluginCaller
-  private _logger?: PluginLogger
+  private _logger?: PluginLogger = new PluginLogger('PluginLocal')
 
   /**
    * @param _options
@@ -595,9 +595,7 @@ class PluginLocal extends EventEmitter<
     // Validate id
     const { registeredPlugins, isRegistering } = this._ctx
     if (isRegistering && registeredPlugins.has(this.id)) {
-      throw new ExistedImportedPluginPackageError(
-        'Registered plugin package Error'
-      )
+      throw new ExistedImportedPluginPackageError(this.id)
     }
 
     return async () => {

+ 9 - 1
libs/src/LSPlugin.ts

@@ -141,7 +141,7 @@ export interface AppUserInfo {
 export interface AppInfo {
   version: string
 
-  [key: string]: any
+  [key: string]: unknown
 }
 
 /**
@@ -159,6 +159,8 @@ export interface AppUserConfigs {
   showBracket: boolean
   enabledFlashcards: boolean
   enabledJournals: boolean
+
+  [key: string]: unknown
 }
 
 /**
@@ -168,6 +170,8 @@ export interface AppGraphInfo {
   name: string
   url: string
   path: string
+
+  [key: string]: unknown
 }
 
 /**
@@ -193,6 +197,8 @@ export interface BlockEntity {
   meta?: { timestamps: any; properties: any; startPos: number; endPos: number }
   title?: Array<any>
   marker?: string
+
+  [key: string]: unknown
 }
 
 /**
@@ -212,6 +218,8 @@ export interface PageEntity {
   format?: 'markdown' | 'org'
   journalDay?: number
   updatedAt?: number
+
+  [key: string]: unknown
 }
 
 export type BlockIdentity = BlockUUID | Pick<BlockEntity, 'uuid'>

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
resources/js/lsplugin.core.js


+ 8 - 8
src/main/frontend/components/plugins.cljs

@@ -119,14 +119,14 @@
   (rum/use-effect!
     (fn []
       (let [err-handle
-                       (fn [^js e]
-                         (case (keyword (aget e "name"))
-                           :IllegalPluginPackageError
-                           (notification/show! "Illegal Logseq plugin package." :error)
-                           :ExistedImportedPluginPackageError
-                           (notification/show! "Existed Imported plugin package." :error)
-                           :default)
-                         (plugin-handler/reset-unpacked-state))
+            (fn [^js e]
+              (case (keyword (aget e "name"))
+                :IllegalPluginPackageError
+                (notification/show! "Illegal Logseq plugin package." :error)
+                :ExistedImportedPluginPackageError
+                (notification/show! (str "Existed plugin package (" (.-message e) ").") :error)
+                :default)
+              (plugin-handler/reset-unpacked-state))
             reg-handle #(plugin-handler/reset-unpacked-state)]
         (when unpacked-pkg-path
           (doto js/LSPluginCore

+ 3 - 3
src/main/frontend/components/query_table.cljs

@@ -181,7 +181,7 @@
           result-as-text (for [row sort-result]
                            (for [column columns]
                              (build-column-text row column)))
-          render-column-value (fn [row-format cell-format value]
+          render-column-value (fn [row-block row-format cell-format value]
                                 (cond
                                   ;; elements should be rendered as they are provided
                                   (= :element cell-format) value
@@ -194,7 +194,7 @@
                                   ;; inline-text when no page entity is found
                                   (string? value) (if-let [page (db/entity [:block/name (util/page-name-sanity-lc value)])]
                                                     (page-cp {} page)
-                                                    (inline-text row-format value))
+                                                    (inline-text row-block row-format value))
                                   ;; anything else should just be rendered as provided
                                   :else value))]
 
@@ -237,4 +237,4 @@
                                                                 :block-ref)
                                                                (reset! *mouse-down? false)))}
                        (when value
-                         (apply render-column-value format value))]))]))]]]))))
+                         (apply render-column-value row format value))]))]))]]]))))

+ 20 - 13
src/main/frontend/handler/editor.cljs

@@ -425,7 +425,7 @@
 
 (declare save-current-block!)
 (defn outliner-insert-block!
-  [config current-block new-block {:keys [sibling? keep-uuid?
+  [config current-block new-block {:keys [sibling? keep-uuid? ordered-list?
                                           replace-empty-target?]}]
   (let [ref-query-top-block? (and (or (:ref? config)
                                       (:custom-query? config))
@@ -446,9 +446,11 @@
     (outliner-tx/transact!
      {:outliner-op :insert-blocks}
      (save-current-block! {:current-block current-block})
-     (outliner-core/insert-blocks! [new-block] current-block {:sibling? sibling?
-                                                              :keep-uuid? keep-uuid?
-                                                              :replace-empty-target? replace-empty-target?}))))
+      (outliner-core/insert-blocks! [new-block] current-block
+        {:sibling?              sibling?
+         :keep-uuid?            keep-uuid?
+         :replace-empty-target? replace-empty-target?
+         :ordered-list? ordered-list?}))))
 
 (defn- block-self-alone-when-insert?
   [config uuid]
@@ -566,7 +568,7 @@
 
 (defn api-insert-new-block!
   [content {:keys [page block-uuid sibling? before? properties
-                   custom-uuid replace-empty-target? edit-block?]
+                   custom-uuid replace-empty-target? edit-block? ordered-list?]
             :or {sibling? false
                  before? false
                  edit-block? true}}]
@@ -626,9 +628,11 @@
                                    :else
                                    nil)]
           (when block-m
-            (outliner-insert-block! {} block-m new-block {:sibling? sibling?
-                                                          :keep-uuid? true
-                                                          :replace-empty-target? replace-empty-target?})
+            (outliner-insert-block! {} block-m new-block
+              {:sibling?              sibling?
+               :keep-uuid?            true
+               :replace-empty-target? replace-empty-target?
+               :ordered-list? ordered-list?})
             (when edit-block?
               (if (and replace-empty-target?
                        (string/blank? (:block/content last-block)))
@@ -2020,7 +2024,8 @@
                   target-block
                   sibling?
                   keep-uuid?
-                  revert-cut-txs]
+                  revert-cut-txs
+                  skip-empty-target?]
            :or {exclude-properties []}}]
   (state/set-editor-op! :paste-blocks)
   (let [editing-block (when-let [editing-block (state/get-edit-block)]
@@ -2033,7 +2038,8 @@
         block (db/entity (:db/id target-block))
         page (if (:block/name block) block
                  (when target-block (:block/page (db/entity (:db/id target-block)))))
-        empty-target? (string/blank? (:block/content target-block))
+        empty-target? (if (true? skip-empty-target?) false
+                        (string/blank? (:block/content target-block)))
         paste-nested-blocks? (nested-blocks blocks)
         target-block-has-children? (db/has-children? (:block/uuid target-block))
         replace-empty-target? (and empty-target?
@@ -2117,9 +2123,10 @@
    A block element: {:content :properties :children [block-1, block-2, ...]}"
   [target-block-id sibling? tree-vec format keep-uuid?]
   (insert-block-tree tree-vec format
-                     {:target-block (db/pull target-block-id)
-                      :keep-uuid?   keep-uuid?
-                      :sibling?     sibling?}))
+    {:target-block       (db/pull target-block-id)
+     :keep-uuid?         keep-uuid?
+     :skip-empty-target? true
+     :sibling?           sibling?}))
 
 (defn insert-template!
   ([element-id db-id]

+ 2 - 2
src/main/frontend/handler/plugin.cljs

@@ -773,8 +773,8 @@
                                                             (when (and (number? end)
                                                                        ;; valid end time
                                                                        (> end 0)
-                                                                       ;; greater than 3s
-                                                                       (> (- end (.-s v)) 3000))
+                                                                       ;; greater than 6s
+                                                                       (> (- end (.-s v)) 6000))
                                                               v))))
                                                       ((fn [perfs]
                                                          (doseq [perf perfs]

+ 3 - 2
src/main/frontend/modules/outliner/core.cljs

@@ -531,7 +531,7 @@
       `replace-empty-target?`: If the `target-block` is an empty block, whether
                                to replace it, it defaults to be `false`.
     ``"
-  [blocks target-block {:keys [sibling? keep-uuid? outliner-op replace-empty-target?] :as opts}]
+  [blocks target-block {:keys [sibling? keep-uuid? outliner-op replace-empty-target? ordered-list?] :as opts}]
   {:pre [(seq blocks)
          (s/valid? ::block-map-or-entity target-block)]}
   (let [target-block' (get-target-block target-block)
@@ -549,7 +549,8 @@
                                      (> (count blocks) 1)
                                      (not move?)))
         blocks' (blocks-with-level blocks)
-        blocks' (blocks-with-ordered-list-props blocks' target-block sibling?)
+        blocks' (if (false? ordered-list?) blocks'
+                  (blocks-with-ordered-list-props blocks' target-block sibling?))
         blocks' (if (= outliner-op :paste)
                   (fix-top-level-blocks blocks')
                   blocks')

+ 22 - 19
src/main/logseq/api.cljs

@@ -604,7 +604,7 @@
   (fn [block-uuid-or-page-name content ^js opts]
     (when (string/blank? block-uuid-or-page-name)
       (throw (js/Error. "Page title or block UUID shouldn't be empty.")))
-    (let [{:keys [before sibling focus customUUID properties]} (bean/->clj opts)
+    (let [{:keys [before sibling focus customUUID properties autoOrderedList]} (bean/->clj opts)
           [page-name block-uuid] (if (util/uuid-string? block-uuid-or-page-name)
                                    [nil (uuid block-uuid-or-page-name)]
                                    [block-uuid-or-page-name nil])
@@ -635,31 +635,34 @@
                                    before?)
           new-block              (editor-handler/api-insert-new-block!
                                    content
-                                   {:block-uuid  block-uuid'
-                                    :sibling?    sibling?
-                                    :before?     before?
-                                    :edit-block? edit-block?
-                                    :page        page-name
-                                    :custom-uuid custom-uuid
-                                    :properties  (merge properties
-                                                        (when custom-uuid {:id custom-uuid}))})]
+                                   {:block-uuid    block-uuid'
+                                    :sibling?      sibling?
+                                    :before?       before?
+                                    :edit-block?   edit-block?
+                                    :page          page-name
+                                    :custom-uuid   custom-uuid
+                                    :ordered-list? (if (boolean? autoOrderedList) autoOrderedList false)
+                                    :properties    (merge properties
+                                                     (when custom-uuid {:id custom-uuid}))})]
       (bean/->js (sdk-utils/normalize-keyword-for-json new-block)))))
 
 (def ^:export insert_batch_block
   (fn [block-uuid ^js batch-blocks ^js opts]
     (when-let [block (db-model/query-block-by-uuid (sdk-utils/uuid-or-throw-error block-uuid))]
       (when-let [bb (bean/->clj batch-blocks)]
-        (let [bb         (if-not (vector? bb) (vector bb) bb)
-              {:keys [sibling keepUUID]} (bean/->clj opts)
+        (let [bb (if-not (vector? bb) (vector bb) bb)
+              {:keys [sibling keepUUID before]} (bean/->clj opts)
               keep-uuid? (or keepUUID false)
-              _          (when keep-uuid? (doseq
-                                            [block (outliner/tree-vec-flatten bb :children)]
-                                            (let [uuid (:id (:properties block))]
-                                              (when (and uuid (db-model/query-block-by-uuid (sdk-utils/uuid-or-throw-error uuid)))
-                                                (throw (js/Error.
-                                                         (util/format "Custom block UUID already exists (%s)." uuid)))))))
-              _          (editor-handler/insert-block-tree-after-target
-                           (:db/id block) sibling bb (:block/format block) keep-uuid?)]
+              _ (when keep-uuid? (doseq
+                                  [block (outliner/tree-vec-flatten bb :children)]
+                                   (let [uuid (:id (:properties block))]
+                                     (when (and uuid (db-model/query-block-by-uuid (sdk-utils/uuid-or-throw-error uuid)))
+                                       (throw (js/Error.
+                                                (util/format "Custom block UUID already exists (%s)." uuid)))))))
+              block (if (and before sibling)
+                      (db/pull (:db/id (:block/left block))) block)
+              _ (editor-handler/insert-block-tree-after-target
+                  (:db/id block) sibling bb (:block/format block) keep-uuid?)]
           nil)))))
 
 (def ^:export remove_block

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.