Преглед изворни кода

fix: data-refs and data-ref-self

Tienson Qin пре 4 година
родитељ
комит
189d6b2862
2 измењених фајлова са 12 додато и 20 уклоњено
  1. 8 12
      src/main/frontend/components/block.cljs
  2. 4 8
      src/main/frontend/modules/outliner/tree.cljs

+ 8 - 12
src/main/frontend/components/block.cljs

@@ -1713,17 +1713,12 @@
    :on-mouse-leave (fn [e]
                      (block-mouse-leave e has-child? *control-show? block-id doc-mode?))})
 
-(defn- get-data-refs-and-self
-  [block refs-with-children]
+(defn- build-refs-data-value
+  [block refs]
   (let [refs (model/get-page-names-by-ids
-              (->> (map :db/id refs-with-children)
-                   (remove nil?)))
-        data-refs (text/build-data-value refs)
-        refs (model/get-page-names-by-ids
-              (->> (map :db/id (:block/ref-pages block))
-                   (remove nil?)))
-        data-refs-self (text/build-data-value refs)]
-    [data-refs data-refs-self]))
+              (->> (map :db/id refs)
+                   (remove nil?)))]
+    (text/build-data-value refs)))
 
 ;; (rum/defc block-immediate-children < rum/reactive
 ;;   [repo config uuid ref? collapsed?]
@@ -1749,7 +1744,7 @@
    :should-update (fn [old-state new-state]
                     (not= (:block/content (second (:rum/args old-state)))
                           (:block/content (second (:rum/args new-state)))))}
-  [state config {:block/keys [uuid title body meta content dummy? page format repo children pre-block? top? properties refs-with-children heading-level level type] :as block}]
+  [state config {:block/keys [uuid title body meta content dummy? page format repo children pre-block? top? properties refs path-refs heading-level level type] :as block}]
   (let [blocks-container-id (:blocks-container-id config)
         heading? (and (= type :heading) heading-level (<= heading-level 6))
         *control-show? (get state ::control-show?)
@@ -1769,7 +1764,8 @@
                      (or (seq children)
                          (seq body))))
         attrs (on-drag-and-mouse-attrs block uuid top? block-id *move-to-top? has-child? *control-show? doc-mode?)
-        [data-refs data-refs-self] (get-data-refs-and-self block refs-with-children)]
+        data-refs (build-refs-data-value block (remove (set refs) path-refs))
+        data-refs-self (build-refs-data-value block refs)]
     [:div.ls-block.flex.flex-col.rounded-sm
      (cond->
       {:id block-id

+ 4 - 8
src/main/frontend/modules/outliner/tree.cljs

@@ -33,13 +33,9 @@
     (reset! blocks (remove (set children) @blocks))
     children))
 
-(defn- with-children-and-refs
+(defn- with-children
   [block children]
-  (let [all-refs (->> (mapcat :block/refs children)
-                      (distinct))]
-    (assoc block
-           :block/children children
-           :block/refs-with-children all-refs)))
+  (assoc block :block/children children))
 
 (defn- blocks->vec-tree-aux
   [blocks root]
@@ -48,7 +44,7 @@
      (get-children blocks root)
      (map (fn [block]
             (let [children (blocks->vec-tree-aux blocks block)]
-              (with-children-and-refs block children)))))))
+              (with-children block children)))))))
 
 (defn- get-root-and-page
   [root-id]
@@ -74,7 +70,7 @@
 
       :else                             ; include root block
       (let [root-block (some #(when (= (:db/id %) (:db/id root)) %) @blocks)
-            root-block (with-children-and-refs root-block result)]
+            root-block (with-children root-block result)]
         [root-block]))))
 
 (defn- sort-blocks-aux