Skip to content

Commit bd4b022

Browse files
committed
enhance(apis): enhance createTag function to accept options for custom UUID
1 parent fa407c1 commit bd4b022

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

libs/src/LSPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ export interface IEditorProxy extends Record<string, any> {
780780
getAllTags: () => Promise<PageEntity[] | null>
781781
getAllProperties: () => Promise<PageEntity[] | null>
782782
getTagObjects: (PageIdentity) => Promise<BlockEntity[] | null>
783-
createTag: (tagName: string) => Promise<PageEntity | null>
783+
createTag: (tagName: string, opts?: Partial<{ uuid: string }>) => Promise<PageEntity | null>
784784
addTagProperty: (tagId: BlockIdentity, propertyIdOrName: BlockIdentity) => Promise<void>
785785
removeTagProperty: (tagId: BlockIdentity, propertyIdOrName: BlockIdentity) => Promise<void>
786786
addBlockTag: (blockId: BlockIdentity, tagId: BlockIdentity) => Promise<void>

src/main/logseq/api/db_based.cljs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,17 @@
204204
(:db/id class))]
205205
(sdk-utils/result->js result)))))
206206

207-
(defn create-tag [title]
208-
(p/let [repo (state/get-current-repo)
209-
tag (db-page-handler/<create-class! title {:redirect? false})
210-
tag (db-async/<get-block repo (:db/id tag) {:children? false})]
211-
(when tag
212-
(sdk-utils/result->js tag))))
207+
(defn create-tag [title ^js opts]
208+
(let [opts (bean/->clj opts)]
209+
(p/let [repo (state/get-current-repo)
210+
tag (db-page-handler/<create-class!
211+
title
212+
(-> opts
213+
(sdk-utils/with-custom-uuid)
214+
(assoc :redirect? false)))
215+
tag (db-async/<get-block repo (:db/id tag) {:children? false})]
216+
(when tag
217+
(sdk-utils/result->js tag)))))
213218

214219
(defn tag-add-property [tag-id property-id-or-name]
215220
(p/let [tag (db/get-page tag-id)

src/main/logseq/sdk/utils.cljs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@
101101
normalize-keyword-for-json
102102
bean/->js))
103103

104+
(defn with-custom-uuid [opts]
105+
(let [custom-uuid (or (:customUUID opts) (:uuid opts))]
106+
(cond-> opts
107+
(util/uuid-string? custom-uuid)
108+
(assoc :uuid (uuid custom-uuid)))))
109+
104110
(def ^:export to-clj bean/->clj)
105111
(def ^:export jsx-to-clj jsx->clj)
106112
(def ^:export to-js bean/->js)

0 commit comments

Comments
 (0)