mirror of
https://github.com/penpot/penpot.git
synced 2025-01-23 06:58:58 -05:00
🐛 Fix frame-id on migration to components-v2
This commit is contained in:
parent
19379fdd2c
commit
9059663a87
1 changed files with 52 additions and 27 deletions
|
@ -211,22 +211,22 @@
|
||||||
|
|
||||||
transform-to-frames
|
transform-to-frames
|
||||||
(fn [file-data]
|
(fn [file-data]
|
||||||
; Transform components and copies to frames, and set the
|
; Transform component and copy heads to frames, and set the
|
||||||
; frame-id of its childrens
|
; frame-id of its childrens
|
||||||
(letfn [(fix-container
|
(letfn [(fix-container
|
||||||
[container]
|
[container]
|
||||||
(update container :objects update-vals fix-shape))
|
(update container :objects update-vals fix-shape))
|
||||||
|
|
||||||
(fix-shape
|
(fix-shape
|
||||||
[shape]
|
[shape]
|
||||||
(if (ctk/instance-head? shape)
|
(if (ctk/instance-head? shape)
|
||||||
(assoc shape
|
(assoc shape
|
||||||
:type :frame ; Old groups must be converted
|
:type :frame ; Old groups must be converted
|
||||||
:fills [] ; to frames and conform to spec
|
:fills [] ; to frames and conform to spec
|
||||||
:hide-in-viewer true
|
:hide-in-viewer true
|
||||||
:rx 0
|
:rx 0
|
||||||
:ry 0)
|
:ry 0)
|
||||||
shape))]
|
shape))]
|
||||||
(-> file-data
|
(-> file-data
|
||||||
(update :pages-index update-vals fix-container)
|
(update :pages-index update-vals fix-container)
|
||||||
(update :components update-vals fix-container))))
|
(update :components update-vals fix-container))))
|
||||||
|
@ -236,15 +236,39 @@
|
||||||
; Remap the frame-ids of the primary childs of the head instances
|
; Remap the frame-ids of the primary childs of the head instances
|
||||||
; to point to the head instance.
|
; to point to the head instance.
|
||||||
(letfn [(fix-container
|
(letfn [(fix-container
|
||||||
[container]
|
[container]
|
||||||
(update container :objects update-vals (partial fix-shape container)))
|
(update container :objects update-vals (partial fix-shape container)))
|
||||||
|
|
||||||
(fix-shape
|
(fix-shape
|
||||||
[container shape]
|
[container shape]
|
||||||
(let [parent (ctst/get-shape container (:parent-id shape))]
|
(let [parent (ctst/get-shape container (:parent-id shape))]
|
||||||
(if (ctk/instance-head? parent)
|
(if (ctk/instance-head? parent)
|
||||||
(assoc shape :frame-id (:id parent))
|
(assoc shape :frame-id (:id parent))
|
||||||
shape)))]
|
shape)))]
|
||||||
|
(-> file-data
|
||||||
|
(update :pages-index update-vals fix-container)
|
||||||
|
(update :components update-vals fix-container))))
|
||||||
|
|
||||||
|
fix-frame-ids
|
||||||
|
(fn [file-data]
|
||||||
|
;; Ensure that frame-id of all shapes point to the parent or to the frame-id
|
||||||
|
;; of the parent, and that the destination is indeed a frame.
|
||||||
|
(letfn [(fix-container [container]
|
||||||
|
(update container :objects #(cph/reduce-objects % fix-shape %)))
|
||||||
|
|
||||||
|
(fix-shape [objects shape]
|
||||||
|
(let [parent (when (:parent-id shape)
|
||||||
|
(get objects (:parent-id shape)))
|
||||||
|
error? (when (some? parent)
|
||||||
|
(if (= (:type parent) :frame)
|
||||||
|
(not= (:frame-id shape) (:id parent))
|
||||||
|
(not= (:frame-id shape) (:frame-id parent))))]
|
||||||
|
(if error?
|
||||||
|
(let [nearest-frame (cph/get-frame objects (:parent-id shape))
|
||||||
|
frame-id (or (:id nearest-frame) uuid/zero)]
|
||||||
|
(update objects (:id shape) assoc :frame-id frame-id))
|
||||||
|
objects)))]
|
||||||
|
|
||||||
(-> file-data
|
(-> file-data
|
||||||
(update :pages-index update-vals fix-container)
|
(update :pages-index update-vals fix-container)
|
||||||
(update :components update-vals fix-container))))]
|
(update :components update-vals fix-container))))]
|
||||||
|
@ -257,7 +281,8 @@
|
||||||
(remap-refs)
|
(remap-refs)
|
||||||
(fix-copies-of-detached)
|
(fix-copies-of-detached)
|
||||||
(transform-to-frames)
|
(transform-to-frames)
|
||||||
(remap-frame-ids))))
|
(remap-frame-ids)
|
||||||
|
(fix-frame-ids))))
|
||||||
|
|
||||||
(defn- migrate-components
|
(defn- migrate-components
|
||||||
"If there is any component in the file library, add a new 'Library
|
"If there is any component in the file library, add a new 'Library
|
||||||
|
@ -312,8 +337,8 @@
|
||||||
(fn [page shape]
|
(fn [page shape]
|
||||||
(let [parent (ctst/get-shape page (:parent-id shape))]
|
(let [parent (ctst/get-shape page (:parent-id shape))]
|
||||||
(if (= :frame (:type parent))
|
(if (= :frame (:type parent))
|
||||||
(:parent-id shape)
|
(:id parent)
|
||||||
(:frame-id shape))))
|
(:frame-id parent))))
|
||||||
|
|
||||||
add-shapes
|
add-shapes
|
||||||
(fn [page]
|
(fn [page]
|
||||||
|
@ -369,7 +394,7 @@
|
||||||
"Convert a media object that contains a bitmap image into shapes,
|
"Convert a media object that contains a bitmap image into shapes,
|
||||||
one shape of type :image and one group that contains it."
|
one shape of type :image and one group that contains it."
|
||||||
[{:keys [name width height id mtype]} position]
|
[{:keys [name width height id mtype]} position]
|
||||||
(let [group-shape (cts/setup-shape
|
(let [frame-shape (cts/setup-shape
|
||||||
{:type :frame
|
{:type :frame
|
||||||
:x (:x position)
|
:x (:x position)
|
||||||
:y (:y position)
|
:y (:y position)
|
||||||
|
@ -390,9 +415,9 @@
|
||||||
:height height
|
:height height
|
||||||
:mtype mtype}
|
:mtype mtype}
|
||||||
:name name
|
:name name
|
||||||
:frame-id uuid/zero
|
:frame-id (:id frame-shape)
|
||||||
:parent-id (:id group-shape)})]
|
:parent-id (:id frame-shape)})]
|
||||||
[group-shape [img-shape]]))
|
[frame-shape [img-shape]]))
|
||||||
|
|
||||||
(defn- parse-datauri
|
(defn- parse-datauri
|
||||||
[data]
|
[data]
|
||||||
|
|
Loading…
Add table
Reference in a new issue