0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-10 06:41:40 -05:00

♻️ Components refactor: remove it usage on libraries_helpers

This commit is contained in:
Pablo Alba 2024-04-23 19:07:16 +02:00 committed by Andrés Moya
parent 05f4459fb7
commit 37e68249aa
7 changed files with 45 additions and 39 deletions

View file

@ -1450,16 +1450,15 @@
page
(cons shape children))
[_ _ changes2]
(cflh/generate-add-component nil
[_ _ changes]
(cflh/generate-add-component changes
[shape]
(:objects page)
(:id page)
file-id
true
nil
cfsh/prepare-create-artboard-from-selection)
changes (fcb/concat-changes changes changes2)]
cfsh/prepare-create-artboard-from-selection)]
(shape-cb shape)
(:redo-changes changes)))

View file

@ -69,6 +69,11 @@
::page page
::page-id (:id page)))
(defn with-page-id
[changes page-id]
(vary-meta changes assoc
::page-id page-id))
(defn with-container
[changes container]
(if (cfh/page? container)

View file

@ -338,7 +338,7 @@
If an asset id is given, only shapes linked to this particular asset will
be synchronized."
[it file-id asset-type asset-id library-id libraries current-file-id]
[changes file-id asset-type asset-id library-id libraries current-file-id]
(s/assert #{:colors :components :typographies} asset-type)
(s/assert (s/nilable ::us/uuid) asset-id)
(s/assert ::us/uuid file-id)
@ -353,13 +353,13 @@
(let [file (get-in libraries [file-id :data])
components-v2 (get-in file [:options :components-v2])]
(loop [containers (ctf/object-containers-seq file)
changes (pcb/empty-changes it)]
changes changes]
(if-let [container (first containers)]
(do
(recur (next containers)
(pcb/concat-changes
(pcb/concat-changes ;;TODO Remove concat changes
changes
(generate-sync-container it
(generate-sync-container (pcb/empty-changes nil)
asset-type
asset-id
library-id
@ -376,7 +376,7 @@
If an asset id is given, only shapes linked to this particular asset will
be synchronized."
[it file-id asset-type asset-id library-id libraries current-file-id]
[changes file-id asset-type asset-id library-id libraries current-file-id]
(s/assert #{:colors :components :typographies} asset-type)
(s/assert (s/nilable ::us/uuid) asset-id)
(s/assert ::us/uuid file-id)
@ -391,25 +391,25 @@
(let [file (get-in libraries [file-id :data])
components-v2 (get-in file [:options :components-v2])]
(loop [local-components (ctkl/components-seq file)
changes (pcb/empty-changes it)]
changes changes]
(if-let [local-component (first local-components)]
(recur (next local-components)
(pcb/concat-changes
(pcb/concat-changes ;;TODO Remove concat changes
changes
(generate-sync-container it
asset-type
asset-id
library-id
(cfh/make-container local-component :component)
components-v2
libraries
current-file-id)))
(generate-sync-container (pcb/empty-changes nil)
asset-type
asset-id
library-id
(cfh/make-container local-component :component)
components-v2
libraries
current-file-id)))
changes))))
(defn- generate-sync-container
"Generate changes to synchronize all shapes in a particular container (a page
or a component) that use assets of the given type in the given library."
[it asset-type asset-id library-id container components-v2 libraries current-file-id]
[changes asset-type asset-id library-id container components-v2 libraries current-file-id]
(if (cfh/page? container)
(log/debug :msg "Sync page in local file" :page-id (:id container))
@ -418,7 +418,7 @@
(let [linked-shapes (->> (vals (:objects container))
(filter #(uses-assets? asset-type asset-id % library-id)))]
(loop [shapes (seq linked-shapes)
changes (-> (pcb/empty-changes it)
changes (-> changes
(pcb/with-container container)
(pcb/with-objects (:objects container)))]
(if-let [shape (first shapes)]
@ -1727,9 +1727,9 @@
"If there is exactly one id, and it's a frame (or a group in v1), and not already a component,
use it as root. Otherwise, create a frame (v2) or group (v1) that contains all ids. Then, make a
component with it, and link all shapes to their corresponding one in the component."
[it shapes objects page-id file-id components-v2 prepare-create-group prepare-create-board]
[changes shapes objects page-id file-id components-v2 prepare-create-group prepare-create-board]
(let [changes (pcb/empty-changes it page-id)
(let [changes (pcb/with-page-id changes page-id)
shapes-count (count shapes)
first-shape (first shapes)
@ -1744,7 +1744,8 @@
(cfh/frame-shape? first-shape))
(not (ctk/instance-head? first-shape)))
[first-shape
(-> (pcb/empty-changes it page-id)
(-> changes
(pcb/with-page-id page-id)
(pcb/with-objects objects))
(:shapes first-shape)]
@ -1756,7 +1757,7 @@
[root changes]
(if-not components-v2
(prepare-create-group it ; These functions needs to be passed as argument
(prepare-create-group changes ; These functions needs to be passed as argument
objects ; to avoid a circular dependence
page-id
shapes

View file

@ -68,7 +68,7 @@
result)))))))
(defn prepare-create-group
[it objects page-id shapes base-name keep-name?]
[changes objects page-id shapes base-name keep-name?]
(let [frame-id (:frame-id (first shapes))
parent-id (:parent-id (first shapes))
gname (if (and keep-name?
@ -114,7 +114,8 @@
(filter (partial ctl/grid-layout? objects)))
shapes)
changes (-> (pcb/empty-changes it page-id)
changes (-> changes
(pcb/with-page-id page-id)
(pcb/with-objects objects)
(pcb/add-object group {:index group-idx})
(pcb/update-shapes (map :id shapes) ctl/remove-layout-item-data)
@ -191,7 +192,7 @@
parents (into #{} (map :parent-id) shapes)]
(when-not (empty? shapes)
(let [[group changes]
(prepare-create-group it objects page-id shapes "Group" false)]
(prepare-create-group (pcb/empty-changes it) objects page-id shapes "Group" false)]
(rx/of (dch/commit-changes changes)
(dws/select-shapes (d/ordered-set (:id group)))
(ptk/data-event :layout/update {:ids parents}))))))))
@ -267,7 +268,7 @@
(= (:type (first shapes)) :group))
[first-shape (-> (pcb/empty-changes it page-id)
(pcb/with-objects objects))]
(prepare-create-group it objects page-id shapes "Mask" true))
(prepare-create-group (pcb/empty-changes it) objects page-id shapes "Mask" true))
changes (-> changes
(pcb/update-shapes (:shapes group)

View file

@ -351,7 +351,7 @@
parents (into #{} (map :parent-id) shapes)]
(when-not (empty? shapes)
(let [[root _ changes]
(cflh/generate-add-component it shapes objects page-id file-id components-v2
(cflh/generate-add-component (pcb/empty-changes it) shapes objects page-id file-id components-v2
dwg/prepare-create-group
cfsh/prepare-create-artboard-from-selection)]
(when-not (empty? (:redo-changes changes))
@ -1024,22 +1024,22 @@
(-> (pcb/empty-changes it)
(pcb/set-undo-group undo-group))
[(when sync-components?
(cflh/generate-sync-library it file-id :components asset-id library-id libraries current-file-id))
(cflh/generate-sync-library (pcb/empty-changes it) file-id :components asset-id library-id libraries current-file-id))
(when sync-colors?
(cflh/generate-sync-library it file-id :colors asset-id library-id libraries current-file-id))
(cflh/generate-sync-library (pcb/empty-changes it) file-id :colors asset-id library-id libraries current-file-id))
(when sync-typographies?
(cflh/generate-sync-library it file-id :typographies asset-id library-id libraries current-file-id))])
(cflh/generate-sync-library (pcb/empty-changes it) file-id :typographies asset-id library-id libraries current-file-id))])
file-changes (reduce
pcb/concat-changes
(-> (pcb/empty-changes it)
(pcb/set-undo-group undo-group))
[(when sync-components?
(cflh/generate-sync-file it file-id :components asset-id library-id libraries current-file-id))
(cflh/generate-sync-file (pcb/empty-changes it) file-id :components asset-id library-id libraries current-file-id))
(when sync-colors?
(cflh/generate-sync-file it file-id :colors asset-id library-id libraries current-file-id))
(cflh/generate-sync-file (pcb/empty-changes it) file-id :colors asset-id library-id libraries current-file-id))
(when sync-typographies?
(cflh/generate-sync-file it file-id :typographies asset-id library-id libraries current-file-id))])
(cflh/generate-sync-file (pcb/empty-changes it) file-id :typographies asset-id library-id libraries current-file-id))])
changes (pcb/concat-changes library-changes file-changes)

View file

@ -422,7 +422,7 @@
(prepare-duplicate-guides shapes page ids-map delta)))))
(defn- prepare-duplicate-component-change
[changes objects page component-root parent-id frame-id delta libraries library-data it]
[changes objects page component-root parent-id frame-id delta libraries library-data]
(let [component-id (:component-id component-root)
file-id (:component-file component-root)
main-component (ctf/get-component libraries file-id component-id)
@ -467,7 +467,7 @@
changes
(ctf/is-main-of-known-component? obj libraries)
(prepare-duplicate-component-change changes objects page obj parent-id frame-id delta libraries library-data it)
(prepare-duplicate-component-change changes objects page obj parent-id frame-id delta libraries library-data)
:else
(let [frame? (cfh/frame-shape? obj)

View file

@ -132,7 +132,7 @@
shapes (dwg/shapes-for-grouping objects shape-ids)
[group component-id changes]
(cflh/generate-add-component nil
(cflh/generate-add-component (pcb/empty-changes nil)
shapes
(:objects page)
(:id page)