mirror of
https://github.com/penpot/penpot.git
synced 2025-02-12 18:18:24 -05: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))]
|
||||
[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
|
||||
[changes file-full libraries container id components-v2 reset?]
|
||||
(let [shape-inst (ctn/get-shape container id)
|
||||
|
|
|
@ -976,34 +976,15 @@
|
|||
libraries (wsh/get-libraries state)
|
||||
current-file-id (:current-file-id state)
|
||||
|
||||
|
||||
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))
|
||||
|
||||
library-changes (reduce
|
||||
pcb/concat-changes
|
||||
(-> (pcb/empty-changes it)
|
||||
(pcb/set-undo-group undo-group))
|
||||
[(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)
|
||||
changes (cflh/generate-sync-file-changes
|
||||
(pcb/empty-changes it)
|
||||
undo-group
|
||||
asset-type
|
||||
file-id
|
||||
asset-id
|
||||
library-id
|
||||
libraries
|
||||
current-file-id)
|
||||
|
||||
find-frames (fn [change]
|
||||
(->> (ch/frames-changed file change)
|
||||
|
@ -1021,8 +1002,7 @@
|
|||
(rx/of (set-updating-library false)
|
||||
(msg/hide-tag :sync-dialog))
|
||||
(when (seq (:redo-changes changes))
|
||||
(rx/of (dch/commit-changes (assoc changes ;; TODO a ver qué pasa con esto
|
||||
:file-id file-id))))
|
||||
(rx/of (dch/commit-changes changes)))
|
||||
(when-not (empty? updated-frames)
|
||||
(rx/merge
|
||||
(rx/of (ptk/data-event :layout/update {:ids (map :id updated-frames) :undo-group undo-group}))
|
||||
|
|
Loading…
Add table
Reference in a new issue