mirror of
https://github.com/penpot/penpot.git
synced 2025-07-08 22:07:16 +02:00
Set toggling without a theme
This commit is contained in:
parent
0b2b8a71fb
commit
e216d84484
5 changed files with 55 additions and 39 deletions
|
@ -274,7 +274,7 @@
|
||||||
[:mod-token-theme
|
[:mod-token-theme
|
||||||
[:map {:title "ModTokenThemeChange"}
|
[:map {:title "ModTokenThemeChange"}
|
||||||
[:type [:= :mod-token-theme]]
|
[:type [:= :mod-token-theme]]
|
||||||
(dm/legacy [:id {:optional true} [:maybe ::sm/uuid]])
|
[:group :string]
|
||||||
[:name :string]
|
[:name :string]
|
||||||
[:token-theme ::ctot/token-theme]]]
|
[:token-theme ::ctot/token-theme]]]
|
||||||
|
|
||||||
|
@ -820,23 +820,13 @@
|
||||||
set-name
|
set-name
|
||||||
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
|
(defmethod process-change :add-temporary-token-theme
|
||||||
[data {:keys [token-theme]}]
|
[data {:keys [token-theme]}]
|
||||||
(-> data
|
(-> data
|
||||||
(update :tokens-lib
|
(update :tokens-lib
|
||||||
#(-> %
|
#(-> %
|
||||||
(ctob/ensure-tokens-lib)
|
(ctob/ensure-tokens-lib)
|
||||||
(ctob/add-theme (-> token-theme
|
(ctob/add-theme (ctob/make-token-theme token-theme))))))
|
||||||
(update :sets (partial set-ids->names data))
|
|
||||||
(ctob/make-token-theme)))))))
|
|
||||||
|
|
||||||
(defmethod process-change :update-active-token-themes
|
(defmethod process-change :update-active-token-themes
|
||||||
[data {:keys [theme-ids]}]
|
[data {:keys [theme-ids]}]
|
||||||
|
@ -860,7 +850,6 @@
|
||||||
#(-> %
|
#(-> %
|
||||||
(ctob/ensure-tokens-lib)
|
(ctob/ensure-tokens-lib)
|
||||||
(ctob/add-theme (-> token-theme
|
(ctob/add-theme (-> token-theme
|
||||||
(update :sets (partial set-ids->names data))
|
|
||||||
(ctob/make-token-theme)))))))
|
(ctob/make-token-theme)))))))
|
||||||
|
|
||||||
(defmethod process-change :mod-token-theme
|
(defmethod process-change :mod-token-theme
|
||||||
|
@ -869,11 +858,9 @@
|
||||||
(update :tokens-lib
|
(update :tokens-lib
|
||||||
#(-> %
|
#(-> %
|
||||||
(ctob/ensure-tokens-lib)
|
(ctob/ensure-tokens-lib)
|
||||||
(ctob/update-theme name group
|
(ctob/update-theme group name
|
||||||
(fn [prev-theme]
|
(fn [prev-theme]
|
||||||
(merge prev-theme
|
(merge prev-theme token-theme)))))))
|
||||||
(-> token-theme
|
|
||||||
(update :sets (partial set-ids->names data))))))))))
|
|
||||||
|
|
||||||
(defmethod process-change :del-token-theme
|
(defmethod process-change :del-token-theme
|
||||||
[data {:keys [group name]}]
|
[data {:keys [group name]}]
|
||||||
|
|
|
@ -719,10 +719,14 @@
|
||||||
|
|
||||||
(defn update-token-theme
|
(defn update-token-theme
|
||||||
[changes token-theme prev-token-theme]
|
[changes token-theme prev-token-theme]
|
||||||
(-> changes
|
(let [name (or (:name prev-token-theme)
|
||||||
(update :redo-changes conj {:type :mod-token-theme :name (:name prev-token-theme) :token-theme token-theme})
|
(:name token-theme))
|
||||||
(update :undo-changes conj {:type :mod-token-theme :name (:name token-theme) :token-theme (or prev-token-theme token-theme)})
|
group (or (:group prev-token-theme)
|
||||||
(apply-changes-local)))
|
(: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
|
(defn delete-token-theme
|
||||||
[changes group name]
|
[changes group name]
|
||||||
|
|
|
@ -6,18 +6,16 @@
|
||||||
|
|
||||||
(ns app.common.types.token-theme
|
(ns app.common.types.token-theme
|
||||||
(:require
|
(:require
|
||||||
[app.common.data.macros :as dm]
|
|
||||||
[app.common.schema :as sm]))
|
[app.common.schema :as sm]))
|
||||||
|
|
||||||
(sm/register! ::token-theme
|
(sm/register! ::token-theme
|
||||||
[:map {:title "TokenTheme"}
|
[:map {:title "TokenTheme"}
|
||||||
(dm/legacy [:id {:optional true} [:maybe ::sm/uuid]])
|
|
||||||
[:name :string]
|
[:name :string]
|
||||||
[:group {:optional true} :string]
|
[:group :string]
|
||||||
[:source? {:optional true} :boolean]
|
[:description [:maybe :string]]
|
||||||
[:description {:optional true} :string]
|
[:is-source :boolean]
|
||||||
[:modified-at {:optional true} ::sm/inst]
|
[:modified-at {:optional true} ::sm/inst]
|
||||||
[:sets [:set {:gen/max 10 :gen/min 1} ::sm/uuid]]])
|
[:sets :any]])
|
||||||
|
|
||||||
(sm/register! ::token-set
|
(sm/register! ::token-set
|
||||||
[:map {:title "TokenSet"}
|
[:map {:title "TokenSet"}
|
||||||
|
|
|
@ -48,6 +48,12 @@
|
||||||
(defn get-tokens-lib [state]
|
(defn get-tokens-lib [state]
|
||||||
(get-in state [:workspace-data :tokens-lib]))
|
(get-in state [:workspace-data :tokens-lib]))
|
||||||
|
|
||||||
|
(def hidden-token-theme-group
|
||||||
|
"")
|
||||||
|
|
||||||
|
(def hidden-token-theme-name
|
||||||
|
"__PENPOT__HIDDEN__TOKEN__SET__")
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; TOKENS Actions
|
;; TOKENS Actions
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
@ -193,21 +199,42 @@
|
||||||
(rx/of
|
(rx/of
|
||||||
(dch/commit-changes changes))))))
|
(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/reify ::toggle-token-set
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state _]
|
(watch [it state _]
|
||||||
(let [target-theme-id (wtts/get-temp-theme-id state)
|
(let [tokens-lib (get-tokens-lib state)
|
||||||
active-set-ids (wtts/get-active-set-ids state)
|
prev-theme (ctob/get-theme tokens-lib hidden-token-theme-group hidden-token-theme-name)
|
||||||
theme (-> (wtts/get-workspace-token-theme target-theme-id state)
|
theme (-> (or prev-theme (ctob/make-token-theme
|
||||||
(assoc :sets active-set-ids))
|
: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)
|
changes (-> (pcb/empty-changes it)
|
||||||
(pcb/update-token-theme
|
(pcb/update-active-token-themes #{(ctob/token-theme-path hidden-token-theme-group hidden-token-theme-name)} prev-active-token-themes))
|
||||||
(wtts/toggle-token-set-to-token-theme token-set-id theme)
|
changes' (if prev-theme
|
||||||
theme)
|
(pcb/update-token-theme changes theme prev-theme)
|
||||||
(pcb/update-active-token-themes #{target-theme-id} (wtts/get-active-theme-ids state)))]
|
(pcb/add-token-theme changes theme))]
|
||||||
(rx/of
|
(rx/of
|
||||||
(dch/commit-changes changes)
|
(dch/commit-changes changes')
|
||||||
(wtu/update-workspace-tokens))))))
|
(wtu/update-workspace-tokens))))))
|
||||||
|
|
||||||
(defn delete-token-set [token-set-name]
|
(defn delete-token-set [token-set-name]
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
(def ^:private chevron-icon
|
(def ^:private chevron-icon
|
||||||
(i/icon-xref :arrow (stl/css :chevron-icon)))
|
(i/icon-xref :arrow (stl/css :chevron-icon)))
|
||||||
|
|
||||||
(defn on-toggle-token-set-click [token-set-id]
|
(defn on-toggle-token-set-click [token-set-name]
|
||||||
(st/emit! (wdt/toggle-token-set {:token-set-id token-set-id})))
|
(st/emit! (wdt/toggle-token-set {:token-set-name token-set-name})))
|
||||||
|
|
||||||
(defn on-select-token-set-click [name]
|
(defn on-select-token-set-click [name]
|
||||||
(st/emit! (wdt/set-selected-token-set-id name)))
|
(st/emit! (wdt/set-selected-token-set-id name)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue