diff --git a/docs/assets/index-C72Cerdq.js b/docs/assets/index-COURB271.js similarity index 97% rename from docs/assets/index-C72Cerdq.js rename to docs/assets/index-COURB271.js index 9f9ed11..abf2e92 100644 --- a/docs/assets/index-C72Cerdq.js +++ b/docs/assets/index-COURB271.js @@ -46,8 +46,8 @@ `).replace(RN,"")}function xs(n,e,t){if(e=fp(e),fp(n)!==e&&t)throw Error(N(425))}function Ol(){}var hc=null,pc=null;function mc(n,e){return n==="textarea"||n==="noscript"||typeof e.children=="string"||typeof e.children=="number"||typeof e.dangerouslySetInnerHTML=="object"&&e.dangerouslySetInnerHTML!==null&&e.dangerouslySetInnerHTML.__html!=null}var gc=typeof setTimeout=="function"?setTimeout:void 0,AN=typeof clearTimeout=="function"?clearTimeout:void 0,dp=typeof Promise=="function"?Promise:void 0,bN=typeof queueMicrotask=="function"?queueMicrotask:typeof dp<"u"?function(n){return dp.resolve(null).then(n).catch(IN)}:gc;function IN(n){setTimeout(function(){throw n})}function ru(n,e){var t=e,r=0;do{var i=t.nextSibling;if(n.removeChild(t),i&&i.nodeType===8)if(t=i.data,t==="/$"){if(r===0){n.removeChild(i),Oo(e);return}r--}else t!=="$"&&t!=="$?"&&t!=="$!"||r++;t=i}while(t);Oo(e)}function kn(n){for(;n!=null;n=n.nextSibling){var e=n.nodeType;if(e===1||e===3)break;if(e===8){if(e=n.data,e==="$"||e==="$!"||e==="$?")break;if(e==="/$")return null}}return n}function hp(n){n=n.previousSibling;for(var e=0;n;){if(n.nodeType===8){var t=n.data;if(t==="$"||t==="$!"||t==="$?"){if(e===0)return n;e--}else t==="/$"&&e++}n=n.previousSibling}return null}var fi=Math.random().toString(36).slice(2),Mt="__reactFiber$"+fi,bo="__reactProps$"+fi,Qt="__reactContainer$"+fi,yc="__reactEvents$"+fi,zN="__reactListeners$"+fi,PN="__reactHandles$"+fi;function jn(n){var e=n[Mt];if(e)return e;for(var t=n.parentNode;t;){if(e=t[Qt]||t[Mt]){if(t=e.alternate,e.child!==null||t!==null&&t.child!==null)for(n=hp(n);n!==null;){if(t=n[Mt])return t;n=hp(n)}return e}n=t,t=n.parentNode}return null}function Xo(n){return n=n[Mt]||n[Qt],!n||n.tag!==5&&n.tag!==6&&n.tag!==13&&n.tag!==3?null:n}function Or(n){if(n.tag===5||n.tag===6)return n.stateNode;throw Error(N(33))}function Zl(n){return n[bo]||null}var Sc=[],Dr=-1;function An(n){return{current:n}}function K(n){0>Dr||(n.current=Sc[Dr],Sc[Dr]=null,Dr--)}function H(n,e){Dr++,Sc[Dr]=n.current,n.current=e}var On={},Me=An(On),_e=An(!1),rr=On;function ei(n,e){var t=n.type.contextTypes;if(!t)return On;var r=n.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===e)return r.__reactInternalMemoizedMaskedChildContext;var i={},o;for(o in t)i[o]=e[o];return r&&(n=n.stateNode,n.__reactInternalMemoizedUnmaskedChildContext=e,n.__reactInternalMemoizedMaskedChildContext=i),i}function We(n){return n=n.childContextTypes,n!=null}function Dl(){K(_e),K(Me)}function pp(n,e,t){if(Me.current!==On)throw Error(N(168));H(Me,e),H(_e,t)}function C0(n,e,t){var r=n.stateNode;if(e=e.childContextTypes,typeof r.getChildContext!="function")return t;r=r.getChildContext();for(var i in r)if(!(i in e))throw Error(N(108,wC(n)||"Unknown",i));return G({},t,r)}function Tl(n){return n=(n=n.stateNode)&&n.__reactInternalMemoizedMergedChildContext||On,rr=Me.current,H(Me,n),H(_e,_e.current),!0}function mp(n,e,t){var r=n.stateNode;if(!r)throw Error(N(169));t?(n=C0(n,e,rr),r.__reactInternalMemoizedMergedChildContext=n,K(_e),K(Me),H(Me,n)):K(_e),H(_e,t)}var Wt=null,ea=!1,iu=!1;function N0(n){Wt===null?Wt=[n]:Wt.push(n)}function FN(n){ea=!0,N0(n)}function bn(){if(!iu&&Wt!==null){iu=!0;var n=0,e=U;try{var t=Wt;for(U=1;n>=s,i-=s,Ut=1<<32-wt(e)+i|t<R?(O=D,D=null):O=D.sibling;var I=d(g,D,S[R],x);if(I===null){D===null&&(D=O);break}n&&D&&I.alternate===null&&e(g,D),y=o(I,y,R),E===null?M=I:E.sibling=I,E=I,D=O}if(R===S.length)return t(g,D),q&&Vn(g,R),M;if(D===null){for(;RR?(O=D,D=null):O=D.sibling;var ne=d(g,D,I.value,x);if(ne===null){D===null&&(D=O);break}n&&D&&ne.alternate===null&&e(g,D),y=o(ne,y,R),E===null?M=ne:E.sibling=ne,E=ne,D=O}if(I.done)return t(g,D),q&&Vn(g,R),M;if(D===null){for(;!I.done;R++,I=S.next())I=f(g,I.value,x),I!==null&&(y=o(I,y,R),E===null?M=I:E.sibling=I,E=I);return q&&Vn(g,R),M}for(D=r(g,D);!I.done;R++,I=S.next())I=p(D,g,R,I.value,x),I!==null&&(n&&I.alternate!==null&&D.delete(I.key===null?R:I.key),y=o(I,y,R),E===null?M=I:E.sibling=I,E=I);return n&&D.forEach(function(Lt){return e(g,Lt)}),q&&Vn(g,R),M}function w(g,y,S,x){if(typeof S=="object"&&S!==null&&S.type===Cr&&S.key===null&&(S=S.props.children),typeof S=="object"&&S!==null){switch(S.$$typeof){case hs:e:{for(var M=S.key,E=y;E!==null;){if(E.key===M){if(M=S.type,M===Cr){if(E.tag===7){t(g,E.sibling),y=i(E,S.props.children),y.return=g,g=y;break e}}else if(E.elementType===M||typeof M=="object"&&M!==null&&M.$$typeof===nn&&xp(M)===E.type){t(g,E.sibling),y=i(E,S.props),y.ref=wi(g,E,S),y.return=g,g=y;break e}t(g,E);break}else e(g,E);E=E.sibling}S.type===Cr?(y=er(S.props.children,g.mode,x,S.key),y.return=g,g=y):(x=sl(S.type,S.key,S.props,null,g.mode,x),x.ref=wi(g,y,S),x.return=g,g=x)}return s(g);case xr:e:{for(E=S.key;y!==null;){if(y.key===E)if(y.tag===4&&y.stateNode.containerInfo===S.containerInfo&&y.stateNode.implementation===S.implementation){t(g,y.sibling),y=i(y,S.children||[]),y.return=g,g=y;break e}else{t(g,y);break}else e(g,y);y=y.sibling}y=du(S,g.mode,x),y.return=g,g=y}return s(g);case nn:return E=S._init,w(g,y,E(S._payload),x)}if(ji(S))return h(g,y,S,x);if(pi(S))return m(g,y,S,x);Ns(g,S)}return typeof S=="string"&&S!==""||typeof S=="number"?(S=""+S,y!==null&&y.tag===6?(t(g,y.sibling),y=i(y,S),y.return=g,g=y):(t(g,y),y=fu(S,g.mode,x),y.return=g,g=y),s(g)):t(g,y)}return w}var ni=b0(!0),I0=b0(!1),Zo={},Rt=An(Zo),Io=An(Zo),zo=An(Zo);function qn(n){if(n===Zo)throw Error(N(174));return n}function Uf(n,e){switch(H(zo,e),H(Io,n),H(Rt,Zo),n=e.nodeType,n){case 9:case 11:e=(e=e.documentElement)?e.namespaceURI:tc(null,"");break;default:n=n===8?e.parentNode:e,e=n.namespaceURI||null,n=n.tagName,e=tc(e,n)}K(Rt),H(Rt,e)}function ri(){K(Rt),K(Io),K(zo)}function z0(n){qn(zo.current);var e=qn(Rt.current),t=tc(e,n.type);e!==t&&(H(Io,n),H(Rt,t))}function Hf(n){Io.current===n&&(K(Rt),K(Io))}var Q=An(0);function Pl(n){for(var e=n;e!==null;){if(e.tag===13){var t=e.memoizedState;if(t!==null&&(t=t.dehydrated,t===null||t.data==="$?"||t.data==="$!"))return e}else if(e.tag===19&&e.memoizedProps.revealOrder!==void 0){if(e.flags&128)return e}else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===n)break;for(;e.sibling===null;){if(e.return===null||e.return===n)return null;e=e.return}e.sibling.return=e.return,e=e.sibling}return null}var ou=[];function jf(){for(var n=0;nt?t:4,n(!0);var r=su.transition;su.transition={};try{n(!1),e()}finally{U=t,su.transition=r}}function Y0(){return dt().memoizedState}function VN(n,e,t){var r=Cn(n);if(t={lane:r,action:t,hasEagerState:!1,eagerState:null,next:null},G0(n))X0(e,t);else if(t=D0(n,e,t,r),t!==null){var i=Te();kt(t,n,r,i),Z0(t,e,r)}}function JN(n,e,t){var r=Cn(n),i={lane:r,action:t,hasEagerState:!1,eagerState:null,next:null};if(G0(n))X0(e,i);else{var o=n.alternate;if(n.lanes===0&&(o===null||o.lanes===0)&&(o=e.lastRenderedReducer,o!==null))try{var s=e.lastRenderedState,l=o(s,t);if(i.hasEagerState=!0,i.eagerState=l,xt(l,s)){var a=e.interleaved;a===null?(i.next=i,_f(e)):(i.next=a.next,a.next=i),e.interleaved=i;return}}catch{}finally{}t=D0(n,e,i,r),t!==null&&(i=Te(),kt(t,n,r,i),Z0(t,e,r))}}function G0(n){var e=n.alternate;return n===Y||e!==null&&e===Y}function X0(n,e){oo=Fl=!0;var t=n.pending;t===null?e.next=e:(e.next=t.next,t.next=e),n.pending=e}function Z0(n,e,t){if(t&4194240){var r=e.lanes;r&=n.pendingLanes,t|=r,e.lanes=t,Df(n,t)}}var Ll={readContext:ft,useCallback:we,useContext:we,useEffect:we,useImperativeHandle:we,useInsertionEffect:we,useLayoutEffect:we,useMemo:we,useReducer:we,useRef:we,useState:we,useDebugValue:we,useDeferredValue:we,useTransition:we,useMutableSource:we,useSyncExternalStore:we,useId:we,unstable_isNewReconciler:!1},_N={readContext:ft,useCallback:function(n,e){return Nt().memoizedState=[n,e===void 0?null:e],n},useContext:ft,useEffect:Np,useImperativeHandle:function(n,e,t){return t=t!=null?t.concat([n]):null,nl(4194308,4,H0.bind(null,e,n),t)},useLayoutEffect:function(n,e){return nl(4194308,4,n,e)},useInsertionEffect:function(n,e){return nl(4,2,n,e)},useMemo:function(n,e){var t=Nt();return e=e===void 0?null:e,n=n(),t.memoizedState=[n,e],n},useReducer:function(n,e,t){var r=Nt();return e=t!==void 0?t(e):e,r.memoizedState=r.baseState=e,n={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:n,lastRenderedState:e},r.queue=n,n=n.dispatch=VN.bind(null,Y,n),[r.memoizedState,n]},useRef:function(n){var e=Nt();return n={current:n},e.memoizedState=n},useState:Cp,useDebugValue:Gf,useDeferredValue:function(n){return Nt().memoizedState=n},useTransition:function(){var n=Cp(!1),e=n[0];return n=BN.bind(null,n[1]),Nt().memoizedState=n,[e,n]},useMutableSource:function(){},useSyncExternalStore:function(n,e,t){var r=Y,i=Nt();if(q){if(t===void 0)throw Error(N(407));t=t()}else{if(t=e(),fe===null)throw Error(N(349));or&30||L0(r,e,t)}i.memoizedState=t;var o={value:t,getSnapshot:e};return i.queue=o,Np(B0.bind(null,r,o,n),[n]),r.flags|=2048,Lo(9,$0.bind(null,r,o,t,e),void 0,null),t},useId:function(){var n=Nt(),e=fe.identifierPrefix;if(q){var t=Ht,r=Ut;t=(r&~(1<<32-wt(r)-1)).toString(32)+t,e=":"+e+"R"+t,t=Po++,0<\/script>",n=n.removeChild(n.firstChild)):typeof r.is=="string"?n=s.createElement(t,{is:r.is}):(n=s.createElement(t),t==="select"&&(s=n,r.multiple?s.multiple=!0:r.size&&(s.size=r.size))):n=s.createElementNS(n,t),n[Mt]=e,n[bo]=r,a1(n,e,!1,!1),e.stateNode=n;e:{switch(s=rc(t,r),t){case"dialog":j("cancel",n),j("close",n),i=r;break;case"iframe":case"object":case"embed":j("load",n),i=r;break;case"video":case"audio":for(i=0;ioi&&(e.flags|=128,r=!0,ki(o,!1),e.lanes=4194304)}else{if(!r)if(n=Pl(s),n!==null){if(e.flags|=128,r=!0,t=n.updateQueue,t!==null&&(e.updateQueue=t,e.flags|=4),ki(o,!0),o.tail===null&&o.tailMode==="hidden"&&!s.alternate&&!q)return ke(e),null}else 2*te()-o.renderingStartTime>oi&&t!==1073741824&&(e.flags|=128,r=!0,ki(o,!1),e.lanes=4194304);o.isBackwards?(s.sibling=e.child,e.child=s):(t=o.last,t!==null?t.sibling=s:e.child=s,o.last=s)}return o.tail!==null?(e=o.tail,o.rendering=e,o.tail=e.sibling,o.renderingStartTime=te(),e.sibling=null,t=Q.current,H(Q,r?t&1|2:t&1),e):(ke(e),null);case 22:case 23:return rd(),r=e.memoizedState!==null,n!==null&&n.memoizedState!==null!==r&&(e.flags|=8192),r&&e.mode&1?Qe&1073741824&&(ke(e),e.subtreeFlags&6&&(e.flags|=8192)):ke(e),null;case 24:return null;case 25:return null}throw Error(N(156,e.tag))}function YN(n,e){switch(Lf(e),e.tag){case 1:return We(e.type)&&Dl(),n=e.flags,n&65536?(e.flags=n&-65537|128,e):null;case 3:return ri(),K(_e),K(Me),jf(),n=e.flags,n&65536&&!(n&128)?(e.flags=n&-65537|128,e):null;case 5:return Hf(e),null;case 13:if(K(Q),n=e.memoizedState,n!==null&&n.dehydrated!==null){if(e.alternate===null)throw Error(N(340));ti()}return n=e.flags,n&65536?(e.flags=n&-65537|128,e):null;case 19:return K(Q),null;case 4:return ri(),null;case 10:return Jf(e.type._context),null;case 22:case 23:return rd(),null;case 24:return null;default:return null}}var Es=!1,xe=!1,GN=typeof WeakSet=="function"?WeakSet:Set,T=null;function br(n,e){var t=n.ref;if(t!==null)if(typeof t=="function")try{t(null)}catch(r){X(n,e,r)}else t.current=null}function Rc(n,e,t){try{t()}catch(r){X(n,e,r)}}var Ip=!1;function XN(n,e){if(hc=Nl,n=p0(),Pf(n)){if("selectionStart"in n)var t={start:n.selectionStart,end:n.selectionEnd};else e:{t=(t=n.ownerDocument)&&t.defaultView||window;var r=t.getSelection&&t.getSelection();if(r&&r.rangeCount!==0){t=r.anchorNode;var i=r.anchorOffset,o=r.focusNode;r=r.focusOffset;try{t.nodeType,o.nodeType}catch{t=null;break e}var s=0,l=-1,a=-1,u=0,c=0,f=n,d=null;t:for(;;){for(var p;f!==t||i!==0&&f.nodeType!==3||(l=s+i),f!==o||r!==0&&f.nodeType!==3||(a=s+r),f.nodeType===3&&(s+=f.nodeValue.length),(p=f.firstChild)!==null;)d=f,f=p;for(;;){if(f===n)break t;if(d===t&&++u===i&&(l=s),d===o&&++c===r&&(a=s),(p=f.nextSibling)!==null)break;f=d,d=f.parentNode}f=p}t=l===-1||a===-1?null:{start:l,end:a}}else t=null}t=t||{start:0,end:0}}else t=null;for(pc={focusedElem:n,selectionRange:t},Nl=!1,T=e;T!==null;)if(e=T,n=e.child,(e.subtreeFlags&1028)!==0&&n!==null)n.return=e,T=n;else for(;T!==null;){e=T;try{var h=e.alternate;if(e.flags&1024)switch(e.tag){case 0:case 11:case 15:break;case 1:if(h!==null){var m=h.memoizedProps,w=h.memoizedState,g=e.stateNode,y=g.getSnapshotBeforeUpdate(e.elementType===e.type?m:mt(e.type,m),w);g.__reactInternalSnapshotBeforeUpdate=y}break;case 3:var S=e.stateNode.containerInfo;S.nodeType===1?S.textContent="":S.nodeType===9&&S.documentElement&&S.removeChild(S.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(N(163))}}catch(x){X(e,e.return,x)}if(n=e.sibling,n!==null){n.return=e.return,T=n;break}T=e.return}return h=Ip,Ip=!1,h}function so(n,e,t){var r=e.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var i=r=r.next;do{if((i.tag&n)===n){var o=i.destroy;i.destroy=void 0,o!==void 0&&Rc(e,t,o)}i=i.next}while(i!==r)}}function ra(n,e){if(e=e.updateQueue,e=e!==null?e.lastEffect:null,e!==null){var t=e=e.next;do{if((t.tag&n)===n){var r=t.create;t.destroy=r()}t=t.next}while(t!==e)}}function Ac(n){var e=n.ref;if(e!==null){var t=n.stateNode;switch(n.tag){case 5:n=t;break;default:n=t}typeof e=="function"?e(n):e.current=n}}function f1(n){var e=n.alternate;e!==null&&(n.alternate=null,f1(e)),n.child=null,n.deletions=null,n.sibling=null,n.tag===5&&(e=n.stateNode,e!==null&&(delete e[Mt],delete e[bo],delete e[yc],delete e[zN],delete e[PN])),n.stateNode=null,n.return=null,n.dependencies=null,n.memoizedProps=null,n.memoizedState=null,n.pendingProps=null,n.stateNode=null,n.updateQueue=null}function d1(n){return n.tag===5||n.tag===3||n.tag===4}function zp(n){e:for(;;){for(;n.sibling===null;){if(n.return===null||d1(n.return))return null;n=n.return}for(n.sibling.return=n.return,n=n.sibling;n.tag!==5&&n.tag!==6&&n.tag!==18;){if(n.flags&2||n.child===null||n.tag===4)continue e;n.child.return=n,n=n.child}if(!(n.flags&2))return n.stateNode}}function bc(n,e,t){var r=n.tag;if(r===5||r===6)n=n.stateNode,e?t.nodeType===8?t.parentNode.insertBefore(n,e):t.insertBefore(n,e):(t.nodeType===8?(e=t.parentNode,e.insertBefore(n,t)):(e=t,e.appendChild(n)),t=t._reactRootContainer,t!=null||e.onclick!==null||(e.onclick=Ol));else if(r!==4&&(n=n.child,n!==null))for(bc(n,e,t),n=n.sibling;n!==null;)bc(n,e,t),n=n.sibling}function Ic(n,e,t){var r=n.tag;if(r===5||r===6)n=n.stateNode,e?t.insertBefore(n,e):t.appendChild(n);else if(r!==4&&(n=n.child,n!==null))for(Ic(n,e,t),n=n.sibling;n!==null;)Ic(n,e,t),n=n.sibling}var he=null,gt=!1;function Zt(n,e,t){for(t=t.child;t!==null;)h1(n,e,t),t=t.sibling}function h1(n,e,t){if(Tt&&typeof Tt.onCommitFiberUnmount=="function")try{Tt.onCommitFiberUnmount(Ql,t)}catch{}switch(t.tag){case 5:xe||br(t,e);case 6:var r=he,i=gt;he=null,Zt(n,e,t),he=r,gt=i,he!==null&&(gt?(n=he,t=t.stateNode,n.nodeType===8?n.parentNode.removeChild(t):n.removeChild(t)):he.removeChild(t.stateNode));break;case 18:he!==null&&(gt?(n=he,t=t.stateNode,n.nodeType===8?ru(n.parentNode,t):n.nodeType===1&&ru(n,t),Oo(n)):ru(he,t.stateNode));break;case 4:r=he,i=gt,he=t.stateNode.containerInfo,gt=!0,Zt(n,e,t),he=r,gt=i;break;case 0:case 11:case 14:case 15:if(!xe&&(r=t.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){i=r=r.next;do{var o=i,s=o.destroy;o=o.tag,s!==void 0&&(o&2||o&4)&&Rc(t,e,s),i=i.next}while(i!==r)}Zt(n,e,t);break;case 1:if(!xe&&(br(t,e),r=t.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=t.memoizedProps,r.state=t.memoizedState,r.componentWillUnmount()}catch(l){X(t,e,l)}Zt(n,e,t);break;case 21:Zt(n,e,t);break;case 22:t.mode&1?(xe=(r=xe)||t.memoizedState!==null,Zt(n,e,t),xe=r):Zt(n,e,t);break;default:Zt(n,e,t)}}function Pp(n){var e=n.updateQueue;if(e!==null){n.updateQueue=null;var t=n.stateNode;t===null&&(t=n.stateNode=new GN),e.forEach(function(r){var i=lM.bind(null,n,r);t.has(r)||(t.add(r),r.then(i,i))})}}function pt(n,e){var t=e.deletions;if(t!==null)for(var r=0;ri&&(i=s),r&=~o}if(r=i,r=te()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*eM(r/1960))-r,10n?16:n,pn===null)var r=!1;else{if(n=pn,pn=null,Vl=0,V&6)throw Error(N(331));var i=V;for(V|=4,T=n.current;T!==null;){var o=T,s=o.child;if(T.flags&16){var l=o.deletions;if(l!==null){for(var a=0;ate()-td?Zn(n,0):ed|=t),Ue(n,e)}function v1(n,e){e===0&&(n.mode&1?(e=ys,ys<<=1,!(ys&130023424)&&(ys=4194304)):e=1);var t=Te();n=Yt(n,e),n!==null&&(Yo(n,e,t),Ue(n,t))}function sM(n){var e=n.memoizedState,t=0;e!==null&&(t=e.retryLane),v1(n,t)}function lM(n,e){var t=0;switch(n.tag){case 13:var r=n.stateNode,i=n.memoizedState;i!==null&&(t=i.retryLane);break;case 19:r=n.stateNode;break;default:throw Error(N(314))}r!==null&&r.delete(e),v1(n,t)}var x1;x1=function(n,e,t){if(n!==null)if(n.memoizedProps!==e.pendingProps||_e.current)Ve=!0;else{if(!(n.lanes&t)&&!(e.flags&128))return Ve=!1,qN(n,e,t);Ve=!!(n.flags&131072)}else Ve=!1,q&&e.flags&1048576&&M0(e,Al,e.index);switch(e.lanes=0,e.tag){case 2:var r=e.type;rl(n,e),n=e.pendingProps;var i=ei(e,Me.current);Jr(e,t),i=qf(null,e,r,n,i,t);var o=Qf();return e.flags|=1,typeof i=="object"&&i!==null&&typeof i.render=="function"&&i.$$typeof===void 0?(e.tag=1,e.memoizedState=null,e.updateQueue=null,We(r)?(o=!0,Tl(e)):o=!1,e.memoizedState=i.state!==null&&i.state!==void 0?i.state:null,Wf(e),i.updater=ta,e.stateNode=i,i._reactInternals=e,Cc(e,r,n,t),e=Ec(null,e,r,!0,o,t)):(e.tag=0,q&&o&&Ff(e),Oe(null,e,i,t),e=e.child),e;case 16:r=e.elementType;e:{switch(rl(n,e),n=e.pendingProps,i=r._init,r=i(r._payload),e.type=r,i=e.tag=uM(r),n=mt(r,n),i){case 0:e=Mc(null,e,r,n,t);break e;case 1:e=Rp(null,e,r,n,t);break e;case 11:e=Dp(null,e,r,n,t);break e;case 14:e=Tp(null,e,r,mt(r.type,n),t);break e}throw Error(N(306,r,""))}return e;case 0:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:mt(r,i),Mc(n,e,r,i,t);case 1:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:mt(r,i),Rp(n,e,r,i,t);case 3:e:{if(o1(e),n===null)throw Error(N(387));r=e.pendingProps,o=e.memoizedState,i=o.element,T0(n,e),zl(e,r,null,t);var s=e.memoizedState;if(r=s.element,o.isDehydrated)if(o={element:r,isDehydrated:!1,cache:s.cache,pendingSuspenseBoundaries:s.pendingSuspenseBoundaries,transitions:s.transitions},e.updateQueue.baseState=o,e.memoizedState=o,e.flags&256){i=ii(Error(N(423)),e),e=Ap(n,e,r,t,i);break e}else if(r!==i){i=ii(Error(N(424)),e),e=Ap(n,e,r,t,i);break e}else for(Ge=kn(e.stateNode.containerInfo.firstChild),Ze=e,q=!0,St=null,t=I0(e,null,r,t),e.child=t;t;)t.flags=t.flags&-3|4096,t=t.sibling;else{if(ti(),r===i){e=Gt(n,e,t);break e}Oe(n,e,r,t)}e=e.child}return e;case 5:return z0(e),n===null&&kc(e),r=e.type,i=e.pendingProps,o=n!==null?n.memoizedProps:null,s=i.children,mc(r,i)?s=null:o!==null&&mc(r,o)&&(e.flags|=32),i1(n,e),Oe(n,e,s,t),e.child;case 6:return n===null&&kc(e),null;case 13:return s1(n,e,t);case 4:return Uf(e,e.stateNode.containerInfo),r=e.pendingProps,n===null?e.child=ni(e,null,r,t):Oe(n,e,r,t),e.child;case 11:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:mt(r,i),Dp(n,e,r,i,t);case 7:return Oe(n,e,e.pendingProps,t),e.child;case 8:return Oe(n,e,e.pendingProps.children,t),e.child;case 12:return Oe(n,e,e.pendingProps.children,t),e.child;case 10:e:{if(r=e.type._context,i=e.pendingProps,o=e.memoizedProps,s=i.value,H(bl,r._currentValue),r._currentValue=s,o!==null)if(xt(o.value,s)){if(o.children===i.children&&!_e.current){e=Gt(n,e,t);break e}}else for(o=e.child,o!==null&&(o.return=e);o!==null;){var l=o.dependencies;if(l!==null){s=o.child;for(var a=l.firstContext;a!==null;){if(a.context===r){if(o.tag===1){a=Kt(-1,t&-t),a.tag=2;var u=o.updateQueue;if(u!==null){u=u.shared;var c=u.pending;c===null?a.next=a:(a.next=c.next,c.next=a),u.pending=a}}o.lanes|=t,a=o.alternate,a!==null&&(a.lanes|=t),vc(o.return,t,e),l.lanes|=t;break}a=a.next}}else if(o.tag===10)s=o.type===e.type?null:o.child;else if(o.tag===18){if(s=o.return,s===null)throw Error(N(341));s.lanes|=t,l=s.alternate,l!==null&&(l.lanes|=t),vc(s,t,e),s=o.sibling}else s=o.child;if(s!==null)s.return=o;else for(s=o;s!==null;){if(s===e){s=null;break}if(o=s.sibling,o!==null){o.return=s.return,s=o;break}s=s.return}o=s}Oe(n,e,i.children,t),e=e.child}return e;case 9:return i=e.type,r=e.pendingProps.children,Jr(e,t),i=ft(i),r=r(i),e.flags|=1,Oe(n,e,r,t),e.child;case 14:return r=e.type,i=mt(r,e.pendingProps),i=mt(r.type,i),Tp(n,e,r,i,t);case 15:return n1(n,e,e.type,e.pendingProps,t);case 17:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:mt(r,i),rl(n,e),e.tag=1,We(r)?(n=!0,Tl(e)):n=!1,Jr(e,t),A0(e,r,i),Cc(e,r,i,t),Ec(null,e,r,!0,n,t);case 19:return l1(n,e,t);case 22:return r1(n,e,t)}throw Error(N(156,e.tag))};function C1(n,e){return Qy(n,e)}function aM(n,e,t,r){this.tag=n,this.key=t,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=e,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function at(n,e,t,r){return new aM(n,e,t,r)}function od(n){return n=n.prototype,!(!n||!n.isReactComponent)}function uM(n){if(typeof n=="function")return od(n)?1:0;if(n!=null){if(n=n.$$typeof,n===Nf)return 11;if(n===Mf)return 14}return 2}function Nn(n,e){var t=n.alternate;return t===null?(t=at(n.tag,e,n.key,n.mode),t.elementType=n.elementType,t.type=n.type,t.stateNode=n.stateNode,t.alternate=n,n.alternate=t):(t.pendingProps=e,t.type=n.type,t.flags=0,t.subtreeFlags=0,t.deletions=null),t.flags=n.flags&14680064,t.childLanes=n.childLanes,t.lanes=n.lanes,t.child=n.child,t.memoizedProps=n.memoizedProps,t.memoizedState=n.memoizedState,t.updateQueue=n.updateQueue,e=n.dependencies,t.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext},t.sibling=n.sibling,t.index=n.index,t.ref=n.ref,t}function sl(n,e,t,r,i,o){var s=2;if(r=n,typeof n=="function")od(n)&&(s=1);else if(typeof n=="string")s=5;else e:switch(n){case Cr:return er(t.children,i,o,e);case Cf:s=8,i|=8;break;case Ku:return n=at(12,t,e,i|2),n.elementType=Ku,n.lanes=o,n;case qu:return n=at(13,t,e,i),n.elementType=qu,n.lanes=o,n;case Qu:return n=at(19,t,e,i),n.elementType=Qu,n.lanes=o,n;case by:return oa(t,i,o,e);default:if(typeof n=="object"&&n!==null)switch(n.$$typeof){case Ry:s=10;break e;case Ay:s=9;break e;case Nf:s=11;break e;case Mf:s=14;break e;case nn:s=16,r=null;break e}throw Error(N(130,n==null?n:typeof n,""))}return e=at(s,t,e,i),e.elementType=n,e.type=r,e.lanes=o,e}function er(n,e,t,r){return n=at(7,n,r,e),n.lanes=t,n}function oa(n,e,t,r){return n=at(22,n,r,e),n.elementType=by,n.lanes=t,n.stateNode={isHidden:!1},n}function fu(n,e,t){return n=at(6,n,null,e),n.lanes=t,n}function du(n,e,t){return e=at(4,n.children!==null?n.children:[],n.key,e),e.lanes=t,e.stateNode={containerInfo:n.containerInfo,pendingChildren:null,implementation:n.implementation},e}function cM(n,e,t,r,i){this.tag=e,this.containerInfo=n,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=ja(0),this.expirationTimes=ja(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=ja(0),this.identifierPrefix=r,this.onRecoverableError=i,this.mutableSourceEagerHydrationData=null}function sd(n,e,t,r,i,o,s,l,a){return n=new cM(n,e,t,l,a),e===1?(e=1,o===!0&&(e|=8)):e=0,o=at(3,null,null,e),n.current=o,o.stateNode=n,o.memoizedState={element:r,isDehydrated:t,cache:null,transitions:null,pendingSuspenseBoundaries:null},Wf(o),n}function fM(n,e,t){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(O1)}catch(n){console.error(n)}}O1(),My.exports=tt;var si=My.exports,D1,Wp=si;D1=Wp.createRoot,Wp.hydrateRoot;const es=C.createContext(null),T1=C.createContext(null);function gM(n){const e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(const r in t)r=="class"?e.class+=" "+t[r]:r=="style"?e.style=(e.style?e.style+";":"")+t[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(t[r]))}),e.translate||(e.translate="no"),[ge.node(0,n.state.doc.content.size,e)]}const yM=[],SM={},$c=_.empty;class Wn{constructor(e){this.members=e}map(e,t){const r=this.members.map(i=>i.map(e,t,SM));return Wn.from(r)}forChild(e,t){if(t.isLeaf)return _.empty;let r=[];for(let i=0;it instanceof _)?e:e.reduce((t,r)=>t.concat(r instanceof _?r:r.members),[]))}}forEachSet(e){for(let t=0;t0;)e++;n.splice(e,0,t)}function kM(n,e){const t=[];return n.someProp("decorations",r=>{const i=r(n.state);i&&i!=$c&&t.push(i)}),e&&t.push(_.create(n.state.doc,[e])),Wn.from(t)}const cd=function(n){for(let e=0;;e++)if(n=n.previousSibling,!n)return e},Hp=function(n){const e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},vM=function(n,e,t,r){return t&&(jp(n,e,t,r,-1)||jp(n,e,t,r,1))},xM=/^(img|br|input|textarea|hr)$/i;function jp(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:Wl(n))){const o=n.parentNode;if(!o||o.nodeType!=1||NM(n)||xM.test(n.nodeName)||n.contentEditable=="false")return!1;e=cd(n)+(i<0?0:1),n=o}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?Wl(n):0}else return!1}}function Wl(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function CM(n,e,t){for(let r=e==0,i=e==Wl(n);r||i;){if(n==t)return!0;const o=cd(n);if(n=n.parentNode,!n)return!1;r=r&&o==0,i=i&&o==Wl(n)}return!1}function NM(n){let e;for(let t=n;t&&!(e=t.pmViewDesc);t=t.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==n||e.contentDOM==n)}const A1=function(n){return n.focusNode&&vM(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)},b1=C.createContext(null);function MM(n,e){const t=C.useContext(b1);C.useLayoutEffect(()=>t(n),e)}function I1(n,e){const{view:t}=C.useContext(es);MM(()=>{if(t)return n(t)},e&&[t,...e])}const EM=C.forwardRef(function({widget:e,pos:t,...r},i){const[o,s]=C.useState(!0),l=C.useRef(null);return C.useImperativeHandle(i,()=>l.current,[]),I1(a=>{if(!a||!l.current)return;a.domObserver.disconnectSelection();const u=a.domSelection(),c=document.createRange(),f=l.current;f.nodeName=="IMG"&&f.parentNode?c.setEnd(f.parentNode,cd(f)+1):c.setEnd(f,0),c.collapse(!1),u.removeAllRanges(),u.addRange(c),s(!1),a.domObserver.connectSelection()},[]),o?b.jsx("img",{ref:l,className:"ProseMirror-separator","mark-placeholder":"true",alt:"",...r}):null});function OM(n,e){if(n==e)return!0;for(const t in n)if(n[t]!==e[t])return!1;for(const t in e)if(!(t in n))return!1;return!0}const DM={side:0};class Bo{constructor(e,t){this.Component=e,this.spec=t??DM,this.side=this.spec.side??0}map(e,t,r,i){const{pos:o,deleted:s}=e.mapResult(t.from+i,this.side<0?-1:1);return s?null:new ge(o-r,o-r,this)}valid(){return!0}eq(e){return this==e||e instanceof Bo&&(this.spec.key&&this.spec.key==e.spec.key||this.Component==e.Component&&OM(this.spec,e.spec))}destroy(){}}function z1(n,e,t){return new ge(n,n,new Bo(e,t))}function hu(){return Math.floor(Math.random()*16777215).toString(16)}const Vo=new Ho("@nytimes/react-prosemirror/reactKeys");function TM(){let n=!1;return new Ft({key:Vo,state:{init(e,t){const r={posToKey:new Map,keyToPos:new Map};return t.doc.descendants((i,o)=>{const s=hu();return r.posToKey.set(o,s),r.keyToPos.set(s,o),!0}),r},apply(e,t,r,i){if(!e.docChanged||n)return t;const o=e.getMeta(Vo),s=(o==null?void 0:o.type)==="bustKey"&&o.payload.key,l={posToKey:new Map,keyToPos:new Map},a=Array.from(t.posToKey.entries()).sort(([u],[c])=>u-c);for(const[u,c]of a){const{pos:f,deleted:d}=e.mapping.mapResult(u);if(d)continue;let p=c;s===c&&(p=hu()),l.posToKey.set(f,p),l.keyToPos.set(p,f)}return i.doc.descendants((u,c)=>{if(l.posToKey.has(c))return!0;const f=hu();return l.posToKey.set(c,f),l.keyToPos.set(f,c),!0}),l}},props:{handleDOMEvents:{compositionstart:()=>{n=!0},compositionend:()=>{n=!1}}}})}function pu(n,e,t={}){var s;if(e===null)return!1;const r=t.from??n.state.selection.from,i=t.to??n.state.selection.to;if(n.someProp("handleTextInput",l=>l(n,r,i,e)))return!0;const{tr:o}=n.state;if(t.marks&&o.ensureMarks(t.marks),o.insertText(e,r,i),t.bust){const l=n.state.doc.resolve(r),a=l.sharedDepth(i),u=l.start(a),c=(s=Vo.getState(n.state))==null?void 0:s.posToKey.get(u-1);o.setMeta(Vo,{type:"bustKey",payload:{key:c}})}return n.dispatch(o),!0}function RM(n){let e=null,t=null;return new Ft({props:{handleDOMEvents:{compositionstart(r){var s;const{state:i}=r;r.dispatch(i.tr.deleteSelection());const o=i.selection.$from;return i.selection.empty&&(i.storedMarks||!o.textOffset&&o.parentOffset&&((s=o.nodeBefore)!=null&&s.marks.some(l=>l.type.spec.inclusive===!1)))&&n(z1(i.selection.from,EM,{key:"cursor-wrapper",marks:i.storedMarks??o.marks()})),t=i.storedMarks??o.marks(),r.input.composing=!0,!0},compositionupdate(){return!0},compositionend(r){if(r.input.composing=!1,e!==null)return pu(r,e,{bust:!0,marks:t}),e=null,t=null,n(null),!0},beforeinput(r,i){var o,s;switch(i.preventDefault(),i.inputType){case"insertCompositionText":{if(i.data===null)break;e=i.data;break}case"insertReplacementText":{const l=i.getTargetRanges();(s=(o=i.dataTransfer)==null?void 0:o.items[0])==null||s.getAsString(a=>{for(const u of l){const c=r.posAtDOM(u.startContainer,u.startOffset,1),f=r.posAtDOM(u.endContainer,u.endOffset,1);pu(r,a,{from:c,to:f})}});break}case"insertText":{pu(r,i.data);break}case"deleteWordBackward":case"deleteContentBackward":case"deleteWordForward":case"deleteContentForward":case"deleteContent":{const l=i.getTargetRanges(),{tr:a}=r.state;for(const u of l){const c=r.posAtDOM(u.startContainer,u.startOffset),f=r.posAtDOM(u.endContainer,u.endOffset),{doc:d}=r.state,p=d.resolve(c).marksAcross(d.resolve(f));a.delete(c,f).setStoredMarks(p)}r.dispatch(a);break}}return!0}}}})}const Pt=typeof navigator<"u"?navigator:null,Kp=typeof document<"u"?document:null,In=Pt&&Pt.userAgent||"",Bc=/Edge\/(\d+)/.exec(In),P1=/MSIE \d/.exec(In),Vc=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(In),ca=!!(P1||Vc||Bc),AM=P1?document.documentMode:Vc?+Vc[1]:Bc?+Bc[1]:0,F1=!ca&&/gecko\/(\d+)/i.test(In),bM=F1&&+(/Firefox\/(\d+)/.exec(In)||[0,0])[1],Jc=!ca&&/Chrome\/(\d+)/.exec(In),IM=!!Jc,zM=Jc?+Jc[1]:0,L1=!ca&&!!Pt&&/Apple Computer/.test(Pt.vendor),$1=L1&&(/Mobile\/\w+/.test(In)||!!Pt&&Pt.maxTouchPoints>2),PM=$1||(Pt?/Mac/.test(Pt.platform):!1),FM=Pt?/Win/.test(Pt.platform):!1,LM=/Android \d/.test(In),B1=!!Kp&&"webkitFontSmoothing"in Kp.documentElement.style,$M=B1?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,Ne={ie:ca,ie_version:AM,gecko:F1,gecko_version:bM,chrome:IM,chrome_version:zM,safari:L1,ios:$1,mac:PM,windows:FM,android:LM,webkit:B1,webkit_version:$M};function mu(n){return n.editable&&!n.hasFocus()?!1:BM(n)}function BM(n){var t,r;const e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(((t=e.focusNode)==null?void 0:t.nodeType)==3?(r=e.focusNode)==null?void 0:r.parentNode:e.focusNode))}catch{return!1}}function VM(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||$.between(e,t,r)}function qp(n,e=null){const t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode);const o=i&&i.size==0,s=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(s<0)return null;const l=r.resolve(s);let a,u;if(A1(t)){for(a=l;i&&!i.node;)i=i.parent;const c=i.node;if(i&&c.isAtom&&z.isSelectable(c)&&i.parent&&!(c.isInline&&CM(t.focusNode,t.focusOffset,i.dom))){const f=i.posBefore;u=new z(s==f?l:r.resolve(f))}}else{const c=n.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(c<0)return null;a=r.resolve(c)}if(!u){const c=e=="pointer"||n.state.selection.head{(r.anchorNode!=i||r.anchorOffset!=o)&&(t.removeEventListener("selectionchange",e.input.hideSelectionGuard),setTimeout(()=>{(!V1(e)||e.state.selection.visible)&&e.dom.classList.remove("ProseMirror-hideselection")},20))})}const em=Ne.safari||Ne.chrome&&Ne.chrome_version<63;function Ts(n,e=!1){const t=n,r=t.state.selection;if(WM(t,r),!!V1(t)){if(!e&&t.input.mouseDown&&t.input.mouseDown.allowDefault&&Ne.chrome){const i=t.domSelectionRange(),o=t.domObserver.currentSelection;if(i.anchorNode&&o.anchorNode&&Ul(i.anchorNode,i.anchorOffset,o.anchorNode,o.anchorOffset)){t.input.mouseDown.delayedSelectionSync=!0,t.domObserver.setCurSelection();return}}if(t.domObserver.disconnectSelection(),t.cursorWrapper)HM(t);else{const{anchor:i,head:o}=r;let s,l;em&&!(r instanceof $)&&(r.$from.parent.inlineContent||(s=Xp(t,r.from)),!r.empty&&!r.$from.parent.inlineContent&&(l=Xp(t,r.to))),t.docView.setSelection(i,o,t.root,e),em&&(s&&Zp(s),l&&Zp(l)),r.visible?t.dom.classList.remove("ProseMirror-hideselection"):(t.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&jM(t))}t.domObserver.setCurSelection(),t.domObserver.connectSelection()}}class KM{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}}class qM{constructor(e){this.view=e,this.flushingSoon=-1,this.currentSelection=new KM,this.suppressingSelectionUpdates=!1,this.view=e,this.onSelectionChange=this.onSelectionChange.bind(this)}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}stop(){this.disconnectSelection()}start(){this.connectSelection()}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;const t=new Set;let r;for(let o=e.focusNode;o;o=Hp(o))t.add(o);for(let o=e.anchorNode;o;o=Hp(o))if(t.has(o)){r=o;break}const i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:(r==null?void 0:r.nodeType)==3?r==null?void 0:r.parentNode:r}))return this.setCurSelection(),!0}registerMutation(){}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}updateSelection(){const{view:e}=this,t=e.input.compositionPendingChanges||(e.composing?e.input.compositionID:0);e.input.compositionPendingChanges=0;const r=e.input.lastSelectionTime>Date.now()-50?e.input.lastSelectionOrigin:null,i=qp(e,r);if(i&&!e.state.selection.eq(i)){const o=e.state.tr.setSelection(i);r=="pointer"?o.setMeta("pointer",!0):r=="key"&&o.scrollIntoView(),t&&o.setMeta("composition",t),e.dispatch(o)}}selectionToDOM(){const{view:e}=this;Ts(e);const t=e.domSelectionRange();this.currentSelection.set(t)}flush(){const{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;const t=e.domSelectionRange(),r=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(t)&&mu(e)&&!this.ignoreSelectionChange(t);let i=null;r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}onSelectionChange(){if(mu(this.view)&&!this.view.composing){if(this.suppressingSelectionUpdates)return Ts(this.view);if(Ne.ie&&Ne.ie_version<=11&&!this.view.state.selection.empty){const e=this.view.domSelectionRange();if(e.focusNode&&Ul(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}}const li=0,tm=1,Rs=2,Jo=3;class ts{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=li,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;ton(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){const o=this.getDesc(i);let s;if(o&&(!t||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}getDesc(e){const t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){const o=this.getDesc(i);if(o)return o.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||s instanceof hd){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof fd&&o.side>=0;r--);if(t<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&t&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,t):{node:this.contentDOM,offset:o?on(o.dom)+1:0}}else{let o,s=!0;for(;o=r=c&&t<=u-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,c);e=s;for(let f=l;f>0;f--){const d=this.children[f-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=on(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(u>t||l==this.children.length-1)){t=u;for(let c=l+1;ch&&st){const h=l;l=a,a=h}const p=document.createRange();p.setEnd(a.node,a.offset),p.setStart(l.node,l.offset),u.removeAllRanges(),u.addRange(p)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let r=0,i=0;i=r:er){const l=r+o.border,a=s-o.border;if(e>=l&&t<=a){this.dirty=e==r||t==s?Rs:tm,e==l&&t==a&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=Jo:o.markDirty(e-l,t-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?Rs:Jo}r=s}this.dirty=Rs}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){const r=e==1?Rs:tm;t.dirtythis.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){const r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>v.empty)}return e}matchesNode(e,t,r){return this.dirty==li&&e.eq(this.node)&&XM(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}update(e,t,r,i){return!0}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}class GM extends dd{constructor(e,t,r,i,o,s,l){super(e,t,r,i,o,s,null,l)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,i){return!0}inParent(){const e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Jo)}get domAtom(){return!1}}class hd extends ts{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==li&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}function XM(n,e){if(n.length!=e.length)return!1;for(let t=0;t{u=!!a.call(this,s,l)}),u||l.defaultPrevented)return!0}return!1};e[r]=o}return new Ft({key:new Ho("@nytimes/react-prosemirror/componentEventListeners"),props:{handleDOMEvents:e}})}function eE(){const[n,e]=C.useState(new Map),t=C.useCallback((o,s)=>{const l=n.get(o)??[];l.unshift(s),n.has(o)||(n.set(o,l),e(new Map(n)))},[n]),r=C.useCallback((o,s)=>{const l=n.get(o);l==null||l.splice(l.indexOf(s),1)},[n]),i=C.useMemo(()=>ZM(n),[n]);return{registerEventListener:t,unregisterEventListener:r,componentEventListenersPlugin:i}}function J1(){const[,n]=C.useReducer(e=>e+1,0);return n}class tE extends Av{constructor(e,t){super(e,{state:un.create({schema:t.state.schema,plugins:t.state.plugins}),plugins:t.plugins}),this.shouldUpdatePluginViews=!1,this.shouldUpdatePluginViews=!0,this._props=t,this.oldProps={state:t.state},this.state=t.state,this.domObserver.stop(),this.domObserver=new qM(this),this.domObserver.start(),this.docView.dom.replaceChildren(),this.docView=t.docView}pureSetProps(e){this._props={...this._props,...e},this.state=this._props.state}runPendingEffects(){const e=this.props;this._props=this.oldProps,this.state=this._props.state,this.update(e)}update(e){super.update(e),this.oldProps=e}updatePluginViews(e){this.shouldUpdatePluginViews&&super.updatePluginViews(e)}destroy(){this.dom=document.createElement("div"),super.destroy()}}const nE=new Om({nodes:{doc:{content:"text*"},text:{inline:!0}}}),rE=un.create({schema:nE});function iE(n,e){const[t,r]=C.useState(null),[i,o]=C.useState(null),s=J1(),l=e.defaultState??rE,[a,u]=C.useState(l),c=e.state??a,{componentEventListenersPlugin:f,registerEventListener:d,unregisterEventListener:p}=eE(),h=C.useCallback(x=>{si.flushSync(()=>{o(x)})},[]),m=C.useMemo(()=>[...e.plugins??[],f,RM(h)],[e.plugins,f,h]);function w(x){si.flushSync(()=>{e.state||u(M=>M.apply(x)),e.dispatchTransaction&&e.dispatchTransaction.call(this,x)})}const g=document.createElement("div"),y=C.useRef(new dd(void 0,[],c.doc,[],_.empty,g,null,g)),S={...e,state:c,plugins:m,dispatchTransaction:w,docView:y.current};return C.useEffect(()=>()=>{t==null||t.destroy()},[t]),C.useLayoutEffect(()=>{if(t&&t.dom!==n&&r(null),!!n&&!t){const x=new tE({mount:n},S);r(x),x.dom.addEventListener("compositionend",s);return}}),t==null||t.pureSetProps(S),C.useMemo(()=>({view:t,state:c,registerEventListener:d,unregisterEventListener:p,cursorWrapper:i,docViewDescRef:y}),[t,c,d,p,i])}function oE(n){C.useLayoutEffect(()=>{n==null||n.domObserver.selectionToDOM(),n==null||n.runPendingEffects()},[n,n==null?void 0:n.props])}function sE({children:n}){const e=C.useRef(new Set).current,t=C.useRef(new Set).current,r=C.useRef(!1),i=J1(),o=C.useRef(!0),s=C.useCallback(()=>{o.current||(i(),o.current=!0)},[i]),l=C.useCallback(a=>{let u;const c=()=>{u=a()};return e.add(c),s(),()=>{e.delete(c),u&&(r.current?(t.add(u),s()):u())}},[e,t,s]);return C.useLayoutEffect(()=>(o.current=!1,e.forEach(a=>a()),e.clear(),()=>{t.forEach(a=>a()),t.clear()})),C.useLayoutEffect(()=>(r.current=!0,()=>{r.current=!1}),[]),b.jsx(b1.Provider,{value:l,children:n})}const ht=C.createContext([]);function _1(n,e,t,r,i,o,s){const l=C.useRef(o),a=C.useContext(ht),u=[];return C.useLayoutEffect(()=>{if(!n||!t.current)return;const c=u[0];l.current?(l.current.parent=void 0,l.current.children=u,l.current.node=n,l.current.outerDeco=i,l.current.innerDeco=r,l.current.dom=(e==null?void 0:e.current)??t.current,l.current.dom.pmViewDesc=l.current,l.current.contentDOM=(s==null?void 0:s.current)??l.current.contentDOM??(c==null?void 0:c.dom.parentElement)??null,l.current.nodeDOM=t.current):l.current=new dd(void 0,u,n,i,r,(e==null?void 0:e.current)??t.current,(c==null?void 0:c.dom.parentElement)??null,t.current),a.push(l.current);for(const f of u)f.parent=l.current}),u}function lE(n,e){return n.type.side-e.type.side}function aE(n,e,t,r){const i=e.locals(n);let o=0;if(i.length==0){for(let u=0;uo;)l.push(i[s++]);let d=o+c.nodeSize;if(c.isText){let h=d;s!h.inline):l.slice();r(c,p,e.forChild(o,c),o,f),o=d}}function fa(){const{state:n}=C.useContext(es);return n}function W1(){const n=fa();return Vo.getState(n)}var U1={exports:{}};/*! +`),c&&h==p.nodeValue.length)for(let m=p,w;m;m=m.parentNode){if(w=m.nextSibling){w.nodeName=="BR"&&(l=a={node:w.parentNode,offset:on(w)+1});break}const g=m.pmViewDesc;if(g&&g.node&&g.node.isBlock)break}}else{const m=p.childNodes[h-1];c=m&&(m.nodeName=="BR"||m.contentEditable=="false")}}if(Ne.gecko&&u.focusNode&&u.focusNode!=a.node&&u.focusNode.nodeType==1){const p=u.focusNode.childNodes[u.focusOffset];p&&p.contentEditable=="false"&&(i=!0)}if(!(i||c&&Ne.safari)&&Ul(l.node,l.offset,u.anchorNode,u.anchorOffset)&&Ul(a.node,a.offset,u.focusNode,u.focusOffset))return;let f=!1;if((u.extend||e==t)&&!c){u.collapse(l.node,l.offset);try{e!=t&&u.extend(a.node,a.offset),f=!0}catch{}}if(!f){if(e>t){const h=l;l=a,a=h}const p=document.createRange();p.setEnd(a.node,a.offset),p.setStart(l.node,l.offset),u.removeAllRanges(),u.addRange(p)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let r=0,i=0;i=r:er){const l=r+o.border,a=s-o.border;if(e>=l&&t<=a){this.dirty=e==r||t==s?Rs:tm,e==l&&t==a&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=Jo:o.markDirty(e-l,t-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?Rs:Jo}r=s}this.dirty=Rs}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){const r=e==1?Rs:tm;t.dirtythis.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){const r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>v.empty)}return e}matchesNode(e,t,r){return this.dirty==li&&e.eq(this.node)&&XM(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}update(e,t,r,i){return!0}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}class GM extends dd{constructor(e,t,r,i,o,s,l){super(e,t,r,i,o,s,null,l)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,i){return!0}inParent(){const e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Jo)}get domAtom(){return!1}}class hd extends ts{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==li&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}function XM(n,e){if(n.length!=e.length)return!1;for(let t=0;t{u=!!a.call(this,s,l)}),u||l.defaultPrevented)return!0}return!1};e[r]=o}return new Ft({key:new Ho("@nytimes/react-prosemirror/componentEventListeners"),props:{handleDOMEvents:e}})}function eE(){const[n,e]=C.useState(new Map),t=C.useCallback((o,s)=>{const l=n.get(o)??[];l.unshift(s),n.has(o)||(n.set(o,l),e(new Map(n)))},[n]),r=C.useCallback((o,s)=>{const l=n.get(o);l==null||l.splice(l.indexOf(s),1)},[n]),i=C.useMemo(()=>ZM(n),[n]);return{registerEventListener:t,unregisterEventListener:r,componentEventListenersPlugin:i}}function J1(){const[,n]=C.useReducer(e=>e+1,0);return n}function tE(n){const e=Object.create(null);function t(r){for(const i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function nE(n,e){let t=0,r=0;for(const i in n){if(n[i]!=e[i])return!0;t++}for(const i in e)r++;return t!=r}class rE extends Av{constructor(e,t){super(e,{state:un.create({schema:t.state.schema,plugins:t.state.plugins}),plugins:t.plugins}),this.shouldUpdatePluginViews=!1,this.shouldUpdatePluginViews=!0,this._props=t,this.oldProps={state:t.state},this.state=t.state,this.domObserver.stop(),this.domObserver=new qM(this),this.domObserver.start(),this.docView.dom.replaceChildren(),this.docView=t.docView}get needsRedraw(){if(this.oldProps.state.plugins===this._props.state.plugins&&this._props.plugins===this.oldProps.plugins)return!1;const e=tE(this);return nE(this.nodeViews,e)}pureSetProps(e){this._props={...this._props,...e},this.state=this._props.state}runPendingEffects(){const e=this.props;this._props=this.oldProps,this.state=this._props.state,this.update(e)}update(e){super.update(e),this.oldProps=e}updatePluginViews(e){this.shouldUpdatePluginViews&&super.updatePluginViews(e)}destroy(){this.dom=document.createElement("div"),super.destroy()}}const iE=new Om({nodes:{doc:{content:"text*"},text:{inline:!0}}}),oE=un.create({schema:iE});function sE(n,e){const[t,r]=C.useState(null),[i,o]=C.useState(null),s=J1(),l=e.defaultState??oE,[a,u]=C.useState(l),c=e.state??a,{componentEventListenersPlugin:f,registerEventListener:d,unregisterEventListener:p}=eE(),h=C.useCallback(x=>{si.flushSync(()=>{o(x)})},[]),m=C.useMemo(()=>[...e.plugins??[],f,RM(h)],[e.plugins,f,h]);function w(x){si.flushSync(()=>{e.state||u(M=>M.apply(x)),e.dispatchTransaction&&e.dispatchTransaction.call(this,x)})}const g=document.createElement("div"),y=C.useRef(new dd(void 0,[],c.doc,[],_.empty,g,null,g)),S={...e,state:c,plugins:m,dispatchTransaction:w,docView:y.current};return C.useLayoutEffect(()=>()=>{t==null||t.destroy()},[t]),C.useLayoutEffect(()=>{if(t&&t.dom!==n&&r(null),!!n&&!t){const x=new rE({mount:n},S);r(x),x.dom.addEventListener("compositionend",s);return}}),C.useLayoutEffect(()=>{if(t!=null&&t.needsRedraw){r(null);return}else t==null||t.domObserver.selectionToDOM(),t==null||t.runPendingEffects()}),t==null||t.pureSetProps(S),C.useMemo(()=>({view:t,state:c,registerEventListener:d,unregisterEventListener:p,cursorWrapper:i,docViewDescRef:y}),[t,c,d,p,i])}function lE({children:n}){const e=C.useRef(new Set).current,t=C.useRef(new Set).current,r=C.useRef(!1),i=J1(),o=C.useRef(!0),s=C.useCallback(()=>{o.current||(i(),o.current=!0)},[i]),l=C.useCallback(a=>{let u;const c=()=>{u=a()};return e.add(c),s(),()=>{e.delete(c),u&&(r.current?(t.add(u),s()):u())}},[e,t,s]);return C.useLayoutEffect(()=>(o.current=!1,e.forEach(a=>a()),e.clear(),()=>{t.forEach(a=>a()),t.clear()})),C.useLayoutEffect(()=>(r.current=!0,()=>{r.current=!1}),[]),b.jsx(b1.Provider,{value:l,children:n})}const ht=C.createContext([]);function _1(n,e,t,r,i,o,s){const l=C.useRef(o),a=C.useContext(ht),u=[];return C.useLayoutEffect(()=>{if(!n||!t.current)return;const c=u[0];l.current?(l.current.parent=void 0,l.current.children=u,l.current.node=n,l.current.outerDeco=i,l.current.innerDeco=r,l.current.dom=(e==null?void 0:e.current)??t.current,l.current.dom.pmViewDesc=l.current,l.current.contentDOM=(s==null?void 0:s.current)??l.current.contentDOM??(c==null?void 0:c.dom.parentElement)??null,l.current.nodeDOM=t.current):l.current=new dd(void 0,u,n,i,r,(e==null?void 0:e.current)??t.current,(c==null?void 0:c.dom.parentElement)??null,t.current),a.push(l.current);for(const f of u)f.parent=l.current}),u}function aE(n,e){return n.type.side-e.type.side}function uE(n,e,t,r){const i=e.locals(n);let o=0;if(i.length==0){for(let u=0;uo;)l.push(i[s++]);let d=o+c.nodeSize;if(c.isText){let h=d;s!h.inline):l.slice();r(c,p,e.forChild(o,c),o,f),o=d}}function fa(){const{state:n}=C.useContext(es);return n}function W1(){const n=fa();return Vo.getState(n)}var U1={exports:{}};/*! Copyright (c) 2018 Jed Watson. Licensed under the MIT License (MIT), see http://jedwatson.github.io/classnames -*/(function(n){(function(){var e={}.hasOwnProperty;function t(){for(var r=[],i=0;i{var t;return((t=e[1])==null?void 0:t.toUpperCase())??""})}function dE(n){const e=new CSSStyleSheet;e.insertRule(`* { ${n} }`);const r=e.cssRules[0].style,i={};for(let o=0;o0&&(e.step=r);break}case"disabled":{e.disabled=r!=null;break}case"rows":{const i=parseInt(r,10);Number.isNaN(i)||(e.rows=r);break}default:{e[t]=r;break}}return e}const pd=C.forwardRef(function({outputSpec:e,children:t,...r},i){if(typeof e=="string")return b.jsx(b.Fragment,{children:e});if(!Array.isArray(e))throw new Error("@nytimes/react-prosemirror only supports strings and arrays in toDOM");const s=e[0].replace(" ",":"),l=e[1];let a={ref:i,...r},u=1;l&&typeof l=="object"&&l.nodeType==null&&!Array.isArray(l)&&(u=2,a=H1(j1(l),a));const c=[];for(let f=u;fu)throw new RangeError("Content hole must be the only child of its parent node");return C.createElement(s,a,t)}c.push(b.jsx(pd,{ref:void 0,outputSpec:d,children:t}))}return C.createElement(s,a,...c)}),K1=C.forwardRef(function({mark:e,children:t},r){var a,u;const i=C.useContext(ht),o=[],s=C.useRef(null);C.useImperativeHandle(r,()=>s.current,[]);const l=(u=(a=e.type.spec).toDOM)==null?void 0:u.call(a,e,!0);if(!l)throw new Error(`Mark spec for ${e.type.name} is missing toDOM`);return C.useLayoutEffect(()=>{if(!s.current)return;const c=o[0],f=new YM(void 0,o,e,s.current,(c==null?void 0:c.dom.parentElement)??s.current);i.push(f);for(const d of o)d.parent=f}),b.jsx(pd,{ref:s,outputSpec:l,children:b.jsx(ht.Provider,{value:o,children:t})})});function hE({widget:n,pos:e}){const t=C.useContext(ht),r=C.useRef(null),i=C.useRef(e);return i.current=e,I1(o=>{if(!r.current)return;const s=n.type.toDOM;let l=typeof s=="function"?s(o,()=>i.current):s;if(!n.type.spec.raw){if(l.nodeType!=1){const a=document.createElement("span");a.appendChild(l),l=a}l.contentEditable="false",l.classList.add("ProseMirror-widget")}r.current.firstElementChild!==l&&r.current.replaceChildren(l)}),C.useLayoutEffect(()=>{if(!r.current)return;const o=new fd(void 0,n,r.current);t.push(o)}),b.jsx("span",{ref:r})}function q1({outerDeco:n,pos:e,node:t,innerDeco:r,...i}){var D,R;const o=C.useRef(null),s=C.useRef(null),l=C.useRef(null),a=C.useRef(t),u=C.useRef(n),c=C.useRef(r),f=C.useRef(e);f.current=e;const d=C.useRef(null),p=C.useRef(null),h=fa(),{nodeViews:m}=C.useContext(T1),{view:w}=C.useContext(es);let g=null;const y=m[t.type.name],S=w==null?void 0:w.someProp("nodeViews",O=>O==null?void 0:O[t.type.name]);C.useLayoutEffect(()=>{if(!p.current||!d.current)return;const{dom:O}=p.current;return s.current=d.current,d.current.appendChild(O),()=>{var I,ne;(ne=(I=p.current)==null?void 0:I.destroy)==null||ne.call(I)}},[]),C.useLayoutEffect(()=>{if(!S||!p.current)return;const{destroy:O,update:I}=p.current;if(((I==null?void 0:I.call(p.current,t,n,r))??!0)||(O==null||O.call(p.current),!d.current))return;a.current=t,u.current=n,c.current=r,p.current=S(a.current,w,()=>f.current,u.current,c.current);const{dom:Lt}=p.current;s.current=d.current,d.current.appendChild(Lt)},[S,w,r,t,n]);const x=_1(t,o,s,r,n,void 0,l);if(y)g=b.jsx(y,{...i,ref:s,nodeProps:{node:t,pos:e,decorations:n,innerDecorations:r,isSelected:h.selection instanceof z&&h.selection.node===t},children:b.jsx(co,{pos:e,node:t,innerDecorations:r})});else if(S){p.current||(p.current=S(a.current,w,()=>f.current,u.current,c.current));const{contentDOM:O}=p.current;l.current=O??null,g=C.createElement(t.isInline?"span":"div",{ref:d,contentEditable:!!O,suppressContentEditableWarning:!0},O&&si.createPortal(b.jsx(co,{pos:e,node:t,innerDecorations:r}),O))}else{const O=(R=(D=t.type.spec).toDOM)==null?void 0:R.call(D,t);O&&(g=b.jsx(pd,{...i,ref:s,outputSpec:O,children:b.jsx(co,{pos:e,node:t,innerDecorations:r})}))}if(!g)throw new Error(`Node spec for ${t.type.name} is missing toDOM`);const M=C.cloneElement(n.reduce(md,g),n.some(O=>O.type.attrs.nodeName)?{ref:o}:void 0),E=t.marks.reduce((O,I)=>b.jsx(K1,{mark:I,children:O}),M);return b.jsx(ht.Provider,{value:x,children:C.cloneElement(E,t.marks.length||n.some(O=>O.type.attrs.nodeName)?{ref:o}:void 0)})}function pE(){const n=C.useContext(ht),e=C.useRef(null),[t,r]=C.useState(!1);return C.useLayoutEffect(()=>{var s;const i=n[n.length-1];if((Ne.safari||Ne.chrome)&&((s=i==null?void 0:i.dom)==null?void 0:s.contentEditable)=="false"){r(!0);return}if(!e.current)return;const o=new hd(void 0,[],e.current,null);n.push(o)}),t?b.jsx("img",{ref:e,className:"ProseMirror-separator"}):null}class mE extends C.Component{constructor(){super(...arguments),this.viewDescRef=null}updateEffect(){const{decorations:e,siblingDescriptors:t,node:r}=this.props,i=si.findDOMNode(this);if(!i)return;let o=i;for(;o.firstChild;)o=o.firstChild;!this.viewDescRef||this.viewDescRef instanceof QM?this.viewDescRef=new GM(void 0,[],r,e,_.empty,i,o):(this.viewDescRef.parent=void 0,this.viewDescRef.children=[],this.viewDescRef.node=r,this.viewDescRef.outerDeco=e,this.viewDescRef.innerDeco=_.empty,this.viewDescRef.dom=i,this.viewDescRef.dom.pmViewDesc=this.viewDescRef,this.viewDescRef.nodeDOM=o),t.push(this.viewDescRef)}componentDidMount(){this.updateEffect()}componentDidUpdate(){this.updateEffect()}render(){const{node:e,decorations:t}=this.props;return t.reduce(md,e.text)}}function gE(){const n=C.useContext(ht),e=C.useRef(null);return C.useLayoutEffect(()=>{if(!e.current)return;const t=new hd(void 0,[],e.current,null);n.push(t)}),b.jsx("br",{ref:e,className:"ProseMirror-trailingBreak"})}function yE({widget:n,pos:e}){const t=C.useContext(ht),r=C.useRef(null);C.useLayoutEffect(()=>{if(!r.current)return;const o=new fd(void 0,n,r.current);t.push(o)});const{Component:i}=n.type;return i&&b.jsx(i,{ref:r,widget:n,pos:e,contentEditable:!1})}function md(n,e){const{nodeName:t,...r}=e.type.attrs,i=j1(r);return t||typeof n=="string"?C.createElement(t??"span",i,n):C.cloneElement(n,H1(n.props,i))}function _c({innerPos:n,childViews:e}){const{view:t}=C.useContext(es),r=fa(),i=W1(),o=e.reduce((s,l)=>{var c;const a=s[s.length-1];if(!a)return[[l]];const u=a[a.length-1];return u?!l.marks.length&&!u.marks.length||l.marks.length&&u.marks.length&&((c=l.marks[0])!=null&&c.eq(u.marks[0]))?[...s.slice(0,s.length-1),[...a.slice(0,a.length),l]]:[...s,[l]]:[...s.slice(0,s.length),[l]]},[]);return b.jsx(b.Fragment,{children:o.map(s=>{const l=s[0];if(!l)return null;const a=l.marks[0];return a?b.jsx(K1,{mark:a,children:b.jsx(_c,{innerPos:n,childViews:s.map(u=>({...u,marks:u.marks.slice(1)}))},uo(r==null?void 0:r.doc,n,l,i==null?void 0:i.posToKey))},uo(r==null?void 0:r.doc,n,l,i==null?void 0:i.posToKey)):s.map(u=>{const c=n+u.offset,f=u.type==="widget"?b.jsx(yE,{widget:u.widget,pos:c}):u.type==="native-widget"?b.jsx(hE,{widget:u.widget,pos:c}):u.node.isText?b.jsx(ht.Consumer,{children:d=>b.jsx(mE,{view:t,node:u.node,pos:c,siblingDescriptors:d,decorations:u.outerDeco})}):b.jsx(q1,{node:u.node,pos:c,outerDeco:u.outerDeco,innerDeco:u.innerDeco});return C.cloneElement(f,{key:uo(r.doc,n,u,i==null?void 0:i.posToKey)})})})})}function uo(n,e,t,r){const i=e+t.offset,o=r==null?void 0:r.get(i);if(t.type==="widget"||t.type==="native-widget")return t.widget.type.spec.key?t.widget.type.spec.key:(console.warn(`Widget at position ${i} doesn't have a key specified. This has negative performance implications.`),`${o}-${t.index}`);if(o)return o;if(!n)return i;const s=n.resolve(i).start()-1,l=r==null?void 0:r.get(s);return l?`${l}-${t.offset}`:i}function SE(n){const e=n[n.length-1];if((e==null?void 0:e.type)!=="widget"&&(e==null?void 0:e.type)!=="native-widget"||e.widget.type.side>=0)return;let t=null;for(let i=n.length-2;i>=0;i--){const o=n[i];if((o==null?void 0:o.type)==="node"){t=o;break}}if(!t||!t.node.isInline)return;const r=t.marks;e.marks=e.marks.reduce((i,o)=>o.addToSet(i),r)}function wE(n){const e=n[n.length-1];if((e==null?void 0:e.type)!=="node"||!e.node.isInline)return;const t=e.marks;for(let r=n.length-2;r>=0;r--){const i=n[r];if((i==null?void 0:i.type)!=="widget"&&(i==null?void 0:i.type)!=="native-widget"||i.widget.type.side<0)break;i.marks=i.marks.reduce((o,s)=>s.addToSet(o),t)}}function kE(n,e,t,r){return n.length?n.every(i=>i.type!=="node"||i.node.isInline)?[b.jsx(_c,{childViews:n,innerPos:e},uo(t,e,n[0],r))]:n.map(i=>{if(i.type==="node"){const o=e+i.offset,s=(r==null?void 0:r.get(o))??o;return b.jsx(q1,{outerDeco:i.outerDeco,node:i.node,innerDeco:i.innerDeco,pos:o},s)}else return b.jsx(_c,{childViews:[i],innerPos:e},uo(t,e,i,r))}):[]}function co({pos:n,node:e,innerDecorations:t}){const r=fa(),i=W1();if(!e)return null;const o=n+1,s=[];aE(e,t,(u,c,f,d)=>{const p=u.type.spec.marks??[];c?s.push({type:"native-widget",widget:u,marks:p,offset:f,index:d}):s.push({type:"widget",widget:u,marks:p,offset:f,index:d}),SE(s)},(u,c,f,d)=>{s.push({type:"node",node:u,marks:u.marks,innerDeco:f,outerDeco:c,offset:d}),wE(s)});const l=kE(s,o,r.doc,i==null?void 0:i.posToKey),a=s[s.length-1];return(!a||a.type!=="node"||a.node.isInline&&!a.node.isText||/\n$/.test(a.node.text))&&l.push(b.jsx(pE,{},"trailing-hack-img"),b.jsx(gE,{},"trailing-hack-br")),b.jsx(b.Fragment,{children:l})}const vE=C.forwardRef(function({className:e,node:t,innerDeco:r,outerDeco:i,as:o,viewDesc:s,...l},a){const u=C.useRef(null);C.useImperativeHandle(a,()=>u.current,[]);const c=_1(t,u,u,r,i,s),f={...l,ref:u,className:e,suppressContentEditableWarning:!0},d=o?C.cloneElement(o,f,b.jsx(ht.Provider,{value:c,children:b.jsx(co,{pos:-1,node:t,innerDecorations:r})})):C.createElement("div",f,b.jsx(ht.Provider,{value:c,children:b.jsx(co,{pos:-1,node:t,innerDecorations:r})}));if(!t)return d;const p=i.filter(m=>!m.inline);return p.length?p.reduce(md,d):d}),Q1=C.createContext(null);function xE({as:n,...e},t){const r=C.useRef(null),{setMount:i,...o}=C.useContext(Q1);return C.useImperativeHandle(t,()=>r.current,[]),b.jsx(ht.Provider,{value:[],children:b.jsx(vE,{ref:s=>{r.current=s,i(s)},...e,...o,as:n})})}const CE=C.forwardRef(xE);function NE({className:n,children:e,nodeViews:t={},customNodeViews:r,...i}){var c;const[o,s]=C.useState(null),l=iE(o,{...i,nodeViews:r});oE(l.view);const a=l.view?kM(l.view,l.cursorWrapper):_.empty,u=l.view?gM(l.view):[];return b.jsx(es.Provider,{value:l,children:b.jsx(T1.Provider,{value:{nodeViews:t},children:b.jsx(Q1.Provider,{value:{className:n,setMount:s,node:(c=l.view)==null?void 0:c.state.doc,innerDeco:a,outerDeco:u,viewDesc:l.docViewDescRef.current},children:e})})})}function ME(n){return b.jsx(sE,{children:b.jsx(NE,{...n})})}const J=new Om({nodes:{doc:{content:"block+"},paragraph:{group:"block",content:"inline*",toDOM(){return["p",0]}},...Px({cellContent:"inline*",cellAttributes:{},tableGroup:"block"}),footnote:{group:"inline",content:"text*",inline:!0,atom:!0,attrs:{number:{default:0}}},list:{group:"block",content:"list_item+",toDOM(){return["ul",0]}},list_item:{content:"paragraph+",toDOM(){return["li",0]}},image:{group:"block",toDOM(){return["div",["img",{src:"https://smoores.gitlab.io/storyteller/img/Storyteller_Logo.png",height:150,width:150}]]}},text:{group:"inline"}},marks:{em:{toDOM(){return["em",0]}},strong:{toDOM(){return["strong",0]}}}}),EE=un.create({schema:J,doc:J.nodes.doc.create({},[J.nodes.paragraph.create({},[J.text("This ",[J.marks.em.create()]),J.text("is",[J.marks.em.create(),J.marks.strong.create()]),J.text(" the first paragraph")]),J.nodes.paragraph.create({},[J.text("This is the second paragraph"),J.nodes.footnote.create({number:1},J.text("Footnote"))]),J.nodes.paragraph.create(),J.nodes.image.create(),J.nodes.image.create(),J.nodes.paragraph.create({},J.text("This is the third paragraph 🫵")),J.nodes.table.create({},[J.nodes.table_row.create({},[J.nodes.table_header.create({},J.text("h1")),J.nodes.table_header.create({},J.text("h2"))]),J.nodes.table_row.create({},[J.nodes.table_cell.create({},J.text("c1")),J.nodes.table_cell.create({},J.text("c2"))])])]),plugins:[TM(),Zv({rules:[ex(/^\s*([-+*])\s$/,J.nodes.list)]}),eC(),dC()]}),OE=C.forwardRef(function({children:e,nodeProps:t,...r},i){return b.jsx("p",{ref:i,...r,children:e})}),DE=C.forwardRef(function({children:e,nodeProps:t,...r},i){return b.jsx("ul",{ref:i,...r,children:e})}),TE=C.forwardRef(function({children:e,nodeProps:t,...r},i){return b.jsx("li",{ref:i,...r,children:e})}),RE=C.forwardRef(function({nodeProps:e,...t},r){return b.jsx("span",{ref:r,...t,suppressContentEditableWarning:!0,contentEditable:"false",children:b.jsx("button",{children:e.node.attrs.number})})}),AE=C.forwardRef(function({widget:e,pos:t,...r},i){return b.jsx("span",{...r,ref:i,style:{display:"block",backgroundColor:"blue",width:"4px",height:"4px",position:"absolute",transform:"translateX(-2px)"},children:"Widget"})}),bE=new Ft({view(n){const e=n.coordsAtPos(n.state.selection.from),t=document.createElement("div");return t.style.width="4px",t.style.height="4px",t.style.position="absolute",t.style.top=`${e.top-2}px`,t.style.left=`${e.left-2}px`,t.style.backgroundColor="blue",document.body.appendChild(t),{update(r){const i=r.coordsAtPos(r.state.selection.from);t.style.top=`${i.top-2}px`,t.style.left=`${i.left-2}px`},destroy(){document.body.removeChild(t)}}}});new Ft({props:{decorations(n){return _.create(n.doc,[z1(n.selection.from,AE,{side:0,key:"widget-plugin-widget"})])}},view(n){const e=n.coordsAtPos(n.state.selection.from),t=document.createElement("div");return t.style.width="4px",t.style.height="4px",t.style.position="absolute",t.style.top=`${e.top-2}px`,t.style.left=`${e.left-2}px`,t.style.backgroundColor="blue",document.body.appendChild(t),{update(r){const i=r.coordsAtPos(r.state.selection.from);t.style.top=`${i.top-2}px`,t.style.left=`${i.left-2}px`},destroy(){document.body.removeChild(t)}}}});const IE=[ix({...Vw,"Mod-i":Vd(J.marks.em),"Mod-b":Vd(J.marks.strong)}),bE,Fv()],zE={paragraph:()=>{const n=document.createElement("p");return{dom:n,contentDOM:n}}};function PE(){const[n,e]=C.useState(EE),[t,r]=C.useState(!0);return b.jsxs("main",{children:[b.jsx("h1",{children:"React ProseMirror Demo"}),b.jsxs("button",{onClick:()=>{t?r(i=>!i):window.location.reload()},children:["Switch to"," ",t?"ProseMirror node views":"React node views (requires reload)"]}),b.jsx(ME,{className:"ProseMirror",state:n,dispatchTransaction:function(i){e(o=>o.apply(i))},plugins:IE,nodeViews:t?{paragraph:OE,list:DE,list_item:TE,footnote:RE}:void 0,customNodeViews:t?void 0:zE,children:b.jsx(CE,{as:b.jsx("article",{})})},`${t}`)]})}const FE=D1(document.getElementById("root"));FE.render(b.jsx(C.StrictMode,{children:b.jsx(PE,{})})); +*/(function(n){(function(){var e={}.hasOwnProperty;function t(){for(var r=[],i=0;i{var t;return((t=e[1])==null?void 0:t.toUpperCase())??""})}function hE(n){const e=new CSSStyleSheet;e.insertRule(`* { ${n} }`);const r=e.cssRules[0].style,i={};for(let o=0;o0&&(e.step=r);break}case"disabled":{e.disabled=r!=null;break}case"rows":{const i=parseInt(r,10);Number.isNaN(i)||(e.rows=r);break}default:{e[t]=r;break}}return e}const pd=C.forwardRef(function({outputSpec:e,children:t,...r},i){if(typeof e=="string")return b.jsx(b.Fragment,{children:e});if(!Array.isArray(e))throw new Error("@nytimes/react-prosemirror only supports strings and arrays in toDOM");const s=e[0].replace(" ",":"),l=e[1];let a={ref:i,...r},u=1;l&&typeof l=="object"&&l.nodeType==null&&!Array.isArray(l)&&(u=2,a=H1(j1(l),a));const c=[];for(let f=u;fu)throw new RangeError("Content hole must be the only child of its parent node");return C.createElement(s,a,t)}c.push(b.jsx(pd,{ref:void 0,outputSpec:d,children:t}))}return C.createElement(s,a,...c)}),K1=C.forwardRef(function({mark:e,children:t},r){var a,u;const i=C.useContext(ht),o=[],s=C.useRef(null);C.useImperativeHandle(r,()=>s.current,[]);const l=(u=(a=e.type.spec).toDOM)==null?void 0:u.call(a,e,!0);if(!l)throw new Error(`Mark spec for ${e.type.name} is missing toDOM`);return C.useLayoutEffect(()=>{if(!s.current)return;const c=o[0],f=new YM(void 0,o,e,s.current,(c==null?void 0:c.dom.parentElement)??s.current);i.push(f);for(const d of o)d.parent=f}),b.jsx(pd,{ref:s,outputSpec:l,children:b.jsx(ht.Provider,{value:o,children:t})})});function pE({widget:n,pos:e}){const t=C.useContext(ht),r=C.useRef(null),i=C.useRef(e);return i.current=e,I1(o=>{if(!r.current)return;const s=n.type.toDOM;let l=typeof s=="function"?s(o,()=>i.current):s;if(!n.type.spec.raw){if(l.nodeType!=1){const a=document.createElement("span");a.appendChild(l),l=a}l.contentEditable="false",l.classList.add("ProseMirror-widget")}r.current.firstElementChild!==l&&r.current.replaceChildren(l)}),C.useLayoutEffect(()=>{if(!r.current)return;const o=new fd(void 0,n,r.current);t.push(o)}),b.jsx("span",{ref:r})}function q1({outerDeco:n,pos:e,node:t,innerDeco:r,...i}){var D,R;const o=C.useRef(null),s=C.useRef(null),l=C.useRef(null),a=C.useRef(t),u=C.useRef(n),c=C.useRef(r),f=C.useRef(e);f.current=e;const d=C.useRef(null),p=C.useRef(null),h=fa(),{nodeViews:m}=C.useContext(T1),{view:w}=C.useContext(es);let g=null;const y=m[t.type.name],S=w==null?void 0:w.someProp("nodeViews",O=>O==null?void 0:O[t.type.name]);C.useLayoutEffect(()=>{if(!p.current||!d.current)return;const{dom:O}=p.current;return s.current=d.current,d.current.appendChild(O),()=>{var I,ne;(ne=(I=p.current)==null?void 0:I.destroy)==null||ne.call(I)}},[]),C.useLayoutEffect(()=>{if(!S||!p.current)return;const{destroy:O,update:I}=p.current;if(((I==null?void 0:I.call(p.current,t,n,r))??!0)||(O==null||O.call(p.current),!d.current))return;a.current=t,u.current=n,c.current=r,p.current=S(a.current,w,()=>f.current,u.current,c.current);const{dom:Lt}=p.current;s.current=d.current,d.current.appendChild(Lt)},[S,w,r,t,n]);const x=_1(t,o,s,r,n,void 0,l);if(y)g=b.jsx(y,{...i,ref:s,nodeProps:{node:t,pos:e,decorations:n,innerDecorations:r,isSelected:h.selection instanceof z&&h.selection.node===t},children:b.jsx(co,{pos:e,node:t,innerDecorations:r})});else if(S){p.current||(p.current=S(a.current,w,()=>f.current,u.current,c.current));const{contentDOM:O}=p.current;l.current=O??null,g=C.createElement(t.isInline?"span":"div",{ref:d,contentEditable:!!O,suppressContentEditableWarning:!0},O&&si.createPortal(b.jsx(co,{pos:e,node:t,innerDecorations:r}),O))}else{const O=(R=(D=t.type.spec).toDOM)==null?void 0:R.call(D,t);O&&(g=b.jsx(pd,{...i,ref:s,outputSpec:O,children:b.jsx(co,{pos:e,node:t,innerDecorations:r})}))}if(!g)throw new Error(`Node spec for ${t.type.name} is missing toDOM`);const M=C.cloneElement(n.reduce(md,g),n.some(O=>O.type.attrs.nodeName)?{ref:o}:void 0),E=t.marks.reduce((O,I)=>b.jsx(K1,{mark:I,children:O}),M);return b.jsx(ht.Provider,{value:x,children:C.cloneElement(E,t.marks.length||n.some(O=>O.type.attrs.nodeName)?{ref:o}:void 0)})}function mE(){const n=C.useContext(ht),e=C.useRef(null),[t,r]=C.useState(!1);return C.useLayoutEffect(()=>{var s;const i=n[n.length-1];if((Ne.safari||Ne.chrome)&&((s=i==null?void 0:i.dom)==null?void 0:s.contentEditable)=="false"){r(!0);return}if(!e.current)return;const o=new hd(void 0,[],e.current,null);n.push(o)}),t?b.jsx("img",{ref:e,className:"ProseMirror-separator"}):null}class gE extends C.Component{constructor(){super(...arguments),this.viewDescRef=null}updateEffect(){const{decorations:e,siblingDescriptors:t,node:r}=this.props,i=si.findDOMNode(this);if(!i)return;let o=i;for(;o.firstChild;)o=o.firstChild;!this.viewDescRef||this.viewDescRef instanceof QM?this.viewDescRef=new GM(void 0,[],r,e,_.empty,i,o):(this.viewDescRef.parent=void 0,this.viewDescRef.children=[],this.viewDescRef.node=r,this.viewDescRef.outerDeco=e,this.viewDescRef.innerDeco=_.empty,this.viewDescRef.dom=i,this.viewDescRef.dom.pmViewDesc=this.viewDescRef,this.viewDescRef.nodeDOM=o),t.push(this.viewDescRef)}componentDidMount(){this.updateEffect()}componentDidUpdate(){this.updateEffect()}render(){const{node:e,decorations:t}=this.props;return t.reduce(md,e.text)}}function yE(){const n=C.useContext(ht),e=C.useRef(null);return C.useLayoutEffect(()=>{if(!e.current)return;const t=new hd(void 0,[],e.current,null);n.push(t)}),b.jsx("br",{ref:e,className:"ProseMirror-trailingBreak"})}function SE({widget:n,pos:e}){const t=C.useContext(ht),r=C.useRef(null);C.useLayoutEffect(()=>{if(!r.current)return;const o=new fd(void 0,n,r.current);t.push(o)});const{Component:i}=n.type;return i&&b.jsx(i,{ref:r,widget:n,pos:e,contentEditable:!1})}function md(n,e){const{nodeName:t,...r}=e.type.attrs,i=j1(r);return t||typeof n=="string"?C.createElement(t??"span",i,n):C.cloneElement(n,H1(n.props,i))}function _c({innerPos:n,childViews:e}){const{view:t}=C.useContext(es),r=fa(),i=W1(),o=e.reduce((s,l)=>{var c;const a=s[s.length-1];if(!a)return[[l]];const u=a[a.length-1];return u?!l.marks.length&&!u.marks.length||l.marks.length&&u.marks.length&&((c=l.marks[0])!=null&&c.eq(u.marks[0]))?[...s.slice(0,s.length-1),[...a.slice(0,a.length),l]]:[...s,[l]]:[...s.slice(0,s.length),[l]]},[]);return b.jsx(b.Fragment,{children:o.map(s=>{const l=s[0];if(!l)return null;const a=l.marks[0];return a?b.jsx(K1,{mark:a,children:b.jsx(_c,{innerPos:n,childViews:s.map(u=>({...u,marks:u.marks.slice(1)}))},uo(r==null?void 0:r.doc,n,l,i==null?void 0:i.posToKey))},uo(r==null?void 0:r.doc,n,l,i==null?void 0:i.posToKey)):s.map(u=>{const c=n+u.offset,f=u.type==="widget"?b.jsx(SE,{widget:u.widget,pos:c}):u.type==="native-widget"?b.jsx(pE,{widget:u.widget,pos:c}):u.node.isText?b.jsx(ht.Consumer,{children:d=>b.jsx(gE,{view:t,node:u.node,pos:c,siblingDescriptors:d,decorations:u.outerDeco})}):b.jsx(q1,{node:u.node,pos:c,outerDeco:u.outerDeco,innerDeco:u.innerDeco});return C.cloneElement(f,{key:uo(r.doc,n,u,i==null?void 0:i.posToKey)})})})})}function uo(n,e,t,r){const i=e+t.offset,o=r==null?void 0:r.get(i);if(t.type==="widget"||t.type==="native-widget")return t.widget.type.spec.key?t.widget.type.spec.key:(console.warn(`Widget at position ${i} doesn't have a key specified. This has negative performance implications.`),`${o}-${t.index}`);if(o)return o;if(!n)return i;const s=n.resolve(i).start()-1,l=r==null?void 0:r.get(s);return l?`${l}-${t.offset}`:i}function wE(n){const e=n[n.length-1];if((e==null?void 0:e.type)!=="widget"&&(e==null?void 0:e.type)!=="native-widget"||e.widget.type.side>=0)return;let t=null;for(let i=n.length-2;i>=0;i--){const o=n[i];if((o==null?void 0:o.type)==="node"){t=o;break}}if(!t||!t.node.isInline)return;const r=t.marks;e.marks=e.marks.reduce((i,o)=>o.addToSet(i),r)}function kE(n){const e=n[n.length-1];if((e==null?void 0:e.type)!=="node"||!e.node.isInline)return;const t=e.marks;for(let r=n.length-2;r>=0;r--){const i=n[r];if((i==null?void 0:i.type)!=="widget"&&(i==null?void 0:i.type)!=="native-widget"||i.widget.type.side<0)break;i.marks=i.marks.reduce((o,s)=>s.addToSet(o),t)}}function vE(n,e,t,r){return n.length?n.every(i=>i.type!=="node"||i.node.isInline)?[b.jsx(_c,{childViews:n,innerPos:e},uo(t,e,n[0],r))]:n.map(i=>{if(i.type==="node"){const o=e+i.offset,s=(r==null?void 0:r.get(o))??o;return b.jsx(q1,{outerDeco:i.outerDeco,node:i.node,innerDeco:i.innerDeco,pos:o},s)}else return b.jsx(_c,{childViews:[i],innerPos:e},uo(t,e,i,r))}):[]}function co({pos:n,node:e,innerDecorations:t}){const r=fa(),i=W1();if(!e)return null;const o=n+1,s=[];uE(e,t,(u,c,f,d)=>{const p=u.type.spec.marks??[];c?s.push({type:"native-widget",widget:u,marks:p,offset:f,index:d}):s.push({type:"widget",widget:u,marks:p,offset:f,index:d}),wE(s)},(u,c,f,d)=>{s.push({type:"node",node:u,marks:u.marks,innerDeco:f,outerDeco:c,offset:d}),kE(s)});const l=vE(s,o,r.doc,i==null?void 0:i.posToKey),a=s[s.length-1];return(!a||a.type!=="node"||a.node.isInline&&!a.node.isText||/\n$/.test(a.node.text))&&l.push(b.jsx(mE,{},"trailing-hack-img"),b.jsx(yE,{},"trailing-hack-br")),b.jsx(b.Fragment,{children:l})}const xE=C.forwardRef(function({className:e,node:t,innerDeco:r,outerDeco:i,as:o,viewDesc:s,...l},a){const u=C.useRef(null);C.useImperativeHandle(a,()=>u.current,[]);const c=_1(t,u,u,r,i,s),f={...l,ref:u,className:e,suppressContentEditableWarning:!0},d=o?C.cloneElement(o,f,b.jsx(ht.Provider,{value:c,children:b.jsx(co,{pos:-1,node:t,innerDecorations:r})})):C.createElement("div",f,b.jsx(ht.Provider,{value:c,children:b.jsx(co,{pos:-1,node:t,innerDecorations:r})}));if(!t)return d;const p=i.filter(m=>!m.inline);return p.length?p.reduce(md,d):d}),Q1=C.createContext(null);function CE({as:n,...e},t){const r=C.useRef(null),{setMount:i,...o}=C.useContext(Q1);return C.useImperativeHandle(t,()=>r.current,[]),b.jsx(ht.Provider,{value:[],children:b.jsx(xE,{ref:s=>{r.current=s,i(s)},...e,...o,as:n})})}const NE=C.forwardRef(CE);function ME({className:n,children:e,nodeViews:t={},customNodeViews:r,...i}){var c;const[o,s]=C.useState(null),l=sE(o,{...i,nodeViews:r}),a=l.view?kM(l.view,l.cursorWrapper):_.empty,u=l.view?gM(l.view):[];return b.jsx(es.Provider,{value:l,children:b.jsx(T1.Provider,{value:{nodeViews:t},children:b.jsx(Q1.Provider,{value:{className:n,setMount:s,node:(c=l.view)==null?void 0:c.state.doc,innerDeco:a,outerDeco:u,viewDesc:l.docViewDescRef.current},children:e})})})}function EE(n){return b.jsx(lE,{children:b.jsx(ME,{...n})})}const J=new Om({nodes:{doc:{content:"block+"},paragraph:{group:"block",content:"inline*",toDOM(){return["p",0]}},...Px({cellContent:"inline*",cellAttributes:{},tableGroup:"block"}),footnote:{group:"inline",content:"text*",inline:!0,atom:!0,attrs:{number:{default:0}}},list:{group:"block",content:"list_item+",toDOM(){return["ul",0]}},list_item:{content:"paragraph+",toDOM(){return["li",0]}},image:{group:"block",toDOM(){return["div",["img",{src:"https://smoores.gitlab.io/storyteller/img/Storyteller_Logo.png",height:150,width:150}]]}},text:{group:"inline"}},marks:{em:{toDOM(){return["em",0]}},strong:{toDOM(){return["strong",0]}}}}),OE=un.create({schema:J,doc:J.nodes.doc.create({},[J.nodes.paragraph.create({},[J.text("This ",[J.marks.em.create()]),J.text("is",[J.marks.em.create(),J.marks.strong.create()]),J.text(" the first paragraph")]),J.nodes.paragraph.create({},[J.text("This is the second paragraph"),J.nodes.footnote.create({number:1},J.text("Footnote"))]),J.nodes.paragraph.create(),J.nodes.image.create(),J.nodes.image.create(),J.nodes.paragraph.create({},J.text("This is the third paragraph 🫵")),J.nodes.table.create({},[J.nodes.table_row.create({},[J.nodes.table_header.create({},J.text("h1")),J.nodes.table_header.create({},J.text("h2"))]),J.nodes.table_row.create({},[J.nodes.table_cell.create({},J.text("c1")),J.nodes.table_cell.create({},J.text("c2"))])])]),plugins:[TM(),Zv({rules:[ex(/^\s*([-+*])\s$/,J.nodes.list)]}),eC(),dC()]}),DE=C.forwardRef(function({children:e,nodeProps:t,...r},i){return b.jsx("p",{ref:i,...r,children:e})}),TE=C.forwardRef(function({children:e,nodeProps:t,...r},i){return b.jsx("ul",{ref:i,...r,children:e})}),RE=C.forwardRef(function({children:e,nodeProps:t,...r},i){return b.jsx("li",{ref:i,...r,children:e})}),AE=C.forwardRef(function({nodeProps:e,...t},r){return b.jsx("span",{ref:r,...t,suppressContentEditableWarning:!0,contentEditable:"false",children:b.jsx("button",{children:e.node.attrs.number})})}),bE=C.forwardRef(function({widget:e,pos:t,...r},i){return b.jsx("span",{...r,ref:i,style:{display:"block",backgroundColor:"blue",width:"4px",height:"4px",position:"absolute",transform:"translateX(-2px)"},children:"Widget"})}),IE=new Ft({view(n){const e=n.coordsAtPos(n.state.selection.from),t=document.createElement("div");return t.style.width="4px",t.style.height="4px",t.style.position="absolute",t.style.top=`${e.top-2}px`,t.style.left=`${e.left-2}px`,t.style.backgroundColor="blue",document.body.appendChild(t),{update(r){const i=r.coordsAtPos(r.state.selection.from);t.style.top=`${i.top-2}px`,t.style.left=`${i.left-2}px`},destroy(){document.body.removeChild(t)}}}});new Ft({props:{decorations(n){return _.create(n.doc,[z1(n.selection.from,bE,{side:0,key:"widget-plugin-widget"})])}},view(n){const e=n.coordsAtPos(n.state.selection.from),t=document.createElement("div");return t.style.width="4px",t.style.height="4px",t.style.position="absolute",t.style.top=`${e.top-2}px`,t.style.left=`${e.left-2}px`,t.style.backgroundColor="blue",document.body.appendChild(t),{update(r){const i=r.coordsAtPos(r.state.selection.from);t.style.top=`${i.top-2}px`,t.style.left=`${i.left-2}px`},destroy(){document.body.removeChild(t)}}}});const zE=[ix({...Vw,"Mod-i":Vd(J.marks.em),"Mod-b":Vd(J.marks.strong)}),IE,Fv()],PE={paragraph:()=>{const n=document.createElement("p");return{dom:n,contentDOM:n}}};function FE(){const[n,e]=C.useState(OE),[t,r]=C.useState(!0);return b.jsxs("main",{children:[b.jsx("h1",{children:"React ProseMirror Demo"}),b.jsxs("button",{onClick:()=>{t?r(i=>!i):window.location.reload()},children:["Switch to"," ",t?"ProseMirror node views":"React node views (requires reload)"]}),b.jsx(EE,{className:"ProseMirror",state:n,dispatchTransaction:function(i){e(o=>o.apply(i))},plugins:zE,nodeViews:t?{paragraph:DE,list:TE,list_item:RE,footnote:AE}:void 0,customNodeViews:t?void 0:PE,children:b.jsx(NE,{as:b.jsx("article",{})})},`${t}`)]})}const LE=D1(document.getElementById("root"));LE.render(b.jsx(C.StrictMode,{children:b.jsx(FE,{})})); diff --git a/docs/index.html b/docs/index.html index 2618f04..383eb8e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -5,7 +5,7 @@ React-ProseMirror Demo - + diff --git a/src/components/ProseMirror.tsx b/src/components/ProseMirror.tsx index ec09108..020a00f 100644 --- a/src/components/ProseMirror.tsx +++ b/src/components/ProseMirror.tsx @@ -10,12 +10,7 @@ import { EditorContext } from "../contexts/EditorContext.js"; import { NodeViewContext } from "../contexts/NodeViewContext.js"; import { computeDocDeco } from "../decorations/computeDocDeco.js"; import { viewDecorations } from "../decorations/viewDecorations.js"; -import { - ReactEditorView, - UseEditorOptions, - useEditor, -} from "../hooks/useEditor.js"; -import { usePendingViewEffects } from "../hooks/usePendingViewEffects.js"; +import { UseEditorOptions, useEditor } from "../hooks/useEditor.js"; import { LayoutGroup } from "./LayoutGroup.js"; import { NodeViewComponentProps } from "./NodeViewComponentProps.js"; @@ -53,8 +48,6 @@ function ProseMirrorInner({ nodeViews: customNodeViews, }); - usePendingViewEffects(editor.view as ReactEditorView | null); - const innerDecos = editor.view ? viewDecorations(editor.view, editor.cursorWrapper) : (DecorationSet.empty as unknown as DecorationSet); diff --git a/src/components/__tests__/ProseMirror.test.tsx b/src/components/__tests__/ProseMirror.test.tsx index f5389da..6fb9039 100644 --- a/src/components/__tests__/ProseMirror.test.tsx +++ b/src/components/__tests__/ProseMirror.test.tsx @@ -2,10 +2,22 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ import { act, render, screen } from "@testing-library/react"; import { Schema } from "prosemirror-model"; -import { EditorState } from "prosemirror-state"; -import { doc, em, hr, li, p, strong, ul } from "prosemirror-test-builder"; +import { EditorState, Plugin } from "prosemirror-state"; +import { + doc, + em, + hr, + li, + p, + schema, + strong, + ul, +} from "prosemirror-test-builder"; +import { EditorView } from "prosemirror-view"; import React, { forwardRef, useEffect, useState } from "react"; +import { useEditorEffect } from "../../hooks/useEditorEffect.js"; +import { reactKeys } from "../../plugins/reactKeys.js"; import { tempEditor } from "../../testing/editorViewTestHelpers.js"; import { NodeViewComponentProps } from "../NodeViewComponentProps.js"; import { ProseMirror } from "../ProseMirror.js"; @@ -259,4 +271,80 @@ describe("ProseMirror", () => { view.dispatch(view.state.tr.insertText("x")); expect(view).toBe(thisBinding); }); + + it("replaces the EditorView when ProseMirror would redraw", async () => { + const viewPlugin = () => + new Plugin({ + props: { + nodeViews: { + horizontal_rule() { + const dom = document.createElement("hr"); + return { + dom, + }; + }, + }, + }, + }); + + const startDoc = doc(p()); + const firstState = EditorState.create({ + doc: startDoc, + schema, + plugins: [viewPlugin(), reactKeys()], + }); + + let firstView: EditorView | null = null; + let secondView: EditorView | null = null; + + function Test() { + useEditorEffect((v) => { + if (firstView === null) { + firstView = v; + } else { + secondView = v; + } + }); + + return null; + } + + const Paragraph = forwardRef( + function Paragraph({ nodeProps, children, ...props }, ref) { + return ( +

+ {children} +

+ ); + } + ); + + const { rerender } = render( + + + + + ); + + expect(() => screen.getByTestId("node-view")).not.toThrow(); + + const secondState = EditorState.create({ + doc: startDoc, + schema, + plugins: [viewPlugin(), reactKeys()], + }); + + rerender( + + + + + ); + + expect(() => screen.getByTestId("node-view")).not.toThrow(); + + expect(firstView).not.toBeNull(); + expect(secondView).not.toBeNull(); + expect(firstView === secondView).toBeFalsy(); + }); }); diff --git a/src/hooks/useEditor.ts b/src/hooks/useEditor.ts index 7f4cd6d..168b06e 100644 --- a/src/hooks/useEditor.ts +++ b/src/hooks/useEditor.ts @@ -6,15 +6,10 @@ import { DirectEditorProps, EditorProps, EditorView, + MarkViewConstructor, + NodeViewConstructor, } from "prosemirror-view"; -import { - useCallback, - useEffect, - useLayoutEffect, - useMemo, - useRef, - useState, -} from "react"; +import { useCallback, useLayoutEffect, useMemo, useRef, useState } from "react"; import { flushSync } from "react-dom"; import { DOMNode } from "../dom.js"; @@ -25,6 +20,34 @@ import { NodeViewDesc } from "../viewdesc.js"; import { useComponentEventListeners } from "./useComponentEventListeners.js"; import { useForceUpdate } from "./useForceUpdate.js"; +type NodeViewSet = { + [name: string]: NodeViewConstructor | MarkViewConstructor; +}; + +function buildNodeViews(view: ReactEditorView) { + const result: NodeViewSet = Object.create(null); + function add(obj: NodeViewSet) { + for (const prop in obj) + if (!Object.prototype.hasOwnProperty.call(result, prop)) + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + result[prop] = obj[prop]!; + } + view.someProp("nodeViews", add); + view.someProp("markViews", add); + return result; +} + +function changedNodeViews(a: NodeViewSet, b: NodeViewSet) { + let nA = 0, + nB = 0; + for (const prop in a) { + if (a[prop] != b[prop]) return true; + nA++; + } + for (const _ in b) nB++; + return nA != nB; +} + // @ts-expect-error We're making use of knowledge of internal methods here export class ReactEditorView extends EditorView { private shouldUpdatePluginViews = false; @@ -76,6 +99,33 @@ export class ReactEditorView extends EditorView { this.docView = props.docView; } + /** + * Whether the EditorView's updateStateInner method thinks that the + * docView needs to be blown away and redrawn. + * + * @privateremarks + * + * When ProseMirror View detects that the EditorState has been reconfigured + * to provide new custom node views, it calls an internal function that + * we can't override in order to recreate the entire editor DOM. + * + * This property mimics that check, so that we can replace the EditorView + * with another of our own, preventing ProseMirror View from taking over + * DOM management responsibility. + */ + get needsRedraw() { + if ( + this.oldProps.state.plugins === this._props.state.plugins && + this._props.plugins === this.oldProps.plugins + ) { + return false; + } + + const newNodeViews = buildNodeViews(this); + // @ts-expect-error Internal property + return changedNodeViews(this.nodeViews, newNodeViews); + } + /** * Like setProps, but without executing any side effects. * Safe to use in a component render method. @@ -239,7 +289,7 @@ export function useEditor( docView: docViewDescRef.current, }; - useEffect(() => { + useLayoutEffect(() => { return () => { view?.destroy(); }; @@ -266,6 +316,25 @@ export function useEditor( } }); + // This rule is concerned about infinite updates due to the + // call to setView. These calls are deliberately conditional, + // so this is not a concern. + // eslint-disable-next-line react-hooks/exhaustive-deps + useLayoutEffect(() => { + // If ProseMirror View is about to redraw the entire document's + // DOM, clear the EditorView and reconstruct another, instead. + // This only happens when a newly instantiated EditorState has + // been provided. + if (view?.needsRedraw) { + setView(null); + return; + } else { + // @ts-expect-error Internal property - domObserver + view?.domObserver.selectionToDOM(); + view?.runPendingEffects(); + } + }); + view?.pureSetProps(directEditorProps); return useMemo( diff --git a/src/hooks/usePendingViewEffects.ts b/src/hooks/usePendingViewEffects.ts deleted file mode 100644 index d561343..0000000 --- a/src/hooks/usePendingViewEffects.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { useLayoutEffect } from "react"; - -import { ReactEditorView } from "./useEditor.js"; - -export function usePendingViewEffects(view: ReactEditorView | null) { - useLayoutEffect(() => { - // @ts-expect-error Internal property - domObserver - view?.domObserver.selectionToDOM(); - view?.runPendingEffects(); - }, [view, view?.props]); -} diff --git a/src/testing/editorViewTestHelpers.tsx b/src/testing/editorViewTestHelpers.tsx index 027305c..0bdd53d 100644 --- a/src/testing/editorViewTestHelpers.tsx +++ b/src/testing/editorViewTestHelpers.tsx @@ -73,7 +73,7 @@ export function tempEditor({ function Test() { useEditorEffect((v) => { view = v; - }, []); + }); return null; } @@ -98,6 +98,7 @@ export function tempEditor({ ); + return view; } return {