draft-js vs prosemirror-view vs slate vs tiptap
Rich Text Editors
draft-jsprosemirror-viewslatetiptapSimilar Packages:

Rich Text Editors

Rich text editors are tools that allow users to create and edit text with various formatting options, such as bold, italics, lists, and links, directly within a web application. These editors provide a user-friendly interface for text manipulation, similar to word processors, but are designed to be embedded in web pages. They are essential for applications like content management systems, email clients, and social media platforms, where users need to input and format text. Rich text editors handle the complexities of HTML and CSS behind the scenes, allowing users to focus on their content without worrying about the underlying code. They often include features like toolbar buttons, keyboard shortcuts, and drag-and-drop functionality to enhance the editing experience. Some popular rich text editors include Draft.js, ProseMirror, Slate, and Tiptap, each offering different levels of customization, performance, and ease of use. These editors can be integrated into web applications using JavaScript frameworks like React, Angular, or Vue, providing a seamless and interactive text editing experience for users.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
draft-js022,882-9546 years agoMIT
prosemirror-view02,033890 kB14a month agoMIT
slate031,5792.17 MB6962 months agoMIT
tiptap035,442-8865 years agoMIT

Feature Comparison: draft-js vs prosemirror-view vs slate vs tiptap

Customization

  • draft-js:

    Draft.js provides a high level of customization, allowing developers to create custom blocks, inline styles, and entities. It is built with React, making it easy to integrate and extend within React applications. However, it requires a good understanding of its architecture to fully leverage its capabilities.

  • prosemirror-view:

    ProseMirror is highly customizable and modular, allowing developers to build complex editors with custom schemas, nodes, and marks. It is designed for extensibility, making it suitable for projects that require advanced features and collaborative editing capabilities. However, it has a steeper learning curve compared to other editors.

  • slate:

    Slate is designed for deep customization, allowing developers to create fully custom editors with their own data models, rendering logic, and behaviors. It provides a flexible API for building complex editing experiences, but it requires more effort to implement compared to more opinionated editors.

  • tiptap:

    Tiptap is built on top of ProseMirror and offers a more user-friendly API for customization. It provides a set of pre-built extensions for common features, making it easier to customize without extensive coding. It is ideal for projects that need a balance between flexibility and ease of use.

Collaboration

  • draft-js:

    Draft.js does not have built-in support for real-time collaboration, but it can be integrated with third-party libraries and services to enable collaborative editing. This requires additional development effort and infrastructure.

  • prosemirror-view:

    ProseMirror is designed with collaboration in mind, offering built-in support for real-time collaborative editing. It provides a robust framework for handling concurrent changes, making it ideal for applications that require multiple users to edit documents simultaneously.

  • slate:

    Slate does not provide native collaboration features, but it can be extended to support real-time editing through third-party libraries and custom implementations. This flexibility allows developers to build collaborative editors, but it requires additional work.

  • tiptap:

    Tiptap inherits ProseMirror's collaboration capabilities, making it easier to implement real-time collaborative editing. It provides a more accessible API for integrating collaboration features, making it a good choice for projects that need collaborative functionality with less complexity.

Performance

  • draft-js:

    Draft.js is optimized for performance, especially when dealing with large documents. Its use of immutable data structures helps minimize unnecessary re-renders, making it efficient for most editing tasks. However, performance can be impacted if not used correctly, especially with complex customizations.

  • prosemirror-view:

    ProseMirror is designed for high performance, even with complex document structures. Its architecture allows for efficient rendering and updates, making it suitable for applications that require fast and responsive editing experiences.

  • slate:

    Slate's performance depends on the implementation, as it provides a flexible framework that can be optimized based on the use case. However, its flexibility can lead to performance issues if not managed properly, especially with large documents or complex customizations.

  • tiptap:

    Tiptap leverages ProseMirror's performance optimizations while providing a more user-friendly interface. It is designed to be efficient and responsive, making it a good choice for applications that need a fast editing experience with minimal setup.

Ease of Use: Code Examples

  • draft-js:

    Simple example of draft-js editor

    import React, { useState } from 'react';
    import { Editor, EditorState } from 'draft-js';
    import 'draft-js/dist/Draft.css';
    
    function MyEditor() {
      const [editorState, setEditorState] = useState(() => EditorState.createEmpty());
    
      return (
        <div>
          <Editor editorState={editorState} onChange={setEditorState} />
        </div>
      );
    }
    
    export default MyEditor;
    
  • prosemirror-view:

    Basic example of prosemirror-view

    import { EditorState } from 'prosemirror-state';
    import { EditorView } from 'prosemirror-view';
    import { schema } from 'prosemirror-schema-basic';
    import { exampleSetup } from 'prosemirror-example-setup';
    
    const state = EditorState.create({
      schema,
      plugins: exampleSetup({ schema }),
    });
    
    const view = new EditorView(document.querySelector('#editor'), {
      state,
    });
    
  • slate:

    Simple example of slate editor

    import React, { useMemo, useState } from 'react';
    import { createEditor } from 'slate';
    import { Slate, Editable, withReact } from 'slate-react';
    
    function MyEditor() {
      const editor = useMemo(() => withReact(createEditor()), []);
      const [value, setValue] = useState([
        { type: 'paragraph', children: [{ text: 'A line of text in a paragraph.' }] },
      ]);
    
      return (
        <Slate editor={editor} value={value} onChange={newValue => setValue(newValue)}>
          <Editable />
        </Slate>
      );
    }
    
    export default MyEditor;
    
  • tiptap:

    Basic example of tiptap editor

    import { Editor } from '@tiptap/core';
    import StarterKit from '@tiptap/starter-kit';
    
    const editor = new Editor({
      element: document.querySelector('#editor'),
      extensions: [StarterKit],
      content: '<p>Hello World!</p>',
    });
    

How to Choose: draft-js vs prosemirror-view vs slate vs tiptap

  • draft-js:

    Choose draft-js if you need a highly customizable editor with a focus on immutability and React integration. It is ideal for projects that require fine-grained control over the editing experience and state management.

  • prosemirror-view:

    Choose prosemirror-view if you need a modular and extensible editor with a strong emphasis on collaborative editing and real-time updates. It is suitable for applications that require complex document structures and advanced features like tables, footnotes, and annotations.

  • slate:

    Choose slate if you need a flexible and extensible editor that allows for deep customization of the editing experience. It is particularly useful for projects that require custom behaviors, plugins, and a more hands-on approach to editor development.

  • tiptap:

    Choose tiptap if you want a modern, user-friendly editor built on top of ProseMirror with a focus on ease of use and quick setup. It is ideal for projects that need a feature-rich editor with a simple API and built-in support for common formatting options.

README for draft-js

draftjs-logo

Draft.js

Build Status npm version

Live Demo


Draft.js is a JavaScript rich text editor framework, built for React and backed by an immutable model.

  • Extensible and Customizable: We provide the building blocks to enable the creation of a broad variety of rich text composition experiences, from basic text styles to embedded media.
  • Declarative Rich Text: Draft.js fits seamlessly into React applications, abstracting away the details of rendering, selection, and input behavior with a familiar declarative API.
  • Immutable Editor State: The Draft.js model is built with immutable-js, offering an API with functional state updates and aggressively leveraging data persistence for scalable memory usage.

Learn how to use Draft.js in your own project.

API Notice

Before getting started, please be aware that we recently changed the API of Entity storage in Draft. The latest version, v0.10.0, supports both the old and new API. Following that up will be v0.11.0 which will remove the old API. If you are interested in helping out, or tracking the progress, please follow issue 839.

Getting Started

npm install --save draft-js react react-dom

or

yarn add draft-js react react-dom

Draft.js depends on React and React DOM which must also be installed.

Using Draft.js

import React from 'react';
import ReactDOM from 'react-dom';
import {Editor, EditorState} from 'draft-js';

class MyEditor extends React.Component {
  constructor(props) {
    super(props);
    this.state = {editorState: EditorState.createEmpty()};
    this.onChange = (editorState) => this.setState({editorState});
    this.setEditor = (editor) => {
      this.editor = editor;
    };
    this.focusEditor = () => {
      if (this.editor) {
        this.editor.focus();
      }
    };
  }

  componentDidMount() {
    this.focusEditor();
  }

  render() {
    return (
      <div style={styles.editor} onClick={this.focusEditor}>
        <Editor
          ref={this.setEditor}
          editorState={this.state.editorState}
          onChange={this.onChange}
        />
      </div>
    );
  }
}

const styles = {
  editor: {
    border: '1px solid gray',
    minHeight: '6em'
  }
};

ReactDOM.render(
  <MyEditor />,
  document.getElementById('container')
);

Since the release of React 16.8, you can use Hooks as a way to work with EditorState without using a class.

import React from 'react';
import ReactDOM from 'react-dom';
import {Editor, EditorState} from 'draft-js';

function MyEditor() {
  const [editorState, setEditorState] = React.useState(
    EditorState.createEmpty()
  );

  const editor = React.useRef(null);

  function focusEditor() {
    editor.current.focus();
  }

  React.useEffect(() => {
    focusEditor()
  }, []);

  return (
    <div onClick={focusEditor}>
      <Editor
        ref={editor}
        editorState={editorState}
        onChange={editorState => setEditorState(editorState)}
      />
    </div>
  );
}

Note that the editor itself is only as tall as its contents. In order to give users a visual cue, we recommend setting a border and a minimum height via the .DraftEditor-root CSS selector, or using a wrapper div like in the above example.

Because Draft.js supports unicode, you must have the following meta tag in the <head> </head> block of your HTML file:

<meta charset="utf-8" />

Further examples of how Draft.js can be used are provided below.

Examples

Visit http://draftjs.org/ to try out a basic rich editor example.

The repository includes a variety of different editor examples to demonstrate some of the features offered by the framework.

To run the examples, first build Draft.js locally. The Draft.js build is tested with Yarn v1 only. If you're using any other package manager and something doesn't work, try using yarn v1:

git clone https://github.com/facebook/draft-js.git
cd draft-js
yarn install
yarn run build

then open the example HTML files in your browser.

Draft.js is used in production on Facebook, including status and comment inputs, Notes, and messenger.com.

Browser Support

IE / Edge
IE / Edge
Firefox
Firefox
Chrome
Chrome
Safari
Safari
iOS Safari
iOS Safari
Chrome for Android
Chrome for Android
IE11, Edge [1, 2]last 2 versionslast 2 versionslast 2 versionsnot fully supported [3]not fully supported [3]

[1] May need a shim or a polyfill for some syntax used in Draft.js (docs).

[2] IME inputs have known issues in these browsers, especially Korean (docs).

[3] There are known issues with mobile browsers, especially on Android (docs).

Resources and Ecosystem

Check out this curated list of articles and open-sourced projects/utilities: Awesome Draft-JS.

Discussion and Support

Join our Slack team!

Contribute

We actively welcome pull requests. Learn how to contribute.

License

Draft.js is MIT licensed.

Examples provided in this repository and in the documentation are separately licensed.