diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index f7338da584..eb65fd6694 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -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]}] diff --git a/common/src/app/common/files/changes_builder.cljc b/common/src/app/common/files/changes_builder.cljc index c83cfa3d78..3d4e1b4ea7 100644 --- a/common/src/app/common/files/changes_builder.cljc +++ b/common/src/app/common/files/changes_builder.cljc @@ -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] diff --git a/common/src/app/common/types/token_theme.cljc b/common/src/app/common/types/token_theme.cljc index e370fb389a..ed7388995c 100644 --- a/common/src/app/common/types/token_theme.cljc +++ b/common/src/app/common/types/token_theme.cljc @@ -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"} diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index a0c5d4c4d5..10c9f33d22 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -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] diff --git a/frontend/src/app/main/ui/workspace/tokens/sets.cljs b/frontend/src/app/main/ui/workspace/tokens/sets.cljs index 30dfa740cc..cbbf97ef63 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sets.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sets.cljs @@ -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)))