API reference for ranges in Plate.

A Range is a set of points that refer to a specific span of a Plate document. They can define a span inside a single node or span across multiple nodes. A range consists of two points: an anchor (start) and a focus (end).

type TRange = {
  anchor: Point
  focus: Point
}

RangeAPI

transform

Transform a range by an operation.

Parameters

  • range TRange

    The range to transform.

  • op Operation

    The operation to apply to the range.

  • options optional RangeTransformOptions

    Options for transforming the range.

OptionsRangeTransformOptions

Collapse all
  • affinity optional RangeDirection | null

    The direction to prefer when transforming the range.

ReturnsTRange | null

    The transformed range, or null if the range was deleted.

edges

Get the start and end points of a range.

Parameters

Collapse all
  • range TRange

    The range to get edges from.

  • options optional RangeEdgesOptions

    Options for retrieving edges.

OptionsRangeEdgesOptions

Collapse all
  • reverse optional boolean

    If true, returns points in reverse order.

Returns[Point, Point]

    A tuple of points representing the start and end points.

end

Get the end point of a range.

Parameters

Collapse all
  • range TRange

    The range to get the end point from.

ReturnsPoint

    The end point of the range.

equals

Check if two ranges are exactly equal.

Parameters

Collapse all
  • range TRange

    The first range to compare.

  • another TRange

    The second range to compare.

Returnsboolean

    true if the ranges are exactly equal.

includes

Check if a range includes a path, point, or part of another range.

Parameters

Collapse all
  • range TRange

    The range to check.

  • target Path | Point | TRange

    The target to check for inclusion.

Returnsboolean

    true if the range includes the target.

intersection

Get the intersection of two ranges.

Parameters

Collapse all
  • range TRange

    The first range.

  • another TRange

    The second range.

ReturnsTRange | null

    The intersecting range, or null if there is no intersection.

isBackward

Check if a range is backward (anchor point appears after focus point).

Parameters

Collapse all
  • range TRange

    The range to check.

Returnsboolean

    true if the range is backward.

isCollapsed

Check if a range is collapsed (both points refer to the same position).

Parameters

Collapse all
  • range optional TRange | null

    The range to check.

Returnsboolean

    true if the range exists and is collapsed.

isExpanded

Check if a range is expanded (not collapsed).

Parameters

Collapse all
  • range optional TRange | null

    The range to check.

Returnsboolean

    true if the range exists and is expanded.

isForward

Check if a range is forward (anchor point appears before focus point).

Parameters

Collapse all
  • range TRange

    The range to check.

Returnsboolean

    true if the range is forward.

isRange

Check if a value implements the TRange interface.

Parameters

Collapse all
  • value any

    The value to check.

Returnsboolean

    true if the value is a range.

points

Iterate through all point entries in a range.

Parameters

Collapse all
  • range TRange

    The range to iterate through.

ReturnsGenerator<PointEntry, void, undefined>

    A generator that yields point entries.

start

Get the start point of a range.

Parameters

Collapse all
  • range TRange

    The range to get the start point from.

ReturnsPoint

    The start point of the range.

surrounds

Check if a range completely surrounds another range.

Parameters

Collapse all
  • range TRange

    The range that might surround the target.

  • target TRange

    The target range that might be surrounded.

Returnsboolean

    true if the range surrounds the target.

Types

TRange

TRange objects are a set of points that refer to a specific span of a Plate document. They can define a span inside a single node or span across multiple nodes.

Range is a type alias for TRange.

Attributes

Collapse all
  • anchor Point

    The start point of the range.

  • focus Point

    The end point of the range.