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

1 line
20 KiB
JavaScript

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