diff --git a/y.js b/y.js new file mode 100644 index 00000000..7a524fed --- /dev/null +++ b/y.js @@ -0,0 +1,9 @@ +/** + * yjs - A framework for real-time p2p shared editing on any data + * @version v13.0.0-55 + * @license MIT + */ +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.Y=e()}(this,function(){"use strict";function t(t,e){var n=e._id;if(void 0===n)e._integrate(t);else{if(t.ss.getState(n.user)>n.clock)return;e._integrate(t);var r=t._missingStructs.get(n.user);if(null!=r)for(var i=n.clock,o=i+e._length;i0&&(u+=" .. missing: "+l.map(v).join(", ")),n.push(u)}}function n(e,n){for(var r=n.readUint32(),i=0;i=0;d--){var _=u[d];f.has(_.user)||f.set(_.user,new Map);var v=f.get(_.user);v.has(_.clock)||v.set(_.clock,[]);(v=v.get(_.clock)).push(h)}}}}function r(t){for(var e=new Map,n=t.readUint32(),r=0;r0){var c=0,h=i[c],f=[];t.ds.iterate(new ot(r,0),new ot(r,Number.MAX_VALUE),function(t){for(;null!=h;){var e=0;if(t._id.clock+t.len<=h[0])break;h[0]=0;d--){var _=f[d];y(t,_[0],_[1],_[2])}for(;c0)for(var a=t.os.findNode(new ot(e,n));null!==a&&r>0&&a.val._id.equals(new ot(e,n));){var l=a.val;l._deleted||(l._splitAt(t,r),l._delete(t,i));var u=l._length;r-=u,n+=u,a=a.next()}}}function p(t,e,n){if(e!==t&&!e._deleted&&!t._transaction.newTypes.has(e)){var r=t._transaction.changedTypes,i=r.get(e);void 0===i&&(i=new Set,r.set(e,i)),i.add(n)}}function g(t,e,n,r){var i=e._id;n._id=new ot(i.user,i.clock+r),n._origin=e,n._left=e,n._right=e._right,null!==n._right&&(n._right._left=n),n._right_origin=e._right_origin,e._right=n,n._parent=e._parent,n._parentSub=e._parentSub,n._deleted=e._deleted;var o=new Set;o.add(e);for(var s=n._right;null!==s&&o.has(s._origin);)s._origin===e&&(s._origin=n),o.add(s),s=s._right;t.os.put(n)}function m(t,e){var n=void 0;do{n=e._right,e._right=null,e._right_origin=null,e._origin=e._left,e._integrate(t),e=n}while(null!==n)}function k(t,e){return e}function b(t){for(;null!==t&&t._deleted;)t=t._right;return t}function w(t,e,n){var r=t.insertDomElementsAfter(e,[n]);return r.length>0?r[0]:e}function S(t){var e=t._yxml;if(e.constructor!==YXmlHook){var n=e._y,r=new Set(Array.prototype.map.call(t.childNodes,function(t){return t._yxml}).filter(function(t){return void 0!==t}));e.forEach(function(t,e){r.has(t)||t._delete(n)});for(var i=t.childNodes,o=i.length,s=null,a=b(e._start),l=0;le)return[n._id.user,n._id.clock+e];e-=n._length}n=n._right}return["endof",t._id.user,t._id.clock||null,t._id.name||null,t._id.type||null]}function U(t,e){if("endof"===e[0]){var n=void 0;n=null===e[3]?new ot(e[1],e[2]):new bt(e[3],e[4]);var r=t.os.get(n);return{type:r,offset:r.length}}var i=0,o=t.os.findNodeWithUpperBound(new ot(e[0],e[1])).val,s=o._parent;if(s._deleted)return null;for(o._deleted||(i=e[1]-o._id.clock),o=o._left;null!==o;)o._deleted||(i+=o._length),o=o._left;return{type:s,offset:i}}function A(t,e,n){if(null!==_t&&n){var r=_t.to,i=_t.from,o=_t.fromY,s=_t.toY,a=!1,l=dt.anchorNode,u=dt.anchorOffset,c=dt.focusNode,h=dt.focusOffset;if(null!==i){var f=U(o,i);if(null!==f){var d=f.type.getDom(),_=f.offset;d===l&&_===u||(l=d,u=_,a=!0)}}if(null!==r){var v=U(s,r);if(null!==v){var y=v.type.getDom(),p=v.offset;y===c&&p===h||(c=y,h=p,a=!0)}}a&&dt.setBaseAndExtent(l,u,c,h)}}function B(t,e){for(var n=0,r=0;n0;){var i=n.pop();null!==i.fromState&&(t.os.getItemCleanStart(i.fromState),t.os.getItemCleanEnd(i.toState),t.os.iterate(i.fromState,i.toState,function(n){for(;n._deleted&&null!==n._redone;)n=n._redone;!1===n._deleted&&P(t,n,e)&&(r=!0,n._delete(t))}));var o=!0,s=!1,a=void 0;try{for(var l,u=i.deletedStructs[Symbol.iterator]();!(o=(l=u.next()).done);o=!0){var c=l.value;P(t,c,e)&&c._parent!==t&&(c._id.user!==t.userID||null===i.fromState||c._id.clocki.toState.clock)&&(r=!0,c._redo(t))}}catch(t){s=!0,a=t}finally{try{!o&&u.return&&u.return()}finally{if(s)throw a}}}}),r}function M(t,e){return e={exports:{}},t(e,e.exports),e.exports}function C(t){if(t=String(t),!(t.length>100)){var e=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(t);if(e){var n=parseFloat(e[1]);switch((e[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return n*Tt;case"days":case"day":case"d":return n*Dt;case"hours":case"hour":case"hrs":case"hr":case"h":return n*xt;case"minutes":case"minute":case"mins":case"min":case"m":return n*Bt;case"seconds":case"second":case"secs":case"sec":case"s":return n*At;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}}}function R(t){return t>=Dt?Math.round(t/Dt)+"d":t>=xt?Math.round(t/xt)+"h":t>=Bt?Math.round(t/Bt)+"m":t>=At?Math.round(t/At)+"s":t+"ms"}function F(t){return H(t,Dt,"day")||H(t,xt,"hour")||H(t,Bt,"minute")||H(t,At,"second")||t+" ms"}function H(t,e,n){if(!(t0))return n;if(n.gc){if(!((r=n._id.clock+n.len-t.clock)=o._id.clock)for(r=n._id.clock+n.len-o._id.clock;r>=0;){if(o.gc){n.len-=r,r>=o.len&&(r-=o.len)>0&&(this.put(n),this.markDeleted(new ot(o._id.user,o._id.clock+o.len),r));break}if(!(r>o.len)){n.len+=o.len-r,this.delete(o._id);break}var s=this.findNext(o._id);if(this.delete(o._id),null==s||n._id.user!==s._id.user)break;o=s,r=n._id.clock+n.len-o._id.clock}return this.put(n),n}}]),e}(it),lt=function(){function t(e){if(G(this,t),e instanceof ArrayBuffer)this.uint8arr=new Uint8Array(e);else{if(!(e instanceof Uint8Array||"undefined"!=typeof Buffer&&e instanceof Buffer))throw new Error("Expected an ArrayBuffer or Uint8Array!");this.uint8arr=e}this.pos=0}return K(t,[{key:"clone",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.pos,n=new t(this.uint8arr);return n.pos=e,n}},{key:"skip8",value:function(){this.pos++}},{key:"readUint8",value:function(){return this.uint8arr[this.pos++]}},{key:"readUint32",value:function(){var t=this.uint8arr[this.pos]+(this.uint8arr[this.pos+1]<<8)+(this.uint8arr[this.pos+2]<<16)+(this.uint8arr[this.pos+3]<<24);return this.pos+=4,t}},{key:"peekUint8",value:function(){return this.uint8arr[this.pos]}},{key:"readVarUint",value:function(){for(var t=0,e=0;;){var n=this.uint8arr[this.pos++];if(t|=(127&n)<>>0;if(e>35)throw new Error("Integer out of range!")}}},{key:"readVarString",value:function(){for(var t=this.readVarUint(),e=new Array(t),n=0;n>>8&255)}},{key:"setUint16",value:function(t,e){this.data[t]=255&e,this.data[t+1]=e>>>8&255}},{key:"writeUint32",value:function(t){for(var e=0;e<4;e++)this.data.push(255&t),t>>>=8}},{key:"setUint32",value:function(t,e){for(var n=0;n<4;n++)this.data[t+n]=255&e,e>>>=8}},{key:"writeVarUint",value:function(t){for(;t>=128;)this.data.push(128|127&t),t>>>=7;this.data.push(127&t)}},{key:"writeVarString",value:function(t){var e=unescape(encodeURIComponent(t)),n=e.split("").map(function(t){return t.codePointAt()}),r=n.length;this.writeVarUint(r);for(var i=0;i1&&void 0!==arguments[1]&&arguments[1])null!==t.connector&&t.connector.broadcastStruct(this);else{var e=this._targetID;y(t,e.user,e.clock,this._length)}null!==t.persistence&&t.persistence.saveStruct(t,this)}},{key:"_logString",value:function(){return"Delete - target: "+v(this._targetID)+", len: "+this._length}}]),Delete}(),ht=function t(e){G(this,t),this.y=e,this.newTypes=new Set,this.changedTypes=new Map,this.deletedStructs=new Set,this.beforeState=new Map,this.changedParentTypes=new Map},Item=function(){function Item(){G(this,Item),this._id=null,this._origin=null,this._left=null,this._right=null,this._right_origin=null,this._parent=null,this._parentSub=null,this._deleted=!1,this._redone=null}return K(Item,[{key:"_copy",value:function(){return new this.constructor}},{key:"_redo",value:function(t){if(null!==this._redone)return this._redone;var e=this._copy(),n=this._left,r=this,i=this._parent;if(!0===i._deleted&&null===i._redone&&i._redo(t),null!==i._redone){for(i=i._redone;null!==n;){if(null!==n._redone&&n._redone._parent===i){n=n._redone;break}n=n._left}for(;null!==r;)null!==r._redone&&r._redone._parent===i&&(r=r._redone),r=r._right}return e._origin=n,e._left=n,e._right=r,e._right_origin=r,e._parent=i,e._parentSub=this._parentSub,e._integrate(t),this._redone=e,e}},{key:"_splitAt",value:function(t,e){return 0===e?this:this._right}},{key:"_delete",value:function(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(!this._deleted){this._deleted=!0,t.ds.markDeleted(this._id,this._length);var n=new Delete;n._targetID=this._id,n._length=this._length,e?n._integrate(t,!0):null!==t.persistence&&t.persistence.saveStruct(t,n),p(t,this._parent,this._parentSub),t._transaction.deletedStructs.add(this)}}},{key:"_beforeChange",value:function(){}},{key:"_integrate",value:function(t){t._transaction.newTypes.add(this);var e=this._parent,n=this._id,r=null===n?t.userID:n.user,i=t.ss.getState(r);if(null===n)this._id=t.ss.getNextID(this._length);else if(n.user===kt);else{if(n.clock=this._length)return this._right;var n=new ItemJSON;return n._content=this._content.splice(e),g(t,this,n,e),n}},{key:"_length",get:function(){return this._content.length}}]),ItemJSON}(Item),ItemString=function(t){function ItemString(){G(this,ItemString);var t=et(this,(ItemString.__proto__||Object.getPrototypeOf(ItemString)).call(this));return t._content=null,t}return tt(ItemString,t),K(ItemString,[{key:"_copy",value:function(){var t=Q(ItemString.prototype.__proto__||Object.getPrototypeOf(ItemString.prototype),"_copy",this).call(this);return t._content=this._content,t}},{key:"_fromBinary",value:function(t,e){var n=Q(ItemString.prototype.__proto__||Object.getPrototypeOf(ItemString.prototype),"_fromBinary",this).call(this,t,e);return this._content=e.readVarString(),n}},{key:"_toBinary",value:function(t){Q(ItemString.prototype.__proto__||Object.getPrototypeOf(ItemString.prototype),"_toBinary",this).call(this,t),t.writeVarString(this._content)}},{key:"_logString",value:function(){var t=null!==this._left?this._left._lastId:null,e=null!==this._origin?this._origin._lastId:null;return"ItemJSON(id:"+v(this._id)+",content:"+JSON.stringify(this._content)+",left:"+v(t)+",origin:"+v(e)+",right:"+v(this._right)+",parent:"+v(this._parent)+",parentSub:"+this._parentSub+")"}},{key:"_splitAt",value:function(t,e){if(0===e)return this;if(e>=this._length)return this._right;var n=new ItemString;return n._content=this._content.slice(e),this._content=this._content.slice(0,e),g(t,this,n,e),n}},{key:"_length",get:function(){return this._content.length}}]),ItemString}(Item),YEvent=function(){function YEvent(t){G(this,YEvent),this.target=t,this.currentTarget=t}return K(YEvent,[{key:"path",get:function(){for(var t=[],e=this.target,n=e._y;e!==this.currentTarget&&e!==n;){var r=e._parent;if(null!==e._parentSub)t.unshift(e._parentSub);else{var i=!0,o=!1,s=void 0;try{for(var a,l=r[Symbol.iterator]();!(i=(a=l.next()).done);i=!0){var u=nt(a.value,2),c=u[0];if(u[1]===e){t.unshift(c);break}}}catch(t){o=!0,s=t}finally{try{!i&&l.return&&l.return()}finally{if(o)throw s}}}e=r}return t}}]),YEvent}(),YArrayEvent=function(t){function YArrayEvent(t,e,n){G(this,YArrayEvent);var r=et(this,(YArrayEvent.__proto__||Object.getPrototypeOf(YArrayEvent)).call(this,t));return r.remote=e,r._transaction=n,r._addedElements=null,r}return tt(YArrayEvent,t),K(YArrayEvent,[{key:"addedElements",get:function(){if(null===this._addedElements){var t=this.target,e=this._transaction,n=new Set;e.newTypes.forEach(function(r){r._parent!==t||e.deletedStructs.has(r)||n.add(r)}),this._addedElements=n}return this._addedElements}},{key:"removedElements",get:function(){var t=this.target,e=this._transaction,n=new Set;return e.deletedStructs.forEach(function(r){r._parent!==t||e.newTypes.has(r)||n.add(r)}),n}}]),YArrayEvent}(YEvent),YArray=function(t){function YArray(){return G(this,YArray),et(this,(YArray.__proto__||Object.getPrototypeOf(YArray)).apply(this,arguments))}return tt(YArray,t),K(YArray,[{key:"_callObserver",value:function(t,e,n){this._callEventHandler(t,new YArrayEvent(this,n,t))}},{key:"get",value:function(t){for(var e=this._start;null!==e;){if(!e._deleted){if(t1&&void 0!==arguments[1]?arguments[1]:1;if(this._y.transact(function(){for(var r=e._start,i=0;null!==r&&n>0;){if(!r._deleted)if(i<=t&&t0)throw new Error("Delete exceeds the range of the YArray")}},{key:"insertAfter",value:function(t,e){var n=this;this._transact(function(r){var i=void 0;i=null===t?n._start:t._right;for(var o=null,s=0;si)throw new Error("Position exceeds array range!");this.insertAfter(n,e)}},{key:"push",value:function(t){for(var e=this._start,n=null;null!==e;)e._deleted||(n=e),e=e._right;this.insertAfter(n,t)}},{key:"_logString",value:function(){var t=null!==this._left?this._left._lastId:null,e=null!==this._origin?this._origin._lastId:null;return"YArray(id:"+v(this._id)+",start:"+v(this._start)+",left:"+v(t)+",origin:"+v(e)+",right:"+v(this._right)+",parent:"+v(this._parent)+",parentSub:"+this._parentSub+")"}},{key:"length",get:function(){for(var t=0,e=this._start;null!==e;)e._deleted||(t+=e._length),e=e._right;return t}}]),YArray}(Type),YMapEvent=function(t){function YMapEvent(t,e,n){G(this,YMapEvent);var r=et(this,(YMapEvent.__proto__||Object.getPrototypeOf(YMapEvent)).call(this,t));return r.keysChanged=e,r.remote=n,r}return tt(YMapEvent,t),YMapEvent}(YEvent),YMap=function(t){function YMap(){return G(this,YMap),et(this,(YMap.__proto__||Object.getPrototypeOf(YMap)).apply(this,arguments))}return tt(YMap,t),K(YMap,[{key:"_callObserver",value:function(t,e,n){this._callEventHandler(t,new YMapEvent(this,e,n))}},{key:"toJSON",value:function(){var t={},e=!0,n=!1,r=void 0;try{for(var i,o=this._map[Symbol.iterator]();!(e=(i=o.next()).done);e=!0){var s=nt(i.value,2),a=s[0],l=s[1];if(!l._deleted){var u=void 0;u=l instanceof Type?void 0!==l.toJSON?l.toJSON():l.toString():l._content[0],t[a]=u}}}catch(t){n=!0,r=t}finally{try{!e&&o.return&&o.return()}finally{if(n)throw r}}return t}},{key:"keys",value:function(){var t=[],e=!0,n=!1,r=void 0;try{for(var i,o=this._map[Symbol.iterator]();!(e=(i=o.next()).done);e=!0){var s=nt(i.value,2),a=s[0];s[1]._deleted||t.push(a)}}catch(t){n=!0,r=t}finally{try{!e&&o.return&&o.return()}finally{if(n)throw r}}return t}},{key:"delete",value:function(t){var e=this;this._transact(function(n){var r=e._map.get(t);null!==n&&void 0!==r&&r._delete(n)})}},{key:"set",value:function(t,e){var n=this;return this._transact(function(r){var i=n._map.get(t)||null;if(null!==i){if(i.constructor===ItemJSON&&!i._deleted&&i._content[0]===e)return e;null!==r&&i._delete(r)}var o=void 0;"function"==typeof e?(o=new e,e=o):e instanceof Item?o=e:(o=new ItemJSON,o._content=[e]),o._right=i,o._right_origin=i,o._parent=n,o._parentSub=t,null!==r?o._integrate(r):n._map.set(t,o)}),e}},{key:"get",value:function(t){var e=this._map.get(t);if(void 0!==e&&!e._deleted)return e instanceof Type?e:e._content[e._content.length-1]}},{key:"has",value:function(t){var e=this._map.get(t);return void 0!==e&&!e._deleted}},{key:"_logString",value:function(){var t=null!==this._left?this._left._lastId:null,e=null!==this._origin?this._origin._lastId:null;return"YMap(id:"+v(this._id)+",mapSize:"+this._map.size+",left:"+v(t)+",origin:"+v(e)+",right:"+v(this._right)+",parent:"+v(this._parent)+",parentSub:"+this._parentSub+")"}}]),YMap}(Type),YText=function(t){function YText(t){G(this,YText);var e=et(this,(YText.__proto__||Object.getPrototypeOf(YText)).call(this));if("string"==typeof t){var n=new ItemString;n._parent=e,n._content=t,e._start=n}return e}return tt(YText,t),K(YText,[{key:"toString",value:function(){for(var t=[],e=this._start;null!==e;)e._deleted||t.push(e._content),e=e._right;return t.join("")}},{key:"insert",value:function(t,e){var n=this;e.length<=0||this._transact(function(r){for(var i=null,o=n._start,s=0;null!==o;){var a=o._deleted?0:o._length-1;if(s<=t&&t<=s+a){var l=t-s;o=o._splitAt(n._y,l),i=o._left,s+=l;break}o._deleted||(s+=o._length),i=o,o=o._right}if(t>s)throw new Error("Position exceeds array range!");var u=new ItemString;u._origin=i,u._left=i,u._right=o,u._right_origin=o,u._parent=n,u._content=e,null!==r?u._integrate(n._y):null===i?n._start=u:i._right=u})}},{key:"_logString",value:function(){var t=null!==this._left?this._left._lastId:null,e=null!==this._origin?this._origin._lastId:null;return"YText(id:"+v(this._id)+",start:"+v(this._start)+",left:"+v(t)+",origin:"+v(e)+",right:"+v(this._right)+",parent:"+v(this._parent)+",parentSub:"+this._parentSub+")"}}]),YText}(YArray),dt=null,_t=null,vt=void 0;vt="undefined"!=typeof getSelection?function(t,e,n){if(n){_t={from:null,to:null,fromY:null,toY:null},dt=getSelection();var r=dt.anchorNode;if(null!==r&&null!=r._yxml){var i=r._yxml;_t.from=O(i,dt.anchorOffset),_t.fromY=i._y}var o=dt.focusNode;if(null!==o&&null!=o._yxml){var s=o._yxml;_t.to=O(s,dt.focusOffset),_t.toY=s._y}}}:function(){};var YXmlEvent=function(t){function YXmlEvent(t,e,n){G(this,YXmlEvent);var r=et(this,(YXmlEvent.__proto__||Object.getPrototypeOf(YXmlEvent)).call(this,t));return r.childListChanged=!1,r.attributesChanged=new Set,r.remote=n,e.forEach(function(t){null===t?r.childListChanged=!0:r.attributesChanged.add(t)}),r}return tt(YXmlEvent,t),YXmlEvent}(YEvent),yt=function(){function t(e,n){G(this,t),this._filter=n||function(){return!0},this._root=e,this._currentNode=e,this._firstCall=!0}return K(t,[{key:Symbol.iterator,value:function(){return this}},{key:"next",value:function(){var t=this._currentNode;if(this._firstCall&&(this._firstCall=!1,!t._deleted&&this._filter(t)))return{value:t,done:!1};do{if(t._deleted||t.constructor!==YXmlFragment._YXmlElement&&t.constructor!==YXmlFragment||null===t._start){for(;t!==this._root;){if(null!==t._right){t=t._right;break}t=t._parent}t===this._root&&(t=null)}else t=t._start;if(t===this._root)break}while(null!==t&&(t._deleted||!this._filter(t)));return this._currentNode=t,null===t?{done:!0}:{value:t,done:!1}}}]),t}(),YXmlFragment=function(t){function YXmlFragment(){G(this,YXmlFragment);var t=et(this,(YXmlFragment.__proto__||Object.getPrototypeOf(YXmlFragment)).call(this));t._dom=null,t._domFilter=k,t._domObserver=null;var e=!0;return t._mutualExclude=function(t){if(e){e=!1;try{t()}catch(t){console.error(t)}e=!0}},t}return tt(YXmlFragment,t),K(YXmlFragment,[{key:"createTreeWalker",value:function(t){return new yt(this,t)}},{key:"querySelector",value:function(t){t=t.toUpperCase();var e=new yt(this,function(e){return e.nodeName===t}),n=e.next();return n.done?null:n.value}},{key:"querySelectorAll",value:function(t){return t=t.toUpperCase(),Array.from(new yt(this,function(e){return e.nodeName===t}))}},{key:"enableSmartScrolling",value:function(t){this._scrollElement=t,this.forEach(function(e){e.enableSmartScrolling(t)})}},{key:"setDomFilter",value:function(t){var e=this;this._domFilter=t;var n=new Map;if(void 0!==this.getAttributes){var r=this.getAttributes();for(var i in r)n.set(i,r[i])}this._y.transact(function(){var r=e._domFilter(e.nodeName,new Map(n));null===r?e._delete(e._y):n.forEach(function(t,n){r.has(n)||e.removeAttribute(n)}),e.forEach(function(e){e.setDomFilter(t)})})}},{key:"_callObserver",value:function(t,e,n){this._callEventHandler(t,new YXmlEvent(this,e,n))}},{key:"toString",value:function(){return this.map(function(t){return t.toString()}).join("")}},{key:"_delete",value:function(t,e){this._unbindFromDom(),Q(YXmlFragment.prototype.__proto__||Object.getPrototypeOf(YXmlFragment.prototype),"_delete",this).call(this,t,e)}},{key:"_unbindFromDom",value:function(){null!=this._domObserver&&(this._domObserver.disconnect(),this._domObserver=null),null!=this._dom&&(this._dom._yxml=null,this._dom=null),void 0!==this._beforeTransactionHandler&&this._y.off("beforeTransaction",this._beforeTransactionHandler)}},{key:"insertDomElementsAfter",value:function(t,e,n){var r=x(this,e,n);return this.insertAfter(t,r),r}},{key:"insertDomElements",value:function(t,e,n){var r=x(this,e,n);return this.insert(t,r),r}},{key:"getDom",value:function(){return this._dom}},{key:"bindToDom",value:function(t,e){null!=this._dom&&this._unbindFromDom(),null!=t._yxml&&t._yxml._unbindFromDom(),t.innerHTML="",this.forEach(function(n){t.insertBefore(n.getDom(e),null)}),this._bindToDom(t,e)}},{key:"_bindToDom",value:function(t,e){var n=this;if(e=e||document,this._dom=t,t._yxml=this,null!==this._parent){this._y.on("beforeTransaction",vt),this._y.on("afterTransaction",A);var r=function(t){if(!t._deleted){for(var e=!1,r=t;r!==n._y;){if(r===n){e=!0;break}r=r._parent}if(e){var i=new Map;if(void 0!==t.getAttributes){var o=t.getAttributes();for(var s in o)i.set(s,o[s])}var a=n._domFilter(t.nodeName,new Map(i));null===a?t._delete(n._y):i.forEach(function(e,n){a.has(n)||t.removeAttribute(n)})}}};return this._y.on("beforeObserverCalls",function(t,e){e.changedTypes.forEach(function(t,e){(t.size>1||!t.has(null))&&r(e)}),e.newTypes.forEach(r)}),this.observeDeep(function(t){E.call(n,t,e)}),"undefined"!=typeof MutationObserver&&(this._beforeTransactionHandler=function(){n._domObserverListener(n._domObserver.takeRecords())},this._y.on("beforeTransaction",this._beforeTransactionHandler),this._domObserverListener=function(t){n._mutualExclude(function(){n._y.transact(function(){var e=new Set;t.forEach(function(t){var r=t.target,i=r._yxml;if(null!=i&&i.constructor!==YXmlHook)switch(t.type){case"characterData":var o=B(i.toString(),r.nodeValue);i.delete(o.pos,o.remove),i.insert(o.pos,o.insert);break;case"attributes":if(i.constructor===YXmlFragment)break;var s=t.attributeName,a=r.getAttribute(s),l=new Map;l.set(s,a),n._domFilter(r.nodeName,l).size>0&&i.constructor!==YXmlFragment&&i.getAttribute(s)!==a&&(null==a?i.removeAttribute(s):i.setAttribute(s,a));break;case"childList":e.add(t.target)}});var r=!0,i=!1,o=void 0;try{for(var s,a=e[Symbol.iterator]();!(r=(s=a.next()).done);r=!0){var l=s.value;void 0!==l.yOnChildrenChanged&&l.yOnChildrenChanged(),null!=l._yxml&&!1!==l._yxml&&S(l)}}catch(t){i=!0,o=t}finally{try{!r&&a.return&&a.return()}finally{if(i)throw o}}})})},this._domObserver=new MutationObserver(this._domObserverListener),this._domObserver.observe(t,{childList:!0,attributes:!0,characterData:!0,subtree:!0})),t}}},{key:"_logString",value:function(){var t=null!==this._left?this._left._lastId:null,e=null!==this._origin?this._origin._lastId:null;return"YXml(id:"+v(this._id)+",left:"+v(t)+",origin:"+v(e)+",right:"+this._right+",parent:"+v(this._parent)+",parentSub:"+this._parentSub+")"}}]),YXmlFragment}(YArray),YXmlElement=function(t){function YXmlElement(t,e,n){G(this,YXmlElement);var r=et(this,(YXmlElement.__proto__||Object.getPrototypeOf(YXmlElement)).call(this));return r.nodeName=null,r._scrollElement=null,"function"==typeof e&&(r._domFilter=e),"string"==typeof t?r.nodeName=t.toUpperCase():null!=t&&null!=t.nodeType&&t.nodeType===t.ELEMENT_NODE?(r.nodeName=t.nodeName,r._setDom(t,n)):r.nodeName="UNDEFINED",r}return tt(YXmlElement,t),K(YXmlElement,[{key:"_copy",value:function(){var t=Q(YXmlElement.prototype.__proto__||Object.getPrototypeOf(YXmlElement.prototype),"_copy",this).call(this);return t.nodeName=this.nodeName,t}},{key:"_setDom",value:function(t,e){var n=this;if(null!=this._dom)throw new Error("Only call this method if you know what you are doing ;)");if(null!=t._yxml)throw new Error("Already bound to an YXml type");for(var r=new Map,i=0;i0?" "+e.join(" "):"")+">"+Q(YXmlElement.prototype.__proto__||Object.getPrototypeOf(YXmlElement.prototype),"toString",this).call(this)+""}},{key:"removeAttribute",value:function(){return YMap.prototype.delete.apply(this,arguments)}},{key:"setAttribute",value:function(){return YMap.prototype.set.apply(this,arguments)}},{key:"getAttribute",value:function(){return YMap.prototype.get.apply(this,arguments)}},{key:"getAttributes",value:function(){var t={},e=!0,n=!1,r=void 0;try{for(var i,o=this._map[Symbol.iterator]();!(e=(i=o.next()).done);e=!0){var s=nt(i.value,2),a=s[0],l=s[1];l._deleted||(t[a]=l._content[0])}}catch(t){n=!0,r=t}finally{try{!e&&o.return&&o.return()}finally{if(n)throw r}}return t}},{key:"getDom",value:function(t){t=t||document;var e=this._dom;if(null==e){e=t.createElement(this.nodeName),e._yxml=this;var n=this.getAttributes();for(var r in n)e.setAttribute(r,n[r]);this.forEach(function(n){e.appendChild(n.getDom(t))}),this._bindToDom(e,t)}return e}}]),YXmlElement}(YXmlFragment),pt={},YXmlHook=function(t){function YXmlHook(t,e){G(this,YXmlHook);var n=et(this,(YXmlHook.__proto__||Object.getPrototypeOf(YXmlHook)).call(this));return n._dom=null,n.hookName=null,void 0!==t&&(n.hookName=t,n._dom=e,e._yjsHook=t,e._yxml=n,T(t).fillType(e,n)),n}return tt(YXmlHook,t),K(YXmlHook,[{key:"_copy",value:function(){var t=Q(YXmlHook.prototype.__proto__||Object.getPrototypeOf(YXmlHook.prototype),"_copy",this).call(this);return t.hookName=this.hookName,t}},{key:"getDom",value:function(t){if(t=t||document,null===this._dom){var e=T(this.hookName).createDom(this);this._dom=e,e._yxml=this,e._yjsHook=this.hookName}return this._dom}},{key:"_unbindFromDom",value:function(){this._dom._yxml=null,this._yxml=null}},{key:"_fromBinary",value:function(t,e){var n=Q(YXmlHook.prototype.__proto__||Object.getPrototypeOf(YXmlHook.prototype),"_fromBinary",this).call(this,t,e);return this.hookName=e.readVarString(),n}},{key:"_toBinary",value:function(t){Q(YXmlHook.prototype.__proto__||Object.getPrototypeOf(YXmlHook.prototype),"_toBinary",this).call(this,t),t.writeVarString(this.hookName)}},{key:"_integrate",value:function(t){if(null===this.hookName)throw new Error("hookName must be defined!");Q(YXmlHook.prototype.__proto__||Object.getPrototypeOf(YXmlHook.prototype),"_integrate",this).call(this,t)}},{key:"setDomFilter",value:function(){}},{key:"enableSmartScrolling",value:function(){}}]),YXmlHook}(YMap);YXmlHook.addHook=D;var YXmlText=function(t){function YXmlText(t){G(this,YXmlText);var e=null,n=null;null!=t&&(null!=t.nodeType&&t.nodeType===t.TEXT_NODE?(e=t,n=e.nodeValue):"string"==typeof t&&(n=t));var r=et(this,(YXmlText.__proto__||Object.getPrototypeOf(YXmlText)).call(this,n));return r._dom=null,r._domObserver=null,r._domObserverListener=null,r._scrollElement=null,null!==e&&r._setDom(t),r}return tt(YXmlText,t),K(YXmlText,[{key:"setDomFilter",value:function(){}},{key:"enableSmartScrolling",value:function(t){this._scrollElement=t}},{key:"_setDom",value:function(t){null!=this._dom&&this._unbindFromDom(),null!=t._yxml&&t._yxml._unbindFromDom(),this._dom=t,t._yxml=this}},{key:"getDom",value:function(t){if(t=t||document,null===this._dom){var e=t.createTextNode(this.toString());return this._setDom(e),e}return this._dom}},{key:"_delete",value:function(t,e){this._unbindFromDom(),Q(YXmlText.prototype.__proto__||Object.getPrototypeOf(YXmlText.prototype),"_delete",this).call(this,t,e)}},{key:"_unbindFromDom",value:function(){null!=this._domObserver&&(this._domObserver.disconnect(),this._domObserver=null),null!=this._dom&&(this._dom._yxml=null,this._dom=null)}}]),YXmlText}(YText);YXmlFragment._YXmlElement=YXmlElement,YXmlFragment._YXmlHook=YXmlHook;var gt=new Map,mt=new Map;N(0,ItemJSON),N(1,ItemString),N(2,Delete),N(3,YArray),N(4,YMap),N(5,YText),N(6,YXmlFragment),N(7,YXmlElement),N(8,YXmlText),N(9,YXmlHook);var kt=16777215,bt=function(){function t(e,n){G(this,t),this.user=kt,this.name=e,this.type=L(n)}return K(t,[{key:"equals",value:function(t){return null!==t&&t.user===this.user&&t.name===this.name&&t.type===this.type}},{key:"lessThan",value:function(e){return e.constructor!==t||(this.user1?e-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:{};G(this,t),this.options=r,r.captureTimeout=null==r.captureTimeout?500:r.captureTimeout,this._undoBuffer=[],this._redoBuffer=[],this._scope=e,this._undoing=!1,this._redoing=!1,this._lastTransactionWasUndo=!1;var i=e._y;this.y=i,i.on("afterTransaction",function(t,i,o){if(!o&&i.changedParentTypes.has(e)){var s=new Ot(t,i);if(n._undoing)n._lastTransactionWasUndo=!0,n._redoBuffer.push(s);else{var a=n._undoBuffer.length>0?n._undoBuffer[n._undoBuffer.length-1]:null;!1===n._redoing&&!1===n._lastTransactionWasUndo&&null!==a&&s.created-a.created<=r.captureTimeout?(a.created=s.created,null!==s.toState&&(a.toState=s.toState,null===a.fromState&&(a.fromState=s.fromState)),s.deletedStructs.forEach(a.deletedStructs.add,a.deletedStructs)):(n._lastTransactionWasUndo=!1,n._undoBuffer.push(s)),n._redoing||(n._redoBuffer=[])}}})}return K(t,[{key:"undo",value:function(){this._undoing=!0;var t=j(this.y,this._scope,this._undoBuffer);return this._undoing=!1,t}},{key:"redo",value:function(){this._redoing=!0;var t=j(this.y,this._scope,this._redoBuffer);return this._redoing=!1,t}}]),t}(),At=1e3,Bt=60*At,xt=60*Bt,Dt=24*xt,Tt=365.25*Dt,Nt=function(t,e){e=e||{};var n=void 0===t?"undefined":Z(t);if("string"===n&&t.length>0)return C(t);if("number"===n&&!1===isNaN(t))return e.long?F(t):R(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))},It=M(function(t,e){function n(t){var n,r=0;for(n in t)r=(r<<5)-r+t.charCodeAt(n),r|=0;return e.colors[Math.abs(r)%e.colors.length]}function r(t){function r(){if(r.enabled){var t=r,n=+new Date,i=n-(l||n);t.diff=i,t.prev=l,t.curr=n,l=n;for(var o=new Array(arguments.length),s=0;s=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))}function r(t){var n=this.useColors;if(t[0]=(n?"%c":"")+this.namespace+(n?" %c":" ")+t[0]+(n?"%c ":" ")+"+"+e.humanize(this.diff),n){var r="color: "+this.color;t.splice(1,0,r,"color: inherit");var i=0,o=0;t[0].replace(/%[a-zA-Z%]/g,function(t){"%%"!==t&&(i++,"%c"===t&&(o=i))}),t.splice(o,0,r)}}function i(){return"object"===("undefined"==typeof console?"undefined":Z(console))&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function o(t){try{null==t?e.storage.removeItem("debug"):e.storage.debug=t}catch(t){}}function s(){var t;try{t=e.storage.debug}catch(t){}return!t&&"undefined"!=typeof process&&"env"in process&&(t=process.env.DEBUG),t}e=t.exports=It,e.log=i,e.formatArgs=r,e.save=o,e.load=s,e.useColors=n,e.storage="undefined"!=typeof chrome&&void 0!==chrome.storage?chrome.storage.local:function(){try{return window.localStorage}catch(t){}}(),e.colors=["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],e.formatters.j=function(t){try{return JSON.stringify(t)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}},e.enable(s())})),Vt=(Lt.log,Lt.formatArgs,Lt.save,Lt.load,Lt.useColors,Lt.storage,Lt.colors,function(){function t(e,n){if(G(this,t),this.y=e,this.opts=n,null==n.role||"master"===n.role)this.role="master";else{if("slave"!==n.role)throw new Error("Role must be either 'master' or 'slave'!");this.role="slave"}this.log=Lt("y:connector"),this.logMessage=Lt("y:connector-message"),this._forwardAppliedStructs=n.forwardAppliedOperations||!1,this.role=n.role,this.connections=new Map,this.isSynced=!1,this.userEventListeners=[],this.whenSyncedListeners=[],this.currentSyncTarget=null,this.debug=!0===n.debug,this.broadcastBuffer=new ct,this.broadcastBufferSize=0,this.protocolVersion=11,this.authInfo=n.auth||null,this.checkAuth=n.checkAuth||function(){return Promise.resolve("write")}, +null==n.maxBufferLength?this.maxBufferLength=-1:this.maxBufferLength=n.maxBufferLength}return K(t,[{key:"reconnect",value:function(){this.log("reconnecting..")}},{key:"disconnect",value:function(){return this.log("discronnecting.."),this.connections=new Map,this.isSynced=!1,this.currentSyncTarget=null,this.whenSyncedListeners=[],Promise.resolve()}},{key:"onUserEvent",value:function(t){this.userEventListeners.push(t)}},{key:"removeUserEventListener",value:function(t){this.userEventListeners=this.userEventListeners.filter(function(e){return t!==e})}},{key:"userLeft",value:function(t){if(this.connections.has(t)){this.log("%s: User left %s",this.y.userID,t),this.connections.delete(t),this._setSyncedWith(null);var e=!0,n=!1,r=void 0;try{for(var i,o=this.userEventListeners[Symbol.iterator]();!(e=(i=o.next()).done);e=!0){(0,i.value)({action:"userLeft",user:t})}}catch(t){n=!0,r=t}finally{try{!e&&o.return&&o.return()}finally{if(n)throw r}}}}},{key:"userJoined",value:function(t,e,n){if(null==e)throw new Error("You must specify the role of the joined user!");if(this.connections.has(t))throw new Error("This user already joined!");this.log("%s: User joined %s",this.y.userID,t),this.connections.set(t,{uid:t,isSynced:!1,role:e,processAfterAuth:[],processAfterSync:[],auth:n||null,receivedSyncStep2:!1});var r={};r.promise=new Promise(function(t){r.resolve=t}),this.connections.get(t).syncStep2=r;var i=!0,o=!1,s=void 0;try{for(var a,l=this.userEventListeners[Symbol.iterator]();!(i=(a=l.next()).done);i=!0){(0,a.value)({action:"userJoined",user:t,role:e})}}catch(t){o=!0,s=t}finally{try{!i&&l.return&&l.return()}finally{if(o)throw s}}this._syncWithUser(t)}},{key:"whenSynced",value:function(t){this.isSynced?t():this.whenSyncedListeners.push(t)}},{key:"_syncWithUser",value:function(t){"slave"!==this.role&&l(this,t)}},{key:"_fireIsSyncedListeners",value:function(){if(!this.isSynced){this.isSynced=!0;var t=!0,e=!1,n=void 0;try{for(var r,i=this.whenSyncedListeners[Symbol.iterator]();!(t=(r=i.next()).done);t=!0){(0,r.value)()}}catch(t){e=!0,n=t}finally{try{!t&&i.return&&i.return()}finally{if(e)throw n}}this.whenSyncedListeners=[],this.y._setContentReady(),this.y.emit("synced")}}},{key:"send",value:function(t,e){var n=this.y;if(!(e instanceof ArrayBuffer||e instanceof Uint8Array))throw new Error("Expected Message to be an ArrayBuffer or Uint8Array - don't use this method to send custom messages");this.log("User%s to User%s: Send '%y'",n.userID,t,e),this.logMessage("User%s to User%s: Send %Y",n.userID,t,[n,e])}},{key:"broadcast",value:function(t){var e=this.y;if(!(t instanceof ArrayBuffer||t instanceof Uint8Array))throw new Error("Expected Message to be an ArrayBuffer or Uint8Array - don't use this method to send custom messages");this.log("User%s: Broadcast '%y'",e.userID,t),this.logMessage("User%s: Broadcast: %Y",e.userID,[e,t])}},{key:"broadcastStruct",value:function(t){var e=this,n=0===this.broadcastBuffer.length;if(n&&(this.broadcastBuffer.writeVarString(this.y.room),this.broadcastBuffer.writeVarString("update"),this.broadcastBufferSize=0,this.broadcastBufferSizePos=this.broadcastBuffer.pos,this.broadcastBuffer.writeUint32(0)),this.broadcastBufferSize++,t._toBinary(this.broadcastBuffer),this.maxBufferLength>0&&this.broadcastBuffer.length>this.maxBufferLength){var r=this.broadcastBuffer;r.setUint32(this.broadcastBufferSizePos,this.broadcastBufferSize),this.broadcastBuffer=new ct,this.whenRemoteResponsive().then(function(){e.broadcast(r.createBuffer())})}else n&&setTimeout(function(){if(e.broadcastBuffer.length>0){var t=e.broadcastBuffer;t.setUint32(e.broadcastBufferSizePos,e.broadcastBufferSize),e.broadcast(t.createBuffer()),e.broadcastBuffer=new ct}},0)}},{key:"whenRemoteResponsive",value:function(){return new Promise(function(t){setTimeout(t,100)})}},{key:"receiveMessage",value:function(t,e,n){var r=this,i=this.y,o=i.userID;if(n=n||!1,!(e instanceof ArrayBuffer||e instanceof Uint8Array))return Promise.reject(new Error("Expected Message to be an ArrayBuffer or Uint8Array!"));if(t===o)return Promise.resolve();var s=new lt(e),a=new ct,l=s.readVarString();a.writeVarString(l);var u=s.readVarString(),c=this.connections.get(t);if(this.log("User%s from User%s: Receive '%s'",o,t,u),this.logMessage("User%s from User%s: Receive %Y",o,t,[i,e]),null==c&&!n)throw new Error("Received message from unknown peer!");if("sync step 1"===u||"sync step 2"===u){var h=s.readVarUint();if(null==c.auth)return c.processAfterAuth.push([u,c,s,a,t]),this.checkAuth(h,i,t).then(function(t){null==c.auth&&(c.auth=t,i.emit("userAuthenticated",{user:c.uid,auth:t}));var e=c.processAfterAuth;c.processAfterAuth=[],e.forEach(function(t){return r.computeMessage(t[0],t[1],t[2],t[3],t[4])})})}!n&&null==c.auth||"update"===u&&!c.isSynced?c.processAfterSync.push([u,c,s,a,t,!1]):this.computeMessage(u,c,s,a,t,n)}},{key:"computeMessage",value:function(t,e,r,i,o,s){if("sync step 1"!==t||"write"!==e.auth&&"read"!==e.auth){var a=this.y;a.transact(function(){if("sync step 2"===t&&"write"===e.auth)f(r,i,a,e,o);else{if("update"!==t||!s&&"write"!==e.auth)throw new Error("Unable to receive message");n(a,r)}},!0)}else c(r,i,this.y,e,o)}},{key:"_setSyncedWith",value:function(t){var e=this;if(null!=t){var n=this.connections.get(t);n.isSynced=!0;var r=n.processAfterSync;n.processAfterSync=[],r.forEach(function(t){e.computeMessage(t[0],t[1],t[2],t[3],t[4])})}var i=Array.from(this.connections.values());i.length>0&&i.every(function(t){return t.isSynced})&&this._fireIsSyncedListeners()}}]),t}()),Pt=function(){function t(e){G(this,t),this.opts=e,this.ys=new Map}return K(t,[{key:"_init",value:function(t){var e=this,n=this.ys.get(t);return void 0===n?(n=X(),n.mutualExclude=z(),this.ys.set(t,n),this.init(t).then(function(){return t.on("afterTransaction",function(t,n){var r=e.ys.get(t);if(r.len>0){r.buffer.setUint32(0,r.len),e.saveUpdate(t,r.buffer.createBuffer(),n);var i=X();for(var o in i)r[o]=i[o]}}),e.retrieve(t)}).then(function(){return Promise.resolve(n)})):Promise.resolve(n)}},{key:"deinit",value:function(t){this.ys.delete(t),t.persistence=null}},{key:"destroy",value:function(){this.ys=null}},{key:"removePersistedData",value:function(t){var e=this,n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];this.ys.forEach(function(r,i){i.room===t&&(n?i.destroy():e.deinit(i))})}},{key:"saveUpdate",value:function(t){}},{key:"saveStruct",value:function(t,e){var n=this.ys.get(t);void 0!==n&&n.mutualExclude(function(){e._toBinary(n.buffer),n.len++})}},{key:"retrieve",value:function(t,e,r){var i=this.ys.get(t);void 0!==i&&i.mutualExclude(function(){t.transact(function(){if(null!=e&&W(t,new lt(new Uint8Array(e))),null!=r)for(var i=0;i1&&void 0!==arguments[1]&&arguments[1],n=null===this._transaction;n&&(this._transaction=new ht(this),this.emit("beforeTransaction",this,this._transaction,e));try{t(this)}catch(t){console.error(t)}if(n){this.emit("beforeObserverCalls",this,this._transaction,e);var r=this._transaction;this._transaction=null,r.changedTypes.forEach(function(t,n){n._deleted||n._callObserver(r,t,e)}),r.changedParentTypes.forEach(function(t,e){e._deleted||(t=t.filter(function(t){return!t.target._deleted}),t.forEach(function(t){t.currentTarget=e}),e._deepEventHandler.callEventListeners(r,t))}),this.emit("afterTransaction",this,r,e)}}},{key:"define",value:function(t,e){var n=new bt(t,e),r=this.os.get(n);if(void 0===this.share[t])this.share[t]=r;else if(this.share[t]!==r)throw new Error("Type is already defined with a different constructor");return r}},{key:"get",value:function(t){return this.share[t]}},{key:"disconnect",value:function(){return this.connected?(this.connected=!1,this.connector.disconnect()):Promise.resolve()}},{key:"reconnect",value:function(){return this.connected?Promise.resolve():(this.connected=!0,this.connector.reconnect())}},{key:"destroy",value:function(){Q(Y.prototype.__proto__||Object.getPrototypeOf(Y.prototype),"destroy",this).call(this),this.share=null,null!=this.connector&&(null!=this.connector.destroy?this.connector.destroy():this.connector.disconnect()),null!==this.persistence&&(this.persistence.deinit(this),this.persistence=null),this.os=null,this.ds=null,this.ss=null}},{key:"whenSynced",value:function(){var t=this;return new Promise(function(e){t.once("synced",function(){e()})})}},{key:"_start",get:function(){return null},set:function(t){return null}}]),Y}(Et);return Y.extend=function(){for(var t=0;t id.clock) {\n return\n }\n struct._integrate(y)\n let msu = y._missingStructs.get(id.user)\n if (msu != null) {\n let clock = id.clock\n const finalClock = clock + struct._length\n for (;clock < finalClock; clock++) {\n const missingStructs = msu.get(clock)\n if (missingStructs !== undefined) {\n missingStructs.forEach(missingDef => {\n missingDef.missing--\n if (missingDef.missing === 0) {\n const decoder = missingDef.decoder\n let oldPos = decoder.pos\n let missing = missingDef.struct._fromBinary(y, decoder)\n decoder.pos = oldPos\n if (missing.length === 0) {\n y._readyToIntegrate.push(missingDef.struct)\n }\n }\n })\n msu.delete(clock)\n }\n }\n }\n }\n}\n\nexport function stringifyStructs (y, decoder, strBuilder) {\n const len = decoder.readUint32()\n for (let i = 0; i < len; i++) {\n let reference = decoder.readVarUint()\n let Constr = getStruct(reference)\n let struct = new Constr()\n let missing = struct._fromBinary(y, decoder)\n let logMessage = ' ' + struct._logString()\n if (missing.length > 0) {\n logMessage += ' .. missing: ' + missing.map(logID).join(', ')\n }\n strBuilder.push(logMessage)\n }\n}\n\nexport function integrateRemoteStructs (y, decoder) {\n const len = decoder.readUint32()\n for (let i = 0; i < len; i++) {\n let reference = decoder.readVarUint()\n let Constr = getStruct(reference)\n let struct = new Constr()\n let decoderPos = decoder.pos\n let missing = struct._fromBinary(y, decoder)\n if (missing.length === 0) {\n while (struct != null) {\n _integrateRemoteStructHelper(y, struct)\n struct = y._readyToIntegrate.shift()\n }\n } else {\n let _decoder = new BinaryDecoder(decoder.uint8arr)\n _decoder.pos = decoderPos\n let missingEntry = new MissingEntry(_decoder, missing, struct)\n let missingStructs = y._missingStructs\n for (let i = missing.length - 1; i >= 0; i--) {\n let m = missing[i]\n if (!missingStructs.has(m.user)) {\n missingStructs.set(m.user, new Map())\n }\n let msu = missingStructs.get(m.user)\n if (!msu.has(m.clock)) {\n msu.set(m.clock, [])\n }\n let mArray = msu = msu.get(m.clock)\n mArray.push(missingEntry)\n }\n }\n }\n}\n","\nexport function readStateSet (decoder) {\n let ss = new Map()\n let ssLength = decoder.readUint32()\n for (let i = 0; i < ssLength; i++) {\n let user = decoder.readVarUint()\n let clock = decoder.readVarUint()\n ss.set(user, clock)\n }\n return ss\n}\n\nexport function writeStateSet (y, encoder) {\n let lenPosition = encoder.pos\n let len = 0\n encoder.writeUint32(0)\n for (let [user, clock] of y.ss.state) {\n encoder.writeVarUint(user)\n encoder.writeVarUint(clock)\n len++\n }\n encoder.setUint32(lenPosition, len)\n}\n","import { deleteItemRange } from '../Struct/Delete.js'\nimport ID from '../Util/ID.js'\n\nexport function stringifyDeleteSet (y, decoder, strBuilder) {\n let dsLength = decoder.readUint32()\n for (let i = 0; i < dsLength; i++) {\n let user = decoder.readVarUint()\n strBuilder.push(' -' + user + ':')\n let dvLength = decoder.readVarUint()\n for (let j = 0; j < dvLength; j++) {\n let from = decoder.readVarUint()\n let len = decoder.readVarUint()\n let gc = decoder.readUint8() === 1\n strBuilder.push(`clock: ${from}, length: ${len}, gc: ${gc}`)\n }\n }\n return strBuilder\n}\n\nexport function writeDeleteSet (y, encoder) {\n let currentUser = null\n let currentLength\n let lastLenPos\n\n let numberOfUsers = 0\n let laterDSLenPus = encoder.pos\n encoder.writeUint32(0)\n\n y.ds.iterate(null, null, function (n) {\n var user = n._id.user\n var clock = n._id.clock\n var len = n.len\n var gc = n.gc\n if (currentUser !== user) {\n numberOfUsers++\n // a new user was found\n if (currentUser !== null) { // happens on first iteration\n encoder.setUint32(lastLenPos, currentLength)\n }\n currentUser = user\n encoder.writeVarUint(user)\n // pseudo-fill pos\n lastLenPos = encoder.pos\n encoder.writeUint32(0)\n currentLength = 0\n }\n encoder.writeVarUint(clock)\n encoder.writeVarUint(len)\n encoder.writeUint8(gc ? 1 : 0)\n currentLength++\n })\n if (currentUser !== null) { // happens on first iteration\n encoder.setUint32(lastLenPos, currentLength)\n }\n encoder.setUint32(laterDSLenPus, numberOfUsers)\n}\n\nexport function readDeleteSet (y, decoder) {\n let dsLength = decoder.readUint32()\n for (let i = 0; i < dsLength; i++) {\n let user = decoder.readVarUint()\n let dv = []\n let dvLength = decoder.readUint32()\n for (let j = 0; j < dvLength; j++) {\n let from = decoder.readVarUint()\n let len = decoder.readVarUint()\n let gc = decoder.readUint8() === 1\n dv.push([from, len, gc])\n }\n if (dvLength > 0) {\n let pos = 0\n let d = dv[pos]\n let deletions = []\n y.ds.iterate(new ID(user, 0), new ID(user, Number.MAX_VALUE), function (n) {\n // cases:\n // 1. d deletes something to the right of n\n // => go to next n (break)\n // 2. d deletes something to the left of n\n // => create deletions\n // => reset d accordingly\n // *)=> if d doesn't delete anything anymore, go to next d (continue)\n // 3. not 2) and d deletes something that also n deletes\n // => reset d so that it doesn't contain n's deletion\n // *)=> if d does not delete anything anymore, go to next d (continue)\n while (d != null) {\n var diff = 0 // describe the diff of length in 1) and 2)\n if (n._id.clock + n.len <= d[0]) {\n // 1)\n break\n } else if (d[0] < n._id.clock) {\n // 2)\n // delete maximum the len of d\n // else delete as much as possible\n diff = Math.min(n._id.clock - d[0], d[1])\n // deleteItemRange(y, user, d[0], diff)\n deletions.push([user, d[0], diff])\n } else {\n // 3)\n diff = n._id.clock + n.len - d[0] // never null (see 1)\n if (d[2] && !n.gc) {\n // d marks as gc'd but n does not\n // then delete either way\n // deleteItemRange(y, user, d[0], Math.min(diff, d[1]))\n deletions.push([user, d[0], Math.min(diff, d[1])])\n }\n }\n if (d[1] <= diff) {\n // d doesn't delete anything anymore\n d = dv[++pos]\n } else {\n d[0] = d[0] + diff // reset pos\n d[1] = d[1] - diff // reset length\n }\n }\n })\n // TODO: It would be more performant to apply the deletes in the above loop\n // Adapt the Tree implementation to support delete while iterating\n for (let i = deletions.length - 1; i >= 0; i--) {\n const del = deletions[i]\n deleteItemRange(y, del[0], del[1], del[2])\n }\n // for the rest.. just apply it\n for (; pos < dv.length; pos++) {\n d = dv[pos]\n deleteItemRange(y, user, d[0], d[1])\n // deletions.push([user, d[0], d[1], d[2]])\n }\n }\n }\n}\n","import BinaryEncoder from '../Binary/Encoder.js'\nimport { readStateSet, writeStateSet } from './stateSet.js'\nimport { writeDeleteSet } from './deleteSet.js'\nimport ID from '../Util/ID.js'\nimport { RootFakeUserID } from '../Util/RootID.js'\n\nexport function stringifySyncStep1 (y, decoder, strBuilder) {\n let auth = decoder.readVarString()\n let protocolVersion = decoder.readVarUint()\n strBuilder.push(` - auth: \"${auth}\"`)\n strBuilder.push(` - protocolVersion: ${protocolVersion}`)\n // write SS\n let ssBuilder = []\n let len = decoder.readUint32()\n for (let i = 0; i < len; i++) {\n let user = decoder.readVarUint()\n let clock = decoder.readVarUint()\n ssBuilder.push(`(${user}:${clock})`)\n }\n strBuilder.push(' == SS: ' + ssBuilder.join(','))\n}\n\nexport function sendSyncStep1 (connector, syncUser) {\n let encoder = new BinaryEncoder()\n encoder.writeVarString(connector.y.room)\n encoder.writeVarString('sync step 1')\n encoder.writeVarString(connector.authInfo || '')\n encoder.writeVarUint(connector.protocolVersion)\n writeStateSet(connector.y, encoder)\n connector.send(syncUser, encoder.createBuffer())\n}\n\nexport function writeStructs (y, encoder, ss) {\n const lenPos = encoder.pos\n encoder.writeUint32(0)\n let len = 0\n for (let user of y.ss.state.keys()) {\n let clock = ss.get(user) || 0\n if (user !== RootFakeUserID) {\n y.os.iterate(new ID(user, clock), new ID(user, Number.MAX_VALUE), function (struct) {\n struct._toBinary(encoder)\n len++\n })\n }\n }\n encoder.setUint32(lenPos, len)\n}\n\nexport function readSyncStep1 (decoder, encoder, y, senderConn, sender) {\n let protocolVersion = decoder.readVarUint()\n // check protocol version\n if (protocolVersion !== y.connector.protocolVersion) {\n console.warn(\n `You tried to sync with a Yjs instance that has a different protocol version\n (You: ${protocolVersion}, Client: ${protocolVersion}).\n `)\n y.destroy()\n }\n // write sync step 2\n encoder.writeVarString('sync step 2')\n encoder.writeVarString(y.connector.authInfo || '')\n const ss = readStateSet(decoder)\n writeStructs(y, encoder, ss)\n writeDeleteSet(y, encoder)\n y.connector.send(senderConn.uid, encoder.createBuffer())\n senderConn.receivedSyncStep2 = true\n if (y.connector.role === 'slave') {\n sendSyncStep1(y.connector, sender)\n }\n}\n","import { stringifyStructs, integrateRemoteStructs } from './integrateRemoteStructs.js'\nimport { readDeleteSet } from './deleteSet.js'\n\nexport function stringifySyncStep2 (y, decoder, strBuilder) {\n strBuilder.push(' - auth: ' + decoder.readVarString())\n strBuilder.push(' == OS:')\n stringifyStructs(y, decoder, strBuilder)\n // write DS to string\n strBuilder.push(' == DS:')\n let len = decoder.readUint32()\n for (let i = 0; i < len; i++) {\n let user = decoder.readVarUint()\n strBuilder.push(` User: ${user}: `)\n let len2 = decoder.readUint32()\n for (let j = 0; j < len2; j++) {\n let from = decoder.readVarUint()\n let to = decoder.readVarUint()\n let gc = decoder.readUint8() === 1\n strBuilder.push(`[${from}, ${to}, ${gc}]`)\n }\n }\n}\n\nexport function readSyncStep2 (decoder, encoder, y, senderConn, sender) {\n integrateRemoteStructs(y, decoder)\n readDeleteSet(y, decoder)\n y.connector._setSyncedWith(sender)\n}\n","import BinaryDecoder from '../Binary/Decoder.js'\nimport { stringifyStructs } from './integrateRemoteStructs.js'\nimport { stringifySyncStep1 } from './syncStep1.js'\nimport { stringifySyncStep2 } from './syncStep2.js'\nimport ID from '../Util/ID.js'\nimport RootID from '../Util/RootID.js'\nimport Y from '../Y.js'\n\nexport function messageToString ([y, buffer]) {\n let decoder = new BinaryDecoder(buffer)\n decoder.readVarString() // read roomname\n let type = decoder.readVarString()\n let strBuilder = []\n strBuilder.push('\\n === ' + type + ' ===')\n if (type === 'update') {\n stringifyStructs(y, decoder, strBuilder)\n } else if (type === 'sync step 1') {\n stringifySyncStep1(y, decoder, strBuilder)\n } else if (type === 'sync step 2') {\n stringifySyncStep2(y, decoder, strBuilder)\n } else {\n strBuilder.push('-- Unknown message type - probably an encoding issue!!!')\n }\n return strBuilder.join('\\n')\n}\n\nexport function messageToRoomname (buffer) {\n let decoder = new BinaryDecoder(buffer)\n decoder.readVarString() // roomname\n return decoder.readVarString() // messageType\n}\n\nexport function logID (id) {\n if (id !== null && id._id != null) {\n id = id._id\n }\n if (id === null) {\n return '()'\n } else if (id instanceof ID) {\n return `(${id.user},${id.clock})`\n } else if (id instanceof RootID) {\n return `(${id.name},${id.type})`\n } else if (id.constructor === Y) {\n return `y`\n } else {\n throw new Error('This is not a valid ID!')\n }\n}\n","import { getReference } from '../Util/structReferences.js'\nimport ID from '../Util/ID.js'\nimport { logID } from '../MessageHandler/messageToString.js'\n\n/**\n * Delete all items in an ID-range\n * TODO: implement getItemCleanStartNode for better performance (only one lookup)\n */\nexport function deleteItemRange (y, user, clock, range) {\n const createDelete = y.connector !== null && y.connector._forwardAppliedStructs\n let item = y.os.getItemCleanStart(new ID(user, clock))\n if (item !== null) {\n if (!item._deleted) {\n item._splitAt(y, range)\n item._delete(y, createDelete)\n }\n let itemLen = item._length\n range -= itemLen\n clock += itemLen\n if (range > 0) {\n let node = y.os.findNode(new ID(user, clock))\n while (node !== null && range > 0 && node.val._id.equals(new ID(user, clock))) {\n const nodeVal = node.val\n if (!nodeVal._deleted) {\n nodeVal._splitAt(y, range)\n nodeVal._delete(y, createDelete)\n }\n const nodeLen = nodeVal._length\n range -= nodeLen\n clock += nodeLen\n node = node.next()\n }\n }\n }\n}\n\n/**\n * Delete is not a real struct. It will not be saved in OS\n */\nexport default class Delete {\n constructor () {\n this._target = null\n this._length = null\n }\n _fromBinary (y, decoder) {\n // TODO: set target, and add it to missing if not found\n // There is an edge case in p2p networks!\n const targetID = decoder.readID()\n this._targetID = targetID\n this._length = decoder.readVarUint()\n if (y.os.getItem(targetID) === null) {\n return [targetID]\n } else {\n return []\n }\n }\n _toBinary (encoder) {\n encoder.writeUint8(getReference(this.constructor))\n encoder.writeID(this._targetID)\n encoder.writeVarUint(this._length)\n }\n /**\n * - If created remotely (a remote user deleted something),\n * this Delete is applied to all structs in id-range.\n * - If created lokally (e.g. when y-array deletes a range of elements),\n * this struct is broadcasted only (it is already executed)\n */\n _integrate (y, locallyCreated = false) {\n if (!locallyCreated) {\n // from remote\n const id = this._targetID\n deleteItemRange(y, id.user, id.clock, this._length)\n } else if (y.connector !== null) {\n // from local\n y.connector.broadcastStruct(this)\n }\n if (y.persistence !== null) {\n y.persistence.saveStruct(y, this)\n }\n }\n _logString () {\n return `Delete - target: ${logID(this._targetID)}, len: ${this._length}`\n }\n}\n","\nexport default class Transaction {\n constructor (y) {\n this.y = y\n // types added during transaction\n this.newTypes = new Set()\n // changed types (does not include new types)\n // maps from type to parentSubs (item._parentSub = null for array elements)\n this.changedTypes = new Map()\n this.deletedStructs = new Set()\n this.beforeState = new Map()\n this.changedParentTypes = new Map()\n }\n}\n\nexport function transactionTypeChanged (y, type, sub) {\n if (type !== y && !type._deleted && !y._transaction.newTypes.has(type)) {\n const changedTypes = y._transaction.changedTypes\n let subs = changedTypes.get(type)\n if (subs === undefined) {\n // create if it doesn't exist yet\n subs = new Set()\n changedTypes.set(type, subs)\n }\n subs.add(sub)\n }\n}\n","import { getReference } from '../Util/structReferences.js'\nimport ID from '../Util/ID.js'\nimport { RootFakeUserID } from '../Util/RootID.js'\nimport Delete from './Delete.js'\nimport { transactionTypeChanged } from '../Transaction.js'\n\n/**\n * Helper utility to split an Item (see _splitAt)\n * - copy all properties from a to b\n * - connect a to b\n * - assigns the correct _id\n * - save b to os\n */\nexport function splitHelper (y, a, b, diff) {\n const aID = a._id\n b._id = new ID(aID.user, aID.clock + diff)\n b._origin = a\n b._left = a\n b._right = a._right\n if (b._right !== null) {\n b._right._left = b\n }\n b._right_origin = a._right_origin\n // do not set a._right_origin, as this will lead to problems when syncing\n a._right = b\n b._parent = a._parent\n b._parentSub = a._parentSub\n b._deleted = a._deleted\n // now search all relevant items to the right and update origin\n // if origin is not it foundOrigins, we don't have to search any longer\n let foundOrigins = new Set()\n foundOrigins.add(a)\n let o = b._right\n while (o !== null && foundOrigins.has(o._origin)) {\n if (o._origin === a) {\n o._origin = b\n }\n foundOrigins.add(o)\n o = o._right\n }\n y.os.put(b)\n}\n\nexport default class Item {\n constructor () {\n this._id = null\n this._origin = null\n this._left = null\n this._right = null\n this._right_origin = null\n this._parent = null\n this._parentSub = null\n this._deleted = false\n this._redone = null\n }\n /**\n * Create a operation with the same effect (without position effect)\n */\n _copy () {\n return new this.constructor()\n }\n /**\n * Redo the effect of this operation.\n */\n _redo (y) {\n if (this._redone !== null) {\n return this._redone\n }\n let struct = this._copy()\n let left = this._left\n let right = this\n let parent = this._parent\n // make sure that parent is redone\n if (parent._deleted === true && parent._redone === null) {\n parent._redo(y)\n }\n if (parent._redone !== null) {\n parent = parent._redone\n // find next cloned items\n while (left !== null) {\n if (left._redone !== null && left._redone._parent === parent) {\n left = left._redone\n break\n }\n left = left._left\n }\n while (right !== null) {\n if (right._redone !== null && right._redone._parent === parent) {\n right = right._redone\n }\n right = right._right\n }\n }\n struct._origin = left\n struct._left = left\n struct._right = right\n struct._right_origin = right\n struct._parent = parent\n struct._parentSub = this._parentSub\n struct._integrate(y)\n this._redone = struct\n return struct\n }\n\n get _lastId () {\n return new ID(this._id.user, this._id.clock + this._length - 1)\n }\n get _length () {\n return 1\n }\n /**\n * Splits this struct so that another struct can be inserted in-between.\n * This must be overwritten if _length > 1\n * Returns right part after split\n * - diff === 0 => this\n * - diff === length => this._right\n * - otherwise => split _content and return right part of split\n * (see ItemJSON/ItemString for implementation)\n */\n _splitAt (y, diff) {\n if (diff === 0) {\n return this\n }\n return this._right\n }\n _delete (y, createDelete = true) {\n if (!this._deleted) {\n this._deleted = true\n y.ds.markDeleted(this._id, this._length)\n let del = new Delete()\n del._targetID = this._id\n del._length = this._length\n if (createDelete) {\n // broadcast and persists Delete\n del._integrate(y, true)\n } else if (y.persistence !== null) {\n // only persist Delete\n y.persistence.saveStruct(y, del)\n }\n transactionTypeChanged(y, this._parent, this._parentSub)\n y._transaction.deletedStructs.add(this)\n }\n }\n /**\n * This is called right before this struct receives any children.\n * It can be overwritten to apply pending changes before applying remote changes\n */\n _beforeChange () {\n // nop\n }\n /*\n * - Integrate the struct so that other types/structs can see it\n * - Add this struct to y.os\n * - Check if this is struct deleted\n */\n _integrate (y) {\n y._transaction.newTypes.add(this)\n const parent = this._parent\n const selfID = this._id\n const user = selfID === null ? y.userID : selfID.user\n const userState = y.ss.getState(user)\n if (selfID === null) {\n this._id = y.ss.getNextID(this._length)\n } else if (selfID.user === RootFakeUserID) {\n // nop\n } else if (selfID.clock < userState) {\n // already applied..\n return []\n } else if (selfID.clock === userState) {\n y.ss.setState(selfID.user, userState + this._length)\n } else {\n // missing content from user\n throw new Error('Can not apply yet!')\n }\n if (!parent._deleted && !y._transaction.changedTypes.has(parent) && !y._transaction.newTypes.has(parent)) {\n // this is the first time parent is updated\n // or this types is new\n this._parent._beforeChange()\n }\n /*\n # $this has to find a unique position between origin and the next known character\n # case 1: $origin equals $o.origin: the $creator parameter decides if left or right\n # let $OL= [o1,o2,o3,o4], whereby $this is to be inserted between o1 and o4\n # o2,o3 and o4 origin is 1 (the position of o2)\n # there is the case that $this.creator < o2.creator, but o3.creator < $this.creator\n # then o2 knows o3. Since on another client $OL could be [o1,o3,o4] the problem is complex\n # therefore $this would be always to the right of o3\n # case 2: $origin < $o.origin\n # if current $this insert_position > $o origin: $this ins\n # else $insert_position will not change\n # (maybe we encounter case 1 later, then this will be to the right of $o)\n # case 3: $origin > $o.origin\n # $this insert_position is to the left of $o (forever!)\n */\n // handle conflicts\n let o\n // set o to the first conflicting item\n if (this._left !== null) {\n o = this._left._right\n } else if (this._parentSub !== null) {\n o = this._parent._map.get(this._parentSub) || null\n } else {\n o = this._parent._start\n }\n let conflictingItems = new Set()\n let itemsBeforeOrigin = new Set()\n // Let c in conflictingItems, b in itemsBeforeOrigin\n // ***{origin}bbbb{this}{c,b}{c,b}{o}***\n // Note that conflictingItems is a subset of itemsBeforeOrigin\n while (o !== null && o !== this._right) {\n itemsBeforeOrigin.add(o)\n conflictingItems.add(o)\n if (this._origin === o._origin) {\n // case 1\n if (o._id.user < this._id.user) {\n this._left = o\n conflictingItems.clear()\n }\n } else if (itemsBeforeOrigin.has(o._origin)) {\n // case 2\n if (!conflictingItems.has(o._origin)) {\n this._left = o\n conflictingItems.clear()\n }\n } else {\n break\n }\n // TODO: try to use right_origin instead.\n // Then you could basically omit conflictingItems!\n // Note: you probably can't use right_origin in every case.. only when setting _left\n o = o._right\n }\n // reconnect left/right + update parent map/start if necessary\n const parentSub = this._parentSub\n if (this._left === null) {\n let right\n if (parentSub !== null) {\n const pmap = parent._map\n right = pmap.get(parentSub) || null\n pmap.set(parentSub, this)\n } else {\n right = parent._start\n parent._start = this\n }\n this._right = right\n if (right !== null) {\n right._left = this\n }\n } else {\n const left = this._left\n const right = left._right\n this._right = right\n left._right = this\n if (right !== null) {\n right._left = this\n }\n }\n if (parent._deleted) {\n this._delete(y, false)\n }\n y.os.put(this)\n transactionTypeChanged(y, parent, parentSub)\n if (this._id.user !== RootFakeUserID) {\n if (y.connector !== null && (y.connector._forwardAppliedStructs || this._id.user === y.userID)) {\n y.connector.broadcastStruct(this)\n }\n if (y.persistence !== null) {\n y.persistence.saveStruct(y, this)\n }\n }\n }\n _toBinary (encoder) {\n encoder.writeUint8(getReference(this.constructor))\n let info = 0\n if (this._origin !== null) {\n info += 0b1 // origin is defined\n }\n // TODO: remove\n /* no longer send _left\n if (this._left !== this._origin) {\n info += 0b10 // do not copy origin to left\n }\n */\n if (this._right_origin !== null) {\n info += 0b100\n }\n if (this._parentSub !== null) {\n info += 0b1000\n }\n encoder.writeUint8(info)\n encoder.writeID(this._id)\n if (info & 0b1) {\n encoder.writeID(this._origin._lastId)\n }\n // TODO: remove\n /* see above\n if (info & 0b10) {\n encoder.writeID(this._left._lastId)\n }\n */\n if (info & 0b100) {\n encoder.writeID(this._right_origin._id)\n }\n if ((info & 0b101) === 0) {\n // neither origin nor right is defined\n encoder.writeID(this._parent._id)\n }\n if (info & 0b1000) {\n encoder.writeVarString(JSON.stringify(this._parentSub))\n }\n }\n _fromBinary (y, decoder) {\n let missing = []\n const info = decoder.readUint8()\n const id = decoder.readID()\n this._id = id\n // read origin\n if (info & 0b1) {\n // origin != null\n const originID = decoder.readID()\n // we have to query for left again because it might have been split/merged..\n const origin = y.os.getItemCleanEnd(originID)\n if (origin === null) {\n missing.push(originID)\n } else {\n this._origin = origin\n this._left = this._origin\n }\n }\n // read right\n if (info & 0b100) {\n // right != null\n const rightID = decoder.readID()\n // we have to query for right again because it might have been split/merged..\n const right = y.os.getItemCleanStart(rightID)\n if (right === null) {\n missing.push(rightID)\n } else {\n this._right = right\n this._right_origin = right\n }\n }\n // read parent\n if ((info & 0b101) === 0) {\n // neither origin nor right is defined\n const parentID = decoder.readID()\n // parent does not change, so we don't have to search for it again\n if (this._parent === null) {\n const parent = y.os.get(parentID)\n if (parent === null) {\n missing.push(parentID)\n } else {\n this._parent = parent\n }\n }\n } else if (this._parent === null) {\n if (this._origin !== null) {\n this._parent = this._origin._parent\n } else if (this._right_origin !== null) {\n this._parent = this._right_origin._parent\n }\n }\n if (info & 0b1000) {\n // TODO: maybe put this in read parent condition (you can also read parentsub from left/right)\n this._parentSub = JSON.parse(decoder.readVarString())\n }\n if (y.ss.getState(id.user) < id.clock) {\n missing.push(new ID(id.user, id.clock - 1))\n }\n return missing\n }\n}\n","import Item from './Item.js'\nimport EventHandler from '../Util/EventHandler.js'\nimport ID from '../Util/ID.js'\n\n// restructure children as if they were inserted one after another\nfunction integrateChildren (y, start) {\n let right\n do {\n right = start._right\n start._right = null\n start._right_origin = null\n start._origin = start._left\n start._integrate(y)\n start = right\n } while (right !== null)\n}\n\nexport function getListItemIDByPosition (type, i) {\n let pos = 0\n let n = type._start\n while (n !== null) {\n if (!n._deleted) {\n if (pos <= i && i < pos + n._length) {\n const id = n._id\n return new ID(id.user, id.clock + i - pos)\n }\n pos++\n }\n n = n._right\n }\n}\n\nexport default class Type extends Item {\n constructor () {\n super()\n this._map = new Map()\n this._start = null\n this._y = null\n this._eventHandler = new EventHandler()\n this._deepEventHandler = new EventHandler()\n }\n getPathTo (type) {\n if (type === this) {\n return []\n }\n const path = []\n const y = this._y\n while (type._parent !== this && this._parent !== y) {\n let parent = type._parent\n if (type._parentSub !== null) {\n path.push(type._parentSub)\n } else {\n // parent is array-ish\n for (let [i, child] of parent) {\n if (child === type) {\n path.push(i)\n break\n }\n }\n }\n type = parent\n }\n if (this._parent !== this) {\n throw new Error('The type is not a child of this node')\n }\n return path\n }\n _callEventHandler (transaction, event) {\n const changedParentTypes = transaction.changedParentTypes\n this._eventHandler.callEventListeners(transaction, event)\n let type = this\n while (type !== this._y) {\n let events = changedParentTypes.get(type)\n if (events === undefined) {\n events = []\n changedParentTypes.set(type, events)\n }\n events.push(event)\n type = type._parent\n }\n }\n _transact (f) {\n const y = this._y\n if (y !== null) {\n y.transact(f)\n } else {\n f(y)\n }\n }\n observe (f) {\n this._eventHandler.addEventListener(f)\n }\n observeDeep (f) {\n this._deepEventHandler.addEventListener(f)\n }\n unobserve (f) {\n this._eventHandler.removeEventListener(f)\n }\n unobserveDeep (f) {\n this._deepEventHandler.removeEventListener(f)\n }\n _integrate (y) {\n super._integrate(y)\n this._y = y\n // when integrating children we must make sure to\n // integrate start\n const start = this._start\n if (start !== null) {\n this._start = null\n integrateChildren(y, start)\n }\n // integrate map children\n const map = this._map\n this._map = new Map()\n for (let t of map.values()) {\n // TODO make sure that right elements are deleted!\n integrateChildren(y, t)\n }\n }\n _delete (y, createDelete) {\n super._delete(y, createDelete)\n y._transaction.changedTypes.delete(this)\n // delete map types\n for (let value of this._map.values()) {\n if (value instanceof Item && !value._deleted) {\n value._delete(y, false)\n }\n }\n // delete array types\n let t = this._start\n while (t !== null) {\n if (!t._deleted) {\n t._delete(y, false)\n }\n t = t._right\n }\n }\n}\n","import { YXmlText, YXmlHook } from './y-xml.js'\n\nexport function defaultDomFilter (node, attributes) {\n return attributes\n}\n\nexport function getAnchorViewPosition (scrollElement) {\n if (scrollElement == null) {\n return null\n }\n let anchor = document.getSelection().anchorNode\n if (anchor != null) {\n let top = getBoundingClientRect(anchor).top\n if (top >= 0 && top <= document.documentElement.clientHeight) {\n return {\n anchor: anchor,\n top: top\n }\n }\n }\n return {\n anchor: null,\n scrollTop: scrollElement.scrollTop,\n scrollHeight: scrollElement.scrollHeight\n }\n}\n\n// get BoundingClientRect that works on text nodes\nexport function getBoundingClientRect (element) {\n if (element.getBoundingClientRect != null) {\n // is element node\n return element.getBoundingClientRect()\n } else {\n // is text node\n if (element.parentNode == null) {\n // range requires that text nodes have a parent\n let span = document.createElement('span')\n span.appendChild(element)\n }\n let range = document.createRange()\n range.selectNode(element)\n return range.getBoundingClientRect()\n }\n}\n\nexport function fixScrollPosition (scrollElement, fix) {\n if (scrollElement !== null && fix !== null) {\n if (fix.anchor === null) {\n if (scrollElement.scrollTop === fix.scrollTop) {\n scrollElement.scrollTop = scrollElement.scrollHeight - fix.scrollHeight\n }\n } else {\n scrollElement.scrollTop = getBoundingClientRect(fix.anchor).top - fix.top\n }\n }\n}\n\nfunction iterateUntilUndeleted (item) {\n while (item !== null && item._deleted) {\n item = item._right\n }\n return item\n}\n\nfunction _insertNodeHelper (yxml, prevExpectedNode, child) {\n let insertedNodes = yxml.insertDomElementsAfter(prevExpectedNode, [child])\n if (insertedNodes.length > 0) {\n return insertedNodes[0]\n } else {\n return prevExpectedNode\n }\n}\n\n/*\n * 1. Check if any of the nodes was deleted\n * 2. Iterate over the children.\n * 2.1 If a node exists without _yxml property, insert a new node\n * 2.2 If _contents.length < dom.childNodes.length, fill the\n * rest of _content with childNodes\n * 2.3 If a node was moved, delete it and\n * recreate a new yxml element that is bound to that node.\n * You can detect that a node was moved because expectedId\n * !== actualId in the list\n */\nexport function applyChangesFromDom (dom) {\n const yxml = dom._yxml\n if (yxml.constructor === YXmlHook) {\n return\n }\n const y = yxml._y\n let knownChildren =\n new Set(\n Array.prototype.map.call(dom.childNodes, child => child._yxml)\n .filter(id => id !== undefined)\n )\n // 1. Check if any of the nodes was deleted\n yxml.forEach(function (childType, i) {\n if (!knownChildren.has(childType)) {\n childType._delete(y)\n }\n })\n // 2. iterate\n let childNodes = dom.childNodes\n let len = childNodes.length\n let prevExpectedNode = null\n let expectedNode = iterateUntilUndeleted(yxml._start)\n for (let domCnt = 0; domCnt < len; domCnt++) {\n const child = childNodes[domCnt]\n const childYXml = child._yxml\n if (childYXml != null) {\n if (childYXml === false) {\n // should be ignored or is going to be deleted\n continue\n }\n if (expectedNode !== null) {\n if (expectedNode !== childYXml) {\n // 2.3 Not expected node\n if (childYXml._parent !== this) {\n // element is going to be deleted by its previous parent\n child._yxml = null\n } else {\n childYXml._delete(y)\n }\n prevExpectedNode = _insertNodeHelper(yxml, prevExpectedNode, child)\n } else {\n prevExpectedNode = expectedNode\n expectedNode = iterateUntilUndeleted(expectedNode._right)\n }\n // if this is the expected node id, just continue\n } else {\n // 2.2 fill _conten with child nodes\n prevExpectedNode = _insertNodeHelper(yxml, prevExpectedNode, child)\n }\n } else {\n // 2.1 A new node was found\n prevExpectedNode = _insertNodeHelper(yxml, prevExpectedNode, child)\n }\n }\n}\n\nexport function reflectChangesOnDom (events, _document) {\n // Make sure that no filtered attributes are applied to the structure\n // if they were, delete them\n /*\n events.forEach(event => {\n const target = event.target\n if (event.attributesChanged === undefined) {\n // event.target is Y.XmlText\n return\n }\n const keys = this._domFilter(target.nodeName, Array.from(event.attributesChanged))\n if (keys === null) {\n target._delete()\n } else {\n const removeKeys = new Set() // is a copy of event.attributesChanged\n event.attributesChanged.forEach(key => { removeKeys.add(key) })\n keys.forEach(key => {\n // remove all accepted keys from removeKeys\n removeKeys.delete(key)\n })\n // remove the filtered attribute\n removeKeys.forEach(key => {\n target.removeAttribute(key)\n })\n }\n })\n */\n this._mutualExclude(() => {\n events.forEach(event => {\n const yxml = event.target\n const dom = yxml._dom\n if (dom != null) {\n // TODO: do this once before applying stuff\n // let anchorViewPosition = getAnchorViewPosition(yxml._scrollElement)\n if (yxml.constructor === YXmlText) {\n yxml._dom.nodeValue = yxml.toString()\n } else if (event.attributesChanged !== undefined) {\n // update attributes\n event.attributesChanged.forEach(attributeName => {\n const value = yxml.getAttribute(attributeName)\n if (value === undefined) {\n dom.removeAttribute(attributeName)\n } else {\n dom.setAttribute(attributeName, value)\n }\n })\n /**\n * TODO: instead of chard-checking the types, it would be best to\n * specify the type's features. E.g.\n * - _yxmlHasAttributes\n * - _yxmlHasChildren\n * Furthermore, the features shouldn't be encoded in the types,\n * only in the attributes (above)\n */\n if (event.childListChanged && yxml.constructor !== YXmlHook) {\n let currentChild = dom.firstChild\n yxml.forEach(function (t) {\n let expectedChild = t.getDom(_document)\n if (expectedChild.parentNode === dom) {\n // is already attached to the dom. Look for it\n while (currentChild !== expectedChild) {\n let del = currentChild\n currentChild = currentChild.nextSibling\n dom.removeChild(del)\n }\n currentChild = currentChild.nextSibling\n } else {\n // this dom is not yet attached to dom\n dom.insertBefore(expectedChild, currentChild)\n }\n })\n while (currentChild !== null) {\n let tmp = currentChild.nextSibling\n dom.removeChild(currentChild)\n currentChild = tmp\n }\n }\n }\n /* TODO: smartscrolling\n .. else if (event.type === 'childInserted' || event.type === 'insert') {\n let nodes = event.values\n for (let i = nodes.length - 1; i >= 0; i--) {\n let node = nodes[i]\n node.setDomFilter(yxml._domFilter)\n node.enableSmartScrolling(yxml._scrollElement)\n let dom = node.getDom()\n let fixPosition = null\n let nextDom = null\n if (yxml._content.length > event.index + i + 1) {\n nextDom = yxml.get(event.index + i + 1).getDom()\n }\n yxml._dom.insertBefore(dom, nextDom)\n if (anchorViewPosition === null) {\n // nop\n } else if (anchorViewPosition.anchor !== null) {\n // no scrolling when current selection\n if (!dom.contains(anchorViewPosition.anchor) && !anchorViewPosition.anchor.contains(dom)) {\n fixPosition = anchorViewPosition\n }\n } else if (getBoundingClientRect(dom).top <= 0) {\n // adjust scrolling if modified element is out of view,\n // there is no anchor element, and the browser did not adjust scrollTop (this is checked later)\n fixPosition = anchorViewPosition\n }\n fixScrollPosition(yxml._scrollElement, fixPosition)\n }\n } else if (event.type === 'childRemoved' || event.type === 'delete') {\n for (let i = event.values.length - 1; i >= 0; i--) {\n let dom = event.values[i]._dom\n let fixPosition = null\n if (anchorViewPosition === null) {\n // nop\n } else if (anchorViewPosition.anchor !== null) {\n // no scrolling when current selection\n if (!dom.contains(anchorViewPosition.anchor) && !anchorViewPosition.anchor.contains(dom)) {\n fixPosition = anchorViewPosition\n }\n } else if (getBoundingClientRect(dom).top <= 0) {\n // adjust scrolling if modified element is out of view,\n // there is no anchor element, and the browser did not adjust scrollTop (this is checked later)\n fixPosition = anchorViewPosition\n }\n dom.remove()\n fixScrollPosition(yxml._scrollElement, fixPosition)\n }\n }\n */\n }\n })\n })\n}\n","import ID from './ID.js'\nimport RootID from './RootID.js'\n\nexport function getRelativePosition (type, offset) {\n let t = type._start\n while (t !== null) {\n if (t._deleted === false) {\n if (t._length > offset) {\n return [t._id.user, t._id.clock + offset]\n }\n offset -= t._length\n }\n t = t._right\n }\n return ['endof', type._id.user, type._id.clock || null, type._id.name || null, type._id.type || null]\n}\n\nexport function fromRelativePosition (y, rpos) {\n if (rpos[0] === 'endof') {\n let id\n if (rpos[3] === null) {\n id = new ID(rpos[1], rpos[2])\n } else {\n id = new RootID(rpos[3], rpos[4])\n }\n const type = y.os.get(id)\n return {\n type,\n offset: type.length\n }\n } else {\n let offset = 0\n let struct = y.os.findNodeWithUpperBound(new ID(rpos[0], rpos[1])).val\n const parent = struct._parent\n if (parent._deleted) {\n return null\n }\n if (!struct._deleted) {\n offset = rpos[1] - struct._id.clock\n }\n struct = struct._left\n while (struct !== null) {\n if (!struct._deleted) {\n offset += struct._length\n }\n struct = struct._left\n }\n return {\n type: parent,\n offset: offset\n }\n }\n}\n","/* globals getSelection */\n\nimport { getRelativePosition, fromRelativePosition } from '../../Util/relativePosition.js'\n\nlet browserSelection = null\nlet relativeSelection = null\n\nexport let beforeTransactionSelectionFixer\nif (typeof getSelection !== 'undefined') {\n beforeTransactionSelectionFixer = function _beforeTransactionSelectionFixer (y, transaction, remote) {\n if (!remote) {\n return\n }\n relativeSelection = { from: null, to: null, fromY: null, toY: null }\n browserSelection = getSelection()\n const anchorNode = browserSelection.anchorNode\n if (anchorNode !== null && anchorNode._yxml != null) {\n const yxml = anchorNode._yxml\n relativeSelection.from = getRelativePosition(yxml, browserSelection.anchorOffset)\n relativeSelection.fromY = yxml._y\n }\n const focusNode = browserSelection.focusNode\n if (focusNode !== null && focusNode._yxml != null) {\n const yxml = focusNode._yxml\n relativeSelection.to = getRelativePosition(yxml, browserSelection.focusOffset)\n relativeSelection.toY = yxml._y\n }\n }\n} else {\n beforeTransactionSelectionFixer = function _fakeBeforeTransactionSelectionFixer () {}\n}\n\nexport function afterTransactionSelectionFixer (y, transaction, remote) {\n if (relativeSelection === null || !remote) {\n return\n }\n const to = relativeSelection.to\n const from = relativeSelection.from\n const fromY = relativeSelection.fromY\n const toY = relativeSelection.toY\n let shouldUpdate = false\n let anchorNode = browserSelection.anchorNode\n let anchorOffset = browserSelection.anchorOffset\n let focusNode = browserSelection.focusNode\n let focusOffset = browserSelection.focusOffset\n if (from !== null) {\n let sel = fromRelativePosition(fromY, from)\n if (sel !== null) {\n let node = sel.type.getDom()\n let offset = sel.offset\n if (node !== anchorNode || offset !== anchorOffset) {\n anchorNode = node\n anchorOffset = offset\n shouldUpdate = true\n }\n }\n }\n if (to !== null) {\n let sel = fromRelativePosition(toY, to)\n if (sel !== null) {\n let node = sel.type.getDom()\n let offset = sel.offset\n if (node !== focusNode || offset !== focusOffset) {\n focusNode = node\n focusOffset = offset\n shouldUpdate = true\n }\n }\n }\n if (shouldUpdate) {\n browserSelection.setBaseAndExtent(\n anchorNode,\n anchorOffset,\n focusNode,\n focusOffset\n )\n }\n}\n","\nexport default function simpleDiff (a, b) {\n let left = 0 // number of same characters counting from left\n let right = 0 // number of same characters counting from right\n while (left < a.length && left < b.length && a[left] === b[left]) {\n left++\n }\n if (left !== a.length || left !== b.length) {\n // Only check right if a !== b\n while (right + left < a.length && right + left < b.length && a[a.length - right - 1] === b[b.length - right - 1]) {\n right++\n }\n }\n return {\n pos: left,\n remove: a.length - left - right,\n insert: b.slice(left, b.length - right)\n }\n}\n","/* global MutationObserver */\n\nimport { defaultDomFilter, applyChangesFromDom, reflectChangesOnDom } from './utils.js'\nimport { beforeTransactionSelectionFixer, afterTransactionSelectionFixer } from './selection.js'\n\nimport YArray from '../YArray.js'\nimport YXmlEvent from './YXmlEvent.js'\nimport { YXmlText, YXmlHook } from './y-xml'\nimport { logID } from '../../MessageHandler/messageToString.js'\nimport diff from '../../Util/simpleDiff.js'\n\nfunction domToYXml (parent, doms, _document) {\n const types = []\n doms.forEach(d => {\n if (d._yxml != null && d._yxml !== false) {\n d._yxml._unbindFromDom()\n }\n if (parent._domFilter(d.nodeName, new Map()) !== null) {\n let type\n const hookName = d._yjsHook || (d.dataset != null ? d.dataset.yjsHook : undefined)\n if (hookName !== undefined) {\n type = new YXmlHook(hookName, d)\n } else if (d.nodeType === d.TEXT_NODE) {\n type = new YXmlText(d)\n } else if (d.nodeType === d.ELEMENT_NODE) {\n type = new YXmlFragment._YXmlElement(d, parent._domFilter, _document)\n } else {\n throw new Error('Unsupported node!')\n }\n // type.enableSmartScrolling(parent._scrollElement)\n types.push(type)\n } else {\n d._yxml = false\n }\n })\n return types\n}\n\nclass YXmlTreeWalker {\n constructor (root, f) {\n this._filter = f || (() => true)\n this._root = root\n this._currentNode = root\n this._firstCall = true\n }\n [Symbol.iterator] () {\n return this\n }\n next () {\n let n = this._currentNode\n if (this._firstCall) {\n this._firstCall = false\n if (!n._deleted && this._filter(n)) {\n return { value: n, done: false }\n }\n }\n do {\n if (!n._deleted && (n.constructor === YXmlFragment._YXmlElement || n.constructor === YXmlFragment) && n._start !== null) {\n // walk down in the tree\n n = n._start\n } else {\n // walk right or up in the tree\n while (n !== this._root) {\n if (n._right !== null) {\n n = n._right\n break\n }\n n = n._parent\n }\n if (n === this._root) {\n n = null\n }\n }\n if (n === this._root) {\n break\n }\n } while (n !== null && (n._deleted || !this._filter(n)))\n this._currentNode = n\n if (n === null) {\n return { done: true }\n } else {\n return { value: n, done: false }\n }\n }\n}\n\nexport default class YXmlFragment extends YArray {\n constructor () {\n super()\n this._dom = null\n this._domFilter = defaultDomFilter\n this._domObserver = null\n // this function makes sure that either the\n // dom event is executed, or the yjs observer is executed\n var token = true\n this._mutualExclude = f => {\n if (token) {\n token = false\n try {\n f()\n } catch (e) {\n console.error(e)\n }\n /*\n if (this._domObserver !== null) {\n this._domObserver.takeRecords()\n }\n */\n token = true\n }\n }\n }\n createTreeWalker (filter) {\n return new YXmlTreeWalker(this, filter)\n }\n /**\n * Retrieve first element that matches *query*\n * Similar to DOM's querySelector, but only accepts a subset of its queries\n *\n * Query support:\n * - tagname\n * TODO:\n * - id\n * - attribute\n */\n querySelector (query) {\n query = query.toUpperCase()\n const iterator = new YXmlTreeWalker(this, element => element.nodeName === query)\n const next = iterator.next()\n if (next.done) {\n return null\n } else {\n return next.value\n }\n }\n querySelectorAll (query) {\n query = query.toUpperCase()\n return Array.from(new YXmlTreeWalker(this, element => element.nodeName === query))\n }\n enableSmartScrolling (scrollElement) {\n this._scrollElement = scrollElement\n this.forEach(xml => {\n xml.enableSmartScrolling(scrollElement)\n })\n }\n setDomFilter (f) {\n this._domFilter = f\n let attributes = new Map()\n if (this.getAttributes !== undefined) {\n let attrs = this.getAttributes()\n for (let key in attrs) {\n attributes.set(key, attrs[key])\n }\n }\n this._y.transact(() => {\n let result = this._domFilter(this.nodeName, new Map(attributes))\n if (result === null) {\n this._delete(this._y)\n } else {\n attributes.forEach((value, key) => {\n if (!result.has(key)) {\n this.removeAttribute(key)\n }\n })\n }\n this.forEach(xml => {\n xml.setDomFilter(f)\n })\n })\n }\n _callObserver (transaction, parentSubs, remote) {\n this._callEventHandler(transaction, new YXmlEvent(this, parentSubs, remote))\n }\n toString () {\n return this.map(xml => xml.toString()).join('')\n }\n _delete (y, createDelete) {\n this._unbindFromDom()\n super._delete(y, createDelete)\n }\n _unbindFromDom () {\n if (this._domObserver != null) {\n this._domObserver.disconnect()\n this._domObserver = null\n }\n if (this._dom != null) {\n this._dom._yxml = null\n this._dom = null\n }\n if (this._beforeTransactionHandler !== undefined) {\n this._y.off('beforeTransaction', this._beforeTransactionHandler)\n }\n }\n insertDomElementsAfter (prev, doms, _document) {\n const types = domToYXml(this, doms, _document)\n this.insertAfter(prev, types)\n return types\n }\n insertDomElements (pos, doms, _document) {\n const types = domToYXml(this, doms, _document)\n this.insert(pos, types)\n return types\n }\n getDom () {\n return this._dom\n }\n bindToDom (dom, _document) {\n if (this._dom != null) {\n this._unbindFromDom()\n }\n if (dom._yxml != null) {\n dom._yxml._unbindFromDom()\n }\n dom.innerHTML = ''\n this.forEach(t => {\n dom.insertBefore(t.getDom(_document), null)\n })\n this._bindToDom(dom, _document)\n }\n // binds to a dom element\n // Only call if dom and YXml are isomorph\n _bindToDom (dom, _document) {\n _document = _document || document\n this._dom = dom\n dom._yxml = this\n if (this._parent === null) {\n return\n }\n this._y.on('beforeTransaction', beforeTransactionSelectionFixer)\n this._y.on('afterTransaction', afterTransactionSelectionFixer)\n const applyFilter = (type) => {\n if (type._deleted) {\n return\n }\n // check if type is a child of this\n let isChild = false\n let p = type\n while (p !== this._y) {\n if (p === this) {\n isChild = true\n break\n }\n p = p._parent\n }\n if (!isChild) {\n return\n }\n // filter attributes\n let attributes = new Map()\n if (type.getAttributes !== undefined) {\n let attrs = type.getAttributes()\n for (let key in attrs) {\n attributes.set(key, attrs[key])\n }\n }\n let result = this._domFilter(type.nodeName, new Map(attributes))\n if (result === null) {\n type._delete(this._y)\n } else {\n attributes.forEach((value, key) => {\n if (!result.has(key)) {\n type.removeAttribute(key)\n }\n })\n }\n }\n this._y.on('beforeObserverCalls', function (y, transaction) {\n // apply dom filter to new and changed types\n transaction.changedTypes.forEach(function (subs, type) {\n if (subs.size > 1 || !subs.has(null)) {\n // only apply changes on attributes\n applyFilter(type)\n }\n })\n transaction.newTypes.forEach(applyFilter)\n })\n // Apply Y.Xml events to dom\n this.observeDeep(events => {\n reflectChangesOnDom.call(this, events, _document)\n })\n // Apply Dom changes on Y.Xml\n if (typeof MutationObserver !== 'undefined') {\n this._beforeTransactionHandler = () => {\n this._domObserverListener(this._domObserver.takeRecords())\n }\n this._y.on('beforeTransaction', this._beforeTransactionHandler)\n this._domObserverListener = mutations => {\n this._mutualExclude(() => {\n this._y.transact(() => {\n let diffChildren = new Set()\n mutations.forEach(mutation => {\n const dom = mutation.target\n const yxml = dom._yxml\n if (yxml == null || yxml.constructor === YXmlHook) {\n // dom element is filtered\n return\n }\n switch (mutation.type) {\n case 'characterData':\n var change = diff(yxml.toString(), dom.nodeValue)\n yxml.delete(change.pos, change.remove)\n yxml.insert(change.pos, change.insert)\n break\n case 'attributes':\n if (yxml.constructor === YXmlFragment) {\n break\n }\n let name = mutation.attributeName\n let val = dom.getAttribute(name)\n // check if filter accepts attribute\n let attributes = new Map()\n attributes.set(name, val)\n if (this._domFilter(dom.nodeName, attributes).size > 0 && yxml.constructor !== YXmlFragment) {\n if (yxml.getAttribute(name) !== val) {\n if (val == null) {\n yxml.removeAttribute(name)\n } else {\n yxml.setAttribute(name, val)\n }\n }\n }\n break\n case 'childList':\n diffChildren.add(mutation.target)\n break\n }\n })\n for (let dom of diffChildren) {\n if (dom.yOnChildrenChanged !== undefined) {\n dom.yOnChildrenChanged()\n }\n if (dom._yxml != null && dom._yxml !== false) {\n applyChangesFromDom(dom)\n }\n }\n })\n })\n }\n this._domObserver = new MutationObserver(this._domObserverListener)\n this._domObserver.observe(dom, {\n childList: true,\n attributes: true,\n characterData: true,\n subtree: true\n })\n }\n return dom\n }\n _logString () {\n const left = this._left !== null ? this._left._lastId : null\n const origin = this._origin !== null ? this._origin._lastId : null\n return `YXml(id:${logID(this._id)},left:${logID(left)},origin:${logID(origin)},right:${this._right},parent:${logID(this._parent)},parentSub:${this._parentSub})`\n }\n}\n","\nconst xmlHooks = {}\n\nexport function addHook (name, hook) {\n xmlHooks[name] = hook\n}\n\nexport function getHook (name) {\n const hook = xmlHooks[name]\n if (hook === undefined) {\n throw new Error(`The hook \"${name}\" is not specified! You must not access this hook!`)\n }\n return hook\n}\n","import YArray from '../Type/YArray.js'\nimport YMap from '../Type/YMap.js'\nimport YText from '../Type/YText.js'\nimport { YXmlFragment, YXmlElement, YXmlText, YXmlHook } from '../Type/y-xml/y-xml.js'\n\nimport Delete from '../Struct/Delete.js'\nimport ItemJSON from '../Struct/ItemJSON.js'\nimport ItemString from '../Struct/ItemString.js'\n\nconst structs = new Map()\nconst references = new Map()\n\nexport function addStruct (reference, structConstructor) {\n structs.set(reference, structConstructor)\n references.set(structConstructor, reference)\n}\n\nexport function getStruct (reference) {\n return structs.get(reference)\n}\n\nexport function getReference (typeConstructor) {\n return references.get(typeConstructor)\n}\n\naddStruct(0, ItemJSON)\naddStruct(1, ItemString)\naddStruct(2, Delete)\n\naddStruct(3, YArray)\naddStruct(4, YMap)\naddStruct(5, YText)\naddStruct(6, YXmlFragment)\naddStruct(7, YXmlElement)\naddStruct(8, YXmlText)\naddStruct(9, YXmlHook)\n","/* global crypto */\n\nexport function generateUserID () {\n if (typeof crypto !== 'undefined' && crypto.getRandomValue != null) {\n // browser\n let arr = new Uint32Array(1)\n crypto.getRandomValues(arr)\n return arr[0]\n } else if (typeof crypto !== 'undefined' && crypto.randomBytes != null) {\n // node\n let buf = crypto.randomBytes(4)\n return new Uint32Array(buf.buffer)[0]\n } else {\n return Math.ceil(Math.random() * 0xFFFFFFFF)\n }\n}\n","import ID from './ID.js'\n\nclass ReverseOperation {\n constructor (y, transaction) {\n this.created = new Date()\n const beforeState = transaction.beforeState\n if (beforeState.has(y.userID)) {\n this.toState = new ID(y.userID, y.ss.getState(y.userID) - 1)\n this.fromState = new ID(y.userID, beforeState.get(y.userID))\n } else {\n this.toState = null\n this.fromState = null\n }\n this.deletedStructs = transaction.deletedStructs\n }\n}\n\nfunction isStructInScope (y, struct, scope) {\n while (struct !== y) {\n if (struct === scope) {\n return true\n }\n struct = struct._parent\n }\n return false\n}\n\nfunction applyReverseOperation (y, scope, reverseBuffer) {\n let performedUndo = false\n y.transact(() => {\n while (!performedUndo && reverseBuffer.length > 0) {\n let undoOp = reverseBuffer.pop()\n // make sure that it is possible to iterate {from}-{to}\n if (undoOp.fromState !== null) {\n y.os.getItemCleanStart(undoOp.fromState)\n y.os.getItemCleanEnd(undoOp.toState)\n y.os.iterate(undoOp.fromState, undoOp.toState, op => {\n while (op._deleted && op._redone !== null) {\n op = op._redone\n }\n if (op._deleted === false && isStructInScope(y, op, scope)) {\n performedUndo = true\n op._delete(y)\n }\n })\n }\n for (let op of undoOp.deletedStructs) {\n if (\n isStructInScope(y, op, scope) &&\n op._parent !== y &&\n (\n op._id.user !== y.userID ||\n undoOp.fromState === null ||\n op._id.clock < undoOp.fromState.clock ||\n op._id.clock > undoOp.toState.clock\n )\n ) {\n performedUndo = true\n op._redo(y)\n }\n }\n }\n })\n return performedUndo\n}\n\nexport default class UndoManager {\n constructor (scope, options = {}) {\n this.options = options\n options.captureTimeout = options.captureTimeout == null ? 500 : options.captureTimeout\n this._undoBuffer = []\n this._redoBuffer = []\n this._scope = scope\n this._undoing = false\n this._redoing = false\n this._lastTransactionWasUndo = false\n const y = scope._y\n this.y = y\n y.on('afterTransaction', (y, transaction, remote) => {\n if (!remote && transaction.changedParentTypes.has(scope)) {\n let reverseOperation = new ReverseOperation(y, transaction)\n if (!this._undoing) {\n let lastUndoOp = this._undoBuffer.length > 0 ? this._undoBuffer[this._undoBuffer.length - 1] : null\n if (\n this._redoing === false &&\n this._lastTransactionWasUndo === false &&\n lastUndoOp !== null &&\n reverseOperation.created - lastUndoOp.created <= options.captureTimeout\n ) {\n lastUndoOp.created = reverseOperation.created\n if (reverseOperation.toState !== null) {\n lastUndoOp.toState = reverseOperation.toState\n if (lastUndoOp.fromState === null) {\n lastUndoOp.fromState = reverseOperation.fromState\n }\n }\n reverseOperation.deletedStructs.forEach(lastUndoOp.deletedStructs.add, lastUndoOp.deletedStructs)\n } else {\n this._lastTransactionWasUndo = false\n this._undoBuffer.push(reverseOperation)\n }\n if (!this._redoing) {\n this._redoBuffer = []\n }\n } else {\n this._lastTransactionWasUndo = true\n this._redoBuffer.push(reverseOperation)\n }\n }\n })\n }\n undo () {\n this._undoing = true\n const performedUndo = applyReverseOperation(this.y, this._scope, this._undoBuffer)\n this._undoing = false\n return performedUndo\n }\n redo () {\n this._redoing = true\n const performedRedo = applyReverseOperation(this.y, this._scope, this._redoBuffer)\n this._redoing = false\n return performedRedo\n }\n}\n","/**\n * Helpers.\n */\n\nvar s = 1000;\nvar m = s * 60;\nvar h = m * 60;\nvar d = h * 24;\nvar y = d * 365.25;\n\n/**\n * Parse or format the given `val`.\n *\n * Options:\n *\n * - `long` verbose formatting [false]\n *\n * @param {String|Number} val\n * @param {Object} [options]\n * @throws {Error} throw an error if val is not a non-empty string or a number\n * @return {String|Number}\n * @api public\n */\n\nmodule.exports = function(val, options) {\n options = options || {};\n var type = typeof val;\n if (type === 'string' && val.length > 0) {\n return parse(val);\n } else if (type === 'number' && isNaN(val) === false) {\n return options.long ? fmtLong(val) : fmtShort(val);\n }\n throw new Error(\n 'val is not a non-empty string or a valid number. val=' +\n JSON.stringify(val)\n );\n};\n\n/**\n * Parse the given `str` and return milliseconds.\n *\n * @param {String} str\n * @return {Number}\n * @api private\n */\n\nfunction parse(str) {\n str = String(str);\n if (str.length > 100) {\n return;\n }\n var match = /^((?:\\d+)?\\.?\\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(\n str\n );\n if (!match) {\n return;\n }\n var n = parseFloat(match[1]);\n var type = (match[2] || 'ms').toLowerCase();\n switch (type) {\n case 'years':\n case 'year':\n case 'yrs':\n case 'yr':\n case 'y':\n return n * y;\n case 'days':\n case 'day':\n case 'd':\n return n * d;\n case 'hours':\n case 'hour':\n case 'hrs':\n case 'hr':\n case 'h':\n return n * h;\n case 'minutes':\n case 'minute':\n case 'mins':\n case 'min':\n case 'm':\n return n * m;\n case 'seconds':\n case 'second':\n case 'secs':\n case 'sec':\n case 's':\n return n * s;\n case 'milliseconds':\n case 'millisecond':\n case 'msecs':\n case 'msec':\n case 'ms':\n return n;\n default:\n return undefined;\n }\n}\n\n/**\n * Short format for `ms`.\n *\n * @param {Number} ms\n * @return {String}\n * @api private\n */\n\nfunction fmtShort(ms) {\n if (ms >= d) {\n return Math.round(ms / d) + 'd';\n }\n if (ms >= h) {\n return Math.round(ms / h) + 'h';\n }\n if (ms >= m) {\n return Math.round(ms / m) + 'm';\n }\n if (ms >= s) {\n return Math.round(ms / s) + 's';\n }\n return ms + 'ms';\n}\n\n/**\n * Long format for `ms`.\n *\n * @param {Number} ms\n * @return {String}\n * @api private\n */\n\nfunction fmtLong(ms) {\n return plural(ms, d, 'day') ||\n plural(ms, h, 'hour') ||\n plural(ms, m, 'minute') ||\n plural(ms, s, 'second') ||\n ms + ' ms';\n}\n\n/**\n * Pluralization helper.\n */\n\nfunction plural(ms, n, name) {\n if (ms < n) {\n return;\n }\n if (ms < n * 1.5) {\n return Math.floor(ms / n) + ' ' + name;\n }\n return Math.ceil(ms / n) + ' ' + name + 's';\n}\n","import { writeStructs } from './syncStep1.js'\nimport { integrateRemoteStructs } from './integrateRemoteStructs.js'\nimport { readDeleteSet, writeDeleteSet } from './deleteSet.js'\nimport BinaryEncoder from '../Binary/Encoder.js'\n\nexport function fromBinary (y, decoder) {\n y.transact(function () {\n integrateRemoteStructs(y, decoder)\n readDeleteSet(y, decoder)\n })\n}\n\nexport function toBinary (y) {\n let encoder = new BinaryEncoder()\n writeStructs(y, encoder, new Map())\n writeDeleteSet(y, encoder)\n return encoder\n}\n","\nexport function createMutualExclude () {\n var token = true\n return function mutualExclude (f) {\n if (token) {\n token = false\n try {\n f()\n } catch (e) {\n console.error(e)\n }\n token = true\n }\n }\n}\n","import BinaryEncoder from './Binary/Encoder.js'\nimport BinaryDecoder from './Binary/Decoder.js'\nimport { toBinary, fromBinary } from './MessageHandler/binaryEncode.js'\nimport { integrateRemoteStructs } from './MessageHandler/integrateRemoteStructs.js'\nimport { createMutualExclude } from './Util/mutualExclude.js'\n\nfunction getFreshCnf () {\n let buffer = new BinaryEncoder()\n buffer.writeUint32(0)\n return {\n len: 0,\n buffer\n }\n}\n\nexport default class AbstractPersistence {\n constructor (opts) {\n this.opts = opts\n this.ys = new Map()\n }\n\n _init (y) {\n let cnf = this.ys.get(y)\n if (cnf === undefined) {\n cnf = getFreshCnf()\n cnf.mutualExclude = createMutualExclude()\n this.ys.set(y, cnf)\n return this.init(y).then(() => {\n y.on('afterTransaction', (y, transaction) => {\n let cnf = this.ys.get(y)\n if (cnf.len > 0) {\n cnf.buffer.setUint32(0, cnf.len)\n this.saveUpdate(y, cnf.buffer.createBuffer(), transaction)\n let _cnf = getFreshCnf()\n for (let key in _cnf) {\n cnf[key] = _cnf[key]\n }\n }\n })\n return this.retrieve(y)\n }).then(function () {\n return Promise.resolve(cnf)\n })\n } else {\n return Promise.resolve(cnf)\n }\n }\n deinit (y) {\n this.ys.delete(y)\n y.persistence = null\n }\n\n destroy () {\n this.ys = null\n }\n\n /**\n * Remove all persisted data that belongs to a room.\n * Automatically destroys all Yjs all Yjs instances that persist to\n * the room. If `destroyYjsInstances = false` the persistence functionality\n * will be removed from the Yjs instances.\n *\n * ** Must be overwritten! **\n */\n removePersistedData (room, destroyYjsInstances = true) {\n this.ys.forEach((cnf, y) => {\n if (y.room === room) {\n if (destroyYjsInstances) {\n y.destroy()\n } else {\n this.deinit(y)\n }\n }\n })\n }\n\n /* overwrite */\n saveUpdate (buffer) {\n }\n\n /**\n * Save struct to update buffer.\n * saveUpdate is called when transaction ends\n */\n saveStruct (y, struct) {\n let cnf = this.ys.get(y)\n if (cnf !== undefined) {\n cnf.mutualExclude(function () {\n struct._toBinary(cnf.buffer)\n cnf.len++\n })\n }\n }\n\n /* overwrite */\n retrieve (y, model, updates) {\n let cnf = this.ys.get(y)\n if (cnf !== undefined) {\n cnf.mutualExclude(function () {\n y.transact(function () {\n if (model != null) {\n fromBinary(y, new BinaryDecoder(new Uint8Array(model)))\n }\n if (updates != null) {\n for (let i = 0; i < updates.length; i++) {\n integrateRemoteStructs(y, new BinaryDecoder(new Uint8Array(updates[i])))\n }\n }\n })\n y.emit('persistenceReady')\n })\n }\n }\n\n /* overwrite */\n persist (y) {\n return toBinary(y).createBuffer()\n }\n}\n","\nimport Binding from './Binding.js'\nimport simpleDiff from '../Util/simpleDiff.js'\nimport { getRelativePosition, fromRelativePosition } from '../Util/relativePosition.js'\n\nfunction typeObserver () {\n this._mutualExclude(() => {\n const textarea = this.target\n const textType = this.type\n const relativeStart = getRelativePosition(textType, textarea.selectionStart)\n const relativeEnd = getRelativePosition(textType, textarea.selectionEnd)\n textarea.value = textType.toString()\n const start = fromRelativePosition(textType._y, relativeStart)\n const end = fromRelativePosition(textType._y, relativeEnd)\n textarea.setSelectionRange(start, end)\n })\n}\n\nfunction domObserver () {\n this._mutualExclude(() => {\n let diff = simpleDiff(this.type.toString(), this.target.value)\n this.type.delete(diff.pos, diff.remove)\n this.type.insert(diff.pos, diff.insert)\n })\n}\n\nexport default class TextareaBinding extends Binding {\n constructor (textType, domTextarea) {\n // Binding handles textType as this.type and domTextarea as this.target\n super(textType, domTextarea)\n // set initial value\n domTextarea.value = textType.toString()\n // Observers are handled by this class\n this._typeObserver = typeObserver.bind(this)\n this._domObserver = domObserver.bind(this)\n textType.observe(this._typeObserver)\n domTextarea.addEventListener('input', this._domObserver)\n }\n destroy () {\n // Remove everything that is handled by this class\n this.type.unobserve(this._typeObserver)\n this.target.unobserve(this._domObserver)\n super.destroy()\n }\n}\n","\nclass N {\n // A created node is always red!\n constructor (val) {\n this.val = val\n this.color = true\n this._left = null\n this._right = null\n this._parent = null\n }\n isRed () { return this.color }\n isBlack () { return !this.color }\n redden () { this.color = true; return this }\n blacken () { this.color = false; return this }\n get grandparent () {\n return this.parent.parent\n }\n get parent () {\n return this._parent\n }\n get sibling () {\n return (this === this.parent.left)\n ? this.parent.right : this.parent.left\n }\n get left () {\n return this._left\n }\n get right () {\n return this._right\n }\n set left (n) {\n if (n !== null) {\n n._parent = this\n }\n this._left = n\n }\n set right (n) {\n if (n !== null) {\n n._parent = this\n }\n this._right = n\n }\n rotateLeft (tree) {\n var parent = this.parent\n var newParent = this.right\n var newRight = this.right.left\n newParent.left = this\n this.right = newRight\n if (parent === null) {\n tree.root = newParent\n newParent._parent = null\n } else if (parent.left === this) {\n parent.left = newParent\n } else if (parent.right === this) {\n parent.right = newParent\n } else {\n throw new Error('The elements are wrongly connected!')\n }\n }\n next () {\n if (this.right !== null) {\n // search the most left node in the right tree\n var o = this.right\n while (o.left !== null) {\n o = o.left\n }\n return o\n } else {\n var p = this\n while (p.parent !== null && p !== p.parent.left) {\n p = p.parent\n }\n return p.parent\n }\n }\n prev () {\n if (this.left !== null) {\n // search the most right node in the left tree\n var o = this.left\n while (o.right !== null) {\n o = o.right\n }\n return o\n } else {\n var p = this\n while (p.parent !== null && p !== p.parent.right) {\n p = p.parent\n }\n return p.parent\n }\n }\n rotateRight (tree) {\n var parent = this.parent\n var newParent = this.left\n var newLeft = this.left.right\n newParent.right = this\n this.left = newLeft\n if (parent === null) {\n tree.root = newParent\n newParent._parent = null\n } else if (parent.left === this) {\n parent.left = newParent\n } else if (parent.right === this) {\n parent.right = newParent\n } else {\n throw new Error('The elements are wrongly connected!')\n }\n }\n getUncle () {\n // we can assume that grandparent exists when this is called!\n if (this.parent === this.parent.parent.left) {\n return this.parent.parent.right\n } else {\n return this.parent.parent.left\n }\n }\n}\n\n/*\n * This is a Red Black Tree implementation\n */\nexport default class Tree {\n constructor () {\n this.root = null\n this.length = 0\n }\n findNext (id) {\n var nextID = id.clone()\n nextID.clock += 1\n return this.findWithLowerBound(nextID)\n }\n findPrev (id) {\n let prevID = id.clone()\n prevID.clock -= 1\n return this.findWithUpperBound(prevID)\n }\n findNodeWithLowerBound (from) {\n var o = this.root\n if (o === null) {\n return null\n } else {\n while (true) {\n if (from === null || (from.lessThan(o.val._id) && o.left !== null)) {\n // o is included in the bound\n // try to find an element that is closer to the bound\n o = o.left\n } else if (from !== null && o.val._id.lessThan(from)) {\n // o is not within the bound, maybe one of the right elements is..\n if (o.right !== null) {\n o = o.right\n } else {\n // there is no right element. Search for the next bigger element,\n // this should be within the bounds\n return o.next()\n }\n } else {\n return o\n }\n }\n }\n }\n findNodeWithUpperBound (to) {\n if (to === void 0) {\n throw new Error('You must define from!')\n }\n var o = this.root\n if (o === null) {\n return null\n } else {\n while (true) {\n if ((to === null || o.val._id.lessThan(to)) && o.right !== null) {\n // o is included in the bound\n // try to find an element that is closer to the bound\n o = o.right\n } else if (to !== null && to.lessThan(o.val._id)) {\n // o is not within the bound, maybe one of the left elements is..\n if (o.left !== null) {\n o = o.left\n } else {\n // there is no left element. Search for the prev smaller element,\n // this should be within the bounds\n return o.prev()\n }\n } else {\n return o\n }\n }\n }\n }\n findSmallestNode () {\n var o = this.root\n while (o != null && o.left != null) {\n o = o.left\n }\n return o\n }\n findWithLowerBound (from) {\n var n = this.findNodeWithLowerBound(from)\n return n == null ? null : n.val\n }\n findWithUpperBound (to) {\n var n = this.findNodeWithUpperBound(to)\n return n == null ? null : n.val\n }\n iterate (from, to, f) {\n var o\n if (from === null) {\n o = this.findSmallestNode()\n } else {\n o = this.findNodeWithLowerBound(from)\n }\n while (\n o !== null &&\n (\n to === null || // eslint-disable-line no-unmodified-loop-condition\n o.val._id.lessThan(to) ||\n o.val._id.equals(to)\n )\n ) {\n f(o.val)\n o = o.next()\n }\n }\n find (id) {\n let n = this.findNode(id)\n if (n !== null) {\n return n.val\n } else {\n return null\n }\n }\n findNode (id) {\n var o = this.root\n if (o === null) {\n return null\n } else {\n while (true) {\n if (o === null) {\n return null\n }\n if (id.lessThan(o.val._id)) {\n o = o.left\n } else if (o.val._id.lessThan(id)) {\n o = o.right\n } else {\n return o\n }\n }\n }\n }\n delete (id) {\n var d = this.findNode(id)\n if (d == null) {\n // throw new Error('Element does not exist!')\n return\n }\n this.length--\n if (d.left !== null && d.right !== null) {\n // switch d with the greates element in the left subtree.\n // o should have at most one child.\n var o = d.left\n // find\n while (o.right !== null) {\n o = o.right\n }\n // switch\n d.val = o.val\n d = o\n }\n // d has at most one child\n // let n be the node that replaces d\n var isFakeChild\n var child = d.left || d.right\n if (child === null) {\n isFakeChild = true\n child = new N(null)\n child.blacken()\n d.right = child\n } else {\n isFakeChild = false\n }\n\n if (d.parent === null) {\n if (!isFakeChild) {\n this.root = child\n child.blacken()\n child._parent = null\n } else {\n this.root = null\n }\n return\n } else if (d.parent.left === d) {\n d.parent.left = child\n } else if (d.parent.right === d) {\n d.parent.right = child\n } else {\n throw new Error('Impossible!')\n }\n if (d.isBlack()) {\n if (child.isRed()) {\n child.blacken()\n } else {\n this._fixDelete(child)\n }\n }\n this.root.blacken()\n if (isFakeChild) {\n if (child.parent.left === child) {\n child.parent.left = null\n } else if (child.parent.right === child) {\n child.parent.right = null\n } else {\n throw new Error('Impossible #3')\n }\n }\n }\n _fixDelete (n) {\n function isBlack (node) {\n return node !== null ? node.isBlack() : true\n }\n function isRed (node) {\n return node !== null ? node.isRed() : false\n }\n if (n.parent === null) {\n // this can only be called after the first iteration of fixDelete.\n return\n }\n // d was already replaced by the child\n // d is not the root\n // d and child are black\n var sibling = n.sibling\n if (isRed(sibling)) {\n // make sibling the grandfather\n n.parent.redden()\n sibling.blacken()\n if (n === n.parent.left) {\n n.parent.rotateLeft(this)\n } else if (n === n.parent.right) {\n n.parent.rotateRight(this)\n } else {\n throw new Error('Impossible #2')\n }\n sibling = n.sibling\n }\n // parent, sibling, and children of n are black\n if (n.parent.isBlack() &&\n sibling.isBlack() &&\n isBlack(sibling.left) &&\n isBlack(sibling.right)\n ) {\n sibling.redden()\n this._fixDelete(n.parent)\n } else if (n.parent.isRed() &&\n sibling.isBlack() &&\n isBlack(sibling.left) &&\n isBlack(sibling.right)\n ) {\n sibling.redden()\n n.parent.blacken()\n } else {\n if (n === n.parent.left &&\n sibling.isBlack() &&\n isRed(sibling.left) &&\n isBlack(sibling.right)\n ) {\n sibling.redden()\n sibling.left.blacken()\n sibling.rotateRight(this)\n sibling = n.sibling\n } else if (n === n.parent.right &&\n sibling.isBlack() &&\n isRed(sibling.right) &&\n isBlack(sibling.left)\n ) {\n sibling.redden()\n sibling.right.blacken()\n sibling.rotateLeft(this)\n sibling = n.sibling\n }\n sibling.color = n.parent.color\n n.parent.blacken()\n if (n === n.parent.left) {\n sibling.right.blacken()\n n.parent.rotateLeft(this)\n } else {\n sibling.left.blacken()\n n.parent.rotateRight(this)\n }\n }\n }\n put (v) {\n var node = new N(v)\n if (this.root !== null) {\n var p = this.root // p abbrev. parent\n while (true) {\n if (node.val._id.lessThan(p.val._id)) {\n if (p.left === null) {\n p.left = node\n break\n } else {\n p = p.left\n }\n } else if (p.val._id.lessThan(node.val._id)) {\n if (p.right === null) {\n p.right = node\n break\n } else {\n p = p.right\n }\n } else {\n p.val = node.val\n return p\n }\n }\n this._fixInsert(node)\n } else {\n this.root = node\n }\n this.length++\n this.root.blacken()\n return node\n }\n _fixInsert (n) {\n if (n.parent === null) {\n n.blacken()\n return\n } else if (n.parent.isBlack()) {\n return\n }\n var uncle = n.getUncle()\n if (uncle !== null && uncle.isRed()) {\n // Note: parent: red, uncle: red\n n.parent.blacken()\n uncle.blacken()\n n.grandparent.redden()\n this._fixInsert(n.grandparent)\n } else {\n // Note: parent: red, uncle: black or null\n // Now we transform the tree in such a way that\n // either of these holds:\n // 1) grandparent.left.isRed\n // and grandparent.left.left.isRed\n // 2) grandparent.right.isRed\n // and grandparent.right.right.isRed\n if (n === n.parent.right && n.parent === n.grandparent.left) {\n n.parent.rotateLeft(this)\n // Since we rotated and want to use the previous\n // cases, we need to set n in such a way that\n // n.parent.isRed again\n n = n.left\n } else if (n === n.parent.left && n.parent === n.grandparent.right) {\n n.parent.rotateRight(this)\n // see above\n n = n.right\n }\n // Case 1) or 2) hold from here on.\n // Now traverse grandparent, make parent a black node\n // on the highest level which holds two red nodes.\n n.parent.blacken()\n n.grandparent.redden()\n if (n === n.parent.left) {\n // Case 1\n n.grandparent.rotateRight(this)\n } else {\n // Case 2\n n.grandparent.rotateLeft(this)\n }\n }\n }\n flush () {}\n}\n","\nexport default class ID {\n constructor (user, clock) {\n this.user = user\n this.clock = clock\n }\n clone () {\n return new ID(this.user, this.clock)\n }\n equals (id) {\n return id !== null && id.user === this.user && id.clock === this.clock\n }\n lessThan (id) {\n if (id.constructor === ID) {\n return this.user < id.user || (this.user === id.user && this.clock < id.clock)\n } else {\n return false\n }\n }\n}\n","import Tree from '../Util/Tree.js'\nimport ID from '../Util/ID.js'\n\nclass DSNode {\n constructor (id, len, gc) {\n this._id = id\n this.len = len\n this.gc = gc\n }\n clone () {\n return new DSNode(this._id, this.len, this.gc)\n }\n}\n\nexport default class DeleteStore extends Tree {\n logTable () {\n const deletes = []\n this.iterate(null, null, function (n) {\n deletes.push({\n user: n._id.user,\n clock: n._id.clock,\n len: n.len,\n gc: n.gc\n })\n })\n console.table(deletes)\n }\n isDeleted (id) {\n var n = this.findWithUpperBound(id)\n return n !== null && n._id.user === id.user && id.clock < n._id.clock + n.len\n }\n /*\n * Mark an operation as deleted. returns the deleted node\n */\n markDeleted (id, length) {\n if (length == null) {\n throw new Error('length must be defined')\n }\n var n = this.findWithUpperBound(id)\n if (n != null && n._id.user === id.user) {\n if (n._id.clock <= id.clock && id.clock <= n._id.clock + n.len) {\n // id is in n's range\n var diff = id.clock + length - (n._id.clock + n.len) // overlapping right\n if (diff > 0) {\n // id+length overlaps n\n if (!n.gc) {\n n.len += diff\n } else {\n diff = n._id.clock + n.len - id.clock // overlapping left (id till n.end)\n if (diff < length) {\n // a partial deletion\n let nId = id.clone()\n nId.clock += diff\n n = new DSNode(nId, length - diff, false)\n this.put(n)\n } else {\n // already gc'd\n throw new Error(\n 'DS reached an inconsistent state. Please report this issue!'\n )\n }\n }\n } else {\n // no overlapping, already deleted\n return n\n }\n } else {\n // cannot extend left (there is no left!)\n n = new DSNode(id, length, false)\n this.put(n) // TODO: you double-put !!\n }\n } else {\n // cannot extend left\n n = new DSNode(id, length, false)\n this.put(n)\n }\n // can extend right?\n var next = this.findNext(n._id)\n if (\n next != null &&\n n._id.user === next._id.user &&\n n._id.clock + n.len >= next._id.clock\n ) {\n diff = n._id.clock + n.len - next._id.clock // from next.start to n.end\n while (diff >= 0) {\n // n overlaps with next\n if (next.gc) {\n // gc is stronger, so reduce length of n\n n.len -= diff\n if (diff >= next.len) {\n // delete the missing range after next\n diff = diff - next.len // missing range after next\n if (diff > 0) {\n this.put(n) // unneccessary? TODO!\n this.markDeleted(new ID(next._id.user, next._id.clock + next.len), diff)\n }\n }\n break\n } else {\n // we can extend n with next\n if (diff > next.len) {\n // n is even longer than next\n // get next.next, and try to extend it\n var _next = this.findNext(next._id)\n this.delete(next._id)\n if (_next == null || n._id.user !== _next._id.user) {\n break\n } else {\n next = _next\n diff = n._id.clock + n.len - next._id.clock // from next.start to n.end\n // continue!\n }\n } else {\n // n just partially overlaps with next. extend n, delete next, and break this loop\n n.len += next.len - diff\n this.delete(next._id)\n break\n }\n }\n }\n }\n this.put(n)\n return n\n }\n}\n","import ID from '../Util/ID.js'\nimport { default as RootID, RootFakeUserID } from '../Util/RootID.js'\n\nexport default class BinaryDecoder {\n constructor (buffer) {\n if (buffer instanceof ArrayBuffer) {\n this.uint8arr = new Uint8Array(buffer)\n } else if (buffer instanceof Uint8Array || (typeof Buffer !== 'undefined' && buffer instanceof Buffer)) {\n this.uint8arr = buffer\n } else {\n throw new Error('Expected an ArrayBuffer or Uint8Array!')\n }\n this.pos = 0\n }\n /**\n * Clone this decoder instance\n * Optionally set a new position parameter\n */\n clone (newPos = this.pos) {\n let decoder = new BinaryDecoder(this.uint8arr)\n decoder.pos = newPos\n return decoder\n }\n /**\n * Number of bytes\n */\n get length () {\n return this.uint8arr.length\n }\n /**\n * Skip one byte, jump to the next position\n */\n skip8 () {\n this.pos++\n }\n /**\n * Read one byte as unsigned integer\n */\n readUint8 () {\n return this.uint8arr[this.pos++]\n }\n /**\n * Read 4 bytes as unsigned integer\n */\n readUint32 () {\n let uint =\n this.uint8arr[this.pos] +\n (this.uint8arr[this.pos + 1] << 8) +\n (this.uint8arr[this.pos + 2] << 16) +\n (this.uint8arr[this.pos + 3] << 24)\n this.pos += 4\n return uint\n }\n /**\n * Look ahead without incrementing position\n * to the next byte and read it as unsigned integer\n */\n peekUint8 () {\n return this.uint8arr[this.pos]\n }\n /**\n * Read unsigned integer (32bit) with variable length\n * 1/8th of the storage is used as encoding overhead\n * - numbers < 2^7 is stored in one byte\n * - numbers < 2^14 is stored in two bytes\n * ..\n */\n readVarUint () {\n let num = 0\n let len = 0\n while (true) {\n let r = this.uint8arr[this.pos++]\n num = num | ((r & 0b1111111) << len)\n len += 7\n if (r < 1 << 7) {\n return num >>> 0 // return unsigned number!\n }\n if (len > 35) {\n throw new Error('Integer out of range!')\n }\n }\n }\n /**\n * Read string of variable length\n * - varUint is used to store the length of the string\n */\n readVarString () {\n let len = this.readVarUint()\n let bytes = new Array(len)\n for (let i = 0; i < len; i++) {\n bytes[i] = this.uint8arr[this.pos++]\n }\n let encodedString = String.fromCodePoint(...bytes)\n return decodeURIComponent(escape(encodedString))\n }\n /**\n * Look ahead and read varString without incrementing position\n */\n peekVarString () {\n let pos = this.pos\n let s = this.readVarString()\n this.pos = pos\n return s\n }\n /**\n * Read ID\n * - If first varUint read is 0xFFFFFF a RootID is returned\n * - Otherwise an ID is returned\n */\n readID () {\n let user = this.readVarUint()\n if (user === RootFakeUserID) {\n // read property name and type id\n const rid = new RootID(this.readVarString(), null)\n rid.type = this.readVarUint()\n return rid\n }\n return new ID(user, this.readVarUint())\n }\n}\n","import { RootFakeUserID } from '../Util/RootID.js'\n\nconst bits7 = 0b1111111\nconst bits8 = 0b11111111\n\nexport default class BinaryEncoder {\n constructor () {\n // TODO: implement chained Uint8Array buffers instead of Array buffer\n this.data = []\n }\n\n get length () {\n return this.data.length\n }\n\n get pos () {\n return this.data.length\n }\n\n createBuffer () {\n return Uint8Array.from(this.data).buffer\n }\n\n writeUint8 (num) {\n this.data.push(num & bits8)\n }\n\n setUint8 (pos, num) {\n this.data[pos] = num & bits8\n }\n\n writeUint16 (num) {\n this.data.push(num & bits8, (num >>> 8) & bits8)\n }\n\n setUint16 (pos, num) {\n this.data[pos] = num & bits8\n this.data[pos + 1] = (num >>> 8) & bits8\n }\n\n writeUint32 (num) {\n for (let i = 0; i < 4; i++) {\n this.data.push(num & bits8)\n num >>>= 8\n }\n }\n\n setUint32 (pos, num) {\n for (let i = 0; i < 4; i++) {\n this.data[pos + i] = num & bits8\n num >>>= 8\n }\n }\n\n writeVarUint (num) {\n while (num >= 0b10000000) {\n this.data.push(0b10000000 | (bits7 & num))\n num >>>= 7\n }\n this.data.push(bits7 & num)\n }\n\n writeVarString (str) {\n let encodedString = unescape(encodeURIComponent(str))\n let bytes = encodedString.split('').map(c => c.codePointAt())\n let len = bytes.length\n this.writeVarUint(len)\n for (let i = 0; i < len; i++) {\n this.data.push(bytes[i])\n }\n }\n\n writeID (id) {\n const user = id.user\n this.writeVarUint(user)\n if (user !== RootFakeUserID) {\n this.writeVarUint(id.clock)\n } else {\n this.writeVarString(id.name)\n this.writeVarUint(id.type)\n }\n }\n}\n","\nexport default class EventHandler {\n constructor () {\n this.eventListeners = []\n }\n destroy () {\n this.eventListeners = null\n }\n addEventListener (f) {\n this.eventListeners.push(f)\n }\n removeEventListener (f) {\n this.eventListeners = this.eventListeners.filter(function (g) {\n return f !== g\n })\n }\n removeAllEventListeners () {\n this.eventListeners = []\n }\n callEventListeners (transaction, event) {\n for (var i = 0; i < this.eventListeners.length; i++) {\n try {\n const f = this.eventListeners[i]\n f(event)\n } catch (e) {\n /*\n Your observer threw an error. This error was caught so that Yjs\n can ensure data consistency! In order to debug this error you\n have to check \"Pause On Caught Exceptions\" in developer tools.\n */\n console.error(e)\n }\n }\n }\n}\n","import { splitHelper, default as Item } from './Item.js'\nimport { logID } from '../MessageHandler/messageToString.js'\n\nexport default class ItemJSON extends Item {\n constructor () {\n super()\n this._content = null\n }\n _copy () {\n let struct = super._copy()\n struct._content = this._content\n return struct\n }\n get _length () {\n return this._content.length\n }\n _fromBinary (y, decoder) {\n let missing = super._fromBinary(y, decoder)\n let len = decoder.readVarUint()\n this._content = new Array(len)\n for (let i = 0; i < len; i++) {\n const ctnt = decoder.readVarString()\n let parsed\n if (ctnt === 'undefined') {\n parsed = undefined\n } else {\n parsed = JSON.parse(ctnt)\n }\n this._content[i] = parsed\n }\n return missing\n }\n _toBinary (encoder) {\n super._toBinary(encoder)\n let len = this._content.length\n encoder.writeVarUint(len)\n for (let i = 0; i < len; i++) {\n let encoded\n let content = this._content[i]\n if (content === undefined) {\n encoded = 'undefined'\n } else {\n encoded = JSON.stringify(content)\n }\n encoder.writeVarString(encoded)\n }\n }\n _logString () {\n const left = this._left !== null ? this._left._lastId : null\n const origin = this._origin !== null ? this._origin._lastId : null\n return `ItemJSON(id:${logID(this._id)},content:${JSON.stringify(this._content)},left:${logID(left)},origin:${logID(origin)},right:${logID(this._right)},parent:${logID(this._parent)},parentSub:${this._parentSub})`\n }\n _splitAt (y, diff) {\n if (diff === 0) {\n return this\n } else if (diff >= this._length) {\n return this._right\n }\n let item = new ItemJSON()\n item._content = this._content.splice(diff)\n splitHelper(y, this, item, diff)\n return item\n }\n}\n","import { splitHelper, default as Item } from './Item.js'\nimport { logID } from '../MessageHandler/messageToString.js'\n\nexport default class ItemString extends Item {\n constructor () {\n super()\n this._content = null\n }\n _copy () {\n let struct = super._copy()\n struct._content = this._content\n return struct\n }\n get _length () {\n return this._content.length\n }\n _fromBinary (y, decoder) {\n let missing = super._fromBinary(y, decoder)\n this._content = decoder.readVarString()\n return missing\n }\n _toBinary (encoder) {\n super._toBinary(encoder)\n encoder.writeVarString(this._content)\n }\n _logString () {\n const left = this._left !== null ? this._left._lastId : null\n const origin = this._origin !== null ? this._origin._lastId : null\n return `ItemJSON(id:${logID(this._id)},content:${JSON.stringify(this._content)},left:${logID(left)},origin:${logID(origin)},right:${logID(this._right)},parent:${logID(this._parent)},parentSub:${this._parentSub})`\n }\n _splitAt (y, diff) {\n if (diff === 0) {\n return this\n } else if (diff >= this._length) {\n return this._right\n }\n let item = new ItemString()\n item._content = this._content.slice(diff)\n this._content = this._content.slice(0, diff)\n splitHelper(y, this, item, diff)\n return item\n }\n}\n","\nexport default class YEvent {\n constructor (target) {\n this.target = target\n this.currentTarget = target\n }\n get path () {\n const path = []\n let type = this.target\n const y = type._y\n while (type !== this.currentTarget && type !== y) {\n let parent = type._parent\n if (type._parentSub !== null) {\n path.unshift(type._parentSub)\n } else {\n // parent is array-ish\n for (let [i, child] of parent) {\n if (child === type) {\n path.unshift(i)\n break\n }\n }\n }\n type = parent\n }\n return path\n }\n}\n","import Type from '../Struct/Type.js'\nimport ItemJSON from '../Struct/ItemJSON.js'\nimport ItemString from '../Struct/ItemString.js'\nimport { logID } from '../MessageHandler/messageToString.js'\nimport YEvent from '../Util/YEvent.js'\n\nclass YArrayEvent extends YEvent {\n constructor (yarray, remote, transaction) {\n super(yarray)\n this.remote = remote\n this._transaction = transaction\n this._addedElements = null\n }\n get addedElements () {\n if (this._addedElements === null) {\n const target = this.target\n const transaction = this._transaction\n const addedElements = new Set()\n transaction.newTypes.forEach(function (type) {\n if (type._parent === target && !transaction.deletedStructs.has(type)) {\n addedElements.add(type)\n }\n })\n this._addedElements = addedElements\n }\n return this._addedElements\n }\n get removedElements () {\n const target = this.target\n const transaction = this._transaction\n const removedElements = new Set()\n transaction.deletedStructs.forEach(function (struct) {\n if (struct._parent === target && !transaction.newTypes.has(struct)) {\n removedElements.add(struct)\n }\n })\n return removedElements\n }\n}\n\nexport default class YArray extends Type {\n _callObserver (transaction, parentSubs, remote) {\n this._callEventHandler(transaction, new YArrayEvent(this, remote, transaction))\n }\n get (pos) {\n let n = this._start\n while (n !== null) {\n if (!n._deleted) {\n if (pos < n._length) {\n if (n.constructor === ItemJSON || n.constructor === ItemString) {\n return n._content[pos]\n } else {\n return n\n }\n }\n pos -= n._length\n }\n n = n._right\n }\n }\n toArray () {\n return this.map(c => c)\n }\n toJSON () {\n return this.map(c => {\n if (c instanceof Type) {\n if (c.toJSON !== null) {\n return c.toJSON()\n } else {\n return c.toString()\n }\n }\n return c\n })\n }\n map (f) {\n const res = []\n this.forEach((c, i) => {\n res.push(f(c, i, this))\n })\n return res\n }\n forEach (f) {\n let pos = 0\n let n = this._start\n while (n !== null) {\n if (!n._deleted) {\n if (n instanceof Type) {\n f(n, pos++, this)\n } else {\n const content = n._content\n const contentLen = content.length\n for (let i = 0; i < contentLen; i++) {\n pos++\n f(content[i], pos, this)\n }\n }\n }\n n = n._right\n }\n }\n get length () {\n let length = 0\n let n = this._start\n while (n !== null) {\n if (!n._deleted) {\n length += n._length\n }\n n = n._right\n }\n return length\n }\n [Symbol.iterator] () {\n return {\n next: function () {\n while (this._item !== null && (this._item._deleted || this._item._length <= this._itemElement)) {\n // item is deleted or itemElement does not exist (is deleted)\n this._item = this._item._right\n this._itemElement = 0\n }\n if (this._item === null) {\n return {\n done: true\n }\n }\n let content\n if (this._item instanceof Type) {\n content = this._item\n } else {\n content = this._item._content[this._itemElement++]\n }\n return {\n value: [this._count, content],\n done: false\n }\n },\n _item: this._start,\n _itemElement: 0,\n _count: 0\n }\n }\n delete (pos, length = 1) {\n this._y.transact(() => {\n let item = this._start\n let count = 0\n while (item !== null && length > 0) {\n if (!item._deleted) {\n if (count <= pos && pos < count + item._length) {\n const diffDel = pos - count\n item = item._splitAt(this._y, diffDel)\n item._splitAt(this._y, length)\n length -= item._length\n item._delete(this._y)\n count += diffDel\n } else {\n count += item._length\n }\n }\n item = item._right\n }\n })\n if (length > 0) {\n throw new Error('Delete exceeds the range of the YArray')\n }\n }\n insertAfter (left, content) {\n this._transact(y => {\n let right\n if (left === null) {\n right = this._start\n } else {\n right = left._right\n }\n let prevJsonIns = null\n for (let i = 0; i < content.length; i++) {\n let c = content[i]\n if (typeof c === 'function') {\n c = new c() // eslint-disable-line new-cap\n }\n if (c instanceof Type) {\n if (prevJsonIns !== null) {\n if (y !== null) {\n prevJsonIns._integrate(y)\n }\n left = prevJsonIns\n prevJsonIns = null\n }\n c._origin = left\n c._left = left\n c._right = right\n c._right_origin = right\n c._parent = this\n if (y !== null) {\n c._integrate(y)\n } else if (left === null) {\n this._start = c\n } else {\n left._right = c\n }\n left = c\n } else {\n if (prevJsonIns === null) {\n prevJsonIns = new ItemJSON()\n prevJsonIns._origin = left\n prevJsonIns._left = left\n prevJsonIns._right = right\n prevJsonIns._right_origin = right\n prevJsonIns._parent = this\n prevJsonIns._content = []\n }\n prevJsonIns._content.push(c)\n }\n }\n if (prevJsonIns !== null) {\n if (y !== null) {\n prevJsonIns._integrate(y)\n } else if (prevJsonIns._left === null) {\n this._start = prevJsonIns\n }\n }\n })\n }\n insert (pos, content) {\n let left = null\n let right = this._start\n let count = 0\n const y = this._y\n while (right !== null) {\n const rightLen = right._deleted ? 0 : (right._length - 1)\n if (count <= pos && pos <= count + rightLen) {\n const splitDiff = pos - count\n right = right._splitAt(y, splitDiff)\n left = right._left\n count += splitDiff\n break\n }\n if (!right._deleted) {\n count += right._length\n }\n left = right\n right = right._right\n }\n if (pos > count) {\n throw new Error('Position exceeds array range!')\n }\n this.insertAfter(left, content)\n }\n push (content) {\n let n = this._start\n let lastUndeleted = null\n while (n !== null) {\n if (!n._deleted) {\n lastUndeleted = n\n }\n n = n._right\n }\n this.insertAfter(lastUndeleted, content)\n }\n _logString () {\n const left = this._left !== null ? this._left._lastId : null\n const origin = this._origin !== null ? this._origin._lastId : null\n return `YArray(id:${logID(this._id)},start:${logID(this._start)},left:${logID(left)},origin:${logID(origin)},right:${logID(this._right)},parent:${logID(this._parent)},parentSub:${this._parentSub})`\n }\n}\n","import Type from '../Struct/Type.js'\nimport Item from '../Struct/Item.js'\nimport ItemJSON from '../Struct/ItemJSON.js'\nimport { logID } from '../MessageHandler/messageToString.js'\nimport YEvent from '../Util/YEvent.js'\n\nclass YMapEvent extends YEvent {\n constructor (ymap, subs, remote) {\n super(ymap)\n this.keysChanged = subs\n this.remote = remote\n }\n}\n\nexport default class YMap extends Type {\n _callObserver (transaction, parentSubs, remote) {\n this._callEventHandler(transaction, new YMapEvent(this, parentSubs, remote))\n }\n toJSON () {\n const map = {}\n for (let [key, item] of this._map) {\n if (!item._deleted) {\n let res\n if (item instanceof Type) {\n if (item.toJSON !== undefined) {\n res = item.toJSON()\n } else {\n res = item.toString()\n }\n } else {\n res = item._content[0]\n }\n map[key] = res\n }\n }\n return map\n }\n keys () {\n let keys = []\n for (let [key, value] of this._map) {\n if (!value._deleted) {\n keys.push(key)\n }\n }\n return keys\n }\n delete (key) {\n this._transact((y) => {\n let c = this._map.get(key)\n if (y !== null && c !== undefined) {\n c._delete(y)\n }\n })\n }\n set (key, value) {\n this._transact(y => {\n const old = this._map.get(key) || null\n if (old !== null) {\n if (old.constructor === ItemJSON && !old._deleted && old._content[0] === value) {\n // Trying to overwrite with same value\n // break here\n return value\n }\n if (y !== null) {\n old._delete(y)\n }\n }\n let v\n if (typeof value === 'function') {\n v = new value() // eslint-disable-line new-cap\n value = v\n } else if (value instanceof Item) {\n v = value\n } else {\n v = new ItemJSON()\n v._content = [value]\n }\n v._right = old\n v._right_origin = old\n v._parent = this\n v._parentSub = key\n if (y !== null) {\n v._integrate(y)\n } else {\n this._map.set(key, v)\n }\n })\n return value\n }\n get (key) {\n let v = this._map.get(key)\n if (v === undefined || v._deleted) {\n return undefined\n }\n if (v instanceof Type) {\n return v\n } else {\n return v._content[v._content.length - 1]\n }\n }\n has (key) {\n let v = this._map.get(key)\n if (v === undefined || v._deleted) {\n return false\n } else {\n return true\n }\n }\n _logString () {\n const left = this._left !== null ? this._left._lastId : null\n const origin = this._origin !== null ? this._origin._lastId : null\n return `YMap(id:${logID(this._id)},mapSize:${this._map.size},left:${logID(left)},origin:${logID(origin)},right:${logID(this._right)},parent:${logID(this._parent)},parentSub:${this._parentSub})`\n }\n}\n","import ItemString from '../Struct/ItemString.js'\nimport YArray from './YArray.js'\nimport { logID } from '../MessageHandler/messageToString.js'\n\nexport default class YText extends YArray {\n constructor (string) {\n super()\n if (typeof string === 'string') {\n const start = new ItemString()\n start._parent = this\n start._content = string\n this._start = start\n }\n }\n toString () {\n const strBuilder = []\n let n = this._start\n while (n !== null) {\n if (!n._deleted) {\n strBuilder.push(n._content)\n }\n n = n._right\n }\n return strBuilder.join('')\n }\n insert (pos, text) {\n if (text.length <= 0) {\n return\n }\n this._transact(y => {\n let left = null\n let right = this._start\n let count = 0\n while (right !== null) {\n const rightLen = right._deleted ? 0 : (right._length - 1)\n if (count <= pos && pos <= count + rightLen) {\n const splitDiff = pos - count\n right = right._splitAt(this._y, splitDiff)\n left = right._left\n count += splitDiff\n break\n }\n if (!right._deleted) {\n count += right._length\n }\n left = right\n right = right._right\n }\n if (pos > count) {\n throw new Error('Position exceeds array range!')\n }\n let item = new ItemString()\n item._origin = left\n item._left = left\n item._right = right\n item._right_origin = right\n item._parent = this\n item._content = text\n if (y !== null) {\n item._integrate(this._y)\n } else if (left === null) {\n this._start = item\n } else {\n left._right = item\n }\n })\n }\n _logString () {\n const left = this._left !== null ? this._left._lastId : null\n const origin = this._origin !== null ? this._origin._lastId : null\n return `YText(id:${logID(this._id)},start:${logID(this._start)},left:${logID(left)},origin:${logID(origin)},right:${logID(this._right)},parent:${logID(this._parent)},parentSub:${this._parentSub})`\n }\n}\n","import YEvent from '../../Util/YEvent.js'\n\nexport default class YXmlEvent extends YEvent {\n constructor (target, subs, remote) {\n super(target)\n this.childListChanged = false\n this.attributesChanged = new Set()\n this.remote = remote\n subs.forEach((sub) => {\n if (sub === null) {\n this.childListChanged = true\n } else {\n this.attributesChanged.add(sub)\n }\n })\n }\n}\n","import { defaultDomFilter } from './utils.js'\n\nimport YMap from '../YMap.js'\nimport { YXmlFragment } from './y-xml.js'\n\nexport default class YXmlElement extends YXmlFragment {\n constructor (arg1, arg2, _document) {\n super()\n this.nodeName = null\n this._scrollElement = null\n if (typeof arg2 === 'function') {\n this._domFilter = arg2\n }\n if (typeof arg1 === 'string') {\n this.nodeName = arg1.toUpperCase()\n } else if (arg1 != null && arg1.nodeType != null && arg1.nodeType === arg1.ELEMENT_NODE) {\n this.nodeName = arg1.nodeName\n this._setDom(arg1, _document)\n } else {\n this.nodeName = 'UNDEFINED'\n }\n }\n _copy () {\n let struct = super._copy()\n struct.nodeName = this.nodeName\n return struct\n }\n _setDom (dom, _document) {\n if (this._dom != null) {\n throw new Error('Only call this method if you know what you are doing ;)')\n } else if (dom._yxml != null) { // TODO do i need to check this? - no.. but for dev purps..\n throw new Error('Already bound to an YXml type')\n } else {\n // tag is already set in constructor\n // set attributes\n let attributes = new Map()\n for (let i = 0; i < dom.attributes.length; i++) {\n let attr = dom.attributes[i]\n // get attribute via getAttribute for custom element support (some write something different in attr.value)\n attributes.set(attr.name, dom.getAttribute(attr.name))\n }\n attributes = this._domFilter(dom.nodeName, attributes)\n attributes.forEach((value, name) => {\n this.setAttribute(name, value)\n })\n this.insertDomElements(0, Array.prototype.slice.call(dom.childNodes), _document)\n this._bindToDom(dom, _document)\n return dom\n }\n }\n _bindToDom (dom, _document) {\n _document = _document || document\n this._dom = dom\n dom._yxml = this\n }\n _fromBinary (y, decoder) {\n const missing = super._fromBinary(y, decoder)\n this.nodeName = decoder.readVarString()\n return missing\n }\n _toBinary (encoder) {\n super._toBinary(encoder)\n encoder.writeVarString(this.nodeName)\n }\n _integrate (y) {\n if (this.nodeName === null) {\n throw new Error('nodeName must be defined!')\n }\n if (this._domFilter === defaultDomFilter && this._parent._domFilter !== undefined) {\n this._domFilter = this._parent._domFilter\n }\n super._integrate(y)\n }\n /**\n * Returns the string representation of the XML document.\n * The attributes are ordered by attribute-name, so you can easily use this\n * method to compare YXmlElements\n */\n toString () {\n const attrs = this.getAttributes()\n const stringBuilder = []\n const keys = []\n for (let key in attrs) {\n keys.push(key)\n }\n keys.sort()\n const keysLen = keys.length\n for (let i = 0; i < keysLen; i++) {\n const key = keys[i]\n stringBuilder.push(key + '=\"' + attrs[key] + '\"')\n }\n const nodeName = this.nodeName.toLocaleLowerCase()\n const attrsString = stringBuilder.length > 0 ? ' ' + stringBuilder.join(' ') : ''\n return `<${nodeName}${attrsString}>${super.toString()}`\n }\n removeAttribute () {\n return YMap.prototype.delete.apply(this, arguments)\n }\n\n setAttribute () {\n return YMap.prototype.set.apply(this, arguments)\n }\n\n getAttribute () {\n return YMap.prototype.get.apply(this, arguments)\n }\n\n getAttributes () {\n const obj = {}\n for (let [key, value] of this._map) {\n if (!value._deleted) {\n obj[key] = value._content[0]\n }\n }\n return obj\n }\n getDom (_document) {\n _document = _document || document\n let dom = this._dom\n if (dom == null) {\n dom = _document.createElement(this.nodeName)\n dom._yxml = this\n let attrs = this.getAttributes()\n for (let key in attrs) {\n dom.setAttribute(key, attrs[key])\n }\n this.forEach(yxml => {\n dom.appendChild(yxml.getDom(_document))\n })\n this._bindToDom(dom, _document)\n }\n return dom\n }\n}\n","import YMap from '../YMap.js'\nimport { getHook, addHook } from './hooks.js'\n\nexport default class YXmlHook extends YMap {\n constructor (hookName, dom) {\n super()\n this._dom = null\n this.hookName = null\n if (hookName !== undefined) {\n this.hookName = hookName\n this._dom = dom\n dom._yjsHook = hookName\n dom._yxml = this\n getHook(hookName).fillType(dom, this)\n }\n }\n _copy () {\n const struct = super._copy()\n struct.hookName = this.hookName\n return struct\n }\n getDom (_document) {\n _document = _document || document\n if (this._dom === null) {\n const dom = getHook(this.hookName).createDom(this)\n this._dom = dom\n dom._yxml = this\n dom._yjsHook = this.hookName\n }\n return this._dom\n }\n _unbindFromDom () {\n this._dom._yxml = null\n this._yxml = null\n // TODO: cleanup hook?\n }\n _fromBinary (y, decoder) {\n const missing = super._fromBinary(y, decoder)\n this.hookName = decoder.readVarString()\n return missing\n }\n _toBinary (encoder) {\n super._toBinary(encoder)\n encoder.writeVarString(this.hookName)\n }\n _integrate (y) {\n if (this.hookName === null) {\n throw new Error('hookName must be defined!')\n }\n super._integrate(y)\n }\n setDomFilter () {\n // TODO: implement new modfilter method!\n }\n enableSmartScrolling () {\n // TODO: implement new smartscrolling method!\n }\n}\nYXmlHook.addHook = addHook\n","import YText from '../YText.js'\n\nexport default class YXmlText extends YText {\n constructor (arg1) {\n let dom = null\n let initialText = null\n if (arg1 != null) {\n if (arg1.nodeType != null && arg1.nodeType === arg1.TEXT_NODE) {\n dom = arg1\n initialText = dom.nodeValue\n } else if (typeof arg1 === 'string') {\n initialText = arg1\n }\n }\n super(initialText)\n this._dom = null\n this._domObserver = null\n this._domObserverListener = null\n this._scrollElement = null\n if (dom !== null) {\n this._setDom(arg1)\n }\n /*\n var token = true\n this._mutualExclude = f => {\n if (token) {\n token = false\n try {\n f()\n } catch (e) {\n console.error(e)\n }\n this._domObserver.takeRecords()\n token = true\n }\n }\n this.observe(event => {\n if (this._dom != null) {\n const dom = this._dom\n this._mutualExclude(() => {\n let anchorViewPosition = getAnchorViewPosition(this._scrollElement)\n let anchorViewFix\n if (anchorViewPosition !== null && (anchorViewPosition.anchor !== null || getBoundingClientRect(this._dom).top <= 0)) {\n anchorViewFix = anchorViewPosition\n } else {\n anchorViewFix = null\n }\n dom.nodeValue = this.toString()\n fixScrollPosition(this._scrollElement, anchorViewFix)\n })\n }\n })\n */\n }\n setDomFilter () {}\n enableSmartScrolling (scrollElement) {\n this._scrollElement = scrollElement\n }\n _setDom (dom) {\n if (this._dom != null) {\n this._unbindFromDom()\n }\n if (dom._yxml != null) {\n dom._yxml._unbindFromDom()\n }\n // set marker\n this._dom = dom\n dom._yxml = this\n }\n getDom (_document) {\n _document = _document || document\n if (this._dom === null) {\n const dom = _document.createTextNode(this.toString())\n this._setDom(dom)\n return dom\n }\n return this._dom\n }\n _delete (y, createDelete) {\n this._unbindFromDom()\n super._delete(y, createDelete)\n }\n _unbindFromDom () {\n if (this._domObserver != null) {\n this._domObserver.disconnect()\n this._domObserver = null\n }\n if (this._dom != null) {\n this._dom._yxml = null\n this._dom = null\n }\n }\n}\n","\nimport YXmlFragment from './YXmlFragment.js'\nimport YXmlElement from './YXmlElement.js'\nimport YXmlHook from './YXmlHook.js'\n\nexport { default as YXmlFragment } from './YXmlFragment.js'\nexport { default as YXmlElement } from './YXmlElement.js'\nexport { default as YXmlText } from './YXmlText.js'\nexport { default as YXmlHook } from './YXmlHook.js'\n\nYXmlFragment._YXmlElement = YXmlElement\nYXmlFragment._YXmlHook = YXmlHook\n","import { getReference } from './structReferences.js'\n\nexport const RootFakeUserID = 0xFFFFFF\n\nexport default class RootID {\n constructor (name, typeConstructor) {\n this.user = RootFakeUserID\n this.name = name\n this.type = getReference(typeConstructor)\n }\n equals (id) {\n return id !== null && id.user === this.user && id.name === this.name && id.type === this.type\n }\n lessThan (id) {\n if (id.constructor === RootID) {\n return this.user < id.user || (this.user === id.user && (this.name < id.name || (this.name === id.name && this.type < id.type)))\n } else {\n return true\n }\n }\n}\n","import Tree from '../Util/Tree.js'\nimport RootID from '../Util/RootID.js'\nimport { getStruct } from '../Util/structReferences.js'\nimport { logID } from '../MessageHandler/messageToString.js'\n\nexport default class OperationStore extends Tree {\n constructor (y) {\n super()\n this.y = y\n }\n logTable () {\n const items = []\n this.iterate(null, null, function (item) {\n items.push({\n id: logID(item),\n origin: logID(item._origin === null ? null : item._origin._lastId),\n left: logID(item._left === null ? null : item._left._lastId),\n right: logID(item._right),\n right_origin: logID(item._right_origin),\n parent: logID(item._parent),\n parentSub: item._parentSub,\n deleted: item._deleted,\n content: JSON.stringify(item._content)\n })\n })\n console.table(items)\n }\n get (id) {\n let struct = this.find(id)\n if (struct === null && id instanceof RootID) {\n const Constr = getStruct(id.type)\n const y = this.y\n struct = new Constr()\n struct._id = id\n struct._parent = y\n y.transact(() => {\n struct._integrate(y)\n })\n this.put(struct)\n }\n return struct\n }\n // Use getItem for structs with _length > 1\n getItem (id) {\n var item = this.findWithUpperBound(id)\n if (item === null) {\n return null\n }\n const itemID = item._id\n if (id.user === itemID.user && id.clock < itemID.clock + item._length) {\n return item\n } else {\n return null\n }\n }\n // Return an insertion such that id is the first element of content\n // This function manipulates an item, if necessary\n getItemCleanStart (id) {\n var ins = this.getItem(id)\n if (ins === null || ins._length === 1) {\n return ins\n }\n const insID = ins._id\n if (insID.clock === id.clock) {\n return ins\n } else {\n return ins._splitAt(this.y, id.clock - insID.clock)\n }\n }\n // Return an insertion such that id is the last element of content\n // This function manipulates an operation, if necessary\n getItemCleanEnd (id) {\n var ins = this.getItem(id)\n if (ins === null || ins._length === 1) {\n return ins\n }\n const insID = ins._id\n if (insID.clock + ins._length - 1 === id.clock) {\n return ins\n } else {\n ins._splitAt(this.y, id.clock - insID.clock + 1)\n return ins\n }\n }\n}\n","import ID from '../Util/ID.js'\n\nexport default class StateStore {\n constructor (y) {\n this.y = y\n this.state = new Map()\n }\n logTable () {\n const entries = []\n for (let [user, state] of this.state) {\n entries.push({\n user, state\n })\n }\n console.table(entries)\n }\n getNextID (len) {\n const user = this.y.userID\n const state = this.getState(user)\n this.setState(user, state + len)\n return new ID(user, state)\n }\n updateRemoteState (struct) {\n let user = struct._id.user\n let userState = this.state.get(user)\n while (struct !== null && struct._id.clock === userState) {\n userState += struct._length\n struct = this.y.os.get(new ID(user, userState))\n }\n this.state.set(user, userState)\n }\n getState (user) {\n let state = this.state.get(user)\n if (state == null) {\n return 0\n }\n return state\n }\n setState (user, state) {\n // TODO: modify missingi structs here\n const beforeState = this.y._transaction.beforeState\n if (!beforeState.has(user)) {\n beforeState.set(user, this.getState(user))\n }\n this.state.set(user, state)\n }\n}\n","export default class NamedEventHandler {\n constructor () {\n this._eventListener = new Map()\n this._stateListener = new Map()\n }\n _getListener (name) {\n let listeners = this._eventListener.get(name)\n if (listeners === undefined) {\n listeners = {\n once: new Set(),\n on: new Set()\n }\n this._eventListener.set(name, listeners)\n }\n return listeners\n }\n once (name, f) {\n let listeners = this._getListener(name)\n listeners.once.add(f)\n }\n on (name, f) {\n let listeners = this._getListener(name)\n listeners.on.add(f)\n }\n _initStateListener (name) {\n let state = this._stateListener.get(name)\n if (state === undefined) {\n state = {}\n state.promise = new Promise(function (resolve) {\n state.resolve = resolve\n })\n this._stateListener.set(name, state)\n }\n return state\n }\n when (name) {\n return this._initStateListener(name).promise\n }\n off (name, f) {\n if (name == null || f == null) {\n throw new Error('You must specify event name and function!')\n }\n const listener = this._eventListener.get(name)\n if (listener !== undefined) {\n listener.on.delete(f)\n listener.once.delete(f)\n }\n }\n emit (name, ...args) {\n this._initStateListener(name).resolve()\n const listener = this._eventListener.get(name)\n if (listener !== undefined) {\n listener.on.forEach(f => f.apply(null, args))\n listener.once.forEach(f => f.apply(null, args))\n listener.once = new Set()\n } else if (name === 'error') {\n console.error(args[0])\n }\n }\n destroy () {\n this._eventListener = null\n }\n}\n","\n/**\n * This is the common logic for both the Node.js and web browser\n * implementations of `debug()`.\n *\n * Expose `debug()` as the module.\n */\n\nexports = module.exports = createDebug.debug = createDebug['default'] = createDebug;\nexports.coerce = coerce;\nexports.disable = disable;\nexports.enable = enable;\nexports.enabled = enabled;\nexports.humanize = require('ms');\n\n/**\n * The currently active debug mode names, and names to skip.\n */\n\nexports.names = [];\nexports.skips = [];\n\n/**\n * Map of special \"%n\" handling functions, for the debug \"format\" argument.\n *\n * Valid key names are a single, lower or upper-case letter, i.e. \"n\" and \"N\".\n */\n\nexports.formatters = {};\n\n/**\n * Previous log timestamp.\n */\n\nvar prevTime;\n\n/**\n * Select a color.\n * @param {String} namespace\n * @return {Number}\n * @api private\n */\n\nfunction selectColor(namespace) {\n var hash = 0, i;\n\n for (i in namespace) {\n hash = ((hash << 5) - hash) + namespace.charCodeAt(i);\n hash |= 0; // Convert to 32bit integer\n }\n\n return exports.colors[Math.abs(hash) % exports.colors.length];\n}\n\n/**\n * Create a debugger with the given `namespace`.\n *\n * @param {String} namespace\n * @return {Function}\n * @api public\n */\n\nfunction createDebug(namespace) {\n\n function debug() {\n // disabled?\n if (!debug.enabled) return;\n\n var self = debug;\n\n // set `diff` timestamp\n var curr = +new Date();\n var ms = curr - (prevTime || curr);\n self.diff = ms;\n self.prev = prevTime;\n self.curr = curr;\n prevTime = curr;\n\n // turn the `arguments` into a proper Array\n var args = new Array(arguments.length);\n for (var i = 0; i < args.length; i++) {\n args[i] = arguments[i];\n }\n\n args[0] = exports.coerce(args[0]);\n\n if ('string' !== typeof args[0]) {\n // anything else let's inspect with %O\n args.unshift('%O');\n }\n\n // apply any `formatters` transformations\n var index = 0;\n args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) {\n // if we encounter an escaped % then don't increase the array index\n if (match === '%%') return match;\n index++;\n var formatter = exports.formatters[format];\n if ('function' === typeof formatter) {\n var val = args[index];\n match = formatter.call(self, val);\n\n // now we need to remove `args[index]` since it's inlined in the `format`\n args.splice(index, 1);\n index--;\n }\n return match;\n });\n\n // apply env-specific formatting (colors, etc.)\n exports.formatArgs.call(self, args);\n\n var logFn = debug.log || exports.log || console.log.bind(console);\n logFn.apply(self, args);\n }\n\n debug.namespace = namespace;\n debug.enabled = exports.enabled(namespace);\n debug.useColors = exports.useColors();\n debug.color = selectColor(namespace);\n\n // env-specific initialization logic for debug instances\n if ('function' === typeof exports.init) {\n exports.init(debug);\n }\n\n return debug;\n}\n\n/**\n * Enables a debug mode by namespaces. This can include modes\n * separated by a colon and wildcards.\n *\n * @param {String} namespaces\n * @api public\n */\n\nfunction enable(namespaces) {\n exports.save(namespaces);\n\n exports.names = [];\n exports.skips = [];\n\n var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\\s,]+/);\n var len = split.length;\n\n for (var i = 0; i < len; i++) {\n if (!split[i]) continue; // ignore empty strings\n namespaces = split[i].replace(/\\*/g, '.*?');\n if (namespaces[0] === '-') {\n exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));\n } else {\n exports.names.push(new RegExp('^' + namespaces + '$'));\n }\n }\n}\n\n/**\n * Disable debug output.\n *\n * @api public\n */\n\nfunction disable() {\n exports.enable('');\n}\n\n/**\n * Returns true if the given mode name is enabled, false otherwise.\n *\n * @param {String} name\n * @return {Boolean}\n * @api public\n */\n\nfunction enabled(name) {\n var i, len;\n for (i = 0, len = exports.skips.length; i < len; i++) {\n if (exports.skips[i].test(name)) {\n return false;\n }\n }\n for (i = 0, len = exports.names.length; i < len; i++) {\n if (exports.names[i].test(name)) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Coerce `val`.\n *\n * @param {Mixed} val\n * @return {Mixed}\n * @api private\n */\n\nfunction coerce(val) {\n if (val instanceof Error) return val.stack || val.message;\n return val;\n}\n","/**\n * This is the web browser implementation of `debug()`.\n *\n * Expose `debug()` as the module.\n */\n\nexports = module.exports = require('./debug');\nexports.log = log;\nexports.formatArgs = formatArgs;\nexports.save = save;\nexports.load = load;\nexports.useColors = useColors;\nexports.storage = 'undefined' != typeof chrome\n && 'undefined' != typeof chrome.storage\n ? chrome.storage.local\n : localstorage();\n\n/**\n * Colors.\n */\n\nexports.colors = [\n 'lightseagreen',\n 'forestgreen',\n 'goldenrod',\n 'dodgerblue',\n 'darkorchid',\n 'crimson'\n];\n\n/**\n * Currently only WebKit-based Web Inspectors, Firefox >= v31,\n * and the Firebug extension (any Firefox version) are known\n * to support \"%c\" CSS customizations.\n *\n * TODO: add a `localStorage` variable to explicitly enable/disable colors\n */\n\nfunction useColors() {\n // NB: In an Electron preload script, document will be defined but not fully\n // initialized. Since we know we're in Chrome, we'll just detect this case\n // explicitly\n if (typeof window !== 'undefined' && window.process && window.process.type === 'renderer') {\n return true;\n }\n\n // is webkit? http://stackoverflow.com/a/16459606/376773\n // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632\n return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||\n // is firebug? http://stackoverflow.com/a/398120/376773\n (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||\n // is firefox >= v31?\n // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages\n (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\\/(\\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||\n // double check webkit in userAgent just in case we are in a worker\n (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\\/(\\d+)/));\n}\n\n/**\n * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.\n */\n\nexports.formatters.j = function(v) {\n try {\n return JSON.stringify(v);\n } catch (err) {\n return '[UnexpectedJSONParseError]: ' + err.message;\n }\n};\n\n\n/**\n * Colorize log arguments if enabled.\n *\n * @api public\n */\n\nfunction formatArgs(args) {\n var useColors = this.useColors;\n\n args[0] = (useColors ? '%c' : '')\n + this.namespace\n + (useColors ? ' %c' : ' ')\n + args[0]\n + (useColors ? '%c ' : ' ')\n + '+' + exports.humanize(this.diff);\n\n if (!useColors) return;\n\n var c = 'color: ' + this.color;\n args.splice(1, 0, c, 'color: inherit')\n\n // the final \"%c\" is somewhat tricky, because there could be other\n // arguments passed either before or after the %c, so we need to\n // figure out the correct index to insert the CSS into\n var index = 0;\n var lastC = 0;\n args[0].replace(/%[a-zA-Z%]/g, function(match) {\n if ('%%' === match) return;\n index++;\n if ('%c' === match) {\n // we only are interested in the *last* %c\n // (the user may have provided their own)\n lastC = index;\n }\n });\n\n args.splice(lastC, 0, c);\n}\n\n/**\n * Invokes `console.log()` when available.\n * No-op when `console.log` is not a \"function\".\n *\n * @api public\n */\n\nfunction log() {\n // this hackery is required for IE8/9, where\n // the `console.log` function doesn't have 'apply'\n return 'object' === typeof console\n && console.log\n && Function.prototype.apply.call(console.log, console, arguments);\n}\n\n/**\n * Save `namespaces`.\n *\n * @param {String} namespaces\n * @api private\n */\n\nfunction save(namespaces) {\n try {\n if (null == namespaces) {\n exports.storage.removeItem('debug');\n } else {\n exports.storage.debug = namespaces;\n }\n } catch(e) {}\n}\n\n/**\n * Load `namespaces`.\n *\n * @return {String} returns the previously persisted debug modes\n * @api private\n */\n\nfunction load() {\n var r;\n try {\n r = exports.storage.debug;\n } catch(e) {}\n\n // If debug isn't set in LS, and we're in Electron, try to load $DEBUG\n if (!r && typeof process !== 'undefined' && 'env' in process) {\n r = process.env.DEBUG;\n }\n\n return r;\n}\n\n/**\n * Enable namespaces listed in `localStorage.debug` initially.\n */\n\nexports.enable(load());\n\n/**\n * Localstorage attempts to return the localstorage.\n *\n * This is necessary because safari throws\n * when a user disables cookies/localstorage\n * and you attempt to access it.\n *\n * @return {LocalStorage}\n * @api private\n */\n\nfunction localstorage() {\n try {\n return window.localStorage;\n } catch (e) {}\n}\n","import BinaryEncoder from './Binary/Encoder.js'\nimport BinaryDecoder from './Binary/Decoder.js'\n\nimport { sendSyncStep1, readSyncStep1 } from './MessageHandler/syncStep1.js'\nimport { readSyncStep2 } from './MessageHandler/syncStep2.js'\nimport { integrateRemoteStructs } from './MessageHandler/integrateRemoteStructs.js'\n\nimport debug from 'debug'\n\nexport default class AbstractConnector {\n constructor (y, opts) {\n this.y = y\n this.opts = opts\n if (opts.role == null || opts.role === 'master') {\n this.role = 'master'\n } else if (opts.role === 'slave') {\n this.role = 'slave'\n } else {\n throw new Error(\"Role must be either 'master' or 'slave'!\")\n }\n this.log = debug('y:connector')\n this.logMessage = debug('y:connector-message')\n this._forwardAppliedStructs = opts.forwardAppliedOperations || false // TODO: rename\n this.role = opts.role\n this.connections = new Map()\n this.isSynced = false\n this.userEventListeners = []\n this.whenSyncedListeners = []\n this.currentSyncTarget = null\n this.debug = opts.debug === true\n this.broadcastBuffer = new BinaryEncoder()\n this.broadcastBufferSize = 0\n this.protocolVersion = 11\n this.authInfo = opts.auth || null\n this.checkAuth = opts.checkAuth || function () { return Promise.resolve('write') } // default is everyone has write access\n if (opts.maxBufferLength == null) {\n this.maxBufferLength = -1\n } else {\n this.maxBufferLength = opts.maxBufferLength\n }\n }\n\n reconnect () {\n this.log('reconnecting..')\n }\n\n disconnect () {\n this.log('discronnecting..')\n this.connections = new Map()\n this.isSynced = false\n this.currentSyncTarget = null\n this.whenSyncedListeners = []\n return Promise.resolve()\n }\n\n onUserEvent (f) {\n this.userEventListeners.push(f)\n }\n\n removeUserEventListener (f) {\n this.userEventListeners = this.userEventListeners.filter(g => f !== g)\n }\n\n userLeft (user) {\n if (this.connections.has(user)) {\n this.log('%s: User left %s', this.y.userID, user)\n this.connections.delete(user)\n // check if isSynced event can be sent now\n this._setSyncedWith(null)\n for (var f of this.userEventListeners) {\n f({\n action: 'userLeft',\n user: user\n })\n }\n }\n }\n\n userJoined (user, role, auth) {\n if (role == null) {\n throw new Error('You must specify the role of the joined user!')\n }\n if (this.connections.has(user)) {\n throw new Error('This user already joined!')\n }\n this.log('%s: User joined %s', this.y.userID, user)\n this.connections.set(user, {\n uid: user,\n isSynced: false,\n role: role,\n processAfterAuth: [],\n processAfterSync: [],\n auth: auth || null,\n receivedSyncStep2: false\n })\n let defer = {}\n defer.promise = new Promise(function (resolve) { defer.resolve = resolve })\n this.connections.get(user).syncStep2 = defer\n for (var f of this.userEventListeners) {\n f({\n action: 'userJoined',\n user: user,\n role: role\n })\n }\n this._syncWithUser(user)\n }\n\n // Execute a function _when_ we are connected.\n // If not connected, wait until connected\n whenSynced (f) {\n if (this.isSynced) {\n f()\n } else {\n this.whenSyncedListeners.push(f)\n }\n }\n\n _syncWithUser (userID) {\n if (this.role === 'slave') {\n return // \"The current sync has not finished or this is controlled by a master!\"\n }\n sendSyncStep1(this, userID)\n }\n\n _fireIsSyncedListeners () {\n if (!this.isSynced) {\n this.isSynced = true\n // It is safer to remove this!\n // call whensynced listeners\n for (var f of this.whenSyncedListeners) {\n f()\n }\n this.whenSyncedListeners = []\n this.y._setContentReady()\n this.y.emit('synced')\n }\n }\n\n send (uid, buffer) {\n const y = this.y\n if (!(buffer instanceof ArrayBuffer || buffer instanceof Uint8Array)) {\n throw new Error('Expected Message to be an ArrayBuffer or Uint8Array - don\\'t use this method to send custom messages')\n }\n this.log('User%s to User%s: Send \\'%y\\'', y.userID, uid, buffer)\n this.logMessage('User%s to User%s: Send %Y', y.userID, uid, [y, buffer])\n }\n\n broadcast (buffer) {\n const y = this.y\n if (!(buffer instanceof ArrayBuffer || buffer instanceof Uint8Array)) {\n throw new Error('Expected Message to be an ArrayBuffer or Uint8Array - don\\'t use this method to send custom messages')\n }\n this.log('User%s: Broadcast \\'%y\\'', y.userID, buffer)\n this.logMessage('User%s: Broadcast: %Y', y.userID, [y, buffer])\n }\n\n /*\n Buffer operations, and broadcast them when ready.\n */\n broadcastStruct (struct) {\n const firstContent = this.broadcastBuffer.length === 0\n if (firstContent) {\n this.broadcastBuffer.writeVarString(this.y.room)\n this.broadcastBuffer.writeVarString('update')\n this.broadcastBufferSize = 0\n this.broadcastBufferSizePos = this.broadcastBuffer.pos\n this.broadcastBuffer.writeUint32(0)\n }\n this.broadcastBufferSize++\n struct._toBinary(this.broadcastBuffer)\n if (this.maxBufferLength > 0 && this.broadcastBuffer.length > this.maxBufferLength) {\n // it is necessary to send the buffer now\n // cache the buffer and check if server is responsive\n const buffer = this.broadcastBuffer\n buffer.setUint32(this.broadcastBufferSizePos, this.broadcastBufferSize)\n this.broadcastBuffer = new BinaryEncoder()\n this.whenRemoteResponsive().then(() => {\n this.broadcast(buffer.createBuffer())\n })\n } else if (firstContent) {\n // send the buffer when all transactions are finished\n // (or buffer exceeds maxBufferLength)\n setTimeout(() => {\n if (this.broadcastBuffer.length > 0) {\n const buffer = this.broadcastBuffer\n buffer.setUint32(this.broadcastBufferSizePos, this.broadcastBufferSize)\n this.broadcast(buffer.createBuffer())\n this.broadcastBuffer = new BinaryEncoder()\n }\n }, 0)\n }\n }\n\n /*\n * Somehow check the responsiveness of the remote clients/server\n * Default behavior:\n * Wait 100ms before broadcasting the next batch of operations\n *\n * Only used when maxBufferLength is set\n *\n */\n whenRemoteResponsive () {\n return new Promise(function (resolve) {\n setTimeout(resolve, 100)\n })\n }\n\n /*\n You received a raw message, and you know that it is intended for Yjs. Then call this function.\n */\n receiveMessage (sender, buffer, skipAuth) {\n const y = this.y\n const userID = y.userID\n skipAuth = skipAuth || false\n if (!(buffer instanceof ArrayBuffer || buffer instanceof Uint8Array)) {\n return Promise.reject(new Error('Expected Message to be an ArrayBuffer or Uint8Array!'))\n }\n if (sender === userID) {\n return Promise.resolve()\n }\n let decoder = new BinaryDecoder(buffer)\n let encoder = new BinaryEncoder()\n let roomname = decoder.readVarString() // read room name\n encoder.writeVarString(roomname)\n let messageType = decoder.readVarString()\n let senderConn = this.connections.get(sender)\n this.log('User%s from User%s: Receive \\'%s\\'', userID, sender, messageType)\n this.logMessage('User%s from User%s: Receive %Y', userID, sender, [y, buffer])\n if (senderConn == null && !skipAuth) {\n throw new Error('Received message from unknown peer!')\n }\n if (messageType === 'sync step 1' || messageType === 'sync step 2') {\n let auth = decoder.readVarUint()\n if (senderConn.auth == null) {\n senderConn.processAfterAuth.push([messageType, senderConn, decoder, encoder, sender])\n // check auth\n return this.checkAuth(auth, y, sender).then(authPermissions => {\n if (senderConn.auth == null) {\n senderConn.auth = authPermissions\n y.emit('userAuthenticated', {\n user: senderConn.uid,\n auth: authPermissions\n })\n }\n let messages = senderConn.processAfterAuth\n senderConn.processAfterAuth = []\n\n messages.forEach(m =>\n this.computeMessage(m[0], m[1], m[2], m[3], m[4])\n )\n })\n }\n }\n if ((skipAuth || senderConn.auth != null) && (messageType !== 'update' || senderConn.isSynced)) {\n this.computeMessage(messageType, senderConn, decoder, encoder, sender, skipAuth)\n } else {\n senderConn.processAfterSync.push([messageType, senderConn, decoder, encoder, sender, false])\n }\n }\n\n computeMessage (messageType, senderConn, decoder, encoder, sender, skipAuth) {\n if (messageType === 'sync step 1' && (senderConn.auth === 'write' || senderConn.auth === 'read')) {\n // cannot wait for sync step 1 to finish, because we may wait for sync step 2 in sync step 1 (->lock)\n readSyncStep1(decoder, encoder, this.y, senderConn, sender)\n } else {\n const y = this.y\n y.transact(function () {\n if (messageType === 'sync step 2' && senderConn.auth === 'write') {\n readSyncStep2(decoder, encoder, y, senderConn, sender)\n } else if (messageType === 'update' && (skipAuth || senderConn.auth === 'write')) {\n integrateRemoteStructs(y, decoder)\n } else {\n throw new Error('Unable to receive message')\n }\n }, true)\n }\n }\n\n _setSyncedWith (user) {\n if (user != null) {\n const userConn = this.connections.get(user)\n userConn.isSynced = true\n const messages = userConn.processAfterSync\n userConn.processAfterSync = []\n messages.forEach(m => {\n this.computeMessage(m[0], m[1], m[2], m[3], m[4])\n })\n }\n const conns = Array.from(this.connections.values())\n if (conns.length > 0 && conns.every(u => u.isSynced)) {\n this._fireIsSyncedListeners()\n }\n }\n}\n","\nimport { createMutualExclude } from '../Util/mutualExclude.js'\n\nexport default class Binding {\n constructor (type, target) {\n this.type = type\n this.target = target\n this._mutualExclude = createMutualExclude()\n }\n destroy () {\n this.type = null\n this.target = null\n }\n}\n","import DeleteStore from './Store/DeleteStore.js'\nimport OperationStore from './Store/OperationStore.js'\nimport StateStore from './Store/StateStore.js'\nimport { generateUserID } from './Util/generateUserID.js'\nimport RootID from './Util/RootID.js'\nimport NamedEventHandler from './Util/NamedEventHandler.js'\nimport UndoManager from './Util/UndoManager.js'\nimport { integrateRemoteStructs } from './MessageHandler/integrateRemoteStructs.js'\n\nimport { messageToString, messageToRoomname } from './MessageHandler/messageToString.js'\n\nimport Connector from './Connector.js'\nimport Persistence from './Persistence.js'\nimport YArray from './Type/YArray.js'\nimport YMap from './Type/YMap.js'\nimport YText from './Type/YText.js'\nimport { YXmlFragment, YXmlElement, YXmlText, YXmlHook } from './Type/y-xml/y-xml.js'\nimport BinaryDecoder from './Binary/Decoder.js'\nimport { getRelativePosition, fromRelativePosition } from './Util/relativePosition.js'\nimport { addStruct as addType } from './Util/structReferences.js'\n\nimport debug from 'debug'\nimport Transaction from './Transaction.js'\n\nimport TextareaBinding from './Binding/TextareaBinding.js'\n\nimport { toBinary, fromBinary } from './MessageHandler/binaryEncode.js'\n\nexport default class Y extends NamedEventHandler {\n constructor (room, opts, persistence) {\n super()\n this.room = room\n if (opts != null) {\n opts.connector.room = room\n }\n this._contentReady = false\n this._opts = opts\n this.userID = generateUserID()\n this.share = {}\n this.ds = new DeleteStore(this)\n this.os = new OperationStore(this)\n this.ss = new StateStore(this)\n this._missingStructs = new Map()\n this._readyToIntegrate = []\n this._transaction = null\n this.connector = null\n this.connected = false\n let initConnection = () => {\n if (opts != null) {\n this.connector = new Y[opts.connector.name](this, opts.connector)\n this.connected = true\n this.emit('connectorReady')\n }\n }\n if (persistence != null) {\n this.persistence = persistence\n persistence._init(this).then(initConnection)\n } else {\n this.persistence = null\n initConnection()\n }\n }\n _setContentReady () {\n if (!this._contentReady) {\n this._contentReady = true\n this.emit('content')\n }\n }\n whenContentReady () {\n if (this._contentReady) {\n return Promise.resolve()\n } else {\n return new Promise(resolve => {\n this.once('content', resolve)\n })\n }\n }\n _beforeChange () {}\n transact (f, remote = false) {\n let initialCall = this._transaction === null\n if (initialCall) {\n this._transaction = new Transaction(this)\n this.emit('beforeTransaction', this, this._transaction, remote)\n }\n try {\n f(this)\n } catch (e) {\n console.error(e)\n }\n if (initialCall) {\n this.emit('beforeObserverCalls', this, this._transaction, remote)\n const transaction = this._transaction\n this._transaction = null\n // emit change events on changed types\n transaction.changedTypes.forEach(function (subs, type) {\n if (!type._deleted) {\n type._callObserver(transaction, subs, remote)\n }\n })\n transaction.changedParentTypes.forEach(function (events, type) {\n if (!type._deleted) {\n events = events\n .filter(event =>\n !event.target._deleted\n )\n events\n .forEach(event => {\n event.currentTarget = type\n })\n // we don't have to check for events.length\n // because there is no way events is empty..\n type._deepEventHandler.callEventListeners(transaction, events)\n }\n })\n // when all changes & events are processed, emit afterTransaction event\n this.emit('afterTransaction', this, transaction, remote)\n }\n }\n // fake _start for root properties (y.set('name', type))\n get _start () {\n return null\n }\n set _start (start) {\n return null\n }\n define (name, TypeConstructor) {\n let id = new RootID(name, TypeConstructor)\n let type = this.os.get(id)\n if (this.share[name] === undefined) {\n this.share[name] = type\n } else if (this.share[name] !== type) {\n throw new Error('Type is already defined with a different constructor')\n }\n return type\n }\n get (name) {\n return this.share[name]\n }\n disconnect () {\n if (this.connected) {\n this.connected = false\n return this.connector.disconnect()\n } else {\n return Promise.resolve()\n }\n }\n reconnect () {\n if (!this.connected) {\n this.connected = true\n return this.connector.reconnect()\n } else {\n return Promise.resolve()\n }\n }\n destroy () {\n super.destroy()\n this.share = null\n if (this.connector != null) {\n if (this.connector.destroy != null) {\n this.connector.destroy()\n } else {\n this.connector.disconnect()\n }\n }\n if (this.persistence !== null) {\n this.persistence.deinit(this)\n this.persistence = null\n }\n this.os = null\n this.ds = null\n this.ss = null\n }\n whenSynced () {\n return new Promise(resolve => {\n this.once('synced', () => {\n resolve()\n })\n })\n }\n}\n\nY.extend = function extendYjs () {\n for (var i = 0; i < arguments.length; i++) {\n var f = arguments[i]\n if (typeof f === 'function') {\n f(Y)\n } else {\n throw new Error('Expected a function!')\n }\n }\n}\n\n// TODO: The following assignments should be moved to yjs-dist\nY.AbstractConnector = Connector\nY.AbstractPersistence = Persistence\nY.Array = YArray\nY.Map = YMap\nY.Text = YText\nY.XmlElement = YXmlElement\nY.XmlFragment = YXmlFragment\nY.XmlText = YXmlText\nY.XmlHook = YXmlHook\n\nY.TextareaBinding = TextareaBinding\n\nY.utils = {\n BinaryDecoder,\n UndoManager,\n getRelativePosition,\n fromRelativePosition,\n addType,\n integrateRemoteStructs,\n toBinary,\n fromBinary\n}\n\nY.debug = debug\ndebug.formatters.Y = messageToString\ndebug.formatters.y = messageToRoomname\n"],"names":["_integrateRemoteStructHelper","y","struct","id","_id","undefined","_integrate","ss","getState","user","clock","msu","_missingStructs","get","finalClock","_length","missingStructs","forEach","missing","decoder","missingDef","oldPos","pos","_fromBinary","length","_readyToIntegrate","push","delete","stringifyStructs","strBuilder","len","readUint32","i","reference","readVarUint","Constr","getStruct","logMessage","_logString","map","logID","join","integrateRemoteStructs","decoderPos","shift","_decoder","BinaryDecoder","uint8arr","missingEntry","MissingEntry","m","has","set","Map","readStateSet","ssLength","writeStateSet","encoder","lenPosition","writeUint32","state","writeVarUint","setUint32","writeDeleteSet","currentUser","currentLength","lastLenPos","numberOfUsers","laterDSLenPus","ds","iterate","n","gc","writeUint8","readDeleteSet","dsLength","dv","dvLength","j","from","readUint8","d","deletions","ID","Number","MAX_VALUE","diff","Math","min","del","stringifySyncStep1","auth","readVarString","protocolVersion","ssBuilder","sendSyncStep1","connector","syncUser","BinaryEncoder","writeVarString","room","authInfo","send","createBuffer","writeStructs","lenPos","keys","RootFakeUserID","os","_toBinary","readSyncStep1","senderConn","sender","warn","destroy","uid","receivedSyncStep2","role","stringifySyncStep2","len2","to","readSyncStep2","_setSyncedWith","messageToString","buffer","type","messageToRoomname","RootID","name","constructor","Y","Error","deleteItemRange","range","createDelete","_forwardAppliedStructs","item","getItemCleanStart","_deleted","_splitAt","_delete","itemLen","node","findNode","val","equals","nodeVal","nodeLen","next","transactionTypeChanged","sub","_transaction","newTypes","changedTypes","subs","Set","add","splitHelper","a","b","aID","_origin","_left","_right","_right_origin","_parent","_parentSub","foundOrigins","o","put","integrateChildren","start","right","defaultDomFilter","attributes","iterateUntilUndeleted","_insertNodeHelper","yxml","prevExpectedNode","child","insertedNodes","insertDomElementsAfter","applyChangesFromDom","dom","_yxml","YXmlHook","_y","knownChildren","Array","prototype","call","childNodes","filter","childType","expectedNode","_start","domCnt","childYXml","this","reflectChangesOnDom","events","_document","_mutualExclude","event","target","_dom","YXmlText","nodeValue","toString","attributesChanged","value","getAttribute","attributeName","removeAttribute","setAttribute","childListChanged","currentChild","firstChild","t","expectedChild","getDom","parentNode","nextSibling","removeChild","insertBefore","tmp","getRelativePosition","offset","fromRelativePosition","rpos","findNodeWithUpperBound","parent","afterTransactionSelectionFixer","transaction","remote","relativeSelection","fromY","toY","shouldUpdate","anchorNode","browserSelection","anchorOffset","focusNode","focusOffset","sel","setBaseAndExtent","simpleDiff","left","slice","domToYXml","doms","types","_unbindFromDom","_domFilter","nodeName","hookName","_yjsHook","dataset","yjsHook","nodeType","TEXT_NODE","ELEMENT_NODE","YXmlFragment","_YXmlElement","addHook","hook","getHook","xmlHooks","addStruct","structConstructor","structs","getReference","typeConstructor","references","generateUserID","crypto","getRandomValue","arr","Uint32Array","getRandomValues","randomBytes","buf","ceil","random","isStructInScope","scope","applyReverseOperation","reverseBuffer","performedUndo","transact","undoOp","pop","fromState","getItemCleanEnd","toState","op","_redone","deletedStructs","userID","_redo","parse","str","String","match","exec","parseFloat","toLowerCase","h","s","fmtShort","ms","round","fmtLong","plural","floor","fromBinary","toBinary","createMutualExclude","token","f","e","error","getFreshCnf","typeObserver","textarea","_this","textType","relativeStart","selectionStart","relativeEnd","selectionEnd","end","setSelectionRange","domObserver","_this2","remove","insert","N","color","tree","newParent","newRight","root","p","newLeft","Tree","nextID","clone","findWithLowerBound","prevID","findWithUpperBound","lessThan","prev","findNodeWithLowerBound","findSmallestNode","isFakeChild","blacken","isBlack","isRed","_fixDelete","sibling","redden","rotateLeft","rotateRight","v","_fixInsert","uncle","getUncle","grandparent","DSNode","DeleteStore","deletes","table","nId","findNext","markDeleted","_next","ArrayBuffer","Uint8Array","Buffer","newPos","uint","num","r","bytes","encodedString","fromCodePoint","decodeURIComponent","escape","rid","data","unescape","encodeURIComponent","split","c","codePointAt","Delete","_target","targetID","readID","_targetID","getItem","writeID","broadcastStruct","persistence","saveStruct","Transaction","beforeState","changedParentTypes","Item","_copy","selfID","userState","getNextID","setState","_beforeChange","_map","conflictingItems","itemsBeforeOrigin","clear","parentSub","pmap","info","_lastId","JSON","stringify","originID","origin","rightID","parentID","EventHandler","eventListeners","g","Type","_eventHandler","_deepEventHandler","path","callEventListeners","addEventListener","removeEventListener","values","ItemJSON","_content","ctnt","parsed","encoded","content","splice","ItemString","YEvent","currentTarget","unshift","YArrayEvent","yarray","_addedElements","addedElements","removedElements","YArray","parentSubs","_callEventHandler","toJSON","res","contentLen","Symbol","iterator","_item","_itemElement","_count","_this4","count","diffDel","_transact","_this5","prevJsonIns","rightLen","splitDiff","insertAfter","lastUndeleted","YMapEvent","ymap","keysChanged","YMap","key","_this3","old","size","YText","string","text","beforeTransactionSelectionFixer","getSelection","YXmlEvent","YXmlTreeWalker","_filter","_root","_currentNode","_firstCall","done","_domObserver","query","toUpperCase","element","scrollElement","_scrollElement","enableSmartScrolling","getAttributes","attrs","result","setDomFilter","xml","disconnect","_beforeTransactionHandler","off","innerHTML","_bindToDom","document","on","applyFilter","isChild","observeDeep","MutationObserver","_domObserverListener","takeRecords","diffChildren","mutation","change","yOnChildrenChanged","observe","YXmlElement","arg1","arg2","_setDom","attr","insertDomElements","stringBuilder","sort","keysLen","toLocaleLowerCase","apply","arguments","obj","createElement","appendChild","fillType","createDom","initialText","createTextNode","_YXmlHook","OperationStore","items","find","itemID","ins","insID","StateStore","entries","NamedEventHandler","_eventListener","_stateListener","listeners","_getListener","once","promise","Promise","resolve","_initStateListener","listener","args","ReverseOperation","created","Date","UndoManager","options","captureTimeout","_undoBuffer","_redoBuffer","_scope","_undoing","_redoing","_lastTransactionWasUndo","reverseOperation","lastUndoOp","performedRedo","isNaN","long","selectColor","namespace","hash","charCodeAt","exports","colors","abs","createDebug","debug","enabled","self","curr","prevTime","coerce","index","replace","format","formatter","formatters","formatArgs","log","console","bind","useColors","init","enable","namespaces","save","skips","RegExp","substr","names","disable","test","stack","message","module","require$$0","window","process","documentElement","style","WebkitAppearance","firebug","exception","navigator","userAgent","parseInt","$1","humanize","lastC","Function","storage","removeItem","load","env","DEBUG","chrome","local","localStorage","err","AbstractConnector","opts","forwardAppliedOperations","connections","isSynced","userEventListeners","whenSyncedListeners","currentSyncTarget","broadcastBuffer","broadcastBufferSize","checkAuth","maxBufferLength","defer","syncStep2","_syncWithUser","_setContentReady","emit","firstContent","broadcastBufferSizePos","whenRemoteResponsive","then","broadcast","skipAuth","reject","roomname","messageType","processAfterAuth","authPermissions","messages","computeMessage","processAfterSync","userConn","conns","every","u","_fireIsSyncedListeners","AbstractPersistence","ys","cnf","mutualExclude","saveUpdate","_cnf","retrieve","destroyYjsInstances","deinit","model","updates","Binding","TextareaBinding","domTextarea","_typeObserver","unobserve","_contentReady","_opts","share","connected","initConnection","_init","initialCall","_callObserver","TypeConstructor","reconnect","extend","Connector","Persistence","Text","XmlElement","XmlFragment","XmlText","XmlHook","utils"],"mappings":";;;;;4KAiBA,SAASA,GAA8BC,EAAGC,MAClCC,GAAKD,EAAOE,WACPC,KAAPF,IACKG,WAAWL,OACb,IACDA,EAAEM,GAAGC,SAASL,EAAGM,MAAQN,EAAGO,eAGzBJ,WAAWL,MACdU,GAAMV,EAAEW,gBAAgBC,IAAIV,EAAGM,SACxB,MAAPE,SACED,GAAQP,EAAGO,MACTI,EAAaJ,EAA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AAGA,EAAI2f,UAAUngB,OAAQQ,IAAK,IACrC+R,GAAI4N,UAAU3f,MACD,kBAAN+R,QAGH,IAAI5L,OAAM,0BAFdD,KAQRA,EAAEogB,kBAAoB+D,GACtBnkB,EAAEwiB,oBAAsB4B,GACxBpkB,EAAE0D,MAAQ6Q,OACVvU,EAAE7E,IAAM4a,KACR/V,EAAEqkB,KAAOjO,MACTpW,EAAEskB,WAAaxL,YACf9Y,EAAEukB,YAAcnc,aAChBpI,EAAEwkB,QAAU5f,SACZ5E,EAAEykB,QAAUlhB,SAEZvD,EAAEojB,gBAAkBA,GAEpBpjB,EAAE0kB,gJAWF1kB,EAAE+c,MAAQA,GACVA,GAAMU,WAAWzd,EAAIP,EACrBsd,GAAMU,WAAW1lB,EAAI6H"} \ No newline at end of file diff --git a/y.node.js b/y.node.js new file mode 100644 index 00000000..f01f57a5 --- /dev/null +++ b/y.node.js @@ -0,0 +1,5041 @@ + +/** + * yjs - A framework for real-time p2p shared editing on any data + * @version v13.0.0-55 + * @license MIT + */ + +'use strict'; + +class N { + // A created node is always red! + constructor (val) { + this.val = val; + this.color = true; + this._left = null; + this._right = null; + this._parent = null; + } + isRed () { return this.color } + isBlack () { return !this.color } + redden () { this.color = true; return this } + blacken () { this.color = false; return this } + get grandparent () { + return this.parent.parent + } + get parent () { + return this._parent + } + get sibling () { + return (this === this.parent.left) + ? this.parent.right : this.parent.left + } + get left () { + return this._left + } + get right () { + return this._right + } + set left (n) { + if (n !== null) { + n._parent = this; + } + this._left = n; + } + set right (n) { + if (n !== null) { + n._parent = this; + } + this._right = n; + } + rotateLeft (tree) { + var parent = this.parent; + var newParent = this.right; + var newRight = this.right.left; + newParent.left = this; + this.right = newRight; + if (parent === null) { + tree.root = newParent; + newParent._parent = null; + } else if (parent.left === this) { + parent.left = newParent; + } else if (parent.right === this) { + parent.right = newParent; + } else { + throw new Error('The elements are wrongly connected!') + } + } + next () { + if (this.right !== null) { + // search the most left node in the right tree + var o = this.right; + while (o.left !== null) { + o = o.left; + } + return o + } else { + var p = this; + while (p.parent !== null && p !== p.parent.left) { + p = p.parent; + } + return p.parent + } + } + prev () { + if (this.left !== null) { + // search the most right node in the left tree + var o = this.left; + while (o.right !== null) { + o = o.right; + } + return o + } else { + var p = this; + while (p.parent !== null && p !== p.parent.right) { + p = p.parent; + } + return p.parent + } + } + rotateRight (tree) { + var parent = this.parent; + var newParent = this.left; + var newLeft = this.left.right; + newParent.right = this; + this.left = newLeft; + if (parent === null) { + tree.root = newParent; + newParent._parent = null; + } else if (parent.left === this) { + parent.left = newParent; + } else if (parent.right === this) { + parent.right = newParent; + } else { + throw new Error('The elements are wrongly connected!') + } + } + getUncle () { + // we can assume that grandparent exists when this is called! + if (this.parent === this.parent.parent.left) { + return this.parent.parent.right + } else { + return this.parent.parent.left + } + } +} + +/* + * This is a Red Black Tree implementation + */ +class Tree { + constructor () { + this.root = null; + this.length = 0; + } + findNext (id) { + var nextID = id.clone(); + nextID.clock += 1; + return this.findWithLowerBound(nextID) + } + findPrev (id) { + let prevID = id.clone(); + prevID.clock -= 1; + return this.findWithUpperBound(prevID) + } + findNodeWithLowerBound (from) { + var o = this.root; + if (o === null) { + return null + } else { + while (true) { + if (from === null || (from.lessThan(o.val._id) && o.left !== null)) { + // o is included in the bound + // try to find an element that is closer to the bound + o = o.left; + } else if (from !== null && o.val._id.lessThan(from)) { + // o is not within the bound, maybe one of the right elements is.. + if (o.right !== null) { + o = o.right; + } else { + // there is no right element. Search for the next bigger element, + // this should be within the bounds + return o.next() + } + } else { + return o + } + } + } + } + findNodeWithUpperBound (to) { + if (to === void 0) { + throw new Error('You must define from!') + } + var o = this.root; + if (o === null) { + return null + } else { + while (true) { + if ((to === null || o.val._id.lessThan(to)) && o.right !== null) { + // o is included in the bound + // try to find an element that is closer to the bound + o = o.right; + } else if (to !== null && to.lessThan(o.val._id)) { + // o is not within the bound, maybe one of the left elements is.. + if (o.left !== null) { + o = o.left; + } else { + // there is no left element. Search for the prev smaller element, + // this should be within the bounds + return o.prev() + } + } else { + return o + } + } + } + } + findSmallestNode () { + var o = this.root; + while (o != null && o.left != null) { + o = o.left; + } + return o + } + findWithLowerBound (from) { + var n = this.findNodeWithLowerBound(from); + return n == null ? null : n.val + } + findWithUpperBound (to) { + var n = this.findNodeWithUpperBound(to); + return n == null ? null : n.val + } + iterate (from, to, f) { + var o; + if (from === null) { + o = this.findSmallestNode(); + } else { + o = this.findNodeWithLowerBound(from); + } + while ( + o !== null && + ( + to === null || // eslint-disable-line no-unmodified-loop-condition + o.val._id.lessThan(to) || + o.val._id.equals(to) + ) + ) { + f(o.val); + o = o.next(); + } + } + find (id) { + let n = this.findNode(id); + if (n !== null) { + return n.val + } else { + return null + } + } + findNode (id) { + var o = this.root; + if (o === null) { + return null + } else { + while (true) { + if (o === null) { + return null + } + if (id.lessThan(o.val._id)) { + o = o.left; + } else if (o.val._id.lessThan(id)) { + o = o.right; + } else { + return o + } + } + } + } + delete (id) { + var d = this.findNode(id); + if (d == null) { + // throw new Error('Element does not exist!') + return + } + this.length--; + if (d.left !== null && d.right !== null) { + // switch d with the greates element in the left subtree. + // o should have at most one child. + var o = d.left; + // find + while (o.right !== null) { + o = o.right; + } + // switch + d.val = o.val; + d = o; + } + // d has at most one child + // let n be the node that replaces d + var isFakeChild; + var child = d.left || d.right; + if (child === null) { + isFakeChild = true; + child = new N(null); + child.blacken(); + d.right = child; + } else { + isFakeChild = false; + } + + if (d.parent === null) { + if (!isFakeChild) { + this.root = child; + child.blacken(); + child._parent = null; + } else { + this.root = null; + } + return + } else if (d.parent.left === d) { + d.parent.left = child; + } else if (d.parent.right === d) { + d.parent.right = child; + } else { + throw new Error('Impossible!') + } + if (d.isBlack()) { + if (child.isRed()) { + child.blacken(); + } else { + this._fixDelete(child); + } + } + this.root.blacken(); + if (isFakeChild) { + if (child.parent.left === child) { + child.parent.left = null; + } else if (child.parent.right === child) { + child.parent.right = null; + } else { + throw new Error('Impossible #3') + } + } + } + _fixDelete (n) { + function isBlack (node) { + return node !== null ? node.isBlack() : true + } + function isRed (node) { + return node !== null ? node.isRed() : false + } + if (n.parent === null) { + // this can only be called after the first iteration of fixDelete. + return + } + // d was already replaced by the child + // d is not the root + // d and child are black + var sibling = n.sibling; + if (isRed(sibling)) { + // make sibling the grandfather + n.parent.redden(); + sibling.blacken(); + if (n === n.parent.left) { + n.parent.rotateLeft(this); + } else if (n === n.parent.right) { + n.parent.rotateRight(this); + } else { + throw new Error('Impossible #2') + } + sibling = n.sibling; + } + // parent, sibling, and children of n are black + if (n.parent.isBlack() && + sibling.isBlack() && + isBlack(sibling.left) && + isBlack(sibling.right) + ) { + sibling.redden(); + this._fixDelete(n.parent); + } else if (n.parent.isRed() && + sibling.isBlack() && + isBlack(sibling.left) && + isBlack(sibling.right) + ) { + sibling.redden(); + n.parent.blacken(); + } else { + if (n === n.parent.left && + sibling.isBlack() && + isRed(sibling.left) && + isBlack(sibling.right) + ) { + sibling.redden(); + sibling.left.blacken(); + sibling.rotateRight(this); + sibling = n.sibling; + } else if (n === n.parent.right && + sibling.isBlack() && + isRed(sibling.right) && + isBlack(sibling.left) + ) { + sibling.redden(); + sibling.right.blacken(); + sibling.rotateLeft(this); + sibling = n.sibling; + } + sibling.color = n.parent.color; + n.parent.blacken(); + if (n === n.parent.left) { + sibling.right.blacken(); + n.parent.rotateLeft(this); + } else { + sibling.left.blacken(); + n.parent.rotateRight(this); + } + } + } + put (v) { + var node = new N(v); + if (this.root !== null) { + var p = this.root; // p abbrev. parent + while (true) { + if (node.val._id.lessThan(p.val._id)) { + if (p.left === null) { + p.left = node; + break + } else { + p = p.left; + } + } else if (p.val._id.lessThan(node.val._id)) { + if (p.right === null) { + p.right = node; + break + } else { + p = p.right; + } + } else { + p.val = node.val; + return p + } + } + this._fixInsert(node); + } else { + this.root = node; + } + this.length++; + this.root.blacken(); + return node + } + _fixInsert (n) { + if (n.parent === null) { + n.blacken(); + return + } else if (n.parent.isBlack()) { + return + } + var uncle = n.getUncle(); + if (uncle !== null && uncle.isRed()) { + // Note: parent: red, uncle: red + n.parent.blacken(); + uncle.blacken(); + n.grandparent.redden(); + this._fixInsert(n.grandparent); + } else { + // Note: parent: red, uncle: black or null + // Now we transform the tree in such a way that + // either of these holds: + // 1) grandparent.left.isRed + // and grandparent.left.left.isRed + // 2) grandparent.right.isRed + // and grandparent.right.right.isRed + if (n === n.parent.right && n.parent === n.grandparent.left) { + n.parent.rotateLeft(this); + // Since we rotated and want to use the previous + // cases, we need to set n in such a way that + // n.parent.isRed again + n = n.left; + } else if (n === n.parent.left && n.parent === n.grandparent.right) { + n.parent.rotateRight(this); + // see above + n = n.right; + } + // Case 1) or 2) hold from here on. + // Now traverse grandparent, make parent a black node + // on the highest level which holds two red nodes. + n.parent.blacken(); + n.grandparent.redden(); + if (n === n.parent.left) { + // Case 1 + n.grandparent.rotateRight(this); + } else { + // Case 2 + n.grandparent.rotateLeft(this); + } + } + } + flush () {} +} + +class ID { + constructor (user, clock) { + this.user = user; + this.clock = clock; + } + clone () { + return new ID(this.user, this.clock) + } + equals (id) { + return id !== null && id.user === this.user && id.clock === this.clock + } + lessThan (id) { + if (id.constructor === ID) { + return this.user < id.user || (this.user === id.user && this.clock < id.clock) + } else { + return false + } + } +} + +class DSNode { + constructor (id, len, gc) { + this._id = id; + this.len = len; + this.gc = gc; + } + clone () { + return new DSNode(this._id, this.len, this.gc) + } +} + +class DeleteStore extends Tree { + logTable () { + const deletes = []; + this.iterate(null, null, function (n) { + deletes.push({ + user: n._id.user, + clock: n._id.clock, + len: n.len, + gc: n.gc + }); + }); + console.table(deletes); + } + isDeleted (id) { + var n = this.findWithUpperBound(id); + return n !== null && n._id.user === id.user && id.clock < n._id.clock + n.len + } + /* + * Mark an operation as deleted. returns the deleted node + */ + markDeleted (id, length) { + if (length == null) { + throw new Error('length must be defined') + } + var n = this.findWithUpperBound(id); + if (n != null && n._id.user === id.user) { + if (n._id.clock <= id.clock && id.clock <= n._id.clock + n.len) { + // id is in n's range + var diff = id.clock + length - (n._id.clock + n.len); // overlapping right + if (diff > 0) { + // id+length overlaps n + if (!n.gc) { + n.len += diff; + } else { + diff = n._id.clock + n.len - id.clock; // overlapping left (id till n.end) + if (diff < length) { + // a partial deletion + let nId = id.clone(); + nId.clock += diff; + n = new DSNode(nId, length - diff, false); + this.put(n); + } else { + // already gc'd + throw new Error( + 'DS reached an inconsistent state. Please report this issue!' + ) + } + } + } else { + // no overlapping, already deleted + return n + } + } else { + // cannot extend left (there is no left!) + n = new DSNode(id, length, false); + this.put(n); // TODO: you double-put !! + } + } else { + // cannot extend left + n = new DSNode(id, length, false); + this.put(n); + } + // can extend right? + var next = this.findNext(n._id); + if ( + next != null && + n._id.user === next._id.user && + n._id.clock + n.len >= next._id.clock + ) { + diff = n._id.clock + n.len - next._id.clock; // from next.start to n.end + while (diff >= 0) { + // n overlaps with next + if (next.gc) { + // gc is stronger, so reduce length of n + n.len -= diff; + if (diff >= next.len) { + // delete the missing range after next + diff = diff - next.len; // missing range after next + if (diff > 0) { + this.put(n); // unneccessary? TODO! + this.markDeleted(new ID(next._id.user, next._id.clock + next.len), diff); + } + } + break + } else { + // we can extend n with next + if (diff > next.len) { + // n is even longer than next + // get next.next, and try to extend it + var _next = this.findNext(next._id); + this.delete(next._id); + if (_next == null || n._id.user !== _next._id.user) { + break + } else { + next = _next; + diff = n._id.clock + n.len - next._id.clock; // from next.start to n.end + // continue! + } + } else { + // n just partially overlaps with next. extend n, delete next, and break this loop + n.len += next.len - diff; + this.delete(next._id); + break + } + } + } + } + this.put(n); + return n + } +} + +class BinaryDecoder { + constructor (buffer) { + if (buffer instanceof ArrayBuffer) { + this.uint8arr = new Uint8Array(buffer); + } else if (buffer instanceof Uint8Array || (typeof Buffer !== 'undefined' && buffer instanceof Buffer)) { + this.uint8arr = buffer; + } else { + throw new Error('Expected an ArrayBuffer or Uint8Array!') + } + this.pos = 0; + } + /** + * Clone this decoder instance + * Optionally set a new position parameter + */ + clone (newPos = this.pos) { + let decoder = new BinaryDecoder(this.uint8arr); + decoder.pos = newPos; + return decoder + } + /** + * Number of bytes + */ + get length () { + return this.uint8arr.length + } + /** + * Skip one byte, jump to the next position + */ + skip8 () { + this.pos++; + } + /** + * Read one byte as unsigned integer + */ + readUint8 () { + return this.uint8arr[this.pos++] + } + /** + * Read 4 bytes as unsigned integer + */ + readUint32 () { + let uint = + this.uint8arr[this.pos] + + (this.uint8arr[this.pos + 1] << 8) + + (this.uint8arr[this.pos + 2] << 16) + + (this.uint8arr[this.pos + 3] << 24); + this.pos += 4; + return uint + } + /** + * Look ahead without incrementing position + * to the next byte and read it as unsigned integer + */ + peekUint8 () { + return this.uint8arr[this.pos] + } + /** + * Read unsigned integer (32bit) with variable length + * 1/8th of the storage is used as encoding overhead + * - numbers < 2^7 is stored in one byte + * - numbers < 2^14 is stored in two bytes + * .. + */ + readVarUint () { + let num = 0; + let len = 0; + while (true) { + let r = this.uint8arr[this.pos++]; + num = num | ((r & 0b1111111) << len); + len += 7; + if (r < 1 << 7) { + return num >>> 0 // return unsigned number! + } + if (len > 35) { + throw new Error('Integer out of range!') + } + } + } + /** + * Read string of variable length + * - varUint is used to store the length of the string + */ + readVarString () { + let len = this.readVarUint(); + let bytes = new Array(len); + for (let i = 0; i < len; i++) { + bytes[i] = this.uint8arr[this.pos++]; + } + let encodedString = String.fromCodePoint(...bytes); + return decodeURIComponent(escape(encodedString)) + } + /** + * Look ahead and read varString without incrementing position + */ + peekVarString () { + let pos = this.pos; + let s = this.readVarString(); + this.pos = pos; + return s + } + /** + * Read ID + * - If first varUint read is 0xFFFFFF a RootID is returned + * - Otherwise an ID is returned + */ + readID () { + let user = this.readVarUint(); + if (user === RootFakeUserID) { + // read property name and type id + const rid = new RootID(this.readVarString(), null); + rid.type = this.readVarUint(); + return rid + } + return new ID(user, this.readVarUint()) + } +} + +class MissingEntry { + constructor (decoder, missing, struct) { + this.decoder = decoder; + this.missing = missing.length; + this.struct = struct; + } +} + +/** + * Integrate remote struct + * When a remote struct is integrated, other structs might be ready to ready to + * integrate. + */ +function _integrateRemoteStructHelper (y, struct) { + const id = struct._id; + if (id === undefined) { + struct._integrate(y); + } else { + if (y.ss.getState(id.user) > id.clock) { + return + } + struct._integrate(y); + let msu = y._missingStructs.get(id.user); + if (msu != null) { + let clock = id.clock; + const finalClock = clock + struct._length; + for (;clock < finalClock; clock++) { + const missingStructs = msu.get(clock); + if (missingStructs !== undefined) { + missingStructs.forEach(missingDef => { + missingDef.missing--; + if (missingDef.missing === 0) { + const decoder = missingDef.decoder; + let oldPos = decoder.pos; + let missing = missingDef.struct._fromBinary(y, decoder); + decoder.pos = oldPos; + if (missing.length === 0) { + y._readyToIntegrate.push(missingDef.struct); + } + } + }); + msu.delete(clock); + } + } + } + } +} + +function stringifyStructs (y, decoder, strBuilder) { + const len = decoder.readUint32(); + for (let i = 0; i < len; i++) { + let reference = decoder.readVarUint(); + let Constr = getStruct(reference); + let struct = new Constr(); + let missing = struct._fromBinary(y, decoder); + let logMessage = ' ' + struct._logString(); + if (missing.length > 0) { + logMessage += ' .. missing: ' + missing.map(logID).join(', '); + } + strBuilder.push(logMessage); + } +} + +function integrateRemoteStructs (y, decoder) { + const len = decoder.readUint32(); + for (let i = 0; i < len; i++) { + let reference = decoder.readVarUint(); + let Constr = getStruct(reference); + let struct = new Constr(); + let decoderPos = decoder.pos; + let missing = struct._fromBinary(y, decoder); + if (missing.length === 0) { + while (struct != null) { + _integrateRemoteStructHelper(y, struct); + struct = y._readyToIntegrate.shift(); + } + } else { + let _decoder = new BinaryDecoder(decoder.uint8arr); + _decoder.pos = decoderPos; + let missingEntry = new MissingEntry(_decoder, missing, struct); + let missingStructs = y._missingStructs; + for (let i = missing.length - 1; i >= 0; i--) { + let m = missing[i]; + if (!missingStructs.has(m.user)) { + missingStructs.set(m.user, new Map()); + } + let msu = missingStructs.get(m.user); + if (!msu.has(m.clock)) { + msu.set(m.clock, []); + } + let mArray = msu = msu.get(m.clock); + mArray.push(missingEntry); + } + } + } +} + +const bits7 = 0b1111111; +const bits8 = 0b11111111; + +class BinaryEncoder { + constructor () { + // TODO: implement chained Uint8Array buffers instead of Array buffer + this.data = []; + } + + get length () { + return this.data.length + } + + get pos () { + return this.data.length + } + + createBuffer () { + return Uint8Array.from(this.data).buffer + } + + writeUint8 (num) { + this.data.push(num & bits8); + } + + setUint8 (pos, num) { + this.data[pos] = num & bits8; + } + + writeUint16 (num) { + this.data.push(num & bits8, (num >>> 8) & bits8); + } + + setUint16 (pos, num) { + this.data[pos] = num & bits8; + this.data[pos + 1] = (num >>> 8) & bits8; + } + + writeUint32 (num) { + for (let i = 0; i < 4; i++) { + this.data.push(num & bits8); + num >>>= 8; + } + } + + setUint32 (pos, num) { + for (let i = 0; i < 4; i++) { + this.data[pos + i] = num & bits8; + num >>>= 8; + } + } + + writeVarUint (num) { + while (num >= 0b10000000) { + this.data.push(0b10000000 | (bits7 & num)); + num >>>= 7; + } + this.data.push(bits7 & num); + } + + writeVarString (str) { + let encodedString = unescape(encodeURIComponent(str)); + let bytes = encodedString.split('').map(c => c.codePointAt()); + let len = bytes.length; + this.writeVarUint(len); + for (let i = 0; i < len; i++) { + this.data.push(bytes[i]); + } + } + + writeID (id) { + const user = id.user; + this.writeVarUint(user); + if (user !== RootFakeUserID) { + this.writeVarUint(id.clock); + } else { + this.writeVarString(id.name); + this.writeVarUint(id.type); + } + } +} + +function readStateSet (decoder) { + let ss = new Map(); + let ssLength = decoder.readUint32(); + for (let i = 0; i < ssLength; i++) { + let user = decoder.readVarUint(); + let clock = decoder.readVarUint(); + ss.set(user, clock); + } + return ss +} + +function writeStateSet (y, encoder) { + let lenPosition = encoder.pos; + let len = 0; + encoder.writeUint32(0); + for (let [user, clock] of y.ss.state) { + encoder.writeVarUint(user); + encoder.writeVarUint(clock); + len++; + } + encoder.setUint32(lenPosition, len); +} + +function writeDeleteSet (y, encoder) { + let currentUser = null; + let currentLength; + let lastLenPos; + + let numberOfUsers = 0; + let laterDSLenPus = encoder.pos; + encoder.writeUint32(0); + + y.ds.iterate(null, null, function (n) { + var user = n._id.user; + var clock = n._id.clock; + var len = n.len; + var gc = n.gc; + if (currentUser !== user) { + numberOfUsers++; + // a new user was found + if (currentUser !== null) { // happens on first iteration + encoder.setUint32(lastLenPos, currentLength); + } + currentUser = user; + encoder.writeVarUint(user); + // pseudo-fill pos + lastLenPos = encoder.pos; + encoder.writeUint32(0); + currentLength = 0; + } + encoder.writeVarUint(clock); + encoder.writeVarUint(len); + encoder.writeUint8(gc ? 1 : 0); + currentLength++; + }); + if (currentUser !== null) { // happens on first iteration + encoder.setUint32(lastLenPos, currentLength); + } + encoder.setUint32(laterDSLenPus, numberOfUsers); +} + +function readDeleteSet (y, decoder) { + let dsLength = decoder.readUint32(); + for (let i = 0; i < dsLength; i++) { + let user = decoder.readVarUint(); + let dv = []; + let dvLength = decoder.readUint32(); + for (let j = 0; j < dvLength; j++) { + let from = decoder.readVarUint(); + let len = decoder.readVarUint(); + let gc = decoder.readUint8() === 1; + dv.push([from, len, gc]); + } + if (dvLength > 0) { + let pos = 0; + let d = dv[pos]; + let deletions = []; + y.ds.iterate(new ID(user, 0), new ID(user, Number.MAX_VALUE), function (n) { + // cases: + // 1. d deletes something to the right of n + // => go to next n (break) + // 2. d deletes something to the left of n + // => create deletions + // => reset d accordingly + // *)=> if d doesn't delete anything anymore, go to next d (continue) + // 3. not 2) and d deletes something that also n deletes + // => reset d so that it doesn't contain n's deletion + // *)=> if d does not delete anything anymore, go to next d (continue) + while (d != null) { + var diff = 0; // describe the diff of length in 1) and 2) + if (n._id.clock + n.len <= d[0]) { + // 1) + break + } else if (d[0] < n._id.clock) { + // 2) + // delete maximum the len of d + // else delete as much as possible + diff = Math.min(n._id.clock - d[0], d[1]); + // deleteItemRange(y, user, d[0], diff) + deletions.push([user, d[0], diff]); + } else { + // 3) + diff = n._id.clock + n.len - d[0]; // never null (see 1) + if (d[2] && !n.gc) { + // d marks as gc'd but n does not + // then delete either way + // deleteItemRange(y, user, d[0], Math.min(diff, d[1])) + deletions.push([user, d[0], Math.min(diff, d[1])]); + } + } + if (d[1] <= diff) { + // d doesn't delete anything anymore + d = dv[++pos]; + } else { + d[0] = d[0] + diff; // reset pos + d[1] = d[1] - diff; // reset length + } + } + }); + // TODO: It would be more performant to apply the deletes in the above loop + // Adapt the Tree implementation to support delete while iterating + for (let i = deletions.length - 1; i >= 0; i--) { + const del = deletions[i]; + deleteItemRange(y, del[0], del[1], del[2]); + } + // for the rest.. just apply it + for (; pos < dv.length; pos++) { + d = dv[pos]; + deleteItemRange(y, user, d[0], d[1]); + // deletions.push([user, d[0], d[1], d[2]]) + } + } + } +} + +function stringifySyncStep1 (y, decoder, strBuilder) { + let auth = decoder.readVarString(); + let protocolVersion = decoder.readVarUint(); + strBuilder.push(` - auth: "${auth}"`); + strBuilder.push(` - protocolVersion: ${protocolVersion}`); + // write SS + let ssBuilder = []; + let len = decoder.readUint32(); + for (let i = 0; i < len; i++) { + let user = decoder.readVarUint(); + let clock = decoder.readVarUint(); + ssBuilder.push(`(${user}:${clock})`); + } + strBuilder.push(' == SS: ' + ssBuilder.join(',')); +} + +function sendSyncStep1 (connector, syncUser) { + let encoder = new BinaryEncoder(); + encoder.writeVarString(connector.y.room); + encoder.writeVarString('sync step 1'); + encoder.writeVarString(connector.authInfo || ''); + encoder.writeVarUint(connector.protocolVersion); + writeStateSet(connector.y, encoder); + connector.send(syncUser, encoder.createBuffer()); +} + +function writeStructs (y, encoder, ss) { + const lenPos = encoder.pos; + encoder.writeUint32(0); + let len = 0; + for (let user of y.ss.state.keys()) { + let clock = ss.get(user) || 0; + if (user !== RootFakeUserID) { + y.os.iterate(new ID(user, clock), new ID(user, Number.MAX_VALUE), function (struct) { + struct._toBinary(encoder); + len++; + }); + } + } + encoder.setUint32(lenPos, len); +} + +function readSyncStep1 (decoder, encoder, y, senderConn, sender) { + let protocolVersion = decoder.readVarUint(); + // check protocol version + if (protocolVersion !== y.connector.protocolVersion) { + console.warn( + `You tried to sync with a Yjs instance that has a different protocol version + (You: ${protocolVersion}, Client: ${protocolVersion}). + `); + y.destroy(); + } + // write sync step 2 + encoder.writeVarString('sync step 2'); + encoder.writeVarString(y.connector.authInfo || ''); + const ss = readStateSet(decoder); + writeStructs(y, encoder, ss); + writeDeleteSet(y, encoder); + y.connector.send(senderConn.uid, encoder.createBuffer()); + senderConn.receivedSyncStep2 = true; + if (y.connector.role === 'slave') { + sendSyncStep1(y.connector, sender); + } +} + +function stringifySyncStep2 (y, decoder, strBuilder) { + strBuilder.push(' - auth: ' + decoder.readVarString()); + strBuilder.push(' == OS:'); + stringifyStructs(y, decoder, strBuilder); + // write DS to string + strBuilder.push(' == DS:'); + let len = decoder.readUint32(); + for (let i = 0; i < len; i++) { + let user = decoder.readVarUint(); + strBuilder.push(` User: ${user}: `); + let len2 = decoder.readUint32(); + for (let j = 0; j < len2; j++) { + let from = decoder.readVarUint(); + let to = decoder.readVarUint(); + let gc = decoder.readUint8() === 1; + strBuilder.push(`[${from}, ${to}, ${gc}]`); + } + } +} + +function readSyncStep2 (decoder, encoder, y, senderConn, sender) { + integrateRemoteStructs(y, decoder); + readDeleteSet(y, decoder); + y.connector._setSyncedWith(sender); +} + +function messageToString ([y, buffer]) { + let decoder = new BinaryDecoder(buffer); + decoder.readVarString(); // read roomname + let type = decoder.readVarString(); + let strBuilder = []; + strBuilder.push('\n === ' + type + ' ==='); + if (type === 'update') { + stringifyStructs(y, decoder, strBuilder); + } else if (type === 'sync step 1') { + stringifySyncStep1(y, decoder, strBuilder); + } else if (type === 'sync step 2') { + stringifySyncStep2(y, decoder, strBuilder); + } else { + strBuilder.push('-- Unknown message type - probably an encoding issue!!!'); + } + return strBuilder.join('\n') +} + +function messageToRoomname (buffer) { + let decoder = new BinaryDecoder(buffer); + decoder.readVarString(); // roomname + return decoder.readVarString() // messageType +} + +function logID (id) { + if (id !== null && id._id != null) { + id = id._id; + } + if (id === null) { + return '()' + } else if (id instanceof ID) { + return `(${id.user},${id.clock})` + } else if (id instanceof RootID) { + return `(${id.name},${id.type})` + } else if (id.constructor === Y$1) { + return `y` + } else { + throw new Error('This is not a valid ID!') + } +} + +/** + * Delete all items in an ID-range + * TODO: implement getItemCleanStartNode for better performance (only one lookup) + */ +function deleteItemRange (y, user, clock, range) { + const createDelete = y.connector !== null && y.connector._forwardAppliedStructs; + let item = y.os.getItemCleanStart(new ID(user, clock)); + if (item !== null) { + if (!item._deleted) { + item._splitAt(y, range); + item._delete(y, createDelete); + } + let itemLen = item._length; + range -= itemLen; + clock += itemLen; + if (range > 0) { + let node = y.os.findNode(new ID(user, clock)); + while (node !== null && range > 0 && node.val._id.equals(new ID(user, clock))) { + const nodeVal = node.val; + if (!nodeVal._deleted) { + nodeVal._splitAt(y, range); + nodeVal._delete(y, createDelete); + } + const nodeLen = nodeVal._length; + range -= nodeLen; + clock += nodeLen; + node = node.next(); + } + } + } +} + +/** + * Delete is not a real struct. It will not be saved in OS + */ +class Delete { + constructor () { + this._target = null; + this._length = null; + } + _fromBinary (y, decoder) { + // TODO: set target, and add it to missing if not found + // There is an edge case in p2p networks! + const targetID = decoder.readID(); + this._targetID = targetID; + this._length = decoder.readVarUint(); + if (y.os.getItem(targetID) === null) { + return [targetID] + } else { + return [] + } + } + _toBinary (encoder) { + encoder.writeUint8(getReference(this.constructor)); + encoder.writeID(this._targetID); + encoder.writeVarUint(this._length); + } + /** + * - If created remotely (a remote user deleted something), + * this Delete is applied to all structs in id-range. + * - If created lokally (e.g. when y-array deletes a range of elements), + * this struct is broadcasted only (it is already executed) + */ + _integrate (y, locallyCreated = false) { + if (!locallyCreated) { + // from remote + const id = this._targetID; + deleteItemRange(y, id.user, id.clock, this._length); + } else if (y.connector !== null) { + // from local + y.connector.broadcastStruct(this); + } + if (y.persistence !== null) { + y.persistence.saveStruct(y, this); + } + } + _logString () { + return `Delete - target: ${logID(this._targetID)}, len: ${this._length}` + } +} + +class Transaction { + constructor (y) { + this.y = y; + // types added during transaction + this.newTypes = new Set(); + // changed types (does not include new types) + // maps from type to parentSubs (item._parentSub = null for array elements) + this.changedTypes = new Map(); + this.deletedStructs = new Set(); + this.beforeState = new Map(); + this.changedParentTypes = new Map(); + } +} + +function transactionTypeChanged (y, type, sub) { + if (type !== y && !type._deleted && !y._transaction.newTypes.has(type)) { + const changedTypes = y._transaction.changedTypes; + let subs = changedTypes.get(type); + if (subs === undefined) { + // create if it doesn't exist yet + subs = new Set(); + changedTypes.set(type, subs); + } + subs.add(sub); + } +} + +/** + * Helper utility to split an Item (see _splitAt) + * - copy all properties from a to b + * - connect a to b + * - assigns the correct _id + * - save b to os + */ +function splitHelper (y, a, b, diff) { + const aID = a._id; + b._id = new ID(aID.user, aID.clock + diff); + b._origin = a; + b._left = a; + b._right = a._right; + if (b._right !== null) { + b._right._left = b; + } + b._right_origin = a._right_origin; + // do not set a._right_origin, as this will lead to problems when syncing + a._right = b; + b._parent = a._parent; + b._parentSub = a._parentSub; + b._deleted = a._deleted; + // now search all relevant items to the right and update origin + // if origin is not it foundOrigins, we don't have to search any longer + let foundOrigins = new Set(); + foundOrigins.add(a); + let o = b._right; + while (o !== null && foundOrigins.has(o._origin)) { + if (o._origin === a) { + o._origin = b; + } + foundOrigins.add(o); + o = o._right; + } + y.os.put(b); +} + +class Item { + constructor () { + this._id = null; + this._origin = null; + this._left = null; + this._right = null; + this._right_origin = null; + this._parent = null; + this._parentSub = null; + this._deleted = false; + this._redone = null; + } + /** + * Create a operation with the same effect (without position effect) + */ + _copy () { + return new this.constructor() + } + /** + * Redo the effect of this operation. + */ + _redo (y) { + if (this._redone !== null) { + return this._redone + } + let struct = this._copy(); + let left = this._left; + let right = this; + let parent = this._parent; + // make sure that parent is redone + if (parent._deleted === true && parent._redone === null) { + parent._redo(y); + } + if (parent._redone !== null) { + parent = parent._redone; + // find next cloned items + while (left !== null) { + if (left._redone !== null && left._redone._parent === parent) { + left = left._redone; + break + } + left = left._left; + } + while (right !== null) { + if (right._redone !== null && right._redone._parent === parent) { + right = right._redone; + } + right = right._right; + } + } + struct._origin = left; + struct._left = left; + struct._right = right; + struct._right_origin = right; + struct._parent = parent; + struct._parentSub = this._parentSub; + struct._integrate(y); + this._redone = struct; + return struct + } + + get _lastId () { + return new ID(this._id.user, this._id.clock + this._length - 1) + } + get _length () { + return 1 + } + /** + * Splits this struct so that another struct can be inserted in-between. + * This must be overwritten if _length > 1 + * Returns right part after split + * - diff === 0 => this + * - diff === length => this._right + * - otherwise => split _content and return right part of split + * (see ItemJSON/ItemString for implementation) + */ + _splitAt (y, diff) { + if (diff === 0) { + return this + } + return this._right + } + _delete (y, createDelete = true) { + if (!this._deleted) { + this._deleted = true; + y.ds.markDeleted(this._id, this._length); + let del = new Delete(); + del._targetID = this._id; + del._length = this._length; + if (createDelete) { + // broadcast and persists Delete + del._integrate(y, true); + } else if (y.persistence !== null) { + // only persist Delete + y.persistence.saveStruct(y, del); + } + transactionTypeChanged(y, this._parent, this._parentSub); + y._transaction.deletedStructs.add(this); + } + } + /** + * This is called right before this struct receives any children. + * It can be overwritten to apply pending changes before applying remote changes + */ + _beforeChange () { + // nop + } + /* + * - Integrate the struct so that other types/structs can see it + * - Add this struct to y.os + * - Check if this is struct deleted + */ + _integrate (y) { + y._transaction.newTypes.add(this); + const parent = this._parent; + const selfID = this._id; + const user = selfID === null ? y.userID : selfID.user; + const userState = y.ss.getState(user); + if (selfID === null) { + this._id = y.ss.getNextID(this._length); + } else if (selfID.user === RootFakeUserID) { + // nop + } else if (selfID.clock < userState) { + // already applied.. + return [] + } else if (selfID.clock === userState) { + y.ss.setState(selfID.user, userState + this._length); + } else { + // missing content from user + throw new Error('Can not apply yet!') + } + if (!parent._deleted && !y._transaction.changedTypes.has(parent) && !y._transaction.newTypes.has(parent)) { + // this is the first time parent is updated + // or this types is new + this._parent._beforeChange(); + } + /* + # $this has to find a unique position between origin and the next known character + # case 1: $origin equals $o.origin: the $creator parameter decides if left or right + # let $OL= [o1,o2,o3,o4], whereby $this is to be inserted between o1 and o4 + # o2,o3 and o4 origin is 1 (the position of o2) + # there is the case that $this.creator < o2.creator, but o3.creator < $this.creator + # then o2 knows o3. Since on another client $OL could be [o1,o3,o4] the problem is complex + # therefore $this would be always to the right of o3 + # case 2: $origin < $o.origin + # if current $this insert_position > $o origin: $this ins + # else $insert_position will not change + # (maybe we encounter case 1 later, then this will be to the right of $o) + # case 3: $origin > $o.origin + # $this insert_position is to the left of $o (forever!) + */ + // handle conflicts + let o; + // set o to the first conflicting item + if (this._left !== null) { + o = this._left._right; + } else if (this._parentSub !== null) { + o = this._parent._map.get(this._parentSub) || null; + } else { + o = this._parent._start; + } + let conflictingItems = new Set(); + let itemsBeforeOrigin = new Set(); + // Let c in conflictingItems, b in itemsBeforeOrigin + // ***{origin}bbbb{this}{c,b}{c,b}{o}*** + // Note that conflictingItems is a subset of itemsBeforeOrigin + while (o !== null && o !== this._right) { + itemsBeforeOrigin.add(o); + conflictingItems.add(o); + if (this._origin === o._origin) { + // case 1 + if (o._id.user < this._id.user) { + this._left = o; + conflictingItems.clear(); + } + } else if (itemsBeforeOrigin.has(o._origin)) { + // case 2 + if (!conflictingItems.has(o._origin)) { + this._left = o; + conflictingItems.clear(); + } + } else { + break + } + // TODO: try to use right_origin instead. + // Then you could basically omit conflictingItems! + // Note: you probably can't use right_origin in every case.. only when setting _left + o = o._right; + } + // reconnect left/right + update parent map/start if necessary + const parentSub = this._parentSub; + if (this._left === null) { + let right; + if (parentSub !== null) { + const pmap = parent._map; + right = pmap.get(parentSub) || null; + pmap.set(parentSub, this); + } else { + right = parent._start; + parent._start = this; + } + this._right = right; + if (right !== null) { + right._left = this; + } + } else { + const left = this._left; + const right = left._right; + this._right = right; + left._right = this; + if (right !== null) { + right._left = this; + } + } + if (parent._deleted) { + this._delete(y, false); + } + y.os.put(this); + transactionTypeChanged(y, parent, parentSub); + if (this._id.user !== RootFakeUserID) { + if (y.connector !== null && (y.connector._forwardAppliedStructs || this._id.user === y.userID)) { + y.connector.broadcastStruct(this); + } + if (y.persistence !== null) { + y.persistence.saveStruct(y, this); + } + } + } + _toBinary (encoder) { + encoder.writeUint8(getReference(this.constructor)); + let info = 0; + if (this._origin !== null) { + info += 0b1; // origin is defined + } + // TODO: remove + /* no longer send _left + if (this._left !== this._origin) { + info += 0b10 // do not copy origin to left + } + */ + if (this._right_origin !== null) { + info += 0b100; + } + if (this._parentSub !== null) { + info += 0b1000; + } + encoder.writeUint8(info); + encoder.writeID(this._id); + if (info & 0b1) { + encoder.writeID(this._origin._lastId); + } + // TODO: remove + /* see above + if (info & 0b10) { + encoder.writeID(this._left._lastId) + } + */ + if (info & 0b100) { + encoder.writeID(this._right_origin._id); + } + if ((info & 0b101) === 0) { + // neither origin nor right is defined + encoder.writeID(this._parent._id); + } + if (info & 0b1000) { + encoder.writeVarString(JSON.stringify(this._parentSub)); + } + } + _fromBinary (y, decoder) { + let missing = []; + const info = decoder.readUint8(); + const id = decoder.readID(); + this._id = id; + // read origin + if (info & 0b1) { + // origin != null + const originID = decoder.readID(); + // we have to query for left again because it might have been split/merged.. + const origin = y.os.getItemCleanEnd(originID); + if (origin === null) { + missing.push(originID); + } else { + this._origin = origin; + this._left = this._origin; + } + } + // read right + if (info & 0b100) { + // right != null + const rightID = decoder.readID(); + // we have to query for right again because it might have been split/merged.. + const right = y.os.getItemCleanStart(rightID); + if (right === null) { + missing.push(rightID); + } else { + this._right = right; + this._right_origin = right; + } + } + // read parent + if ((info & 0b101) === 0) { + // neither origin nor right is defined + const parentID = decoder.readID(); + // parent does not change, so we don't have to search for it again + if (this._parent === null) { + const parent = y.os.get(parentID); + if (parent === null) { + missing.push(parentID); + } else { + this._parent = parent; + } + } + } else if (this._parent === null) { + if (this._origin !== null) { + this._parent = this._origin._parent; + } else if (this._right_origin !== null) { + this._parent = this._right_origin._parent; + } + } + if (info & 0b1000) { + // TODO: maybe put this in read parent condition (you can also read parentsub from left/right) + this._parentSub = JSON.parse(decoder.readVarString()); + } + if (y.ss.getState(id.user) < id.clock) { + missing.push(new ID(id.user, id.clock - 1)); + } + return missing + } +} + +class EventHandler { + constructor () { + this.eventListeners = []; + } + destroy () { + this.eventListeners = null; + } + addEventListener (f) { + this.eventListeners.push(f); + } + removeEventListener (f) { + this.eventListeners = this.eventListeners.filter(function (g) { + return f !== g + }); + } + removeAllEventListeners () { + this.eventListeners = []; + } + callEventListeners (transaction, event) { + for (var i = 0; i < this.eventListeners.length; i++) { + try { + const f = this.eventListeners[i]; + f(event); + } catch (e) { + /* + Your observer threw an error. This error was caught so that Yjs + can ensure data consistency! In order to debug this error you + have to check "Pause On Caught Exceptions" in developer tools. + */ + console.error(e); + } + } + } +} + +// restructure children as if they were inserted one after another +function integrateChildren (y, start) { + let right; + do { + right = start._right; + start._right = null; + start._right_origin = null; + start._origin = start._left; + start._integrate(y); + start = right; + } while (right !== null) +} + + + +class Type extends Item { + constructor () { + super(); + this._map = new Map(); + this._start = null; + this._y = null; + this._eventHandler = new EventHandler(); + this._deepEventHandler = new EventHandler(); + } + getPathTo (type) { + if (type === this) { + return [] + } + const path = []; + const y = this._y; + while (type._parent !== this && this._parent !== y) { + let parent = type._parent; + if (type._parentSub !== null) { + path.push(type._parentSub); + } else { + // parent is array-ish + for (let [i, child] of parent) { + if (child === type) { + path.push(i); + break + } + } + } + type = parent; + } + if (this._parent !== this) { + throw new Error('The type is not a child of this node') + } + return path + } + _callEventHandler (transaction, event) { + const changedParentTypes = transaction.changedParentTypes; + this._eventHandler.callEventListeners(transaction, event); + let type = this; + while (type !== this._y) { + let events = changedParentTypes.get(type); + if (events === undefined) { + events = []; + changedParentTypes.set(type, events); + } + events.push(event); + type = type._parent; + } + } + _transact (f) { + const y = this._y; + if (y !== null) { + y.transact(f); + } else { + f(y); + } + } + observe (f) { + this._eventHandler.addEventListener(f); + } + observeDeep (f) { + this._deepEventHandler.addEventListener(f); + } + unobserve (f) { + this._eventHandler.removeEventListener(f); + } + unobserveDeep (f) { + this._deepEventHandler.removeEventListener(f); + } + _integrate (y) { + super._integrate(y); + this._y = y; + // when integrating children we must make sure to + // integrate start + const start = this._start; + if (start !== null) { + this._start = null; + integrateChildren(y, start); + } + // integrate map children + const map = this._map; + this._map = new Map(); + for (let t of map.values()) { + // TODO make sure that right elements are deleted! + integrateChildren(y, t); + } + } + _delete (y, createDelete) { + super._delete(y, createDelete); + y._transaction.changedTypes.delete(this); + // delete map types + for (let value of this._map.values()) { + if (value instanceof Item && !value._deleted) { + value._delete(y, false); + } + } + // delete array types + let t = this._start; + while (t !== null) { + if (!t._deleted) { + t._delete(y, false); + } + t = t._right; + } + } +} + +class ItemJSON extends Item { + constructor () { + super(); + this._content = null; + } + _copy () { + let struct = super._copy(); + struct._content = this._content; + return struct + } + get _length () { + return this._content.length + } + _fromBinary (y, decoder) { + let missing = super._fromBinary(y, decoder); + let len = decoder.readVarUint(); + this._content = new Array(len); + for (let i = 0; i < len; i++) { + const ctnt = decoder.readVarString(); + let parsed; + if (ctnt === 'undefined') { + parsed = undefined; + } else { + parsed = JSON.parse(ctnt); + } + this._content[i] = parsed; + } + return missing + } + _toBinary (encoder) { + super._toBinary(encoder); + let len = this._content.length; + encoder.writeVarUint(len); + for (let i = 0; i < len; i++) { + let encoded; + let content = this._content[i]; + if (content === undefined) { + encoded = 'undefined'; + } else { + encoded = JSON.stringify(content); + } + encoder.writeVarString(encoded); + } + } + _logString () { + const left = this._left !== null ? this._left._lastId : null; + const origin = this._origin !== null ? this._origin._lastId : null; + return `ItemJSON(id:${logID(this._id)},content:${JSON.stringify(this._content)},left:${logID(left)},origin:${logID(origin)},right:${logID(this._right)},parent:${logID(this._parent)},parentSub:${this._parentSub})` + } + _splitAt (y, diff) { + if (diff === 0) { + return this + } else if (diff >= this._length) { + return this._right + } + let item = new ItemJSON(); + item._content = this._content.splice(diff); + splitHelper(y, this, item, diff); + return item + } +} + +class ItemString extends Item { + constructor () { + super(); + this._content = null; + } + _copy () { + let struct = super._copy(); + struct._content = this._content; + return struct + } + get _length () { + return this._content.length + } + _fromBinary (y, decoder) { + let missing = super._fromBinary(y, decoder); + this._content = decoder.readVarString(); + return missing + } + _toBinary (encoder) { + super._toBinary(encoder); + encoder.writeVarString(this._content); + } + _logString () { + const left = this._left !== null ? this._left._lastId : null; + const origin = this._origin !== null ? this._origin._lastId : null; + return `ItemJSON(id:${logID(this._id)},content:${JSON.stringify(this._content)},left:${logID(left)},origin:${logID(origin)},right:${logID(this._right)},parent:${logID(this._parent)},parentSub:${this._parentSub})` + } + _splitAt (y, diff) { + if (diff === 0) { + return this + } else if (diff >= this._length) { + return this._right + } + let item = new ItemString(); + item._content = this._content.slice(diff); + this._content = this._content.slice(0, diff); + splitHelper(y, this, item, diff); + return item + } +} + +class YEvent { + constructor (target) { + this.target = target; + this.currentTarget = target; + } + get path () { + const path = []; + let type = this.target; + const y = type._y; + while (type !== this.currentTarget && type !== y) { + let parent = type._parent; + if (type._parentSub !== null) { + path.unshift(type._parentSub); + } else { + // parent is array-ish + for (let [i, child] of parent) { + if (child === type) { + path.unshift(i); + break + } + } + } + type = parent; + } + return path + } +} + +class YArrayEvent extends YEvent { + constructor (yarray, remote, transaction) { + super(yarray); + this.remote = remote; + this._transaction = transaction; + this._addedElements = null; + } + get addedElements () { + if (this._addedElements === null) { + const target = this.target; + const transaction = this._transaction; + const addedElements = new Set(); + transaction.newTypes.forEach(function (type) { + if (type._parent === target && !transaction.deletedStructs.has(type)) { + addedElements.add(type); + } + }); + this._addedElements = addedElements; + } + return this._addedElements + } + get removedElements () { + const target = this.target; + const transaction = this._transaction; + const removedElements = new Set(); + transaction.deletedStructs.forEach(function (struct) { + if (struct._parent === target && !transaction.newTypes.has(struct)) { + removedElements.add(struct); + } + }); + return removedElements + } +} + +class YArray extends Type { + _callObserver (transaction, parentSubs, remote) { + this._callEventHandler(transaction, new YArrayEvent(this, remote, transaction)); + } + get (pos) { + let n = this._start; + while (n !== null) { + if (!n._deleted) { + if (pos < n._length) { + if (n.constructor === ItemJSON || n.constructor === ItemString) { + return n._content[pos] + } else { + return n + } + } + pos -= n._length; + } + n = n._right; + } + } + toArray () { + return this.map(c => c) + } + toJSON () { + return this.map(c => { + if (c instanceof Type) { + if (c.toJSON !== null) { + return c.toJSON() + } else { + return c.toString() + } + } + return c + }) + } + map (f) { + const res = []; + this.forEach((c, i) => { + res.push(f(c, i, this)); + }); + return res + } + forEach (f) { + let pos = 0; + let n = this._start; + while (n !== null) { + if (!n._deleted) { + if (n instanceof Type) { + f(n, pos++, this); + } else { + const content = n._content; + const contentLen = content.length; + for (let i = 0; i < contentLen; i++) { + pos++; + f(content[i], pos, this); + } + } + } + n = n._right; + } + } + get length () { + let length = 0; + let n = this._start; + while (n !== null) { + if (!n._deleted) { + length += n._length; + } + n = n._right; + } + return length + } + [Symbol.iterator] () { + return { + next: function () { + while (this._item !== null && (this._item._deleted || this._item._length <= this._itemElement)) { + // item is deleted or itemElement does not exist (is deleted) + this._item = this._item._right; + this._itemElement = 0; + } + if (this._item === null) { + return { + done: true + } + } + let content; + if (this._item instanceof Type) { + content = this._item; + } else { + content = this._item._content[this._itemElement++]; + } + return { + value: [this._count, content], + done: false + } + }, + _item: this._start, + _itemElement: 0, + _count: 0 + } + } + delete (pos, length = 1) { + this._y.transact(() => { + let item = this._start; + let count = 0; + while (item !== null && length > 0) { + if (!item._deleted) { + if (count <= pos && pos < count + item._length) { + const diffDel = pos - count; + item = item._splitAt(this._y, diffDel); + item._splitAt(this._y, length); + length -= item._length; + item._delete(this._y); + count += diffDel; + } else { + count += item._length; + } + } + item = item._right; + } + }); + if (length > 0) { + throw new Error('Delete exceeds the range of the YArray') + } + } + insertAfter (left, content) { + this._transact(y => { + let right; + if (left === null) { + right = this._start; + } else { + right = left._right; + } + let prevJsonIns = null; + for (let i = 0; i < content.length; i++) { + let c = content[i]; + if (typeof c === 'function') { + c = new c(); // eslint-disable-line new-cap + } + if (c instanceof Type) { + if (prevJsonIns !== null) { + if (y !== null) { + prevJsonIns._integrate(y); + } + left = prevJsonIns; + prevJsonIns = null; + } + c._origin = left; + c._left = left; + c._right = right; + c._right_origin = right; + c._parent = this; + if (y !== null) { + c._integrate(y); + } else if (left === null) { + this._start = c; + } else { + left._right = c; + } + left = c; + } else { + if (prevJsonIns === null) { + prevJsonIns = new ItemJSON(); + prevJsonIns._origin = left; + prevJsonIns._left = left; + prevJsonIns._right = right; + prevJsonIns._right_origin = right; + prevJsonIns._parent = this; + prevJsonIns._content = []; + } + prevJsonIns._content.push(c); + } + } + if (prevJsonIns !== null) { + if (y !== null) { + prevJsonIns._integrate(y); + } else if (prevJsonIns._left === null) { + this._start = prevJsonIns; + } + } + }); + } + insert (pos, content) { + let left = null; + let right = this._start; + let count = 0; + const y = this._y; + while (right !== null) { + const rightLen = right._deleted ? 0 : (right._length - 1); + if (count <= pos && pos <= count + rightLen) { + const splitDiff = pos - count; + right = right._splitAt(y, splitDiff); + left = right._left; + count += splitDiff; + break + } + if (!right._deleted) { + count += right._length; + } + left = right; + right = right._right; + } + if (pos > count) { + throw new Error('Position exceeds array range!') + } + this.insertAfter(left, content); + } + push (content) { + let n = this._start; + let lastUndeleted = null; + while (n !== null) { + if (!n._deleted) { + lastUndeleted = n; + } + n = n._right; + } + this.insertAfter(lastUndeleted, content); + } + _logString () { + const left = this._left !== null ? this._left._lastId : null; + const origin = this._origin !== null ? this._origin._lastId : null; + return `YArray(id:${logID(this._id)},start:${logID(this._start)},left:${logID(left)},origin:${logID(origin)},right:${logID(this._right)},parent:${logID(this._parent)},parentSub:${this._parentSub})` + } +} + +class YMapEvent extends YEvent { + constructor (ymap, subs, remote) { + super(ymap); + this.keysChanged = subs; + this.remote = remote; + } +} + +class YMap extends Type { + _callObserver (transaction, parentSubs, remote) { + this._callEventHandler(transaction, new YMapEvent(this, parentSubs, remote)); + } + toJSON () { + const map = {}; + for (let [key, item] of this._map) { + if (!item._deleted) { + let res; + if (item instanceof Type) { + if (item.toJSON !== undefined) { + res = item.toJSON(); + } else { + res = item.toString(); + } + } else { + res = item._content[0]; + } + map[key] = res; + } + } + return map + } + keys () { + let keys = []; + for (let [key, value] of this._map) { + if (!value._deleted) { + keys.push(key); + } + } + return keys + } + delete (key) { + this._transact((y) => { + let c = this._map.get(key); + if (y !== null && c !== undefined) { + c._delete(y); + } + }); + } + set (key, value) { + this._transact(y => { + const old = this._map.get(key) || null; + if (old !== null) { + if (old.constructor === ItemJSON && !old._deleted && old._content[0] === value) { + // Trying to overwrite with same value + // break here + return value + } + if (y !== null) { + old._delete(y); + } + } + let v; + if (typeof value === 'function') { + v = new value(); // eslint-disable-line new-cap + value = v; + } else if (value instanceof Item) { + v = value; + } else { + v = new ItemJSON(); + v._content = [value]; + } + v._right = old; + v._right_origin = old; + v._parent = this; + v._parentSub = key; + if (y !== null) { + v._integrate(y); + } else { + this._map.set(key, v); + } + }); + return value + } + get (key) { + let v = this._map.get(key); + if (v === undefined || v._deleted) { + return undefined + } + if (v instanceof Type) { + return v + } else { + return v._content[v._content.length - 1] + } + } + has (key) { + let v = this._map.get(key); + if (v === undefined || v._deleted) { + return false + } else { + return true + } + } + _logString () { + const left = this._left !== null ? this._left._lastId : null; + const origin = this._origin !== null ? this._origin._lastId : null; + return `YMap(id:${logID(this._id)},mapSize:${this._map.size},left:${logID(left)},origin:${logID(origin)},right:${logID(this._right)},parent:${logID(this._parent)},parentSub:${this._parentSub})` + } +} + +class YText extends YArray { + constructor (string) { + super(); + if (typeof string === 'string') { + const start = new ItemString(); + start._parent = this; + start._content = string; + this._start = start; + } + } + toString () { + const strBuilder = []; + let n = this._start; + while (n !== null) { + if (!n._deleted) { + strBuilder.push(n._content); + } + n = n._right; + } + return strBuilder.join('') + } + insert (pos, text) { + if (text.length <= 0) { + return + } + this._transact(y => { + let left = null; + let right = this._start; + let count = 0; + while (right !== null) { + const rightLen = right._deleted ? 0 : (right._length - 1); + if (count <= pos && pos <= count + rightLen) { + const splitDiff = pos - count; + right = right._splitAt(this._y, splitDiff); + left = right._left; + count += splitDiff; + break + } + if (!right._deleted) { + count += right._length; + } + left = right; + right = right._right; + } + if (pos > count) { + throw new Error('Position exceeds array range!') + } + let item = new ItemString(); + item._origin = left; + item._left = left; + item._right = right; + item._right_origin = right; + item._parent = this; + item._content = text; + if (y !== null) { + item._integrate(this._y); + } else if (left === null) { + this._start = item; + } else { + left._right = item; + } + }); + } + _logString () { + const left = this._left !== null ? this._left._lastId : null; + const origin = this._origin !== null ? this._origin._lastId : null; + return `YText(id:${logID(this._id)},start:${logID(this._start)},left:${logID(left)},origin:${logID(origin)},right:${logID(this._right)},parent:${logID(this._parent)},parentSub:${this._parentSub})` + } +} + +function defaultDomFilter (node, attributes) { + return attributes +} + + + +// get BoundingClientRect that works on text nodes + + + + +function iterateUntilUndeleted (item) { + while (item !== null && item._deleted) { + item = item._right; + } + return item +} + +function _insertNodeHelper (yxml, prevExpectedNode, child) { + let insertedNodes = yxml.insertDomElementsAfter(prevExpectedNode, [child]); + if (insertedNodes.length > 0) { + return insertedNodes[0] + } else { + return prevExpectedNode + } +} + +/* + * 1. Check if any of the nodes was deleted + * 2. Iterate over the children. + * 2.1 If a node exists without _yxml property, insert a new node + * 2.2 If _contents.length < dom.childNodes.length, fill the + * rest of _content with childNodes + * 2.3 If a node was moved, delete it and + * recreate a new yxml element that is bound to that node. + * You can detect that a node was moved because expectedId + * !== actualId in the list + */ +function applyChangesFromDom (dom) { + const yxml = dom._yxml; + if (yxml.constructor === YXmlHook) { + return + } + const y = yxml._y; + let knownChildren = + new Set( + Array.prototype.map.call(dom.childNodes, child => child._yxml) + .filter(id => id !== undefined) + ); + // 1. Check if any of the nodes was deleted + yxml.forEach(function (childType, i) { + if (!knownChildren.has(childType)) { + childType._delete(y); + } + }); + // 2. iterate + let childNodes = dom.childNodes; + let len = childNodes.length; + let prevExpectedNode = null; + let expectedNode = iterateUntilUndeleted(yxml._start); + for (let domCnt = 0; domCnt < len; domCnt++) { + const child = childNodes[domCnt]; + const childYXml = child._yxml; + if (childYXml != null) { + if (childYXml === false) { + // should be ignored or is going to be deleted + continue + } + if (expectedNode !== null) { + if (expectedNode !== childYXml) { + // 2.3 Not expected node + if (childYXml._parent !== this) { + // element is going to be deleted by its previous parent + child._yxml = null; + } else { + childYXml._delete(y); + } + prevExpectedNode = _insertNodeHelper(yxml, prevExpectedNode, child); + } else { + prevExpectedNode = expectedNode; + expectedNode = iterateUntilUndeleted(expectedNode._right); + } + // if this is the expected node id, just continue + } else { + // 2.2 fill _conten with child nodes + prevExpectedNode = _insertNodeHelper(yxml, prevExpectedNode, child); + } + } else { + // 2.1 A new node was found + prevExpectedNode = _insertNodeHelper(yxml, prevExpectedNode, child); + } + } +} + +function reflectChangesOnDom (events, _document) { + // Make sure that no filtered attributes are applied to the structure + // if they were, delete them + /* + events.forEach(event => { + const target = event.target + if (event.attributesChanged === undefined) { + // event.target is Y.XmlText + return + } + const keys = this._domFilter(target.nodeName, Array.from(event.attributesChanged)) + if (keys === null) { + target._delete() + } else { + const removeKeys = new Set() // is a copy of event.attributesChanged + event.attributesChanged.forEach(key => { removeKeys.add(key) }) + keys.forEach(key => { + // remove all accepted keys from removeKeys + removeKeys.delete(key) + }) + // remove the filtered attribute + removeKeys.forEach(key => { + target.removeAttribute(key) + }) + } + }) + */ + this._mutualExclude(() => { + events.forEach(event => { + const yxml = event.target; + const dom = yxml._dom; + if (dom != null) { + // TODO: do this once before applying stuff + // let anchorViewPosition = getAnchorViewPosition(yxml._scrollElement) + if (yxml.constructor === YXmlText) { + yxml._dom.nodeValue = yxml.toString(); + } else if (event.attributesChanged !== undefined) { + // update attributes + event.attributesChanged.forEach(attributeName => { + const value = yxml.getAttribute(attributeName); + if (value === undefined) { + dom.removeAttribute(attributeName); + } else { + dom.setAttribute(attributeName, value); + } + }); + /** + * TODO: instead of chard-checking the types, it would be best to + * specify the type's features. E.g. + * - _yxmlHasAttributes + * - _yxmlHasChildren + * Furthermore, the features shouldn't be encoded in the types, + * only in the attributes (above) + */ + if (event.childListChanged && yxml.constructor !== YXmlHook) { + let currentChild = dom.firstChild; + yxml.forEach(function (t) { + let expectedChild = t.getDom(_document); + if (expectedChild.parentNode === dom) { + // is already attached to the dom. Look for it + while (currentChild !== expectedChild) { + let del = currentChild; + currentChild = currentChild.nextSibling; + dom.removeChild(del); + } + currentChild = currentChild.nextSibling; + } else { + // this dom is not yet attached to dom + dom.insertBefore(expectedChild, currentChild); + } + }); + while (currentChild !== null) { + let tmp = currentChild.nextSibling; + dom.removeChild(currentChild); + currentChild = tmp; + } + } + } + /* TODO: smartscrolling + .. else if (event.type === 'childInserted' || event.type === 'insert') { + let nodes = event.values + for (let i = nodes.length - 1; i >= 0; i--) { + let node = nodes[i] + node.setDomFilter(yxml._domFilter) + node.enableSmartScrolling(yxml._scrollElement) + let dom = node.getDom() + let fixPosition = null + let nextDom = null + if (yxml._content.length > event.index + i + 1) { + nextDom = yxml.get(event.index + i + 1).getDom() + } + yxml._dom.insertBefore(dom, nextDom) + if (anchorViewPosition === null) { + // nop + } else if (anchorViewPosition.anchor !== null) { + // no scrolling when current selection + if (!dom.contains(anchorViewPosition.anchor) && !anchorViewPosition.anchor.contains(dom)) { + fixPosition = anchorViewPosition + } + } else if (getBoundingClientRect(dom).top <= 0) { + // adjust scrolling if modified element is out of view, + // there is no anchor element, and the browser did not adjust scrollTop (this is checked later) + fixPosition = anchorViewPosition + } + fixScrollPosition(yxml._scrollElement, fixPosition) + } + } else if (event.type === 'childRemoved' || event.type === 'delete') { + for (let i = event.values.length - 1; i >= 0; i--) { + let dom = event.values[i]._dom + let fixPosition = null + if (anchorViewPosition === null) { + // nop + } else if (anchorViewPosition.anchor !== null) { + // no scrolling when current selection + if (!dom.contains(anchorViewPosition.anchor) && !anchorViewPosition.anchor.contains(dom)) { + fixPosition = anchorViewPosition + } + } else if (getBoundingClientRect(dom).top <= 0) { + // adjust scrolling if modified element is out of view, + // there is no anchor element, and the browser did not adjust scrollTop (this is checked later) + fixPosition = anchorViewPosition + } + dom.remove() + fixScrollPosition(yxml._scrollElement, fixPosition) + } + } + */ + } + }); + }); +} + +function getRelativePosition (type, offset) { + let t = type._start; + while (t !== null) { + if (t._deleted === false) { + if (t._length > offset) { + return [t._id.user, t._id.clock + offset] + } + offset -= t._length; + } + t = t._right; + } + return ['endof', type._id.user, type._id.clock || null, type._id.name || null, type._id.type || null] +} + +function fromRelativePosition (y, rpos) { + if (rpos[0] === 'endof') { + let id; + if (rpos[3] === null) { + id = new ID(rpos[1], rpos[2]); + } else { + id = new RootID(rpos[3], rpos[4]); + } + const type = y.os.get(id); + return { + type, + offset: type.length + } + } else { + let offset = 0; + let struct = y.os.findNodeWithUpperBound(new ID(rpos[0], rpos[1])).val; + const parent = struct._parent; + if (parent._deleted) { + return null + } + if (!struct._deleted) { + offset = rpos[1] - struct._id.clock; + } + struct = struct._left; + while (struct !== null) { + if (!struct._deleted) { + offset += struct._length; + } + struct = struct._left; + } + return { + type: parent, + offset: offset + } + } +} + +/* globals getSelection */ + +let browserSelection = null; +let relativeSelection = null; + +let beforeTransactionSelectionFixer; +if (typeof getSelection !== 'undefined') { + beforeTransactionSelectionFixer = function _beforeTransactionSelectionFixer (y, transaction, remote) { + if (!remote) { + return + } + relativeSelection = { from: null, to: null, fromY: null, toY: null }; + browserSelection = getSelection(); + const anchorNode = browserSelection.anchorNode; + if (anchorNode !== null && anchorNode._yxml != null) { + const yxml = anchorNode._yxml; + relativeSelection.from = getRelativePosition(yxml, browserSelection.anchorOffset); + relativeSelection.fromY = yxml._y; + } + const focusNode = browserSelection.focusNode; + if (focusNode !== null && focusNode._yxml != null) { + const yxml = focusNode._yxml; + relativeSelection.to = getRelativePosition(yxml, browserSelection.focusOffset); + relativeSelection.toY = yxml._y; + } + }; +} else { + beforeTransactionSelectionFixer = function _fakeBeforeTransactionSelectionFixer () {}; +} + +function afterTransactionSelectionFixer (y, transaction, remote) { + if (relativeSelection === null || !remote) { + return + } + const to = relativeSelection.to; + const from = relativeSelection.from; + const fromY = relativeSelection.fromY; + const toY = relativeSelection.toY; + let shouldUpdate = false; + let anchorNode = browserSelection.anchorNode; + let anchorOffset = browserSelection.anchorOffset; + let focusNode = browserSelection.focusNode; + let focusOffset = browserSelection.focusOffset; + if (from !== null) { + let sel = fromRelativePosition(fromY, from); + if (sel !== null) { + let node = sel.type.getDom(); + let offset = sel.offset; + if (node !== anchorNode || offset !== anchorOffset) { + anchorNode = node; + anchorOffset = offset; + shouldUpdate = true; + } + } + } + if (to !== null) { + let sel = fromRelativePosition(toY, to); + if (sel !== null) { + let node = sel.type.getDom(); + let offset = sel.offset; + if (node !== focusNode || offset !== focusOffset) { + focusNode = node; + focusOffset = offset; + shouldUpdate = true; + } + } + } + if (shouldUpdate) { + browserSelection.setBaseAndExtent( + anchorNode, + anchorOffset, + focusNode, + focusOffset + ); + } +} + +class YXmlEvent extends YEvent { + constructor (target, subs, remote) { + super(target); + this.childListChanged = false; + this.attributesChanged = new Set(); + this.remote = remote; + subs.forEach((sub) => { + if (sub === null) { + this.childListChanged = true; + } else { + this.attributesChanged.add(sub); + } + }); + } +} + +function simpleDiff (a, b) { + let left = 0; // number of same characters counting from left + let right = 0; // number of same characters counting from right + while (left < a.length && left < b.length && a[left] === b[left]) { + left++; + } + if (left !== a.length || left !== b.length) { + // Only check right if a !== b + while (right + left < a.length && right + left < b.length && a[a.length - right - 1] === b[b.length - right - 1]) { + right++; + } + } + return { + pos: left, + remove: a.length - left - right, + insert: b.slice(left, b.length - right) + } +} + +/* global MutationObserver */ + +function domToYXml (parent, doms, _document) { + const types = []; + doms.forEach(d => { + if (d._yxml != null && d._yxml !== false) { + d._yxml._unbindFromDom(); + } + if (parent._domFilter(d.nodeName, new Map()) !== null) { + let type; + const hookName = d._yjsHook || (d.dataset != null ? d.dataset.yjsHook : undefined); + if (hookName !== undefined) { + type = new YXmlHook(hookName, d); + } else if (d.nodeType === d.TEXT_NODE) { + type = new YXmlText(d); + } else if (d.nodeType === d.ELEMENT_NODE) { + type = new YXmlFragment._YXmlElement(d, parent._domFilter, _document); + } else { + throw new Error('Unsupported node!') + } + // type.enableSmartScrolling(parent._scrollElement) + types.push(type); + } else { + d._yxml = false; + } + }); + return types +} + +class YXmlTreeWalker { + constructor (root, f) { + this._filter = f || (() => true); + this._root = root; + this._currentNode = root; + this._firstCall = true; + } + [Symbol.iterator] () { + return this + } + next () { + let n = this._currentNode; + if (this._firstCall) { + this._firstCall = false; + if (!n._deleted && this._filter(n)) { + return { value: n, done: false } + } + } + do { + if (!n._deleted && (n.constructor === YXmlFragment._YXmlElement || n.constructor === YXmlFragment) && n._start !== null) { + // walk down in the tree + n = n._start; + } else { + // walk right or up in the tree + while (n !== this._root) { + if (n._right !== null) { + n = n._right; + break + } + n = n._parent; + } + if (n === this._root) { + n = null; + } + } + if (n === this._root) { + break + } + } while (n !== null && (n._deleted || !this._filter(n))) + this._currentNode = n; + if (n === null) { + return { done: true } + } else { + return { value: n, done: false } + } + } +} + +class YXmlFragment extends YArray { + constructor () { + super(); + this._dom = null; + this._domFilter = defaultDomFilter; + this._domObserver = null; + // this function makes sure that either the + // dom event is executed, or the yjs observer is executed + var token = true; + this._mutualExclude = f => { + if (token) { + token = false; + try { + f(); + } catch (e) { + console.error(e); + } + /* + if (this._domObserver !== null) { + this._domObserver.takeRecords() + } + */ + token = true; + } + }; + } + createTreeWalker (filter) { + return new YXmlTreeWalker(this, filter) + } + /** + * Retrieve first element that matches *query* + * Similar to DOM's querySelector, but only accepts a subset of its queries + * + * Query support: + * - tagname + * TODO: + * - id + * - attribute + */ + querySelector (query) { + query = query.toUpperCase(); + const iterator = new YXmlTreeWalker(this, element => element.nodeName === query); + const next = iterator.next(); + if (next.done) { + return null + } else { + return next.value + } + } + querySelectorAll (query) { + query = query.toUpperCase(); + return Array.from(new YXmlTreeWalker(this, element => element.nodeName === query)) + } + enableSmartScrolling (scrollElement) { + this._scrollElement = scrollElement; + this.forEach(xml => { + xml.enableSmartScrolling(scrollElement); + }); + } + setDomFilter (f) { + this._domFilter = f; + let attributes = new Map(); + if (this.getAttributes !== undefined) { + let attrs = this.getAttributes(); + for (let key in attrs) { + attributes.set(key, attrs[key]); + } + } + this._y.transact(() => { + let result = this._domFilter(this.nodeName, new Map(attributes)); + if (result === null) { + this._delete(this._y); + } else { + attributes.forEach((value, key) => { + if (!result.has(key)) { + this.removeAttribute(key); + } + }); + } + this.forEach(xml => { + xml.setDomFilter(f); + }); + }); + } + _callObserver (transaction, parentSubs, remote) { + this._callEventHandler(transaction, new YXmlEvent(this, parentSubs, remote)); + } + toString () { + return this.map(xml => xml.toString()).join('') + } + _delete (y, createDelete) { + this._unbindFromDom(); + super._delete(y, createDelete); + } + _unbindFromDom () { + if (this._domObserver != null) { + this._domObserver.disconnect(); + this._domObserver = null; + } + if (this._dom != null) { + this._dom._yxml = null; + this._dom = null; + } + if (this._beforeTransactionHandler !== undefined) { + this._y.off('beforeTransaction', this._beforeTransactionHandler); + } + } + insertDomElementsAfter (prev, doms, _document) { + const types = domToYXml(this, doms, _document); + this.insertAfter(prev, types); + return types + } + insertDomElements (pos, doms, _document) { + const types = domToYXml(this, doms, _document); + this.insert(pos, types); + return types + } + getDom () { + return this._dom + } + bindToDom (dom, _document) { + if (this._dom != null) { + this._unbindFromDom(); + } + if (dom._yxml != null) { + dom._yxml._unbindFromDom(); + } + dom.innerHTML = ''; + this.forEach(t => { + dom.insertBefore(t.getDom(_document), null); + }); + this._bindToDom(dom, _document); + } + // binds to a dom element + // Only call if dom and YXml are isomorph + _bindToDom (dom, _document) { + _document = _document || document; + this._dom = dom; + dom._yxml = this; + if (this._parent === null) { + return + } + this._y.on('beforeTransaction', beforeTransactionSelectionFixer); + this._y.on('afterTransaction', afterTransactionSelectionFixer); + const applyFilter = (type) => { + if (type._deleted) { + return + } + // check if type is a child of this + let isChild = false; + let p = type; + while (p !== this._y) { + if (p === this) { + isChild = true; + break + } + p = p._parent; + } + if (!isChild) { + return + } + // filter attributes + let attributes = new Map(); + if (type.getAttributes !== undefined) { + let attrs = type.getAttributes(); + for (let key in attrs) { + attributes.set(key, attrs[key]); + } + } + let result = this._domFilter(type.nodeName, new Map(attributes)); + if (result === null) { + type._delete(this._y); + } else { + attributes.forEach((value, key) => { + if (!result.has(key)) { + type.removeAttribute(key); + } + }); + } + }; + this._y.on('beforeObserverCalls', function (y, transaction) { + // apply dom filter to new and changed types + transaction.changedTypes.forEach(function (subs, type) { + if (subs.size > 1 || !subs.has(null)) { + // only apply changes on attributes + applyFilter(type); + } + }); + transaction.newTypes.forEach(applyFilter); + }); + // Apply Y.Xml events to dom + this.observeDeep(events => { + reflectChangesOnDom.call(this, events, _document); + }); + // Apply Dom changes on Y.Xml + if (typeof MutationObserver !== 'undefined') { + this._beforeTransactionHandler = () => { + this._domObserverListener(this._domObserver.takeRecords()); + }; + this._y.on('beforeTransaction', this._beforeTransactionHandler); + this._domObserverListener = mutations => { + this._mutualExclude(() => { + this._y.transact(() => { + let diffChildren = new Set(); + mutations.forEach(mutation => { + const dom = mutation.target; + const yxml = dom._yxml; + if (yxml == null || yxml.constructor === YXmlHook) { + // dom element is filtered + return + } + switch (mutation.type) { + case 'characterData': + var change = simpleDiff(yxml.toString(), dom.nodeValue); + yxml.delete(change.pos, change.remove); + yxml.insert(change.pos, change.insert); + break + case 'attributes': + if (yxml.constructor === YXmlFragment) { + break + } + let name = mutation.attributeName; + let val = dom.getAttribute(name); + // check if filter accepts attribute + let attributes = new Map(); + attributes.set(name, val); + if (this._domFilter(dom.nodeName, attributes).size > 0 && yxml.constructor !== YXmlFragment) { + if (yxml.getAttribute(name) !== val) { + if (val == null) { + yxml.removeAttribute(name); + } else { + yxml.setAttribute(name, val); + } + } + } + break + case 'childList': + diffChildren.add(mutation.target); + break + } + }); + for (let dom of diffChildren) { + if (dom.yOnChildrenChanged !== undefined) { + dom.yOnChildrenChanged(); + } + if (dom._yxml != null && dom._yxml !== false) { + applyChangesFromDom(dom); + } + } + }); + }); + }; + this._domObserver = new MutationObserver(this._domObserverListener); + this._domObserver.observe(dom, { + childList: true, + attributes: true, + characterData: true, + subtree: true + }); + } + return dom + } + _logString () { + const left = this._left !== null ? this._left._lastId : null; + const origin = this._origin !== null ? this._origin._lastId : null; + return `YXml(id:${logID(this._id)},left:${logID(left)},origin:${logID(origin)},right:${this._right},parent:${logID(this._parent)},parentSub:${this._parentSub})` + } +} + +class YXmlElement extends YXmlFragment { + constructor (arg1, arg2, _document) { + super(); + this.nodeName = null; + this._scrollElement = null; + if (typeof arg2 === 'function') { + this._domFilter = arg2; + } + if (typeof arg1 === 'string') { + this.nodeName = arg1.toUpperCase(); + } else if (arg1 != null && arg1.nodeType != null && arg1.nodeType === arg1.ELEMENT_NODE) { + this.nodeName = arg1.nodeName; + this._setDom(arg1, _document); + } else { + this.nodeName = 'UNDEFINED'; + } + } + _copy () { + let struct = super._copy(); + struct.nodeName = this.nodeName; + return struct + } + _setDom (dom, _document) { + if (this._dom != null) { + throw new Error('Only call this method if you know what you are doing ;)') + } else if (dom._yxml != null) { // TODO do i need to check this? - no.. but for dev purps.. + throw new Error('Already bound to an YXml type') + } else { + // tag is already set in constructor + // set attributes + let attributes = new Map(); + for (let i = 0; i < dom.attributes.length; i++) { + let attr = dom.attributes[i]; + // get attribute via getAttribute for custom element support (some write something different in attr.value) + attributes.set(attr.name, dom.getAttribute(attr.name)); + } + attributes = this._domFilter(dom.nodeName, attributes); + attributes.forEach((value, name) => { + this.setAttribute(name, value); + }); + this.insertDomElements(0, Array.prototype.slice.call(dom.childNodes), _document); + this._bindToDom(dom, _document); + return dom + } + } + _bindToDom (dom, _document) { + _document = _document || document; + this._dom = dom; + dom._yxml = this; + } + _fromBinary (y, decoder) { + const missing = super._fromBinary(y, decoder); + this.nodeName = decoder.readVarString(); + return missing + } + _toBinary (encoder) { + super._toBinary(encoder); + encoder.writeVarString(this.nodeName); + } + _integrate (y) { + if (this.nodeName === null) { + throw new Error('nodeName must be defined!') + } + if (this._domFilter === defaultDomFilter && this._parent._domFilter !== undefined) { + this._domFilter = this._parent._domFilter; + } + super._integrate(y); + } + /** + * Returns the string representation of the XML document. + * The attributes are ordered by attribute-name, so you can easily use this + * method to compare YXmlElements + */ + toString () { + const attrs = this.getAttributes(); + const stringBuilder = []; + const keys = []; + for (let key in attrs) { + keys.push(key); + } + keys.sort(); + const keysLen = keys.length; + for (let i = 0; i < keysLen; i++) { + const key = keys[i]; + stringBuilder.push(key + '="' + attrs[key] + '"'); + } + const nodeName = this.nodeName.toLocaleLowerCase(); + const attrsString = stringBuilder.length > 0 ? ' ' + stringBuilder.join(' ') : ''; + return `<${nodeName}${attrsString}>${super.toString()}` + } + removeAttribute () { + return YMap.prototype.delete.apply(this, arguments) + } + + setAttribute () { + return YMap.prototype.set.apply(this, arguments) + } + + getAttribute () { + return YMap.prototype.get.apply(this, arguments) + } + + getAttributes () { + const obj = {}; + for (let [key, value] of this._map) { + if (!value._deleted) { + obj[key] = value._content[0]; + } + } + return obj + } + getDom (_document) { + _document = _document || document; + let dom = this._dom; + if (dom == null) { + dom = _document.createElement(this.nodeName); + dom._yxml = this; + let attrs = this.getAttributes(); + for (let key in attrs) { + dom.setAttribute(key, attrs[key]); + } + this.forEach(yxml => { + dom.appendChild(yxml.getDom(_document)); + }); + this._bindToDom(dom, _document); + } + return dom + } +} + +const xmlHooks = {}; + +function addHook (name, hook) { + xmlHooks[name] = hook; +} + +function getHook (name) { + const hook = xmlHooks[name]; + if (hook === undefined) { + throw new Error(`The hook "${name}" is not specified! You must not access this hook!`) + } + return hook +} + +class YXmlHook extends YMap { + constructor (hookName, dom) { + super(); + this._dom = null; + this.hookName = null; + if (hookName !== undefined) { + this.hookName = hookName; + this._dom = dom; + dom._yjsHook = hookName; + dom._yxml = this; + getHook(hookName).fillType(dom, this); + } + } + _copy () { + const struct = super._copy(); + struct.hookName = this.hookName; + return struct + } + getDom (_document) { + _document = _document || document; + if (this._dom === null) { + const dom = getHook(this.hookName).createDom(this); + this._dom = dom; + dom._yxml = this; + dom._yjsHook = this.hookName; + } + return this._dom + } + _unbindFromDom () { + this._dom._yxml = null; + this._yxml = null; + // TODO: cleanup hook? + } + _fromBinary (y, decoder) { + const missing = super._fromBinary(y, decoder); + this.hookName = decoder.readVarString(); + return missing + } + _toBinary (encoder) { + super._toBinary(encoder); + encoder.writeVarString(this.hookName); + } + _integrate (y) { + if (this.hookName === null) { + throw new Error('hookName must be defined!') + } + super._integrate(y); + } + setDomFilter () { + // TODO: implement new modfilter method! + } + enableSmartScrolling () { + // TODO: implement new smartscrolling method! + } +} +YXmlHook.addHook = addHook; + +class YXmlText extends YText { + constructor (arg1) { + let dom = null; + let initialText = null; + if (arg1 != null) { + if (arg1.nodeType != null && arg1.nodeType === arg1.TEXT_NODE) { + dom = arg1; + initialText = dom.nodeValue; + } else if (typeof arg1 === 'string') { + initialText = arg1; + } + } + super(initialText); + this._dom = null; + this._domObserver = null; + this._domObserverListener = null; + this._scrollElement = null; + if (dom !== null) { + this._setDom(arg1); + } + /* + var token = true + this._mutualExclude = f => { + if (token) { + token = false + try { + f() + } catch (e) { + console.error(e) + } + this._domObserver.takeRecords() + token = true + } + } + this.observe(event => { + if (this._dom != null) { + const dom = this._dom + this._mutualExclude(() => { + let anchorViewPosition = getAnchorViewPosition(this._scrollElement) + let anchorViewFix + if (anchorViewPosition !== null && (anchorViewPosition.anchor !== null || getBoundingClientRect(this._dom).top <= 0)) { + anchorViewFix = anchorViewPosition + } else { + anchorViewFix = null + } + dom.nodeValue = this.toString() + fixScrollPosition(this._scrollElement, anchorViewFix) + }) + } + }) + */ + } + setDomFilter () {} + enableSmartScrolling (scrollElement) { + this._scrollElement = scrollElement; + } + _setDom (dom) { + if (this._dom != null) { + this._unbindFromDom(); + } + if (dom._yxml != null) { + dom._yxml._unbindFromDom(); + } + // set marker + this._dom = dom; + dom._yxml = this; + } + getDom (_document) { + _document = _document || document; + if (this._dom === null) { + const dom = _document.createTextNode(this.toString()); + this._setDom(dom); + return dom + } + return this._dom + } + _delete (y, createDelete) { + this._unbindFromDom(); + super._delete(y, createDelete); + } + _unbindFromDom () { + if (this._domObserver != null) { + this._domObserver.disconnect(); + this._domObserver = null; + } + if (this._dom != null) { + this._dom._yxml = null; + this._dom = null; + } + } +} + +YXmlFragment._YXmlElement = YXmlElement; +YXmlFragment._YXmlHook = YXmlHook; + +const structs = new Map(); +const references = new Map(); + +function addStruct (reference, structConstructor) { + structs.set(reference, structConstructor); + references.set(structConstructor, reference); +} + +function getStruct (reference) { + return structs.get(reference) +} + +function getReference (typeConstructor) { + return references.get(typeConstructor) +} + +addStruct(0, ItemJSON); +addStruct(1, ItemString); +addStruct(2, Delete); + +addStruct(3, YArray); +addStruct(4, YMap); +addStruct(5, YText); +addStruct(6, YXmlFragment); +addStruct(7, YXmlElement); +addStruct(8, YXmlText); +addStruct(9, YXmlHook); + +const RootFakeUserID = 0xFFFFFF; + +class RootID { + constructor (name, typeConstructor) { + this.user = RootFakeUserID; + this.name = name; + this.type = getReference(typeConstructor); + } + equals (id) { + return id !== null && id.user === this.user && id.name === this.name && id.type === this.type + } + lessThan (id) { + if (id.constructor === RootID) { + return this.user < id.user || (this.user === id.user && (this.name < id.name || (this.name === id.name && this.type < id.type))) + } else { + return true + } + } +} + +class OperationStore extends Tree { + constructor (y) { + super(); + this.y = y; + } + logTable () { + const items = []; + this.iterate(null, null, function (item) { + items.push({ + id: logID(item), + origin: logID(item._origin === null ? null : item._origin._lastId), + left: logID(item._left === null ? null : item._left._lastId), + right: logID(item._right), + right_origin: logID(item._right_origin), + parent: logID(item._parent), + parentSub: item._parentSub, + deleted: item._deleted, + content: JSON.stringify(item._content) + }); + }); + console.table(items); + } + get (id) { + let struct = this.find(id); + if (struct === null && id instanceof RootID) { + const Constr = getStruct(id.type); + const y = this.y; + struct = new Constr(); + struct._id = id; + struct._parent = y; + y.transact(() => { + struct._integrate(y); + }); + this.put(struct); + } + return struct + } + // Use getItem for structs with _length > 1 + getItem (id) { + var item = this.findWithUpperBound(id); + if (item === null) { + return null + } + const itemID = item._id; + if (id.user === itemID.user && id.clock < itemID.clock + item._length) { + return item + } else { + return null + } + } + // Return an insertion such that id is the first element of content + // This function manipulates an item, if necessary + getItemCleanStart (id) { + var ins = this.getItem(id); + if (ins === null || ins._length === 1) { + return ins + } + const insID = ins._id; + if (insID.clock === id.clock) { + return ins + } else { + return ins._splitAt(this.y, id.clock - insID.clock) + } + } + // Return an insertion such that id is the last element of content + // This function manipulates an operation, if necessary + getItemCleanEnd (id) { + var ins = this.getItem(id); + if (ins === null || ins._length === 1) { + return ins + } + const insID = ins._id; + if (insID.clock + ins._length - 1 === id.clock) { + return ins + } else { + ins._splitAt(this.y, id.clock - insID.clock + 1); + return ins + } + } +} + +class StateStore { + constructor (y) { + this.y = y; + this.state = new Map(); + } + logTable () { + const entries = []; + for (let [user, state] of this.state) { + entries.push({ + user, state + }); + } + console.table(entries); + } + getNextID (len) { + const user = this.y.userID; + const state = this.getState(user); + this.setState(user, state + len); + return new ID(user, state) + } + updateRemoteState (struct) { + let user = struct._id.user; + let userState = this.state.get(user); + while (struct !== null && struct._id.clock === userState) { + userState += struct._length; + struct = this.y.os.get(new ID(user, userState)); + } + this.state.set(user, userState); + } + getState (user) { + let state = this.state.get(user); + if (state == null) { + return 0 + } + return state + } + setState (user, state) { + // TODO: modify missingi structs here + const beforeState = this.y._transaction.beforeState; + if (!beforeState.has(user)) { + beforeState.set(user, this.getState(user)); + } + this.state.set(user, state); + } +} + +/* global crypto */ + +function generateUserID () { + if (typeof crypto !== 'undefined' && crypto.getRandomValue != null) { + // browser + let arr = new Uint32Array(1); + crypto.getRandomValues(arr); + return arr[0] + } else if (typeof crypto !== 'undefined' && crypto.randomBytes != null) { + // node + let buf = crypto.randomBytes(4); + return new Uint32Array(buf.buffer)[0] + } else { + return Math.ceil(Math.random() * 0xFFFFFFFF) + } +} + +class NamedEventHandler { + constructor () { + this._eventListener = new Map(); + this._stateListener = new Map(); + } + _getListener (name) { + let listeners = this._eventListener.get(name); + if (listeners === undefined) { + listeners = { + once: new Set(), + on: new Set() + }; + this._eventListener.set(name, listeners); + } + return listeners + } + once (name, f) { + let listeners = this._getListener(name); + listeners.once.add(f); + } + on (name, f) { + let listeners = this._getListener(name); + listeners.on.add(f); + } + _initStateListener (name) { + let state = this._stateListener.get(name); + if (state === undefined) { + state = {}; + state.promise = new Promise(function (resolve) { + state.resolve = resolve; + }); + this._stateListener.set(name, state); + } + return state + } + when (name) { + return this._initStateListener(name).promise + } + off (name, f) { + if (name == null || f == null) { + throw new Error('You must specify event name and function!') + } + const listener = this._eventListener.get(name); + if (listener !== undefined) { + listener.on.delete(f); + listener.once.delete(f); + } + } + emit (name, ...args) { + this._initStateListener(name).resolve(); + const listener = this._eventListener.get(name); + if (listener !== undefined) { + listener.on.forEach(f => f.apply(null, args)); + listener.once.forEach(f => f.apply(null, args)); + listener.once = new Set(); + } else if (name === 'error') { + console.error(args[0]); + } + } + destroy () { + this._eventListener = null; + } +} + +class ReverseOperation { + constructor (y, transaction) { + this.created = new Date(); + const beforeState = transaction.beforeState; + if (beforeState.has(y.userID)) { + this.toState = new ID(y.userID, y.ss.getState(y.userID) - 1); + this.fromState = new ID(y.userID, beforeState.get(y.userID)); + } else { + this.toState = null; + this.fromState = null; + } + this.deletedStructs = transaction.deletedStructs; + } +} + +function isStructInScope (y, struct, scope) { + while (struct !== y) { + if (struct === scope) { + return true + } + struct = struct._parent; + } + return false +} + +function applyReverseOperation (y, scope, reverseBuffer) { + let performedUndo = false; + y.transact(() => { + while (!performedUndo && reverseBuffer.length > 0) { + let undoOp = reverseBuffer.pop(); + // make sure that it is possible to iterate {from}-{to} + if (undoOp.fromState !== null) { + y.os.getItemCleanStart(undoOp.fromState); + y.os.getItemCleanEnd(undoOp.toState); + y.os.iterate(undoOp.fromState, undoOp.toState, op => { + while (op._deleted && op._redone !== null) { + op = op._redone; + } + if (op._deleted === false && isStructInScope(y, op, scope)) { + performedUndo = true; + op._delete(y); + } + }); + } + for (let op of undoOp.deletedStructs) { + if ( + isStructInScope(y, op, scope) && + op._parent !== y && + ( + op._id.user !== y.userID || + undoOp.fromState === null || + op._id.clock < undoOp.fromState.clock || + op._id.clock > undoOp.toState.clock + ) + ) { + performedUndo = true; + op._redo(y); + } + } + } + }); + return performedUndo +} + +class UndoManager { + constructor (scope, options = {}) { + this.options = options; + options.captureTimeout = options.captureTimeout == null ? 500 : options.captureTimeout; + this._undoBuffer = []; + this._redoBuffer = []; + this._scope = scope; + this._undoing = false; + this._redoing = false; + this._lastTransactionWasUndo = false; + const y = scope._y; + this.y = y; + y.on('afterTransaction', (y, transaction, remote) => { + if (!remote && transaction.changedParentTypes.has(scope)) { + let reverseOperation = new ReverseOperation(y, transaction); + if (!this._undoing) { + let lastUndoOp = this._undoBuffer.length > 0 ? this._undoBuffer[this._undoBuffer.length - 1] : null; + if ( + this._redoing === false && + this._lastTransactionWasUndo === false && + lastUndoOp !== null && + reverseOperation.created - lastUndoOp.created <= options.captureTimeout + ) { + lastUndoOp.created = reverseOperation.created; + if (reverseOperation.toState !== null) { + lastUndoOp.toState = reverseOperation.toState; + if (lastUndoOp.fromState === null) { + lastUndoOp.fromState = reverseOperation.fromState; + } + } + reverseOperation.deletedStructs.forEach(lastUndoOp.deletedStructs.add, lastUndoOp.deletedStructs); + } else { + this._lastTransactionWasUndo = false; + this._undoBuffer.push(reverseOperation); + } + if (!this._redoing) { + this._redoBuffer = []; + } + } else { + this._lastTransactionWasUndo = true; + this._redoBuffer.push(reverseOperation); + } + } + }); + } + undo () { + this._undoing = true; + const performedUndo = applyReverseOperation(this.y, this._scope, this._undoBuffer); + this._undoing = false; + return performedUndo + } + redo () { + this._redoing = true; + const performedRedo = applyReverseOperation(this.y, this._scope, this._redoBuffer); + this._redoing = false; + return performedRedo + } +} + +function createCommonjsModule(fn, module) { + return module = { exports: {} }, fn(module, module.exports), module.exports; +} + +/** + * Helpers. + */ + +var s = 1000; +var m = s * 60; +var h = m * 60; +var d = h * 24; +var y = d * 365.25; + +/** + * Parse or format the given `val`. + * + * Options: + * + * - `long` verbose formatting [false] + * + * @param {String|Number} val + * @param {Object} [options] + * @throws {Error} throw an error if val is not a non-empty string or a number + * @return {String|Number} + * @api public + */ + +var ms = function(val, options) { + options = options || {}; + var type = typeof val; + if (type === 'string' && val.length > 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 > 100) { + 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'; +} + +var debug$1 = createCommonjsModule(function (module, exports) { +/** + * 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 = 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$$1 = curr - (prevTime || curr); + self.diff = ms$$1; + 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 = (typeof namespaces === 'string' ? 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; +} +}); + +var debug_1 = debug$1.coerce; +var debug_2 = debug$1.disable; +var debug_3 = debug$1.enable; +var debug_4 = debug$1.enabled; +var debug_5 = debug$1.humanize; +var debug_6 = debug$1.names; +var debug_7 = debug$1.skips; +var debug_8 = debug$1.formatters; + +var browser = createCommonjsModule(function (module, exports) { +/** + * This is the web browser implementation of `debug()`. + * + * Expose `debug()` as the module. + */ + +exports = module.exports = debug$1; +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.process && 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.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) || + // is firebug? http://stackoverflow.com/a/398120/376773 + (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) || + // is firefox >= v31? + // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages + (typeof navigator !== 'undefined' && 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.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 + && 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) {} +} +}); + +var browser_1 = browser.log; +var browser_2 = browser.formatArgs; +var browser_3 = browser.save; +var browser_4 = browser.load; +var browser_5 = browser.useColors; +var browser_6 = browser.storage; +var browser_7 = browser.colors; + +class AbstractConnector { + constructor (y, opts) { + this.y = y; + this.opts = 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 = browser('y:connector'); + this.logMessage = browser('y:connector-message'); + this._forwardAppliedStructs = opts.forwardAppliedOperations || false; // TODO: rename + this.role = opts.role; + this.connections = new Map(); + this.isSynced = false; + this.userEventListeners = []; + this.whenSyncedListeners = []; + this.currentSyncTarget = null; + this.debug = opts.debug === true; + this.broadcastBuffer = new BinaryEncoder(); + this.broadcastBufferSize = 0; + 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.maxBufferLength == null) { + this.maxBufferLength = -1; + } else { + this.maxBufferLength = opts.maxBufferLength; + } + } + + reconnect () { + this.log('reconnecting..'); + } + + disconnect () { + this.log('discronnecting..'); + this.connections = new Map(); + this.isSynced = false; + this.currentSyncTarget = null; + this.whenSyncedListeners = []; + return Promise.resolve() + } + + onUserEvent (f) { + this.userEventListeners.push(f); + } + + removeUserEventListener (f) { + this.userEventListeners = this.userEventListeners.filter(g => f !== g); + } + + userLeft (user) { + if (this.connections.has(user)) { + this.log('%s: User left %s', this.y.userID, user); + this.connections.delete(user); + // check if isSynced event can be sent now + this._setSyncedWith(null); + for (var f of this.userEventListeners) { + f({ + action: 'userLeft', + user: user + }); + } + } + } + + userJoined (user, role, auth) { + if (role == null) { + throw new Error('You must specify the role of the joined user!') + } + if (this.connections.has(user)) { + throw new Error('This user already joined!') + } + this.log('%s: User joined %s', this.y.userID, user); + this.connections.set(user, { + uid: user, + isSynced: false, + role: role, + processAfterAuth: [], + processAfterSync: [], + auth: auth || null, + receivedSyncStep2: false + }); + let defer = {}; + defer.promise = new Promise(function (resolve) { defer.resolve = resolve; }); + this.connections.get(user).syncStep2 = defer; + for (var f of this.userEventListeners) { + f({ + action: 'userJoined', + user: user, + role: role + }); + } + this._syncWithUser(user); + } + + // Execute a function _when_ we are connected. + // If not connected, wait until connected + whenSynced (f) { + if (this.isSynced) { + f(); + } else { + this.whenSyncedListeners.push(f); + } + } + + _syncWithUser (userID) { + if (this.role === 'slave') { + return // "The current sync has not finished or this is controlled by a master!" + } + sendSyncStep1(this, userID); + } + + _fireIsSyncedListeners () { + if (!this.isSynced) { + this.isSynced = true; + // It is safer to remove this! + // call whensynced listeners + for (var f of this.whenSyncedListeners) { + f(); + } + this.whenSyncedListeners = []; + this.y._setContentReady(); + this.y.emit('synced'); + } + } + + send (uid, buffer) { + const y = this.y; + if (!(buffer instanceof ArrayBuffer || buffer instanceof Uint8Array)) { + throw new Error('Expected Message to be an ArrayBuffer or Uint8Array - don\'t use this method to send custom messages') + } + this.log('User%s to User%s: Send \'%y\'', y.userID, uid, buffer); + this.logMessage('User%s to User%s: Send %Y', y.userID, uid, [y, buffer]); + } + + broadcast (buffer) { + const y = this.y; + if (!(buffer instanceof ArrayBuffer || buffer instanceof Uint8Array)) { + throw new Error('Expected Message to be an ArrayBuffer or Uint8Array - don\'t use this method to send custom messages') + } + this.log('User%s: Broadcast \'%y\'', y.userID, buffer); + this.logMessage('User%s: Broadcast: %Y', y.userID, [y, buffer]); + } + + /* + Buffer operations, and broadcast them when ready. + */ + broadcastStruct (struct) { + const firstContent = this.broadcastBuffer.length === 0; + if (firstContent) { + this.broadcastBuffer.writeVarString(this.y.room); + this.broadcastBuffer.writeVarString('update'); + this.broadcastBufferSize = 0; + this.broadcastBufferSizePos = this.broadcastBuffer.pos; + this.broadcastBuffer.writeUint32(0); + } + this.broadcastBufferSize++; + struct._toBinary(this.broadcastBuffer); + if (this.maxBufferLength > 0 && this.broadcastBuffer.length > this.maxBufferLength) { + // it is necessary to send the buffer now + // cache the buffer and check if server is responsive + const buffer = this.broadcastBuffer; + buffer.setUint32(this.broadcastBufferSizePos, this.broadcastBufferSize); + this.broadcastBuffer = new BinaryEncoder(); + this.whenRemoteResponsive().then(() => { + this.broadcast(buffer.createBuffer()); + }); + } else if (firstContent) { + // send the buffer when all transactions are finished + // (or buffer exceeds maxBufferLength) + setTimeout(() => { + if (this.broadcastBuffer.length > 0) { + const buffer = this.broadcastBuffer; + buffer.setUint32(this.broadcastBufferSizePos, this.broadcastBufferSize); + this.broadcast(buffer.createBuffer()); + this.broadcastBuffer = new BinaryEncoder(); + } + }, 0); + } + } + + /* + * Somehow check the responsiveness of the remote clients/server + * Default behavior: + * Wait 100ms before broadcasting the next batch of operations + * + * Only used when maxBufferLength is set + * + */ + whenRemoteResponsive () { + return new Promise(function (resolve) { + setTimeout(resolve, 100); + }) + } + + /* + You received a raw message, and you know that it is intended for Yjs. Then call this function. + */ + receiveMessage (sender, buffer, skipAuth) { + const y = this.y; + const userID = y.userID; + skipAuth = skipAuth || false; + if (!(buffer instanceof ArrayBuffer || buffer instanceof Uint8Array)) { + return Promise.reject(new Error('Expected Message to be an ArrayBuffer or Uint8Array!')) + } + if (sender === userID) { + return Promise.resolve() + } + let decoder = new BinaryDecoder(buffer); + let encoder = new BinaryEncoder(); + let roomname = decoder.readVarString(); // read room name + encoder.writeVarString(roomname); + let messageType = decoder.readVarString(); + let senderConn = this.connections.get(sender); + this.log('User%s from User%s: Receive \'%s\'', userID, sender, messageType); + this.logMessage('User%s from User%s: Receive %Y', userID, sender, [y, buffer]); + if (senderConn == null && !skipAuth) { + throw new Error('Received message from unknown peer!') + } + if (messageType === 'sync step 1' || messageType === 'sync step 2') { + let auth = decoder.readVarUint(); + if (senderConn.auth == null) { + senderConn.processAfterAuth.push([messageType, senderConn, decoder, encoder, sender]); + // check auth + return this.checkAuth(auth, y, sender).then(authPermissions => { + if (senderConn.auth == null) { + senderConn.auth = authPermissions; + y.emit('userAuthenticated', { + user: senderConn.uid, + auth: authPermissions + }); + } + let messages = senderConn.processAfterAuth; + senderConn.processAfterAuth = []; + + messages.forEach(m => + this.computeMessage(m[0], m[1], m[2], m[3], m[4]) + ); + }) + } + } + if ((skipAuth || senderConn.auth != null) && (messageType !== 'update' || senderConn.isSynced)) { + this.computeMessage(messageType, senderConn, decoder, encoder, sender, skipAuth); + } else { + senderConn.processAfterSync.push([messageType, senderConn, decoder, encoder, sender, false]); + } + } + + computeMessage (messageType, senderConn, decoder, encoder, sender, skipAuth) { + if (messageType === 'sync step 1' && (senderConn.auth === 'write' || senderConn.auth === 'read')) { + // cannot wait for sync step 1 to finish, because we may wait for sync step 2 in sync step 1 (->lock) + readSyncStep1(decoder, encoder, this.y, senderConn, sender); + } else { + const y = this.y; + y.transact(function () { + if (messageType === 'sync step 2' && senderConn.auth === 'write') { + readSyncStep2(decoder, encoder, y, senderConn, sender); + } else if (messageType === 'update' && (skipAuth || senderConn.auth === 'write')) { + integrateRemoteStructs(y, decoder); + } else { + throw new Error('Unable to receive message') + } + }, true); + } + } + + _setSyncedWith (user) { + if (user != null) { + const userConn = this.connections.get(user); + userConn.isSynced = true; + const messages = userConn.processAfterSync; + userConn.processAfterSync = []; + messages.forEach(m => { + this.computeMessage(m[0], m[1], m[2], m[3], m[4]); + }); + } + const conns = Array.from(this.connections.values()); + if (conns.length > 0 && conns.every(u => u.isSynced)) { + this._fireIsSyncedListeners(); + } + } +} + +function fromBinary (y, decoder) { + y.transact(function () { + integrateRemoteStructs(y, decoder); + readDeleteSet(y, decoder); + }); +} + +function toBinary (y) { + let encoder = new BinaryEncoder(); + writeStructs(y, encoder, new Map()); + writeDeleteSet(y, encoder); + return encoder +} + +function createMutualExclude () { + var token = true; + return function mutualExclude (f) { + if (token) { + token = false; + try { + f(); + } catch (e) { + console.error(e); + } + token = true; + } + } +} + +function getFreshCnf () { + let buffer = new BinaryEncoder(); + buffer.writeUint32(0); + return { + len: 0, + buffer + } +} + +class AbstractPersistence { + constructor (opts) { + this.opts = opts; + this.ys = new Map(); + } + + _init (y) { + let cnf = this.ys.get(y); + if (cnf === undefined) { + cnf = getFreshCnf(); + cnf.mutualExclude = createMutualExclude(); + this.ys.set(y, cnf); + return this.init(y).then(() => { + y.on('afterTransaction', (y, transaction) => { + let cnf = this.ys.get(y); + if (cnf.len > 0) { + cnf.buffer.setUint32(0, cnf.len); + this.saveUpdate(y, cnf.buffer.createBuffer(), transaction); + let _cnf = getFreshCnf(); + for (let key in _cnf) { + cnf[key] = _cnf[key]; + } + } + }); + return this.retrieve(y) + }).then(function () { + return Promise.resolve(cnf) + }) + } else { + return Promise.resolve(cnf) + } + } + deinit (y) { + this.ys.delete(y); + y.persistence = null; + } + + destroy () { + this.ys = null; + } + + /** + * Remove all persisted data that belongs to a room. + * Automatically destroys all Yjs all Yjs instances that persist to + * the room. If `destroyYjsInstances = false` the persistence functionality + * will be removed from the Yjs instances. + * + * ** Must be overwritten! ** + */ + removePersistedData (room, destroyYjsInstances = true) { + this.ys.forEach((cnf, y) => { + if (y.room === room) { + if (destroyYjsInstances) { + y.destroy(); + } else { + this.deinit(y); + } + } + }); + } + + /* overwrite */ + saveUpdate (buffer) { + } + + /** + * Save struct to update buffer. + * saveUpdate is called when transaction ends + */ + saveStruct (y, struct) { + let cnf = this.ys.get(y); + if (cnf !== undefined) { + cnf.mutualExclude(function () { + struct._toBinary(cnf.buffer); + cnf.len++; + }); + } + } + + /* overwrite */ + retrieve (y, model, updates) { + let cnf = this.ys.get(y); + if (cnf !== undefined) { + cnf.mutualExclude(function () { + y.transact(function () { + if (model != null) { + fromBinary(y, new BinaryDecoder(new Uint8Array(model))); + } + if (updates != null) { + for (let i = 0; i < updates.length; i++) { + integrateRemoteStructs(y, new BinaryDecoder(new Uint8Array(updates[i]))); + } + } + }); + y.emit('persistenceReady'); + }); + } + } + + /* overwrite */ + persist (y) { + return toBinary(y).createBuffer() + } +} + +class Binding { + constructor (type, target) { + this.type = type; + this.target = target; + this._mutualExclude = createMutualExclude(); + } + destroy () { + this.type = null; + this.target = null; + } +} + +function typeObserver () { + this._mutualExclude(() => { + const textarea = this.target; + const textType = this.type; + const relativeStart = getRelativePosition(textType, textarea.selectionStart); + const relativeEnd = getRelativePosition(textType, textarea.selectionEnd); + textarea.value = textType.toString(); + const start = fromRelativePosition(textType._y, relativeStart); + const end = fromRelativePosition(textType._y, relativeEnd); + textarea.setSelectionRange(start, end); + }); +} + +function domObserver () { + this._mutualExclude(() => { + let diff = simpleDiff(this.type.toString(), this.target.value); + this.type.delete(diff.pos, diff.remove); + this.type.insert(diff.pos, diff.insert); + }); +} + +class TextareaBinding extends Binding { + constructor (textType, domTextarea) { + // Binding handles textType as this.type and domTextarea as this.target + super(textType, domTextarea); + // set initial value + domTextarea.value = textType.toString(); + // Observers are handled by this class + this._typeObserver = typeObserver.bind(this); + this._domObserver = domObserver.bind(this); + textType.observe(this._typeObserver); + domTextarea.addEventListener('input', this._domObserver); + } + destroy () { + // Remove everything that is handled by this class + this.type.unobserve(this._typeObserver); + this.target.unobserve(this._domObserver); + super.destroy(); + } +} + +class Y$1 extends NamedEventHandler { + constructor (room, opts, persistence) { + super(); + this.room = room; + if (opts != null) { + opts.connector.room = room; + } + this._contentReady = false; + this._opts = opts; + this.userID = generateUserID(); + this.share = {}; + this.ds = new DeleteStore(this); + this.os = new OperationStore(this); + this.ss = new StateStore(this); + this._missingStructs = new Map(); + this._readyToIntegrate = []; + this._transaction = null; + this.connector = null; + this.connected = false; + let initConnection = () => { + if (opts != null) { + this.connector = new Y$1[opts.connector.name](this, opts.connector); + this.connected = true; + this.emit('connectorReady'); + } + }; + if (persistence != null) { + this.persistence = persistence; + persistence._init(this).then(initConnection); + } else { + this.persistence = null; + initConnection(); + } + } + _setContentReady () { + if (!this._contentReady) { + this._contentReady = true; + this.emit('content'); + } + } + whenContentReady () { + if (this._contentReady) { + return Promise.resolve() + } else { + return new Promise(resolve => { + this.once('content', resolve); + }) + } + } + _beforeChange () {} + transact (f, remote = false) { + let initialCall = this._transaction === null; + if (initialCall) { + this._transaction = new Transaction(this); + this.emit('beforeTransaction', this, this._transaction, remote); + } + try { + f(this); + } catch (e) { + console.error(e); + } + if (initialCall) { + this.emit('beforeObserverCalls', this, this._transaction, remote); + const transaction = this._transaction; + this._transaction = null; + // emit change events on changed types + transaction.changedTypes.forEach(function (subs, type) { + if (!type._deleted) { + type._callObserver(transaction, subs, remote); + } + }); + transaction.changedParentTypes.forEach(function (events, type) { + if (!type._deleted) { + events = events + .filter(event => + !event.target._deleted + ); + events + .forEach(event => { + event.currentTarget = type; + }); + // we don't have to check for events.length + // because there is no way events is empty.. + type._deepEventHandler.callEventListeners(transaction, events); + } + }); + // when all changes & events are processed, emit afterTransaction event + this.emit('afterTransaction', this, transaction, remote); + } + } + // fake _start for root properties (y.set('name', type)) + get _start () { + return null + } + set _start (start) { + return null + } + define (name, TypeConstructor) { + let id = new RootID(name, TypeConstructor); + let type = this.os.get(id); + if (this.share[name] === undefined) { + this.share[name] = type; + } else if (this.share[name] !== type) { + throw new Error('Type is already defined with a different constructor') + } + return type + } + get (name) { + return this.share[name] + } + disconnect () { + if (this.connected) { + this.connected = false; + return this.connector.disconnect() + } else { + return Promise.resolve() + } + } + reconnect () { + if (!this.connected) { + this.connected = true; + return this.connector.reconnect() + } else { + return Promise.resolve() + } + } + destroy () { + super.destroy(); + this.share = null; + if (this.connector != null) { + if (this.connector.destroy != null) { + this.connector.destroy(); + } else { + this.connector.disconnect(); + } + } + if (this.persistence !== null) { + this.persistence.deinit(this); + this.persistence = null; + } + this.os = null; + this.ds = null; + this.ss = null; + } + whenSynced () { + return new Promise(resolve => { + this.once('synced', () => { + resolve(); + }); + }) + } +} + +Y$1.extend = function extendYjs () { + for (var i = 0; i < arguments.length; i++) { + var f = arguments[i]; + if (typeof f === 'function') { + f(Y$1); + } else { + throw new Error('Expected a function!') + } + } +}; + +// TODO: The following assignments should be moved to yjs-dist +Y$1.AbstractConnector = AbstractConnector; +Y$1.AbstractPersistence = AbstractPersistence; +Y$1.Array = YArray; +Y$1.Map = YMap; +Y$1.Text = YText; +Y$1.XmlElement = YXmlElement; +Y$1.XmlFragment = YXmlFragment; +Y$1.XmlText = YXmlText; +Y$1.XmlHook = YXmlHook; + +Y$1.TextareaBinding = TextareaBinding; + +Y$1.utils = { + BinaryDecoder, + UndoManager, + getRelativePosition, + fromRelativePosition, + addType: addStruct, + integrateRemoteStructs, + toBinary, + fromBinary +}; + +Y$1.debug = browser; +browser.formatters.Y = messageToString; +browser.formatters.y = messageToRoomname; + +module.exports = Y$1; +//# sourceMappingURL=y.node.js.map diff --git a/y.node.js.map b/y.node.js.map new file mode 100644 index 00000000..176221d8 --- /dev/null +++ b/y.node.js.map @@ -0,0 +1 @@ +{"version":3,"file":"y.node.js","sources":["src/Util/Tree.js","src/Util/ID.js","src/Store/DeleteStore.js","src/Binary/Decoder.js","src/MessageHandler/integrateRemoteStructs.js","src/Binary/Encoder.js","src/MessageHandler/stateSet.js","src/MessageHandler/deleteSet.js","src/MessageHandler/syncStep1.js","src/MessageHandler/syncStep2.js","src/MessageHandler/messageToString.js","src/Struct/Delete.js","src/Transaction.js","src/Struct/Item.js","src/Util/EventHandler.js","src/Struct/Type.js","src/Struct/ItemJSON.js","src/Struct/ItemString.js","src/Util/YEvent.js","src/Type/YArray.js","src/Type/YMap.js","src/Type/YText.js","src/Type/y-xml/utils.js","src/Util/relativePosition.js","src/Type/y-xml/selection.js","src/Type/y-xml/YXmlEvent.js","src/Util/simpleDiff.js","src/Type/y-xml/YXmlFragment.js","src/Type/y-xml/YXmlElement.js","src/Type/y-xml/hooks.js","src/Type/y-xml/YXmlHook.js","src/Type/y-xml/YXmlText.js","src/Type/y-xml/y-xml.js","src/Util/structReferences.js","src/Util/RootID.js","src/Store/OperationStore.js","src/Store/StateStore.js","src/Util/generateUserID.js","src/Util/NamedEventHandler.js","src/Util/UndoManager.js","node_modules/ms/index.js","node_modules/debug/src/debug.js","node_modules/debug/src/browser.js","src/Connector.js","src/MessageHandler/binaryEncode.js","src/Util/mutualExclude.js","src/Persistence.js","src/Binding/Binding.js","src/Binding/TextareaBinding.js","src/Y.js"],"sourcesContent":["\nclass N {\n // A created node is always red!\n constructor (val) {\n this.val = val\n this.color = true\n this._left = null\n this._right = null\n this._parent = null\n }\n isRed () { return this.color }\n isBlack () { return !this.color }\n redden () { this.color = true; return this }\n blacken () { this.color = false; return this }\n get grandparent () {\n return this.parent.parent\n }\n get parent () {\n return this._parent\n }\n get sibling () {\n return (this === this.parent.left)\n ? this.parent.right : this.parent.left\n }\n get left () {\n return this._left\n }\n get right () {\n return this._right\n }\n set left (n) {\n if (n !== null) {\n n._parent = this\n }\n this._left = n\n }\n set right (n) {\n if (n !== null) {\n n._parent = this\n }\n this._right = n\n }\n rotateLeft (tree) {\n var parent = this.parent\n var newParent = this.right\n var newRight = this.right.left\n newParent.left = this\n this.right = newRight\n if (parent === null) {\n tree.root = newParent\n newParent._parent = null\n } else if (parent.left === this) {\n parent.left = newParent\n } else if (parent.right === this) {\n parent.right = newParent\n } else {\n throw new Error('The elements are wrongly connected!')\n }\n }\n next () {\n if (this.right !== null) {\n // search the most left node in the right tree\n var o = this.right\n while (o.left !== null) {\n o = o.left\n }\n return o\n } else {\n var p = this\n while (p.parent !== null && p !== p.parent.left) {\n p = p.parent\n }\n return p.parent\n }\n }\n prev () {\n if (this.left !== null) {\n // search the most right node in the left tree\n var o = this.left\n while (o.right !== null) {\n o = o.right\n }\n return o\n } else {\n var p = this\n while (p.parent !== null && p !== p.parent.right) {\n p = p.parent\n }\n return p.parent\n }\n }\n rotateRight (tree) {\n var parent = this.parent\n var newParent = this.left\n var newLeft = this.left.right\n newParent.right = this\n this.left = newLeft\n if (parent === null) {\n tree.root = newParent\n newParent._parent = null\n } else if (parent.left === this) {\n parent.left = newParent\n } else if (parent.right === this) {\n parent.right = newParent\n } else {\n throw new Error('The elements are wrongly connected!')\n }\n }\n getUncle () {\n // we can assume that grandparent exists when this is called!\n if (this.parent === this.parent.parent.left) {\n return this.parent.parent.right\n } else {\n return this.parent.parent.left\n }\n }\n}\n\n/*\n * This is a Red Black Tree implementation\n */\nexport default class Tree {\n constructor () {\n this.root = null\n this.length = 0\n }\n findNext (id) {\n var nextID = id.clone()\n nextID.clock += 1\n return this.findWithLowerBound(nextID)\n }\n findPrev (id) {\n let prevID = id.clone()\n prevID.clock -= 1\n return this.findWithUpperBound(prevID)\n }\n findNodeWithLowerBound (from) {\n var o = this.root\n if (o === null) {\n return null\n } else {\n while (true) {\n if (from === null || (from.lessThan(o.val._id) && o.left !== null)) {\n // o is included in the bound\n // try to find an element that is closer to the bound\n o = o.left\n } else if (from !== null && o.val._id.lessThan(from)) {\n // o is not within the bound, maybe one of the right elements is..\n if (o.right !== null) {\n o = o.right\n } else {\n // there is no right element. Search for the next bigger element,\n // this should be within the bounds\n return o.next()\n }\n } else {\n return o\n }\n }\n }\n }\n findNodeWithUpperBound (to) {\n if (to === void 0) {\n throw new Error('You must define from!')\n }\n var o = this.root\n if (o === null) {\n return null\n } else {\n while (true) {\n if ((to === null || o.val._id.lessThan(to)) && o.right !== null) {\n // o is included in the bound\n // try to find an element that is closer to the bound\n o = o.right\n } else if (to !== null && to.lessThan(o.val._id)) {\n // o is not within the bound, maybe one of the left elements is..\n if (o.left !== null) {\n o = o.left\n } else {\n // there is no left element. Search for the prev smaller element,\n // this should be within the bounds\n return o.prev()\n }\n } else {\n return o\n }\n }\n }\n }\n findSmallestNode () {\n var o = this.root\n while (o != null && o.left != null) {\n o = o.left\n }\n return o\n }\n findWithLowerBound (from) {\n var n = this.findNodeWithLowerBound(from)\n return n == null ? null : n.val\n }\n findWithUpperBound (to) {\n var n = this.findNodeWithUpperBound(to)\n return n == null ? null : n.val\n }\n iterate (from, to, f) {\n var o\n if (from === null) {\n o = this.findSmallestNode()\n } else {\n o = this.findNodeWithLowerBound(from)\n }\n while (\n o !== null &&\n (\n to === null || // eslint-disable-line no-unmodified-loop-condition\n o.val._id.lessThan(to) ||\n o.val._id.equals(to)\n )\n ) {\n f(o.val)\n o = o.next()\n }\n }\n find (id) {\n let n = this.findNode(id)\n if (n !== null) {\n return n.val\n } else {\n return null\n }\n }\n findNode (id) {\n var o = this.root\n if (o === null) {\n return null\n } else {\n while (true) {\n if (o === null) {\n return null\n }\n if (id.lessThan(o.val._id)) {\n o = o.left\n } else if (o.val._id.lessThan(id)) {\n o = o.right\n } else {\n return o\n }\n }\n }\n }\n delete (id) {\n var d = this.findNode(id)\n if (d == null) {\n // throw new Error('Element does not exist!')\n return\n }\n this.length--\n if (d.left !== null && d.right !== null) {\n // switch d with the greates element in the left subtree.\n // o should have at most one child.\n var o = d.left\n // find\n while (o.right !== null) {\n o = o.right\n }\n // switch\n d.val = o.val\n d = o\n }\n // d has at most one child\n // let n be the node that replaces d\n var isFakeChild\n var child = d.left || d.right\n if (child === null) {\n isFakeChild = true\n child = new N(null)\n child.blacken()\n d.right = child\n } else {\n isFakeChild = false\n }\n\n if (d.parent === null) {\n if (!isFakeChild) {\n this.root = child\n child.blacken()\n child._parent = null\n } else {\n this.root = null\n }\n return\n } else if (d.parent.left === d) {\n d.parent.left = child\n } else if (d.parent.right === d) {\n d.parent.right = child\n } else {\n throw new Error('Impossible!')\n }\n if (d.isBlack()) {\n if (child.isRed()) {\n child.blacken()\n } else {\n this._fixDelete(child)\n }\n }\n this.root.blacken()\n if (isFakeChild) {\n if (child.parent.left === child) {\n child.parent.left = null\n } else if (child.parent.right === child) {\n child.parent.right = null\n } else {\n throw new Error('Impossible #3')\n }\n }\n }\n _fixDelete (n) {\n function isBlack (node) {\n return node !== null ? node.isBlack() : true\n }\n function isRed (node) {\n return node !== null ? node.isRed() : false\n }\n if (n.parent === null) {\n // this can only be called after the first iteration of fixDelete.\n return\n }\n // d was already replaced by the child\n // d is not the root\n // d and child are black\n var sibling = n.sibling\n if (isRed(sibling)) {\n // make sibling the grandfather\n n.parent.redden()\n sibling.blacken()\n if (n === n.parent.left) {\n n.parent.rotateLeft(this)\n } else if (n === n.parent.right) {\n n.parent.rotateRight(this)\n } else {\n throw new Error('Impossible #2')\n }\n sibling = n.sibling\n }\n // parent, sibling, and children of n are black\n if (n.parent.isBlack() &&\n sibling.isBlack() &&\n isBlack(sibling.left) &&\n isBlack(sibling.right)\n ) {\n sibling.redden()\n this._fixDelete(n.parent)\n } else if (n.parent.isRed() &&\n sibling.isBlack() &&\n isBlack(sibling.left) &&\n isBlack(sibling.right)\n ) {\n sibling.redden()\n n.parent.blacken()\n } else {\n if (n === n.parent.left &&\n sibling.isBlack() &&\n isRed(sibling.left) &&\n isBlack(sibling.right)\n ) {\n sibling.redden()\n sibling.left.blacken()\n sibling.rotateRight(this)\n sibling = n.sibling\n } else if (n === n.parent.right &&\n sibling.isBlack() &&\n isRed(sibling.right) &&\n isBlack(sibling.left)\n ) {\n sibling.redden()\n sibling.right.blacken()\n sibling.rotateLeft(this)\n sibling = n.sibling\n }\n sibling.color = n.parent.color\n n.parent.blacken()\n if (n === n.parent.left) {\n sibling.right.blacken()\n n.parent.rotateLeft(this)\n } else {\n sibling.left.blacken()\n n.parent.rotateRight(this)\n }\n }\n }\n put (v) {\n var node = new N(v)\n if (this.root !== null) {\n var p = this.root // p abbrev. parent\n while (true) {\n if (node.val._id.lessThan(p.val._id)) {\n if (p.left === null) {\n p.left = node\n break\n } else {\n p = p.left\n }\n } else if (p.val._id.lessThan(node.val._id)) {\n if (p.right === null) {\n p.right = node\n break\n } else {\n p = p.right\n }\n } else {\n p.val = node.val\n return p\n }\n }\n this._fixInsert(node)\n } else {\n this.root = node\n }\n this.length++\n this.root.blacken()\n return node\n }\n _fixInsert (n) {\n if (n.parent === null) {\n n.blacken()\n return\n } else if (n.parent.isBlack()) {\n return\n }\n var uncle = n.getUncle()\n if (uncle !== null && uncle.isRed()) {\n // Note: parent: red, uncle: red\n n.parent.blacken()\n uncle.blacken()\n n.grandparent.redden()\n this._fixInsert(n.grandparent)\n } else {\n // Note: parent: red, uncle: black or null\n // Now we transform the tree in such a way that\n // either of these holds:\n // 1) grandparent.left.isRed\n // and grandparent.left.left.isRed\n // 2) grandparent.right.isRed\n // and grandparent.right.right.isRed\n if (n === n.parent.right && n.parent === n.grandparent.left) {\n n.parent.rotateLeft(this)\n // Since we rotated and want to use the previous\n // cases, we need to set n in such a way that\n // n.parent.isRed again\n n = n.left\n } else if (n === n.parent.left && n.parent === n.grandparent.right) {\n n.parent.rotateRight(this)\n // see above\n n = n.right\n }\n // Case 1) or 2) hold from here on.\n // Now traverse grandparent, make parent a black node\n // on the highest level which holds two red nodes.\n n.parent.blacken()\n n.grandparent.redden()\n if (n === n.parent.left) {\n // Case 1\n n.grandparent.rotateRight(this)\n } else {\n // Case 2\n n.grandparent.rotateLeft(this)\n }\n }\n }\n flush () {}\n}\n","\nexport default class ID {\n constructor (user, clock) {\n this.user = user\n this.clock = clock\n }\n clone () {\n return new ID(this.user, this.clock)\n }\n equals (id) {\n return id !== null && id.user === this.user && id.clock === this.clock\n }\n lessThan (id) {\n if (id.constructor === ID) {\n return this.user < id.user || (this.user === id.user && this.clock < id.clock)\n } else {\n return false\n }\n }\n}\n","import Tree from '../Util/Tree.js'\nimport ID from '../Util/ID.js'\n\nclass DSNode {\n constructor (id, len, gc) {\n this._id = id\n this.len = len\n this.gc = gc\n }\n clone () {\n return new DSNode(this._id, this.len, this.gc)\n }\n}\n\nexport default class DeleteStore extends Tree {\n logTable () {\n const deletes = []\n this.iterate(null, null, function (n) {\n deletes.push({\n user: n._id.user,\n clock: n._id.clock,\n len: n.len,\n gc: n.gc\n })\n })\n console.table(deletes)\n }\n isDeleted (id) {\n var n = this.findWithUpperBound(id)\n return n !== null && n._id.user === id.user && id.clock < n._id.clock + n.len\n }\n /*\n * Mark an operation as deleted. returns the deleted node\n */\n markDeleted (id, length) {\n if (length == null) {\n throw new Error('length must be defined')\n }\n var n = this.findWithUpperBound(id)\n if (n != null && n._id.user === id.user) {\n if (n._id.clock <= id.clock && id.clock <= n._id.clock + n.len) {\n // id is in n's range\n var diff = id.clock + length - (n._id.clock + n.len) // overlapping right\n if (diff > 0) {\n // id+length overlaps n\n if (!n.gc) {\n n.len += diff\n } else {\n diff = n._id.clock + n.len - id.clock // overlapping left (id till n.end)\n if (diff < length) {\n // a partial deletion\n let nId = id.clone()\n nId.clock += diff\n n = new DSNode(nId, length - diff, false)\n this.put(n)\n } else {\n // already gc'd\n throw new Error(\n 'DS reached an inconsistent state. Please report this issue!'\n )\n }\n }\n } else {\n // no overlapping, already deleted\n return n\n }\n } else {\n // cannot extend left (there is no left!)\n n = new DSNode(id, length, false)\n this.put(n) // TODO: you double-put !!\n }\n } else {\n // cannot extend left\n n = new DSNode(id, length, false)\n this.put(n)\n }\n // can extend right?\n var next = this.findNext(n._id)\n if (\n next != null &&\n n._id.user === next._id.user &&\n n._id.clock + n.len >= next._id.clock\n ) {\n diff = n._id.clock + n.len - next._id.clock // from next.start to n.end\n while (diff >= 0) {\n // n overlaps with next\n if (next.gc) {\n // gc is stronger, so reduce length of n\n n.len -= diff\n if (diff >= next.len) {\n // delete the missing range after next\n diff = diff - next.len // missing range after next\n if (diff > 0) {\n this.put(n) // unneccessary? TODO!\n this.markDeleted(new ID(next._id.user, next._id.clock + next.len), diff)\n }\n }\n break\n } else {\n // we can extend n with next\n if (diff > next.len) {\n // n is even longer than next\n // get next.next, and try to extend it\n var _next = this.findNext(next._id)\n this.delete(next._id)\n if (_next == null || n._id.user !== _next._id.user) {\n break\n } else {\n next = _next\n diff = n._id.clock + n.len - next._id.clock // from next.start to n.end\n // continue!\n }\n } else {\n // n just partially overlaps with next. extend n, delete next, and break this loop\n n.len += next.len - diff\n this.delete(next._id)\n break\n }\n }\n }\n }\n this.put(n)\n return n\n }\n}\n","import ID from '../Util/ID.js'\nimport { default as RootID, RootFakeUserID } from '../Util/RootID.js'\n\nexport default class BinaryDecoder {\n constructor (buffer) {\n if (buffer instanceof ArrayBuffer) {\n this.uint8arr = new Uint8Array(buffer)\n } else if (buffer instanceof Uint8Array || (typeof Buffer !== 'undefined' && buffer instanceof Buffer)) {\n this.uint8arr = buffer\n } else {\n throw new Error('Expected an ArrayBuffer or Uint8Array!')\n }\n this.pos = 0\n }\n /**\n * Clone this decoder instance\n * Optionally set a new position parameter\n */\n clone (newPos = this.pos) {\n let decoder = new BinaryDecoder(this.uint8arr)\n decoder.pos = newPos\n return decoder\n }\n /**\n * Number of bytes\n */\n get length () {\n return this.uint8arr.length\n }\n /**\n * Skip one byte, jump to the next position\n */\n skip8 () {\n this.pos++\n }\n /**\n * Read one byte as unsigned integer\n */\n readUint8 () {\n return this.uint8arr[this.pos++]\n }\n /**\n * Read 4 bytes as unsigned integer\n */\n readUint32 () {\n let uint =\n this.uint8arr[this.pos] +\n (this.uint8arr[this.pos + 1] << 8) +\n (this.uint8arr[this.pos + 2] << 16) +\n (this.uint8arr[this.pos + 3] << 24)\n this.pos += 4\n return uint\n }\n /**\n * Look ahead without incrementing position\n * to the next byte and read it as unsigned integer\n */\n peekUint8 () {\n return this.uint8arr[this.pos]\n }\n /**\n * Read unsigned integer (32bit) with variable length\n * 1/8th of the storage is used as encoding overhead\n * - numbers < 2^7 is stored in one byte\n * - numbers < 2^14 is stored in two bytes\n * ..\n */\n readVarUint () {\n let num = 0\n let len = 0\n while (true) {\n let r = this.uint8arr[this.pos++]\n num = num | ((r & 0b1111111) << len)\n len += 7\n if (r < 1 << 7) {\n return num >>> 0 // return unsigned number!\n }\n if (len > 35) {\n throw new Error('Integer out of range!')\n }\n }\n }\n /**\n * Read string of variable length\n * - varUint is used to store the length of the string\n */\n readVarString () {\n let len = this.readVarUint()\n let bytes = new Array(len)\n for (let i = 0; i < len; i++) {\n bytes[i] = this.uint8arr[this.pos++]\n }\n let encodedString = String.fromCodePoint(...bytes)\n return decodeURIComponent(escape(encodedString))\n }\n /**\n * Look ahead and read varString without incrementing position\n */\n peekVarString () {\n let pos = this.pos\n let s = this.readVarString()\n this.pos = pos\n return s\n }\n /**\n * Read ID\n * - If first varUint read is 0xFFFFFF a RootID is returned\n * - Otherwise an ID is returned\n */\n readID () {\n let user = this.readVarUint()\n if (user === RootFakeUserID) {\n // read property name and type id\n const rid = new RootID(this.readVarString(), null)\n rid.type = this.readVarUint()\n return rid\n }\n return new ID(user, this.readVarUint())\n }\n}\n","import { getStruct } from '../Util/structReferences.js'\nimport BinaryDecoder from '../Binary/Decoder.js'\nimport { logID } from './messageToString.js'\n\nclass MissingEntry {\n constructor (decoder, missing, struct) {\n this.decoder = decoder\n this.missing = missing.length\n this.struct = struct\n }\n}\n\n/**\n * Integrate remote struct\n * When a remote struct is integrated, other structs might be ready to ready to\n * integrate.\n */\nfunction _integrateRemoteStructHelper (y, struct) {\n const id = struct._id\n if (id === undefined) {\n struct._integrate(y)\n } else {\n if (y.ss.getState(id.user) > id.clock) {\n return\n }\n struct._integrate(y)\n let msu = y._missingStructs.get(id.user)\n if (msu != null) {\n let clock = id.clock\n const finalClock = clock + struct._length\n for (;clock < finalClock; clock++) {\n const missingStructs = msu.get(clock)\n if (missingStructs !== undefined) {\n missingStructs.forEach(missingDef => {\n missingDef.missing--\n if (missingDef.missing === 0) {\n const decoder = missingDef.decoder\n let oldPos = decoder.pos\n let missing = missingDef.struct._fromBinary(y, decoder)\n decoder.pos = oldPos\n if (missing.length === 0) {\n y._readyToIntegrate.push(missingDef.struct)\n }\n }\n })\n msu.delete(clock)\n }\n }\n }\n }\n}\n\nexport function stringifyStructs (y, decoder, strBuilder) {\n const len = decoder.readUint32()\n for (let i = 0; i < len; i++) {\n let reference = decoder.readVarUint()\n let Constr = getStruct(reference)\n let struct = new Constr()\n let missing = struct._fromBinary(y, decoder)\n let logMessage = ' ' + struct._logString()\n if (missing.length > 0) {\n logMessage += ' .. missing: ' + missing.map(logID).join(', ')\n }\n strBuilder.push(logMessage)\n }\n}\n\nexport function integrateRemoteStructs (y, decoder) {\n const len = decoder.readUint32()\n for (let i = 0; i < len; i++) {\n let reference = decoder.readVarUint()\n let Constr = getStruct(reference)\n let struct = new Constr()\n let decoderPos = decoder.pos\n let missing = struct._fromBinary(y, decoder)\n if (missing.length === 0) {\n while (struct != null) {\n _integrateRemoteStructHelper(y, struct)\n struct = y._readyToIntegrate.shift()\n }\n } else {\n let _decoder = new BinaryDecoder(decoder.uint8arr)\n _decoder.pos = decoderPos\n let missingEntry = new MissingEntry(_decoder, missing, struct)\n let missingStructs = y._missingStructs\n for (let i = missing.length - 1; i >= 0; i--) {\n let m = missing[i]\n if (!missingStructs.has(m.user)) {\n missingStructs.set(m.user, new Map())\n }\n let msu = missingStructs.get(m.user)\n if (!msu.has(m.clock)) {\n msu.set(m.clock, [])\n }\n let mArray = msu = msu.get(m.clock)\n mArray.push(missingEntry)\n }\n }\n }\n}\n","import { RootFakeUserID } from '../Util/RootID.js'\n\nconst bits7 = 0b1111111\nconst bits8 = 0b11111111\n\nexport default class BinaryEncoder {\n constructor () {\n // TODO: implement chained Uint8Array buffers instead of Array buffer\n this.data = []\n }\n\n get length () {\n return this.data.length\n }\n\n get pos () {\n return this.data.length\n }\n\n createBuffer () {\n return Uint8Array.from(this.data).buffer\n }\n\n writeUint8 (num) {\n this.data.push(num & bits8)\n }\n\n setUint8 (pos, num) {\n this.data[pos] = num & bits8\n }\n\n writeUint16 (num) {\n this.data.push(num & bits8, (num >>> 8) & bits8)\n }\n\n setUint16 (pos, num) {\n this.data[pos] = num & bits8\n this.data[pos + 1] = (num >>> 8) & bits8\n }\n\n writeUint32 (num) {\n for (let i = 0; i < 4; i++) {\n this.data.push(num & bits8)\n num >>>= 8\n }\n }\n\n setUint32 (pos, num) {\n for (let i = 0; i < 4; i++) {\n this.data[pos + i] = num & bits8\n num >>>= 8\n }\n }\n\n writeVarUint (num) {\n while (num >= 0b10000000) {\n this.data.push(0b10000000 | (bits7 & num))\n num >>>= 7\n }\n this.data.push(bits7 & num)\n }\n\n writeVarString (str) {\n let encodedString = unescape(encodeURIComponent(str))\n let bytes = encodedString.split('').map(c => c.codePointAt())\n let len = bytes.length\n this.writeVarUint(len)\n for (let i = 0; i < len; i++) {\n this.data.push(bytes[i])\n }\n }\n\n writeID (id) {\n const user = id.user\n this.writeVarUint(user)\n if (user !== RootFakeUserID) {\n this.writeVarUint(id.clock)\n } else {\n this.writeVarString(id.name)\n this.writeVarUint(id.type)\n }\n }\n}\n","\nexport function readStateSet (decoder) {\n let ss = new Map()\n let ssLength = decoder.readUint32()\n for (let i = 0; i < ssLength; i++) {\n let user = decoder.readVarUint()\n let clock = decoder.readVarUint()\n ss.set(user, clock)\n }\n return ss\n}\n\nexport function writeStateSet (y, encoder) {\n let lenPosition = encoder.pos\n let len = 0\n encoder.writeUint32(0)\n for (let [user, clock] of y.ss.state) {\n encoder.writeVarUint(user)\n encoder.writeVarUint(clock)\n len++\n }\n encoder.setUint32(lenPosition, len)\n}\n","import { deleteItemRange } from '../Struct/Delete.js'\nimport ID from '../Util/ID.js'\n\nexport function stringifyDeleteSet (y, decoder, strBuilder) {\n let dsLength = decoder.readUint32()\n for (let i = 0; i < dsLength; i++) {\n let user = decoder.readVarUint()\n strBuilder.push(' -' + user + ':')\n let dvLength = decoder.readVarUint()\n for (let j = 0; j < dvLength; j++) {\n let from = decoder.readVarUint()\n let len = decoder.readVarUint()\n let gc = decoder.readUint8() === 1\n strBuilder.push(`clock: ${from}, length: ${len}, gc: ${gc}`)\n }\n }\n return strBuilder\n}\n\nexport function writeDeleteSet (y, encoder) {\n let currentUser = null\n let currentLength\n let lastLenPos\n\n let numberOfUsers = 0\n let laterDSLenPus = encoder.pos\n encoder.writeUint32(0)\n\n y.ds.iterate(null, null, function (n) {\n var user = n._id.user\n var clock = n._id.clock\n var len = n.len\n var gc = n.gc\n if (currentUser !== user) {\n numberOfUsers++\n // a new user was found\n if (currentUser !== null) { // happens on first iteration\n encoder.setUint32(lastLenPos, currentLength)\n }\n currentUser = user\n encoder.writeVarUint(user)\n // pseudo-fill pos\n lastLenPos = encoder.pos\n encoder.writeUint32(0)\n currentLength = 0\n }\n encoder.writeVarUint(clock)\n encoder.writeVarUint(len)\n encoder.writeUint8(gc ? 1 : 0)\n currentLength++\n })\n if (currentUser !== null) { // happens on first iteration\n encoder.setUint32(lastLenPos, currentLength)\n }\n encoder.setUint32(laterDSLenPus, numberOfUsers)\n}\n\nexport function readDeleteSet (y, decoder) {\n let dsLength = decoder.readUint32()\n for (let i = 0; i < dsLength; i++) {\n let user = decoder.readVarUint()\n let dv = []\n let dvLength = decoder.readUint32()\n for (let j = 0; j < dvLength; j++) {\n let from = decoder.readVarUint()\n let len = decoder.readVarUint()\n let gc = decoder.readUint8() === 1\n dv.push([from, len, gc])\n }\n if (dvLength > 0) {\n let pos = 0\n let d = dv[pos]\n let deletions = []\n y.ds.iterate(new ID(user, 0), new ID(user, Number.MAX_VALUE), function (n) {\n // cases:\n // 1. d deletes something to the right of n\n // => go to next n (break)\n // 2. d deletes something to the left of n\n // => create deletions\n // => reset d accordingly\n // *)=> if d doesn't delete anything anymore, go to next d (continue)\n // 3. not 2) and d deletes something that also n deletes\n // => reset d so that it doesn't contain n's deletion\n // *)=> if d does not delete anything anymore, go to next d (continue)\n while (d != null) {\n var diff = 0 // describe the diff of length in 1) and 2)\n if (n._id.clock + n.len <= d[0]) {\n // 1)\n break\n } else if (d[0] < n._id.clock) {\n // 2)\n // delete maximum the len of d\n // else delete as much as possible\n diff = Math.min(n._id.clock - d[0], d[1])\n // deleteItemRange(y, user, d[0], diff)\n deletions.push([user, d[0], diff])\n } else {\n // 3)\n diff = n._id.clock + n.len - d[0] // never null (see 1)\n if (d[2] && !n.gc) {\n // d marks as gc'd but n does not\n // then delete either way\n // deleteItemRange(y, user, d[0], Math.min(diff, d[1]))\n deletions.push([user, d[0], Math.min(diff, d[1])])\n }\n }\n if (d[1] <= diff) {\n // d doesn't delete anything anymore\n d = dv[++pos]\n } else {\n d[0] = d[0] + diff // reset pos\n d[1] = d[1] - diff // reset length\n }\n }\n })\n // TODO: It would be more performant to apply the deletes in the above loop\n // Adapt the Tree implementation to support delete while iterating\n for (let i = deletions.length - 1; i >= 0; i--) {\n const del = deletions[i]\n deleteItemRange(y, del[0], del[1], del[2])\n }\n // for the rest.. just apply it\n for (; pos < dv.length; pos++) {\n d = dv[pos]\n deleteItemRange(y, user, d[0], d[1])\n // deletions.push([user, d[0], d[1], d[2]])\n }\n }\n }\n}\n","import BinaryEncoder from '../Binary/Encoder.js'\nimport { readStateSet, writeStateSet } from './stateSet.js'\nimport { writeDeleteSet } from './deleteSet.js'\nimport ID from '../Util/ID.js'\nimport { RootFakeUserID } from '../Util/RootID.js'\n\nexport function stringifySyncStep1 (y, decoder, strBuilder) {\n let auth = decoder.readVarString()\n let protocolVersion = decoder.readVarUint()\n strBuilder.push(` - auth: \"${auth}\"`)\n strBuilder.push(` - protocolVersion: ${protocolVersion}`)\n // write SS\n let ssBuilder = []\n let len = decoder.readUint32()\n for (let i = 0; i < len; i++) {\n let user = decoder.readVarUint()\n let clock = decoder.readVarUint()\n ssBuilder.push(`(${user}:${clock})`)\n }\n strBuilder.push(' == SS: ' + ssBuilder.join(','))\n}\n\nexport function sendSyncStep1 (connector, syncUser) {\n let encoder = new BinaryEncoder()\n encoder.writeVarString(connector.y.room)\n encoder.writeVarString('sync step 1')\n encoder.writeVarString(connector.authInfo || '')\n encoder.writeVarUint(connector.protocolVersion)\n writeStateSet(connector.y, encoder)\n connector.send(syncUser, encoder.createBuffer())\n}\n\nexport function writeStructs (y, encoder, ss) {\n const lenPos = encoder.pos\n encoder.writeUint32(0)\n let len = 0\n for (let user of y.ss.state.keys()) {\n let clock = ss.get(user) || 0\n if (user !== RootFakeUserID) {\n y.os.iterate(new ID(user, clock), new ID(user, Number.MAX_VALUE), function (struct) {\n struct._toBinary(encoder)\n len++\n })\n }\n }\n encoder.setUint32(lenPos, len)\n}\n\nexport function readSyncStep1 (decoder, encoder, y, senderConn, sender) {\n let protocolVersion = decoder.readVarUint()\n // check protocol version\n if (protocolVersion !== y.connector.protocolVersion) {\n console.warn(\n `You tried to sync with a Yjs instance that has a different protocol version\n (You: ${protocolVersion}, Client: ${protocolVersion}).\n `)\n y.destroy()\n }\n // write sync step 2\n encoder.writeVarString('sync step 2')\n encoder.writeVarString(y.connector.authInfo || '')\n const ss = readStateSet(decoder)\n writeStructs(y, encoder, ss)\n writeDeleteSet(y, encoder)\n y.connector.send(senderConn.uid, encoder.createBuffer())\n senderConn.receivedSyncStep2 = true\n if (y.connector.role === 'slave') {\n sendSyncStep1(y.connector, sender)\n }\n}\n","import { stringifyStructs, integrateRemoteStructs } from './integrateRemoteStructs.js'\nimport { readDeleteSet } from './deleteSet.js'\n\nexport function stringifySyncStep2 (y, decoder, strBuilder) {\n strBuilder.push(' - auth: ' + decoder.readVarString())\n strBuilder.push(' == OS:')\n stringifyStructs(y, decoder, strBuilder)\n // write DS to string\n strBuilder.push(' == DS:')\n let len = decoder.readUint32()\n for (let i = 0; i < len; i++) {\n let user = decoder.readVarUint()\n strBuilder.push(` User: ${user}: `)\n let len2 = decoder.readUint32()\n for (let j = 0; j < len2; j++) {\n let from = decoder.readVarUint()\n let to = decoder.readVarUint()\n let gc = decoder.readUint8() === 1\n strBuilder.push(`[${from}, ${to}, ${gc}]`)\n }\n }\n}\n\nexport function readSyncStep2 (decoder, encoder, y, senderConn, sender) {\n integrateRemoteStructs(y, decoder)\n readDeleteSet(y, decoder)\n y.connector._setSyncedWith(sender)\n}\n","import BinaryDecoder from '../Binary/Decoder.js'\nimport { stringifyStructs } from './integrateRemoteStructs.js'\nimport { stringifySyncStep1 } from './syncStep1.js'\nimport { stringifySyncStep2 } from './syncStep2.js'\nimport ID from '../Util/ID.js'\nimport RootID from '../Util/RootID.js'\nimport Y from '../Y.js'\n\nexport function messageToString ([y, buffer]) {\n let decoder = new BinaryDecoder(buffer)\n decoder.readVarString() // read roomname\n let type = decoder.readVarString()\n let strBuilder = []\n strBuilder.push('\\n === ' + type + ' ===')\n if (type === 'update') {\n stringifyStructs(y, decoder, strBuilder)\n } else if (type === 'sync step 1') {\n stringifySyncStep1(y, decoder, strBuilder)\n } else if (type === 'sync step 2') {\n stringifySyncStep2(y, decoder, strBuilder)\n } else {\n strBuilder.push('-- Unknown message type - probably an encoding issue!!!')\n }\n return strBuilder.join('\\n')\n}\n\nexport function messageToRoomname (buffer) {\n let decoder = new BinaryDecoder(buffer)\n decoder.readVarString() // roomname\n return decoder.readVarString() // messageType\n}\n\nexport function logID (id) {\n if (id !== null && id._id != null) {\n id = id._id\n }\n if (id === null) {\n return '()'\n } else if (id instanceof ID) {\n return `(${id.user},${id.clock})`\n } else if (id instanceof RootID) {\n return `(${id.name},${id.type})`\n } else if (id.constructor === Y) {\n return `y`\n } else {\n throw new Error('This is not a valid ID!')\n }\n}\n","import { getReference } from '../Util/structReferences.js'\nimport ID from '../Util/ID.js'\nimport { logID } from '../MessageHandler/messageToString.js'\n\n/**\n * Delete all items in an ID-range\n * TODO: implement getItemCleanStartNode for better performance (only one lookup)\n */\nexport function deleteItemRange (y, user, clock, range) {\n const createDelete = y.connector !== null && y.connector._forwardAppliedStructs\n let item = y.os.getItemCleanStart(new ID(user, clock))\n if (item !== null) {\n if (!item._deleted) {\n item._splitAt(y, range)\n item._delete(y, createDelete)\n }\n let itemLen = item._length\n range -= itemLen\n clock += itemLen\n if (range > 0) {\n let node = y.os.findNode(new ID(user, clock))\n while (node !== null && range > 0 && node.val._id.equals(new ID(user, clock))) {\n const nodeVal = node.val\n if (!nodeVal._deleted) {\n nodeVal._splitAt(y, range)\n nodeVal._delete(y, createDelete)\n }\n const nodeLen = nodeVal._length\n range -= nodeLen\n clock += nodeLen\n node = node.next()\n }\n }\n }\n}\n\n/**\n * Delete is not a real struct. It will not be saved in OS\n */\nexport default class Delete {\n constructor () {\n this._target = null\n this._length = null\n }\n _fromBinary (y, decoder) {\n // TODO: set target, and add it to missing if not found\n // There is an edge case in p2p networks!\n const targetID = decoder.readID()\n this._targetID = targetID\n this._length = decoder.readVarUint()\n if (y.os.getItem(targetID) === null) {\n return [targetID]\n } else {\n return []\n }\n }\n _toBinary (encoder) {\n encoder.writeUint8(getReference(this.constructor))\n encoder.writeID(this._targetID)\n encoder.writeVarUint(this._length)\n }\n /**\n * - If created remotely (a remote user deleted something),\n * this Delete is applied to all structs in id-range.\n * - If created lokally (e.g. when y-array deletes a range of elements),\n * this struct is broadcasted only (it is already executed)\n */\n _integrate (y, locallyCreated = false) {\n if (!locallyCreated) {\n // from remote\n const id = this._targetID\n deleteItemRange(y, id.user, id.clock, this._length)\n } else if (y.connector !== null) {\n // from local\n y.connector.broadcastStruct(this)\n }\n if (y.persistence !== null) {\n y.persistence.saveStruct(y, this)\n }\n }\n _logString () {\n return `Delete - target: ${logID(this._targetID)}, len: ${this._length}`\n }\n}\n","\nexport default class Transaction {\n constructor (y) {\n this.y = y\n // types added during transaction\n this.newTypes = new Set()\n // changed types (does not include new types)\n // maps from type to parentSubs (item._parentSub = null for array elements)\n this.changedTypes = new Map()\n this.deletedStructs = new Set()\n this.beforeState = new Map()\n this.changedParentTypes = new Map()\n }\n}\n\nexport function transactionTypeChanged (y, type, sub) {\n if (type !== y && !type._deleted && !y._transaction.newTypes.has(type)) {\n const changedTypes = y._transaction.changedTypes\n let subs = changedTypes.get(type)\n if (subs === undefined) {\n // create if it doesn't exist yet\n subs = new Set()\n changedTypes.set(type, subs)\n }\n subs.add(sub)\n }\n}\n","import { getReference } from '../Util/structReferences.js'\nimport ID from '../Util/ID.js'\nimport { RootFakeUserID } from '../Util/RootID.js'\nimport Delete from './Delete.js'\nimport { transactionTypeChanged } from '../Transaction.js'\n\n/**\n * Helper utility to split an Item (see _splitAt)\n * - copy all properties from a to b\n * - connect a to b\n * - assigns the correct _id\n * - save b to os\n */\nexport function splitHelper (y, a, b, diff) {\n const aID = a._id\n b._id = new ID(aID.user, aID.clock + diff)\n b._origin = a\n b._left = a\n b._right = a._right\n if (b._right !== null) {\n b._right._left = b\n }\n b._right_origin = a._right_origin\n // do not set a._right_origin, as this will lead to problems when syncing\n a._right = b\n b._parent = a._parent\n b._parentSub = a._parentSub\n b._deleted = a._deleted\n // now search all relevant items to the right and update origin\n // if origin is not it foundOrigins, we don't have to search any longer\n let foundOrigins = new Set()\n foundOrigins.add(a)\n let o = b._right\n while (o !== null && foundOrigins.has(o._origin)) {\n if (o._origin === a) {\n o._origin = b\n }\n foundOrigins.add(o)\n o = o._right\n }\n y.os.put(b)\n}\n\nexport default class Item {\n constructor () {\n this._id = null\n this._origin = null\n this._left = null\n this._right = null\n this._right_origin = null\n this._parent = null\n this._parentSub = null\n this._deleted = false\n this._redone = null\n }\n /**\n * Create a operation with the same effect (without position effect)\n */\n _copy () {\n return new this.constructor()\n }\n /**\n * Redo the effect of this operation.\n */\n _redo (y) {\n if (this._redone !== null) {\n return this._redone\n }\n let struct = this._copy()\n let left = this._left\n let right = this\n let parent = this._parent\n // make sure that parent is redone\n if (parent._deleted === true && parent._redone === null) {\n parent._redo(y)\n }\n if (parent._redone !== null) {\n parent = parent._redone\n // find next cloned items\n while (left !== null) {\n if (left._redone !== null && left._redone._parent === parent) {\n left = left._redone\n break\n }\n left = left._left\n }\n while (right !== null) {\n if (right._redone !== null && right._redone._parent === parent) {\n right = right._redone\n }\n right = right._right\n }\n }\n struct._origin = left\n struct._left = left\n struct._right = right\n struct._right_origin = right\n struct._parent = parent\n struct._parentSub = this._parentSub\n struct._integrate(y)\n this._redone = struct\n return struct\n }\n\n get _lastId () {\n return new ID(this._id.user, this._id.clock + this._length - 1)\n }\n get _length () {\n return 1\n }\n /**\n * Splits this struct so that another struct can be inserted in-between.\n * This must be overwritten if _length > 1\n * Returns right part after split\n * - diff === 0 => this\n * - diff === length => this._right\n * - otherwise => split _content and return right part of split\n * (see ItemJSON/ItemString for implementation)\n */\n _splitAt (y, diff) {\n if (diff === 0) {\n return this\n }\n return this._right\n }\n _delete (y, createDelete = true) {\n if (!this._deleted) {\n this._deleted = true\n y.ds.markDeleted(this._id, this._length)\n let del = new Delete()\n del._targetID = this._id\n del._length = this._length\n if (createDelete) {\n // broadcast and persists Delete\n del._integrate(y, true)\n } else if (y.persistence !== null) {\n // only persist Delete\n y.persistence.saveStruct(y, del)\n }\n transactionTypeChanged(y, this._parent, this._parentSub)\n y._transaction.deletedStructs.add(this)\n }\n }\n /**\n * This is called right before this struct receives any children.\n * It can be overwritten to apply pending changes before applying remote changes\n */\n _beforeChange () {\n // nop\n }\n /*\n * - Integrate the struct so that other types/structs can see it\n * - Add this struct to y.os\n * - Check if this is struct deleted\n */\n _integrate (y) {\n y._transaction.newTypes.add(this)\n const parent = this._parent\n const selfID = this._id\n const user = selfID === null ? y.userID : selfID.user\n const userState = y.ss.getState(user)\n if (selfID === null) {\n this._id = y.ss.getNextID(this._length)\n } else if (selfID.user === RootFakeUserID) {\n // nop\n } else if (selfID.clock < userState) {\n // already applied..\n return []\n } else if (selfID.clock === userState) {\n y.ss.setState(selfID.user, userState + this._length)\n } else {\n // missing content from user\n throw new Error('Can not apply yet!')\n }\n if (!parent._deleted && !y._transaction.changedTypes.has(parent) && !y._transaction.newTypes.has(parent)) {\n // this is the first time parent is updated\n // or this types is new\n this._parent._beforeChange()\n }\n /*\n # $this has to find a unique position between origin and the next known character\n # case 1: $origin equals $o.origin: the $creator parameter decides if left or right\n # let $OL= [o1,o2,o3,o4], whereby $this is to be inserted between o1 and o4\n # o2,o3 and o4 origin is 1 (the position of o2)\n # there is the case that $this.creator < o2.creator, but o3.creator < $this.creator\n # then o2 knows o3. Since on another client $OL could be [o1,o3,o4] the problem is complex\n # therefore $this would be always to the right of o3\n # case 2: $origin < $o.origin\n # if current $this insert_position > $o origin: $this ins\n # else $insert_position will not change\n # (maybe we encounter case 1 later, then this will be to the right of $o)\n # case 3: $origin > $o.origin\n # $this insert_position is to the left of $o (forever!)\n */\n // handle conflicts\n let o\n // set o to the first conflicting item\n if (this._left !== null) {\n o = this._left._right\n } else if (this._parentSub !== null) {\n o = this._parent._map.get(this._parentSub) || null\n } else {\n o = this._parent._start\n }\n let conflictingItems = new Set()\n let itemsBeforeOrigin = new Set()\n // Let c in conflictingItems, b in itemsBeforeOrigin\n // ***{origin}bbbb{this}{c,b}{c,b}{o}***\n // Note that conflictingItems is a subset of itemsBeforeOrigin\n while (o !== null && o !== this._right) {\n itemsBeforeOrigin.add(o)\n conflictingItems.add(o)\n if (this._origin === o._origin) {\n // case 1\n if (o._id.user < this._id.user) {\n this._left = o\n conflictingItems.clear()\n }\n } else if (itemsBeforeOrigin.has(o._origin)) {\n // case 2\n if (!conflictingItems.has(o._origin)) {\n this._left = o\n conflictingItems.clear()\n }\n } else {\n break\n }\n // TODO: try to use right_origin instead.\n // Then you could basically omit conflictingItems!\n // Note: you probably can't use right_origin in every case.. only when setting _left\n o = o._right\n }\n // reconnect left/right + update parent map/start if necessary\n const parentSub = this._parentSub\n if (this._left === null) {\n let right\n if (parentSub !== null) {\n const pmap = parent._map\n right = pmap.get(parentSub) || null\n pmap.set(parentSub, this)\n } else {\n right = parent._start\n parent._start = this\n }\n this._right = right\n if (right !== null) {\n right._left = this\n }\n } else {\n const left = this._left\n const right = left._right\n this._right = right\n left._right = this\n if (right !== null) {\n right._left = this\n }\n }\n if (parent._deleted) {\n this._delete(y, false)\n }\n y.os.put(this)\n transactionTypeChanged(y, parent, parentSub)\n if (this._id.user !== RootFakeUserID) {\n if (y.connector !== null && (y.connector._forwardAppliedStructs || this._id.user === y.userID)) {\n y.connector.broadcastStruct(this)\n }\n if (y.persistence !== null) {\n y.persistence.saveStruct(y, this)\n }\n }\n }\n _toBinary (encoder) {\n encoder.writeUint8(getReference(this.constructor))\n let info = 0\n if (this._origin !== null) {\n info += 0b1 // origin is defined\n }\n // TODO: remove\n /* no longer send _left\n if (this._left !== this._origin) {\n info += 0b10 // do not copy origin to left\n }\n */\n if (this._right_origin !== null) {\n info += 0b100\n }\n if (this._parentSub !== null) {\n info += 0b1000\n }\n encoder.writeUint8(info)\n encoder.writeID(this._id)\n if (info & 0b1) {\n encoder.writeID(this._origin._lastId)\n }\n // TODO: remove\n /* see above\n if (info & 0b10) {\n encoder.writeID(this._left._lastId)\n }\n */\n if (info & 0b100) {\n encoder.writeID(this._right_origin._id)\n }\n if ((info & 0b101) === 0) {\n // neither origin nor right is defined\n encoder.writeID(this._parent._id)\n }\n if (info & 0b1000) {\n encoder.writeVarString(JSON.stringify(this._parentSub))\n }\n }\n _fromBinary (y, decoder) {\n let missing = []\n const info = decoder.readUint8()\n const id = decoder.readID()\n this._id = id\n // read origin\n if (info & 0b1) {\n // origin != null\n const originID = decoder.readID()\n // we have to query for left again because it might have been split/merged..\n const origin = y.os.getItemCleanEnd(originID)\n if (origin === null) {\n missing.push(originID)\n } else {\n this._origin = origin\n this._left = this._origin\n }\n }\n // read right\n if (info & 0b100) {\n // right != null\n const rightID = decoder.readID()\n // we have to query for right again because it might have been split/merged..\n const right = y.os.getItemCleanStart(rightID)\n if (right === null) {\n missing.push(rightID)\n } else {\n this._right = right\n this._right_origin = right\n }\n }\n // read parent\n if ((info & 0b101) === 0) {\n // neither origin nor right is defined\n const parentID = decoder.readID()\n // parent does not change, so we don't have to search for it again\n if (this._parent === null) {\n const parent = y.os.get(parentID)\n if (parent === null) {\n missing.push(parentID)\n } else {\n this._parent = parent\n }\n }\n } else if (this._parent === null) {\n if (this._origin !== null) {\n this._parent = this._origin._parent\n } else if (this._right_origin !== null) {\n this._parent = this._right_origin._parent\n }\n }\n if (info & 0b1000) {\n // TODO: maybe put this in read parent condition (you can also read parentsub from left/right)\n this._parentSub = JSON.parse(decoder.readVarString())\n }\n if (y.ss.getState(id.user) < id.clock) {\n missing.push(new ID(id.user, id.clock - 1))\n }\n return missing\n }\n}\n","\nexport default class EventHandler {\n constructor () {\n this.eventListeners = []\n }\n destroy () {\n this.eventListeners = null\n }\n addEventListener (f) {\n this.eventListeners.push(f)\n }\n removeEventListener (f) {\n this.eventListeners = this.eventListeners.filter(function (g) {\n return f !== g\n })\n }\n removeAllEventListeners () {\n this.eventListeners = []\n }\n callEventListeners (transaction, event) {\n for (var i = 0; i < this.eventListeners.length; i++) {\n try {\n const f = this.eventListeners[i]\n f(event)\n } catch (e) {\n /*\n Your observer threw an error. This error was caught so that Yjs\n can ensure data consistency! In order to debug this error you\n have to check \"Pause On Caught Exceptions\" in developer tools.\n */\n console.error(e)\n }\n }\n }\n}\n","import Item from './Item.js'\nimport EventHandler from '../Util/EventHandler.js'\nimport ID from '../Util/ID.js'\n\n// restructure children as if they were inserted one after another\nfunction integrateChildren (y, start) {\n let right\n do {\n right = start._right\n start._right = null\n start._right_origin = null\n start._origin = start._left\n start._integrate(y)\n start = right\n } while (right !== null)\n}\n\nexport function getListItemIDByPosition (type, i) {\n let pos = 0\n let n = type._start\n while (n !== null) {\n if (!n._deleted) {\n if (pos <= i && i < pos + n._length) {\n const id = n._id\n return new ID(id.user, id.clock + i - pos)\n }\n pos++\n }\n n = n._right\n }\n}\n\nexport default class Type extends Item {\n constructor () {\n super()\n this._map = new Map()\n this._start = null\n this._y = null\n this._eventHandler = new EventHandler()\n this._deepEventHandler = new EventHandler()\n }\n getPathTo (type) {\n if (type === this) {\n return []\n }\n const path = []\n const y = this._y\n while (type._parent !== this && this._parent !== y) {\n let parent = type._parent\n if (type._parentSub !== null) {\n path.push(type._parentSub)\n } else {\n // parent is array-ish\n for (let [i, child] of parent) {\n if (child === type) {\n path.push(i)\n break\n }\n }\n }\n type = parent\n }\n if (this._parent !== this) {\n throw new Error('The type is not a child of this node')\n }\n return path\n }\n _callEventHandler (transaction, event) {\n const changedParentTypes = transaction.changedParentTypes\n this._eventHandler.callEventListeners(transaction, event)\n let type = this\n while (type !== this._y) {\n let events = changedParentTypes.get(type)\n if (events === undefined) {\n events = []\n changedParentTypes.set(type, events)\n }\n events.push(event)\n type = type._parent\n }\n }\n _transact (f) {\n const y = this._y\n if (y !== null) {\n y.transact(f)\n } else {\n f(y)\n }\n }\n observe (f) {\n this._eventHandler.addEventListener(f)\n }\n observeDeep (f) {\n this._deepEventHandler.addEventListener(f)\n }\n unobserve (f) {\n this._eventHandler.removeEventListener(f)\n }\n unobserveDeep (f) {\n this._deepEventHandler.removeEventListener(f)\n }\n _integrate (y) {\n super._integrate(y)\n this._y = y\n // when integrating children we must make sure to\n // integrate start\n const start = this._start\n if (start !== null) {\n this._start = null\n integrateChildren(y, start)\n }\n // integrate map children\n const map = this._map\n this._map = new Map()\n for (let t of map.values()) {\n // TODO make sure that right elements are deleted!\n integrateChildren(y, t)\n }\n }\n _delete (y, createDelete) {\n super._delete(y, createDelete)\n y._transaction.changedTypes.delete(this)\n // delete map types\n for (let value of this._map.values()) {\n if (value instanceof Item && !value._deleted) {\n value._delete(y, false)\n }\n }\n // delete array types\n let t = this._start\n while (t !== null) {\n if (!t._deleted) {\n t._delete(y, false)\n }\n t = t._right\n }\n }\n}\n","import { splitHelper, default as Item } from './Item.js'\nimport { logID } from '../MessageHandler/messageToString.js'\n\nexport default class ItemJSON extends Item {\n constructor () {\n super()\n this._content = null\n }\n _copy () {\n let struct = super._copy()\n struct._content = this._content\n return struct\n }\n get _length () {\n return this._content.length\n }\n _fromBinary (y, decoder) {\n let missing = super._fromBinary(y, decoder)\n let len = decoder.readVarUint()\n this._content = new Array(len)\n for (let i = 0; i < len; i++) {\n const ctnt = decoder.readVarString()\n let parsed\n if (ctnt === 'undefined') {\n parsed = undefined\n } else {\n parsed = JSON.parse(ctnt)\n }\n this._content[i] = parsed\n }\n return missing\n }\n _toBinary (encoder) {\n super._toBinary(encoder)\n let len = this._content.length\n encoder.writeVarUint(len)\n for (let i = 0; i < len; i++) {\n let encoded\n let content = this._content[i]\n if (content === undefined) {\n encoded = 'undefined'\n } else {\n encoded = JSON.stringify(content)\n }\n encoder.writeVarString(encoded)\n }\n }\n _logString () {\n const left = this._left !== null ? this._left._lastId : null\n const origin = this._origin !== null ? this._origin._lastId : null\n return `ItemJSON(id:${logID(this._id)},content:${JSON.stringify(this._content)},left:${logID(left)},origin:${logID(origin)},right:${logID(this._right)},parent:${logID(this._parent)},parentSub:${this._parentSub})`\n }\n _splitAt (y, diff) {\n if (diff === 0) {\n return this\n } else if (diff >= this._length) {\n return this._right\n }\n let item = new ItemJSON()\n item._content = this._content.splice(diff)\n splitHelper(y, this, item, diff)\n return item\n }\n}\n","import { splitHelper, default as Item } from './Item.js'\nimport { logID } from '../MessageHandler/messageToString.js'\n\nexport default class ItemString extends Item {\n constructor () {\n super()\n this._content = null\n }\n _copy () {\n let struct = super._copy()\n struct._content = this._content\n return struct\n }\n get _length () {\n return this._content.length\n }\n _fromBinary (y, decoder) {\n let missing = super._fromBinary(y, decoder)\n this._content = decoder.readVarString()\n return missing\n }\n _toBinary (encoder) {\n super._toBinary(encoder)\n encoder.writeVarString(this._content)\n }\n _logString () {\n const left = this._left !== null ? this._left._lastId : null\n const origin = this._origin !== null ? this._origin._lastId : null\n return `ItemJSON(id:${logID(this._id)},content:${JSON.stringify(this._content)},left:${logID(left)},origin:${logID(origin)},right:${logID(this._right)},parent:${logID(this._parent)},parentSub:${this._parentSub})`\n }\n _splitAt (y, diff) {\n if (diff === 0) {\n return this\n } else if (diff >= this._length) {\n return this._right\n }\n let item = new ItemString()\n item._content = this._content.slice(diff)\n this._content = this._content.slice(0, diff)\n splitHelper(y, this, item, diff)\n return item\n }\n}\n","\nexport default class YEvent {\n constructor (target) {\n this.target = target\n this.currentTarget = target\n }\n get path () {\n const path = []\n let type = this.target\n const y = type._y\n while (type !== this.currentTarget && type !== y) {\n let parent = type._parent\n if (type._parentSub !== null) {\n path.unshift(type._parentSub)\n } else {\n // parent is array-ish\n for (let [i, child] of parent) {\n if (child === type) {\n path.unshift(i)\n break\n }\n }\n }\n type = parent\n }\n return path\n }\n}\n","import Type from '../Struct/Type.js'\nimport ItemJSON from '../Struct/ItemJSON.js'\nimport ItemString from '../Struct/ItemString.js'\nimport { logID } from '../MessageHandler/messageToString.js'\nimport YEvent from '../Util/YEvent.js'\n\nclass YArrayEvent extends YEvent {\n constructor (yarray, remote, transaction) {\n super(yarray)\n this.remote = remote\n this._transaction = transaction\n this._addedElements = null\n }\n get addedElements () {\n if (this._addedElements === null) {\n const target = this.target\n const transaction = this._transaction\n const addedElements = new Set()\n transaction.newTypes.forEach(function (type) {\n if (type._parent === target && !transaction.deletedStructs.has(type)) {\n addedElements.add(type)\n }\n })\n this._addedElements = addedElements\n }\n return this._addedElements\n }\n get removedElements () {\n const target = this.target\n const transaction = this._transaction\n const removedElements = new Set()\n transaction.deletedStructs.forEach(function (struct) {\n if (struct._parent === target && !transaction.newTypes.has(struct)) {\n removedElements.add(struct)\n }\n })\n return removedElements\n }\n}\n\nexport default class YArray extends Type {\n _callObserver (transaction, parentSubs, remote) {\n this._callEventHandler(transaction, new YArrayEvent(this, remote, transaction))\n }\n get (pos) {\n let n = this._start\n while (n !== null) {\n if (!n._deleted) {\n if (pos < n._length) {\n if (n.constructor === ItemJSON || n.constructor === ItemString) {\n return n._content[pos]\n } else {\n return n\n }\n }\n pos -= n._length\n }\n n = n._right\n }\n }\n toArray () {\n return this.map(c => c)\n }\n toJSON () {\n return this.map(c => {\n if (c instanceof Type) {\n if (c.toJSON !== null) {\n return c.toJSON()\n } else {\n return c.toString()\n }\n }\n return c\n })\n }\n map (f) {\n const res = []\n this.forEach((c, i) => {\n res.push(f(c, i, this))\n })\n return res\n }\n forEach (f) {\n let pos = 0\n let n = this._start\n while (n !== null) {\n if (!n._deleted) {\n if (n instanceof Type) {\n f(n, pos++, this)\n } else {\n const content = n._content\n const contentLen = content.length\n for (let i = 0; i < contentLen; i++) {\n pos++\n f(content[i], pos, this)\n }\n }\n }\n n = n._right\n }\n }\n get length () {\n let length = 0\n let n = this._start\n while (n !== null) {\n if (!n._deleted) {\n length += n._length\n }\n n = n._right\n }\n return length\n }\n [Symbol.iterator] () {\n return {\n next: function () {\n while (this._item !== null && (this._item._deleted || this._item._length <= this._itemElement)) {\n // item is deleted or itemElement does not exist (is deleted)\n this._item = this._item._right\n this._itemElement = 0\n }\n if (this._item === null) {\n return {\n done: true\n }\n }\n let content\n if (this._item instanceof Type) {\n content = this._item\n } else {\n content = this._item._content[this._itemElement++]\n }\n return {\n value: [this._count, content],\n done: false\n }\n },\n _item: this._start,\n _itemElement: 0,\n _count: 0\n }\n }\n delete (pos, length = 1) {\n this._y.transact(() => {\n let item = this._start\n let count = 0\n while (item !== null && length > 0) {\n if (!item._deleted) {\n if (count <= pos && pos < count + item._length) {\n const diffDel = pos - count\n item = item._splitAt(this._y, diffDel)\n item._splitAt(this._y, length)\n length -= item._length\n item._delete(this._y)\n count += diffDel\n } else {\n count += item._length\n }\n }\n item = item._right\n }\n })\n if (length > 0) {\n throw new Error('Delete exceeds the range of the YArray')\n }\n }\n insertAfter (left, content) {\n this._transact(y => {\n let right\n if (left === null) {\n right = this._start\n } else {\n right = left._right\n }\n let prevJsonIns = null\n for (let i = 0; i < content.length; i++) {\n let c = content[i]\n if (typeof c === 'function') {\n c = new c() // eslint-disable-line new-cap\n }\n if (c instanceof Type) {\n if (prevJsonIns !== null) {\n if (y !== null) {\n prevJsonIns._integrate(y)\n }\n left = prevJsonIns\n prevJsonIns = null\n }\n c._origin = left\n c._left = left\n c._right = right\n c._right_origin = right\n c._parent = this\n if (y !== null) {\n c._integrate(y)\n } else if (left === null) {\n this._start = c\n } else {\n left._right = c\n }\n left = c\n } else {\n if (prevJsonIns === null) {\n prevJsonIns = new ItemJSON()\n prevJsonIns._origin = left\n prevJsonIns._left = left\n prevJsonIns._right = right\n prevJsonIns._right_origin = right\n prevJsonIns._parent = this\n prevJsonIns._content = []\n }\n prevJsonIns._content.push(c)\n }\n }\n if (prevJsonIns !== null) {\n if (y !== null) {\n prevJsonIns._integrate(y)\n } else if (prevJsonIns._left === null) {\n this._start = prevJsonIns\n }\n }\n })\n }\n insert (pos, content) {\n let left = null\n let right = this._start\n let count = 0\n const y = this._y\n while (right !== null) {\n const rightLen = right._deleted ? 0 : (right._length - 1)\n if (count <= pos && pos <= count + rightLen) {\n const splitDiff = pos - count\n right = right._splitAt(y, splitDiff)\n left = right._left\n count += splitDiff\n break\n }\n if (!right._deleted) {\n count += right._length\n }\n left = right\n right = right._right\n }\n if (pos > count) {\n throw new Error('Position exceeds array range!')\n }\n this.insertAfter(left, content)\n }\n push (content) {\n let n = this._start\n let lastUndeleted = null\n while (n !== null) {\n if (!n._deleted) {\n lastUndeleted = n\n }\n n = n._right\n }\n this.insertAfter(lastUndeleted, content)\n }\n _logString () {\n const left = this._left !== null ? this._left._lastId : null\n const origin = this._origin !== null ? this._origin._lastId : null\n return `YArray(id:${logID(this._id)},start:${logID(this._start)},left:${logID(left)},origin:${logID(origin)},right:${logID(this._right)},parent:${logID(this._parent)},parentSub:${this._parentSub})`\n }\n}\n","import Type from '../Struct/Type.js'\nimport Item from '../Struct/Item.js'\nimport ItemJSON from '../Struct/ItemJSON.js'\nimport { logID } from '../MessageHandler/messageToString.js'\nimport YEvent from '../Util/YEvent.js'\n\nclass YMapEvent extends YEvent {\n constructor (ymap, subs, remote) {\n super(ymap)\n this.keysChanged = subs\n this.remote = remote\n }\n}\n\nexport default class YMap extends Type {\n _callObserver (transaction, parentSubs, remote) {\n this._callEventHandler(transaction, new YMapEvent(this, parentSubs, remote))\n }\n toJSON () {\n const map = {}\n for (let [key, item] of this._map) {\n if (!item._deleted) {\n let res\n if (item instanceof Type) {\n if (item.toJSON !== undefined) {\n res = item.toJSON()\n } else {\n res = item.toString()\n }\n } else {\n res = item._content[0]\n }\n map[key] = res\n }\n }\n return map\n }\n keys () {\n let keys = []\n for (let [key, value] of this._map) {\n if (!value._deleted) {\n keys.push(key)\n }\n }\n return keys\n }\n delete (key) {\n this._transact((y) => {\n let c = this._map.get(key)\n if (y !== null && c !== undefined) {\n c._delete(y)\n }\n })\n }\n set (key, value) {\n this._transact(y => {\n const old = this._map.get(key) || null\n if (old !== null) {\n if (old.constructor === ItemJSON && !old._deleted && old._content[0] === value) {\n // Trying to overwrite with same value\n // break here\n return value\n }\n if (y !== null) {\n old._delete(y)\n }\n }\n let v\n if (typeof value === 'function') {\n v = new value() // eslint-disable-line new-cap\n value = v\n } else if (value instanceof Item) {\n v = value\n } else {\n v = new ItemJSON()\n v._content = [value]\n }\n v._right = old\n v._right_origin = old\n v._parent = this\n v._parentSub = key\n if (y !== null) {\n v._integrate(y)\n } else {\n this._map.set(key, v)\n }\n })\n return value\n }\n get (key) {\n let v = this._map.get(key)\n if (v === undefined || v._deleted) {\n return undefined\n }\n if (v instanceof Type) {\n return v\n } else {\n return v._content[v._content.length - 1]\n }\n }\n has (key) {\n let v = this._map.get(key)\n if (v === undefined || v._deleted) {\n return false\n } else {\n return true\n }\n }\n _logString () {\n const left = this._left !== null ? this._left._lastId : null\n const origin = this._origin !== null ? this._origin._lastId : null\n return `YMap(id:${logID(this._id)},mapSize:${this._map.size},left:${logID(left)},origin:${logID(origin)},right:${logID(this._right)},parent:${logID(this._parent)},parentSub:${this._parentSub})`\n }\n}\n","import ItemString from '../Struct/ItemString.js'\nimport YArray from './YArray.js'\nimport { logID } from '../MessageHandler/messageToString.js'\n\nexport default class YText extends YArray {\n constructor (string) {\n super()\n if (typeof string === 'string') {\n const start = new ItemString()\n start._parent = this\n start._content = string\n this._start = start\n }\n }\n toString () {\n const strBuilder = []\n let n = this._start\n while (n !== null) {\n if (!n._deleted) {\n strBuilder.push(n._content)\n }\n n = n._right\n }\n return strBuilder.join('')\n }\n insert (pos, text) {\n if (text.length <= 0) {\n return\n }\n this._transact(y => {\n let left = null\n let right = this._start\n let count = 0\n while (right !== null) {\n const rightLen = right._deleted ? 0 : (right._length - 1)\n if (count <= pos && pos <= count + rightLen) {\n const splitDiff = pos - count\n right = right._splitAt(this._y, splitDiff)\n left = right._left\n count += splitDiff\n break\n }\n if (!right._deleted) {\n count += right._length\n }\n left = right\n right = right._right\n }\n if (pos > count) {\n throw new Error('Position exceeds array range!')\n }\n let item = new ItemString()\n item._origin = left\n item._left = left\n item._right = right\n item._right_origin = right\n item._parent = this\n item._content = text\n if (y !== null) {\n item._integrate(this._y)\n } else if (left === null) {\n this._start = item\n } else {\n left._right = item\n }\n })\n }\n _logString () {\n const left = this._left !== null ? this._left._lastId : null\n const origin = this._origin !== null ? this._origin._lastId : null\n return `YText(id:${logID(this._id)},start:${logID(this._start)},left:${logID(left)},origin:${logID(origin)},right:${logID(this._right)},parent:${logID(this._parent)},parentSub:${this._parentSub})`\n }\n}\n","import { YXmlText, YXmlHook } from './y-xml.js'\n\nexport function defaultDomFilter (node, attributes) {\n return attributes\n}\n\nexport function getAnchorViewPosition (scrollElement) {\n if (scrollElement == null) {\n return null\n }\n let anchor = document.getSelection().anchorNode\n if (anchor != null) {\n let top = getBoundingClientRect(anchor).top\n if (top >= 0 && top <= document.documentElement.clientHeight) {\n return {\n anchor: anchor,\n top: top\n }\n }\n }\n return {\n anchor: null,\n scrollTop: scrollElement.scrollTop,\n scrollHeight: scrollElement.scrollHeight\n }\n}\n\n// get BoundingClientRect that works on text nodes\nexport function getBoundingClientRect (element) {\n if (element.getBoundingClientRect != null) {\n // is element node\n return element.getBoundingClientRect()\n } else {\n // is text node\n if (element.parentNode == null) {\n // range requires that text nodes have a parent\n let span = document.createElement('span')\n span.appendChild(element)\n }\n let range = document.createRange()\n range.selectNode(element)\n return range.getBoundingClientRect()\n }\n}\n\nexport function fixScrollPosition (scrollElement, fix) {\n if (scrollElement !== null && fix !== null) {\n if (fix.anchor === null) {\n if (scrollElement.scrollTop === fix.scrollTop) {\n scrollElement.scrollTop = scrollElement.scrollHeight - fix.scrollHeight\n }\n } else {\n scrollElement.scrollTop = getBoundingClientRect(fix.anchor).top - fix.top\n }\n }\n}\n\nfunction iterateUntilUndeleted (item) {\n while (item !== null && item._deleted) {\n item = item._right\n }\n return item\n}\n\nfunction _insertNodeHelper (yxml, prevExpectedNode, child) {\n let insertedNodes = yxml.insertDomElementsAfter(prevExpectedNode, [child])\n if (insertedNodes.length > 0) {\n return insertedNodes[0]\n } else {\n return prevExpectedNode\n }\n}\n\n/*\n * 1. Check if any of the nodes was deleted\n * 2. Iterate over the children.\n * 2.1 If a node exists without _yxml property, insert a new node\n * 2.2 If _contents.length < dom.childNodes.length, fill the\n * rest of _content with childNodes\n * 2.3 If a node was moved, delete it and\n * recreate a new yxml element that is bound to that node.\n * You can detect that a node was moved because expectedId\n * !== actualId in the list\n */\nexport function applyChangesFromDom (dom) {\n const yxml = dom._yxml\n if (yxml.constructor === YXmlHook) {\n return\n }\n const y = yxml._y\n let knownChildren =\n new Set(\n Array.prototype.map.call(dom.childNodes, child => child._yxml)\n .filter(id => id !== undefined)\n )\n // 1. Check if any of the nodes was deleted\n yxml.forEach(function (childType, i) {\n if (!knownChildren.has(childType)) {\n childType._delete(y)\n }\n })\n // 2. iterate\n let childNodes = dom.childNodes\n let len = childNodes.length\n let prevExpectedNode = null\n let expectedNode = iterateUntilUndeleted(yxml._start)\n for (let domCnt = 0; domCnt < len; domCnt++) {\n const child = childNodes[domCnt]\n const childYXml = child._yxml\n if (childYXml != null) {\n if (childYXml === false) {\n // should be ignored or is going to be deleted\n continue\n }\n if (expectedNode !== null) {\n if (expectedNode !== childYXml) {\n // 2.3 Not expected node\n if (childYXml._parent !== this) {\n // element is going to be deleted by its previous parent\n child._yxml = null\n } else {\n childYXml._delete(y)\n }\n prevExpectedNode = _insertNodeHelper(yxml, prevExpectedNode, child)\n } else {\n prevExpectedNode = expectedNode\n expectedNode = iterateUntilUndeleted(expectedNode._right)\n }\n // if this is the expected node id, just continue\n } else {\n // 2.2 fill _conten with child nodes\n prevExpectedNode = _insertNodeHelper(yxml, prevExpectedNode, child)\n }\n } else {\n // 2.1 A new node was found\n prevExpectedNode = _insertNodeHelper(yxml, prevExpectedNode, child)\n }\n }\n}\n\nexport function reflectChangesOnDom (events, _document) {\n // Make sure that no filtered attributes are applied to the structure\n // if they were, delete them\n /*\n events.forEach(event => {\n const target = event.target\n if (event.attributesChanged === undefined) {\n // event.target is Y.XmlText\n return\n }\n const keys = this._domFilter(target.nodeName, Array.from(event.attributesChanged))\n if (keys === null) {\n target._delete()\n } else {\n const removeKeys = new Set() // is a copy of event.attributesChanged\n event.attributesChanged.forEach(key => { removeKeys.add(key) })\n keys.forEach(key => {\n // remove all accepted keys from removeKeys\n removeKeys.delete(key)\n })\n // remove the filtered attribute\n removeKeys.forEach(key => {\n target.removeAttribute(key)\n })\n }\n })\n */\n this._mutualExclude(() => {\n events.forEach(event => {\n const yxml = event.target\n const dom = yxml._dom\n if (dom != null) {\n // TODO: do this once before applying stuff\n // let anchorViewPosition = getAnchorViewPosition(yxml._scrollElement)\n if (yxml.constructor === YXmlText) {\n yxml._dom.nodeValue = yxml.toString()\n } else if (event.attributesChanged !== undefined) {\n // update attributes\n event.attributesChanged.forEach(attributeName => {\n const value = yxml.getAttribute(attributeName)\n if (value === undefined) {\n dom.removeAttribute(attributeName)\n } else {\n dom.setAttribute(attributeName, value)\n }\n })\n /**\n * TODO: instead of chard-checking the types, it would be best to\n * specify the type's features. E.g.\n * - _yxmlHasAttributes\n * - _yxmlHasChildren\n * Furthermore, the features shouldn't be encoded in the types,\n * only in the attributes (above)\n */\n if (event.childListChanged && yxml.constructor !== YXmlHook) {\n let currentChild = dom.firstChild\n yxml.forEach(function (t) {\n let expectedChild = t.getDom(_document)\n if (expectedChild.parentNode === dom) {\n // is already attached to the dom. Look for it\n while (currentChild !== expectedChild) {\n let del = currentChild\n currentChild = currentChild.nextSibling\n dom.removeChild(del)\n }\n currentChild = currentChild.nextSibling\n } else {\n // this dom is not yet attached to dom\n dom.insertBefore(expectedChild, currentChild)\n }\n })\n while (currentChild !== null) {\n let tmp = currentChild.nextSibling\n dom.removeChild(currentChild)\n currentChild = tmp\n }\n }\n }\n /* TODO: smartscrolling\n .. else if (event.type === 'childInserted' || event.type === 'insert') {\n let nodes = event.values\n for (let i = nodes.length - 1; i >= 0; i--) {\n let node = nodes[i]\n node.setDomFilter(yxml._domFilter)\n node.enableSmartScrolling(yxml._scrollElement)\n let dom = node.getDom()\n let fixPosition = null\n let nextDom = null\n if (yxml._content.length > event.index + i + 1) {\n nextDom = yxml.get(event.index + i + 1).getDom()\n }\n yxml._dom.insertBefore(dom, nextDom)\n if (anchorViewPosition === null) {\n // nop\n } else if (anchorViewPosition.anchor !== null) {\n // no scrolling when current selection\n if (!dom.contains(anchorViewPosition.anchor) && !anchorViewPosition.anchor.contains(dom)) {\n fixPosition = anchorViewPosition\n }\n } else if (getBoundingClientRect(dom).top <= 0) {\n // adjust scrolling if modified element is out of view,\n // there is no anchor element, and the browser did not adjust scrollTop (this is checked later)\n fixPosition = anchorViewPosition\n }\n fixScrollPosition(yxml._scrollElement, fixPosition)\n }\n } else if (event.type === 'childRemoved' || event.type === 'delete') {\n for (let i = event.values.length - 1; i >= 0; i--) {\n let dom = event.values[i]._dom\n let fixPosition = null\n if (anchorViewPosition === null) {\n // nop\n } else if (anchorViewPosition.anchor !== null) {\n // no scrolling when current selection\n if (!dom.contains(anchorViewPosition.anchor) && !anchorViewPosition.anchor.contains(dom)) {\n fixPosition = anchorViewPosition\n }\n } else if (getBoundingClientRect(dom).top <= 0) {\n // adjust scrolling if modified element is out of view,\n // there is no anchor element, and the browser did not adjust scrollTop (this is checked later)\n fixPosition = anchorViewPosition\n }\n dom.remove()\n fixScrollPosition(yxml._scrollElement, fixPosition)\n }\n }\n */\n }\n })\n })\n}\n","import ID from './ID.js'\nimport RootID from './RootID.js'\n\nexport function getRelativePosition (type, offset) {\n let t = type._start\n while (t !== null) {\n if (t._deleted === false) {\n if (t._length > offset) {\n return [t._id.user, t._id.clock + offset]\n }\n offset -= t._length\n }\n t = t._right\n }\n return ['endof', type._id.user, type._id.clock || null, type._id.name || null, type._id.type || null]\n}\n\nexport function fromRelativePosition (y, rpos) {\n if (rpos[0] === 'endof') {\n let id\n if (rpos[3] === null) {\n id = new ID(rpos[1], rpos[2])\n } else {\n id = new RootID(rpos[3], rpos[4])\n }\n const type = y.os.get(id)\n return {\n type,\n offset: type.length\n }\n } else {\n let offset = 0\n let struct = y.os.findNodeWithUpperBound(new ID(rpos[0], rpos[1])).val\n const parent = struct._parent\n if (parent._deleted) {\n return null\n }\n if (!struct._deleted) {\n offset = rpos[1] - struct._id.clock\n }\n struct = struct._left\n while (struct !== null) {\n if (!struct._deleted) {\n offset += struct._length\n }\n struct = struct._left\n }\n return {\n type: parent,\n offset: offset\n }\n }\n}\n","/* globals getSelection */\n\nimport { getRelativePosition, fromRelativePosition } from '../../Util/relativePosition.js'\n\nlet browserSelection = null\nlet relativeSelection = null\n\nexport let beforeTransactionSelectionFixer\nif (typeof getSelection !== 'undefined') {\n beforeTransactionSelectionFixer = function _beforeTransactionSelectionFixer (y, transaction, remote) {\n if (!remote) {\n return\n }\n relativeSelection = { from: null, to: null, fromY: null, toY: null }\n browserSelection = getSelection()\n const anchorNode = browserSelection.anchorNode\n if (anchorNode !== null && anchorNode._yxml != null) {\n const yxml = anchorNode._yxml\n relativeSelection.from = getRelativePosition(yxml, browserSelection.anchorOffset)\n relativeSelection.fromY = yxml._y\n }\n const focusNode = browserSelection.focusNode\n if (focusNode !== null && focusNode._yxml != null) {\n const yxml = focusNode._yxml\n relativeSelection.to = getRelativePosition(yxml, browserSelection.focusOffset)\n relativeSelection.toY = yxml._y\n }\n }\n} else {\n beforeTransactionSelectionFixer = function _fakeBeforeTransactionSelectionFixer () {}\n}\n\nexport function afterTransactionSelectionFixer (y, transaction, remote) {\n if (relativeSelection === null || !remote) {\n return\n }\n const to = relativeSelection.to\n const from = relativeSelection.from\n const fromY = relativeSelection.fromY\n const toY = relativeSelection.toY\n let shouldUpdate = false\n let anchorNode = browserSelection.anchorNode\n let anchorOffset = browserSelection.anchorOffset\n let focusNode = browserSelection.focusNode\n let focusOffset = browserSelection.focusOffset\n if (from !== null) {\n let sel = fromRelativePosition(fromY, from)\n if (sel !== null) {\n let node = sel.type.getDom()\n let offset = sel.offset\n if (node !== anchorNode || offset !== anchorOffset) {\n anchorNode = node\n anchorOffset = offset\n shouldUpdate = true\n }\n }\n }\n if (to !== null) {\n let sel = fromRelativePosition(toY, to)\n if (sel !== null) {\n let node = sel.type.getDom()\n let offset = sel.offset\n if (node !== focusNode || offset !== focusOffset) {\n focusNode = node\n focusOffset = offset\n shouldUpdate = true\n }\n }\n }\n if (shouldUpdate) {\n browserSelection.setBaseAndExtent(\n anchorNode,\n anchorOffset,\n focusNode,\n focusOffset\n )\n }\n}\n","import YEvent from '../../Util/YEvent.js'\n\nexport default class YXmlEvent extends YEvent {\n constructor (target, subs, remote) {\n super(target)\n this.childListChanged = false\n this.attributesChanged = new Set()\n this.remote = remote\n subs.forEach((sub) => {\n if (sub === null) {\n this.childListChanged = true\n } else {\n this.attributesChanged.add(sub)\n }\n })\n }\n}\n","\nexport default function simpleDiff (a, b) {\n let left = 0 // number of same characters counting from left\n let right = 0 // number of same characters counting from right\n while (left < a.length && left < b.length && a[left] === b[left]) {\n left++\n }\n if (left !== a.length || left !== b.length) {\n // Only check right if a !== b\n while (right + left < a.length && right + left < b.length && a[a.length - right - 1] === b[b.length - right - 1]) {\n right++\n }\n }\n return {\n pos: left,\n remove: a.length - left - right,\n insert: b.slice(left, b.length - right)\n }\n}\n","/* global MutationObserver */\n\nimport { defaultDomFilter, applyChangesFromDom, reflectChangesOnDom } from './utils.js'\nimport { beforeTransactionSelectionFixer, afterTransactionSelectionFixer } from './selection.js'\n\nimport YArray from '../YArray.js'\nimport YXmlEvent from './YXmlEvent.js'\nimport { YXmlText, YXmlHook } from './y-xml'\nimport { logID } from '../../MessageHandler/messageToString.js'\nimport diff from '../../Util/simpleDiff.js'\n\nfunction domToYXml (parent, doms, _document) {\n const types = []\n doms.forEach(d => {\n if (d._yxml != null && d._yxml !== false) {\n d._yxml._unbindFromDom()\n }\n if (parent._domFilter(d.nodeName, new Map()) !== null) {\n let type\n const hookName = d._yjsHook || (d.dataset != null ? d.dataset.yjsHook : undefined)\n if (hookName !== undefined) {\n type = new YXmlHook(hookName, d)\n } else if (d.nodeType === d.TEXT_NODE) {\n type = new YXmlText(d)\n } else if (d.nodeType === d.ELEMENT_NODE) {\n type = new YXmlFragment._YXmlElement(d, parent._domFilter, _document)\n } else {\n throw new Error('Unsupported node!')\n }\n // type.enableSmartScrolling(parent._scrollElement)\n types.push(type)\n } else {\n d._yxml = false\n }\n })\n return types\n}\n\nclass YXmlTreeWalker {\n constructor (root, f) {\n this._filter = f || (() => true)\n this._root = root\n this._currentNode = root\n this._firstCall = true\n }\n [Symbol.iterator] () {\n return this\n }\n next () {\n let n = this._currentNode\n if (this._firstCall) {\n this._firstCall = false\n if (!n._deleted && this._filter(n)) {\n return { value: n, done: false }\n }\n }\n do {\n if (!n._deleted && (n.constructor === YXmlFragment._YXmlElement || n.constructor === YXmlFragment) && n._start !== null) {\n // walk down in the tree\n n = n._start\n } else {\n // walk right or up in the tree\n while (n !== this._root) {\n if (n._right !== null) {\n n = n._right\n break\n }\n n = n._parent\n }\n if (n === this._root) {\n n = null\n }\n }\n if (n === this._root) {\n break\n }\n } while (n !== null && (n._deleted || !this._filter(n)))\n this._currentNode = n\n if (n === null) {\n return { done: true }\n } else {\n return { value: n, done: false }\n }\n }\n}\n\nexport default class YXmlFragment extends YArray {\n constructor () {\n super()\n this._dom = null\n this._domFilter = defaultDomFilter\n this._domObserver = null\n // this function makes sure that either the\n // dom event is executed, or the yjs observer is executed\n var token = true\n this._mutualExclude = f => {\n if (token) {\n token = false\n try {\n f()\n } catch (e) {\n console.error(e)\n }\n /*\n if (this._domObserver !== null) {\n this._domObserver.takeRecords()\n }\n */\n token = true\n }\n }\n }\n createTreeWalker (filter) {\n return new YXmlTreeWalker(this, filter)\n }\n /**\n * Retrieve first element that matches *query*\n * Similar to DOM's querySelector, but only accepts a subset of its queries\n *\n * Query support:\n * - tagname\n * TODO:\n * - id\n * - attribute\n */\n querySelector (query) {\n query = query.toUpperCase()\n const iterator = new YXmlTreeWalker(this, element => element.nodeName === query)\n const next = iterator.next()\n if (next.done) {\n return null\n } else {\n return next.value\n }\n }\n querySelectorAll (query) {\n query = query.toUpperCase()\n return Array.from(new YXmlTreeWalker(this, element => element.nodeName === query))\n }\n enableSmartScrolling (scrollElement) {\n this._scrollElement = scrollElement\n this.forEach(xml => {\n xml.enableSmartScrolling(scrollElement)\n })\n }\n setDomFilter (f) {\n this._domFilter = f\n let attributes = new Map()\n if (this.getAttributes !== undefined) {\n let attrs = this.getAttributes()\n for (let key in attrs) {\n attributes.set(key, attrs[key])\n }\n }\n this._y.transact(() => {\n let result = this._domFilter(this.nodeName, new Map(attributes))\n if (result === null) {\n this._delete(this._y)\n } else {\n attributes.forEach((value, key) => {\n if (!result.has(key)) {\n this.removeAttribute(key)\n }\n })\n }\n this.forEach(xml => {\n xml.setDomFilter(f)\n })\n })\n }\n _callObserver (transaction, parentSubs, remote) {\n this._callEventHandler(transaction, new YXmlEvent(this, parentSubs, remote))\n }\n toString () {\n return this.map(xml => xml.toString()).join('')\n }\n _delete (y, createDelete) {\n this._unbindFromDom()\n super._delete(y, createDelete)\n }\n _unbindFromDom () {\n if (this._domObserver != null) {\n this._domObserver.disconnect()\n this._domObserver = null\n }\n if (this._dom != null) {\n this._dom._yxml = null\n this._dom = null\n }\n if (this._beforeTransactionHandler !== undefined) {\n this._y.off('beforeTransaction', this._beforeTransactionHandler)\n }\n }\n insertDomElementsAfter (prev, doms, _document) {\n const types = domToYXml(this, doms, _document)\n this.insertAfter(prev, types)\n return types\n }\n insertDomElements (pos, doms, _document) {\n const types = domToYXml(this, doms, _document)\n this.insert(pos, types)\n return types\n }\n getDom () {\n return this._dom\n }\n bindToDom (dom, _document) {\n if (this._dom != null) {\n this._unbindFromDom()\n }\n if (dom._yxml != null) {\n dom._yxml._unbindFromDom()\n }\n dom.innerHTML = ''\n this.forEach(t => {\n dom.insertBefore(t.getDom(_document), null)\n })\n this._bindToDom(dom, _document)\n }\n // binds to a dom element\n // Only call if dom and YXml are isomorph\n _bindToDom (dom, _document) {\n _document = _document || document\n this._dom = dom\n dom._yxml = this\n if (this._parent === null) {\n return\n }\n this._y.on('beforeTransaction', beforeTransactionSelectionFixer)\n this._y.on('afterTransaction', afterTransactionSelectionFixer)\n const applyFilter = (type) => {\n if (type._deleted) {\n return\n }\n // check if type is a child of this\n let isChild = false\n let p = type\n while (p !== this._y) {\n if (p === this) {\n isChild = true\n break\n }\n p = p._parent\n }\n if (!isChild) {\n return\n }\n // filter attributes\n let attributes = new Map()\n if (type.getAttributes !== undefined) {\n let attrs = type.getAttributes()\n for (let key in attrs) {\n attributes.set(key, attrs[key])\n }\n }\n let result = this._domFilter(type.nodeName, new Map(attributes))\n if (result === null) {\n type._delete(this._y)\n } else {\n attributes.forEach((value, key) => {\n if (!result.has(key)) {\n type.removeAttribute(key)\n }\n })\n }\n }\n this._y.on('beforeObserverCalls', function (y, transaction) {\n // apply dom filter to new and changed types\n transaction.changedTypes.forEach(function (subs, type) {\n if (subs.size > 1 || !subs.has(null)) {\n // only apply changes on attributes\n applyFilter(type)\n }\n })\n transaction.newTypes.forEach(applyFilter)\n })\n // Apply Y.Xml events to dom\n this.observeDeep(events => {\n reflectChangesOnDom.call(this, events, _document)\n })\n // Apply Dom changes on Y.Xml\n if (typeof MutationObserver !== 'undefined') {\n this._beforeTransactionHandler = () => {\n this._domObserverListener(this._domObserver.takeRecords())\n }\n this._y.on('beforeTransaction', this._beforeTransactionHandler)\n this._domObserverListener = mutations => {\n this._mutualExclude(() => {\n this._y.transact(() => {\n let diffChildren = new Set()\n mutations.forEach(mutation => {\n const dom = mutation.target\n const yxml = dom._yxml\n if (yxml == null || yxml.constructor === YXmlHook) {\n // dom element is filtered\n return\n }\n switch (mutation.type) {\n case 'characterData':\n var change = diff(yxml.toString(), dom.nodeValue)\n yxml.delete(change.pos, change.remove)\n yxml.insert(change.pos, change.insert)\n break\n case 'attributes':\n if (yxml.constructor === YXmlFragment) {\n break\n }\n let name = mutation.attributeName\n let val = dom.getAttribute(name)\n // check if filter accepts attribute\n let attributes = new Map()\n attributes.set(name, val)\n if (this._domFilter(dom.nodeName, attributes).size > 0 && yxml.constructor !== YXmlFragment) {\n if (yxml.getAttribute(name) !== val) {\n if (val == null) {\n yxml.removeAttribute(name)\n } else {\n yxml.setAttribute(name, val)\n }\n }\n }\n break\n case 'childList':\n diffChildren.add(mutation.target)\n break\n }\n })\n for (let dom of diffChildren) {\n if (dom.yOnChildrenChanged !== undefined) {\n dom.yOnChildrenChanged()\n }\n if (dom._yxml != null && dom._yxml !== false) {\n applyChangesFromDom(dom)\n }\n }\n })\n })\n }\n this._domObserver = new MutationObserver(this._domObserverListener)\n this._domObserver.observe(dom, {\n childList: true,\n attributes: true,\n characterData: true,\n subtree: true\n })\n }\n return dom\n }\n _logString () {\n const left = this._left !== null ? this._left._lastId : null\n const origin = this._origin !== null ? this._origin._lastId : null\n return `YXml(id:${logID(this._id)},left:${logID(left)},origin:${logID(origin)},right:${this._right},parent:${logID(this._parent)},parentSub:${this._parentSub})`\n }\n}\n","import { defaultDomFilter } from './utils.js'\n\nimport YMap from '../YMap.js'\nimport { YXmlFragment } from './y-xml.js'\n\nexport default class YXmlElement extends YXmlFragment {\n constructor (arg1, arg2, _document) {\n super()\n this.nodeName = null\n this._scrollElement = null\n if (typeof arg2 === 'function') {\n this._domFilter = arg2\n }\n if (typeof arg1 === 'string') {\n this.nodeName = arg1.toUpperCase()\n } else if (arg1 != null && arg1.nodeType != null && arg1.nodeType === arg1.ELEMENT_NODE) {\n this.nodeName = arg1.nodeName\n this._setDom(arg1, _document)\n } else {\n this.nodeName = 'UNDEFINED'\n }\n }\n _copy () {\n let struct = super._copy()\n struct.nodeName = this.nodeName\n return struct\n }\n _setDom (dom, _document) {\n if (this._dom != null) {\n throw new Error('Only call this method if you know what you are doing ;)')\n } else if (dom._yxml != null) { // TODO do i need to check this? - no.. but for dev purps..\n throw new Error('Already bound to an YXml type')\n } else {\n // tag is already set in constructor\n // set attributes\n let attributes = new Map()\n for (let i = 0; i < dom.attributes.length; i++) {\n let attr = dom.attributes[i]\n // get attribute via getAttribute for custom element support (some write something different in attr.value)\n attributes.set(attr.name, dom.getAttribute(attr.name))\n }\n attributes = this._domFilter(dom.nodeName, attributes)\n attributes.forEach((value, name) => {\n this.setAttribute(name, value)\n })\n this.insertDomElements(0, Array.prototype.slice.call(dom.childNodes), _document)\n this._bindToDom(dom, _document)\n return dom\n }\n }\n _bindToDom (dom, _document) {\n _document = _document || document\n this._dom = dom\n dom._yxml = this\n }\n _fromBinary (y, decoder) {\n const missing = super._fromBinary(y, decoder)\n this.nodeName = decoder.readVarString()\n return missing\n }\n _toBinary (encoder) {\n super._toBinary(encoder)\n encoder.writeVarString(this.nodeName)\n }\n _integrate (y) {\n if (this.nodeName === null) {\n throw new Error('nodeName must be defined!')\n }\n if (this._domFilter === defaultDomFilter && this._parent._domFilter !== undefined) {\n this._domFilter = this._parent._domFilter\n }\n super._integrate(y)\n }\n /**\n * Returns the string representation of the XML document.\n * The attributes are ordered by attribute-name, so you can easily use this\n * method to compare YXmlElements\n */\n toString () {\n const attrs = this.getAttributes()\n const stringBuilder = []\n const keys = []\n for (let key in attrs) {\n keys.push(key)\n }\n keys.sort()\n const keysLen = keys.length\n for (let i = 0; i < keysLen; i++) {\n const key = keys[i]\n stringBuilder.push(key + '=\"' + attrs[key] + '\"')\n }\n const nodeName = this.nodeName.toLocaleLowerCase()\n const attrsString = stringBuilder.length > 0 ? ' ' + stringBuilder.join(' ') : ''\n return `<${nodeName}${attrsString}>${super.toString()}`\n }\n removeAttribute () {\n return YMap.prototype.delete.apply(this, arguments)\n }\n\n setAttribute () {\n return YMap.prototype.set.apply(this, arguments)\n }\n\n getAttribute () {\n return YMap.prototype.get.apply(this, arguments)\n }\n\n getAttributes () {\n const obj = {}\n for (let [key, value] of this._map) {\n if (!value._deleted) {\n obj[key] = value._content[0]\n }\n }\n return obj\n }\n getDom (_document) {\n _document = _document || document\n let dom = this._dom\n if (dom == null) {\n dom = _document.createElement(this.nodeName)\n dom._yxml = this\n let attrs = this.getAttributes()\n for (let key in attrs) {\n dom.setAttribute(key, attrs[key])\n }\n this.forEach(yxml => {\n dom.appendChild(yxml.getDom(_document))\n })\n this._bindToDom(dom, _document)\n }\n return dom\n }\n}\n","\nconst xmlHooks = {}\n\nexport function addHook (name, hook) {\n xmlHooks[name] = hook\n}\n\nexport function getHook (name) {\n const hook = xmlHooks[name]\n if (hook === undefined) {\n throw new Error(`The hook \"${name}\" is not specified! You must not access this hook!`)\n }\n return hook\n}\n","import YMap from '../YMap.js'\nimport { getHook, addHook } from './hooks.js'\n\nexport default class YXmlHook extends YMap {\n constructor (hookName, dom) {\n super()\n this._dom = null\n this.hookName = null\n if (hookName !== undefined) {\n this.hookName = hookName\n this._dom = dom\n dom._yjsHook = hookName\n dom._yxml = this\n getHook(hookName).fillType(dom, this)\n }\n }\n _copy () {\n const struct = super._copy()\n struct.hookName = this.hookName\n return struct\n }\n getDom (_document) {\n _document = _document || document\n if (this._dom === null) {\n const dom = getHook(this.hookName).createDom(this)\n this._dom = dom\n dom._yxml = this\n dom._yjsHook = this.hookName\n }\n return this._dom\n }\n _unbindFromDom () {\n this._dom._yxml = null\n this._yxml = null\n // TODO: cleanup hook?\n }\n _fromBinary (y, decoder) {\n const missing = super._fromBinary(y, decoder)\n this.hookName = decoder.readVarString()\n return missing\n }\n _toBinary (encoder) {\n super._toBinary(encoder)\n encoder.writeVarString(this.hookName)\n }\n _integrate (y) {\n if (this.hookName === null) {\n throw new Error('hookName must be defined!')\n }\n super._integrate(y)\n }\n setDomFilter () {\n // TODO: implement new modfilter method!\n }\n enableSmartScrolling () {\n // TODO: implement new smartscrolling method!\n }\n}\nYXmlHook.addHook = addHook\n","import YText from '../YText.js'\n\nexport default class YXmlText extends YText {\n constructor (arg1) {\n let dom = null\n let initialText = null\n if (arg1 != null) {\n if (arg1.nodeType != null && arg1.nodeType === arg1.TEXT_NODE) {\n dom = arg1\n initialText = dom.nodeValue\n } else if (typeof arg1 === 'string') {\n initialText = arg1\n }\n }\n super(initialText)\n this._dom = null\n this._domObserver = null\n this._domObserverListener = null\n this._scrollElement = null\n if (dom !== null) {\n this._setDom(arg1)\n }\n /*\n var token = true\n this._mutualExclude = f => {\n if (token) {\n token = false\n try {\n f()\n } catch (e) {\n console.error(e)\n }\n this._domObserver.takeRecords()\n token = true\n }\n }\n this.observe(event => {\n if (this._dom != null) {\n const dom = this._dom\n this._mutualExclude(() => {\n let anchorViewPosition = getAnchorViewPosition(this._scrollElement)\n let anchorViewFix\n if (anchorViewPosition !== null && (anchorViewPosition.anchor !== null || getBoundingClientRect(this._dom).top <= 0)) {\n anchorViewFix = anchorViewPosition\n } else {\n anchorViewFix = null\n }\n dom.nodeValue = this.toString()\n fixScrollPosition(this._scrollElement, anchorViewFix)\n })\n }\n })\n */\n }\n setDomFilter () {}\n enableSmartScrolling (scrollElement) {\n this._scrollElement = scrollElement\n }\n _setDom (dom) {\n if (this._dom != null) {\n this._unbindFromDom()\n }\n if (dom._yxml != null) {\n dom._yxml._unbindFromDom()\n }\n // set marker\n this._dom = dom\n dom._yxml = this\n }\n getDom (_document) {\n _document = _document || document\n if (this._dom === null) {\n const dom = _document.createTextNode(this.toString())\n this._setDom(dom)\n return dom\n }\n return this._dom\n }\n _delete (y, createDelete) {\n this._unbindFromDom()\n super._delete(y, createDelete)\n }\n _unbindFromDom () {\n if (this._domObserver != null) {\n this._domObserver.disconnect()\n this._domObserver = null\n }\n if (this._dom != null) {\n this._dom._yxml = null\n this._dom = null\n }\n }\n}\n","\nimport YXmlFragment from './YXmlFragment.js'\nimport YXmlElement from './YXmlElement.js'\nimport YXmlHook from './YXmlHook.js'\n\nexport { default as YXmlFragment } from './YXmlFragment.js'\nexport { default as YXmlElement } from './YXmlElement.js'\nexport { default as YXmlText } from './YXmlText.js'\nexport { default as YXmlHook } from './YXmlHook.js'\n\nYXmlFragment._YXmlElement = YXmlElement\nYXmlFragment._YXmlHook = YXmlHook\n","import YArray from '../Type/YArray.js'\nimport YMap from '../Type/YMap.js'\nimport YText from '../Type/YText.js'\nimport { YXmlFragment, YXmlElement, YXmlText, YXmlHook } from '../Type/y-xml/y-xml.js'\n\nimport Delete from '../Struct/Delete.js'\nimport ItemJSON from '../Struct/ItemJSON.js'\nimport ItemString from '../Struct/ItemString.js'\n\nconst structs = new Map()\nconst references = new Map()\n\nexport function addStruct (reference, structConstructor) {\n structs.set(reference, structConstructor)\n references.set(structConstructor, reference)\n}\n\nexport function getStruct (reference) {\n return structs.get(reference)\n}\n\nexport function getReference (typeConstructor) {\n return references.get(typeConstructor)\n}\n\naddStruct(0, ItemJSON)\naddStruct(1, ItemString)\naddStruct(2, Delete)\n\naddStruct(3, YArray)\naddStruct(4, YMap)\naddStruct(5, YText)\naddStruct(6, YXmlFragment)\naddStruct(7, YXmlElement)\naddStruct(8, YXmlText)\naddStruct(9, YXmlHook)\n","import { getReference } from './structReferences.js'\n\nexport const RootFakeUserID = 0xFFFFFF\n\nexport default class RootID {\n constructor (name, typeConstructor) {\n this.user = RootFakeUserID\n this.name = name\n this.type = getReference(typeConstructor)\n }\n equals (id) {\n return id !== null && id.user === this.user && id.name === this.name && id.type === this.type\n }\n lessThan (id) {\n if (id.constructor === RootID) {\n return this.user < id.user || (this.user === id.user && (this.name < id.name || (this.name === id.name && this.type < id.type)))\n } else {\n return true\n }\n }\n}\n","import Tree from '../Util/Tree.js'\nimport RootID from '../Util/RootID.js'\nimport { getStruct } from '../Util/structReferences.js'\nimport { logID } from '../MessageHandler/messageToString.js'\n\nexport default class OperationStore extends Tree {\n constructor (y) {\n super()\n this.y = y\n }\n logTable () {\n const items = []\n this.iterate(null, null, function (item) {\n items.push({\n id: logID(item),\n origin: logID(item._origin === null ? null : item._origin._lastId),\n left: logID(item._left === null ? null : item._left._lastId),\n right: logID(item._right),\n right_origin: logID(item._right_origin),\n parent: logID(item._parent),\n parentSub: item._parentSub,\n deleted: item._deleted,\n content: JSON.stringify(item._content)\n })\n })\n console.table(items)\n }\n get (id) {\n let struct = this.find(id)\n if (struct === null && id instanceof RootID) {\n const Constr = getStruct(id.type)\n const y = this.y\n struct = new Constr()\n struct._id = id\n struct._parent = y\n y.transact(() => {\n struct._integrate(y)\n })\n this.put(struct)\n }\n return struct\n }\n // Use getItem for structs with _length > 1\n getItem (id) {\n var item = this.findWithUpperBound(id)\n if (item === null) {\n return null\n }\n const itemID = item._id\n if (id.user === itemID.user && id.clock < itemID.clock + item._length) {\n return item\n } else {\n return null\n }\n }\n // Return an insertion such that id is the first element of content\n // This function manipulates an item, if necessary\n getItemCleanStart (id) {\n var ins = this.getItem(id)\n if (ins === null || ins._length === 1) {\n return ins\n }\n const insID = ins._id\n if (insID.clock === id.clock) {\n return ins\n } else {\n return ins._splitAt(this.y, id.clock - insID.clock)\n }\n }\n // Return an insertion such that id is the last element of content\n // This function manipulates an operation, if necessary\n getItemCleanEnd (id) {\n var ins = this.getItem(id)\n if (ins === null || ins._length === 1) {\n return ins\n }\n const insID = ins._id\n if (insID.clock + ins._length - 1 === id.clock) {\n return ins\n } else {\n ins._splitAt(this.y, id.clock - insID.clock + 1)\n return ins\n }\n }\n}\n","import ID from '../Util/ID.js'\n\nexport default class StateStore {\n constructor (y) {\n this.y = y\n this.state = new Map()\n }\n logTable () {\n const entries = []\n for (let [user, state] of this.state) {\n entries.push({\n user, state\n })\n }\n console.table(entries)\n }\n getNextID (len) {\n const user = this.y.userID\n const state = this.getState(user)\n this.setState(user, state + len)\n return new ID(user, state)\n }\n updateRemoteState (struct) {\n let user = struct._id.user\n let userState = this.state.get(user)\n while (struct !== null && struct._id.clock === userState) {\n userState += struct._length\n struct = this.y.os.get(new ID(user, userState))\n }\n this.state.set(user, userState)\n }\n getState (user) {\n let state = this.state.get(user)\n if (state == null) {\n return 0\n }\n return state\n }\n setState (user, state) {\n // TODO: modify missingi structs here\n const beforeState = this.y._transaction.beforeState\n if (!beforeState.has(user)) {\n beforeState.set(user, this.getState(user))\n }\n this.state.set(user, state)\n }\n}\n","/* global crypto */\n\nexport function generateUserID () {\n if (typeof crypto !== 'undefined' && crypto.getRandomValue != null) {\n // browser\n let arr = new Uint32Array(1)\n crypto.getRandomValues(arr)\n return arr[0]\n } else if (typeof crypto !== 'undefined' && crypto.randomBytes != null) {\n // node\n let buf = crypto.randomBytes(4)\n return new Uint32Array(buf.buffer)[0]\n } else {\n return Math.ceil(Math.random() * 0xFFFFFFFF)\n }\n}\n","export default class NamedEventHandler {\n constructor () {\n this._eventListener = new Map()\n this._stateListener = new Map()\n }\n _getListener (name) {\n let listeners = this._eventListener.get(name)\n if (listeners === undefined) {\n listeners = {\n once: new Set(),\n on: new Set()\n }\n this._eventListener.set(name, listeners)\n }\n return listeners\n }\n once (name, f) {\n let listeners = this._getListener(name)\n listeners.once.add(f)\n }\n on (name, f) {\n let listeners = this._getListener(name)\n listeners.on.add(f)\n }\n _initStateListener (name) {\n let state = this._stateListener.get(name)\n if (state === undefined) {\n state = {}\n state.promise = new Promise(function (resolve) {\n state.resolve = resolve\n })\n this._stateListener.set(name, state)\n }\n return state\n }\n when (name) {\n return this._initStateListener(name).promise\n }\n off (name, f) {\n if (name == null || f == null) {\n throw new Error('You must specify event name and function!')\n }\n const listener = this._eventListener.get(name)\n if (listener !== undefined) {\n listener.on.delete(f)\n listener.once.delete(f)\n }\n }\n emit (name, ...args) {\n this._initStateListener(name).resolve()\n const listener = this._eventListener.get(name)\n if (listener !== undefined) {\n listener.on.forEach(f => f.apply(null, args))\n listener.once.forEach(f => f.apply(null, args))\n listener.once = new Set()\n } else if (name === 'error') {\n console.error(args[0])\n }\n }\n destroy () {\n this._eventListener = null\n }\n}\n","import ID from './ID.js'\n\nclass ReverseOperation {\n constructor (y, transaction) {\n this.created = new Date()\n const beforeState = transaction.beforeState\n if (beforeState.has(y.userID)) {\n this.toState = new ID(y.userID, y.ss.getState(y.userID) - 1)\n this.fromState = new ID(y.userID, beforeState.get(y.userID))\n } else {\n this.toState = null\n this.fromState = null\n }\n this.deletedStructs = transaction.deletedStructs\n }\n}\n\nfunction isStructInScope (y, struct, scope) {\n while (struct !== y) {\n if (struct === scope) {\n return true\n }\n struct = struct._parent\n }\n return false\n}\n\nfunction applyReverseOperation (y, scope, reverseBuffer) {\n let performedUndo = false\n y.transact(() => {\n while (!performedUndo && reverseBuffer.length > 0) {\n let undoOp = reverseBuffer.pop()\n // make sure that it is possible to iterate {from}-{to}\n if (undoOp.fromState !== null) {\n y.os.getItemCleanStart(undoOp.fromState)\n y.os.getItemCleanEnd(undoOp.toState)\n y.os.iterate(undoOp.fromState, undoOp.toState, op => {\n while (op._deleted && op._redone !== null) {\n op = op._redone\n }\n if (op._deleted === false && isStructInScope(y, op, scope)) {\n performedUndo = true\n op._delete(y)\n }\n })\n }\n for (let op of undoOp.deletedStructs) {\n if (\n isStructInScope(y, op, scope) &&\n op._parent !== y &&\n (\n op._id.user !== y.userID ||\n undoOp.fromState === null ||\n op._id.clock < undoOp.fromState.clock ||\n op._id.clock > undoOp.toState.clock\n )\n ) {\n performedUndo = true\n op._redo(y)\n }\n }\n }\n })\n return performedUndo\n}\n\nexport default class UndoManager {\n constructor (scope, options = {}) {\n this.options = options\n options.captureTimeout = options.captureTimeout == null ? 500 : options.captureTimeout\n this._undoBuffer = []\n this._redoBuffer = []\n this._scope = scope\n this._undoing = false\n this._redoing = false\n this._lastTransactionWasUndo = false\n const y = scope._y\n this.y = y\n y.on('afterTransaction', (y, transaction, remote) => {\n if (!remote && transaction.changedParentTypes.has(scope)) {\n let reverseOperation = new ReverseOperation(y, transaction)\n if (!this._undoing) {\n let lastUndoOp = this._undoBuffer.length > 0 ? this._undoBuffer[this._undoBuffer.length - 1] : null\n if (\n this._redoing === false &&\n this._lastTransactionWasUndo === false &&\n lastUndoOp !== null &&\n reverseOperation.created - lastUndoOp.created <= options.captureTimeout\n ) {\n lastUndoOp.created = reverseOperation.created\n if (reverseOperation.toState !== null) {\n lastUndoOp.toState = reverseOperation.toState\n if (lastUndoOp.fromState === null) {\n lastUndoOp.fromState = reverseOperation.fromState\n }\n }\n reverseOperation.deletedStructs.forEach(lastUndoOp.deletedStructs.add, lastUndoOp.deletedStructs)\n } else {\n this._lastTransactionWasUndo = false\n this._undoBuffer.push(reverseOperation)\n }\n if (!this._redoing) {\n this._redoBuffer = []\n }\n } else {\n this._lastTransactionWasUndo = true\n this._redoBuffer.push(reverseOperation)\n }\n }\n })\n }\n undo () {\n this._undoing = true\n const performedUndo = applyReverseOperation(this.y, this._scope, this._undoBuffer)\n this._undoing = false\n return performedUndo\n }\n redo () {\n this._redoing = true\n const performedRedo = applyReverseOperation(this.y, this._scope, this._redoBuffer)\n this._redoing = false\n return performedRedo\n }\n}\n","/**\n * Helpers.\n */\n\nvar s = 1000;\nvar m = s * 60;\nvar h = m * 60;\nvar d = h * 24;\nvar y = d * 365.25;\n\n/**\n * Parse or format the given `val`.\n *\n * Options:\n *\n * - `long` verbose formatting [false]\n *\n * @param {String|Number} val\n * @param {Object} [options]\n * @throws {Error} throw an error if val is not a non-empty string or a number\n * @return {String|Number}\n * @api public\n */\n\nmodule.exports = function(val, options) {\n options = options || {};\n var type = typeof val;\n if (type === 'string' && val.length > 0) {\n return parse(val);\n } else if (type === 'number' && isNaN(val) === false) {\n return options.long ? fmtLong(val) : fmtShort(val);\n }\n throw new Error(\n 'val is not a non-empty string or a valid number. val=' +\n JSON.stringify(val)\n );\n};\n\n/**\n * Parse the given `str` and return milliseconds.\n *\n * @param {String} str\n * @return {Number}\n * @api private\n */\n\nfunction parse(str) {\n str = String(str);\n if (str.length > 100) {\n return;\n }\n var match = /^((?:\\d+)?\\.?\\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(\n str\n );\n if (!match) {\n return;\n }\n var n = parseFloat(match[1]);\n var type = (match[2] || 'ms').toLowerCase();\n switch (type) {\n case 'years':\n case 'year':\n case 'yrs':\n case 'yr':\n case 'y':\n return n * y;\n case 'days':\n case 'day':\n case 'd':\n return n * d;\n case 'hours':\n case 'hour':\n case 'hrs':\n case 'hr':\n case 'h':\n return n * h;\n case 'minutes':\n case 'minute':\n case 'mins':\n case 'min':\n case 'm':\n return n * m;\n case 'seconds':\n case 'second':\n case 'secs':\n case 'sec':\n case 's':\n return n * s;\n case 'milliseconds':\n case 'millisecond':\n case 'msecs':\n case 'msec':\n case 'ms':\n return n;\n default:\n return undefined;\n }\n}\n\n/**\n * Short format for `ms`.\n *\n * @param {Number} ms\n * @return {String}\n * @api private\n */\n\nfunction fmtShort(ms) {\n if (ms >= d) {\n return Math.round(ms / d) + 'd';\n }\n if (ms >= h) {\n return Math.round(ms / h) + 'h';\n }\n if (ms >= m) {\n return Math.round(ms / m) + 'm';\n }\n if (ms >= s) {\n return Math.round(ms / s) + 's';\n }\n return ms + 'ms';\n}\n\n/**\n * Long format for `ms`.\n *\n * @param {Number} ms\n * @return {String}\n * @api private\n */\n\nfunction fmtLong(ms) {\n return plural(ms, d, 'day') ||\n plural(ms, h, 'hour') ||\n plural(ms, m, 'minute') ||\n plural(ms, s, 'second') ||\n ms + ' ms';\n}\n\n/**\n * Pluralization helper.\n */\n\nfunction plural(ms, n, name) {\n if (ms < n) {\n return;\n }\n if (ms < n * 1.5) {\n return Math.floor(ms / n) + ' ' + name;\n }\n return Math.ceil(ms / n) + ' ' + name + 's';\n}\n","\n/**\n * This is the common logic for both the Node.js and web browser\n * implementations of `debug()`.\n *\n * Expose `debug()` as the module.\n */\n\nexports = module.exports = createDebug.debug = createDebug['default'] = createDebug;\nexports.coerce = coerce;\nexports.disable = disable;\nexports.enable = enable;\nexports.enabled = enabled;\nexports.humanize = require('ms');\n\n/**\n * The currently active debug mode names, and names to skip.\n */\n\nexports.names = [];\nexports.skips = [];\n\n/**\n * Map of special \"%n\" handling functions, for the debug \"format\" argument.\n *\n * Valid key names are a single, lower or upper-case letter, i.e. \"n\" and \"N\".\n */\n\nexports.formatters = {};\n\n/**\n * Previous log timestamp.\n */\n\nvar prevTime;\n\n/**\n * Select a color.\n * @param {String} namespace\n * @return {Number}\n * @api private\n */\n\nfunction selectColor(namespace) {\n var hash = 0, i;\n\n for (i in namespace) {\n hash = ((hash << 5) - hash) + namespace.charCodeAt(i);\n hash |= 0; // Convert to 32bit integer\n }\n\n return exports.colors[Math.abs(hash) % exports.colors.length];\n}\n\n/**\n * Create a debugger with the given `namespace`.\n *\n * @param {String} namespace\n * @return {Function}\n * @api public\n */\n\nfunction createDebug(namespace) {\n\n function debug() {\n // disabled?\n if (!debug.enabled) return;\n\n var self = debug;\n\n // set `diff` timestamp\n var curr = +new Date();\n var ms = curr - (prevTime || curr);\n self.diff = ms;\n self.prev = prevTime;\n self.curr = curr;\n prevTime = curr;\n\n // turn the `arguments` into a proper Array\n var args = new Array(arguments.length);\n for (var i = 0; i < args.length; i++) {\n args[i] = arguments[i];\n }\n\n args[0] = exports.coerce(args[0]);\n\n if ('string' !== typeof args[0]) {\n // anything else let's inspect with %O\n args.unshift('%O');\n }\n\n // apply any `formatters` transformations\n var index = 0;\n args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) {\n // if we encounter an escaped % then don't increase the array index\n if (match === '%%') return match;\n index++;\n var formatter = exports.formatters[format];\n if ('function' === typeof formatter) {\n var val = args[index];\n match = formatter.call(self, val);\n\n // now we need to remove `args[index]` since it's inlined in the `format`\n args.splice(index, 1);\n index--;\n }\n return match;\n });\n\n // apply env-specific formatting (colors, etc.)\n exports.formatArgs.call(self, args);\n\n var logFn = debug.log || exports.log || console.log.bind(console);\n logFn.apply(self, args);\n }\n\n debug.namespace = namespace;\n debug.enabled = exports.enabled(namespace);\n debug.useColors = exports.useColors();\n debug.color = selectColor(namespace);\n\n // env-specific initialization logic for debug instances\n if ('function' === typeof exports.init) {\n exports.init(debug);\n }\n\n return debug;\n}\n\n/**\n * Enables a debug mode by namespaces. This can include modes\n * separated by a colon and wildcards.\n *\n * @param {String} namespaces\n * @api public\n */\n\nfunction enable(namespaces) {\n exports.save(namespaces);\n\n exports.names = [];\n exports.skips = [];\n\n var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\\s,]+/);\n var len = split.length;\n\n for (var i = 0; i < len; i++) {\n if (!split[i]) continue; // ignore empty strings\n namespaces = split[i].replace(/\\*/g, '.*?');\n if (namespaces[0] === '-') {\n exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));\n } else {\n exports.names.push(new RegExp('^' + namespaces + '$'));\n }\n }\n}\n\n/**\n * Disable debug output.\n *\n * @api public\n */\n\nfunction disable() {\n exports.enable('');\n}\n\n/**\n * Returns true if the given mode name is enabled, false otherwise.\n *\n * @param {String} name\n * @return {Boolean}\n * @api public\n */\n\nfunction enabled(name) {\n var i, len;\n for (i = 0, len = exports.skips.length; i < len; i++) {\n if (exports.skips[i].test(name)) {\n return false;\n }\n }\n for (i = 0, len = exports.names.length; i < len; i++) {\n if (exports.names[i].test(name)) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Coerce `val`.\n *\n * @param {Mixed} val\n * @return {Mixed}\n * @api private\n */\n\nfunction coerce(val) {\n if (val instanceof Error) return val.stack || val.message;\n return val;\n}\n","/**\n * This is the web browser implementation of `debug()`.\n *\n * Expose `debug()` as the module.\n */\n\nexports = module.exports = require('./debug');\nexports.log = log;\nexports.formatArgs = formatArgs;\nexports.save = save;\nexports.load = load;\nexports.useColors = useColors;\nexports.storage = 'undefined' != typeof chrome\n && 'undefined' != typeof chrome.storage\n ? chrome.storage.local\n : localstorage();\n\n/**\n * Colors.\n */\n\nexports.colors = [\n 'lightseagreen',\n 'forestgreen',\n 'goldenrod',\n 'dodgerblue',\n 'darkorchid',\n 'crimson'\n];\n\n/**\n * Currently only WebKit-based Web Inspectors, Firefox >= v31,\n * and the Firebug extension (any Firefox version) are known\n * to support \"%c\" CSS customizations.\n *\n * TODO: add a `localStorage` variable to explicitly enable/disable colors\n */\n\nfunction useColors() {\n // NB: In an Electron preload script, document will be defined but not fully\n // initialized. Since we know we're in Chrome, we'll just detect this case\n // explicitly\n if (typeof window !== 'undefined' && window.process && window.process.type === 'renderer') {\n return true;\n }\n\n // is webkit? http://stackoverflow.com/a/16459606/376773\n // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632\n return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||\n // is firebug? http://stackoverflow.com/a/398120/376773\n (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||\n // is firefox >= v31?\n // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages\n (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\\/(\\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||\n // double check webkit in userAgent just in case we are in a worker\n (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\\/(\\d+)/));\n}\n\n/**\n * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.\n */\n\nexports.formatters.j = function(v) {\n try {\n return JSON.stringify(v);\n } catch (err) {\n return '[UnexpectedJSONParseError]: ' + err.message;\n }\n};\n\n\n/**\n * Colorize log arguments if enabled.\n *\n * @api public\n */\n\nfunction formatArgs(args) {\n var useColors = this.useColors;\n\n args[0] = (useColors ? '%c' : '')\n + this.namespace\n + (useColors ? ' %c' : ' ')\n + args[0]\n + (useColors ? '%c ' : ' ')\n + '+' + exports.humanize(this.diff);\n\n if (!useColors) return;\n\n var c = 'color: ' + this.color;\n args.splice(1, 0, c, 'color: inherit')\n\n // the final \"%c\" is somewhat tricky, because there could be other\n // arguments passed either before or after the %c, so we need to\n // figure out the correct index to insert the CSS into\n var index = 0;\n var lastC = 0;\n args[0].replace(/%[a-zA-Z%]/g, function(match) {\n if ('%%' === match) return;\n index++;\n if ('%c' === match) {\n // we only are interested in the *last* %c\n // (the user may have provided their own)\n lastC = index;\n }\n });\n\n args.splice(lastC, 0, c);\n}\n\n/**\n * Invokes `console.log()` when available.\n * No-op when `console.log` is not a \"function\".\n *\n * @api public\n */\n\nfunction log() {\n // this hackery is required for IE8/9, where\n // the `console.log` function doesn't have 'apply'\n return 'object' === typeof console\n && console.log\n && Function.prototype.apply.call(console.log, console, arguments);\n}\n\n/**\n * Save `namespaces`.\n *\n * @param {String} namespaces\n * @api private\n */\n\nfunction save(namespaces) {\n try {\n if (null == namespaces) {\n exports.storage.removeItem('debug');\n } else {\n exports.storage.debug = namespaces;\n }\n } catch(e) {}\n}\n\n/**\n * Load `namespaces`.\n *\n * @return {String} returns the previously persisted debug modes\n * @api private\n */\n\nfunction load() {\n var r;\n try {\n r = exports.storage.debug;\n } catch(e) {}\n\n // If debug isn't set in LS, and we're in Electron, try to load $DEBUG\n if (!r && typeof process !== 'undefined' && 'env' in process) {\n r = process.env.DEBUG;\n }\n\n return r;\n}\n\n/**\n * Enable namespaces listed in `localStorage.debug` initially.\n */\n\nexports.enable(load());\n\n/**\n * Localstorage attempts to return the localstorage.\n *\n * This is necessary because safari throws\n * when a user disables cookies/localstorage\n * and you attempt to access it.\n *\n * @return {LocalStorage}\n * @api private\n */\n\nfunction localstorage() {\n try {\n return window.localStorage;\n } catch (e) {}\n}\n","import BinaryEncoder from './Binary/Encoder.js'\nimport BinaryDecoder from './Binary/Decoder.js'\n\nimport { sendSyncStep1, readSyncStep1 } from './MessageHandler/syncStep1.js'\nimport { readSyncStep2 } from './MessageHandler/syncStep2.js'\nimport { integrateRemoteStructs } from './MessageHandler/integrateRemoteStructs.js'\n\nimport debug from 'debug'\n\nexport default class AbstractConnector {\n constructor (y, opts) {\n this.y = y\n this.opts = opts\n if (opts.role == null || opts.role === 'master') {\n this.role = 'master'\n } else if (opts.role === 'slave') {\n this.role = 'slave'\n } else {\n throw new Error(\"Role must be either 'master' or 'slave'!\")\n }\n this.log = debug('y:connector')\n this.logMessage = debug('y:connector-message')\n this._forwardAppliedStructs = opts.forwardAppliedOperations || false // TODO: rename\n this.role = opts.role\n this.connections = new Map()\n this.isSynced = false\n this.userEventListeners = []\n this.whenSyncedListeners = []\n this.currentSyncTarget = null\n this.debug = opts.debug === true\n this.broadcastBuffer = new BinaryEncoder()\n this.broadcastBufferSize = 0\n this.protocolVersion = 11\n this.authInfo = opts.auth || null\n this.checkAuth = opts.checkAuth || function () { return Promise.resolve('write') } // default is everyone has write access\n if (opts.maxBufferLength == null) {\n this.maxBufferLength = -1\n } else {\n this.maxBufferLength = opts.maxBufferLength\n }\n }\n\n reconnect () {\n this.log('reconnecting..')\n }\n\n disconnect () {\n this.log('discronnecting..')\n this.connections = new Map()\n this.isSynced = false\n this.currentSyncTarget = null\n this.whenSyncedListeners = []\n return Promise.resolve()\n }\n\n onUserEvent (f) {\n this.userEventListeners.push(f)\n }\n\n removeUserEventListener (f) {\n this.userEventListeners = this.userEventListeners.filter(g => f !== g)\n }\n\n userLeft (user) {\n if (this.connections.has(user)) {\n this.log('%s: User left %s', this.y.userID, user)\n this.connections.delete(user)\n // check if isSynced event can be sent now\n this._setSyncedWith(null)\n for (var f of this.userEventListeners) {\n f({\n action: 'userLeft',\n user: user\n })\n }\n }\n }\n\n userJoined (user, role, auth) {\n if (role == null) {\n throw new Error('You must specify the role of the joined user!')\n }\n if (this.connections.has(user)) {\n throw new Error('This user already joined!')\n }\n this.log('%s: User joined %s', this.y.userID, user)\n this.connections.set(user, {\n uid: user,\n isSynced: false,\n role: role,\n processAfterAuth: [],\n processAfterSync: [],\n auth: auth || null,\n receivedSyncStep2: false\n })\n let defer = {}\n defer.promise = new Promise(function (resolve) { defer.resolve = resolve })\n this.connections.get(user).syncStep2 = defer\n for (var f of this.userEventListeners) {\n f({\n action: 'userJoined',\n user: user,\n role: role\n })\n }\n this._syncWithUser(user)\n }\n\n // Execute a function _when_ we are connected.\n // If not connected, wait until connected\n whenSynced (f) {\n if (this.isSynced) {\n f()\n } else {\n this.whenSyncedListeners.push(f)\n }\n }\n\n _syncWithUser (userID) {\n if (this.role === 'slave') {\n return // \"The current sync has not finished or this is controlled by a master!\"\n }\n sendSyncStep1(this, userID)\n }\n\n _fireIsSyncedListeners () {\n if (!this.isSynced) {\n this.isSynced = true\n // It is safer to remove this!\n // call whensynced listeners\n for (var f of this.whenSyncedListeners) {\n f()\n }\n this.whenSyncedListeners = []\n this.y._setContentReady()\n this.y.emit('synced')\n }\n }\n\n send (uid, buffer) {\n const y = this.y\n if (!(buffer instanceof ArrayBuffer || buffer instanceof Uint8Array)) {\n throw new Error('Expected Message to be an ArrayBuffer or Uint8Array - don\\'t use this method to send custom messages')\n }\n this.log('User%s to User%s: Send \\'%y\\'', y.userID, uid, buffer)\n this.logMessage('User%s to User%s: Send %Y', y.userID, uid, [y, buffer])\n }\n\n broadcast (buffer) {\n const y = this.y\n if (!(buffer instanceof ArrayBuffer || buffer instanceof Uint8Array)) {\n throw new Error('Expected Message to be an ArrayBuffer or Uint8Array - don\\'t use this method to send custom messages')\n }\n this.log('User%s: Broadcast \\'%y\\'', y.userID, buffer)\n this.logMessage('User%s: Broadcast: %Y', y.userID, [y, buffer])\n }\n\n /*\n Buffer operations, and broadcast them when ready.\n */\n broadcastStruct (struct) {\n const firstContent = this.broadcastBuffer.length === 0\n if (firstContent) {\n this.broadcastBuffer.writeVarString(this.y.room)\n this.broadcastBuffer.writeVarString('update')\n this.broadcastBufferSize = 0\n this.broadcastBufferSizePos = this.broadcastBuffer.pos\n this.broadcastBuffer.writeUint32(0)\n }\n this.broadcastBufferSize++\n struct._toBinary(this.broadcastBuffer)\n if (this.maxBufferLength > 0 && this.broadcastBuffer.length > this.maxBufferLength) {\n // it is necessary to send the buffer now\n // cache the buffer and check if server is responsive\n const buffer = this.broadcastBuffer\n buffer.setUint32(this.broadcastBufferSizePos, this.broadcastBufferSize)\n this.broadcastBuffer = new BinaryEncoder()\n this.whenRemoteResponsive().then(() => {\n this.broadcast(buffer.createBuffer())\n })\n } else if (firstContent) {\n // send the buffer when all transactions are finished\n // (or buffer exceeds maxBufferLength)\n setTimeout(() => {\n if (this.broadcastBuffer.length > 0) {\n const buffer = this.broadcastBuffer\n buffer.setUint32(this.broadcastBufferSizePos, this.broadcastBufferSize)\n this.broadcast(buffer.createBuffer())\n this.broadcastBuffer = new BinaryEncoder()\n }\n }, 0)\n }\n }\n\n /*\n * Somehow check the responsiveness of the remote clients/server\n * Default behavior:\n * Wait 100ms before broadcasting the next batch of operations\n *\n * Only used when maxBufferLength is set\n *\n */\n whenRemoteResponsive () {\n return new Promise(function (resolve) {\n setTimeout(resolve, 100)\n })\n }\n\n /*\n You received a raw message, and you know that it is intended for Yjs. Then call this function.\n */\n receiveMessage (sender, buffer, skipAuth) {\n const y = this.y\n const userID = y.userID\n skipAuth = skipAuth || false\n if (!(buffer instanceof ArrayBuffer || buffer instanceof Uint8Array)) {\n return Promise.reject(new Error('Expected Message to be an ArrayBuffer or Uint8Array!'))\n }\n if (sender === userID) {\n return Promise.resolve()\n }\n let decoder = new BinaryDecoder(buffer)\n let encoder = new BinaryEncoder()\n let roomname = decoder.readVarString() // read room name\n encoder.writeVarString(roomname)\n let messageType = decoder.readVarString()\n let senderConn = this.connections.get(sender)\n this.log('User%s from User%s: Receive \\'%s\\'', userID, sender, messageType)\n this.logMessage('User%s from User%s: Receive %Y', userID, sender, [y, buffer])\n if (senderConn == null && !skipAuth) {\n throw new Error('Received message from unknown peer!')\n }\n if (messageType === 'sync step 1' || messageType === 'sync step 2') {\n let auth = decoder.readVarUint()\n if (senderConn.auth == null) {\n senderConn.processAfterAuth.push([messageType, senderConn, decoder, encoder, sender])\n // check auth\n return this.checkAuth(auth, y, sender).then(authPermissions => {\n if (senderConn.auth == null) {\n senderConn.auth = authPermissions\n y.emit('userAuthenticated', {\n user: senderConn.uid,\n auth: authPermissions\n })\n }\n let messages = senderConn.processAfterAuth\n senderConn.processAfterAuth = []\n\n messages.forEach(m =>\n this.computeMessage(m[0], m[1], m[2], m[3], m[4])\n )\n })\n }\n }\n if ((skipAuth || senderConn.auth != null) && (messageType !== 'update' || senderConn.isSynced)) {\n this.computeMessage(messageType, senderConn, decoder, encoder, sender, skipAuth)\n } else {\n senderConn.processAfterSync.push([messageType, senderConn, decoder, encoder, sender, false])\n }\n }\n\n computeMessage (messageType, senderConn, decoder, encoder, sender, skipAuth) {\n if (messageType === 'sync step 1' && (senderConn.auth === 'write' || senderConn.auth === 'read')) {\n // cannot wait for sync step 1 to finish, because we may wait for sync step 2 in sync step 1 (->lock)\n readSyncStep1(decoder, encoder, this.y, senderConn, sender)\n } else {\n const y = this.y\n y.transact(function () {\n if (messageType === 'sync step 2' && senderConn.auth === 'write') {\n readSyncStep2(decoder, encoder, y, senderConn, sender)\n } else if (messageType === 'update' && (skipAuth || senderConn.auth === 'write')) {\n integrateRemoteStructs(y, decoder)\n } else {\n throw new Error('Unable to receive message')\n }\n }, true)\n }\n }\n\n _setSyncedWith (user) {\n if (user != null) {\n const userConn = this.connections.get(user)\n userConn.isSynced = true\n const messages = userConn.processAfterSync\n userConn.processAfterSync = []\n messages.forEach(m => {\n this.computeMessage(m[0], m[1], m[2], m[3], m[4])\n })\n }\n const conns = Array.from(this.connections.values())\n if (conns.length > 0 && conns.every(u => u.isSynced)) {\n this._fireIsSyncedListeners()\n }\n }\n}\n","import { writeStructs } from './syncStep1.js'\nimport { integrateRemoteStructs } from './integrateRemoteStructs.js'\nimport { readDeleteSet, writeDeleteSet } from './deleteSet.js'\nimport BinaryEncoder from '../Binary/Encoder.js'\n\nexport function fromBinary (y, decoder) {\n y.transact(function () {\n integrateRemoteStructs(y, decoder)\n readDeleteSet(y, decoder)\n })\n}\n\nexport function toBinary (y) {\n let encoder = new BinaryEncoder()\n writeStructs(y, encoder, new Map())\n writeDeleteSet(y, encoder)\n return encoder\n}\n","\nexport function createMutualExclude () {\n var token = true\n return function mutualExclude (f) {\n if (token) {\n token = false\n try {\n f()\n } catch (e) {\n console.error(e)\n }\n token = true\n }\n }\n}\n","import BinaryEncoder from './Binary/Encoder.js'\nimport BinaryDecoder from './Binary/Decoder.js'\nimport { toBinary, fromBinary } from './MessageHandler/binaryEncode.js'\nimport { integrateRemoteStructs } from './MessageHandler/integrateRemoteStructs.js'\nimport { createMutualExclude } from './Util/mutualExclude.js'\n\nfunction getFreshCnf () {\n let buffer = new BinaryEncoder()\n buffer.writeUint32(0)\n return {\n len: 0,\n buffer\n }\n}\n\nexport default class AbstractPersistence {\n constructor (opts) {\n this.opts = opts\n this.ys = new Map()\n }\n\n _init (y) {\n let cnf = this.ys.get(y)\n if (cnf === undefined) {\n cnf = getFreshCnf()\n cnf.mutualExclude = createMutualExclude()\n this.ys.set(y, cnf)\n return this.init(y).then(() => {\n y.on('afterTransaction', (y, transaction) => {\n let cnf = this.ys.get(y)\n if (cnf.len > 0) {\n cnf.buffer.setUint32(0, cnf.len)\n this.saveUpdate(y, cnf.buffer.createBuffer(), transaction)\n let _cnf = getFreshCnf()\n for (let key in _cnf) {\n cnf[key] = _cnf[key]\n }\n }\n })\n return this.retrieve(y)\n }).then(function () {\n return Promise.resolve(cnf)\n })\n } else {\n return Promise.resolve(cnf)\n }\n }\n deinit (y) {\n this.ys.delete(y)\n y.persistence = null\n }\n\n destroy () {\n this.ys = null\n }\n\n /**\n * Remove all persisted data that belongs to a room.\n * Automatically destroys all Yjs all Yjs instances that persist to\n * the room. If `destroyYjsInstances = false` the persistence functionality\n * will be removed from the Yjs instances.\n *\n * ** Must be overwritten! **\n */\n removePersistedData (room, destroyYjsInstances = true) {\n this.ys.forEach((cnf, y) => {\n if (y.room === room) {\n if (destroyYjsInstances) {\n y.destroy()\n } else {\n this.deinit(y)\n }\n }\n })\n }\n\n /* overwrite */\n saveUpdate (buffer) {\n }\n\n /**\n * Save struct to update buffer.\n * saveUpdate is called when transaction ends\n */\n saveStruct (y, struct) {\n let cnf = this.ys.get(y)\n if (cnf !== undefined) {\n cnf.mutualExclude(function () {\n struct._toBinary(cnf.buffer)\n cnf.len++\n })\n }\n }\n\n /* overwrite */\n retrieve (y, model, updates) {\n let cnf = this.ys.get(y)\n if (cnf !== undefined) {\n cnf.mutualExclude(function () {\n y.transact(function () {\n if (model != null) {\n fromBinary(y, new BinaryDecoder(new Uint8Array(model)))\n }\n if (updates != null) {\n for (let i = 0; i < updates.length; i++) {\n integrateRemoteStructs(y, new BinaryDecoder(new Uint8Array(updates[i])))\n }\n }\n })\n y.emit('persistenceReady')\n })\n }\n }\n\n /* overwrite */\n persist (y) {\n return toBinary(y).createBuffer()\n }\n}\n","\nimport { createMutualExclude } from '../Util/mutualExclude.js'\n\nexport default class Binding {\n constructor (type, target) {\n this.type = type\n this.target = target\n this._mutualExclude = createMutualExclude()\n }\n destroy () {\n this.type = null\n this.target = null\n }\n}\n","\nimport Binding from './Binding.js'\nimport simpleDiff from '../Util/simpleDiff.js'\nimport { getRelativePosition, fromRelativePosition } from '../Util/relativePosition.js'\n\nfunction typeObserver () {\n this._mutualExclude(() => {\n const textarea = this.target\n const textType = this.type\n const relativeStart = getRelativePosition(textType, textarea.selectionStart)\n const relativeEnd = getRelativePosition(textType, textarea.selectionEnd)\n textarea.value = textType.toString()\n const start = fromRelativePosition(textType._y, relativeStart)\n const end = fromRelativePosition(textType._y, relativeEnd)\n textarea.setSelectionRange(start, end)\n })\n}\n\nfunction domObserver () {\n this._mutualExclude(() => {\n let diff = simpleDiff(this.type.toString(), this.target.value)\n this.type.delete(diff.pos, diff.remove)\n this.type.insert(diff.pos, diff.insert)\n })\n}\n\nexport default class TextareaBinding extends Binding {\n constructor (textType, domTextarea) {\n // Binding handles textType as this.type and domTextarea as this.target\n super(textType, domTextarea)\n // set initial value\n domTextarea.value = textType.toString()\n // Observers are handled by this class\n this._typeObserver = typeObserver.bind(this)\n this._domObserver = domObserver.bind(this)\n textType.observe(this._typeObserver)\n domTextarea.addEventListener('input', this._domObserver)\n }\n destroy () {\n // Remove everything that is handled by this class\n this.type.unobserve(this._typeObserver)\n this.target.unobserve(this._domObserver)\n super.destroy()\n }\n}\n","import DeleteStore from './Store/DeleteStore.js'\nimport OperationStore from './Store/OperationStore.js'\nimport StateStore from './Store/StateStore.js'\nimport { generateUserID } from './Util/generateUserID.js'\nimport RootID from './Util/RootID.js'\nimport NamedEventHandler from './Util/NamedEventHandler.js'\nimport UndoManager from './Util/UndoManager.js'\nimport { integrateRemoteStructs } from './MessageHandler/integrateRemoteStructs.js'\n\nimport { messageToString, messageToRoomname } from './MessageHandler/messageToString.js'\n\nimport Connector from './Connector.js'\nimport Persistence from './Persistence.js'\nimport YArray from './Type/YArray.js'\nimport YMap from './Type/YMap.js'\nimport YText from './Type/YText.js'\nimport { YXmlFragment, YXmlElement, YXmlText, YXmlHook } from './Type/y-xml/y-xml.js'\nimport BinaryDecoder from './Binary/Decoder.js'\nimport { getRelativePosition, fromRelativePosition } from './Util/relativePosition.js'\nimport { addStruct as addType } from './Util/structReferences.js'\n\nimport debug from 'debug'\nimport Transaction from './Transaction.js'\n\nimport TextareaBinding from './Binding/TextareaBinding.js'\n\nimport { toBinary, fromBinary } from './MessageHandler/binaryEncode.js'\n\nexport default class Y extends NamedEventHandler {\n constructor (room, opts, persistence) {\n super()\n this.room = room\n if (opts != null) {\n opts.connector.room = room\n }\n this._contentReady = false\n this._opts = opts\n this.userID = generateUserID()\n this.share = {}\n this.ds = new DeleteStore(this)\n this.os = new OperationStore(this)\n this.ss = new StateStore(this)\n this._missingStructs = new Map()\n this._readyToIntegrate = []\n this._transaction = null\n this.connector = null\n this.connected = false\n let initConnection = () => {\n if (opts != null) {\n this.connector = new Y[opts.connector.name](this, opts.connector)\n this.connected = true\n this.emit('connectorReady')\n }\n }\n if (persistence != null) {\n this.persistence = persistence\n persistence._init(this).then(initConnection)\n } else {\n this.persistence = null\n initConnection()\n }\n }\n _setContentReady () {\n if (!this._contentReady) {\n this._contentReady = true\n this.emit('content')\n }\n }\n whenContentReady () {\n if (this._contentReady) {\n return Promise.resolve()\n } else {\n return new Promise(resolve => {\n this.once('content', resolve)\n })\n }\n }\n _beforeChange () {}\n transact (f, remote = false) {\n let initialCall = this._transaction === null\n if (initialCall) {\n this._transaction = new Transaction(this)\n this.emit('beforeTransaction', this, this._transaction, remote)\n }\n try {\n f(this)\n } catch (e) {\n console.error(e)\n }\n if (initialCall) {\n this.emit('beforeObserverCalls', this, this._transaction, remote)\n const transaction = this._transaction\n this._transaction = null\n // emit change events on changed types\n transaction.changedTypes.forEach(function (subs, type) {\n if (!type._deleted) {\n type._callObserver(transaction, subs, remote)\n }\n })\n transaction.changedParentTypes.forEach(function (events, type) {\n if (!type._deleted) {\n events = events\n .filter(event =>\n !event.target._deleted\n )\n events\n .forEach(event => {\n event.currentTarget = type\n })\n // we don't have to check for events.length\n // because there is no way events is empty..\n type._deepEventHandler.callEventListeners(transaction, events)\n }\n })\n // when all changes & events are processed, emit afterTransaction event\n this.emit('afterTransaction', this, transaction, remote)\n }\n }\n // fake _start for root properties (y.set('name', type))\n get _start () {\n return null\n }\n set _start (start) {\n return null\n }\n define (name, TypeConstructor) {\n let id = new RootID(name, TypeConstructor)\n let type = this.os.get(id)\n if (this.share[name] === undefined) {\n this.share[name] = type\n } else if (this.share[name] !== type) {\n throw new Error('Type is already defined with a different constructor')\n }\n return type\n }\n get (name) {\n return this.share[name]\n }\n disconnect () {\n if (this.connected) {\n this.connected = false\n return this.connector.disconnect()\n } else {\n return Promise.resolve()\n }\n }\n reconnect () {\n if (!this.connected) {\n this.connected = true\n return this.connector.reconnect()\n } else {\n return Promise.resolve()\n }\n }\n destroy () {\n super.destroy()\n this.share = null\n if (this.connector != null) {\n if (this.connector.destroy != null) {\n this.connector.destroy()\n } else {\n this.connector.disconnect()\n }\n }\n if (this.persistence !== null) {\n this.persistence.deinit(this)\n this.persistence = null\n }\n this.os = null\n this.ds = null\n this.ss = null\n }\n whenSynced () {\n return new Promise(resolve => {\n this.once('synced', () => {\n resolve()\n })\n })\n }\n}\n\nY.extend = function extendYjs () {\n for (var i = 0; i < arguments.length; i++) {\n var f = arguments[i]\n if (typeof f === 'function') {\n f(Y)\n } else {\n throw new Error('Expected a function!')\n }\n }\n}\n\n// TODO: The following assignments should be moved to yjs-dist\nY.AbstractConnector = Connector\nY.AbstractPersistence = Persistence\nY.Array = YArray\nY.Map = YMap\nY.Text = YText\nY.XmlElement = YXmlElement\nY.XmlFragment = YXmlFragment\nY.XmlText = YXmlText\nY.XmlHook = YXmlHook\n\nY.TextareaBinding = TextareaBinding\n\nY.utils = {\n BinaryDecoder,\n UndoManager,\n getRelativePosition,\n fromRelativePosition,\n addType,\n integrateRemoteStructs,\n toBinary,\n fromBinary\n}\n\nY.debug = debug\ndebug.formatters.Y = messageToString\ndebug.formatters.y = messageToRoomname\n"],"names":["Y","diff","require$$0","ms","debug","Connector","Persistence","addType"],"mappings":";;;;;;;;;AACA,MAAM,CAAC,CAAC;;EAEN,WAAW,CAAC,CAAC,GAAG,EAAE;IAChB,IAAI,CAAC,GAAG,GAAG,IAAG;IACd,IAAI,CAAC,KAAK,GAAG,KAAI;IACjB,IAAI,CAAC,KAAK,GAAG,KAAI;IACjB,IAAI,CAAC,MAAM,GAAG,KAAI;IAClB,IAAI,CAAC,OAAO,GAAG,KAA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