0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-07 15:39:42 -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.main.ui.workspace.tokens.token :as wtt]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.webapi :as wapi] [app.util.webapi :as wapi]
[cuerdas.core :as str] [cuerdas.core :as str]))
[app.common.data.macros :as dm]))
;; Helpers --------------------------------------------------------------------- ;; Helpers ---------------------------------------------------------------------
@ -24,25 +23,6 @@
(defn maybe-resolve-token-value [{:keys [value] :as token}] (defn maybe-resolve-token-value [{:keys [value] :as token}]
(when value (resolve-token-value 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]}] (defn tokens->select-options [{:keys [shape tokens attributes selected-attributes]}]
(map (map
(fn [{:keys [name] :as item}] (fn [{:keys [name] :as item}]

View file

@ -32,7 +32,8 @@
[cuerdas.core :as str] [cuerdas.core :as str]
[okulary.core :as l] [okulary.core :as l]
[rumext.v2 :as mf] [rumext.v2 :as mf]
[shadow.resource])) [shadow.resource]
[app.common.types.tokens-lib :as ctob]))
(def lens:token-type-open-status (def lens:token-type-open-status
(l/derived (l/in [:workspace-tokens :open-status]) st/state)) (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. "Separate token-types into groups of `:empty` or `:filled` depending if tokens exist for that type.
Sort each group alphabetically (by their `:token-key`)." Sort each group alphabetically (by their `:token-key`)."
[tokens] [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 {:keys [empty filled]} (->> wtty/token-types
(map (fn [[token-key token-type-props]] (map (fn [[token-key token-type-props]]
{:token-key token-key {:token-key token-key

View file

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