🔧 Add guard to apply-token (#8879)

This commit is contained in:
Eva Marco 2026-04-09 09:16:28 +02:00 committed by GitHub
parent 5937a8b0fc
commit 62b59991a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 11 deletions

View File

@ -314,16 +314,12 @@
{:value parsed-value
:unit unit}))))
;; FIXME: looks very redundant function
(defn token-identifier
[{:keys [name] :as _token}]
name)
(defn attributes-map
"Creats an attributes map using collection of `attributes` for `id`."
"Creates an attributes map using collection of `attributes` for `id`."
[attributes token]
(->> (map (fn [attr] [attr (token-identifier token)]) attributes)
(into {})))
(into {}
(map (fn [attr] [attr (:name token)]))
attributes))
(defn remove-attributes-for-token
"Removes applied tokens with `token-name` for the given `attributes` set from `applied-tokens`."
@ -339,7 +335,7 @@
"Test if `token` is applied to a `shape` on single `token-attribute`."
[token shape token-attribute]
(when-let [id (dm/get-in shape [:applied-tokens token-attribute])]
(= (token-identifier token) id)))
(= (:name token) id)))
(defn token-applied?
"Test if `token` is applied to a `shape` with at least one of the given `token-attributes`."

View File

@ -656,6 +656,7 @@
this is useful for applying a single attribute from an attributes set
while removing other applied tokens from this set."
[{:keys [attributes attributes-to-remove token shape-ids on-update-shape]}]
(assert (ctob/token? token) "apply-token event requires a valid token")
(ptk/reify ::apply-token
ptk/WatchEvent
(watch [_ state _]
@ -667,9 +668,10 @@
text-editing? (and (some? edition)
(= :text (:type (get objects edition))))]
(if (and (empty? (get state :workspace-editor-state))
(some? token)
(not text-editing?))
(let [attributes-to-remove
;; Remove atomic typography tokens when applying composite and vice-verca
;; Remove atomic typography tokens when applying composite and vice-versa
(cond
(ctt/typography-token-keys (:type token)) (set/union attributes-to-remove ctt/typography-keys)
(ctt/typography-keys (:type token)) (set/union attributes-to-remove ctt/typography-token-keys)
@ -696,7 +698,7 @@
shape-ids (d/nilv (keys shapes) [])
any-variant? (->> shapes vals (some ctk/is-variant?) boolean)
resolved-value (get-in resolved-tokens [(cfo/token-identifier token) :resolved-value])
resolved-value (get-in resolved-tokens [(:name token) :resolved-value])
resolved-value (if (contains? cf/flags :tokenscript)
(ts/tokenscript-symbols->penpot-unit resolved-value)
resolved-value)