1.0.0 • Published 6 years ago

@jimmycode/draft-js-toolbox v1.0.0

Weekly downloads
109
License
MIT
Repository
github
Last release
6 years ago

DraftJs Toolbox

Useful goodies for DraftJS.

Installation

npm install @jimmycode/draft-js-toolbox

Usage

This library contains two sets of functions: 1. Utilities: that determine certain conditions on the editor's state. 2. Modifiers: which perform transformations on the editor's state.

Utils

import { getCurrentBlock, isCurrentBlockType, isBlockWithEntityType } from '@jimmycode/draft-js-toolbox';
FunctionParamsDescription
getCurrentBlockeditorStateReturns the current block selected.
isCurrentBlockTypeeditorState, blockTypeChecks the current block's type.
isBlockWithEntityTypeeditorState, block, entityTypeChecks if the current block is an atomic block with an specific entity type.

Modifiers

import { addBlock, addAtomicBlock, removeBlock } from '@jimmycode/draft-js-toolbox';
FunctionParamsDescription
addBlockeditorState, entityType, dataChanges the current block's type and replace its data.
addAtomicBlockeditorState, entityType, dataInserts an atomic block and creates an Entity with custom data.
removeBlockeditorState, blockKeyRemoves a block given its key.