Skip to main content

@lexical/history

Interfaces​

HistoryConfig​

Defined in: packages/lexical-history/src/index.ts:682

Properties​

createInitialHistoryState​

createInitialHistoryState: (editor) => HistoryState

Defined in: packages/lexical-history/src/index.ts:691

The initial history state, the default is createEmptyHistoryState.

Parameters​
editor​

LexicalEditor

Returns​

HistoryState

delay​

delay: number

Defined in: packages/lexical-history/src/index.ts:687

The time (in milliseconds) the editor should delay generating a new history stack, instead of merging the current changes with the current stack. The default is 300ms.

disabled​

disabled: boolean

Defined in: packages/lexical-history/src/index.ts:695

Whether history is disabled or not

maxDepth​

maxDepth: number | null

Defined in: packages/lexical-history/src/index.ts:711

The maximum number of entries the undo stack may hold. When the cap is exceeded the oldest entries are dropped (FIFO) so the stack stays at this length. Defaults to null, which keeps the stack unbounded — the historical behavior. Setting a finite cap is recommended for editors that may receive a very large number of distinct history events (long writing sessions, automated input, etc.) since each entry retains a full EditorState snapshot.

For reference, ProseMirror's history() plugin defaults to depth: 100.

now​

now: () => number

Defined in: packages/lexical-history/src/index.ts:699

The now() function, defaults to Date.now.

Returns​

number


HistoryExtensionOutput​

Defined in: packages/lexical-history/src/index.ts:730

The output signals exposed by HistoryExtension.

Config-derived signals (delay, disabled, historyState, maxDepth, now) are writable so that peer extensions such as SharedHistoryExtension can redirect them at runtime. The canUndo / canRedo signals are readonly for consumers — they are derived from the current HistoryState and kept in sync automatically.

Properties​

canRedo​

canRedo: ReadonlySignal<boolean>

Defined in: packages/lexical-history/src/index.ts:735

true when there is at least one entry in the redo stack, i.e. the editor can perform a redo.

canUndo​

canUndo: ReadonlySignal<boolean>

Defined in: packages/lexical-history/src/index.ts:740

true when there is at least one entry in the undo stack, i.e. the editor can perform an undo.

delay​

delay: Signal<number>

Defined in: packages/lexical-history/src/index.ts:742

The merge-delay in milliseconds forwarded to registerHistory.

disabled​

disabled: Signal<boolean>

Defined in: packages/lexical-history/src/index.ts:744

When true the history listener is not registered.

historyState​

historyState: Signal<HistoryState>

Defined in: packages/lexical-history/src/index.ts:746

The active HistoryState instance.

maxDepth​

maxDepth: Signal<number | null>

Defined in: packages/lexical-history/src/index.ts:752

Maximum number of entries the undo stack may hold. null disables the cap. Changes apply to the next history event — the current undo stack is not retroactively trimmed when the value is lowered.

now​

now: Signal<() => number>

Defined in: packages/lexical-history/src/index.ts:754

The clock function forwarded to registerHistory.


SharedHistoryConfig​

Defined in: packages/lexical-history/src/index.ts:863

Properties​

disabled​

disabled: boolean

Defined in: packages/lexical-history/src/index.ts:867

Whether shared history is disabled or not

parentEditor​

parentEditor: LexicalEditor | null

Defined in: packages/lexical-history/src/index.ts:873

The parentEditor to use, by default it is derived from config.parentEditor which can be provided by NestedEditorExtension

Type Aliases​

HistoryState​

HistoryState = object

Defined in: packages/lexical-history/src/index.ts:70

The undo/redo history maintained by the history plugin: the current entry plus the undoStack and redoStack of previous and future HistoryStateEntrys. Create an empty one with createEmptyHistoryState and pass it to the history plugin to share history across editors.

Properties​

current​

current: null | HistoryStateEntry

Defined in: packages/lexical-history/src/index.ts:71

redoStack​

redoStack: HistoryStateEntry[]

Defined in: packages/lexical-history/src/index.ts:72

undoStack​

undoStack: HistoryStateEntry[]

Defined in: packages/lexical-history/src/index.ts:73


HistoryStateEntry​

HistoryStateEntry = object

Defined in: packages/lexical-history/src/index.ts:59

Properties​

editor​

editor: LexicalEditor

Defined in: packages/lexical-history/src/index.ts:60

editorState​

editorState: EditorState

Defined in: packages/lexical-history/src/index.ts:61

Variables​

HistoryExtension​

const HistoryExtension: LexicalExtension<HistoryConfig, "@lexical/history/History", HistoryExtensionOutput, HistoryExtensionInit>

Defined in: packages/lexical-history/src/index.ts:761

Registers necessary listeners to manage undo/redo history stack and related editor commands, via the @lexical/history module.


SharedHistoryExtension​

const SharedHistoryExtension: LexicalExtension<SharedHistoryConfig, "@lexical/history/SharedHistory", NamedSignalsOutput<{ disabled: boolean; parentEditor: LexicalEditor | null; }>, unknown>

Defined in: packages/lexical-history/src/index.ts:881

Registers necessary listeners to manage undo/redo history stack and related editor commands, via the @lexical/history module, only if the parent editor has a history plugin implementation.

Functions​

createEmptyHistoryState()​

createEmptyHistoryState(): HistoryState

Defined in: packages/lexical-history/src/index.ts:674

Creates an empty history state.

Returns​

HistoryState

  • The empty history state, as an object.

registerHistory()​

registerHistory(editor, historyState, delay, dateNow?, onHistoryStateChange?, maxDepth?): () => void

Defined in: packages/lexical-history/src/index.ts:544

Registers necessary listeners to manage undo/redo history stack and related editor commands. It returns unregister callback that cleans up all listeners and should be called on editor unmount.

Parameters​

editor​

LexicalEditor

The lexical editor.

historyState​

HistoryState

The history state, containing the current state and the undo/redo stack.

delay​

number | ReadonlySignal<number>

The time (in milliseconds) the editor should delay generating a new history stack, instead of merging the current changes with the current stack.

dateNow?​

() => number

The clock function used for delay-based merging.

onHistoryStateChange?​

(state) => void

Optional callback invoked once on registration and again any time historyState is mutated (push, pop, clear, etc.). It is NOT invoked when a candidate update is discarded without changing the stacks. Useful for keeping derived values (e.g. signals) in sync with the current HistoryState.

maxDepth?​

number | ReadonlySignal<number | null> | null

The maximum number of entries the undo stack may hold. When the cap is exceeded a new history event has been pushed the oldest entries are dropped from the front of the stack until the stack length is maxDepth. Pass null (the default) to keep the stack unbounded — the historical behavior. May be a plain number or a ReadonlySignal<number | null> for reactive reconfiguration.

Returns​

The listeners cleanup callback function.

() => void