0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-11 09:38:56 -05:00

Move theme-path impl to ITokenTheme

This commit is contained in:
Florian Schroedl 2024-09-24 14:24:35 +02:00
parent 49579d75c6
commit 6d75993fd7

View file

@ -96,14 +96,6 @@
(group? group)) (group? group))
(seq group)) (seq group))
(def theme-separator "/")
(defn theme-path [group name]
(join-path [group name] theme-separator))
(defn token-theme->path [token-theme]
(theme-path (:group token-theme) (:name token-theme)))
;; === Token ;; === Token
(defrecord Token [name type value description modified-at]) (defrecord Token [name type value description modified-at])
@ -258,8 +250,14 @@
;; === TokenTheme ;; === TokenTheme
(def theme-separator "/")
(defn token-theme-path [group name]
(join-path [group name] theme-separator))
(defprotocol ITokenTheme (defprotocol ITokenTheme
(toggle-set [_ set-name] "togle a set used / not used in the theme")) (toggle-set [_ set-name] "togle a set used / not used in the theme")
(theme-path [_] "get `token-theme-path` from theme"))
(defrecord TokenTheme [name group description is-source modified-at sets] (defrecord TokenTheme [name group description is-source modified-at sets]
ITokenTheme ITokenTheme
@ -271,7 +269,9 @@
(dt/now) (dt/now)
(if (sets set-name) (if (sets set-name)
(disj sets set-name) (disj sets set-name)
(conj sets set-name))))) (conj sets set-name))))
(theme-path [_]
(token-theme-path group name)))
(def schema:token-theme (def schema:token-theme
[:and [:map {:title "TokenTheme"} [:and [:map {:title "TokenTheme"}
@ -468,7 +468,7 @@
(TokensLib. sets (TokensLib. sets
set-groups set-groups
(d/dissoc-in themes [group name]) (d/dissoc-in themes [group name])
(disj active-themes (theme-path group name)))) (disj active-themes (token-theme-path group name))))
(get-theme-tree [_] (get-theme-tree [_]
themes) themes)
@ -490,12 +490,12 @@
(dm/get-in themes [group name])) (dm/get-in themes [group name]))
(activate-theme [this group name] (activate-theme [this group name]
(if (get-theme this group name) (if-let [theme (get-theme this group name)]
(let [group-themes (->> (get themes group) (let [group-themes (->> (get themes group)
(map (comp token-theme->path val)) (map (comp theme-path val))
(into #{})) (into #{}))
active-themes' (-> (set/difference active-themes group-themes) active-themes' (-> (set/difference active-themes group-themes)
(conj (theme-path group name)))] (conj (theme-path theme)))]
(TokensLib. sets (TokensLib. sets
set-groups set-groups
themes themes
@ -506,10 +506,10 @@
(TokensLib. sets (TokensLib. sets
set-groups set-groups
themes themes
(disj active-themes (theme-path group name)))) (disj active-themes (token-theme-path group name))))
(theme-active? [_ group name] (theme-active? [_ group name]
(contains? active-themes (theme-path group name))) (contains? active-themes (token-theme-path group name)))
(toggle-theme-active? [this group name] (toggle-theme-active? [this group name]
(if (theme-active? this group name) (if (theme-active? this group name)