From zbeyens. The source code is available on GitHub.

Plate
PlatePliteEditorsTemplates
GitHub16kGitHub
DiscordDiscord
UNPUBLISHED
  • Overview
  • Why This Fork
  • Examples
Walkthroughs
  • Installing Plite
  • Adding Event Handlers
  • Defining Custom Elements
  • Applying Custom Formatting
  • Executing Commands
  • Saving to a Database
  • Canonical Change Substrate
  • Improving Performance
Concepts
  • Interfaces
  • Nodes
  • Locations
  • Transforms
  • Document Changes
  • Commands
  • Editor
  • Extensions
  • Rendering
  • Serializing
  • Normalizing
  • Using TypeScript
  • Roots
  • Document State
  • Editing Behavior
  • Selection And DOM
  • Clipboard And Paste
  • Projection And Overlays
  • Schema
API
  • Anchor API
  • Location API
  • Path API
  • PointEntry API
  • Point API
  • Range API
  • Selection API
  • Location Types APIs
  • Span API
  • Editor
  • Element API
  • NodeEntry API
  • Node API
  • Node Types APIs
  • Text API
  • Debug Value Scrubbing
  • Transforms API
Libraries
  • Plite DOM
  • History Editor API
  • History Extension Setup
  • History
  • Plite History
  • Plite Hyperscript
  • Plite Layout
  • Annotations
  • DOM Coverage Boundaries
  • Editable Component
  • Plite React Event Handling
  • Virtualized Rendering
  • Plite React Hooks
  • React Editor Setup
  • React Editor
  • Plite React
  • Plite Component
  • Plite Yjs
  • Plite
General
  • Migration
  • Contributing
  • Docs Proof Map
  • FAQ
  • Resources

History Editor API

PreviousNext

Read history state, run undo/redo transactions, and control history batches.

History adds owner-local read and update groups instead of mutating the root editor object.

State API

state.history(): History

Read the full history value.

state.history.undos(): readonly Batch[]

Plite DOMHistory Extension Setup

On This Page

State APIstate.history(): Historystate.history.undos(): readonly Batch[]state.history.redos(): readonly Batch[]Transaction APItx.history.undo(): voidtx.history.redo(): voidtx.history.skip(): voidtx.history.merge(): voidtx.history.newBatch(): voidUpdate Policyeditor.update({ history: "skip" }, fn): voideditor.update({ history: "merge" }, fn): voideditor.update({ history: "new-batch" }, fn): voideditor.update.history.undo(): voideditor.update.history.redo(): voidTypes
Build your editor
Production-ready AI template and reusable components.
Get all-access

Read the undo stack.

state.history.redos(): readonly Batch[]

Read the redo stack.

Transaction API

tx.history.undo(): void

Undo the previous history batch.

tx.history.redo(): void

Redo the next history batch.

tx.history.skip(): void

Do not save the current transaction to history.

tx.history.merge(): void

Merge the current transaction into the previous compatible undo batch.

tx.history.newBatch(): void

Start a fresh undo batch for the current transaction.

Update Policy

editor.update({ history: "skip" }, fn): void

Run one update without saving it to history.

editor.update({ history: "merge" }, fn): void

Run one update that merges into the previous compatible undo batch.

editor.update({ history: "new-batch" }, fn): void

Run one update where the first write starts a fresh history batch, then the rest of the callback merges into that batch.

Configure a direct write by calling editor.update(policy) first.

editor.update({ history: "skip" }).text.insert("draft");
editor.update({ history: "skip" }).text.insert("draft");

editor.update.history.undo(): void

Undo the previous history batch outside a larger transaction.

editor.update.history.redo(): void

Redo the next history batch outside a larger transaction.

Types

import type {
  DocumentChange,
  EditorEffect,
  EditorSchemaIdentity,
  Selection,
} from "@platejs/plite";
 
type History = {
  readonly redos: readonly Batch[];
  readonly revision: number;
  readonly schema: EditorSchemaIdentity;
  readonly undos: readonly Batch[];
};
 
type Batch = {
  readonly change: DocumentChange;
  readonly effects: readonly EditorEffect[];
  readonly selectionAfter: Selection;
  readonly selectionAfterRoot?: string;
  readonly selectionBefore: Selection;
  readonly selectionBeforeRoot?: string;
};
import type {
  DocumentChange,
  EditorEffect,
  EditorSchemaIdentity,
  Selection,
} from "@platejs/plite";
 
type History = {
  readonly redos: readonly Batch[];
  readonly revision: number;
  readonly schema: EditorSchemaIdentity;
  readonly undos: readonly Batch[];
};
 
type Batch = {
  readonly change: DocumentChange;
  readonly effects: readonly EditorEffect[];




Persist the installed stacks with History.toJSON(editor). Decode them with History.fromJSON(editor, json), then install the returned value through tx.history.restore(...). Custom standalone effects belong to an installed extension's effects resource so their keyed versioned codecs can decode the batch. The version 4 envelope requires the current derived or named schema identity and rejects null or mismatched schema semantics before decoding a batch.

Compatible typing and same-node property updates coalesce from canonical DocumentChange classifications and changed ranges. Grouping fingerprints are runtime-only; loading persisted history starts a fresh automatic group.

readonly selectionAfter: Selection;
readonly selectionAfterRoot?: string;
readonly selectionBefore: Selection;
readonly selectionBeforeRoot?: string;
};