From fdca6e4edf89054ff438c4353ef3c81d82725179 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 10:46:55 +0200 Subject: [PATCH] Fix measures options --- common/src/app/common/types/tokens_lib.cljc | 7 +++++++ frontend/src/app/main/refs.cljs | 8 -------- .../sidebar/options/menus/layout_container.cljs | 12 ++++++++---- .../ui/workspace/sidebar/options/menus/measures.cljs | 6 +++--- frontend/src/app/main/ui/workspace/tokens/core.cljs | 9 ++++++++- 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index b43ac7fd5..6fd65030b 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -132,6 +132,13 @@ token)) +(defn filter-by-type [token-type tokens] + (let [token-type? #(= token-type (:type %))] + (cond + (d/ordered-map? tokens) (into (d/ordered-map) (filter (comp token-type? val) tokens)) + (map? tokens) (into {} (filter (comp token-type? val) tokens)) + :else (filter token-type? tokens)))) + ;; === Token Set (defprotocol ITokenSet diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index 33687b81e..3e86ec33a 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -502,14 +502,6 @@ (def workspace-selected-token-set-tokens (l/derived #(or (wtts/get-selected-token-set-tokens %) {}) st/state)) -(dm/legacy - (def workspace-selected-token-set-tokens-OLD - (l/derived - (fn [data] - {}) - st/state - =))) - ;; ---- Viewer refs (defn lookup-viewer-objects-by-id diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/layout_container.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/layout_container.cljs index 0092dac58..47b3a8c87 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/layout_container.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/layout_container.cljs @@ -27,16 +27,18 @@ [app.main.ui.formats :as fmt] [app.main.ui.hooks :as h] [app.main.ui.icons :as i] + [app.main.ui.workspace.tokens.changes :as wtch] [app.main.ui.workspace.tokens.core :as wtc] [app.main.ui.workspace.tokens.editable-select :refer [editable-select]] + [app.main.ui.workspace.tokens.style-dictionary :as sd] [app.main.ui.workspace.tokens.token :as wtt] - [app.main.ui.workspace.tokens.changes :as wtch] [app.main.ui.workspace.tokens.token-types :as wtty] [app.util.dom :as dom] [app.util.i18n :as i18n :refer [tr]] [app.util.keyboard :as kbd] [cuerdas.core :as str] - [rumext.v2 :as mf])) + [rumext.v2 :as mf] + [app.common.types.tokens-lib :as ctob])) (defn- dir-icons-refactor [val] @@ -856,8 +858,10 @@ shape (when-not multiple (first (deref (refs/objects-by-id ids)))) - tokens (mf/deref refs/workspace-selected-token-set-tokens-OLD) - spacing-tokens (mf/use-memo (mf/deps tokens) #(:spacing (wtc/group-tokens-by-type-OLD tokens))) + tokens (sd/use-active-theme-sets-tokens) + spacing-tokens (mf/use-memo + (mf/deps tokens) + #(ctob/filter-by-type :spacing tokens)) spacing-column-options (mf/use-memo (mf/deps shape spacing-tokens) diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs index b1fdb562f..c5df4dc6c 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs @@ -108,21 +108,21 @@ border-radius-tokens (:border-radius tokens-by-type) border-radius-options (mf/use-memo (mf/deps shape border-radius-tokens) - #(wtc/tokens-name-map->select-options + #(wtc/tokens-name-map->select-options-OLD {:shape shape :tokens border-radius-tokens :attributes (wtty/token-attributes :border-radius)})) sizing-tokens (:sizing tokens-by-type) width-options (mf/use-memo (mf/deps shape sizing-tokens) - #(wtc/tokens-name-map->select-options + #(wtc/tokens-name-map->select-options-OLD {:shape shape :tokens sizing-tokens :attributes (wtty/token-attributes :sizing) :selected-attributes #{:width}})) height-options (mf/use-memo (mf/deps shape sizing-tokens) - #(wtc/tokens-name-map->select-options + #(wtc/tokens-name-map->select-options-OLD {:shape shape :tokens sizing-tokens :attributes (wtty/token-attributes :sizing) diff --git a/frontend/src/app/main/ui/workspace/tokens/core.cljs b/frontend/src/app/main/ui/workspace/tokens/core.cljs index 6fe482836..70d413e8d 100644 --- a/frontend/src/app/main/ui/workspace/tokens/core.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/core.cljs @@ -37,12 +37,19 @@ (->> (vals tokens) (group-by :type)))) -(defn tokens-name-map->select-options [{:keys [shape tokens attributes selected-attributes]}] +(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-name-map->select-options [{:keys [shape tokens attributes selected-attributes]}] + (map + (fn [[_k {:keys [name] :as item}]] + (cond-> (assoc item :label name) + (wtt/token-applied? item shape (or selected-attributes attributes)) (assoc :selected? true))) + tokens)) + ;; JSON export functions ------------------------------------------------------- (defn encode-tokens