Giter Site home page Giter Site logo

learn-prosemirror-typescript-react-app's Introduction

DEMO

Learning ProseMirror

ProseMirror is a collection of open-sourced libraries which provides the utilities for rich text editing.

Why ProseMirror?

Examples

Basic Data Flow

 ┌─────────────┐    ┌────────────┐    ┌──────────┐
 │             │    │            │    │          │
 │ EditorState ├───►│ EditorView ├───►│  Editing │
 │             │    │            │    │          │
 └─────────────┘    └────────────┘    └─────┬────┘
        ▲                                   │
        │                                   │
        │           ┌─────────────┐         │
        │           │             │         │
        └───────────┤ Transaction │ ◄───────┘
                    │             │
                    └─────────────┘

Core Data Structures

Schema

A schema defined the supported contents in the editor. The simplest schema could be the one that only supports plain text. In Notebooks, it uses the schema that supports list, table, image, video, rurbic-card...etc.

Different products that want to build different kind of editors that support their own specific needs. For example, we have different editors for comments and students work.

EditorState

  • The serializable state of the editor which renders the state.
  • It's immutable and read-only.
  • It contains the selection and the root node of the document.

A state can be created from raw JSON blob:

const editorState = EditorState.create({
  doc: schema.nodeFromJSON(json),
  schema: schema,
});

Or it can be created by applying transform

const editorState = previousEditorState.apply(transform);

Transform

Most editing features could be handled by writing codes that handle transform. A transform defines sequential steps of how to update editor state.

For example, applying a transform to an editor state will generate a new editor state.

let transform = editorState.tr;
transform = formatTextHighlightColor(transform, "#222");
transform = insertText(transform, "hello");
const nextEditorState = editorState.apply(transform);

Build your your first editor.

ProseMirror does not provide any UI, so we need to build the UI and all the interactions from scratch.

  1. Create schema.
  2. Create editor state.
  3. Create editor view.
  4. Add basic editing plugins (e.g. history)
  5. Add basic keyboard shorts bindings (e.g. undo, redo, new line...etc).

Advance editor features.

  • Add transform to modify document.
  • Add plugin for text caret.
  • Add keyboard mapping to edit.
  • Add macro (input rule) to edit.

Quick Start

  • npm install
  • npm run start

Developer Guide

  1. This app is created with create-react-app. Please read its instruction if needed.
  2. run npm run deploy to publish DEMO.

learn-prosemirror-typescript-react-app's People

Contributors

hedgerwang avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.