🔧 Retrieve tokens from library and not from set

This commit is contained in:
Andrés Moya
2025-09-01 09:51:37 +02:00
committed by Andrés Moya
parent b28be62845
commit f5fd978a07
17 changed files with 577 additions and 536 deletions

View File

@@ -983,13 +983,13 @@
(let [lib' (ctob/ensure-tokens-lib lib)] (let [lib' (ctob/ensure-tokens-lib lib)]
(cond (cond
(not token) (not token)
(ctob/delete-token-from-set lib' set-id token-id) (ctob/delete-token lib' set-id token-id)
(not (ctob/get-token-in-set lib' set-id token-id)) (not (ctob/get-token lib' set-id token-id))
(ctob/add-token-in-set lib' set-id (ctob/make-token token)) (ctob/add-token lib' set-id (ctob/make-token token))
:else :else
(ctob/update-token-in-set lib' set-id token-id (ctob/update-token lib' set-id token-id
(fn [prev-token] (fn [prev-token]
(ctob/make-token (merge prev-token token))))))))) (ctob/make-token (merge prev-token token)))))))))

View File

@@ -803,8 +803,9 @@
[changes active-theme-paths] [changes active-theme-paths]
(assert-library! changes) (assert-library! changes)
(let [library-data (::library-data (meta changes)) (let [library-data (::library-data (meta changes))
prev-active-theme-paths (some-> (get library-data :tokens-lib) prev-active-theme-paths (d/nilv (some-> (get library-data :tokens-lib)
(ctob/get-active-theme-paths))] (ctob/get-active-theme-paths))
#{})]
(-> changes (-> changes
(update :redo-changes conj {:type :update-active-token-themes :theme-paths active-theme-paths}) (update :redo-changes conj {:type :update-active-token-themes :theme-paths active-theme-paths})
(update :undo-changes conj {:type :update-active-token-themes :theme-paths prev-active-theme-paths}) (update :undo-changes conj {:type :update-active-token-themes :theme-paths prev-active-theme-paths})
@@ -889,8 +890,7 @@
(assert-library! changes) (assert-library! changes)
(let [library-data (::library-data (meta changes)) (let [library-data (::library-data (meta changes))
prev-token (some-> (get library-data :tokens-lib) prev-token (some-> (get library-data :tokens-lib)
(ctob/get-set set-id) (ctob/get-token set-id token-id))]
(ctob/get-token token-id))]
(-> changes (-> changes
(update :redo-changes conj {:type :set-token (update :redo-changes conj {:type :set-token
:set-id set-id :set-id set-id

View File

@@ -31,9 +31,7 @@
[file set-id token-id] [file set-id token-id]
(let [tokens-lib (:tokens-lib (:data file))] (let [tokens-lib (:tokens-lib (:data file))]
(when tokens-lib (when tokens-lib
(-> tokens-lib (ctob/get-token tokens-lib set-id token-id))))
(ctob/get-set set-id)
(ctob/get-token token-id)))))
(defn token-data-eq? (defn token-data-eq?
"Compare token data without comparing unstable fields." "Compare token data without comparing unstable fields."

View File

@@ -213,13 +213,16 @@
;; === Token Set ;; === Token Set
(defprotocol ITokenSet (defprotocol ITokenSet
(add-token [_ token] "add a token at the end of the list") ;; TODO: the tokens tree is planned to be moved to the TokensLib. So this protocol will be no
(update-token [_ id f] "update a token in the list") ;; longer needed. For now, it's kept but it should only be used internally in the TokensLib.
(delete-token [_ id] "delete a token from the list") ;; The - suffix is to remind it.
(get-token [_ id] "get a token by its id") (add-token- [_ token] "add a token at the end of the list")
(get-token-by-name [_ name] "get a token by its name") (update-token- [_ id f] "update a token in the list")
(get-tokens [_] "return an ordered sequence of all tokens in the set") (delete-token- [_ id] "delete a token from the list")
(get-tokens-map [_] "return a map of tokens in the set, indexed by token-name")) (get-token- [_ id] "get a token by its id")
(get-token-by-name- [_ name] "get a token by its name")
(get-tokens-seq- [_] "return an ordered sequence of all tokens in the set")
(get-tokens-map- [_] "return a map of tokens in the set, indexed by token-name"))
;; TODO: this structure is temporary. It's needed to be able to migrate TokensLib ;; TODO: this structure is temporary. It's needed to be able to migrate TokensLib
;; from 1.2 to 1.3 when TokenSet datatype was changed to a deftype. This should ;; from 1.2 to 1.3 when TokenSet datatype was changed to a deftype. This should
@@ -286,7 +289,7 @@
tokens)) tokens))
ITokenSet ITokenSet
(add-token [_ token] (add-token- [_ token]
(let [token (check-token token)] (let [token (check-token token)]
(TokenSet. id (TokenSet. id
name name
@@ -294,9 +297,9 @@
(ct/now) (ct/now)
(assoc tokens (:name token) token)))) (assoc tokens (:name token) token))))
(update-token [this token-id f] (update-token- [this token-id f]
(assert (uuid? token-id) "expected uuid for `token-id`") (assert (uuid? token-id) "expected uuid for `token-id`")
(if-let [token (get-token this token-id)] (if-let [token (get-token- this token-id)]
(let [token' (-> (make-token (f token)) (let [token' (-> (make-token (f token))
(assoc :modified-at (ct/now)))] (assoc :modified-at (ct/now)))]
(TokenSet. id (TokenSet. id
@@ -310,28 +313,28 @@
(dissoc (:name token)))))) (dissoc (:name token))))))
this)) this))
(delete-token [this token-id] (delete-token- [this token-id]
(assert (uuid? token-id) "expected uuid for `token-id`") (assert (uuid? token-id) "expected uuid for `token-id`")
(let [token (get-token this token-id)] (let [token (get-token- this token-id)]
(TokenSet. id (TokenSet. id
name name
description description
(ct/now) (ct/now)
(dissoc tokens (:name token))))) (dissoc tokens (:name token)))))
(get-token [_ token-id] (get-token- [_ token-id]
(assert (uuid? token-id) "expected uuid for `token-id`") (assert (uuid? token-id) "expected uuid for `token-id`")
(some #(when (= (:id %) token-id) %) ;; TODO: this will be made in an efficient way when (some #(when (= (:id %) token-id) %) ;; TODO: this will be made in an efficient way when
(vals tokens))) ;; we refactor the tokens lib internal structure (vals tokens))) ;; we refactor the tokens lib internal structure
(get-token-by-name [_ name] (get-token-by-name- [_ name]
(assert (string? name) "expected string for `name`") (assert (string? name) "expected string for `name`")
(get tokens name)) (get tokens name))
(get-tokens [_] (get-tokens-seq- [_]
(vals tokens)) (vals tokens))
(get-tokens-map [_] (get-tokens-map- [_]
tokens)) tokens))
(defmethod pp/simple-dispatch TokenSet [^TokenSet obj] (defmethod pp/simple-dispatch TokenSet [^TokenSet obj]
@@ -940,11 +943,11 @@
(empty-lib? [_] "True if the lib does not contain any token, set or theme") (empty-lib? [_] "True if the lib does not contain any token, set or theme")
(set-path-exists? [_ path] "if a set at `path` exists") (set-path-exists? [_ path] "if a set at `path` exists")
(set-group-path-exists? [_ path] "if a set group at `path` exists") (set-group-path-exists? [_ path] "if a set group at `path` exists")
(add-token-in-set [_ set-id token] "add token to a set") (add-token [_ set-id token] "add token to a set")
(get-token-in-set [_ set-id token-id] "get token in a set") (get-token [_ set-id token-id] "get token in a set")
(get-token-in-set-by-name [_ set-id token-name] "get token in a set searching by token name") (get-token-by-name [_ set-name token-name] "get token in a set searching by set and token names")
(update-token-in-set [_ set-id token-id f] "update a token in a set") (update-token [_ set-id token-id f] "update a token in a set")
(delete-token-from-set [_ set-id token-id] "delete a token from a set") (delete-token [_ set-id token-id] "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") (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-names [_] "set of set names that are active in the the active themes")
(sets-at-path-all-active? [_ group-path] "compute active state for child sets at `group-path`. (sets-at-path-all-active? [_ group-path] "compute active state for child sets at `group-path`.
@@ -954,6 +957,8 @@ Will return a value that matches this schema:
`:partial` Mixed active state of nested sets") `:partial` Mixed active state of nested sets")
(get-tokens-in-active-sets [_] "set of set names that are active in the the active themes") (get-tokens-in-active-sets [_] "set of set names that are active in the the active themes")
(get-all-tokens [_] "all tokens in the lib") (get-all-tokens [_] "all tokens in the lib")
(get-tokens-seq [_ set-id] "return an ordered sequence of all tokens in a set")
(get-tokens-map [_ set-id] "return a map of tokens in the set, indexed by token-name")
(validate [_])) (validate [_]))
(declare parse-multi-set-dtcg-json) (declare parse-multi-set-dtcg-json)
@@ -1262,24 +1267,24 @@ Will return a value that matches this schema:
(set-group-path-exists? [_ set-path] (set-group-path-exists? [_ set-path]
(some? (get-in sets (set-group-path->set-group-prefixed-path set-path)))) (some? (get-in sets (set-group-path->set-group-prefixed-path set-path))))
(add-token-in-set [this set-id token] (add-token [this set-id token]
(update-set this set-id #(add-token % token))) (update-set this set-id #(add-token- % token)))
(get-token-in-set [this set-id token-id] (get-token [this set-id token-id]
(some-> this (some-> this
(get-set set-id) (get-set set-id)
(get-token token-id))) (get-token- token-id)))
(get-token-in-set-by-name [this set-id token-name] (get-token-by-name [this set-name token-name]
(some-> this (some-> this
(get-set set-id) (get-set-by-name set-name)
(get-token-by-name token-name))) (get-token-by-name- token-name)))
(update-token-in-set [this set-id token-id f] (update-token [this set-id token-id f]
(update-set this set-id #(update-token % token-id f))) (update-set this set-id #(update-token- % token-id f)))
(delete-token-from-set [this set-id token-id] (delete-token [this set-id token-id]
(update-set this set-id #(delete-token % token-id))) (update-set this set-id #(delete-token- % token-id)))
(toggle-set-in-theme [this theme-group theme-name set-name] (toggle-set-in-theme [this theme-group theme-name set-name]
(if-let [_theme (get-in themes theme-group theme-name)] (if-let [_theme (get-in themes theme-group theme-name)]
@@ -1314,7 +1319,7 @@ Will return a value that matches this schema:
active-set-names (filter theme-set-names all-set-names) active-set-names (filter theme-set-names all-set-names)
tokens (reduce (fn [tokens set-name] tokens (reduce (fn [tokens set-name]
(let [set (get-set-by-name this set-name)] (let [set (get-set-by-name this set-name)]
(merge tokens (get-tokens-map set)))) (merge tokens (get-tokens-map- set))))
(d/ordered-map) (d/ordered-map)
active-set-names)] active-set-names)]
tokens)) tokens))
@@ -1322,10 +1327,20 @@ Will return a value that matches this schema:
(get-all-tokens [this] (get-all-tokens [this]
(reduce (reduce
(fn [tokens' set] (fn [tokens' set]
(into tokens' (map (fn [x] [(:name x) x]) (get-tokens set)))) (into tokens' (map (fn [x] [(:name x) x]) (get-tokens-seq- set))))
{} {}
(get-sets this))) (get-sets this)))
(get-tokens-seq [this set-id]
(some-> this
(get-set set-id)
(get-tokens-seq-)))
(get-tokens-map [this set-id]
(some-> this
(get-set set-id)
(get-tokens-map-)))
(validate [_] (validate [_]
(and (valid-token-sets? sets) (and (valid-token-sets? sets)
(valid-token-themes? themes) (valid-token-themes? themes)
@@ -1776,7 +1791,7 @@ Will return a value that matches this schema:
sets (->> (get-sets tokens-lib) sets (->> (get-sets tokens-lib)
(map (fn [token-set] (map (fn [token-set]
(let [name (get-name token-set) (let [name (get-name token-set)
tokens (get-tokens-map token-set)] tokens (get-tokens-map- token-set)]
[(str name ".json") (tokens-tree tokens :update-token-fn token->dtcg-token)]))) [(str name ".json") (tokens-tree tokens :update-token-fn token->dtcg-token)])))
(into {}))] (into {}))]
(-> sets (-> sets
@@ -1796,7 +1811,7 @@ Will return a value that matches this schema:
(filter (partial instance? TokenSet)) (filter (partial instance? TokenSet))
(map (fn [set] (map (fn [set]
[(get-name set) [(get-name set)
(tokens-tree (get-tokens-map set) :update-token-fn token->dtcg-token)]))) (tokens-tree (get-tokens-map- set) :update-token-fn token->dtcg-token)])))
ordered-set-names ordered-set-names
(mapv first name-set-tuples) (mapv first name-set-tuples)

View File

@@ -149,12 +149,12 @@
(ctob/add-theme (ctob/make-token-theme :name "test-theme" (ctob/add-theme (ctob/make-token-theme :name "test-theme"
:sets #{"test-token-set"})) :sets #{"test-token-set"}))
(ctob/set-active-themes #{"/test-theme"}) (ctob/set-active-themes #{"/test-theme"})
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-sizing) (ctob/make-token :id (thi/new-id! :token-sizing)
:name "token-sizing" :name "token-sizing"
:type :sizing :type :sizing
:value 10)) :value 10))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-spacing) (ctob/make-token :id (thi/new-id! :token-spacing)
:name "token-spacing" :name "token-spacing"
:type :spacing :type :spacing

View File

@@ -32,57 +32,57 @@
(ctob/add-theme (ctob/make-token-theme :name "test-theme" (ctob/add-theme (ctob/make-token-theme :name "test-theme"
:sets #{"test-token-set"})) :sets #{"test-token-set"}))
(ctob/set-active-themes #{"/test-theme"}) (ctob/set-active-themes #{"/test-theme"})
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-radius) (ctob/make-token :id (thi/new-id! :token-radius)
:name "token-radius" :name "token-radius"
:type :border-radius :type :border-radius
:value 10)) :value 10))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-rotation) (ctob/make-token :id (thi/new-id! :token-rotation)
:name "token-rotation" :name "token-rotation"
:type :rotation :type :rotation
:value 30)) :value 30))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-opacity) (ctob/make-token :id (thi/new-id! :token-opacity)
:name "token-opacity" :name "token-opacity"
:type :opacity :type :opacity
:value 0.7)) :value 0.7))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-stroke-width) (ctob/make-token :id (thi/new-id! :token-stroke-width)
:name "token-stroke-width" :name "token-stroke-width"
:type :stroke-width :type :stroke-width
:value 2)) :value 2))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-color) (ctob/make-token :id (thi/new-id! :token-color)
:name "token-color" :name "token-color"
:type :color :type :color
:value "#00ff00")) :value "#00ff00"))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-dimensions) (ctob/make-token :id (thi/new-id! :token-dimensions)
:name "token-dimensions" :name "token-dimensions"
:type :dimensions :type :dimensions
:value 100)) :value 100))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-font-size) (ctob/make-token :id (thi/new-id! :token-font-size)
:name "token-font-size" :name "token-font-size"
:type :font-size :type :font-size
:value 24)) :value 24))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-letter-spacing) (ctob/make-token :id (thi/new-id! :token-letter-spacing)
:name "token-letter-spacing" :name "token-letter-spacing"
:type :letter-spacing :type :letter-spacing
:value 2)) :value 2))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-font-family) (ctob/make-token :id (thi/new-id! :token-font-family)
:name "token-font-family" :name "token-font-family"
:type :font-family :type :font-family
:value ["Helvetica" "Arial" "sans-serif"])) :value ["Helvetica" "Arial" "sans-serif"]))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-sizing) (ctob/make-token :id (thi/new-id! :token-sizing)
:name "token-sizing" :name "token-sizing"
:type :sizing :type :sizing
:value 10)) :value 10))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-spacing) (ctob/make-token :id (thi/new-id! :token-spacing)
:name "token-spacing" :name "token-spacing"
:type :spacing :type :spacing

View File

@@ -171,7 +171,7 @@
file (setup-file #(-> % file (setup-file #(-> %
(ctob/add-set (ctob/make-token-set :id set-id (ctob/add-set (ctob/make-token-set :id set-id
:name set-name)) :name set-name))
(ctob/add-token-in-set set-id (ctob/make-token {:name "to.delete.color.red" (ctob/add-token set-id (ctob/make-token {:name "to.delete.color.red"
:id token-id :id token-id
:value "red" :value "red"
:type :color})))) :type :color}))))
@@ -183,9 +183,9 @@
redo-lib (tht/get-tokens-lib redo) redo-lib (tht/get-tokens-lib redo)
undo (thf/apply-undo-changes redo changes) undo (thf/apply-undo-changes redo changes)
undo-lib (tht/get-tokens-lib undo)] undo-lib (tht/get-tokens-lib undo)]
(t/is (nil? (ctob/get-token-in-set redo-lib set-id token-id))) (t/is (nil? (ctob/get-token redo-lib set-id token-id)))
;; Undo ;; Undo
(t/is (some? (ctob/get-token-in-set undo-lib set-id token-id))))) (t/is (some? (ctob/get-token undo-lib set-id token-id)))))
(t/testing "add token" (t/testing "add token"
(let [set-name "foo" (let [set-name "foo"
@@ -203,9 +203,9 @@
redo-lib (tht/get-tokens-lib redo) redo-lib (tht/get-tokens-lib redo)
undo (thf/apply-undo-changes redo changes) undo (thf/apply-undo-changes redo changes)
undo-lib (tht/get-tokens-lib undo)] undo-lib (tht/get-tokens-lib undo)]
(t/is (= token (ctob/get-token-in-set redo-lib set-id (:id token)))) (t/is (= token (ctob/get-token redo-lib set-id (:id token))))
;; Undo ;; Undo
(t/is (nil? (ctob/get-token-in-set undo-lib set-id (:id token)))))) (t/is (nil? (ctob/get-token undo-lib set-id (:id token))))))
(t/testing "update token" (t/testing "update token"
(let [set-name "foo" (let [set-name "foo"
@@ -219,7 +219,7 @@
file (setup-file #(-> % file (setup-file #(-> %
(ctob/add-set (ctob/make-token-set :id set-id (ctob/add-set (ctob/make-token-set :id set-id
:name set-name)) :name set-name))
(ctob/add-token-in-set set-id prev-token))) (ctob/add-token set-id prev-token)))
changes (-> (pcb/empty-changes) changes (-> (pcb/empty-changes)
(pcb/with-library-data (:data file)) (pcb/with-library-data (:data file))
(pcb/set-token set-id (:id prev-token) token)) (pcb/set-token set-id (:id prev-token) token))
@@ -228,9 +228,9 @@
redo-lib (tht/get-tokens-lib redo) redo-lib (tht/get-tokens-lib redo)
undo (thf/apply-undo-changes redo changes) undo (thf/apply-undo-changes redo changes)
undo-lib (tht/get-tokens-lib undo)] undo-lib (tht/get-tokens-lib undo)]
(t/is (tht/token-data-eq? token (ctob/get-token-in-set redo-lib set-id (:id token)))) (t/is (tht/token-data-eq? token (ctob/get-token redo-lib set-id (:id token))))
;; Undo ;; Undo
(t/is (tht/token-data-eq? prev-token (ctob/get-token-in-set undo-lib set-id (:id prev-token))))))) (t/is (tht/token-data-eq? prev-token (ctob/get-token undo-lib set-id (:id prev-token)))))))
(t/deftest set-token-set-test (t/deftest set-token-set-test
(t/testing "delete token set" (t/testing "delete token set"

View File

@@ -81,11 +81,11 @@
(t/is (= (ctob/get-name token-set1) "test-token-set-1")) (t/is (= (ctob/get-name token-set1) "test-token-set-1"))
(t/is (= (ctob/get-description token-set1) "")) (t/is (= (ctob/get-description token-set1) ""))
(t/is (some? (ctob/get-modified-at token-set1))) (t/is (some? (ctob/get-modified-at token-set1)))
(t/is (empty? (ctob/get-tokens-map token-set1))) (t/is (empty? (ctob/get-tokens-map- token-set1)))
(t/is (= (ctob/get-name token-set2) "test-token-set-2")) (t/is (= (ctob/get-name token-set2) "test-token-set-2"))
(t/is (= (ctob/get-description token-set2) "test description")) (t/is (= (ctob/get-description token-set2) "test description"))
(t/is (= (ctob/get-modified-at token-set2) now)) (t/is (= (ctob/get-modified-at token-set2) now))
(t/is (empty? (ctob/get-tokens-map token-set2))))) (t/is (empty? (ctob/get-tokens-map- token-set2)))))
(t/deftest make-invalid-token-set (t/deftest make-invalid-token-set
(let [params {:name 777 :description 999}] (let [params {:name 777 :description 999}]
@@ -189,8 +189,8 @@
"baz.boo" (ctob/make-token :name "baz.boo" "baz.boo" (ctob/make-token :name "baz.boo"
:type :boolean :type :boolean
:value true)}))) :value true)})))
expected (-> (ctob/get-set tokens-lib (thi/id :test-token-set)) expected (-> tokens-lib
(ctob/get-tokens-map) (ctob/get-tokens-map (thi/id :test-token-set))
(ctob/tokens-tree))] (ctob/tokens-tree))]
(t/is (= (get-in expected ["foo" "bar" "baz" :name]) "foo.bar.baz")) (t/is (= (get-in expected ["foo" "bar" "baz" :name]) "foo.bar.baz"))
(t/is (= (get-in expected ["foo" "bar" "bam" :name]) "foo.bar.bam")) (t/is (= (get-in expected ["foo" "bar" "bam" :name]) "foo.bar.bam"))
@@ -316,11 +316,11 @@
:type :boolean :type :boolean
:value true)}))) :value true)})))
token-set-copy (ctob/duplicate-set (thi/id :test-token-set) tokens-lib {:suffix "copy"}) token-set-copy (ctob/duplicate-set (thi/id :test-token-set) tokens-lib {:suffix "copy"})
token (ctob/get-token token-set-copy (thi/id :test-token))] token (ctob/get-token- token-set-copy (thi/id :test-token))]
(t/is (some? token-set-copy)) (t/is (some? token-set-copy))
(t/is (= (ctob/get-name token-set-copy) "test-token-set-copy")) (t/is (= (ctob/get-name token-set-copy) "test-token-set-copy"))
(t/is (= (count (ctob/get-tokens-map token-set-copy)) 1)) (t/is (= (count (ctob/get-tokens-map- token-set-copy)) 1))
(t/is (= (:name token) "test-token")))) (t/is (= (:name token) "test-token"))))
(t/deftest duplicate-token-set-twice (t/deftest duplicate-token-set-twice
@@ -336,11 +336,11 @@
tokens-lib (ctob/add-set tokens-lib (ctob/duplicate-set (thi/id :test-token-set) tokens-lib {:suffix "copy"})) tokens-lib (ctob/add-set tokens-lib (ctob/duplicate-set (thi/id :test-token-set) tokens-lib {:suffix "copy"}))
token-set-copy (ctob/duplicate-set (thi/id :test-token-set) tokens-lib {:suffix "copy"}) token-set-copy (ctob/duplicate-set (thi/id :test-token-set) tokens-lib {:suffix "copy"})
token (ctob/get-token token-set-copy (thi/id :test-token))] token (ctob/get-token- token-set-copy (thi/id :test-token))]
(t/is (some? token-set-copy)) (t/is (some? token-set-copy))
(t/is (= (ctob/get-name token-set-copy) "test-token-set-copy-2")) (t/is (= (ctob/get-name token-set-copy) "test-token-set-copy-2"))
(t/is (= (count (ctob/get-tokens-map token-set-copy)) 1)) (t/is (= (count (ctob/get-tokens-map- token-set-copy)) 1))
(t/is (= (:name token) "test-token")))) (t/is (= (:name token) "test-token"))))
(t/deftest duplicate-empty-token-set (t/deftest duplicate-empty-token-set
@@ -349,11 +349,11 @@
:name "test-token-set"))) :name "test-token-set")))
token-set-copy (ctob/duplicate-set (thi/id :test-token-set) tokens-lib {:suffix "copy"}) token-set-copy (ctob/duplicate-set (thi/id :test-token-set) tokens-lib {:suffix "copy"})
tokens (ctob/get-tokens-map token-set-copy)] tokens (ctob/get-tokens-map- token-set-copy)]
(t/is (some? token-set-copy)) (t/is (some? token-set-copy))
(t/is (= (ctob/get-name token-set-copy) "test-token-set-copy")) (t/is (= (ctob/get-name token-set-copy) "test-token-set-copy"))
(t/is (= (count (ctob/get-tokens-map token-set-copy)) 0)) (t/is (= (count (ctob/get-tokens-map- token-set-copy)) 0))
(t/is (= (count tokens) 0)))) (t/is (= (count tokens) 0))))
(t/deftest duplicate-not-existing-token-set (t/deftest duplicate-not-existing-token-set
@@ -372,15 +372,17 @@
:type :boolean :type :boolean
:value true) :value true)
tokens-lib' (-> tokens-lib tokens-lib' (-> tokens-lib
(ctob/add-token-in-set (thi/id :test-token-set) token) (ctob/add-token (thi/id :test-token-set) token)
(ctob/add-token-in-set (uuid/next) token)) (ctob/add-token (uuid/next) token))
token-set (ctob/get-set tokens-lib (thi/id :test-token-set)) token-set (ctob/get-set tokens-lib (thi/id :test-token-set))
token-set' (ctob/get-set tokens-lib' (thi/id :test-token-set)) token-set' (ctob/get-set tokens-lib' (thi/id :test-token-set))
token' (ctob/get-token token-set' (thi/id :token))] token' (ctob/get-token tokens-lib'
(thi/id :test-token-set)
(thi/id :token))]
(t/is (= (ctob/set-count tokens-lib') 1)) (t/is (= (ctob/set-count tokens-lib') 1))
(t/is (= (count (ctob/get-tokens-map token-set')) 1)) (t/is (= (count (ctob/get-tokens-map tokens-lib' (thi/id :test-token-set))) 1))
(t/is (= (:name token') "test-token")) (t/is (= (:name token') "test-token"))
(t/is (ct/is-after? (ctob/get-modified-at token-set') (ctob/get-modified-at token-set))))) (t/is (ct/is-after? (ctob/get-modified-at token-set') (ctob/get-modified-at token-set)))))
@@ -388,40 +390,46 @@
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
:name "test-token-set")) :name "test-token-set"))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-1) (ctob/make-token :id (thi/new-id! :test-token-1)
:name "test-token-1" :name "test-token-1"
:type :boolean :type :boolean
:value true)) :value true))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-2) (ctob/make-token :id (thi/new-id! :test-token-2)
:name "test-token-2" :name "test-token-2"
:type :boolean :type :boolean
:value true))) :value true)))
tokens-lib' (-> tokens-lib tokens-lib' (-> tokens-lib
(ctob/update-token-in-set (thi/id :test-token-set) (thi/id :test-token-1) (ctob/update-token (thi/id :test-token-set) (thi/id :test-token-1)
(fn [token] (fn [token]
(assoc token (assoc token
:description "some description" :description "some description"
:value false))) :value false)))
(ctob/update-token-in-set (uuid/next) (thi/id :test-token-1) (ctob/update-token (uuid/next) (thi/id :test-token-1)
(fn [token] (fn [token]
(assoc token (assoc token
:name "no-effect"))) :name "no-effect")))
(ctob/update-token-in-set (thi/id :test-token-set) (uuid/next) (ctob/update-token (thi/id :test-token-set) (uuid/next)
(fn [token] (fn [token]
(assoc token (assoc token
:name "no-effect")))) :name "no-effect"))))
token-set (ctob/get-set tokens-lib (thi/id :test-token-set)) token-set (ctob/get-set tokens-lib (thi/id :test-token-set))
token-set' (ctob/get-set tokens-lib' (thi/id :test-token-set)) token-set' (ctob/get-set tokens-lib' (thi/id :test-token-set))
token (ctob/get-token token-set (thi/id :test-token-1)) token (ctob/get-token tokens-lib
token' (ctob/get-token token-set' (thi/id :test-token-1))] (thi/id :test-token-set)
(thi/id :test-token-1))
token' (ctob/get-token tokens-lib'
(thi/id :test-token-set)
(thi/id :test-token-1))
tokens' (ctob/get-tokens-map tokens-lib'
(thi/id :test-token-set))]
(t/is (= (ctob/set-count tokens-lib') 1)) (t/is (= (ctob/set-count tokens-lib') 1))
(t/is (= (count (ctob/get-tokens-map token-set')) 2)) (t/is (= (count tokens') 2))
(t/is (= (d/index-of (keys (ctob/get-tokens-map token-set')) "test-token-1") 0)) (t/is (= (d/index-of (keys tokens') "test-token-1") 0))
(t/is (= (:name token') "test-token-1")) (t/is (= (:name token') "test-token-1"))
(t/is (= (:description token') "some description")) (t/is (= (:description token') "some description"))
(t/is (= (:value token') false)) (t/is (= (:value token') false))
@@ -432,31 +440,37 @@
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
:name "test-token-set")) :name "test-token-set"))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-1) (ctob/make-token :id (thi/new-id! :test-token-1)
:name "test-token-1" :name "test-token-1"
:type :boolean :type :boolean
:value true)) :value true))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-2) (ctob/make-token :id (thi/new-id! :test-token-2)
:name "test-token-2" :name "test-token-2"
:type :boolean :type :boolean
:value true))) :value true)))
tokens-lib' (-> tokens-lib tokens-lib' (-> tokens-lib
(ctob/update-token-in-set (thi/id :test-token-set) (thi/id :test-token-1) (ctob/update-token (thi/id :test-token-set) (thi/id :test-token-1)
(fn [token] (fn [token]
(assoc token (assoc token
:name "updated-name")))) :name "updated-name"))))
token-set (ctob/get-set tokens-lib (thi/id :test-token-set)) token-set (ctob/get-set tokens-lib (thi/id :test-token-set))
token-set' (ctob/get-set tokens-lib' (thi/id :test-token-set)) token-set' (ctob/get-set tokens-lib' (thi/id :test-token-set))
token (ctob/get-token token-set (thi/id :test-token-1)) token (ctob/get-token tokens-lib
token' (ctob/get-token token-set' (thi/id :test-token-1))] (thi/id :test-token-set)
(thi/id :test-token-1))
token' (ctob/get-token tokens-lib'
(thi/id :test-token-set)
(thi/id :test-token-1))
tokens' (ctob/get-tokens-map tokens-lib'
(thi/id :test-token-set))]
(t/is (= (ctob/set-count tokens-lib') 1)) (t/is (= (ctob/set-count tokens-lib') 1))
(t/is (= (count (ctob/get-tokens-map token-set')) 2)) (t/is (= (count tokens') 2))
(t/is (= (d/index-of (keys (ctob/get-tokens-map token-set')) "updated-name") 0)) (t/is (= (d/index-of (keys tokens') "updated-name") 0))
(t/is (= (:name token') "updated-name")) (t/is (= (:name token') "updated-name"))
(t/is (= (:description token') "")) (t/is (= (:description token') ""))
(t/is (= (:value token') true)) (t/is (= (:value token') true))
@@ -467,22 +481,26 @@
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
:name "test-token-set")) :name "test-token-set"))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token) (ctob/make-token :id (thi/new-id! :test-token)
:name "test-token" :name "test-token"
:type :boolean :type :boolean
:value true))) :value true)))
tokens-lib' (-> tokens-lib tokens-lib' (-> tokens-lib
(ctob/delete-token-from-set (thi/id :test-token-set) (thi/id :test-token)) (ctob/delete-token (thi/id :test-token-set) (thi/id :test-token))
(ctob/delete-token-from-set (uuid/next) (thi/id :test-token)) (ctob/delete-token (uuid/next) (thi/id :test-token))
(ctob/delete-token-from-set (thi/id :test-token-set) (uuid/next))) (ctob/delete-token (thi/id :test-token-set) (uuid/next)))
token-set (ctob/get-set tokens-lib (thi/id :test-token-set)) token-set (ctob/get-set tokens-lib (thi/id :test-token-set))
token-set' (ctob/get-set tokens-lib' (thi/id :test-token-set)) token-set' (ctob/get-set tokens-lib' (thi/id :test-token-set))
token' (ctob/get-token token-set' (thi/id :test-token))] token' (ctob/get-token tokens-lib'
(thi/id :test-token-set)
(thi/id :test-token))
tokens' (ctob/get-tokens-map tokens-lib'
(thi/id :test-token-set))]
(t/is (= (ctob/set-count tokens-lib') 1)) (t/is (= (ctob/set-count tokens-lib') 1))
(t/is (= (count (ctob/get-tokens-map token-set')) 0)) (t/is (= (count tokens') 0))
(t/is (nil? token')) (t/is (nil? token'))
(t/is (ct/is-after? (ctob/get-modified-at token-set') (ctob/get-modified-at token-set))))) (t/is (ct/is-after? (ctob/get-modified-at token-set') (ctob/get-modified-at token-set)))))
@@ -821,7 +839,7 @@
(t/deftest transit-serialization (t/deftest transit-serialization
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :name "test-token-set")) (ctob/add-set (ctob/make-token-set :name "test-token-set"))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "test-token" (ctob/make-token :name "test-token"
:type :boolean :type :boolean
:value true)) :value true))
@@ -839,7 +857,7 @@
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
:name "test-token-set")) :name "test-token-set"))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "test-token" (ctob/make-token :name "test-token"
:type :boolean :type :boolean
:value true)) :value true))
@@ -872,29 +890,28 @@
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
:name "test-token-set")) :name "test-token-set"))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "token1" (ctob/make-token :name "token1"
:type :boolean :type :boolean
:value true)) :value true))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "group1.token2" (ctob/make-token :name "group1.token2"
:type :boolean :type :boolean
:value true)) :value true))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "group1.token3" (ctob/make-token :name "group1.token3"
:type :boolean :type :boolean
:value true)) :value true))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "group1.subgroup11.token4" (ctob/make-token :name "group1.subgroup11.token4"
:type :boolean :type :boolean
:value true)) :value true))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "group2.token5" (ctob/make-token :name "group2.token5"
:type :boolean :type :boolean
:value true))) :value true)))
set (ctob/get-set tokens-lib (thi/id :test-token-set)) tokens-list (ctob/get-tokens-seq tokens-lib (thi/id :test-token-set))]
tokens-list (ctob/get-tokens set)]
(t/is (= (count tokens-list) 5)) (t/is (= (count tokens-list) 5))
(t/is (= (:name (nth tokens-list 0)) "token1")) (t/is (= (:name (nth tokens-list 0)) "token1"))
@@ -907,24 +924,24 @@
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
:name "test-token-set")) :name "test-token-set"))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-1) (ctob/make-token :id (thi/new-id! :test-token-1)
:name "test-token-1" :name "test-token-1"
:type :boolean :type :boolean
:value true)) :value true))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-2) (ctob/make-token :id (thi/new-id! :test-token-2)
:name "group1.test-token-2" :name "group1.test-token-2"
:type :boolean :type :boolean
:value true)) :value true))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-3) (ctob/make-token :id (thi/new-id! :test-token-3)
:name "group1.test-token-3" :name "group1.test-token-3"
:type :boolean :type :boolean
:value true))) :value true)))
tokens-lib' (-> tokens-lib tokens-lib' (-> tokens-lib
(ctob/update-token-in-set (thi/id :test-token-set) (thi/id :test-token-2) (ctob/update-token (thi/id :test-token-set) (thi/id :test-token-2)
(fn [token] (fn [token]
(assoc token (assoc token
:description "some description" :description "some description"
@@ -932,8 +949,12 @@
token-set (ctob/get-set tokens-lib (thi/id :test-token-set)) token-set (ctob/get-set tokens-lib (thi/id :test-token-set))
token-set' (ctob/get-set tokens-lib' (thi/id :test-token-set)) token-set' (ctob/get-set tokens-lib' (thi/id :test-token-set))
token (ctob/get-token token-set (thi/id :test-token-2)) token (ctob/get-token tokens-lib
token' (ctob/get-token token-set' (thi/id :test-token-2))] (thi/id :test-token-set)
(thi/id :test-token-2))
token' (ctob/get-token tokens-lib'
(thi/id :test-token-set)
(thi/id :test-token-2))]
(t/is (= (ctob/set-count tokens-lib') 1)) (t/is (= (ctob/set-count tokens-lib') 1))
(t/is (= (:name token') "group1.test-token-2")) (t/is (= (:name token') "group1.test-token-2"))
@@ -946,32 +967,36 @@
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
:name "test-token-set")) :name "test-token-set"))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-1) (ctob/make-token :id (thi/new-id! :test-token-1)
:name "test-token-1" :name "test-token-1"
:type :boolean :type :boolean
:value true)) :value true))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-2) (ctob/make-token :id (thi/new-id! :test-token-2)
:name "group1.test-token-2" :name "group1.test-token-2"
:type :boolean :type :boolean
:value true)) :value true))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-3) (ctob/make-token :id (thi/new-id! :test-token-3)
:name "group1.test-token-3" :name "group1.test-token-3"
:type :boolean :type :boolean
:value true))) :value true)))
tokens-lib' (-> tokens-lib tokens-lib' (-> tokens-lib
(ctob/update-token-in-set (thi/id :test-token-set) (thi/id :test-token-2) (ctob/update-token (thi/id :test-token-set) (thi/id :test-token-2)
(fn [token] (fn [token]
(assoc token (assoc token
:name "group1.updated-name")))) :name "group1.updated-name"))))
token-set (ctob/get-set tokens-lib (thi/id :test-token-set)) token-set (ctob/get-set tokens-lib (thi/id :test-token-set))
token-set' (ctob/get-set tokens-lib' (thi/id :test-token-set)) token-set' (ctob/get-set tokens-lib' (thi/id :test-token-set))
token (ctob/get-token token-set (thi/id :test-token-2)) token (ctob/get-token tokens-lib
token' (ctob/get-token token-set' (thi/id :test-token-2))] (thi/id :test-token-set)
(thi/id :test-token-2))
token' (ctob/get-token tokens-lib'
(thi/id :test-token-set)
(thi/id :test-token-2))]
(t/is (= (ctob/set-count tokens-lib') 1)) (t/is (= (ctob/set-count tokens-lib') 1))
(t/is (= (:name token') "group1.updated-name")) (t/is (= (:name token') "group1.updated-name"))
@@ -984,35 +1009,41 @@
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
:name "test-token-set")) :name "test-token-set"))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-1) (ctob/make-token :id (thi/new-id! :test-token-1)
:name "test-token-1" :name "test-token-1"
:type :boolean :type :boolean
:value true)) :value true))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-2) (ctob/make-token :id (thi/new-id! :test-token-2)
:name "group1.test-token-2" :name "group1.test-token-2"
:type :boolean :type :boolean
:value true)) :value true))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-3) (ctob/make-token :id (thi/new-id! :test-token-3)
:name "group1.test-token-3" :name "group1.test-token-3"
:type :boolean :type :boolean
:value true))) :value true)))
tokens-lib' (-> tokens-lib tokens-lib' (-> tokens-lib
(ctob/update-token-in-set (thi/id :test-token-set) (thi/id :test-token-2) (ctob/update-token (thi/id :test-token-set) (thi/id :test-token-2)
(fn [token] (fn [token]
(assoc token (assoc token
:name "group2.updated-name")))) :name "group2.updated-name"))))
token-set (ctob/get-set tokens-lib (thi/id :test-token-set)) token-set (ctob/get-set tokens-lib (thi/id :test-token-set))
token-set' (ctob/get-set tokens-lib' (thi/id :test-token-set)) token-set' (ctob/get-set tokens-lib' (thi/id :test-token-set))
token (ctob/get-token token-set (thi/id :test-token-2)) token (ctob/get-token tokens-lib
token' (ctob/get-token token-set' (thi/id :test-token-2))] (thi/id :test-token-set)
(thi/id :test-token-2))
token' (ctob/get-token tokens-lib'
(thi/id :test-token-set)
(thi/id :test-token-2))
tokens' (ctob/get-tokens-map tokens-lib'
(thi/id :test-token-set))]
(t/is (= (ctob/set-count tokens-lib') 1)) (t/is (= (ctob/set-count tokens-lib') 1))
(t/is (= (d/index-of (keys (ctob/get-tokens-map token-set')) "group2.updated-name") 1)) (t/is (= (d/index-of (keys tokens') "group2.updated-name") 1))
(t/is (= (:name token') "group2.updated-name")) (t/is (= (:name token') "group2.updated-name"))
(t/is (= (:description token') "")) (t/is (= (:description token') ""))
(t/is (= (:value token') true)) (t/is (= (:value token') true))
@@ -1023,25 +1054,29 @@
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
:name "test-token-set")) :name "test-token-set"))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-1) (ctob/make-token :id (thi/new-id! :test-token-1)
:name "test-token-1" :name "test-token-1"
:type :boolean :type :boolean
:value true)) :value true))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-2) (ctob/make-token :id (thi/new-id! :test-token-2)
:name "group1.test-token-2" :name "group1.test-token-2"
:type :boolean :type :boolean
:value true))) :value true)))
tokens-lib' (-> tokens-lib tokens-lib' (-> tokens-lib
(ctob/delete-token-from-set (thi/id :test-token-set) (thi/id :test-token-2))) (ctob/delete-token (thi/id :test-token-set) (thi/id :test-token-2)))
token-set (ctob/get-set tokens-lib (thi/id :test-token-set)) token-set (ctob/get-set tokens-lib (thi/id :test-token-set))
token-set' (ctob/get-set tokens-lib' (thi/id :test-token-set)) token-set' (ctob/get-set tokens-lib' (thi/id :test-token-set))
token' (ctob/get-token token-set' (thi/id :test-token-2))] token' (ctob/get-token tokens-lib'
(thi/id :test-token-set)
(thi/id :test-token-2))
tokens' (ctob/get-tokens-map tokens-lib'
(thi/id :test-token-set))]
(t/is (= (ctob/set-count tokens-lib') 1)) (t/is (= (ctob/set-count tokens-lib') 1))
(t/is (= (count (ctob/get-tokens-map token-set')) 1)) (t/is (= (count tokens') 1))
(t/is (nil? token')) (t/is (nil? token'))
(t/is (ct/is-after? (ctob/get-modified-at token-set') (ctob/get-modified-at token-set))))) (t/is (ct/is-after? (ctob/get-modified-at token-set') (ctob/get-modified-at token-set)))))
@@ -1269,85 +1304,79 @@
(t/deftest parse-single-set-legacy-json (t/deftest parse-single-set-legacy-json
(let [json (-> (slurp "test/common_tests/types/data/tokens-single-set-legacy-example.json") (let [json (-> (slurp "test/common_tests/types/data/tokens-single-set-legacy-example.json")
(json/decode {:key-fn identity})) (json/decode {:key-fn identity}))
lib (ctob/parse-decoded-json json "single_set") lib (ctob/parse-decoded-json json "single_set")]
token-set (ctob/get-set-by-name lib "single_set")]
(t/is (= '("single_set") (ctob/get-ordered-set-names lib))) (t/is (= '("single_set") (ctob/get-ordered-set-names lib)))
(t/testing "token added" (t/testing "token added"
(t/is (some? (ctob/get-token-in-set-by-name lib (ctob/get-id token-set) "color.red.100"))))))) (t/is (some? (ctob/get-token-by-name lib "single_set" "color.red.100")))))))
#?(:clj #?(:clj
(t/deftest parse-single-set-dtcg-json (t/deftest parse-single-set-dtcg-json
(let [json (-> (slurp "test/common_tests/types/data/tokens-single-set-dtcg-example.json") (let [json (-> (slurp "test/common_tests/types/data/tokens-single-set-dtcg-example.json")
(json/decode {:key-fn identity})) (json/decode {:key-fn identity}))
lib (ctob/parse-decoded-json json "single_set") lib (ctob/parse-decoded-json json "single_set")]
token-set (ctob/get-set-by-name lib "single_set")]
(t/is (= '("single_set") (ctob/get-ordered-set-names lib))) (t/is (= '("single_set") (ctob/get-ordered-set-names lib)))
(t/testing "token added" (t/testing "token added"
(t/is (some? (ctob/get-token-in-set-by-name lib (ctob/get-id token-set) "color.red.100"))))))) (t/is (some? (ctob/get-token-by-name lib "single_set" "color.red.100")))))))
#?(:clj #?(:clj
(t/deftest parse-multi-set-legacy-json (t/deftest parse-multi-set-legacy-json
(let [json (-> (slurp "test/common_tests/types/data/tokens-multi-set-legacy-example.json") (let [json (-> (slurp "test/common_tests/types/data/tokens-multi-set-legacy-example.json")
(json/decode {:key-fn identity})) (json/decode {:key-fn identity}))
lib (ctob/parse-decoded-json json "") lib (ctob/parse-decoded-json json "")
token-theme (ctob/get-theme lib "group-1" "theme-1") token-theme (ctob/get-theme lib "group-1" "theme-1")]
core-set (ctob/get-set-by-name lib "core")
theme-set (ctob/get-set-by-name lib "theme")]
(t/is (= '("core" "light" "dark" "theme") (ctob/get-ordered-set-names lib))) (t/is (= '("core" "light" "dark" "theme") (ctob/get-ordered-set-names lib)))
(t/testing "set exists in theme" (t/testing "set exists in theme"
(t/is (= (:group token-theme) "group-1")) (t/is (= (:group token-theme) "group-1"))
(t/is (= (:name token-theme) "theme-1")) (t/is (= (:name token-theme) "theme-1"))
(t/is (= (:sets token-theme) #{"light"}))) (t/is (= (:sets token-theme) #{"light"})))
(t/testing "tokens exist in core set" (t/testing "tokens exist in core set"
(t/is (tht/token-data-eq? (ctob/get-token-in-set-by-name lib (ctob/get-id core-set) "colors.red.600") (t/is (tht/token-data-eq? (ctob/get-token-by-name lib "core" "colors.red.600")
{:name "colors.red.600" {:name "colors.red.600"
:type :color :type :color
:value "#e53e3e" :value "#e53e3e"
:description ""})) :description ""}))
(t/is (tht/token-data-eq? (ctob/get-token-in-set-by-name lib (ctob/get-id core-set) "spacing.multi-value") (t/is (tht/token-data-eq? (ctob/get-token-by-name lib "core" "spacing.multi-value")
{:name "spacing.multi-value" {:name "spacing.multi-value"
:type :spacing :type :spacing
:value "{dimension.sm} {dimension.xl}" :value "{dimension.sm} {dimension.xl}"
:description "You can have multiple values in a single spacing token"})) :description "You can have multiple values in a single spacing token"}))
(t/is (tht/token-data-eq? (ctob/get-token-in-set-by-name lib (ctob/get-id theme-set) "button.primary.background") (t/is (tht/token-data-eq? (ctob/get-token-by-name lib "theme" "button.primary.background")
{:name "button.primary.background" {:name "button.primary.background"
:type :color :type :color
:value "{accent.default}" :value "{accent.default}"
:description ""}))) :description ""})))
(t/testing "invalid tokens got discarded" (t/testing "invalid tokens got discarded"
(t/is (nil? (ctob/get-token-in-set-by-name lib (ctob/get-id theme-set) "boxShadow.default"))))))) (t/is (nil? (ctob/get-token-by-name lib "theme" "boxShadow.default")))))))
#?(:clj #?(:clj
(t/deftest parse-multi-set-dtcg-json (t/deftest parse-multi-set-dtcg-json
(let [json (-> (slurp "test/common_tests/types/data/tokens-multi-set-example.json") (let [json (-> (slurp "test/common_tests/types/data/tokens-multi-set-example.json")
(json/decode {:key-fn identity})) (json/decode {:key-fn identity}))
lib (ctob/parse-decoded-json json "") lib (ctob/parse-decoded-json json "")
token-theme (ctob/get-theme lib "group-1" "theme-1") token-theme (ctob/get-theme lib "group-1" "theme-1")]
core-set (ctob/get-set-by-name lib "core")
theme-set (ctob/get-set-by-name lib "theme")]
(t/is (= '("core" "light" "dark" "theme") (ctob/get-ordered-set-names lib))) (t/is (= '("core" "light" "dark" "theme") (ctob/get-ordered-set-names lib)))
(t/testing "set exists in theme" (t/testing "set exists in theme"
(t/is (= (:group token-theme) "group-1")) (t/is (= (:group token-theme) "group-1"))
(t/is (= (:name token-theme) "theme-1")) (t/is (= (:name token-theme) "theme-1"))
(t/is (= (:sets token-theme) #{"light"}))) (t/is (= (:sets token-theme) #{"light"})))
(t/testing "tokens exist in core set" (t/testing "tokens exist in core set"
(t/is (tht/token-data-eq? (ctob/get-token-in-set-by-name lib (ctob/get-id core-set) "colors.red.600") (t/is (tht/token-data-eq? (ctob/get-token-by-name lib "core" "colors.red.600")
{:name "colors.red.600" {:name "colors.red.600"
:type :color :type :color
:value "#e53e3e" :value "#e53e3e"
:description ""})) :description ""}))
(t/is (tht/token-data-eq? (ctob/get-token-in-set-by-name lib (ctob/get-id core-set) "spacing.multi-value") (t/is (tht/token-data-eq? (ctob/get-token-by-name lib "core" "spacing.multi-value")
{:name "spacing.multi-value" {:name "spacing.multi-value"
:type :spacing :type :spacing
:value "{dimension.sm} {dimension.xl}" :value "{dimension.sm} {dimension.xl}"
:description "You can have multiple values in a single spacing token"})) :description "You can have multiple values in a single spacing token"}))
(t/is (tht/token-data-eq? (ctob/get-token-in-set-by-name lib (ctob/get-id theme-set) "button.primary.background") (t/is (tht/token-data-eq? (ctob/get-token-by-name lib "theme" "button.primary.background")
{:name "button.primary.background" {:name "button.primary.background"
:type :color :type :color
:value "{accent.default}" :value "{accent.default}"
:description ""}))) :description ""})))
(t/testing "invalid tokens got discarded" (t/testing "invalid tokens got discarded"
(t/is (nil? (ctob/get-token-in-set-by-name lib (ctob/get-id theme-set) "boxShadow.default"))))))) (t/is (nil? (ctob/get-token-by-name lib "theme" "boxShadow.default")))))))
#?(:clj #?(:clj
(t/deftest parse-multi-set-dtcg-json-default-team (t/deftest parse-multi-set-dtcg-json-default-team
@@ -1355,15 +1384,14 @@
(json/decode {:key-fn identity})) (json/decode {:key-fn identity}))
lib (ctob/parse-decoded-json json "") lib (ctob/parse-decoded-json json "")
themes (ctob/get-themes lib) themes (ctob/get-themes lib)
first-theme (first themes) first-theme (first themes)]
dark-set (ctob/get-set-by-name lib "dark")]
(t/is (= '("dark") (ctob/get-ordered-set-names lib))) (t/is (= '("dark") (ctob/get-ordered-set-names lib)))
(t/is (= 1 (count themes))) (t/is (= 1 (count themes)))
(t/testing "existing theme is default theme" (t/testing "existing theme is default theme"
(t/is (= (:group first-theme) "")) (t/is (= (:group first-theme) ""))
(t/is (= (:name first-theme) ctob/hidden-theme-name))) (t/is (= (:name first-theme) ctob/hidden-theme-name)))
(t/testing "token exist in dark set" (t/testing "token exist in dark set"
(t/is (tht/token-data-eq? (ctob/get-token-in-set-by-name lib (ctob/get-id dark-set) "small") (t/is (tht/token-data-eq? (ctob/get-token-by-name lib "dark" "small")
{:name "small" {:name "small"
:value "8" :value "8"
:type :border-radius :type :border-radius
@@ -1599,11 +1627,10 @@
(t/deftest parse-typography-tokens (t/deftest parse-typography-tokens
(let [json (-> (slurp "test/common_tests/types/data/tokens-typography-example.json") (let [json (-> (slurp "test/common_tests/types/data/tokens-typography-example.json")
(json/decode {:key-fn identity})) (json/decode {:key-fn identity}))
lib (ctob/parse-decoded-json json "typography-test") lib (ctob/parse-decoded-json json "typography-test")]
set (ctob/get-set-by-name lib "typography-test")]
(t/testing "typography token with composite value" (t/testing "typography token with composite value"
(let [token (ctob/get-token-in-set-by-name lib (ctob/get-id set) "test.typo")] (let [token (ctob/get-token-by-name lib "typography-test" "test.typo")]
(t/is (some? token)) (t/is (some? token))
(t/is (= (:type token) :typography)) (t/is (= (:type token) :typography))
(t/is (= (:value token) {:font-weight "100" (t/is (= (:value token) {:font-weight "100"
@@ -1612,28 +1639,28 @@
(t/is (= (:description token) "")))) (t/is (= (:description token) ""))))
(t/testing "typography token with string reference" (t/testing "typography token with string reference"
(let [token (ctob/get-token-in-set-by-name lib (ctob/get-id set) "test.typo2")] (let [token (ctob/get-token-by-name lib "typography-test" "test.typo2")]
(t/is (some? token)) (t/is (some? token))
(t/is (= (:type token) :typography)) (t/is (= (:type token) :typography))
(t/is (= (:value token) "{typo}")) (t/is (= (:value token) "{typo}"))
(t/is (= (:description token) "")))) (t/is (= (:description token) ""))))
(t/testing "typography token referencing single token" (t/testing "typography token referencing single token"
(let [token (ctob/get-token-in-set-by-name lib (ctob/get-id set) "test.typo-to-single")] (let [token (ctob/get-token-by-name lib "typography-test" "test.typo-to-single")]
(t/is (some? token)) (t/is (some? token))
(t/is (= (:type token) :typography)) (t/is (= (:type token) :typography))
(t/is (= (:value token) "{font-weight}")) (t/is (= (:value token) "{font-weight}"))
(t/is (= (:description token) "")))) (t/is (= (:description token) ""))))
(t/testing "typography token with empty value" (t/testing "typography token with empty value"
(let [token (ctob/get-token-in-set-by-name lib (ctob/get-id set) "test.test-empty")] (let [token (ctob/get-token-by-name lib "typography-test" "test.test-empty")]
(t/is (some? token)) (t/is (some? token))
(t/is (= (:type token) :typography)) (t/is (= (:type token) :typography))
(t/is (= (:value token) {})) (t/is (= (:value token) {}))
(t/is (= (:description token) "")))) (t/is (= (:description token) ""))))
(t/testing "typography token with complex value and description" (t/testing "typography token with complex value and description"
(let [token (ctob/get-token-in-set-by-name lib (ctob/get-id set) "test.typo-complex")] (let [token (ctob/get-token-by-name lib "typography-test" "test.typo-complex")]
(t/is (some? token)) (t/is (some? token))
(t/is (= (:type token) :typography)) (t/is (= (:type token) :typography))
(t/is (= (:value token) {:font-weight "bold" (t/is (= (:value token) {:font-weight "bold"
@@ -1645,8 +1672,8 @@
(t/is (= (:description token) "A complex typography token")))) (t/is (= (:description token) "A complex typography token"))))
(t/testing "individual font tokens still work" (t/testing "individual font tokens still work"
(let [font-weight-token (ctob/get-token-in-set-by-name lib (ctob/get-id set) "test.font-weight") (let [font-weight-token (ctob/get-token-by-name lib "typography-test" "test.font-weight")
font-size-token (ctob/get-token-in-set-by-name lib (ctob/get-id set) "test.font-size")] font-size-token (ctob/get-token-by-name lib "typography-test" "test.font-size")]
(t/is (some? font-weight-token)) (t/is (some? font-weight-token))
(t/is (= (:type font-weight-token) :font-weight)) (t/is (= (:type font-weight-token) :font-weight))
(t/is (= (:value font-weight-token) "200")) (t/is (= (:value font-weight-token) "200"))
@@ -1656,7 +1683,7 @@
(t/is (= (:value font-size-token) "18px")))) (t/is (= (:value font-size-token) "18px"))))
(t/testing "typography token with string font family gets transformed to array" (t/testing "typography token with string font family gets transformed to array"
(let [token (ctob/get-token-in-set-by-name lib (ctob/get-id set) "test.typo-with-string-font-family")] (let [token (ctob/get-token-by-name lib "typography-test" "test.typo-with-string-font-family")]
(t/is (some? token)) (t/is (some? token))
(t/is (= (:type token) :typography)) (t/is (= (:type token) :typography))
(t/is (= (:value token) {:font-weight "600" (t/is (= (:value token) {:font-weight "600"
@@ -1732,20 +1759,18 @@
;; Export to JSON format ;; Export to JSON format
exported (ctob/export-dtcg-json original-lib) exported (ctob/export-dtcg-json original-lib)
;; Import back ;; Import back
imported-lib (ctob/parse-decoded-json exported "") imported-lib (ctob/parse-decoded-json exported "")]
original-set (ctob/get-set-by-name original-lib "test-set")
imported-set (ctob/get-set-by-name imported-lib "test-set")]
(t/testing "round trip preserves typography tokens" (t/testing "round trip preserves typography tokens"
(let [original-token (ctob/get-token-in-set-by-name original-lib (ctob/get-id original-set) "typo.test") (let [original-token (ctob/get-token-by-name original-lib "test-set" "typo.test")
imported-token (ctob/get-token-in-set-by-name imported-lib (ctob/get-id imported-set) "typo.test")] imported-token (ctob/get-token-by-name imported-lib "test-set" "typo.test")]
(t/is (some? imported-token)) (t/is (some? imported-token))
(t/is (= (:type imported-token) (:type original-token))) (t/is (= (:type imported-token) (:type original-token)))
(t/is (= (:value imported-token) (:value original-token))) (t/is (= (:value imported-token) (:value original-token)))
(t/is (= (:description imported-token) (:description original-token)))) (t/is (= (:description imported-token) (:description original-token))))
(let [original-ref (ctob/get-token-in-set-by-name original-lib (ctob/get-id original-set) "typo.ref") (let [original-ref (ctob/get-token-by-name original-lib "test-set" "typo.ref")
imported-ref (ctob/get-token-in-set-by-name imported-lib (ctob/get-id imported-set) "typo.ref")] imported-ref (ctob/get-token-by-name imported-lib "test-set" "typo.ref")]
(t/is (some? imported-ref)) (t/is (some? imported-ref))
(t/is (= (:type imported-ref) (:type original-ref))) (t/is (= (:type imported-ref) (:type original-ref)))
(t/is (= (:value imported-ref) (:value original-ref)))))))) (t/is (= (:value imported-ref) (:value original-ref))))))))
@@ -1754,32 +1779,31 @@
(t/deftest parse-font-family-tokens (t/deftest parse-font-family-tokens
(let [json (-> (slurp "test/common_tests/types/data/tokens-font-family-example.json") (let [json (-> (slurp "test/common_tests/types/data/tokens-font-family-example.json")
(json/decode {:key-fn identity})) (json/decode {:key-fn identity}))
lib (ctob/parse-decoded-json json "font-family-test") lib (ctob/parse-decoded-json json "font-family-test")]
set (ctob/get-set-by-name lib "font-family-test")]
(t/testing "string font family token gets split into array" (t/testing "string font family token gets split into array"
(let [token (ctob/get-token-in-set-by-name lib (ctob/get-id set) "fonts.string-font-family")] (let [token (ctob/get-token-by-name lib "font-family-test" "fonts.string-font-family")]
(t/is (some? token)) (t/is (some? token))
(t/is (= (:type token) :font-family)) (t/is (= (:type token) :font-family))
(t/is (= (:value token) ["Arial" "Helvetica" "sans-serif"])) (t/is (= (:value token) ["Arial" "Helvetica" "sans-serif"]))
(t/is (= (:description token) "A font family defined as a string")))) (t/is (= (:description token) "A font family defined as a string"))))
(t/testing "array font family token stays as array" (t/testing "array font family token stays as array"
(let [token (ctob/get-token-in-set-by-name lib (ctob/get-id set) "fonts.array-font-family")] (let [token (ctob/get-token-by-name lib "font-family-test" "fonts.array-font-family")]
(t/is (some? token)) (t/is (some? token))
(t/is (= (:type token) :font-family)) (t/is (= (:type token) :font-family))
(t/is (= (:value token) ["Inter" "system-ui" "sans-serif"])) (t/is (= (:value token) ["Inter" "system-ui" "sans-serif"]))
(t/is (= (:description token) "A font family defined as an array")))) (t/is (= (:description token) "A font family defined as an array"))))
(t/testing "single font family string gets converted to array" (t/testing "single font family string gets converted to array"
(let [token (ctob/get-token-in-set-by-name lib (ctob/get-id set) "fonts.single-font-family")] (let [token (ctob/get-token-by-name lib "font-family-test" "fonts.single-font-family")]
(t/is (some? token)) (t/is (some? token))
(t/is (= (:type token) :font-family)) (t/is (= (:type token) :font-family))
(t/is (= (:value token) ["Georgia"])) (t/is (= (:value token) ["Georgia"]))
(t/is (= (:description token) "")))) (t/is (= (:description token) ""))))
(t/testing "complex font names with spaces handled correctly" (t/testing "complex font names with spaces handled correctly"
(let [token (ctob/get-token-in-set-by-name lib (ctob/get-id set) "fonts.font-with-spaces")] (let [token (ctob/get-token-by-name lib "font-family-test" "fonts.font-with-spaces")]
(t/is (some? token)) (t/is (some? token))
(t/is (= (:type token) :font-family)) (t/is (= (:type token) :font-family))
(t/is (= (:value token) ["Source Sans Pro" "Arial" "sans-serif"]))))))) (t/is (= (:value token) ["Source Sans Pro" "Arial" "sans-serif"])))))))
@@ -1834,20 +1858,18 @@
;; Export to JSON format ;; Export to JSON format
exported (ctob/export-dtcg-json original-lib) exported (ctob/export-dtcg-json original-lib)
;; Import back ;; Import back
imported-lib (ctob/parse-decoded-json exported "") imported-lib (ctob/parse-decoded-json exported "")]
original-set (ctob/get-set-by-name original-lib "test-set")
imported-set (ctob/get-set-by-name imported-lib "test-set")]
(t/testing "round trip preserves font family tokens" (t/testing "round trip preserves font family tokens"
(let [original-token (ctob/get-token-in-set-by-name original-lib (ctob/get-id original-set) "fonts.test-array") (let [original-token (ctob/get-token-by-name original-lib "test-set" "fonts.test-array")
imported-token (ctob/get-token-in-set-by-name imported-lib (ctob/get-id imported-set) "fonts.test-array")] imported-token (ctob/get-token-by-name imported-lib "test-set" "fonts.test-array")]
(t/is (some? imported-token)) (t/is (some? imported-token))
(t/is (= (:type imported-token) (:type original-token))) (t/is (= (:type imported-token) (:type original-token)))
(t/is (= (:value imported-token) (:value original-token))) (t/is (= (:value imported-token) (:value original-token)))
(t/is (= (:description imported-token) (:description original-token)))) (t/is (= (:description imported-token) (:description original-token))))
(let [original-single (ctob/get-token-in-set-by-name original-lib (ctob/get-id original-set) "fonts.test-single") (let [original-single (ctob/get-token-by-name original-lib "test-set" "fonts.test-single")
imported-single (ctob/get-token-in-set-by-name imported-lib (ctob/get-id imported-set) "fonts.test-single")] imported-single (ctob/get-token-by-name imported-lib "test-set" "fonts.test-single")]
(t/is (some? imported-single)) (t/is (some? imported-single))
(t/is (= (:type imported-single) (:type original-single))) (t/is (= (:type imported-single) (:type original-single)))
(t/is (= (:value imported-single) (:value original-single)))))))) (t/is (= (:value imported-single) (:value original-single))))))))

View File

@@ -328,8 +328,7 @@
"Global" "Global"
token-set token-set
(-> (ctob/make-token-set :name set-name) (ctob/make-token-set :name set-name)
(ctob/add-token token))
hidden-theme hidden-theme
(ctob/make-hidden-theme) (ctob/make-hidden-theme)
@@ -340,7 +339,8 @@
changes changes
(-> (pcb/empty-changes) (-> (pcb/empty-changes)
(pcb/with-library-data data) (pcb/with-library-data data)
(pcb/set-token-set set-name token-set) (pcb/set-token-set (ctob/get-id token-set) token-set)
(pcb/set-token (ctob/get-id token-set) (:id token) token)
(pcb/set-token-theme (:group hidden-theme) (pcb/set-token-theme (:group hidden-theme)
(:name hidden-theme) (:name hidden-theme)
hidden-theme-with-set) hidden-theme-with-set)
@@ -377,7 +377,8 @@
(watch [it state _] (watch [it state _]
(let [token-set (lookup-token-set state) (let [token-set (lookup-token-set state)
data (dsh/lookup-file-data state) data (dsh/lookup-file-data state)
token (ctob/get-token token-set id) token (-> (get-tokens-lib state)
(ctob/get-token (ctob/get-id token-set) id))
token' (->> (merge token params) token' (->> (merge token params)
(into {}) (into {})
(ctob/make-token)) (ctob/make-token))
@@ -410,15 +411,17 @@
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
(when-let [token-set (lookup-token-set state)] (when-let [token-set (lookup-token-set state)]
(when-let [token (ctob/get-token token-set token-id)] (when-let [tokens-lib (get-tokens-lib state)]
(let [tokens (ctob/get-tokens token-set) (when-let [token (ctob/get-token tokens-lib
(ctob/get-id token-set)
token-id)]
(let [tokens (ctob/get-tokens-seq tokens-lib (ctob/get-id token-set))
unames (map :name tokens) unames (map :name tokens)
suffix (tr "workspace.tokens.duplicate-suffix") suffix (tr "workspace.tokens.duplicate-suffix")
copy-name (cfh/generate-unique-name (:name token) unames :suffix suffix)] copy-name (cfh/generate-unique-name (:name token) unames :suffix suffix)]
(rx/of (create-token (assoc token (rx/of (create-token (assoc token
:id (uuid/next) :id (uuid/next)
:name copy-name))))))))) :name copy-name))))))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; TOKEN UI OPS ;; TOKEN UI OPS

View File

@@ -26,9 +26,13 @@
(ctob/get-set set-id)))) (ctob/get-set set-id))))
(defn get-token-in-selected-set [state token-id] (defn get-token-in-selected-set [state token-id]
(some-> (get-selected-token-set state) (when-let [set-id (get-selected-token-set-id state)]
(ctob/get-token token-id))) (some-> (dsh/lookup-file-data state)
(get :tokens-lib)
(ctob/get-token set-id token-id))))
(defn get-all-tokens-in-selected-set [state] (defn get-all-tokens-in-selected-set [state]
(some-> (get-selected-token-set state) (when-let [set-id (get-selected-token-set-id state)]
(ctob/get-tokens-map))) (some-> (dsh/lookup-file-data state)
(get :tokens-lib)
(ctob/get-tokens-map set-id))))

View File

@@ -693,7 +693,7 @@
[sets] [sets]
(map (fn [s] (map (fn [s]
{:set (ctob/get-name s) {:set (ctob/get-name s)
:tokens (ctob/get-tokens s)}) :tokens (ctob/get-tokens-seq- s)}) ;; TODO: this function should be moved to common.logic and refactored
sets)) sets))
(defn- filter-active-sets (defn- filter-active-sets

View File

@@ -81,8 +81,8 @@
;; If we have not selected any set explicitly we just ;; If we have not selected any set explicitly we just
;; select the first one from the list of sets ;; select the first one from the list of sets
selected-token-set-tokens selected-token-set-tokens
(when selected-token-set (when selected-token-set-id
(ctob/get-tokens-map selected-token-set)) (some-> tokens-lib (ctob/get-tokens-map selected-token-set-id)))
tokens tokens
(mf/with-memo [active-tokens selected-token-set-tokens] (mf/with-memo [active-tokens selected-token-set-tokens]

View File

@@ -39,17 +39,17 @@
(ctob/add-theme (ctob/make-token-theme :name "test-theme" (ctob/add-theme (ctob/make-token-theme :name "test-theme"
:sets #{"test-token-set"})) :sets #{"test-token-set"}))
(ctob/set-active-themes #{"/test-theme"}) (ctob/set-active-themes #{"/test-theme"})
(ctob/add-token-in-set (cthi/id :test-token-set) (ctob/add-token (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :test-token-1) (ctob/make-token :id (cthi/new-id! :test-token-1)
:name "test-token-1" :name "test-token-1"
:type :border-radius :type :border-radius
:value 25)) :value 25))
(ctob/add-token-in-set (cthi/id :test-token-set) (ctob/add-token (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :test-token-2) (ctob/make-token :id (cthi/new-id! :test-token-2)
:name "test-token-2" :name "test-token-2"
:type :border-radius :type :border-radius
:value 50)) :value 50))
(ctob/add-token-in-set (cthi/id :test-token-set) (ctob/add-token (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :test-token-3) (ctob/make-token :id (cthi/new-id! :test-token-3)
:name "test-token-3" :name "test-token-3"
:type :border-radius :type :border-radius
@@ -327,32 +327,32 @@
(ctob/add-theme (ctob/make-token-theme :name "test-theme" (ctob/add-theme (ctob/make-token-theme :name "test-theme"
:sets #{"test-token-set"})) :sets #{"test-token-set"}))
(ctob/set-active-themes #{"/test-theme"}) (ctob/set-active-themes #{"/test-theme"})
(ctob/add-token-in-set (cthi/id :test-token-set) (ctob/add-token (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :token-radius) (ctob/make-token :id (cthi/new-id! :token-radius)
:name "token-radius" :name "token-radius"
:type :border-radius :type :border-radius
:value 10)) :value 10))
(ctob/add-token-in-set (cthi/id :test-token-set) (ctob/add-token (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :token-rotation) (ctob/make-token :id (cthi/new-id! :token-rotation)
:name "token-rotation" :name "token-rotation"
:type :rotation :type :rotation
:value 30)) :value 30))
(ctob/add-token-in-set (cthi/id :test-token-set) (ctob/add-token (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :token-opacity) (ctob/make-token :id (cthi/new-id! :token-opacity)
:name "token-opacity" :name "token-opacity"
:type :opacity :type :opacity
:value 0.7)) :value 0.7))
(ctob/add-token-in-set (cthi/id :test-token-set) (ctob/add-token (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :token-stroke-width) (ctob/make-token :id (cthi/new-id! :token-stroke-width)
:name "token-stroke-width" :name "token-stroke-width"
:type :stroke-width :type :stroke-width
:value 2)) :value 2))
(ctob/add-token-in-set (cthi/id :test-token-set) (ctob/add-token (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :token-color) (ctob/make-token :id (cthi/new-id! :token-color)
:name "token-color" :name "token-color"
:type :color :type :color
:value "#00ff00")) :value "#00ff00"))
(ctob/add-token-in-set (cthi/id :test-token-set) (ctob/add-token (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :token-dimensions) (ctob/make-token :id (cthi/new-id! :token-dimensions)
:name "token-dimensions" :name "token-dimensions"
:type :dimensions :type :dimensions

View File

@@ -17,35 +17,35 @@
(ctob/add-theme (ctob/make-token-theme :name "test-theme" (ctob/add-theme (ctob/make-token-theme :name "test-theme"
:sets #{"test-token-set"})) :sets #{"test-token-set"}))
(ctob/set-active-themes #{"/test-theme"}) (ctob/set-active-themes #{"/test-theme"})
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "token-radius" (ctob/make-token :name "token-radius"
:type :border-radius :type :border-radius
:value 10)) :value 10))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "token-color" (ctob/make-token :name "token-color"
:type :color :type :color
:value "red")) :value "red"))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "token-spacing" (ctob/make-token :name "token-spacing"
:type :spacing :type :spacing
:value 10)) :value 10))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "token-sizing" (ctob/make-token :name "token-sizing"
:type :sizing :type :sizing
:value 10)) :value 10))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "token-rotation" (ctob/make-token :name "token-rotation"
:type :rotation :type :rotation
:value 10)) :value 10))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "token-opacity" (ctob/make-token :name "token-opacity"
:type :opacity :type :opacity
:value 10)) :value 10))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "token-dimensions" (ctob/make-token :name "token-dimensions"
:type :dimensions :type :dimensions
:value 10)) :value 10))
(ctob/add-token-in-set (thi/id :test-token-set) (ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "token-number" (ctob/make-token :name "token-number"
:type :number :type :number
:value 10)))) :value 10))))

View File

@@ -24,8 +24,8 @@
(dwti/import-file-stream "core") (dwti/import-file-stream "core")
(rx/subs! (fn [tokens-lib] (rx/subs! (fn [tokens-lib]
(t/is (instance? ctob/TokensLib tokens-lib)) (t/is (instance? ctob/TokensLib tokens-lib))
(t/is (= "red" (-> (ctob/get-set-by-name tokens-lib "core") (t/is (= "red" (-> tokens-lib
(ctob/get-token-by-name "color") (ctob/get-token-by-name "core" "color")
(:value)))) (:value))))
(done)))))))) (done))))))))
@@ -96,7 +96,6 @@ color.value tries to reference missing, which is not defined.")))
(->> (rx/of json) (->> (rx/of json)
(dwti/import-file-stream "") (dwti/import-file-stream "")
(rx/subs! (fn [tokens-lib] (rx/subs! (fn [tokens-lib]
(let [token-set (ctob/get-set-by-name tokens-lib "core")]
(t/is (instance? ctob/TokensLib tokens-lib)) (t/is (instance? ctob/TokensLib tokens-lib))
(t/is (= "{missing}" (:value (ctob/get-token-in-set-by-name tokens-lib (ctob/get-id token-set) "color")))) (t/is (= "{missing}" (:value (ctob/get-token-by-name tokens-lib "core" "color"))))
(done))))))))) (done))))))))

View File

@@ -49,9 +49,9 @@
(ctob/set-active-themes #{"/Theme A"}) (ctob/set-active-themes #{"/Theme A"})
(ctob/add-set (ctob/make-token-set :id (cthi/new-id! :set-a) (ctob/add-set (ctob/make-token-set :id (cthi/new-id! :set-a)
:name "Set A")) :name "Set A"))
(ctob/add-token-in-set (cthi/id :set-a) (ctob/add-token (cthi/id :set-a)
(ctob/make-token border-radius-token)) (ctob/make-token border-radius-token))
(ctob/add-token-in-set (cthi/id :set-a) (ctob/add-token (cthi/id :set-a)
(ctob/make-token reference-border-radius-token)))))) (ctob/make-token reference-border-radius-token))))))
(t/deftest test-apply-token (t/deftest test-apply-token
@@ -193,9 +193,9 @@
file (-> (setup-file-with-tokens) file (-> (setup-file-with-tokens)
(update-in [:data :tokens-lib] (update-in [:data :tokens-lib]
#(-> % #(-> %
(ctob/add-token-in-set (cthi/id :set-a) (ctob/add-token (cthi/id :set-a)
(ctob/make-token color-token)) (ctob/make-token color-token))
(ctob/add-token-in-set (cthi/id :set-a) (ctob/add-token (cthi/id :set-a)
(ctob/make-token color-alpha-token))))) (ctob/make-token color-alpha-token)))))
store (ths/setup-store file) store (ths/setup-store file)
rect-1 (cths/get-shape file :rect-1) rect-1 (cths/get-shape file :rect-1)
@@ -253,7 +253,7 @@
:type :dimensions} :type :dimensions}
file (-> (setup-file-with-tokens) file (-> (setup-file-with-tokens)
(update-in [:data :tokens-lib] (update-in [:data :tokens-lib]
#(ctob/add-token-in-set % (cthi/id :set-a) #(ctob/add-token % (cthi/id :set-a)
(ctob/make-token dimensions-token)))) (ctob/make-token dimensions-token))))
store (ths/setup-store file) store (ths/setup-store file)
rect-1 (cths/get-shape file :rect-1) rect-1 (cths/get-shape file :rect-1)
@@ -286,7 +286,7 @@
(ctho/add-frame :frame-1) (ctho/add-frame :frame-1)
(ctho/add-frame :frame-2 {:layout :grid}) (ctho/add-frame :frame-2 {:layout :grid})
(update-in [:data :tokens-lib] (update-in [:data :tokens-lib]
#(ctob/add-token-in-set % (cthi/id :set-a) #(ctob/add-token % (cthi/id :set-a)
(ctob/make-token spacing-token)))) (ctob/make-token spacing-token))))
store (ths/setup-store file) store (ths/setup-store file)
frame-1 (cths/get-shape file :frame-1) frame-1 (cths/get-shape file :frame-1)
@@ -326,7 +326,7 @@
:type :sizing} :type :sizing}
file (-> (setup-file-with-tokens) file (-> (setup-file-with-tokens)
(update-in [:data :tokens-lib] (update-in [:data :tokens-lib]
#(ctob/add-token-in-set % (cthi/id :set-a) #(ctob/add-token % (cthi/id :set-a)
(ctob/make-token sizing-token)))) (ctob/make-token sizing-token))))
store (ths/setup-store file) store (ths/setup-store file)
rect-1 (cths/get-shape file :rect-1) rect-1 (cths/get-shape file :rect-1)
@@ -364,11 +364,11 @@
file (-> (setup-file-with-tokens) file (-> (setup-file-with-tokens)
(update-in [:data :tokens-lib] (update-in [:data :tokens-lib]
#(-> % #(-> %
(ctob/add-token-in-set (cthi/id :set-a) (ctob/add-token (cthi/id :set-a)
(ctob/make-token opacity-float)) (ctob/make-token opacity-float))
(ctob/add-token-in-set (cthi/id :set-a) (ctob/add-token (cthi/id :set-a)
(ctob/make-token opacity-percent)) (ctob/make-token opacity-percent))
(ctob/add-token-in-set (cthi/id :set-a) (ctob/add-token (cthi/id :set-a)
(ctob/make-token opacity-invalid))))) (ctob/make-token opacity-invalid)))))
store (ths/setup-store file) store (ths/setup-store file)
rect-1 (cths/get-shape file :rect-1) rect-1 (cths/get-shape file :rect-1)
@@ -415,7 +415,7 @@
:type :rotation} :type :rotation}
file (-> (setup-file-with-tokens) file (-> (setup-file-with-tokens)
(update-in [:data :tokens-lib] (update-in [:data :tokens-lib]
#(ctob/add-token-in-set % (cthi/id :set-a) #(ctob/add-token % (cthi/id :set-a)
(ctob/make-token rotation-token)))) (ctob/make-token rotation-token))))
store (ths/setup-store file) store (ths/setup-store file)
rect-1 (cths/get-shape file :rect-1) rect-1 (cths/get-shape file :rect-1)
@@ -446,7 +446,7 @@
:stroke-opacity 1, :stroke-opacity 1,
:stroke-width 5}]}}) :stroke-width 5}]}})
(update-in [:data :tokens-lib] (update-in [:data :tokens-lib]
#(ctob/add-token-in-set % (cthi/id :set-a) #(ctob/add-token % (cthi/id :set-a)
(ctob/make-token stroke-width-token)))) (ctob/make-token stroke-width-token))))
store (ths/setup-store file) store (ths/setup-store file)
rect-with-stroke (cths/get-shape file :rect-1) rect-with-stroke (cths/get-shape file :rect-1)
@@ -478,7 +478,7 @@
:type :font-size} :type :font-size}
file (-> (setup-file-with-tokens) file (-> (setup-file-with-tokens)
(update-in [:data :tokens-lib] (update-in [:data :tokens-lib]
#(ctob/add-token-in-set % (cthi/id :set-a) #(ctob/add-token % (cthi/id :set-a)
(ctob/make-token font-size-token)))) (ctob/make-token font-size-token))))
store (ths/setup-store file) store (ths/setup-store file)
text-1 (cths/get-shape file :text-1) text-1 (cths/get-shape file :text-1)
@@ -513,7 +513,7 @@
:type :number} :type :number}
file (-> (setup-file-with-tokens) file (-> (setup-file-with-tokens)
(update-in [:data :tokens-lib] (update-in [:data :tokens-lib]
#(ctob/add-token-in-set % (cthi/id :set-a) #(ctob/add-token % (cthi/id :set-a)
(ctob/make-token line-height-token)))) (ctob/make-token line-height-token))))
store (ths/setup-store file) store (ths/setup-store file)
text-1 (cths/get-shape file :text-1) text-1 (cths/get-shape file :text-1)
@@ -548,7 +548,7 @@
:type :letter-spacing} :type :letter-spacing}
file (-> (setup-file-with-tokens) file (-> (setup-file-with-tokens)
(update-in [:data :tokens-lib] (update-in [:data :tokens-lib]
#(ctob/add-token-in-set % (cthi/id :set-a) #(ctob/add-token % (cthi/id :set-a)
(ctob/make-token letter-spacing-token)))) (ctob/make-token letter-spacing-token))))
store (ths/setup-store file) store (ths/setup-store file)
text-1 (cths/get-shape file :text-1) text-1 (cths/get-shape file :text-1)
@@ -583,7 +583,7 @@
:type :font-family} :type :font-family}
file (-> (setup-file-with-tokens) file (-> (setup-file-with-tokens)
(update-in [:data :tokens-lib] (update-in [:data :tokens-lib]
#(ctob/add-token-in-set % (cthi/id :set-a) #(ctob/add-token % (cthi/id :set-a)
(ctob/make-token font-family-token)))) (ctob/make-token font-family-token))))
store (ths/setup-store file) store (ths/setup-store file)
text-1 (cths/get-shape file :text-1) text-1 (cths/get-shape file :text-1)
@@ -618,7 +618,7 @@
:type :text-case} :type :text-case}
file (-> (setup-file-with-tokens) file (-> (setup-file-with-tokens)
(update-in [:data :tokens-lib] (update-in [:data :tokens-lib]
#(ctob/add-token-in-set % (cthi/id :set-a) #(ctob/add-token % (cthi/id :set-a)
(ctob/make-token text-case-token)))) (ctob/make-token text-case-token))))
store (ths/setup-store file) store (ths/setup-store file)
text-1 (cths/get-shape file :text-1) text-1 (cths/get-shape file :text-1)
@@ -653,7 +653,7 @@
:type :text-decoration} :type :text-decoration}
file (-> (setup-file-with-tokens) file (-> (setup-file-with-tokens)
(update-in [:data :tokens-lib] (update-in [:data :tokens-lib]
#(ctob/add-token-in-set % (cthi/id :set-a) #(ctob/add-token % (cthi/id :set-a)
(ctob/make-token text-decoration-token)))) (ctob/make-token text-decoration-token))))
store (ths/setup-store file) store (ths/setup-store file)
text-1 (cths/get-shape file :text-1) text-1 (cths/get-shape file :text-1)
@@ -688,7 +688,7 @@
:type :font-weight} :type :font-weight}
file (-> (setup-file-with-tokens) file (-> (setup-file-with-tokens)
(update-in [:data :tokens-lib] (update-in [:data :tokens-lib]
#(ctob/add-token-in-set % (cthi/id :set-a) #(ctob/add-token % (cthi/id :set-a)
(ctob/make-token font-weight-token)))) (ctob/make-token font-weight-token))))
store (ths/setup-store file) store (ths/setup-store file)
text-1 (cths/get-shape file :text-1) text-1 (cths/get-shape file :text-1)
@@ -815,7 +815,7 @@
{:frame-params {:layout :grid}}) {:frame-params {:layout :grid}})
(ctho/add-rect :rect-regular) (ctho/add-rect :rect-regular)
(update-in [:data :tokens-lib] (update-in [:data :tokens-lib]
#(ctob/add-token-in-set % (cthi/id :set-a) #(ctob/add-token % (cthi/id :set-a)
(ctob/make-token spacing-token)))) (ctob/make-token spacing-token))))
store (ths/setup-store file) store (ths/setup-store file)
frame-layout (cths/get-shape file :frame-layout) frame-layout (cths/get-shape file :frame-layout)
@@ -859,7 +859,7 @@
file (setup-file-with-tokens) file (setup-file-with-tokens)
file (-> file file (-> file
(update-in [:data :tokens-lib] (update-in [:data :tokens-lib]
#(ctob/add-token-in-set % (cthi/id :set-a) #(ctob/add-token % (cthi/id :set-a)
(ctob/make-token color-token))) (ctob/make-token color-token)))
(cths/add-sample-library-color :color1 {:name "Test color" (cths/add-sample-library-color :color1 {:name "Test color"
:color "#abcdef"}) :color "#abcdef"})
@@ -904,9 +904,9 @@
file (-> (setup-file-with-tokens) file (-> (setup-file-with-tokens)
(update-in [:data :tokens-lib] (update-in [:data :tokens-lib]
#(-> % #(-> %
(ctob/add-token-in-set (cthi/id :set-a) (ctob/make-token font-size-token)) (ctob/add-token (cthi/id :set-a) (ctob/make-token font-size-token))
(ctob/add-token-in-set (cthi/id :set-a) (ctob/make-token font-family-token)) (ctob/add-token (cthi/id :set-a) (ctob/make-token font-family-token))
(ctob/add-token-in-set (cthi/id :set-a) (ctob/make-token typography-token))))) (ctob/add-token (cthi/id :set-a) (ctob/make-token typography-token)))))
store (ths/setup-store file) store (ths/setup-store file)
text-1 (cths/get-shape file :text-1) text-1 (cths/get-shape file :text-1)
events [(dwta/apply-token {:shape-ids [(:id text-1)] events [(dwta/apply-token {:shape-ids [(:id text-1)]
@@ -954,9 +954,9 @@
file (-> (setup-file-with-tokens) file (-> (setup-file-with-tokens)
(update-in [:data :tokens-lib] (update-in [:data :tokens-lib]
#(-> % #(-> %
(ctob/add-token-in-set (cthi/id :set-a) (ctob/make-token font-size-token)) (ctob/add-token (cthi/id :set-a) (ctob/make-token font-size-token))
(ctob/add-token-in-set (cthi/id :set-a) (ctob/make-token font-family-token)) (ctob/add-token (cthi/id :set-a) (ctob/make-token font-family-token))
(ctob/add-token-in-set (cthi/id :set-a) (ctob/make-token typography-token))))) (ctob/add-token (cthi/id :set-a) (ctob/make-token typography-token)))))
store (ths/setup-store file) store (ths/setup-store file)
text-1 (cths/get-shape file :text-1) text-1 (cths/get-shape file :text-1)
events [(dwta/apply-token {:shape-ids [(:id text-1)] events [(dwta/apply-token {:shape-ids [(:id text-1)]
@@ -995,8 +995,8 @@
file (-> (setup-file-with-tokens) file (-> (setup-file-with-tokens)
(update-in [:data :tokens-lib] (update-in [:data :tokens-lib]
#(-> % #(-> %
(ctob/add-token-in-set (cthi/id :set-a) (ctob/make-token font-size-token)) (ctob/add-token (cthi/id :set-a) (ctob/make-token font-size-token))
(ctob/add-token-in-set (cthi/id :set-a) (ctob/make-token typography-token))))) (ctob/add-token (cthi/id :set-a) (ctob/make-token typography-token)))))
store (ths/setup-store file) store (ths/setup-store file)
text-1 (cths/get-shape file :text-1) text-1 (cths/get-shape file :text-1)
events [(dwta/apply-token {:shape-ids [(:id text-1)] events [(dwta/apply-token {:shape-ids [(:id text-1)]
@@ -1029,8 +1029,8 @@
file (-> (setup-file-with-tokens) file (-> (setup-file-with-tokens)
(update-in [:data :tokens-lib] (update-in [:data :tokens-lib]
#(-> % #(-> %
(ctob/add-token-in-set (cthi/id :set-a) (ctob/make-token font-size-token)) (ctob/add-token (cthi/id :set-a) (ctob/make-token font-size-token))
(ctob/add-token-in-set (cthi/id :set-a) (ctob/make-token typography-token))))) (ctob/add-token (cthi/id :set-a) (ctob/make-token typography-token)))))
store (ths/setup-store file) store (ths/setup-store file)
text-1 (cths/get-shape file :text-1) text-1 (cths/get-shape file :text-1)
events [(dwta/apply-token {:shape-ids [(:id text-1)] events [(dwta/apply-token {:shape-ids [(:id text-1)]
@@ -1066,11 +1066,11 @@
file (-> (setup-file-with-tokens) file (-> (setup-file-with-tokens)
(update-in [:data :tokens-lib] (update-in [:data :tokens-lib]
#(-> % #(-> %
(ctob/add-token-in-set (cthi/id :set-a) (ctob/add-token (cthi/id :set-a)
(ctob/make-token font-size-token)) (ctob/make-token font-size-token))
(ctob/add-token-in-set (cthi/id :set-a) (ctob/add-token (cthi/id :set-a)
(ctob/make-token line-height-token)) (ctob/make-token line-height-token))
(ctob/add-token-in-set (cthi/id :set-a) (ctob/add-token (cthi/id :set-a)
(ctob/make-token letter-spacing-token)))) (ctob/make-token letter-spacing-token))))
(cths/add-sample-typography :typography1 {:name "Test typography"})) (cths/add-sample-typography :typography1 {:name "Test typography"}))
content {:type "root" content {:type "root"

View File

@@ -19,23 +19,23 @@
(let [tokens (-> (ctob/make-tokens-lib) (let [tokens (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (cthi/new-id! :core-set) (ctob/add-set (ctob/make-token-set :id (cthi/new-id! :core-set)
:name "core")) :name "core"))
(ctob/add-token-in-set (cthi/id :core-set) (ctob/add-token (cthi/id :core-set)
(ctob/make-token {:name "borderRadius.sm" (ctob/make-token {:name "borderRadius.sm"
:value "12px" :value "12px"
:type :border-radius})) :type :border-radius}))
(ctob/add-token-in-set (cthi/id :core-set) (ctob/add-token (cthi/id :core-set)
(ctob/make-token {:value "{borderRadius.sm} * 2" (ctob/make-token {:value "{borderRadius.sm} * 2"
:name "borderRadius.md-with-dashes" :name "borderRadius.md-with-dashes"
:type :border-radius})) :type :border-radius}))
(ctob/add-token-in-set (cthi/id :core-set) (ctob/add-token (cthi/id :core-set)
(ctob/make-token {:name "borderRadius.large" (ctob/make-token {:name "borderRadius.large"
:value "123456789012345" :value "123456789012345"
:type :border-radius})) :type :border-radius}))
(ctob/add-token-in-set (cthi/id :core-set) (ctob/add-token (cthi/id :core-set)
(ctob/make-token {:name "borderRadius.largePx" (ctob/make-token {:name "borderRadius.largePx"
:value "123456789012345px" :value "123456789012345px"
:type :border-radius})) :type :border-radius}))
(ctob/add-token-in-set (cthi/id :core-set) (ctob/add-token (cthi/id :core-set)
(ctob/make-token {:name "borderRadius.largeFn" (ctob/make-token {:name "borderRadius.largeFn"
:value "{borderRadius.sm} * 200000000" :value "{borderRadius.sm} * 200000000"
:type :border-radius})) :type :border-radius}))