Socket
Socket
Sign inDemoInstall

draft-js-ast-importer

Package Overview
Dependencies
23
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    draft-js-ast-importer

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


Version published
Maintainers
1
Install size
357 kB
Created

Changelog

Source

v2.0.3 2019-08-08

  • Remove draft-js-utils dependency (was unused)

Readme

Source

Draft.js AST Importer

Allows you to import the abstract syntax tree (AST) output from the companion 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

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 (
      <Editor editorState={editorState} onChange={this.onChange}/>
    )
  }
}

Keywords

FAQs

Last updated on 08 Aug 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc