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 2 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
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;
125 changes: 125 additions & 0 deletions types/scenegraph.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,122 @@ declare interface ScaleFactor {
scaleY: number;
}

/**
* (**Since:** XD 29)
*
* Stores metadata accessible to multiple plugins, separated into silos by plugin ID. Your plugin can read & write the storage for its own plugin ID, but storage for other plugin IDs is *read-only*.
*
* Each per-plugin storage silo is a collection of key-value pairs. Keys and values must both be strings.
*
* *Each* scenenode has its own metadata storage, accessed via `SceneNode.sharedPluginData`. To store general metadata that is not specific to one scenenode, use `sharedPluginData` on the document's scenegraph root.
* @example ```js
* // This example shows how to save & retrieve rich JSON data in shared metadata storage.
// See below for simpler examples of using individual APIs.
const PLUGIN_ID = "<your manifest's plugin ID here>";
let richObject = {
list: [2, 4, 6],
name: "Hello world"
};
node.sharedPluginData.setItem(PLUGIN_ID, "richData", JSON.stringify(richObject));

// Later on...
// (This could be in a different plugin, if it passes the original plugin's ID here)
let jsonString = node.sharedPluginData.getItem(PLUGIN_ID, "richData");
if (jsonString) { // may be undefined
let richObjectCopy = JSON.parse(jsonString);
console.log(richObjectCopy.list.length); // 3
}
pklaschka marked this conversation as resolved.
Show resolved Hide resolved
*/
declare interface PerPluginStorage {
/**
* Returns a map where key is plugin ID and value is a nested map containing all the shared metadata for that plugin ID (i.e. the result of calling `getForPluginId()` with that ID).
*/
pklaschka marked this conversation as resolved.
Show resolved Hide resolved
getAll(): { [key: string]: {[key:string]: string} };

/**
* Returns a map of key-value string pairs containing all shared metadata stored on this node by the given plugin. May be an empty object (zero keys), but is never null.
*
* This map is a clone of the stored metadata, so modifying it has no effect.
* @param pluginId
*
* @example
*const MY_PLUGIN_ID = "<your manifest's plugin ID here>";
let mySharedMetadata = node.sharedPluginData.getForPluginId(MY_PLUGIN_ID);
console.log("My shared 'foo' & 'bar' values:",
mySharedMetadata.foo, mySharedMetadata.bar);


console.log("Plugin B's shared 'foo' value:",
node.sharedPluginData.getForPluginId("B").foo);
pklaschka marked this conversation as resolved.
Show resolved Hide resolved
*/
getForPluginId(pluginId: string): {[key:string]: string};

/**
* Returns a list of all keys stored on this node by the given plugin. May be empty (length zero), but is never null.
* @param pluginId
*
* @example
* console.log("All properties stored by plugin A on this node:",
node.sharedPluginData.keys("A"));
pklaschka marked this conversation as resolved.
Show resolved Hide resolved
*/
keys(pluginId: string): string[];

/**
* Returns the value stored under the given key on this node by the given plugin, or `undefined` if the plugin hasn't stored anything under the given key.
*
* Because metadata is stored separately per plugin, two plugins can store two different values under the same key.
* @param pluginId
* @param key
*
* @example
* // These are two different values, stored independently per plugin
console.log("Plugin A's 'foo' value:", node.sharedPluginData.getItem("A", "foo"));
console.log("Plugin B's 'foo' value:", node.sharedPluginData.getItem("B", "foo"));
pklaschka marked this conversation as resolved.
Show resolved Hide resolved
*/
getItem(pluginId: string, key: string): string | undefined;

/**
* Set a metadata key which can be read by any other plugin.
* @param pluginId *Must* be equal to your plugin's ID.
* @param key
* @param value If undefined, behaves as if you'd called `removeItem()` instead.
*
* @example
const MY_PLUGIN_ID = "<your manifest's plugin ID here>";
node.sharedPluginData.setItem(MY_PLUGIN_ID, "foo", "42");

node.sharedPluginData.setItem("other_plugin_id", "foo", "42");
// ^ ERROR: other plugin's metadata is read-only

console.log(node.sharedPluginData.getItem(MY_PLUGIN_ID, "foo")); // "42"
*/
pklaschka marked this conversation as resolved.
Show resolved Hide resolved
setItem(pluginId: string, key: string, value: string | undefined): void;

/**
* Clears a shared metadata key stored by your plugin.
* @param pluginId *Must* be equal to your plugin's ID.
* @param key
* @example
const MY_PLUGIN_ID = "<your manifest's plugin ID here>";
node.sharedPluginData.setItem(MY_PLUGIN_ID, "foo", "42");
console.log(node.sharedPluginData.getItem(MY_PLUGIN_ID, "foo")); // "42"

node.sharedPluginData.removeItem(MY_PLUGIN_ID, "foo");
console.log(node.sharedPluginData.getItem(MY_PLUGIN_ID, "foo")); // undefined
pklaschka marked this conversation as resolved.
Show resolved Hide resolved
*/
removeItem(pluginId: string, key:string): void;

/**
* Provided for convenience: you can `console.log(node.sharedPluginData)` to see the value of `getAll()`.
*/
toString(): string;

/**
* Provided for convenience: you can include a `PerPluginStorage` object inside data you are going to convert to JSON, even though it is not a plain JavaScript object. Returns the same value as `getAll()`.
*/
toJSON(): object;
}

/**
* Represents the children of a scenenode. Typically accessed via the SceneNode.children property.
*/
Expand Down Expand Up @@ -319,6 +435,15 @@ export class ImageFill {
*/
scaleBehaviour: string;

// TODO: assetId: string (readonly?)
/**
* (**Since**: XD 29)
*
* A unique identifier for the image asset used by this ImageFill. May be shared by other ImageFills, including those with different cropping, size,
rotation, or mirroring. If identical images are imported into XD from separate sources, they may have different `assetId`s however.
pklaschka marked this conversation as resolved.
Show resolved Hide resolved
*/
assetId: string;

/**
* Format the image data was originally encoded in, such as `image/gif` or `image/jpeg`.
*/
Expand Down