mirror of
https://github.com/penpot/penpot.git
synced 2026-06-20 06:12:04 +00:00
🔧 Refactor tokens-lib initialization
This commit is contained in:
parent
ff941603c7
commit
000401ecc4
@ -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
|
||||
|
||||
|
||||
@ -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]
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user