R
C

Transaction

tested

A mutable builder that accumulates atomic {@link Step}s over a working copy of the document. Each builder method applies its step immediately (so later builders see prior effects) and records the exact inverse for undo. Dispatch turns the finished transaction into a new {@link EditorState}.

Signature

ts
class Transaction

Properties

PropertyTypeDescription
beforereadonlyEditorState
stepsreadonlyStep[]
invertedreadonlyStep[]Inverse of each step, in application order (reversed when undoing).
metareadonlyMap<string, unknown>
docEditorDocumentWorking document after the steps applied so far.
selectionSelectionSelection to apply after this transaction.
storedMarksMarks | null | undefined`undefined` = leave stored marks to default handling; otherwise set them.
lastSplitIdstring | undefinedId of the block created by the most recent {@link splitBlock}.

Methods

step

Apply a raw step (also used by undo/redo to replay stored steps).

ts
step(step: Step): this
ParameterTypeDescription
stepStep
Returnsthis
insertText
ts
insertText(pos: Position, text: string, marks: Marks = []): this
ParameterTypeDescription
posPosition
textstring
marks?Marks
Returnsthis
insertInline
ts
insertInline(pos: Position, content: Inline): this
ParameterTypeDescription
posPosition
contentInline
Returnsthis
deleteText
ts
deleteText(blockId: string, from: number, to: number): this
ParameterTypeDescription
blockIdstring
fromnumber
tonumber
Returnsthis
replaceInline
ts
replaceInline(blockId: string, from: number, to: number, content: Inline): this
ParameterTypeDescription
blockIdstring
fromnumber
tonumber
contentInline
Returnsthis
setBlockContent

Replace a block's entire inline content (used by the input flush path).

ts
setBlockContent(blockId: string, content: Inline): this
ParameterTypeDescription
blockIdstring
contentInline
Returnsthis
addMark
ts
addMark(blockId: string, from: number, to: number, mark: Mark): this
ParameterTypeDescription
blockIdstring
fromnumber
tonumber
markMark
Returnsthis
removeMark
ts
removeMark(blockId: string, from: number, to: number, mark: Mark): this
ParameterTypeDescription
blockIdstring
fromnumber
tonumber
markMark
Returnsthis
setAttrs

Merge `attrs` into the block's existing attrs.

ts
setAttrs(blockId: string, attrs: Attrs): this
ParameterTypeDescription
blockIdstring
attrsReadonly<Record<string, import("..").AttrValue>>
Returnsthis
setBlockType

Convert a block to another type, preserving its inline content.

ts
setBlockType(blockId: string, type: string, attrs?: Attrs): this
ParameterTypeDescription
blockIdstring
typestring
attrs?Readonly<Record<string, import("..").AttrValue>> | undefined
Returnsthis
splitBlock
ts
splitBlock(pos: Position, newType?: string, newAttrs?: Attrs, newId: string = createId()): this
ParameterTypeDescription
posPosition
newType?string | undefined
newAttrs?Readonly<Record<string, import("..").AttrValue>> | undefined
newId?string
Returnsthis
mergeBlock
ts
mergeBlock(blockId: string, intoId: string): this
ParameterTypeDescription
blockIdstring
intoIdstring
Returnsthis
insertBlock
ts
insertBlock(node: Node, index: number): this
ParameterTypeDescription
nodeNode
indexnumber
Returnsthis
removeBlock
ts
removeBlock(blockId: string): this
ParameterTypeDescription
blockIdstring
Returnsthis
moveBlock
ts
moveBlock(blockId: string, toIndex: number): this
ParameterTypeDescription
blockIdstring
toIndexnumber
Returnsthis
setDoc

Replace the whole document (used to apply a remote CRDT snapshot).

ts
setDoc(doc: EditorDocument): this
ParameterTypeDescription
docEditorDocument
Returnsthis
setSelection
ts
setSelection(selection: Selection): this
ParameterTypeDescription
selectionSelection
Returnsthis
setStoredMarks
ts
setStoredMarks(marks: Marks | null): this
ParameterTypeDescription
marksMarks | null
Returnsthis
setMeta
ts
setMeta(key: string, value: unknown): this
ParameterTypeDescription
keystring
valueunknown
Returnsthis
getMeta
ts
getMeta(key: string): unknown
ParameterTypeDescription
keystring
Returnsunknown