Skip to content

Commit

Permalink
feat(notifications): add notifications
Browse files Browse the repository at this point in the history
update dependencies
  • Loading branch information
ph1p committed Sep 15, 2019
1 parent 69bec6b commit e66819a
Show file tree
Hide file tree
Showing 5 changed files with 572 additions and 235 deletions.
111 changes: 84 additions & 27 deletions figma.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// Figma Plugin API version 1, update 1

// Global variable with Figma's plugin API.
declare const figma: PluginAPI;
declare const __html__: string;

interface PluginAPI {
readonly apiVersion: '1.0.0';
readonly command: string;
readonly root: DocumentNode;
readonly viewport: ViewportAPI;
closePlugin(message?: string): void;

notify(message: string, options?: NotificationOptions): NotificationHandler;

showUI(html: string, options?: ShowUIOptions): void;
readonly ui: UIAPI;

Expand All @@ -17,6 +20,7 @@ interface PluginAPI {
getNodeById(id: string): BaseNode | null;
getStyleById(id: string): BaseStyle | null;

readonly root: DocumentNode;
currentPage: PageNode;

readonly mixed: symbol;
Expand All @@ -28,17 +32,27 @@ interface PluginAPI {
createStar(): StarNode;
createVector(): VectorNode;
createText(): TextNode;
createBooleanOperation(): BooleanOperationNode;
createFrame(): FrameNode;
createComponent(): ComponentNode;
createPage(): PageNode;
createSlice(): SliceNode;
/**
* [DEPRECATED]: This API often fails to create a valid boolean operation. Use figma.union, figma.subtract, figma.intersect and figma.exclude instead.
*/
createBooleanOperation(): BooleanOperationNode;

createPaintStyle(): PaintStyle;
createTextStyle(): TextStyle;
createEffectStyle(): EffectStyle;
createGridStyle(): GridStyle;

// The styles are returned in the same order as displayed in the UI. Only
// local styles are returned. Never styles from team library.
getLocalPaintStyles(): PaintStyle[];
getLocalTextStyles(): TextStyle[];
getLocalEffectStyles(): EffectStyle[];
getLocalGridStyles(): GridStyle[];

importComponentByKeyAsync(key: string): Promise<ComponentNode>;
importStyleByKeyAsync(key: string): Promise<BaseStyle>;

Expand All @@ -61,26 +75,55 @@ interface PluginAPI {
parent?: BaseNode & ChildrenMixin,
index?: number
): VectorNode;

union(
nodes: ReadonlyArray<BaseNode>,
parent: BaseNode & ChildrenMixin,
index?: number
): BooleanOperationNode;
subtract(
nodes: ReadonlyArray<BaseNode>,
parent: BaseNode & ChildrenMixin,
index?: number
): BooleanOperationNode;
intersect(
nodes: ReadonlyArray<BaseNode>,
parent: BaseNode & ChildrenMixin,
index?: number
): BooleanOperationNode;
exclude(
nodes: ReadonlyArray<BaseNode>,
parent: BaseNode & ChildrenMixin,
index?: number
): BooleanOperationNode;
}

interface ClientStorageAPI {
getAsync(key: string): Promise<any | undefined>;
setAsync(key: string, value: any): Promise<void>;
}

type ShowUIOptions = {
interface NotificationOptions {
timeout?: number;
}

interface NotificationHandler {
cancel: () => void;
}

interface ShowUIOptions {
visible?: boolean;
width?: number;
height?: number;
};
}

type UIPostMessageOptions = {
targetOrigin?: string;
};
interface UIPostMessageOptions {
origin?: string;
}

type OnMessageProperties = {
sourceOrigin: string;
};
interface OnMessageProperties {
origin: string;
}

interface UIAPI {
show(): void;
Expand Down Expand Up @@ -168,13 +211,13 @@ interface ColorStop {
}

interface ImageFilters {
exposure?: number;
contrast?: number;
saturation?: number;
temperature?: number;
tint?: number;
highlights?: number;
shadows?: number;
readonly exposure?: number;
readonly contrast?: number;
readonly saturation?: number;
readonly temperature?: number;
readonly tint?: number;
readonly highlights?: number;
readonly shadows?: number;
}

interface SolidPaint {
Expand Down Expand Up @@ -311,10 +354,10 @@ interface VectorPath {

type VectorPaths = ReadonlyArray<VectorPath>;

type LetterSpacing = {
interface LetterSpacing {
readonly value: number;
readonly unit: 'PIXELS' | 'PERCENT';
};
}

type LineHeight =
| {
Expand Down Expand Up @@ -356,7 +399,7 @@ interface Font {
interface BaseNodeMixin {
readonly id: string;
readonly parent: (BaseNode & ChildrenMixin) | null;
name: string; // Note: setting this also sets `autoRename` to false on TextNodes
name: string; // Note: setting this also sets \`autoRename\` to false on TextNodes
readonly removed: boolean;
toString(): string;
remove(): void;
Expand All @@ -376,13 +419,13 @@ interface SceneNodeMixin {
}

interface ChildrenMixin {
readonly children: ReadonlyArray<BaseNode>;
readonly children: ReadonlyArray<SceneNode>;

appendChild(child: BaseNode): void;
insertChild(index: number, child: BaseNode): void;
appendChild(child: SceneNode): void;
insertChild(index: number, child: SceneNode): void;

findAll(callback?: (node: BaseNode) => boolean): ReadonlyArray<BaseNode>;
findOne(callback: (node: BaseNode) => boolean): BaseNode | null;
findAll(callback?: (node: SceneNode) => boolean): SceneNode[];
findOne(callback: (node: SceneNode) => boolean): SceneNode | null;
}

interface ConstraintMixin {
Expand Down Expand Up @@ -447,7 +490,7 @@ interface CornerMixin {
}

interface ExportMixin {
exportSettings: ExportSettings[];
exportSettings: ReadonlyArray<ExportSettings>;
exportAsync(settings?: ExportSettings): Promise<Uint8Array>; // Defaults to PNG format
}

Expand All @@ -472,8 +515,20 @@ interface DefaultContainerMixin
////////////////////////////////////////////////////////////////////////////////
// Nodes

interface DocumentNode extends BaseNodeMixin, ChildrenMixin {
interface DocumentNode extends BaseNodeMixin {
readonly type: 'DOCUMENT';

readonly children: ReadonlyArray<PageNode>;

appendChild(child: PageNode): void;
insertChild(index: number, child: PageNode): void;

findAll(
callback?: (node: PageNode | SceneNode) => boolean
): Array<PageNode | SceneNode>;
findOne(
callback: (node: PageNode | SceneNode) => boolean
): PageNode | SceneNode | null;
}

interface PageNode extends BaseNodeMixin, ChildrenMixin, ExportMixin {
Expand All @@ -482,6 +537,8 @@ interface PageNode extends BaseNodeMixin, ChildrenMixin, ExportMixin {

guides: ReadonlyArray<Guide>;
selection: ReadonlyArray<SceneNode>;

backgrounds: ReadonlyArray<Paint>;
}

interface FrameNode extends DefaultContainerMixin {
Expand Down
Loading

0 comments on commit e66819a

Please sign in to comment.