From fbfc093f3e2916e8fa2a1333068bce137c668b4a Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 8 Apr 2026 16:50:05 +0200 Subject: [PATCH] :sparkles: Add waitForLayoutUpdate to plugins --- frontend/src/app/plugins/api.cljs | 26 +++++++++++++++++-- plugins/CHANGELOG.md | 1 + plugins/libs/plugin-types/index.d.ts | 8 ++++++ .../libs/plugins-runtime/src/lib/api/index.ts | 5 ++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/plugins/api.cljs b/frontend/src/app/plugins/api.cljs index 68526ae8a4..90c7a3eb98 100644 --- a/frontend/src/app/plugins/api.cljs +++ b/frontend/src/app/plugins/api.cljs @@ -54,7 +54,8 @@ [app.util.object :as obj] [app.util.theme :as theme] [beicon.v2.core :as rx] - [cuerdas.core :as str])) + [cuerdas.core :as str] + [potok.v2.core :as ptk])) ;; ;; PLUGINS PUBLIC API - The plugins will able to access this functions @@ -653,4 +654,25 @@ {:trigger "plugin:combine-as-variants" :variant-id variant-id})) (shape/shape-proxy plugin-id variant-id)) - (u/not-valid plugin-id :shapes "One of the components is not on the same page or is already a variant"))))))) + (u/not-valid plugin-id :shapes "One of the components is not on the same page or is already a variant"))))) + + :waitForLayoutUpdate + (fn [timeout] + (js/Promise. + (fn [resolve reject] + (->> (rx/combine-latest-all + [(if timeout + (->> (rx/of :timeout) + (rx/delay timeout)) + (rx/empty)) + + ;; TODO: Wait for the layout to update + ]) + (rx/take 1) + (rx/subs! + (fn [value] + (if (= value :timeout) + ;; If timeout we reject + (reject) + (resolve))) + reject))))))) diff --git a/plugins/CHANGELOG.md b/plugins/CHANGELOG.md index 4b58244e86..fbe60f99c9 100644 --- a/plugins/CHANGELOG.md +++ b/plugins/CHANGELOG.md @@ -8,6 +8,7 @@ - **plugin-types**: Added `textBounds` property for text shapes - **plugin-types**: Added flag `throwValidationErrors` to enable exceptions on validation - **plugin-types**: Fix missing `webp` export format in `Export.type` +- **plugin-types**: Added `waitForLayoutUpdate` for synchronously wait for layout updates ## 1.4.2 (2026-01-21) diff --git a/plugins/libs/plugin-types/index.d.ts b/plugins/libs/plugin-types/index.d.ts index dd42f365fe..2f8491db39 100644 --- a/plugins/libs/plugin-types/index.d.ts +++ b/plugins/libs/plugin-types/index.d.ts @@ -1317,6 +1317,14 @@ export interface Context { * @return The variant container created */ createVariantFromComponents(shapes: Board[]): VariantContainer; + + /** + * This method returns a promise that will be resolved when the layout + * has finished updating. + * @param timeout A timeout for the wait. If there is a timeout the promise will be rejected + * @return The promise to be resolved when the layout is updated + */ + waitForLayoutUpdate(timeout?: number): Promise; } /** diff --git a/plugins/libs/plugins-runtime/src/lib/api/index.ts b/plugins/libs/plugins-runtime/src/lib/api/index.ts index 00d64e58ed..4fd38f145a 100644 --- a/plugins/libs/plugins-runtime/src/lib/api/index.ts +++ b/plugins/libs/plugins-runtime/src/lib/api/index.ts @@ -380,6 +380,11 @@ export function createApi( checkPermission('content:write'); return plugin.context.createVariantFromComponents(shapes); }, + + waitForLayoutUpdate(timeout?: number): Promise { + checkPermission('content:read'); + return plugin.context.waitForLayoutUpdate(timeout); + }, }; return {