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

Extract token grouping to core

This commit is contained in:
Florian Schroedl 2024-05-15 17:44:06 +02:00
parent 622843f18d
commit 5e301605ad
2 changed files with 8 additions and 3 deletions

View file

@ -37,6 +37,12 @@
int-or-double
(throw (ex-info (str "Implement token value resolve for " value) token))))
(defn group-tokens-by-type
"Groups tokens by their `:type` property."
[tokens]
(->> (vals tokens)
(group-by :type)))
;; Update functions ------------------------------------------------------------
(defn on-apply-token [{:keys [token token-type-props selected-shapes] :as _props}]

View file

@ -113,13 +113,12 @@
"Separate token-types into groups of `:empty` or `:filled` depending if tokens exist for that type.
Sort each group alphabetically (by their `:token-key`)."
[tokens]
(let [tokens-by-group (->> (vals tokens)
(group-by :type))
(let [tokens-by-type (wtc/group-tokens-by-type tokens)
{:keys [empty filled]} (->> wtc/token-types
(map (fn [[token-key token-type-props]]
{:token-key token-key
:token-type-props token-type-props
:tokens (get tokens-by-group token-key [])}))
:tokens (get tokens-by-type token-key [])}))
(group-by (fn [{:keys [tokens]}]
(if (empty? tokens) :empty :filled))))]
{:empty (sort-by :token-key empty)