🔧 Renames, privacy adjustments and other small enhancements

This commit is contained in:
Andrés Moya 2025-05-29 14:43:25 +02:00 committed by Andrés Moya
parent 1b3a200010
commit 8a0aa20789
18 changed files with 131 additions and 126 deletions

View file

@ -20,15 +20,15 @@
(let [prev-active-token-themes (ctob/get-active-theme-paths tokens-lib) (let [prev-active-token-themes (ctob/get-active-theme-paths tokens-lib)
active-token-set-names (ctob/get-active-themes-set-names tokens-lib) active-token-set-names (ctob/get-active-themes-set-names tokens-lib)
prev-hidden-token-theme (ctob/get-hidden-theme tokens-lib) prev-hidden-theme (ctob/get-hidden-theme tokens-lib)
hidden-token-theme (-> (some-> prev-hidden-token-theme (ctob/set-sets active-token-set-names)) hidden-theme (-> (some-> prev-hidden-theme (ctob/set-sets active-token-set-names))
(update-theme-fn))] (update-theme-fn))]
(-> changes (-> changes
(pcb/update-active-token-themes #{ctob/hidden-token-theme-path} prev-active-token-themes) (pcb/update-active-token-themes #{(ctob/theme-path hidden-theme)} prev-active-token-themes)
(pcb/set-token-theme (:group prev-hidden-token-theme) (pcb/set-token-theme (:group prev-hidden-theme)
(:name prev-hidden-token-theme) (:name prev-hidden-theme)
hidden-token-theme)))) hidden-theme))))
(defn generate-toggle-token-set (defn generate-toggle-token-set
"Toggle a token set at `set-name` in `tokens-lib` without modifying a "Toggle a token set at `set-name` in `tokens-lib` without modifying a

View file

@ -25,14 +25,14 @@
;; TODO: add again the removed functions and refactor the rest of the module to use them ;; TODO: add again the removed functions and refactor the rest of the module to use them
(def schema:groupable-item (def ^:private schema:groupable-item
[:map {:title "Groupable item"} [:map {:title "Groupable item"}
[:name :string]]) [:name :string]])
(def valid-groupable-item? (def ^:private valid-groupable-item?
(sm/validator schema:groupable-item)) (sm/validator schema:groupable-item))
(def xf-map-trim (def ^:private xf-map-trim
(comp (comp
(map str/trim) (map str/trim)
(remove str/empty?))) (remove str/empty?)))
@ -44,18 +44,22 @@
(into [] xf-map-trim) (into [] xf-map-trim)
(not-empty))) (not-empty)))
(defn split-path-name [s separator]
(let [[path name] (str/split s (re-pattern (str "\\" separator)) 2)]
[(or path "") name]))
(defn join-path (defn join-path
"Regenerate a path as a string, from a vector." "Regenerate a path as a string, from a vector."
[path separator] [path separator]
(str/join separator path)) (str/join separator path))
(defn split-path-name
"Decompose a string in the form 'one.two.three' into a vector with two elements: first the
path and second the name, removing spaces (e.g. ['one.two' 'three'])."
[path separator]
(let [pathv (split-path path separator)]
[(join-path (butlast pathv) separator)
(last pathv)]))
(defn get-path (defn get-path
"Get the path of object by specified separator (E.g. with '.' "Get the path of object by specified separator (E.g. with '.' separator, the
separator, the 'group.subgroup.name' -> ['group' 'subgroup'])" 'group.subgroup.name' -> ['group' 'subgroup'])"
[item separator] [item separator]
(assert (valid-groupable-item? item) "expected groupable item") (assert (valid-groupable-item? item) "expected groupable item")
(->> (split-path (:name item) separator) (->> (split-path (:name item) separator)
@ -101,7 +105,7 @@
(check-token-attrs) (check-token-attrs)
(map->Token))) (map->Token)))
(def token-separator ".") (def ^:private token-separator ".")
(defn get-token-path (defn get-token-path
[token] [token]
@ -219,7 +223,7 @@
(sm/required-keys schema:token-set-attrs) (sm/required-keys schema:token-set-attrs)
[:fn token-set?]]) [:fn token-set?]])
(sm/register! ::token-set schema:token-set) ;; Need to register for the recursive schema of token-sets (sm/register! ::token-set schema:token-set) ;; need to register for the recursive schema of token-sets
(def ^:private check-token-set-attrs (def ^:private check-token-set-attrs
(sm/check-fn schema:token-set-attrs :hint "expected valid params for token-set")) (sm/check-fn schema:token-set-attrs :hint "expected valid params for token-set"))
@ -237,11 +241,11 @@
(check-token-set-attrs) (check-token-set-attrs)
(map->TokenSet))) (map->TokenSet)))
(def set-prefix "S-") (def ^:private set-prefix "S-")
(def set-group-prefix "G-") (def ^:private set-group-prefix "G-")
(def set-separator "/") (def ^:private set-separator "/")
(defn join-set-path [path] (defn join-set-path [path]
(join-path path set-separator)) (join-path path set-separator))
@ -285,11 +289,11 @@
(defn add-set-group-prefix [group-path] (defn add-set-group-prefix [group-path]
(str set-group-prefix group-path)) (str set-group-prefix group-path))
(defn get-token-set-path (defn get-set-path
[token-set] [token-set]
(get-path token-set set-separator)) (get-path token-set set-separator))
(defn split-token-set-name (defn split-set-name
[name] [name]
(split-path name set-separator)) (split-path name set-separator))
@ -299,23 +303,23 @@
If `relative-to` is provided, the normalized name will preserve the If `relative-to` is provided, the normalized name will preserve the
same group prefix as reference name" same group prefix as reference name"
([name] ([name]
(->> (split-token-set-name name) (->> (split-set-name name)
(str/join set-separator))) (str/join set-separator)))
([name relative-to] ([name relative-to]
(->> (concat (butlast (split-token-set-name relative-to)) (->> (concat (butlast (split-set-name relative-to))
(split-token-set-name name)) (split-set-name name))
(str/join set-separator)))) (str/join set-separator))))
(defn set-name->prefixed-full-path [name-str] (defn set-name->prefixed-full-path [name-str]
(-> (split-token-set-name name-str) (-> (split-set-name name-str)
(set-full-path->set-prefixed-full-path))) (set-full-path->set-prefixed-full-path)))
(defn get-token-set-prefixed-path [token-set] (defn get-set-prefixed-path [token-set]
(let [path (get-path token-set set-separator)] (let [path (get-path token-set set-separator)]
(set-full-path->set-prefixed-full-path path))) (set-full-path->set-prefixed-full-path path)))
(defn prefixed-set-path-string->set-name-string [path-str] (defn prefixed-set-path-string->set-name-string [path-str]
(->> (split-token-set-name path-str) (->> (split-set-name path-str)
(map (fn [path-part] (map (fn [path-part]
(or (-> (split-set-str-path-prefix path-part) (or (-> (split-set-str-path-prefix path-part)
(second)) (second))
@ -351,7 +355,8 @@
(-> acc (-> acc
(assoc-in (concat [:tokens-tree] path) token) (assoc-in (concat [:tokens-tree] path) token)
(assoc-in [:ids temp-id] token)))) (assoc-in [:ids temp-id] token))))
{:tokens-tree {} :ids {}} tokens)) {:tokens-tree {} :ids {}}
tokens))
;; === TokenSets (collection) ;; === TokenSets (collection)
@ -403,27 +408,27 @@
(def ^:private check-token-sets (def ^:private check-token-sets
(sm/check-fn schema:token-sets :hint "expected valid token sets")) (sm/check-fn schema:token-sets :hint "expected valid token sets"))
(def valid-token-sets? (def ^:private valid-token-sets?
(sm/validator schema:token-sets)) (sm/validator schema:token-sets))
;; === TokenTheme ;; === TokenTheme
(def theme-separator "/") (def ^:private theme-separator "/")
(defn token-theme-path [group name] (defn join-theme-path [group name]
(join-path [group name] theme-separator)) (join-path [group name] theme-separator))
(defn split-token-theme-path [path] (defn split-theme-path [path]
(split-path-name path theme-separator)) (split-path-name path theme-separator))
(def hidden-token-theme-group (def hidden-theme-group
"") "")
(def hidden-token-theme-name (def hidden-theme-name
"__PENPOT__HIDDEN__TOKEN__THEME__") "__PENPOT__HIDDEN__TOKEN__THEME__")
(def hidden-token-theme-path (def hidden-theme-path
(token-theme-path hidden-token-theme-group hidden-token-theme-name)) (join-theme-path hidden-theme-group hidden-theme-name))
(defprotocol ITokenTheme (defprotocol ITokenTheme
(set-sets [_ set-names] "set the active token sets") (set-sets [_ set-names] "set the active token sets")
@ -433,9 +438,9 @@
(disable-sets [_ set-names] "disable sets in theme") (disable-sets [_ set-names] "disable sets in theme")
(toggle-set [_ set-name] "toggle a set enabled / disabled in the theme") (toggle-set [_ set-name] "toggle a set enabled / disabled in the theme")
(update-set-name [_ prev-set-name set-name] "update set-name from `prev-set-name` to `set-name` when it exists") (update-set-name [_ prev-set-name set-name] "update set-name from `prev-set-name` to `set-name` when it exists")
(theme-path [_] "get `token-theme-path` from theme") (theme-path [_] "get `theme-path` from theme")
(theme-matches-group-name [_ group name] "if a theme matches the given group & name") (theme-matches-group-name [_ group name] "if a theme matches the given group & name")
(hidden-temporary-theme? [_] "if a theme is the (from the user ui) hidden temporary theme")) (hidden-theme? [_] "if a theme is the (from the user ui) hidden temporary theme"))
(defrecord TokenTheme [id name group description is-source external-id modified-at sets] (defrecord TokenTheme [id name group description is-source external-id modified-at sets]
ITokenTheme ITokenTheme
@ -479,14 +484,14 @@
this)) this))
(theme-path [_] (theme-path [_]
(token-theme-path group name)) (join-theme-path group name))
(theme-matches-group-name [this group name] (theme-matches-group-name [this group name]
(and (= (:group this) group) (and (= (:group this) group)
(= (:name this) name))) (= (:name this) name)))
(hidden-temporary-theme? [this] (hidden-theme? [this]
(theme-matches-group-name this hidden-token-theme-group hidden-token-theme-name))) (theme-matches-group-name this hidden-theme-group hidden-theme-name)))
(defn token-theme? (defn token-theme?
[o] [o]
@ -508,13 +513,13 @@
(sm/required-keys schema:token-theme-attrs) (sm/required-keys schema:token-theme-attrs)
[:fn token-theme?]]) [:fn token-theme?]])
(def check-token-theme
(sm/check-fn schema:token-theme :hint "expected a valid token-theme"))
(def ^:private check-token-theme-attrs (def ^:private check-token-theme-attrs
(sm/check-fn schema:token-theme-attrs :hint "expected valid params for token-theme")) (sm/check-fn schema:token-theme-attrs :hint "expected valid params for token-theme"))
(def top-level-theme-group-name (def check-token-theme
(sm/check-fn schema:token-theme :hint "expected a valid token-theme"))
(def ^:private top-level-theme-group-name
"Top level theme groups have an empty string as the theme group." "Top level theme groups have an empty string as the theme group."
"") "")
@ -535,13 +540,13 @@
(check-token-theme-attrs) (check-token-theme-attrs)
(map->TokenTheme)))) (map->TokenTheme))))
(defn make-hidden-token-theme (defn make-hidden-theme
[& {:as attrs}] [& {:as attrs}]
(-> attrs (-> attrs
(assoc :id uuid/zero) (assoc :id uuid/zero)
(assoc :external-id "") (assoc :external-id "")
(assoc :group hidden-token-theme-group) (assoc :group hidden-theme-group)
(assoc :name hidden-token-theme-name) (assoc :name hidden-theme-name)
(make-token-theme))) (make-token-theme)))
;; === TokenThemes (collection) ;; === TokenThemes (collection)
@ -573,7 +578,7 @@
(def ^:private check-token-themes (def ^:private check-token-themes
(sm/check-fn schema:token-themes :hint "expected valid token themes")) (sm/check-fn schema:token-themes :hint "expected valid token themes"))
(def valid-token-themes? (def ^:private valid-token-themes?
(sm/validator schema:token-themes)) (sm/validator schema:token-themes))
(def ^:private schema:active-themes (def ^:private schema:active-themes
@ -582,7 +587,7 @@
(def ^:private check-active-themes (def ^:private check-active-themes
(sm/check-fn schema:active-themes :hint "expected valid active themes")) (sm/check-fn schema:active-themes :hint "expected valid active themes"))
(def valid-active-token-themes? (def ^:private valid-active-token-themes?
(sm/validator schema:active-themes)) (sm/validator schema:active-themes))
(defn walk-sets-tree-seq (defn walk-sets-tree-seq
@ -613,7 +618,7 @@
;; Set ;; Set
(and v (instance? TokenSet v)) (and v (instance? TokenSet v))
[{:group? false [{:group? false
:path (split-token-set-name (:name v)) :path (split-set-name (:name v))
:parent-path parent :parent-path parent
:depth depth :depth depth
:set v}] :set v}]
@ -661,7 +666,7 @@
(and v (instance? TokenSet v)) (and v (instance? TokenSet v))
(let [name (:name v)] (let [name (:name v)]
[{:is-group false [{:is-group false
:path (split-token-set-name name) :path (split-set-name name)
:id name :id name
:parent-path parent :parent-path parent
:depth depth :depth depth
@ -712,7 +717,7 @@ Will return a value that matches this schema:
`:none` None of the nested sets are active `:none` None of the nested sets are active
`:all` All of the nested sets are active `:all` All of the nested sets are active
`:partial` Mixed active state of nested sets") `:partial` Mixed active state of nested sets")
(get-active-themes-set-tokens [_] "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")
(validate [_])) (validate [_]))
@ -741,7 +746,7 @@ Will return a value that matches this schema:
ITokenSets ITokenSets
(add-set [_ token-set] (add-set [_ token-set]
(let [path (get-token-set-prefixed-path token-set) (let [path (get-set-prefixed-path token-set)
token-set (check-token-set token-set)] token-set (check-token-set token-set)]
(TokensLib. (d/oassoc-in sets path token-set) (TokensLib. (d/oassoc-in sets path token-set)
themes themes
@ -753,7 +758,7 @@ Will return a value that matches this schema:
(if set (if set
(let [set' (-> (make-token-set (f set)) (let [set' (-> (make-token-set (f set))
(assoc :modified-at (dt/now))) (assoc :modified-at (dt/now)))
prefixed-full-path' (get-token-set-prefixed-path set') prefixed-full-path' (get-set-prefixed-path set')
name-changed? (not= (:name set) (:name set'))] name-changed? (not= (:name set) (:name set'))]
(if name-changed? (if name-changed?
(TokensLib. (-> sets (TokensLib. (-> sets
@ -783,7 +788,7 @@ Will return a value that matches this schema:
active-themes))) active-themes)))
(delete-set-group [this set-group-name] (delete-set-group [this set-group-name]
(let [path (split-token-set-name set-group-name) (let [path (split-set-name set-group-name)
prefixed-path (map add-set-group-prefix path) prefixed-path (map add-set-group-prefix path)
child-set-names (->> (get-sets-at-path this path) child-set-names (->> (get-sets-at-path this path)
(map :name) (map :name)
@ -798,7 +803,7 @@ Will return a value that matches this schema:
active-themes))) active-themes)))
(delete-set-path [_ prefixed-set-name] (delete-set-path [_ prefixed-set-name]
(let [prefixed-set-path (split-token-set-name prefixed-set-name) (let [prefixed-set-path (split-set-name prefixed-set-name)
set-node (get-in sets prefixed-set-path) set-node (get-in sets prefixed-set-path)
set-group? (not (instance? TokenSet set-node)) set-group? (not (instance? TokenSet set-node))
set-name-string (prefixed-set-path-string->set-name-string prefixed-set-name)] set-name-string (prefixed-set-path-string->set-name-string prefixed-set-name)]
@ -912,7 +917,7 @@ Will return a value that matches this schema:
(filter (partial instance? TokenSet)))) (filter (partial instance? TokenSet))))
(get-sets-at-prefix-path [_ prefixed-path-str] (get-sets-at-prefix-path [_ prefixed-path-str]
(some->> (get-in sets (split-token-set-name prefixed-path-str)) (some->> (get-in sets (split-set-name prefixed-path-str))
(tree-seq d/ordered-map? vals) (tree-seq d/ordered-map? vals)
(filter (partial instance? TokenSet)))) (filter (partial instance? TokenSet))))
@ -968,13 +973,13 @@ Will return a value that matches this schema:
(d/dissoc-in [group name]))) (d/dissoc-in [group name])))
(if same-path? (if same-path?
active-themes active-themes
(disj active-themes (token-theme-path group name))))) (disj active-themes (join-theme-path group name)))))
this))) this)))
(delete-theme [_ group name] (delete-theme [_ group name]
(TokensLib. sets (TokensLib. sets
(d/dissoc-in themes [group name]) (d/dissoc-in themes [group name])
(disj active-themes (token-theme-path group name)))) (disj active-themes (join-theme-path group name))))
(get-theme-tree [_] (get-theme-tree [_]
themes) themes)
@ -1015,10 +1020,10 @@ Will return a value that matches this schema:
(deactivate-theme [_ group name] (deactivate-theme [_ group name]
(TokensLib. sets (TokensLib. sets
themes themes
(disj active-themes (token-theme-path group name)))) (disj active-themes (join-theme-path group name))))
(theme-active? [_ group name] (theme-active? [_ group name]
(contains? active-themes (token-theme-path group name))) (contains? active-themes (join-theme-path group name)))
(toggle-theme-active? [this group name] (toggle-theme-active? [this group name]
(if (theme-active? this group name) (if (theme-active? this group name)
@ -1084,7 +1089,7 @@ Will return a value that matches this schema:
:else :none)) :else :none))
:none))) :none)))
(get-active-themes-set-tokens [this] (get-tokens-in-active-sets [this]
(let [theme-set-names (get-active-themes-set-names this) (let [theme-set-names (get-active-themes-set-names this)
all-set-names (get-ordered-set-names this) all-set-names (get-ordered-set-names this)
active-set-names (filter theme-set-names all-set-names) active-set-names (filter theme-set-names all-set-names)
@ -1099,7 +1104,8 @@ Will return a value that matches this schema:
(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 set))))
{} (get-sets this))) {}
(get-sets this)))
(validate [_] (validate [_]
(and (valid-token-sets? sets) (and (valid-token-sets? sets)
@ -1108,7 +1114,7 @@ Will return a value that matches this schema:
(defn get-hidden-theme (defn get-hidden-theme
[tokens-lib] [tokens-lib]
(get-theme tokens-lib hidden-token-theme-group hidden-token-theme-name)) (get-theme tokens-lib hidden-theme-group hidden-theme-name))
(defn valid-tokens-lib? (defn valid-tokens-lib?
[o] [o]
@ -1119,11 +1125,11 @@ Will return a value that matches this schema:
"A helper that is responsible to ensure that the hidden theme always "A helper that is responsible to ensure that the hidden theme always
exists on the themes data structure" exists on the themes data structure"
[themes] [themes]
(update themes hidden-token-theme-group (update themes hidden-theme-group
(fn [data] (fn [data]
(if (contains? data hidden-token-theme-name) (if (contains? data hidden-theme-name)
data data
(d/oassoc data hidden-token-theme-name (make-hidden-token-theme)))))) (d/oassoc data hidden-theme-name (make-hidden-theme))))))
(defn make-tokens-lib (defn make-tokens-lib
"Create an empty or prepopulated tokens library." "Create an empty or prepopulated tokens library."
@ -1131,7 +1137,7 @@ Will return a value that matches this schema:
(let [sets (or sets (d/ordered-map)) (let [sets (or sets (d/ordered-map))
themes (-> (or themes (d/ordered-map)) themes (-> (or themes (d/ordered-map))
(ensure-hidden-theme)) (ensure-hidden-theme))
active-themes (or active-themes #{hidden-token-theme-path})] active-themes (or active-themes #{hidden-theme-path})]
(TokensLib. (TokensLib.
(check-token-sets sets) (check-token-sets sets)
(check-token-themes themes) (check-token-themes themes)
@ -1325,7 +1331,7 @@ Will return a value that matches this schema:
(or (->> (get metadata "activeThemes") (or (->> (get metadata "activeThemes")
(into #{}) (into #{})
(not-empty)) (not-empty))
#{hidden-token-theme-path}) #{hidden-theme-path})
themes themes
(->> (get decoded-json "$themes") (->> (get decoded-json "$themes")
@ -1366,7 +1372,7 @@ Will return a value that matches this schema:
ordered-set-names) ordered-set-names)
library library
(update-theme library hidden-token-theme-group hidden-token-theme-name (update-theme library hidden-theme-group hidden-theme-name
#(assoc % :sets active-set-names)) #(assoc % :sets active-set-names))
library library
@ -1374,7 +1380,7 @@ Will return a value that matches this schema:
library library
(reduce (fn [library theme-path] (reduce (fn [library theme-path]
(let [[group name] (split-token-theme-path theme-path)] (let [[group name] (split-theme-path theme-path)]
(activate-theme library group name))) (activate-theme library group name)))
library library
active-theme-names)] active-theme-names)]
@ -1420,7 +1426,7 @@ Will return a value that matches this schema:
(let [themes-xform (let [themes-xform
(comp (comp
(filter #(and (instance? TokenTheme %) (filter #(and (instance? TokenTheme %)
(not (hidden-temporary-theme? %)))) (not (hidden-theme? %))))
(map (fn [token-theme] (map (fn [token-theme]
(let [theme-map (->> token-theme (let [theme-map (->> token-theme
(into {}) (into {})
@ -1439,7 +1445,7 @@ Will return a value that matches this schema:
;; Active themes without exposing hidden penpot theme ;; Active themes without exposing hidden penpot theme
active-themes-clear active-themes-clear
(-> (get-active-theme-paths tokens-lib) (-> (get-active-theme-paths tokens-lib)
(disj hidden-token-theme-path)) (disj hidden-theme-path))
update-token-fn update-token-fn
(fn [token] (fn [token]
@ -1592,7 +1598,7 @@ Will return a value that matches this schema:
(fn [theme] (fn [theme]
(if (get theme :external-id) (if (get theme :external-id)
theme theme
(if (hidden-temporary-theme? theme) (if (hidden-theme? theme)
(assoc theme (assoc theme
:id uuid/zero :id uuid/zero
:external-id "") :external-id "")

View file

@ -36,7 +36,7 @@
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 (= #{ctob/hidden-token-theme-path} (ctob/get-active-theme-paths redo-lib))) (t/is (= #{ctob/hidden-theme-path} (ctob/get-active-theme-paths redo-lib)))
(t/is (= #{} (:sets (ctob/get-hidden-theme redo-lib)))) (t/is (= #{} (:sets (ctob/get-hidden-theme redo-lib))))
;; Undo ;; Undo
@ -56,7 +56,7 @@
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 (= #{ctob/hidden-token-theme-path} (ctob/get-active-theme-paths redo-lib))) (t/is (= #{ctob/hidden-theme-path} (ctob/get-active-theme-paths redo-lib)))
(t/is (= #{} (:sets (ctob/get-hidden-theme redo-lib)))) (t/is (= #{} (:sets (ctob/get-hidden-theme redo-lib))))
;; Undo ;; Undo
@ -65,8 +65,8 @@
(t/testing "toggling an set with hidden theme already active will toggle set in hidden theme" (t/testing "toggling an set with hidden theme already active will toggle set in hidden theme"
(let [file (setup-file #(-> % (let [file (setup-file #(-> %
(ctob/add-set (ctob/make-token-set :name "foo/bar")) (ctob/add-set (ctob/make-token-set :name "foo/bar"))
(ctob/add-theme (ctob/make-hidden-token-theme)) (ctob/add-theme (ctob/make-hidden-theme))
(ctob/set-active-themes #{ctob/hidden-token-theme-path}))) (ctob/set-active-themes #{ctob/hidden-theme-path})))
changes (-> (pcb/empty-changes) changes (-> (pcb/empty-changes)
(pcb/with-library-data (:data file)) (pcb/with-library-data (:data file))
@ -299,7 +299,7 @@
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 (= #{ctob/hidden-token-theme-path} (ctob/get-active-theme-paths redo-lib))) (t/is (= #{ctob/hidden-theme-path} (ctob/get-active-theme-paths redo-lib)))
(t/is (= #{"foo/bar/baz" "foo/bar/baz/baz-child"} (:sets (ctob/get-hidden-theme redo-lib)))) (t/is (= #{"foo/bar/baz" "foo/bar/baz/baz-child"} (:sets (ctob/get-hidden-theme redo-lib))))
;; Undo ;; Undo
@ -323,7 +323,7 @@
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 (= #{} (:sets (ctob/get-hidden-theme redo-lib)))) (t/is (= #{} (:sets (ctob/get-hidden-theme redo-lib))))
(t/is (= #{ctob/hidden-token-theme-path} (ctob/get-active-theme-paths redo-lib))) (t/is (= #{ctob/hidden-theme-path} (ctob/get-active-theme-paths redo-lib)))
;; Undo ;; Undo
(t/is (= #{"/theme"} (ctob/get-active-theme-paths undo-lib)))))) (t/is (= #{"/theme"} (ctob/get-active-theme-paths undo-lib))))))

View file

@ -544,10 +544,10 @@
(ctob/make-token :name "token-4" (ctob/make-token :name "token-4"
:type :border-radius :type :border-radius
:value 4000)})) :value 4000)}))
(ctob/update-theme ctob/hidden-token-theme-group ctob/hidden-token-theme-name (ctob/update-theme ctob/hidden-theme-group ctob/hidden-theme-name
#(ctob/enable-sets % #{"set-a" "set-b"}))) #(ctob/enable-sets % #{"set-a" "set-b"})))
tokens (ctob/get-active-themes-set-tokens tokens-lib)] tokens (ctob/get-tokens-in-active-sets tokens-lib)]
(t/is (= (mapv key tokens) ["token-1" "token-2" "token-3"])) (t/is (= (mapv key tokens) ["token-1" "token-2" "token-3"]))
(t/is (= (get-in tokens ["token-1" :value]) 100)) (t/is (= (get-in tokens ["token-1" :value]) 100))
@ -595,7 +595,7 @@
:sets #{"set-b" "set-c" "set-a"})) :sets #{"set-b" "set-c" "set-a"}))
(ctob/set-active-themes #{"/single-theme"})) (ctob/set-active-themes #{"/single-theme"}))
tokens (ctob/get-active-themes-set-tokens tokens-lib)] tokens (ctob/get-tokens-in-active-sets tokens-lib)]
;; Note that sets order inside the theme is undefined. What matters is order in that the ;; Note that sets order inside the theme is undefined. What matters is order in that the
;; sets have been added to the library. ;; sets have been added to the library.
@ -648,7 +648,7 @@
:sets #{"set-b" "set-a"})) :sets #{"set-b" "set-a"}))
(ctob/set-active-themes #{"/theme-1" "/theme-2"})) (ctob/set-active-themes #{"/theme-1" "/theme-2"}))
tokens (ctob/get-active-themes-set-tokens tokens-lib)] tokens (ctob/get-tokens-in-active-sets tokens-lib)]
;; Note that themes order is irrelevant. What matters is the union of the active sets ;; Note that themes order is irrelevant. What matters is the union of the active sets
;; and the order of the sets in the library. ;; and the order of the sets in the library.
@ -693,7 +693,7 @@
:sets #{})) :sets #{}))
(ctob/set-active-themes #{"App/Web" "Brand/Brand A"})) (ctob/set-active-themes #{"App/Web" "Brand/Brand A"}))
tokens (ctob/get-active-themes-set-tokens tokens-lib)] tokens (ctob/get-tokens-in-active-sets tokens-lib)]
(t/is (= (mapv key tokens) ["red" "border1"])) (t/is (= (mapv key tokens) ["red" "border1"]))
(t/is (= (get-in tokens ["red" :value]) "#ff0000")) (t/is (= (get-in tokens ["red" :value]) "#ff0000"))
@ -703,13 +703,13 @@
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :name "set-a"))) (ctob/add-set (ctob/make-token-set :name "set-a")))
tokens (ctob/get-active-themes-set-tokens tokens-lib)] tokens (ctob/get-tokens-in-active-sets tokens-lib)]
(t/is (empty? tokens)))) (t/is (empty? tokens))))
(t/deftest list-active-themes-tokens-no-sets (t/deftest list-active-themes-tokens-no-sets
(let [tokens-lib (ctob/make-tokens-lib) (let [tokens-lib (ctob/make-tokens-lib)
tokens (ctob/get-active-themes-set-tokens tokens-lib)] tokens (ctob/get-tokens-in-active-sets tokens-lib)]
(t/is (empty? tokens)))) (t/is (empty? tokens))))
@ -1327,7 +1327,7 @@
(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-token-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 lib "dark" "small") (t/is (tht/token-data-eq? (ctob/get-token-in-set lib "dark" "small")
{:name "small" {:name "small"

View file

@ -138,7 +138,6 @@
If the `value` is not parseable and/or has missing references returns a map with `:errors`. If the `value` is not parseable and/or has missing references returns a map with `:errors`.
If the `value` is parseable but is out of range returns a map with `warnings`." If the `value` is parseable but is out of range returns a map with `warnings`."
[value has-references?] [value has-references?]
(let [parsed-value (cft/parse-token-value value) (let [parsed-value (cft/parse-token-value value)
out-of-scope (< (:value parsed-value) 0) out-of-scope (< (:value parsed-value) 0)
references (seq (ctob/find-token-value-references value))] references (seq (ctob/find-token-value-references value))]
@ -277,7 +276,7 @@
(let [{:keys [tokens-tree ids]} (ctob/backtrace-tokens-tree tokens)] (let [{:keys [tokens-tree ids]} (ctob/backtrace-tokens-tree tokens)]
(resolve-tokens-tree tokens-tree #(get ids (sd-token-uuid %))))) (resolve-tokens-tree tokens-tree #(get ids (sd-token-uuid %)))))
(defn resolve-tokens-with-errors [tokens] (defn resolve-tokens-with-verbose-errors [tokens]
(resolve-tokens-tree (resolve-tokens-tree
(ctob/tokens-tree tokens) (ctob/tokens-tree tokens)
#(get tokens (sd-token-name %)) #(get tokens (sd-token-name %))

View file

@ -47,7 +47,7 @@
(when (empty? (get state :workspace-editor-state)) (when (empty? (get state :workspace-editor-state))
(when-let [tokens (some-> (dsh/lookup-file-data state) (when-let [tokens (some-> (dsh/lookup-file-data state)
(get :tokens-lib) (get :tokens-lib)
(ctob/get-active-themes-set-tokens))] (ctob/get-tokens-in-active-sets))]
(->> (sd/resolve-tokens tokens) (->> (sd/resolve-tokens tokens)
(rx/mapcat (rx/mapcat
(fn [resolved-tokens] (fn [resolved-tokens]

View file

@ -74,7 +74,7 @@
(st/emit! (show-unknown-types-warning unknown-tokens))) (st/emit! (show-unknown-types-warning unknown-tokens)))
(try (try
(->> (ctob/get-all-tokens tokens-lib) (->> (ctob/get-all-tokens tokens-lib)
(sd/resolve-tokens-with-errors) (sd/resolve-tokens-with-verbose-errors)
(rx/map (fn [_] (rx/map (fn [_]
tokens-lib)) tokens-lib))
(rx/catch (fn [sd-error] (rx/catch (fn [sd-error]

View file

@ -114,9 +114,9 @@
active-token-themes (some-> tokens-lib active-token-themes (some-> tokens-lib
(ctob/toggle-theme-active? group name) (ctob/toggle-theme-active? group name)
(ctob/get-active-theme-paths)) (ctob/get-active-theme-paths))
active-token-themes' (if (= active-token-themes #{ctob/hidden-token-theme-path}) active-token-themes' (if (= active-token-themes #{ctob/hidden-theme-path})
active-token-themes active-token-themes
(disj active-token-themes ctob/hidden-token-theme-path)) (disj active-token-themes ctob/hidden-theme-path))
changes (-> (pcb/empty-changes it) changes (-> (pcb/empty-changes it)
(pcb/update-active-token-themes active-token-themes' prev-active-token-themes))] (pcb/update-active-token-themes active-token-themes' prev-active-token-themes))]
(rx/of (rx/of
@ -319,7 +319,7 @@
(ctob/add-token token)) (ctob/add-token token))
hidden-theme hidden-theme
(ctob/make-hidden-token-theme) (ctob/make-hidden-theme)
hidden-theme-with-set hidden-theme-with-set
(ctob/enable-set hidden-theme set-name) (ctob/enable-set hidden-theme set-name)
@ -331,7 +331,7 @@
(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)
(pcb/update-active-token-themes #{ctob/hidden-token-theme-path} #{}))] (pcb/update-active-token-themes #{ctob/hidden-theme-path} #{}))]
(rx/of (dch/commit-changes changes) (rx/of (dch/commit-changes changes)
(set-selected-token-set-name set-name)))))) (set-selected-token-set-name set-name))))))

View file

@ -187,7 +187,7 @@
(watch [_ state _] (watch [_ state _]
(when-let [tokens-lib (-> (dsh/lookup-file-data state) (when-let [tokens-lib (-> (dsh/lookup-file-data state)
(get :tokens-lib))] (get :tokens-lib))]
(->> (ctob/get-active-themes-set-tokens tokens-lib) (->> (ctob/get-tokens-in-active-sets tokens-lib)
(sd/resolve-tokens) (sd/resolve-tokens)
(rx/mapcat (fn [sd-tokens] (rx/mapcat (fn [sd-tokens]
(let [undo-id (js/Symbol)] (let [undo-id (js/Symbol)]

View file

@ -25,10 +25,10 @@
(get :tokens-lib) (get :tokens-lib)
(ctob/get-set set-name)))) (ctob/get-set set-name))))
(defn get-selected-token-set-token [state token-name] (defn get-token-in-selected-set [state token-name]
(some-> (get-selected-token-set state) (some-> (get-selected-token-set state)
(ctob/get-token token-name))) (ctob/get-token token-name)))
(defn get-selected-token-set-tokens [state] (defn get-all-tokens-in-selected-set [state]
(some-> (get-selected-token-set state) (some-> (get-selected-token-set state)
:tokens)) :tokens))

View file

@ -466,7 +466,7 @@
(l/derived (fn [lib] (l/derived (fn [lib]
(or (or
(some-> lib (some-> lib
(ctob/delete-theme ctob/hidden-token-theme-group ctob/hidden-token-theme-name) (ctob/delete-theme ctob/hidden-theme-group ctob/hidden-theme-name)
(ctob/get-theme-tree)) (ctob/get-theme-tree))
[])) []))
tokens-lib)) tokens-lib))
@ -475,7 +475,7 @@
(l/derived #(or (some-> % ctob/get-themes) []) tokens-lib)) (l/derived #(or (some-> % ctob/get-themes) []) tokens-lib))
(def workspace-token-themes-no-hidden (def workspace-token-themes-no-hidden
(l/derived #(remove ctob/hidden-temporary-theme? %) workspace-token-themes)) (l/derived #(remove ctob/hidden-theme? %) workspace-token-themes))
(def selected-token-set-name (def selected-token-set-name
(l/derived (l/key :selected-token-set-name) workspace-tokens)) (l/derived (l/key :selected-token-set-name) workspace-tokens))
@ -498,20 +498,20 @@
tokens-lib)) tokens-lib))
(def workspace-active-theme-paths-no-hidden (def workspace-active-theme-paths-no-hidden
(l/derived #(disj % ctob/hidden-token-theme-path) workspace-active-theme-paths)) (l/derived #(disj % ctob/hidden-theme-path) workspace-active-theme-paths))
;; FIXME: deprecated, it should not be implemented with ref (still used in form) ;; FIXME: deprecated, it should not be implemented with ref (still used in form)
(def workspace-active-theme-sets-tokens (def workspace-active-theme-sets-tokens
(l/derived #(or (some-> % ctob/get-active-themes-set-tokens) {}) tokens-lib)) (l/derived #(or (some-> % ctob/get-tokens-in-active-sets) {}) tokens-lib))
(def workspace-selected-token-set-token (def workspace-token-in-selected-set
(fn [token-name] (fn [token-name]
(l/derived (l/derived
#(dwts/get-selected-token-set-token % token-name) #(dwts/get-token-in-selected-set % token-name)
st/state))) st/state)))
(def workspace-selected-token-set-tokens (def workspace-all-tokens-in-selected-set
(l/derived #(or (dwts/get-selected-token-set-tokens %) {}) st/state)) (l/derived #(or (dwts/get-all-tokens-in-selected-set %) {}) st/state))
(def plugins-permissions-peek (def plugins-permissions-peek
(l/derived (fn [state] (l/derived (fn [state]

View file

@ -411,7 +411,7 @@
selected (mf/deref refs/selected-shapes) selected (mf/deref refs/selected-shapes)
selected-shapes (into [] (keep (d/getf objects)) selected) selected-shapes (into [] (keep (d/getf objects)) selected)
token-name (:token-name mdata) token-name (:token-name mdata)
token (mf/deref (refs/workspace-selected-token-set-token token-name)) token (mf/deref (refs/workspace-token-in-selected-set token-name))
selected-token-set-name (mf/deref refs/selected-token-set-name)] selected-token-set-name (mf/deref refs/selected-token-set-name)]
[:ul {:class (stl/css :context-list)} [:ul {:class (stl/css :context-list)}
[:& menu-tree {:submenu-offset width [:& menu-tree {:submenu-offset width

View file

@ -239,7 +239,7 @@
token (or token {:type token-type}) token (or token {:type token-type})
token-properties (dwta/get-token-properties token) token-properties (dwta/get-token-properties token)
is-color-token (cft/color-token? token) is-color-token (cft/color-token? token)
selected-set-tokens (mf/deref refs/workspace-selected-token-set-tokens) tokens-in-selected-set (mf/deref refs/workspace-all-tokens-in-selected-set)
active-theme-tokens (cond-> (mf/deref refs/workspace-active-theme-sets-tokens) active-theme-tokens (cond-> (mf/deref refs/workspace-active-theme-sets-tokens)
;; Ensure that the resolved value uses the currently editing token ;; Ensure that the resolved value uses the currently editing token
@ -254,12 +254,12 @@
(mf/deps (:name token)) (mf/deps (:name token))
#(cft/token-name->path (:name token))) #(cft/token-name->path (:name token)))
selected-set-tokens-tree (mf/use-memo tokens-tree-in-selected-set (mf/use-memo
(mf/deps token-path selected-set-tokens) (mf/deps token-path tokens-in-selected-set)
(fn [] (fn []
(-> (ctob/tokens-tree selected-set-tokens) (-> (ctob/tokens-tree tokens-in-selected-set)
;; Allow setting editing token to it's own path ;; Allow setting editing token to it's own path
(d/dissoc-in token-path)))) (d/dissoc-in token-path))))
cancel-ref (mf/use-ref nil) cancel-ref (mf/use-ref nil)
on-cancel-ref on-cancel-ref
@ -278,10 +278,10 @@
validate-name validate-name
(mf/use-fn (mf/use-fn
(mf/deps selected-set-tokens-tree) (mf/deps tokens-tree-in-selected-set)
(fn [value] (fn [value]
(let [schema (token-name-schema {:token token (let [schema (token-name-schema {:token token
:tokens-tree selected-set-tokens-tree})] :tokens-tree tokens-tree-in-selected-set})]
(m/explain schema (finalize-name value))))) (m/explain schema (finalize-name value)))))
on-blur-name on-blur-name

View file

@ -57,8 +57,8 @@
(let [;; FIXME: this code should be reusable under helper under (let [;; FIXME: this code should be reusable under helper under
;; common types namespace ;; common types namespace
name name
(if-let [parent-path (ctob/get-token-set-path parent-set)] (if-let [parent-path (ctob/get-set-path parent-set)]
(->> (concat parent-path (ctob/split-token-set-name name)) (->> (concat parent-path (ctob/split-set-name name))
(ctob/join-set-path)) (ctob/join-set-path))
(ctob/normalize-set-name name))] (ctob/normalize-set-name name))]

View file

@ -269,7 +269,7 @@
active-theme-tokens active-theme-tokens
(mf/with-memo [tokens-lib] (mf/with-memo [tokens-lib]
(if tokens-lib (if tokens-lib
(ctob/get-active-themes-set-tokens tokens-lib) (ctob/get-tokens-in-active-sets tokens-lib)
{})) {}))
;; Resolve tokens as second step ;; Resolve tokens as second step

View file

@ -83,7 +83,7 @@
current-label (cond current-label (cond
(> active-themes-count 1) (tr "workspace.tokens.active-themes" active-themes-count) (> active-themes-count 1) (tr "workspace.tokens.active-themes" active-themes-count)
(= active-themes-count 1) (some->> (first active-theme-paths) (= active-themes-count 1) (some->> (first active-theme-paths)
(ctob/split-token-theme-path) (ctob/split-theme-path)
(remove empty?) (remove empty?)
(str/join " / ")) (str/join " / "))
:else (tr "workspace.tokens.no-active-theme")) :else (tr "workspace.tokens.no-active-theme"))

View file

@ -31,7 +31,7 @@
(watch [_ state _] (watch [_ state _]
(let [data (dsh/lookup-file-data state)] (let [data (dsh/lookup-file-data state)]
(->> (get data :tokens-lib) (->> (get data :tokens-lib)
(ctob/get-active-themes-set-tokens) (ctob/get-tokens-in-active-sets)
(sd/resolve-tokens) (sd/resolve-tokens)
(rx/mapcat #(rx/of (end)))))))) (rx/mapcat #(rx/of (end))))))))

View file

@ -12,7 +12,7 @@
(defn get-token [file name] (defn get-token [file name]
(some-> (get-in file [:data :tokens-lib]) (some-> (get-in file [:data :tokens-lib])
(ctob/get-active-themes-set-tokens) (ctob/get-tokens-in-active-sets)
(get name))) (get name)))
(defn apply-token-to-shape (defn apply-token-to-shape