Skip to content

SyntheticBehaviorEvent

SyntheticBehaviorEvent = { annotation: { _key?: string; name: string; value: {[prop: string]: unknown; }; }; at?: NonNullable<EditorSelection>; type: StrictExtract<SyntheticBehaviorEventType, "annotation.add">; } | { annotation: { name: string; }; at?: NonNullable<EditorSelection>; type: StrictExtract<SyntheticBehaviorEventType, "annotation.remove">; } | { at: BlockPath; props: Record<string, unknown>; type: StrictExtract<SyntheticBehaviorEventType, "block.set">; } | { at: BlockPath; props: string[]; type: StrictExtract<SyntheticBehaviorEventType, "block.unset">; } | { at: ChildPath; props: {[prop: string]: unknown; }; type: StrictExtract<SyntheticBehaviorEventType, "child.set">; } | { at: ChildPath; props: string[]; type: StrictExtract<SyntheticBehaviorEventType, "child.unset">; } | { at?: NonNullable<EditorSelection>; decorator: string; type: StrictExtract<SyntheticBehaviorEventType, "decorator.add">; } | { at?: NonNullable<EditorSelection>; decorator: string; type: StrictExtract<SyntheticBehaviorEventType, "decorator.remove">; } | { at?: NonNullable<EditorSelection>; direction?: "backward" | "forward"; type: StrictExtract<SyntheticBehaviorEventType, "delete">; unit?: "character" | "word" | "line" | "block" | "child"; } | { type: StrictExtract<SyntheticBehaviorEventType, "history.redo">; } | { type: StrictExtract<SyntheticBehaviorEventType, "history.undo">; } | { at: Path; position: "before" | "after"; type: StrictExtract<SyntheticBehaviorEventType, "insert">; value: PortableTextTextBlock | PortableTextObject | PortableTextSpan; } | { at?: NonNullable<EditorSelection>; block: BlockWithOptionalKey; placement: InsertPlacement; select?: "start" | "end" | "none"; type: StrictExtract<SyntheticBehaviorEventType, "insert.block">; } | { child: ChildWithOptionalKey; type: StrictExtract<SyntheticBehaviorEventType, "insert.child">; } | { at?: Path; offset?: number; text: string; type: StrictExtract<SyntheticBehaviorEventType, "insert.text">; } | { distance: number; type: StrictExtract<SyntheticBehaviorEventType, "move.backward">; } | { distance: number; type: StrictExtract<SyntheticBehaviorEventType, "move.forward">; } | { at: Path; offset: number; text: string; type: StrictExtract<SyntheticBehaviorEventType, "remove.text">; } | { at: EditorSelection; type: StrictExtract<SyntheticBehaviorEventType, "select">; } | { at: Path; type: StrictExtract<SyntheticBehaviorEventType, "set">; value: unknown; } | { at: Path; type: StrictExtract<SyntheticBehaviorEventType, "unset">; } | AbstractBehaviorEvent

Defined in: behavior.types.event.ts:102

{ annotation: { _key?: string; name: string; value: {[prop: string]: unknown; }; }; at?: NonNullable<EditorSelection>; type: StrictExtract<SyntheticBehaviorEventType, "annotation.add">; }

annotation: object

optional _key: string

name: string

value: object

[prop: string]: unknown

optional at: NonNullable<EditorSelection>

type: StrictExtract<SyntheticBehaviorEventType, "annotation.add">

{ annotation: { name: string; }; at?: NonNullable<EditorSelection>; type: StrictExtract<SyntheticBehaviorEventType, "annotation.remove">; }

annotation: object

name: string

optional at: NonNullable<EditorSelection>

type: StrictExtract<SyntheticBehaviorEventType, "annotation.remove">

{ at: BlockPath; props: Record<string, unknown>; type: StrictExtract<SyntheticBehaviorEventType, "block.set">; }

at: BlockPath

props: Record<string, unknown>

type: StrictExtract<SyntheticBehaviorEventType, "block.set">

{ at: BlockPath; props: string[]; type: StrictExtract<SyntheticBehaviorEventType, "block.unset">; }

at: BlockPath

props: string[]

type: StrictExtract<SyntheticBehaviorEventType, "block.unset">

{ at: ChildPath; props: {[prop: string]: unknown; }; type: StrictExtract<SyntheticBehaviorEventType, "child.set">; }

at: ChildPath

props: object

[prop: string]: unknown

type: StrictExtract<SyntheticBehaviorEventType, "child.set">

{ at: ChildPath; props: string[]; type: StrictExtract<SyntheticBehaviorEventType, "child.unset">; }

at: ChildPath

props: string[]

type: StrictExtract<SyntheticBehaviorEventType, "child.unset">

{ at?: NonNullable<EditorSelection>; decorator: string; type: StrictExtract<SyntheticBehaviorEventType, "decorator.add">; }

optional at: NonNullable<EditorSelection>

decorator: string

type: StrictExtract<SyntheticBehaviorEventType, "decorator.add">

{ at?: NonNullable<EditorSelection>; decorator: string; type: StrictExtract<SyntheticBehaviorEventType, "decorator.remove">; }

optional at: NonNullable<EditorSelection>

decorator: string

type: StrictExtract<SyntheticBehaviorEventType, "decorator.remove">

{ at?: NonNullable<EditorSelection>; direction?: "backward" | "forward"; type: StrictExtract<SyntheticBehaviorEventType, "delete">; unit?: "character" | "word" | "line" | "block" | "child"; }

optional at: NonNullable<EditorSelection>

optional direction: "backward" | "forward"

Defaults to forward deletion.

type: StrictExtract<SyntheticBehaviorEventType, "delete">

optional unit: "character" | "word" | "line" | "block" | "child"

Defaults to character deletion.

{ type: StrictExtract<SyntheticBehaviorEventType, "history.redo">; }

type: StrictExtract<SyntheticBehaviorEventType, "history.redo">

{ type: StrictExtract<SyntheticBehaviorEventType, "history.undo">; }

type: StrictExtract<SyntheticBehaviorEventType, "history.undo">

{ at: Path; position: "before" | "after"; type: StrictExtract<SyntheticBehaviorEventType, "insert">; value: PortableTextTextBlock | PortableTextObject | PortableTextSpan; }

at: Path

position: "before" | "after"

type: StrictExtract<SyntheticBehaviorEventType, "insert">

Primitive: insert a node into an array.

The last segment of at resolves the insertion point:

  • A keyed {_key} segment inserts relative to that sibling.
  • A numeric index inserts relative to that slot.

position (‘before’ or ‘after’) is always meaningful: before: [2] inserts at index 2, after: [2] inserts at index 3.

raise({
type: 'insert',
at: [{_key: 'list'}, 'items', {_key: 'item3'}],
value: newItem,
position: 'after',
})

value: PortableTextTextBlock | PortableTextObject | PortableTextSpan

{ at?: NonNullable<EditorSelection>; block: BlockWithOptionalKey; placement: InsertPlacement; select?: "start" | "end" | "none"; type: StrictExtract<SyntheticBehaviorEventType, "insert.block">; }

optional at: NonNullable<EditorSelection>

block: BlockWithOptionalKey

placement: InsertPlacement

optional select: "start" | "end" | "none"

type: StrictExtract<SyntheticBehaviorEventType, "insert.block">

{ child: ChildWithOptionalKey; type: StrictExtract<SyntheticBehaviorEventType, "insert.child">; }

child: ChildWithOptionalKey

type: StrictExtract<SyntheticBehaviorEventType, "insert.child">

{ at?: Path; offset?: number; text: string; type: StrictExtract<SyntheticBehaviorEventType, "insert.text">; }

optional at: Path

optional offset: number

text: string

type: StrictExtract<SyntheticBehaviorEventType, "insert.text">

Inserts text into a span.

Without at/offset, text is inserted at the current caret position. This is the form used by typing handlers.

With at and offset, text is inserted at the explicit position. Recommended for plugin behaviors and collaborative-edit contexts.

// Caret form
raise({type: 'insert.text', text: 'x'})
// Primitive form (@alpha)
raise({
type: 'insert.text',
at: [{_key: 'b1'}, 'children', {_key: 's1'}],
offset: 5,
text: 'world',
})

{ distance: number; type: StrictExtract<SyntheticBehaviorEventType, "move.backward">; }

distance: number

type: StrictExtract<SyntheticBehaviorEventType, "move.backward">

{ distance: number; type: StrictExtract<SyntheticBehaviorEventType, "move.forward">; }

distance: number

type: StrictExtract<SyntheticBehaviorEventType, "move.forward">

{ at: Path; offset: number; text: string; type: StrictExtract<SyntheticBehaviorEventType, "remove.text">; }

at: Path

offset: number

text: string

type: StrictExtract<SyntheticBehaviorEventType, "remove.text">

Primitive: remove text from a span at the given offset.

The text field carries the exact text being removed (matches the apply-layer shape so the inverse can be computed without re-reading the span).

Recommended for collaborative-edit contexts (concurrent edits compose cleanly under operational transform).

raise({
type: 'remove.text',
at: [{_key: 'b1'}, 'children', {_key: 's1'}],
offset: 5,
text: 'world',
})

{ at: EditorSelection; type: StrictExtract<SyntheticBehaviorEventType, "select">; }

at: EditorSelection

type: StrictExtract<SyntheticBehaviorEventType, "select">

{ at: Path; type: StrictExtract<SyntheticBehaviorEventType, "set">; value: unknown; }

at: Path

type: StrictExtract<SyntheticBehaviorEventType, "set">

Primitive: set a property on a node, or replace a node wholesale.

The last segment of at is the property name (a string) for property updates, OR a keyed/indexed segment for full-node replacement.

Note: set on span text ({at: [...spanPath, 'text'], value: '...'}) is legal but not recommended in collaborative-edit contexts. Use insert.text and remove.text for text edits that compose under operational transform.

// Set a block's style
raise({type: 'set', at: [{_key: 'b1'}, 'style'], value: 'h1'})
// Replace a block wholesale
raise({type: 'set', at: [{_key: 'b1'}], value: newBlock})

value: unknown

{ at: Path; type: StrictExtract<SyntheticBehaviorEventType, "unset">; }

at: Path

type: StrictExtract<SyntheticBehaviorEventType, "unset">

Primitive: unset a property on an object, OR remove a node from an array.

When the last segment of at is a string, the property is removed. When the last segment is a keyed {_key} segment or a numeric index, the node at that array position is removed.

// Remove a property
raise({type: 'unset', at: [{_key: 'b1'}, 'level']})
// Remove a node from an array
raise({type: 'unset', at: [{_key: 'list'}, 'items', {_key: 'item3'}]})

AbstractBehaviorEvent