0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-13 16:21:57 -05:00

🐛 Detach a shape when moving it out of a component

This commit is contained in:
Andrés Moya 2021-01-18 11:42:29 +01:00 committed by Andrey Antukh
parent bde62473a4
commit f3d5515795
2 changed files with 25 additions and 6 deletions

View file

@ -222,7 +222,24 @@
(d/dissoc-in [pid :remote-synced?])))))))))
(update-parent-id [objects id]
(update objects id assoc :parent-id parent-id))
(update objects id
(fn [object]
(let [prev-component-root (cph/get-root-shape object objects)
detach-component (fn [object]
(let [new-component-root
(cph/get-root-shape object objects)]
(cond-> object
(not= prev-component-root new-component-root)
(dissoc object
:component-id
:component-file
:component-root?
:remote-synced?
:shape-ref
:touched))))]
(-> object
(assoc :parent-id parent-id)
detach-component)))))
;; Updates the frame-id references that might be outdated
(assign-frame-id [frame-id objects id]

View file

@ -36,11 +36,13 @@
(defn get-root-shape
"Get the root shape linked to a component for this shape, if any"
[shape objects]
(if (:component-id shape)
shape
(if-let [parent-id (:parent-id shape)]
(get-root-shape (get objects parent-id) objects)
nil)))
(if-not (:shape-ref shape)
nil
(if (:component-id shape)
shape
(if-let [parent-id (:parent-id shape)]
(get-root-shape (get objects parent-id) objects)
nil))))
(defn make-container
[page-or-component type]