@buffmomo/zeditor

Documentation · Playground · Changelog

An extensible rich-text and block editor. One engine, two interfaces:

  • Classic mode — a formatting toolbar and continuous document editing.
  • Block mode — slash commands, block handles, nesting and drag-to-reorder.

Switching modes keeps the document, the caret, the scroll position and the undo history. Written from scratch in TypeScript: no ProseMirror, Lexical, Slate, Quill or Editor.js underneath. Zero runtime dependencies in the base bundle. Integrations: plain HTML/JS, React, Vue 3.

Quick start#

Plain HTML — no framework, no build step#

html
<link rel="stylesheet" href="./node_modules/@buffmomo/zeditor/dist/style.css" />
<div id="editor"></div>
<script type="module">
  import { createEditor } from './node_modules/@buffmomo/zeditor/dist/zeditor.browser.js';

  const z = createEditor({ element: '#editor', placeholder: 'Write something…' });
  // z.setMode('block');  z.getJSON();  z.setJSON(saved);
</script>

React#

tsx
import { ZEditor, useEditorState } from '@buffmomo/zeditor/react';
import '@buffmomo/zeditor/style.css';

export function Notes() {
  return <ZEditor mode="block" placeholder="Type / for commands" onChange={(editor) => save(editor.getJSON())} />;
}

content is the initial document. The editor owns its state afterwards, so parent re-renders (and Strict Mode's double mount) never reset the document or the caret. mode and readOnly are live props. Load another document with ref.current.setJSON(doc).

Vue 3#

vue
<script setup>
import { ZEditor } from '@buffmomo/zeditor/vue';
import '@buffmomo/zeditor/style.css';
</script>

<template>
  <ZEditor :options="{ placeholder: 'Write something…' }" mode="classic" @change="(editor) => save(editor.getJSON())" />
</template>

Events: @ready (the editor instance, once mounted), @change and @selection (the Editor).

Three levels of customization#

Level What you write
Ready-made createEditor({ element })
Configurable features, `ui.toolbar: ['bold', 'italic', '
Headless ui: false (or createHeadlessEditor() with no DOM at all) and render every control yourself from getState() / subscribe() and editor.commands
js
import { createEditor } from '@buffmomo/zeditor';

const z = createEditor({
  element: '#editor',
  mode: 'block',
  features: { tables: false, equation: false }, // switch built-in features off
  ui: { toolbar: ['undo', 'redo', '|', 'bold', 'italic', 'link'], statusBar: true },
  labels: { 'mark.bold': 'Fett' }, // any UI string
  icons: { bold: '<svg …/>' }, // any icon
  theme: 'auto', // light | dark | auto; or `unstyled: true`
  upload: async (file, { signal, onProgress }) => ({ url: await myUpload(file, signal, onProgress) }),
  mentions: { search: async (query, { signal }) => fetchPeople(query, signal) },
  autosave: { save: (doc) => api.save(doc), draftKey: 'doc-42' },
});

Theme with CSS variables — no selectors to override:

css
.zeditor { --z-accent: #7c3aed; --z-radius: 16px; --z-font: Georgia, serif; }

Databases and workspace blocks#

Notion-style structures are built in: databases with typed properties (including formulas, relations, rollups and your own property types), saved table / board / list / gallery / calendar / timeline views, filters, sorts, grouping and column calculations — where every row is a page with its own content — plus a live table of contents, bookmarks, page links ([[), date chips, template buttons, toggle headings, synced copies and nested sub-pages with breadcrumbs. Everything in the slash menu is also in the toolbar's searchable Insert menu.

js
z.commands.insertDatabase('board', {
  title: 'Tasks',
  properties: [{ name: 'Task', type: 'title' }, { name: 'Status', type: 'select', options: [{ id: 'todo', name: 'To do', color: 'gray' }, { id: 'done', name: 'Done', color: 'green' }] }],
  rows: [{ Task: 'Write docs', Status: 'To do' }],
});

See docs/databases.md for the model, the command API and what is not implemented.

Extensions#

Everything built in is an extension, and yours use the same API:

js
const issueRef = {
  name: 'issue-ref',
  schemaVersion: 1,
  nodes: [{ type: 'issue', kind: 'inline', attrs: { key: { default: '' } }, toText: (a) => a.attrs.key }],
  commands: { insertIssue: (editor, issue) => editor.exec('insertInline', { atom: 'issue', attrs: issue }) },
  keymap: { 'Mod-Shift-i': (editor) => editor.exec('insertIssue', { key: 'ZED-1' }) },
  typeahead: [{ name: 'issue', trigger: '#', search: (q, { signal }) => searchIssues(q, signal), select: (editor, item, range) => { /* … */ } }],
};
createEditor({ element: '#editor', extensions: [issueRef] });

Nodes, marks, commands, shortcuts, input rules, paste rules, serializers, toolbar items, slash-menu items, block actions, typeahead sources, renderers, labels and migrations are all extension points. See docs/extensions.md.

Entry points#

Import Contents Needs
@buffmomo/zeditor createEditor, view, default UI, everything from /core a browser
@buffmomo/zeditor/core headless engine, commands, HTML/Markdown/JSON, comments, suggestions, versions, autosave, uploads nothing (Node, workers, SSR)
@buffmomo/zeditor/react <ZEditor>, useEditorState, useEditor, NodeContent react, react-dom ≥ 18
@buffmomo/zeditor/vue <ZEditor>, useEditorState, useEditor, NodeContent vue ≥ 3.3
@buffmomo/zeditor/collab Yjs binding, presence, sync, transports yjs, y-protocols
@buffmomo/zeditor/code-highlight syntax highlighting for code blocks —
@buffmomo/zeditor/style.css styles (optional with unstyled) —
@buffmomo/zeditor/browser single-file ES module for <script type="module"> —
@buffmomo/zeditor/collab/browser single-file collaboration module (bundles Yjs) —

All framework and collaboration packages are optional peer dependencies: a vanilla consumer installs none of them. The package is ESM, marked side-effect free (except CSS) and split into shared chunks, so bundlers tree-shake what you do not import.

Server-side rendering and SEO#

js
import { renderToHTML, renderToText } from '@buffmomo/zeditor/core';

const html = renderToHTML(savedDoc, { ids: true }); // semantic, sanitized HTML: h1–h6, ul/ol, table, figure…
const description = renderToText(savedDoc).slice(0, 160);

renderToHTML runs in Node with no DOM, so stored documents can be served as crawlable HTML, and every entry point is safe to import during SSR.

Documentation#

All guides are on the documentation website, https://pushpa1105.github.io/zed-editor/:

License#

MIT

Esc