Migrate from Slate and Plate
Migrate from Slate or Plate to GoTipe by mapping stored values, elements and leaves, replacing the React editor and porting transforms and collaboration.
This guide is for teams that run Slate, or Plate on top of Slate, in production, store the editor value as JSON and want to move to GoTipe. It walks through the data first, then the code. Slate lets every application define its own schema, so the data step depends on the element names you use; the guide shows the names Slate's examples use and a rewrite for Plate's.
What moves and what does not
Moves automatically, with @gotipe/migration:
- Elements with the names of Slate's examples: paragraphs,
heading-onetoheading-sixorheadingwithlevel,block-quote,code-block, bulleted, numbered and check lists, tables, images withurl, horizontal rules, and links withurlorhref. - Text leaves with
bold,italic,underline,strikethrough,code,subscript,superscript,highlightandcolor, elementids andalign.
Needs your work:
- Element names of your own schema: you map them, or declare your own types as GoTipe extensions.
- Plate values: Plate names its elements differently and keeps lists as flat blocks, so you rewrite the value into the names the converter knows first (see Plate values).
- Inline elements such as mentions: GoTipe has no inline nodes, so a mention becomes text with an atomic mark.
- Editor code: the
SlateandEditablecomponents,renderElement,renderLeaf, plugins, transforms and serializers. - Collaboration: Yjs state is not converted. You convert a snapshot of each document and start collaborating in GoTipe from it.
Not migrated at all: undo history, selection, operations, Yjs updates and the behaviour of plugins and normalizeNode.
Concept map
| Slate | GoTipe | Docs |
|---|---|---|
with |
use; History is in every preset |
React |
< |
The content option of useEditor |
Quick start |
onChange, onValueChange, on |
onUpdate, on, or editor.on() |
Events |
< |
Editor or EditorContent from @gotipe/react |
Components |
renderElement with Render |
blockViews with BlockViewProps |
Block views |
renderLeaf |
The renderer draws the built-in marks; decorations for the rest | Plugins and decorations |
placeholder, readOnly of Editable |
Placeholder extension, editable: false or editor. |
Behaviours |
useSlate, useSlateStatic |
use, use |
Hooks |
useSelected, useFocused, useReadOnly |
isSelected, readOnly props of a block view; focus and blur events |
Block views |
Transforms., setNodes, wrapNodes, unwrapNodes |
Steps insertBlock, setBlockAttrs, setBlockType; list commands |
Transactions |
Transforms., Transforms. |
setSelection(), insert |
Commands |
Editor.addMark, Editor. |
add, remove, toggle |
Marks |
Editor. |
editor. |
Reading state |
editor.undo(), editor.redo() |
editor.undo(), editor.redo() |
History |
Plugins withX(editor) |
Extensions from defineExtension |
Writing extensions |
editor.isInline, editor.isVoid |
content: "empty" blocks; atomic marks for inline tokens |
Inline atoms |
normalizeNode |
The schema validates every transaction | Document model |
editor.onChange, editor. |
The transaction event with transaction, before and after |
Events |
A serialize function of your own |
getHTML(), getMarkdown(), getText(), renderToHtml |
Content formats |
@slate-yjs/core |
@gotipe/ and the CRDT of the WASM engine |
Collaboration |
Plate builds on Slate and adds its own API:
| Plate | GoTipe |
|---|---|
use, <Plate>, < |
use, Editor |
create, create |
defineExtension |
BoldPlugin and the other plugins of @platejs/ |
DefaultPreset or FullPreset from @gotipe/ |
editor., editor. |
toggleBold() or toggle, set |
editor. |
editor. |
editor., deserialize(md) |
editor., parse |
serialize from platejs/static |
render from @gotipe/ |
YjsPlugin from @platejs/yjs |
@gotipe/ |
The document model differs in one way that matters everywhere: a GoTipe document is a tree of blocks with IDs, declared by a schema, and the text of a block is a list of spans with marks. There are no inline elements, and an element field the schema does not declare is rejected. See Document model.
| Slate element or leaf | GoTipe |
|---|---|
paragraph, an element without a type |
paragraph |
heading-one … heading-six, heading with level |
heading with level |
block-quote, code-block |
blockquote, codeBlock |
bulleted-list, numbered-list, list-item |
bulletList, orderedList, listItem |
check-list, check-list-item |
todoList, todoItem with checked |
table, table-row, table-cell, table-header |
table, tableRow, tableCell, tableHeader |
image with url, horizontal-rule |
image with src, divider |
link with url or href |
The link mark |
{ text, bold: true } and the other leaf properties |
Spans with bold, italic, underline, strikethrough, code, subscript, superscript, highlight, textColor |
Step 1: Install GoTipe
npm install @gotipe/core @gotipe/react @gotipe/markdown @gotipe/migration react react-dompnpm add @gotipe/core @gotipe/react @gotipe/markdown @gotipe/migration react react-domyarn add @gotipe/core @gotipe/react @gotipe/markdown @gotipe/migration react react-dombun add @gotipe/core @gotipe/react @gotipe/markdown @gotipe/migration react react-dom@gotipe/migration is needed only by the conversion script. For the ready editor UI with the / menu and block handle, add the commercial @gotipe/block-editor; see installation. For collaboration, add @gotipe/wasm and @gotipe/collaboration (step 7).
Step 2: Convert stored documents
Put the schema in one module and use it in both the script and the editor, so that a document the script accepts is one the editor accepts:
import { defineExtension } from "@gotipe/core";
import { Mention } from "@gotipe/core/extensions";
import { FullPreset } from "@gotipe/core/presets";
import { markdownRawNodeSpec } from "@gotipe/markdown";
// Holds source content the converter could not represent, as its JSON.
export const MarkdownRaw = defineExtension({ name: "markdownRaw", nodes: [markdownRawNodeSpec] });
export const extensions = [...FullPreset, Mention, MarkdownRaw];A batch script
This script reads one Slate value per file, converts it, checks it against the schema and writes the result. It runs in Node; the converter loads no editor and no DOM. The value is the array that onChange gives you and that Slate's "Saving to a Database" walkthrough stores with JSON.stringify.
import { mkdir, readdir, readFile, writeFile } from "node:fs/promises";
import path from "node:path";
import { createId } from "@gotipe/core";
import { createHeadlessEditor } from "@gotipe/core/server";
import { convertSlateToGoTipe } from "@gotipe/migration";
import { extensions } from "./schema";
type SlateNode = { type?: string; text?: string; children?: SlateNode[]; [key: string]: unknown };
// GoTipe has no inline nodes: a mention element becomes a leaf that markTypeMap turns into a mark.
function mentionsToLeaves(node: SlateNode): SlateNode {
if (node.type === "mention") {
const label = String(node.character ?? "");
return { text: `@${label}`, mention: { id: label, label, key: createId() } };
}
return node.children ? { ...node, children: node.children.map(mentionsToLeaves) } : node;
}
const input = "export/slate";
const output = "export/gotipe";
await mkdir(output, { recursive: true });
const editor = await createHeadlessEditor({ extensions });
for (const name of await readdir(input)) {
if (!name.endsWith(".json")) continue;
const value: SlateNode[] = JSON.parse(await readFile(path.join(input, name), "utf8"));
const result = convertSlateToGoTipe(value.map(mentionsToLeaves), {
blockTypeMap: { code: "codeBlock", quote: "blockquote" },
markTypeMap: { mention: "mention" },
});
for (const warning of result.warnings) console.warn(`${name}: ${warning}`);
if (!editor.validate(result.document)) {
console.error(`${name}: does not fit the schema, not written`);
continue;
}
const record = { document: result.document, unmapped: result.unmapped, preserved: result.preserved };
await writeFile(path.join(output, name), JSON.stringify(record));
}
editor.destroy();Here code and quote are the names Slate's walkthroughs use, and character is the field of the mention in Slate's mentions example; replace them with the names of your schema. Run the script on a copy of production data first, read the warnings, and keep the source data until you have checked the result on your own documents. The converter rejects values that are not JSON, such as undefined, so leave a field out of your own rewrites instead of setting it to undefined.
Read the result
| Field | What to do with it |
|---|---|
result.document |
The GoTipe document. Store it in place of the Slate value. |
result.warnings |
One message per problem, with the source path, such as [3].children[0]: preserved subtrees, replaced IDs, fields that do not fit. Log them and review a sample. |
result. |
Subtrees kept as JSON in a markdownRaw block (kind: "json"): blockId, source path, sourceType and reason. Each one is content to port by hand or with a mapping. |
result.unmapped |
Element fields that have no GoTipe attribute, tied to the block by blockId. Store them if you may need them later. |
A preserved block is valid content: the editor shows it, and nothing is lost. It is not editable as the original element, so aim for zero entries in preserved before the switch.
Custom element and leaf types
blockTypeMap and markTypeMap add names the converter does not know. They rename types; they do not convert fields:
- A GoTipe type, such as
{ code: "codeBlock" }, gets the attributes its schema declares; the other element fields go tounmapped. - A type of your own gets the element's fields as they are, so its extension must declare them. The converter gives it rich text; for a void element declared with
content: "empty", setcontenttonullbefore validating. markTypeMapmaps a leaf property to a mark.truegives a mark without attributes, an object gives its attributes, and a string gives thecoloroftextColororhighlight.- An inline element needs a rewrite before the conversion, as
mentionsToLeavesdoes above.
Strict mode
While you build the mappings, strict: true makes the converter throw UnsupportedContent on the first element or leaf property it cannot convert, with the source path and the reason:
import { UnsupportedContent, convertSlateToGoTipe } from "@gotipe/migration";
export function findUnsupported(value: unknown): string | null {
try {
convertSlateToGoTipe(value, { strict: true, blockTypeMap: { code: "codeBlock" } });
return null;
} catch (error) {
if (error instanceof UnsupportedContent) return `${error.path}: ${error.reason}`;
throw error;
}
}The full list of converted elements, fields, options and limits is in Migration.
Plate values
A Plate value is a Slate value with Plate's element names: p, h1 to h6, blockquote, a, img, hr, code_block with code_line children, table, tr, td and th. Plate's list plugin keeps list items as flat blocks with listStyleType and indent instead of nested lists. This rewrite turns such a value into the names the converter knows, nests the lists and turns mentions into leaves:
import { createId } from "@gotipe/core";
type PlateNode = { type?: string; text?: string; children?: PlateNode[]; [key: string]: unknown };
const HEADINGS: Record<string, number> = { h1: 1, h2: 2, h3: 3, h4: 4, h5: 5, h6: 6 };
const NUMBERED = new Set(["decimal", "lower-alpha", "upper-alpha", "lower-roman", "upper-roman"]);
function element(node: PlateNode): PlateNode {
if (typeof node.text === "string") return node;
const { type = "", children = [], ...rest } = node;
if (type in HEADINGS) return { ...rest, type: "heading", level: HEADINGS[type], children: blocks(children) };
if (type === "a") return { ...rest, type: "link", children: blocks(children) };
if (type === "mention") {
const label = String(rest.value ?? "");
return { text: `@${label}`, mention: { id: label, label, key: createId() } };
}
if (type === "code_block") {
const { lang, ...attrs } = rest;
const lines = children.map((line) => (line.children ?? []).map((leaf) => leaf.text ?? "").join(""));
if (typeof lang === "string") attrs.language = lang;
return { ...attrs, type: "code-block", children: [{ text: lines.join("\n") }] };
}
if (type === "td" || type === "th") {
const { colSpan, rowSpan, ...attrs } = rest;
if (typeof colSpan === "number") attrs.colspan = colSpan;
if (typeof rowSpan === "number") attrs.rowspan = rowSpan;
return { ...attrs, type, children: blocks(children) };
}
return { ...rest, type, children: blocks(children) };
}
// Nests the flat list blocks of Plate's list plugin by their `indent`.
function blocks(nodes: PlateNode[]): PlateNode[] {
const out: PlateNode[] = [];
const open: { depth: number; style: string; list: PlateNode }[] = [];
for (const node of nodes) {
const { listStyleType, indent, listStart, checked, ...block } = node;
if (typeof listStyleType !== "string") {
open.length = 0;
out.push(element(node));
continue;
}
const depth = typeof indent === "number" ? indent : 1;
while (open.length && open[open.length - 1].depth > depth) open.pop();
const top = open[open.length - 1];
if (top && top.depth === depth && top.style !== listStyleType) open.pop();
const todo = listStyleType === "todo";
const item: PlateNode = {
type: todo ? "check-list-item" : "list-item",
...(todo ? { checked: checked === true } : {}),
children: [element(block)],
};
const current = open[open.length - 1];
if (current && current.depth === depth) {
current.list.children?.push(item);
continue;
}
const list: PlateNode = {
type: todo ? "check-list" : NUMBERED.has(listStyleType) ? "numbered-list" : "bulleted-list",
...(typeof listStart === "number" ? { start: listStart } : {}),
children: [item],
};
if (current) current.list.children?.at(-1)?.children?.push(list);
else out.push(list);
open.push({ depth, style: listStyleType, list });
}
return out;
}
export function plateToSlate(value: PlateNode[]): PlateNode[] {
return blocks(value);
}Then convert with the remaining names in the maps:
import { convertSlateToGoTipe } from "@gotipe/migration";
import { plateToSlate } from "./plate-to-slate";
export function convertPlate(value: Parameters<typeof plateToSlate>[0]) {
return convertSlateToGoTipe(plateToSlate(value), {
blockTypeMap: {
p: "paragraph",
blockquote: "blockquote",
img: "image",
hr: "divider",
table: "table",
tr: "tableRow",
td: "tableCell",
th: "tableHeader",
},
markTypeMap: { backgroundColor: "highlight", mention: "mention" },
});
}Paths in the warnings refer to the rewritten value. What else to expect from a Plate value:
- Plate's classic list plugin (
ul,ol,li,lic) needs no rewrite: mapultobulletList,oltoorderedList,litolistItemandlictoparagraph. alignon paragraphs and headings is kept when it isleft,center,rightorjustify;startandendgo tounmapped, as doindentoutside lists, a table'scolSizesand an image'scaption.- Leaves with
fontSize,fontFamilyorkbdhave no GoTipe mark: their paragraph is kept as JSON unless you map or remove those properties in the rewrite. - Callouts, toggles, columns, equations and other Plate elements are kept as JSON unless you map them.
Step 3: Replace the editor component
A minimal Slate editor and its GoTipe counterpart:
import { useState } from "react";
import { type Descendant, createEditor } from "slate";
import { withHistory } from "slate-history";
import { Editable, Slate, withReact } from "slate-react";
export function NotesEditor({ value, onSave }: { value: Descendant[]; onSave: (value: Descendant[]) => void }) {
const [editor] = useState(() => withHistory(withReact(createEditor())));
return (
<Slate editor={editor} initialValue={value} onValueChange={onSave}>
<Editable placeholder="Write something" />
</Slate>
);
}import type { Document } from "@gotipe/core";
import { Placeholder } from "@gotipe/core/extensions";
import { Editor, useEditor } from "@gotipe/react";
import { extensions } from "./schema";
export function NotesEditor({ content, onSave }: { content: Document; onSave: (doc: Document) => void }) {
const editor = useEditor({
extensions: [...extensions, Placeholder.configure({ text: "Write something" })],
content,
onUpdate: ({ editor }) => onSave(editor.getJSON()),
});
return <Editor editor={editor} ariaLabel="Notes" />;
}With Plate, usePlateEditor, <Plate> and <PlateContent /> are replaced the same way. Differences to know:
- There is no
renderElementswitch and norenderLeaf. The renderer draws every built-in block and mark; you give views only for the block types you want to draw yourself. useEditorreturnsnulluntil the editor exists, andEditorrenders nothing while it isnull. Options are read once; to load another document, calleditor.setContent(doc).@gotipe/reactships no CSS. Style.gotipe-contentyourself, or useBlockEditorwith@gotipe/theme; see installation.- Images and files are read-only in
Editoruntil you provide@gotipe/react/media; see image and file editing.
For a ready editing surface with the / menu, the block handle and the formatting bubble, pass the editor to BlockEditor from @gotipe/block-editor; see Block editor.
Step 4: Port custom elements and leaves
Each element type of your schema becomes a node spec, and its renderElement branch becomes a block view:
import { defineExtension } from "@gotipe/core";
export const Notice = defineExtension({
name: "notice",
nodes: [
{
name: "notice",
group: ["block"],
content: "richText",
attrs: { tone: { type: "enum", values: ["info", "warning"], default: "info" } },
topLevel: true,
marksAllowed: "all",
leaf: false,
allowsChildren: false,
},
],
});import type { BlockViewProps } from "@gotipe/react";
// Was: case "notice": return <aside {...attributes}>{children}</aside>; in renderElement.
export function NoticeView({ block, rootProps, content }: BlockViewProps) {
const className = ["notice", rootProps.className].filter(Boolean).join(" ");
return (
<aside {...rootProps} data-block-type="notice" data-tone={String(block.attrs.tone ?? "info")} className={className}>
{content}
</aside>
);
}
// <Editor editor={editor} blockViews={{ notice: NoticeView }} />Add Notice to the extensions of schema.ts and { notice: "notice" } to blockTypeMap.
| Slate | GoTipe |
|---|---|
| An element whose children are text | content: "rich |
| An element whose children are elements | allows, and childTypes to limit them |
A void element (editor.isVoid) |
content: "empty", leaf: true |
An inline element (editor.isInline), such as a link or a mention |
A mark; an atomic mark for a token the caret must not enter |
| Element fields | attrs: every attribute declared with a type; undeclared ones are rejected |
Render: attributes, children, element |
BlockViewProps: rootProps, content and children, block |
A leaf property and its renderLeaf branch |
A mark in marks |
normalizeNode rules |
Constraints of the node spec: topLevel, childTypes, marksAllowed |
The React and Vue renderers draw only the built-in marks, so text with a mark of your own renders unformatted; show it with an inline decoration from a plugin (see Writing extensions). An inline element becomes a mark with atomic: true: the text is its fallback and the caret never enters it. See Inline atoms.
Behaviour that a withX(editor) plugin added by overriding insertText or insertData moves to the extension's inputRules, pasteRules, transformPastedText and parsePastedText. An input rule is tested against the whole text of the block; see input rules.
Step 5: Port transforms and events
Slate transforms take paths and points. GoTipe commands act on the selection, and transactions name blocks by ID and text by UTF-16 offset:
| Slate | GoTipe |
|---|---|
Editor. |
editor., or add |
Transforms. |
chain(). |
Transforms. |
chain(). |
Transforms. with a list |
toggle, toggle, toggle |
Transforms. |
insert, or an insertBlock step |
Transforms. |
set |
Transforms. |
insert |
editor.undo(), editor.redo() |
editor.undo(), editor.redo() |
A helper of your own becomes a function that takes the editor:
import type { GoTipeEditor } from "@gotipe/core";
export function insertNotice(editor: GoTipeEditor, tone: "info" | "warning" = "info"): boolean {
return editor.chain().focus().insertBlockAfter("notice", { tone }).run();
}A chain runs as one transaction and one undo step, and the editor checks the whole result against the schema before anything changes; see Transactions.
| Slate | GoTipe event |
|---|---|
onChange, onValueChange of <Slate> |
update, with origin: "local" or "remote" |
on |
selectionChange |
editor.onChange with editor. |
transaction, with transaction, before and after |
onKeyDown of Editable |
keybindings of an extension |
editor.on(event, handler) returns the function that removes the handler. Saving a value no longer needs a check for selection-only operations: update fires only when the document changes, or a mark is toggled at the caret.
Step 6: Markdown and HTML
Slate ships no serializers; GoTipe has them built in. editor.getMarkdown() writes GitHub-flavoured Markdown and replaces Plate's editor.api.markdown.serialize(). To load Markdown, parse it with @gotipe/markdown:
import type { GoTipeEditor } from "@gotipe/core";
import { parseMarkdown } from "@gotipe/markdown";
export function loadMarkdown(editor: GoTipeEditor, text: string) {
editor.setContent(parseMarkdown(text).doc);
}The parser keeps Markdown the editor cannot edit (HTML, footnotes) as markdownRaw blocks and mdRaw text, so register both, as Content formats shows. If you stored Markdown rather than the value, you need no converter: parse the files.
editor.getHTML() replaces an HTML serialize function of your own or Plate's serializeHtml, and editor.setContent(html) replaces a deserialize function; HTML import runs in the browser only. On a server, renderToHtml(doc) from @gotipe/core/server renders without a DOM, and its blockRenderers option gives your own block types their HTML. HTML import knows the built-in elements, and the exporters write a type they do not know as a paragraph with its text. See Server rendering. editor.getText() joins the text of all blocks with \n, as the plain-text serializer of Slate's docs does.
Step 7: Collaboration
There is no automatic conversion of Yjs state. GoTipe does not read a Y.Doc, @slate-yjs/core or @platejs/yjs state, and GoTipe's own CRDT starts from a plain document. Move each shared document this way:
- Stop edits to the document in Slate or Plate, for example by making it read-only for the switch.
- Take a snapshot of the value from an editor connected to the document: the value of
onChange, oreditor.childrenin Plate. - Convert the snapshot with
@gotipe/migrationas in step 2. - Store the result as the document's new baseline, for example with
POST /v1/documentsof GoTipe Cloud (REST API). - Open it in GoTipe with
engine: "wasm"and@gotipe/collaboration, as in Connect to GoTipe Cloud.
Edits made after the snapshot are not in GoTipe, so take it last. The Yjs update history, cursors and undo stacks are not carried over. Collaboration in GoTipe needs the WASM engine; with your own server, use the editor's collaboration methods (Your own transport).
What GoTipe does not have
- A schema-free document. Slate accepts any element shape; GoTipe accepts only the block types and attributes its extensions declare.
- Inline elements. Links, mentions and other inline tokens are marks on text; an inline element with its own children has no counterpart.
- Rendering every element and leaf yourself. Views replace blocks one type at a time, and the React and Vue renderers draw only the built-in marks.
- Method overrides and normalization. There is no
normalizeNode,isInlineorinsertDatato override; extensions declare node specs, rules and hooks. - Operations and paths. Changes are transactions of steps on block IDs, not Slate operations on paths.
- Yjs interoperability. GoTipe's CRDT is its own;
@slate-yjs/coreand Plate'sYjsPlugindo not connect to it. - Plate's plugin set. Font size and family, indentation of any block, and Plate elements without a GoTipe block type need a port or stay as JSON.
- Converter coverage for every schema. Element names outside the table in Migration need a mapping or stay as JSON.
Related
- Migration: the converter's options, result and limits.
- Document model and Writing extensions
- React and Block editor
- Collaboration