🔧 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,15 +983,15 @@
(let [lib' (ctob/ensure-tokens-lib lib)]
(cond
(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))
(ctob/add-token-in-set lib' set-id (ctob/make-token token))
(not (ctob/get-token lib' set-id token-id))
(ctob/add-token lib' set-id (ctob/make-token token))
:else
(ctob/update-token-in-set lib' set-id token-id
(fn [prev-token]
(ctob/make-token (merge prev-token token)))))))))
(ctob/update-token lib' set-id token-id
(fn [prev-token]
(ctob/make-token (merge prev-token token)))))))))
(defmethod process-change :set-token-set
[data {:keys [id token-set]}]

View File

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

View File

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

View File

@@ -213,13 +213,16 @@
;; === Token Set
(defprotocol ITokenSet
(add-token [_ token] "add a token at the end of the list")
(update-token [_ id f] "update a token in the list")
(delete-token [_ id] "delete a token from the list")
(get-token [_ id] "get a token by its id")
(get-token-by-name [_ name] "get a token by its name")
(get-tokens [_] "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: the tokens tree is planned to be moved to the TokensLib. So this protocol will be no
;; longer needed. For now, it's kept but it should only be used internally in the TokensLib.
;; The - suffix is to remind it.
(add-token- [_ token] "add a token at the end of the list")
(update-token- [_ id f] "update a token in the list")
(delete-token- [_ id] "delete a token from the list")
(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
;; from 1.2 to 1.3 when TokenSet datatype was changed to a deftype. This should
@@ -286,7 +289,7 @@
tokens))
ITokenSet
(add-token [_ token]
(add-token- [_ token]
(let [token (check-token token)]
(TokenSet. id
name
@@ -294,9 +297,9 @@
(ct/now)
(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`")
(if-let [token (get-token this token-id)]
(if-let [token (get-token- this token-id)]
(let [token' (-> (make-token (f token))
(assoc :modified-at (ct/now)))]
(TokenSet. id
@@ -310,28 +313,28 @@
(dissoc (:name token))))))
this))
(delete-token [this token-id]
(delete-token- [this 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
name
description
(ct/now)
(dissoc tokens (:name token)))))
(get-token [_ token-id]
(get-token- [_ 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
(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`")
(get tokens name))
(get-tokens [_]
(get-tokens-seq- [_]
(vals tokens))
(get-tokens-map [_]
(get-tokens-map- [_]
tokens))
(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")
(set-path-exists? [_ path] "if a set 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")
(get-token-in-set [_ 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")
(update-token-in-set [_ 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")
(add-token [_ set-id token] "add token to a set")
(get-token [_ set-id token-id] "get token in a set")
(get-token-by-name [_ set-name token-name] "get token in a set searching by set and token names")
(update-token [_ set-id token-id f] "update a token in 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")
(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`.
@@ -954,6 +957,8 @@ Will return a value that matches this schema:
`: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-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 [_]))
(declare parse-multi-set-dtcg-json)
@@ -1262,24 +1267,24 @@ Will return a value that matches this schema:
(set-group-path-exists? [_ set-path]
(some? (get-in sets (set-group-path->set-group-prefixed-path set-path))))
(add-token-in-set [this set-id token]
(update-set this set-id #(add-token % token)))
(add-token [this set-id 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
(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
(get-set set-id)
(get-token-by-name token-name)))
(get-set-by-name set-name)
(get-token-by-name- token-name)))
(update-token-in-set [this set-id token-id f]
(update-set this set-id #(update-token % token-id f)))
(update-token [this set-id token-id f]
(update-set this set-id #(update-token- % token-id f)))
(delete-token-from-set [this set-id token-id]
(update-set this set-id #(delete-token % token-id)))
(delete-token [this set-id token-id]
(update-set this set-id #(delete-token- % token-id)))
(toggle-set-in-theme [this theme-group theme-name set-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)
tokens (reduce (fn [tokens 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)
active-set-names)]
tokens))
@@ -1322,10 +1327,20 @@ Will return a value that matches this schema:
(get-all-tokens [this]
(reduce
(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-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 [_]
(and (valid-token-sets? sets)
(valid-token-themes? themes)
@@ -1776,7 +1791,7 @@ Will return a value that matches this schema:
sets (->> (get-sets tokens-lib)
(map (fn [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)])))
(into {}))]
(-> sets
@@ -1796,7 +1811,7 @@ Will return a value that matches this schema:
(filter (partial instance? TokenSet))
(map (fn [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
(mapv first name-set-tuples)

View File

@@ -149,16 +149,16 @@
(ctob/add-theme (ctob/make-token-theme :name "test-theme"
:sets #{"test-token-set"}))
(ctob/set-active-themes #{"/test-theme"})
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-sizing)
:name "token-sizing"
:type :sizing
:value 10))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-spacing)
:name "token-spacing"
:type :spacing
:value 30))))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-sizing)
:name "token-sizing"
:type :sizing
:value 10))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-spacing)
:name "token-spacing"
:type :spacing
:value 30))))
(tho/add-frame :frame-1
:layout :flex ;; TODO: those values come from main.data.workspace.shape_layout/default-layout-params
:layout-flex-dir :row ;; it should be good to use it directly, but first it should be moved to common.logic

View File

@@ -32,61 +32,61 @@
(ctob/add-theme (ctob/make-token-theme :name "test-theme"
:sets #{"test-token-set"}))
(ctob/set-active-themes #{"/test-theme"})
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-radius)
:name "token-radius"
:type :border-radius
:value 10))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-rotation)
:name "token-rotation"
:type :rotation
:value 30))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-opacity)
:name "token-opacity"
:type :opacity
:value 0.7))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-stroke-width)
:name "token-stroke-width"
:type :stroke-width
:value 2))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-color)
:name "token-color"
:type :color
:value "#00ff00"))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-dimensions)
:name "token-dimensions"
:type :dimensions
:value 100))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-font-size)
:name "token-font-size"
:type :font-size
:value 24))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-letter-spacing)
:name "token-letter-spacing"
:type :letter-spacing
:value 2))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-font-family)
:name "token-font-family"
:type :font-family
:value ["Helvetica" "Arial" "sans-serif"]))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-sizing)
:name "token-sizing"
:type :sizing
:value 10))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-spacing)
:name "token-spacing"
:type :spacing
:value 30))))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-radius)
:name "token-radius"
:type :border-radius
:value 10))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-rotation)
:name "token-rotation"
:type :rotation
:value 30))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-opacity)
:name "token-opacity"
:type :opacity
:value 0.7))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-stroke-width)
:name "token-stroke-width"
:type :stroke-width
:value 2))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-color)
:name "token-color"
:type :color
:value "#00ff00"))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-dimensions)
:name "token-dimensions"
:type :dimensions
:value 100))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-font-size)
:name "token-font-size"
:type :font-size
:value 24))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-letter-spacing)
:name "token-letter-spacing"
:type :letter-spacing
:value 2))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-font-family)
:name "token-font-family"
:type :font-family
:value ["Helvetica" "Arial" "sans-serif"]))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-sizing)
:name "token-sizing"
:type :sizing
:value 10))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :token-spacing)
:name "token-spacing"
:type :spacing
:value 30))))
(tho/add-frame :frame1
:layout :flex ;; TODO: those values come from main.data.workspace.shape_layout/default-layout-params
:layout-flex-dir :row ;; it should be good to use it directly, but first it should be moved to common.logic

View File

@@ -171,10 +171,10 @@
file (setup-file #(-> %
(ctob/add-set (ctob/make-token-set :id set-id
:name set-name))
(ctob/add-token-in-set set-id (ctob/make-token {:name "to.delete.color.red"
:id token-id
:value "red"
:type :color}))))
(ctob/add-token set-id (ctob/make-token {:name "to.delete.color.red"
:id token-id
:value "red"
:type :color}))))
changes (-> (pcb/empty-changes)
(pcb/with-library-data (:data file))
(pcb/set-token set-id token-id nil))
@@ -183,9 +183,9 @@
redo-lib (tht/get-tokens-lib redo)
undo (thf/apply-undo-changes redo changes)
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
(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"
(let [set-name "foo"
@@ -203,9 +203,9 @@
redo-lib (tht/get-tokens-lib redo)
undo (thf/apply-undo-changes redo changes)
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
(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"
(let [set-name "foo"
@@ -219,7 +219,7 @@
file (setup-file #(-> %
(ctob/add-set (ctob/make-token-set :id set-id
:name set-name))
(ctob/add-token-in-set set-id prev-token)))
(ctob/add-token set-id prev-token)))
changes (-> (pcb/empty-changes)
(pcb/with-library-data (:data file))
(pcb/set-token set-id (:id prev-token) token))
@@ -228,9 +228,9 @@
redo-lib (tht/get-tokens-lib redo)
undo (thf/apply-undo-changes redo changes)
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
(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/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-description 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-description token-set2) "test description"))
(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
(let [params {:name 777 :description 999}]
@@ -189,8 +189,8 @@
"baz.boo" (ctob/make-token :name "baz.boo"
:type :boolean
:value true)})))
expected (-> (ctob/get-set tokens-lib (thi/id :test-token-set))
(ctob/get-tokens-map)
expected (-> tokens-lib
(ctob/get-tokens-map (thi/id :test-token-set))
(ctob/tokens-tree))]
(t/is (= (get-in expected ["foo" "bar" "baz" :name]) "foo.bar.baz"))
(t/is (= (get-in expected ["foo" "bar" "bam" :name]) "foo.bar.bam"))
@@ -316,11 +316,11 @@
:type :boolean
:value true)})))
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 (= (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/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"}))
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 (= (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/deftest duplicate-empty-token-set
@@ -349,11 +349,11 @@
:name "test-token-set")))
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 (= (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/deftest duplicate-not-existing-token-set
@@ -372,15 +372,17 @@
:type :boolean
:value true)
tokens-lib' (-> tokens-lib
(ctob/add-token-in-set (thi/id :test-token-set) token)
(ctob/add-token-in-set (uuid/next) token))
(ctob/add-token (thi/id :test-token-set) 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' (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 (= (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 (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)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
:name "test-token-set"))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-1)
:name "test-token-1"
:type :boolean
:value true))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-2)
:name "test-token-2"
:type :boolean
:value true)))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-1)
:name "test-token-1"
:type :boolean
:value true))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-2)
:name "test-token-2"
:type :boolean
:value true)))
tokens-lib' (-> tokens-lib
(ctob/update-token-in-set (thi/id :test-token-set) (thi/id :test-token-1)
(fn [token]
(assoc token
:description "some description"
:value false)))
(ctob/update-token-in-set (uuid/next) (thi/id :test-token-1)
(fn [token]
(assoc token
:name "no-effect")))
(ctob/update-token-in-set (thi/id :test-token-set) (uuid/next)
(fn [token]
(assoc token
:name "no-effect"))))
(ctob/update-token (thi/id :test-token-set) (thi/id :test-token-1)
(fn [token]
(assoc token
:description "some description"
:value false)))
(ctob/update-token (uuid/next) (thi/id :test-token-1)
(fn [token]
(assoc token
:name "no-effect")))
(ctob/update-token (thi/id :test-token-set) (uuid/next)
(fn [token]
(assoc token
: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 (ctob/get-token token-set (thi/id :test-token-1))
token' (ctob/get-token token-set' (thi/id :test-token-1))]
token (ctob/get-token tokens-lib
(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 (= (count (ctob/get-tokens-map token-set')) 2))
(t/is (= (d/index-of (keys (ctob/get-tokens-map token-set')) "test-token-1") 0))
(t/is (= (count tokens') 2))
(t/is (= (d/index-of (keys tokens') "test-token-1") 0))
(t/is (= (:name token') "test-token-1"))
(t/is (= (:description token') "some description"))
(t/is (= (:value token') false))
@@ -432,31 +440,37 @@
(let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
:name "test-token-set"))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-1)
:name "test-token-1"
:type :boolean
:value true))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-2)
:name "test-token-2"
:type :boolean
:value true)))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-1)
:name "test-token-1"
:type :boolean
:value true))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-2)
:name "test-token-2"
:type :boolean
:value true)))
tokens-lib' (-> tokens-lib
(ctob/update-token-in-set (thi/id :test-token-set) (thi/id :test-token-1)
(fn [token]
(assoc token
:name "updated-name"))))
(ctob/update-token (thi/id :test-token-set) (thi/id :test-token-1)
(fn [token]
(assoc token
: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 (ctob/get-token token-set (thi/id :test-token-1))
token' (ctob/get-token token-set' (thi/id :test-token-1))]
token (ctob/get-token tokens-lib
(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 (= (count (ctob/get-tokens-map token-set')) 2))
(t/is (= (d/index-of (keys (ctob/get-tokens-map token-set')) "updated-name") 0))
(t/is (= (count tokens') 2))
(t/is (= (d/index-of (keys tokens') "updated-name") 0))
(t/is (= (:name token') "updated-name"))
(t/is (= (:description token') ""))
(t/is (= (:value token') true))
@@ -467,22 +481,26 @@
(let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
:name "test-token-set"))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token)
:name "test-token"
:type :boolean
:value true)))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token)
:name "test-token"
:type :boolean
:value true)))
tokens-lib' (-> tokens-lib
(ctob/delete-token-from-set (thi/id :test-token-set) (thi/id :test-token))
(ctob/delete-token-from-set (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) (thi/id :test-token))
(ctob/delete-token (uuid/next) (thi/id :test-token))
(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' (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 (= (count (ctob/get-tokens-map token-set')) 0))
(t/is (= (count tokens') 0))
(t/is (nil? token'))
(t/is (ct/is-after? (ctob/get-modified-at token-set') (ctob/get-modified-at token-set)))))
@@ -821,10 +839,10 @@
(t/deftest transit-serialization
(let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :name "test-token-set"))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "test-token"
:type :boolean
:value true))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "test-token"
:type :boolean
:value true))
(ctob/add-theme (ctob/make-token-theme :name "test-token-theme"))
(ctob/toggle-set-in-theme "" "test-token-theme" "test-token-set"))
encoded-str (tr/encode-str tokens-lib)
@@ -839,10 +857,10 @@
(let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
:name "test-token-set"))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "test-token"
:type :boolean
:value true))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "test-token"
:type :boolean
:value true))
(ctob/add-theme (ctob/make-token-theme :name "test-token-theme"))
(ctob/toggle-set-in-theme "" "test-token-theme" "test-token-set"))
encoded-blob (fres/encode tokens-lib)
@@ -872,29 +890,28 @@
(let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
:name "test-token-set"))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "token1"
:type :boolean
:value true))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "group1.token2"
:type :boolean
:value true))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "group1.token3"
:type :boolean
:value true))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "group1.subgroup11.token4"
:type :boolean
:value true))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "group2.token5"
:type :boolean
:value true)))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "token1"
:type :boolean
:value true))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "group1.token2"
:type :boolean
:value true))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "group1.token3"
:type :boolean
:value true))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "group1.subgroup11.token4"
:type :boolean
:value true))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "group2.token5"
:type :boolean
:value true)))
set (ctob/get-set tokens-lib (thi/id :test-token-set))
tokens-list (ctob/get-tokens set)]
tokens-list (ctob/get-tokens-seq tokens-lib (thi/id :test-token-set))]
(t/is (= (count tokens-list) 5))
(t/is (= (:name (nth tokens-list 0)) "token1"))
@@ -907,33 +924,37 @@
(let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
:name "test-token-set"))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-1)
:name "test-token-1"
:type :boolean
:value true))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-2)
:name "group1.test-token-2"
:type :boolean
:value true))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-3)
:name "group1.test-token-3"
:type :boolean
:value true)))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-1)
:name "test-token-1"
:type :boolean
:value true))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-2)
:name "group1.test-token-2"
:type :boolean
:value true))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-3)
:name "group1.test-token-3"
:type :boolean
:value true)))
tokens-lib' (-> tokens-lib
(ctob/update-token-in-set (thi/id :test-token-set) (thi/id :test-token-2)
(fn [token]
(assoc token
:description "some description"
:value false))))
(ctob/update-token (thi/id :test-token-set) (thi/id :test-token-2)
(fn [token]
(assoc token
:description "some description"
:value false))))
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 token-set' (thi/id :test-token-2))]
token (ctob/get-token tokens-lib
(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 (= (:name token') "group1.test-token-2"))
@@ -946,32 +967,36 @@
(let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
:name "test-token-set"))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-1)
:name "test-token-1"
:type :boolean
:value true))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-2)
:name "group1.test-token-2"
:type :boolean
:value true))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-3)
:name "group1.test-token-3"
:type :boolean
:value true)))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-1)
:name "test-token-1"
:type :boolean
:value true))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-2)
:name "group1.test-token-2"
:type :boolean
:value true))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-3)
:name "group1.test-token-3"
:type :boolean
:value true)))
tokens-lib' (-> tokens-lib
(ctob/update-token-in-set (thi/id :test-token-set) (thi/id :test-token-2)
(fn [token]
(assoc token
:name "group1.updated-name"))))
(ctob/update-token (thi/id :test-token-set) (thi/id :test-token-2)
(fn [token]
(assoc token
: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 (ctob/get-token token-set (thi/id :test-token-2))
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))
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 (= (:name token') "group1.updated-name"))
@@ -984,35 +1009,41 @@
(let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
:name "test-token-set"))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-1)
:name "test-token-1"
:type :boolean
:value true))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-2)
:name "group1.test-token-2"
:type :boolean
:value true))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-3)
:name "group1.test-token-3"
:type :boolean
:value true)))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-1)
:name "test-token-1"
:type :boolean
:value true))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-2)
:name "group1.test-token-2"
:type :boolean
:value true))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-3)
:name "group1.test-token-3"
:type :boolean
:value true)))
tokens-lib' (-> tokens-lib
(ctob/update-token-in-set (thi/id :test-token-set) (thi/id :test-token-2)
(fn [token]
(assoc token
:name "group2.updated-name"))))
(ctob/update-token (thi/id :test-token-set) (thi/id :test-token-2)
(fn [token]
(assoc token
: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 (ctob/get-token token-set (thi/id :test-token-2))
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))
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 (= (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 (= (:description token') ""))
(t/is (= (:value token') true))
@@ -1023,25 +1054,29 @@
(let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
:name "test-token-set"))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-1)
:name "test-token-1"
:type :boolean
:value true))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-2)
:name "group1.test-token-2"
:type :boolean
:value true)))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-1)
:name "test-token-1"
:type :boolean
:value true))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-2)
:name "group1.test-token-2"
:type :boolean
:value true)))
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' (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 (= (count (ctob/get-tokens-map token-set')) 1))
(t/is (= (count tokens') 1))
(t/is (nil? token'))
(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
(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")
token-set (ctob/get-set-by-name lib "single_set")]
lib (ctob/parse-decoded-json json "single_set")]
(t/is (= '("single_set") (ctob/get-ordered-set-names lib)))
(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
(t/deftest parse-single-set-dtcg-json
(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")
token-set (ctob/get-set-by-name lib "single_set")]
lib (ctob/parse-decoded-json json "single_set")]
(t/is (= '("single_set") (ctob/get-ordered-set-names lib)))
(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
(t/deftest parse-multi-set-legacy-json
(let [json (-> (slurp "test/common_tests/types/data/tokens-multi-set-legacy-example.json")
(json/decode {:key-fn identity}))
lib (ctob/parse-decoded-json json "")
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")]
token-theme (ctob/get-theme lib "group-1" "theme-1")]
(t/is (= '("core" "light" "dark" "theme") (ctob/get-ordered-set-names lib)))
(t/testing "set exists in theme"
(t/is (= (:group token-theme) "group-1"))
(t/is (= (:name token-theme) "theme-1"))
(t/is (= (:sets token-theme) #{"light"})))
(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"
:type :color
:value "#e53e3e"
: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"
:type :spacing
:value "{dimension.sm} {dimension.xl}"
: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"
:type :color
:value "{accent.default}"
:description ""})))
(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
(t/deftest parse-multi-set-dtcg-json
(let [json (-> (slurp "test/common_tests/types/data/tokens-multi-set-example.json")
(json/decode {:key-fn identity}))
lib (ctob/parse-decoded-json json "")
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")]
token-theme (ctob/get-theme lib "group-1" "theme-1")]
(t/is (= '("core" "light" "dark" "theme") (ctob/get-ordered-set-names lib)))
(t/testing "set exists in theme"
(t/is (= (:group token-theme) "group-1"))
(t/is (= (:name token-theme) "theme-1"))
(t/is (= (:sets token-theme) #{"light"})))
(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"
:type :color
:value "#e53e3e"
: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"
:type :spacing
:value "{dimension.sm} {dimension.xl}"
: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"
:type :color
:value "{accent.default}"
:description ""})))
(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
(t/deftest parse-multi-set-dtcg-json-default-team
@@ -1355,15 +1384,14 @@
(json/decode {:key-fn identity}))
lib (ctob/parse-decoded-json json "")
themes (ctob/get-themes lib)
first-theme (first themes)
dark-set (ctob/get-set-by-name lib "dark")]
first-theme (first themes)]
(t/is (= '("dark") (ctob/get-ordered-set-names lib)))
(t/is (= 1 (count themes)))
(t/testing "existing theme is default theme"
(t/is (= (:group first-theme) ""))
(t/is (= (:name first-theme) ctob/hidden-theme-name)))
(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"
:value "8"
:type :border-radius
@@ -1599,11 +1627,10 @@
(t/deftest parse-typography-tokens
(let [json (-> (slurp "test/common_tests/types/data/tokens-typography-example.json")
(json/decode {:key-fn identity}))
lib (ctob/parse-decoded-json json "typography-test")
set (ctob/get-set-by-name lib "typography-test")]
lib (ctob/parse-decoded-json json "typography-test")]
(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 (= (:type token) :typography))
(t/is (= (:value token) {:font-weight "100"
@@ -1612,28 +1639,28 @@
(t/is (= (:description token) ""))))
(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 (= (:type token) :typography))
(t/is (= (:value token) "{typo}"))
(t/is (= (:description 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 (= (:type token) :typography))
(t/is (= (:value token) "{font-weight}"))
(t/is (= (:description token) ""))))
(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 (= (:type token) :typography))
(t/is (= (:value token) {}))
(t/is (= (:description token) ""))))
(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 (= (:type token) :typography))
(t/is (= (:value token) {:font-weight "bold"
@@ -1645,8 +1672,8 @@
(t/is (= (:description token) "A complex typography token"))))
(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")
font-size-token (ctob/get-token-in-set-by-name lib (ctob/get-id set) "test.font-size")]
(let [font-weight-token (ctob/get-token-by-name lib "typography-test" "test.font-weight")
font-size-token (ctob/get-token-by-name lib "typography-test" "test.font-size")]
(t/is (some? font-weight-token))
(t/is (= (:type font-weight-token) :font-weight))
(t/is (= (:value font-weight-token) "200"))
@@ -1656,7 +1683,7 @@
(t/is (= (:value font-size-token) "18px"))))
(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 (= (:type token) :typography))
(t/is (= (:value token) {:font-weight "600"
@@ -1732,20 +1759,18 @@
;; Export to JSON format
exported (ctob/export-dtcg-json original-lib)
;; Import back
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")]
imported-lib (ctob/parse-decoded-json exported "")]
(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")
imported-token (ctob/get-token-in-set-by-name imported-lib (ctob/get-id imported-set) "typo.test")]
(let [original-token (ctob/get-token-by-name original-lib "test-set" "typo.test")
imported-token (ctob/get-token-by-name imported-lib "test-set" "typo.test")]
(t/is (some? imported-token))
(t/is (= (:type imported-token) (:type original-token)))
(t/is (= (:value imported-token) (:value 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")
imported-ref (ctob/get-token-in-set-by-name imported-lib (ctob/get-id imported-set) "typo.ref")]
(let [original-ref (ctob/get-token-by-name original-lib "test-set" "typo.ref")
imported-ref (ctob/get-token-by-name imported-lib "test-set" "typo.ref")]
(t/is (some? imported-ref))
(t/is (= (:type imported-ref) (:type original-ref)))
(t/is (= (:value imported-ref) (:value original-ref))))))))
@@ -1754,32 +1779,31 @@
(t/deftest parse-font-family-tokens
(let [json (-> (slurp "test/common_tests/types/data/tokens-font-family-example.json")
(json/decode {:key-fn identity}))
lib (ctob/parse-decoded-json json "font-family-test")
set (ctob/get-set-by-name lib "font-family-test")]
lib (ctob/parse-decoded-json json "font-family-test")]
(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 (= (:type token) :font-family))
(t/is (= (:value token) ["Arial" "Helvetica" "sans-serif"]))
(t/is (= (:description token) "A font family defined as a string"))))
(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 (= (:type token) :font-family))
(t/is (= (:value token) ["Inter" "system-ui" "sans-serif"]))
(t/is (= (:description token) "A font family defined as an 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 (= (:type token) :font-family))
(t/is (= (:value token) ["Georgia"]))
(t/is (= (:description token) ""))))
(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 (= (:type token) :font-family))
(t/is (= (:value token) ["Source Sans Pro" "Arial" "sans-serif"])))))))
@@ -1834,20 +1858,18 @@
;; Export to JSON format
exported (ctob/export-dtcg-json original-lib)
;; Import back
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")]
imported-lib (ctob/parse-decoded-json exported "")]
(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")
imported-token (ctob/get-token-in-set-by-name imported-lib (ctob/get-id imported-set) "fonts.test-array")]
(let [original-token (ctob/get-token-by-name original-lib "test-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 (= (:type imported-token) (:type original-token)))
(t/is (= (:value imported-token) (:value 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")
imported-single (ctob/get-token-in-set-by-name imported-lib (ctob/get-id imported-set) "fonts.test-single")]
(let [original-single (ctob/get-token-by-name original-lib "test-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 (= (:type imported-single) (:type original-single)))
(t/is (= (:value imported-single) (:value original-single))))))))

View File

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

View File

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

View File

@@ -693,7 +693,7 @@
[sets]
(map (fn [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))
(defn- filter-active-sets

View File

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

View File

@@ -39,21 +39,21 @@
(ctob/add-theme (ctob/make-token-theme :name "test-theme"
:sets #{"test-token-set"}))
(ctob/set-active-themes #{"/test-theme"})
(ctob/add-token-in-set (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :test-token-1)
:name "test-token-1"
:type :border-radius
:value 25))
(ctob/add-token-in-set (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :test-token-2)
:name "test-token-2"
:type :border-radius
:value 50))
(ctob/add-token-in-set (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :test-token-3)
:name "test-token-3"
:type :border-radius
:value 75))))
(ctob/add-token (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :test-token-1)
:name "test-token-1"
:type :border-radius
:value 25))
(ctob/add-token (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :test-token-2)
:name "test-token-2"
:type :border-radius
:value 50))
(ctob/add-token (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :test-token-3)
:name "test-token-3"
:type :border-radius
:value 75))))
(ctho/add-frame :frame1)
(ctht/apply-token-to-shape :frame1 "test-token-1" [:r1 :r2 :r3 :r4] [:r1 :r2 :r3 :r4] 25)))
@@ -327,36 +327,36 @@
(ctob/add-theme (ctob/make-token-theme :name "test-theme"
:sets #{"test-token-set"}))
(ctob/set-active-themes #{"/test-theme"})
(ctob/add-token-in-set (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :token-radius)
:name "token-radius"
:type :border-radius
:value 10))
(ctob/add-token-in-set (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :token-rotation)
:name "token-rotation"
:type :rotation
:value 30))
(ctob/add-token-in-set (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :token-opacity)
:name "token-opacity"
:type :opacity
:value 0.7))
(ctob/add-token-in-set (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :token-stroke-width)
:name "token-stroke-width"
:type :stroke-width
:value 2))
(ctob/add-token-in-set (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :token-color)
:name "token-color"
:type :color
:value "#00ff00"))
(ctob/add-token-in-set (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :token-dimensions)
:name "token-dimensions"
:type :dimensions
:value 100))))
(ctob/add-token (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :token-radius)
:name "token-radius"
:type :border-radius
:value 10))
(ctob/add-token (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :token-rotation)
:name "token-rotation"
:type :rotation
:value 30))
(ctob/add-token (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :token-opacity)
:name "token-opacity"
:type :opacity
:value 0.7))
(ctob/add-token (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :token-stroke-width)
:name "token-stroke-width"
:type :stroke-width
:value 2))
(ctob/add-token (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :token-color)
:name "token-color"
:type :color
:value "#00ff00"))
(ctob/add-token (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :token-dimensions)
:name "token-dimensions"
:type :dimensions
:value 100))))
(ctho/add-frame :frame1)
(ctht/apply-token-to-shape :frame1 "token-radius" [:r1 :r2 :r3 :r4] [:r1 :r2 :r3 :r4] 10)
(ctht/apply-token-to-shape :frame1 "token-rotation" [:rotation] [:rotation] 30)

View File

@@ -17,38 +17,38 @@
(ctob/add-theme (ctob/make-token-theme :name "test-theme"
:sets #{"test-token-set"}))
(ctob/set-active-themes #{"/test-theme"})
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "token-radius"
:type :border-radius
:value 10))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "token-color"
:type :color
:value "red"))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "token-spacing"
:type :spacing
:value 10))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "token-sizing"
:type :sizing
:value 10))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "token-rotation"
:type :rotation
:value 10))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "token-opacity"
:type :opacity
:value 10))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "token-dimensions"
:type :dimensions
:value 10))
(ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "token-number"
:type :number
:value 10))))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "token-radius"
:type :border-radius
:value 10))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "token-color"
:type :color
:value "red"))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "token-spacing"
:type :spacing
:value 10))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "token-sizing"
:type :sizing
:value 10))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "token-rotation"
:type :rotation
:value 10))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "token-opacity"
:type :opacity
:value 10))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "token-dimensions"
:type :dimensions
:value 10))
(ctob/add-token (thi/id :test-token-set)
(ctob/make-token :name "token-number"
:type :number
:value 10))))
;; app.main.data.workspace.tokens.application/generic-attributes
(tho/add-group :group1)
;; app.main.data.workspace.tokens.application/rect-attributes

View File

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

View File

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

View File

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