Skip to main content

@lexical/history

Interfaces

HistoryConfig

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

Properties

createInitialHistoryState

createInitialHistoryState: (editor) => HistoryState

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

The initial history state, the default is createEmptyHistoryState.

Parameters
editor

LexicalEditor

Returns

HistoryState

delay

delay: number

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

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:595

Whether history is disabled or not

now

now: () => number

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

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

Returns

number


HistoryExtensionOutput

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

The output signals exposed by HistoryExtension.

Config-derived signals (delay, disabled, historyState, 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:622

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:627

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:629

The merge-delay in milliseconds forwarded to registerHistory.

disabled

disabled: Signal<boolean>

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

When true the history listener is not registered.

historyState

historyState: Signal<HistoryState>

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

The active HistoryState instance.

now

now: Signal<() => number>

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

The clock function forwarded to registerHistory.


SharedHistoryConfig

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

Properties

disabled

disabled: boolean

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

Whether shared history is disabled or not

parentEditor

parentEditor: LexicalEditor | null

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

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:58

Properties

current

current: null | HistoryStateEntry

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

redoStack

redoStack: HistoryStateEntry[]

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

undoStack

undoStack: HistoryStateEntry[]

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


HistoryStateEntry

HistoryStateEntry = object

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

Properties

editor

editor: LexicalEditor

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

editorState

editorState: EditorState

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

Variables

HistoryExtension

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

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

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:731

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:574

Creates an empty history state.

Returns

HistoryState

  • The empty history state, as an object.

registerHistory()

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

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

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.

Returns

The listeners cleanup callback function.

() => void