🎉 Update tokens

This commit is contained in:
Eva Marco
2025-03-03 13:51:08 +01:00
parent f06f11ad7a
commit c1abd2d635

View File

@@ -1,6 +1,7 @@
(ns app.main.ui.workspace.tokens.update
(:require
[app.common.files.helpers :as cfh]
[app.common.logging :as l]
[app.common.types.token :as ctt]
[app.main.data.helpers :as dsh]
[app.main.data.workspace.shapes :as dwsh]
@@ -9,6 +10,7 @@
[app.main.ui.workspace.tokens.changes :as wtch]
[app.main.ui.workspace.tokens.style-dictionary :as wtsd]
[app.main.ui.workspace.tokens.token-set :as wtts]
[app.util.time :as dt]
[beicon.v2.core :as rx]
[clojure.data :as data]
[clojure.set :as set]
@@ -18,7 +20,7 @@
(def filter-existing-values? false)
(def attributes->shape-update
(def ^:private attributes->shape-update
{ctt/border-radius-keys wtch/update-shape-radius-for-corners
ctt/color-keys wtch/update-fill-stroke
ctt/stroke-width-keys wtch/update-stroke-width
@@ -33,10 +35,10 @@
ctt/rotation-keys wtch/update-rotation})
(def attribute-actions-map
(reduce
(fn [acc [ks action]]
(into acc (map (fn [k] [k action]) ks)))
{} attributes->shape-update))
(reduce-kv (fn [acc ks action]
(into acc (map (fn [k] [k action]) ks)))
{}
attributes->shape-update))
;; Helpers ---------------------------------------------------------------------
@@ -113,22 +115,30 @@
[tokens frame-ids text-ids])))
;; FIXME: revisit this
(defn- actionize-shapes-update-info [page-id shapes-update-info]
(defn- actionize-shapes-update-info
[page-id shapes-update-info]
(mapcat (fn [[attrs update-infos]]
(let [action (some attribute-actions-map attrs)]
(map
(fn [[v shape-ids]]
(action v shape-ids attrs page-id))
update-infos)))
(map (fn [[v shape-ids]]
(action v shape-ids attrs page-id))
update-infos)))
shapes-update-info))
(defn update-tokens
[state resolved-tokens]
(let [file-id (get state :current-file-id)
current-page-id (get state :current-page-id)
fdata (dsh/lookup-file-data state file-id)]
(->> (rx/from (:pages fdata))
fdata (dsh/lookup-file-data state file-id)
tpoint (dt/tpoint-ms)]
(l/inf :status "START" :hint "update-tokens")
(->> (rx/concat
(rx/of current-page-id)
(->> (rx/from (:pages fdata))
(rx/filter (fn [id] (not= id current-page-id)))
(rx/mapcat (fn [page-id]
(->> (rx/of page-id)
(rx/delay 0))))))
(rx/mapcat
(fn [page-id]
(let [page
@@ -141,17 +151,28 @@
(actionize-shapes-update-info page-id attrs)]
(rx/merge
(rx/from actions)
(->> (rx/from (partition-all 10 actions))
(rx/mapcat (fn [actions]
;; We introduce a minimal delay for each ten actions,
;; inorder to not block the whole UI and leave the next
;; action application to the next frame
(->> (rx/from actions)
(rx/delay 1)
(rx/observe-on :af)))))
(->> (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")))))
(->> (rx/of (dwt/clear-thumbnail file-id page-id frame-id "frame")
(dwt/clear-thumbnail file-id page-id frame-id "component"))))))
(when (not= page-id current-page-id) ;; Texts in the current page have already their position-data regenerated
(rx/of (dwsh/update-shapes text-ids ;; after change. But those on other pages need to be specifically reset.
(fn [shape]
(dissoc shape :position-data))
{:page-id page-id
:ignore-touched true}))))))))))
:ignore-touched true})))))))
(rx/finalize
(fn [_]
(let [elapsed (tpoint)]
(l/inf :status "END" :hint "update-tokens" :elapsed elapsed)))))))
(defn update-workspace-tokens
[]