0.1.3 • Published 3 years ago
@monroeclinton/editor v0.1.3
editor
A text editor based on Notion.
Installation
npm i @monroeclinton/editor
Usage
Create new editor:
const editor = new Diction("#editor", {
maxElements?: number,
maxLength?: {
title?: number,
subtitle?: number,
paragraph?: number,
},
beforeCreate?: (el: IElement) => Promise<IElement>,
});
Listen for events:
editor.on('change', (el) => {
})
editor.on('delete', (id) => {
})
Editor method:
// Create element by ElementType and position
editor.createElement(elementType, position);
// Update element
editor.updateElement(id, element);
// Delete element by ID
editor.deleteElement(id);
// IElement[]
editor.getElements();
// Return HTML of content
editor.getHTML();
An element is defined as:
interface IElement {
id: string,
type: ElementType,
position: number,
text: string,
}
enum ElementType {
TITLE = 'h1',
SUBTITLE = 'h3',
PARAGRAPH = 'p',
}
License
Editor is MIT licensed.
0.1.3
3 years ago