diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index cf0f34a1c2..9bc022f722 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -993,9 +993,9 @@ (defmethod process-change :set-token [data {:keys [set-id token-id attrs]}] - (update data :tokens-lib - (fn [lib] - (let [lib' (ctob/ensure-tokens-lib lib)] + (let [data (ctf/ensure-tokens-lib data)] + (update data :tokens-lib + (fn [lib'] (cond (not attrs) (ctob/delete-token lib' set-id token-id) @@ -1010,9 +1010,9 @@ (defmethod process-change :set-token-set [data {:keys [id attrs]}] - (update data :tokens-lib - (fn [lib] - (let [lib' (ctob/ensure-tokens-lib lib)] + (let [data (ctf/ensure-tokens-lib data)] + (update data :tokens-lib + (fn [lib'] (cond (not attrs) (ctob/delete-set lib' id) @@ -1025,9 +1025,9 @@ (defmethod process-change :set-token-theme [data {:keys [id attrs]}] - (update data :tokens-lib - (fn [lib] - (let [lib' (ctob/ensure-tokens-lib lib)] + (let [data (ctf/ensure-tokens-lib data)] + (update data :tokens-lib + (fn [lib'] (cond (not attrs) (ctob/delete-theme lib' id) @@ -1043,27 +1043,23 @@ (defmethod process-change :set-active-token-themes [data {:keys [theme-paths]}] - (update data :tokens-lib #(-> % (ctob/ensure-tokens-lib) - (ctob/set-active-themes theme-paths)))) + (-> (ctf/ensure-tokens-lib data) + (update :tokens-lib ctob/set-active-themes theme-paths))) (defmethod process-change :rename-token-set-group [data {:keys [set-group-path set-group-fname]}] - (update data :tokens-lib (fn [lib] - (-> lib - (ctob/ensure-tokens-lib) - (ctob/rename-set-group set-group-path set-group-fname))))) + (-> (ctf/ensure-tokens-lib data) + (update :tokens-lib ctob/rename-set-group set-group-path set-group-fname))) (defmethod process-change :move-token-set [data {:keys [from-path to-path before-path before-group] :as changes}] - (update data :tokens-lib #(-> % - (ctob/ensure-tokens-lib) - (ctob/move-set from-path to-path before-path before-group)))) + (-> (ctf/ensure-tokens-lib data) + (update :tokens-lib ctob/move-set from-path to-path before-path before-group))) (defmethod process-change :move-token-set-group [data {:keys [from-path to-path before-path before-group]}] - (update data :tokens-lib #(-> % - (ctob/ensure-tokens-lib) - (ctob/move-set-group from-path to-path before-path before-group)))) + (-> (ctf/ensure-tokens-lib data) + (update :tokens-lib ctob/move-set-group from-path to-path before-path before-group))) ;; === Design Tokens configuration diff --git a/common/src/app/common/test_helpers/tokens.cljc b/common/src/app/common/test_helpers/tokens.cljc index 21a8dd4f04..01da59e616 100644 --- a/common/src/app/common/test_helpers/tokens.cljc +++ b/common/src/app/common/test_helpers/tokens.cljc @@ -21,7 +21,7 @@ (defn add-tokens-lib [file] - (ctf/update-file-data file #(update % :tokens-lib ctob/ensure-tokens-lib))) + (ctf/update-file-data file ctf/ensure-tokens-lib)) (defn update-tokens-lib [file f] diff --git a/common/src/app/common/types/file.cljc b/common/src/app/common/types/file.cljc index accda94bc5..08f86bdb5b 100644 --- a/common/src/app/common/types/file.cljc +++ b/common/src/app/common/types/file.cljc @@ -28,7 +28,7 @@ [app.common.types.shape :as cts] [app.common.types.shape-tree :as ctst] [app.common.types.text :as txt] - [app.common.types.tokens-lib :refer [schema:tokens-lib]] + [app.common.types.tokens-lib :as ctob] [app.common.types.typographies-list :as ctyl] [app.common.types.typography :as cty] [app.common.uuid :as uuid] @@ -86,7 +86,7 @@ [:components {:optional true} schema:components] [:typographies {:optional true} schema:typographies] [:plugin-data {:optional true} schema:plugin-data] - [:tokens-lib {:optional true} schema:tokens-lib]]) + [:tokens-lib {:optional true} ctob/schema:tokens-lib]]) (def schema:file "A schema for validate a file data structure; data is optional @@ -196,6 +196,11 @@ (check-file file))) +(defn ensure-tokens-lib + "Ensure file-data has a :tokens-lib key, creating one if necessary." + [file-data] + (update file-data :tokens-lib #(or % (ctob/make-tokens-lib)))) + ;; Helpers (defn file-data diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index 2376dd7563..9b5beaf72a 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -1452,10 +1452,6 @@ Will return a value that matches this schema: (check-tokens-lib-map) (map->tokens-lib))) -(defn ensure-tokens-lib - [tokens-lib] - (or tokens-lib (make-tokens-lib))) - (def schema:tokens-lib (sm/type-schema {:type ::tokens-lib