Table of contents

Public class

Signature
abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {}
References

TLUnknownShape

Source

packages/editor/src/lib/editor/shapes/ShapeUtil.ts


Constructor

Public constructor

Constructs a new instance of the ShapeUtil class

Parameters
NameDescription

editor

Editor
References

Editor


Properties

canBind

Public property

Whether the shape can be bound to by an arrow.

Signature
canBind: <K>(_shape: Shape, _otherShape?: K) => boolean
Parameters
NameDescription

_otherShape

The other shape attempting to bind to this shape.


canCrop

Public property

Whether the shape can be cropped.

Signature
canCrop: TLShapeUtilFlag<Shape>
References

TLShapeUtilFlag


canEdit

Public property

Whether the shape can be double clicked to edit.

Signature
canEdit: TLShapeUtilFlag<Shape>
References

TLShapeUtilFlag


canEditInReadOnly

Public property

Whether the shape can be edited in read-only mode.

Signature
canEditInReadOnly: TLShapeUtilFlag<Shape>
References

TLShapeUtilFlag


canResize

Public property

Whether the shape can be resized.

Signature
canResize: TLShapeUtilFlag<Shape>
References

TLShapeUtilFlag


canScroll

Public property

Whether the shape can be scrolled while editing.

Signature
canScroll: TLShapeUtilFlag<Shape>
References

TLShapeUtilFlag


canSnap

Public property

Whether the shape can be snapped to by another shape.

Signature
canSnap: TLShapeUtilFlag<Shape>
References

TLShapeUtilFlag


editor

Public property

Signature
editor: Editor
References

Editor


hideResizeHandles

Public property

Whether the shape should hide its resize handles when selected.

Signature
hideResizeHandles: TLShapeUtilFlag<Shape>
References

TLShapeUtilFlag


hideRotateHandle

Public property

Whether the shape should hide its rotation handles when selected.

Signature
hideRotateHandle: TLShapeUtilFlag<Shape>
References

TLShapeUtilFlag


hideSelectionBoundsBg

Public property

Whether the shape should hide its selection bounds background when selected.

Signature
hideSelectionBoundsBg: TLShapeUtilFlag<Shape>
References

TLShapeUtilFlag


hideSelectionBoundsFg

Public property

Whether the shape should hide its selection bounds foreground when selected.

Signature
hideSelectionBoundsFg: TLShapeUtilFlag<Shape>
References

TLShapeUtilFlag


isAspectRatioLocked

Public property

Whether the shape's aspect ratio is locked.

Signature
isAspectRatioLocked: TLShapeUtilFlag<Shape>
References

TLShapeUtilFlag


migrations

Public static property

Signature
static migrations?: LegacyMigrations | TLShapePropsMigrations
References

LegacyMigrations, TLShapePropsMigrations


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 }
}
Signature
onBeforeCreate?: TLOnBeforeCreateHandler<Shape>
Parameters
NameDescription

next

The next shape.

References

TLOnBeforeCreateHandler


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 }
  }
}
Signature
onBeforeUpdate?: TLOnBeforeUpdateHandler<Shape>
Parameters
NameDescription

prev

The previous shape.

next

The next shape.

References

TLOnBeforeUpdateHandler


onChildrenChange

Public property

A callback called when a shape's children change.

Signature
onChildrenChange?: TLOnChildrenChangeHandler<Shape>
Parameters
NameDescription

shape

The shape.

References

TLOnChildrenChangeHandler


onClick

Public property

A callback called when a shape is clicked.

Signature
onClick?: TLOnClickHandler<Shape>
Parameters
NameDescription

shape

The shape.

References

TLOnClickHandler


onDoubleClick

Public property

A callback called when a shape is double clicked.

Signature
onDoubleClick?: TLOnDoubleClickHandler<Shape>
Parameters
NameDescription

shape

The shape.

References

TLOnDoubleClickHandler


onDoubleClickEdge

Public property

A callback called when a shape's edge is double clicked.

Signature
onDoubleClickEdge?: TLOnDoubleClickHandler<Shape>
Parameters
NameDescription

shape

The shape.

References

TLOnDoubleClickHandler


onDoubleClickHandle

Public property

A callback called when a shape's handle is double clicked.

Signature
onDoubleClickHandle?: TLOnDoubleClickHandleHandler<Shape>
Parameters
NameDescription

shape

The shape.

handle

The handle that is double-clicked.

References

TLOnDoubleClickHandleHandler


onDragShapesOut

Public property

A callback called when some other shapes are dragged out of this one.

Signature
onDragShapesOut?: TLOnDragHandler<Shape>
Parameters
NameDescription

shape

The shape.

shapes

The shapes that are being dragged out.

References

TLOnDragHandler


onDragShapesOver

Public property

A callback called when some other shapes are dragged over this one.

Example
onDragShapesOver = (shape, shapes) => {
  this.editor.reparentShapes(shapes, shape.id)
}
Signature
onDragShapesOver?: TLOnDragHandler<Shape>
Parameters
NameDescription

shape

The shape.

shapes

The shapes that are being dragged over this one.

References

TLOnDragHandler


onDropShapesOver

Public property

A callback called when some other shapes are dropped over this one.

Signature
onDropShapesOver?: TLOnDragHandler<Shape>
Parameters
NameDescription

shape

The shape.

shapes

The shapes that are being dropped over this one.

References

TLOnDragHandler


onEditEnd

Public property

A callback called when a shape finishes being editing.

Signature
onEditEnd?: TLOnEditEndHandler<Shape>
Parameters
NameDescription

shape

The shape.

References

TLOnEditEndHandler


onHandleDrag

Public property

A callback called when a shape's handle changes.

Signature
onHandleDrag?: TLOnHandleDragHandler<Shape>
Parameters
NameDescription

shape

The current shape.

info

An object containing the handle and whether the handle is 'precise' or not.

References

TLOnHandleDragHandler


onResize

Public property

A callback called when a shape changes from a resize.

Signature
onResize?: TLOnResizeHandler<Shape>
Parameters
NameDescription

shape

The shape at the start of the resize.

info

Info about the resize.

References

TLOnResizeHandler


onResizeEnd

Public property

A callback called when a shape finishes resizing.

Signature
onResizeEnd?: TLOnResizeEndHandler<Shape>
Parameters
NameDescription

initial

The shape at the start of the resize.

current

The current shape.

References

TLOnResizeEndHandler


onResizeStart

Public property

A callback called when a shape starts being resized.

Signature
onResizeStart?: TLOnResizeStartHandler<Shape>
Parameters
NameDescription

shape

The shape.

References

TLOnResizeStartHandler


onRotate

Public property

A callback called when a shape changes from a rotation.

Signature
onRotate?: TLOnRotateHandler<Shape>
Parameters
NameDescription

initial

The shape at the start of the rotation.

current

The current shape.

References

TLOnRotateHandler


onRotateEnd

Public property

A callback called when a shape finishes rotating.

Signature
onRotateEnd?: TLOnRotateEndHandler<Shape>
Parameters
NameDescription

initial

The shape at the start of the rotation.

current

The current shape.

References

TLOnRotateEndHandler


onRotateStart

Public property

A callback called when a shape starts being rotated.

Signature
onRotateStart?: TLOnRotateStartHandler<Shape>
Parameters
NameDescription

shape

The shape.

References

TLOnRotateStartHandler


onTranslate

Public property

A callback called when a shape changes from a translation.

Signature
onTranslate?: TLOnTranslateHandler<Shape>
Parameters
NameDescription

initial

The shape at the start of the translation.

current

The current shape.

References

TLOnTranslateHandler


onTranslateEnd

Public property

A callback called when a shape finishes translating.

Signature
onTranslateEnd?: TLOnTranslateEndHandler<Shape>
Parameters
NameDescription

initial

The shape at the start of the translation.

current

The current shape.

References

TLOnTranslateEndHandler


onTranslateStart

Public property

A callback called when a shape starts being translated.

Signature
onTranslateStart?: TLOnTranslateStartHandler<Shape>
Parameters
NameDescription

shape

The shape.

References

TLOnTranslateStartHandler


props

Public static property

Signature
static props?: ShapeProps<TLUnknownShape>
References

ShapeProps, TLUnknownShape


type

Public static property

The type of the shape util, which should match the shape's type.

Signature
static type: string

Methods

canDropShapes()

Public method

Get whether the shape can receive children of a given type.

Signature
canDropShapes(shape: Shape, shapes: TLShape[]): boolean
Parameters
NameDescription

shape

Shape

The shape type.

shapes

TLShape[]

The shapes that are being dropped.

Returns
boolean
References

TLShape


canReceiveNewChildrenOfType()

Public method

Get whether the shape can receive children of a given type.

Signature
canReceiveNewChildrenOfType(shape: Shape, type: TLShape['type']): boolean
Parameters
NameDescription

shape

Shape

type

TLShape['type']

The shape type.

Returns
boolean
References

TLShape


component()

Public method

Get a JSX element for the shape (as an HTML element).

Signature
abstract component(shape: Shape): any
Parameters
NameDescription

shape

Shape

The shape.

Returns
any

getBoundsSnapGeometry()

Public method

Get the geometry to use when snapping to this this shape in translate/resize operations. See BoundsSnapGeometry for details.

Signature
getBoundsSnapGeometry(shape: Shape): BoundsSnapGeometry
Parameters
NameDescription

shape

Shape
Returns
BoundsSnapGeometry
References

BoundsSnapGeometry


getCanvasSvgDefs()

Public method

Return elements to be added to the <defs> section of the canvases SVG context. This can be used to define SVG content (e.g. patterns & masks) that can be referred to by ID from svg elements returned by component.

Each def should have a unique key. If multiple defs from different shapes all have the same key, only one will be used.

Signature
getCanvasSvgDefs(): TLShapeUtilCanvasSvgDef[]
References

TLShapeUtilCanvasSvgDef


getDefaultProps()

Public method

Get the default props for a shape.

Signature
abstract getDefaultProps(): Shape['props']

getGeometry()

Public method

Get the shape's geometry.

Signature
abstract getGeometry(shape: Shape): Geometry2d
Parameters
NameDescription

shape

Shape

The shape.

Returns
Geometry2d
References

Geometry2d


getHandles()

Public method

Get an array of handle models for the shape. This is an optional method.

Example
util.getHandles?.(myShape)
Signature
getHandles?(shape: Shape): TLHandle[]
Parameters
NameDescription

shape

Shape

The shape.

Returns
TLHandle[]
References

TLHandle


getHandleSnapGeometry()

Public method

Get the geometry to use when snapping handles to this shape. See HandleSnapGeometry for details.

Signature
getHandleSnapGeometry(shape: Shape): HandleSnapGeometry
Parameters
NameDescription

shape

Shape
Returns
HandleSnapGeometry
References

HandleSnapGeometry


indicator()

Public method

Get JSX describing the shape's indicator (as an SVG element).

Signature
abstract indicator(shape: Shape): any
Parameters
NameDescription

shape

Shape

The shape.

Returns
any

toBackgroundSvg()

Public method

Get the shape's background layer as an SVG object.

Signature
toBackgroundSvg?(
  shape: Shape,
  ctx: SvgExportContext
): null | Promise<null | ReactElement> | ReactElement
Parameters
NameDescription

shape

Shape

The shape.

ctx

SvgExportContext

ctx - The export context for the SVG - used for adding e.g. <def>s

Returns
null | Promise<null | ReactElement> | ReactElement

An SVG element.

References

SvgExportContext


toSvg()

Public method

Get the shape as an SVG object.

Signature
toSvg?(
  shape: Shape,
  ctx: SvgExportContext
): null | Promise<null | ReactElement> | ReactElement
Parameters
NameDescription

shape

Shape

The shape.

ctx

SvgExportContext

The export context for the SVG - used for adding e.g. <def>s

Returns
null | Promise<null | ReactElement> | ReactElement

An SVG element.

References

SvgExportContext


setUserPreferencesSharedStyle