Add token set changes

This commit is contained in:
Florian Schroedl
2024-08-13 11:57:06 +02:00
parent 9ff3a135a8
commit 547358d579
5 changed files with 78 additions and 11 deletions

View File

@@ -24,6 +24,7 @@
[app.common.types.shape :as cts]
[app.common.types.shape-tree :as ctst]
[app.common.types.token :as cto]
[app.common.types.token-theme :as ctot]
[app.common.types.tokens-list :as ctol]
[app.common.types.typographies-list :as ctyl]
[app.common.types.typography :as ctt]
@@ -247,6 +248,21 @@
[:type [:= :del-typography]]
[:id ::sm/uuid]]]
[:add-token-set
[:map {:title "AddTokenSetChange"}
[:type [:= :add-token-set]]
[:token-set ::ctot/token-set]]]
[:mod-token-set
[:map {:title "ModTokenSetChange"}
[:type [:= :mod-token-set]]
[:id ::ctot/token-set]]]
[:del-token-set
[:map {:title "DelTokenSetChange"}
[:type [:= :del-token-set]]
[:id ::sm/uuid]]]
[:add-token
[:map {:title "AddTokenChange"}
[:type [:= :add-token]]

View File

@@ -695,6 +695,30 @@
(update :undo-changes conj {:type :add-typography :typography prev-typography})
(apply-changes-local))))
(defn add-token-set
[changes token-set]
(-> changes
(update :redo-changes conj {:type :add-token-set :token-set token-set})
(update :undo-changes conj {:type :del-token-set :id (:id token-set)})
(apply-changes-local)))
(defn update-token-set
[changes token-set prev-token-set]
(-> changes
(update :redo-changes conj {:type :mod-token-set :id (:id token-set) :token-set token-set})
(update :undo-changes conj {:type :mod-token-set :id (:id token-set) :token-set (or prev-token-set token-set)})
(apply-changes-local)))
(defn delete-token-set
[changes token-set-id]
(assert-library! changes)
(let [library-data (::library-data (meta changes))
prev-token-set (get-in library-data [:token-set token-set-id])]
(-> changes
(update :redo-changes conj {:type :del-token-set :id token-set-id})
(update :undo-changes conj {:type :add-token-set :token prev-token-set})
(apply-changes-local))))
(defn add-token
[changes token]
(-> changes