0.1.3 • Published 3 years ago
@monroeclinton/diction v0.1.3
diction
A text editor based on Notion.
Installation
npm i @monroeclinton/diction
Usage
Create new editor:
const diction = new Diction("#editor", {
maxElements?: number,
maxLength?: {
title?: number,
subtitle?: number,
paragraph?: number,
},
beforeCreate?: (el: IElement) => Promise<IElement>,
});
Listen for events:
diction.on('change', (el) => {
})
diction.on('delete', (id) => {
})
Editor method:
// Create element by ElementType and position
diction.createElement(elementType, position);
// Update element
diction.updateElement(id, element);
// Delete element by ID
diction.deleteElement(id);
// IElement[]
diction.getElements();
// Return HTML of content
diction.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
Diction is MIT licensed.