@lexical/history
Interfaces
HistoryConfig
Defined in: packages/lexical-history/src/index.ts:620
Properties
createInitialHistoryState
createInitialHistoryState: (
editor) =>HistoryState
Defined in: packages/lexical-history/src/index.ts:629
The initial history state, the default is createEmptyHistoryState.
Parameters
editor
Returns
delay
delay:
number
Defined in: packages/lexical-history/src/index.ts:625
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:633
Whether history is disabled or not
maxDepth
maxDepth:
number|null
Defined in: packages/lexical-history/src/index.ts:649
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:637
The now() function, defaults to Date.now.
Returns
number
HistoryExtensionOutput
Defined in: packages/lexical-history/src/index.ts:667
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:672
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:677
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:679
The merge-delay in milliseconds forwarded to registerHistory.
disabled
disabled:
Signal<boolean>
Defined in: packages/lexical-history/src/index.ts:681
When true the history listener is not registered.
historyState
historyState:
Signal<HistoryState>
Defined in: packages/lexical-history/src/index.ts:683
The active HistoryState instance.
maxDepth
maxDepth:
Signal<number|null>
Defined in: packages/lexical-history/src/index.ts:689
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:691
The clock function forwarded to registerHistory.
SharedHistoryConfig
Defined in: packages/lexical-history/src/index.ts:772
Properties
disabled
disabled:
boolean
Defined in: packages/lexical-history/src/index.ts:776
Whether shared history is disabled or not
parentEditor
parentEditor:
LexicalEditor|null
Defined in: packages/lexical-history/src/index.ts:782
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:67
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:68
redoStack
redoStack:
HistoryStateEntry[]
Defined in: packages/lexical-history/src/index.ts:69
undoStack
undoStack:
HistoryStateEntry[]
Defined in: packages/lexical-history/src/index.ts:70
HistoryStateEntry
HistoryStateEntry =
object
Defined in: packages/lexical-history/src/index.ts:56
Properties
editor
editor:
LexicalEditor
Defined in: packages/lexical-history/src/index.ts:57
editorState
editorState:
EditorState
Defined in: packages/lexical-history/src/index.ts:58
Variables
HistoryExtension
constHistoryExtension:LexicalExtension<HistoryConfig,"@lexical/history/History",HistoryExtensionOutput,HistoryExtensionInit>
Defined in: packages/lexical-history/src/index.ts:698
Registers necessary listeners to manage undo/redo history stack and related editor commands, via the @lexical/history module.
SharedHistoryExtension
constSharedHistoryExtension:LexicalExtension<SharedHistoryConfig,"@lexical/history/SharedHistory",NamedSignalsOutput<{disabled:boolean;parentEditor:LexicalEditor|null; }>,unknown>
Defined in: packages/lexical-history/src/index.ts:790
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:612
Creates an empty history state.
Returns
- The empty history state, as an object.
registerHistory()
registerHistory(
editor,historyState,delay,dateNow?,onHistoryStateChange?,maxDepth?): () =>void
Defined in: packages/lexical-history/src/index.ts:482
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
The lexical editor.
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