Employee Spotlight
From Academia to Industry
Philipp Burckhardt recounts his journey from childhood computer fascinations, to building an e-learning platform at Carnegie Mellon University, and on to his current role at Socket.
y-prosemirror
Advanced tools
Package description
The y-prosemirror package is a binding for ProseMirror, a toolkit for building rich-text editors, to Yjs, a high-performance CRDT (Conflict-free Replicated Data Type) for building collaborative applications. This package allows you to create collaborative rich-text editors that can be used in real-time by multiple users.
Collaborative Editing
This code sets up a ProseMirror editor with Yjs bindings, enabling collaborative editing. The ySyncPlugin synchronizes the editor state with a Yjs document, yCursorPlugin shows the cursor positions of other users, and yUndoPlugin adds undo/redo functionality.
const Y = require('yjs');
const { ySyncPlugin, yCursorPlugin, yUndoPlugin, undo, redo } = require('y-prosemirror');
const { EditorState } = require('prosemirror-state');
const { EditorView } = require('prosemirror-view');
const { schema } = require('prosemirror-schema-basic');
const ydoc = new Y.Doc();
const yXmlFragment = ydoc.getXmlFragment('prosemirror');
const state = EditorState.create({
schema,
plugins: [
ySyncPlugin(yXmlFragment),
yCursorPlugin(ydoc),
yUndoPlugin()
]
});
const view = new EditorView(document.querySelector('#editor'), {
state
});
Undo/Redo Functionality
This code demonstrates how to use the undo and redo functions provided by y-prosemirror to manage undo/redo actions in a collaborative editor.
const { undo, redo } = require('y-prosemirror');
// To undo the last change
undo(view.state, view.dispatch);
// To redo the last undone change
redo(view.state, view.dispatch);
Cursor Synchronization
This code sets up cursor synchronization in a collaborative ProseMirror editor using the yCursorPlugin. It shows the cursor positions of other users in real-time.
const { yCursorPlugin } = require('y-prosemirror');
const ydoc = new Y.Doc();
const yXmlFragment = ydoc.getXmlFragment('prosemirror');
const state = EditorState.create({
schema,
plugins: [
ySyncPlugin(yXmlFragment),
yCursorPlugin(ydoc)
]
});
const view = new EditorView(document.querySelector('#editor'), {
state
});
Tiptap is a headless, framework-agnostic, and collaborative editor built on top of ProseMirror. It provides a more modern and flexible API compared to y-prosemirror and includes built-in support for collaborative editing using Yjs.
Quill is a powerful, rich text editor that offers a variety of features for building collaborative applications. While it does not natively support Yjs, it can be integrated with Yjs for collaborative editing, similar to y-prosemirror.
Slate is a completely customizable framework for building rich text editors. It provides a more flexible and extensible API compared to ProseMirror. Like Quill, it can be integrated with Yjs for collaborative editing.
Readme
ProseMirror Binding for Yjs - Demo
This binding maps a Y.XmlFragment to the ProseMirror state.
import { prosemirrorPlugin, cursorPlugin } from 'y-prosemirror'
..
const type = ydocument.get('prosemirror', Y.XmlFragment)
const prosemirrorView = new EditorView(document.querySelector('#editor'), {
state: EditorState.create({
schema,
plugins: exampleSetup({ schema }).concat([prosemirrorPlugin(type), cursorPlugin])
})
})
Also look here for a working example.
The MIT License © Kevin Jahns
FAQs
Prosemirror bindings for Yjs
The npm package y-prosemirror receives a total of 92,719 weekly downloads. As such, y-prosemirror popularity was classified as popular.
We found that y-prosemirror demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Employee Spotlight
Philipp Burckhardt recounts his journey from childhood computer fascinations, to building an e-learning platform at Carnegie Mellon University, and on to his current role at Socket.
Security News
Git dependencies in open source packages can introduce significant risks, including lack of version control, stability issues, dependency drift, and difficulty in auditing, making them potential targets for supply chain attacks.
Security News
Node.js has added experimental support for TypeScript, a move that highlights the growing importance of TypeScript in modern development.