1
0
Эх сурвалжийг харах

fix: copy block properties doesn't work

Fixes LOG-3160
Tienson Qin 1 жил өмнө
parent
commit
71dc122a75

+ 9 - 20
deps/db/src/logseq/db.cljs

@@ -87,27 +87,16 @@
   [blocks]
   [blocks]
   (sort-by :block/order blocks))
   (sort-by :block/order blocks))
 
 
-;; TODO: use the tree directly
-(defn flatten-tree
-  [blocks-tree]
-  (if-let [children (:block/_parent blocks-tree)]
-    (cons (dissoc blocks-tree :block/_parent) (mapcat flatten-tree children))
-    [blocks-tree]))
-
-;; TODO: performance enhance
+(defn- get-block-and-children-aux
+  [entity]
+  (if-let [children (:block/_parent entity)]
+    (cons (dissoc entity :block/_parent) (mapcat get-block-and-children-aux children))
+    [entity]))
+
 (defn get-block-and-children
 (defn get-block-and-children
-  [repo db block-uuid]
-  (some-> (d/q
-           '[:find [(pull ?block ?block-attrs) ...]
-             :in $ ?id ?block-attrs
-             :where
-             [?block :block/uuid ?id]]
-           db
-           block-uuid
-           block-attrs)
-          first
-          flatten-tree
-          (->> (map #(db-content/update-block-content repo db % (:db/id %))))))
+  [db block-uuid]
+  (when-let [e (d/entity db [:block/uuid block-uuid])]
+    (get-block-and-children-aux e)))
 
 
 (defn whiteboard-page?
 (defn whiteboard-page?
   "Given a page entity or map, check if it is a whiteboard page"
   "Given a page entity or map, check if it is a whiteboard page"

+ 1 - 1
deps/db/src/logseq/db/frontend/entity_plus.cljc

@@ -76,7 +76,7 @@
 
 
      IMap
      IMap
      (-dissoc [this k]
      (-dissoc [this k]
-       (assert (keyword? k) "attribute must be keyword")
+       (assert (keyword? k) (str "attribute must be keyword: " k))
        (set! (.-kv this) (dissoc (.-kv this) k))
        (set! (.-kv this) (dissoc (.-kv this) k))
        this)
        this)
 
 

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

@@ -114,19 +114,20 @@
                 children (ldb/sort-by-order (get @parent-groups parent-id))
                 children (ldb/sort-by-order (get @parent-groups parent-id))
                 _ (swap! parent-groups #(dissoc % parent-id))
                 _ (swap! parent-groups #(dissoc % parent-id))
                 sorted-nested-children (when (not-empty children) (sort-blocks-aux children parent-groups))]
                 sorted-nested-children (when (not-empty children) (sort-blocks-aux children parent-groups))]
-                    (if sorted-nested-children [parent sorted-nested-children] [parent])))
+            (if sorted-nested-children [parent sorted-nested-children] [parent])))
         parents))
         parents))
 
 
+;; Do we still need this?
 (defn ^:api sort-blocks
 (defn ^:api sort-blocks
-  "sort blocks by parent & left"
+  "sort blocks by parent & order"
   [blocks-exclude-root root]
   [blocks-exclude-root root]
   (let [parent-groups (atom (group-by :block/parent blocks-exclude-root))]
   (let [parent-groups (atom (group-by :block/parent blocks-exclude-root))]
     (flatten (concat (sort-blocks-aux [root] parent-groups) (vals @parent-groups)))))
     (flatten (concat (sort-blocks-aux [root] parent-groups) (vals @parent-groups)))))
 
 
 (defn get-sorted-block-and-children
 (defn get-sorted-block-and-children
-  [repo db db-id]
+  [db db-id]
   (when db-id
   (when db-id
-    (when-let [root-block (d/pull db '[*]  db-id)]
-      (let [blocks (ldb/get-block-and-children repo db (:block/uuid root-block))
+    (when-let [root-block (d/entity db db-id)]
+      (let [blocks (ldb/get-block-and-children db (:block/uuid root-block))
             blocks-exclude-root (remove (fn [b] (= (:db/id b) db-id)) blocks)]
             blocks-exclude-root (remove (fn [b] (= (:db/id b) db-id)) blocks)]
         (sort-blocks blocks-exclude-root root-block)))))
         (sort-blocks blocks-exclude-root root-block)))))

+ 1 - 1
src/main/frontend/db/model.cljs

@@ -417,7 +417,7 @@ independent of format as format specific heading characters are stripped"
 (defn get-block-and-children
 (defn get-block-and-children
   [repo block-uuid]
   [repo block-uuid]
   (let [db (conn/get-db repo)]
   (let [db (conn/get-db repo)]
-    (ldb/get-block-and-children repo db block-uuid)))
+    (ldb/get-block-and-children db block-uuid)))
 
 
 (defn get-file-page
 (defn get-file-page
   ([file-path]
   ([file-path]

+ 1 - 0
src/main/frontend/handler/editor.cljs

@@ -2072,6 +2072,7 @@
                 (ui-outliner-tx/transact!
                 (ui-outliner-tx/transact!
                  {:outliner-op :save-block}
                  {:outliner-op :save-block}
                  (outliner-save-block! editing-block)))
                  (outliner-save-block! editing-block)))
+            _ (state/clear-edit!)
             result (ui-outliner-tx/transact!
             result (ui-outliner-tx/transact!
                     {:outliner-op :insert-blocks
                     {:outliner-op :insert-blocks
                      :additional-tx revert-cut-txs}
                      :additional-tx revert-cut-txs}

+ 1 - 1
src/main/frontend/modules/outliner/tree.cljs

@@ -21,4 +21,4 @@
 (defn get-sorted-block-and-children
 (defn get-sorted-block-and-children
   [repo db-id]
   [repo db-id]
   (let [db (db/get-db repo)]
   (let [db (db/get-db repo)]
-    (otree/get-sorted-block-and-children repo db db-id)))
+    (otree/get-sorted-block-and-children db db-id)))

+ 4 - 2
src/main/frontend/util.cljc

@@ -27,7 +27,8 @@
             [rum.core :as rum]
             [rum.core :as rum]
             [clojure.core.async :as async]
             [clojure.core.async :as async]
             [frontend.pubsub :as pubsub]
             [frontend.pubsub :as pubsub]
-            [frontend.worker.util :as worker-util]))
+            [frontend.worker.util :as worker-util]
+            [datascript.impl.entity :as de]))
   #?(:cljs (:import [goog.async Debouncer]))
   #?(:cljs (:import [goog.async Debouncer]))
   (:require
   (:require
    [clojure.pprint]
    [clojure.pprint]
@@ -819,7 +820,8 @@
 #?(:cljs
 #?(:cljs
    (defn copy-to-clipboard!
    (defn copy-to-clipboard!
      [text & {:keys [graph html blocks owner-window]}]
      [text & {:keys [graph html blocks owner-window]}]
-     (let [data (clj->js
+     (let [blocks (map (fn [block] (if (de/entity? block) (into {} block) block)) blocks)
+           data (clj->js
                  (common-util/remove-nils-non-nested
                  (common-util/remove-nils-non-nested
                   {:text text
                   {:text text
                    :html html
                    :html html

+ 1 - 1
src/main/frontend/worker/export.cljs

@@ -14,7 +14,7 @@
                        (if (ldb/page? (d/entity db [:block/uuid root-block-uuid]))
                        (if (ldb/page? (d/entity db [:block/uuid root-block-uuid]))
                          0
                          0
                          1))
                          1))
-        blocks (ldb/get-block-and-children repo db root-block-uuid)
+        blocks (ldb/get-block-and-children db root-block-uuid)
         tree (otree/blocks->vec-tree repo db blocks (str root-block-uuid))]
         tree (otree/blocks->vec-tree repo db blocks (str root-block-uuid))]
     (worker-file/tree->file-content repo db tree
     (worker-file/tree->file-content repo db tree
                                     (assoc tree->file-opts :init-level init-level)
                                     (assoc tree->file-opts :init-level init-level)