fixed editor

This commit is contained in:
Kevin Jahns 2014-08-16 16:33:45 +02:00
parent f348ca8f5e
commit 9d61dd87fc
25 changed files with 169 additions and 183 deletions

View File

@ -12,7 +12,7 @@ Predefined data structures:
Unlike other frameworks, Yatta! supports P2P message propagation and is not bound to a specific communication protocol.
Currently supported communication protocols:
It is possible to add any communication protocol to yatta. Currently it supports:
* [PeerJs](http://peerjs.com/) - WebRTC library
* [IWC](http://dbis.rwth-aachen.de/cms/projects/the-xmpp-experience#interwidget-communication) - Inter-widget Communication

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
!function n(e,t,o){function r(u,c){if(!t[u]){if(!e[u]){var s="function"==typeof require&&require;if(!c&&s)return s(u,!0);if(i)return i(u,!0);throw new Error("Cannot find module '"+u+"'")}var f=t[u]={exports:{}};e[u][0].call(f.exports,function(n){var t=e[u][1][n];return r(t?t:n)},f,f.exports,n,e,t,o)}return t[u].exports}for(var i="function"==typeof require&&require,u=0;u<o.length;u++)r(o[u]);return r}({1:[function(n,e){var t;t=function(n){var e,t;return t=new Peer({key:"h7nlefbgavh1tt9"}),e=function(){function n(n,e,o,r){var i;this.engine=n,this.HB=e,this.execution_listener=o,this.yatta=r,this.peer=t,this.connections={},this.peer.on("connection",function(n){return function(e){return e.send("hey"),n.addConnection(e)}}(this)),i=function(n){return function(e){return n.send(e)}}(this),this.execution_listener.push(i)}return n.prototype.connectToPeer=function(n){return null==this.connections[n]&&n!==this.yatta.getUserId()?this.addConnection(t.connect(n)):void 0},n.prototype.getAllConnectionIds=function(){var n,e;e=[];for(n in this.connections)e.push(n);return e},n.prototype.addConnection=function(n){var e;return this.connections[n.peer]=n,n.on("data",function(n){return function(e){var t,o,r,i,u;if("hey"===e)return console.log("Yatta: Connection received with init message (debug)");if(null!=e.HB)return n.engine.applyOpsCheckDouble(e.HB);if(null!=e.op)return n.engine.applyOp(e.op);if(null!=e.conns){for(console.log("conns received"),i=e.conns,u=[],o=0,r=i.length;r>o;o++)t=i[o],u.push(n.connectToPeer(t));return u}throw new Error("Can't parse this operation")}}(this)),e=function(e){return function(){return n.send({HB:e.yatta.getHistoryBuffer()._encode()}),n.send({conns:e.getAllConnectionIds()})}}(this),setTimeout(e,1e3)},n.prototype.send=function(n){var e,t,o,r;if(n.uid.creator===this.HB.getUserId()&&"string"!=typeof n.uid.op_number){o=this.connections,r=[];for(t in o)e=o[t],r.push(e.send({op:n}));return r}},n.prototype.receive=function(n){return n.uid.creator!==this.HB.getUserId()?this.engine.applyOp(n):void 0},n}(),t.on("open",function(t){return n(e,t)})},e.exports=t,"undefined"!=typeof window&&null!==window&&(null==window.Y&&(window.Y={}),window.Y.createPeerJsConnector=t)},{}]},{},[1]);
!function n(e,t,r){function o(u,c){if(!t[u]){if(!e[u]){var s="function"==typeof require&&require;if(!c&&s)return s(u,!0);if(i)return i(u,!0);throw new Error("Cannot find module '"+u+"'")}var f=t[u]={exports:{}};e[u][0].call(f.exports,function(n){var t=e[u][1][n];return o(t?t:n)},f,f.exports,n,e,t,r)}return t[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({1:[function(n,e){var t;t=function(n){var e,t;return t=new Peer({key:"h7nlefbgavh1tt9"}),e=function(){function n(n,e,r,o){var i;this.engine=n,this.HB=e,this.execution_listener=r,this.yatta=o,this.peer=t,this.connections={},this.peer.on("connection",function(n){return function(e){return e.send("hey"),n.addConnection(e)}}(this)),i=function(n){return function(e){return n.send(e)}}(this),this.execution_listener.push(i)}return n.prototype.connectToPeer=function(n){return null==this.connections[n]&&n!==this.yatta.getUserId()?this.addConnection(t.connect(n)):void 0},n.prototype.getAllConnectionIds=function(){var n,e;e=[];for(n in this.connections)e.push(n);return e},n.prototype.addConnection=function(n){var e;return this.connections[n.peer]=n,n.on("data",function(n){return function(e){var t,r,o,i,u;if("hey"===e)return console.log("Yatta: Connection received with init message (debug)");if(null!=e.HB)return n.engine.applyOpsCheckDouble(e.HB);if(null!=e.op)return n.engine.applyOp(e.op);if(null!=e.conns){for(i=e.conns,u=[],r=0,o=i.length;o>r;r++)t=i[r],u.push(n.connectToPeer(t));return u}throw new Error("Can't parse this operation")}}(this)),e=function(e){return function(){return n.send({HB:e.yatta.getHistoryBuffer()._encode()}),n.send({conns:e.getAllConnectionIds()})}}(this),setTimeout(e,1e3)},n.prototype.send=function(n){var e,t,r,o;if(n.uid.creator===this.HB.getUserId()&&"string"!=typeof n.uid.op_number){r=this.connections,o=[];for(t in r)e=r[t],o.push(e.send({op:n}));return o}},n.prototype.receive=function(n){return n.uid.creator!==this.HB.getUserId()?this.engine.applyOp(n):void 0},n}(),t.on("open",function(t){return n(e,t)})},e.exports=t,"undefined"!=typeof window&&null!==window&&(null==window.Y&&(window.Y={}),window.Y.createPeerJsConnector=t)},{}]},{},[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

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

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,2 +1,2 @@
(function(){var e,t={}.hasOwnProperty,n=function(e,n){function i(){this.constructor=e}for(var r in n)t.call(n,r)&&(e[r]=n[r]);return i.prototype=n.prototype,e.prototype=new i,e.__super__=n.prototype,e};e=require("./BasicTypes"),module.exports=function(t){var i,r,a,o,p,s,u,c;return s=e(t),c=s.types,u=s.parser,a=function(e){function r(e){this.map={},r.__super__.constructor.call(this,e)}return n(r,e),r.prototype.val=function(e,n){var a,o,p,s,u;if(null!=n)return null==this.map[e]&&t.addOperation(new i(void 0,this,e)).execute(),this.map[e].replace(n),this;if(null!=e)return o=null!=(s=this.map[e])?s.val():void 0,o instanceof c.ImmutableObject?o.val():o;p={},u=this.map;for(e in u)a=u[e],o=a.val(),(o instanceof c.ImmutableObject||o instanceof r)&&(o=o.val()),p[e]=o;return p},r}(c.Operation),i=function(e){function i(e,t,n){this.name=n,this.saveOperation("map_manager",t),i.__super__.constructor.call(this,e)}return n(i,e),i.prototype.execute=function(){var e,n,r,a,p;return this.validateSavedOperations()?(p=this.map_manager.getUid(),p.op_number="_"+p.op_number+"_RM_"+this.name,null==t.getOperation(p)&&(r=this.map_manager.getUid(),r.op_number="_"+r.op_number+"_RM_"+this.name+"_beginning",a=this.map_manager.getUid(),a.op_number="_"+a.op_number+"_RM_"+this.name+"_end",e=t.addOperation(new c.Delimiter(r,void 0,a)).execute(),n=t.addOperation(new c.Delimiter(a,e,void 0)).execute(),this.map_manager.map[this.name]=t.addOperation(new o(void 0,p,e,n)).execute()),i.__super__.execute.apply(this,arguments)):!1},i.prototype._encode=function(){return{type:"AddName",uid:this.getUid(),map_manager:this.map_manager.getUid(),name:this.name}},i}(c.Operation),u.AddName=function(e){var t,n,r;return t=e.map_manager,r=e.uid,n=e.name,new i(r,t,n)},r=function(e){function i(e,n,r,a,o,p){null!=n&&null!=r?(this.saveOperation("beginning",n),this.saveOperation("end",r)):(this.beginning=t.addOperation(new c.Delimiter(void 0,void 0,void 0)),this.end=t.addOperation(new c.Delimiter(void 0,this.beginning,void 0)),this.beginning.next_cl=this.end,this.beginning.execute(),this.end.execute()),i.__super__.constructor.call(this,e,a,o,p)}return n(i,e),i.prototype.execute=function(){return this.validateSavedOperations()?(this.beginning.setParent(this),this.end.setParent(this),i.__super__.execute.apply(this,arguments)):!1},i.prototype.getLastOperation=function(){return this.end.prev_cl},i.prototype.getFirstOperation=function(){return this.beginning.next_cl},i.prototype.toArray=function(){var e,t;for(e=this.beginning.next_cl,t=[];e!==this.end;)t.push(e),e=e.next_cl;return t},i.prototype.getOperationByPosition=function(e){var t;if(t=this.beginning.next_cl,e>0)for(;;){if(t=t.next_cl,t.isDeleted()||(e-=1),0===e)break;if(t instanceof c.Delimiter){console.log("position parameter exceeded the length of the document!"),t=null;break}}return t},i}(c.Insert),o=function(e){function i(e,t,n,r,a,o,p){i.__super__.constructor.call(this,t,n,r,a,o,p),null!=e&&this.replace(e)}return n(i,e),i.prototype.replace=function(e){var n,i;return n=this.getLastOperation(),i=new p(e,this,void 0,n,n.next_cl),t.addOperation(i).execute()},i.prototype.val=function(){var e;if(e=this.getLastOperation(),e instanceof c.Delimiter)throw new Error("dtrn");return e.val()},i.prototype._encode=function(){var e;return e={type:"ReplaceManager",uid:this.getUid(),beginning:this.beginning.getUid(),end:this.end.getUid()},null!=this.prev_cl&&null!=this.next_cl&&(e.prev=this.prev_cl.getUid(),e.next=this.next_cl.getUid()),null!=this.origin&&this.origin!==this.prev_cl&&(e.origin=this.origin.getUid()),e},i}(r),u.ReplaceManager=function(e){var t,n,i,r,a,p,s;return n=e.content,s=e.uid,p=e.prev,r=e.next,a=e.origin,t=e.beginning,i=e.end,new o(n,s,t,i,p,r,a)},p=function(e){function t(e,n,i,r,a,o){if(this.saveOperation("content",e),this.saveOperation("parent",n),null==r||null==a||null==e)throw new Error("You must define content, prev, and next for Replaceable-types!");t.__super__.constructor.call(this,i,r,a,o)}return n(t,e),t.prototype.val=function(){return this.content},t.prototype.replace=function(e){return this.parent.replace(e)},t.prototype.execute=function(){var e;return this.validateSavedOperations()?("function"==typeof(e=this.content).setReplaceManager&&e.setReplaceManager(this.parent),t.__super__.execute.apply(this,arguments)):!1},t.prototype._encode=function(){var e;return e={type:"Replaceable",content:this.content.getUid(),ReplaceManager:this.parent.getUid(),prev:this.prev_cl.getUid(),next:this.next_cl.getUid(),uid:this.getUid()},null!=this.origin&&this.origin!==this.prev_cl&&(e.origin=this.origin.getUid()),e},t}(c.Insert),u.Replaceable=function(e){var t,n,i,r,a,o;return t=e.content,r=e.ReplaceManager,o=e.uid,a=e.prev,n=e.next,i=e.origin,new p(t,r,o,a,n,i)},c.ListManager=r,c.MapManager=a,c.ReplaceManager=o,c.Replaceable=p,s}}).call(this);
(function(){var e,t={}.hasOwnProperty,n=function(e,n){function i(){this.constructor=e}for(var r in n)t.call(n,r)&&(e[r]=n[r]);return i.prototype=n.prototype,e.prototype=new i,e.__super__=n.prototype,e};e=require("./BasicTypes"),module.exports=function(t){var i,r,a,o,p,s,u,c;return s=e(t),c=s.types,u=s.parser,a=function(e){function r(e){this.map={},r.__super__.constructor.call(this,e)}return n(r,e),r.prototype.val=function(e,n){var a,o,p,s,u;if(null!=n)return null==this.map[e]&&t.addOperation(new i(void 0,this,e)).execute(),this.map[e].replace(n),this;if(null!=e)return o=null!=(s=this.map[e])?s.val():void 0,o instanceof c.ImmutableObject?o.val():o;p={},u=this.map;for(e in u)a=u[e],o=a.val(),(o instanceof c.ImmutableObject||o instanceof r)&&(o=o.val()),p[e]=o;return p},r}(c.Operation),i=function(e){function i(e,t,n){this.name=n,this.saveOperation("map_manager",t),i.__super__.constructor.call(this,e)}return n(i,e),i.prototype.execute=function(){var e,n,r,a,p;return this.validateSavedOperations()?(p=this.map_manager.getUid(),p.op_number="_"+p.op_number+"_RM_"+this.name,null==t.getOperation(p)&&(r=this.map_manager.getUid(),r.op_number="_"+r.op_number+"_RM_"+this.name+"_beginning",a=this.map_manager.getUid(),a.op_number="_"+a.op_number+"_RM_"+this.name+"_end",e=t.addOperation(new c.Delimiter(r,void 0,a)).execute(),n=t.addOperation(new c.Delimiter(a,e,void 0)).execute(),this.map_manager.map[this.name]=t.addOperation(new o(void 0,p,e,n)).execute()),i.__super__.execute.apply(this,arguments)):!1},i.prototype._encode=function(){return{type:"AddName",uid:this.getUid(),map_manager:this.map_manager.getUid(),name:this.name}},i}(c.Operation),u.AddName=function(e){var t,n,r;return t=e.map_manager,r=e.uid,n=e.name,new i(r,t,n)},r=function(e){function i(e,n,r,a,o,p){null!=n&&null!=r?(this.saveOperation("beginning",n),this.saveOperation("end",r)):(this.beginning=t.addOperation(new c.Delimiter(void 0,void 0,void 0)),this.end=t.addOperation(new c.Delimiter(void 0,this.beginning,void 0)),this.beginning.next_cl=this.end,this.beginning.execute(),this.end.execute()),i.__super__.constructor.call(this,e,a,o,p)}return n(i,e),i.prototype.execute=function(){return this.validateSavedOperations()?(this.beginning.setParent(this),this.end.setParent(this),i.__super__.execute.apply(this,arguments)):!1},i.prototype.getLastOperation=function(){return this.end.prev_cl},i.prototype.getFirstOperation=function(){return this.beginning.next_cl},i.prototype.toArray=function(){var e,t;for(e=this.beginning.next_cl,t=[];e!==this.end;)t.push(e),e=e.next_cl;return t},i.prototype.getOperationByPosition=function(e){var t;if(t=this.beginning.next_cl,(e>0||t.isDeleted())&&!(t instanceof c.Delimiter)){for(;t.isDeleted()&&!(t instanceof c.Delimiter);)t=t.next_cl;for(;;){if(t instanceof c.Delimiter)break;if(t=t.next_cl,t.isDeleted()||(e-=1),0>=e&&!t.isDeleted())break}}return t},i}(c.Insert),o=function(e){function i(e,t,n,r,a,o,p){i.__super__.constructor.call(this,t,n,r,a,o,p),null!=e&&this.replace(e)}return n(i,e),i.prototype.replace=function(e){var n,i;return n=this.getLastOperation(),i=new p(e,this,void 0,n,n.next_cl),t.addOperation(i).execute()},i.prototype.val=function(){var e;if(e=this.getLastOperation(),e instanceof c.Delimiter)throw new Error("dtrn");return e.val()},i.prototype._encode=function(){var e;return e={type:"ReplaceManager",uid:this.getUid(),beginning:this.beginning.getUid(),end:this.end.getUid()},null!=this.prev_cl&&null!=this.next_cl&&(e.prev=this.prev_cl.getUid(),e.next=this.next_cl.getUid()),null!=this.origin&&this.origin!==this.prev_cl&&(e.origin=this.origin.getUid()),e},i}(r),u.ReplaceManager=function(e){var t,n,i,r,a,p,s;return n=e.content,s=e.uid,p=e.prev,r=e.next,a=e.origin,t=e.beginning,i=e.end,new o(n,s,t,i,p,r,a)},p=function(e){function t(e,n,i,r,a,o){if(this.saveOperation("content",e),this.saveOperation("parent",n),null==r||null==a||null==e)throw new Error("You must define content, prev, and next for Replaceable-types!");t.__super__.constructor.call(this,i,r,a,o)}return n(t,e),t.prototype.val=function(){return this.content},t.prototype.replace=function(e){return this.parent.replace(e)},t.prototype.execute=function(){var e;return this.validateSavedOperations()?("function"==typeof(e=this.content).setReplaceManager&&e.setReplaceManager(this.parent),t.__super__.execute.apply(this,arguments)):!1},t.prototype._encode=function(){var e;return e={type:"Replaceable",content:this.content.getUid(),ReplaceManager:this.parent.getUid(),prev:this.prev_cl.getUid(),next:this.next_cl.getUid(),uid:this.getUid()},null!=this.origin&&this.origin!==this.prev_cl&&(e.origin=this.origin.getUid()),e},t}(c.Insert),u.Replaceable=function(e){var t,n,i,r,a,o;return t=e.content,r=e.ReplaceManager,o=e.uid,a=e.prev,n=e.next,i=e.origin,new p(t,r,o,a,n,i)},c.ListManager=r,c.MapManager=a,c.ReplaceManager=o,c.Replaceable=p,s}}).call(this);
//# sourceMappingURL=../Types/StructuredTypes.js.map

File diff suppressed because one or more lines are too long

View File

@ -1,2 +1,2 @@
(function(){var e,t={}.hasOwnProperty,n=function(e,n){function r(){this.constructor=e}for(var i in n)t.call(n,i)&&(e[i]=n[i]);return r.prototype=n.prototype,e.prototype=new r,e.__super__=n.prototype,e};e=require("./StructuredTypes"),module.exports=function(t){var r,i,o,l,s,a;return s=e(t),a=s.types,l=s.parser,r=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return n(t,e),t}(a.Delete),l.TextDelete=l.Delete,i=function(e){function t(e,n,r,i,o){if(this.content=e,null==r||null==i)throw new Error("You must define prev, and next for TextInsert-types!");t.__super__.constructor.call(this,n,r,i,o)}return n(t,e),t.prototype.getLength=function(){return this.isDeleted()?0:this.content.length},t.prototype.val=function(){return this.isDeleted()?"":this.content},t.prototype._encode=function(){var e;return e={type:"TextInsert",content:this.content,uid:this.getUid(),prev:this.prev_cl.getUid(),next:this.next_cl.getUid()},null!=this.origin&&this.origin!==this.prev_cl&&(e.origin=this.origin.getUid()),e},t}(a.Insert),l.TextInsert=function(e){var t,n,r,o,l;return t=e.content,l=e.uid,o=e.prev,n=e.next,r=e.origin,new i(t,l,o,n,r)},o=function(e){function o(e,t,n,r,i,l){o.__super__.constructor.call(this,e,t,n,r,i,l)}return n(o,e),o.prototype.insertText=function(e,n){var r,o,l,s,a,u;for(o=this.getOperationByPosition(e),u=[],s=0,a=n.length;a>s;s++)r=n[s],l=new i(r,void 0,o.prev_cl,o),u.push(t.addOperation(l).execute());return u},o.prototype.deleteText=function(e,n){var i,o,l,s,u,c;for(s=this.getOperationByPosition(e),o=[],c=[],l=u=0;n>=0?n>u:u>n;l=n>=0?++u:--u){for(i=t.addOperation(new r(void 0,s)).execute(),s=s.next_cl;s.isDeleted()&&!(s instanceof a.Delimiter);){if(s instanceof a.Delimiter)throw new Error("You can't delete more than there is..");s=s.next_cl}if(o.push(i._encode()),s instanceof a.Delimiter)break;c.push(void 0)}return c},o.prototype.replaceText=function(e){var n;if(null!=this.replace_manager)return n=t.addOperation(new o(void 0)).execute(),n.insertText(0,e),this.replace_manager.replace(n);throw new Error("This type is currently not maintained by a ReplaceManager!")},o.prototype.val=function(){var e,t;return e=function(){var e,n,r,i;for(r=this.toArray(),i=[],e=0,n=r.length;n>e;e++)t=r[e],i.push(null!=t.val?t.val():"");return i}.call(this),e.join("")},o.prototype.setReplaceManager=function(e){return this.saveOperation("replace_manager",e),this.validateSavedOperations},o.prototype.bind=function(e){var t;return t=this,e.value=this.val(),this.on("insert",function(n,r){var i,o,l,s;return l=r.getPosition(),i=function(e){return l>=e?e:e+=1},o=i(e.selectionStart),s=i(e.selectionEnd),e.value=t.val(),e.setSelectionRange(o,s)}),this.on("delete",function(n,r){var i,o,l,s;return l=r.getPosition(),i=function(e){return l>e?e:e-=1},o=i(e.selectionStart),s=i(e.selectionEnd),e.value=t.val(),e.setSelectionRange(o,s)}),e.onkeypress=function(n){var r,i,o,l;return r=String.fromCharCode(n.keyCode),r.length>0?(console.log(r),l=Math.min(e.selectionStart,e.selectionEnd),i=Math.abs(e.selectionEnd-e.selectionStart),t.deleteText(l,i),t.insertText(l,r),o=l+r.length,e.setSelectionRange(o,o),n.preventDefault()):n.preventDefault()},e.onkeydown=function(n){var r,i,o,l,s;if(l=Math.min(e.selectionStart,e.selectionEnd),i=Math.abs(e.selectionEnd-e.selectionStart),null!=n.keyCode&&8===n.keyCode){if(i>0)t.deleteText(l,i);else if(null!=n.ctrlKey&&n.ctrlKey){for(s=e.value,o=l,r=0,l>0&&(o--,r++);o>0&&" "!==s[o]&&"\n"!==s[o];)o--,r++;t.deleteText(o,l-o),e.setSelectionRange(o,o)}else t.deleteText(l-1,1);return n.preventDefault()}return null!=n.keyCode&&46===n.keyCode?(i>0?t.deleteText(l,i):t.deleteText(l,1),n.preventDefault()):void 0}},o.prototype._encode=function(){var e;return e={type:"Word",uid:this.getUid(),beginning:this.beginning.getUid(),end:this.end.getUid()},null!=this.prev_cl&&(e.prev=this.prev_cl.getUid()),null!=this.next_cl&&(e.next=this.next_cl.getUid()),null!=this.origin&&this.origin!==this.prev_cl&&(e.origin=this.origin.getUid()),e},o}(a.ListManager),l.Word=function(e){var t,n,r,i,l,s;return s=e.uid,t=e.beginning,n=e.end,l=e.prev,r=e.next,i=e.origin,new o(s,t,n,l,r,i)},a.TextInsert=i,a.TextDelete=r,a.Word=o,s}}).call(this);
(function(){var e,t={}.hasOwnProperty,n=function(e,n){function r(){this.constructor=e}for(var i in n)t.call(n,i)&&(e[i]=n[i]);return r.prototype=n.prototype,e.prototype=new r,e.__super__=n.prototype,e};e=require("./StructuredTypes"),module.exports=function(t){var r,i,o,l,s,a;return s=e(t),a=s.types,l=s.parser,r=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return n(t,e),t}(a.Delete),l.TextDelete=l.Delete,i=function(e){function t(e,n,r,i,o){if(this.content=e,null==r||null==i)throw new Error("You must define prev, and next for TextInsert-types!");t.__super__.constructor.call(this,n,r,i,o)}return n(t,e),t.prototype.getLength=function(){return this.isDeleted()?0:this.content.length},t.prototype.val=function(){return this.isDeleted()?"":this.content},t.prototype._encode=function(){var e;return e={type:"TextInsert",content:this.content,uid:this.getUid(),prev:this.prev_cl.getUid(),next:this.next_cl.getUid()},null!=this.origin&&this.origin!==this.prev_cl&&(e.origin=this.origin.getUid()),e},t}(a.Insert),l.TextInsert=function(e){var t,n,r,o,l;return t=e.content,l=e.uid,o=e.prev,n=e.next,r=e.origin,new i(t,l,o,n,r)},o=function(e){function o(e,t,n,r,i,l){o.__super__.constructor.call(this,e,t,n,r,i,l)}return n(o,e),o.prototype.insertText=function(e,n){var r,o,l,s,a,u;for(o=this.getOperationByPosition(e),u=[],s=0,a=n.length;a>s;s++)r=n[s],l=new i(r,void 0,o.prev_cl,o),u.push(t.addOperation(l).execute());return u},o.prototype.deleteText=function(e,n){var i,o,l,s,u;for(s=this.getOperationByPosition(e),o=[],l=u=0;(n>=0?n>u:u>n)&&!(s instanceof a.Delimiter);l=n>=0?++u:--u){for(i=t.addOperation(new r(void 0,s)).execute(),s=s.next_cl;!(s instanceof a.Delimiter)&&s.isDeleted();)s=s.next_cl;o.push(i._encode())}return o},o.prototype.replaceText=function(e){var n;if(null!=this.replace_manager)return n=t.addOperation(new o(void 0)).execute(),n.insertText(0,e),this.replace_manager.replace(n);throw new Error("This type is currently not maintained by a ReplaceManager!")},o.prototype.val=function(){var e,t;return e=function(){var e,n,r,i;for(r=this.toArray(),i=[],e=0,n=r.length;n>e;e++)t=r[e],i.push(null!=t.val?t.val():"");return i}.call(this),e.join("")},o.prototype.setReplaceManager=function(e){return this.saveOperation("replace_manager",e),this.validateSavedOperations},o.prototype.bind=function(e){var t;return t=this,e.value=this.val(),this.on("insert",function(n,r){var i,o,l,s;return l=r.getPosition(),i=function(e){return l>=e?e:e+=1},o=i(e.selectionStart),s=i(e.selectionEnd),e.value=t.val(),e.setSelectionRange(o,s)}),this.on("delete",function(n,r){var i,o,l,s;return l=r.getPosition(),i=function(e){return l>e?e:e-=1},o=i(e.selectionStart),s=i(e.selectionEnd),e.value=t.val(),e.setSelectionRange(o,s)}),e.onkeypress=function(n){var r,i,o,l;return r=String.fromCharCode(n.keyCode),r.length>0?(console.log(r),l=Math.min(e.selectionStart,e.selectionEnd),i=Math.abs(e.selectionEnd-e.selectionStart),t.deleteText(l,i),t.insertText(l,r),o=l+r.length,e.setSelectionRange(o,o),n.preventDefault()):n.preventDefault()},e.onkeydown=function(n){var r,i,o,l,s;if(l=Math.min(e.selectionStart,e.selectionEnd),i=Math.abs(e.selectionEnd-e.selectionStart),null!=n.keyCode&&8===n.keyCode){if(i>0)t.deleteText(l,i),e.setSelectionRange(l,l);else if(null!=n.ctrlKey&&n.ctrlKey){for(s=e.value,o=l,r=0,l>0&&(o--,r++);o>0&&" "!==s[o]&&"\n"!==s[o];)o--,r++;t.deleteText(o,l-o),e.setSelectionRange(o,o)}else t.deleteText(l-1,1);return n.preventDefault()}return null!=n.keyCode&&46===n.keyCode?(i>0?(t.deleteText(l,i),e.setSelectionRange(l,l)):(t.deleteText(l,1),e.setSelectionRange(l,l)),n.preventDefault()):void 0}},o.prototype._encode=function(){var e;return e={type:"Word",uid:this.getUid(),beginning:this.beginning.getUid(),end:this.end.getUid()},null!=this.prev_cl&&(e.prev=this.prev_cl.getUid()),null!=this.next_cl&&(e.next=this.next_cl.getUid()),null!=this.origin&&this.origin!==this.prev_cl&&(e.origin=this.origin.getUid()),e},o}(a.ListManager),l.Word=function(e){var t,n,r,i,l,s;return s=e.uid,t=e.beginning,n=e.end,l=e.prev,r=e.next,i=e.origin,new o(s,t,n,l,r,i)},a.TextInsert=i,a.TextDelete=r,a.Word=o,s}}).call(this);
//# sourceMappingURL=../Types/TextTypes.js.map

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
{"version":3,"file":"Types/XmlTypes.js","sources":["Types/XmlTypes.coffee"],"names":[],"mappings":"CAwFuB","sourcesContent":[""],"sourceRoot":"/source/"}
{"version":3,"file":"Types/XmlTypes.js","sources":["Types/XmlTypes.coffee"],"names":[],"mappings":"CA0H8B","sourcesContent":[""],"sourceRoot":"/source/"}

File diff suppressed because one or more lines are too long

View File

@ -5,3 +5,4 @@ Here you find some (hopefully) usefull examples on how to use Yatta!
* [Text Editing](./TextEditing/) Simple collaborative text editing demo with PeerJs and Text Framework
* [IWC + Json](./IwcJson/) Tutorial on how to use Yatta! with Json and IWC
* [IWC](./IwcJson/) More IWC example widgets.

View File

@ -49,7 +49,6 @@ createPeerJsConnector = (callback)->
else if data.op?
@engine.applyOp data.op
else if data.conns?
console.log "conns received"
for conn_id in data.conns
@connectToPeer conn_id
else

View File

@ -153,17 +153,21 @@ module.exports = (HB)->
#
getOperationByPosition: (position)->
o = @beginning.next_cl
if position > 0
if (position > 0 or o.isDeleted()) and not (o instanceof types.Delimiter)
while o.isDeleted() and not (o instanceof types.Delimiter)
# find first non deleted op
o = o.next_cl
while true
# find the i-th op
if o instanceof types.Delimiter
break
if position <= 0 and not o.isDeleted()
break
o = o.next_cl
if not o.isDeleted()
position -= 1
if position is 0
break
if o instanceof types.Delimiter
console.log "position parameter exceeded the length of the document!"
o = null
break
o
#

View File

@ -99,16 +99,14 @@ module.exports = (HB)->
delete_ops = []
for i in [0...length]
d = HB.addOperation(new TextDelete undefined, o).execute()
o = o.next_cl
while o.isDeleted() and not (o instanceof types.Delimiter)
if o instanceof types.Delimiter
throw new Error "You can't delete more than there is.."
o = o.next_cl
delete_ops.push d._encode()
if o instanceof types.Delimiter
break
d = HB.addOperation(new TextDelete undefined, o).execute()
o = o.next_cl
while not (o instanceof types.Delimiter) and o.isDeleted()
o = o.next_cl
delete_ops.push d._encode()
delete_ops
#
# Replace the content of this word with another one. Concurrent replacements are not merged!
@ -184,7 +182,6 @@ module.exports = (HB)->
textfield.onkeypress = (event)->
char = String.fromCharCode event.keyCode
if char.length > 0
console.log char
pos = Math.min textfield.selectionStart, textfield.selectionEnd
diff = Math.abs(textfield.selectionEnd - textfield.selectionStart)
word.deleteText (pos), diff
@ -205,9 +202,10 @@ module.exports = (HB)->
textfield.onkeydown = (event)->
pos = Math.min textfield.selectionStart, textfield.selectionEnd
diff = Math.abs(textfield.selectionEnd - textfield.selectionStart)
if event.keyCode? and event.keyCode is 8
if event.keyCode? and event.keyCode is 8 # Backspace
if diff > 0
word.deleteText pos, diff
textfield.setSelectionRange pos, pos
else
if event.ctrlKey? and event.ctrlKey
val = textfield.value
@ -224,11 +222,13 @@ module.exports = (HB)->
else
word.deleteText (pos-1), 1
event.preventDefault()
else if event.keyCode? and event.keyCode is 46
else if event.keyCode? and event.keyCode is 46 # Delete
if diff > 0
word.deleteText pos, diff
textfield.setSelectionRange pos, pos
else
word.deleteText pos, 1
textfield.setSelectionRange pos, pos
event.preventDefault()