diff --git a/package-lock.json b/package-lock.json index 348ec562..489244d5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "yjs", - "version": "13.0.0-25", + "version": "13.0.0-26", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -2808,14 +2808,6 @@ } } }, - "string_decoder": { - "version": "1.0.1", - "bundled": true, - "dev": true, - "requires": { - "safe-buffer": "5.0.1" - } - }, "string-width": { "version": "1.0.2", "bundled": true, @@ -2826,6 +2818,14 @@ "strip-ansi": "3.0.1" } }, + "string_decoder": { + "version": "1.0.1", + "bundled": true, + "dev": true, + "requires": { + "safe-buffer": "5.0.1" + } + }, "stringstream": { "version": "0.0.5", "bundled": true, @@ -4868,15 +4868,6 @@ "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": { "version": "1.0.2", "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", "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": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", diff --git a/rollup.test.js b/rollup.test.js index c74129e6..db02778f 100644 --- a/rollup.test.js +++ b/rollup.test.js @@ -3,7 +3,7 @@ import commonjs from 'rollup-plugin-commonjs' import multiEntry from 'rollup-plugin-multi-entry' export default { - entry: 'test/y-xml.tests.js', + entry: 'test/y-map.tests.js', moduleName: 'y-tests', format: 'umd', plugins: [ diff --git a/src/Type/YArray.js b/src/Type/YArray.js index 543969ba..d277327f 100644 --- a/src/Type/YArray.js +++ b/src/Type/YArray.js @@ -1,5 +1,6 @@ import Type from '../Struct/Type.js' import ItemJSON from '../Struct/ItemJSON.js' +import ItemString from '../Struct/ItemString.js' import { logID } from '../MessageHandler/messageToString.js' import YEvent from '../Util/YEvent.js' @@ -19,7 +20,11 @@ export default class YArray extends Type { while (n !== null) { if (!n._deleted) { 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 } diff --git a/src/Type/y-xml/YXmlFragment.js b/src/Type/y-xml/YXmlFragment.js index 96dbaf79..dfe0873d 100644 --- a/src/Type/y-xml/YXmlFragment.js +++ b/src/Type/y-xml/YXmlFragment.js @@ -255,7 +255,7 @@ export default class YXmlFragment extends YArray { } }) for (let dom of diffChildren) { - if (dom._yxml != null) { + if (dom._yxml != null && dom._yxml !== false) { applyChangesFromDom(dom) } } diff --git a/src/Util/UndoManager.js b/src/Util/UndoManager.js index 4e2a5190..6efc76ea 100644 --- a/src/Util/UndoManager.js +++ b/src/Util/UndoManager.js @@ -76,7 +76,6 @@ export default class UndoManager { if (!this._undoing) { let lastUndoOp = this._undoBuffer.length > 0 ? this._undoBuffer[this._undoBuffer.length - 1] : null if (lastUndoOp !== null && reverseOperation.created - lastUndoOp.created <= options.captureTimeout) { - console.log('appending', lastUndoOp, reverseOperation) lastUndoOp.created = reverseOperation.created lastUndoOp.toState = reverseOperation.toState reverseOperation.deletedStructs.forEach(lastUndoOp.deletedStructs.add, lastUndoOp.deletedStructs) @@ -93,7 +92,6 @@ export default class UndoManager { }) } undo () { - console.log('undoing') this._undoing = true const performedUndo = applyReverseOperation(this.y, this._scope, this._undoBuffer) this._undoing = false diff --git a/src/Util/YEvent.js b/src/Util/YEvent.js index cf37bf35..aed8c4e8 100644 --- a/src/Util/YEvent.js +++ b/src/Util/YEvent.js @@ -8,15 +8,15 @@ export default class YEvent { const path = [] let type = this.target const y = type._y - while (type._parent !== this._currentTarget && type._parent !== y) { + while (type !== this.currentTarget && type !== y) { let parent = type._parent if (type._parentSub !== null) { - path.push(type._parentSub) + path.unshift(type._parentSub) } else { // parent is array-ish for (let [i, child] of parent) { if (child === type) { - path.push(i) + path.unshift(i) break } } diff --git a/test/y-map.tests.js b/test/y-map.tests.js index 896a77fc..36b0983c 100644 --- a/test/y-map.tests.js +++ b/test/y-map.tests.js @@ -172,31 +172,36 @@ test('observePath properties', async function map10 (t) { }) */ -/* TODO: reimplement observeDeep test('observe deep properties', async function map11 (t) { let { users, map1, map2, map3 } = await initArrays(t, { users: 4 }) var _map1 = map1.set('map', new Y.Map()) var calls = 0 var dmapid - _map1.observe(function (event) { - calls++ - t.compare(event.name, 'deepmap') - dmapid = event.target.opContents.deepmap + map1.observeDeep(function (events) { + events.forEach(event => { + calls++ + 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) var _map3 = map3.get('map') _map3.set('deepmap', new Y.Map()) await flushAll(t, users) var _map2 = map2.get('map') _map2.set('deepmap', new Y.Map()) await flushAll(t, users) + await flushAll(t, users) var dmap1 = _map1.get('deepmap') var dmap2 = _map2.get('deepmap') var dmap3 = _map3.get('deepmap') t.assert(calls > 0) - t.compare(dmap1._model, dmap2._model) - t.compare(dmap1._model, dmap3._model) - t.compare(dmap1._model, dmapid) + t.assert(dmap1._id.equals(dmap2._id)) + t.assert(dmap1._id.equals(dmap3._id)) + t.assert(dmap1._id.equals(dmapid)) await compareUsers(t, users) }) @@ -204,8 +209,10 @@ test('observes using observeDeep', async function map12 (t) { let { users, map0 } = await initArrays(t, { users: 2 }) var pathes = [] var calls = 0 - map0.observeDeep(function (event) { - pathes.push(event.path) + map0.observeDeep(function (events) { + events.forEach(event => { + pathes.push(event.path) + }) calls++ }) map0.set('map', new Y.Map()) @@ -215,7 +222,6 @@ test('observes using observeDeep', async function map12 (t) { t.compare(pathes, [[], ['map'], ['map', 'array']]) await compareUsers(t, users) }) -*/ /* TODO: Test events in Y.Map function compareEvent (t, is, should) { diff --git a/tests-lib/helper.js b/tests-lib/helper.js index de6dc92a..ec7284cb 100644 --- a/tests-lib/helper.js +++ b/tests-lib/helper.js @@ -187,7 +187,7 @@ export async function flushAll (t, users) { if (users.length === 0) { return } - await wait(0) + await wait(10) if (users[0].connector.testRoom != null) { // use flushAll method specified in Test Connector await users[0].connector.testRoom.flushAll(users)