diff --git a/libs/plugin-types/index.d.ts b/libs/plugin-types/index.d.ts index a29667f..824e842 100644 --- a/libs/plugin-types/index.d.ts +++ b/libs/plugin-types/index.d.ts @@ -482,11 +482,6 @@ export interface Penpot isFrame(shape: PenpotShape): shape is PenpotFrame; }; }; - /** - * Description of setTimeout - * - */ - setTimeout: (callback: () => void, time: number) => void; closePlugin: () => void; on: ( type: T, diff --git a/libs/plugins-runtime/src/lib/api/index.ts b/libs/plugins-runtime/src/lib/api/index.ts index b58bda9..b35203e 100644 --- a/libs/plugins-runtime/src/lib/api/index.ts +++ b/libs/plugins-runtime/src/lib/api/index.ts @@ -117,13 +117,6 @@ export function createApi(context: PenpotContext, manifest: Manifest): Penpot { }, }, - setTimeout: z - .function() - .args(z.function(), z.number()) - .implement((callback: Callback, time: number) => { - setTimeout(callback, time); - }), - closePlugin, on( diff --git a/libs/plugins-runtime/src/lib/load-plugin.ts b/libs/plugins-runtime/src/lib/load-plugin.ts index 2b2f065..03d28bf 100644 --- a/libs/plugins-runtime/src/lib/load-plugin.ts +++ b/libs/plugins-runtime/src/lib/load-plugin.ts @@ -34,6 +34,16 @@ export const ɵloadPlugin = async function (manifest: Manifest) { fetch: window.fetch.bind(window), console: harden(window.console), Math: harden(Math), + setTimeout: harden( + (...[handler, timeout]: Parameters) => { + return setTimeout(() => { + handler(); + }, timeout); + } + ), + clearTimeout: harden((id: Parameters[0]) => { + clearTimeout(id); + }), }); c.evaluate(code);