Tiptap Editor
A Notion-style rich-text editor on Tiptap 3 with a Liquid Glass surface — slash menu, selection bubble, block drag handle, tables, columns, cards, toggles, math, code, embeds, attachments and four kinds of diagrams — plus a read-only renderer.
TiptapEditor is a block (registry:block) built on Tiptap 3:
- Blocks: headings, lists and to-dos, quotes, highlighted code, tables (row / column handles), responsive columns, cards, toggles (
detailsin the reader), resizable icons, KaTeX formulas, images, file attachments, video / Figma / web embeds, and Mermaid, Excalidraw, mind map and draw.io diagrams. - Editing: type
/for the slash menu, select text for the formatting bubble, drag blocks by their handle, paste Markdown, import / export document files. - Liquid Glass surface: the editor is a glass panel like
Card(mediummaterial) with the toolbar on it; the slash menu and bubble aremenu-material glass, and every menu and dialog opened from the editor inherits its material.glass={false}renders it 100% opaque. - Both platforms: on iPhone (
< 768px) the toolbar wraps into iOS-size rows, the slash menu becomes a bottom drawer and the bubble docks to the bottom of the screen. - Lazy diagrams: Mermaid, Excalidraw, simple-mind-map and highlight.js are dynamic imports, fetched the first time a block of that kind appears. draw.io uses the official diagrams.net embed and needs network access to
embed.diagrams.net.
Installation (Shadcn Registry)
npx shadcn@latest add @apple-liquid/tiptap-editorUsage
'use client';
import * as React from 'react';
import { TiptapEditor } from '@/components/blocks/tiptap-editor';
export function ArticleForm() {
const [content, setContent] = React.useState('');
return <TiptapEditor value={content} onChange={setContent} contentClassName="h-[480px]" />;
}value/onChangeuse ProseMirror JSON strings; legacy HTML input is accepted.onChangeMarkdownhands you the derived Markdown.- The editor is uncontrolled while typing: an external
valueis applied only when it differs from the current document, so the caret never jumps. - Set the editing area's height with
contentClassName(e.g.h-[480px]ormax-h-[60vh]); it scrolls inside the glass panel while the toolbar stays put.
File uploads
Images and attachments go through a FileStorageAdapter you provide. The document stores only the durable value returned by upload; display URLs (often short-lived signed links) come from resolve at render time.
import type { FileStorageAdapter } from '@/components/blocks/tiptap-editor';
const storage: FileStorageAdapter = {
async upload(file, { nodeType, signal, onProgress }) {
const { key, url } = await uploadToYourStorage(`${nodeType}/${file.name}`, file, { signal, onProgress });
return { value: key, url };
},
resolve: (key, { signal }) => getSignedUrl(key, { signal }),
validate: (file, { nodeType }) =>
nodeType === 'image' && file.size > 20 * 1024 * 1024 ? 'Images must be under 20 MB' : undefined,
};
<TiptapEditor value={content} onChange={setContent} fileStorageAdapter={storage} />;Every callback receives nodeType (image, file, excalidraw, drawio or mindMap), so you can use a folder, size limit or permission per node type. When an external link to a file is re-hosted it is passed as file.
With an adapter, the editor also:
- stores pasted screenshots, dropped files and
blob:/data:images automatically: images follow the resource mode (uploaded and swapped for a stored key, or embedded as a data URL — see below), attachments are always uploaded; - lists external files that arrive by paste or import (images, attachments, links to files) and offers to save the checked ones to your storage. Browsers can only download files that allow cross-origin reads; provide
fetchRemote(usually your own server proxy) to cover the rest, andisOwnUrlfor URLs that are already yours (such as a public bucket domain).
The editor never deletes stored files — not even when an image is removed, since undo can bring it back. Clean up unused files in your own save flow.
About the live demo: Because this documentation site is statically exported without a backend, the preview above uses the browser's IndexedDB to simulate server uploads (
idb:<nodeType>/…keys, up to 10 MB per file). Files stay only in your local browser so you can test upload progress, storage keys, and inline/upload switching directly; in production, replace it with your own server or object storage (such as Cloudflare R2, S3, or Supabase Storage).
Inline or upload
The whole resource of an image, Excalidraw, draw.io or mind map node can live inside the document or in your storage:
| Node | Inline | Upload |
|---|---|---|
| Image | src is a data URL | The original file is uploaded; src is the stored key |
| Excalidraw / draw.io / mind map | Source data and SVG cache svg stay in the node | The whole diagram is uploaded as one JSON file ({ type, data, svg }); the node keeps only the src key |
resourceMode(default"upload") decides how new nodes are stored. Any node can be switched in its block menu under Storage; the whole resource is converted and the change can be undone.- Existing nodes keep their mode: editing an uploaded diagram uploads a new file, editing an inline one stays inline. If an upload fails the node is saved inline instead, so nothing is lost.
- Without a storage adapter every node is inline. Inline images must be PNG, JPEG, GIF, WebP or AVIF (the reader strips SVG data URLs).
- The editor and the reader fetch uploaded diagrams through
resolve.renderTiptapHtmloutputs only the stored key and the diagram loads in the browser, so passfileStorageAdapterto the reader as well. - Images added inside a diagram are always embedded as data URLs in its data. Two runtimes reach the network: the draw.io editor runs in an iframe on
embed.diagrams.net(the diagram XML is posted into it), and Excalidraw loads its hand-drawn fonts fromesm.shand embeds the glyphs it uses in the SVG cache. - Switching modes or re-uploading never deletes the previous file; clean up in your own save flow.
- Upload progress, failures and storage switches are reported with the library's
toast; mount<Toaster />once in your app to show them.
Reading view
TiptapContentRenderer renders saved content with the same styles and rebuilds the interactive parts: code chrome with copy, Mermaid, pannable diagrams, mind maps, embeds and toggles. It is transparent, so place it on your page or inside a Card.
import { TiptapContentRenderer } from '@/components/blocks/tiptap-editor';
<TiptapContentRenderer content={article.content} fileStorageAdapter={storage} />;For reader pages, render sanitized HTML on the server and pass it as html so the first paint doesn't wait for the editor schema:
// app/articles/[id]/page.tsx (Server Component)
import { renderTiptapHtml } from '@/components/blocks/tiptap-editor/renderer/server/render-html';
import { TiptapContentRenderer } from '@/components/blocks/tiptap-editor';
export default async function Page() {
const article = await getArticle();
return <TiptapContentRenderer html={renderTiptapHtml(article.content)} />;
}The server entry imports server-only; never import it from client code.
Language
All built-in text (toolbar, menus, dialogs, placeholders) follows <LiquidGlassProvider locale> in 12 languages, and the Excalidraw and draw.io interfaces switch with it. Override individual strings with messages:
<TiptapEditor messages={{ placeholder: 'Write your answer…' }} />Toolbar placement
showToolbar={false} hides the built-in toolbar so you can render EditorToolbar elsewhere (for example a sticky page header). Get the editor instance from onCreate:
const [editor, setEditor] = React.useState<Editor | null>(null);
<>
{editor && <EditorToolbar editor={editor} />}
<TiptapEditor showToolbar={false} onCreate={(instance) => setEditor(instance)} />
</>;Props API
TiptapEditor
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | — | ProseMirror JSON string (legacy HTML accepted) |
onChange | (doc: string, context) => void | — | Latest document JSON on every change |
onChangeMarkdown | (markdown: string) => void | — | Derived Markdown on every change |
onCreate | (editor: Editor, context) => void | — | Called once the editor instance is ready |
placeholder | string | Built-in text | Empty-paragraph hint |
editable | boolean | true | false makes it read-only and hides the toolbar |
showToolbar | boolean | true | Render the built-in toolbar |
fileStorageAdapter | FileStorageAdapter | — | Enables uploads and resolves stored keys |
resourceMode | 'upload' | 'inline' | 'upload' | How new image and diagram nodes store their resource (with an adapter); switchable per node |
locale | LiquidGlassLocaleInput | Global locale | UI language of this instance; overrides <LiquidGlassProvider locale> |
messages | Partial<TiptapEditorMessages> | Built-in text | Text overrides, deep-merged over the built-in text and the global messages.tiptapEditor |
glass | boolean | true | Liquid Glass surface (medium, like Card); glass={false} is 100% opaque |
className / toolbarClassName / contentClassName | string | — | Root, toolbar and scrolling content area |
TiptapContentRenderer
| Prop | Type | Default | Description |
|---|---|---|---|
content | string | — | Document JSON (or legacy HTML), converted in the browser |
html | string | — | Server-rendered HTML from renderTiptapHtml; preferred for reader pages |
fileStorageAdapter | FileStorageAdapter | — | Resolves stored images, attachments and uploaded diagrams |
locale | LiquidGlassLocaleInput | Global locale | UI language of this instance; overrides <LiquidGlassProvider locale> |
messages | Partial<TiptapEditorMessages> | Built-in text | Text overrides, deep-merged over the built-in text and the global messages.tiptapEditor |
className | string | — | Root element |
FileStorageAdapter
| Member | Type | Description |
|---|---|---|
upload | (file, { nodeType, signal, onProgress }) => Promise<{ value, url }> | Stores a file; value goes into the document |
resolve | (value, { nodeType, signal }) => Promise<string> | Display URL for a stored value |
validate | (file, { nodeType }) => string | undefined | Optional; return an error message to reject a file |
fetchRemote | (url, { nodeType, signal }) => Promise<Blob> | Optional; downloads external files the browser can't read |
isOwnUrl | (url: URL, { nodeType }) => boolean | Optional; URLs not offered for re-hosting |
Document helpers
| Export | Description |
|---|---|
docToHtml(json) / htmlToDoc(html) | Convert between document JSON and HTML (browser only) |
serializeTiptapDocument(editor) / parseTiptapDocument(raw) | Versioned document file, diagrams included |
downloadTiptapDocument(editor, name) / pickTiptapDocument() / loadTiptapDocument(editor, file) | Save to and open from a local file |
requestRemoteFileScan(editor) | Re-scan for external files after replacing the whole document |