mirror of
https://github.com/penpot/penpot.git
synced 2026-08-01 10:56:20 +00:00
✨ Auto link tokens when adding external libraries (provisional)
This commit is contained in:
parent
e705b6e12c
commit
37eeca1b29
@ -425,9 +425,15 @@
|
|||||||
[:before-group [:maybe :boolean]]]]
|
[:before-group [:maybe :boolean]]]]
|
||||||
|
|
||||||
[:set-base-font-size
|
[:set-base-font-size
|
||||||
[:map {:title "ModBaseFontSize"}
|
[:map {:title "ModBaseFontSize"}
|
||||||
[:type [:= :set-base-font-size]]
|
[:type [:= :set-base-font-size]]
|
||||||
[:base-font-size :string]]]])
|
[: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
|
(def schema:changes
|
||||||
[:sequential {:gen/max 5 :gen/min 1} schema:change])
|
[:sequential {:gen/max 5 :gen/min 1} schema:change])
|
||||||
@ -1065,6 +1071,10 @@
|
|||||||
[data {:keys [base-font-size]}]
|
[data {:keys [base-font-size]}]
|
||||||
(ctf/set-base-font-size data 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
|
;; === Operations
|
||||||
|
|
||||||
|
|||||||
@ -1084,6 +1084,21 @@
|
|||||||
:base-font-size previous-font-size})
|
:base-font-size previous-font-size})
|
||||||
(apply-changes-local))))
|
(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
|
;; Misc changes
|
||||||
|
|
||||||
(defn reorder-children
|
(defn reorder-children
|
||||||
|
|||||||
@ -133,6 +133,7 @@
|
|||||||
:token-tokenscript
|
:token-tokenscript
|
||||||
:token-import-from-library
|
:token-import-from-library
|
||||||
:token-typography-row
|
:token-typography-row
|
||||||
|
:token-lib-sync
|
||||||
|
|
||||||
;; Only for developtment.
|
;; Only for developtment.
|
||||||
:transit-readable-response
|
:transit-readable-response
|
||||||
|
|||||||
@ -37,6 +37,13 @@
|
|||||||
([state file-id]
|
([state file-id]
|
||||||
(dm/get-in state [:files file-id :data])))
|
(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
|
(defn get-page
|
||||||
[fdata page-id]
|
[fdata page-id]
|
||||||
(dm/get-in fdata [:pages-index page-id]))
|
(dm/get-in fdata [:pages-index page-id]))
|
||||||
|
|||||||
@ -1547,16 +1547,17 @@
|
|||||||
|
|
||||||
(defn link-file-to-library
|
(defn link-file-to-library
|
||||||
[file-id library-id]
|
[file-id library-id]
|
||||||
(ptk/reify ::attach-library
|
(ptk/reify ::link-file-to-library
|
||||||
ev/Event
|
ev/Event
|
||||||
(-data [_]
|
(-data [_]
|
||||||
{::ev/name "attach-library"
|
{::ev/name "link-file-to-library"
|
||||||
:file-id file-id
|
:file-id file-id
|
||||||
:library-id library-id})
|
:library-id library-id})
|
||||||
|
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(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)
|
library (get libraries library-id)
|
||||||
variants-count (-> library :library-summary :variants count)
|
variants-count (-> library :library-summary :variants count)
|
||||||
|
|
||||||
@ -1567,23 +1568,26 @@
|
|||||||
(map first)
|
(map first)
|
||||||
set)]
|
set)]
|
||||||
(rx/concat
|
(rx/concat
|
||||||
(rx/merge
|
(when (contains? cf/flags :token-lib-sync)
|
||||||
(->> (rp/cmd! :link-file-to-library {:file-id file-id :library-id library-id})
|
(rx/of (dch/commit-changes (-> (pcb/empty-changes nil)
|
||||||
(rx/merge-map (fn [libraries-to-load]
|
(pcb/with-file-data file-data)
|
||||||
(as-> libraries-to-load $
|
(pcb/set-tokens-file library-id)))))
|
||||||
(remove loaded-libraries $)
|
(->> (rp/cmd! :link-file-to-library {:file-id file-id :library-id library-id})
|
||||||
(conj $ library-id)
|
(rx/merge-map (fn [libraries-to-load]
|
||||||
(map #(load-library-file file-id %) $))))
|
(as-> libraries-to-load $
|
||||||
(rx/catch (fn [cause]
|
(remove loaded-libraries $)
|
||||||
|
(conj $ library-id)
|
||||||
|
(map #(load-library-file file-id %) $))))
|
||||||
|
(rx/catch (fn [cause]
|
||||||
(let [error (ex-data cause)]
|
(let [error (ex-data cause)]
|
||||||
(if (= (:code error) :circular-library-reference)
|
(if (= (:code error) :circular-library-reference)
|
||||||
(rx/of (ntf/error (tr "errors.circular-library-reference")))
|
(rx/of (ntf/error (tr "errors.circular-library-reference")))
|
||||||
(rx/throw cause)))))))
|
(rx/throw cause))))))
|
||||||
(rx/of (ptk/reify ::attach-library-finished))
|
(rx/of (ptk/reify ::link-file-to-library-finished))
|
||||||
(when (pos? variants-count)
|
(when (pos? variants-count)
|
||||||
(->> (rp/cmd! :get-library-usage {:file-id library-id})
|
(->> (rp/cmd! :get-library-usage {:file-id library-id})
|
||||||
(rx/map (fn [library-usage]
|
(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
|
:file-id file-id
|
||||||
:library-id library-id
|
:library-id library-id
|
||||||
:variants-count variants-count
|
:variants-count variants-count
|
||||||
|
|||||||
@ -675,8 +675,7 @@
|
|||||||
(ctt/typography-token-keys (:type token)) (set/union attributes-to-remove ctt/typography-keys)
|
(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)
|
(ctt/typography-keys (:type token)) (set/union attributes-to-remove ctt/typography-token-keys)
|
||||||
:else attributes-to-remove)]
|
:else attributes-to-remove)]
|
||||||
(when-let [tokens (some-> (dsh/lookup-file-data state)
|
(when-let [tokens (some-> (dsh/lookup-tokens-lib state)
|
||||||
(get :tokens-lib)
|
|
||||||
(ctob/get-tokens-in-active-sets))]
|
(ctob/get-tokens-in-active-sets))]
|
||||||
(->> (if (contains? cf/flags :tokenscript)
|
(->> (if (contains? cf/flags :tokenscript)
|
||||||
(rx/of (ts/resolve-tokens tokens))
|
(rx/of (ts/resolve-tokens tokens))
|
||||||
|
|||||||
@ -38,8 +38,7 @@
|
|||||||
|
|
||||||
(defn get-tokens-lib
|
(defn get-tokens-lib
|
||||||
[state]
|
[state]
|
||||||
(-> (dsh/lookup-file-data state)
|
(dsh/lookup-tokens-lib state))
|
||||||
(get :tokens-lib)))
|
|
||||||
|
|
||||||
(defn lookup-token-set
|
(defn lookup-token-set
|
||||||
([state]
|
([state]
|
||||||
@ -231,8 +230,7 @@
|
|||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state _]
|
(watch [it state _]
|
||||||
(let [data (dsh/lookup-file-data 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)))
|
(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")
|
(rx/of (ntf/show {:content (tr "errors.token-theme-already-exists")
|
||||||
:type :toast
|
:type :toast
|
||||||
@ -249,8 +247,8 @@
|
|||||||
(ptk/reify ::update-token-theme
|
(ptk/reify ::update-token-theme
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state _]
|
(watch [it state _]
|
||||||
(let [data (dsh/lookup-file-data state)
|
(let [data (dsh/lookup-file-data state)
|
||||||
tokens-lib (get data :tokens-lib)]
|
tokens-lib (dsh/lookup-tokens-lib state)]
|
||||||
(if (and (not= id (ctob/get-id token-theme))
|
(if (and (not= id (ctob/get-id token-theme))
|
||||||
(ctob/get-theme tokens-lib (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")
|
(rx/of (ntf/show {:content (tr "errors.token-theme-already-exists")
|
||||||
@ -350,7 +348,7 @@
|
|||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state _]
|
(watch [it state _]
|
||||||
(let [data (dsh/lookup-file-data 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")]
|
suffix (tr "workspace.tokens.duplicate-suffix")]
|
||||||
|
|
||||||
(when-let [token-set (ctob/duplicate-set id tokens-lib {:suffix suffix})]
|
(when-let [token-set (ctob/duplicate-set id tokens-lib {:suffix suffix})]
|
||||||
|
|||||||
@ -188,8 +188,7 @@
|
|||||||
(ptk/reify ::propagate-workspace-tokens
|
(ptk/reify ::propagate-workspace-tokens
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(when-let [tokens-tree (-> (dsh/lookup-file-data state)
|
(when-let [tokens-tree (-> (dsh/lookup-tokens-lib state)
|
||||||
(get :tokens-lib)
|
|
||||||
(ctob/get-tokens-in-active-sets))]
|
(ctob/get-tokens-in-active-sets))]
|
||||||
(->> (if (contains? cf/flags :tokenscript)
|
(->> (if (contains? cf/flags :tokenscript)
|
||||||
(rx/of (-> (ts/resolve-tokens tokens-tree)
|
(rx/of (-> (ts/resolve-tokens tokens-tree)
|
||||||
|
|||||||
@ -13,26 +13,22 @@
|
|||||||
|
|
||||||
(defn- get-selected-token-set-id [state]
|
(defn- get-selected-token-set-id [state]
|
||||||
(or (get-in state [:workspace-tokens :selected-token-set-id])
|
(or (get-in state [:workspace-tokens :selected-token-set-id])
|
||||||
(some-> (dsh/lookup-file-data state)
|
(some-> (dsh/lookup-tokens-lib state)
|
||||||
(get :tokens-lib)
|
|
||||||
(ctob/get-sets)
|
(ctob/get-sets)
|
||||||
(first)
|
(first)
|
||||||
(ctob/get-id))))
|
(ctob/get-id))))
|
||||||
|
|
||||||
(defn get-selected-token-set [state]
|
(defn get-selected-token-set [state]
|
||||||
(when-let [set-id (get-selected-token-set-id state)]
|
(when-let [set-id (get-selected-token-set-id state)]
|
||||||
(some-> (dsh/lookup-file-data state)
|
(some-> (dsh/lookup-tokens-lib state)
|
||||||
(get :tokens-lib)
|
|
||||||
(ctob/get-set set-id))))
|
(ctob/get-set set-id))))
|
||||||
|
|
||||||
(defn get-token-in-selected-set [state token-id]
|
(defn get-token-in-selected-set [state token-id]
|
||||||
(when-let [set-id (get-selected-token-set-id state)]
|
(when-let [set-id (get-selected-token-set-id state)]
|
||||||
(some-> (dsh/lookup-file-data state)
|
(some-> (dsh/lookup-tokens-lib state)
|
||||||
(get :tokens-lib)
|
|
||||||
(ctob/get-token set-id token-id))))
|
(ctob/get-token set-id token-id))))
|
||||||
|
|
||||||
(defn get-all-tokens-in-selected-set [state]
|
(defn get-all-tokens-in-selected-set [state]
|
||||||
(when-let [set-id (get-selected-token-set-id state)]
|
(when-let [set-id (get-selected-token-set-id state)]
|
||||||
(some-> (dsh/lookup-file-data state)
|
(some-> (dsh/lookup-tokens-lib state)
|
||||||
(get :tokens-lib)
|
|
||||||
(ctob/get-tokens set-id))))
|
(ctob/get-tokens set-id))))
|
||||||
|
|||||||
@ -461,7 +461,7 @@
|
|||||||
;; ---- Token refs
|
;; ---- Token refs
|
||||||
|
|
||||||
(def tokens-lib
|
(def tokens-lib
|
||||||
(l/derived :tokens-lib workspace-data))
|
(l/derived dsh/lookup-tokens-lib st/state))
|
||||||
|
|
||||||
(def workspace-token-theme-groups
|
(def workspace-token-theme-groups
|
||||||
(l/derived (d/nilf ctob/get-theme-groups) tokens-lib))
|
(l/derived (d/nilf ctob/get-theme-groups) tokens-lib))
|
||||||
|
|||||||
@ -1177,7 +1177,7 @@
|
|||||||
(let [file-id (:current-file-id @st/state)
|
(let [file-id (:current-file-id @st/state)
|
||||||
library-id (uuid/parse library-id)]
|
library-id (uuid/parse library-id)]
|
||||||
(->> st/stream
|
(->> st/stream
|
||||||
(rx/filter (ptk/type? ::dwl/attach-library-finished))
|
(rx/filter (ptk/type? ::dwl/link-file-to-library-finished))
|
||||||
(rx/take 1)
|
(rx/take 1)
|
||||||
(rx/subs! #(resolve (library-proxy plugin-id library-id)) reject))
|
(rx/subs! #(resolve (library-proxy plugin-id library-id)) reject))
|
||||||
(st/emit! (-> (dwl/link-file-to-library file-id library-id)
|
(st/emit! (-> (dwl/link-file-to-library file-id library-id)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user