4 lines
44 KiB
JavaScript
4 lines
44 KiB
JavaScript
"use strict";function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(e.__proto__=t)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _flushOne(){var e=[];for(var t in globalRoom.buffers)globalRoom.buffers[t].length>0&&e.push(t);if(e.length>0){var r=getRandom(e),n=globalRoom.buffers[r].shift(),i=globalRoom.users[r];return i.receiveMessage(n[0],n[1]),!0}return!1}function copyObject(e){var t={};for(var r in e)t[r]=e[r];return t}function compareIds(e,t){return null==e||null==t?null==e&&null==t?!0:!1:e[0]===t[0]&&e[1]===t[1]?!0:!1}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();!function(e){function t(e,t,r,i){var a=Object.create((t||n).prototype);return a._invoke=c(e,r||null,new f(i||[])),a}function r(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(n){return{type:"throw",arg:n}}}function n(){}function i(){}function a(){}function s(e){["next","throw","return"].forEach(function(t){e[t]=function(e){return this._invoke(t,e)}})}function o(e){this.arg=e}function u(e){function t(t,r){var n=e[t](r),s=n.value;return s instanceof o?Promise.resolve(s.arg).then(i,a):Promise.resolve(s).then(function(e){return n.value=e,n},a)}function r(e,r){var i=n?n.then(function(){return t(e,r)}):new Promise(function(n){n(t(e,r))});return n=i["catch"](s),i}"object"==typeof process&&process.domain&&(t=process.domain.bind(t));var n,i=t.bind(e,"next"),a=t.bind(e,"throw"),s=t.bind(e,"return");this._invoke=r}function c(e,t,n){var i=k;return function(a,s){if(i===w)throw new Error("Generator is already running");if(i===R)return d();for(;;){var o=n.delegate;if(o){if("return"===a||"throw"===a&&o.iterator[a]===g){n.delegate=null;var u=o.iterator["return"];if(u){var c=r(u,o.iterator,s);if("throw"===c.type){a="throw",s=c.arg;continue}}if("return"===a)continue}var c=r(o.iterator[a],o.iterator,s);if("throw"===c.type){n.delegate=null,a="throw",s=c.arg;continue}a="next",s=g;var l=c.arg;if(!l.done)return i=x,l;n[o.resultName]=l.value,n.next=o.nextLoc,n.delegate=null}if("next"===a)i===x?n.sent=s:delete n.sent;else if("throw"===a){if(i===k)throw i=R,s;n.dispatchException(s)&&(a="next",s=g)}else"return"===a&&n.abrupt("return",s);i=w;var c=r(e,t,n);if("normal"===c.type){i=n.done?R:x;var l={value:c.arg,done:n.done};if(c.arg!==S)return l;n.delegate&&"next"===a&&(s=g)}else"throw"===c.type&&(i=R,a="throw",s=c.arg)}}}function l(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function p(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function f(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(l,this),this.reset()}function h(e){if(e){var t=e[y];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,n=function i(){for(;++r<e.length;)if(b.call(e,r))return i.value=e[r],i.done=!1,i;return i.value=g,i.done=!0,i};return n.next=n}}return{next:d}}function d(){return{value:g,done:!0}}var g,b=Object.prototype.hasOwnProperty,y="function"==typeof Symbol&&Symbol.iterator||"@@iterator",v="object"==typeof module,m=e.regeneratorRuntime;if(m)return void(v&&(module.exports=m));m=e.regeneratorRuntime=v?module.exports:{},m.wrap=t;var k="suspendedStart",x="suspendedYield",w="executing",R="completed",S={},O=a.prototype=n.prototype;i.prototype=O.constructor=a,a.constructor=i,i.displayName="GeneratorFunction",m.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return t?t===i||"GeneratorFunction"===(t.displayName||t.name):!1},m.mark=function(e){return e.__proto__=a,e.prototype=Object.create(O),e},m.awrap=function(e){return new o(e)},s(u.prototype),m.async=function(e,r,n,i){var a=new u(t(e,r,n,i));return m.isGeneratorFunction(r)?a:a.next().then(function(e){return e.done?e.value:a.next()})},s(O),O[y]=function(){return this},O.toString=function(){return"[object Generator]"},m.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},m.values=h,f.prototype={constructor:f,reset:function(){this.prev=0,this.next=0,this.sent=g,this.done=!1,this.delegate=null,this.tryEntries.forEach(p);for(var e,t=0;b.call(this,e="t"+t)||20>t;++t)this[e]=null},stop:function(){this.done=!0;var e=this.tryEntries[0],t=e.completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){function t(t,n){return a.type="throw",a.arg=e,r.next=t,!!n}if(this.done)throw e;for(var r=this,n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n],a=i.completion;if("root"===i.tryLoc)return t("end");if(i.tryLoc<=this.prev){var s=b.call(i,"catchLoc"),o=b.call(i,"finallyLoc");if(s&&o){if(this.prev<i.catchLoc)return t(i.catchLoc,!0);if(this.prev<i.finallyLoc)return t(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return t(i.catchLoc,!0)}else{if(!o)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return t(i.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&b.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?this.next=i.finallyLoc:this.complete(a),S},complete:function(e,t){if("throw"===e.type)throw e.arg;"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=e.arg,this.next="end"):"normal"===e.type&&t&&(this.next=t)},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),p(r),S}},"catch":function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;p(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:h(e),resultName:t,nextLoc:r},S}}}("object"==typeof global?global:"object"==typeof window?window:"object"==typeof self?self:void 0);var GeneratorFunction=regeneratorRuntime.mark(function e(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}},e,this)}).constructor,Y=function(){function e(t){_classCallCheck(this,e),this.db=new e[t.db.name](this,t.db),this.connector=new e[t.connector.name](this,t.connector),this.db.requestTransaction(regeneratorRuntime.mark(function r(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.delegateYield(this.addOperation({id:["_",0],struct:"Map",map:{}}),"t0",1);case 1:case"end":return e.stop()}},r,this)}))}return e.prototype.transact=function(e){if(e.constructor!==GeneratorFunction)throw new Error("y.transact requires a Generator function! E.g. function*(){/*..*/}");this.db.requestTransaction(e)},e.prototype.destroy=function(){this.connector.disconnect(),this.db.removeDatabase(),this.connector=null,this.db=null,this.transact=function(){throw new Error("Remember?, you destroyed this type ;)")}},e}();Y.AbstractTransaction=AbstractTransaction,Y.AbstractOperationStore=AbstractOperationStore,Y.Struct=Struct;var globalRoom={users:{},buffers:{},removeUser:function(e){for(var t in this.users)this.users[t].userLeft(e);delete this.users[e],delete this.buffers[e]},addUser:function(e){this.users[e.userId]=e,this.buffers[e.userId]=[];for(var t in this.users)if(t!==e.userId){var r=this.users[t];r.userJoined(e.userId,"master"),e.userJoined(r.userId,"master")}}},userIdCounter=0,Test=function(e){function t(r,n){if(_classCallCheck(this,t),void 0===n)throw new Error("Options must not be undefined!");n.role="master",n.forwardToSyncingClients=!1,e.call(this,r,n),this.setUserId(userIdCounter++ +""),globalRoom.addUser(this),this.globalRoom=globalRoom}return _inherits(t,e),t.prototype.send=function(e,t){globalRoom.buffers[e].push(JSON.parse(JSON.stringify([this.userId,t])))},t.prototype.broadcast=function(e){for(var t in globalRoom.buffers)globalRoom.buffers[t].push(JSON.parse(JSON.stringify([this.userId,e])))},t.prototype.disconnect=function(){globalRoom.removeUser(this.userId)},t.prototype.flushAll=function(){for(var e=!0;e;)e=_flushOne()},t.prototype.flushOne=function(){_flushOne()},t}(AbstractConnector);Y.Test=Test;var WebRTC=function(e){function t(r){if(_classCallCheck(this,t),void 0===r)throw new Error("Options must not be undefined!");e.call(this,{role:"slave"});var n=r.room;null==r.url&&(r.url="https://yatta.ninja:8888");var i=new SimpleWebRTC(r);this.swr=i;var a=this;i.once("connectionReady",function(e){i.joinRoom(n),i.once("joinedRoom",function(){a.setUserId(e);var t;for(t in a.swr.webrtc.peers)a.userJoined(a.swr.webrtc.peers[t].id,"master");i.on("channelMessage",function(e,t,r){null!=r.type&&a.receiveMessage(e.id,r.payload)})}),i.on("createdPeer",function(e){a.userJoined(e.id,"master")}),i.on("peerStreamRemoved",function(e){a.userLeft(e.id)})})}return _inherits(t,e),t.prototype.send=function r(e,t){var n=this,r=function i(){var r,a=n.swr.webrtc.getPeers(e)[0];a&&(r=a.sendDirectly("simplewebrtc","yjs",t)),r||setTimeout(i,500)};r()},t.prototype.broadcast=function(e){this.swr.sendDirectlyToAll("simplewebrtc","yjs",e)},t}(AbstractConnector);Y.WebRTC=WebRTC,Y.IndexedDB=function(){var e=function(e){function t(r){_classCallCheck(this,t),e.call(this,r),this.transaction=r.db.transaction(["OperationStore","StateVector"],"readwrite"),this.sv=this.transaction.objectStore("StateVector"),this.os=this.transaction.objectStore("OperationStore"),this.buffer={}}return _inherits(t,e),t.prototype.setOperation=regeneratorRuntime.mark(function r(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.os.put(e);case 2:return this.buffer[JSON.stringify(e.id)]=e,t.abrupt("return",e);case 4:case"end":return t.stop()}},r,this)}),t.prototype.getOperation=regeneratorRuntime.mark(function n(e){var t;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(t=this.buffer[JSON.stringify(e)],null!=t){r.next=6;break}return r.next=4,this.os.get(e);case 4:t=r.sent,this.buffer[JSON.stringify(e)]=t;case 6:return r.abrupt("return",t);case 7:case"end":return r.stop()}},n,this)}),t.prototype.removeOperation=regeneratorRuntime.mark(function i(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.buffer[JSON.stringify(e)]=null,t.next=3,this.os["delete"](e);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}},i,this)}),t.prototype.setState=regeneratorRuntime.mark(function a(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.sv.put(e);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},a,this)}),t.prototype.getState=regeneratorRuntime.mark(function s(e){var t;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this.sv.get(e);case 2:if(r.t0=t=r.sent,null==r.t0){r.next=7;break}return r.abrupt("return",t);case 7:return r.abrupt("return",{user:e,clock:0});case 8:case"end":return r.stop()}},s,this)}),t.prototype.getStateVector=regeneratorRuntime.mark(function o(){var e,t,r;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:e=[],t=this.sv.openCursor();case 2:return n.next=4,t;case 4:if(n.t0=r=n.sent,null==n.t0){n.next=10;break}e.push(r.value),r["continue"](),n.next=2;break;case 10:return n.abrupt("return",e);case 11:case"end":return n.stop()}},o,this)}),t.prototype.getStateSet=regeneratorRuntime.mark(function u(){var e,t,r,n,i,a,s;return regeneratorRuntime.wrap(function(o){for(;;)switch(o.prev=o.next){case 0:return o.delegateYield(this.getStateVector(),"t0",1);case 1:e=o.t0,t={},r=e,n=Array.isArray(r),i=0,r=n?r:r[Symbol.iterator]();case 4:if(!n){o.next=10;break}if(!(i>=r.length)){o.next=7;break}return o.abrupt("break",18);case 7:a=r[i++],o.next=14;break;case 10:if(i=r.next(),!i.done){o.next=13;break}return o.abrupt("break",18);case 13:a=i.value;case 14:s=a,t[s.user]=s.clock;case 16:o.next=4;break;case 18:return o.abrupt("return",t);case 19:case"end":return o.stop()}},u,this)}),t.prototype.getOperations=regeneratorRuntime.mark(function c(e){var t,r,n,i,a,s,o,u,l,p,f,h,d;return regeneratorRuntime.wrap(function(c){for(;;)switch(c.prev=c.next){case 0:return null==e&&(e={}),t=[],c.delegateYield(this.getStateVector(),"t0",3);case 3:r=c.t0,n=r,i=Array.isArray(n),a=0,n=i?n:n[Symbol.iterator]();case 5:if(!i){c.next=11;break}if(!(a>=n.length)){c.next=8;break}return c.abrupt("break",31);case 8:s=n[a++],c.next=15;break;case 11:if(a=n.next(),!a.done){c.next=14;break}return c.abrupt("break",31);case 14:s=a.value;case 15:o=s,u=o.user,l=e[u]||0,p=o.clock,f=IDBKeyRange.bound([u,l],[u,p]),h=this.os.openCursor(f);case 21:return c.next=23,h;case 23:if(c.t1=d=c.sent,null==c.t1){c.next=29;break}t.push(d.value),d["continue"](),c.next=21;break;case 29:c.next=5;break;case 31:return c.abrupt("return",t);case 32:case"end":return c.stop()}},c,this)}),t}(AbstractTransaction),t=function(t){function r(n,i){function a(e){var t=e.value;e.done||(t.constructor===IDBRequest||t.constructor===IDBCursor?(t.onsuccess=function(){a(o.next(t.result))},t.onerror=function(e){o["throw"](e)}):t===s.transactionQueue?t.queue.length>0?a(o.next(t.queue.shift())):t.onRequest=function(){t.onRequest=null,a(o.next(t.queue.shift()))}:t.constructor===IDBOpenDBRequest?(t.onsuccess=function(e){var t=e.target.result;a(o.next(t))},t.onerror=function(){o["throw"]("Couldn't open IndexedDB database!")},t.onupgradeneeded=function(e){var t=e.target.result;try{t.createObjectStore("OperationStore",{keyPath:"id"}),t.createObjectStore("StateVector",{keyPath:"user"})}catch(r){}}):o["throw"]("You can not yield this type!"))}if(_classCallCheck(this,r),t.call(this,n),null==i&&(i={}),null==i.namespace||"string"!=typeof i.namespace)throw new Error("IndexedDB: expect a string (opts.namespace)!");this.namespace=i.namespace,this.idbVersion=null!=i.idbVersion?i.idbVersion:5,this.transactionQueue={queue:[],onRequest:null};var s=this,o=regeneratorRuntime.mark(function u(){var t,r,n,a;return regeneratorRuntime.wrap(function(o){for(;;)switch(o.prev=o.next){case 0:return o.next=2,indexedDB.open(i.namespace,s.idbVersion);case 2:s.db=o.sent,t=s.transactionQueue,r=null,n=!0;case 6:if(!n){o.next=14;break}return o.next=9,t;case 9:return a=o.sent,r=new e(s),o.delegateYield(a.call(r,a),"t0",12);case 12:o.next=6;break;case 14:case"end":return o.stop()}},u,this)})();a(o.next())}return _inherits(r,t),r.prototype.requestTransaction=function(e){this.transactionQueue.queue.push(e),null!=this.transactionQueue.onRequest&&this.transactionQueue.onRequest()},r.prototype.removeDatabase=regeneratorRuntime.mark(function n(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.db.close(),e.next=3,indexedDB.deleteDatabase(this.namespace);case 3:case"end":return e.stop()}},n,this)}),r}(AbstractOperationStore);return t}(),Y.Memory=function(){var e=function(e){function t(r){_classCallCheck(this,t),e.call(this,r),this.ss=r.ss,this.os=r.os}return _inherits(t,e),t.prototype.setOperation=regeneratorRuntime.mark(function r(e){var t;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return t=this.os.findNode(e.id),t.val=e,r.abrupt("return",e);case 3:case"end":return r.stop()}},r,this)}),t.prototype.getOperation=regeneratorRuntime.mark(function n(e){var t;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(t=this.os.find(e),null!=t){r.next=5;break}throw new Error("Op does not exist..");case 5:return r.abrupt("return",t);case 6:case"end":return r.stop()}},n,this)}),t.prototype.removeOperation=regeneratorRuntime.mark(function i(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:this.os["delete"](e);case 1:case"end":return t.stop()}},i,this)}),t.prototype.setState=regeneratorRuntime.mark(function a(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:this.ss[e.user]=e.clock;case 1:case"end":return t.stop()}},a,this)}),t.prototype.getState=regeneratorRuntime.mark(function s(e){var t;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return t=this.ss[e],null==t&&(t=0),r.abrupt("return",{user:e,clock:t});case 3:case"end":return r.stop()}},s,this)}),t.prototype.getStateVector=regeneratorRuntime.mark(function o(){var e,t,r;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:e=[];for(t in this.ss)r=this.ss[t],e.push({user:t,clock:r});return n.abrupt("return",e);case 3:case"end":return n.stop()}},o,this)}),t.prototype.getStateSet=regeneratorRuntime.mark(function u(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.ss);case 1:case"end":return e.stop()}},u,this)}),t.prototype.getOperations=regeneratorRuntime.mark(function c(e){var t,r,n,i,a,s,o,u,l,p,f,h,d,g,b,y;return regeneratorRuntime.wrap(function(c){for(;;)switch(c.prev=c.next){case 0:return null==e&&(e={}),t=[],c.delegateYield(this.getStateVector(),"t0",3);case 3:r=c.t0,n=r,i=Array.isArray(n),a=0,n=i?n:n[Symbol.iterator]();case 5:if(!i){c.next=11;break}if(!(a>=n.length)){c.next=8;break}return c.abrupt("break",24);case 8:s=n[a++],c.next=15;break;case 11:if(a=n.next(),!a.done){c.next=14;break}return c.abrupt("break",24);case 14:s=a.value;case 15:if(o=s,u=o.user,"_"!==u){c.next=19;break}return c.abrupt("continue",22);case 19:l=e[u]||0,p=o.clock,this.os.iterate([u,l],[u,p],function(e){t.push(Struct[e.struct].encode(e))});case 22:c.next=5;break;case 24:f=[],h=t,d=Array.isArray(h),g=0,h=d?h:h[Symbol.iterator]();case 26:if(!d){c.next=32;break}if(!(g>=h.length)){c.next=29;break}return c.abrupt("break",43);case 29:b=h[g++],c.next=36;break;case 32:if(g=h.next(),!g.done){c.next=35;break}return c.abrupt("break",43);case 35:b=g.value;case 36:return y=b,c.t1=f,c.delegateYield(this.makeOperationReady.call(this,e,y),"t2",39);case 39:c.t3=c.t2,c.t1.push.call(c.t1,c.t3);case 41:c.next=26;break;case 43:return c.abrupt("return",f);case 44:case"end":return c.stop()}},c,this)}),t.prototype.makeOperationReady=regeneratorRuntime.mark(function l(e,t){var r,n;return regeneratorRuntime.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:n=t;case 1:if(null==n.right){i.next=9;break}return i.delegateYield(this.getOperation(n.right),"t0",3);case 3:if(n=i.t0,r=e[n.id[0]],!(null!=r&&n.id[1]<r)){i.next=7;break}return i.abrupt("break",9);case 7:i.next=1;break;case 9:return t=copyObject(t),t.right=null==n?null:n.id,i.abrupt("return",t);case 12:case"end":return i.stop()}},l,this)}),t}(AbstractTransaction),t=function(t){function r(e){_classCallCheck(this,r),t.call(this,e),this.os=new RBTree,this.ss={}}return _inherits(r,t),r.prototype.requestTransaction=function(t){for(var r=new e(this),n=t.call(r,new Y.Map.Create(["_",0])),i=n.next();!i.done;){if("transaction"!==i.value)throw new Error("You may not yield this type. (Maybe you meant to use 'yield*'?)");i=n.next(r)}},r.prototype.removeDatabase=regeneratorRuntime.mark(function n(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:delete this.os;case 1:case"end":return e.stop()}},n,this)}),r}(AbstractOperationStore);return t}();var N=function(){function e(t){if(_classCallCheck(this,e),this.val=t,this.color=!0,this._left=null,this._right=null,this._parent=null,null===t.id)throw new Error("You must define id!")}return e.prototype.isRed=function(){return this.color},e.prototype.isBlack=function(){return!this.color},e.prototype.redden=function(){return this.color=!0,this},e.prototype.blacken=function(){return this.color=!1,this},e.prototype.rotateLeft=function(e){var t=this.parent,r=this.right,n=this.right.left;if(r.left=this,this.right=n,null===t)e.root=r,r._parent=null;else if(t.left===this)t.left=r;else{if(t.right!==this)throw new Error("The elements are wrongly connected!");t.right=r}},e.prototype.next=function(){if(null!==this.right){for(var e=this.right;null!==e.left;)e=e.left;return e}for(var t=this;null!==t.parent&&t!==t.parent.left;)t=t.parent;return t.parent},e.prototype.rotateRight=function(e){var t=this.parent,r=this.left,n=this.left.right;if(r.right=this,this.left=n,null===t)e.root=r,r._parent=null;else if(t.left===this)t.left=r;else{if(t.right!==this)throw new Error("The elements are wrongly connected!");t.right=r}},e.prototype.getUncle=function(){return this.parent===this.parent.parent.left?this.parent.parent.right:this.parent.parent.left},_createClass(e,[{key:"grandparent",get:function(){return this.parent.parent}},{key:"parent",get:function(){return this._parent}},{key:"sibling",get:function(){return this===this.parent.left?this.parent.right:this.parent.left}},{key:"left",get:function(){return this._left},set:function(e){null!==e&&(e._parent=this),this._left=e}},{key:"right",get:function(){return this._right},set:function(e){null!==e&&(e._parent=this),this._right=e}}]),e}(),RBTree=function(){function e(){_classCallCheck(this,e),this.root=null}return e.prototype.findNodeWithLowerBound=function(e){var t=this.root;if(null===t)return!1;for(;;)if((null===e||e<t.val.id)&&null!==t.left)t=t.left;else{if(!(t.val.id<e))return t;if(null===t.right)return t.next();t=t.right}},e.prototype.iterate=function(e,t,r){for(var n=this.findNodeWithLowerBound(e);null!==n&&(null===t||n.val.id<=t);)r(n.val),n=n.next();return!0},e.prototype.find=function(e){return this.findNode(e).val},e.prototype.findNode=function(e){var t=this.root;if(null===t)return!1;for(;;){if(null===t)return!1;if(e<t.val.id)t=t.left;else{if(!(t.val.id<e))return t;t=t.right}}},e.prototype["delete"]=function(e){var t=this.findNode(e);if(null!==t.left&&null!==t.right){for(var r=t.left;null!==r.right;)r=r.right;t.val=r.val,t=r}var n,i=t.left||t.right;if(null===i?(n=!0,i=new N({id:0}),i.blacken(),t.right=i):n=!1,null===t.parent)return void(n?this.root=null:(this.root=i,i.blacken(),i._parent=null));if(t.parent.left===t)t.parent.left=i;else{if(t.parent.right!==t)throw new Error("Impossible!");t.parent.right=i}if(t.isBlack()&&(i.isRed()?i.blacken():this._fixDelete(i)),this.root.blacken(),n)if(i.parent.left===i)i.parent.left=null;else{if(i.parent.right!==i)throw new Error("Impossible #3");i.parent.right=null}},e.prototype._fixDelete=function(e){function t(e){return null!==e?e.isBlack():!0}function r(e){return null!==e?e.isRed():!1}if(null!==e.parent){var n=e.sibling;if(r(n)){if(e.parent.redden(),n.blacken(),e===e.parent.left)e.parent.rotateLeft(this);else{if(e!==e.parent.right)throw new Error("Impossible #2");e.parent.rotateRight(this)}n=e.sibling}e.parent.isBlack()&&n.isBlack()&&t(n.left)&&t(n.right)?(n.redden(),this._fixDelete(e.parent)):e.parent.isRed()&&n.isBlack()&&t(n.left)&&t(n.right)?(n.redden(),e.parent.blacken()):(e===e.parent.left&&n.isBlack()&&r(n.left)&&t(n.right)?(n.redden(),n.left.blacken(),n.rotateRight(this),n=e.sibling):e===e.parent.right&&n.isBlack()&&r(n.right)&&t(n.left)&&(n.redden(),n.right.blacken(),n.rotateLeft(this),n=e.sibling),n.color=e.parent.color,e.parent.blacken(),e===e.parent.left?(n.right.blacken(),e.parent.rotateLeft(this)):(n.left.blacken(),e.parent.rotateRight(this)))}},e.prototype.add=function(e){var t=new N(e);if(null!==this.root){for(var r=this.root;;)if(t.val.id<r.val.id){if(null===r.left){r.left=t;break}r=r.left}else{if(!(r.val.id<t.val.id))return!1;if(null===r.right){r.right=t;break}r=r.right}this._fixInsert(t)}else this.root=t;this.root.blacken()},e.prototype._fixInsert=function(e){if(null===e.parent)return void e.blacken();if(!e.parent.isBlack()){var t=e.getUncle();null!==t&&t.isRed()?(e.parent.blacken(),t.blacken(),e.grandparent.redden(),this._fixInsert(e.grandparent)):(e===e.parent.right&&e.parent===e.grandparent.left?(e.parent.rotateLeft(this),e=e.left):e===e.parent.left&&e.parent===e.grandparent.right&&(e.parent.rotateRight(this),e=e.right),e.parent.blacken(),e.grandparent.redden(),e===e.parent.left?e.grandparent.rotateRight(this):e.grandparent.rotateLeft(this))}},e}();!function(){var e=function(){function e(t){_classCallCheck(this,e),this._model=t}return e.prototype.val=regeneratorRuntime.mark(function t(e){var r,n;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,"transaction";case 2:if(r=t.sent,null==e){t.next=9;break}return t.delegateYield(Y.Struct.List.ref.call(r,this._model,e),"t0",5);case 5:return n=t.t0,t.abrupt("return",n?n.content:null);case 9:return t.delegateYield(Y.Struct.List.map.call(r,this._model,function(e){return e}),"t1",10);case 10:return t.abrupt("return",t.t1);case 11:case"end":return t.stop()}},t,this)}),e.prototype.insert=regeneratorRuntime.mark(function r(e,t){var n;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,"transaction";case 2:return n=r.sent,r.delegateYield(Y.Struct.List.insert.call(n,this._model,e,t),"t0",4);case 4:case"end":return r.stop()}},r,this)}),e}();Y.List=regeneratorRuntime.mark(function t(){var r,n;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,"transaction";case 2:return r=t.sent,t.delegateYield(Y.Struct.List.create.call(r,{type:"List"}),"t0",4);case 4:return n=t.t0,t.abrupt("return",new e(n));case 6:case"end":return t.stop()}},t,this)}),Y.List.Create=e}(),function(){var e=function(){function e(t){_classCallCheck(this,e),this._model=t}return e.prototype.val=regeneratorRuntime.mark(function t(){var e,r,n=arguments;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,"transaction";case 2:return e=t.sent,t.delegateYield(e.getOperation(this._model),"t0",4);case 4:if(r=t.t0,1!==n.length){t.next=10;break}return t.delegateYield(Y.Struct.Map.get.call(e,r,n[0]),"t1",7);case 7:return t.abrupt("return",t.t1);case 10:if(2!==n.length){t.next=15;break}return t.delegateYield(Y.Struct.Map.set.call(e,r,n[0],n[1]),"t2",12);case 12:return t.abrupt("return",t.t2);case 15:throw new Error("Implement this case!");case 16:case"end":return t.stop()}},t,this)}),e}();Y.Map=regeneratorRuntime.mark(function t(){var r,n;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,"transaction";case 2:if(r=t.sent,!(this instanceof Y.AbstractOperationStore)){t.next=9;break}return t.delegateYield(Y.Struct.map.create.call(r,{type:"Map"}),"t0",5);case 5:return n=t.t0,t.abrupt("return",new e(n));case 9:throw new Error("Don't use `new` to create this type!");case 10:case"end":return t.stop()}},t,this)}),Y.Map.Create=e}();var AbstractConnector=function(){function e(t,r){if(_classCallCheck(this,e),this.y=t,null==r&&(r={}),null==r.role||"master"===r.role)this.role="master";else{if("slave"!==r.role)throw new Error("Role must be either 'master' or 'slave'!");this.role="slave"}this.role=r.role,this.connections={},this.userEventListeners=[],this.whenSyncedListeners=[],this.currentSyncTarget=null,this.syncingClients=[],this.forwardToSyncingClients=r.forwardToSyncingClients===!1?!1:!0,this.debug=r.debug?!0:!1}return e.prototype.setUserId=function(e){this.userId=e,this.y.db.setUserId(e)},e.prototype.onUserEvent=function(e){this.userEventListeners.push(e)},e.prototype.userLeft=function(e){delete this.connections[e],e===this.currentSyncTarget&&(this.currentSyncTarget=null,this.findNextSyncTarget());for(var t=this.userEventListeners,r=Array.isArray(t),n=0,t=r?t:t[Symbol.iterator]();;){var i;if(r){if(n>=t.length)break;i=t[n++]}else{if(n=t.next(),n.done)break;i=n.value}var a=i;a({action:"userLeft",user:e})}},e.prototype.userJoined=function(e,t){if(null==t)throw new Error("You must specify the role of the joined user!");if(null!=this.connections[e])throw new Error("This user already joined!");this.connections[e]={isSynced:!1,role:t};for(var r=this.userEventListeners,n=Array.isArray(r),i=0,r=n?r:r[Symbol.iterator]();;){var a;if(n){if(i>=r.length)break;a=r[i++]}else{if(i=r.next(),i.done)break;a=i.value}var s=a;s({action:"userJoined",user:e,role:t})}null==this.currentSyncTarget&&this.findNextSyncTarget()},e.prototype.whenSynced=function(e){this.isSynced===!0?e():this.whenSyncedListeners.push(e)},e.prototype.findNextSyncTarget=function(){if(null!=this.currentSyncTarget&&this.connections[this.currentSyncTarget].isSynced===!1)throw new Error("The current sync has not finished!");var e=null;for(var t in this.connections)if(e=this.connections[t],!e.isSynced)break;if(null!=e){var r=this;this.y.db.requestTransaction(regeneratorRuntime.mark(function u(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r.currentSyncTarget=t,e.t0=r,e.t1=t,e.delegateYield(this.getStateVector(),"t2",4);case 4:e.t3=e.t2,e.t4={type:"sync step 1",stateVector:e.t3},e.t0.send.call(e.t0,e.t1,e.t4);case 7:case"end":return e.stop()}},u,this)}))}if(!this.isSynced){this.isSynced=!0;for(var n=this.whenSyncedListeners,i=Array.isArray(n),a=0,n=i?n:n[Symbol.iterator]();;){var s;if(i){if(a>=n.length)break;s=n[a++]}else{if(a=n.next(),a.done)break;s=a.value}var o=s;o()}this.whenSyncedListeners=null}return!1},e.prototype.receiveMessage=function(e,t){var r=this;if(this.debug&&console.log(e+" -> "+this.userId+": "+JSON.stringify(t)),"sync step 1"===t.type)!function(){var n=r;r.y.db.requestTransaction(regeneratorRuntime.mark(function i(){var r,a;return regeneratorRuntime.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return i.delegateYield(this.getOperations(t.stateVector),"t0",1);case 1:return r=i.t0,i.delegateYield(this.getStateVector(),"t1",3);case 3:a=i.t1,n.send(e,{type:"sync step 2",os:r,stateVector:a}),this.forwardToSyncingClients&&(n.syncingClients.push(e),setTimeout(function(){n.syncingClients=n.syncingClients.filter(function(t){return t!==e}),n.send(e,{type:"sync done"})},n.syncingClientDuration));case 6:case"end":return i.stop()}},i,this)}))}();else if("sync step 2"===t.type)!function(){r.y.db.apply(t.os);var e=r;r.y.db.requestTransaction(regeneratorRuntime.mark(function n(){var r;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.delegateYield(this.getOperations(t.stateVector),"t0",1);case 1:r=n.t0,r.length>0&&e.broadcast({type:"update",ops:r});case 3:case"end":return n.stop()}},n,this)}))}();else if("sync done"===t.type)this.connections[e].isSynced=!0,this.findNextSyncTarget();else if("update"===t.type){if(this.forwardToSyncingClients)for(var n=this.syncingClients,i=Array.isArray(n),a=0,n=i?n:n[Symbol.iterator]();;){var s;if(i){if(a>=n.length)break;s=n[a++]}else{if(a=n.next(),a.done)break;s=a.value}var o=s;this.send(o,t)}this.y.db.apply(t.ops)}},e.prototype.parseMessageFromXml=function(e){function t(e){var t=!0;e:for(;t;){var n=e;i=a=s=i=o=u=void 0,t=!1;for(var i=n.children,a=Array.isArray(i),s=0,i=a?i:i[Symbol.iterator]();;){var o;if(a){if(s>=i.length)break;o=i[s++]}else{if(s=i.next(),s.done)break;o=s.value}var u=o;if("true"===u.getAttribute("isArray")){e=u,t=!0;continue e}return r(u)}}}function r(e){var n={};for(var i in e.attrs){var a=e.attrs[i],s=parseInt(a);n[i]=isNaN(s)||""+s!==a?a:s}for(var o in e.children){var u=o.name;n[u]="true"===o.getAttribute("isArray")?t(o):r(o)}return n}r(e)},e.prototype.encodeMessageToXml=function(e,t){function r(e,t){for(var i in t){var a=t[i];null==i||(a.constructor===Object?r(e.c(i),a):a.constructor===Array?n(e.c(i),a):e.setAttribute(i,a))}}function n(e,t){e.setAttribute("isArray","true");for(var i=t,a=Array.isArray(i),s=0,i=a?i:i[Symbol.iterator]();;){var o;if(a){if(s>=i.length)break;o=i[s++]}else{if(s=i.next(),s.done)break;o=s.value}var u=o;u.constructor===Object?r(e.c("array-element"),u):n(e.c("array-element"),u);
|
|
|
|
}}if(t.constructor===Object)r(e.c("y",{xmlns:"http://y.ninja/connector-stanza"}),t);else{if(t.constructor!==Array)throw new Error("I can't encode this json!");n(e.c("y",{xmlns:"http://y.ninja/connector-stanza"}),t)}},e}(),AbstractTransaction=function(){function e(t){_classCallCheck(this,e),this.store=t}return e.prototype.getType=regeneratorRuntime.mark(function t(e){var r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.delegateYield(this.getOperation(e),"t0",1);case 1:return r=t.t0,t.abrupt("return",new Y[r.type].Create(r));case 3:case"end":return t.stop()}},t,this)}),e.prototype.addOperation=regeneratorRuntime.mark(function r(e){var t;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.delegateYield(this.getState(e.id[0]),"t0",1);case 1:if(t=r.t0,e.id[1]!==t.clock){r.next=10;break}return t.clock++,r.delegateYield(this.setState(t),"t1",5);case 5:return this.os.add(e),this.store.operationAdded(e),r.abrupt("return",!0);case 10:if(!(e.id[1]<t.clock)){r.next=14;break}return r.abrupt("return",!1);case 14:throw new Error("Operations must arrive in order!");case 15:case"end":return r.stop()}},r,this)}),e}(),AbstractOperationStore=function(){function e(t){_classCallCheck(this,e),this.y=t,this.parentListeners={},this.parentListenersRequestPending=!1,this.parentListenersActivated={},this.listenersById={},this.listenersByIdExecuteNow=[],this.listenersByIdRequestPending=!1}return e.prototype.setUserId=function(e){this.userId=e},e.prototype.apply=function(e){for(var t in e){var r=e[t],n=Y.Struct[r.struct].requiredOps(r);this.whenOperationsExist(n,r)}},e.prototype.whenOperationsExist=function(e,t){if(e.length>0){var r={op:t,missing:e.length};for(var n in e){var i=e[n],a=JSON.stringify(i),s=this.listenersById[a];null==s&&(s=[],this.listenersById[a]=s),s.push(r)}}else this.listenersByIdExecuteNow.push({op:t});if(!this.listenersByIdRequestPending){this.listenersByIdRequestPending=!0;var o=this;this.requestTransaction(regeneratorRuntime.mark(function u(){var e,t,r,n,i,a,s,c;return regeneratorRuntime.wrap(function(u){for(;;)switch(u.prev=u.next){case 0:e=o.listenersByIdExecuteNow,o.listenersByIdExecuteNow=[],t=o.listenersById,o.listenersById={},o.listenersByIdRequestPending=!1,u.t0=regeneratorRuntime.keys(e);case 6:if((u.t1=u.t0()).done){u.next=12;break}return r=u.t1.value,n=e[r].op,u.delegateYield(Struct[n.struct].execute.call(this,n),"t2",10);case 10:u.next=6;break;case 12:u.t3=regeneratorRuntime.keys(t);case 13:if((u.t4=u.t3()).done){u.next=34;break}return i=u.t4.value,a=t[i],s=JSON.parse(i),u.delegateYield(this.getOperation(s),"t5",18);case 18:if(u.t6=u.t5,null!=u.t6){u.next=23;break}o.listenersById[i]=a,u.next=32;break;case 23:u.t7=regeneratorRuntime.keys(a);case 24:if((u.t8=u.t7()).done){u.next=32;break}if(r=u.t8.value,c=a[r],n=c.op,0!==--c.missing){u.next=30;break}return u.delegateYield(Struct[n.struct].execute.call(this,n),"t9",30);case 30:u.next=24;break;case 32:u.next=13;break;case 34:case"end":return u.stop()}},u,this)}))}},e.prototype.operationAdded=function(e){var t=JSON.stringify(e.id),r=this.listenersById[t];if(delete this.listenersById[t],null!=r)for(var n in r){var i=r[n];0===--i.missing&&this.whenOperationsExist([],i.op)}var a=this.parentListeners[e.parent];if(!this.parentListenersRequestPending&&null!=a&&0!==a.length){var s=this.parentListenersActivated[JSON.stringify(e.parent)];null==s&&(s=[],this.parentListenersActivated[JSON.stringify(e.parent)]=s),s.push(e),this.parentListenersRequestPending=!0;var o=this;this.requestTransaction(regeneratorRuntime.mark(function u(){var e,t,r;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:o.parentListenersRequestPending=!1,e=o.parentListenersActivated,o.parentListenersActivated={},n.t0=regeneratorRuntime.keys(e);case 4:if((n.t1=n.t0()).done){n.next=11;break}return t=n.t1.value,n.delegateYield(this.getOperation(t),"t2",7);case 7:r=n.t2,Struct[r.struct].notifyObservers(e[t]),n.next=4;break;case 11:case"end":return n.stop()}},u,this)}))}},e.prototype.removeParentListener=function(e,t){var r=this.parentListeners[e];null!=r&&(this.parentListeners[e]=r.filter(function(e){return t!==e}))},e.prototype.addParentListener=function(e,t){var r=this.parentListeners[JSON.stringify(e)];null==r&&(r=[],this.parentListeners[JSON.stringify(e)]=r),r.push(t)},e}(),Struct={Operation:{create:regeneratorRuntime.mark(function t(e){var r,n;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=this.store.y.connector.userId,t.delegateYield(this.getState(r),"t0",2);case 2:return n=t.t0,e.id=[r,n.clock],t.delegateYield(this.addOperation(e),"t1",5);case 5:if(t.t2=t.t1,t.t2!==!1){t.next=8;break}throw new Error("This is highly unexpected :(");case 8:return this.store.y.connector.broadcast({type:"update",ops:[Struct[e.struct].encode(e)]}),t.abrupt("return",e);case 10:case"end":return t.stop()}},t,this)})},Insert:{create:regeneratorRuntime.mark(function r(e){var t,n,i,a,s;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(void 0!==e.left&&void 0!==e.right&&void 0!==e.parent){r.next=2;break}throw new Error("You must define left, right, and parent!");case 2:return e.origin=e.left,e.struct="Insert",r.delegateYield(Struct.Operation.create.call(this,e),"t0",5);case 5:if(null==e.left){r.next=10;break}return r.delegateYield(this.getOperation(e.left),"t1",7);case 7:return t=r.t1,t.right=e.id,r.delegateYield(this.setOperation(t),"t2",10);case 10:if(null==e.right){r.next=15;break}return r.delegateYield(this.getOperation(e.right),"t3",12);case 12:return n=r.t3,n.left=e.id,r.delegateYield(this.setOperation(n),"t4",15);case 15:return r.delegateYield(this.getOperation(e.parent),"t5",16);case 16:if(i=r.t5,null==e.parentSub){r.next=23;break}if(!compareIds(i.map[e.parentSub],e.right)){r.next=21;break}return i.map[e.parentSub]=e.id,r.delegateYield(this.setOperation(i),"t6",21);case 21:r.next=29;break;case 23:if(a=compareIds(i.start,e.right),s=compareIds(i.end,e.left),!a&&!s){r.next=29;break}return a&&(i.start=e.id),s&&(i.end=e.id),r.delegateYield(this.setOperation(i),"t7",29);case 29:return r.abrupt("return",e);case 30:case"end":return r.stop()}},r,this)}),encode:function(e){return e},requiredOps:function(e){var t=[];return null!=e.left&&t.push(e.left),null!=e.right&&t.push(e.right),null==e.right&&null==e.left&&t.push(e.parent),null!=e.opContent&&t.push(e.opContent),t},getDistanceToOrigin:regeneratorRuntime.mark(function n(e){var t,r;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(null!=e.left){n.next=4;break}return n.abrupt("return",0);case 4:return t=0,n.delegateYield(this.getOperation(e.left),"t0",6);case 6:r=n.t0;case 7:if(compareIds(e.origin,r?r.id:null)){n.next=17;break}if(t++,null!=r.left){n.next=13;break}return n.abrupt("break",17);case 13:return n.delegateYield(this.getOperation(r.left),"t1",14);case 14:r=n.t1;case 15:n.next=7;break;case 17:return n.abrupt("return",t);case 18:case"end":return n.stop()}},n,this)}),execute:regeneratorRuntime.mark(function i(e){var t,r,n,a,s,o,u,c,l;return regeneratorRuntime.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return i.delegateYield(Struct.Insert.getDistanceToOrigin.call(this,e),"t0",1);case 1:if(r=t=i.t0,null==e.left){i.next=14;break}return i.delegateYield(this.getOperation(e.left),"t1",4);case 4:if(n=i.t1,null!=n.right){i.next=9;break}i.t2=null,i.next=11;break;case 9:return i.delegateYield(this.getOperation(n.right),"t3",10);case 10:i.t2=i.t3;case 11:n=i.t2,i.next=25;break;case 14:return i.delegateYield(this.getOperation(e.parent),"t4",15);case 15:if(a=i.t4,o=e.parentSub?a.map[e.parentSub]:a.start,null!=o){i.next=21;break}i.t5=null,i.next=23;break;case 21:return i.delegateYield(this.getOperation(o),"t6",22);case 22:i.t5=i.t6;case 23:s=i.t5,n=s;case 25:if(null==n||compareIds(n.id,e.right)){i.next=48;break}return i.delegateYield(Struct.Insert.getDistanceToOrigin.call(this,n),"t7",28);case 28:if(u=i.t7,u!==t){i.next=33;break}n.id[0]<e.id[0]&&(e.left=n.id,r=t+1),i.next=38;break;case 33:if(!(t>u)){i.next=37;break}u>=t-r&&(e.left=n.id,r=t+1),i.next=38;break;case 37:return i.abrupt("break",51);case 38:if(t++,!n.right){i.next=44;break}return i.delegateYield(this.getOperation(n.right),"t9",41);case 41:i.t8=i.t9,i.next=45;break;case 44:i.t8=null;case 45:n=i.t8,i.next=49;break;case 48:return i.abrupt("break",51);case 49:i.next=25;break;case 51:if(c=null,l=null,i.t10=a,i.t10){i.next=57;break}return i.delegateYield(this.getOperation(e.parent),"t11",56);case 56:i.t10=i.t11;case 57:if(a=i.t10,null==e.left){i.next=70;break}return i.delegateYield(this.getOperation(e.left),"t12",60);case 60:return c=i.t12,e.right=c.right,i.delegateYield(this.addOperation(e),"t13",63);case 63:if(i.t14=i.t13,i.t14!==!1){i.next=66;break}return i.abrupt("return");case 66:return c.right=e.id,i.delegateYield(this.setOperation(c),"t15",68);case 68:i.next=75;break;case 70:return e.right=e.parentSub?a.map[e.parentSub]||null:a.start,i.delegateYield(this.addOperation(e),"t16",72);case 72:if(i.t17=i.t16,i.t17!==!1){i.next=75;break}return i.abrupt("return");case 75:if(null==e.right){i.next=80;break}return i.delegateYield(this.getOperation(e.right),"t18",77);case 77:return l=i.t18,l.left=e.id,i.delegateYield(this.setOperation(l),"t19",80);case 80:if(null==e.parentSub){i.next=86;break}if(null!=c){i.next=84;break}return a.map[e.parentSub]=e.id,i.delegateYield(this.setOperation(a),"t20",84);case 84:i.next=90;break;case 86:if(null!=l&&null!=c){i.next=90;break}return null==l&&(a.end=e.id),null==c&&(a.start=e.id),i.delegateYield(this.setOperation(a),"t21",90);case 90:case"end":return i.stop()}},i,this)})},List:{create:regeneratorRuntime.mark(function a(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e.start=null,e.end=null,e.struct="List",t.delegateYield(Struct.Operation.create.call(this,e),"t0",4);case 4:return t.abrupt("return",t.t0);case 5:case"end":return t.stop()}},a,this)}),encode:function(e){return{struct:"List",id:e.id,type:e.type}},requiredOps:function(){return[]},execute:regeneratorRuntime.mark(function s(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e.start=null,e.end=null,t.delegateYield(this.addOperation(e),"t0",3);case 3:if(t.t1=t.t0,t.t1!==!1){t.next=6;break}return t.abrupt("return");case 6:case"end":return t.stop()}},s,this)}),ref:regeneratorRuntime.mark(function o(e,t){var r;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(null!=e.start){n.next=2;break}return n.abrupt("return",null);case 2:return n.delegateYield(this.getOperation(e.start),"t0",3);case 3:r=n.t0;case 4:if(0===t||null==r.right){n.next=10;break}return n.delegateYield(this.getOperation(r.right),"t1",6);case 6:r=n.t1,t--,n.next=4;break;case 10:return n.abrupt("return",r);case 11:case"end":return n.stop()}},o,this)}),map:regeneratorRuntime.mark(function u(e,t){var r,n;return regeneratorRuntime.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:e=e.start,r=[];case 2:if(null==e){i.next=9;break}return i.delegateYield(this.getOperation(e),"t0",4);case 4:n=i.t0,r.push(t(n.content)),e=n.right,i.next=2;break;case 9:return i.abrupt("return",r);case 10:case"end":return i.stop()}},u,this)}),insert:regeneratorRuntime.mark(function c(e,t,r){var n,i,a,s,c;return regeneratorRuntime.wrap(function(o){for(;;)switch(o.prev=o.next){case 0:return o.delegateYield(Struct.List.ref.call(this,e,t),"t0",1);case 1:n=o.t0,i=null!=n?n.id:null,a=null!=n?n.left:null,o.t1=regeneratorRuntime.keys(r);case 5:if((o.t2=o.t1()).done){o.next=12;break}return s=o.t2.value,c={left:a,right:i,content:r[s],parent:e.id},o.delegateYield(Struct.Insert.create.call(this,c),"t3",9);case 9:a=o.t3.id,o.next=5;break;case 12:case"end":return o.stop()}},c,this)})},Map:{create:regeneratorRuntime.mark(function l(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e.map={},e.struct="Map",t.delegateYield(Struct.Operation.create.call(this,e),"t0",3);case 3:return t.abrupt("return",t.t0);case 4:case"end":return t.stop()}},l,this)}),encode:function(e){return{struct:"Map",type:e.type,id:e.id}},requiredOps:function(){return[]},execute:regeneratorRuntime.mark(function p(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.delegateYield(this.addOperation(e),"t0",1);case 1:if(t.t1=t.t0,t.t1!==!1){t.next=4;break}return t.abrupt("return");case 4:case"end":return t.stop()}},p,this)}),get:regeneratorRuntime.mark(function f(e,t){var r;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.delegateYield(this.getOperation(e.map[t]),"t0",1);case 1:if(r=n.t0,null!=r){n.next=6;break}n.t1=void 0,n.next=13;break;case 6:if(null!=r.opContent){n.next=10;break}n.t2=r.content,n.next=12;break;case 10:return n.delegateYield(this.getType(r.opContent),"t3",11);case 11:n.t2=n.t3;case 12:n.t1=n.t2;case 13:return n.abrupt("return",n.t1);case 14:case"end":return n.stop()}},f,this)}),set:regeneratorRuntime.mark(function h(e,t,r){var n,i;return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return n={left:null,right:e.map[t]||null,parent:e.id,parentSub:t},null!=r&&null!=r._model&&null!=(i=r._model.id)&&2===i.length?n.opContent=i:n.content=r,a.delegateYield(Struct.Insert.create.call(this,n),"t0",3);case 3:case"end":return a.stop()}},h,this)})}};
|
|
//# sourceMappingURL=y.js.map
|