mirror of
https://github.com/penpot/penpot.git
synced 2025-01-08 07:50:43 -05:00
✨ Add id functionality to undo transactions
This commit is contained in:
parent
32746a5960
commit
694d90d485
15 changed files with 208 additions and 165 deletions
|
@ -1601,11 +1601,12 @@
|
|||
:width width
|
||||
:height height
|
||||
:grow-type (if (> (count text) 100) :auto-height :auto-width)
|
||||
:content (as-content text)})]
|
||||
(rx/of (dwu/start-undo-transaction)
|
||||
:content (as-content text)})
|
||||
undo-id (uuid/next)]
|
||||
(rx/of (dwu/start-undo-transaction undo-id)
|
||||
(dws/deselect-all)
|
||||
(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?
|
||||
(defn- paste-svg
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
;; Add & select the created shape to the workspace
|
||||
(rx/concat
|
||||
(if (= :text (:type shape))
|
||||
(rx/of (dwu/start-undo-transaction))
|
||||
(rx/of (dwu/start-undo-transaction (:id shape)))
|
||||
(rx/empty))
|
||||
|
||||
(rx/of (dwsh/add-shape shape {:no-select? (= tool :curve)}))
|
||||
|
|
|
@ -245,10 +245,11 @@
|
|||
(ctsi/set-action-type :navigate)
|
||||
|
||||
:always
|
||||
(ctsi/set-destination (:id target-frame))))]
|
||||
(ctsi/set-destination (:id target-frame))))
|
||||
undo-id (uuid/next)]
|
||||
|
||||
(rx/of
|
||||
(dwu/start-undo-transaction)
|
||||
(dwu/start-undo-transaction undo-id)
|
||||
|
||||
(when (:hide-in-viewer target-frame)
|
||||
; If the target frame is hidden, we need to unhide it so
|
||||
|
@ -274,7 +275,7 @@
|
|||
:else
|
||||
(update-interaction shape index change-interaction))
|
||||
|
||||
(dwu/commit-undo-transaction))))))
|
||||
(dwu/commit-undo-transaction undo-id))))))
|
||||
|
||||
;; --- Overlays
|
||||
|
||||
|
|
|
@ -152,11 +152,13 @@
|
|||
color (assoc color :path path :name name)
|
||||
changes (-> (pcb/empty-changes it)
|
||||
(pcb/with-library-data data)
|
||||
(pcb/update-color color))]
|
||||
(rx/of (dwu/start-undo-transaction)
|
||||
(pcb/update-color color))
|
||||
|
||||
undo-id (uuid/next)]
|
||||
(rx/of (dwu/start-undo-transaction undo-id)
|
||||
(dch/commit-changes changes)
|
||||
(sync-file (:current-file-id state) file-id :colors (:id color))
|
||||
(dwu/commit-undo-transaction))))
|
||||
(dwu/commit-undo-transaction undo-id))))
|
||||
|
||||
(defn update-color
|
||||
[color file-id]
|
||||
|
@ -256,11 +258,12 @@
|
|||
typography (extract-path-if-missing typography)
|
||||
changes (-> (pcb/empty-changes it)
|
||||
(pcb/with-library-data data)
|
||||
(pcb/update-typography typography))]
|
||||
(rx/of (dwu/start-undo-transaction)
|
||||
(pcb/update-typography typography))
|
||||
undo-id (uuid/next)]
|
||||
(rx/of (dwu/start-undo-transaction undo-id)
|
||||
(dch/commit-changes changes)
|
||||
(sync-file (:current-file-id state) file-id :typographies (:id typography))
|
||||
(dwu/commit-undo-transaction))))
|
||||
(dwu/commit-undo-transaction undo-id))))
|
||||
|
||||
(defn update-typography
|
||||
[typography file-id]
|
||||
|
@ -646,24 +649,26 @@
|
|||
(watch [_ state _]
|
||||
(let [current-file-id (:current-file-id 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
|
||||
(dwu/start-undo-transaction)
|
||||
(dwu/start-undo-transaction undo-id)
|
||||
(update-component shape-id)
|
||||
(sync-file current-file-id file-id :components (:component-id shape))
|
||||
(when (not= current-file-id file-id)
|
||||
(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
|
||||
[shapes file-id]
|
||||
(ptk/reify ::update-component-in-bulk
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
(rx/concat
|
||||
(rx/of (dwu/start-undo-transaction))
|
||||
(let [undo-id (uuid/next)]
|
||||
(rx/concat
|
||||
(rx/of (dwu/start-undo-transaction undo-id))
|
||||
(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)
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
[app.common.types.modifiers :as ctm]
|
||||
[app.common.types.shape :as cts]
|
||||
[app.common.types.shape.layout :as ctl]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.workspace.changes :as dch]
|
||||
[app.main.data.workspace.comments :as-alias dwcm]
|
||||
[app.main.data.workspace.guides :as-alias dwg]
|
||||
|
@ -293,11 +294,12 @@
|
|||
|
||||
shapes (map (d/getf objects) ids)
|
||||
ignore-tree (->> (map #(get-ignore-tree object-modifiers objects %) shapes)
|
||||
(reduce merge {}))]
|
||||
(reduce merge {}))
|
||||
undo-id (uuid/next)]
|
||||
|
||||
(rx/concat
|
||||
(if undo-transation?
|
||||
(rx/of (dwu/start-undo-transaction))
|
||||
(rx/of (dwu/start-undo-transaction undo-id))
|
||||
(rx/empty))
|
||||
(rx/of (ptk/event ::dwg/move-frame-guides ids-with-children)
|
||||
(ptk/event ::dwcm/move-frame-comment-threads ids-with-children)
|
||||
|
@ -333,5 +335,5 @@
|
|||
]})
|
||||
(clear-local-transform))
|
||||
(if undo-transation?
|
||||
(rx/of (dwu/commit-undo-transaction))
|
||||
(rx/of (dwu/commit-undo-transaction undo-id))
|
||||
(rx/empty))))))))
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
[app.main.data.workspace.shapes :as dws]
|
||||
[app.main.data.workspace.shapes-update-layout :as wsul]
|
||||
[app.main.data.workspace.state-helpers :as wsh]
|
||||
[app.main.data.workspace.undo :as dwu]
|
||||
[beicon.core :as rx]
|
||||
[potok.core :as ptk]))
|
||||
|
||||
|
@ -110,8 +111,12 @@
|
|||
(ptk/reify ::remove-layout
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
(rx/of (dwc/update-shapes ids #(apply dissoc % layout-keys))
|
||||
(wsul/update-layout-positions ids)))))
|
||||
(let [undo-id (uuid/next)]
|
||||
(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
|
||||
[]
|
||||
|
|
|
@ -79,7 +79,7 @@
|
|||
(assoc :content content)
|
||||
(merge modifiers)
|
||||
(cts/setup-rect-selrect))))
|
||||
(dwu/commit-undo-transaction)))))
|
||||
(dwu/commit-undo-transaction (:id shape))))))
|
||||
|
||||
(when (some? id)
|
||||
(rx/of (dws/deselect-shape id)
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
[app.common.types.modifiers :as ctm]
|
||||
[app.common.types.shape-tree :as ctst]
|
||||
[app.common.types.shape.layout :as ctl]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.workspace.changes :as dch]
|
||||
[app.main.data.workspace.collapse :as dwc]
|
||||
[app.main.data.workspace.modifiers :as dwm]
|
||||
|
@ -504,11 +505,12 @@
|
|||
(rx/last)
|
||||
(rx/mapcat
|
||||
(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)
|
||||
(dwm/apply-modifiers {:undo-transation? false})
|
||||
(finish-transform)
|
||||
(dwu/commit-undo-transaction)))))))))))))
|
||||
(dwu/commit-undo-transaction undo-id))))))))))))))
|
||||
|
||||
(s/def ::direction #{:up :down :right :left})
|
||||
|
||||
|
|
|
@ -73,28 +73,34 @@
|
|||
(def empty-tx
|
||||
{:undo-changes [] :redo-changes []})
|
||||
|
||||
(defn start-undo-transaction []
|
||||
(defn start-undo-transaction [id]
|
||||
(ptk/reify ::start-undo-transaction
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
;; 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
|
||||
(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 []
|
||||
(ptk/reify ::discard-undo-transaction
|
||||
ptk/UpdateEvent
|
||||
(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/UpdateEvent
|
||||
(update [_ state]
|
||||
(-> state
|
||||
(add-undo-entry (get-in state [:workspace-undo :transaction]))
|
||||
(update :workspace-undo dissoc :transaction)))))
|
||||
(let [state (update-in state [:workspace-undo :transactions-pending] disj id)]
|
||||
(if (empty? (get-in state [:workspace-undo :transactions-pending]))
|
||||
(-> state
|
||||
(add-undo-entry (get-in state [:workspace-undo :transaction]))
|
||||
(update :workspace-undo dissoc :transaction))
|
||||
state)))))
|
||||
|
||||
(def pop-undo-into-transaction
|
||||
(ptk/reify ::last-undo-into-transaction
|
||||
|
|
|
@ -108,13 +108,13 @@
|
|||
(mf/use-fn
|
||||
(fn []
|
||||
(reset! drag? true)
|
||||
(st/emit! (dwu/start-undo-transaction))))
|
||||
(st/emit! (dwu/start-undo-transaction (mf/ref-val node-ref)))))
|
||||
|
||||
on-finish-drag
|
||||
(mf/use-fn
|
||||
(fn []
|
||||
(reset! drag? false)
|
||||
(st/emit! (dwu/commit-undo-transaction))))]
|
||||
(st/emit! (dwu/commit-undo-transaction (mf/ref-val node-ref)))))]
|
||||
|
||||
;; Initialize colorpicker state
|
||||
(mf/with-effect []
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
[app.common.pages.helpers :as cph]
|
||||
[app.common.spec :as us]
|
||||
[app.common.text :as txt]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.config :as cf]
|
||||
[app.main.data.events :as ev]
|
||||
[app.main.data.modal :as modal]
|
||||
|
@ -181,13 +182,14 @@
|
|||
|
||||
(defn- create-assets-group
|
||||
[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!
|
||||
(->> components-to-group
|
||||
(map #(rename
|
||||
(:id %)
|
||||
(add-group % group-name)))))
|
||||
(st/emit! (dwu/commit-undo-transaction)))
|
||||
(st/emit! (dwu/commit-undo-transaction undo-id))))
|
||||
|
||||
(defn- on-drop-asset
|
||||
[event asset dragging? selected-assets selected-assets-full selected-assets-paths rename]
|
||||
|
@ -589,23 +591,25 @@
|
|||
(mf/use-fn
|
||||
(mf/deps @state)
|
||||
(fn []
|
||||
(if (empty? selected-components)
|
||||
(let [undo-id (uuid/next)]
|
||||
(if (empty? selected-components)
|
||||
(st/emit! (dwl/duplicate-component {:id (:component-id @state)}))
|
||||
(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))
|
||||
(st/emit! (dwu/commit-undo-transaction))))))
|
||||
(st/emit! (dwu/commit-undo-transaction undo-id)))))))
|
||||
|
||||
on-delete
|
||||
(mf/use-fn
|
||||
(mf/deps @state file-id multi-components? multi-assets?)
|
||||
(fn []
|
||||
(if (or multi-components? multi-assets?)
|
||||
(let [undo-id (uuid/next)]
|
||||
(if (or multi-components? multi-assets?)
|
||||
(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/sync-file file-id file-id :components (:component-id @state))
|
||||
(dwu/commit-undo-transaction)))))
|
||||
(dwu/commit-undo-transaction undo-id))))))
|
||||
|
||||
on-rename
|
||||
(mf/use-fn
|
||||
|
@ -646,30 +650,32 @@
|
|||
(mf/deps components selected-components on-clear-selection)
|
||||
(fn [group-name]
|
||||
(on-clear-selection)
|
||||
(st/emit! (dwu/start-undo-transaction))
|
||||
(apply st/emit!
|
||||
(->> components
|
||||
(filter #(if multi-components?
|
||||
(contains? selected-components (:id %))
|
||||
(= (:component-id @state) (:id %))))
|
||||
(map #(dwl/rename-component
|
||||
(:id %)
|
||||
(add-group % group-name)))))
|
||||
(st/emit! (dwu/commit-undo-transaction))))
|
||||
(let [undo-id (uuid/next)]
|
||||
(st/emit! (dwu/start-undo-transaction undo-id))
|
||||
(apply st/emit!
|
||||
(->> components
|
||||
(filter #(if multi-components?
|
||||
(contains? selected-components (:id %))
|
||||
(= (:component-id @state) (:id %))))
|
||||
(map #(dwl/rename-component
|
||||
(:id %)
|
||||
(add-group % group-name)))))
|
||||
(st/emit! (dwu/commit-undo-transaction undo-id)))))
|
||||
|
||||
rename-group
|
||||
(mf/use-fn
|
||||
(mf/deps components)
|
||||
(fn [path last-path]
|
||||
(on-clear-selection)
|
||||
(st/emit! (dwu/start-undo-transaction))
|
||||
(apply st/emit!
|
||||
(->> components
|
||||
(filter #(str/starts-with? (:path %) path))
|
||||
(map #(dwl/rename-component
|
||||
(:id %)
|
||||
(rename-group % path last-path)))))
|
||||
(st/emit! (dwu/commit-undo-transaction))))
|
||||
(let [undo-id (uuid/next)]
|
||||
(st/emit! (dwu/start-undo-transaction undo-id))
|
||||
(apply st/emit!
|
||||
(->> components
|
||||
(filter #(str/starts-with? (:path %) path))
|
||||
(map #(dwl/rename-component
|
||||
(:id %)
|
||||
(rename-group % path last-path)))))
|
||||
(st/emit! (dwu/commit-undo-transaction undo-id)))))
|
||||
|
||||
on-group
|
||||
(mf/use-fn
|
||||
|
@ -692,14 +698,15 @@
|
|||
(mf/deps components)
|
||||
(fn [path]
|
||||
(on-clear-selection)
|
||||
(st/emit! (dwu/start-undo-transaction))
|
||||
(apply st/emit!
|
||||
(->> components
|
||||
(filter #(str/starts-with? (:path %) path))
|
||||
(map #(dwl/rename-component
|
||||
(:id %)
|
||||
(ungroup % path)))))
|
||||
(st/emit! (dwu/commit-undo-transaction))))
|
||||
(let [undo-id (uuid/next)]
|
||||
(st/emit! (dwu/start-undo-transaction undo-id))
|
||||
(apply st/emit!
|
||||
(->> components
|
||||
(filter #(str/starts-with? (:path %) path))
|
||||
(map #(dwl/rename-component
|
||||
(:id %)
|
||||
(ungroup % path)))))
|
||||
(st/emit! (dwu/commit-undo-transaction undo-id)))))
|
||||
|
||||
on-drag-start
|
||||
(mf/use-fn
|
||||
|
@ -1015,30 +1022,32 @@
|
|||
(mf/deps objects selected-objects on-clear-selection)
|
||||
(fn [group-name]
|
||||
(on-clear-selection)
|
||||
(st/emit! (dwu/start-undo-transaction))
|
||||
(apply st/emit!
|
||||
(->> objects
|
||||
(filter #(if multi-objects?
|
||||
(contains? selected-objects (:id %))
|
||||
(= (:object-id @state) (:id %))))
|
||||
(map #(dwl/rename-media
|
||||
(:id %)
|
||||
(add-group % group-name)))))
|
||||
(st/emit! (dwu/commit-undo-transaction))))
|
||||
(let [undo-id (uuid/next)]
|
||||
(st/emit! (dwu/start-undo-transaction undo-id))
|
||||
(apply st/emit!
|
||||
(->> objects
|
||||
(filter #(if multi-objects?
|
||||
(contains? selected-objects (:id %))
|
||||
(= (:object-id @state) (:id %))))
|
||||
(map #(dwl/rename-media
|
||||
(:id %)
|
||||
(add-group % group-name)))))
|
||||
(st/emit! (dwu/commit-undo-transaction undo-id)))))
|
||||
|
||||
rename-group
|
||||
(mf/use-fn
|
||||
(mf/deps objects)
|
||||
(fn [path last-path]
|
||||
(on-clear-selection)
|
||||
(st/emit! (dwu/start-undo-transaction))
|
||||
(apply st/emit!
|
||||
(->> objects
|
||||
(filter #(str/starts-with? (:path %) path))
|
||||
(map #(dwl/rename-media
|
||||
(:id %)
|
||||
(rename-group % path last-path)))))
|
||||
(st/emit! (dwu/commit-undo-transaction))))
|
||||
(let [undo-id (uuid/next)]
|
||||
(st/emit! (dwu/start-undo-transaction undo-id))
|
||||
(apply st/emit!
|
||||
(->> objects
|
||||
(filter #(str/starts-with? (:path %) path))
|
||||
(map #(dwl/rename-media
|
||||
(:id %)
|
||||
(rename-group % path last-path)))))
|
||||
(st/emit! (dwu/commit-undo-transaction undo-id)))))
|
||||
|
||||
on-group
|
||||
(mf/use-fn
|
||||
|
@ -1060,14 +1069,15 @@
|
|||
(mf/deps objects)
|
||||
(fn [path]
|
||||
(on-clear-selection)
|
||||
(st/emit! (dwu/start-undo-transaction))
|
||||
(apply st/emit!
|
||||
(->> objects
|
||||
(filter #(str/starts-with? (:path %) path))
|
||||
(map #(dwl/rename-media
|
||||
(:id %)
|
||||
(ungroup % path)))))
|
||||
(st/emit! (dwu/commit-undo-transaction))))
|
||||
(let [undo-id (uuid/next)]
|
||||
(st/emit! (dwu/start-undo-transaction undo-id))
|
||||
(apply st/emit!
|
||||
(->> objects
|
||||
(filter #(str/starts-with? (:path %) path))
|
||||
(map #(dwl/rename-media
|
||||
(:id %)
|
||||
(ungroup % path)))))
|
||||
(st/emit! (dwu/commit-undo-transaction undo-id)))))
|
||||
|
||||
on-drag-start
|
||||
(mf/use-fn
|
||||
|
@ -1175,10 +1185,11 @@
|
|||
(fn []
|
||||
(if (or multi-colors? multi-assets?)
|
||||
(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/sync-file file-id file-id :colors (:id color))
|
||||
(dwu/commit-undo-transaction)))))
|
||||
(dwu/commit-undo-transaction undo-id))))))
|
||||
|
||||
rename-color-clicked
|
||||
(fn [event]
|
||||
|
@ -1436,7 +1447,8 @@
|
|||
(fn [color-id]
|
||||
(fn [group-name]
|
||||
(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!
|
||||
(->> colors
|
||||
(filter #(if multi-colors?
|
||||
|
@ -1446,22 +1458,23 @@
|
|||
(assoc % :name
|
||||
(add-group % group-name))
|
||||
file-id))))
|
||||
(st/emit! (dwu/commit-undo-transaction)))))
|
||||
(st/emit! (dwu/commit-undo-transaction undo-id))))))
|
||||
|
||||
rename-group
|
||||
(mf/use-fn
|
||||
(mf/deps colors)
|
||||
(fn [path last-path]
|
||||
(on-clear-selection)
|
||||
(st/emit! (dwu/start-undo-transaction))
|
||||
(apply st/emit!
|
||||
(->> colors
|
||||
(filter #(str/starts-with? (:path %) path))
|
||||
(map #(dwl/update-color
|
||||
(assoc % :name
|
||||
(rename-group % path last-path))
|
||||
file-id))))
|
||||
(st/emit! (dwu/commit-undo-transaction))))
|
||||
(let [undo-id (uuid/next)]
|
||||
(st/emit! (dwu/start-undo-transaction undo-id))
|
||||
(apply st/emit!
|
||||
(->> colors
|
||||
(filter #(str/starts-with? (:path %) path))
|
||||
(map #(dwl/update-color
|
||||
(assoc % :name
|
||||
(rename-group % path last-path))
|
||||
file-id))))
|
||||
(st/emit! (dwu/commit-undo-transaction undo-id)))))
|
||||
|
||||
on-group
|
||||
(mf/use-fn
|
||||
|
@ -1484,15 +1497,16 @@
|
|||
(mf/deps colors)
|
||||
(fn [path]
|
||||
(on-clear-selection)
|
||||
(st/emit! (dwu/start-undo-transaction))
|
||||
(apply st/emit!
|
||||
(->> colors
|
||||
(filter #(str/starts-with? (:path %) path))
|
||||
(map #(dwl/update-color
|
||||
(assoc % :name
|
||||
(ungroup % path))
|
||||
file-id))))
|
||||
(st/emit! (dwu/commit-undo-transaction))))]
|
||||
(let [undo-id (uuid/next)]
|
||||
(st/emit! (dwu/start-undo-transaction undo-id))
|
||||
(apply st/emit!
|
||||
(->> colors
|
||||
(filter #(str/starts-with? (:path %) path))
|
||||
(map #(dwl/update-color
|
||||
(assoc % :name
|
||||
(ungroup % path))
|
||||
file-id))))
|
||||
(st/emit! (dwu/commit-undo-transaction undo-id)))))]
|
||||
|
||||
[:& asset-section {:file-id file-id
|
||||
:title (tr "workspace.assets.colors")
|
||||
|
@ -1724,32 +1738,34 @@
|
|||
(mf/deps typographies selected-typographies on-clear-selection file-id)
|
||||
(fn [group-name]
|
||||
(on-clear-selection)
|
||||
(st/emit! (dwu/start-undo-transaction))
|
||||
(apply st/emit!
|
||||
(->> typographies
|
||||
(filter #(if multi-typographies?
|
||||
(contains? selected-typographies (:id %))
|
||||
(= (:id @state) (:id %))))
|
||||
(map #(dwl/update-typography
|
||||
(assoc % :name
|
||||
(add-group % group-name))
|
||||
file-id))))
|
||||
(st/emit! (dwu/commit-undo-transaction))))
|
||||
(let [undo-id (uuid/next)]
|
||||
(st/emit! (dwu/start-undo-transaction undo-id))
|
||||
(apply st/emit!
|
||||
(->> typographies
|
||||
(filter #(if multi-typographies?
|
||||
(contains? selected-typographies (:id %))
|
||||
(= (:id @state) (:id %))))
|
||||
(map #(dwl/update-typography
|
||||
(assoc % :name
|
||||
(add-group % group-name))
|
||||
file-id))))
|
||||
(st/emit! (dwu/commit-undo-transaction undo-id)))))
|
||||
|
||||
rename-group
|
||||
(mf/use-fn
|
||||
(mf/deps typographies)
|
||||
(fn [path last-path]
|
||||
(on-clear-selection)
|
||||
(st/emit! (dwu/start-undo-transaction))
|
||||
(apply st/emit!
|
||||
(->> typographies
|
||||
(filter #(str/starts-with? (:path %) path))
|
||||
(map #(dwl/update-typography
|
||||
(assoc % :name
|
||||
(rename-group % path last-path))
|
||||
file-id))))
|
||||
(st/emit! (dwu/commit-undo-transaction))))
|
||||
(let [undo-id (uuid/next)]
|
||||
(st/emit! (dwu/start-undo-transaction undo-id))
|
||||
(apply st/emit!
|
||||
(->> typographies
|
||||
(filter #(str/starts-with? (:path %) path))
|
||||
(map #(dwl/update-typography
|
||||
(assoc % :name
|
||||
(rename-group % path last-path))
|
||||
file-id))))
|
||||
(st/emit! (dwu/commit-undo-transaction undo-id)))))
|
||||
|
||||
on-group
|
||||
(mf/use-fn
|
||||
|
@ -1771,15 +1787,16 @@
|
|||
(mf/deps typographies)
|
||||
(fn [path]
|
||||
(on-clear-selection)
|
||||
(st/emit! (dwu/start-undo-transaction))
|
||||
(apply st/emit!
|
||||
(->> typographies
|
||||
(filter #(str/starts-with? (:path %) path))
|
||||
(map #(dwl/rename-typography
|
||||
file-id
|
||||
(:id %)
|
||||
(ungroup % path)))))
|
||||
(st/emit! (dwu/commit-undo-transaction))))
|
||||
(let [undo-id (uuid/next)]
|
||||
(st/emit! (dwu/start-undo-transaction undo-id))
|
||||
(apply st/emit!
|
||||
(->> typographies
|
||||
(filter #(str/starts-with? (:path %) path))
|
||||
(map #(dwl/rename-typography
|
||||
file-id
|
||||
(:id %)
|
||||
(ungroup % path)))))
|
||||
(st/emit! (dwu/commit-undo-transaction undo-id)))))
|
||||
|
||||
on-context-menu
|
||||
(mf/use-fn
|
||||
|
@ -1808,12 +1825,13 @@
|
|||
(mf/use-fn
|
||||
(mf/deps @state multi-typographies? multi-assets?)
|
||||
(fn []
|
||||
(if (or multi-typographies? multi-assets?)
|
||||
(on-assets-delete)
|
||||
(st/emit! (dwu/start-undo-transaction)
|
||||
(dwl/delete-typography (:id @state))
|
||||
(dwl/sync-file file-id file-id :typographies (:id @state))
|
||||
(dwu/commit-undo-transaction)))))
|
||||
(let [undo-id (uuid/next)]
|
||||
(if (or multi-typographies? multi-assets?)
|
||||
(on-assets-delete)
|
||||
(st/emit! (dwu/start-undo-transaction undo-id)
|
||||
(dwl/delete-typography (:id @state))
|
||||
(dwl/sync-file file-id file-id :typographies (:id @state))
|
||||
(dwu/commit-undo-transaction undo-id))))))
|
||||
|
||||
editing-id (or (:rename-typography local-data)
|
||||
(:edit-typography local-data))]
|
||||
|
@ -2045,7 +2063,8 @@
|
|||
(mf/use-fn
|
||||
(mf/deps selected-assets)
|
||||
(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 %})
|
||||
(:components selected-assets)))
|
||||
(apply st/emit! (map #(dwl/delete-media {:id %})
|
||||
|
@ -2058,7 +2077,7 @@
|
|||
(d/not-empty? (:colors selected-assets))
|
||||
(d/not-empty? (:typographies selected-assets)))
|
||||
(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 %)
|
||||
:on-click unselect-all}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.types.shape.layout :as ctl]
|
||||
[app.common.types.shape.radius :as ctsr]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.constants :refer [size-presets]]
|
||||
[app.main.data.workspace :as udw]
|
||||
[app.main.data.workspace.changes :as dch]
|
||||
|
@ -248,9 +249,10 @@
|
|||
(mf/use-callback
|
||||
(mf/deps ids)
|
||||
(fn [event]
|
||||
(let [value (-> event dom/get-target dom/checked?)]
|
||||
(let [value (-> event dom/get-target dom/checked?)
|
||||
undo-id (uuid/next)]
|
||||
(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)))))
|
||||
|
||||
(when-not value
|
||||
|
@ -258,7 +260,7 @@
|
|||
;; interactions that navigate to it.
|
||||
(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))]
|
||||
|
||||
|
|
|
@ -192,8 +192,8 @@
|
|||
:disable-gradient true
|
||||
:on-change (update-color index)
|
||||
:on-detach (detach-color index)
|
||||
:on-open #(st/emit! (dwu/start-undo-transaction))
|
||||
:on-close #(st/emit! (dwu/commit-undo-transaction))}]]]]))
|
||||
:on-open #(st/emit! (dwu/start-undo-transaction :color-row))
|
||||
:on-close #(st/emit! (dwu/commit-undo-transaction :color-row))}]]]]))
|
||||
(mf/defc shadow-menu
|
||||
[{:keys [ids type values] :as props}]
|
||||
(let [on-remove-all-shadows
|
||||
|
|
|
@ -27,11 +27,11 @@
|
|||
|
||||
on-open
|
||||
(fn []
|
||||
(st/emit! (dwu/start-undo-transaction)))
|
||||
(st/emit! (dwu/start-undo-transaction :options)))
|
||||
|
||||
on-close
|
||||
(fn []
|
||||
(st/emit! (dwu/commit-undo-transaction)))]
|
||||
(st/emit! (dwu/commit-undo-transaction :options)))]
|
||||
|
||||
[:div.element-set
|
||||
[:div.element-set-title (tr "workspace.options.canvas-background")]
|
||||
|
|
|
@ -114,7 +114,7 @@
|
|||
(fn [event]
|
||||
(dom/prevent-default 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)))))
|
||||
|
||||
handle-mouse-up-picker
|
||||
|
@ -122,7 +122,7 @@
|
|||
(fn [event]
|
||||
(dom/prevent-default event)
|
||||
(dom/stop-propagation event)
|
||||
(st/emit! (dwu/commit-undo-transaction)
|
||||
(st/emit! (dwu/commit-undo-transaction :mouse-down-picker)
|
||||
(dwc/stop-picker))
|
||||
(modal/disallow-click-outside!)))
|
||||
|
||||
|
|
Loading…
Reference in a new issue