0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-25 07:58:49 -05:00

:tada Add undo-group for layout updates

This commit is contained in:
Alejandro Alonso 2024-03-07 11:04:35 +01:00
parent c214d8b044
commit bad0fb912b
13 changed files with 61 additions and 58 deletions

View file

@ -777,7 +777,7 @@
(rx/of (dwu/start-undo-transaction undo-id)
(dch/commit-changes changes)
(ptk/data-event :layout/update selected-ids)
(ptk/data-event :layout/update {:ids selected-ids})
(dwu/commit-undo-transaction undo-id))))))
;; --- Change Shape Order (D&D Ordering)
@ -987,7 +987,7 @@
(rx/of (dwu/start-undo-transaction undo-id)
(dch/commit-changes changes)
(dwco/expand-collapse parent-id)
(ptk/data-event :layout/update (concat all-parents ids))
(ptk/data-event :layout/update {:ids (concat all-parents ids)})
(dwu/commit-undo-transaction undo-id))))))
(defn relocate-selected-shapes
@ -1105,7 +1105,7 @@
(when (can-align? selected objects)
(rx/of (dwu/start-undo-transaction undo-id)
(dwt/position-shapes moved)
(ptk/data-event :layout/update selected)
(ptk/data-event :layout/update {:ids selected})
(dwu/commit-undo-transaction undo-id)))))))
(defn can-distribute? [selected]
@ -1132,7 +1132,7 @@
(when (can-distribute? selected)
(rx/of (dwu/start-undo-transaction undo-id)
(dwt/position-shapes moved)
(ptk/data-event :layout/update selected)
(ptk/data-event :layout/update {:ids selected})
(dwu/commit-undo-transaction undo-id)))))))
;; --- Shape Proportions
@ -2016,7 +2016,7 @@
(rx/of (dwu/start-undo-transaction undo-id)
(dch/commit-changes changes)
(dws/select-shapes selected)
(ptk/data-event :layout/update [frame-id])
(ptk/data-event :layout/update {:ids [frame-id]})
(dwu/commit-undo-transaction undo-id)))))))
(defn as-content [text]

View file

@ -101,7 +101,7 @@
;; Update layouts for properties marked
(if (d/not-empty? update-layout-ids)
(rx/of (ptk/data-event :layout/update update-layout-ids))
(rx/of (ptk/data-event :layout/update {:ids update-layout-ids}))
(rx/empty))))))))
(defn send-update-indices

View file

@ -194,7 +194,7 @@
(prepare-create-group 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 parents))))))))
(ptk/data-event :layout/update {:ids parents}))))))))
(def ungroup-selected
(ptk/reify ::ungroup-selected
@ -244,7 +244,7 @@
(when-not (empty? selected)
(rx/of (dwu/start-undo-transaction undo-id)
(dch/commit-changes changes)
(ptk/data-event :layout/update parents)
(ptk/data-event :layout/update {:ids parents})
(dwu/commit-undo-transaction undo-id)
(dws/select-shapes child-ids)))))))
@ -289,7 +289,7 @@
(rx/of (dwu/start-undo-transaction undo-id)
(dch/commit-changes changes)
(dws/select-shapes (d/ordered-set (:id group)))
(ptk/data-event :layout/update [(:id group)])
(ptk/data-event :layout/update {:ids [(:id group)]})
(dwu/commit-undo-transaction undo-id))))))))
(def unmask-group

View file

@ -52,7 +52,7 @@
[potok.v2.core :as ptk]))
;; Change this to :info :debug or :trace to debug this module, or :warn to reset to default
(log/set-level! :trace)
(log/set-level! :warn)
(defn- log-changes
[changes file]
@ -334,7 +334,7 @@
(when-not (empty? (:redo-changes changes))
(rx/of (dch/commit-changes changes)
(dws/select-shapes (d/ordered-set (:id root)))
(ptk/data-event :layout/update parents)))))))))
(ptk/data-event :layout/update {:ids parents})))))))))
(defn add-component
"Add a new component to current file library, from the currently selected shapes.
@ -566,7 +566,7 @@
undo-id (js/Symbol)]
(rx/of (dwu/start-undo-transaction undo-id)
(dch/commit-changes changes)
(ptk/data-event :layout/update [(:id new-shape)])
(ptk/data-event :layout/update {:ids [(:id new-shape)]})
(dws/select-shapes (d/ordered-set (:id new-shape)))
(when start-move?
(dwtr/start-move initial-point #{(:id new-shape)}))
@ -948,7 +948,6 @@
undo-id (js/Symbol)
undo-group (uuid/next)]
(rx/of
(dwu/start-undo-transaction undo-id)
(dwsh/delete-shapes nil (d/ordered-set (:id shape)) {:component-swap true
@ -956,7 +955,7 @@
:undo-group undo-group})
(add-component-for-swap shape file page libraries id-new-component index target-cell keep-props-values
{:undo-group undo-group})
(ptk/data-event :layout/update [(:parent-id shape)])
(ptk/data-event :layout/update {:ids [(:parent-id shape)] :undo-group undo-group})
(dwu/commit-undo-transaction undo-id))))))
(defn component-multi-swap
@ -1082,7 +1081,7 @@
:file-id file-id))))
(when-not (empty? updated-frames)
(rx/merge
(rx/of (ptk/data-event :layout/update (map :id updated-frames)))
(rx/of (ptk/data-event :layout/update {:ids (map :id updated-frames) :undo-group undo-group}))
(->> (rx/from updated-frames)
(rx/mapcat
(fn [shape]

View file

@ -30,7 +30,7 @@
[clojure.set :as set]))
;; Change this to :info :debug or :trace to debug this module, or :warn to reset to default
(log/set-level! :trace)
(log/set-level! :warn)
(declare generate-sync-container)
(declare generate-sync-shape)
@ -320,16 +320,17 @@
(loop [containers (ctf/object-containers-seq file)
changes (pcb/empty-changes it)]
(if-let [container (first containers)]
(recur (next containers)
(pcb/concat-changes
changes
(generate-sync-container it
asset-type
asset-id
library-id
state
container
components-v2)))
(do
(recur (next containers)
(pcb/concat-changes
changes
(generate-sync-container it
asset-type
asset-id
library-id
state
container
components-v2))))
changes))))
(defn generate-sync-library

View file

@ -454,7 +454,7 @@
([]
(apply-modifiers nil))
([{:keys [modifiers undo-transation? stack-undo? ignore-constraints ignore-snap-pixel]
([{:keys [modifiers undo-transation? stack-undo? ignore-constraints ignore-snap-pixel undo-group]
:or {undo-transation? true stack-undo? false ignore-constraints false ignore-snap-pixel false}}]
(ptk/reify ::apply-modifiers
ptk/WatchEvent
@ -504,6 +504,7 @@
{:reg-objects? true
:stack-undo? stack-undo?
:ignore-tree ignore-tree
:undo-group undo-group
;; Attributes that can change in the transform. This way we don't have to check
;; all the attributes
:attrs [:selrect

View file

@ -332,7 +332,7 @@
ptk/WatchEvent
(watch [_ _ _]
(rx/of (ptk/data-event :layout/update [id])))))
(rx/of (ptk/data-event :layout/update {:ids [id]})))))
(defn split-segments
[{:keys [from-p to-p t]}]

View file

@ -751,7 +751,7 @@
(dwu/start-undo-transaction undo-id)
(dch/commit-changes changes)
(select-shapes new-selected)
(ptk/data-event :layout/update frames)
(ptk/data-event :layout/update {:ids frames})
(memorize-duplicated id-original id-duplicated)
(dwu/commit-undo-transaction undo-id))))))))))

View file

@ -94,7 +94,7 @@
;; Never call this directly but through the data-event `:layout/update`
;; Otherwise a lot of cycle dependencies could be generated
(defn- update-layout-positions
[ids]
[{:keys [ids undo-group]}]
(ptk/reify ::update-layout-positions
ptk/WatchEvent
(watch [_ state _]
@ -103,7 +103,8 @@
(if (d/not-empty? ids)
(let [modif-tree (dwm/create-modif-tree ids (ctm/reflow-modifiers))]
(rx/of (dwm/apply-modifiers {:modifiers modif-tree
:stack-undo? true})))
:stack-undo? true
:undo-group undo-group})))
(rx/empty))))))
(defn initialize
@ -139,7 +140,7 @@
(rx/of (dwu/start-undo-transaction undo-id)
(dch/update-shapes [id] layout-initializer {:with-objects? true})
(dch/update-shapes (dm/get-prop parent :shapes) #(dissoc % :constraints-h :constraints-v))
(ptk/data-event :layout/update [id])
(ptk/data-event :layout/update {:ids [id]})
(dwu/commit-undo-transaction undo-id))))))
(defn create-layout-from-selection
@ -180,7 +181,7 @@
(dch/update-shapes [new-shape-id] #(assoc % :layout-item-h-sizing :auto :layout-item-v-sizing :auto))
(dch/update-shapes selected #(assoc % :layout-item-h-sizing :fix :layout-item-v-sizing :fix))
(dwsh/delete-shapes page-id selected)
(ptk/data-event :layout/update [new-shape-id])
(ptk/data-event :layout/update {:ids [new-shape-id]})
(dwu/commit-undo-transaction undo-id)))
;; Create Layout from selection
@ -191,7 +192,7 @@
(dch/update-shapes [new-shape-id] #(assoc % :layout-item-h-sizing :auto :layout-item-v-sizing :auto))
(dch/update-shapes selected #(assoc % :layout-item-h-sizing :fix :layout-item-v-sizing :fix))))
(rx/of (ptk/data-event :layout/update [new-shape-id])
(rx/of (ptk/data-event :layout/update {:ids [new-shape-id]})
(dwu/commit-undo-transaction undo-id)))))))
(defn remove-layout
@ -203,7 +204,7 @@
(rx/of
(dwu/start-undo-transaction undo-id)
(dch/update-shapes ids #(apply dissoc % layout-keys))
(ptk/data-event :layout/update ids)
(ptk/data-event :layout/update {:ids ids})
(dwu/commit-undo-transaction undo-id))))))
(defn create-layout
@ -256,7 +257,7 @@
(let [undo-id (js/Symbol)]
(rx/of (dwu/start-undo-transaction undo-id)
(dch/update-shapes ids (d/patch-object changes))
(ptk/data-event :layout/update ids)
(ptk/data-event :layout/update {:ids ids})
(dwu/commit-undo-transaction undo-id))))))
(defn add-layout-track
@ -275,7 +276,7 @@
(case type
:row (ctl/add-grid-row shape value index)
:column (ctl/add-grid-column shape value index))))
(ptk/data-event :layout/update ids)
(ptk/data-event :layout/update {:ids ids})
(dwu/commit-undo-transaction undo-id)))))))
(defn remove-layout-track
@ -309,7 +310,7 @@
:row (ctl/remove-grid-row shape index objects)
:column (ctl/remove-grid-column shape index objects)))
{:with-objects? true})
(ptk/data-event :layout/update ids)
(ptk/data-event :layout/update {:ids ids})
(dwu/commit-undo-transaction undo-id)))))))
(defn duplicate-layout-track
@ -363,7 +364,7 @@
undo-id (js/Symbol)]
(rx/of (dwu/start-undo-transaction undo-id)
(dch/commit-changes changes)
(ptk/data-event :layout/update ids)
(ptk/data-event :layout/update {:ids ids})
(dwu/commit-undo-transaction undo-id))))))
(defn reorder-layout-track
@ -381,7 +382,7 @@
(case type
:row (ctl/reorder-grid-row shape from-index to-index move-content?)
:column (ctl/reorder-grid-column shape from-index to-index move-content?))))
(ptk/data-event :layout/update ids)
(ptk/data-event :layout/update {:ids ids})
(dwu/commit-undo-transaction undo-id))))))
(defn hover-layout-track
@ -426,7 +427,7 @@
(fn [shape]
(-> shape
(update-in [property index] merge props))))
(ptk/data-event :layout/update ids)
(ptk/data-event :layout/update {:ids ids})
(dwu/commit-undo-transaction undo-id))))))
(defn fix-child-sizing
@ -523,7 +524,7 @@
(cond-> (ctl/grid-layout? parent)
(ctl/assign-cells objects))))
{:with-objects? true})
(ptk/data-event :layout/update ids)
(ptk/data-event :layout/update {:ids ids})
(dwu/commit-undo-transaction undo-id))))))
(defn update-grid-cells
@ -546,7 +547,7 @@
[:layout-grid-cells cell-id]
d/patch-object props))
shape))))
(ptk/data-event :layout/update [layout-id])
(ptk/data-event :layout/update {:ids [layout-id]})
(dwu/commit-undo-transaction undo-id))))))
(defn change-cells-mode
@ -612,7 +613,7 @@
(d/update-in-when [:layout-grid-cells (:id target-cell)] assoc :position :area)))))
{:with-objects? true})
(dwge/clean-selection layout-id)
(ptk/data-event :layout/update [layout-id])
(ptk/data-event :layout/update {:ids [layout-id]})
(dwu/commit-undo-transaction undo-id))))))
(defn merge-cells
@ -644,7 +645,7 @@
(ctl/assign-cells objects))))
{:with-objects? true})
(dwge/clean-selection layout-id)
(ptk/data-event :layout/update [layout-id])
(ptk/data-event :layout/update {:ids [layout-id]})
(dwu/commit-undo-transaction undo-id))))))
(defn update-grid-cell-position
@ -669,7 +670,7 @@
(:row-span new-data) (:column-span new-data))
(ctl/assign-cells objects))))
{:with-objects? true})
(ptk/data-event :layout/update [layout-id])
(ptk/data-event :layout/update {:ids [layout-id]})
(dwu/commit-undo-transaction undo-id))))))
@ -724,5 +725,5 @@
(rx/of
(dwu/start-undo-transaction undo-id)
(dch/commit-changes changes)
(ptk/data-event :layout/update [layout-id])
(ptk/data-event :layout/update {:ids [layout-id]})
(dwu/commit-undo-transaction undo-id))))))

View file

@ -57,7 +57,7 @@
(rx/of (dwu/start-undo-transaction undo-id)
(dch/commit-changes changes)
(when-not no-update-layout?
(ptk/data-event :layout/update [(:parent-id shape)]))
(ptk/data-event :layout/update {:ids [(:parent-id shape)]}))
(when-not no-select?
(dws/select-shapes (d/ordered-set (:id shape))))
(dwu/commit-undo-transaction undo-id))
@ -141,10 +141,11 @@
(rx/concat
(rx/of (dwu/start-undo-transaction undo-id)
(update-shape-flags ids-to-hide {:hidden true}))
(update-shape-flags ids-to-hide {:hidden true :undo-group (:undo-group options)}))
(real-delete-shapes file page objects ids-to-delete it {:components-v2 components-v2
:ignore-touched (:component-swap options)
:undo-group (:undo-group options)})
:undo-group (:undo-group options)
:undo-id undo-id})
(rx/of (dwu/commit-undo-transaction undo-id))))))))
(defn- real-delete-shapes-changes
@ -291,11 +292,11 @@
(defn- real-delete-shapes
[file page objects ids it options]
(let [[changes all-parents] (real-delete-shapes-changes file page objects ids it options)
undo-id (js/Symbol)]
undo-id (or (:undo-id options) (js/Symbol))]
(rx/of (dwu/start-undo-transaction undo-id)
(dc/detach-comment-thread ids)
(dch/commit-changes changes)
(ptk/data-event :layout/update all-parents)
(ptk/data-event :layout/update {:ids all-parents :undo-group (:undo-group options)})
(dwu/commit-undo-transaction undo-id))))
(defn create-and-add-shape
@ -377,7 +378,7 @@
(dwu/start-undo-transaction undo-id)
(dch/commit-changes changes)
(dws/select-shapes (d/ordered-set (:id frame-shape)))
(ptk/data-event :layout/update [(:id frame-shape)])
(ptk/data-event :layout/update {:ids [(:id frame-shape)]})
(dwu/commit-undo-transaction undo-id))))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -385,7 +386,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn update-shape-flags
[ids {:keys [blocked hidden transforming] :as flags}]
[ids {:keys [blocked hidden transforming undo-group] :as flags}]
(dm/assert!
"expected valid coll of uuids"
(every? uuid? ids))
@ -409,7 +410,7 @@
ids (if (boolean? blocked)
(into ids (->> ids (mapcat #(cfh/get-children-ids objects %))))
ids)]
(rx/of (dch/update-shapes ids update-fn {:attrs #{:blocked :hidden :transforming}}))))))
(rx/of (dch/update-shapes ids update-fn {:attrs #{:blocked :hidden :transforming} :undo-group undo-group}))))))
(defn toggle-visibility-selected
[]

View file

@ -102,7 +102,7 @@
(rx/of (dwu/start-undo-transaction undo-id)
(dch/commit-changes changes)
(dws/select-shapes (d/ordered-set (:id new-shape)))
(ptk/data-event :layout/update [(:id new-shape)])
(ptk/data-event :layout/update {:ids [(:id new-shape)]})
(dwu/commit-undo-transaction undo-id)))
(catch :default cause

View file

@ -382,7 +382,7 @@
:stack-undo? true
:ignore-remote? true
:ignore-touched true})
(ptk/data-event :layout/update ids)
(ptk/data-event :layout/update {:ids ids})
(dwu/commit-undo-transaction undo-id))))))))
(defn resize-text

View file

@ -719,7 +719,7 @@
(rx/of
(dwu/start-undo-transaction undo-id)
(dch/commit-changes changes)
(ptk/data-event :layout/update selected)
(ptk/data-event :layout/update {:ids selected})
(dwu/commit-undo-transaction undo-id))))))
(defn nudge-selected-shapes