mirror of
https://github.com/penpot/penpot.git
synced 2025-05-31 11:56:12 +02:00
🐛 Fix rmap shape refs on components v2 migration
This commit is contained in:
parent
89b43d7127
commit
d6b60ce43a
1 changed files with 54 additions and 36 deletions
|
@ -731,10 +731,10 @@
|
||||||
(fn [file-data]
|
(fn [file-data]
|
||||||
;; Remap shape-refs so that they point to the near main.
|
;; 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.
|
;; At the same time, if there are any dangling ref, detach the shape and its children.
|
||||||
(letfn [(fix-container [container]
|
(let [count (volatile! 0)
|
||||||
(reduce fix-shape container (ctn/shapes-seq container)))
|
|
||||||
|
|
||||||
(fix-shape [container shape]
|
fix-shape
|
||||||
|
(fn [container shape]
|
||||||
(if (ctk/in-component-copy? shape)
|
(if (ctk/in-component-copy? shape)
|
||||||
;; First look for the direct shape.
|
;; First look for the direct shape.
|
||||||
(let [root (ctn/get-component-shape (:objects container) shape)
|
(let [root (ctn/get-component-shape (:objects container) shape)
|
||||||
|
@ -750,7 +750,9 @@
|
||||||
(ctf/get-component-shapes (:data library) component))]
|
(ctf/get-component-shapes (:data library) component))]
|
||||||
(if (some? near-shape)
|
(if (some? near-shape)
|
||||||
;; If found, update the ref to point to the 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
|
;; If not found, it may be a fostered component. Try to locate a direct shape
|
||||||
;; in the head component.
|
;; in the head component.
|
||||||
(let [head (ctn/get-head-shape (:objects container) shape)
|
(let [head (ctn/get-head-shape (:objects container) shape)
|
||||||
|
@ -762,12 +764,28 @@
|
||||||
container
|
container
|
||||||
;; If not found, detach shape and all children.
|
;; If not found, detach shape and all children.
|
||||||
;; container
|
;; container
|
||||||
(detach-shape container shape)))))))
|
(do
|
||||||
container))]
|
(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)
|
(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
|
fix-converted-copies
|
||||||
(fn [file-data]
|
(fn [file-data]
|
||||||
|
@ -993,8 +1011,8 @@
|
||||||
(remove-nested-roots)
|
(remove-nested-roots)
|
||||||
(add-not-nested-roots)
|
(add-not-nested-roots)
|
||||||
(fix-components-without-id)
|
(fix-components-without-id)
|
||||||
(remap-refs)
|
|
||||||
(fix-converted-copies)
|
(fix-converted-copies)
|
||||||
|
(remap-refs-recur)
|
||||||
(wrap-non-group-component-roots)
|
(wrap-non-group-component-roots)
|
||||||
(detach-non-group-instance-roots)
|
(detach-non-group-instance-roots)
|
||||||
(transform-to-frames)
|
(transform-to-frames)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue