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

feat: expose fetch as global object

This commit is contained in:
alonso.torres 2024-05-09 13:07:16 +02:00 committed by Alonso Torres
parent e3db7a0485
commit e3252387bd
5 changed files with 7 additions and 10 deletions

View file

@ -31,7 +31,7 @@ Receive message from iframe:
```ts
penpot.ui.onMessage((message) => {
penpot.log('Received message:', message);
console.log('Received message:', message);
});
```
@ -61,7 +61,7 @@ Current events `pagechange`, `filechange`,`selectionchange` and `themechange`.
```ts
const event = (page) => {
penpot.log(page.name);
console.log(page.name);
};
penpot.on('pagechange', event);

View file

@ -368,7 +368,6 @@ export interface Penpot extends PenpotContext {
isFrame(shape: PenpotShape): shape is PenpotFrame;
};
};
log: (...data: unknown[]) => void;
setTimeout: (callback: () => void, time: number) => void;
closePlugin: () => void;
on: <T extends keyof EventsMap>(
@ -379,8 +378,6 @@ export interface Penpot extends PenpotContext {
type: T,
callback: (event: EventsMap[T]) => void
) => void;
fetch: typeof fetch;
}
declare global {

View file

@ -10,7 +10,9 @@ console.log('%c[PLUGINS] Loading plugin system', 'color: #008d7c');
repairIntrinsics({
evalTaming: 'unsafeEval',
consoleTaming: import.meta.env.MODE === 'development' ? 'unsafe' : 'safe',
stackFiltering: 'verbose',
errorTaming: 'unsafe',
consoleTaming: 'unsafe',
});
globalThis.initPluginsRuntime = (context: PenpotContext) => {

View file

@ -107,8 +107,6 @@ export function createApi(context: PenpotContext, manifest: Manifest): Penpot {
},
},
log: console.log,
setTimeout: z
.function()
.args(z.function(), z.number())
@ -223,8 +221,6 @@ export function createApi(context: PenpotContext, manifest: Manifest): Penpot {
uploadMediaUrl(name: string, url: string) {
return context.uploadMediaUrl(name, url);
},
fetch,
};
return penpot;

View file

@ -31,6 +31,8 @@ export const ɵloadPlugin = async function (config: PluginConfig) {
const c = new Compartment({
penpot: harden(lastApi),
fetch: window.fetch.bind(window),
console: harden(window.console),
});
c.evaluate(code);