0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-28 15:41:25 -05:00

♻️ Components refactor: generator for reset component

This commit is contained in:
Alejandro Alonso 2024-04-25 09:32:09 +02:00 committed by Andrés Moya
parent f3220fa985
commit c73eb77125
2 changed files with 31 additions and 48 deletions

View file

@ -2048,10 +2048,29 @@
[new-shape all-parents changes]))
(defn generate-sync-head
[changes file-full libraries container head components-v2]
(let [changes
[changes file-full libraries container id components-v2 reset?]
(let [shape-inst (ctn/get-shape container id)
objects (:objects container)
parent (get objects (:parent-id shape-inst))
head (ctn/get-component-shape container parent)
changes
(-> changes
(pcb/with-container container)
(pcb/with-objects (:objects container))
(generate-sync-shape-direct file-full libraries container (:id head) false components-v2))]
changes))
(generate-sync-shape-direct file-full libraries container (:id head) reset? components-v2))]
changes))
(defn generate-reset-component
[changes file-full libraries container id components-v2]
(let [objects (:objects container)
swap-slot (-> (ctn/get-shape container id)
(ctk/get-swap-slot))
changes
(-> changes
(pcb/with-container container)
(pcb/with-objects objects)
(generate-sync-shape-direct file-full libraries container id true components-v2))]
(cond-> changes
(some? swap-slot)
(generate-sync-head file-full libraries container id components-v2 true))))

View file

@ -672,36 +672,6 @@
(rx/take-until stopper-s))))))
(defn sync-head
[id]
(ptk/reify ::sync-head
ptk/WatchEvent
(watch [it state _]
(log/info :msg "SYNC-head of shape" :id (str id))
(let [file (wsh/get-local-file state)
file-full (wsh/get-local-file-full state)
libraries (wsh/get-libraries state)
page-id (:current-page-id state)
container (cfh/get-container file :page page-id)
objects (:objects container)
shape-inst (ctn/get-shape container id)
parent (get objects (:parent-id shape-inst))
head (ctn/get-component-shape container parent)
components-v2
(features/active-feature? state "components/v2")
changes
(-> (pcb/empty-changes it)
(cflh/generate-sync-head file-full libraries container head components-v2))]
(log/debug :msg "SYNC-head finished" :js/rchanges (log-changes
(:redo-changes changes)
file))
(rx/of (dch/commit-changes changes))))))
(defn reset-component
"Cancels all modifications in the shape with the given id, and all its children, in
the current page. Set all attributes equal to the ones in the linked component,
@ -712,35 +682,29 @@
ptk/WatchEvent
(watch [it state _]
(log/info :msg "RESET-COMPONENT of shape" :id (str id))
(let [file (wsh/get-local-file state)
file-full (wsh/get-local-file-full state)
libraries (wsh/get-libraries state)
(let [file (wsh/get-local-file state)
file-full (wsh/get-local-file-full state)
libraries (wsh/get-libraries state)
page-id (:current-page-id state)
container (cfh/get-container file :page page-id)
page-id (:current-page-id state)
container (cfh/get-container file :page page-id)
components-v2
(features/active-feature? state "components/v2")
swap-slot (-> (ctn/get-shape container id)
(ctk/get-swap-slot))
undo-id (js/Symbol)
undo-id (js/Symbol)
changes
(-> (pcb/empty-changes it)
(pcb/with-container container)
(pcb/with-objects (:objects container))
(cflh/generate-sync-shape-direct file-full libraries container id true components-v2))]
(cflh/generate-reset-component file-full libraries container id components-v2))]
(log/debug :msg "RESET-COMPONENT finished" :js/rchanges (log-changes
(:redo-changes changes)
file))
(rx/of
(dwu/start-undo-transaction undo-id)
(dch/commit-changes changes)
(when (some? swap-slot)
(sync-head id))
(dwu/commit-undo-transaction undo-id))))))
(defn reset-components