mirror of
https://github.com/penpot/penpot.git
synced 2025-03-11 07:11:32 -05:00
⚡ Add minor perf improvement on components-v2 migration
This commit is contained in:
parent
0078c0e601
commit
68c0b0e8a7
1 changed files with 73 additions and 73 deletions
|
@ -326,88 +326,88 @@
|
||||||
main instances for all components there and remove shapes from library components.
|
main instances for all components there and remove shapes from library components.
|
||||||
Mark the file with the :components-v2 option."
|
Mark the file with the :components-v2 option."
|
||||||
[file-data]
|
[file-data]
|
||||||
(let [components (ctkl/components-seq file-data)]
|
(let [migrated? (dm/get-in file-data [:options :components-v2])]
|
||||||
(if (or (empty? components)
|
(if migrated?
|
||||||
(dm/get-in file-data [:options :components-v2]))
|
file-data
|
||||||
(assoc-in file-data [:options :components-v2] true)
|
(let [components (ctkl/components-seq file-data)]
|
||||||
(let [grid-gap 50
|
(if (empty? components)
|
||||||
|
(assoc-in file-data [:options :components-v2] true)
|
||||||
|
(let [grid-gap 50
|
||||||
|
[file-data page-id start-pos]
|
||||||
|
(get-or-add-library-page file-data grid-gap)
|
||||||
|
|
||||||
[file-data page-id start-pos]
|
add-main-instance
|
||||||
(get-or-add-library-page file-data grid-gap)
|
(fn [file-data component position]
|
||||||
|
(let [page (ctpl/get-page file-data page-id)
|
||||||
|
|
||||||
add-main-instance
|
[new-shape new-shapes]
|
||||||
(fn [file-data component position]
|
(ctn/make-component-instance page
|
||||||
(let [page (ctpl/get-page file-data page-id)
|
component
|
||||||
|
file-data
|
||||||
|
position
|
||||||
|
false
|
||||||
|
{:main-instance? true
|
||||||
|
:force-frame-id uuid/zero})
|
||||||
|
|
||||||
[new-shape new-shapes]
|
add-shapes
|
||||||
(ctn/make-component-instance page
|
(fn [page]
|
||||||
component
|
(reduce (fn [page shape]
|
||||||
file-data
|
(ctst/add-shape (:id shape)
|
||||||
position
|
shape
|
||||||
false
|
page
|
||||||
{:main-instance? true
|
(:frame-id shape)
|
||||||
:force-frame-id uuid/zero})
|
(:parent-id shape)
|
||||||
|
nil ; <- As shapes are ordered, we can safely add each
|
||||||
|
true)) ; one at the end of the parent's children list.
|
||||||
|
page
|
||||||
|
new-shapes))
|
||||||
|
|
||||||
add-shapes
|
update-component
|
||||||
(fn [page]
|
(fn [component]
|
||||||
(reduce (fn [page shape]
|
(-> component
|
||||||
(ctst/add-shape (:id shape)
|
(assoc :main-instance-id (:id new-shape)
|
||||||
shape
|
:main-instance-page page-id)
|
||||||
page
|
(dissoc :objects)))]
|
||||||
(:frame-id shape)
|
|
||||||
(:parent-id shape)
|
|
||||||
nil ; <- As shapes are ordered, we can safely add each
|
|
||||||
true)) ; one at the end of the parent's children list.
|
|
||||||
page
|
|
||||||
new-shapes))
|
|
||||||
|
|
||||||
update-component
|
(-> file-data
|
||||||
(fn [component]
|
(ctpl/update-page page-id add-shapes)
|
||||||
(-> component
|
(ctkl/update-component (:id component) update-component))))
|
||||||
(assoc :main-instance-id (:id new-shape)
|
|
||||||
:main-instance-page page-id)
|
|
||||||
(dissoc :objects)))]
|
|
||||||
|
|
||||||
(-> file-data
|
add-instance-grid
|
||||||
(ctpl/update-page page-id add-shapes)
|
(fn [file-data components]
|
||||||
(ctkl/update-component (:id component) update-component))))
|
(let [position-seq (ctst/generate-shape-grid
|
||||||
|
(map (partial get-component-root file-data) components)
|
||||||
|
start-pos
|
||||||
|
grid-gap)]
|
||||||
|
(loop [file-data file-data
|
||||||
|
components-seq (seq components)
|
||||||
|
position-seq position-seq]
|
||||||
|
(let [component (first components-seq)
|
||||||
|
position (first position-seq)]
|
||||||
|
(if (nil? component)
|
||||||
|
file-data
|
||||||
|
(recur (add-main-instance file-data component position)
|
||||||
|
(rest components-seq)
|
||||||
|
(rest position-seq)))))))
|
||||||
|
|
||||||
add-instance-grid
|
root-to-board
|
||||||
(fn [file-data components]
|
(fn [shape]
|
||||||
(let [position-seq (ctst/generate-shape-grid
|
(cond-> shape
|
||||||
(map (partial get-component-root file-data) components)
|
(and (ctk/instance-root? shape)
|
||||||
start-pos
|
(cph/frame-shape? shape))
|
||||||
grid-gap)]
|
(assoc :fills []
|
||||||
(loop [file-data file-data
|
:hide-in-viewer true
|
||||||
components-seq (seq components)
|
:rx 0
|
||||||
position-seq position-seq]
|
:ry 0)))
|
||||||
(let [component (first components-seq)
|
|
||||||
position (first position-seq)]
|
|
||||||
(if (nil? component)
|
|
||||||
file-data
|
|
||||||
(recur (add-main-instance file-data component position)
|
|
||||||
(rest components-seq)
|
|
||||||
(rest position-seq)))))))
|
|
||||||
|
|
||||||
root-to-board
|
roots-to-board
|
||||||
(fn [shape]
|
(fn [page]
|
||||||
(cond-> shape
|
(update page :objects update-vals root-to-board))]
|
||||||
(and (ctk/instance-head? shape)
|
|
||||||
(not= (:type shape) :frame))
|
|
||||||
(assoc :type :frame
|
|
||||||
:fills []
|
|
||||||
:hide-in-viewer true
|
|
||||||
:rx 0
|
|
||||||
:ry 0)))
|
|
||||||
|
|
||||||
roots-to-board
|
(-> file-data
|
||||||
(fn [page]
|
(add-instance-grid (sort-by :name components))
|
||||||
(update page :objects update-vals root-to-board))]
|
(update :pages-index update-vals roots-to-board)
|
||||||
|
(assoc-in [:options :components-v2] true))))))))
|
||||||
(-> file-data
|
|
||||||
(add-instance-grid (sort-by :name components))
|
|
||||||
(update :pages-index update-vals roots-to-board)
|
|
||||||
(assoc-in [:options :components-v2] true))))))
|
|
||||||
|
|
||||||
(defn- absorb-components
|
(defn- absorb-components
|
||||||
[file-data used-components library-data]
|
[file-data used-components library-data]
|
||||||
|
|
Loading…
Add table
Reference in a new issue