0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-21 06:02:32 -05:00

Create temporary theme when creating set

This commit is contained in:
Florian Schroedl 2024-08-16 10:32:59 +02:00
parent 9329513949
commit 879ef1123f
7 changed files with 85 additions and 12 deletions

View file

@ -249,6 +249,16 @@
[:type [:= :del-typography]]
[: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
[:map {:title "AddTokenThemeChange"}
[:type [:= :add-token-theme]]
@ -776,6 +786,14 @@
[data {:keys [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
[data {:keys [token-theme]}]
(ctotl/add-token-theme data token-theme))

View file

@ -695,6 +695,13 @@
(update :undo-changes conj {:type :add-typography :typography prev-typography})
(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
[changes token-theme]
(-> changes

View file

@ -65,6 +65,9 @@
[:map-of {:gen/max 5} :keyword ::ctpg/plugin-data]]
[:token-theme-temporary-id {:optional true}
::sm/uuid]
[:token-active-themes {:optional true
:default #{}}
[:set ::sm/uuid]]
[:token-themes {:optional true}
[:vector ::sm/uuid]]
[:token-themes-index {:optional true}

View file

@ -13,7 +13,7 @@
[:id ::sm/uuid]
[:name :string]
[:group {:optional true} :string]
[:selected [:enum :enabled :disabled #_:source]]
[:source? {:optional true} :boolean]
[:description {:optional true} :string]
[:modified-at {:optional true} ::sm/inst]
[:sets [:set {:gen/max 10 :gen/min 1} ::sm/uuid]]])

View file

@ -14,6 +14,19 @@
[token-set]
(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
[file-data {:keys [index id] :as token-theme}]
(-> file-data

View file

@ -147,17 +147,31 @@
selected-token-set-id (if create-set?
(:id new-token-set)
(:id token-set))
changes (cond
create-set? (-> token-changes
(pcb/add-token-set new-token-set))
:else (let [updated-token-set (if (contains? token-set (:id token))
token-set
(update token-set :tokens conj (:id token)))]
(-> token-changes
(pcb/update-token-set updated-token-set token-set))))]
set-changes (cond
create-set? (-> token-changes
(pcb/add-token-set new-token-set))
:else (let [updated-token-set (if (contains? token-set (:id token))
token-set
(update token-set :tokens conj (:id token)))]
(-> token-changes
(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
(set-selected-token-set-id selected-token-set-id)
(dch/commit-changes changes)))))))
(dch/commit-changes theme-changes)))))))
(defn delete-token
[id]

View file

@ -17,8 +17,26 @@
(->> (map #(get themes-index %) themes)
(group-by :group))))
(defn theme-selected? [theme]
(= :enabled (:selected theme)))
(defn get-active-theme-ids [state]
(: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 ------------------------------------------------------------------------