mirror of
https://github.com/penpot/penpot.git
synced 2025-01-21 06:02:32 -05:00
Move to token-set namespace
This commit is contained in:
parent
188e7d220a
commit
ead8a983ab
2 changed files with 41 additions and 30 deletions
|
@ -19,7 +19,8 @@
|
|||
[beicon.v2.core :as rx]
|
||||
[clojure.data :as data]
|
||||
[cuerdas.core :as str]
|
||||
[potok.v2.core :as ptk]))
|
||||
[potok.v2.core :as ptk]
|
||||
[app.main.ui.workspace.tokens.token-set :as wtts]))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Helpers
|
||||
|
@ -79,39 +80,12 @@
|
|||
(let [workspace-data (deref refs/workspace-data)]
|
||||
(get (:tokens workspace-data) id)))
|
||||
|
||||
(defn get-workspace-sets [state]
|
||||
(get-in state [:workspace-data :token-sets-index]))
|
||||
|
||||
(defn get-token-set [set-id state]
|
||||
(some-> (get-workspace-sets state)
|
||||
(get set-id)))
|
||||
|
||||
(def default-token-set-name "Global")
|
||||
|
||||
(defn create-global-set [])
|
||||
|
||||
(defn add-token-to-token-set [token token-set]
|
||||
(update token-set :items conj (:id token)))
|
||||
|
||||
(defn get-selected-token-set-id [state]
|
||||
(get-in state [:workspace-local :selected-token-set-id]))
|
||||
|
||||
(defn get-selected-token-set [state]
|
||||
(when-let [id (get-selected-token-set-id state)]
|
||||
(get-token-set id state)))
|
||||
|
||||
(defn get-token-set-tokens [{:keys [tokens] :as token-set} file]
|
||||
(map #(get-in file [:data :tokens %]) tokens))
|
||||
|
||||
(defn assoc-selected-token-set-id [state id]
|
||||
(assoc-in state [:workspace-local :selected-token-set-id] id))
|
||||
|
||||
(defn set-selected-token-set-id
|
||||
[id]
|
||||
(ptk/reify ::set-selected-token-set-id
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(assoc-selected-token-set-id state id))))
|
||||
(wtts/assoc-selected-token-set-id state id))))
|
||||
|
||||
(defn update-create-token
|
||||
[token]
|
||||
|
@ -126,7 +100,7 @@
|
|||
(pcb/add-token token))
|
||||
(-> (pcb/empty-changes it)
|
||||
(pcb/update-token token prev-token)))
|
||||
token-set (get-selected-token-set state)
|
||||
token-set (wtts/get-selected-token-set state)
|
||||
create-set? (not token-set)
|
||||
new-token-set {:id (uuid/next)
|
||||
:name "Global"
|
||||
|
|
37
frontend/src/app/main/ui/workspace/tokens/token_set.cljs
Normal file
37
frontend/src/app/main/ui/workspace/tokens/token_set.cljs
Normal file
|
@ -0,0 +1,37 @@
|
|||
(ns app.main.ui.workspace.tokens.token-set)
|
||||
|
||||
(defn get-workspace-tokens [state]
|
||||
(get-in state [:workspace-data :tokens]))
|
||||
|
||||
(defn get-workspace-sets [state]
|
||||
(get-in state [:workspace-data :token-sets-index]))
|
||||
|
||||
(defn get-token-set [set-id state]
|
||||
(some-> (get-workspace-sets state)
|
||||
(get set-id)))
|
||||
|
||||
(def default-token-set-name "Global")
|
||||
|
||||
(defn create-global-set [])
|
||||
|
||||
(defn add-token-to-token-set [token token-set]
|
||||
(update token-set :items conj (:id token)))
|
||||
|
||||
(defn get-selected-token-set-id [state]
|
||||
(or (get-in state [:workspace-local :selected-token-set-id])
|
||||
(get-in state [:workspace-data :token-set-groups 0])))
|
||||
|
||||
(defn get-selected-token-set [state]
|
||||
(when-let [id (get-selected-token-set-id state)]
|
||||
(get-token-set id state)))
|
||||
|
||||
(defn get-selected-token-set-tokens [state]
|
||||
(when-let [token-set (get-selected-token-set state)]
|
||||
(let [tokens (or (get-workspace-tokens state) {})]
|
||||
(select-keys tokens (:tokens token-set)))))
|
||||
|
||||
(defn get-token-set-tokens [{:keys [tokens] :as token-set} file]
|
||||
(map #(get-in file [:data :tokens %]) tokens))
|
||||
|
||||
(defn assoc-selected-token-set-id [state id]
|
||||
(assoc-in state [:workspace-local :selected-token-set-id] id))
|
Loading…
Add table
Reference in a new issue