mirror of
https://github.com/penpot/penpot.git
synced 2025-01-21 06:02:32 -05:00
Add token set changes
This commit is contained in:
parent
9ff3a135a8
commit
547358d579
5 changed files with 78 additions and 11 deletions
|
@ -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]]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -80,18 +80,45 @@
|
|||
(let [workspace-data (deref refs/workspace-data)]
|
||||
(get (:tokens workspace-data) id)))
|
||||
|
||||
(defn get-workspace-sets [state]
|
||||
(get-in state [:workspace-data :token-sets-index]))
|
||||
|
||||
(defn get-token-set [set-id state]
|
||||
(some-> (get-workspace-sets state)
|
||||
(get set-id)))
|
||||
|
||||
(def default-token-set-name "Global")
|
||||
|
||||
(defn create-global-set [])
|
||||
|
||||
(defn add-token-to-token-set [token token-set]
|
||||
(update token-set :items conj (:id token)))
|
||||
|
||||
(defn update-create-token
|
||||
[token]
|
||||
[token set-id]
|
||||
(let [token (update token :id #(or % (uuid/next)))]
|
||||
(ptk/reify ::add-token
|
||||
ptk/WatchEvent
|
||||
(watch [it _ _]
|
||||
(watch [it state _]
|
||||
(let [prev-token (get-token-data-from-token-id (:id token))
|
||||
changes (if prev-token
|
||||
(-> (pcb/empty-changes it)
|
||||
(pcb/update-token token prev-token))
|
||||
(-> (pcb/empty-changes it)
|
||||
(pcb/add-token token)))]
|
||||
create-token? (not prev-token)
|
||||
token-changes (if create-token?
|
||||
(-> (pcb/empty-changes it)
|
||||
(pcb/add-token token))
|
||||
(-> (pcb/empty-changes it)
|
||||
(pcb/update-token token prev-token)))
|
||||
token-set (get-token-set state set-id)
|
||||
create-set? (not token-set)
|
||||
changes (cond
|
||||
create-set? (-> token-changes
|
||||
(pcb/add-token-set {:id (uuid/next)
|
||||
:name "Global"
|
||||
:items [(:id token)]}))
|
||||
:else (let [updated-token-set (if (contains? token-set (:id token))
|
||||
token-set
|
||||
(update token-set :items conj (:id token)))]
|
||||
(-> token-changes
|
||||
(pcb/update-token-set token-set updated-token-set))))]
|
||||
(rx/of (dch/commit-changes changes)))))))
|
||||
|
||||
(defn delete-token
|
||||
|
@ -107,11 +134,11 @@
|
|||
(rx/of (dch/commit-changes changes))))))
|
||||
|
||||
(defn duplicate-token
|
||||
[id]
|
||||
[id set-id]
|
||||
(let [new-token (-> (get-token-data-from-token-id id)
|
||||
(dissoc :id)
|
||||
(update :name #(str/concat % "-copy")))]
|
||||
(update-create-token new-token)))
|
||||
(update-create-token new-token set-id)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; TEMP (Move to test)
|
||||
|
|
|
@ -207,7 +207,7 @@
|
|||
[{:title "Delete Token"
|
||||
:action #(st/emit! (dt/delete-token (:id token)))}
|
||||
{:title "Duplicate Token"
|
||||
:action #(st/emit! (dt/duplicate-token (:id token)))}
|
||||
:action #(st/emit! (dt/duplicate-token (:id token) nil))}
|
||||
{:title "Edit Token"
|
||||
:action (fn [event]
|
||||
(let [{:keys [key fields]} modal
|
||||
|
|
|
@ -246,7 +246,7 @@ Token names should only contain letters and digits separated by . characters.")}
|
|||
:value final-value}
|
||||
final-description (assoc :description final-description)
|
||||
(:id token) (assoc :id (:id token)))]
|
||||
(st/emit! (dt/update-create-token new-token))
|
||||
(st/emit! (dt/update-create-token new-token nil))
|
||||
(st/emit! (wtu/update-workspace-tokens))
|
||||
(modal/hide!)))))))))]
|
||||
[:form
|
||||
|
|
Loading…
Add table
Reference in a new issue