Registry / web-framework / slate
library0.5.2jsnpmunverified

Slate is a unopinionated and completely customizable framework for building rich text editors, providing a foundational set of primitives rather than a monolithic solution. It allows developers to create bespoke editing experiences by composing plugins and extending its core data model. Currently at version `0.124.1` (core `slate` package), it maintains an active development pace with frequent patch and minor releases across its monorepo packages (e.g., `slate-react`, `slate-history`, `slate-dom`). Key differentiators include its pluggable architecture, a robust data model representing content as a nested tree, and deep integration with React for rendering. This approach enables it to be adapted for a wide range of applications, from simple note-taking to complex document authoring systems, by avoiding prescriptive UI/UX decisions.

npm install slate
INSTALL
IMPORT
SIG · SLATE
S
slate
web-frameworkjavascriptv0.5.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createEditor
import { createEditor } from 'slate';
const createEditor = require('slate').createEditor;
Primary function to initialize a new Slate editor instance. Modern usage strongly favors ESM imports.
Slate, Editable, withReact
import { Slate, Editable, withReact } from 'slate-react';
const { Slate, Editable, withReact } = require('slate-react');
These are the core components and HOC for integrating Slate into a React application. `withReact` is essential for connecting the Slate editor to React's rendering lifecycle.
Descendant, Editor, Element, Text
import { Descendant, Editor, Element, Text } from 'slate';
These are fundamental TypeScript types for defining the structure of Slate content and extending the editor's capabilities. Developers must extend these in their application's `CustomTypes`.
withHistory
import { withHistory } from 'slate-history';
Used as an editor enhancer to add undo/redo capabilities.

This quickstart demonstrates how to set up a basic Slate editor with React and TypeScript, including custom type definitions and simple bold text rendering. It shows the initialization of the editor with `createEditor`, `withReact`, and `withHistory`, and then renders it using the `Slate` provider and `Editable` component.

import React, { useMemo, useState } from 'react'; import { createEditor, Descendant } from 'slate'; import { Slate, Editable, withReact, ReactEditor } from 'slate-react'; import { withHistory } from 'slate-history'; // Define our custom editor and element types for TypeScript to enable type safety type CustomEditor = ReactEditor; type ParagraphElement = { type: 'paragraph'; children: CustomText[] }; type CustomText = { text: string; bold?: boolean; italic?: boolean }; declare module 'slate' { interface CustomTypes { Editor: CustomEditor; Element: ParagraphElement; Text: CustomText; } } const initialValue: Descendant[] = [ { type: 'paragraph', children: [{ text: 'Hello, Slate!' }], }, { type: 'paragraph', children: [{ text: 'This is some ' }, { text: 'bold', bold: true }, { text: ' text.' }], }, ]; const MySimpleEditor = () => { // Create a Slate editor object that won't change across renders. // It's enhanced with React capabilities and history (undo/redo). const editor = useMemo(() => withHistory(withReact(createEditor())), []); const [value, setValue] = useState<Descendant[]>(initialValue); return ( <Slate editor={editor} value={value} onChange={setValue}> <Editable placeholder="Start typing..." // Define a rendering function for elements renderElement={props => <p {...props.attributes}>{props.children}</p>} // Define a rendering function for leaf nodes (text with formatting) renderLeaf={props => { let children = props.children; if (props.leaf.bold) children = <strong>{children}</strong>; if (props.leaf.italic) children = <em>{children}</em>; return <span {...props.attributes}>{children}</span>; }} style={{ border: '1px solid #ccc', padding: '10px', minHeight: '100px' }} /> </Slate> ); }; export default MySimpleEditor;
Debug
Known issues
breakingSlate's `0.x` versioning scheme means that minor versions (`0.x.y` to `0.z.w` where `x != z`) can introduce significant breaking changes to the API and internal data structures. Users should always review the changelog when updating minor versions.
fix
Thoroughly review release notes for each minor version upgrade. Expect to refactor code related to editor operations, data models, or plugin APIs. Consult migration guides if available.
affects: >=0.x
gotchaThe `slate@0.123.0` release introduced new, more efficient type discriminators like `Location.isPath`, `Location.isPoint`, `Location.isRange`, and `Location.isSpan`. While the older `Path.isPath`, `Point.isPoint`, etc., still exist, the new `Location` prefixed versions are recommended for better performance and consistency.
fix
Update existing code to use `Location.isPath`, `Location.isPoint`, `Location.isRange`, and `Location.isSpan` where appropriate, especially in performance-critical loops or frequently called functions.
affects: >=0.123.0
gotchaEnsuring the `Slate` component properly handles editor updates in `slate-react` requires careful management of the editor instance. If the `editor` object itself is re-created or mutated in a way that React's `useEffect` hooks don't track, the editor might not reflect changes correctly.
fix
Always initialize your editor instance using `useMemo` to ensure it's stable across renders, as shown in the quickstart. If your editor needs to dynamically change based on props, ensure `editor` is correctly listed as a dependency in relevant `useEffect` hooks, or pass an immutable editor instance.
affects: >=0.124.0
Errors
Common errors & fixes
Type 'MyCustomEditor' is not assignable to type 'ReactEditor'. Type 'MyCustomEditor' is missing the following properties from type 'ReactEditor': markIs) and related React DOM properties.
Incorrectly extending Slate's built-in TypeScript types (Editor, Element, Text) or failing to declare the custom types module.
fix
Ensure you have a `declare module 'slate' { interface CustomTypes { Editor: MyCustomEditor; Element: MyCustomElement; Text: MyCustomText; } }` block in a `.d.ts` file or at the top of your relevant TypeScript file, and that your custom types correctly extend the base Slate types (`ReactEditor`, `BaseElement`, `BaseText`).
Error: Editor instance not found in context. This is likely because you've used `useEditor` outside of a `<Slate>` context.
Attempting to use `Editable` or any Slate-related hooks (`useEditor`, `useSlate`, etc.) outside of a `<Slate>` component context.
fix
Wrap your `Editable` component and any custom components utilizing Slate hooks within the `<Slate editor={editor} value={value} onChange={setValue}>` provider component.
Cannot read properties of undefined (reading 'children') when rendering a custom element.
Your `renderElement` or `renderLeaf` function is not correctly handling different types of nodes or is expecting properties that aren't present on the given node.
fix
Add a `default` case to your `switch` statement in `renderElement` and `renderLeaf` to handle unexpected node types gracefully. Ensure all custom element types you define in `CustomTypes` are explicitly handled in `renderElement`.
Upgrade
Version history
0.5.2latest on npm
Audit
Dependencies
reactrequiredRequired for `slate-react`, the primary way to integrate Slate into web applications.
react-domrequiredRequired for `slate-react` for rendering the editor.
slate-historyoptionalCommonly used for undo/redo functionality in a Slate editor setup.
Agent activity
16 hits · last 30 days
node
14
Resources
slate — npm install slate · libregistry