diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index 0f90faac4..e1023197b 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -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)) diff --git a/common/src/app/common/files/changes_builder.cljc b/common/src/app/common/files/changes_builder.cljc index 24fd4d4d2..7b7f1fc51 100644 --- a/common/src/app/common/files/changes_builder.cljc +++ b/common/src/app/common/files/changes_builder.cljc @@ -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 diff --git a/common/src/app/common/types/file.cljc b/common/src/app/common/types/file.cljc index 0cbf4e849..bd5237af1 100644 --- a/common/src/app/common/types/file.cljc +++ b/common/src/app/common/types/file.cljc @@ -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} diff --git a/common/src/app/common/types/token_theme.cljc b/common/src/app/common/types/token_theme.cljc index 9b11dbbc9..d76f1e277 100644 --- a/common/src/app/common/types/token_theme.cljc +++ b/common/src/app/common/types/token_theme.cljc @@ -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]]]) diff --git a/common/src/app/common/types/tokens_theme_list.cljc b/common/src/app/common/types/tokens_theme_list.cljc index 98c8e5d01..aa26ac207 100644 --- a/common/src/app/common/types/tokens_theme_list.cljc +++ b/common/src/app/common/types/tokens_theme_list.cljc @@ -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 diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index 7b055f73a..4b6b04f37 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -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] diff --git a/frontend/src/app/main/ui/workspace/tokens/token_set.cljs b/frontend/src/app/main/ui/workspace/tokens/token_set.cljs index b144c919d..0681e078b 100644 --- a/frontend/src/app/main/ui/workspace/tokens/token_set.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/token_set.cljs @@ -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 ------------------------------------------------------------------------