Type Editor / @type-editor/state / Transaction / Transaction
Class: Transaction
Defined in: state/src/Transaction.ts:40
An editor state transaction, which can be applied to a state to create an updated state. Use EditorState.tr to create an instance.
Transactions track changes to the document (they are a subclass of Transform), but also other state changes, like selection updates and adjustments of the set of stored marks. In addition, you can store metadata properties in a transaction, which are extra pieces of information that client code or plugins can use to describe what a transaction represents, so that they can update their own state accordingly.
The editor view uses a few metadata properties: it will attach a property 'pointer' with the value true to selection transactions directly caused by mouse or touch input, a 'composition' property holding an ID identifying the composition that caused it to transactions caused by composed DOM input, and a 'uiEvent' property of that may be 'paste', 'cut', or 'drop'.
Extends
Transform
Implements
PmTransaction
Constructors
Constructor
new Transaction(state): Transaction;Defined in: state/src/Transaction.ts:70
Parameters
| Parameter | Type |
|---|---|
state | EditorState |
Returns
Transaction
Overrides
Transform.constructor;Properties
| Property | Modifier | Type | Inherited from | Defined in |
|---|---|---|---|---|
_doc | protected | Node_2 | Transform._doc | transform/dist/index.d.ts:270 |
Accessors
before
Get Signature
get before(): Node_2;Defined in: transform/dist/index.d.ts:276
Returns
Node_2
Implementation of
PmTransaction.before;Inherited from
Transform.before;doc
Get Signature
get doc(): Node_2;Defined in: transform/dist/index.d.ts:272
Returns
Node_2
Implementation of
PmTransaction.doc;Inherited from
Transform.doc;docChanged
Get Signature
get docChanged(): boolean;Defined in: transform/dist/index.d.ts:277
Returns
boolean
Implementation of
PmTransaction.docChanged;Inherited from
Transform.docChanged;docs
Get Signature
get docs(): readonly Node_2[];Defined in: transform/dist/index.d.ts:274
Returns
readonly Node_2[]
Implementation of
PmTransaction.docs;Inherited from
Transform.docs;isGeneric
Get Signature
get isGeneric(): boolean;Defined in: state/src/Transaction.ts:124
Returns true if this transaction doesn't contain any metadata, and can thus safely be extended.
Returns
boolean
Implementation of
PmTransaction.isGeneric;mapping
Get Signature
get mapping(): Mapping;Defined in: transform/dist/index.d.ts:275
Returns
Mapping
Implementation of
PmTransaction.mapping;Inherited from
Transform.mapping;scrolledIntoView
Get Signature
get scrolledIntoView(): boolean;Defined in: state/src/Transaction.ts:131
True when this transaction has had scrollIntoView called on it.
Returns
boolean
Implementation of
PmTransaction.scrolledIntoView;selection
Get Signature
get selection(): Selection;Defined in: state/src/Transaction.ts:98
The transaction's current selection. This defaults to the editor selection mapped through the steps in the transaction, but can be overwritten with setSelection.
Returns
Implementation of
PmTransaction.selection;selectionSet
Get Signature
get selectionSet(): boolean;Defined in: state/src/Transaction.ts:109
Whether the selection was explicitly updated by this transaction.
Returns
boolean
Implementation of
PmTransaction.selectionSet;steps
Get Signature
get steps(): readonly Step[];Defined in: transform/dist/index.d.ts:273
Returns
readonly Step[]
Implementation of
PmTransaction.steps;Inherited from
Transform.steps;storedMarks
Get Signature
get storedMarks(): readonly Mark[];Defined in: state/src/Transaction.ts:80
The stored marks set by this transaction, if any.
Returns
readonly Mark[]
Implementation of
PmTransaction.storedMarks;storedMarksSet
Get Signature
get storedMarksSet(): boolean;Defined in: state/src/Transaction.ts:116
Whether the stored marks were explicitly set for this transaction.
Returns
boolean
Implementation of
PmTransaction.storedMarksSet;time
Get Signature
get time(): number;Defined in: state/src/Transaction.ts:88
The timestamp associated with this transaction, in the same format as Date.now().
Returns
number
Implementation of
PmTransaction.time;Methods
addMark()
addMark(
from,
to,
mark): this;Defined in: transform/dist/index.d.ts:308
Parameters
| Parameter | Type |
|---|---|
from | number |
to | number |
mark | Mark |
Returns
this
Implementation of
PmTransaction.addMark;Inherited from
Transform.addMark;addNodeMark()
addNodeMark(position, mark): this;Defined in: transform/dist/index.d.ts:302
Parameters
| Parameter | Type |
|---|---|
position | number |
mark | Mark |
Returns
this
Implementation of
PmTransaction.addNodeMark;Inherited from
Transform.addNodeMark;addStep()
addStep(step, doc): void;Defined in: state/src/Transaction.ts:186
Parameters
| Parameter | Type |
|---|---|
step | Step |
doc | Node_2 |
Returns
void
Implementation of
PmTransaction.addStep;Overrides
Transform.addStep;addStoredMark()
addStoredMark(mark): Transaction;Defined in: state/src/Transaction.ts:173
Add a mark to the set of stored marks.
Parameters
| Parameter | Type |
|---|---|
mark | Mark |
Returns
Transaction
Implementation of
PmTransaction.addStoredMark;changedRange()
changedRange(): {
from: number;
to: number;
};Defined in: transform/dist/index.d.ts:280
Returns
{
from: number;
to: number;
}| Name | Type | Defined in |
|---|---|---|
from | number | transform/dist/index.d.ts:281 |
to | number | transform/dist/index.d.ts:282 |
Implementation of
PmTransaction.changedRange;Inherited from
Transform.changedRange;clearIncompatible()
clearIncompatible(
position,
parentType,
match?): this;Defined in: transform/dist/index.d.ts:310
Parameters
| Parameter | Type |
|---|---|
position | number |
parentType | NodeType |
match? | ContentMatch |
Returns
this
Implementation of
PmTransaction.clearIncompatible;Inherited from
Transform.clearIncompatible;delete()
delete(from, to): this;Defined in: transform/dist/index.d.ts:287
Parameters
| Parameter | Type |
|---|---|
from | number |
to | number |
Returns
this
Implementation of
PmTransaction.delete;Inherited from
Transform.delete;deleteRange()
deleteRange(from, to): this;Defined in: transform/dist/index.d.ts:291
Parameters
| Parameter | Type |
|---|---|
from | number |
to | number |
Returns
this
Implementation of
PmTransaction.deleteRange;Inherited from
Transform.deleteRange;deleteSelection()
deleteSelection(): Transaction;Defined in: state/src/Transaction.ts:238
Delete the selection.
Returns
Transaction
Implementation of
PmTransaction.deleteSelection;ensureMarks()
ensureMarks(marks): Transaction;Defined in: state/src/Transaction.ts:163
Make sure the current stored marks or, if that is null, the marks at the selection, match the given set of marks. Does nothing if this is already the case.
Parameters
| Parameter | Type |
|---|---|
marks | readonly Mark[] |
Returns
Transaction
Implementation of
PmTransaction.ensureMarks;getMeta()
getMeta(key): any;Defined in: state/src/Transaction.ts:289
Retrieve a metadata property for a given name or plugin.
Parameters
| Parameter | Type |
|---|---|
key | | string | Plugin<any> | PluginKey<any> |
Returns
any
Implementation of
PmTransaction.getMeta;getUpdated()
getUpdated(): number;Defined in: state/src/Transaction.ts:150
Returns
number
Implementation of
PmTransaction.getUpdated;insert()
insert(pos, content): this;Defined in: transform/dist/index.d.ts:288
Parameters
| Parameter | Type |
|---|---|
pos | number |
content | Node_2 | readonly Node_2[] | Fragment |
Returns
this
Implementation of
PmTransaction.insert;Inherited from
Transform.insert;insertText()
insertText(
text,
from?,
to?): Transaction;Defined in: state/src/Transaction.ts:247
Replace the given range, or the selection if no range is given, with a text node containing the given string.
Parameters
| Parameter | Type |
|---|---|
text | string |
from? | number |
to? | number |
Returns
Transaction
Implementation of
PmTransaction.insertText;join()
join(pos, depth?): this;Defined in: transform/dist/index.d.ts:293
Parameters
| Parameter | Type |
|---|---|
pos | number |
depth? | number |
Returns
this
Implementation of
PmTransaction.join;Inherited from
Transform.join;lift()
lift(range, target): this;Defined in: transform/dist/index.d.ts:292
Parameters
| Parameter | Type |
|---|---|
range | NodeRange |
target | number |
Returns
this
Implementation of
PmTransaction.lift;Inherited from
Transform.lift;maybeStep()
maybeStep(step): StepResult;Defined in: transform/dist/index.d.ts:279
Parameters
| Parameter | Type |
|---|---|
step | PmStep |
Returns
StepResult
Implementation of
PmTransaction.maybeStep;Inherited from
Transform.maybeStep;removeMark()
removeMark(
from,
to,
mark?): this;Defined in: transform/dist/index.d.ts:309
Parameters
| Parameter | Type |
|---|---|
from | number |
to | number |
mark? | Mark | MarkType |
Returns
this
Implementation of
PmTransaction.removeMark;Inherited from
Transform.removeMark;removeNodeMark()
removeNodeMark(position, mark): this;Defined in: transform/dist/index.d.ts:303
Parameters
| Parameter | Type |
|---|---|
position | number |
mark | Mark | MarkType |
Returns
this
Implementation of
PmTransaction.removeNodeMark;Inherited from
Transform.removeNodeMark;removeStoredMark()
removeStoredMark(mark): Transaction;Defined in: state/src/Transaction.ts:181
Remove a mark or mark type from the set of stored marks.
Parameters
| Parameter | Type |
|---|---|
mark | Mark | MarkType |
Returns
Transaction
Implementation of
PmTransaction.removeStoredMark;replace()
replace(
from,
to?,
slice?): this;Defined in: transform/dist/index.d.ts:285
Parameters
| Parameter | Type |
|---|---|
from | number |
to? | number |
slice? | Slice |
Returns
this
Implementation of
PmTransaction.replace;Inherited from
Transform.replace;replaceRange()
replaceRange(
from,
to,
slice): this;Defined in: transform/dist/index.d.ts:289
Parameters
| Parameter | Type |
|---|---|
from | number |
to | number |
slice | Slice |
Returns
this
Implementation of
PmTransaction.replaceRange;Inherited from
Transform.replaceRange;replaceRangeWith()
replaceRangeWith(
from,
to,
node): this;Defined in: transform/dist/index.d.ts:290
Parameters
| Parameter | Type |
|---|---|
from | number |
to | number |
node | Node_2 |
Returns
this
Implementation of
PmTransaction.replaceRangeWith;Inherited from
Transform.replaceRangeWith;replaceSelection()
replaceSelection(slice): Transaction;Defined in: state/src/Transaction.ts:205
Replace the current selection with the given slice.
Parameters
| Parameter | Type |
|---|---|
slice | Slice |
Returns
Transaction
Implementation of
PmTransaction.replaceSelection;replaceSelectionWith()
replaceSelectionWith(node, inheritMarks?): Transaction;Defined in: state/src/Transaction.ts:217
Replace the selection with the given node. When inheritMarks is true and the content is inline, it inherits the marks from the place where it is inserted.
Parameters
| Parameter | Type | Default value |
|---|---|---|
node | Node_2 | undefined |
inheritMarks | boolean | true |
Returns
Transaction
Implementation of
PmTransaction.replaceSelectionWith;replaceWith()
replaceWith(
from,
to,
content): this;Defined in: transform/dist/index.d.ts:286
Parameters
| Parameter | Type |
|---|---|
from | number |
to | number |
content | Node_2 | readonly Node_2[] | Fragment |
Returns
this
Implementation of
PmTransaction.replaceWith;Inherited from
Transform.replaceWith;scrollIntoView()
scrollIntoView(): Transaction;Defined in: state/src/Transaction.ts:297
Indicate that the editor should scroll the selection into view when updated to the state produced by this transaction.
Returns
Transaction
Implementation of
PmTransaction.scrollIntoView;setBlockType()
setBlockType(
from,
to,
type,
attrs?): this;Defined in: transform/dist/index.d.ts:298
Parameters
| Parameter | Type |
|---|---|
from | number |
to | number |
type | NodeType |
attrs? | | Readonly<Record<string, any>> | (oldNode) => Attrs |
Returns
this
Implementation of
PmTransaction.setBlockType;Inherited from
Transform.setBlockType;setDocAttribute()
setDocAttribute(attr, value): this;Defined in: transform/dist/index.d.ts:301
Parameters
| Parameter | Type |
|---|---|
attr | string |
value | AttrValue |
Returns
this
Implementation of
PmTransaction.setDocAttribute;Inherited from
Transform.setDocAttribute;setMeta()
setMeta(key, value): Transaction;Defined in: state/src/Transaction.ts:281
Store a metadata property in this transaction, keyed either by name or by plugin.
Parameters
| Parameter | Type |
|---|---|
key | | string | Plugin<any> | PluginKey<any> |
value | any |
Returns
Transaction
Implementation of
PmTransaction.setMeta;setNodeAttribute()
setNodeAttribute(
pos,
attr,
value): this;Defined in: transform/dist/index.d.ts:300
Parameters
| Parameter | Type |
|---|---|
pos | number |
attr | string |
value | AttrValue |
Returns
this
Implementation of
PmTransaction.setNodeAttribute;Inherited from
Transform.setNodeAttribute;setNodeMarkup()
setNodeMarkup(
pos,
type?,
attrs?,
marks?): this;Defined in: transform/dist/index.d.ts:299
Parameters
| Parameter | Type |
|---|---|
pos | number |
type? | NodeType |
attrs? | Readonly<Record<string, any>> |
marks? | readonly Mark[] |
Returns
this
Implementation of
PmTransaction.setNodeMarkup;Inherited from
Transform.setNodeMarkup;setSelection()
setSelection(selection): Transaction;Defined in: state/src/Transaction.ts:139
Update the transaction's current selection. Will determine the selection that the editor gets when the transaction is applied.
Parameters
| Parameter | Type |
|---|---|
selection | Selection |
Returns
Transaction
Implementation of
PmTransaction.setSelection;setStoredMarks()
setStoredMarks(marks): Transaction;Defined in: state/src/Transaction.ts:305
Set the current stored marks.
Parameters
| Parameter | Type |
|---|---|
marks | readonly Mark[] |
Returns
Transaction
Implementation of
PmTransaction.setStoredMarks;setTime()
setTime(time): Transaction;Defined in: state/src/Transaction.ts:196
Update the timestamp for the transaction.
Parameters
| Parameter | Type |
|---|---|
time | number |
Returns
Transaction
Implementation of
PmTransaction.setTime;setUpdated()
setUpdated(updated): void;Defined in: state/src/Transaction.ts:154
Parameters
| Parameter | Type |
|---|---|
updated | number |
Returns
void
Implementation of
PmTransaction.setUpdated;split()
split(
pos,
depth?,
typesAfter?): this;Defined in: transform/dist/index.d.ts:304
Parameters
| Parameter | Type |
|---|---|
pos | number |
depth? | number |
typesAfter? | { attrs?: Readonly<Record<string, any>>; type: NodeType; }[] |
Returns
this
Implementation of
PmTransaction.split;Inherited from
Transform.split;step()
step(step): this;Defined in: transform/dist/index.d.ts:278
Parameters
| Parameter | Type |
|---|---|
step | PmStep |
Returns
this
Implementation of
PmTransaction.step;Inherited from
Transform.step;wrap()
wrap(range, wrappers): this;Defined in: transform/dist/index.d.ts:294
Parameters
| Parameter | Type |
|---|---|
range | NodeRange |
wrappers | readonly { attrs?: Readonly<Record<string, any>>; type: NodeType; }[] |
Returns
this
Implementation of
PmTransaction.wrap;Inherited from
Transform.wrap;