@platejs/slate is the framework-free editor runtime. It owns document values,
roots, operations, schema extensions, state fields, read APIs, transaction
groups, and pure node/location helper namespaces.
Installation
pnpm add @platejs/slatepnpm add @platejs/slateUse @platejs/slate in package code that should not import React or Plate core.
Framework packages such as @platejs/slate-react and @platejs/core/react
mount this runtime instead of replacing it.
Quick Use
import { createEditor } from '@platejs/slate';
const editor = createEditor({
initialValue: [{ children: [{ text: 'Hello' }], type: 'p' }],
});
editor.update((tx) => {
tx.text.insert(' world');
});
const text = editor.read((state) => state.text.string([]));import { createEditor } from '@platejs/slate';
const editor = createEditor({
initialValue: [{ children: [{ text: 'Hello' }], type: 'p' }],
});
editor.update((tx) => {
tx.text.insert(' world');
});
const text = editor.read((state) => state.text.string([]));createEditor returns an editor with explicit read(...) and update(...)
boundaries. Reads observe committed state. Writes run inside transaction groups.
Package Surface
| Surface | Export | Use |
|---|---|---|
| Editor factory | createEditor | Creates a framework-free Slate editor. |
| Runtime views | createEditorRuntime, createEditorView | Create one committed runtime and optional root-scoped editor views. |
| Editor types | Editor, BaseEditor, Value, InitialValue, Selection, ValueOf | Type editor instances, document values, and selection state. |
| Read API | EditorStateView, EditorStateValueApi, EditorStateSelectionApi, EditorStateTextApi | Read committed state inside editor.read(...). |
| Transaction API | EditorUpdateTransaction, EditorTransactionValueApi, EditorTransactionNodesApi, EditorTransactionSelectionApi | Mutate editor state inside editor.update(...). |
| Interfaces | ElementApi, NodeApi, TextApi, PathApi, PointApi, RangeApi, OperationApi | Typed helpers for Slate data structures. |
| Refs | PathRef, PointRef, RangeRef | Mutable location refs that track editor operations. |
| Extensions | defineEditorExtension, defineStateField, elementProperty | Register schema facts, state groups, tx groups, normalizers, middleware, and commit hooks. |
Editor Shape
An Editor contains committed document state plus explicit read and update
entrypoints.
| Field | Type | Use |
|---|---|---|
children | Value | Primary document children. |
selection | Selection | Current selection. |
operations | Operation[] | Operations applied since the last change flush. |
marks | EditorMarks | null | Marks applied to the next inserted text. |
read | <T>(fn: (state) => T) => T | Read committed state. |
update | (fn: (tx, context) => void, options?) => void | Commit model, selection, mark, root, operation, and state-field writes. |
API Map
| Page | Covers |
|---|---|
| Editor API | Read methods on editor.read(...) state groups. |
| Editor Transforms | Transaction methods on editor.update(...) tx groups. |
| Node | Node, descendant, ancestor, and node-entry helpers. |
| Element | Element types, element props, and element guards. |
| Text | Text node types, mark objects, and text guards. |
| Path | Path comparison, movement, ancestry, and transform helpers. |
| Point | Point comparison, edge checks, and point transforms. |
| Range | Range checks, edge helpers, intersection, inclusion, and transforms. |
| Location | Path, Point, Range, and Span location unions. |
| Location Ref | PathRef, PointRef, and RangeRef affinity behavior. |
| Operation | Slate operation types, operation lists, and operation inversion. |
History
editor.update((tx) => {
tx.history.withNewBatch(() => {
tx.text.insert('Title');
tx.text.insertBreak();
});
tx.history.withoutSaving(() => {
tx.selection.select([]);
});
});editor.update((tx) => {
tx.history.withNewBatch(() => {
tx.text.insert('Title');
tx.text.insertBreak();
});
tx.history.withoutSaving(() => {
tx.selection.select([]);
});
});History is a Slate extension. It stores undo and redo batches, exposes history state through read groups, and exposes undo/redo plus batching helpers through transaction groups.
Extension Authoring
Extensions register schema facts, state groups, transaction groups, normalizers, operation middleware, commit listeners, and runtime APIs.
Use api for mounted host/runtime services. Use tx for feature commands that
change Slate model state.
import {
defineEditorExtension,
defineStateField,
elementProperty,
} from '@platejs/slate';import {
defineEditorExtension,
defineStateField,
elementProperty,
} from '@platejs/slate';Helper Namespaces
Pure data helpers live on ElementApi, LocationApi, NodeApi,
OperationApi, PathApi, PathRefApi, PointApi, PointRefApi, RangeApi,
RangeRefApi, SpanApi, and TextApi.
Inside editor.read(...) and editor.update(...), prefer grouped state.*
and tx.* APIs. Use helper namespaces when library code needs pure operations
on Slate data outside an editor transaction.
Related APIs
- Plate shows where
@platejs/slateis re-exported from theplatejsumbrella package. - Plate Editor covers the React/Core editor layer built on top of this package.