From 93bf198073fa23f87ad2925bc804bd5e1c3e9f8d Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 20 Mar 2025 13:21:33 +0100 Subject: [PATCH 1/5] :bug: Prevent theme replacement on ranaming --- frontend/src/app/main/data/tokens.cljs | 25 +++++++++++-------- frontend/src/app/main/data/workspace.cljs | 1 - .../ui/workspace/tokens/modals/themes.cljs | 15 ++++++----- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index 415c06bbb..7c234838f 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -91,16 +91,21 @@ (ptk/reify ::update-token-theme ptk/WatchEvent (watch [it state _] - (let [tokens-lib (get-tokens-lib state) - data (dsh/lookup-file-data state) - prev-token-theme (some-> tokens-lib (ctob/get-theme group name)) - changes (-> (pcb/empty-changes it) - (pcb/with-library-data data) - (pcb/set-token-theme (:group prev-token-theme) - (:name prev-token-theme) - token-theme))] - (rx/of - (dch/commit-changes changes)))))) + (let [data (dsh/lookup-file-data state) + tokens-lib (get data :tokens-lib)] + (if (and (or (not= group (:group token-theme)) + (not= name (:name token-theme))) + (ctob/get-theme tokens-lib + (:group token-theme) + (:name token-theme))) + (rx/of (ntf/show {:content (tr "errors.token-theme-already-exists") + :type :toast + :level :error + :timeout 9000})) + (let [changes (-> (pcb/empty-changes it) + (pcb/with-library-data data) + (pcb/set-token-theme group name token-theme))] + (rx/of (dch/commit-changes changes)))))))) (defn toggle-token-theme-active? [group name] (ptk/reify ::toggle-token-theme-active? diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 1f353c4ac..2c1a00620 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -253,7 +253,6 @@ (watch [_ state _] (let [team-id (:current-team-id state) file-id (:id file)] - (rx/of (dwn/initialize team-id file-id) (dwsl/initialize-shape-layout) (fetch-libraries file-id)))))) 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 cdeec2753..d07a99281 100644 --- a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs @@ -308,7 +308,6 @@ ;; Form / Modal handlers on-back #(set-state (constantly {:type :themes-overview})) - on-submit #(st/emit! (wdt/update-token-theme [(:group theme) (:name theme)] %)) disabled? (-> (:name theme-state) (str/trim) (str/empty?)) @@ -320,16 +319,16 @@ on-save-form (mf/use-fn - (mf/deps theme-state on-submit) + (mf/deps theme theme-state) (fn [e] (dom/prevent-default e) - (let [theme (-> theme-state - (update :name str/trim) - (update :group str/trim) - (update :description str/trim))] + (let [theme' (-> theme-state + (update :name str/trim) + (update :group str/trim) + (update :description str/trim))] (when-not (str/empty? (:name theme)) - (on-submit theme))) - (on-back))) + (st/emit! (wdt/update-token-theme [(:group theme) (:name theme)] theme'))) + (on-back)))) close-modal (mf/use-fn From c6bfae0d6340fce2657c5c48f5bc64a62b82d886 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 20 Mar 2025 13:36:27 +0100 Subject: [PATCH 2/5] :bug: Normalize set names on importing themes dtcg json --- common/src/app/common/types/tokens_lib.cljc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index e85cea19b..59d5f7580 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -1297,7 +1297,9 @@ Will return a value that matches this schema: (map (fn [theme] (-> theme (set/rename-keys {"selectedTokenSets" "sets"}) - (update "sets" keys))))) + (update "sets" keys) + (update "sets" #(map normalize-set-name %)))))) + active-sets (get metadata "activeSets") active-themes (get metadata "activeThemes") active-themes (if (empty? active-themes) From e8e9037ef1a904dcfd2b9969ff317d70eea1bfeb Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 20 Mar 2025 16:15:17 +0100 Subject: [PATCH 3/5] :bug: Fix inconsistencies on parsing tokens dtcg json --- common/src/app/common/types/tokens_lib.cljc | 127 ++++++++++++-------- 1 file changed, 78 insertions(+), 49 deletions(-) diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index 59d5f7580..369ffd37f 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -799,7 +799,7 @@ (map-indexed (fn [index item] (assoc item :index index)))))) -(defn flatten-nested-tokens-json +(defn- flatten-nested-tokens-json "Recursively flatten the dtcg token structure, joining keys with '.'." [tokens token-path] (reduce-kv @@ -1290,56 +1290,85 @@ Will return a value that matches this schema: (assoc-in ["$metadata" "activeThemes"] active-themes-clear) (assoc-in ["$metadata" "activeSets"] active-sets)))) - (decode-dtcg-json [_ parsed-json] - (let [metadata (get parsed-json "$metadata") - sets-data (dissoc parsed-json "$themes" "$metadata") - themes-data (->> (get parsed-json "$themes") - (map (fn [theme] - (-> theme - (set/rename-keys {"selectedTokenSets" "sets"}) - (update "sets" keys) - (update "sets" #(map normalize-set-name %)))))) + (decode-dtcg-json [_ data] + (assert (map? data) "expected a map data structure for `data`") - active-sets (get metadata "activeSets") - active-themes (get metadata "activeThemes") - active-themes (if (empty? active-themes) - #{hidden-token-theme-path} - active-themes) + (let [metadata (get data "$metadata") - set-order (get metadata "tokenSetOrder") - name->pos (into {} (map-indexed (fn [idx itm] [itm idx]) set-order)) - sets-data' (sort-by (comp name->pos first) sets-data) - lib (make-tokens-lib) - lib' (->> sets-data' - (reduce (fn [lib [set-name tokens]] - (add-set lib (make-token-set - :name set-name - :tokens (flatten-nested-tokens-json tokens "")))) - lib)) - lib' (cond-> lib' - (and (seq active-sets) (= #{hidden-token-theme-path} active-themes)) - (update-theme hidden-token-theme-group hidden-token-theme-name - #(assoc % :sets active-sets)))] - (if-let [themes-data (seq themes-data)] - (as-> lib' $ - (reduce - (fn [lib {:strs [name group description is-source id modified-at sets]}] - (add-theme lib (TokenTheme. name - (or group "") - description - (some? is-source) - (or id (str (uuid/next))) - (or (some-> modified-at - (dt/parse-instant)) - (dt/now)) - (set sets)))) - $ themes-data) - (reduce - (fn [lib active-theme] - (let [[group name] (split-token-theme-path active-theme)] - (activate-theme lib group name))) - $ active-themes)) - lib'))) + xf-normalize-set-name + (map normalize-set-name) + + sets + (dissoc data "$themes" "$metadata") + + ordered-sets + (-> (d/ordered-set) + (into xf-normalize-set-name (get metadata "tokenSetOrder")) + (into xf-normalize-set-name (keys sets))) + + active-sets + (or (->> (get metadata "activeSets") + (into #{} xf-normalize-set-name) + (not-empty)) + #{}) + + active-themes + (or (->> (get metadata "activeThemes") + (into #{}) + (not-empty)) + #{hidden-token-theme-path}) + + themes + (->> (get data "$themes") + (map (fn [theme] + (make-token-theme + :name (get theme "name") + :group (get theme "group") + :is-source (get theme "is-source") + :id (get theme "id") + :modified-at (some-> (get theme "modified-at") + (dt/parse-instant)) + :sets (into #{} + (comp (map key) + xf-normalize-set-name + (filter #(contains? ordered-sets %))) + (get theme "selectedTokenSets"))))) + (not-empty)) + + library + (make-tokens-lib) + + sets + (reduce-kv (fn [result name tokens] + (assoc result + (normalize-set-name name) + (flatten-nested-tokens-json tokens ""))) + {} + sets) + + library + (reduce (fn [library name] + (if-let [tokens (get sets name)] + (add-set library (make-token-set :name name :tokens tokens)) + library)) + library + ordered-sets) + + library + (update-theme library hidden-token-theme-group hidden-token-theme-name + #(assoc % :sets active-sets)) + + library + (reduce add-theme library themes) + + library + (reduce (fn [library theme-path] + (let [[group name] (split-token-theme-path theme-path)] + (activate-theme library group name))) + library + active-themes)] + + library)) (decode-legacy-json [this parsed-legacy-json] (let [other-data (select-keys parsed-legacy-json ["$themes" "$metadata"]) From e5319e04c773a62bdc158eb34f44a2bfe93c517e Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 20 Mar 2025 16:25:30 +0100 Subject: [PATCH 4/5] :recycle: Fix naming on token-set group move change operation --- common/src/app/common/files/changes.cljc | 14 +++++++------- common/src/app/common/files/changes_builder.cljc | 10 +++++----- common/src/app/common/logic/tokens.cljc | 6 +++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index 1a45f64bf..78845e8f4 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -390,13 +390,13 @@ [:before-path [:maybe [:vector :string]]] [:before-group [:maybe :boolean]]]] - [:move-token-set-group-before - [:map {:title "MoveTokenSetGroupBefore"} - [:type [:= :move-token-set-group-before]] + [:move-token-set-group + [:map {:title "MoveTokenSetGroup"} + [:type [:= :move-token-set-group]] [:from-path [:vector :string]] [:to-path [:vector :string]] [:before-path [:maybe [:vector :string]]] - [:before-group? [:maybe :boolean]]]] + [:before-group [:maybe :boolean]]]] [:set-token-theme [:map {:title "SetTokenThemeChange"} @@ -1057,11 +1057,11 @@ (ctob/ensure-tokens-lib) (ctob/move-set from-path to-path before-path before-group)))) -(defmethod process-change :move-token-set-group-before - [data {:keys [from-path to-path before-path before-group?]}] +(defmethod process-change :move-token-set-group + [data {:keys [from-path to-path before-path before-group]}] (update data :tokens-lib #(-> % (ctob/ensure-tokens-lib) - (ctob/move-set-group from-path to-path before-path before-group?)))) + (ctob/move-set-group from-path to-path before-path before-group)))) ;; === Operations diff --git a/common/src/app/common/files/changes_builder.cljc b/common/src/app/common/files/changes_builder.cljc index f955214d6..aa360d292 100644 --- a/common/src/app/common/files/changes_builder.cljc +++ b/common/src/app/common/files/changes_builder.cljc @@ -824,19 +824,19 @@ :before-group prev-before-group?}) (apply-changes-local))) -(defn move-token-set-group-before +(defn move-token-set-group [changes {:keys [from-path to-path before-path before-group? prev-before-path prev-before-group?]}] (-> changes - (update :redo-changes conj {:type :move-token-set-group-before + (update :redo-changes conj {:type :move-token-set-group :from-path from-path :to-path to-path :before-path before-path - :before-group? before-group?}) - (update :undo-changes conj {:type :move-token-set-group-before + :before-group before-group?}) + (update :undo-changes conj {:type :move-token-set-group :from-path to-path :to-path from-path :before-path prev-before-path - :before-group? prev-before-group?}) + :before-group prev-before-group?}) (apply-changes-local))) (defn set-tokens-lib diff --git a/common/src/app/common/logic/tokens.cljc b/common/src/app/common/logic/tokens.cljc index 50fdc7b8a..3e7ca4a08 100644 --- a/common/src/app/common/logic/tokens.cljc +++ b/common/src/app/common/logic/tokens.cljc @@ -140,7 +140,7 @@ (defn generate-move-token-set-group "Create changes for dropping a token set or token set group. Throws for impossible moves" - [changes tokens-lib drop-opts] - (if-let [drop-opts' (calculate-move-token-set-or-set-group tokens-lib drop-opts)] - (pcb/move-token-set-group-before changes drop-opts') + [changes tokens-lib params] + (if-let [params (calculate-move-token-set-or-set-group tokens-lib params)] + (pcb/move-token-set-group changes params) changes)) From 752f74767e9e2cacdd9d71a06eda3618837b5b27 Mon Sep 17 00:00:00 2001 From: Eva Marco Date: Fri, 21 Mar 2025 10:47:32 +0100 Subject: [PATCH 5/5] :bug: Fix error copy (#6132) --- frontend/translations/en.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/translations/en.po b/frontend/translations/en.po index 5b83d3672..3ac5cb4a3 100644 --- a/frontend/translations/en.po +++ b/frontend/translations/en.po @@ -6677,7 +6677,7 @@ msgstr "Opacity must be between 0 and 100% or 0 and 1 (e.g. 50% or 0.5)." #: src/app/main/ui/workspace/tokens/errors.cljs msgid "workspace.token.stroke-width-range" -msgstr "Stroke width must be between equal or bigger than 0." +msgstr "Stroke width must be greater than or equal to 0." #: src/app/main/ui/workspace/tokens/modals/themes.cljs:179 msgid "workspace.token.label.group"