Tienson Qin il y a 1 an
Parent
commit
b0c03b0003

+ 5 - 3
deps/outliner/src/logseq/outliner/tree.cljs

@@ -22,9 +22,11 @@
                                 (let [id (:db/id m)
                                 (let [id (:db/id m)
                                       children (-> (block-children id (inc level))
                                       children (-> (block-children id (inc level))
                                                    (ldb/sort-by-order))]
                                                    (ldb/sort-by-order))]
-                                  (assoc m
-                                         :block/level level
-                                         :block/children children)))
+                                  (->
+                                   (assoc m
+                                          :block/level level
+                                          :block/children children)
+                                   (dissoc :block/parent :block/tx-id))))
                               (sort-fn parent)))]
                               (sort-fn parent)))]
     (block-children root-id 1)))
     (block-children root-id 1)))
 
 

+ 5 - 5
src/main/logseq/api/block.cljs

@@ -108,17 +108,17 @@
                      (db-utils/pull id-or-uuid)
                      (db-utils/pull id-or-uuid)
                      (and id-or-uuid (db-model/query-block-by-uuid (sdk-utils/uuid-or-throw-error id-or-uuid))))]
                      (and id-or-uuid (db-model/query-block-by-uuid (sdk-utils/uuid-or-throw-error id-or-uuid))))]
     (when (or (true? (some-> opts (.-includePage)))
     (when (or (true? (some-> opts (.-includePage)))
-            (not (contains? block :block/name)))
+              (not (contains? block :block/name)))
       (when-let [uuid (:block/uuid block)]
       (when-let [uuid (:block/uuid block)]
         (let [{:keys [includeChildren]} (bean/->clj opts)
         (let [{:keys [includeChildren]} (bean/->clj opts)
               repo (state/get-current-repo)
               repo (state/get-current-repo)
               block (if includeChildren
               block (if includeChildren
                       ;; nested children results
                       ;; nested children results
-                      (first (outliner-tree/blocks->vec-tree
-                               (db-model/get-block-and-children repo uuid) uuid))
+                      (let [blocks (db-model/get-block-and-children repo uuid)]
+                        (first (outliner-tree/blocks->vec-tree blocks uuid)))
                       ;; attached shallow children
                       ;; attached shallow children
                       (assoc block :block/children
                       (assoc block :block/children
-                        (map #(list :uuid (:block/uuid %))
-                          (db/get-block-immediate-children repo uuid))))
+                             (map #(list :uuid (:block/uuid %))
+                                  (db/get-block-immediate-children repo uuid))))
               block (into-properties repo block)]
               block (into-properties repo block)]
           (bean/->js (sdk-utils/normalize-keyword-for-json block)))))))
           (bean/->js (sdk-utils/normalize-keyword-for-json block)))))))

+ 18 - 13
src/main/logseq/sdk/utils.cljs

@@ -6,27 +6,32 @@
             [goog.object :as gobj]
             [goog.object :as gobj]
             [cljs-bean.core :as bean]))
             [cljs-bean.core :as bean]))
 
 
-(defn- entity? [e]
-  (when e (instance? de/Entity e)))
+(defn- entity->map
+  "Convert a db Entity to a map"
+  [e]
+  (assert (de/entity? e))
+  (assoc (into {} e) :db/id (:db/id e)))
 
 
 (defn normalize-keyword-for-json
 (defn normalize-keyword-for-json
   ([input] (normalize-keyword-for-json input true))
   ([input] (normalize-keyword-for-json input true))
   ([input camel-case?]
   ([input camel-case?]
    (when input
    (when input
      (let [input (cond
      (let [input (cond
-                   (entity? input) (into {} input)
-                   (sequential? input) (map #(if (entity? %) (into {} %) %) input)
+                   (de/entity? input) (entity->map input)
+                   (sequential? input) (map #(if (de/entity? %)
+                                               (entity->map %)
+                                               %) input)
                    :else input)]
                    :else input)]
        (walk/postwalk
        (walk/postwalk
-         (fn [a]
-           (cond
-             (keyword? a)
-             (cond-> (name a)
-               camel-case?
-               (csk/->camelCase))
+        (fn [a]
+          (cond
+            (keyword? a)
+            (cond-> (name a)
+              camel-case?
+              (csk/->camelCase))
 
 
-             (uuid? a) (str a)
-             :else a)) input)))))
+            (uuid? a) (str a)
+            :else a)) input)))))
 
 
 (defn uuid-or-throw-error
 (defn uuid-or-throw-error
   [s]
   [s]
@@ -56,4 +61,4 @@
 (def ^:export jsx-to-clj jsx->clj)
 (def ^:export jsx-to-clj jsx->clj)
 (def ^:export to-js bean/->js)
 (def ^:export to-js bean/->js)
 (def ^:export to-keyword keyword)
 (def ^:export to-keyword keyword)
-(def ^:export to-symbol symbol)
+(def ^:export to-symbol symbol)