C

Transaction

tested

A mutable builder that accumulates atomic Steps 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 WritekitState.

Signature

ts
class Transaction

Properties

PropertyTypeDescription
beforereadonlyWritekitState—
stepsreadonlyStep[]—
invertedreadonlyStep[]Inverse of each step, in application order (reversed when undoing).
metareadonlyMap<string, unknown>—
docWritekitDocumentWorking document after the steps applied so far.
selectionSelectionSelection to apply after this transaction.
storedMarksMarks | null | undefinedundefined = leave stored marks to default handling; otherwise set them.
lastSplitIdstring | undefinedId of the block created by the most recent 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—
attrsAttrs—
Returnsthis
setBlockType

Convert a block to another type, preserving its inline content — minus the marks the new type forbids (prose turned into a code block sheds its bold), recorded as a second step so undo restores them exactly.

ts
setBlockType(blockId: string, type: string, attrs?: Attrs): this
ParameterTypeDescription
blockIdstring—
typestring—
attrs?Attrs—
Returnsthis
splitBlock
ts
splitBlock(pos: Position, newType?: string, newAttrs?: Attrs, newId: string = createId()): this
ParameterTypeDescription
posPosition—
newType?string—
newAttrs?Attrs—
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: WritekitDocument): this
ParameterTypeDescription
docWritekitDocument—
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