0.7.0 • Published 10 years ago

draftmirror v0.7.0

Weekly downloads
3
License
Apache-2.0
Repository
github
Last release
10 years ago

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
  };
}
0.7.0

10 years ago

0.6.1

10 years ago

0.6.0

10 years ago

0.5.3

10 years ago

0.5.2

10 years ago

0.5.1

10 years ago

0.5.0

10 years ago

0.4.0

10 years ago

0.3.0

10 years ago

0.2.5

10 years ago

0.2.4

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago