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 - npm Package Compare versions

Comparing version 0.16.0 to 0.17.0

90

dist/collab.js

@@ -51,39 +51,2 @@ var ref = require("prosemirror-state");

// Pushes a set of steps (received from the central authority) into
// the editor state (which should have the collab plugin enabled).
// Will recognize its own changes, and confirm unconfirmed steps as
// appropriate. Remaining unconfirmed steps will be rebased over
// remote steps.
function makeReceiveAction(state, steps, clientIDs, ourID) {
var collabState = collabKey.getState(state)
var version = collabState.version + steps.length
// Find out which prefix of the steps originated with us
var ours = 0
while (ours < clientIDs.length && clientIDs[ours] == ourID) { ++ours }
var unconfirmed = collabState.unconfirmed.slice(ours)
steps = ours ? steps.slice(ours) : steps
// If all steps originated with us, we're done.
if (!steps.length)
{ return {type: "collabConfirm", collabState: new CollabState(version, unconfirmed)} }
var nUnconfirmed = unconfirmed.length
var transform = state.tr
if (nUnconfirmed) {
rebaseSteps(transform, unconfirmed.map(function (s) { return s.step; }), unconfirmed.map(function (s) { return s.inverted; }), steps)
} else {
for (var i = 0; i < steps.length; i++) { transform.step(steps[i]) }
}
unconfirmed = RopeSequence.from(unconfirmedFrom(transform, nUnconfirmed + steps.length))
var newCollabState = new CollabState(version, unconfirmed)
return transform.action({
rebased: nUnconfirmed,
addToHistory: false,
collabState: newCollabState,
sealed: true
})
}
var collabKey = new PluginKey("collab")

@@ -116,8 +79,8 @@

init: function () { return new CollabState(config.version, RopeSequence.empty); },
applyAction: function applyAction(action, collab) {
if (action.type == "transform")
{ return action.collabState ||
new CollabState(collab.version, collab.unconfirmed.append(unconfirmedFrom(action.transform))) }
if (action.type == "collabConfirm")
{ return action.collabState }
apply: function apply(tr, collab) {
var newState = tr.getMeta(collabKey)
if (newState)
{ return newState }
if (tr.docChanged)
{ return new CollabState(collab.version, collab.unconfirmed.append(unconfirmedFrom(tr))) }
return collab

@@ -132,10 +95,39 @@ }

// :: (state: EditorState, steps: [Step], clientIDs: [number]) → Action
// Create an action that represents a set of new steps received from
// the authority. Applying this action moves the state forward to
// :: (state: EditorState, steps: [Step], clientIDs: [number]) → Transaction
// Create a transaction that represents a set of new steps received from
// the authority. Applying this transaction moves the state forward to
// adjust to the authority's view of the document.
function receiveAction(state, steps, clientIDs) {
return makeReceiveAction(state, steps, clientIDs, collabKey.get(state).options.config.clientID)
function receiveTransaction(state, steps, clientIDs) {
// Pushes a set of steps (received from the central authority) into
// the editor state (which should have the collab plugin enabled).
// Will recognize its own changes, and confirm unconfirmed steps as
// appropriate. Remaining unconfirmed steps will be rebased over
// remote steps.
var collabState = collabKey.getState(state)
var version = collabState.version + steps.length
var ourID = collabKey.get(state).options.config.clientID
// Find out which prefix of the steps originated with us
var ours = 0
while (ours < clientIDs.length && clientIDs[ours] == ourID) { ++ours }
var unconfirmed = collabState.unconfirmed.slice(ours)
steps = ours ? steps.slice(ours) : steps
// If all steps originated with us, we're done.
if (!steps.length)
{ return state.tr.setMeta(collabKey, new CollabState(version, unconfirmed)) }
var nUnconfirmed = unconfirmed.length
var tr = state.tr
if (nUnconfirmed) {
rebaseSteps(tr, unconfirmed.map(function (s) { return s.step; }), unconfirmed.map(function (s) { return s.inverted; }), steps)
} else {
for (var i = 0; i < steps.length; i++) { tr.step(steps[i]) }
}
unconfirmed = RopeSequence.from(unconfirmedFrom(tr, nUnconfirmed + steps.length))
var newCollabState = new CollabState(version, unconfirmed)
return tr.setMeta("rebased", nUnconfirmed).setMeta("addToHistory", false).setMeta(collabKey, newCollabState)
}
exports.receiveAction = receiveAction
exports.receiveTransaction = receiveTransaction

@@ -142,0 +134,0 @@ // :: (state: EditorState) → ?{version: number, steps: [Step], clientID: number}

{
"name": "prosemirror-collab",
"version": "0.16.0",
"version": "0.17.0",
"description": "Collaborative editing for ProseMirror",

@@ -19,3 +19,3 @@ "main": "dist/collab.js",

"dependencies": {
"prosemirror-state": "^0.16.0",
"prosemirror-state": "^0.17.0",
"rope-sequence": "^1.2.0"

@@ -25,5 +25,5 @@ },

"buble": "^0.15.1",
"prosemirror-model": "^0.16.0",
"prosemirror-transform": "^0.16.0",
"prosemirror-history": "^0.16.0",
"prosemirror-model": "^0.17.0",
"prosemirror-transform": "^0.17.0",
"prosemirror-history": "^0.17.0",
"ist": "^1.0.0",

@@ -30,0 +30,0 @@ "mocha": "^3.0.2",

@@ -49,39 +49,2 @@ const {Plugin, PluginKey} = require("prosemirror-state")

// Pushes a set of steps (received from the central authority) into
// the editor state (which should have the collab plugin enabled).
// Will recognize its own changes, and confirm unconfirmed steps as
// appropriate. Remaining unconfirmed steps will be rebased over
// remote steps.
function makeReceiveAction(state, steps, clientIDs, ourID) {
let collabState = collabKey.getState(state)
let version = collabState.version + steps.length
// Find out which prefix of the steps originated with us
let ours = 0
while (ours < clientIDs.length && clientIDs[ours] == ourID) ++ours
let unconfirmed = collabState.unconfirmed.slice(ours)
steps = ours ? steps.slice(ours) : steps
// If all steps originated with us, we're done.
if (!steps.length)
return {type: "collabConfirm", collabState: new CollabState(version, unconfirmed)}
let nUnconfirmed = unconfirmed.length
let transform = state.tr
if (nUnconfirmed) {
rebaseSteps(transform, unconfirmed.map(s => s.step), unconfirmed.map(s => s.inverted), steps)
} else {
for (let i = 0; i < steps.length; i++) transform.step(steps[i])
}
unconfirmed = RopeSequence.from(unconfirmedFrom(transform, nUnconfirmed + steps.length))
let newCollabState = new CollabState(version, unconfirmed)
return transform.action({
rebased: nUnconfirmed,
addToHistory: false,
collabState: newCollabState,
sealed: true
})
}
const collabKey = new PluginKey("collab")

@@ -112,8 +75,8 @@

init: () => new CollabState(config.version, RopeSequence.empty),
applyAction(action, collab) {
if (action.type == "transform")
return action.collabState ||
new CollabState(collab.version, collab.unconfirmed.append(unconfirmedFrom(action.transform)))
if (action.type == "collabConfirm")
return action.collabState
apply(tr, collab) {
let newState = tr.getMeta(collabKey)
if (newState)
return newState
if (tr.docChanged)
return new CollabState(collab.version, collab.unconfirmed.append(unconfirmedFrom(tr)))
return collab

@@ -128,10 +91,39 @@ }

// :: (state: EditorState, steps: [Step], clientIDs: [number]) → Action
// Create an action that represents a set of new steps received from
// the authority. Applying this action moves the state forward to
// :: (state: EditorState, steps: [Step], clientIDs: [number]) → Transaction
// Create a transaction that represents a set of new steps received from
// the authority. Applying this transaction moves the state forward to
// adjust to the authority's view of the document.
function receiveAction(state, steps, clientIDs) {
return makeReceiveAction(state, steps, clientIDs, collabKey.get(state).options.config.clientID)
function receiveTransaction(state, steps, clientIDs) {
// Pushes a set of steps (received from the central authority) into
// the editor state (which should have the collab plugin enabled).
// Will recognize its own changes, and confirm unconfirmed steps as
// appropriate. Remaining unconfirmed steps will be rebased over
// remote steps.
let collabState = collabKey.getState(state)
let version = collabState.version + steps.length
let ourID = collabKey.get(state).options.config.clientID
// Find out which prefix of the steps originated with us
let ours = 0
while (ours < clientIDs.length && clientIDs[ours] == ourID) ++ours
let unconfirmed = collabState.unconfirmed.slice(ours)
steps = ours ? steps.slice(ours) : steps
// If all steps originated with us, we're done.
if (!steps.length)
return state.tr.setMeta(collabKey, new CollabState(version, unconfirmed))
let nUnconfirmed = unconfirmed.length
let tr = state.tr
if (nUnconfirmed) {
rebaseSteps(tr, unconfirmed.map(s => s.step), unconfirmed.map(s => s.inverted), steps)
} else {
for (let i = 0; i < steps.length; i++) tr.step(steps[i])
}
unconfirmed = RopeSequence.from(unconfirmedFrom(tr, nUnconfirmed + steps.length))
let newCollabState = new CollabState(version, unconfirmed)
return tr.setMeta("rebased", nUnconfirmed).setMeta("addToHistory", false).setMeta(collabKey, newCollabState)
}
exports.receiveAction = receiveAction
exports.receiveTransaction = receiveTransaction

@@ -138,0 +130,0 @@ // :: (state: EditorState) → ?{version: number, steps: [Step], clientID: number}

@@ -9,4 +9,4 @@ This module implements an API into which a communication channel for

@receiveAction
@receiveTransaction
@sendableSteps
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