Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/icelab/draft-js-ast-importer
Allows you to import an abstract syntax tree (AST) output from the companion draft-js-ast-exporter.
https://github.com/icelab/draft-js-ast-importer
Last synced: 27 days ago
JSON representation
Allows you to import an abstract syntax tree (AST) output from the companion draft-js-ast-exporter.
- Host: GitHub
- URL: https://github.com/icelab/draft-js-ast-importer
- Owner: icelab
- License: mit
- Created: 2016-05-20T00:12:48.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-04T04:08:45.000Z (about 2 years ago)
- Last Synced: 2024-04-13T19:12:42.418Z (8 months ago)
- Language: JavaScript
- Size: 183 KB
- Stars: 13
- Watchers: 7
- Forks: 3
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-draft-js - Draft.js AST Importer - Import an abstract syntax tree (AST) output from the companion draft-js-ast-exporter. (Common Utilities)
README
# Draft.js AST Importer
Allows you to import the abstract syntax tree (AST) output from the companion [`draft-js-ast-exporter`](https://github.com/icelab/draft-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 by `draft-js-ast-exporter` mitigates this issue by joining common ranges together into marked `inline` or `entity` sections, and by allowing blocks to be nested within one another based on their depth.
## Installation
```
npm install --save draft-js-ast-importer
```## Usage
```js
import {Editor} from 'draft-js'
import importer from 'draft-js-ast-importer'
import yourDecorator from './decorator'class Foo extends React.Component {
constructor(props) {
super(props)
const contentState = importer(ast)
this.state {
editorState: EditorState.createWithContent(contentState, yourDecorator)
}
},onChange (editorState) {
this.setState({editorState})
},render () {
const {editorState} = this.state
return (
)
}
}
```