mirror of
https://github.com/penpot/penpot.git
synced 2025-06-05 07:31:38 +02:00
🔥 Remove unnecesary API from tokens lib
Removes the `get-dtcg-tokens-tree` protocol method
This commit is contained in:
parent
f2f492bf3f
commit
626c65df02
1 changed files with 41 additions and 34 deletions
|
@ -329,8 +329,7 @@
|
||||||
(get-token [_ token-name] "return token by token-name")
|
(get-token [_ token-name] "return token by token-name")
|
||||||
(get-tokens [_] "return an ordered sequence of all tokens in the set")
|
(get-tokens [_] "return an ordered sequence of all tokens in the set")
|
||||||
(get-set-prefixed-path-string [_] "convert set name to prefixed full path string")
|
(get-set-prefixed-path-string [_] "convert set name to prefixed full path string")
|
||||||
(get-tokens-tree [_] "returns a tree of tokens split & nested by their name path")
|
(get-tokens-tree [_] "returns a tree of tokens split & nested by their name path"))
|
||||||
(get-dtcg-tokens-tree [_] "returns tokens tree formated to the dtcg spec"))
|
|
||||||
|
|
||||||
(defrecord TokenSet [name description modified-at tokens]
|
(defrecord TokenSet [name description modified-at tokens]
|
||||||
ITokenSet
|
ITokenSet
|
||||||
|
@ -381,14 +380,7 @@
|
||||||
(join-set-path)))
|
(join-set-path)))
|
||||||
|
|
||||||
(get-tokens-tree [_]
|
(get-tokens-tree [_]
|
||||||
(tokens-tree tokens))
|
(tokens-tree tokens)))
|
||||||
|
|
||||||
;; FIXME: looks redundant
|
|
||||||
(get-dtcg-tokens-tree [_]
|
|
||||||
(tokens-tree tokens :update-token-fn (fn [token]
|
|
||||||
(cond-> {"$value" (:value token)
|
|
||||||
"$type" (cto/token-type->dtcg-token-type (:type token))}
|
|
||||||
(:description token) (assoc "$description" (:description token)))))))
|
|
||||||
|
|
||||||
(defn token-set?
|
(defn token-set?
|
||||||
[o]
|
[o]
|
||||||
|
@ -1257,33 +1249,48 @@ Will return a value that matches this schema:
|
||||||
(d/ordered-map) active-themes)))
|
(d/ordered-map) active-themes)))
|
||||||
|
|
||||||
(encode-dtcg [this]
|
(encode-dtcg [this]
|
||||||
(let [themes (into []
|
(let [themes-xform
|
||||||
(comp
|
(comp
|
||||||
(filter #(and (instance? TokenTheme %)
|
(filter #(and (instance? TokenTheme %)
|
||||||
(not (hidden-temporary-theme? %))))
|
(not (hidden-temporary-theme? %))))
|
||||||
(map (fn [token-theme]
|
(map (fn [token-theme]
|
||||||
(let [theme-map (->> token-theme
|
(let [theme-map (->> token-theme
|
||||||
(into {})
|
(into {})
|
||||||
walk/stringify-keys)]
|
walk/stringify-keys)]
|
||||||
(-> theme-map
|
(-> theme-map
|
||||||
(set/rename-keys {"sets" "selectedTokenSets"})
|
(set/rename-keys {"sets" "selectedTokenSets"})
|
||||||
(update "selectedTokenSets" (fn [sets]
|
(update "selectedTokenSets" (fn [sets]
|
||||||
(->> (for [s sets]
|
(->> (for [s sets] [s "enabled"])
|
||||||
[s "enabled"])
|
(into {})))))))))
|
||||||
(into {})))))))))
|
themes
|
||||||
(tree-seq d/ordered-map? vals themes))
|
(->> (tree-seq d/ordered-map? vals themes)
|
||||||
|
(into [] themes-xform))
|
||||||
|
|
||||||
;; Active themes without exposing hidden penpot theme
|
;; Active themes without exposing hidden penpot theme
|
||||||
active-themes-clear (disj active-themes hidden-token-theme-path)
|
active-themes-clear
|
||||||
|
(disj active-themes hidden-token-theme-path)
|
||||||
|
|
||||||
name-set-tuples (->> sets
|
update-token-fn
|
||||||
(tree-seq d/ordered-map? vals)
|
(fn [token]
|
||||||
(filter (partial instance? TokenSet))
|
(cond-> {"$value" (:value token)
|
||||||
(map (fn [token-set]
|
"$type" (cto/token-type->dtcg-token-type (:type token))}
|
||||||
[(:name token-set) (get-dtcg-tokens-tree token-set)])))
|
(:description token) (assoc "$description" (:description token))))
|
||||||
ordered-set-names (mapv first name-set-tuples)
|
|
||||||
sets (into {} name-set-tuples)
|
|
||||||
active-sets (get-active-themes-set-names this)]
|
|
||||||
|
|
||||||
|
name-set-tuples
|
||||||
|
(->> sets
|
||||||
|
(tree-seq d/ordered-map? vals)
|
||||||
|
(filter (partial instance? TokenSet))
|
||||||
|
(map (fn [{:keys [name tokens]}]
|
||||||
|
[name (tokens-tree tokens :update-token-fn update-token-fn)])))
|
||||||
|
|
||||||
|
ordered-set-names
|
||||||
|
(mapv first name-set-tuples)
|
||||||
|
|
||||||
|
sets
|
||||||
|
(into {} name-set-tuples)
|
||||||
|
|
||||||
|
active-sets
|
||||||
|
(get-active-themes-set-names this)]
|
||||||
|
|
||||||
(-> sets
|
(-> sets
|
||||||
(assoc "$themes" themes)
|
(assoc "$themes" themes)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue