insertBefore (xml), and prevent bug for addProperty-listener

This commit is contained in:
Kevin Jahns
2014-09-29 09:58:44 +02:00
parent 98b1a8f660
commit 03d652f70b
66 changed files with 32695 additions and 382 deletions

View File

@@ -0,0 +1 @@
!function t(n,e,r){function i(u,a){if(!e[u]){if(!n[u]){var s="function"==typeof require&&require;if(!a&&s)return s(u,!0);if(o)return o(u,!0);throw new Error("Cannot find module '"+u+"'")}var c=e[u]={exports:{}};n[u][0].call(c.exports,function(t){var e=n[u][1][t];return i(e?e:t)},c,c.exports,t,n,e,r)}return e[u].exports}for(var o="function"==typeof require&&require,u=0;u<r.length;u++)i(r[u]);return i}({1:[function(t,n){var e;e=function(t,n){var e,r,i,o,u,a;return a=null,null!=n&&(a=n.iwcHandler),o={},r=new DUIClient,r.connect(function(t){var n;return null!=(n=o[t.action])&&n.map(function(n){return setTimeout(function(){return n(t)},0)}),null!=a?a(t):void 0}),r.initOK(),u=null,e=function(){function t(t,n,e,i){var a,s,c,l;this.engine=t,this.HB=n,this.execution_listener=e,this.yatta=i,this.duiClient=r,this.iwcHandler=o,l=function(t){return function(n){return 0!==Object.getOwnPropertyNames(t.initialized).length?t.send(n):void 0}}(this),this.execution_listener.push(l),this.initialized={},a=function(t){return function(e){var r;return n=e.extras.HB,r=e.extras.user,t.engine.applyOpsCheckDouble(n),t.initialized[r]=!0}}(this),o.Yatta_push_HB_element=[a],this.sendIwcIntent("Yatta_get_HB_element",this.HB.getOperationCounter()),s=function(t){return function(n){var e;return e=n.extras,null!=t.initialized[e.uid.creator]?t.receive(e):void 0}}(this),this.iwcHandler.Yatta_new_operation=[s],null!=u&&this.engine.applyOpsCheckDouble(u),c=function(t){return function(n){var e,r;return r=n.extras,console.log(r),e={HB:t.yatta.getHistoryBuffer()._encode(r),user:t.yatta.getUserId()},t.sendIwcIntent("Yatta_push_HB_element",e)}}(this),this.iwcHandler.Yatta_get_HB_element=[c]}return t.prototype.setIwcHandler=function(t){return a=t},t.prototype.sendIwcIntent=function(t,n){var e;return e=null,arguments.length>=2?(t=arguments[0],n=arguments[1],e={action:t,component:"",data:"",dataType:"",flags:["PUBLISH_GLOBAL"],extras:n}):e=arguments[0],this.duiClient.sendIntent(e)},t.prototype.send=function(t){return t.uid.creator===this.HB.getUserId()&&"string"!=typeof t.uid.op_number?this.sendIwcIntent("Yatta_new_operation",t):void 0},t.prototype.receive=function(t){return t.uid.creator!==this.HB.getUserId()?this.engine.applyOp(t):void 0},t}(),i=function(){var n;return n=Math.floor(1e6*Math.random()),t(e,n)},setTimeout(i,5e3),void 0},n.exports=e,"undefined"!=typeof window&&null!==window&&(null==window.Y&&(window.Y={}),window.Y.createIwcConnector=e)},{}]},{},[1]);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -28,7 +28,7 @@
send_ = (function(_this) {
return function(o) {
var conn, conn_id, _ref, _results;
if (o.creator === _this.HB.getUserId() && (typeof o.uid.op_number !== "string") && o.uid.sync) {
if (o.uid.creator === _this.HB.getUserId() && (typeof o.uid.op_number !== "string")) {
_ref = _this.connections;
_results = [];
for (conn_id in _ref) {
@@ -71,7 +71,7 @@
} else if (data.HB != null) {
initialized_me = true;
_this.engine.applyOpsCheckDouble(data.HB, data.state_vector);
_this.engine.applyOpsCheckDouble(data.HB);
return conn.send({
conns: _this.getAllConnectionIds()
});
@@ -88,8 +88,7 @@
} else if (data.state_vector != null) {
if (!initialized_him) {
conn.send({
HB: _this.yatta.getHistoryBuffer()._encode(data.state_vector),
state_vector: _this.yatta.HB.getOperationCounter()
HB: _this.yatta.getHistoryBuffer()._encode(data.state_vector)
});
return initialized_him = true;
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,85 @@
(function() {
var Engine, HistoryBuffer, XmlFramework, json_types_uninitialized;
json_types_uninitialized = require("../Types/XmlTypes");
HistoryBuffer = require("../HistoryBuffer");
Engine = require("../Engine");
XmlFramework = (function() {
function XmlFramework(user_id, Connector) {
var beg, end, type_manager, uid_beg, uid_end;
this.HB = new HistoryBuffer(user_id);
type_manager = json_types_uninitialized(this.HB);
this.types = type_manager.types;
this.engine = new Engine(this.HB, type_manager.parser);
this.HB.engine = this.engine;
this.connector = new Connector(this.engine, this.HB, type_manager.execution_listener, this);
uid_beg = this.HB.getReservedUniqueIdentifier();
uid_end = this.HB.getReservedUniqueIdentifier();
beg = this.HB.addOperation(new this.types.Delimiter(uid_beg, void 0, uid_end)).execute();
end = this.HB.addOperation(new this.types.Delimiter(uid_end, beg, void 0)).execute();
this.root_element = new this.types.ReplaceManager(void 0, this.HB.getReservedUniqueIdentifier(), beg, end);
this.HB.addOperation(this.root_element).execute();
}
XmlFramework.prototype.getSharedObject = function() {
return this.root_element.val();
};
XmlFramework.prototype.getConnector = function() {
return this.connector;
};
XmlFramework.prototype.getHistoryBuffer = function() {
return this.HB;
};
XmlFramework.prototype.setMutableDefault = function(mutable) {
return this.getSharedObject().setMutableDefault(mutable);
};
XmlFramework.prototype.getUserId = function() {
return this.HB.getUserId();
};
XmlFramework.prototype.toJson = function() {
return this.getSharedObject().toJson();
};
XmlFramework.prototype.val = function() {
var newXml;
if ((arguments.length === 0) || (typeof arguments[0] === "boolean")) {
return this.getSharedObject().val(arguments[0]);
} else if (arguments.length === 1) {
newXml = new this.types.XmlType(void 0, void 0, void 0, void 0, arguments[0]);
this.HB.addOperation(newXml).execute();
this.root_element.replace(newXml);
return newXml;
} else {
throw new Error("can only parse 0, or 1 parameter!");
}
};
XmlFramework.prototype.on = function() {
var _ref;
return (_ref = this.getSharedObject()).on.apply(_ref, arguments);
};
return XmlFramework;
})();
module.exports = XmlFramework;
if (typeof window !== "undefined" && window !== null) {
if (window.Y == null) {
window.Y = {};
}
window.Y.XmlFramework = XmlFramework;
}
}).call(this);
//# sourceMappingURL=../Frameworks/XmlFramework.js.map

File diff suppressed because one or more lines are too long

View File

@@ -12,12 +12,13 @@
this.is_deleted = false;
this.doSync = true;
this.garbage_collected = false;
if (uid != null) {
this.doSync = !isNaN(parseInt(uid.op_number));
} else {
if (uid == null) {
uid = HB.getNextOperationIdentifier();
}
this.creator = uid['creator'], this.op_number = uid['op_number'];
if (uid.doSync == null) {
uid.doSync = !isNaN(parseInt(uid.op_number));
}
this.creator = uid['creator'], this.op_number = uid['op_number'], this.doSync = uid['doSync'];
}
Operation.prototype.type = "Insert";
@@ -217,34 +218,32 @@
Insert.prototype.type = "Insert";
Insert.prototype.applyDelete = function(o) {
var garbagecollect;
var garbagecollect, _ref;
if (this.deleted_by == null) {
this.deleted_by = [];
}
if ((this.parent != null) && !this.isDeleted()) {
if (o != null) {
this.parent.callEvent("delete", this, o);
}
this.parent.callEvent("delete", this, o);
}
if (o != null) {
this.deleted_by.push(o);
}
garbagecollect = false;
if (this.prev_cl.isDeleted()) {
if (!((this.prev_cl != null) && (this.next_cl != null)) || this.prev_cl.isDeleted()) {
garbagecollect = true;
}
Insert.__super__.applyDelete.call(this, garbagecollect);
if (this.next_cl.isDeleted()) {
if ((_ref = this.next_cl) != null ? _ref.isDeleted() : void 0) {
return this.next_cl.applyDelete();
}
};
Insert.prototype.cleanup = function() {
var d, o, _i, _len, _ref;
if (this.prev_cl.isDeleted()) {
_ref = this.deleted_by;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
d = _ref[_i];
var d, o, _i, _len, _ref, _ref1;
if ((_ref = this.prev_cl) != null ? _ref.isDeleted() : void 0) {
_ref1 = this.deleted_by;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
d = _ref1[_i];
d.cleanup();
}
o = this.next_cl;
@@ -274,8 +273,11 @@
return d;
};
Insert.prototype.execute = function() {
Insert.prototype.execute = function(fire_event) {
var distance_to_origin, i, o, parent, _ref;
if (fire_event == null) {
fire_event = true;
}
if (!this.validateSavedOperations()) {
return false;
} else {
@@ -313,7 +315,7 @@
this.next_cl.prev_cl = this;
}
parent = (_ref = this.prev_cl) != null ? _ref.getParent() : void 0;
if (parent != null) {
if ((parent != null) && fire_event) {
this.setParent(parent);
this.parent.callEvent("insert", this);
}

File diff suppressed because one or more lines are too long

View File

@@ -255,9 +255,7 @@
}
});
addPropertyListener = function(event, op) {
if (op.next_cl instanceof types.Delimiter && op.prev_cl instanceof types.Delimiter) {
repl_manager.parent.callEvent('addProperty', property_name, op);
}
repl_manager.parent.callEvent('addProperty', property_name, op);
return repl_manager.deleteListener('addProperty', addPropertyListener);
};
this.on('insert', addPropertyListener);
@@ -323,7 +321,6 @@
this.content.applyDelete();
this.content.dontSync();
}
this.beforeDelete = this.content;
this.content = null;
return Replaceable.__super__.applyDelete.apply(this, arguments);
};
@@ -342,7 +339,7 @@
_ref.setReplaceManager(this.parent);
}
}
ins_result = Replaceable.__super__.execute.call(this);
ins_result = Replaceable.__super__.execute.call(this, this.content != null);
if (ins_result) {
if (this.next_cl.type === "Delimiter" && this.prev_cl.type !== "Delimiter") {
this.prev_cl.applyDelete();

File diff suppressed because one or more lines are too long

View File

@@ -101,23 +101,37 @@
return WordType.__super__.cleanup.call(this);
};
WordType.prototype.insertText = function(position, content) {
var c, ith, left, op, right, _i, _len;
ith = this.getOperationByPosition(position);
left = ith.prev_cl;
WordType.prototype.push = function(content) {
return this.insertAfter(this.end.prev_cl, content);
};
WordType.prototype.insertAfter = function(left, content) {
var c, op, right, _i, _len;
while (left.isDeleted()) {
left = left.prev_cl;
}
right = left.next_cl;
for (_i = 0, _len = content.length; _i < _len; _i++) {
c = content[_i];
op = new TextInsert(c, void 0, left, right);
if (content.type != null) {
op = new TextInsert(content, void 0, left, right);
HB.addOperation(op).execute();
left = op;
} else {
for (_i = 0, _len = content.length; _i < _len; _i++) {
c = content[_i];
op = new TextInsert(c, void 0, left, right);
HB.addOperation(op).execute();
left = op;
}
}
return this;
};
WordType.prototype.insertText = function(position, content) {
var ith, left;
ith = this.getOperationByPosition(position);
left = ith.prev_cl;
return this.insertAfter(left, content);
};
WordType.prototype.deleteText = function(position, length) {
var d, delete_ops, i, o, _i;
o = this.getOperationByPosition(position);
@@ -174,12 +188,16 @@
WordType.prototype.setReplaceManager = function(op) {
this.saveOperation('replace_manager', op);
this.validateSavedOperations();
this.on('insert', function(event, ins) {
return op.forwardEvent(this, 'change', ins);
});
this.on('insert', (function(_this) {
return function(event, ins) {
var _ref;
return (_ref = _this.replace_manager) != null ? _ref.forwardEvent(_this, 'change', ins) : void 0;
};
})(this));
return this.on('delete', (function(_this) {
return function(event, ins, del) {
return op.forwardEvent(_this, 'change', del);
var _ref;
return (_ref = _this.replace_manager) != null ? _ref.forwardEvent(_this, 'change', del) : void 0;
};
})(this));
};

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,193 @@
(function() {
var json_types_uninitialized,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
json_types_uninitialized = require("./JsonTypes");
if (typeof Element !== "undefined" && Element !== null) {
Element.prototype._proxy = function(f_name, f) {
var old_f;
old_f = this[f_name];
if (old_f != null) {
return this[f_name] = function() {
f.apply(this, arguments);
return old_f.apply(this, arguments);
};
} else {
return this[f_name] = f;
}
};
}
module.exports = function(HB) {
var XmlType, json_types, parser, types;
json_types = json_types_uninitialized(HB);
types = json_types.types;
parser = json_types.parser;
XmlType = (function(_super) {
__extends(XmlType, _super);
function XmlType(uid, tagname, attributes, elements, xml, prev, next, origin) {
var attr, element, i, last, n, word, _i, _j, _len, _ref, _ref1;
this.tagname = tagname;
this.xml = xml;
if ((prev != null) && (next == null) && (prev.type != null)) {
while (prev.isDeleted()) {
prev = prev.prev_cl;
}
next = prev.next_cl;
}
XmlType.__super__.constructor.call(this, uid, prev, next, origin);
if ((attributes != null) && (elements != null)) {
this.saveOperation('attributes', attributes);
this.saveOperation('elements', elements);
} else if ((attributes == null) && (elements == null)) {
this.attributes = new types.JsonType();
HB.addOperation(this.attributes).execute();
this.elements = new types.WordType();
this.elements.parent = this;
HB.addOperation(this.elements).execute();
} else {
throw new Error("Either define attribute and elements both, or none of them");
}
if (this.xml != null) {
this.tagname = this.xml.tagName;
for (i = _i = 0, _ref = this.xml.attributes.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
attr = xml.attributes[i];
this.attributes.val(attr.name, attr.value);
}
_ref1 = this.xml.childNodes;
for (_j = 0, _len = _ref1.length; _j < _len; _j++) {
n = _ref1[_j];
if (n.nodeType === n.TEXT_NODE) {
word = new types.WordType();
HB.addOperation(word).execute();
word.push(n.textContent);
this.elements.push(word);
} else if (n.nodeType === n.ELEMENT_NODE) {
last = this.elements.end;
element = new XmlType(void 0, void 0, void 0, void 0, n, last.prev_cl, last);
HB.addOperation(element).execute();
this.elements.push(element);
} else {
throw new Error("I don't know Node-type " + n.nodeType + "!!");
}
}
this.setXmlProxy();
}
void 0;
}
XmlType.prototype.type = "XmlType";
XmlType.prototype.applyDelete = function() {
this.attributes.applyDelete();
this.elements.applyDelete();
return XmlType.__super__.applyDelete.call(this);
};
XmlType.prototype.cleanup = function() {
return XmlType.__super__.cleanup.call(this);
};
XmlType.prototype.setXmlProxy = function() {
this.xml._yatta = this;
return this.xml._proxy('insertBefore', function(insertedNode, adjacentNode) {
var element, next, prev;
next = adjacentNode != null ? adjacentNode._yatta : void 0;
prev = null;
if (next != null) {
prev = next.prev_cl;
} else {
prev = this._yatta.elements.end.prev_cl;
}
element = new XmlType(void 0, void 0, void 0, void 0, insertedNode, prev);
return HB.addOperation(element).execute();
});
};
XmlType.prototype.val = function(enforce) {
var a, attr, attr_name, e, n, text_node, value;
if (enforce == null) {
enforce = false;
}
if (typeof document !== "undefined" && document !== null) {
if ((this.xml == null) || enforce) {
this.xml = document.createElement(this.tagname);
attr = this.attributes.val();
for (attr_name in attr) {
value = attr[attr_name];
a = document.createAttribute(attr_name);
a.value = value;
this.xml.setAttributeNode(a);
}
e = this.elements.beginning.next_cl;
while (e.type !== "Delimiter") {
n = e.content;
if (!n.isDeleted()) {
if (n.type === "XmlType") {
this.xml.appendChild(n.val(enforce));
} else if (n.type === "WordType") {
text_node = document.createTextNode(n.val());
this.xml.appendChild(text_node);
} else {
throw new Error("Internal structure cannot be transformed to dom");
}
}
e = e.next_cl;
}
}
this.setXmlProxy();
return this.xml;
}
};
XmlType.prototype.execute = function() {
return XmlType.__super__.execute.apply(this, arguments);
};
/*
if not @validateSavedOperations()
return false
else
return true
*/
XmlType.prototype.getParent = function() {
return this.parent;
};
XmlType.prototype._encode = function() {
var json, _ref, _ref1, _ref2;
json = {
'type': this.type,
'attributes': this.attributes.getUid(),
'elements': this.elements.getUid(),
'tagname': this.tagname,
'uid': this.getUid(),
'prev': (_ref = this.prev_cl) != null ? _ref.getUid() : void 0,
'next': (_ref1 = this.next_cl) != null ? _ref1.getUid() : void 0
};
if (this.origin !== this.prev_cl) {
json["origin"] = (_ref2 = this.origin) != null ? _ref2.getUid() : void 0;
}
return json;
};
return XmlType;
})(types.Insert);
parser['XmlType'] = function(json) {
var attributes, elements, next, origin, prev, tagname, uid;
uid = json['uid'], attributes = json['attributes'], elements = json['elements'], tagname = json['tagname'], prev = json['prev'], next = json['next'], origin = json['origin'];
return new XmlType(uid, tagname, attributes, elements, void 0, prev, next, origin);
};
types['XmlType'] = XmlType;
return json_types;
};
}).call(this);

File diff suppressed because one or more lines are too long

View File

@@ -7,6 +7,8 @@
exports['TextFramework'] = require('./Frameworks/TextFramework');
exports['XmlFramework'] = require('./Frameworks/XmlFramework');
}).call(this);
//# sourceMappingURL=index.js.map

View File

@@ -1 +1 @@
{"version":3,"sources":["index.coffee"],"names":[],"mappings":"AAEA;AAAA,EAAA,OAAQ,CAAA,cAAA,CAAR,GACE,OAAA,CAAQ,2BAAR,CADF,CAAA;;AAAA,EAEA,OAAQ,CAAA,eAAA,CAAR,GACE,OAAA,CAAQ,4BAAR,CAHF,CAAA;;AAAA,EAIA,OAAQ,CAAA,eAAA,CAAR,GACE,OAAA,CAAQ,4BAAR,CALF,CAAA;;AAAA,EAMA,OAAQ,CAAA,eAAA,CAAR,GACE,OAAA,CAAQ,4BAAR,CAPF,CAAA;AAAA","file":"index.js","sourceRoot":"/source/","sourcesContent":["\n\nexports['IwcConnector'] =\n require './Connectors/IwcConnector'\nexports['TestConnector'] =\n require './Connectors/TestConnector'\nexports['JsonFramework'] =\n require './Frameworks/JsonFramework'\nexports['TextFramework'] =\n require './Frameworks/TextFramework'\n\n"]}
{"version":3,"sources":["index.coffee"],"names":[],"mappings":"AAEA;AAAA,EAAA,OAAQ,CAAA,cAAA,CAAR,GACE,OAAA,CAAQ,2BAAR,CADF,CAAA;;AAAA,EAEA,OAAQ,CAAA,eAAA,CAAR,GACE,OAAA,CAAQ,4BAAR,CAHF,CAAA;;AAAA,EAIA,OAAQ,CAAA,eAAA,CAAR,GACE,OAAA,CAAQ,4BAAR,CALF,CAAA;;AAAA,EAMA,OAAQ,CAAA,eAAA,CAAR,GACE,OAAA,CAAQ,4BAAR,CAPF,CAAA;;AAAA,EAQA,OAAQ,CAAA,cAAA,CAAR,GACE,OAAA,CAAQ,2BAAR,CATF,CAAA;AAAA","file":"index.js","sourceRoot":"/source/","sourcesContent":["\n\nexports['IwcConnector'] =\n require './Connectors/IwcConnector'\nexports['TestConnector'] =\n require './Connectors/TestConnector'\nexports['JsonFramework'] =\n require './Frameworks/JsonFramework'\nexports['TextFramework'] =\n require './Frameworks/TextFramework'\nexports['XmlFramework'] =\n require './Frameworks/XmlFramework'\n\n"]}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -6,13 +6,21 @@
</head>
<body>
<div id="mocha"></div>
<script src="../../node_modules/mocha/mocha.js"></script>
<script>mocha.setup('bdd')</script>
<script src="TextYatta_test.js"></script>
<script src="JsonYatta_test.js"></script>
<div id="test_dom"><p>This is a test object for <b>XmlFramework</b></p></div>
<script src="../../node_modules/mocha/mocha.js" class="awesome"></script>
<script>
mocha.checkLeaks();
mocha.run();
mocha.setup('bdd');
mocha.ui('bdd');
mocha.reporter('html');
</script>
<!--script src="TextYatta_test.js"></script>
<script src="JsonYatta_test.js"></script-->
<script src="XmlYatta_test_browser.js"></script>
<script>
//mocha.checkLeaks();
//mocha.run();
if (window.mochaPhantomJS) { mochaPhantomJS.run(); }
else { mocha.run(); }
</script>
</body>
</html>