1 line
25 KiB
JavaScript
1 line
25 KiB
JavaScript
!function e(t,n,r){function i(s,p){if(!n[s]){if(!t[s]){var a="function"==typeof require&&require;if(!p&&a)return a(s,!0);if(o)return o(s,!0);throw new Error("Cannot find module '"+s+"'")}var l=n[s]={exports:{}};t[s][0].call(l.exports,function(e){var n=t[s][1][e];return i(n?n:e)},l,l.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,p,a;for(n=[],r=0,s=e.length;s>r;r++)t=e[r],n.push(this.parseOperation(t));for(i=0,p=n.length;p>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],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,p,a,l,u,c,h;this.HB=new r(e),l=o(this.HB),this.types=l.types,this.engine=new n(this.HB,l.parser),this.connector=new t(this.engine,this.HB,l.execution_listener,this),s=this.HB.addOperation(new this.types.Delimiter({creator:"_",op_number:"_beginning"},void 0,void 0)),p=this.HB.addOperation(new this.types.Delimiter({creator:"_",op_number:"_end"},s,void 0)),s.next_cl=p,s.execute(),p.execute(),a=new this.types.WordType({creator:"_",op_number:"_"},s,p),this.HB.addOperation(a).execute(),h={creator:"_",op_number:"RM"},u={creator:"_",op_number:"_RM_beginning"},c={creator:"_",op_number:"_RM_end"},i=this.HB.addOperation(new this.types.Delimiter(u,void 0,c)).execute(),p=this.HB.addOperation(new this.types.Delimiter(c,i,void 0)).execute(),this.root_element=this.HB.addOperation(new this.types.ReplaceManager(void 0,h,i,p)).execute(),this.root_element.replace(a,{creator:"_",op_number:"Replaceable"})}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.getUserId=function(){return this.HB.getUserId()},e.prototype.val=function(){return this.getSharedObject().val()},e.prototype.insertText=function(e,t){return this.getSharedObject().insertText(e,t)},e.prototype.deleteText=function(e,t){return this.getSharedObject().deleteText(e,t)},e.prototype.bind=function(e){return this.getSharedObject().bind(e)},e.prototype.replaceText=function(e){return this.getSharedObject().replaceText(e)},e.prototype.on=function(){var e;return(e=this.root_element).on.apply(e,arguments)},e}(),t.exports=i,"undefined"!=typeof window&&null!==window&&(null==window.Y&&(window.Y={}),window.Y.TextFramework=i)},{"../Engine":1,"../HistoryBuffer":3,"../Types/TextTypes":6}],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=[],void(-1!==this.garbageCollectTimeout&&(this.garbageCollectTimeoutId=setTimeout(this.emptyGarbage,this.garbageCollectTimeout)))},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],r.push(null!=e?this.garbage.push(e):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++}},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,p,a,l,u;null==e&&(e={}),t=[],a=function(t,n){if(null==t||null==n)throw new Error("dah!");return null==e[t]||e[t]<=n},u=this.buffer;for(p in u){l=u[p];for(o in l)if(n=l[o],n.doSync&&a(p,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,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,p,a,l;return l={},a=[],p=function(){function t(t){this.is_deleted=!1,this.doSync=!0,this.garbage_collected=!1,null!=t?this.doSync=!isNaN(parseInt(t.op_number)):t=e.getNextOperationIdentifier(),this.creator=t.creator,this.op_number=t.op_number}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],s.push(null!=(null!=(o=this.event_listeners)?o[n]:void 0)?this.event_listeners[n]=this.event_listeners[n].filter(function(e){return t!==e}):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,p,a,l;if(i=arguments[0],t=arguments[1],e=3<=arguments.length?n.call(arguments,2):[],null!=(null!=(p=this.event_listeners)?p[t]:void 0)){for(a=this.event_listeners[t],l=[],o=0,s=a.length;s>o;o++)r=a[o],l.push(r.call.apply(r,[i,t].concat(n.call(e))));return l}},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])(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}(p),l.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;return null==this.deleted_by&&(this.deleted_by=[]),null==this.parent||this.isDeleted()||this.parent.callEvent("delete",this),null!=e&&this.deleted_by.push(e),n=!1,this.prev_cl.isDeleted()&&(n=!0),t.__super__.applyDelete.call(this,n),this.next_cl.isDeleted()?this.next_cl.applyDelete():void 0},t.prototype.cleanup=function(){var e,n,r,i,o;if(this.prev_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)}},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,i,o;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.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 i=null!=(o=this.prev_cl)?o.getParent():void 0,null!=i&&(this.setParent(i),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}(p),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}(p),l.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}(p),l.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:p,ImmutableObject:o},parser:l,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};n=e("./BasicTypes"),t.exports=function(e){var t,r,o,s,p,a,l,u;return a=n(e),u=a.types,l=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,p,a,l;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 u.ImmutableObject?s.val():s;p={},l=this.map;for(n in l)o=l[n],s=o.val(),(s instanceof u.ImmutableObject||s instanceof r)&&(s=s.val()),p[n]=s;return p},r}(u.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,p,a;return this.validateSavedOperations()?(p=this.map_manager.getUid(),p.op_number="_"+p.op_number+"_RM_"+this.name,null==e.getOperation(p)&&(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 u.Delimiter(i,void 0,o)).execute(),r=e.addOperation(new u.Delimiter(o,t,void 0)).execute(),this.map_manager.map[this.name]=e.addOperation(new s(void 0,p,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}(u.Operation),l.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,p){null!=r&&null!=i?(this.saveOperation("beginning",r),this.saveOperation("end",i)):(this.beginning=e.addOperation(new u.Delimiter(void 0,void 0,void 0)),this.end=e.addOperation(new u.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,p)}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 u.Delimiter)){for(;t.isDeleted()&&!(t instanceof u.Delimiter);)t=t.next_cl;for(;;){if(t instanceof u.Delimiter)break;if(0>=e&&!t.isDeleted())break;t=t.next_cl,t.isDeleted()||(e-=1)}}return t},n}(u.Operation),s=function(t){function n(e,t,r,i,o,s,p){n.__super__.constructor.call(this,t,r,i,o,s,p),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 p(t,this,n,r,r.next_cl),void e.addOperation(i).execute()},n.prototype.setParent=function(e,t){var r;return this.on("insert",function(e){return function(n,r){return r.next_cl instanceof u.Delimiter?e.parent.callEvent("change",t):void 0}}(this)),this.on("change",function(e){return function(){return e.parent.callEvent("change",t)}}(this)),r=function(e){return function(n,i){return i.next_cl instanceof u.Delimiter&&i.prev_cl instanceof u.Delimiter&&e.parent.callEvent("addProperty",t),e.deleteListener("addProperty",r)}}(this),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),l.ReplaceManager=function(e){var t,n,r,i,o,p,a;return n=e.content,a=e.uid,p=e.prev,i=e.next,o=e.origin,t=e.beginning,r=e.end,new s(n,a,t,r,p,i,o)},p=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.beforeDelete=this.content,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),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}(u.Insert),l.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 p(t,i,s,o,n,r)},u.ListManager=r,u.MapManager=o,u.ReplaceManager=s,u.Replaceable=p,a}},{"./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,p,a;return p=n(e),a=p.types,s=p.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(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 this.content=null,t.__super__.applyDelete.apply(this,arguments)},t.prototype.val=function(){return this.isDeleted()||null==this.content?"":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()},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.insertText=function(t,n){var i,o,s,p,a,l,u;for(o=this.getOperationByPosition(t),s=o.prev_cl;s.isDeleted();)s=s.prev_cl;for(a=s.next_cl,l=0,u=n.length;u>l;l++)i=n[l],p=new r(i,void 0,s,a),e.addOperation(p).execute(),s=p;return this},o.prototype.deleteText=function(n,r){var i,o,s,p,l;for(p=this.getOperationByPosition(n),o=[],s=l=0;(r>=0?r>l:l>r)&&!(p instanceof a.Delimiter);s=r>=0?++l:--l){for(i=e.addOperation(new t(void 0,p)).execute(),p=p.next_cl;!(p instanceof a.Delimiter)&&p.isDeleted();)p=p.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],i.push(null!=t.val?t.val():"");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","delete"],function(e){return function(){var t;return null!=(t=e.replace_manager)?t.callEvent("change"):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,p;return s=r.getPosition(),i=function(e){return s>=e?e:e+=1},o=i(e.selectionStart),p=i(e.selectionEnd),e.value=t.val(),e.setSelectionRange(o,p)}),this.on("delete",function(n,r){var i,o,s,p;return s=r.getPosition(),i=function(e){return s>e?e:e-=1},o=i(e.selectionStart),p=i(e.selectionEnd),e.value=t.val(),e.setSelectionRange(o,p)}),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,p;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(p=e.value,o=s,r=0,s>0&&(o--,r++);o>0&&" "!==p[o]&&"\n"!==p[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,p;return p=e.uid,t=e.beginning,n=e.end,s=e.prev,r=e.next,i=e.origin,new o(p,t,n,s,r,i)},a.TextInsert=r,a.TextDelete=t,a.WordType=o,p}},{"./StructuredTypes":5}]},{},[2]); |