From 4e607d8da24bfe8cac14c637a18143a9e2b33216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Fri, 19 Sep 2025 11:47:43 +0200 Subject: [PATCH] :lipstick: Clarify and reorder interfaces --- common/src/app/common/types/token.cljc | 21 +++ common/src/app/common/types/tokens_lib.cljc | 120 ++++++++---------- .../test/common_tests/logic/token_test.cljc | 48 +++---- .../common_tests/types/tokens_lib_test.cljc | 34 ++--- .../src/app/main/data/style_dictionary.cljs | 30 ++--- .../tokens/management/create/form.cljs | 32 ++--- 6 files changed, 149 insertions(+), 136 deletions(-) diff --git a/common/src/app/common/types/token.cljc b/common/src/app/common/types/token.cljc index cd4a4d8195..82fc167793 100644 --- a/common/src/app/common/types/token.cljc +++ b/common/src/app/common/types/token.cljc @@ -26,6 +26,27 @@ (mu/keys) (into #{}))) +(defn find-token-value-references + "Returns set of token references found in `token-value`. + + Used for checking if a token has a reference in the value. + Token references are strings delimited by curly braces. + E.g.: {foo.bar.baz} -> foo.bar.baz" + [token-value] + (if (string? token-value) + (some->> (re-seq #"\{([^}]*)\}" token-value) + (map second) + (into #{})) + #{})) + +(defn token-value-self-reference? + "Check if the token is self referencing with its `token-name` in `token-value`. + Simple 1 level check, doesn't account for circular self refernces across multiple tokens." + [token-name token-value] + (let [token-references (find-token-value-references token-value) + self-reference? (get token-references token-name)] + self-reference?)) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; SCHEMA ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index acf47d44eb..5f309ad519 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -182,27 +182,6 @@ [token] (get-path (:name token) token-separator)) -(defn find-token-value-references - "Returns set of token references found in `token-value`. - - Used for checking if a token has a reference in the value. - Token references are strings delimited by curly braces. - E.g.: {foo.bar.baz} -> foo.bar.baz" - [token-value] - (if (string? token-value) - (some->> (re-seq #"\{([^}]*)\}" token-value) - (map second) - (into #{})) - #{})) - -(defn token-value-self-reference? - "Check if the token is self referencing with its `token-name` in `token-value`. - Simple 1 level check, doesn't account for circular self refernces across multiple tokens." - [token-name token-value] - (let [token-references (find-token-value-references token-value) - self-reference? (get token-references token-name)] - self-reference?)) - (defn group-by-type [tokens] (let [tokens' (if (or (map? tokens) (d/ordered-map? tokens)) @@ -537,34 +516,33 @@ ;; === TokenSets (collection) (defprotocol ITokenSets - "Collection of sets and set groups. - - Naming conventions: - Set name: the complete name as a string, without prefix \"some-group/some-subgroup/some-set\". - Set final name or fname: the last part of the name \"some-set\". - Set path: the groups part of the name, as a vector [\"some-group\" \"some-subgroup\"]. - Set path str: the set path as a string \"some-group/some-subgroup\". - Set full path: the path including the fname, as a vector [\"some-group\", \"some-subgroup\", \"some-set\"]. - Set full path str: the set full path as a string \"some-group/some-subgroup/some-set\". - - Set prefix: the two-characters prefix added to a full path item \"G-\" / \"S-\". - Prefixed set path or ppath: a path wit added prefixes [\"G-some-group\", \"G-some-subgroup\"]. - Prefixed set full path or pfpath: a full path wit prefixes [\"G-some-group\", \"G-some-subgroup\", \"S-some-set\"]. - Prefixed set final name or pfname: a final name with prefix \"S-some-set\"." - (add-set [_ token-set] "add a set to the library, at the end") - (update-set [_ id f] "modify a set in the library") - (delete-set [_ id] "delete a set in the library and disable it in all themes") - (move-set [_ from-path to-path before-path before-group?] "Move token set at `from-path` to `to-path` and order it before `before-path` with `before-group?`.") - (move-set-group [_ from-path to-path before-path before-group?] "Move token set group at `from-path` to `to-path` and order it before `before-path` with `before-group?`.") - (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-at-prefix-path- [_ prefixed-path-str] "get an ordered sequence of sets at `prefixed-path-str` in the library") - (get-sets-at-path [_ path-str] "get an ordered sequence of sets at `path` in the library") - (rename-set-group [_ from-path-str to-path-str] "renames set groups and all child set names from `from-path-str` to `to-path-str`") - (get-ordered-set-names [_] "get an ordered sequence of all sets names in the library") - (get-set [_ id] "get a set looking by id") - (get-set-by-name [_ name] "get a set looking by name")) + "Collection of sets and set groups." + (add-set [_ token-set] + "Add a set to the library, at the end of the list") + (update-set [_ id f] + "Modify a set in the library") + (delete-set [_ id] + "Delete a set in the library and remove it from all themes") + (move-set [_ from-path to-path before-path before-group?] + "Move token set at `from-path` to `to-path` and order it before `before-path` with `before-group?`") + (move-set-group [_ from-path to-path before-path before-group?] + "Move token set group at `from-path` to `to-path` and order it before `before-path` with `before-group?`.") + (rename-set-group [_ from-path-str to-path-str] + "Renames set groups and all child set names from `from-path-str` to `to-path-str`") + (set-count [_] + "Get the total number if sets in the library") + (get-set [_ id] + "Get a set looking by id") + (get-set-by-name [_ name] + "Get a set looking by name") + (get-sets [_] + "Get an ordered sequence of all sets in the library") + (get-set-names [_] + "Get an ordered sequence of all sets names in the library") + (get-set-tree [_] + "Get a nested tree of all sets in the library") + (get-sets-at-path [_ path-str] + "Get an ordered sequence of sets under `path` in the library")) (def ^:private schema:token-set-node [:schema {:registry {::node @@ -606,12 +584,12 @@ (defprotocol ITokenTheme (set-sets [_ set-names] "set the active token sets") - (enable-set [_ set-name] "enable set in theme") - (enable-sets [_ set-names] "enable sets in theme") - (disable-set [_ set-name] "disable set in theme") - (disable-sets [_ set-names] "disable sets in theme") + (enable-set [_ set-name] "enable one set in theme") + (enable-sets [_ set-names] "enable several sets in theme") + (disable-set [_ set-name] "disable one set in theme") + (disable-sets [_ set-names] "disable several sets in theme") (toggle-set [_ set-name] "toggle a set enabled / disabled in the theme") - (update-set-name [_ prev-set-name set-name] "update set-name from `prev-set-name` to `set-name` when it exists") + (update-set-name [_ prev-set-name set-name] "update set-name when it exists") (theme-path [_] "get `theme-path` from theme") (theme-matches-group-name [_ group name] "if a theme matches the given group & name") (hidden-theme? [_] "if a theme is the (from the user ui) hidden temporary theme")) @@ -783,6 +761,7 @@ ;; === TokenThemes (collection) (defprotocol ITokenThemes + "Collection of themes in groups" (add-theme [_ token-theme] "add a theme to the library, at the end") (update-theme [_ group name f] "modify a theme in the ilbrary") (delete-theme [_ group name] "delete a theme in the library") @@ -977,6 +956,19 @@ Will return a value that matches this schema: (-write [this writter options] (json/-write (export-dtcg-json this) writter options))]) ITokenSets + ; Naming conventions: + ; (TODO: this will disappear after refactoring the internal structure of TokensLib). + ; Set name: the complete name as a string, without prefix \"some-group/some-subgroup/some-set\". + ; Set final name or fname: the last part of the name \"some-set\". + ; Set path: the groups part of the name, as a vector [\"some-group\" \"some-subgroup\"]. + ; Set path str: the set path as a string \"some-group/some-subgroup\". + ; Set full path: the path including the fname, as a vector [\"some-group\", \"some-subgroup\", \"some-set\"]. + ; Set full path str: the set full path as a string \"some-group/some-subgroup/some-set\". + + ; Set prefix: the two-characters prefix added to a full path item \"G-\" / \"S-\". + ; Prefixed set path or ppath: a path wit added prefixes [\"G-some-group\", \"G-some-subgroup\"]. + ; Prefixed set full path or pfpath: a full path wit prefixes [\"G-some-group\", \"G-some-subgroup\", \"S-some-set\"]. + ; Prefixed set final name or pfname: a final name with prefix \"S-some-set\". (add-set [_ token-set] (assert (token-set? token-set) "expected valid token-set") (let [path (get-set-prefixed-path token-set)] @@ -1120,11 +1112,6 @@ Will return a value that matches this schema: (->> (tree-seq d/ordered-map? vals sets) (filter (partial instance? TokenSet)))) - (get-sets-at-prefix-path- [_ prefixed-path-str] - (some->> (get-in sets (split-set-name prefixed-path-str)) - (tree-seq d/ordered-map? vals) - (filter (partial instance? TokenSet)))) - (get-sets-at-path [_ path] (some->> (map add-set-path-group-prefix path) (get-in sets) @@ -1142,7 +1129,7 @@ Will return a value that matches this schema: (rename set' (str to-path-str (str/strip-prefix (get-name set') from-path-str)))))) this sets))) - (get-ordered-set-names [this] + (get-set-names [this] (map get-name (get-sets this))) (set-count [this] @@ -1302,10 +1289,13 @@ Will return a value that matches this schema: (sets-at-path-all-active? [this group-path] (let [active-set-names (get-active-themes-set-names this) prefixed-path-str (set-group-path->set-group-prefixed-path-str group-path)] + (if (seq active-set-names) - (let [path-active-set-names (->> (get-sets-at-prefix-path- this prefixed-path-str) - (map get-name) - (into #{})) + (let [path-active-set-names (some->> (get-in sets (split-set-name prefixed-path-str)) + (tree-seq d/ordered-map? vals) + (filter (partial instance? TokenSet)) + (map get-name) + (into #{})) difference (set/difference path-active-set-names active-set-names)] (cond (empty? difference) :all @@ -1315,7 +1305,7 @@ Will return a value that matches this schema: (get-tokens-in-active-sets [this] (let [theme-set-names (get-active-themes-set-names this) - all-set-names (get-ordered-set-names this) + all-set-names (get-set-names this) active-set-names (filter theme-set-names all-set-names) tokens (reduce (fn [tokens set-name] (let [set (get-set-by-name this set-name)] @@ -1796,7 +1786,7 @@ Will return a value that matches this schema: (into {}))] (-> sets (assoc "$themes.json" themes) - (assoc "$metadata.json" {"tokenSetOrder" (get-ordered-set-names tokens-lib) + (assoc "$metadata.json" {"tokenSetOrder" (get-set-names tokens-lib) "activeThemes" active-themes "activeSets" (get-active-themes-set-names tokens-lib)})))) diff --git a/common/test/common_tests/logic/token_test.cljc b/common/test/common_tests/logic/token_test.cljc index 45733021ed..4347f0fb21 100644 --- a/common/test/common_tests/logic/token_test.cljc +++ b/common/test/common_tests/logic/token_test.cljc @@ -368,13 +368,13 @@ :position :top}) redo (thf/apply-changes file changes) redo-sets (-> (tht/get-tokens-lib redo) - (ctob/get-ordered-set-names)) + (ctob/get-set-names)) undo (thf/apply-undo-changes redo changes) undo-sets (-> (tht/get-tokens-lib undo) - (ctob/get-ordered-set-names))] + (ctob/get-set-names))] (t/is (= ["bar" "foo" "baz"] (vec redo-sets))) (t/testing "undo" - (t/is (= (ctob/get-ordered-set-names lib) undo-sets))))) + (t/is (= (ctob/get-set-names lib) undo-sets))))) (t/testing "at bottom" (let [file (setup-file #(-> % @@ -387,13 +387,13 @@ :position :bot}) redo (thf/apply-changes file changes) redo-sets (-> (tht/get-tokens-lib redo) - (ctob/get-ordered-set-names)) + (ctob/get-set-names)) undo (thf/apply-undo-changes redo changes) undo-sets (-> (tht/get-tokens-lib undo) - (ctob/get-ordered-set-names))] + (ctob/get-set-names))] (t/is (= ["bar" "baz" "foo"] (vec redo-sets))) (t/testing "undo" - (t/is (= (ctob/get-ordered-set-names lib) undo-sets))))) + (t/is (= (ctob/get-set-names lib) undo-sets))))) (t/testing "dropping out of set group" (let [file (setup-file #(-> % @@ -405,13 +405,13 @@ :position :top}) redo (thf/apply-changes file changes) redo-sets (-> (tht/get-tokens-lib redo) - (ctob/get-ordered-set-names)) + (ctob/get-set-names)) undo (thf/apply-undo-changes redo changes) undo-sets (-> (tht/get-tokens-lib undo) - (ctob/get-ordered-set-names))] + (ctob/get-set-names))] (t/is (= ["bar" "foo"] (vec redo-sets))) (t/testing "undo" - (t/is (= (ctob/get-ordered-set-names lib) undo-sets))))) + (t/is (= (ctob/get-set-names lib) undo-sets))))) (t/testing "into set group" (let [file (setup-file #(-> % @@ -423,13 +423,13 @@ :position :bot}) redo (thf/apply-changes file changes) redo-sets (-> (tht/get-tokens-lib redo) - (ctob/get-ordered-set-names)) + (ctob/get-set-names)) undo (thf/apply-undo-changes redo changes) undo-sets (-> (tht/get-tokens-lib undo) - (ctob/get-ordered-set-names))] + (ctob/get-set-names))] (t/is (= ["foo/bar" "foo/foo"] (vec redo-sets))) (t/testing "undo" - (t/is (= (ctob/get-ordered-set-names lib) undo-sets))))) + (t/is (= (ctob/get-set-names lib) undo-sets))))) (t/testing "edge-cases:" (t/testing "prevent overriding set to identical path" @@ -461,13 +461,13 @@ :collapsed-paths #{["foo"]}}) redo (thf/apply-changes file changes) redo-sets (-> (tht/get-tokens-lib redo) - (ctob/get-ordered-set-names)) + (ctob/get-set-names)) undo (thf/apply-undo-changes redo changes) undo-sets (-> (tht/get-tokens-lib undo) - (ctob/get-ordered-set-names))] + (ctob/get-set-names))] (t/is (= ["foo/bar" "foo"] (vec redo-sets))) (t/testing "undo" - (t/is (= (ctob/get-ordered-set-names lib) undo-sets)))))))) + (t/is (= (ctob/get-set-names lib) undo-sets)))))))) (t/deftest generate-move-token-group-test (t/testing "Ignore dropping set group to the same position" @@ -503,14 +503,14 @@ :position :top}) redo (thf/apply-changes file changes) redo-sets (-> (tht/get-tokens-lib redo) - (ctob/get-ordered-set-names)) + (ctob/get-set-names)) undo (thf/apply-undo-changes redo changes) undo-sets (-> (tht/get-tokens-lib undo) - (ctob/get-ordered-set-names))] + (ctob/get-set-names))] (t/is (= ["bar/bar" "foo/foo" "baz/baz"] (vec redo-sets))) (t/testing "undo" - (t/is (= (ctob/get-ordered-set-names lib) undo-sets))))) + (t/is (= (ctob/get-set-names lib) undo-sets))))) (t/testing "to bottom" (let [file (setup-file #(-> % @@ -522,14 +522,14 @@ :position :bot}) redo (thf/apply-changes file changes) redo-sets (-> (tht/get-tokens-lib redo) - (ctob/get-ordered-set-names)) + (ctob/get-set-names)) undo (thf/apply-undo-changes redo changes) undo-sets (-> (tht/get-tokens-lib undo) - (ctob/get-ordered-set-names))] + (ctob/get-set-names))] (t/is (= ["bar" "foo/foo"] (vec redo-sets))) (t/testing "undo" - (t/is (= (ctob/get-ordered-set-names lib) undo-sets))))) + (t/is (= (ctob/get-set-names lib) undo-sets))))) (t/testing "into set group" (let [file (setup-file #(-> % @@ -541,13 +541,13 @@ :position :bot}) redo (thf/apply-changes file changes) redo-sets (-> (tht/get-tokens-lib redo) - (ctob/get-ordered-set-names)) + (ctob/get-set-names)) undo (thf/apply-undo-changes redo changes) undo-sets (-> (tht/get-tokens-lib undo) - (ctob/get-ordered-set-names))] + (ctob/get-set-names))] (t/is (= ["bar/foo/foo" "bar/bar"] (vec redo-sets))) (t/testing "undo" - (t/is (= (ctob/get-ordered-set-names lib) undo-sets)))) + (t/is (= (ctob/get-set-names lib) undo-sets)))) (t/testing "edge-cases:" (t/testing "prevent overriding set to identical path" diff --git a/common/test/common_tests/types/tokens_lib_test.cljc b/common/test/common_tests/types/tokens_lib_test.cljc index ef4a9fd337..fb4486b772 100644 --- a/common/test/common_tests/types/tokens_lib_test.cljc +++ b/common/test/common_tests/types/tokens_lib_test.cljc @@ -14,6 +14,7 @@ [app.common.test-helpers.ids-map :as thi] [app.common.time :as ct] [app.common.transit :as tr] + [app.common.types.token :as cto] [app.common.types.tokens-lib :as ctob] [app.common.uuid :as uuid] [clojure.test :as t])) @@ -62,13 +63,13 @@ (t/deftest find-token-value-references (t/testing "finds references inside curly braces in a string" - (t/is (= #{"foo" "bar"} (ctob/find-token-value-references "{foo} + {bar}"))) + (t/is (= #{"foo" "bar"} (cto/find-token-value-references "{foo} + {bar}"))) (t/testing "ignores extra text" - (t/is (= #{"foo.bar.baz"} (ctob/find-token-value-references "{foo.bar.baz} + something"))))) + (t/is (= #{"foo.bar.baz"} (cto/find-token-value-references "{foo.bar.baz} + something"))))) (t/testing "ignores string without references" - (t/is (nil? (ctob/find-token-value-references "1 + 2")))) + (t/is (nil? (cto/find-token-value-references "1 + 2")))) (t/testing "handles edge-case for extra curly braces" - (t/is (= #{"foo" "bar"} (ctob/find-token-value-references "{foo}} + {bar}"))))) + (t/is (= #{"foo" "bar"} (cto/find-token-value-references "{foo}} + {bar}"))))) (t/deftest make-token-set (let [now (ct/now) @@ -99,7 +100,7 @@ (ctob/add-set (ctob/make-token-set :name "Move"))) move (fn [from-path to-path before-path before-group?] (->> (ctob/move-set tokens-lib from-path to-path before-path before-group?) - (ctob/get-ordered-set-names) + (ctob/get-set-names) (into [])))] (t/testing "move to top" (t/is (= ["Move" "A" "B"] (move ["Move"] ["Move"] ["A"] false)))) @@ -117,10 +118,11 @@ (ctob/add-set (ctob/make-token-set :name "Foo"))) move (fn [from-path to-path before-path before-group?] (->> (ctob/move-set tokens-lib from-path to-path before-path before-group?) - (ctob/get-ordered-set-names) + (ctob/get-set-names) (into [])))] (t/testing "move outside of group" (t/is (= ["Foo/Baz" "Bar" "Foo"] (move ["Foo" "Bar"] ["Bar"] ["Foo"] false))) + (t/is (= ["Bar" "Foo/Baz" "Foo"] (move ["Foo" "Bar"] ["Bar"] ["Foo"] true))) (t/is (= ["Bar" "Foo/Baz" "Foo"] (move ["Foo" "Bar"] ["Bar"] ["Foo" "Baz"] true))) (t/is (= ["Foo/Baz" "Foo" "Bar"] (move ["Foo" "Bar"] ["Bar"] nil false)))) @@ -136,10 +138,10 @@ (ctob/add-set (ctob/make-token-set :name "b/b"))) move (fn [from-path to-path before-path before-group?] (->> (ctob/move-set tokens-lib from-path to-path before-path before-group?) - (ctob/get-ordered-set-names) + (ctob/get-set-names) (vec)))] (t/testing "move within group" - (t/is (= ["a/b" "a/a" "b/a" "b/b"] (vec (ctob/get-ordered-set-names tokens-lib)))) + (t/is (= ["a/b" "a/a" "b/a" "b/b"] (vec (ctob/get-set-names tokens-lib)))) (t/is (= ["a/a" "a/b" "b/a" "b/b"] (move ["a" "b"] ["a" "b"] nil true)))))) (t/deftest move-token-set-nested-3 @@ -161,7 +163,7 @@ :sets #{"Foo/A" "Bar/Foo"}))) move (fn [from-path to-path before-path before-group?] (->> (ctob/move-set-group tokens-lib from-path to-path before-path before-group?) - (ctob/get-ordered-set-names) + (ctob/get-set-names) (into [])))] (t/is (= ["Bar/Foo" "Bar/Foo/A" "Bar/Foo/B"] (move ["Foo"] ["Bar" "Foo"] nil nil))) (t/is (= ["Bar/Foo" "Foo/A" "Foo/B"] (move ["Bar"] ["Bar"] ["Foo"] true))))) @@ -297,7 +299,7 @@ tokens-lib' (-> tokens-lib (ctob/rename-set-group ["foo" "bar"] "bar-renamed") (ctob/rename-set-group ["foo" "bar-renamed" "baz"] "baz-renamed")) - expected-set-names (ctob/get-ordered-set-names tokens-lib') + expected-set-names (ctob/get-set-names tokens-lib') expected-theme-sets (-> (ctob/get-theme tokens-lib' "" "theme") :sets)] (t/is (= expected-set-names @@ -511,7 +513,7 @@ (ctob/add-set (ctob/make-token-set :name "group-2/set-a")) (ctob/add-set (ctob/make-token-set :name "group-1/set-c"))) - ordered-sets (ctob/get-ordered-set-names tokens-lib)] + ordered-sets (ctob/get-set-names tokens-lib)] (t/is (= ordered-sets '("group-1/set-a" "group-1/set-b" @@ -1305,7 +1307,7 @@ (let [json (-> (slurp "test/common_tests/types/data/tokens-single-set-legacy-example.json") (json/decode {:key-fn identity})) lib (ctob/parse-decoded-json json "single_set")] - (t/is (= '("single_set") (ctob/get-ordered-set-names lib))) + (t/is (= '("single_set") (ctob/get-set-names lib))) (t/testing "token added" (t/is (some? (ctob/get-token-by-name lib "single_set" "color.red.100"))))))) @@ -1314,7 +1316,7 @@ (let [json (-> (slurp "test/common_tests/types/data/tokens-single-set-dtcg-example.json") (json/decode {:key-fn identity})) lib (ctob/parse-decoded-json json "single_set")] - (t/is (= '("single_set") (ctob/get-ordered-set-names lib))) + (t/is (= '("single_set") (ctob/get-set-names lib))) (t/testing "token added" (t/is (some? (ctob/get-token-by-name lib "single_set" "color.red.100"))))))) @@ -1324,7 +1326,7 @@ (json/decode {:key-fn identity})) lib (ctob/parse-decoded-json json "") token-theme (ctob/get-theme lib "group-1" "theme-1")] - (t/is (= '("core" "light" "dark" "theme") (ctob/get-ordered-set-names lib))) + (t/is (= '("core" "light" "dark" "theme") (ctob/get-set-names lib))) (t/testing "set exists in theme" (t/is (= (:group token-theme) "group-1")) (t/is (= (:name token-theme) "theme-1")) @@ -1354,7 +1356,7 @@ (json/decode {:key-fn identity})) lib (ctob/parse-decoded-json json "") token-theme (ctob/get-theme lib "group-1" "theme-1")] - (t/is (= '("core" "light" "dark" "theme") (ctob/get-ordered-set-names lib))) + (t/is (= '("core" "light" "dark" "theme") (ctob/get-set-names lib))) (t/testing "set exists in theme" (t/is (= (:group token-theme) "group-1")) (t/is (= (:name token-theme) "theme-1")) @@ -1385,7 +1387,7 @@ lib (ctob/parse-decoded-json json "") themes (ctob/get-themes lib) first-theme (first themes)] - (t/is (= '("dark") (ctob/get-ordered-set-names lib))) + (t/is (= '("dark") (ctob/get-set-names lib))) (t/is (= 1 (count themes))) (t/testing "existing theme is default theme" (t/is (= (:group first-theme) "")) diff --git a/frontend/src/app/main/data/style_dictionary.cljs b/frontend/src/app/main/data/style_dictionary.cljs index 5c506440ba..41631cdc74 100644 --- a/frontend/src/app/main/data/style_dictionary.cljs +++ b/frontend/src/app/main/data/style_dictionary.cljs @@ -12,7 +12,7 @@ [app.common.logging :as l] [app.common.schema :as sm] [app.common.time :as ct] - [app.common.types.token :as ctt] + [app.common.types.token :as cto] [app.common.types.tokens-lib :as ctob] [app.main.data.tinycolor :as tinycolor] [app.main.data.workspace.tokens.errors :as wte] @@ -88,8 +88,8 @@ out-of-bounds {:errors [(wte/error-with-value :error.token/number-too-large value)]} - (seq (ctob/find-token-value-references value)) - (let [references (seq (ctob/find-token-value-references value))] + (seq (cto/find-token-value-references value)) + (let [references (seq (cto/find-token-value-references value))] {:errors [(wte/error-with-value :error.style-dictionary/missing-reference references)] :references references}) @@ -110,7 +110,7 @@ parsed-value (if out-of-bounds {:errors [(wte/error-with-value :error.token/number-too-large value)]} - (if-let [references (seq (ctob/find-token-value-references value))] + (if-let [references (seq (cto/find-token-value-references value))] {: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)]}))))) @@ -120,10 +120,10 @@ If the `value` is not parseable and/or has missing references returns a map with `:errors`. If the `value` is parseable but is out of range returns a map with `warnings`." [value] - (let [missing-references? (seq (ctob/find-token-value-references value)) + (let [missing-references? (seq (cto/find-token-value-references value)) parsed-value (cft/parse-token-value value) out-of-scope (not (<= 0 (:value parsed-value) 1)) - references (seq (ctob/find-token-value-references value))] + references (seq (cto/find-token-value-references value))] (cond (and parsed-value (not out-of-scope)) parsed-value @@ -144,10 +144,10 @@ If the `value` is not parseable and/or has missing references returns a map with `:errors`. If the `value` is parseable but is out of range returns a map with `warnings`." [value] - (let [missing-references? (seq (ctob/find-token-value-references value)) + (let [missing-references? (seq (cto/find-token-value-references value)) parsed-value (cft/parse-token-value value) out-of-scope (< (:value parsed-value) 0) - references (seq (ctob/find-token-value-references value))] + references (seq (cto/find-token-value-references value))] (cond (and parsed-value (not out-of-scope)) parsed-value @@ -179,7 +179,7 @@ [value] (let [normalized-value (str/lower (str/trim value)) valid? (contains? #{"none" "uppercase" "lowercase" "capitalize"} normalized-value) - references (seq (ctob/find-token-value-references value))] + references (seq (cto/find-token-value-references value))] (cond valid? {:value normalized-value} @@ -195,8 +195,8 @@ "Parses `value` of a text-decoration `sd-token` into a map like `{:value \"underline\"}`. If the `value` is not parseable and/or has missing references returns a map with `:errors`." [value] - (let [valid-text-decoration (ctt/valid-text-decoration value) - references (seq (ctob/find-token-value-references value))] + (let [valid-text-decoration (cto/valid-text-decoration value) + references (seq (cto/find-token-value-references value))] (cond valid-text-decoration {:value valid-text-decoration} @@ -212,8 +212,8 @@ "Parses `value` of a font-weight `sd-token` into a map like `{:value \"700\"}` or `{:value \"700 Italic\"}`. If the `value` is not parseable and/or has missing references returns a map with `:errors`." [value] - (let [valid-font-weight (ctt/valid-font-weight-variant value) - references (seq (ctob/find-token-value-references value))] + (let [valid-font-weight (cto/valid-font-weight-variant value) + references (seq (cto/find-token-value-references value))] (cond valid-font-weight {:value value} @@ -255,7 +255,7 @@ (defn- parse-sd-token-font-family-value [value] - (let [missing-references (seq (some ctob/find-token-value-references value))] + (let [missing-references (seq (some cto/find-token-value-references value))] (cond missing-references {:errors [(wte/error-with-value :error.style-dictionary/missing-reference missing-references)] @@ -280,7 +280,7 @@ [value] (let [missing-references (when (string? value) - (seq (ctob/find-token-value-references value)))] + (seq (cto/find-token-value-references value)))] (cond missing-references {:errors [(wte/error-with-value :error.style-dictionary/missing-reference missing-references)] diff --git a/frontend/src/app/main/ui/workspace/tokens/management/create/form.cljs b/frontend/src/app/main/ui/workspace/tokens/management/create/form.cljs index 06d189212a..e4c9333f75 100644 --- a/frontend/src/app/main/ui/workspace/tokens/management/create/form.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/management/create/form.cljs @@ -12,7 +12,7 @@ [app.common.files.tokens :as cft] [app.common.schema :as sm] [app.common.types.color :as c] - [app.common.types.token :as ctt] + [app.common.types.token :as cto] [app.common.types.tokens-lib :as ctob] [app.main.constants :refer [max-input-length]] [app.main.data.modal :as modal] @@ -113,7 +113,7 @@ (check-empty-value (:value token))) (defn check-self-reference [token-name token-value] - (when (ctob/token-value-self-reference? token-name token-value) + (when (cto/token-value-self-reference? token-name token-value) (wte/get-error-code :error.token/direct-self-reference))) (defn check-token-self-reference [token] @@ -125,7 +125,7 @@ ;; When creating a new token we dont have a name yet or invalid name, ;; but we still want to resolve the value to show in the form. ;; So we use a temporary token name that hopefully doesn't clash with any of the users token names - (not (sm/valid? ctt/token-name-ref (:name token))) (assoc :name "__PENPOT__TOKEN__NAME__PLACEHOLDER__")) + (not (sm/valid? cto/token-name-ref (:name token))) (assoc :name "__PENPOT__TOKEN__NAME__PLACEHOLDER__")) tokens' (cond-> tokens ;; Remove previous token when renaming a token (not= (:name token) (:name prev-token)) @@ -182,7 +182,7 @@ (defn check-coll-self-reference "Invalidate a collection of `token-vals` for a self-refernce against `token-name`.," [token-name token-vals] - (when (some #(ctob/token-value-self-reference? token-name %) token-vals) + (when (some #(cto/token-value-self-reference? token-name %) token-vals) (wte/get-error-code :error.token/direct-self-reference))) (defn check-font-family-token-self-reference [token] @@ -191,7 +191,7 @@ (defn validate-font-family-token [props] (-> props - (update :token-value ctt/split-font-family) + (update :token-value cto/split-font-family) (assoc :validators [(fn [token] (when (empty? (:value token)) (wte/get-error-code :error.token/empty-input))) @@ -220,14 +220,14 @@ ;; Entering form without a value - show no error just resolve nil (nil? token-value) (rx/of nil) ;; Validate refrence string - (ctt/typography-composite-token-reference? token-value) (default-validate-token props) + (cto/typography-composite-token-reference? token-value) (default-validate-token props) ;; Validate composite token :else (-> props (update :token-value (fn [v] (-> (or v {}) - (d/update-when :font-family #(if (string? %) (ctt/split-font-family %) %))))) + (d/update-when :font-family #(if (string? %) (cto/split-font-family %) %))))) (assoc :validators [check-empty-typography-token check-typography-token-self-reference]) (default-validate-token)))) @@ -306,10 +306,10 @@ custom-input-token-value-props: Custom props passed to the custom-input-token-va ;; Style dictionary resolver needs font families to be an array of strings (= :font-family (or (:type token) token-type)) - (update-in [(:name token) :value] ctt/split-font-family) + (update-in [(:name token) :value] cto/split-font-family) (= :typography (or (:type token) token-type)) - (d/update-in-when [(:name token) :font-family :value] ctt/split-font-family)) + (d/update-in-when [(:name token) :font-family :value] cto/split-font-family)) resolved-tokens (sd/use-resolved-tokens active-theme-tokens {:cache-atom form-token-cache-atom :interactive? true}) @@ -791,7 +791,7 @@ custom-input-token-value-props: Custom props passed to the custom-input-token-va (let [current-font* (mf/use-state (or font (some-> (mf/ref-val input-ref) (dom/get-value) - (ctt/split-font-family) + (cto/split-font-family) (first) (fonts/find-font-family)))) current-font (deref current-font*)] @@ -871,9 +871,9 @@ custom-input-token-value-props: Custom props passed to the custom-input-token-va (mf/use-fn (fn [value] (when value - (ctt/join-font-family value))))] + (cto/join-font-family value))))] [:> form* - (mf/spread-props props {:token (when token (update token :value ctt/join-font-family)) + (mf/spread-props props {:token (when token (update token :value cto/join-font-family)) :custom-input-token-value font-picker-combobox* :on-value-resolve on-value-resolve :validate-token validate-font-family-token})])) @@ -966,7 +966,7 @@ custom-input-token-value-props: Custom props passed to the custom-input-token-va {:aria-label label :placeholder placeholder :input-ref input-ref - :default-value (when value (ctt/join-font-family value)) + :default-value (when value (cto/join-font-family value)) :on-blur on-blur :on-update-value on-change :on-external-update-value on-external-update-value @@ -986,7 +986,7 @@ custom-input-token-value-props: Custom props passed to the custom-input-token-va {:aria-label (tr "labels.reference") :placeholder (tr "workspace.tokens.reference-composite") :icon i/text-typography - :default-value (when (ctt/typography-composite-token-reference? default-value) default-value) + :default-value (when (cto/typography-composite-token-reference? default-value) default-value) :on-blur on-blur :on-change on-update-value :token-resolve-result (when (or @@ -997,7 +997,7 @@ custom-input-token-value-props: Custom props passed to the custom-input-token-va (mf/defc typography-inputs* [{:keys [default-value on-update-value on-external-update-value on-value-resolve clear-resolve-value] :rest props}] (let [;; Active Tab State - active-tab* (mf/use-state (if (ctt/typography-composite-token-reference? default-value) :reference :composite)) + active-tab* (mf/use-state (if (cto/typography-composite-token-reference? default-value) :reference :composite)) active-tab (deref active-tab*) reference-tab-active? (= :reference active-tab) ;; Backup value ref @@ -1030,7 +1030,7 @@ custom-input-token-value-props: Custom props passed to the custom-input-token-va (let [token-type (obj/get e "tokenType") token-value (dom/get-target-val e) token-value (cond-> token-value - (= :font-family token-type) (ctt/split-font-family))] + (= :font-family token-type) (cto/split-font-family))] (swap! backup-state-ref assoc-in [:composite token-type] token-value))) (on-update-value e)))