diff --git a/common/src/app/common/pages/changes.cljc b/common/src/app/common/pages/changes.cljc index 96336e386..a6637d008 100644 --- a/common/src/app/common/pages/changes.cljc +++ b/common/src/app/common/pages/changes.cljc @@ -675,7 +675,7 @@ any-sync? (some need-sync? operations)] (when any-sync? (let [xform (comp (filter :main-instance?) ; Select shapes that are main component instances - (map :id))] + (map :component-id))] (into #{} xform shape-and-parents)))))) (defmethod components-changed :mov-objects @@ -684,7 +684,7 @@ (let [page (ctpl/get-page file-data page-id) xform (comp (filter :main-instance?) - (map :id)) + (map :component-id)) check-shape (fn [shape-id others] @@ -703,7 +703,7 @@ 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))] + (map :component-id))] (into #{} xform shape-and-parents)))) (defmethod components-changed :default diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 52fbef829..d47efe802 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -665,6 +665,22 @@ (sync-file file-id file-id :components (:component-id shape) undo-group)) (dwu/commit-undo-transaction undo-id))))))) +(defn launch-component-sync + "Launch a sync of the current file and of the library file of the given component." + ([component-id file-id] (launch-component-sync component-id file-id nil)) + ([component-id file-id undo-group] + (ptk/reify ::launch-component-sync + ptk/WatchEvent + (watch [_ state _] + (let [current-file-id (:current-file-id state) + undo-id (js/Symbol)] + (rx/of + (dwu/start-undo-transaction undo-id) + (sync-file current-file-id file-id :components component-id undo-group) + (when (not= current-file-id file-id) + (sync-file file-id file-id :components component-id undo-group)) + (dwu/commit-undo-transaction undo-id))))))) + (defn update-component-in-bulk [shapes file-id] (ptk/reify ::update-component-in-bulk @@ -897,7 +913,7 @@ :ids (map str components-changed) :undo-group undo-group) (run! st/emit! - (map #(update-component-sync % (:id old-data) undo-group) + (map #(launch-component-sync % (:id old-data) undo-group) components-changed))))))] (when components-v2