prosemirror-collab
Advanced tools
Comparing version 0.22.0 to 0.23.0
@@ -16,3 +16,3 @@ # How to contribute | ||
[GitHub issue tracker](http://github.com/prosemirror/prosemirror/issues). | ||
Before reporting a bug, read these pointers. | ||
Before reporting a bug, please read these pointers. | ||
@@ -26,6 +26,7 @@ - The issue tracker is for *bugs*, not requests for help. Questions | ||
- Mention very precisely what went wrong. "X is broken" is not a good bug | ||
report. What did you expect to happen? What happened instead? Describe the | ||
exact steps a maintainer has to take to make the problem occur. We can not | ||
fix something that we can not observe. | ||
- Mention very precisely what went wrong. "X is broken" is not a good | ||
bug report. What did you expect to happen? What happened instead? | ||
Describe the exact steps a maintainer has to take to make the | ||
problem occur. A screencast can be useful, but is no substitute for | ||
a textual description. | ||
@@ -50,4 +51,4 @@ - A great way to make it easy to reproduce your problem, if it can not | ||
- Follow the code style of the rest of the project (see below). Run | ||
`npm run lint` (in the main repository checkout) that the linter is | ||
happy. | ||
`npm run lint` (in the main repository checkout) to make sure that | ||
the linter is happy. | ||
@@ -54,0 +55,0 @@ - If your changes are easy to test or likely to regress, add tests in |
@@ -1,9 +0,11 @@ | ||
var ref = require("prosemirror-state"); | ||
var Plugin = ref.Plugin; | ||
var PluginKey = ref.PluginKey; | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var prosemirrorState = require('prosemirror-state'); | ||
var Rebaseable = function Rebaseable(step, inverted, origin) { | ||
this.step = step | ||
this.inverted = inverted | ||
this.origin = origin | ||
this.step = step; | ||
this.inverted = inverted; | ||
this.origin = origin; | ||
}; | ||
@@ -15,11 +17,11 @@ | ||
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 = 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-- | ||
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) | ||
result.push(new Rebaseable(mapped, mapped.invert(transform.docs[transform.docs.length - 1]), steps[i$2].origin)) | ||
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)); | ||
} | ||
@@ -29,3 +31,2 @@ } | ||
} | ||
exports.rebaseSteps = rebaseSteps | ||
@@ -43,3 +44,3 @@ // This state field accumulates changes that have to be sent to the | ||
// was enabled. | ||
this.version = version | ||
this.version = version; | ||
@@ -49,15 +50,15 @@ // : [Rebaseable] | ||
// server yet. | ||
this.unconfirmed = unconfirmed | ||
this.unconfirmed = unconfirmed; | ||
}; | ||
function unconfirmedFrom(transform) { | ||
var result = [] | ||
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)) } | ||
transform)); } | ||
return result | ||
} | ||
var collabKey = new PluginKey("collab") | ||
var collabKey = new prosemirrorState.PluginKey("collab"); | ||
@@ -82,5 +83,5 @@ // :: (?Object) → Plugin | ||
config = {version: config.version || 0, | ||
clientID: config.clientID == null ? Math.floor(Math.random() * 0xFFFFFFFF) : config.clientID} | ||
clientID: config.clientID == null ? Math.floor(Math.random() * 0xFFFFFFFF) : config.clientID}; | ||
return new Plugin({ | ||
return new prosemirrorState.Plugin({ | ||
key: collabKey, | ||
@@ -91,3 +92,3 @@ | ||
apply: function apply(tr, collab) { | ||
var newState = tr.getMeta(collabKey) | ||
var newState = tr.getMeta(collabKey); | ||
if (newState) | ||
@@ -104,3 +105,2 @@ { return newState } | ||
} | ||
exports.collab = collab | ||
@@ -117,11 +117,11 @@ // :: (state: EditorState, steps: [Step], clientIDs: [union<number, string>]) → Transaction | ||
// remote steps. | ||
var collabState = collabKey.getState(state) | ||
var version = collabState.version + steps.length | ||
var ourID = collabKey.get(state).spec.config.clientID | ||
var collabState = collabKey.getState(state); | ||
var version = collabState.version + steps.length; | ||
var ourID = collabKey.get(state).spec.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 | ||
var ours = 0; | ||
while (ours < clientIDs.length && clientIDs[ours] == ourID) { ++ours; } | ||
var unconfirmed = collabState.unconfirmed.slice(ours); | ||
steps = ours ? steps.slice(ours) : steps; | ||
@@ -132,19 +132,18 @@ // If all steps originated with us, we're done. | ||
var nUnconfirmed = unconfirmed.length | ||
var tr = state.tr | ||
var nUnconfirmed = unconfirmed.length; | ||
var tr = state.tr; | ||
if (nUnconfirmed) { | ||
unconfirmed = rebaseSteps(unconfirmed, steps, tr) | ||
unconfirmed = rebaseSteps(unconfirmed, steps, tr); | ||
} else { | ||
for (var i = 0; i < steps.length; i++) { tr.step(steps[i]) } | ||
unconfirmed = [] | ||
for (var i = 0; i < steps.length; i++) { tr.step(steps[i]); } | ||
unconfirmed = []; | ||
} | ||
var newCollabState = new CollabState(version, unconfirmed) | ||
var newCollabState = new CollabState(version, unconfirmed); | ||
return tr.setMeta("rebased", nUnconfirmed).setMeta("addToHistory", false).setMeta(collabKey, newCollabState) | ||
} | ||
exports.receiveTransaction = receiveTransaction | ||
// :: (state: EditorState) → ?{version: number, steps: [Step], clientID: union<number, string>, origins: [Transaction]} | ||
// Provides the data describing the editor's unconfirmed steps, which | ||
// you'd send to the central authority. Returns null when there is | ||
// Provides data describing the editor's unconfirmed steps, which need | ||
// to be sent to the central authority. Returns null when there is | ||
// nothing to send. | ||
@@ -158,3 +157,3 @@ // | ||
function sendableSteps(state) { | ||
var collabState = collabKey.getState(state) | ||
var collabState = collabKey.getState(state); | ||
if (collabState.unconfirmed.length == 0) { return null } | ||
@@ -168,3 +167,2 @@ return { | ||
} | ||
exports.sendableSteps = sendableSteps | ||
@@ -177,2 +175,8 @@ // :: (EditorState) → number | ||
} | ||
exports.getVersion = getVersion | ||
exports.rebaseSteps = rebaseSteps; | ||
exports.collab = collab; | ||
exports.receiveTransaction = receiveTransaction; | ||
exports.sendableSteps = sendableSteps; | ||
exports.getVersion = getVersion; | ||
//# sourceMappingURL=collab.js.map |
{ | ||
"name": "prosemirror-collab", | ||
"version": "0.22.0", | ||
"version": "0.23.0", | ||
"description": "Collaborative editing for ProseMirror", | ||
@@ -19,19 +19,20 @@ "main": "dist/collab.js", | ||
"dependencies": { | ||
"prosemirror-state": "^0.22.0" | ||
"prosemirror-state": "^0.23.0" | ||
}, | ||
"devDependencies": { | ||
"buble": "^0.15.1", | ||
"prosemirror-model": "^0.22.0", | ||
"prosemirror-transform": "^0.22.0", | ||
"prosemirror-history": "^0.22.0", | ||
"ist": "^1.0.0", | ||
"mocha": "^3.0.2", | ||
"rimraf": "^2.5.4", | ||
"prosemirror-test-builder": "^0.22.0" | ||
"prosemirror-history": "^0.23.0", | ||
"prosemirror-model": "^0.23.0", | ||
"prosemirror-test-builder": "^0.23.0", | ||
"prosemirror-transform": "^0.23.0", | ||
"rollup": "^0.49.0", | ||
"rollup-plugin-buble": "^0.15.0" | ||
}, | ||
"scripts": { | ||
"test": "mocha test/test-*.js", | ||
"build": "rimraf dist && buble -i src -o dist", | ||
"prepublish": "npm run build" | ||
"build": "rollup -c", | ||
"watch": "rollup -c -w", | ||
"prepare": "npm run build" | ||
} | ||
} |
@@ -9,14 +9,10 @@ # prosemirror-collab | ||
This [module](http://prosemirror.net/ref.html#collab) implements a | ||
This [module](http://prosemirror.net/docs/ref/#collab) implements a | ||
plugin that helps track and merge changes for | ||
[collaborative editing](http://prosemirror.net/guide/collab.html). | ||
[collaborative editing](http://prosemirror\.net/docs/guide/#collab). | ||
The [project page](http://prosemirror.net) has more information, a | ||
number of [demos](http://prosemirror.net/#demos) and the | ||
[documentation](http://prosemirror.net/docs.html). | ||
number of [examples](http://prosemirror.net/examples/) and the | ||
[documentation](http://prosemirror.net/docs/). | ||
**NOTE:** This project is in *BETA* stage. It isn't thoroughly tested, | ||
and the API might still change across `0.x` releases. You are welcome | ||
to use it, but don't expect it to be very stable yet. | ||
This code is released under an | ||
@@ -23,0 +19,0 @@ [MIT license](https://github.com/prosemirror/prosemirror/tree/master/LICENSE). |
@@ -1,2 +0,2 @@ | ||
const {Plugin, PluginKey} = require("prosemirror-state") | ||
import {Plugin, PluginKey} from "prosemirror-state" | ||
@@ -14,3 +14,3 @@ class Rebaseable { | ||
// redo them. | ||
function rebaseSteps(steps, over, transform) { | ||
export function rebaseSteps(steps, over, transform) { | ||
for (let i = steps.length - 1; i >= 0; i--) transform.step(steps[i].inverted) | ||
@@ -29,3 +29,2 @@ for (let i = 0; i < over.length; i++) transform.step(over[i]) | ||
} | ||
exports.rebaseSteps = rebaseSteps | ||
@@ -78,3 +77,3 @@ // This state field accumulates changes that have to be sent to the | ||
// other clients. Defaults to a random 32-bit number. | ||
function collab(config = {}) { | ||
export function collab(config = {}) { | ||
config = {version: config.version || 0, | ||
@@ -101,3 +100,2 @@ clientID: config.clientID == null ? Math.floor(Math.random() * 0xFFFFFFFF) : config.clientID} | ||
} | ||
exports.collab = collab | ||
@@ -108,3 +106,3 @@ // :: (state: EditorState, steps: [Step], clientIDs: [union<number, string>]) → Transaction | ||
// adjust to the authority's view of the document. | ||
function receiveTransaction(state, steps, clientIDs) { | ||
export function receiveTransaction(state, steps, clientIDs) { | ||
// Pushes a set of steps (received from the central authority) into | ||
@@ -141,7 +139,6 @@ // the editor state (which should have the collab plugin enabled). | ||
} | ||
exports.receiveTransaction = receiveTransaction | ||
// :: (state: EditorState) → ?{version: number, steps: [Step], clientID: union<number, string>, origins: [Transaction]} | ||
// Provides the data describing the editor's unconfirmed steps, which | ||
// you'd send to the central authority. Returns null when there is | ||
// Provides data describing the editor's unconfirmed steps, which need | ||
// to be sent to the central authority. Returns null when there is | ||
// nothing to send. | ||
@@ -154,3 +151,3 @@ // | ||
// unchanged objects. | ||
function sendableSteps(state) { | ||
export function sendableSteps(state) { | ||
let collabState = collabKey.getState(state) | ||
@@ -165,3 +162,2 @@ if (collabState.unconfirmed.length == 0) return null | ||
} | ||
exports.sendableSteps = sendableSteps | ||
@@ -171,5 +167,4 @@ // :: (EditorState) → number | ||
// central authority. | ||
function getVersion(state) { | ||
export function getVersion(state) { | ||
return collabKey.getState(state).version | ||
} | ||
exports.getVersion = getVersion |
This module implements an API into which a communication channel for | ||
collaborative editing can be hooked. See | ||
[this guide](/docs/guides/collab/) for more details and an example. | ||
[the guide](/docs/guide/#collab) for more details and an example. | ||
@@ -5,0 +5,0 @@ @collab |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30250
10
300
23
+ Addedprosemirror-model@0.23.1(transitive)
+ Addedprosemirror-state@0.23.0(transitive)
+ Addedprosemirror-transform@0.23.0(transitive)
- Removedprosemirror-model@0.22.0(transitive)
- Removedprosemirror-state@0.22.0(transitive)
- Removedprosemirror-transform@0.22.2(transitive)
Updatedprosemirror-state@^0.23.0