mirror of
https://github.com/penpot/penpot-plugins.git
synced 2025-01-06 14:50:21 -05:00
feat: close plugins when exiting the workspace
This commit is contained in:
parent
66ebaffb06
commit
c7e1722459
3 changed files with 22 additions and 4 deletions
10
libs/plugin-types/index.d.ts
vendored
10
libs/plugin-types/index.d.ts
vendored
|
@ -387,6 +387,7 @@ export interface EventsMap {
|
|||
filechange: PenpotFile;
|
||||
selectionchange: string[];
|
||||
themechange: PenpotTheme;
|
||||
finish: string;
|
||||
}
|
||||
|
||||
export type PenpotTheme = 'light' | 'dark';
|
||||
|
@ -433,8 +434,8 @@ export interface PenpotContext {
|
|||
|
||||
uploadMediaUrl(name: string, url: string): Promise<PenpotImageData>;
|
||||
|
||||
group(first: PenpotShape, ...rest: PenpotShape[]): PenpotGroup;
|
||||
ungroup(first: PenpotShape, ...rest: PenpotShape[]): void;
|
||||
group(shapes: PenpotShape[]): PenpotGroup;
|
||||
ungroup(group: PenpotGroup, ...other: PenpotGroup[]): void;
|
||||
|
||||
createRectangle(): PenpotRectangle;
|
||||
createFrame(): PenpotFrame;
|
||||
|
@ -443,7 +444,8 @@ export interface PenpotContext {
|
|||
addListener<T extends keyof EventsMap>(
|
||||
type: T,
|
||||
callback: (event: EventsMap[T]) => void
|
||||
): void;
|
||||
): symbol;
|
||||
removeListener(listenerId: symbol): void;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -451,7 +453,7 @@ export interface PenpotContext {
|
|||
*
|
||||
*/
|
||||
export interface Penpot
|
||||
extends Omit<PenpotContext, 'addListener' | 'group' | 'ungroup'> {
|
||||
extends Omit<PenpotContext, 'addListener' | 'removeListener'> {
|
||||
ui: {
|
||||
/**
|
||||
* Description of open
|
||||
|
|
|
@ -24,6 +24,7 @@ import { getValidUrl } from '../parse-manifest.js';
|
|||
type Callback<T> = (message: T) => void;
|
||||
|
||||
export const validEvents = [
|
||||
'finish',
|
||||
'pagechange',
|
||||
'filechange',
|
||||
'selectionchange',
|
||||
|
@ -232,6 +233,16 @@ export function createApi(context: PenpotContext, manifest: Manifest): Penpot {
|
|||
return context.createShapeFromSvg(svgString);
|
||||
},
|
||||
|
||||
group(shapes: PenpotShape[]): PenpotGroup {
|
||||
// checkPermission('page:write');
|
||||
return context.group(shapes);
|
||||
},
|
||||
|
||||
ungroup(group: PenpotGroup, ...other: PenpotGroup[]): void {
|
||||
// checkPermission('page:write');
|
||||
context.ungroup(group, ...other);
|
||||
},
|
||||
|
||||
uploadMediaUrl(name: string, url: string) {
|
||||
return context.uploadMediaUrl(name, url);
|
||||
},
|
||||
|
|
|
@ -37,6 +37,11 @@ export const ɵloadPlugin = async function (manifest: Manifest) {
|
|||
});
|
||||
|
||||
c.evaluate(code);
|
||||
|
||||
const listenerId: symbol = pluginContext.addListener('finish', () => {
|
||||
lastApi?.closePlugin();
|
||||
pluginContext?.removeListener(listenerId);
|
||||
});
|
||||
} else {
|
||||
console.error('Cannot find Penpot Context');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue