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

prosemirror-collab

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prosemirror-collab

Collaborative editing for ProseMirror

  • 1.3.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is prosemirror-collab?

The prosemirror-collab package provides collaborative editing functionality for ProseMirror, a toolkit for building rich-text editors. It allows multiple users to edit the same document simultaneously, with changes being synchronized in real-time.

What are prosemirror-collab's main functionalities?

Collaboration Plugin

This code sets up a ProseMirror editor with the collaboration plugin enabled. It initializes the editor state with a document and includes the collab plugin to handle collaborative editing.

const { collab, receiveTransaction, sendableSteps, getVersion } = require('prosemirror-collab');
const { EditorState } = require('prosemirror-state');
const { EditorView } = require('prosemirror-view');
const { Schema, DOMParser } = require('prosemirror-model');
const { schema } = require('prosemirror-schema-basic');
const { exampleSetup } = require('prosemirror-example-setup');

let doc = DOMParser.fromSchema(schema).parse(document.querySelector('#content'));
let state = EditorState.create({
  doc,
  plugins: exampleSetup({ schema }).concat(collab({ version: 0 }))
});

let view = new EditorView(document.querySelector('#editor'), { state });

Receiving Transactions

This function receives transactions from other collaborators and applies them to the editor state. It uses the receiveTransaction function from the prosemirror-collab package.

function receiveCollabTransaction(view, steps, clientIDs) {
  let tr = receiveTransaction(view.state, steps, clientIDs);
  view.updateState(view.state.apply(tr));
}

Sending Steps

This function checks if there are any steps to be sent to the server for synchronization. It uses the sendableSteps function from the prosemirror-collab package.

function sendCollabSteps(view) {
  let sendable = sendableSteps(view.state);
  if (sendable) {
    // Send sendable.steps and sendable.clientID to the server
  }
}

Getting Document Version

This function retrieves the current version of the document being edited. It uses the getVersion function from the prosemirror-collab package.

function getDocVersion(view) {
  return getVersion(view.state);
}

Other packages similar to prosemirror-collab

FAQs

Package last updated on 17 May 2023

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