Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xd 29 updates #77

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"es2015",
"dom"
]
},
}
}
}
2 changes: 1 addition & 1 deletion sample.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {Text, Ellipse, Color} = require("scenegraph");
const {Text, Ellipse, Color, SceneNode} = require("scenegraph");
const clipboard = require("clipboard");
const shell = require("uxp").shell;
const fs = require("uxp").storage.localFileSystem;
Expand Down
55 changes: 26 additions & 29 deletions types/application.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,6 @@ declare module 'application' {
mergeId?: string;
}

/**
* 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.
*/
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.
*
Expand Down Expand Up @@ -125,6 +110,19 @@ declare module 'application' {
outputFile: storage.File;
}

type DocumentInfo = {
/**
* Document name as displayed in the titlebar. For untitled documents, this will be a localized string such as "Untitled-1."
*/
name: string,
/**
* *Semi*-unique document identifier. Duplicating an .xd file on disk will result in two files with the same GUID. Duplicating a document via "Save As" will change its GUID; thus two *cloud* documents will never have the same GUID. The GUID of an Untitled document doesn't change when it is saved for the first time.
*
* This returns the same value as `scenegraph.root.guid`.
*/
guid: string
};

/**
* Generate renditions of nodes in the document in a batch. Overwrites any existing files without warning.
*
Expand Down Expand Up @@ -158,22 +156,21 @@ declare module 'application' {
export const systemLocale: string;

/**
* Information about the document which this instance of the plugin is attached to.
*
*/
type DocumentInfo = {
/**
* Document name as displayed in the document window.
*/
name: string;
/**
* Unique document identifier that does not change.
*/
guid: string;
}

/**
* Represents the active document. Provides the document guid and current saved name.
* > **Tip**
* >
* > _This does **not** indicate the frontmost "active" document window in the XD application._
* > In XD, each document window loads a separate copy of your plugin. When a given instance of your plugin calls this API, you will always receive information about the document that this instance of the plugin is attached to, even if it's not the active window.
*
* @example
* let application = require("application");
* let documentInfo = application.activeDocument;
* console.log("Document title: " + documentInfo.name);
* console.log("Document ID: " + documentInfo.guid);
*/
export const activeDocument: DocumentInfo;

}


10 changes: 4 additions & 6 deletions types/assets.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,8 @@ declare module 'assets' {
* The list may contain a mix of solid Color assets and/or gradient assets. If there are no color/gradient assets, an empty array is returned.
*
* @example
* var assets = require("assets"),
* allColors = assets.colors.get();
*
* var assets = require("assets"),
* allColors = assets.colors.get();
*/
get(): Array<ColorAsset | GradientAsset>;

Expand Down Expand Up @@ -155,9 +154,8 @@ declare module 'assets' {
* If there are no character style assets, an empty array is returned.
*
* @example
* var assets = require("assets"),
* allCharacterStyles = assets.characterStyles.get();
*
* var assets = require("assets"),
* allCharacterStyles = assets.characterStyles.get();
*/
get(): Array<CharacterStyleAsset>;

Expand Down
27 changes: 20 additions & 7 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,26 +75,39 @@ declare global {
/**
* Array representing the current selection plus any locked items that the user has attempted to select.
*/
itemsIncludingLocked: Array<SceneNode>;
readonly itemsIncludingLocked: ReadonlyArray<SceneNode>;
/**
* True if the selection isn’t empty and consists of one or more non-Artboards. Never true at the same time as hasArtboards.
*/
hasArtwork: boolean;
readonly hasArtwork: boolean;
/**
* True if the selection isn’t empty and consists of one or more Artboards. Never true at the same time as hasArtwork.
*/
hasArtboards: boolean;
readonly hasArtboards: boolean;
/**
* The context in which selection and edit operations must occur. If the user hasn’t drilled into any container node, this value is the document root, and its scope includes all immediate children of the pasteboard (including Artboards), and all immediate children of all those Artboards.
*/
editContext: SceneNode;
readonly editContext: SceneNode;
/**
* The preferred parent to insert newly added content into. Takes into account the current edit context as well as the “focused artboard” if in the root context.
* The preferred parent to insert newly added content into. Takes into account the current edit context as well as the "focused artboard" if in the root context.
Typically this is the same parent where, for example, XD's shape drawing tools would add items.
*
* _Selected items are not necessarily all immediate children of the `insertionParent`._ They can be anywhere within the edit context's scope.
*/
insertionParent: SceneNode;
readonly insertionParent: SceneNode;
/**
* The artboard the user is currently most focused on (via recent selection or edit operations). May be null, for example if no artboards exist or if the user just deleted an artboard.
*/
focusedArtboard: Artboard | null | undefined;
readonly focusedArtboard: Artboard | null | undefined;

/**
* **Since:** XD 28
*
* Returns true if the node is accessible for editing in the scope of the current edit context.
* If false, the node cannot be edited given the user's current selection.
* Nodes that are currently selected are always in the current edit context.
* @param node
*/
isInEditContext(node: SceneNode): boolean;
pklaschka marked this conversation as resolved.
Show resolved Hide resolved
}
}
37 changes: 20 additions & 17 deletions types/interactions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,33 @@ declare module 'interactions' {
*
* May include interactions that are impossible to trigger because the trigger node (or one of its ancestors) has `visible` = false.
*
* Note: currently, this API excludes all of the document's keyboard/gamepad interactions.
* > **Tip**
* >
* > Currently, this API excludes some types of interactions: keypress/gamepad, scrolling, hover, component state transitions, or non-speech audio playback.
*/
export const allInteractions: Array<{ triggerNode: SceneNode, interactions: Array<Interaction> }>;

/**
* An interaction consists of a Trigger + Action pair and is attached to a single, specific scenenode.
*
* @example ```javascript
{
trigger: {
type: "tap"
},
action: {
type: "goToArtboard",
destination: Artboard node,
preserveScrollPosition: false,
transition: {
type: "dissolve",
duration: 0.4,
easing: "ease-out"
}
}
}```
* Note: Interaction objects are not plain JSON -- they may reference scenenodes (as seen above) and other strongly-typed objects.
*
* @example
* {
* trigger: {
* type: "tap"
* },
* action: {
* type: "goToArtboard",
* destination: Artboard node,
* preserveScrollPosition: false,
* transition: {
* type: "dissolve",
* duration: 0.4,
* easing: "ease-out"
* }
* }
* }
*/
type Interaction = {
/**
Expand Down
Loading