🔧 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

@@ -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!