@express-document-sdk

Class: Editor

Entry point for APIs that read or modify the document's content.

Extends

Extended by

Constructors

Constructor

new Editor(): Editor;

Returns

Editor

Inherited from

ProxyLiveObject.constructor

Accessors

context

Get Signature

get context(): Context;

User's current selection context

Returns

Context

Methods

queueAsyncEdit()

queueAsyncEdit(lambda): Promise<void>;

Enqueues a function to be run at a later time when edits to the user's document may be performed. You can always edit the document immediately when invoked in response to your add-on's UI code. However, if you delay to await an asynchronous operation such as loadBitmapImage, any edits following this pause must be scheduled using queueAsyncEdit(). This ensures the edit is properly tracked for saving and undo.

The delay before your edit function is executed is typically just a few milliseconds, so it will appear instantaneous to users. However, note that queueAsyncEdit() will return before your function has been run. If you need to trigger any code after the edit has been performed, either include this in the lambda you are enqueuing or await the Promise returned by queueAsyncEdit().

Generally, calling any setter or method is treated as an edit; but simple getters may be safely called at any time.

Example of typical usage:

// Assume insertImage() is called from your UI code, and given a Blob containing image data
async function insertImage(blob) {
    // This function was invoked from the UI iframe, so we can make any edits we want synchronously here.
    // Initially load the bitmap - an async operation
    const bitmapImage = await editor.loadBitmapImage(blob);

    // Execution doesn't arrive at this line until an async delay, due to the Promise 'await' above

    // Further edits need to be queued to run at a safe time
    editor.queueAsyncEdit(() => {
         // Create scenenode to display the image, and add it to the current artboard
         const mediaContainer = editor.createImageContainer(bitmapImage);
         editor.context.insertionParent.children.append(mediaContainer);
    });
}

Parameters

Parameter
Type
Description
lambda
() => void
a function which edits the document model.

Returns

Promise<void>

a Promise that resolves when the lambda has finished running, or rejects if the lambda throws an error.

createText()

Call Signature

createText(): StandaloneTextNode;
Returns

StandaloneTextNode

a text node with default styles. The text content is initially empty, so the text node will be invisible until its fullContent property's text is set. Creates auto-width text, so the node's width will automatically adjust to accommodate whatever text is set.

Deprecated

Call Signature

createText(textContent): StandaloneTextNode;
Parameters
Parameter
Type
Description
textContent
string
the initial string to show.
Returns

StandaloneTextNode

a text node with default styles. Creates auto-width text, so the node's width will automatically adjust to accommodate the given text content.

Note: the registration point of this text node is not guaranteed to be at the top-left of the bounding box of its insertion parent. Recommend using setPositionInParent over translation to set the position.

createEllipse()

createEllipse(): EllipseNode;

Returns

EllipseNode

an ellipse node with default x/y radii, a black fill, and no initial stroke. Transform values default to 0.

createRectangle()

createRectangle(): RectangleNode;

Returns

RectangleNode

a rectangle node with default width and height, a black fill, and no initial stroke. Transform values default to 0.

createLine()

createLine(): LineNode;

Returns

LineNode

a line node with default start point and end point and a default stroke. Transform values default to 0.

createGroup()

createGroup(): GroupNode;

Returns

GroupNode

a group node.

makeColorFill()

makeColorFill(color): ColorFill;

Convenience helper to create a complete ColorFill value given just its color.

Parameters

Parameter
Type
Description
color
Color
The color to use for the fill.

Returns

ColorFill

createImageContainer()

createImageContainer(bitmapData, options): MediaContainerNode;

Creates a bitmap image, represented as a multi-node MediaContainerNode structure. Always creates a "full-frame," uncropped image initially, but cropping can be changed after it is created by modifying the properties of the container's mediaRectangle and maskShape children.

Image creation involves some asynchronous steps. The image will be visible in this client almost instantly, but will render as a gray placeholder on other clients until it has been uploaded to DCX and then downloaded by those clients. This local client will act as having unsaved changes until the upload has finished.

Parameters

Parameter
Type
Description
bitmapData
BitmapImage
BitmapImage resource (e.g. returned from loadBitmapImage).
options
{ initialSize?: RectangleGeometry; }
Additional configuration: - initialSize - Size the image is displayed at. Must have the same aspect ratio as bitmapData. Defaults to the size the image would be created at by a UI drag-drop gesture (typically the image's full size, but scaled down if needed to stay below an application-defined size cap).
options.initialSize?
RectangleGeometry
-

Returns

MediaContainerNode

MediaContainerNode representing the top container node of the multi-node structure.

loadBitmapImage()

loadBitmapImage(bitmapData): Promise<BitmapImage>;

Creates a bitmap image resource in the document, which can be displayed in the scenegraph by passing it to createImageContainer to create a MediaContainerNode. The same BitmapImage can be used to create multiple MediaContainerNodes.

Because the resulting BitmapImage is returned asynchronously, to use it you must schedule an edit lambda to run at a safe later time in order to call createImageContainer. See queueAsyncEdit.

Further async steps to upload image resource data may continue in the background after this call's Promise resolves, but the resulting BitmapImage can be used right away (via the queue API noted above). The local client will act as having unsaved changes until all the upload steps have finished.

Parameters

Parameter
Type
Description
bitmapData
Blob
Encoded image data in PNG or JPEG format.

Returns

Promise<BitmapImage>

makeStroke()

makeStroke(options?): SolidColorStroke;

Convenience helper to create a complete SolidColorStroke value given just a subset of its fields. All other fields are populated with default values.

See SolidColorStroke for more details on the options fields. Defaults:

Parameters

Parameter
Type
options?
Partial<SolidColorStroke>

Returns

SolidColorStroke

a stroke configured with the given options.

createThreadedText()

createThreadedText(
   parentNode, 
   textContent, 
   geometry?): ThreadedTextNode;

Experimental

data-slots=text
data-variant=warning
IMPORTANT: This is currently experimental only and should not be used in any add-ons you will be distributing until it has been declared stable. To use it, you will first need to set the experimentalApis flag to true in the requirements section of the manifest.json.

Parameters

Parameter
Type
Description
parentNode
ContainerNode
The parent node that will contain the threaded text node. This must be a container node (e.g., ArtboardNode, GroupNode) that is attached to the document.
textContent
string
The initial text content for the threaded text node.
geometry?
TextFrameAreaGeometry
The geometry of the threaded text node.

Returns

ThreadedTextNode

A new ThreadedTextNode that is part of a threaded text flow.

Throws

if parentNode is not provided or is not a valid container node.

Throws

if textContent is empty or invalid.

createPath()

createPath(path): PathNode;

Parameters

Parameter
Type
Description
path
string
a string representing any SVG path element. Note that the path data will be normalized, and therefore the path getter may return a different SVG string from the path creation input. For example, "M 10 80 Q 52.5 10, 95 80 T 180 80" becomes "M 10 80 C 38.33 33.33 66.67 33.33 95 80...". Throws if the input is empty or is not legal SVG path syntax. Note: the visual top-left corner of a path may not be its local (0,0) origin point, so it's easiest to position a newly created path using Node.setPositionInParent rather than setting Node.translation directly.

Returns

PathNode

a path node with a default stroke and no initial fill.