🐛 Launch component sync when adding or removing shapes

This commit is contained in:
Andrés Moya 2023-05-18 11:28:51 +02:00
parent 36b016a37b
commit 19ea85d9cc
2 changed files with 38 additions and 6 deletions

View file

@ -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)