← All packages

@searsuite/sear-domain-commands

Typed command definitions and the editor-local command bus contract.

Document transactions

enumDocTransactionRenderOperationType

Render pipeline effect declared by a document command transaction.

enum memberReflow: "reflow"
enum memberRepaint: "repaint"
classDocTransaction

Builder for rich-document command transactions.

Commands append document OT steps and selection mapping metadata here. The caller later applies the steps through the editor pipeline.

constructorDocTransaction(): DocTransaction
propertyreadonly meta: Record<string, unknown>

Command metadata consumed by the document editor host.

propertyreadonly renderOperationType: DocTransactionRenderOperationType

Render pipeline effect produced by this document transaction.

propertyreadonly steps: DocStep[]

Ordered steps produced by the command.

methodaddStep(step: DocStep): this

Appends a prepared document step.

ReturnsThe current transaction for chaining.

step

Step to run during transaction application.

methoddeleteNode(path: number[], nodeSnapshot: NodeSchema): this

Appends a node deletion step.

ReturnsThe current transaction for chaining.

path

Path of the node to delete.

nodeSnapshot

Deleted node payload used for OT inversion.

methoddeleteText(path: number[], offset: number, text: string): this

Appends a text deletion step.

ReturnsThe current transaction for chaining.

path

Path to the text node.

offset

String offset where deletion starts.

text

Exact text expected to be deleted.

methodgetMeta<T>(key: string): T | undefined

Reads command metadata by key.

ReturnsThe stored value when present.

key

Metadata key.

methodinsertNode(path: number[], node: NodeSchema): this

Appends a node insertion step.

ReturnsThe current transaction for chaining.

path

Target insertion path.

node

Node payload to insert.

methodinsertText(path: number[], offset: number, text: string): this

Appends a text insertion step.

ReturnsThe current transaction for chaining.

path

Path to the text node.

offset

String offset where text is inserted.

text

Text to insert.

methodsetInlineTextStyle(doc: RichDocNode[], selection: DocSelection, property: string, value: unknown, patchAttrs?: InlineTextRangeAttrsPatcher): this

Applies one inline text-style property to the selected range using RichDoc OT operations.

methodsetMeta(key: string, value: unknown): this

Stores command metadata.

ReturnsThe current transaction for chaining.

key

Metadata key.

value

Metadata value.

methodsetSelection(sel: DocSelection): this

Appends a selection-only step.

ReturnsThe current transaction for chaining.

sel

Selection that should be active after this transaction.

methodupdateAttrs(path: number[], key: string, value: unknown, prev: unknown): this

Appends one attribute update operation and retains its previous value for inversion.

classReflowDocTransaction
class ReflowDocTransaction extends DocTransaction

Document transaction whose RichDoc OT operations may change layout measurement.

constructorReflowDocTransaction(): ReflowDocTransaction
propertyreadonly renderOperationType: Reflow

Render pipeline effect produced by this document transaction.

Inherited members 12

Inherited from DocTransaction.

classRepaintDocTransaction
class RepaintDocTransaction extends DocTransaction

Document transaction whose RichDoc OT operations only require repainting existing layout.

constructorRepaintDocTransaction(): RepaintDocTransaction
propertyreadonly renderOperationType: Repaint

Render pipeline effect produced by this document transaction.

Inherited members 12

Inherited from DocTransaction.

interfaceDocCommandContext

Runtime state available while a rich-document command builds a transaction.

propertydocSelection: DocSelection

Current document selection before the command applies.

propertylastSnapshot: LayoutSnapshot | null

Last measured layout snapshot, required for vertical cursor movement.

propertypendingDoc: RichDocNode[]

Pending document tree used for reads before the transaction is committed.

propertypreferredX: number | null

Preferred horizontal position used by repeated vertical cursor navigation.

interfaceDocStep

One atomic document transaction step with its selection mapping logic.

propertyops: RichDocOTOperation[]

Rich-document OT operations produced by this step.

methodmapSelection(sel: DocSelection, newDoc: RichDocNode[]): DocSelection

Maps an existing selection through the step.

ReturnsSelection rebased onto newDoc.

sel

Selection before this step.

newDoc

Document state after this step.

typeDocCommand
type DocCommand = (tr: DocTransaction, state: DocCommandContext): DocTransaction

Rich-document command that appends steps to a transaction.

typeDocCursorDirection
type DocCursorDirection = typeof DocCursorDirection[keyof typeof DocCursorDirection] DocCursorDirection: { Down: "down"; Left: "left"; Right: "right"; Up: "up" }

Union of cursor directions accepted by rich-document navigation.

Editing commands

functiondeleteBackwardCommand
deleteBackwardCommand(): DocCommand

Creates a command for Backspace behavior.

ReturnsCommand that deletes a selection, deletes the previous character, or merges with the previous paragraph.

functioninputCommand
inputCommand(text: string): DocCommand

Creates a command that inserts text at the current cursor or replaces a same-node selection.

ReturnsCommand that records text OT and collapses the selection after the insert.

text

Text to insert into the rich document.

functionmoveCursorCommand
moveCursorCommand(direction: DocCursorDirection, shiftKey: boolean, layoutEngine: DocLayoutEngine): DocCommand

Creates a command for arrow-key cursor movement.

ReturnsSelection-only command with the computed cursor or range.

direction

Navigation direction.

shiftKey

Whether the movement should extend selection.

layoutEngine

Layout engine used for vertical line navigation.

functionselectAllCommand
selectAllCommand(): DocCommand

Creates a command that selects the complete rich document.

ReturnsSelection-only command spanning the first text node to the last text node.

functionsplitParagraphCommand
splitParagraphCommand(): DocCommand

Creates a command that splits the current paragraph at the cursor.

ReturnsCommand that moves trailing text and nodes into a newly inserted paragraph.