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.11.1 to 0.12.0

92

dist/collab.js
var ref = require("prosemirror-state");
var Plugin = ref.Plugin;
var PluginKey = ref.PluginKey;
var RopeSequence = require("rope-sequence")

@@ -9,4 +10,4 @@

function rebaseSteps(transform, steps, inverted, inside) {
for (var i = inverted.length - 1; i >= 0; i--) transform.step(inverted[i])
for (var i$1 = 0; i$1 < inside.length; i$1++) transform.step(inside[i$1])
for (var i = inverted.length - 1; i >= 0; i--) { transform.step(inverted[i]) }
for (var i$1 = 0; i$1 < inside.length; i$1++) { transform.step(inside[i$1]) }
for (var i$2 = 0, mapFrom = inverted.length; i$2 < steps.length; i$2++) {

@@ -16,3 +17,3 @@ var mapped = steps[i$2].map(transform.mapping.slice(mapFrom))

if (mapped && !transform.maybeStep(mapped).failed)
transform.mapping.setMirror(mapFrom, transform.steps.length - 1)
{ transform.mapping.setMirror(mapFrom, transform.steps.length - 1) }
}

@@ -47,4 +48,4 @@ return inverted.length + inside.length

for (var i = start; i < transform.steps.length; i++)
add.push({step: transform.steps[i],
inverted: transform.steps[i].invert(transform.docs[i])})
{ add.push({step: transform.steps[i],
inverted: transform.steps[i].invert(transform.docs[i])}) }
return add

@@ -59,9 +60,9 @@ }

function makeReceiveAction(state, steps, clientIDs, ourID) {
var collab = state.collab
var version = collab.version + steps.length
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 = collab.unconfirmed.slice(ours)
while (ours < clientIDs.length && clientIDs[ours] == ourID) { ++ours }
var unconfirmed = collabState.unconfirmed.slice(ours)
steps = ours ? steps.slice(ours) : steps

@@ -71,3 +72,3 @@

if (!steps.length)
return {type: "collabConfirm", collabState: new CollabState(version, unconfirmed)}
{ return {type: "collabConfirm", collabState: new CollabState(version, unconfirmed)} }

@@ -79,3 +80,3 @@ var nUnconfirmed = unconfirmed.length

} else {
for (var i = 0; i < steps.length; i++) transform.step(steps[i])
for (var i = 0; i < steps.length; i++) { transform.step(steps[i]) }
}

@@ -85,28 +86,12 @@

var newCollabState = new CollabState(version, unconfirmed)
return transform.action({rebased: nUnconfirmed, addToHistory: false, newCollabState: newCollabState, interaction: false})
return transform.action({
rebased: nUnconfirmed,
addToHistory: false,
collabState: newCollabState,
interaction: false
})
}
var plugin = new Plugin({
stateFields: {
collab: {
init: function (_, state) { return new CollabState(plugin.find(state).config.version, RopeSequence.empty); },
applyAction: function applyAction(ref, action) {
var collab = ref.collab;
var collabKey = new PluginKey("collab")
if (action.type == "transform")
return action.newCollabState ||
new CollabState(collab.version, collab.unconfirmed.append(unconfirmedFrom(action.transform)))
if (action.type == "collabConfirm")
return action.collabState
return collab
}
}
},
config: {
version: 0,
clientID: -1
}
})
// :: (?Object) → Plugin

@@ -127,8 +112,24 @@ //

function collab(config) {
var clientID = config && config.clientID
if (clientID == null) clientID = Math.floor(Math.random() * 0xFFFFFFFF)
if ( config === void 0 ) config = {};
var reconf = {clientID: clientID}
if (config && config.version != null) reconf.version = config.version
return plugin.configure(reconf)
config = {version: config.version || 0,
clientID: config.clientID == null ? Math.floor(Math.random() * 0xFFFFFFFF) : config.clientID}
return new Plugin({
key: collabKey,
state: {
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 }
return collab
}
},
config: config
})
}

@@ -142,3 +143,3 @@ exports.collab = collab

function receiveAction(state, steps, clientIDs) {
return makeReceiveAction(state, steps, clientIDs, plugin.find(state).config.clientID)
return makeReceiveAction(state, steps, clientIDs, collabKey.get(state).options.config.clientID)
}

@@ -152,7 +153,8 @@ exports.receiveAction = receiveAction

function sendableSteps(state) {
if (state.collab.unconfirmed.length == 0) return null
var collabState = collabKey.getState(state)
if (collabState.unconfirmed.length == 0) { return null }
return {
version: state.collab.version,
steps: state.collab.unconfirmed.map(function (s) { return s.step; }),
clientID: plugin.find(state).config.clientID
version: collabState.version,
steps: collabState.unconfirmed.map(function (s) { return s.step; }),
clientID: collabKey.get(state).options.config.clientID
}

@@ -166,4 +168,4 @@ }

function getVersion(state) {
return state.collab.version
return collabKey.getState(state).version
}
exports.getVersion = getVersion
{
"name": "prosemirror-collab",
"version": "0.11.1",
"version": "0.12.0",
"description": "Collaborative editing for ProseMirror",

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

"dependencies": {
"prosemirror-state": "^0.11.0",
"prosemirror-state": "^0.12.0",
"rope-sequence": "^1.2.0"

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

"buble": "~0.14.0",
"prosemirror-model": "^0.11.0",
"prosemirror-transform": "^0.11.0",
"prosemirror-history": "^0.11.0",
"prosemirror-model": "^0.12.0",
"prosemirror-transform": "^0.12.0",
"prosemirror-history": "^0.12.0",
"ist": "^1.0.0",

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

@@ -1,2 +0,2 @@

const {Plugin} = require("prosemirror-state")
const {Plugin, PluginKey} = require("prosemirror-state")
const RopeSequence = require("rope-sequence")

@@ -55,4 +55,4 @@

function makeReceiveAction(state, steps, clientIDs, ourID) {
let collab = state.collab
let version = collab.version + steps.length
let collabState = collabKey.getState(state)
let version = collabState.version + steps.length

@@ -62,3 +62,3 @@ // Find out which prefix of the steps originated with us

while (ours < clientIDs.length && clientIDs[ours] == ourID) ++ours
let unconfirmed = collab.unconfirmed.slice(ours)
let unconfirmed = collabState.unconfirmed.slice(ours)
steps = ours ? steps.slice(ours) : steps

@@ -80,26 +80,12 @@

let newCollabState = new CollabState(version, unconfirmed)
return transform.action({rebased: nUnconfirmed, addToHistory: false, newCollabState, interaction: false})
return transform.action({
rebased: nUnconfirmed,
addToHistory: false,
collabState: newCollabState,
interaction: false
})
}
const plugin = new Plugin({
stateFields: {
collab: {
init: (_, state) => new CollabState(plugin.find(state).config.version, RopeSequence.empty),
applyAction({collab}, action) {
if (action.type == "transform")
return action.newCollabState ||
new CollabState(collab.version, collab.unconfirmed.append(unconfirmedFrom(action.transform)))
if (action.type == "collabConfirm")
return action.collabState
return collab
}
}
},
const collabKey = new PluginKey("collab")
config: {
version: 0,
clientID: -1
}
})
// :: (?Object) → Plugin

@@ -119,9 +105,23 @@ //

// other clients. Defaults to a random 32-bit number.
function collab(config) {
let clientID = config && config.clientID
if (clientID == null) clientID = Math.floor(Math.random() * 0xFFFFFFFF)
function collab(config = {}) {
config = {version: config.version || 0,
clientID: config.clientID == null ? Math.floor(Math.random() * 0xFFFFFFFF) : config.clientID}
let reconf = {clientID}
if (config && config.version != null) reconf.version = config.version
return plugin.configure(reconf)
return new Plugin({
key: collabKey,
state: {
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
return collab
}
},
config
})
}

@@ -135,3 +135,3 @@ exports.collab = collab

function receiveAction(state, steps, clientIDs) {
return makeReceiveAction(state, steps, clientIDs, plugin.find(state).config.clientID)
return makeReceiveAction(state, steps, clientIDs, collabKey.get(state).options.config.clientID)
}

@@ -145,7 +145,8 @@ exports.receiveAction = receiveAction

function sendableSteps(state) {
if (state.collab.unconfirmed.length == 0) return null
let collabState = collabKey.getState(state)
if (collabState.unconfirmed.length == 0) return null
return {
version: state.collab.version,
steps: state.collab.unconfirmed.map(s => s.step),
clientID: plugin.find(state).config.clientID
version: collabState.version,
steps: collabState.unconfirmed.map(s => s.step),
clientID: collabKey.get(state).options.config.clientID
}

@@ -159,4 +160,4 @@ }

function getVersion(state) {
return state.collab.version
return collabKey.getState(state).version
}
exports.getVersion = getVersion
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