Create React-backed editors with useEditor when a React component owns
the editor lifetime.
import { EditorRoot, useEditor } from "plitejs/react";
const MyEditor = () => {
const editor = useEditor({
initialValue: [{ type: "paragraph", children: [{ text: "" }] }],
});
return <EditorRoot editor={editor}>...</EditorRoot>;
};import { EditorRoot, useEditor } from "plitejs/react";
useEditor creates one editor for the component lifetime and installs
React, DOM, and clipboard capabilities. Install the history() plugin when
undo and redo are needed. The editor exposes host APIs through editor.api.
editor.api.dom.focus();
editor.api.dom.clipboard.insertTextData(dataTransfer);
editor.api.react.isComposing();editor.api.dom.focus();
editor.api.dom.clipboard.insertTextData(dataTransfer);
editor.api.react.isComposing();Its plugins take outside resources, such as a Yjs document, when React
commits the component, and give them back when it unmounts or its deps
replace the editor.
Use createEditor when the editor is created outside a component. It is
live when it returns, and editor.destroy() ends it.
import { createEditor } from "plitejs/react";
const editor = createEditor({
initialValue: [{ type: "paragraph", children: [{ text: "" }] }],
});import { createEditor } from "plitejs/react";
const editor = createEditor({
initialValue: [{ type: "paragraph", children: [{ text: "" }] }],
});Use the lower-level react({ dom }) plugin only when composing plugins
through createEditor. Pass the exact DOM descriptor that React installs as a
dependency.
import { createEditor as createCoreEditor } from "plitejs";
import { dom } from "plitejs/dom";
import { react } from "plitejs/react";
const DOMPlugin = dom();
const editor = createCoreEditor({
plugins: [react({ dom: DOMPlugin })],
initialValue: [{ type: "paragraph", children: [{ text: "" }] }],
});
Configure the internal Plite clipboard payload with clipboardFormatKey.
import { createEditor } from "plitejs/react";
const editor = createEditor({
clipboardFormatKey: "x-acme-editor-fragment",
initialValue,
});import { createEditor } from "plitejs/react";
const editor = createEditor({
clipboardFormatKey: "x-acme-editor-fragment",
initialValue,
});See React Editor for DOM, focus, selection, and clipboard APIs.