mirror of
https://github.com/penpot/penpot.git
synced 2026-08-29 08:08:46 +00:00
🐛 Propagate tokens after synchronizing components in ext library
This commit is contained in:
parent
87ae2e0012
commit
8979835576
@ -47,6 +47,7 @@
|
||||
[app.main.data.workspace.specialized-panel :as dwsp]
|
||||
[app.main.data.workspace.thumbnails :as dwt]
|
||||
[app.main.data.workspace.thumbnails-wasm :as dwt.wasm]
|
||||
[app.main.data.workspace.tokens.propagation :as dwtp]
|
||||
[app.main.data.workspace.transforms :as dwtr]
|
||||
[app.main.data.workspace.undo :as dwu]
|
||||
[app.main.data.workspace.wasm-text :as dwwt]
|
||||
@ -1346,6 +1347,9 @@
|
||||
#(do (apply st/emit! (map (fn [library]
|
||||
(sync-file file-id (:id library)))
|
||||
libraries-with-changes))
|
||||
;; Launch a local tokens propagation, so that the copies have the token values
|
||||
;; with the local tokens status, not the one coming from the external library.
|
||||
(st/emit! (dwtp/propagate-workspace-tokens))
|
||||
(st/emit! (ntf/hide)))
|
||||
|
||||
do-dismiss
|
||||
@ -1398,8 +1402,8 @@
|
||||
(launch-component-sync component-id file-id undo-group)))))
|
||||
|
||||
(defn watch-component-changes
|
||||
"Watch the state for changes that affect to any main instance. If a change is detected will throw
|
||||
an update-component-sync, so changes are immediately propagated to the component and copies."
|
||||
"Watch the state for changes that affect to any main instance. If a change is detected will call
|
||||
component-changed, so changes are immediately propagated to the component and copies."
|
||||
[]
|
||||
(ptk/reify ::watch-component-changes
|
||||
ptk/WatchEvent
|
||||
|
||||
@ -335,5 +335,4 @@
|
||||
(watch [_ state _]
|
||||
(when (contains? (:files state) file-id)
|
||||
(rx/of (dwl/ext-library-changed file-id modified-at revn changes)
|
||||
(dwl/notify-sync-file)
|
||||
(dwtp/propagate-workspace-tokens))))))
|
||||
(dwl/notify-sync-file))))))
|
||||
|
||||
@ -22,11 +22,9 @@
|
||||
[app.common.types.text :as txt]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.changes :as dch]
|
||||
[app.main.data.event :as ev]
|
||||
[app.main.data.helpers :as dsh]
|
||||
[app.main.data.workspace :as-alias dw]
|
||||
[app.main.data.workspace.common :as dwc]
|
||||
[app.main.data.workspace.libraries :as dwl]
|
||||
[app.main.data.workspace.modifiers :as dwm]
|
||||
[app.main.data.workspace.pages :as-alias dwpg]
|
||||
[app.main.data.workspace.reflow :as wrf]
|
||||
@ -1163,66 +1161,6 @@
|
||||
(let [{:keys [name]} (fonts/get-font-data font-id)]
|
||||
(assoc typography :name (str name " " (str/title font-variant-id)))))
|
||||
|
||||
(defn add-typography
|
||||
"A higher level version of dwl/add-typography, and has mainly two
|
||||
responsabilities: add the typography to the library and apply it to
|
||||
the currently selected text shapes (being aware of the open text
|
||||
editors.
|
||||
Optionally accepts a group-path to place the new typography inside
|
||||
a specific group."
|
||||
([file-id] (add-typography file-id nil))
|
||||
([file-id group-path]
|
||||
(ptk/reify ::add-typography
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [selected (dsh/lookup-selected state)
|
||||
objects (dsh/lookup-page-objects state)
|
||||
|
||||
xform (comp (keep (d/getf objects))
|
||||
(filter cfh/text-shape?))
|
||||
shapes (into [] xform selected)
|
||||
shape (first shapes)
|
||||
|
||||
values (current-text-values
|
||||
{:editor-state (dm/get-in state [:workspace-editor-state (:id shape)])
|
||||
:shape shape
|
||||
:attrs txt/text-node-attrs})
|
||||
|
||||
multiple? (or (> 1 (count shapes))
|
||||
(d/seek (partial = :multiple)
|
||||
(vals values)))
|
||||
|
||||
values (-> (d/without-nils values)
|
||||
(select-keys
|
||||
(d/concat-vec txt/text-font-attrs
|
||||
txt/text-spacing-attrs
|
||||
txt/text-transform-attrs)))
|
||||
values (cond-> values
|
||||
(number? (:line-height values))
|
||||
(update :line-height #(str (mth/precision % 2)))
|
||||
|
||||
(number? (:letter-spacing values))
|
||||
(update :letter-spacing #(str (mth/precision % 2))))
|
||||
|
||||
typ-id (uuid/next)
|
||||
typ (-> (if multiple?
|
||||
txt/default-typography
|
||||
(merge txt/default-typography values))
|
||||
(generate-typography-name)
|
||||
(assoc :id typ-id)
|
||||
(cond-> (string? group-path)
|
||||
(update :name #(str group-path " / " %))))]
|
||||
|
||||
(rx/concat
|
||||
(rx/of (dwl/add-typography typ)
|
||||
(ev/event {::ev/name "add-asset-to-library"
|
||||
:asset-type "typography"}))
|
||||
|
||||
(when (not multiple?)
|
||||
(rx/of (update-attrs (:id shape)
|
||||
{:typography-ref-id typ-id
|
||||
:typography-ref-file file-id})))))))))
|
||||
|
||||
;; -- Text Editor v2
|
||||
|
||||
(defn v2-update-text-editor-styles
|
||||
|
||||
85
frontend/src/app/main/data/workspace/texts_events.cljs
Normal file
85
frontend/src/app/main/data/workspace/texts_events.cljs
Normal file
@ -0,0 +1,85 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
||||
|
||||
(ns app.main.data.workspace.texts-events
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.data.macros :as dm]
|
||||
[app.common.files.helpers :as cfh]
|
||||
[app.common.math :as mth]
|
||||
[app.common.types.text :as txt]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.event :as ev]
|
||||
[app.main.data.helpers :as dsh]
|
||||
[app.main.data.workspace :as-alias dw]
|
||||
[app.main.data.workspace.libraries :as dwl]
|
||||
[app.main.data.workspace.pages :as-alias dwpg]
|
||||
[app.main.data.workspace.texts :as dwt]
|
||||
[beicon.v2.core :as rx]
|
||||
[potok.v2.core :as ptk]))
|
||||
|
||||
;; This function must be separated from app.main.data.workspace.texts to avoid a circular
|
||||
;; dependency due main.data.workspace.libraries eventually calling app.main.data.workspace.texts.
|
||||
|
||||
(defn add-typography
|
||||
"A higher level version of dwl/add-typography, and has mainly two
|
||||
responsabilities: add the typography to the library and apply it to
|
||||
the currently selected text shapes (being aware of the open text
|
||||
editors.
|
||||
Optionally accepts a group-path to place the new typography inside
|
||||
a specific group."
|
||||
([file-id] (add-typography file-id nil))
|
||||
([file-id group-path]
|
||||
(ptk/reify ::add-typography
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [selected (dsh/lookup-selected state)
|
||||
objects (dsh/lookup-page-objects state)
|
||||
|
||||
xform (comp (keep (d/getf objects))
|
||||
(filter cfh/text-shape?))
|
||||
shapes (into [] xform selected)
|
||||
shape (first shapes)
|
||||
|
||||
values (dwt/current-text-values
|
||||
{:editor-state (dm/get-in state [:workspace-editor-state (:id shape)])
|
||||
:shape shape
|
||||
:attrs txt/text-node-attrs})
|
||||
|
||||
multiple? (or (> 1 (count shapes))
|
||||
(d/seek (partial = :multiple)
|
||||
(vals values)))
|
||||
|
||||
values (-> (d/without-nils values)
|
||||
(select-keys
|
||||
(d/concat-vec txt/text-font-attrs
|
||||
txt/text-spacing-attrs
|
||||
txt/text-transform-attrs)))
|
||||
values (cond-> values
|
||||
(number? (:line-height values))
|
||||
(update :line-height #(str (mth/precision % 2)))
|
||||
|
||||
(number? (:letter-spacing values))
|
||||
(update :letter-spacing #(str (mth/precision % 2))))
|
||||
|
||||
typ-id (uuid/next)
|
||||
typ (-> (if multiple?
|
||||
txt/default-typography
|
||||
(merge txt/default-typography values))
|
||||
(dwt/generate-typography-name)
|
||||
(assoc :id typ-id)
|
||||
(cond-> (string? group-path)
|
||||
(update :name #(str group-path " / " %))))]
|
||||
|
||||
(rx/concat
|
||||
(rx/of (dwl/add-typography typ)
|
||||
(ev/event {::ev/name "add-asset-to-library"
|
||||
:asset-type "typography"}))
|
||||
|
||||
(when (not multiple?)
|
||||
(rx/of (dwt/update-attrs (:id shape)
|
||||
{:typography-ref-id typ-id
|
||||
:typography-ref-file file-id})))))))))
|
||||
@ -15,6 +15,7 @@
|
||||
[app.main.data.workspace :as dw]
|
||||
[app.main.data.workspace.libraries :as dwl]
|
||||
[app.main.data.workspace.texts :as dwt]
|
||||
[app.main.data.workspace.texts-events :as dwte]
|
||||
[app.main.data.workspace.undo :as dwu]
|
||||
[app.main.refs :as refs]
|
||||
[app.main.store :as st]
|
||||
@ -170,7 +171,7 @@
|
||||
(mf/deps file-id prefix)
|
||||
(fn [_]
|
||||
(st/emit! (dw/set-assets-section-open file-id :typographies true)
|
||||
(dwt/add-typography file-id prefix))))]
|
||||
(dwte/add-typography file-id prefix))))]
|
||||
|
||||
[:div {:class (stl/css :typographies-group)
|
||||
:on-drag-enter on-drag-enter
|
||||
@ -278,7 +279,7 @@
|
||||
(mf/deps file-id)
|
||||
(fn [_]
|
||||
(st/emit! (dw/set-assets-section-open file-id :typographies true))
|
||||
(st/emit! (dwt/add-typography file-id))))
|
||||
(st/emit! (dwte/add-typography file-id))))
|
||||
|
||||
handle-change
|
||||
(mf/use-fn
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user