Skip to content

Latest commit

 

History

History
409 lines (314 loc) · 7.09 KB

File metadata and controls

409 lines (314 loc) · 7.09 KB

What's new in ...

UXP

JavaScript Version | Engine

JSX UXP
ECMAScript 3 ECMAScript 6 | V8

Variables

JSX UXP
var, const var, let, const

InDesign Collection

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)

InDesign DOM Object Constructor Name

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"

InDesign DOM Object Comparison Operator

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

InDesign DOM Object instanceof

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.

Global object document

The global object document (which stood for an InDesign document) is unsupported in UXP.

ActiveScript

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:///"

Passing Script Arguments

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"]

Logging

JSX UXP
$.writeln('Your log message.');
console.log('Your log message.');
console.warn('Your log message.');
...

File System

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 App Version 18.4.0 / UXP Version 6.5.0

  • 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"
  • doScript works:
const indesign = require("indesign");
const app = indesign.app;
app.doScript("console.log(\"Hello UXP world!\")", indesign.ScriptLanguage.UXPSCRIPT);
  • And application events and menus are now available as well.

  • 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 path module 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

  1. 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

  1. 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";

  1. Usage
<sp-theme theme="spectrum" color="light" scale="medium" dir="ltr">
	<sp-button variant="primary">Click me</sp-button>
</sp-theme>

Footnotes

  1. 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.