diff --git a/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs b/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs index d309645a7a..08893f57d8 100644 --- a/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs @@ -74,14 +74,14 @@ (get errors :style-dictionary/missing-reference))) (defn resolve-tokens+ - [tokens & {:keys [debug?] :as config}] + [tokens & {:keys [names-map? debug?] :as config}] (p/let [sd-tokens (-> (wtt/token-names-tree tokens) (resolve-sd-tokens+ config))] (let [resolved-tokens (reduce (fn [acc ^js cur] - (let [identifier (if (uuid? (ffirst tokens)) - (uuid (.-uuid (.-id cur))) - (.. cur -original -name)) + (let [identifier (if names-map? + (.. cur -original -name) + (uuid (.-uuid (.-id cur)))) origin-token (get tokens identifier) parsed-value (wtt/parse-token-value (.-value cur)) resolved-token (if (not parsed-value) diff --git a/frontend/src/app/main/ui/workspace/tokens/update.cljs b/frontend/src/app/main/ui/workspace/tokens/update.cljs index 1ae50d2316..2f64aa65b1 100644 --- a/frontend/src/app/main/ui/workspace/tokens/update.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/update.cljs @@ -124,7 +124,7 @@ (rx/from (-> (wtts/get-active-theme-sets-tokens-names-map state) - (wtsd/resolve-tokens+))) + (wtsd/resolve-tokens+ {:names-map? true}))) (rx/mapcat (fn [sd-tokens] (let [undo-id (js/Symbol)] diff --git a/frontend/test/token_tests/style_dictionary_test.cljs b/frontend/test/token_tests/style_dictionary_test.cljs index cc96abe1b8..354da5c893 100644 --- a/frontend/test/token_tests/style_dictionary_test.cljs +++ b/frontend/test/token_tests/style_dictionary_test.cljs @@ -2,7 +2,8 @@ (:require [app.main.ui.workspace.tokens.style-dictionary :as sd] [cljs.test :as t :include-macros true] - [promesa.core :as p])) + [promesa.core :as p] + [app.main.ui.workspace.tokens.token :as wtt])) (def border-radius-token {:id #uuid "8c868278-7c8d-431b-bbc9-7d8f15c8edb9" @@ -35,3 +36,22 @@ :resolved-unit "px")}] (t/is (= expected-tokens resolved-tokens)) (done)))))))) + +(t/deftest resolve-tokens-test + (t/async + done + (t/testing "resolves tokens using style-dictionary in a names-map" + (-> (vals tokens) + (wtt/token-names-map) + (sd/resolve-tokens+ {:names-map? true}) + (p/finally (fn [resolved-tokens] + (let [expected-tokens {"borderRadius.sm" + (assoc border-radius-token + :resolved-value 12 + :resolved-unit "px") + "borderRadius.md-with-dashes" + (assoc reference-border-radius-token + :resolved-value 24 + :resolved-unit "px")}] + (t/is (= expected-tokens resolved-tokens)) + (done))))))))