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.17.0 to 0.18.0

66

dist/collab.js
var ref = require("prosemirror-state");
var Plugin = ref.Plugin;
var PluginKey = ref.PluginKey;
var RopeSequence = require("rope-sequence")
// : (Transform, [Step], [Step], [Step]) → number
var Rebaseable = function Rebaseable(step, inverted, origin) {
this.step = step
this.inverted = inverted
this.origin = origin
};
// : (Transform, [Rebaseable], [Step]) → [Rebaseable]
// Undo a given set of steps, apply a set of other steps, and then
// redo them.
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$2 = 0, mapFrom = inverted.length; i$2 < steps.length; i$2++) {
var mapped = steps[i$2].map(transform.mapping.slice(mapFrom))
function rebaseSteps(steps, over, transform) {
for (var i = steps.length - 1; i >= 0; i--) { transform.step(steps[i].inverted) }
for (var i$1 = 0; i$1 < over.length; i$1++) { transform.step(over[i$1]) }
var result = []
for (var i$2 = 0, mapFrom = steps.length; i$2 < steps.length; i$2++) {
var mapped = steps[i$2].step.map(transform.mapping.slice(mapFrom))
mapFrom--
if (mapped && !transform.maybeStep(mapped).failed)
{ transform.mapping.setMirror(mapFrom, transform.steps.length - 1) }
if (mapped && !transform.maybeStep(mapped).failed) {
transform.mapping.setMirror(mapFrom, transform.steps.length - 1)
result.push(new Rebaseable(mapped, mapped.invert(transform.docs[transform.docs.length - 1]), steps[i$2].origin))
}
}
return inverted.length + inside.length
return result
}

@@ -35,3 +43,3 @@ exports.rebaseSteps = rebaseSteps

// : RopeSequence<{step: Step, inverted: Step}>
// : [Rebaseable]
// The local steps that havent been successfully sent to the

@@ -42,10 +50,9 @@ // server yet.

function unconfirmedFrom(transform, start) {
if ( start === void 0 ) start = 0;
var add = []
for (var i = start; i < transform.steps.length; i++)
{ add.push({step: transform.steps[i],
inverted: transform.steps[i].invert(transform.docs[i])}) }
return add
function unconfirmedFrom(transform) {
var result = []
for (var i = 0; i < transform.steps.length; i++)
{ result.push(new Rebaseable(transform.steps[i],
transform.steps[i].invert(transform.docs[i]),
transform)) }
return result
}

@@ -79,3 +86,3 @@

state: {
init: function () { return new CollabState(config.version, RopeSequence.empty); },
init: function () { return new CollabState(config.version, []); },
apply: function apply(tr, collab) {

@@ -86,3 +93,3 @@ var newState = tr.getMeta(collabKey)

if (tr.docChanged)
{ return new CollabState(collab.version, collab.unconfirmed.append(unconfirmedFrom(tr))) }
{ return new CollabState(collab.version, collab.unconfirmed.concat(unconfirmedFrom(tr))) }
return collab

@@ -109,3 +116,3 @@ }

var version = collabState.version + steps.length
var ourID = collabKey.get(state).options.config.clientID
var ourID = collabKey.get(state).spec.config.clientID

@@ -125,8 +132,8 @@ // Find out which prefix of the steps originated with us

if (nUnconfirmed) {
rebaseSteps(tr, unconfirmed.map(function (s) { return s.step; }), unconfirmed.map(function (s) { return s.inverted; }), steps)
unconfirmed = rebaseSteps(unconfirmed, steps, tr)
} else {
for (var i = 0; i < steps.length; i++) { tr.step(steps[i]) }
unconfirmed = []
}
unconfirmed = RopeSequence.from(unconfirmedFrom(tr, nUnconfirmed + steps.length))
var newCollabState = new CollabState(version, unconfirmed)

@@ -137,6 +144,12 @@ return tr.setMeta("rebased", nUnconfirmed).setMeta("addToHistory", false).setMeta(collabKey, newCollabState)

// :: (state: EditorState) → ?{version: number, steps: [Step], clientID: number}
// :: (state: EditorState) → ?{version: number, steps: [Step], clientID: number, origins: [Transaction]}
// Provides the data describing the editor's unconfirmed steps, which
// you'd send to the central authority. Returns null when there is
// nothing to send.
//
// `origins` holds the _original_ transactions that produced each
// steps. This can be useful for looking up time stamps and other
// metadata for the steps, but note that the steps may have been
// rebased, whereas the origin transactions are still the old,
// unchanged objects.
function sendableSteps(state) {

@@ -148,3 +161,4 @@ var collabState = collabKey.getState(state)

steps: collabState.unconfirmed.map(function (s) { return s.step; }),
clientID: collabKey.get(state).options.config.clientID
clientID: collabKey.get(state).spec.config.clientID,
get origins() { return this._origins || (this._origins = collabState.unconfirmed.map(function (s) { return s.origin; })) }
}

@@ -151,0 +165,0 @@ }

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

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

"dependencies": {
"prosemirror-state": "^0.17.0",
"rope-sequence": "^1.2.0"
"prosemirror-state": "^0.18.0"
},
"devDependencies": {
"buble": "^0.15.1",
"prosemirror-model": "^0.17.0",
"prosemirror-transform": "^0.17.0",
"prosemirror-history": "^0.17.0",
"prosemirror-model": "^0.18.0",
"prosemirror-transform": "^0.18.0",
"prosemirror-history": "^0.18.0",
"ist": "^1.0.0",

@@ -29,0 +28,0 @@ "mocha": "^3.0.2",

const {Plugin, PluginKey} = require("prosemirror-state")
const RopeSequence = require("rope-sequence")
// : (Transform, [Step], [Step], [Step]) → number
class Rebaseable {
constructor(step, inverted, origin) {
this.step = step
this.inverted = inverted
this.origin = origin
}
}
// : (Transform, [Rebaseable], [Step]) → [Rebaseable]
// Undo a given set of steps, apply a set of other steps, and then
// redo them.
function rebaseSteps(transform, steps, inverted, inside) {
for (let i = inverted.length - 1; i >= 0; i--) transform.step(inverted[i])
for (let i = 0; i < inside.length; i++) transform.step(inside[i])
for (let i = 0, mapFrom = inverted.length; i < steps.length; i++) {
let mapped = steps[i].map(transform.mapping.slice(mapFrom))
function rebaseSteps(steps, over, transform) {
for (let i = steps.length - 1; i >= 0; i--) transform.step(steps[i].inverted)
for (let i = 0; i < over.length; i++) transform.step(over[i])
let result = []
for (let i = 0, mapFrom = steps.length; i < steps.length; i++) {
let mapped = steps[i].step.map(transform.mapping.slice(mapFrom))
mapFrom--
if (mapped && !transform.maybeStep(mapped).failed)
if (mapped && !transform.maybeStep(mapped).failed) {
transform.mapping.setMirror(mapFrom, transform.steps.length - 1)
result.push(new Rebaseable(mapped, mapped.invert(transform.docs[transform.docs.length - 1]), steps[i].origin))
}
}
return inverted.length + inside.length
return result
}

@@ -34,3 +44,3 @@ exports.rebaseSteps = rebaseSteps

// : RopeSequence<{step: Step, inverted: Step}>
// : [Rebaseable]
// The local steps that havent been successfully sent to the

@@ -42,8 +52,9 @@ // server yet.

function unconfirmedFrom(transform, start = 0) {
let add = []
for (let i = start; i < transform.steps.length; i++)
add.push({step: transform.steps[i],
inverted: transform.steps[i].invert(transform.docs[i])})
return add
function unconfirmedFrom(transform) {
let result = []
for (let i = 0; i < transform.steps.length; i++)
result.push(new Rebaseable(transform.steps[i],
transform.steps[i].invert(transform.docs[i]),
transform))
return result
}

@@ -75,3 +86,3 @@

state: {
init: () => new CollabState(config.version, RopeSequence.empty),
init: () => new CollabState(config.version, []),
apply(tr, collab) {

@@ -82,3 +93,3 @@ let newState = tr.getMeta(collabKey)

if (tr.docChanged)
return new CollabState(collab.version, collab.unconfirmed.append(unconfirmedFrom(tr)))
return new CollabState(collab.version, collab.unconfirmed.concat(unconfirmedFrom(tr)))
return collab

@@ -105,3 +116,3 @@ }

let version = collabState.version + steps.length
let ourID = collabKey.get(state).options.config.clientID
let ourID = collabKey.get(state).spec.config.clientID

@@ -121,8 +132,8 @@ // Find out which prefix of the steps originated with us

if (nUnconfirmed) {
rebaseSteps(tr, unconfirmed.map(s => s.step), unconfirmed.map(s => s.inverted), steps)
unconfirmed = rebaseSteps(unconfirmed, steps, tr)
} else {
for (let i = 0; i < steps.length; i++) tr.step(steps[i])
unconfirmed = []
}
unconfirmed = RopeSequence.from(unconfirmedFrom(tr, nUnconfirmed + steps.length))
let newCollabState = new CollabState(version, unconfirmed)

@@ -133,6 +144,12 @@ return tr.setMeta("rebased", nUnconfirmed).setMeta("addToHistory", false).setMeta(collabKey, newCollabState)

// :: (state: EditorState) → ?{version: number, steps: [Step], clientID: number}
// :: (state: EditorState) → ?{version: number, steps: [Step], clientID: number, origins: [Transaction]}
// Provides the data describing the editor's unconfirmed steps, which
// you'd send to the central authority. Returns null when there is
// nothing to send.
//
// `origins` holds the _original_ transactions that produced each
// steps. This can be useful for looking up time stamps and other
// metadata for the steps, but note that the steps may have been
// rebased, whereas the origin transactions are still the old,
// unchanged objects.
function sendableSteps(state) {

@@ -144,3 +161,4 @@ let collabState = collabKey.getState(state)

steps: collabState.unconfirmed.map(s => s.step),
clientID: collabKey.get(state).options.config.clientID
clientID: collabKey.get(state).spec.config.clientID,
get origins() { return this._origins || (this._origins = collabState.unconfirmed.map(s => s.origin)) }
}

@@ -147,0 +165,0 @@ }

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