npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

better-react-email-editor

v0.1.9

Published

Drag & drop email builder for React (Unlayer-style), built on @react-email/editor. Modular components, English and French included.

Readme


Introduction

Add a visual email builder to your React app. Your users drag blocks into a layout, edit text in place and adjust styles from a side panel. Your app gets the email back as JSON, to save and reload, and as email-ready HTML (table layout, inline styles), to send.

It works like Unlayer, but it is open source and renders directly in your page: no iframe, no hosted service. Every part of the interface is a React component that you can restyle, replace or rearrange.

Demo: place an image, edit a heading, export the HTML

Features

  • Drag & drop: layouts of 1 to 4 columns and 12 content blocks (heading, text, button, image, divider, spacer, social links, menu, list, quote, HTML, card), plus prebuilt rows (header, hero, products, features, testimonial, footer).
  • Canvas: hover and selection frames, a move handle, a toolbar (select parent, duplicate, delete) and keyboard shortcuts (Esc selects the parent, Delete removes the block).
  • Layers panel: the email as a tree. You can select, reorder and nest blocks by drag & drop, with keyboard navigation.
  • Properties panel: one panel per block type (typography, spacing, background, border, links, column widths, social networks, HTML…) and a breadcrumb of the hierarchy.
  • Inline text editing: floating menu and / commands.
  • Copy / paste of blocks and text, and undo / redo.
  • Export: one button opens the rendered email: desktop and mobile preview, HTML (copy or download) and plain text.
  • Modular: replace, restyle or rearrange any part, and add your own blocks, palette items, templates and properties panels.
  • i18n: English and French are built in, and you can override any string.

Installation

npm install better-react-email-editor @react-email/editor react-email \
  @tiptap/core @tiptap/pm @tiptap/react @tiptap/html @tiptap/extension-placeholder

react and react-dom (18 or 19), @react-email/editor, react-email and the @tiptap/* packages are peer dependencies. Your app and the editor must share one copy of each.

Quick start

import { BetterEmailEditor } from 'better-react-email-editor';
import '@react-email/editor/themes/default.css';
import 'better-react-email-editor/styles.css';

export function NewsletterEditor() {
  return (
    <div style={{ height: '100vh' }}>
      <BetterEmailEditor
        locale="en" // or "fr"
        onChange={(value) => save(value)} // { doc, settings }
        uploadImage={async (file) => ({ url: await uploadToS3(file) })}
      />
    </div>
  );
}

The editor fills its parent, so give the parent a height.

Loading, saving and exporting

const ref = useRef<EmailEditorHandle>(null);

<BetterEmailEditor ref={ref} defaultValue={savedValue} onChange={setDraft} />;

const value = ref.current.getValue(); // { doc, settings } — store it as JSON
ref.current.setValue(otherValue); // replace the content
const { html, text } = await ref.current.exportEmail(); // ready-to-send email

| EmailEditorHandle | Description | | --- | --- | | editor | The underlying Tiptap Editor. | | getValue() / setValue(value) | Read or replace { doc, settings }. setValue also accepts a bare Tiptap document. | | getJSON() | The Tiptap document only. | | exportEmail() | Promise<{ html, text, unformattedHtml }>, including the preview text. | | getHtml() / getText() | Shortcuts for exportEmail(). | | insertBlocks(json[]) | Appends blocks at the end of the email. |

settings holds subject and previewText. The preview text is rendered into the HTML; the subject is not, so pass it to your email provider.

defaultValue is read on mount. The editor is uncontrolled, because re-applying a document on every keystroke would reset the cursor. Use setValue to replace the content later.

Props

BetterEmailEditor accepts every EditorRoot prop, plus the layout props listed further down.

| Prop | Type | Default | Description | | --- | --- | --- | --- | | defaultValue | EmailValue \| JSONContent | empty email | Initial content, read on mount. | | onChange | (value: EmailValue) => void | | Called on every document or settings change. Debounce it yourself if you save to a server. | | onReady | (handle) => void | | Called once the editor exists. | | locale | 'en' \| 'fr' \| string | 'en' | UI language. | | messages | PartialMessages | | Overrides any UI string, deep-merged over the locale. | | uploadImage | (file) => Promise<{ url }> | inline data URL | Stores uploaded or pasted images. | | nodes | NodeDefinition[] | defaultNodes | Block types: label, icon, properties panel, layers preview, extensions. | | palette | PaletteItem[] | defaultPalette | Tiles of the Content tab. | | paletteGroups | PaletteGroup[] | Layout, Content | Groups of tiles. | | templates | TemplateItem[] | defaultTemplates | Prebuilt rows of the Blocks tab. | | fonts | FontOption[] | defaultFonts | Fonts of the font pickers ({ label, value }, value being a CSS font-family stack). Defaults to Inter, Arial, Verdana, Tahoma, Georgia and Times New Roman. A font with an href (stylesheet URL) is a web font: loaded in the editor and linked in the exported email when used. Only some clients (Apple Mail, iOS) load web fonts, the others fall back (Inter → Arial). | | starterDocument | (i18n) => JSONContent | demo email | Loaded by the top bar's Template button. | | extensions | Extensions | | Extra Tiptap extensions, read on mount. | | theme | EditorThemeInput | defaultTheme | Email theme for new documents, read on mount. | | editable | boolean | true | | | device / defaultDevice / onDeviceChange | 'desktop' \| 'mobile' | 'desktop' | Canvas width, controlled or not. | | layersOpen / defaultLayersOpen / onLayersOpenChange | boolean | true | Layers panel visibility, controlled or not. | | className / style | | | Applied to the root element. |

Layout props, BetterEmailEditor only:

| Prop | Description | | --- | --- | | showTopBar, showLayers, showSidebar | Hide a part (all true by default). | | showEmailHeader | Show a card with the subject and preview text above the email (false by default). | | slotProps | Props for each part, e.g. { sidebar: { className: 'my-sidebar' }, topBar: { actions: <MyButton /> } }. | | components | Replace a part entirely: { TopBar, LayersPanel, Canvas, Sidebar }. |

Components

Every component below accepts className and style, and must be rendered inside EditorRoot (or BetterEmailEditor).

| Component | What it is | | --- | --- | | EditorRoot | Provider: creates the editor and shares it. Renders a div.bree. | | Canvas | The editable email, with its overlay (frames, handle, toolbar, drop indicator). Props: overlay, bubbleMenu, slashCommands, header (subject and preview text card above the email). | | EmailHeader | The subject and preview text card on its own, to place anywhere. | | TopBar | Top bar: desktop / mobile toggle and the export button. Props: brand (left side, empty by default), actions (extra controls before the export button), or children to replace its content. | | DeviceToggle, ExportHtmlButton | The default top bar controls. | | LayersToggle, UndoRedo, TemplateButton, ImportButton, ExportJsonButton, PreviewButton | Optional controls, not shown by default: add them through actions or your own bar. | | LayersPanel | Layers tree. Props: title, onClose to show a close button, and expandCollapseButtons={false} to hide the expand / collapse all buttons. | | Sidebar | Right panel. Switches between three screens; override any of them with renderDocument, renderNode or renderText. | | ContentPanel | Screen shown when nothing is selected: tabs. Prop tabs picks or reorders 'content' \| 'blocks' \| 'body' and accepts your own tabs. | | ContentTab / PaletteTile | Palette of draggable tiles. | | BlocksTab / TemplateCard | Prebuilt rows. | | BodyTab | Email-wide settings: background, width, default font and colors, preview text. | | PropertiesPanel | Properties shell: header, close button, breadcrumb. | | BlockProperties | Properties of the selected block, using the inspector registered for its type. | | TextProperties | Properties of a text selection. | | PreviewDialog | Preview and export modal. | | ImageInspector, ButtonInspector, HeadingInspector, SocialLinksInspector, ColumnsInspector, SpacerInspector, HtmlInspector, DividerInspector, ContainerInspector, DefaultInspector | Properties panel of each block type. | | TypographyGroup, SpacingGroup, BoxGroup | Reusable groups of controls. | | Group, Field, TextInput, TextArea, NumberInput, RangeInput, ColorInput, FontInput, Select, Segmented, AlignInput, PaddingInput | Form controls, to build your own panels. |

Hooks:

  • useEmailEditor() gives the editor, t (messages), locale, registries, device, layersOpen, settings, handle…
  • useI18n() gives { locale, t }.
  • useDraggableBlock(label, content) turns any element into a source of blocks: drag it onto the canvas or click it.
  • useDeselect() clears the selection.

Custom layout

import { EditorRoot, Canvas, Sidebar, UndoRedo, DeviceToggle, ExportHtmlButton } from 'better-react-email-editor';

<EditorRoot locale="fr" defaultValue={value} onChange={save} className="my-editor">
  <div style={{ display: 'flex', height: '100%' }}>
    <main style={{ flex: 1, display: 'flex', flexDirection: 'column' }}>
      <Canvas style={{ flex: 1 }} />
      <footer>
        <UndoRedo />
        <DeviceToggle />
        <ExportHtmlButton />
      </footer>
    </main>
    <Sidebar style={{ width: 320 }} />
  </div>
</EditorRoot>;

A custom layout

The playground contains this example: npm run dev, then open /?example=custom.

Styling

All classes are prefixed with bree-, and the stylesheet never touches global elements. Restyle a part through its className or style, or theme the whole editor with CSS custom properties:

.my-editor {
  --bree-accent: #7c3aed;
  --bree-accent-hover: #6d28d9;
  --bree-accent-soft: #f5f3ff;
  --bree-font: 'Inter', sans-serif;
  --bree-sidebar-width: 320px;
}

| Variable | Default | | --- | --- | | --bree-bg, --bree-bg-subtle | #ffffff, #f8fafc | | --bree-border, --bree-border-strong | #e5e7eb, #d1d5db | | --bree-text, --bree-text-secondary, --bree-muted | #111827, #334155, #6b7280 | | --bree-accent, --bree-accent-hover, --bree-accent-soft | #2563eb, #1d4ed8, #eff6ff | | --bree-danger | #dc2626 | | --bree-radius | 8px | | --bree-frame-gap (space between a block and its hover / selection frame) | 4px | | --bree-canvas-bg | #eef1f5 | | --bree-topbar-height, --bree-sidebar-width, --bree-layers-width | 56px, 360px, 270px | | --bree-font | Inter, system-ui… |

The default layout is a CSS grid on .bree-layout. The color picker popover is rendered in a portal; it carries the bree class, so the variables apply to it too. Its popoverClassName prop adds your own class.

Languages

<BetterEmailEditor locale="fr" />

// Override a few strings
<BetterEmailEditor locale="en" messages={{ topBar: { exportHtml: 'Export' }, palette: { card: 'Callout' } }} />

// Add a language: provide every string, starting from `en`
import { en, type Messages } from 'better-react-email-editor';
const de: Messages = { ...en, topBar: { ...en.topBar, preview: 'Vorschau' /* … */ } };
<BetterEmailEditor locale="de" messages={de} />

en and fr are exported. messages covers the UI, the default content inserted by the palette and templates, the placeholders and the / commands.

Extending

A palette item

import { content, defaultPalette, type PaletteItem } from 'better-react-email-editor';

const promo: PaletteItem = {
  id: 'promo',
  group: 'brand', // new group, or 'layout' / 'content'
  label: ({ locale }) => (locale === 'fr' ? 'Bandeau promo' : 'Promo banner'),
  icon: <PercentIcon />,
  content: () => [content.section('padding:20px;background-color:#fef3c7', content.heading(2, '20% off'))],
};

<BetterEmailEditor
  palette={[promo, ...defaultPalette]}
  paletteGroups={[{ id: 'brand', title: 'My brand' }, ...defaultPaletteGroups]}
/>;

content provides helpers to build the document JSON: paragraph, heading, button, image, columns, column, sized, section, padding, link, text, doc and placeholderImage.

A template (prebuilt row)

const signature: TemplateItem = {
  id: 'signature',
  label: 'Signature',
  description: 'Name, role and logo',
  content: () => [content.paragraph('Jane Doe — CEO')],
};

<BetterEmailEditor templates={[...defaultTemplates, signature]} />;

A properties panel

Replace the panel of an existing block, or give one to a new block:

import { defaultNodes, Group, Field, TextInput, SpacingGroup, type InspectorProps } from 'better-react-email-editor';

function MyButtonInspector({ ctx, className, style }: InspectorProps) {
  return (
    <div className={className} style={style}>
      <Group title="Link">
        <Field label="URL" stacked>
          <TextInput value={String(ctx.getAttr('href') ?? '')} onChange={(v) => ctx.setAttr('href', v)} />
        </Field>
      </Group>
      <SpacingGroup ctx={ctx} />
    </div>
  );
}

const nodes = defaultNodes.map((node) => (node.type === 'button' ? { ...node, inspector: MyButtonInspector } : node));

<BetterEmailEditor nodes={nodes} />;

ctx is the @react-email/editor inspector context: getAttr, setAttr, getStyle, setStyle, batchSetStyle, presetColors, nodeType and nodePos.

A new block type

Create the node with EmailNode.create from @react-email/editor/core. It needs an editor rendering and an email rendering (renderToReactEmail). Then register it:

const countdownNode: NodeDefinition = {
  type: 'countdown',
  label: ({ locale }) => (locale === 'fr' ? 'Compte à rebours' : 'Countdown'),
  icon: TimerIcon,
  inspector: CountdownInspector,
  preview: (node) => node.attrs.date,
  extensions: [Countdown], // your EmailNode
};

<BetterEmailEditor nodes={[...defaultNodes, countdownNode]} palette={[...defaultPalette, countdownTile]} />;

See src/nodes/custom-nodes.tsx for complete examples (spacer, social links, raw HTML).

Adding or removing controls

The default top bar only has the device toggle and the export button. Add the optional controls back, or remove parts:

import { UndoRedo, PreviewButton, ExportJsonButton, LayersToggle } from 'better-react-email-editor';

<BetterEmailEditor
  slotProps={{
    topBar: { brand: <img src="/logo.svg" alt="Acme" height={28} />, actions: <><UndoRedo /><ExportJsonButton /><PreviewButton /></> },
  }}
/>

<BetterEmailEditor
  palette={defaultPalette.filter((item) => item.id !== 'html')}
  showLayers={false}
  slotProps={{ sidebar: { renderDocument: (ctx) => <ContentPanel ctx={ctx} tabs={['content', 'body']} /> } }}
/>

To let users hide and show the layers panel, add a LayersToggle and give the panel a close button:

const [layersOpen, setLayersOpen] = useState(true);

<BetterEmailEditor
  layersOpen={layersOpen}
  onLayersOpenChange={setLayersOpen}
  slotProps={{ topBar: { actions: <LayersToggle /> }, layersPanel: { onClose: () => setLayersOpen(false) } }}
/>;

Headless core

The drag & drop engine has no UI and can be reused: findDropTarget, applyDrop, appendBlocks, unitAt, selectedUnit, selectUnit, duplicateUnit, deleteUnit, parentUnit, BLOCK_CONTAINERS and COLUMN_PARENTS.

How it fits into ProseMirror:

  • The model is the package's: container (the email) holds the blocks. The drop zones are container, section and columnsColumn. The rows twoColumns, threeColumns and fourColumns hold columns.
  • findDropTarget() walks down from the container to the deepest zone under the pointer, then picks the gap between two children. The schema validates every drop (node.canReplace), so a block never lands somewhere invalid.
  • dragover and drop are captured on the canvas before ProseMirror sees them. Native text drags stay with ProseMirror.
  • Insertions and moves are plain transactions, so undo / redo work with no extra code.

Development

npm install
npm run dev               # playground on http://localhost:5173 (?lang=fr, ?example=custom)
npm run build             # library → dist/ (ESM, CJS, types, styles.css)
npm run typecheck
npm run lint
src/
  index.ts                 public API
  context.tsx              EditorRoot, hooks, imperative handle
  components/              one file per screen: TopBar, LayersPanel, Canvas (+ CanvasOverlay),
                           Sidebar, ContentPanel, ContentTab, BlocksTab, BodyTab, PropertiesPanel,
                           BlockProperties, TextProperties, PreviewDialog, fields, inspectors/
  registry/                default nodes, palette, templates and starter email
  nodes/                   custom email nodes (spacer, social links, HTML)
  core/                    headless drag & drop engine, paste handling, JSON helpers
  i18n/                    en.ts, fr.ts
  styles.css
playground/                demo app consuming the library from its sources
scripts/                   Playwright scenarios

The scenarios in scripts/ drive the playground in French with Playwright. They use the Edge installed locally, through playwright-core.

npx vite --port 5179 &
node scripts/e2e.mjs        # also e2e2 … e2e10, e2e-custom, check-padding; screenshots in ./screenshots

Known limitations

These are workarounds for @react-email/editor:

  • The package has no block drag & drop; this library adds it.
  • The package's Button.parseHTML ignores the data-href and alignment it writes, so EmailButton (in core/paste.ts) reads them back. Without it, a copy-pasted button loses its link.
  • Pasting with a block selected inserts after the block instead of replacing it.
  • Divider rejects insertions while a divider is selected. The selection is released before a drop or a duplication.
  • The package's floating menus for buttons and images duplicate the properties panel, so CSS hides them.
  • TrailingNode leaves an empty paragraph after non-text blocks. It stays collapsed until the caret enters it.
  • EmailEditor always places its editing area before its children. EditorRoot creates the editor itself, so Canvas can sit anywhere in your layout; it reproduces the package's paste sanitizer, which is not exported.

Further ideas: host PNG social icons (Gmail does not display SVG), add media queries to stack columns on mobile in the exported HTML, and add more blocks (video thumbnail, countdown).

License

MIT