From 80e89037549266f5d29f7cfc09bf7f59da701eec Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 19 Sep 2024 10:26:17 +0200 Subject: [PATCH 01/92] Refactor: Use tokens-lib for getting tokens theme --- frontend/src/app/main/refs.cljs | 10 ++++++++-- .../app/main/ui/workspace/tokens/modals/themes.cljs | 8 +++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index 3e8994e36..422a7b2d5 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -250,8 +250,14 @@ (l/derived #(some-> % ctob/get-theme-groups) tokens-lib)) (defn workspace-token-theme - [id] - (l/derived #(wtts/get-workspace-theme id %) st/state)) + [group name] + (l/derived + (fn [lib] + (when lib + (ctob/get-theme lib group name))) + tokens-lib)) + +;; Old (def workspace-active-theme-ids (l/derived wtts/get-active-theme-ids st/state)) diff --git a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs index 47e00588d..9923c51d7 100644 --- a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs @@ -62,7 +62,8 @@ (dom/prevent-default e) (dom/stop-propagation e) (set-state (fn [_] {:type :edit-theme - :theme-id (:id theme)})))] + :theme-id (:id theme) + :theme-path [(:id theme) (:group theme) (:name theme)]})))] [:div [:ul {:class (stl/css :theme-group-wrapper)} (for [[group themes] themes] @@ -212,9 +213,10 @@ (mf/defc controlled-edit-theme [{:keys [state set-state]}] - (let [{:keys [theme-id]} @state + (let [{:keys [theme-path]} @state + [_ theme-group theme-name] theme-path token-sets (mf/deref refs/workspace-ordered-token-sets) - theme (mf/deref (refs/workspace-token-theme theme-id)) + theme (mf/deref (refs/workspace-token-theme theme-group theme-name)) theme-groups (mf/deref refs/workspace-token-theme-groups)] [:& edit-theme {:token-sets token-sets From 7758e48c48b41f5367f80c3230fdd9a8d8ee8274 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 19 Sep 2024 10:52:15 +0200 Subject: [PATCH 02/92] Add legacy macro --- frontend/src/app/main/ui/workspace/tokens/macros.clj | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 frontend/src/app/main/ui/workspace/tokens/macros.clj diff --git a/frontend/src/app/main/ui/workspace/tokens/macros.clj b/frontend/src/app/main/ui/workspace/tokens/macros.clj new file mode 100644 index 000000000..eb143c86e --- /dev/null +++ b/frontend/src/app/main/ui/workspace/tokens/macros.clj @@ -0,0 +1,5 @@ +(ns app.main.ui.workspace.tokens.macros) + +(defmacro legacy + "Purely annotational macro to find instances later to remove when the refactor to tokens-lib is done." + [& body] `(do ~@body)) From 743f61f2cd4ed5bf29a8846370e268b26a7cf3b8 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 19 Sep 2024 15:44:56 +0200 Subject: [PATCH 03/92] Adding themes --- common/src/app/common/data/macros.cljc | 4 +++ common/src/app/common/files/changes.cljc | 6 ++-- .../src/app/common/files/changes_builder.cljc | 6 ++-- common/src/app/common/macros.cljc | 0 common/src/app/common/types/token_theme.cljc | 3 +- frontend/src/app/main/data/tokens.cljs | 22 ++++++++------ .../app/main/ui/workspace/tokens/macros.clj | 5 ---- .../ui/workspace/tokens/modals/themes.cljs | 29 ++++++++++--------- 8 files changed, 40 insertions(+), 35 deletions(-) create mode 100644 common/src/app/common/macros.cljc delete mode 100644 frontend/src/app/main/ui/workspace/tokens/macros.clj diff --git a/common/src/app/common/data/macros.cljc b/common/src/app/common/data/macros.cljc index 7740ef362..2992aff9b 100644 --- a/common/src/app/common/data/macros.cljc +++ b/common/src/app/common/data/macros.cljc @@ -16,6 +16,10 @@ [cljs.analyzer.api :as aapi] [cuerdas.core :as str])) +(defmacro legacy + "Purely annotational macro to find instances later to remove when the refactor to tokens-lib is done." + [& body] `(do ~@body)) + (defmacro select-keys "A macro version of `select-keys`. Useful when keys vector is known at compile time (aprox 600% performance boost). diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index 67353769a..0d848f197 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -274,7 +274,7 @@ [:mod-token-theme [:map {:title "ModTokenThemeChange"} [:type [:= :mod-token-theme]] - [:id ::sm/uuid] + (dm/legacy [:id {:optional true} [:maybe ::sm/uuid]]) [:name :string] [:token-theme ::ctot/token-theme]]] @@ -860,7 +860,6 @@ (defmethod process-change :add-token-theme [data {:keys [token-theme]}] (-> data - (ctotl/add-token-theme token-theme) (update :tokens-lib #(-> % (ctob/ensure-tokens-lib) @@ -871,7 +870,8 @@ (defmethod process-change :mod-token-theme [data {:keys [id name group token-theme]}] (-> data - (ctotl/update-token-theme id merge token-theme) + (dm/legacy (#(when id + (ctotl/update-token-theme % (random-uuid) merge token-theme)))) (update :tokens-lib #(-> % (ctob/ensure-tokens-lib) diff --git a/common/src/app/common/files/changes_builder.cljc b/common/src/app/common/files/changes_builder.cljc index 44f57464c..6fd4aac22 100644 --- a/common/src/app/common/files/changes_builder.cljc +++ b/common/src/app/common/files/changes_builder.cljc @@ -713,14 +713,14 @@ [changes token-theme] (-> changes (update :redo-changes conj {:type :add-token-theme :token-theme token-theme}) - (update :undo-changes conj {:type :del-token-theme :id (:id token-theme) :name (:name token-theme)}) + ;; (legacy (update :undo-changes conj {:type :del-token-theme :name (:name token-theme)})) (apply-changes-local))) (defn update-token-theme [changes token-theme prev-token-theme] (-> changes - (update :redo-changes conj {:type :mod-token-theme :id (:id token-theme) :name (:name prev-token-theme) :token-theme token-theme}) - (update :undo-changes conj {:type :mod-token-theme :id (:id token-theme) :name (:name token-theme) :token-theme (or prev-token-theme token-theme)}) + (update :redo-changes conj {:type :mod-token-theme :name (:name prev-token-theme) :token-theme token-theme}) + (update :undo-changes conj {:type :mod-token-theme :name (:name token-theme) :token-theme (or prev-token-theme token-theme)}) (apply-changes-local))) (defn delete-token-theme diff --git a/common/src/app/common/macros.cljc b/common/src/app/common/macros.cljc new file mode 100644 index 000000000..e69de29bb diff --git a/common/src/app/common/types/token_theme.cljc b/common/src/app/common/types/token_theme.cljc index d76f1e277..59d1bdc03 100644 --- a/common/src/app/common/types/token_theme.cljc +++ b/common/src/app/common/types/token_theme.cljc @@ -6,11 +6,12 @@ (ns app.common.types.token-theme (:require + [app.common.data.macros :as dm] [app.common.schema :as sm])) (sm/register! ::token-theme [:map {:title "TokenTheme"} - [:id ::sm/uuid] + (dm/legacy [:id {:optional true} [:maybe ::sm/uuid]]) [:name :string] [:group {:optional true} :string] [:source? {:optional true} :boolean] diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index 820911b82..495c1f98c 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -11,6 +11,7 @@ [app.common.files.changes-builder :as pcb] [app.common.geom.point :as gpt] [app.common.types.shape :as cts] + [app.common.types.tokens-lib :as ctob] [app.common.uuid :as uuid] [app.main.data.changes :as dch] [app.main.data.workspace.shapes :as dwsh] @@ -40,6 +41,13 @@ (watch [_ _ _] (rx/of (dwsh/update-shapes [id] #(merge % attrs)))))) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; TOKENS Getters +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(defn get-tokens-lib [state] + (get-in state [:workspace-data :tokens-lib])) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; TOKENS Actions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -98,11 +106,7 @@ (map #(get-in file [:tokens %]) (:tokens token-set))) (defn create-token-theme [token-theme] - (let [new-token-theme (merge - {:id (uuid/next) - :sets #{} - :selected :enabled} - token-theme)] + (let [new-token-theme token-theme] (ptk/reify ::create-token-theme ptk/WatchEvent (watch [it _ _] @@ -111,13 +115,13 @@ (rx/of (dch/commit-changes changes))))))) -(defn update-token-theme [token-theme] +(defn update-token-theme [[group name] token-theme] (ptk/reify ::update-token-theme ptk/WatchEvent (watch [it state _] - (let [prev-token-theme (wtts/get-workspace-token-theme (:id token-theme) state) - changes (-> (pcb/empty-changes it) - (pcb/update-token-theme token-theme prev-token-theme))] + (let [tokens-lib (get-tokens-lib state) + prev-token-theme (some-> tokens-lib (ctob/get-theme group name)) + changes (pcb/update-token-theme (pcb/empty-changes it) token-theme prev-token-theme)] (rx/of (dch/commit-changes changes)))))) diff --git a/frontend/src/app/main/ui/workspace/tokens/macros.clj b/frontend/src/app/main/ui/workspace/tokens/macros.clj deleted file mode 100644 index eb143c86e..000000000 --- a/frontend/src/app/main/ui/workspace/tokens/macros.clj +++ /dev/null @@ -1,5 +0,0 @@ -(ns app.main.ui.workspace.tokens.macros) - -(defmacro legacy - "Purely annotational macro to find instances later to remove when the refactor to tokens-lib is done." - [& body] `(do ~@body)) diff --git a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs index 9923c51d7..62ffa17e3 100644 --- a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs @@ -15,12 +15,11 @@ [app.main.ui.icons :as i] [app.main.ui.workspace.tokens.common :refer [labeled-input] :as wtco] [app.main.ui.workspace.tokens.sets :as wts] + [app.main.ui.workspace.tokens.sets-context :as sets-context] [app.main.ui.workspace.tokens.token-set :as wtts] [app.util.dom :as dom] - [rumext.v2 :as mf] [cuerdas.core :as str] - [app.main.ui.workspace.tokens.sets-context :as sets-context] - [app.main.ui.shapes.group :as group])) + [rumext.v2 :as mf])) (def ^:private chevron-icon (i/icon-xref :arrow (stl/css :chevron-icon))) @@ -110,10 +109,8 @@ "Create theme"]]])) (mf/defc edit-theme - [{:keys [token-sets theme theme-groups on-back on-submit]}] + [{:keys [edit? token-sets theme theme-groups on-back on-submit]}] (let [{:keys [dropdown-open? on-open-dropdown on-close-dropdown on-toggle-dropdown]} (wtco/use-dropdown-open-state) - - edit? (some? (:id theme)) theme-state (mf/use-state {:token-sets token-sets :theme theme}) disabled? (-> (get-in @theme-state [:theme :name]) @@ -139,13 +136,15 @@ (fn [e] (dom/prevent-default e) (let [theme (:theme @theme-state) - final-name (str/trim (:name theme)) - final-group (-> (:group theme) - (str/trim) - (str/lower))] + final-name (-> (:name theme) + (str/trim)) + empty-description? (-> (:description theme) + (str/trim) + (str/empty?))] (when-not (str/empty? final-name) (cond-> theme - (empty final-group) (dissoc :group) + empty-description? (assoc :description "") + :always (doto js/console.log) :always on-submit))) (on-back)))] [:form {:on-submit on-save-form} @@ -219,11 +218,12 @@ theme (mf/deref (refs/workspace-token-theme theme-group theme-name)) theme-groups (mf/deref refs/workspace-token-theme-groups)] [:& edit-theme - {:token-sets token-sets + {:edit? true + :token-sets token-sets :theme theme :theme-groups theme-groups :on-back #(set-state (constantly {:type :themes-overview})) - :on-submit #(st/emit! (wdt/update-token-theme %))}])) + :on-submit #(st/emit! (wdt/update-token-theme [(:group theme) (:name theme)] %))}])) (mf/defc create-theme [{:keys [set-state]}] @@ -231,7 +231,8 @@ theme {:name "" :sets #{}} theme-groups (mf/deref refs/workspace-token-theme-groups)] [:& edit-theme - {:token-sets token-sets + {:edit? false + :token-sets token-sets :theme theme :theme-groups theme-groups :on-back #(set-state (constantly {:type :themes-overview})) From 191d95798460844e73458c537d3bcd90a01272e3 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 19 Sep 2024 16:06:53 +0200 Subject: [PATCH 04/92] Use theme listing --- frontend/src/app/main/refs.cljs | 77 +++++++++++-------- .../ui/workspace/tokens/modals/themes.cljs | 13 ++-- .../app/main/ui/workspace/tokens/sidebar.cljs | 2 +- .../ui/workspace/tokens/theme_select.cljs | 4 +- 4 files changed, 55 insertions(+), 41 deletions(-) diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index 422a7b2d5..76ab34870 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -12,11 +12,11 @@ [app.common.files.helpers :as cph] [app.common.types.shape-tree :as ctt] [app.common.types.shape.layout :as ctl] + [app.common.types.tokens-lib :as ctob] [app.main.data.workspace.state-helpers :as wsh] [app.main.store :as st] [app.main.ui.workspace.tokens.token-set :as wtts] - [okulary.core :as l] - [app.common.types.tokens-lib :as ctob])) + [okulary.core :as l])) ;; ---- Global refs @@ -257,42 +257,57 @@ (ctob/get-theme lib group name))) tokens-lib)) -;; Old - -(def workspace-active-theme-ids - (l/derived wtts/get-active-theme-ids st/state)) - -(def workspace-temp-theme-id - (l/derived wtts/get-temp-theme-id st/state)) - -(def workspace-active-set-ids - (l/derived wtts/get-active-set-ids st/state)) +(def workspace-token-theme-tree + (l/derived #(or (some-> % ctob/get-theme-tree) []) tokens-lib)) (def workspace-token-themes - (l/derived wtts/get-workspace-themes-index st/state)) + (l/derived #(or (some-> % ctob/get-themes) []) tokens-lib)) -(def workspace-ordered-token-themes - (l/derived wtts/get-workspace-ordered-themes st/state)) +(comment + @workspace-token-theme-tree + @workspace-token-themes-OLD + nil) -(def workspace-ordered-token-sets - (l/derived - (fn [data] - (or (wtts/get-workspace-ordered-sets data) {})) - st/state - =)) -(def workspace-active-theme-sets-tokens - (l/derived wtts/get-active-theme-sets-tokens-names-map st/state =)) -(def workspace-ordered-token-sets-tokens - (l/derived wtts/get-workspace-ordered-sets-tokens st/state =)) +;; Old -(def workspace-selected-token-set-tokens - (l/derived - (fn [data] - (or (wtts/get-selected-token-set-tokens data) {})) - st/state - =)) +(dm/legacy + + (def workspace-active-theme-ids + (l/derived wtts/get-active-theme-ids st/state)) + + (def workspace-temp-theme-id + (l/derived wtts/get-temp-theme-id st/state)) + + (def workspace-active-set-ids + (l/derived wtts/get-active-set-ids st/state)) + + (def workspace-token-themes-OLD + (l/derived wtts/get-workspace-themes-index st/state)) + + (def workspace-ordered-token-themes-OLD + (l/derived wtts/get-workspace-ordered-themes st/state)) + + (def workspace-ordered-token-sets + (l/derived + (fn [data] + (or (wtts/get-workspace-ordered-sets data) {})) + st/state + =)) + + (def workspace-active-theme-sets-tokens + (l/derived wtts/get-active-theme-sets-tokens-names-map st/state =)) + + (def workspace-ordered-token-sets-tokens + (l/derived wtts/get-workspace-ordered-sets-tokens st/state =)) + + (def workspace-selected-token-set-tokens + (l/derived + (fn [data] + (or (wtts/get-selected-token-set-tokens data) {})) + st/state + =))) (def workspace-file-colors (l/derived (fn [data] diff --git a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs index 62ffa17e3..0dc6fcb57 100644 --- a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs @@ -56,21 +56,20 @@ (mf/defc themes-overview [{:keys [set-state]}] (let [active-theme-ids (mf/deref refs/workspace-active-theme-ids) - themes (mf/deref refs/workspace-ordered-token-themes) + themes-groups (mf/deref refs/workspace-token-theme-tree) on-edit-theme (fn [theme e] (dom/prevent-default e) (dom/stop-propagation e) (set-state (fn [_] {:type :edit-theme - :theme-id (:id theme) :theme-path [(:id theme) (:group theme) (:name theme)]})))] [:div [:ul {:class (stl/css :theme-group-wrapper)} - (for [[group themes] themes] + (for [[group themes] themes-groups] [:li {:key (str "token-theme-group" group)} (when (seq group) [:span {:class (stl/css :theme-group-label)} group]) [:ul {:class (stl/css :theme-group-rows-wrapper)} - (for [{:keys [id name] :as theme} themes + (for [[_ {:keys [id name] :as theme}] themes :let [selected? (some? (get active-theme-ids id))]] [:li {:key (str "token-theme-" id) :class (stl/css :theme-row)} @@ -239,8 +238,8 @@ :on-submit #(st/emit! (wdt/create-token-theme %))}])) (mf/defc themes - [{:keys [] :as _args}] - (let [themes (mf/deref refs/workspace-ordered-token-themes) + [_] + (let [themes (mf/deref refs/workspace-token-themes) state (mf/use-state (if (empty? themes) {:type :create-theme} {:type :themes-overview})) @@ -261,7 +260,7 @@ (mf/defc modal {::mf/wrap-props false} - [{:keys [] :as _args}] + [_] (let [handle-close-dialog (mf/use-callback #(st/emit! (modal/hide)))] [:div {:class (stl/css :modal-overlay)} [:div {:class (stl/css :modal-dialog)} diff --git a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs index b76b8e1df..8e8a371a0 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs @@ -200,7 +200,7 @@ (mf/defc themes-sidebar [_props] - (let [ordered-themes (mf/deref refs/workspace-ordered-token-themes)] + (let [ordered-themes (mf/deref refs/workspace-ordered-token-themes-OLD)] [:div {:class (stl/css :theme-sidebar)} [:span {:class (stl/css :themes-header)} "Themes"] [:div {:class (stl/css :theme-select-wrapper)} diff --git a/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs b/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs index 0f0cc2a4e..66f9d4d47 100644 --- a/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs @@ -38,7 +38,7 @@ (mf/defc theme-options [{:keys [on-close]}] (let [active-theme-ids (mf/deref refs/workspace-active-theme-ids) - ordered-themes (mf/deref refs/workspace-ordered-token-themes) + ordered-themes (mf/deref refs/workspace-ordered-token-themes-OLD) grouped-themes (dissoc ordered-themes nil) ungrouped-themes (get ordered-themes nil)] [:ul @@ -66,7 +66,7 @@ active-theme-ids (-> (mf/deref refs/workspace-active-theme-ids) (disj temp-theme-id)) active-themes-count (count active-theme-ids) - themes (mf/deref refs/workspace-token-themes) + themes (mf/deref refs/workspace-token-themes-OLD) ;; Data current-label (cond From 9b2993a344335ed1cdd522c37d2447540f88bd5b Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 19 Sep 2024 16:22:47 +0200 Subject: [PATCH 05/92] Fix theme select --- common/src/app/common/data/macros.cljc | 4 +++ .../ui/workspace/tokens/theme_select.cljs | 26 ++++++++----------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/common/src/app/common/data/macros.cljc b/common/src/app/common/data/macros.cljc index 2992aff9b..00a1aaeb2 100644 --- a/common/src/app/common/data/macros.cljc +++ b/common/src/app/common/data/macros.cljc @@ -16,6 +16,10 @@ [cljs.analyzer.api :as aapi] [cuerdas.core :as str])) +(defmacro fixme + "Purely annotational macro to find instances later to remove when the refactor to tokens-lib is done." + [& body] `(do ~@body)) + (defmacro legacy "Purely annotational macro to find instances later to remove when the refactor to tokens-lib is done." [& body] `(do ~@body)) diff --git a/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs b/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs index 66f9d4d47..09ab604d2 100644 --- a/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs @@ -7,6 +7,7 @@ (ns app.main.ui.workspace.tokens.theme-select (:require-macros [app.main.style :as stl]) (:require + [app.common.data.macros :as dm] [app.common.uuid :as uuid] [app.main.data.modal :as modal] [app.main.data.tokens :as wdt] @@ -21,7 +22,7 @@ [{:keys [themes active-theme-ids on-close grouped?]}] (when (seq themes) [:ul - (for [{:keys [id name]} themes + (for [[_ {:keys [id name]}] themes :let [selected? (get active-theme-ids id)]] [:li {:key id :class (stl/css-case @@ -37,17 +38,12 @@ (mf/defc theme-options [{:keys [on-close]}] - (let [active-theme-ids (mf/deref refs/workspace-active-theme-ids) - ordered-themes (mf/deref refs/workspace-ordered-token-themes-OLD) - grouped-themes (dissoc ordered-themes nil) - ungrouped-themes (get ordered-themes nil)] + (let [active-theme-ids (dm/fixme (mf/deref refs/workspace-active-theme-ids)) + theme-groups (mf/deref refs/workspace-token-theme-tree)] [:ul - [:& themes-list {:themes ungrouped-themes - :active-theme-ids active-theme-ids - :on-close on-close}] - (for [[group themes] grouped-themes] + (for [[group themes] theme-groups] [:li {:key group} - (when group + (when (seq group) [:span {:class (stl/css :group)} group]) [:& themes-list {:themes themes :active-theme-ids active-theme-ids @@ -62,16 +58,16 @@ (mf/defc theme-select [{:keys []}] (let [;; Store - temp-theme-id (mf/deref refs/workspace-temp-theme-id) - active-theme-ids (-> (mf/deref refs/workspace-active-theme-ids) - (disj temp-theme-id)) + temp-theme-id (dm/legacy (mf/deref refs/workspace-temp-theme-id)) + active-theme-ids (dm/legacy (-> (mf/deref refs/workspace-active-theme-ids) + (disj temp-theme-id))) active-themes-count (count active-theme-ids) - themes (mf/deref refs/workspace-token-themes-OLD) + themes (mf/deref refs/workspace-token-theme-tree) ;; Data current-label (cond (> active-themes-count 1) (str active-themes-count " themes active") - (pos? active-themes-count) (get-in themes [(first active-theme-ids) :name]) + ;; (pos? active-themes-count) (get-in themes [(first active-theme-ids) :name]) :else "No theme active") ;; State From 501256f16bb28a13f1124bcb93fbd07d28f2ba8d Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Fri, 20 Sep 2024 09:34:54 +0200 Subject: [PATCH 06/92] Disable namespace loading info in console from shadow-cljs --- frontend/dev/preload.cljs | 7 +++++++ frontend/shadow-cljs.edn | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 frontend/dev/preload.cljs diff --git a/frontend/dev/preload.cljs b/frontend/dev/preload.cljs new file mode 100644 index 000000000..57d3cc0d8 --- /dev/null +++ b/frontend/dev/preload.cljs @@ -0,0 +1,7 @@ +(ns preload + (:require + [devtools.core :as devtools])) + +;; Silence shadow-cljs devtools (ns reloading) +(devtools/set-pref! :dont-display-banner true) +(devtools/set-pref! :min-expandable-sequable-count-for-well-known-types 0) diff --git a/frontend/shadow-cljs.edn b/frontend/shadow-cljs.edn index ef001a93d..6e26f906d 100644 --- a/frontend/shadow-cljs.edn +++ b/frontend/shadow-cljs.edn @@ -8,7 +8,9 @@ {:target :browser :output-dir "resources/public/js/" :asset-path "/js" - :devtools {:browser-inject :main + :devtools {:preloads [preload devtools.preload] + :log false + :browser-inject :main :watch-dir "resources/public" :reload-strategy :full} :build-options {:manifest-name "manifest.json"} @@ -65,7 +67,8 @@ :compiler-options {:output-feature-set :es2020 :output-wrapper false - :warnings {:fn-deprecated false}} + :warnings {:fn-deprecated false} + :closure-defines {shadow.debug.LogLevel :warning}} :release {:closure-defines {goog.DEBUG false From f5249196f994241dd3ec47c3e868ad44532bba1b Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Fri, 20 Sep 2024 14:27:19 +0200 Subject: [PATCH 07/92] Sets sidebar --- .../options/menus/layout_container.cljs | 2 +- .../sidebar/options/menus/measures.cljs | 2 +- .../app/main/ui/workspace/tokens/core.cljs | 10 +++- .../app/main/ui/workspace/tokens/sets.cljs | 2 +- .../app/main/ui/workspace/tokens/sidebar.cljs | 1 - .../ui/workspace/tokens/style_dictionary.cljs | 60 ++++++++++--------- .../app/main/ui/workspace/tokens/token.cljs | 36 ++++++++--- .../main/ui/workspace/tokens/token_set.cljs | 42 ++++++++----- 8 files changed, 96 insertions(+), 59 deletions(-) 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 ef32a4e67..b758051d5 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 @@ -857,7 +857,7 @@ shape (when-not multiple (first (deref (refs/objects-by-id ids)))) tokens (mf/deref refs/workspace-selected-token-set-tokens) - spacing-tokens (mf/use-memo (mf/deps tokens) #(:spacing (wtc/group-tokens-by-type tokens))) + spacing-tokens (mf/use-memo (mf/deps tokens) #(:spacing (wtc/group-tokens-by-type-OLD 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 2f9dd5a3a..b1fdb562f 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 @@ -103,7 +103,7 @@ tokens (-> (mf/deref refs/workspace-active-theme-sets-tokens) (sd/use-resolved-tokens)) - tokens-by-type (mf/use-memo (mf/deps tokens) #(wtc/group-tokens-by-type tokens)) + tokens-by-type (mf/use-memo (mf/deps tokens) #(wtc/group-tokens-by-type-OLD tokens)) border-radius-tokens (:border-radius tokens-by-type) border-radius-options (mf/use-memo diff --git a/frontend/src/app/main/ui/workspace/tokens/core.cljs b/frontend/src/app/main/ui/workspace/tokens/core.cljs index 489d3f041..117e7b3df 100644 --- a/frontend/src/app/main/ui/workspace/tokens/core.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/core.cljs @@ -11,7 +11,8 @@ [app.main.ui.workspace.tokens.token :as wtt] [app.util.dom :as dom] [app.util.webapi :as wapi] - [cuerdas.core :as str])) + [cuerdas.core :as str] + [app.common.data.macros :as dm])) ;; Helpers --------------------------------------------------------------------- @@ -29,6 +30,13 @@ (->> (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 [{:keys [shape tokens attributes selected-attributes]}] (->> (wtt/token-names-map tokens) (map (fn [[_k {:keys [name] :as item}]] diff --git a/frontend/src/app/main/ui/workspace/tokens/sets.cljs b/frontend/src/app/main/ui/workspace/tokens/sets.cljs index 11db39e78..c4f95f992 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sets.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sets.cljs @@ -72,7 +72,7 @@ on-cancel] :as _props}] (let [{:keys [id name _children]} token-set - selected? (and set? (token-set-selected? id)) + selected? (and set? (token-set-selected? name)) visible? (token-set-active? id) collapsed? (mf/use-state false) set? true #_(= type :set) diff --git a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs index 8e8a371a0..64ebfb449 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs @@ -241,7 +241,6 @@ selected (mf/deref refs/selected-shapes) selected-shapes (into [] (keep (d/getf objects)) selected) - active-theme-tokens (sd/use-active-theme-sets-tokens) tokens (sd/use-resolved-workspace-tokens) diff --git a/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs b/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs index 72e133730..7c6f73200 100644 --- a/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs @@ -72,34 +72,34 @@ (defn resolve-tokens+ [tokens & {:keys [names-map?] :as config}] - (p/let [sd-tokens (-> (wtt/token-names-tree tokens) - (resolve-sd-tokens+))] - (let [resolved-tokens (reduce - (fn [acc ^js cur] - (let [identifier (if names-map? - (.. cur -original -name) - (uuid (.-uuid (.-id cur)))) - {:keys [type] :as origin-token} (get tokens identifier) - value (.-value cur) - token-or-err (case type - :color (if-let [tc (tinycolor/valid-color value)] - {:value value :unit (tinycolor/color-format tc)} - {:errors [(wte/error-with-value :error.token/invalid-color value)]}) - (or (wtt/parse-token-value value) - (if-let [references (-> (wtt/find-token-references value) - (seq))] - {:errors [(wte/error-with-value :error.style-dictionary/missing-reference references)] - :references references} - {:errors [(wte/error-with-value :error.style-dictionary/invalid-token-value value)]}))) - output-token (if (:errors token-or-err) - (merge origin-token token-or-err) - (assoc origin-token - :resolved-value (:value token-or-err) - :unit (:unit token-or-err)))] - (assoc acc (wtt/token-identifier output-token) output-token))) - {} sd-tokens)] - (l/debug :hint "Resolved tokens" :js/tokens resolved-tokens) - resolved-tokens))) + (let [{:keys [tree ids-map]} (wtt/token-names-tree-id-map tokens)] + (p/let [sd-tokens (resolve-sd-tokens+ tree)] + (let [resolved-tokens (reduce + (fn [acc ^js cur] + (let [identifier (if names-map? + (.. cur -original -name) + (uuid (.-uuid (.-id cur)))) + {:keys [type] :as origin-token} (get ids-map identifier) + value (.-value cur) + token-or-err (case type + :color (if-let [tc (tinycolor/valid-color value)] + {:value value :unit (tinycolor/color-format tc)} + {:errors [(wte/error-with-value :error.token/invalid-color value)]}) + (or (wtt/parse-token-value value) + (if-let [references (-> (wtt/find-token-references value) + (seq))] + {:errors [(wte/error-with-value :error.style-dictionary/missing-reference references)] + :references references} + {:errors [(wte/error-with-value :error.style-dictionary/invalid-token-value value)]}))) + output-token (if (:errors token-or-err) + (merge origin-token token-or-err) + (assoc origin-token + :resolved-value (:value token-or-err) + :unit (:unit token-or-err)))] + (assoc acc (wtt/token-identifier output-token) output-token))) + {} sd-tokens)] + (l/debug :hint "Resolved tokens" :js/tokens resolved-tokens) + resolved-tokens)))) ;; Hooks ----------------------------------------------------------------------- @@ -125,7 +125,9 @@ (let [cached (get @cache-atom tokens)] (cond ;; The tokens are already processing somewhere - (p/promise? cached) (p/then cached #(reset! tokens-state %)) + (p/promise? cached) (-> cached + (p/then #(reset! tokens-state %)) + #_(p/catch js/console.error)) ;; Get the cached entry (some? cached) (reset! tokens-state cached) ;; No cached entry, start processing diff --git a/frontend/src/app/main/ui/workspace/tokens/token.cljs b/frontend/src/app/main/ui/workspace/tokens/token.cljs index 5f1a95766..9c097b180 100644 --- a/frontend/src/app/main/ui/workspace/tokens/token.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/token.cljs @@ -1,9 +1,10 @@ (ns app.main.ui.workspace.tokens.token (:require [app.common.data :as d] + [app.common.data.macros :as dm] + [app.main.ui.workspace.tokens.tinycolor :as tinycolor] [clojure.set :as set] - [cuerdas.core :as str] - [app.main.ui.workspace.tokens.tinycolor :as tinycolor])) + [cuerdas.core :as str])) (defn get-workspace-tokens [state] @@ -117,15 +118,32 @@ (->> (map (fn [{:keys [name] :as token}] [name token]) tokens) (into {}))) -(defn token-names-tree - "Convert tokens into a nested tree with their `:name` as the path." - [tokens] +(defonce a (atom nil)) + +(defn token-names-tree-id-map [tokens] + (reset! a tokens) (reduce - (fn [acc [_ {:keys [name] :as token}]] + (fn [acc {:keys [name] :as token}] (when (string? name) - (let [path (token-name->path name)] - (assoc-in acc path token)))) - {} tokens)) + (let [temp-id (random-uuid) + token (assoc token :temp/id temp-id)] + (-> acc + (assoc-in (concat [:tree] (token-name->path name)) token) + (assoc-in [:ids-map temp-id] token))))) + {:tree {} + :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-name-path-exists? "Traverses the path from `token-name` down a `token-tree` and checks if a token at that path exists. diff --git a/frontend/src/app/main/ui/workspace/tokens/token_set.cljs b/frontend/src/app/main/ui/workspace/tokens/token_set.cljs index b7b06e59e..237b778cd 100644 --- a/frontend/src/app/main/ui/workspace/tokens/token_set.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/token_set.cljs @@ -2,7 +2,11 @@ (:require [app.common.data :refer [ordered-map]] [app.main.ui.workspace.tokens.token :as wtt] - [clojure.set :as set])) + [clojure.set :as set] + [app.common.types.tokens-lib :as ctob])) + +(defn get-workspace-tokens-lib [state] + (get-in state [:workspace-data :tokens-lib])) ;; Themes ---------------------------------------------------------------------- @@ -146,21 +150,6 @@ (-> (get-token-set set-id state) :tokens)) -(defn get-selected-token-set-id [state] - (or (get-in state [:workspace-local :selected-token-set-id]) - (get-in state [:workspace-data :token-set-groups 0]))) - -(defn get-selected-token-set [state] - (when-let [id (get-selected-token-set-id state)] - (get-token-set id state))) - -(defn get-selected-token-set-tokens [state] - (when-let [token-set (get-selected-token-set state)] - (let [tokens (or (wtt/get-workspace-tokens state) {})] - (select-keys tokens (:tokens token-set))))) - -(defn assoc-selected-token-set-id [state id] - (assoc-in state [:workspace-local :selected-token-set-id] id)) (defn get-active-theme-sets-tokens-names-map [state] (let [active-set-ids (get-ordered-active-set-ids state)] @@ -174,3 +163,24 @@ acc)) names-map-acc token-ids))) (ordered-map) active-set-ids))) + +;; === Set selection + +(defn get-selected-token-set-id [state] + (or (get-in state [:workspace-local :selected-token-set-id]) + (some-> (get-workspace-tokens-lib state) + (ctob/get-sets) + (first) + (:name)))) + +(defn get-selected-token-set [state] + (when-let [id (get-selected-token-set-id state)] + (some-> (get-workspace-tokens-lib state) + (ctob/get-set id)))) + +(defn get-selected-token-set-tokens [state] + (some-> (get-selected-token-set state) + (ctob/get-tokens))) + +(defn assoc-selected-token-set-id [state id] + (assoc-in state [:workspace-local :selected-token-set-id] id)) From 43e5e780533c959e09c2ec22139a5d3a1d06786e Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Fri, 20 Sep 2024 14:35:47 +0200 Subject: [PATCH 08/92] Cleanup --- frontend/src/app/main/refs.cljs | 135 +++++++++++++++----------------- 1 file changed, 61 insertions(+), 74 deletions(-) diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index 76ab34870..8f4ef4d6a 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -235,80 +235,6 @@ (def workspace-data (l/derived :workspace-data st/state)) -(def workspace-selected-token-set-id - (l/derived - wtts/get-selected-token-set-id - st/state - =)) - -;; ---- Tokens - -(def tokens-lib - (l/derived :tokens-lib workspace-data)) - -(def workspace-token-theme-groups - (l/derived #(some-> % ctob/get-theme-groups) tokens-lib)) - -(defn workspace-token-theme - [group name] - (l/derived - (fn [lib] - (when lib - (ctob/get-theme lib group name))) - tokens-lib)) - -(def workspace-token-theme-tree - (l/derived #(or (some-> % ctob/get-theme-tree) []) tokens-lib)) - -(def workspace-token-themes - (l/derived #(or (some-> % ctob/get-themes) []) tokens-lib)) - -(comment - @workspace-token-theme-tree - @workspace-token-themes-OLD - nil) - - - -;; Old - -(dm/legacy - - (def workspace-active-theme-ids - (l/derived wtts/get-active-theme-ids st/state)) - - (def workspace-temp-theme-id - (l/derived wtts/get-temp-theme-id st/state)) - - (def workspace-active-set-ids - (l/derived wtts/get-active-set-ids st/state)) - - (def workspace-token-themes-OLD - (l/derived wtts/get-workspace-themes-index st/state)) - - (def workspace-ordered-token-themes-OLD - (l/derived wtts/get-workspace-ordered-themes st/state)) - - (def workspace-ordered-token-sets - (l/derived - (fn [data] - (or (wtts/get-workspace-ordered-sets data) {})) - st/state - =)) - - (def workspace-active-theme-sets-tokens - (l/derived wtts/get-active-theme-sets-tokens-names-map st/state =)) - - (def workspace-ordered-token-sets-tokens - (l/derived wtts/get-workspace-ordered-sets-tokens st/state =)) - - (def workspace-selected-token-set-tokens - (l/derived - (fn [data] - (or (wtts/get-selected-token-set-tokens data) {})) - st/state - =))) - (def workspace-file-colors (l/derived (fn [data] (when data @@ -517,6 +443,67 @@ ids))) st/state =)) +;; ---- Token refs + +(def tokens-lib + (l/derived :tokens-lib workspace-data)) + +(def workspace-token-theme-groups + (l/derived #(some-> % ctob/get-theme-groups) tokens-lib)) + +(defn workspace-token-theme + [group name] + (l/derived + (fn [lib] + (when lib + (ctob/get-theme lib group name))) + tokens-lib)) + +(def workspace-token-theme-tree + (l/derived #(or (some-> % ctob/get-theme-tree) []) tokens-lib)) + +(def workspace-token-themes + (l/derived #(or (some-> % ctob/get-themes) []) tokens-lib)) + +(dm/legacy + (def workspace-selected-token-set-id + (l/derived + wtts/get-selected-token-set-id + st/state + =)) + + (def workspace-active-theme-ids + (l/derived wtts/get-active-theme-ids st/state)) + + (def workspace-temp-theme-id + (l/derived wtts/get-temp-theme-id st/state)) + + (def workspace-active-set-ids + (l/derived wtts/get-active-set-ids st/state)) + + (def workspace-ordered-token-themes-OLD + (l/derived wtts/get-workspace-ordered-themes st/state)) + + (def workspace-ordered-token-sets + (l/derived + (fn [data] + (or (wtts/get-workspace-ordered-sets data) {})) + st/state + =)) + + (def workspace-active-theme-sets-tokens + (l/derived wtts/get-active-theme-sets-tokens-names-map st/state =)) + + (def workspace-ordered-token-sets-tokens + (l/derived wtts/get-workspace-ordered-sets-tokens st/state =)) + + (def workspace-selected-token-set-tokens + (l/derived + (fn [data] + (or (wtts/get-selected-token-set-tokens data) {})) + st/state + =))) + ;; ---- Viewer refs (defn lookup-viewer-objects-by-id From c6770f43c77b717bd9f791139c2ea1ffa5bffd8c Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Fri, 20 Sep 2024 14:38:53 +0200 Subject: [PATCH 09/92] Move out of legacy --- frontend/src/app/main/refs.cljs | 9 +++------ frontend/src/app/main/ui/workspace/tokens/token_set.cljs | 7 ++++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index 8f4ef4d6a..6687ef60f 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -465,13 +465,10 @@ (def workspace-token-themes (l/derived #(or (some-> % ctob/get-themes) []) tokens-lib)) -(dm/legacy - (def workspace-selected-token-set-id - (l/derived - wtts/get-selected-token-set-id - st/state - =)) +(def workspace-selected-token-set-id + (l/derived wtts/get-selected-token-set-id st/state)) +(dm/legacy (def workspace-active-theme-ids (l/derived wtts/get-active-theme-ids st/state)) diff --git a/frontend/src/app/main/ui/workspace/tokens/token_set.cljs b/frontend/src/app/main/ui/workspace/tokens/token_set.cljs index 237b778cd..c20898d74 100644 --- a/frontend/src/app/main/ui/workspace/tokens/token_set.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/token_set.cljs @@ -1,9 +1,10 @@ (ns app.main.ui.workspace.tokens.token-set (:require [app.common.data :refer [ordered-map]] + [app.common.data.macros :as dm] + [app.common.types.tokens-lib :as ctob] [app.main.ui.workspace.tokens.token :as wtt] - [clojure.set :as set] - [app.common.types.tokens-lib :as ctob])) + [clojure.set :as set])) (defn get-workspace-tokens-lib [state] (get-in state [:workspace-data :tokens-lib])) @@ -167,7 +168,7 @@ ;; === Set selection (defn get-selected-token-set-id [state] - (or (get-in state [:workspace-local :selected-token-set-id]) + (or (dm/legacy (get-in state [:workspace-local :selected-token-set-id])) (some-> (get-workspace-tokens-lib state) (ctob/get-sets) (first) From f5c122b0db2fd954402402a7ed0962f1bf781582 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Fri, 20 Sep 2024 14:42:48 +0200 Subject: [PATCH 10/92] Remove legacy --- frontend/src/app/main/refs.cljs | 3 --- frontend/src/app/main/ui/workspace/tokens/sidebar.cljs | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index 6687ef60f..1d423608d 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -478,9 +478,6 @@ (def workspace-active-set-ids (l/derived wtts/get-active-set-ids st/state)) - (def workspace-ordered-token-themes-OLD - (l/derived wtts/get-workspace-ordered-themes st/state)) - (def workspace-ordered-token-sets (l/derived (fn [data] diff --git a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs index 64ebfb449..4e44c1415 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs @@ -200,7 +200,7 @@ (mf/defc themes-sidebar [_props] - (let [ordered-themes (mf/deref refs/workspace-ordered-token-themes-OLD)] + (let [ordered-themes (mf/deref refs/workspace-token-themes)] [:div {:class (stl/css :theme-sidebar)} [:span {:class (stl/css :themes-header)} "Themes"] [:div {:class (stl/css :theme-select-wrapper)} From 4c327f38ef493e82bb94f6fed910520c6500ea51 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 23 Sep 2024 15:18:46 +0200 Subject: [PATCH 11/92] Replace sets --- frontend/src/app/main/refs.cljs | 10 +++---- .../app/main/ui/workspace/tokens/sets.cljs | 27 ++++++++++--------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index 1d423608d..6650c4828 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -468,6 +468,9 @@ (def workspace-selected-token-set-id (l/derived wtts/get-selected-token-set-id st/state)) +(def workspace-ordered-token-sets + (l/derived #(or (some-> % ctob/get-sets) []) tokens-lib)) + (dm/legacy (def workspace-active-theme-ids (l/derived wtts/get-active-theme-ids st/state)) @@ -478,13 +481,6 @@ (def workspace-active-set-ids (l/derived wtts/get-active-set-ids st/state)) - (def workspace-ordered-token-sets - (l/derived - (fn [data] - (or (wtts/get-workspace-ordered-sets data) {})) - st/state - =)) - (def workspace-active-theme-sets-tokens (l/derived wtts/get-active-theme-sets-tokens-names-map st/state =)) diff --git a/frontend/src/app/main/ui/workspace/tokens/sets.cljs b/frontend/src/app/main/ui/workspace/tokens/sets.cljs index c4f95f992..994214ed2 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sets.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sets.cljs @@ -146,20 +146,21 @@ :as _props}] (let [{:keys [editing? new? on-edit on-create on-reset] :as ctx} (or context (sets-context/use-context))] [:ul {:class (stl/css :sets-list)} - (for [[id token-set] token-sets] + (for [token-set token-sets] (when token-set - [:& sets-tree {:key id - :token-set token-set - :token-set-selected? (if new? (constantly false) token-set-selected?) - :token-set-active? token-set-active? - :editing? editing? - :on-select on-select - :on-edit on-edit - :on-toggle on-toggle-token-set - :on-submit #(do - (on-update-token-set %) - (on-reset)) - :on-cancel on-reset}])) + [:& sets-tree + {:key (:name token-set) + :token-set token-set + :token-set-selected? (if new? (constantly false) token-set-selected?) + :token-set-active? token-set-active? + :editing? editing? + :on-select on-select + :on-edit on-edit + :on-toggle on-toggle-token-set + :on-submit #(do + (on-update-token-set %) + (on-reset)) + :on-cancel on-reset}])) (when new? [:& sets-tree {:token-set {:name ""} :token-set-selected? (constantly true) From 844819a50cd0c811209b4b97cd1c0e326eafd28f Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Tue, 24 Sep 2024 15:25:29 +0200 Subject: [PATCH 12/92] Activate themes via lib --- common/src/app/common/files/changes.cljc | 7 +++++-- common/src/app/common/types/tokens_lib.cljc | 7 +++++++ frontend/src/app/main/data/tokens.cljs | 18 ++++++++++-------- frontend/src/app/main/refs.cljs | 6 +++--- .../ui/workspace/tokens/modals/themes.cljs | 9 +++++---- .../main/ui/workspace/tokens/theme_select.cljs | 11 ++++++----- 6 files changed, 36 insertions(+), 22 deletions(-) diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index 0d848f197..fca19bc28 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -258,7 +258,7 @@ [:update-active-token-themes [:map {:title "UpdateActiveTokenThemes"} [:type [:= :update-active-token-themes]] - [:theme-ids [:set ::sm/uuid]]]] + [:theme-ids [:set :string]]]] [:delete-temporary-token-theme [:map {:title "DeleteTemporaryTokenThemeChange"} @@ -846,7 +846,10 @@ (defmethod process-change :update-active-token-themes [data {:keys [theme-ids]}] - (ctotl/assoc-active-token-themes data theme-ids)) + (-> data + (update :tokens-lib #(-> % + (ctob/ensure-tokens-lib) + (ctob/set-active-themes theme-ids))))) (defmethod process-change :delete-temporary-token-theme [data {:keys [id group name]}] diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index a2e1e2ddf..5dd6e2a53 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -328,6 +328,7 @@ (get-theme-groups [_] "get a sequence of group names by order") (get-active-theme-paths [_] "get the active theme paths") (get-active-themes [_] "get an ordered sequence of active themes in the library") + (set-active-themes [_ active-themes] "set active themes in library") (theme-active? [_ group name] "predicate if token theme is active") (activate-theme [_ group name] "adds theme from the active-themes") (deactivate-theme [_ group name] "removes theme from the active-themes") @@ -489,6 +490,12 @@ (get-theme [_ group name] (dm/get-in themes [group name])) + (set-active-themes [_ active-themes] + (TokensLib. sets + set-groups + themes + active-themes)) + (activate-theme [this group name] (if-let [theme (get-theme this group name)] (let [group-themes (->> (get themes group) diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index 495c1f98c..fb0fd0ee0 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -140,17 +140,19 @@ theme)) :else changes))) -(defn toggle-token-theme [token-theme-id] - (ptk/reify ::toggle-token-theme +(defn toggle-token-theme-active? [group name] + (ptk/reify ::toggle-token-theme-active? ptk/WatchEvent (watch [it state _] - (let [themes (wtts/get-active-theme-ids state) - new-themes (wtts/toggle-active-theme-id token-theme-id state) - changes (-> (pcb/empty-changes it) - (pcb/update-active-token-themes new-themes themes))] + (let [tokens-lib (get-tokens-lib state) + prev-active-token-themes (some-> tokens-lib + (ctob/get-active-theme-paths)) + active-token-themes (some-> tokens-lib + (ctob/toggle-theme-active? group name) + (ctob/get-active-theme-paths)) + changes (pcb/update-active-token-themes (pcb/empty-changes it) active-token-themes prev-active-token-themes)] (rx/of - (dch/commit-changes changes) - (wtu/update-workspace-tokens)))))) + (dch/commit-changes changes)))))) (defn delete-token-theme [token-theme-id] (ptk/reify ::delete-token-theme diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index 6650c4828..e8b0b7b32 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -471,10 +471,10 @@ (def workspace-ordered-token-sets (l/derived #(or (some-> % ctob/get-sets) []) tokens-lib)) -(dm/legacy - (def workspace-active-theme-ids - (l/derived wtts/get-active-theme-ids st/state)) +(def workspace-active-theme-paths + (l/derived #(some-> % ctob/get-active-theme-paths) tokens-lib)) +(dm/legacy (def workspace-temp-theme-id (l/derived wtts/get-temp-theme-id st/state)) diff --git a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs index 0dc6fcb57..c992ef46c 100644 --- a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs @@ -7,6 +7,7 @@ (ns app.main.ui.workspace.tokens.modals.themes (:require-macros [app.main.style :as stl]) (:require + [app.common.types.tokens-lib :as ctob] [app.main.data.modal :as modal] [app.main.data.tokens :as wdt] [app.main.refs :as refs] @@ -55,7 +56,7 @@ (mf/defc themes-overview [{:keys [set-state]}] - (let [active-theme-ids (mf/deref refs/workspace-active-theme-ids) + (let [active-theme-ids (mf/deref refs/workspace-active-theme-paths) themes-groups (mf/deref refs/workspace-token-theme-tree) on-edit-theme (fn [theme e] (dom/prevent-default e) @@ -69,15 +70,15 @@ (when (seq group) [:span {:class (stl/css :theme-group-label)} group]) [:ul {:class (stl/css :theme-group-rows-wrapper)} - (for [[_ {:keys [id name] :as theme}] themes - :let [selected? (some? (get active-theme-ids id))]] + (for [[_ {:keys [id group name] :as theme}] themes + :let [selected? (some? (get active-theme-ids (ctob/theme-path theme)))]] [:li {:key (str "token-theme-" id) :class (stl/css :theme-row)} [:div {:class (stl/css :theme-row-left)} [:div {:on-click (fn [e] (dom/prevent-default e) (dom/stop-propagation e) - (st/emit! (wdt/toggle-token-theme id)))} + (st/emit! (wdt/toggle-token-theme-active? group name)))} [:& switch {:name (str "Theme" name) :on-change (constantly nil) :selected? selected?}]] diff --git a/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs b/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs index 09ab604d2..49b169a78 100644 --- a/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs @@ -8,6 +8,7 @@ (:require-macros [app.main.style :as stl]) (:require [app.common.data.macros :as dm] + [app.common.types.tokens-lib :as ctob] [app.common.uuid :as uuid] [app.main.data.modal :as modal] [app.main.data.tokens :as wdt] @@ -22,8 +23,8 @@ [{:keys [themes active-theme-ids on-close grouped?]}] (when (seq themes) [:ul - (for [[_ {:keys [id name]}] themes - :let [selected? (get active-theme-ids id)]] + (for [[_ {:keys [id group name] :as theme}] themes + :let [selected? (get active-theme-ids (ctob/theme-path theme))]] [:li {:key id :class (stl/css-case :checked-element true @@ -31,14 +32,14 @@ :is-selected selected?) :on-click (fn [e] (dom/stop-propagation e) - (st/emit! (wdt/toggle-token-theme id)) + (st/emit! (wdt/toggle-token-theme-active? group name)) (on-close))} [:span {:class (stl/css :label)} name] [:span {:class (stl/css :check-icon)} i/tick]])])) (mf/defc theme-options [{:keys [on-close]}] - (let [active-theme-ids (dm/fixme (mf/deref refs/workspace-active-theme-ids)) + (let [active-theme-ids (dm/fixme (mf/deref refs/workspace-active-theme-paths)) theme-groups (mf/deref refs/workspace-token-theme-tree)] [:ul (for [[group themes] theme-groups] @@ -59,7 +60,7 @@ [{:keys []}] (let [;; Store temp-theme-id (dm/legacy (mf/deref refs/workspace-temp-theme-id)) - active-theme-ids (dm/legacy (-> (mf/deref refs/workspace-active-theme-ids) + active-theme-ids (dm/legacy (-> (mf/deref refs/workspace-active-theme-paths) (disj temp-theme-id))) active-themes-count (count active-theme-ids) themes (mf/deref refs/workspace-token-theme-tree) From ec96e7918d98d57f41e039ae2df9430b1f95e558 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 25 Sep 2024 08:16:29 +0200 Subject: [PATCH 13/92] Token theme deletion --- common/src/app/common/files/changes.cljc | 5 ++--- common/src/app/common/files/changes_builder.cljc | 10 ++++++---- frontend/src/app/main/data/tokens.cljs | 4 ++-- .../app/main/ui/workspace/tokens/modals/themes.cljs | 11 ++++++----- .../app/main/ui/workspace/tokens/theme_select.cljs | 7 ++++--- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index fca19bc28..e4af8d1ed 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -281,7 +281,7 @@ [:del-token-theme [:map {:title "DelTokenThemeChange"} [:type [:= :del-token-theme]] - [:id ::sm/uuid] + [:group :string] [:name :string]]] [:add-token-set @@ -885,9 +885,8 @@ (update :sets (partial set-ids->names data)))))))))) (defmethod process-change :del-token-theme - [data {:keys [id group name]}] + [data {:keys [group name]}] (-> data - (ctotl/delete-token-theme id) (update :tokens-lib #(-> % (ctob/ensure-tokens-lib) diff --git a/common/src/app/common/files/changes_builder.cljc b/common/src/app/common/files/changes_builder.cljc index 6fd4aac22..c422adb2c 100644 --- a/common/src/app/common/files/changes_builder.cljc +++ b/common/src/app/common/files/changes_builder.cljc @@ -20,7 +20,8 @@ [app.common.types.component :as ctk] [app.common.types.file :as ctf] [app.common.types.shape.layout :as ctl] - [app.common.uuid :as uuid])) + [app.common.uuid :as uuid] + [app.common.types.tokens-lib :as ctob])) ;; Auxiliary functions to help create a set of changes (undo + redo) @@ -724,12 +725,13 @@ (apply-changes-local))) (defn delete-token-theme - [changes token-theme-id] + [changes group name] (assert-library! changes) (let [library-data (::library-data (meta changes)) - prev-token-theme (get-in library-data [:token-themes-index token-theme-id])] + prev-token-theme (some-> (get library-data :tokens-lib) + (ctob/get-theme group name))] (-> changes - (update :redo-changes conj {:type :del-token-theme :id token-theme-id :name (:name prev-token-theme)}) + (update :redo-changes conj {:type :del-token-theme :group group :name name}) (update :undo-changes conj {:type :add-token-theme :token-theme prev-token-theme}) (apply-changes-local)))) diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index fb0fd0ee0..44d913c45 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -154,14 +154,14 @@ (rx/of (dch/commit-changes changes)))))) -(defn delete-token-theme [token-theme-id] +(defn delete-token-theme [group name] (ptk/reify ::delete-token-theme ptk/WatchEvent (watch [it state _] (let [data (get state :workspace-data) changes (-> (pcb/empty-changes it) (pcb/with-library-data data) - (pcb/delete-token-theme token-theme-id))] + (pcb/delete-token-theme group name))] (rx/of (dch/commit-changes changes) (wtu/update-workspace-tokens)))))) diff --git a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs index c992ef46c..afc1d0c4f 100644 --- a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs @@ -70,9 +70,10 @@ (when (seq group) [:span {:class (stl/css :theme-group-label)} group]) [:ul {:class (stl/css :theme-group-rows-wrapper)} - (for [[_ {:keys [id group name] :as theme}] themes - :let [selected? (some? (get active-theme-ids (ctob/theme-path theme)))]] - [:li {:key (str "token-theme-" id) + (for [[_ {:keys [group name] :as theme}] themes + :let [theme-id (ctob/theme-path theme) + selected? (some? (get active-theme-ids theme-id))]] + [:li {:key theme-id :class (stl/css :theme-row)} [:div {:class (stl/css :theme-row-left)} [:div {:on-click (fn [e] @@ -97,7 +98,7 @@ [:button {:on-click (fn [e] (dom/prevent-default e) (dom/stop-propagation e) - (st/emit! (wdt/delete-token-theme id)))} + (st/emit! (wdt/delete-token-theme group name)))} i/delete]]]])]])] [:div {:class (stl/css :button-footer)} [:button {:class (stl/css :create-theme-button) @@ -195,7 +196,7 @@ [:button {:class (stl/css :button-secondary) :type "button" :on-click (fn [] - (st/emit! (wdt/delete-token-theme (:id theme))) + (st/emit! (wdt/delete-token-theme (:group theme) (:name theme))) (on-back))} "Delete"] [:div]) diff --git a/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs b/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs index 49b169a78..c8a30f678 100644 --- a/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs @@ -23,9 +23,10 @@ [{:keys [themes active-theme-ids on-close grouped?]}] (when (seq themes) [:ul - (for [[_ {:keys [id group name] :as theme}] themes - :let [selected? (get active-theme-ids (ctob/theme-path theme))]] - [:li {:key id + (for [[_ {:keys [group name] :as theme}] themes + :let [theme-id (ctob/theme-path theme) + selected? (get active-theme-ids theme-id)]] + [:li {:key theme-id :class (stl/css-case :checked-element true :sub-item grouped? From 4d4c4355ad598a40d2e0d3d3aead1ec4767371be Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 25 Sep 2024 08:33:34 +0200 Subject: [PATCH 14/92] Selection by name --- frontend/src/app/main/data/tokens.cljs | 4 ++-- frontend/src/app/main/ui/workspace/tokens/sets.cljs | 10 +++++----- .../src/app/main/ui/workspace/tokens/token_set.cljs | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index 44d913c45..dd8d89474 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -180,7 +180,7 @@ (ensure-token-theme-changes state {:id (:id new-token-set) :new-set? true}))] (rx/of - (set-selected-token-set-id (:id new-token-set)) + (set-selected-token-set-id (:name new-token-set)) (dch/commit-changes changes))))))) (defn update-token-set [token-set] @@ -251,7 +251,7 @@ (ensure-token-theme-changes state {:new-set? create-set? :id (:id token-set)}))] (rx/of - (set-selected-token-set-id (:id token-set)) + (set-selected-token-set-id (:name token-set)) (dch/commit-changes changes))))))) (defn delete-token diff --git a/frontend/src/app/main/ui/workspace/tokens/sets.cljs b/frontend/src/app/main/ui/workspace/tokens/sets.cljs index 994214ed2..fade69a90 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sets.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sets.cljs @@ -23,8 +23,8 @@ (defn on-toggle-token-set-click [token-set-id] (st/emit! (wdt/toggle-token-set {:token-set-id token-set-id}))) -(defn on-select-token-set-click [id] - (st/emit! (wdt/set-selected-token-set-id id))) +(defn on-select-token-set-click [name] + (st/emit! (wdt/set-selected-token-set-id name))) (defn on-delete-token-set-click [id name event] (dom/stop-propagation event) @@ -83,7 +83,7 @@ (fn [event] (dom/stop-propagation event) (when-not editing-node? - (on-select id)))) + (on-select name)))) on-context-menu (mf/use-callback (mf/deps editing-node? id) (fn [event] @@ -179,8 +179,8 @@ selected-token-set-id (mf/deref refs/workspace-selected-token-set-id) token-set-selected? (mf/use-callback (mf/deps selected-token-set-id) - (fn [id] - (= id selected-token-set-id))) + (fn [set-name] + (= set-name selected-token-set-id))) active-token-set-ids (mf/deref refs/workspace-active-set-ids) token-set-active? (mf/use-callback (mf/deps active-token-set-ids) diff --git a/frontend/src/app/main/ui/workspace/tokens/token_set.cljs b/frontend/src/app/main/ui/workspace/tokens/token_set.cljs index c20898d74..529c13cd5 100644 --- a/frontend/src/app/main/ui/workspace/tokens/token_set.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/token_set.cljs @@ -168,7 +168,7 @@ ;; === Set selection (defn get-selected-token-set-id [state] - (or (dm/legacy (get-in state [:workspace-local :selected-token-set-id])) + (or (get-in state [:workspace-local :selected-token-set-id]) (some-> (get-workspace-tokens-lib state) (ctob/get-sets) (first) From 99e551925aa6cc3d12c8fcce9cc7a6564dabbb6b Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 25 Sep 2024 11:08:54 +0200 Subject: [PATCH 15/92] Updates --- common/src/app/common/types/tokens_lib.cljc | 17 ++++++++++++++ .../common_tests/types/tokens_lib_test.cljc | 13 +++++++++++ frontend/src/app/main/refs.cljs | 13 ++++++----- .../app/main/ui/workspace/tokens/sets.cljs | 23 ++++++++++--------- 4 files changed, 49 insertions(+), 17 deletions(-) diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index 5dd6e2a53..927f7ee8c 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -363,6 +363,8 @@ (update-token-in-set [_ set-name token-name f] "update a token in a set") (delete-token-from-set [_ set-name token-name] "delete a token from a set") (toggle-set-in-theme [_ group-name theme-name set-name] "toggle a set used / not used in a theme") + (get-active-themes-set-names [_] "set of set names that are active in the the active themes") + (get-active-themes-set-tokens [_] "set of set names that are active in the the active themes") (validate [_])) (deftype TokensLib [sets set-groups themes active-themes] @@ -571,6 +573,21 @@ active-themes) this)) + (get-active-themes-set-names [this] + (into #{} + (mapcat :sets) + (get-active-themes this))) + + (get-active-themes-set-tokens [this] + (mapcat (fn [x] + (->> (get x :sets) + (map (fn [y] + (-> + (get-set this y) + :tokens))))) + (get-active-themes this))) + + (validate [_] (and (valid-token-sets? sets) ;; TODO: validate set-groups (valid-token-themes? themes) diff --git a/common/test/common_tests/types/tokens_lib_test.cljc b/common/test/common_tests/types/tokens_lib_test.cljc index 377372a84..8c4d9f469 100644 --- a/common/test/common_tests/types/tokens_lib_test.cljc +++ b/common/test/common_tests/types/tokens_lib_test.cljc @@ -182,6 +182,19 @@ (t/is (dt/is-after? (:modified-at token-set') (:modified-at token-set))))) (t/deftest delete-token-set + (let [tokens-lib (-> (ctob/make-tokens-lib) + (ctob/add-set (ctob/make-token-set :name "test-token-set"))) + + tokens-lib' (-> tokens-lib + (ctob/delete-set "test-token-set") + (ctob/delete-set "not-existing-set")) + + token-set' (ctob/get-set tokens-lib' "updated-name")] + + (t/is (= (ctob/set-count tokens-lib') 0)) + (t/is (nil? token-set')))) + + (t/deftest active-themes-set-names (let [tokens-lib (-> (ctob/make-tokens-lib) (ctob/add-set (ctob/make-token-set :name "test-token-set"))) diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index e8b0b7b32..2e460ffb0 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -474,16 +474,17 @@ (def workspace-active-theme-paths (l/derived #(some-> % ctob/get-active-theme-paths) tokens-lib)) +(def workspace-active-set-names + (l/derived #(some-> % ctob/get-active-themes-set-names) tokens-lib)) + +(def workspace-active-theme-sets-tokens + #_(l/derived wtts/get-active-theme-sets-tokens-names-map st/state =) + (l/derived #(some-> % ctob/get-active-themes-set-tokens) tokens-lib)) + (dm/legacy (def workspace-temp-theme-id (l/derived wtts/get-temp-theme-id st/state)) - (def workspace-active-set-ids - (l/derived wtts/get-active-set-ids st/state)) - - (def workspace-active-theme-sets-tokens - (l/derived wtts/get-active-theme-sets-tokens-names-map st/state =)) - (def workspace-ordered-token-sets-tokens (l/derived wtts/get-workspace-ordered-sets-tokens st/state =)) diff --git a/frontend/src/app/main/ui/workspace/tokens/sets.cljs b/frontend/src/app/main/ui/workspace/tokens/sets.cljs index fade69a90..48beaa723 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sets.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sets.cljs @@ -7,6 +7,7 @@ (ns app.main.ui.workspace.tokens.sets (:require-macros [app.main.style :as stl]) (:require + [app.common.data.macros :as dm] [app.main.data.tokens :as wdt] [app.main.refs :as refs] [app.main.store :as st] @@ -26,9 +27,9 @@ (defn on-select-token-set-click [name] (st/emit! (wdt/set-selected-token-set-id name))) -(defn on-delete-token-set-click [id name event] +(defn on-delete-token-set-click [name event] (dom/stop-propagation event) - (st/emit! (wdt/delete-token-set id name))) + (st/emit! (wdt/delete-token-set (dm/legacy nil) name))) (defn on-update-token-set [token-set] (st/emit! (wdt/update-token-set token-set))) @@ -71,13 +72,13 @@ on-submit on-cancel] :as _props}] - (let [{:keys [id name _children]} token-set + (let [{:keys [name _children]} token-set selected? (and set? (token-set-selected? name)) - visible? (token-set-active? id) + visible? (token-set-active? name) collapsed? (mf/use-state false) set? true #_(= type :set) group? false #_(= type :group) - editing-node? (editing? id) + editing-node? (editing? name) on-select (mf/use-callback (mf/deps editing-node?) (fn [event] @@ -85,7 +86,7 @@ (when-not editing-node? (on-select name)))) on-context-menu (mf/use-callback - (mf/deps editing-node? id) + (mf/deps editing-node? name) (fn [event] (dom/prevent-default event) (dom/stop-propagation event) @@ -93,11 +94,11 @@ (st/emit! (wdt/show-token-set-context-menu {:position (dom/get-client-position event) - :token-set-id id + :token-set-id name :token-set-name name})))))] [:div {:class (stl/css :set-item-container) :on-click on-select - :on-double-click #(on-edit id) + :on-double-click #(on-edit name) :on-context-menu on-context-menu} [:div {:class (stl/css-case :set-item-group group? :set-item-set set? @@ -116,14 +117,14 @@ [:* [:div {:class (stl/css :set-name)} name] [:div {:class (stl/css :delete-set)} - [:button {:on-click #(on-delete-token-set-click id name %) + [:button {:on-click #(on-delete-token-set-click name %) :type "button"} i/delete]] (if set? [:span {:class (stl/css :action-btn) :on-click (fn [event] (dom/stop-propagation event) - (on-toggle id))} + (on-toggle name))} (if visible? i/shown i/hide)] nil #_(when (and children (not @collapsed?)) @@ -181,7 +182,7 @@ (mf/deps selected-token-set-id) (fn [set-name] (= set-name selected-token-set-id))) - active-token-set-ids (mf/deref refs/workspace-active-set-ids) + active-token-set-ids (mf/deref refs/workspace-active-set-names) token-set-active? (mf/use-callback (mf/deps active-token-set-ids) (fn [id] From d2ed6b550139c0f6108cabd9ec0f141a64f663bc Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 25 Sep 2024 14:45:31 +0200 Subject: [PATCH 16/92] Add set --- common/src/app/common/files/changes.cljc | 24 +++++++----------------- common/src/app/common/types/file.cljc | 16 ---------------- frontend/src/app/main/data/tokens.cljs | 7 +++---- 3 files changed, 10 insertions(+), 37 deletions(-) diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index e4af8d1ed..27940f6be 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -793,18 +793,16 @@ ;; -- Tokens (defmethod process-change :add-token - [data {:keys [set-id set-name token]}] + [data {:keys [set-name token]}] (-> data - (ctol/add-token set-id token) (update :tokens-lib #(-> % (ctob/ensure-tokens-lib) (ctob/add-token-in-set set-name (ctob/make-token token)))))) (defmethod process-change :mod-token - [data {:keys [set-name id name token]}] + [data {:keys [set-name name token]}] (-> data - (ctol/update-token id merge token) (update :tokens-lib #(-> % (ctob/ensure-tokens-lib) @@ -815,9 +813,8 @@ (ctob/make-token (merge old-token token)))))))) (defmethod process-change :del-token - [data {:keys [set-name id name]}] + [data {:keys [set-name name]}] (-> data - (ctol/delete-token id) (update :tokens-lib #(-> % (ctob/ensure-tokens-lib) @@ -836,7 +833,6 @@ (defmethod process-change :add-temporary-token-theme [data {:keys [token-theme]}] (-> data - (ctotl/add-temporary-token-theme token-theme) (update :tokens-lib #(-> % (ctob/ensure-tokens-lib) @@ -852,9 +848,8 @@ (ctob/set-active-themes theme-ids))))) (defmethod process-change :delete-temporary-token-theme - [data {:keys [id group name]}] + [data {:keys [group name]}] (-> data - (ctotl/delete-temporary-token-theme id) (update :tokens-lib #(-> % (ctob/ensure-tokens-lib) @@ -871,10 +866,8 @@ (ctob/make-token-theme))))))) (defmethod process-change :mod-token-theme - [data {:keys [id name group token-theme]}] + [data {:keys [name group token-theme]}] (-> data - (dm/legacy (#(when id - (ctotl/update-token-theme % (random-uuid) merge token-theme)))) (update :tokens-lib #(-> % (ctob/ensure-tokens-lib) @@ -895,16 +888,14 @@ (defmethod process-change :add-token-set [data {:keys [token-set]}] (-> data - (ctotl/add-token-set token-set) (update :tokens-lib #(-> % (ctob/ensure-tokens-lib) (ctob/add-set (ctob/make-token-set token-set)))))) (defmethod process-change :mod-token-set - [data {:keys [id name token-set]}] + [data {:keys [name token-set]}] (-> data - (ctotl/update-token-set id merge token-set) (update :tokens-lib #(-> % (ctob/ensure-tokens-lib) @@ -913,9 +904,8 @@ (dissoc token-set :tokens)))))))) (defmethod process-change :del-token-set - [data {:keys [id name]}] + [data {:keys [name]}] (-> data - (ctotl/delete-token-set id) (update :tokens-lib #(-> % (ctob/ensure-tokens-lib) diff --git a/common/src/app/common/types/file.cljc b/common/src/app/common/types/file.cljc index dcf9900f8..69e57a259 100644 --- a/common/src/app/common/types/file.cljc +++ b/common/src/app/common/types/file.cljc @@ -64,22 +64,6 @@ [:map-of {:gen/max 5} ::sm/uuid ::media-object]] [:plugin-data {:optional true} [:map-of {:gen/max 5} :keyword ::ctpg/plugin-data]] - [:token-theme-temporary-id {:optional true} - ::sm/uuid] - [:token-active-themes {:optional true :default #{}} - [:set ::sm/uuid]] - [:token-themes {:optional true} - [:vector ::sm/uuid]] - [:token-themes-index {:optional true} - [:map-of {:gen/max 5} ::sm/uuid ::ctt/token-theme]] - [:token-set-groups {:optional true} - [:vector ::sm/uuid]] - [:token-set-groups-index {:optional true} - [:map-of {:gen/max 10} ::sm/uuid ::ctt/token-set-group]] - [:token-sets-index {:optional true} - [:map-of {:gen/max 10} ::sm/uuid ::ctt/token-set]] - [:tokens {:optional true} - [:map-of {:gen/max 100} ::sm/uuid ::cto/token]] [:tokens-lib {:optional true} ::ctl/tokens-lib]]) (def check-file-data! diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index dd8d89474..12ccff1c3 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -168,8 +168,7 @@ (defn create-token-set [token-set] (let [new-token-set (merge - {:id (uuid/next) - :name "Token Set" + {:name "Token Set" :tokens []} token-set)] (ptk/reify ::create-token-set @@ -177,8 +176,8 @@ (watch [it state _] (let [changes (-> (pcb/empty-changes it) (pcb/add-token-set new-token-set) - (ensure-token-theme-changes state {:id (:id new-token-set) - :new-set? true}))] + #_(ensure-token-theme-changes state {:id (:id new-token-set) + :new-set? true}))] (rx/of (set-selected-token-set-id (:name new-token-set)) (dch/commit-changes changes))))))) From 9c1a509fa4f37b38376fefe71aa88e0ab4beaab9 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 25 Sep 2024 14:59:20 +0200 Subject: [PATCH 17/92] Set renaming --- common/src/app/common/files/changes.cljc | 1 - .../src/app/common/files/changes_builder.cljc | 4 ++-- common/src/app/common/types/token_theme.cljc | 22 ++----------------- frontend/src/app/main/data/tokens.cljs | 5 +++-- .../app/main/ui/workspace/tokens/sets.cljs | 6 ++--- 5 files changed, 10 insertions(+), 28 deletions(-) diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index 27940f6be..5bbe20b11 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -292,7 +292,6 @@ [:mod-token-set [:map {:title "ModTokenSetChange"} [:type [:= :mod-token-set]] - [:id ::sm/uuid] [:name :string] [:token-set ::ctot/token-set]]] diff --git a/common/src/app/common/files/changes_builder.cljc b/common/src/app/common/files/changes_builder.cljc index c422adb2c..df67b78e4 100644 --- a/common/src/app/common/files/changes_builder.cljc +++ b/common/src/app/common/files/changes_builder.cljc @@ -745,8 +745,8 @@ (defn update-token-set [changes token-set prev-token-set] (-> changes - (update :redo-changes conj {:type :mod-token-set :id (:id token-set) :name (:name prev-token-set) :token-set token-set}) - (update :undo-changes conj {:type :mod-token-set :id (:id token-set) :name (:name prev-token-set) :token-set (or prev-token-set token-set)}) + (update :redo-changes conj {:type :mod-token-set :name (:name prev-token-set) :token-set token-set}) + (update :undo-changes conj {:type :mod-token-set :name (:name prev-token-set) :token-set (or prev-token-set token-set)}) (apply-changes-local))) (defn delete-token-set diff --git a/common/src/app/common/types/token_theme.cljc b/common/src/app/common/types/token_theme.cljc index 59d1bdc03..e370fb389 100644 --- a/common/src/app/common/types/token_theme.cljc +++ b/common/src/app/common/types/token_theme.cljc @@ -19,27 +19,9 @@ [:modified-at {:optional true} ::sm/inst] [:sets [:set {:gen/max 10 :gen/min 1} ::sm/uuid]]]) -(sm/register! ::token-set-group-ref - [:map - [:id ::sm/uuid] - [:type [:= :group]]]) - -(sm/register! ::token-set-ref - [:map - [:id ::sm/uuid] - [:type [:= :set]]]) - -(sm/register! ::token-set-group - [:map {:title "TokenSetGroup"} - [:id ::sm/uuid] - [:name :string] - [:items [:vector {:gen/max 10 :gen/min 1} - [:or ::token-set-group-ref ::token-set-ref]]]]) - (sm/register! ::token-set [:map {:title "TokenSet"} - [:id ::sm/uuid] [:name :string] - [:description {:optional true} :string] + [:description {:optional true} [:maybe :string]] [:modified-at {:optional true} ::sm/inst] - [:tokens [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]]]) + [:tokens :any]]) diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index 12ccff1c3..f9e44ed75 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -182,11 +182,12 @@ (set-selected-token-set-id (:name new-token-set)) (dch/commit-changes changes))))))) -(defn update-token-set [token-set] +(defn update-token-set [set-name token-set] (ptk/reify ::update-token-set ptk/WatchEvent (watch [it state _] - (let [prev-token-set (wtts/get-token-set (:id token-set) state) + (let [prev-token-set (some-> (get-tokens-lib state) + (ctob/get-set set-name)) changes (-> (pcb/empty-changes it) (pcb/update-token-set token-set prev-token-set))] (rx/of diff --git a/frontend/src/app/main/ui/workspace/tokens/sets.cljs b/frontend/src/app/main/ui/workspace/tokens/sets.cljs index 48beaa723..447ba9f50 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sets.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sets.cljs @@ -31,8 +31,8 @@ (dom/stop-propagation event) (st/emit! (wdt/delete-token-set (dm/legacy nil) name))) -(defn on-update-token-set [token-set] - (st/emit! (wdt/update-token-set token-set))) +(defn on-update-token-set [set-name token-set] + (st/emit! (wdt/update-token-set set-name token-set))) (defn on-create-token-set [token-set] (st/emit! (wdt/create-token-set token-set))) @@ -159,7 +159,7 @@ :on-edit on-edit :on-toggle on-toggle-token-set :on-submit #(do - (on-update-token-set %) + (on-update-token-set (:name token-set) %) (on-reset)) :on-cancel on-reset}])) (when new? From 0b2b8a71fb32595aafb1f300586e70151e21dc13 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 25 Sep 2024 15:08:52 +0200 Subject: [PATCH 18/92] Token deletion --- common/src/app/common/files/changes.cljc | 1 - common/src/app/common/files/changes_builder.cljc | 13 +++++++------ frontend/src/app/main/data/tokens.cljs | 4 ++-- frontend/src/app/main/ui/workspace/tokens/sets.cljs | 3 +-- .../main/ui/workspace/tokens/sets_context_menu.cljs | 2 +- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index 5bbe20b11..f7338da58 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -298,7 +298,6 @@ [:del-token-set [:map {:title "DelTokenSetChange"} [:type [:= :del-token-set]] - [:id ::sm/uuid] [:name :string]]] [:add-token diff --git a/common/src/app/common/files/changes_builder.cljc b/common/src/app/common/files/changes_builder.cljc index df67b78e4..c83cfa3d7 100644 --- a/common/src/app/common/files/changes_builder.cljc +++ b/common/src/app/common/files/changes_builder.cljc @@ -739,24 +739,25 @@ [changes token-set] (-> changes (update :redo-changes conj {:type :add-token-set :token-set token-set}) - (update :undo-changes conj {:type :del-token-set :id (:id token-set) :name (:name token-set)}) + (update :undo-changes conj {:type :del-token-set :name (:name token-set)}) (apply-changes-local))) (defn update-token-set [changes token-set prev-token-set] (-> changes (update :redo-changes conj {:type :mod-token-set :name (:name prev-token-set) :token-set token-set}) - (update :undo-changes conj {:type :mod-token-set :name (:name prev-token-set) :token-set (or prev-token-set token-set)}) + (update :undo-changes conj {:type :mod-token-set :name (:name token-set) :token-set (or prev-token-set token-set)}) (apply-changes-local))) (defn delete-token-set - [changes token-set-id token-set-name] + [changes token-set-name] (assert-library! changes) (let [library-data (::library-data (meta changes)) - prev-token-set (get-in library-data [:token-sets-index token-set-id])] + prev-token-theme (some-> (get library-data :tokens-lib) + (ctob/get-set token-set-name))] (-> changes - (update :redo-changes conj {:type :del-token-set :id token-set-id :name token-set-name}) - (update :undo-changes conj {:type :add-token-set :token-set prev-token-set}) + (update :redo-changes conj {:type :del-token-set :name token-set-name}) + (update :undo-changes conj {:type :add-token-set :token-set prev-token-theme}) (apply-changes-local)))) (defn add-token diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index f9e44ed75..a0c5d4c4d 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -210,14 +210,14 @@ (dch/commit-changes changes) (wtu/update-workspace-tokens)))))) -(defn delete-token-set [token-set-id token-set-name] +(defn delete-token-set [token-set-name] (ptk/reify ::delete-token-set ptk/WatchEvent (watch [it state _] (let [data (get state :workspace-data) changes (-> (pcb/empty-changes it) (pcb/with-library-data data) - (pcb/delete-token-set token-set-id token-set-name))] + (pcb/delete-token-set token-set-name))] (rx/of (dch/commit-changes changes) (wtu/update-workspace-tokens)))))) diff --git a/frontend/src/app/main/ui/workspace/tokens/sets.cljs b/frontend/src/app/main/ui/workspace/tokens/sets.cljs index 447ba9f50..30dfa740c 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sets.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sets.cljs @@ -7,7 +7,6 @@ (ns app.main.ui.workspace.tokens.sets (:require-macros [app.main.style :as stl]) (:require - [app.common.data.macros :as dm] [app.main.data.tokens :as wdt] [app.main.refs :as refs] [app.main.store :as st] @@ -29,7 +28,7 @@ (defn on-delete-token-set-click [name event] (dom/stop-propagation event) - (st/emit! (wdt/delete-token-set (dm/legacy nil) name))) + (st/emit! (wdt/delete-token-set name))) (defn on-update-token-set [set-name token-set] (st/emit! (wdt/update-token-set set-name token-set))) diff --git a/frontend/src/app/main/ui/workspace/tokens/sets_context_menu.cljs b/frontend/src/app/main/ui/workspace/tokens/sets_context_menu.cljs index 922f44858..4873702c8 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sets_context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sets_context_menu.cljs @@ -32,7 +32,7 @@ (let [{:keys [on-edit]} (sets-context/use-context)] [:ul {:class (stl/css :context-list)} [:& menu-entry {:title "Rename" :on-click #(on-edit token-set-id)}] - [:& menu-entry {:title "Delete" :on-click #(st/emit! (wdt/delete-token-set token-set-id token-set-name))}]])) + [:& menu-entry {:title "Delete" :on-click #(st/emit! (wdt/delete-token-set token-set-name))}]])) (mf/defc sets-context-menu [] From e216d84484b15b38955c7ed5a62028ecb35018ad Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 26 Sep 2024 11:28:14 +0200 Subject: [PATCH 19/92] Set toggling without a theme --- common/src/app/common/files/changes.cljc | 21 ++------- .../src/app/common/files/changes_builder.cljc | 12 +++-- common/src/app/common/types/token_theme.cljc | 10 ++-- frontend/src/app/main/data/tokens.cljs | 47 +++++++++++++++---- .../app/main/ui/workspace/tokens/sets.cljs | 4 +- 5 files changed, 55 insertions(+), 39 deletions(-) diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index f7338da58..eb65fd669 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -274,7 +274,7 @@ [:mod-token-theme [:map {:title "ModTokenThemeChange"} [:type [:= :mod-token-theme]] - (dm/legacy [:id {:optional true} [:maybe ::sm/uuid]]) + [:group :string] [:name :string] [:token-theme ::ctot/token-theme]]] @@ -820,23 +820,13 @@ set-name name))))) -(defn- set-ids->names - [data sets] - (let [lib-sets (:token-sets-index data) - set-id->name - (fn [set-id] - (dm/get-in lib-sets [set-id :name]))] - (map set-id->name sets))) - (defmethod process-change :add-temporary-token-theme [data {:keys [token-theme]}] (-> data (update :tokens-lib #(-> % (ctob/ensure-tokens-lib) - (ctob/add-theme (-> token-theme - (update :sets (partial set-ids->names data)) - (ctob/make-token-theme))))))) + (ctob/add-theme (ctob/make-token-theme token-theme)))))) (defmethod process-change :update-active-token-themes [data {:keys [theme-ids]}] @@ -860,7 +850,6 @@ #(-> % (ctob/ensure-tokens-lib) (ctob/add-theme (-> token-theme - (update :sets (partial set-ids->names data)) (ctob/make-token-theme))))))) (defmethod process-change :mod-token-theme @@ -869,11 +858,9 @@ (update :tokens-lib #(-> % (ctob/ensure-tokens-lib) - (ctob/update-theme name group + (ctob/update-theme group name (fn [prev-theme] - (merge prev-theme - (-> token-theme - (update :sets (partial set-ids->names data)))))))))) + (merge prev-theme token-theme))))))) (defmethod process-change :del-token-theme [data {:keys [group name]}] diff --git a/common/src/app/common/files/changes_builder.cljc b/common/src/app/common/files/changes_builder.cljc index c83cfa3d7..3d4e1b4ea 100644 --- a/common/src/app/common/files/changes_builder.cljc +++ b/common/src/app/common/files/changes_builder.cljc @@ -719,10 +719,14 @@ (defn update-token-theme [changes token-theme prev-token-theme] - (-> changes - (update :redo-changes conj {:type :mod-token-theme :name (:name prev-token-theme) :token-theme token-theme}) - (update :undo-changes conj {:type :mod-token-theme :name (:name token-theme) :token-theme (or prev-token-theme token-theme)}) - (apply-changes-local))) + (let [name (or (:name prev-token-theme) + (:name token-theme)) + group (or (:group prev-token-theme) + (:group token-theme))] + (-> changes + (update :redo-changes conj {:type :mod-token-theme :group group :name name :token-theme token-theme}) + (update :undo-changes conj {:type :mod-token-theme :group group :name name :token-theme (or prev-token-theme token-theme)}) + (apply-changes-local)))) (defn delete-token-theme [changes group name] diff --git a/common/src/app/common/types/token_theme.cljc b/common/src/app/common/types/token_theme.cljc index e370fb389..ed7388995 100644 --- a/common/src/app/common/types/token_theme.cljc +++ b/common/src/app/common/types/token_theme.cljc @@ -6,18 +6,16 @@ (ns app.common.types.token-theme (:require - [app.common.data.macros :as dm] [app.common.schema :as sm])) (sm/register! ::token-theme [:map {:title "TokenTheme"} - (dm/legacy [:id {:optional true} [:maybe ::sm/uuid]]) [:name :string] - [:group {:optional true} :string] - [:source? {:optional true} :boolean] - [:description {:optional true} :string] + [:group :string] + [:description [:maybe :string]] + [:is-source :boolean] [:modified-at {:optional true} ::sm/inst] - [:sets [:set {:gen/max 10 :gen/min 1} ::sm/uuid]]]) + [:sets :any]]) (sm/register! ::token-set [:map {:title "TokenSet"} diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index a0c5d4c4d..10c9f33d2 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -48,6 +48,12 @@ (defn get-tokens-lib [state] (get-in state [:workspace-data :tokens-lib])) +(def hidden-token-theme-group + "") + +(def hidden-token-theme-name + "__PENPOT__HIDDEN__TOKEN__SET__") + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; TOKENS Actions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -193,21 +199,42 @@ (rx/of (dch/commit-changes changes)))))) -(defn toggle-token-set [{:keys [token-set-id]}] +#_[target-theme-id (wtts/get-temp-theme-id state) + active-set-ids (wtts/get-active-set-ids state) + theme (-> (wtts/get-workspace-token-theme target-theme-id state) + (assoc :sets active-set-ids)) + changes (-> (pcb/empty-changes it) + (pcb/update-token-theme + (wtts/toggle-token-set-to-token-theme token-set-id theme) + theme) + (pcb/update-active-token-themes #{target-theme-id} (wtts/get-active-theme-ids state)))] + +(comment + (-> (ctob/make-token-theme + :group "" + :name "bar") + (ctob/toggle-set "foo")) + nil) + + +(defn toggle-token-set [{:keys [token-set-name]}] (ptk/reify ::toggle-token-set ptk/WatchEvent (watch [it state _] - (let [target-theme-id (wtts/get-temp-theme-id state) - active-set-ids (wtts/get-active-set-ids state) - theme (-> (wtts/get-workspace-token-theme target-theme-id state) - (assoc :sets active-set-ids)) + (let [tokens-lib (get-tokens-lib state) + prev-theme (ctob/get-theme tokens-lib hidden-token-theme-group hidden-token-theme-name) + theme (-> (or prev-theme (ctob/make-token-theme + :group hidden-token-theme-group + :name hidden-token-theme-name)) + (ctob/toggle-set token-set-name)) + prev-active-token-themes (ctob/get-active-theme-paths tokens-lib) changes (-> (pcb/empty-changes it) - (pcb/update-token-theme - (wtts/toggle-token-set-to-token-theme token-set-id theme) - theme) - (pcb/update-active-token-themes #{target-theme-id} (wtts/get-active-theme-ids state)))] + (pcb/update-active-token-themes #{(ctob/token-theme-path hidden-token-theme-group hidden-token-theme-name)} prev-active-token-themes)) + changes' (if prev-theme + (pcb/update-token-theme changes theme prev-theme) + (pcb/add-token-theme changes theme))] (rx/of - (dch/commit-changes changes) + (dch/commit-changes changes') (wtu/update-workspace-tokens)))))) (defn delete-token-set [token-set-name] diff --git a/frontend/src/app/main/ui/workspace/tokens/sets.cljs b/frontend/src/app/main/ui/workspace/tokens/sets.cljs index 30dfa740c..cbbf97ef6 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sets.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sets.cljs @@ -20,8 +20,8 @@ (def ^:private chevron-icon (i/icon-xref :arrow (stl/css :chevron-icon))) -(defn on-toggle-token-set-click [token-set-id] - (st/emit! (wdt/toggle-token-set {:token-set-id token-set-id}))) +(defn on-toggle-token-set-click [token-set-name] + (st/emit! (wdt/toggle-token-set {:token-set-name token-set-name}))) (defn on-select-token-set-click [name] (st/emit! (wdt/set-selected-token-set-id name))) From 895f92e7c215e9004f435020e837cc357835780d Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 26 Sep 2024 12:03:03 +0200 Subject: [PATCH 20/92] Hide temporary token theme from user --- common/src/app/common/types/tokens_lib.cljc | 21 +++++++++++++++++-- frontend/src/app/main/data/tokens.cljs | 14 ++++--------- frontend/src/app/main/refs.cljs | 3 +++ .../ui/workspace/tokens/modals/themes.cljs | 2 +- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index 927f7ee8c..6dd036778 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -16,6 +16,14 @@ [cuerdas.core :as str] #?(:clj [app.common.fressian :as fres]))) +;; === Constants + +(def hidden-token-theme-group + "") + +(def hidden-token-theme-name + "__PENPOT__HIDDEN__TOKEN__THEME__") + ;; === Groups handling (def schema:groupable-item @@ -257,7 +265,9 @@ (defprotocol ITokenTheme (toggle-set [_ set-name] "togle a set used / not used in the theme") - (theme-path [_] "get `token-theme-path` from theme")) + (theme-path [_] "get `token-theme-path` from theme") + (theme-matches-group-name [_ group name] "if a theme matches the given group & name") + (hidden-temporary-theme? [_] "if a theme is the (from the user ui) hidden temporary theme")) (defrecord TokenTheme [name group description is-source modified-at sets] ITokenTheme @@ -271,7 +281,14 @@ (disj sets set-name) (conj sets set-name)))) (theme-path [_] - (token-theme-path group name))) + (token-theme-path group name)) + + (theme-matches-group-name [this group name] + (and (= (:group this) group) + (= (:name this) name))) + + (hidden-temporary-theme? [this] + (theme-matches-group-name this hidden-token-theme-group hidden-token-theme-name))) (def schema:token-theme [:and [:map {:title "TokenTheme"} diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index 10c9f33d2..6a33024a2 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -48,12 +48,6 @@ (defn get-tokens-lib [state] (get-in state [:workspace-data :tokens-lib])) -(def hidden-token-theme-group - "") - -(def hidden-token-theme-name - "__PENPOT__HIDDEN__TOKEN__SET__") - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; TOKENS Actions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -222,14 +216,14 @@ ptk/WatchEvent (watch [it state _] (let [tokens-lib (get-tokens-lib state) - prev-theme (ctob/get-theme tokens-lib hidden-token-theme-group hidden-token-theme-name) + prev-theme (ctob/get-theme tokens-lib ctob/hidden-token-theme-group ctob/hidden-token-theme-name) theme (-> (or prev-theme (ctob/make-token-theme - :group hidden-token-theme-group - :name hidden-token-theme-name)) + :group ctob/hidden-token-theme-group + :name ctob/hidden-token-theme-name)) (ctob/toggle-set token-set-name)) prev-active-token-themes (ctob/get-active-theme-paths tokens-lib) changes (-> (pcb/empty-changes it) - (pcb/update-active-token-themes #{(ctob/token-theme-path hidden-token-theme-group hidden-token-theme-name)} prev-active-token-themes)) + (pcb/update-active-token-themes #{(ctob/token-theme-path ctob/hidden-token-theme-group ctob/hidden-token-theme-name)} prev-active-token-themes)) changes' (if prev-theme (pcb/update-token-theme changes theme prev-theme) (pcb/add-token-theme changes theme))] diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index 2e460ffb0..1bf96a760 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -465,6 +465,9 @@ (def workspace-token-themes (l/derived #(or (some-> % ctob/get-themes) []) tokens-lib)) +(def workspace-token-themes-no-hidden + (l/derived #(remove ctob/hidden-temporary-theme? %) workspace-token-themes)) + (def workspace-selected-token-set-id (l/derived wtts/get-selected-token-set-id st/state)) diff --git a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs index afc1d0c4f..24bd15bf0 100644 --- a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs @@ -241,7 +241,7 @@ (mf/defc themes [_] - (let [themes (mf/deref refs/workspace-token-themes) + (let [themes (mf/deref refs/workspace-token-themes-no-hidden) state (mf/use-state (if (empty? themes) {:type :create-theme} {:type :themes-overview})) From 9c97b31d286d702976282b4d00117274b645c328 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 26 Sep 2024 13:21:53 +0200 Subject: [PATCH 21/92] Fix theme creation/editing --- .../src/app/common/files/changes_builder.cljc | 2 +- .../ui/workspace/tokens/modals/themes.cljs | 50 ++++++++----------- 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/common/src/app/common/files/changes_builder.cljc b/common/src/app/common/files/changes_builder.cljc index 3d4e1b4ea..4bc2f967f 100644 --- a/common/src/app/common/files/changes_builder.cljc +++ b/common/src/app/common/files/changes_builder.cljc @@ -714,7 +714,7 @@ [changes token-theme] (-> changes (update :redo-changes conj {:type :add-token-theme :token-theme token-theme}) - ;; (legacy (update :undo-changes conj {:type :del-token-theme :name (:name token-theme)})) + (update :undo-changes conj {:type :del-token-theme :group (:group token-theme) :name (:name token-theme)}) (apply-changes-local))) (defn update-token-theme diff --git a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs index 24bd15bf0..674450fe2 100644 --- a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs @@ -112,41 +112,33 @@ (mf/defc edit-theme [{:keys [edit? token-sets theme theme-groups on-back on-submit]}] (let [{:keys [dropdown-open? on-open-dropdown on-close-dropdown on-toggle-dropdown]} (wtco/use-dropdown-open-state) - theme-state (mf/use-state {:token-sets token-sets - :theme theme}) - disabled? (-> (get-in @theme-state [:theme :name]) + theme-state (mf/use-state theme) + disabled? (-> (:name @theme-state) (str/trim) (str/empty?)) token-set-active? (mf/use-callback (mf/deps theme-state) - (fn [id] - (get-in @theme-state [:theme :sets id]))) + (fn [set-name] + (get-in @theme-state [:sets set-name]))) on-toggle-token-set (mf/use-callback (mf/deps theme-state) - (fn [token-set-id] - (swap! theme-state (fn [st] - (update st :theme #(wtts/toggle-token-set-to-token-theme token-set-id %)))))) + (fn [set-name] + (swap! theme-state #(ctob/toggle-set % set-name)))) on-change-field (fn [field] (fn [e] - (swap! theme-state (fn [st] (assoc-in st field (dom/get-target-val e)))))) + (swap! theme-state #(assoc % field (dom/get-target-val e))))) group-input-ref (mf/use-ref) - on-update-group (on-change-field [:theme :group]) - on-update-name (on-change-field [:theme :name]) + on-update-group (on-change-field :group) + on-update-name (on-change-field :name) on-save-form (mf/use-callback (mf/deps theme-state on-submit) (fn [e] (dom/prevent-default e) - (let [theme (:theme @theme-state) - final-name (-> (:name theme) - (str/trim)) - empty-description? (-> (:description theme) - (str/trim) - (str/empty?))] - (when-not (str/empty? final-name) - (cond-> theme - empty-description? (assoc :description "") - :always (doto js/console.log) - :always on-submit))) + (let [theme (-> @theme-state + (update :name str/trim) + (update :description str/trim))] + (when-not (str/empty? (:name theme)) + (on-submit theme))) (on-back)))] [:form {:on-submit on-save-form} [:div {:class (stl/css :edit-theme-wrapper)} @@ -174,12 +166,12 @@ :on-change on-update-group} :render-right (when (seq theme-groups) (mf/fnc [] - [:button {:class (stl/css :group-drop-down-button) - :type "button" - :on-click (fn [e] - (dom/stop-propagation e) - (on-toggle-dropdown))} - i/arrow]))}]] + [:button {:class (stl/css :group-drop-down-button) + :type "button" + :on-click (fn [e] + (dom/stop-propagation e) + (on-toggle-dropdown))} + i/arrow]))}]] [:& labeled-input {:label "Theme" :input-props {:default-value (:name theme) :on-change on-update-name}}]] @@ -229,7 +221,7 @@ (mf/defc create-theme [{:keys [set-state]}] (let [token-sets (mf/deref refs/workspace-ordered-token-sets) - theme {:name "" :sets #{}} + theme (ctob/make-token-theme :name "") theme-groups (mf/deref refs/workspace-token-theme-groups)] [:& edit-theme {:edit? false From 2104fc04df5ce9a73d66a793511e420ac79a1194 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 26 Sep 2024 14:28:27 +0200 Subject: [PATCH 22/92] Fix theme select --- common/src/app/common/types/tokens_lib.cljc | 20 ++++--- frontend/src/app/main/refs.cljs | 12 +++++ .../ui/workspace/tokens/theme_select.cljs | 54 +++++++++---------- 3 files changed, 51 insertions(+), 35 deletions(-) diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index 6dd036778..60b7b79f3 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -16,14 +16,6 @@ [cuerdas.core :as str] #?(:clj [app.common.fressian :as fres]))) -;; === Constants - -(def hidden-token-theme-group - "") - -(def hidden-token-theme-name - "__PENPOT__HIDDEN__TOKEN__THEME__") - ;; === Groups handling (def schema:groupable-item @@ -263,6 +255,18 @@ (defn token-theme-path [group name] (join-path [group name] theme-separator)) +(defn split-token-theme-path [path] + (split-path path theme-separator)) + +(def hidden-token-theme-group + "") + +(def hidden-token-theme-name + "__PENPOT__HIDDEN__TOKEN__THEME__") + +(def hidden-token-theme-path + (token-theme-path hidden-token-theme-group hidden-token-theme-name)) + (defprotocol ITokenTheme (toggle-set [_ set-name] "togle a set used / not used in the theme") (theme-path [_] "get `token-theme-path` from theme") diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index 1bf96a760..2e69e5347 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -462,6 +462,15 @@ (def workspace-token-theme-tree (l/derived #(or (some-> % ctob/get-theme-tree) []) tokens-lib)) +(def workspace-token-theme-tree-no-hidden + (l/derived (fn [lib] + (or + (some-> lib + (ctob/delete-theme ctob/hidden-token-theme-group ctob/hidden-token-theme-name) + (ctob/get-theme-tree)) + [])) + tokens-lib)) + (def workspace-token-themes (l/derived #(or (some-> % ctob/get-themes) []) tokens-lib)) @@ -477,6 +486,9 @@ (def workspace-active-theme-paths (l/derived #(some-> % ctob/get-active-theme-paths) tokens-lib)) +(def workspace-active-theme-paths-no-hidden + (l/derived #(disj % ctob/hidden-token-theme-path) workspace-active-theme-paths)) + (def workspace-active-set-names (l/derived #(some-> % ctob/get-active-themes-set-names) tokens-lib)) diff --git a/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs b/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs index c8a30f678..46f8cdfd9 100644 --- a/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs @@ -17,15 +17,16 @@ [app.main.ui.components.dropdown :refer [dropdown]] [app.main.ui.icons :as i] [app.util.dom :as dom] - [rumext.v2 :as mf])) + [rumext.v2 :as mf] + [cuerdas.core :as str])) (mf/defc themes-list - [{:keys [themes active-theme-ids on-close grouped?]}] + [{:keys [themes active-theme-paths on-close grouped?]}] (when (seq themes) [:ul (for [[_ {:keys [group name] :as theme}] themes :let [theme-id (ctob/theme-path theme) - selected? (get active-theme-ids theme-id)]] + selected? (get active-theme-paths theme-id)]] [:li {:key theme-id :class (stl/css-case :checked-element true @@ -39,37 +40,34 @@ [:span {:class (stl/css :check-icon)} i/tick]])])) (mf/defc theme-options - [{:keys [on-close]}] - (let [active-theme-ids (dm/fixme (mf/deref refs/workspace-active-theme-paths)) - theme-groups (mf/deref refs/workspace-token-theme-tree)] - [:ul - (for [[group themes] theme-groups] - [:li {:key group} - (when (seq group) - [:span {:class (stl/css :group)} group]) - [:& themes-list {:themes themes - :active-theme-ids active-theme-ids - :on-close on-close - :grouped? true}]]) - [:li {:class (stl/css-case :checked-element true - :checked-element-button true) - :on-click #(modal/show! :tokens/themes {})} - [:span "Edit themes"] - [:span {:class (stl/css :icon)} i/arrow]]])) + [{:keys [active-theme-paths themes on-close]}] + [:ul + (for [[group themes] themes] + [:li {:key group} + (when (seq group) + [:span {:class (stl/css :group)} group]) + [:& themes-list {:themes themes + :active-theme-paths active-theme-paths + :on-close on-close + :grouped? true}]]) + [:li {:class (stl/css-case :checked-element true + :checked-element-button true) + :on-click #(modal/show! :tokens/themes {})} + [:span "Edit themes"] + [:span {:class (stl/css :icon)} i/arrow]]]) (mf/defc theme-select [{:keys []}] (let [;; Store - temp-theme-id (dm/legacy (mf/deref refs/workspace-temp-theme-id)) - active-theme-ids (dm/legacy (-> (mf/deref refs/workspace-active-theme-paths) - (disj temp-theme-id))) - active-themes-count (count active-theme-ids) - themes (mf/deref refs/workspace-token-theme-tree) + active-theme-paths (mf/deref refs/workspace-active-theme-paths-no-hidden) + active-themes-count (count active-theme-paths) + themes (mf/deref refs/workspace-token-theme-tree-no-hidden) ;; Data current-label (cond (> active-themes-count 1) (str active-themes-count " themes active") - ;; (pos? active-themes-count) (get-in themes [(first active-theme-ids) :name]) + (= active-themes-count 1) (some-> (first active-theme-paths) + (str/replace "/" " / ")) :else "No theme active") ;; State @@ -90,4 +88,6 @@ [:& dropdown {:show is-open? :on-close on-close-dropdown} [:div {:ref dropdown-element* :class (stl/css :custom-select-dropdown)} - [:& theme-options {:on-close on-close-dropdown}]]]])) + [:& theme-options {:active-theme-paths active-theme-paths + :themes themes + :on-close on-close-dropdown}]]]])) From b3ff480e81846d388218cf18c184596c26f09a33 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 26 Sep 2024 15:08:54 +0200 Subject: [PATCH 23/92] Hide temporary theme --- frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs index 674450fe2..f081a2cb7 100644 --- a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs @@ -57,7 +57,7 @@ (mf/defc themes-overview [{:keys [set-state]}] (let [active-theme-ids (mf/deref refs/workspace-active-theme-paths) - themes-groups (mf/deref refs/workspace-token-theme-tree) + themes-groups (mf/deref refs/workspace-token-theme-tree-no-hidden) on-edit-theme (fn [theme e] (dom/prevent-default e) (dom/stop-propagation e) From 29a2478bb5da3b6c14d96c0de7adddef8daa47a4 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 26 Sep 2024 15:15:50 +0200 Subject: [PATCH 24/92] Fix theme group drop-down not updating group value --- .../ui/workspace/tokens/modals/themes.cljs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs index f081a2cb7..a8cd00c1a 100644 --- a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs @@ -124,19 +124,20 @@ (mf/deps theme-state) (fn [set-name] (swap! theme-state #(ctob/toggle-set % set-name)))) - on-change-field (fn [field] - (fn [e] - (swap! theme-state #(assoc % field (dom/get-target-val e))))) + on-change-field (fn [field value] + (swap! theme-state #(assoc % field value))) group-input-ref (mf/use-ref) - on-update-group (on-change-field :group) - on-update-name (on-change-field :name) + on-update-group (partial on-change-field :group) + on-update-name (partial on-change-field :name) on-save-form (mf/use-callback (mf/deps theme-state on-submit) (fn [e] (dom/prevent-default e) (let [theme (-> @theme-state (update :name str/trim) - (update :description str/trim))] + (update :group str/trim) + (update :description str/trim) + (doto js/console.log))] (when-not (str/empty? (:name theme)) (on-submit theme))) (on-back)))] @@ -158,12 +159,12 @@ theme-groups) :on-select (fn [{:keys [value]}] (set! (.-value (mf/ref-val group-input-ref)) value) - (swap! theme-state assoc-in [:theme :group] value)) + (on-update-group value)) :on-close on-close-dropdown}]) [:& labeled-input {:label "Group" :input-props {:ref group-input-ref :default-value (:group theme) - :on-change on-update-group} + :on-change (comp on-update-group dom/get-target-val)} :render-right (when (seq theme-groups) (mf/fnc [] [:button {:class (stl/css :group-drop-down-button) @@ -174,7 +175,7 @@ i/arrow]))}]] [:& labeled-input {:label "Theme" :input-props {:default-value (:name theme) - :on-change on-update-name}}]] + :on-change (comp on-update-name dom/get-target-val)}}]] [:div {:class (stl/css :sets-list-wrapper)} [:& wts/controlled-sets-list {:token-sets token-sets From 5f6a76dfce9cbbf6e974f5734aafdefc3db80eec Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 26 Sep 2024 15:24:02 +0200 Subject: [PATCH 25/92] Use currently active sets as sets for temporary theme --- common/src/app/common/types/tokens_lib.cljc | 13 +++++++++---- frontend/src/app/main/data/tokens.cljs | 10 +++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index 60b7b79f3..7cf9837e1 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -268,6 +268,7 @@ (token-theme-path hidden-token-theme-group hidden-token-theme-name)) (defprotocol ITokenTheme + (set-sets [_ set-names] "set the active token sets") (toggle-set [_ set-name] "togle a set used / not used in the theme") (theme-path [_] "get `token-theme-path` from theme") (theme-matches-group-name [_ group name] "if a theme matches the given group & name") @@ -275,15 +276,19 @@ (defrecord TokenTheme [name group description is-source modified-at sets] ITokenTheme - (toggle-set [_ set-name] + (set-sets [_ set-names] (TokenTheme. name group description is-source (dt/now) - (if (sets set-name) - (disj sets set-name) - (conj sets set-name)))) + set-names)) + + (toggle-set [this set-name] + (set-sets this (if (sets set-name) + (disj sets set-name) + (conj sets set-name)))) + (theme-path [_] (token-theme-path group name)) diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index 6a33024a2..990e6bea3 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -217,9 +217,13 @@ (watch [it state _] (let [tokens-lib (get-tokens-lib state) prev-theme (ctob/get-theme tokens-lib ctob/hidden-token-theme-group ctob/hidden-token-theme-name) - theme (-> (or prev-theme (ctob/make-token-theme - :group ctob/hidden-token-theme-group - :name ctob/hidden-token-theme-name)) + active-token-set-names (ctob/get-active-themes-set-names tokens-lib) + theme (-> (or (some-> prev-theme + (ctob/set-sets active-token-set-names)) + (ctob/make-token-theme + :group ctob/hidden-token-theme-group + :name ctob/hidden-token-theme-name + :sets active-token-set-names)) (ctob/toggle-set token-set-name)) prev-active-token-themes (ctob/get-active-theme-paths tokens-lib) changes (-> (pcb/empty-changes it) From 3843253a5da59c18d49c26a7220ef66a89195cc7 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 26 Sep 2024 15:27:16 +0200 Subject: [PATCH 26/92] Dont render starting slash --- frontend/src/app/main/ui/workspace/tokens/theme_select.cljs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs b/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs index 46f8cdfd9..720998d8c 100644 --- a/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs @@ -66,8 +66,9 @@ ;; Data current-label (cond (> active-themes-count 1) (str active-themes-count " themes active") - (= active-themes-count 1) (some-> (first active-theme-paths) - (str/replace "/" " / ")) + (= active-themes-count 1) (some->> (first active-theme-paths) + (ctob/split-token-theme-path) + (str/join " / ")) :else "No theme active") ;; State From c8494c9931451eaff92b5001dfb87f9e7976a788 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 26 Sep 2024 15:32:46 +0200 Subject: [PATCH 27/92] Remove unused --- frontend/src/app/main/refs.cljs | 6 -- .../main/ui/workspace/tokens/token_set.cljs | 75 ------------------- 2 files changed, 81 deletions(-) diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index 2e69e5347..3c6f682b7 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -497,12 +497,6 @@ (l/derived #(some-> % ctob/get-active-themes-set-tokens) tokens-lib)) (dm/legacy - (def workspace-temp-theme-id - (l/derived wtts/get-temp-theme-id st/state)) - - (def workspace-ordered-token-sets-tokens - (l/derived wtts/get-workspace-ordered-sets-tokens st/state =)) - (def workspace-selected-token-set-tokens (l/derived (fn [data] diff --git a/frontend/src/app/main/ui/workspace/tokens/token_set.cljs b/frontend/src/app/main/ui/workspace/tokens/token_set.cljs index 529c13cd5..888fcfa06 100644 --- a/frontend/src/app/main/ui/workspace/tokens/token_set.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/token_set.cljs @@ -1,7 +1,6 @@ (ns app.main.ui.workspace.tokens.token-set (:require [app.common.data :refer [ordered-map]] - [app.common.data.macros :as dm] [app.common.types.tokens-lib :as ctob] [app.main.ui.workspace.tokens.token :as wtt] [clojure.set :as set])) @@ -14,29 +13,12 @@ (defn get-workspace-themes [state] (get-in state [:workspace-data :token-themes] [])) -(defn get-workspace-theme [id state] - (get-in state [:workspace-data :token-themes-index id])) - (defn get-workspace-themes-index [state] (get-in state [:workspace-data :token-themes-index] {})) -(defn get-workspace-theme-groups [state] - (reduce - (fn [acc {:keys [group]}] - (if group - (conj acc group) - acc)) - #{} (vals (get-workspace-themes-index state)))) - (defn get-workspace-token-set-groups [state] (get-in state [:workspace-data :token-set-groups])) -(defn get-workspace-ordered-themes [state] - (let [themes (get-workspace-themes state) - themes-index (get-workspace-themes-index state)] - (->> (map #(get themes-index %) themes) - (group-by :group)))) - (defn get-active-theme-ids [state] (get-in state [:workspace-data :token-active-themes] #{})) @@ -66,40 +48,6 @@ token-set-groups (get-workspace-token-set-groups state)] (filter active-set-ids token-set-groups))) -(defn theme-ids-with-group - "Returns set of theme-ids that share the same `:group` property as the theme with `theme-id`. - Will also return matching theme-ids without a `:group` property." - [theme-id state] - (let [themes (get-workspace-themes-index state) - theme-group (get-in themes [theme-id :group]) - same-group-theme-ids (->> themes - (eduction - (map val) - (filter #(= (:group %) theme-group)) - (map :id)) - (into #{}))] - same-group-theme-ids)) - -(defn toggle-active-theme-id - "Toggle a `theme-id` by checking `:token-active-themes`. - Deactivate all theme-ids that have the same group as `theme-id` when activating `theme-id`. - Ensures that the temporary theme id is selected when the resulting set is empty." - [theme-id state] - (let [temp-theme-id-set (some->> (get-temp-theme-id state) (conj #{})) - active-theme-ids (get-active-theme-ids state) - add? (not (get active-theme-ids theme-id)) - ;; Deactivate themes with the same group when activating a theme - same-group-ids (when add? (theme-ids-with-group theme-id state)) - theme-ids-without-same-group (set/difference active-theme-ids - same-group-ids - temp-theme-id-set) - new-themes (if add? - (conj theme-ids-without-same-group theme-id) - (disj theme-ids-without-same-group theme-id))] - (if (empty? new-themes) - (or temp-theme-id-set #{}) - new-themes))) - (defn update-theme-id [state] (let [active-themes (get-active-theme-ids state) @@ -115,34 +63,11 @@ (defn add-token-set-to-token-theme [token-set-id token-theme] (update token-theme :sets conj token-set-id)) -(defn toggle-token-set-to-token-theme [token-set-id token-theme] - (update token-theme :sets #(if (get % token-set-id) - (disj % token-set-id) - (conj % token-set-id)))) - ;; Sets ------------------------------------------------------------------------ (defn get-workspace-sets [state] (get-in state [:workspace-data :token-sets-index])) -(defn get-workspace-ordered-sets [state] - ;; TODO Include groups - (let [top-level-set-ids (get-in state [:workspace-data :token-set-groups]) - token-sets (get-workspace-sets state)] - (->> (map (fn [id] [id (get token-sets id)]) top-level-set-ids) - (into (ordered-map))))) - -(defn get-workspace-ordered-sets-tokens [state] - (let [sets (get-workspace-ordered-sets state)] - (reduce - (fn [acc [_ {:keys [tokens] :as sets}]] - (reduce (fn [acc' token-id] - (if-let [token (wtt/get-workspace-token token-id state)] - (assoc acc' (wtt/token-identifier token) token) - acc')) - acc tokens)) - {} sets))) - (defn get-token-set [set-id state] (some-> (get-workspace-sets state) (get set-id))) From 577fa2bc81ec94ac61f5407990eb6ad1c5270a33 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 26 Sep 2024 15:38:36 +0200 Subject: [PATCH 28/92] Cleanup --- frontend/src/app/main/refs.cljs | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index 3c6f682b7..0598e9088 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -493,7 +493,6 @@ (l/derived #(some-> % ctob/get-active-themes-set-names) tokens-lib)) (def workspace-active-theme-sets-tokens - #_(l/derived wtts/get-active-theme-sets-tokens-names-map st/state =) (l/derived #(some-> % ctob/get-active-themes-set-tokens) tokens-lib)) (dm/legacy From 9f2b96332c36e37bed109fae80323189ea0fa33e Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 26 Sep 2024 16:16:44 +0200 Subject: [PATCH 29/92] Fix up active themes tokens method --- common/src/app/common/types/tokens_lib.cljc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index 7cf9837e1..1ca3e0987 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -605,14 +605,14 @@ (get-active-themes this))) (get-active-themes-set-tokens [this] - (mapcat (fn [x] - (->> (get x :sets) - (map (fn [y] - (-> - (get-set this y) - :tokens))))) - (get-active-themes this))) - + (reduce + (fn [acc cur] + (if (theme-active? this (:group cur) (:name cur)) + (into acc + (->> (get cur :sets) + (map #(-> (get-set this %) :tokens)))) + acc)) + (d/ordered-map) (tree-seq d/ordered-map? vals themes))) (validate [_] (and (valid-token-sets? sets) ;; TODO: validate set-groups From 2f13814285294ebc86732749e2f92ade9a518875 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 26 Sep 2024 16:37:30 +0200 Subject: [PATCH 30/92] Cleanup --- .../app/main/ui/workspace/tokens/common.cljs | 12 +------- .../app/main/ui/workspace/tokens/form.cljs | 5 ++-- .../app/main/ui/workspace/tokens/sidebar.cljs | 28 ------------------- .../app/main/ui/workspace/tokens/token.cljs | 16 ++++------- 4 files changed, 10 insertions(+), 51 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/common.cljs b/frontend/src/app/main/ui/workspace/tokens/common.cljs index ea0b8bc65..e81c93999 100644 --- a/frontend/src/app/main/ui/workspace/tokens/common.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/common.cljs @@ -19,20 +19,10 @@ [cuerdas.core :as str] [goog.events :as events] [rumext.v2 :as mf]) - (:import - goog.events.EventType)) + (:import goog.events.EventType)) ;; Helpers --------------------------------------------------------------------- -(defn workspace-shapes [workspace page-id shape-ids] - (-> (get-in workspace [:pages-index page-id :objects]) - (keep shape-ids))) - -(defn vec-remove - "remove elem in coll" - [pos coll] - (into (subvec coll 0 pos) (subvec coll (inc pos)))) - (defn camel-keys [m] (->> m (d/deep-mapm diff --git a/frontend/src/app/main/ui/workspace/tokens/form.cljs b/frontend/src/app/main/ui/workspace/tokens/form.cljs index b202c3ac8..8f19159c4 100644 --- a/frontend/src/app/main/ui/workspace/tokens/form.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/form.cljs @@ -203,8 +203,9 @@ Token names should only contain letters and digits separated by . characters.")} color? (wtt/color-token? token) selected-set-tokens (mf/deref refs/workspace-selected-token-set-tokens) active-theme-tokens (mf/deref refs/workspace-active-theme-sets-tokens) - resolved-tokens (sd/use-resolved-tokens active-theme-tokens {:names-map? true - :cache-atom form-token-cache-atom}) + resolved-tokens (sd/use-resolved-tokens (vals active-theme-tokens) {:names-map? true + :cache-atom form-token-cache-atom}) + _ (js/console.log "resolved-tokens" resolved-tokens) token-path (mf/use-memo (mf/deps (:name token)) #(wtt/token-name->path (:name token))) diff --git a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs index 4e44c1415..bb67de78b 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs @@ -10,7 +10,6 @@ [app.common.data :as d] [app.main.data.modal :as modal] [app.main.data.tokens :as dt] - [app.main.data.tokens :as wdt] [app.main.refs :as refs] [app.main.store :as st] [app.main.ui.components.color-bullet :refer [color-bullet]] @@ -19,7 +18,6 @@ [app.main.ui.icons :as i] [app.main.ui.workspace.sidebar.assets.common :as cmm] [app.main.ui.workspace.tokens.changes :as wtch] - [app.main.ui.workspace.tokens.common :refer [labeled-input]] [app.main.ui.workspace.tokens.context-menu :refer [token-context-menu]] [app.main.ui.workspace.tokens.core :as wtc] [app.main.ui.workspace.tokens.sets :refer [sets-list]] @@ -42,15 +40,6 @@ (def ^:private download-icon (i/icon-xref :download (stl/css :download-icon))) -(def selected-set-id - (l/derived :selected-set-id st/state)) - - ;; Event Functions ------------------------------------------------------------- - -(defn on-set-add-click [_event] - (when-let [set-name (js/window.prompt "Set name")] - (st/emit! (wdt/create-token-set {:name set-name})))) - ;; Components ------------------------------------------------------------------ (mf/defc token-pill @@ -173,23 +162,6 @@ {:empty (sort-by :token-key empty) :filled (sort-by :token-key filled)})) -(mf/defc tokene-theme-create - [_props] - (let [group (mf/use-state "") - name (mf/use-state "")] - [:div {:style {:display "flex" - :flex-direction "column" - :gap "10px"}} - [:& labeled-input {:label "Group name" - :input-props {:value @group - :on-change #(reset! group (dom/event->value %))}}] - [:& labeled-input {:label "Theme name" - :input-props {:value @name - :on-change #(reset! name (dom/event->value %))}}] - [:button {:on-click #(st/emit! (wdt/create-token-theme {:group @group - :name @name}))} - "Create"]])) - (mf/defc edit-button [{:keys [create?]}] [:button {:class (stl/css :themes-button) diff --git a/frontend/src/app/main/ui/workspace/tokens/token.cljs b/frontend/src/app/main/ui/workspace/tokens/token.cljs index 9c097b180..6a7448195 100644 --- a/frontend/src/app/main/ui/workspace/tokens/token.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/token.cljs @@ -6,10 +6,6 @@ [clojure.set :as set] [cuerdas.core :as str])) -(defn get-workspace-tokens - [state] - (get-in state [:workspace-data :tokens] {})) - (defn get-workspace-token [token-id state] (get-in state [:workspace-data :tokens token-id])) @@ -67,12 +63,6 @@ [token shape token-attributes] (some #(token-attribute-applied? token shape %) token-attributes)) -(defn token-applied-attributes - "Return a set of which `token-attributes` are applied with `token`." - [token shape token-attributes] - (-> (filter #(token-attribute-applied? token shape %) token-attributes) - (set))) - (defn shapes-token-applied? "Test if `token` is applied to to any of `shapes` with at least one of the one of the given `token-attributes`." [token shapes token-attributes] @@ -120,6 +110,12 @@ (defonce a (atom nil)) +(comment + + (token-names-tree-id-map @a) + nil) + + (defn token-names-tree-id-map [tokens] (reset! a tokens) (reduce From 7c4cbe52652472798112d5ee9f802f69c4adccb2 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 26 Sep 2024 16:40:38 +0200 Subject: [PATCH 31/92] Cleanup --- frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs | 1 - frontend/src/app/main/ui/workspace/tokens/token_set.cljs | 3 --- 2 files changed, 4 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs index a8cd00c1a..df481aa25 100644 --- a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs @@ -17,7 +17,6 @@ [app.main.ui.workspace.tokens.common :refer [labeled-input] :as wtco] [app.main.ui.workspace.tokens.sets :as wts] [app.main.ui.workspace.tokens.sets-context :as sets-context] - [app.main.ui.workspace.tokens.token-set :as wtts] [app.util.dom :as dom] [cuerdas.core :as str] [rumext.v2 :as mf])) diff --git a/frontend/src/app/main/ui/workspace/tokens/token_set.cljs b/frontend/src/app/main/ui/workspace/tokens/token_set.cljs index 888fcfa06..d3b514928 100644 --- a/frontend/src/app/main/ui/workspace/tokens/token_set.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/token_set.cljs @@ -10,9 +10,6 @@ ;; Themes ---------------------------------------------------------------------- -(defn get-workspace-themes [state] - (get-in state [:workspace-data :token-themes] [])) - (defn get-workspace-themes-index [state] (get-in state [:workspace-data :token-themes-index] {})) From 1d50bacfbc412ceca036820ade12fbd952a5c75e Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 26 Sep 2024 17:21:02 +0200 Subject: [PATCH 32/92] Fix set renaming not being updated in themes --- common/src/app/common/files/changes.cljc | 13 ++++++++----- common/src/app/common/types/tokens_lib.cljc | 19 +++++++++++++++++-- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index eb65fd669..f43fb7199 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -882,11 +882,14 @@ [data {:keys [name token-set]}] (-> data (update :tokens-lib - #(-> % - (ctob/ensure-tokens-lib) - (ctob/update-set name (fn [prev-set] - (merge prev-set - (dissoc token-set :tokens)))))))) + (fn [element] + (let [path-changed? (not= name (:name token-set)) + lib (-> element + (ctob/ensure-tokens-lib) + (ctob/update-set name (fn [prev-set] + (merge prev-set (dissoc token-set :tokens)))))] + (cond-> lib + path-changed? (ctob/update-set-name name (:name token-set)))))))) (defmethod process-change :del-token-set [data {:keys [name]}] diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index 1ca3e0987..2811a13d9 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -6,6 +6,7 @@ (ns app.common.types.tokens-lib (:require + #?(:clj [app.common.fressian :as fres]) [app.common.data :as d] [app.common.data.macros :as dm] [app.common.schema :as sm] @@ -13,8 +14,8 @@ [app.common.transit :as t] [app.common.types.token :as cto] [clojure.set :as set] - [cuerdas.core :as str] - #?(:clj [app.common.fressian :as fres]))) + [clojure.walk :as walk] + [cuerdas.core :as str])) ;; === Groups handling @@ -391,6 +392,7 @@ (toggle-set-in-theme [_ group-name theme-name set-name] "toggle a set used / not used in a theme") (get-active-themes-set-names [_] "set of set names that are active in the the active themes") (get-active-themes-set-tokens [_] "set of set names that are active in the the active themes") + (update-set-name [_ old-set-name new-set-name] "updates set name in themes") (validate [_])) (deftype TokensLib [sets set-groups themes active-themes] @@ -614,6 +616,19 @@ acc)) (d/ordered-map) (tree-seq d/ordered-map? vals themes))) + (update-set-name [_ old-set-name new-set-name] + (TokensLib. sets + set-groups + (walk/postwalk + (fn [form] + (if (instance? TokenTheme form) + (-> form + (update :sets disj old-set-name) + (update :sets conj new-set-name)) + form)) + themes) + active-themes)) + (validate [_] (and (valid-token-sets? sets) ;; TODO: validate set-groups (valid-token-themes? themes) From 93ed1ded1791d1d03164d1eef09931adafdebd54 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Fri, 27 Sep 2024 11:14:34 +0200 Subject: [PATCH 33/92] Token resolving on add fixed --- .../app/main/ui/workspace/tokens/form.cljs | 41 +++++++++---------- .../ui/workspace/tokens/style_dictionary.cljs | 10 ++--- .../app/main/ui/workspace/tokens/token.cljs | 11 +---- 3 files changed, 26 insertions(+), 36 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/form.cljs b/frontend/src/app/main/ui/workspace/tokens/form.cljs index 8f19159c4..2d0409638 100644 --- a/frontend/src/app/main/ui/workspace/tokens/form.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/form.cljs @@ -25,6 +25,7 @@ [app.main.ui.workspace.tokens.update :as wtu] [app.util.dom :as dom] [cuerdas.core :as str] + [linked.map :as lkm] [malli.core :as m] [malli.error :as me] [promesa.core :as p] @@ -99,30 +100,28 @@ Token names should only contain letters and digits separated by . characters.")} (defn validate-token-value+ "Validates token value by resolving the value `input` using `StyleDictionary`. Returns a promise of either resolved tokens or rejects with an error state." - [{:keys [input name-value token tokens]}] - (let [ ;; When creating a new token we dont have a token name yet, + [{:keys [value name-value token tokens]}] + (let [;; When creating a new token we dont have a token name yet, ;; so we use a temporary token name that hopefully doesn't clash with any of the users token names token-name (if (str/empty? name-value) "__TOKEN_STUDIO_SYSTEM.TEMP" name-value)] (cond - (empty? (str/trim input)) + (empty? (str/trim value)) (p/rejected {:errors [{:error/code :error/empty-input}]}) - (token-self-reference? token-name input) + (token-self-reference? token-name value) (p/rejected {:errors [(wte/get-error-code :error.token/direct-self-reference)]}) :else - (let [token-id (or (:id token) (random-uuid)) - new-tokens (update tokens token-name merge {:id token-id - :value input - :name token-name - :type (:type token)})] - (-> (sd/resolve-tokens+ new-tokens {:names-map? true}) - (p/then - (fn [resolved-tokens] - (let [{:keys [errors resolved-value] :as resolved-token} (get resolved-tokens token-name)] - (cond - resolved-value (p/resolved resolved-token) - :else (p/rejected {:errors (or errors (wte/get-error-code :error/unknown-error))})))))))))) + (-> (update tokens token-name merge {:value value + :name token-name + :type (:type token)}) + (sd/resolve-tokens+ {:names-map? true}) + (p/then + (fn [resolved-tokens] + (let [{:keys [errors resolved-value] :as resolved-token} (get resolved-tokens token-name)] + (cond + resolved-value (p/resolved resolved-token) + :else (p/rejected {:errors (or errors (wte/get-error-code :error/unknown-error))}))))))))) (defn use-debonced-resolve-callback "Resolves a token values using `StyleDictionary`. @@ -141,7 +140,7 @@ Token names should only contain letters and digits separated by . characters.")} (js/setTimeout (fn [] (when (not (timeout-outdated-cb?)) - (-> (validate-token-value+ {:input value + (-> (validate-token-value+ {:value value :name-value @name-ref :token token :tokens tokens}) @@ -203,9 +202,9 @@ Token names should only contain letters and digits separated by . characters.")} color? (wtt/color-token? token) selected-set-tokens (mf/deref refs/workspace-selected-token-set-tokens) active-theme-tokens (mf/deref refs/workspace-active-theme-sets-tokens) - resolved-tokens (sd/use-resolved-tokens (vals active-theme-tokens) {:names-map? true - :cache-atom form-token-cache-atom}) - _ (js/console.log "resolved-tokens" resolved-tokens) + resolved-tokens (sd/use-resolved-tokens (vals active-theme-tokens) + {:names-map? true + :cache-atom form-token-cache-atom}) token-path (mf/use-memo (mf/deps (:name token)) #(wtt/token-name->path (:name token))) @@ -310,7 +309,7 @@ Token names should only contain letters and digits separated by . characters.")} valid-description?+ (some-> final-description validate-descripion schema-validation->promise)] (-> (p/all [valid-name?+ valid-description?+ - (validate-token-value+ {:input final-value + (validate-token-value+ {:value final-value :name-value final-name :token token :tokens resolved-tokens})]) diff --git a/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs b/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs index 7c6f73200..eb603f50f 100644 --- a/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs @@ -76,10 +76,9 @@ (p/let [sd-tokens (resolve-sd-tokens+ tree)] (let [resolved-tokens (reduce (fn [acc ^js cur] - (let [identifier (if names-map? - (.. cur -original -name) - (uuid (.-uuid (.-id cur)))) - {:keys [type] :as origin-token} (get ids-map identifier) + (let [{:keys [type] :as origin-token} (if names-map? + (get tokens (.. cur -original -name)) + (get ids-map (uuid (.-uuid (.-id cur))))) value (.-value cur) token-or-err (case type :color (if-let [tc (tinycolor/valid-color value)] @@ -115,7 +114,7 @@ This hook will return the unresolved tokens as state until they are processed, then the state will be updated with the resolved tokens." - [tokens & {:keys [cache-atom _names-map?] + [tokens & {:keys [cache-atom names-map?] :or {cache-atom !tokens-cache} :as config}] (let [tokens-state (mf/use-state (get @cache-atom tokens))] @@ -124,6 +123,7 @@ (fn [] (let [cached (get @cache-atom tokens)] (cond + (nil? tokens) (if names-map? {} []) ;; The tokens are already processing somewhere (p/promise? cached) (-> cached (p/then #(reset! tokens-state %)) diff --git a/frontend/src/app/main/ui/workspace/tokens/token.cljs b/frontend/src/app/main/ui/workspace/tokens/token.cljs index 6a7448195..49427bee9 100644 --- a/frontend/src/app/main/ui/workspace/tokens/token.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/token.cljs @@ -108,18 +108,9 @@ (->> (map (fn [{:keys [name] :as token}] [name token]) tokens) (into {}))) -(defonce a (atom nil)) - -(comment - - (token-names-tree-id-map @a) - nil) - - (defn token-names-tree-id-map [tokens] - (reset! a tokens) (reduce - (fn [acc {:keys [name] :as token}] + (fn [acc [_ {:keys [name] :as token}]] (when (string? name) (let [temp-id (random-uuid) token (assoc token :temp/id temp-id)] From b7cedf219bca70c1ce40bb86faa236e237263bef Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Fri, 27 Sep 2024 11:21:30 +0200 Subject: [PATCH 34/92] Cleanup --- frontend/src/app/main/data/tokens.cljs | 33 +++++++++++++------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index 990e6bea3..810399036 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -253,28 +253,27 @@ (ptk/reify ::update-create-token ptk/WatchEvent (watch [it state _] - (let [token-set (wtts/get-selected-token-set state) - create-set? (not token-set) - token-set (or token-set - {:id (uuid/next) - :name "Global" - :tokens []}) + (let [token-set (wtts/get-selected-token-set state) + create-set? (not token-set) + token-set (or token-set + {:id (uuid/next) + :name "Global" + :tokens []}) - changes (cond-> (pcb/empty-changes it) - create-set? - (pcb/add-token-set token-set)) + changes (cond-> (pcb/empty-changes it) + create-set? + (pcb/add-token-set token-set)) prev-token-id (d/seek #(= % (:id token)) (:tokens token-set)) - prev-token (get-token-data-from-token-id prev-token-id) + prev-token (get-token-data-from-token-id prev-token-id) create-token? (not prev-token) - changes (if create-token? - (pcb/add-token changes (:id token-set) (:name token-set) token) - (pcb/update-token changes (:id token-set) (:name token-set) token prev-token)) - - changes (-> changes - (ensure-token-theme-changes state {:new-set? create-set? - :id (:id token-set)}))] + changes (if create-token? + (pcb/add-token changes (:id token-set) (:name token-set) token) + (pcb/update-token changes (:id token-set) (:name token-set) token prev-token)) + changes (-> changes + (ensure-token-theme-changes state {:new-set? create-set? + :id (:id token-set)}))] (rx/of (set-selected-token-set-id (:name token-set)) (dch/commit-changes changes))))))) From cce4014fbedd2e5be3a26089cffdd9f7efd9e618 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Fri, 27 Sep 2024 15:36:07 +0200 Subject: [PATCH 35/92] Fix token create --- common/src/app/common/files/changes.cljc | 4 -- .../src/app/common/files/changes_builder.cljc | 16 +++--- common/src/app/common/types/token.cljc | 1 - common/src/app/common/types/tokens_lib.cljc | 4 ++ frontend/src/app/main/data/tokens.cljs | 53 ++++++------------- 5 files changed, 29 insertions(+), 49 deletions(-) diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index f43fb7199..eccd349bb 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -303,16 +303,13 @@ [:add-token [:map {:title "AddTokenChange"} [:type [:= :add-token]] - [:set-id ::sm/uuid] [:set-name :string] [:token ::cto/token]]] [:mod-token [:map {:title "ModTokenChange"} [:type [:= :mod-token]] - [:set-id ::sm/uuid] [:set-name :string] - [:id ::sm/uuid] [:name :string] [:token ::cto/token]]] @@ -320,7 +317,6 @@ [:map {:title "DelTokenChange"} [:type [:= :del-token]] [:set-name :string] - [:id ::sm/uuid] [:name :string]]]]]) (sm/register! ::changes diff --git a/common/src/app/common/files/changes_builder.cljc b/common/src/app/common/files/changes_builder.cljc index 4bc2f967f..c0f5bd29f 100644 --- a/common/src/app/common/files/changes_builder.cljc +++ b/common/src/app/common/files/changes_builder.cljc @@ -765,17 +765,17 @@ (apply-changes-local)))) (defn add-token - [changes set-id set-name token] + [changes set-name token] (-> changes - (update :redo-changes conj {:type :add-token :set-id set-id :set-name set-name :token token}) - (update :undo-changes conj {:type :del-token :set-name set-name :id (:id token) :name (:name token)}) + (update :redo-changes conj {:type :add-token :set-name set-name :token token}) + (update :undo-changes conj {:type :del-token :set-name set-name :name (:name token)}) (apply-changes-local))) (defn update-token - [changes set-id set-name {:keys [id name] :as token} {prev-name :name :as prev-token}] + [changes set-name token prev-token] (-> changes - (update :redo-changes conj {:type :mod-token :set-id set-id :set-name set-name :id id :name prev-name :token token}) - (update :undo-changes conj {:type :mod-token :set-id set-id :set-name set-name :id id :name name :token (or prev-token token)}) + (update :redo-changes conj {:type :mod-token :set-name set-name :name (:name prev-token) :token token}) + (update :undo-changes conj {:type :mod-token :set-name set-name :name (:name token) :token (or prev-token token)}) (apply-changes-local))) (defn delete-token @@ -784,8 +784,8 @@ (let [library-data (::library-data (meta changes)) prev-token (get-in library-data [:tokens token-id])] (-> changes - (update :redo-changes conj {:type :del-token :set-name set-name :id token-id :name token-name}) - (update :undo-changes conj {:type :add-token :set-id uuid/zero :set-name set-name :token prev-token}) + (update :redo-changes conj {:type :del-token :set-name set-name :name token-name}) + (update :undo-changes conj {:type :add-token :set-name set-name :token prev-token}) (apply-changes-local)))) (defn add-component diff --git a/common/src/app/common/types/token.cljc b/common/src/app/common/types/token.cljc index ed63908ab..e66c65af6 100644 --- a/common/src/app/common/types/token.cljc +++ b/common/src/app/common/types/token.cljc @@ -60,7 +60,6 @@ (sm/register! ::token [:map {:title "Token"} - [:id ::sm/uuid] [:name token-name-ref] [:type [::sm/one-of token-types]] [:value :any] diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index 2811a13d9..a72d3dd35 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -138,6 +138,7 @@ (add-token [_ token] "add a token at the end of the list") (update-token [_ token-name f] "update a token in the list") (delete-token [_ token-name] "delete a token from the list") + (get-token [_ token-name] "return an ordered sequence of all tokens in the set") (get-tokens [_] "return an ordered sequence of all tokens in the set")) (defrecord TokenSet [name description modified-at tokens] @@ -170,6 +171,9 @@ (dt/now) (dissoc tokens token-name))) + (get-token [_ token-name] + (get tokens token-name)) + (get-tokens [_] (vals tokens))) diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index 810399036..e396988eb 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -203,14 +203,6 @@ theme) (pcb/update-active-token-themes #{target-theme-id} (wtts/get-active-theme-ids state)))] -(comment - (-> (ctob/make-token-theme - :group "" - :name "bar") - (ctob/toggle-set "foo")) - nil) - - (defn toggle-token-set [{:keys [token-set-name]}] (ptk/reify ::toggle-token-set ptk/WatchEvent @@ -249,34 +241,23 @@ (defn update-create-token [token] - (let [token (update token :id #(or % (uuid/next)))] - (ptk/reify ::update-create-token - ptk/WatchEvent - (watch [it state _] - (let [token-set (wtts/get-selected-token-set state) - create-set? (not token-set) - token-set (or token-set - {:id (uuid/next) - :name "Global" - :tokens []}) - - changes (cond-> (pcb/empty-changes it) - create-set? - (pcb/add-token-set token-set)) - - prev-token-id (d/seek #(= % (:id token)) (:tokens token-set)) - prev-token (get-token-data-from-token-id prev-token-id) - create-token? (not prev-token) - - changes (if create-token? - (pcb/add-token changes (:id token-set) (:name token-set) token) - (pcb/update-token changes (:id token-set) (:name token-set) token prev-token)) - changes (-> changes - (ensure-token-theme-changes state {:new-set? create-set? - :id (:id token-set)}))] - (rx/of - (set-selected-token-set-id (:name token-set)) - (dch/commit-changes changes))))))) + (ptk/reify ::update-create-token + ptk/WatchEvent + (watch [_ state _] + (let [tlib (get-tokens-lib state) + token-set (wtts/get-selected-token-set state) + changes (if (not token-set) + ;; No set created add a global set + (->> (ctob/make-token-set tlib :name "Global") + (ctob/add-token token) + (pcb/add-token-set (pcb/empty-changes))) + ;; Either update or add token to existing set + (if-let [prev-token (ctob/get-token token-set (:name token))] + (pcb/update-token (pcb/empty-changes) (:name token-set) token prev-token) + (pcb/add-token (pcb/empty-changes) (:name token-set) token)))] + (rx/of + (set-selected-token-set-id (:name token-set)) + (dch/commit-changes changes)))))) (defn delete-token [set-name id name] From 066ee9c489c3f15e790a73a5d31786f8ebfe437a Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 30 Sep 2024 08:23:22 +0200 Subject: [PATCH 36/92] Tokens in sidebar --- frontend/src/app/main/refs.cljs | 12 ++++++------ .../sidebar/options/menus/layout_container.cljs | 2 +- .../app/main/ui/workspace/tokens/context_menu.cljs | 2 +- frontend/src/app/main/ui/workspace/tokens/core.cljs | 2 +- frontend/src/app/main/ui/workspace/tokens/form.cljs | 2 +- .../src/app/main/ui/workspace/tokens/token_set.cljs | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index 0598e9088..f1052dbc8 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -459,9 +459,6 @@ (ctob/get-theme lib group name))) tokens-lib)) -(def workspace-token-theme-tree - (l/derived #(or (some-> % ctob/get-theme-tree) []) tokens-lib)) - (def workspace-token-theme-tree-no-hidden (l/derived (fn [lib] (or @@ -493,13 +490,16 @@ (l/derived #(some-> % ctob/get-active-themes-set-names) tokens-lib)) (def workspace-active-theme-sets-tokens - (l/derived #(some-> % ctob/get-active-themes-set-tokens) tokens-lib)) + (l/derived #(or (some-> % ctob/get-active-themes-set-tokens) {}) tokens-lib)) + +(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 + (def workspace-selected-token-set-tokens-OLD (l/derived (fn [data] - (or (wtts/get-selected-token-set-tokens data) {})) + {}) st/state =))) 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 b758051d5..0092dac58 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 @@ -856,7 +856,7 @@ shape (when-not multiple (first (deref (refs/objects-by-id ids)))) - tokens (mf/deref refs/workspace-selected-token-set-tokens) + 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))) spacing-column-options (mf/use-memo diff --git a/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs b/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs index 6e4156d03..e4ce8b795 100644 --- a/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs @@ -312,7 +312,7 @@ selected (mf/deref refs/selected-shapes) selected-shapes (into [] (keep (d/getf objects)) selected) token-id (:token-id mdata) - token (get (mf/deref refs/workspace-selected-token-set-tokens) token-id) + token (get (mf/deref refs/workspace-selected-token-set-tokens-OLD) token-id) selected-token-set-id (mf/deref refs/workspace-selected-token-set-id)] (mf/use-effect (mf/deps mdata) diff --git a/frontend/src/app/main/ui/workspace/tokens/core.cljs b/frontend/src/app/main/ui/workspace/tokens/core.cljs index 117e7b3df..6fe482836 100644 --- a/frontend/src/app/main/ui/workspace/tokens/core.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/core.cljs @@ -66,6 +66,6 @@ {:global global})) (defn download-tokens-as-json [] - (let [all-tokens (deref refs/workspace-selected-token-set-tokens) + (let [all-tokens (deref refs/workspace-selected-token-set-tokens-OLD) transformed-tokens-json (transform-tokens-into-json-format all-tokens)] (export-tokens-file transformed-tokens-json))) diff --git a/frontend/src/app/main/ui/workspace/tokens/form.cljs b/frontend/src/app/main/ui/workspace/tokens/form.cljs index 2d0409638..ac90d9a42 100644 --- a/frontend/src/app/main/ui/workspace/tokens/form.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/form.cljs @@ -202,7 +202,7 @@ Token names should only contain letters and digits separated by . characters.")} color? (wtt/color-token? token) selected-set-tokens (mf/deref refs/workspace-selected-token-set-tokens) active-theme-tokens (mf/deref refs/workspace-active-theme-sets-tokens) - resolved-tokens (sd/use-resolved-tokens (vals active-theme-tokens) + resolved-tokens (sd/use-resolved-tokens active-theme-tokens {:names-map? true :cache-atom form-token-cache-atom}) token-path (mf/use-memo diff --git a/frontend/src/app/main/ui/workspace/tokens/token_set.cljs b/frontend/src/app/main/ui/workspace/tokens/token_set.cljs index d3b514928..20ebb5d81 100644 --- a/frontend/src/app/main/ui/workspace/tokens/token_set.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/token_set.cljs @@ -103,7 +103,7 @@ (defn get-selected-token-set-tokens [state] (some-> (get-selected-token-set state) - (ctob/get-tokens))) + :tokens)) (defn assoc-selected-token-set-id [state id] (assoc-in state [:workspace-local :selected-token-set-id] id)) From 8c58ed80ac801ee6113145aab8d4301be2783c0e Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 30 Sep 2024 08:31:18 +0200 Subject: [PATCH 37/92] Fix id --- frontend/src/app/main/ui/workspace/tokens/sidebar.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs index bb67de78b..3c1750858 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs @@ -140,7 +140,7 @@ (for [token (sort-by :modified-at tokens)] (let [theme-token (get active-theme-tokens (wtt/token-identifier token))] [:& token-pill - {:key (:id token) + {:key (:name token) :token token :theme-token theme-token :highlighted? (wtt/shapes-token-applied? token selected-shapes (or all-attributes attributes)) From 99a3ed98c917ce6568abbb48342dd6f61f0c95d0 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 30 Sep 2024 08:46:31 +0200 Subject: [PATCH 38/92] Only load context menu when open --- .../ui/workspace/tokens/context_menu.cljs | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs b/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs index e4ce8b795..6481da79f 100644 --- a/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs @@ -301,19 +301,28 @@ :on-click action :selected? selected?}])]))) +(mf/defc token-context-menu-tree + [{:keys [width] :as mdata}] + (js/console.log "mdata" mdata) + (let [objects (mf/deref refs/workspace-page-objects) + selected (mf/deref refs/selected-shapes) + selected-shapes (into [] (keep (d/getf objects)) selected) + token-name (:token-name mdata) + token (mf/deref (refs/workspace-selected-token-set-token token-name)) + selected-token-set-id (mf/deref refs/workspace-selected-token-set-id)] + [:ul {:class (stl/css :context-list)} + [:& menu-tree {:submenu-offset width + :token token + :selected-token-set-id selected-token-set-id + :selected-shapes selected-shapes}]])) + (mf/defc token-context-menu [] (let [mdata (mf/deref tokens-menu-ref) top (+ (get-in mdata [:position :y]) 5) left (+ (get-in mdata [:position :x]) 5) width (mf/use-state 0) - dropdown-ref (mf/use-ref) - objects (mf/deref refs/workspace-page-objects) - selected (mf/deref refs/selected-shapes) - selected-shapes (into [] (keep (d/getf objects)) selected) - token-id (:token-id mdata) - token (get (mf/deref refs/workspace-selected-token-set-tokens-OLD) token-id) - selected-token-set-id (mf/deref refs/workspace-selected-token-set-id)] + dropdown-ref (mf/use-ref)] (mf/use-effect (mf/deps mdata) (fn [] @@ -325,9 +334,5 @@ :ref dropdown-ref :style {:top top :left left} :on-context-menu prevent-default} - (when token - [:ul {:class (stl/css :context-list)} - [:& menu-tree {:submenu-offset @width - :token token - :selected-token-set-id selected-token-set-id - :selected-shapes selected-shapes}]])]])) + (when mdata + [:& token-context-menu-tree (assoc mdata :offset @width)])]])) From cfec4ae958a72d1a8ee037435e7bd9d898ad0a6d Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 30 Sep 2024 09:08:14 +0200 Subject: [PATCH 39/92] Cleanup --- common/src/app/common/types/tokens_lib.cljc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index a72d3dd35..b14951059 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -104,10 +104,10 @@ (def schema:token [:and [:map {:title "Token"} - [:name cto/token-name-ref] ;; not necessary to have uuid + [:name cto/token-name-ref] [:type [::sm/one-of cto/token-types]] [:value :any] - [:description [:maybe :string]] ;; defrecord always have the attributes, even with nil value + [:description [:maybe :string]] [:modified-at ::sm/inst]] [:fn (partial instance? Token)]]) From a59e391b387578e66153e5d5341d02176e292869 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 30 Sep 2024 09:19:06 +0200 Subject: [PATCH 40/92] Fix token deletion menu --- .../src/app/common/files/changes_builder.cljc | 6 ++- common/src/app/common/types/token.cljc | 2 +- frontend/src/app/main/data/tokens.cljs | 47 ++----------------- frontend/src/app/main/refs.cljs | 7 +++ .../ui/workspace/tokens/context_menu.cljs | 11 ++--- .../app/main/ui/workspace/tokens/sets.cljs | 1 - .../app/main/ui/workspace/tokens/sidebar.cljs | 2 +- 7 files changed, 22 insertions(+), 54 deletions(-) diff --git a/common/src/app/common/files/changes_builder.cljc b/common/src/app/common/files/changes_builder.cljc index c0f5bd29f..57978d0d2 100644 --- a/common/src/app/common/files/changes_builder.cljc +++ b/common/src/app/common/files/changes_builder.cljc @@ -779,10 +779,12 @@ (apply-changes-local))) (defn delete-token - [changes set-name token-id token-name] + [changes set-name token-name] (assert-library! changes) (let [library-data (::library-data (meta changes)) - prev-token (get-in library-data [:tokens token-id])] + prev-token (some-> (get library-data :tokens-lib) + (ctob/get-set set-name) + (ctob/get-token token-name))] (-> changes (update :redo-changes conj {:type :del-token :set-name set-name :name token-name}) (update :undo-changes conj {:type :add-token :set-name set-name :token prev-token}) diff --git a/common/src/app/common/types/token.cljc b/common/src/app/common/types/token.cljc index e66c65af6..7dc03a305 100644 --- a/common/src/app/common/types/token.cljc +++ b/common/src/app/common/types/token.cljc @@ -63,7 +63,7 @@ [:name token-name-ref] [:type [::sm/one-of token-types]] [:value :any] - [:description {:optional true} :string] + [:description {:optional true} [:maybe :string]] [:modified-at {:optional true} ::sm/inst]]) (sm/register! ::color diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index e396988eb..91e90c325 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -260,17 +260,16 @@ (dch/commit-changes changes)))))) (defn delete-token - [set-name id name] + [set-name token-name] (dm/assert! (string? set-name)) - (dm/assert! (uuid? id)) - (dm/assert! (string? name)) + (dm/assert! (string? token-name)) (ptk/reify ::delete-token ptk/WatchEvent (watch [it state _] (let [data (get state :workspace-data) changes (-> (pcb/empty-changes it) (pcb/with-library-data data) - (pcb/delete-token set-name id name))] + (pcb/delete-token set-name token-name))] (rx/of (dch/commit-changes changes)))))) (defn duplicate-token @@ -280,42 +279,6 @@ (update :name #(str/concat % "-copy")))] (update-create-token new-token))) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; TEMP (Move to test) -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(comment - (def shape-1 {:r3 3}) - - (def token-1 {:rx 1 - :ry 1}) - - - (def shape-after-token-1-is-applied {:rx 1 - :ry 1 - :r3 3}) - - (def token-2 {:r3 1}) - - - (def shape-after-token-2-is-applied {:rx 1 - :ry 1 - :r3 1}) - - (def token-3 {:r3 1}) - - (def shape-after-token-3-is-applied {:rx 1 - :ry 1}) - - (= (toggle-or-apply-token shape-1 token-1) - shape-after-token-1-is-applied) - (= (toggle-or-apply-token shape-after-token-1-is-applied token-2) - shape-after-token-2-is-applied) - (= (toggle-or-apply-token shape-after-token-2-is-applied token-3) - shape-after-token-3-is-applied) - nil) - (defn set-token-type-section-open [token-type open?] (ptk/reify ::set-token-type-section-open @@ -326,7 +289,7 @@ ;; Token Context Menu Functions ------------------------------------------------- (defn show-token-context-menu - [{:keys [position _token-id] :as params}] + [{:keys [position _token-name] :as params}] (dm/assert! (gpt/point? position)) (ptk/reify ::show-token-context-menu ptk/UpdateEvent @@ -340,7 +303,7 @@ (assoc-in state [:workspace-local :token-context-menu] nil)))) (defn show-token-set-context-menu - [{:keys [position _token-set-id] :as params}] + [{:keys [position _token-set-name] :as params}] (dm/assert! (gpt/point? position)) (ptk/reify ::show-token-set-context-menu ptk/UpdateEvent diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index f1052dbc8..33687b81e 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -492,6 +492,13 @@ (def workspace-active-theme-sets-tokens (l/derived #(or (some-> % ctob/get-active-themes-set-tokens) {}) tokens-lib)) +(def workspace-selected-token-set-token + (fn [token-name] + (l/derived + #(some-> (wtts/get-selected-token-set %) + (ctob/get-token token-name)) + st/state))) + (def workspace-selected-token-set-tokens (l/derived #(or (wtts/get-selected-token-set-tokens %) {}) st/state)) diff --git a/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs b/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs index 6481da79f..a50218df7 100644 --- a/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs @@ -202,16 +202,14 @@ (generic-attribute-actions #{:y} "Y" (assoc context-data :on-update-shape wtch/update-shape-position))))})) (defn default-actions [{:keys [token selected-token-set-id]}] - (let [{:keys [modal]} (wtty/get-token-properties token) - selected-token-set (dt/get-token-set-data-from-token-set-id selected-token-set-id)] + (let [{:keys [modal]} (wtty/get-token-properties token)] [{:title "Delete Token" - :action #(st/emit! (dt/delete-token (:name selected-token-set) (:id token) (:name token)))} + :action #(st/emit! (dt/delete-token selected-token-set-id (:name token)))} {:title "Duplicate Token" - :action #(st/emit! (dt/duplicate-token (:id token)))} + :action #(st/emit! (dt/duplicate-token (:name token)))} {:title "Edit Token" :action (fn [event] - (let [{:keys [key fields]} modal - token (dt/get-token-data-from-token-id (:id token))] + (let [{:keys [key fields]} modal] (st/emit! dt/hide-token-context-menu) (dom/stop-propagation event) (modal/show! key {:x (.-clientX ^js event) @@ -303,7 +301,6 @@ (mf/defc token-context-menu-tree [{:keys [width] :as mdata}] - (js/console.log "mdata" mdata) (let [objects (mf/deref refs/workspace-page-objects) selected (mf/deref refs/selected-shapes) selected-shapes (into [] (keep (d/getf objects)) selected) diff --git a/frontend/src/app/main/ui/workspace/tokens/sets.cljs b/frontend/src/app/main/ui/workspace/tokens/sets.cljs index cbbf97ef6..c5f14a5b8 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sets.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sets.cljs @@ -93,7 +93,6 @@ (st/emit! (wdt/show-token-set-context-menu {:position (dom/get-client-position event) - :token-set-id name :token-set-name name})))))] [:div {:class (stl/css :set-item-container) :on-click on-select diff --git a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs index 3c1750858..8675954fc 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs @@ -96,7 +96,7 @@ (dom/stop-propagation event) (st/emit! (dt/show-token-context-menu {:type :token :position (dom/get-client-position event) - :token-id (:id token)})))) + :token-name (:name token)})))) on-toggle-open-click (mf/use-fn (mf/deps open? tokens) From 5d61ddb3856f1367a104cc98edd29709a74d19c5 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 30 Sep 2024 09:33:35 +0200 Subject: [PATCH 41/92] Fix property applying --- .../app/main/ui/workspace/tokens/changes.cljs | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/changes.cljs b/frontend/src/app/main/ui/workspace/tokens/changes.cljs index e1438da95..0ddd8c830 100644 --- a/frontend/src/app/main/ui/workspace/tokens/changes.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/changes.cljs @@ -8,19 +8,20 @@ (:require [app.common.types.shape.radius :as ctsr] [app.common.types.token :as ctt] - [app.main.data.workspace.colors :as wdc] + [app.common.types.tokens-lib :as ctob] [app.main.data.workspace :as udw] + [app.main.data.workspace.colors :as wdc] [app.main.data.workspace.shape-layout :as dwsl] [app.main.data.workspace.shapes :as dwsh] [app.main.data.workspace.state-helpers :as wsh] [app.main.data.workspace.transforms :as dwt] [app.main.data.workspace.undo :as dwu] [app.main.ui.workspace.tokens.style-dictionary :as sd] + [app.main.ui.workspace.tokens.tinycolor :as tinycolor] [app.main.ui.workspace.tokens.token :as wtt] [beicon.v2.core :as rx] [clojure.set :as set] - [potok.v2.core :as ptk] - [app.main.ui.workspace.tokens.tinycolor :as tinycolor])) + [potok.v2.core :as ptk])) ;; Token Updates --------------------------------------------------------------- @@ -34,21 +35,23 @@ (ptk/reify ::apply-token ptk/WatchEvent (watch [_ state _] - (->> (rx/from (sd/resolve-tokens+ (get-in state [:workspace-data :tokens]))) - (rx/mapcat - (fn [resolved-tokens] - (let [undo-id (js/Symbol) - resolved-value (get-in resolved-tokens [(wtt/token-identifier token) :resolved-value]) - tokenized-attributes (wtt/attributes-map attributes token)] - (rx/of - (dwu/start-undo-transaction undo-id) - (dwsh/update-shapes shape-ids (fn [shape] - (cond-> shape - attributes-to-remove (update :applied-tokens #(apply (partial dissoc %) attributes-to-remove)) - :always (update :applied-tokens merge tokenized-attributes)))) - (when on-update-shape - (on-update-shape resolved-value shape-ids attributes)) - (dwu/commit-undo-transaction undo-id))))))))) + (when-let [tokens (some-> (get-in state [:workspace-data :tokens-lib]) + (ctob/get-active-themes-set-tokens))] + (->> (rx/from (sd/resolve-tokens+ tokens)) + (rx/mapcat + (fn [resolved-tokens] + (let [undo-id (js/Symbol) + resolved-value (get-in resolved-tokens [(wtt/token-identifier token) :resolved-value]) + tokenized-attributes (wtt/attributes-map attributes token)] + (rx/of + (dwu/start-undo-transaction undo-id) + (dwsh/update-shapes shape-ids (fn [shape] + (cond-> shape + attributes-to-remove (update :applied-tokens #(apply (partial dissoc %) attributes-to-remove)) + :always (update :applied-tokens merge tokenized-attributes)))) + (when on-update-shape + (on-update-shape resolved-value shape-ids attributes)) + (dwu/commit-undo-transaction undo-id)))))))))) (defn unapply-token "Removes `attributes` that match `token` for `shape-ids`. From a49992a74e915ae9d0a0796ef458a281f0bde498 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 30 Sep 2024 09:38:01 +0200 Subject: [PATCH 42/92] Fix token updating --- .../src/app/main/ui/workspace/tokens/token_set.cljs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/token_set.cljs b/frontend/src/app/main/ui/workspace/tokens/token_set.cljs index 20ebb5d81..bbddbd0da 100644 --- a/frontend/src/app/main/ui/workspace/tokens/token_set.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/token_set.cljs @@ -75,17 +75,8 @@ (defn get-active-theme-sets-tokens-names-map [state] - (let [active-set-ids (get-ordered-active-set-ids state)] - (reduce - (fn [names-map-acc set-id] - (let [token-ids (get-workspace-token-set-tokens set-id state)] - (reduce - (fn [acc token-id] - (if-let [token (wtt/get-workspace-token token-id state)] - (assoc acc (wtt/token-identifier token) token) - acc)) - names-map-acc token-ids))) - (ordered-map) active-set-ids))) + (when-let [lib (get-workspace-tokens-lib state)] + (ctob/get-active-themes-set-tokens lib))) ;; === Set selection From 1194eb7c61a67de6137e2442da82dd9a6e490d4c Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 30 Sep 2024 09:39:11 +0200 Subject: [PATCH 43/92] Remove unused functions --- .../main/ui/workspace/tokens/token_set.cljs | 46 +------------------ 1 file changed, 1 insertion(+), 45 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/token_set.cljs b/frontend/src/app/main/ui/workspace/tokens/token_set.cljs index bbddbd0da..9e1af19c4 100644 --- a/frontend/src/app/main/ui/workspace/tokens/token_set.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/token_set.cljs @@ -1,50 +1,18 @@ (ns app.main.ui.workspace.tokens.token-set (:require - [app.common.data :refer [ordered-map]] - [app.common.types.tokens-lib :as ctob] - [app.main.ui.workspace.tokens.token :as wtt] - [clojure.set :as set])) + [app.common.types.tokens-lib :as ctob])) (defn get-workspace-tokens-lib [state] (get-in state [:workspace-data :tokens-lib])) ;; Themes ---------------------------------------------------------------------- -(defn get-workspace-themes-index [state] - (get-in state [:workspace-data :token-themes-index] {})) - -(defn get-workspace-token-set-groups [state] - (get-in state [:workspace-data :token-set-groups])) - (defn get-active-theme-ids [state] (get-in state [:workspace-data :token-active-themes] #{})) (defn get-temp-theme-id [state] (get-in state [:workspace-data :token-theme-temporary-id])) -(defn get-active-theme-ids-or-fallback [state] - (let [active-theme-ids (get-active-theme-ids state) - temp-theme-id (get-temp-theme-id state)] - (cond - (seq active-theme-ids) active-theme-ids - temp-theme-id #{temp-theme-id}))) - -(defn get-active-set-ids [state] - (let [active-theme-ids (get-active-theme-ids-or-fallback state) - themes-index (get-workspace-themes-index state) - active-set-ids (reduce - (fn [acc cur] - (if-let [sets (get-in themes-index [cur :sets])] - (set/union acc sets) - acc)) - #{} active-theme-ids)] - active-set-ids)) - -(defn get-ordered-active-set-ids [state] - (let [active-set-ids (get-active-set-ids state) - token-set-groups (get-workspace-token-set-groups state)] - (filter active-set-ids token-set-groups))) - (defn update-theme-id [state] (let [active-themes (get-active-theme-ids state) @@ -62,18 +30,6 @@ ;; Sets ------------------------------------------------------------------------ -(defn get-workspace-sets [state] - (get-in state [:workspace-data :token-sets-index])) - -(defn get-token-set [set-id state] - (some-> (get-workspace-sets state) - (get set-id))) - -(defn get-workspace-token-set-tokens [set-id state] - (-> (get-token-set set-id state) - :tokens)) - - (defn get-active-theme-sets-tokens-names-map [state] (when-let [lib (get-workspace-tokens-lib state)] (ctob/get-active-themes-set-tokens lib))) From df8f67b5d38e466515083a21d448b6fc265139d0 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 30 Sep 2024 13:52:50 +0200 Subject: [PATCH 44/92] Update workspace tokens --- frontend/src/app/main/data/tokens.cljs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index 91e90c325..e409f5f64 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -150,9 +150,11 @@ active-token-themes (some-> tokens-lib (ctob/toggle-theme-active? group name) (ctob/get-active-theme-paths)) - changes (pcb/update-active-token-themes (pcb/empty-changes it) active-token-themes prev-active-token-themes)] + changes (-> (pcb/empty-changes it) + (pcb/update-active-token-themes active-token-themes prev-active-token-themes))] (rx/of - (dch/commit-changes changes)))))) + (dch/commit-changes changes) + (wtu/update-workspace-tokens)))))) (defn delete-token-theme [group name] (ptk/reify ::delete-token-theme From c75ab61732e6a888d08511fd8703367eb12f87f2 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 30 Sep 2024 14:44:42 +0200 Subject: [PATCH 45/92] Fix renamed theme staying in active-themes --- common/src/app/common/types/tokens_lib.cljc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index b14951059..88eb76c72 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -487,16 +487,21 @@ (let [theme' (-> (make-token-theme (f theme)) (assoc :modified-at (dt/now))) group' (:group theme') - name' (:name theme')] + name' (:name theme') + same-group? (= group group') + same-name? (= name name') + same-path? (and same-group? same-name?)] (check-token-theme! theme') (TokensLib. sets set-groups - (if (and (= group group') (= name name')) + (if same-path? (update themes group' assoc name' theme') (-> themes (d/oassoc-in-before [group name] [group' name'] theme') (d/dissoc-in [group name]))) - active-themes)) + (if same-path? + active-themes + (disj active-themes (token-theme-path group name))))) this))) (delete-theme [_ group name] From 18d120bbaa40735355fad82efdbb3c2e2554bbef Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 30 Sep 2024 15:04:12 +0200 Subject: [PATCH 46/92] Fix token creation without set --- frontend/src/app/main/data/tokens.cljs | 9 ++++----- frontend/src/app/main/ui/workspace/tokens/form.cljs | 11 +++++------ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index e409f5f64..fe4d864d1 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -246,19 +246,18 @@ (ptk/reify ::update-create-token ptk/WatchEvent (watch [_ state _] - (let [tlib (get-tokens-lib state) - token-set (wtts/get-selected-token-set state) + (let [token-set (wtts/get-selected-token-set state) + token-set-name (or (:name token-set) "Global") changes (if (not token-set) ;; No set created add a global set - (->> (ctob/make-token-set tlib :name "Global") - (ctob/add-token token) + (->> (ctob/make-token-set :name token-set-name :tokens {(:name token) token}) (pcb/add-token-set (pcb/empty-changes))) ;; Either update or add token to existing set (if-let [prev-token (ctob/get-token token-set (:name token))] (pcb/update-token (pcb/empty-changes) (:name token-set) token prev-token) (pcb/add-token (pcb/empty-changes) (:name token-set) token)))] (rx/of - (set-selected-token-set-id (:name token-set)) + (set-selected-token-set-id token-set-name) (dch/commit-changes changes)))))) (defn delete-token diff --git a/frontend/src/app/main/ui/workspace/tokens/form.cljs b/frontend/src/app/main/ui/workspace/tokens/form.cljs index ac90d9a42..d47811c3d 100644 --- a/frontend/src/app/main/ui/workspace/tokens/form.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/form.cljs @@ -10,6 +10,7 @@ ["lodash.debounce" :as debounce] [app.common.colors :as c] [app.common.data :as d] + [app.common.types.tokens-lib :as ctob] [app.main.data.modal :as modal] [app.main.data.tokens :as dt] [app.main.refs :as refs] @@ -25,7 +26,6 @@ [app.main.ui.workspace.tokens.update :as wtu] [app.util.dom :as dom] [cuerdas.core :as str] - [linked.map :as lkm] [malli.core :as m] [malli.error :as me] [promesa.core :as p] @@ -317,11 +317,10 @@ Token names should only contain letters and digits separated by . characters.")} ;; The result should be a vector of all resolved validations ;; We do not handle the error case as it will be handled by the components validations (when (and (seq result) (not err)) - (let [new-token (cond-> {:name final-name - :type (or (:type token) token-type) - :value final-value} - final-description (assoc :description final-description) - (:id token) (assoc :id (:id token)))] + (let [new-token (ctob/make-token :name final-name + :type (or (:type token) token-type) + :value final-value + :description final-description)] (st/emit! (dt/update-create-token new-token)) (st/emit! (wtu/update-workspace-tokens)) (modal/hide!)))))))))] From dc0a1c1555db67de73f625c6a1520d0630b0e168 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 30 Sep 2024 15:07:22 +0200 Subject: [PATCH 47/92] Cleanup --- frontend/src/app/main/data/tokens.cljs | 35 -------------------------- 1 file changed, 35 deletions(-) diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index fe4d864d1..9b0d59191 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -12,7 +12,6 @@ [app.common.geom.point :as gpt] [app.common.types.shape :as cts] [app.common.types.tokens-lib :as ctob] - [app.common.uuid :as uuid] [app.main.data.changes :as dch] [app.main.data.workspace.shapes :as dwsh] [app.main.refs :as refs] @@ -89,11 +88,6 @@ (let [workspace-data (deref refs/workspace-data)] (get (:tokens workspace-data) id))) -(defn get-token-set-data-from-token-set-id - [id] - (let [workspace-data (deref refs/workspace-data)] - (get (:token-sets-index workspace-data) id))) - (defn set-selected-token-set-id [id] (ptk/reify ::set-selected-token-set-id @@ -101,10 +95,6 @@ (update [_ state] (wtts/assoc-selected-token-set-id state id)))) -(defn get-token-set-tokens - [token-set file] - (map #(get-in file [:tokens %]) (:tokens token-set))) - (defn create-token-theme [token-theme] (let [new-token-theme token-theme] (ptk/reify ::create-token-theme @@ -125,21 +115,6 @@ (rx/of (dch/commit-changes changes)))))) -(defn ensure-token-theme-changes [changes state {:keys [id new-set?]}] - (let [theme-id (wtts/update-theme-id state) - theme (some-> theme-id (wtts/get-workspace-token-theme state))] - (cond - (not theme-id) (-> changes - (pcb/add-temporary-token-theme - {:id (uuid/next) - :name "Test theme" - :sets #{id}})) - new-set? (-> changes - (pcb/update-token-theme - (wtts/add-token-set-to-token-theme id theme) - theme)) - :else changes))) - (defn toggle-token-theme-active? [group name] (ptk/reify ::toggle-token-theme-active? ptk/WatchEvent @@ -195,16 +170,6 @@ (rx/of (dch/commit-changes changes)))))) -#_[target-theme-id (wtts/get-temp-theme-id state) - active-set-ids (wtts/get-active-set-ids state) - theme (-> (wtts/get-workspace-token-theme target-theme-id state) - (assoc :sets active-set-ids)) - changes (-> (pcb/empty-changes it) - (pcb/update-token-theme - (wtts/toggle-token-set-to-token-theme token-set-id theme) - theme) - (pcb/update-active-token-themes #{target-theme-id} (wtts/get-active-theme-ids state)))] - (defn toggle-token-set [{:keys [token-set-name]}] (ptk/reify ::toggle-token-set ptk/WatchEvent From 3182ff1e15294cca5e7f900b94c28054b31ab8e0 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 30 Sep 2024 15:08:18 +0200 Subject: [PATCH 48/92] Cleanup --- frontend/src/app/main/ui/workspace/tokens/token.cljs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/token.cljs b/frontend/src/app/main/ui/workspace/tokens/token.cljs index 49427bee9..c55f5c60f 100644 --- a/frontend/src/app/main/ui/workspace/tokens/token.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/token.cljs @@ -6,10 +6,6 @@ [clojure.set :as set] [cuerdas.core :as str])) -(defn get-workspace-token - [token-id state] - (get-in state [:workspace-data :tokens token-id])) - (def parseable-token-value-regexp "Regexp that can be used to parse a number value out of resolved token value. This regexp also trims whitespace around the value." From b0d46e17674ce86578918cbefb49f3e4a5d24cec Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 30 Sep 2024 15:15:05 +0200 Subject: [PATCH 49/92] Cleanup --- frontend/src/app/main/ui/workspace/tokens/sidebar.cljs | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs index 8675954fc..5f1ed3a06 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs @@ -106,7 +106,6 @@ (let [{:keys [key fields]} modal] (dom/stop-propagation event) (st/emit! (dt/set-token-type-section-open type true)) - (js/console.log "key" key) (modal/show! key {:x (.-clientX ^js event) :y (.-clientY ^js event) :position :right From bfa90d0347f3f5ff38e82585ca0a2d14c8f2becd Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 30 Sep 2024 15:18:26 +0200 Subject: [PATCH 50/92] Fix duplicate token event --- frontend/src/app/main/data/tokens.cljs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index 9b0d59191..79d771671 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -239,11 +239,16 @@ (rx/of (dch/commit-changes changes)))))) (defn duplicate-token - [id] - (let [new-token (-> (get-token-data-from-token-id id) - (dissoc :id) - (update :name #(str/concat % "-copy")))] - (update-create-token new-token))) + [token-name] + (dm/assert! (string? token-name)) + (ptk/reify ::duplicate-token + ptk/WatchEvent + (watch [_ state _] + (when-let [token (some-> (wtts/get-selected-token-set state) + (ctob/get-token token-name) + (update :name #(str/concat % "-copy")))] + (rx/of + (update-create-token token)))))) (defn set-token-type-section-open [token-type open?] From 0ea0834b1aaec2252c2d77f30f2117f4c083bf0f Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 30 Sep 2024 15:21:15 +0200 Subject: [PATCH 51/92] Cleanup --- frontend/src/app/main/ui/workspace/tokens/theme_select.cljs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs b/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs index 720998d8c..2805949b7 100644 --- a/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs @@ -7,7 +7,6 @@ (ns app.main.ui.workspace.tokens.theme-select (:require-macros [app.main.style :as stl]) (:require - [app.common.data.macros :as dm] [app.common.types.tokens-lib :as ctob] [app.common.uuid :as uuid] [app.main.data.modal :as modal] @@ -17,8 +16,8 @@ [app.main.ui.components.dropdown :refer [dropdown]] [app.main.ui.icons :as i] [app.util.dom :as dom] - [rumext.v2 :as mf] - [cuerdas.core :as str])) + [cuerdas.core :as str] + [rumext.v2 :as mf])) (mf/defc themes-list [{:keys [themes active-theme-paths on-close grouped?]}] From c5173d2df8be6ea90c6680c8b655851f30879d70 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 30 Sep 2024 15:33:17 +0200 Subject: [PATCH 52/92] Remove hidden token theme when activating a theme --- frontend/src/app/main/data/tokens.cljs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index 79d771671..4c87649d3 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -125,8 +125,11 @@ active-token-themes (some-> tokens-lib (ctob/toggle-theme-active? group name) (ctob/get-active-theme-paths)) + active-token-themes' (if (= active-token-themes #{ctob/hidden-token-theme-path}) + active-token-themes + (disj active-token-themes ctob/hidden-token-theme-path)) changes (-> (pcb/empty-changes it) - (pcb/update-active-token-themes active-token-themes prev-active-token-themes))] + (pcb/update-active-token-themes active-token-themes' prev-active-token-themes))] (rx/of (dch/commit-changes changes) (wtu/update-workspace-tokens)))))) From 4b39b6970a17421828b1d1d0861f79cb57e2c8d0 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 30 Sep 2024 16:26:26 +0200 Subject: [PATCH 53/92] Fix theme sets not being in order of the root order --- common/src/app/common/types/tokens_lib.cljc | 22 +++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index 88eb76c72..efe84abf6 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -227,6 +227,7 @@ (set-count [_] "get the total number if sets in the library") (get-set-tree [_] "get a nested tree of all sets in the library") (get-sets [_] "get an ordered sequence of all sets in the library") + (get-sets-order [_] "get an ordered sequence of all sets in the library") (get-set [_ set-name] "get one set looking for name") (get-set-group [_ set-group-path] "get the attributes of a set group")) @@ -463,6 +464,9 @@ (->> (tree-seq d/ordered-map? vals sets) (filter (partial instance? TokenSet)))) + (get-sets-order [this] + (map :name (get-sets this))) + (set-count [this] (count (get-sets this))) @@ -616,14 +620,16 @@ (get-active-themes this))) (get-active-themes-set-tokens [this] - (reduce - (fn [acc cur] - (if (theme-active? this (:group cur) (:name cur)) - (into acc - (->> (get cur :sets) - (map #(-> (get-set this %) :tokens)))) - acc)) - (d/ordered-map) (tree-seq d/ordered-map? vals themes))) + (let [sets-order (get-sets-order this)] + (reduce + (fn [acc cur] + (reduce + (fn [acc cur] + (merge acc (:tokens (get-set this cur)))) + acc + (let [ref-set (set (:sets cur))] + (filter #(contains? ref-set %) sets-order)))) + (d/ordered-map) (get-active-themes this)))) (update-set-name [_ old-set-name new-set-name] (TokensLib. sets From 231baac31dc44f8c7438d4711fc63a8d383385d0 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 30 Sep 2024 16:41:51 +0200 Subject: [PATCH 54/92] Fix renaming token creating new token --- frontend/src/app/main/data/tokens.cljs | 6 +++--- .../src/app/main/ui/workspace/tokens/form.cljs | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index 4c87649d3..bbd355337 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -210,7 +210,7 @@ (wtu/update-workspace-tokens)))))) (defn update-create-token - [token] + [{:keys [token prev-token-name]}] (ptk/reify ::update-create-token ptk/WatchEvent (watch [_ state _] @@ -221,7 +221,7 @@ (->> (ctob/make-token-set :name token-set-name :tokens {(:name token) token}) (pcb/add-token-set (pcb/empty-changes))) ;; Either update or add token to existing set - (if-let [prev-token (ctob/get-token token-set (:name token))] + (if-let [prev-token (ctob/get-token token-set (or prev-token-name (:name token)))] (pcb/update-token (pcb/empty-changes) (:name token-set) token prev-token) (pcb/add-token (pcb/empty-changes) (:name token-set) token)))] (rx/of @@ -251,7 +251,7 @@ (ctob/get-token token-name) (update :name #(str/concat % "-copy")))] (rx/of - (update-create-token token)))))) + (update-create-token {:token token})))))) (defn set-token-type-section-open [token-type open?] diff --git a/frontend/src/app/main/ui/workspace/tokens/form.cljs b/frontend/src/app/main/ui/workspace/tokens/form.cljs index d47811c3d..3bb0339f4 100644 --- a/frontend/src/app/main/ui/workspace/tokens/form.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/form.cljs @@ -317,13 +317,13 @@ Token names should only contain letters and digits separated by . characters.")} ;; The result should be a vector of all resolved validations ;; We do not handle the error case as it will be handled by the components validations (when (and (seq result) (not err)) - (let [new-token (ctob/make-token :name final-name - :type (or (:type token) token-type) - :value final-value - :description final-description)] - (st/emit! (dt/update-create-token new-token)) - (st/emit! (wtu/update-workspace-tokens)) - (modal/hide!)))))))))] + (st/emit! (dt/update-create-token {:token (ctob/make-token :name final-name + :type (or (:type token) token-type) + :value final-value + :description final-description) + :prev-token-name (:name token)})) + (st/emit! (wtu/update-workspace-tokens)) + (modal/hide!))))))))] [:form {:class (stl/css :form-wrapper) :on-submit on-submit} From 0d870610e189c2a4334ecedf02c7219c8e5c8770 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Tue, 1 Oct 2024 09:14:54 +0200 Subject: [PATCH 55/92] Fix infer warnings in tokens test --- frontend/src/app/main/ui/components/tab_container.cljs | 2 ++ frontend/src/app/main/ui/workspace/tokens/tinycolor.cljs | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/main/ui/components/tab_container.cljs b/frontend/src/app/main/ui/components/tab_container.cljs index 1e3b99079..0d39e93d8 100644 --- a/frontend/src/app/main/ui/components/tab_container.cljs +++ b/frontend/src/app/main/ui/components/tab_container.cljs @@ -16,6 +16,8 @@ [cuerdas.core :as str] [rumext.v2 :as mf])) +(set! *warn-on-infer* false) + (mf/defc tab-element {::mf/wrap-props false} [{:keys [children]}] diff --git a/frontend/src/app/main/ui/workspace/tokens/tinycolor.cljs b/frontend/src/app/main/ui/workspace/tokens/tinycolor.cljs index 91fac6bdf..9a8d74f10 100644 --- a/frontend/src/app/main/ui/workspace/tokens/tinycolor.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/tinycolor.cljs @@ -6,18 +6,18 @@ (:require ["tinycolor2" :as tinycolor])) -(defn tinycolor? [x] +(defn tinycolor? [^js x] (and (instance? tinycolor x) (.isValid x))) (defn valid-color [color-str] (let [tc (tinycolor color-str)] (when (.isValid tc) tc))) -(defn ->hex [tc] +(defn ->hex [^js tc] (assert (tinycolor? tc)) (.toHex tc)) -(defn color-format [tc] +(defn color-format [^js tc] (assert (tinycolor? tc)) (.getFormat tc)) From 442732117bf8e135001a2ba3a576f41d4aff9f9d Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Tue, 1 Oct 2024 09:55:23 +0200 Subject: [PATCH 56/92] Disable logic tests for now (nee new setup) --- .../token_tests/logic/token_actions_test.cljs | 710 +++++++++--------- 1 file changed, 337 insertions(+), 373 deletions(-) diff --git a/frontend/test/token_tests/logic/token_actions_test.cljs b/frontend/test/token_tests/logic/token_actions_test.cljs index c95af99a2..77a3530fe 100644 --- a/frontend/test/token_tests/logic/token_actions_test.cljs +++ b/frontend/test/token_tests/logic/token_actions_test.cljs @@ -15,6 +15,7 @@ [token-tests.helpers.state :as tohs] [token-tests.helpers.tokens :as toht])) + (t/use-fixtures :each {:before (fn [] ;; Ignore rxjs async errors @@ -29,400 +30,363 @@ :name "borderRadius.sm" :type :border-radius}) -(def ^:private reference-border-radius-token +(def reference-border-radius-token {:value "{borderRadius.sm} * 2" :name "borderRadius.md" :type :border-radius}) -(defn setup-file-with-tokens - [& {:keys [rect-1 rect-2 rect-3]}] - (-> (setup-file) - (ctho/add-rect :rect-1 rect-1) - (ctho/add-rect :rect-2 rect-2) - (ctho/add-rect :rect-3 rect-3) - (toht/add-token :token-1 border-radius-token) - (toht/add-token :token-2 reference-border-radius-token))) +;; (defn setup-file-with-tokens +;; [& {:keys [rect-1 rect-2 rect-3]}] +;; (-> (setup-file) +;; (ctho/add-rect :rect-1 rect-1) +;; (ctho/add-rect :rect-2 rect-2) +;; (ctho/add-rect :rect-3 rect-3) +;; (toht/add-token :token-1 border-radius-token) +;; (toht/add-token :token-2 reference-border-radius-token))) -(t/deftest test-create-token - (t/testing "creates token in new token set" - (t/async - done - (let [file (setup-file) - store (ths/setup-store file) - events [(wdt/update-create-token border-radius-token)]] - (tohs/run-store-async - store done events - (fn [new-state] - (let [set-id (wtts/get-selected-token-set-id new-state) - token-set (wtts/get-token-set set-id new-state) - set-tokens (wtts/get-active-theme-sets-tokens-names-map new-state)] - (t/testing "selects created workspace set and adds token to it" - (t/is (some? token-set)) - (t/is (= 1 (count set-tokens))) - (t/is (= (list border-radius-token) (->> (vals set-tokens) - (map #(dissoc % :id :modified-at))))))))))))) +;; (t/deftest test-apply-token +;; (t/testing "applies token to shape and updates shape attributes to resolved value" +;; (t/async +;; done +;; (let [file (setup-file-with-tokens) +;; store (ths/setup-store file) +;; rect-1 (cths/get-shape file :rect-1) +;; events [(wtch/apply-token {:shape-ids [(:id rect-1)] +;; :attributes #{:rx :ry} +;; :token (toht/get-token file :token-2) +;; :on-update-shape wtch/update-shape-radius-all})]] +;; (tohs/run-store-async +;; store done events +;; (fn [new-state] +;; (let [file' (ths/get-file-from-store new-state) +;; token-2' (toht/get-token file' :token-2) +;; rect-1' (cths/get-shape file' :rect-1)] +;; (t/testing "shape `:applied-tokens` got updated" +;; (t/is (some? (:applied-tokens rect-1'))) +;; (t/is (= (:rx (:applied-tokens rect-1')) (wtt/token-identifier token-2'))) +;; (t/is (= (:ry (:applied-tokens rect-1')) (wtt/token-identifier token-2')))) +;; (t/testing "shape radius got update to the resolved token value." +;; (t/is (= (:rx rect-1') 24)) +;; (t/is (= (:ry rect-1') 24)))))))))) -(t/deftest test-create-multiple-tokens - (t/testing "uses selected tokens set when creating multiple tokens" - (t/async - done - (let [file (setup-file) - store (ths/setup-store file) - events [(wdt/update-create-token border-radius-token) - (wdt/update-create-token reference-border-radius-token)]] - (tohs/run-store-async - store done events - (fn [new-state] - (let [set-tokens (wtts/get-active-theme-sets-tokens-names-map new-state)] - (t/testing "selects created workspace set and adds token to it" - (t/is (= 2 (count set-tokens))) - (t/is (= (list border-radius-token reference-border-radius-token) - (->> (vals set-tokens) - (map #(dissoc % :id :modified-at))))))))))))) +;; (t/deftest test-apply-multiple-tokens +;; (t/testing "applying a token twice with the same attributes will override the previously applied tokens values" +;; (t/async +;; done +;; (let [file (setup-file-with-tokens) +;; store (ths/setup-store file) +;; rect-1 (cths/get-shape file :rect-1) +;; events [(wtch/apply-token {:shape-ids [(:id rect-1)] +;; :attributes #{:rx :ry} +;; :token (toht/get-token file :token-1) +;; :on-update-shape wtch/update-shape-radius-all}) +;; (wtch/apply-token {:shape-ids [(:id rect-1)] +;; :attributes #{:rx :ry} +;; :token (toht/get-token file :token-2) +;; :on-update-shape wtch/update-shape-radius-all})]] +;; (tohs/run-store-async +;; store done events +;; (fn [new-state] +;; (let [file' (ths/get-file-from-store new-state) +;; token-2' (toht/get-token file' :token-2) +;; rect-1' (cths/get-shape file' :rect-1)] +;; (t/testing "shape `:applied-tokens` got updated" +;; (t/is (some? (:applied-tokens rect-1'))) +;; (t/is (= (:rx (:applied-tokens rect-1')) (wtt/token-identifier token-2'))) +;; (t/is (= (:ry (:applied-tokens rect-1')) (wtt/token-identifier token-2')))) +;; (t/testing "shape radius got update to the resolved token value." +;; (t/is (= (:rx rect-1') 24)) +;; (t/is (= (:ry rect-1') 24)))))))))) -(t/deftest test-apply-token - (t/testing "applies token to shape and updates shape attributes to resolved value" - (t/async - done - (let [file (setup-file-with-tokens) - store (ths/setup-store file) - rect-1 (cths/get-shape file :rect-1) - events [(wtch/apply-token {:shape-ids [(:id rect-1)] - :attributes #{:rx :ry} - :token (toht/get-token file :token-2) - :on-update-shape wtch/update-shape-radius-all})]] - (tohs/run-store-async - store done events - (fn [new-state] - (let [file' (ths/get-file-from-store new-state) - token-2' (toht/get-token file' :token-2) - rect-1' (cths/get-shape file' :rect-1)] - (t/testing "shape `:applied-tokens` got updated" - (t/is (some? (:applied-tokens rect-1'))) - (t/is (= (:rx (:applied-tokens rect-1')) (wtt/token-identifier token-2'))) - (t/is (= (:ry (:applied-tokens rect-1')) (wtt/token-identifier token-2')))) - (t/testing "shape radius got update to the resolved token value." - (t/is (= (:rx rect-1') 24)) - (t/is (= (:ry rect-1') 24)))))))))) +;; (t/deftest test-apply-token-overwrite +;; (t/testing "removes old token attributes and applies only single attribute" +;; (t/async +;; done +;; (let [file (setup-file-with-tokens) +;; store (ths/setup-store file) +;; rect-1 (cths/get-shape file :rect-1) +;; events [;; Apply `:token-1` to all border radius attributes +;; (wtch/apply-token {:attributes #{:rx :ry :r1 :r2 :r3 :r4} +;; :token (toht/get-token file :token-1) +;; :shape-ids [(:id rect-1)] +;; :on-update-shape wtch/update-shape-radius-all}) +;; ;; Apply single `:r1` attribute to same shape +;; ;; while removing other attributes from the border-radius set +;; ;; but keep `:r4` for testing purposes +;; (wtch/apply-token {:attributes #{:r1} +;; :attributes-to-remove #{:rx :ry :r1 :r2 :r3} +;; :token (toht/get-token file :token-2) +;; :shape-ids [(:id rect-1)] +;; :on-update-shape wtch/update-shape-radius-all})]] +;; (tohs/run-store-async +;; store done events +;; (fn [new-state] +;; (let [file' (ths/get-file-from-store new-state) +;; token-1' (toht/get-token file' :token-1) +;; token-2' (toht/get-token file' :token-2) +;; rect-1' (cths/get-shape file' :rect-1)] +;; (t/testing "other border-radius attributes got removed" +;; (t/is (nil? (:rx (:applied-tokens rect-1'))))) +;; (t/testing "r1 got applied with :token-2" +;; (t/is (= (:r1 (:applied-tokens rect-1')) (wtt/token-identifier token-2')))) +;; (t/testing "while :r4 was kept" +;; (t/is (= (:r4 (:applied-tokens rect-1')) (wtt/token-identifier token-1')))))))))));))))))))))) -(t/deftest test-apply-multiple-tokens - (t/testing "applying a token twice with the same attributes will override the previously applied tokens values" - (t/async - done - (let [file (setup-file-with-tokens) - store (ths/setup-store file) - rect-1 (cths/get-shape file :rect-1) - events [(wtch/apply-token {:shape-ids [(:id rect-1)] - :attributes #{:rx :ry} - :token (toht/get-token file :token-1) - :on-update-shape wtch/update-shape-radius-all}) - (wtch/apply-token {:shape-ids [(:id rect-1)] - :attributes #{:rx :ry} - :token (toht/get-token file :token-2) - :on-update-shape wtch/update-shape-radius-all})]] - (tohs/run-store-async - store done events - (fn [new-state] - (let [file' (ths/get-file-from-store new-state) - token-2' (toht/get-token file' :token-2) - rect-1' (cths/get-shape file' :rect-1)] - (t/testing "shape `:applied-tokens` got updated" - (t/is (some? (:applied-tokens rect-1'))) - (t/is (= (:rx (:applied-tokens rect-1')) (wtt/token-identifier token-2'))) - (t/is (= (:ry (:applied-tokens rect-1')) (wtt/token-identifier token-2')))) - (t/testing "shape radius got update to the resolved token value." - (t/is (= (:rx rect-1') 24)) - (t/is (= (:ry rect-1') 24)))))))))) +;; (t/deftest test-apply-dimensions +;; (t/testing "applies dimensions token and updates the shapes width and height" +;; (t/async +;; done +;; (let [file (-> (setup-file-with-tokens) +;; (toht/add-token :token-target {:value "100" +;; :name "dimensions.sm" +;; :type :dimensions})) +;; store (ths/setup-store file) +;; rect-1 (cths/get-shape file :rect-1) +;; events [(wtch/apply-token {:shape-ids [(:id rect-1)] +;; :attributes #{:width :height} +;; :token (toht/get-token file :token-target) +;; :on-update-shape wtch/update-shape-dimensions})]] +;; (tohs/run-store-async +;; store done events +;; (fn [new-state] +;; (let [file' (ths/get-file-from-store new-state) +;; token-target' (toht/get-token file' :token-target) +;; rect-1' (cths/get-shape file' :rect-1)] +;; (t/testing "shape `:applied-tokens` got updated" +;; (t/is (some? (:applied-tokens rect-1'))) +;; (t/is (= (:width (:applied-tokens rect-1')) (wtt/token-identifier token-target'))) +;; (t/is (= (:height (:applied-tokens rect-1')) (wtt/token-identifier token-target')))) +;; (t/testing "shapes width and height got updated" +;; (t/is (= (:width rect-1') 100)) +;; (t/is (= (:height rect-1') 100)))))))))) -(t/deftest test-apply-token-overwrite - (t/testing "removes old token attributes and applies only single attribute" - (t/async - done - (let [file (setup-file-with-tokens) - store (ths/setup-store file) - rect-1 (cths/get-shape file :rect-1) - events [;; Apply `:token-1` to all border radius attributes - (wtch/apply-token {:attributes #{:rx :ry :r1 :r2 :r3 :r4} - :token (toht/get-token file :token-1) - :shape-ids [(:id rect-1)] - :on-update-shape wtch/update-shape-radius-all}) - ;; Apply single `:r1` attribute to same shape - ;; while removing other attributes from the border-radius set - ;; but keep `:r4` for testing purposes - (wtch/apply-token {:attributes #{:r1} - :attributes-to-remove #{:rx :ry :r1 :r2 :r3} - :token (toht/get-token file :token-2) - :shape-ids [(:id rect-1)] - :on-update-shape wtch/update-shape-radius-all})]] - (tohs/run-store-async - store done events - (fn [new-state] - (let [file' (ths/get-file-from-store new-state) - token-1' (toht/get-token file' :token-1) - token-2' (toht/get-token file' :token-2) - rect-1' (cths/get-shape file' :rect-1)] - (t/testing "other border-radius attributes got removed" - (t/is (nil? (:rx (:applied-tokens rect-1'))))) - (t/testing "r1 got applied with :token-2" - (t/is (= (:r1 (:applied-tokens rect-1')) (wtt/token-identifier token-2')))) - (t/testing "while :r4 was kept" - (t/is (= (:r4 (:applied-tokens rect-1')) (wtt/token-identifier token-1')))))))))));))))))))))) +;; (t/deftest test-apply-sizing +;; (t/testing "applies sizing token and updates the shapes width and height" +;; (t/async +;; done +;; (let [file (-> (setup-file-with-tokens) +;; (toht/add-token :token-target {:value "100" +;; :name "sizing.sm" +;; :type :sizing})) +;; store (ths/setup-store file) +;; rect-1 (cths/get-shape file :rect-1) +;; events [(wtch/apply-token {:shape-ids [(:id rect-1)] +;; :attributes #{:width :height} +;; :token (toht/get-token file :token-target) +;; :on-update-shape wtch/update-shape-dimensions})]] +;; (tohs/run-store-async +;; store done events +;; (fn [new-state] +;; (let [file' (ths/get-file-from-store new-state) +;; token-target' (toht/get-token file' :token-target) +;; rect-1' (cths/get-shape file' :rect-1)] +;; (t/testing "shape `:applied-tokens` got updated" +;; (t/is (some? (:applied-tokens rect-1'))) +;; (t/is (= (:width (:applied-tokens rect-1')) (wtt/token-identifier token-target'))) +;; (t/is (= (:height (:applied-tokens rect-1')) (wtt/token-identifier token-target')))) +;; (t/testing "shapes width and height got updated" +;; (t/is (= (:width rect-1') 100)) +;; (t/is (= (:height rect-1') 100)))))))))) -(t/deftest test-apply-dimensions - (t/testing "applies dimensions token and updates the shapes width and height" - (t/async - done - (let [file (-> (setup-file-with-tokens) - (toht/add-token :token-target {:value "100" - :name "dimensions.sm" - :type :dimensions})) - store (ths/setup-store file) - rect-1 (cths/get-shape file :rect-1) - events [(wtch/apply-token {:shape-ids [(:id rect-1)] - :attributes #{:width :height} - :token (toht/get-token file :token-target) - :on-update-shape wtch/update-shape-dimensions})]] - (tohs/run-store-async - store done events - (fn [new-state] - (let [file' (ths/get-file-from-store new-state) - token-target' (toht/get-token file' :token-target) - rect-1' (cths/get-shape file' :rect-1)] - (t/testing "shape `:applied-tokens` got updated" - (t/is (some? (:applied-tokens rect-1'))) - (t/is (= (:width (:applied-tokens rect-1')) (wtt/token-identifier token-target'))) - (t/is (= (:height (:applied-tokens rect-1')) (wtt/token-identifier token-target')))) - (t/testing "shapes width and height got updated" - (t/is (= (:width rect-1') 100)) - (t/is (= (:height rect-1') 100)))))))))) +;; (t/deftest test-apply-opacity +;; (t/testing "applies opacity token and updates the shapes opacity" +;; (t/async +;; done +;; (let [file (-> (setup-file-with-tokens) +;; (toht/add-token :opacity-float {:value "0.3" +;; :name "opacity.float" +;; :type :opacity}) +;; (toht/add-token :opacity-percent {:value "40%" +;; :name "opacity.percent" +;; :type :opacity}) +;; (toht/add-token :opacity-invalid {:value "100" +;; :name "opacity.invalid" +;; :type :opacity})) +;; store (ths/setup-store file) +;; rect-1 (cths/get-shape file :rect-1) +;; rect-2 (cths/get-shape file :rect-2) +;; rect-3 (cths/get-shape file :rect-3) +;; events [(wtch/apply-token {:shape-ids [(:id rect-1)] +;; :attributes #{:opacity} +;; :token (toht/get-token file :opacity-float) +;; :on-update-shape wtch/update-opacity}) +;; (wtch/apply-token {:shape-ids [(:id rect-2)] +;; :attributes #{:opacity} +;; :token (toht/get-token file :opacity-percent) +;; :on-update-shape wtch/update-opacity}) +;; (wtch/apply-token {:shape-ids [(:id rect-3)] +;; :attributes #{:opacity} +;; :token (toht/get-token file :opacity-invalid) +;; :on-update-shape wtch/update-opacity})]] +;; (tohs/run-store-async +;; store done events +;; (fn [new-state] +;; (let [file' (ths/get-file-from-store new-state) +;; rect-1' (cths/get-shape file' :rect-1) +;; rect-2' (cths/get-shape file' :rect-2) +;; rect-3' (cths/get-shape file' :rect-3) +;; token-opacity-float (toht/get-token file' :opacity-float) +;; token-opacity-percent (toht/get-token file' :opacity-percent) +;; token-opacity-invalid (toht/get-token file' :opacity-invalid)] +;; (t/testing "float value got translated to float and applied to opacity" +;; (t/is (= (:opacity (:applied-tokens rect-1')) (wtt/token-identifier token-opacity-float))) +;; (t/is (= (:opacity rect-1') 0.3))) +;; (t/testing "percentage value got translated to float and applied to opacity" +;; (t/is (= (:opacity (:applied-tokens rect-2')) (wtt/token-identifier token-opacity-percent))) +;; (t/is (= (:opacity rect-2') 0.4))) +;; (t/testing "invalid opacity value got applied but did not change shape" +;; (t/is (= (:opacity (:applied-tokens rect-3')) (wtt/token-identifier token-opacity-invalid))) +;; (t/is (nil? (:opacity rect-3'))))))))))) -(t/deftest test-apply-sizing - (t/testing "applies sizing token and updates the shapes width and height" - (t/async - done - (let [file (-> (setup-file-with-tokens) - (toht/add-token :token-target {:value "100" - :name "sizing.sm" - :type :sizing})) - store (ths/setup-store file) - rect-1 (cths/get-shape file :rect-1) - events [(wtch/apply-token {:shape-ids [(:id rect-1)] - :attributes #{:width :height} - :token (toht/get-token file :token-target) - :on-update-shape wtch/update-shape-dimensions})]] - (tohs/run-store-async - store done events - (fn [new-state] - (let [file' (ths/get-file-from-store new-state) - token-target' (toht/get-token file' :token-target) - rect-1' (cths/get-shape file' :rect-1)] - (t/testing "shape `:applied-tokens` got updated" - (t/is (some? (:applied-tokens rect-1'))) - (t/is (= (:width (:applied-tokens rect-1')) (wtt/token-identifier token-target'))) - (t/is (= (:height (:applied-tokens rect-1')) (wtt/token-identifier token-target')))) - (t/testing "shapes width and height got updated" - (t/is (= (:width rect-1') 100)) - (t/is (= (:height rect-1') 100)))))))))) +;; (t/deftest test-apply-rotation +;; (t/testing "applies rotation token and updates the shapes rotation" +;; (t/async +;; done +;; (let [file (-> (setup-file-with-tokens) +;; (toht/add-token :token-target {:value "120" +;; :name "rotation.medium" +;; :type :rotation})) +;; store (ths/setup-store file) +;; rect-1 (cths/get-shape file :rect-1) +;; events [(wtch/apply-token {:shape-ids [(:id rect-1)] +;; :attributes #{:rotation} +;; :token (toht/get-token file :token-target) +;; :on-update-shape wtch/update-rotation})]] +;; (tohs/run-store-async +;; store done events +;; (fn [new-state] +;; (let [file' (ths/get-file-from-store new-state) +;; token-target' (toht/get-token file' :token-target) +;; rect-1' (cths/get-shape file' :rect-1)] +;; (t/is (some? (:applied-tokens rect-1'))) +;; (t/is (= (:rotation (:applied-tokens rect-1')) (wtt/token-identifier token-target'))) +;; (t/is (= (:rotation rect-1') 120))))))))) -(t/deftest test-apply-opacity - (t/testing "applies opacity token and updates the shapes opacity" - (t/async - done - (let [file (-> (setup-file-with-tokens) - (toht/add-token :opacity-float {:value "0.3" - :name "opacity.float" - :type :opacity}) - (toht/add-token :opacity-percent {:value "40%" - :name "opacity.percent" - :type :opacity}) - (toht/add-token :opacity-invalid {:value "100" - :name "opacity.invalid" - :type :opacity})) - store (ths/setup-store file) - rect-1 (cths/get-shape file :rect-1) - rect-2 (cths/get-shape file :rect-2) - rect-3 (cths/get-shape file :rect-3) - events [(wtch/apply-token {:shape-ids [(:id rect-1)] - :attributes #{:opacity} - :token (toht/get-token file :opacity-float) - :on-update-shape wtch/update-opacity}) - (wtch/apply-token {:shape-ids [(:id rect-2)] - :attributes #{:opacity} - :token (toht/get-token file :opacity-percent) - :on-update-shape wtch/update-opacity}) - (wtch/apply-token {:shape-ids [(:id rect-3)] - :attributes #{:opacity} - :token (toht/get-token file :opacity-invalid) - :on-update-shape wtch/update-opacity})]] - (tohs/run-store-async - store done events - (fn [new-state] - (let [file' (ths/get-file-from-store new-state) - rect-1' (cths/get-shape file' :rect-1) - rect-2' (cths/get-shape file' :rect-2) - rect-3' (cths/get-shape file' :rect-3) - token-opacity-float (toht/get-token file' :opacity-float) - token-opacity-percent (toht/get-token file' :opacity-percent) - token-opacity-invalid (toht/get-token file' :opacity-invalid)] - (t/testing "float value got translated to float and applied to opacity" - (t/is (= (:opacity (:applied-tokens rect-1')) (wtt/token-identifier token-opacity-float))) - (t/is (= (:opacity rect-1') 0.3))) - (t/testing "percentage value got translated to float and applied to opacity" - (t/is (= (:opacity (:applied-tokens rect-2')) (wtt/token-identifier token-opacity-percent))) - (t/is (= (:opacity rect-2') 0.4))) - (t/testing "invalid opacity value got applied but did not change shape" - (t/is (= (:opacity (:applied-tokens rect-3')) (wtt/token-identifier token-opacity-invalid))) - (t/is (nil? (:opacity rect-3'))))))))))) +;; (t/deftest test-apply-stroke-width +;; (t/testing "applies stroke-width token and updates the shapes with stroke" +;; (t/async +;; done +;; (let [file (-> (setup-file-with-tokens {:rect-1 {:strokes [{:stroke-alignment :inner, +;; :stroke-style :solid, +;; :stroke-color "#000000", +;; :stroke-opacity 1, +;; :stroke-width 5}]}}) +;; (toht/add-token :token-target {:value "10" +;; :name "stroke-width.sm" +;; :type :stroke-width})) +;; store (ths/setup-store file) +;; rect-with-stroke (cths/get-shape file :rect-1) +;; rect-without-stroke (cths/get-shape file :rect-2) +;; events [(wtch/apply-token {:shape-ids [(:id rect-with-stroke) (:id rect-without-stroke)] +;; :attributes #{:stroke-width} +;; :token (toht/get-token file :token-target) +;; :on-update-shape wtch/update-stroke-width})]] +;; (tohs/run-store-async +;; store done events +;; (fn [new-state] +;; (let [file' (ths/get-file-from-store new-state) +;; token-target' (toht/get-token file' :token-target) +;; rect-with-stroke' (cths/get-shape file' :rect-1) +;; rect-without-stroke' (cths/get-shape file' :rect-2)] +;; (t/testing "token got applied to rect with stroke and shape stroke got updated" +;; (t/is (= (:stroke-width (:applied-tokens rect-with-stroke')) (wtt/token-identifier token-target'))) +;; (t/is (= (get-in rect-with-stroke' [:strokes 0 :stroke-width]) 10))) +;; (t/testing "token got applied to rect without stroke but shape didnt get updated" +;; (t/is (= (:stroke-width (:applied-tokens rect-without-stroke')) (wtt/token-identifier token-target'))) +;; (t/is (empty? (:strokes rect-without-stroke'))))))))))) -(t/deftest test-apply-rotation - (t/testing "applies rotation token and updates the shapes rotation" - (t/async - done - (let [file (-> (setup-file-with-tokens) - (toht/add-token :token-target {:value "120" - :name "rotation.medium" - :type :rotation})) - store (ths/setup-store file) - rect-1 (cths/get-shape file :rect-1) - events [(wtch/apply-token {:shape-ids [(:id rect-1)] - :attributes #{:rotation} - :token (toht/get-token file :token-target) - :on-update-shape wtch/update-rotation})]] - (tohs/run-store-async - store done events - (fn [new-state] - (let [file' (ths/get-file-from-store new-state) - token-target' (toht/get-token file' :token-target) - rect-1' (cths/get-shape file' :rect-1)] - (t/is (some? (:applied-tokens rect-1'))) - (t/is (= (:rotation (:applied-tokens rect-1')) (wtt/token-identifier token-target'))) - (t/is (= (:rotation rect-1') 120))))))))) +;; (t/deftest test-toggle-token-none +;; (t/testing "should apply token to all selected items, where no item has the token applied" +;; (t/async +;; done +;; (let [file (setup-file-with-tokens) +;; store (ths/setup-store file) +;; rect-1 (cths/get-shape file :rect-1) +;; rect-2 (cths/get-shape file :rect-2) +;; events [(wtch/toggle-token {:shapes [rect-1 rect-2] +;; :token-type-props {:attributes #{:rx :ry} +;; :on-update-shape wtch/update-shape-radius-all} +;; :token (toht/get-token file :token-2)})]] +;; (tohs/run-store-async +;; store done events +;; (fn [new-state] +;; (let [file' (ths/get-file-from-store new-state) +;; token-2' (toht/get-token file' :token-2) +;; rect-1' (cths/get-shape file' :rect-1) +;; rect-2' (cths/get-shape file' :rect-2)] +;; (t/is (some? (:applied-tokens rect-1'))) +;; (t/is (some? (:applied-tokens rect-2'))) +;; (t/is (= (:rx (:applied-tokens rect-1')) (wtt/token-identifier token-2'))) +;; (t/is (= (:rx (:applied-tokens rect-2')) (wtt/token-identifier token-2'))) +;; (t/is (= (:ry (:applied-tokens rect-1')) (wtt/token-identifier token-2'))) +;; (t/is (= (:ry (:applied-tokens rect-2')) (wtt/token-identifier token-2'))) +;; (t/is (= (:rx rect-1') 24)) +;; (t/is (= (:rx rect-2') 24))))))))) -(t/deftest test-apply-stroke-width - (t/testing "applies stroke-width token and updates the shapes with stroke" - (t/async - done - (let [file (-> (setup-file-with-tokens {:rect-1 {:strokes [{:stroke-alignment :inner, - :stroke-style :solid, - :stroke-color "#000000", - :stroke-opacity 1, - :stroke-width 5}]}}) - (toht/add-token :token-target {:value "10" - :name "stroke-width.sm" - :type :stroke-width})) - store (ths/setup-store file) - rect-with-stroke (cths/get-shape file :rect-1) - rect-without-stroke (cths/get-shape file :rect-2) - events [(wtch/apply-token {:shape-ids [(:id rect-with-stroke) (:id rect-without-stroke)] - :attributes #{:stroke-width} - :token (toht/get-token file :token-target) - :on-update-shape wtch/update-stroke-width})]] - (tohs/run-store-async - store done events - (fn [new-state] - (let [file' (ths/get-file-from-store new-state) - token-target' (toht/get-token file' :token-target) - rect-with-stroke' (cths/get-shape file' :rect-1) - rect-without-stroke' (cths/get-shape file' :rect-2)] - (t/testing "token got applied to rect with stroke and shape stroke got updated" - (t/is (= (:stroke-width (:applied-tokens rect-with-stroke')) (wtt/token-identifier token-target'))) - (t/is (= (get-in rect-with-stroke' [:strokes 0 :stroke-width]) 10))) - (t/testing "token got applied to rect without stroke but shape didnt get updated" - (t/is (= (:stroke-width (:applied-tokens rect-without-stroke')) (wtt/token-identifier token-target'))) - (t/is (empty? (:strokes rect-without-stroke'))))))))))) +;; (t/deftest test-toggle-token-mixed +;; (t/testing "should unapply given token if one of the selected items has the token applied while keeping other tokens with some attributes" +;; (t/async +;; done +;; (let [file (-> (setup-file-with-tokens) +;; (toht/apply-token-to-shape :rect-1 :token-1 #{:rx :ry}) +;; (toht/apply-token-to-shape :rect-3 :token-2 #{:rx :ry})) +;; store (ths/setup-store file) -(t/deftest test-toggle-token-none - (t/testing "should apply token to all selected items, where no item has the token applied" - (t/async - done - (let [file (setup-file-with-tokens) - store (ths/setup-store file) - rect-1 (cths/get-shape file :rect-1) - rect-2 (cths/get-shape file :rect-2) - events [(wtch/toggle-token {:shapes [rect-1 rect-2] - :token-type-props {:attributes #{:rx :ry} - :on-update-shape wtch/update-shape-radius-all} - :token (toht/get-token file :token-2)})]] - (tohs/run-store-async - store done events - (fn [new-state] - (let [file' (ths/get-file-from-store new-state) - token-2' (toht/get-token file' :token-2) - rect-1' (cths/get-shape file' :rect-1) - rect-2' (cths/get-shape file' :rect-2)] - (t/is (some? (:applied-tokens rect-1'))) - (t/is (some? (:applied-tokens rect-2'))) - (t/is (= (:rx (:applied-tokens rect-1')) (wtt/token-identifier token-2'))) - (t/is (= (:rx (:applied-tokens rect-2')) (wtt/token-identifier token-2'))) - (t/is (= (:ry (:applied-tokens rect-1')) (wtt/token-identifier token-2'))) - (t/is (= (:ry (:applied-tokens rect-2')) (wtt/token-identifier token-2'))) - (t/is (= (:rx rect-1') 24)) - (t/is (= (:rx rect-2') 24))))))))) +;; rect-with-token (cths/get-shape file :rect-1) +;; rect-without-token (cths/get-shape file :rect-2) +;; rect-with-other-token (cths/get-shape file :rect-3) -(t/deftest test-toggle-token-mixed - (t/testing "should unapply given token if one of the selected items has the token applied while keeping other tokens with some attributes" - (t/async - done - (let [file (-> (setup-file-with-tokens) - (toht/apply-token-to-shape :rect-1 :token-1 #{:rx :ry}) - (toht/apply-token-to-shape :rect-3 :token-2 #{:rx :ry})) - store (ths/setup-store file) +;; events [(wtch/toggle-token {:shapes [rect-with-token rect-without-token rect-with-other-token] +;; :token (toht/get-token file :token-1) +;; :token-type-props {:attributes #{:rx :ry}}})]] +;; (tohs/run-store-async +;; store done events +;; (fn [new-state] +;; (let [file' (ths/get-file-from-store new-state) +;; rect-with-token' (cths/get-shape file' :rect-1) +;; rect-without-token' (cths/get-shape file' :rect-2) +;; rect-with-other-token' (cths/get-shape file' :rect-3)] - rect-with-token (cths/get-shape file :rect-1) - rect-without-token (cths/get-shape file :rect-2) - rect-with-other-token (cths/get-shape file :rect-3) +;; (t/testing "rect-with-token got the token remove" +;; (t/is (nil? (:rx (:applied-tokens rect-with-token')))) +;; (t/is (nil? (:ry (:applied-tokens rect-with-token'))))) - events [(wtch/toggle-token {:shapes [rect-with-token rect-without-token rect-with-other-token] - :token (toht/get-token file :token-1) - :token-type-props {:attributes #{:rx :ry}}})]] - (tohs/run-store-async - store done events - (fn [new-state] - (let [file' (ths/get-file-from-store new-state) - rect-with-token' (cths/get-shape file' :rect-1) - rect-without-token' (cths/get-shape file' :rect-2) - rect-with-other-token' (cths/get-shape file' :rect-3)] +;; (t/testing "rect-without-token didn't get updated" +;; (t/is (= (:applied-tokens rect-without-token') (:applied-tokens rect-without-token)))) - (t/testing "rect-with-token got the token remove" - (t/is (nil? (:rx (:applied-tokens rect-with-token')))) - (t/is (nil? (:ry (:applied-tokens rect-with-token'))))) +;; (t/testing "rect-with-other-token didn't get updated" +;; (t/is (= (:applied-tokens rect-with-other-token') (:applied-tokens rect-with-other-token))))))))))) - (t/testing "rect-without-token didn't get updated" - (t/is (= (:applied-tokens rect-without-token') (:applied-tokens rect-without-token)))) +;; (t/deftest test-toggle-token-apply-to-all +;; (t/testing "should apply token to all if none of the shapes has it applied" +;; (t/async +;; done +;; (let [file (-> (setup-file-with-tokens) +;; (toht/apply-token-to-shape :rect-1 :token-2 #{:rx :ry}) +;; (toht/apply-token-to-shape :rect-3 :token-2 #{:rx :ry})) +;; store (ths/setup-store file) - (t/testing "rect-with-other-token didn't get updated" - (t/is (= (:applied-tokens rect-with-other-token') (:applied-tokens rect-with-other-token))))))))))) +;; rect-with-other-token-1 (cths/get-shape file :rect-1) +;; rect-without-token (cths/get-shape file :rect-2) +;; rect-with-other-token-2 (cths/get-shape file :rect-3) -(t/deftest test-toggle-token-apply-to-all - (t/testing "should apply token to all if none of the shapes has it applied" - (t/async - done - (let [file (-> (setup-file-with-tokens) - (toht/apply-token-to-shape :rect-1 :token-2 #{:rx :ry}) - (toht/apply-token-to-shape :rect-3 :token-2 #{:rx :ry})) - store (ths/setup-store file) +;; events [(wtch/toggle-token {:shapes [rect-with-other-token-1 rect-without-token rect-with-other-token-2] +;; :token (toht/get-token file :token-1) +;; :token-type-props {:attributes #{:rx :ry}}})]] +;; (tohs/run-store-async +;; store done events +;; (fn [new-state] +;; (let [file' (ths/get-file-from-store new-state) +;; target-token (toht/get-token file' :token-1) +;; rect-with-other-token-1' (cths/get-shape file' :rect-1) +;; rect-without-token' (cths/get-shape file' :rect-2) +;; rect-with-other-token-2' (cths/get-shape file' :rect-3)] - rect-with-other-token-1 (cths/get-shape file :rect-1) - rect-without-token (cths/get-shape file :rect-2) - rect-with-other-token-2 (cths/get-shape file :rect-3) +;; (t/testing "token got applied to all shapes" +;; (t/is (= (:rx (:applied-tokens rect-with-other-token-1')) (wtt/token-identifier target-token))) +;; (t/is (= (:rx (:applied-tokens rect-without-token')) (wtt/token-identifier target-token))) +;; (t/is (= (:rx (:applied-tokens rect-with-other-token-2')) (wtt/token-identifier target-token))) - events [(wtch/toggle-token {:shapes [rect-with-other-token-1 rect-without-token rect-with-other-token-2] - :token (toht/get-token file :token-1) - :token-type-props {:attributes #{:rx :ry}}})]] - (tohs/run-store-async - store done events - (fn [new-state] - (let [file' (ths/get-file-from-store new-state) - target-token (toht/get-token file' :token-1) - rect-with-other-token-1' (cths/get-shape file' :rect-1) - rect-without-token' (cths/get-shape file' :rect-2) - rect-with-other-token-2' (cths/get-shape file' :rect-3)] - - (t/testing "token got applied to all shapes" - (t/is (= (:rx (:applied-tokens rect-with-other-token-1')) (wtt/token-identifier target-token))) - (t/is (= (:rx (:applied-tokens rect-without-token')) (wtt/token-identifier target-token))) - (t/is (= (:rx (:applied-tokens rect-with-other-token-2')) (wtt/token-identifier target-token))) - - (t/is (= (:ry (:applied-tokens rect-with-other-token-1')) (wtt/token-identifier target-token))) - (t/is (= (:ry (:applied-tokens rect-without-token')) (wtt/token-identifier target-token))) - (t/is (= (:ry (:applied-tokens rect-with-other-token-2')) (wtt/token-identifier target-token))))))))))) +;; (t/is (= (:ry (:applied-tokens rect-with-other-token-1')) (wtt/token-identifier target-token))) +;; (t/is (= (:ry (:applied-tokens rect-without-token')) (wtt/token-identifier target-token))) +;; (t/is (= (:ry (:applied-tokens rect-with-other-token-2')) (wtt/token-identifier target-token))))))))))) From 993df2362468bd13ee8916f98be06e785a5d973e Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Tue, 1 Oct 2024 09:55:58 +0200 Subject: [PATCH 57/92] Remove unneeded tests --- frontend/test/token_tests/token_set_test.cljs | 37 ------------------- 1 file changed, 37 deletions(-) delete mode 100644 frontend/test/token_tests/token_set_test.cljs diff --git a/frontend/test/token_tests/token_set_test.cljs b/frontend/test/token_tests/token_set_test.cljs deleted file mode 100644 index d199e221c..000000000 --- a/frontend/test/token_tests/token_set_test.cljs +++ /dev/null @@ -1,37 +0,0 @@ -(ns token-tests.token-set-test - (:require - [app.main.ui.workspace.tokens.token-set :as wtts] - [cljs.test :as t])) - -(t/deftest toggle-active-theme-id-test - (t/testing "toggles active theme id" - (let [state {:workspace-data {:token-themes-index {1 {:id 1}}}}] - (t/testing "activates theme with id") - (t/is (= (wtts/toggle-active-theme-id 1 state) #{1}))) - - (let [state {:workspace-data {:token-active-themes #{1} - :token-themes-index {1 {:id 1}}}}] - (t/testing "missing temp theme returns empty set" - (t/is (= #{} (wtts/toggle-active-theme-id 1 state))))) - - (let [state {:workspace-data {:token-theme-temporary-id :temp - :token-active-themes #{1} - :token-themes-index {1 {:id 1}}}}] - (t/testing "empty set returns temp theme" - (t/is (= #{:temp} (wtts/toggle-active-theme-id 1 state))))) - - (let [state {:workspace-data {:token-active-themes #{2 3 4} - :token-themes-index {1 {:id 1} - 2 {:id 2} - 3 {:id 3} - 4 {:id 4 :group :different}}}}] - (t/testing "removes same group themes and keeps different group themes" - (t/is (= #{1 4} (wtts/toggle-active-theme-id 1 state))))) - - (let [state {:workspace-data {:token-active-themes #{1 2 3 4}} - :token-themes-index {1 {:id 1} - 2 {:id 2} - 3 {:id 3} - 4 {:id 4 :group :different}}}] - (t/testing "removes theme when active" - (t/is (= #{4 3 2} (wtts/toggle-active-theme-id 1 state))))))) From 5825fa656bec830801d95f3d7563f0cb7f1f8d9d Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Tue, 1 Oct 2024 09:56:03 +0200 Subject: [PATCH 58/92] Fix tests --- .../token_tests/style_dictionary_test.cljs | 45 ++++++++++--------- frontend/test/token_tests/token_test.cljs | 4 -- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/frontend/test/token_tests/style_dictionary_test.cljs b/frontend/test/token_tests/style_dictionary_test.cljs index 638fa7e3c..07b407e13 100644 --- a/frontend/test/token_tests/style_dictionary_test.cljs +++ b/frontend/test/token_tests/style_dictionary_test.cljs @@ -3,39 +3,42 @@ [app.main.ui.workspace.tokens.style-dictionary :as sd] [cljs.test :as t :include-macros true] [promesa.core :as p] - [app.main.ui.workspace.tokens.token :as wtt])) + [app.main.ui.workspace.tokens.token :as wtt] + [app.common.data :as d])) (def border-radius-token - {:id #uuid "8c868278-7c8d-431b-bbc9-7d8f15c8edb9" - :value "12px" + {:value "12px" :name "borderRadius.sm" :type :border-radius}) (def reference-border-radius-token - {:id #uuid "b9448d78-fd5b-4e3d-aa32-445904063f5b" - :value "{borderRadius.sm} * 2" + {:value "{borderRadius.sm} * 2" :name "borderRadius.md-with-dashes" :type :border-radius}) -(def tokens {(:id border-radius-token) border-radius-token - (:id reference-border-radius-token) reference-border-radius-token}) - +(def tokens (d/ordered-map + (:name border-radius-token) border-radius-token + (:name reference-border-radius-token) reference-border-radius-token)) (t/deftest resolve-tokens-test (t/async done (t/testing "resolves tokens using style-dictionary from a ids map" (-> (sd/resolve-tokens+ tokens) - (p/finally (fn [resolved-tokens] - (let [expected-tokens {"borderRadius.sm" - (assoc border-radius-token - :resolved-value 12 - :resolved-unit "px") - "borderRadius.md-with-dashes" - (assoc reference-border-radius-token - :resolved-value 24 - :resolved-unit "px")}] - (t/is (= expected-tokens resolved-tokens)) - (done)))))))) + (p/finally + (fn [resolved-tokens] + (let [expected-tokens {"borderRadius.sm" + (assoc border-radius-token + :resolved-value 12 + :resolved-unit "px") + "borderRadius.md-with-dashes" + (assoc reference-border-radius-token + :resolved-value 24 + :resolved-unit "px")}] + (t/is (= 12 (get-in resolved-tokens ["borderRadius.sm" :resolved-value]))) + (t/is (= "px" (get-in resolved-tokens ["borderRadius.sm" :unit]))) + (t/is (= 24 (get-in resolved-tokens ["borderRadius.md-with-dashes" :resolved-value]))) + (t/is (= "px" (get-in resolved-tokens ["borderRadius.md-with-dashes" :unit]))) + (done)))))))) (t/deftest resolve-tokens-names-map-test (t/async @@ -48,10 +51,10 @@ (let [expected-tokens {"borderRadius.sm" (assoc border-radius-token :resolved-value 12 - :resolved-unit "px") + :unit "px") "borderRadius.md-with-dashes" (assoc reference-border-radius-token :resolved-value 24 - :resolved-unit "px")}] + :unit "px")}] (t/is (= expected-tokens resolved-tokens)) (done)))))))) diff --git a/frontend/test/token_tests/token_test.cljs b/frontend/test/token_tests/token_test.cljs index 4b38c889c..0dfaf675d 100644 --- a/frontend/test/token_tests/token_test.cljs +++ b/frontend/test/token_tests/token_test.cljs @@ -50,10 +50,6 @@ (t/testing "doesn't match passed `:token-attributes`" (t/is (nil? (wtt/token-applied? {:name "a"} {:applied-tokens {:x "a"}} #{:y}))))) -(t/deftest token-applied-attributes - (t/is (= #{:x} (wtt/token-applied-attributes {:name "a"} - {:applied-tokens {:x "a" :y "b"}} - #{:x :missing})))) (t/deftest shapes-ids-by-applied-attributes (t/testing "Returns set of matched attributes that fit the applied token" (let [attributes #{:x :y :z} From f1f2767e2a872e2adf2ce143005a1cb9c8f979f4 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Tue, 1 Oct 2024 12:49:03 +0200 Subject: [PATCH 59/92] Activating initial sets by adding them to the token theme --- common/src/app/common/types/tokens_lib.cljc | 7 +++++++ frontend/src/app/main/data/tokens.cljs | 23 +++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index efe84abf6..2b355a249 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -273,6 +273,7 @@ (def hidden-token-theme-path (token-theme-path hidden-token-theme-group hidden-token-theme-name)) + (defprotocol ITokenTheme (set-sets [_ set-names] "set the active token sets") (toggle-set [_ set-name] "togle a set used / not used in the theme") @@ -347,6 +348,12 @@ token-theme)) +(defn make-hidden-token-theme + [& {:keys [] :as params}] + (make-token-theme (assoc params + :group hidden-token-theme-group + :name hidden-token-theme-name))) + ;; === TokenThemes (collection) (defprotocol ITokenThemes diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index bbd355337..0100f8360 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -182,10 +182,7 @@ active-token-set-names (ctob/get-active-themes-set-names tokens-lib) theme (-> (or (some-> prev-theme (ctob/set-sets active-token-set-names)) - (ctob/make-token-theme - :group ctob/hidden-token-theme-group - :name ctob/hidden-token-theme-name - :sets active-token-set-names)) + (ctob/make-hidden-token-theme :sets active-token-set-names)) (ctob/toggle-set token-set-name)) prev-active-token-themes (ctob/get-active-theme-paths tokens-lib) changes (-> (pcb/empty-changes it) @@ -218,8 +215,22 @@ token-set-name (or (:name token-set) "Global") changes (if (not token-set) ;; No set created add a global set - (->> (ctob/make-token-set :name token-set-name :tokens {(:name token) token}) - (pcb/add-token-set (pcb/empty-changes))) + (let [tokens-lib (get-tokens-lib state) + token-set (ctob/make-token-set :name token-set-name :tokens {(:name token) token}) + hidden-theme (ctob/make-hidden-token-theme :sets [token-set-name]) + active-theme-paths (some-> tokens-lib ctob/get-active-theme-paths) + add-to-hidden-theme? (= active-theme-paths #{ctob/hidden-token-theme-path}) + base-changes (pcb/add-token-set (pcb/empty-changes) token-set)] + (cond + (not tokens-lib) (-> base-changes + (pcb/add-token-theme hidden-theme) + (pcb/update-active-token-themes #{ctob/hidden-token-theme-path} #{})) + + add-to-hidden-theme? (let [prev-hidden-theme (ctob/get-theme tokens-lib ctob/hidden-token-theme-group ctob/hidden-token-theme-name)] + (-> base-changes + (pcb/update-token-theme (ctob/toggle-set prev-hidden-theme ctob/hidden-token-theme-path) prev-hidden-theme))) + + :else base-changes)) ;; Either update or add token to existing set (if-let [prev-token (ctob/get-token token-set (or prev-token-name (:name token)))] (pcb/update-token (pcb/empty-changes) (:name token-set) token prev-token) From 9268b18e56c64e2a87ac83b83dbbe7c94faffc3f Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Tue, 1 Oct 2024 12:53:01 +0200 Subject: [PATCH 60/92] Fix edit button --- frontend/src/app/main/ui/workspace/tokens/sidebar.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs index 5f1ed3a06..9bc807478 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs @@ -171,7 +171,7 @@ (mf/defc themes-sidebar [_props] - (let [ordered-themes (mf/deref refs/workspace-token-themes)] + (let [ordered-themes (mf/deref refs/workspace-token-themes-no-hidden)] [:div {:class (stl/css :theme-sidebar)} [:span {:class (stl/css :themes-header)} "Themes"] [:div {:class (stl/css :theme-select-wrapper)} From 3681678dc425ff741a69e733120f65c66ba2f120 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Tue, 1 Oct 2024 14:40:05 +0200 Subject: [PATCH 61/92] Migrate token tests to tokens-lib --- frontend/test/token_tests/helpers/tokens.cljs | 10 +++-- .../token_tests/logic/token_actions_test.cljs | 40 +++++++++---------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/frontend/test/token_tests/helpers/tokens.cljs b/frontend/test/token_tests/helpers/tokens.cljs index 87db316fb..df222f83a 100644 --- a/frontend/test/token_tests/helpers/tokens.cljs +++ b/frontend/test/token_tests/helpers/tokens.cljs @@ -1,16 +1,18 @@ (ns token-tests.helpers.tokens (:require [app.common.test-helpers.ids-map :as thi] - [app.main.ui.workspace.tokens.token :as wtt])) + [app.main.ui.workspace.tokens.token :as wtt] + [app.common.types.tokens-lib :as ctob])) (defn add-token [state label params] (let [id (thi/new-id! label) token (assoc params :id id)] (update-in state [:data :tokens] assoc id token))) -(defn get-token [file label] - (let [id (thi/id label)] - (get-in file [:data :tokens id]))) +(defn get-token [file name] + (some-> (get-in file [:data :tokens-li]) + (ctob/get-active-themes-set-tokens) + (get name))) (defn apply-token-to-shape [file shape-label token-label attributes] (let [first-page-id (get-in file [:data :pages 0]) diff --git a/frontend/test/token_tests/logic/token_actions_test.cljs b/frontend/test/token_tests/logic/token_actions_test.cljs index 77a3530fe..140cbd318 100644 --- a/frontend/test/token_tests/logic/token_actions_test.cljs +++ b/frontend/test/token_tests/logic/token_actions_test.cljs @@ -1,18 +1,15 @@ (ns token-tests.logic.token-actions-test (:require - [app.common.pprint :refer [pprint]] + [token-tests.helpers.state :as tohs] [app.common.logging :as log] [app.common.test-helpers.compositions :as ctho] - [app.common.test-helpers.files :as cthf] - [app.common.test-helpers.shapes :as cths] - [app.main.data.tokens :as wdt] [app.main.ui.workspace.tokens.changes :as wtch] - [app.main.ui.workspace.tokens.token :as wtt] - [app.main.ui.workspace.tokens.token-set :as wtts] + [app.common.test-helpers.files :as cthf] + [app.common.types.tokens-lib :as ctob] [cljs.test :as t :include-macros true] - [frontend-tests.helpers.pages :as thp] + [app.common.test-helpers.shapes :as cths] [frontend-tests.helpers.state :as ths] - [token-tests.helpers.state :as tohs] + [frontend-tests.helpers.pages :as thp] [token-tests.helpers.tokens :as toht])) @@ -26,23 +23,26 @@ (cthf/sample-file :file-1 :page-label :page-1)) (def border-radius-token - {:value "12" - :name "borderRadius.sm" + {:name "borderRadius.sm" + :value "12" :type :border-radius}) (def reference-border-radius-token - {:value "{borderRadius.sm} * 2" - :name "borderRadius.md" + {:name "borderRadius.md" + :value "{borderRadius.sm} * 2" :type :border-radius}) -;; (defn setup-file-with-tokens -;; [& {:keys [rect-1 rect-2 rect-3]}] -;; (-> (setup-file) -;; (ctho/add-rect :rect-1 rect-1) -;; (ctho/add-rect :rect-2 rect-2) -;; (ctho/add-rect :rect-3 rect-3) -;; (toht/add-token :token-1 border-radius-token) -;; (toht/add-token :token-2 reference-border-radius-token))) +(defn setup-file-with-tokens + [& {:keys [rect-1 rect-2 rect-3]}] + (-> (setup-file) + (ctho/add-rect :rect-1 rect-1) + (ctho/add-rect :rect-2 rect-2) + (ctho/add-rect :rect-3 rect-3) + (assoc-in [:data :tokens-lib] + (-> (ctob/make-tokens-lib) + (ctob/add-set (ctob/make-token-set :name "Set A")) + (ctob/add-token-in-set "Set A" (ctob/make-token border-radius-token)) + (ctob/add-token-in-set "Set A" (ctob/make-token reference-border-radius-token)))))) ;; (t/deftest test-apply-token ;; (t/testing "applies token to shape and updates shape attributes to resolved value" From 7418d1fa2cd06a862542b5aac7e5606592793aaa Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Tue, 1 Oct 2024 15:42:09 +0200 Subject: [PATCH 62/92] Dont support token set grouping for now --- .../src/app/main/ui/workspace/tokens/sets.cljs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/sets.cljs b/frontend/src/app/main/ui/workspace/tokens/sets.cljs index c5f14a5b8..40c3a46ef 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sets.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sets.cljs @@ -7,6 +7,7 @@ (ns app.main.ui.workspace.tokens.sets (:require-macros [app.main.style :as stl]) (:require + [app.main.data.messages :as msg] [app.main.data.tokens :as wdt] [app.main.refs :as refs] [app.main.store :as st] @@ -133,6 +134,12 @@ :set-id child-id :selected-set-id selected-token-set-id)])]))])]])) +(defn warn-on-try-create-token-set-group! [] + (st/emit! (msg/show {:content "Token Set grouping is not supported yet." + :notification-type :toast + :type :warning + :timeout 3000}))) + (mf/defc controlled-sets-list [{:keys [token-sets on-update-token-set @@ -143,7 +150,8 @@ on-select context] :as _props}] - (let [{:keys [editing? new? on-edit on-create on-reset] :as ctx} (or context (sets-context/use-context))] + (let [{:keys [editing? new? on-edit on-create on-reset] :as ctx} (or context (sets-context/use-context)) + avoid-token-set-grouping #(str/replace % "/" "-")] [:ul {:class (stl/css :sets-list)} (for [token-set token-sets] (when token-set @@ -157,7 +165,9 @@ :on-edit on-edit :on-toggle on-toggle-token-set :on-submit #(do - (on-update-token-set (:name token-set) %) + ;; TODO: We don't support set grouping for now so we rename sets for now + (warn-on-try-create-token-set-group!) + (on-update-token-set (avoid-token-set-grouping (:name token-set)) (update % :name avoid-token-set-grouping)) (on-reset)) :on-cancel on-reset}])) (when new? @@ -168,7 +178,9 @@ :on-select (constantly nil) :on-edit on-create :on-submit #(do - (on-create-token-set %) + ;; TODO: We don't support set grouping for now so we rename sets for now + (warn-on-try-create-token-set-group!) + (on-create-token-set (update % :name avoid-token-set-grouping)) (on-reset)) :on-cancel on-reset}])])) From fa3e2c90e67b3d56ad5291856227452d3fc16b48 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Tue, 1 Oct 2024 15:45:14 +0200 Subject: [PATCH 63/92] Fix renaming via context menu --- .../app/main/ui/workspace/tokens/sets_context_menu.cljs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/sets_context_menu.cljs b/frontend/src/app/main/ui/workspace/tokens/sets_context_menu.cljs index 4873702c8..e82ba44c4 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sets_context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sets_context_menu.cljs @@ -28,10 +28,10 @@ [:span {:class (stl/css :title)} title]]) (mf/defc menu - [{:keys [token-set-id token-set-name]}] + [{:keys [token-set-name]}] (let [{:keys [on-edit]} (sets-context/use-context)] [:ul {:class (stl/css :context-list)} - [:& menu-entry {:title "Rename" :on-click #(on-edit token-set-id)}] + [:& menu-entry {:title "Rename" :on-click #(on-edit token-set-name)}] [:& menu-entry {:title "Delete" :on-click #(st/emit! (wdt/delete-token-set token-set-name))}]])) (mf/defc sets-context-menu @@ -41,7 +41,6 @@ left (+ (get-in mdata [:position :x]) 5) width (mf/use-state 0) dropdown-ref (mf/use-ref) - token-set-id (:token-set-id mdata) token-set-name (:token-set-name mdata)] (mf/use-effect (mf/deps mdata) @@ -54,5 +53,4 @@ :ref dropdown-ref :style {:top top :left left} :on-context-menu prevent-default} - [:& menu {:token-set-id token-set-id - :token-set-name token-set-name}]]])) + [:& menu {:token-set-name token-set-name}]]])) From 43e5367988fa0394767ba75a98470b47467891c0 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 09:42:42 +0200 Subject: [PATCH 64/92] Fix testing from cljs --- common/test/common_tests/types/tokens_lib_test.cljc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/test/common_tests/types/tokens_lib_test.cljc b/common/test/common_tests/types/tokens_lib_test.cljc index 75fcea2c8..4e169a7a3 100644 --- a/common/test/common_tests/types/tokens_lib_test.cljc +++ b/common/test/common_tests/types/tokens_lib_test.cljc @@ -6,8 +6,8 @@ (ns common-tests.types.tokens-lib-test (:require + #?(:clj [app.common.fressian :as fres]) [app.common.data :as d] - [app.common.fressian :as fres] [app.common.time :as dt] [app.common.transit :as tr] [app.common.types.tokens-lib :as ctob] From 57a133e09de7f8ed3449af6d1f3f7f19fbf69c7c Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 09:42:49 +0200 Subject: [PATCH 65/92] Add ordered tokens test --- .../common_tests/types/tokens_lib_test.cljc | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/common/test/common_tests/types/tokens_lib_test.cljc b/common/test/common_tests/types/tokens_lib_test.cljc index 4e169a7a3..4c7dd8a7a 100644 --- a/common/test/common_tests/types/tokens_lib_test.cljc +++ b/common/test/common_tests/types/tokens_lib_test.cljc @@ -320,7 +320,34 @@ (t/is (= (ctob/set-count tokens-lib') 1)) (t/is (= (count (:tokens token-set')) 0)) (t/is (nil? token')) - (t/is (dt/is-after? (:modified-at token-set') (:modified-at token-set)))))) + (t/is (dt/is-after? (:modified-at token-set') (:modified-at token-set))))) + + (t/deftest list-active-themes-tokens-in-order + (let [tokens-lib (-> (ctob/make-tokens-lib) + (ctob/add-theme (ctob/make-token-theme :name "out-of-order-theme" + ;; Out of order sets in theme + :sets ["unknown-set" "set-b" "set-a"])) + (ctob/set-active-themes #{"/out-of-order-theme"}) + + (ctob/add-set (ctob/make-token-set :name "set-a")) + (ctob/add-token-in-set "set-a" (ctob/make-token :name "set-a-token" + :type :boolean + :value true)) + (ctob/add-set (ctob/make-token-set :name "set-b")) + (ctob/add-token-in-set "set-b" (ctob/make-token :name "set-b-token" + :type :boolean + :value true)) + + (ctob/add-set (ctob/make-token-set :name "inactive-set")) + (ctob/add-token-in-set "inactive-set" (ctob/make-token :name "inactive-set-token" + :type :boolean + :value true))) + + + expected-order (ctob/get-sets-order tokens-lib) + expected-tokens (ctob/get-active-themes-set-tokens tokens-lib)] + (t/is (= expected-order '("set-a" "set-b"))) + (t/is (= ["set-a-token" "set-b-token"] (map key expected-tokens)))))) (t/testing "token-theme in a lib" From 669594e3c164081c72e769796ec62feca2a29e1f Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 09:42:56 +0200 Subject: [PATCH 66/92] Cleanup --- common/src/app/common/data/macros.cljc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/common/src/app/common/data/macros.cljc b/common/src/app/common/data/macros.cljc index 00a1aaeb2..2992aff9b 100644 --- a/common/src/app/common/data/macros.cljc +++ b/common/src/app/common/data/macros.cljc @@ -16,10 +16,6 @@ [cljs.analyzer.api :as aapi] [cuerdas.core :as str])) -(defmacro fixme - "Purely annotational macro to find instances later to remove when the refactor to tokens-lib is done." - [& body] `(do ~@body)) - (defmacro legacy "Purely annotational macro to find instances later to remove when the refactor to tokens-lib is done." [& body] `(do ~@body)) From 0b081d24e0184d8d57d7152f2b73336a079d4f4c Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 10:03:34 +0200 Subject: [PATCH 67/92] Only show warning when string has / --- frontend/src/app/main/ui/workspace/tokens/sets.cljs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/sets.cljs b/frontend/src/app/main/ui/workspace/tokens/sets.cljs index 40c3a46ef..75854e941 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sets.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sets.cljs @@ -166,7 +166,8 @@ :on-toggle on-toggle-token-set :on-submit #(do ;; TODO: We don't support set grouping for now so we rename sets for now - (warn-on-try-create-token-set-group!) + (when (str/includes? (:name %) "/") + (warn-on-try-create-token-set-group!)) (on-update-token-set (avoid-token-set-grouping (:name token-set)) (update % :name avoid-token-set-grouping)) (on-reset)) :on-cancel on-reset}])) @@ -179,7 +180,8 @@ :on-edit on-create :on-submit #(do ;; TODO: We don't support set grouping for now so we rename sets for now - (warn-on-try-create-token-set-group!) + (when (str/includes? (:name %) "/") + (warn-on-try-create-token-set-group!)) (on-create-token-set (update % :name avoid-token-set-grouping)) (on-reset)) :on-cancel on-reset}])])) From 053d0fc923d0f82008c552df62e2d0d50950854c Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 10:15:35 +0200 Subject: [PATCH 68/92] Cleanup function --- common/src/app/common/types/tokens_lib.cljc | 17 +++++++++-------- .../common_tests/types/tokens_lib_test.cljc | 9 +++++---- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index 2b355a249..b43ac7fd5 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -627,16 +627,17 @@ (get-active-themes this))) (get-active-themes-set-tokens [this] - (let [sets-order (get-sets-order this)] + (let [sets-order (get-sets-order this) + active-themes (get-active-themes this) + order-theme-set (fn [theme] + (filter #(contains? (set (:sets theme)) %) sets-order))] (reduce - (fn [acc cur] + (fn [tokens theme] (reduce - (fn [acc cur] - (merge acc (:tokens (get-set this cur)))) - acc - (let [ref-set (set (:sets cur))] - (filter #(contains? ref-set %) sets-order)))) - (d/ordered-map) (get-active-themes this)))) + (fn [tokens' cur] + (merge tokens' (:tokens (get-set this cur)))) + tokens (order-theme-set theme))) + (d/ordered-map) active-themes))) (update-set-name [_ old-set-name new-set-name] (TokensLib. sets diff --git a/common/test/common_tests/types/tokens_lib_test.cljc b/common/test/common_tests/types/tokens_lib_test.cljc index 4c7dd8a7a..945504e69 100644 --- a/common/test/common_tests/types/tokens_lib_test.cljc +++ b/common/test/common_tests/types/tokens_lib_test.cljc @@ -337,7 +337,7 @@ (ctob/add-token-in-set "set-b" (ctob/make-token :name "set-b-token" :type :boolean :value true)) - + ;; Ignore this set (ctob/add-set (ctob/make-token-set :name "inactive-set")) (ctob/add-token-in-set "inactive-set" (ctob/make-token :name "inactive-set-token" :type :boolean @@ -345,9 +345,10 @@ expected-order (ctob/get-sets-order tokens-lib) - expected-tokens (ctob/get-active-themes-set-tokens tokens-lib)] - (t/is (= expected-order '("set-a" "set-b"))) - (t/is (= ["set-a-token" "set-b-token"] (map key expected-tokens)))))) + expected-tokens (ctob/get-active-themes-set-tokens tokens-lib) + expected-token-names (mapv key expected-tokens)] + (t/is (= '("set-a" "set-b" "inactive-set") expected-order)) + (t/is (= ["set-a-token" "set-b-token"] expected-token-names))))) (t/testing "token-theme in a lib" From 028809f1d52994717c66b329df5d8fdbe4c8b781 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 10:22:09 +0200 Subject: [PATCH 69/92] Cleanup --- common/src/app/common/macros.cljc | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 common/src/app/common/macros.cljc diff --git a/common/src/app/common/macros.cljc b/common/src/app/common/macros.cljc deleted file mode 100644 index e69de29bb..000000000 From fdca6e4edf89054ff438c4353ef3c81d82725179 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 10:46:55 +0200 Subject: [PATCH 70/92] 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 From 845de5d885d9a4349efd90c0f5c29cf6b0e09c1b Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 10:52:48 +0200 Subject: [PATCH 71/92] Fix export --- .../src/app/main/ui/workspace/tokens/core.cljs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/core.cljs b/frontend/src/app/main/ui/workspace/tokens/core.cljs index 70d413e8d..9a0779a17 100644 --- a/frontend/src/app/main/ui/workspace/tokens/core.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/core.cljs @@ -61,18 +61,18 @@ (defn export-tokens-file [tokens-json] (let [file-name "tokens.json" file-content (encode-tokens tokens-json) - blob (wapi/create-blob (clj->js file-content) "application/json")] + blob (wapi/create-blob file-content "application/json")] (dom/trigger-download file-name blob))) -(defn transform-tokens-into-json-format [tokens] +(defn tokens->dtcg-map [tokens] (let [global (reduce (fn [acc [_ {:keys [name value type]}]] - (assoc acc name {:$value value - :$type (str/camel type)})) - (sorted-map) tokens)] + (assoc acc name {"$value" value + "$type" (str/camel type)})) + (d/ordered-map) tokens)] {:global global})) (defn download-tokens-as-json [] - (let [all-tokens (deref refs/workspace-selected-token-set-tokens-OLD) - transformed-tokens-json (transform-tokens-into-json-format all-tokens)] - (export-tokens-file transformed-tokens-json))) + (let [tokens (deref refs/workspace-active-theme-sets-tokens) + dtcg-format-tokens-map (tokens->dtcg-map tokens)] + (export-tokens-file dtcg-format-tokens-map))) From 93cc8214fa7fa23fb5bc089977c701db1e761a4d Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 11:05:39 +0200 Subject: [PATCH 72/92] Fix border-radius and sizing panels --- common/src/app/common/types/tokens_lib.cljc | 7 +++++++ .../sidebar/options/menus/measures.cljs | 16 +++++++++------- .../src/app/main/ui/workspace/tokens/core.cljs | 7 +++++++ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index 6fd65030b..53b47f7bf 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 group-by-type [tokens] + (let [tokens' (if (or (map? tokens) + (d/ordered-map? tokens)) + (vals tokens) + tokens)] + (group-by :type tokens'))) + (defn filter-by-type [token-type tokens] (let [token-type? #(= token-type (:type %))] (cond 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 c5df4dc6c..1aed9f173 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 @@ -32,7 +32,8 @@ [app.util.dom :as dom] [app.util.i18n :as i18n :refer [tr]] [clojure.set :refer [rename-keys union]] - [rumext.v2 :as mf])) + [rumext.v2 :as mf] + [app.common.types.tokens-lib :as ctob])) (def measure-attrs [:proportion-lock @@ -101,28 +102,29 @@ selection-parents-ref (mf/use-memo (mf/deps ids) #(refs/parents-by-ids ids)) selection-parents (mf/deref selection-parents-ref) - tokens (-> (mf/deref refs/workspace-active-theme-sets-tokens) - (sd/use-resolved-tokens)) - tokens-by-type (mf/use-memo (mf/deps tokens) #(wtc/group-tokens-by-type-OLD tokens)) + tokens (sd/use-active-theme-sets-tokens) + tokens-by-type (mf/use-memo + (mf/deps tokens) + #(ctob/group-by-type tokens)) 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-OLD + #(wtc/tokens->select-options {: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-OLD + #(wtc/tokens->select-options {: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-OLD + #(wtc/tokens->select-options {: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 9a0779a17..b511f5c4b 100644 --- a/frontend/src/app/main/ui/workspace/tokens/core.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/core.cljs @@ -43,6 +43,13 @@ (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}] + (cond-> (assoc item :label name) + (wtt/token-applied? item shape (or selected-attributes attributes)) (assoc :selected? true))) + tokens)) + (defn tokens-name-map->select-options [{:keys [shape tokens attributes selected-attributes]}] (map (fn [[_k {:keys [name] :as item}]] From 0ffcda404b7fc7e41a36fc0e847584be12b53f61 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 11:09:52 +0200 Subject: [PATCH 73/92] Cleanup --- .../app/main/ui/workspace/tokens/core.cljs | 22 +------------------ .../app/main/ui/workspace/tokens/sidebar.cljs | 5 +++-- .../app/main/ui/workspace/tokens/token.cljs | 19 ++++++++-------- 3 files changed, 13 insertions(+), 33 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/core.cljs b/frontend/src/app/main/ui/workspace/tokens/core.cljs index b511f5c4b..c37ace5a2 100644 --- a/frontend/src/app/main/ui/workspace/tokens/core.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/core.cljs @@ -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}] diff --git a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs index 9bc807478..683265113 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs @@ -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 diff --git a/frontend/src/app/main/ui/workspace/tokens/token.cljs b/frontend/src/app/main/ui/workspace/tokens/token.cljs index c55f5c60f..b12ce4e55 100644 --- a/frontend/src/app/main/ui/workspace/tokens/token.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/token.cljs @@ -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. From a235327c3e609d43885eb80cd33744868a722325 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 11:33:14 +0200 Subject: [PATCH 74/92] Cleanup --- common/src/app/common/data/macros.cljc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/common/src/app/common/data/macros.cljc b/common/src/app/common/data/macros.cljc index 2992aff9b..7740ef362 100644 --- a/common/src/app/common/data/macros.cljc +++ b/common/src/app/common/data/macros.cljc @@ -16,10 +16,6 @@ [cljs.analyzer.api :as aapi] [cuerdas.core :as str])) -(defmacro legacy - "Purely annotational macro to find instances later to remove when the refactor to tokens-lib is done." - [& body] `(do ~@body)) - (defmacro select-keys "A macro version of `select-keys`. Useful when keys vector is known at compile time (aprox 600% performance boost). From 041e04dcb1e09a658450cb651c877d81684e748f Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 14:09:51 +0200 Subject: [PATCH 75/92] Remove unneeded -> --- common/src/app/common/files/changes.cljc | 122 +++++++++-------------- 1 file changed, 49 insertions(+), 73 deletions(-) diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index eccd349bb..4241c42a0 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -788,112 +788,88 @@ (defmethod process-change :add-token [data {:keys [set-name token]}] - (-> data - (update :tokens-lib - #(-> % - (ctob/ensure-tokens-lib) - (ctob/add-token-in-set set-name (ctob/make-token token)))))) + (update data :tokens-lib #(-> % + (ctob/ensure-tokens-lib) + (ctob/add-token-in-set set-name (ctob/make-token token))))) (defmethod process-change :mod-token [data {:keys [set-name name token]}] - (-> data - (update :tokens-lib - #(-> % - (ctob/ensure-tokens-lib) - (ctob/update-token-in-set - set-name - name - (fn [old-token] - (ctob/make-token (merge old-token token)))))))) + (update data :tokens-lib #(-> % + (ctob/ensure-tokens-lib) + (ctob/update-token-in-set + set-name + name + (fn [old-token] + (ctob/make-token (merge old-token token))))))) (defmethod process-change :del-token [data {:keys [set-name name]}] - (-> data - (update :tokens-lib - #(-> % - (ctob/ensure-tokens-lib) - (ctob/delete-token-from-set - set-name - name))))) + (update data :tokens-lib #(-> % + (ctob/ensure-tokens-lib) + (ctob/delete-token-from-set + set-name + name)))) (defmethod process-change :add-temporary-token-theme [data {:keys [token-theme]}] - (-> data - (update :tokens-lib - #(-> % - (ctob/ensure-tokens-lib) - (ctob/add-theme (ctob/make-token-theme token-theme)))))) + (update data :tokens-lib #(-> % + (ctob/ensure-tokens-lib) + (ctob/add-theme (ctob/make-token-theme token-theme))))) (defmethod process-change :update-active-token-themes [data {:keys [theme-ids]}] - (-> data - (update :tokens-lib #(-> % - (ctob/ensure-tokens-lib) - (ctob/set-active-themes theme-ids))))) + (update data :tokens-lib #(-> % (ctob/ensure-tokens-lib) + (ctob/set-active-themes theme-ids)))) (defmethod process-change :delete-temporary-token-theme [data {:keys [group name]}] - (-> data - (update :tokens-lib - #(-> % - (ctob/ensure-tokens-lib) - (ctob/delete-theme group name))))) + (update data :tokens-lib #(-> % + (ctob/ensure-tokens-lib) + (ctob/delete-theme group name)))) (defmethod process-change :add-token-theme [data {:keys [token-theme]}] - (-> data - (update :tokens-lib - #(-> % - (ctob/ensure-tokens-lib) - (ctob/add-theme (-> token-theme - (ctob/make-token-theme))))))) + (update data :tokens-lib #(-> % + (ctob/ensure-tokens-lib) + (ctob/add-theme (-> token-theme + (ctob/make-token-theme)))))) (defmethod process-change :mod-token-theme [data {:keys [name group token-theme]}] - (-> data - (update :tokens-lib - #(-> % - (ctob/ensure-tokens-lib) - (ctob/update-theme group name - (fn [prev-theme] - (merge prev-theme token-theme))))))) + (update data :tokens-lib #(-> % + (ctob/ensure-tokens-lib) + (ctob/update-theme group name + (fn [prev-theme] + (merge prev-theme token-theme)))))) (defmethod process-change :del-token-theme [data {:keys [group name]}] - (-> data - (update :tokens-lib - #(-> % - (ctob/ensure-tokens-lib) - (ctob/delete-theme group name))))) + (update data :tokens-lib #(-> % + (ctob/ensure-tokens-lib) + (ctob/delete-theme group name)))) (defmethod process-change :add-token-set [data {:keys [token-set]}] - (-> data - (update :tokens-lib - #(-> % - (ctob/ensure-tokens-lib) - (ctob/add-set (ctob/make-token-set token-set)))))) + (update data :tokens-lib #(-> % + (ctob/ensure-tokens-lib) + (ctob/add-set (ctob/make-token-set token-set))))) (defmethod process-change :mod-token-set [data {:keys [name token-set]}] - (-> data - (update :tokens-lib - (fn [element] - (let [path-changed? (not= name (:name token-set)) - lib (-> element - (ctob/ensure-tokens-lib) - (ctob/update-set name (fn [prev-set] - (merge prev-set (dissoc token-set :tokens)))))] - (cond-> lib - path-changed? (ctob/update-set-name name (:name token-set)))))))) + (update data :tokens-lib (fn [element] + (let [path-changed? (not= name (:name token-set)) + lib (-> element + (ctob/ensure-tokens-lib) + (ctob/update-set name (fn [prev-set] + (merge prev-set (dissoc token-set :tokens)))))] + (cond-> lib + path-changed? (ctob/update-set-name name (:name token-set))))))) (defmethod process-change :del-token-set [data {:keys [name]}] - (-> data - (update :tokens-lib - #(-> % - (ctob/ensure-tokens-lib) - (ctob/delete-set name))))) + (update data :tokens-lib #(-> % + (ctob/ensure-tokens-lib) + (ctob/delete-set name)))) ;; === Operations (defmethod process-operation :set From b12d5938e0cbad010d13467b563ae14b17ff37d8 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 14:10:41 +0200 Subject: [PATCH 76/92] Replace generic arg name --- common/src/app/common/files/changes.cljc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index 4241c42a0..ec8bb4775 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -856,13 +856,13 @@ (defmethod process-change :mod-token-set [data {:keys [name token-set]}] - (update data :tokens-lib (fn [element] + (update data :tokens-lib (fn [lib] (let [path-changed? (not= name (:name token-set)) - lib (-> element - (ctob/ensure-tokens-lib) - (ctob/update-set name (fn [prev-set] - (merge prev-set (dissoc token-set :tokens)))))] - (cond-> lib + lib' (-> lib + (ctob/ensure-tokens-lib) + (ctob/update-set name (fn [prev-set] + (merge prev-set (dissoc token-set :tokens)))))] + (cond-> lib' path-changed? (ctob/update-set-name name (:name token-set))))))) (defmethod process-change :del-token-set From bbdc9e95f7b9bc8741be3e50004d038440c7d735 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 14:17:20 +0200 Subject: [PATCH 77/92] Add todo --- common/src/app/common/types/tokens_lib.cljc | 1 + 1 file changed, 1 insertion(+) diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index 53b47f7bf..f202de931 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -653,6 +653,7 @@ tokens (order-theme-set theme))) (d/ordered-map) active-themes))) + ;; TODO Move to `update-set` (update-set-name [_ old-set-name new-set-name] (TokensLib. sets set-groups From 4a818d55c8656594455cd754f1a8cc55ed8d3203 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 14:18:49 +0200 Subject: [PATCH 78/92] Rename, fix docstring --- common/src/app/common/types/tokens_lib.cljc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index f202de931..670baffce 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -241,7 +241,7 @@ (set-count [_] "get the total number if sets in the library") (get-set-tree [_] "get a nested tree of all sets in the library") (get-sets [_] "get an ordered sequence of all sets in the library") - (get-sets-order [_] "get an ordered sequence of all sets in the library") + (get-ordered-set-names [_] "get an ordered sequence of all sets names in the library") (get-set [_ set-name] "get one set looking for name") (get-set-group [_ set-group-path] "get the attributes of a set group")) @@ -485,7 +485,7 @@ (->> (tree-seq d/ordered-map? vals sets) (filter (partial instance? TokenSet)))) - (get-sets-order [this] + (get-ordered-set-names [this] (map :name (get-sets this))) (set-count [this] @@ -641,7 +641,7 @@ (get-active-themes this))) (get-active-themes-set-tokens [this] - (let [sets-order (get-sets-order this) + (let [sets-order (get-ordered-set-names this) active-themes (get-active-themes this) order-theme-set (fn [theme] (filter #(contains? (set (:sets theme)) %) sets-order))] From 5170d328bdd0b06d03b5503bd424696ca874645c Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 14:19:02 +0200 Subject: [PATCH 79/92] Fix docstring --- common/src/app/common/types/tokens_lib.cljc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index 670baffce..056a18cd0 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -152,7 +152,7 @@ (add-token [_ token] "add a token at the end of the list") (update-token [_ token-name f] "update a token in the list") (delete-token [_ token-name] "delete a token from the list") - (get-token [_ token-name] "return an ordered sequence of all tokens in the set") + (get-token [_ token-name] "return token by token-name") (get-tokens [_] "return an ordered sequence of all tokens in the set")) (defrecord TokenSet [name description modified-at tokens] From 306a5e5f8513811ccc6b8d988493006a10bd16e4 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 14:20:27 +0200 Subject: [PATCH 80/92] Sets don't have a specific order inside themes --- common/src/app/common/types/tokens_lib.cljc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index 056a18cd0..d9a5c95a0 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -327,8 +327,7 @@ [:description [:maybe :string]] [:is-source :boolean] [:modified-at ::sm/inst] - [:sets [:and [:set {:gen/max 5} :string] - [:fn d/ordered-set?]]]] + [:sets [:set {:gen/max 5} :string]]] [:fn (partial instance? TokenTheme)]]) (sm/register! ::token-theme schema:token-theme) @@ -353,7 +352,7 @@ (update :group #(or % top-level-theme-group-name)) (update :is-source #(or % false)) (update :modified-at #(or % (dt/now))) - (update :sets #(into (d/ordered-set) %))) + (update :sets #(into #{} %))) token-theme (map->TokenTheme params)] (dm/assert! From 2b6075d1a208c8bab4cb15e85b287d50c741b646 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 14:21:18 +0200 Subject: [PATCH 81/92] Cleanup --- frontend/src/app/main/data/tokens.cljs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index 0100f8360..c725f68a0 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -155,9 +155,7 @@ ptk/WatchEvent (watch [it state _] (let [changes (-> (pcb/empty-changes it) - (pcb/add-token-set new-token-set) - #_(ensure-token-theme-changes state {:id (:id new-token-set) - :new-set? true}))] + (pcb/add-token-set new-token-set))] (rx/of (set-selected-token-set-id (:name new-token-set)) (dch/commit-changes changes))))))) From fa6b8cb6deb056de003d527bee7af7b9fb219380 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 14:31:56 +0200 Subject: [PATCH 82/92] Use d/nilf --- frontend/src/app/main/refs.cljs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index 3e86ec33a..8bf9a7c75 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -449,7 +449,7 @@ (l/derived :tokens-lib workspace-data)) (def workspace-token-theme-groups - (l/derived #(some-> % ctob/get-theme-groups) tokens-lib)) + (l/derived (d/nilf ctob/get-theme-groups) tokens-lib)) (defn workspace-token-theme [group name] @@ -481,13 +481,13 @@ (l/derived #(or (some-> % ctob/get-sets) []) tokens-lib)) (def workspace-active-theme-paths - (l/derived #(some-> % ctob/get-active-theme-paths) tokens-lib)) + (l/derived (d/nilf ctob/get-active-theme-paths) tokens-lib)) (def workspace-active-theme-paths-no-hidden (l/derived #(disj % ctob/hidden-token-theme-path) workspace-active-theme-paths)) (def workspace-active-set-names - (l/derived #(some-> % ctob/get-active-themes-set-names) tokens-lib)) + (l/derived (d/nilf ctob/get-active-themes-set-names) tokens-lib)) (def workspace-active-theme-sets-tokens (l/derived #(or (some-> % ctob/get-active-themes-set-tokens) {}) tokens-lib)) From 2634388d096556b4c0bebc6e48eefa2ed4a78b30 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 14:37:24 +0200 Subject: [PATCH 83/92] Remove logging --- frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs index df481aa25..f75bb4ba8 100644 --- a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs @@ -135,8 +135,7 @@ (let [theme (-> @theme-state (update :name str/trim) (update :group str/trim) - (update :description str/trim) - (doto js/console.log))] + (update :description str/trim))] (when-not (str/empty? (:name theme)) (on-submit theme))) (on-back)))] From e55f323d60c2aae48e6d9cb39b41e10a3c48b64a Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 15:47:59 +0200 Subject: [PATCH 84/92] Fix tests --- common/test/common_tests/types/tokens_lib_test.cljc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/test/common_tests/types/tokens_lib_test.cljc b/common/test/common_tests/types/tokens_lib_test.cljc index 945504e69..072f71382 100644 --- a/common/test/common_tests/types/tokens_lib_test.cljc +++ b/common/test/common_tests/types/tokens_lib_test.cljc @@ -344,7 +344,7 @@ :value true))) - expected-order (ctob/get-sets-order tokens-lib) + expected-order (ctob/get-ordered-set-names tokens-lib) expected-tokens (ctob/get-active-themes-set-tokens tokens-lib) expected-token-names (mapv key expected-tokens)] (t/is (= '("set-a" "set-b" "inactive-set") expected-order)) From eceffda095b5016727c81cddb1db61936c94978b Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 16:47:17 +0200 Subject: [PATCH 85/92] Added todo --- common/src/app/common/types/token.cljc | 1 + 1 file changed, 1 insertion(+) diff --git a/common/src/app/common/types/token.cljc b/common/src/app/common/types/token.cljc index 7dc03a305..ea8744d68 100644 --- a/common/src/app/common/types/token.cljc +++ b/common/src/app/common/types/token.cljc @@ -58,6 +58,7 @@ [n] (string? n)) +;; TODO Move this to tokens-lib (sm/register! ::token [:map {:title "Token"} [:name token-name-ref] From 1df40ea07a918ebd0a03935df79a2da0737ce216 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 16:57:20 +0200 Subject: [PATCH 86/92] Restore apply-tokens test --- frontend/test/token_tests/helpers/state.cljs | 10 +-- frontend/test/token_tests/helpers/tokens.cljs | 2 +- .../token_tests/logic/token_actions_test.cljs | 62 ++++++++++--------- 3 files changed, 39 insertions(+), 35 deletions(-) diff --git a/frontend/test/token_tests/helpers/state.cljs b/frontend/test/token_tests/helpers/state.cljs index 283c3125f..789de7049 100644 --- a/frontend/test/token_tests/helpers/state.cljs +++ b/frontend/test/token_tests/helpers/state.cljs @@ -1,5 +1,6 @@ (ns token-tests.helpers.state (:require + [app.common.types.tokens-lib :as ctob] [app.main.ui.workspace.tokens.style-dictionary :as sd] [beicon.v2.core :as rx] [potok.v2.core :as ptk])) @@ -21,11 +22,10 @@ (ptk/reify ::end+ ptk/WatchEvent (watch [_ state _] - (->> (rx/from (sd/resolve-tokens+ (get-in state [:workspace-data :tokens]))) - (rx/mapcat - (fn [_] - (rx/of - (end)))))))) + (->> (rx/from (-> (get-in state [:workspace-data :tokens-lib]) + (ctob/get-active-themes-set-tokens) + (sd/resolve-tokens+ {:names-map? true}))) + (rx/mapcat #(rx/of (end))))))) (defn stop-on "Helper function to be used with async version of run-store. diff --git a/frontend/test/token_tests/helpers/tokens.cljs b/frontend/test/token_tests/helpers/tokens.cljs index df222f83a..73cf124fc 100644 --- a/frontend/test/token_tests/helpers/tokens.cljs +++ b/frontend/test/token_tests/helpers/tokens.cljs @@ -10,7 +10,7 @@ (update-in state [:data :tokens] assoc id token))) (defn get-token [file name] - (some-> (get-in file [:data :tokens-li]) + (some-> (get-in file [:data :tokens-lib]) (ctob/get-active-themes-set-tokens) (get name))) diff --git a/frontend/test/token_tests/logic/token_actions_test.cljs b/frontend/test/token_tests/logic/token_actions_test.cljs index 140cbd318..5f0f22f04 100644 --- a/frontend/test/token_tests/logic/token_actions_test.cljs +++ b/frontend/test/token_tests/logic/token_actions_test.cljs @@ -1,18 +1,20 @@ (ns token-tests.logic.token-actions-test (:require - [token-tests.helpers.state :as tohs] [app.common.logging :as log] [app.common.test-helpers.compositions :as ctho] - [app.main.ui.workspace.tokens.changes :as wtch] [app.common.test-helpers.files :as cthf] - [app.common.types.tokens-lib :as ctob] - [cljs.test :as t :include-macros true] [app.common.test-helpers.shapes :as cths] - [frontend-tests.helpers.state :as ths] + [app.common.types.tokens-lib :as ctob] + [app.main.ui.workspace.tokens.changes :as wtch] + [cljs.pprint :as pprint] + [cljs.test :as t :include-macros true] [frontend-tests.helpers.pages :as thp] + [frontend-tests.helpers.state :as ths] + [token-tests.helpers.state :as tohs] [token-tests.helpers.tokens :as toht])) + (t/use-fixtures :each {:before (fn [] ;; Ignore rxjs async errors @@ -40,34 +42,36 @@ (ctho/add-rect :rect-3 rect-3) (assoc-in [:data :tokens-lib] (-> (ctob/make-tokens-lib) + (ctob/add-theme (ctob/make-token-theme :name "Theme A" :sets #{"Set A"})) + (ctob/set-active-themes #{"/Theme A"}) (ctob/add-set (ctob/make-token-set :name "Set A")) (ctob/add-token-in-set "Set A" (ctob/make-token border-radius-token)) (ctob/add-token-in-set "Set A" (ctob/make-token reference-border-radius-token)))))) -;; (t/deftest test-apply-token -;; (t/testing "applies token to shape and updates shape attributes to resolved value" -;; (t/async -;; done -;; (let [file (setup-file-with-tokens) -;; store (ths/setup-store file) -;; rect-1 (cths/get-shape file :rect-1) -;; events [(wtch/apply-token {:shape-ids [(:id rect-1)] -;; :attributes #{:rx :ry} -;; :token (toht/get-token file :token-2) -;; :on-update-shape wtch/update-shape-radius-all})]] -;; (tohs/run-store-async -;; store done events -;; (fn [new-state] -;; (let [file' (ths/get-file-from-store new-state) -;; token-2' (toht/get-token file' :token-2) -;; rect-1' (cths/get-shape file' :rect-1)] -;; (t/testing "shape `:applied-tokens` got updated" -;; (t/is (some? (:applied-tokens rect-1'))) -;; (t/is (= (:rx (:applied-tokens rect-1')) (wtt/token-identifier token-2'))) -;; (t/is (= (:ry (:applied-tokens rect-1')) (wtt/token-identifier token-2')))) -;; (t/testing "shape radius got update to the resolved token value." -;; (t/is (= (:rx rect-1') 24)) -;; (t/is (= (:ry rect-1') 24)))))))))) +(t/deftest test-apply-token + (t/testing "applies token to shape and updates shape attributes to resolved value" + (t/async + done + (let [file (setup-file-with-tokens) + store (ths/setup-store file) + rect-1 (cths/get-shape file :rect-1) + events [(wtch/apply-token {:shape-ids [(:id rect-1)] + :attributes #{:rx :ry} + :token (toht/get-token file "borderRadius.md") + :on-update-shape wtch/update-shape-radius-all})]] + (tohs/run-store-async + store done events + (fn [new-state] + (let [file' (ths/get-file-from-store new-state) + token (toht/get-token file' "borderRadius.md") + rect-1' (cths/get-shape file' :rect-1)] + (t/testing "shape `:applied-tokens` got updated" + (t/is (some? (:applied-tokens rect-1'))) + (t/is (= (:rx (:applied-tokens rect-1')) (:name token))) + (t/is (= (:ry (:applied-tokens rect-1')) (:name token)))) + (t/testing "shape radius got update to the resolved token value." + (t/is (= (:rx rect-1') 24)) + (t/is (= (:ry rect-1') 24)))))))))) ;; (t/deftest test-apply-multiple-tokens ;; (t/testing "applying a token twice with the same attributes will override the previously applied tokens values" From f2900c6519090aea32ce99eaa9e1b047a44ddbb8 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 16:57:53 +0200 Subject: [PATCH 87/92] Cleanup: Sort --- .../ui/workspace/sidebar/options/menus/layout_container.cljs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 47b3a8c87..d3d95ca1a 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 @@ -11,6 +11,7 @@ [app.common.data.macros :as dm] [app.common.math :as mth] [app.common.types.shape.layout :as ctl] + [app.common.types.tokens-lib :as ctob] [app.config :as cf] [app.main.data.events :as-alias ev] [app.main.data.workspace :as udw] @@ -37,8 +38,7 @@ [app.util.i18n :as i18n :refer [tr]] [app.util.keyboard :as kbd] [cuerdas.core :as str] - [rumext.v2 :as mf] - [app.common.types.tokens-lib :as ctob])) + [rumext.v2 :as mf])) (defn- dir-icons-refactor [val] From f9a49f82f82df884172e5617c8a40abe61b4417b Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 17:00:31 +0200 Subject: [PATCH 88/92] Restore apply-multiple --- .../token_tests/logic/token_actions_test.cljs | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/frontend/test/token_tests/logic/token_actions_test.cljs b/frontend/test/token_tests/logic/token_actions_test.cljs index 5f0f22f04..f0a89c13a 100644 --- a/frontend/test/token_tests/logic/token_actions_test.cljs +++ b/frontend/test/token_tests/logic/token_actions_test.cljs @@ -73,34 +73,34 @@ (t/is (= (:rx rect-1') 24)) (t/is (= (:ry rect-1') 24)))))))))) -;; (t/deftest test-apply-multiple-tokens -;; (t/testing "applying a token twice with the same attributes will override the previously applied tokens values" -;; (t/async -;; done -;; (let [file (setup-file-with-tokens) -;; store (ths/setup-store file) -;; rect-1 (cths/get-shape file :rect-1) -;; events [(wtch/apply-token {:shape-ids [(:id rect-1)] -;; :attributes #{:rx :ry} -;; :token (toht/get-token file :token-1) -;; :on-update-shape wtch/update-shape-radius-all}) -;; (wtch/apply-token {:shape-ids [(:id rect-1)] -;; :attributes #{:rx :ry} -;; :token (toht/get-token file :token-2) -;; :on-update-shape wtch/update-shape-radius-all})]] -;; (tohs/run-store-async -;; store done events -;; (fn [new-state] -;; (let [file' (ths/get-file-from-store new-state) -;; token-2' (toht/get-token file' :token-2) -;; rect-1' (cths/get-shape file' :rect-1)] -;; (t/testing "shape `:applied-tokens` got updated" -;; (t/is (some? (:applied-tokens rect-1'))) -;; (t/is (= (:rx (:applied-tokens rect-1')) (wtt/token-identifier token-2'))) -;; (t/is (= (:ry (:applied-tokens rect-1')) (wtt/token-identifier token-2')))) -;; (t/testing "shape radius got update to the resolved token value." -;; (t/is (= (:rx rect-1') 24)) -;; (t/is (= (:ry rect-1') 24)))))))))) +(t/deftest test-apply-multiple-tokens + (t/testing "applying a token twice with the same attributes will override the previously applied tokens values" + (t/async + done + (let [file (setup-file-with-tokens) + store (ths/setup-store file) + rect-1 (cths/get-shape file :rect-1) + events [(wtch/apply-token {:shape-ids [(:id rect-1)] + :attributes #{:rx :ry} + :token (toht/get-token file "borderRadius.sm") + :on-update-shape wtch/update-shape-radius-all}) + (wtch/apply-token {:shape-ids [(:id rect-1)] + :attributes #{:rx :ry} + :token (toht/get-token file "borderRadius.md") + :on-update-shape wtch/update-shape-radius-all})]] + (tohs/run-store-async + store done events + (fn [new-state] + (let [file' (ths/get-file-from-store new-state) + token (toht/get-token file' "borderRadius.md") + rect-1' (cths/get-shape file' :rect-1)] + (t/testing "shape `:applied-tokens` got updated" + (t/is (some? (:applied-tokens rect-1'))) + (t/is (= (:rx (:applied-tokens rect-1')) (:name token))) + (t/is (= (:ry (:applied-tokens rect-1')) (:name token)))) + (t/testing "shape radius got update to the resolved token value." + (t/is (= (:rx rect-1') 24)) + (t/is (= (:ry rect-1') 24)))))))))) ;; (t/deftest test-apply-token-overwrite ;; (t/testing "removes old token attributes and applies only single attribute" From 1097c1f28254a2e0a7d0b7173fe9f625cb973f01 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 17:02:10 +0200 Subject: [PATCH 89/92] Restore apply overwrite --- .../token_tests/logic/token_actions_test.cljs | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/frontend/test/token_tests/logic/token_actions_test.cljs b/frontend/test/token_tests/logic/token_actions_test.cljs index f0a89c13a..d69599732 100644 --- a/frontend/test/token_tests/logic/token_actions_test.cljs +++ b/frontend/test/token_tests/logic/token_actions_test.cljs @@ -102,39 +102,39 @@ (t/is (= (:rx rect-1') 24)) (t/is (= (:ry rect-1') 24)))))))))) -;; (t/deftest test-apply-token-overwrite -;; (t/testing "removes old token attributes and applies only single attribute" -;; (t/async -;; done -;; (let [file (setup-file-with-tokens) -;; store (ths/setup-store file) -;; rect-1 (cths/get-shape file :rect-1) -;; events [;; Apply `:token-1` to all border radius attributes -;; (wtch/apply-token {:attributes #{:rx :ry :r1 :r2 :r3 :r4} -;; :token (toht/get-token file :token-1) -;; :shape-ids [(:id rect-1)] -;; :on-update-shape wtch/update-shape-radius-all}) -;; ;; Apply single `:r1` attribute to same shape -;; ;; while removing other attributes from the border-radius set -;; ;; but keep `:r4` for testing purposes -;; (wtch/apply-token {:attributes #{:r1} -;; :attributes-to-remove #{:rx :ry :r1 :r2 :r3} -;; :token (toht/get-token file :token-2) -;; :shape-ids [(:id rect-1)] -;; :on-update-shape wtch/update-shape-radius-all})]] -;; (tohs/run-store-async -;; store done events -;; (fn [new-state] -;; (let [file' (ths/get-file-from-store new-state) -;; token-1' (toht/get-token file' :token-1) -;; token-2' (toht/get-token file' :token-2) -;; rect-1' (cths/get-shape file' :rect-1)] -;; (t/testing "other border-radius attributes got removed" -;; (t/is (nil? (:rx (:applied-tokens rect-1'))))) -;; (t/testing "r1 got applied with :token-2" -;; (t/is (= (:r1 (:applied-tokens rect-1')) (wtt/token-identifier token-2')))) -;; (t/testing "while :r4 was kept" -;; (t/is (= (:r4 (:applied-tokens rect-1')) (wtt/token-identifier token-1')))))))))));))))))))))) +(t/deftest test-apply-token-overwrite + (t/testing "removes old token attributes and applies only single attribute" + (t/async + done + (let [file (setup-file-with-tokens) + store (ths/setup-store file) + rect-1 (cths/get-shape file :rect-1) + events [;; Apply "borderRadius.sm" to all border radius attributes + (wtch/apply-token {:attributes #{:rx :ry :r1 :r2 :r3 :r4} + :token (toht/get-token file "borderRadius.sm") + :shape-ids [(:id rect-1)] + :on-update-shape wtch/update-shape-radius-all}) + ;; Apply single `:r1` attribute to same shape + ;; while removing other attributes from the border-radius set + ;; but keep `:r4` for testing purposes + (wtch/apply-token {:attributes #{:r1} + :attributes-to-remove #{:rx :ry :r1 :r2 :r3} + :token (toht/get-token file "borderRadius.md") + :shape-ids [(:id rect-1)] + :on-update-shape wtch/update-shape-radius-all})]] + (tohs/run-store-async + store done events + (fn [new-state] + (let [file' (ths/get-file-from-store new-state) + token-sm (toht/get-token file' "borderRadius.sm") + token-md (toht/get-token file' "borderRadius.md") + rect-1' (cths/get-shape file' :rect-1)] + (t/testing "other border-radius attributes got removed" + (t/is (nil? (:rx (:applied-tokens rect-1'))))) + (t/testing "r1 got applied with borderRadius.md" + (t/is (= (:r1 (:applied-tokens rect-1')) (:name token-md)))) + (t/testing "while :r4 was kept with borderRadius.sm" + (t/is (= (:r4 (:applied-tokens rect-1')) (:name token-sm))))))))))) ;; (t/deftest test-apply-dimensions ;; (t/testing "applies dimensions token and updates the shapes width and height" From 921f4a666073d62348321a4f7d2a61659ea7fbd6 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 17:10:07 +0200 Subject: [PATCH 90/92] Restore all logic tests --- .../token_tests/logic/token_actions_test.cljs | 525 ++++++++++-------- 1 file changed, 283 insertions(+), 242 deletions(-) diff --git a/frontend/test/token_tests/logic/token_actions_test.cljs b/frontend/test/token_tests/logic/token_actions_test.cljs index d69599732..720dfbef7 100644 --- a/frontend/test/token_tests/logic/token_actions_test.cljs +++ b/frontend/test/token_tests/logic/token_actions_test.cljs @@ -136,261 +136,302 @@ (t/testing "while :r4 was kept with borderRadius.sm" (t/is (= (:r4 (:applied-tokens rect-1')) (:name token-sm))))))))))) -;; (t/deftest test-apply-dimensions -;; (t/testing "applies dimensions token and updates the shapes width and height" -;; (t/async -;; done -;; (let [file (-> (setup-file-with-tokens) -;; (toht/add-token :token-target {:value "100" -;; :name "dimensions.sm" -;; :type :dimensions})) -;; store (ths/setup-store file) -;; rect-1 (cths/get-shape file :rect-1) -;; events [(wtch/apply-token {:shape-ids [(:id rect-1)] -;; :attributes #{:width :height} -;; :token (toht/get-token file :token-target) -;; :on-update-shape wtch/update-shape-dimensions})]] -;; (tohs/run-store-async -;; store done events -;; (fn [new-state] -;; (let [file' (ths/get-file-from-store new-state) -;; token-target' (toht/get-token file' :token-target) -;; rect-1' (cths/get-shape file' :rect-1)] -;; (t/testing "shape `:applied-tokens` got updated" -;; (t/is (some? (:applied-tokens rect-1'))) -;; (t/is (= (:width (:applied-tokens rect-1')) (wtt/token-identifier token-target'))) -;; (t/is (= (:height (:applied-tokens rect-1')) (wtt/token-identifier token-target')))) -;; (t/testing "shapes width and height got updated" -;; (t/is (= (:width rect-1') 100)) -;; (t/is (= (:height rect-1') 100)))))))))) +(t/deftest test-apply-dimensions + (t/testing "applies dimensions token and updates the shapes width and height" + (t/async + done + (let [file (-> (setup-file-with-tokens) + (toht/add-token :token-target {:value "100" + :name "dimensions.sm" + :type :dimensions})) + store (ths/setup-store file) + rect-1 (cths/get-shape file :rect-1) + events [(wtch/apply-token {:shape-ids [(:id rect-1)] + :attributes #{:width :height} + :token (toht/get-token file :token-target) + :on-update-shape wtch/update-shape-dimensions})]] + (tohs/run-store-async + store done events + (fn [new-state] + (let [file' (ths/get-file-from-store new-state) + token-target' (toht/get-token file' :token-target) + rect-1' (cths/get-shape file' :rect-1)] + (t/testing "shape `:applied-tokens` got updated" + (t/is (some? (:applied-tokens rect-1'))) + (t/is (= (:width (:applied-tokens rect-1')) (wtt/token-identifier token-target'))) + (t/is (= (:height (:applied-tokens rect-1')) (wtt/token-identifier token-target')))) + (t/testing "shapes width and height got updated" + (t/is (= (:width rect-1') 100)) + (t/is (= (:height rect-1') 100)))))))))) -;; (t/deftest test-apply-sizing -;; (t/testing "applies sizing token and updates the shapes width and height" -;; (t/async -;; done -;; (let [file (-> (setup-file-with-tokens) -;; (toht/add-token :token-target {:value "100" -;; :name "sizing.sm" -;; :type :sizing})) -;; store (ths/setup-store file) -;; rect-1 (cths/get-shape file :rect-1) -;; events [(wtch/apply-token {:shape-ids [(:id rect-1)] -;; :attributes #{:width :height} -;; :token (toht/get-token file :token-target) -;; :on-update-shape wtch/update-shape-dimensions})]] -;; (tohs/run-store-async -;; store done events -;; (fn [new-state] -;; (let [file' (ths/get-file-from-store new-state) -;; token-target' (toht/get-token file' :token-target) -;; rect-1' (cths/get-shape file' :rect-1)] -;; (t/testing "shape `:applied-tokens` got updated" -;; (t/is (some? (:applied-tokens rect-1'))) -;; (t/is (= (:width (:applied-tokens rect-1')) (wtt/token-identifier token-target'))) -;; (t/is (= (:height (:applied-tokens rect-1')) (wtt/token-identifier token-target')))) -;; (t/testing "shapes width and height got updated" -;; (t/is (= (:width rect-1') 100)) -;; (t/is (= (:height rect-1') 100)))))))))) +(t/deftest test-apply-dimensions + (t/testing "applies dimensions token and updates the shapes width and height" + (t/async + done + (let [dimensions-token {:name "dimensions.sm" + :value "100" + :type :dimensions} + file (-> (setup-file-with-tokens) + (update-in [:data :tokens-lib] + #(ctob/add-token-in-set % "Set A" (ctob/make-token dimensions-token)))) + store (ths/setup-store file) + rect-1 (cths/get-shape file :rect-1) + events [(wtch/apply-token {:shape-ids [(:id rect-1)] + :attributes #{:width :height} + :token (toht/get-token file "dimensions.sm") + :on-update-shape wtch/update-shape-dimensions})]] + (tohs/run-store-async + store done events + (fn [new-state] + (let [file' (ths/get-file-from-store new-state) + token-target' (toht/get-token file' "dimensions.sm") + rect-1' (cths/get-shape file' :rect-1)] + (t/testing "shape `:applied-tokens` got updated" + (t/is (some? (:applied-tokens rect-1'))) + (t/is (= (:width (:applied-tokens rect-1')) (:name token-target'))) + (t/is (= (:height (:applied-tokens rect-1')) (:name token-target')))) + (t/testing "shapes width and height got updated" + (t/is (= (:width rect-1') 100)) + (t/is (= (:height rect-1') 100)))))))))) -;; (t/deftest test-apply-opacity -;; (t/testing "applies opacity token and updates the shapes opacity" -;; (t/async -;; done -;; (let [file (-> (setup-file-with-tokens) -;; (toht/add-token :opacity-float {:value "0.3" -;; :name "opacity.float" -;; :type :opacity}) -;; (toht/add-token :opacity-percent {:value "40%" -;; :name "opacity.percent" -;; :type :opacity}) -;; (toht/add-token :opacity-invalid {:value "100" -;; :name "opacity.invalid" -;; :type :opacity})) -;; store (ths/setup-store file) -;; rect-1 (cths/get-shape file :rect-1) -;; rect-2 (cths/get-shape file :rect-2) -;; rect-3 (cths/get-shape file :rect-3) -;; events [(wtch/apply-token {:shape-ids [(:id rect-1)] -;; :attributes #{:opacity} -;; :token (toht/get-token file :opacity-float) -;; :on-update-shape wtch/update-opacity}) -;; (wtch/apply-token {:shape-ids [(:id rect-2)] -;; :attributes #{:opacity} -;; :token (toht/get-token file :opacity-percent) -;; :on-update-shape wtch/update-opacity}) -;; (wtch/apply-token {:shape-ids [(:id rect-3)] -;; :attributes #{:opacity} -;; :token (toht/get-token file :opacity-invalid) -;; :on-update-shape wtch/update-opacity})]] -;; (tohs/run-store-async -;; store done events -;; (fn [new-state] -;; (let [file' (ths/get-file-from-store new-state) -;; rect-1' (cths/get-shape file' :rect-1) -;; rect-2' (cths/get-shape file' :rect-2) -;; rect-3' (cths/get-shape file' :rect-3) -;; token-opacity-float (toht/get-token file' :opacity-float) -;; token-opacity-percent (toht/get-token file' :opacity-percent) -;; token-opacity-invalid (toht/get-token file' :opacity-invalid)] -;; (t/testing "float value got translated to float and applied to opacity" -;; (t/is (= (:opacity (:applied-tokens rect-1')) (wtt/token-identifier token-opacity-float))) -;; (t/is (= (:opacity rect-1') 0.3))) -;; (t/testing "percentage value got translated to float and applied to opacity" -;; (t/is (= (:opacity (:applied-tokens rect-2')) (wtt/token-identifier token-opacity-percent))) -;; (t/is (= (:opacity rect-2') 0.4))) -;; (t/testing "invalid opacity value got applied but did not change shape" -;; (t/is (= (:opacity (:applied-tokens rect-3')) (wtt/token-identifier token-opacity-invalid))) -;; (t/is (nil? (:opacity rect-3'))))))))))) +(t/deftest test-apply-sizing + (t/testing "applies sizing token and updates the shapes width and height" + (t/async + done + (let [sizing-token {:name "sizing.sm" + :value "100" + :type :sizing} + file (-> (setup-file-with-tokens) + (update-in [:data :tokens-lib] + #(ctob/add-token-in-set % "Set A" (ctob/make-token sizing-token)))) + store (ths/setup-store file) + rect-1 (cths/get-shape file :rect-1) + events [(wtch/apply-token {:shape-ids [(:id rect-1)] + :attributes #{:width :height} + :token (toht/get-token file "sizing.sm") + :on-update-shape wtch/update-shape-dimensions})]] + (tohs/run-store-async + store done events + (fn [new-state] + (let [file' (ths/get-file-from-store new-state) + token-target' (toht/get-token file' "sizing.sm") + rect-1' (cths/get-shape file' :rect-1)] + (t/testing "shape `:applied-tokens` got updated" + (t/is (some? (:applied-tokens rect-1'))) + (t/is (= (:width (:applied-tokens rect-1')) (:name token-target'))) + (t/is (= (:height (:applied-tokens rect-1')) (:name token-target')))) + (t/testing "shapes width and height got updated" + (t/is (= (:width rect-1') 100)) + (t/is (= (:height rect-1') 100)))))))))) -;; (t/deftest test-apply-rotation -;; (t/testing "applies rotation token and updates the shapes rotation" -;; (t/async -;; done -;; (let [file (-> (setup-file-with-tokens) -;; (toht/add-token :token-target {:value "120" -;; :name "rotation.medium" -;; :type :rotation})) -;; store (ths/setup-store file) -;; rect-1 (cths/get-shape file :rect-1) -;; events [(wtch/apply-token {:shape-ids [(:id rect-1)] -;; :attributes #{:rotation} -;; :token (toht/get-token file :token-target) -;; :on-update-shape wtch/update-rotation})]] -;; (tohs/run-store-async -;; store done events -;; (fn [new-state] -;; (let [file' (ths/get-file-from-store new-state) -;; token-target' (toht/get-token file' :token-target) -;; rect-1' (cths/get-shape file' :rect-1)] -;; (t/is (some? (:applied-tokens rect-1'))) -;; (t/is (= (:rotation (:applied-tokens rect-1')) (wtt/token-identifier token-target'))) -;; (t/is (= (:rotation rect-1') 120))))))))) +(t/deftest test-apply-opacity + (t/testing "applies opacity token and updates the shapes opacity" + (t/async + done + (let [opacity-float {:name "opacity.float" + :value "0.3" + :type :opacity} + opacity-percent {:name "opacity.percent" + :value "40%" + :type :opacity} + opacity-invalid {:name "opacity.invalid" + :value "100" + :type :opacity} + file (-> (setup-file-with-tokens) + (update-in [:data :tokens-lib] + #(-> % + (ctob/add-token-in-set "Set A" (ctob/make-token opacity-float)) + (ctob/add-token-in-set "Set A" (ctob/make-token opacity-percent)) + (ctob/add-token-in-set "Set A" (ctob/make-token opacity-invalid))))) + store (ths/setup-store file) + rect-1 (cths/get-shape file :rect-1) + rect-2 (cths/get-shape file :rect-2) + rect-3 (cths/get-shape file :rect-3) + events [(wtch/apply-token {:shape-ids [(:id rect-1)] + :attributes #{:opacity} + :token (toht/get-token file "opacity.float") + :on-update-shape wtch/update-opacity}) + (wtch/apply-token {:shape-ids [(:id rect-2)] + :attributes #{:opacity} + :token (toht/get-token file "opacity.percent") + :on-update-shape wtch/update-opacity}) + (wtch/apply-token {:shape-ids [(:id rect-3)] + :attributes #{:opacity} + :token (toht/get-token file "opacity.invalid") + :on-update-shape wtch/update-opacity})]] + (tohs/run-store-async + store done events + (fn [new-state] + (let [file' (ths/get-file-from-store new-state) + rect-1' (cths/get-shape file' :rect-1) + rect-2' (cths/get-shape file' :rect-2) + rect-3' (cths/get-shape file' :rect-3) + token-opacity-float (toht/get-token file' "opacity.float") + token-opacity-percent (toht/get-token file' "opacity.percent") + token-opacity-invalid (toht/get-token file' "opacity.invalid")] + (t/testing "float value got translated to float and applied to opacity" + (t/is (= (:opacity (:applied-tokens rect-1')) (:name token-opacity-float))) + (t/is (= (:opacity rect-1') 0.3))) + (t/testing "percentage value got translated to float and applied to opacity" + (t/is (= (:opacity (:applied-tokens rect-2')) (:name token-opacity-percent))) + (t/is (= (:opacity rect-2') 0.4))) + (t/testing "invalid opacity value got applied but did not change shape" + (t/is (= (:opacity (:applied-tokens rect-3')) (:name token-opacity-invalid))) + (t/is (nil? (:opacity rect-3'))))))))))) -;; (t/deftest test-apply-stroke-width -;; (t/testing "applies stroke-width token and updates the shapes with stroke" -;; (t/async -;; done -;; (let [file (-> (setup-file-with-tokens {:rect-1 {:strokes [{:stroke-alignment :inner, -;; :stroke-style :solid, -;; :stroke-color "#000000", -;; :stroke-opacity 1, -;; :stroke-width 5}]}}) -;; (toht/add-token :token-target {:value "10" -;; :name "stroke-width.sm" -;; :type :stroke-width})) -;; store (ths/setup-store file) -;; rect-with-stroke (cths/get-shape file :rect-1) -;; rect-without-stroke (cths/get-shape file :rect-2) -;; events [(wtch/apply-token {:shape-ids [(:id rect-with-stroke) (:id rect-without-stroke)] -;; :attributes #{:stroke-width} -;; :token (toht/get-token file :token-target) -;; :on-update-shape wtch/update-stroke-width})]] -;; (tohs/run-store-async -;; store done events -;; (fn [new-state] -;; (let [file' (ths/get-file-from-store new-state) -;; token-target' (toht/get-token file' :token-target) -;; rect-with-stroke' (cths/get-shape file' :rect-1) -;; rect-without-stroke' (cths/get-shape file' :rect-2)] -;; (t/testing "token got applied to rect with stroke and shape stroke got updated" -;; (t/is (= (:stroke-width (:applied-tokens rect-with-stroke')) (wtt/token-identifier token-target'))) -;; (t/is (= (get-in rect-with-stroke' [:strokes 0 :stroke-width]) 10))) -;; (t/testing "token got applied to rect without stroke but shape didnt get updated" -;; (t/is (= (:stroke-width (:applied-tokens rect-without-stroke')) (wtt/token-identifier token-target'))) -;; (t/is (empty? (:strokes rect-without-stroke'))))))))))) +(t/deftest test-apply-rotation + (t/testing "applies rotation token and updates the shapes rotation" + (t/async + done + (let [rotation-token {:name "rotation.medium" + :value "120" + :type :rotation} + file (-> (setup-file-with-tokens) + (update-in [:data :tokens-lib] + #(ctob/add-token-in-set % "Set A" (ctob/make-token rotation-token)))) + store (ths/setup-store file) + rect-1 (cths/get-shape file :rect-1) + events [(wtch/apply-token {:shape-ids [(:id rect-1)] + :attributes #{:rotation} + :token (toht/get-token file "rotation.medium") + :on-update-shape wtch/update-rotation})]] + (tohs/run-store-async + store done events + (fn [new-state] + (let [file' (ths/get-file-from-store new-state) + token-target' (toht/get-token file' "rotation.medium") + rect-1' (cths/get-shape file' :rect-1)] + (t/is (some? (:applied-tokens rect-1'))) + (t/is (= (:rotation (:applied-tokens rect-1')) (:name token-target'))) + (t/is (= (:rotation rect-1') 120))))))))) -;; (t/deftest test-toggle-token-none -;; (t/testing "should apply token to all selected items, where no item has the token applied" -;; (t/async -;; done -;; (let [file (setup-file-with-tokens) -;; store (ths/setup-store file) -;; rect-1 (cths/get-shape file :rect-1) -;; rect-2 (cths/get-shape file :rect-2) -;; events [(wtch/toggle-token {:shapes [rect-1 rect-2] -;; :token-type-props {:attributes #{:rx :ry} -;; :on-update-shape wtch/update-shape-radius-all} -;; :token (toht/get-token file :token-2)})]] -;; (tohs/run-store-async -;; store done events -;; (fn [new-state] -;; (let [file' (ths/get-file-from-store new-state) -;; token-2' (toht/get-token file' :token-2) -;; rect-1' (cths/get-shape file' :rect-1) -;; rect-2' (cths/get-shape file' :rect-2)] -;; (t/is (some? (:applied-tokens rect-1'))) -;; (t/is (some? (:applied-tokens rect-2'))) -;; (t/is (= (:rx (:applied-tokens rect-1')) (wtt/token-identifier token-2'))) -;; (t/is (= (:rx (:applied-tokens rect-2')) (wtt/token-identifier token-2'))) -;; (t/is (= (:ry (:applied-tokens rect-1')) (wtt/token-identifier token-2'))) -;; (t/is (= (:ry (:applied-tokens rect-2')) (wtt/token-identifier token-2'))) -;; (t/is (= (:rx rect-1') 24)) -;; (t/is (= (:rx rect-2') 24))))))))) +(t/deftest test-apply-stroke-width + (t/testing "applies stroke-width token and updates the shapes with stroke" + (t/async + done + (let [stroke-width-token {:name "stroke-width.sm" + :value "10" + :type :stroke-width} + file (-> (setup-file-with-tokens {:rect-1 {:strokes [{:stroke-alignment :inner, + :stroke-style :solid, + :stroke-color "#000000", + :stroke-opacity 1, + :stroke-width 5}]}}) + (update-in [:data :tokens-lib] + #(ctob/add-token-in-set % "Set A" (ctob/make-token stroke-width-token)))) + store (ths/setup-store file) + rect-with-stroke (cths/get-shape file :rect-1) + rect-without-stroke (cths/get-shape file :rect-2) + events [(wtch/apply-token {:shape-ids [(:id rect-with-stroke) (:id rect-without-stroke)] + :attributes #{:stroke-width} + :token (toht/get-token file "stroke-width.sm") + :on-update-shape wtch/update-stroke-width})]] + (tohs/run-store-async + store done events + (fn [new-state] + (let [file' (ths/get-file-from-store new-state) + token-target' (toht/get-token file' "stroke-width.sm") + rect-with-stroke' (cths/get-shape file' :rect-1) + rect-without-stroke' (cths/get-shape file' :rect-2)] + (t/testing "token got applied to rect with stroke and shape stroke got updated" + (t/is (= (:stroke-width (:applied-tokens rect-with-stroke')) (:name token-target'))) + (t/is (= (get-in rect-with-stroke' [:strokes 0 :stroke-width]) 10))) + (t/testing "token got applied to rect without stroke but shape didnt get updated" + (t/is (= (:stroke-width (:applied-tokens rect-without-stroke')) (:name token-target'))) + (t/is (empty? (:strokes rect-without-stroke'))))))))))) -;; (t/deftest test-toggle-token-mixed -;; (t/testing "should unapply given token if one of the selected items has the token applied while keeping other tokens with some attributes" -;; (t/async -;; done -;; (let [file (-> (setup-file-with-tokens) -;; (toht/apply-token-to-shape :rect-1 :token-1 #{:rx :ry}) -;; (toht/apply-token-to-shape :rect-3 :token-2 #{:rx :ry})) -;; store (ths/setup-store file) +(t/deftest test-toggle-token-none + (t/testing "should apply token to all selected items, where no item has the token applied" + (t/async + done + (let [file (setup-file-with-tokens) + store (ths/setup-store file) + rect-1 (cths/get-shape file :rect-1) + rect-2 (cths/get-shape file :rect-2) + events [(wtch/toggle-token {:shapes [rect-1 rect-2] + :token-type-props {:attributes #{:rx :ry} + :on-update-shape wtch/update-shape-radius-all} + :token (toht/get-token file "borderRadius.md")})]] + (tohs/run-store-async + store done events + (fn [new-state] + (let [file' (ths/get-file-from-store new-state) + token-2' (toht/get-token file' "borderRadius.md") + rect-1' (cths/get-shape file' :rect-1) + rect-2' (cths/get-shape file' :rect-2)] + (t/is (some? (:applied-tokens rect-1'))) + (t/is (some? (:applied-tokens rect-2'))) + (t/is (= (:rx (:applied-tokens rect-1')) (:name token-2'))) + (t/is (= (:rx (:applied-tokens rect-2')) (:name token-2'))) + (t/is (= (:ry (:applied-tokens rect-1')) (:name token-2'))) + (t/is (= (:ry (:applied-tokens rect-2')) (:name token-2'))) + (t/is (= (:rx rect-1') 24)) + (t/is (= (:rx rect-2') 24))))))))) -;; rect-with-token (cths/get-shape file :rect-1) -;; rect-without-token (cths/get-shape file :rect-2) -;; rect-with-other-token (cths/get-shape file :rect-3) +(t/deftest test-toggle-token-mixed + (t/testing "should unapply given token if one of the selected items has the token applied while keeping other tokens with some attributes" + (t/async + done + (let [file (-> (setup-file-with-tokens) + (toht/apply-token-to-shape :rect-1 "borderRadius.sm" #{:rx :ry}) + (toht/apply-token-to-shape :rect-3 "borderRadius.md" #{:rx :ry})) + store (ths/setup-store file) -;; events [(wtch/toggle-token {:shapes [rect-with-token rect-without-token rect-with-other-token] -;; :token (toht/get-token file :token-1) -;; :token-type-props {:attributes #{:rx :ry}}})]] -;; (tohs/run-store-async -;; store done events -;; (fn [new-state] -;; (let [file' (ths/get-file-from-store new-state) -;; rect-with-token' (cths/get-shape file' :rect-1) -;; rect-without-token' (cths/get-shape file' :rect-2) -;; rect-with-other-token' (cths/get-shape file' :rect-3)] + rect-with-token (cths/get-shape file :rect-1) + rect-without-token (cths/get-shape file :rect-2) + rect-with-other-token (cths/get-shape file :rect-3) -;; (t/testing "rect-with-token got the token remove" -;; (t/is (nil? (:rx (:applied-tokens rect-with-token')))) -;; (t/is (nil? (:ry (:applied-tokens rect-with-token'))))) + events [(wtch/toggle-token {:shapes [rect-with-token rect-without-token rect-with-other-token] + :token (toht/get-token file "borderRadius.sm") + :token-type-props {:attributes #{:rx :ry}}})]] + (tohs/run-store-async + store done events + (fn [new-state] + (let [file' (ths/get-file-from-store new-state) + rect-with-token' (cths/get-shape file' :rect-1) + rect-without-token' (cths/get-shape file' :rect-2) + rect-with-other-token' (cths/get-shape file' :rect-3)] -;; (t/testing "rect-without-token didn't get updated" -;; (t/is (= (:applied-tokens rect-without-token') (:applied-tokens rect-without-token)))) + (t/testing "rect-with-token got the token removed" + (t/is (nil? (:rx (:applied-tokens rect-with-token')))) + (t/is (nil? (:ry (:applied-tokens rect-with-token'))))) -;; (t/testing "rect-with-other-token didn't get updated" -;; (t/is (= (:applied-tokens rect-with-other-token') (:applied-tokens rect-with-other-token))))))))))) + (t/testing "rect-without-token didn't get updated" + (t/is (= (:applied-tokens rect-without-token') (:applied-tokens rect-without-token)))) -;; (t/deftest test-toggle-token-apply-to-all -;; (t/testing "should apply token to all if none of the shapes has it applied" -;; (t/async -;; done -;; (let [file (-> (setup-file-with-tokens) -;; (toht/apply-token-to-shape :rect-1 :token-2 #{:rx :ry}) -;; (toht/apply-token-to-shape :rect-3 :token-2 #{:rx :ry})) -;; store (ths/setup-store file) + (t/testing "rect-with-other-token didn't get updated" + (t/is (= (:applied-tokens rect-with-other-token') (:applied-tokens rect-with-other-token))))))))))) -;; rect-with-other-token-1 (cths/get-shape file :rect-1) -;; rect-without-token (cths/get-shape file :rect-2) -;; rect-with-other-token-2 (cths/get-shape file :rect-3) +(t/deftest test-toggle-token-apply-to-all + (t/testing "should apply token to all if none of the shapes has it applied" + (t/async + done + (let [file (-> (setup-file-with-tokens) + (toht/apply-token-to-shape :rect-1 "borderRadius.md" #{:rx :ry}) + (toht/apply-token-to-shape :rect-3 "borderRadius.md" #{:rx :ry})) + store (ths/setup-store file) -;; events [(wtch/toggle-token {:shapes [rect-with-other-token-1 rect-without-token rect-with-other-token-2] -;; :token (toht/get-token file :token-1) -;; :token-type-props {:attributes #{:rx :ry}}})]] -;; (tohs/run-store-async -;; store done events -;; (fn [new-state] -;; (let [file' (ths/get-file-from-store new-state) -;; target-token (toht/get-token file' :token-1) -;; rect-with-other-token-1' (cths/get-shape file' :rect-1) -;; rect-without-token' (cths/get-shape file' :rect-2) -;; rect-with-other-token-2' (cths/get-shape file' :rect-3)] + rect-with-other-token-1 (cths/get-shape file :rect-1) + rect-without-token (cths/get-shape file :rect-2) + rect-with-other-token-2 (cths/get-shape file :rect-3) -;; (t/testing "token got applied to all shapes" -;; (t/is (= (:rx (:applied-tokens rect-with-other-token-1')) (wtt/token-identifier target-token))) -;; (t/is (= (:rx (:applied-tokens rect-without-token')) (wtt/token-identifier target-token))) -;; (t/is (= (:rx (:applied-tokens rect-with-other-token-2')) (wtt/token-identifier target-token))) + events [(wtch/toggle-token {:shapes [rect-with-other-token-1 rect-without-token rect-with-other-token-2] + :token (toht/get-token file "borderRadius.sm") + :token-type-props {:attributes #{:rx :ry}}})]] + (tohs/run-store-async + store done events + (fn [new-state] + (let [file' (ths/get-file-from-store new-state) + target-token (toht/get-token file' "borderRadius.sm") + rect-with-other-token-1' (cths/get-shape file' :rect-1) + rect-without-token' (cths/get-shape file' :rect-2) + rect-with-other-token-2' (cths/get-shape file' :rect-3)] -;; (t/is (= (:ry (:applied-tokens rect-with-other-token-1')) (wtt/token-identifier target-token))) -;; (t/is (= (:ry (:applied-tokens rect-without-token')) (wtt/token-identifier target-token))) -;; (t/is (= (:ry (:applied-tokens rect-with-other-token-2')) (wtt/token-identifier target-token))))))))))) + (t/testing "token got applied to all shapes" + (t/is (= (:rx (:applied-tokens rect-with-other-token-1')) (:name target-token))) + (t/is (= (:rx (:applied-tokens rect-without-token')) (:name target-token))) + (t/is (= (:rx (:applied-tokens rect-with-other-token-2')) (:name target-token))) + + (t/is (= (:ry (:applied-tokens rect-with-other-token-1')) (:name target-token))) + (t/is (= (:ry (:applied-tokens rect-without-token')) (:name target-token))) + (t/is (= (:ry (:applied-tokens rect-with-other-token-2')) (:name target-token))))))))))) From d097b5b179fd42d8e843e1109e53a8f0099d306f Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 17:10:26 +0200 Subject: [PATCH 91/92] Cleanup --- frontend/test/token_tests/logic/token_actions_test.cljs | 3 --- 1 file changed, 3 deletions(-) diff --git a/frontend/test/token_tests/logic/token_actions_test.cljs b/frontend/test/token_tests/logic/token_actions_test.cljs index 720dfbef7..d710c9bf1 100644 --- a/frontend/test/token_tests/logic/token_actions_test.cljs +++ b/frontend/test/token_tests/logic/token_actions_test.cljs @@ -6,15 +6,12 @@ [app.common.test-helpers.shapes :as cths] [app.common.types.tokens-lib :as ctob] [app.main.ui.workspace.tokens.changes :as wtch] - [cljs.pprint :as pprint] [cljs.test :as t :include-macros true] [frontend-tests.helpers.pages :as thp] [frontend-tests.helpers.state :as ths] [token-tests.helpers.state :as tohs] [token-tests.helpers.tokens :as toht])) - - (t/use-fixtures :each {:before (fn [] ;; Ignore rxjs async errors From 69cc9d02ba126bdc4119775dc153069d9e28a5b7 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 17:23:04 +0200 Subject: [PATCH 92/92] Cleanup: item->token --- frontend/src/app/main/ui/workspace/tokens/core.cljs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/core.cljs b/frontend/src/app/main/ui/workspace/tokens/core.cljs index c37ace5a2..14c2df725 100644 --- a/frontend/src/app/main/ui/workspace/tokens/core.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/core.cljs @@ -25,16 +25,16 @@ (defn tokens->select-options [{:keys [shape tokens attributes selected-attributes]}] (map - (fn [{:keys [name] :as item}] - (cond-> (assoc item :label name) - (wtt/token-applied? item shape (or selected-attributes attributes)) (assoc :selected? true))) + (fn [{:keys [name] :as token}] + (cond-> (assoc token :label name) + (wtt/token-applied? token shape (or selected-attributes attributes)) (assoc :selected? true))) tokens)) (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))) + (fn [[_k {:keys [name] :as token}]] + (cond-> (assoc token :label name) + (wtt/token-applied? token shape (or selected-attributes attributes)) (assoc :selected? true))) tokens)) ;; JSON export functions -------------------------------------------------------