@wangeditor-next/yjs 0.1.2-beta.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,2 +1,1438 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("slate"),require("yjs")):"function"==typeof define&&define.amd?define(["exports","slate","yjs"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).WangEditorYjsModule={},t.slate,t.Y)}(this,(function(t,e,n){"use strict";function r(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}})),e.default=t,Object.freeze(e)}var o=r(n),i="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function a(t){var e={exports:{}};return t(e,e.exports),e.exports}var u,c,s=function(t){return t&&t.Math==Math&&t},f=s("object"==typeof globalThis&&globalThis)||s("object"==typeof window&&window)||s("object"==typeof self&&self)||s("object"==typeof i&&i)||function(){return this}()||Function("return this")(),l=function(t){try{return!!t()}catch(t){return!0}},d=!l((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),h=Function.prototype.call,p=h.bind?h.bind(h):function(){return h.apply(h,arguments)},v={}.propertyIsEnumerable,g=Object.getOwnPropertyDescriptor,y=g&&!v.call({1:2},1)?function(t){var e=g(this,t);return!!e&&e.enumerable}:v,b={f:y},m=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},w=Function.prototype,x=w.bind,O=w.call,S=x&&x.bind(O),T=x?function(t){return t&&S(O,t)}:function(t){return t&&function(){return O.apply(t,arguments)}},E=T({}.toString),j=T("".slice),P=function(t){return j(E(t),8,-1)},R=f.Object,A=T("".split),k=l((function(){return!R("z").propertyIsEnumerable(0)}))?function(t){return"String"==P(t)?A(t,""):R(t)}:R,C=f.TypeError,L=function(t){if(null==t)throw C("Can't call method on "+t);return t},_=function(t){return k(L(t))},M=function(t){return"function"==typeof t},F=function(t){return"object"==typeof t?null!==t:M(t)},I=function(t,e){return arguments.length<2?(n=f[t],M(n)?n:void 0):f[t]&&f[t][e];var n},D=T({}.isPrototypeOf),z=I("navigator","userAgent")||"",N=f.process,W=f.Deno,Y=N&&N.versions||W&&W.version,G=Y&&Y.v8;G&&(c=(u=G.split("."))[0]>0&&u[0]<4?1:+(u[0]+u[1])),!c&&z&&(!(u=z.match(/Edge\/(\d+)/))||u[1]>=74)&&(u=z.match(/Chrome\/(\d+)/))&&(c=+u[1]);var X=c,B=!!Object.getOwnPropertySymbols&&!l((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&X&&X<41})),U=B&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,V=f.Object,q=U?function(t){return"symbol"==typeof t}:function(t){var e=I("Symbol");return M(e)&&D(e.prototype,V(t))},H=f.String,J=function(t){try{return H(t)}catch(t){return"Object"}},K=f.TypeError,$=function(t){if(M(t))return t;throw K(J(t)+" is not a function")},Q=function(t,e){var n=t[e];return null==n?void 0:$(n)},Z=f.TypeError,tt=Object.defineProperty,et=function(t,e){try{tt(f,t,{value:e,configurable:!0,writable:!0})}catch(n){f[t]=e}return e},nt="__core-js_shared__",rt=f[nt]||et(nt,{}),ot=a((function(t){(t.exports=function(t,e){return rt[t]||(rt[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.19.3",mode:"global",copyright:"© 2021 Denis Pushkarev (zloirock.ru)"})})),it=f.Object,at=function(t){return it(L(t))},ut=T({}.hasOwnProperty),ct=Object.hasOwn||function(t,e){return ut(at(t),e)},st=0,ft=Math.random(),lt=T(1..toString),dt=function(t){return"Symbol("+(void 0===t?"":t)+")_"+lt(++st+ft,36)},ht=ot("wks"),pt=f.Symbol,vt=pt&&pt.for,gt=U?pt:pt&&pt.withoutSetter||dt,yt=function(t){if(!ct(ht,t)||!B&&"string"!=typeof ht[t]){var e="Symbol."+t;B&&ct(pt,t)?ht[t]=pt[t]:ht[t]=U&&vt?vt(e):gt(e)}return ht[t]},bt=f.TypeError,mt=yt("toPrimitive"),wt=function(t,e){if(!F(t)||q(t))return t;var n,r=Q(t,mt);if(r){if(void 0===e&&(e="default"),n=p(r,t,e),!F(n)||q(n))return n;throw bt("Can't convert object to primitive value")}return void 0===e&&(e="number"),function(t,e){var n,r;if("string"===e&&M(n=t.toString)&&!F(r=p(n,t)))return r;if(M(n=t.valueOf)&&!F(r=p(n,t)))return r;if("string"!==e&&M(n=t.toString)&&!F(r=p(n,t)))return r;throw Z("Can't convert object to primitive value")}(t,e)},xt=function(t){var e=wt(t,"string");return q(e)?e:e+""},Ot=f.document,St=F(Ot)&&F(Ot.createElement),Tt=function(t){return St?Ot.createElement(t):{}},Et=!d&&!l((function(){return 7!=Object.defineProperty(Tt("div"),"a",{get:function(){return 7}}).a})),jt=Object.getOwnPropertyDescriptor,Pt={f:d?jt:function(t,e){if(t=_(t),e=xt(e),Et)try{return jt(t,e)}catch(t){}if(ct(t,e))return m(!p(b.f,t,e),t[e])}},Rt=f.String,At=f.TypeError,kt=function(t){if(F(t))return t;throw At(Rt(t)+" is not an object")},Ct=f.TypeError,Lt=Object.defineProperty,_t={f:d?Lt:function(t,e,n){if(kt(t),e=xt(e),kt(n),Et)try{return Lt(t,e,n)}catch(t){}if("get"in n||"set"in n)throw Ct("Accessors not supported");return"value"in n&&(t[e]=n.value),t}},Mt=d?function(t,e,n){return _t.f(t,e,m(1,n))}:function(t,e,n){return t[e]=n,t},Ft=T(Function.toString);M(rt.inspectSource)||(rt.inspectSource=function(t){return Ft(t)});var It,Dt,zt,Nt=rt.inspectSource,Wt=f.WeakMap,Yt=M(Wt)&&/native code/.test(Nt(Wt)),Gt=ot("keys"),Xt=function(t){return Gt[t]||(Gt[t]=dt(t))},Bt={},Ut="Object already initialized",Vt=f.TypeError,qt=f.WeakMap;if(Yt||rt.state){var Ht=rt.state||(rt.state=new qt),Jt=T(Ht.get),Kt=T(Ht.has),$t=T(Ht.set);It=function(t,e){if(Kt(Ht,t))throw new Vt(Ut);return e.facade=t,$t(Ht,t,e),e},Dt=function(t){return Jt(Ht,t)||{}},zt=function(t){return Kt(Ht,t)}}else{var Qt=Xt("state");Bt[Qt]=!0,It=function(t,e){if(ct(t,Qt))throw new Vt(Ut);return e.facade=t,Mt(t,Qt,e),e},Dt=function(t){return ct(t,Qt)?t[Qt]:{}},zt=function(t){return ct(t,Qt)}}var Zt={set:It,get:Dt,has:zt,enforce:function(t){return zt(t)?Dt(t):It(t,{})},getterFor:function(t){return function(e){var n;if(!F(e)||(n=Dt(e)).type!==t)throw Vt("Incompatible receiver, "+t+" required");return n}}},te=Function.prototype,ee=d&&Object.getOwnPropertyDescriptor,ne=ct(te,"name"),re={EXISTS:ne,PROPER:ne&&"something"===function(){}.name,CONFIGURABLE:ne&&(!d||d&&ee(te,"name").configurable)},oe=a((function(t){var e=re.CONFIGURABLE,n=Zt.get,r=Zt.enforce,o=String(String).split("String");(t.exports=function(t,n,i,a){var u,c=!!a&&!!a.unsafe,s=!!a&&!!a.enumerable,l=!!a&&!!a.noTargetGet,d=a&&void 0!==a.name?a.name:n;M(i)&&("Symbol("===String(d).slice(0,7)&&(d="["+String(d).replace(/^Symbol\(([^)]*)\)/,"$1")+"]"),(!ct(i,"name")||e&&i.name!==d)&&Mt(i,"name",d),(u=r(i)).source||(u.source=o.join("string"==typeof d?d:""))),t!==f?(c?!l&&t[n]&&(s=!0):delete t[n],s?t[n]=i:Mt(t,n,i)):s?t[n]=i:et(n,i)})(Function.prototype,"toString",(function(){return M(this)&&n(this).source||Nt(this)}))})),ie=Math.ceil,ae=Math.floor,ue=function(t){var e=+t;return e!=e||0===e?0:(e>0?ae:ie)(e)},ce=Math.max,se=Math.min,fe=function(t,e){var n=ue(t);return n<0?ce(n+e,0):se(n,e)},le=Math.min,de=function(t){return t>0?le(ue(t),9007199254740991):0},he=function(t){return de(t.length)},pe=function(t){return function(e,n,r){var o,i=_(e),a=he(i),u=fe(r,a);if(t&&n!=n){for(;a>u;)if((o=i[u++])!=o)return!0}else for(;a>u;u++)if((t||u in i)&&i[u]===n)return t||u||0;return!t&&-1}},ve={includes:pe(!0),indexOf:pe(!1)},ge=ve.indexOf,ye=T([].push),be=function(t,e){var n,r=_(t),o=0,i=[];for(n in r)!ct(Bt,n)&&ct(r,n)&&ye(i,n);for(;e.length>o;)ct(r,n=e[o++])&&(~ge(i,n)||ye(i,n));return i},me=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],we=me.concat("length","prototype"),xe={f:Object.getOwnPropertyNames||function(t){return be(t,we)}},Oe={f:Object.getOwnPropertySymbols},Se=T([].concat),Te=I("Reflect","ownKeys")||function(t){var e=xe.f(kt(t)),n=Oe.f;return n?Se(e,n(t)):e},Ee=function(t,e){for(var n=Te(e),r=_t.f,o=Pt.f,i=0;i<n.length;i++){var a=n[i];ct(t,a)||r(t,a,o(e,a))}},je=/#|\.prototype\./,Pe=function(t,e){var n=Ae[Re(t)];return n==Ce||n!=ke&&(M(e)?l(e):!!e)},Re=Pe.normalize=function(t){return String(t).replace(je,".").toLowerCase()},Ae=Pe.data={},ke=Pe.NATIVE="N",Ce=Pe.POLYFILL="P",Le=Pe,_e=Pt.f,Me=function(t,e){var n,r,o,i,a,u=t.target,c=t.global,s=t.stat;if(n=c?f:s?f[u]||et(u,{}):(f[u]||{}).prototype)for(r in e){if(i=e[r],o=t.noTargetGet?(a=_e(n,r))&&a.value:n[r],!Le(c?r:u+(s?".":"#")+r,t.forced)&&void 0!==o){if(typeof i==typeof o)continue;Ee(i,o)}(t.sham||o&&o.sham)&&Mt(i,"sham",!0),oe(n,r,i,t)}},Fe=Function.prototype,Ie=Fe.apply,De=Fe.bind,ze=Fe.call,Ne="object"==typeof Reflect&&Reflect.apply||(De?ze.bind(Ie):function(){return ze.apply(Ie,arguments)}),We=Array.isArray||function(t){return"Array"==P(t)},Ye={};Ye[yt("toStringTag")]="z";var Ge,Xe="[object z]"===String(Ye),Be=yt("toStringTag"),Ue=f.Object,Ve="Arguments"==P(function(){return arguments}()),qe=Xe?P:function(t){var e,n,r;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(n=function(t,e){try{return t[e]}catch(t){}}(e=Ue(t),Be))?n:Ve?P(e):"Object"==(r=P(e))&&M(e.callee)?"Arguments":r},He=f.String,Je=function(t){if("Symbol"===qe(t))throw TypeError("Cannot convert a Symbol value to a string");return He(t)},Ke=Object.keys||function(t){return be(t,me)},$e=d?Object.defineProperties:function(t,e){kt(t);for(var n,r=_(e),o=Ke(e),i=o.length,a=0;i>a;)_t.f(t,n=o[a++],r[n]);return t},Qe=I("document","documentElement"),Ze="prototype",tn="script",en=Xt("IE_PROTO"),nn=function(){},rn=function(t){return"<"+tn+">"+t+"</"+tn+">"},on=function(t){t.write(rn("")),t.close();var e=t.parentWindow.Object;return t=null,e},an=function(){try{Ge=new ActiveXObject("htmlfile")}catch(t){}var t,e,n;an="undefined"!=typeof document?document.domain&&Ge?on(Ge):(e=Tt("iframe"),n="java"+tn+":",e.style.display="none",Qe.appendChild(e),e.src=String(n),(t=e.contentWindow.document).open(),t.write(rn("document.F=Object")),t.close(),t.F):on(Ge);for(var r=me.length;r--;)delete an[Ze][me[r]];return an()};Bt[en]=!0;var un=Object.create||function(t,e){var n;return null!==t?(nn[Ze]=kt(t),n=new nn,nn[Ze]=null,n[en]=t):n=an(),void 0===e?n:$e(n,e)},cn=function(t,e,n){var r=xt(e);r in t?_t.f(t,r,m(0,n)):t[r]=n},sn=f.Array,fn=Math.max,ln=xe.f,dn="object"==typeof window&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[],hn=function(t){try{return ln(t)}catch(t){return function(t,e,n){for(var r=he(t),o=fe(e,r),i=fe(void 0===n?r:n,r),a=sn(fn(i-o,0)),u=0;o<i;o++,u++)cn(a,u,t[o]);return a.length=u,a}(dn)}},pn={f:function(t){return dn&&"Window"==P(t)?hn(t):ln(_(t))}},vn=T([].slice),gn={f:yt},yn=f,bn=_t.f,mn=_t.f,wn=yt("toStringTag"),xn=function(t,e,n){t&&!ct(t=n?t:t.prototype,wn)&&mn(t,wn,{configurable:!0,value:e})},On=T(T.bind),Sn=function(t,e){return $(t),void 0===e?t:On?On(t,e):function(){return t.apply(e,arguments)}},Tn=function(){},En=[],jn=I("Reflect","construct"),Pn=/^\s*(?:class|function)\b/,Rn=T(Pn.exec),An=!Pn.exec(Tn),kn=function(t){if(!M(t))return!1;try{return jn(Tn,En,t),!0}catch(t){return!1}},Cn=!jn||l((function(){var t;return kn(kn.call)||!kn(Object)||!kn((function(){t=!0}))||t}))?function(t){if(!M(t))return!1;switch(qe(t)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}return An||!!Rn(Pn,Nt(t))}:kn,Ln=yt("species"),_n=f.Array,Mn=function(t,e){return new(function(t){var e;return We(t)&&(e=t.constructor,(Cn(e)&&(e===_n||We(e.prototype))||F(e)&&null===(e=e[Ln]))&&(e=void 0)),void 0===e?_n:e}(t))(0===e?0:e)},Fn=T([].push),In=function(t){var e=1==t,n=2==t,r=3==t,o=4==t,i=6==t,a=7==t,u=5==t||i;return function(c,s,f,l){for(var d,h,p=at(c),v=k(p),g=Sn(s,f),y=he(v),b=0,m=l||Mn,w=e?m(c,y):n||a?m(c,0):void 0;y>b;b++)if((u||b in v)&&(h=g(d=v[b],b,p),t))if(e)w[b]=h;else if(h)switch(t){case 3:return!0;case 5:return d;case 6:return b;case 2:Fn(w,d)}else switch(t){case 4:return!1;case 7:Fn(w,d)}return i?-1:r||o?o:w}},Dn={forEach:In(0),map:In(1),filter:In(2),some:In(3),every:In(4),find:In(5),findIndex:In(6),filterReject:In(7)},zn=Dn.forEach,Nn=Xt("hidden"),Wn="Symbol",Yn="prototype",Gn=yt("toPrimitive"),Xn=Zt.set,Bn=Zt.getterFor(Wn),Un=Object[Yn],Vn=f.Symbol,qn=Vn&&Vn[Yn],Hn=f.TypeError,Jn=f.QObject,Kn=I("JSON","stringify"),$n=Pt.f,Qn=_t.f,Zn=pn.f,tr=b.f,er=T([].push),nr=ot("symbols"),rr=ot("op-symbols"),or=ot("string-to-symbol-registry"),ir=ot("symbol-to-string-registry"),ar=ot("wks"),ur=!Jn||!Jn[Yn]||!Jn[Yn].findChild,cr=d&&l((function(){return 7!=un(Qn({},"a",{get:function(){return Qn(this,"a",{value:7}).a}})).a}))?function(t,e,n){var r=$n(Un,e);r&&delete Un[e],Qn(t,e,n),r&&t!==Un&&Qn(Un,e,r)}:Qn,sr=function(t,e){var n=nr[t]=un(qn);return Xn(n,{type:Wn,tag:t,description:e}),d||(n.description=e),n},fr=function(t,e,n){t===Un&&fr(rr,e,n),kt(t);var r=xt(e);return kt(n),ct(nr,r)?(n.enumerable?(ct(t,Nn)&&t[Nn][r]&&(t[Nn][r]=!1),n=un(n,{enumerable:m(0,!1)})):(ct(t,Nn)||Qn(t,Nn,m(1,{})),t[Nn][r]=!0),cr(t,r,n)):Qn(t,r,n)},lr=function(t,e){kt(t);var n=_(e),r=Ke(n).concat(vr(n));return zn(r,(function(e){d&&!p(dr,n,e)||fr(t,e,n[e])})),t},dr=function(t){var e=xt(t),n=p(tr,this,e);return!(this===Un&&ct(nr,e)&&!ct(rr,e))&&(!(n||!ct(this,e)||!ct(nr,e)||ct(this,Nn)&&this[Nn][e])||n)},hr=function(t,e){var n=_(t),r=xt(e);if(n!==Un||!ct(nr,r)||ct(rr,r)){var o=$n(n,r);return!o||!ct(nr,r)||ct(n,Nn)&&n[Nn][r]||(o.enumerable=!0),o}},pr=function(t){var e=Zn(_(t)),n=[];return zn(e,(function(t){ct(nr,t)||ct(Bt,t)||er(n,t)})),n},vr=function(t){var e=t===Un,n=Zn(e?rr:_(t)),r=[];return zn(n,(function(t){!ct(nr,t)||e&&!ct(Un,t)||er(r,nr[t])})),r};if(B||(Vn=function(){if(D(qn,this))throw Hn("Symbol is not a constructor");var t=arguments.length&&void 0!==arguments[0]?Je(arguments[0]):void 0,e=dt(t),n=function(t){this===Un&&p(n,rr,t),ct(this,Nn)&&ct(this[Nn],e)&&(this[Nn][e]=!1),cr(this,e,m(1,t))};return d&&ur&&cr(Un,e,{configurable:!0,set:n}),sr(e,t)},qn=Vn[Yn],oe(qn,"toString",(function(){return Bn(this).tag})),oe(Vn,"withoutSetter",(function(t){return sr(dt(t),t)})),b.f=dr,_t.f=fr,Pt.f=hr,xe.f=pn.f=pr,Oe.f=vr,gn.f=function(t){return sr(yt(t),t)},d&&(Qn(qn,"description",{configurable:!0,get:function(){return Bn(this).description}}),oe(Un,"propertyIsEnumerable",dr,{unsafe:!0}))),Me({global:!0,wrap:!0,forced:!B,sham:!B},{Symbol:Vn}),zn(Ke(ar),(function(t){!function(t){var e=yn.Symbol||(yn.Symbol={});ct(e,t)||bn(e,t,{value:gn.f(t)})}(t)})),Me({target:Wn,stat:!0,forced:!B},{for:function(t){var e=Je(t);if(ct(or,e))return or[e];var n=Vn(e);return or[e]=n,ir[n]=e,n},keyFor:function(t){if(!q(t))throw Hn(t+" is not a symbol");if(ct(ir,t))return ir[t]},useSetter:function(){ur=!0},useSimple:function(){ur=!1}}),Me({target:"Object",stat:!0,forced:!B,sham:!d},{create:function(t,e){return void 0===e?un(t):lr(un(t),e)},defineProperty:fr,defineProperties:lr,getOwnPropertyDescriptor:hr}),Me({target:"Object",stat:!0,forced:!B},{getOwnPropertyNames:pr,getOwnPropertySymbols:vr}),Me({target:"Object",stat:!0,forced:l((function(){Oe.f(1)}))},{getOwnPropertySymbols:function(t){return Oe.f(at(t))}}),Kn){var gr=!B||l((function(){var t=Vn();return"[null]"!=Kn([t])||"{}"!=Kn({a:t})||"{}"!=Kn(Object(t))}));Me({target:"JSON",stat:!0,forced:gr},{stringify:function(t,e,n){var r=vn(arguments),o=e;if((F(e)||void 0!==t)&&!q(t))return We(e)||(e=function(t,e){if(M(o)&&(e=p(o,this,t,e)),!q(e))return e}),r[1]=e,Ne(Kn,null,r)}})}if(!qn[Gn]){var yr=qn.valueOf;oe(qn,Gn,(function(t){return p(yr,this)}))}xn(Vn,Wn),Bt[Nn]=!0;var br=_t.f,mr=f.Symbol,wr=mr&&mr.prototype;if(d&&M(mr)&&(!("description"in wr)||void 0!==mr().description)){var xr={},Or=function(){var t=arguments.length<1||void 0===arguments[0]?void 0:Je(arguments[0]),e=D(wr,this)?new mr(t):void 0===t?mr():mr(t);return""===t&&(xr[e]=!0),e};Ee(Or,mr),Or.prototype=wr,wr.constructor=Or;var Sr="Symbol(test)"==String(mr("test")),Tr=T(wr.toString),Er=T(wr.valueOf),jr=/^Symbol\((.*)\)[^)]+$/,Pr=T("".replace),Rr=T("".slice);br(wr,"description",{configurable:!0,get:function(){var t=Er(this),e=Tr(t);if(ct(xr,t))return"";var n=Sr?Rr(e,7,-1):Pr(e,jr,"$1");return""===n?void 0:n}}),Me({global:!0,forced:!0},{Symbol:Or})}var Ar=yt("unscopables"),kr=Array.prototype;null==kr[Ar]&&_t.f(kr,Ar,{configurable:!0,value:un(null)});var Cr,Lr,_r,Mr=function(t){kr[Ar][t]=!0},Fr={},Ir=!l((function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype})),Dr=Xt("IE_PROTO"),zr=f.Object,Nr=zr.prototype,Wr=Ir?zr.getPrototypeOf:function(t){var e=at(t);if(ct(e,Dr))return e[Dr];var n=e.constructor;return M(n)&&e instanceof n?n.prototype:e instanceof zr?Nr:null},Yr=yt("iterator"),Gr=!1;[].keys&&("next"in(_r=[].keys())?(Lr=Wr(Wr(_r)))!==Object.prototype&&(Cr=Lr):Gr=!0);var Xr=null==Cr||l((function(){var t={};return Cr[Yr].call(t)!==t}));Xr&&(Cr={}),M(Cr[Yr])||oe(Cr,Yr,(function(){return this}));var Br={IteratorPrototype:Cr,BUGGY_SAFARI_ITERATORS:Gr},Ur=Br.IteratorPrototype,Vr=function(){return this},qr=f.String,Hr=f.TypeError,Jr=Object.setPrototypeOf||("__proto__"in{}?function(){var t,e=!1,n={};try{(t=T(Object.getOwnPropertyDescriptor(Object.prototype,"__proto__").set))(n,[]),e=n instanceof Array}catch(t){}return function(n,r){return kt(n),function(t){if("object"==typeof t||M(t))return t;throw Hr("Can't set "+qr(t)+" as a prototype")}(r),e?t(n,r):n.__proto__=r,n}}():void 0),Kr=re.PROPER,$r=re.CONFIGURABLE,Qr=Br.IteratorPrototype,Zr=Br.BUGGY_SAFARI_ITERATORS,to=yt("iterator"),eo="keys",no="values",ro="entries",oo=function(){return this},io=function(t,e,n,r,o,i,a){!function(t,e,n,r){var o=e+" Iterator";t.prototype=un(Ur,{next:m(+!r,n)}),xn(t,o,!1),Fr[o]=Vr}(n,e,r);var u,c,s,f=function(t){if(t===o&&g)return g;if(!Zr&&t in h)return h[t];switch(t){case eo:case no:case ro:return function(){return new n(this,t)}}return function(){return new n(this)}},l=e+" Iterator",d=!1,h=t.prototype,v=h[to]||h["@@iterator"]||o&&h[o],g=!Zr&&v||f(o),y="Array"==e&&h.entries||v;if(y&&(u=Wr(y.call(new t)))!==Object.prototype&&u.next&&(Wr(u)!==Qr&&(Jr?Jr(u,Qr):M(u[to])||oe(u,to,oo)),xn(u,l,!0)),Kr&&o==no&&v&&v.name!==no&&($r?Mt(h,"name",no):(d=!0,g=function(){return p(v,this)})),o)if(c={values:f(no),keys:i?g:f(eo),entries:f(ro)},a)for(s in c)(Zr||d||!(s in h))&&oe(h,s,c[s]);else Me({target:e,proto:!0,forced:Zr||d},c);return h[to]!==g&&oe(h,to,g,{name:o}),Fr[e]=g,c},ao="Array Iterator",uo=Zt.set,co=Zt.getterFor(ao),so=io(Array,"Array",(function(t,e){uo(this,{type:ao,target:_(t),index:0,kind:e})}),(function(){var t=co(this),e=t.target,n=t.kind,r=t.index++;return!e||r>=e.length?(t.target=void 0,{value:void 0,done:!0}):"keys"==n?{value:r,done:!1}:"values"==n?{value:e[r],done:!1}:{value:[r,e[r]],done:!1}}),"values");Fr.Arguments=Fr.Array,Mr("keys"),Mr("values"),Mr("entries");var fo=Xe?{}.toString:function(){return"[object "+qe(this)+"]"};Xe||oe(Object.prototype,"toString",fo,{unsafe:!0});var lo=T("".charAt),ho=T("".charCodeAt),po=T("".slice),vo=function(t){return function(e,n){var r,o,i=Je(L(e)),a=ue(n),u=i.length;return a<0||a>=u?t?"":void 0:(r=ho(i,a))<55296||r>56319||a+1===u||(o=ho(i,a+1))<56320||o>57343?t?lo(i,a):r:t?po(i,a,a+2):o-56320+(r-55296<<10)+65536}},go={codeAt:vo(!1),charAt:vo(!0)}.charAt,yo="String Iterator",bo=Zt.set,mo=Zt.getterFor(yo);io(String,"String",(function(t){bo(this,{type:yo,string:Je(t),index:0})}),(function(){var t,e=mo(this),n=e.string,r=e.index;return r>=n.length?{value:void 0,done:!0}:(t=go(n,r),e.index+=t.length,{value:t,done:!1})}));var wo=function(t,e,n){for(var r in e)oe(t,r,e[r],n);return t},xo=l((function(){if("function"==typeof ArrayBuffer){var t=new ArrayBuffer(8);Object.isExtensible(t)&&Object.defineProperty(t,"a",{value:8})}})),Oo=Object.isExtensible,So=l((function(){Oo(1)}))||xo?function(t){return!!F(t)&&((!xo||"ArrayBuffer"!=P(t))&&(!Oo||Oo(t)))}:Oo,To=!l((function(){return Object.isExtensible(Object.preventExtensions({}))})),Eo=a((function(t){var e=_t.f,n=!1,r=dt("meta"),o=0,i=function(t){e(t,r,{value:{objectID:"O"+o++,weakData:{}}})},a=t.exports={enable:function(){a.enable=function(){},n=!0;var t=xe.f,e=T([].splice),o={};o[r]=1,t(o).length&&(xe.f=function(n){for(var o=t(n),i=0,a=o.length;i<a;i++)if(o[i]===r){e(o,i,1);break}return o},Me({target:"Object",stat:!0,forced:!0},{getOwnPropertyNames:pn.f}))},fastKey:function(t,e){if(!F(t))return"symbol"==typeof t?t:("string"==typeof t?"S":"P")+t;if(!ct(t,r)){if(!So(t))return"F";if(!e)return"E";i(t)}return t[r].objectID},getWeakData:function(t,e){if(!ct(t,r)){if(!So(t))return!0;if(!e)return!1;i(t)}return t[r].weakData},onFreeze:function(t){return To&&n&&So(t)&&!ct(t,r)&&i(t),t}};Bt[r]=!0})),jo=yt("iterator"),Po=Array.prototype,Ro=function(t){return void 0!==t&&(Fr.Array===t||Po[jo]===t)},Ao=yt("iterator"),ko=function(t){if(null!=t)return Q(t,Ao)||Q(t,"@@iterator")||Fr[qe(t)]},Co=f.TypeError,Lo=function(t,e){var n=arguments.length<2?ko(t):e;if($(n))return kt(p(n,t));throw Co(J(t)+" is not iterable")},_o=function(t,e,n){var r,o;kt(t);try{if(!(r=Q(t,"return"))){if("throw"===e)throw n;return n}r=p(r,t)}catch(t){o=!0,r=t}if("throw"===e)throw n;if(o)throw r;return kt(r),n},Mo=f.TypeError,Fo=function(t,e){this.stopped=t,this.result=e},Io=Fo.prototype,Do=function(t,e,n){var r,o,i,a,u,c,s,f=n&&n.that,l=!(!n||!n.AS_ENTRIES),d=!(!n||!n.IS_ITERATOR),h=!(!n||!n.INTERRUPTED),v=Sn(e,f),g=function(t){return r&&_o(r,"normal",t),new Fo(!0,t)},y=function(t){return l?(kt(t),h?v(t[0],t[1],g):v(t[0],t[1])):h?v(t,g):v(t)};if(d)r=t;else{if(!(o=ko(t)))throw Mo(J(t)+" is not iterable");if(Ro(o)){for(i=0,a=he(t);a>i;i++)if((u=y(t[i]))&&D(Io,u))return u;return new Fo(!1)}r=Lo(t,o)}for(c=r.next;!(s=p(c,r)).done;){try{u=y(s.value)}catch(t){_o(r,"throw",t)}if("object"==typeof u&&u&&D(Io,u))return u}return new Fo(!1)},zo=f.TypeError,No=function(t,e){if(D(e,t))return t;throw zo("Incorrect invocation")},Wo=yt("iterator"),Yo=!1;try{var Go=0,Xo={next:function(){return{done:!!Go++}},return:function(){Yo=!0}};Xo[Wo]=function(){return this},Array.from(Xo,(function(){throw 2}))}catch(t){}var Bo=function(t,e){if(!e&&!Yo)return!1;var n=!1;try{var r={};r[Wo]=function(){return{next:function(){return{done:n=!0}}}},t(r)}catch(t){}return n},Uo=function(t,e,n){var r=-1!==t.indexOf("Map"),o=-1!==t.indexOf("Weak"),i=r?"set":"add",a=f[t],u=a&&a.prototype,c=a,s={},d=function(t){var e=T(u[t]);oe(u,t,"add"==t?function(t){return e(this,0===t?0:t),this}:"delete"==t?function(t){return!(o&&!F(t))&&e(this,0===t?0:t)}:"get"==t?function(t){return o&&!F(t)?void 0:e(this,0===t?0:t)}:"has"==t?function(t){return!(o&&!F(t))&&e(this,0===t?0:t)}:function(t,n){return e(this,0===t?0:t,n),this})};if(Le(t,!M(a)||!(o||u.forEach&&!l((function(){(new a).entries().next()})))))c=n.getConstructor(e,t,r,i),Eo.enable();else if(Le(t,!0)){var h=new c,p=h[i](o?{}:-0,1)!=h,v=l((function(){h.has(1)})),g=Bo((function(t){new a(t)})),y=!o&&l((function(){for(var t=new a,e=5;e--;)t[i](e,e);return!t.has(-0)}));g||((c=e((function(t,e){No(t,u);var n=function(t,e,n){var r,o;return Jr&&M(r=e.constructor)&&r!==n&&F(o=r.prototype)&&o!==n.prototype&&Jr(t,o),t}(new a,t,c);return null!=e&&Do(e,n[i],{that:n,AS_ENTRIES:r}),n}))).prototype=u,u.constructor=c),(v||y)&&(d("delete"),d("has"),r&&d("get")),(y||p)&&d(i),o&&u.clear&&delete u.clear}return s[t]=c,Me({global:!0,forced:c!=a},s),xn(c,t),o||n.setStrong(c,t,r),c},Vo=Eo.getWeakData,qo=Zt.set,Ho=Zt.getterFor,Jo=Dn.find,Ko=Dn.findIndex,$o=T([].splice),Qo=0,Zo=function(t){return t.frozen||(t.frozen=new ti)},ti=function(){this.entries=[]},ei=function(t,e){return Jo(t.entries,(function(t){return t[0]===e}))};ti.prototype={get:function(t){var e=ei(this,t);if(e)return e[1]},has:function(t){return!!ei(this,t)},set:function(t,e){var n=ei(this,t);n?n[1]=e:this.entries.push([t,e])},delete:function(t){var e=Ko(this.entries,(function(e){return e[0]===t}));return~e&&$o(this.entries,e,1),!!~e}};var ni,ri={getConstructor:function(t,e,n,r){var o=t((function(t,o){No(t,i),qo(t,{type:e,id:Qo++,frozen:void 0}),null!=o&&Do(o,t[r],{that:t,AS_ENTRIES:n})})),i=o.prototype,a=Ho(e),u=function(t,e,n){var r=a(t),o=Vo(kt(e),!0);return!0===o?Zo(r).set(e,n):o[r.id]=n,t};return wo(i,{delete:function(t){var e=a(this);if(!F(t))return!1;var n=Vo(t);return!0===n?Zo(e).delete(t):n&&ct(n,e.id)&&delete n[e.id]},has:function(t){var e=a(this);if(!F(t))return!1;var n=Vo(t);return!0===n?Zo(e).has(t):n&&ct(n,e.id)}}),wo(i,n?{get:function(t){var e=a(this);if(F(t)){var n=Vo(t);return!0===n?Zo(e).get(t):n?n[e.id]:void 0}},set:function(t,e){return u(this,t,e)}}:{add:function(t){return u(this,t,!0)}}),o}},oi=Zt.enforce,ii=!f.ActiveXObject&&"ActiveXObject"in f,ai=function(t){return function(){return t(this,arguments.length?arguments[0]:void 0)}},ui=Uo("WeakMap",ai,ri);if(Yt&&ii){ni=ri.getConstructor(ai,"WeakMap",!0),Eo.enable();var ci=ui.prototype,si=T(ci.delete),fi=T(ci.has),li=T(ci.get),di=T(ci.set);wo(ci,{delete:function(t){if(F(t)&&!So(t)){var e=oi(this);return e.frozen||(e.frozen=new ni),si(this,t)||e.frozen.delete(t)}return si(this,t)},has:function(t){if(F(t)&&!So(t)){var e=oi(this);return e.frozen||(e.frozen=new ni),fi(this,t)||e.frozen.has(t)}return fi(this,t)},get:function(t){if(F(t)&&!So(t)){var e=oi(this);return e.frozen||(e.frozen=new ni),fi(this,t)?li(this,t):e.frozen.get(t)}return li(this,t)},set:function(t,e){if(F(t)&&!So(t)){var n=oi(this);n.frozen||(n.frozen=new ni),fi(this,t)?di(this,t,e):n.frozen.set(t,e)}else di(this,t,e);return this}})}Uo("WeakSet",(function(t){return function(){return t(this,arguments.length?arguments[0]:void 0)}}),ri);var hi,pi,vi={CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0},gi=Tt("span").classList,yi=gi&&gi.constructor&&gi.constructor.prototype,bi=yi===Object.prototype?void 0:yi,mi=Dn.forEach,wi=!!(pi=[]["forEach"])&&l((function(){pi.call(null,hi||function(){throw 1},1)}))?[].forEach:function(t){return mi(this,t,arguments.length>1?arguments[1]:void 0)},xi=function(t){if(t&&t.forEach!==wi)try{Mt(t,"forEach",wi)}catch(e){t.forEach=wi}};for(var Oi in vi)vi[Oi]&&xi(f[Oi]&&f[Oi].prototype);xi(bi);var Si=yt("iterator"),Ti=yt("toStringTag"),Ei=so.values,ji=function(t,e){if(t){if(t[Si]!==Ei)try{Mt(t,Si,Ei)}catch(e){t[Si]=Ei}if(t[Ti]||Mt(t,Ti,e),vi[e])for(var n in so)if(t[n]!==so[n])try{Mt(t,n,so[n])}catch(e){t[n]=so[n]}}};for(var Pi in vi)ji(f[Pi]&&f[Pi].prototype,Pi);ji(bi,"DOMTokenList");var Ri=function(){return Ri=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Ri.apply(this,arguments)};function Ai(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}function ki(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function Ci(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a}function Li(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var _i=function(t,e,n,r){try{return r?e(kt(n)[0],n[1]):e(n)}catch(e){_o(t,"throw",e)}},Mi=f.Array,Fi=!Bo((function(t){Array.from(t)}));Me({target:"Array",stat:!0,forced:Fi},{from:function(t){var e=at(t),n=Cn(this),r=arguments.length,o=r>1?arguments[1]:void 0,i=void 0!==o;i&&(o=Sn(o,r>2?arguments[2]:void 0));var a,u,c,s,f,l,d=ko(e),h=0;if(!d||this==Mi&&Ro(d))for(a=he(e),u=n?new this(a):Mi(a);a>h;h++)l=i?o(e[h],h):e[h],cn(u,h,l);else for(f=(s=Lo(e,d)).next,u=n?new this:[];!(c=p(f,s)).done;h++)l=i?_i(s,o,[c.value,h],!0):c.value,cn(u,h,l);return u.length=h,u}});var Ii=yt("species"),Di=function(t){return X>=51||!l((function(){var e=[];return(e.constructor={})[Ii]=function(){return{foo:1}},1!==e[t](Boolean).foo}))},zi=Dn.map,Ni=Di("map");Me({target:"Array",proto:!0,forced:!Ni},{map:function(t){return zi(this,t,arguments.length>1?arguments[1]:void 0)}});var Wi=Di("slice"),Yi=yt("species"),Gi=f.Array,Xi=Math.max;Me({target:"Array",proto:!0,forced:!Wi},{slice:function(t,e){var n,r,o,i=_(this),a=he(i),u=fe(t,a),c=fe(void 0===e?a:e,a);if(We(i)&&(n=i.constructor,(Cn(n)&&(n===Gi||We(n.prototype))||F(n)&&null===(n=n[Yi]))&&(n=void 0),n===Gi||void 0===n))return vn(i,u,c);for(r=new(void 0===n?Gi:n)(Xi(c-u,0)),o=0;u<c;u++,o++)u in i&&cn(r,o,i[u]);return r.length=o,r}}),Me({target:"Object",stat:!0},{fromEntries:function(t){var e={};return Do(t,(function(t,n){cn(e,t,n)}),{AS_ENTRIES:!0}),e}});var Bi=l((function(){Ke(1)}));Me({target:"Object",stat:!0,forced:Bi},{keys:function(t){return Ke(at(t))}});var Ui=b.f,Vi=T(Ui),qi=T([].push),Hi=function(t){return function(e){for(var n,r=_(e),o=Ke(r),i=o.length,a=0,u=[];i>a;)n=o[a++],d&&!Vi(r,n)||qi(u,t?[n,r[n]]:r[n]);return u}},Ji={entries:Hi(!0),values:Hi(!1)}.entries;Me({target:"Object",stat:!0},{entries:function(t){return Ji(t)}});var Ki=Dn.filter,$i=Di("filter");Me({target:"Array",proto:!0,forced:!$i},{filter:function(t){return Ki(this,t,arguments.length>1?arguments[1]:void 0)}});var Qi=ve.includes;Me({target:"Array",proto:!0},{includes:function(t){return Qi(this,t,arguments.length>1?arguments[1]:void 0)}}),Mr("includes");var Zi=re.PROPER,ta="toString",ea=RegExp.prototype,na=ea[ta],ra=T((function(){var t=kt(this),e="";return t.global&&(e+="g"),t.ignoreCase&&(e+="i"),t.multiline&&(e+="m"),t.dotAll&&(e+="s"),t.unicode&&(e+="u"),t.sticky&&(e+="y"),e})),oa=l((function(){return"/a/b"!=na.call({source:"a",flags:"b"})})),ia=Zi&&na.name!=ta;function aa(t){return"[object Object]"===Object.prototype.toString.call(t)}function ua(t){if(!aa(t))return!1;var e=t.constructor;if(void 0===e)return!0;var n=e.prototype;return!1!==aa(n)&&!Object.prototype.hasOwnProperty.call(n,"isPrototypeOfOf")}function ca(t,e){for(var n in t){var r=t[n],o=e[n];if(ua(r)&&ua(o)){if(!ca(r,o))return!1}else if(Array.isArray(r)&&Array.isArray(o)){if(r.length!==o.length)return!1;for(var i=0;i<r.length;i++)if(r[i]!==o[i])return!1}else if(r!==o)return!1}for(var n in e)if(void 0===t[n]&&void 0!==e[n])return!1;return!0}function sa(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];return Object.fromEntries(Object.entries(t).filter((function(t){var n=Ci(t,1)[0];return e.includes(n)})))}function fa(t){return function(t){var e,n,r,o,i=[];try{for(var a=ki(t),u=a.next();!u.done;u=a.next()){var c=u.value;if("string"!=typeof c.insert||0!==c.insert.length){var s=i[i.length-1];s&&"string"==typeof s.insert&&"string"==typeof c.insert&&(s.attributes===c.attributes||!s.attributes==!c.attributes&&ca(null!==(r=s.attributes)&&void 0!==r?r:{},null!==(o=c.attributes)&&void 0!==o?o:{}))?s.insert+=c.insert:i.push(c)}}}catch(t){e={error:t}}finally{try{u&&!u.done&&(n=a.return)&&n.call(a)}finally{if(e)throw e.error}}return i}(t.toDelta())}function la(t){var e=t.insert;return"string"==typeof e?e.length:1}function da(t){return t.reduce((function(t,e){return t+la(e)}),0)}function ha(t,e,n){if(n<1)return[];for(var r=0,o=[],i=e+n,a=0;a<t.length&&!(r>=i);a++){var u=t[a],c=la(u);if(r+c<=e)r+=c;else if("string"==typeof u.insert){var s=Math.max(0,e-r),f=Math.min(c,c-(r+c-i));o.push(Ri(Ri({},u),{insert:u.insert.slice(s,f)})),r+=c}else r+=c,o.push(u)}return o}function pa(t){return function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];return Object.fromEntries(Object.entries(t).filter((function(t){var n=Ci(t,1)[0];return!e.includes(n)})))}(t,e.Text.isText(t)?"text":"children")}function va(t){var e=fa(t),n=e.length>0?e.map(ga):[{text:""}];return Ri(Ri({},t.getAttributes()),{children:n})}function ga(t){return"string"==typeof t.insert?Ri(Ri({},t.attributes),{text:t.insert}):va(t.insert)}function ya(t){return t.map((function(t){return e.Text.isText(t)?{insert:t.text,attributes:pa(t)}:{insert:ba(t)}}))}function ba(t){var e=t.children,n=Ai(t,["children"]),r=new o.XmlText;return Object.entries(n).forEach((function(t){var e=Ci(t,2),n=e[0],o=e[1];r.setAttribute(n,o)})),r.applyDelta(ya(e),{sanitize:!1}),r}(oa||ia)&&oe(RegExp.prototype,ta,(function(){var t=kt(this),e=Je(t.source),n=t.flags;return"/"+e+"/"+Je(void 0===n&&D(ea,t)&&!("flags"in ea)?ra(t):n)}),{unsafe:!0});var ma=yt("isConcatSpreadable"),wa=9007199254740991,xa="Maximum allowed index exceeded",Oa=f.TypeError,Sa=X>=51||!l((function(){var t=[];return t[ma]=!1,t.concat()[0]!==t})),Ta=Di("concat"),Ea=function(t){if(!F(t))return!1;var e=t[ma];return void 0!==e?!!e:We(t)};function ja(t){return t?e.Text.isText(t)?t.text.length:1:0}function Pa(t,n,r){var i;if(0===r.length)throw new Error("Path has to a have a length >= 1");if(e.Text.isText(n))throw new Error("Cannot descent into slate text");var a=Ci(r),u=a[0],c=a.slice(1),s=function(t,e){return t.children.slice(0,e).reduce((function(t,e){return t+ja(e)}),0)}(n,u),f=n.children[u],l=fa(t),d=ja(f),h=ha(l,s,d);if(h.length>1)throw new Error("Path doesn't match yText, yTarget spans multiple nodes");var p=null===(i=h[0])||void 0===i?void 0:i.insert;if(c.length>0){if(!(p instanceof o.XmlText))throw new Error("Path doesn't match yText, cannot descent into non-yText");return Pa(p,f,c)}return{yParent:t,textRange:{start:s,end:s+d},yTarget:p instanceof o.XmlText?p:void 0,slateParent:n,slateTarget:f,targetDelta:h}}function Ra(t,n,r){void 0===r&&(r={});for(var o=r.assoc,i=void 0===o?0:o,a=r.insert,u=void 0!==a&&a,c=0,s=0,f=0;f<t.children.length;f++){var l=t.children[f],d=e.Text.isText(l)?l.text.length:1;d>0&&(s=f);var h=c+d;if(d>0&&(i>=0?h>n:h>=n))return[f,n-c];c+=d}if(n>c+(u?1:0))throw new Error("yOffset out of bounds");if(u)return[t.children.length,0];var p=t.children[s];return[s,e.Text.isText(p)?p.text.length:1]}function Aa(t,n,r){for(var i=[r];i[0]!==t;){var a=i[0].parent;if(!a)throw new Error("yText isn't a descendant of root element");if(!(a instanceof o.XmlText))throw new Error("Unexpected y parent type");i.unshift(a)}if(i.length<2)return[];var u=n;return i.reduce((function(t,n,r){var o,a,c=i[r+1];if(!c)return t;var s=0,f=fa(n);try{for(var l=ki(f),d=l.next();!d.done;d=l.next()){var h=d.value;if(h.insert===c)break;s+="string"==typeof h.insert?h.insert.length:1}}catch(t){o={error:t}}finally{try{d&&!d.done&&(a=l.return)&&a.call(l)}finally{if(o)throw o.error}}if(e.Text.isText(u))throw new Error("Cannot descent into slate text");var p=Ci(Ra(u,s),1)[0];return u=u.children[p],t.concat(p)}),[])}function ka(t,n,r){var i=r.target,a=r.changes,u=r.delta;if(!(i instanceof o.XmlText))throw new Error("Unexpected target node type");var c=[],s=Aa(t,n,i),f=e.Node.get(n,s);if(e.Text.isText(f))throw new Error("Cannot apply yTextEvent to text node");var l=Array.from(a.keys.entries());if(s.length>0&&l.length>0){var d=Object.fromEntries(l.map((function(t){var e=Ci(t,2),n=e[0];return[n,"delete"===e[1].action?null:i.getAttribute(n)]}))),h=Object.fromEntries(l.map((function(t){var e=Ci(t,1)[0];return[e,f[e]]})));c.push({type:"set_node",newProperties:d,properties:h,path:s})}return u.length>0&&c.push.apply(c,Li([],Ci(function(t,n,r){var o=[],i=r.reduce((function(t,e){return"retain"in e?t+e.retain:"delete"in e?t+e.delete:t}),0);return r.reverse().forEach((function(r){var a,u;if("attributes"in r&&"retain"in r)for(var c=Ci(Ra(t,i-r.retain),2),s=c[0],f=c[1],l=Ci(Ra(t,i,{assoc:-1}),2),d=l[0],h=l[1],p=d;p>=s;p--){var v=t.children[p],g=Li(Li([],Ci(n)),[p]);if(e.Text.isText(v)){var y=r.attributes,b=sa.apply(void 0,Li([t],Ci(Object.keys(r.attributes))));if(p===s||p===d){var m=p===s?f:0;if((O=p===d?h:v.text.length)!==v.text.length&&o.push({type:"split_node",path:g,position:O,properties:pa(v)}),0!==m){o.push({type:"split_node",path:g,position:m,properties:(u=Ri(Ri({},pa(v)),y),Object.fromEntries(Object.entries(u).filter((function(t){return null!==Ci(t,2)[1]}))))});continue}}o.push({type:"set_node",newProperties:y,path:g,properties:b})}}if("retain"in r&&(i-=r.retain),"delete"in r){var w=Ci(Ra(t,i-r.delete),2),x=(s=w[0],f=w[1],Ci(Ra(t,i,{assoc:-1}),2));for(d=x[0],p=0===(h=x[1])?d-1:d;p>=s;p--)if(v=t.children[p],g=Li(Li([],Ci(n)),[p]),!e.Text.isText(v)||p!==s&&p!==d)o.push({type:"remove_node",node:v,path:g}),i-=ja(v);else{m=p===s?f:0;var O=p===d?h:v.text.length;o.push({type:"remove_text",offset:m,text:v.text.slice(m,O),path:g}),i-=O-m}}else if("insert"in r){var S=Ci(Ra(t,i,{insert:!0}),2),T=(p=S[0],S[1]);if(v=t.children[p],g=Li(Li([],Ci(n)),[p]),e.Text.isText(v)){var E=o[o.length-1],j=null!=E&&"insert_node"===E.type?E.node:pa(v),P=[];if(null==E||"insert_node"!==E.type&&"insert_text"!==E.type&&"split_node"!==E.type&&"set_node"!==E.type||(P=E.path),"string"==typeof r.insert&&ca(null!==(a=r.attributes)&&void 0!==a?a:{},j)&&e.Path.equals(g,P))return o.push({type:"insert_text",offset:T,text:r.insert,path:g});var R=ga(r);return 0===T?o.push({type:"insert_node",path:g,node:R}):(T<v.text.length&&o.push({type:"split_node",path:g,position:T,properties:pa(v)}),o.push({type:"insert_node",path:e.Path.next(g),node:R}))}return o.push({type:"insert_node",path:g,node:ga(r)})}})),o}(f,s,u)))),c}function Ca(t,n,r){e.Editor.withoutNormalizing(n,(function(){r.forEach((function(e){(function(t,e,n){if(n instanceof o.YTextEvent)return ka(t,e,n);throw new Error("Unexpected Y event type")})(t,n,e).forEach((function(t){n.apply(t)}))}))}))}function La(t){return t.map((function(t){return"string"==typeof t.insert?t:Ri(Ri({},t),{insert:_a(t.insert)})}))}function _a(t){var e=new o.XmlText,n=t.getAttributes();return Object.entries(n).forEach((function(t){var n=Ci(t,2),r=n[0],o=n[1];e.setAttribute(r,o)})),e.applyDelta(La(fa(t)),{sanitize:!1}),e}Me({target:"Array",proto:!0,forced:!Sa||!Ta},{concat:function(t){var e,n,r,o,i,a=at(this),u=Mn(a,0),c=0;for(e=-1,r=arguments.length;e<r;e++)if(Ea(i=-1===e?a:arguments[e])){if(c+(o=he(i))>wa)throw Oa(xa);for(n=0;n<o;n++,c++)n in i&&cn(u,c,i[n])}else{if(c>=wa)throw Oa(xa);cn(u,c++,i)}return u.length=c,u}});var Ma=Object.assign,Fa=Object.defineProperty,Ia=T([].concat),Da=!Ma||l((function(){if(d&&1!==Ma({b:1},Ma(Fa({},"a",{enumerable:!0,get:function(){Fa(this,"b",{value:3,enumerable:!1})}}),{b:2})).b)return!0;var t={},e={},n=Symbol(),r="abcdefghijklmnopqrst";return t[n]=7,r.split("").forEach((function(t){e[t]=t})),7!=Ma({},t)[n]||Ke(Ma({},e)).join("")!=r}))?function(t,e){for(var n=at(t),r=arguments.length,o=1,i=Oe.f,a=b.f;r>o;)for(var u,c=k(arguments[o++]),s=i?Ia(Ke(c),i(c)):Ke(c),f=s.length,l=0;f>l;)u=s[l++],d&&!p(a,c,u)||(n[u]=c[u]);return n}:Ma;Me({target:"Object",stat:!0,forced:Object.assign!==Da},{assign:Da});var za,Na=yt("match"),Wa=f.TypeError,Ya=function(t){if(function(t){var e;return F(t)&&(void 0!==(e=t[Na])?!!e:"RegExp"==P(t))}(t))throw Wa("The method doesn't accept regular expressions");return t},Ga=yt("match"),Xa=Pt.f,Ba=T("".startsWith),Ua=T("".slice),Va=Math.min,qa=function(t){var e=/./;try{"/./"[t](e)}catch(n){try{return e[Ga]=!1,"/./"[t](e)}catch(t){}}return!1}("startsWith"),Ha=!(qa||(za=Xa(String.prototype,"startsWith"),!za||za.writable));Me({target:"String",proto:!0,forced:!Ha&&!qa},{startsWith:function(t){var e=Je(L(this));Ya(t);var n=de(Va(arguments.length>1?arguments[1]:void 0,e.length)),r=Je(t);return Ba?Ba(e,r,n):Ua(e,n,n+r.length)===r}});var Ja=/"/g,Ka=T("".replace);function $a(t){if(!t.doc)throw new Error("shared type isn't attached to a document")}Me({target:"String",proto:!0,forced:function(t){return l((function(){var e=""[t]('"');return e!==e.toLowerCase()||e.split('"').length>3}))}("anchor")},{anchor:function(t){return e="a",n="name",r=t,o=Je(L(this)),i="<"+e,""!==n&&(i+=" "+n+'="'+Ka(Je(r),Ja,"&quot;")+'"'),i+">"+o+"</"+e+">";var e,n,r,o,i}});var Qa="__slateYjsStoredPosition_";function Za(t,e,n){var r=Pa(t,e,n.path),i=r.yTarget,a=r.yParent,u=r.textRange;if(i)throw new Error("Slate point points to a non-text element inside sharedRoot");var c=u.start+n.offset;return o.createRelativePositionFromTypeIndex(a,c,c===u.end?-1:0)}function tu(t,n,r){if(!t.doc)throw new Error("sharedRoot isn't attach to a yDoc");var i=o.createAbsolutePositionFromRelativePosition(r,t.doc);return i&&function(t,n,r){var i=r.type,a=r.index,u=r.assoc;if(!(i instanceof o.XmlText))throw new Error("Absolute position points to a non-XMLText");var c=Aa(t,n,i),s=e.Node.get(n,c);if(e.Text.isText(s))throw new Error("Absolute position doesn't match slateRoot, cannot descent into text");var f=Ci(Ra(s,a,{assoc:u}),2),l=f[0],d=f[1],h=s.children[l];return e.Text.isText(h)?{path:Li(Li([],Ci(c)),[l]),offset:d}:null}(t,n,i)}function eu(t,e,n){t.setAttribute(Qa+e,o.encodeRelativePosition(n))}function nu(t,e,n){return Object.fromEntries(Object.entries(t).filter((function(t){var r=Ci(t,2)[1];return r.type===e&&(!n||(r.assoc>=0?r.index>=n.start&&r.index<n.end:r.index>n.start&&r.index>=n.end))})))}function ru(t,e,n){var r;void 0===n&&(n="");var i=((r={})[n]=nu(t,e),r);return fa(e).forEach((function(e,r){var a=e.insert;a instanceof o.XmlText&&Object.assign(i,ru(t,a,n?n+"."+r:r.toString()))})),i}function ou(t,e,n,r){void 0===r&&(r=0);var i=function(t){return $a(t),Object.fromEntries(Object.entries(t.getAttributes()).filter((function(t){return Ci(t,1)[0].startsWith(Qa)})).map((function(e){var n=Ci(e,2),r=n[0],i=n[1];return[r.slice(Qa.length),o.createAbsolutePositionFromRelativePosition(o.decodeRelativePosition(i),t.doc)]})).filter((function(t){return Ci(t,2)[1]})))}(t),a={"":nu(i,e,{start:r,end:r+da(n)})};return n.forEach((function(t,e){var n=t.insert;n instanceof o.XmlText&&Object.assign(a,ru(i,n,e.toString()))})),a}function iu(t,e,n,r,i,a,u){void 0===i&&(i=0),void 0===a&&(a=0),void 0===u&&(u="");var c=n[u];c&&Object.entries(c).forEach((function(n){var r=Ci(n,2),u=r[0],c=r[1];eu(t,u,o.createRelativePositionFromTypeIndex(e,c.index-a+i,c.assoc))})),r.forEach((function(e,r){var i=e.insert;i instanceof o.XmlText&&iu(t,i,n,fa(i),0,0,u?u+"."+r:r.toString())}))}function au(t,e,n){return{anchor:Za(t,e,n.anchor),focus:Za(t,e,n.focus)}}function uu(t,e,n){var r=tu(t,e,n.anchor);if(!r)return null;var o=tu(t,e,n.focus);return o?{anchor:r,focus:o}:null}var cu={insert_node:function(t,n,r){var o=Pa(t,n,r.path),i=o.yParent,a=o.textRange;if(e.Text.isText(r.node))return i.insert(a.start,r.node.text,pa(r.node));i.insertEmbed(a.start,ba(r.node))},remove_node:function(t,e,n){var r=Pa(t,e,n.path),o=r.yParent,i=r.textRange;o.delete(i.start,i.end-i.start)},set_node:function(t,e,n){var r=Pa(t,e,n.path),o=r.yTarget,i=r.textRange,a=r.yParent;if(o)return Object.entries(n.newProperties).forEach((function(t){var e=Ci(t,2),n=e[0],r=e[1];if(null===r)return o.removeAttribute(n);o.setAttribute(n,r)})),Object.entries(n.properties).forEach((function(t){var e=Ci(t,1)[0];Object.prototype.hasOwnProperty.call(n.newProperties,e)||o.removeAttribute(e)}));var u=Object.fromEntries(Object.keys(n.properties).map((function(t){return[t,null]}))),c=Ri(Ri({},u),n.newProperties);a.format(i.start,i.end-i.start,c)},merge_node:function(t,n,r){var o=Pa(t,n,r.path),i=Pa(o.yParent,o.slateParent,e.Path.previous(r.path.slice(-1)));if(!o.yTarget!=!i.yTarget)throw new Error("Cannot merge y text with y element");if(!i.yTarget||!o.yTarget){var a=o.yParent,u=o.textRange,c=o.slateTarget;if(!c)throw new Error("Expected Slate target node for merge op.");var s=e.Node.get(n,e.Path.previous(r.path));if(!e.Text.isText(s))throw new Error("Path points to Y.Text but not a Slate text node.");var f=pa(c),l=pa(s),d=Object.keys(f).reduce((function(t,e){var n;return e in l?t:Ri(Ri({},t),((n={})[e]=null,n))}),{});return a.format(u.start,u.end-u.start,Ri(Ri({},d),l))}var h=i.yTarget.length,p=fa(o.yTarget),v=La(p),g=ou(t,o.yTarget,p,h),y=Li([{retain:h}],Ci(v));i.yTarget.applyDelta(y,{sanitize:!1}),o.yParent.delete(o.textRange.start,o.textRange.end-o.textRange.start),iu(t,i.yTarget,g,v,h)},move_node:function(t,n,r){var o=e.Path.parent(r.newPath),i=r.newPath[r.newPath.length-1],a=e.Node.get(n,o);if(e.Text.isText(a))throw new Error("Cannot move slate node into text element");var u=Li(Li([],Ci(o)),[Math.min(i,a.children.length)]),c=Pa(t,n,r.path),s=Pa(t,n,u),f=La(c.targetDelta),l=ou(t,c.yParent,c.targetDelta);c.yParent.delete(c.textRange.start,c.textRange.end-c.textRange.start);var d=da(fa(s.yParent)),h=Math.min(s.textRange.start,d),p=Li([{retain:h}],Ci(f));s.yParent.applyDelta(p,{sanitize:!1}),iu(t,s.yParent,l,f,h,c.textRange.start)},split_node:function(t,n,r){var i=Pa(t,n,r.path);if(!i.slateTarget)throw new Error("Y target without corresponding slate node");if(!i.yTarget){if(!e.Text.isText(i.slateTarget))throw new Error("Mismatch node type between y target and slate node");var a={};return i.targetDelta.forEach((function(t){t.attributes&&Object.keys(t.attributes).forEach((function(t){a[t]=null}))})),i.yParent.format(i.textRange.start,i.textRange.end-i.textRange.start,Ri(Ri({},a),r.properties))}if(e.Text.isText(i.slateTarget))throw new Error("Mismatch node type between y target and slate node");var u=Pa(i.yTarget,i.slateTarget,[r.position]),c=i.slateTarget.children.slice(0,r.position).reduce((function(t,e){return t+ja(e)}),0),s=i.slateTarget.children.reduce((function(t,e){return t+ja(e)}),0),f=ha(fa(i.yTarget),c,s-c),l=La(f),d=ou(t,i.yTarget,f,c),h=new o.XmlText;h.applyDelta(l,{sanitize:!1}),Object.entries(r.properties).forEach((function(t){var e=Ci(t,2),n=e[0],r=e[1];h.setAttribute(n,r)})),i.yTarget.delete(u.textRange.start,i.yTarget.length-u.textRange.start),i.yParent.insertEmbed(i.textRange.end,h),iu(t,h,d,l,0,c)}};var su=Ri(Ri(Ri({},{insert_text:function(t,n,r){var o=Pa(t,n,r.path),i=o.yParent,a=o.textRange,u=e.Node.get(n,r.path);if(!e.Text.isText(u))throw new Error("Cannot insert text into non-text node");i.insert(a.start+r.offset,r.text,pa(u))},remove_text:function(t,e,n){var r=Pa(t,e,n.path),o=r.yParent,i=r.textRange;o.delete(i.start+n.offset,n.text.length)}}),cu),{set_selection:function(){}});var fu=Symbol("slate-yjs-operation"),lu=Symbol("slate-yjs-position-storage"),du=new WeakMap,hu=new WeakMap,pu=new WeakSet,vu={isYjsEditor:function(t){return e.Editor.isEditor(t)&&t.sharedRoot instanceof o.XmlText&&"localOrigin"in t&&"positionStorageOrigin"in t&&"function"==typeof t.applyRemoteEvents&&"function"==typeof t.storeLocalChange&&"function"==typeof t.flushLocalChanges&&"function"==typeof t.isLocalOrigin&&"function"==typeof t.connect&&"function"==typeof t.disconnect},localChanges:function(t){var e;return null!==(e=hu.get(t))&&void 0!==e?e:[]},applyRemoteEvents:function(t,e,n){t.applyRemoteEvents(e,n)},storeLocalChange:function(t,e){t.storeLocalChange(e)},flushLocalChanges:function(t){t.flushLocalChanges()},connected:function(t){return pu.has(t)},connect:function(t){t.connect()},disconnect:function(t){t.disconnect()},isLocal:function(t){return t.isLocalOrigin(vu.origin(t))},origin:function(t){var e=du.get(t);return void 0!==e?e:t.localOrigin},withOrigin:function(t,e,n){var r=vu.origin(t);du.set(t,e),n(),du.set(t,r)},storePosition:function(t,e,n){var r=t.sharedRoot,o=t.positionStorageOrigin;$a(r);var i=Za(r,t,n);r.doc.transact((function(){eu(r,e,i)}),o)},removeStoredPosition:function(t,e){var n=t.sharedRoot,r=t.positionStorageOrigin;$a(n),n.doc.transact((function(){!function(t,e){t.removeAttribute(Qa+e)}(n,e)}),r)},position:function(t,e){var n=function(t,e){var n=t.getAttribute(Qa+e);return n?o.decodeRelativePosition(n):null}(t.sharedRoot,e);if(n)return tu(t.sharedRoot,t,n)},storedPositionsRelative:function(t){return e=t.sharedRoot,Object.fromEntries(Object.entries(e.getAttributes()).filter((function(t){return Ci(t,1)[0].startsWith(Qa)})).map((function(t){var e=Ci(t,2),n=e[0],r=e[1];return[n.slice(Qa.length),o.createRelativePositionFromJSON(r)]})));var e}};var gu=yt("species"),yu=_t.f,bu=Eo.fastKey,mu=Zt.set,wu=Zt.getterFor,xu={getConstructor:function(t,e,n,r){var o=t((function(t,o){No(t,i),mu(t,{type:e,index:un(null),first:void 0,last:void 0,size:0}),d||(t.size=0),null!=o&&Do(o,t[r],{that:t,AS_ENTRIES:n})})),i=o.prototype,a=wu(e),u=function(t,e,n){var r,o,i=a(t),u=c(t,e);return u?u.value=n:(i.last=u={index:o=bu(e,!0),key:e,value:n,previous:r=i.last,next:void 0,removed:!1},i.first||(i.first=u),r&&(r.next=u),d?i.size++:t.size++,"F"!==o&&(i.index[o]=u)),t},c=function(t,e){var n,r=a(t),o=bu(e);if("F"!==o)return r.index[o];for(n=r.first;n;n=n.next)if(n.key==e)return n};return wo(i,{clear:function(){for(var t=a(this),e=t.index,n=t.first;n;)n.removed=!0,n.previous&&(n.previous=n.previous.next=void 0),delete e[n.index],n=n.next;t.first=t.last=void 0,d?t.size=0:this.size=0},delete:function(t){var e=this,n=a(e),r=c(e,t);if(r){var o=r.next,i=r.previous;delete n.index[r.index],r.removed=!0,i&&(i.next=o),o&&(o.previous=i),n.first==r&&(n.first=o),n.last==r&&(n.last=i),d?n.size--:e.size--}return!!r},forEach:function(t){for(var e,n=a(this),r=Sn(t,arguments.length>1?arguments[1]:void 0);e=e?e.next:n.first;)for(r(e.value,e.key,this);e&&e.removed;)e=e.previous},has:function(t){return!!c(this,t)}}),wo(i,n?{get:function(t){var e=c(this,t);return e&&e.value},set:function(t,e){return u(this,0===t?0:t,e)}}:{add:function(t){return u(this,t=0===t?0:t,t)}}),d&&yu(i,"size",{get:function(){return a(this).size}}),o},setStrong:function(t,e,n){var r=e+" Iterator",o=wu(e),i=wu(r);io(t,e,(function(t,e){mu(this,{type:r,target:t,state:o(t),kind:e,last:void 0})}),(function(){for(var t=i(this),e=t.kind,n=t.last;n&&n.removed;)n=n.previous;return t.target&&(t.last=n=n?n.next:t.state.first)?"keys"==e?{value:n.key,done:!1}:"values"==e?{value:n.value,done:!1}:{value:[n.key,n.value],done:!1}:(t.target=void 0,{value:void 0,done:!0})}),n?"entries":"values",!n,!0),function(t){var e=I(t),n=_t.f;d&&e&&!e[gu]&&n(e,gu,{configurable:!0,get:function(){return this}})}(e)}};Uo("Set",(function(t){return function(){return t(this,arguments.length?arguments[0]:void 0)}}),xu);var Ou=new WeakMap,Su=Symbol("slate-yjs-history-without-saving"),Tu={isYHistoryEditor:function(t){return vu.isYjsEditor(t)&&t.undoManager instanceof o.UndoManager&&"function"==typeof t.undo&&"function"==typeof t.redo&&"withoutSavingOrigin"in t},canUndo:function(t){return t.undoManager.undoStack.length>0},canRedo:function(t){return t.undoManager.redoStack.length>0},isSaving:function(t){return t.undoManager.trackedOrigins.has(vu.origin(t))},withoutSaving:function(t,e){vu.withOrigin(t,t.withoutSavingOrigin,e)}};var Eu=new WeakMap,ju={isCursorEditor:function(t){return vu.isYjsEditor(t)&&t.awareness&&"string"==typeof t.cursorDataField&&"string"==typeof t.selectionStateField&&"function"==typeof t.sendCursorPosition&&"function"==typeof t.sendCursorData},sendCursorPosition:function(t,e){void 0===e&&(e=t.selection),t.sendCursorPosition(e)},sendCursorData:function(t,e){t.sendCursorData(e)},on:function(t,e,n){var r;if("change"===e){var o=null!==(r=Eu.get(t))&&void 0!==r?r:new Set;o.add(n),t&&Eu.set(t,o)}},off:function(t,e,n){if("change"===e){var r=Eu.get(t);r&&r.delete(n)}},cursorState:function(t,e){var n;if(e===t.awareness.clientID||!vu.connected(t))return null;var r=t.awareness.getStates().get(e);return r?{relativeSelection:null!==(n=r[t.selectionStateField])&&void 0!==n?n:null,data:r[t.cursorDataField],clientId:e}:null},cursorStates:function(t){return vu.connected(t)?Object.fromEntries(Array.from(t.awareness.getStates().entries(),(function(e){var n=Ci(e,2),r=n[0],o=n[1];return r!==t.awareness.clientID&&o?[r,{relativeSelection:o[t.selectionStateField],data:o[t.cursorDataField]}]:null})).filter(Array.isArray)):{}}};t.CursorEditor=ju,t.YHistoryEditor=Tu,t.YjsEditor=vu,t.relativePositionToSlatePoint=tu,t.relativeRangeToSlateRange=uu,t.slateNodesToInsertDelta=ya,t.slatePointToRelativePosition=Za,t.slateRangeToRelativeRange=au,t.withCursors=function(t,e){return void 0===e&&(e={}),function(n){var r=e.cursorStateField,i=void 0===r?"selection":r,a=e.cursorDataField,u=void 0===a?"data":a,c=e.autoSend,s=void 0===c||c,f=e.data,l=n;l.awareness=t,l.cursorDataField=u,l.selectionStateField=i,l.sendCursorData=function(t){l.awareness.setLocalStateField(l.cursorDataField,t)},l.sendCursorPosition=function(t){var e=l.awareness.getLocalState(),n=null==e?void 0:e[i];if(t){var r=au(l.sharedRoot,l,t),a=r.anchor,u=r.focus;n&&o.compareRelativePositions(a,n)&&o.compareRelativePositions(u,n)||l.awareness.setLocalStateField(l.selectionStateField,{anchor:a,focus:u})}else n&&l.awareness.setLocalStateField(l.selectionStateField,null)};var d=function(t){var e=Eu.get(l);if(e){var n=l.awareness.clientID,r={added:t.added.filter((function(t){return t!==n})),removed:t.removed.filter((function(t){return t!==n})),updated:t.updated.filter((function(t){return t!==n}))};(r.added.length>0||r.removed.length>0||r.updated.length>0)&&e.forEach((function(t){return t(r)}))}},h=l.connect,p=l.disconnect;return l.connect=function(){if(h(),l.awareness.on("change",d),d({removed:[],added:Array.from(l.awareness.getStates().keys()),updated:[]}),s){f&&ju.sendCursorData(l,f);var t=l.onChange;l.onChange=function(){t(),vu.connected(l)&&ju.sendCursorPosition(l)}}},l.disconnect=function(){l.awareness.off("change",d),d({removed:Array.from(l.awareness.getStates().keys()),added:[],updated:[]}),p()},l}},t.withYHistory=function(t){return void 0===t&&(t={}),function(n){var r=n,i=t.withoutSavingOrigin,a=void 0===i?Su:i,u=t.trackedOrigins,c=void 0===u?new Set([r.localOrigin]):u,s=Ai(t,["withoutSavingOrigin","trackedOrigins"]),f=new o.UndoManager(r.sharedRoot,Ri({trackedOrigins:c},s));r.undoManager=f,r.withoutSavingOrigin=a;var l=r.onChange,d=r.isLocalOrigin;r.onChange=function(){l(),Ou.set(r,r.selection&&au(r.sharedRoot,r,r.selection))},r.isLocalOrigin=function(t){return t===r.withoutSavingOrigin||d(t)};var h=function(t){var e=t.stackItem;e.meta.set("selection",r.selection&&au(r.sharedRoot,r,r.selection)),e.meta.set("selectionBefore",Ou.get(r))},p=function(t){t.stackItem.meta.set("selection",r.selection&&au(r.sharedRoot,r,r.selection))},v=function(t){var n=t.stackItem,o="undo"===t.type?r.undoManager.redoStack:r.undoManager.undoStack,i=o[o.length-1];i&&(i.meta.set("selection",n.meta.get("selectionBefore")),i.meta.set("selectionBefore",n.meta.get("selection")));var a=n.meta.get("selectionBefore");if(a){var u=uu(r.sharedRoot,r,a);u&&e.Transforms.select(r,u)}},g=r.connect,y=r.disconnect;return r.connect=function(){g(),r.undoManager.on("stack-item-added",h),r.undoManager.on("stack-item-popped",v),r.undoManager.on("stack-item-updated",p)},r.disconnect=function(){r.undoManager.off("stack-item-added",h),r.undoManager.off("stack-item-popped",v),r.undoManager.off("stack-item-updated",p),y()},r.undo=function(){vu.connected(r)&&(vu.flushLocalChanges(r),r.undoManager.undo())},r.redo=function(){vu.connected(r)&&(vu.flushLocalChanges(r),r.undoManager.redo())},r}},t.withYjs=function(t,n){return void 0===n&&(n={}),function(r){var o,i,a=r;a.sharedRoot=t,a.localOrigin=null!==(o=n.localOrigin)&&void 0!==o?o:fu,a.positionStorageOrigin=null!==(i=n.positionStorageOrigin)&&void 0!==i?i:lu,a.applyRemoteEvents=function(t,n){vu.flushLocalChanges(a),e.Editor.withoutNormalizing(a,(function(){vu.withOrigin(a,n,(function(){Ca(a.sharedRoot,a,t)}))}))},a.isLocalOrigin=function(t){return t===a.localOrigin};var u=function(t,e){a.isLocalOrigin(e.origin)||vu.applyRemoteEvents(a,t,e.origin)},c=null;n.autoConnect&&(c=setTimeout((function(){c=null,vu.connect(a)}))),a.connect=function(){if(vu.connected(a))throw new Error("already connected");a.sharedRoot.observeDeep(u);var t=va(a.sharedRoot);a.children=t.children,pu.add(a),e.Editor.normalize(r,{force:!0}),r.operations.length||r.onChange()},a.disconnect=function(){c&&clearTimeout(c),vu.flushLocalChanges(a),a.sharedRoot.unobserveDeep(u),pu.delete(a)},a.storeLocalChange=function(t){hu.set(a,Li(Li([],Ci(vu.localChanges(a))),[{op:t,doc:r.children,origin:vu.origin(a)}]))},a.flushLocalChanges=function(){$a(a.sharedRoot);var t=vu.localChanges(a);hu.delete(a);var e=[];t.forEach((function(t){var n=e[e.length-1];if(n&&n[0].origin===t.origin)return n.push(t);e.push([t])})),e.forEach((function(t){$a(a.sharedRoot),a.sharedRoot.doc.transact((function(){t.forEach((function(t){$a(a.sharedRoot),function(t,e,n){var r=su[n.type];if(!r)throw new Error("Unknown operation: "+n.type);r(t,e,n)}(a.sharedRoot,{children:t.doc},t.op)}))}),t[0].origin)}))};var s=a.apply,f=a.onChange;return a.apply=function(t){vu.connected(a)&&vu.isLocal(a)&&vu.storeLocalChange(a,t),s(t)},a.onChange=function(){vu.connected(a)&&vu.flushLocalChanges(a),f()},a}},t.yTextToSlateElement=va,Object.defineProperty(t,"__esModule",{value:!0})}));
2
- //# sourceMappingURL=index.js.map
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('slate'), require('yjs')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'slate', 'yjs'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.WangEditorYjsModule = {}, global.slate, global.Y));
5
+ })(this, (function (exports, slate, Y) { 'use strict';
6
+
7
+ function _interopNamespace(e) {
8
+ if (e && e.__esModule) return e;
9
+ var n = Object.create(null);
10
+ if (e) {
11
+ Object.keys(e).forEach(function (k) {
12
+ if (k !== 'default') {
13
+ var d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: function () { return e[k]; }
17
+ });
18
+ }
19
+ });
20
+ }
21
+ n["default"] = e;
22
+ return Object.freeze(n);
23
+ }
24
+
25
+ var Y__namespace = /*#__PURE__*/_interopNamespace(Y);
26
+
27
+ /******************************************************************************
28
+ Copyright (c) Microsoft Corporation.
29
+
30
+ Permission to use, copy, modify, and/or distribute this software for any
31
+ purpose with or without fee is hereby granted.
32
+
33
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
34
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
35
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
36
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
37
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
38
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
39
+ PERFORMANCE OF THIS SOFTWARE.
40
+ ***************************************************************************** */
41
+
42
+ var __assign = function() {
43
+ __assign = Object.assign || function __assign(t) {
44
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
45
+ s = arguments[i];
46
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
47
+ }
48
+ return t;
49
+ };
50
+ return __assign.apply(this, arguments);
51
+ };
52
+
53
+ function __rest(s, e) {
54
+ var t = {};
55
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
56
+ t[p] = s[p];
57
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
58
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
59
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
60
+ t[p[i]] = s[p[i]];
61
+ }
62
+ return t;
63
+ }
64
+
65
+ function __values(o) {
66
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
67
+ if (m) return m.call(o);
68
+ if (o && typeof o.length === "number") return {
69
+ next: function () {
70
+ if (o && i >= o.length) o = void 0;
71
+ return { value: o && o[i++], done: !o };
72
+ }
73
+ };
74
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
75
+ }
76
+
77
+ function __read(o, n) {
78
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
79
+ if (!m) return o;
80
+ var i = m.call(o), r, ar = [], e;
81
+ try {
82
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
83
+ }
84
+ catch (error) { e = { error: error }; }
85
+ finally {
86
+ try {
87
+ if (r && !r.done && (m = i["return"])) m.call(i);
88
+ }
89
+ finally { if (e) throw e.error; }
90
+ }
91
+ return ar;
92
+ }
93
+
94
+ function __spreadArray(to, from, pack) {
95
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
96
+ if (ar || !(i in from)) {
97
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
98
+ ar[i] = from[i];
99
+ }
100
+ }
101
+ return to.concat(ar || Array.prototype.slice.call(from));
102
+ }
103
+
104
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
105
+ var e = new Error(message);
106
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
107
+ };
108
+
109
+ function isObject(o) {
110
+ return Object.prototype.toString.call(o) === '[object Object]';
111
+ }
112
+ function isPlainObject(o) {
113
+ if (!isObject(o)) {
114
+ return false;
115
+ }
116
+ // If has modified constructor
117
+ var ctor = o.constructor;
118
+ if (ctor === undefined) {
119
+ return true;
120
+ }
121
+ // If has modified prototype
122
+ var prot = ctor.prototype;
123
+ if (isObject(prot) === false) {
124
+ return false;
125
+ }
126
+ // If constructor does not have an Object-specific method
127
+ if (Object.prototype.hasOwnProperty.call(prot, 'isPrototypeOfOf')) {
128
+ return false;
129
+ }
130
+ // Most likely a plain Object
131
+ return true;
132
+ }
133
+ // Slates deep equality function: https://github.com/ianstormtaylor/slate/blob/68aff89e892fe15a16314398ff052ade6068900b/packages/slate/src/utils/deep-equal.ts#L13
134
+ // We have to match slates deepEquals behavior to merge insert deltas in the same way slate does.
135
+ function deepEquals(node, another) {
136
+ // eslint-disable-next-line guard-for-in
137
+ for (var key in node) {
138
+ var a = node[key];
139
+ var b = another[key];
140
+ if (isPlainObject(a) && isPlainObject(b)) {
141
+ if (!deepEquals(a, b)) {
142
+ return false;
143
+ }
144
+ }
145
+ else if (Array.isArray(a) && Array.isArray(b)) {
146
+ if (a.length !== b.length)
147
+ return false;
148
+ for (var i = 0; i < a.length; i++) {
149
+ if (a[i] !== b[i]) {
150
+ return false;
151
+ }
152
+ }
153
+ }
154
+ else if (a !== b) {
155
+ return false;
156
+ }
157
+ }
158
+ for (var key in another) {
159
+ if (node[key] === undefined && another[key] !== undefined) {
160
+ return false;
161
+ }
162
+ }
163
+ return true;
164
+ }
165
+ function pick(obj) {
166
+ var keys = [];
167
+ for (var _i = 1; _i < arguments.length; _i++) {
168
+ keys[_i - 1] = arguments[_i];
169
+ }
170
+ return Object.fromEntries(Object.entries(obj).filter(function (_a) {
171
+ var _b = __read(_a, 1), key = _b[0];
172
+ return keys.includes(key);
173
+ }));
174
+ }
175
+ function omit(obj) {
176
+ var keys = [];
177
+ for (var _i = 1; _i < arguments.length; _i++) {
178
+ keys[_i - 1] = arguments[_i];
179
+ }
180
+ return Object.fromEntries(Object.entries(obj).filter(function (_a) {
181
+ var _b = __read(_a, 1), key = _b[0];
182
+ return !keys.includes(key);
183
+ }));
184
+ }
185
+ function omitNullEntries(obj) {
186
+ return Object.fromEntries(Object.entries(obj).filter(function (_a) {
187
+ var _b = __read(_a, 2), value = _b[1];
188
+ return value !== null;
189
+ }));
190
+ }
191
+
192
+ function normalizeInsertDelta(delta) {
193
+ var e_1, _a;
194
+ var _b, _c;
195
+ var normalized = [];
196
+ try {
197
+ for (var delta_1 = __values(delta), delta_1_1 = delta_1.next(); !delta_1_1.done; delta_1_1 = delta_1.next()) {
198
+ var element = delta_1_1.value;
199
+ if (typeof element.insert === 'string' && element.insert.length === 0) {
200
+ continue;
201
+ }
202
+ var prev = normalized[normalized.length - 1];
203
+ if (!prev || typeof prev.insert !== 'string' || typeof element.insert !== 'string') {
204
+ normalized.push(element);
205
+ continue;
206
+ }
207
+ var merge = prev.attributes === element.attributes ||
208
+ (!prev.attributes === !element.attributes &&
209
+ deepEquals((_b = prev.attributes) !== null && _b !== void 0 ? _b : {}, (_c = element.attributes) !== null && _c !== void 0 ? _c : {}));
210
+ if (merge) {
211
+ prev.insert += element.insert;
212
+ continue;
213
+ }
214
+ normalized.push(element);
215
+ }
216
+ }
217
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
218
+ finally {
219
+ try {
220
+ if (delta_1_1 && !delta_1_1.done && (_a = delta_1.return)) _a.call(delta_1);
221
+ }
222
+ finally { if (e_1) throw e_1.error; }
223
+ }
224
+ return normalized;
225
+ }
226
+ function yTextToInsertDelta(yText) {
227
+ return normalizeInsertDelta(yText.toDelta());
228
+ }
229
+ function getInsertLength(_a) {
230
+ var insert = _a.insert;
231
+ return typeof insert === 'string' ? insert.length : 1;
232
+ }
233
+ function getInsertDeltaLength(delta) {
234
+ return delta.reduce(function (curr, element) { return curr + getInsertLength(element); }, 0);
235
+ }
236
+ function sliceInsertDelta(delta, start, length) {
237
+ if (length < 1) {
238
+ return [];
239
+ }
240
+ var currentOffset = 0;
241
+ var sliced = [];
242
+ var end = start + length;
243
+ for (var i = 0; i < delta.length; i++) {
244
+ if (currentOffset >= end) {
245
+ break;
246
+ }
247
+ var element = delta[i];
248
+ var elementLength = getInsertLength(element);
249
+ if (currentOffset + elementLength <= start) {
250
+ currentOffset += elementLength;
251
+ continue;
252
+ }
253
+ if (typeof element.insert !== 'string') {
254
+ currentOffset += elementLength;
255
+ sliced.push(element);
256
+ continue;
257
+ }
258
+ var startOffset = Math.max(0, start - currentOffset);
259
+ var endOffset = Math.min(elementLength, elementLength - (currentOffset + elementLength - end));
260
+ sliced.push(__assign(__assign({}, element), { insert: element.insert.slice(startOffset, endOffset) }));
261
+ currentOffset += elementLength;
262
+ }
263
+ return sliced;
264
+ }
265
+
266
+ function getProperties(node) {
267
+ return omit(node, (slate.Text.isText(node) ? 'text' : 'children'));
268
+ }
269
+
270
+ function yTextToSlateElement(yText) {
271
+ var delta = yTextToInsertDelta(yText);
272
+ var children = delta.length > 0 ? delta.map(deltaInsertToSlateNode) : [{ text: '' }];
273
+ return __assign(__assign({}, yText.getAttributes()), { children: children });
274
+ }
275
+ function deltaInsertToSlateNode(insert) {
276
+ if (typeof insert.insert === 'string') {
277
+ return __assign(__assign({}, insert.attributes), { text: insert.insert });
278
+ }
279
+ return yTextToSlateElement(insert.insert);
280
+ }
281
+ function slateNodesToInsertDelta(nodes) {
282
+ return nodes.map(function (node) {
283
+ if (slate.Text.isText(node)) {
284
+ return { insert: node.text, attributes: getProperties(node) };
285
+ }
286
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
287
+ return { insert: slateElementToYText(node) };
288
+ });
289
+ }
290
+ function slateElementToYText(_a) {
291
+ var children = _a.children, attributes = __rest(_a, ["children"]);
292
+ var yElement = new Y__namespace.XmlText();
293
+ Object.entries(attributes).forEach(function (_a) {
294
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
295
+ yElement.setAttribute(key, value);
296
+ });
297
+ yElement.applyDelta(slateNodesToInsertDelta(children), { sanitize: false });
298
+ return yElement;
299
+ }
300
+
301
+ function getSlateNodeYLength(node) {
302
+ if (!node) {
303
+ return 0;
304
+ }
305
+ return slate.Text.isText(node) ? node.text.length : 1;
306
+ }
307
+ function slatePathOffsetToYOffset(element, pathOffset) {
308
+ return element.children
309
+ .slice(0, pathOffset)
310
+ .reduce(function (yOffset, node) { return yOffset + getSlateNodeYLength(node); }, 0);
311
+ }
312
+ function getYTarget(yRoot, slateRoot, path) {
313
+ var _a;
314
+ if (path.length === 0) {
315
+ throw new Error('Path has to a have a length >= 1');
316
+ }
317
+ if (slate.Text.isText(slateRoot)) {
318
+ throw new Error('Cannot descent into slate text');
319
+ }
320
+ var _b = __read(path), pathOffset = _b[0], childPath = _b.slice(1);
321
+ var yOffset = slatePathOffsetToYOffset(slateRoot, pathOffset);
322
+ var targetNode = slateRoot.children[pathOffset];
323
+ var delta = yTextToInsertDelta(yRoot);
324
+ var targetLength = getSlateNodeYLength(targetNode);
325
+ var targetDelta = sliceInsertDelta(delta, yOffset, targetLength);
326
+ if (targetDelta.length > 1) {
327
+ throw new Error("Path doesn't match yText, yTarget spans multiple nodes");
328
+ }
329
+ var yTarget = (_a = targetDelta[0]) === null || _a === void 0 ? void 0 : _a.insert;
330
+ if (childPath.length > 0) {
331
+ if (!(yTarget instanceof Y__namespace.XmlText)) {
332
+ throw new Error("Path doesn't match yText, cannot descent into non-yText");
333
+ }
334
+ return getYTarget(yTarget, targetNode, childPath);
335
+ }
336
+ return {
337
+ yParent: yRoot,
338
+ textRange: { start: yOffset, end: yOffset + targetLength },
339
+ yTarget: yTarget instanceof Y__namespace.XmlText ? yTarget : undefined,
340
+ slateParent: slateRoot,
341
+ slateTarget: targetNode,
342
+ targetDelta: targetDelta,
343
+ };
344
+ }
345
+ function yOffsetToSlateOffsets(parent, yOffset, opts) {
346
+ if (opts === void 0) { opts = {}; }
347
+ var _a = opts.assoc, assoc = _a === void 0 ? 0 : _a, _b = opts.insert, insert = _b === void 0 ? false : _b;
348
+ var currentOffset = 0;
349
+ var lastNonEmptyPathOffset = 0;
350
+ for (var pathOffset = 0; pathOffset < parent.children.length; pathOffset++) {
351
+ var child_1 = parent.children[pathOffset];
352
+ var nodeLength = slate.Text.isText(child_1) ? child_1.text.length : 1;
353
+ if (nodeLength > 0) {
354
+ lastNonEmptyPathOffset = pathOffset;
355
+ }
356
+ var endOffset = currentOffset + nodeLength;
357
+ if (nodeLength > 0 && (assoc >= 0 ? endOffset > yOffset : endOffset >= yOffset)) {
358
+ return [pathOffset, yOffset - currentOffset];
359
+ }
360
+ currentOffset += nodeLength;
361
+ }
362
+ if (yOffset > currentOffset + (insert ? 1 : 0)) {
363
+ throw new Error('yOffset out of bounds');
364
+ }
365
+ if (insert) {
366
+ return [parent.children.length, 0];
367
+ }
368
+ var child = parent.children[lastNonEmptyPathOffset];
369
+ var textOffset = slate.Text.isText(child) ? child.text.length : 1;
370
+ return [lastNonEmptyPathOffset, textOffset];
371
+ }
372
+ function getSlatePath(sharedRoot, slateRoot, yText) {
373
+ var yNodePath = [yText];
374
+ while (yNodePath[0] !== sharedRoot) {
375
+ var yParent = yNodePath[0].parent;
376
+ if (!yParent) {
377
+ throw new Error("yText isn't a descendant of root element");
378
+ }
379
+ if (!(yParent instanceof Y__namespace.XmlText)) {
380
+ throw new Error('Unexpected y parent type');
381
+ }
382
+ yNodePath.unshift(yParent);
383
+ }
384
+ if (yNodePath.length < 2) {
385
+ return [];
386
+ }
387
+ var slateParent = slateRoot;
388
+ return yNodePath.reduce(function (path, yParent, idx) {
389
+ var e_1, _a;
390
+ var yChild = yNodePath[idx + 1];
391
+ if (!yChild) {
392
+ return path;
393
+ }
394
+ var yOffset = 0;
395
+ var currentDelta = yTextToInsertDelta(yParent);
396
+ try {
397
+ for (var currentDelta_1 = __values(currentDelta), currentDelta_1_1 = currentDelta_1.next(); !currentDelta_1_1.done; currentDelta_1_1 = currentDelta_1.next()) {
398
+ var element = currentDelta_1_1.value;
399
+ if (element.insert === yChild) {
400
+ break;
401
+ }
402
+ yOffset += typeof element.insert === 'string' ? element.insert.length : 1;
403
+ }
404
+ }
405
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
406
+ finally {
407
+ try {
408
+ if (currentDelta_1_1 && !currentDelta_1_1.done && (_a = currentDelta_1.return)) _a.call(currentDelta_1);
409
+ }
410
+ finally { if (e_1) throw e_1.error; }
411
+ }
412
+ if (slate.Text.isText(slateParent)) {
413
+ throw new Error('Cannot descent into slate text');
414
+ }
415
+ var _b = __read(yOffsetToSlateOffsets(slateParent, yOffset), 1), pathOffset = _b[0];
416
+ slateParent = slateParent.children[pathOffset];
417
+ return path.concat(pathOffset);
418
+ }, []);
419
+ }
420
+
421
+ function applyDelta(node, slatePath, delta) {
422
+ var ops = [];
423
+ var yOffset = delta.reduce(function (length, change) {
424
+ if ('retain' in change) {
425
+ return length + change.retain;
426
+ }
427
+ if ('delete' in change) {
428
+ return length + change.delete;
429
+ }
430
+ return length;
431
+ }, 0);
432
+ // Apply changes in reverse order to avoid path changes.
433
+ delta.reverse().forEach(function (change) {
434
+ var _a;
435
+ if ('attributes' in change && 'retain' in change) {
436
+ var _b = __read(yOffsetToSlateOffsets(node, yOffset - change.retain), 2), startPathOffset = _b[0], startTextOffset = _b[1];
437
+ var _c = __read(yOffsetToSlateOffsets(node, yOffset, { assoc: -1 }), 2), endPathOffset = _c[0], endTextOffset = _c[1];
438
+ for (var pathOffset = endPathOffset; pathOffset >= startPathOffset; pathOffset--) {
439
+ var child = node.children[pathOffset];
440
+ var childPath = __spreadArray(__spreadArray([], __read(slatePath)), [pathOffset]);
441
+ if (!slate.Text.isText(child)) {
442
+ // Ignore attribute updates on non-text nodes (which are backed by Y.XmlText)
443
+ // to be consistent with deltaInsertToSlateNode. Y.XmlText attributes don't show
444
+ // up in deltas but in key changes (YEvent.changes.keys).
445
+ continue;
446
+ }
447
+ var newProperties = change.attributes;
448
+ var properties = pick.apply(void 0, __spreadArray([node], __read(Object.keys(change.attributes))));
449
+ if (pathOffset === startPathOffset || pathOffset === endPathOffset) {
450
+ var start = pathOffset === startPathOffset ? startTextOffset : 0;
451
+ var end = pathOffset === endPathOffset ? endTextOffset : child.text.length;
452
+ if (end !== child.text.length) {
453
+ ops.push({
454
+ type: 'split_node',
455
+ path: childPath,
456
+ position: end,
457
+ properties: getProperties(child),
458
+ });
459
+ }
460
+ if (start !== 0) {
461
+ ops.push({
462
+ type: 'split_node',
463
+ path: childPath,
464
+ position: start,
465
+ properties: omitNullEntries(__assign(__assign({}, getProperties(child)), newProperties)),
466
+ });
467
+ continue;
468
+ }
469
+ }
470
+ ops.push({
471
+ type: 'set_node',
472
+ newProperties: newProperties,
473
+ path: childPath,
474
+ properties: properties,
475
+ });
476
+ }
477
+ }
478
+ if ('retain' in change) {
479
+ yOffset -= change.retain;
480
+ }
481
+ if ('delete' in change) {
482
+ var _d = __read(yOffsetToSlateOffsets(node, yOffset - change.delete), 2), startPathOffset = _d[0], startTextOffset = _d[1];
483
+ var _e = __read(yOffsetToSlateOffsets(node, yOffset, { assoc: -1 }), 2), endPathOffset = _e[0], endTextOffset = _e[1];
484
+ for (var pathOffset = endTextOffset === 0 ? endPathOffset - 1 : endPathOffset; pathOffset >= startPathOffset; pathOffset--) {
485
+ var child = node.children[pathOffset];
486
+ var childPath = __spreadArray(__spreadArray([], __read(slatePath)), [pathOffset]);
487
+ if (slate.Text.isText(child) &&
488
+ (pathOffset === startPathOffset || pathOffset === endPathOffset)) {
489
+ var start = pathOffset === startPathOffset ? startTextOffset : 0;
490
+ var end = pathOffset === endPathOffset ? endTextOffset : child.text.length;
491
+ ops.push({
492
+ type: 'remove_text',
493
+ offset: start,
494
+ text: child.text.slice(start, end),
495
+ path: childPath,
496
+ });
497
+ yOffset -= end - start;
498
+ continue;
499
+ }
500
+ ops.push({
501
+ type: 'remove_node',
502
+ node: child,
503
+ path: childPath,
504
+ });
505
+ yOffset -= getSlateNodeYLength(child);
506
+ }
507
+ return;
508
+ }
509
+ if ('insert' in change) {
510
+ var _f = __read(yOffsetToSlateOffsets(node, yOffset, {
511
+ insert: true,
512
+ }), 2), pathOffset = _f[0], textOffset = _f[1];
513
+ var child = node.children[pathOffset];
514
+ var childPath = __spreadArray(__spreadArray([], __read(slatePath)), [pathOffset]);
515
+ if (slate.Text.isText(child)) {
516
+ var lastOp = ops[ops.length - 1];
517
+ /**
518
+ * The props that exist at the current path
519
+ * Since we're not actually using slate to update the node
520
+ * this is a simulation
521
+ */
522
+ var currentProps = lastOp != null && lastOp.type === 'insert_node' ? lastOp.node : getProperties(child);
523
+ var lastPath = [];
524
+ if (lastOp != null &&
525
+ (lastOp.type === 'insert_node' ||
526
+ lastOp.type === 'insert_text' ||
527
+ lastOp.type === 'split_node' ||
528
+ lastOp.type === 'set_node')) {
529
+ lastPath = lastOp.path;
530
+ }
531
+ /**
532
+ * If the insert is a string and the attributes are the same as the
533
+ * props at the current path, we can just insert a text node
534
+ */
535
+ if (typeof change.insert === 'string' &&
536
+ deepEquals((_a = change.attributes) !== null && _a !== void 0 ? _a : {}, currentProps) &&
537
+ slate.Path.equals(childPath, lastPath)) {
538
+ return ops.push({
539
+ type: 'insert_text',
540
+ offset: textOffset,
541
+ text: change.insert,
542
+ path: childPath,
543
+ });
544
+ }
545
+ var toInsert = deltaInsertToSlateNode(change);
546
+ if (textOffset === 0) {
547
+ return ops.push({
548
+ type: 'insert_node',
549
+ path: childPath,
550
+ node: toInsert,
551
+ });
552
+ }
553
+ if (textOffset < child.text.length) {
554
+ ops.push({
555
+ type: 'split_node',
556
+ path: childPath,
557
+ position: textOffset,
558
+ properties: getProperties(child),
559
+ });
560
+ }
561
+ return ops.push({
562
+ type: 'insert_node',
563
+ path: slate.Path.next(childPath),
564
+ node: toInsert,
565
+ });
566
+ }
567
+ return ops.push({
568
+ type: 'insert_node',
569
+ path: childPath,
570
+ node: deltaInsertToSlateNode(change),
571
+ });
572
+ }
573
+ });
574
+ return ops;
575
+ }
576
+ function translateYTextEvent(sharedRoot, editor, event) {
577
+ var target = event.target, changes = event.changes;
578
+ var delta = event.delta;
579
+ if (!(target instanceof Y__namespace.XmlText)) {
580
+ throw new Error('Unexpected target node type');
581
+ }
582
+ var ops = [];
583
+ var slatePath = getSlatePath(sharedRoot, editor, target);
584
+ var targetElement = slate.Node.get(editor, slatePath);
585
+ if (slate.Text.isText(targetElement)) {
586
+ throw new Error('Cannot apply yTextEvent to text node');
587
+ }
588
+ var keyChanges = Array.from(changes.keys.entries());
589
+ if (slatePath.length > 0 && keyChanges.length > 0) {
590
+ var newProperties = Object.fromEntries(keyChanges.map(function (_a) {
591
+ var _b = __read(_a, 2), key = _b[0], info = _b[1];
592
+ return [
593
+ key,
594
+ info.action === 'delete' ? null : target.getAttribute(key),
595
+ ];
596
+ }));
597
+ var properties = Object.fromEntries(keyChanges.map(function (_a) {
598
+ var _b = __read(_a, 1), key = _b[0];
599
+ return [key, targetElement[key]];
600
+ }));
601
+ ops.push({ type: 'set_node', newProperties: newProperties, properties: properties, path: slatePath });
602
+ }
603
+ if (delta.length > 0) {
604
+ ops.push.apply(ops, __spreadArray([], __read(applyDelta(targetElement, slatePath, delta))));
605
+ }
606
+ return ops;
607
+ }
608
+
609
+ /**
610
+ * Translate a yjs event into slate operations. The editor state has to match the
611
+ * yText state before the event occurred.
612
+ *
613
+ * @param sharedType
614
+ * @param op
615
+ */
616
+ function translateYjsEvent(sharedRoot, editor, event) {
617
+ if (event instanceof Y__namespace.YTextEvent) {
618
+ return translateYTextEvent(sharedRoot, editor, event);
619
+ }
620
+ throw new Error('Unexpected Y event type');
621
+ }
622
+ /**
623
+ * Translates yjs events into slate operations and applies them to the editor. The
624
+ * editor state has to match the yText state before the events occurred.
625
+ *
626
+ * @param sharedRoot
627
+ * @param editor
628
+ * @param events
629
+ */
630
+ function applyYjsEvents(sharedRoot, editor, events) {
631
+ slate.Editor.withoutNormalizing(editor, function () {
632
+ events.forEach(function (event) {
633
+ translateYjsEvent(sharedRoot, editor, event).forEach(function (op) {
634
+ editor.apply(op);
635
+ });
636
+ });
637
+ });
638
+ }
639
+
640
+ function insertNode(sharedRoot, slateRoot, op) {
641
+ var _a = getYTarget(sharedRoot, slateRoot, op.path), yParent = _a.yParent, textRange = _a.textRange;
642
+ if (slate.Text.isText(op.node)) {
643
+ return yParent.insert(textRange.start, op.node.text, getProperties(op.node));
644
+ }
645
+ yParent.insertEmbed(textRange.start, slateElementToYText(op.node));
646
+ }
647
+
648
+ function cloneInsertDeltaDeep(delta) {
649
+ return delta.map(function (element) {
650
+ if (typeof element.insert === 'string') {
651
+ return element;
652
+ }
653
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
654
+ return __assign(__assign({}, element), { insert: cloneDeep(element.insert) });
655
+ });
656
+ }
657
+ function cloneDeep(yText) {
658
+ var clone = new Y__namespace.XmlText();
659
+ var attributes = yText.getAttributes();
660
+ Object.entries(attributes).forEach(function (_a) {
661
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
662
+ clone.setAttribute(key, value);
663
+ });
664
+ clone.applyDelta(cloneInsertDeltaDeep(yTextToInsertDelta(yText)), {
665
+ sanitize: false,
666
+ });
667
+ return clone;
668
+ }
669
+
670
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
671
+ function assertDocumentAttachment(sharedType) {
672
+ if (!sharedType.doc) {
673
+ throw new Error("shared type isn't attached to a document");
674
+ }
675
+ }
676
+
677
+ var STORED_POSITION_PREFIX = '__slateYjsStoredPosition_';
678
+ function slatePointToRelativePosition(sharedRoot, slateRoot, point) {
679
+ var _a = getYTarget(sharedRoot, slateRoot, point.path), yTarget = _a.yTarget, yParent = _a.yParent, textRange = _a.textRange;
680
+ if (yTarget) {
681
+ throw new Error('Slate point points to a non-text element inside sharedRoot');
682
+ }
683
+ var index = textRange.start + point.offset;
684
+ return Y__namespace.createRelativePositionFromTypeIndex(yParent, index, index === textRange.end ? -1 : 0);
685
+ }
686
+ function absolutePositionToSlatePoint(sharedRoot, slateRoot, _a) {
687
+ var type = _a.type, index = _a.index, assoc = _a.assoc;
688
+ if (!(type instanceof Y__namespace.XmlText)) {
689
+ throw new Error('Absolute position points to a non-XMLText');
690
+ }
691
+ var parentPath = getSlatePath(sharedRoot, slateRoot, type);
692
+ var parent = slate.Node.get(slateRoot, parentPath);
693
+ if (slate.Text.isText(parent)) {
694
+ throw new Error("Absolute position doesn't match slateRoot, cannot descent into text");
695
+ }
696
+ var _b = __read(yOffsetToSlateOffsets(parent, index, {
697
+ assoc: assoc,
698
+ }), 2), pathOffset = _b[0], textOffset = _b[1];
699
+ var target = parent.children[pathOffset];
700
+ if (!slate.Text.isText(target)) {
701
+ return null;
702
+ }
703
+ return { path: __spreadArray(__spreadArray([], __read(parentPath)), [pathOffset]), offset: textOffset };
704
+ }
705
+ function relativePositionToSlatePoint(sharedRoot, slateRoot, pos) {
706
+ if (!sharedRoot.doc) {
707
+ throw new Error("sharedRoot isn't attach to a yDoc");
708
+ }
709
+ var absPos = Y__namespace.createAbsolutePositionFromRelativePosition(pos, sharedRoot.doc);
710
+ return absPos && absolutePositionToSlatePoint(sharedRoot, slateRoot, absPos);
711
+ }
712
+ function getStoredPosition(sharedRoot, key) {
713
+ var rawPosition = sharedRoot.getAttribute(STORED_POSITION_PREFIX + key);
714
+ if (!rawPosition) {
715
+ return null;
716
+ }
717
+ return Y__namespace.decodeRelativePosition(rawPosition);
718
+ }
719
+ function getStoredPositions(sharedRoot) {
720
+ return Object.fromEntries(Object.entries(sharedRoot.getAttributes())
721
+ .filter(function (_a) {
722
+ var _b = __read(_a, 1), key = _b[0];
723
+ return key.startsWith(STORED_POSITION_PREFIX);
724
+ })
725
+ .map(function (_a) {
726
+ var _b = __read(_a, 2), key = _b[0], position = _b[1];
727
+ return [
728
+ key.slice(STORED_POSITION_PREFIX.length),
729
+ Y__namespace.createRelativePositionFromJSON(position),
730
+ ];
731
+ }));
732
+ }
733
+ function getStoredPositionsAbsolute(sharedRoot) {
734
+ assertDocumentAttachment(sharedRoot);
735
+ return Object.fromEntries(Object.entries(sharedRoot.getAttributes())
736
+ .filter(function (_a) {
737
+ var _b = __read(_a, 1), key = _b[0];
738
+ return key.startsWith(STORED_POSITION_PREFIX);
739
+ })
740
+ .map(function (_a) {
741
+ var _b = __read(_a, 2), key = _b[0], position = _b[1];
742
+ return [
743
+ key.slice(STORED_POSITION_PREFIX.length),
744
+ Y__namespace.createAbsolutePositionFromRelativePosition(Y__namespace.decodeRelativePosition(position), sharedRoot.doc),
745
+ ];
746
+ })
747
+ .filter(function (_a) {
748
+ var _b = __read(_a, 2), position = _b[1];
749
+ return position;
750
+ }));
751
+ }
752
+ function removeStoredPosition(sharedRoot, key) {
753
+ sharedRoot.removeAttribute(STORED_POSITION_PREFIX + key);
754
+ }
755
+ function setStoredPosition(sharedRoot, key, position) {
756
+ sharedRoot.setAttribute(STORED_POSITION_PREFIX + key, Y__namespace.encodeRelativePosition(position));
757
+ }
758
+ function getAbsolutePositionsInTextRange(absolutePositions, yTarget, textRange) {
759
+ return Object.fromEntries(Object.entries(absolutePositions).filter(function (_a) {
760
+ var _b = __read(_a, 2), position = _b[1];
761
+ if (position.type !== yTarget) {
762
+ return false;
763
+ }
764
+ if (!textRange) {
765
+ return true;
766
+ }
767
+ return position.assoc >= 0
768
+ ? position.index >= textRange.start && position.index < textRange.end
769
+ : position.index > textRange.start && position.index >= textRange.end;
770
+ }));
771
+ }
772
+ function getAbsolutePositionsInYText(absolutePositions, yText, parentPath) {
773
+ var _a;
774
+ if (parentPath === void 0) { parentPath = ''; }
775
+ var positions = (_a = {},
776
+ _a[parentPath] = getAbsolutePositionsInTextRange(absolutePositions, yText),
777
+ _a);
778
+ var insertDelta = yTextToInsertDelta(yText);
779
+ insertDelta.forEach(function (_a, i) {
780
+ var insert = _a.insert;
781
+ if (insert instanceof Y__namespace.XmlText) {
782
+ Object.assign(positions, getAbsolutePositionsInYText(absolutePositions, insert, parentPath ? parentPath + "." + i : i.toString()));
783
+ }
784
+ });
785
+ return positions;
786
+ }
787
+ function getStoredPositionsInDeltaAbsolute(sharedRoot, yText, delta, deltaOffset) {
788
+ if (deltaOffset === void 0) { deltaOffset = 0; }
789
+ var absolutePositions = getStoredPositionsAbsolute(sharedRoot);
790
+ var positions = {
791
+ '': getAbsolutePositionsInTextRange(absolutePositions, yText, {
792
+ start: deltaOffset,
793
+ end: deltaOffset + getInsertDeltaLength(delta),
794
+ }),
795
+ };
796
+ delta.forEach(function (_a, i) {
797
+ var insert = _a.insert;
798
+ if (insert instanceof Y__namespace.XmlText) {
799
+ Object.assign(positions, getAbsolutePositionsInYText(absolutePositions, insert, i.toString()));
800
+ }
801
+ });
802
+ return positions;
803
+ }
804
+ function restoreStoredPositionsWithDeltaAbsolute(sharedRoot, yText, absolutePositions, delta, newDeltaOffset, previousDeltaOffset, path) {
805
+ if (newDeltaOffset === void 0) { newDeltaOffset = 0; }
806
+ if (previousDeltaOffset === void 0) { previousDeltaOffset = 0; }
807
+ if (path === void 0) { path = ''; }
808
+ var toRestore = absolutePositions[path];
809
+ if (toRestore) {
810
+ Object.entries(toRestore).forEach(function (_a) {
811
+ var _b = __read(_a, 2), key = _b[0], position = _b[1];
812
+ setStoredPosition(sharedRoot, key, Y__namespace.createRelativePositionFromTypeIndex(yText, position.index - previousDeltaOffset + newDeltaOffset, position.assoc));
813
+ });
814
+ }
815
+ delta.forEach(function (_a, i) {
816
+ var insert = _a.insert;
817
+ if (insert instanceof Y__namespace.XmlText) {
818
+ restoreStoredPositionsWithDeltaAbsolute(sharedRoot, insert, absolutePositions, yTextToInsertDelta(insert), 0, 0, path ? path + "." + i : i.toString());
819
+ }
820
+ });
821
+ }
822
+ function slateRangeToRelativeRange(sharedRoot, slateRoot, range) {
823
+ return {
824
+ anchor: slatePointToRelativePosition(sharedRoot, slateRoot, range.anchor),
825
+ focus: slatePointToRelativePosition(sharedRoot, slateRoot, range.focus),
826
+ };
827
+ }
828
+ function relativeRangeToSlateRange(sharedRoot, slateRoot, range) {
829
+ var anchor = relativePositionToSlatePoint(sharedRoot, slateRoot, range.anchor);
830
+ if (!anchor) {
831
+ return null;
832
+ }
833
+ var focus = relativePositionToSlatePoint(sharedRoot, slateRoot, range.focus);
834
+ if (!focus) {
835
+ return null;
836
+ }
837
+ return { anchor: anchor, focus: focus };
838
+ }
839
+
840
+ function mergeNode(sharedRoot, slateRoot, op) {
841
+ var target = getYTarget(sharedRoot, slateRoot, op.path);
842
+ var prev = getYTarget(target.yParent, target.slateParent, slate.Path.previous(op.path.slice(-1)));
843
+ if (!target.yTarget !== !prev.yTarget) {
844
+ throw new Error('Cannot merge y text with y element');
845
+ }
846
+ if (!prev.yTarget || !target.yTarget) {
847
+ var parent_1 = target.yParent, textRange = target.textRange, slateTarget = target.slateTarget;
848
+ if (!slateTarget) {
849
+ throw new Error('Expected Slate target node for merge op.');
850
+ }
851
+ var prevSibling = slate.Node.get(slateRoot, slate.Path.previous(op.path));
852
+ if (!slate.Text.isText(prevSibling)) {
853
+ throw new Error('Path points to Y.Text but not a Slate text node.');
854
+ }
855
+ var targetProps = getProperties(slateTarget);
856
+ var prevSiblingProps_1 = getProperties(prevSibling);
857
+ var unsetProps = Object.keys(targetProps).reduce(function (acc, key) {
858
+ var _a;
859
+ var prevSiblingHasProp = key in prevSiblingProps_1;
860
+ return prevSiblingHasProp ? acc : __assign(__assign({}, acc), (_a = {}, _a[key] = null, _a));
861
+ }, {});
862
+ return parent_1.format(textRange.start, textRange.end - textRange.start, __assign(__assign({}, unsetProps), prevSiblingProps_1));
863
+ }
864
+ var deltaApplyYOffset = prev.yTarget.length;
865
+ var targetDelta = yTextToInsertDelta(target.yTarget);
866
+ var clonedDelta = cloneInsertDeltaDeep(targetDelta);
867
+ var storedPositions = getStoredPositionsInDeltaAbsolute(sharedRoot, target.yTarget, targetDelta, deltaApplyYOffset);
868
+ var applyDelta = __spreadArray([{ retain: deltaApplyYOffset }], __read(clonedDelta));
869
+ prev.yTarget.applyDelta(applyDelta, {
870
+ sanitize: false,
871
+ });
872
+ target.yParent.delete(target.textRange.start, target.textRange.end - target.textRange.start);
873
+ restoreStoredPositionsWithDeltaAbsolute(sharedRoot, prev.yTarget, storedPositions, clonedDelta, deltaApplyYOffset);
874
+ }
875
+
876
+ function moveNode(sharedRoot, slateRoot, op) {
877
+ var newParentPath = slate.Path.parent(op.newPath);
878
+ var newPathOffset = op.newPath[op.newPath.length - 1];
879
+ var parent = slate.Node.get(slateRoot, newParentPath);
880
+ if (slate.Text.isText(parent)) {
881
+ throw new Error('Cannot move slate node into text element');
882
+ }
883
+ var normalizedNewPath = __spreadArray(__spreadArray([], __read(newParentPath)), [Math.min(newPathOffset, parent.children.length)]);
884
+ var origin = getYTarget(sharedRoot, slateRoot, op.path);
885
+ var target = getYTarget(sharedRoot, slateRoot, normalizedNewPath);
886
+ var insertDelta = cloneInsertDeltaDeep(origin.targetDelta);
887
+ var storedPositions = getStoredPositionsInDeltaAbsolute(sharedRoot, origin.yParent, origin.targetDelta);
888
+ origin.yParent.delete(origin.textRange.start, origin.textRange.end - origin.textRange.start);
889
+ var targetLength = getInsertDeltaLength(yTextToInsertDelta(target.yParent));
890
+ var deltaApplyYOffset = Math.min(target.textRange.start, targetLength);
891
+ var applyDelta = __spreadArray([{ retain: deltaApplyYOffset }], __read(insertDelta));
892
+ target.yParent.applyDelta(applyDelta, { sanitize: false });
893
+ restoreStoredPositionsWithDeltaAbsolute(sharedRoot, target.yParent, storedPositions, insertDelta, deltaApplyYOffset, origin.textRange.start);
894
+ }
895
+
896
+ function removeNode(sharedRoot, slateRoot, op) {
897
+ var _a = getYTarget(sharedRoot, slateRoot, op.path), parent = _a.yParent, textRange = _a.textRange;
898
+ parent.delete(textRange.start, textRange.end - textRange.start);
899
+ }
900
+
901
+ function setNode(sharedRoot, slateRoot, op) {
902
+ var _a = getYTarget(sharedRoot, slateRoot, op.path), yTarget = _a.yTarget, textRange = _a.textRange, yParent = _a.yParent;
903
+ if (yTarget) {
904
+ Object.entries(op.newProperties).forEach(function (_a) {
905
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
906
+ if (value === null) {
907
+ return yTarget.removeAttribute(key);
908
+ }
909
+ yTarget.setAttribute(key, value);
910
+ });
911
+ return Object.entries(op.properties).forEach(function (_a) {
912
+ var _b = __read(_a, 1), key = _b[0];
913
+ if (!Object.prototype.hasOwnProperty.call(op.newProperties, key)) {
914
+ yTarget.removeAttribute(key);
915
+ }
916
+ });
917
+ }
918
+ var unset = Object.fromEntries(Object.keys(op.properties).map(function (key) { return [key, null]; }));
919
+ var newProperties = __assign(__assign({}, unset), op.newProperties);
920
+ yParent.format(textRange.start, textRange.end - textRange.start, newProperties);
921
+ }
922
+
923
+ function splitNode(sharedRoot, slateRoot, op) {
924
+ var target = getYTarget(sharedRoot, slateRoot, op.path);
925
+ if (!target.slateTarget) {
926
+ throw new Error('Y target without corresponding slate node');
927
+ }
928
+ if (!target.yTarget) {
929
+ if (!slate.Text.isText(target.slateTarget)) {
930
+ throw new Error('Mismatch node type between y target and slate node');
931
+ }
932
+ var unset_1 = {};
933
+ target.targetDelta.forEach(function (element) {
934
+ if (element.attributes) {
935
+ Object.keys(element.attributes).forEach(function (key) {
936
+ unset_1[key] = null;
937
+ });
938
+ }
939
+ });
940
+ return target.yParent.format(target.textRange.start, target.textRange.end - target.textRange.start, __assign(__assign({}, unset_1), op.properties));
941
+ }
942
+ if (slate.Text.isText(target.slateTarget)) {
943
+ throw new Error('Mismatch node type between y target and slate node');
944
+ }
945
+ var splitTarget = getYTarget(target.yTarget, target.slateTarget, [op.position]);
946
+ var ySplitOffset = target.slateTarget.children
947
+ .slice(0, op.position)
948
+ .reduce(function (length, child) { return length + getSlateNodeYLength(child); }, 0);
949
+ var length = target.slateTarget.children.reduce(function (current, child) { return current + getSlateNodeYLength(child); }, 0);
950
+ var splitDelta = sliceInsertDelta(yTextToInsertDelta(target.yTarget), ySplitOffset, length - ySplitOffset);
951
+ var clonedDelta = cloneInsertDeltaDeep(splitDelta);
952
+ var storedPositions = getStoredPositionsInDeltaAbsolute(sharedRoot, target.yTarget, splitDelta, ySplitOffset);
953
+ var toInsert = new Y__namespace.XmlText();
954
+ toInsert.applyDelta(clonedDelta, {
955
+ sanitize: false,
956
+ });
957
+ Object.entries(op.properties).forEach(function (_a) {
958
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
959
+ toInsert.setAttribute(key, value);
960
+ });
961
+ target.yTarget.delete(splitTarget.textRange.start, target.yTarget.length - splitTarget.textRange.start);
962
+ target.yParent.insertEmbed(target.textRange.end, toInsert);
963
+ restoreStoredPositionsWithDeltaAbsolute(sharedRoot, toInsert, storedPositions, clonedDelta, 0, ySplitOffset);
964
+ }
965
+
966
+ var NODE_MAPPER = {
967
+ insert_node: insertNode,
968
+ remove_node: removeNode,
969
+ set_node: setNode,
970
+ merge_node: mergeNode,
971
+ move_node: moveNode,
972
+ split_node: splitNode,
973
+ };
974
+
975
+ function insertText(sharedRoot, slateRoot, op) {
976
+ var _a = getYTarget(sharedRoot, slateRoot, op.path), target = _a.yParent, textRange = _a.textRange;
977
+ var targetNode = slate.Node.get(slateRoot, op.path);
978
+ if (!slate.Text.isText(targetNode)) {
979
+ throw new Error('Cannot insert text into non-text node');
980
+ }
981
+ target.insert(textRange.start + op.offset, op.text, getProperties(targetNode));
982
+ }
983
+
984
+ function removeText(sharedRoot, slateRoot, op) {
985
+ var _a = getYTarget(sharedRoot, slateRoot, op.path), target = _a.yParent, textRange = _a.textRange;
986
+ target.delete(textRange.start + op.offset, op.text.length);
987
+ }
988
+
989
+ var TEXT_MAPPER = {
990
+ insert_text: insertText,
991
+ remove_text: removeText,
992
+ };
993
+
994
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
995
+ var NOOP = function () { };
996
+ var opMappers = __assign(__assign(__assign({}, TEXT_MAPPER), NODE_MAPPER), { set_selection: NOOP });
997
+ function applySlateOp(sharedRoot, slateRoot, op) {
998
+ var apply = opMappers[op.type];
999
+ if (!apply) {
1000
+ throw new Error("Unknown operation: " + op.type);
1001
+ }
1002
+ apply(sharedRoot, slateRoot, op);
1003
+ }
1004
+
1005
+ var DEFAULT_LOCAL_ORIGIN = Symbol('slate-yjs-operation');
1006
+ var DEFAULT_POSITION_STORAGE_ORIGIN = Symbol('slate-yjs-position-storage');
1007
+ var ORIGIN = new WeakMap();
1008
+ var LOCAL_CHANGES = new WeakMap();
1009
+ var CONNECTED = new WeakSet();
1010
+ var YjsEditor = {
1011
+ isYjsEditor: function (value) {
1012
+ return (slate.Editor.isEditor(value) &&
1013
+ value.sharedRoot instanceof Y__namespace.XmlText &&
1014
+ 'localOrigin' in value &&
1015
+ 'positionStorageOrigin' in value &&
1016
+ typeof value.applyRemoteEvents === 'function' &&
1017
+ typeof value.storeLocalChange === 'function' &&
1018
+ typeof value.flushLocalChanges === 'function' &&
1019
+ typeof value.isLocalOrigin === 'function' &&
1020
+ typeof value.connect === 'function' &&
1021
+ typeof value.disconnect === 'function');
1022
+ },
1023
+ localChanges: function (editor) {
1024
+ var _a;
1025
+ return (_a = LOCAL_CHANGES.get(editor)) !== null && _a !== void 0 ? _a : [];
1026
+ },
1027
+ applyRemoteEvents: function (editor, events, origin) {
1028
+ editor.applyRemoteEvents(events, origin);
1029
+ },
1030
+ storeLocalChange: function (editor, op) {
1031
+ editor.storeLocalChange(op);
1032
+ },
1033
+ flushLocalChanges: function (editor) {
1034
+ editor.flushLocalChanges();
1035
+ },
1036
+ connected: function (editor) {
1037
+ return CONNECTED.has(editor);
1038
+ },
1039
+ connect: function (editor) {
1040
+ editor.connect();
1041
+ },
1042
+ disconnect: function (editor) {
1043
+ editor.disconnect();
1044
+ },
1045
+ isLocal: function (editor) {
1046
+ return editor.isLocalOrigin(YjsEditor.origin(editor));
1047
+ },
1048
+ origin: function (editor) {
1049
+ var origin = ORIGIN.get(editor);
1050
+ return origin !== undefined ? origin : editor.localOrigin;
1051
+ },
1052
+ withOrigin: function (editor, origin, fn) {
1053
+ var prev = YjsEditor.origin(editor);
1054
+ ORIGIN.set(editor, origin);
1055
+ fn();
1056
+ ORIGIN.set(editor, prev);
1057
+ },
1058
+ storePosition: function (editor, key, point) {
1059
+ var sharedRoot = editor.sharedRoot, locationStorageOrigin = editor.positionStorageOrigin;
1060
+ assertDocumentAttachment(sharedRoot);
1061
+ var position = slatePointToRelativePosition(sharedRoot, editor, point);
1062
+ sharedRoot.doc.transact(function () {
1063
+ setStoredPosition(sharedRoot, key, position);
1064
+ }, locationStorageOrigin);
1065
+ },
1066
+ removeStoredPosition: function (editor, key) {
1067
+ var sharedRoot = editor.sharedRoot, locationStorageOrigin = editor.positionStorageOrigin;
1068
+ assertDocumentAttachment(sharedRoot);
1069
+ sharedRoot.doc.transact(function () {
1070
+ removeStoredPosition(sharedRoot, key);
1071
+ }, locationStorageOrigin);
1072
+ },
1073
+ position: function (editor, key) {
1074
+ var position = getStoredPosition(editor.sharedRoot, key);
1075
+ if (!position) {
1076
+ return undefined;
1077
+ }
1078
+ return relativePositionToSlatePoint(editor.sharedRoot, editor, position);
1079
+ },
1080
+ storedPositionsRelative: function (editor) {
1081
+ return getStoredPositions(editor.sharedRoot);
1082
+ },
1083
+ };
1084
+ function withYjs(sharedRoot, options) {
1085
+ if (options === void 0) { options = {}; }
1086
+ return function (editor) {
1087
+ var _a, _b;
1088
+ var e = editor;
1089
+ e.sharedRoot = sharedRoot;
1090
+ e.localOrigin = (_a = options.localOrigin) !== null && _a !== void 0 ? _a : DEFAULT_LOCAL_ORIGIN;
1091
+ e.positionStorageOrigin = (_b = options.positionStorageOrigin) !== null && _b !== void 0 ? _b : DEFAULT_POSITION_STORAGE_ORIGIN;
1092
+ e.applyRemoteEvents = function (events, origin) {
1093
+ YjsEditor.flushLocalChanges(e);
1094
+ slate.Editor.withoutNormalizing(e, function () {
1095
+ YjsEditor.withOrigin(e, origin, function () {
1096
+ applyYjsEvents(e.sharedRoot, e, events);
1097
+ });
1098
+ });
1099
+ };
1100
+ e.isLocalOrigin = function (origin) { return origin === e.localOrigin; };
1101
+ var handleYEvents = function (events, transaction) {
1102
+ if (e.isLocalOrigin(transaction.origin)) {
1103
+ return;
1104
+ }
1105
+ YjsEditor.applyRemoteEvents(e, events, transaction.origin);
1106
+ };
1107
+ var autoConnectTimeoutId = null;
1108
+ if (options.autoConnect) {
1109
+ autoConnectTimeoutId = setTimeout(function () {
1110
+ autoConnectTimeoutId = null;
1111
+ YjsEditor.connect(e);
1112
+ });
1113
+ }
1114
+ e.connect = function () {
1115
+ if (YjsEditor.connected(e)) {
1116
+ throw new Error('already connected');
1117
+ }
1118
+ e.sharedRoot.observeDeep(handleYEvents);
1119
+ var content = yTextToSlateElement(e.sharedRoot);
1120
+ e.children = content.children;
1121
+ CONNECTED.add(e);
1122
+ slate.Editor.normalize(editor, { force: true });
1123
+ if (!editor.operations.length) {
1124
+ editor.onChange();
1125
+ }
1126
+ };
1127
+ e.disconnect = function () {
1128
+ if (autoConnectTimeoutId) {
1129
+ clearTimeout(autoConnectTimeoutId);
1130
+ }
1131
+ YjsEditor.flushLocalChanges(e);
1132
+ e.sharedRoot.unobserveDeep(handleYEvents);
1133
+ CONNECTED.delete(e);
1134
+ };
1135
+ e.storeLocalChange = function (op) {
1136
+ LOCAL_CHANGES.set(e, __spreadArray(__spreadArray([], __read(YjsEditor.localChanges(e))), [
1137
+ { op: op, doc: editor.children, origin: YjsEditor.origin(e) },
1138
+ ]));
1139
+ };
1140
+ e.flushLocalChanges = function () {
1141
+ assertDocumentAttachment(e.sharedRoot);
1142
+ var localChanges = YjsEditor.localChanges(e);
1143
+ LOCAL_CHANGES.delete(e);
1144
+ var txGroups = [];
1145
+ localChanges.forEach(function (change) {
1146
+ var currentGroup = txGroups[txGroups.length - 1];
1147
+ if (currentGroup && currentGroup[0].origin === change.origin) {
1148
+ return currentGroup.push(change);
1149
+ }
1150
+ txGroups.push([change]);
1151
+ });
1152
+ txGroups.forEach(function (txGroup) {
1153
+ assertDocumentAttachment(e.sharedRoot);
1154
+ e.sharedRoot.doc.transact(function () {
1155
+ txGroup.forEach(function (change) {
1156
+ assertDocumentAttachment(e.sharedRoot);
1157
+ applySlateOp(e.sharedRoot, { children: change.doc }, change.op);
1158
+ });
1159
+ }, txGroup[0].origin);
1160
+ });
1161
+ };
1162
+ var apply = e.apply, onChange = e.onChange;
1163
+ e.apply = function (op) {
1164
+ if (YjsEditor.connected(e) && YjsEditor.isLocal(e)) {
1165
+ YjsEditor.storeLocalChange(e, op);
1166
+ }
1167
+ apply(op);
1168
+ };
1169
+ e.onChange = function () {
1170
+ if (YjsEditor.connected(e)) {
1171
+ YjsEditor.flushLocalChanges(e);
1172
+ }
1173
+ onChange();
1174
+ };
1175
+ return e;
1176
+ };
1177
+ }
1178
+
1179
+ var LAST_SELECTION = new WeakMap();
1180
+ var DEFAULT_WITHOUT_SAVING_ORIGIN = Symbol('slate-yjs-history-without-saving');
1181
+ var YHistoryEditor = {
1182
+ isYHistoryEditor: function (value) {
1183
+ return (YjsEditor.isYjsEditor(value) &&
1184
+ value.undoManager instanceof Y__namespace.UndoManager &&
1185
+ typeof value.undo === 'function' &&
1186
+ typeof value.redo === 'function' &&
1187
+ 'withoutSavingOrigin' in value);
1188
+ },
1189
+ canUndo: function (editor) {
1190
+ return editor.undoManager.undoStack.length > 0;
1191
+ },
1192
+ canRedo: function (editor) {
1193
+ return editor.undoManager.redoStack.length > 0;
1194
+ },
1195
+ isSaving: function (editor) {
1196
+ return editor.undoManager.trackedOrigins.has(YjsEditor.origin(editor));
1197
+ },
1198
+ withoutSaving: function (editor, fn) {
1199
+ YjsEditor.withOrigin(editor, editor.withoutSavingOrigin, fn);
1200
+ },
1201
+ };
1202
+ function withYHistory(options) {
1203
+ if (options === void 0) { options = {}; }
1204
+ return function (editor) {
1205
+ var e = editor;
1206
+ // 将 trackedOrigins 的初始化放到 editor 被传入之后
1207
+ var _a = options.withoutSavingOrigin, withoutSavingOrigin = _a === void 0 ? DEFAULT_WITHOUT_SAVING_ORIGIN : _a, _b = options.trackedOrigins, trackedOrigins = _b === void 0 ? new Set([e.localOrigin]) : _b, restOptions = __rest(options, ["withoutSavingOrigin", "trackedOrigins"]);
1208
+ var undoManager = new Y__namespace.UndoManager(e.sharedRoot, __assign({ trackedOrigins: trackedOrigins }, restOptions));
1209
+ e.undoManager = undoManager;
1210
+ e.withoutSavingOrigin = withoutSavingOrigin;
1211
+ var onChange = e.onChange, isLocalOrigin = e.isLocalOrigin;
1212
+ e.onChange = function () {
1213
+ onChange();
1214
+ LAST_SELECTION.set(e, e.selection && slateRangeToRelativeRange(e.sharedRoot, e, e.selection));
1215
+ };
1216
+ e.isLocalOrigin = function (origin) { return origin === e.withoutSavingOrigin || isLocalOrigin(origin); };
1217
+ var handleStackItemAdded = function (_a) {
1218
+ var stackItem = _a.stackItem;
1219
+ stackItem.meta.set('selection', e.selection && slateRangeToRelativeRange(e.sharedRoot, e, e.selection));
1220
+ stackItem.meta.set('selectionBefore', LAST_SELECTION.get(e));
1221
+ };
1222
+ var handleStackItemUpdated = function (_a) {
1223
+ var stackItem = _a.stackItem;
1224
+ stackItem.meta.set('selection', e.selection && slateRangeToRelativeRange(e.sharedRoot, e, e.selection));
1225
+ };
1226
+ var handleStackItemPopped = function (_a) {
1227
+ var stackItem = _a.stackItem, type = _a.type;
1228
+ // TODO: Change once https://github.com/yjs/yjs/issues/353 is resolved
1229
+ var inverseStack = type === 'undo' ? e.undoManager.redoStack : e.undoManager.undoStack;
1230
+ var inverseItem = inverseStack[inverseStack.length - 1];
1231
+ if (inverseItem) {
1232
+ inverseItem.meta.set('selection', stackItem.meta.get('selectionBefore'));
1233
+ inverseItem.meta.set('selectionBefore', stackItem.meta.get('selection'));
1234
+ }
1235
+ var relativeSelection = stackItem.meta.get('selectionBefore');
1236
+ if (!relativeSelection) {
1237
+ return;
1238
+ }
1239
+ var selection = relativeRangeToSlateRange(e.sharedRoot, e, relativeSelection);
1240
+ if (!selection) {
1241
+ return;
1242
+ }
1243
+ slate.Transforms.select(e, selection);
1244
+ };
1245
+ var connect = e.connect, disconnect = e.disconnect;
1246
+ e.connect = function () {
1247
+ connect();
1248
+ e.undoManager.on('stack-item-added', handleStackItemAdded);
1249
+ e.undoManager.on('stack-item-popped', handleStackItemPopped);
1250
+ e.undoManager.on('stack-item-updated', handleStackItemUpdated);
1251
+ };
1252
+ e.disconnect = function () {
1253
+ e.undoManager.off('stack-item-added', handleStackItemAdded);
1254
+ e.undoManager.off('stack-item-popped', handleStackItemPopped);
1255
+ e.undoManager.off('stack-item-updated', handleStackItemUpdated);
1256
+ disconnect();
1257
+ };
1258
+ e.undo = function () {
1259
+ if (YjsEditor.connected(e)) {
1260
+ YjsEditor.flushLocalChanges(e);
1261
+ e.undoManager.undo();
1262
+ }
1263
+ };
1264
+ e.redo = function () {
1265
+ if (YjsEditor.connected(e)) {
1266
+ YjsEditor.flushLocalChanges(e);
1267
+ e.undoManager.redo();
1268
+ }
1269
+ };
1270
+ return e;
1271
+ };
1272
+ }
1273
+
1274
+ var CURSOR_CHANGE_EVENT_LISTENERS = new WeakMap();
1275
+ var CursorEditor = {
1276
+ isCursorEditor: function (value) {
1277
+ return (YjsEditor.isYjsEditor(value) &&
1278
+ value.awareness &&
1279
+ typeof value.cursorDataField === 'string' &&
1280
+ typeof value.selectionStateField === 'string' &&
1281
+ typeof value.sendCursorPosition === 'function' &&
1282
+ typeof value.sendCursorData === 'function');
1283
+ },
1284
+ sendCursorPosition: function (editor, range) {
1285
+ if (range === void 0) { range = editor.selection; }
1286
+ editor.sendCursorPosition(range);
1287
+ },
1288
+ sendCursorData: function (editor, data) {
1289
+ editor.sendCursorData(data);
1290
+ },
1291
+ on: function (editor, event, handler) {
1292
+ var _a;
1293
+ if (event !== 'change') {
1294
+ return;
1295
+ }
1296
+ if (!editor)
1297
+ return;
1298
+ var listeners = (_a = CURSOR_CHANGE_EVENT_LISTENERS.get(editor)) !== null && _a !== void 0 ? _a : new Set();
1299
+ listeners.add(handler);
1300
+ CURSOR_CHANGE_EVENT_LISTENERS.set(editor, listeners);
1301
+ },
1302
+ off: function (editor, event, listener) {
1303
+ if (event !== 'change') {
1304
+ return;
1305
+ }
1306
+ var listeners = CURSOR_CHANGE_EVENT_LISTENERS.get(editor);
1307
+ if (listeners) {
1308
+ listeners.delete(listener);
1309
+ }
1310
+ },
1311
+ cursorState: function (editor, clientId) {
1312
+ var _a;
1313
+ if (clientId === editor.awareness.clientID || !YjsEditor.connected(editor)) {
1314
+ return null;
1315
+ }
1316
+ var state = editor.awareness.getStates().get(clientId);
1317
+ if (!state) {
1318
+ return null;
1319
+ }
1320
+ return {
1321
+ relativeSelection: (_a = state[editor.selectionStateField]) !== null && _a !== void 0 ? _a : null,
1322
+ data: state[editor.cursorDataField],
1323
+ clientId: clientId,
1324
+ };
1325
+ },
1326
+ cursorStates: function (editor) {
1327
+ if (!YjsEditor.connected(editor)) {
1328
+ return {};
1329
+ }
1330
+ return Object.fromEntries(Array.from(editor.awareness.getStates().entries(), function (_a) {
1331
+ var _b = __read(_a, 2), id = _b[0], state = _b[1];
1332
+ // Ignore own state
1333
+ if (id === editor.awareness.clientID || !state) {
1334
+ return null;
1335
+ }
1336
+ return [
1337
+ id,
1338
+ {
1339
+ relativeSelection: state[editor.selectionStateField],
1340
+ data: state[editor.cursorDataField],
1341
+ },
1342
+ ];
1343
+ }).filter(Array.isArray));
1344
+ },
1345
+ };
1346
+ function withCursors(awareness, options) {
1347
+ if (options === void 0) { options = {}; }
1348
+ return function (editor) {
1349
+ var _a = options.cursorStateField, selectionStateField = _a === void 0 ? 'selection' : _a, _b = options.cursorDataField, cursorDataField = _b === void 0 ? 'data' : _b, _c = options.autoSend, autoSend = _c === void 0 ? true : _c, data = options.data;
1350
+ var e = editor;
1351
+ e.awareness = awareness;
1352
+ e.cursorDataField = cursorDataField;
1353
+ e.selectionStateField = selectionStateField;
1354
+ e.sendCursorData = function (cursorData) {
1355
+ e.awareness.setLocalStateField(e.cursorDataField, cursorData);
1356
+ };
1357
+ e.sendCursorPosition = function (range) {
1358
+ var localState = e.awareness.getLocalState();
1359
+ var currentRange = localState === null || localState === void 0 ? void 0 : localState[selectionStateField];
1360
+ if (!range) {
1361
+ if (currentRange) {
1362
+ e.awareness.setLocalStateField(e.selectionStateField, null);
1363
+ }
1364
+ return;
1365
+ }
1366
+ var _a = slateRangeToRelativeRange(e.sharedRoot, e, range), anchor = _a.anchor, focus = _a.focus;
1367
+ if (!currentRange ||
1368
+ !Y__namespace.compareRelativePositions(anchor, currentRange) ||
1369
+ !Y__namespace.compareRelativePositions(focus, currentRange)) {
1370
+ e.awareness.setLocalStateField(e.selectionStateField, { anchor: anchor, focus: focus });
1371
+ }
1372
+ };
1373
+ var awarenessChangeListener = function (yEvent) {
1374
+ var listeners = CURSOR_CHANGE_EVENT_LISTENERS.get(e);
1375
+ if (!listeners) {
1376
+ return;
1377
+ }
1378
+ var localId = e.awareness.clientID;
1379
+ var event = {
1380
+ added: yEvent.added.filter(function (id) { return id !== localId; }),
1381
+ removed: yEvent.removed.filter(function (id) { return id !== localId; }),
1382
+ updated: yEvent.updated.filter(function (id) { return id !== localId; }),
1383
+ };
1384
+ if (event.added.length > 0 || event.removed.length > 0 || event.updated.length > 0) {
1385
+ listeners.forEach(function (listener) { return listener(event); });
1386
+ }
1387
+ };
1388
+ var connect = e.connect, disconnect = e.disconnect;
1389
+ e.connect = function () {
1390
+ connect();
1391
+ e.awareness.on('change', awarenessChangeListener);
1392
+ awarenessChangeListener({
1393
+ removed: [],
1394
+ added: Array.from(e.awareness.getStates().keys()),
1395
+ updated: [],
1396
+ });
1397
+ if (autoSend) {
1398
+ if (data) {
1399
+ CursorEditor.sendCursorData(e, data);
1400
+ }
1401
+ var onChange_1 = e.onChange;
1402
+ e.onChange = function () {
1403
+ onChange_1();
1404
+ if (YjsEditor.connected(e)) {
1405
+ CursorEditor.sendCursorPosition(e);
1406
+ }
1407
+ };
1408
+ }
1409
+ };
1410
+ e.disconnect = function () {
1411
+ e.awareness.off('change', awarenessChangeListener);
1412
+ awarenessChangeListener({
1413
+ removed: Array.from(e.awareness.getStates().keys()),
1414
+ added: [],
1415
+ updated: [],
1416
+ });
1417
+ disconnect();
1418
+ };
1419
+ return e;
1420
+ };
1421
+ }
1422
+
1423
+ exports.CursorEditor = CursorEditor;
1424
+ exports.YHistoryEditor = YHistoryEditor;
1425
+ exports.YjsEditor = YjsEditor;
1426
+ exports.relativePositionToSlatePoint = relativePositionToSlatePoint;
1427
+ exports.relativeRangeToSlateRange = relativeRangeToSlateRange;
1428
+ exports.slateNodesToInsertDelta = slateNodesToInsertDelta;
1429
+ exports.slatePointToRelativePosition = slatePointToRelativePosition;
1430
+ exports.slateRangeToRelativeRange = slateRangeToRelativeRange;
1431
+ exports.withCursors = withCursors;
1432
+ exports.withYHistory = withYHistory;
1433
+ exports.withYjs = withYjs;
1434
+ exports.yTextToSlateElement = yTextToSlateElement;
1435
+
1436
+ Object.defineProperty(exports, '__esModule', { value: true });
1437
+
1438
+ }));