From 0921f8043bbb5ba9c5fb1e8eb315ce7f9e6719ec Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 12 Jun 2024 16:10:02 +0200 Subject: [PATCH] Allow passing of tokens --- .../ui/workspace/tokens/style_dictionary.cljs | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) 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 a7afd9414..b8dd86e2e 100644 --- a/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs @@ -41,7 +41,7 @@ (js/console.log "Input Data" js-data)) (StyleDictionary. js-data))) -(defn resolve-tokens+ +(defn resolve-sd-tokens+ "Resolves references and math expressions using StyleDictionary. Returns a promise with the resolved dictionary." [tokens & {:keys [debug?] :as config}] @@ -61,22 +61,25 @@ (js/console.log "Resolved tokens" resolved-tokens)) resolved-tokens)))))) +(defn resolve-tokens+ + [tokens & {:keys [debug?] :as config}] + (p/let [sd-tokens (-> (tokens->tree tokens) + (clj->js) + (resolve-sd-tokens+ config))] + (let [resolved-tokens (reduce + (fn [acc cur] + (let [resolved-value (.-value cur) + id (uuid (.-id cur))] + (assoc-in acc [id :value] resolved-value))) + tokens sd-tokens)] + (when debug? + (js/console.log "Resolved tokens" resolved-tokens)) + resolved-tokens))) + (defn resolve-workspace-tokens+ [& {:keys [debug?] :as config}] (when-let [workspace-tokens @refs/workspace-tokens] - (p/let [sd-tokens (-> workspace-tokens - (tokens->tree) - (clj->js) - (resolve-tokens+ config))] - (let [resolved-tokens (reduce - (fn [acc cur] - (let [resolved-value (.-value cur) - id (uuid (.-id cur))] - (assoc-in acc [id :value] resolved-value))) - workspace-tokens sd-tokens)] - (when debug? - (js/console.log "Resolved tokens" resolved-tokens)) - resolved-tokens)))) + (resolve-tokens+ workspace-tokens))) ;; Testing --------------------------------------------------------------------- @@ -98,9 +101,9 @@ (tokens->tree) (clj->js) (#(doto % js/console.log)) - (resolve-tokens+ {:debug? true})) + (resolve-sd-tokens+ {:debug? true})) (-> (tokens-studio-example) - (resolve-tokens+ {:debug? true})) + (resolve-sd-tokens+ {:debug? true})) nil)