浏览代码

fix: Deleting embedded blocks deletes source material

close #1836 #1652
Tienson Qin 4 年之前
父节点
当前提交
4e333eb78e
共有 3 个文件被更改,包括 18 次插入9 次删除
  1. 2 1
      shadow-cljs.edn
  2. 7 2
      src/main/frontend/components/block.cljs
  3. 9 6
      src/main/frontend/handler/editor.cljs

+ 2 - 1
shadow-cljs.edn

@@ -37,7 +37,8 @@
     :http-root    "public"
     :http-root    "public"
     :http-port    3001
     :http-port    3001
     :watch-path   "static"
     :watch-path   "static"
-    :preloads     [devtools.preload]}}
+    :preloads     [devtools.preload
+                   shadow.remote.runtime.cljs.browser]}}
 
 
   :electron {:target :node-script
   :electron {:target :node-script
              :output-to "static/electron.js"
              :output-to "static/electron.js"

+ 7 - 2
src/main/frontend/components/block.cljs

@@ -658,7 +658,7 @@
 
 
     ["Block_reference" id]
     ["Block_reference" id]
     ;; FIXME: alert when self block reference
     ;; FIXME: alert when self block reference
-    (block-reference config id nil)
+    (block-reference (assoc config :reference? true) id nil)
 
 
     ["Nested_link" link]
     ["Nested_link" link]
     (nested-link config html-export? link)
     (nested-link config html-export? link)
@@ -1679,6 +1679,7 @@
         slide? (boolean (:slide? config))
         slide? (boolean (:slide? config))
         doc-mode? (:document/mode? config)
         doc-mode? (:document/mode? config)
         embed? (:embed? config)
         embed? (:embed? config)
+        reference? (:reference? config)
         unique-dom-id (build-id (dissoc config :block/uuid))
         unique-dom-id (build-id (dissoc config :block/uuid))
         block-id (str "ls-block-" unique-dom-id uuid)
         block-id (str "ls-block-" unique-dom-id uuid)
         has-child? (boolean
         has-child? (boolean
@@ -1701,8 +1702,12 @@
        :blockid (str uuid)
        :blockid (str uuid)
        :repo repo
        :repo repo
        :haschild (str has-child?)}
        :haschild (str has-child?)}
+
        (not slide?)
        (not slide?)
-       (merge attrs))
+       (merge attrs)
+
+       (or reference? embed?)
+       (assoc :data-transclude true))
 
 
      (when (and ref? breadcrumb-show?)
      (when (and ref? breadcrumb-show?)
        (when-let [comp (block-parents config repo uuid format false)]
        (when-let [comp (block-parents config repo uuid format false)]

+ 9 - 6
src/main/frontend/handler/editor.cljs

@@ -986,12 +986,15 @@
   [copy?]
   [copy?]
   (when copy? (copy-selection-blocks))
   (when copy? (copy-selection-blocks))
   (when-let [blocks (seq (get-selected-blocks-with-children))]
   (when-let [blocks (seq (get-selected-blocks-with-children))]
-    (let [repo (dom/attr (first blocks) "repo")
-          ids (distinct (map #(uuid (dom/attr % "blockid")) blocks))
-          ids (if (= :up (state/get-selection-direction))
-                (reverse ids)
-                ids)]
-      (delete-blocks! repo ids))))
+    ;; remove embeds and references
+    (let [blocks (remove (fn [block] (= "true" (dom/attr block "data-transclude"))) blocks)]
+      (when (seq blocks)
+        (let [repo (dom/attr (first blocks) "repo")
+             ids (distinct (map #(uuid (dom/attr % "blockid")) blocks))
+             ids (if (= :up (state/get-selection-direction))
+                   (reverse ids)
+                   ids)]
+         (delete-blocks! repo ids))))))
 
 
 (defn- get-nearest-page
 (defn- get-nearest-page
   []
   []