0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-21 06:02:32 -05:00

Only remove given token

This commit is contained in:
Florian Schroedl 2024-07-04 11:41:00 +02:00
parent b73cdd15e0
commit 893e790787
2 changed files with 9 additions and 6 deletions

View file

@ -94,15 +94,16 @@
"Removes `attributes` that match `token` for `shape-ids`.
Doesn't update shape attributes."
[{:keys [attributes shape-ids] :as _props}]
[{:keys [attributes token shape-ids] :as _props}]
(ptk/reify ::unapply-token
ptk/WatchEvent
(watch [_ _ _]
(rx/of
(dch/update-shapes
shape-ids
(fn [shape]
(update shape :applied-tokens remove-keys attributes)))))))
(let [remove-token #(wtt/remove-attributes-for-token-id attributes (:id token) %)]
(dch/update-shapes
shape-ids
(fn [shape]
(update shape :applied-tokens remove-token))))))))
(defn toggle-token
[{:keys [token-type-props token shapes] :as _props}]
@ -115,6 +116,7 @@
(if unapply-tokens?
(rx/of
(unapply-token {:attributes attributes
:token token
:shape-ids shape-ids}))
(rx/of
(apply-token {:attributes attributes

View file

@ -206,7 +206,7 @@
(t/is (= (:rx rect-2') 24)))))))))
(t/deftest test-toggle-token-mixed
(t/testing "should unapply token if one of the selected items has the token applied"
(t/testing "should unapply given token if one of the selected items has the token applied"
(t/async
done
(let [file (-> (setup-file)
@ -215,6 +215,7 @@
rect-1 (cths/get-shape file :rect-1)
rect-2 (cths/get-shape file :rect-2)
events [(wtc/toggle-token {:shapes [rect-1 rect-2]
:token (toht/get-token file :token-1)
:token-type-props {:attributes #{:rx :ry}}})]]
(tohs/run-store-async
store done events