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

editkit-text-editor

v2.0.4

Published

XSS-safe, Trusted Types-compatible TypeScript rich text (WYSIWYG) editor for React, Next.js, Vue, Nuxt, Svelte, Angular, and Laravel — with stable caret/selection handling, slash commands, advanced tables, content.css, and RSC viewer.

Readme

EditKit Text Editor — Rich Text & WYSIWYG Text Editor for React, Vue, Svelte & JavaScript

Overview

editkit-text-editor is an open-source, XSS-safe TypeScript rich text (WYSIWYG) and Markdown editor npm package for React, Next.js, Vue 3, Nuxt, Svelte, SvelteKit, Angular, Laravel, and vanilla JavaScript. It includes a complete customizable UI, interactive tables, image tools, HTML source mode, built-in DOMPurify sanitization, and dark/light themes.

The default factory and framework integrations mount the same maintained editor UI. Feature flags, CSS variables, commands, extensions, and custom toolbar items let an application customize it without maintaining a fork.

Official entry points cover React/Next.js, Vue/Nuxt, Svelte/SvelteKit, and vanilla JavaScript. Angular uses the framework-agnostic browser API; Laravel can use that API through Vite or a React/Vue adapter through Inertia.

Rich text editor features

  • Complete WYSIWYG toolbar, floating bubble menu, document preview, and HTML source editor
  • Built-in XSS sanitization powered by DOMPurify across initial content, paste, drop, and undo/redo
  • Interactive tables with row, column, cell, resize, and contextual-menu tools
  • Images, links, colors, lists, emoji, symbols, charts, math, panels, and content blocks
  • Markdown, clean HTML, email-safe HTML, plain text, DOCX, and PDF export via @editkit/export
  • TypeScript types, ESM and CommonJS builds, SSR-safe imports, and responsive layouts
  • React, Next.js, Vue, Nuxt, Svelte, SvelteKit, Angular, Laravel Vite, and vanilla JavaScript support
  • No third-party editor engine; the core editing engine and UI are maintained in this repository

Install EditKit Text Editor

Choose the integration for your framework. Each option provides the same default UI and imports the stylesheet from editkit-text-editor/styles.

React, Vue, and Svelte are normally already installed in projects created with their official framework tools; the commands below make those peer requirements explicit.

| Framework | Install | JavaScript / TypeScript import | | :--- | :--- | :--- | | Vanilla JavaScript or TypeScript | npm install editkit-text-editor | editkit-text-editor | | React, Next.js, or Laravel Inertia React | npm install editkit-text-editor react react-dom | editkit-text-editor/react | | Vue 3, Nuxt, or Laravel Inertia Vue | npm install editkit-text-editor vue | editkit-text-editor/vue | | Svelte or SvelteKit | npm install editkit-text-editor svelte | editkit-text-editor/svelte | | Angular | npm install editkit-text-editor | editkit-text-editor | | Laravel Blade with Vite | npm install editkit-text-editor | editkit-text-editor |

Vanilla JavaScript and TypeScript quick start

npm install editkit-text-editor

Import the stylesheet once in your application entry, layout, or global CSS entry. Without it, the editor works but does not have the standard EditKit appearance.

import { createEditKit } from 'editkit-text-editor';
import 'editkit-text-editor/styles';

const editkit = createEditKit({
  element: '#editor',
  content: '<h1>Hello EditKit</h1><p>Start writing...</p>',
  theme: 'dark',
  placeholder: 'Write something amazing...',
  onUpdate: (editor) => {
    console.log(editor.getHTML());
  },
});

// Later, when the page/view is torn down:
// editkit.destroy();
<div id="editor"></div>

createEditKit() mounts the default toolbar, bubble menu, table menu, and image menu. Its return value exposes those UI instances and the core editor, plus one idempotent destroy() method for complete cleanup.

Package entry points

For the complete public API and adapter contracts, see docs/API.md. Framework-specific React, Vue, Svelte, Nuxt, and Next.js patterns are in docs/examples/framework-integrations.md.

| Use case | Import | | :--- | :--- | | Complete UI / vanilla / Angular / Laravel Blade | editkit-text-editor | | React / Next.js / Laravel Inertia React | editkit-text-editor/react | | Vue 3 / Nuxt / Laravel Inertia Vue | editkit-text-editor/vue | | Svelte / SvelteKit | editkit-text-editor/svelte | | Default stylesheet | editkit-text-editor/styles | | Content stylesheet (display saved HTML, no editor) | editkit-text-editor/content.css | | Modular editor engine | @editkit/core | | Modular visual components and stylesheet | @editkit/ui, @editkit/ui/styles, @editkit/ui/content.css |

The editor mounts DOM, so create it in a browser/client lifecycle. Package entry points can be imported by SSR builds, but mounting must wait until the browser is available.

Framework setup

React and Next.js

Install React and React DOM alongside the all-in-one package, then use the React subpath. In a Next.js App Router project, keep the component in a client module.

'use client';

import { useState } from 'react';
import { EditKitEditor } from 'editkit-text-editor/react';
import 'editkit-text-editor/styles';

export default function EditorPage() {
  const [content, setContent] = useState('<p>Hello from React.</p>');

  return (
    <EditKitEditor
      value={content}
      onChange={setContent}
      theme="dark"
      features={{ panel: true, insertElements: true, math: false }}
    />
  );
}

The component and useEditKitEditor() hook destroy the editor and all mounted UI when React unmounts them.

Vue 3 and Nuxt

<script setup lang="ts">
import { ref } from 'vue';
import { EditKitEditor } from 'editkit-text-editor/vue';
import 'editkit-text-editor/styles';

const content = ref('<p>Hello from Vue.</p>');
</script>

<template>
  <ClientOnly>
    <EditKitEditor
      v-model="content"
      theme="dark"
      :features="{ panel: true, insertElements: true, math: false }"
    />
  </ClientOnly>
</template>

ClientOnly is a Nuxt component; omit it in a client-rendered Vue application. The component and useEditKitEditor() composable clean up automatically on unmount.

Svelte and SvelteKit

<script lang="ts">
  import { editkit } from 'editkit-text-editor/svelte';
  import 'editkit-text-editor/styles';

  let content = '<p>Hello from Svelte.</p>';
</script>

<div
  use:editkit={{
    content,
    theme: 'dark',
    features: { panel: true, insertElements: true, math: false },
    onChange: (html) => (content = html),
  }}
/>

Svelte invokes the action's cleanup when the element is removed.

Angular

There is no separate Angular adapter. Mount the complete browser UI in ngAfterViewInit() and destroy it in ngOnDestroy().

import { AfterViewInit, Component, ElementRef, OnDestroy, ViewChild } from '@angular/core';
import { createEditKit, type EditKitInstance } from 'editkit-text-editor';
import 'editkit-text-editor/styles';

@Component({
  selector: 'app-editor',
  standalone: true,
  template: '<div #editorHost></div>',
})
export class EditorComponent implements AfterViewInit, OnDestroy {
  @ViewChild('editorHost', { static: true }) editorHost!: ElementRef<HTMLDivElement>;
  private editkit?: EditKitInstance;

  ngAfterViewInit(): void {
    this.editkit = createEditKit({
      element: this.editorHost.nativeElement,
      content: '<p>Hello from Angular.</p>',
    });
  }

  ngOnDestroy(): void {
    this.editkit?.destroy();
  }
}

Laravel Blade, Vite, and Inertia

EditKit runs in the browser, not in PHP. Use the React or Vue entry point for Inertia, or mount the complete UI from a Vite entry for Blade.

// resources/js/app.js
import { createEditKit } from 'editkit-text-editor';
import 'editkit-text-editor/styles';

const host = document.querySelector('#editor');
const editkit = host
  ? createEditKit({ element: host, content: '<p>Hello from Laravel.</p>' })
  : null;

// Prevent duplicate listeners during Vite hot updates.
import.meta.hot?.dispose(() => editkit?.destroy());
<div id="editor"></div>
@vite(['resources/css/app.css', 'resources/js/app.js'])

Configuration

createEditKit(options) accepts all core editor options plus these complete-UI options:

| Option | Type | Default | Purpose | | :--- | :--- | :--- | :--- | | element | HTMLElement \| string | required | Host element or selector | | showToolbar | boolean | true | Mount the standard toolbar | | features | ToolbarFeaturesConfig | all enabled | Toggle standard toolbar controls | | toolbar | ToolbarConfig | {} | Advanced toolbar configuration | | bubbleMenu | boolean | true | Mount the selection bubble menu | | tableMenu | boolean | true | Mount contextual table controls | | imageMenu | boolean | true | Mount contextual image controls |

Core options include content, editable, theme, placeholder, autofocus, default font settings, history depth, extensions, custom toolbar items, lifecycle callbacks, locale, and per-instance translations.

Localization

English (en) and Bengali (bn) UI translations are built in. Regional tags such as bn-BD use the matching language fallback. Translation overrides are isolated to each editor instance:

const editor = createEditor({
  element: '#editor',
  locale: 'bn-BD',
  translations: {
    'editor.label': 'আমার ডকুমেন্ট এডিটর',
    'toolbar.label': 'ডকুমেন্ট টুলবার',
  },
});

editor.setLocale('en');
editor.t('editor.label');

Applications can register a reusable locale dictionary before creating editors:

import { registerLocale } from '@editkit/core';

registerLocale('fr', {
  'editor.label': 'Éditeur de texte',
  'editor.close': 'Fermer',
});

setLocale() emits localeChange; the standard mounted toolbar refreshes automatically.

Toolbar feature flags

Omitted flags default to true.

| Flag | Controls | | :--- | :--- | | history, undo, redo | History controls; history: false hides both undo and redo | | block, fontFamily, fontSize | Block type and typography controls | | bold, format, color | Inline formatting and colors | | align, lists | Alignment, line height, lists, and indentation | | image, table, chart, math, link, emoji, symbol | Media and rich-content tools | | panel | Info, warning, error, success, and note panel menu | | insertElements | Standalone insert menu for dividers, uploads, signatures, editorial elements, blocks, and patterns | | selectAll, clearAll, preview | Selection, clear-content, and document-preview controls |

panel and insertElements are separate flags. Disabling one does not implicitly disable the other.

const editkit = createEditKit({
  element: '#editor',
  features: {
    chart: false,
    math: false,
    panel: true,
    insertElements: true,
  },
});

Customization

Keep the default UI and change its theme

Scope CSS overrides to your editor wrapper. The standard stylesheet remains the base, so controls and responsive behavior keep their default design.

<div class="brand-editor"><div id="editor"></div></div>
.brand-editor [data-editkit] {
  --editkit-bg: #0b1020;
  --editkit-card-bg: #111827;
  --editkit-toolbar-bg: #172033;
  --editkit-content-bg: #101827;
  --editkit-border: #334155;
  --editkit-border-focus: #22c55e;
  --editkit-primary: #22c55e;
  --editkit-font: Inter, sans-serif;
  --editkit-radius-card: 14px;
  --editkit-radius-btn: 5px;
}

Add an application-specific toolbar item

customToolbarItems keeps the standard toolbar and appends typed application controls. An extension can also return the same item shape from defineToolbarItems().

const editkit = createEditKit({
  element: '#editor',
  customToolbarItems: [
    {
      id: 'save-document',
      label: 'Save',
      tooltip: 'Save document',
      group: 'right',
      onClick: (editor) => saveDocument(editor.getHTML()),
    },
  ],
});

Replace the standard toolbar

For a fully application-owned toolbar, disable the standard toolbar and call core commands from your own controls.

const editkit = createEditKit({ element: '#editor', showToolbar: false });

document.querySelector('#bold')?.addEventListener('click', () => {
  editkit.editor.commands.bold();
});

Transactions, chaining and JSON

// Group programmatic edits into one undo step.
editkit.editor.transact(() => {
  document.querySelector('#title')?.replaceChildren(document.createTextNode('New title'));
  editkit.editor.commands.insertText(' — updated');
});

// Chain commands; run() commits one history entry.
editkit.editor.chain().focus().bold().setLink({ url: 'https://example.com' }).run();

// Import/export a versioned document.
const doc = editkit.editor.getJSON();
editkit.editor.setJSON(doc);

Use editor.can().bold() / editor.can().link() to enable custom controls, and listen to transaction, historyChange and contentError for state changes. Bidirectional text can be set globally with direction: 'rtl' in EditKitConfig or per block with editor.commands.setTextDirection('rtl'); the toolbar dropdown is enabled with features: { direction: true }.

Everyday editing tools

The toolbar can enable a slash menu (features.slash), find & replace (features.find), a word/character status bar (features.statusBar), full-screen mode (features.fullscreen), a shortcut reference (features.shortcuts), tables of contents (features.toc) and collapsible blocks (features.collapsible). editor.getStats() returns word, character, paragraph and reading-time counts. Markdown shortcuts (# , - , **bold**, etc.) and Ctrl/Cmd+F, Ctrl/Cmd+H, Ctrl/Cmd+Shift+F and Ctrl/Cmd+/ work while typing.

Advanced tables

Select multiple cells by dragging or with Shift+Click/Shift+Arrow, then merge/split, duplicate rows or columns, clear cells or change padding from the table context menu (right-click or Shift+F10). Pasting tab- or spreadsheet-copied data fills cells from the caret and creates a table when no table is active. Wide tables scroll horizontally on small screens without changing the saved markup.

Uploads, embeds and link previews

Pass an async upload(file, { signal, onProgress }) adapter as an editor option to enable real uploads, image-progress UI and file attachments. accept and maxSize validate files before upload. Use linkPreview: async url => ({ title, ... }) to enable preview cards, and features.embed / features.linkPreview to expose the insert controls. SSRF-safe server examples live in docs/examples/.

Content blocks

Charts are editable (bar/line/pie with a label/value table) and render as inline SVG. Embedded HTML blocks render sanitized markup in a sandboxed iframe whose srcdoc is rebuilt from data-html and never saved. All custom blocks share one set of hover controls for select, duplicate, delete, move and drag reordering. Enable the HTML-block insert control with features.htmlBlock.

HTML source mode

The toolbar's HTML source control opens a source editor with validation, pretty-print, split preview (desktop/tablet/mobile), file import, copy and download. Applying source always sanitizes the markup through setContent() as one undo step and lists anything that will be removed.

Import & export

Install @editkit/export for Markdown (GFM), clean/email HTML, plain text, JSON, DOCX and PDF helpers. Heavy dependencies such as docx are dynamically imported only when used, so the core bundle is unaffected.

Content safety

EditKit is secure by default. All HTML that enters the editor is sanitized with an EditKit policy built on DOMPurify before it touches the DOM. That covers content, value, defaultValue, modelValue, setContent(), clipboard paste, drag-and-drop, panel content and undo/redo snapshots.

The default policy:

  • removes scripts, event handlers (on*), <style>, <form> and form controls (task-list checkboxes are kept), <object>, <embed>, <base>, <meta>, MathML, and the SVG elements used for attacks (<use>, <foreignObject>, animations)
  • allows http:, https:, mailto: and tel: links, plus relative URLs and fragments. http:, https: and blob: media are allowed, as are base64 raster data:image/* sources. javascript:, vbscript: and other data: URLs are removed.
  • filters inline CSS through a property allowlist and drops values containing url(), expression(), escapes or @import; position is not allowed
  • keeps iframes only from YouTube, Vimeo, Loom and Figma, always sandboxed and lazy-loaded
  • protects against mutation XSS and DOM clobbering (name attributes and clobbering ids are removed)
  • keeps EditKit formatting, tables, task lists, panels, charts, math, columns, buttons and other blocks

Configure the policy

import { createEditKit } from 'editkit-text-editor';

createEditKit({
  element: '#editor',
  content: savedHTML,
  sanitize: {
    allowedTags: ['mark'],
    forbiddenTags: ['iframe'],
    allowedAttributes: ['data-user-id'],
    linkSchemes: ['https', 'mailto'],
    mediaSchemes: ['https'],
    allowDataImages: false,
    extraStyleProperties: ['letter-spacing'],
    embedHosts: ['www.youtube-nocookie.com'],
    transform(fragment) {
      fragment.querySelectorAll('a').forEach((a) => a.setAttribute('rel', 'nofollow noopener'));
    },
  },
});

| sanitize value | Behavior | | :--- | :--- | | omitted / true | EditKit default policy | | object | Default policy with your allowlists (allowedTags, forbiddenTags, allowedAttributes, forbiddenAttributes, linkSchemes, mediaSchemes, allowDataImages, styleProperties, extraStyleProperties, allowCustomProperties, embedHosts, transform) | | function (html) => string | Your own sanitizer | | false | No sanitization (trusted HTML only; the pre-1.1 behavior) |

editor.sanitize(html) applies the editor's policy to any string, and sanitizeHTML() / createSanitizer() are exported for use elsewhere in your app (for example before rendering saved HTML outside the editor).

Server-side sanitization

Always sanitize again on the server before storing or rendering HTML. A browser can be bypassed. In Node.js, pass a DOM window from jsdom:

import { JSDOM } from 'jsdom';
import { createSanitizer } from '@editkit/core';

const sanitize = createSanitizer({}, new JSDOM('').window);

app.post('/posts', (req, res) => {
  const html = sanitize(req.body.html);
  // store html…
});

sanitizeHTML() throws if no DOM is available, rather than returning unsanitized input. In other server languages, use a maintained sanitizer with an equivalent allowlist. In Laravel, for example, use mews/purifier (HTML Purifier) configured for the tags, attributes and URL schemes above.

Content Security Policy and Trusted Types

EditKit does not use eval, inline scripts or new Function. When the page enforces Trusted Types (require-trusted-types-for 'script'), the editor writes content through DOMPurify's dompurify Trusted Types policy, so allow that policy name:

Content-Security-Policy: require-trusted-types-for 'script'; trusted-types dompurify

The core editor (content loading, editing commands, paste, undo/redo) works under enforced Trusted Types when sanitization is on. The bundled toolbar and menus (@editkit/ui) still render their icons with HTML strings and are not yet Trusted Types compatible.

Lifecycle and output

  • Call destroy() for every manually created createEditKit() instance.
  • React, Vue, and Svelte integrations perform their own unmount cleanup.
  • editor.getHTML() returns HTML, getText() returns plain text, and getJSON() returns EditKit's document representation.
  • Controlled framework values should be updated through their documented binding (value, v-model, or the Svelte action options).

Display saved content

Pages that only show saved EditKit HTML (a blog post, a product page) do not need the editor. Import the content stylesheet instead of the full one and render the HTML statically:

import 'editkit-text-editor/content.css';
<div data-editkit-theme="light">
  <div class="editkit-content"><!-- saved, sanitized HTML --></div>
</div>

content.css holds the design tokens and every rule for saved content (typography, tables, task lists, panels, math, code and the content blocks) and nothing for the editor's toolbar, menus, modals or pickers. It is about a third of styles (10 KB gzip instead of 31 KB) and does not load the Google Fonts the editor's font picker uses, so it adds no third-party request. Set data-editkit-theme="light" or "dark" on an ancestor to choose the palette; content then looks as it did in the editor.

content.css is generated from the editor stylesheet at build time (scripts/build-content-css.mjs), and a test checks that every editor rule matching saved content is kept. Sanitize the HTML before rendering it (see Content safety).

Modular installation

Applications that want to assemble the editor engine and UI separately can install the scoped packages:

npm install @editkit/core @editkit/ui
import { EditKitEditor } from '@editkit/core';
import { createToolbar } from '@editkit/ui';
import '@editkit/ui/styles';

See each package README for manual lifecycle guidance.

FAQ

What is the best way to add a text editor to a React or Next.js app?

Install editkit-text-editor with react and react-dom, import EditKitEditor from editkit-text-editor/react, and import editkit-text-editor/styles once. In the Next.js App Router, put the editor in a 'use client' component. See React and Next.js.

Is there a Vue 3 and Nuxt text editor component?

Yes. editkit-text-editor/vue exports an EditKitEditor component with v-model support and a useEditKitEditor() composable. In Nuxt, wrap it in <ClientOnly>. See Vue 3 and Nuxt.

Does it work with Svelte, SvelteKit, Angular and Laravel?

Yes. Svelte and SvelteKit use the use:editkit action. Angular and Laravel Blade mount the framework-agnostic createEditKit() API. Laravel Inertia uses the React or Vue entry. See Framework setup.

Is EditKit a free and open-source text editor npm package?

Yes. It is MIT licensed, and the editing engine and UI are maintained in this repository without a third-party editor engine.

Does the text editor support tables, images and dark mode?

Yes. Interactive tables, image tools, links, colors, lists, math, panels, content blocks, document preview and light/dark themes are included in the default UI.

How do I get the HTML from the editor?

Call editor.getHTML() for HTML, editor.getText() for plain text or editor.getJSON() for EditKit's document structure. The React and Vue components also report changes through onChange and v-model.

Is the editor safe against XSS?

Yes, by default. Content loaded, pasted or dropped into the editor is sanitized with a DOMPurify-based allowlist. Also sanitize on your server before storing or rendering HTML. See Content safety.

Development

pnpm install
pnpm verify
pnpm playground

License

MIT © Ashikur Rahman · Source code · npm package