Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

draftmirror

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

draftmirror

React component for ProseMirror providing a Draft.js like API

  • 0.7.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

DraftMirror

DraftMirror provides a Draft.js-like API on top of ProseMirror.

Installation

$ npm install draftmirror

Basic Usage

var DraftMirror = require('draftmirror');

var MyApp = React.createClass({
    getInitialState: function() {
        return {
            editorState: DraftMirror.EditorState.createFromJSON(schema, defaultJson)
        }
    },

    onChange: function(newEditorState) {
        this.setState({
            editorState: newEditorState
        });
    },

    render: function() {
        return <DraftMirror
            editorState={this.state.editorState}
            onChange={this.onChange}
        />;
    }
});

API

Modify style and blocks
var newEditorState = DraftMirror.StyleUtils.toggleInlineStyle(editorState, 'strong');
Widgets

DraftMirror allows the extension of ProseMirror syntax using custom React widgets:

var DraftMirror = require('draftmirror');
var schema = DraftMirror.schema;

var MyWidgetComponent = React.createClass({
    render: function() {
        return <div>...</div>;
    }
});

var MyWidget = DraftMirror.createWidget({
    component: MyWidgetComponent
});

const mySchema = new Schema({
    nodes: schema.nodeSpec.addBefore('image', 'mywidget', {
        type: MyWidget, group: "inline"
    }),
    marks: schema.markSpec
});
Tooltips

You can ask to render tooltips by providing a callback function as prop getTooltip. You callback should have such signature:

/**
 * Return tooltip depending on context
 *
 * @param {DraftMirror.SelectionContext} context The current context
 * @return {DraftMirror.Tooltip}
 */
function getTooltip(context) {
  return {
      component: <ReactComponent>,
      props:     <Object>
      position:  'bottom' | 'center' | 'right' | 'left',
      type:      'mark' | 'node',
      className: <String>, // Additionnal class for the div
  };
}

Keywords

FAQs

Package last updated on 28 Jul 2016

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc