Compare commits

..

3 Commits

Author SHA1 Message Date
Kevin Jahns
4f670a3b5e v13.0.0-40 -- distribution files 2017-12-05 21:50:47 -08:00
Kevin Jahns
4efa16e2dd 13.0.0-40 2017-12-05 21:50:34 -08:00
Kevin Jahns
ad44f59def implement new dom update algorithm 2017-12-05 21:50:00 -08:00
9 changed files with 47 additions and 37 deletions

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "yjs",
"version": "13.0.0-39",
"version": "13.0.0-40",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@@ -1,6 +1,6 @@
{
"name": "yjs",
"version": "13.0.0-39",
"version": "13.0.0-40",
"description": "A framework for real-time p2p shared editing on any data",
"main": "./y.node.js",
"browser": "./y.js",

View File

@@ -254,9 +254,7 @@ export default class YXmlFragment extends YArray {
})
// Apply Y.Xml events to dom
this.observeDeep(events => {
this._mutualExclude(() => {
reflectChangesOnDom.call(this, events, _document)
})
reflectChangesOnDom.call(this, events, _document)
})
// Apply Dom changes on Y.Xml
if (typeof MutationObserver !== 'undefined') {

View File

@@ -68,7 +68,6 @@ export function afterTransactionSelectionFixer (y, transaction, remote) {
}
}
if (shouldUpdate) {
console.info('updating selection!!')
browserSelection.setBaseAndExtent(
anchorNode,
anchorOffset,

View File

@@ -193,19 +193,27 @@ export function reflectChangesOnDom (events, _document) {
* only in the attributes (above)
*/
if (event.childListChanged && yxml.constructor !== YXmlHook) {
// create fragment of undeleted nodes
const fragment = _document.createDocumentFragment()
let currentChild = dom.firstChild
yxml.forEach(function (t) {
fragment.appendChild(t.getDom(_document))
let expectedChild = t.getDom(_document)
if (expectedChild.parentNode === dom) {
// is already attached to the dom. Look for it
while (currentChild !== expectedChild) {
let del = currentChild
currentChild = currentChild.nextSibling
dom.removeChild(del)
}
currentChild = currentChild.nextSibling
} else {
// this dom is not yet attached to dom
dom.insertBefore(expectedChild, currentChild)
}
})
// remove remainding nodes
let lastChild = dom.lastChild
while (lastChild !== null) {
dom.removeChild(lastChild)
lastChild = dom.lastChild
while (currentChild !== null) {
let tmp = currentChild.nextSibling
dom.removeChild(currentChild)
currentChild = tmp
}
// insert fragment of undeleted nodes
dom.appendChild(fragment)
}
}
/* TODO: smartscrolling

8
y.js

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +1,7 @@
/**
* yjs - A framework for real-time p2p shared editing on any data
* @version v13.0.0-39
* @version v13.0.0-40
* @license MIT
*/
@@ -2745,19 +2745,27 @@ function reflectChangesOnDom (events, _document) {
* only in the attributes (above)
*/
if (event.childListChanged && yxml.constructor !== YXmlHook) {
// create fragment of undeleted nodes
const fragment = _document.createDocumentFragment();
let currentChild = dom.firstChild;
yxml.forEach(function (t) {
fragment.appendChild(t.getDom(_document));
let expectedChild = t.getDom(_document);
if (expectedChild.parentNode === dom) {
// is already attached to the dom. Look for it
while (currentChild !== expectedChild) {
let del = currentChild;
currentChild = currentChild.nextSibling;
dom.removeChild(del);
}
currentChild = currentChild.nextSibling;
} else {
// this dom is not yet attached to dom
dom.insertBefore(expectedChild, currentChild);
}
});
// remove remainding nodes
let lastChild = dom.lastChild;
while (lastChild !== null) {
dom.removeChild(lastChild);
lastChild = dom.lastChild;
while (currentChild !== null) {
let tmp = currentChild.nextSibling;
dom.removeChild(currentChild);
currentChild = tmp;
}
// insert fragment of undeleted nodes
dom.appendChild(fragment);
}
}
/* TODO: smartscrolling
@@ -2939,7 +2947,6 @@ function afterTransactionSelectionFixer (y, transaction, remote) {
}
}
if (shouldUpdate) {
console.info('updating selection!!');
browserSelection.setBaseAndExtent(
anchorNode,
anchorOffset,
@@ -3951,9 +3958,7 @@ class YXmlFragment extends YArray {
});
// Apply Y.Xml events to dom
this.observeDeep(events => {
this._mutualExclude(() => {
reflectChangesOnDom.call(this, events, _document);
});
reflectChangesOnDom.call(this, events, _document);
});
// Apply Dom changes on Y.Xml
if (typeof MutationObserver !== 'undefined') {

File diff suppressed because one or more lines are too long