From 62b59991a9bd4bbd06f531895aa43402379c6dc8 Mon Sep 17 00:00:00 2001 From: Eva Marco Date: Thu, 9 Apr 2026 09:16:28 +0200 Subject: [PATCH] :wrench: Add guard to apply-token (#8879) --- common/src/app/common/files/tokens.cljc | 14 +++++--------- .../main/data/workspace/tokens/application.cljs | 6 ++++-- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/common/src/app/common/files/tokens.cljc b/common/src/app/common/files/tokens.cljc index 071b28a4e7..cd6dc44cb2 100644 --- a/common/src/app/common/files/tokens.cljc +++ b/common/src/app/common/files/tokens.cljc @@ -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`." diff --git a/frontend/src/app/main/data/workspace/tokens/application.cljs b/frontend/src/app/main/data/workspace/tokens/application.cljs index 9c79d40260..89cccdd869 100644 --- a/frontend/src/app/main/data/workspace/tokens/application.cljs +++ b/frontend/src/app/main/data/workspace/tokens/application.cljs @@ -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)