enhance(apis): enhance createTag function to accept options for custom UUID

This commit is contained in:
charlie
2025-11-06 15:46:31 +08:00
parent fa407c1564
commit bd4b022a08
3 changed files with 18 additions and 7 deletions

View File

@@ -780,7 +780,7 @@ export interface IEditorProxy extends Record<string, any> {
getAllTags: () => Promise<PageEntity[] | null>
getAllProperties: () => Promise<PageEntity[] | null>
getTagObjects: (PageIdentity) => Promise<BlockEntity[] | null>
createTag: (tagName: string) => Promise<PageEntity | null>
createTag: (tagName: string, opts?: Partial<{ uuid: string }>) => Promise<PageEntity | null>
addTagProperty: (tagId: BlockIdentity, propertyIdOrName: BlockIdentity) => Promise<void>
removeTagProperty: (tagId: BlockIdentity, propertyIdOrName: BlockIdentity) => Promise<void>
addBlockTag: (blockId: BlockIdentity, tagId: BlockIdentity) => Promise<void>

View File

@@ -204,12 +204,17 @@
(:db/id class))]
(sdk-utils/result->js result)))))
(defn create-tag [title]
(p/let [repo (state/get-current-repo)
tag (db-page-handler/<create-class! title {:redirect? false})
tag (db-async/<get-block repo (:db/id tag) {:children? false})]
(when tag
(sdk-utils/result->js tag))))
(defn create-tag [title ^js opts]
(let [opts (bean/->clj opts)]
(p/let [repo (state/get-current-repo)
tag (db-page-handler/<create-class!
title
(-> opts
(sdk-utils/with-custom-uuid)
(assoc :redirect? false)))
tag (db-async/<get-block repo (:db/id tag) {:children? false})]
(when tag
(sdk-utils/result->js tag)))))
(defn tag-add-property [tag-id property-id-or-name]
(p/let [tag (db/get-page tag-id)

View File

@@ -101,6 +101,12 @@
normalize-keyword-for-json
bean/->js))
(defn with-custom-uuid [opts]
(let [custom-uuid (or (:customUUID opts) (:uuid opts))]
(cond-> opts
(util/uuid-string? custom-uuid)
(assoc :uuid (uuid custom-uuid)))))
(def ^:export to-clj bean/->clj)
(def ^:export jsx-to-clj jsx->clj)
(def ^:export to-js bean/->js)