Explorar el Código

enhances(apis): add apis for retrieving tags by name

charlie hace 1 mes
padre
commit
2d2a44e6b6
Se han modificado 3 ficheros con 10 adiciones y 0 borrados
  1. 1 0
      libs/src/LSPlugin.ts
  2. 1 0
      src/main/logseq/api.cljs
  3. 8 0
      src/main/logseq/api/db_based.cljs

+ 1 - 0
libs/src/LSPlugin.ts

@@ -771,6 +771,7 @@ export interface IEditorProxy extends Record<string, any> {
   getTagObjects: (nameOrIdent: string) => Promise<BlockEntity[] | null>
   createTag: (tagName: string, opts?: Partial<{ uuid: string }>) => Promise<PageEntity | null>
   getTag: (nameOrIdent: string | EntityID) => Promise<PageEntity | null>
+  getTagsByName: (tagName: string) => Promise<Array<PageEntity> | null>
   addTagProperty: (tagId: BlockIdentity, propertyIdOrName: BlockIdentity) => Promise<void>
   removeTagProperty: (tagId: BlockIdentity, propertyIdOrName: BlockIdentity) => Promise<void>
   addTagExtends: (tagId: BlockIdentity, parentTagIdOrName: BlockIdentity) => Promise<void>

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

@@ -204,6 +204,7 @@
 (def ^:export get_tag_objects db-based-api/get-tag-objects)
 (def ^:export create_tag db-based-api/create-tag)
 (def ^:export get_tag db-based-api/get-tag)
+(def ^:export get_tags_by_name db-based-api/get-tags-by-name)
 (def ^:export add_tag_extends db-based-api/add-tag-extends)
 (def ^:export remove_tag_extends db-based-api/remove-tag-extends)
 (def ^:export add_block_tag db-based-api/add-block-tag)

+ 8 - 0
src/main/logseq/api/db_based.cljs

@@ -7,6 +7,7 @@
             [clojure.walk :as walk]
             [datascript.core :as d]
             [frontend.db :as db]
+            [frontend.db.conn :as db-conn]
             [frontend.db.async :as db-async]
             [frontend.db.model :as db-model]
             [frontend.handler.common.page :as page-common-handler]
@@ -17,6 +18,7 @@
             [frontend.modules.layout.core]
             [frontend.state :as state]
             [frontend.util :as util]
+            [logseq.db.frontend.entity-util :as entity-util]
             [goog.object :as gobj]
             [logseq.api.block :as api-block]
             [logseq.db :as ldb]
@@ -272,6 +274,12 @@
       (when (ldb/class? tag)
         (sdk-utils/result->js tag)))))
 
+(defn get-tags-by-name [name]
+  (when-let [tags (some->> (entity-util/get-pages-by-name (db-conn/get-db) name)
+                           (map #(some-> % (first) (db/entity)))
+                           (filter ldb/class?))]
+    (sdk-utils/result->js tags)))
+
 (defn tag-add-property [tag-id property-id-or-name]
   (p/let [tag (db/get-case-page tag-id)
           property (db/get-case-page property-id-or-name)]