mirror of
https://github.com/penpot/penpot.git
synced 2025-12-12 06:24:17 +01:00
🔧 Modify token sets by id instead of name and review usage
This commit is contained in:
@@ -409,13 +409,12 @@
|
||||
[:map {:title "SetTokenSetChange"}
|
||||
[:type [:= :set-token-set]]
|
||||
[:id ::sm/uuid]
|
||||
[:is-group :boolean]
|
||||
[:token-set [:maybe ctob/schema:token-set-attrs]]]]
|
||||
|
||||
[:set-token
|
||||
[:map {:title "SetTokenChange"}
|
||||
[:type [:= :set-token]]
|
||||
[:set-name :string]
|
||||
[:set-id ::sm/uuid]
|
||||
[:token-id ::sm/uuid]
|
||||
[:token [:maybe ctob/schema:token-attrs]]]]
|
||||
|
||||
@@ -978,39 +977,36 @@
|
||||
(assoc data :tokens-lib tokens-lib))
|
||||
|
||||
(defmethod process-change :set-token
|
||||
[data {:keys [set-name token-id token]}]
|
||||
[data {:keys [set-id token-id token]}]
|
||||
(update data :tokens-lib
|
||||
(fn [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
|
||||
(let [lib' (ctob/ensure-tokens-lib lib)]
|
||||
(cond
|
||||
(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))
|
||||
(ctob/add-token-in-set lib' set-name (ctob/make-token token))
|
||||
(not (ctob/get-token-in-set lib' set-id token-id))
|
||||
(ctob/add-token-in-set lib' set-id (ctob/make-token token))
|
||||
|
||||
:else
|
||||
(ctob/update-token-in-set lib' set-name token-id (fn [prev-token]
|
||||
(ctob/make-token (merge prev-token token)))))))))
|
||||
(ctob/update-token-in-set lib' set-id token-id
|
||||
(fn [prev-token]
|
||||
(ctob/make-token (merge prev-token token)))))))))
|
||||
|
||||
(defmethod process-change :set-token-set
|
||||
[data {:keys [id is-group token-set]}]
|
||||
[data {:keys [id token-set]}]
|
||||
(update data :tokens-lib
|
||||
(fn [lib]
|
||||
(let [lib' (ctob/ensure-tokens-lib lib)
|
||||
set (ctob/get-set lib' id)] ;; FIXME: remove this when set-token-set uses set-id
|
||||
(let [lib' (ctob/ensure-tokens-lib lib)]
|
||||
(cond
|
||||
(not token-set)
|
||||
(if is-group
|
||||
(ctob/delete-set-group lib' (ctob/get-name set)) ;; FIXME: move to a separate change
|
||||
(ctob/delete-set lib' (ctob/get-name set)))
|
||||
(ctob/delete-set lib' id)
|
||||
|
||||
(not (ctob/get-set lib' id))
|
||||
(ctob/add-set lib' (ctob/make-token-set token-set))
|
||||
|
||||
: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
|
||||
[data {:keys [group theme-name theme]}]
|
||||
|
||||
@@ -800,11 +800,15 @@
|
||||
(apply-changes-local))))
|
||||
|
||||
(defn update-active-token-themes
|
||||
[changes active-theme-paths prev-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)))
|
||||
[changes active-theme-paths]
|
||||
(assert-library! changes)
|
||||
(let [library-data (::library-data (meta changes))
|
||||
prev-active-theme-paths (some-> (get library-data :tokens-lib)
|
||||
(ctob/get-active-theme-paths))]
|
||||
(-> 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]
|
||||
(assert-library! changes)
|
||||
@@ -881,31 +885,21 @@
|
||||
(update :undo-changes conj {:type :set-tokens-lib :tokens-lib prev-tokens-lib})
|
||||
(apply-changes-local))))
|
||||
|
||||
(defn set-token [changes set-name token-id token]
|
||||
(defn set-token [changes set-id token-id token]
|
||||
(assert-library! changes)
|
||||
(let [library-data (::library-data (meta changes))
|
||||
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))]
|
||||
(-> changes
|
||||
(update :redo-changes conj {:type :set-token
|
||||
:set-name set-name
|
||||
:set-id set-id
|
||||
:token-id token-id
|
||||
:token token})
|
||||
(update :undo-changes conj (if prev-token
|
||||
{:type :set-token
|
||||
:set-name set-name
|
||||
:token-id (or
|
||||
;; 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}))
|
||||
(update :undo-changes conj {:type :set-token
|
||||
:set-id set-id
|
||||
:token-id token-id
|
||||
:token prev-token})
|
||||
(apply-changes-local))))
|
||||
|
||||
(defn rename-token-set
|
||||
@@ -917,16 +911,14 @@
|
||||
(-> changes
|
||||
(update :redo-changes conj {:type :set-token-set
|
||||
:id id
|
||||
:token-set (datafy (ctob/rename prev-token-set new-name))
|
||||
:is-group false})
|
||||
:token-set (datafy (ctob/rename prev-token-set new-name))})
|
||||
(update :undo-changes conj {:type :set-token-set
|
||||
:id id
|
||||
:token-set (datafy prev-token-set)
|
||||
:is-group false})
|
||||
:token-set (datafy prev-token-set)})
|
||||
(apply-changes-local))))
|
||||
|
||||
(defn set-token-set
|
||||
[changes id is-group token-set]
|
||||
[changes id token-set]
|
||||
(assert-library! changes)
|
||||
(let [library-data (::library-data (meta changes))
|
||||
prev-token-set (some-> (get library-data :tokens-lib)
|
||||
@@ -934,12 +926,10 @@
|
||||
(-> changes
|
||||
(update :redo-changes conj {:type :set-token-set
|
||||
:id id
|
||||
:token-set (datafy token-set)
|
||||
:is-group is-group})
|
||||
:token-set (datafy token-set)})
|
||||
(update :undo-changes conj {:type :set-token-set
|
||||
:id id
|
||||
:token-set (datafy prev-token-set)
|
||||
:is-group is-group})
|
||||
:token-set (datafy prev-token-set)})
|
||||
(apply-changes-local))))
|
||||
|
||||
(defn add-component
|
||||
|
||||
@@ -17,18 +17,17 @@
|
||||
Use this for managing sets active state without having to modify a
|
||||
user created theme (\"no themes selected\" state in the ui)."
|
||||
[changes tokens-lib update-theme-fn]
|
||||
(let [prev-active-token-themes (ctob/get-active-theme-paths tokens-lib)
|
||||
active-token-set-names (ctob/get-active-themes-set-names tokens-lib)
|
||||
(let [active-token-set-names (ctob/get-active-themes-set-names tokens-lib)
|
||||
|
||||
prev-hidden-theme (ctob/get-hidden-theme tokens-lib)
|
||||
|
||||
hidden-theme (-> (some-> prev-hidden-theme (ctob/set-sets active-token-set-names))
|
||||
(update-theme-fn))]
|
||||
hidden-theme (ctob/get-hidden-theme tokens-lib)
|
||||
hidden-theme' (-> (some-> hidden-theme
|
||||
(ctob/set-sets active-token-set-names))
|
||||
(update-theme-fn))]
|
||||
(-> changes
|
||||
(pcb/update-active-token-themes #{(ctob/theme-path hidden-theme)} prev-active-token-themes)
|
||||
(pcb/set-token-theme (:group prev-hidden-theme)
|
||||
(:name prev-hidden-theme)
|
||||
hidden-theme))))
|
||||
(pcb/update-active-token-themes #{(ctob/theme-path hidden-theme')})
|
||||
(pcb/set-token-theme (:group hidden-theme)
|
||||
(:name hidden-theme)
|
||||
hidden-theme'))))
|
||||
|
||||
(defn generate-toggle-token-set
|
||||
"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)]
|
||||
(pcb/move-token-set-group changes params)
|
||||
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)))
|
||||
@@ -295,6 +295,7 @@
|
||||
(assoc tokens (:name token) token))))
|
||||
|
||||
(update-token [this token-id f]
|
||||
(assert (uuid? token-id) "expected uuid for `token-id`")
|
||||
(if-let [token (get-token this token-id)]
|
||||
(let [token' (-> (make-token (f token))
|
||||
(assoc :modified-at (ct/now)))]
|
||||
@@ -310,6 +311,7 @@
|
||||
this))
|
||||
|
||||
(delete-token [this token-id]
|
||||
(assert (uuid? token-id) "expected uuid for `token-id`")
|
||||
(let [token (get-token this token-id)]
|
||||
(TokenSet. id
|
||||
name
|
||||
@@ -317,11 +319,13 @@
|
||||
(ct/now)
|
||||
(dissoc tokens (:name token)))))
|
||||
|
||||
(get-token [_ id]
|
||||
(some #(when (= (:id %) id) %) ;; TODO: this will be made in an efficient way when
|
||||
(vals tokens))) ;; we refactor the tokens lib internal structure
|
||||
(get-token [_ token-id]
|
||||
(assert (uuid? token-id) "expected uuid for `token-id`")
|
||||
(some #(when (= (:id %) token-id) %) ;; TODO: this will be made in an efficient way when
|
||||
(vals tokens))) ;; we refactor the tokens lib internal structure
|
||||
|
||||
(get-token-by-name [_ name]
|
||||
(assert (string? name) "expected string for `name`")
|
||||
(get tokens name))
|
||||
|
||||
(get-tokens [_]
|
||||
@@ -425,10 +429,39 @@
|
||||
|
||||
(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]
|
||||
(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
|
||||
|
||||
E.g.: \"S-some-set\" -> [\"S-\" \"some-set\"]
|
||||
@@ -438,13 +471,13 @@
|
||||
(re-matches #"^([SG]-)(.*)")
|
||||
(rest)))
|
||||
|
||||
(defn add-set-path-prefix [set-name-str]
|
||||
(defn- add-set-path-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))
|
||||
|
||||
(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.
|
||||
|
||||
Sets will be prefixed with `set-prefix` (S-).
|
||||
@@ -454,62 +487,24 @@
|
||||
set-name (add-set-path-prefix (last full-path))]
|
||||
(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."
|
||||
[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]
|
||||
(-> (set-group-path->set-group-prefixed-path path)
|
||||
(join-set-path)))
|
||||
|
||||
(defn add-set-group-prefix [group-path]
|
||||
(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]
|
||||
(defn- set-name->prefixed-full-path [name-str]
|
||||
(-> (split-set-name name-str)
|
||||
(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)]
|
||||
(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
|
||||
"Convert tokens into a nested tree with their name as the path.
|
||||
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 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")
|
||||
(update-set [_ set-name f] "modify a set in the library")
|
||||
(delete-set-path [_ set-path] "delete a set in the library")
|
||||
(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")
|
||||
(update-set [_ id f] "modify a set in the library")
|
||||
(delete-set [_ id] "delete a set in the library and disable it 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-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")
|
||||
(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-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")
|
||||
(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")
|
||||
@@ -875,48 +868,52 @@
|
||||
(walk (or nodes (d/ordered-map)) nil)))
|
||||
|
||||
(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:
|
||||
`:skip-children-pred`: predicate to skip iterating over a set groups children by checking the path of the set group
|
||||
`:new-editing-set-path`: append a an item with `:new?` at the given path"
|
||||
`:skip-children-pred`: predicate that is given a node path. If it returns true, the children of that node are skipped.
|
||||
`: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]
|
||||
: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
|
||||
(cond
|
||||
;; New set
|
||||
(= :is-new k)
|
||||
(let [tset (make-token-set :name (if (empty? parent)
|
||||
""
|
||||
(join-set-path parent)))]
|
||||
(let [token-set (make-token-set :name (if (empty? parent-path)
|
||||
""
|
||||
(join-set-path parent-path)))]
|
||||
[{:is-new true
|
||||
:is-group false
|
||||
:id "" ; FIXME: This is a calculated id, used for the sets tree in the sidear
|
||||
:parent-path parent ; It may be refactored now to use the actual :id
|
||||
:token-set tset
|
||||
:depth depth}])
|
||||
:path (split-set-name (get-name token-set))
|
||||
:depth depth
|
||||
:id (get-id token-set)
|
||||
:token-set token-set}])
|
||||
|
||||
;; Set
|
||||
(and v (instance? TokenSet v))
|
||||
(let [name (get-name v)]
|
||||
[{:is-group false
|
||||
:path (split-set-name name)
|
||||
:id name
|
||||
:parent-path parent
|
||||
:depth depth
|
||||
:token-set v}])
|
||||
[{:is-group false
|
||||
:path (split-set-name (get-name v))
|
||||
:depth depth
|
||||
:id (get-id v)
|
||||
:token-set v}]
|
||||
|
||||
;; Set group
|
||||
(and v (d/ordered-map? v))
|
||||
(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
|
||||
:path path
|
||||
:id (join-set-path path)
|
||||
:parent-path parent
|
||||
:depth depth}]
|
||||
:depth depth
|
||||
:id (join-set-path path)}]
|
||||
|
||||
(if (skip-children-pred path)
|
||||
[item]
|
||||
@@ -982,31 +979,36 @@ Will return a value that matches this schema:
|
||||
themes
|
||||
active-themes)))
|
||||
|
||||
(update-set [this set-name f]
|
||||
(let [prefixed-full-path (set-name->prefixed-full-path set-name)
|
||||
set (get-in sets prefixed-full-path)]
|
||||
(update-set [this id f]
|
||||
(assert (uuid? id) "expected uuid for `id`")
|
||||
(let [set (get-set this id)
|
||||
name (get-name set)
|
||||
prefixed-full-path (set-name->prefixed-full-path name)]
|
||||
(if set
|
||||
(let [set' (f set)
|
||||
prefixed-full-path' (get-set-prefixed-path set')
|
||||
name-changed? (not= (get-name set) (get-name set'))]
|
||||
(if name-changed?
|
||||
name' (get-name set')
|
||||
prefixed-full-path' (get-set-prefixed-path set')]
|
||||
(if (= name name')
|
||||
(TokensLib. (d/oassoc-in sets prefixed-full-path set')
|
||||
themes
|
||||
active-themes)
|
||||
(TokensLib. (-> sets
|
||||
(d/oassoc-in-before prefixed-full-path prefixed-full-path' set')
|
||||
(d/dissoc-in prefixed-full-path))
|
||||
(walk/postwalk
|
||||
(fn [form]
|
||||
(if (instance? TokenTheme form)
|
||||
(update-set-name form (get-name set) (get-name set'))
|
||||
(update-set-name form name name')
|
||||
form))
|
||||
themes)
|
||||
active-themes)
|
||||
(TokensLib. (d/oassoc-in sets prefixed-full-path set')
|
||||
themes
|
||||
active-themes)))
|
||||
this)))
|
||||
|
||||
(delete-set [_ set-name]
|
||||
(let [prefixed-path (set-name->prefixed-full-path set-name)]
|
||||
(delete-set [this id]
|
||||
(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)
|
||||
(walk/postwalk
|
||||
(fn [form]
|
||||
@@ -1016,38 +1018,6 @@ Will return a value that matches this schema:
|
||||
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?]
|
||||
(let [prefixed-from-path (set-full-path->set-prefixed-full-path 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)
|
||||
(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))
|
||||
(tree-seq d/ordered-map? vals)
|
||||
(filter (partial instance? TokenSet))))
|
||||
@@ -1163,8 +1133,8 @@ Will return a value that matches this schema:
|
||||
sets (get-sets-at-path this path)]
|
||||
(reduce
|
||||
(fn [lib set]
|
||||
(update-set lib (get-name set) (fn [set']
|
||||
(rename set' (str to-path-str (str/strip-prefix (get-name set') from-path-str))))))
|
||||
(update-set lib (get-id set) (fn [set']
|
||||
(rename set' (str to-path-str (str/strip-prefix (get-name set') from-path-str))))))
|
||||
this sets)))
|
||||
|
||||
(get-ordered-set-names [this]
|
||||
@@ -1174,10 +1144,12 @@ Will return a value that matches this schema:
|
||||
(count (get-sets this)))
|
||||
|
||||
(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
|
||||
(get-sets this))) ;; we refactor the tokens lib internal structure
|
||||
|
||||
(get-set-by-name [_ name]
|
||||
(assert (string? name) "expected string for `name`")
|
||||
(let [path (set-name->prefixed-full-path name)]
|
||||
(get-in sets path)))
|
||||
|
||||
@@ -1290,8 +1262,8 @@ Will return a value that matches this schema:
|
||||
(set-group-path-exists? [_ set-path]
|
||||
(some? (get-in sets (set-group-path->set-group-prefixed-path set-path))))
|
||||
|
||||
(add-token-in-set [this set-name token]
|
||||
(update-set this set-name #(add-token % token)))
|
||||
(add-token-in-set [this set-id token]
|
||||
(update-set this set-id #(add-token % token)))
|
||||
|
||||
(get-token-in-set [this set-id token-id]
|
||||
(some-> this
|
||||
@@ -1303,11 +1275,11 @@ Will return a value that matches this schema:
|
||||
(get-set set-id)
|
||||
(get-token-by-name token-name)))
|
||||
|
||||
(update-token-in-set [this set-name token-id f]
|
||||
(update-set this set-name #(update-token % token-id f)))
|
||||
(update-token-in-set [this set-id token-id f]
|
||||
(update-set this set-id #(update-token % token-id f)))
|
||||
|
||||
(delete-token-from-set [this set-name token-id]
|
||||
(update-set this set-name #(delete-token % token-id)))
|
||||
(delete-token-from-set [this set-id token-id]
|
||||
(update-set this set-id #(delete-token % token-id)))
|
||||
|
||||
(toggle-set-in-theme [this theme-group theme-name set-name]
|
||||
(if-let [_theme (get-in themes theme-group theme-name)]
|
||||
@@ -1326,7 +1298,7 @@ Will return a value that matches this schema:
|
||||
(let [active-set-names (get-active-themes-set-names this)
|
||||
prefixed-path-str (set-group-path->set-group-prefixed-path-str group-path)]
|
||||
(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)
|
||||
(into #{}))
|
||||
difference (set/difference path-active-set-names active-set-names)]
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
[app.common.types.file :as ctf]
|
||||
[app.common.types.shape :as cts]
|
||||
[app.common.uuid :as uuid]
|
||||
[clojure.pprint :refer [pprint]]
|
||||
[clojure.test :as t]
|
||||
[common-tests.types.shape-decode-encode-test :refer [json-roundtrip]]))
|
||||
|
||||
|
||||
@@ -32,47 +32,47 @@
|
||||
(ctob/add-theme (ctob/make-token-theme :name "test-theme"
|
||||
:sets #{"test-token-set"}))
|
||||
(ctob/set-active-themes #{"/test-theme"})
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :id (thi/new-id! :token-radius)
|
||||
:name "token-radius"
|
||||
:type :border-radius
|
||||
:value 10))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :id (thi/new-id! :token-rotation)
|
||||
:name "token-rotation"
|
||||
:type :rotation
|
||||
:value 30))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :id (thi/new-id! :token-opacity)
|
||||
:name "token-opacity"
|
||||
:type :opacity
|
||||
:value 0.7))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :id (thi/new-id! :token-stroke-width)
|
||||
:name "token-stroke-width"
|
||||
:type :stroke-width
|
||||
:value 2))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :id (thi/new-id! :token-color)
|
||||
:name "token-color"
|
||||
:type :color
|
||||
:value "#00ff00"))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :id (thi/new-id! :token-dimensions)
|
||||
:name "token-dimensions"
|
||||
:type :dimensions
|
||||
:value 100))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :id (thi/new-id! :token-font-size)
|
||||
:name "token-font-size"
|
||||
:type :font-size
|
||||
:value 24))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :id (thi/new-id! :token-letter-spacing)
|
||||
:name "token-letter-spacing"
|
||||
:type :letter-spacing
|
||||
:value 2))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :id (thi/new-id! :token-font-family)
|
||||
:name "token-font-family"
|
||||
:type :font-family
|
||||
|
||||
@@ -171,13 +171,13 @@
|
||||
file (setup-file #(-> %
|
||||
(ctob/add-set (ctob/make-token-set :id set-id
|
||||
:name set-name))
|
||||
(ctob/add-token-in-set set-name (ctob/make-token {:name "to.delete.color.red"
|
||||
:id token-id
|
||||
:value "red"
|
||||
:type :color}))))
|
||||
(ctob/add-token-in-set set-id (ctob/make-token {:name "to.delete.color.red"
|
||||
:id token-id
|
||||
:value "red"
|
||||
:type :color}))))
|
||||
changes (-> (pcb/empty-changes)
|
||||
(pcb/with-library-data (:data file))
|
||||
(pcb/set-token set-name token-id nil))
|
||||
(pcb/set-token set-id token-id nil))
|
||||
|
||||
redo (thf/apply-changes file changes)
|
||||
redo-lib (tht/get-tokens-lib redo)
|
||||
@@ -197,7 +197,7 @@
|
||||
:name set-name))))
|
||||
changes (-> (pcb/empty-changes)
|
||||
(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-lib (tht/get-tokens-lib redo)
|
||||
@@ -219,10 +219,10 @@
|
||||
file (setup-file #(-> %
|
||||
(ctob/add-set (ctob/make-token-set :id set-id
|
||||
: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)
|
||||
(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-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)))
|
||||
changes (-> (pcb/empty-changes)
|
||||
(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-lib (tht/get-tokens-lib redo)
|
||||
@@ -256,7 +256,7 @@
|
||||
file (setup-file identity)
|
||||
changes (-> (pcb/empty-changes)
|
||||
(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-lib (tht/get-tokens-lib redo)
|
||||
@@ -275,7 +275,7 @@
|
||||
|
||||
changes (-> (pcb/empty-changes)
|
||||
(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-lib (tht/get-tokens-lib redo)
|
||||
|
||||
@@ -256,10 +256,10 @@
|
||||
:name "test-token-set")))
|
||||
|
||||
tokens-lib' (-> tokens-lib
|
||||
(ctob/update-set "test-token-set"
|
||||
(ctob/update-set (thi/id :test-token-set)
|
||||
(fn [token-set]
|
||||
(ctob/set-description token-set "some description")))
|
||||
(ctob/update-set "not-existing-set"
|
||||
(ctob/update-set (uuid/next)
|
||||
(fn [token-set]
|
||||
(ctob/set-description token-set "no-effect"))))
|
||||
|
||||
@@ -277,7 +277,7 @@
|
||||
:name "test-token-set")))
|
||||
|
||||
tokens-lib' (-> tokens-lib
|
||||
(ctob/update-set "test-token-set"
|
||||
(ctob/update-set (thi/id :test-token-set)
|
||||
(fn [token-set]
|
||||
(ctob/rename token-set "updated-name"))))
|
||||
|
||||
@@ -306,23 +306,6 @@
|
||||
"foo/bar-renamed/baz-renamed/baz-child-2")))
|
||||
(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
|
||||
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
||||
(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/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
|
||||
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
||||
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
|
||||
@@ -403,8 +372,8 @@
|
||||
:type :boolean
|
||||
:value true)
|
||||
tokens-lib' (-> tokens-lib
|
||||
(ctob/add-token-in-set "test-token-set" token)
|
||||
(ctob/add-token-in-set "not-existing-set" token))
|
||||
(ctob/add-token-in-set (thi/id :test-token-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))
|
||||
@@ -419,28 +388,28 @@
|
||||
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
||||
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
|
||||
:name "test-token-set"))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :id (thi/new-id! :test-token-1)
|
||||
:name "test-token-1"
|
||||
:type :boolean
|
||||
:value true))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :id (thi/new-id! :test-token-2)
|
||||
:name "test-token-2"
|
||||
:type :boolean
|
||||
:value true)))
|
||||
|
||||
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]
|
||||
(assoc token
|
||||
:description "some description"
|
||||
: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]
|
||||
(assoc token
|
||||
: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]
|
||||
(assoc token
|
||||
:name "no-effect"))))
|
||||
@@ -463,19 +432,19 @@
|
||||
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
||||
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
|
||||
:name "test-token-set"))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :id (thi/new-id! :test-token-1)
|
||||
:name "test-token-1"
|
||||
:type :boolean
|
||||
:value true))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :id (thi/new-id! :test-token-2)
|
||||
:name "test-token-2"
|
||||
:type :boolean
|
||||
:value true)))
|
||||
|
||||
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]
|
||||
(assoc token
|
||||
:name "updated-name"))))
|
||||
@@ -498,15 +467,15 @@
|
||||
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
||||
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
|
||||
:name "test-token-set"))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :id (thi/new-id! :test-token)
|
||||
:name "test-token"
|
||||
:type :boolean
|
||||
:value true)))
|
||||
tokens-lib' (-> tokens-lib
|
||||
(ctob/delete-token-from-set "test-token-set" (thi/id :test-token))
|
||||
(ctob/delete-token-from-set "not-existing-set" (thi/id :test-token))
|
||||
(ctob/delete-token-from-set "test-token-set" (uuid/next)))
|
||||
(ctob/delete-token-from-set (thi/id :test-token-set) (thi/id :test-token))
|
||||
(ctob/delete-token-from-set (uuid/next) (thi/id :test-token))
|
||||
(ctob/delete-token-from-set (thi/id :test-token-set) (uuid/next)))
|
||||
|
||||
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
|
||||
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
||||
(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"
|
||||
:type :boolean
|
||||
:value true))
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :name "test-token"
|
||||
:type :boolean
|
||||
:value true))
|
||||
(ctob/add-theme (ctob/make-token-theme :name "test-token-theme"))
|
||||
(ctob/toggle-set-in-theme "" "test-token-theme" "test-token-set"))
|
||||
encoded-str (tr/encode-str tokens-lib)
|
||||
@@ -867,10 +837,12 @@
|
||||
#?(:clj
|
||||
(t/deftest fressian-serialization
|
||||
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
||||
(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"
|
||||
:type :boolean
|
||||
:value true))
|
||||
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
|
||||
:name "test-token-set"))
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :name "test-token"
|
||||
:type :boolean
|
||||
:value true))
|
||||
(ctob/add-theme (ctob/make-token-theme :name "test-token-theme"))
|
||||
(ctob/toggle-set-in-theme "" "test-token-theme" "test-token-set"))
|
||||
encoded-blob (fres/encode tokens-lib)
|
||||
@@ -900,23 +872,23 @@
|
||||
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
||||
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
|
||||
:name "test-token-set"))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :name "token1"
|
||||
:type :boolean
|
||||
:value true))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :name "group1.token2"
|
||||
:type :boolean
|
||||
:value true))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :name "group1.token3"
|
||||
:type :boolean
|
||||
:value true))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :name "group1.subgroup11.token4"
|
||||
:type :boolean
|
||||
:value true))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :name "group2.token5"
|
||||
:type :boolean
|
||||
:value true)))
|
||||
@@ -935,24 +907,24 @@
|
||||
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
||||
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
|
||||
:name "test-token-set"))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :id (thi/new-id! :test-token-1)
|
||||
:name "test-token-1"
|
||||
:type :boolean
|
||||
:value true))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :id (thi/new-id! :test-token-2)
|
||||
:name "group1.test-token-2"
|
||||
:type :boolean
|
||||
:value true))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :id (thi/new-id! :test-token-3)
|
||||
:name "group1.test-token-3"
|
||||
:type :boolean
|
||||
:value true)))
|
||||
|
||||
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]
|
||||
(assoc token
|
||||
:description "some description"
|
||||
@@ -974,24 +946,24 @@
|
||||
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
||||
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
|
||||
:name "test-token-set"))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :id (thi/new-id! :test-token-1)
|
||||
:name "test-token-1"
|
||||
:type :boolean
|
||||
:value true))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :id (thi/new-id! :test-token-2)
|
||||
:name "group1.test-token-2"
|
||||
:type :boolean
|
||||
:value true))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :id (thi/new-id! :test-token-3)
|
||||
:name "group1.test-token-3"
|
||||
:type :boolean
|
||||
:value true)))
|
||||
|
||||
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]
|
||||
(assoc token
|
||||
:name "group1.updated-name"))))
|
||||
@@ -1012,24 +984,24 @@
|
||||
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
||||
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
|
||||
:name "test-token-set"))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :id (thi/new-id! :test-token-1)
|
||||
:name "test-token-1"
|
||||
:type :boolean
|
||||
:value true))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :id (thi/new-id! :test-token-2)
|
||||
:name "group1.test-token-2"
|
||||
:type :boolean
|
||||
:value true))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :id (thi/new-id! :test-token-3)
|
||||
:name "group1.test-token-3"
|
||||
:type :boolean
|
||||
:value true)))
|
||||
|
||||
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]
|
||||
(assoc token
|
||||
:name "group2.updated-name"))))
|
||||
@@ -1051,18 +1023,18 @@
|
||||
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
||||
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :test-token-set)
|
||||
:name "test-token-set"))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :id (thi/new-id! :test-token-1)
|
||||
:name "test-token-1"
|
||||
:type :boolean
|
||||
:value true))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :id (thi/new-id! :test-token-2)
|
||||
:name "group1.test-token-2"
|
||||
:type :boolean
|
||||
:value true)))
|
||||
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))
|
||||
@@ -1075,14 +1047,19 @@
|
||||
|
||||
(t/deftest update-token-set-in-groups
|
||||
(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 :name "group1/token-set-2"))
|
||||
(ctob/add-set (ctob/make-token-set :name "group1/token-set-3"))
|
||||
(ctob/add-set (ctob/make-token-set :name "group1/subgroup11/token-set-4"))
|
||||
(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-1)
|
||||
:name "token-set-1"))
|
||||
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :token-set-2)
|
||||
:name "group1/token-set-2"))
|
||||
(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
|
||||
(ctob/update-set "group1/token-set-2"
|
||||
(ctob/update-set (thi/id :token-set-2)
|
||||
(fn [token-set]
|
||||
(ctob/set-description token-set "some description"))))
|
||||
|
||||
@@ -1101,14 +1078,19 @@
|
||||
|
||||
(t/deftest rename-token-set-in-groups
|
||||
(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 :name "group1/token-set-2"))
|
||||
(ctob/add-set (ctob/make-token-set :name "group1/token-set-3"))
|
||||
(ctob/add-set (ctob/make-token-set :name "group1/subgroup11/token-set-4"))
|
||||
(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-1)
|
||||
:name "token-set-1"))
|
||||
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :token-set-2)
|
||||
:name "group1/token-set-2"))
|
||||
(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
|
||||
(ctob/update-set "group1/token-set-2"
|
||||
(ctob/update-set (thi/id :token-set-2)
|
||||
(fn [token-set]
|
||||
(ctob/rename token-set "group1/updated-name"))))
|
||||
|
||||
@@ -1127,14 +1109,19 @@
|
||||
|
||||
(t/deftest move-token-set-of-group
|
||||
(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 :name "group1/token-set-2"))
|
||||
(ctob/add-set (ctob/make-token-set :name "group1/token-set-3"))
|
||||
(ctob/add-set (ctob/make-token-set :name "group1/subgroup11/token-set-4"))
|
||||
#_(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-1)
|
||||
:name "token-set-1"))
|
||||
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :token-set-2)
|
||||
:name "group1/token-set-2"))
|
||||
(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
|
||||
(ctob/update-set "group1/token-set-2"
|
||||
(ctob/update-set (thi/id :token-set-2)
|
||||
(fn [token-set]
|
||||
(ctob/rename token-set "group2/updated-name"))))
|
||||
|
||||
@@ -1155,11 +1142,13 @@
|
||||
|
||||
(t/deftest delete-token-set-in-group
|
||||
(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 :name "group1/token-set-2")))
|
||||
(ctob/add-set (ctob/make-token-set :id (thi/new-id! :token-set-1)
|
||||
: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
|
||||
(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')
|
||||
token-set' (get-in sets-tree' ["group1" "token-set-2"])]
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
[beicon.v2.core :as rx]
|
||||
[potok.v2.core :as ptk]))
|
||||
|
||||
(declare set-selected-token-set-name)
|
||||
(declare set-selected-token-set-id)
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
@@ -110,9 +109,9 @@
|
||||
(ptk/reify ::toggle-token-theme-active?
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
(let [tokens-lib (get-tokens-lib state)
|
||||
prev-active-token-themes (some-> tokens-lib
|
||||
(ctob/get-active-theme-paths))
|
||||
(let [data (dsh/lookup-file-data state)
|
||||
|
||||
tokens-lib (get-tokens-lib state)
|
||||
active-token-themes (some-> tokens-lib
|
||||
(ctob/toggle-theme-active? group name)
|
||||
(ctob/get-active-theme-paths))
|
||||
@@ -120,7 +119,8 @@
|
||||
active-token-themes
|
||||
(disj active-token-themes ctob/hidden-theme-path))
|
||||
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
|
||||
(dch/commit-changes changes)
|
||||
(dwtp/propagate-workspace-tokens))))))
|
||||
@@ -158,9 +158,8 @@
|
||||
(let [token-set (ctob/make-token-set :name set-name)
|
||||
changes (-> (pcb/empty-changes it)
|
||||
(pcb/with-library-data data)
|
||||
(pcb/set-token-set (ctob/get-id token-set) false token-set))]
|
||||
(rx/of (set-selected-token-set-name set-name)
|
||||
(set-selected-token-set-id (ctob/get-id token-set))
|
||||
(pcb/set-token-set (ctob/get-id token-set) token-set))]
|
||||
(rx/of (set-selected-token-set-id (ctob/get-id token-set))
|
||||
(dch/commit-changes changes))))))))
|
||||
|
||||
(defn rename-token-set-group [set-group-path set-group-fname]
|
||||
@@ -189,12 +188,11 @@
|
||||
(let [changes (-> (pcb/empty-changes it)
|
||||
(pcb/with-library-data data)
|
||||
(pcb/rename-token-set (ctob/get-id token-set) name))]
|
||||
(rx/of (set-selected-token-set-name name)
|
||||
(set-selected-token-set-id (ctob/get-id token-set))
|
||||
(rx/of (set-selected-token-set-id (ctob/get-id token-set))
|
||||
(dch/commit-changes changes))))))))
|
||||
|
||||
(defn duplicate-token-set
|
||||
[id is-group]
|
||||
[id]
|
||||
(ptk/reify ::duplicate-token-set
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
@@ -205,9 +203,8 @@
|
||||
(when-let [token-set (ctob/duplicate-set id tokens-lib {:suffix suffix})]
|
||||
(let [changes (-> (pcb/empty-changes it)
|
||||
(pcb/with-library-data data)
|
||||
(pcb/set-token-set (ctob/get-id token-set) is-group token-set))]
|
||||
(rx/of (set-selected-token-set-name (ctob/get-name token-set))
|
||||
(set-selected-token-set-id (ctob/get-id token-set))
|
||||
(pcb/set-token-set (ctob/get-id token-set) token-set))]
|
||||
(rx/of (set-selected-token-set-id (ctob/get-id token-set))
|
||||
(dch/commit-changes changes))))))))
|
||||
|
||||
(defn toggle-token-set
|
||||
@@ -248,16 +245,27 @@
|
||||
(rx/of (dch/commit-changes changes)
|
||||
(dwtp/propagate-workspace-tokens))))))
|
||||
|
||||
(defn delete-token-set-path
|
||||
[group? path]
|
||||
(ptk/reify ::delete-token-set-path
|
||||
(defn delete-token-set
|
||||
[id]
|
||||
(ptk/reify ::delete-token-set
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
(prn "path" path)
|
||||
(let [data (dsh/lookup-file-data state)
|
||||
changes (-> (pcb/empty-changes it)
|
||||
(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)
|
||||
(dwtp/propagate-workspace-tokens))))))
|
||||
|
||||
@@ -332,13 +340,12 @@
|
||||
changes
|
||||
(-> (pcb/empty-changes)
|
||||
(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)
|
||||
(:name hidden-theme)
|
||||
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)
|
||||
(set-selected-token-set-name set-name)
|
||||
(set-selected-token-set-id (ctob/get-id token-set)))))))
|
||||
|
||||
(defn create-token
|
||||
@@ -352,7 +359,7 @@
|
||||
token-type (:type token)
|
||||
changes (-> (pcb/empty-changes it)
|
||||
(pcb/with-library-data data)
|
||||
(pcb/set-token (ctob/get-name token-set)
|
||||
(pcb/set-token (ctob/get-id token-set)
|
||||
(:id token)
|
||||
token))]
|
||||
|
||||
@@ -377,15 +384,15 @@
|
||||
token-type (:type token)
|
||||
changes (-> (pcb/empty-changes it)
|
||||
(pcb/with-library-data data)
|
||||
(pcb/set-token (ctob/get-name token-set)
|
||||
(pcb/set-token (ctob/get-id token-set)
|
||||
id
|
||||
token'))]
|
||||
(rx/of (dch/commit-changes changes)
|
||||
(ptk/data-event ::ev/event {::ev/name "edit-token" :type token-type}))))))
|
||||
|
||||
(defn delete-token
|
||||
[set-name token-id]
|
||||
(dm/assert! (string? set-name))
|
||||
[set-id token-id]
|
||||
(dm/assert! (uuid? set-id))
|
||||
(dm/assert! (uuid? token-id))
|
||||
(ptk/reify ::delete-token
|
||||
ptk/WatchEvent
|
||||
@@ -393,7 +400,7 @@
|
||||
(let [data (dsh/lookup-file-data state)
|
||||
changes (-> (pcb/empty-changes it)
|
||||
(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))))))
|
||||
|
||||
(defn duplicate-token
|
||||
@@ -453,13 +460,6 @@
|
||||
(update state :workspace-tokens assoc :token-set-context-menu params)
|
||||
(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
|
||||
[id]
|
||||
(ptk/reify ::set-selected-token-set-id
|
||||
@@ -469,7 +469,8 @@
|
||||
|
||||
(defn start-token-set-edition
|
||||
[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/UpdateEvent
|
||||
|
||||
@@ -459,9 +459,6 @@
|
||||
(def workspace-token-themes-no-hidden
|
||||
(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
|
||||
(l/derived (l/key :selected-token-set-id) workspace-tokens))
|
||||
|
||||
|
||||
@@ -115,8 +115,7 @@
|
||||
(mf/with-memo [tokens-by-type]
|
||||
(get-sorted-token-groups tokens-by-type))]
|
||||
|
||||
;; (mf/with-effect [tokens-lib selected-token-set-id]
|
||||
(mf/with-effect []
|
||||
(mf/with-effect [tokens-lib selected-token-set-id]
|
||||
(when (and tokens-lib
|
||||
(or (nil? selected-token-set-id)
|
||||
(and selected-token-set-id
|
||||
@@ -124,8 +123,7 @@
|
||||
(let [match (->> (ctob/get-sets tokens-lib)
|
||||
(first))]
|
||||
(when match
|
||||
(st/emit! (dwtl/set-selected-token-set-name (ctob/get-name match))
|
||||
(dwtl/set-selected-token-set-id (ctob/get-id match)))))))
|
||||
(st/emit! (dwtl/set-selected-token-set-id (ctob/get-id match)))))))
|
||||
|
||||
[:*
|
||||
[:& token-context-menu]
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
[app.common.files.tokens :as cft]
|
||||
[app.common.types.shape.layout :as ctsl]
|
||||
[app.common.types.token :as ctt]
|
||||
[app.common.types.tokens-lib :as ctob]
|
||||
[app.main.data.modal :as modal]
|
||||
[app.main.data.workspace.shape-layout :as dwsl]
|
||||
[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)))
|
||||
(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)]
|
||||
[{:title (tr "workspace.tokens.edit")
|
||||
:no-selectable true
|
||||
@@ -331,7 +330,7 @@
|
||||
:position :right
|
||||
:fields fields
|
||||
:action "edit"
|
||||
:selected-token-set-name selected-token-set-name
|
||||
:selected-token-set-id selected-token-set-id
|
||||
:token token}))))}
|
||||
{:title (tr "workspace.tokens.duplicate")
|
||||
:no-selectable true
|
||||
@@ -339,7 +338,7 @@
|
||||
{:title (tr "workspace.tokens.delete")
|
||||
:no-selectable true
|
||||
:action #(st/emit! (dwtl/delete-token
|
||||
(ctob/prefixed-set-path-string->set-name-string selected-token-set-name)
|
||||
selected-token-set-id
|
||||
(:id token)))}]))
|
||||
|
||||
(defn- allowed-shape-attributes [shapes]
|
||||
@@ -472,7 +471,7 @@
|
||||
token-id (:token-id mdata)
|
||||
token (mf/deref (refs/workspace-token-in-selected-set token-id))
|
||||
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
|
||||
(mf/with-memo [selected objects]
|
||||
@@ -487,7 +486,7 @@
|
||||
[:& menu-tree {:submenu-offset width
|
||||
:token token
|
||||
:errors errors
|
||||
:selected-token-set-name selected-token-set-name
|
||||
:selected-token-set-id selected-token-set-id
|
||||
:selected-shapes selected-shapes
|
||||
:is-selected-inside-layout is-selected-inside-layout}]]))
|
||||
|
||||
|
||||
@@ -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"
|
||||
[{:keys [token
|
||||
token-type
|
||||
selected-token-set-name
|
||||
selected-token-set-id
|
||||
action
|
||||
input-value-placeholder
|
||||
|
||||
@@ -493,13 +493,11 @@ custom-input-token-value-props: Custom props passed to the custom-input-token-va
|
||||
|
||||
on-delete-token
|
||||
(mf/use-fn
|
||||
(mf/deps selected-token-set-name)
|
||||
(mf/deps selected-token-set-id)
|
||||
(fn [e]
|
||||
(dom/prevent-default e)
|
||||
(modal/hide!)
|
||||
(st/emit! (dwtl/delete-token
|
||||
(ctob/prefixed-set-path-string->set-name-string selected-token-set-name)
|
||||
(:id token)))))
|
||||
(st/emit! (dwtl/delete-token selected-token-set-id (:id token)))))
|
||||
|
||||
on-cancel
|
||||
(mf/use-fn
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
|
||||
(mf/defc token-update-create-modal
|
||||
{::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))
|
||||
modal-size-large* (mf/use-state (= token-type :typography))
|
||||
modal-size-large? (deref modal-size-large*)
|
||||
@@ -90,7 +90,7 @@
|
||||
:aria-label (tr "labels.close")}]
|
||||
[:> form-wrapper* {:token token
|
||||
:action action
|
||||
:selected-token-set-name selected-token-set-name
|
||||
:selected-token-set-id selected-token-set-id
|
||||
:token-type token-type
|
||||
:on-display-colorpicker update-modal-size}]]))
|
||||
|
||||
|
||||
@@ -15,9 +15,8 @@
|
||||
[app.main.ui.workspace.tokens.sets.lists :refer [controlled-sets-list*]]
|
||||
[rumext.v2 :as mf]))
|
||||
|
||||
(defn- on-select-token-set-click [id name]
|
||||
(st/emit! (dwtl/set-selected-token-set-id id)
|
||||
(dwtl/set-selected-token-set-name name)))
|
||||
(defn- on-select-token-set-click [id]
|
||||
(st/emit! (dwtl/set-selected-token-set-id id)))
|
||||
|
||||
(defn- on-toggle-token-set-click [name]
|
||||
(st/emit! (dwtl/toggle-token-set name)))
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
(mf/defc menu*
|
||||
{::mf/private true}
|
||||
[{:keys [is-group id edition-id path]}]
|
||||
[{:keys [is-group id path]}]
|
||||
(let [create-set-at-path
|
||||
(mf/use-fn (mf/deps path) #(st/emit! (dwtl/start-token-set-creation path)))
|
||||
|
||||
@@ -42,18 +42,20 @@
|
||||
(mf/use-fn
|
||||
(mf/deps id)
|
||||
(fn []
|
||||
(st/emit! (dwtl/start-token-set-edition edition-id))))
|
||||
(st/emit! (dwtl/start-token-set-edition id))))
|
||||
|
||||
on-duplicate
|
||||
(mf/use-fn
|
||||
(mf/deps is-group id)
|
||||
(fn []
|
||||
(st/emit! (dwtl/duplicate-token-set id is-group))))
|
||||
(st/emit! (dwtl/duplicate-token-set id))))
|
||||
|
||||
on-delete
|
||||
(mf/use-fn
|
||||
(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)}
|
||||
(when is-group
|
||||
@@ -65,7 +67,7 @@
|
||||
|
||||
(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)
|
||||
|
||||
position-top
|
||||
@@ -86,5 +88,4 @@
|
||||
:on-context-menu prevent-default}
|
||||
[:> menu* {:is-group is-group
|
||||
:id id
|
||||
:edition-id edition-id
|
||||
:path path}]]]))
|
||||
|
||||
@@ -32,5 +32,3 @@
|
||||
|
||||
(st/emit! (ptk/data-event ::ev/event {::ev/name "create-token-set" :name name})
|
||||
(dwtl/create-token-set name))))
|
||||
|
||||
|
||||
|
||||
@@ -30,12 +30,6 @@
|
||||
[]
|
||||
(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/private true}
|
||||
[{:keys [default-value on-cancel on-submit]}]
|
||||
@@ -113,8 +107,8 @@
|
||||
|
||||
(mf/defc sets-tree-set-group*
|
||||
{::mf/private true}
|
||||
[{:keys [id label tree-depth tree-path is-active is-selected is-draggable is-collapsed tree-index on-drop
|
||||
on-toggle-collapse on-toggle is-editing on-start-edition on-reset-edition on-edit-submit]}]
|
||||
[{:keys [id label is-editing is-active is-selected is-draggable is-collapsed path depth index
|
||||
on-toggle on-drop on-start-edition on-reset-edition on-edit-submit on-toggle-collapse]}]
|
||||
|
||||
(let [can-edit?
|
||||
(mf/use-ctx ctx/can-edit?)
|
||||
@@ -124,7 +118,7 @@
|
||||
|
||||
on-context-menu
|
||||
(mf/use-fn
|
||||
(mf/deps is-editing id tree-path can-edit?)
|
||||
(mf/deps is-editing id path can-edit?)
|
||||
(fn [event]
|
||||
(dom/prevent-default event)
|
||||
(dom/stop-propagation event)
|
||||
@@ -133,47 +127,46 @@
|
||||
{:position (dom/get-client-position event)
|
||||
:is-group true
|
||||
:id id
|
||||
:edition-id (group-edition-id id)
|
||||
:path tree-path})))))
|
||||
:path path})))))
|
||||
|
||||
on-collapse-click
|
||||
(mf/use-fn
|
||||
(fn [event]
|
||||
(dom/prevent-default event)
|
||||
(dom/stop-propagation event)
|
||||
(on-toggle-collapse tree-path)))
|
||||
(on-toggle-collapse path)))
|
||||
|
||||
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
|
||||
(mf/use-fn
|
||||
(mf/deps on-toggle tree-path can-edit?)
|
||||
#(on-toggle tree-path))
|
||||
(mf/deps on-toggle path can-edit?)
|
||||
#(on-toggle path))
|
||||
|
||||
on-edit-submit'
|
||||
(mf/use-fn
|
||||
(mf/deps tree-path on-edit-submit can-edit?)
|
||||
#(on-edit-submit tree-path %))
|
||||
(mf/deps path on-edit-submit can-edit?)
|
||||
#(on-edit-submit path %))
|
||||
|
||||
on-drop
|
||||
(mf/use-fn
|
||||
(mf/deps tree-index on-drop)
|
||||
(mf/deps index on-drop)
|
||||
(fn [position data]
|
||||
(on-drop tree-index position data)))
|
||||
(on-drop index position data)))
|
||||
|
||||
[dprops dref]
|
||||
(h/use-sortable
|
||||
:data-type "penpot/token-set"
|
||||
:on-drop on-drop
|
||||
:data {:index tree-index
|
||||
:data {:index index
|
||||
:is-group true}
|
||||
:detect-center? true
|
||||
:draggable? is-draggable)]
|
||||
|
||||
[:div {:ref dref
|
||||
:data-testid "tokens-set-group-item"
|
||||
:style {"--tree-depth" tree-depth}
|
||||
:style {"--tree-depth" depth}
|
||||
:class (stl/css-case :set-item-container true
|
||||
:set-item-group true
|
||||
:selected-set is-selected
|
||||
@@ -211,25 +204,23 @@
|
||||
:arial-label (tr "workspace.tokens.select-set")}]])]))
|
||||
|
||||
(mf/defc sets-tree-set*
|
||||
[{:keys [id set label tree-depth tree-path tree-index is-selected is-active is-draggable is-editing
|
||||
on-select on-drop on-toggle on-start-edition on-reset-edition on-edit-submit is-new]}]
|
||||
[{:keys [id set label is-editing is-active is-selected is-draggable is-new path depth index
|
||||
on-select on-toggle on-drop on-start-edition on-reset-edition on-edit-submit]}]
|
||||
|
||||
(let [set-id (ctob/get-id set)
|
||||
set-name (ctob/get-name set)
|
||||
can-edit? (mf/use-ctx ctx/can-edit?)
|
||||
(let [can-edit? (mf/use-ctx ctx/can-edit?)
|
||||
|
||||
on-click
|
||||
(mf/use-fn
|
||||
(mf/deps is-editing tree-path)
|
||||
(mf/deps is-editing on-select id)
|
||||
(fn [event]
|
||||
(dom/stop-propagation event)
|
||||
(when-not is-editing
|
||||
(when (fn? on-select)
|
||||
(on-select set-id set-name)))))
|
||||
(on-select id)))))
|
||||
|
||||
on-context-menu
|
||||
(mf/use-fn
|
||||
(mf/deps is-editing id tree-path can-edit?)
|
||||
(mf/deps is-editing id path can-edit?)
|
||||
(fn [event]
|
||||
(dom/prevent-default event)
|
||||
(dom/stop-propagation event)
|
||||
@@ -238,8 +229,7 @@
|
||||
{:position (dom/get-client-position event)
|
||||
:is-group false
|
||||
:id id
|
||||
:edition-id id
|
||||
:path tree-path})))))
|
||||
:path path})))))
|
||||
|
||||
on-double-click
|
||||
(mf/use-fn
|
||||
@@ -250,11 +240,11 @@
|
||||
|
||||
on-checkbox-click
|
||||
(mf/use-fn
|
||||
(mf/deps set-name on-toggle)
|
||||
(mf/deps id on-toggle)
|
||||
(fn [event]
|
||||
(dom/stop-propagation event)
|
||||
(when (fn? on-toggle)
|
||||
(on-toggle set-name))))
|
||||
(on-toggle (ctob/get-name set)))))
|
||||
|
||||
on-edit-submit'
|
||||
(mf/use-fn
|
||||
@@ -263,23 +253,23 @@
|
||||
|
||||
on-drag
|
||||
(mf/use-fn
|
||||
(mf/deps tree-path)
|
||||
(mf/deps path)
|
||||
(fn [_]
|
||||
(when-not is-selected
|
||||
(on-select tree-path))))
|
||||
(on-select path))))
|
||||
|
||||
on-drop
|
||||
(mf/use-fn
|
||||
(mf/deps tree-index on-drop)
|
||||
(mf/deps index on-drop)
|
||||
(fn [position data]
|
||||
(on-drop tree-index position data)))
|
||||
(on-drop index position data)))
|
||||
|
||||
[dprops dref]
|
||||
(h/use-sortable
|
||||
:data-type "penpot/token-set"
|
||||
:on-drag on-drag
|
||||
:on-drop on-drop
|
||||
:data {:index tree-index
|
||||
:data {:index index
|
||||
:is-group false}
|
||||
:draggable? is-draggable)
|
||||
|
||||
@@ -290,7 +280,7 @@
|
||||
:role "button"
|
||||
:data-testid "tokens-set-item"
|
||||
: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
|
||||
:selected-set is-selected
|
||||
:dnd-over (= drop-over :center)
|
||||
@@ -304,7 +294,7 @@
|
||||
[:> icon*
|
||||
{:icon-id i/document
|
||||
:class (stl/css-case :icon true
|
||||
:root-icon (not tree-depth))}]
|
||||
:root-icon (not depth))}]
|
||||
(if is-editing
|
||||
[:> editing-label*
|
||||
{:default-value label
|
||||
@@ -346,9 +336,9 @@
|
||||
on-drop
|
||||
(mf/use-fn
|
||||
(mf/deps collapsed-paths)
|
||||
(fn [tree-index position data]
|
||||
(fn [index position data]
|
||||
(let [params {:from-index (:index data)
|
||||
:to-index tree-index
|
||||
:to-index index
|
||||
:position position
|
||||
:collapsed-paths collapsed-paths}]
|
||||
(if (:is-group data)
|
||||
@@ -372,76 +362,76 @@
|
||||
(fn []
|
||||
(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
|
||||
{:skip-children-pred collapsed?
|
||||
:new-at-path new-path})]
|
||||
(cond
|
||||
^boolean is-group
|
||||
[:> sets-tree-set-group*
|
||||
{:key index
|
||||
:label (peek path)
|
||||
:id id
|
||||
:is-active (is-token-set-group-active path)
|
||||
:is-selected false
|
||||
:is-draggable is-draggable
|
||||
:is-editing (= edition-id (group-edition-id id))
|
||||
:is-collapsed (collapsed? path)
|
||||
:on-select on-select
|
||||
(do
|
||||
(cond
|
||||
^boolean is-group
|
||||
[:> sets-tree-set-group*
|
||||
{:key index
|
||||
:id id
|
||||
:label (peek path)
|
||||
:is-editing (= edition-id id)
|
||||
:is-active (is-token-set-group-active path)
|
||||
:is-selected false
|
||||
:is-draggable is-draggable
|
||||
:is-collapsed (collapsed? path)
|
||||
|
||||
:tree-path path
|
||||
:tree-depth depth
|
||||
:tree-index index
|
||||
:tree-parent-path parent-path
|
||||
:path path
|
||||
:depth depth
|
||||
:index index
|
||||
|
||||
:on-drop on-drop
|
||||
:on-start-edition on-start-edition
|
||||
:on-reset-edition on-reset-edition
|
||||
:on-edit-submit on-edit-submit-group
|
||||
:on-toggle-collapse on-toggle-collapse
|
||||
:on-toggle on-toggle-set-group}]
|
||||
:on-toggle on-toggle-set-group
|
||||
:on-drop on-drop
|
||||
:on-start-edition on-start-edition
|
||||
:on-reset-edition on-reset-edition
|
||||
:on-edit-submit on-edit-submit-group
|
||||
:on-toggle-collapse on-toggle-collapse}]
|
||||
|
||||
^boolean is-new
|
||||
[:> sets-tree-set*
|
||||
{:key index
|
||||
:set token-set
|
||||
:label ""
|
||||
:id id
|
||||
:is-editing true
|
||||
:is-active true
|
||||
:is-selected true
|
||||
:is-new true
|
||||
:tree-path path
|
||||
:tree-depth depth
|
||||
:tree-index index
|
||||
:tree-parent-path parent-path
|
||||
^boolean is-new
|
||||
[:> sets-tree-set*
|
||||
{:key index
|
||||
:id id
|
||||
:set token-set
|
||||
:label ""
|
||||
:is-editing true
|
||||
:is-active true
|
||||
:is-selected true
|
||||
:is-draggable false
|
||||
:is-new true
|
||||
|
||||
:on-drop on-drop
|
||||
:on-reset-edition on-reset-edition
|
||||
:on-edit-submit sets-helpers/on-create-token-set}]
|
||||
:path path
|
||||
:depth depth
|
||||
:index index
|
||||
|
||||
:else
|
||||
[:> sets-tree-set*
|
||||
{:key index
|
||||
:set token-set
|
||||
:id id
|
||||
:label (peek path)
|
||||
:is-editing (= edition-id id)
|
||||
:is-active (is-token-set-active id)
|
||||
:is-selected (= selected id)
|
||||
:is-draggable is-draggable
|
||||
:on-select on-select
|
||||
:tree-path path
|
||||
:tree-depth depth
|
||||
:tree-index index
|
||||
:is-new false
|
||||
:tree-parent-path parent-path
|
||||
:on-toggle on-toggle-set
|
||||
:edition-id edition-id
|
||||
:on-start-edition on-start-edition
|
||||
:on-drop on-drop
|
||||
:on-reset-edition on-reset-edition
|
||||
:on-edit-submit on-edit-submit-set}]))))
|
||||
:on-drop on-drop
|
||||
:on-reset-edition on-reset-edition
|
||||
:on-edit-submit sets-helpers/on-create-token-set}]
|
||||
|
||||
:else
|
||||
[:> sets-tree-set*
|
||||
{:key index
|
||||
:id id
|
||||
:set token-set
|
||||
:label (peek path)
|
||||
:is-editing (= edition-id id)
|
||||
:is-active (is-token-set-active (ctob/get-name token-set))
|
||||
:is-selected (= selected id)
|
||||
:is-draggable is-draggable
|
||||
:is-new false
|
||||
|
||||
:path path
|
||||
:depth depth
|
||||
:index index
|
||||
|
||||
:on-select on-select
|
||||
: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*
|
||||
[{:keys [token-sets
|
||||
|
||||
@@ -35,13 +35,8 @@
|
||||
(mf/defc token-sets-list*
|
||||
{::mf/private true}
|
||||
[{:keys [tokens-lib]}]
|
||||
(let [;; FIXME: This is an inneficient operation just for being
|
||||
;; ability to check if there are some sets and lookup the
|
||||
;; 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))
|
||||
(let [token-sets
|
||||
(some-> tokens-lib (ctob/get-set-tree))
|
||||
|
||||
selected-token-set-id
|
||||
(mf/deref refs/selected-token-set-id)
|
||||
|
||||
@@ -318,9 +318,8 @@
|
||||
on-click-token-set
|
||||
(mf/use-fn
|
||||
(mf/deps on-toggle-token-set)
|
||||
(fn [prefixed-set-path-str]
|
||||
(let [set-name (ctob/prefixed-set-path-string->set-name-string prefixed-set-path-str)]
|
||||
(on-toggle-token-set set-name))))]
|
||||
(fn [set-id]
|
||||
(on-toggle-token-set set-id)))]
|
||||
|
||||
[:div {:class (stl/css :themes-modal-wrapper)}
|
||||
[:> heading* {:level 2 :typography "headline-medium" :class (stl/css :themes-modal-title)}
|
||||
|
||||
@@ -39,17 +39,17 @@
|
||||
(ctob/add-theme (ctob/make-token-theme :name "test-theme"
|
||||
:sets #{"test-token-set"}))
|
||||
(ctob/set-active-themes #{"/test-theme"})
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (cthi/id :test-token-set)
|
||||
(ctob/make-token :id (cthi/new-id! :test-token-1)
|
||||
:name "test-token-1"
|
||||
:type :border-radius
|
||||
:value 25))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (cthi/id :test-token-set)
|
||||
(ctob/make-token :id (cthi/new-id! :test-token-2)
|
||||
:name "test-token-2"
|
||||
:type :border-radius
|
||||
:value 50))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (cthi/id :test-token-set)
|
||||
(ctob/make-token :id (cthi/new-id! :test-token-3)
|
||||
:name "test-token-3"
|
||||
:type :border-radius
|
||||
@@ -208,7 +208,6 @@
|
||||
|
||||
;; ==== Action
|
||||
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)
|
||||
{:name "test-token-1"
|
||||
:type :border-radius
|
||||
@@ -328,32 +327,32 @@
|
||||
(ctob/add-theme (ctob/make-token-theme :name "test-theme"
|
||||
:sets #{"test-token-set"}))
|
||||
(ctob/set-active-themes #{"/test-theme"})
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (cthi/id :test-token-set)
|
||||
(ctob/make-token :id (cthi/new-id! :token-radius)
|
||||
:name "token-radius"
|
||||
:type :border-radius
|
||||
:value 10))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (cthi/id :test-token-set)
|
||||
(ctob/make-token :id (cthi/new-id! :token-rotation)
|
||||
:name "token-rotation"
|
||||
:type :rotation
|
||||
:value 30))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (cthi/id :test-token-set)
|
||||
(ctob/make-token :id (cthi/new-id! :token-opacity)
|
||||
:name "token-opacity"
|
||||
:type :opacity
|
||||
:value 0.7))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (cthi/id :test-token-set)
|
||||
(ctob/make-token :id (cthi/new-id! :token-stroke-width)
|
||||
:name "token-stroke-width"
|
||||
:type :stroke-width
|
||||
:value 2))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (cthi/id :test-token-set)
|
||||
(ctob/make-token :id (cthi/new-id! :token-color)
|
||||
:name "token-color"
|
||||
:type :color
|
||||
:value "#00ff00"))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (cthi/id :test-token-set)
|
||||
(ctob/make-token :id (cthi/new-id! :token-dimensions)
|
||||
:name "token-dimensions"
|
||||
:type :dimensions
|
||||
@@ -372,7 +371,6 @@
|
||||
|
||||
;; ==== Action
|
||||
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)
|
||||
{:name "token-radius"
|
||||
:value 30})
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
(:require
|
||||
[app.common.test-helpers.compositions :as tho]
|
||||
[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.tokens :as tht]
|
||||
[app.common.types.tokens-lib :as ctob]
|
||||
@@ -16,35 +17,35 @@
|
||||
(ctob/add-theme (ctob/make-token-theme :name "test-theme"
|
||||
:sets #{"test-token-set"}))
|
||||
(ctob/set-active-themes #{"/test-theme"})
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :name "token-radius"
|
||||
:type :border-radius
|
||||
:value 10))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :name "token-color"
|
||||
:type :color
|
||||
:value "red"))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :name "token-spacing"
|
||||
:type :spacing
|
||||
:value 10))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :name "token-sizing"
|
||||
:type :sizing
|
||||
:value 10))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :name "token-rotation"
|
||||
:type :rotation
|
||||
:value 10))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :name "token-opacity"
|
||||
:type :opacity
|
||||
:value 10))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :name "token-dimensions"
|
||||
:type :dimensions
|
||||
:value 10))
|
||||
(ctob/add-token-in-set "test-token-set"
|
||||
(ctob/add-token-in-set (thi/id :test-token-set)
|
||||
(ctob/make-token :name "token-number"
|
||||
:type :number
|
||||
:value 10))))
|
||||
|
||||
@@ -47,9 +47,12 @@
|
||||
(-> (ctob/make-tokens-lib)
|
||||
(ctob/add-theme (ctob/make-token-theme :name "Theme A" :sets #{"Set A"}))
|
||||
(ctob/set-active-themes #{"/Theme A"})
|
||||
(ctob/add-set (ctob/make-token-set :name "Set A"))
|
||||
(ctob/add-token-in-set "Set A" (ctob/make-token border-radius-token))
|
||||
(ctob/add-token-in-set "Set A" (ctob/make-token reference-border-radius-token))))))
|
||||
(ctob/add-set (ctob/make-token-set :id (cthi/new-id! :set-a)
|
||||
:name "Set A"))
|
||||
(ctob/add-token-in-set (cthi/id :set-a)
|
||||
(ctob/make-token border-radius-token))
|
||||
(ctob/add-token-in-set (cthi/id :set-a)
|
||||
(ctob/make-token reference-border-radius-token))))))
|
||||
|
||||
(t/deftest test-apply-token
|
||||
(t/testing "applies token to shape and updates shape attributes to resolved value"
|
||||
@@ -190,8 +193,10 @@
|
||||
file (-> (setup-file-with-tokens)
|
||||
(update-in [:data :tokens-lib]
|
||||
#(-> %
|
||||
(ctob/add-token-in-set "Set A" (ctob/make-token color-token))
|
||||
(ctob/add-token-in-set "Set A" (ctob/make-token color-alpha-token)))))
|
||||
(ctob/add-token-in-set (cthi/id :set-a)
|
||||
(ctob/make-token color-token))
|
||||
(ctob/add-token-in-set (cthi/id :set-a)
|
||||
(ctob/make-token color-alpha-token)))))
|
||||
store (ths/setup-store file)
|
||||
rect-1 (cths/get-shape file :rect-1)
|
||||
rect-2 (cths/get-shape file :rect-2)
|
||||
@@ -248,7 +253,8 @@
|
||||
:type :dimensions}
|
||||
file (-> (setup-file-with-tokens)
|
||||
(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)
|
||||
rect-1 (cths/get-shape file :rect-1)
|
||||
events [(dwta/apply-token {:shape-ids [(:id rect-1)]
|
||||
@@ -280,7 +286,8 @@
|
||||
(ctho/add-frame :frame-1)
|
||||
(ctho/add-frame :frame-2 {:layout :grid})
|
||||
(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)
|
||||
frame-1 (cths/get-shape file :frame-1)
|
||||
frame-2 (cths/get-shape file :frame-2)
|
||||
@@ -319,7 +326,8 @@
|
||||
:type :sizing}
|
||||
file (-> (setup-file-with-tokens)
|
||||
(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)
|
||||
rect-1 (cths/get-shape file :rect-1)
|
||||
events [(dwta/apply-token {:shape-ids [(:id rect-1)]
|
||||
@@ -356,9 +364,12 @@
|
||||
file (-> (setup-file-with-tokens)
|
||||
(update-in [:data :tokens-lib]
|
||||
#(-> %
|
||||
(ctob/add-token-in-set "Set A" (ctob/make-token opacity-float))
|
||||
(ctob/add-token-in-set "Set A" (ctob/make-token opacity-percent))
|
||||
(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-float))
|
||||
(ctob/add-token-in-set (cthi/id :set-a)
|
||||
(ctob/make-token opacity-percent))
|
||||
(ctob/add-token-in-set (cthi/id :set-a)
|
||||
(ctob/make-token opacity-invalid)))))
|
||||
store (ths/setup-store file)
|
||||
rect-1 (cths/get-shape file :rect-1)
|
||||
rect-2 (cths/get-shape file :rect-2)
|
||||
@@ -404,7 +415,8 @@
|
||||
:type :rotation}
|
||||
file (-> (setup-file-with-tokens)
|
||||
(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)
|
||||
rect-1 (cths/get-shape file :rect-1)
|
||||
events [(dwta/apply-token {:shape-ids [(:id rect-1)]
|
||||
@@ -434,7 +446,8 @@
|
||||
:stroke-opacity 1,
|
||||
:stroke-width 5}]}})
|
||||
(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)
|
||||
rect-with-stroke (cths/get-shape file :rect-1)
|
||||
rect-without-stroke (cths/get-shape file :rect-2)
|
||||
@@ -465,7 +478,8 @@
|
||||
:type :font-size}
|
||||
file (-> (setup-file-with-tokens)
|
||||
(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)
|
||||
text-1 (cths/get-shape file :text-1)
|
||||
events [(dwta/apply-token {:shape-ids [(:id text-1)]
|
||||
@@ -499,7 +513,8 @@
|
||||
:type :number}
|
||||
file (-> (setup-file-with-tokens)
|
||||
(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)
|
||||
text-1 (cths/get-shape file :text-1)
|
||||
events [(dwta/apply-token {:shape-ids [(:id text-1)]
|
||||
@@ -533,7 +548,8 @@
|
||||
:type :letter-spacing}
|
||||
file (-> (setup-file-with-tokens)
|
||||
(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)
|
||||
text-1 (cths/get-shape file :text-1)
|
||||
events [(dwta/apply-token {:shape-ids [(:id text-1)]
|
||||
@@ -567,7 +583,8 @@
|
||||
:type :font-family}
|
||||
file (-> (setup-file-with-tokens)
|
||||
(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)
|
||||
text-1 (cths/get-shape file :text-1)
|
||||
events [(dwta/apply-token {:shape-ids [(:id text-1)]
|
||||
@@ -601,7 +618,8 @@
|
||||
:type :text-case}
|
||||
file (-> (setup-file-with-tokens)
|
||||
(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)
|
||||
text-1 (cths/get-shape file :text-1)
|
||||
events [(dwta/apply-token {:shape-ids [(:id text-1)]
|
||||
@@ -635,7 +653,8 @@
|
||||
:type :text-decoration}
|
||||
file (-> (setup-file-with-tokens)
|
||||
(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)
|
||||
text-1 (cths/get-shape file :text-1)
|
||||
events [(dwta/apply-token {:shape-ids [(:id text-1)]
|
||||
@@ -669,7 +688,8 @@
|
||||
:type :font-weight}
|
||||
file (-> (setup-file-with-tokens)
|
||||
(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)
|
||||
text-1 (cths/get-shape file :text-1)
|
||||
events [(dwta/apply-token {:shape-ids [(:id text-1)]
|
||||
@@ -795,7 +815,8 @@
|
||||
{:frame-params {:layout :grid}})
|
||||
(ctho/add-rect :rect-regular)
|
||||
(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)
|
||||
frame-layout (cths/get-shape file :frame-layout)
|
||||
rect-in-layout (cths/get-shape file :rect-in-layout)
|
||||
@@ -838,7 +859,8 @@
|
||||
file (setup-file-with-tokens)
|
||||
file (-> file
|
||||
(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"
|
||||
:color "#abcdef"})
|
||||
(cths/update-shape :rect-1 :fills
|
||||
@@ -882,9 +904,9 @@
|
||||
file (-> (setup-file-with-tokens)
|
||||
(update-in [:data :tokens-lib]
|
||||
#(-> %
|
||||
(ctob/add-token-in-set "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 "Set A" (ctob/make-token typography-token)))))
|
||||
(ctob/add-token-in-set (cthi/id :set-a) (ctob/make-token font-size-token))
|
||||
(ctob/add-token-in-set (cthi/id :set-a) (ctob/make-token font-family-token))
|
||||
(ctob/add-token-in-set (cthi/id :set-a) (ctob/make-token typography-token)))))
|
||||
store (ths/setup-store file)
|
||||
text-1 (cths/get-shape file :text-1)
|
||||
events [(dwta/apply-token {:shape-ids [(:id text-1)]
|
||||
@@ -932,9 +954,9 @@
|
||||
file (-> (setup-file-with-tokens)
|
||||
(update-in [:data :tokens-lib]
|
||||
#(-> %
|
||||
(ctob/add-token-in-set "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 "Set A" (ctob/make-token typography-token)))))
|
||||
(ctob/add-token-in-set (cthi/id :set-a) (ctob/make-token font-size-token))
|
||||
(ctob/add-token-in-set (cthi/id :set-a) (ctob/make-token font-family-token))
|
||||
(ctob/add-token-in-set (cthi/id :set-a) (ctob/make-token typography-token)))))
|
||||
store (ths/setup-store file)
|
||||
text-1 (cths/get-shape file :text-1)
|
||||
events [(dwta/apply-token {:shape-ids [(:id text-1)]
|
||||
@@ -973,8 +995,8 @@
|
||||
file (-> (setup-file-with-tokens)
|
||||
(update-in [:data :tokens-lib]
|
||||
#(-> %
|
||||
(ctob/add-token-in-set "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 font-size-token))
|
||||
(ctob/add-token-in-set (cthi/id :set-a) (ctob/make-token typography-token)))))
|
||||
store (ths/setup-store file)
|
||||
text-1 (cths/get-shape file :text-1)
|
||||
events [(dwta/apply-token {:shape-ids [(:id text-1)]
|
||||
@@ -1007,8 +1029,8 @@
|
||||
file (-> (setup-file-with-tokens)
|
||||
(update-in [:data :tokens-lib]
|
||||
#(-> %
|
||||
(ctob/add-token-in-set "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 font-size-token))
|
||||
(ctob/add-token-in-set (cthi/id :set-a) (ctob/make-token typography-token)))))
|
||||
store (ths/setup-store file)
|
||||
text-1 (cths/get-shape file :text-1)
|
||||
events [(dwta/apply-token {:shape-ids [(:id text-1)]
|
||||
@@ -1044,9 +1066,12 @@
|
||||
file (-> (setup-file-with-tokens)
|
||||
(update-in [:data :tokens-lib]
|
||||
#(-> %
|
||||
(ctob/add-token-in-set "Set A" (ctob/make-token font-size-token))
|
||||
(ctob/add-token-in-set "Set A" (ctob/make-token line-height-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 font-size-token))
|
||||
(ctob/add-token-in-set (cthi/id :set-a)
|
||||
(ctob/make-token line-height-token))
|
||||
(ctob/add-token-in-set (cthi/id :set-a)
|
||||
(ctob/make-token letter-spacing-token))))
|
||||
(cths/add-sample-typography :typography1 {:name "Test typography"}))
|
||||
content {:type "root"
|
||||
:children [{:type "paragraph-set"
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
[app.common.test-helpers.files :as cthf]
|
||||
[app.common.test-helpers.ids-map :as cthi]
|
||||
[app.common.types.tokens-lib :as ctob]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.workspace.tokens.library-edit :as dwtl]
|
||||
[cljs.test :as t :include-macros true]
|
||||
[frontend-tests.helpers.pages :as thp]
|
||||
@@ -76,7 +77,7 @@
|
||||
done
|
||||
(let [file (setup-file-with-token-lib)
|
||||
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
|
||||
store done events
|
||||
@@ -93,7 +94,7 @@
|
||||
done
|
||||
(let [file (setup-file-with-token-lib)
|
||||
store (ths/setup-store file)
|
||||
events [(dwtl/duplicate-token-set "Set B" false)]]
|
||||
events [(dwtl/duplicate-token-set (uuid/next))]]
|
||||
|
||||
(tohs/run-store-async
|
||||
store done events
|
||||
@@ -110,7 +111,7 @@
|
||||
done
|
||||
(let [file (setup-file-with-token-lib)
|
||||
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
|
||||
store done events
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
(ns frontend-tests.tokens.style-dictionary-test
|
||||
(:require
|
||||
[app.common.test-helpers.ids-map :as cthi]
|
||||
[app.common.types.tokens-lib :as ctob]
|
||||
[app.main.data.style-dictionary :as sd]
|
||||
[beicon.v2.core :as rx]
|
||||
@@ -16,22 +17,28 @@
|
||||
done
|
||||
(t/testing "resolves tokens using style-dictionary from a ids map"
|
||||
(let [tokens (-> (ctob/make-tokens-lib)
|
||||
(ctob/add-set (ctob/make-token-set :name "core"))
|
||||
(ctob/add-token-in-set "core" (ctob/make-token {:name "borderRadius.sm"
|
||||
:value "12px"
|
||||
:type :border-radius}))
|
||||
(ctob/add-token-in-set "core" (ctob/make-token {:value "{borderRadius.sm} * 2"
|
||||
:name "borderRadius.md-with-dashes"
|
||||
:type :border-radius}))
|
||||
(ctob/add-token-in-set "core" (ctob/make-token {:name "borderRadius.large"
|
||||
:value "123456789012345"
|
||||
:type :border-radius}))
|
||||
(ctob/add-token-in-set "core" (ctob/make-token {:name "borderRadius.largePx"
|
||||
:value "123456789012345px"
|
||||
:type :border-radius}))
|
||||
(ctob/add-token-in-set "core" (ctob/make-token {:name "borderRadius.largeFn"
|
||||
:value "{borderRadius.sm} * 200000000"
|
||||
:type :border-radius}))
|
||||
(ctob/add-set (ctob/make-token-set :id (cthi/new-id! :core-set)
|
||||
:name "core"))
|
||||
(ctob/add-token-in-set (cthi/id :core-set)
|
||||
(ctob/make-token {:name "borderRadius.sm"
|
||||
:value "12px"
|
||||
:type :border-radius}))
|
||||
(ctob/add-token-in-set (cthi/id :core-set)
|
||||
(ctob/make-token {:value "{borderRadius.sm} * 2"
|
||||
:name "borderRadius.md-with-dashes"
|
||||
:type :border-radius}))
|
||||
(ctob/add-token-in-set (cthi/id :core-set)
|
||||
(ctob/make-token {:name "borderRadius.large"
|
||||
:value "123456789012345"
|
||||
:type :border-radius}))
|
||||
(ctob/add-token-in-set (cthi/id :core-set)
|
||||
(ctob/make-token {:name "borderRadius.largePx"
|
||||
:value "123456789012345px"
|
||||
:type :border-radius}))
|
||||
(ctob/add-token-in-set (cthi/id :core-set)
|
||||
(ctob/make-token {:name "borderRadius.largeFn"
|
||||
:value "{borderRadius.sm} * 200000000"
|
||||
:type :border-radius}))
|
||||
(ctob/get-all-tokens))]
|
||||
(-> (sd/resolve-tokens tokens)
|
||||
(rx/sub!
|
||||
|
||||
Reference in New Issue
Block a user