Merge branch 'diffdom' of github.com:xwiki-labs/cryptpad into demoEffect
This commit is contained in:
commit
7f92abc7bf
4 changed files with 30 additions and 25 deletions
|
@ -25,6 +25,7 @@
|
|||
"ckeditor": "~4.5.6",
|
||||
"requirejs": "~2.1.15",
|
||||
"modalBox": "~1.0.2",
|
||||
"reconnectingWebsocket": ""
|
||||
"reconnectingWebsocket": "",
|
||||
"diff-dom": "~2.0.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,14 @@ var nThen = require('nthen');
|
|||
|
||||
var getIndex = function(db, cName, cb) {
|
||||
db.get(cName+'=>index', function(e, out){
|
||||
if (e) { throw e; }
|
||||
if (e) {
|
||||
if (e.notFound) {
|
||||
cb(-1);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
return;
|
||||
}
|
||||
cb(parseInt(out));
|
||||
});
|
||||
};
|
||||
|
@ -11,11 +18,11 @@ var getIndex = function(db, cName, cb) {
|
|||
var insert = function (db, channelName, content, cb) {
|
||||
var index;
|
||||
nThen(function (waitFor) {
|
||||
getIndex(db, channelName, waitFor(function (i) { index = i; }));
|
||||
}).nThen(function (waitFor) {
|
||||
db.put(channelName+'=>index', ''+index, waitFor(function (e) { if (e) { throw e; } }));
|
||||
getIndex(db, channelName, waitFor(function (i) { index = i+1; }));
|
||||
}).nThen(function (waitFor) {
|
||||
db.put(channelName+'=>'+index, content, waitFor(function (e) { if (e) { throw e; } }));
|
||||
}).nThen(function (waitFor) {
|
||||
db.put(channelName+'=>index', ''+index, waitFor(function (e) { if (e) { throw e; } }));
|
||||
}).nThen(cb);
|
||||
};
|
||||
|
||||
|
|
|
@ -230,8 +230,8 @@ define([
|
|||
//verbose("Received own message");
|
||||
} else {
|
||||
//verbose("Received remote message");
|
||||
// obviously this is only going to get called if
|
||||
onRemote && onRemote(realtime.getAuthDoc());
|
||||
// obviously this is only going to get called if
|
||||
onRemote && onRemote(realtime.getUserDoc());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -290,7 +290,7 @@ define([
|
|||
});
|
||||
return {
|
||||
onEvent: function () {
|
||||
onEvent();
|
||||
onEvent();
|
||||
},
|
||||
bumpSharejs: function () { bump(); }
|
||||
};
|
||||
|
|
|
@ -6,12 +6,15 @@ define([
|
|||
'/common/convert.js',
|
||||
'/common/toolbar.js',
|
||||
'/common/cursor.js',
|
||||
'/bower_components/diff-dom/diffDOM.js',
|
||||
|
||||
'/bower_components/jquery/dist/jquery.min.js',
|
||||
'/customize/pad.js'
|
||||
], function (Config, Messages, Crypto, realtimeInput, Convert, Toolbar, Cursor) {
|
||||
var $ = window.jQuery;
|
||||
var ifrw = $('#pad-iframe')[0].contentWindow;
|
||||
window.Ckeditor = ifrw.CKEDITOR;
|
||||
var DiffDom = window.diffDOM;
|
||||
|
||||
var userName = Crypto.rand64(8),
|
||||
toolbar;
|
||||
|
@ -59,28 +62,22 @@ define([
|
|||
|
||||
var applyHjson = function (shjson) {
|
||||
console.log("Applying HJSON");
|
||||
// before integrating external changes, check in your own
|
||||
vdom1 = Convert.dom.to.vdom(inner);
|
||||
// the authoritative document is hyperjson, parse it
|
||||
var authDoc = JSON.parse(shjson);
|
||||
// use the authdoc to construct a second vdom
|
||||
var vdom2 = Convert.hjson.to.vdom(authDoc);
|
||||
// diff it against your version
|
||||
var patches = Vdom.diff(vdom1, vdom2);
|
||||
// apply the resulting patches
|
||||
Vdom.patch(inner, patches);
|
||||
var userDocStateDom = Vdom.create(Convert.hjson.to.vdom(JSON.parse(shjson)));
|
||||
userDocStateDom.setAttribute("contentEditable", "true"); // lol wtf
|
||||
var patch = (new DiffDom()).diff(inner, userDocStateDom);
|
||||
(new DiffDom()).apply(inner, patch);
|
||||
};
|
||||
|
||||
var onRemote = function (shjson) {
|
||||
// remember where the cursor is
|
||||
cursor.update()
|
||||
//cursor.update()
|
||||
|
||||
applyHjson(shjson);
|
||||
|
||||
cursor.find();
|
||||
//cursor.find();
|
||||
|
||||
// put the cursor back where you left it
|
||||
cursor.replace();
|
||||
//cursor.replace();
|
||||
};
|
||||
|
||||
var onInit = function (info) {
|
||||
|
@ -104,7 +101,7 @@ define([
|
|||
onInit: onInit,
|
||||
|
||||
transformFunction : function (text, toTransform, transformBy) {
|
||||
/* FIXME
|
||||
/* FIXME
|
||||
operational transform on json shouldn't be in all editors
|
||||
just those transmitting/expecting JSON
|
||||
*/
|
||||
|
@ -141,14 +138,14 @@ define([
|
|||
|
||||
$textarea.val(JSON.stringify(hjson));
|
||||
rti.bumpSharejs();
|
||||
cursor.update()
|
||||
//cursor.update()
|
||||
});
|
||||
|
||||
['mouseup', 'keyup'].forEach(function (type) {
|
||||
/*['mouseup', 'keyup'].forEach(function (type) {
|
||||
editor.document.on(type, function (e) {
|
||||
cursor.update();
|
||||
});
|
||||
});
|
||||
});*/
|
||||
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue