draft-js-raw-content-state
Table of Contents
Installation
npm i draft-js-raw-content-state --save
Usage
;const rawContentState = ;
API
-
.addBlock(text, type, data) Adds a new block.
-
setKey(key) Adds a blockKey
-
toRawContentState() Exports content as a rawContentState
-
isBackward() Sets isBackward SelectionState property to true
-
.addEntity(entity, offset, length) Creates a new entity.
-
.addInlineStyle(style, offset, length) Creates a new inline style.
-
.anchorKey(offset)
-
.setAnchorKey(offset) Sets the anchorKey, you can also provide an offset.
-
.focusKey(offset)
-
.setFocusKey(offset) Sets the focusKey, you can also provide an offset.
-
.collapse(offset) Sets focus and anchorKey, you may provide an offset.
-
.setData(data) Sets the data on the block.
-
.log() console.logs the rawContentState.
-
.toContentState() Converts the raw contentState into a ContentState type object.
-
.toEditorState(decorator) Converts the raw contentState into an EditorState type object.
Example
To convert to a raw contentState
const newEntity = type: 'CUSTOM_COLOR' mutability: 'MUTABLE' data: color: 'red' ; const contentState = // first block // second block ;
Generates
You an also generate EditorState and ContentStates typed objects.
Support
Please open an issue for support.
Contributing
Feel free to fork this project, make changes and submit pull requests.