mirror of
https://github.com/penpot/penpot-plugins.git
synced 2025-01-21 22:22:45 -05:00
feat(plugin-types): add undo block operations to api
This commit is contained in:
parent
9a9b33a8fe
commit
1d3ad89c99
2 changed files with 40 additions and 2 deletions
37
libs/plugin-types/index.d.ts
vendored
37
libs/plugin-types/index.d.ts
vendored
|
@ -202,12 +202,21 @@ export interface PenpotFile extends PenpotPluginData {
|
||||||
pages: PenpotPage[];
|
pages: PenpotPage[];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Export the current file to an archive
|
* Export the current file to an archive.
|
||||||
* @param `exportType` indicates the type of file to generate.
|
* @param `exportType` indicates the type of file to generate.
|
||||||
* - `'penpot'` will create a *.penpot file with a binary representation of the file
|
* - `'penpot'` will create a *.penpot file with a binary representation of the file
|
||||||
* - `'zip'` will create a *.zip with the file exported in several SVG files with some JSON metadata
|
* - `'zip'` will create a *.zip with the file exported in several SVG files with some JSON metadata
|
||||||
|
* @param `libraryExportType` indicates what to do with the linked libraries of the file when
|
||||||
|
* exporting it. Defaults to `all` if not sent.
|
||||||
|
* - `'all'` will include the libraries as external files that will be exported in a single bundle
|
||||||
|
* - `'merge'` will add all the assets into the main file and only one file will be imported
|
||||||
|
* - `'detach'` will unlink all the external assets and no libraries will be imported
|
||||||
|
* @param `progressCallback` for `zip` export can be pass this callback so a progress report is sent.
|
||||||
*/
|
*/
|
||||||
export(exportType: 'penpot' | 'zip'): Promise<Uint8Array>;
|
export(
|
||||||
|
exportType: 'penpot' | 'zip',
|
||||||
|
libraryExportType?: 'all' | 'merge' | 'detach'
|
||||||
|
): Promise<Uint8Array>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2598,6 +2607,12 @@ export interface PenpotContext {
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
readonly viewport: PenpotViewport;
|
readonly viewport: PenpotViewport;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Context encapsulating the history operations
|
||||||
|
*/
|
||||||
|
readonly history: PenpotHistoryContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The library context in the Penpot context, including both local and connected libraries. Requires `library:read` permission.
|
* The library context in the Penpot context, including both local and connected libraries. Requires `library:read` permission.
|
||||||
* @example
|
* @example
|
||||||
|
@ -3176,6 +3191,24 @@ export interface PenpotPush {
|
||||||
*/
|
*/
|
||||||
export type PenpotAnimation = PenpotDissolve | PenpotSlide | PenpotPush;
|
export type PenpotAnimation = PenpotDissolve | PenpotSlide | PenpotPush;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This object allows to access to some history functions
|
||||||
|
*/
|
||||||
|
export interface PenpotHistoryContext {
|
||||||
|
/**
|
||||||
|
* Starts an undo block. All operations done inside this block will be undone together until
|
||||||
|
* a call to `undoBlockFinish` is called.
|
||||||
|
* @returns the block identifier
|
||||||
|
*/
|
||||||
|
undoBlockBegin(): Symbol;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ends the undo block started with `undoBlockBegin`
|
||||||
|
* @parm `blockId` is the id returned by `undoBlockBegin`
|
||||||
|
*/
|
||||||
|
undoBlockFinish(blockId: Symbol): void;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility methods for geometric calculations in Penpot.
|
* Utility methods for geometric calculations in Penpot.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -22,6 +22,7 @@ import type {
|
||||||
PenpotSvgRaw,
|
PenpotSvgRaw,
|
||||||
PenpotColor,
|
PenpotColor,
|
||||||
PenpotColorShapeInfo,
|
PenpotColorShapeInfo,
|
||||||
|
PenpotHistoryContext,
|
||||||
} from '@penpot/plugin-types';
|
} from '@penpot/plugin-types';
|
||||||
|
|
||||||
import { Manifest, Permissions } from '../models/manifest.model.js';
|
import { Manifest, Permissions } from '../models/manifest.model.js';
|
||||||
|
@ -231,6 +232,10 @@ export function createApi(context: PenpotContext, manifest: Manifest): Penpot {
|
||||||
return context.viewport;
|
return context.viewport;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
get history(): PenpotHistoryContext {
|
||||||
|
return context.history;
|
||||||
|
},
|
||||||
|
|
||||||
get library(): PenpotLibraryContext {
|
get library(): PenpotLibraryContext {
|
||||||
checkPermission('library:read');
|
checkPermission('library:read');
|
||||||
return context.library;
|
return context.library;
|
||||||
|
|
Loading…
Add table
Reference in a new issue