mirror of
https://github.com/penpot/penpot.git
synced 2025-02-12 10:09:03 -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 _]
|
||||
(->> (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)
|
||||
|
|
|
@ -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"}
|
||||
|
|
Loading…
Add table
Reference in a new issue