mirror of
https://github.com/penpot/penpot.git
synced 2025-08-07 14:38:33 +02:00
Backporting resolved tokens to the original structure
This commit is contained in:
parent
1519f8f560
commit
4b90e90974
1 changed files with 30 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
(ns app.main.ui.workspace.tokens.style-dictionary
|
(ns app.main.ui.workspace.tokens.style-dictionary
|
||||||
(:require
|
(:require
|
||||||
[app.main.refs :as refs]
|
[app.main.refs :as refs]
|
||||||
|
[promesa.core :as p]
|
||||||
[shadow.resource]))
|
[shadow.resource]))
|
||||||
|
|
||||||
(def StyleDictionary
|
(def StyleDictionary
|
||||||
|
@ -9,6 +10,8 @@
|
||||||
because shadow-cljs doesn't support some of the more modern bundler features."
|
because shadow-cljs doesn't support some of the more modern bundler features."
|
||||||
js/window.StyleDictionary)
|
js/window.StyleDictionary)
|
||||||
|
|
||||||
|
(defonce !StyleDictionary (atom nil))
|
||||||
|
|
||||||
;; Helpers ---------------------------------------------------------------------
|
;; Helpers ---------------------------------------------------------------------
|
||||||
|
|
||||||
(defn tokens->tree
|
(defn tokens->tree
|
||||||
|
@ -16,7 +19,8 @@
|
||||||
[tokens]
|
[tokens]
|
||||||
(reduce
|
(reduce
|
||||||
(fn [acc [_ {:keys [type name] :as token}]]
|
(fn [acc [_ {:keys [type name] :as token}]]
|
||||||
(assoc-in acc [type name] token))
|
(->> (update token :id str)
|
||||||
|
(assoc-in acc [type name])))
|
||||||
{} tokens))
|
{} tokens))
|
||||||
|
|
||||||
;; Functions -------------------------------------------------------------------
|
;; Functions -------------------------------------------------------------------
|
||||||
|
@ -57,6 +61,23 @@
|
||||||
(js/console.log "Resolved tokens" resolved-tokens))
|
(js/console.log "Resolved tokens" 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))))
|
||||||
|
|
||||||
;; Testing ---------------------------------------------------------------------
|
;; Testing ---------------------------------------------------------------------
|
||||||
|
|
||||||
(defn tokens-studio-example []
|
(defn tokens-studio-example []
|
||||||
|
@ -65,6 +86,14 @@
|
||||||
.-core))
|
.-core))
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
|
|
||||||
|
(defonce !output (atom nil))
|
||||||
|
|
||||||
|
@!output
|
||||||
|
|
||||||
|
(-> (resolve-workspace-tokens+ {:debug? true})
|
||||||
|
(p/then #(reset! !output %)))
|
||||||
|
|
||||||
(-> @refs/workspace-tokens
|
(-> @refs/workspace-tokens
|
||||||
(tokens->tree)
|
(tokens->tree)
|
||||||
(clj->js)
|
(clj->js)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue