@editkit/core
v2.0.4
Published
XSS-safe, Trusted Types-compatible TypeScript rich text editor engine with DOMPurify sanitization, stable caret and selection restoration, transactional undo/redo, JSON document AST, and zero framework dependencies.
Maintainers
Keywords
Readme
EditKit Core Text Editor Engine — @editkit/core
Framework-agnostic text editor engine for JavaScript and TypeScript — the lightweight rich text (WYSIWYG) editor core behind EditKit's React, Vue and Svelte text editors. Its only runtime dependency is DOMPurify, used to sanitize HTML. It does not include the standard toolbar styles or UI components.
Install
npm install @editkit/coreimport { EditKitEditor } from '@editkit/core';
const editor = new EditKitEditor({
content: '<p>Hello from EditKit.</p>',
onUpdate: current => console.log(current.getHTML()),
});
editor.mount(document.querySelector('#editor')!);
// Run during application teardown.
editor.destroy();Use editkit-text-editor when you want the complete default UI, or combine this package with @editkit/ui to build a custom layout.
Core API
- Formatting:
bold(),italic(),underline(),strikethrough(), andcode() - Blocks:
paragraph(),heading(1..6), lists, quotes, panels, and dividers - Media: images, links, tables, and math blocks
- State:
getHTML(),getText(),getJSON(),setContent(),undo(), andredo() - Extensions: commands, keyboard shortcuts, lifecycle hooks, and toolbar item definitions
Content safety
HTML passed to content, setContent(), paste, drag-and-drop, panels and undo/redo is sanitized with EditKit's DOMPurify-based policy before it reaches the DOM. Configure it with the sanitize option:
new EditKitEditor({
sanitize: {
linkSchemes: ['https', 'mailto'],
embedHosts: ['www.youtube.com', 'player.vimeo.com'],
extraStyleProperties: ['position'],
},
});sanitize: false restores the previous trusted-HTML behavior. A function replaces the policy. See the main README for the full option list and server-side usage.
License
MIT © Ashikur Rahman
