Add id functionality to undo transactions

This commit is contained in:
Eva 2022-11-22 14:36:45 +01:00 committed by Alonso Torres
parent 32746a5960
commit 694d90d485
15 changed files with 208 additions and 165 deletions

View file

@ -1601,11 +1601,12 @@
:width width :width width
:height height :height height
:grow-type (if (> (count text) 100) :auto-height :auto-width) :grow-type (if (> (count text) 100) :auto-height :auto-width)
:content (as-content text)})] :content (as-content text)})
(rx/of (dwu/start-undo-transaction) undo-id (uuid/next)]
(rx/of (dwu/start-undo-transaction undo-id)
(dws/deselect-all) (dws/deselect-all)
(dwsh/add-shape shape) (dwsh/add-shape shape)
(dwu/commit-undo-transaction)))))) (dwu/commit-undo-transaction undo-id))))))
;; TODO: why not implement it in terms of upload-media-workspace? ;; TODO: why not implement it in terms of upload-media-workspace?
(defn- paste-svg (defn- paste-svg

View file

@ -64,7 +64,7 @@
;; Add & select the created shape to the workspace ;; Add & select the created shape to the workspace
(rx/concat (rx/concat
(if (= :text (:type shape)) (if (= :text (:type shape))
(rx/of (dwu/start-undo-transaction)) (rx/of (dwu/start-undo-transaction (:id shape)))
(rx/empty)) (rx/empty))
(rx/of (dwsh/add-shape shape {:no-select? (= tool :curve)})) (rx/of (dwsh/add-shape shape {:no-select? (= tool :curve)}))

View file

@ -245,10 +245,11 @@
(ctsi/set-action-type :navigate) (ctsi/set-action-type :navigate)
:always :always
(ctsi/set-destination (:id target-frame))))] (ctsi/set-destination (:id target-frame))))
undo-id (uuid/next)]
(rx/of (rx/of
(dwu/start-undo-transaction) (dwu/start-undo-transaction undo-id)
(when (:hide-in-viewer target-frame) (when (:hide-in-viewer target-frame)
; If the target frame is hidden, we need to unhide it so ; If the target frame is hidden, we need to unhide it so
@ -274,7 +275,7 @@
:else :else
(update-interaction shape index change-interaction)) (update-interaction shape index change-interaction))
(dwu/commit-undo-transaction)))))) (dwu/commit-undo-transaction undo-id))))))
;; --- Overlays ;; --- Overlays

View file

@ -152,11 +152,13 @@
color (assoc color :path path :name name) color (assoc color :path path :name name)
changes (-> (pcb/empty-changes it) changes (-> (pcb/empty-changes it)
(pcb/with-library-data data) (pcb/with-library-data data)
(pcb/update-color color))] (pcb/update-color color))
(rx/of (dwu/start-undo-transaction)
undo-id (uuid/next)]
(rx/of (dwu/start-undo-transaction undo-id)
(dch/commit-changes changes) (dch/commit-changes changes)
(sync-file (:current-file-id state) file-id :colors (:id color)) (sync-file (:current-file-id state) file-id :colors (:id color))
(dwu/commit-undo-transaction)))) (dwu/commit-undo-transaction undo-id))))
(defn update-color (defn update-color
[color file-id] [color file-id]
@ -256,11 +258,12 @@
typography (extract-path-if-missing typography) typography (extract-path-if-missing typography)
changes (-> (pcb/empty-changes it) changes (-> (pcb/empty-changes it)
(pcb/with-library-data data) (pcb/with-library-data data)
(pcb/update-typography typography))] (pcb/update-typography typography))
(rx/of (dwu/start-undo-transaction) undo-id (uuid/next)]
(rx/of (dwu/start-undo-transaction undo-id)
(dch/commit-changes changes) (dch/commit-changes changes)
(sync-file (:current-file-id state) file-id :typographies (:id typography)) (sync-file (:current-file-id state) file-id :typographies (:id typography))
(dwu/commit-undo-transaction)))) (dwu/commit-undo-transaction undo-id))))
(defn update-typography (defn update-typography
[typography file-id] [typography file-id]
@ -646,24 +649,26 @@
(watch [_ state _] (watch [_ state _]
(let [current-file-id (:current-file-id state) (let [current-file-id (:current-file-id state)
page (wsh/lookup-page state) page (wsh/lookup-page state)
shape (ctn/get-shape page shape-id)] shape (ctn/get-shape page shape-id)
undo-id (uuid/next)]
(rx/of (rx/of
(dwu/start-undo-transaction) (dwu/start-undo-transaction undo-id)
(update-component shape-id) (update-component shape-id)
(sync-file current-file-id file-id :components (:component-id shape)) (sync-file current-file-id file-id :components (:component-id shape))
(when (not= current-file-id file-id) (when (not= current-file-id file-id)
(sync-file file-id file-id :components (:component-id shape))) (sync-file file-id file-id :components (:component-id shape)))
(dwu/commit-undo-transaction)))))) (dwu/commit-undo-transaction undo-id))))))
(defn update-component-in-bulk (defn update-component-in-bulk
[shapes file-id] [shapes file-id]
(ptk/reify ::update-component-in-bulk (ptk/reify ::update-component-in-bulk
ptk/WatchEvent ptk/WatchEvent
(watch [_ _ _] (watch [_ _ _]
(rx/concat (let [undo-id (uuid/next)]
(rx/of (dwu/start-undo-transaction)) (rx/concat
(rx/of (dwu/start-undo-transaction undo-id))
(rx/map #(update-component-sync (:id %) file-id) (rx/from shapes)) (rx/map #(update-component-sync (:id %) file-id) (rx/from shapes))
(rx/of (dwu/commit-undo-transaction)))))) (rx/of (dwu/commit-undo-transaction undo-id)))))))
(declare sync-file-2nd-stage) (declare sync-file-2nd-stage)

View file

@ -17,6 +17,7 @@
[app.common.types.modifiers :as ctm] [app.common.types.modifiers :as ctm]
[app.common.types.shape :as cts] [app.common.types.shape :as cts]
[app.common.types.shape.layout :as ctl] [app.common.types.shape.layout :as ctl]
[app.common.uuid :as uuid]
[app.main.data.workspace.changes :as dch] [app.main.data.workspace.changes :as dch]
[app.main.data.workspace.comments :as-alias dwcm] [app.main.data.workspace.comments :as-alias dwcm]
[app.main.data.workspace.guides :as-alias dwg] [app.main.data.workspace.guides :as-alias dwg]
@ -293,11 +294,12 @@
shapes (map (d/getf objects) ids) shapes (map (d/getf objects) ids)
ignore-tree (->> (map #(get-ignore-tree object-modifiers objects %) shapes) ignore-tree (->> (map #(get-ignore-tree object-modifiers objects %) shapes)
(reduce merge {}))] (reduce merge {}))
undo-id (uuid/next)]
(rx/concat (rx/concat
(if undo-transation? (if undo-transation?
(rx/of (dwu/start-undo-transaction)) (rx/of (dwu/start-undo-transaction undo-id))
(rx/empty)) (rx/empty))
(rx/of (ptk/event ::dwg/move-frame-guides ids-with-children) (rx/of (ptk/event ::dwg/move-frame-guides ids-with-children)
(ptk/event ::dwcm/move-frame-comment-threads ids-with-children) (ptk/event ::dwcm/move-frame-comment-threads ids-with-children)
@ -333,5 +335,5 @@
]}) ]})
(clear-local-transform)) (clear-local-transform))
(if undo-transation? (if undo-transation?
(rx/of (dwu/commit-undo-transaction)) (rx/of (dwu/commit-undo-transaction undo-id))
(rx/empty)))))))) (rx/empty))))))))

View file

@ -17,6 +17,7 @@
[app.main.data.workspace.shapes :as dws] [app.main.data.workspace.shapes :as dws]
[app.main.data.workspace.shapes-update-layout :as wsul] [app.main.data.workspace.shapes-update-layout :as wsul]
[app.main.data.workspace.state-helpers :as wsh] [app.main.data.workspace.state-helpers :as wsh]
[app.main.data.workspace.undo :as dwu]
[beicon.core :as rx] [beicon.core :as rx]
[potok.core :as ptk])) [potok.core :as ptk]))
@ -110,8 +111,12 @@
(ptk/reify ::remove-layout (ptk/reify ::remove-layout
ptk/WatchEvent ptk/WatchEvent
(watch [_ _ _] (watch [_ _ _]
(rx/of (dwc/update-shapes ids #(apply dissoc % layout-keys)) (let [undo-id (uuid/next)]
(wsul/update-layout-positions ids))))) (rx/of
(dwu/start-undo-transaction undo-id)
(dwc/update-shapes ids #(apply dissoc % layout-keys))
(wsul/update-layout-positions ids)
(dwu/commit-undo-transaction undo-id))))))
(defn create-layout (defn create-layout
[] []

View file

@ -79,7 +79,7 @@
(assoc :content content) (assoc :content content)
(merge modifiers) (merge modifiers)
(cts/setup-rect-selrect)))) (cts/setup-rect-selrect))))
(dwu/commit-undo-transaction))))) (dwu/commit-undo-transaction (:id shape))))))
(when (some? id) (when (some? id)
(rx/of (dws/deselect-shape id) (rx/of (dws/deselect-shape id)

View file

@ -19,6 +19,7 @@
[app.common.types.modifiers :as ctm] [app.common.types.modifiers :as ctm]
[app.common.types.shape-tree :as ctst] [app.common.types.shape-tree :as ctst]
[app.common.types.shape.layout :as ctl] [app.common.types.shape.layout :as ctl]
[app.common.uuid :as uuid]
[app.main.data.workspace.changes :as dch] [app.main.data.workspace.changes :as dch]
[app.main.data.workspace.collapse :as dwc] [app.main.data.workspace.collapse :as dwc]
[app.main.data.workspace.modifiers :as dwm] [app.main.data.workspace.modifiers :as dwm]
@ -504,11 +505,12 @@
(rx/last) (rx/last)
(rx/mapcat (rx/mapcat
(fn [[_ target-frame drop-index]] (fn [[_ target-frame drop-index]]
(rx/of (dwu/start-undo-transaction) (let [undo-id (uuid/next)]
(rx/of (dwu/start-undo-transaction undo-id)
(move-shapes-to-frame ids target-frame drop-index) (move-shapes-to-frame ids target-frame drop-index)
(dwm/apply-modifiers {:undo-transation? false}) (dwm/apply-modifiers {:undo-transation? false})
(finish-transform) (finish-transform)
(dwu/commit-undo-transaction))))))))))))) (dwu/commit-undo-transaction undo-id))))))))))))))
(s/def ::direction #{:up :down :right :left}) (s/def ::direction #{:up :down :right :left})

View file

@ -73,28 +73,34 @@
(def empty-tx (def empty-tx
{:undo-changes [] :redo-changes []}) {:undo-changes [] :redo-changes []})
(defn start-undo-transaction [] (defn start-undo-transaction [id]
(ptk/reify ::start-undo-transaction (ptk/reify ::start-undo-transaction
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
;; We commit the old transaction before starting the new one ;; We commit the old transaction before starting the new one
(let [current-tx (get-in state [:workspace-undo :transaction])] (let [current-tx (get-in state [:workspace-undo :transaction])
pending-tx (get-in state [:workspace-undo :transactions-pending])]
(cond-> state (cond-> state
(nil? current-tx) (assoc-in [:workspace-undo :transaction] empty-tx)))))) (nil? current-tx) (assoc-in [:workspace-undo :transaction] empty-tx)
(nil? pending-tx) (assoc-in [:workspace-undo :transactions-pending] #{id})
(some? pending-tx) (update-in [:workspace-undo :transactions-pending] conj id))))))
(defn discard-undo-transaction [] (defn discard-undo-transaction []
(ptk/reify ::discard-undo-transaction (ptk/reify ::discard-undo-transaction
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(update state :workspace-undo dissoc :transaction)))) (update state :workspace-undo dissoc :transaction :transactions-pending))))
(defn commit-undo-transaction [] (defn commit-undo-transaction [id]
(ptk/reify ::commit-undo-transaction (ptk/reify ::commit-undo-transaction
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(-> state (let [state (update-in state [:workspace-undo :transactions-pending] disj id)]
(add-undo-entry (get-in state [:workspace-undo :transaction])) (if (empty? (get-in state [:workspace-undo :transactions-pending]))
(update :workspace-undo dissoc :transaction))))) (-> state
(add-undo-entry (get-in state [:workspace-undo :transaction]))
(update :workspace-undo dissoc :transaction))
state)))))
(def pop-undo-into-transaction (def pop-undo-into-transaction
(ptk/reify ::last-undo-into-transaction (ptk/reify ::last-undo-into-transaction

View file

@ -108,13 +108,13 @@
(mf/use-fn (mf/use-fn
(fn [] (fn []
(reset! drag? true) (reset! drag? true)
(st/emit! (dwu/start-undo-transaction)))) (st/emit! (dwu/start-undo-transaction (mf/ref-val node-ref)))))
on-finish-drag on-finish-drag
(mf/use-fn (mf/use-fn
(fn [] (fn []
(reset! drag? false) (reset! drag? false)
(st/emit! (dwu/commit-undo-transaction))))] (st/emit! (dwu/commit-undo-transaction (mf/ref-val node-ref)))))]
;; Initialize colorpicker state ;; Initialize colorpicker state
(mf/with-effect [] (mf/with-effect []

View file

@ -12,6 +12,7 @@
[app.common.pages.helpers :as cph] [app.common.pages.helpers :as cph]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.text :as txt] [app.common.text :as txt]
[app.common.uuid :as uuid]
[app.config :as cf] [app.config :as cf]
[app.main.data.events :as ev] [app.main.data.events :as ev]
[app.main.data.modal :as modal] [app.main.data.modal :as modal]
@ -181,13 +182,14 @@
(defn- create-assets-group (defn- create-assets-group
[rename components-to-group group-name] [rename components-to-group group-name]
(st/emit! (dwu/start-undo-transaction)) (let [undo-id (uuid/next)]
(st/emit! (dwu/start-undo-transaction undo-id))
(apply st/emit! (apply st/emit!
(->> components-to-group (->> components-to-group
(map #(rename (map #(rename
(:id %) (:id %)
(add-group % group-name))))) (add-group % group-name)))))
(st/emit! (dwu/commit-undo-transaction))) (st/emit! (dwu/commit-undo-transaction undo-id))))
(defn- on-drop-asset (defn- on-drop-asset
[event asset dragging? selected-assets selected-assets-full selected-assets-paths rename] [event asset dragging? selected-assets selected-assets-full selected-assets-paths rename]
@ -589,23 +591,25 @@
(mf/use-fn (mf/use-fn
(mf/deps @state) (mf/deps @state)
(fn [] (fn []
(if (empty? selected-components) (let [undo-id (uuid/next)]
(if (empty? selected-components)
(st/emit! (dwl/duplicate-component {:id (:component-id @state)})) (st/emit! (dwl/duplicate-component {:id (:component-id @state)}))
(do (do
(st/emit! (dwu/start-undo-transaction)) (st/emit! (dwu/start-undo-transaction undo-id))
(apply st/emit! (map #(dwl/duplicate-component {:id %}) selected-components)) (apply st/emit! (map #(dwl/duplicate-component {:id %}) selected-components))
(st/emit! (dwu/commit-undo-transaction)))))) (st/emit! (dwu/commit-undo-transaction undo-id)))))))
on-delete on-delete
(mf/use-fn (mf/use-fn
(mf/deps @state file-id multi-components? multi-assets?) (mf/deps @state file-id multi-components? multi-assets?)
(fn [] (fn []
(if (or multi-components? multi-assets?) (let [undo-id (uuid/next)]
(if (or multi-components? multi-assets?)
(on-assets-delete) (on-assets-delete)
(st/emit! (dwu/start-undo-transaction) (st/emit! (dwu/start-undo-transaction undo-id)
(dwl/delete-component {:id (:component-id @state)}) (dwl/delete-component {:id (:component-id @state)})
(dwl/sync-file file-id file-id :components (:component-id @state)) (dwl/sync-file file-id file-id :components (:component-id @state))
(dwu/commit-undo-transaction))))) (dwu/commit-undo-transaction undo-id))))))
on-rename on-rename
(mf/use-fn (mf/use-fn
@ -646,30 +650,32 @@
(mf/deps components selected-components on-clear-selection) (mf/deps components selected-components on-clear-selection)
(fn [group-name] (fn [group-name]
(on-clear-selection) (on-clear-selection)
(st/emit! (dwu/start-undo-transaction)) (let [undo-id (uuid/next)]
(apply st/emit! (st/emit! (dwu/start-undo-transaction undo-id))
(->> components (apply st/emit!
(filter #(if multi-components? (->> components
(contains? selected-components (:id %)) (filter #(if multi-components?
(= (:component-id @state) (:id %)))) (contains? selected-components (:id %))
(map #(dwl/rename-component (= (:component-id @state) (:id %))))
(:id %) (map #(dwl/rename-component
(add-group % group-name))))) (:id %)
(st/emit! (dwu/commit-undo-transaction)))) (add-group % group-name)))))
(st/emit! (dwu/commit-undo-transaction undo-id)))))
rename-group rename-group
(mf/use-fn (mf/use-fn
(mf/deps components) (mf/deps components)
(fn [path last-path] (fn [path last-path]
(on-clear-selection) (on-clear-selection)
(st/emit! (dwu/start-undo-transaction)) (let [undo-id (uuid/next)]
(apply st/emit! (st/emit! (dwu/start-undo-transaction undo-id))
(->> components (apply st/emit!
(filter #(str/starts-with? (:path %) path)) (->> components
(map #(dwl/rename-component (filter #(str/starts-with? (:path %) path))
(:id %) (map #(dwl/rename-component
(rename-group % path last-path))))) (:id %)
(st/emit! (dwu/commit-undo-transaction)))) (rename-group % path last-path)))))
(st/emit! (dwu/commit-undo-transaction undo-id)))))
on-group on-group
(mf/use-fn (mf/use-fn
@ -692,14 +698,15 @@
(mf/deps components) (mf/deps components)
(fn [path] (fn [path]
(on-clear-selection) (on-clear-selection)
(st/emit! (dwu/start-undo-transaction)) (let [undo-id (uuid/next)]
(apply st/emit! (st/emit! (dwu/start-undo-transaction undo-id))
(->> components (apply st/emit!
(filter #(str/starts-with? (:path %) path)) (->> components
(map #(dwl/rename-component (filter #(str/starts-with? (:path %) path))
(:id %) (map #(dwl/rename-component
(ungroup % path))))) (:id %)
(st/emit! (dwu/commit-undo-transaction)))) (ungroup % path)))))
(st/emit! (dwu/commit-undo-transaction undo-id)))))
on-drag-start on-drag-start
(mf/use-fn (mf/use-fn
@ -1015,30 +1022,32 @@
(mf/deps objects selected-objects on-clear-selection) (mf/deps objects selected-objects on-clear-selection)
(fn [group-name] (fn [group-name]
(on-clear-selection) (on-clear-selection)
(st/emit! (dwu/start-undo-transaction)) (let [undo-id (uuid/next)]
(apply st/emit! (st/emit! (dwu/start-undo-transaction undo-id))
(->> objects (apply st/emit!
(filter #(if multi-objects? (->> objects
(contains? selected-objects (:id %)) (filter #(if multi-objects?
(= (:object-id @state) (:id %)))) (contains? selected-objects (:id %))
(map #(dwl/rename-media (= (:object-id @state) (:id %))))
(:id %) (map #(dwl/rename-media
(add-group % group-name))))) (:id %)
(st/emit! (dwu/commit-undo-transaction)))) (add-group % group-name)))))
(st/emit! (dwu/commit-undo-transaction undo-id)))))
rename-group rename-group
(mf/use-fn (mf/use-fn
(mf/deps objects) (mf/deps objects)
(fn [path last-path] (fn [path last-path]
(on-clear-selection) (on-clear-selection)
(st/emit! (dwu/start-undo-transaction)) (let [undo-id (uuid/next)]
(apply st/emit! (st/emit! (dwu/start-undo-transaction undo-id))
(->> objects (apply st/emit!
(filter #(str/starts-with? (:path %) path)) (->> objects
(map #(dwl/rename-media (filter #(str/starts-with? (:path %) path))
(:id %) (map #(dwl/rename-media
(rename-group % path last-path))))) (:id %)
(st/emit! (dwu/commit-undo-transaction)))) (rename-group % path last-path)))))
(st/emit! (dwu/commit-undo-transaction undo-id)))))
on-group on-group
(mf/use-fn (mf/use-fn
@ -1060,14 +1069,15 @@
(mf/deps objects) (mf/deps objects)
(fn [path] (fn [path]
(on-clear-selection) (on-clear-selection)
(st/emit! (dwu/start-undo-transaction)) (let [undo-id (uuid/next)]
(apply st/emit! (st/emit! (dwu/start-undo-transaction undo-id))
(->> objects (apply st/emit!
(filter #(str/starts-with? (:path %) path)) (->> objects
(map #(dwl/rename-media (filter #(str/starts-with? (:path %) path))
(:id %) (map #(dwl/rename-media
(ungroup % path))))) (:id %)
(st/emit! (dwu/commit-undo-transaction)))) (ungroup % path)))))
(st/emit! (dwu/commit-undo-transaction undo-id)))))
on-drag-start on-drag-start
(mf/use-fn (mf/use-fn
@ -1175,10 +1185,11 @@
(fn [] (fn []
(if (or multi-colors? multi-assets?) (if (or multi-colors? multi-assets?)
(on-assets-delete) (on-assets-delete)
(st/emit! (dwu/start-undo-transaction) (let [undo-id (uuid/next)]
(st/emit! (dwu/start-undo-transaction undo-id)
(dwl/delete-color color) (dwl/delete-color color)
(dwl/sync-file file-id file-id :colors (:id color)) (dwl/sync-file file-id file-id :colors (:id color))
(dwu/commit-undo-transaction))))) (dwu/commit-undo-transaction undo-id))))))
rename-color-clicked rename-color-clicked
(fn [event] (fn [event]
@ -1436,7 +1447,8 @@
(fn [color-id] (fn [color-id]
(fn [group-name] (fn [group-name]
(on-clear-selection) (on-clear-selection)
(st/emit! (dwu/start-undo-transaction)) (let [undo-id (uuid/next)]
(st/emit! (dwu/start-undo-transaction undo-id))
(apply st/emit! (apply st/emit!
(->> colors (->> colors
(filter #(if multi-colors? (filter #(if multi-colors?
@ -1446,22 +1458,23 @@
(assoc % :name (assoc % :name
(add-group % group-name)) (add-group % group-name))
file-id)))) file-id))))
(st/emit! (dwu/commit-undo-transaction))))) (st/emit! (dwu/commit-undo-transaction undo-id))))))
rename-group rename-group
(mf/use-fn (mf/use-fn
(mf/deps colors) (mf/deps colors)
(fn [path last-path] (fn [path last-path]
(on-clear-selection) (on-clear-selection)
(st/emit! (dwu/start-undo-transaction)) (let [undo-id (uuid/next)]
(apply st/emit! (st/emit! (dwu/start-undo-transaction undo-id))
(->> colors (apply st/emit!
(filter #(str/starts-with? (:path %) path)) (->> colors
(map #(dwl/update-color (filter #(str/starts-with? (:path %) path))
(assoc % :name (map #(dwl/update-color
(rename-group % path last-path)) (assoc % :name
file-id)))) (rename-group % path last-path))
(st/emit! (dwu/commit-undo-transaction)))) file-id))))
(st/emit! (dwu/commit-undo-transaction undo-id)))))
on-group on-group
(mf/use-fn (mf/use-fn
@ -1484,15 +1497,16 @@
(mf/deps colors) (mf/deps colors)
(fn [path] (fn [path]
(on-clear-selection) (on-clear-selection)
(st/emit! (dwu/start-undo-transaction)) (let [undo-id (uuid/next)]
(apply st/emit! (st/emit! (dwu/start-undo-transaction undo-id))
(->> colors (apply st/emit!
(filter #(str/starts-with? (:path %) path)) (->> colors
(map #(dwl/update-color (filter #(str/starts-with? (:path %) path))
(assoc % :name (map #(dwl/update-color
(ungroup % path)) (assoc % :name
file-id)))) (ungroup % path))
(st/emit! (dwu/commit-undo-transaction))))] file-id))))
(st/emit! (dwu/commit-undo-transaction undo-id)))))]
[:& asset-section {:file-id file-id [:& asset-section {:file-id file-id
:title (tr "workspace.assets.colors") :title (tr "workspace.assets.colors")
@ -1724,32 +1738,34 @@
(mf/deps typographies selected-typographies on-clear-selection file-id) (mf/deps typographies selected-typographies on-clear-selection file-id)
(fn [group-name] (fn [group-name]
(on-clear-selection) (on-clear-selection)
(st/emit! (dwu/start-undo-transaction)) (let [undo-id (uuid/next)]
(apply st/emit! (st/emit! (dwu/start-undo-transaction undo-id))
(->> typographies (apply st/emit!
(filter #(if multi-typographies? (->> typographies
(contains? selected-typographies (:id %)) (filter #(if multi-typographies?
(= (:id @state) (:id %)))) (contains? selected-typographies (:id %))
(map #(dwl/update-typography (= (:id @state) (:id %))))
(assoc % :name (map #(dwl/update-typography
(add-group % group-name)) (assoc % :name
file-id)))) (add-group % group-name))
(st/emit! (dwu/commit-undo-transaction)))) file-id))))
(st/emit! (dwu/commit-undo-transaction undo-id)))))
rename-group rename-group
(mf/use-fn (mf/use-fn
(mf/deps typographies) (mf/deps typographies)
(fn [path last-path] (fn [path last-path]
(on-clear-selection) (on-clear-selection)
(st/emit! (dwu/start-undo-transaction)) (let [undo-id (uuid/next)]
(apply st/emit! (st/emit! (dwu/start-undo-transaction undo-id))
(->> typographies (apply st/emit!
(filter #(str/starts-with? (:path %) path)) (->> typographies
(map #(dwl/update-typography (filter #(str/starts-with? (:path %) path))
(assoc % :name (map #(dwl/update-typography
(rename-group % path last-path)) (assoc % :name
file-id)))) (rename-group % path last-path))
(st/emit! (dwu/commit-undo-transaction)))) file-id))))
(st/emit! (dwu/commit-undo-transaction undo-id)))))
on-group on-group
(mf/use-fn (mf/use-fn
@ -1771,15 +1787,16 @@
(mf/deps typographies) (mf/deps typographies)
(fn [path] (fn [path]
(on-clear-selection) (on-clear-selection)
(st/emit! (dwu/start-undo-transaction)) (let [undo-id (uuid/next)]
(apply st/emit! (st/emit! (dwu/start-undo-transaction undo-id))
(->> typographies (apply st/emit!
(filter #(str/starts-with? (:path %) path)) (->> typographies
(map #(dwl/rename-typography (filter #(str/starts-with? (:path %) path))
file-id (map #(dwl/rename-typography
(:id %) file-id
(ungroup % path))))) (:id %)
(st/emit! (dwu/commit-undo-transaction)))) (ungroup % path)))))
(st/emit! (dwu/commit-undo-transaction undo-id)))))
on-context-menu on-context-menu
(mf/use-fn (mf/use-fn
@ -1808,12 +1825,13 @@
(mf/use-fn (mf/use-fn
(mf/deps @state multi-typographies? multi-assets?) (mf/deps @state multi-typographies? multi-assets?)
(fn [] (fn []
(if (or multi-typographies? multi-assets?) (let [undo-id (uuid/next)]
(on-assets-delete) (if (or multi-typographies? multi-assets?)
(st/emit! (dwu/start-undo-transaction) (on-assets-delete)
(dwl/delete-typography (:id @state)) (st/emit! (dwu/start-undo-transaction undo-id)
(dwl/sync-file file-id file-id :typographies (:id @state)) (dwl/delete-typography (:id @state))
(dwu/commit-undo-transaction))))) (dwl/sync-file file-id file-id :typographies (:id @state))
(dwu/commit-undo-transaction undo-id))))))
editing-id (or (:rename-typography local-data) editing-id (or (:rename-typography local-data)
(:edit-typography local-data))] (:edit-typography local-data))]
@ -2045,7 +2063,8 @@
(mf/use-fn (mf/use-fn
(mf/deps selected-assets) (mf/deps selected-assets)
(fn [] (fn []
(st/emit! (dwu/start-undo-transaction)) (let [undo-id (uuid/next)]
(st/emit! (dwu/start-undo-transaction undo-id))
(apply st/emit! (map #(dwl/delete-component {:id %}) (apply st/emit! (map #(dwl/delete-component {:id %})
(:components selected-assets))) (:components selected-assets)))
(apply st/emit! (map #(dwl/delete-media {:id %}) (apply st/emit! (map #(dwl/delete-media {:id %})
@ -2058,7 +2077,7 @@
(d/not-empty? (:colors selected-assets)) (d/not-empty? (:colors selected-assets))
(d/not-empty? (:typographies selected-assets))) (d/not-empty? (:typographies selected-assets)))
(st/emit! (dwl/sync-file (:id file) (:id file)))) (st/emit! (dwl/sync-file (:id file) (:id file))))
(st/emit! (dwu/commit-undo-transaction))))] (st/emit! (dwu/commit-undo-transaction undo-id)))))]
[:div.tool-window {:on-context-menu #(dom/prevent-default %) [:div.tool-window {:on-context-menu #(dom/prevent-default %)
:on-click unselect-all} :on-click unselect-all}

View file

@ -10,6 +10,7 @@
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.types.shape.layout :as ctl] [app.common.types.shape.layout :as ctl]
[app.common.types.shape.radius :as ctsr] [app.common.types.shape.radius :as ctsr]
[app.common.uuid :as uuid]
[app.main.constants :refer [size-presets]] [app.main.constants :refer [size-presets]]
[app.main.data.workspace :as udw] [app.main.data.workspace :as udw]
[app.main.data.workspace.changes :as dch] [app.main.data.workspace.changes :as dch]
@ -248,9 +249,10 @@
(mf/use-callback (mf/use-callback
(mf/deps ids) (mf/deps ids)
(fn [event] (fn [event]
(let [value (-> event dom/get-target dom/checked?)] (let [value (-> event dom/get-target dom/checked?)
undo-id (uuid/next)]
(do (do
(st/emit! (dwu/start-undo-transaction) (st/emit! (dwu/start-undo-transaction undo-id)
(dch/update-shapes ids (fn [shape] (assoc shape :hide-in-viewer (not value))))) (dch/update-shapes ids (fn [shape] (assoc shape :hide-in-viewer (not value)))))
(when-not value (when-not value
@ -258,7 +260,7 @@
;; interactions that navigate to it. ;; interactions that navigate to it.
(apply st/emit! (map #(dwi/remove-all-interactions-nav-to %) ids))) (apply st/emit! (map #(dwi/remove-all-interactions-nav-to %) ids)))
(st/emit! (dwu/commit-undo-transaction)))))) (st/emit! (dwu/commit-undo-transaction undo-id))))))
select-all #(-> % (dom/get-target) (.select))] select-all #(-> % (dom/get-target) (.select))]

View file

@ -192,8 +192,8 @@
:disable-gradient true :disable-gradient true
:on-change (update-color index) :on-change (update-color index)
:on-detach (detach-color index) :on-detach (detach-color index)
:on-open #(st/emit! (dwu/start-undo-transaction)) :on-open #(st/emit! (dwu/start-undo-transaction :color-row))
:on-close #(st/emit! (dwu/commit-undo-transaction))}]]]])) :on-close #(st/emit! (dwu/commit-undo-transaction :color-row))}]]]]))
(mf/defc shadow-menu (mf/defc shadow-menu
[{:keys [ids type values] :as props}] [{:keys [ids type values] :as props}]
(let [on-remove-all-shadows (let [on-remove-all-shadows

View file

@ -27,11 +27,11 @@
on-open on-open
(fn [] (fn []
(st/emit! (dwu/start-undo-transaction))) (st/emit! (dwu/start-undo-transaction :options)))
on-close on-close
(fn [] (fn []
(st/emit! (dwu/commit-undo-transaction)))] (st/emit! (dwu/commit-undo-transaction :options)))]
[:div.element-set [:div.element-set
[:div.element-set-title (tr "workspace.options.canvas-background")] [:div.element-set-title (tr "workspace.options.canvas-background")]

View file

@ -114,7 +114,7 @@
(fn [event] (fn [event]
(dom/prevent-default event) (dom/prevent-default event)
(dom/stop-propagation event) (dom/stop-propagation event)
(st/emit! (dwu/start-undo-transaction) (st/emit! (dwu/start-undo-transaction :mouse-down-picker)
(dwc/pick-color-select true (kbd/shift? event))))) (dwc/pick-color-select true (kbd/shift? event)))))
handle-mouse-up-picker handle-mouse-up-picker
@ -122,7 +122,7 @@
(fn [event] (fn [event]
(dom/prevent-default event) (dom/prevent-default event)
(dom/stop-propagation event) (dom/stop-propagation event)
(st/emit! (dwu/commit-undo-transaction) (st/emit! (dwu/commit-undo-transaction :mouse-down-picker)
(dwc/stop-picker)) (dwc/stop-picker))
(modal/disallow-click-outside!))) (modal/disallow-click-outside!)))