| JSX | UXP |
|---|---|
| ECMAScript 3 | ECMAScript 6 | V8 |
| JSX | UXP |
|---|---|
| var, const | var, let, const |
Collection objects returned by InDesign no longer support the subscript operator [] to access an element with a specific index. In UXP you have to use item() instead.
| JSX | UXP |
|---|---|
Story.paragraphs[0] |
Story.paragraphs.item(0) |
| JSX | UXP |
|---|---|
app.activeDocument.constructor.name // Document |
app.activeDocument.constructorName // "Document" Prior to InDesign 18.4
const app = require("indesign").app; // Onwards InDesign 18.4
app.activeDocument.constructor.name // "Document"
app.activeDocument.constructorName // "Document" |
| JSX | UXP |
|---|---|
app.activeDocument === app.documents[0] // true |
const app = require("indesign").app; // Onwards InDesign 18.4
app.activeDocument.equals(app.documents.item(0)); // true |
The instanceof keyword isn't supported for InDesign DOM objects.
| JSX | UXP |
|---|---|
app.activeDocument instanceof Document // true |
// Instead, we have to use the Constructor Name property. |
The global object document (which stood for an InDesign document) is unsupported in UXP.
Prior to InDesign 18.4: app.activeScript returns the path of the current script as a string and a error in UXP Developer Tool (UDT).
Onwards InDesign 18.4: see below.
| JSX | UXP |
|---|---|
app.activeScript // File |
const app = require("indesign").app; // Onwards InDesign 18.4
const script = await app.activeScript
script.nativePath; // "/"
script.isFolder; // true
script.scriptPath.url.href // "file:///" |
InDesign 18.4 onward: Arguments/parameters can be passed to UXP scripts. Read more in the recipe Passing Arguments
| JSX | UXP |
|---|---|
app.scriptArgs.setValue("argOne", "one);
app.scriptArgs.getValue("argOne"); // "one" |
const script = require("uxp").script;
script.args.push("one");
script.args.push("two");
script.args // ["one", "two"] |
| JSX | UXP |
|---|---|
|
console.log('Your log message.');
console.warn('Your log message.');
... |
Standard open file dialog box
| JSX | UXP |
|---|---|
var file = File.openDialog("Select file"); |
const ufs = require('uxp').storage.localFileSystem;
const file = await ufs.getFileForOpening(); |
- InDesign DOM is now available only via module:
const app = require("indesign").app;
console.log(app.activeDocument.name);
- Indesign enumerators no longer available globally, e.g.:
const indesign = require("indesign");
const app = indesign.app;
app.scriptPreferences.userInteractionLevel = indesign.UserInteractionLevels.NEVER_INTERACT;
constructor.name for InDesign DOM objects now works again:
require("indesign").app;
app.activeDocument.constructor.name // "Document"
doScriptworks:
const indesign = require("indesign");
const app = indesign.app;
app.doScript("console.log(\"Hello UXP world!\")", indesign.ScriptLanguage.UXPSCRIPT);
-
The prototype chain for InDesign DOM objects has changed. So you can no longer check with hasOwnProperty:
var app = require("indesign").app;
app.hasOwnProperty("activeDocument") // false
Object.hasOwn(app, "activeDocument") // false
Instead e.g.:
("activeDocument" in app) // true
- The plugin folder is no longer available for UXP scripts.
const uxpStorage = require('uxp').storage;
const localFS = uxpStorage.localFileSystem;
const pluginFolder = await localFS.getPluginFolder(); // InDesign 18.4 onward: Error
-
Arguments/parameters can now be passed to UXP scripts. Read more in the recipe Passing Arguments
-
InDesign now has the functionality to set result of a UXP script.
script.setResult("Hello World!");
- The
pathmodule is provided:
path.parse("~/Desktop/image.jpg") // {root: "", dir: "~/Desktop", base: "image.jpg", ext: ".jpg", name: "image"}
- Sectrum Web Components (BETA)
In addition to the built-in Spectrum UXP widgets, Spectrum Web Components are now supported. They are currently still in the beta phase.
Manifest
...
"featureFlags: {
"enableSWCSupport": true
}
...
Example: SP-Button
- Install1
yarn
yarn add @spectrum-web-components/theme
yarn add @swc-uxp-wrappers/utils
yarn add @swc-uxp-wrappers/button
npm
npm install @spectrum-web-components/theme
npm install @swc-uxp-wrappers/utils
npm install @swc-uxp-wrappers/button
- Import
import "@spectrum-web-components/theme/sp-theme.js";
import "@spectrum-web-components/theme/src/themes.js";
import "@swc-uxp-wrappers/button/sp-button.js";
- Usage
<sp-theme theme="spectrum" color="light" scale="medium" dir="ltr">
<sp-button variant="primary">Click me</sp-button>
</sp-theme>
Footnotes
-
Via yarn and npm, not always the same versions of the components are available. I think that since yarn is recommended by Adobe, the components here are more up-to-date. ↩