Plate
PlateEditorsCreateTemplates
GitHub16kGitHub
DiscordDiscord
  • From Plite to Plate

From Plite to Plate

PreviousNext

Move a Plite React editor to Plate's editor, plugin, and rendering model.

Plate keeps Plite's document model and moves editor setup, rendering, events, and command wiring into plugins. Migrate the editor shell first, then move custom rendering and behavior into plugins.

Install

pnpm add platejs
pnpm add platejs

Use feature packages only for the nodes, marks, or behavior you add to the editor. Plate UI users should start with Plate UI instead of rebuilding every component by hand.

Unchanged Imports

Plate re-exports Plite's document model with the same bindings. Unless Renamed And Dropped Names lists a value, change only its import path: becomes , and becomes . , , , and the rest of the document API work as before. , , , , , and re-export their Plite entrypoint whole.

Details DemoOverview

On This Page

InstallUnchanged ImportsMigration MapEditor ShellCustom ElementsCustom BehaviorEvents And ShortcutsAPI CallsHeadless CodeRenamed And Dropped NamesEditor And PluginsRenderingHooksTypesDOMReview And AnnotationsRelated
Build your editor
Production-ready AI template and reusable components.
Get all-access
plitejs
platejs
plitejs/<entrypoint>
platejs/<entrypoint>
editor.read
editor.update
tx
NodeApi
platejs/diff
platejs/history
platejs/hyperscript
platejs/pagination
platejs/testing
platejs/yjs
platejs/yjs/react

Migration Map

Plite surfacePlate surface
useEditor(options) from plitejs/react, which creates an editoruseCreateEditor(options) in React components, or createEditor(options) in factories and tests. Plate's useEditor() returns the editor from context.
useEditorContext()useEditor().
<EditorRoot> plus <Editable><EditorRoot> plus <EditorContent>.
renderElement / renderLeaf switch statementsPlugin components through .configure({ component }).
Plite pluginsConstructor api, read, selectors, update, native Plite fields, and format mappings built by defineFormats.
Top-level event handlers on EditablePlugin on or shortcuts.
editor.update(...)Keep the transaction boundary; add plugin-owned commands through update.
editor.read(...)Keep the read boundary; add plugin-owned queries through read.

Editor Shell

Move the editor value into the editor creation call and render the editable with EditorContent.

components/editor.tsx
'use client';
 
import { EditorRoot, EditorContent, useCreateEditor } from 'platejs/react';
 
const initialValue = [
  {
    children: [{ text: 'Hello world.' }],
    type: 'paragraph',
  },
];
 
export function Editor() {
  const editor = useCreateEditor({
    initialValue,
  });
 
  return (
    <EditorRoot editor={editor}>
      <EditorContent className="p-4" />
    </EditorRoot>
  );
}
components/editor.tsx
'use client';
 
import { EditorRoot, EditorContent, useCreateEditor } from 'platejs/react';
 
const initialValue = [
  {
    children: [{ text: 'Hello world.' }],
    type: 'paragraph',
  },
];
 
export function Editor() {
  const editor = useCreateEditor({
    initialValue,
  });
 
  return (
    <EditorRoot editor={editor}>
      <EditorContent className="p-4" />
    </EditorRoot>
  );

Use createEditor({ ... }) when the editor is created outside React memoization.

lib/create-editor.ts
import { createEditor } from 'platejs/react';
 
export const editor = createEditor({
  initialValue: [
    {
      children: [{ text: 'Draft' }],
      type: 'paragraph',
    },
  ],
});
lib/create-editor.ts
import { createEditor } from 'platejs/react';
 
export const editor = createEditor({
  initialValue: [
    {
      children: [{ text: 'Draft' }],
      type: 'paragraph',
    },
  ],
});

Custom Elements

Replace renderElement branches with node plugins. Use .configure({ component }) when the only change is the React component.

components/editor/paragraph-plugin.tsx
import {
  ParagraphPlugin,
  EditorElement,
  type EditorElementProps,
} from 'platejs/react';
 
export function ParagraphElement({
  children,
  ...props
}: EditorElementProps<typeof ParagraphPlugin>) {
  return (
    <EditorElement className="m-0 px-0 py-1" {...props}>
      {children}
    </EditorElement>
  );
}
 
export const AppParagraphPlugin = ParagraphPlugin.configure({ component: ParagraphElement });
components/editor/paragraph-plugin.tsx
import {
  ParagraphPlugin,
  EditorElement,
  type EditorElementProps,
} from 'platejs/react';
 
export function ParagraphElement({
  children,
  ...props
}: EditorElementProps<typeof ParagraphPlugin>) {
  return (
    <EditorElement className="m-0 px-0 py-1" {...props}>
      {children}
    </EditorElement>
  );
}
 
export const AppParagraphPlugin = ParagraphPlugin.configure({ component: ParagraphElement });

If an existing document uses a different persisted type, remap that element in the closed editor schema. Plugin configuration cannot rewrite schema identity.

components/editor/document-editor.tsx
import { schema } from 'platejs';
import { createEditor } from 'platejs/react';
 
const editor = createEditor({
  plugins: [AppParagraphPlugin],
  schema: {
    overrides: [
      schema.override(AppParagraphPlugin, {
        element: { type: 'p' },
      }),
    ],
  },
});
components/editor/document-editor.tsx
import { schema } from 'platejs';
import { createEditor } from 'platejs/react';
 
const editor = createEditor({
  plugins: [AppParagraphPlugin],
  schema: {
    overrides: [
      schema.override(AppParagraphPlugin, {
        element: { type: 'p' },
      }),
    ],
  },
});

Custom Behavior

Put a reusable document command under the plugin's update contribution. The command is available inside editor.update(...) under the plugin name.

components/editor/signature-plugin.tsx
import { definePlugin } from 'platejs/react';
 
export const SignaturePlugin = definePlugin('signature', {
  update: ({ tx }) => ({
    insert() {
      tx.text.insert(' - Signed');
    },
  }),
});
components/editor/signature-plugin.tsx
import { definePlugin } from 'platejs/react';
 
export const SignaturePlugin = definePlugin('signature', {
  update: ({ tx }) => ({
    insert() {
      tx.text.insert(' - Signed');
    },
  }),
});

Call it from a shortcut, toolbar, menu item, or test:

commands.ts
editor.update((tx) => {
  tx.signature.insert();
});
commands.ts
editor.update((tx) => {
  tx.signature.insert();
});

Element plugins already receive schema-inferred insert, set, and remove updates. Do not wrap those generic operations in a feature method.

components/editor/callout-plugin.tsx
import { schema } from 'platejs';
import { definePlugin } from 'platejs/react';
 
export const CalloutPlugin = definePlugin('callout', {
  schema: {
    element: schema.element.textBlock(),
  },
});
components/editor/callout-plugin.tsx
import { schema } from 'platejs';
import { definePlugin } from 'platejs/react';
 
export const CalloutPlugin = definePlugin('callout', {
  schema: {
    element: schema.element.textBlock(),
  },
});
commands.ts
editor.plugin(CalloutPlugin).update.insert();
commands.ts
editor.plugin(CalloutPlugin).update.insert();

Add a custom update only when it performs behavior beyond those generic node operations. Keep that method flat and task-shaped; the portal already owns the plugin noun.

Use api for plugin-scoped immutable services, read for snapshot-local queries, and the root native Plite fields for commands, corrections, read middleware, lifecycle, activation, validation, and other substrate behavior. Combine independent fields in the constructor. Use .extend() only for an imported/prebuilt declaration, a shared factory the constructor cannot access, or an earlier-stage type dependency.

Events And Shortcuts

Move editor events into the plugin that owns the behavior.

components/editor/tab-plugin.tsx
import { definePlugin } from 'platejs/react';
 
export const TabPlugin = definePlugin('tab', {
  on: {
    keyDown: ({ event }) => {
      if (event.key !== 'Tab') return false;
 
      event.preventDefault();
 
      return true;
    },
  },
});
components/editor/tab-plugin.tsx
import { definePlugin } from 'platejs/react';
 
export const TabPlugin = definePlugin('tab', {
  on: {
    keyDown: ({ event }) => {
      if (event.key !== 'Tab') return false;
 
      event.preventDefault();
 
      return true;
    },
  },
});

Use shortcuts when the key combination should call a plugin API, transform, or explicit handler.

components/editor/save-plugin.tsx
import { definePlugin } from 'platejs/react';
 
export const SavePlugin = definePlugin('save', {
  shortcuts: {
    draft: {
      keys: 'mod+s',
      handler: ({ event }) => {
        event.preventDefault();
 
        return true;
      },
    },
  },
});
components/editor/save-plugin.tsx
import { definePlugin } from 'platejs/react';
 
export const SavePlugin = definePlugin('save', {
  shortcuts: {
    draft: {
      keys: 'mod+s',
      handler: ({ event }) => {
        event.preventDefault();
 
        return true;
      },
    },
  },
});

API Calls

Plate keeps reads and writes separate. Read editor state with editor.read(...). Mutate the document with editor.update(...). Use editor.api.* for plugin services and host/runtime APIs, not document mutations.

editor-commands.ts
const text = editor.read((state) => state.text.string([]));
 
editor.update((tx) => {
  tx.marks.toggle('bold');
  tx.text.insert('Hello');
});
 
editor.api.debug.log(text);
editor-commands.ts
const text = editor.read((state) => state.text.string([]));
 
editor.update((tx) => {
  tx.marks.toggle('bold');
  tx.text.insert('Hello');
});
 
editor.api.debug.log(text);

Headless Code

Use createEditor from platejs for non-React importers, serializers, transforms, and tests.

lib/headless-editor.ts
import { createEditor } from 'platejs';
 
export const editor = createEditor({
  initialValue: [
    {
      children: [{ text: 'Headless document.' }],
      type: 'paragraph',
    },
  ],
});
lib/headless-editor.ts
import { createEditor } from 'platejs';
 
export const editor = createEditor({
  initialValue: [
    {
      children: [{ text: 'Headless document.' }],
      type: 'paragraph',
    },
  ],
});

Renamed And Dropped Names

These tables list each Plite value that Plate drops, renames, or exports under the same name with a different contract, and the types an app imports with them. Every other value keeps its binding, as Unchanged Imports says.

Editor And Plugins

PlitePlateNotes
useEditor(options, deps)useCreateEditor(options, deps)Plate's useEditor() takes no arguments and returns the editor from context.
useEditorContext()useEditor()
useOptionalEditorContext()useOptionalEditor()
useCaretEditor()useEditor() outside EditorContentOutside every editing area, useEditor() returns the editor of the root that holds the caret.
createEditor(options)createEditor(options) from platejs, or from platejs/react in ReactThe options are the same except clipboardFormatKey, which Plate refuses.
definePlugin(name, definition)definePlugin(name, definition) from platejs, or from platejs/react in ReactThe definition fields are the same. The result is a Plate plugin with .configure() and .extend(), and a name key inside the definition throws.
useCommand(command, options)editor.update.command(command, input), with the editor from useEditor()Plate has no root or focus option for a command.

Rendering

PlitePlateNotes
EditableEditorContentMove renderElement, renderLeaf, renderText, renderPlaceholder and renderVoid into plugin components. The other props carry over.
PagedEditable from plitejs/pagination/reactPagedEditorContent from platejs/pagination/reactThe render props move into plugin components, as with EditorContent.
VirtualizedEditable from plitejs/react/virtualizedVirtualizedEditorContent from platejs/react/virtualizedThe render props move into plugin components, as with EditorContent.
EditorPlaceholderplaceholder on EditorContent, or BlockPlaceholderPlugin for empty blocksPlate has no renderPlaceholder.
EditorRootEditorRootonValueChange receives the whole document value, { children, ... }, instead of the children array. Plate's EditorRoot has no authorId, decorations, document or root prop. Pass userId to createEditor, decorate through a plugin's decorate, and set root on EditorContent. To render another document, create an editor for it with createEditor({ initialValue }).
EditorElement, EditorLeaf, EditorTextEditorElement, EditorLeaf, EditorTextPlate's take the props a plugin component receives, so spread them: <EditorElement {...props}>. Plite's read the node from context.
EditorReadOnlyProviderreadOnly on EditorRoot or EditorContent
useClaimEditableDOMCommit, setDOMTextSyncRendererCapability, setRetainedTextFlowRendererCapabilityNonePlate's renderers call them for every plugin component.

Hooks

PlitePlateNotes
useEditorSelector(selector, options)useEditorSelector(selector, options)The options are equalityFn and shouldUpdate only. The hook follows the editor of the root that holds the caret.
useEditorState(selector, options)useEditorState(selector, options)There is no deferred option.
useEditorSelection, useEditorFocused, useEditorComposing, useEditorReadOnlyThe same namesThe calls are the same. Plate reads the selected editing area.
useOptionalEditorReadOnly()useEditorReadOnly()Plate always returns a boolean.
useEditorHistory(options)useEditorHistory(options)The options are the same.
useElement<MyElement>()useElement(MyPlugin)useElement() without arguments still returns the nearest element, and throws outside an element component.
useOptionalElement()NoneCall useElement() inside an element plugin's component.
useNodeSelector(selector)useElementSelector(selector) inside an element componentThe selector receives the element. Plate has no hook that selects a node by key.
useTextSelector(selector)NoneA text plugin component receives its text in props.
useEditorEditableElement()useEditableRef()The ref is null before mount and does not rerender when the element mounts. useEditorMounted() returns a boolean.

Types

PlitePlateNotes
EditablePropsEditorContentPropsPlate's EditableProps is an internal renderer type.
PagedEditableProps, VirtualizedEditablePropsPagedEditorContentProps, VirtualizedEditorContentProps
UseEditorOptionsCreateEditorOptions
EditorSelectorOptions, EditorStateSelectorOptionsUseEditorSelectorOptions, UseEditorStateOptions
EditorRootProps, ValueChangeContextThe same namesvalue is the whole document value.
NodeProps from plitejs/reactNodeProps from platejsNodeProps from platejs/react types the props a plugin injects into its node.
Editor, PluginThe same namesPlate's take other type parameters, and Plugin is the type of a Plate plugin.
ReactPluginRuntimeReactPlugin

DOM

platejs/dom keeps ariaKeyShortcuts, dataTransferFormats, domCommands, DOMResolutionError, isHotkey, usesAppleDOMHotkeys and writeDataTransferFragment. The other plitejs/dom values map as follows.

PlitePlateNotes
DOMEditor.focus(editor) and the other DOMEditor methodseditor.api.dom.focus() and the other editor.api.dom methodsDrop the editor argument.
getEditorDOMRoot(editor)editor.api.dom.root()
domNonecreateEditor from platejs/react installs Plate's DOM plugin. A headless editor adds DOMPlugin from platejs.
getDOMClipboardFormatKey, writeDOMFragmentData, writeDOMRangeData, cleanDOMClipboardContentseditor.api.dom.clipboard and a plugin's dataTransferFormats
HotkeysHotkeys from platejsPlate's set has other members.
createCompiledHotkeyMatcher, KeyisHotkey, or a plugin's shortcuts
readDOMSelectionRange, writeDOMSelectionNoneEditorContent reads and writes the DOM selection.
isEditor, isElement, isLeaf, isNode, isString, isText, isVoid, getElements, getNodeDataAttributeKeys, keyToDataAttributeNoneThey read Plite's DOM data attributes. isEditor from platejs is a different function that checks an editor object.
getSelection, getActiveElement, getDefaultView, isDOMNode, isDOMElement, isDOMText, isDOMSelection, hasShadowRoot, closestShadowAware, containsShadowAware, isAfter, isBefore, normalizeDOMPoint, isPlainTextOnlyPaste, CAN_USE_DOM, isGeckoDOMHost, TRIPLE_CLICKNoneUse the DOM API.
DOMCoverage, isTrackedMutation, applyStringDiff, mergeStringDiffs, normalizeStringDiff, normalizePoint, normalizeRange, targetRange, verifyDiffStateNoneEditorContent owns DOM coverage, mutation tracking and Android input diffs.

Review And Annotations

PlitePlateNotes
authored({ authorId }) from plitejs/authoredAuthoredPlugin from platejs/authored in pluginsThe author is the editor's userId, or the authorId of a view from createEditorView.
authoredRecordsNoneAuthoredPlugin installs it.
createAuthoredPluginNoneIt is Plite's test helper with fixed ids and clock.
AuthoredPlugin typetypeof AuthoredPluginPlate's AuthoredPlugin is the plugin value.
createAnnotationStore from plitejs/annotationsuseAnnotationStore(editor, annotations, options) from platejs/reactPlate has no headless annotation store. The annotation types move to platejs/react.

Related

  • Editor for editor creation options.
  • Plugin Components for replacing renderElement and renderLeaf.
  • Plugin Methods for .configure() and typed .extend() contributions.
  • Plugin Shortcuts for keyboard command wiring.
}