ModaEditor — Rich Text Editor
Headless editor core — React/Vue/Svelte/vanilla.
A framework-agnostic headless rich-text editor built on immutable JSON AST documents and transaction updates.
All editor logic — document model, transactions, selection, input binding — lives in a pure TypeScript core; each framework adapter is a thin reactive binding. Five renderers emit the same DOM contract, so behavior is identical everywhere.
One starter bundle covers marks, headings, quotes, lists, tasks, tables, code blocks, links, images, alignment, history — and extensions/plugins/input rules allow infinite growth.
Live demo
Runs on the real core loaded from CDN. Each toolbar button maps 1:1 to an editor.commands.* call (API name in tooltip); every edit streams the HTML serialization and document JSON to the panel below, and events subscribed via editor.on() flow at the bottom.
Packages by environment
| Environment | Package | Notes |
|---|---|---|
| React | @moda-editor/react | useEditor + EditorView; custom node views are React components |
| Vue 3 | @moda-editor/vue | useEditor + EditorView SFC, useEditorState subscribes outside |
| Vue 2.7 | @moda-editor/vue2 | Same Composition API usage as Vue 3 |
| Svelte 5 | @moda-editor/svelte | createEditorStore + EditorView, readable store binding |
| Vanilla JS / CDN | moda-editor.js | One <script> line, no build tools — window.ModaEditor |
| No framework | @moda-editor/core | Use headless createEditor + mountEditor directly |
Install via npm
npm i @moda-editor/react # Reactnpm i @moda-editor/vue # Vue 3npm i @moda-editor/vue2 # Vue 2.7npm i @moda-editor/svelte # Svelte 5npm i @moda-editor/core # Headless core onlyUse via CDN
https://editor.modaolive.com/moda-editor.jshttps://editor.modaolive.com/style.cssGet started in 3 steps
- 1
Install package
Install an adapter like npm i @moda-editor/react, or load the core with a single CDN <script>.
- 2
Pass extensions
starterExtensions() alone bundles schema·commands·keymaps·input rules·history. Pass the initial doc JSON via doc.
- 3
Render & control
Adapters only need one <EditorView>. Wire the toolbar to editor.commands.*; vanilla uses mountEditor(el, options).
// npm i @moda-editor/react
import { EditorView, starterExtensions, useEditor } from "@moda-editor/react";
import "@moda-editor/react/styles.css";
function App() {
const { editor, state } = useEditor({
doc: myDoc, // DocNode JSON (empty doc if omitted)
extensions: starterExtensions(), // starter schema·commands·keymaps·history
});
return (
<>
<button onClick={() => editor.commands.toggleBold()}>B</button>
<button onClick={() => editor.commands.setHeading(2)}>H2</button>
<EditorView editor={editor} />
</>
);
}
// state is an immutable EditorState — === comparison decides whether to re-renderEditorState is immutable — it returns the same reference until a change, so the React useSyncExternalStore snapshot contract holds structurally.
Usage by feature — what to use
Every feature runs on core commands/options — adapters just forward them. Hover a toolbar button in the live demo to see the matching API.
Formatting (inline marks)
| Feature | How to enable (option/prop/input) | Core API |
|---|---|---|
| Bold·italic·underline | Toolbar / Mod-B·I·U | commands.toggleBold() / toggleItalic() / toggleUnderline() |
| Strikethrough | Toolbar button | commands.toggleStrike() |
| Super/subscript | — | commands.toggleSuperscript() / toggleSubscript() |
| Inline code | Toolbar button | commands.toggleCode() |
| Change mark attrs | — | commands.setMarkAttr("link", { href }) |
| Clear formatting | — | clearFormat (starter helper) |
Blocks
| Feature | How to enable (option/prop/input) | Core API |
|---|---|---|
| Headings | Toolbar button | commands.setHeading(1~6) |
| Blockquote | Toolbar button | commands.toggleQuote() |
| Code block | toggleCodeBlock — incl. language picker | commands.setCodeLanguage(lang) / highlightCode |
| Divider · hard break | — | commands.insertHorizontalRule() / insertHardBreak() |
| Alignment | When align feature is registered | commands.setAlign("left"|"center"|"right") |
| Split / exit block | Enter / Mod-Enter | splitBlock / exitBlock commands |
Lists & tables
| Feature | How to enable (option/prop/input) | Core API |
|---|---|---|
| Bulleted · numbered lists | Toolbar button | commands.toggleBulletList() / toggleOrderedList() |
| Task list | Toolbar button | commands.toggleTaskList() / toggleTaskItem() |
| Indent / outdent | Tab / Shift-Tab | commands.sinkListItem() / liftListItem() |
| Insert table · rows · columns | — | commands.insertTable(r,c) / addTableRow / addTableColumn / deleteTable |
| Cell navigation | Tab inside a table | nextCell / prevCell |
Links, images & paste
| Feature | How to enable (option/prop/input) | Core API |
|---|---|---|
| Link | Toolbar / [text](url) input rule | commands.setLink(href) / unsetLink() |
| Image | Insert URL / paste · drop | commands.insertImage(src, alt) / updateImage / deleteImage |
| Image upload hook | onImageUpload option — async File → URL | If omitted, inserts instantly as a FileReader data URL |
| HTML paste sanitizing | Automatic — strips script·on*·javascript: | parseHTML + sanitizeHTML built-in pipeline |
| Paste from Word · Google Docs | Automatic — prevents stray bolds & wrapper flattening | On external paste: structure cleanup + history skip |
| paste event | — | editor.on("paste", ({html, text}) => …) |
State, events & history
| Feature | How to enable (option/prop/input) | Core API |
|---|---|---|
| Immutable state | — | editor.state — same reference until a change |
| Render subscription | Adapters wire it automatically | editor.subscribe(fn) / getSnapshot() |
| Semantic events | — | editor.on("update"|"selectionUpdate"|"transaction"|"focus"|"blur"|"destroy") |
| Undo / redo | starterExtensions includes history, Mod-Z / Mod-Shift-Z | commands.undo() / redo(), canUndo / canRedo |
| Read-only | EditorOptions.editable: false | Signals the view to disable contenteditable |
| Collaboration (CRDT) | bindCollab — @moda-editor/collab-yjs | Lifecycle binding via subscribe·apply, Point-based position mapping |
| Manual dispatch | — | editor.dispatch(tr) — single entry point for all changes |
Doc & extensions
| Feature | How to enable (option/prop/input) | Core API |
|---|---|---|
| JSON doc model | doc: DocNode option | createDoc(content) / createText(text, marks) |
| HTML serialization | — | serializeToHTML(doc, schema) |
| HTML → doc | — | parseHTML(html, schema) → createDoc(nodes) |
| Custom node view | EditorView's nodeViews prop | { codeBlock: MyComponent } — NodeViewProps |
| Extension system | extensions array | Extension = nodes + marks + commands + keymap + inputRules + plugins |
| Starter bundle | extensions: starterExtensions() | Schema·commands·keymaps·input rules·history bundle |
| Theme | --me-* CSS variables in styles.css | .me-* DOM class contract for custom |
Common recipes
Copy-paste-ready code snippets.
Wire toolbar buttons
editor.commands is the command registry from extensions — bind to onClick
<button onClick={() => editor.commands.toggleBold()}>B</button>
<button onClick={() => editor.commands.setHeading(2)}>H2</button>
<button onClick={() => editor.commands.toggleTaskList()}>{t.todoL}</button>
<button onClick={() => editor.commands.undo()}>↶</button>
// returning false = not applicable at the current selection → use as a button-disabled signalAutosave (update event)
Fired on every doc/selection change — debounce & send to server
editor.on("update", ({ state, prevState }) => {
if (state.doc === prevState.doc) return; // skip when only the selection changed
scheduleSave(serializeToHTML(state.doc, editor.schema));
});
// or store the document JSON as-is
const payload = JSON.stringify(state.doc);Load HTML → doc
Parses existing HTML to initial doc — built-in sanitizer removes dangerous tags
import { createEditor, createDoc, parseHTML, starterExtensions }
from "@moda-editor/core";
const extensions = starterExtensions();
const boot = createEditor({ extensions });
const doc = createDoc(parseHTML(savedHtml, boot.schema));
const editor = createEditor({ extensions, doc });Image upload
Files from paste/drop/picker get replaced with server upload URLs
useEditor({
extensions: starterExtensions(),
onImageUpload: async (file) => {
const form = new FormData();
form.append("file", file);
const res = await fetch("/api/upload", { method: "POST", body: form });
return (await res.json()).url; // the editor inserts it as src
},
});Custom node view (React)
Replace a node type's rendering with your component — content gets an editor outlet
function CodeBlockView({ node, editor, path, content }: NodeViewProps) {
return (
<div className="my-codeblock">
<select onChange={(e) =>
editor.commands.setCodeLanguageAt(path, e.target.value)} />
{content} {/* editing area — must be rendered */}
</div>
);
}
<EditorView editor={editor} nodeViews={{ codeBlock: CodeBlockView }} />Event log & external sync
transaction emits every tr pre-filter — the lowest-level hook for debug/sync
editor.on("transaction", ({ tr, state }) => console.log(tr.steps));
editor.on("paste", ({ html, text }) => console.log(t.pasteL, text));
editor.on("blur", () => saveDraft());
editor.on("destroy", () => cleanup());
// share an externally created editor with the view
const editor = createEditor({ extensions: starterExtensions() });
<EditorView editor={editor} /> // the view handles subscriptionSame behavior across frameworks
React, Vue, Svelte, and Vanilla renderers all emit the same DOM contract (.me-* classes) and are verified by the shared conformance spec (runWidgetConformance). The API and CSS variables (--me-*) you learn on one platform carry over to the rest.
Source & docs
github.com/park-taejoon/moda-editor-releases- Platform guides — React / Vue 3 / Vue 2.7 / Svelte 5 / Vanilla
- Feature guides — custom nodeViews, searchable list example
- Theming — --me-* CSS variables, migration mapping doc
How to use
Headless editor core — React/Vue/Svelte/vanilla.