0
Fork 0
mirror of https://github.com/penpot/penpot-plugins.git synced 2025-01-06 14:50:21 -05:00

feat: move setTimeout as a global fn

This commit is contained in:
Juanfran 2024-05-23 14:09:56 +02:00
parent c7e1722459
commit 625b8bdde5
3 changed files with 10 additions and 12 deletions

View file

@ -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: <T extends keyof EventsMap>(
type: T,

View file

@ -117,13 +117,6 @@ export function createApi(context: PenpotContext, manifest: Manifest): Penpot {
},
},
setTimeout: z
.function()
.args(z.function(), z.number())
.implement((callback: Callback<unknown>, time: number) => {
setTimeout(callback, time);
}),
closePlugin,
on<T extends keyof EventsMap>(

View file

@ -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<typeof setTimeout>) => {
return setTimeout(() => {
handler();
}, timeout);
}
),
clearTimeout: harden((id: Parameters<typeof clearTimeout>[0]) => {
clearTimeout(id);
}),
});
c.evaluate(code);