GeoShapeUtil
See source codeTable of contents
- migrations
- props
- type
- editor
- Properties
- Methods
- canBeLaidOut
- canBind
- canCrop
- canDropShapes
- canEdit
- canEditInReadOnly
- canReceiveNewChildrenOfType
- canResize
- canScroll
- canSnap
- component
- getBoundsSnapGeometry
- getCanvasSvgDefs
- getDefaultProps
- getGeometry
- getHandles
- getHandleSnapGeometry
- getInterpolatedProps
- getText
- hideResizeHandles
- hideRotateHandle
- hideSelectionBoundsBg
- hideSelectionBoundsFg
- indicator
- isAspectRatioLocked
- onBeforeCreate
- onBeforeUpdate
- onChildrenChange
- onClick
- onDoubleClick
- onDoubleClickEdge
- onDoubleClickHandle
- onDragShapesOut
- onDragShapesOver
- onDropShapesOver
- onEditEnd
- onHandleDrag
- onResize
- onResizeEnd
- onResizeStart
- onRotate
- onRotateEnd
- onRotateStart
- onTranslate
- onTranslateEnd
- onTranslateStart
- toBackgroundSvg
- toSvg
 
Extends BaseBoxShapeUtil<TLGeoShape>.
class GeoShapeUtil extends BaseBoxShapeUtil<TLGeoShape> {}Constructor
Constructs a new instance of the ShapeUtil class
Parameters
| Name | Description | 
|---|---|
| 
 | 
Properties
migrations
static migrations: import('@tldraw/editor').TLPropsMigrationsprops
static props: import('@tldraw/editor').RecordProps<TLGeoShape>type
static type: 'geo'editor
editor: EditorMethods
canBeLaidOut()
Whether the shape participates in stacking, aligning, and distributing.
canBeLaidOut(_shape: Shape): booleanParameters
| Name | Description | 
|---|---|
| 
 |  | 
Returns
booleancanBind()
Whether the shape can be bound to. See TLShapeUtilCanBindOpts for details.
canBind(_opts: TLShapeUtilCanBindOpts<Shape>): booleanParameters
| Name | Description | 
|---|---|
| 
 |  | 
Returns
booleancanCrop()
Whether the shape can be cropped.
canCrop(_shape: Shape): booleanParameters
| Name | Description | 
|---|---|
| 
 |  | 
Returns
booleancanDropShapes()
Get whether the shape can receive children of a given type.
canDropShapes(_shape: Shape, _shapes: TLShape[]): booleanParameters
| Name | Description | 
|---|---|
| 
 |  | 
| 
 |  | 
Returns
booleancanEdit()
canEdit(): booleancanEditInReadOnly()
Whether the shape can be edited in read-only mode.
canEditInReadOnly(_shape: Shape): booleanParameters
| Name | Description | 
|---|---|
| 
 |  | 
Returns
booleancanReceiveNewChildrenOfType()
Get whether the shape can receive children of a given type.
canReceiveNewChildrenOfType(_shape: Shape, _type: TLShape['type']): booleanParameters
| Name | Description | 
|---|---|
| 
 |  | 
| 
 |  | 
Returns
booleancanResize()
Whether the shape can be resized.
canResize(_shape: Shape): booleanParameters
| Name | Description | 
|---|---|
| 
 |  | 
Returns
booleancanScroll()
Whether the shape can be scrolled while editing.
canScroll(_shape: Shape): booleanParameters
| Name | Description | 
|---|---|
| 
 |  | 
Returns
booleancanSnap()
Whether the shape can be snapped to by another shape.
canSnap(_shape: Shape): booleanParameters
| Name | Description | 
|---|---|
| 
 |  | 
Returns
booleancomponent()
component(shape: TLGeoShape): import('react/jsx-runtime').JSX.ElementParameters
| Name | Description | 
|---|---|
| 
 | 
Returns
import('react/jsx-runtime').JSX.ElementgetBoundsSnapGeometry()
Get the geometry to use when snapping to this this shape in translate/resize operations. See BoundsSnapGeometry for details.
getBoundsSnapGeometry(_shape: Shape): BoundsSnapGeometryParameters
| Name | Description | 
|---|---|
| 
 |  | 
Returns
getCanvasSvgDefs()
getCanvasSvgDefs(): TLShapeUtilCanvasSvgDef[]getDefaultProps()
getDefaultProps(): TLGeoShape['props']getGeometry()
getGeometry(shape: TLGeoShape): Group2dParameters
| Name | Description | 
|---|---|
| 
 | 
Returns
getHandles()
Get an array of handle models for the shape. This is an optional method.
getHandles?(shape: Shape): TLHandle[]Example
util.getHandles?.(myShape)Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Returns
TLHandle[]getHandleSnapGeometry()
getHandleSnapGeometry(shape: TLGeoShape): HandleSnapGeometryParameters
| Name | Description | 
|---|---|
| 
 | 
Returns
getInterpolatedProps()
getInterpolatedProps(
  startShape: TLGeoShape,
  endShape: TLGeoShape,
  t: number
): TLGeoShapePropsParameters
| Name | Description | 
|---|---|
| 
 | |
| 
 | |
| 
 |  | 
Returns
getText()
getText(shape: TLGeoShape): string | undefinedParameters
| Name | Description | 
|---|---|
| 
 | 
Returns
string | undefinedhideResizeHandles()
Whether the shape should hide its resize handles when selected.
hideResizeHandles(_shape: Shape): booleanParameters
| Name | Description | 
|---|---|
| 
 |  | 
Returns
booleanhideRotateHandle()
Whether the shape should hide its rotation handles when selected.
hideRotateHandle(_shape: Shape): booleanParameters
| Name | Description | 
|---|---|
| 
 |  | 
Returns
booleanhideSelectionBoundsBg()
Whether the shape should hide its selection bounds background when selected.
hideSelectionBoundsBg(_shape: Shape): booleanParameters
| Name | Description | 
|---|---|
| 
 |  | 
Returns
booleanhideSelectionBoundsFg()
Whether the shape should hide its selection bounds foreground when selected.
hideSelectionBoundsFg(_shape: Shape): booleanParameters
| Name | Description | 
|---|---|
| 
 |  | 
Returns
booleanindicator()
indicator(shape: TLGeoShape): import('react/jsx-runtime').JSX.ElementParameters
| Name | Description | 
|---|---|
| 
 | 
Returns
import('react/jsx-runtime').JSX.ElementisAspectRatioLocked()
Whether the shape's aspect ratio is locked.
isAspectRatioLocked(_shape: Shape): booleanParameters
| Name | Description | 
|---|---|
| 
 |  | 
Returns
booleanonBeforeCreate()
onBeforeCreate(shape: TLGeoShape):
  | {
      id: import('@tldraw/editor').TLShapeId
      index: import('@tldraw/editor').IndexKey
      isLocked: boolean
      meta: import('@tldraw/editor').JsonObject
      opacity: number
      parentId: import('@tldraw/editor').TLParentId
      props: {
        align:
          | 'end-legacy'
          | 'end'
          | 'middle-legacy'
          | 'middle'
          | 'start-legacy'
          | 'start'
        color:
          | 'black'
          | 'blue'
          | 'green'
          | 'grey'
          | 'light-blue'
          | 'light-green'
          | 'light-red'
          | 'light-violet'
          | 'orange'
          | 'red'
          | 'violet'
          | 'white'
          | 'yellow'
        dash: 'dashed' | 'dotted' | 'draw' | 'solid'
        fill: 'fill' | 'none' | 'pattern' | 'semi' | 'solid'
        font: 'draw' | 'mono' | 'sans' | 'serif'
        geo:
          | 'arrow-down'
          | 'arrow-left'
          | 'arrow-right'
          | 'arrow-up'
          | 'check-box'
          | 'cloud'
          | 'diamond'
          | 'ellipse'
          | 'heart'
          | 'hexagon'
          | 'octagon'
          | 'oval'
          | 'pentagon'
          | 'rectangle'
          | 'rhombus-2'
          | 'rhombus'
          | 'star'
          | 'trapezoid'
          | 'triangle'
          | 'x-box'
        growY: number
        h: number
        labelColor:
          | 'black'
          | 'blue'
          | 'green'
          | 'grey'
          | 'light-blue'
          | 'light-green'
          | 'light-red'
          | 'light-violet'
          | 'orange'
          | 'red'
          | 'violet'
          | 'white'
          | 'yellow'
        richText?:
          | {
              content: unknown[]
              type: string
            }
          | undefined
        scale: number
        size: 'l' | 'm' | 's' | 'xl'
        url: string
        verticalAlign: 'end' | 'middle' | 'start'
        w: number
      }
      rotation: number
      type: 'geo'
      typeName: 'shape'
      x: number
      y: number
    }
  | undefinedParameters
| Name | Description | 
|---|---|
| 
 | 
Returns
  | {
      id: import('@tldraw/editor').TLShapeId
      index: import('@tldraw/editor').IndexKey
      isLocked: boolean
      meta: import('@tldraw/editor').JsonObject
      opacity: number
      parentId: import('@tldraw/editor').TLParentId
      props: {
        align:
          | 'end-legacy'
          | 'end'
          | 'middle-legacy'
          | 'middle'
          | 'start-legacy'
          | 'start'
        color:
          | 'black'
          | 'blue'
          | 'green'
          | 'grey'
          | 'light-blue'
          | 'light-green'
          | 'light-red'
          | 'light-violet'
          | 'orange'
          | 'red'
          | 'violet'
          | 'white'
          | 'yellow'
        dash: 'dashed' | 'dotted' | 'draw' | 'solid'
        fill: 'fill' | 'none' | 'pattern' | 'semi' | 'solid'
        font: 'draw' | 'mono' | 'sans' | 'serif'
        geo:
          | 'arrow-down'
          | 'arrow-left'
          | 'arrow-right'
          | 'arrow-up'
          | 'check-box'
          | 'cloud'
          | 'diamond'
          | 'ellipse'
          | 'heart'
          | 'hexagon'
          | 'octagon'
          | 'oval'
          | 'pentagon'
          | 'rectangle'
          | 'rhombus-2'
          | 'rhombus'
          | 'star'
          | 'trapezoid'
          | 'triangle'
          | 'x-box'
        growY: number
        h: number
        labelColor:
          | 'black'
          | 'blue'
          | 'green'
          | 'grey'
          | 'light-blue'
          | 'light-green'
          | 'light-red'
          | 'light-violet'
          | 'orange'
          | 'red'
          | 'violet'
          | 'white'
          | 'yellow'
        richText?:
          | {
              content: unknown[]
              type: string
            }
          | undefined
        scale: number
        size: 'l' | 'm' | 's' | 'xl'
        url: string
        verticalAlign: 'end' | 'middle' | 'start'
        w: number
      }
      rotation: number
      type: 'geo'
      typeName: 'shape'
      x: number
      y: number
    }
  | undefinedonBeforeUpdate()
onBeforeUpdate(
  prev: TLGeoShape,
  next: TLGeoShape
):
  | {
      id: import('@tldraw/editor').TLShapeId
      index: import('@tldraw/editor').IndexKey
      isLocked: boolean
      meta: import('@tldraw/editor').JsonObject
      opacity: number
      parentId: import('@tldraw/editor').TLParentId
      props: {
        align:
          | 'end-legacy'
          | 'end'
          | 'middle-legacy'
          | 'middle'
          | 'start-legacy'
          | 'start'
        color:
          | 'black'
          | 'blue'
          | 'green'
          | 'grey'
          | 'light-blue'
          | 'light-green'
          | 'light-red'
          | 'light-violet'
          | 'orange'
          | 'red'
          | 'violet'
          | 'white'
          | 'yellow'
        dash: 'dashed' | 'dotted' | 'draw' | 'solid'
        fill: 'fill' | 'none' | 'pattern' | 'semi' | 'solid'
        font: 'draw' | 'mono' | 'sans' | 'serif'
        geo:
          | 'arrow-down'
          | 'arrow-left'
          | 'arrow-right'
          | 'arrow-up'
          | 'check-box'
          | 'cloud'
          | 'diamond'
          | 'ellipse'
          | 'heart'
          | 'hexagon'
          | 'octagon'
          | 'oval'
          | 'pentagon'
          | 'rectangle'
          | 'rhombus-2'
          | 'rhombus'
          | 'star'
          | 'trapezoid'
          | 'triangle'
          | 'x-box'
        growY: number
        h: number
        labelColor:
          | 'black'
          | 'blue'
          | 'green'
          | 'grey'
          | 'light-blue'
          | 'light-green'
          | 'light-red'
          | 'light-violet'
          | 'orange'
          | 'red'
          | 'violet'
          | 'white'
          | 'yellow'
        richText?:
          | {
              content: unknown[]
              type: string
            }
          | undefined
        scale: number
        size: 'l' | 'm' | 's' | 'xl'
        url: string
        verticalAlign: 'end' | 'middle' | 'start'
        w: number
      }
      rotation: number
      type: 'geo'
      typeName: 'shape'
      x: number
      y: number
    }
  | undefinedParameters
| Name | Description | 
|---|---|
| 
 | |
| 
 | 
Returns
  | {
      id: import('@tldraw/editor').TLShapeId
      index: import('@tldraw/editor').IndexKey
      isLocked: boolean
      meta: import('@tldraw/editor').JsonObject
      opacity: number
      parentId: import('@tldraw/editor').TLParentId
      props: {
        align:
          | 'end-legacy'
          | 'end'
          | 'middle-legacy'
          | 'middle'
          | 'start-legacy'
          | 'start'
        color:
          | 'black'
          | 'blue'
          | 'green'
          | 'grey'
          | 'light-blue'
          | 'light-green'
          | 'light-red'
          | 'light-violet'
          | 'orange'
          | 'red'
          | 'violet'
          | 'white'
          | 'yellow'
        dash: 'dashed' | 'dotted' | 'draw' | 'solid'
        fill: 'fill' | 'none' | 'pattern' | 'semi' | 'solid'
        font: 'draw' | 'mono' | 'sans' | 'serif'
        geo:
          | 'arrow-down'
          | 'arrow-left'
          | 'arrow-right'
          | 'arrow-up'
          | 'check-box'
          | 'cloud'
          | 'diamond'
          | 'ellipse'
          | 'heart'
          | 'hexagon'
          | 'octagon'
          | 'oval'
          | 'pentagon'
          | 'rectangle'
          | 'rhombus-2'
          | 'rhombus'
          | 'star'
          | 'trapezoid'
          | 'triangle'
          | 'x-box'
        growY: number
        h: number
        labelColor:
          | 'black'
          | 'blue'
          | 'green'
          | 'grey'
          | 'light-blue'
          | 'light-green'
          | 'light-red'
          | 'light-violet'
          | 'orange'
          | 'red'
          | 'violet'
          | 'white'
          | 'yellow'
        richText?:
          | {
              content: unknown[]
              type: string
            }
          | undefined
        scale: number
        size: 'l' | 'm' | 's' | 'xl'
        url: string
        verticalAlign: 'end' | 'middle' | 'start'
        w: number
      }
      rotation: number
      type: 'geo'
      typeName: 'shape'
      x: number
      y: number
    }
  | undefinedonChildrenChange()
A callback called when a shape's children change.
onChildrenChange?(shape: Shape): TLShapePartial[] | voidParameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Returns
TLShapePartial[] | voidAn array of shape updates, or void.
onClick()
A callback called when a shape is clicked.
onClick?(shape: Shape): TLShapePartial<Shape> | voidParameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Returns
TLShapePartial<Shape> | voidA change to apply to the shape, or void.
onDoubleClick()
onDoubleClick(shape: TLGeoShape):
  | {
      id: import('@tldraw/editor').TLShapeId
      index: import('@tldraw/editor').IndexKey
      isLocked: boolean
      meta: import('@tldraw/editor').JsonObject
      opacity: number
      parentId: import('@tldraw/editor').TLParentId
      props: {
        geo: 'check-box'
      }
      rotation: number
      type: 'geo'
      typeName: 'shape'
      x: number
      y: number
    }
  | {
      id: import('@tldraw/editor').TLShapeId
      index: import('@tldraw/editor').IndexKey
      isLocked: boolean
      meta: import('@tldraw/editor').JsonObject
      opacity: number
      parentId: import('@tldraw/editor').TLParentId
      props: {
        geo: 'rectangle'
      }
      rotation: number
      type: 'geo'
      typeName: 'shape'
      x: number
      y: number
    }
  | undefinedParameters
| Name | Description | 
|---|---|
| 
 | 
Returns
  | {
      id: import('@tldraw/editor').TLShapeId
      index: import('@tldraw/editor').IndexKey
      isLocked: boolean
      meta: import('@tldraw/editor').JsonObject
      opacity: number
      parentId: import('@tldraw/editor').TLParentId
      props: {
        geo: 'check-box'
      }
      rotation: number
      type: 'geo'
      typeName: 'shape'
      x: number
      y: number
    }
  | {
      id: import('@tldraw/editor').TLShapeId
      index: import('@tldraw/editor').IndexKey
      isLocked: boolean
      meta: import('@tldraw/editor').JsonObject
      opacity: number
      parentId: import('@tldraw/editor').TLParentId
      props: {
        geo: 'rectangle'
      }
      rotation: number
      type: 'geo'
      typeName: 'shape'
      x: number
      y: number
    }
  | undefinedonDoubleClickEdge()
A callback called when a shape's edge is double clicked.
onDoubleClickEdge?(shape: Shape): TLShapePartial<Shape> | voidParameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Returns
TLShapePartial<Shape> | voidA change to apply to the shape, or void.
onDoubleClickHandle()
A callback called when a shape's handle is double clicked.
onDoubleClickHandle?(
  shape: Shape,
  handle: TLHandle
): TLShapePartial<Shape> | voidParameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
| 
 | The handle that is double-clicked. | 
Returns
TLShapePartial<Shape> | voidA change to apply to the shape, or void.
onDragShapesOut()
A callback called when some other shapes are dragged out of this one.
onDragShapesOut?(shape: Shape, shapes: TLShape[]): voidParameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
| 
 | The shapes that are being dragged out. | 
Returns
voidonDragShapesOver()
A callback called when some other shapes are dragged over this one.
onDragShapesOver?(shape: Shape, shapes: TLShape[]): voidExample
onDragShapesOver = (shape, shapes) => {
  this.editor.reparentShapes(shapes, shape.id)
}Parameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
| 
 | The shapes that are being dragged over this one. | 
Returns
voidonDropShapesOver()
A callback called when some other shapes are dropped over this one.
onDropShapesOver?(shape: Shape, shapes: TLShape[]): voidParameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
| 
 | The shapes that are being dropped over this one. | 
Returns
voidonEditEnd()
A callback called when a shape finishes being editing.
onEditEnd?(shape: Shape): voidParameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Returns
voidonHandleDrag()
A callback called when a shape's handle changes.
onHandleDrag?(
  shape: Shape,
  info: TLHandleDragInfo<Shape>
): TLShapePartial<Shape> | voidParameters
| Name | Description | 
|---|---|
| 
 | The current shape. | 
| 
 | An object containing the handle and whether the handle is 'precise' or not. | 
Returns
TLShapePartial<Shape> | voidA change to apply to the shape, or void.
onResize()
onResize(
  shape: TLGeoShape,
  { handle, newPoint, scaleX, scaleY, initialShape }: TLResizeInfo<TLGeoShape>
): {
  props: {
    growY: number
    h: number
    w: number
  }
  x: number
  y: number
}Parameters
| Name | Description | 
|---|---|
| 
 | |
| 
 | 
Returns
{
  props: {
    growY: number
    h: number
    w: number
  }
  x: number
  y: number
}onResizeEnd()
A callback called when a shape finishes resizing.
onResizeEnd?(initial: Shape, current: Shape): TLShapePartial<Shape> | voidParameters
| Name | Description | 
|---|---|
| 
 | The shape at the start of the resize. | 
| 
 | The current shape. | 
Returns
TLShapePartial<Shape> | voidA change to apply to the shape, or void.
onResizeStart()
A callback called when a shape starts being resized.
onResizeStart?(shape: Shape): TLShapePartial<Shape> | voidParameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Returns
TLShapePartial<Shape> | voidA change to apply to the shape, or void.
onRotate()
A callback called when a shape changes from a rotation.
onRotate?(initial: Shape, current: Shape): TLShapePartial<Shape> | voidParameters
| Name | Description | 
|---|---|
| 
 | The shape at the start of the rotation. | 
| 
 | The current shape. | 
Returns
TLShapePartial<Shape> | voidA change to apply to the shape, or void.
onRotateEnd()
A callback called when a shape finishes rotating.
onRotateEnd?(initial: Shape, current: Shape): TLShapePartial<Shape> | voidParameters
| Name | Description | 
|---|---|
| 
 | The shape at the start of the rotation. | 
| 
 | The current shape. | 
Returns
TLShapePartial<Shape> | voidA change to apply to the shape, or void.
onRotateStart()
A callback called when a shape starts being rotated.
onRotateStart?(shape: Shape): TLShapePartial<Shape> | voidParameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Returns
TLShapePartial<Shape> | voidA change to apply to the shape, or void.
onTranslate()
A callback called when a shape changes from a translation.
onTranslate?(initial: Shape, current: Shape): TLShapePartial<Shape> | voidParameters
| Name | Description | 
|---|---|
| 
 | The shape at the start of the translation. | 
| 
 | The current shape. | 
Returns
TLShapePartial<Shape> | voidA change to apply to the shape, or void.
onTranslateEnd()
A callback called when a shape finishes translating.
onTranslateEnd?(initial: Shape, current: Shape): TLShapePartial<Shape> | voidParameters
| Name | Description | 
|---|---|
| 
 | The shape at the start of the translation. | 
| 
 | The current shape. | 
Returns
TLShapePartial<Shape> | voidA change to apply to the shape, or void.
onTranslateStart()
A callback called when a shape starts being translated.
onTranslateStart?(shape: Shape): TLShapePartial<Shape> | voidParameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
Returns
TLShapePartial<Shape> | voidA change to apply to the shape, or void.
toBackgroundSvg()
Get the shape's background layer as an SVG object.
toBackgroundSvg?(
  shape: Shape,
  ctx: SvgExportContext
): null | Promise<null | ReactElement> | ReactElementParameters
| Name | Description | 
|---|---|
| 
 | The shape. | 
| 
 | ctx - The export context for the SVG - used for adding e.g. <def>s | 
Returns
null | Promise<null | ReactElement> | ReactElementAn SVG element.
toSvg()
toSvg(
  shape: TLGeoShape,
  ctx: SvgExportContext
): import('react/jsx-runtime').JSX.ElementParameters
| Name | Description | 
|---|---|
| 
 | |
| 
 | 
Returns
import('react/jsx-runtime').JSX.Element