diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index f6b643b39..a486fc950 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -26,6 +26,7 @@ [app.common.types.token :as cto] [app.common.types.token-theme :as ctot] [app.common.types.tokens-list :as ctol] + [app.common.types.tokens-theme-list :as ctotl] [app.common.types.typographies-list :as ctyl] [app.common.types.typography :as ctt] [clojure.set :as set])) @@ -256,7 +257,8 @@ [:mod-token-set [:map {:title "ModTokenSetChange"} [:type [:= :mod-token-set]] - [:id ::ctot/token-set]]] + [:id ::sm/uuid] + [:token-set ::ctot/token-set]]] [:del-token-set [:map {:title "DelTokenSetChange"} @@ -758,6 +760,18 @@ [data {:keys [id]}] (ctol/delete-token data id)) +(defmethod process-change :add-token-set + [data {:keys [token-set]}] + (ctotl/add-token-set data token-set)) + +(defmethod process-change :mod-token-set + [data {:keys [id token-set]}] + (ctotl/update-token-set data id merge token-set)) + +(defmethod process-change :del-token-set + [data {:keys [id]}] + (ctotl/delete-token-set data id)) + ;; === Operations (defmethod process-operation :set [on-changed shape op] diff --git a/common/src/app/common/files/changes_builder.cljc b/common/src/app/common/files/changes_builder.cljc index 391703760..34f74c980 100644 --- a/common/src/app/common/files/changes_builder.cljc +++ b/common/src/app/common/files/changes_builder.cljc @@ -716,7 +716,7 @@ prev-token-set (get-in library-data [:token-set token-set-id])] (-> changes (update :redo-changes conj {:type :del-token-set :id token-set-id}) - (update :undo-changes conj {:type :add-token-set :token prev-token-set}) + (update :undo-changes conj {:type :add-token-set :token-set prev-token-set}) (apply-changes-local)))) (defn add-token diff --git a/common/src/app/common/types/tokens_theme_list.cljc b/common/src/app/common/types/tokens_theme_list.cljc new file mode 100644 index 000000000..966016b02 --- /dev/null +++ b/common/src/app/common/types/tokens_theme_list.cljc @@ -0,0 +1,38 @@ +;; This Source Code Form is subject to the terms of the Mozilla Public +;; License, v. 2.0. If a copy of the MPL was not distributed with this +;; file, You can obtain one at http://mozilla.org/MPL/2.0/. +;; +;; Copyright (c) KALEIDOS INC + +(ns app.common.types.tokens-theme-list + (:require + [app.common.data :as d] + [app.common.exceptions :as ex] + [app.common.time :as dt])) + +(defn- touch + "Updates the `modified-at` timestamp of a token set." + [token-set] + (assoc token-set :modified-at (dt/now))) + +(defn add-token-set + [file-data {:keys [index id] :as token-set}] + (-> file-data + (update :token-set-groups + (fn [token-set-groups] + (let [exists? (some (partial = id) token-set-groups)] + (cond + exists? token-set-groups + (nil? index) (conj token-set-groups id) + :else (d/insert-at-index token-set-groups index [id]))))) + (update :token-sets-index assoc id token-set))) + +(defn update-token-set + [file-data token-id f & args] + #_(ex/raise :type :not-implemented) + file-data) + +(defn delete-token-set + [file-data token-id] + #_(ex/raise :type :not-implemented) + file-data) diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index 151d48f9c..d0063518f 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -113,12 +113,13 @@ create-set? (-> token-changes (pcb/add-token-set {:id (uuid/next) :name "Global" - :items [(:id token)]})) + :tokens [(:id token)]})) :else (let [updated-token-set (if (contains? token-set (:id token)) token-set - (update token-set :items conj (:id token)))] + (update token-set :tokens conj (:id token)))] (-> token-changes (pcb/update-token-set token-set updated-token-set))))] + (js/console.log "changes" changes) (rx/of (dch/commit-changes changes))))))) (defn delete-token