EditorClient


Constructors

new EditorClient()

new EditorClient(): EditorClient

Returns

EditorClient


Properties

callbacks

protected readonly callbacks: Map<string, (value) => void | JsonSerializable | Promise<any>>;

Methods

actionExists()

actionExists(name): boolean

Parameters

ParameterTypeDescription
namestringname of the action to check

Returns

boolean

true if a callback has been registered for this action; false otherwise


alert()

alert(
   text, 
   title?, 
   buttonText?): AlertResult

Display an alert modal to the user

Parameters

ParameterTypeDescription
textstringBody text to display in the alert modal
title?stringTitle of the alert modal; defaults to the extension title specified in manifest.json
buttonText?stringText for the OK button; defaults to "OK" (or a translation)

Returns

AlertResult

a Promise that resolves true if the user clicks OK, false if they otherwise dismiss the modal


asyncOAuthXhr()

asyncOAuthXhr(providerName, request)

asyncOAuthXhr(providerName, request): Promise<TextXHRResponse>

Make an asyncronous OAuth network request. The request is enqueued to eventually execute. The request may be attempted multiple times with
an overall timeout of 120 seconds.

Parameters
ParameterTypeDescription
providerNamestringName of the OAuth provider
requestOAuthXHRRequest & objectSettings for the request
Returns

Promise<TextXHRResponse>

A promise that will either resolve or reject with an XHRResponse. If the HTTP status
code is not 2xx, the promise will reject.

asyncOAuthXhr(providerName, request)

asyncOAuthXhr(providerName, request): Promise<BinaryXHRResponse>
Parameters
ParameterType
providerNamestring
requestOAuthXHRRequest & object
Returns

Promise<BinaryXHRResponse>

asyncOAuthXhr(providerName, request)

asyncOAuthXhr(providerName, request): Promise<XHRResponse>
Parameters
ParameterType
providerNamestring
requestOAuthXHRRequest
Returns

Promise<XHRResponse>


awaitDataImport()

awaitDataImport(
   dataConnectorName, 
   syncDataSourceId, 
   syncCollectionId, 
   primaryKeys, 
timeout): Promise<CollectionProxy>

Parameters

ParameterTypeDefault value
dataConnectorNamestringundefined
syncDataSourceIdundefined | stringundefined
syncCollectionIdstringundefined
primaryKeysstring[]undefined
timeoutnumber30000

Returns

Promise<CollectionProxy>


canEditPackageSettings()

canEditPackageSettings(): Promise<boolean>

Returns

Promise<boolean>

True if the current user is allowed to edit package settings on this installation
of this extension (if any settings exist), or false otherwise.


confirm()

confirm(
   text, 
   title?, 
   okText?, 
   cancelText?): ConfirmResult

Display a confirm modal to the user

Parameters

ParameterTypeDescription
textstringBody text to display in the alert modal
title?stringTitle of the alert modal; defaults to the extension title specified in manifest.json
okText?stringText for the OK button; defaults to "OK" (or a translation)
cancelText?stringText for the Cancel button; defaults to "Cancel" (or a translation)

Returns

ConfirmResult

a Promise that resolves true if the user clicks OK, false if they click Cancel or otherwise dismiss the modal


createUserImage()

createUserImage(mediaType, data): Promise<string>

Upload an image and return a URL that can be used for displaying that image on the canvas. Note: the URL is
public - anyone with the URL can access the image.

Parameters

ParameterTypeDescription
mediaTypestringThe media type, e.g. 'image/png'
datastring | Uint8ArrayThe binary image contents, or a base64-encoded string

Returns

Promise<string>

A promise that resolves with the URL of the created image.


deleteAction()

deleteAction(name): void

Remove the callback for a given action. If the action is later invoked, nothing will happen.

Parameters

ParameterTypeDescription
namestringname of the action to unregister

Returns

void


download()

download(
   filename, 
   data, 
   mime, 
   base64): void

Initiate a browser file download of custom content

Parameters

ParameterTypeDescription
filenamestringFilename of the downloaded file
datastringThe content to put into the file, either in plain text or as base64-encoded binary data
mimestringThe MIME type to tell the browser it is downloading
base64booleanIf true, base64 decode the data before downloading it

Returns

void


duplicatePages()

duplicatePages(pageNums): Promise<void>

Duplicates one or more pages of the current document as new pages.

Parameters

ParameterTypeDescription
pageNumsnumber[]An array of zero-indexed page indices to duplicate from the current document

Returns

Promise<void>

a promise that resolves to void when the pages have been duplicated or the
the duplication failed


getBlockProxy()

getBlockProxy(id): BlockProxy

Create and return a proxy for accessing a block with the given ID. If the block is of a type that has a specific
proxy implementation (e.g. an ERD block) then a specialized subclass of BlockProxy may be returned.

Parameters

ParameterTypeDescription
idstringID of the block to create a proxy for

Returns

BlockProxy

the given block


getCustomShapeDefinition()

getCustomShapeDefinition(library, shape): Promise<undefined | BlockDefinition>

Load the requested shape library's content, and if it was found, return a block definition ready to be
created.

Example usage:

const client = new EditorClient();
const viewport = new Viewport(client);

const page = viewport.getCurrentPage();
if (page) {
    const def = await page.getCustomShapeDefinition('libraryName', 'shapeName');
    if (def) {
        //Customize the shape about to be created
        def.boundingBox.x = 500;
        def.boundingBox.y = 500;

        //Create the shape itself
        const block = page.addBlock(def);

        //Set any data fields on the shape as needed
        block.shapeData.set('Value', 50);
    }
}

Parameters

ParameterTypeDescription
librarystringName of the shape library in this extension to search for
shapestringName of the shape within that library to search for

Returns

Promise<undefined | BlockDefinition>


getElementProxy()

getElementProxy(id): ElementProxy

Parameters

ParameterTypeDescription
idstringID of the element to create a proxy for

Returns

ElementProxy

the given element


getItemProxy()

getItemProxy(id): BlockProxy | LineProxy | GroupProxy

Parameters

ParameterTypeDescription
idstringID of the item to create a proxy for

Returns

BlockProxy | LineProxy | GroupProxy

the given item


getLineProxy()

getLineProxy(id): LineProxy

Parameters

ParameterTypeDescription
idstringID of the line to create a proxy for

Returns

LineProxy

the given line


getOAuthClientId()

getOAuthClientId(providerName): Promise<undefined | string>

Fetch the OAuth Client Id if there is one

Parameters

ParameterTypeDescription
providerNamestringName of the OAuth provider

Returns

Promise<undefined | string>

A oauth client id or undefined if it doesn't exist


getOAuthToken()

getOAuthToken(providerName): Promise<undefined | string>

Returns an OAuth token for the given provider, prompting the user to grant access if necessary

Parameters

ParameterTypeDescription
providerNamestringName of the OAuth provider

Returns

Promise<undefined | string>

An oauth token, or undefined if a valid token cannot be obtained


getPackageSettings()

getPackageSettings(): Promise<Map<string, JsonSerializable>>

If the extension package containing this editor extension has configurable settings,
fetch the current values of those settings for this installation of this extension.

Only settings that have been set by the installing user will have a value in the map,
other settings will be missing.

Returns

Promise<Map<string, JsonSerializable>>

A promise that resolves to a map of setting names to current setting values


getPageProxy()

getPageProxy(id): PageProxy

Parameters

ParameterTypeDescription
idstringID of the page to create a proxy for

Returns

PageProxy

the given page


getProduct()

getProduct(): LucidProduct

Get which Lucid product this editor extension has been loaded in.

Returns

LucidProduct


importPage()

importPage(documentId, pageNums): Promise<void>

Import one or pages of the specified document or template into the current document
as new pages.
NOTE: The indices of the pages to import will change if the pages are rearranged
on the source document or template.

Parameters

ParameterTypeDescription
documentIdstringThe ID of the document or template to import
pageNumsnumber[]An array of zero-indexed page indices to import from the document or template

Returns

Promise<void>

a promise that resolves to void when the pages have been imported or the
the import failed


killExtension()

killExtension(): void

Unload this extension immediately, removing any custom menu items etc., until the user refreshes the browser tab.

Returns

void


loadBlockClasses()

loadBlockClasses(classNames): Promise<undefined>

Because code for block classes are loaded incrementally, you MUST call
loadBlockClasses with the given block class name (and wait for it to
resolve) before attempting to create a block. If you don't, an error
will be thrown.

Parameters

ParameterTypeDescription
classNamesstring[]the block classes to load

Returns

Promise<undefined>

a promise that resolves when the block classes can be used to create new blocks on the document


oauthXhr()

oauthXhr(providerName, request)

oauthXhr(providerName, request): Promise<TextXHRResponse>

Make an OAuth network request. Make the request immediately and only once with a 10 second timeout.

Parameters
ParameterTypeDescription
providerNamestringName of the OAuth provider
requestOAuthXHRRequest & objectSettings for the request
Returns

Promise<TextXHRResponse>

A promise that will either resolve or reject with an XHRResponse. If the HTTP status
code is not 2xx, the promise will reject.

oauthXhr(providerName, request)

oauthXhr(providerName, request): Promise<BinaryXHRResponse>
Parameters
ParameterType
providerNamestring
requestOAuthXHRRequest & object
Returns

Promise<BinaryXHRResponse>

oauthXhr(providerName, request)

oauthXhr(providerName, request): Promise<XHRResponse>
Parameters
ParameterType
providerNamestring
requestOAuthXHRRequest
Returns

Promise<XHRResponse>


performDataAction()

performDataAction(options): Promise<DataActionResponse>

Parameters

ParameterType
optionsDataActionOptions

Returns

Promise<DataActionResponse>


permanentTokenXhr()

permanentTokenXhr(providerName, request)

permanentTokenXhr(providerName, request): Promise<BinaryXHRResponse>
Parameters
ParameterType
providerNamestring
requestXHRRequest & object
Returns

Promise<BinaryXHRResponse>

permanentTokenXhr(providerName, request)

permanentTokenXhr(providerName, request): Promise<XHRResponse>
Parameters
ParameterType
providerNamestring
requestXHRRequest
Returns

Promise<XHRResponse>


processAndClearBootstrapData()

processAndClearBootstrapData(callback, markExtensionAsRequired?): Promise<void>

Parameters

ParameterTypeDescription
callback(data) => void | Promise<void>A callback that processes the bootstrap data, if any, stored on the document and associated with this editor extension. If this callback is async (returns a promise), then the bootstrap data is not cleared off of the document until that promise resolves.
markExtensionAsRequired?booleanIf bootstrap data is available for this editor extension, this will mark the document as requiring the extension. Once marked, if the extension is not installed the user will be notified about the extension being required on document load. The minimum extension version required by the document is the version provided in the request body when creating the document.

Returns

Promise<void>

a promise that resolves immediately if there is no available bootstrap data, or else after
the callback successfully completes. This promise will reject/throw if the callback throws or
returns a promise that rejects, or if there is another editor session processing the same bootstrap
data at the same time.


prompt()

prompt(text, title?): PromptResult

Display a prompt modal to the user

Parameters

ParameterTypeDescription
textstringBody text to display in the alert modal
title?stringTitle of the alert modal; defaults to the extension title specified in manifest.json

Returns

PromptResult

a Promise that resolves to a string if a user enters one, or undefined if they cancel


registerAction()

registerAction(name, callback): void

Register a named action. These actions can be triggered from custom UI, for example as the action of a
custom menu item.

Some actions may return a value that is used by the core application, e.g. a visibleAction for a menu
item. However, if you return a Promise from your callback, that value will be discarded and your
action will return undefined instead. The ability to provide a callback that returns a Promise is only
a convenience so that you can register actions with async callbacks for easy async/await.

Throws an error if the same action name is registered multiple times.

Parameters

ParameterTypeDescription
namestringname of the action
callback(value) => void | JsonSerializable | Promise<any>function to execute when this action is invoked

Returns

void


registerFileUploadAction()

registerFileUploadAction(name, callback): void

Register a named action that receives file upload data. These callbacks can be used in
Menu.addMenuItem as the file action.

Parameters

ParameterTypeDescription
namestringThe name of the action
callback(files) => voidFunction to execute when this action is invoked

Returns

void


registerUnfurlHandler()

registerUnfurlHandler(domain, callbacks): void

Registers a handler for link unfurling.

Parameters

ParameterTypeDescription
domainstringThe domain
callbacksUnfurlCallbacksThe callbacks to call when a link matching the domain is pasted.

Returns

void


reloadExtension()

reloadExtension(): void

Unload this extension, and then re-execute it.

Returns

void


sendCommand()

sendCommand<C>(name, params): CommandArgs[C]["result"]

Execute an API command. This is the low-level API that most of this SDK wraps. It is not expected that you should
ever need to use this directly.

Type parameters

Type parameter
C extends CommandName

Parameters

ParameterTypeDescription
nameCname of the API command to execute
paramsUnionToIntersection<CommandArgs[C]["query"]>data to pass to the API command

Returns

CommandArgs[C]["result"]

the output of the given API command


setPackageSettings()

setPackageSettings(settings): Promise<undefined>

If the extension package containing this editor extension has configurable settings, set the
value of those settings for this installation of this extension. A subset of setting values
can be provided to update those values while leaving others unchanged.

If the user does not have permission to change settings on this installation of this
extension, or if no settings exist, an error is thrown.

Parameters

ParameterType
settingsRecord<string, string> | Map<string, string>

Returns

Promise<undefined>


showPackageSettingsModal()

showPackageSettingsModal(): Promise<void>

If the extension package containing this editor extension has configurable settings,
show a standard modal allowing the user to view or change those settings.

If the user does not have permission to change settings on this installation of this
extension, or if no settings exist, an error is thrown.

Returns

Promise<void>

A promise that resolves when the user closes the settings modal.


triggerAuthFlow()

triggerAuthFlow(providerName): TriggerAuthFlowResult

Parameters

ParameterType
providerNamestring

Returns

TriggerAuthFlowResult


tryGetItemProxy()

tryGetItemProxy(id): undefined | BlockProxy | LineProxy | GroupProxy

Parameters

ParameterTypeDescription
idstringID of the item to create a proxy for

Returns

undefined | BlockProxy | LineProxy | GroupProxy

the given item, or undefined if the item does not exist or an error occurs


withIntraDocumentMutex()

withIntraDocumentMutex(name, callback): Promise<boolean>

Executes the given callback within a mutex scoped to the current document, extension, and the given name.
If another editor session currently has the given mutex name locked within the same extension package ID
on this same document, this function's returned promise will resolve to false. Otherwise, the mutex will
be locked for the duration of the callback and the returned promise will resolve to true.

Parameters

ParameterTypeDescription
namestringName of the intra-document mutex to attempt to lock
callback() => void | Promise<void>Code to execute while the mutex is locked, if it is successfully locked

Returns

Promise<boolean>

A promise resolving to a boolean indicating whether the mutex was successfully locked


withSilentActions()

withSilentActions(callback): void

Parameters

ParameterTypeDescription
callback() => voidCallback that will be executed with the user's local undo/redo history suppressed. This is useful when you want to make changes to a document that will not be erased if the user uses undo or redo, for example adding shape data onto shapes as a result of a background process that collects data from a remote API.

Returns

void


xhr()

xhr(request)

xhr(request): Promise<TextXHRResponse>

Make a network request

Parameters
ParameterTypeDescription
requestXHRRequest & objectSettings for the network request
Returns

Promise<TextXHRResponse>

A promise that will either resolve or reject with an XHRResponse. If the HTTP status
code is not 2xx, the promise will reject.

xhr(request)

xhr(request): Promise<BinaryXHRResponse>
Parameters
ParameterType
requestXHRRequest & object
Returns

Promise<BinaryXHRResponse>

xhr(request)

xhr(request): Promise<XHRResponse>
Parameters
ParameterType
requestXHRRequest
Returns

Promise<XHRResponse>