mirror of
https://github.com/penpot/penpot.git
synced 2025-02-23 15:26:29 -05:00
🐛 Fix thumbnail regeration when changing sets of tokens
This commit is contained in:
parent
f4f0478975
commit
24281b512e
1 changed files with 56 additions and 33 deletions
|
@ -1,8 +1,10 @@
|
||||||
(ns app.main.ui.workspace.tokens.update
|
(ns app.main.ui.workspace.tokens.update
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.files.helpers :as cfh]
|
||||||
[app.common.types.token :as ctt]
|
[app.common.types.token :as ctt]
|
||||||
[app.main.data.helpers :as dsh]
|
[app.main.data.helpers :as dsh]
|
||||||
[app.main.data.workspace.shape-layout :as dwsl]
|
[app.main.data.workspace.shape-layout :as dwsl]
|
||||||
|
[app.main.data.workspace.thumbnails :as dwt]
|
||||||
[app.main.data.workspace.undo :as dwu]
|
[app.main.data.workspace.undo :as dwu]
|
||||||
[app.main.ui.workspace.tokens.changes :as wtch]
|
[app.main.ui.workspace.tokens.changes :as wtch]
|
||||||
[app.main.ui.workspace.tokens.style-dictionary :as wtsd]
|
[app.main.ui.workspace.tokens.style-dictionary :as wtsd]
|
||||||
|
@ -86,18 +88,29 @@
|
||||||
(->> (map (fn [[value attrs]] [attrs {value #{object-id}}]) attrs-values-map)
|
(->> (map (fn [[value attrs]] [attrs {value #{object-id}}]) attrs-values-map)
|
||||||
(into {})))
|
(into {})))
|
||||||
|
|
||||||
(defn collect-shapes-update-info [resolved-tokens objects]
|
(defn- collect-shapes-update-info [resolved-tokens objects]
|
||||||
(reduce
|
(loop [items (seq objects)
|
||||||
(fn [acc [shape-id {:keys [applied-tokens] :as shape}]]
|
frame-ids #{}
|
||||||
(if (seq applied-tokens)
|
tokens {}]
|
||||||
(let [applied-tokens (-> (invert-collect-key-vals applied-tokens resolved-tokens shape)
|
(if-let [[shape-id {:keys [applied-tokens] :as shape}] (first items)]
|
||||||
|
(let [applied-tokens
|
||||||
|
(-> (invert-collect-key-vals applied-tokens resolved-tokens shape)
|
||||||
(shape-ids-by-values shape-id)
|
(shape-ids-by-values shape-id)
|
||||||
(split-attribute-groups))]
|
(split-attribute-groups))
|
||||||
(deep-merge acc applied-tokens))
|
|
||||||
acc))
|
|
||||||
{} objects))
|
|
||||||
|
|
||||||
(defn actionize-shapes-update-info [page-id shapes-update-info]
|
parent-frame-id
|
||||||
|
(cfh/get-shape-id-root-frame objects shape-id)]
|
||||||
|
|
||||||
|
(recur (rest items)
|
||||||
|
(if parent-frame-id
|
||||||
|
(conj frame-ids parent-frame-id)
|
||||||
|
frame-ids)
|
||||||
|
(deep-merge tokens applied-tokens)))
|
||||||
|
|
||||||
|
[tokens frame-ids])))
|
||||||
|
|
||||||
|
;; FIXME: revisit this
|
||||||
|
(defn- actionize-shapes-update-info [page-id shapes-update-info]
|
||||||
(mapcat (fn [[attrs update-infos]]
|
(mapcat (fn [[attrs update-infos]]
|
||||||
(let [action (some attribute-actions-map attrs)]
|
(let [action (some attribute-actions-map attrs)]
|
||||||
(map
|
(map
|
||||||
|
@ -106,30 +119,40 @@
|
||||||
update-infos)))
|
update-infos)))
|
||||||
shapes-update-info))
|
shapes-update-info))
|
||||||
|
|
||||||
(defn update-tokens-in-page [state page-id resolved-tokens]
|
(defn update-tokens
|
||||||
(->> (dsh/lookup-page-objects state page-id)
|
[state resolved-tokens]
|
||||||
(collect-shapes-update-info resolved-tokens)
|
(let [file-id (get state :current-file-id)
|
||||||
(actionize-shapes-update-info page-id)))
|
fdata (dsh/lookup-file-data state file-id)]
|
||||||
|
(->> (rx/from (:pages fdata))
|
||||||
|
(rx/mapcat
|
||||||
|
(fn [page-id]
|
||||||
|
(let [page
|
||||||
|
(dsh/get-page fdata page-id)
|
||||||
|
|
||||||
(defn update-tokens [state resolved-tokens]
|
[attrs frame-ids]
|
||||||
(reduce (fn [events page-id]
|
(collect-shapes-update-info resolved-tokens (:objects page))
|
||||||
(rx/concat events (update-tokens-in-page state page-id resolved-tokens)))
|
|
||||||
(rx/empty)
|
|
||||||
(dsh/get-all-page-ids state)))
|
|
||||||
|
|
||||||
(defn update-workspace-tokens []
|
actions
|
||||||
|
(actionize-shapes-update-info page-id attrs)]
|
||||||
|
|
||||||
|
(rx/merge
|
||||||
|
(rx/from actions)
|
||||||
|
(->> (rx/from frame-ids)
|
||||||
|
(rx/mapcat (fn [frame-id]
|
||||||
|
(rx/of (dwt/clear-thumbnail file-id page-id frame-id "frame")
|
||||||
|
(dwt/clear-thumbnail file-id page-id frame-id "component"))))))))))))
|
||||||
|
|
||||||
|
(defn update-workspace-tokens
|
||||||
|
[]
|
||||||
(ptk/reify ::update-workspace-tokens
|
(ptk/reify ::update-workspace-tokens
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(->>
|
(let [tokens (-> (wtts/get-active-theme-sets-tokens-names-map state)
|
||||||
(rx/from
|
(wtsd/resolve-tokens+))]
|
||||||
(->
|
(->> (rx/from tokens)
|
||||||
(wtts/get-active-theme-sets-tokens-names-map state)
|
(rx/mapcat (fn [sd-tokens]
|
||||||
(wtsd/resolve-tokens+)))
|
|
||||||
(rx/mapcat
|
|
||||||
(fn [sd-tokens]
|
|
||||||
(let [undo-id (js/Symbol)]
|
(let [undo-id (js/Symbol)]
|
||||||
(rx/concat
|
(rx/concat
|
||||||
(rx/of (dwu/start-undo-transaction undo-id))
|
(rx/of (dwu/start-undo-transaction undo-id))
|
||||||
(update-tokens state sd-tokens)
|
(update-tokens state sd-tokens)
|
||||||
(rx/of (dwu/commit-undo-transaction undo-id))))))))))
|
(rx/of (dwu/commit-undo-transaction undo-id)))))))))))
|
||||||
|
|
Loading…
Add table
Reference in a new issue