ShapeUtil
Public Class
Table of Contents
- Properties
- canBind
- canCrop
- canEdit
- canResize
- canScroll
- canUnmount
- editor
- 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
- type
- Methods
Signature
abstract class ShapeUtil<T extends TLUnknownShape = TLUnknownShape> {}
References
Constructor
Public Constructor
Constructs a new instance of the ShapeUtil
class
Parameters
Name | Description |
---|---|
|
|
|
|
References
Properties
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 should unmount when not visible in the editor. Consider keeping this to false if the shape's component
has local state.
Signature
canUnmount: TLShapeUtilFlag<T>
References
editor
Public Property
Signature
editor: Editor
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?: TLOnBeforeCreateHandler<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?: TLOnBeforeUpdateHandler<T>
References
onChildrenChange
Public Property
A callback called when a shape's children change.
Parameters
Name | Description |
---|---|
| The shape. |
Signature
onChildrenChange?: TLOnChildrenChangeHandler<T>
References
onClick
Public Property
A callback called when a shape is clicked.
Parameters
Name | Description |
---|---|
| The shape. |
Signature
onClick?: TLOnClickHandler<T>
References
onDoubleClick
Public Property
A callback called when a shape is double clicked.
Parameters
Name | Description |
---|---|
| The shape. |
Signature
onDoubleClick?: TLOnDoubleClickHandler<T>
References
onDoubleClickEdge
Public Property
A callback called when a shape's edge is double clicked.
Parameters
Name | Description |
---|---|
| The shape. |
Signature
onDoubleClickEdge?: TLOnDoubleClickHandler<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?: TLOnDoubleClickHandleHandler<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?: TLOnDragHandler<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?: TLOnDragHandler<
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?: TLOnDragHandler<T>
References
onEditEnd
Public Property
A callback called when a shape finishes being editing.
Parameters
Name | Description |
---|---|
| The shape. |
Signature
onEditEnd?: TLOnEditEndHandler<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?: TLOnHandleChangeHandler<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?: TLOnResizeHandler<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?: TLOnResizeEndHandler<T>
References
onResizeStart
Public Property
A callback called when a shape starts being resized.
Parameters
Name | Description |
---|---|
| The shape. |
Signature
onResizeStart?: TLOnResizeStartHandler<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?: TLOnRotateHandler<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?: TLOnRotateEndHandler<T>
References
onRotateStart
Public Property
A callback called when a shape starts being rotated.
Parameters
Name | Description |
---|---|
| The shape. |
Signature
onRotateStart?: TLOnRotateStartHandler<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?: TLOnTranslateHandler<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?: TLOnTranslateEndHandler<T>
References
onTranslateStart
Public Property
A callback called when a shape starts being translated.
Parameters
Name | Description |
---|---|
| The shape. |
Signature
onTranslateStart?: TLOnTranslateStartHandler<T>
References
type
Public Readonly Property
Signature
readonly type: T['type']
type
Public Static Property
The type of the shape util, which should match the shape's type.
Signature
static type: string
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
outline()
Public Method
Get the shape's outline. 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
toBackgroundSvg()
Public Method
Get the shape's background layer as an SVG object.
Parameters
Name | Description |
---|---|
|
The shape. |
|
The shape's CSS font (actual). |
|
|
Returns
null | Promise<SVGElement> | SVGElement
An SVG element.
References
TLExportColors, Promise, SVGElement
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