yjs/yatta-element.js
2015-01-12 17:01:20 +00:00

2 lines
32 KiB
JavaScript

!function e(t,n,r){function i(s,u){if(!n[s]){if(!t[s]){var l="function"==typeof require&&require;if(!u&&l)return l(s,!0);if(o)return o(s,!0);throw new Error("Cannot find module '"+s+"'")}var p=n[s]={exports:{}};t[s][0].call(p.exports,function(e){var n=t[s][1][e];return i(n?n:e)},p,p.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(e,t,n,r){var i,o,s,u,l,p;return p=function(t){return t.uid.creator===n.getUserId()&&"string"!=typeof t.uid.op_number?e.broadcast(t):void 0},null!=e.invokeSync&&n.setInvokeSyncHandler(e.invokeSync),r.push(p),o=function(e){var t,n,r;r=[];for(t in e)n=e[t],r.push({user:t,state:n});return r},s=function(e){var t,n,r,i;for(n={},r=0,i=e.length;i>r;r++)t=e[r],n[t.user]=t.state;return n},l=function(){return o(n.getOperationCounter())},u=function(e){var t,r;return r=s(e),t={hb:n._encode(r),state_vector:o(n.getOperationCounter())}},i=function(e){return n.renewStateVector(s(e.state_vector)),t.applyOpsCheckDouble(e.hb)},e.whenSyncing(l,u,i),e.whenReceiving(function(e,r){return r.uid.creator!==n.getUserId()?t.applyOp(r):void 0}),null!=e._whenBoundToYatta?e._whenBoundToYatta():void 0},t.exports=n},{}],2:[function(e,t){var n;"undefined"!=typeof window&&null!==window&&(window.unprocessed_counter=0),"undefined"!=typeof window&&null!==window&&(window.unprocessed_exec_counter=0),"undefined"!=typeof window&&null!==window&&(window.unprocessed_types=[]),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.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){return this.applyOp(e)},e.prototype.applyOp=function(e){var t,n,r,i;for(e.constructor!==Array&&(e=[e]),r=0,i=e.length;i>r;r++)n=e[r],t=this.parseOperation(n),null!=this.HB.getOperation(t)||this.HB.isExpectedOperation(t)&&t.execute()||(this.unprocessed_ops.push(t),"undefined"!=typeof window&&null!==window&&window.unprocessed_types.push(t.type));return this.tryUnprocessed()},e.prototype.tryUnprocessed=function(){for(var e,t,n,r,i,o;;){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)||this.HB.isExpectedOperation(t)&&t.execute()||n.push(t);if(this.unprocessed_ops=n,this.unprocessed_ops.length===e)break}return 0!==this.unprocessed_ops.length?this.HB.invokeSync():void 0},e}(),t.exports=n},{}],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=2e4,this.reserved_identifier_counter=0,setTimeout(this.emptyGarbage,this.garbageCollectTimeout)}return e.prototype.resetUserId=function(e){var t,n,r;if(r=this.buffer[this.user_id],null!=r){for(n in r)t=r[n],t.uid.creator=e;if(null!=this.buffer[e])throw new Error("You are re-assigning an old user id - this is not (yet) possible!");this.buffer[e]=r,delete this.buffer[this.user_id]}return this.operation_counter[e]=this.operation_counter[this.user_id],delete this.operation_counter[this.user_id],this.user_id=e},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.isExpectedOperation=function(e){var t,n;return null==(t=this.operation_counter)[n=e.uid.creator]&&(t[n]=0),e.uid.op_number<=this.operation_counter[e.uid.creator]},e.prototype._encode=function(e){var t,n,r,i,o,s,u,l,p,a;null==e&&(e={}),t=[],l=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){p=a[u];for(o in p)if(n=p[o],n.uid.doSync&&l(u,o)){if(r=n._encode(),null!=n.next_cl){for(i=n.next_cl;null!=i.next_cl&&l(i.uid.creator,i.uid.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&&l(s.uid.creator,s.uid.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],doSync:!0},this.operation_counter[e]++,t},e.prototype.getOperation=function(e){var t;return null!=e.uid&&(e=e.uid),null!=(t=this.buffer[e.creator])?t[e.op_number]:void 0},e.prototype.addOperation=function(e){if(null==this.buffer[e.uid.creator]&&(this.buffer[e.uid.creator]={}),null!=this.buffer[e.uid.creator][e.uid.op_number])throw new Error("You must not overwrite operations!");if(e.uid.op_number.constructor!==String&&!this.isExpectedOperation(e))throw new Error("this operation was not expected!");return this.addToCounter(e),this.buffer[e.uid.creator][e.uid.op_number]=e,e},e.prototype.removeOperation=function(e){var t;return null!=(t=this.buffer[e.uid.creator])?delete t[e.uid.op_number]:void 0},e.prototype.setInvokeSyncHandler=function(e){return this.invokeSync=e},e.prototype.invokeSync=function(){},e.prototype.renewStateVector=function(e){var t,n,r;r=[];for(n in e)t=e[n],null==this.operation_counter[n]||this.operation_counter[n]<e[n]?r.push(this.operation_counter[n]=e[n]):r.push(void 0);return r},e.prototype.addToCounter=function(e){return null==this.operation_counter[e.uid.creator]&&(this.operation_counter[e.uid.creator]=0),"number"==typeof e.uid.op_number&&e.uid.creator!==this.getUserId()?e.uid.op_number===this.operation_counter[e.uid.creator]?this.operation_counter[e.uid.creator]++:this.invokeSync(e.uid.creator):void 0},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,u,l,p;return p={},l=[],u=function(){function t(e){this.is_deleted=!1,this.garbage_collected=!1,this.event_listeners=[],null!=e&&(this.uid=e)}return t.prototype.type="Operation",t.prototype.observe=function(e){return this.event_listeners.push(e)},t.prototype.unobserve=function(e){return this.event_listeners=this.event_listeners.filter(function(t){return e!==t})},t.prototype.deleteAllObservers=function(){return this.event_listeners=[]},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,u;for(r=arguments[0],e=2<=arguments.length?n.call(arguments,1):[],s=this.event_listeners,u=[],i=0,o=s.length;o>i;i++)t=s[i],u.push(t.call.apply(t,[r].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),this.deleteAllObservers()},t.prototype.setParent=function(e){this.parent=e},t.prototype.getParent=function(){return this.parent},t.prototype.getUid=function(){return this.uid},t.prototype.dontSync=function(){return this.uid.doSync=!1},t.prototype.execute=function(){var t,n,r;for(this.is_executed=!0,null==this.uid&&(this.uid=e.getNextOperationIdentifier()),e.addOperation(this),n=0,r=l.length;r>n;n++)t=l[n],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 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(){var e;return this.validateSavedOperations()?(e=t.__super__.execute.apply(this,arguments),e&&this.deletes.applyDelete(this),e):!1},t}(u),p.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()||null==e||(n=!0),null!=e&&this.deleted_by.push(e),r=!1,this.next_cl.isDeleted()&&(r=!0),t.__super__.applyDelete.call(this,r),n&&this.callOperationSpecificDeleteEvents(e),(null!=(i=this.prev_cl)?i.isDeleted():void 0)?this.prev_cl.applyDelete():void 0},t.prototype.cleanup=function(){var e,n,r,i,o;if(this.next_cl.isDeleted()){for(o=this.deleted_by,r=0,i=o.length;i>r;r++)e=o[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)}if(null!=this.next_cl&&null!=this.prev_cl)throw new Error("This insertion was not supposed to be deleted!")},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(){var e,n,r;if(this.validateSavedOperations()){if(null!=this.prev_cl){for(e=this.getDistanceToOrigin(),r=this.prev_cl.next_cl,n=e;;){if(r===this.next_cl)break;if(r.getDistanceToOrigin()===n)r.uid.creator<this.uid.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 this.setParent(this.prev_cl.getParent()),t.__super__.execute.apply(this,arguments),this.callOperationSpecificInsertEvents(),this}return!1},t.prototype.callOperationSpecificInsertEvents=function(){var e;return null!=(e=this.parent)?e.callEvent([{type:"insert",position:this.getPosition(),object:this.parent,changedBy:this.uid.creator,value:this.content}]):void 0},t.prototype.callOperationSpecificDeleteEvents=function(e){return this.parent.callEvent([{type:"delete",position:this.getPosition(),object:this.parent,length:1,changedBy:e.uid.creator}])},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}(u),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}(u),p.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.prev_cl;null!=e;)e.applyDelete(),e=e.prev_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,t.__super__.execute.apply(this,arguments)}return!1}return null!=this.prev_cl&&null==this.prev_cl.next_cl?(delete this.prev_cl.unchecked.next_cl,this.prev_cl.next_cl=this,t.__super__.execute.apply(this,arguments)):t.__super__.execute.apply(this,arguments)},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}(u),p.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:u,ImmutableObject:o},parser:p,execution_listener:l}}},{}],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("./TextTypes"),t.exports=function(e){var t,r,o,s,u;return s=n(e),u=s.types,o=s.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 u.ImmutableObject?e.val():e},set:function(e){var t,r,o,s;if(o=n.val(i),e.constructor==={}.constructor&&o instanceof u.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(){return n.__super__.constructor.apply(this,arguments)}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(t){var r,i,o,s,l;null==t&&(t=!1),l=this.val(),r={};for(i in l)o=l[i],r[i]=o instanceof n?o.toJson(t):t&&o instanceof u.Operation?o.val():o;return this.bound_json=r,null!=Object.observe&&(s=this,Object.observe(this.bound_json,function(e){var t,n,r,i;for(i=[],n=0,r=e.length;r>n;n++)t=e[n],null!=t.changedBy||"add"!==t.type&&!(t.type="update")?i.push(void 0):i.push(s.val(t.name,t.object[t.name]));return i}),this.observe(function(t){var n,r,i,o,u,l;for(l=[],o=0,u=t.length;u>o;o++)n=t[o],n.created_!==e.getUserId()?(r=Object.getNotifier(s.bound_json),i=s.bound_json[n.name],null!=i?(r.performChange("update",function(){return s.bound_json[n.name]=s.val(n.name)},s.bound_json),l.push(r.notify({object:s.bound_json,type:"update",name:n.name,oldValue:i,changedBy:n.changedBy}))):(r.performChange("add",function(){return s.bound_json[n.name]=s.val(n.name)},s.bound_json),l.push(r.notify({object:s.bound_json,type:"add",name:n.name,oldValue:i,changedBy:n.changedBy})))):l.push(void 0);return l})),this.bound_json},n.prototype.mutable_default=!1,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(e,t,r){var i,o,s,l;if(null!=e&&arguments.length>1){if(r=null!=r?r===!0||"mutable"===r?!0:!1:this.mutable_default,"function"==typeof t)return this;if(null!=t&&(r&&"number"!=typeof t||t.constructor===Object)){if("string"==typeof t)return l=new u.WordType(void 0).execute(),l.insertText(0,t),n.__super__.val.call(this,e,l);if(t.constructor===Object){i=(new n).execute();for(o in t)s=t[o],i.val(o,s,r);return n.__super__.val.call(this,e,i)}throw new Error("You must not set "+typeof t+"-types in collaborative Json-objects!")}return n.__super__.val.call(this,e,new u.ImmutableObject(void 0,t).execute())}return n.__super__.val.call(this,e,t)},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}(u.MapManager),o.JsonType=function(e){var n;return n=e.uid,new t(n)},u.JsonType=t,s}},{"./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,u,l,p,a;return l=n(e),a=l.types,p=l.parser,o=function(e){function n(e){this.map={},n.__super__.constructor.call(this,e)}return i(n,e),n.prototype.type="MapManager",n.prototype.applyDelete=function(){var e,t,r;r=this.map;for(e in r)t=r[e],t.applyDelete();return n.__super__.applyDelete.call(this)},n.prototype.cleanup=function(){return n.__super__.cleanup.call(this)},n.prototype.val=function(e,n){var r,i,o,s,u;if(null!=n)return null==this.map[e]&&new t(void 0,this,e).execute(),this.map[e].replace(n),this;if(null!=e)return o=this.map[e],null==o||o.isContentDeleted()?void 0:(i=o.val(),i instanceof a.ImmutableObject?i.val():i);s={},u=this.map;for(e in u)r=u[e],r.isContentDeleted()||(i=r.val(),i instanceof a.ImmutableObject&&(i=i.val()),s[e]=i);return s},n.prototype["delete"]=function(e){var t;return null!=(t=this.map[e])&&t.deleteContent(),this},n}(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.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,u,l,p,c,h;return this.validateSavedOperations()?(r=function(e){var t,n,r;n={};for(t in e)r=e[t],n[t]=r;return n},c=r(this.map_manager.getUid()),c.doSync=!1,c.op_number="_"+c.op_number+"_RM_"+this.name,null==e.getOperation(c)&&(l=r(c),l.op_number=""+c.op_number+"_beginning",p=r(c),p.op_number=""+c.op_number+"_end",t=new a.Delimiter(l,void 0,p).execute(),i=new a.Delimiter(p,t,void 0).execute(),o={name:this.name},u=this.map_manager,this.map_manager.map[this.name]=new s(o,u,c,t,i),this.map_manager.map[this.name].setParent(this.map_manager,this.name),(null!=(h=this.map_manager.map[this.name]).add_name_ops?h.add_name_ops:h.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}(a.Operation),p.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(e){function t(e,n,r,i,o,s){null!=n&&null!=r?(this.saveOperation("beginning",n),this.saveOperation("end",r)):(this.beginning=new a.Delimiter(void 0,void 0,void 0),this.end=new a.Delimiter(void 0,this.beginning,void 0),this.beginning.next_cl=this.end,this.beginning.execute(),this.end.execute()),t.__super__.constructor.call(this,e,i,o,s)}return i(t,e),t.prototype.type="ListManager",t.prototype.execute=function(){return this.validateSavedOperations()?(this.beginning.setParent(this),this.end.setParent(this),t.__super__.execute.apply(this,arguments)):!1},t.prototype.getLastOperation=function(){return this.end.prev_cl},t.prototype.getFirstOperation=function(){return this.beginning.next_cl},t.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},t.prototype.getOperationByPosition=function(e){var t;for(t=this.beginning;;){if(t instanceof a.Delimiter&&null!=t.prev_cl){for(t=t.prev_cl;t.isDeleted()||!(t instanceof a.Delimiter);)t=t.prev_cl;break}if(0>=e&&!t.isDeleted())break;t=t.next_cl,t.isDeleted()||(e-=1)}return t},t}(a.Operation),s=function(e){function t(e,n,r,i,o,s,u,l){this.event_properties=e,this.event_this=n,null==this.event_properties.object&&(this.event_properties.object=this.event_this),t.__super__.constructor.call(this,r,i,o,s,u,l)}return i(t,e),t.prototype.type="ReplaceManager",t.prototype.applyDelete=function(){var e,n,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,n=0,r=i.length;r>n;n++)e=i[n],e.applyDelete();return t.__super__.applyDelete.call(this)},t.prototype.cleanup=function(){return t.__super__.cleanup.call(this)},t.prototype.callEventDecorator=function(e){var t,n,r,i,o,s;if(!this.isDeleted()){for(i=0,o=e.length;o>i;i++){t=e[i],s=this.event_properties;for(n in s)r=s[n],t[n]=r}this.event_this.callEvent(e)}return void 0},t.prototype.replace=function(e,t){var n,r;return n=this.getLastOperation(),r=new u(e,this,t,n,n.next_cl).execute(),void 0},t.prototype.isContentDeleted=function(){return this.getLastOperation().isDeleted()},t.prototype.deleteContent=function(){return new a.Delete(void 0,this.getLastOperation().uid).execute(),void 0},t.prototype.val=function(){var e;return e=this.getLastOperation(),"function"==typeof e.val?e.val():void 0},t.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},t}(r),p.ReplaceManager=function(e){var t,n,r,i,o,u;return u=e.uid,o=e.prev,r=e.next,i=e.origin,t=e.beginning,n=e.end,new s(u,t,n,o,r,i)},u=function(e){function t(e,n,r,i,o,s,u){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),this.is_deleted=u}return i(t,e),t.prototype.type="Replaceable",t.prototype.val=function(){return this.content},t.prototype.applyDelete=function(){var e;return e=t.__super__.applyDelete.apply(this,arguments),null!=this.content&&("Delimiter"!==this.next_cl.type&&this.content.deleteAllObservers(),this.content.applyDelete(),this.content.dontSync()),this.content=null,e},t.prototype.cleanup=function(){return t.__super__.cleanup.apply(this,arguments)},t.prototype.callOperationSpecificInsertEvents=function(){var e;return"Delimiter"===this.next_cl.type&&"Delimiter"!==this.prev_cl.type?(this.is_deleted||(e=this.prev_cl.content,this.parent.callEventDecorator([{type:"update",changedBy:this.uid.creator,oldValue:e}])),this.prev_cl.applyDelete()):"Delimiter"!==this.next_cl.type?this.applyDelete():this.parent.callEventDecorator([{type:"add",changedBy:this.uid.creator}]),void 0},t.prototype.callOperationSpecificDeleteEvents=function(e){return"Delimiter"===this.next_cl.type?this.parent.callEventDecorator([{type:"delete",changedBy:e.uid.creator,oldValue:this.content}]):void 0},t.prototype._encode=function(){var e,t;return e={type:"Replaceable",content:null!=(t=this.content)?t.getUid():void 0,replace_manager:this.parent.getUid(),prev:this.prev_cl.getUid(),next:this.next_cl.getUid(),uid:this.getUid(),is_deleted:this.is_deleted},null!=this.origin&&this.origin!==this.prev_cl&&(e.origin=this.origin.getUid()),e},t}(a.Insert),p.Replaceable=function(e){var t,n,r,i,o,s,l;return t=e.content,o=e.replace_manager,l=e.uid,s=e.prev,r=e.next,i=e.origin,n=e.is_deleted,new u(t,o,l,s,r,i,n)},a.ListManager=r,a.MapManager=o,a.ReplaceManager=s,a.Replaceable=u,l}},{"./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,u,l;return u=n(e),l=u.types,s=u.parser,t=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return i(t,e),t}(l.Delete),s.TextDelete=s.Delete,r=function(e){function t(e,n,r,i,o){var s;if((null!=e?null!=(s=e.uid)?s.creator:void 0: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 l.Operation&&this.content.applyDelete(),this.content=null},t.prototype.execute=function(){return this.validateSavedOperations()?(this.content instanceof l.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}(l.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(e){function n(e,t,r,i,o,s){this.textfields=[],n.__super__.constructor.call(this,e,t,r,i,o,s)}return i(n,e),n.prototype.type="WordType",n.prototype.applyDelete=function(){var e;for(e=this.end;null!=e;)e.applyDelete(),e=e.prev_cl;return n.__super__.applyDelete.call(this)},n.prototype.cleanup=function(){return n.__super__.cleanup.call(this)},n.prototype.push=function(e){return this.insertAfter(this.end.prev_cl,e)},n.prototype.insertAfter=function(e,t){var n,i,o,s,u;for(i=e.next_cl;i.isDeleted();)i=i.next_cl;if(e=i.prev_cl,null!=t.type)new r(t,void 0,e,i).execute();else for(s=0,u=t.length;u>s;s++)n=t[s],o=new r(n,void 0,e,i).execute(),e=o;return this},n.prototype.insertText=function(e,t){var n;return n=this.getOperationByPosition(e),this.insertAfter(n,t)},n.prototype.deleteText=function(e,n){var r,i,o,s,u;for(s=this.getOperationByPosition(e+1),i=[],o=u=0;(n>=0?n>u:u>n)&&!(s instanceof l.Delimiter);o=n>=0?++u:--u){for(r=new t(void 0,s).execute(),s=s.next_cl;!(s instanceof l.Delimiter)&&s.isDeleted();)s=s.next_cl;i.push(r._encode())}return this},n.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("")},n.prototype.toString=function(){return this.val()},n.prototype.bind=function(e){var t;return t=this,e.value=this.val(),this.textfields.push(e),this.observe(function(n){var r,i,o,s,u,l,p,a;for(a=[],l=0,p=n.length;p>l;l++)r=n[l],"insert"===r.type?(s=r.position,i=function(e){return s>=e?e:e+=1},o=i(e.selectionStart),u=i(e.selectionEnd),e.value=t.val(),a.push(e.setSelectionRange(o,u))):"delete"===r.type?(s=r.position,i=function(e){return s>e?e:e-=1},o=i(e.selectionStart),u=i(e.selectionEnd),e.value=t.val(),a.push(e.setSelectionRange(o,u))):a.push(void 0);return a}),e.onkeypress=function(n){var r,i,o,s;return t.is_deleted?(e.onkeypress=null,!0):(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(n){return t.is_deleted?(e.onpaste=null,!0):n.preventDefault()},e.oncut=function(n){return t.is_deleted?(e.oncut=null,!0):n.preventDefault()},e.onkeydown=function(n){var r,i,o,s,u;if(t.is_deleted)return e.onkeydown=null,!0;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(u=e.value,o=s,r=0,s>0&&(o--,r++);o>0&&" "!==u[o]&&"\n"!==u[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}},n.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},n}(l.ListManager),s.WordType=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)},l.TextInsert=r,l.TextDelete=t,l.WordType=o,u}},{"./StructuredTypes":6}],8:[function(e){var t,n;t=e("./yatta"),n=function(e){var t,n,r,i;for(n=r=0,i=e.children.length;i>=0?i>r:r>i;n=i>=0?++r:--r)t=e.children.item(n),null!=t.name&&(t.val=e.val.val(t.name));return e.val.observe(function(r){var i,o,s,u,l;for(l=[],s=0,u=r.length;u>s;s++)i=r[s],null!=i.name?l.push(function(){var r,s,u;for(u=[],n=r=0,s=e.children.length;s>=0?s>r:r>s;n=s>=0?++r:--r)t=e.children.item(n),null!=t.name&&t.name===i.name?(o=e.val.val(t.name),t.val!==o?u.push(t.val=o):u.push(void 0)):u.push(void 0);return u}()):l.push(void 0);return l})},Polymer("yatta-element",{ready:function(){return null!=this.connector?(this.val=new t(this.connector),n(this)):null!=this.val?n(this):void 0},valChanged:function(){return null!=this.val&&"JsonType"===this.val.type?n(this):void 0},connectorChanged:function(){return null==this.val?(this.val=new t(this.connector),n(this)):void 0}}),Polymer("yatta-property",{ready:function(){return null!=this.val&&null!=this.name&&(this.val.constructor===Object?this.val=this.parentElement.val(this.name,this.val).val(this.name):"string"==typeof this.val&&this.parentElement.val(this.name,this.val),"JsonType"===this.val.type)?n(this):void 0},valChanged:function(){var e;if(null!=this.val&&null!=this.name){if(this.val.constructor===Object)return this.val=this.parentElement.val.val(this.name,this.val).val(this.name);if("JsonType"===this.val.type)return n(this);if(null!=(null!=(e=this.parentElement.val)?e.val:void 0)&&this.val!==this.parentElement.val.val(this.name))return this.parentElement.val.val(this.name,this.val)}}})},{"./yatta":9}],9:[function(e,t){var n,r,i,o,s,u={}.hasOwnProperty,l=function(e,t){function n(){this.constructor=e}for(var r in t)u.call(t,r)&&(e[r]=t[r]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e};s=e("./Types/JsonTypes"),r=e("./HistoryBuffer"),n=e("./Engine"),i=e("./ConnectorAdapter"),o=function(e){var t,o,u,p,a;return a=null,null!=e.id?a=e.id:(a="_temp",e.whenUserIdSet(function(e){return a=e,t.resetUserId(e)})),t=new r(a),u=s(t),p=u.types,o=function(r){function o(){this.connector=e,this.HB=t,this.types=p,this.engine=new n(this.HB,u.parser),i(this.connector,this.engine,this.HB,u.execution_listener),o.__super__.constructor.apply(this,arguments)
}return l(o,r),o.prototype.getConnector=function(){return this.connector},o}(p.JsonType),new o(t.getReservedUniqueIdentifier()).execute()},t.exports=o,"undefined"!=typeof window&&null!==window&&null==window.Yatta&&(window.Yatta=o)},{"./ConnectorAdapter":1,"./Engine":2,"./HistoryBuffer":3,"./Types/JsonTypes":5}]},{},[8]);