0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-06 14:50:20 -05:00
This commit is contained in:
Florian Schroedl 2024-10-02 11:09:52 +02:00
parent 93cc8214fa
commit 0ffcda404b
3 changed files with 13 additions and 33 deletions

View file

@ -11,8 +11,7 @@
[app.main.ui.workspace.tokens.token :as wtt]
[app.util.dom :as dom]
[app.util.webapi :as wapi]
[cuerdas.core :as str]
[app.common.data.macros :as dm]))
[cuerdas.core :as str]))
;; Helpers ---------------------------------------------------------------------
@ -24,25 +23,6 @@
(defn maybe-resolve-token-value [{:keys [value] :as token}]
(when value (resolve-token-value token)))
(defn group-tokens-by-type
"Groups tokens by their `:type` property."
[tokens]
(->> (vals tokens)
(group-by :type)))
(dm/legacy
(defn group-tokens-by-type-OLD
"Groups tokens by their `:type` property."
[tokens]
(->> (vals tokens)
(group-by :type))))
(defn tokens-name-map->select-options-OLD [{:keys [shape tokens attributes selected-attributes]}]
(->> (wtt/token-names-map tokens)
(map (fn [[_k {:keys [name] :as item}]]
(cond-> (assoc item :label name)
(wtt/token-applied? item shape (or selected-attributes attributes)) (assoc :selected? true))))))
(defn tokens->select-options [{:keys [shape tokens attributes selected-attributes]}]
(map
(fn [{:keys [name] :as item}]

View file

@ -32,7 +32,8 @@
[cuerdas.core :as str]
[okulary.core :as l]
[rumext.v2 :as mf]
[shadow.resource]))
[shadow.resource]
[app.common.types.tokens-lib :as ctob]))
(def lens:token-type-open-status
(l/derived (l/in [:workspace-tokens :open-status]) st/state))
@ -150,7 +151,7 @@
"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-type (wtc/group-tokens-by-type tokens)
(let [tokens-by-type (ctob/group-by-type tokens)
{:keys [empty filled]} (->> wtty/token-types
(map (fn [[token-key token-type-props]]
{:token-key token-key

View file

@ -117,16 +117,15 @@
:ids-map {}}
tokens))
(dm/legacy
(defn token-names-tree
"Convert tokens into a nested tree with their `:name` as the path."
[tokens]
(reduce
(fn [acc [_ {:keys [name] :as token}]]
(when (string? name)
(let [path (token-name->path name)]
(assoc-in acc path token))))
{} tokens)))
(defn token-names-tree
"Convert tokens into a nested tree with their `:name` as the path."
[tokens]
(reduce
(fn [acc [_ {:keys [name] :as token}]]
(when (string? name)
(let [path (token-name->path name)]
(assoc-in acc path token))))
{} tokens))
(defn token-name-path-exists?
"Traverses the path from `token-name` down a `token-tree` and checks if a token at that path exists.