Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

y-prosemirror

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

y-prosemirror

Prosemirror bindings for Yjs

  • 1.2.15
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is y-prosemirror?

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.

What are y-prosemirror's main functionalities?

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
});

Other packages similar to y-prosemirror

Keywords

FAQs

Package last updated on 04 Dec 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc