- block schema and validation
- CRUD blocks
- documented public API
- self-contained editor constructor
- state-driven user interface
- versioned block types
- block type state management
- block type primitives
- contributing guide
- customisable styling
- i18n
- rich-text editing
- tests
- undo
const Editor = require('editor')
const editor = new Editor()
editor.addBlockType(require('./text'))
document.body.appendChild(editor.element)
Instantiate an editor
Parameters
initialState
Object= optional initial state
Examples
const editor = new Editor()
Add block type
Parameters
blockType
Object
Examples
const editor = new Editor()
editor.addBlockType(require('editor/text'))
Create block
Parameters
Examples
const editor = new Editor()
editor.createBlock('text')
Returns number id of the block
Delete block
Parameters
id
number id of the block to delete
Examples
const editor = new Editor()
editor.deleteBlock(123)
Hide toolbar
Examples
const editor = new Editor()
editor.hideToolbar()
Show toolbar
Parameters
position
number id of the block to position after
Examples
const editor = new Editor()
editor.showToolbar(123)
Get blocks
Examples
const editor = new Editor()
editor.blocks
Get editor DOM element
Examples
const editor = new Editor()
document.body.appendChild(editor.element)
Get editor state
Examples
const editor = new Editor()
editor.state
Instantiate a block
Parameters
Update block data
Parameters
data
Object
Examples
const editor = new Editor()
const block = editor.blocks.find(b => b.id === 123)
block.updateData({ text: 'abc' })
Update block state
Parameters
state
Object
Examples
const editor = new Editor()
const block = editor.blocks.find(b => b.id === 123)
block.updateState({ edit: true })
Validate block data
Examples
const editor = new Editor()
const block = editor.blocks.find(b => b.id === 123)
block.validate()
Returns (Boolean|Array) an array of errors if there are any, otherwise true