All Projects → HubSpot → Draft Extend

HubSpot / Draft Extend

Licence: apache-2.0
Build extensible Draft.js editors with configurable plugins and integrated serialization.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Draft Extend

Megadraft
Megadraft is a Rich Text editor built on top of Facebook's Draft.JS featuring a nice default base of components and extensibility
Stars: ✭ 982 (+800.92%)
Mutual labels:  rich-text-editor, draft-js
Medium Draft
📝 A medium like Rich Text Editor built on draft-js with a focus on keyboard shortcuts.
Stars: ✭ 1,705 (+1464.22%)
Mutual labels:  rich-text-editor, draft-js
Braft Editor
美观易用的React富文本编辑器,基于draft-js开发
Stars: ✭ 4,310 (+3854.13%)
Mutual labels:  rich-text-editor, draft-js
React Tapable Editor
A pluginable, intuitive medium/notion like rich text editor(currently in wip)
Stars: ✭ 170 (+55.96%)
Mutual labels:  rich-text-editor, draft-js
Mui Rte
Material-UI Rich Text Editor and Viewer
Stars: ✭ 233 (+113.76%)
Mutual labels:  rich-text-editor, draft-js
React Text Selection Popover
Selection based Text UI made easy
Stars: ✭ 245 (+124.77%)
Mutual labels:  rich-text-editor, draft-js
Draft Convert
Extensibly serialize & deserialize Draft.js ContentState with HTML.
Stars: ✭ 416 (+281.65%)
Mutual labels:  rich-text-editor, draft-js
Richtextfx
Rich-text area for JavaFX
Stars: ✭ 902 (+727.52%)
Mutual labels:  rich-text-editor
French Press Editor
☕ An offline-first rich text editor component.
Stars: ✭ 69 (-36.7%)
Mutual labels:  rich-text-editor
Dante2
A complete rewrite of dante editor in draft-js
Stars: ✭ 890 (+716.51%)
Mutual labels:  draft-js
Angular Froala Wysiwyg
Angular 4, 5, 6, 7, 8 and 9 plugin for Froala WYSIWYG HTML Rich Text Editor.
Stars: ✭ 696 (+538.53%)
Mutual labels:  rich-text-editor
Awesome Medium Editor
Medium.com WYSIWYG editor clone, with RTL support.
Stars: ✭ 12 (-88.99%)
Mutual labels:  rich-text-editor
Leotextview
🐬A high-performance rich editor develop with swift on iOS platform, based on TextKit.
Stars: ✭ 87 (-20.18%)
Mutual labels:  rich-text-editor
React Lz Editor
A multilingual react rich-text editor component includes media support such as texts, images, videos, audios, links etc. Development based on Draft-Js and Ant-design, good support html, markdown, draft-raw mode. 一款基于 draft-Js 和 ant-design 实现的 react 富文本编辑器组件,支持文本、图片、视频、音频、链接等元素插入,同时支持HTML、markdown、draft Raw格式。
Stars: ✭ 894 (+720.18%)
Mutual labels:  draft-js
Z Editor
Online Z-notations Editor with Draft.js and React.js
Stars: ✭ 99 (-9.17%)
Mutual labels:  draft-js
Uncolored
(Un)colored — Next generation desktop rich content editor that saves documents with themes. HTML & Markdown compatible. For Windows, OS X & Linux. — http://n457.github.io/Uncolored/
Stars: ✭ 733 (+572.48%)
Mutual labels:  rich-text-editor
Ngx Quill
Angular (>=2) components for the Quill Rich Text Editor
Stars: ✭ 1,382 (+1167.89%)
Mutual labels:  rich-text-editor
Slate Edit Table
Slate plugin for table edition
Stars: ✭ 97 (-11.01%)
Mutual labels:  rich-text-editor
Slate Edit Code
A Slate plugin for code block editing
Stars: ✭ 44 (-59.63%)
Mutual labels:  rich-text-editor
Balsa
This repository holds source code of Balsa, a self hosted, privacy focused knowledgebase.
Stars: ✭ 93 (-14.68%)
Mutual labels:  rich-text-editor

draft-extend

npm version License

Build extensible Draft.js editors with configurable plugins and integrated serialization


Jump to:

Overview

Draft Extend is a platform to build a full-featured Draft.js editor using modular plugins that can integrate with draft-convert to serialize with HTML. The higher-order function API makes it extremely easy to use any number of plugins for rendering and conversion.

Usage:

import React from 'react';
import ReactDOM from 'react-dom';
import {EditorState} from 'draft-js';
import {Editor, compose} from 'draft-extend';
import {convertFromHTML, convertToHTML} from 'draft-convert';

const plugins = compose(
    FirstPlugin,
    SecondPlugin,
    ThirdPlugin
);

const EditorWithPlugins = plugins(Editor); // Rich text editor component with plugin functionality
const toHTML = plugins(convertFromHTML); // function to convert from HTML including plugin functionality
const fromHTML = plugins(convertToHTML); // function to convert to HTML including plugin functionality

const MyEditor = React.createClass({
    getInitialState() {
        return {
            editorState: EditorState.createWithContent(fromHTML('<div></div>'))
        };
    },

    onChange(editorState) {
        const html = toHTML(editorState.getCurrentContent());
        console.log(html); // don't actually convert to HTML on every change!
        this.setState({editorState});
    },

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

ReactDOM.render(
    <MyEditor />,
    document.querySelector('.app')
);

Examples

Examples of how to build plugins of different types are included in the example directory. To run the examples locally:

  1. run npm install in the draft-extend directory
  2. open any HTML file in the examples directory in your web browser - no local server is necessary

Editor

Editor component on which to extend functionality with plugins created by createPlugin.

Props

The most important two props are:

  • editorState - Draft.js EditorState instance to be rendered.
  • onChange: function(editorState: EditorState): void - Like with vanilla Draft.js, function called on any editor change passing the EditorState.

Other props are used by plugins composed around Editor. See Building Plugins for more information. These should generally not be used outside of the context of a plugin:

  • buttons: Array<Component> Array of React components to add to the controls of the editor.
  • overlays: Array<Component> Array of React components to add as overlays to the editor.
  • decorators: Array<DraftDecorator> Array of Draft.js decorator objects used to render the EditorState. They are added to the EditorState as a CompositeDecorator within the component and are of shape {strategy, component}.
  • baseDecorator: DraftDecoratorType Replacement decorator object to override the built-in CompositeDecorator's behavior. See the "Beyond CompositeDecorator" section on this page of the Draft.js docs for more information.
  • styleMap: Object Object map from Draft.js inline style type to style object. Used for the Draft.js Editor's customStyleMap prop.

All other props are passed down to the Draft.js Editor component and to any buttons and overlays added by plugins.


compose

Since the API of plugins is based around composition, a basic compose function is provided to make it easy to apply plugins to the component as well as conversion functions and provides a single source of truth for plugin configuration.

// without compose
const EditorWithPlugins = FirstPlugin(SecondPlugin(ThirdPlugin(Editor)));
const fromHTML = FirstPlugin(SecondPlugin(ThirdPlugin(convertFromHTML)));
const toHTML = FirstPlugin(SecondPlugin(ThirdPlugin(convertToHTML)));

// with compose
const plugins = compose(
    FirstPlugin,
    SecondPlugin,
    ThirdPlugin
);

const EditorWithPlugins = plugins(Editor);
const toHTML = plugins(convertToHTML);
const fromHTML = plugins(convertFromHTML);

KeyCommandController

Higher-order component to consolidate key command listeners across the component tree

An increasingly common pattern for rich text editors is a toolbar detached from the main Editor component. This toolbar will be outside of the Editor component subtree, but will often need to respond to key commands that would otherwise be encapsulated by the Editor. KeyCommandController is a higher-order component that allows the subscription to key commands to move up the React tree so that components outside that subtree may listen and emit changes to editor state. KeyCommandController. It may be used with any component, but a good example is the Toolbar component:

import {Editor, Toolbar, KeyCommandController, compose} from 'draft-extend';

const plugins = compose(
  FirstPlugin,
  SecondPlugin
);

const WrappedEditor = plugins(Editor);
const WrappedToolbar = plugins(Toolbar);

const Parent = ({editorState, onChange, handleKeyCommand, addKeyCommandListener, removeKeyCommandListener}) => {
  return (
    <div>
      <WrappedEditor
        editorState={editorState}
        onChange={onChange}
        handleKeyCommand={handleKeyCommand}
        addKeyCommandListener={addKeyCommandListener}
        removeKeyCommandListener={removeKeyCommandListener}
      />
      <WrappedToolbar
        editorState={editorState}
        onChange={onChange}
        addKeyCommandListener={addKeyCommandListener}
        removeKeyCommandListener={removeKeyCommandListener}
      />
    </div>
  );
};

export default KeyCommandController(Parent);

KeyCommandController provides the final handleKeyCommand to use in the Editor component as well as subscribe/unsubscribe functions. As long as these props are passed from some common parent wrapped with KeyCommandController that also receives editorState and onChange props, other components may subscribe and emit chagnes to the editor state.

Additionally, KeyCommandControllers are composable and will defer to the highest parent instance. That is, if a KeyCommandController receives handleKeyCommand, addKeyCommandListener, and removeKeyCommandListener props (presumably from another controller) it will delegate to that controller's record of subscribed functions, keeping all listeners in one place.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].