0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-04-14 07:51:35 -05:00

Set toggling without a theme

This commit is contained in:
Florian Schroedl 2024-09-26 11:28:14 +02:00
parent 0b2b8a71fb
commit e216d84484
5 changed files with 55 additions and 39 deletions

View file

@ -274,7 +274,7 @@
[:mod-token-theme
[:map {:title "ModTokenThemeChange"}
[:type [:= :mod-token-theme]]
(dm/legacy [:id {:optional true} [:maybe ::sm/uuid]])
[:group :string]
[:name :string]
[:token-theme ::ctot/token-theme]]]
@ -820,23 +820,13 @@
set-name
name)))))
(defn- set-ids->names
[data sets]
(let [lib-sets (:token-sets-index data)
set-id->name
(fn [set-id]
(dm/get-in lib-sets [set-id :name]))]
(map set-id->name sets)))
(defmethod process-change :add-temporary-token-theme
[data {:keys [token-theme]}]
(-> data
(update :tokens-lib
#(-> %
(ctob/ensure-tokens-lib)
(ctob/add-theme (-> token-theme
(update :sets (partial set-ids->names data))
(ctob/make-token-theme)))))))
(ctob/add-theme (ctob/make-token-theme token-theme))))))
(defmethod process-change :update-active-token-themes
[data {:keys [theme-ids]}]
@ -860,7 +850,6 @@
#(-> %
(ctob/ensure-tokens-lib)
(ctob/add-theme (-> token-theme
(update :sets (partial set-ids->names data))
(ctob/make-token-theme)))))))
(defmethod process-change :mod-token-theme
@ -869,11 +858,9 @@
(update :tokens-lib
#(-> %
(ctob/ensure-tokens-lib)
(ctob/update-theme name group
(ctob/update-theme group name
(fn [prev-theme]
(merge prev-theme
(-> token-theme
(update :sets (partial set-ids->names data))))))))))
(merge prev-theme token-theme)))))))
(defmethod process-change :del-token-theme
[data {:keys [group name]}]

View file

@ -719,10 +719,14 @@
(defn update-token-theme
[changes token-theme prev-token-theme]
(-> changes
(update :redo-changes conj {:type :mod-token-theme :name (:name prev-token-theme) :token-theme token-theme})
(update :undo-changes conj {:type :mod-token-theme :name (:name token-theme) :token-theme (or prev-token-theme token-theme)})
(apply-changes-local)))
(let [name (or (:name prev-token-theme)
(:name token-theme))
group (or (:group prev-token-theme)
(:group token-theme))]
(-> changes
(update :redo-changes conj {:type :mod-token-theme :group group :name name :token-theme token-theme})
(update :undo-changes conj {:type :mod-token-theme :group group :name name :token-theme (or prev-token-theme token-theme)})
(apply-changes-local))))
(defn delete-token-theme
[changes group name]

View file

@ -6,18 +6,16 @@
(ns app.common.types.token-theme
(:require
[app.common.data.macros :as dm]
[app.common.schema :as sm]))
(sm/register! ::token-theme
[:map {:title "TokenTheme"}
(dm/legacy [:id {:optional true} [:maybe ::sm/uuid]])
[:name :string]
[:group {:optional true} :string]
[:source? {:optional true} :boolean]
[:description {:optional true} :string]
[:group :string]
[:description [:maybe :string]]
[:is-source :boolean]
[:modified-at {:optional true} ::sm/inst]
[:sets [:set {:gen/max 10 :gen/min 1} ::sm/uuid]]])
[:sets :any]])
(sm/register! ::token-set
[:map {:title "TokenSet"}

View file

@ -48,6 +48,12 @@
(defn get-tokens-lib [state]
(get-in state [:workspace-data :tokens-lib]))
(def hidden-token-theme-group
"")
(def hidden-token-theme-name
"__PENPOT__HIDDEN__TOKEN__SET__")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; TOKENS Actions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -193,21 +199,42 @@
(rx/of
(dch/commit-changes changes))))))
(defn toggle-token-set [{:keys [token-set-id]}]
#_[target-theme-id (wtts/get-temp-theme-id state)
active-set-ids (wtts/get-active-set-ids state)
theme (-> (wtts/get-workspace-token-theme target-theme-id state)
(assoc :sets active-set-ids))
changes (-> (pcb/empty-changes it)
(pcb/update-token-theme
(wtts/toggle-token-set-to-token-theme token-set-id theme)
theme)
(pcb/update-active-token-themes #{target-theme-id} (wtts/get-active-theme-ids state)))]
(comment
(-> (ctob/make-token-theme
:group ""
:name "bar")
(ctob/toggle-set "foo"))
nil)
(defn toggle-token-set [{:keys [token-set-name]}]
(ptk/reify ::toggle-token-set
ptk/WatchEvent
(watch [it state _]
(let [target-theme-id (wtts/get-temp-theme-id state)
active-set-ids (wtts/get-active-set-ids state)
theme (-> (wtts/get-workspace-token-theme target-theme-id state)
(assoc :sets active-set-ids))
(let [tokens-lib (get-tokens-lib state)
prev-theme (ctob/get-theme tokens-lib hidden-token-theme-group hidden-token-theme-name)
theme (-> (or prev-theme (ctob/make-token-theme
:group hidden-token-theme-group
:name hidden-token-theme-name))
(ctob/toggle-set token-set-name))
prev-active-token-themes (ctob/get-active-theme-paths tokens-lib)
changes (-> (pcb/empty-changes it)
(pcb/update-token-theme
(wtts/toggle-token-set-to-token-theme token-set-id theme)
theme)
(pcb/update-active-token-themes #{target-theme-id} (wtts/get-active-theme-ids state)))]
(pcb/update-active-token-themes #{(ctob/token-theme-path hidden-token-theme-group hidden-token-theme-name)} prev-active-token-themes))
changes' (if prev-theme
(pcb/update-token-theme changes theme prev-theme)
(pcb/add-token-theme changes theme))]
(rx/of
(dch/commit-changes changes)
(dch/commit-changes changes')
(wtu/update-workspace-tokens))))))
(defn delete-token-set [token-set-name]

View file

@ -20,8 +20,8 @@
(def ^:private chevron-icon
(i/icon-xref :arrow (stl/css :chevron-icon)))
(defn on-toggle-token-set-click [token-set-id]
(st/emit! (wdt/toggle-token-set {:token-set-id token-set-id})))
(defn on-toggle-token-set-click [token-set-name]
(st/emit! (wdt/toggle-token-set {:token-set-name token-set-name})))
(defn on-select-token-set-click [name]
(st/emit! (wdt/set-selected-token-set-id name)))