mirror of
https://github.com/penpot/penpot.git
synced 2025-12-11 22:14:05 +01:00
🎉 Update tokens
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
(ns app.main.ui.workspace.tokens.update
|
(ns app.main.ui.workspace.tokens.update
|
||||||
(:require
|
(:require
|
||||||
[app.common.files.helpers :as cfh]
|
[app.common.files.helpers :as cfh]
|
||||||
|
[app.common.logging :as l]
|
||||||
[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.shapes :as dwsh]
|
[app.main.data.workspace.shapes :as dwsh]
|
||||||
@@ -9,6 +10,7 @@
|
|||||||
[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]
|
||||||
[app.main.ui.workspace.tokens.token-set :as wtts]
|
[app.main.ui.workspace.tokens.token-set :as wtts]
|
||||||
|
[app.util.time :as dt]
|
||||||
[beicon.v2.core :as rx]
|
[beicon.v2.core :as rx]
|
||||||
[clojure.data :as data]
|
[clojure.data :as data]
|
||||||
[clojure.set :as set]
|
[clojure.set :as set]
|
||||||
@@ -18,7 +20,7 @@
|
|||||||
|
|
||||||
(def filter-existing-values? false)
|
(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/border-radius-keys wtch/update-shape-radius-for-corners
|
||||||
ctt/color-keys wtch/update-fill-stroke
|
ctt/color-keys wtch/update-fill-stroke
|
||||||
ctt/stroke-width-keys wtch/update-stroke-width
|
ctt/stroke-width-keys wtch/update-stroke-width
|
||||||
@@ -33,10 +35,10 @@
|
|||||||
ctt/rotation-keys wtch/update-rotation})
|
ctt/rotation-keys wtch/update-rotation})
|
||||||
|
|
||||||
(def attribute-actions-map
|
(def attribute-actions-map
|
||||||
(reduce
|
(reduce-kv (fn [acc ks action]
|
||||||
(fn [acc [ks action]]
|
|
||||||
(into acc (map (fn [k] [k action]) ks)))
|
(into acc (map (fn [k] [k action]) ks)))
|
||||||
{} attributes->shape-update))
|
{}
|
||||||
|
attributes->shape-update))
|
||||||
|
|
||||||
;; Helpers ---------------------------------------------------------------------
|
;; Helpers ---------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -113,12 +115,11 @@
|
|||||||
|
|
||||||
[tokens frame-ids text-ids])))
|
[tokens frame-ids text-ids])))
|
||||||
|
|
||||||
;; FIXME: revisit this
|
(defn- actionize-shapes-update-info
|
||||||
(defn- actionize-shapes-update-info [page-id 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 (fn [[v shape-ids]]
|
||||||
(fn [[v shape-ids]]
|
|
||||||
(action v shape-ids attrs page-id))
|
(action v shape-ids attrs page-id))
|
||||||
update-infos)))
|
update-infos)))
|
||||||
shapes-update-info))
|
shapes-update-info))
|
||||||
@@ -127,8 +128,17 @@
|
|||||||
[state resolved-tokens]
|
[state resolved-tokens]
|
||||||
(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)
|
||||||
|
tpoint (dt/tpoint-ms)]
|
||||||
|
|
||||||
|
(l/inf :status "START" :hint "update-tokens")
|
||||||
|
(->> (rx/concat
|
||||||
|
(rx/of current-page-id)
|
||||||
(->> (rx/from (:pages fdata))
|
(->> (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
|
(rx/mapcat
|
||||||
(fn [page-id]
|
(fn [page-id]
|
||||||
(let [page
|
(let [page
|
||||||
@@ -141,17 +151,28 @@
|
|||||||
(actionize-shapes-update-info page-id attrs)]
|
(actionize-shapes-update-info page-id attrs)]
|
||||||
|
|
||||||
(rx/merge
|
(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/from frame-ids)
|
||||||
(rx/mapcat (fn [frame-id]
|
(rx/mapcat (fn [frame-id]
|
||||||
(rx/of (dwt/clear-thumbnail file-id page-id frame-id "frame")
|
(->> (rx/of (dwt/clear-thumbnail file-id page-id frame-id "frame")
|
||||||
(dwt/clear-thumbnail file-id page-id frame-id "component")))))
|
(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
|
(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.
|
(rx/of (dwsh/update-shapes text-ids ;; after change. But those on other pages need to be specifically reset.
|
||||||
(fn [shape]
|
(fn [shape]
|
||||||
(dissoc shape :position-data))
|
(dissoc shape :position-data))
|
||||||
{:page-id page-id
|
{: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
|
(defn update-workspace-tokens
|
||||||
[]
|
[]
|
||||||
|
|||||||
Reference in New Issue
Block a user