0
Fork 0
mirror of https://github.com/penpot/penpot-plugins.git synced 2025-01-23 07:08:47 -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 ```ts
penpot.ui.onMessage((message) => { 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 ```ts
const event = (page) => { const event = (page) => {
penpot.log(page.name); console.log(page.name);
}; };
penpot.on('pagechange', event); penpot.on('pagechange', event);

View file

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

View file

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

View file

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

View file

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