From 9fa72fb25b72271477f8f4ec065646de14ca3b08 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 16 Apr 2026 12:04:50 +0200 Subject: [PATCH] WIP --- .../app/main/data/workspace/modifiers.cljs | 2 +- .../app/main/data/workspace/shape_layout.cljs | 4 +++ .../app/main/data/workspace/wasm_text.cljs | 4 +++ frontend/src/app/plugins/api.cljs | 32 +++++++++++++++---- frontend/src/app/plugins/text.cljs | 3 +- 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/frontend/src/app/main/data/workspace/modifiers.cljs b/frontend/src/app/main/data/workspace/modifiers.cljs index c7181abbaf..def87731ae 100644 --- a/frontend/src/app/main/data/workspace/modifiers.cljs +++ b/frontend/src/app/main/data/workspace/modifiers.cljs @@ -669,7 +669,7 @@ [modif-tree & {:keys [ignore-constraints ignore-snap-pixel snap-ignore-axis undo-transation?] :or {ignore-constraints false ignore-snap-pixel false snap-ignore-axis nil undo-transation? true} :as params}] - (ptk/reify ::apply-wasm-modifiesr + (ptk/reify ::apply-wasm-modifiers ptk/WatchEvent (watch [_ state _] (wasm.api/clean-modifiers) diff --git a/frontend/src/app/main/data/workspace/shape_layout.cljs b/frontend/src/app/main/data/workspace/shape_layout.cljs index 163195f11f..71dd225eab 100644 --- a/frontend/src/app/main/data/workspace/shape_layout.cljs +++ b/frontend/src/app/main/data/workspace/shape_layout.cljs @@ -119,6 +119,8 @@ :undo-group undo-group})))) (rx/empty)))))) +(defonce layout-pending (atom false)) + (defn initialize-shape-layout [] (ptk/reify ::initialize-shape-layout @@ -129,10 +131,12 @@ ;; FIXME: we don't need use types for simple signaling, ;; we can just use a keyword for it (rx/filter (ptk/type? :layout/update)) + (rx/tap #(reset! layout-pending true)) (rx/map deref) ;; We buffer the updates to the layout so if there are many changes at the same time ;; they are process together. It will get a better performance. (rx/buffer-time 100) + (rx/tap #(reset! layout-pending false)) (rx/filter #(d/not-empty? %)) (rx/mapcat (fn [data] diff --git a/frontend/src/app/main/data/workspace/wasm_text.cljs b/frontend/src/app/main/data/workspace/wasm_text.cljs index 7effaef13e..c7796464ff 100644 --- a/frontend/src/app/main/data/workspace/wasm_text.cljs +++ b/frontend/src/app/main/data/workspace/wasm_text.cljs @@ -121,6 +121,8 @@ :else (rx/empty))))))) +(def resize-pending (atom false)) + ;; This event will debounce the resize events so, if there are many, they ;; are processed at the same time and not one-by-one. This will improve ;; performance because it's better to make only one layout calculation instead @@ -146,8 +148,10 @@ (rx/merge (->> stream (rx/filter (ptk/type? ::resize-wasm-text-debounce-inner)) + (rx/tap #(reset! resize-pending true)) (rx/debounce debounce-resize-text-time) (rx/take 1) + (rx/tap #(reset! resize-pending false)) (rx/map (fn [evt] (resize-wasm-text-debounce-commit (some-> evt meta :undo-group) diff --git a/frontend/src/app/plugins/api.cljs b/frontend/src/app/plugins/api.cljs index 90c7a3eb98..5eb3b93290 100644 --- a/frontend/src/app/plugins/api.cljs +++ b/frontend/src/app/plugins/api.cljs @@ -27,7 +27,9 @@ [app.main.data.workspace.colors :as dwc] [app.main.data.workspace.groups :as dwg] [app.main.data.workspace.media :as dwm] + [app.main.data.workspace.modifiers :as dwmm] [app.main.data.workspace.selection :as dws] + [app.main.data.workspace.shape-layout :as dwsl] [app.main.data.workspace.variants :as dwv] [app.main.data.workspace.wasm-text :as dwwt] [app.main.features :as features] @@ -660,14 +662,30 @@ (fn [timeout] (js/Promise. (fn [resolve reject] - (->> (rx/combine-latest-all - [(if timeout - (->> (rx/of :timeout) - (rx/delay timeout)) - (rx/empty)) + (->> (rx/merge + (if timeout + (->> (rx/of :timeout) + (rx/delay timeout)) + (rx/empty)) - ;; TODO: Wait for the layout to update - ]) + ;; Estas dos operaciones seria "take last" y luego tambien esta que + ;; hay que ver lo de la fuente. + (if @dwsl/layout-pending + (->> st/stream + (rx/filter (ptk/type? ::dwsl/update-layout-positions)) + (rx/take 1)) + (rx/empty)) + + (if @dwwt/resize-pending + (->> st/stream + (rx/filter (ptk/type? ::dwmm/apply-wasm-modifiers)) + (rx/take 1)) + (rx/empty)) + + (if (and (not @dwwt/resize-pending) + (not @dwsl/layout-pending)) + (rx/of :ok) + (rx/empty))) (rx/take 1) (rx/subs! (fn [value] diff --git a/frontend/src/app/plugins/text.cljs b/frontend/src/app/plugins/text.cljs index 11b590a7ce..aa4539c980 100644 --- a/frontend/src/app/plugins/text.cljs +++ b/frontend/src/app/plugins/text.cljs @@ -25,8 +25,7 @@ [app.plugins.utils :as u] [app.util.object :as obj] [app.util.text-editor :as ted] - [cuerdas.core :as str] - [potok.v2.core :as ptk])) + [cuerdas.core :as str])) ;; This regex seems duplicated but probably in the future when we support diferent units ;; this will need to reflect changes for each property