Back to Plate

Version History

content/docs/examples/version-history.mdx

53.0.81.9 KB
Original Source

This example stores immutable Plate value snapshots in local React state. It compares the selected revision with the current value through @platejs/diff.

Demo

<ComponentPreview name="version-history-demo" />

Source

<ComponentSource name="version-history-demo" />

Runtime Shape

PieceOwnerRole
createVersionSnapshotregistry exampleClones each Value with cloneDeep before saving or diffing.
revisionsregistry exampleStores the saved Plate values and feeds the revision picker.
computeDiff@platejs/diffCompares the selected revision and live value, then returns diff-marked nodes.
DiffPluginregistry exampleRenders diff leaves and wraps diff elements with insert, delete, or update styling.
InlinePlugin and InlineVoidPluginregistry exampleKeep inline and inline-void nodes in the demo value so the diff path covers mixed content.
withGetFragmentExcludeDiff@platejs/diffRemoves diff and diffOperation metadata from copied fragments.

Snapshot Flow

  1. The editor starts from initialValue and keeps the live value in local state.
  2. Save revision clones the live value and appends it to revisions.
  3. The select menu chooses one saved revision for comparison.
  4. computeDiff receives the selected revision, current value, editor.api.isInline, and lineBreakChar: '¶'.
  5. The read-only diff editor renders the returned value with the same inline plugins plus DiffPlugin.

Product Preview

Potion uses the same document-history idea in a full app surface with stored versions, restore actions, and visual comparison.

<ComponentPreview name="potion-iframe-demo" />