Add waitForLayoutUpdate to plugins

This commit is contained in:
alonso.torres 2026-04-08 16:50:05 +02:00
parent 79604dacbb
commit fbfc093f3e
4 changed files with 38 additions and 2 deletions

View File

@ -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)))))))

View File

@ -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)

View File

@ -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<void>;
}
/**

View File

@ -380,6 +380,11 @@ export function createApi(
checkPermission('content:write');
return plugin.context.createVariantFromComponents(shapes);
},
waitForLayoutUpdate(timeout?: number): Promise<void> {
checkPermission('content:read');
return plugin.context.waitForLayoutUpdate(timeout);
},
};
return {