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

Editing Behavior

PreviousNext

Understand how browser input, transactions, changes, corrections, commits, rendering, and proof fit together.

Editing behavior is the path from user intent to committed Plite state. Use this page for the runtime pipeline; use Selection And DOM for caret, native selection, and DOM coverage rules.

Choose The Right Surface

Most editing bugs come from putting behavior in the wrong layer.

SurfaceUse it whenOwner
Editable event propsOne React editable needs a local browser shortcut or event hook.@platejs/plite-react
editor.update((tx) => ...)A command should change the document, selection, marks, roots, or state.
Document StateSelection And DOM

On This Page

Choose The Right SurfaceRuntime PipelineEvent HandlersTransactionsCommand HandlersChanges And CorrectionsCommits And ReactBrowser ProofRecipes
Build your editor
Production-ready AI template and reusable components.
Get all-access
@platejs/plite
Extension commandsA reusable semantic action should compose across browser, programmatic, and test callers.@platejs/plite
clipboardHandler(...) contributionPaste or drop ingress needs package-owned DOM policy.@platejs/plite-dom
DOM coverage boundariesModel content exists but its DOM is intentionally hidden or virtualized.@platejs/plite-dom and @platejs/plite-react
@platejs/browserA behavior claim needs model, DOM, native selection, focus, trace, screenshot, or follow-up typing proof.@platejs/browser

Use Editable for UI-local event interception. Use transactions and extensions for editor behavior that should survive another input path.

Runtime Pipeline

Plite edits run through explicit owners.

StageWhat happensOwner
Browser eventThe browser sends key, beforeinput, input, paste, cut, drop, focus, drag, or selection events.Browser
Editable handlerEditable runs app handlers and decides whether Plite should continue.@platejs/plite-react
Input importPlite imports the relevant DOM/native selection when the browser owns the current edit target.@platejs/plite-react and @platejs/plite-dom
Command dispatchPure extension command handlers consume, delegate, or compose typed semantic actions.@platejs/plite
Transactioneditor.update((tx) => ...) groups model writes into one runtime change.@platejs/plite
Canonical changePlite builds one root-aware DocumentChange for the complete transaction.@platejs/plite
CorrectionsBuilt-in and extension corrections repair changed ranges to a deterministic fixed point.@platejs/plite
CommitSubscribers, history, React, replay, collaboration adapters, and proof tools observe one committed change.@platejs/plite
Render and repairReact renders the new state and exports a valid DOM/native selection when needed.@platejs/plite-react
ProofBrowser tests assert the model, DOM, native selection, focus, trace, and follow-up typing that matter for the claim.@platejs/browser

The important rule is simple: user intent can arrive through many browser paths, but Plite behavior should land in the transaction pipeline when it changes editor state.

Event Handlers

Editable event props are the right tool for editor-local UI behavior.

import { Editable } from "@platejs/plite-react";
 
<Editable
  onKeyDown={(event, { editor }) => {
    if (!(event.metaKey && event.key === "k")) return false;
 
    editor.update((tx) => {
      tx.text.insert("link");
    });
 
    return true;
  }}
/>;
import { Editable } from "@platejs/plite-react";
 
<Editable
  onKeyDown={(event, { editor }) => {
    if (!(event.metaKey && event.key === "k")) return false;
 
    editor.update((tx) => {
      tx.text.insert("link");
    });
 
    return true;
  }}
/>;

Return true when your handler owns the event. Return false when Plite should keep running its default behavior.

Use Plite React Event Handling for the exact handler return contract.

Transactions

Transactions are the write boundary. They group related changes and publish one commit.

editor.update((tx) => {
  tx.text.insert("Hello");
  tx.marks.toggle("bold");
  tx.selection.collapse({ edge: "end" });
});
editor.update((tx) => {
  tx.text.insert("Hello");
  tx.marks.toggle("bold");
  tx.selection.collapse({ edge: "end" });
});

Keep writes inside one update when they belong to one user action. That gives history, subscribers, React rendering, change replay, and proof tooling one commit to observe.

Use Transforms for the concept guide and Transforms API for the exact transaction groups.

Command Handlers

Reusable semantic behavior belongs in pure extension command handlers when it should apply outside one React event.

import {
  defineExtension,
  editorCommands,
  RangeApi,
} from "@platejs/plite";
 
const shortcuts = defineExtension("shortcuts", {
  commands: ({ handle }) => [
    handle(editorCommands.insertText, ({ input, state }) => {
      const selection = state.selection();
 
      if (input.text !== " " || !selection || !RangeApi.isCollapsed(selection)) {
        return false;
      }
 
      return state.transaction((tx) => {
        tx.nodes.set({ type: "heading-one" });
        tx.text.insert(input.text, input.options);
      });
    }),
  ],
});
import {
  defineExtension,
  editorCommands,
  RangeApi,
} from "@platejs/plite";
 
const shortcuts = defineExtension("shortcuts", {
  commands: ({ handle }) => [
    handle(editorCommands.insertText, ({ input, state }) => {
      const selection = state.selection();
 
      if (input.text !== " " || !selection || !RangeApi.isCollapsed(selection)) {
        return false;
      }
 
      return state.





Use built-in definitions such as editorCommands.insertText, editorCommands.insertBreak, editorCommands.delete, and editorCommands.replaceSlice. A handler returns false or an immutable TransactionSpec. Returning false delegates to the next handler or the built-in implementation. Use around(descriptor, handler) from the command factory only when a handler must rewrite input or compose with downstream behavior.

Changes And Corrections

DocumentChange is the replay boundary. Plite corrects the affected regions before publishing the final change.

editor.update({ tags: "remote-import" }, (tx) => {
  tx.changes.apply(DocumentChange.fromJSON(remoteChange));
});
editor.update({ tags: "remote-import" }, (tx) => {
  tx.changes.apply(DocumentChange.fromJSON(remoteChange));
});

Use Document Changes for replay and mapping. Use Normalizing when a structural edit can leave the document temporarily invalid.

Commits And React

A finished update publishes one commit. Runtime subscribers can observe it, history can batch it, React can render from it, and browser proof can inspect the aftermath.

const unsubscribe = editor.subscribe((_snapshot, change) => {
  if (change?.changed.has("document") || change?.dirtyStateKeys.length) {
    saveDocument(editor.read.value());
  }
});
const unsubscribe = editor.subscribe((_snapshot, change) => {
  if (change?.changed.has("document") || change?.dirtyStateKeys.length) {
    saveDocument(editor.read.value());
  }
});

React UI should read narrow editor facts through hooks where possible. App services can subscribe to commits when they need persistence, analytics, replay, or sync work.

Browser Proof

Model-only tests do not prove browser editing. DOM-only tests do not prove Plite correctness.

import { openExample } from "@platejs/browser/playwright";
 
const editor = await openExample(page, "plaintext", {
  ready: { editor: "visible" },
});
 
await editor.focus();
await editor.type("Hello");
await editor.assert.text("Hello");
await editor.assert.selection({
  anchor: { path: [0, 0], offset: 5 },
  focus: { path: [0, 0], offset: 5 },
});
await editor.assert.noDoubleSelectionHighlight();
import { openExample } from "@platejs/browser/playwright";
 
const editor = await openExample(page, "plaintext", {
  ready: { editor: "visible" },
});
 
await editor.focus();
await editor.type("Hello");
await editor.assert.text("Hello");
await editor.assert.selection({
  anchor: { path: [0, 0], offset: 5 },
  focus: { path: [0, 0], offset: 5 },
});
await editor.assert.noDoubleSelectionHighlight();

Use Browser when a claim depends on browser events, focus, native selection, screenshots, clipboard, replay, or follow-up typing.

Recipes

GoalStart with
Add one local hotkeyPlite React Event Handling
Write a reusable commandCommands and Transforms
Change Enter, Backspace, Delete, or typed text behaviorCommands and Extensions
Preserve valid document shapeNormalizing
Apply document changes from storage or syncCanonical Change Substrate
Debug caret or DOM selection bugsSelection And DOM
Own paste, copy, drop, or fragment import policyClipboard And Paste
Build comments, highlights, diagnostics, or overlay UIProjection And Overlays
Prove a browser editing claimBrowser

Done. You can now place an editing behavior in the layer that owns it.

transaction
((
tx
)
=>
{
tx.nodes.set({ type: "heading-one" });
tx.text.insert(input.text, input.options);
});
}),
],
});