mirror of
https://github.com/penpot/penpot.git
synced 2026-07-20 04:58:12 +00:00
wip
This commit is contained in:
parent
ccd34a2705
commit
c0140cde0e
@ -425,9 +425,15 @@
|
||||
[:before-group [:maybe :boolean]]]]
|
||||
|
||||
[:set-base-font-size
|
||||
[:map {:title "ModBaseFontSize"}
|
||||
[:type [:= :set-base-font-size]]
|
||||
[:base-font-size :string]]]])
|
||||
[:map {:title "ModBaseFontSize"}
|
||||
[:type [:= :set-base-font-size]]
|
||||
[:base-font-size :string]]]
|
||||
|
||||
[:set-tokens-file
|
||||
[:map {:title "SetTokensFile"}
|
||||
[:type [:= :set-tokens-file]]
|
||||
[:file-id ::sm/uuid]
|
||||
[:library-id [:maybe ::sm/uuid]]]]])
|
||||
|
||||
(def schema:changes
|
||||
[:sequential {:gen/max 5 :gen/min 1} schema:change])
|
||||
@ -1065,6 +1071,10 @@
|
||||
[data {:keys [base-font-size]}]
|
||||
(ctf/set-base-font-size data base-font-size))
|
||||
|
||||
(defmethod process-change :set-tokens-file
|
||||
[data {:keys [library-id]}]
|
||||
(assoc data :tokens-file library-id))
|
||||
|
||||
|
||||
;; === Operations
|
||||
|
||||
|
||||
@ -1084,6 +1084,21 @@
|
||||
:base-font-size previous-font-size})
|
||||
(apply-changes-local))))
|
||||
|
||||
(defn set-tokens-file
|
||||
[changes library-id]
|
||||
(assert-file-data! changes)
|
||||
(let [file-data (::file-data (meta changes))
|
||||
file-id (:id file-data)
|
||||
prev-val (:tokens-file file-data)]
|
||||
(-> changes
|
||||
(update :redo-changes conj {:type :set-tokens-file
|
||||
:file-id file-id
|
||||
:library-id library-id})
|
||||
(update :undo-changes conj {:type :set-tokens-file
|
||||
:file-id file-id
|
||||
:library-id prev-val})
|
||||
(apply-changes-local))))
|
||||
|
||||
;; Misc changes
|
||||
|
||||
(defn reorder-children
|
||||
|
||||
@ -37,6 +37,13 @@
|
||||
([state file-id]
|
||||
(dm/get-in state [:files file-id :data])))
|
||||
|
||||
(defn lookup-tokens-lib
|
||||
[state]
|
||||
(let [current-file-data (lookup-file-data state)
|
||||
tokens-file-id (or (:tokens-file current-file-data) (:id current-file-data))
|
||||
tokens-file-data (lookup-file-data state tokens-file-id)]
|
||||
(:tokens-lib tokens-file-data)))
|
||||
|
||||
(defn get-page
|
||||
[fdata page-id]
|
||||
(dm/get-in fdata [:pages-index page-id]))
|
||||
|
||||
@ -1545,16 +1545,17 @@
|
||||
|
||||
(defn link-file-to-library
|
||||
[file-id library-id]
|
||||
(ptk/reify ::attach-library
|
||||
(ptk/reify ::link-file-to-library
|
||||
ev/Event
|
||||
(-data [_]
|
||||
{::ev/name "attach-library"
|
||||
{::ev/name "link-file-to-library"
|
||||
:file-id file-id
|
||||
:library-id library-id})
|
||||
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [libraries (:shared-files state)
|
||||
(let [file-data (dm/get-in state [:files file-id :data])
|
||||
libraries (:shared-files state)
|
||||
library (get libraries library-id)
|
||||
variants-count (-> library :library-summary :variants count)
|
||||
|
||||
@ -1565,18 +1566,20 @@
|
||||
(map first)
|
||||
set)]
|
||||
(rx/concat
|
||||
(rx/merge
|
||||
(->> (rp/cmd! :link-file-to-library {:file-id file-id :library-id library-id})
|
||||
(rx/merge-map (fn [libraries-to-load]
|
||||
(as-> libraries-to-load $
|
||||
(remove loaded-libraries $)
|
||||
(conj $ library-id)
|
||||
(map #(load-library-file file-id %) $))))))
|
||||
(rx/of (ptk/reify ::attach-library-finished))
|
||||
(rx/of (dch/commit-changes (-> (pcb/empty-changes nil)
|
||||
(pcb/with-file-data file-data)
|
||||
(pcb/set-tokens-file library-id))))
|
||||
(->> (rp/cmd! :link-file-to-library {:file-id file-id :library-id library-id})
|
||||
(rx/merge-map (fn [libraries-to-load]
|
||||
(as-> libraries-to-load $
|
||||
(remove loaded-libraries $)
|
||||
(conj $ library-id)
|
||||
(map #(load-library-file file-id %) $)))))
|
||||
(rx/of (ptk/reify ::link-file-to-library-finished))
|
||||
(when (pos? variants-count)
|
||||
(->> (rp/cmd! :get-library-usage {:file-id library-id})
|
||||
(rx/map (fn [library-usage]
|
||||
(ev/event {::ev/name "attach-library-variants"
|
||||
(ev/event {::ev/name "link-file-to-library-variants"
|
||||
:file-id file-id
|
||||
:library-id library-id
|
||||
:variants-count variants-count
|
||||
|
||||
@ -675,8 +675,7 @@
|
||||
(ctt/typography-token-keys (:type token)) (set/union attributes-to-remove ctt/typography-keys)
|
||||
(ctt/typography-keys (:type token)) (set/union attributes-to-remove ctt/typography-token-keys)
|
||||
:else attributes-to-remove)]
|
||||
(when-let [tokens (some-> (dsh/lookup-file-data state)
|
||||
(get :tokens-lib)
|
||||
(when-let [tokens (some-> (dsh/lookup-tokens-lib state)
|
||||
(ctob/get-tokens-in-active-sets))]
|
||||
(->> (if (contains? cf/flags :tokenscript)
|
||||
(rx/of (ts/resolve-tokens tokens))
|
||||
|
||||
@ -38,8 +38,7 @@
|
||||
|
||||
(defn get-tokens-lib
|
||||
[state]
|
||||
(-> (dsh/lookup-file-data state)
|
||||
(get :tokens-lib)))
|
||||
(dsh/lookup-tokens-lib state))
|
||||
|
||||
(defn lookup-token-set
|
||||
([state]
|
||||
@ -231,8 +230,7 @@
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
(let [data (dsh/lookup-file-data state)
|
||||
tokens-lib (get data :tokens-lib)]
|
||||
|
||||
tokens-lib (dsh/lookup-tokens-lib state)]
|
||||
(if (and tokens-lib (ctob/get-theme tokens-lib (ctob/get-id token-theme)))
|
||||
(rx/of (ntf/show {:content (tr "errors.token-theme-already-exists")
|
||||
:type :toast
|
||||
@ -249,8 +247,8 @@
|
||||
(ptk/reify ::update-token-theme
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
(let [data (dsh/lookup-file-data state)
|
||||
tokens-lib (get data :tokens-lib)]
|
||||
(let [data (dsh/lookup-file-data state)
|
||||
tokens-lib (dsh/lookup-tokens-lib state)]
|
||||
(if (and (not= id (ctob/get-id token-theme))
|
||||
(ctob/get-theme tokens-lib (ctob/get-id token-theme)))
|
||||
(rx/of (ntf/show {:content (tr "errors.token-theme-already-exists")
|
||||
@ -348,7 +346,7 @@
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
(let [data (dsh/lookup-file-data state)
|
||||
tokens-lib (get data :tokens-lib)
|
||||
tokens-lib (dsh/lookup-tokens-lib state)
|
||||
suffix (tr "workspace.tokens.duplicate-suffix")]
|
||||
|
||||
(when-let [token-set (ctob/duplicate-set id tokens-lib {:suffix suffix})]
|
||||
|
||||
@ -188,8 +188,7 @@
|
||||
(ptk/reify ::propagate-workspace-tokens
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(when-let [tokens-tree (-> (dsh/lookup-file-data state)
|
||||
(get :tokens-lib)
|
||||
(when-let [tokens-tree (-> (dsh/lookup-tokens-lib state)
|
||||
(ctob/get-tokens-in-active-sets))]
|
||||
(->> (if (contains? cf/flags :tokenscript)
|
||||
(rx/of (-> (ts/resolve-tokens tokens-tree)
|
||||
|
||||
@ -13,26 +13,22 @@
|
||||
|
||||
(defn- get-selected-token-set-id [state]
|
||||
(or (get-in state [:workspace-tokens :selected-token-set-id])
|
||||
(some-> (dsh/lookup-file-data state)
|
||||
(get :tokens-lib)
|
||||
(some-> (dsh/lookup-tokens-lib state)
|
||||
(ctob/get-sets)
|
||||
(first)
|
||||
(ctob/get-id))))
|
||||
|
||||
(defn get-selected-token-set [state]
|
||||
(when-let [set-id (get-selected-token-set-id state)]
|
||||
(some-> (dsh/lookup-file-data state)
|
||||
(get :tokens-lib)
|
||||
(some-> (dsh/lookup-tokens-lib state)
|
||||
(ctob/get-set set-id))))
|
||||
|
||||
(defn get-token-in-selected-set [state token-id]
|
||||
(when-let [set-id (get-selected-token-set-id state)]
|
||||
(some-> (dsh/lookup-file-data state)
|
||||
(get :tokens-lib)
|
||||
(some-> (dsh/lookup-tokens-lib state)
|
||||
(ctob/get-token set-id token-id))))
|
||||
|
||||
(defn get-all-tokens-in-selected-set [state]
|
||||
(when-let [set-id (get-selected-token-set-id state)]
|
||||
(some-> (dsh/lookup-file-data state)
|
||||
(get :tokens-lib)
|
||||
(some-> (dsh/lookup-tokens-lib state)
|
||||
(ctob/get-tokens set-id))))
|
||||
|
||||
@ -458,7 +458,7 @@
|
||||
;; ---- Token refs
|
||||
|
||||
(def tokens-lib
|
||||
(l/derived :tokens-lib workspace-data))
|
||||
(l/derived dsh/lookup-tokens-lib st/state))
|
||||
|
||||
(def workspace-token-theme-groups
|
||||
(l/derived (d/nilf ctob/get-theme-groups) tokens-lib))
|
||||
|
||||
@ -1130,7 +1130,7 @@
|
||||
(let [file-id (:current-file-id @st/state)
|
||||
library-id (uuid/parse library-id)]
|
||||
(->> st/stream
|
||||
(rx/filter (ptk/type? ::dwl/attach-library-finished))
|
||||
(rx/filter (ptk/type? ::dwl/link-file-to-library-finished))
|
||||
(rx/take 1)
|
||||
(rx/subs! #(resolve (library-proxy plugin-id library-id)) reject))
|
||||
(st/emit! (-> (dwl/link-file-to-library file-id library-id)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user