فهرست منبع

fix(plugin): incorrect normalize data case for the hashmap value

charlie 1 سال پیش
والد
کامیت
e05dc085a2
3فایلهای تغییر یافته به همراه10 افزوده شده و 8 حذف شده
  1. 1 1
      libs/src/LSPlugin.ts
  2. 8 6
      src/main/logseq/api.cljs
  3. 1 1
      src/main/logseq/sdk/utils.cljs

+ 1 - 1
libs/src/LSPlugin.ts

@@ -810,7 +810,7 @@ export interface IEditorProxy extends Record<string, any> {
   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

+ 8 - 6
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/<get-block (state/get-current-repo) block-uuid :children? false)
             db? (config/db-based-graph? (state/get-current-repo))
@@ -930,13 +930,15 @@
             _ (db-async/<get-block (state/get-current-repo) block-uuid :children? false)]
       (when-let [block (db-model/get-block-by-uuid block-uuid)]
         (let [properties (:block/properties block)
-              key (sanitize-user-property-key key)
+              key (sanitize-user-property-name key)
               property-name (-> (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]

+ 1 - 1
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)))))