0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-27 07:01:27 -05:00

🐛 Fix rmap shape refs on components v2 migration

This commit is contained in:
Alejandro Alonso 2024-02-15 10:57:52 +01:00 committed by Andrés Moya
parent 89b43d7127
commit d6b60ce43a

View file

@ -731,10 +731,10 @@
(fn [file-data]
;; Remap shape-refs so that they point to the near main.
;; At the same time, if there are any dangling ref, detach the shape and its children.
(letfn [(fix-container [container]
(reduce fix-shape container (ctn/shapes-seq container)))
(let [count (volatile! 0)
(fix-shape [container shape]
fix-shape
(fn [container shape]
(if (ctk/in-component-copy? shape)
;; First look for the direct shape.
(let [root (ctn/get-component-shape (:objects container) shape)
@ -750,7 +750,9 @@
(ctf/get-component-shapes (:data library) component))]
(if (some? near-shape)
;; If found, update the ref to point to the near shape.
(ctn/update-shape container (:id shape) #(assoc % :shape-ref (:id near-shape)))
(do
(vswap! count inc)
(ctn/update-shape container (:id shape) #(assoc % :shape-ref (:id near-shape))))
;; If not found, it may be a fostered component. Try to locate a direct shape
;; in the head component.
(let [head (ctn/get-head-shape (:objects container) shape)
@ -762,12 +764,28 @@
container
;; If not found, detach shape and all children.
;; container
(detach-shape container shape)))))))
container))]
(do
(vswap! count inc)
(detach-shape container shape))))))))
container))
(-> file-data
fix-container
(fn [container]
(reduce fix-shape container (ctn/shapes-seq container)))]
[(-> file-data
(update :pages-index update-vals fix-container)
(d/update-when :components update-vals fix-container))))
(d/update-when :components update-vals fix-container))
@count]))
remap-refs-recur
;; remapping refs can generate cascade changes so we call it until no changes are done
(fn [file-data]
(loop [f-data file-data]
(let [[f-data count] (remap-refs f-data)]
(if (= count 0)
f-data
(recur f-data)))))
fix-converted-copies
(fn [file-data]
@ -993,8 +1011,8 @@
(remove-nested-roots)
(add-not-nested-roots)
(fix-components-without-id)
(remap-refs)
(fix-converted-copies)
(remap-refs-recur)
(wrap-non-group-component-roots)
(detach-non-group-instance-roots)
(transform-to-frames)