0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-06 14:50:20 -05:00

Make passing of names-map explicit

This commit is contained in:
Florian Schroedl 2024-08-21 14:42:39 +02:00
parent 7c3716a709
commit 011fc734f6
3 changed files with 26 additions and 6 deletions

View file

@ -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)

View file

@ -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)]

View file

@ -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))))))))