TLShapeUtil
Public Class
Table of Contents
- Properties
- app
- canBind
- canCrop
- canEdit
- canResize
- canScroll
- canUnmount
- getEditingBounds
- hideResizeHandles
- hideRotateHandle
- hideSelectionBoundsBg
- hideSelectionBoundsFg
- isAspectRatioLocked
- isClosed
- onBeforeCreate
- onBeforeUpdate
- onChildrenChange
- onClick
- onDoubleClick
- onDoubleClickEdge
- onDoubleClickHandle
- onDragShapesOut
- onDragShapesOver
- onDropShapesOver
- onEditEnd
- onHandleChange
- onResize
- onResizeEnd
- onResizeStart
- onRotate
- onRotateEnd
- onRotateStart
- onTranslate
- onTranslateEnd
- onTranslateStart
- type
 
- Methods
Signature
abstract class TLShapeUtil<T extends TLUnknownShape> {}
References
Constructor
Public Constructor
Constructs a new instance of the TLShapeUtil class
Parameters
| Name | Description | 
|---|---|
| 
 |  | 
| 
 |  | 
References
Properties
app
Public Property
Signature
app: App
References
canBind
Public Property
Whether the shape can be bound to by an arrow.
Parameters
| Name | Description | 
|---|---|
| 
 | The other shape attempting to bind to this shape. | 
Signature
canBind: <K>(_shape: T, _otherShape?: K | undefined) => boolean
canCrop
Public Property
Whether the shape can be cropped.
Signature
canCrop: TLShapeUtilFlag<T>
References
canEdit
Public Property
Whether the shape can be double clicked to edit.
Signature
canEdit: TLShapeUtilFlag<T>
References
canResize
Public Property
Whether the shape can be resized.
Signature
canResize: TLShapeUtilFlag<T>
References
canScroll
Public Property
Whether the shape can be scrolled while editing.
Signature
canScroll: TLShapeUtilFlag<T>
References
canUnmount
Public Property
Whether the shape can be bound to by an arrow.
Signature
canUnmount: TLShapeUtilFlag<T>
References
getEditingBounds
Public Property
Bounds of the shape to edit.
Note: this could be a text area within a shape for example arrow labels.
Signature
getEditingBounds: (shape: T) => Box2d
References
hideResizeHandles
Public Property
Whether the shape should hide its resize handles when selected.
Signature
hideResizeHandles: TLShapeUtilFlag<T>
References
hideRotateHandle
Public Property
Whether the shape should hide its resize handles when selected.
Signature
hideRotateHandle: TLShapeUtilFlag<T>
References
hideSelectionBoundsBg
Public Property
Whether the shape should hide its selection bounds background when selected.
Signature
hideSelectionBoundsBg: TLShapeUtilFlag<T>
References
hideSelectionBoundsFg
Public Property
Whether the shape should hide its selection bounds foreground when selected.
Signature
hideSelectionBoundsFg: TLShapeUtilFlag<T>
References
isAspectRatioLocked
Public Property
Whether the shape's aspect ratio is locked.
Signature
isAspectRatioLocked: TLShapeUtilFlag<T>
References
isClosed
Public Property
Whether the shape's outline is closed.
Signature
isClosed: TLShapeUtilFlag<T>
References
onBeforeCreate
Public Property
A callback called just before a shape is created. This method provides a last chance to modify the created shape.
Example
onBeforeCreate = (next) => {
  return { ...next, x: next.x + 1 }
}
Parameters
| Name | Description | 
|---|---|
| 
 | The next shape. | 
Signature
onBeforeCreate?: OnBeforeCreateHandler<T>
References
onBeforeUpdate
Public Property
A callback called just before a shape is updated. This method provides a last chance to modify the updated shape.
Example
onBeforeUpdate = (prev, next) => {
  if (prev.x === next.x) {
    return { ...next, x: next.x + 1 }
  }
}
Parameters
| Name | Description | 
|---|---|
| 
 | The previous shape. | 
| 
 | The next shape. | 
Signature
onBeforeUpdate?: OnBeforeUpdateHandler<T>
References
onChildrenChange
Public Property
A callback called when a shape's children change.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Signature
onChildrenChange?: OnChildrenChangeHandler<T>
References
onClick
Public Property
A callback called when a shape is clicked.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Signature
onClick?: OnClickHandler<T>
References
onDoubleClick
Public Property
A callback called when a shape is double clicked.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Signature
onDoubleClick?: OnDoubleClickHandler<T>
References
onDoubleClickEdge
Public Property
A callback called when a shape's edge is double clicked.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Signature
onDoubleClickEdge?: OnDoubleClickHandler<T>
References
onDoubleClickHandle
Public Property
A callback called when a shape's handle is double clicked.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
| 
 | The handle that is double-clicked. | 
Signature
onDoubleClickHandle?: OnDoubleClickHandleHandler<T>
References
onDragShapesOut
Public Property
A callback called when some other shapes are dragged out of this one.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
| 
 | The shapes that are being dragged out. | 
Signature
onDragShapesOut?: OnDragHandler<T>
References
onDragShapesOver
Public Property
A callback called when some other shapes are dragged over this one.
Example
onDragShapesOver = (shape, shapes) => {
  return { shouldHint: true }
}
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
| 
 | The shapes that are being dragged over this one. | 
Signature
onDragShapesOver?: OnDragHandler<
  T,
  {
    shouldHint: boolean
  }
>
References
onDropShapesOver
Public Property
A callback called when some other shapes are dropped over this one.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
| 
 | The shapes that are being dropped over this one. | 
Signature
onDropShapesOver?: OnDragHandler<T>
References
onEditEnd
Public Property
A callback called when a shape finishes being editing.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Signature
onEditEnd?: OnEditEndHandler<T>
References
onHandleChange
Public Property
A callback called when a shape's handle changes.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
| 
 | An object containing the handle and whether the handle is 'precise' or not. | 
Signature
onHandleChange?: OnHandleChangeHandler<T>
References
onResize
Public Property
A callback called when a shape changes from a resize.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape at the start of the resize. | 
| 
 | Info about the resize. | 
Signature
onResize?: OnResizeHandler<T>
References
onResizeEnd
Public Property
A callback called when a shape finishes resizing.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape at the start of the resize. | 
| 
 | The current shape. | 
Signature
onResizeEnd?: OnResizeEndHandler<T>
References
onResizeStart
Public Property
A callback called when a shape starts being resized.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Signature
onResizeStart?: OnResizeStartHandler<T>
References
onRotate
Public Property
A callback called when a shape changes from a rotation.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape at the start of the rotation. | 
| 
 | The current shape. | 
Signature
onRotate?: OnRotateHandler<T>
References
onRotateEnd
Public Property
A callback called when a shape finishes rotating.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape at the start of the rotation. | 
| 
 | The current shape. | 
Signature
onRotateEnd?: OnRotateEndHandler<T>
References
onRotateStart
Public Property
A callback called when a shape starts being rotated.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Signature
onRotateStart?: OnRotateStartHandler<T>
References
onTranslate
Public Property
A callback called when a shape changes from a translation.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape at the start of the translation. | 
| 
 | The current shape. | 
Signature
onTranslate?: OnTranslateHandler<T>
References
onTranslateEnd
Public Property
A callback called when a shape finishes translating.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape at the start of the translation. | 
| 
 | The current shape. | 
Signature
onTranslateEnd?: OnTranslateEndHandler<T>
References
onTranslateStart
Public Property
A callback called when a shape starts being translated.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Signature
onTranslateStart?: OnTranslateStartHandler<T>
References
type
Public Readonly Property
Signature
readonly type: T['type']
Methods
bounds()
Public Method
Get the cached bounds for the shape.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Returns
Box2d
References
canDropShapes()
Public Method
Get whether the shape can receive children of a given type.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape type. | 
| 
 | The shapes that are being dropped. | 
Returns
boolean
References
canReceiveNewChildrenOfType()
Public Method
Get whether the shape can receive children of a given type.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape type. | 
Returns
boolean
References
center()
Public Method
Get the shape's cached center.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Returns
Vec2dModel
References
defaultProps()
Public Method
Get the default props for a shape.
Parameters
None
Returns
T['props']
getBounds()
Public Method
Get the (not cached) bounds for the shape.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Returns
Box2d
References
getCenter()
Public Method
Get the shape's (not cached) center.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Returns
Vec2dModel
References
getHandles()
Public Method
Get an array of handle models for the shape. This is an optional method.
Example
util.getHandles?.(myShape)
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Returns
TLHandle[]
References
getOutline()
Public Method
Get the shape's (not cached) outline. Do not override this method!
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Returns
Vec2dModel[]
References
handles()
Public Method
Get the cached handles (this should not be overridden!)
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Returns
TLHandle[]
References
hitTestLineSegment()
Public Method
Get whether a point intersects the shape.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
| 
 | The line segment's first point. | 
| 
 | The line segment's second point. | 
Returns
boolean
Whether the line segment intersects the shape.
References
hitTestPoint()
Public Method
Get whether a point intersects the shape.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
| 
 | The point to test. | 
Returns
boolean
Whether the point intersects the shape.
References
indicator()
Public Method
Get JSX describing the shape's indicator (as an SVG element).
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Returns
any
is()
Public Method
Check if a shape is of this type.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape to check. | 
Returns
shape is T
Whether the shape is of this type.
References
outline()
Public Method
Get the shape's outline. Do not override this method!
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Returns
Vec2dModel[]
References
point()
Public Method
Get the cached point. Do not override this method!
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Returns
Vec2dModel
References
render()
Public Method
Get a JSX element for the shape (as an HTML element).
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Returns
any
snapPoints()
Public Method
Get the shape's snap points.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Returns
import('@tldraw/primitives').Vec2d[]
References
toSvg()
Public Method
Get the shape as an SVG object.
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
| 
 | The shape's CSS font (actual). | 
| 
 |  | 
Returns
Promise<SVGElement> | SVGElement
An SVG element.
References
TLExportColors, Promise, SVGElement
transform()
Public Method
Get the cached transform. Do not override this method!
Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Returns
Matrix2d