mirror of
https://github.com/penpot/penpot.git
synced 2025-06-10 16:41:39 +02:00
Create temporary theme when creating set
This commit is contained in:
parent
9329513949
commit
879ef1123f
7 changed files with 85 additions and 12 deletions
|
@ -249,6 +249,16 @@
|
||||||
[:type [:= :del-typography]]
|
[:type [:= :del-typography]]
|
||||||
[:id ::sm/uuid]]]
|
[:id ::sm/uuid]]]
|
||||||
|
|
||||||
|
[:add-temporary-token-theme
|
||||||
|
[:map {:title "AddTemporaryTokenThemeChange"}
|
||||||
|
[:type [:= :add-temporary-token-theme]]
|
||||||
|
[:token-theme ::ctot/token-theme]]]
|
||||||
|
|
||||||
|
[:delete-temporary-token-theme
|
||||||
|
[:map {:title "DeleteTemporaryTokenThemeChange"}
|
||||||
|
[:type [:= :delete-temporary-token-theme]]
|
||||||
|
[:id ::sm/uuid]]]
|
||||||
|
|
||||||
[:add-token-theme
|
[:add-token-theme
|
||||||
[:map {:title "AddTokenThemeChange"}
|
[:map {:title "AddTokenThemeChange"}
|
||||||
[:type [:= :add-token-theme]]
|
[:type [:= :add-token-theme]]
|
||||||
|
@ -776,6 +786,14 @@
|
||||||
[data {:keys [id]}]
|
[data {:keys [id]}]
|
||||||
(ctol/delete-token data id))
|
(ctol/delete-token data id))
|
||||||
|
|
||||||
|
(defmethod process-change :add-temporary-token-theme
|
||||||
|
[data {:keys [token-theme]}]
|
||||||
|
(ctotl/add-temporary-token-theme data token-theme))
|
||||||
|
|
||||||
|
(defmethod process-change :delete-temporary-token-theme
|
||||||
|
[data {:keys [id]}]
|
||||||
|
(ctotl/delete-temporary-token-theme data id))
|
||||||
|
|
||||||
(defmethod process-change :add-token-theme
|
(defmethod process-change :add-token-theme
|
||||||
[data {:keys [token-theme]}]
|
[data {:keys [token-theme]}]
|
||||||
(ctotl/add-token-theme data token-theme))
|
(ctotl/add-token-theme data token-theme))
|
||||||
|
|
|
@ -695,6 +695,13 @@
|
||||||
(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-temporary-token-theme
|
||||||
|
[changes token-theme]
|
||||||
|
(-> changes
|
||||||
|
(update :redo-changes conj {:type :add-temporary-token-theme :token-theme token-theme})
|
||||||
|
(update :undo-changes conj {:type :delete-temporary-token-theme :id (:id token-theme)})
|
||||||
|
(apply-changes-local)))
|
||||||
|
|
||||||
(defn add-token-theme
|
(defn add-token-theme
|
||||||
[changes token-theme]
|
[changes token-theme]
|
||||||
(-> changes
|
(-> changes
|
||||||
|
|
|
@ -65,6 +65,9 @@
|
||||||
[:map-of {:gen/max 5} :keyword ::ctpg/plugin-data]]
|
[:map-of {:gen/max 5} :keyword ::ctpg/plugin-data]]
|
||||||
[:token-theme-temporary-id {:optional true}
|
[:token-theme-temporary-id {:optional true}
|
||||||
::sm/uuid]
|
::sm/uuid]
|
||||||
|
[:token-active-themes {:optional true
|
||||||
|
:default #{}}
|
||||||
|
[:set ::sm/uuid]]
|
||||||
[:token-themes {:optional true}
|
[:token-themes {:optional true}
|
||||||
[:vector ::sm/uuid]]
|
[:vector ::sm/uuid]]
|
||||||
[:token-themes-index {:optional true}
|
[:token-themes-index {:optional true}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
[:id ::sm/uuid]
|
[:id ::sm/uuid]
|
||||||
[:name :string]
|
[:name :string]
|
||||||
[:group {:optional true} :string]
|
[:group {:optional true} :string]
|
||||||
[:selected [:enum :enabled :disabled #_:source]]
|
[:source? {:optional true} :boolean]
|
||||||
[:description {:optional true} :string]
|
[:description {:optional true} :string]
|
||||||
[:modified-at {:optional true} ::sm/inst]
|
[:modified-at {:optional true} ::sm/inst]
|
||||||
[:sets [:set {:gen/max 10 :gen/min 1} ::sm/uuid]]])
|
[:sets [:set {:gen/max 10 :gen/min 1} ::sm/uuid]]])
|
||||||
|
|
|
@ -14,6 +14,19 @@
|
||||||
[token-set]
|
[token-set]
|
||||||
(assoc token-set :modified-at (dt/now)))
|
(assoc token-set :modified-at (dt/now)))
|
||||||
|
|
||||||
|
(defn add-temporary-token-theme
|
||||||
|
[file-data {:keys [id] :as token-theme}]
|
||||||
|
(-> file-data
|
||||||
|
(d/dissoc-in [:token-themes-index (:token-theme-temporary-id file-data)])
|
||||||
|
(assoc :token-theme-temporary-id id)
|
||||||
|
(update :token-themes-index assoc id token-theme)))
|
||||||
|
|
||||||
|
(defn delete-temporary-token-theme
|
||||||
|
[file-data token-theme-id]
|
||||||
|
(cond-> file-data
|
||||||
|
(= (:token-theme-temporary-id file-data) token-theme-id) (dissoc :token-theme-temporary-id)
|
||||||
|
:always (d/dissoc-in [:token-themes-index (:token-theme-temporary-id file-data)])))
|
||||||
|
|
||||||
(defn add-token-theme
|
(defn add-token-theme
|
||||||
[file-data {:keys [index id] :as token-theme}]
|
[file-data {:keys [index id] :as token-theme}]
|
||||||
(-> file-data
|
(-> file-data
|
||||||
|
|
|
@ -147,17 +147,31 @@
|
||||||
selected-token-set-id (if create-set?
|
selected-token-set-id (if create-set?
|
||||||
(:id new-token-set)
|
(:id new-token-set)
|
||||||
(:id token-set))
|
(:id token-set))
|
||||||
changes (cond
|
set-changes (cond
|
||||||
create-set? (-> token-changes
|
create-set? (-> token-changes
|
||||||
(pcb/add-token-set new-token-set))
|
(pcb/add-token-set new-token-set))
|
||||||
:else (let [updated-token-set (if (contains? token-set (:id token))
|
:else (let [updated-token-set (if (contains? token-set (:id token))
|
||||||
token-set
|
token-set
|
||||||
(update token-set :tokens conj (:id token)))]
|
(update token-set :tokens conj (:id token)))]
|
||||||
(-> token-changes
|
(-> token-changes
|
||||||
(pcb/update-token-set updated-token-set token-set))))]
|
(pcb/update-token-set updated-token-set token-set))))
|
||||||
|
theme-id (wtts/update-theme-id state)
|
||||||
|
theme (some-> theme-id (wtts/get-workspace-token-theme state))
|
||||||
|
theme-changes (cond
|
||||||
|
(not theme-id) (-> set-changes
|
||||||
|
(pcb/add-temporary-token-theme
|
||||||
|
|
||||||
|
{:id (uuid/next)
|
||||||
|
:name ""
|
||||||
|
:sets #{selected-token-set-id}}))
|
||||||
|
create-set? (-> set-changes
|
||||||
|
(pcb/update-token-theme
|
||||||
|
(wtts/add-token-set-to-token-theme selected-token-set-id theme)
|
||||||
|
theme))
|
||||||
|
:else set-changes)]
|
||||||
(rx/of
|
(rx/of
|
||||||
(set-selected-token-set-id selected-token-set-id)
|
(set-selected-token-set-id selected-token-set-id)
|
||||||
(dch/commit-changes changes)))))))
|
(dch/commit-changes theme-changes)))))))
|
||||||
|
|
||||||
(defn delete-token
|
(defn delete-token
|
||||||
[id]
|
[id]
|
||||||
|
|
|
@ -17,8 +17,26 @@
|
||||||
(->> (map #(get themes-index %) themes)
|
(->> (map #(get themes-index %) themes)
|
||||||
(group-by :group))))
|
(group-by :group))))
|
||||||
|
|
||||||
(defn theme-selected? [theme]
|
(defn get-active-theme-ids [state]
|
||||||
(= :enabled (:selected theme)))
|
(:token-active-themes state))
|
||||||
|
|
||||||
|
(defn get-temp-theme-id [state]
|
||||||
|
(:token-theme-temporary-id state))
|
||||||
|
|
||||||
|
(defn update-theme-id
|
||||||
|
[state]
|
||||||
|
(let [active-themes (get-active-theme-ids state)
|
||||||
|
temporary-theme-id (get-temp-theme-id state)]
|
||||||
|
(cond
|
||||||
|
(empty? active-themes) temporary-theme-id
|
||||||
|
(= 1 (count active-themes)) (first active-themes)
|
||||||
|
:else temporary-theme-id)))
|
||||||
|
|
||||||
|
(defn get-workspace-token-theme [id state]
|
||||||
|
(get-in state (get-in state [:workspace-data :token-sets-index id])))
|
||||||
|
|
||||||
|
(defn add-token-set-to-token-theme [token-set-id token-theme]
|
||||||
|
(update token-theme :sets conj token-set-id))
|
||||||
|
|
||||||
;; Sets ------------------------------------------------------------------------
|
;; Sets ------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue