- Notifications
You must be signed in to change notification settings - Fork3
Allows you to import an abstract syntax tree (AST) output from the companion draft-js-ast-exporter.
License
icelab/draft-js-ast-importer
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Allows you to import the abstract syntax tree (AST) output from the companiondraft-js-ast-exporter
. Together they form the full cycle of exporting content from a Draft.js editor instance and then re-importing it.
Draft.js supports exporting its content JSON, but this format is a little awkward. Blocks of text are disconnected from their style and entity ranges, and the depth of blocks isn’t implicit. So when it comes to rendering that content in contexts outside a Draft.js editor, you need to have an understanding of how those ranges should be applied and how blocks fit together.
The AST generated bydraft-js-ast-exporter
mitigates this issue by joining common ranges together into markedinline
orentity
sections, and by allowing blocks to be nested within one another based on their depth.
npm install --save draft-js-ast-importer
import{Editor}from'draft-js'importimporterfrom'draft-js-ast-importer'importyourDecoratorfrom'./decorator'classFooextendsReact.Component{constructor(props){super(props)constcontentState=importer(ast)this.state{editorState:EditorState.createWithContent(contentState,yourDecorator)}},onChange(editorState){this.setState({editorState})},render(){const{editorState}=this.statereturn(<EditoreditorState={editorState}onChange={this.onChange}/>)}}
About
Allows you to import an abstract syntax tree (AST) output from the companion draft-js-ast-exporter.
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.