|
|
@ -28,13 +28,16 @@ define([
|
|
|
|
toolbar;
|
|
|
|
toolbar;
|
|
|
|
|
|
|
|
|
|
|
|
var module = window.REALTIME_MODULE = {
|
|
|
|
var module = window.REALTIME_MODULE = {
|
|
|
|
localChangeInProgress: 0
|
|
|
|
localChangeInProgress: 0,
|
|
|
|
|
|
|
|
Hyperjson: Hyperjson,
|
|
|
|
|
|
|
|
Hyperscript: Hyperscript
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var isNotMagicLine = function (el) {
|
|
|
|
var isNotMagicLine = function (el) {
|
|
|
|
// factor as:
|
|
|
|
// factor as:
|
|
|
|
// return !(el.tagName === 'SPAN' && el.contentEditable === 'false');
|
|
|
|
// return !(el.tagName === 'SPAN' && el.contentEditable === 'false');
|
|
|
|
var filter = (el.tagName === 'SPAN' && el.contentEditable === 'false');
|
|
|
|
var filter = (el.tagName === 'SPAN' &&
|
|
|
|
|
|
|
|
el.getAttribute('contentEditable') === 'false');
|
|
|
|
if (filter) {
|
|
|
|
if (filter) {
|
|
|
|
console.log("[hyperjson.serializer] prevented an element" +
|
|
|
|
console.log("[hyperjson.serializer] prevented an element" +
|
|
|
|
"from being serialized:", el);
|
|
|
|
"from being serialized:", el);
|
|
|
@ -95,7 +98,7 @@ define([
|
|
|
|
we should check when such an element is going to be
|
|
|
|
we should check when such an element is going to be
|
|
|
|
removed, and prevent that from happening. */
|
|
|
|
removed, and prevent that from happening. */
|
|
|
|
if (info.node && info.node.tagName === 'SPAN' &&
|
|
|
|
if (info.node && info.node.tagName === 'SPAN' &&
|
|
|
|
info.node.contentEditable === "true") {
|
|
|
|
info.node.getAttribute('contentEditable') === "false") {
|
|
|
|
// it seems to be a magicline plugin element...
|
|
|
|
// it seems to be a magicline plugin element...
|
|
|
|
if (info.diff.action === 'removeElement') {
|
|
|
|
if (info.diff.action === 'removeElement') {
|
|
|
|
// and you're about to remove it...
|
|
|
|
// and you're about to remove it...
|
|
|
@ -163,7 +166,8 @@ define([
|
|
|
|
doc: inner,
|
|
|
|
doc: inner,
|
|
|
|
|
|
|
|
|
|
|
|
// provide initialstate...
|
|
|
|
// provide initialstate...
|
|
|
|
initialState: JSON.stringify(Hyperjson.fromDOM(inner, isNotMagicLine)),
|
|
|
|
initialState: JSON.stringify(Hyperjson
|
|
|
|
|
|
|
|
.fromDOM(inner, isNotMagicLine)) || '{}',
|
|
|
|
|
|
|
|
|
|
|
|
// really basic operational transform
|
|
|
|
// really basic operational transform
|
|
|
|
// reject patch if it results in invalid JSON
|
|
|
|
// reject patch if it results in invalid JSON
|
|
|
@ -186,8 +190,7 @@ define([
|
|
|
|
var localWorkInProgress = function (stage) {
|
|
|
|
var localWorkInProgress = function (stage) {
|
|
|
|
if (module.localChangeInProgress) {
|
|
|
|
if (module.localChangeInProgress) {
|
|
|
|
console.error("Applied a change while a local patch was in progress");
|
|
|
|
console.error("Applied a change while a local patch was in progress");
|
|
|
|
alert("local work was interrupted at stage: " + stage);
|
|
|
|
console.error("local work was interrupted at stage: " + stage);
|
|
|
|
//module.realtimeInput.onLocal();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
@ -200,6 +203,21 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
var userDocStateDom = hjsonToDom(JSON.parse(shjson));
|
|
|
|
var userDocStateDom = hjsonToDom(JSON.parse(shjson));
|
|
|
|
localWorkInProgress(2); // check again
|
|
|
|
localWorkInProgress(2); // check again
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* in the DOM contentEditable is "false"
|
|
|
|
|
|
|
|
while "contenteditable" is undefined.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
When it goes over the wire, it seems hyperjson transforms it.
|
|
|
|
|
|
|
|
of course, hyperjson simply gets attributes from the DOM.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
el.attributes returns 'contenteditable', so we have to correct for that
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
There are quite possibly all sorts of other attributes which might lose
|
|
|
|
|
|
|
|
information, and we won't know what they are until after we've lost them.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this comes from hyperscript line 101. FIXME maybe
|
|
|
|
|
|
|
|
*/
|
|
|
|
userDocStateDom.setAttribute("contenteditable", "true"); // lol wtf
|
|
|
|
userDocStateDom.setAttribute("contenteditable", "true"); // lol wtf
|
|
|
|
localWorkInProgress(3); // check again
|
|
|
|
localWorkInProgress(3); // check again
|
|
|
|
var patch = (DD).diff(inner, userDocStateDom);
|
|
|
|
var patch = (DD).diff(inner, userDocStateDom);
|
|
|
|