Skip to content

Commit

Permalink
Merge pull request #47 from AdobeXD/xd-19-fixes
Browse files Browse the repository at this point in the history
XD 20 APIs
  • Loading branch information
pklaschka authored Jun 25, 2019
2 parents 357af6b + 1160e75 commit 2bc1dca
Show file tree
Hide file tree
Showing 10 changed files with 619 additions and 398 deletions.
14 changes: 10 additions & 4 deletions sample.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const {Text, Ellipse, Color} = require("scenegraph");
const {Text, Ellipse, Color, RootNode} = require("scenegraph");
const clipboard = require("clipboard");
const application = require("application");
const shell = require("uxp").shell;
const fs = require("uxp").storage.localFileSystem;

Expand All @@ -19,9 +18,16 @@ async function test(selection, documentRoot) {
}
});
const tempFolder = await fs.getTemporaryFolder();
const newFile = await tempFolder.createEntry("tempfile.txt", {overwrite: true});
newFile.write("Hello, world!");
const newFile = await tempFolder.createFile("tempfile.txt", {overwrite: true});
await newFile.write("Hello, world!");
await newFile.moveTo(tempFolder, {overwrite: true});

const anotherFile = await tempFolder.getEntry('tempfile.txt');
if (anotherFile.isFile) {
anotherFile.write("Good day");
} else if (anotherFile.isFolder) {
console.log("That's a folder. It shouldn't be a folder. What have you done?")
}
}

module.exports = {
Expand Down
8 changes: 4 additions & 4 deletions types/application.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,22 @@ declare class application {
* @param renditions List of renditions to generate
* @return Promise<Array<RenditionResult>, string> - Promise which is fulfilled with an array of RenditionResults (pointing to the same outputFiles that were originally passed in, or rejected with an error string if one or more renditions failed for any reason.
*/
public static createRenditions(renditions: RenditionSettings[]): Promise<RenditionResult[] | string>;
static createRenditions(renditions: RenditionSettings[]): Promise<RenditionResult[] | string>;

/**
* Adobe XD version number in the form "major.minor.patch.build"
*/
public static readonly version: string;
static readonly version: string;

/**
* Current language the application UI is using. This may not equal the user's OS locale setting: it is the closest locale supported by XD - use this when you want your plugin's UI to be consistent with XD's UI. Specifies language only, with no region info (e.g. "fr", not "fr_FR").
*/
public static readonly appLanguage: string;
static readonly 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").
*/
public static readonly systemLocale: string;
static readonly systemLocale: string;
}

export = application;
37 changes: 29 additions & 8 deletions types/assets.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ declare module assets {

/**
* Character style properties. See documentation for the Text node type for more details.
*
* When creating a new character style, all properties are mandatory except those with default values specified here. When deleting
an existing character style, always pass the exact object returned by [`characterStyles.get()`](#module_assets-characterStyles-get) (with all properties fully
specified) to avoid any ambiguity.
*/
type CharacterStyle = {
/**
Expand Down Expand Up @@ -92,6 +96,21 @@ declare module assets {
* whether underline is turned on
*/
underline: boolean;
/**
* (**Since**: XD 19)
* Default `false`; whether strikethrough is turned on
*/
strikethrough?: boolean;
/**
* (**Since**: XD 19)
* Default "none"; one of "none", "uppercase", "lowercase", or "titlecase"
*/
textTransform?: 'none' | 'uppercase' | 'lowercase' | 'titlecase';
/**
* (**Since**: XD 20)
* Default "none"; one of "none", "superscript", or "subscript"
*/
textScript?: 'none' | 'superscript' | 'subscript';
}

/**
Expand All @@ -108,7 +127,7 @@ declare module assets {
* allColors = assets.colors.get();
*
*/
public static get(): Array<ColorAsset | GradientAsset>;
static get(): Array<ColorAsset | GradientAsset>;

/**
* Add color/gradient assets to the collection.
Expand All @@ -117,7 +136,7 @@ declare module assets {
* @param colorAssets The color assets
* @returns {number} number of assets added (may be less than requested if duplicates already exist)
*/
public static add(colorAssets: Color | ColorAsset | LinearGradientFill | RadialGradientFill | GradientAsset | Array<Color | ColorAsset | LinearGradientFill | RadialGradientFill | GradientAsset>): number;
static add(colorAssets: Color | ColorAsset | LinearGradientFill | RadialGradientFill | GradientAsset | Array<Color | ColorAsset | LinearGradientFill | RadialGradientFill | GradientAsset>): number;

/**
* Delete color/gradient assets from the collection.
Expand All @@ -127,7 +146,7 @@ declare module assets {
* @param colorAssets The color assets
* @returns {number} number of assets deleted (may be less than requested if some didn't exist)
*/
public static delete(colorAssets: Color | ColorAsset | LinearGradientFill | RadialGradientFill | GradientAsset | Array<Color | ColorAsset | LinearGradientFill | RadialGradientFill | GradientAsset>): number;
static delete(colorAssets: Color | ColorAsset | LinearGradientFill | RadialGradientFill | GradientAsset | Array<Color | ColorAsset | LinearGradientFill | RadialGradientFill | GradientAsset>): number;
}

/**
Expand All @@ -144,7 +163,7 @@ declare module assets {
* allCharacterStyles = assets.characterStyles.get();
*
*/
public static get(): Array<CharacterStyleAsset>;
static get(): Array<CharacterStyleAsset>;

/**
* Add one or more character style assets to the collection.
Expand All @@ -154,18 +173,20 @@ declare module assets {
* @param charStyleAssets The character style assets
* @returns {number} number of assets added (may be less than requested if duplicates already exist)
*/
public static add(charStyleAssets: CharacterStyleAsset | Array<CharacterStyleAsset>): number;
static add(charStyleAssets: CharacterStyleAsset | Array<CharacterStyleAsset>): number;

/**
* Delete one or more character style assets from the collection.
*
* Assets with the same character style are removed even if their names differ. Assets that already don't exist in the collection are silently ignored. All character style properties must be fully specified (no properties are optional). Typically you will pass asset objects returned from `get()` directly to this function.
* Assets with the same character style are removed *even if their names differ*. Assets that already don't exist in the
* collection are silently ignored. All character style properties must be fully specified (no properties are optional).
* To avoid ambiguity, pass the exact asset objects returned from [`get()`](#module_assets-characterStyles-get) directlyto this function.
*
* @returns {number} number of assets deleted (may be less than requested if some didn't exist)
* @param charStyleAssets The character styles
*/
public static delete(charStyleAssets: CharacterStyleAsset | Array<CharacterStyleAsset>): number;
static delete(charStyleAssets: CharacterStyleAsset | Array<CharacterStyleAsset>): number;
}
}

export = assets;
export = assets;
2 changes: 1 addition & 1 deletion types/clipboard.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ declare class clipboard {
* Write plain text to the clipboard.
* @param text Will be automatically converted to string if a different type is passed
*/
public static copyText(text: string | any): void;
static copyText(text: string | any): void;
}

export = clipboard;
42 changes: 21 additions & 21 deletions types/commands.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ declare class commands {
/**
* Wraps the selected objects in a Group, leaving the Group selected afterward. Equivalent to Object > Group in the UI.
*/
public static group(): void;
static group(): void;

/**
* Ungroups any of the selected objects that are ungroupable containers (Groups, Symbols, Repeat Grids, etc.). Equivalent to Object > Ungroup.
* Ungroups any of the selected objects that are ungroupable containers (Group, SymbolInstance, RepeatGrid, etc.). Equivalent to _Object > Ungroup_.
*/
public static ungroup(): void;
static ungroup(): void;

/**
* Creates a masked Group from the selected objects, using the object that is highest in the z order as the mask shape. The mask shape must be a leaf node or Boolean Group. Equivalent to Object > Mask With Shape.
*/
public static createMaskGroup(): void;
static createMaskGroup(): void;

/**
* Converts each selected object to a Path with the exact same visual appearance. Only applies to leaf nodes and Boolean Groups. Equivalent to Object > Path > Convert to Path.
*/
public static convertToPath(): void;
static convertToPath(): void;

/**
* Duplicates all selected objects, leaving the duplicates selected afterward.
Expand All @@ -30,83 +30,83 @@ declare class commands {
*
* Edit > Duplicate
*/
public static duplicate(): void;
static duplicate(): void;

/**
* Brings selected objects to the front of the z order. Equivalent to Object > Arrange > Bring to Front.
*/
public static bringToFront(): void;
static bringToFront(): void;

/**
* Brings each selected object one step closer to the front of the z order. Equivalent to Object > Arrange > Bring Forward.
*/
public static bringForward(): void;
static bringForward(): void;

/**
* Sends selected objects to the back of the z order. Equivalent to Object > Arrange > Send to Back.
*/
public static sendToBack(): void;
static sendToBack(): void;

/**
* Sends each selected object one step closer to the back of the z order. Equivalent to Object > Arrange > Send Backward.
*/
public static sendBackward(): void;
static sendBackward(): void;

/**
* Aligns all selected objects flush left. Equivalent to Object > Align > Left.
*/
public static alignLeft(): void;
static alignLeft(): void;

/**
* Aligns all selected objects flush right. Equivalent to Object > Align > Right.
*/
public static alignRight(): void;
static alignRight(): void;

/**
* Aligns all selected objects along their horizontal centerlines. Equivalent to Object > Align > Center (Horizontally).
*/
public static alignHorizontalCenter(): void;
static alignHorizontalCenter(): void;

/**
* Aligns all selected objects flush top. Equivalent to Object > Align > Top.
*/
public static alignTop(): void;
static alignTop(): void;

/**
* Aligns all selected objects flush bottom. Equivalent to Object > Align > Bottom.
*/
public static alignBottom(): void;
static alignBottom(): void;

/**
* Aligns all selected objects along their vertical centerlines. Equivalent to Object > Align > Center (Vertically).
*/
public static alignVerticalCenter(): void;
static alignVerticalCenter(): void;

/**
* Distributes all selected objects evenly along the X axis. Equivalent to Object > Distribute > Horizontally.
*/
public static distributeHorizontal(): void;
static distributeHorizontal(): void;

/**
* Distributes all selected objects evenly along the Y axis. Equivalent to Object > Distribute > Vertically.
*/
public static distributeVertical(): void;
static distributeVertical(): void;

/**
* Shifts all selected objects and their content so they align crisply with the pixel grid. Equivalent to Object > Align to Pixel Grid.
*/
public static alignToPixelGrid(): void;
static alignToPixelGrid(): void;


// /**
//* Flips the object horizontally. Some objects such as Symbols cannot be flipped. Equivalent to Object > Flip > Horizontally.
//*/
//public static filpHorizontal(): void;
//static filpHorizontal(): void;
//
// /**
// * Flips the object vertically. Some objects such as Symbols cannot be flipped. Equivalent to Object > Flip > Vertically.
//*/
//public static flipVertical(): void;
//static flipVertical(): void;
}

export = commands;
18 changes: 9 additions & 9 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,35 @@ declare global {
* Represents the children of a scenenode. Typically accessed via the SceneNode.children property.
*/
class SceneNodeList {
public items: SceneNode[];
public readonly length: number;
items: SceneNode[];
readonly length: number;

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

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

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

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

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

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

/**
Expand Down Expand Up @@ -106,6 +106,6 @@ declare global {
* Opens the url in an the system browser.
* @param url The url which should be opened
*/
public openExternal(url: string);
openExternal(url: string);
}
}
Loading

0 comments on commit 2bc1dca

Please sign in to comment.