[]previous and next page

Editor API

Every public method and property on the editor, grouped by what you're trying to do.

Everything here is on the Editor you get from createEditor(), app.editor, useEditor() or onReady. Methods that change the document are undoable unless noted.

Events and lifecycle#

Member Description
on(event, fn) Subscribe to an event. Returns an unsubscribe function
emit(event, payload) Emit an event (for plugins that add their own)
subscribe(fn) Run fn after any change. Returns an unsubscribe function
use(plugin) Install a code plugin. Returns a remove function
dispose() Tear down the editor and its plugins

State#

Member Description
state The instance state (camera per page, selection, tool, styles, theme…)
updateState(partial) Change instance state (not undoable; it isn't part of the document)
isReadonly, setReadonly(value) View mode
setTheme('light' | 'dark') Switch theme
announce(message) Speak a message to screen readers

History#

Member Description
batch(fn, { label, history, mergeKey }) Run changes as one undo step. history: 'ignore' skips history
undo(), redo() Undo or redo
canUndo, canRedo Whether there's anything to undo or redo
history.begin(label), history.end(), history.bail() Open, close, or cancel a step that spans a gesture
mergeRemoteChanges(fn) Apply changes as remote (used by sync)

Shapes#

Member Description
createShape(partial, { select }) Create a shape. Returns its id
createShapes(partials) Create several in one step
updateShape(partial), updateShapes(partials) Change shapes (props merge into the existing props)
deleteShapes(ids), deleteSelected() Delete
getShape(id) A shape record, or undefined
getCurrentPageShapes(), getPageShapes(pageId) All shapes on a page
getSortedChildren(parentId) Children in z-order
getDescendants(id) Everything inside a frame or group
renameShape(id, name) Set the name shown in the layers panel
reparentShapes(ids, parentId) Move shapes into a frame or back to the page

Geometry and coordinates#

Member Description
getShapeGeometry(shape) The shape's outline, in its local space
getShapePageBounds(shapeOrId) Axis-aligned bounds in page space
getShapeVisualPageBounds(shapeOrId) Bounds including stroke and decorations
getShapesPageBounds(shapes) Bounds of several shapes
getShapePageTransform(shape) The shape's page transform matrix
pageToLocal(shape, point), localToPage(shape, point) Convert between page and shape space
screenToPage(point), pageToScreen(point) Convert between screen and page space

Selection#

Member Description
select(...ids), setSelectedIds(ids) Replace the selection
addToSelection(ids), removeFromSelection(ids) Change it
selectAll(), selectNone(), selectAdjacent(1 | -1) Select everything, nothing, or the next shape
getSelectedIds(), getSelectedShapes(), getOnlySelectedShape() Read it
isSelected(id) Whether one shape is selected
getSelectionPageBounds(), getSelectionRotatedBounds() Its bounds
focusGroup(groupId) Enter a group (select inside it)

Structure#

Member Description
alignShapes(ids, 'left' | 'center-horizontal' | 'right' | 'top' | 'center-vertical' | 'bottom') Align
distributeShapes(ids, 'horizontal' | 'vertical') Equal spacing
stackShapes(ids, axis, gap) Line up with a fixed gap
flipShapes(ids, 'horizontal' | 'vertical') Mirror
rotateShapesBy(ids, radians), nudgeShapes(ids, dx, dy) Rotate or move
bringToFront, bringForward, sendBackward, sendToBack Z-order (default: the selection)
moveShapeToIndex(id, parentId, position) Exact z-order placement
groupShapes(ids), ungroupShapes(ids) Groups
toggleLock(ids), toggleHidden(ids) Lock or hide
duplicateShapes(ids) Duplicate in place

Bindings (arrows)#

Member Description
bindArrow(arrowId, 'start' | 'end', targetId, anchor, isPrecise) Attach an arrow end to a shape
unbindArrow(arrowId, terminal) Detach it
getArrowBindings(arrowId) { start?, end? }
getBindingsFromShape(id), getBindingsToShape(id) All bindings in either direction

Styles#

Member Description
setStyle(key, value) Apply to the selection and to the next shape
getSharedStyles() Each style's value across the selection, with mixed
setOpacity(value), getSharedOpacity() Opacity
copyStyles(), pasteStyles() Copy styles between shapes
getStylesForType(type) The styles a new shape of this type would get

Text editing#

Member Description
startEditing(id), stopEditing() Enter or leave text editing
updateShapeText(id, text) Change a shape's text (merges keystrokes into one undo step)
canEditShape(shape) Whether a shape has editable text
measureText(text, style, maxWidth) Lay out text the way shapes do

Tools and input#

Member Description
setTool(id), getCurrentTool() Switch or read the tool
isIn(path) Whether a tool state is active, like 'select.resizing'
toggleToolLock() Keep the tool after creating a shape
registerTool(Tool), unregisterTool(id) Add or remove tools
inputs Live pointer and modifier state
dispatch(event) Feed a normalized input event (hosts do this for you)
cancel(), interrupt() Stop the current gesture
actions The action registry

Camera#

Member Description
camera, zoom The camera and its zoom
setCamera(camera, { animate, duration }) Move the camera
pan(dx, dy), zoomAt(screenPoint, z) Relative moves
zoomIn(), zoomOut(), resetZoom() Step through the zoom stops
zoomToFit(), zoomToSelection(), zoomToBounds(box) Frame content
centerOnPoint(point) Center the view
getViewportPageBounds() What's visible, in page space
setViewport(w, h) Tell the editor its size (hosts do this for you)

Pages and document#

Member Description
getPages(), getCurrentPage(), currentPageId Read pages
createPage(name, { switchTo }), setCurrentPage(id) Add or switch
renamePage, deletePage, duplicatePage, movePage Manage pages
getDocument(), updateDocument(partial) The document record (name, grid size)
clearPage() Delete everything on the current page

Content and clipboard#

Member Description
getContent(ids) Shapes with their bindings and assets, ready to move elsewhere
putContent(content, options) Insert content (ids are remapped)
copy(ids), cut(ids), paste(content, point) Clipboard operations
getSnapshot(), loadSnapshot(snapshot) The whole document

Assets#

Member Description
createAsset(asset), getAsset(id) Asset records (images, files, specs)

Shape types#

Member Description
registerShapeUtil(Util) Add a shape type at runtime
getShapeUtil(shapeOrType), hasShapeUtil(type), getShapeTypes() Look them up
invalidateGeometry() Re-measure everything (after fonts load)
setTextMeasurer(measurer) Swap the text measurer