mirror of
https://github.com/penpot/penpot.git
synced 2025-05-10 00:06:38 +02:00
♻️ Components refactor: generator for sync-file
This commit is contained in:
parent
c73eb77125
commit
a7bfa7c7c8
2 changed files with 34 additions and 30 deletions
|
@ -2047,6 +2047,30 @@
|
||||||
(generate-new-shape-for-swap shape file page libraries id-new-component index target-cell keep-props-values))]
|
(generate-new-shape-for-swap shape file page libraries id-new-component index target-cell keep-props-values))]
|
||||||
[new-shape all-parents changes]))
|
[new-shape all-parents changes]))
|
||||||
|
|
||||||
|
(defn generate-sync-file-changes
|
||||||
|
[changes undo-group asset-type file-id asset-id library-id libraries current-file-id]
|
||||||
|
(let [sync-components? (or (nil? asset-type) (= asset-type :components))
|
||||||
|
sync-colors? (or (nil? asset-type) (= asset-type :colors))
|
||||||
|
sync-typographies? (or (nil? asset-type) (= asset-type :typographies))]
|
||||||
|
(cond-> changes
|
||||||
|
:always
|
||||||
|
(pcb/set-undo-group undo-group)
|
||||||
|
;; library-changes
|
||||||
|
sync-components?
|
||||||
|
(generate-sync-library file-id :components asset-id library-id libraries current-file-id)
|
||||||
|
sync-colors?
|
||||||
|
(generate-sync-library file-id :colors asset-id library-id libraries current-file-id)
|
||||||
|
sync-typographies?
|
||||||
|
(generate-sync-library file-id :typographies asset-id library-id libraries current-file-id)
|
||||||
|
|
||||||
|
;; file-changes
|
||||||
|
sync-components?
|
||||||
|
(generate-sync-file file-id :components asset-id library-id libraries current-file-id)
|
||||||
|
sync-colors?
|
||||||
|
(generate-sync-file file-id :colors asset-id library-id libraries current-file-id)
|
||||||
|
sync-typographies?
|
||||||
|
(generate-sync-file file-id :typographies asset-id library-id libraries current-file-id))))
|
||||||
|
|
||||||
(defn generate-sync-head
|
(defn generate-sync-head
|
||||||
[changes file-full libraries container id components-v2 reset?]
|
[changes file-full libraries container id components-v2 reset?]
|
||||||
(let [shape-inst (ctn/get-shape container id)
|
(let [shape-inst (ctn/get-shape container id)
|
||||||
|
|
|
@ -976,34 +976,15 @@
|
||||||
libraries (wsh/get-libraries state)
|
libraries (wsh/get-libraries state)
|
||||||
current-file-id (:current-file-id state)
|
current-file-id (:current-file-id state)
|
||||||
|
|
||||||
|
changes (cflh/generate-sync-file-changes
|
||||||
sync-components? (or (nil? asset-type) (= asset-type :components))
|
(pcb/empty-changes it)
|
||||||
sync-colors? (or (nil? asset-type) (= asset-type :colors))
|
undo-group
|
||||||
sync-typographies? (or (nil? asset-type) (= asset-type :typographies))
|
asset-type
|
||||||
|
file-id
|
||||||
library-changes (reduce
|
asset-id
|
||||||
pcb/concat-changes
|
library-id
|
||||||
(-> (pcb/empty-changes it)
|
libraries
|
||||||
(pcb/set-undo-group undo-group))
|
current-file-id)
|
||||||
[(when sync-components?
|
|
||||||
(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 (pcb/empty-changes it) file-id :colors asset-id library-id libraries current-file-id))
|
|
||||||
(when sync-typographies?
|
|
||||||
(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 (pcb/empty-changes it) file-id :components asset-id library-id libraries current-file-id))
|
|
||||||
(when sync-colors?
|
|
||||||
(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 (pcb/empty-changes it) file-id :typographies asset-id library-id libraries current-file-id))])
|
|
||||||
|
|
||||||
changes (pcb/concat-changes library-changes file-changes)
|
|
||||||
|
|
||||||
find-frames (fn [change]
|
find-frames (fn [change]
|
||||||
(->> (ch/frames-changed file change)
|
(->> (ch/frames-changed file change)
|
||||||
|
@ -1021,8 +1002,7 @@
|
||||||
(rx/of (set-updating-library false)
|
(rx/of (set-updating-library false)
|
||||||
(msg/hide-tag :sync-dialog))
|
(msg/hide-tag :sync-dialog))
|
||||||
(when (seq (:redo-changes changes))
|
(when (seq (:redo-changes changes))
|
||||||
(rx/of (dch/commit-changes (assoc changes ;; TODO a ver qué pasa con esto
|
(rx/of (dch/commit-changes changes)))
|
||||||
:file-id file-id))))
|
|
||||||
(when-not (empty? updated-frames)
|
(when-not (empty? updated-frames)
|
||||||
(rx/merge
|
(rx/merge
|
||||||
(rx/of (ptk/data-event :layout/update {:ids (map :id updated-frames) :undo-group undo-group}))
|
(rx/of (ptk/data-event :layout/update {:ids (map :id updated-frames) :undo-group undo-group}))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue