Viewport


Constructors

new Viewport()

new Viewport(client): Viewport

Parameters

ParameterType
clientEditorClient

Returns

Viewport


Methods

cancelDraggingNewBlock()

cancelDraggingNewBlock(): void

If startDraggingNewBlock has been called, and the drag-new-block interaction is still active,
cancel that interaction.

Returns

void


cancelDraggingNewImage()

cancelDraggingNewImage(): void

If startDraggingNewImage has been called, and the drag-new-image interaction is still active,
cancel that interaction.

Returns

void


dragPointerMove()

dragPointerMove(x, y): void

After calling startDraggingNewBlock, call this to simulate the user moving the mouse at the
given location within the top-level browser window.

This has no effect if the drag-new-block interaction is not active.

To convert a position in a Panel's iframe to a position in the top-level browser window,
add the IframeUI.framePosition.

Parameters

ParameterType
xnumber
ynumber

Returns

void


dragPointerUp()

dragPointerUp(x, y): void

After calling startDraggingNewBlock, call this to simulate the user releasing the mouse
button at the given location within the top-level browser window.

This has no effect if the drag-new-block interaction is not active.

To convert a position in a Panel's iframe to a position in the top-level browser window,
add the IframeUI.framePosition.

Parameters

ParameterType
xnumber
ynumber

Returns

void


findAvailableSpace()

findAvailableSpace(width, height): object

Find available space on the current page for adding new content.

Parameters

ParameterTypeDescription
widthnumber
heightnumber

Returns

object

a reference to the page and origin (upper-left point) of the space you can add new
content of the given size to.

page
page: PageProxy;
x
x: number;
y
y: number;

focusCameraOnItems()

focusCameraOnItems(items): void

Switch to the page containing these items, if necessary, and then animate the viewport
to zoom in and focus on these items.

Parameters

ParameterTypeDescription
itemsItemProxy[]The items the camera should zoom to

Returns

void


getCurrentPage()

getCurrentPage(): undefined | PageProxy

Returns

undefined | PageProxy

the page currently being viewed


getSelectedItems()

getSelectedItems(deep?): ItemProxy[]

Parameters

ParameterTypeDescription
deep?booleanIf true, and groups are selected, include the contents of those groups in the array

Returns

ItemProxy[]

An array of currently-selected items on the currently-visible page


getVisibleRect()

getVisibleRect(): Box

Returns

Box

the box for the current viewport location


hookSelection()

hookSelection(callback): string

Parameters

ParameterTypeDescription
callback(items) => voidCalled when the user changes their selection of items

Returns

string

A handle representing this hook, which can be passed to unhookSelection to remove this hook.


hookTextEdit()

hookTextEdit(callback, eager?): string

If callback returns false, text editing is prevented.
If callback returns true, text editing continues as normal.

If callback returns a TextEditCompletionCallback(/extension-sdk/#modules_ui_viewport_texteditcompletioncallback),
then text editing is allowed, but that completion callback is called.

when the user finishes editing that text. That completion callback may return true or false to allow or deny the edit, or
also may return a replacement string to use instead of the text the user actually typed. If replacement text is provided,
it will be styled as close to the original as possible, but styles that apply to only parts of the original text will be
discarded.

Parameters

ParameterTypeDescription
callback(item, textAreaKey, text?) => boolean | TextEditCompletionCallback | Promise<boolean | TextEditCompletionCallback>Called just before the user starts editing text.
eager?booleanWhether to trigger the callback eagerly during text edit

Returns

string

A handle representing this hook, which can be passed to unhookTextEdit to remove this hook.


setCurrentPage()

setCurrentPage(page): void

View the given page in the viewport

Parameters

ParameterTypeDescription
pagePageProxyThe page to view

Returns

void


setSelectedItems()

setSelectedItems(items): void

Unselect all currently-selected items, and select the subset of the given items that exist on
the currently-visible page.

Parameters

ParameterTypeDescription
itemsItemProxy[]

Returns

void


startDraggingNewBlock()

startDraggingNewBlock(definition): Promise<undefined | BlockProxy>

Start an interaction of the current user dragging a new block onto the current page, exactly
as if they started dragging that block out of the normal toolbox. At the time this function is
called, the user's primary mouse button should be down (e.g. in a mousedown event handler).

Parameters

ParameterTypeDescription
definitionBlockDefinitionDefinition of the block to create if and where the user drops it on-canvas

Returns

Promise<undefined | BlockProxy>

A promise resolving to a reference to the created block, if successfully dropped,
or undefined if the user cancels the drag interaction.


startDraggingNewImage()

startDraggingNewImage(definition): Promise<undefined | BlockProxy>

Start an interaction of the current user dragging a new image onto the current page, exactly
as if they started dragging that image out of the normal toolbox. At the time this function is
called, the user's primary mouse button should be down (e.g. in a mousedown event handler).

Parameters

ParameterTypeDescription
definitionImageDefinitionDefinition of the image to create if and where the user drops it on-canvas

Returns

Promise<undefined | BlockProxy>

A promise resolving to a reference to the created image, if successfully dropped,
or undefined if the user cancels the drag interaction.


unhookSelection()

unhookSelection(handle): void

Remove a hook set by hookSelection.

Parameters

ParameterTypeDescription
handlestringThe return value of hookSelection.

Returns

void


unhookTextEdit()

unhookTextEdit(handle): void

Remove a hook set by hookTextEdit.

Parameters

ParameterTypeDescription
handlestringThe return value of hookTextEdit.

Returns

void