项目作者: kjj6198

项目描述 :
draft-js utils to simplify draftjs.
高级语言: JavaScript
项目地址: git://github.com/kjj6198/draft-utils.git
创建时间: 2017-08-04T02:48:58Z
项目社区:https://github.com/kjj6198/draft-utils

开源协议:MIT License

下载


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

  1. editorState
  2. .getCurrentContent()
  3. .getBlockForKey(selection.getStartKey())
  4. .getText();

so this utils provide convienient way to use draftJS.

For example,

  1. 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