mirror of
https://github.com/penpot/penpot.git
synced 2025-01-20 05:34:23 -05:00
✨ Add function to compute active state of nested sets
This commit is contained in:
parent
bb337361b8
commit
9318c10172
2 changed files with 45 additions and 1 deletions
|
@ -625,6 +625,11 @@ When `before-set-name` is nil, move set to bottom")
|
|||
(delete-token-from-set [_ set-name token-name] "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? [_ prefixed-path] "compute active state for child sets at `prefixed-path`.
|
||||
Will return a value that matches this schema:
|
||||
`:none` None of the nested sets are active
|
||||
`:all` All of the nested sets are active
|
||||
`:partial` Mixed active state of nested sets")
|
||||
(get-active-themes-set-tokens [_] "set of set names that are active in the the active themes")
|
||||
(encode-dtcg [_] "Encodes library to a dtcg compatible json string")
|
||||
(decode-dtcg-json [_ parsed-json] "Decodes parsed json containing tokens and converts to library")
|
||||
|
@ -870,6 +875,18 @@ When `before-set-name` is nil, move set to bottom")
|
|||
(mapcat :sets)
|
||||
(get-active-themes this)))
|
||||
|
||||
(sets-at-path-all-active? [this prefix-path]
|
||||
(let [active-set-names (get-active-themes-set-names this)]
|
||||
(if (seq active-set-names)
|
||||
(let [path-active-set-names (->> (get-sets-at-prefix-path this prefix-path)
|
||||
(map :name)
|
||||
(into #{}))
|
||||
difference (set/difference path-active-set-names active-set-names)]
|
||||
(if (empty? difference)
|
||||
:all
|
||||
difference))
|
||||
:none)))
|
||||
|
||||
(get-active-themes-set-tokens [this]
|
||||
(let [sets-order (get-ordered-set-names this)
|
||||
active-themes (get-active-themes this)
|
||||
|
|
|
@ -399,8 +399,35 @@
|
|||
expected-tokens (ctob/get-active-themes-set-tokens tokens-lib)
|
||||
expected-token-names (mapv key expected-tokens)]
|
||||
(t/is (= '("set-a" "set-b" "inactive-set") expected-order))
|
||||
(t/is (= ["set-a-token" "set-b-token"] expected-token-names)))))
|
||||
(t/is (= ["set-a-token" "set-b-token"] expected-token-names))))
|
||||
|
||||
(t/testing "sets-at-path-active-state"
|
||||
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
||||
|
||||
(ctob/add-set (ctob/make-token-set :name "foo/bar/baz"))
|
||||
(ctob/add-set (ctob/make-token-set :name "foo/bar/bam"))
|
||||
|
||||
(ctob/add-theme (ctob/make-token-theme :name "none"))
|
||||
(ctob/add-theme (ctob/make-token-theme :name "partial"
|
||||
:sets #{"foo/bar/baz"}))
|
||||
(ctob/add-theme (ctob/make-token-theme :name "all"
|
||||
:sets #{"foo/bar/baz"
|
||||
"foo/bar/bam"})))
|
||||
|
||||
expected-none (-> tokens-lib
|
||||
(ctob/set-active-themes #{"/none"})
|
||||
(ctob/sets-at-path-all-active? "G-foo"))
|
||||
expected-all (-> tokens-lib
|
||||
(ctob/set-active-themes #{"/all"})
|
||||
(ctob/sets-at-path-all-active? "G-foo"))
|
||||
expected-partial (-> tokens-lib
|
||||
(ctob/set-active-themes #{"/partial"})
|
||||
(ctob/sets-at-path-all-active? "G-foo"))]
|
||||
(t/is (= :none expected-none))
|
||||
(t/is (= :all expected-all))
|
||||
(t/is (= #{"foo/bar/baz"} expected-partial))
|
||||
expected-partial))
|
||||
nil)
|
||||
|
||||
(t/deftest token-theme-in-a-lib
|
||||
(t/testing "add-token-theme"
|
||||
|
|
Loading…
Add table
Reference in a new issue