diff --git a/common/src/app/common/pages/changes.cljc b/common/src/app/common/pages/changes.cljc index df19f0829..4e4a429e5 100644 --- a/common/src/app/common/pages/changes.cljc +++ b/common/src/app/common/pages/changes.cljc @@ -27,7 +27,8 @@ [app.common.types.shape :as cts] [app.common.types.shape-tree :as ctst] [app.common.types.typographies-list :as ctyl] - [app.common.types.typography :as ctt])) + [app.common.types.typography :as ctt] + [clojure.set :as set])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; SCHEMAS @@ -665,7 +666,7 @@ (when page-id (let [page (ctpl/get-page file-data page-id) shape-and-parents (map #(ctn/get-shape page %) - (into [id] (cph/get-parent-ids (:objects page) id))) + (cons id (cph/get-parent-ids (:objects page) id))) need-sync? (fn [operation] ; We need to trigger a sync if the shape has changed any ; attribute that participates in components synchronization. @@ -677,6 +678,34 @@ (map :id))] (into #{} xform shape-and-parents)))))) +(defmethod components-changed :mov-objects + [file-data {:keys [page-id _component-id parent-id shapes] :as change}] + (when page-id + (let [page (ctpl/get-page file-data page-id) + + xform (comp (filter :main-instance?) + (map :id)) + + check-shape + (fn [shape-id others] + (let [all-parents (map (partial ctn/get-shape page) + (concat others (cph/get-parent-ids (:objects page) shape-id)))] + (into #{} xform all-parents)))] + + (reduce #(set/union %1 (check-shape %2 [])) + (check-shape parent-id [parent-id]) + shapes)))) + +(defmethod components-changed :del-obj + [file-data {:keys [id page-id _component-id] :as change}] + (when page-id + (let [page (ctpl/get-page file-data page-id) + shape-and-parents (map (partial ctn/get-shape page) + (cons id (cph/get-parent-ids (:objects page) id))) + xform (comp (filter :main-instance?) + (map :id))] + (into #{} xform shape-and-parents)))) + (defmethod components-changed :default [_ _] nil) diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index e86e83235..afb3fc7cc 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -871,7 +871,10 @@ workspace-data-s (->> (rx/concat (rx/of nil) - (rx/from-atom refs/workspace-data {:emit-current-value? true}))) + (rx/from-atom refs/workspace-data {:emit-current-value? true})) + ;; Need to get the file data before the change, so deleted shapes + ;; still exist, for example + (rx/buffer 3 1)) change-s (->> stream @@ -880,16 +883,16 @@ (rx/observe-on :async)) check-changes - (fn [[event data]] + (fn [[event [old-data _mid_data _new-data]]] (let [{:keys [changes save-undo? undo-group]} (deref event) - components-changed (reduce #(into %1 (ch/components-changed data %2)) + components-changed (reduce #(into %1 (ch/components-changed old-data %2)) #{} changes)] (when (and (d/not-empty? components-changed) save-undo?) (log/info :msg "DETECTED COMPONENTS CHANGED" :ids (map str components-changed)) (run! st/emit! - (map #(update-component-sync % (:id data) undo-group) + (map #(update-component-sync % (:id old-data) undo-group) components-changed)))))] (when components-v2