Skip to content

Type Editor


Type Editor / @type-editor/changeset / Span / Span

Class: Span<Data>

Defined in: Span.ts:12

Stores metadata for a part of a change.

A Span represents a contiguous range in a document with associated metadata. Spans are immutable and can be sliced, joined, or cut to create new spans.

Type Parameters

Type ParameterDefault typeDescription
DataanyThe type of metadata associated with this span.

Constructors

Constructor

ts
new Span<Data>(length, data): Span<Data>;

Defined in: Span.ts:26

Creates a new Span with the specified length and associated data.

Parameters

ParameterTypeDescription
lengthnumberThe length of this span (must be non-negative).
dataDataThe metadata associated with this span.

Returns

Span<Data>

Properties

PropertyModifierTypeDefault valueDescriptionDefined in
nonereadonlyreadonly Span<any>[][]An empty span array constant to avoid allocations.Span.ts:15

Accessors

data

Get Signature

ts
get data(): Data;

Defined in: Span.ts:37

Returns the metadata associated with this span.

Returns

Data


length

Get Signature

ts
get length(): number;

Defined in: Span.ts:32

Returns the length of this span.

Returns

number

Methods

join()

ts
static join<Data>(
   spanListA,
   spanListB,
   combine): readonly Span<Data>[];

Defined in: Span.ts:120

Joins two span arrays, potentially combining adjacent spans at the boundary.

When the last span of the first array and the first span of the second array meet, the combine function is called. If it returns a value, those spans are merged into a single span with the combined data.

Type Parameters

Type ParameterDescription
DataThe type of metadata in the spans.

Parameters

ParameterTypeDescription
spanListAreadonly Span<Data>[]The first array of spans.
spanListBreadonly Span<Data>[]The second array of spans.
combine(dataA, dataB) => DataFunction to combine the data of adjacent spans. Returns the combined data, or null/undefined if spans should not be merged.

Returns

readonly Span<Data>[]

A new array containing the joined spans.


slice()

ts
static slice<Data>(
   spans,
   from,
   to): readonly Span<Data>[];

Defined in: Span.ts:65

Slices a range from an array of spans.

This extracts a sub-range from a span array, potentially cutting spans that partially overlap with the range boundaries.

Type Parameters

Type ParameterDescription
DataThe type of metadata in the spans.

Parameters

ParameterTypeDescription
spansreadonly Span<Data>[]The array of spans to slice from.
fromnumberThe start position (inclusive).
tonumberThe end position (exclusive).

Returns

readonly Span<Data>[]

A new array containing the spans within the specified range.