mirror of
https://github.com/penpot/penpot.git
synced 2025-02-14 19:19:09 -05:00
Add token theme data scaffold
This commit is contained in:
parent
35759792a3
commit
3695ba3438
4 changed files with 86 additions and 0 deletions
|
@ -249,6 +249,22 @@
|
||||||
[:type [:= :del-typography]]
|
[:type [:= :del-typography]]
|
||||||
[:id ::sm/uuid]]]
|
[:id ::sm/uuid]]]
|
||||||
|
|
||||||
|
[:add-token-theme
|
||||||
|
[:map {:title "AddTokenThemeChange"}
|
||||||
|
[:type [:= :add-token-theme]]
|
||||||
|
[:token-theme ::ctot/token-theme]]]
|
||||||
|
|
||||||
|
[:mod-token-theme
|
||||||
|
[:map {:title "ModTokenThemeChange"}
|
||||||
|
[:type [:= :mod-token-theme]]
|
||||||
|
[:id ::sm/uuid]
|
||||||
|
[:token-theme ::ctot/token-theme]]]
|
||||||
|
|
||||||
|
[:del-token-theme
|
||||||
|
[:map {:title "DelTokenThemeChange"}
|
||||||
|
[:type [:= :del-token-theme]]
|
||||||
|
[:id ::sm/uuid]]]
|
||||||
|
|
||||||
[:add-token-set
|
[:add-token-set
|
||||||
[:map {:title "AddTokenSetChange"}
|
[:map {:title "AddTokenSetChange"}
|
||||||
[:type [:= :add-token-set]]
|
[:type [:= :add-token-set]]
|
||||||
|
@ -760,6 +776,18 @@
|
||||||
[data {:keys [id]}]
|
[data {:keys [id]}]
|
||||||
(ctol/delete-token data id))
|
(ctol/delete-token data id))
|
||||||
|
|
||||||
|
(defmethod process-change :add-token-theme
|
||||||
|
[data {:keys [token-theme]}]
|
||||||
|
(ctotl/add-token-theme data token-theme))
|
||||||
|
|
||||||
|
(defmethod process-change :mod-token-theme
|
||||||
|
[data {:keys [id token-theme]}]
|
||||||
|
(ctotl/update-token-theme data id merge token-theme))
|
||||||
|
|
||||||
|
(defmethod process-change :del-token-theme
|
||||||
|
[data {:keys [id]}]
|
||||||
|
(ctotl/delete-token-theme data id))
|
||||||
|
|
||||||
(defmethod process-change :add-token-set
|
(defmethod process-change :add-token-set
|
||||||
[data {:keys [token-set]}]
|
[data {:keys [token-set]}]
|
||||||
(ctotl/add-token-set data token-set))
|
(ctotl/add-token-set data token-set))
|
||||||
|
|
|
@ -695,6 +695,30 @@
|
||||||
(update :undo-changes conj {:type :add-typography :typography prev-typography})
|
(update :undo-changes conj {:type :add-typography :typography prev-typography})
|
||||||
(apply-changes-local))))
|
(apply-changes-local))))
|
||||||
|
|
||||||
|
(defn add-token-theme
|
||||||
|
[changes token-theme]
|
||||||
|
(-> changes
|
||||||
|
(update :redo-changes conj {:type :add-token-theme :token-theme token-theme})
|
||||||
|
(update :undo-changes conj {:type :del-token-theme :id (:id token-theme)})
|
||||||
|
(apply-changes-local)))
|
||||||
|
|
||||||
|
(defn update-token-theme
|
||||||
|
[changes token-theme prev-token-theme]
|
||||||
|
(-> changes
|
||||||
|
(update :redo-changes conj {:type :mod-token-theme :id (:id token-theme) :token-theme token-theme})
|
||||||
|
(update :undo-changes conj {:type :mod-token-theme :id (:id token-theme) :token-theme (or prev-token-theme token-theme)})
|
||||||
|
(apply-changes-local)))
|
||||||
|
|
||||||
|
(defn delete-token-theme
|
||||||
|
[changes token-theme-id]
|
||||||
|
(assert-library! changes)
|
||||||
|
(let [library-data (::library-data (meta changes))
|
||||||
|
prev-token-theme (get-in library-data [:token-theme token-theme-id])]
|
||||||
|
(-> changes
|
||||||
|
(update :redo-changes conj {:type :del-token-theme :id token-theme-id})
|
||||||
|
(update :undo-changes conj {:type :add-token-theme :token-theme prev-token-theme})
|
||||||
|
(apply-changes-local))))
|
||||||
|
|
||||||
(defn add-token-set
|
(defn add-token-set
|
||||||
[changes token-set]
|
[changes token-set]
|
||||||
(-> changes
|
(-> changes
|
||||||
|
|
|
@ -14,6 +14,26 @@
|
||||||
[token-set]
|
[token-set]
|
||||||
(assoc token-set :modified-at (dt/now)))
|
(assoc token-set :modified-at (dt/now)))
|
||||||
|
|
||||||
|
(defn add-token-theme
|
||||||
|
[file-data {:keys [index id] :as token-theme}]
|
||||||
|
(-> file-data
|
||||||
|
(update :token-themes
|
||||||
|
(fn [token-themes]
|
||||||
|
(let [exists? (some (partial = id) token-themes)]
|
||||||
|
(cond
|
||||||
|
exists? token-themes
|
||||||
|
(nil? index) (conj (or token-themes []) id)
|
||||||
|
:else (d/insert-at-index token-themes index [id])))))
|
||||||
|
(update :token-themes-index assoc id token-theme)))
|
||||||
|
|
||||||
|
(defn update-token-theme
|
||||||
|
[file-data token-theme-id f & args]
|
||||||
|
(d/update-in-when file-data [:token-themes-index token-theme-id] #(-> (apply f % args) (touch))))
|
||||||
|
|
||||||
|
(defn delete-token-theme
|
||||||
|
[file-data token-id]
|
||||||
|
file-data)
|
||||||
|
|
||||||
(defn add-token-set
|
(defn add-token-set
|
||||||
[file-data {:keys [index id] :as token-set}]
|
[file-data {:keys [index id] :as token-set}]
|
||||||
(-> file-data
|
(-> file-data
|
||||||
|
|
|
@ -88,6 +88,20 @@
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(wtts/assoc-selected-token-set-id state id))))
|
(wtts/assoc-selected-token-set-id state id))))
|
||||||
|
|
||||||
|
(defn create-token-theme [token-theme]
|
||||||
|
(let [new-token-theme (merge
|
||||||
|
{:id (uuid/next)
|
||||||
|
:sets #{}
|
||||||
|
:selected :enabled}
|
||||||
|
token-theme)]
|
||||||
|
(ptk/reify ::create-token-theme
|
||||||
|
ptk/WatchEvent
|
||||||
|
(watch [it _ _]
|
||||||
|
(let [changes (-> (pcb/empty-changes it)
|
||||||
|
(pcb/add-token-theme new-token-theme))]
|
||||||
|
(rx/of
|
||||||
|
(dch/commit-changes changes)))))))
|
||||||
|
|
||||||
(defn create-token-set [token-set]
|
(defn create-token-set [token-set]
|
||||||
(let [new-token-set (merge
|
(let [new-token-set (merge
|
||||||
{:id (uuid/next)
|
{:id (uuid/next)
|
||||||
|
|
Loading…
Add table
Reference in a new issue