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

feat(plugin-types): add undo block operations to api

This commit is contained in:
alonso.torres 2024-07-26 12:03:36 +02:00 committed by Alonso Torres
parent 9a9b33a8fe
commit 1d3ad89c99
2 changed files with 40 additions and 2 deletions

View file

@ -202,12 +202,21 @@ export interface PenpotFile extends PenpotPluginData {
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.
* - `'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
* @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;
/**
* 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.
* @example
@ -3176,6 +3191,24 @@ export interface 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.
*/

View file

@ -22,6 +22,7 @@ import type {
PenpotSvgRaw,
PenpotColor,
PenpotColorShapeInfo,
PenpotHistoryContext,
} from '@penpot/plugin-types';
import { Manifest, Permissions } from '../models/manifest.model.js';
@ -231,6 +232,10 @@ export function createApi(context: PenpotContext, manifest: Manifest): Penpot {
return context.viewport;
},
get history(): PenpotHistoryContext {
return context.history;
},
get library(): PenpotLibraryContext {
checkPermission('library:read');
return context.library;