Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kjj6198/draft-utils
draft-js utils to simplify draftjs.
https://github.com/kjj6198/draft-utils
development draft-js draftjs-utils react utils
Last synced: about 1 month ago
JSON representation
draft-js utils to simplify draftjs.
- Host: GitHub
- URL: https://github.com/kjj6198/draft-utils
- Owner: kjj6198
- License: mit
- Created: 2017-08-04T02:48:58.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-08-04T03:07:08.000Z (over 7 years ago)
- Last Synced: 2024-11-17T06:48:02.985Z (about 2 months ago)
- Topics: development, draft-js, draftjs-utils, react, utils
- Language: JavaScript
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
**WARN: this repo is under development.**
## Draft Utils
draft-js is awesome, and it provide some method to use.
### What's problem?
if we want to get text in ContentBlock, we need to do something like
```javascript
editorState
.getCurrentContent()
.getBlockForKey(selection.getStartKey())
.getText();
```so this utils provide convienient way to use draftJS.
For example,
```javascript
getContentBlockText(editorState) // do the some thing above.
```All you need to do is passing editorState, which is more reasonable.
### API
#### getSelectedEntity(editorState)
get selected entity instance (not entity key!)
@param {EditorState} editorState
@return {Entity}### createEntity(type, mutable, data)
return a function(editorState) and create an entity.
### setContentState(contentState, editorState)
set contentState in provided editorState. useful when you use some method only return contentState.
### applyEntity(contentState, selectionState, entityKey)
return a function(editorState). apply an entity and set ContentState to provided EditorState.
### setBlockType(contentState, selectionState, blockType)
return a function(editorState). apply an blockType and set ContentState to provided EditorState.
### getCurrentBlockType(editorState)
return currentBlock type.
### getSelectedText(editorState)
get selected text with editorState.
### toHTML(editorState)
convert editorState into HTML.
### getPlainText(editorState)
get plain text with editorState.
### LICENSE
MIT