yjs/build/browser/Frameworks/TextYatta.min.js
2014-08-12 19:18:56 +02:00

1 line
17 KiB
JavaScript

!function e(t,n,r){function i(s,u){if(!n[s]){if(!t[s]){var p="function"==typeof require&&require;if(!u&&p)return p(s,!0);if(o)return o(s,!0);throw new Error("Cannot find module '"+s+"'")}var c=n[s]={exports:{}};t[s][0].call(c.exports,function(e){var n=t[s][1][e];return i(n?n:e)},c,c.exports,e,t,n,r)}return n[s].exports}for(var o="function"==typeof require&&require,s=0;s<r.length;s++)i(r[s]);return i}({1:[function(e,t){var n;n=function(){function e(e,t){this.HB=e,this.parser=t,this.unprocessed_ops=[]}return e.prototype.parseOperation=function(e){var t;if(t=this.parser[e.type],null!=t)return t(e);throw new Error("You forgot to specify a parser for type "+e.type+". The message is "+JSON.stringify(e)+".")},e.prototype.applyOpsBundle=function(e){var t,n,r,i,o,s,u,p;for(n=[],r=0,s=e.length;s>r;r++)t=e[r],n.push(this.parseOperation(t));for(i=0,u=n.length;u>i;i++)t=n[i],this.HB.addOperation(t);for(o=0,p=n.length;p>o;o++)t=n[o],t.execute()||this.unprocessed_ops.push(t);return this.tryUnprocessed()},e.prototype.applyOpsCheckDouble=function(e){var t,n,r,i;for(i=[],n=0,r=e.length;r>n;n++)t=e[n],i.push(null!=this.HB.getOperation(t.uid)?this.applyOp(t):void 0);return i},e.prototype.applyOps=function(e){var t,n,r,i;for(i=[],n=0,r=e.length;r>n;n++)t=e[n],i.push(this.applyOp(t));return i},e.prototype.applyOp=function(e){var t;return t=this.parseOperation(e),this.HB.addToCounter(t),t.execute()?this.HB.addOperation(t):this.unprocessed_ops.push(t),this.tryUnprocessed()},e.prototype.tryUnprocessed=function(){var e,t,n,r,i,o,s;for(s=[];;){for(e=this.unprocessed_ops.length,n=[],o=this.unprocessed_ops,r=0,i=o.length;i>r;r++)t=o[r],t.execute()?this.HB.addOperation(t):n.push(t);if(this.unprocessed_ops=n,this.unprocessed_ops.length===e)break;s.push(void 0)}return s},e}(),t.exports=n},{}],2:[function(e,t){var n,r,i,o;o=e("../Types/TextTypes"),r=e("../HistoryBuffer"),n=e("../Engine"),i=function(){function e(e,t){var i,s;this.HB=new r(e),s=o(this.HB),this.engine=new n(this.HB,s.parser),this.connector=new t(this.engine,this.HB,s.execution_listener),i=new s.types.Word(void 0),this.HB.addOperation(i).execute(),this.root_element=i}return e.prototype.getRootElement=function(){return this.root_element},e.prototype.getEngine=function(){return this.engine},e.prototype.getConnector=function(){return this.connector},e.prototype.getHistoryBuffer=function(){return this.HB},e.prototype.getUserId=function(){return this.HB.getUserId()},e.prototype.val=function(){return this.root_element.val()},e.prototype.insertText=function(e,t){return this.root_element.insertText(e,t)},e.prototype.deleteText=function(e,t){return this.root_element.deleteText(e,t)},e.prototype.replaceText=function(e){return this.root_element.replaceText(e)},e}(),t.exports=i},{"../Engine":1,"../HistoryBuffer":3,"../Types/TextTypes":6}],3:[function(e,t){var n;n=function(){function e(e){this.user_id=e,this.operation_counter={},this.buffer={},this.change_listeners=[]}return e.prototype.getUserId=function(){return this.user_id},e.prototype.getReservedUniqueIdentifier=function(){return{creator:"_",op_number:"_"}},e.prototype.getOperationCounter=function(){var e,t,n,r;t={},r=this.operation_counter;for(n in r)e=r[n],t[n]=e;return t},e.prototype._encode=function(e){var t,n,r,i,o,s,u,p,c,a;null==e&&(e={}),t=[],p=function(t,n){if(null==t||null==n)throw new Error("dah!");return null==e[t]||e[t]<=n},a=this.buffer;for(u in a){c=a[u];for(o in c)if(n=c[o],!isNaN(parseInt(o))&&p(u,o)){if(r=n._encode(),null!=n.next_cl){for(i=n.next_cl;null!=i.next_cl&&p(i.creator,i.op_number);)i=i.next_cl;r.next=i.getUid()}else if(null!=n.prev_cl){for(s=n.prev_cl;null!=s.prev_cl&&p(i.creator,i.op_number);)s=s.prev_cl;r.prev=s.getUid()}t.push(r)}}return t},e.prototype.getNextOperationIdentifier=function(e){var t;return null==e&&(e=this.user_id),null==this.operation_counter[e]&&(this.operation_counter[e]=0),t={creator:e,op_number:this.operation_counter[e]},this.operation_counter[e]++,t},e.prototype.getOperation=function(e){var t;if(e instanceof Object)return null!=(t=this.buffer[e.creator])?t[e.op_number]:void 0;if(null!=e)throw new Error("This type of uid is not defined!")},e.prototype.addOperation=function(e){if(null==this.buffer[e.creator]&&(this.buffer[e.creator]={}),null!=this.buffer[e.creator][e.op_number])throw new Error("You must not overwrite operations!");return this.buffer[e.creator][e.op_number]=e,e},e.prototype.addToCounter=function(e){return null==this.operation_counter[e.creator]&&(this.operation_counter[e.creator]=0),"number"==typeof e.op_number&&e.creator!==this.getUserId()?this.operation_counter[e.creator]++:void 0},e}(),t.exports=n},{}],4:[function(e,t){var n={}.hasOwnProperty,r=function(e,t){function r(){this.constructor=e}for(var i in t)n.call(t,i)&&(e[i]=t[i]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e};t.exports=function(e){var t,n,i,o,s,u,p;return p={},u=[],s=function(){function t(t){null==t&&(t=e.getNextOperationIdentifier()),this.creator=t.creator,this.op_number=t.op_number}return t.prototype.on=function(e,t){var n;return null==this.event_listeners&&(this.event_listeners={}),null==(n=this.event_listeners)[e]&&(n[e]=[]),this.event_listeners[e].push(t)},t.prototype.callEvent=function(e,t){var n,r,i,o,s;if(null!=this.event_listeners[e]){for(o=this.event_listeners[e],s=[],r=0,i=o.length;i>r;r++)n=o[r],s.push(n.call(this,e,t));return s}},t.prototype.setParent=function(e){return this.parent=e},t.prototype.getUid=function(){return{creator:this.creator,op_number:this.op_number}},t.prototype.execute=function(){var e,t,n;for(this.is_executed=!0,t=0,n=u.length;n>t;t++)(e=u[t])(this._encode());return this},t.prototype.saveOperation=function(e,t){return null!=(null!=t?t.execute:void 0)?this[e]=t:null!=t?(null==this.unchecked&&(this.unchecked={}),this.unchecked[e]=t):void 0},t.prototype.validateSavedOperations=function(){var t,n,r,i,o,s;o={},i=this,s=this.unchecked;for(t in s)r=s[t],n=e.getOperation(r),n?this[t]=n:(o[t]=r,i=!1);return delete this.unchecked,i||(this.unchecked=o),i},t}(),t=function(e){function t(e,n){this.saveOperation("deletes",n),t.__super__.constructor.call(this,e)}return r(t,e),t.prototype._encode=function(){return{type:"Delete",uid:this.getUid(),deletes:this.deletes.getUid()}},t.prototype.execute=function(){return this.validateSavedOperations()?(this.deletes.applyDelete(this),t.__super__.execute.apply(this,arguments),this):!1},t}(s),p.Delete=function(e){var n,r;return r=e.uid,n=e.deletes,new t(r,n)},o=function(e){function t(e,n,r,i){this.saveOperation("prev_cl",n),this.saveOperation("next_cl",r),null!=i?this.saveOperation("origin",i):this.saveOperation("origin",n),t.__super__.constructor.call(this,e)}return r(t,e),t.prototype.applyDelete=function(e){return null==this.deleted_by&&(this.deleted_by=[]),this.deleted_by.push(e)},t.prototype.isDeleted=function(){var e;return(null!=(e=this.deleted_by)?e.length:void 0)>0},t.prototype.getDistanceToOrigin=function(){var e,t;for(e=0,t=this.prev_cl;;){if(this.origin===t)break;if(e++,this===this.prev_cl)throw new Error("this should not happen ;) ");t=t.prev_cl}return e},t.prototype.update_sl=function(){var e;return e=this.prev_cl,update("prev_cl","prev_sl"),update("next_cl","prev_sl")},t.prototype.execute=function(){var e,n,r,i,o;if(null!=this.is_executed)return this;if(this.validateSavedOperations()){if((null!=(i=this.prev_cl)?i.validateSavedOperations():void 0)&&(null!=(o=this.next_cl)?o.validateSavedOperations():void 0)&&this.prev_cl.next_cl!==this){for(e=0,r=this.prev_cl.next_cl,n=0;;){if(null==r&&(console.log(JSON.stringify(this.prev_cl.getUid())),console.log(JSON.stringify(this.next_cl.getUid()))),r===this.next_cl)break;if(r.getDistanceToOrigin()===n)r.creator<this.creator&&(this.prev_cl=r,e=n+1);else{if(!(r.getDistanceToOrigin()<n))break;n-e<=r.getDistanceToOrigin()&&(this.prev_cl=r,e=n+1)}n++,r=r.next_cl}this.next_cl=this.prev_cl.next_cl,this.prev_cl.next_cl=this,this.next_cl.prev_cl=this}return t.__super__.execute.apply(this,arguments),this}return!1},t}(s),i=function(e){function t(e,n,r,i,o){this.content=n,t.__super__.constructor.call(this,e,r,i,o)}return r(t,e),t.prototype.val=function(){return this.content},t.prototype._encode=function(){var e;return e={type:"ImmutableObject",uid:this.getUid(),content:this.content},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},t}(o),p.ImmutableObject=function(e){var t,n,r,o,s;return s=e.uid,t=e.content,o=e.prev,n=e.next,r=e.origin,new i(s,t,o,n,r)},n=function(e){function t(e,n,r){this.saveOperation("prev_cl",n),this.saveOperation("next_cl",r),this.saveOperation("origin",n),t.__super__.constructor.call(this,e)}return r(t,e),t.prototype.isDeleted=function(){return!1},t.prototype.execute=function(){var e,n;if(null!=(null!=(e=this.unchecked)?e.next_cl:void 0))return t.__super__.execute.apply(this,arguments);if(null!=(n=this.unchecked)?n.prev_cl:void 0){if(this.validateSavedOperations()){if(null!=this.prev_cl.next_cl)throw new Error("Probably duplicated operations");return this.prev_cl.next_cl=this,delete this.prev_cl.unchecked.next_cl,t.__super__.execute.apply(this,arguments)}return!1}if(null!=this.prev_cl&&null==this.prev_cl.next_cl)return delete this.prev_cl.unchecked.next_cl,this.prev_cl.next_cl=this;if(null!=this.prev_cl||null!=this.next_cl)return t.__super__.execute.apply(this,arguments);throw new Error("Delimiter is unsufficient defined!")},t.prototype._encode=function(){var e,t;return{type:"Delimiter",uid:this.getUid(),prev:null!=(e=this.prev_cl)?e.getUid():void 0,next:null!=(t=this.next_cl)?t.getUid():void 0}},t}(s),p.Delimiter=function(e){var t,r,i;return i=e.uid,r=e.prev,t=e.next,new n(i,r,t)},{types:{Delete:t,Insert:o,Delimiter:n,Operation:s,ImmutableObject:i},parser:p,execution_listener:u}}},{}],5:[function(e,t){var n,r={}.hasOwnProperty,i=function(e,t){function n(){this.constructor=e}for(var i in t)r.call(t,i)&&(e[i]=t[i]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e};n=e("./BasicTypes"),t.exports=function(e){var t,r,o,s,u,p,c,a;return p=n(e),a=p.types,c=p.parser,o=function(n){function r(e){this.map={},r.__super__.constructor.call(this,e)}return i(r,n),r.prototype.val=function(n,i){var o,s,u,p,c;if(null!=i)return null==this.map[n]&&e.addOperation(new t(void 0,this,n)).execute(),this.map[n].replace(i),this;if(null!=n)return s=null!=(p=this.map[n])?p.val():void 0,s instanceof a.ImmutableObject?s.val():s;u={},c=this.map;for(n in c)o=c[n],s=o.val(),(s instanceof a.ImmutableObject||s instanceof r)&&(s=s.val()),u[n]=s;return u},r}(a.Operation),t=function(t){function n(e,t,r){this.name=r,this.saveOperation("map_manager",t),n.__super__.constructor.call(this,e)}return i(n,t),n.prototype.execute=function(){var t,r,i,o,u;return this.validateSavedOperations()?(u=this.map_manager.getUid(),u.op_number="_"+u.op_number+"_RM_"+this.name,null==e.getOperation(u)&&(i=this.map_manager.getUid(),i.op_number="_"+i.op_number+"_RM_"+this.name+"_beginning",o=this.map_manager.getUid(),o.op_number="_"+o.op_number+"_RM_"+this.name+"_end",t=e.addOperation(new a.Delimiter(i,void 0,o)).execute(),r=e.addOperation(new a.Delimiter(o,t,void 0)).execute(),this.map_manager.map[this.name]=e.addOperation(new s(void 0,u,t,r)).execute()),n.__super__.execute.apply(this,arguments)):!1},n.prototype._encode=function(){return{type:"AddName",uid:this.getUid(),map_manager:this.map_manager.getUid(),name:this.name}},n}(a.Operation),c.AddName=function(e){var n,r,i;return n=e.map_manager,i=e.uid,r=e.name,new t(i,n,r)},r=function(t){function n(t,r,i,o,s,u){null!=r&&null!=i?(this.saveOperation("beginning",r),this.saveOperation("end",i)):(this.beginning=e.addOperation(new a.Delimiter(void 0,void 0,void 0)),this.end=e.addOperation(new a.Delimiter(void 0,this.beginning,void 0)),this.beginning.next_cl=this.end,this.beginning.execute(),this.end.execute()),n.__super__.constructor.call(this,t,o,s,u)}return i(n,t),n.prototype.getLastOperation=function(){return this.end.prev_cl},n.prototype.getFirstOperation=function(){return this.beginning.next_cl},n.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},n.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 a.Delimiter)throw new Error("position parameter exceeded the length of the document!")}return t},n}(a.Insert),s=function(t){function n(e,t,r,i,o,s,u){n.__super__.constructor.call(this,t,r,i,o,s,u),null!=e&&this.replace(e)}return i(n,t),n.prototype.replace=function(t){var n,r;return n=this.getLastOperation(),r=new u(t,this,void 0,n,n.next_cl),e.addOperation(r).execute()},n.prototype.val=function(){var e;if(e=this.getLastOperation(),e instanceof a.Delimiter)throw new Error("dtrn");return e.val()},n.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},n}(r),c.ReplaceManager=function(e){var t,n,r,i,o,u,p;return n=e.content,p=e.uid,u=e.prev,i=e.next,o=e.origin,t=e.beginning,r=e.end,new s(n,p,t,r,u,i,o)},u=function(e){function t(e,n,r,i,o,s){if(this.saveOperation("content",e),this.saveOperation("parent",n),null==i||null==o||null==e)throw new Error("You must define content, prev, and next for Replaceable-types!");t.__super__.constructor.call(this,r,i,o,s)}return i(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),this):!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}(a.Insert),c.Replaceable=function(e){var t,n,r,i,o,s;return t=e.content,i=e.ReplaceManager,s=e.uid,o=e.prev,n=e.next,r=e.origin,new u(t,i,s,o,n,r)},a.ListManager=r,a.MapManager=o,a.ReplaceManager=s,a.Replaceable=u,p}},{"./BasicTypes":4}],6:[function(e,t){var n,r={}.hasOwnProperty,i=function(e,t){function n(){this.constructor=e}for(var i in t)r.call(t,i)&&(e[i]=t[i]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e};n=e("./StructuredTypes"),t.exports=function(e){var t,r,o,s,u,p;return u=n(e),p=u.types,s=u.parser,t=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return i(t,e),t}(p.Delete),s.TextDelete=s.Delete,r=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 i(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}(p.Insert),s.TextInsert=function(e){var t,n,i,o,s;return t=e.content,s=e.uid,o=e.prev,n=e.next,i=e.origin,new r(t,s,o,n,i)},o=function(n){function o(e,t,n,r,i,s){o.__super__.constructor.call(this,e,t,n,r,i,s)}return i(o,n),o.prototype.insertText=function(t,n){var i,o,s,u,p,c;for(o=this.getOperationByPosition(t),c=[],u=0,p=n.length;p>u;u++)i=n[u],s=new r(i,void 0,o.prev_cl,o),c.push(e.addOperation(s).execute());return c},o.prototype.deleteText=function(n,r){var i,o,s,u,c;for(s=this.getOperationByPosition(n),c=[],o=u=0;r>=0?r>u:u>r;o=r>=0?++u:--u){for(i=e.addOperation(new t(void 0,s)).execute(),s=s.next_cl;s.isDeleted();){if(s instanceof p.Delimiter)throw new Error("You can't delete more than there is..");s=s.next_cl}c.push(i._encode())}return c},o.prototype.replaceText=function(t){var n;if(null!=this.replace_manager)return n=e.addOperation(new o(void 0)).execute(),n.insertText(0,t),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._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}(p.ListManager),s.Word=function(e){var t,n,r,i,s,u;return u=e.uid,t=e.beginning,n=e.end,s=e.prev,r=e.next,i=e.origin,new o(u,t,n,s,r,i)},p.TextInsert=r,p.TextDelete=t,p.Word=o,u}},{"./StructuredTypes":5}]},{},[2]);