diff --git a/Examples/WebWorker/index.html b/Examples/ServiceWorker/index.html
similarity index 100%
rename from Examples/WebWorker/index.html
rename to Examples/ServiceWorker/index.html
diff --git a/Examples/WebWorker/index.js b/Examples/ServiceWorker/index.js
similarity index 61%
rename from Examples/WebWorker/index.js
rename to Examples/ServiceWorker/index.js
index 605131a4..f4db86ca 100644
--- a/Examples/WebWorker/index.js
+++ b/Examples/ServiceWorker/index.js
@@ -1,21 +1,31 @@
/* global Y, Quill */
+// register yjs service worker
+if('serviceWorker' in navigator){
+ // Register service worker
+ // it is important to copy yjs-sw-template to the root directory!
+ navigator.serviceWorker.register('./yjs-sw-template.js').then(function(reg){
+ console.log("Yjs service worker registration succeeded. Scope is " + reg.scope);
+ }).catch(function(err){
+ console.error("Yjs service worker registration failed with error " + err);
+ })
+}
+
// initialize a shared object. This function call returns a promise!
Y({
db: {
name: 'memory'
},
connector: {
- name: 'webworker',
- url: '../bower_components/y-webworker/yjs-webworker.js',
- room: 'WebWorkerExample2'
+ name: 'serviceworker',
+ room: 'ServiceWorkerExample2'
},
sourceDir: '/bower_components',
share: {
richtext: 'Richtext' // y.share.richtext is of type Y.Richtext
}
}).then(function (y) {
- window.yQuill = y
+ window.yServiceWorker = y
// create quill element
window.quill = new Quill('#quill', {
diff --git a/Examples/ServiceWorker/yjs-sw-template.js b/Examples/ServiceWorker/yjs-sw-template.js
new file mode 100644
index 00000000..0fc8dd13
--- /dev/null
+++ b/Examples/ServiceWorker/yjs-sw-template.js
@@ -0,0 +1,22 @@
+/* eslint-env worker */
+
+// copy and modify this file
+
+self.DBConfig = {
+ name: 'indexeddb'
+}
+self.ConnectorConfig = {
+ name: 'websockets-client',
+ // url: '..',
+ options: {
+ jsonp: false
+ }
+}
+
+importScripts(
+ '/bower_components/yjs/y.js',
+ '/bower_components/y-memory/y-memory.js',
+ '/bower_components/y-indexeddb/y-indexeddb.js',
+ '/bower_components/y-websockets-client/y-websockets-client.js',
+ '/bower_components/y-serviceworker/yjs-sw-include.js'
+)
diff --git a/y.es6 b/y.es6
index 30d9e5dc..ab164388 100644
--- a/y.es6
+++ b/y.es6
@@ -1,6 +1,6 @@
/**
* yjs - A framework for real-time p2p shared editing on any data
- * @version v12.1.6
+ * @version v12.1.7
* @link http://y-js.org
* @license MIT
*/
diff --git a/y.js b/y.js
index 49ba6f02..7610259d 100644
--- a/y.js
+++ b/y.js
@@ -1,10 +1,7977 @@
/**
* yjs - A framework for real-time p2p shared editing on any data
- * @version v12.1.6
+ * @version v12.1.7
* @link http://y-js.org
* @license MIT
*/
-!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.Y=e()}}(function(){return function e(t,r,n){function i(s,o){if(!r[s]){if(!t[s]){var u="function"==typeof require&&require;if(!o&&u)return u(s,!0);if(a)return a(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var l=r[s]={exports:{}};t[s][0].call(l.exports,function(e){var r=t[s][1][e];return i(r?r:e)},l,l.exports,e,t,r,n)}return r[s].exports}for(var a="function"==typeof require&&require,s=0;s1e4)){var t=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(e);if(t){var r=parseFloat(t[1]),n=(t[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return r*d;case"days":case"day":case"d":return r*l;case"hours":case"hour":case"hrs":case"hr":case"h":return r*c;case"minutes":case"minute":case"mins":case"min":case"m":return r*u;case"seconds":case"second":case"secs":case"sec":case"s":return r*o;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}}}function i(e){return e>=l?Math.round(e/l)+"d":e>=c?Math.round(e/c)+"h":e>=u?Math.round(e/u)+"m":e>=o?Math.round(e/o)+"s":e+"ms"}function a(e){return s(e,l,"day")||s(e,c,"hour")||s(e,u,"minute")||s(e,o,"second")||e+" ms"}function s(e,t,r){if(!(e0)return n(e);if("number"===r&&isNaN(e)===!1)return t.long?a(e):i(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},{}],2:[function(e,t,r){(function(n){"use strict";function i(){return!("undefined"==typeof window||!window||"undefined"==typeof window.process||"renderer"!==window.process.type)||("undefined"!=typeof document&&document&&"WebkitAppearance"in document.documentElement.style||"undefined"!=typeof window&&window&&window.console&&(console.firebug||console.exception&&console.table)||"undefined"!=typeof navigator&&navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))}function a(e){var t=this.useColors;if(e[0]=(t?"%c":"")+this.namespace+(t?" %c":" ")+e[0]+(t?"%c ":" ")+"+"+r.humanize(this.diff),t){var n="color: "+this.color;e.splice(1,0,n,"color: inherit");var i=0,a=0;e[0].replace(/%[a-zA-Z%]/g,function(e){"%%"!==e&&(i++,"%c"===e&&(a=i))}),e.splice(a,0,n)}}function s(){return"object"===("undefined"==typeof console?"undefined":l(console))&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function o(e){try{null==e?r.storage.removeItem("debug"):r.storage.debug=e}catch(e){}}function u(){var e;try{e=r.storage.debug}catch(e){}return!e&&"undefined"!=typeof n&&"env"in n&&(e=n.env.DEBUG),e}function c(){try{return window.localStorage}catch(e){}}var l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e};r=t.exports=e("./debug"),r.log=s,r.formatArgs=a,r.save=o,r.load=u,r.useColors=i,r.storage="undefined"!=typeof chrome&&"undefined"!=typeof chrome.storage?chrome.storage.local:c(),r.colors=["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],r.formatters.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}},r.enable(u())}).call(this,e("_process"))},{"./debug":3,_process:4}],3:[function(e,t,r){"use strict";function n(e){var t,n=0;for(t in e)n=(n<<5)-n+e.charCodeAt(t),n|=0;return r.colors[Math.abs(n)%r.colors.length]}function i(e){function t(){if(t.enabled){var e=t,n=+new Date,i=n-(c||n);e.diff=i,e.prev=c,e.curr=n,c=n;for(var a=new Array(arguments.length),s=0;s1)for(var r=1;r=0;--n){var i=this.tryEntries[n],a=i.completion;if("root"===i.tryLoc)return t("end");if(i.tryLoc<=this.prev){var s=m.call(i,"catchLoc"),o=m.call(i,"finallyLoc");if(s&&o){if(this.prev=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&m.call(n,"finallyLoc")&&this.prev=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),p(r),C}},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:y(e),resultName:t,nextLoc:r},C}}}("object"===("undefined"==typeof r?"undefined":n(r))?r:"object"===("undefined"==typeof window?"undefined":n(window))?window:"object"===("undefined"==typeof self?"undefined":n(self))?self:void 0)}).call(this,e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{_process:4}],6:[function(e,t,r){"use strict";console.warn("The regenerator/runtime module is deprecated; please import regenerator-runtime/runtime instead."),t.exports=e("regenerator-runtime/runtime")},{"regenerator-runtime/runtime":5}],7:[function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e){return"read"===e||"write"===e}function a(e){return"write"===e}var s=function(){function e(e,t){for(var r=0;r0&&(n.broadcast({type:"update",ops:n.broadcastOpBuffer}),n.broadcastOpBuffer=[])}t=t.map(function(t){return e.Struct[t.struct].encode(t)});var n=this;0===this.broadcastOpBuffer.length?(this.broadcastOpBuffer=t,this.y.db.transactionInProgress?this.y.db.whenTransactionsFinished().then(r):setTimeout(r,0)):this.broadcastOpBuffer=this.broadcastOpBuffer.concat(t)}},{key:"receiveMessage",value:function(e,t){var r=this;if(e===this.userId)return Promise.resolve();if(this.log("Receive '%s' from %s",t.type,e),this.logMessage("Message: %j",t),null!=t.protocolVersion&&t.protocolVersion!==this.protocolVersion)return this.log("You tried to sync with a yjs instance that has a different protocol version\n (You: "+this.protocolVersion+", Client: "+t.protocolVersion+").\n The sync was stopped. You need to upgrade your dependencies (especially Yjs & the Connector)!\n "),this.send(e,{type:"sync stop",protocolVersion:this.protocolVersion}),Promise.reject("Incompatible protocol version");if(null!=t.auth&&null!=this.connections[e]){var n=this.checkAuth(t.auth,this.y);this.connections[e].auth=n,n.then(function(t){var n=!0,i=!1,a=void 0;try{for(var s,o=r.userEventListeners[Symbol.iterator]();!(n=(s=o.next()).done);n=!0){var u=s.value;u({action:"userAuthenticated",user:e,auth:t})}}catch(e){i=!0,a=e}finally{try{!n&&o.return&&o.return()}finally{if(i)throw a}}})}else null!=this.connections[e]&&null==this.connections[e].auth&&(this.connections[e].auth=this.checkAuth(null,this.y));return null!=this.connections[e]&&null!=this.connections[e].auth?this.connections[e].auth.then(function(n){if("sync step 1"===t.type&&i(n))!function(){var i=r,s=t;r.y.db.requestTransaction(regeneratorRuntime.mark(function t(){var r,o,u;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.delegateYield(this.getStateSet(),"t0",1);case 1:if(r=t.t0,!a(n)){t.next=4;break}return t.delegateYield(this.applyDeleteSet(s.deleteSet),"t1",4);case 4:return t.delegateYield(this.getDeleteSet(),"t2",5);case 5:return o=t.t2,t.delegateYield(this.getOperations(s.stateSet),"t3",7);case 7:u=t.t3,i.send(e,{type:"sync step 2",os:u,stateSet:r,deleteSet:o,protocolVersion:this.protocolVersion,auth:this.authInfo}),this.forwardToSyncingClients?(i.syncingClients.push(e),setTimeout(function(){i.syncingClients=i.syncingClients.filter(function(t){return t!==e}),i.send(e,{type:"sync done"})},5e3)):i.send(e,{type:"sync done"});case 10:case"end":return t.stop()}},t,this)}))}();else if("sync step 2"===t.type&&a(n)){var s,o,u;!function(){var n=r;s=!r.broadcastedHB,r.broadcastedHB=!0,o=r.y.db,u={},u.promise=new Promise(function(e){u.resolve=e}),r.syncStep2=u.promise;var i=t;o.requestTransaction(regeneratorRuntime.mark(function t(){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.delegateYield(this.applyDeleteSet(i.deleteSet),"t0",1);case 1:this.store.apply(i.os),o.requestTransaction(regeneratorRuntime.mark(function t(){var r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.delegateYield(this.getOperations(i.stateSet),"t0",1);case 1:r=t.t0,r.length>0&&(s?n.broadcastOps(r):n.send(e,{type:"update",ops:r})),u.resolve();case 4:case"end":return t.stop()}},t,this)}));case 3:case"end":return t.stop()}},t,this)}))}()}else if("sync done"===t.type){var c=r;r.syncStep2.then(function(){c._setSyncedWith(e)})}else if("update"===t.type&&a(n)){if(r.forwardToSyncingClients){var l=!0,d=!1,f=void 0;try{for(var h,p=r.syncingClients[Symbol.iterator]();!(l=(h=p.next()).done);l=!0){var g=h.value;r.send(g,t)}}catch(e){d=!0,f=e}finally{try{!l&&p.return&&p.return()}finally{if(d)throw f}}}if(r.y.db.forwardAppliedOperations){var y=t.ops.filter(function(e){return"Delete"===e.struct});y.length>0&&r.broadcastOps(y)}r.y.db.apply(t.ops)}}):Promise.reject("Unable to deliver message")}},{key:"_setSyncedWith",value:function(e){var t=this.connections[e];null!=t&&(t.isSynced=!0),e===this.currentSyncTarget&&(this.currentSyncTarget=null,this.findNextSyncTarget())}},{key:"parseMessageFromXml",value:function(e){function t(e){var n=!0,i=!1,a=void 0;try{for(var s,o=e.children[Symbol.iterator]();!(n=(s=o.next()).done);n=!0){var u=s.value;return"true"===u.getAttribute("isArray")?t(u):r(u)}}catch(e){i=!0,a=e}finally{try{!n&&o.return&&o.return()}finally{if(i)throw a}}}function r(e){var n={};for(var i in e.attrs){var a=e.attrs[i],s=parseInt(a,10);isNaN(s)||""+s!==a?n[i]=a:n[i]=s}for(var o in e.children){var u=o.name;"true"===o.getAttribute("isArray")?n[u]=t(o):n[u]=r(o)}return n}r(e)}},{key:"encodeMessageToXml",value: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");var i=!0,a=!1,s=void 0;try{for(var o,u=t[Symbol.iterator]();!(i=(o=u.next()).done);i=!0){var c=o.value;c.constructor===Object?r(e.c("array-element"),c):n(e.c("array-element"),c)}}catch(e){a=!0,s=e}finally{try{!i&&u.return&&u.return()}finally{if(a)throw s}}}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)}}}]),t}();e.AbstractConnector=t}},{}],8:[function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(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&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var s=function(){function e(e,t){for(var r=0;r0){i=!0;break}i&&e.push(r)}if(e.length>0){var s=getRandom(e),o=t.buffers[s],u=getRandom(Object.keys(o)),c=o[u].shift();0===o[u].length&&delete o[u];var l=t.users[s];return l.receiveMessage(c[0],c[1]).then(function(){return l.y.db.whenTransactionsFinished()},function(){})}return!1},flushAll:function(){return new Promise(function(e){function r(){var n=t.flushOne();if(n){for(;n;)n=t.flushOne();t.whenTransactionsFinished().then(r)}else n=t.flushOne(),n?n.then(function(){t.whenTransactionsFinished().then(r)}):e()}t.whenTransactionsFinished().then(r)})}};e.utils.globalRoom=t;var r=0,u=function(u){function c(e,a){if(n(this,c),void 0===a)throw new Error("Options must not be undefined!");a.role="master",a.forwardToSyncingClients=!1;var s=i(this,Object.getPrototypeOf(c).call(this,e,a));return s.setUserId(r++ +"").then(function(){t.addUser(s)}),s.globalRoom=t,s.syncingClientDuration=0,s}return a(c,u),s(c,[{key:"receiveMessage",value:function(e,t){return o(Object.getPrototypeOf(c.prototype),"receiveMessage",this).call(this,e,JSON.parse(JSON.stringify(t)))}},{key:"send",value:function(e,r){var n=t.buffers[e];null!=n&&(null==n[this.userId]&&(n[this.userId]=[]),n[this.userId].push(JSON.parse(JSON.stringify([this.userId,r]))))}},{key:"broadcast",value:function(e){for(var r in t.buffers){var n=t.buffers[r];null==n[this.userId]&&(n[this.userId]=[]),n[this.userId].push(JSON.parse(JSON.stringify([this.userId,e])))}}},{key:"isDisconnected",value:function(){return null==t.users[this.userId]}},{key:"reconnect",value:function(){return this.isDisconnected()&&(t.addUser(this),o(Object.getPrototypeOf(c.prototype),"reconnect",this).call(this)),e.utils.globalRoom.flushAll()}},{key:"disconnect",value:function(){return this.isDisconnected()||(t.removeUser(this.userId),o(Object.getPrototypeOf(c.prototype),"disconnect",this).call(this)),this.y.db.whenTransactionsFinished()}},{key:"flush",value:function(){var e=this;return async(regeneratorRuntime.mark(function r(){var n,i,a;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:n=t.buffers[e.userId];case 1:if(!(Object.keys(n).length>0)){r.next=9;break}return i=getRandom(Object.keys(n)),a=n[i].shift(),0===n[i].length&&delete n[i],r.next=7,this.receiveMessage(a[0],a[1]);case 7:r.next=1;break;case 9:return r.next=11,e.whenTransactionsFinished();case 11:case"end":return r.stop()}},r,this)}))}}]),c}(e.AbstractConnector);e.Test=u}},{}],9:[function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,t){for(var r=0;r0||a.gc2.length>0?(a.y.connector.isSynced||console.warn("gc should be empty when not synced!"),new Promise(function(e){a.requestTransaction(regeneratorRuntime.mark(function t(){var r,n;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(null==a.y.connector||!a.y.connector.isSynced){t.next=10;break}r=0;case 2:if(!(r0&&(a.gcInterval=setTimeout(i,a.gcTimeout)),e();case 12:case"end":return t.stop()}},t,this)}))})):(a.gcTimeout>0&&(a.gcInterval=setTimeout(i,a.gcTimeout)),Promise.resolve())})}n(this,t),this.y=e;var a=this;this.userId=null;var s;this.userIdPromise=new Promise(function(e){s=e}),this.userIdPromise.resolve=s,this.forwardAppliedOperations=!1,this.listenersById={},this.listenersByIdExecuteNow=[],this.listenersByIdRequestPending=!1,this.initializedTypes={},this.waitingTransactions=[],this.transactionInProgress=!1,this.transactionIsFlushed=!1,"undefined"!=typeof YConcurrency_TestingMode&&(this.executeOrder=[]),this.gc1=[],this.gc2=[],this.gc=null==r.gc||r.gc,this.gc?this.gcTimeout=r.gcTimeout?r.gcTimeout:5e4:this.gcTimeout=-1,this.garbageCollect=i,this.gcTimeout>0&&i(),this.repairCheckInterval=r.repairCheckInterval?r.repairCheckInterval:6e3,this.opsReceivedTimestamp=new Date,this.startRepairCheck()}return i(t,[{key:"startRepairCheck",value:function(){var e=this;this.repairCheckInterval>0&&(this.repairCheckIntervalHandler=setInterval(function(){new Date-e.opsReceivedTimestamp>e.repairCheckInterval&&Object.keys(e.listenersById).length>0&&(e.listenersById={},e.opsReceivedTimestamp=new Date,e.y.connector.repair())},this.repairCheckInterval))}},{key:"stopRepairCheck",value:function(){clearInterval(this.repairCheckIntervalHandler)}},{key:"queueGarbageCollector",value:function(e){this.y.connector.isSynced&&this.gc&&this.gc1.push(e)}},{key:"emptyGarbageCollector",value:function(){var e=this;return new Promise(function(t){var r=function r(){e.gc1.length>0||e.gc2.length>0?e.garbageCollect().then(r):t()};setTimeout(r,0)})}},{key:"addToDebug",value:function(){if("undefined"!=typeof YConcurrency_TestingMode){var e=Array.prototype.map.call(arguments,function(e){return"string"==typeof e?e:JSON.stringify(e)}).join("").replace(/"/g,"'").replace(/,/g,", ").replace(/:/g,": ");this.executeOrder.push(e)}}},{key:"getDebugData",value:function(){console.log(this.executeOrder.join("\n"))}},{key:"stopGarbageCollector",value:function(){var e=this;return this.gc=!1,this.gcTimeout=-1,new Promise(function(t){e.requestTransaction(regeneratorRuntime.mark(function r(){var n,i,a;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:n=e.gc1.concat(e.gc2),e.gc1=[],e.gc2=[],i=0;case 4:if(!(i1)){e.next=10;break}return e.delegateYield(this.getInsertionCleanStart([t.id[0],t.id[1]+1]),"t0",8);case 8:t=e.t0,n=!0;case 10:
-if(!n){e.next=15;break}return t.gc=!0,e.delegateYield(this.setOperation(t),"t1",13);case 13:return this.store.queueGarbageCollector(t.id),e.abrupt("return",!0);case 15:return e.abrupt("return",!1);case 16:case"end":return e.stop()}},e,this)})},{key:"removeFromGarbageCollector",value:function(t){function r(r){return!e.utils.compareIds(r,t.id)}this.gc1=this.gc1.filter(r),this.gc2=this.gc2.filter(r),delete t.gc}},{key:"destroyTypes",value:function(){for(var e in this.initializedTypes){var t=this.initializedTypes[e];null!=t._destroy?t._destroy():console.error("The type you included does not provide destroy functionality, it will remain in memory (updating your packages will help).")}}},{key:"destroy",value:regeneratorRuntime.mark(function e(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:clearInterval(this.gcInterval),this.gcInterval=null,this.stopRepairCheck();case 3:case"end":return e.stop()}},e,this)})},{key:"setUserId",value:function(e){if(!this.userIdPromise.inProgress){this.userIdPromise.inProgress=!0;var t=this;t.requestTransaction(regeneratorRuntime.mark(function r(){var n;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return t.userId=e,r.delegateYield(this.getState(e),"t0",2);case 2:n=r.t0,t.opClock=n.clock,t.userIdPromise.resolve(e);case 5:case"end":return r.stop()}},r,this)}))}return this.userIdPromise}},{key:"whenUserIdSet",value:function(e){this.userIdPromise.then(e)}},{key:"getNextOpId",value:function(e){if(null==e)throw new Error("getNextOpId expects the number of created ids to create!");if(null==this.userId)throw new Error("OperationStore not yet initialized!");var t=[this.userId,this.opClock];return this.opClock+=e,t}},{key:"apply",value:function(t){this.opsReceivedTimestamp=new Date;for(var r=0;r0)for(var r={op:t,missing:e.length},n=0;n1)){r.next=84;break}return r.delegateYield(this.getInsertionCleanEnd(p.id),"t16",83);case 83:p=r.t16;case 84:this.store.removeFromGarbageCollector(p);case 85:return r.delegateYield(this.setOperation(p),"t17",86);case 86:if(null==n.parentSub){r.next=96;break}if(null!=h){r.next=90;break}return c.map[n.parentSub]=n.id,r.delegateYield(this.setOperation(c),"t18",90);case 90:if(null==n.right){r.next=92;break}return r.delegateYield(this.deleteOperation(n.right,1,!0),"t19",92);case 92:if(null==n.left){r.next=94;break}return r.delegateYield(this.deleteOperation(n.id,1,!0),"t20",94);case 94:r.next=100;break;case 96:if(null!=p&&null!=h){r.next=100;break}return null==p&&(c.end=e.utils.getLastId(n)),null==h&&(c.start=n.id),r.delegateYield(this.setOperation(c),"t21",100);case 100:i=0;case 101:if(!(i=0&&null!=i.right)){e.next=12;break}return e.delegateYield(this.getOperation(i.right),"t1",9);case 9:i=e.t1,e.next=13;break;case 12:return e.abrupt("break",15);case 13:e.next=5;break;case 15:return e.abrupt("return",n);case 16:case"end":return e.stop()}},e,this)}),map:regeneratorRuntime.mark(function e(t,r){var n,i;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:t=t.start,n=[];case 2:if(null==t){e.next=9;break}return e.delegateYield(this.getOperation(t),"t0",4);case 4:i=e.t0,i.deleted||n.push(r(i)),t=i.right,e.next=2;break;case 9:return e.abrupt("return",n);case 10:case"end":return e.stop()}},e,this)})},Map:{create:function(e){return{id:e,map:{},struct:"Map"}},encode:function(e){var t={struct:"Map",type:e.type,id:e.id,map:{}};return null!=e.requires&&(t.requires=e.requires),null!=e.info&&(t.info=e.info),t},requiredOps:function(){return[]},execute:regeneratorRuntime.mark(function e(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}},e,this)}),get:regeneratorRuntime.mark(function e(t,r){var n,i;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.map[r],null==n){e.next=14;break}return e.delegateYield(this.getOperation(n),"t0",3);case 3:if(i=e.t0,null!=i&&!i.deleted){e.next=8;break}return e.abrupt("return",void 0);case 8:if(null!=i.opContent){e.next=12;break}return e.abrupt("return",i.content[0]);case 12:return e.delegateYield(this.getType(i.opContent),"t1",13);case 13:return e.abrupt("return",e.t1);case 14:case"end":return e.stop()}},e,this)})}};e.Struct=t}},{}],11:[function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,t){for(var r=0;r0&&this.store.y.connector.broadcastOps(n);case 10:case"end":return t.stop()}},t,this)})},{key:"deleteList",value:regeneratorRuntime.mark(function e(t){var r;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(null==t){e.next=15;break}return e.delegateYield(this.getOperation(t),"t0",2);case 2:if(t=e.t0,t.gc){e.next=12;break}return t.gc=!0,t.deleted=!0,e.delegateYield(this.setOperation(t),"t1",7);case 7:return r=null!=t.content?t.content.length:1,e.delegateYield(this.markDeleted(t.id,r),"t2",9);case 9:if(null==t.opContent){e.next=11;break}return e.delegateYield(this.deleteOperation(t.opContent),"t3",11);case 11:this.store.queueGarbageCollector(t.id);case 12:t=t.right,e.next=0;break;case 15:case"end":return e.stop()}},e,this)})},{key:"deleteOperation",value:regeneratorRuntime.mark(function e(t,r,n){var i,a,s,o,u,c,l;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return null==r&&(r=1),e.delegateYield(this.markDeleted(t,r),"t0",2);case 2:if(!(r>0)){e.next=64;break}return i=!1,e.delegateYield(this.os.findWithUpperBound([t[0],t[1]+r-1]),"t1",5);case 5:if(a=e.t1,s=null!=a&&null!=a.content?a.content.length:1,!(null==a||a.id[0]!==t[0]||a.id[1]+s<=t[1])){e.next=12;break}a=null,r=0,e.next=22;break;case 12:if(a.deleted){e.next=21;break}if(!(a.id[1]t[1]+r)){e.next=21;break}return e.delegateYield(this.getInsertionCleanEnd([t[0],t[1]+r-1]),"t3",19);case 19:a=e.t3,s=a.content.length;case 21:r=a.id[1]-t[1];case 22:if(null==a){e.next=62;break}if(a.deleted){e.next=44;break}if(i=!0,a.deleted=!0,null==a.start){e.next=28;break}return e.delegateYield(this.deleteList(a.start),"t4",28);case 28:if(null==a.map){e.next=35;break}e.t5=regeneratorRuntime.keys(a.map);case 30:if((e.t6=e.t5()).done){e.next=35;break}return o=e.t6.value,e.delegateYield(this.deleteList(a.map[o]),"t7",33);case 33:e.next=30;break;case 35:if(null==a.opContent){e.next=37;break}return e.delegateYield(this.deleteOperation(a.opContent),"t8",37);case 37:if(null==a.requires){e.next=44;break}u=0;case 39:if(!(u0)){e.next=20;break}if(n.gc){e.next=11;break}n.len+=i,e.next=18;break;case 11:if(i=n.id[1]+n.len-t[1],!(i=a.id[1])){e.next=61;break}i=n.id[1]+n.len-a.id[1];case 33:if(!(i>=0)){e.next=61;break}if(!a.gc){e.next=44;break}if(n.len-=i,!(i>=a.len)){e.next=41;break}if(i-=a.len,!(i>0)){e.next=41;break}return e.delegateYield(this.ds.put(n),"t5",40);case 40:return e.delegateYield(this.markDeleted([a.id[0],a.id[1]+a.len],i),"t6",41);case 41:return e.abrupt("break",61);case 44:if(!(i>a.len)){e.next=56;break}return e.delegateYield(this.ds.findNext(a.id),"t7",46);case 46:return s=e.t7,e.delegateYield(this.ds.delete(a.id),"t8",48);case 48:if(null!=s&&n.id[0]===s.id[0]){e.next=52;break}return e.abrupt("break",61);case 52:a=s,i=n.id[1]+n.len-a.id[1];case 54:e.next=59;break;case 56:return n.len+=a.len-i,e.delegateYield(this.ds.delete(a.id),"t9",58);case 58:return e.abrupt("break",61);case 59:e.next=33;break;case 61:return e.delegateYield(this.ds.put(n),"t10",62);case 62:return e.abrupt("return",n);case 63:case"end":return e.stop()}},e,this)})},{key:"garbageCollectAfterSync",value:regeneratorRuntime.mark(function e(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if((this.store.gc1.length>0||this.store.gc2.length>0)&&console.warn("gc should be empty after sync"),this.store.gc){e.next=3;break}return e.abrupt("return");case 3:return e.delegateYield(this.os.iterate(this,null,null,regeneratorRuntime.mark(function e(t){var r,n,i;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.gc){e.next=3;break}return delete t.gc,e.delegateYield(this.setOperation(t),"t0",3);case 3:if(null==t.parent){e.next=23;break}return e.delegateYield(this.isDeleted(t.parent),"t1",5);case 5:if(r=e.t1,!r){e.next=23;break}if(t.gc=!0,t.deleted){e.next=20;break}return e.delegateYield(this.markDeleted(t.id,null!=t.content?t.content.length:1),"t2",10);case 10:if(t.deleted=!0,null==t.opContent){e.next=13;break}return e.delegateYield(this.deleteOperation(t.opContent),"t3",13);case 13:if(null==t.requires){e.next=20;break}n=0;case 15:if(!(n0)){t.next=60;break}c=n.left,l=null;case 39:if(null==c){t.next=47;break}return t.delegateYield(this.getInsertion(c),"t11",41);case 41:if(l=t.t11,!l.deleted){t.next=44;break}return t.abrupt("break",47);case 44:c=l.left,t.next=39;break;case 47:t.t12=regeneratorRuntime.keys(n.originOf);case 48:if((t.t13=t.t12()).done){t.next=57;break}return d=t.t13.value,t.delegateYield(this.getOperation(n.originOf[d]),"t14",51);case 51:if(f=t.t14,null==f){t.next=55;break}return f.origin=c,t.delegateYield(this.setOperation(f),"t15",55);case 55:t.next=48;break;case 57:if(null==c){t.next=60;break}return null==l.originOf?l.originOf=n.originOf:l.originOf=n.originOf.concat(l.originOf),t.delegateYield(this.setOperation(l),"t16",60);case 60:if(null==n.origin){t.next=65;break}return t.delegateYield(this.getInsertion(n.origin),"t17",62);case 62:return h=t.t17,h.originOf=h.originOf.filter(function(t){return!e.utils.compareIds(r,t)}),t.delegateYield(this.setOperation(h),"t18",65);case 65:if(null==n.parent){t.next=68;break}return t.delegateYield(this.getOperation(n.parent),"t19",67);case 67:p=t.t19;case 68:if(null==p){t.next=73;break}if(g=!1,null!=n.parentSub?e.utils.compareIds(p.map[n.parentSub],n.id)&&(g=!0,null!=n.right?p.map[n.parentSub]=n.right:delete p.map[n.parentSub]):(e.utils.compareIds(p.start,n.id)&&(g=!0,p.start=n.right),e.utils.matchesId(n,p.end)&&(g=!0,p.end=n.left)),!g){t.next=73;break}return t.delegateYield(this.setOperation(p),"t20",73);case 73:return t.delegateYield(this.removeOperation(n.id),"t21",74);case 74:case"end":return t.stop()}},t,this)})},{key:"checkDeleteStoreForState",value:regeneratorRuntime.mark(function e(t){var r;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.delegateYield(this.ds.findWithUpperBound([t.user,t.clock]),"t0",1);case 1:r=e.t0,null!=r&&r.id[0]===t.user&&r.gc&&(t.clock=Math.max(t.clock,r.id[1]+r.len));case 3:case"end":return e.stop()}},e,this)})},{key:"updateState",value:regeneratorRuntime.mark(function e(t){var r,n,i;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.delegateYield(this.getState(t),"t0",1);case 1:return r=e.t0,e.delegateYield(this.checkDeleteStoreForState(r),"t1",3);case 3:return e.delegateYield(this.getInsertion([t,r.clock]),"t2",4);case 4:n=e.t2,i=null!=n&&null!=n.content?n.content.length:1;case 6:if(!(null!=n&&t===n.id[0]&&n.id[1]<=r.clock&&n.id[1]+i>r.clock)){e.next=14;break}return r.clock+=i,e.delegateYield(this.checkDeleteStoreForState(r),"t3",9);case 9:return e.delegateYield(this.os.findNext(n.id),"t4",10);case 10:n=e.t4,i=null!=n&&null!=n.content?n.content.length:1,e.next=6;break;case 14:return e.delegateYield(this.setState(r),"t5",15);case 15:case"end":return e.stop()}},e,this)})},{key:"applyDeleteSet",value:regeneratorRuntime.mark(function e(t){var r,n,i,a,s,o,u,c,l,d,f;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:r=[],e.t0=regeneratorRuntime.keys(t);case 2:if((e.t1=e.t0()).done){e.next=11;break}return n=e.t1.value,i=t[n],a=0,s=i[a],e.delegateYield(this.ds.iterate(this,[n,0],[n,Number.MAX_VALUE],regeneratorRuntime.mark(function e(t){var o;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(null==s){e.next=10;break}if(o=0,!(t.id[1]+t.len<=s[0])){e.next=6;break}return e.abrupt("break",10);case 6:s[0]=u[1])){e.next=36;break}return e.delegateYield(this.os.findWithUpperBound([u[0],c-1]),"t5",20);case 20:if(l=e.t5,null!=l){e.next=23;break}return e.abrupt("break",36);case 23:if(d=null!=l.content?l.content.length:1,!(l.id[0]!==u[0]||l.id[1]+d<=u[1])){e.next=26;break}return e.abrupt("break",36);case 26:if(!(l.id[1]+d>u[1]+u[2])){e.next=29;break}return e.delegateYield(this.getInsertionCleanEnd([u[0],u[1]+u[2]-1]),"t6",28);case 28:l=e.t6;case 29:if(!(l.id[1]1)){t.next=15;break}return a=i[0],s=e.Struct[a].create(r),s.type=i[1],t.delegateYield(this.setOperation(s),"t1",12);case 12:return t.abrupt("return",s);case 15:return console.error("Unexpected case. How can this happen?"),t.abrupt("return",null);case 18:case"end":return t.stop()}},t,this)})},{key:"removeOperation",value:regeneratorRuntime.mark(function e(t){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.delegateYield(this.os.delete(t),"t0",1);case 1:case"end":return e.stop()}},e,this)})},{key:"setState",value:regeneratorRuntime.mark(function e(t){var r;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r={id:[t.user],clock:t.clock},e.delegateYield(this.ss.put(r),"t0",2);case 2:case"end":return e.stop()}},e,this)})},{key:"getState",value:regeneratorRuntime.mark(function e(t){var r,n;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.delegateYield(this.ss.find([t]),"t0",1);case 1:return r=e.t0,n=null==r?null:r.clock,null==n&&(n=0),e.abrupt("return",{user:t,clock:n});case 5:case"end":return e.stop()}},e,this)})},{key:"getStateVector",value:regeneratorRuntime.mark(function e(){var t;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=[],e.delegateYield(this.ss.iterate(this,null,null,regeneratorRuntime.mark(function e(r){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:t.push({user:r.id[0],clock:r.clock});case 1:case"end":return e.stop()}},e,this)})),"t0",2);case 2:return e.abrupt("return",t);case 3:case"end":return e.stop()}},e,this)})},{key:"getStateSet",value:regeneratorRuntime.mark(function e(){var t;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t={},e.delegateYield(this.ss.iterate(this,null,null,regeneratorRuntime.mark(function e(r){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:t[r.id[0]]=r.clock;case 1:case"end":return e.stop()}},e,this)})),"t0",2);case 2:return e.abrupt("return",t);case 3:case"end":return e.stop()}},e,this)})},{key:"getOperations",value:regeneratorRuntime.mark(function t(r){var n,i,a,s,o,u,c,l,d,f,h;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return null==r&&(r={}),n=[],t.delegateYield(this.getStateVector(),"t0",3);case 3:i=t.t0,a=!0,s=!1,o=void 0,t.prev=7,u=i[Symbol.iterator]();case 9:if(a=(c=u.next()).done){t.next=23;break}if(l=c.value,d=l.user,"_"!==d){t.next=14;break}return t.abrupt("continue",20);case 14:if(f=r[d]||0,!(f>0)){t.next=19;break}return t.delegateYield(this.getInsertion([d,f]),"t1",17);case 17:h=t.t1,null!=h&&(f=h.id[1],r[d]=f);case 19:return t.delegateYield(this.os.iterate(this,[d,f],[d,Number.MAX_VALUE],regeneratorRuntime.mark(function t(i){var a,s,o,u;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(i=e.Struct[i.struct].encode(i),"Insert"===i.struct){t.next=5;break}n.push(i),t.next=27;break;case 5:if(!(null==i.right||i.right[1]<(r[i.right[0]]||0))){t.next=27;break}a=i,s=[i],o=i.right;case 9:if(null!=a.left){t.next=15;break}return i.left=null,n.push(i),e.utils.compareIds(a.id,i.id)||(a=e.Struct[i.struct].encode(a),a.right=s[s.length-1].id,n.push(a)),t.abrupt("break",27);case 15:return t.delegateYield(this.getInsertion(a.left),"t0",16);case 16:for(a=t.t0;s.length>0&&e.utils.matchesId(a,s[s.length-1].origin);)s.pop();if(!(a.id[1]<(r[a.id[0]]||0))){t.next=24;break}return i.left=e.utils.getLastId(a),n.push(i),t.abrupt("break",27);case 24:e.utils.matchesId(a,i.origin)?(i.left=i.origin,n.push(i),i=e.Struct[i.struct].encode(a),i.right=o,s.length>0&&console.log("This should not happen .. :( please report this"),s=[i]):(u=e.Struct[i.struct].encode(a),u.right=s[s.length-1].id,u.left=u.origin,n.push(u),s.push(a));case 25:t.next=9;break;case 27:case"end":return t.stop()}},t,this)})),"t2",20);case 20:a=!0,t.next=9;break;case 23:t.next=29;break;case 25:t.prev=25,t.t3=t.catch(7),s=!0,o=t.t3;case 29:t.prev=29,t.prev=30,!a&&u.return&&u.return();case 32:if(t.prev=32,!s){t.next=35;break}throw o;case 35:return t.finish(32);case 36:return t.finish(29);case 37:return t.abrupt("return",n.reverse());case 38:case"end":return t.stop()}},t,this,[[7,25,29,37],[30,,32,36]])})},{key:"flush",value:regeneratorRuntime.mark(function e(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.delegateYield(this.os.flush(),"t0",1);case 1:return e.delegateYield(this.ss.flush(),"t1",2);case 2:return e.delegateYield(this.ds.flush(),"t2",3);case 3:case"end":return e.stop()}},e,this)})}]),t}();e.Transaction=t}},{}],12:[function(e,t,r){"use strict";function n(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(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&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},o=function e(t,r,n){null===t&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,r);if(void 0===i){var a=Object.getPrototypeOf(t);return null===a?void 0:e(a,r,n)}if("value"in i)return i.value;var s=i.get;if(void 0!==s)return s.call(n)},u=function(){function e(e,t){for(var r=0;r=e.id[1]&&t[1]=0)){e.next=10;break}if(a=this.readBuffer[i],a.id[1]!==r[1]||a.id[0]!==r[0]){e.next=7;break}for(;i=0)){e.next=19;break}if(a=this.writeBuffer[i],a.id[1]!==r[1]||a.id[0]!==r[0]){e.next=16;break}return s=a,e.abrupt("break",19);case 16:i--,e.next=11;break;case 19:if(!(i<0&&void 0===n)){e.next=22;break}return e.delegateYield(o(Object.getPrototypeOf(t.prototype),"find",this).call(this,r),"t0",21);case 21:s=e.t0;case 22:if(null!=s){for(i=0;i=0)){e.next=11;break}if(a=this.writeBuffer[i],a.id[1]!==n[1]||a.id[0]!==n[0]){e.next=8;break}for(;i>e/4).toString(16):([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,y)}e.utils={};var b=function(){function e(){a(this,e),this.eventListeners=[]}return u(e,[{key:"destroy",value:function(){this.eventListeners=null}},{key:"addEventListener",value:function(e){this.eventListeners.push(e)}},{key:"removeEventListener",value:function(e){this.eventListeners=this.eventListeners.filter(function(t){return e!==t})}},{key:"removeAllEventListeners",value:function(){this.eventListeners=[]}},{key:"callEventListeners",value:function(e){for(var t=0;t0;)for(var n=0;n0&&this.awaiting--,!(0===this.awaiting&&this.waiting.length>0)){t.next=70;break}o=0;case 7:if(!(o=0;a--){var s=this.waiting[a];"Insert"===s.struct&&(e.utils.matchesId(s,i.left)?(s.right=i.id,i.left=s.left):e.utils.compareIds(s.id,i.right)&&(s.left=e.utils.getLastId(i),i.right=s.right))}}this._tryCallEvents(t)}},{key:"awaitedDeletes",value:function(t,r){for(var n=this.waiting.splice(this.waiting.length-t),i=0;i0;)for(var n=0;n0&&this.awaiting--,0===this.awaiting&&this.waiting.length>0){var r=[],n=[];this.waiting.forEach(function(e){"Delete"===e.struct?n.push(e):r.push(e)}),r=t(r),r.forEach(this.onevent),n.forEach(this.onevent),this.waiting=[]}}}]),r}(b);e.utils.EventHandler=v;var m=function e(){a(this,e)};e.utils.CustomType=m;var k=function e(t){if(a(this,e),null==t.struct||null==t.initType||null==t.class||null==t.name||null==t.createType)throw new Error("Custom type was not initialized correctly!");this.struct=t.struct,this.initType=t.initType,this.createType=t.createType,this.class=t.class,this.name=t.name,null!=t.appendAdditionalInfo&&(this.appendAdditionalInfo=t.appendAdditionalInfo),this.parseArguments=(t.parseArguments||function(){return[this]}).bind(this),this.parseArguments.typeDefinition=this};e.utils.CustomTypeDefinition=k,e.utils.isTypeDefinition=function(t){if(null!=t){if(t instanceof e.utils.CustomTypeDefinition)return[t];if(t.constructor===Array&&t[0]instanceof e.utils.CustomTypeDefinition)return t;if(t instanceof Function&&t.typeDefinition instanceof e.utils.CustomTypeDefinition)return[t.typeDefinition]}return!1},e.utils.copyObject=t,e.utils.copyOperation=r,e.utils.smaller=c,e.utils.inDeletionRange=l,e.utils.compareIds=d,e.utils.matchesId=f,e.utils.getLastId=h,e.utils.createSmallLookupBuffer=g,e.utils.generateGuid=y}},{}],13:[function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(t){var r;r=null===a.sourceDir?null:a.sourceDir||"/bower_components";for(var n="undefined"!=typeof regeneratorRuntime?".js":".es6",i=[],s=0;s 0) {
+ return parse(val)
+ } else if (type === 'number' && isNaN(val) === false) {
+ return options.long ?
+ fmtLong(val) :
+ fmtShort(val)
+ }
+ throw new Error('val is not a non-empty string or a valid number. val=' + JSON.stringify(val))
+}
+
+/**
+ * Parse the given `str` and return milliseconds.
+ *
+ * @param {String} str
+ * @return {Number}
+ * @api private
+ */
+
+function parse(str) {
+ str = String(str)
+ if (str.length > 10000) {
+ return
+ }
+ var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str)
+ if (!match) {
+ return
+ }
+ var n = parseFloat(match[1])
+ var type = (match[2] || 'ms').toLowerCase()
+ switch (type) {
+ case 'years':
+ case 'year':
+ case 'yrs':
+ case 'yr':
+ case 'y':
+ return n * y
+ case 'days':
+ case 'day':
+ case 'd':
+ return n * d
+ case 'hours':
+ case 'hour':
+ case 'hrs':
+ case 'hr':
+ case 'h':
+ return n * h
+ case 'minutes':
+ case 'minute':
+ case 'mins':
+ case 'min':
+ case 'm':
+ return n * m
+ case 'seconds':
+ case 'second':
+ case 'secs':
+ case 'sec':
+ case 's':
+ return n * s
+ case 'milliseconds':
+ case 'millisecond':
+ case 'msecs':
+ case 'msec':
+ case 'ms':
+ return n
+ default:
+ return undefined
+ }
+}
+
+/**
+ * Short format for `ms`.
+ *
+ * @param {Number} ms
+ * @return {String}
+ * @api private
+ */
+
+function fmtShort(ms) {
+ if (ms >= d) {
+ return Math.round(ms / d) + 'd'
+ }
+ if (ms >= h) {
+ return Math.round(ms / h) + 'h'
+ }
+ if (ms >= m) {
+ return Math.round(ms / m) + 'm'
+ }
+ if (ms >= s) {
+ return Math.round(ms / s) + 's'
+ }
+ return ms + 'ms'
+}
+
+/**
+ * Long format for `ms`.
+ *
+ * @param {Number} ms
+ * @return {String}
+ * @api private
+ */
+
+function fmtLong(ms) {
+ return plural(ms, d, 'day') ||
+ plural(ms, h, 'hour') ||
+ plural(ms, m, 'minute') ||
+ plural(ms, s, 'second') ||
+ ms + ' ms'
+}
+
+/**
+ * Pluralization helper.
+ */
+
+function plural(ms, n, name) {
+ if (ms < n) {
+ return
+ }
+ if (ms < n * 1.5) {
+ return Math.floor(ms / n) + ' ' + name
+ }
+ return Math.ceil(ms / n) + ' ' + name + 's'
+}
+
+},{}],2:[function(require,module,exports){
+(function (process){
+'use strict';
+
+var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
+
+/**
+ * This is the web browser implementation of `debug()`.
+ *
+ * Expose `debug()` as the module.
+ */
+
+exports = module.exports = require('./debug');
+exports.log = log;
+exports.formatArgs = formatArgs;
+exports.save = save;
+exports.load = load;
+exports.useColors = useColors;
+exports.storage = 'undefined' != typeof chrome && 'undefined' != typeof chrome.storage ? chrome.storage.local : localstorage();
+
+/**
+ * Colors.
+ */
+
+exports.colors = ['lightseagreen', 'forestgreen', 'goldenrod', 'dodgerblue', 'darkorchid', 'crimson'];
+
+/**
+ * Currently only WebKit-based Web Inspectors, Firefox >= v31,
+ * and the Firebug extension (any Firefox version) are known
+ * to support "%c" CSS customizations.
+ *
+ * TODO: add a `localStorage` variable to explicitly enable/disable colors
+ */
+
+function useColors() {
+ // NB: In an Electron preload script, document will be defined but not fully
+ // initialized. Since we know we're in Chrome, we'll just detect this case
+ // explicitly
+ if (typeof window !== 'undefined' && window && typeof window.process !== 'undefined' && window.process.type === 'renderer') {
+ return true;
+ }
+
+ // is webkit? http://stackoverflow.com/a/16459606/376773
+ // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
+ return typeof document !== 'undefined' && document && 'WebkitAppearance' in document.documentElement.style ||
+ // is firebug? http://stackoverflow.com/a/398120/376773
+ typeof window !== 'undefined' && window && window.console && (console.firebug || console.exception && console.table) ||
+ // is firefox >= v31?
+ // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
+ typeof navigator !== 'undefined' && navigator && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 ||
+ // double check webkit in userAgent just in case we are in a worker
+ typeof navigator !== 'undefined' && navigator && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
+}
+
+/**
+ * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
+ */
+
+exports.formatters.j = function (v) {
+ try {
+ return JSON.stringify(v);
+ } catch (err) {
+ return '[UnexpectedJSONParseError]: ' + err.message;
+ }
+};
+
+/**
+ * Colorize log arguments if enabled.
+ *
+ * @api public
+ */
+
+function formatArgs(args) {
+ var useColors = this.useColors;
+
+ args[0] = (useColors ? '%c' : '') + this.namespace + (useColors ? ' %c' : ' ') + args[0] + (useColors ? '%c ' : ' ') + '+' + exports.humanize(this.diff);
+
+ if (!useColors) return;
+
+ var c = 'color: ' + this.color;
+ args.splice(1, 0, c, 'color: inherit');
+
+ // the final "%c" is somewhat tricky, because there could be other
+ // arguments passed either before or after the %c, so we need to
+ // figure out the correct index to insert the CSS into
+ var index = 0;
+ var lastC = 0;
+ args[0].replace(/%[a-zA-Z%]/g, function (match) {
+ if ('%%' === match) return;
+ index++;
+ if ('%c' === match) {
+ // we only are interested in the *last* %c
+ // (the user may have provided their own)
+ lastC = index;
+ }
+ });
+
+ args.splice(lastC, 0, c);
+}
+
+/**
+ * Invokes `console.log()` when available.
+ * No-op when `console.log` is not a "function".
+ *
+ * @api public
+ */
+
+function log() {
+ // this hackery is required for IE8/9, where
+ // the `console.log` function doesn't have 'apply'
+ return 'object' === (typeof console === 'undefined' ? 'undefined' : _typeof(console)) && console.log && Function.prototype.apply.call(console.log, console, arguments);
+}
+
+/**
+ * Save `namespaces`.
+ *
+ * @param {String} namespaces
+ * @api private
+ */
+
+function save(namespaces) {
+ try {
+ if (null == namespaces) {
+ exports.storage.removeItem('debug');
+ } else {
+ exports.storage.debug = namespaces;
+ }
+ } catch (e) {}
+}
+
+/**
+ * Load `namespaces`.
+ *
+ * @return {String} returns the previously persisted debug modes
+ * @api private
+ */
+
+function load() {
+ var r;
+ try {
+ r = exports.storage.debug;
+ } catch (e) {}
+
+ // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
+ if (!r && typeof process !== 'undefined' && 'env' in process) {
+ r = process.env.DEBUG;
+ }
+
+ return r;
+}
+
+/**
+ * Enable namespaces listed in `localStorage.debug` initially.
+ */
+
+exports.enable(load());
+
+/**
+ * Localstorage attempts to return the localstorage.
+ *
+ * This is necessary because safari throws
+ * when a user disables cookies/localstorage
+ * and you attempt to access it.
+ *
+ * @return {LocalStorage}
+ * @api private
+ */
+
+function localstorage() {
+ try {
+ return window.localStorage;
+ } catch (e) {}
+}
+
+}).call(this,require('_process'))
+
+},{"./debug":3,"_process":4}],3:[function(require,module,exports){
+'use strict';
+
+/**
+ * This is the common logic for both the Node.js and web browser
+ * implementations of `debug()`.
+ *
+ * Expose `debug()` as the module.
+ */
+
+exports = module.exports = createDebug.debug = createDebug['default'] = createDebug;
+exports.coerce = coerce;
+exports.disable = disable;
+exports.enable = enable;
+exports.enabled = enabled;
+exports.humanize = require('ms');
+
+/**
+ * The currently active debug mode names, and names to skip.
+ */
+
+exports.names = [];
+exports.skips = [];
+
+/**
+ * Map of special "%n" handling functions, for the debug "format" argument.
+ *
+ * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
+ */
+
+exports.formatters = {};
+
+/**
+ * Previous log timestamp.
+ */
+
+var prevTime;
+
+/**
+ * Select a color.
+ * @param {String} namespace
+ * @return {Number}
+ * @api private
+ */
+
+function selectColor(namespace) {
+ var hash = 0,
+ i;
+
+ for (i in namespace) {
+ hash = (hash << 5) - hash + namespace.charCodeAt(i);
+ hash |= 0; // Convert to 32bit integer
+ }
+
+ return exports.colors[Math.abs(hash) % exports.colors.length];
+}
+
+/**
+ * Create a debugger with the given `namespace`.
+ *
+ * @param {String} namespace
+ * @return {Function}
+ * @api public
+ */
+
+function createDebug(namespace) {
+
+ function debug() {
+ // disabled?
+ if (!debug.enabled) return;
+
+ var self = debug;
+
+ // set `diff` timestamp
+ var curr = +new Date();
+ var ms = curr - (prevTime || curr);
+ self.diff = ms;
+ self.prev = prevTime;
+ self.curr = curr;
+ prevTime = curr;
+
+ // turn the `arguments` into a proper Array
+ var args = new Array(arguments.length);
+ for (var i = 0; i < args.length; i++) {
+ args[i] = arguments[i];
+ }
+
+ args[0] = exports.coerce(args[0]);
+
+ if ('string' !== typeof args[0]) {
+ // anything else let's inspect with %O
+ args.unshift('%O');
+ }
+
+ // apply any `formatters` transformations
+ var index = 0;
+ args[0] = args[0].replace(/%([a-zA-Z%])/g, function (match, format) {
+ // if we encounter an escaped % then don't increase the array index
+ if (match === '%%') return match;
+ index++;
+ var formatter = exports.formatters[format];
+ if ('function' === typeof formatter) {
+ var val = args[index];
+ match = formatter.call(self, val);
+
+ // now we need to remove `args[index]` since it's inlined in the `format`
+ args.splice(index, 1);
+ index--;
+ }
+ return match;
+ });
+
+ // apply env-specific formatting (colors, etc.)
+ exports.formatArgs.call(self, args);
+
+ var logFn = debug.log || exports.log || console.log.bind(console);
+ logFn.apply(self, args);
+ }
+
+ debug.namespace = namespace;
+ debug.enabled = exports.enabled(namespace);
+ debug.useColors = exports.useColors();
+ debug.color = selectColor(namespace);
+
+ // env-specific initialization logic for debug instances
+ if ('function' === typeof exports.init) {
+ exports.init(debug);
+ }
+
+ return debug;
+}
+
+/**
+ * Enables a debug mode by namespaces. This can include modes
+ * separated by a colon and wildcards.
+ *
+ * @param {String} namespaces
+ * @api public
+ */
+
+function enable(namespaces) {
+ exports.save(namespaces);
+
+ exports.names = [];
+ exports.skips = [];
+
+ var split = (namespaces || '').split(/[\s,]+/);
+ var len = split.length;
+
+ for (var i = 0; i < len; i++) {
+ if (!split[i]) continue; // ignore empty strings
+ namespaces = split[i].replace(/\*/g, '.*?');
+ if (namespaces[0] === '-') {
+ exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
+ } else {
+ exports.names.push(new RegExp('^' + namespaces + '$'));
+ }
+ }
+}
+
+/**
+ * Disable debug output.
+ *
+ * @api public
+ */
+
+function disable() {
+ exports.enable('');
+}
+
+/**
+ * Returns true if the given mode name is enabled, false otherwise.
+ *
+ * @param {String} name
+ * @return {Boolean}
+ * @api public
+ */
+
+function enabled(name) {
+ var i, len;
+ for (i = 0, len = exports.skips.length; i < len; i++) {
+ if (exports.skips[i].test(name)) {
+ return false;
+ }
+ }
+ for (i = 0, len = exports.names.length; i < len; i++) {
+ if (exports.names[i].test(name)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+/**
+ * Coerce `val`.
+ *
+ * @param {Mixed} val
+ * @return {Mixed}
+ * @api private
+ */
+
+function coerce(val) {
+ if (val instanceof Error) return val.stack || val.message;
+ return val;
+}
+
+},{"ms":1}],4:[function(require,module,exports){
+// shim for using process in browser
+var process = module.exports = {};
+
+// cached from whatever global is present so that test runners that stub it
+// don't break things. But we need to wrap it in a try catch in case it is
+// wrapped in strict mode code which doesn't define any globals. It's inside a
+// function because try/catches deoptimize in certain engines.
+
+var cachedSetTimeout;
+var cachedClearTimeout;
+
+(function () {
+ try {
+ cachedSetTimeout = setTimeout;
+ } catch (e) {
+ cachedSetTimeout = function () {
+ throw new Error('setTimeout is not defined');
+ }
+ }
+ try {
+ cachedClearTimeout = clearTimeout;
+ } catch (e) {
+ cachedClearTimeout = function () {
+ throw new Error('clearTimeout is not defined');
+ }
+ }
+} ())
+function runTimeout(fun) {
+ if (cachedSetTimeout === setTimeout) {
+ return setTimeout(fun, 0);
+ } else {
+ return cachedSetTimeout.call(null, fun, 0);
+ }
+}
+function runClearTimeout(marker) {
+ if (cachedClearTimeout === clearTimeout) {
+ clearTimeout(marker);
+ } else {
+ cachedClearTimeout.call(null, marker);
+ }
+}
+var queue = [];
+var draining = false;
+var currentQueue;
+var queueIndex = -1;
+
+function cleanUpNextTick() {
+ if (!draining || !currentQueue) {
+ return;
+ }
+ draining = false;
+ if (currentQueue.length) {
+ queue = currentQueue.concat(queue);
+ } else {
+ queueIndex = -1;
+ }
+ if (queue.length) {
+ drainQueue();
+ }
+}
+
+function drainQueue() {
+ if (draining) {
+ return;
+ }
+ var timeout = runTimeout(cleanUpNextTick);
+ draining = true;
+
+ var len = queue.length;
+ while(len) {
+ currentQueue = queue;
+ queue = [];
+ while (++queueIndex < len) {
+ if (currentQueue) {
+ currentQueue[queueIndex].run();
+ }
+ }
+ queueIndex = -1;
+ len = queue.length;
+ }
+ currentQueue = null;
+ draining = false;
+ runClearTimeout(timeout);
+}
+
+process.nextTick = function (fun) {
+ var args = new Array(arguments.length - 1);
+ if (arguments.length > 1) {
+ for (var i = 1; i < arguments.length; i++) {
+ args[i - 1] = arguments[i];
+ }
+ }
+ queue.push(new Item(fun, args));
+ if (queue.length === 1 && !draining) {
+ runTimeout(drainQueue);
+ }
+};
+
+// v8 likes predictible objects
+function Item(fun, array) {
+ this.fun = fun;
+ this.array = array;
+}
+Item.prototype.run = function () {
+ this.fun.apply(null, this.array);
+};
+process.title = 'browser';
+process.browser = true;
+process.env = {};
+process.argv = [];
+process.version = ''; // empty string to avoid regexp issues
+process.versions = {};
+
+function noop() {}
+
+process.on = noop;
+process.addListener = noop;
+process.once = noop;
+process.off = noop;
+process.removeListener = noop;
+process.removeAllListeners = noop;
+process.emit = noop;
+
+process.binding = function (name) {
+ throw new Error('process.binding is not supported');
+};
+
+process.cwd = function () { return '/' };
+process.chdir = function (dir) {
+ throw new Error('process.chdir is not supported');
+};
+process.umask = function() { return 0; };
+
+},{}],5:[function(require,module,exports){
+(function (process,global){
+"use strict";
+
+var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
+
+/**
+ * Copyright (c) 2014, Facebook, Inc.
+ * All rights reserved.
+ *
+ * This source code is licensed under the BSD-style license found in the
+ * https://raw.github.com/facebook/regenerator/master/LICENSE file. An
+ * additional grant of patent rights can be found in the PATENTS file in
+ * the same directory.
+ */
+
+!function (global) {
+ "use strict";
+
+ var hasOwn = Object.prototype.hasOwnProperty;
+ var undefined; // More compressible than void 0.
+ var $Symbol = typeof Symbol === "function" ? Symbol : {};
+ var iteratorSymbol = $Symbol.iterator || "@@iterator";
+ var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
+
+ var inModule = (typeof module === "undefined" ? "undefined" : _typeof(module)) === "object";
+ var runtime = global.regeneratorRuntime;
+ if (runtime) {
+ if (inModule) {
+ // If regeneratorRuntime is defined globally and we're in a module,
+ // make the exports object identical to regeneratorRuntime.
+ module.exports = runtime;
+ }
+ // Don't bother evaluating the rest of this file if the runtime was
+ // already defined globally.
+ return;
+ }
+
+ // Define the runtime globally (as expected by generated code) as either
+ // module.exports (if we're in a module) or a new, empty object.
+ runtime = global.regeneratorRuntime = inModule ? module.exports : {};
+
+ function wrap(innerFn, outerFn, self, tryLocsList) {
+ // If outerFn provided, then outerFn.prototype instanceof Generator.
+ var generator = Object.create((outerFn || Generator).prototype);
+ var context = new Context(tryLocsList || []);
+
+ // The ._invoke method unifies the implementations of the .next,
+ // .throw, and .return methods.
+ generator._invoke = makeInvokeMethod(innerFn, self, context);
+
+ return generator;
+ }
+ runtime.wrap = wrap;
+
+ // Try/catch helper to minimize deoptimizations. Returns a completion
+ // record like context.tryEntries[i].completion. This interface could
+ // have been (and was previously) designed to take a closure to be
+ // invoked without arguments, but in all the cases we care about we
+ // already have an existing method we want to call, so there's no need
+ // to create a new function object. We can even get away with assuming
+ // the method takes exactly one argument, since that happens to be true
+ // in every case, so we don't have to touch the arguments object. The
+ // only additional allocation required is the completion record, which
+ // has a stable shape and so hopefully should be cheap to allocate.
+ function tryCatch(fn, obj, arg) {
+ try {
+ return { type: "normal", arg: fn.call(obj, arg) };
+ } catch (err) {
+ return { type: "throw", arg: err };
+ }
+ }
+
+ var GenStateSuspendedStart = "suspendedStart";
+ var GenStateSuspendedYield = "suspendedYield";
+ var GenStateExecuting = "executing";
+ var GenStateCompleted = "completed";
+
+ // Returning this object from the innerFn has the same effect as
+ // breaking out of the dispatch switch statement.
+ var ContinueSentinel = {};
+
+ // Dummy constructor functions that we use as the .constructor and
+ // .constructor.prototype properties for functions that return Generator
+ // objects. For full spec compliance, you may wish to configure your
+ // minifier not to mangle the names of these two functions.
+ function Generator() {}
+ function GeneratorFunction() {}
+ function GeneratorFunctionPrototype() {}
+
+ var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype;
+ GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
+ GeneratorFunctionPrototype.constructor = GeneratorFunction;
+ GeneratorFunctionPrototype[toStringTagSymbol] = GeneratorFunction.displayName = "GeneratorFunction";
+
+ // Helper for defining the .next, .throw, and .return methods of the
+ // Iterator interface in terms of a single ._invoke method.
+ function defineIteratorMethods(prototype) {
+ ["next", "throw", "return"].forEach(function (method) {
+ prototype[method] = function (arg) {
+ return this._invoke(method, arg);
+ };
+ });
+ }
+
+ runtime.isGeneratorFunction = function (genFun) {
+ var ctor = typeof genFun === "function" && genFun.constructor;
+ return ctor ? ctor === GeneratorFunction ||
+ // For the native GeneratorFunction constructor, the best we can
+ // do is to check its .name property.
+ (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
+ };
+
+ runtime.mark = function (genFun) {
+ if (Object.setPrototypeOf) {
+ Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
+ } else {
+ genFun.__proto__ = GeneratorFunctionPrototype;
+ if (!(toStringTagSymbol in genFun)) {
+ genFun[toStringTagSymbol] = "GeneratorFunction";
+ }
+ }
+ genFun.prototype = Object.create(Gp);
+ return genFun;
+ };
+
+ // Within the body of any async function, `await x` is transformed to
+ // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
+ // `value instanceof AwaitArgument` to determine if the yielded value is
+ // meant to be awaited. Some may consider the name of this method too
+ // cutesy, but they are curmudgeons.
+ runtime.awrap = function (arg) {
+ return new AwaitArgument(arg);
+ };
+
+ function AwaitArgument(arg) {
+ this.arg = arg;
+ }
+
+ function AsyncIterator(generator) {
+ function invoke(method, arg, resolve, reject) {
+ var record = tryCatch(generator[method], generator, arg);
+ if (record.type === "throw") {
+ reject(record.arg);
+ } else {
+ var result = record.arg;
+ var value = result.value;
+ if (value instanceof AwaitArgument) {
+ return Promise.resolve(value.arg).then(function (value) {
+ invoke("next", value, resolve, reject);
+ }, function (err) {
+ invoke("throw", err, resolve, reject);
+ });
+ }
+
+ return Promise.resolve(value).then(function (unwrapped) {
+ // When a yielded Promise is resolved, its final value becomes
+ // the .value of the Promise<{value,done}> result for the
+ // current iteration. If the Promise is rejected, however, the
+ // result for this iteration will be rejected with the same
+ // reason. Note that rejections of yielded Promises are not
+ // thrown back into the generator function, as is the case
+ // when an awaited Promise is rejected. This difference in
+ // behavior between yield and await is important, because it
+ // allows the consumer to decide what to do with the yielded
+ // rejection (swallow it and continue, manually .throw it back
+ // into the generator, abandon iteration, whatever). With
+ // await, by contrast, there is no opportunity to examine the
+ // rejection reason outside the generator function, so the
+ // only option is to throw it from the await expression, and
+ // let the generator function handle the exception.
+ result.value = unwrapped;
+ resolve(result);
+ }, reject);
+ }
+ }
+
+ if ((typeof process === "undefined" ? "undefined" : _typeof(process)) === "object" && process.domain) {
+ invoke = process.domain.bind(invoke);
+ }
+
+ var previousPromise;
+
+ function enqueue(method, arg) {
+ function callInvokeWithMethodAndArg() {
+ return new Promise(function (resolve, reject) {
+ invoke(method, arg, resolve, reject);
+ });
+ }
+
+ return previousPromise =
+ // If enqueue has been called before, then we want to wait until
+ // all previous Promises have been resolved before calling invoke,
+ // so that results are always delivered in the correct order. If
+ // enqueue has not been called before, then it is important to
+ // call invoke immediately, without waiting on a callback to fire,
+ // so that the async generator function has the opportunity to do
+ // any necessary setup in a predictable way. This predictability
+ // is why the Promise constructor synchronously invokes its
+ // executor callback, and why async functions synchronously
+ // execute code before the first await. Since we implement simple
+ // async functions in terms of async generators, it is especially
+ // important to get this right, even though it requires care.
+ previousPromise ? previousPromise.then(callInvokeWithMethodAndArg,
+ // Avoid propagating failures to Promises returned by later
+ // invocations of the iterator.
+ callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
+ }
+
+ // Define the unified helper method that is used to implement .next,
+ // .throw, and .return (see defineIteratorMethods).
+ this._invoke = enqueue;
+ }
+
+ defineIteratorMethods(AsyncIterator.prototype);
+
+ // Note that simple async functions are implemented on top of
+ // AsyncIterator objects; they just return a Promise for the value of
+ // the final result produced by the iterator.
+ runtime.async = function (innerFn, outerFn, self, tryLocsList) {
+ var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList));
+
+ return runtime.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
+ : iter.next().then(function (result) {
+ return result.done ? result.value : iter.next();
+ });
+ };
+
+ function makeInvokeMethod(innerFn, self, context) {
+ var state = GenStateSuspendedStart;
+
+ return function invoke(method, arg) {
+ if (state === GenStateExecuting) {
+ throw new Error("Generator is already running");
+ }
+
+ if (state === GenStateCompleted) {
+ if (method === "throw") {
+ throw arg;
+ }
+
+ // Be forgiving, per 25.3.3.3.3 of the spec:
+ // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
+ return doneResult();
+ }
+
+ while (true) {
+ var delegate = context.delegate;
+ if (delegate) {
+ if (method === "return" || method === "throw" && delegate.iterator[method] === undefined) {
+ // A return or throw (when the delegate iterator has no throw
+ // method) always terminates the yield* loop.
+ context.delegate = null;
+
+ // If the delegate iterator has a return method, give it a
+ // chance to clean up.
+ var returnMethod = delegate.iterator["return"];
+ if (returnMethod) {
+ var record = tryCatch(returnMethod, delegate.iterator, arg);
+ if (record.type === "throw") {
+ // If the return method threw an exception, let that
+ // exception prevail over the original return or throw.
+ method = "throw";
+ arg = record.arg;
+ continue;
+ }
+ }
+
+ if (method === "return") {
+ // Continue with the outer return, now that the delegate
+ // iterator has been terminated.
+ continue;
+ }
+ }
+
+ var record = tryCatch(delegate.iterator[method], delegate.iterator, arg);
+
+ if (record.type === "throw") {
+ context.delegate = null;
+
+ // Like returning generator.throw(uncaught), but without the
+ // overhead of an extra function call.
+ method = "throw";
+ arg = record.arg;
+ continue;
+ }
+
+ // Delegate generator ran and handled its own exceptions so
+ // regardless of what the method was, we continue as if it is
+ // "next" with an undefined arg.
+ method = "next";
+ arg = undefined;
+
+ var info = record.arg;
+ if (info.done) {
+ context[delegate.resultName] = info.value;
+ context.next = delegate.nextLoc;
+ } else {
+ state = GenStateSuspendedYield;
+ return info;
+ }
+
+ context.delegate = null;
+ }
+
+ if (method === "next") {
+ // Setting context._sent for legacy support of Babel's
+ // function.sent implementation.
+ context.sent = context._sent = arg;
+ } else if (method === "throw") {
+ if (state === GenStateSuspendedStart) {
+ state = GenStateCompleted;
+ throw arg;
+ }
+
+ if (context.dispatchException(arg)) {
+ // If the dispatched exception was caught by a catch block,
+ // then let that catch block handle the exception normally.
+ method = "next";
+ arg = undefined;
+ }
+ } else if (method === "return") {
+ context.abrupt("return", arg);
+ }
+
+ state = GenStateExecuting;
+
+ var record = tryCatch(innerFn, self, context);
+ if (record.type === "normal") {
+ // If an exception is thrown from innerFn, we leave state ===
+ // GenStateExecuting and loop back for another invocation.
+ state = context.done ? GenStateCompleted : GenStateSuspendedYield;
+
+ var info = {
+ value: record.arg,
+ done: context.done
+ };
+
+ if (record.arg === ContinueSentinel) {
+ if (context.delegate && method === "next") {
+ // Deliberately forget the last sent value so that we don't
+ // accidentally pass it on to the delegate.
+ arg = undefined;
+ }
+ } else {
+ return info;
+ }
+ } else if (record.type === "throw") {
+ state = GenStateCompleted;
+ // Dispatch the exception by looping back around to the
+ // context.dispatchException(arg) call above.
+ method = "throw";
+ arg = record.arg;
+ }
+ }
+ };
+ }
+
+ // Define Generator.prototype.{next,throw,return} in terms of the
+ // unified ._invoke helper method.
+ defineIteratorMethods(Gp);
+
+ Gp[iteratorSymbol] = function () {
+ return this;
+ };
+
+ Gp[toStringTagSymbol] = "Generator";
+
+ Gp.toString = function () {
+ return "[object Generator]";
+ };
+
+ function pushTryEntry(locs) {
+ var entry = { tryLoc: locs[0] };
+
+ if (1 in locs) {
+ entry.catchLoc = locs[1];
+ }
+
+ if (2 in locs) {
+ entry.finallyLoc = locs[2];
+ entry.afterLoc = locs[3];
+ }
+
+ this.tryEntries.push(entry);
+ }
+
+ function resetTryEntry(entry) {
+ var record = entry.completion || {};
+ record.type = "normal";
+ delete record.arg;
+ entry.completion = record;
+ }
+
+ function Context(tryLocsList) {
+ // The root entry object (effectively a try statement without a catch
+ // or a finally block) gives us a place to store values thrown from
+ // locations where there is no enclosing try statement.
+ this.tryEntries = [{ tryLoc: "root" }];
+ tryLocsList.forEach(pushTryEntry, this);
+ this.reset(true);
+ }
+
+ runtime.keys = function (object) {
+ var keys = [];
+ for (var key in object) {
+ keys.push(key);
+ }
+ keys.reverse();
+
+ // Rather than returning an object with a next method, we keep
+ // things simple and return the next function itself.
+ return function next() {
+ while (keys.length) {
+ var key = keys.pop();
+ if (key in object) {
+ next.value = key;
+ next.done = false;
+ return next;
+ }
+ }
+
+ // To avoid creating an additional object, we just hang the .value
+ // and .done properties off the next function object itself. This
+ // also ensures that the minifier will not anonymize the function.
+ next.done = true;
+ return next;
+ };
+ };
+
+ function values(iterable) {
+ if (iterable) {
+ var iteratorMethod = iterable[iteratorSymbol];
+ if (iteratorMethod) {
+ return iteratorMethod.call(iterable);
+ }
+
+ if (typeof iterable.next === "function") {
+ return iterable;
+ }
+
+ if (!isNaN(iterable.length)) {
+ var i = -1,
+ next = function next() {
+ while (++i < iterable.length) {
+ if (hasOwn.call(iterable, i)) {
+ next.value = iterable[i];
+ next.done = false;
+ return next;
+ }
+ }
+
+ next.value = undefined;
+ next.done = true;
+
+ return next;
+ };
+
+ return next.next = next;
+ }
+ }
+
+ // Return an iterator with no values.
+ return { next: doneResult };
+ }
+ runtime.values = values;
+
+ function doneResult() {
+ return { value: undefined, done: true };
+ }
+
+ Context.prototype = {
+ constructor: Context,
+
+ reset: function reset(skipTempReset) {
+ this.prev = 0;
+ this.next = 0;
+ // Resetting context._sent for legacy support of Babel's
+ // function.sent implementation.
+ this.sent = this._sent = undefined;
+ this.done = false;
+ this.delegate = null;
+
+ this.tryEntries.forEach(resetTryEntry);
+
+ if (!skipTempReset) {
+ for (var name in this) {
+ // Not sure about the optimal order of these conditions:
+ if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
+ this[name] = undefined;
+ }
+ }
+ }
+ },
+
+ stop: function stop() {
+ this.done = true;
+
+ var rootEntry = this.tryEntries[0];
+ var rootRecord = rootEntry.completion;
+ if (rootRecord.type === "throw") {
+ throw rootRecord.arg;
+ }
+
+ return this.rval;
+ },
+
+ dispatchException: function dispatchException(exception) {
+ if (this.done) {
+ throw exception;
+ }
+
+ var context = this;
+ function handle(loc, caught) {
+ record.type = "throw";
+ record.arg = exception;
+ context.next = loc;
+ return !!caught;
+ }
+
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
+ var entry = this.tryEntries[i];
+ var record = entry.completion;
+
+ if (entry.tryLoc === "root") {
+ // Exception thrown outside of any try block that could handle
+ // it, so set the completion value of the entire function to
+ // throw the exception.
+ return handle("end");
+ }
+
+ if (entry.tryLoc <= this.prev) {
+ var hasCatch = hasOwn.call(entry, "catchLoc");
+ var hasFinally = hasOwn.call(entry, "finallyLoc");
+
+ if (hasCatch && hasFinally) {
+ if (this.prev < entry.catchLoc) {
+ return handle(entry.catchLoc, true);
+ } else if (this.prev < entry.finallyLoc) {
+ return handle(entry.finallyLoc);
+ }
+ } else if (hasCatch) {
+ if (this.prev < entry.catchLoc) {
+ return handle(entry.catchLoc, true);
+ }
+ } else if (hasFinally) {
+ if (this.prev < entry.finallyLoc) {
+ return handle(entry.finallyLoc);
+ }
+ } else {
+ throw new Error("try statement without catch or finally");
+ }
+ }
+ }
+ },
+
+ abrupt: function abrupt(type, arg) {
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
+ var entry = this.tryEntries[i];
+ if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
+ var finallyEntry = entry;
+ break;
+ }
+ }
+
+ if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
+ // Ignore the finally entry if control is not jumping to a
+ // location outside the try/catch block.
+ finallyEntry = null;
+ }
+
+ var record = finallyEntry ? finallyEntry.completion : {};
+ record.type = type;
+ record.arg = arg;
+
+ if (finallyEntry) {
+ this.next = finallyEntry.finallyLoc;
+ } else {
+ this.complete(record);
+ }
+
+ return ContinueSentinel;
+ },
+
+ complete: function complete(record, afterLoc) {
+ if (record.type === "throw") {
+ throw record.arg;
+ }
+
+ if (record.type === "break" || record.type === "continue") {
+ this.next = record.arg;
+ } else if (record.type === "return") {
+ this.rval = record.arg;
+ this.next = "end";
+ } else if (record.type === "normal" && afterLoc) {
+ this.next = afterLoc;
+ }
+ },
+
+ finish: function finish(finallyLoc) {
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
+ var entry = this.tryEntries[i];
+ if (entry.finallyLoc === finallyLoc) {
+ this.complete(entry.completion, entry.afterLoc);
+ resetTryEntry(entry);
+ return ContinueSentinel;
+ }
+ }
+ },
+
+ "catch": function _catch(tryLoc) {
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
+ var entry = this.tryEntries[i];
+ if (entry.tryLoc === tryLoc) {
+ var record = entry.completion;
+ if (record.type === "throw") {
+ var thrown = record.arg;
+ resetTryEntry(entry);
+ }
+ return thrown;
+ }
+ }
+
+ // The context.catch method must only be called with a location
+ // argument that corresponds to a known catch block.
+ throw new Error("illegal catch attempt");
+ },
+
+ delegateYield: function delegateYield(iterable, resultName, nextLoc) {
+ this.delegate = {
+ iterator: values(iterable),
+ resultName: resultName,
+ nextLoc: nextLoc
+ };
+
+ return ContinueSentinel;
+ }
+ };
+}(
+// Among the various tricks for obtaining a reference to the global
+// object, this seems to be the most reliable technique that does not
+// use indirect eval (which violates Content Security Policy).
+(typeof global === "undefined" ? "undefined" : _typeof(global)) === "object" ? global : (typeof window === "undefined" ? "undefined" : _typeof(window)) === "object" ? window : (typeof self === "undefined" ? "undefined" : _typeof(self)) === "object" ? self : undefined);
+
+}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+
+},{"_process":4}],6:[function(require,module,exports){
+"use strict";
+
+console.warn("The regenerator/runtime module is deprecated; " + "please import regenerator-runtime/runtime instead.");
+
+module.exports = require("regenerator-runtime/runtime");
+
+},{"regenerator-runtime/runtime":5}],7:[function(require,module,exports){
+/* @flow */
+'use strict';
+
+var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
+
+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
+
+function canRead(auth) {
+ return auth === 'read' || auth === 'write';
+}
+function canWrite(auth) {
+ return auth === 'write';
+}
+
+module.exports = function (Y /* :any */) {
+ var AbstractConnector = function () {
+ /* ::
+ y: YConfig;
+ role: SyncRole;
+ connections: Object;
+ isSynced: boolean;
+ userEventListeners: Array;
+ whenSyncedListeners: Array;
+ currentSyncTarget: ?UserId;
+ syncingClients: Array;
+ forwardToSyncingClients: boolean;
+ debug: boolean;
+ broadcastedHB: boolean;
+ syncStep2: Promise;
+ userId: UserId;
+ send: Function;
+ broadcast: Function;
+ broadcastOpBuffer: Array;
+ protocolVersion: number;
+ */
+ /*
+ opts contains the following information:
+ role : String Role of this client ("master" or "slave")
+ userId : String Uniquely defines the user.
+ debug: Boolean Whether to print debug messages (optional)
+ */
+ function AbstractConnector(y, opts) {
+ _classCallCheck(this, AbstractConnector);
+
+ this.y = y;
+ if (opts == null) {
+ opts = {};
+ }
+ if (opts.role == null || opts.role === 'master') {
+ this.role = 'master';
+ } else if (opts.role === 'slave') {
+ this.role = 'slave';
+ } else {
+ throw new Error("Role must be either 'master' or 'slave'!");
+ }
+ this.log = Y.debug('y:connector');
+ this.logMessage = Y.debug('y:connector-message');
+ this.y.db.forwardAppliedOperations = opts.forwardAppliedOperations || false;
+ this.role = opts.role;
+ this.connections = {};
+ this.isSynced = false;
+ this.userEventListeners = [];
+ this.whenSyncedListeners = [];
+ this.currentSyncTarget = null;
+ this.syncingClients = [];
+ this.forwardToSyncingClients = opts.forwardToSyncingClients !== false;
+ this.debug = opts.debug === true;
+ this.broadcastedHB = false;
+ this.syncStep2 = Promise.resolve();
+ this.broadcastOpBuffer = [];
+ this.protocolVersion = 11;
+ this.authInfo = opts.auth || null;
+ this.checkAuth = opts.checkAuth || function () {
+ return Promise.resolve('write');
+ }; // default is everyone has write access
+ if (opts.generateUserId === true) {
+ this.setUserId(Y.utils.generateGuid());
+ }
+ }
+
+ _createClass(AbstractConnector, [{
+ key: 'resetAuth',
+ value: function resetAuth(auth) {
+ if (this.authInfo !== auth) {
+ this.authInfo = auth;
+ this.broadcast({
+ type: 'auth',
+ auth: this.authInfo
+ });
+ }
+ }
+ }, {
+ key: 'reconnect',
+ value: function reconnect() {
+ this.log('reconnecting..');
+ }
+ }, {
+ key: 'disconnect',
+ value: function disconnect() {
+ this.log('discronnecting..');
+ this.connections = {};
+ this.isSynced = false;
+ this.currentSyncTarget = null;
+ this.broadcastedHB = false;
+ this.syncingClients = [];
+ this.whenSyncedListeners = [];
+ return this.y.db.stopGarbageCollector();
+ }
+ }, {
+ key: 'repair',
+ value: function repair() {
+ this.log('Repairing the state of Yjs. This can happen if messages get lost, and Yjs detects that something is wrong. If this happens often, please report an issue here: https://github.com/y-js/yjs/issues');
+ for (var name in this.connections) {
+ this.connections[name].isSynced = false;
+ }
+ this.isSynced = false;
+ this.currentSyncTarget = null;
+ this.broadcastedHB = false;
+ this.findNextSyncTarget();
+ }
+ }, {
+ key: 'setUserId',
+ value: function setUserId(userId) {
+ if (this.userId == null) {
+ this.log('Set userId to "%s"', userId);
+ this.userId = userId;
+ return this.y.db.setUserId(userId);
+ } else {
+ return null;
+ }
+ }
+ }, {
+ key: 'onUserEvent',
+ value: function onUserEvent(f) {
+ this.userEventListeners.push(f);
+ }
+ }, {
+ key: 'removeUserEventListener',
+ value: function removeUserEventListener(f) {
+ this.userEventListeners = this.userEventListeners.filter(function (g) {
+ f !== g;
+ });
+ }
+ }, {
+ key: 'userLeft',
+ value: function userLeft(user) {
+ if (this.connections[user] != null) {
+ this.log('User left: %s', user);
+ delete this.connections[user];
+ if (user === this.currentSyncTarget) {
+ this.currentSyncTarget = null;
+ this.findNextSyncTarget();
+ }
+ this.syncingClients = this.syncingClients.filter(function (cli) {
+ return cli !== user;
+ });
+ var _iteratorNormalCompletion = true;
+ var _didIteratorError = false;
+ var _iteratorError = undefined;
+
+ try {
+ for (var _iterator = this.userEventListeners[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
+ var f = _step.value;
+
+ f({
+ action: 'userLeft',
+ user: user
+ });
+ }
+ } catch (err) {
+ _didIteratorError = true;
+ _iteratorError = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion && _iterator.return) {
+ _iterator.return();
+ }
+ } finally {
+ if (_didIteratorError) {
+ throw _iteratorError;
+ }
+ }
+ }
+ }
+ }
+ }, {
+ key: 'userJoined',
+ value: function userJoined(user, role) {
+ if (role == null) {
+ throw new Error('You must specify the role of the joined user!');
+ }
+ if (this.connections[user] != null) {
+ throw new Error('This user already joined!');
+ }
+ this.log('User joined: %s', user);
+ this.connections[user] = {
+ isSynced: false,
+ role: role
+ };
+ var _iteratorNormalCompletion2 = true;
+ var _didIteratorError2 = false;
+ var _iteratorError2 = undefined;
+
+ try {
+ for (var _iterator2 = this.userEventListeners[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
+ var f = _step2.value;
+
+ f({
+ action: 'userJoined',
+ user: user,
+ role: role
+ });
+ }
+ } catch (err) {
+ _didIteratorError2 = true;
+ _iteratorError2 = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion2 && _iterator2.return) {
+ _iterator2.return();
+ }
+ } finally {
+ if (_didIteratorError2) {
+ throw _iteratorError2;
+ }
+ }
+ }
+
+ if (this.currentSyncTarget == null) {
+ this.findNextSyncTarget();
+ }
+ }
+ // Execute a function _when_ we are connected.
+ // If not connected, wait until connected
+
+ }, {
+ key: 'whenSynced',
+ value: function whenSynced(f) {
+ if (this.isSynced) {
+ f();
+ } else {
+ this.whenSyncedListeners.push(f);
+ }
+ }
+ }, {
+ key: 'findNextSyncTarget',
+ value: function findNextSyncTarget() {
+ if (this.currentSyncTarget != null) {
+ return; // "The current sync has not finished!"
+ }
+
+ var syncUser = null;
+ for (var uid in this.connections) {
+ if (!this.connections[uid].isSynced) {
+ syncUser = uid;
+ break;
+ }
+ }
+ var conn = this;
+ if (syncUser != null) {
+ this.currentSyncTarget = syncUser;
+ this.y.db.requestTransaction(regeneratorRuntime.mark(function _callee() {
+ var stateSet, deleteSet;
+ return regeneratorRuntime.wrap(function _callee$(_context) {
+ while (1) {
+ switch (_context.prev = _context.next) {
+ case 0:
+ return _context.delegateYield(this.getStateSet(), 't0', 1);
+
+ case 1:
+ stateSet = _context.t0;
+ return _context.delegateYield(this.getDeleteSet(), 't1', 3);
+
+ case 3:
+ deleteSet = _context.t1;
+
+ conn.send(syncUser, {
+ type: 'sync step 1',
+ stateSet: stateSet,
+ deleteSet: deleteSet,
+ protocolVersion: conn.protocolVersion,
+ auth: conn.authInfo
+ });
+
+ case 5:
+ case 'end':
+ return _context.stop();
+ }
+ }
+ }, _callee, this);
+ }));
+ } else {
+ if (!conn.isSynced) {
+ this.y.db.requestTransaction(regeneratorRuntime.mark(function _callee2() {
+ var _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _iterator3, _step3, f;
+
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
+ while (1) {
+ switch (_context2.prev = _context2.next) {
+ case 0:
+ if (conn.isSynced) {
+ _context2.next = 23;
+ break;
+ }
+
+ // it is crucial that isSynced is set at the time garbageCollectAfterSync is called
+ conn.isSynced = true;
+ return _context2.delegateYield(this.garbageCollectAfterSync(), 't0', 3);
+
+ case 3:
+ // call whensynced listeners
+ _iteratorNormalCompletion3 = true;
+ _didIteratorError3 = false;
+ _iteratorError3 = undefined;
+ _context2.prev = 6;
+ for (_iterator3 = conn.whenSyncedListeners[Symbol.iterator](); !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
+ f = _step3.value;
+
+ f();
+ }
+ _context2.next = 14;
+ break;
+
+ case 10:
+ _context2.prev = 10;
+ _context2.t1 = _context2['catch'](6);
+ _didIteratorError3 = true;
+ _iteratorError3 = _context2.t1;
+
+ case 14:
+ _context2.prev = 14;
+ _context2.prev = 15;
+
+ if (!_iteratorNormalCompletion3 && _iterator3.return) {
+ _iterator3.return();
+ }
+
+ case 17:
+ _context2.prev = 17;
+
+ if (!_didIteratorError3) {
+ _context2.next = 20;
+ break;
+ }
+
+ throw _iteratorError3;
+
+ case 20:
+ return _context2.finish(17);
+
+ case 21:
+ return _context2.finish(14);
+
+ case 22:
+ conn.whenSyncedListeners = [];
+
+ case 23:
+ case 'end':
+ return _context2.stop();
+ }
+ }
+ }, _callee2, this, [[6, 10, 14, 22], [15,, 17, 21]]);
+ }));
+ }
+ }
+ }
+ }, {
+ key: 'send',
+ value: function send(uid, message) {
+ this.log('Send \'%s\' to %s', message.type, uid);
+ this.logMessage('Message: %j', message);
+ }
+ }, {
+ key: 'broadcast',
+ value: function broadcast(message) {
+ this.log('Broadcast \'%s\'', message.type);
+ this.logMessage('Message: %j', message);
+ }
+ /*
+ Buffer operations, and broadcast them when ready.
+ */
+
+ }, {
+ key: 'broadcastOps',
+ value: function broadcastOps(ops) {
+ ops = ops.map(function (op) {
+ return Y.Struct[op.struct].encode(op);
+ });
+ var self = this;
+ function broadcastOperations() {
+ if (self.broadcastOpBuffer.length > 0) {
+ self.broadcast({
+ type: 'update',
+ ops: self.broadcastOpBuffer
+ });
+ self.broadcastOpBuffer = [];
+ }
+ }
+ if (this.broadcastOpBuffer.length === 0) {
+ this.broadcastOpBuffer = ops;
+ if (this.y.db.transactionInProgress) {
+ this.y.db.whenTransactionsFinished().then(broadcastOperations);
+ } else {
+ setTimeout(broadcastOperations, 0);
+ }
+ } else {
+ this.broadcastOpBuffer = this.broadcastOpBuffer.concat(ops);
+ }
+ }
+ /*
+ You received a raw message, and you know that it is intended for Yjs. Then call this function.
+ */
+
+ }, {
+ key: 'receiveMessage',
+ value: function receiveMessage(sender /* :UserId */, message /* :Message */) {
+ var _this = this;
+
+ if (sender === this.userId) {
+ return Promise.resolve();
+ }
+ this.log('Receive \'%s\' from %s', message.type, sender);
+ this.logMessage('Message: %j', message);
+ if (message.protocolVersion != null && message.protocolVersion !== this.protocolVersion) {
+ this.log('You tried to sync with a yjs instance that has a different protocol version\n (You: ' + this.protocolVersion + ', Client: ' + message.protocolVersion + ').\n The sync was stopped. You need to upgrade your dependencies (especially Yjs & the Connector)!\n ');
+ this.send(sender, {
+ type: 'sync stop',
+ protocolVersion: this.protocolVersion
+ });
+ return Promise.reject('Incompatible protocol version');
+ }
+ if (message.auth != null && this.connections[sender] != null) {
+ // authenticate using auth in message
+ var auth = this.checkAuth(message.auth, this.y);
+ this.connections[sender].auth = auth;
+ auth.then(function (auth) {
+ var _iteratorNormalCompletion4 = true;
+ var _didIteratorError4 = false;
+ var _iteratorError4 = undefined;
+
+ try {
+ for (var _iterator4 = _this.userEventListeners[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
+ var f = _step4.value;
+
+ f({
+ action: 'userAuthenticated',
+ user: sender,
+ auth: auth
+ });
+ }
+ } catch (err) {
+ _didIteratorError4 = true;
+ _iteratorError4 = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion4 && _iterator4.return) {
+ _iterator4.return();
+ }
+ } finally {
+ if (_didIteratorError4) {
+ throw _iteratorError4;
+ }
+ }
+ }
+ });
+ } else if (this.connections[sender] != null && this.connections[sender].auth == null) {
+ // authenticate without otherwise
+ this.connections[sender].auth = this.checkAuth(null, this.y);
+ }
+ if (this.connections[sender] != null && this.connections[sender].auth != null) {
+ return this.connections[sender].auth.then(function (auth) {
+ if (message.type === 'sync step 1' && canRead(auth)) {
+ (function () {
+ var conn = _this;
+ var m = message;
+
+ _this.y.db.requestTransaction(regeneratorRuntime.mark(function _callee3() {
+ var currentStateSet, ds, ops;
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
+ while (1) {
+ switch (_context3.prev = _context3.next) {
+ case 0:
+ return _context3.delegateYield(this.getStateSet(), 't0', 1);
+
+ case 1:
+ currentStateSet = _context3.t0;
+
+ if (!canWrite(auth)) {
+ _context3.next = 4;
+ break;
+ }
+
+ return _context3.delegateYield(this.applyDeleteSet(m.deleteSet), 't1', 4);
+
+ case 4:
+ return _context3.delegateYield(this.getDeleteSet(), 't2', 5);
+
+ case 5:
+ ds = _context3.t2;
+ return _context3.delegateYield(this.getOperations(m.stateSet), 't3', 7);
+
+ case 7:
+ ops = _context3.t3;
+
+ conn.send(sender, {
+ type: 'sync step 2',
+ os: ops,
+ stateSet: currentStateSet,
+ deleteSet: ds,
+ protocolVersion: this.protocolVersion,
+ auth: this.authInfo
+ });
+ if (this.forwardToSyncingClients) {
+ conn.syncingClients.push(sender);
+ setTimeout(function () {
+ conn.syncingClients = conn.syncingClients.filter(function (cli) {
+ return cli !== sender;
+ });
+ conn.send(sender, {
+ type: 'sync done'
+ });
+ }, 5000); // TODO: conn.syncingClientDuration)
+ } else {
+ conn.send(sender, {
+ type: 'sync done'
+ });
+ }
+
+ case 10:
+ case 'end':
+ return _context3.stop();
+ }
+ }
+ }, _callee3, this);
+ }));
+ })();
+ } else if (message.type === 'sync step 2' && canWrite(auth)) {
+ var broadcastHB;
+ var db;
+ var defer;
+
+ (function () {
+ var conn = _this;
+ broadcastHB = !_this.broadcastedHB;
+
+ _this.broadcastedHB = true;
+ db = _this.y.db;
+ defer = {};
+
+ defer.promise = new Promise(function (resolve) {
+ defer.resolve = resolve;
+ });
+ _this.syncStep2 = defer.promise;
+ var m /* :MessageSyncStep2 */ = message;
+ db.requestTransaction(regeneratorRuntime.mark(function _callee5() {
+ return regeneratorRuntime.wrap(function _callee5$(_context5) {
+ while (1) {
+ switch (_context5.prev = _context5.next) {
+ case 0:
+ return _context5.delegateYield(this.applyDeleteSet(m.deleteSet), 't0', 1);
+
+ case 1:
+ this.store.apply(m.os);
+ db.requestTransaction(regeneratorRuntime.mark(function _callee4() {
+ var ops;
+ return regeneratorRuntime.wrap(function _callee4$(_context4) {
+ while (1) {
+ switch (_context4.prev = _context4.next) {
+ case 0:
+ return _context4.delegateYield(this.getOperations(m.stateSet), 't0', 1);
+
+ case 1:
+ ops = _context4.t0;
+
+ if (ops.length > 0) {
+ if (!broadcastHB) {
+ // TODO: consider to broadcast here..
+ conn.send(sender, {
+ type: 'update',
+ ops: ops
+ });
+ } else {
+ // broadcast only once!
+ conn.broadcastOps(ops);
+ }
+ }
+ defer.resolve();
+
+ case 4:
+ case 'end':
+ return _context4.stop();
+ }
+ }
+ }, _callee4, this);
+ }));
+
+ case 3:
+ case 'end':
+ return _context5.stop();
+ }
+ }
+ }, _callee5, this);
+ }));
+ })();
+ } else if (message.type === 'sync done') {
+ var self = _this;
+ _this.syncStep2.then(function () {
+ self._setSyncedWith(sender);
+ });
+ } else if (message.type === 'update' && canWrite(auth)) {
+ if (_this.forwardToSyncingClients) {
+ var _iteratorNormalCompletion5 = true;
+ var _didIteratorError5 = false;
+ var _iteratorError5 = undefined;
+
+ try {
+ for (var _iterator5 = _this.syncingClients[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
+ var client = _step5.value;
+
+ _this.send(client, message);
+ }
+ } catch (err) {
+ _didIteratorError5 = true;
+ _iteratorError5 = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion5 && _iterator5.return) {
+ _iterator5.return();
+ }
+ } finally {
+ if (_didIteratorError5) {
+ throw _iteratorError5;
+ }
+ }
+ }
+ }
+ if (_this.y.db.forwardAppliedOperations) {
+ var delops = message.ops.filter(function (o) {
+ return o.struct === 'Delete';
+ });
+ if (delops.length > 0) {
+ _this.broadcastOps(delops);
+ }
+ }
+ _this.y.db.apply(message.ops);
+ }
+ });
+ } else {
+ return Promise.reject('Unable to deliver message');
+ }
+ }
+ }, {
+ key: '_setSyncedWith',
+ value: function _setSyncedWith(user) {
+ var conn = this.connections[user];
+ if (conn != null) {
+ conn.isSynced = true;
+ }
+ if (user === this.currentSyncTarget) {
+ this.currentSyncTarget = null;
+ this.findNextSyncTarget();
+ }
+ }
+ /*
+ Currently, the HB encodes operations as JSON. For the moment I want to keep it
+ that way. Maybe we support encoding in the HB as XML in the future, but for now I don't want
+ too much overhead. Y is very likely to get changed a lot in the future
+ Because we don't want to encode JSON as string (with character escaping, wich makes it pretty much unreadable)
+ we encode the JSON as XML.
+ When the HB support encoding as XML, the format should look pretty much like this.
+ does not support primitive values as array elements
+ expects an ltx (less than xml) object
+ */
+
+ }, {
+ key: 'parseMessageFromXml',
+ value: function parseMessageFromXml(m /* :any */) {
+ function parseArray(node) {
+ var _iteratorNormalCompletion6 = true;
+ var _didIteratorError6 = false;
+ var _iteratorError6 = undefined;
+
+ try {
+ for (var _iterator6 = node.children[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
+ var n = _step6.value;
+
+ if (n.getAttribute('isArray') === 'true') {
+ return parseArray(n);
+ } else {
+ return parseObject(n);
+ }
+ }
+ } catch (err) {
+ _didIteratorError6 = true;
+ _iteratorError6 = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion6 && _iterator6.return) {
+ _iterator6.return();
+ }
+ } finally {
+ if (_didIteratorError6) {
+ throw _iteratorError6;
+ }
+ }
+ }
+ }
+ function parseObject(node /* :any */) {
+ var json = {};
+ for (var attrName in node.attrs) {
+ var value = node.attrs[attrName];
+ var int = parseInt(value, 10);
+ if (isNaN(int) || '' + int !== value) {
+ json[attrName] = value;
+ } else {
+ json[attrName] = int;
+ }
+ }
+ for (var n /* :any */ in node.children) {
+ var name = n.name;
+ if (n.getAttribute('isArray') === 'true') {
+ json[name] = parseArray(n);
+ } else {
+ json[name] = parseObject(n);
+ }
+ }
+ return json;
+ }
+ parseObject(m);
+ }
+ /*
+ encode message in xml
+ we use string because Strophe only accepts an "xml-string"..
+ So {a:4,b:{c:5}} will look like
+
+
+
+ m - ltx element
+ json - Object
+ */
+
+ }, {
+ key: 'encodeMessageToXml',
+ value: function encodeMessageToXml(msg, obj) {
+ // attributes is optional
+ function encodeObject(m, json) {
+ for (var name in json) {
+ var value = json[name];
+ if (name == null) {
+ // nop
+ } else if (value.constructor === Object) {
+ encodeObject(m.c(name), value);
+ } else if (value.constructor === Array) {
+ encodeArray(m.c(name), value);
+ } else {
+ m.setAttribute(name, value);
+ }
+ }
+ }
+ function encodeArray(m, array) {
+ m.setAttribute('isArray', 'true');
+ var _iteratorNormalCompletion7 = true;
+ var _didIteratorError7 = false;
+ var _iteratorError7 = undefined;
+
+ try {
+ for (var _iterator7 = array[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
+ var e = _step7.value;
+
+ if (e.constructor === Object) {
+ encodeObject(m.c('array-element'), e);
+ } else {
+ encodeArray(m.c('array-element'), e);
+ }
+ }
+ } catch (err) {
+ _didIteratorError7 = true;
+ _iteratorError7 = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion7 && _iterator7.return) {
+ _iterator7.return();
+ }
+ } finally {
+ if (_didIteratorError7) {
+ throw _iteratorError7;
+ }
+ }
+ }
+ }
+ if (obj.constructor === Object) {
+ encodeObject(msg.c('y', { xmlns: 'http://y.ninja/connector-stanza' }), obj);
+ } else if (obj.constructor === Array) {
+ encodeArray(msg.c('y', { xmlns: 'http://y.ninja/connector-stanza' }), obj);
+ } else {
+ throw new Error("I can't encode this json!");
+ }
+ }
+ }]);
+
+ return AbstractConnector;
+ }();
+
+ Y.AbstractConnector = AbstractConnector;
+};
+
+},{}],8:[function(require,module,exports){
+/* global getRandom, async */
+'use strict';
+
+var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
+
+var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
+
+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
+
+function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
+
+function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
+
+module.exports = function (Y) {
+ var globalRoom = {
+ users: {},
+ buffers: {},
+ removeUser: function removeUser(user) {
+ for (var i in this.users) {
+ this.users[i].userLeft(user);
+ }
+ delete this.users[user];
+ delete this.buffers[user];
+ },
+ addUser: function addUser(connector) {
+ this.users[connector.userId] = connector;
+ this.buffers[connector.userId] = {};
+ for (var uname in this.users) {
+ if (uname !== connector.userId) {
+ var u = this.users[uname];
+ u.userJoined(connector.userId, 'master');
+ connector.userJoined(u.userId, 'master');
+ }
+ }
+ },
+ whenTransactionsFinished: function whenTransactionsFinished() {
+ var self = this;
+ return new Promise(function (resolve, reject) {
+ // The connector first has to send the messages to the db.
+ // Wait for the checkAuth-function to resolve
+ // The test lib only has a simple checkAuth function: `() => Promise.resolve()`
+ // Just add a function to the event-queue, in order to wait for the event.
+ // TODO: this may be buggy in test applications (but it isn't be for real-life apps)
+ setTimeout(function () {
+ var ps = [];
+ for (var name in self.users) {
+ ps.push(self.users[name].y.db.whenTransactionsFinished());
+ }
+ Promise.all(ps).then(resolve, reject);
+ }, 0);
+ });
+ },
+ flushOne: function flushOne() {
+ var bufs = [];
+ for (var receiver in globalRoom.buffers) {
+ var buff = globalRoom.buffers[receiver];
+ var push = false;
+ for (var sender in buff) {
+ if (buff[sender].length > 0) {
+ push = true;
+ break;
+ }
+ }
+ if (push) {
+ bufs.push(receiver);
+ }
+ }
+ if (bufs.length > 0) {
+ var userId = getRandom(bufs);
+ var _buff = globalRoom.buffers[userId];
+ var _sender = getRandom(Object.keys(_buff));
+ var m = _buff[_sender].shift();
+ if (_buff[_sender].length === 0) {
+ delete _buff[_sender];
+ }
+ var user = globalRoom.users[userId];
+ return user.receiveMessage(m[0], m[1]).then(function () {
+ return user.y.db.whenTransactionsFinished();
+ }, function () {});
+ } else {
+ return false;
+ }
+ },
+ flushAll: function flushAll() {
+ return new Promise(function (resolve) {
+ // flushes may result in more created operations,
+ // flush until there is nothing more to flush
+ function nextFlush() {
+ var c = globalRoom.flushOne();
+ if (c) {
+ while (c) {
+ c = globalRoom.flushOne();
+ }
+ globalRoom.whenTransactionsFinished().then(nextFlush);
+ } else {
+ c = globalRoom.flushOne();
+ if (c) {
+ c.then(function () {
+ globalRoom.whenTransactionsFinished().then(nextFlush);
+ });
+ } else {
+ resolve();
+ }
+ }
+ }
+ globalRoom.whenTransactionsFinished().then(nextFlush);
+ });
+ }
+ };
+ Y.utils.globalRoom = globalRoom;
+
+ var userIdCounter = 0;
+
+ var Test = function (_Y$AbstractConnector) {
+ _inherits(Test, _Y$AbstractConnector);
+
+ function Test(y, options) {
+ _classCallCheck(this, Test);
+
+ if (options === undefined) {
+ throw new Error('Options must not be undefined!');
+ }
+ options.role = 'master';
+ options.forwardToSyncingClients = false;
+
+ var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Test).call(this, y, options));
+
+ _this.setUserId(userIdCounter++ + '').then(function () {
+ globalRoom.addUser(_this);
+ });
+ _this.globalRoom = globalRoom;
+ _this.syncingClientDuration = 0;
+ return _this;
+ }
+
+ _createClass(Test, [{
+ key: 'receiveMessage',
+ value: function receiveMessage(sender, m) {
+ return _get(Object.getPrototypeOf(Test.prototype), 'receiveMessage', this).call(this, sender, JSON.parse(JSON.stringify(m)));
+ }
+ }, {
+ key: 'send',
+ value: function send(userId, message) {
+ var buffer = globalRoom.buffers[userId];
+ if (buffer != null) {
+ if (buffer[this.userId] == null) {
+ buffer[this.userId] = [];
+ }
+ buffer[this.userId].push(JSON.parse(JSON.stringify([this.userId, message])));
+ }
+ }
+ }, {
+ key: 'broadcast',
+ value: function broadcast(message) {
+ for (var key in globalRoom.buffers) {
+ var buff = globalRoom.buffers[key];
+ if (buff[this.userId] == null) {
+ buff[this.userId] = [];
+ }
+ buff[this.userId].push(JSON.parse(JSON.stringify([this.userId, message])));
+ }
+ }
+ }, {
+ key: 'isDisconnected',
+ value: function isDisconnected() {
+ return globalRoom.users[this.userId] == null;
+ }
+ }, {
+ key: 'reconnect',
+ value: function reconnect() {
+ if (this.isDisconnected()) {
+ globalRoom.addUser(this);
+ _get(Object.getPrototypeOf(Test.prototype), 'reconnect', this).call(this);
+ }
+ return Y.utils.globalRoom.flushAll();
+ }
+ }, {
+ key: 'disconnect',
+ value: function disconnect() {
+ if (!this.isDisconnected()) {
+ globalRoom.removeUser(this.userId);
+ _get(Object.getPrototypeOf(Test.prototype), 'disconnect', this).call(this);
+ }
+ return this.y.db.whenTransactionsFinished();
+ }
+ }, {
+ key: 'flush',
+ value: function flush() {
+ var self = this;
+ return async(regeneratorRuntime.mark(function _callee() {
+ var buff, sender, m;
+ return regeneratorRuntime.wrap(function _callee$(_context) {
+ while (1) {
+ switch (_context.prev = _context.next) {
+ case 0:
+ buff = globalRoom.buffers[self.userId];
+
+ case 1:
+ if (!(Object.keys(buff).length > 0)) {
+ _context.next = 9;
+ break;
+ }
+
+ sender = getRandom(Object.keys(buff));
+ m = buff[sender].shift();
+
+ if (buff[sender].length === 0) {
+ delete buff[sender];
+ }
+ _context.next = 7;
+ return this.receiveMessage(m[0], m[1]);
+
+ case 7:
+ _context.next = 1;
+ break;
+
+ case 9:
+ _context.next = 11;
+ return self.whenTransactionsFinished();
+
+ case 11:
+ case 'end':
+ return _context.stop();
+ }
+ }
+ }, _callee, this);
+ }));
+ }
+ }]);
+
+ return Test;
+ }(Y.AbstractConnector);
+
+ Y.Test = Test;
+};
+
+},{}],9:[function(require,module,exports){
+/* @flow */
+'use strict';
+
+var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
+
+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
+
+module.exports = function (Y /* :any */) {
+ /*
+ Partial definition of an OperationStore.
+ TODO: name it Database, operation store only holds operations.
+ A database definition must alse define the following methods:
+ * logTable() (optional)
+ - show relevant information information in a table
+ * requestTransaction(makeGen)
+ - request a transaction
+ * destroy()
+ - destroy the database
+ */
+ var AbstractDatabase = function () {
+ /* ::
+ y: YConfig;
+ forwardAppliedOperations: boolean;
+ listenersById: Object;
+ listenersByIdExecuteNow: Array