Editor
Table of contents
- Properties
- Methods
- addOpenMenu
- alignShapes
- animateShape
- animateShapes
- 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
- focus
- getAncestorPageId
- getArrowInfo
- getArrowsBoundTo
- getAsset
- getAssetForExternalContent
- getAssets
- getBaseZoom
- getCamera
- getCameraOptions
- getCameraState
- getCanRedo
- getCanUndo
- getCollaborators
- getCollaboratorsOnCurrentPage
- getContentFromCurrentPage
- getCroppingShapeId
- getCulledShapes
- getCurrentPage
- getCurrentPageBounds
- getCurrentPageId
- getCurrentPageRenderingShapesSorted
- getCurrentPageShapeIds
- getCurrentPageShapes
- getCurrentPageShapesSorted
- getCurrentPageState
- getCurrentTool
- getCurrentToolId
- getDocumentSettings
- getDroppingOverShape
- getEditingShape
- getEditingShapeId
- getErasingShapeIds
- getErasingShapes
- getFocusedGroup
- getFocusedGroupId
- getHighestIndexForParent
- getHintingShape
- getHintingShapeIds
- getHoveredShape
- getHoveredShapeId
- getInitialMetaForShape
- getInitialZoom
- getInstanceState
- getIsMenuOpen
- getOnlySelectedShape
- getOnlySelectedShapeId
- getOpenMenus
- getOutermostSelectableShape
- getPage
- getPages
- getPageShapeIds
- getPageStates
- getPath
- getPointInParentSpace
- getPointInShapeSpace
- getRenderingShapes
- getSelectedShapeAtPoint
- getSelectedShapeIds
- getSelectedShapes
- getSelectionPageBounds
- getSelectionRotatedPageBounds
- getSelectionRotatedScreenBounds
- getSelectionRotation
- getShape
- getShapeAncestors
- getShapeAndDescendantIds
- getShapeAtPoint
- getShapeClipPath
- getShapeGeometry
- getShapeHandles
- getShapeLocalTransform
- getShapeMask
- getShapeMaskedPageBounds
- getShapePageBounds
- getShapePageTransform
- getShapeParent
- getShapeParentTransform
- getShapesAtPoint
- getShapeStyleIfExists
- getShapeUtil
- getShapeUtil
- getShapeUtil
- getSharedOpacity
- getSharedStyles
- getSortedChildIdsForParent
- getStateDescendant
- getStyleForNextShape
- getSvg
- getSvgElement
- getSvgString
- getViewportPageBounds
- getViewportScreenBounds
- getViewportScreenCenter
- getZoomLevel
- groupShapes
- hasAncestor
- interrupt
- isAncestorSelected
- isIn
- isInAny
- isPointInShape
- isShapeInPage
- isShapeOfType
- isShapeOfType
- isShapeOrAncestorLocked
- isShapeOrAncestorLocked
- mark
- moveShapesToPage
- nudgeShapes
- packShapes
- pageToScreen
- pageToViewport
- popFocusedGroupId
- putContentOntoCurrentPage
- putExternalContent
- redo
- registerExternalAssetHandler
- registerExternalContentHandler
- renamePage
- reparentShapes
- resetZoom
- resizeShape
- rotateShapesBy
- screenToPage
- select
- selectAll
- selectNone
- sendBackward
- sendToBack
- setCamera
- setCameraOptions
- 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
- zoomToFit
- zoomToSelection
- zoomToUser
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.
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
focusManager
Public readonly property
A manager for ensuring correct focus. See FocusManager for details.
readonly focusManager: FocusManager
getContainer
Public property
The current HTML element containing the editor.
const container = editor.getContainer()
getContainer: () => HTMLElement
history
Public readonly property
A manager for the app's history.
readonly history: HistoryManager<TLRecord>
inputs
Public property
The app's current input state.
inputs: {
buttons: Set<number>
keys: Set<string>
originScreenPoint: Vec
originPagePoint: Vec
currentScreenPoint: Vec
currentPagePoint: Vec
previousScreenPoint: Vec
previousPagePoint: Vec
pointerVelocity: Vec
altKey: boolean
ctrlKey: boolean
isPen: boolean
shiftKey: boolean
isDragging: boolean
isEditing: boolean
isPanning: boolean
isPinching: boolean
isPointing: boolean
}
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. See SideEffectManager for details.
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<any>, 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.
editor.addOpenMenu('menu-id')
addOpenMenu(id: string): this
Name | Description |
---|---|
|
|
this
alignShapes()
Public method
Align shape positions.
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.
editor.animateShape({ id: 'box1', type: 'box', x: 100, y: 100 })
editor.animateShape(
{ id: 'box1', type: 'box', x: 100, y: 100 },
{ animation: { duration: 100, ease: (t) => t * t } }
)
animateShape(
partial: null | TLShapePartial | undefined,
opts?: Partial<{
animation: Partial<{
duration: number
easing: (t: number) => number
}>
force: boolean
immediate: boolean
reset: boolean
}>
): this
Name | Description |
---|---|
|
The shape partial to update. |
|
|
this
animateShapes()
Public method
Animate shapes.
editor.animateShapes([{ id: 'box1', type: 'box', x: 100, y: 100 }])
editor.animateShapes([{ id: 'box1', type: 'box', x: 100, y: 100 }], {
animation: { duration: 100, ease: (t) => t * t },
})
animateShapes(
partials: (null | TLShapePartial | undefined)[],
opts?: Partial<{
animation: Partial<{
duration: number
easing: (t: number) => number
}>
force: boolean
immediate: boolean
reset: boolean
}>
): this
Name | Description |
---|---|
|
The shape partials to update. |
|
|
this
bail()
Public method
Clear all marks in the undo stack back to the next mark.
editor.bail()
bail(): this
bailToMark()
Public method
Clear all marks in the undo stack back to the mark with the provided mark id.
editor.bailToMark('dragging')
bailToMark(id: string): this
Name | Description |
---|---|
|
|
this
batch()
Public method
Run a function in a batch.
batch(fn: () => void, opts?: TLHistoryBatchOptions): this
Name | Description |
---|---|
|
|
|
|
this
bringForward()
Public method
Bring shapes forward in the page's object list.
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.
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.
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).
editor.centerOnPoint({ x: 100, y: 100 })
editor.centerOnPoint({ x: 100, y: 100 }, { animation: { duration: 200 } })
centerOnPoint(point: VecLike, opts?: TLCameraMoveOptions): this
Name | Description |
---|---|
|
The point in the current page space to center on. |
|
|
this
clearOpenMenus()
Public method
Clear all open menus.
editor.clearOpenMenus()
clearOpenMenus(): this
complete()
Public method
Dispatch a complete event.
editor.complete()
complete(): this
createAssets()
Public method
Create one or more assets.
editor.createAssets([...myAssets])
createAssets(assets: TLAsset[]): this
Name | Description |
---|---|
|
The assets to create. |
this
createPage()
Public method
Create a page.
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.
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.
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.
editor.deleteAssets(['asset1', 'asset2'])
deleteAssets(assets: TLAsset[] | TLAssetId[]): this
Name | Description |
---|---|
|
|
this
deleteOpenMenu()
Public method
Delete an open menu.
editor.deleteOpenMenu('menu-id')
deleteOpenMenu(id: string): this
Name | Description |
---|---|
|
|
this
deletePage()
Public method
Delete a page.
editor.deletePage('page1')
deletePage(page: TLPage | TLPageId): this
Name | Description |
---|---|
|
|
this
deleteShape()
Public method
Delete a shape.
editor.deleteShape(shape.id)
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.
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.
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.
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.
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
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.
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
focus()
Public method
Dispatch a focus event.
editor.focus()
focus(): 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.
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.
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.
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
getBaseZoom()
Public method
Get the camera's base level for calculating actual zoom levels based on the zoom steps.
editor.getBaseZoom()
getBaseZoom(): number
getCamera()
Public method
The current camera.
getCamera(): import('@tldraw/tlschema').TLCamera
getCameraOptions()
Public method
Get the current camera options.
editor.getCameraOptions()
getCameraOptions(): TLCameraOptions
getCameraState()
Public method
Whether the camera is moving or idle.
editor.getCameraState()
getCameraState(): 'idle' | 'moving'
getCanRedo()
Public method
Whether the app can redo.
getCanRedo(): boolean
getCanUndo()
Public method
Whether the app can undo.
getCanUndo(): boolean
getCollaborators()
Public method
Returns a list of presence records for all peer collaborators. This will return the latest presence record for each connected user.
getCollaborators(): import('@tldraw/tlschema').TLInstancePresence[]
getCollaboratorsOnCurrentPage()
Public method
Returns a list of presence records for all peer collaborators on the current page. This will return the latest presence record for each connected user.
getCollaboratorsOnCurrentPage(): import('@tldraw/tlschema').TLInstancePresence[]
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
getCulledShapes()
Public method
Get culled shapes.
getCulledShapes(): Set<TLShapeId>
getCurrentPage()
Public method
The current page.
editor.getCurrentPage()
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.
editor.getCurrentPageId()
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.
editor.getCurrentPageIds()
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): IndexKey
Name | Description |
---|---|
|
|
IndexKey
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.
editor.getInitialMetaForShape = (shape) => {
if (shape.type === 'note') {
return { createdBy: myCurrentUser.id }
}
}
getInitialMetaForShape(_shape: TLShape): JsonObject
Name | Description |
---|---|
|
|
JsonObject
getInitialZoom()
Public method
Get the camera's initial or reset zoom level.
editor.getInitialZoom()
getInitialZoom(): number
getInstanceState()
Public method
The current instance's state.
getInstanceState(): TLInstance
getIsMenuOpen()
Public method
Get whether any menus are open.
editor.getIsMenuOpen()
getIsMenuOpen(): boolean
getOnlySelectedShape()
Public method
The app's only selected shape.
getOnlySelectedShape(): null | TLShape
getOnlySelectedShapeId()
Public method
The id of the app's only selected shape.
getOnlySelectedShapeId(): null | TLShapeId
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.
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.
editor.getPages()
getPages(): TLPage[]
getPageShapeIds()
Public method
Get the ids of shapes on a page.
const idsOnPage1 = editor.getPageShapeIds('page1')
const idsOnPage2 = editor.getPageShapeIds(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.
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.
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.
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
getRenderingShapes()
Public method
Get the shapes that should be displayed in the current viewport.
editor.getRenderingShapes()
getRenderingShapes(): {
backgroundIndex: number
id: TLShapeId
index: number
opacity: number
shape: TLShape
util: ShapeUtil<TLUnknownShape>
}[]
TLShapeId, TLShape, ShapeUtil, TLUnknownShape
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
getSelectionRotatedScreenBounds()
Public method
The bounds of the selection bounding box in the current page space.
getSelectionRotatedScreenBounds(): 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.
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.
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?: {
filter?: ((shape: TLShape) => boolean) | undefined
hitFrameInside?: boolean | undefined
hitInside?: boolean | undefined
hitLabels?: boolean | undefined
hitLocked?: boolean | undefined
margin?: number | undefined
renderingOnly?: 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.
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.
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.
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.
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.
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.
editor.getShapeMaskedPageBounds(myShape)
editor.getShapeMaskedPageBounds(myShapeId)
getShapeMaskedPageBounds(shape: TLShape | TLShapeId): Box | undefined
Name | Description |
---|---|
|
The shape to get the masked bounds for. |
Box | undefined
getShapePageBounds()
Public method
Get the bounds of a shape in the current page space.
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.
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.
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.
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.
editor.getShapesAtPoint({ x: 100, y: 100 })
editor.getShapesAtPoint({ x: 100, y: 100 }, { hitInside: true, exact: true })
getShapesAtPoint(
point: VecLike,
opts?: {
hitInside?: boolean | undefined
margin?: number | 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.
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.
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.
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.
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
getStyleForNextShape()
Public method
Get the style for the next shape.
const color = editor.getStyleForNextShape(DefaultColorStyle)
getStyleForNextShape<T>(style: StyleProp<T>): T
Name | Description |
---|---|
|
The style to get. |
T
getSvg()
Public method
getSvg(
shapes: TLShape[] | TLShapeId[],
opts?: Partial<TLSvgOptions>
): Promise<SVGSVGElement | undefined>
Name | Description |
---|---|
|
|
|
|
Promise<SVGSVGElement | undefined>
TLShape, TLShapeId, TLSvgOptions
getSvgElement()
Public method
Get an exported SVG element of the given shapes.
getSvgElement(
shapes: TLShape[] | TLShapeId[],
opts?: Partial<TLSvgOptions>
): Promise<
| {
height: number
svg: SVGSVGElement
width: number
}
| undefined
>
Name | Description |
---|---|
|
|
|
Options for the export. |
Promise<
| {
height: number
svg: SVGSVGElement
width: number
}
| undefined
>
The SVG element.
TLShape, TLShapeId, TLSvgOptions
getSvgString()
Public method
Get an exported SVG string of the given shapes.
getSvgString(
shapes: TLShape[] | TLShapeId[],
opts?: Partial<TLSvgOptions>
): Promise<
| {
height: number
svg: string
width: number
}
| undefined
>
Name | Description |
---|---|
|
|
|
Options for the export. |
Promise<
| {
height: number
svg: string
width: number
}
| undefined
>
The SVG element.
TLShape, TLShapeId, TLSvgOptions
getViewportPageBounds()
Public method
The current viewport in the current page space.
getViewportPageBounds(): Box
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.
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.
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.
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.
editor.isPointInShape({ x: 100, y: 100 }, myShape)
isPointInShape(
shape: TLShape | TLShapeId,
point: VecLike,
opts?: {
hitInside?: boolean | undefined
margin?: number | 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.
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.
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.
editor.mark()
editor.mark('flip shapes')
mark(markId?: string): this
Name | Description |
---|---|
|
The mark's id, usually the reason for adding the mark. |
this
moveShapesToPage()
Public method
Move shapes to page.
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.
editor.nudgeShapes(['box1', 'box2'], { x: 8, y: 8 })
nudgeShapes(shapes: TLShape[] | TLShapeId[], offset: VecLike): this
Name | Description |
---|---|
|
The shapes (or shape ids) to move. |
|
|
this
packShapes()
Public method
Pack shapes into a grid centered on their current position. Based on potpack (https://github.com/mapbox/potpack).
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.
editor.pageToScreen({ x: 100, y: 100 })
pageToScreen(point: VecLike): Vec
Name | Description |
---|---|
|
The point in page space. |
Vec
pageToViewport()
Public method
Convert a point in the current page space to a point in current viewport space.
editor.pageToViewport({ x: 100, y: 100 })
pageToViewport(point: VecLike): Vec
Name | Description |
---|---|
|
The point in page space. |
Vec
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
preserveIds?: boolean
preservePosition?: boolean
select?: 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.
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.
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.
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.
editor.renamePage('page1', 'My Page')
renamePage(page: TLPage | TLPageId, name: string): this
Name | Description |
---|---|
|
|
|
The new name. |
this
reparentShapes()
Public method
Reparent shapes to a new parent. This operation preserves the shape's current page positions / rotations.
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?: IndexKey
): 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%.
editor.resetZoom()
editor.resetZoom(editor.getViewportScreenCenter(), {
animation: { duration: 200 },
})
editor.resetZoom(editor.getViewportScreenCenter(), {
animation: { duration: 200 },
})
resetZoom(point?: Vec, opts?: TLCameraMoveOptions): this
Name | Description |
---|---|
|
The screen point to zoom out on. Defaults to the viewport screen center. |
|
The camera move options. |
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.
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.
editor.screenToPage({ x: 100, y: 100 })
screenToPage(point: VecLike): Vec
Name | Description |
---|---|
|
The point in screen space. |
Vec
select()
Public method
Select one or more shapes.
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.
editor.selectAll()
selectAll(): this
selectNone()
Public method
Clear the selection.
editor.selectNone()
selectNone(): this
sendBackward()
Public method
Send shapes backward in the page's object list.
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.
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.
editor.setCamera({ x: 0, y: 0 })
editor.setCamera({ x: 0, y: 0, z: 1.5 })
editor.setCamera(
{ x: 0, y: 0, z: 1.5 },
{ animation: { duration: 1000, easing: (t) => t * t } }
)
setCamera(point: VecLike, opts?: TLCameraMoveOptions): this
Name | Description |
---|---|
|
The new camera position. |
|
The camera move options. |
this
setCameraOptions()
Public method
Set the camera options. Changing the options won't immediately change the camera itself, so you may want to call setCamera
after changing the options.
editor.setCameraOptions(myCameraOptions)
editor.setCamera(editor.getCamera())
setCameraOptions(options: Partial<TLCameraOptions>): this
Name | Description |
---|---|
|
The camera options to set. |
this
setCroppingShape()
Public method
Set the current cropping shape.
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.
editor.setCurrentPage('page1')
editor.setCurrentPage(myPage1)
setCurrentPage(page: TLPage | TLPageId): this
Name | Description |
---|---|
|
The page (or page id) to set as the current page. |
this
setCurrentTool()
Public method
Set the selected tool.
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.
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.
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.
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.
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.
editor.setOpacityForNextShapes(0.5)
setOpacityForNextShapes(
opacity: number,
historyOptions?: TLHistoryBatchOptions
): 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.
editor.setOpacityForSelectedShapes(0.5)
setOpacityForSelectedShapes(opacity: number): this
Name | Description |
---|---|
|
The opacity to set. Must be a number between 0 and 1 inclusive. |
this
setSelectedShapes()
Public method
Select one or more shapes.
editor.setSelectedShapes(['id1'])
editor.setSelectedShapes(['id1', 'id2'])
setSelectedShapes(shapes: TLShape[] | TLShapeId[]): this
Name | Description |
---|---|
|
|
this
setStyleForNextShapes()
Public method
Set the value of a StyleProp for the next shapes. This change will be applied to subsequently created shapes.
editor.setStyleForNextShapes(DefaultColorStyle, 'red')
editor.setStyleForNextShapes(DefaultColorStyle, 'red', { ephemeral: true })
setStyleForNextShapes<T>(
style: StyleProp<T>,
value: T,
historyOptions?: TLHistoryBatchOptions
): this
Name | Description |
---|---|
|
The style to set. |
|
The value to set. |
|
The history options for the change. |
this
setStyleForSelectedShapes()
Public method
Set the value of a StyleProp. This change will be applied to the currently selected shapes.
editor.setStyleForSelectedShapes(DefaultColorStyle, 'red')
setStyleForSelectedShapes<S extends StyleProp<any>>(
style: S,
value: StylePropValue<S>
): this
Name | Description |
---|---|
|
The style to set. |
|
The value to set. |
this
slideCamera()
Public method
Slide the camera in a certain direction.
editor.slideCamera({ speed: 1, direction: { x: 1, y: 0 }, friction: 0.1 })
slideCamera(opts?: {
direction: VecLike
friction: number
speed: number
speedThreshold?: number | undefined
}): this
Name | Description |
---|---|
|
Options for the slide |
this
stackShapes()
Public method
Stack shape.
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.
editor.startFollowingUser(myUserId)
startFollowingUser(userId: string): this
Name | Description |
---|---|
|
The id of the user to follow. |
this
stopCameraAnimation()
Public method
Stop the current camera animation, if any.
editor.stopCameraAnimation()
stopCameraAnimation(): this
stopFollowingUser()
Public method
Stop viewport-following a user.
editor.stopFollowingUser()
stopFollowingUser(): this
stretchShapes()
Public method
Stretch shape sizes and positions to fill their common bounding box.
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.
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.
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.
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?: TLHistoryBatchOptions
): this
Name | Description |
---|---|
|
The partial of the page state object containing the changes. |
|
The history options for the change. |
this
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?: TLHistoryBatchOptions
): this
Name | Description |
---|---|
|
A partial object to update the instance state with. |
|
|
this
updatePage()
Public method
Update a page.
editor.updatePage({ id: 'page2', name: 'Page 2' })
updatePage(partial: RequiredKeys<TLPage, 'id'>): this
Name | Description |
---|---|
|
The partial of the shape to update. |
this
updateShape()
Public method
Update a shape using a partial of the shape.
editor.updateShape({ id: 'box1', type: 'geo', props: { w: 100, h: 100 } })
updateShape<T extends TLUnknownShape>(
partial: null | TLShapePartial<T> | undefined
): this
Name | Description |
---|---|
|
The shape partial to update. |
this
TLUnknownShape, TLShapePartial
updateShapes()
Public method
Update shapes using partials of each shape.
editor.updateShapes([{ id: 'box1', type: 'geo', props: { w: 100, h: 100 } }])
updateShapes<T extends TLUnknownShape>(
partials: (null | TLShapePartial<T> | undefined)[]
): this
Name | Description |
---|---|
|
The shape partials to update. |
this
TLUnknownShape, TLShapePartial
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.
editor.updateViewportScreenBounds()
editor.updateViewportScreenBounds(true)
updateViewportScreenBounds(screenBounds: Box, 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.
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.
editor.zoomIn()
editor.zoomIn(editor.getViewportScreenCenter(), {
animation: { duration: 200 },
})
editor.zoomIn(editor.inputs.currentScreenPoint, {
animation: { duration: 200 },
})
zoomIn(point?: Vec, opts?: TLCameraMoveOptions): this
Name | Description |
---|---|
|
The screen point to zoom in on. Defaults to the screen center |
|
The camera move options. |
this
zoomOut()
Public method
Zoom the camera out.
editor.zoomOut()
editor.zoomOut(editor.getViewportScreenCenter(), {
animation: { duration: 120 },
})
editor.zoomOut(editor.inputs.currentScreenPoint, {
animation: { duration: 120 },
})
zoomOut(point?: Vec, opts?: TLCameraMoveOptions): this
Name | Description |
---|---|
|
The point to zoom out on. Defaults to the viewport screen center. |
|
The camera move options. |
this
zoomToBounds()
Public method
Zoom the camera to fit a bounding box (in the current page space).
editor.zoomToBounds(myBounds)
editor.zoomToBounds(myBounds, { animation: { duration: 200 } })
editor.zoomToBounds(myBounds, {
animation: { duration: 200 },
inset: 0,
targetZoom: 1,
})
zoomToBounds(
bounds: BoxLike,
opts?: {
inset?: number
targetZoom?: number
} & TLCameraMoveOptions
): this
Name | Description |
---|---|
|
The bounding box. |
|
The camera move options, target zoom, or custom inset amount. |
this
zoomToFit()
Public method
Zoom the camera to fit the current page's content in the viewport.
editor.zoomToFit()
editor.zoomToFit({ animation: { duration: 200 } })
zoomToFit(opts?: TLCameraMoveOptions): this
Name | Description |
---|---|
|
The camera move options. |
this
zoomToSelection()
Public method
Zoom the camera to fit the current selection in the viewport.
editor.zoomToSelection()
editor.zoomToSelection({ animation: { duration: 200 } })
zoomToSelection(opts?: TLCameraMoveOptions): this
Name | Description |
---|---|
|
|
this
zoomToUser()
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.
editor.zoomToUser(myUserId)
editor.zoomToUser(myUserId, { animation: { duration: 200 } })
zoomToUser(userId: string, opts?: TLCameraMoveOptions): this
Name | Description |
---|---|
|
The id of the user to aniamte to. |
|
The camera move options. |
this