Compare commits

..

7 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
Kevin Jahns
9c471ea24d 13.0.0-39 2017-12-05 17:06:01 -08:00
Kevin Jahns
d9e76014f5 fix remaining cursor relocation issues 2017-12-05 17:05:12 -08:00
Kevin Jahns
4091b7d004 13.0.0-38 2017-12-05 00:53:25 -08:00
Kevin Jahns
dfc183643d support data-yjs-hook attribute for yjs hooks 2017-12-05 00:52:52 -08:00
9 changed files with 47 additions and 39 deletions

2
package-lock.json generated
View File

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

View File

@@ -1,6 +1,6 @@
{ {
"name": "yjs", "name": "yjs",
"version": "13.0.0-37", "version": "13.0.0-40",
"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",

View File

@@ -17,7 +17,7 @@ function domToYXml (parent, doms, _document) {
} }
if (parent._domFilter(d.nodeName, new Map()) !== null) { if (parent._domFilter(d.nodeName, new Map()) !== null) {
let type let type
const hookName = d._yjsHook const hookName = d._yjsHook || (d.dataset != null ? d.dataset.yjsHook : undefined)
if (hookName !== undefined) { if (hookName !== undefined) {
type = new YXmlHook(hookName, d) type = new YXmlHook(hookName, d)
} else if (d.nodeType === d.TEXT_NODE) { } else if (d.nodeType === d.TEXT_NODE) {

View File

@@ -68,7 +68,6 @@ export function afterTransactionSelectionFixer (y, transaction, remote) {
} }
} }
if (shouldUpdate) { if (shouldUpdate) {
console.info('updating selection!!')
browserSelection.setBaseAndExtent( browserSelection.setBaseAndExtent(
anchorNode, anchorNode,
anchorOffset, anchorOffset,
@@ -76,7 +75,4 @@ export function afterTransactionSelectionFixer (y, transaction, remote) {
focusOffset focusOffset
) )
} }
// delete, so the objects can be gc'd
relativeSelection = null
browserSelection = null
} }

View File

@@ -193,19 +193,27 @@ export function reflectChangesOnDom (events, _document) {
* only in the attributes (above) * only in the attributes (above)
*/ */
if (event.childListChanged && yxml.constructor !== YXmlHook) { if (event.childListChanged && yxml.constructor !== YXmlHook) {
// create fragment of undeleted nodes let currentChild = dom.firstChild
const fragment = _document.createDocumentFragment()
yxml.forEach(function (t) { 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 while (currentChild !== null) {
let lastChild = dom.lastChild let tmp = currentChild.nextSibling
while (lastChild !== null) { dom.removeChild(currentChild)
dom.removeChild(lastChild) currentChild = tmp
lastChild = dom.lastChild
} }
// insert fragment of undeleted nodes
dom.appendChild(fragment)
} }
} }
/* TODO: smartscrolling /* 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 * yjs - A framework for real-time p2p shared editing on any data
* @version v13.0.0-37 * @version v13.0.0-40
* @license MIT * @license MIT
*/ */
@@ -2745,19 +2745,27 @@ function reflectChangesOnDom (events, _document) {
* only in the attributes (above) * only in the attributes (above)
*/ */
if (event.childListChanged && yxml.constructor !== YXmlHook) { if (event.childListChanged && yxml.constructor !== YXmlHook) {
// create fragment of undeleted nodes let currentChild = dom.firstChild;
const fragment = _document.createDocumentFragment();
yxml.forEach(function (t) { 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 while (currentChild !== null) {
let lastChild = dom.lastChild; let tmp = currentChild.nextSibling;
while (lastChild !== null) { dom.removeChild(currentChild);
dom.removeChild(lastChild); currentChild = tmp;
lastChild = dom.lastChild;
} }
// insert fragment of undeleted nodes
dom.appendChild(fragment);
} }
} }
/* TODO: smartscrolling /* TODO: smartscrolling
@@ -2939,7 +2947,6 @@ function afterTransactionSelectionFixer (y, transaction, remote) {
} }
} }
if (shouldUpdate) { if (shouldUpdate) {
console.info('updating selection!!');
browserSelection.setBaseAndExtent( browserSelection.setBaseAndExtent(
anchorNode, anchorNode,
anchorOffset, anchorOffset,
@@ -2947,9 +2954,6 @@ function afterTransactionSelectionFixer (y, transaction, remote) {
focusOffset focusOffset
); );
} }
// delete, so the objects can be gc'd
relativeSelection = null;
browserSelection = null;
} }
class YXmlEvent extends YEvent { class YXmlEvent extends YEvent {
@@ -3717,7 +3721,7 @@ function domToYXml (parent, doms, _document) {
} }
if (parent._domFilter(d.nodeName, new Map()) !== null) { if (parent._domFilter(d.nodeName, new Map()) !== null) {
let type; let type;
const hookName = d._yjsHook; const hookName = d._yjsHook || (d.dataset != null ? d.dataset.yjsHook : undefined);
if (hookName !== undefined) { if (hookName !== undefined) {
type = new YXmlHook(hookName, d); type = new YXmlHook(hookName, d);
} else if (d.nodeType === d.TEXT_NODE) { } else if (d.nodeType === d.TEXT_NODE) {

File diff suppressed because one or more lines are too long