浏览代码

allow indent a block to a linked page

Tienson Qin 2 年之前
父节点
当前提交
ecfed114f5
共有 1 个文件被更改,包括 13 次插入7 次删除
  1. 13 7
      src/main/frontend/modules/outliner/core.cljs

+ 13 - 7
src/main/frontend/modules/outliner/core.cljs

@@ -612,11 +612,17 @@
                  blocks)))
 
 (defn- get-target-block
-  [target-block]
-  (if (:db/id target-block)
-    (db/pull (:db/id target-block))
-    (when (:block/uuid target-block)
-      (db/pull [:block/uuid (:block/uuid target-block)]))))
+  [target-block sibling?]
+  (when-let [block (if (:db/id target-block)
+                     (db/entity (:db/id target-block))
+                     (when (:block/uuid target-block)
+                       (db/entity [:block/uuid (:block/uuid target-block)])))]
+    (if-let [linked (:block/link block)]
+      (let [last-child (some-> (db-model/get-block-last-direct-child (conn/get-db) (:db/id linked))
+                               db/entity)
+            target (or last-child linked)]
+        [target (if last-child true false)])
+      [block sibling?])))
 
 (defn insert-blocks
   "Insert blocks as children (or siblings) of target-node.
@@ -635,7 +641,7 @@
   [blocks target-block {:keys [sibling? keep-uuid? outliner-op replace-empty-target?] :as opts}]
   {:pre [(seq blocks)
          (s/valid? ::block-map-or-entity target-block)]}
-  (let [target-block' (get-target-block target-block)
+  (let [[target-block' sibling?] (get-target-block target-block sibling?)
         _ (assert (some? target-block') (str "Invalid target: " target-block))
         sibling? (if (page-block? target-block') false sibling?)
         move? (contains? #{:move-blocks :move-blocks-up-down :indent-outdent-blocks} outliner-op)
@@ -819,7 +825,7 @@
   [blocks target-block {:keys [sibling? outliner-op]}]
   [:pre [(seq blocks)
          (s/valid? ::block-map-or-entity target-block)]]
-  (let [target-block (get-target-block target-block)
+  (let [[target-block sibling?] (get-target-block target-block sibling?)
         _ (assert (some? target-block) (str "Invalid target: " target-block))
         non-consecutive-blocks? (seq (db-model/get-non-consecutive-blocks blocks))
         original-position? (move-to-original-position? blocks target-block sibling? non-consecutive-blocks?)]