🔧 Modify token sets by id instead of name and review usage

This commit is contained in:
Andrés Moya
2025-08-22 10:36:17 +02:00
committed by Andrés Moya
parent 03e05da41e
commit d76a5c615c
25 changed files with 519 additions and 558 deletions

View File

@@ -409,13 +409,12 @@
[:map {:title "SetTokenSetChange"} [:map {:title "SetTokenSetChange"}
[:type [:= :set-token-set]] [:type [:= :set-token-set]]
[:id ::sm/uuid] [:id ::sm/uuid]
[:is-group :boolean]
[:token-set [:maybe ctob/schema:token-set-attrs]]]] [:token-set [:maybe ctob/schema:token-set-attrs]]]]
[:set-token [:set-token
[:map {:title "SetTokenChange"} [:map {:title "SetTokenChange"}
[:type [:= :set-token]] [:type [:= :set-token]]
[:set-name :string] [:set-id ::sm/uuid]
[:token-id ::sm/uuid] [:token-id ::sm/uuid]
[:token [:maybe ctob/schema:token-attrs]]]] [:token [:maybe ctob/schema:token-attrs]]]]
@@ -978,39 +977,36 @@
(assoc data :tokens-lib tokens-lib)) (assoc data :tokens-lib tokens-lib))
(defmethod process-change :set-token (defmethod process-change :set-token
[data {:keys [set-name token-id token]}] [data {:keys [set-id token-id token]}]
(update data :tokens-lib (update data :tokens-lib
(fn [lib] (fn [lib]
(let [lib' (ctob/ensure-tokens-lib lib) (let [lib' (ctob/ensure-tokens-lib lib)]
set (ctob/get-set-by-name lib' set-name)] ;; FIXME: remove this when set-token uses set-id
(cond (cond
(not token) (not token)
(ctob/delete-token-from-set lib' set-name token-id) (ctob/delete-token-from-set lib' set-id token-id)
(not (ctob/get-token-in-set lib' (ctob/get-id set) token-id)) (not (ctob/get-token-in-set lib' set-id token-id))
(ctob/add-token-in-set lib' set-name (ctob/make-token token)) (ctob/add-token-in-set lib' set-id (ctob/make-token token))
:else :else
(ctob/update-token-in-set lib' set-name token-id (fn [prev-token] (ctob/update-token-in-set lib' set-id token-id
(ctob/make-token (merge prev-token token))))))))) (fn [prev-token]
(ctob/make-token (merge prev-token token)))))))))
(defmethod process-change :set-token-set (defmethod process-change :set-token-set
[data {:keys [id is-group token-set]}] [data {:keys [id token-set]}]
(update data :tokens-lib (update data :tokens-lib
(fn [lib] (fn [lib]
(let [lib' (ctob/ensure-tokens-lib lib) (let [lib' (ctob/ensure-tokens-lib lib)]
set (ctob/get-set lib' id)] ;; FIXME: remove this when set-token-set uses set-id
(cond (cond
(not token-set) (not token-set)
(if is-group (ctob/delete-set lib' id)
(ctob/delete-set-group lib' (ctob/get-name set)) ;; FIXME: move to a separate change
(ctob/delete-set lib' (ctob/get-name set)))
(not (ctob/get-set lib' id)) (not (ctob/get-set lib' id))
(ctob/add-set lib' (ctob/make-token-set token-set)) (ctob/add-set lib' (ctob/make-token-set token-set))
:else :else
(ctob/update-set lib' (ctob/get-name set) (fn [_] (ctob/make-token-set token-set)))))))) (ctob/update-set lib' id (fn [_] (ctob/make-token-set token-set))))))))
(defmethod process-change :set-token-theme (defmethod process-change :set-token-theme
[data {:keys [group theme-name theme]}] [data {:keys [group theme-name theme]}]

View File

@@ -800,11 +800,15 @@
(apply-changes-local)))) (apply-changes-local))))
(defn update-active-token-themes (defn update-active-token-themes
[changes active-theme-paths prev-active-theme-paths] [changes active-theme-paths]
(-> changes (assert-library! changes)
(update :redo-changes conj {:type :update-active-token-themes :theme-paths active-theme-paths}) (let [library-data (::library-data (meta changes))
(update :undo-changes conj {:type :update-active-token-themes :theme-paths prev-active-theme-paths}) prev-active-theme-paths (some-> (get library-data :tokens-lib)
(apply-changes-local))) (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})
(apply-changes-local))))
(defn set-token-theme [changes group theme-name theme] (defn set-token-theme [changes group theme-name theme]
(assert-library! changes) (assert-library! changes)
@@ -881,31 +885,21 @@
(update :undo-changes conj {:type :set-tokens-lib :tokens-lib prev-tokens-lib}) (update :undo-changes conj {:type :set-tokens-lib :tokens-lib prev-tokens-lib})
(apply-changes-local)))) (apply-changes-local))))
(defn set-token [changes set-name token-id token] (defn set-token [changes set-id token-id token]
(assert-library! changes) (assert-library! changes)
(let [library-data (::library-data (meta changes)) (let [library-data (::library-data (meta changes))
prev-token (some-> (get library-data :tokens-lib) prev-token (some-> (get library-data :tokens-lib)
(ctob/get-set-by-name set-name) (ctob/get-set set-id)
(ctob/get-token token-id))] (ctob/get-token token-id))]
(-> changes (-> changes
(update :redo-changes conj {:type :set-token (update :redo-changes conj {:type :set-token
:set-name set-name :set-id set-id
:token-id token-id :token-id token-id
:token token}) :token token})
(update :undo-changes conj (if prev-token (update :undo-changes conj {:type :set-token
{:type :set-token :set-id set-id
:set-name set-name :token-id token-id
:token-id (or :token prev-token})
;; Undo of edit
(:id token)
;; Undo of delete
token-id)
:token prev-token}
;; Undo of create token
{:type :set-token
:set-name set-name
:token-id token-id
:token nil}))
(apply-changes-local)))) (apply-changes-local))))
(defn rename-token-set (defn rename-token-set
@@ -917,16 +911,14 @@
(-> changes (-> changes
(update :redo-changes conj {:type :set-token-set (update :redo-changes conj {:type :set-token-set
:id id :id id
:token-set (datafy (ctob/rename prev-token-set new-name)) :token-set (datafy (ctob/rename prev-token-set new-name))})
:is-group false})
(update :undo-changes conj {:type :set-token-set (update :undo-changes conj {:type :set-token-set
:id id :id id
:token-set (datafy prev-token-set) :token-set (datafy prev-token-set)})
:is-group false})
(apply-changes-local)))) (apply-changes-local))))
(defn set-token-set (defn set-token-set
[changes id is-group token-set] [changes id token-set]
(assert-library! changes) (assert-library! changes)
(let [library-data (::library-data (meta changes)) (let [library-data (::library-data (meta changes))
prev-token-set (some-> (get library-data :tokens-lib) prev-token-set (some-> (get library-data :tokens-lib)
@@ -934,12 +926,10 @@
(-> changes (-> changes
(update :redo-changes conj {:type :set-token-set (update :redo-changes conj {:type :set-token-set
:id id :id id
:token-set (datafy token-set) :token-set (datafy token-set)})
:is-group is-group})
(update :undo-changes conj {:type :set-token-set (update :undo-changes conj {:type :set-token-set
:id id :id id
:token-set (datafy prev-token-set) :token-set (datafy prev-token-set)})
:is-group is-group})
(apply-changes-local)))) (apply-changes-local))))
(defn add-component (defn add-component

View File

@@ -17,18 +17,17 @@
Use this for managing sets active state without having to modify a Use this for managing sets active state without having to modify a
user created theme (\"no themes selected\" state in the ui)." user created theme (\"no themes selected\" state in the ui)."
[changes tokens-lib update-theme-fn] [changes tokens-lib update-theme-fn]
(let [prev-active-token-themes (ctob/get-active-theme-paths tokens-lib) (let [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-theme (ctob/get-hidden-theme tokens-lib) hidden-theme (ctob/get-hidden-theme tokens-lib)
hidden-theme' (-> (some-> hidden-theme
hidden-theme (-> (some-> prev-hidden-theme (ctob/set-sets active-token-set-names)) (ctob/set-sets active-token-set-names))
(update-theme-fn))] (update-theme-fn))]
(-> changes (-> changes
(pcb/update-active-token-themes #{(ctob/theme-path hidden-theme)} prev-active-token-themes) (pcb/update-active-token-themes #{(ctob/theme-path hidden-theme')})
(pcb/set-token-theme (:group prev-hidden-theme) (pcb/set-token-theme (:group hidden-theme)
(:name prev-hidden-theme) (:name hidden-theme)
hidden-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
@@ -139,3 +138,12 @@
(if-let [params (calculate-move-token-set-or-set-group tokens-lib params)] (if-let [params (calculate-move-token-set-or-set-group tokens-lib params)]
(pcb/move-token-set-group changes params) (pcb/move-token-set-group changes params)
changes)) changes))
(defn generate-delete-token-set-group
"Create changes for deleting a token set group."
[changes tokens-lib path]
(let [sets (ctob/get-sets-at-path tokens-lib path)]
(reduce (fn [changes set]
(pcb/set-token-set changes (ctob/get-id set) nil))
changes
sets)))

View File

@@ -295,6 +295,7 @@
(assoc tokens (:name token) token)))) (assoc tokens (:name token) token))))
(update-token [this token-id f] (update-token [this token-id f]
(assert (uuid? token-id) "expected uuid for `token-id`")
(if-let [token (get-token this token-id)] (if-let [token (get-token this token-id)]
(let [token' (-> (make-token (f token)) (let [token' (-> (make-token (f token))
(assoc :modified-at (ct/now)))] (assoc :modified-at (ct/now)))]
@@ -310,6 +311,7 @@
this)) 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 (TokenSet. id
name name
@@ -317,11 +319,13 @@
(ct/now) (ct/now)
(dissoc tokens (:name token))))) (dissoc tokens (:name token)))))
(get-token [_ id] (get-token [_ token-id]
(some #(when (= (:id %) id) %) ;; TODO: this will be made in an efficient way when (assert (uuid? token-id) "expected uuid for `token-id`")
(vals tokens))) ;; we refactor the tokens lib internal structure (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 name))
(get-tokens [_] (get-tokens [_]
@@ -425,10 +429,39 @@
(def ^:private set-separator "/") (def ^:private set-separator "/")
(defn get-set-path
[token-set]
(get-path (get-name token-set) set-separator))
(defn split-set-name
[name]
(split-path name set-separator))
(defn join-set-path [path] (defn join-set-path [path]
(join-path path set-separator)) (join-path path set-separator))
(defn split-set-str-path-prefix (defn normalize-set-name
"Normalize a set name (ensure that there are no extra spaces, like ' group / set' -> 'group/set').
If `relative-to` is provided, the normalized name will preserve the same group prefix as reference name."
([name]
(->> (split-set-name name)
(str/join set-separator)))
([name relative-to]
(->> (concat (butlast (split-set-name relative-to))
(split-set-name name))
(str/join set-separator))))
(defn replace-last-path-name
"Replaces the last element in a `path` vector with `name`."
[path name]
(-> (into [] (drop-last path))
(conj name)))
;; The following functions will be removed after refactoring the internal structure of TokensLib,
;; since we'll no longer need group prefixes to differentiate between sets and set-groups.
(defn- split-set-str-path-prefix
"Split set-path "Split set-path
E.g.: \"S-some-set\" -> [\"S-\" \"some-set\"] E.g.: \"S-some-set\" -> [\"S-\" \"some-set\"]
@@ -438,13 +471,13 @@
(re-matches #"^([SG]-)(.*)") (re-matches #"^([SG]-)(.*)")
(rest))) (rest)))
(defn add-set-path-prefix [set-name-str] (defn- add-set-path-prefix [set-name-str]
(str set-prefix set-name-str)) (str set-prefix set-name-str))
(defn add-set-path-group-prefix [group-path-str] (defn- add-set-path-group-prefix [group-path-str]
(str set-group-prefix group-path-str)) (str set-group-prefix group-path-str))
(defn set-full-path->set-prefixed-full-path (defn- set-full-path->set-prefixed-full-path
"Returns token-set paths with prefixes to differentiate between sets and set-groups. "Returns token-set paths with prefixes to differentiate between sets and set-groups.
Sets will be prefixed with `set-prefix` (S-). Sets will be prefixed with `set-prefix` (S-).
@@ -454,62 +487,24 @@
set-name (add-set-path-prefix (last full-path))] set-name (add-set-path-prefix (last full-path))]
(conj set-path set-name))) (conj set-path set-name)))
(defn set-group-path->set-group-prefixed-path (defn- set-group-path->set-group-prefixed-path
"Adds `set-group-prefix` (G-) to the `path` vector elements." "Adds `set-group-prefix` (G-) to the `path` vector elements."
[path] [path]
(mapv add-set-path-group-prefix path)) (mapv add-set-path-group-prefix path))
(defn set-group-path->set-group-prefixed-path-str (defn- set-group-path->set-group-prefixed-path-str
[path] [path]
(-> (set-group-path->set-group-prefixed-path path) (-> (set-group-path->set-group-prefixed-path path)
(join-set-path))) (join-set-path)))
(defn add-set-group-prefix [group-path] (defn- set-name->prefixed-full-path [name-str]
(str set-group-prefix group-path))
(defn get-set-path
[token-set]
(get-path (get-name token-set) set-separator))
(defn split-set-name
[name]
(split-path name set-separator))
(defn normalize-set-name
"Normalize a set name.
If `relative-to` is provided, the normalized name will preserve the
same group prefix as reference name"
([name]
(->> (split-set-name name)
(str/join set-separator)))
([name relative-to]
(->> (concat (butlast (split-set-name relative-to))
(split-set-name name))
(str/join set-separator))))
(defn set-name->prefixed-full-path [name-str]
(-> (split-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-set-prefixed-path [token-set] (defn- get-set-prefixed-path [token-set]
(let [path (get-path (get-name token-set) set-separator)] (let [path (get-path (get-name 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]
(->> (split-set-name path-str)
(map (fn [path-part]
(or (-> (split-set-str-path-prefix path-part)
(second))
path-part)))
(join-set-path)))
(defn replace-last-path-name
"Replaces the last element in a `path` vector with `name`."
[path name]
(-> (into [] (drop-last path))
(conj name)))
(defn tokens-tree (defn tokens-tree
"Convert tokens into a nested tree with their name as the path. "Convert tokens into a nested tree with their name as the path.
Optionally use `update-token-fn` option to transform the token." Optionally use `update-token-fn` option to transform the token."
@@ -554,16 +549,14 @@
Prefixed set full path or pfpath: a full path wit prefixes [\"G-some-group\", \"G-some-subgroup\", \"S-some-set\"]. Prefixed set full path or pfpath: a full path wit prefixes [\"G-some-group\", \"G-some-subgroup\", \"S-some-set\"].
Prefixed set final name or pfname: a final name with prefix \"S-some-set\"." Prefixed set final name or pfname: a final name with prefix \"S-some-set\"."
(add-set [_ token-set] "add a set to the library, at the end") (add-set [_ token-set] "add a set to the library, at the end")
(update-set [_ set-name f] "modify a set in the library") (update-set [_ id f] "modify a set in the library")
(delete-set-path [_ set-path] "delete a set in the library") (delete-set [_ id] "delete a set in the library and disable it in all themes")
(delete-set [_ set-name] "delete a set at `set-name` in the library and disable the `set-name` in all themes")
(delete-set-group [_ set-group-name] "delete a set group at `set-group-name` in the library and disable its child sets in all themes")
(move-set [_ from-path to-path before-path before-group?] "Move token set at `from-path` to `to-path` and order it before `before-path` with `before-group?`.") (move-set [_ from-path to-path before-path before-group?] "Move token set at `from-path` to `to-path` and order it before `before-path` with `before-group?`.")
(move-set-group [_ from-path to-path before-path before-group?] "Move token set group at `from-path` to `to-path` and order it before `before-path` with `before-group?`.") (move-set-group [_ from-path to-path before-path before-group?] "Move token set group at `from-path` to `to-path` and order it before `before-path` with `before-group?`.")
(set-count [_] "get the total number if sets in the library") (set-count [_] "get the total number if sets in the library")
(get-set-tree [_] "get a nested tree of all sets in the library") (get-set-tree [_] "get a nested tree of all sets in the library")
(get-sets [_] "get an ordered sequence of all sets in the library") (get-sets [_] "get an ordered sequence of all sets in the library")
(get-sets-at-prefix-path [_ prefixed-path-str] "get an ordered sequence of sets at `prefixed-path-str` in the library") (get-sets-at-prefix-path- [_ prefixed-path-str] "get an ordered sequence of sets at `prefixed-path-str` in the library")
(get-sets-at-path [_ path-str] "get an ordered sequence of sets at `path` in the library") (get-sets-at-path [_ path-str] "get an ordered sequence of sets at `path` in the library")
(rename-set-group [_ from-path-str to-path-str] "renames set groups and all child set names from `from-path-str` to `to-path-str`") (rename-set-group [_ from-path-str to-path-str] "renames set groups and all child set names from `from-path-str` to `to-path-str`")
(get-ordered-set-names [_] "get an ordered sequence of all sets names in the library") (get-ordered-set-names [_] "get an ordered sequence of all sets names in the library")
@@ -875,48 +868,52 @@
(walk (or nodes (d/ordered-map)) nil))) (walk (or nodes (d/ordered-map)) nil)))
(defn sets-tree-seq (defn sets-tree-seq
"Get tokens sets tree as a flat list "Return a lazy sequence that walks through the tokens sets tree in a depth-first order. It returns a node for each
group and set. The nodes contain:
- is-group: true if the node is a group, false if it's a set.
- path: vector with the path of the group or set (without prefixes).
- depth: depth in the tree, starting from 0.
- index: index in the sequence, starting from 0.
- id: the uuid if it's a set, and the path string if it's a group.
- token-set: the TokenSet instance if it's a set.
Options: Options:
`:skip-children-pred`: predicate to skip iterating over a set groups children by checking the path of the set group `:skip-children-pred`: predicate that is given a node path. If it returns true, the children of that node are skipped.
`:new-editing-set-path`: append a an item with `:new?` at the given path" `:new-at-path`: append at the given path a node with `:is-new true` and a newly created set."
[tree & {:keys [skip-children-pred new-at-path] [tree & {:keys [skip-children-pred new-at-path]
:or {skip-children-pred (constantly false)}}] :or {skip-children-pred (constantly false)}}]
(let [walk (fn walk [[k v :as node] parent depth] (let [walk (fn walk [[k v :as node] parent-path depth]
(lazy-seq (lazy-seq
(cond (cond
;; New set ;; New set
(= :is-new k) (= :is-new k)
(let [tset (make-token-set :name (if (empty? parent) (let [token-set (make-token-set :name (if (empty? parent-path)
"" ""
(join-set-path parent)))] (join-set-path parent-path)))]
[{:is-new true [{:is-new true
:is-group false :is-group false
:id "" ; FIXME: This is a calculated id, used for the sets tree in the sidear :path (split-set-name (get-name token-set))
:parent-path parent ; It may be refactored now to use the actual :id :depth depth
:token-set tset :id (get-id token-set)
:depth depth}]) :token-set token-set}])
;; Set ;; Set
(and v (instance? TokenSet v)) (and v (instance? TokenSet v))
(let [name (get-name v)] [{:is-group false
[{:is-group false :path (split-set-name (get-name v))
:path (split-set-name name) :depth depth
:id name :id (get-id v)
:parent-path parent :token-set v}]
:depth depth
:token-set v}])
;; Set group ;; Set group
(and v (d/ordered-map? v)) (and v (d/ordered-map? v))
(let [unprefixed-path (last (split-set-str-path-prefix k)) (let [unprefixed-path (last (split-set-str-path-prefix k))
path (conj parent unprefixed-path) path (conj parent-path unprefixed-path)
item {:is-group true item {:is-group true
:path path :path path
:id (join-set-path path) :depth depth
:parent-path parent :id (join-set-path path)}]
:depth depth}]
(if (skip-children-pred path) (if (skip-children-pred path)
[item] [item]
@@ -982,31 +979,36 @@ Will return a value that matches this schema:
themes themes
active-themes))) active-themes)))
(update-set [this set-name f] (update-set [this id f]
(let [prefixed-full-path (set-name->prefixed-full-path set-name) (assert (uuid? id) "expected uuid for `id`")
set (get-in sets prefixed-full-path)] (let [set (get-set this id)
name (get-name set)
prefixed-full-path (set-name->prefixed-full-path name)]
(if set (if set
(let [set' (f set) (let [set' (f set)
prefixed-full-path' (get-set-prefixed-path set') name' (get-name set')
name-changed? (not= (get-name set) (get-name set'))] prefixed-full-path' (get-set-prefixed-path set')]
(if name-changed? (if (= name name')
(TokensLib. (d/oassoc-in sets prefixed-full-path set')
themes
active-themes)
(TokensLib. (-> sets (TokensLib. (-> sets
(d/oassoc-in-before prefixed-full-path prefixed-full-path' set') (d/oassoc-in-before prefixed-full-path prefixed-full-path' set')
(d/dissoc-in prefixed-full-path)) (d/dissoc-in prefixed-full-path))
(walk/postwalk (walk/postwalk
(fn [form] (fn [form]
(if (instance? TokenTheme form) (if (instance? TokenTheme form)
(update-set-name form (get-name set) (get-name set')) (update-set-name form name name')
form)) form))
themes) themes)
active-themes)
(TokensLib. (d/oassoc-in sets prefixed-full-path set')
themes
active-themes))) active-themes)))
this))) this)))
(delete-set [_ set-name] (delete-set [this id]
(let [prefixed-path (set-name->prefixed-full-path set-name)] (assert (uuid? id) "expected uuid for `id`")
(let [set (get-set this id)
set-name (get-name set)
prefixed-path (set-name->prefixed-full-path set-name)]
(TokensLib. (d/dissoc-in sets prefixed-path) (TokensLib. (d/dissoc-in sets prefixed-path)
(walk/postwalk (walk/postwalk
(fn [form] (fn [form]
@@ -1016,38 +1018,6 @@ Will return a value that matches this schema:
themes) themes)
active-themes))) active-themes)))
(delete-set-group [this set-group-name]
(let [path (split-set-name set-group-name)
prefixed-path (map add-set-group-prefix path)
child-set-names (->> (get-sets-at-path this path)
(map get-name)
(into #{}))]
(TokensLib. (d/dissoc-in sets prefixed-path)
(walk/postwalk
(fn [form]
(if (instance? TokenTheme form)
(disable-sets form child-set-names)
form))
themes)
active-themes)))
(delete-set-path [_ prefixed-set-name]
(let [prefixed-set-path (split-set-name prefixed-set-name)
set-node (get-in sets prefixed-set-path)
set-group? (not (instance? TokenSet set-node))
set-name-string (prefixed-set-path-string->set-name-string prefixed-set-name)]
(TokensLib. (d/dissoc-in sets prefixed-set-path)
;; TODO: When deleting a set-group, also deactivate the child sets
(if set-group?
themes
(walk/postwalk
(fn [form]
(if (instance? TokenTheme form)
(disable-set form set-name-string)
form))
themes))
active-themes)))
(move-set [_ from-path to-path before-path before-group?] (move-set [_ from-path to-path before-path before-group?]
(let [prefixed-from-path (set-full-path->set-prefixed-full-path from-path) (let [prefixed-from-path (set-full-path->set-prefixed-full-path from-path)
prev-set (get-in sets prefixed-from-path)] prev-set (get-in sets prefixed-from-path)]
@@ -1145,7 +1115,7 @@ Will return a value that matches this schema:
(->> (tree-seq d/ordered-map? vals sets) (->> (tree-seq d/ordered-map? vals sets)
(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-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))))
@@ -1163,8 +1133,8 @@ Will return a value that matches this schema:
sets (get-sets-at-path this path)] sets (get-sets-at-path this path)]
(reduce (reduce
(fn [lib set] (fn [lib set]
(update-set lib (get-name set) (fn [set'] (update-set lib (get-id set) (fn [set']
(rename set' (str to-path-str (str/strip-prefix (get-name set') from-path-str)))))) (rename set' (str to-path-str (str/strip-prefix (get-name set') from-path-str))))))
this sets))) this sets)))
(get-ordered-set-names [this] (get-ordered-set-names [this]
@@ -1174,10 +1144,12 @@ Will return a value that matches this schema:
(count (get-sets this))) (count (get-sets this)))
(get-set [this id] (get-set [this id]
(assert (uuid? id) "expected uuid for `id`")
(some #(when (= (get-id %) id) %) ;; TODO: this will be made in an efficient way when (some #(when (= (get-id %) id) %) ;; TODO: this will be made in an efficient way when
(get-sets this))) ;; we refactor the tokens lib internal structure (get-sets this))) ;; we refactor the tokens lib internal structure
(get-set-by-name [_ name] (get-set-by-name [_ name]
(assert (string? name) "expected string for `name`")
(let [path (set-name->prefixed-full-path name)] (let [path (set-name->prefixed-full-path name)]
(get-in sets path))) (get-in sets path)))
@@ -1290,8 +1262,8 @@ Will return a value that matches this schema:
(set-group-path-exists? [_ set-path] (set-group-path-exists? [_ set-path]
(some? (get-in sets (set-group-path->set-group-prefixed-path set-path)))) (some? (get-in sets (set-group-path->set-group-prefixed-path set-path))))
(add-token-in-set [this set-name token] (add-token-in-set [this set-id token]
(update-set this set-name #(add-token % token))) (update-set this set-id #(add-token % token)))
(get-token-in-set [this set-id token-id] (get-token-in-set [this set-id token-id]
(some-> this (some-> this
@@ -1303,11 +1275,11 @@ Will return a value that matches this schema:
(get-set set-id) (get-set set-id)
(get-token-by-name token-name))) (get-token-by-name token-name)))
(update-token-in-set [this set-name token-id f] (update-token-in-set [this set-id token-id f]
(update-set this set-name #(update-token % token-id f))) (update-set this set-id #(update-token % token-id f)))
(delete-token-from-set [this set-name token-id] (delete-token-from-set [this set-id token-id]
(update-set this set-name #(delete-token % token-id))) (update-set this set-id #(delete-token % token-id)))
(toggle-set-in-theme [this theme-group theme-name set-name] (toggle-set-in-theme [this theme-group theme-name set-name]
(if-let [_theme (get-in themes theme-group theme-name)] (if-let [_theme (get-in themes theme-group theme-name)]
@@ -1326,7 +1298,7 @@ Will return a value that matches this schema:
(let [active-set-names (get-active-themes-set-names this) (let [active-set-names (get-active-themes-set-names this)
prefixed-path-str (set-group-path->set-group-prefixed-path-str group-path)] prefixed-path-str (set-group-path->set-group-prefixed-path-str group-path)]
(if (seq active-set-names) (if (seq active-set-names)
(let [path-active-set-names (->> (get-sets-at-prefix-path this prefixed-path-str) (let [path-active-set-names (->> (get-sets-at-prefix-path- this prefixed-path-str)
(map get-name) (map get-name)
(into #{})) (into #{}))
difference (set/difference path-active-set-names active-set-names)] difference (set/difference path-active-set-names active-set-names)]

View File

@@ -14,7 +14,6 @@
[app.common.types.file :as ctf] [app.common.types.file :as ctf]
[app.common.types.shape :as cts] [app.common.types.shape :as cts]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[clojure.pprint :refer [pprint]]
[clojure.test :as t] [clojure.test :as t]
[common-tests.types.shape-decode-encode-test :refer [json-roundtrip]])) [common-tests.types.shape-decode-encode-test :refer [json-roundtrip]]))

View File

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

View File

@@ -171,13 +171,13 @@
file (setup-file #(-> % file (setup-file #(-> %
(ctob/add-set (ctob/make-token-set :id set-id (ctob/add-set (ctob/make-token-set :id set-id
:name set-name)) :name set-name))
(ctob/add-token-in-set set-name (ctob/make-token {:name "to.delete.color.red" (ctob/add-token-in-set set-id (ctob/make-token {:name "to.delete.color.red"
:id token-id :id token-id
:value "red" :value "red"
:type :color})))) :type :color}))))
changes (-> (pcb/empty-changes) changes (-> (pcb/empty-changes)
(pcb/with-library-data (:data file)) (pcb/with-library-data (:data file))
(pcb/set-token set-name token-id nil)) (pcb/set-token set-id token-id nil))
redo (thf/apply-changes file changes) redo (thf/apply-changes file changes)
redo-lib (tht/get-tokens-lib redo) redo-lib (tht/get-tokens-lib redo)
@@ -197,7 +197,7 @@
:name set-name)))) :name set-name))))
changes (-> (pcb/empty-changes) changes (-> (pcb/empty-changes)
(pcb/with-library-data (:data file)) (pcb/with-library-data (:data file))
(pcb/set-token set-name (:id token) token)) (pcb/set-token set-id (:id token) token))
redo (thf/apply-changes file changes) redo (thf/apply-changes file changes)
redo-lib (tht/get-tokens-lib redo) redo-lib (tht/get-tokens-lib redo)
@@ -219,10 +219,10 @@
file (setup-file #(-> % file (setup-file #(-> %
(ctob/add-set (ctob/make-token-set :id set-id (ctob/add-set (ctob/make-token-set :id set-id
:name set-name)) :name set-name))
(ctob/add-token-in-set set-name prev-token))) (ctob/add-token-in-set set-id prev-token)))
changes (-> (pcb/empty-changes) changes (-> (pcb/empty-changes)
(pcb/with-library-data (:data file)) (pcb/with-library-data (:data file))
(pcb/set-token set-name (:id prev-token) token)) (pcb/set-token set-id (:id prev-token) token))
redo (thf/apply-changes file changes) redo (thf/apply-changes file changes)
redo-lib (tht/get-tokens-lib redo) redo-lib (tht/get-tokens-lib redo)
@@ -239,7 +239,7 @@
file (setup-file #(ctob/add-set % (ctob/make-token-set :id set-id :name set-name))) file (setup-file #(ctob/add-set % (ctob/make-token-set :id set-id :name set-name)))
changes (-> (pcb/empty-changes) changes (-> (pcb/empty-changes)
(pcb/with-library-data (:data file)) (pcb/with-library-data (:data file))
(pcb/set-token-set set-id false nil)) (pcb/set-token-set set-id nil))
redo (thf/apply-changes file changes) redo (thf/apply-changes file changes)
redo-lib (tht/get-tokens-lib redo) redo-lib (tht/get-tokens-lib redo)
@@ -256,7 +256,7 @@
file (setup-file identity) file (setup-file identity)
changes (-> (pcb/empty-changes) changes (-> (pcb/empty-changes)
(pcb/with-library-data (:data file)) (pcb/with-library-data (:data file))
(pcb/set-token-set set-id false token-set)) (pcb/set-token-set set-id token-set))
redo (thf/apply-changes file changes) redo (thf/apply-changes file changes)
redo-lib (tht/get-tokens-lib redo) redo-lib (tht/get-tokens-lib redo)
@@ -275,7 +275,7 @@
changes (-> (pcb/empty-changes) changes (-> (pcb/empty-changes)
(pcb/with-library-data (:data file)) (pcb/with-library-data (:data file))
(pcb/set-token-set set-id false (ctob/rename token-set new-set-name))) (pcb/set-token-set set-id (ctob/rename token-set new-set-name)))
redo (thf/apply-changes file changes) redo (thf/apply-changes file changes)
redo-lib (tht/get-tokens-lib redo) redo-lib (tht/get-tokens-lib redo)

View File

@@ -256,10 +256,10 @@
:name "test-token-set"))) :name "test-token-set")))
tokens-lib' (-> tokens-lib tokens-lib' (-> tokens-lib
(ctob/update-set "test-token-set" (ctob/update-set (thi/id :test-token-set)
(fn [token-set] (fn [token-set]
(ctob/set-description token-set "some description"))) (ctob/set-description token-set "some description")))
(ctob/update-set "not-existing-set" (ctob/update-set (uuid/next)
(fn [token-set] (fn [token-set]
(ctob/set-description token-set "no-effect")))) (ctob/set-description token-set "no-effect"))))
@@ -277,7 +277,7 @@
:name "test-token-set"))) :name "test-token-set")))
tokens-lib' (-> tokens-lib tokens-lib' (-> tokens-lib
(ctob/update-set "test-token-set" (ctob/update-set (thi/id :test-token-set)
(fn [token-set] (fn [token-set]
(ctob/rename token-set "updated-name")))) (ctob/rename token-set "updated-name"))))
@@ -306,23 +306,6 @@
"foo/bar-renamed/baz-renamed/baz-child-2"))) "foo/bar-renamed/baz-renamed/baz-child-2")))
(t/is (= expected-theme-sets #{"foo/bar-renamed/baz-renamed/baz-child-1"})))) (t/is (= expected-theme-sets #{"foo/bar-renamed/baz-renamed/baz-child-1"}))))
(t/deftest delete-token-set
(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-theme (ctob/make-token-theme :name "test-token-theme" :sets #{"test-token-set"})))
tokens-lib' (-> tokens-lib
(ctob/delete-set-path "S-test-token-set")
(ctob/delete-set-path "S-not-existing-set"))
token-set' (ctob/get-set tokens-lib' (thi/id :test-token-set))
token-theme' (ctob/get-theme tokens-lib' "" "test-token-theme")]
(t/is (= (ctob/set-count tokens-lib') 0))
(t/is (= (:sets token-theme') #{}))
(t/is (nil? token-set'))))
(t/deftest duplicate-token-set (t/deftest duplicate-token-set
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
@@ -380,20 +363,6 @@
(t/is (nil? token-set-copy)))) (t/is (nil? token-set-copy))))
(t/deftest active-themes-set-names
(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")))
tokens-lib' (-> tokens-lib
(ctob/delete-set-path "S-test-token-set")
(ctob/delete-set-path "S-not-existing-set"))
token-set' (ctob/get-set tokens-lib' (thi/id :test-token-set))]
(t/is (= (ctob/set-count tokens-lib') 0))
(t/is (nil? token-set'))))
(t/deftest add-token (t/deftest add-token
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
@@ -403,8 +372,8 @@
:type :boolean :type :boolean
:value true) :value true)
tokens-lib' (-> tokens-lib tokens-lib' (-> tokens-lib
(ctob/add-token-in-set "test-token-set" token) (ctob/add-token-in-set (thi/id :test-token-set) token)
(ctob/add-token-in-set "not-existing-set" token)) (ctob/add-token-in-set (uuid/next) token))
token-set (ctob/get-set tokens-lib (thi/id :test-token-set)) token-set (ctob/get-set tokens-lib (thi/id :test-token-set))
token-set' (ctob/get-set tokens-lib' (thi/id :test-token-set)) token-set' (ctob/get-set tokens-lib' (thi/id :test-token-set))
@@ -419,28 +388,28 @@
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
:name "test-token-set")) :name "test-token-set"))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-1) (ctob/make-token :id (thi/new-id! :test-token-1)
:name "test-token-1" :name "test-token-1"
:type :boolean :type :boolean
:value true)) :value true))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-2) (ctob/make-token :id (thi/new-id! :test-token-2)
:name "test-token-2" :name "test-token-2"
:type :boolean :type :boolean
:value true))) :value true)))
tokens-lib' (-> tokens-lib tokens-lib' (-> tokens-lib
(ctob/update-token-in-set "test-token-set" (thi/id :test-token-1) (ctob/update-token-in-set (thi/id :test-token-set) (thi/id :test-token-1)
(fn [token] (fn [token]
(assoc token (assoc token
:description "some description" :description "some description"
:value false))) :value false)))
(ctob/update-token-in-set "not-existing-set" (thi/id :test-token-1) (ctob/update-token-in-set (uuid/next) (thi/id :test-token-1)
(fn [token] (fn [token]
(assoc token (assoc token
:name "no-effect"))) :name "no-effect")))
(ctob/update-token-in-set "test-token-set" (uuid/next) (ctob/update-token-in-set (thi/id :test-token-set) (uuid/next)
(fn [token] (fn [token]
(assoc token (assoc token
:name "no-effect")))) :name "no-effect"))))
@@ -463,19 +432,19 @@
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
:name "test-token-set")) :name "test-token-set"))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-1) (ctob/make-token :id (thi/new-id! :test-token-1)
:name "test-token-1" :name "test-token-1"
:type :boolean :type :boolean
:value true)) :value true))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-2) (ctob/make-token :id (thi/new-id! :test-token-2)
:name "test-token-2" :name "test-token-2"
:type :boolean :type :boolean
:value true))) :value true)))
tokens-lib' (-> tokens-lib tokens-lib' (-> tokens-lib
(ctob/update-token-in-set "test-token-set" (thi/id :test-token-1) (ctob/update-token-in-set (thi/id :test-token-set) (thi/id :test-token-1)
(fn [token] (fn [token]
(assoc token (assoc token
:name "updated-name")))) :name "updated-name"))))
@@ -498,15 +467,15 @@
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
:name "test-token-set")) :name "test-token-set"))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token) (ctob/make-token :id (thi/new-id! :test-token)
:name "test-token" :name "test-token"
:type :boolean :type :boolean
:value true))) :value true)))
tokens-lib' (-> tokens-lib tokens-lib' (-> tokens-lib
(ctob/delete-token-from-set "test-token-set" (thi/id :test-token)) (ctob/delete-token-from-set (thi/id :test-token-set) (thi/id :test-token))
(ctob/delete-token-from-set "not-existing-set" (thi/id :test-token)) (ctob/delete-token-from-set (uuid/next) (thi/id :test-token))
(ctob/delete-token-from-set "test-token-set" (uuid/next))) (ctob/delete-token-from-set (thi/id :test-token-set) (uuid/next)))
token-set (ctob/get-set tokens-lib (thi/id :test-token-set)) token-set (ctob/get-set tokens-lib (thi/id :test-token-set))
token-set' (ctob/get-set tokens-lib' (thi/id :test-token-set)) token-set' (ctob/get-set tokens-lib' (thi/id :test-token-set))
@@ -852,9 +821,10 @@
(t/deftest transit-serialization (t/deftest transit-serialization
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :name "test-token-set")) (ctob/add-set (ctob/make-token-set :name "test-token-set"))
(ctob/add-token-in-set "test-token-set" (ctob/make-token :name "test-token" (ctob/add-token-in-set (thi/id :test-token-set)
:type :boolean (ctob/make-token :name "test-token"
:value true)) :type :boolean
:value true))
(ctob/add-theme (ctob/make-token-theme :name "test-token-theme")) (ctob/add-theme (ctob/make-token-theme :name "test-token-theme"))
(ctob/toggle-set-in-theme "" "test-token-theme" "test-token-set")) (ctob/toggle-set-in-theme "" "test-token-theme" "test-token-set"))
encoded-str (tr/encode-str tokens-lib) encoded-str (tr/encode-str tokens-lib)
@@ -867,10 +837,12 @@
#?(:clj #?(:clj
(t/deftest fressian-serialization (t/deftest fressian-serialization
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :name "test-token-set")) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
(ctob/add-token-in-set "test-token-set" (ctob/make-token :name "test-token" :name "test-token-set"))
:type :boolean (ctob/add-token-in-set (thi/id :test-token-set)
:value true)) (ctob/make-token :name "test-token"
:type :boolean
:value true))
(ctob/add-theme (ctob/make-token-theme :name "test-token-theme")) (ctob/add-theme (ctob/make-token-theme :name "test-token-theme"))
(ctob/toggle-set-in-theme "" "test-token-theme" "test-token-set")) (ctob/toggle-set-in-theme "" "test-token-theme" "test-token-set"))
encoded-blob (fres/encode tokens-lib) encoded-blob (fres/encode tokens-lib)
@@ -900,23 +872,23 @@
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
:name "test-token-set")) :name "test-token-set"))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "token1" (ctob/make-token :name "token1"
:type :boolean :type :boolean
:value true)) :value true))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "group1.token2" (ctob/make-token :name "group1.token2"
:type :boolean :type :boolean
:value true)) :value true))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "group1.token3" (ctob/make-token :name "group1.token3"
:type :boolean :type :boolean
:value true)) :value true))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "group1.subgroup11.token4" (ctob/make-token :name "group1.subgroup11.token4"
:type :boolean :type :boolean
:value true)) :value true))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "group2.token5" (ctob/make-token :name "group2.token5"
:type :boolean :type :boolean
:value true))) :value true)))
@@ -935,24 +907,24 @@
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
:name "test-token-set")) :name "test-token-set"))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-1) (ctob/make-token :id (thi/new-id! :test-token-1)
:name "test-token-1" :name "test-token-1"
:type :boolean :type :boolean
:value true)) :value true))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-2) (ctob/make-token :id (thi/new-id! :test-token-2)
:name "group1.test-token-2" :name "group1.test-token-2"
:type :boolean :type :boolean
:value true)) :value true))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-3) (ctob/make-token :id (thi/new-id! :test-token-3)
:name "group1.test-token-3" :name "group1.test-token-3"
:type :boolean :type :boolean
:value true))) :value true)))
tokens-lib' (-> tokens-lib tokens-lib' (-> tokens-lib
(ctob/update-token-in-set "test-token-set" (thi/id :test-token-2) (ctob/update-token-in-set (thi/id :test-token-set) (thi/id :test-token-2)
(fn [token] (fn [token]
(assoc token (assoc token
:description "some description" :description "some description"
@@ -974,24 +946,24 @@
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
:name "test-token-set")) :name "test-token-set"))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-1) (ctob/make-token :id (thi/new-id! :test-token-1)
:name "test-token-1" :name "test-token-1"
:type :boolean :type :boolean
:value true)) :value true))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-2) (ctob/make-token :id (thi/new-id! :test-token-2)
:name "group1.test-token-2" :name "group1.test-token-2"
:type :boolean :type :boolean
:value true)) :value true))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-3) (ctob/make-token :id (thi/new-id! :test-token-3)
:name "group1.test-token-3" :name "group1.test-token-3"
:type :boolean :type :boolean
:value true))) :value true)))
tokens-lib' (-> tokens-lib tokens-lib' (-> tokens-lib
(ctob/update-token-in-set "test-token-set" (thi/id :test-token-2) (ctob/update-token-in-set (thi/id :test-token-set) (thi/id :test-token-2)
(fn [token] (fn [token]
(assoc token (assoc token
:name "group1.updated-name")))) :name "group1.updated-name"))))
@@ -1012,24 +984,24 @@
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
:name "test-token-set")) :name "test-token-set"))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-1) (ctob/make-token :id (thi/new-id! :test-token-1)
:name "test-token-1" :name "test-token-1"
:type :boolean :type :boolean
:value true)) :value true))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-2) (ctob/make-token :id (thi/new-id! :test-token-2)
:name "group1.test-token-2" :name "group1.test-token-2"
:type :boolean :type :boolean
:value true)) :value true))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-3) (ctob/make-token :id (thi/new-id! :test-token-3)
:name "group1.test-token-3" :name "group1.test-token-3"
:type :boolean :type :boolean
:value true))) :value true)))
tokens-lib' (-> tokens-lib tokens-lib' (-> tokens-lib
(ctob/update-token-in-set "test-token-set" (thi/id :test-token-2) (ctob/update-token-in-set (thi/id :test-token-set) (thi/id :test-token-2)
(fn [token] (fn [token]
(assoc token (assoc token
:name "group2.updated-name")))) :name "group2.updated-name"))))
@@ -1051,18 +1023,18 @@
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
:name "test-token-set")) :name "test-token-set"))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-1) (ctob/make-token :id (thi/new-id! :test-token-1)
:name "test-token-1" :name "test-token-1"
:type :boolean :type :boolean
:value true)) :value true))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :id (thi/new-id! :test-token-2) (ctob/make-token :id (thi/new-id! :test-token-2)
:name "group1.test-token-2" :name "group1.test-token-2"
:type :boolean :type :boolean
:value true))) :value true)))
tokens-lib' (-> tokens-lib tokens-lib' (-> tokens-lib
(ctob/delete-token-from-set "test-token-set" (thi/id :test-token-2))) (ctob/delete-token-from-set (thi/id :test-token-set) (thi/id :test-token-2)))
token-set (ctob/get-set tokens-lib (thi/id :test-token-set)) token-set (ctob/get-set tokens-lib (thi/id :test-token-set))
token-set' (ctob/get-set tokens-lib' (thi/id :test-token-set)) token-set' (ctob/get-set tokens-lib' (thi/id :test-token-set))
@@ -1075,14 +1047,19 @@
(t/deftest update-token-set-in-groups (t/deftest update-token-set-in-groups
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :name "token-set-1")) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :token-set-1)
(ctob/add-set (ctob/make-token-set :name "group1/token-set-2")) :name "token-set-1"))
(ctob/add-set (ctob/make-token-set :name "group1/token-set-3")) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :token-set-2)
(ctob/add-set (ctob/make-token-set :name "group1/subgroup11/token-set-4")) :name "group1/token-set-2"))
(ctob/add-set (ctob/make-token-set :name "group2/token-set-5"))) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :token-set-3)
:name "group1/token-set-3"))
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :token-set-4)
:name "group1/subgroup11/token-set-4"))
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :token-set-5)
:name "group2/token-set-5")))
tokens-lib' (-> tokens-lib tokens-lib' (-> tokens-lib
(ctob/update-set "group1/token-set-2" (ctob/update-set (thi/id :token-set-2)
(fn [token-set] (fn [token-set]
(ctob/set-description token-set "some description")))) (ctob/set-description token-set "some description"))))
@@ -1101,14 +1078,19 @@
(t/deftest rename-token-set-in-groups (t/deftest rename-token-set-in-groups
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :name "token-set-1")) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :token-set-1)
(ctob/add-set (ctob/make-token-set :name "group1/token-set-2")) :name "token-set-1"))
(ctob/add-set (ctob/make-token-set :name "group1/token-set-3")) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :token-set-2)
(ctob/add-set (ctob/make-token-set :name "group1/subgroup11/token-set-4")) :name "group1/token-set-2"))
(ctob/add-set (ctob/make-token-set :name "group2/token-set-5"))) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :token-set-3)
:name "group1/token-set-3"))
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :token-set-4)
:name "group1/subgroup11/token-set-4"))
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :token-set-5)
:name "group2/token-set-5")))
tokens-lib' (-> tokens-lib tokens-lib' (-> tokens-lib
(ctob/update-set "group1/token-set-2" (ctob/update-set (thi/id :token-set-2)
(fn [token-set] (fn [token-set]
(ctob/rename token-set "group1/updated-name")))) (ctob/rename token-set "group1/updated-name"))))
@@ -1127,14 +1109,19 @@
(t/deftest move-token-set-of-group (t/deftest move-token-set-of-group
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :name "token-set-1")) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :token-set-1)
(ctob/add-set (ctob/make-token-set :name "group1/token-set-2")) :name "token-set-1"))
(ctob/add-set (ctob/make-token-set :name "group1/token-set-3")) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :token-set-2)
(ctob/add-set (ctob/make-token-set :name "group1/subgroup11/token-set-4")) :name "group1/token-set-2"))
#_(ctob/add-set (ctob/make-token-set :name "group2/token-set-5"))) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :token-set-3)
:name "group1/token-set-3"))
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :token-set-4)
:name "group1/subgroup11/token-set-4"))
#_(ctob/add-set (ctob/make-token-set :id (thi/new-id! :token-set-5)
:name "group2/token-set-5")))
tokens-lib' (-> tokens-lib tokens-lib' (-> tokens-lib
(ctob/update-set "group1/token-set-2" (ctob/update-set (thi/id :token-set-2)
(fn [token-set] (fn [token-set]
(ctob/rename token-set "group2/updated-name")))) (ctob/rename token-set "group2/updated-name"))))
@@ -1155,11 +1142,13 @@
(t/deftest delete-token-set-in-group (t/deftest delete-token-set-in-group
(let [tokens-lib (-> (ctob/make-tokens-lib) (let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :name "token-set-1")) (ctob/add-set (ctob/make-token-set :id (thi/new-id! :token-set-1)
(ctob/add-set (ctob/make-token-set :name "group1/token-set-2"))) :name "token-set-1"))
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :token-set-2)
:name "group1/token-set-2")))
tokens-lib' (-> tokens-lib tokens-lib' (-> tokens-lib
(ctob/delete-set-path "G-group1/S-token-set-2")) (ctob/delete-set (thi/id :token-set-2)))
sets-tree' (ctob/get-set-tree tokens-lib') sets-tree' (ctob/get-set-tree tokens-lib')
token-set' (get-in sets-tree' ["group1" "token-set-2"])] token-set' (get-in sets-tree' ["group1" "token-set-2"])]

View File

@@ -24,7 +24,6 @@
[beicon.v2.core :as rx] [beicon.v2.core :as rx]
[potok.v2.core :as ptk])) [potok.v2.core :as ptk]))
(declare set-selected-token-set-name)
(declare set-selected-token-set-id) (declare set-selected-token-set-id)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -110,9 +109,9 @@
(ptk/reify ::toggle-token-theme-active? (ptk/reify ::toggle-token-theme-active?
ptk/WatchEvent ptk/WatchEvent
(watch [it state _] (watch [it state _]
(let [tokens-lib (get-tokens-lib state) (let [data (dsh/lookup-file-data state)
prev-active-token-themes (some-> tokens-lib
(ctob/get-active-theme-paths)) tokens-lib (get-tokens-lib state)
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))
@@ -120,7 +119,8 @@
active-token-themes active-token-themes
(disj active-token-themes ctob/hidden-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/with-library-data data)
(pcb/update-active-token-themes active-token-themes'))]
(rx/of (rx/of
(dch/commit-changes changes) (dch/commit-changes changes)
(dwtp/propagate-workspace-tokens)))))) (dwtp/propagate-workspace-tokens))))))
@@ -158,9 +158,8 @@
(let [token-set (ctob/make-token-set :name set-name) (let [token-set (ctob/make-token-set :name set-name)
changes (-> (pcb/empty-changes it) changes (-> (pcb/empty-changes it)
(pcb/with-library-data data) (pcb/with-library-data data)
(pcb/set-token-set (ctob/get-id token-set) false token-set))] (pcb/set-token-set (ctob/get-id token-set) token-set))]
(rx/of (set-selected-token-set-name set-name) (rx/of (set-selected-token-set-id (ctob/get-id token-set))
(set-selected-token-set-id (ctob/get-id token-set))
(dch/commit-changes changes)))))))) (dch/commit-changes changes))))))))
(defn rename-token-set-group [set-group-path set-group-fname] (defn rename-token-set-group [set-group-path set-group-fname]
@@ -189,12 +188,11 @@
(let [changes (-> (pcb/empty-changes it) (let [changes (-> (pcb/empty-changes it)
(pcb/with-library-data data) (pcb/with-library-data data)
(pcb/rename-token-set (ctob/get-id token-set) name))] (pcb/rename-token-set (ctob/get-id token-set) name))]
(rx/of (set-selected-token-set-name name) (rx/of (set-selected-token-set-id (ctob/get-id token-set))
(set-selected-token-set-id (ctob/get-id token-set))
(dch/commit-changes changes)))))))) (dch/commit-changes changes))))))))
(defn duplicate-token-set (defn duplicate-token-set
[id is-group] [id]
(ptk/reify ::duplicate-token-set (ptk/reify ::duplicate-token-set
ptk/WatchEvent ptk/WatchEvent
(watch [it state _] (watch [it state _]
@@ -205,9 +203,8 @@
(when-let [token-set (ctob/duplicate-set id tokens-lib {:suffix suffix})] (when-let [token-set (ctob/duplicate-set id tokens-lib {:suffix suffix})]
(let [changes (-> (pcb/empty-changes it) (let [changes (-> (pcb/empty-changes it)
(pcb/with-library-data data) (pcb/with-library-data data)
(pcb/set-token-set (ctob/get-id token-set) is-group token-set))] (pcb/set-token-set (ctob/get-id token-set) token-set))]
(rx/of (set-selected-token-set-name (ctob/get-name token-set)) (rx/of (set-selected-token-set-id (ctob/get-id token-set))
(set-selected-token-set-id (ctob/get-id token-set))
(dch/commit-changes changes)))))))) (dch/commit-changes changes))))))))
(defn toggle-token-set (defn toggle-token-set
@@ -248,16 +245,27 @@
(rx/of (dch/commit-changes changes) (rx/of (dch/commit-changes changes)
(dwtp/propagate-workspace-tokens)))))) (dwtp/propagate-workspace-tokens))))))
(defn delete-token-set-path (defn delete-token-set
[group? path] [id]
(ptk/reify ::delete-token-set-path (ptk/reify ::delete-token-set
ptk/WatchEvent ptk/WatchEvent
(watch [it state _] (watch [it state _]
(prn "path" path)
(let [data (dsh/lookup-file-data state) (let [data (dsh/lookup-file-data state)
changes (-> (pcb/empty-changes it) changes (-> (pcb/empty-changes it)
(pcb/with-library-data data) (pcb/with-library-data data)
(pcb/set-token-set (ctob/join-set-path path) group? nil))] (pcb/set-token-set id nil))]
(rx/of (dch/commit-changes changes)
(dwtp/propagate-workspace-tokens))))))
(defn delete-token-set-group
[path]
(ptk/reify ::delete-token-set-group
ptk/WatchEvent
(watch [it state _]
(let [data (dsh/lookup-file-data state)
changes (-> (pcb/empty-changes it)
(pcb/with-library-data data)
(clt/generate-delete-token-set-group (get-tokens-lib state) path))]
(rx/of (dch/commit-changes changes) (rx/of (dch/commit-changes changes)
(dwtp/propagate-workspace-tokens)))))) (dwtp/propagate-workspace-tokens))))))
@@ -332,13 +340,12 @@
changes changes
(-> (pcb/empty-changes) (-> (pcb/empty-changes)
(pcb/with-library-data data) (pcb/with-library-data data)
(pcb/set-token-set set-name false token-set) (pcb/set-token-set set-name token-set)
(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-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-id (ctob/get-id token-set))))))) (set-selected-token-set-id (ctob/get-id token-set)))))))
(defn create-token (defn create-token
@@ -352,7 +359,7 @@
token-type (:type token) token-type (:type token)
changes (-> (pcb/empty-changes it) changes (-> (pcb/empty-changes it)
(pcb/with-library-data data) (pcb/with-library-data data)
(pcb/set-token (ctob/get-name token-set) (pcb/set-token (ctob/get-id token-set)
(:id token) (:id token)
token))] token))]
@@ -377,15 +384,15 @@
token-type (:type token) token-type (:type token)
changes (-> (pcb/empty-changes it) changes (-> (pcb/empty-changes it)
(pcb/with-library-data data) (pcb/with-library-data data)
(pcb/set-token (ctob/get-name token-set) (pcb/set-token (ctob/get-id token-set)
id id
token'))] token'))]
(rx/of (dch/commit-changes changes) (rx/of (dch/commit-changes changes)
(ptk/data-event ::ev/event {::ev/name "edit-token" :type token-type})))))) (ptk/data-event ::ev/event {::ev/name "edit-token" :type token-type}))))))
(defn delete-token (defn delete-token
[set-name token-id] [set-id token-id]
(dm/assert! (string? set-name)) (dm/assert! (uuid? set-id))
(dm/assert! (uuid? token-id)) (dm/assert! (uuid? token-id))
(ptk/reify ::delete-token (ptk/reify ::delete-token
ptk/WatchEvent ptk/WatchEvent
@@ -393,7 +400,7 @@
(let [data (dsh/lookup-file-data state) (let [data (dsh/lookup-file-data state)
changes (-> (pcb/empty-changes it) changes (-> (pcb/empty-changes it)
(pcb/with-library-data data) (pcb/with-library-data data)
(pcb/set-token set-name token-id nil))] (pcb/set-token set-id token-id nil))]
(rx/of (dch/commit-changes changes)))))) (rx/of (dch/commit-changes changes))))))
(defn duplicate-token (defn duplicate-token
@@ -453,13 +460,6 @@
(update state :workspace-tokens assoc :token-set-context-menu params) (update state :workspace-tokens assoc :token-set-context-menu params)
(update state :workspace-tokens dissoc :token-set-context-menu))))) (update state :workspace-tokens dissoc :token-set-context-menu)))))
(defn set-selected-token-set-name ;; TODO: remove this when all functions use set-id
[name]
(ptk/reify ::set-selected-token-set-name
ptk/UpdateEvent
(update [_ state]
(update state :workspace-tokens assoc :selected-token-set-name name))))
(defn set-selected-token-set-id (defn set-selected-token-set-id
[id] [id]
(ptk/reify ::set-selected-token-set-id (ptk/reify ::set-selected-token-set-id
@@ -469,7 +469,8 @@
(defn start-token-set-edition (defn start-token-set-edition
[edition-id] [edition-id]
(assert (string? edition-id) "expected a string for `edition-id`") ;; Path string for edition of a group, UUID for edition of a set.
(assert (or (string? edition-id) (uuid? edition-id)) "expected a string or uuid for `edition-id`")
(ptk/reify ::start-token-set-edition (ptk/reify ::start-token-set-edition
ptk/UpdateEvent ptk/UpdateEvent

View File

@@ -459,9 +459,6 @@
(def workspace-token-themes-no-hidden (def workspace-token-themes-no-hidden
(l/derived #(remove ctob/hidden-theme? %) workspace-token-themes)) (l/derived #(remove ctob/hidden-theme? %) workspace-token-themes))
(def selected-token-set-name ;; FIXME: remove this when all functions use set-id
(l/derived (l/key :selected-token-set-name) workspace-tokens))
(def selected-token-set-id (def selected-token-set-id
(l/derived (l/key :selected-token-set-id) workspace-tokens)) (l/derived (l/key :selected-token-set-id) workspace-tokens))

View File

@@ -115,8 +115,7 @@
(mf/with-memo [tokens-by-type] (mf/with-memo [tokens-by-type]
(get-sorted-token-groups tokens-by-type))] (get-sorted-token-groups tokens-by-type))]
;; (mf/with-effect [tokens-lib selected-token-set-id] (mf/with-effect [tokens-lib selected-token-set-id]
(mf/with-effect []
(when (and tokens-lib (when (and tokens-lib
(or (nil? selected-token-set-id) (or (nil? selected-token-set-id)
(and selected-token-set-id (and selected-token-set-id
@@ -124,8 +123,7 @@
(let [match (->> (ctob/get-sets tokens-lib) (let [match (->> (ctob/get-sets tokens-lib)
(first))] (first))]
(when match (when match
(st/emit! (dwtl/set-selected-token-set-name (ctob/get-name match)) (st/emit! (dwtl/set-selected-token-set-id (ctob/get-id match)))))))
(dwtl/set-selected-token-set-id (ctob/get-id match)))))))
[:* [:*
[:& token-context-menu] [:& token-context-menu]

View File

@@ -12,7 +12,6 @@
[app.common.files.tokens :as cft] [app.common.files.tokens :as cft]
[app.common.types.shape.layout :as ctsl] [app.common.types.shape.layout :as ctsl]
[app.common.types.token :as ctt] [app.common.types.token :as ctt]
[app.common.types.tokens-lib :as ctob]
[app.main.data.modal :as modal] [app.main.data.modal :as modal]
[app.main.data.workspace.shape-layout :as dwsl] [app.main.data.workspace.shape-layout :as dwsl]
[app.main.data.workspace.tokens.application :as dwta] [app.main.data.workspace.tokens.application :as dwta]
@@ -318,7 +317,7 @@
(generic-attribute-actions #{:y} "Y" (assoc context-data :on-update-shape dwta/update-shape-position))) (generic-attribute-actions #{:y} "Y" (assoc context-data :on-update-shape dwta/update-shape-position)))
(clean-separators)))})) (clean-separators)))}))
(defn default-actions [{:keys [token selected-token-set-name]}] (defn default-actions [{:keys [token selected-token-set-id]}]
(let [{:keys [modal]} (dwta/get-token-properties token)] (let [{:keys [modal]} (dwta/get-token-properties token)]
[{:title (tr "workspace.tokens.edit") [{:title (tr "workspace.tokens.edit")
:no-selectable true :no-selectable true
@@ -331,7 +330,7 @@
:position :right :position :right
:fields fields :fields fields
:action "edit" :action "edit"
:selected-token-set-name selected-token-set-name :selected-token-set-id selected-token-set-id
:token token}))))} :token token}))))}
{:title (tr "workspace.tokens.duplicate") {:title (tr "workspace.tokens.duplicate")
:no-selectable true :no-selectable true
@@ -339,7 +338,7 @@
{:title (tr "workspace.tokens.delete") {:title (tr "workspace.tokens.delete")
:no-selectable true :no-selectable true
:action #(st/emit! (dwtl/delete-token :action #(st/emit! (dwtl/delete-token
(ctob/prefixed-set-path-string->set-name-string selected-token-set-name) selected-token-set-id
(:id token)))}])) (:id token)))}]))
(defn- allowed-shape-attributes [shapes] (defn- allowed-shape-attributes [shapes]
@@ -472,7 +471,7 @@
token-id (:token-id mdata) token-id (:token-id mdata)
token (mf/deref (refs/workspace-token-in-selected-set token-id)) token (mf/deref (refs/workspace-token-in-selected-set token-id))
token-type (:type token) token-type (:type token)
selected-token-set-name (mf/deref refs/selected-token-set-name) selected-token-set-id (mf/deref refs/selected-token-set-id)
selected-shapes selected-shapes
(mf/with-memo [selected objects] (mf/with-memo [selected objects]
@@ -487,7 +486,7 @@
[:& menu-tree {:submenu-offset width [:& menu-tree {:submenu-offset width
:token token :token token
:errors errors :errors errors
:selected-token-set-name selected-token-set-name :selected-token-set-id selected-token-set-id
:selected-shapes selected-shapes :selected-shapes selected-shapes
:is-selected-inside-layout is-selected-inside-layout}]])) :is-selected-inside-layout is-selected-inside-layout}]]))

View File

@@ -279,7 +279,7 @@ custom-input-token-value: Custom component for editing/displaying the token valu
custom-input-token-value-props: Custom props passed to the custom-input-token-value merged with the default props" custom-input-token-value-props: Custom props passed to the custom-input-token-value merged with the default props"
[{:keys [token [{:keys [token
token-type token-type
selected-token-set-name selected-token-set-id
action action
input-value-placeholder input-value-placeholder
@@ -493,13 +493,11 @@ custom-input-token-value-props: Custom props passed to the custom-input-token-va
on-delete-token on-delete-token
(mf/use-fn (mf/use-fn
(mf/deps selected-token-set-name) (mf/deps selected-token-set-id)
(fn [e] (fn [e]
(dom/prevent-default e) (dom/prevent-default e)
(modal/hide!) (modal/hide!)
(st/emit! (dwtl/delete-token (st/emit! (dwtl/delete-token selected-token-set-id (:id token)))))
(ctob/prefixed-set-path-string->set-name-string selected-token-set-name)
(:id token)))))
on-cancel on-cancel
(mf/use-fn (mf/use-fn

View File

@@ -68,7 +68,7 @@
(mf/defc token-update-create-modal (mf/defc token-update-create-modal
{::mf/wrap-props false} {::mf/wrap-props false}
[{:keys [x y position token token-type action selected-token-set-name] :as _args}] [{:keys [x y position token token-type action selected-token-set-id] :as _args}]
(let [wrapper-style (use-viewport-position-style x y position (= token-type :color)) (let [wrapper-style (use-viewport-position-style x y position (= token-type :color))
modal-size-large* (mf/use-state (= token-type :typography)) modal-size-large* (mf/use-state (= token-type :typography))
modal-size-large? (deref modal-size-large*) modal-size-large? (deref modal-size-large*)
@@ -90,7 +90,7 @@
:aria-label (tr "labels.close")}] :aria-label (tr "labels.close")}]
[:> form-wrapper* {:token token [:> form-wrapper* {:token token
:action action :action action
:selected-token-set-name selected-token-set-name :selected-token-set-id selected-token-set-id
:token-type token-type :token-type token-type
:on-display-colorpicker update-modal-size}]])) :on-display-colorpicker update-modal-size}]]))

View File

@@ -15,9 +15,8 @@
[app.main.ui.workspace.tokens.sets.lists :refer [controlled-sets-list*]] [app.main.ui.workspace.tokens.sets.lists :refer [controlled-sets-list*]]
[rumext.v2 :as mf])) [rumext.v2 :as mf]))
(defn- on-select-token-set-click [id name] (defn- on-select-token-set-click [id]
(st/emit! (dwtl/set-selected-token-set-id id) (st/emit! (dwtl/set-selected-token-set-id id)))
(dwtl/set-selected-token-set-name name)))
(defn- on-toggle-token-set-click [name] (defn- on-toggle-token-set-click [name]
(st/emit! (dwtl/toggle-token-set name))) (st/emit! (dwtl/toggle-token-set name)))

View File

@@ -34,7 +34,7 @@
(mf/defc menu* (mf/defc menu*
{::mf/private true} {::mf/private true}
[{:keys [is-group id edition-id path]}] [{:keys [is-group id path]}]
(let [create-set-at-path (let [create-set-at-path
(mf/use-fn (mf/deps path) #(st/emit! (dwtl/start-token-set-creation path))) (mf/use-fn (mf/deps path) #(st/emit! (dwtl/start-token-set-creation path)))
@@ -42,18 +42,20 @@
(mf/use-fn (mf/use-fn
(mf/deps id) (mf/deps id)
(fn [] (fn []
(st/emit! (dwtl/start-token-set-edition edition-id)))) (st/emit! (dwtl/start-token-set-edition id))))
on-duplicate on-duplicate
(mf/use-fn (mf/use-fn
(mf/deps is-group id) (mf/deps is-group id)
(fn [] (fn []
(st/emit! (dwtl/duplicate-token-set id is-group)))) (st/emit! (dwtl/duplicate-token-set id))))
on-delete on-delete
(mf/use-fn (mf/use-fn
(mf/deps is-group path) (mf/deps is-group path)
#(st/emit! (dwtl/delete-token-set-path is-group path)))] (if is-group
#(st/emit! (dwtl/delete-token-set-group path))
#(st/emit! (dwtl/delete-token-set id))))]
[:ul {:class (stl/css :context-list)} [:ul {:class (stl/css :context-list)}
(when is-group (when is-group
@@ -65,7 +67,7 @@
(mf/defc token-set-context-menu* (mf/defc token-set-context-menu*
[] []
(let [{:keys [position is-group id edition-id path]} (let [{:keys [position is-group id path]}
(mf/deref ref:token-sets-context-menu) (mf/deref ref:token-sets-context-menu)
position-top position-top
@@ -86,5 +88,4 @@
:on-context-menu prevent-default} :on-context-menu prevent-default}
[:> menu* {:is-group is-group [:> menu* {:is-group is-group
:id id :id id
:edition-id edition-id
:path path}]]])) :path path}]]]))

View File

@@ -32,5 +32,3 @@
(st/emit! (ptk/data-event ::ev/event {::ev/name "create-token-set" :name name}) (st/emit! (ptk/data-event ::ev/event {::ev/name "create-token-set" :name name})
(dwtl/create-token-set name)))) (dwtl/create-token-set name))))

View File

@@ -30,12 +30,6 @@
[] []
(st/emit! (dwtl/start-token-set-creation []))) (st/emit! (dwtl/start-token-set-creation [])))
(defn- group-edition-id
"Prefix editing groups `edition-id` so it can be differentiated from sets with the same id."
[edition-id]
(str "group-" edition-id))
(mf/defc editing-label* (mf/defc editing-label*
{::mf/private true} {::mf/private true}
[{:keys [default-value on-cancel on-submit]}] [{:keys [default-value on-cancel on-submit]}]
@@ -113,8 +107,8 @@
(mf/defc sets-tree-set-group* (mf/defc sets-tree-set-group*
{::mf/private true} {::mf/private true}
[{:keys [id label tree-depth tree-path is-active is-selected is-draggable is-collapsed tree-index on-drop [{:keys [id label is-editing is-active is-selected is-draggable is-collapsed path depth index
on-toggle-collapse on-toggle is-editing on-start-edition on-reset-edition on-edit-submit]}] on-toggle on-drop on-start-edition on-reset-edition on-edit-submit on-toggle-collapse]}]
(let [can-edit? (let [can-edit?
(mf/use-ctx ctx/can-edit?) (mf/use-ctx ctx/can-edit?)
@@ -124,7 +118,7 @@
on-context-menu on-context-menu
(mf/use-fn (mf/use-fn
(mf/deps is-editing id tree-path can-edit?) (mf/deps is-editing id path can-edit?)
(fn [event] (fn [event]
(dom/prevent-default event) (dom/prevent-default event)
(dom/stop-propagation event) (dom/stop-propagation event)
@@ -133,47 +127,46 @@
{:position (dom/get-client-position event) {:position (dom/get-client-position event)
:is-group true :is-group true
:id id :id id
:edition-id (group-edition-id id) :path path})))))
:path tree-path})))))
on-collapse-click on-collapse-click
(mf/use-fn (mf/use-fn
(fn [event] (fn [event]
(dom/prevent-default event) (dom/prevent-default event)
(dom/stop-propagation event) (dom/stop-propagation event)
(on-toggle-collapse tree-path))) (on-toggle-collapse path)))
on-double-click on-double-click
(mf/use-fn (mf/deps id) #(on-start-edition (group-edition-id id))) (mf/use-fn (mf/deps id) #(on-start-edition id))
on-checkbox-click on-checkbox-click
(mf/use-fn (mf/use-fn
(mf/deps on-toggle tree-path can-edit?) (mf/deps on-toggle path can-edit?)
#(on-toggle tree-path)) #(on-toggle path))
on-edit-submit' on-edit-submit'
(mf/use-fn (mf/use-fn
(mf/deps tree-path on-edit-submit can-edit?) (mf/deps path on-edit-submit can-edit?)
#(on-edit-submit tree-path %)) #(on-edit-submit path %))
on-drop on-drop
(mf/use-fn (mf/use-fn
(mf/deps tree-index on-drop) (mf/deps index on-drop)
(fn [position data] (fn [position data]
(on-drop tree-index position data))) (on-drop index position data)))
[dprops dref] [dprops dref]
(h/use-sortable (h/use-sortable
:data-type "penpot/token-set" :data-type "penpot/token-set"
:on-drop on-drop :on-drop on-drop
:data {:index tree-index :data {:index index
:is-group true} :is-group true}
:detect-center? true :detect-center? true
:draggable? is-draggable)] :draggable? is-draggable)]
[:div {:ref dref [:div {:ref dref
:data-testid "tokens-set-group-item" :data-testid "tokens-set-group-item"
:style {"--tree-depth" tree-depth} :style {"--tree-depth" depth}
:class (stl/css-case :set-item-container true :class (stl/css-case :set-item-container true
:set-item-group true :set-item-group true
:selected-set is-selected :selected-set is-selected
@@ -211,25 +204,23 @@
:arial-label (tr "workspace.tokens.select-set")}]])])) :arial-label (tr "workspace.tokens.select-set")}]])]))
(mf/defc sets-tree-set* (mf/defc sets-tree-set*
[{:keys [id set label tree-depth tree-path tree-index is-selected is-active is-draggable is-editing [{:keys [id set label is-editing is-active is-selected is-draggable is-new path depth index
on-select on-drop on-toggle on-start-edition on-reset-edition on-edit-submit is-new]}] on-select on-toggle on-drop on-start-edition on-reset-edition on-edit-submit]}]
(let [set-id (ctob/get-id set) (let [can-edit? (mf/use-ctx ctx/can-edit?)
set-name (ctob/get-name set)
can-edit? (mf/use-ctx ctx/can-edit?)
on-click on-click
(mf/use-fn (mf/use-fn
(mf/deps is-editing tree-path) (mf/deps is-editing on-select id)
(fn [event] (fn [event]
(dom/stop-propagation event) (dom/stop-propagation event)
(when-not is-editing (when-not is-editing
(when (fn? on-select) (when (fn? on-select)
(on-select set-id set-name))))) (on-select id)))))
on-context-menu on-context-menu
(mf/use-fn (mf/use-fn
(mf/deps is-editing id tree-path can-edit?) (mf/deps is-editing id path can-edit?)
(fn [event] (fn [event]
(dom/prevent-default event) (dom/prevent-default event)
(dom/stop-propagation event) (dom/stop-propagation event)
@@ -238,8 +229,7 @@
{:position (dom/get-client-position event) {:position (dom/get-client-position event)
:is-group false :is-group false
:id id :id id
:edition-id id :path path})))))
:path tree-path})))))
on-double-click on-double-click
(mf/use-fn (mf/use-fn
@@ -250,11 +240,11 @@
on-checkbox-click on-checkbox-click
(mf/use-fn (mf/use-fn
(mf/deps set-name on-toggle) (mf/deps id on-toggle)
(fn [event] (fn [event]
(dom/stop-propagation event) (dom/stop-propagation event)
(when (fn? on-toggle) (when (fn? on-toggle)
(on-toggle set-name)))) (on-toggle (ctob/get-name set)))))
on-edit-submit' on-edit-submit'
(mf/use-fn (mf/use-fn
@@ -263,23 +253,23 @@
on-drag on-drag
(mf/use-fn (mf/use-fn
(mf/deps tree-path) (mf/deps path)
(fn [_] (fn [_]
(when-not is-selected (when-not is-selected
(on-select tree-path)))) (on-select path))))
on-drop on-drop
(mf/use-fn (mf/use-fn
(mf/deps tree-index on-drop) (mf/deps index on-drop)
(fn [position data] (fn [position data]
(on-drop tree-index position data))) (on-drop index position data)))
[dprops dref] [dprops dref]
(h/use-sortable (h/use-sortable
:data-type "penpot/token-set" :data-type "penpot/token-set"
:on-drag on-drag :on-drag on-drag
:on-drop on-drop :on-drop on-drop
:data {:index tree-index :data {:index index
:is-group false} :is-group false}
:draggable? is-draggable) :draggable? is-draggable)
@@ -290,7 +280,7 @@
:role "button" :role "button"
:data-testid "tokens-set-item" :data-testid "tokens-set-item"
:id (str "token-set-item-" (str/join "/" tree-path)) :id (str "token-set-item-" (str/join "/" tree-path))
:style {"--tree-depth" tree-depth} :style {"--tree-depth" depth}
:class (stl/css-case :set-item-container true :class (stl/css-case :set-item-container true
:selected-set is-selected :selected-set is-selected
:dnd-over (= drop-over :center) :dnd-over (= drop-over :center)
@@ -304,7 +294,7 @@
[:> icon* [:> icon*
{:icon-id i/document {:icon-id i/document
:class (stl/css-case :icon true :class (stl/css-case :icon true
:root-icon (not tree-depth))}] :root-icon (not depth))}]
(if is-editing (if is-editing
[:> editing-label* [:> editing-label*
{:default-value label {:default-value label
@@ -346,9 +336,9 @@
on-drop on-drop
(mf/use-fn (mf/use-fn
(mf/deps collapsed-paths) (mf/deps collapsed-paths)
(fn [tree-index position data] (fn [index position data]
(let [params {:from-index (:index data) (let [params {:from-index (:index data)
:to-index tree-index :to-index index
:position position :position position
:collapsed-paths collapsed-paths}] :collapsed-paths collapsed-paths}]
(if (:is-group data) (if (:is-group data)
@@ -372,76 +362,76 @@
(fn [] (fn []
(rx/dispose! sub)))) (rx/dispose! sub))))
(for [{:keys [id token-set index is-new is-group path parent-path depth] :as node} (for [{:keys [token-set id index is-new is-group path parent-path depth] :as node}
(ctob/sets-tree-seq token-sets (ctob/sets-tree-seq token-sets
{:skip-children-pred collapsed? {:skip-children-pred collapsed?
:new-at-path new-path})] :new-at-path new-path})]
(cond (do
^boolean is-group (cond
[:> sets-tree-set-group* ^boolean is-group
{:key index [:> sets-tree-set-group*
:label (peek path) {:key index
:id id :id id
:is-active (is-token-set-group-active path) :label (peek path)
:is-selected false :is-editing (= edition-id id)
:is-draggable is-draggable :is-active (is-token-set-group-active path)
:is-editing (= edition-id (group-edition-id id)) :is-selected false
:is-collapsed (collapsed? path) :is-draggable is-draggable
:on-select on-select :is-collapsed (collapsed? path)
:tree-path path :path path
:tree-depth depth :depth depth
:tree-index index :index index
:tree-parent-path parent-path
:on-drop on-drop :on-toggle on-toggle-set-group
:on-start-edition on-start-edition :on-drop on-drop
:on-reset-edition on-reset-edition :on-start-edition on-start-edition
:on-edit-submit on-edit-submit-group :on-reset-edition on-reset-edition
:on-toggle-collapse on-toggle-collapse :on-edit-submit on-edit-submit-group
:on-toggle on-toggle-set-group}] :on-toggle-collapse on-toggle-collapse}]
^boolean is-new ^boolean is-new
[:> sets-tree-set* [:> sets-tree-set*
{:key index {:key index
:set token-set :id id
:label "" :set token-set
:id id :label ""
:is-editing true :is-editing true
:is-active true :is-active true
:is-selected true :is-selected true
:is-new true :is-draggable false
:tree-path path :is-new true
:tree-depth depth
:tree-index index
:tree-parent-path parent-path
:on-drop on-drop :path path
:on-reset-edition on-reset-edition :depth depth
:on-edit-submit sets-helpers/on-create-token-set}] :index index
:else :on-drop on-drop
[:> sets-tree-set* :on-reset-edition on-reset-edition
{:key index :on-edit-submit sets-helpers/on-create-token-set}]
:set token-set
:id id :else
:label (peek path) [:> sets-tree-set*
:is-editing (= edition-id id) {:key index
:is-active (is-token-set-active id) :id id
:is-selected (= selected id) :set token-set
:is-draggable is-draggable :label (peek path)
:on-select on-select :is-editing (= edition-id id)
:tree-path path :is-active (is-token-set-active (ctob/get-name token-set))
:tree-depth depth :is-selected (= selected id)
:tree-index index :is-draggable is-draggable
:is-new false :is-new false
:tree-parent-path parent-path
:on-toggle on-toggle-set :path path
:edition-id edition-id :depth depth
:on-start-edition on-start-edition :index index
:on-drop on-drop
:on-reset-edition on-reset-edition :on-select on-select
:on-edit-submit on-edit-submit-set}])))) :on-toggle on-toggle-set
:on-drop on-drop
:on-start-edition on-start-edition
:on-reset-edition on-reset-edition
:on-edit-submit on-edit-submit-set}])))))
(mf/defc controlled-sets-list* (mf/defc controlled-sets-list*
[{:keys [token-sets [{:keys [token-sets

View File

@@ -35,13 +35,8 @@
(mf/defc token-sets-list* (mf/defc token-sets-list*
{::mf/private true} {::mf/private true}
[{:keys [tokens-lib]}] [{:keys [tokens-lib]}]
(let [;; FIXME: This is an inneficient operation just for being (let [token-sets
;; ability to check if there are some sets and lookup the (some-> tokens-lib (ctob/get-set-tree))
;; first one when no set is selected, should be REFACTORED; is
;; inneficient because instead of return the sets as-is (tree)
;; it firstly makes it a plain seq from tree.
token-sets
(some-> tokens-lib (ctob/get-sets))
selected-token-set-id selected-token-set-id
(mf/deref refs/selected-token-set-id) (mf/deref refs/selected-token-set-id)

View File

@@ -318,9 +318,8 @@
on-click-token-set on-click-token-set
(mf/use-fn (mf/use-fn
(mf/deps on-toggle-token-set) (mf/deps on-toggle-token-set)
(fn [prefixed-set-path-str] (fn [set-id]
(let [set-name (ctob/prefixed-set-path-string->set-name-string prefixed-set-path-str)] (on-toggle-token-set set-id)))]
(on-toggle-token-set set-name))))]
[:div {:class (stl/css :themes-modal-wrapper)} [:div {:class (stl/css :themes-modal-wrapper)}
[:> heading* {:level 2 :typography "headline-medium" :class (stl/css :themes-modal-title)} [:> heading* {:level 2 :typography "headline-medium" :class (stl/css :themes-modal-title)}

View File

@@ -39,17 +39,17 @@
(ctob/add-theme (ctob/make-token-theme :name "test-theme" (ctob/add-theme (ctob/make-token-theme :name "test-theme"
:sets #{"test-token-set"})) :sets #{"test-token-set"}))
(ctob/set-active-themes #{"/test-theme"}) (ctob/set-active-themes #{"/test-theme"})
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :test-token-1) (ctob/make-token :id (cthi/new-id! :test-token-1)
:name "test-token-1" :name "test-token-1"
:type :border-radius :type :border-radius
:value 25)) :value 25))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :test-token-2) (ctob/make-token :id (cthi/new-id! :test-token-2)
:name "test-token-2" :name "test-token-2"
:type :border-radius :type :border-radius
:value 50)) :value 50))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :test-token-3) (ctob/make-token :id (cthi/new-id! :test-token-3)
:name "test-token-3" :name "test-token-3"
:type :border-radius :type :border-radius
@@ -208,7 +208,6 @@
;; ==== Action ;; ==== Action
events [(dwtl/set-selected-token-set-id (cthi/id :test-token-set)) events [(dwtl/set-selected-token-set-id (cthi/id :test-token-set))
(dwtl/set-selected-token-set-name "test-token-set")
(dwtl/update-token (cthi/id :test-token-1) (dwtl/update-token (cthi/id :test-token-1)
{:name "test-token-1" {:name "test-token-1"
:type :border-radius :type :border-radius
@@ -328,32 +327,32 @@
(ctob/add-theme (ctob/make-token-theme :name "test-theme" (ctob/add-theme (ctob/make-token-theme :name "test-theme"
:sets #{"test-token-set"})) :sets #{"test-token-set"}))
(ctob/set-active-themes #{"/test-theme"}) (ctob/set-active-themes #{"/test-theme"})
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :token-radius) (ctob/make-token :id (cthi/new-id! :token-radius)
:name "token-radius" :name "token-radius"
:type :border-radius :type :border-radius
:value 10)) :value 10))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :token-rotation) (ctob/make-token :id (cthi/new-id! :token-rotation)
:name "token-rotation" :name "token-rotation"
:type :rotation :type :rotation
:value 30)) :value 30))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :token-opacity) (ctob/make-token :id (cthi/new-id! :token-opacity)
:name "token-opacity" :name "token-opacity"
:type :opacity :type :opacity
:value 0.7)) :value 0.7))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :token-stroke-width) (ctob/make-token :id (cthi/new-id! :token-stroke-width)
:name "token-stroke-width" :name "token-stroke-width"
:type :stroke-width :type :stroke-width
:value 2)) :value 2))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :token-color) (ctob/make-token :id (cthi/new-id! :token-color)
:name "token-color" :name "token-color"
:type :color :type :color
:value "#00ff00")) :value "#00ff00"))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (cthi/id :test-token-set)
(ctob/make-token :id (cthi/new-id! :token-dimensions) (ctob/make-token :id (cthi/new-id! :token-dimensions)
:name "token-dimensions" :name "token-dimensions"
:type :dimensions :type :dimensions
@@ -372,7 +371,6 @@
;; ==== Action ;; ==== Action
events [(dwtl/set-selected-token-set-id (cthi/id :test-token-set)) events [(dwtl/set-selected-token-set-id (cthi/id :test-token-set))
(dwtl/set-selected-token-set-name "test-token-set")
(dwtl/update-token (cthi/id :token-radius) (dwtl/update-token (cthi/id :token-radius)
{:name "token-radius" {:name "token-radius"
:value 30}) :value 30})

View File

@@ -2,6 +2,7 @@
(:require (:require
[app.common.test-helpers.compositions :as tho] [app.common.test-helpers.compositions :as tho]
[app.common.test-helpers.files :as thf] [app.common.test-helpers.files :as thf]
[app.common.test-helpers.ids-map :as thi]
[app.common.test-helpers.shapes :as ths] [app.common.test-helpers.shapes :as ths]
[app.common.test-helpers.tokens :as tht] [app.common.test-helpers.tokens :as tht]
[app.common.types.tokens-lib :as ctob] [app.common.types.tokens-lib :as ctob]
@@ -16,35 +17,35 @@
(ctob/add-theme (ctob/make-token-theme :name "test-theme" (ctob/add-theme (ctob/make-token-theme :name "test-theme"
:sets #{"test-token-set"})) :sets #{"test-token-set"}))
(ctob/set-active-themes #{"/test-theme"}) (ctob/set-active-themes #{"/test-theme"})
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "token-radius" (ctob/make-token :name "token-radius"
:type :border-radius :type :border-radius
:value 10)) :value 10))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "token-color" (ctob/make-token :name "token-color"
:type :color :type :color
:value "red")) :value "red"))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "token-spacing" (ctob/make-token :name "token-spacing"
:type :spacing :type :spacing
:value 10)) :value 10))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "token-sizing" (ctob/make-token :name "token-sizing"
:type :sizing :type :sizing
:value 10)) :value 10))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "token-rotation" (ctob/make-token :name "token-rotation"
:type :rotation :type :rotation
:value 10)) :value 10))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "token-opacity" (ctob/make-token :name "token-opacity"
:type :opacity :type :opacity
:value 10)) :value 10))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "token-dimensions" (ctob/make-token :name "token-dimensions"
:type :dimensions :type :dimensions
:value 10)) :value 10))
(ctob/add-token-in-set "test-token-set" (ctob/add-token-in-set (thi/id :test-token-set)
(ctob/make-token :name "token-number" (ctob/make-token :name "token-number"
:type :number :type :number
:value 10)))) :value 10))))

View File

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

View File

@@ -9,6 +9,7 @@
[app.common.test-helpers.files :as cthf] [app.common.test-helpers.files :as cthf]
[app.common.test-helpers.ids-map :as cthi] [app.common.test-helpers.ids-map :as cthi]
[app.common.types.tokens-lib :as ctob] [app.common.types.tokens-lib :as ctob]
[app.common.uuid :as uuid]
[app.main.data.workspace.tokens.library-edit :as dwtl] [app.main.data.workspace.tokens.library-edit :as dwtl]
[cljs.test :as t :include-macros true] [cljs.test :as t :include-macros true]
[frontend-tests.helpers.pages :as thp] [frontend-tests.helpers.pages :as thp]
@@ -76,7 +77,7 @@
done done
(let [file (setup-file-with-token-lib) (let [file (setup-file-with-token-lib)
store (ths/setup-store file) store (ths/setup-store file)
events [(dwtl/duplicate-token-set (cthi/id :test-token-set) false)]] events [(dwtl/duplicate-token-set (cthi/id :test-token-set))]]
(tohs/run-store-async (tohs/run-store-async
store done events store done events
@@ -93,7 +94,7 @@
done done
(let [file (setup-file-with-token-lib) (let [file (setup-file-with-token-lib)
store (ths/setup-store file) store (ths/setup-store file)
events [(dwtl/duplicate-token-set "Set B" false)]] events [(dwtl/duplicate-token-set (uuid/next))]]
(tohs/run-store-async (tohs/run-store-async
store done events store done events
@@ -110,7 +111,7 @@
done done
(let [file (setup-file-with-token-lib) (let [file (setup-file-with-token-lib)
store (ths/setup-store file) store (ths/setup-store file)
events [(dwtl/delete-token-set-path (ctob/split-set-name "Set A") false)]] events [(dwtl/delete-token-set (cthi/id :test-token-set))]]
(tohs/run-store-async (tohs/run-store-async
store done events store done events

View File

@@ -6,6 +6,7 @@
(ns frontend-tests.tokens.style-dictionary-test (ns frontend-tests.tokens.style-dictionary-test
(:require (:require
[app.common.test-helpers.ids-map :as cthi]
[app.common.types.tokens-lib :as ctob] [app.common.types.tokens-lib :as ctob]
[app.main.data.style-dictionary :as sd] [app.main.data.style-dictionary :as sd]
[beicon.v2.core :as rx] [beicon.v2.core :as rx]
@@ -16,22 +17,28 @@
done done
(t/testing "resolves tokens using style-dictionary from a ids map" (t/testing "resolves tokens using style-dictionary from a ids map"
(let [tokens (-> (ctob/make-tokens-lib) (let [tokens (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :name "core")) (ctob/add-set (ctob/make-token-set :id (cthi/new-id! :core-set)
(ctob/add-token-in-set "core" (ctob/make-token {:name "borderRadius.sm" :name "core"))
:value "12px" (ctob/add-token-in-set (cthi/id :core-set)
:type :border-radius})) (ctob/make-token {:name "borderRadius.sm"
(ctob/add-token-in-set "core" (ctob/make-token {:value "{borderRadius.sm} * 2" :value "12px"
:name "borderRadius.md-with-dashes" :type :border-radius}))
:type :border-radius})) (ctob/add-token-in-set (cthi/id :core-set)
(ctob/add-token-in-set "core" (ctob/make-token {:name "borderRadius.large" (ctob/make-token {:value "{borderRadius.sm} * 2"
:value "123456789012345" :name "borderRadius.md-with-dashes"
:type :border-radius})) :type :border-radius}))
(ctob/add-token-in-set "core" (ctob/make-token {:name "borderRadius.largePx" (ctob/add-token-in-set (cthi/id :core-set)
:value "123456789012345px" (ctob/make-token {:name "borderRadius.large"
:type :border-radius})) :value "123456789012345"
(ctob/add-token-in-set "core" (ctob/make-token {:name "borderRadius.largeFn" :type :border-radius}))
:value "{borderRadius.sm} * 200000000" (ctob/add-token-in-set (cthi/id :core-set)
:type :border-radius})) (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/get-all-tokens))] (ctob/get-all-tokens))]
(-> (sd/resolve-tokens tokens) (-> (sd/resolve-tokens tokens)
(rx/sub! (rx/sub!