@ecodrix/erix-editor
v1.2.0
Published
Rich-text editor (ProseMirror, TinyMCE-style API) and drag-and-drop email builder for React. Zero platform coupling.
Readme
Erix Editor
A rich-text editor and a drag-and-drop email builder for React, with the same API shape as TinyMCE. Built on ProseMirror, so content stays structured, paste is clean and undo is reliable.
- Free and MIT-licensed. No account, no API key, no paid tiers. Every feature is on.
- No network calls. Image uploads go through a handler your app passes in.
- Drop-in styles. Prebuilt CSS scoped under
.erix-app; no Tailwind setup in your app. - Matches your app. One theme object, or plain CSS variables, for colours, radius, fonts and control size. Light, dark or follow the page.
| Package export | What it is |
| --- | --- |
| Editor | Rich text for blog posts, product details, comments, email bodies and documents |
| ErixRenderer | Renders saved content anywhere, without loading the editor |
| EmailEditor (/email) | Block-based email builder with email-ready HTML export |
Contents
- Install
- Quick start
- Rich text:
Editor - Showing saved content:
ErixRenderer - Email builder:
EmailEditor - Theming
- Accessibility
- Security
- Browser support and size
- Migrating from 0.x
- Contributing
Install
pnpm add @ecodrix/erix-editor lucide-react clsx radix-ui
# only for the email builder:
pnpm add @dnd-kit/coreNeeds React 18 or 19. Import the styles once, anywhere in your app:
import "@ecodrix/erix-editor/styles";Quick start
import { Editor } from "@ecodrix/erix-editor";
import "@ecodrix/erix-editor/styles";
export function PostForm() {
return (
<form method="post" action="/posts">
<Editor
initialValue="<p>Write something…</p>"
init={{ preset: "blog", height: 500 }}
textareaName="body" // the HTML posts with the form as "body"
/>
<button type="submit">Publish</button>
</form>
);
}The package marks itself "use client", so in the Next.js App Router you can import
Editor straight into a server component.
To keep the content in state instead:
const [body, setBody] = useState("");
<Editor value={body} onEditorChange={(content) => setBody(content)} init={{ preset: "product" }} />;Rich text: Editor
The props follow @tinymce/tinymce-react: init, initialValue, value (controlled),
onEditorChange, onInit, textareaName and disabled, plus imagePicker for your
own media library.
What it edits:
- Headings 1–6, quotes and code blocks.
- Bold, italic, underline, strikethrough, inline code, superscript and subscript.
- Text colour and highlight, font family and size, alignment and indent.
- Links, which are also detected as you type.
- Bullet, numbered and task lists.
- Tables with a row and column menu.
- Images you can resize, and YouTube and Vimeo videos.
- Callouts, toggles, two- and three-column layouts, and dividers.
How you edit:
- A toolbar that folds overflow into a
···menu. - A formatting bubble on text selection.
- A
/menu for inserting blocks, which you can extend. - Markdown shortcuts (
#,-,**bold**), and Markdown pasted as text becomes rich content. - Find and replace (Ctrl/⌘+F), an HTML source view, full screen (Ctrl/⌘+Shift+F), special characters and emoji.
- Clean paste from Word, Outlook and Google Docs: real lists, no stray fonts.
- English or Hindi labels, or your own translations.
Presets
init.preset sets the toolbar, plugins, size and placeholder. Anything else you pass
in init overrides it.
| Preset | For | Toolbar |
| --- | --- | --- |
| minimal | textarea replacement | bold, italic, underline, lists |
| comment | comments, notes | bold, italic, strike, code, link |
| description (default) | short descriptions | text styles, lists, link |
| product | product details | headings, lists, link, table; grows with the content |
| email | email body text | headings, colour, alignment, lists, link, image |
| blog | articles | everything: fonts, colours, media, special characters, emoji, find and replace, HTML view, full screen, slash menu, word count |
| document | long documents | same as blog, taller |
The product preset also has the HTML view, like Shopify's "Show HTML".
init options
| Option | Meaning |
| --- | --- |
| toolbar | Button names, groups split by \|, or false for none: undo redo blocks fontfamily fontsize bold italic underline strikethrough superscript subscript code removeformat forecolor backcolor lists bullist numlist checklist align alignleft aligncenter alignright alignjustify indentgroup outdent indent link unlink image media table insert blockquote codesample hr callout toggle columns charmap emoticons searchreplace sourcecode fullscreen, plus any button you add. |
| plugins | quickbars (selection bubble), slashcommands, textpattern (Markdown shortcuts), autolink, table (table menu), image (resize), wordcount (status bar), autoresize, searchreplace (find bar and Ctrl/⌘+F). TinyMCE names such as lists link are accepted; those features are always on. |
| height, min_height, max_height | Pixels or any CSS length. "auto" grows with the content. |
| format | What onEditorChange, getContent() and the form field give you: html (default), json, markdown or text. |
| input_format | Format of initialValue and value. auto (default) detects HTML, JSON, Markdown or plain text. |
| placeholder, readonly | As in TinyMCE. |
| content_style | CSS for the content area, scoped to this editor. body selectors target the content root. |
| aria_label | Name of the editing area for screen readers. Default "Rich text editor". |
| language | UI labels: "en" (default) or "hi" (Hindi). TinyMCE codes such as "hi_IN" work too. |
| translations | Your own labels, keyed by the English label, e.g. { Bold: "Gras" }. They win over language. |
| skin | light, dark or auto (follows the page). TinyMCE's oxide-dark also means dark. |
| theme | Colours, radius, fonts and sizes to match your app. See Theming. |
| images_upload_handler | (file) => Promise<url>, called for pasted and dropped images. Without it, pasted base64 images are dropped instead of bloating your content. |
| setup | (editor) => void, runs before onInit. Register your own buttons here. |
| tokens | Raw 0.x token overrides. Prefer theme. |
Images
<Editor
init={{
preset: "blog",
// pasted and dropped images: upload them, return the stored URL
images_upload_handler: async (file) => (await uploadToYourStorage(file)).url,
}}
// the toolbar's image button: open your own media library
imagePicker={({ onInsert, children }) => <MyMediaLibrary onPick={(url) => onInsert(url)}>{children}</MyMediaLibrary>}
/>Without imagePicker, the image button asks for an image URL.
Your own buttons and slash commands
Register a button in setup the TinyMCE way, then name it in the toolbar:
import { DEFAULT_SLASH_COMMANDS, Editor } from "@ecodrix/erix-editor";
import { PenLine } from "lucide-react";
<Editor
init={{
toolbar: "bold italic | signature",
setup: (editor) => {
editor.ui.registry.addButton("signature", {
icon: <PenLine size={14} />, // or text: "Sign"
tooltip: "Add signature",
onAction: (ed) => ed.insertContent("<p>— Team Acme</p>"),
// isActive: (ed) => …, isEnabled: (ed) => …
});
},
}}
slashCommands={[
...DEFAULT_SLASH_COMMANDS,
{ id: "greeting", label: "Greeting", description: "Insert a greeting", run: (ed) => ed.insertText("Namaste! ") },
]}
/>Differences from TinyMCE: icon is a React node rather than an icon name, and onAction
receives the editor.
Find, HTML view and full screen
- Find and replace (
searchreplace): Ctrl/⌘+F opens a bar under the toolbar. Enter and Shift+Enter step through matches; replace one or all. Without the plugin, Ctrl/⌘+F stays the browser's own find. - HTML view (
sourcecode): edit the HTML directly. Changes apply when you leave the field or switch back, and pass through the same cleaning as paste, so scripts and event handlers are dropped. Note that in Erixcodeis the inline-code button, not TinyMCE's source view. - Full screen (
fullscreen, Ctrl/⌘+Shift+F): the editor fills the window and the page behind stops scrolling.
Languages
<Editor init={{ preset: "blog", language: "hi" }} />
<Editor init={{ preset: "blog", translations: { Bold: "Gras", Italic: "Italique" } }} />The Hindi pack covers every label in the rich-text editor. The email builder's labels are English for now.
Editor instance
From ref or onInit(evt, editor):
editor.getContent({ format: "json" }); // "html" | "json" | "markdown" | "text"
editor.setContent("# Title\n\nBody"); // format detected
editor.insertContent("<strong>hi</strong>");
editor.execCommand("Bold"); // TinyMCE names: Bold, InsertUnorderedList, mceInsertTable, CreateLink, FormatBlock…
editor.queryCommandState("Bold");
editor.isDirty(); editor.setDirty(false);
editor.mode.set("readonly");
editor.on("update", ({ html, json, text, wordCount, charCount }) => {});
editor.insertText("₹999"); // plain text at the cursor
editor.find("gold"); editor.findNext(); editor.replace("silver"); editor.replaceAll("silver");
editor.execCommand("mceFullScreen"); // also mceCodeEditor (HTML view) and SearchReplacecharCount counts characters as people read them: a Hindi conjunct or an emoji counts once.
Showing saved content: ErixRenderer
Store json and render it anywhere, including server components:
import { ErixRenderer } from "@ecodrix/erix-editor";
<ErixRenderer content={savedJson} format="json" />;format="json"builds React elements directly. It never injects raw HTML, and it only renders http(s), mailto, tel and site-relative links.format="html"first cleans the HTML through the editor's own schema, so scripts, event handlers and unsafe links are dropped. Cleaning needs a browser DOM, so during server rendering the box stays empty until the page hydrates. Usejsonfor content that must be in the server-rendered HTML.
On the server: @ecodrix/erix-editor/render
For pages that must ship the content in their HTML (blogs, help articles, emails), render
on the server with the render entry. It has no DOM, no React and no "use client", so it
runs in server components, route handlers and plain Node, and the browser gets none of the
editor's code.
import { renderContent } from "@ecodrix/erix-editor/render";
const html = renderContent(post.body); // ErixNode JSON, HTML, Markdown or plain text- The format is detected the same way the editor detects it (
detectFormat); pass a format as the second argument to skip detection, or pass the ErixNode tree already parsed. - The result is cleaned without a DOM: scripts and similar elements, event-handler
attributes, unsafe link and image URLs and iframes other than YouTube and Vimeo players
are removed (
sanitizeHtml). Style the output with your own CSS.
Email builder: EmailEditor
import { EmailEditor, type EmailEditorRef } from "@ecodrix/erix-editor/email";
import "@ecodrix/erix-editor/styles";
const ref = useRef<EmailEditorRef>(null);
<EmailEditor
ref={ref}
defaultValue={savedDesign} // a design from any earlier version is migrated
onChange={(design, html) => save(design, html)}
variables={["first_name", "order_id"]} // offered in the text toolbar as {{first_name}}
previewValues={{ first_name: "Priya" }}
imagePicker={({ open, onOpenChange, onInsert }) => (
<MyMediaLibrary open={open} onOpenChange={onOpenChange} onPick={(url) => onInsert({ url })} />
)}
/>;
const { design, html } = ref.current!.exportHtml();Save design to edit later and send html.
Blocks: sections with up to 4 columns, nav menu, heading, text, button, image, hero, product card, video, divider, spacer, list, social links, footer, variable and custom HTML.
Export: the HTML uses tables and inline styles, with fallbacks for Outlook, columns that stack on screens under 480px, and dark-mode hints.
Building:
- Drag blocks in, or click to append them.
- Edit text in place.
- Undo and redo.
- Preview at desktop and mobile widths.
- Start from one of 5 starter templates.
Narrow screens: below 900px wide (compactBelow, measured on the builder itself)
the three panes become tabs: Blocks, Email and Settings. The canvas zooms the email to
fit its width at every size.
For your own shell (header, variables panel, template gallery), compose
useBuilderState, EmailBuilder, StarterGallery, PreviewPane and VariablesPanel.
documentToHtml(design) exports without rendering anything.
Theming
Both editors take one ErixTheme: init.theme on Editor, and theme on EmailEditor
and EmailBuilder. Colours accept any CSS value, including your own variables.
const theme: ErixTheme = {
colors: { primary: "#652933", brand: "var(--brand)", border: "#e9dadd", link: "#652933" },
radius: "4px",
controlHeight: "28px", // buttons, tabs, inputs and selects; default 28px
fonts: { heading: "Georgia, serif" }, // ui, body, heading, mono
content: { fontSize: "16px", lineHeight: "1.7", padding: "1rem 1.25rem", blockGap: "0.75em" },
};
<Editor init={{ preset: "blog", skin: "auto", theme }} />
<EmailEditor theme={theme} mode="auto" />- Inherit from your app.
{ inherit: "shadcn" }reads your--background,--foreground,--primary,--muted,--accent,--border,--ringand--radius(shadcn/ui v4). Use"shadcn-hsl"when those variables are HSL triplets (shadcn/ui v3). Anything you also set incolors,radiusorfontswins. - No props needed. Every theme key is a CSS variable you can set on any parent:
--erix-color-<name>(kebab case, e.g.--erix-color-primary-foreground),--erix-radius,--erix-control-height,--erix-font-ui,--erix-font-body,--erix-font-headingand--erix-font-mono.themeToVars(theme)returns the same variables as astyleobject. - Colours:
- Surfaces:
background foreground card popover primary secondary muted accent destructive, each with a…Foreground, plusborder input ring. brand: the caret, selection, focus and builder highlights.- Status:
success warning. - Content:
link linkHover placeholder codeBackground codeForeground codeblockBackground codeblockForeground quoteBorder quoteBackground tableBorder tableHeader.
- Surfaces:
- Fonts default to your page's font. Headings default to the body font.
- Dark mode:
skin/modeof"auto"follows adarkclass ordata-theme="dark"on<html>, then the OS setting. Set dark colours by scoping the variables, e.g..dark { --erix-color-primary: #e8b4bc }.
Accessibility
- Toolbar: it is one Tab stop. Arrow keys, Home and End move between its buttons.
- Selection bubble: its buttons work from the keyboard and announce bold or italic as pressed.
- Editing area: it has an accessible name (
init.aria_label). - Email builder: blocks are selectable with Enter and deselected with Escape. The narrow-screen tabs follow the ARIA tabs pattern.
- Target size: controls are 28px tall, above the WCAG 2.2 AA minimum of 24px.
- Touch screens: form fields use 16px text, so iPhone Safari doesn't zoom the page.
Found a barrier? Please open an issue.
Security
- Pasted and loaded HTML is parsed into the editor's schema.
<script>, event handlers andjavascript:links never reach the document. - Link and image URLs must be http(s), mailto, tel, an anchor or site-relative.
- Email designs: colours, fonts, sizes and image URLs are checked before they reach the exported HTML, so a saved design can't inject markup or extra CSS.
- Email canvas: before the canvas shows a block's HTML in your page, it removes
scripts,
<style>, inline SVG and event handlers.
Report vulnerabilities privately; see SECURITY.md.
Browser support and size
- Browsers: current Chrome, Edge, Firefox and Safari. The styles use CSS
color-mix(): Chrome and Edge 111+, Firefox 113+, Safari 16.2+. - Size (gzip):
Editorabout 123 KB andEmailEditorabout 67 KB, plus 8 KB of CSS. React, Radix and Lucide are not counted, since your app usually has them already.
Migrating from 0.x
ErixEditorstill works but is deprecated. Move to<Editor init={{ preset, toolbar }} />.- The editor no longer runs in an iframe. It mounts in your page; the content area is
.erix-app .erix-content, andcontentStyles/content_styleare scoped to it. - JSON saved by 0.x loads unchanged and saves in the same shape.
- Plans and API keys are gone. Every feature is free and the editor makes no network
calls.
apiKey,apiUrlandclientCode(andapi_key,api_url,client_codeininit) are ignored. - AI is not part of 1.0.
aiProvider, theaiplugin and toolbar name, andtoolbar.aiare ignored. ref.engineis the new engine.setHTML,getHTML,getJSON,on/offand the formatting methods are unchanged; iframe-only internals are gone.- Removed:
ContentCountDisplay,useContentCounterandContentCounter. Use thewordcountplugin's status bar, oreditor.on("update", ({ wordCount, charCount }) => …).
All changes are listed in the CHANGELOG.
Contributing
Bug reports and pull requests are welcome. CONTRIBUTING.md covers the playground, the tests and the few rules the code follows. Everyone taking part agrees to the Code of Conduct.
License
MIT. See LICENSE and THIRD_PARTY_NOTICES.md.
