From 0684d893e06561e0c1ef754a61595b493a1af662 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 8 Aug 2024 11:06:49 +0200 Subject: [PATCH] Return resolved & parsed token names map --- .../app/main/ui/workspace/tokens/changes.cljs | 5 ++-- .../ui/workspace/tokens/style_dictionary.cljs | 30 +++++++++++-------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/changes.cljs b/frontend/src/app/main/ui/workspace/tokens/changes.cljs index e6e311ad00..45ff044df4 100644 --- a/frontend/src/app/main/ui/workspace/tokens/changes.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/changes.cljs @@ -34,10 +34,9 @@ (watch [_ state _] (->> (rx/from (sd/resolve-tokens+ (get-in state [:workspace-data :tokens]))) (rx/mapcat - (fn [sd-tokens] + (fn [resolved-tokens] (let [undo-id (js/Symbol) - resolved-value (-> (get sd-tokens (:id token)) - (wtt/resolve-token-value)) + resolved-value (get-in resolved-tokens [(wtt/token-identifier token) :resolved-value]) tokenized-attributes (wtt/attributes-map attributes token)] (rx/of (dwu/start-undo-transaction undo-id) 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 83231fc30c..1ab85db960 100644 --- a/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs @@ -79,19 +79,16 @@ [tokens & {:keys [debug?] :as config}] (p/let [sd-tokens (-> (wtt/token-names-tree tokens) (resolve-sd-tokens+ config))] - (let [tokens-by-name (wtt/token-names-map tokens) - resolved-tokens (reduce + (let [resolved-tokens (reduce (fn [acc ^js cur] - (let [value (.-value cur) - resolved-value (d/parse-double (.-value cur)) - original-value (-> cur .-original .-value) - id (.-name cur) - missing-reference? (and (not resolved-value) - (re-find #"\{" value) - (= value original-value))] - (cond-> (assoc-in acc [id :resolved-value] resolved-value) - missing-reference? (update-in [id :errors] (fnil conj #{}) :style-dictionary/missing-reference)))) - tokens-by-name sd-tokens)] + (let [id (uuid (.-uuid (.-id cur))) + origin-token (get tokens id) + resolved-value (wtt/parse-token-value (.-value cur)) + resolved-token (if (not resolved-value) + (assoc origin-token :errors [:style-dictionary/missing-reference]) + (assoc origin-token :resolved-value resolved-value))] + (assoc acc (wtt/token-identifier resolved-token) resolved-token))) + {} sd-tokens)] (when debug? (js/console.log "Resolved tokens" resolved-tokens)) resolved-tokens))) @@ -142,11 +139,18 @@ (comment (defonce !output (atom nil)) + (-> @refs/workspace-tokens + (resolve-tokens+ {:debug? false}) + (.then js/console.log)) + (-> (resolve-workspace-tokens+ {:debug? true}) (p/then #(reset! !output %))) + @!output + (->> @refs/workspace-tokens - (resolve-tokens+)) + (resolve-tokens+) + (#(doto % js/console.log))) (-> (clj->js {"a" {:name "a" :value "5"}