mirror of
https://github.com/penpot/penpot-plugins.git
synced 2025-01-04 13:50:13 -05:00
feat(plugin-types): add ruler guides and new zoom methods
This commit is contained in:
parent
3bfa2a5c22
commit
c8066becca
5 changed files with 22 additions and 25 deletions
16
libs/plugin-types/index.d.ts
vendored
16
libs/plugin-types/index.d.ts
vendored
|
@ -354,7 +354,7 @@ export interface Page extends PluginData {
|
|||
/**
|
||||
* Removes the `guide` from the current page.
|
||||
*/
|
||||
removeRulerGuide(guide: RulerGuide);
|
||||
removeRulerGuide(guide: RulerGuide): void;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1845,7 +1845,7 @@ export interface Board extends ShapeBase {
|
|||
/**
|
||||
* Removes the `guide` from the current page.
|
||||
*/
|
||||
removeRulerGuide(guide: RulerGuide);
|
||||
removeRulerGuide(guide: RulerGuide): void;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2312,18 +2312,18 @@ export interface Viewport {
|
|||
/**
|
||||
* Resets the zoom level.
|
||||
*/
|
||||
zoomReset();
|
||||
zoomReset(): void;
|
||||
|
||||
/**
|
||||
* Changes the viewport and zoom so can fit all the current shapes in the page.
|
||||
*/
|
||||
zoomToFitAll();
|
||||
zoomToFitAll(): void;
|
||||
|
||||
/**
|
||||
* Changes the viewport and zoom so all the `shapes` in the argument are
|
||||
* visible.
|
||||
*/
|
||||
zoomToShapes(shapes: Shape[]);
|
||||
zoomToShapes(shapes: Shape[]): void;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2341,7 +2341,7 @@ export interface Viewport {
|
|||
export type Shape =
|
||||
| Board
|
||||
| Group
|
||||
| Bool
|
||||
| Boolean
|
||||
| Rectangle
|
||||
| Path
|
||||
| Text
|
||||
|
@ -3363,7 +3363,7 @@ export interface Context {
|
|||
* const booleanShape = context.createBoolean('union', [shape1, shape2]);
|
||||
* ```
|
||||
*/
|
||||
createBoolean(boolType: BooleanType, shapes: Shape[]): Bool | null;
|
||||
createBoolean(boolType: BooleanType, shapes: Shape[]): Boolean | null;
|
||||
/**
|
||||
* Creates a Group from an SVG string. Requires `content:write` permission.
|
||||
* @param svgString The SVG string representing the shapes to be converted into a group.
|
||||
|
@ -3861,7 +3861,7 @@ export interface ContextTypesUtils {
|
|||
* @param shape - The shape to check.
|
||||
* @return Returns true if the shape is a Bool, otherwise false.
|
||||
*/
|
||||
isBool(shape: Shape): shape is Bool;
|
||||
isBool(shape: Shape): shape is Boolean;
|
||||
|
||||
/**
|
||||
* Checks if the given shape is a rectangle.
|
||||
|
|
|
@ -2,7 +2,7 @@ import { describe, it, vi, expect, beforeEach, afterEach } from 'vitest';
|
|||
import { createPlugin } from './create-plugin';
|
||||
import { createPluginManager } from './plugin-manager.js';
|
||||
import { createSandbox } from './create-sandbox.js';
|
||||
import type { PenpotContext } from '@penpot/plugin-types';
|
||||
import type { Context } from '@penpot/plugin-types';
|
||||
import type { Manifest } from './models/manifest.model.js';
|
||||
|
||||
vi.mock('./plugin-manager.js', () => ({
|
||||
|
@ -14,7 +14,7 @@ vi.mock('./create-sandbox.js', () => ({
|
|||
}));
|
||||
|
||||
describe('createPlugin', () => {
|
||||
let mockContext: PenpotContext;
|
||||
let mockContext: Context;
|
||||
let manifest: Manifest;
|
||||
let onCloseCallback: ReturnType<typeof vi.fn>;
|
||||
let mockPluginManager: Awaited<ReturnType<typeof createPluginManager>>;
|
||||
|
@ -59,7 +59,7 @@ describe('createPlugin', () => {
|
|||
addListener: vi.fn(),
|
||||
removeListener: vi.fn(),
|
||||
getTheme: vi.fn().mockReturnValue('light'),
|
||||
} as unknown as PenpotContext;
|
||||
} as unknown as Context;
|
||||
|
||||
onCloseCallback = vi.fn();
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import type { PenpotContext } from '@penpot/plugin-types';
|
||||
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: PenpotContext,
|
||||
context: Context,
|
||||
manifest: Manifest,
|
||||
onCloseCallback: () => void
|
||||
) {
|
||||
|
|
|
@ -3,7 +3,7 @@ import { createPluginManager } from './plugin-manager';
|
|||
import { loadManifestCode, getValidUrl } from './parse-manifest.js';
|
||||
import { PluginModalElement } from './modal/plugin-modal.js';
|
||||
import { openUIApi } from './api/openUI.api.js';
|
||||
import type { PenpotContext, PenpotTheme } from '@penpot/plugin-types';
|
||||
import type { Context, Theme } from '@penpot/plugin-types';
|
||||
import type { Manifest } from './models/manifest.model.js';
|
||||
|
||||
vi.mock('./parse-manifest.js', () => ({
|
||||
|
@ -16,7 +16,7 @@ vi.mock('./api/openUI.api.js', () => ({
|
|||
}));
|
||||
|
||||
describe('createPluginManager', () => {
|
||||
let mockContext: PenpotContext;
|
||||
let mockContext: Context;
|
||||
let manifest: Manifest;
|
||||
let onCloseCallback: ReturnType<typeof vi.fn>;
|
||||
let onReloadModal: ReturnType<typeof vi.fn>;
|
||||
|
@ -59,7 +59,7 @@ describe('createPluginManager', () => {
|
|||
addListener: vi.fn().mockReturnValue(Symbol()),
|
||||
removeListener: vi.fn(),
|
||||
getTheme: vi.fn().mockReturnValue('light'),
|
||||
} as unknown as PenpotContext;
|
||||
} as unknown as Context;
|
||||
|
||||
onCloseCallback = vi.fn();
|
||||
onReloadModal = vi.fn();
|
||||
|
@ -159,7 +159,7 @@ describe('createPluginManager', () => {
|
|||
throw new Error('Theme change callback not found');
|
||||
}
|
||||
|
||||
themeChangeCallback('dark' as PenpotTheme);
|
||||
themeChangeCallback('dark' as Theme);
|
||||
|
||||
expect(mockModal.setTheme).toHaveBeenCalledWith('dark');
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import type { PenpotContext, PenpotTheme } from '@penpot/plugin-types';
|
||||
import type { Context, Theme } from '@penpot/plugin-types';
|
||||
|
||||
import { getValidUrl, loadManifestCode } from './parse-manifest.js';
|
||||
import { Manifest } from './models/manifest.model.js';
|
||||
|
@ -8,7 +8,7 @@ import { OpenUIOptions } from './models/open-ui-options.model.js';
|
|||
import { RegisterListener, DestroyListener } from './models/plugin.model.js';
|
||||
|
||||
export async function createPluginManager(
|
||||
context: PenpotContext,
|
||||
context: Context,
|
||||
manifest: Manifest,
|
||||
onCloseCallback: () => void,
|
||||
onReloadModal: (code: string) => void
|
||||
|
@ -21,12 +21,9 @@ export async function createPluginManager(
|
|||
let uiMessagesCallbacks: ((message: unknown) => void)[] = [];
|
||||
const timeouts = new Set<ReturnType<typeof setTimeout>>();
|
||||
|
||||
const themeChangeId = context.addListener(
|
||||
'themechange',
|
||||
(theme: PenpotTheme) => {
|
||||
modal?.setTheme(theme);
|
||||
}
|
||||
);
|
||||
const themeChangeId = context.addListener('themechange', (theme: Theme) => {
|
||||
modal?.setTheme(theme);
|
||||
});
|
||||
|
||||
const listenerId: symbol = context.addListener('finish', () => {
|
||||
closePlugin();
|
||||
|
|
Loading…
Reference in a new issue