mirror of
https://github.com/logseq/logseq.git
synced 2026-04-24 14:14:55 +00:00
enhance(apis): enhance createTag function to accept options for custom UUID
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user