0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-13 10:38:13 -05:00

🐛 Maintain ids of main shapes to keep existing copies in sync

This commit is contained in:
Andrés Moya 2023-05-23 16:46:33 +02:00 committed by Alonso Torres
parent 61cad18bcc
commit 968dcefc28
3 changed files with 16 additions and 8 deletions

View file

@ -173,8 +173,8 @@
(make-component-instance container component library-data position components-v2 {}))
([container component library-data position components-v2
{:keys [main-instance? force-id force-frame-id]
:or {main-instance? false force-id nil force-frame-id nil}}]
{:keys [main-instance? force-id force-frame-id keep-ids?]
:or {main-instance? false force-id nil force-frame-id nil keep-ids? false}}]
(let [component-page (when components-v2
(ctpl/get-page library-data (:main-instance-page component)))
component-shape (if components-v2
@ -237,7 +237,8 @@
(if components-v2 (:objects component-page) (:objects component))
update-new-shape
(fn [object _] object)
force-id)
force-id
keep-ids?)
;; If frame-id points to a shape inside the component, remap it to the
;; corresponding new frame shape. If not, set it to the destination frame.

View file

@ -347,7 +347,8 @@
position
false
{:main-instance? true
:force-frame-id uuid/zero})
:force-frame-id uuid/zero
:keep-ids? true})
add-shapes
(fn [page]

View file

@ -329,13 +329,19 @@
the order of the children of each parent."
([object parent-id objects update-new-object]
(clone-object object parent-id objects update-new-object (fn [object _] object) nil))
(clone-object object parent-id objects update-new-object (fn [object _] object) nil false))
([object parent-id objects update-new-object update-original-object]
(clone-object object parent-id objects update-new-object update-original-object nil))
(clone-object object parent-id objects update-new-object update-original-object nil false))
([object parent-id objects update-new-object update-original-object force-id]
(let [new-id (or force-id (uuid/next))]
(clone-object object parent-id objects update-new-object update-original-object force-id false))
([object parent-id objects update-new-object update-original-object force-id keep-ids?]
(let [new-id (cond
(some? force-id) force-id
keep-ids? (:id object)
:else (uuid/next))]
(loop [child-ids (seq (:shapes object))
new-direct-children []
new-children []
@ -365,7 +371,7 @@
_ (dm/assert! (some? child))
[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 nil keep-ids?)]
(recur
(next child-ids)