mirror of
https://github.com/penpot/penpot.git
synced 2025-06-07 18:41:41 +02:00
🔥 Remove not necessary API from tokens-lib: add-sets
This commit is contained in:
parent
802c67ace4
commit
1e10e3818e
5 changed files with 29 additions and 41 deletions
|
@ -376,11 +376,6 @@
|
||||||
[:type [:= :update-active-token-themes]]
|
[:type [:= :update-active-token-themes]]
|
||||||
[:theme-ids [:set :string]]]]
|
[:theme-ids [:set :string]]]]
|
||||||
|
|
||||||
[:add-token-sets
|
|
||||||
[:map {:title "AddTokenSetsChange"}
|
|
||||||
[:type [:= :add-token-sets]]
|
|
||||||
[:token-sets [:sequential ::ctot/token-set]]]]
|
|
||||||
|
|
||||||
[:rename-token-set-group
|
[:rename-token-set-group
|
||||||
[:map {:title "RenameTokenSetGroup"}
|
[:map {:title "RenameTokenSetGroup"}
|
||||||
[:type [:= :rename-token-set-group]]
|
[:type [:= :rename-token-set-group]]
|
||||||
|
@ -1049,12 +1044,6 @@
|
||||||
(update data :tokens-lib #(-> % (ctob/ensure-tokens-lib)
|
(update data :tokens-lib #(-> % (ctob/ensure-tokens-lib)
|
||||||
(ctob/set-active-themes theme-ids))))
|
(ctob/set-active-themes theme-ids))))
|
||||||
|
|
||||||
(defmethod process-change :add-token-sets
|
|
||||||
[data {:keys [token-sets]}]
|
|
||||||
(update data :tokens-lib #(-> %
|
|
||||||
(ctob/ensure-tokens-lib)
|
|
||||||
(ctob/add-sets (map ctob/make-token-set token-sets)))))
|
|
||||||
|
|
||||||
(defmethod process-change :rename-token-set-group
|
(defmethod process-change :rename-token-set-group
|
||||||
[data {:keys [set-group-path set-group-fname]}]
|
[data {:keys [set-group-path set-group-fname]}]
|
||||||
(update data :tokens-lib (fn [lib]
|
(update data :tokens-lib (fn [lib]
|
||||||
|
|
|
@ -430,7 +430,6 @@
|
||||||
Prefixed set full path or pfpath: a full path wit prefixes [\"G-some-group\", \"G-some-subgroup\", \"S-some-set\"].
|
Prefixed set full path or pfpath: a full path wit prefixes [\"G-some-group\", \"G-some-subgroup\", \"S-some-set\"].
|
||||||
Prefixed set final name or pfname: a final name with prefix \"S-some-set\"."
|
Prefixed set final name or pfname: a final name with prefix \"S-some-set\"."
|
||||||
(add-set [_ token-set] "add a set to the library, at the end")
|
(add-set [_ token-set] "add a set to the library, at the end")
|
||||||
(add-sets [_ token-set] "add a collection of sets to the library, at the end")
|
|
||||||
(update-set [_ set-name f] "modify a set in the library")
|
(update-set [_ set-name f] "modify a set in the library")
|
||||||
(delete-set-path [_ set-path] "delete 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 [_ set-name] "delete a set at `set-name` in the library and disable the `set-name` in all themes")
|
||||||
|
@ -875,9 +874,6 @@ Will return a value that matches this schema:
|
||||||
themes
|
themes
|
||||||
active-themes)))
|
active-themes)))
|
||||||
|
|
||||||
(add-sets [this token-sets]
|
|
||||||
(reduce add-set this token-sets))
|
|
||||||
|
|
||||||
(update-set [this set-name f]
|
(update-set [this set-name f]
|
||||||
(let [prefixed-full-path (set-name->prefixed-full-path set-name)
|
(let [prefixed-full-path (set-name->prefixed-full-path set-name)
|
||||||
set (get-in sets prefixed-full-path)]
|
set (get-in sets prefixed-full-path)]
|
||||||
|
@ -1483,10 +1479,12 @@ Will return a value that matches this schema:
|
||||||
prev-sets (->> (fres/read-object! r)
|
prev-sets (->> (fres/read-object! r)
|
||||||
(tree-seq d/ordered-map? vals)
|
(tree-seq d/ordered-map? vals)
|
||||||
(filter (partial instance? TokenSet)))
|
(filter (partial instance? TokenSet)))
|
||||||
sets (-> (make-tokens-lib)
|
|
||||||
(add-sets prev-sets)
|
;; FIXME: wtf we usind deref here?
|
||||||
(deref)
|
sets (-> (reduce add-set (make-tokens-lib) prev-sets)
|
||||||
:sets)
|
(deref)
|
||||||
|
(:sets))
|
||||||
|
|
||||||
_set-groups (fres/read-object! r)
|
_set-groups (fres/read-object! r)
|
||||||
themes (fres/read-object! r)
|
themes (fres/read-object! r)
|
||||||
active-themes (fres/read-object! r)]
|
active-themes (fres/read-object! r)]
|
||||||
|
|
|
@ -86,22 +86,22 @@
|
||||||
|
|
||||||
(t/deftest move-token-set
|
(t/deftest move-token-set
|
||||||
(t/testing "flat"
|
(t/testing "flat"
|
||||||
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
||||||
(ctob/add-set (ctob/make-token-set :name "A"))
|
(ctob/add-set (ctob/make-token-set :name "A"))
|
||||||
(ctob/add-set (ctob/make-token-set :name "B"))
|
(ctob/add-set (ctob/make-token-set :name "B"))
|
||||||
(ctob/add-set (ctob/make-token-set :name "Move")))
|
(ctob/add-set (ctob/make-token-set :name "Move")))
|
||||||
move (fn [from-path to-path before-path before-group?]
|
move (fn [from-path to-path before-path before-group?]
|
||||||
(->> (ctob/move-set tokens-lib from-path to-path before-path before-group?)
|
(->> (ctob/move-set tokens-lib from-path to-path before-path before-group?)
|
||||||
(ctob/get-ordered-set-names)
|
(ctob/get-ordered-set-names)
|
||||||
(into [])))]
|
(into [])))]
|
||||||
(t/testing "move to top"
|
(t/testing "move to top"
|
||||||
(t/is (= ["Move" "A" "B"] (move ["Move"] ["Move"] ["A"] false))))
|
(t/is (= ["Move" "A" "B"] (move ["Move"] ["Move"] ["A"] false))))
|
||||||
|
|
||||||
(t/testing "move in-between"
|
(t/testing "move in-between"
|
||||||
(t/is (= ["A" "Move" "B"] (move ["Move"] ["Move"] ["B"] false))))
|
(t/is (= ["A" "Move" "B"] (move ["Move"] ["Move"] ["B"] false))))
|
||||||
|
|
||||||
(t/testing "move to bottom"
|
(t/testing "move to bottom"
|
||||||
(t/is (= ["A" "B" "Move"] (move ["Move"] ["Move"] nil false))))))
|
(t/is (= ["A" "B" "Move"] (move ["Move"] ["Move"] nil false))))))
|
||||||
|
|
||||||
(t/testing "nested"
|
(t/testing "nested"
|
||||||
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
||||||
|
@ -129,7 +129,7 @@
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "Theme"
|
(ctob/add-theme (ctob/make-token-theme :name "Theme"
|
||||||
:sets #{"Foo/Bar/Baz"}))
|
:sets #{"Foo/Bar/Baz"}))
|
||||||
(ctob/move-set ["Foo" "Bar" "Baz"] ["Other/Baz"] nil nil))]
|
(ctob/move-set ["Foo" "Bar" "Baz"] ["Other/Baz"] nil nil))]
|
||||||
(t/is (= #{"Other/Baz"} (:sets (ctob/get-theme tokens-lib "" "Theme")))))))
|
(t/is (= #{"Other/Baz"} (:sets (ctob/get-theme tokens-lib "" "Theme")))))))
|
||||||
|
|
||||||
(t/deftest move-token-set-group
|
(t/deftest move-token-set-group
|
||||||
(t/testing "reordering"
|
(t/testing "reordering"
|
||||||
|
@ -590,7 +590,7 @@
|
||||||
:type :boolean
|
:type :boolean
|
||||||
:value true))
|
:value true))
|
||||||
(ctob/add-theme (ctob/make-token-theme :name "test-token-theme"))
|
(ctob/add-theme (ctob/make-token-theme :name "test-token-theme"))
|
||||||
(ctob/toggle-set-in-theme "" "test-token-theme" "test-token-set"))
|
(ctob/toggle-set-in-theme "" "test-token-theme" "test-token-set"))
|
||||||
encoded-blob (fres/encode tokens-lib)
|
encoded-blob (fres/encode tokens-lib)
|
||||||
tokens-lib' (fres/decode encoded-blob)]
|
tokens-lib' (fres/decode encoded-blob)]
|
||||||
|
|
||||||
|
|
|
@ -139,7 +139,7 @@
|
||||||
(let [data (dsh/lookup-file-data state)
|
(let [data (dsh/lookup-file-data state)
|
||||||
tokens-lib (get data :tokens-lib)
|
tokens-lib (get data :tokens-lib)
|
||||||
set-name (ctob/normalize-set-name set-name)]
|
set-name (ctob/normalize-set-name set-name)]
|
||||||
(if (ctob/get-set tokens-lib set-name)
|
(if (and tokens-lib (ctob/get-set tokens-lib set-name))
|
||||||
(rx/of (ntf/show {:content (tr "errors.token-set-already-exists")
|
(rx/of (ntf/show {:content (tr "errors.token-set-already-exists")
|
||||||
:type :toast
|
:type :toast
|
||||||
:level :error
|
:level :error
|
||||||
|
|
|
@ -293,11 +293,12 @@
|
||||||
:on-save-form on-save-form
|
:on-save-form on-save-form
|
||||||
:disabled? disabled?}]]]]]))
|
:disabled? disabled?}]]]]]))
|
||||||
|
|
||||||
(defn- make-lib-with-theme [theme sets]
|
(defn- make-lib-with-theme
|
||||||
(-> (ctob/make-tokens-lib)
|
[theme sets]
|
||||||
(ctob/add-theme theme)
|
(let [tlib (-> (ctob/make-tokens-lib)
|
||||||
(ctob/add-sets sets)
|
(ctob/add-theme theme))
|
||||||
(ctob/activate-theme (:group theme) (:name theme))))
|
tlib (reduce ctob/add-set tlib sets)]
|
||||||
|
(ctob/activate-theme tlib (:group theme) (:name theme))))
|
||||||
|
|
||||||
(mf/defc controlled-edit-theme
|
(mf/defc controlled-edit-theme
|
||||||
[{:keys [state set-state]}]
|
[{:keys [state set-state]}]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue