0.1.3 • Published 3 years ago

@monroeclinton/diction v0.1.3

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

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.

0.1.2

3 years ago

0.1.3

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago