Type Editor / @type-editor/changeset / Change / Change
Class: Change<Data>
Defined in: Change.ts:34
Represents a change between two document versions with metadata.
A Change tracks a replaced range in the document, including both what was deleted from the old version and what was inserted in the new version. It uses two coordinate systems:
- A coordinates: positions in the old document
- B coordinates: positions in the new document
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
Data | any | The type of metadata associated with the changed content. |
Constructors
Constructor
new Change<Data>(
fromA,
toA,
fromB,
toB,
deleted,
inserted): Change<Data>;Defined in: Change.ts:55
Creates a new Change representing a document modification.
Parameters
| Parameter | Type | Description |
|---|---|---|
fromA | number | The start position of the range in the old document (A coordinates). |
toA | number | The end position of the range in the old document (A coordinates). |
fromB | number | The start position of the range in the new document (B coordinates). |
toB | number | The end position of the range in the new document (B coordinates). |
deleted | readonly Span<Data>[] | Metadata spans for the deleted content. The total length of these spans must equal toA - fromA. |
inserted | readonly Span<Data>[] | Metadata spans for the inserted content. The total length of these spans must equal toB - fromB. |
Returns
Change<Data>
Accessors
deleted
Get Signature
get deleted(): readonly Span<Data>[];Defined in: Change.ts:90
The spans of deleted content with associated metadata.
Returns
readonly Span<Data>[]
fromA
Get Signature
get fromA(): number;Defined in: Change.ts:70
The start position in the old document (A coordinates).
Returns
number
fromB
Get Signature
get fromB(): number;Defined in: Change.ts:80
The start position in the new document (B coordinates).
Returns
number
inserted
Get Signature
get inserted(): readonly Span<Data>[];Defined in: Change.ts:95
The spans of inserted content with associated metadata.
Returns
readonly Span<Data>[]
lenA
Get Signature
get lenA(): number;Defined in: Change.ts:100
The length of the deleted range in the old document.
Returns
number
lenB
Get Signature
get lenB(): number;Defined in: Change.ts:105
The length of the inserted range in the new document.
Returns
number
toA
Get Signature
get toA(): number;Defined in: Change.ts:75
The end position in the old document (A coordinates).
Returns
number
toB
Get Signature
get toB(): number;Defined in: Change.ts:85
The end position in the new document (B coordinates).
Returns
number
Methods
slice()
slice(
startA,
endA,
startB,
endB): Change<Data>;Defined in: Change.ts:424
Creates a sub-change by slicing ranges from both coordinate systems.
This extracts a portion of this change, specified by ranges in both the A and B coordinate systems. If the slice covers the entire change, returns this instance to avoid allocation.
Parameters
| Parameter | Type | Description |
|---|---|---|
startA | number | The start position in A coordinates (relative to this change). |
endA | number | The end position in A coordinates (relative to this change). |
startB | number | The start position in B coordinates (relative to this change). |
endB | number | The end position in B coordinates (relative to this change). |
Returns
Change<Data>
A new Change representing the specified slice, or this if unchanged.
toJSON()
toJSON(): ChangeJSON<Data>;Defined in: Change.ts:453
Serializes this Change to a JSON-compatible representation.
Since the Change class structure matches the ChangeJSON interface, this method returns the instance itself.
Returns
ChangeJSON<Data>
A JSON representation of this change.
fromJSON()
static fromJSON<Data>(json): Change<Data>;Defined in: Change.ts:202
Deserializes a Change from its JSON representation.
Type Parameters
| Type Parameter | Description |
|---|---|
Data | The type of metadata in the change. |
Parameters
| Parameter | Type | Description |
|---|---|---|
json | ChangeJSON<Data> | The JSON object representing the change. |
Returns
Change<Data>
A new Change instance reconstructed from the JSON data.
merge()
static merge<Data>(
x,
y,
combine): readonly Change<Data>[];Defined in: Change.ts:126
Merges two changesets into a single changeset.
This combines two sequential changesets where the end document of the first changeset is the start document of the second. The result is a single changeset spanning from the start of the first to the end of the second.
The merge operates by synchronizing over a "middle" coordinate system:
- For the first changeset (x): the B coordinates represent the middle document
- For the second changeset (y): the A coordinates represent the middle document
Type Parameters
| Type Parameter | Description |
|---|---|
Data | The type of metadata in the changes. |
Parameters
| Parameter | Type | Description |
|---|---|---|
x | readonly Change<Data>[] | The first changeset. |
y | readonly Change<Data>[] | The second changeset applied after x. |
combine | (dataA, dataB) => Data | Function to combine metadata when spans need to be merged. |
Returns
readonly Change<Data>[]
A single changeset representing both transformations.