🐛 Fix synchronization when adding a subcomponent to a instance

This commit is contained in:
Andrés Moya 2020-12-03 14:18:03 +01:00 committed by Andrey Antukh
parent b4246c2869
commit e9714c4fd0
4 changed files with 16 additions and 9 deletions

View file

@ -764,8 +764,8 @@
:frame-id frame-id :frame-id frame-id
:parent-id parent-id :parent-id parent-id
:id id)] :id id)]
(if (and (contains? objects parent-id) (if (and (or (nil? parent-id) (contains? objects parent-id))
(contains? objects frame-id)) (or (nil? frame-id) (contains? objects frame-id)))
(-> data (-> data
(update :objects assoc id obj) (update :objects assoc id obj)
(update-in [:objects parent-id :shapes] (update-in [:objects parent-id :shapes]

View file

@ -10,8 +10,9 @@
(ns app.common.pages-helpers (ns app.common.pages-helpers
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.uuid :as uuid] [app.common.geom.shapes :as gsh]
[app.common.geom.shapes :as gsh])) [app.common.spec :as us]
[app.common.uuid :as uuid]))
(defn walk-pages (defn walk-pages
"Go through all pages of a file and apply a function to each one" "Go through all pages of a file and apply a function to each one"
@ -48,7 +49,7 @@
(defn page? (defn page?
[container] [container]
(assert (some? (:type container))) (us/assert some? (:type container))
(= (:type container) :page)) (= (:type container) :page))
(defn component? (defn component?
@ -246,6 +247,7 @@
(let [child-id (first child-ids) (let [child-id (first child-ids)
child (get objects child-id) child (get objects child-id)
_ (us/assert some? child)
[new-child new-child-objects updated-child-objects] [new-child new-child-objects updated-child-objects]
(clone-object child new-id objects update-new-object update-original-object)] (clone-object child new-id objects update-new-object update-original-object)]

View file

@ -664,8 +664,13 @@
root-instance)] root-instance)]
(cond-> new-shape (cond-> new-shape
true true
(assoc :shape-ref (:id original-shape) (assoc :frame-id (:frame-id parent-shape))
:frame-id (:frame-id parent-shape))
(nil? (:shape-ref original-shape))
(assoc :shape-ref (:id original-shape))
(some? (:shape-ref original-shape))
(assoc :shape-ref (:shape-ref original-shape))
(:component-id original-shape) (:component-id original-shape)
(assoc :component-id (:component-id original-shape)) (assoc :component-id (:component-id original-shape))
@ -685,7 +690,7 @@
[new-shape new-shapes _] [new-shape new-shapes _]
(cph/clone-object component-shape (cph/clone-object component-shape
(:id parent-shape) (:id parent-shape)
(get container :objects) (get component :objects)
update-new-shape update-new-shape
update-original-shape) update-original-shape)

View file

@ -148,7 +148,7 @@
(when component-file (str/format "<%s> " (:name component-file))) (when component-file (str/format "<%s> " (:name component-file)))
(:name component))))))))] (:name component))))))))]
(println "[Workspace]") (println "[Page]")
(show-shape (:id root) 0 objects) (show-shape (:id root) 0 objects)
(dorun (for [component (vals components)] (dorun (for [component (vals components)]