mirror of
https://github.com/penpot/penpot.git
synced 2025-05-17 02:36:15 +02:00
♻️ Components refactor: remove it usage on libraries_helpers
This commit is contained in:
parent
05f4459fb7
commit
37e68249aa
7 changed files with 45 additions and 39 deletions
|
@ -1450,16 +1450,15 @@
|
||||||
page
|
page
|
||||||
(cons shape children))
|
(cons shape children))
|
||||||
|
|
||||||
[_ _ changes2]
|
[_ _ changes]
|
||||||
(cflh/generate-add-component nil
|
(cflh/generate-add-component changes
|
||||||
[shape]
|
[shape]
|
||||||
(:objects page)
|
(:objects page)
|
||||||
(:id page)
|
(:id page)
|
||||||
file-id
|
file-id
|
||||||
true
|
true
|
||||||
nil
|
nil
|
||||||
cfsh/prepare-create-artboard-from-selection)
|
cfsh/prepare-create-artboard-from-selection)]
|
||||||
changes (fcb/concat-changes changes changes2)]
|
|
||||||
|
|
||||||
(shape-cb shape)
|
(shape-cb shape)
|
||||||
(:redo-changes changes)))
|
(:redo-changes changes)))
|
||||||
|
|
|
@ -69,6 +69,11 @@
|
||||||
::page page
|
::page page
|
||||||
::page-id (:id page)))
|
::page-id (:id page)))
|
||||||
|
|
||||||
|
(defn with-page-id
|
||||||
|
[changes page-id]
|
||||||
|
(vary-meta changes assoc
|
||||||
|
::page-id page-id))
|
||||||
|
|
||||||
(defn with-container
|
(defn with-container
|
||||||
[changes container]
|
[changes container]
|
||||||
(if (cfh/page? container)
|
(if (cfh/page? container)
|
||||||
|
|
|
@ -338,7 +338,7 @@
|
||||||
|
|
||||||
If an asset id is given, only shapes linked to this particular asset will
|
If an asset id is given, only shapes linked to this particular asset will
|
||||||
be synchronized."
|
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 #{:colors :components :typographies} asset-type)
|
||||||
(s/assert (s/nilable ::us/uuid) asset-id)
|
(s/assert (s/nilable ::us/uuid) asset-id)
|
||||||
(s/assert ::us/uuid file-id)
|
(s/assert ::us/uuid file-id)
|
||||||
|
@ -353,13 +353,13 @@
|
||||||
(let [file (get-in libraries [file-id :data])
|
(let [file (get-in libraries [file-id :data])
|
||||||
components-v2 (get-in file [:options :components-v2])]
|
components-v2 (get-in file [:options :components-v2])]
|
||||||
(loop [containers (ctf/object-containers-seq file)
|
(loop [containers (ctf/object-containers-seq file)
|
||||||
changes (pcb/empty-changes it)]
|
changes changes]
|
||||||
(if-let [container (first containers)]
|
(if-let [container (first containers)]
|
||||||
(do
|
(do
|
||||||
(recur (next containers)
|
(recur (next containers)
|
||||||
(pcb/concat-changes
|
(pcb/concat-changes ;;TODO Remove concat changes
|
||||||
changes
|
changes
|
||||||
(generate-sync-container it
|
(generate-sync-container (pcb/empty-changes nil)
|
||||||
asset-type
|
asset-type
|
||||||
asset-id
|
asset-id
|
||||||
library-id
|
library-id
|
||||||
|
@ -376,7 +376,7 @@
|
||||||
|
|
||||||
If an asset id is given, only shapes linked to this particular asset will
|
If an asset id is given, only shapes linked to this particular asset will
|
||||||
be synchronized."
|
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 #{:colors :components :typographies} asset-type)
|
||||||
(s/assert (s/nilable ::us/uuid) asset-id)
|
(s/assert (s/nilable ::us/uuid) asset-id)
|
||||||
(s/assert ::us/uuid file-id)
|
(s/assert ::us/uuid file-id)
|
||||||
|
@ -391,25 +391,25 @@
|
||||||
(let [file (get-in libraries [file-id :data])
|
(let [file (get-in libraries [file-id :data])
|
||||||
components-v2 (get-in file [:options :components-v2])]
|
components-v2 (get-in file [:options :components-v2])]
|
||||||
(loop [local-components (ctkl/components-seq file)
|
(loop [local-components (ctkl/components-seq file)
|
||||||
changes (pcb/empty-changes it)]
|
changes changes]
|
||||||
(if-let [local-component (first local-components)]
|
(if-let [local-component (first local-components)]
|
||||||
(recur (next local-components)
|
(recur (next local-components)
|
||||||
(pcb/concat-changes
|
(pcb/concat-changes ;;TODO Remove concat changes
|
||||||
changes
|
changes
|
||||||
(generate-sync-container it
|
(generate-sync-container (pcb/empty-changes nil)
|
||||||
asset-type
|
asset-type
|
||||||
asset-id
|
asset-id
|
||||||
library-id
|
library-id
|
||||||
(cfh/make-container local-component :component)
|
(cfh/make-container local-component :component)
|
||||||
components-v2
|
components-v2
|
||||||
libraries
|
libraries
|
||||||
current-file-id)))
|
current-file-id)))
|
||||||
changes))))
|
changes))))
|
||||||
|
|
||||||
(defn- generate-sync-container
|
(defn- generate-sync-container
|
||||||
"Generate changes to synchronize all shapes in a particular container (a page
|
"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."
|
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)
|
(if (cfh/page? container)
|
||||||
(log/debug :msg "Sync page in local file" :page-id (:id container))
|
(log/debug :msg "Sync page in local file" :page-id (:id container))
|
||||||
|
@ -418,7 +418,7 @@
|
||||||
(let [linked-shapes (->> (vals (:objects container))
|
(let [linked-shapes (->> (vals (:objects container))
|
||||||
(filter #(uses-assets? asset-type asset-id % library-id)))]
|
(filter #(uses-assets? asset-type asset-id % library-id)))]
|
||||||
(loop [shapes (seq linked-shapes)
|
(loop [shapes (seq linked-shapes)
|
||||||
changes (-> (pcb/empty-changes it)
|
changes (-> changes
|
||||||
(pcb/with-container container)
|
(pcb/with-container container)
|
||||||
(pcb/with-objects (:objects container)))]
|
(pcb/with-objects (:objects container)))]
|
||||||
(if-let [shape (first shapes)]
|
(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,
|
"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
|
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."
|
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)
|
shapes-count (count shapes)
|
||||||
first-shape (first shapes)
|
first-shape (first shapes)
|
||||||
|
|
||||||
|
@ -1744,7 +1744,8 @@
|
||||||
(cfh/frame-shape? first-shape))
|
(cfh/frame-shape? first-shape))
|
||||||
(not (ctk/instance-head? first-shape)))
|
(not (ctk/instance-head? first-shape)))
|
||||||
[first-shape
|
[first-shape
|
||||||
(-> (pcb/empty-changes it page-id)
|
(-> changes
|
||||||
|
(pcb/with-page-id page-id)
|
||||||
(pcb/with-objects objects))
|
(pcb/with-objects objects))
|
||||||
(:shapes first-shape)]
|
(:shapes first-shape)]
|
||||||
|
|
||||||
|
@ -1756,7 +1757,7 @@
|
||||||
|
|
||||||
[root changes]
|
[root changes]
|
||||||
(if-not components-v2
|
(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
|
objects ; to avoid a circular dependence
|
||||||
page-id
|
page-id
|
||||||
shapes
|
shapes
|
||||||
|
|
|
@ -68,7 +68,7 @@
|
||||||
result)))))))
|
result)))))))
|
||||||
|
|
||||||
(defn prepare-create-group
|
(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))
|
(let [frame-id (:frame-id (first shapes))
|
||||||
parent-id (:parent-id (first shapes))
|
parent-id (:parent-id (first shapes))
|
||||||
gname (if (and keep-name?
|
gname (if (and keep-name?
|
||||||
|
@ -114,7 +114,8 @@
|
||||||
(filter (partial ctl/grid-layout? objects)))
|
(filter (partial ctl/grid-layout? objects)))
|
||||||
shapes)
|
shapes)
|
||||||
|
|
||||||
changes (-> (pcb/empty-changes it page-id)
|
changes (-> changes
|
||||||
|
(pcb/with-page-id page-id)
|
||||||
(pcb/with-objects objects)
|
(pcb/with-objects objects)
|
||||||
(pcb/add-object group {:index group-idx})
|
(pcb/add-object group {:index group-idx})
|
||||||
(pcb/update-shapes (map :id shapes) ctl/remove-layout-item-data)
|
(pcb/update-shapes (map :id shapes) ctl/remove-layout-item-data)
|
||||||
|
@ -191,7 +192,7 @@
|
||||||
parents (into #{} (map :parent-id) shapes)]
|
parents (into #{} (map :parent-id) shapes)]
|
||||||
(when-not (empty? shapes)
|
(when-not (empty? shapes)
|
||||||
(let [[group changes]
|
(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)
|
(rx/of (dch/commit-changes changes)
|
||||||
(dws/select-shapes (d/ordered-set (:id group)))
|
(dws/select-shapes (d/ordered-set (:id group)))
|
||||||
(ptk/data-event :layout/update {:ids parents}))))))))
|
(ptk/data-event :layout/update {:ids parents}))))))))
|
||||||
|
@ -267,7 +268,7 @@
|
||||||
(= (:type (first shapes)) :group))
|
(= (:type (first shapes)) :group))
|
||||||
[first-shape (-> (pcb/empty-changes it page-id)
|
[first-shape (-> (pcb/empty-changes it page-id)
|
||||||
(pcb/with-objects objects))]
|
(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
|
changes (-> changes
|
||||||
(pcb/update-shapes (:shapes group)
|
(pcb/update-shapes (:shapes group)
|
||||||
|
|
|
@ -351,7 +351,7 @@
|
||||||
parents (into #{} (map :parent-id) shapes)]
|
parents (into #{} (map :parent-id) shapes)]
|
||||||
(when-not (empty? shapes)
|
(when-not (empty? shapes)
|
||||||
(let [[root _ changes]
|
(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
|
dwg/prepare-create-group
|
||||||
cfsh/prepare-create-artboard-from-selection)]
|
cfsh/prepare-create-artboard-from-selection)]
|
||||||
(when-not (empty? (:redo-changes changes))
|
(when-not (empty? (:redo-changes changes))
|
||||||
|
@ -1024,22 +1024,22 @@
|
||||||
(-> (pcb/empty-changes it)
|
(-> (pcb/empty-changes it)
|
||||||
(pcb/set-undo-group undo-group))
|
(pcb/set-undo-group undo-group))
|
||||||
[(when sync-components?
|
[(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?
|
(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?
|
(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
|
file-changes (reduce
|
||||||
pcb/concat-changes
|
pcb/concat-changes
|
||||||
(-> (pcb/empty-changes it)
|
(-> (pcb/empty-changes it)
|
||||||
(pcb/set-undo-group undo-group))
|
(pcb/set-undo-group undo-group))
|
||||||
[(when sync-components?
|
[(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?
|
(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?
|
(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)
|
changes (pcb/concat-changes library-changes file-changes)
|
||||||
|
|
||||||
|
|
|
@ -422,7 +422,7 @@
|
||||||
(prepare-duplicate-guides shapes page ids-map delta)))))
|
(prepare-duplicate-guides shapes page ids-map delta)))))
|
||||||
|
|
||||||
(defn- prepare-duplicate-component-change
|
(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)
|
(let [component-id (:component-id component-root)
|
||||||
file-id (:component-file component-root)
|
file-id (:component-file component-root)
|
||||||
main-component (ctf/get-component libraries file-id component-id)
|
main-component (ctf/get-component libraries file-id component-id)
|
||||||
|
@ -467,7 +467,7 @@
|
||||||
changes
|
changes
|
||||||
|
|
||||||
(ctf/is-main-of-known-component? obj libraries)
|
(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
|
:else
|
||||||
(let [frame? (cfh/frame-shape? obj)
|
(let [frame? (cfh/frame-shape? obj)
|
||||||
|
|
|
@ -132,7 +132,7 @@
|
||||||
shapes (dwg/shapes-for-grouping objects shape-ids)
|
shapes (dwg/shapes-for-grouping objects shape-ids)
|
||||||
|
|
||||||
[group component-id changes]
|
[group component-id changes]
|
||||||
(cflh/generate-add-component nil
|
(cflh/generate-add-component (pcb/empty-changes nil)
|
||||||
shapes
|
shapes
|
||||||
(:objects page)
|
(:objects page)
|
||||||
(:id page)
|
(:id page)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue