mirror of
https://github.com/penpot/penpot.git
synced 2026-08-01 10:56:20 +00:00
♻️ Revert trigger interactive via actionize and propagation
This commit is contained in:
parent
0df420d353
commit
18e6842e35
@ -76,15 +76,6 @@
|
|||||||
(def ^:private attribute-actions-map
|
(def ^:private attribute-actions-map
|
||||||
(flatten-set-keyed-map attributes->shape-update {}))
|
(flatten-set-keyed-map attributes->shape-update {}))
|
||||||
|
|
||||||
(def ^:private interactive-attributes->shape-update
|
|
||||||
{ctt/font-family-keys dwta/update-font-family-interactive
|
|
||||||
ctt/font-weight-keys dwta/update-font-weight-interactive
|
|
||||||
ctt/text-decoration-keys dwta/update-text-decoration-interactive
|
|
||||||
ctt/typography-token-keys dwta/update-typography-interactive})
|
|
||||||
|
|
||||||
(def ^:private interactive-attribute-actions-map
|
|
||||||
(flatten-set-keyed-map interactive-attributes->shape-update attribute-actions-map))
|
|
||||||
|
|
||||||
;; Data flows ------------------------------------------------------------------
|
;; Data flows ------------------------------------------------------------------
|
||||||
|
|
||||||
(defn- invert-collect-key-vals
|
(defn- invert-collect-key-vals
|
||||||
@ -148,26 +139,19 @@
|
|||||||
|
|
||||||
[tokens frame-ids text-ids])))
|
[tokens frame-ids text-ids])))
|
||||||
|
|
||||||
(defn- actionize-shapes-update-info
|
(defn- actionize-shapes-update-info [page-id shapes-update-info]
|
||||||
[page-id shapes-update-info interactive?]
|
(mapcat (fn [[attrs update-infos]]
|
||||||
(let [attribute-actions (if interactive?
|
(let [action (some attribute-actions-map attrs)]
|
||||||
interactive-attribute-actions-map
|
(assert (fn? action) "missing action function on attributes->shape-update")
|
||||||
attribute-actions-map)]
|
(map
|
||||||
(mapcat (fn [[attrs update-infos]]
|
(fn [[v shape-ids]]
|
||||||
(let [action (some attribute-actions attrs)]
|
(action v shape-ids attrs page-id))
|
||||||
(assert (fn? action) "missing action function on attributes->shape-update")
|
update-infos)))
|
||||||
(map
|
shapes-update-info))
|
||||||
(fn [[v shape-ids]]
|
|
||||||
(action v shape-ids attrs page-id))
|
|
||||||
update-infos)))
|
|
||||||
shapes-update-info)))
|
|
||||||
|
|
||||||
(defn propagate-tokens
|
(defn propagate-tokens
|
||||||
"Propagate tokens values to all shapes where they are applied
|
"Propagate tokens values to all shapes where they are applied"
|
||||||
|
[state resolved-tokens]
|
||||||
Pass `interactive?` to indicate the propagation was triggered by a user interaction
|
|
||||||
and should use update functions that may execute ui side-effects like showing warnings."
|
|
||||||
[state resolved-tokens interactive?]
|
|
||||||
(let [file-id (get state :current-file-id)
|
(let [file-id (get state :current-file-id)
|
||||||
current-page-id (get state :current-page-id)
|
current-page-id (get state :current-page-id)
|
||||||
fdata (dsh/lookup-file-data state file-id)
|
fdata (dsh/lookup-file-data state file-id)
|
||||||
@ -187,7 +171,7 @@
|
|||||||
(collect-shapes-update-info resolved-tokens (:objects page))
|
(collect-shapes-update-info resolved-tokens (:objects page))
|
||||||
|
|
||||||
actions
|
actions
|
||||||
(actionize-shapes-update-info page-id attrs interactive?)
|
(actionize-shapes-update-info page-id attrs)
|
||||||
|
|
||||||
;; Composed updates return observables and need to be executed differently
|
;; Composed updates return observables and need to be executed differently
|
||||||
{:keys [observable normal]} (group-by #(if (rx/observable? %) :observable :normal) actions)]
|
{:keys [observable normal]} (group-by #(if (rx/observable? %) :observable :normal) actions)]
|
||||||
@ -218,11 +202,7 @@
|
|||||||
(l/inf :status "END" :hint "propagate-tokens" :elapsed elapsed)))))))
|
(l/inf :status "END" :hint "propagate-tokens" :elapsed elapsed)))))))
|
||||||
|
|
||||||
(defn propagate-workspace-tokens
|
(defn propagate-workspace-tokens
|
||||||
"Updates styles for tokens.
|
[]
|
||||||
|
|
||||||
Pass `interactive?` to indicate the propagation was triggered by a user interaction
|
|
||||||
and should use update functions that may execute ui side-effects like showing warnings."
|
|
||||||
[& {:keys [interactive?]}]
|
|
||||||
(ptk/reify ::propagate-workspace-tokens
|
(ptk/reify ::propagate-workspace-tokens
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
@ -234,5 +214,5 @@
|
|||||||
(let [undo-id (js/Symbol)]
|
(let [undo-id (js/Symbol)]
|
||||||
(rx/concat
|
(rx/concat
|
||||||
(rx/of (dwu/start-undo-transaction undo-id :timeout false))
|
(rx/of (dwu/start-undo-transaction undo-id :timeout false))
|
||||||
(propagate-tokens state sd-tokens interactive?)
|
(propagate-tokens state sd-tokens)
|
||||||
(rx/of (dwu/commit-undo-transaction undo-id)))))))))))
|
(rx/of (dwu/commit-undo-transaction undo-id)))))))))))
|
||||||
|
|||||||
@ -469,7 +469,7 @@ custom-input-token-value-props: Custom props passed to the custom-input-token-va
|
|||||||
{:name final-name
|
{:name final-name
|
||||||
:value (:value valid-token)
|
:value (:value valid-token)
|
||||||
:description final-description}))
|
:description final-description}))
|
||||||
(dwtp/propagate-workspace-tokens :interactive? true)
|
(dwtp/propagate-workspace-tokens)
|
||||||
(modal/hide)))))))))
|
(modal/hide)))))))))
|
||||||
|
|
||||||
on-delete-token
|
on-delete-token
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user