mirror of
https://github.com/penpot/penpot-plugins.git
synced 2025-01-07 15:39:49 -05:00
feat: move setTimeout as a global fn
This commit is contained in:
parent
c7e1722459
commit
625b8bdde5
3 changed files with 10 additions and 12 deletions
5
libs/plugin-types/index.d.ts
vendored
5
libs/plugin-types/index.d.ts
vendored
|
@ -482,11 +482,6 @@ export interface Penpot
|
||||||
isFrame(shape: PenpotShape): shape is PenpotFrame;
|
isFrame(shape: PenpotShape): shape is PenpotFrame;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
/**
|
|
||||||
* Description of setTimeout
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
setTimeout: (callback: () => void, time: number) => void;
|
|
||||||
closePlugin: () => void;
|
closePlugin: () => void;
|
||||||
on: <T extends keyof EventsMap>(
|
on: <T extends keyof EventsMap>(
|
||||||
type: T,
|
type: T,
|
||||||
|
|
|
@ -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,
|
closePlugin,
|
||||||
|
|
||||||
on<T extends keyof EventsMap>(
|
on<T extends keyof EventsMap>(
|
||||||
|
|
|
@ -34,6 +34,16 @@ export const ɵloadPlugin = async function (manifest: Manifest) {
|
||||||
fetch: window.fetch.bind(window),
|
fetch: window.fetch.bind(window),
|
||||||
console: harden(window.console),
|
console: harden(window.console),
|
||||||
Math: harden(Math),
|
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);
|
c.evaluate(code);
|
||||||
|
|
Loading…
Reference in a new issue