Skip to content

Commit 2bc1dca

Browse files
authored
Merge pull request #47 from AdobeXD/xd-19-fixes
XD 20 APIs
2 parents 357af6b + 1160e75 commit 2bc1dca

10 files changed

+619
-398
lines changed

sample.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
const {Text, Ellipse, Color} = require("scenegraph");
1+
const {Text, Ellipse, Color, RootNode} = require("scenegraph");
22
const clipboard = require("clipboard");
3-
const application = require("application");
43
const shell = require("uxp").shell;
54
const fs = require("uxp").storage.localFileSystem;
65

@@ -19,9 +18,16 @@ async function test(selection, documentRoot) {
1918
}
2019
});
2120
const tempFolder = await fs.getTemporaryFolder();
22-
const newFile = await tempFolder.createEntry("tempfile.txt", {overwrite: true});
23-
newFile.write("Hello, world!");
21+
const newFile = await tempFolder.createFile("tempfile.txt", {overwrite: true});
22+
await newFile.write("Hello, world!");
2423
await newFile.moveTo(tempFolder, {overwrite: true});
24+
25+
const anotherFile = await tempFolder.getEntry('tempfile.txt');
26+
if (anotherFile.isFile) {
27+
anotherFile.write("Good day");
28+
} else if (anotherFile.isFolder) {
29+
console.log("That's a folder. It shouldn't be a folder. What have you done?")
30+
}
2531
}
2632

2733
module.exports = {

types/application.d.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,22 @@ declare class application {
6161
* @param renditions List of renditions to generate
6262
* @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.
6363
*/
64-
public static createRenditions(renditions: RenditionSettings[]): Promise<RenditionResult[] | string>;
64+
static createRenditions(renditions: RenditionSettings[]): Promise<RenditionResult[] | string>;
6565

6666
/**
6767
* Adobe XD version number in the form "major.minor.patch.build"
6868
*/
69-
public static readonly version: string;
69+
static readonly version: string;
7070

7171
/**
7272
* 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").
7373
*/
74-
public static readonly appLanguage: string;
74+
static readonly appLanguage: string;
7575

7676
/**
7777
* 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").
7878
*/
79-
public static readonly systemLocale: string;
79+
static readonly systemLocale: string;
8080
}
8181

8282
export = application;

types/assets.d.ts

+29-8
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ declare module assets {
6262

6363
/**
6464
* Character style properties. See documentation for the Text node type for more details.
65+
*
66+
* When creating a new character style, all properties are mandatory except those with default values specified here. When deleting
67+
an existing character style, always pass the exact object returned by [`characterStyles.get()`](#module_assets-characterStyles-get) (with all properties fully
68+
specified) to avoid any ambiguity.
6569
*/
6670
type CharacterStyle = {
6771
/**
@@ -92,6 +96,21 @@ declare module assets {
9296
* whether underline is turned on
9397
*/
9498
underline: boolean;
99+
/**
100+
* (**Since**: XD 19)
101+
* Default `false`; whether strikethrough is turned on
102+
*/
103+
strikethrough?: boolean;
104+
/**
105+
* (**Since**: XD 19)
106+
* Default "none"; one of "none", "uppercase", "lowercase", or "titlecase"
107+
*/
108+
textTransform?: 'none' | 'uppercase' | 'lowercase' | 'titlecase';
109+
/**
110+
* (**Since**: XD 20)
111+
* Default "none"; one of "none", "superscript", or "subscript"
112+
*/
113+
textScript?: 'none' | 'superscript' | 'subscript';
95114
}
96115

97116
/**
@@ -108,7 +127,7 @@ declare module assets {
108127
* allColors = assets.colors.get();
109128
*
110129
*/
111-
public static get(): Array<ColorAsset | GradientAsset>;
130+
static get(): Array<ColorAsset | GradientAsset>;
112131

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

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

133152
/**
@@ -144,7 +163,7 @@ declare module assets {
144163
* allCharacterStyles = assets.characterStyles.get();
145164
*
146165
*/
147-
public static get(): Array<CharacterStyleAsset>;
166+
static get(): Array<CharacterStyleAsset>;
148167

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

159178
/**
160179
* Delete one or more character style assets from the collection.
161180
*
162-
* 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.
181+
* Assets with the same character style are removed *even if their names differ*. Assets that already don't exist in the
182+
* collection are silently ignored. All character style properties must be fully specified (no properties are optional).
183+
* To avoid ambiguity, pass the exact asset objects returned from [`get()`](#module_assets-characterStyles-get) directlyto this function.
163184
*
164185
* @returns {number} number of assets deleted (may be less than requested if some didn't exist)
165186
* @param charStyleAssets The character styles
166187
*/
167-
public static delete(charStyleAssets: CharacterStyleAsset | Array<CharacterStyleAsset>): number;
188+
static delete(charStyleAssets: CharacterStyleAsset | Array<CharacterStyleAsset>): number;
168189
}
169190
}
170191

171-
export = assets;
192+
export = assets;

types/clipboard.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ declare class clipboard {
66
* Write plain text to the clipboard.
77
* @param text Will be automatically converted to string if a different type is passed
88
*/
9-
public static copyText(text: string | any): void;
9+
static copyText(text: string | any): void;
1010
}
1111

1212
export = clipboard;

types/commands.d.ts

+21-21
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@ declare class commands {
55
/**
66
* Wraps the selected objects in a Group, leaving the Group selected afterward. Equivalent to Object > Group in the UI.
77
*/
8-
public static group(): void;
8+
static group(): void;
99

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

1515
/**
1616
* 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.
1717
*/
18-
public static createMaskGroup(): void;
18+
static createMaskGroup(): void;
1919

2020
/**
2121
* 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.
2222
*/
23-
public static convertToPath(): void;
23+
static convertToPath(): void;
2424

2525
/**
2626
* Duplicates all selected objects, leaving the duplicates selected afterward.
@@ -30,83 +30,83 @@ declare class commands {
3030
*
3131
* Edit > Duplicate
3232
*/
33-
public static duplicate(): void;
33+
static duplicate(): void;
3434

3535
/**
3636
* Brings selected objects to the front of the z order. Equivalent to Object > Arrange > Bring to Front.
3737
*/
38-
public static bringToFront(): void;
38+
static bringToFront(): void;
3939

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

4545
/**
4646
* Sends selected objects to the back of the z order. Equivalent to Object > Arrange > Send to Back.
4747
*/
48-
public static sendToBack(): void;
48+
static sendToBack(): void;
4949

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

5555
/**
5656
* Aligns all selected objects flush left. Equivalent to Object > Align > Left.
5757
*/
58-
public static alignLeft(): void;
58+
static alignLeft(): void;
5959

6060
/**
6161
* Aligns all selected objects flush right. Equivalent to Object > Align > Right.
6262
*/
63-
public static alignRight(): void;
63+
static alignRight(): void;
6464

6565
/**
6666
* Aligns all selected objects along their horizontal centerlines. Equivalent to Object > Align > Center (Horizontally).
6767
*/
68-
public static alignHorizontalCenter(): void;
68+
static alignHorizontalCenter(): void;
6969

7070
/**
7171
* Aligns all selected objects flush top. Equivalent to Object > Align > Top.
7272
*/
73-
public static alignTop(): void;
73+
static alignTop(): void;
7474

7575
/**
7676
* Aligns all selected objects flush bottom. Equivalent to Object > Align > Bottom.
7777
*/
78-
public static alignBottom(): void;
78+
static alignBottom(): void;
7979

8080
/**
8181
* Aligns all selected objects along their vertical centerlines. Equivalent to Object > Align > Center (Vertically).
8282
*/
83-
public static alignVerticalCenter(): void;
83+
static alignVerticalCenter(): void;
8484

8585
/**
8686
* Distributes all selected objects evenly along the X axis. Equivalent to Object > Distribute > Horizontally.
8787
*/
88-
public static distributeHorizontal(): void;
88+
static distributeHorizontal(): void;
8989

9090
/**
9191
* Distributes all selected objects evenly along the Y axis. Equivalent to Object > Distribute > Vertically.
9292
*/
93-
public static distributeVertical(): void;
93+
static distributeVertical(): void;
9494

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

100100

101101
// /**
102102
//* Flips the object horizontally. Some objects such as Symbols cannot be flipped. Equivalent to Object > Flip > Horizontally.
103103
//*/
104-
//public static filpHorizontal(): void;
104+
//static filpHorizontal(): void;
105105
//
106106
// /**
107107
// * Flips the object vertically. Some objects such as Symbols cannot be flipped. Equivalent to Object > Flip > Vertically.
108108
//*/
109-
//public static flipVertical(): void;
109+
//static flipVertical(): void;
110110
}
111111

112112
export = commands;

types/index.d.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,35 @@ declare global {
1515
* Represents the children of a scenenode. Typically accessed via the SceneNode.children property.
1616
*/
1717
class SceneNodeList {
18-
public items: SceneNode[];
19-
public readonly length: number;
18+
items: SceneNode[];
19+
readonly length: number;
2020

21-
public forEach(
21+
forEach(
2222
callback: (sceneNode: SceneNode, index: number) => void,
2323
thisArg?: object
2424
): void;
2525

26-
public forEachRight(
26+
forEachRight(
2727
callback: (sceneNode: SceneNode, index: number) => void,
2828
thisArg?: object
2929
): void;
3030

31-
public filter(
31+
filter(
3232
callback: (sceneNode: SceneNode, index: number) => boolean,
3333
thisArg?: object
3434
): Array<SceneNode>;
3535

36-
public map(
36+
map(
3737
callback: (sceneNode: SceneNode, index: number) => any,
3838
thisArg?: object
3939
): Array<any>;
4040

41-
public some(
41+
some(
4242
callback: (sceneNode: SceneNode, index: number) => boolean,
4343
thisArg?: object
4444
): boolean;
4545

46-
public at(index: number): SceneNode | null;
46+
at(index: number): SceneNode | null;
4747
}
4848

4949
/**
@@ -106,6 +106,6 @@ declare global {
106106
* Opens the url in an the system browser.
107107
* @param url The url which should be opened
108108
*/
109-
public openExternal(url: string);
109+
openExternal(url: string);
110110
}
111111
}

0 commit comments

Comments
 (0)