mirror of
https://github.com/penpot/penpot.git
synced 2025-12-11 22:14:05 +01:00
Simplify token application
This commit is contained in:
@@ -59,10 +59,21 @@
|
|||||||
(let [token (token-from-attributes token-id attributes)]
|
(let [token (token-from-attributes token-id attributes)]
|
||||||
(toggle-or-apply-token shape token)))
|
(toggle-or-apply-token shape token)))
|
||||||
|
|
||||||
(defn apply-token-to-shape [{:keys [shape _token-id _attributes] :as props}]
|
(defn apply-token-to-shape
|
||||||
(let [applied-tokens (apply-token-id-to-attributes props)]
|
"When the passed `:token` is non-nil apply it to the `:applied-tokens` on a shape."
|
||||||
|
[{:keys [shape token attributes] :as props}]
|
||||||
|
(let [applied-tokens (apply-token-id-to-attributes {:shape shape
|
||||||
|
:token-id (:id token)
|
||||||
|
:attributes attributes})]
|
||||||
(update shape :applied-tokens #(merge % applied-tokens))))
|
(update shape :applied-tokens #(merge % applied-tokens))))
|
||||||
|
|
||||||
|
(defn maybe-apply-token-to-shape
|
||||||
|
"When the passed `:token` is non-nil apply it to the `:applied-tokens` on a shape."
|
||||||
|
[{:keys [shape token _attributes] :as props}]
|
||||||
|
(if token
|
||||||
|
(apply-token-to-shape props)
|
||||||
|
shape))
|
||||||
|
|
||||||
(defn update-token-from-attributes
|
(defn update-token-from-attributes
|
||||||
[{:keys [token-id shape-id attributes]}]
|
[{:keys [token-id shape-id attributes]}]
|
||||||
(ptk/reify ::update-token-from-attributes
|
(ptk/reify ::update-token-from-attributes
|
||||||
|
|||||||
@@ -296,11 +296,11 @@
|
|||||||
token-value (some-> token wtc/resolve-token-value)]
|
token-value (some-> token wtc/resolve-token-value)]
|
||||||
(st/emit!
|
(st/emit!
|
||||||
(change-radius (fn [shape]
|
(change-radius (fn [shape]
|
||||||
(cond-> shape
|
(-> (dt/maybe-apply-token-to-shape
|
||||||
token-value (#(dt/apply-token-to-shape {:token-id (:id token)
|
{:token-id token
|
||||||
:shape %
|
:shape shape
|
||||||
:attributes (wtc/token-attributes :border-radius)}))
|
:attributes (wtc/token-attributes :border-radius)})
|
||||||
:always (ctsr/set-radius-1 (or token-value value)))))))))
|
(ctsr/set-radius-1 (or token-value value)))))))))
|
||||||
|
|
||||||
on-radius-multi-change
|
on-radius-multi-change
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
|
|||||||
Reference in New Issue
Block a user