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 5 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
3 changes: 2 additions & 1 deletion sample.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {Text, Ellipse, Color, RootNode} = require("scenegraph");
const {Text, Ellipse, Color, RootNode, SceneNode} = require("scenegraph");
const clipboard = require("clipboard");
const shell = require("uxp").shell;
const fs = require("uxp").storage.localFileSystem;
Expand All @@ -9,6 +9,7 @@ const assets = require('assets');
* @param {RootNode} documentRoot
*/
async function test(selection, documentRoot) {

selection.items.forEach(async node => {
console.log("Hello world: ", node);
if (node instanceof Text) {
Expand Down
29 changes: 29 additions & 0 deletions types/application.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ type RenditionResult = {
outputFile: 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. <br><br>This returns the same value as `scenegraph.root.guid`.
pklaschka marked this conversation as resolved.
Show resolved Hide resolved
*/
guid: string
};

/**
* Generate renditions of nodes in the document in a batch. Overwrites any existing files without warning.
*
Expand All @@ -72,3 +83,21 @@ export const appLanguage: string;
* User's OS-wide locale setting. May not match the XD UI, since XD does not support all world languages. Includes both language and region (e.g. "fr_CA" or "en_US").
*/
export const systemLocale: string;

/**
* Information about the document which this instance of the plugin is attached to.
*
* > **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.
pklaschka marked this conversation as resolved.
Show resolved Hide resolved
*
* @example ```js
let application = require("application");
let documentInfo = application.activeDocument;
console.log("Document title: " + documentInfo.name);
console.log("Document ID: " + documentInfo.guid);
```
*/
pklaschka marked this conversation as resolved.
Show resolved Hide resolved
export const activeDocument: DocumentInfo;
29 changes: 20 additions & 9 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,7 @@ declare global {
*/
function require(module: string): void;

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

/**
* 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 Expand Up @@ -37,26 +37,37 @@ declare global {
/**
* Array representing the current selection plus any locked items that the user has attempted to select.
*/
itemsIncludingLocked: Array<SceneNode>;
readonly itemsIncludingLocked: Array<SceneNode>;
pklaschka marked this conversation as resolved.
Show resolved Hide resolved
/**
* 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](/reference/core/edit-context.md) scope.
pklaschka marked this conversation as resolved.
Show resolved Hide resolved
*/
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;

/**
* 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
}
}
4 changes: 3 additions & 1 deletion types/interactions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export const homeArtboard: Artboard | null;
*
* 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> }>;

Expand Down
Loading