Compare commits
5 Commits
v13.0.0-25
...
v13.0.0-27
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cbe2abafbb | ||
|
|
c51e8b46c2 | ||
|
|
0cda1630d2 | ||
|
|
d232b883e9 | ||
|
|
3a0e65403f |
@@ -17,11 +17,12 @@ window.onload = function () {
|
|||||||
window.yXmlType.bindToDom(document.body)
|
window.yXmlType.bindToDom(document.body)
|
||||||
}
|
}
|
||||||
window.undoManager = new Y.utils.UndoManager(window.yXmlType, {
|
window.undoManager = new Y.utils.UndoManager(window.yXmlType, {
|
||||||
captureTimeout: 1000
|
captureTimeout: 0
|
||||||
})
|
})
|
||||||
|
|
||||||
document.onkeydown = function interceptUndoRedo (e) {
|
document.onkeydown = function interceptUndoRedo (e) {
|
||||||
if (e.keyCode === 90 && e.ctrlKey) {
|
if (e.keyCode === 90 && e.metaKey) {
|
||||||
|
console.log('uidtaren')
|
||||||
if (!e.shiftKey) {
|
if (!e.shiftKey) {
|
||||||
console.info('Undo!')
|
console.info('Undo!')
|
||||||
window.undoManager.undo()
|
window.undoManager.undo()
|
||||||
|
|||||||
36
package-lock.json
generated
36
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "yjs",
|
"name": "yjs",
|
||||||
"version": "13.0.0-25",
|
"version": "13.0.0-27",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -2808,14 +2808,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"string_decoder": {
|
|
||||||
"version": "1.0.1",
|
|
||||||
"bundled": true,
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"safe-buffer": "5.0.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"string-width": {
|
"string-width": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
@@ -2826,6 +2818,14 @@
|
|||||||
"strip-ansi": "3.0.1"
|
"strip-ansi": "3.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"string_decoder": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"bundled": true,
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"safe-buffer": "5.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"stringstream": {
|
"stringstream": {
|
||||||
"version": "0.0.5",
|
"version": "0.0.5",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
@@ -4868,15 +4868,6 @@
|
|||||||
"duplexer": "0.1.1"
|
"duplexer": "0.1.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"string_decoder": {
|
|
||||||
"version": "1.0.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz",
|
|
||||||
"integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"safe-buffer": "5.1.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"string-width": {
|
"string-width": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
|
||||||
@@ -4898,6 +4889,15 @@
|
|||||||
"resolved": "https://registry.npmjs.org/string.prototype.codepointat/-/string.prototype.codepointat-0.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/string.prototype.codepointat/-/string.prototype.codepointat-0.2.0.tgz",
|
||||||
"integrity": "sha1-aybpvTr8qnvjtCabUm3huCAArHg="
|
"integrity": "sha1-aybpvTr8qnvjtCabUm3huCAArHg="
|
||||||
},
|
},
|
||||||
|
"string_decoder": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz",
|
||||||
|
"integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"safe-buffer": "5.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"strip-ansi": {
|
"strip-ansi": {
|
||||||
"version": "3.0.1",
|
"version": "3.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "yjs",
|
"name": "yjs",
|
||||||
"version": "13.0.0-25",
|
"version": "13.0.0-27",
|
||||||
"description": "A framework for real-time p2p shared editing on any data",
|
"description": "A framework for real-time p2p shared editing on any data",
|
||||||
"main": "./y.node.js",
|
"main": "./y.node.js",
|
||||||
"browser": "./y.js",
|
"browser": "./y.js",
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import commonjs from 'rollup-plugin-commonjs'
|
|||||||
import multiEntry from 'rollup-plugin-multi-entry'
|
import multiEntry from 'rollup-plugin-multi-entry'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
entry: 'test/y-xml.tests.js',
|
entry: 'test/y-map.tests.js',
|
||||||
moduleName: 'y-tests',
|
moduleName: 'y-tests',
|
||||||
format: 'umd',
|
format: 'umd',
|
||||||
plugins: [
|
plugins: [
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import Type from '../Struct/Type.js'
|
import Type from '../Struct/Type.js'
|
||||||
import ItemJSON from '../Struct/ItemJSON.js'
|
import ItemJSON from '../Struct/ItemJSON.js'
|
||||||
|
import ItemString from '../Struct/ItemString.js'
|
||||||
import { logID } from '../MessageHandler/messageToString.js'
|
import { logID } from '../MessageHandler/messageToString.js'
|
||||||
import YEvent from '../Util/YEvent.js'
|
import YEvent from '../Util/YEvent.js'
|
||||||
|
|
||||||
@@ -19,7 +20,11 @@ export default class YArray extends Type {
|
|||||||
while (n !== null) {
|
while (n !== null) {
|
||||||
if (!n._deleted) {
|
if (!n._deleted) {
|
||||||
if (pos < n._length) {
|
if (pos < n._length) {
|
||||||
return n._content[n._length - pos]
|
if (n.constructor === ItemJSON || n.constructor === ItemString) {
|
||||||
|
return n._content[pos]
|
||||||
|
} else {
|
||||||
|
return n
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pos -= n._length
|
pos -= n._length
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -255,7 +255,7 @@ export default class YXmlFragment extends YArray {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
for (let dom of diffChildren) {
|
for (let dom of diffChildren) {
|
||||||
if (dom._yxml != null) {
|
if (dom._yxml != null && dom._yxml !== false) {
|
||||||
applyChangesFromDom(dom)
|
applyChangesFromDom(dom)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,10 +24,45 @@ function isStructInScope (y, struct, scope) {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function applyReverseOperation (y, scope, reverseBuffer) {
|
||||||
|
let performedUndo = false
|
||||||
|
y.transact(() => {
|
||||||
|
while (!performedUndo && reverseBuffer.length > 0) {
|
||||||
|
let undoOp = reverseBuffer.pop()
|
||||||
|
// make sure that it is possible to iterate {from}-{to}
|
||||||
|
y.os.getItemCleanStart(undoOp.fromState)
|
||||||
|
y.os.getItemCleanEnd(undoOp.toState)
|
||||||
|
y.os.iterate(undoOp.fromState, undoOp.toState, op => {
|
||||||
|
if (!op._deleted && isStructInScope(y, op, scope)) {
|
||||||
|
performedUndo = true
|
||||||
|
op._delete(y)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
for (let op of undoOp.deletedStructs) {
|
||||||
|
if (
|
||||||
|
isStructInScope(y, op, scope) &&
|
||||||
|
op._parent !== y &&
|
||||||
|
!op._parent._deleted &&
|
||||||
|
(
|
||||||
|
op._parent._id.user !== y.userID ||
|
||||||
|
op._parent._id.clock < undoOp.fromState.clock ||
|
||||||
|
op._parent._id.clock > undoOp.fromState.clock
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
performedUndo = true
|
||||||
|
op = op._copy(undoOp.deletedStructs)
|
||||||
|
op._integrate(y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return performedUndo
|
||||||
|
}
|
||||||
|
|
||||||
export default class UndoManager {
|
export default class UndoManager {
|
||||||
constructor (scope, options = {}) {
|
constructor (scope, options = {}) {
|
||||||
this.options = options
|
this.options = options
|
||||||
options.captureTimeout = options.captureTimeout || 0
|
options.captureTimeout = options.captureTimeout == null ? 500 : options.captureTimeout
|
||||||
this._undoBuffer = []
|
this._undoBuffer = []
|
||||||
this._redoBuffer = []
|
this._redoBuffer = []
|
||||||
this._scope = scope
|
this._scope = scope
|
||||||
@@ -36,12 +71,11 @@ export default class UndoManager {
|
|||||||
const y = scope._y
|
const y = scope._y
|
||||||
this.y = y
|
this.y = y
|
||||||
y.on('afterTransaction', (y, remote) => {
|
y.on('afterTransaction', (y, remote) => {
|
||||||
if (!remote && (y._transaction.beforeState.has(y.userID) || y._transaction.deletedStructs.size > 0)) {
|
if (!remote && y._transaction.changedParentTypes.has(scope)) {
|
||||||
let reverseOperation = new ReverseOperation(y)
|
let reverseOperation = new ReverseOperation(y)
|
||||||
if (!this._undoing) {
|
if (!this._undoing) {
|
||||||
let lastUndoOp = this._undoBuffer.length > 0 ? this._undoBuffer[this._undoBuffer.length - 1] : null
|
let lastUndoOp = this._undoBuffer.length > 0 ? this._undoBuffer[this._undoBuffer.length - 1] : null
|
||||||
if (lastUndoOp !== null && lastUndoOp.created - reverseOperation.created <= options.captureTimeout) {
|
if (lastUndoOp !== null && reverseOperation.created - lastUndoOp.created <= options.captureTimeout) {
|
||||||
console.log('appending', lastUndoOp, reverseOperation)
|
|
||||||
lastUndoOp.created = reverseOperation.created
|
lastUndoOp.created = reverseOperation.created
|
||||||
lastUndoOp.toState = reverseOperation.toState
|
lastUndoOp.toState = reverseOperation.toState
|
||||||
reverseOperation.deletedStructs.forEach(lastUndoOp.deletedStructs.add, lastUndoOp.deletedStructs)
|
reverseOperation.deletedStructs.forEach(lastUndoOp.deletedStructs.add, lastUndoOp.deletedStructs)
|
||||||
@@ -58,47 +92,15 @@ export default class UndoManager {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
undo () {
|
undo () {
|
||||||
console.log('undoing')
|
|
||||||
this._undoing = true
|
this._undoing = true
|
||||||
this._applyReverseOperation(this._undoBuffer)
|
const performedUndo = applyReverseOperation(this.y, this._scope, this._undoBuffer)
|
||||||
this._undoing = false
|
this._undoing = false
|
||||||
|
return performedUndo
|
||||||
}
|
}
|
||||||
redo () {
|
redo () {
|
||||||
this._redoing = true
|
this._redoing = true
|
||||||
this._applyReverseOperation(this._redoBuffer)
|
const performedRedo = applyReverseOperation(this.y, this._scope, this._redoBuffer)
|
||||||
this._redoing = false
|
this._redoing = false
|
||||||
}
|
return performedRedo
|
||||||
_applyReverseOperation (reverseBuffer) {
|
|
||||||
this.y.transact(() => {
|
|
||||||
let performedUndo = false
|
|
||||||
while (!performedUndo && reverseBuffer.length > 0) {
|
|
||||||
let undoOp = reverseBuffer.pop()
|
|
||||||
// make sure that it is possible to iterate {from}-{to}
|
|
||||||
this.y.os.getItemCleanStart(undoOp.fromState)
|
|
||||||
this.y.os.getItemCleanEnd(undoOp.toState)
|
|
||||||
this.y.os.iterate(undoOp.fromState, undoOp.toState, op => {
|
|
||||||
if (!op._deleted && isStructInScope(this.y, op, this._scope)) {
|
|
||||||
performedUndo = true
|
|
||||||
op._delete(this.y)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
for (let op of undoOp.deletedStructs) {
|
|
||||||
if (
|
|
||||||
isStructInScope(this.y, op, this._scope) &&
|
|
||||||
op._parent !== this.y &&
|
|
||||||
!op._parent._deleted &&
|
|
||||||
(
|
|
||||||
op._parent._id.user !== this.y.userID ||
|
|
||||||
op._parent._id.clock < undoOp.fromState.clock ||
|
|
||||||
op._parent._id.clock > undoOp.fromState.clock
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
performedUndo = true
|
|
||||||
op = op._copy(undoOp.deletedStructs)
|
|
||||||
op._integrate(this.y)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,15 +8,15 @@ export default class YEvent {
|
|||||||
const path = []
|
const path = []
|
||||||
let type = this.target
|
let type = this.target
|
||||||
const y = type._y
|
const y = type._y
|
||||||
while (type._parent !== this._currentTarget && type._parent !== y) {
|
while (type !== this.currentTarget && type !== y) {
|
||||||
let parent = type._parent
|
let parent = type._parent
|
||||||
if (type._parentSub !== null) {
|
if (type._parentSub !== null) {
|
||||||
path.push(type._parentSub)
|
path.unshift(type._parentSub)
|
||||||
} else {
|
} else {
|
||||||
// parent is array-ish
|
// parent is array-ish
|
||||||
for (let [i, child] of parent) {
|
for (let [i, child] of parent) {
|
||||||
if (child === type) {
|
if (child === type) {
|
||||||
path.push(i)
|
path.unshift(i)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -172,31 +172,36 @@ test('observePath properties', async function map10 (t) {
|
|||||||
})
|
})
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* TODO: reimplement observeDeep
|
|
||||||
test('observe deep properties', async function map11 (t) {
|
test('observe deep properties', async function map11 (t) {
|
||||||
let { users, map1, map2, map3 } = await initArrays(t, { users: 4 })
|
let { users, map1, map2, map3 } = await initArrays(t, { users: 4 })
|
||||||
var _map1 = map1.set('map', new Y.Map())
|
var _map1 = map1.set('map', new Y.Map())
|
||||||
var calls = 0
|
var calls = 0
|
||||||
var dmapid
|
var dmapid
|
||||||
_map1.observe(function (event) {
|
map1.observeDeep(function (events) {
|
||||||
calls++
|
events.forEach(event => {
|
||||||
t.compare(event.name, 'deepmap')
|
calls++
|
||||||
dmapid = event.target.opContents.deepmap
|
t.assert(event.keysChanged.has('deepmap'))
|
||||||
|
t.assert(event.path.length === 1)
|
||||||
|
t.assert(event.path[0] === 'map')
|
||||||
|
dmapid = event.target.get('deepmap')._id
|
||||||
|
})
|
||||||
})
|
})
|
||||||
await flushAll(t, users)
|
await flushAll(t, users)
|
||||||
|
await flushAll(t, users)
|
||||||
var _map3 = map3.get('map')
|
var _map3 = map3.get('map')
|
||||||
_map3.set('deepmap', new Y.Map())
|
_map3.set('deepmap', new Y.Map())
|
||||||
await flushAll(t, users)
|
await flushAll(t, users)
|
||||||
var _map2 = map2.get('map')
|
var _map2 = map2.get('map')
|
||||||
_map2.set('deepmap', new Y.Map())
|
_map2.set('deepmap', new Y.Map())
|
||||||
await flushAll(t, users)
|
await flushAll(t, users)
|
||||||
|
await flushAll(t, users)
|
||||||
var dmap1 = _map1.get('deepmap')
|
var dmap1 = _map1.get('deepmap')
|
||||||
var dmap2 = _map2.get('deepmap')
|
var dmap2 = _map2.get('deepmap')
|
||||||
var dmap3 = _map3.get('deepmap')
|
var dmap3 = _map3.get('deepmap')
|
||||||
t.assert(calls > 0)
|
t.assert(calls > 0)
|
||||||
t.compare(dmap1._model, dmap2._model)
|
t.assert(dmap1._id.equals(dmap2._id))
|
||||||
t.compare(dmap1._model, dmap3._model)
|
t.assert(dmap1._id.equals(dmap3._id))
|
||||||
t.compare(dmap1._model, dmapid)
|
t.assert(dmap1._id.equals(dmapid))
|
||||||
await compareUsers(t, users)
|
await compareUsers(t, users)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -204,8 +209,10 @@ test('observes using observeDeep', async function map12 (t) {
|
|||||||
let { users, map0 } = await initArrays(t, { users: 2 })
|
let { users, map0 } = await initArrays(t, { users: 2 })
|
||||||
var pathes = []
|
var pathes = []
|
||||||
var calls = 0
|
var calls = 0
|
||||||
map0.observeDeep(function (event) {
|
map0.observeDeep(function (events) {
|
||||||
pathes.push(event.path)
|
events.forEach(event => {
|
||||||
|
pathes.push(event.path)
|
||||||
|
})
|
||||||
calls++
|
calls++
|
||||||
})
|
})
|
||||||
map0.set('map', new Y.Map())
|
map0.set('map', new Y.Map())
|
||||||
@@ -215,7 +222,6 @@ test('observes using observeDeep', async function map12 (t) {
|
|||||||
t.compare(pathes, [[], ['map'], ['map', 'array']])
|
t.compare(pathes, [[], ['map'], ['map', 'array']])
|
||||||
await compareUsers(t, users)
|
await compareUsers(t, users)
|
||||||
})
|
})
|
||||||
*/
|
|
||||||
|
|
||||||
/* TODO: Test events in Y.Map
|
/* TODO: Test events in Y.Map
|
||||||
function compareEvent (t, is, should) {
|
function compareEvent (t, is, should) {
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ export async function flushAll (t, users) {
|
|||||||
if (users.length === 0) {
|
if (users.length === 0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
await wait(0)
|
await wait(10)
|
||||||
if (users[0].connector.testRoom != null) {
|
if (users[0].connector.testRoom != null) {
|
||||||
// use flushAll method specified in Test Connector
|
// use flushAll method specified in Test Connector
|
||||||
await users[0].connector.testRoom.flushAll(users)
|
await users[0].connector.testRoom.flushAll(users)
|
||||||
|
|||||||
198
y.node.js
198
y.node.js
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* yjs - A framework for real-time p2p shared editing on any data
|
* yjs - A framework for real-time p2p shared editing on any data
|
||||||
* @version v13.0.0-25
|
* @version v13.0.0-27
|
||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -687,7 +687,6 @@ if (!String.fromCodePoint) {
|
|||||||
/*! http://mths.be/codepointat v0.2.0 by @mathias */
|
/*! http://mths.be/codepointat v0.2.0 by @mathias */
|
||||||
if (!String.prototype.codePointAt) {
|
if (!String.prototype.codePointAt) {
|
||||||
(function() {
|
(function() {
|
||||||
'use strict'; // needed to support `apply`/`call` with `undefined`/`null`
|
|
||||||
var defineProperty = (function() {
|
var defineProperty = (function() {
|
||||||
// IE 8 only supports `Object.defineProperty` on DOM elements
|
// IE 8 only supports `Object.defineProperty` on DOM elements
|
||||||
try {
|
try {
|
||||||
@@ -2122,6 +2121,47 @@ class ItemJSON extends Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ItemString extends Item {
|
||||||
|
constructor () {
|
||||||
|
super();
|
||||||
|
this._content = null;
|
||||||
|
}
|
||||||
|
_copy () {
|
||||||
|
let struct = super._copy();
|
||||||
|
struct._content = this._content;
|
||||||
|
return struct
|
||||||
|
}
|
||||||
|
get _length () {
|
||||||
|
return this._content.length
|
||||||
|
}
|
||||||
|
_fromBinary (y, decoder) {
|
||||||
|
let missing = super._fromBinary(y, decoder);
|
||||||
|
this._content = decoder.readVarString();
|
||||||
|
return missing
|
||||||
|
}
|
||||||
|
_toBinary (encoder) {
|
||||||
|
super._toBinary(encoder);
|
||||||
|
encoder.writeVarString(this._content);
|
||||||
|
}
|
||||||
|
_logString () {
|
||||||
|
const left = this._left !== null ? this._left._lastId : null;
|
||||||
|
const origin = this._origin !== null ? this._origin._lastId : null;
|
||||||
|
return `ItemJSON(id:${logID(this._id)},content:${JSON.stringify(this._content)},left:${logID(left)},origin:${logID(origin)},right:${logID(this._right)},parent:${logID(this._parent)},parentSub:${this._parentSub})`
|
||||||
|
}
|
||||||
|
_splitAt (y, diff) {
|
||||||
|
if (diff === 0) {
|
||||||
|
return this
|
||||||
|
} else if (diff >= this._length) {
|
||||||
|
return this._right
|
||||||
|
}
|
||||||
|
let item = new ItemString();
|
||||||
|
item._content = this._content.slice(diff);
|
||||||
|
this._content = this._content.slice(0, diff);
|
||||||
|
splitHelper(y, this, item, diff);
|
||||||
|
return item
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class YEvent {
|
class YEvent {
|
||||||
constructor (target) {
|
constructor (target) {
|
||||||
this.target = target;
|
this.target = target;
|
||||||
@@ -2131,15 +2171,15 @@ class YEvent {
|
|||||||
const path = [];
|
const path = [];
|
||||||
let type = this.target;
|
let type = this.target;
|
||||||
const y = type._y;
|
const y = type._y;
|
||||||
while (type._parent !== this._currentTarget && type._parent !== y) {
|
while (type !== this.currentTarget && type !== y) {
|
||||||
let parent = type._parent;
|
let parent = type._parent;
|
||||||
if (type._parentSub !== null) {
|
if (type._parentSub !== null) {
|
||||||
path.push(type._parentSub);
|
path.unshift(type._parentSub);
|
||||||
} else {
|
} else {
|
||||||
// parent is array-ish
|
// parent is array-ish
|
||||||
for (let [i, child] of parent) {
|
for (let [i, child] of parent) {
|
||||||
if (child === type) {
|
if (child === type) {
|
||||||
path.push(i);
|
path.unshift(i);
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2166,7 +2206,11 @@ class YArray extends Type {
|
|||||||
while (n !== null) {
|
while (n !== null) {
|
||||||
if (!n._deleted) {
|
if (!n._deleted) {
|
||||||
if (pos < n._length) {
|
if (pos < n._length) {
|
||||||
return n._content[n._length - pos]
|
if (n.constructor === ItemJSON || n.constructor === ItemString) {
|
||||||
|
return n._content[pos]
|
||||||
|
} else {
|
||||||
|
return n
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pos -= n._length;
|
pos -= n._length;
|
||||||
}
|
}
|
||||||
@@ -2472,47 +2516,6 @@ class YMap extends Type {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ItemString extends Item {
|
|
||||||
constructor () {
|
|
||||||
super();
|
|
||||||
this._content = null;
|
|
||||||
}
|
|
||||||
_copy () {
|
|
||||||
let struct = super._copy();
|
|
||||||
struct._content = this._content;
|
|
||||||
return struct
|
|
||||||
}
|
|
||||||
get _length () {
|
|
||||||
return this._content.length
|
|
||||||
}
|
|
||||||
_fromBinary (y, decoder) {
|
|
||||||
let missing = super._fromBinary(y, decoder);
|
|
||||||
this._content = decoder.readVarString();
|
|
||||||
return missing
|
|
||||||
}
|
|
||||||
_toBinary (encoder) {
|
|
||||||
super._toBinary(encoder);
|
|
||||||
encoder.writeVarString(this._content);
|
|
||||||
}
|
|
||||||
_logString () {
|
|
||||||
const left = this._left !== null ? this._left._lastId : null;
|
|
||||||
const origin = this._origin !== null ? this._origin._lastId : null;
|
|
||||||
return `ItemJSON(id:${logID(this._id)},content:${JSON.stringify(this._content)},left:${logID(left)},origin:${logID(origin)},right:${logID(this._right)},parent:${logID(this._parent)},parentSub:${this._parentSub})`
|
|
||||||
}
|
|
||||||
_splitAt (y, diff) {
|
|
||||||
if (diff === 0) {
|
|
||||||
return this
|
|
||||||
} else if (diff >= this._length) {
|
|
||||||
return this._right
|
|
||||||
}
|
|
||||||
let item = new ItemString();
|
|
||||||
item._content = this._content.slice(diff);
|
|
||||||
this._content = this._content.slice(0, diff);
|
|
||||||
splitHelper(y, this, item, diff);
|
|
||||||
return item
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class YText extends YArray {
|
class YText extends YArray {
|
||||||
constructor (string) {
|
constructor (string) {
|
||||||
super();
|
super();
|
||||||
@@ -3982,7 +3985,7 @@ class YXmlFragment extends YArray {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
for (let dom of diffChildren) {
|
for (let dom of diffChildren) {
|
||||||
if (dom._yxml != null) {
|
if (dom._yxml != null && dom._yxml !== false) {
|
||||||
applyChangesFromDom(dom);
|
applyChangesFromDom(dom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4390,10 +4393,45 @@ function isStructInScope (y, struct, scope) {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function applyReverseOperation (y, scope, reverseBuffer) {
|
||||||
|
let performedUndo = false;
|
||||||
|
y.transact(() => {
|
||||||
|
while (!performedUndo && reverseBuffer.length > 0) {
|
||||||
|
let undoOp = reverseBuffer.pop();
|
||||||
|
// make sure that it is possible to iterate {from}-{to}
|
||||||
|
y.os.getItemCleanStart(undoOp.fromState);
|
||||||
|
y.os.getItemCleanEnd(undoOp.toState);
|
||||||
|
y.os.iterate(undoOp.fromState, undoOp.toState, op => {
|
||||||
|
if (!op._deleted && isStructInScope(y, op, scope)) {
|
||||||
|
performedUndo = true;
|
||||||
|
op._delete(y);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
for (let op of undoOp.deletedStructs) {
|
||||||
|
if (
|
||||||
|
isStructInScope(y, op, scope) &&
|
||||||
|
op._parent !== y &&
|
||||||
|
!op._parent._deleted &&
|
||||||
|
(
|
||||||
|
op._parent._id.user !== y.userID ||
|
||||||
|
op._parent._id.clock < undoOp.fromState.clock ||
|
||||||
|
op._parent._id.clock > undoOp.fromState.clock
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
performedUndo = true;
|
||||||
|
op = op._copy(undoOp.deletedStructs);
|
||||||
|
op._integrate(y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return performedUndo
|
||||||
|
}
|
||||||
|
|
||||||
class UndoManager {
|
class UndoManager {
|
||||||
constructor (scope, options = {}) {
|
constructor (scope, options = {}) {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
options.captureTimeout = options.captureTimeout || 0;
|
options.captureTimeout = options.captureTimeout == null ? 500 : options.captureTimeout;
|
||||||
this._undoBuffer = [];
|
this._undoBuffer = [];
|
||||||
this._redoBuffer = [];
|
this._redoBuffer = [];
|
||||||
this._scope = scope;
|
this._scope = scope;
|
||||||
@@ -4402,12 +4440,11 @@ class UndoManager {
|
|||||||
const y = scope._y;
|
const y = scope._y;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
y.on('afterTransaction', (y, remote) => {
|
y.on('afterTransaction', (y, remote) => {
|
||||||
if (!remote && (y._transaction.beforeState.has(y.userID) || y._transaction.deletedStructs.size > 0)) {
|
if (!remote && y._transaction.changedParentTypes.has(scope)) {
|
||||||
let reverseOperation = new ReverseOperation(y);
|
let reverseOperation = new ReverseOperation(y);
|
||||||
if (!this._undoing) {
|
if (!this._undoing) {
|
||||||
let lastUndoOp = this._undoBuffer.length > 0 ? this._undoBuffer[this._undoBuffer.length - 1] : null;
|
let lastUndoOp = this._undoBuffer.length > 0 ? this._undoBuffer[this._undoBuffer.length - 1] : null;
|
||||||
if (lastUndoOp !== null && lastUndoOp.created - reverseOperation.created <= options.captureTimeout) {
|
if (lastUndoOp !== null && reverseOperation.created - lastUndoOp.created <= options.captureTimeout) {
|
||||||
console.log('appending', lastUndoOp, reverseOperation);
|
|
||||||
lastUndoOp.created = reverseOperation.created;
|
lastUndoOp.created = reverseOperation.created;
|
||||||
lastUndoOp.toState = reverseOperation.toState;
|
lastUndoOp.toState = reverseOperation.toState;
|
||||||
reverseOperation.deletedStructs.forEach(lastUndoOp.deletedStructs.add, lastUndoOp.deletedStructs);
|
reverseOperation.deletedStructs.forEach(lastUndoOp.deletedStructs.add, lastUndoOp.deletedStructs);
|
||||||
@@ -4424,48 +4461,16 @@ class UndoManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
undo () {
|
undo () {
|
||||||
console.log('undoing');
|
|
||||||
this._undoing = true;
|
this._undoing = true;
|
||||||
this._applyReverseOperation(this._undoBuffer);
|
const performedUndo = applyReverseOperation(this.y, this._scope, this._undoBuffer);
|
||||||
this._undoing = false;
|
this._undoing = false;
|
||||||
|
return performedUndo
|
||||||
}
|
}
|
||||||
redo () {
|
redo () {
|
||||||
this._redoing = true;
|
this._redoing = true;
|
||||||
this._applyReverseOperation(this._redoBuffer);
|
const performedRedo = applyReverseOperation(this.y, this._scope, this._redoBuffer);
|
||||||
this._redoing = false;
|
this._redoing = false;
|
||||||
}
|
return performedRedo
|
||||||
_applyReverseOperation (reverseBuffer) {
|
|
||||||
this.y.transact(() => {
|
|
||||||
let performedUndo = false;
|
|
||||||
while (!performedUndo && reverseBuffer.length > 0) {
|
|
||||||
let undoOp = reverseBuffer.pop();
|
|
||||||
// make sure that it is possible to iterate {from}-{to}
|
|
||||||
this.y.os.getItemCleanStart(undoOp.fromState);
|
|
||||||
this.y.os.getItemCleanEnd(undoOp.toState);
|
|
||||||
this.y.os.iterate(undoOp.fromState, undoOp.toState, op => {
|
|
||||||
if (!op._deleted && isStructInScope(this.y, op, this._scope)) {
|
|
||||||
performedUndo = true;
|
|
||||||
op._delete(this.y);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
for (let op of undoOp.deletedStructs) {
|
|
||||||
if (
|
|
||||||
isStructInScope(this.y, op, this._scope) &&
|
|
||||||
op._parent !== this.y &&
|
|
||||||
!op._parent._deleted &&
|
|
||||||
(
|
|
||||||
op._parent._id.user !== this.y.userID ||
|
|
||||||
op._parent._id.clock < undoOp.fromState.clock ||
|
|
||||||
op._parent._id.clock > undoOp.fromState.clock
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
performedUndo = true;
|
|
||||||
op = op._copy(undoOp.deletedStructs);
|
|
||||||
op._integrate(this.y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4826,6 +4831,15 @@ function coerce(val) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var debug_1 = debug$1.coerce;
|
||||||
|
var debug_2 = debug$1.disable;
|
||||||
|
var debug_3 = debug$1.enable;
|
||||||
|
var debug_4 = debug$1.enabled;
|
||||||
|
var debug_5 = debug$1.humanize;
|
||||||
|
var debug_6 = debug$1.names;
|
||||||
|
var debug_7 = debug$1.skips;
|
||||||
|
var debug_8 = debug$1.formatters;
|
||||||
|
|
||||||
var browser = createCommonjsModule(function (module, exports) {
|
var browser = createCommonjsModule(function (module, exports) {
|
||||||
/**
|
/**
|
||||||
* This is the web browser implementation of `debug()`.
|
* This is the web browser implementation of `debug()`.
|
||||||
@@ -5014,6 +5028,14 @@ function localstorage() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var browser_1 = browser.log;
|
||||||
|
var browser_2 = browser.formatArgs;
|
||||||
|
var browser_3 = browser.save;
|
||||||
|
var browser_4 = browser.load;
|
||||||
|
var browser_5 = browser.useColors;
|
||||||
|
var browser_6 = browser.storage;
|
||||||
|
var browser_7 = browser.colors;
|
||||||
|
|
||||||
class AbstractConnector {
|
class AbstractConnector {
|
||||||
constructor (y, opts) {
|
constructor (y, opts) {
|
||||||
this.y = y;
|
this.y = y;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user