← All packages

API reference

@searsuite/sear-domain-commands

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

14 exportsderived from source

enumDocTransactionRenderOperationTypesource ↗
enum DocTransactionRenderOperationType

Render pipeline effect declared by a document command transaction.

enum memberReflow
Reflow: "reflow"
enum memberRepaint
Repaint: "repaint"
classDocTransactionsource ↗
class DocTransaction

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.

constructorconstructor
DocTransaction(): DocTransaction
propertymeta
readonly meta: Record<string, unknown>

Command metadata consumed by the document editor host.

propertyrenderOperationType
readonly renderOperationType: DocTransactionRenderOperationType

Render pipeline effect produced by this document transaction.

propertysteps
readonly steps: DocStep[]

Ordered steps produced by the command.

methodaddStep
addStep(step: DocStep): this

Appends a prepared document step.

ReturnsThe current transaction for chaining.

step: DocStep

Step to run during transaction application.

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

Appends a node deletion step.

ReturnsThe current transaction for chaining.

path: number[]

Path of the node to delete.

nodeSnapshot: NodeSchema

Deleted node payload used for OT inversion.

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

Appends a text deletion step.

ReturnsThe current transaction for chaining.

path: number[]

Path to the text node.

offset: number

String offset where deletion starts.

text: string

Exact text expected to be deleted.

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

Reads command metadata by key.

ReturnsThe stored value when present.

key: string

Metadata key.

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

Appends a node insertion step.

ReturnsThe current transaction for chaining.

path: number[]

Target insertion path.

node: NodeSchema

Node payload to insert.

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

Appends a text insertion step.

ReturnsThe current transaction for chaining.

path: number[]

Path to the text node.

offset: number

String offset where text is inserted.

text: string

Text to insert.

methodsetInlineTextStyle
setInlineTextStyle(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.

doc: RichDocNode[]
selection: DocSelection
property: string
value: unknown
patchAttrs: InlineTextRangeAttrsPatcher
methodsetMeta
setMeta(key: string, value: unknown): this

Stores command metadata.

ReturnsThe current transaction for chaining.

key: string

Metadata key.

value: unknown

Metadata value.

methodsetSelection
setSelection(sel: DocSelection): this

Appends a selection-only step.

ReturnsThe current transaction for chaining.

sel: DocSelection

Selection that should be active after this transaction.

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

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

path: number[]
key: string
value: unknown
prev: unknown
classReflowDocTransactionsource ↗
class ReflowDocTransaction extends DocTransaction

Document transaction whose RichDoc OT operations may change layout measurement.

constructorconstructor
ReflowDocTransaction(): ReflowDocTransaction
propertyrenderOperationType
readonly renderOperationType: Reflow

Render pipeline effect produced by this document transaction.

Inherited members 12

Inherited from DocTransaction.

classRepaintDocTransactionsource ↗
class RepaintDocTransaction extends DocTransaction

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

constructorconstructor
RepaintDocTransaction(): RepaintDocTransaction
propertyrenderOperationType
readonly renderOperationType: Repaint

Render pipeline effect produced by this document transaction.

Inherited members 12

Inherited from DocTransaction.

interfaceDocCommandContextsource ↗
interface DocCommandContext

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

propertydocSelection
docSelection: DocSelection

Current document selection before the command applies.

propertylastSnapshot
lastSnapshot: LayoutSnapshot | null

Last measured layout snapshot, required for vertical cursor movement.

propertypendingDoc
pendingDoc: RichDocNode[]

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

propertypreferredX
preferredX: number | null

Preferred horizontal position used by repeated vertical cursor navigation.

interfaceDocStepsource ↗
interface DocStep

One atomic document transaction step with its selection mapping logic.

propertyops
ops: RichDocOTOperation[]

Rich-document OT operations produced by this step.

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

Maps an existing selection through the step.

ReturnsSelection rebased onto newDoc.

sel: DocSelection

Selection before this step.

newDoc: RichDocNode[]

Document state after this step.

typeDocCommandsource ↗
type DocCommand = (tr: DocTransaction, state: DocCommandContext): DocTransaction

Rich-document command that appends steps to a transaction.

typeDocCursorDirectionsource ↗
type DocCursorDirection = typeof DocCursorDirection[keyof typeof DocCursorDirection]

Union of cursor directions accepted by rich-document navigation.

variableDocCursorDirectionsource ↗
DocCursorDirection: { Down: "down"; Left: "left"; Right: "right"; Up: "up" }

Cardinal directions accepted by rich-document cursor navigation commands.

functiondeleteBackwardCommandsource ↗
deleteBackwardCommand(): DocCommand

Creates a command for Backspace behavior.

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

functioninputCommandsource ↗
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: string

Text to insert into the rich document.

functionmoveCursorCommandsource ↗
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: DocCursorDirection

Navigation direction.

shiftKey: boolean

Whether the movement should extend selection.

layoutEngine: DocLayoutEngine

Layout engine used for vertical line navigation.

functionselectAllCommandsource ↗
selectAllCommand(): DocCommand

Creates a command that selects the complete rich document.

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

functionsplitParagraphCommandsource ↗
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.