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

@labnol/email-editor

v3.2.0

Published

A rich-text email editor for mail merge, with merge fields, image uploads and email-safe HTML

Readme

React Email Editor with Merge Fields and Image Uploads

A rich-text editor for composing email bodies in React. It writes email-safe HTML (inline styles, no classes), inserts {{merge fields}}, and uploads pasted, dropped and picked images through your own server.

It is the email editor in the Google Workspace add-ons by Digital Inspiration: Mail Merge, Document Studio, Email Google Sheets and Email Notifications for Google Forms, which together have 50 million installs.

Features

  • Merge fields, fast. Type {{ to pick a field from a list that filters as you type, or use the Fields menu with search. Fields show as chips, and a field that is not in your list, usually a typo, shows in amber.
  • Fields stay whole. Bold, a colour or a link applied to part of {{First Name}} covers the whole field, so a merge never leaves a tag open. <<First Name>> markers are kept too.
  • HTML that looks the same in the inbox. Inline styles only, and the editor's spacing is written into the HTML, so Gmail, Outlook and Apple Mail show the email as it was written.
  • Images through your server. Pick, paste or drop an image; it uploads with a faded preview where it will go, and lands on a line of its own. Base64 images in pasted content are uploaded too, since email clients block them.
  • An image menu. Select an image to set its size (sized for a 600 px email), alignment, alt text and link, or drag its handles to resize. The size is written as width and height, which Outlook reads.
  • A link menu. Put the cursor in a link to see its address, open it, edit its text and address together, or remove it.
  • Tables, quotes, lists, dividers, colours and alignment, all written as inline styles email clients keep.
  • Right-to-left text. Arabic, Hebrew, Persian and Urdu paragraphs run right to left on their own, in a left-to-right editor too.
  • A small API. value and onChange, with a ref to insert fields or text, read the HTML, and check for uploads still running before you send.
npm install @labnol/email-editor

React 18 or 19 is a peer dependency. Tiptap comes with the package. The toolbar uses Tabler Icons, built in under the MIT License (see licenses/).

Usage

import '@labnol/email-editor/style.css';

import { EmailEditor } from '@labnol/email-editor';
import toast from 'react-hot-toast';

const uploadImage = async (file) => {
  // Send the image to your own server and resolve to its public URL
  const body = new FormData();
  body.append('file', file);
  const response = await fetch('/api/upload', { method: 'POST', body });
  if (!response.ok) {
    toast.error('Sorry, the image could not be uploaded.');
    return null;
  }
  const { url } = await response.json();
  return url;
};

export const Editor = ({ html, onChange }) => (
  <EmailEditor
    value={html}
    onChange={onChange}
    onUploadImage={uploadImage}
    onError={(message) => toast.error(message)}
    fields={['First Name', 'Email', 'Company', 'What is your first name?']}
    placeholder='Write your email. Use {{First Name}} and other fields to personalize it.'
  />
);

Props

| Prop | Default | | | --------------------------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | value | '' | The HTML to show. When it changes to something the editor did not send, the editor loads it, so an HTML source view can edit the same value. | | onChange(value) | | Called with the content after the user stops typing for 300 ms, and right away on blur and unmount. | | dir | 'ltr' | 'rtl' for an editor used mainly in Arabic, Hebrew, Persian or Urdu: mirrors the toolbar, and paragraphs with no letters run right to left. Every paragraph still follows its own text. Read once. | | onUploadImage(file) | | Upload an image and resolve to its public http(s) URL, or to { url, width, height } to write its size (scaled to at most 600 px wide for Outlook), or to null when you have already told the user why it failed. If it throws, onError gets the message. Without it, the image button is hidden and pasted images are ignored. cloud-run/ has a sample upload service. | | onError(message) | | Show a message to the user. Gets the image checks and upload failures. | | fields | | Merge fields for the built-in Fields menu: strings, or { label, value } when the inserted name differs from the label. One toolbar button however many there are; past six it adds a search box, and long names wrap to two lines. Typing {{ in the text lists them too: keep typing to filter, Enter or Tab to insert, Escape to close. A field in the text that is not in the list shows as an amber chip, marked Unknown field; case and spaces don't count. | | placeholder | | Shown while the editor is empty. | | editable | true | | | maxImageSize | 4 MB | In bytes. | | minHeight, maxHeight | '14rem', '28rem' | The height of the empty editor below the toolbar, and the height past which the content scrolls. A CSS length, or a number of pixels. | | className, style, ariaLabel | | On the outer element and the editable area. |

Ref

const ref = useRef(null);
<EmailEditor ref={ref} … />;

ref.current.insertMarker('Email'); // insert {{Email}} at the cursor
ref.current.insertText('Hello');
ref.current.getValue(); // the current HTML, without waiting for onChange
ref.current.flush(); // send a pending onChange now
ref.current.isUploading(); // true while an image uploads: check it before sending the email
ref.current.focus();
ref.current.editor; // the Tiptap editor

More

Styling

Import @labnol/email-editor/style.css once. The editor has a fixed, neutral look and no border of its own, so put it in a container with the frame you want:

.email-body {
  border: 1px solid #e5e5e5;
  border-radius: 10px;
}

Size

The editor is 711 kB minified, 194 kB gzipped, without React; about 70% of it is Tiptap and ProseMirror. The stylesheet is 12 kB, 3 kB gzipped.

License

MIT. The Tabler Icons are © Paweł Kuna, under the MIT License: licenses/tabler-icons.txt.