From e05dc085a20a97e22dc1c0db5430d4016d1997c7 Mon Sep 17 00:00:00 2001 From: charlie Date: Thu, 5 Sep 2024 20:12:29 +0800 Subject: [PATCH] fix(plugin): incorrect normalize data case for the hashmap value --- libs/src/LSPlugin.ts | 2 +- src/main/logseq/api.cljs | 14 ++++++++------ src/main/logseq/sdk/utils.cljs | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/libs/src/LSPlugin.ts b/libs/src/LSPlugin.ts index f18ae6b0d..e4027a37d 100644 --- a/libs/src/LSPlugin.ts +++ b/libs/src/LSPlugin.ts @@ -810,7 +810,7 @@ export interface IEditorProxy extends Record { upsertProperty: ( key: string, schema?: Partial<{ - type: 'default' | 'map' | 'keyword' | 'date' | 'checkbox' | string, + type: 'default' | 'map' | 'number' | 'keyword' | 'node' | 'date' | 'checkbox' | string, cardinality: 'many' | 'one', hide: boolean public: boolean diff --git a/src/main/logseq/api.cljs b/src/main/logseq/api.cljs index a9190e136..679b965bb 100644 --- a/src/main/logseq/api.cljs +++ b/src/main/logseq/api.cljs @@ -80,7 +80,7 @@ (defn- get-caller-plugin-id [] (gobj/get js/window "$$callerPluginID")) -(defn- sanitize-user-property-key +(defn- sanitize-user-property-name [k] (if (string? k) (-> k (string/trim) @@ -869,7 +869,7 @@ ;; properties (db only) (defn ^:export get_property [k] - (when-let [k' (and (string? k) (some-> k (sanitize-user-property-key) (keyword)))] + (when-let [k' (and (string? k) (some-> k (sanitize-user-property-name) (keyword)))] (p/let [k (if (qualified-keyword? k') k' (get-db-ident-for-property-name k)) p (db-utils/pull k)] (bean/->js (sdk-utils/normalize-keyword-for-json p))))) @@ -913,7 +913,7 @@ (def ^:export remove_block_property (fn [block-uuid key] - (p/let [key (sanitize-user-property-key key) + (p/let [key (sanitize-user-property-name key) block-uuid (sdk-utils/uuid-or-throw-error block-uuid) _ (db-async/ (if (keyword? key) (name key) key) (util/safe-lower-case)) property-value (or (get properties key) (get properties property-name) (get properties (get-db-ident-for-property-name property-name))) - property-value (if-let [property-id (:db/id property-value)] (db/pull property-id) property-value)] - (bean/->js (sdk-utils/normalize-keyword-for-json property-value))))))) + property-value (if-let [property-id (:db/id property-value)] + (db/pull property-id) property-value) + ret (sdk-utils/normalize-keyword-for-json property-value)] + (bean/->js ret)))))) (def ^:export get_block_properties (fn [block-uuid] diff --git a/src/main/logseq/sdk/utils.cljs b/src/main/logseq/sdk/utils.cljs index 7febcb795..9f9cb9795 100644 --- a/src/main/logseq/sdk/utils.cljs +++ b/src/main/logseq/sdk/utils.cljs @@ -42,7 +42,7 @@ ;; @FIXME compatible layer for classic APIs (and (map? a) (:block/uuid a)) - (some->> (:block/title a) (assoc a :block/content)) + (or (some->> (:block/title a) (assoc a :block/content)) a) :else a)) input)))))