yjs/build/browser/Frameworks/XmlFramework.min.js

2 lines
36 KiB
JavaScript

!function e(t,n,r){function i(s,l){if(!n[s]){if(!t[s]){var a="function"==typeof require&&require;if(!l&&a)return a(s,!0);if(o)return o(s,!0);throw new Error("Cannot find module '"+s+"'")}var u=n[s]={exports:{}};t[s][0].call(u.exports,function(e){var n=t[s][1][e];return i(n?n:e)},u,u.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,l,a;for(n=[],r=0,s=e.length;s>r;r++)t=e[r],n.push(this.parseOperation(t));for(i=0,l=n.length;l>i;i++)t=n[i],this.HB.addOperation(t);for(o=0,a=n.length;a>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],null==this.HB.getOperation(t.uid)?i.push(this.applyOp(t)):i.push(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),null!=this.HB.getOperation(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],null!=this.HB.getOperation(t)||(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/XmlTypes"),r=e("../HistoryBuffer"),n=e("../Engine"),i=function(){function e(e,t){var i,s,l,a,u;this.HB=new r(e),l=o(this.HB),this.types=l.types,this.engine=new n(this.HB,l.parser),this.HB.engine=this.engine,this.connector=new t(this.engine,this.HB,l.execution_listener,this),a=this.HB.getReservedUniqueIdentifier(),u=this.HB.getReservedUniqueIdentifier(),i=this.HB.addOperation(new this.types.Delimiter(a,void 0,u)).execute(),s=this.HB.addOperation(new this.types.Delimiter(u,i,void 0)).execute(),this.root_element=new this.types.ReplaceManager(void 0,this.HB.getReservedUniqueIdentifier(),i,s),this.HB.addOperation(this.root_element).execute()}return e.prototype.getSharedObject=function(){return this.root_element.val()},e.prototype.getConnector=function(){return this.connector},e.prototype.getHistoryBuffer=function(){return this.HB},e.prototype.setMutableDefault=function(e){return this.getSharedObject().setMutableDefault(e)},e.prototype.getUserId=function(){return this.HB.getUserId()},e.prototype.toJson=function(){return this.getSharedObject().toJson()},e.prototype.val=function(){var e;if(0===arguments.length||"boolean"==typeof arguments[0])return this.getSharedObject().val(arguments[0]);if(1===arguments.length)return e=new this.types.XmlType(void 0,void 0,void 0,void 0,arguments[0]),this.HB.addOperation(e).execute(),this.root_element.replace(e),e;throw new Error("can only parse 0, or 1 parameter!")},e.prototype.on=function(){var e;return(e=this.getSharedObject()).on.apply(e,arguments)},e}(),t.exports=i,"undefined"!=typeof window&&null!==window&&(null==window.Y&&(window.Y={}),window.Y.XmlFramework=i)},{"../Engine":1,"../HistoryBuffer":3,"../Types/XmlTypes":8}],3:[function(e,t){var n,r=function(e,t){return function(){return e.apply(t,arguments)}};n=function(){function e(e){this.user_id=e,this.emptyGarbage=r(this.emptyGarbage,this),this.operation_counter={},this.buffer={},this.change_listeners=[],this.garbage=[],this.trash=[],this.performGarbageCollection=!0,this.garbageCollectTimeout=1e3,this.reserved_identifier_counter=0,setTimeout(this.emptyGarbage,this.garbageCollectTimeout)}return e.prototype.emptyGarbage=function(){var e,t,n,r;for(r=this.garbage,t=0,n=r.length;n>t;t++)e=r[t],"function"==typeof e.cleanup&&e.cleanup();return this.garbage=this.trash,this.trash=[],-1!==this.garbageCollectTimeout&&(this.garbageCollectTimeoutId=setTimeout(this.emptyGarbage,this.garbageCollectTimeout)),void 0},e.prototype.getUserId=function(){return this.user_id},e.prototype.addToGarbageCollector=function(){var e,t,n,r;if(this.performGarbageCollection){for(r=[],t=0,n=arguments.length;n>t;t++)e=arguments[t],null!=e?r.push(this.garbage.push(e)):r.push(void 0);return r}},e.prototype.stopGarbageCollection=function(){return this.performGarbageCollection=!1,this.setManualGarbageCollect(),this.garbage=[],this.trash=[]},e.prototype.setManualGarbageCollect=function(){return this.garbageCollectTimeout=-1,clearTimeout(this.garbageCollectTimeoutId),this.garbageCollectTimeoutId=void 0},e.prototype.setGarbageCollectTimeout=function(e){this.garbageCollectTimeout=e},e.prototype.getReservedUniqueIdentifier=function(){return{creator:"_",op_number:"_"+this.reserved_identifier_counter++,doSync:!1}},e.prototype.getOperationCounter=function(e){var t,n,r,i;if(null==e){n={},i=this.operation_counter;for(r in i)t=i[r],n[r]=t;return n}return this.operation_counter[e]},e.prototype._encode=function(e){var t,n,r,i,o,s,l,a,u,p;null==e&&(e={}),t=[],a=function(t,n){if(null==t||null==n)throw new Error("dah!");return null==e[t]||e[t]<=n},p=this.buffer;for(l in p){u=p[l];for(o in u)if(n=u[o],n.doSync&&a(l,o)){if(r=n._encode(),null!=n.next_cl){for(i=n.next_cl;null!=i.next_cl&&a(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&&a(s.creator,s.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,null==this.number_of_operations_added_to_HB&&(this.number_of_operations_added_to_HB=0),this.number_of_operations_added_to_HB++,e},e.prototype.removeOperation=function(e){var t;return null!=(t=this.buffer[e.creator])?delete t[e.op_number]:void 0},e.prototype.addToCounter=function(e){var t;if(null==this.operation_counter[e.creator]&&(this.operation_counter[e.creator]=0),"number"==typeof e.op_number&&e.creator!==this.getUserId()&&e.op_number===this.operation_counter[e.creator]){for(this.operation_counter[e.creator]++,t=[];null!=this.getOperation({creator:e.creator,op_number:this.operation_counter[e.creator]});)t.push(this.operation_counter[e.creator]++);return t}},e}(),t.exports=n},{}],4:[function(e,t){var n=[].slice,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};t.exports=function(e){var t,r,o,s,l,a,u;return u={},a=[],l=function(){function t(t){this.is_deleted=!1,this.doSync=!0,this.garbage_collected=!1,null==t&&(t=e.getNextOperationIdentifier()),null==t.doSync&&(t.doSync=!isNaN(parseInt(t.op_number))),this.creator=t.creator,this.op_number=t.op_number,this.doSync=t.doSync}return t.prototype.type="Insert",t.prototype.on=function(e,t){var n,r,i,o,s;for(null==this.event_listeners&&(this.event_listeners={}),e.constructor!==[].constructor&&(e=[e]),s=[],i=0,o=e.length;o>i;i++)n=e[i],null==(r=this.event_listeners)[n]&&(r[n]=[]),s.push(this.event_listeners[n].push(t));return s},t.prototype.deleteListener=function(e,t){var n,r,i,o,s;for(e.constructor!==[].constructor&&(e=[e]),s=[],r=0,i=e.length;i>r;r++)n=e[r],null!=(null!=(o=this.event_listeners)?o[n]:void 0)?s.push(this.event_listeners[n]=this.event_listeners[n].filter(function(e){return t!==e})):s.push(void 0);return s},t.prototype.callEvent=function(){return this.forwardEvent.apply(this,[this].concat(n.call(arguments)))},t.prototype.forwardEvent=function(){var e,t,r,i,o,s,l,a,u;if(i=arguments[0],t=arguments[1],e=3<=arguments.length?n.call(arguments,2):[],null!=(null!=(l=this.event_listeners)?l[t]:void 0)){for(a=this.event_listeners[t],u=[],o=0,s=a.length;s>o;o++)r=a[o],u.push(r.call.apply(r,[i,t].concat(n.call(e))));return u}},t.prototype.isDeleted=function(){return this.is_deleted},t.prototype.applyDelete=function(t){return null==t&&(t=!0),!this.garbage_collected&&(this.is_deleted=!0,t)?(this.garbage_collected=!0,e.addToGarbageCollector(this)):void 0},t.prototype.cleanup=function(){return e.removeOperation(this)},t.prototype.setParent=function(e){this.parent=e},t.prototype.getParent=function(){return this.parent},t.prototype.getUid=function(){return{creator:this.creator,op_number:this.op_number,sync:this.doSync}},t.prototype.dontSync=function(){return this.doSync=!1},t.prototype.execute=function(){var e,t,n;for(this.is_executed=!0,t=0,n=a.length;n>t;t++)e=a[t],e(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 i(t,e),t.prototype.type="Delete",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)):!1},t}(l),u.Delete=function(e){var n,r;return r=e.uid,n=e.deletes,new t(r,n)},s=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 i(t,e),t.prototype.type="Insert",t.prototype.applyDelete=function(e){var n,r,i;return null==this.deleted_by&&(this.deleted_by=[]),n=!1,null==this.parent||this.isDeleted()||(n=!0),null!=e&&this.deleted_by.push(e),r=!1,(null==this.prev_cl||null==this.next_cl||this.prev_cl.isDeleted())&&(r=!0),t.__super__.applyDelete.call(this,r),n&&this.parent.callEvent("delete",this,e),(null!=(i=this.next_cl)?i.isDeleted():void 0)?this.next_cl.applyDelete():void 0},t.prototype.cleanup=function(){var e,n,r,i,o,s;if(null!=(o=this.prev_cl)?o.isDeleted():void 0){for(s=this.deleted_by,r=0,i=s.length;i>r;r++)e=s[r],e.cleanup();for(n=this.next_cl;"Delimiter"!==n.type;)n.origin===this&&(n.origin=this.prev_cl),n=n.next_cl;return this.prev_cl.next_cl=this.next_cl,this.next_cl.prev_cl=this.prev_cl,t.__super__.cleanup.apply(this,arguments)}},t.prototype.getDistanceToOrigin=function(){var e,t;for(e=0,t=this.prev_cl;;){if(this.origin===t)break;e++,t=t.prev_cl}return e},t.prototype.execute=function(e){var n,r,i,o,s;if(null==e&&(e=!0),this.validateSavedOperations()){if(null!=this.prev_cl){for(n=this.getDistanceToOrigin(),i=this.prev_cl.next_cl,r=n;;){if(i===this.next_cl)break;if(i.getDistanceToOrigin()===r)i.creator<this.creator&&(this.prev_cl=i,n=r+1);else{if(!(i.getDistanceToOrigin()<r))break;r-n<=i.getDistanceToOrigin()&&(this.prev_cl=i,n=r+1)}r++,i=i.next_cl}this.next_cl=this.prev_cl.next_cl,this.prev_cl.next_cl=this,this.next_cl.prev_cl=this}return o=null!=(s=this.prev_cl)?s.getParent():void 0,null!=o&&e&&(this.setParent(o),this.parent.callEvent("insert",this)),t.__super__.execute.apply(this,arguments)}return!1},t.prototype.getPosition=function(){var e,t;for(e=0,t=this.prev_cl;;){if(t instanceof r)break;t.isDeleted()||e++,t=t.prev_cl}return e},t}(l),o=function(e){function t(e,n,r,i,o){this.content=n,t.__super__.constructor.call(this,e,r,i,o)}return i(t,e),t.prototype.type="ImmutableObject",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&&(e.origin=this.origin().getUid()),e},t}(l),u.ImmutableObject=function(e){var t,n,r,i,s;return s=e.uid,t=e.content,i=e.prev,n=e.next,r=e.origin,new o(s,t,i,n,r)},r=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 i(t,e),t.prototype.type="Delimiter",t.prototype.applyDelete=function(){var e;for(t.__super__.applyDelete.call(this),e=this.next_cl;null!=e;)e.applyDelete(),e=e.next_cl;return void 0},t.prototype.cleanup=function(){return t.__super__.cleanup.call(this)},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}(l),u.Delimiter=function(e){var t,n,i;return i=e.uid,n=e.prev,t=e.next,new r(i,n,t)},{types:{Delete:t,Insert:s,Delimiter:r,Operation:l,ImmutableObject:o},parser:u,execution_listener:a}}},{}],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},o=[].slice;n=e("./TextTypes"),t.exports=function(e){var t,r,s,l,a;return l=n(e),a=l.types,s=l.parser,r=function(e){var n;return n=function(){function e(n){var i,o,s,l;l=n.map,s=function(i,o){return Object.defineProperty(e.prototype,i,{get:function(){var e;return e=o.val(),e instanceof t?r(e):e instanceof a.ImmutableObject?e.val():e},set:function(e){var t,r,o,s;if(o=n.val(i),e.constructor==={}.constructor&&o instanceof a.Operation){s=[];for(t in e)r=e[t],s.push(o.val(t,r,"immutable"));return s}return n.val(i,e,"immutable")},enumerable:!0,configurable:!1})};for(i in l)o=l[i],s(i,o)}return e}(),new n(e)},t=function(t){function n(e,t,r){var i,o;if(n.__super__.constructor.call(this,e),null!=t){if("object"!=typeof t)throw new Error("The initial value of JsonTypes must be of type Object! (current type: "+typeof t+")");for(i in t)o=t[i],this.val(i,o,r)}}return i(n,t),n.prototype.type="JsonType",n.prototype.applyDelete=function(){return n.__super__.applyDelete.call(this)},n.prototype.cleanup=function(){return n.__super__.cleanup.call(this)},n.prototype.toJson=function(){var e,t,n,r;r=this.val(),e={};for(t in r)if(n=r[t],null===n)e[t]=n;else if(n.constructor==={}.constructor)e[t]=this.val(t).toJson();else if(n instanceof a.Operation){for(;n instanceof a.Operation;)n=n.val();e[t]=n}else e[t]=n;return e},n.prototype.setReplaceManager=function(e){return this.replace_manager=e,this.on(["change","addProperty"],function(){var t;return null!=e.parent?(t=e.parent).forwardEvent.apply(t,[this].concat(o.call(arguments))):void 0})},n.prototype.getParent=function(){return this.replace_manager.parent},n.prototype.mutable_default=!0,n.prototype.setMutableDefault=function(e){if(e===!0||"mutable"===e)n.prototype.mutable_default=!0;else{if(e!==!1&&"immutable"!==e)throw new Error('Set mutable either "mutable" or "immutable"!');n.prototype.mutable_default=!1}return"OK"},n.prototype.val=function(t,r,i){var o,s,l;if("object"==typeof t)return o=new n(void 0,t,r),e.addOperation(o).execute(),this.replace_manager.replace(o),this;if(null!=t&&arguments.length>1){if(i=null!=i?i===!0||"mutable"===i?!0:!1:this.mutable_default,"function"==typeof r)return this;if(null!=r&&(i&&"number"!=typeof r||r.constructor===Object)){if("string"==typeof r)return l=e.addOperation(new a.WordType(void 0)).execute(),l.insertText(0,r),n.__super__.val.call(this,t,l);if(r.constructor===Object)return o=e.addOperation(new n(void 0,r,i)).execute(),n.__super__.val.call(this,t,o);throw new Error("You must not set "+typeof r+"-types in collaborative Json-objects!")}return s=e.addOperation(new a.ImmutableObject(void 0,r)).execute(),n.__super__.val.call(this,t,s)}return n.__super__.val.call(this,t,r)},Object.defineProperty(n.prototype,"value",{get:function(){return r(this)},set:function(e){var t,n,r;if(e.constructor==={}.constructor){r=[];for(t in e)n=e[t],r.push(this.val(t,n,"immutable"));return r}throw new Error("You must only set Object values!")}}),n.prototype._encode=function(){return{type:"JsonType",uid:this.getUid()}},n}(a.MapManager),s.JsonType=function(e){var n;return n=e.uid,new t(n)},a.JsonType=t,l}},{"./TextTypes":7}],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("./BasicTypes"),t.exports=function(e){var t,r,o,s,l,a,u,p;return a=n(e),p=a.types,u=a.parser,o=function(n){function r(e){this.map={},r.__super__.constructor.call(this,e)}return i(r,n),r.prototype.type="MapManager",r.prototype.applyDelete=function(){var e,t,n;n=this.map;for(e in n)t=n[e],t.applyDelete();return r.__super__.applyDelete.call(this)},r.prototype.cleanup=function(){return r.__super__.cleanup.call(this)},r.prototype.val=function(n,i){var o,s,l,a,u;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!=(a=this.map[n])?a.val():void 0,s instanceof p.ImmutableObject?s.val():s;l={},u=this.map;for(n in u)o=u[n],s=o.val(),(s instanceof p.ImmutableObject||s instanceof r)&&(s=s.val()),l[n]=s;return l},r}(p.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.type="AddName",n.prototype.applyDelete=function(){return n.__super__.applyDelete.call(this)},n.prototype.cleanup=function(){return n.__super__.cleanup.call(this)},n.prototype.execute=function(){var t,r,i,o,l,a;return this.validateSavedOperations()?(l=this.map_manager.getUid(),l.op_number="_"+l.op_number+"_RM_"+this.name,null==e.getOperation(l)&&(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 p.Delimiter(i,void 0,o)).execute(),r=e.addOperation(new p.Delimiter(o,t,void 0)).execute(),this.map_manager.map[this.name]=e.addOperation(new s(void 0,l,t,r)),this.map_manager.map[this.name].setParent(this.map_manager,this.name),(null!=(a=this.map_manager.map[this.name]).add_name_ops?a.add_name_ops:a.add_name_ops=[]).push(this),this.map_manager.map[this.name].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}(p.Operation),u.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,l){null!=r&&null!=i?(this.saveOperation("beginning",r),this.saveOperation("end",i)):(this.beginning=e.addOperation(new p.Delimiter(void 0,void 0,void 0)),this.end=e.addOperation(new p.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,l)}return i(n,t),n.prototype.type="ListManager",n.prototype.execute=function(){return this.validateSavedOperations()?(this.beginning.setParent(this),this.end.setParent(this),n.__super__.execute.apply(this,arguments)):!1},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||t.isDeleted())&&!(t instanceof p.Delimiter)){for(;t.isDeleted()&&!(t instanceof p.Delimiter);)t=t.next_cl;for(;;){if(t instanceof p.Delimiter)break;if(0>=e&&!t.isDeleted())break;t=t.next_cl,t.isDeleted()||(e-=1)}}return t},n}(p.Operation),s=function(t){function n(e,t,r,i,o,s,l){n.__super__.constructor.call(this,t,r,i,o,s,l),null!=e&&this.replace(e)}return i(n,t),n.prototype.type="ReplaceManager",n.prototype.applyDelete=function(){var e,t,r,i;for(e=this.beginning;null!=e;)e.applyDelete(),e=e.next_cl;if(null!=this.add_name_ops)for(i=this.add_name_ops,t=0,r=i.length;r>t;t++)e=i[t],e.applyDelete();return n.__super__.applyDelete.call(this)},n.prototype.cleanup=function(){return n.__super__.cleanup.call(this)},n.prototype.replace=function(t,n){var r,i;return r=this.getLastOperation(),i=new l(t,this,n,r,r.next_cl),e.addOperation(i).execute(),void 0},n.prototype.setParent=function(e,t){var r,i;return i=this,this.on("insert",function(e,n){return n.next_cl instanceof p.Delimiter?i.parent.callEvent("change",t,n):void 0}),this.on("change",function(e,n){return i!==this?i.parent.callEvent("change",t,n):void 0}),r=function(e,n){return i.deleteListener("addProperty",r),i.parent.callEvent("addProperty",t,n)},this.on("insert",r),n.__super__.setParent.call(this,e)},n.prototype.val=function(){var e;return e=this.getLastOperation(),"function"==typeof e.val?e.val():void 0},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&&(e.origin=this.origin().getUid()),e},n}(r),u.ReplaceManager=function(e){var t,n,r,i,o,l,a;return n=e.content,a=e.uid,l=e.prev,i=e.next,o=e.origin,t=e.beginning,r=e.end,new s(n,a,t,r,l,i,o)},l=function(e){function t(e,n,r,i,o,s){if(this.saveOperation("content",e),this.saveOperation("parent",n),null==i||null==o)throw new Error("You must define prev, and next for Replaceable-types!");t.__super__.constructor.call(this,r,i,o,s)}return i(t,e),t.prototype.type="Replaceable",t.prototype.val=function(){return this.content},t.prototype.replace=function(e){return this.parent.replace(e)},t.prototype.applyDelete=function(){return null!=this.content&&(this.content.applyDelete(),this.content.dontSync()),this.content=null,t.__super__.applyDelete.apply(this,arguments)},t.prototype.cleanup=function(){return t.__super__.cleanup.apply(this,arguments)},t.prototype.execute=function(){var e,n;return this.validateSavedOperations()?(null!=(n=this.content)&&"function"==typeof n.setReplaceManager&&n.setReplaceManager(this.parent),e=t.__super__.execute.call(this,null!=this.content),e&&("Delimiter"===this.next_cl.type&&"Delimiter"!==this.prev_cl.type?this.prev_cl.applyDelete():"Delimiter"!==this.next_cl.type&&this.applyDelete()),e):!1},t.prototype._encode=function(){var e,t;return e={type:"Replaceable",content:null!=(t=this.content)?t.getUid():void 0,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}(p.Insert),u.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 l(t,i,s,o,n,r)},p.ListManager=r,p.MapManager=o,p.ReplaceManager=s,p.Replaceable=l,a}},{"./BasicTypes":4}],7:[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,l,a;return l=n(e),a=l.types,s=l.parser,t=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return i(t,e),t}(a.Delete),s.TextDelete=s.Delete,r=function(e){function t(e,n,r,i,o){if(null!=(null!=e?e.creator:void 0)?this.saveOperation("content",e):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.type="TextInsert",t.prototype.getLength=function(){return this.isDeleted()?0:this.content.length},t.prototype.applyDelete=function(){return t.__super__.applyDelete.apply(this,arguments),this.content instanceof a.Operation&&this.content.applyDelete(),this.content=null},t.prototype.execute=function(){return this.validateSavedOperations()?(this.content instanceof a.Operation&&(this.content.insert_parent=this),t.__super__.execute.call(this)):!1},t.prototype.val=function(){return this.isDeleted()||null==this.content?"":this.content},t.prototype._encode=function(){var e,t;return e={type:"TextInsert",uid:this.getUid(),prev:this.prev_cl.getUid(),next:this.next_cl.getUid()},e.content=null!=(null!=(t=this.content)?t.getUid:void 0)?this.content.getUid():this.content,this.origin!==this.prev_cl&&(e.origin=this.origin.getUid()),e},t}(a.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.type="WordType",o.prototype.applyDelete=function(){var e;for(e=this.beginning;null!=e;)e.applyDelete(),e=e.next_cl;return o.__super__.applyDelete.call(this)},o.prototype.cleanup=function(){return o.__super__.cleanup.call(this)},o.prototype.push=function(e){return this.insertAfter(this.end.prev_cl,e)},o.prototype.insertAfter=function(t,n){for(var i,o,s,l,a;t.isDeleted();)t=t.prev_cl;if(s=t.next_cl,null!=n.type)o=new r(n,void 0,t,s),e.addOperation(o).execute();else for(l=0,a=n.length;a>l;l++)i=n[l],o=new r(i,void 0,t,s),e.addOperation(o).execute(),t=o;return this},o.prototype.insertText=function(e,t){var n,r;return n=this.getOperationByPosition(e),r=n.prev_cl,this.insertAfter(r,t)},o.prototype.deleteText=function(n,r){var i,o,s,l,u;for(l=this.getOperationByPosition(n),o=[],s=u=0;(r>=0?r>u:u>r)&&!(l instanceof a.Delimiter);s=r>=0?++u:--u){for(i=e.addOperation(new t(void 0,l)).execute(),l=l.next_cl;!(l instanceof a.Delimiter)&&l.isDeleted();)l=l.next_cl;o.push(i._encode())}return this},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),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],null!=t.val?i.push(t.val()):i.push("");return i}.call(this),e.join("")},o.prototype.toString=function(){return this.val()},o.prototype.setReplaceManager=function(e){return this.saveOperation("replace_manager",e),this.validateSavedOperations(),this.on("insert",function(e){return function(t,n){var r;return null!=(r=e.replace_manager)?r.forwardEvent(e,"change",n):void 0}}(this)),this.on("delete",function(e){return function(t,n,r){var i;return null!=(i=e.replace_manager)?i.forwardEvent(e,"change",r):void 0}}(this))},o.prototype.bind=function(e){var t;return t=this,e.value=this.val(),this.on("insert",function(n,r){var i,o,s,l;return s=r.getPosition(),i=function(e){return s>=e?e:e+=1},o=i(e.selectionStart),l=i(e.selectionEnd),e.value=t.val(),e.setSelectionRange(o,l)}),this.on("delete",function(n,r){var i,o,s,l;return s=r.getPosition(),i=function(e){return s>e?e:e-=1},o=i(e.selectionStart),l=i(e.selectionEnd),e.value=t.val(),e.setSelectionRange(o,l)}),e.onkeypress=function(n){var r,i,o,s;return r=null,r=null!=n.key?32===n.charCode?" ":13===n.keyCode?"\n":n.key:String.fromCharCode(n.keyCode),r.length>0?(s=Math.min(e.selectionStart,e.selectionEnd),i=Math.abs(e.selectionEnd-e.selectionStart),t.deleteText(s,i),t.insertText(s,r),o=s+r.length,e.setSelectionRange(o,o),n.preventDefault()):n.preventDefault()},e.onpaste=function(e){return e.preventDefault()},e.oncut=function(e){return e.preventDefault()},e.onkeydown=function(n){var r,i,o,s,l;if(s=Math.min(e.selectionStart,e.selectionEnd),i=Math.abs(e.selectionEnd-e.selectionStart),null!=n.keyCode&&8===n.keyCode){if(i>0)t.deleteText(s,i),e.setSelectionRange(s,s);else if(null!=n.ctrlKey&&n.ctrlKey){for(l=e.value,o=s,r=0,s>0&&(o--,r++);o>0&&" "!==l[o]&&"\n"!==l[o];)o--,r++;t.deleteText(o,s-o),e.setSelectionRange(o,o)}else t.deleteText(s-1,1);return n.preventDefault()}return null!=n.keyCode&&46===n.keyCode?(i>0?(t.deleteText(s,i),e.setSelectionRange(s,s)):(t.deleteText(s,1),e.setSelectionRange(s,s)),n.preventDefault()):void 0}},o.prototype._encode=function(){var e;return e={type:"WordType",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&&(e.origin=this.origin().getUid()),e},o}(a.ListManager),s.WordType=function(e){var t,n,r,i,s,l;return l=e.uid,t=e.beginning,n=e.end,s=e.prev,r=e.next,i=e.origin,new o(l,t,n,s,r,i)},a.TextInsert=r,a.TextDelete=t,a.WordType=o,l}},{"./StructuredTypes":6}],8:[function(e,t){var n,r,i,o,s={}.hasOwnProperty,l=function(e,t){function n(){this.constructor=e}for(var r in t)s.call(t,r)&&(e[r]=t[r]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e};r=e("./JsonTypes"),i=!1,n=function(e){var t;i=!0;try{e()}catch(n){throw t=n,i=!1,new Error(t)}return i=!1},o=function(e,t){var r;return r=this[e],null!=r?this[e]=function(){var e,o,s;return i||(null!=(s=this._yatta)?s.isDeleted():void 0)?r.apply(this,arguments):(o=this,e=arguments,n(function(){return t.apply(o,e),r.apply(o,e)}))}:void 0},"undefined"!=typeof Element&&null!==Element&&(Element.prototype._proxy=o),t.exports=function(e){var t,i,s,a,u;return s=r(e),u=s.types,a=s.parser,i=function(r){function i(n,r,o,s,l){var a,p,c,h,d,_,f,y,v,g,m,x;if(this.tagname=r,this.xml=l,i.__super__.constructor.call(this,n),null!=(null!=(g=this.xml)?g._yatta:void 0)&&(p=new u.Delete(void 0,this.xml._yatta),e.addOperation(p).execute(),this.xml._yatta=null),null!=o&&null!=s)this.saveOperation("attributes",o),this.saveOperation("elements",s);else{if(null!=o||null!=s)throw new Error("Either define attribute and elements both, or none of them");this.attributes=new u.JsonType,this.attributes.setMutableDefault("immutable"),e.addOperation(this.attributes).execute(),this.elements=new u.WordType,this.elements.parent=this,e.addOperation(this.elements).execute()}if(null!=this.xml){for(this.tagname=this.xml.tagName,h=f=0,m=this.xml.attributes.length;m>=0?m>f:f>m;h=m>=0?++f:--f)a=l.attributes[h],this.attributes.val(a.name,a.value);for(x=this.xml.childNodes,y=0,v=x.length;v>y;y++)if(d=x[y],d.nodeType===d.TEXT_NODE)_=new t(void 0,d),e.addOperation(_).execute(),this.elements.push(_);else{if(d.nodeType!==d.ELEMENT_NODE)throw new Error("I don't know Node-type "+d.nodeType+"!!");c=new i(void 0,void 0,void 0,void 0,d),e.addOperation(c).execute(),this.elements.push(c)}this.setXmlProxy()}}return l(i,r),i.prototype.type="XmlType",i.prototype.applyDelete=function(e){return null==this.insert_parent||this.insert_parent.isDeleted()?(this.attributes.applyDelete(),this.elements.applyDelete(),i.__super__.applyDelete.apply(this,arguments)):this.insert_parent.applyDelete(e)
},i.prototype.cleanup=function(){return i.__super__.cleanup.call(this)},i.prototype.setXmlProxy=function(){var t,r,s,l,a;return this.xml._yatta=this,a=this,this.elements.on("insert",function(t,r){var i,o,s;if(r.creator!==e.getUserId()&&this===a.elements){for(i=r.content.val(),o=r.next_cl;null!=o&&o.isDeleted();)o=o.next_cl;return s=null,"Delimiter"!==o.type&&(s=o.val().val()),n(function(){return a.xml.insertBefore(i,s)})}}),this.elements.on("delete",function(t,r){var i,o;return i=r.deleted_by[0],null!=i&&i.creator!==e.getUserId()&&this===a.elements?(o=r.content.val(),n(function(){return a.xml.removeChild(o)})):void 0}),this.attributes.on(["addProperty","change"],function(t,r,i){return i.creator!==e.getUserId()&&this===a.attributes?n(function(){var e;return e=i.val().val(),null!=e?a.xml.setAttribute(r,i.val().val()):a.xml.removeAttribute(r)}):void 0}),t=function(e){var t;if(null==e)throw new Error("you must specify a parameter!");for(e=e._yatta,t=a.elements.beginning.next_cl;"Delimiter"!==t.type&&t.content!==e;)t=t.next_cl;return"Delimiter"===t.type?!1:t},r=function(n,r){var o,s,l,u,p,c;if(u=null,null!=r&&(u=t(r)),p=null,u)p=u.prev_cl;else for(p=this._yatta.elements.end.prev_cl;p.isDeleted();)p=p.prev_cl;if(l=null,n.nodeType===n.DOCUMENT_FRAGMENT_NODE){for(o=n.lastChild,c=[];null!=o;)s=new i(void 0,void 0,void 0,void 0,o),e.addOperation(s).execute(),a.elements.insertAfter(p,s),c.push(o=o.previousSibling);return c}return s=new i(void 0,void 0,void 0,void 0,n),e.addOperation(s).execute(),a.elements.insertAfter(p,s)},this.xml._proxy("insertBefore",r),this.xml._proxy("appendChild",r),this.xml._proxy("removeAttribute",function(e){return a.attributes.val(e,void 0)}),this.xml._proxy("setAttribute",function(e,t){return a.attributes.val(e,t)}),l=function(e){var t,n,r,i,o;if(t=!1,null!=e)for(i=0,o=this.length;o>i;i++)n=this[i],e===n&&(t=!0);return r=Array.prototype.join.call(this," "),null==e||t||(r+=" "+e),a.attributes.val("class",r)},o.call(this.xml.classList,"add",l),o.call(this.xml.classList,"remove",l),this.xml.__defineSetter__("className",function(e){return this.setAttribute("class",e)}),this.xml.__defineGetter__("className",function(){return a.attributes.val("class")}),this.xml.__defineSetter__("textContent",function(e){var t,n,r;for(t=a.xml.firstChild;null!=t;)n=t,t=t.nextSibling,a.xml.removeChild(n);return""!==e?(r=document.createTextNode(e),a.xml.appendChild(r)):void 0}),s=function(n){var r,i;if(i=t(n),!i)throw new Error("You are only allowed to delete existing (direct) child elements!");return r=new u.Delete(void 0,i),e.addOperation(r).execute(),n._yatta=null},this.xml._proxy("removeChild",s),this.xml._proxy("replaceChild",function(e,t){return r.call(this,e,t),s.call(this,t)})},i.prototype.val=function(e){var t,n,r,i,o,s,l;if(null==e&&(e=!1),"undefined"!=typeof document&&null!==document){if(null==this.xml||e){this.xml=document.createElement(this.tagname),n=this.attributes.val();for(r in n)l=n[r],null!=l&&(t=document.createAttribute(r),t.value=l,this.xml.setAttributeNode(t));for(i=this.elements.beginning.next_cl;"Delimiter"!==i.type;){if(o=i.content,!i.isDeleted()&&null!=i.content)if("XmlType"===o.type)this.xml.appendChild(o.val(e));else{if("TextNodeType"!==o.type)throw new Error("Internal structure cannot be transformed to dom");s=o.val(),this.xml.appendChild(s)}i=i.next_cl}}return this.setXmlProxy(),this.xml}},i.prototype.execute=function(){return i.__super__.execute.call(this)},i.prototype.getParent=function(){return this.parent},i.prototype._encode=function(){var e;return e={type:this.type,attributes:this.attributes.getUid(),elements:this.elements.getUid(),tagname:this.tagname,uid:this.getUid()}},i}(u.Insert),a.XmlType=function(e){var t,n,r,o;return o=e.uid,t=e.attributes,n=e.elements,r=e.tagname,new i(o,r,t,n,void 0)},t=function(t){function n(t,r){var i;null!=r._yatta&&(i=new u.Delete(void 0,r._yatta),e.addOperation(i).execute(),r._yatta=null),r._yatta=this,n.__super__.constructor.call(this,t,r)}return l(n,t),n.prototype.applyDelete=function(e){return null==this.insert_parent||this.insert_parent.isDeleted()?n.__super__.applyDelete.apply(this,arguments):this.insert_parent.applyDelete(e)},n.prototype.type="TextNodeType",n.prototype._encode=function(){var e;return e={type:this.type,uid:this.getUid(),content:this.content.textContent}},n}(u.ImmutableObject),a.TextNodeType=function(e){var n,r,i;return i=e.uid,n=e.content,r=document.createTextNode(n),new t(i,r)},u.XmlType=i,s}},{"./JsonTypes":5}]},{},[2]);