mirror of
https://github.com/penpot/penpot.git
synced 2025-02-12 18:18:24 -05:00
Return resolved & parsed token names map
This commit is contained in:
parent
37f23855e8
commit
0684d893e0
2 changed files with 19 additions and 16 deletions
|
@ -34,10 +34,9 @@
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(->> (rx/from (sd/resolve-tokens+ (get-in state [:workspace-data :tokens])))
|
(->> (rx/from (sd/resolve-tokens+ (get-in state [:workspace-data :tokens])))
|
||||||
(rx/mapcat
|
(rx/mapcat
|
||||||
(fn [sd-tokens]
|
(fn [resolved-tokens]
|
||||||
(let [undo-id (js/Symbol)
|
(let [undo-id (js/Symbol)
|
||||||
resolved-value (-> (get sd-tokens (:id token))
|
resolved-value (get-in resolved-tokens [(wtt/token-identifier token) :resolved-value])
|
||||||
(wtt/resolve-token-value))
|
|
||||||
tokenized-attributes (wtt/attributes-map attributes token)]
|
tokenized-attributes (wtt/attributes-map attributes token)]
|
||||||
(rx/of
|
(rx/of
|
||||||
(dwu/start-undo-transaction undo-id)
|
(dwu/start-undo-transaction undo-id)
|
||||||
|
|
|
@ -79,19 +79,16 @@
|
||||||
[tokens & {:keys [debug?] :as config}]
|
[tokens & {:keys [debug?] :as config}]
|
||||||
(p/let [sd-tokens (-> (wtt/token-names-tree tokens)
|
(p/let [sd-tokens (-> (wtt/token-names-tree tokens)
|
||||||
(resolve-sd-tokens+ config))]
|
(resolve-sd-tokens+ config))]
|
||||||
(let [tokens-by-name (wtt/token-names-map tokens)
|
(let [resolved-tokens (reduce
|
||||||
resolved-tokens (reduce
|
|
||||||
(fn [acc ^js cur]
|
(fn [acc ^js cur]
|
||||||
(let [value (.-value cur)
|
(let [id (uuid (.-uuid (.-id cur)))
|
||||||
resolved-value (d/parse-double (.-value cur))
|
origin-token (get tokens id)
|
||||||
original-value (-> cur .-original .-value)
|
resolved-value (wtt/parse-token-value (.-value cur))
|
||||||
id (.-name cur)
|
resolved-token (if (not resolved-value)
|
||||||
missing-reference? (and (not resolved-value)
|
(assoc origin-token :errors [:style-dictionary/missing-reference])
|
||||||
(re-find #"\{" value)
|
(assoc origin-token :resolved-value resolved-value))]
|
||||||
(= value original-value))]
|
(assoc acc (wtt/token-identifier resolved-token) resolved-token)))
|
||||||
(cond-> (assoc-in acc [id :resolved-value] resolved-value)
|
{} sd-tokens)]
|
||||||
missing-reference? (update-in [id :errors] (fnil conj #{}) :style-dictionary/missing-reference))))
|
|
||||||
tokens-by-name sd-tokens)]
|
|
||||||
(when debug?
|
(when debug?
|
||||||
(js/console.log "Resolved tokens" resolved-tokens))
|
(js/console.log "Resolved tokens" resolved-tokens))
|
||||||
resolved-tokens)))
|
resolved-tokens)))
|
||||||
|
@ -142,11 +139,18 @@
|
||||||
(comment
|
(comment
|
||||||
(defonce !output (atom nil))
|
(defonce !output (atom nil))
|
||||||
|
|
||||||
|
(-> @refs/workspace-tokens
|
||||||
|
(resolve-tokens+ {:debug? false})
|
||||||
|
(.then js/console.log))
|
||||||
|
|
||||||
(-> (resolve-workspace-tokens+ {:debug? true})
|
(-> (resolve-workspace-tokens+ {:debug? true})
|
||||||
(p/then #(reset! !output %)))
|
(p/then #(reset! !output %)))
|
||||||
|
|
||||||
|
@!output
|
||||||
|
|
||||||
(->> @refs/workspace-tokens
|
(->> @refs/workspace-tokens
|
||||||
(resolve-tokens+))
|
(resolve-tokens+)
|
||||||
|
(#(doto % js/console.log)))
|
||||||
|
|
||||||
(->
|
(->
|
||||||
(clj->js {"a" {:name "a" :value "5"}
|
(clj->js {"a" {:name "a" :value "5"}
|
||||||
|
|
Loading…
Add table
Reference in a new issue