diff --git a/deps/outliner/src/logseq/outliner/tree.cljs b/deps/outliner/src/logseq/outliner/tree.cljs index 9c1417559..fa7bcbdaf 100644 --- a/deps/outliner/src/logseq/outliner/tree.cljs +++ b/deps/outliner/src/logseq/outliner/tree.cljs @@ -22,9 +22,11 @@ (let [id (:db/id m) children (-> (block-children id (inc level)) (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)))] (block-children root-id 1))) diff --git a/src/main/logseq/api/block.cljs b/src/main/logseq/api/block.cljs index 54f9f3601..9bc3e5f2f 100644 --- a/src/main/logseq/api/block.cljs +++ b/src/main/logseq/api/block.cljs @@ -108,17 +108,17 @@ (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))))] (when (or (true? (some-> opts (.-includePage))) - (not (contains? block :block/name))) + (not (contains? block :block/name))) (when-let [uuid (:block/uuid block)] (let [{:keys [includeChildren]} (bean/->clj opts) repo (state/get-current-repo) block (if includeChildren ;; 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 (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)] (bean/->js (sdk-utils/normalize-keyword-for-json block))))))) diff --git a/src/main/logseq/sdk/utils.cljs b/src/main/logseq/sdk/utils.cljs index 83ce185de..c8f3d3da8 100644 --- a/src/main/logseq/sdk/utils.cljs +++ b/src/main/logseq/sdk/utils.cljs @@ -6,27 +6,32 @@ [goog.object :as gobj] [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 ([input] (normalize-keyword-for-json input true)) ([input camel-case?] (when input (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)] (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 [s] @@ -56,4 +61,4 @@ (def ^:export jsx-to-clj jsx->clj) (def ^:export to-js bean/->js) (def ^:export to-keyword keyword) -(def ^:export to-symbol symbol) \ No newline at end of file +(def ^:export to-symbol symbol)