ProseMirror is a collection of open-sourced libraries which provides the utilities for rich text editing.
- It's free & open-sourced.
- It has well-documented APIs.
- It has active community support.
- It supports collaborative editing.
- It's is designed to support modern editor featured. Such as collaborative editing, custom rich contents...etc.
- https://prosemirror.net/examples/
- https://atlaskit.atlassian.com/packages/editor/editor-core/example/full-page-minimal
┌─────────────┐ ┌────────────┐ ┌──────────┐
│ │ │ │ │ │
│ EditorState ├───►│ EditorView ├───►│ Editing │
│ │ │ │ │ │
└─────────────┘ └────────────┘ └─────┬────┘
▲ │
│ │
│ ┌─────────────┐ │
│ │ │ │
└───────────┤ Transaction │ ◄───────┘
│ │
└─────────────┘
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.
- 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);
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);
ProseMirror does not provide any UI, so we need to build the UI and all the interactions from scratch.
- Create schema.
- Create editor state.
- Create editor view.
- Add basic editing plugins (e.g. history)
- Add basic keyboard shorts bindings (e.g. undo, redo, new line...etc).
- Add transform to modify document.
- Add plugin for text caret.
- Add keyboard mapping to edit.
- Add macro (input rule) to edit.
- npm install
- npm run start
- This app is created with create-react-app. Please read its instruction if needed.
- run
npm run deploy
to publish DEMO.