mirror of
https://github.com/penpot/penpot.git
synced 2025-06-06 01:31:40 +02:00
🐛 Avoid marking copies touched when changing token values
This commit is contained in:
parent
99c30dd44f
commit
d51a2640bf
6 changed files with 60 additions and 47 deletions
|
@ -82,7 +82,7 @@
|
||||||
(assoc-in [:workspace-global :picked-shift?] shift?)))))
|
(assoc-in [:workspace-global :picked-shift?] shift?)))))
|
||||||
|
|
||||||
(defn transform-fill
|
(defn transform-fill
|
||||||
[state ids color transform]
|
[state ids color transform & options]
|
||||||
(let [objects (wsh/lookup-page-objects state)
|
(let [objects (wsh/lookup-page-objects state)
|
||||||
|
|
||||||
is-text? #(= :text (:type (get objects %)))
|
is-text? #(= :text (:type (get objects %)))
|
||||||
|
@ -118,8 +118,8 @@
|
||||||
|
|
||||||
(rx/concat
|
(rx/concat
|
||||||
(rx/of (dwu/start-undo-transaction undo-id))
|
(rx/of (dwu/start-undo-transaction undo-id))
|
||||||
(rx/from (map #(dwt/update-text-with-function % transform-attrs) text-ids))
|
(rx/from (map #(apply dwt/update-text-with-function % transform-attrs options) text-ids))
|
||||||
(rx/of (dwsh/update-shapes shape-ids transform-attrs))
|
(rx/of (dwsh/update-shapes shape-ids transform-attrs options))
|
||||||
(rx/of (dwu/commit-undo-transaction undo-id)))))
|
(rx/of (dwu/commit-undo-transaction undo-id)))))
|
||||||
|
|
||||||
(defn swap-attrs [shape attr index new-index]
|
(defn swap-attrs [shape attr index new-index]
|
||||||
|
@ -146,7 +146,7 @@
|
||||||
(rx/of (dwsh/update-shapes shape-ids transform-attrs)))))))
|
(rx/of (dwsh/update-shapes shape-ids transform-attrs)))))))
|
||||||
|
|
||||||
(defn change-fill
|
(defn change-fill
|
||||||
[ids color position]
|
[ids color position & options]
|
||||||
(ptk/reify ::change-fill
|
(ptk/reify ::change-fill
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
|
@ -155,18 +155,18 @@
|
||||||
(cond-> (not (contains? shape :fills))
|
(cond-> (not (contains? shape :fills))
|
||||||
(assoc :fills []))
|
(assoc :fills []))
|
||||||
(assoc-in [:fills position] (into {} attrs))))]
|
(assoc-in [:fills position] (into {} attrs))))]
|
||||||
(transform-fill state ids color change-fn)))))
|
(apply transform-fill state ids color change-fn options)))))
|
||||||
|
|
||||||
(defn change-fill-and-clear
|
(defn change-fill-and-clear
|
||||||
[ids color]
|
[ids color & options]
|
||||||
(ptk/reify ::change-fill-and-clear
|
(ptk/reify ::change-fill-and-clear
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(let [set (fn [shape attrs] (assoc shape :fills [attrs]))]
|
(let [set (fn [shape attrs] (assoc shape :fills [attrs]))]
|
||||||
(transform-fill state ids color set)))))
|
(apply transform-fill state ids color set options)))))
|
||||||
|
|
||||||
(defn add-fill
|
(defn add-fill
|
||||||
[ids color]
|
[ids color & options]
|
||||||
|
|
||||||
(dm/assert!
|
(dm/assert!
|
||||||
"expected a valid color struct"
|
"expected a valid color struct"
|
||||||
|
@ -182,10 +182,10 @@
|
||||||
(let [add (fn [shape attrs]
|
(let [add (fn [shape attrs]
|
||||||
(-> shape
|
(-> shape
|
||||||
(update :fills #(into [attrs] %))))]
|
(update :fills #(into [attrs] %))))]
|
||||||
(transform-fill state ids color add)))))
|
(apply transform-fill state ids color add options)))))
|
||||||
|
|
||||||
(defn remove-fill
|
(defn remove-fill
|
||||||
[ids color position]
|
[ids color position & options]
|
||||||
|
|
||||||
(dm/assert!
|
(dm/assert!
|
||||||
"expected a valid color struct"
|
"expected a valid color struct"
|
||||||
|
@ -203,10 +203,10 @@
|
||||||
(mapv second)))
|
(mapv second)))
|
||||||
|
|
||||||
remove (fn [shape _] (update shape :fills remove-fill-by-index position))]
|
remove (fn [shape _] (update shape :fills remove-fill-by-index position))]
|
||||||
(transform-fill state ids color remove)))))
|
(apply transform-fill state ids color remove options)))))
|
||||||
|
|
||||||
(defn remove-all-fills
|
(defn remove-all-fills
|
||||||
[ids color]
|
[ids color & options]
|
||||||
|
|
||||||
(dm/assert!
|
(dm/assert!
|
||||||
"expected a valid color struct"
|
"expected a valid color struct"
|
||||||
|
@ -220,7 +220,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(let [remove-all (fn [shape _] (assoc shape :fills []))]
|
(let [remove-all (fn [shape _] (assoc shape :fills []))]
|
||||||
(transform-fill state ids color remove-all)))))
|
(apply transform-fill state ids color remove-all options)))))
|
||||||
|
|
||||||
(defn change-hide-fill-on-export
|
(defn change-hide-fill-on-export
|
||||||
[ids hide-fill-on-export]
|
[ids hide-fill-on-export]
|
||||||
|
@ -237,7 +237,7 @@
|
||||||
(d/merge shape attrs)
|
(d/merge shape attrs)
|
||||||
shape))))))))
|
shape))))))))
|
||||||
(defn change-stroke
|
(defn change-stroke
|
||||||
[ids attrs index]
|
[ids attrs index & options]
|
||||||
(ptk/reify ::change-stroke
|
(ptk/reify ::change-stroke
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ _ _]
|
(watch [_ _ _]
|
||||||
|
@ -286,7 +286,8 @@
|
||||||
(assoc :strokes [])
|
(assoc :strokes [])
|
||||||
|
|
||||||
:always
|
:always
|
||||||
(assoc-in [:strokes index] new-attrs))))))))))
|
(assoc-in [:strokes index] new-attrs))))
|
||||||
|
options))))))
|
||||||
|
|
||||||
(defn change-shadow
|
(defn change-shadow
|
||||||
[ids attrs index]
|
[ids attrs index]
|
||||||
|
|
|
@ -465,8 +465,10 @@
|
||||||
([]
|
([]
|
||||||
(apply-modifiers nil))
|
(apply-modifiers nil))
|
||||||
|
|
||||||
([{:keys [modifiers undo-transation? stack-undo? ignore-constraints ignore-snap-pixel undo-group]
|
([{:keys [modifiers undo-transation? stack-undo? ignore-constraints
|
||||||
:or {undo-transation? true stack-undo? false ignore-constraints false ignore-snap-pixel false}}]
|
ignore-snap-pixel ignore-touched undo-group]
|
||||||
|
:or {undo-transation? true stack-undo? false ignore-constraints false
|
||||||
|
ignore-snap-pixel false ignore-touched false}}]
|
||||||
(ptk/reify ::apply-modifiers
|
(ptk/reify ::apply-modifiers
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
|
@ -515,6 +517,7 @@
|
||||||
{:reg-objects? true
|
{:reg-objects? true
|
||||||
:stack-undo? stack-undo?
|
:stack-undo? stack-undo?
|
||||||
:ignore-tree ignore-tree
|
:ignore-tree ignore-tree
|
||||||
|
:ignore-touched ignore-touched
|
||||||
:undo-group undo-group
|
:undo-group undo-group
|
||||||
;; Attributes that can change in the transform. This way we don't have to check
|
;; Attributes that can change in the transform. This way we don't have to check
|
||||||
;; all the attributes
|
;; all the attributes
|
||||||
|
|
|
@ -260,13 +260,13 @@
|
||||||
(rx/of (with-meta event (meta it)))))))))
|
(rx/of (with-meta event (meta it)))))))))
|
||||||
|
|
||||||
(defn update-layout
|
(defn update-layout
|
||||||
[ids changes]
|
[ids changes & options]
|
||||||
(ptk/reify ::update-layout
|
(ptk/reify ::update-layout
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ _ _]
|
(watch [_ _ _]
|
||||||
(let [undo-id (js/Symbol)]
|
(let [undo-id (js/Symbol)]
|
||||||
(rx/of (dwu/start-undo-transaction undo-id)
|
(rx/of (dwu/start-undo-transaction undo-id)
|
||||||
(dwsh/update-shapes ids (d/patch-object changes))
|
(dwsh/update-shapes ids (d/patch-object changes) options)
|
||||||
(ptk/data-event :layout/update {:ids ids})
|
(ptk/data-event :layout/update {:ids ids})
|
||||||
(dwu/commit-undo-transaction undo-id))))))
|
(dwu/commit-undo-transaction undo-id))))))
|
||||||
|
|
||||||
|
@ -516,7 +516,7 @@
|
||||||
(assoc :layout-item-v-sizing :fix))))
|
(assoc :layout-item-v-sizing :fix))))
|
||||||
|
|
||||||
(defn update-layout-child
|
(defn update-layout-child
|
||||||
[ids changes]
|
[ids changes & options]
|
||||||
(ptk/reify ::update-layout-child
|
(ptk/reify ::update-layout-child
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
|
@ -525,8 +525,8 @@
|
||||||
parent-ids (->> ids (map #(cfh/get-parent-id objects %)))
|
parent-ids (->> ids (map #(cfh/get-parent-id objects %)))
|
||||||
undo-id (js/Symbol)]
|
undo-id (js/Symbol)]
|
||||||
(rx/of (dwu/start-undo-transaction undo-id)
|
(rx/of (dwu/start-undo-transaction undo-id)
|
||||||
(dwsh/update-shapes ids (d/patch-object changes))
|
(dwsh/update-shapes ids (d/patch-object changes) options)
|
||||||
(dwsh/update-shapes children-ids (partial fix-child-sizing objects changes))
|
(dwsh/update-shapes children-ids (partial fix-child-sizing objects changes) options)
|
||||||
(dwsh/update-shapes
|
(dwsh/update-shapes
|
||||||
parent-ids
|
parent-ids
|
||||||
(fn [parent objects]
|
(fn [parent objects]
|
||||||
|
@ -534,7 +534,7 @@
|
||||||
(fix-parent-sizing objects (set ids) changes)
|
(fix-parent-sizing objects (set ids) changes)
|
||||||
(cond-> (ctl/grid-layout? parent)
|
(cond-> (ctl/grid-layout? parent)
|
||||||
(ctl/assign-cells objects))))
|
(ctl/assign-cells objects))))
|
||||||
{:with-objects? true})
|
(merge options {:with-objects? true}))
|
||||||
(ptk/data-event :layout/update {:ids ids})
|
(ptk/data-event :layout/update {:ids ids})
|
||||||
(dwu/commit-undo-transaction undo-id))))))
|
(dwu/commit-undo-transaction undo-id))))))
|
||||||
|
|
||||||
|
|
|
@ -432,7 +432,7 @@
|
||||||
(txt/transform-nodes (some-fn txt/is-text-node? txt/is-paragraph-node?) migrate-node content))
|
(txt/transform-nodes (some-fn txt/is-text-node? txt/is-paragraph-node?) migrate-node content))
|
||||||
|
|
||||||
(defn update-text-with-function
|
(defn update-text-with-function
|
||||||
[id update-node-fn]
|
[id update-node-fn & options]
|
||||||
(ptk/reify ::update-text-with-function
|
(ptk/reify ::update-text-with-function
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -464,7 +464,7 @@
|
||||||
(-> shape
|
(-> shape
|
||||||
(dissoc :fills)
|
(dissoc :fills)
|
||||||
(d/update-when :content update-content)))]
|
(d/update-when :content update-content)))]
|
||||||
(rx/of (dwsh/update-shapes shape-ids update-shape)))))
|
(rx/of (dwsh/update-shapes shape-ids update-shape options)))))
|
||||||
|
|
||||||
ptk/EffectEvent
|
ptk/EffectEvent
|
||||||
(effect [_ state _]
|
(effect [_ state _]
|
||||||
|
|
|
@ -301,7 +301,7 @@
|
||||||
(defn update-dimensions
|
(defn update-dimensions
|
||||||
"Change size of shapes, from the sideber options form.
|
"Change size of shapes, from the sideber options form.
|
||||||
Will ignore pixel snap used in the options side panel"
|
Will ignore pixel snap used in the options side panel"
|
||||||
[ids attr value]
|
[ids attr value & options]
|
||||||
(dm/assert! (number? value))
|
(dm/assert! (number? value))
|
||||||
(dm/assert!
|
(dm/assert!
|
||||||
"expected valid coll of uuids"
|
"expected valid coll of uuids"
|
||||||
|
@ -324,7 +324,7 @@
|
||||||
|
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ _ _]
|
(watch [_ _ _]
|
||||||
(rx/of (dwm/apply-modifiers)))))
|
(rx/of (dwm/apply-modifiers options)))))
|
||||||
|
|
||||||
(defn change-orientation
|
(defn change-orientation
|
||||||
"Change orientation of shapes, from the sidebar options form.
|
"Change orientation of shapes, from the sidebar options form.
|
||||||
|
@ -402,7 +402,7 @@
|
||||||
"Rotate shapes a fixed angle, from a keyboard action."
|
"Rotate shapes a fixed angle, from a keyboard action."
|
||||||
([ids rotation]
|
([ids rotation]
|
||||||
(increase-rotation ids rotation nil))
|
(increase-rotation ids rotation nil))
|
||||||
([ids rotation params]
|
([ids rotation params & options]
|
||||||
(ptk/reify ::increase-rotation
|
(ptk/reify ::increase-rotation
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
|
@ -411,7 +411,7 @@
|
||||||
shapes (->> ids (map #(get objects %)))]
|
shapes (->> ids (map #(get objects %)))]
|
||||||
(rx/concat
|
(rx/concat
|
||||||
(rx/of (dwm/set-delta-rotation-modifiers rotation shapes params))
|
(rx/of (dwm/set-delta-rotation-modifiers rotation shapes params))
|
||||||
(rx/of (dwm/apply-modifiers))))))))
|
(rx/of (dwm/apply-modifiers options))))))))
|
||||||
|
|
||||||
|
|
||||||
;; -- Move ----------------------------------------------------------
|
;; -- Move ----------------------------------------------------------
|
||||||
|
|
|
@ -95,20 +95,9 @@
|
||||||
(when (ctsr/has-radius? shape)
|
(when (ctsr/has-radius? shape)
|
||||||
(ctsr/set-radius-1 shape value)))
|
(ctsr/set-radius-1 shape value)))
|
||||||
{:reg-objects? true
|
{:reg-objects? true
|
||||||
|
:ignore-touched true
|
||||||
:attrs ctt/border-radius-keys}))
|
:attrs ctt/border-radius-keys}))
|
||||||
|
|
||||||
(defn update-opacity [value shape-ids]
|
|
||||||
(when (<= 0 value 1)
|
|
||||||
(dwsh/update-shapes shape-ids #(assoc % :opacity value))))
|
|
||||||
|
|
||||||
(defn update-rotation [value shape-ids]
|
|
||||||
(ptk/reify ::update-shape-rotation
|
|
||||||
ptk/WatchEvent
|
|
||||||
(watch [_ _ _]
|
|
||||||
(rx/of
|
|
||||||
(udw/trigger-bounding-box-cloaking shape-ids)
|
|
||||||
(udw/increase-rotation shape-ids value)))))
|
|
||||||
|
|
||||||
(defn update-shape-radius-single-corner [value shape-ids attributes]
|
(defn update-shape-radius-single-corner [value shape-ids attributes]
|
||||||
(dwsh/update-shapes shape-ids
|
(dwsh/update-shapes shape-ids
|
||||||
(fn [shape]
|
(fn [shape]
|
||||||
|
@ -117,8 +106,23 @@
|
||||||
(:rx shape) (ctsr/switch-to-radius-4)
|
(:rx shape) (ctsr/switch-to-radius-4)
|
||||||
:always (ctsr/set-radius-4 (first attributes) value))))
|
:always (ctsr/set-radius-4 (first attributes) value))))
|
||||||
{:reg-objects? true
|
{:reg-objects? true
|
||||||
|
:ignore-touched true
|
||||||
:attrs [:rx :ry :r1 :r2 :r3 :r4]}))
|
:attrs [:rx :ry :r1 :r2 :r3 :r4]}))
|
||||||
|
|
||||||
|
(defn update-opacity [value shape-ids]
|
||||||
|
(when (<= 0 value 1)
|
||||||
|
(dwsh/update-shapes shape-ids
|
||||||
|
#(assoc % :opacity value)
|
||||||
|
{:ignore-touched true})))
|
||||||
|
|
||||||
|
(defn update-rotation [value shape-ids]
|
||||||
|
(ptk/reify ::update-shape-rotation
|
||||||
|
ptk/WatchEvent
|
||||||
|
(watch [_ _ _]
|
||||||
|
(rx/of
|
||||||
|
(udw/trigger-bounding-box-cloaking shape-ids)
|
||||||
|
(udw/increase-rotation shape-ids value nil :ignore-touched true)))))
|
||||||
|
|
||||||
(defn update-stroke-width
|
(defn update-stroke-width
|
||||||
[value shape-ids]
|
[value shape-ids]
|
||||||
(dwsh/update-shapes shape-ids
|
(dwsh/update-shapes shape-ids
|
||||||
|
@ -126,6 +130,7 @@
|
||||||
(when (seq (:strokes shape))
|
(when (seq (:strokes shape))
|
||||||
(assoc-in shape [:strokes 0 :stroke-width] value)))
|
(assoc-in shape [:strokes 0 :stroke-width] value)))
|
||||||
{:reg-objects? true
|
{:reg-objects? true
|
||||||
|
:ignore-touched true
|
||||||
:attrs [:strokes]}))
|
:attrs [:strokes]}))
|
||||||
|
|
||||||
(defn update-color [f value shape-ids]
|
(defn update-color [f value shape-ids]
|
||||||
|
@ -133,7 +138,7 @@
|
||||||
(tinycolor/valid-color)
|
(tinycolor/valid-color)
|
||||||
(tinycolor/->hex)
|
(tinycolor/->hex)
|
||||||
(str "#"))]
|
(str "#"))]
|
||||||
(f shape-ids {:color color} 0)))
|
(apply f shape-ids {:color color} 0 [:ignore-touched true])))
|
||||||
|
|
||||||
(defn update-fill
|
(defn update-fill
|
||||||
[value shape-ids]
|
[value shape-ids]
|
||||||
|
@ -156,8 +161,8 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ _ _]
|
(watch [_ _ _]
|
||||||
(rx/of
|
(rx/of
|
||||||
(when (:width attributes) (dwt/update-dimensions shape-ids :width value))
|
(when (:width attributes) (dwt/update-dimensions shape-ids :width value :ignore-touched true))
|
||||||
(when (:height attributes) (dwt/update-dimensions shape-ids :height value))))))
|
(when (:height attributes) (dwt/update-dimensions shape-ids :height value :ignore-touched true))))))
|
||||||
|
|
||||||
(defn- attributes->layout-gap [attributes value]
|
(defn- attributes->layout-gap [attributes value]
|
||||||
(let [layout-gap (-> (set/intersection attributes #{:column-gap :row-gap})
|
(let [layout-gap (-> (set/intersection attributes #{:column-gap :row-gap})
|
||||||
|
@ -165,7 +170,9 @@
|
||||||
{:layout-gap layout-gap}))
|
{:layout-gap layout-gap}))
|
||||||
|
|
||||||
(defn update-layout-padding [value shape-ids attrs]
|
(defn update-layout-padding [value shape-ids attrs]
|
||||||
(dwsl/update-layout shape-ids {:layout-padding (zipmap attrs (repeat value))}))
|
(dwsl/update-layout shape-ids
|
||||||
|
{:layout-padding (zipmap attrs (repeat value))}
|
||||||
|
:ignore-touched true))
|
||||||
|
|
||||||
(defn update-layout-spacing [value shape-ids attributes]
|
(defn update-layout-spacing [value shape-ids attributes]
|
||||||
(ptk/reify ::update-layout-spacing
|
(ptk/reify ::update-layout-spacing
|
||||||
|
@ -177,7 +184,9 @@
|
||||||
(map :id)))
|
(map :id)))
|
||||||
layout-attributes (attributes->layout-gap attributes value)]
|
layout-attributes (attributes->layout-gap attributes value)]
|
||||||
(rx/of
|
(rx/of
|
||||||
(dwsl/update-layout layout-shape-ids layout-attributes))))))
|
(dwsl/update-layout layout-shape-ids
|
||||||
|
layout-attributes
|
||||||
|
:ignore-touched true))))))
|
||||||
|
|
||||||
(defn update-shape-position [value shape-ids attributes]
|
(defn update-shape-position [value shape-ids attributes]
|
||||||
(ptk/reify ::update-shape-position
|
(ptk/reify ::update-shape-position
|
||||||
|
@ -195,4 +204,4 @@
|
||||||
:layout-item-max-w value
|
:layout-item-max-w value
|
||||||
:layout-item-max-h value}
|
:layout-item-max-h value}
|
||||||
(select-keys attributes))]
|
(select-keys attributes))]
|
||||||
(dwsl/update-layout-child shape-ids props)))))
|
(dwsl/update-layout-child shape-ids props :ignore-touched true)))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue