Editor
Table of contents
- Properties
- Methods
- addOpenMenu
- alignShapes
- animateShape
- animateShapes
- animateToShape
- animateToUser
- bail
- bailToMark
- batch
- bringForward
- bringToFront
- cancel
- cancelDoubleClick
- centerOnPoint
- clearOpenMenus
- complete
- createAssets
- createPage
- createShape
- createShapes
- deleteAssets
- deleteOpenMenu
- deletePage
- deleteShape
- deleteShape
- deleteShapes
- deleteShapes
- deselect
- dispose
- distributeShapes
- duplicatePage
- duplicateShapes
- findCommonAncestor
- findShapeAncestor
- flipShapes
- getAncestorPageId
- getArrowInfo
- getArrowsBoundTo
- getAsset
- getAssetForExternalContent
- getAssets
- getCamera
- getCameraState
- getCanRedo
- getCanUndo
- getContentFromCurrentPage
- getCroppingShapeId
- getCurrentPage
- getCurrentPageBounds
- getCurrentPageId
- getCurrentPageRenderingShapesSorted
- getCurrentPageShapeIds
- getCurrentPageShapes
- getCurrentPageShapesSorted
- getCurrentPageState
- getCurrentTool
- getCurrentToolId
- getDocumentSettings
- getDroppingOverShape
- getEditingShape
- getEditingShapeId
- getErasingShapeIds
- getErasingShapes
- getFocusedGroup
- getFocusedGroupId
- getHighestIndexForParent
- getHintingShape
- getHintingShapeIds
- getHoveredShape
- getHoveredShapeId
- getInitialMetaForShape
- getInstanceState
- getIsMenuOpen
- getOnlySelectedShape
- getOpenMenus
- getOutermostSelectableShape
- getPage
- getPages
- getPageShapeIds
- getPageStates
- getPath
- getPointInParentSpace
- getPointInShapeSpace
- getRenderingBounds
- getRenderingBoundsExpanded
- getRenderingShapes
- getSelectedShapeAtPoint
- getSelectedShapeIds
- getSelectedShapes
- getSelectionPageBounds
- getSelectionRotatedPageBounds
- getSelectionRotation
- getShape
- getShapeAncestors
- getShapeAndDescendantIds
- getShapeAtPoint
- getShapeClipPath
- getShapeGeometry
- getShapeHandles
- getShapeLocalTransform
- getShapeMask
- getShapeMaskedPageBounds
- getShapeOutlineSegments
- getShapePageBounds
- getShapePageTransform
- getShapeParent
- getShapeParentTransform
- getShapesAtPoint
- getShapeStyleIfExists
- getShapeUtil
- getShapeUtil
- getShapeUtil
- getSharedOpacity
- getSharedStyles
- getSortedChildIdsForParent
- getStateDescendant
- getSvg
- getViewportPageBounds
- getViewportPageCenter
- getViewportScreenBounds
- getViewportScreenCenter
- getZoomLevel
- groupShapes
- hasAncestor
- interrupt
- isAncestorSelected
- isIn
- isInAny
- isPointInShape
- isShapeInPage
- isShapeOfType
- isShapeOfType
- isShapeOrAncestorLocked
- isShapeOrAncestorLocked
- mark
- moveShapesToPage
- nudgeShapes
- packShapes
- pageToScreen
- pan
- panZoomIntoView
- popFocusedGroupId
- putContentOntoCurrentPage
- putExternalContent
- redo
- registerExternalAssetHandler
- registerExternalContentHandler
- renamePage
- reparentShapes
- resetZoom
- resizeShape
- rotateShapesBy
- screenToPage
- select
- selectAll
- selectNone
- sendBackward
- sendToBack
- setCamera
- setCroppingShape
- setCurrentPage
- setCurrentTool
- setEditingShape
- setErasingShapes
- setFocusedGroup
- setHintingShapes
- setHoveredShape
- setOpacityForNextShapes
- setOpacityForSelectedShapes
- setSelectedShapes
- setStyleForNextShapes
- setStyleForSelectedShapes
- slideCamera
- stackShapes
- startFollowingUser
- stopCameraAnimation
- stopFollowingUser
- stretchShapes
- toggleLock
- undo
- ungroupShapes
- ungroupShapes
- updateAssets
- updateCurrentPageState
- updateDocumentSettings
- updateInstanceState
- updatePage
- updateShape
- updateShapes
- updateViewportScreenBounds
- visitDescendants
- zoomIn
- zoomOut
- zoomToBounds
- zoomToContent
- zoomToFit
- zoomToSelection
Public class
class Editor extends EventEmitter<TLEventMap> {}
packages/editor/src/lib/editor/Editor.ts
Constructor
Public constructor
Constructs a new instance of the Editor
class
Name | Description |
---|---|
|
|
Properties
dispatch
Public property
Dispatch an event to the editor.
Example
editor.dispatch(myPointerEvent)
dispatch: (info: TLEventInfo) => this
Name | Description |
---|---|
| The event info. |
disposables
Public readonly property
A set of functions to call when the app is disposed.
readonly disposables: Set<() => void>
environment
Public readonly property
A manager for the editor's environment.
readonly environment: EnvironmentManager
getContainer
Public property
The current HTML element containing the editor.
Example
const container = editor.getContainer()
getContainer: () => HTMLElement
history
Public readonly property
A manager for the app's history.
readonly history: HistoryManager<this>
inputs
Public property
The app's current input state.
inputs: {
originPagePoint: Vec
originScreenPoint: Vec
previousPagePoint: Vec
previousScreenPoint: Vec
currentPagePoint: Vec
currentScreenPoint: Vec
keys: Set<string>
buttons: Set<number>
isPen: boolean
shiftKey: boolean
ctrlKey: boolean
altKey: boolean
isDragging: boolean
isPointing: boolean
isPinching: boolean
isEditing: boolean
isPanning: boolean
pointerVelocity: Vec
}
renderingBoundsMargin
Public property
The distance to expand the viewport when measuring culling. A larger distance will mean that shapes near to the viewport (but still outside of it) will not be culled.
renderingBoundsMargin: number
root
Public readonly property
The root state of the statechart.
readonly root: RootState
scribbles
Public readonly property
A manager for the editor's scribbles.
readonly scribbles: ScribbleManager
setCursor
Public property
Set the cursor.
setCursor: (cursor: Partial<TLCursor>) => this
Name | Description |
---|---|
| The cursor type. |
| The cursor rotation. |
shapeUtils
Public property
A map of shape utility classes (TLShapeUtils) by shape type.
shapeUtils: {
readonly [K in string]?: ShapeUtil<TLUnknownShape>
}
sideEffects
Public readonly property
A manager for side effects and correct state enforcement.
readonly sideEffects: SideEffectManager<this>
snaps
Public readonly property
A manager for the app's snapping feature.
readonly snaps: SnapManager
store
Public readonly property
The editor's store
readonly store: TLStore
styleProps
Public property
styleProps: {
[key: string]: Map<StyleProp<unknown>, string>
}
textMeasure
Public readonly property
A helper for measuring text.
readonly textMeasure: TextManager
user
Public readonly property
A manager for the user and their preferences.
readonly user: UserPreferencesManager
Methods
addOpenMenu()
Public method
Add an open menu.
Example
editor.addOpenMenu('menu-id')
addOpenMenu(id: string): this
Name | Description |
---|---|
|
|
this
alignShapes()
Public method
Align shape positions.
Example
editor.alignShapes([box1, box2], 'left')
editor.alignShapes(editor.getSelectedShapeIds(), 'left')
alignShapes(
shapes: TLShape[] | TLShapeId[],
operation:
| 'bottom'
| 'center-horizontal'
| 'center-vertical'
| 'left'
| 'right'
| 'top'
): this
Name | Description |
---|---|
|
The shapes (or shape ids) to align. |
|
The align operation to apply. |
this
animateShape()
Public method
Animate a shape.
Example
editor.animateShape({ id: 'box1', type: 'box', x: 100, y: 100 })
editor.animateShape(
{ id: 'box1', type: 'box', x: 100, y: 100 },
{ duration: 100, ease: (t) => t * t }
)
animateShape(
partial: null | TLShapePartial | undefined,
animationOptions?: TLAnimationOptions
): this
Name | Description |
---|---|
|
The shape partial to update. |
|
|
this
TLShapePartial, TLAnimationOptions
animateShapes()
Public method
Animate shapes.
Example
editor.animateShapes([{ id: 'box1', type: 'box', x: 100, y: 100 }])
editor.animateShapes([{ id: 'box1', type: 'box', x: 100, y: 100 }], {
duration: 100,
ease: (t) => t * t,
})
animateShapes(
partials: (null | TLShapePartial | undefined)[],
animationOptions?: Partial<{
duration: number
easing: (t: number) => number
}>
): this
Name | Description |
---|---|
|
The shape partials to update. |
|
|
this
animateToShape()
Public method
Animate the camera to a shape.
animateToShape(shapeId: TLShapeId, opts?: TLAnimationOptions): this
Name | Description |
---|---|
|
|
|
|
this
animateToUser()
Public method
Animate the camera to a user's cursor position. This also briefly show the user's cursor if it's not currently visible.
animateToUser(userId: string): this
Name | Description |
---|---|
|
The id of the user to aniamte to. |
this
bail()
Public method
Clear all marks in the undo stack back to the next mark.
Example
editor.bail()
bail(): this
bailToMark()
Public method
Clear all marks in the undo stack back to the mark with the provided mark id.
Example
editor.bailToMark('dragging')
bailToMark(id: string): this
Name | Description |
---|---|
|
|
this
batch()
Public method
Run a function in a batch, which will be undone/redone as a single action.
Example
editor.batch(() => {
editor.selectAll()
editor.deleteShapes(editor.getSelectedShapeIds())
editor.createShapes(myShapes)
editor.selectNone()
})
editor.undo() // will undo all of the above
batch(fn: () => void): this
Name | Description |
---|---|
|
|
this
bringForward()
Public method
Bring shapes forward in the page's object list.
Example
editor.bringForward(['id1', 'id2'])
editor.bringForward(box1, box2)
bringForward(shapes: TLShape[] | TLShapeId[]): this
Name | Description |
---|---|
|
The shapes (or shape ids) to move. |
this
bringToFront()
Public method
Bring shapes to the front of the page's object list.
Example
editor.bringToFront(['id1', 'id2'])
editor.bringToFront([box1, box2])
bringToFront(shapes: TLShape[] | TLShapeId[]): this
Name | Description |
---|---|
|
The shapes (or shape ids) to move. |
this
cancel()
Public method
Dispatch a cancel event.
Example
editor.cancel()
cancel(): this
cancelDoubleClick()
Public method
Prevent a double click event from firing the next time the user clicks
cancelDoubleClick(): void
centerOnPoint()
Public method
Center the camera on a point (in the current page space).
Example
editor.centerOnPoint({ x: 100, y: 100 })
editor.centerOnPoint({ x: 100, y: 100 }, { duration: 200 })
centerOnPoint(point: VecLike, animation?: TLAnimationOptions): this
Name | Description |
---|---|
|
The point in the current page space to center on. |
|
The options for an animation. |
this
clearOpenMenus()
Public method
Clear all open menus.
Example
editor.clearOpenMenus()
clearOpenMenus(): this
complete()
Public method
Dispatch a complete event.
Example
editor.complete()
complete(): this
createAssets()
Public method
Create one or more assets.
Example
editor.createAssets([...myAssets])
createAssets(assets: TLAsset[]): this
Name | Description |
---|---|
|
The assets to create. |
this
createPage()
Public method
Create a page.
Example
editor.createPage(myPage)
editor.createPage({ name: 'Page 2' })
createPage(page: Partial<TLPage>): this
Name | Description |
---|---|
|
The page (or page partial) to create. |
this
createShape()
Public method
Create a single shape.
Example
editor.createShape(myShape)
editor.createShape({ id: 'box1', type: 'text', props: { text: 'ok' } })
createShape<T extends TLUnknownShape>(
shape: OptionalKeys<TLShapePartial<T>, 'id'>
): this
Name | Description |
---|---|
|
The shape (or shape partial) to create. |
this
TLUnknownShape, TLShapePartial
createShapes()
Public method
Create shapes.
Example
editor.createShapes([myShape])
editor.createShapes([{ id: 'box1', type: 'text', props: { text: 'ok' } }])
createShapes<T extends TLUnknownShape>(
shapes: OptionalKeys<TLShapePartial<T>, 'id'>[]
): this
Name | Description |
---|---|
|
The shapes (or shape partials) to create. |
this
TLUnknownShape, TLShapePartial
deleteAssets()
Public method
Delete one or more assets.
Example
editor.deleteAssets(['asset1', 'asset2'])
deleteAssets(assets: TLAsset[] | TLAssetId[]): this
Name | Description |
---|---|
|
|
this
deleteOpenMenu()
Public method
Delete an open menu.
Example
editor.deleteOpenMenu('menu-id')
deleteOpenMenu(id: string): this
Name | Description |
---|---|
|
|
this
deletePage()
Public method
Delete a page.
Example
editor.deletePage('page1')
deletePage(page: TLPage | TLPageId): this
Name | Description |
---|---|
|
|
this
deleteShape()
Public method
Delete a shape.
Example
editor.deleteShapes(['box1', 'box2'])
deleteShape(id: TLShapeId): this
Name | Description |
---|---|
|
The id of the shape to delete. |
this
deleteShape()
Public method
deleteShape(shape: TLShape): this
Name | Description |
---|---|
|
|
this
deleteShapes()
Public method
Delete shapes.
Example
editor.deleteShapes(['box1', 'box2'])
deleteShapes(ids: TLShapeId[]): this
Name | Description |
---|---|
|
The ids of the shapes to delete. |
this
deleteShapes()
Public method
deleteShapes(shapes: TLShape[]): this
Name | Description |
---|---|
|
|
this
deselect()
Public method
Remove a shape from the existing set of selected shapes.
Example
editor.deselect(shape.id)
deselect(...shapes: TLShape[] | TLShapeId[]): this
Name | Description |
---|---|
|
|
this
dispose()
Public method
Dispose the editor.
dispose(): void
distributeShapes()
Public method
Distribute shape positions.
Example
editor.distributeShapes([box1, box2], 'horizontal')
editor.distributeShapes(editor.getSelectedShapeIds(), 'horizontal')
distributeShapes(
shapes: TLShape[] | TLShapeId[],
operation: 'horizontal' | 'vertical'
): this
Name | Description |
---|---|
|
The shapes (or shape ids) to distribute. |
|
Whether to distribute shapes horizontally or vertically. |
this
duplicatePage()
Public method
Duplicate a page.
duplicatePage(page: TLPage | TLPageId, createId?: TLPageId): this
Name | Description |
---|---|
|
|
|
The id of the new page. Defaults to a new id. |
this
duplicateShapes()
Public method
Duplicate shapes.
Example
editor.duplicateShapes(['box1', 'box2'], { x: 8, y: 8 })
editor.duplicateShapes(editor.getSelectedShapes(), { x: 8, y: 8 })
duplicateShapes(shapes: TLShape[] | TLShapeId[], offset?: VecLike): this
Name | Description |
---|---|
|
The shapes (or shape ids) to duplicate. |
|
The offset (in pixels) to apply to the duplicated shapes. |
this
findCommonAncestor()
Public method
Get the common ancestor of two or more shapes that matches a predicate.
findCommonAncestor(
shapes: TLShape[] | TLShapeId[],
predicate?: (shape: TLShape) => boolean
): TLShapeId | undefined
Name | Description |
---|---|
|
The shapes (or shape ids) to check. |
|
The predicate to match. |
TLShapeId | undefined
findShapeAncestor()
Public method
Find the first ancestor matching the given predicate
Example
const ancestor = editor.findShapeAncestor(myShape)
const ancestor = editor.findShapeAncestor(myShape.id)
const ancestor = editor.findShapeAncestor(
myShape.id,
(shape) => shape.type === 'frame'
)
findShapeAncestor(
shape: TLShape | TLShapeId,
predicate: (parent: TLShape) => boolean
): TLShape | undefined
Name | Description |
---|---|
|
The shape to check the ancestors for. |
|
|
TLShape | undefined
flipShapes()
Public method
Flip shape positions.
Example
editor.flipShapes([box1, box2], 'horizontal', 32)
editor.flipShapes(editor.getSelectedShapeIds(), 'horizontal', 32)
flipShapes(
shapes: TLShape[] | TLShapeId[],
operation: 'horizontal' | 'vertical'
): this
Name | Description |
---|---|
|
The ids of the shapes to flip. |
|
Whether to flip horizontally or vertically. |
this
getAncestorPageId()
Public method
Get the id of the containing page for a given shape.
getAncestorPageId(shape?: TLShape | TLShapeId): TLPageId | undefined
Name | Description |
---|---|
|
The shape to get the page id for. |
TLPageId | undefined
The id of the page that contains the shape, or undefined if the shape is undefined.
getArrowInfo()
Public method
Get cached info about an arrow.
Example
const arrowInfo = editor.getArrowInfo(myArrow)
getArrowInfo(shape: TLArrowShape | TLShapeId): TLArrowInfo | undefined
Name | Description |
---|---|
|
The shape (or shape id) of the arrow to get the info for. |
TLArrowInfo | undefined
TLArrowShape, TLShapeId, TLArrowInfo
getArrowsBoundTo()
Public method
Get all arrows bound to a shape.
getArrowsBoundTo(shapeId: TLShapeId): {
arrowId: TLShapeId
handleId: 'end' | 'start'
}[]
Name | Description |
---|---|
|
The id of the shape. |
{
arrowId: TLShapeId
handleId: 'end' | 'start'
}[]
getAsset()
Public method
Get an asset by its id.
Example
editor.getAsset('asset1')
getAsset(asset: TLAsset | TLAssetId): TLAsset | undefined
Name | Description |
---|---|
|
The asset (or asset id) to get. |
TLAsset | undefined
getAssetForExternalContent()
Public method
Get an asset for an external asset content type.
Example
const asset = await editor.getAssetForExternalContent({
type: 'file',
file: myFile,
})
const asset = await editor.getAssetForExternalContent({
type: 'url',
url: myUrl,
})
getAssetForExternalContent(
info: TLExternalAssetContent
): Promise<TLAsset | undefined>
Name | Description |
---|---|
|
Info about the external content. |
Promise<TLAsset | undefined>
The asset.
TLExternalAssetContent, TLAsset
getAssets()
Public method
Get all assets in the editor.
getAssets(): (
| import('@tldraw/tlschema').TLBookmarkAsset
| TLImageAsset
| TLVideoAsset
)[]
TLBookmarkAsset, TLImageAsset, TLVideoAsset
getCamera()
Public method
The current camera.
getCamera(): import('@tldraw/tlschema').TLCamera
getCameraState()
Public method
Whether the camera is moving or idle.
getCameraState(): 'idle' | 'moving'
getCanRedo()
Public method
Whether the app can redo.
getCanRedo(): boolean
getCanUndo()
Public method
Whether the app can undo.
getCanUndo(): boolean
getContentFromCurrentPage()
Public method
Get content that can be exported for the given shape ids.
getContentFromCurrentPage(
shapes: TLShape[] | TLShapeId[]
): TLContent | undefined
Name | Description |
---|---|
|
The shapes (or shape ids) to get content for. |
TLContent | undefined
The exported content.
getCroppingShapeId()
Public method
The current cropping shape's id.
getCroppingShapeId(): null | TLShapeId
getCurrentPage()
Public method
The current page.
getCurrentPage(): TLPage
getCurrentPageBounds()
Public method
The bounds of the current page (the common bounds of all of the shapes on the page).
getCurrentPageBounds(): Box | undefined
getCurrentPageId()
Public method
The current page id.
getCurrentPageId(): TLPageId
getCurrentPageRenderingShapesSorted()
Public method
An array containing all of the rendering shapes in the current page, sorted in z-index order (accounting for nested shapes): e.g. A, B, BA, BB, C.
getCurrentPageRenderingShapesSorted(): TLShape[]
getCurrentPageShapeIds()
Public method
An array of all of the shapes on the current page.
getCurrentPageShapeIds(): Set<TLShapeId>
getCurrentPageShapes()
Public method
An array containing all of the shapes in the current page.
getCurrentPageShapes(): TLShape[]
getCurrentPageShapesSorted()
Public method
An array containing all of the shapes in the current page, sorted in z-index order (accounting for nested shapes): e.g. A, B, BA, BB, C.
getCurrentPageShapesSorted(): TLShape[]
getCurrentPageState()
Public method
The current page state.
getCurrentPageState(): TLInstancePageState
getCurrentTool()
Public method
The current selected tool.
getCurrentTool(): StateNode
getCurrentToolId()
Public method
The id of the current selected tool.
getCurrentToolId(): string
getDocumentSettings()
Public method
The global document settings that apply to all users.
getDocumentSettings(): TLDocument
getDroppingOverShape()
Public method
Get the shape that some shapes should be dropped on at a given point.
getDroppingOverShape(
point: VecLike,
droppingShapes?: TLShape[]
): TLUnknownShape | undefined
Name | Description |
---|---|
|
The point to find the parent for. |
|
The shapes that are being dropped. |
TLUnknownShape | undefined
The shape to drop on.
VecLike, TLShape, TLUnknownShape
getEditingShape()
Public method
The current editing shape.
getEditingShape(): TLShape | undefined
getEditingShapeId()
Public method
The current editing shape's id.
getEditingShapeId(): null | TLShapeId
getErasingShapeIds()
Public method
The editor's current erasing ids.
getErasingShapeIds(): TLShapeId[]
getErasingShapes()
Public method
The editor's current erasing shapes.
getErasingShapes(): NonNullable<TLShape | undefined>[]
getFocusedGroup()
Public method
The current focused group.
getFocusedGroup(): TLShape | undefined
getFocusedGroupId()
Public method
The current focused group id.
getFocusedGroupId(): TLPageId | TLShapeId
getHighestIndexForParent()
Public method
Get the index above the highest child of a given parent.
getHighestIndexForParent(parent: TLPage | TLParentId | TLShape): string
Name | Description |
---|---|
|
|
string
The index.
getHintingShape()
Public method
The editor's current hinting shapes.
getHintingShape(): NonNullable<TLShape | undefined>[]
getHintingShapeIds()
Public method
The editor's current hinting shape ids.
getHintingShapeIds(): TLShapeId[]
getHoveredShape()
Public method
The current hovered shape.
getHoveredShape(): TLShape | undefined
getHoveredShapeId()
Public method
The current hovered shape id.
getHoveredShapeId(): null | TLShapeId
getInitialMetaForShape()
Public method
Get the initial meta value for a shape.
Example
editor.getInitialMetaForShape = (shape) => {
if (shape.type === 'note') {
return { createdBy: myCurrentUser.id }
}
}
getInitialMetaForShape(_shape: TLShape): JsonObject
Name | Description |
---|---|
|
|
JsonObject
getInstanceState()
Public method
The current instance's state.
getInstanceState(): TLInstance
getIsMenuOpen()
Public method
Get whether any menus are open.
Example
editor.isMenuOpen()
getIsMenuOpen(): boolean
getOnlySelectedShape()
Public method
The app's only selected shape.
getOnlySelectedShape(): null | TLShape
getOpenMenus()
Public method
A set of strings representing any open menus. When menus are open, certain interactions will behave differently; for example, when a draw tool is selected and a menu is open, a pointer-down will not create a dot (because the user is probably trying to close the menu) however a pointer-down event followed by a drag will begin drawing a line (because the user is BOTH trying to close the menu AND start drawing a line).
getOpenMenus(): string[]
getOutermostSelectableShape()
Public method
Get the shape that should be selected when you click on a given shape, assuming there is nothing already selected. It will not return anything higher than or including the current focus layer.
getOutermostSelectableShape(
shape: TLShape | TLShapeId,
filter?: (shape: TLShape) => boolean
): TLShape
Name | Description |
---|---|
|
The shape to get the outermost selectable shape for. |
|
A function to filter the selectable shapes. |
TLShape
The outermost selectable shape.
getPage()
Public method
Get a page.
Example
editor.getPage(myPage.id)
editor.getPage(myPage)
getPage(page: TLPage | TLPageId): TLPage | undefined
Name | Description |
---|---|
|
The page (or page id) to get. |
TLPage | undefined
getPages()
Public method
Info about the project's current pages.
getPages(): TLPage[]
getPageShapeIds()
Public method
Get the ids of shapes on a page.
Example
const idsOnPage1 = editor.getCurrentPageShapeIds('page1')
const idsOnPage2 = editor.getCurrentPageShapeIds(myPage2)
getPageShapeIds(page: TLPage | TLPageId): Set<TLShapeId>
Name | Description |
---|---|
|
The page (or page id) to get. |
Set<TLShapeId>
getPageStates()
Public method
Page states.
getPageStates(): TLInstancePageState[]
getPath()
Public method
The editor's current path of active states.
Example
editor.getPath() // "select.idle"
getPath(): string
getPointInParentSpace()
Public method
Convert a delta in the current page space to a point in the local space of a shape's parent.
Example
editor.getPointInParentSpace(myShape.id, { x: 100, y: 100 })
getPointInParentSpace(shape: TLShape | TLShapeId, point: VecLike): Vec
Name | Description |
---|---|
|
The shape to get the point in the local space of. |
|
The page point to get in the local space of the shape. |
Vec
TLShape, TLShapeId, VecLike, Vec
getPointInShapeSpace()
Public method
Convert a point in the current page space to a point in the local space of a shape. For example, if a shape's page point were { x: 100, y: 100 }
, a page point at { x: 110, y: 110 }
would be at { x: 10, y: 10 }
in the shape's local space.
Example
editor.getPointInShapeSpace(myShape, { x: 100, y: 100 })
getPointInShapeSpace(shape: TLShape | TLShapeId, point: VecLike): Vec
Name | Description |
---|---|
|
The shape to get the point in the local space of. |
|
The page point to get in the local space of the shape. |
Vec
TLShape, TLShapeId, VecLike, Vec
getRenderingBounds()
Public method
The current rendering bounds in the current page space, used for checking which shapes are "on screen".
getRenderingBounds(): Box
getRenderingBoundsExpanded()
Public method
The current rendering bounds in the current page space, expanded slightly. Used for determining which shapes to render and which to "cull".
getRenderingBoundsExpanded(): Box
getRenderingShapes()
Public method
Get the shapes that should be displayed in the current viewport.
getRenderingShapes(): {
id: TLShapeId
shape: TLShape
util: ShapeUtil<TLUnknownShape>
index: number
backgroundIndex: number
opacity: number
isCulled: boolean
maskedPageBounds: Box | undefined
}[]
TLShapeId, TLShape, ShapeUtil, TLUnknownShape, Box
getSelectedShapeAtPoint()
Public method
Get the top-most selected shape at the given point, ignoring groups.
getSelectedShapeAtPoint(point: VecLike): TLShape | undefined
Name | Description |
---|---|
|
The point to check. |
TLShape | undefined
The top-most selected shape at the given point, or undefined if there is no shape at the point.
getSelectedShapeIds()
Public method
The current selected ids.
getSelectedShapeIds(): TLShapeId[]
getSelectedShapes()
Public method
An array containing all of the currently selected shapes.
getSelectedShapes(): TLShape[]
getSelectionPageBounds()
Public method
The current page bounds of all the selected shapes. If the selection is rotated, then these bounds are the axis-aligned box that the rotated bounds would fit inside of.
getSelectionPageBounds(): Box | null
getSelectionRotatedPageBounds()
Public method
The bounds of the selection bounding box in the current page space.
getSelectionRotatedPageBounds(): Box | undefined
getSelectionRotation()
Public method
The rotation of the selection bounding box in the current page space.
getSelectionRotation(): number
getShape()
Public method
Get a shape by its id.
Example
editor.getShape('box1')
getShape<T extends TLShape = TLShape>(
shape: TLParentId | TLShape
): T | undefined
Name | Description |
---|---|
|
|
T | undefined
getShapeAncestors()
Public method
Get the ancestors of a shape.
Example
const ancestors = editor.getShapeAncestors(myShape)
const ancestors = editor.getShapeAncestors(myShapeId)
getShapeAncestors(shape: TLShape | TLShapeId, acc?: TLShape[]): TLShape[]
Name | Description |
---|---|
|
The shape (or shape id) to get the ancestors for. |
|
|
TLShape[]
getShapeAndDescendantIds()
Public method
Get the shape ids of all descendants of the given shapes (including the shapes themselves).
getShapeAndDescendantIds(ids: TLShapeId[]): Set<TLShapeId>
Name | Description |
---|---|
|
The ids of the shapes to get descendants of. |
Set<TLShapeId>
The decscendant ids.
getShapeAtPoint()
Public method
Get the shape at the current point.
getShapeAtPoint(
point: VecLike,
opts?: {
renderingOnly?: boolean | undefined
margin?: number | undefined
hitInside?: boolean | undefined
hitLabels?: boolean | undefined
hitFrameInside?: boolean | undefined
filter?: ((shape: TLShape) => boolean) | undefined
}
): TLShape | undefined
Name | Description |
---|---|
|
The point to check. |
|
Options for the check: |
TLShape | undefined
The shape at the given point, or undefined if there is no shape at the point.
getShapeClipPath()
Public method
Get the clip path for a shape.
Example
const clipPath = editor.getShapeClipPath(shape)
const clipPath = editor.getShapeClipPath(shape.id)
getShapeClipPath(shape: TLShape | TLShapeId): string | undefined
Name | Description |
---|---|
|
The shape (or shape id) to get the clip path for. |
string | undefined
The clip path or undefined.
getShapeGeometry()
Public method
Get the geometry of a shape.
Example
editor.getShapeGeometry(myShape)
editor.getShapeGeometry(myShapeId)
getShapeGeometry<T extends Geometry2d>(shape: TLShape | TLShapeId): T
Name | Description |
---|---|
|
The shape (or shape id) to get the geometry for. |
T
Geometry2d, TLShape, TLShapeId
getShapeHandles()
Public method
Get the handles (if any) for a shape.
Example
editor.getShapeHandles(myShape)
editor.getShapeHandles(myShapeId)
getShapeHandles<T extends TLShape>(shape: T | T['id']): TLHandle[] | undefined
Name | Description |
---|---|
|
The shape (or shape id) to get the handles for. |
TLHandle[] | undefined
getShapeLocalTransform()
Public method
Get the local transform for a shape as a matrix model. This transform reflects both its translation (x, y) from from either its parent's top left corner, if the shape's parent is another shape, or else from the 0,0 of the page, if the shape's parent is the page; and the shape's rotation.
Example
editor.getShapeLocalTransform(myShape)
getShapeLocalTransform(shape: TLShape | TLShapeId): Mat
Name | Description |
---|---|
|
The shape to get the local transform for. |
Mat
getShapeMask()
Public method
Get the mask (in the current page space) for a shape.
Example
const pageMask = editor.getShapeMask(shape.id)
getShapeMask(shape: TLShape | TLShapeId): undefined | VecLike[]
Name | Description |
---|---|
|
|
undefined | VecLike[]
The mask for the shape.
getShapeMaskedPageBounds()
Public method
Get the bounds of a shape in the current page space, incorporating any masks. For example, if the shape were the child of a frame and was half way out of the frame, the bounds would be the half of the shape that was in the frame.
Example
editor.getShapeMaskedPageBounds(myShape)
editor.getShapeMaskedPageBounds(myShapeId)
getShapeMaskedPageBounds(shape: TLShape | TLShapeId): Box | undefined
Name | Description |
---|---|
|
The shape to get the masked bounds for. |
Box | undefined
getShapeOutlineSegments()
Public method
Get the local outline segments of a shape.
Example
editor.getShapeOutlineSegments(myShape)
editor.getShapeOutlineSegments(myShapeId)
getShapeOutlineSegments<T extends TLShape>(shape: T | T['id']): Vec[][]
Name | Description |
---|---|
|
The shape (or shape id) to get the outline segments for. |
Vec[][]
getShapePageBounds()
Public method
Get the bounds of a shape in the current page space.
Example
editor.getShapePageBounds(myShape)
editor.getShapePageBounds(myShapeId)
getShapePageBounds(shape: TLShape | TLShapeId): Box | undefined
Name | Description |
---|---|
|
The shape (or shape id) to get the bounds for. |
Box | undefined
getShapePageTransform()
Public method
Get the transform of a shape in the current page space.
Example
editor.getShapePageTransform(myShape)
editor.getShapePageTransform(myShapeId)
getShapePageTransform(shape: TLShape | TLShapeId): Mat
Name | Description |
---|---|
|
The shape (or shape id) to get the page transform for. |
Mat
getShapeParent()
Public method
Get the parent shape for a given shape. Returns undefined if the shape is the direct child of the page.
Example
editor.getShapeParent(myShape)
getShapeParent(shape?: TLShape | TLShapeId): TLShape | undefined
Name | Description |
---|---|
|
|
TLShape | undefined
getShapeParentTransform()
Public method
Get the local transform of a shape's parent as a matrix model.
Example
editor.getShapeParentTransform(myShape)
getShapeParentTransform(shape: TLShape | TLShapeId): Mat
Name | Description |
---|---|
|
The shape (or shape id) to get the parent transform for. |
Mat
getShapesAtPoint()
Public method
Get the shapes, if any, at a given page point.
Example
editor.getShapesAtPoint({ x: 100, y: 100 })
editor.getShapesAtPoint({ x: 100, y: 100 }, { hitInside: true, exact: true })
getShapesAtPoint(
point: VecLike,
opts?: {
margin?: number | undefined
hitInside?: boolean | undefined
}
): TLShape[]
Name | Description |
---|---|
|
The page point to test. |
|
|
TLShape[]
getShapeStyleIfExists()
Public method
getShapeStyleIfExists<T>(shape: TLShape, style: StyleProp<T>): T | undefined
Name | Description |
---|---|
|
|
|
|
T | undefined
getShapeUtil()
Public method
Get a shape util from a shape itself.
Example
const util = editor.getShapeUtil(myArrowShape)
const util = editor.getShapeUtil('arrow')
const util = editor.getShapeUtil<TLArrowShape>(myArrowShape)
const util = editor.getShapeUtil(TLArrowShape)('arrow')
getShapeUtil<S extends TLUnknownShape>(
shape: S | TLShapePartial<S>
): ShapeUtil<S>
Name | Description |
---|---|
|
A shape, shape partial, or shape type. |
ShapeUtil<S>
TLUnknownShape, TLShapePartial, ShapeUtil
getShapeUtil()
Public method
getShapeUtil<S extends TLUnknownShape>(type: S['type']): ShapeUtil<S>
Name | Description |
---|---|
|
|
ShapeUtil<S>
getShapeUtil()
Public method
getShapeUtil<T extends ShapeUtil>(
type: T extends ShapeUtil<infer R> ? R['type'] : string
): T
Name | Description |
---|---|
|
|
T
getSharedOpacity()
Public method
Get the currently selected shared opacity. If any shapes are selected, this returns the shared opacity of the selected shapes. Otherwise, this returns the chosen opacity for the next shape.
getSharedOpacity(): SharedStyle<number>
getSharedStyles()
Public method
A map of all the current styles either in the current selection, or that are relevant to the current tool.
Example
const color = editor.getSharedStyles().get(DefaultColorStyle)
if (color && color.type === 'shared') {
print('All selected shapes have the same color:', color.value)
}
getSharedStyles(): ReadonlySharedStyleMap
getSortedChildIdsForParent()
Public method
Get an array of all the children of a shape.
Example
editor.getSortedChildIdsForParent('frame1')
getSortedChildIdsForParent(parent: TLPage | TLParentId | TLShape): TLShapeId[]
Name | Description |
---|---|
|
|
TLShapeId[]
TLPage, TLParentId, TLShape, TLShapeId
getStateDescendant()
Public method
Get a descendant by its path.
Example
state.getStateDescendant('select')
state.getStateDescendant('select.brushing')
getStateDescendant<T extends StateNode>(path: string): T | undefined
Name | Description |
---|---|
|
The descendant's path of state ids, separated by periods. |
T | undefined
getSvg()
Public method
Get an exported SVG of the given shapes.
getSvg(
shapes: TLShape[] | TLShapeId[],
opts?: Partial<TLSvgOptions>
): Promise<SVGSVGElement | undefined>
Name | Description |
---|---|
|
|
|
Options for the export. |
Promise<SVGSVGElement | undefined>
The SVG element.
TLShape, TLShapeId, TLSvgOptions
getViewportPageBounds()
Public method
The current viewport in the current page space.
getViewportPageBounds(): Box
getViewportPageCenter()
Public method
The center of the viewport in the current page space.
getViewportPageCenter(): Vec
getViewportScreenBounds()
Public method
The bounds of the editor's viewport in screen space.
getViewportScreenBounds(): Box
getViewportScreenCenter()
Public method
The center of the editor's viewport in screen space.
getViewportScreenCenter(): Vec
getZoomLevel()
Public method
The current camera zoom level.
getZoomLevel(): number
groupShapes()
Public method
Create a group containing the provided shapes.
groupShapes(shapes: TLShape[] | TLShapeId[], groupId?: TLShapeId): this
Name | Description |
---|---|
|
The shapes (or shape ids) to group. Defaults to the selected shapes. |
|
The id of the group to create. |
this
hasAncestor()
Public method
Returns true if the the given shape has the given ancestor.
hasAncestor(
shape: TLShape | TLShapeId | undefined,
ancestorId: TLShapeId
): boolean
Name | Description |
---|---|
|
The shape. |
|
The id of the ancestor. |
boolean
interrupt()
Public method
Dispatch an interrupt event.
Example
editor.interrupt()
interrupt(): this
isAncestorSelected()
Public method
Determine whether or not any of a shape's ancestors are selected.
isAncestorSelected(shape: TLShape | TLShapeId): boolean
Name | Description |
---|---|
|
|
boolean
isIn()
Public method
Get whether a certain tool (or other state node) is currently active.
Example
editor.isIn('select')
editor.isIn('select.brushing')
isIn(path: string): boolean
Name | Description |
---|---|
|
The path of active states, separated by periods. |
boolean
isInAny()
Public method
Get whether the state node is in any of the given active paths.
Example
state.isInAny('select', 'erase')
state.isInAny('select.brushing', 'erase.idle')
isInAny(...paths: string[]): boolean
Name | Description |
---|---|
|
|
boolean
isPointInShape()
Public method
Test whether a point (in the current page space) will will a shape. This method takes into account masks, such as when a shape is the child of a frame and is partially clipped by the frame.
Example
editor.isPointInShape({ x: 100, y: 100 }, myShape)
isPointInShape(
shape: TLShape | TLShapeId,
point: VecLike,
opts?: {
margin?: number | undefined
hitInside?: boolean | undefined
}
): boolean
Name | Description |
---|---|
|
The shape to test against. |
|
The page point to test (in the current page space). |
|
|
boolean
isShapeInPage()
Public method
Get whether the given shape is the descendant of the given page.
Example
editor.isShapeInPage(myShape)
editor.isShapeInPage(myShape, 'page1')
isShapeInPage(shape: TLShape | TLShapeId, pageId?: TLPageId): boolean
Name | Description |
---|---|
|
The shape to check. |
|
The id of the page to check against. Defaults to the current page. |
boolean
isShapeOfType()
Public method
Get whether a shape matches the type of a TLShapeUtil.
Example
const isArrowShape = isShapeOfType<TLArrowShape>(someShape, 'arrow')
isShapeOfType<T extends TLUnknownShape>(
shape: TLUnknownShape,
type: T['type']
): shape is T
Name | Description |
---|---|
|
the shape to test |
|
|
shape is T
isShapeOfType()
Public method
isShapeOfType<T extends TLUnknownShape>(
shapeId: TLUnknownShape['id'],
type: T['type']
): shapeId is T['id']
Name | Description |
---|---|
|
|
|
|
shapeId is T['id']
isShapeOrAncestorLocked()
Public method
Check whether a shape or its parent is locked.
isShapeOrAncestorLocked(shape?: TLShape): boolean
Name | Description |
---|---|
|
The shape (or shape id) to check. |
boolean
isShapeOrAncestorLocked()
Public method
isShapeOrAncestorLocked(id?: TLShapeId): boolean
Name | Description |
---|---|
|
|
boolean
mark()
Public method
Create a new "mark", or stopping point, in the undo redo history. Creating a mark will clear any redos.
Example
editor.mark()
editor.mark('flip shapes')
mark(markId?: string, onUndo?: boolean, onRedo?: boolean): this
Name | Description |
---|---|
|
The mark's id, usually the reason for adding the mark. |
|
Whether to stop at the mark when undoing. |
|
Whether to stop at the mark when redoing. |
this
moveShapesToPage()
Public method
Move shapes to page.
Example
editor.moveShapesToPage(['box1', 'box2'], 'page1')
moveShapesToPage(shapes: TLShape[] | TLShapeId[], pageId: TLPageId): this
Name | Description |
---|---|
|
The shapes (or shape ids) of the shapes to move. |
|
The id of the page where the shapes will be moved. |
this
nudgeShapes()
Public method
Move shapes by a delta.
Example
editor.nudgeShapes(['box1', 'box2'], { x: 8, y: 8 })
editor.nudgeShapes(
editor.getSelectedShapes(),
{ x: 8, y: 8 },
{ squashing: true }
)
nudgeShapes(
shapes: TLShape[] | TLShapeId[],
offset: VecLike,
historyOptions?: TLCommandHistoryOptions
): this
Name | Description |
---|---|
|
The shapes (or shape ids) to move. |
|
|
|
The history options for the change. |
this
TLShape, TLShapeId, VecLike, TLCommandHistoryOptions
packShapes()
Public method
Pack shapes into a grid centered on their current position. Based on potpack (https://github.com/mapbox/potpack).
Example
editor.packShapes([box1, box2], 32)
editor.packShapes(editor.getSelectedShapeIds(), 32)
packShapes(shapes: TLShape[] | TLShapeId[], gap: number): this
Name | Description |
---|---|
|
The shapes (or shape ids) to pack. |
|
The padding to apply to the packed shapes. Defaults to 16. |
this
pageToScreen()
Public method
Convert a point in the current page space to a point in current screen space.
Example
editor.pageToScreen({ x: 100, y: 100 })
pageToScreen(point: VecLike): {
x: number
y: number
z: number
}
Name | Description |
---|---|
|
The point in screen space. |
{
x: number
y: number
z: number
}
pan()
Public method
Pan the camera.
Example
editor.pan({ x: 100, y: 100 })
editor.pan({ x: 100, y: 100 }, { duration: 1000 })
pan(offset: VecLike, animation?: TLAnimationOptions): this
Name | Description |
---|---|
|
The offset in the current page space. |
|
The animation options. |
this
panZoomIntoView()
Public method
Pan or pan/zoom the selected ids into view. This method tries to not change the zoom if possible.
panZoomIntoView(ids: TLShapeId[], animation?: TLAnimationOptions): this
Name | Description |
---|---|
|
The ids of the shapes to pan and zoom into view. |
|
The options for an animation. |
this
popFocusedGroupId()
Public method
Exit the current focused group, moving up to the next parent group if there is one.
popFocusedGroupId(): this
putContentOntoCurrentPage()
Public method
Place content into the editor.
putContentOntoCurrentPage(
content: TLContent,
options?: {
point?: VecLike
select?: boolean
preservePosition?: boolean
preserveIds?: boolean
}
): this
Name | Description |
---|---|
|
The content. |
|
Options for placing the content. |
this
putExternalContent()
Public method
Handle external content, such as files, urls, embeds, or plain text which has been put into the app, for example by pasting external text or dropping external images onto canvas.
putExternalContent(info: TLExternalContent): Promise<void>
Name | Description |
---|---|
|
Info about the external content. |
Promise<void>
redo()
Public method
Redo to the next mark.
Example
editor.redo()
redo(): this
registerExternalAssetHandler()
Public method
Register an external content handler. This handler will be called when the editor receives external content of the provided type. For example, the 'image' type handler will be called when a user drops an image onto the canvas.
Example
editor.registerExternalAssetHandler('text', myHandler)
registerExternalAssetHandler<T extends TLExternalAssetContent['type']>(
type: T,
handler:
| ((
info: TLExternalAssetContent & {
type: T
}
) => Promise<TLAsset>)
| null
): this
Name | Description |
---|---|
|
The type of external content. |
|
The handler to use for this content type. |
this
TLExternalAssetContent, TLAsset
registerExternalContentHandler()
Public method
Register an external content handler. This handler will be called when the editor receives external content of the provided type. For example, the 'image' type handler will be called when a user drops an image onto the canvas.
Example
editor.registerExternalContentHandler('text', myHandler)
registerExternalContentHandler<T extends TLExternalContent['type']>(
type: T,
handler:
| ((
info: T extends TLExternalContent['type']
? TLExternalContent & {
type: T
}
: TLExternalContent
) => void)
| null
): this
Name | Description |
---|---|
|
The type of external content. |
|
The handler to use for this content type. |
this
renamePage()
Public method
Rename a page.
Example
editor.renamePage('page1', 'My Page')
renamePage(
page: TLPage | TLPageId,
name: string,
historyOptions?: TLCommandHistoryOptions
): this
Name | Description |
---|---|
|
|
|
The new name. |
|
|
this
TLPage, TLPageId, TLCommandHistoryOptions
reparentShapes()
Public method
Reparent shapes to a new parent. This operation preserves the shape's current page positions / rotations.
Example
editor.reparentShapes([box1, box2], 'frame1')
editor.reparentShapes([box1.id, box2.id], 'frame1')
editor.reparentShapes([box1.id, box2.id], 'frame1', 4)
reparentShapes(
shapes: TLShape[] | TLShapeId[],
parentId: TLParentId,
insertIndex?: string
): this
Name | Description |
---|---|
|
The shapes (or shape ids) of the shapes to reparent. |
|
The id of the new parent shape. |
|
The index to insert the children. |
this
TLShape, TLShapeId, TLParentId
resetZoom()
Public method
Set the zoom back to 100%.
Example
editor.resetZoom()
editor.resetZoom(editor.getViewportScreenCenter(), { duration: 200 })
editor.resetZoom(editor.getViewportScreenCenter(), { duration: 200 })
resetZoom(point?: Vec, animation?: TLAnimationOptions): this
Name | Description |
---|---|
|
The screen point to zoom out on. Defaults to the viewport screen center. |
|
The options for an animation. |
this
resizeShape()
Public method
Resize a shape.
resizeShape(
shape: TLShape | TLShapeId,
scale: VecLike,
options?: TLResizeShapeOptions
): this
Name | Description |
---|---|
|
|
|
The scale factor to apply to the shape. |
|
Additional options. |
this
TLShape, TLShapeId, VecLike, TLResizeShapeOptions
rotateShapesBy()
Public method
Rotate shapes by a delta in radians. Note: Currently, this assumes that the shapes are your currently selected shapes.
Example
editor.rotateShapesBy(editor.getSelectedShapeIds(), Math.PI)
editor.rotateShapesBy(editor.getSelectedShapeIds(), Math.PI / 2)
rotateShapesBy(shapes: TLShape[] | TLShapeId[], delta: number): this
Name | Description |
---|---|
|
The shapes (or shape ids) of the shapes to move. |
|
The delta in radians to apply to the selection rotation. |
this
screenToPage()
Public method
Convert a point in screen space to a point in the current page space.
Example
editor.screenToPage({ x: 100, y: 100 })
screenToPage(point: VecLike): {
x: number
y: number
z: number
}
Name | Description |
---|---|
|
The point in screen space. |
{
x: number
y: number
z: number
}
select()
Public method
Select one or more shapes.
Example
editor.select('id1')
editor.select('id1', 'id2')
select(...shapes: TLShape[] | TLShapeId[]): this
Name | Description |
---|---|
|
|
this
selectAll()
Public method
Select all direct children of the current page.
Example
editor.selectAll()
selectAll(): this
selectNone()
Public method
Clear the selection.
Example
editor.selectNone()
selectNone(): this
sendBackward()
Public method
Send shapes backward in the page's object list.
Example
editor.sendBackward(['id1', 'id2'])
editor.sendBackward([box1, box2])
sendBackward(shapes: TLShape[] | TLShapeId[]): this
Name | Description |
---|---|
|
The shapes (or shape ids) to move. |
this
sendToBack()
Public method
Send shapes to the back of the page's object list.
Example
editor.sendToBack(['id1', 'id2'])
editor.sendToBack(box1, box2)
sendToBack(shapes: TLShape[] | TLShapeId[]): this
Name | Description |
---|---|
|
The shapes (or shape ids) to move. |
this
setCamera()
Public method
Set the current camera.
Example
editor.setCamera({ x: 0, y: 0 })
editor.setCamera({ x: 0, y: 0, z: 1.5 })
editor.setCamera(
{ x: 0, y: 0, z: 1.5 },
{ duration: 1000, easing: (t) => t * t }
)
setCamera(point: VecLike, animation?: TLAnimationOptions): this
Name | Description |
---|---|
|
The new camera position. |
|
Options for an animation. |
this
setCroppingShape()
Public method
Set the current cropping shape.
Example
editor.setCroppingShape(myShape)
editor.setCroppingShape(myShape.id)
setCroppingShape(shape: null | TLShape | TLShapeId): this
Name | Description |
---|---|
|
The shape (or shape id) to set as cropping. |
this
setCurrentPage()
Public method
Set the current page.
Example
editor.setCurrentPage('page1')
editor.setCurrentPage(myPage1)
setCurrentPage(
page: TLPage | TLPageId,
historyOptions?: TLCommandHistoryOptions
): this
Name | Description |
---|---|
|
The page (or page id) to set as the current page. |
|
The history options for the change. |
this
TLPage, TLPageId, TLCommandHistoryOptions
setCurrentTool()
Public method
Set the selected tool.
Example
editor.setCurrentTool('hand')
editor.setCurrentTool('hand', { date: Date.now() })
setCurrentTool(id: string, info?: {}): this
Name | Description |
---|---|
|
The id of the tool to select. |
|
Arbitrary data to pass along into the transition. |
this
setEditingShape()
Public method
Set the current editing shape.
Example
editor.setEditingShape(myShape)
editor.setEditingShape(myShape.id)
setEditingShape(shape: null | TLShape | TLShapeId): this
Name | Description |
---|---|
|
The shape (or shape id) to set as editing. |
this
setErasingShapes()
Public method
Set the editor's current erasing shapes.
Example
editor.setErasingShapes([myShape])
editor.setErasingShapes([myShape.id])
setErasingShapes(shapes: TLShape[] | TLShapeId[]): this
Name | Description |
---|---|
|
The shapes (or shape ids) to set as hinting. |
this
setFocusedGroup()
Public method
Set the current focused group shape.
setFocusedGroup(shape: null | TLGroupShape | TLShapeId): this
Name | Description |
---|---|
|
The group shape id (or group shape's id) to set as the focused group shape. |
this
setHintingShapes()
Public method
Set the editor's current hinting shapes.
Example
editor.setHintingShapes([myShape])
editor.setHintingShapes([myShape.id])
setHintingShapes(shapes: TLShape[] | TLShapeId[]): this
Name | Description |
---|---|
|
The shapes (or shape ids) to set as hinting. |
this
setHoveredShape()
Public method
Set the editor's current hovered shape.
Example
editor.setHoveredShape(myShape)
editor.setHoveredShape(myShape.id)
setHoveredShape(shape: null | TLShape | TLShapeId): this
Name | Description |
---|---|
|
|
this
setOpacityForNextShapes()
Public method
Set the opacity for the next shapes. This will effect subsequently created shapes.
Example
editor.setOpacityForNextShapes(0.5)
editor.setOpacityForNextShapes(0.5, { squashing: true })
setOpacityForNextShapes(
opacity: number,
historyOptions?: TLCommandHistoryOptions
): this
Name | Description |
---|---|
|
The opacity to set. Must be a number between 0 and 1 inclusive. |
|
The history options for the change. |
this
setOpacityForSelectedShapes()
Public method
Set the current opacity. This will effect any selected shapes.
Example
editor.setOpacityForSelectedShapes(0.5)
editor.setOpacityForSelectedShapes(0.5, { squashing: true })
setOpacityForSelectedShapes(
opacity: number,
historyOptions?: TLCommandHistoryOptions
): this
Name | Description |
---|---|
|
The opacity to set. Must be a number between 0 and 1 inclusive. |
|
The history options for the change. |
this
setSelectedShapes()
Public method
Select one or more shapes.
Example
editor.setSelectedShapes(['id1'])
editor.setSelectedShapes(['id1', 'id2'])
setSelectedShapes(
shapes: TLShape[] | TLShapeId[],
historyOptions?: TLCommandHistoryOptions
): this
Name | Description |
---|---|
|
|
|
The history options for the change. |
this
TLShape, TLShapeId, TLCommandHistoryOptions
setStyleForNextShapes()
Public method
Set the value of a StyleProp for the next shapes. This change will be applied to subsequently created shapes.
Example
editor.setStyleForNextShapes(DefaultColorStyle, 'red')
editor.setStyleForNextShapes(DefaultColorStyle, 'red', { ephemeral: true })
setStyleForNextShapes<T>(
style: StyleProp<T>,
value: T,
historyOptions?: TLCommandHistoryOptions
): this
Name | Description |
---|---|
|
The style to set. |
|
The value to set. |
|
The history options for the change. |
this
StyleProp, TLCommandHistoryOptions
setStyleForSelectedShapes()
Public method
Set the value of a StyleProp. This change will be applied to the currently selected shapes.
Example
editor.setStyleForSelectedShapes(DefaultColorStyle, 'red')
editor.setStyleForSelectedShapes(DefaultColorStyle, 'red', { ephemeral: true })
setStyleForSelectedShapes<T>(
style: StyleProp<T>,
value: T,
historyOptions?: TLCommandHistoryOptions
): this
Name | Description |
---|---|
|
The style to set. |
|
The value to set. |
|
The history options for the change. |
this
StyleProp, TLCommandHistoryOptions
slideCamera()
Public method
Slide the camera in a certain direction.
slideCamera(opts?: {
speed: number
direction: VecLike
friction: number
speedThreshold?: number | undefined
}): this
Name | Description |
---|---|
|
Options for the slide |
this
stackShapes()
Public method
Stack shape.
Example
editor.stackShapes([box1, box2], 'horizontal', 32)
editor.stackShapes(editor.getSelectedShapeIds(), 'horizontal', 32)
stackShapes(
shapes: TLShape[] | TLShapeId[],
operation: 'horizontal' | 'vertical',
gap: number
): this
Name | Description |
---|---|
|
The shapes (or shape ids) to stack. |
|
Whether to stack horizontally or vertically. |
|
The gap to leave between shapes. |
this
startFollowingUser()
Public method
Start viewport-following a user.
startFollowingUser(userId: string): this
Name | Description |
---|---|
|
The id of the user to follow. |
this
stopCameraAnimation()
Public method
Stop the current camera animation, if any.
stopCameraAnimation(): this
stopFollowingUser()
Public method
Stop viewport-following a user.
stopFollowingUser(): this
stretchShapes()
Public method
Stretch shape sizes and positions to fill their common bounding box.
Example
editor.stretchShapes([box1, box2], 'horizontal')
editor.stretchShapes(editor.getSelectedShapeIds(), 'horizontal')
stretchShapes(
shapes: TLShape[] | TLShapeId[],
operation: 'horizontal' | 'vertical'
): this
Name | Description |
---|---|
|
The shapes (or shape ids) to stretch. |
|
Whether to stretch shapes horizontally or vertically. |
this
toggleLock()
Public method
Toggle the lock state of one or more shapes. If there is a mix of locked and unlocked shapes, all shapes will be locked.
toggleLock(shapes: TLShape[] | TLShapeId[]): this
Name | Description |
---|---|
|
The shapes (or shape ids) to toggle. |
this
undo()
Public method
Undo to the last mark.
Example
editor.undo()
undo(): this
ungroupShapes()
Public method
Ungroup some shapes.
ungroupShapes(ids: TLShapeId[]): this
Name | Description |
---|---|
|
Ids of the shapes to ungroup. Defaults to the selected shapes. |
this
ungroupShapes()
Public method
ungroupShapes(ids: TLShape[]): this
Name | Description |
---|---|
|
|
this
updateAssets()
Public method
Update one or more assets.
Example
editor.updateAssets([{ id: 'asset1', name: 'New name' }])
updateAssets(assets: TLAssetPartial[]): this
Name | Description |
---|---|
|
The assets to update. |
this
updateCurrentPageState()
Public method
Update this instance's page state.
Example
editor.updateCurrentPageState({ id: 'page1', editingShapeId: 'shape:123' })
editor.updateCurrentPageState(
{ id: 'page1', editingShapeId: 'shape:123' },
{ ephemeral: true }
)
updateCurrentPageState(
partial: Partial<
Omit<
TLInstancePageState,
'editingShapeId' | 'focusedGroupId' | 'pageId' | 'selectedShapeIds'
>
>,
historyOptions?: TLCommandHistoryOptions
): this
Name | Description |
---|---|
|
The partial of the page state object containing the changes. |
|
The history options for the change. |
this
TLInstancePageState, TLCommandHistoryOptions
updateDocumentSettings()
Public method
Update the global document settings that apply to all users.
updateDocumentSettings(settings: Partial<TLDocument>): this
Name | Description |
---|---|
|
|
this
updateInstanceState()
Public method
Update the instance's state.
updateInstanceState(
partial: Partial<Omit<TLInstance, 'currentPageId'>>,
historyOptions?: TLCommandHistoryOptions
): this
Name | Description |
---|---|
|
A partial object to update the instance state with. |
|
The history options for the change. |
this
TLInstance, TLCommandHistoryOptions
updatePage()
Public method
Update a page.
Example
editor.updatePage({ id: 'page2', name: 'Page 2' })
editor.updatePage({ id: 'page2', name: 'Page 2' }, { squashing: true })
updatePage(
partial: RequiredKeys<TLPage, 'id'>,
historyOptions?: TLCommandHistoryOptions
): this
Name | Description |
---|---|
|
The partial of the shape to update. |
|
The history options for the change. |
this
RequiredKeys, TLPage, TLCommandHistoryOptions
updateShape()
Public method
Update a shape using a partial of the shape.
Example
editor.updateShape({ id: 'box1', type: 'geo', props: { w: 100, h: 100 } })
updateShape<T extends TLUnknownShape>(
partial: null | TLShapePartial<T> | undefined,
historyOptions?: TLCommandHistoryOptions
): this
Name | Description |
---|---|
|
The shape partial to update. |
|
The history options for the change. |
this
TLUnknownShape, TLShapePartial, TLCommandHistoryOptions
updateShapes()
Public method
Update shapes using partials of each shape.
Example
editor.updateShapes([{ id: 'box1', type: 'geo', props: { w: 100, h: 100 } }])
updateShapes<T extends TLUnknownShape>(
partials: (null | TLShapePartial<T> | undefined)[],
historyOptions?: TLCommandHistoryOptions
): this
Name | Description |
---|---|
|
The shape partials to update. |
|
The history options for the change. |
this
TLUnknownShape, TLShapePartial, TLCommandHistoryOptions
updateViewportScreenBounds()
Public method
Update the viewport. The viewport will measure the size and screen position of its container element. This should be done whenever the container's position on the screen changes.
Example
editor.updateViewportScreenBounds()
editor.updateViewportScreenBounds(true)
updateViewportScreenBounds(center?: boolean): this
Name | Description |
---|---|
|
Whether to preserve the viewport page center as the viewport changes. |
this
visitDescendants()
Public method
Run a visitor function for all descendants of a shape.
Example
editor.visitDescendants('frame1', myCallback)
visitDescendants(
parent: TLPage | TLParentId | TLShape,
visitor: (id: TLShapeId) => false | void
): this
Name | Description |
---|---|
|
|
|
The visitor function. |
this
TLPage, TLParentId, TLShape, TLShapeId
zoomIn()
Public method
Zoom the camera in.
Example
editor.zoomIn()
editor.zoomIn(editor.getViewportScreenCenter(), { duration: 120 })
editor.zoomIn(editor.inputs.currentScreenPoint, { duration: 120 })
zoomIn(point?: Vec, animation?: TLAnimationOptions): this
Name | Description |
---|---|
|
|
|
The options for an animation. |
this
zoomOut()
Public method
Zoom the camera out.
Example
editor.zoomOut()
editor.zoomOut(editor.getViewportScreenCenter(), { duration: 120 })
editor.zoomOut(editor.inputs.currentScreenPoint, { duration: 120 })
zoomOut(point?: Vec, animation?: TLAnimationOptions): this
Name | Description |
---|---|
|
|
|
The options for an animation. |
this
zoomToBounds()
Public method
Zoom the camera to fit a bounding box (in the current page space).
Example
editor.zoomToBounds(myBounds)
editor.zoomToBounds(myBounds, 1)
editor.zoomToBounds(myBounds, 1, { duration: 100 })
zoomToBounds(
bounds: Box,
targetZoom?: number,
animation?: TLAnimationOptions
): this
Name | Description |
---|---|
|
The bounding box. |
|
The desired zoom level. Defaults to 0.1. |
|
The options for an animation. |
this
zoomToContent()
Public method
Move the camera to the nearest content.
Example
editor.zoomToContent()
editor.zoomToContent({ duration: 200 })
zoomToContent(): this
zoomToFit()
Public method
Zoom the camera to fit the current page's content in the viewport.
Example
editor.zoomToFit()
editor.zoomToFit({ duration: 200 })
zoomToFit(animation?: TLAnimationOptions): this
Name | Description |
---|---|
|
The options for an animation. |
this
zoomToSelection()
Public method
Zoom the camera to fit the current selection in the viewport.
Example
editor.zoomToSelection()
zoomToSelection(animation?: TLAnimationOptions): this
Name | Description |
---|---|
|
The options for an animation. |
this