Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Allows you to import an abstract syntax tree (AST) output from the companion draft-js-ast-exporter.

License

NotificationsYou must be signed in to change notification settings

icelab/draft-js-ast-importer

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.

Why?

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.

Installation

npm install --save draft-js-ast-importer

Usage

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

Stars

Watchers

Forks

Packages

No packages published

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp