Files
penpot/plugins/libs/plugins-runtime/src/lib/create-plugin.ts
Andrey Antukh ec1af4ad96 🎉 Import penpot-plugins repository
As commit 819a549e4928d2b1fa98e52bee82d59aec0f70d8
2025-12-30 14:56:15 +01:00

43 lines
864 B
TypeScript

import type { Context } from '@penpot/plugin-types';
import type { Manifest } from './models/manifest.model.js';
import { createPluginManager } from './plugin-manager.js';
import { createSandbox } from './create-sandbox.js';
export async function createPlugin(
context: Context,
manifest: Manifest,
onCloseCallback: () => void,
) {
const evaluateSandbox = async () => {
try {
sandbox.evaluate();
} catch (error) {
console.error(error);
plugin.close();
}
};
const plugin = await createPluginManager(
context,
manifest,
function onClose() {
sandbox.cleanGlobalThis();
onCloseCallback();
},
function onReloadModal() {
evaluateSandbox();
},
);
const sandbox = createSandbox(plugin);
evaluateSandbox();
return {
plugin,
manifest,
compartment: sandbox,
};
}