@jimmycode/draft-js-toolbox
v1.0.0
Published
Useful goodies for DraftJS
Downloads
290
Readme
DraftJs Toolbox
Useful goodies for DraftJS.
Installation
npm install @jimmycode/draft-js-toolbox
Usage
This library contains two sets of functions:
- Utilities: that determine certain conditions on the editor's state.
- Modifiers: which perform transformations on the editor's state.
Utils
import { getCurrentBlock, isCurrentBlockType, isBlockWithEntityType } from '@jimmycode/draft-js-toolbox';
| Function | Params | Description | |-----------------------|---------------------------------|------------------------------------------------------------------------------| | getCurrentBlock | editorState | Returns the current block selected. | | isCurrentBlockType | editorState, blockType | Checks the current block's type. | | isBlockWithEntityType | editorState, block, entityType | Checks if the current block is an atomic block with an specific entity type. |
Modifiers
import { addBlock, addAtomicBlock, removeBlock } from '@jimmycode/draft-js-toolbox';
| Function | Params | Description | |----------------|-------------------------------|-----------------------------------------------------------------| | addBlock | editorState, entityType, data | Changes the current block's type and replace its data. | | addAtomicBlock | editorState, entityType, data | Inserts an atomic block and creates an Entity with custom data. | | removeBlock | editorState, blockKey | Removes a block given its key. |