Skip to content

Commit

Permalink
Merge pull request #59 from AdobeXD/scenenode-rootnode-fix
Browse files Browse the repository at this point in the history
Stop exporting SceneNode and RootNode
  • Loading branch information
pklaschka authored Aug 28, 2019
2 parents a5305e1 + c8c0953 commit 572a817
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 60 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adobexd/typings",
"version": "20.1.0",
"version": "20.2.0",
"typings": "./types/index.d.ts",
"description": "Typings for Adobe XD CC",
"repository": {
Expand Down
101 changes: 90 additions & 11 deletions types/application.d.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,93 @@
import {Color, SceneNode} from "scenegraph";
import { Color, SceneNode, RootNode } from "scenegraph";
import { storage } from "uxp";

interface EditSettings {
/**
* Used as the Undo label in the **Edit** menu. If unspecified, XD uses the `uxp-edit-label` attribute on the DOM node which the user interacted with, and if that does not exist then the plugin's name will be used.
*/
editLabel?: string;
/**
* If two consecutive edits to the same selection have the same `mergeId`, they are flattened together into one Undo step. If unspecified, for "high frequency" UI events (see above), XD treats the originating DOM node as a unique identifier for merging; for other UI events, merging is disabled.
*/
mergeId?: string;
}

/**
* All rendition settings fields are required (for a given rendition type) unless otherwise specified.
* Call `editDocument()` from a plugin panel UI event listener to initiate an edit operation batch in order to modify the XD document. This API is irrelevant for plugin menu item commands, which are wrapped in an edit batch automatically.
*
* XD calls the `editFunction()` synchronously (before `editDocument()` returns). This function is treated the same as a menu command handler:
*
* * It is passed two arguments, the selection and the root node of the scenegraph
* * It can return a Promise to extend the duration of the edit asynchronously
*
* You can only call `editDocument()` in response to a user action, such as a button `"click"` event or a text input's `"input"` event. This generally means you must call it while a UI event handler is on the call stack.
*
* For UI events that often occur in rapid-fire clusters, such as dragging a slider or pressing keys in a text field, XD tries to smartly merge consecutive edits into a single atomic Undo step. See the `mergeId` option below to customize this behavior.
* @param editFunction Function which will perform your plugin's edits to the scenegraph.
*/
type RenditionSettings = {
export function editDocument(editFunction: (selection: Selection, root: RootNode) => Promise<any> | void): void;

/**
* Call `editDocument()` from a plugin panel UI event listener to initiate an edit operation batch in order to modify the XD document. This API is irrelevant for plugin menu item commands, which are wrapped in an edit batch automatically.
*
* XD calls the `editFunction()` synchronously (before `editDocument()` returns). This function is treated the same as a menu command handler:
*
* * It is passed two arguments, the selection and the root node of the scenegraph
* * It can return a Promise to extend the duration of the edit asynchronously
*
* You can only call `editDocument()` in response to a user action, such as a button `"click"` event or a text input's `"input"` event. This generally means you must call it while a UI event handler is on the call stack.
*
* For UI events that often occur in rapid-fire clusters, such as dragging a slider or pressing keys in a text field, XD tries to smartly merge consecutive edits into a single atomic Undo step. See the `mergeId` option below to customize this behavior.
* @param options Optional settings object (see below). This argument can be omitted.
* @param editFunction Function which will perform your plugin's edits to the scenegraph.
*/
export function editDocument(options: EditSettings, editFunction: (selection: Selection, root: RootNode) => Promise<any> | void): void;

interface RenditionSettingsBase {
/**
* Root of scenegraph subtree to render. This may be any node in the scenegraph, regardless of the current edit context.
*/
node: SceneNode;
/**
* File to save the rendition to (overwritten without warning if it already exists)
*/
outputFile: File;
/**
* File type: RenditionType.PNG, JPG, PDF, or SVG
*/
type: string;
outputFile: storage.File;
}

interface RenditionSettingsPNGorJPG extends RenditionSettingsBase {
/**
* (PNG & JPG renditions) DPI multipler in the range [0.1, 100], e.g. 2.0 for @2x DPI.
*/
scale: number;
/**
* (PNG & JPEG renditions) Alpha component ignored for JPG. Optional: defaults to transparent for PNG, solid white for JPG.
*/
background?: Color;
}

export interface RenditionSettingsPNG extends RenditionSettingsPNGorJPG {
/**
* File type
*/
type: RenditionType.PNG;
}

export interface RenditionSettingsJPG extends RenditionSettingsPNGorJPG {
/**
* File type.
*/
type: RenditionType.JPG;
/**
* (JPG renditions) Compression quality in the range [1, 100].
*/
quality: number;
}

export interface RenditionSettingsSVG extends RenditionSettingsBase {
/**
* (PNG & JPEG renditions) Alpha component ignored for JPG. Optional: defaults to transparent for PNG, solid white for JPG.
* File type.
*/
background: Color;
type: RenditionType.SVG;
/**
* (SVG renditions) If true, SVG code is minified.
*/
Expand All @@ -38,14 +98,26 @@ type RenditionSettings = {
embedImages: boolean;
}

export interface RenditionSettingsPDF extends RenditionSettingsBase {
/**
* File type
*/
type: RenditionType.PDF;
}

/**
* All rendition settings fields are required (for a given rendition type) unless otherwise specified.
*/
export type RenditionSettings = RenditionSettingsPNG | RenditionSettingsJPG | RenditionSettingsSVG | RenditionSettingsPDF;

/**
* Type that gets returned by `application.createRenditions`
*/
type RenditionResult = {
/**
* File the rendition was written to (equal to outputFile in RenditionSettings)
*/
outputFile: File;
outputFile: storage.File;
}

/**
Expand All @@ -58,6 +130,13 @@ type RenditionResult = {
*/
export function createRenditions(renditions: RenditionSettings[]): Promise<RenditionResult[] | string>;

export enum RenditionType {
JPG = "jpg",
PNG = "png",
PDF = "pdf",
SVG = "svg",
}

/**
* Adobe XD version number in the form "major.minor.patch.build"
*/
Expand Down
39 changes: 37 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Artboard, SceneNode} from "./scenegraph";
import { Artboard, SceneNode } from "./scenegraph";

declare global {
/**
Expand All @@ -7,7 +7,42 @@ declare global {
*/
function require(module: string): void;

let module: {exports:any};
let module: { exports: any };

/**
* Represents the children of a scenenode. Typically accessed via the SceneNode.children property.
*/
interface SceneNodeList {
items: SceneNode[];
readonly length: number;

forEach(
callback: (sceneNode: SceneNode, index: number) => void,
thisArg?: object
): void;

forEachRight(
callback: (sceneNode: SceneNode, index: number) => void,
thisArg?: object
): void;

filter(
callback: (sceneNode: SceneNode, index: number) => boolean,
thisArg?: object
): Array<SceneNode>;

map(
callback: (sceneNode: SceneNode, index: number) => any,
thisArg?: object
): Array<any>;

some(
callback: (sceneNode: SceneNode, index: number) => boolean,
thisArg?: object
): boolean;

at(index: number): SceneNode | null;
}

/**
* The selection object represents the currently selected set of nodes in the UI. You can set the selection to use it as input for commands, or to determine what is left selected for the user when your plugin’s edit operation completes.
Expand Down
64 changes: 18 additions & 46 deletions types/scenegraph.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Interaction} from 'interactions';
import { Interaction } from 'interactions';
import { storage } from 'uxp';

declare interface Point {
x: number;
Expand All @@ -10,41 +11,6 @@ declare interface ScaleFactor {
scaleY: number;
}

/**
* Represents the children of a scenenode. Typically accessed via the SceneNode.children property.
*/
declare interface SceneNodeList {
items: SceneNode[];
readonly length: number;

forEach(
callback: (sceneNode: SceneNode, index: number) => void,
thisArg?: object
): void;

forEachRight(
callback: (sceneNode: SceneNode, index: number) => void,
thisArg?: object
): void;

filter(
callback: (sceneNode: SceneNode, index: number) => boolean,
thisArg?: object
): Array<SceneNode>;

map(
callback: (sceneNode: SceneNode, index: number) => any,
thisArg?: object
): Array<any>;

some(
callback: (sceneNode: SceneNode, index: number) => boolean,
thisArg?: object
): boolean;

at(index: number): SceneNode | null;
}

export class Matrix {
/**
* Creates a new transform matrix with the following structure:
Expand Down Expand Up @@ -343,7 +309,7 @@ export class ImageFill {
*
* @param fileOrDataURI File object pointing to an image file; or a string containing a data: URI with a base-64 encoded image.
*/
constructor(fileOrDataURI: string | File);
constructor(fileOrDataURI: string | storage.File);

/**
* @returns a new copy of this ImageFill.
Expand Down Expand Up @@ -433,10 +399,12 @@ export interface Bounds {
height: number;
}

export interface SceneNode extends SceneNodeClass { }

/**
* Base class of all scenegraph nodes. Nodes will always be an instance of some subclass of SceneNode.
*/
export abstract class SceneNode {
declare abstract class SceneNodeClass {
/**
* Returns a unique identifier for this node that stays the same when the file is closed & reopened, or if the node is moved to a different part of the document. Cut-Paste will result in a new guid, however.
*/
Expand Down Expand Up @@ -629,7 +597,7 @@ export abstract class SceneNode {
/**
* Base class for nodes that have a stroke and/or fill. This includes leaf nodes such as Rectangle, as well as BooleanGroup which is a container node. If you create a shape node, it will not be visible unless you explicitly give it either a stroke or a fill.
*/
export class GraphicNode extends SceneNode {
export class GraphicNode extends SceneNodeClass {
/**
* The fill applied to this shape, if any. If this property is null or fillEnabled is false, no fill is drawn. Freshly created nodes have no fill by default.
*
Expand Down Expand Up @@ -882,7 +850,7 @@ export class Line extends GraphicNode {
* @param {number} endX
* @param {number} endY
*/
setSTartEnd(
setStartEnd(
startX: number,
startY: number,
endX: number,
Expand Down Expand Up @@ -1170,7 +1138,7 @@ export class Text extends GraphicNode {
*
* In a Mask Group, the mask shape is included in the group’s children list, at the top of the z order. It is not visible - only its path outline is used, for clipping the group.
*/
export class Group extends SceneNode {
export class Group extends SceneNodeClass {
/**
* The mask shape applied to this group, if any. This object is also present in the group’s children list. Though it has no direct visual appearance of its own, the mask affects the entire groups’s appearance by clipping all its other content.
*/
Expand Down Expand Up @@ -1212,9 +1180,9 @@ export class Group extends SceneNode {
*
* Note that overrides vary somewhat in granularity. In some but not all cases, overriding one property may also prevent other properties on the same node from receiving future updates from the master instance.
*
* It is not currently possible for plugins to *create* a new component definition or a new SymbolInstance node, aside from using {@link commands.duplicate} to clone existing SymbolInstances.
* It is not currently possible for plugins to *create* a new component definition or a new SymbolInstance node, aside from using `require('commands').duplicate` to clone existing SymbolInstances.
*/
export class SymbolInstance extends SceneNode {
export class SymbolInstance extends SceneNodeClass {
/**
* An identifier unique within this document that is shared by all instances of the same component.
*/
Expand Down Expand Up @@ -1258,7 +1226,7 @@ export class SymbolInstance extends SceneNode {
* Each grid cell is a Group that is an immediate child of the RepeatGrid. These groups are automatically created and destroyed as needed when the RepeatGrid is resized.
* It is not currently possible for plugins to create a new RepeatGrid node, aside from using commands.duplicate to clone existing RepeatGrids.
*/
export class RepeatGrid extends SceneNode {
export class RepeatGrid extends SceneNodeClass {
/**
* Defines size of the RepeatGrid. Cells are created and destroyed as necessary to fill the current size. Cells that only partially fit will be clipped.
*/
Expand Down Expand Up @@ -1344,13 +1312,15 @@ export class RepeatGrid extends SceneNode {
/**
* Container node whose content is linked to an external resource, such as Creative Cloud Libraries. It cannot be edited except by first ungrouping it, breaking this link.
*/
export class LinkedGraphic extends SceneNode {
export class LinkedGraphic extends SceneNodeClass {
}

export interface RootNode extends RootNodeClass { }

/**
* Class representing the root node of the document. All Artboards are children of this node, as well as any pasteboard content that does not lie within an Artboard. Artboards must be grouped contiguously at the bottom of this node’s z order. The root node has no visual appearance of its own.
*/
export class RootNode extends SceneNode {
declare class RootNodeClass extends SceneNodeClass {
/**
* Adds a child node to this container node. You can only add leaf nodes this way; to create structured subtrees of content, use commands.
* @param {SceneNode} node Child to add
Expand Down Expand Up @@ -1389,3 +1359,5 @@ export const selection: SceneNodeList;
* Root node of the current document's scenegraph. Also available as the second argument passed to your plugin command handler function.
*/
export const root: RootNode;

export { };

0 comments on commit 572a817

Please sign in to comment.