diff --git a/example/src/Examples/Advanced/AdvancedRichText.tsx b/example/src/Examples/Advanced/AdvancedRichText.tsx index f06c38d..80a42f3 100644 --- a/example/src/Examples/Advanced/AdvancedRichText.tsx +++ b/example/src/Examples/Advanced/AdvancedRichText.tsx @@ -17,13 +17,14 @@ import { TenTapStartKit, Toolbar, UnderlineBridge, - useEditor, + useNativeEditor, } from 'tentap'; // @ts-ignore import AdvancedEditor from './Editor/build/index.html'; import { CustomKeyboard } from '../../../../src/RichText/Keyboard'; import { ColorKeyboard } from '../../../../src/RichText/Keyboard/ColorKeyboard'; +import { BubbleMenuBridge } from './BubbleMenuBridge'; const exampleStyles = StyleSheet.create({ fullScreen: { @@ -37,8 +38,8 @@ const exampleStyles = StyleSheet.create({ }); export const Advanced = ({}: NativeStackScreenProps) => { - const editor = useEditor({ - initialContent: `

This is a basic example of implementing images.

s

`, + const editor = useNativeEditor({ + initialContent: `

This is a basic example of implementing images.

s sdfdsf fd dsfd ssdfd dsfdsfdsfdsfd

`, plugins: [ TenTapStartKit, UnderlineBridge, @@ -47,6 +48,7 @@ export const Advanced = ({}: NativeStackScreenProps) => { LinkBridge, ColorBridge, HighlightBridge, + BubbleMenuBridge, ], }); const TapRef = useRef(null); @@ -58,6 +60,7 @@ export const Advanced = ({}: NativeStackScreenProps) => { diff --git a/example/src/Examples/Advanced/BubbleMenuBridge.ts b/example/src/Examples/Advanced/BubbleMenuBridge.ts new file mode 100644 index 0000000..045584c --- /dev/null +++ b/example/src/Examples/Advanced/BubbleMenuBridge.ts @@ -0,0 +1,33 @@ +import { TenTapBridge } from 'tentap'; + +type BubbleEditorState = {}; + +type BubbleEditorInstance = {}; + +declare module 'tentap' { + interface EditorNativeState extends BubbleEditorState {} + interface EditorInstance extends BubbleEditorInstance {} +} + +export enum BubbleEditorActionType { + OnComment = 'new-comment', +} + +type BubbleMessage = { + type: BubbleEditorActionType.OnComment; +}; + +export const BubbleMenuBridge = new TenTapBridge< + BubbleEditorState, + BubbleEditorInstance, + BubbleMessage +>({ + forceName: 'sdfs', + onEditorMessage: (message: BubbleMessage) => { + if (message.type === BubbleEditorActionType.OnComment) { + console.log('ddddd333'); + return true; + } + return true; + }, +}); diff --git a/example/src/Examples/Advanced/Editor/AdvancedEditor.tsx b/example/src/Examples/Advanced/Editor/AdvancedEditor.tsx index 2617465..f8bd709 100644 --- a/example/src/Examples/Advanced/Editor/AdvancedEditor.tsx +++ b/example/src/Examples/Advanced/Editor/AdvancedEditor.tsx @@ -1,9 +1,28 @@ import React from 'react'; -import { EditorContent } from '@tiptap/react'; -import { useTenTap } from 'tentap'; +import { BubbleMenu, EditorContent } from '@tiptap/react'; +import { sendMessage, useTenTap } from 'tentap'; export const AdvancedEditor = () => { const editor = useTenTap(); - - return ; + // alert('ssss') + return ( + <> + {editor && ( + + + + )} + + + ); }; diff --git a/example/src/Examples/Advanced/Editor/build/index.html b/example/src/Examples/Advanced/Editor/build/index.html index 0d61ad6..cd50624 100644 --- a/example/src/Examples/Advanced/Editor/build/index.html +++ b/example/src/Examples/Advanced/Editor/build/index.html @@ -47,7 +47,7 @@ `+o.stack}return{value:t,source:e,stack:i,digest:null}}function Ba(t,e,n){return{value:t,source:null,stack:n??null,digest:e??null}}function qu(t,e){try{console.error(e.value)}catch(n){setTimeout(function(){throw n})}}var Kk=typeof WeakMap=="function"?WeakMap:Map;function Rg(t,e,n){n=Gt(-1,n),n.tag=3,n.payload={element:null};var r=e.value;return n.callback=function(){Vs||(Vs=!0,ic=r),qu(t,e)},n}function Ig(t,e,n){n=Gt(-1,n),n.tag=3;var r=t.type.getDerivedStateFromError;if(typeof r=="function"){var i=e.value;n.payload=function(){return r(i)},n.callback=function(){qu(t,e)}}var o=t.stateNode;return o!==null&&typeof o.componentDidCatch=="function"&&(n.callback=function(){qu(t,e),typeof r!="function"&&(On===null?On=new Set([this]):On.add(this));var s=e.stack;this.componentDidCatch(e.value,{componentStack:s!==null?s:""})}),n}function th(t,e,n){var r=t.pingCache;if(r===null){r=t.pingCache=new Kk;var i=new Set;r.set(e,i)}else i=r.get(e),i===void 0&&(i=new Set,r.set(e,i));i.has(n)||(i.add(n),t=sv.bind(null,t,e,n),e.then(t,t))}function nh(t){do{var e;if((e=t.tag===13)&&(e=t.memoizedState,e=e!==null?e.dehydrated!==null:!0),e)return t;t=t.return}while(t!==null);return null}function rh(t,e,n,r,i){return t.mode&1?(t.flags|=65536,t.lanes=i,t):(t===e?t.flags|=65536:(t.flags|=128,n.flags|=131072,n.flags&=-52805,n.tag===1&&(n.alternate===null?n.tag=17:(e=Gt(-1,1),e.tag=2,Tn(n,e,1))),n.lanes|=1),t)}var Jk=nn.ReactCurrentOwner,Ve=!1;function Ie(t,e,n,r){e.child=t===null?cg(e,null,n,r):ti(e,t.child,n,r)}function ih(t,e,n,r,i){n=n.render;var o=e.ref;return Kr(e,i),r=yd(t,e,n,r,o,i),n=kd(),t!==null&&!Ve?(e.updateQueue=t.updateQueue,e.flags&=-2053,t.lanes&=~i,tn(t,e,i)):(Y&&n&&od(e),e.flags|=1,Ie(t,e,r,i),e.child)}function oh(t,e,n,r,i){if(t===null){var o=n.type;return typeof o=="function"&&!Nd(o)&&o.defaultProps===void 0&&n.compare===null&&n.defaultProps===void 0?(e.tag=15,e.type=o,Lg(t,e,o,r,i)):(t=ys(n.type,null,r,e,e.mode,i),t.ref=e.ref,t.return=e,e.child=t)}if(o=t.child,!(t.lanes&i)){var s=o.memoizedProps;if(n=n.compare,n=n!==null?n:ro,n(s,r)&&t.ref===e.ref)return tn(t,e,i)}return e.flags|=1,t=An(o,r),t.ref=e.ref,t.return=e,e.child=t}function Lg(t,e,n,r,i){if(t!==null){var o=t.memoizedProps;if(ro(o,r)&&t.ref===e.ref)if(Ve=!1,e.pendingProps=r=o,(t.lanes&i)!==0)t.flags&131072&&(Ve=!0);else return e.lanes=t.lanes,tn(t,e,i)}return Qu(t,e,n,r,i)}function Dg(t,e,n){var r=e.pendingProps,i=r.children,o=t!==null?t.memoizedState:null;if(r.mode==="hidden")if(!(e.mode&1))e.memoizedState={baseLanes:0,cachePool:null,transitions:null},J(_r,Ge),Ge|=n;else{if(!(n&1073741824))return t=o!==null?o.baseLanes|n:n,e.lanes=e.childLanes=1073741824,e.memoizedState={baseLanes:t,cachePool:null,transitions:null},e.updateQueue=null,J(_r,Ge),Ge|=t,null;e.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=o!==null?o.baseLanes:n,J(_r,Ge),Ge|=r}else o!==null?(r=o.baseLanes|n,e.memoizedState=null):r=n,J(_r,Ge),Ge|=r;return Ie(t,e,i,n),e.child}function Pg(t,e){var n=e.ref;(t===null&&n!==null||t!==null&&t.ref!==n)&&(e.flags|=512,e.flags|=2097152)}function Qu(t,e,n,r,i){var o=We(n)?cr:be.current;return o=Zr(e,o),Kr(e,i),n=yd(t,e,n,r,o,i),r=kd(),t!==null&&!Ve?(e.updateQueue=t.updateQueue,e.flags&=-2053,t.lanes&=~i,tn(t,e,i)):(Y&&r&&od(e),e.flags|=1,Ie(t,e,n,i),e.child)}function sh(t,e,n,r,i){if(We(n)){var o=!0;Ls(e)}else o=!1;if(Kr(e,i),e.stateNode===null)ps(t,e),ag(e,n,r),Ju(e,n,r,i),r=!0;else if(t===null){var s=e.stateNode,l=e.memoizedProps;s.props=l;var a=s.context,u=n.contextType;typeof u=="object"&&u!==null?u=ft(u):(u=We(n)?cr:be.current,u=Zr(e,u));var c=n.getDerivedStateFromProps,d=typeof c=="function"||typeof s.getSnapshotBeforeUpdate=="function";d||typeof s.UNSAFE_componentWillReceiveProps!="function"&&typeof s.componentWillReceiveProps!="function"||(l!==r||a!==u)&&Yf(e,s,r,u),un=!1;var f=e.memoizedState;s.state=f,Fs(e,r,s,i),a=e.memoizedState,l!==r||f!==a||Ue.current||un?(typeof c=="function"&&(Ku(e,n,c,r),a=e.memoizedState),(l=un||Gf(e,n,l,r,f,a,u))?(d||typeof s.UNSAFE_componentWillMount!="function"&&typeof s.componentWillMount!="function"||(typeof s.componentWillMount=="function"&&s.componentWillMount(),typeof s.UNSAFE_componentWillMount=="function"&&s.UNSAFE_componentWillMount()),typeof s.componentDidMount=="function"&&(e.flags|=4194308)):(typeof s.componentDidMount=="function"&&(e.flags|=4194308),e.memoizedProps=r,e.memoizedState=a),s.props=r,s.state=a,s.context=u,r=l):(typeof s.componentDidMount=="function"&&(e.flags|=4194308),r=!1)}else{s=e.stateNode,sg(t,e),l=e.memoizedProps,u=e.type===e.elementType?l:mt(e.type,l),s.props=u,d=e.pendingProps,f=s.context,a=n.contextType,typeof a=="object"&&a!==null?a=ft(a):(a=We(n)?cr:be.current,a=Zr(e,a));var h=n.getDerivedStateFromProps;(c=typeof h=="function"||typeof s.getSnapshotBeforeUpdate=="function")||typeof s.UNSAFE_componentWillReceiveProps!="function"&&typeof s.componentWillReceiveProps!="function"||(l!==d||f!==a)&&Yf(e,s,r,a),un=!1,f=e.memoizedState,s.state=f,Fs(e,r,s,i);var p=e.memoizedState;l!==d||f!==p||Ue.current||un?(typeof h=="function"&&(Ku(e,n,h,r),p=e.memoizedState),(u=un||Gf(e,n,u,r,f,p,a)||!1)?(c||typeof s.UNSAFE_componentWillUpdate!="function"&&typeof s.componentWillUpdate!="function"||(typeof s.componentWillUpdate=="function"&&s.componentWillUpdate(r,p,a),typeof s.UNSAFE_componentWillUpdate=="function"&&s.UNSAFE_componentWillUpdate(r,p,a)),typeof s.componentDidUpdate=="function"&&(e.flags|=4),typeof s.getSnapshotBeforeUpdate=="function"&&(e.flags|=1024)):(typeof s.componentDidUpdate!="function"||l===t.memoizedProps&&f===t.memoizedState||(e.flags|=4),typeof s.getSnapshotBeforeUpdate!="function"||l===t.memoizedProps&&f===t.memoizedState||(e.flags|=1024),e.memoizedProps=r,e.memoizedState=p),s.props=r,s.state=p,s.context=a,r=u):(typeof s.componentDidUpdate!="function"||l===t.memoizedProps&&f===t.memoizedState||(e.flags|=4),typeof s.getSnapshotBeforeUpdate!="function"||l===t.memoizedProps&&f===t.memoizedState||(e.flags|=1024),r=!1)}return Gu(t,e,n,r,o,i)}function Gu(t,e,n,r,i,o){Pg(t,e);var s=(e.flags&128)!==0;if(!r&&!s)return i&&Wf(e,n,!1),tn(t,e,o);r=e.stateNode,Jk.current=e;var l=s&&typeof n.getDerivedStateFromError!="function"?null:r.render();return e.flags|=1,t!==null&&s?(e.child=ti(e,t.child,null,o),e.child=ti(e,null,l,o)):Ie(t,e,l,o),e.memoizedState=r.state,i&&Wf(e,n,!0),e.child}function zg(t){var e=t.stateNode;e.pendingContext?Uf(t,e.pendingContext,e.pendingContext!==e.context):e.context&&Uf(t,e.context,!1),hd(t,e.containerInfo)}function lh(t,e,n,r,i){return ei(),ld(i),e.flags|=256,Ie(t,e,n,r),e.child}var Yu={dehydrated:null,treeContext:null,retryLane:0};function Xu(t){return{baseLanes:t,cachePool:null,transitions:null}}function Bg(t,e,n){var r=e.pendingProps,i=Z.current,o=!1,s=(e.flags&128)!==0,l;if((l=s)||(l=t!==null&&t.memoizedState===null?!1:(i&2)!==0),l?(o=!0,e.flags&=-129):(t===null||t.memoizedState!==null)&&(i|=1),J(Z,i&1),t===null)return Uu(e),t=e.memoizedState,t!==null&&(t=t.dehydrated,t!==null)?(e.mode&1?t.data==="$!"?e.lanes=8:e.lanes=1073741824:e.lanes=1,null):(s=r.children,t=r.fallback,o?(r=e.mode,o=e.child,s={mode:"hidden",children:s},!(r&1)&&o!==null?(o.childLanes=0,o.pendingProps=s):o=Ql(s,r,0,null),t=ir(t,r,n,null),o.return=e,t.return=e,o.sibling=t,e.child=o,e.child.memoizedState=Xu(n),e.memoizedState=Yu,t):wd(e,s));if(i=t.memoizedState,i!==null&&(l=i.dehydrated,l!==null))return qk(t,e,s,r,l,i,n);if(o){o=r.fallback,s=e.mode,i=t.child,l=i.sibling;var a={mode:"hidden",children:r.children};return!(s&1)&&e.child!==i?(r=e.child,r.childLanes=0,r.pendingProps=a,e.deletions=null):(r=An(i,a),r.subtreeFlags=i.subtreeFlags&14680064),l!==null?o=An(l,o):(o=ir(o,s,n,null),o.flags|=2),o.return=e,r.return=e,r.sibling=o,e.child=r,r=o,o=e.child,s=t.child.memoizedState,s=s===null?Xu(n):{baseLanes:s.baseLanes|n,cachePool:null,transitions:s.transitions},o.memoizedState=s,o.childLanes=t.childLanes&~n,e.memoizedState=Yu,r}return o=t.child,t=o.sibling,r=An(o,{mode:"visible",children:r.children}),!(e.mode&1)&&(r.lanes=n),r.return=e,r.sibling=null,t!==null&&(n=e.deletions,n===null?(e.deletions=[t],e.flags|=16):n.push(t)),e.child=r,e.memoizedState=null,r}function wd(t,e){return e=Ql({mode:"visible",children:e},t.mode,0,null),e.return=t,t.child=e}function Jo(t,e,n,r){return r!==null&&ld(r),ti(e,t.child,null,n),t=wd(e,e.pendingProps.children),t.flags|=2,e.memoizedState=null,t}function qk(t,e,n,r,i,o,s){if(n)return e.flags&256?(e.flags&=-257,r=Ba(Error(E(422))),Jo(t,e,s,r)):e.memoizedState!==null?(e.child=t.child,e.flags|=128,null):(o=r.fallback,i=e.mode,r=Ql({mode:"visible",children:r.children},i,0,null),o=ir(o,i,s,null),o.flags|=2,r.return=e,o.return=e,r.sibling=o,e.child=r,e.mode&1&&ti(e,t.child,null,s),e.child.memoizedState=Xu(s),e.memoizedState=Yu,o);if(!(e.mode&1))return Jo(t,e,s,null);if(i.data==="$!"){if(r=i.nextSibling&&i.nextSibling.dataset,r)var l=r.dgst;return r=l,o=Error(E(419)),r=Ba(o,r,void 0),Jo(t,e,s,r)}if(l=(s&t.childLanes)!==0,Ve||l){if(r=me,r!==null){switch(s&-s){case 4:i=2;break;case 16:i=8;break;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:i=32;break;case 536870912:i=268435456;break;default:i=0}i=i&(r.suspendedLanes|s)?0:i,i!==0&&i!==o.retryLane&&(o.retryLane=i,en(t,i),wt(r,t,i,-1))}return Od(),r=Ba(Error(E(421))),Jo(t,e,s,r)}return i.data==="$?"?(e.flags|=128,e.child=t.child,e=lv.bind(null,t),i._reactRetry=e,null):(t=o.treeContext,Xe=Mn(i.nextSibling),Ze=e,Y=!0,yt=null,t!==null&&(st[lt++]=qt,st[lt++]=Qt,st[lt++]=dr,qt=t.id,Qt=t.overflow,dr=e),e=wd(e,r.children),e.flags|=4096,e)}function ah(t,e,n){t.lanes|=e;var r=t.alternate;r!==null&&(r.lanes|=e),Wu(t.return,e,n)}function Fa(t,e,n,r,i){var o=t.memoizedState;o===null?t.memoizedState={isBackwards:e,rendering:null,renderingStartTime:0,last:r,tail:n,tailMode:i}:(o.isBackwards=e,o.rendering=null,o.renderingStartTime=0,o.last=r,o.tail=n,o.tailMode=i)}function Fg(t,e,n){var r=e.pendingProps,i=r.revealOrder,o=r.tail;if(Ie(t,e,r.children,n),r=Z.current,r&2)r=r&1|2,e.flags|=128;else{if(t!==null&&t.flags&128)e:for(t=e.child;t!==null;){if(t.tag===13)t.memoizedState!==null&&ah(t,n,e);else if(t.tag===19)ah(t,n,e);else if(t.child!==null){t.child.return=t,t=t.child;continue}if(t===e)break e;for(;t.sibling===null;){if(t.return===null||t.return===e)break e;t=t.return}t.sibling.return=t.return,t=t.sibling}r&=1}if(J(Z,r),!(e.mode&1))e.memoizedState=null;else switch(i){case"forwards":for(n=e.child,i=null;n!==null;)t=n.alternate,t!==null&&_s(t)===null&&(i=n),n=n.sibling;n=i,n===null?(i=e.child,e.child=null):(i=n.sibling,n.sibling=null),Fa(e,!1,i,n,o);break;case"backwards":for(n=null,i=e.child,e.child=null;i!==null;){if(t=i.alternate,t!==null&&_s(t)===null){e.child=i;break}t=i.sibling,i.sibling=n,n=i,i=t}Fa(e,!0,n,null,o);break;case"together":Fa(e,!1,null,null,void 0);break;default:e.memoizedState=null}return e.child}function ps(t,e){!(e.mode&1)&&t!==null&&(t.alternate=null,e.alternate=null,e.flags|=2)}function tn(t,e,n){if(t!==null&&(e.dependencies=t.dependencies),hr|=e.lanes,!(n&e.childLanes))return null;if(t!==null&&e.child!==t.child)throw Error(E(153));if(e.child!==null){for(t=e.child,n=An(t,t.pendingProps),e.child=n,n.return=e;t.sibling!==null;)t=t.sibling,n=n.sibling=An(t,t.pendingProps),n.return=e;n.sibling=null}return e.child}function Qk(t,e,n){switch(e.tag){case 3:zg(e),ei();break;case 5:dg(e);break;case 1:We(e.type)&&Ls(e);break;case 4:hd(e,e.stateNode.containerInfo);break;case 10:var r=e.type._context,i=e.memoizedProps.value;J(zs,r._currentValue),r._currentValue=i;break;case 13:if(r=e.memoizedState,r!==null)return r.dehydrated!==null?(J(Z,Z.current&1),e.flags|=128,null):n&e.child.childLanes?Bg(t,e,n):(J(Z,Z.current&1),t=tn(t,e,n),t!==null?t.sibling:null);J(Z,Z.current&1);break;case 19:if(r=(n&e.childLanes)!==0,t.flags&128){if(r)return Fg(t,e,n);e.flags|=128}if(i=e.memoizedState,i!==null&&(i.rendering=null,i.tail=null,i.lastEffect=null),J(Z,Z.current),r)break;return null;case 22:case 23:return e.lanes=0,Dg(t,e,n)}return tn(t,e,n)}var _g,Zu,Hg,$g;_g=function(t,e){for(var n=e.child;n!==null;){if(n.tag===5||n.tag===6)t.appendChild(n.stateNode);else if(n.tag!==4&&n.child!==null){n.child.return=n,n=n.child;continue}if(n===e)break;for(;n.sibling===null;){if(n.return===null||n.return===e)return;n=n.return}n.sibling.return=n.return,n=n.sibling}};Zu=function(){};Hg=function(t,e,n,r){var i=t.memoizedProps;if(i!==r){t=e.stateNode,Xn(_t.current);var o=null;switch(n){case"input":i=wu(t,i),r=wu(t,r),o=[];break;case"select":i=te({},i,{value:void 0}),r=te({},r,{value:void 0}),o=[];break;case"textarea":i=Eu(t,i),r=Eu(t,r),o=[];break;default:typeof i.onClick!="function"&&typeof r.onClick=="function"&&(t.onclick=Rs)}Tu(n,r);var s;n=null;for(u in i)if(!r.hasOwnProperty(u)&&i.hasOwnProperty(u)&&i[u]!=null)if(u==="style"){var l=i[u];for(s in l)l.hasOwnProperty(s)&&(n||(n={}),n[s]="")}else u!=="dangerouslySetInnerHTML"&&u!=="children"&&u!=="suppressContentEditableWarning"&&u!=="suppressHydrationWarning"&&u!=="autoFocus"&&(Gi.hasOwnProperty(u)?o||(o=[]):(o=o||[]).push(u,null));for(u in r){var a=r[u];if(l=i!=null?i[u]:void 0,r.hasOwnProperty(u)&&a!==l&&(a!=null||l!=null))if(u==="style")if(l){for(s in l)!l.hasOwnProperty(s)||a&&a.hasOwnProperty(s)||(n||(n={}),n[s]="");for(s in a)a.hasOwnProperty(s)&&l[s]!==a[s]&&(n||(n={}),n[s]=a[s])}else n||(o||(o=[]),o.push(u,n)),n=a;else u==="dangerouslySetInnerHTML"?(a=a?a.__html:void 0,l=l?l.__html:void 0,a!=null&&l!==a&&(o=o||[]).push(u,a)):u==="children"?typeof a!="string"&&typeof a!="number"||(o=o||[]).push(u,""+a):u!=="suppressContentEditableWarning"&&u!=="suppressHydrationWarning"&&(Gi.hasOwnProperty(u)?(a!=null&&u==="onScroll"&&q("scroll",t),o||l===a||(o=[])):(o=o||[]).push(u,a))}n&&(o=o||[]).push("style",n);var u=o;(e.updateQueue=u)&&(e.flags|=4)}};$g=function(t,e,n,r){n!==r&&(e.flags|=4)};function Ci(t,e){if(!Y)switch(t.tailMode){case"hidden":e=t.tail;for(var n=null;e!==null;)e.alternate!==null&&(n=e),e=e.sibling;n===null?t.tail=null:n.sibling=null;break;case"collapsed":n=t.tail;for(var r=null;n!==null;)n.alternate!==null&&(r=n),n=n.sibling;r===null?e||t.tail===null?t.tail=null:t.tail.sibling=null:r.sibling=null}}function Te(t){var e=t.alternate!==null&&t.alternate.child===t.child,n=0,r=0;if(e)for(var i=t.child;i!==null;)n|=i.lanes|i.childLanes,r|=i.subtreeFlags&14680064,r|=i.flags&14680064,i.return=t,i=i.sibling;else for(i=t.child;i!==null;)n|=i.lanes|i.childLanes,r|=i.subtreeFlags,r|=i.flags,i.return=t,i=i.sibling;return t.subtreeFlags|=r,t.childLanes=n,e}function Gk(t,e,n){var r=e.pendingProps;switch(sd(e),e.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return Te(e),null;case 1:return We(e.type)&&Is(),Te(e),null;case 3:return r=e.stateNode,ni(),Q(Ue),Q(be),md(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(t===null||t.child===null)&&(Wo(e)?e.flags|=4:t===null||t.memoizedState.isDehydrated&&!(e.flags&256)||(e.flags|=1024,yt!==null&&(lc(yt),yt=null))),Zu(t,e),Te(e),null;case 5:pd(e);var i=Xn(ao.current);if(n=e.type,t!==null&&e.stateNode!=null)Hg(t,e,n,r,i),t.ref!==e.ref&&(e.flags|=512,e.flags|=2097152);else{if(!r){if(e.stateNode===null)throw Error(E(166));return Te(e),null}if(t=Xn(_t.current),Wo(e)){r=e.stateNode,n=e.type;var o=e.memoizedProps;switch(r[Dt]=e,r[so]=o,t=(e.mode&1)!==0,n){case"dialog":q("cancel",r),q("close",r);break;case"iframe":case"object":case"embed":q("load",r);break;case"video":case"audio":for(i=0;i<\/script>",t=t.removeChild(t.firstChild)):typeof r.is=="string"?t=s.createElement(n,{is:r.is}):(t=s.createElement(n),n==="select"&&(s=t,r.multiple?s.multiple=!0:r.size&&(s.size=r.size))):t=s.createElementNS(t,n),t[Dt]=e,t[so]=r,_g(t,e,!1,!1),e.stateNode=t;e:{switch(s=Ou(n,r),n){case"dialog":q("cancel",t),q("close",t),i=r;break;case"iframe":case"object":case"embed":q("load",t),i=r;break;case"video":case"audio":for(i=0;iii&&(e.flags|=128,r=!0,Ci(o,!1),e.lanes=4194304)}else{if(!r)if(t=_s(s),t!==null){if(e.flags|=128,r=!0,n=t.updateQueue,n!==null&&(e.updateQueue=n,e.flags|=4),Ci(o,!0),o.tail===null&&o.tailMode==="hidden"&&!s.alternate&&!Y)return Te(e),null}else 2*oe()-o.renderingStartTime>ii&&n!==1073741824&&(e.flags|=128,r=!0,Ci(o,!1),e.lanes=4194304);o.isBackwards?(s.sibling=e.child,e.child=s):(n=o.last,n!==null?n.sibling=s:e.child=s,o.last=s)}return o.tail!==null?(e=o.tail,o.rendering=e,o.tail=e.sibling,o.renderingStartTime=oe(),e.sibling=null,n=Z.current,J(Z,r?n&1|2:n&1),e):(Te(e),null);case 22:case 23:return Td(),r=e.memoizedState!==null,t!==null&&t.memoizedState!==null!==r&&(e.flags|=8192),r&&e.mode&1?Ge&1073741824&&(Te(e),e.subtreeFlags&6&&(e.flags|=8192)):Te(e),null;case 24:return null;case 25:return null}throw Error(E(156,e.tag))}function Yk(t,e){switch(sd(e),e.tag){case 1:return We(e.type)&&Is(),t=e.flags,t&65536?(e.flags=t&-65537|128,e):null;case 3:return ni(),Q(Ue),Q(be),md(),t=e.flags,t&65536&&!(t&128)?(e.flags=t&-65537|128,e):null;case 5:return pd(e),null;case 13:if(Q(Z),t=e.memoizedState,t!==null&&t.dehydrated!==null){if(e.alternate===null)throw Error(E(340));ei()}return t=e.flags,t&65536?(e.flags=t&-65537|128,e):null;case 19:return Q(Z),null;case 4:return ni(),null;case 10:return cd(e.type._context),null;case 22:case 23:return Td(),null;case 24:return null;default:return null}}var qo=!1,Ne=!1,Xk=typeof WeakSet=="function"?WeakSet:Set,b=null;function Fr(t,e){var n=t.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){ne(t,e,r)}else n.current=null}function ec(t,e,n){try{n()}catch(r){ne(t,e,r)}}var uh=!1;function Zk(t,e){if(Bu=Ns,t=Wm(),id(t)){if("selectionStart"in t)var n={start:t.selectionStart,end:t.selectionEnd};else e:{n=(n=t.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var i=r.anchorOffset,o=r.focusNode;r=r.focusOffset;try{n.nodeType,o.nodeType}catch{n=null;break e}var s=0,l=-1,a=-1,u=0,c=0,d=t,f=null;t:for(;;){for(var h;d!==n||i!==0&&d.nodeType!==3||(l=s+i),d!==o||r!==0&&d.nodeType!==3||(a=s+r),d.nodeType===3&&(s+=d.nodeValue.length),(h=d.firstChild)!==null;)f=d,d=h;for(;;){if(d===t)break t;if(f===n&&++u===i&&(l=s),f===o&&++c===r&&(a=s),(h=d.nextSibling)!==null)break;d=f,f=d.parentNode}d=h}n=l===-1||a===-1?null:{start:l,end:a}}else n=null}n=n||{start:0,end:0}}else n=null;for(Fu={focusedElem:t,selectionRange:n},Ns=!1,b=e;b!==null;)if(e=b,t=e.child,(e.subtreeFlags&1028)!==0&&t!==null)t.return=e,b=t;else for(;b!==null;){e=b;try{var p=e.alternate;if(e.flags&1024)switch(e.tag){case 0:case 11:case 15:break;case 1:if(p!==null){var y=p.memoizedProps,v=p.memoizedState,m=e.stateNode,g=m.getSnapshotBeforeUpdate(e.elementType===e.type?y:mt(e.type,y),v);m.__reactInternalSnapshotBeforeUpdate=g}break;case 3:var k=e.stateNode.containerInfo;k.nodeType===1?k.textContent="":k.nodeType===9&&k.documentElement&&k.removeChild(k.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(E(163))}}catch(S){ne(e,e.return,S)}if(t=e.sibling,t!==null){t.return=e.return,b=t;break}b=e.return}return p=uh,uh=!1,p}function Hi(t,e,n){var r=e.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var i=r=r.next;do{if((i.tag&t)===t){var o=i.destroy;i.destroy=void 0,o!==void 0&&ec(e,n,o)}i=i.next}while(i!==r)}}function Jl(t,e){if(e=e.updateQueue,e=e!==null?e.lastEffect:null,e!==null){var n=e=e.next;do{if((n.tag&t)===t){var r=n.create;n.destroy=r()}n=n.next}while(n!==e)}}function tc(t){var e=t.ref;if(e!==null){var n=t.stateNode;switch(t.tag){case 5:t=n;break;default:t=n}typeof e=="function"?e(t):e.current=t}}function jg(t){var e=t.alternate;e!==null&&(t.alternate=null,jg(e)),t.child=null,t.deletions=null,t.sibling=null,t.tag===5&&(e=t.stateNode,e!==null&&(delete e[Dt],delete e[so],delete e[$u],delete e[Pk],delete e[zk])),t.stateNode=null,t.return=null,t.dependencies=null,t.memoizedProps=null,t.memoizedState=null,t.pendingProps=null,t.stateNode=null,t.updateQueue=null}function Vg(t){return t.tag===5||t.tag===3||t.tag===4}function ch(t){e:for(;;){for(;t.sibling===null;){if(t.return===null||Vg(t.return))return null;t=t.return}for(t.sibling.return=t.return,t=t.sibling;t.tag!==5&&t.tag!==6&&t.tag!==18;){if(t.flags&2||t.child===null||t.tag===4)continue e;t.child.return=t,t=t.child}if(!(t.flags&2))return t.stateNode}}function nc(t,e,n){var r=t.tag;if(r===5||r===6)t=t.stateNode,e?n.nodeType===8?n.parentNode.insertBefore(t,e):n.insertBefore(t,e):(n.nodeType===8?(e=n.parentNode,e.insertBefore(t,n)):(e=n,e.appendChild(t)),n=n._reactRootContainer,n!=null||e.onclick!==null||(e.onclick=Rs));else if(r!==4&&(t=t.child,t!==null))for(nc(t,e,n),t=t.sibling;t!==null;)nc(t,e,n),t=t.sibling}function rc(t,e,n){var r=t.tag;if(r===5||r===6)t=t.stateNode,e?n.insertBefore(t,e):n.appendChild(t);else if(r!==4&&(t=t.child,t!==null))for(rc(t,e,n),t=t.sibling;t!==null;)rc(t,e,n),t=t.sibling}var ve=null,gt=!1;function on(t,e,n){for(n=n.child;n!==null;)Ug(t,e,n),n=n.sibling}function Ug(t,e,n){if(Ft&&typeof Ft.onCommitFiberUnmount=="function")try{Ft.onCommitFiberUnmount(_l,n)}catch{}switch(n.tag){case 5:Ne||Fr(n,e);case 6:var r=ve,i=gt;ve=null,on(t,e,n),ve=r,gt=i,ve!==null&&(gt?(t=ve,n=n.stateNode,t.nodeType===8?t.parentNode.removeChild(n):t.removeChild(n)):ve.removeChild(n.stateNode));break;case 18:ve!==null&&(gt?(t=ve,n=n.stateNode,t.nodeType===8?Ra(t.parentNode,n):t.nodeType===1&&Ra(t,n),to(t)):Ra(ve,n.stateNode));break;case 4:r=ve,i=gt,ve=n.stateNode.containerInfo,gt=!0,on(t,e,n),ve=r,gt=i;break;case 0:case 11:case 14:case 15:if(!Ne&&(r=n.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)&&ec(n,e,s),i=i.next}while(i!==r)}on(t,e,n);break;case 1:if(!Ne&&(Fr(n,e),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(l){ne(n,e,l)}on(t,e,n);break;case 21:on(t,e,n);break;case 22:n.mode&1?(Ne=(r=Ne)||n.memoizedState!==null,on(t,e,n),Ne=r):on(t,e,n);break;default:on(t,e,n)}}function dh(t){var e=t.updateQueue;if(e!==null){t.updateQueue=null;var n=t.stateNode;n===null&&(n=t.stateNode=new Xk),e.forEach(function(r){var i=av.bind(null,t,r);n.has(r)||(n.add(r),r.then(i,i))})}}function pt(t,e){var n=e.deletions;if(n!==null)for(var r=0;ri&&(i=s),r&=~o}if(r=i,r=oe()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*tv(r/1960))-r,10t?16:t,kn===null)var r=!1;else{if(t=kn,kn=null,Us=0,j&6)throw Error(E(331));var i=j;for(j|=4,b=t.current;b!==null;){var o=b,s=o.child;if(b.flags&16){var l=o.deletions;if(l!==null){for(var a=0;aoe()-Ed?rr(t,0):Cd|=n),Ke(t,e)}function Xg(t,e){e===0&&(t.mode&1?(e=_o,_o<<=1,!(_o&130023424)&&(_o=4194304)):e=1);var n=De();t=en(t,e),t!==null&&(Eo(t,e,n),Ke(t,n))}function lv(t){var e=t.memoizedState,n=0;e!==null&&(n=e.retryLane),Xg(t,n)}function av(t,e){var n=0;switch(t.tag){case 13:var r=t.stateNode,i=t.memoizedState;i!==null&&(n=i.retryLane);break;case 19:r=t.stateNode;break;default:throw Error(E(314))}r!==null&&r.delete(e),Xg(t,n)}var Zg;Zg=function(t,e,n){if(t!==null)if(t.memoizedProps!==e.pendingProps||Ue.current)Ve=!0;else{if(!(t.lanes&n)&&!(e.flags&128))return Ve=!1,Qk(t,e,n);Ve=!!(t.flags&131072)}else Ve=!1,Y&&e.flags&1048576&&ng(e,Ps,e.index);switch(e.lanes=0,e.tag){case 2:var r=e.type;ps(t,e),t=e.pendingProps;var i=Zr(e,be.current);Kr(e,n),i=yd(null,e,r,t,i,n);var o=kd();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,Ls(e)):o=!1,e.memoizedState=i.state!==null&&i.state!==void 0?i.state:null,fd(e),i.updater=Wl,e.stateNode=i,i._reactInternals=e,Ju(e,r,t,n),e=Gu(null,e,r,!0,o,n)):(e.tag=0,Y&&o&&od(e),Ie(null,e,i,n),e=e.child),e;case 16:r=e.elementType;e:{switch(ps(t,e),t=e.pendingProps,i=r._init,r=i(r._payload),e.type=r,i=e.tag=cv(r),t=mt(r,t),i){case 0:e=Qu(null,e,r,t,n);break e;case 1:e=sh(null,e,r,t,n);break e;case 11:e=ih(null,e,r,t,n);break e;case 14:e=oh(null,e,r,mt(r.type,t),n);break e}throw Error(E(306,r,""))}return e;case 0:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:mt(r,i),Qu(t,e,r,i,n);case 1:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:mt(r,i),sh(t,e,r,i,n);case 3:e:{if(zg(e),t===null)throw Error(E(387));r=e.pendingProps,o=e.memoizedState,i=o.element,sg(t,e),Fs(e,r,null,n);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=ri(Error(E(423)),e),e=lh(t,e,r,n,i);break e}else if(r!==i){i=ri(Error(E(424)),e),e=lh(t,e,r,n,i);break e}else for(Xe=Mn(e.stateNode.containerInfo.firstChild),Ze=e,Y=!0,yt=null,n=cg(e,null,r,n),e.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(ei(),r===i){e=tn(t,e,n);break e}Ie(t,e,r,n)}e=e.child}return e;case 5:return dg(e),t===null&&Uu(e),r=e.type,i=e.pendingProps,o=t!==null?t.memoizedProps:null,s=i.children,_u(r,i)?s=null:o!==null&&_u(r,o)&&(e.flags|=32),Pg(t,e),Ie(t,e,s,n),e.child;case 6:return t===null&&Uu(e),null;case 13:return Bg(t,e,n);case 4:return hd(e,e.stateNode.containerInfo),r=e.pendingProps,t===null?e.child=ti(e,null,r,n):Ie(t,e,r,n),e.child;case 11:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:mt(r,i),ih(t,e,r,i,n);case 7:return Ie(t,e,e.pendingProps,n),e.child;case 8:return Ie(t,e,e.pendingProps.children,n),e.child;case 12:return Ie(t,e,e.pendingProps.children,n),e.child;case 10:e:{if(r=e.type._context,i=e.pendingProps,o=e.memoizedProps,s=i.value,J(zs,r._currentValue),r._currentValue=s,o!==null)if(Ct(o.value,s)){if(o.children===i.children&&!Ue.current){e=tn(t,e,n);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=Gt(-1,n&-n),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|=n,a=o.alternate,a!==null&&(a.lanes|=n),Wu(o.return,n,e),l.lanes|=n;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(E(341));s.lanes|=n,l=s.alternate,l!==null&&(l.lanes|=n),Wu(s,n,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}Ie(t,e,i.children,n),e=e.child}return e;case 9:return i=e.type,r=e.pendingProps.children,Kr(e,n),i=ft(i),r=r(i),e.flags|=1,Ie(t,e,r,n),e.child;case 14:return r=e.type,i=mt(r,e.pendingProps),i=mt(r.type,i),oh(t,e,r,i,n);case 15:return Lg(t,e,e.type,e.pendingProps,n);case 17:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:mt(r,i),ps(t,e),e.tag=1,We(r)?(t=!0,Ls(e)):t=!1,Kr(e,n),ag(e,r,i),Ju(e,r,i,n),Gu(null,e,r,!0,t,n);case 19:return Fg(t,e,n);case 22:return Dg(t,e,n)}throw Error(E(156,e.tag))};function ey(t,e){return Tm(t,e)}function uv(t,e,n,r){this.tag=t,this.key=n,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(t,e,n,r){return new uv(t,e,n,r)}function Nd(t){return t=t.prototype,!(!t||!t.isReactComponent)}function cv(t){if(typeof t=="function")return Nd(t)?1:0;if(t!=null){if(t=t.$$typeof,t===Jc)return 11;if(t===qc)return 14}return 2}function An(t,e){var n=t.alternate;return n===null?(n=at(t.tag,e,t.key,t.mode),n.elementType=t.elementType,n.type=t.type,n.stateNode=t.stateNode,n.alternate=t,t.alternate=n):(n.pendingProps=e,n.type=t.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=t.flags&14680064,n.childLanes=t.childLanes,n.lanes=t.lanes,n.child=t.child,n.memoizedProps=t.memoizedProps,n.memoizedState=t.memoizedState,n.updateQueue=t.updateQueue,e=t.dependencies,n.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext},n.sibling=t.sibling,n.index=t.index,n.ref=t.ref,n}function ys(t,e,n,r,i,o){var s=2;if(r=t,typeof t=="function")Nd(t)&&(s=1);else if(typeof t=="string")s=5;else e:switch(t){case Ar:return ir(n.children,i,o,e);case Kc:s=8,i|=8;break;case yu:return t=at(12,n,e,i|2),t.elementType=yu,t.lanes=o,t;case ku:return t=at(13,n,e,i),t.elementType=ku,t.lanes=o,t;case vu:return t=at(19,n,e,i),t.elementType=vu,t.lanes=o,t;case um:return Ql(n,i,o,e);default:if(typeof t=="object"&&t!==null)switch(t.$$typeof){case lm:s=10;break e;case am:s=9;break e;case Jc:s=11;break e;case qc:s=14;break e;case an:s=16,r=null;break e}throw Error(E(130,t==null?t:typeof t,""))}return e=at(s,n,e,i),e.elementType=t,e.type=r,e.lanes=o,e}function ir(t,e,n,r){return t=at(7,t,r,e),t.lanes=n,t}function Ql(t,e,n,r){return t=at(22,t,r,e),t.elementType=um,t.lanes=n,t.stateNode={isHidden:!1},t}function _a(t,e,n){return t=at(6,t,null,e),t.lanes=n,t}function Ha(t,e,n){return e=at(4,t.children!==null?t.children:[],t.key,e),e.lanes=n,e.stateNode={containerInfo:t.containerInfo,pendingChildren:null,implementation:t.implementation},e}function dv(t,e,n,r,i){this.tag=e,this.containerInfo=t,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Sa(0),this.expirationTimes=Sa(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Sa(0),this.identifierPrefix=r,this.onRecoverableError=i,this.mutableSourceEagerHydrationData=null}function Ad(t,e,n,r,i,o,s,l,a){return t=new dv(t,e,n,l,a),e===1?(e=1,o===!0&&(e|=8)):e=0,o=at(3,null,null,e),t.current=o,o.stateNode=t,o.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},fd(o),t}function fv(t,e,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(iy)}catch(t){console.error(t)}}iy(),nm.exports=tt;var ea=nm.exports;const oy=Fc(ea);var sy,vh=ea;sy=vh.createRoot,vh.hydrateRoot;function Se(t){this.content=t}Se.prototype={constructor:Se,find:function(t){for(var e=0;e>1}};Se.from=function(t){if(t instanceof Se)return t;var e=[];if(t)for(var n in t)e.push(n,t[n]);return new Se(e)};function ly(t,e,n){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:n;let i=t.child(r),o=e.child(r);if(i==o){n+=i.nodeSize;continue}if(!i.sameMarkup(o))return n;if(i.isText&&i.text!=o.text){for(let s=0;i.text[s]==o.text[s];s++)n++;return n}if(i.content.size||o.content.size){let s=ly(i.content,o.content,n+1);if(s!=null)return s}n+=i.nodeSize}}function ay(t,e,n,r){for(let i=t.childCount,o=e.childCount;;){if(i==0||o==0)return i==o?null:{a:n,b:r};let s=t.child(--i),l=e.child(--o),a=s.nodeSize;if(s==l){n-=a,r-=a;continue}if(!s.sameMarkup(l))return{a:n,b:r};if(s.isText&&s.text!=l.text){let u=0,c=Math.min(s.text.length,l.text.length);for(;ue&&r(a,i+l,o||null,s)!==!1&&a.content.size){let c=l+1;a.nodesBetween(Math.max(0,e-c),Math.min(a.content.size,n-c),r,i+c)}l=u}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,r,i){let o="",s=!0;return this.nodesBetween(e,n,(l,a)=>{let u=l.isText?l.text.slice(Math.max(e,a)-a,n-a):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&u||l.isTextblock)&&r&&(s?s=!1:o+=r),o+=u},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,r=e.firstChild,i=this.content.slice(),o=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),o=1);oe)for(let o=0,s=0;se&&((sn)&&(l.isText?l=l.cut(Math.max(0,e-s),Math.min(l.text.length,n-s)):l=l.cut(Math.max(0,e-s-1),Math.min(l.content.size,n-s-1))),r.push(l),i+=l.nodeSize),s=a}return new C(r,i)}cutByIndex(e,n){return e==n?C.empty:e==0&&n==this.content.length?this:new C(this.content.slice(e,n))}replaceChild(e,n){let r=this.content[e];if(r==n)return this;let i=this.content.slice(),o=this.size+n.nodeSize-r.nodeSize;return i[e]=n,new C(i,o)}addToStart(e){return new C([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new C(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let n=0;nthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let o=this.child(r),s=i+o.nodeSize;if(s>=e)return s==e||n>0?Yo(r+1,s):Yo(r,i);i=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return C.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new C(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return C.empty;let n,r=0;for(let i=0;ithis.type.rank&&(n||(n=e.slice(0,i)),n.push(this),r=!0),n&&n.push(o)}}return n||(n=e.slice()),r||n.push(this),n}removeFromSet(e){for(let n=0;nr.type.rank-i.type.rank),n}};U.none=[];class qs extends Error{}class A{constructor(e,n,r){this.content=e,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let r=cy(this.content,e+this.openStart,n);return r&&new A(r,this.openStart,this.openEnd)}removeBetween(e,n){return new A(uy(this.content,e+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,n){if(!n)return A.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new A(C.fromJSON(e,n.content),r,i)}static maxOpen(e,n=!0){let r=0,i=0;for(let o=e.firstChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.lastChild)i++;return new A(e,r,i)}}A.empty=new A(C.empty,0,0);function uy(t,e,n){let{index:r,offset:i}=t.findIndex(e),o=t.maybeChild(r),{index:s,offset:l}=t.findIndex(n);if(i==e||o.isText){if(l!=n&&!t.child(s).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(r!=s)throw new RangeError("Removing non-flat range");return t.replaceChild(r,o.copy(uy(o.content,e-i-1,n-i-1)))}function cy(t,e,n,r){let{index:i,offset:o}=t.findIndex(e),s=t.maybeChild(i);if(o==e||s.isText)return r&&!r.canReplace(i,i,n)?null:t.cut(0,e).append(n).append(t.cut(e));let l=cy(s.content,e-o-1,n);return l&&t.replaceChild(i,s.copy(l))}function yv(t,e,n){if(n.openStart>t.depth)throw new qs("Inserted content deeper than insertion position");if(t.depth-n.openStart!=e.depth-n.openEnd)throw new qs("Inconsistent open depths");return dy(t,e,n,0)}function dy(t,e,n,r){let i=t.index(r),o=t.node(r);if(i==e.index(r)&&r=0&&t.isText&&t.sameMarkup(e[n])?e[n]=t.withText(e[n].text+t.text):e.push(t)}function Vi(t,e,n,r){let i=(e||t).node(n),o=0,s=e?e.index(n):i.childCount;t&&(o=t.index(n),t.depth>n?o++:t.textOffset&&(or(t.nodeAfter,r),o++));for(let l=o;li&&uc(t,e,i+1),s=r.depth>i&&uc(n,r,i+1),l=[];return Vi(null,t,i,l),o&&s&&e.index(i)==n.index(i)?(fy(o,s),or(sr(o,hy(t,e,n,r,i+1)),l)):(o&&or(sr(o,Qs(t,e,i+1)),l),Vi(e,n,i,l),s&&or(sr(s,Qs(n,r,i+1)),l)),Vi(r,null,i,l),new C(l)}function Qs(t,e,n){let r=[];if(Vi(null,t,n,r),t.depth>n){let i=uc(t,e,n+1);or(sr(i,Qs(t,e,n+1)),r)}return Vi(e,null,n,r),new C(r)}function kv(t,e){let n=e.depth-t.openStart,i=e.node(n).copy(t.content);for(let o=n-1;o>=0;o--)i=e.node(o).copy(C.from(i));return{start:i.resolveNoCache(t.openStart+n),end:i.resolveNoCache(i.content.size-t.openEnd-n)}}class po{constructor(e,n,r){this.pos=e,this.path=n,this.parentOffset=r,this.depth=n.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,n=this.index(this.depth);if(n==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(n);return r?e.child(n).cut(r):i}get nodeBefore(){let e=this.index(this.depth),n=this.pos-this.path[this.path.length-1];return n?this.parent.child(e).cut(0,n):e==0?null:this.parent.child(e-1)}posAtIndex(e,n){n=this.resolveDepth(n);let r=this.path[n*3],i=n==0?0:this.path[n*3-1]+1;for(let o=0;o0;n--)if(this.start(n)<=e&&this.end(n)>=e)return n;return 0}blockRange(e=this,n){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!n||n(this.node(r))))return new Gs(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&n<=e.content.size))throw new RangeError("Position "+n+" out of range");let r=[],i=0,o=n;for(let s=e;;){let{index:l,offset:a}=s.content.findIndex(o),u=o-a;if(r.push(s,l,i+a),!u||(s=s.child(l),s.isText))break;o=u-1,i+=a+1}return new po(n,r,o)}static resolveCached(e,n){for(let i=0;ie&&this.nodesBetween(e,n,o=>(r.isInSet(o.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),py(this.marks,e)}contentMatchAt(e){let n=this.type.contentMatch.matchFragment(this.content,0,e);if(!n)throw new Error("Called contentMatchAt on a node with invalid content");return n}canReplace(e,n,r=C.empty,i=0,o=r.childCount){let s=this.contentMatchAt(e).matchFragment(r,i,o),l=s&&s.matchFragment(this.content,n);if(!l||!l.validEnd)return!1;for(let a=i;an.type.name)}`);this.content.forEach(n=>n.check())}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(n=>n.toJSON())),e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Node.fromJSON");let r=null;if(n.marks){if(!Array.isArray(n.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=n.marks.map(e.markFromJSON)}if(n.type=="text"){if(typeof n.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(n.text,r)}let i=C.fromJSON(e,n.content);return e.nodeType(n.type).create(n.attrs,i,r)}};lr.prototype.text=void 0;class Ys extends lr{constructor(e,n,r,i){if(super(e,n,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):py(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,n){return this.text.slice(e,n)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new Ys(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new Ys(this.type,this.attrs,e,this.marks)}cut(e=0,n=this.text.length){return e==0&&n==this.text.length?this:this.withText(this.text.slice(e,n))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function py(t,e){for(let n=t.length-1;n>=0;n--)e=t[n].type.name+"("+e+")";return e}class mr{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,n){let r=new wv(e,n);if(r.next==null)return mr.empty;let i=my(r);r.next&&r.err("Unexpected trailing text");let o=Nv(Ov(i));return Av(o,r),o}matchType(e){for(let n=0;nu.createAndFill()));for(let u=0;u=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function n(r){e.push(r);for(let i=0;i{let o=i+(r.validEnd?"*":" ")+" ";for(let s=0;s"+e.indexOf(r.next[s].next);return o}).join(` `)}}mr.empty=new mr(!0);class wv{constructor(e,n){this.string=e,this.nodeTypes=n,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}}function my(t){let e=[];do e.push(xv(t));while(t.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function xv(t){let e=[];do e.push(Cv(t));while(t.next&&t.next!=")"&&t.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function Cv(t){let e=Tv(t);for(;;)if(t.eat("+"))e={type:"plus",expr:e};else if(t.eat("*"))e={type:"star",expr:e};else if(t.eat("?"))e={type:"opt",expr:e};else if(t.eat("{"))e=Ev(t,e);else break;return e}function Sh(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);return t.pos++,e}function Ev(t,e){let n=Sh(t),r=n;return t.eat(",")&&(t.next!="}"?r=Sh(t):r=-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:e}}function Mv(t,e){let n=t.nodeTypes,r=n[e];if(r)return[r];let i=[];for(let o in n){let s=n[o];s.groups.indexOf(e)>-1&&i.push(s)}return i.length==0&&t.err("No node type or group '"+e+"' found"),i}function Tv(t){if(t.eat("(")){let e=my(t);return t.eat(")")||t.err("Missing closing paren"),e}else if(/\W/.test(t.next))t.err("Unexpected token '"+t.next+"'");else{let e=Mv(t,t.next).map(n=>(t.inline==null?t.inline=n.isInline:t.inline!=n.isInline&&t.err("Mixing inline and block content"),{type:"name",value:n}));return t.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Ov(t){let e=[[]];return i(o(t,0),n()),e;function n(){return e.push([])-1}function r(s,l,a){let u={term:a,to:l};return e[s].push(u),u}function i(s,l){s.forEach(a=>a.to=l)}function o(s,l){if(s.type=="choice")return s.exprs.reduce((a,u)=>a.concat(o(u,l)),[]);if(s.type=="seq")for(let a=0;;a++){let u=o(s.exprs[a],l);if(a==s.exprs.length-1)return u;i(u,l=n())}else if(s.type=="star"){let a=n();return r(l,a),i(o(s.expr,a),a),[r(a)]}else if(s.type=="plus"){let a=n();return i(o(s.expr,l),a),i(o(s.expr,a),a),[r(a)]}else{if(s.type=="opt")return[r(l)].concat(o(s.expr,l));if(s.type=="range"){let a=l;for(let u=0;u{t[s].forEach(({term:l,to:a})=>{if(!l)return;let u;for(let c=0;c{u||i.push([l,u=[]]),u.indexOf(c)==-1&&u.push(c)})})});let o=e[r.join(",")]=new mr(r.indexOf(t.length-1)>-1);for(let s=0;s-1}allowsMarks(e){if(this.markSet==null)return!0;for(let n=0;nr[o]=new Sy(o,n,s));let i=n.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let o in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};class bv{constructor(e){this.hasDefault=Object.prototype.hasOwnProperty.call(e,"default"),this.default=e.default}get isRequired(){return!this.hasDefault}}class ta{constructor(e,n,r,i){this.name=e,this.rank=n,this.schema=r,this.spec=i,this.attrs=vy(i.attrs),this.excluded=null;let o=yy(this.attrs);this.instance=o?new U(this,o):null}create(e=null){return!e&&this.instance?this.instance:new U(this,ky(this.attrs,e))}static compile(e,n){let r=Object.create(null),i=0;return e.forEach((o,s)=>r[o]=new ta(o,i++,n,s)),r}removeFromSet(e){for(var n=0;n-1}}class Rv{constructor(e){this.cached=Object.create(null);let n=this.spec={};for(let i in e)n[i]=e[i];n.nodes=Se.from(e.nodes),n.marks=Se.from(e.marks||{}),this.nodes=xh.compile(this.spec.nodes,this),this.marks=ta.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let o=this.nodes[i],s=o.spec.content||"",l=o.spec.marks;o.contentMatch=r[s]||(r[s]=mr.parse(s,this.nodes)),o.inlineContent=o.contentMatch.inlineContent,o.markSet=l=="_"?null:l?Ch(this,l.split(" ")):l==""||!o.inlineContent?[]:null}for(let i in this.marks){let o=this.marks[i],s=o.spec.excludes;o.excluded=s==null?[o]:s==""?[]:Ch(this,s.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,n=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof xh){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(n,r,i)}text(e,n){let r=this.nodes.text;return new Ys(r,r.defaultAttrs,e,U.setFrom(n))}mark(e,n){return typeof e=="string"&&(e=this.marks[e]),e.create(n)}nodeFromJSON(e){return lr.fromJSON(this,e)}markFromJSON(e){return U.fromJSON(this,e)}nodeType(e){let n=this.nodes[e];if(!n)throw new RangeError("Unknown node type: "+e);return n}}function Ch(t,e){let n=[];for(let r=0;r-1)&&n.push(s=a)}if(!s)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return n}let Ld=class dc{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[],n.forEach(r=>{r.tag?this.tags.push(r):r.style&&this.styles.push(r)}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let i=e.nodes[r.node];return i.contentMatch.matchType(i)})}parse(e,n={}){let r=new Mh(this,n,!1);return r.addAll(e,n.from,n.to),r.finish()}parseSlice(e,n={}){let r=new Mh(this,n,!0);return r.addAll(e,n.from,n.to),A.maxOpen(r.finish())}matchTag(e,n,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=n))){if(s.getAttrs){let a=s.getAttrs(n);if(a===!1)continue;s.attrs=a||void 0}return s}}}static schemaRules(e){let n=[];function r(i){let o=i.priority==null?50:i.priority,s=0;for(;s{r(s=Th(s)),s.mark||s.ignore||s.clearMark||(s.mark=i)})}for(let i in e.nodes){let o=e.nodes[i].spec.parseDOM;o&&o.forEach(s=>{r(s=Th(s)),s.node||s.ignore||s.mark||(s.node=i)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new dc(e,dc.schemaRules(e)))}};const wy={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Iv={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},xy={ol:!0,ul:!0},Xs=1,Zs=2,Ui=4;function Eh(t,e,n){return e!=null?(e?Xs:0)|(e==="full"?Zs:0):t&&t.whitespace=="pre"?Xs|Zs:n&~Ui}class Xo{constructor(e,n,r,i,o,s,l){this.type=e,this.attrs=n,this.marks=r,this.pendingMarks=i,this.solid=o,this.options=l,this.content=[],this.activeMarks=U.none,this.stashMarks=[],this.match=s||(l&Ui?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(C.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Xs)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-i[0].length))}}let n=C.from(this.content);return!e&&this.match&&(n=n.append(this.match.fillBefore(C.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}popFromStashMark(e){for(let n=this.stashMarks.length-1;n>=0;n--)if(e.eq(this.stashMarks[n]))return this.stashMarks.splice(n,1)[0]}applyPending(e){for(let n=0,r=this.pendingMarks;nthis.addAll(e)),s&&this.sync(l),this.needsBlock=a}else this.withStyleRules(e,()=>{this.addElementByRule(e,o,o.consuming===!1?i:void 0)})}leafFallback(e){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` -`))}ignoreFallback(e){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(e){let n=U.none,r=U.none;for(let i=0;i{s.clearMark(l)&&(r=l.addToSet(r))}):n=this.parser.schema.marks[s.mark].create(s.attrs).addToSet(n),s.consuming===!1)o=s;else break}return[n,r]}addElementByRule(e,n,r){let i,o,s;n.node?(o=this.parser.schema.nodes[n.node],o.isLeaf?this.insertNode(o.create(n.attrs))||this.leafFallback(e):i=this.enter(o,n.attrs||null,n.preserveWhitespace)):(s=this.parser.schema.marks[n.mark].create(n.attrs),this.addPendingMark(s));let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(r)this.addElement(e,r);else if(n.getContent)this.findInside(e),n.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a));else{let a=e;typeof n.contentElement=="string"?a=e.querySelector(n.contentElement):typeof n.contentElement=="function"?a=n.contentElement(e):n.contentElement&&(a=n.contentElement),this.findAround(e,a,!0),this.addAll(a)}i&&this.sync(l)&&this.open--,s&&this.removePendingMark(s,l)}addAll(e,n,r){let i=n||0;for(let o=n?e.childNodes[n]:e.firstChild,s=r==null?null:e.childNodes[r];o!=s;o=o.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(o);this.findAtPoint(e,i)}findPlace(e){let n,r;for(let i=this.open;i>=0;i--){let o=this.nodes[i],s=o.findWrapping(e);if(s&&(!n||n.length>s.length)&&(n=s,r=o,!s.length)||o.solid)break}if(!n)return!1;this.sync(r);for(let i=0;ithis.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let n=this.open;n>=0;n--)if(this.nodes[n]==e)return this.open=n,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;n&&e++}return e}findAtPoint(e,n){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let n=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(i?0:1),s=(l,a)=>{for(;l>=0;l--){let u=n[l];if(u==""){if(l==n.length-1||l==0)continue;for(;a>=o;a--)if(s(l-1,a))return!0;return!1}else{let c=a>0||a==0&&i?this.nodes[a].type:r&&a>=o?r.node(a-o).type:null;if(!c||c.name!=u&&c.groups.indexOf(u)==-1)return!1;a--}}return!0};return s(n.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let n=e.depth;n>=0;n--){let r=e.node(n).contentMatchAt(e.indexAfter(n)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let n in this.parser.schema.nodes){let r=this.parser.schema.nodes[n];if(r.isTextblock&&r.defaultAttrs)return r}}addPendingMark(e){let n=Bv(e,this.top.pendingMarks);n&&this.top.stashMarks.push(n),this.top.pendingMarks=e.addToSet(this.top.pendingMarks)}removePendingMark(e,n){for(let r=this.open;r>=0;r--){let i=this.nodes[r];if(i.pendingMarks.lastIndexOf(e)>-1)i.pendingMarks=e.removeFromSet(i.pendingMarks);else{i.activeMarks=e.removeFromSet(i.activeMarks);let s=i.popFromStashMark(e);s&&i.type&&i.type.allowsMarkType(s.type)&&(i.activeMarks=s.addToSet(i.activeMarks))}if(i==n)break}}}function Lv(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&xy.hasOwnProperty(r)&&n?(n.appendChild(e),e=n):r=="li"?n=e:r&&(n=null)}}function Dv(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function Pv(t){let e=/\s*([\w-]+)\s*:\s*([^;]+)/g,n,r=[];for(;n=e.exec(t);)r.push(n[1],n[2].trim());return r}function Th(t){let e={};for(let n in t)e[n]=t[n];return e}function zv(t,e){let n=e.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(t))continue;let o=[],s=l=>{o.push(l);for(let a=0;a{if(o.length||s.marks.length){let l=0,a=0;for(;l=0;i--){let o=this.serializeMark(e.marks[i],e.isInline,n);o&&((o.contentDOM||o.dom).appendChild(r),r=o.dom)}return r}serializeMark(e,n,r={}){let i=this.marks[e.type.name];return i&&zt.renderSpec(Ua(r),i(e,n))}static renderSpec(e,n,r=null){if(typeof n=="string")return{dom:e.createTextNode(n)};if(n.nodeType!=null)return{dom:n};if(n.dom&&n.dom.nodeType!=null)return n;let i=n[0],o=i.indexOf(" ");o>0&&(r=i.slice(0,o),i=i.slice(o+1));let s,l=r?e.createElementNS(r,i):e.createElement(i),a=n[1],u=1;if(a&&typeof a=="object"&&a.nodeType==null&&!Array.isArray(a)){u=2;for(let c in a)if(a[c]!=null){let d=c.indexOf(" ");d>0?l.setAttributeNS(c.slice(0,d),c.slice(d+1),a[c]):l.setAttribute(c,a[c])}}for(let c=u;cu)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}else{let{dom:f,contentDOM:h}=zt.renderSpec(e,d,r);if(l.appendChild(f),h){if(s)throw new RangeError("Multiple content holes");s=h}}}return{dom:l,contentDOM:s}}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new zt(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let n=Oh(e.nodes);return n.text||(n.text=r=>r.text),n}static marksFromSchema(e){return Oh(e.marks)}}function Oh(t){let e={};for(let n in t){let r=t[n].spec.toDOM;r&&(e[n]=r)}return e}function Ua(t){return t.document||window.document}const Cy=65535,Ey=Math.pow(2,16);function Fv(t,e){return t+e*Ey}function Nh(t){return t&Cy}function _v(t){return(t-(t&Cy))/Ey}const My=1,Ty=2,ks=4,Oy=8;class fc{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&Oy)>0}get deletedBefore(){return(this.delInfo&(My|ks))>0}get deletedAfter(){return(this.delInfo&(Ty|ks))>0}get deletedAcross(){return(this.delInfo&ks)>0}}class Ye{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&Ye.empty)return Ye.empty}recover(e){let n=0,r=Nh(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],d=a+u;if(e<=d){let f=u?e==a?-1:e==d?1:n:n,h=a+i+(f<0?0:c);if(r)return h;let p=e==(n<0?a:d)?null:Fv(l/3,e-a),y=e==a?Ty:e==d?My:ks;return(n<0?e!=a:e!=d)&&(y|=Oy),new fc(h,y,p)}i+=c-u}return r?e+i:new fc(e+i,0,null)}touches(e,n){let r=0,i=Nh(n),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let n=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i=0;n--){let i=e.getMirror(n);this.appendMap(e.maps[n].invert(),i!=null&&i>n?r-i-1:void 0)}}invert(){let e=new qr;return e.appendMappingInverted(this),e}map(e,n=1){if(this.mirror)return this._map(e,n,!0);for(let r=this.from;ro&&a!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),n.openStart,n.openEnd);return ae.fromReplace(e,this.from,this.to,o)}invert(){return new Bt(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new vn(n.pos,r.pos,this.mark)}merge(e){return e instanceof vn&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new vn(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new vn(n.from,n.to,e.markFromJSON(n.mark))}}Re.jsonID("addMark",vn);class Bt extends Re{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=new A(Dd(n.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),n.openStart,n.openEnd);return ae.fromReplace(e,this.from,this.to,r)}invert(){return new vn(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new Bt(n.pos,r.pos,this.mark)}merge(e){return e instanceof Bt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Bt(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Bt(n.from,n.to,e.markFromJSON(n.mark))}}Re.jsonID("removeMark",Bt);class Sn extends Re{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return ae.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return ae.fromReplace(e,this.pos,this.pos+1,new A(C.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let i=0;ir.pos?null:new ge(n.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new ge(n.from,n.to,n.gapFrom,n.gapTo,A.fromJSON(e,n.slice),n.insert,!!n.structure)}}Re.jsonID("replaceAround",ge);function hc(t,e,n){let r=t.resolve(e),i=n-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function Hv(t,e,n,r){let i=[],o=[],s,l;t.doc.nodesBetween(e,n,(a,u,c)=>{if(!a.isInline)return;let d=a.marks;if(!r.isInSet(d)&&c.type.allowsMarkType(r.type)){let f=Math.max(u,e),h=Math.min(u+a.nodeSize,n),p=r.addToSet(d);for(let y=0;yt.step(a)),o.forEach(a=>t.step(a))}function $v(t,e,n,r){let i=[],o=0;t.doc.nodesBetween(e,n,(s,l)=>{if(!s.isInline)return;o++;let a=null;if(r instanceof ta){let u=s.marks,c;for(;c=r.isInSet(u);)(a||(a=[])).push(c),u=c.removeFromSet(u)}else r?r.isInSet(s.marks)&&(a=[r]):a=s.marks;if(a&&a.length){let u=Math.min(l+s.nodeSize,n);for(let c=0;ct.step(new Bt(s.from,s.to,s.style)))}function jv(t,e,n,r=n.contentMatch){let i=t.doc.nodeAt(e),o=[],s=e+1;for(let l=0;l=0;l--)t.step(o[l])}function Vv(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function pi(t){let n=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let r=t.depth;;--r){let i=t.$from.node(r),o=t.$from.index(r),s=t.$to.indexAfter(r);if(rn;p--)y||r.index(p)>0?(y=!0,c=C.from(r.node(p).copy(c)),d++):a--;let f=C.empty,h=0;for(let p=o,y=!1;p>n;p--)y||i.after(p+1)=0;s--){if(r.size){let l=n[s].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=C.from(n[s].type.create(n[s].attrs,r))}let i=e.start,o=e.end;t.step(new ge(i,o,i,o,new A(r,0,0),n.length,!0))}function qv(t,e,n,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=t.steps.length;t.doc.nodesBetween(e,n,(s,l)=>{if(s.isTextblock&&!s.hasMarkup(r,i)&&Qv(t.doc,t.mapping.slice(o).map(l),r)){t.clearIncompatible(t.mapping.slice(o).map(l,1),r);let a=t.mapping.slice(o),u=a.map(l,1),c=a.map(l+s.nodeSize,1);return t.step(new ge(u,c,u+1,c-1,new A(C.from(r.create(i,null,s.marks)),0,0),1,!0)),!1}})}function Qv(t,e,n){let r=t.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function Gv(t,e,n,r,i){let o=t.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");n||(n=o.type);let s=n.create(r,null,i||o.marks);if(o.isLeaf)return t.replaceWith(e,e+o.nodeSize,s);if(!n.validContent(o.content))throw new RangeError("Invalid content for node type "+n.name);t.step(new ge(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new A(C.from(s),0,0),1,!0))}function Qr(t,e,n=1,r){let i=t.resolve(e),o=i.depth-n,s=r&&r[r.length-1]||i.parent;if(o<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!s.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let u=i.depth-1,c=n-2;u>o;u--,c--){let d=i.node(u),f=i.index(u);if(d.type.spec.isolating)return!1;let h=d.content.cutByIndex(f,d.childCount),p=r&&r[c+1];p&&(h=h.replaceChild(0,p.type.create(p.attrs)));let y=r&&r[c]||d;if(!d.canReplace(f+1,d.childCount)||!y.type.validContent(h))return!1}let l=i.indexAfter(o),a=r&&r[0];return i.node(o).canReplaceWith(l,l,a?a.type:i.node(o+1).type)}function Yv(t,e,n=1,r){let i=t.doc.resolve(e),o=C.empty,s=C.empty;for(let l=i.depth,a=i.depth-n,u=n-1;l>a;l--,u--){o=C.from(i.node(l).copy(o));let c=r&&r[u];s=C.from(c?c.type.create(c.attrs,s):i.node(l).copy(s))}t.step(new we(e,e,new A(o.append(s),n,n),!0))}function $n(t,e){let n=t.resolve(e),r=n.index();return Ny(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function Ny(t,e){return!!(t&&e&&!t.isLeaf&&t.canAppend(e))}function na(t,e,n=-1){let r=t.resolve(e);for(let i=r.depth;;i--){let o,s,l=r.index(i);if(i==r.depth?(o=r.nodeBefore,s=r.nodeAfter):n>0?(o=r.node(i+1),l++,s=r.node(i).maybeChild(l)):(o=r.node(i).maybeChild(l-1),s=r.node(i+1)),o&&!o.isTextblock&&Ny(o,s)&&r.node(i).canReplace(l,l+1))return e;if(i==0)break;e=n<0?r.before(i):r.after(i)}}function Xv(t,e,n){let r=new we(e-n,e+n,A.empty,!0);t.step(r)}function Zv(t,e,n){let r=t.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),n))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let o=r.index(i);if(r.node(i).canReplaceWith(o,o,n))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,n))return r.after(i+1);if(o=0;s--){let l=s==r.depth?0:r.pos<=(r.start(s+1)+r.end(s+1))/2?-1:1,a=r.index(s)+(l>0?1:0),u=r.node(s),c=!1;if(o==1)c=u.canReplace(a,a,i);else{let d=u.contentMatchAt(a).findWrapping(i.firstChild.type);c=d&&u.canReplaceWith(a,a,d[0])}if(c)return l==0?r.pos:l<0?r.before(s+1):r.after(s+1)}return null}function zd(t,e,n=e,r=A.empty){if(e==n&&!r.size)return null;let i=t.resolve(e),o=t.resolve(n);return by(i,o,r)?new we(e,n,r):new eS(i,o,r).fit()}function by(t,e,n){return!n.openStart&&!n.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),n.content)}class eS{constructor(e,n,r){this.$from=e,this.$to=n,this.unplaced=r,this.frontier=[],this.placed=C.empty;for(let i=0;i<=e.depth;i++){let o=e.node(i);this.frontier.push({type:o.type,match:o.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=C.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let u=this.findFittable();u?this.placeNodes(u):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),n=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let a=new A(o,s,l);return e>-1?new ge(r.pos,e,this.$to.pos,this.$to.end(),a,n):a.size||r.pos!=this.$to.pos?new we(r.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let n=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),o.type.spec.isolating&&i<=r){e=r;break}n=o.content}for(let n=1;n<=2;n++)for(let r=n==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=Ka(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:u}=this.frontier[l],c,d=null;if(n==1&&(s?u.matchType(s.type)||(d=u.fillBefore(C.from(s),!1)):o&&a.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:d};if(n==2&&s&&(c=u.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:c};if(o&&u.matchType(o.type))break}}}openMore(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=Ka(e,n);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new A(e,n+1,Math.max(r,i.size+n>=e.size-r?n+1:0)),!0)}dropNode(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=Ka(e,n);if(i.childCount<=1&&n>0){let o=e.size-n<=n+i.size;this.unplaced=new A(Ri(e,n-1,1),n-1,o?n-1:r)}else this.unplaced=new A(Ri(e,n,1),n,r)}placeNodes({sliceDepth:e,frontierDepth:n,parent:r,inject:i,wrap:o}){for(;this.depth>n;)this.closeFrontierNode();if(o)for(let y=0;y1||a==0||y.content.size)&&(d=v,c.push(Ry(y.mark(f.allowedMarks(y.marks)),u==1?a:0,u==l.childCount?h:-1)))}let p=u==l.childCount;p||(h=-1),this.placed=Ii(this.placed,n,C.from(c)),this.frontier[n].match=d,p&&h<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let y=0,v=l;y1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let n=Math.min(this.depth,e.depth);n>=0;n--){let{match:r,type:i}=this.frontier[n],o=n=0;l--){let{match:a,type:u}=this.frontier[l],c=Ja(e,l,u,a,!0);if(!c||c.childCount)continue e}return{depth:n,fit:s,move:o?e.doc.resolve(e.after(n+1)):e}}}}close(e){let n=this.findCloseLevel(e);if(!n)return null;for(;this.depth>n.depth;)this.closeFrontierNode();n.fit.childCount&&(this.placed=Ii(this.placed,n.depth,n.fit)),e=n.move;for(let r=n.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,n=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Ii(this.placed,this.depth,C.from(e.create(n,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let n=this.frontier.pop().match.fillBefore(C.empty,!0);n.childCount&&(this.placed=Ii(this.placed,this.frontier.length,n))}}function Ri(t,e,n){return e==0?t.cutByIndex(n,t.childCount):t.replaceChild(0,t.firstChild.copy(Ri(t.firstChild.content,e-1,n)))}function Ii(t,e,n){return e==0?t.append(n):t.replaceChild(t.childCount-1,t.lastChild.copy(Ii(t.lastChild.content,e-1,n)))}function Ka(t,e){for(let n=0;n1&&(r=r.replaceChild(0,Ry(r.firstChild,e-1,r.childCount==1?n-1:0))),e>0&&(r=t.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(t.type.contentMatch.matchFragment(r).fillBefore(C.empty,!0)))),t.copy(r)}function Ja(t,e,n,r,i){let o=t.node(e),s=i?t.indexAfter(e):t.index(e);if(s==o.childCount&&!n.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!tS(n,o.content,s)?l:null}function tS(t,e,n){for(let r=n;r0;f--,h--){let p=i.node(f).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;s.indexOf(f)>-1?l=f:i.before(f)==h&&s.splice(1,0,-f)}let a=s.indexOf(l),u=[],c=r.openStart;for(let f=r.content,h=0;;h++){let p=f.firstChild;if(u.push(p),h==r.openStart)break;f=p.content}for(let f=c-1;f>=0;f--){let h=u[f],p=nS(h.type);if(p&&!h.sameMarkup(i.node(Math.abs(l)-1)))c=f;else if(p||!h.type.isTextblock)break}for(let f=r.openStart;f>=0;f--){let h=(f+c+1)%(r.openStart+1),p=u[h];if(p)for(let y=0;y=0&&(t.replace(e,n,r),!(t.steps.length>d));f--){let h=s[f];h<0||(e=i.before(h),n=o.after(h))}}function Iy(t,e,n,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(t).append(t);t=s.append(o.matchFragment(s).fillBefore(C.empty,!0))}return t}function iS(t,e,n,r){if(!r.isInline&&e==n&&t.doc.resolve(e).parent.content.size){let i=Zv(t.doc,e,r.type);i!=null&&(e=n=i)}t.replaceRange(e,n,new A(C.from(r),0,0))}function oS(t,e,n){let r=t.doc.resolve(e),i=t.doc.resolve(n),o=Ly(r,i);for(let s=0;s0&&(a||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return t.delete(r.before(l),i.after(l))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&n>r.end(s)&&i.end(s)-n!=i.depth-s)return t.delete(r.before(s),n);t.delete(e,n)}function Ly(t,e){let n=[],r=Math.min(t.depth,e.depth);for(let i=r;i>=0;i--){let o=t.start(i);if(oe.pos+(e.depth-i)||t.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==t.depth&&i==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&n.push(i)}return n}class Gr extends Re{constructor(e,n,r){super(),this.pos=e,this.attr=n,this.value=r}apply(e){let n=e.nodeAt(this.pos);if(!n)return ae.fail("No node at attribute step's position");let r=Object.create(null);for(let o in n.attrs)r[o]=n.attrs[o];r[this.attr]=this.value;let i=n.type.create(r,null,n.marks);return ae.fromReplace(e,this.pos,this.pos+1,new A(C.from(i),0,n.isLeaf?0:1))}getMap(){return Ye.empty}invert(e){return new Gr(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new Gr(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new Gr(n.pos,n.attr,n.value)}}Re.jsonID("attr",Gr);class mo extends Re{constructor(e,n){super(),this.attr=e,this.value=n}apply(e){let n=Object.create(null);for(let i in e.attrs)n[i]=e.attrs[i];n[this.attr]=this.value;let r=e.type.create(n,e.content,e.marks);return ae.ok(r)}getMap(){return Ye.empty}invert(e){return new mo(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new mo(n.attr,n.value)}}Re.jsonID("docAttr",mo);let si=class extends Error{};si=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n};si.prototype=Object.create(Error.prototype);si.prototype.constructor=si;si.prototype.name="TransformError";class Dy{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new qr}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let n=this.maybeStep(e);if(n.failed)throw new si(n.failed);return this}maybeStep(e){let n=e.apply(this.doc);return n.failed||this.addStep(e,n.doc),n}get docChanged(){return this.steps.length>0}addStep(e,n){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=n}replace(e,n=e,r=A.empty){let i=zd(this.doc,e,n,r);return i&&this.step(i),this}replaceWith(e,n,r){return this.replace(e,n,new A(C.from(r),0,0))}delete(e,n){return this.replace(e,n,A.empty)}insert(e,n){return this.replaceWith(e,e,n)}replaceRange(e,n,r){return rS(this,e,n,r),this}replaceRangeWith(e,n,r){return iS(this,e,n,r),this}deleteRange(e,n){return oS(this,e,n),this}lift(e,n){return Uv(this,e,n),this}join(e,n=1){return Xv(this,e,n),this}wrap(e,n){return Jv(this,e,n),this}setBlockType(e,n=e,r,i=null){return qv(this,e,n,r,i),this}setNodeMarkup(e,n,r=null,i){return Gv(this,e,n,r,i),this}setNodeAttribute(e,n,r){return this.step(new Gr(e,n,r)),this}setDocAttribute(e,n){return this.step(new mo(e,n)),this}addNodeMark(e,n){return this.step(new Sn(e,n)),this}removeNodeMark(e,n){if(!(n instanceof U)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(n=n.isInSet(r.marks),!n)return this}return this.step(new oi(e,n)),this}split(e,n=1,r){return Yv(this,e,n,r),this}addMark(e,n,r){return Hv(this,e,n,r),this}removeMark(e,n,r){return $v(this,e,n,r),this}clearIncompatible(e,n,r){return jv(this,e,n,r),this}}const qa=Object.create(null);class _{constructor(e,n,r){this.$anchor=e,this.$head=n,this.ranges=r||[new sS(e.min(n),e.max(n))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let n=0;n=0;o--){let s=n<0?Mr(e.node(0),e.node(o),e.before(o+1),e.index(o),n,r):Mr(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,n,r);if(s)return s}return null}static near(e,n=1){return this.findFrom(e,n)||this.findFrom(e,-n)||new xt(e.node(0))}static atStart(e){return Mr(e,e,0,0,1)||new xt(e)}static atEnd(e){return Mr(e,e,e.content.size,e.childCount,-1)||new xt(e)}static fromJSON(e,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=qa[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in qa)throw new RangeError("Duplicate use of selection JSON ID "+e);return qa[e]=n,n.prototype.jsonID=e,n}getBookmark(){return P.between(this.$anchor,this.$head).getBookmark()}}_.prototype.visible=!0;class sS{constructor(e,n){this.$from=e,this.$to=n}}let bh=!1;function Rh(t){!bh&&!t.parent.inlineContent&&(bh=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class P extends _{constructor(e,n=e){Rh(e),Rh(n),super(e,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,n){let r=e.resolve(n.map(this.head));if(!r.parent.inlineContent)return _.near(r);let i=e.resolve(n.map(this.anchor));return new P(i.parent.inlineContent?i:r,r)}replace(e,n=A.empty){if(super.replace(e,n),n==A.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof P&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new ra(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new P(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){let i=e.resolve(n);return new this(i,r==n?i:e.resolve(r))}static between(e,n,r){let i=e.pos-n.pos;if((!r||i)&&(r=i>=0?1:-1),!n.parent.inlineContent){let o=_.findFrom(n,r,!0)||_.findFrom(n,-r,!0);if(o)n=o.$head;else return _.near(n,r)}return e.parent.inlineContent||(i==0?e=n:(e=(_.findFrom(e,-r,!0)||_.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?s=0;s+=i){let l=e.child(s);if(l.isAtom){if(!o&&L.isSelectable(l))return L.create(t,n-(i<0?l.nodeSize:0))}else{let a=Mr(t,l,n+i,i<0?l.childCount:0,i,o);if(a)return a}n+=l.nodeSize*i}return null}function Ih(t,e,n){let r=t.steps.length-1;if(r{s==null&&(s=c)}),t.setSelection(_.near(t.doc.resolve(s),n))}const Lh=1,Zo=2,Dh=4;class aS extends Dy{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Zo,this}ensureMarks(e){return U.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Zo)>0}addStep(e,n){super.addStep(e,n),this.updated=this.updated&~Zo,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,n=!0){let r=this.selection;return n&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||U.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,n,r){let i=this.doc.type.schema;if(n==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=n),r=r??n,!e)return this.deleteRange(n,r);let o=this.storedMarks;if(!o){let s=this.doc.resolve(n);o=r==n?s.marks():s.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(n,r,i.text(e,o)),this.selection.empty||this.setSelection(_.near(this.selection.$to)),this}}setMeta(e,n){return this.meta[typeof e=="string"?e:e.key]=n,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=Dh,this}get scrolledIntoView(){return(this.updated&Dh)>0}}function Ph(t,e){return!e||!t?t:t.bind(e)}class Li{constructor(e,n,r){this.name=e,this.init=Ph(n.init,r),this.apply=Ph(n.apply,r)}}const uS=[new Li("doc",{init(t){return t.doc||t.schema.topNodeType.createAndFill()},apply(t){return t.doc}}),new Li("selection",{init(t,e){return t.selection||_.atStart(e.doc)},apply(t){return t.selection}}),new Li("storedMarks",{init(t){return t.storedMarks||null},apply(t,e,n,r){return r.selection.$cursor?t.storedMarks:null}}),new Li("scrollToSelection",{init(){return 0},apply(t,e){return t.scrolledIntoView?e+1:e}})];class Qa{constructor(e,n){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=uS.slice(),n&&n.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new Li(r.key,r.spec.state,r))})}}class Hr{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,n=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],o=i.spec.state;o&&o.toJSON&&(n[r]=o.toJSON.call(i,this[i.key]))}return n}static fromJSON(e,n,r){if(!n)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Qa(e.schema,e.plugins),o=new Hr(i);return i.fields.forEach(s=>{if(s.name=="doc")o.doc=lr.fromJSON(e.schema,n.doc);else if(s.name=="selection")o.selection=_.fromJSON(o.doc,n.selection);else if(s.name=="storedMarks")n.storedMarks&&(o.storedMarks=n.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let a=r[l],u=a.spec.state;if(a.key==s.name&&u&&u.fromJSON&&Object.prototype.hasOwnProperty.call(n,l)){o[s.name]=u.fromJSON.call(a,e,n[l],o);return}}o[s.name]=s.init(e,o)}}),o}}function Py(t,e,n){for(let r in t){let i=t[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Py(i,e,{})),n[r]=i}return n}class He{constructor(e){this.spec=e,this.props={},e.props&&Py(e.props,this,this.props),this.key=e.key?e.key.key:zy("plugin")}getState(e){return e[this.key]}}const Ga=Object.create(null);function zy(t){return t in Ga?t+"$"+ ++Ga[t]:(Ga[t]=0,t+"$")}class Mt{constructor(e="key"){this.key=zy(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const Le=function(t){for(var e=0;;e++)if(t=t.previousSibling,!t)return e},go=function(t){let e=t.assignedSlot||t.parentNode;return e&&e.nodeType==11?e.host:e};let zh=null;const Kt=function(t,e,n){let r=zh||(zh=document.createRange());return r.setEnd(t,n??t.nodeValue.length),r.setStart(t,e||0),r},gr=function(t,e,n,r){return n&&(Bh(t,e,n,r,-1)||Bh(t,e,n,r,1))},cS=/^(img|br|input|textarea|hr)$/i;function Bh(t,e,n,r,i){for(;;){if(t==n&&e==r)return!0;if(e==(i<0?0:Pt(t))){let o=t.parentNode;if(!o||o.nodeType!=1||Fd(t)||cS.test(t.nodeName)||t.contentEditable=="false")return!1;e=Le(t)+(i<0?0:1),t=o}else if(t.nodeType==1){if(t=t.childNodes[e+(i<0?-1:0)],t.contentEditable=="false")return!1;e=i<0?Pt(t):0}else return!1}}function Pt(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function dS(t,e,n){for(let r=e==0,i=e==Pt(t);r||i;){if(t==n)return!0;let o=Le(t);if(t=t.parentNode,!t)return!1;r=r&&o==0,i=i&&o==Pt(t)}}function Fd(t){let e;for(let n=t;n&&!(e=n.pmViewDesc);n=n.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==t||e.contentDOM==t)}const ia=function(t){return t.focusNode&&gr(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)};function Qn(t,e){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=t,n.key=n.code=e,n}function fS(t){let e=t.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function hS(t,e,n){if(t.caretPositionFromPoint)try{let r=t.caretPositionFromPoint(e,n);if(r)return{node:r.offsetNode,offset:r.offset}}catch{}if(t.caretRangeFromPoint){let r=t.caretRangeFromPoint(e,n);if(r)return{node:r.startContainer,offset:r.startOffset}}}const Ht=typeof navigator<"u"?navigator:null,Fh=typeof document<"u"?document:null,jn=Ht&&Ht.userAgent||"",pc=/Edge\/(\d+)/.exec(jn),By=/MSIE \d/.exec(jn),mc=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(jn),Je=!!(By||mc||pc),bn=By?document.documentMode:mc?+mc[1]:pc?+pc[1]:0,Et=!Je&&/gecko\/(\d+)/i.test(jn);Et&&+(/Firefox\/(\d+)/.exec(jn)||[0,0])[1];const gc=!Je&&/Chrome\/(\d+)/.exec(jn),Ae=!!gc,pS=gc?+gc[1]:0,Pe=!Je&&!!Ht&&/Apple Computer/.test(Ht.vendor),li=Pe&&(/Mobile\/\w+/.test(jn)||!!Ht&&Ht.maxTouchPoints>2),ot=li||(Ht?/Mac/.test(Ht.platform):!1),mS=Ht?/Win/.test(Ht.platform):!1,kt=/Android \d/.test(jn),No=!!Fh&&"webkitFontSmoothing"in Fh.documentElement.style,gS=No?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function yS(t){return{left:0,right:t.documentElement.clientWidth,top:0,bottom:t.documentElement.clientHeight}}function Vt(t,e){return typeof t=="number"?t:t[e]}function kS(t){let e=t.getBoundingClientRect(),n=e.width/t.offsetWidth||1,r=e.height/t.offsetHeight||1;return{left:e.left,right:e.left+t.clientWidth*n,top:e.top,bottom:e.top+t.clientHeight*r}}function _h(t,e,n){let r=t.someProp("scrollThreshold")||0,i=t.someProp("scrollMargin")||5,o=t.dom.ownerDocument;for(let s=n||t.dom;s;s=go(s)){if(s.nodeType!=1)continue;let l=s,a=l==o.body,u=a?yS(o):kS(l),c=0,d=0;if(e.topu.bottom-Vt(r,"bottom")&&(d=e.bottom-e.top>u.bottom-u.top?e.top+Vt(i,"top")-u.top:e.bottom-u.bottom+Vt(i,"bottom")),e.leftu.right-Vt(r,"right")&&(c=e.right-u.right+Vt(i,"right")),c||d)if(a)o.defaultView.scrollBy(c,d);else{let f=l.scrollLeft,h=l.scrollTop;d&&(l.scrollTop+=d),c&&(l.scrollLeft+=c);let p=l.scrollLeft-f,y=l.scrollTop-h;e={left:e.left-p,top:e.top-y,right:e.right-p,bottom:e.bottom-y}}if(a||/^(fixed|sticky)$/.test(getComputedStyle(s).position))break}}function vS(t){let e=t.dom.getBoundingClientRect(),n=Math.max(0,e.top),r,i;for(let o=(e.left+e.right)/2,s=n+1;s=n-20){r=l,i=a.top;break}}return{refDOM:r,refTop:i,stack:Fy(t.dom)}}function Fy(t){let e=[],n=t.ownerDocument;for(let r=t;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),t!=n);r=go(r));return e}function SS({refDOM:t,refTop:e,stack:n}){let r=t?t.getBoundingClientRect().top:0;_y(n,r==0?0:r-e)}function _y(t,e){for(let n=0;n=l){s=Math.max(p.bottom,s),l=Math.min(p.top,l);let y=p.left>e.left?p.left-e.left:p.right=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!a&&p.left<=e.left&&p.right>=e.left&&(a=c,u={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!n&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(o=d+1)}}return!n&&a&&(n=a,i=u,r=0),n&&n.nodeType==3?xS(n,i):!n||r&&n.nodeType==1?{node:t,offset:o}:Hy(n,i)}function xS(t,e){let n=t.nodeValue.length,r=document.createRange();for(let i=0;i=(o.left+o.right)/2?1:0)}}return{node:t,offset:0}}function _d(t,e){return t.left>=e.left-1&&t.left<=e.right+1&&t.top>=e.top-1&&t.top<=e.bottom+1}function CS(t,e){let n=t.parentNode;return n&&/^li$/i.test(n.nodeName)&&e.left(s.left+s.right)/2?1:-1}return t.docView.posFromDOM(r,i,o)}function MS(t,e,n,r){let i=-1;for(let o=e,s=!1;o!=t.dom;){let l=t.docView.nearestDesc(o,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent&&!s||!l.contentDOM)){let a=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&!s&&(s=!0,a.left>r.left||a.top>r.top?i=l.posBefore:(a.right-1?i:t.docView.posFromDOM(e,n,-1)}function $y(t,e,n){let r=t.childNodes.length;if(r&&n.tope.top&&i++}let u;No&&i&&r.nodeType==1&&(u=r.childNodes[i-1]).nodeType==1&&u.contentEditable=="false"&&u.getBoundingClientRect().top>=e.top&&i--,r==t.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=t.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=MS(t,r,i,e))}l==null&&(l=ES(t,s,e));let a=t.docView.nearestDesc(s,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function Hh(t){return t.top=0&&i==r.nodeValue.length?(a--,c=1):n<0?a--:u++,Mi(ln(Kt(r,a,u),c),c<0)}if(!t.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&i&&(n<0||i==Pt(r))){let a=r.childNodes[i-1];if(a.nodeType==1)return Ya(a.getBoundingClientRect(),!1)}if(o==null&&i=0)}if(o==null&&i&&(n<0||i==Pt(r))){let a=r.childNodes[i-1],u=a.nodeType==3?Kt(a,Pt(a)-(s?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(u)return Mi(ln(u,1),!1)}if(o==null&&i=0)}function Mi(t,e){if(t.width==0)return t;let n=e?t.left:t.right;return{top:t.top,bottom:t.bottom,left:n,right:n}}function Ya(t,e){if(t.height==0)return t;let n=e?t.top:t.bottom;return{top:n,bottom:n,left:t.left,right:t.right}}function Vy(t,e,n){let r=t.state,i=t.root.activeElement;r!=e&&t.updateState(e),i!=t.dom&&t.focus();try{return n()}finally{r!=e&&t.updateState(r),i!=t.dom&&i&&i.focus()}}function NS(t,e,n){let r=e.selection,i=n=="up"?r.$from:r.$to;return Vy(t,e,()=>{let{node:o}=t.docView.domFromPos(i.pos,n=="up"?-1:1);for(;;){let l=t.docView.nearestDesc(o,!0);if(!l)break;if(l.node.isBlock){o=l.contentDOM||l.dom;break}o=l.dom.parentNode}let s=jy(t,i.pos,1);for(let l=o.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=Kt(l,0,l.nodeValue.length).getClientRects();else continue;for(let u=0;uc.top+1&&(n=="up"?s.top-c.top>(c.bottom-s.top)*2:c.bottom-s.bottom>(s.bottom-c.top)*2))return!1}}return!0})}const AS=/[\u0590-\u08ac]/;function bS(t,e,n){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,l=t.domSelection();return!AS.test(r.parent.textContent)||!l.modify?n=="left"||n=="backward"?o:s:Vy(t,e,()=>{let{focusNode:a,focusOffset:u,anchorNode:c,anchorOffset:d}=t.domSelectionRange(),f=l.caretBidiLevel;l.modify("move",n,"character");let h=r.depth?t.docView.domAfterPos(r.before()):t.dom,{focusNode:p,focusOffset:y}=t.domSelectionRange(),v=p&&!h.contains(p.nodeType==1?p:p.parentNode)||a==p&&u==y;try{l.collapse(c,d),a&&(a!=c||u!=d)&&l.extend&&l.extend(a,u)}catch{}return f!=null&&(l.caretBidiLevel=f),v})}let $h=null,jh=null,Vh=!1;function RS(t,e,n){return $h==e&&jh==n?Vh:($h=e,jh=n,Vh=n=="up"||n=="down"?NS(t,e,n):bS(t,e,n))}const dt=0,Uh=1,Zn=2,$t=3;class Ao{constructor(e,n,r,i){this.parent=e,this.children=n,this.dom=r,this.contentDOM=i,this.dirty=dt,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,n,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let n=0;nLe(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(n==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&n==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,n=!1){for(let r=!0,i=e;i;i=i.parentNode){let o=this.getDesc(i),s;if(o&&(!n||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){let n=e.pmViewDesc;for(let r=n;r;r=r.parent)if(r==this)return n}posFromDOM(e,n,r){for(let i=e;i;i=i.parentNode){let o=this.getDesc(i);if(o)return o.localPosFromDOM(e,n,r)}return-1}descAt(e){for(let n=0,r=0;ne||s instanceof Wy){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,n);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof Uy&&o.side>=0;r--);if(n<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&n&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,n):{node:this.contentDOM,offset:o?Le(o.dom)+1:0}}else{let o,s=!0;for(;o=r=c&&n<=u-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,n,c);e=s;for(let d=l;d>0;d--){let f=this.children[d-1];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(1)){i=Le(f.dom)+1;break}e-=f.size}i==-1&&(i=0)}if(i>-1&&(u>n||l==this.children.length-1)){n=u;for(let c=l+1;ch&&s{s.clearMark(l)&&(r=l.addToSet(r))}):n=this.parser.schema.marks[s.mark].create(s.attrs).addToSet(n),s.consuming===!1)o=s;else break}return[n,r]}addElementByRule(e,n,r){let i,o,s;n.node?(o=this.parser.schema.nodes[n.node],o.isLeaf?this.insertNode(o.create(n.attrs))||this.leafFallback(e):i=this.enter(o,n.attrs||null,n.preserveWhitespace)):(s=this.parser.schema.marks[n.mark].create(n.attrs),this.addPendingMark(s));let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(r)this.addElement(e,r);else if(n.getContent)this.findInside(e),n.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a));else{let a=e;typeof n.contentElement=="string"?a=e.querySelector(n.contentElement):typeof n.contentElement=="function"?a=n.contentElement(e):n.contentElement&&(a=n.contentElement),this.findAround(e,a,!0),this.addAll(a)}i&&this.sync(l)&&this.open--,s&&this.removePendingMark(s,l)}addAll(e,n,r){let i=n||0;for(let o=n?e.childNodes[n]:e.firstChild,s=r==null?null:e.childNodes[r];o!=s;o=o.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(o);this.findAtPoint(e,i)}findPlace(e){let n,r;for(let i=this.open;i>=0;i--){let o=this.nodes[i],s=o.findWrapping(e);if(s&&(!n||n.length>s.length)&&(n=s,r=o,!s.length)||o.solid)break}if(!n)return!1;this.sync(r);for(let i=0;ithis.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let n=this.open;n>=0;n--)if(this.nodes[n]==e)return this.open=n,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;n&&e++}return e}findAtPoint(e,n){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let n=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(i?0:1),s=(l,a)=>{for(;l>=0;l--){let u=n[l];if(u==""){if(l==n.length-1||l==0)continue;for(;a>=o;a--)if(s(l-1,a))return!0;return!1}else{let c=a>0||a==0&&i?this.nodes[a].type:r&&a>=o?r.node(a-o).type:null;if(!c||c.name!=u&&c.groups.indexOf(u)==-1)return!1;a--}}return!0};return s(n.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let n=e.depth;n>=0;n--){let r=e.node(n).contentMatchAt(e.indexAfter(n)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let n in this.parser.schema.nodes){let r=this.parser.schema.nodes[n];if(r.isTextblock&&r.defaultAttrs)return r}}addPendingMark(e){let n=Bv(e,this.top.pendingMarks);n&&this.top.stashMarks.push(n),this.top.pendingMarks=e.addToSet(this.top.pendingMarks)}removePendingMark(e,n){for(let r=this.open;r>=0;r--){let i=this.nodes[r];if(i.pendingMarks.lastIndexOf(e)>-1)i.pendingMarks=e.removeFromSet(i.pendingMarks);else{i.activeMarks=e.removeFromSet(i.activeMarks);let s=i.popFromStashMark(e);s&&i.type&&i.type.allowsMarkType(s.type)&&(i.activeMarks=s.addToSet(i.activeMarks))}if(i==n)break}}}function Lv(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&xy.hasOwnProperty(r)&&n?(n.appendChild(e),e=n):r=="li"?n=e:r&&(n=null)}}function Dv(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function Pv(t){let e=/\s*([\w-]+)\s*:\s*([^;]+)/g,n,r=[];for(;n=e.exec(t);)r.push(n[1],n[2].trim());return r}function Th(t){let e={};for(let n in t)e[n]=t[n];return e}function zv(t,e){let n=e.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(t))continue;let o=[],s=l=>{o.push(l);for(let a=0;a{if(o.length||s.marks.length){let l=0,a=0;for(;l=0;i--){let o=this.serializeMark(e.marks[i],e.isInline,n);o&&((o.contentDOM||o.dom).appendChild(r),r=o.dom)}return r}serializeMark(e,n,r={}){let i=this.marks[e.type.name];return i&&zt.renderSpec(Ua(r),i(e,n))}static renderSpec(e,n,r=null){if(typeof n=="string")return{dom:e.createTextNode(n)};if(n.nodeType!=null)return{dom:n};if(n.dom&&n.dom.nodeType!=null)return n;let i=n[0],o=i.indexOf(" ");o>0&&(r=i.slice(0,o),i=i.slice(o+1));let s,l=r?e.createElementNS(r,i):e.createElement(i),a=n[1],u=1;if(a&&typeof a=="object"&&a.nodeType==null&&!Array.isArray(a)){u=2;for(let c in a)if(a[c]!=null){let d=c.indexOf(" ");d>0?l.setAttributeNS(c.slice(0,d),c.slice(d+1),a[c]):l.setAttribute(c,a[c])}}for(let c=u;cu)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}else{let{dom:f,contentDOM:h}=zt.renderSpec(e,d,r);if(l.appendChild(f),h){if(s)throw new RangeError("Multiple content holes");s=h}}}return{dom:l,contentDOM:s}}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new zt(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let n=Oh(e.nodes);return n.text||(n.text=r=>r.text),n}static marksFromSchema(e){return Oh(e.marks)}}function Oh(t){let e={};for(let n in t){let r=t[n].spec.toDOM;r&&(e[n]=r)}return e}function Ua(t){return t.document||window.document}const Cy=65535,Ey=Math.pow(2,16);function Fv(t,e){return t+e*Ey}function Nh(t){return t&Cy}function _v(t){return(t-(t&Cy))/Ey}const My=1,Ty=2,ks=4,Oy=8;class fc{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&Oy)>0}get deletedBefore(){return(this.delInfo&(My|ks))>0}get deletedAfter(){return(this.delInfo&(Ty|ks))>0}get deletedAcross(){return(this.delInfo&ks)>0}}class Ye{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&Ye.empty)return Ye.empty}recover(e){let n=0,r=Nh(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],d=a+u;if(e<=d){let f=u?e==a?-1:e==d?1:n:n,h=a+i+(f<0?0:c);if(r)return h;let p=e==(n<0?a:d)?null:Fv(l/3,e-a),y=e==a?Ty:e==d?My:ks;return(n<0?e!=a:e!=d)&&(y|=Oy),new fc(h,y,p)}i+=c-u}return r?e+i:new fc(e+i,0,null)}touches(e,n){let r=0,i=Nh(n),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let n=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i=0;n--){let i=e.getMirror(n);this.appendMap(e.maps[n].invert(),i!=null&&i>n?r-i-1:void 0)}}invert(){let e=new qr;return e.appendMappingInverted(this),e}map(e,n=1){if(this.mirror)return this._map(e,n,!0);for(let r=this.from;ro&&a!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),n.openStart,n.openEnd);return ae.fromReplace(e,this.from,this.to,o)}invert(){return new Bt(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new vn(n.pos,r.pos,this.mark)}merge(e){return e instanceof vn&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new vn(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new vn(n.from,n.to,e.markFromJSON(n.mark))}}Re.jsonID("addMark",vn);class Bt extends Re{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=new A(Dd(n.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),n.openStart,n.openEnd);return ae.fromReplace(e,this.from,this.to,r)}invert(){return new vn(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new Bt(n.pos,r.pos,this.mark)}merge(e){return e instanceof Bt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Bt(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Bt(n.from,n.to,e.markFromJSON(n.mark))}}Re.jsonID("removeMark",Bt);class Sn extends Re{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return ae.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return ae.fromReplace(e,this.pos,this.pos+1,new A(C.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let i=0;ir.pos?null:new ge(n.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new ge(n.from,n.to,n.gapFrom,n.gapTo,A.fromJSON(e,n.slice),n.insert,!!n.structure)}}Re.jsonID("replaceAround",ge);function hc(t,e,n){let r=t.resolve(e),i=n-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function Hv(t,e,n,r){let i=[],o=[],s,l;t.doc.nodesBetween(e,n,(a,u,c)=>{if(!a.isInline)return;let d=a.marks;if(!r.isInSet(d)&&c.type.allowsMarkType(r.type)){let f=Math.max(u,e),h=Math.min(u+a.nodeSize,n),p=r.addToSet(d);for(let y=0;yt.step(a)),o.forEach(a=>t.step(a))}function $v(t,e,n,r){let i=[],o=0;t.doc.nodesBetween(e,n,(s,l)=>{if(!s.isInline)return;o++;let a=null;if(r instanceof ta){let u=s.marks,c;for(;c=r.isInSet(u);)(a||(a=[])).push(c),u=c.removeFromSet(u)}else r?r.isInSet(s.marks)&&(a=[r]):a=s.marks;if(a&&a.length){let u=Math.min(l+s.nodeSize,n);for(let c=0;ct.step(new Bt(s.from,s.to,s.style)))}function jv(t,e,n,r=n.contentMatch){let i=t.doc.nodeAt(e),o=[],s=e+1;for(let l=0;l=0;l--)t.step(o[l])}function Vv(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function pi(t){let n=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let r=t.depth;;--r){let i=t.$from.node(r),o=t.$from.index(r),s=t.$to.indexAfter(r);if(rn;p--)y||r.index(p)>0?(y=!0,c=C.from(r.node(p).copy(c)),d++):a--;let f=C.empty,h=0;for(let p=o,y=!1;p>n;p--)y||i.after(p+1)=0;s--){if(r.size){let l=n[s].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=C.from(n[s].type.create(n[s].attrs,r))}let i=e.start,o=e.end;t.step(new ge(i,o,i,o,new A(r,0,0),n.length,!0))}function qv(t,e,n,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=t.steps.length;t.doc.nodesBetween(e,n,(s,l)=>{if(s.isTextblock&&!s.hasMarkup(r,i)&&Qv(t.doc,t.mapping.slice(o).map(l),r)){t.clearIncompatible(t.mapping.slice(o).map(l,1),r);let a=t.mapping.slice(o),u=a.map(l,1),c=a.map(l+s.nodeSize,1);return t.step(new ge(u,c,u+1,c-1,new A(C.from(r.create(i,null,s.marks)),0,0),1,!0)),!1}})}function Qv(t,e,n){let r=t.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function Gv(t,e,n,r,i){let o=t.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");n||(n=o.type);let s=n.create(r,null,i||o.marks);if(o.isLeaf)return t.replaceWith(e,e+o.nodeSize,s);if(!n.validContent(o.content))throw new RangeError("Invalid content for node type "+n.name);t.step(new ge(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new A(C.from(s),0,0),1,!0))}function Qr(t,e,n=1,r){let i=t.resolve(e),o=i.depth-n,s=r&&r[r.length-1]||i.parent;if(o<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!s.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let u=i.depth-1,c=n-2;u>o;u--,c--){let d=i.node(u),f=i.index(u);if(d.type.spec.isolating)return!1;let h=d.content.cutByIndex(f,d.childCount),p=r&&r[c+1];p&&(h=h.replaceChild(0,p.type.create(p.attrs)));let y=r&&r[c]||d;if(!d.canReplace(f+1,d.childCount)||!y.type.validContent(h))return!1}let l=i.indexAfter(o),a=r&&r[0];return i.node(o).canReplaceWith(l,l,a?a.type:i.node(o+1).type)}function Yv(t,e,n=1,r){let i=t.doc.resolve(e),o=C.empty,s=C.empty;for(let l=i.depth,a=i.depth-n,u=n-1;l>a;l--,u--){o=C.from(i.node(l).copy(o));let c=r&&r[u];s=C.from(c?c.type.create(c.attrs,s):i.node(l).copy(s))}t.step(new we(e,e,new A(o.append(s),n,n),!0))}function $n(t,e){let n=t.resolve(e),r=n.index();return Ny(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function Ny(t,e){return!!(t&&e&&!t.isLeaf&&t.canAppend(e))}function na(t,e,n=-1){let r=t.resolve(e);for(let i=r.depth;;i--){let o,s,l=r.index(i);if(i==r.depth?(o=r.nodeBefore,s=r.nodeAfter):n>0?(o=r.node(i+1),l++,s=r.node(i).maybeChild(l)):(o=r.node(i).maybeChild(l-1),s=r.node(i+1)),o&&!o.isTextblock&&Ny(o,s)&&r.node(i).canReplace(l,l+1))return e;if(i==0)break;e=n<0?r.before(i):r.after(i)}}function Xv(t,e,n){let r=new we(e-n,e+n,A.empty,!0);t.step(r)}function Zv(t,e,n){let r=t.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),n))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let o=r.index(i);if(r.node(i).canReplaceWith(o,o,n))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,n))return r.after(i+1);if(o=0;s--){let l=s==r.depth?0:r.pos<=(r.start(s+1)+r.end(s+1))/2?-1:1,a=r.index(s)+(l>0?1:0),u=r.node(s),c=!1;if(o==1)c=u.canReplace(a,a,i);else{let d=u.contentMatchAt(a).findWrapping(i.firstChild.type);c=d&&u.canReplaceWith(a,a,d[0])}if(c)return l==0?r.pos:l<0?r.before(s+1):r.after(s+1)}return null}function zd(t,e,n=e,r=A.empty){if(e==n&&!r.size)return null;let i=t.resolve(e),o=t.resolve(n);return by(i,o,r)?new we(e,n,r):new eS(i,o,r).fit()}function by(t,e,n){return!n.openStart&&!n.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),n.content)}class eS{constructor(e,n,r){this.$from=e,this.$to=n,this.unplaced=r,this.frontier=[],this.placed=C.empty;for(let i=0;i<=e.depth;i++){let o=e.node(i);this.frontier.push({type:o.type,match:o.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=C.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let u=this.findFittable();u?this.placeNodes(u):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),n=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let a=new A(o,s,l);return e>-1?new ge(r.pos,e,this.$to.pos,this.$to.end(),a,n):a.size||r.pos!=this.$to.pos?new we(r.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let n=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),o.type.spec.isolating&&i<=r){e=r;break}n=o.content}for(let n=1;n<=2;n++)for(let r=n==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=Ka(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:u}=this.frontier[l],c,d=null;if(n==1&&(s?u.matchType(s.type)||(d=u.fillBefore(C.from(s),!1)):o&&a.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:d};if(n==2&&s&&(c=u.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:c};if(o&&u.matchType(o.type))break}}}openMore(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=Ka(e,n);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new A(e,n+1,Math.max(r,i.size+n>=e.size-r?n+1:0)),!0)}dropNode(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=Ka(e,n);if(i.childCount<=1&&n>0){let o=e.size-n<=n+i.size;this.unplaced=new A(Ri(e,n-1,1),n-1,o?n-1:r)}else this.unplaced=new A(Ri(e,n,1),n,r)}placeNodes({sliceDepth:e,frontierDepth:n,parent:r,inject:i,wrap:o}){for(;this.depth>n;)this.closeFrontierNode();if(o)for(let y=0;y1||a==0||y.content.size)&&(d=v,c.push(Ry(y.mark(f.allowedMarks(y.marks)),u==1?a:0,u==l.childCount?h:-1)))}let p=u==l.childCount;p||(h=-1),this.placed=Ii(this.placed,n,C.from(c)),this.frontier[n].match=d,p&&h<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let y=0,v=l;y1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let n=Math.min(this.depth,e.depth);n>=0;n--){let{match:r,type:i}=this.frontier[n],o=n=0;l--){let{match:a,type:u}=this.frontier[l],c=Ja(e,l,u,a,!0);if(!c||c.childCount)continue e}return{depth:n,fit:s,move:o?e.doc.resolve(e.after(n+1)):e}}}}close(e){let n=this.findCloseLevel(e);if(!n)return null;for(;this.depth>n.depth;)this.closeFrontierNode();n.fit.childCount&&(this.placed=Ii(this.placed,n.depth,n.fit)),e=n.move;for(let r=n.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,n=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Ii(this.placed,this.depth,C.from(e.create(n,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let n=this.frontier.pop().match.fillBefore(C.empty,!0);n.childCount&&(this.placed=Ii(this.placed,this.frontier.length,n))}}function Ri(t,e,n){return e==0?t.cutByIndex(n,t.childCount):t.replaceChild(0,t.firstChild.copy(Ri(t.firstChild.content,e-1,n)))}function Ii(t,e,n){return e==0?t.append(n):t.replaceChild(t.childCount-1,t.lastChild.copy(Ii(t.lastChild.content,e-1,n)))}function Ka(t,e){for(let n=0;n1&&(r=r.replaceChild(0,Ry(r.firstChild,e-1,r.childCount==1?n-1:0))),e>0&&(r=t.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(t.type.contentMatch.matchFragment(r).fillBefore(C.empty,!0)))),t.copy(r)}function Ja(t,e,n,r,i){let o=t.node(e),s=i?t.indexAfter(e):t.index(e);if(s==o.childCount&&!n.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!tS(n,o.content,s)?l:null}function tS(t,e,n){for(let r=n;r0;f--,h--){let p=i.node(f).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;s.indexOf(f)>-1?l=f:i.before(f)==h&&s.splice(1,0,-f)}let a=s.indexOf(l),u=[],c=r.openStart;for(let f=r.content,h=0;;h++){let p=f.firstChild;if(u.push(p),h==r.openStart)break;f=p.content}for(let f=c-1;f>=0;f--){let h=u[f],p=nS(h.type);if(p&&!h.sameMarkup(i.node(Math.abs(l)-1)))c=f;else if(p||!h.type.isTextblock)break}for(let f=r.openStart;f>=0;f--){let h=(f+c+1)%(r.openStart+1),p=u[h];if(p)for(let y=0;y=0&&(t.replace(e,n,r),!(t.steps.length>d));f--){let h=s[f];h<0||(e=i.before(h),n=o.after(h))}}function Iy(t,e,n,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(t).append(t);t=s.append(o.matchFragment(s).fillBefore(C.empty,!0))}return t}function iS(t,e,n,r){if(!r.isInline&&e==n&&t.doc.resolve(e).parent.content.size){let i=Zv(t.doc,e,r.type);i!=null&&(e=n=i)}t.replaceRange(e,n,new A(C.from(r),0,0))}function oS(t,e,n){let r=t.doc.resolve(e),i=t.doc.resolve(n),o=Ly(r,i);for(let s=0;s0&&(a||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return t.delete(r.before(l),i.after(l))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&n>r.end(s)&&i.end(s)-n!=i.depth-s)return t.delete(r.before(s),n);t.delete(e,n)}function Ly(t,e){let n=[],r=Math.min(t.depth,e.depth);for(let i=r;i>=0;i--){let o=t.start(i);if(oe.pos+(e.depth-i)||t.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==t.depth&&i==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&n.push(i)}return n}class Gr extends Re{constructor(e,n,r){super(),this.pos=e,this.attr=n,this.value=r}apply(e){let n=e.nodeAt(this.pos);if(!n)return ae.fail("No node at attribute step's position");let r=Object.create(null);for(let o in n.attrs)r[o]=n.attrs[o];r[this.attr]=this.value;let i=n.type.create(r,null,n.marks);return ae.fromReplace(e,this.pos,this.pos+1,new A(C.from(i),0,n.isLeaf?0:1))}getMap(){return Ye.empty}invert(e){return new Gr(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new Gr(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new Gr(n.pos,n.attr,n.value)}}Re.jsonID("attr",Gr);class mo extends Re{constructor(e,n){super(),this.attr=e,this.value=n}apply(e){let n=Object.create(null);for(let i in e.attrs)n[i]=e.attrs[i];n[this.attr]=this.value;let r=e.type.create(n,e.content,e.marks);return ae.ok(r)}getMap(){return Ye.empty}invert(e){return new mo(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new mo(n.attr,n.value)}}Re.jsonID("docAttr",mo);let si=class extends Error{};si=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n};si.prototype=Object.create(Error.prototype);si.prototype.constructor=si;si.prototype.name="TransformError";class Dy{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new qr}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let n=this.maybeStep(e);if(n.failed)throw new si(n.failed);return this}maybeStep(e){let n=e.apply(this.doc);return n.failed||this.addStep(e,n.doc),n}get docChanged(){return this.steps.length>0}addStep(e,n){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=n}replace(e,n=e,r=A.empty){let i=zd(this.doc,e,n,r);return i&&this.step(i),this}replaceWith(e,n,r){return this.replace(e,n,new A(C.from(r),0,0))}delete(e,n){return this.replace(e,n,A.empty)}insert(e,n){return this.replaceWith(e,e,n)}replaceRange(e,n,r){return rS(this,e,n,r),this}replaceRangeWith(e,n,r){return iS(this,e,n,r),this}deleteRange(e,n){return oS(this,e,n),this}lift(e,n){return Uv(this,e,n),this}join(e,n=1){return Xv(this,e,n),this}wrap(e,n){return Jv(this,e,n),this}setBlockType(e,n=e,r,i=null){return qv(this,e,n,r,i),this}setNodeMarkup(e,n,r=null,i){return Gv(this,e,n,r,i),this}setNodeAttribute(e,n,r){return this.step(new Gr(e,n,r)),this}setDocAttribute(e,n){return this.step(new mo(e,n)),this}addNodeMark(e,n){return this.step(new Sn(e,n)),this}removeNodeMark(e,n){if(!(n instanceof U)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(n=n.isInSet(r.marks),!n)return this}return this.step(new oi(e,n)),this}split(e,n=1,r){return Yv(this,e,n,r),this}addMark(e,n,r){return Hv(this,e,n,r),this}removeMark(e,n,r){return $v(this,e,n,r),this}clearIncompatible(e,n,r){return jv(this,e,n,r),this}}const qa=Object.create(null);class _{constructor(e,n,r){this.$anchor=e,this.$head=n,this.ranges=r||[new sS(e.min(n),e.max(n))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let n=0;n=0;o--){let s=n<0?Mr(e.node(0),e.node(o),e.before(o+1),e.index(o),n,r):Mr(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,n,r);if(s)return s}return null}static near(e,n=1){return this.findFrom(e,n)||this.findFrom(e,-n)||new xt(e.node(0))}static atStart(e){return Mr(e,e,0,0,1)||new xt(e)}static atEnd(e){return Mr(e,e,e.content.size,e.childCount,-1)||new xt(e)}static fromJSON(e,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=qa[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in qa)throw new RangeError("Duplicate use of selection JSON ID "+e);return qa[e]=n,n.prototype.jsonID=e,n}getBookmark(){return P.between(this.$anchor,this.$head).getBookmark()}}_.prototype.visible=!0;class sS{constructor(e,n){this.$from=e,this.$to=n}}let bh=!1;function Rh(t){!bh&&!t.parent.inlineContent&&(bh=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class P extends _{constructor(e,n=e){Rh(e),Rh(n),super(e,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,n){let r=e.resolve(n.map(this.head));if(!r.parent.inlineContent)return _.near(r);let i=e.resolve(n.map(this.anchor));return new P(i.parent.inlineContent?i:r,r)}replace(e,n=A.empty){if(super.replace(e,n),n==A.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof P&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new ra(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new P(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){let i=e.resolve(n);return new this(i,r==n?i:e.resolve(r))}static between(e,n,r){let i=e.pos-n.pos;if((!r||i)&&(r=i>=0?1:-1),!n.parent.inlineContent){let o=_.findFrom(n,r,!0)||_.findFrom(n,-r,!0);if(o)n=o.$head;else return _.near(n,r)}return e.parent.inlineContent||(i==0?e=n:(e=(_.findFrom(e,-r,!0)||_.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?s=0;s+=i){let l=e.child(s);if(l.isAtom){if(!o&&L.isSelectable(l))return L.create(t,n-(i<0?l.nodeSize:0))}else{let a=Mr(t,l,n+i,i<0?l.childCount:0,i,o);if(a)return a}n+=l.nodeSize*i}return null}function Ih(t,e,n){let r=t.steps.length-1;if(r{s==null&&(s=c)}),t.setSelection(_.near(t.doc.resolve(s),n))}const Lh=1,Zo=2,Dh=4;class aS extends Dy{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Zo,this}ensureMarks(e){return U.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Zo)>0}addStep(e,n){super.addStep(e,n),this.updated=this.updated&~Zo,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,n=!0){let r=this.selection;return n&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||U.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,n,r){let i=this.doc.type.schema;if(n==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=n),r=r??n,!e)return this.deleteRange(n,r);let o=this.storedMarks;if(!o){let s=this.doc.resolve(n);o=r==n?s.marks():s.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(n,r,i.text(e,o)),this.selection.empty||this.setSelection(_.near(this.selection.$to)),this}}setMeta(e,n){return this.meta[typeof e=="string"?e:e.key]=n,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=Dh,this}get scrolledIntoView(){return(this.updated&Dh)>0}}function Ph(t,e){return!e||!t?t:t.bind(e)}class Li{constructor(e,n,r){this.name=e,this.init=Ph(n.init,r),this.apply=Ph(n.apply,r)}}const uS=[new Li("doc",{init(t){return t.doc||t.schema.topNodeType.createAndFill()},apply(t){return t.doc}}),new Li("selection",{init(t,e){return t.selection||_.atStart(e.doc)},apply(t){return t.selection}}),new Li("storedMarks",{init(t){return t.storedMarks||null},apply(t,e,n,r){return r.selection.$cursor?t.storedMarks:null}}),new Li("scrollToSelection",{init(){return 0},apply(t,e){return t.scrolledIntoView?e+1:e}})];class Qa{constructor(e,n){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=uS.slice(),n&&n.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new Li(r.key,r.spec.state,r))})}}class Hr{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,n=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],o=i.spec.state;o&&o.toJSON&&(n[r]=o.toJSON.call(i,this[i.key]))}return n}static fromJSON(e,n,r){if(!n)throw new RangeError("Invalid input for EditorNativeState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Qa(e.schema,e.plugins),o=new Hr(i);return i.fields.forEach(s=>{if(s.name=="doc")o.doc=lr.fromJSON(e.schema,n.doc);else if(s.name=="selection")o.selection=_.fromJSON(o.doc,n.selection);else if(s.name=="storedMarks")n.storedMarks&&(o.storedMarks=n.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let a=r[l],u=a.spec.state;if(a.key==s.name&&u&&u.fromJSON&&Object.prototype.hasOwnProperty.call(n,l)){o[s.name]=u.fromJSON.call(a,e,n[l],o);return}}o[s.name]=s.init(e,o)}}),o}}function Py(t,e,n){for(let r in t){let i=t[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Py(i,e,{})),n[r]=i}return n}class He{constructor(e){this.spec=e,this.props={},e.props&&Py(e.props,this,this.props),this.key=e.key?e.key.key:zy("plugin")}getState(e){return e[this.key]}}const Ga=Object.create(null);function zy(t){return t in Ga?t+"$"+ ++Ga[t]:(Ga[t]=0,t+"$")}class Mt{constructor(e="key"){this.key=zy(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const Le=function(t){for(var e=0;;e++)if(t=t.previousSibling,!t)return e},go=function(t){let e=t.assignedSlot||t.parentNode;return e&&e.nodeType==11?e.host:e};let zh=null;const Kt=function(t,e,n){let r=zh||(zh=document.createRange());return r.setEnd(t,n??t.nodeValue.length),r.setStart(t,e||0),r},gr=function(t,e,n,r){return n&&(Bh(t,e,n,r,-1)||Bh(t,e,n,r,1))},cS=/^(img|br|input|textarea|hr)$/i;function Bh(t,e,n,r,i){for(;;){if(t==n&&e==r)return!0;if(e==(i<0?0:Pt(t))){let o=t.parentNode;if(!o||o.nodeType!=1||Fd(t)||cS.test(t.nodeName)||t.contentEditable=="false")return!1;e=Le(t)+(i<0?0:1),t=o}else if(t.nodeType==1){if(t=t.childNodes[e+(i<0?-1:0)],t.contentEditable=="false")return!1;e=i<0?Pt(t):0}else return!1}}function Pt(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function dS(t,e,n){for(let r=e==0,i=e==Pt(t);r||i;){if(t==n)return!0;let o=Le(t);if(t=t.parentNode,!t)return!1;r=r&&o==0,i=i&&o==Pt(t)}}function Fd(t){let e;for(let n=t;n&&!(e=n.pmViewDesc);n=n.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==t||e.contentDOM==t)}const ia=function(t){return t.focusNode&&gr(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)};function Qn(t,e){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=t,n.key=n.code=e,n}function fS(t){let e=t.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function hS(t,e,n){if(t.caretPositionFromPoint)try{let r=t.caretPositionFromPoint(e,n);if(r)return{node:r.offsetNode,offset:r.offset}}catch{}if(t.caretRangeFromPoint){let r=t.caretRangeFromPoint(e,n);if(r)return{node:r.startContainer,offset:r.startOffset}}}const Ht=typeof navigator<"u"?navigator:null,Fh=typeof document<"u"?document:null,jn=Ht&&Ht.userAgent||"",pc=/Edge\/(\d+)/.exec(jn),By=/MSIE \d/.exec(jn),mc=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(jn),Je=!!(By||mc||pc),bn=By?document.documentMode:mc?+mc[1]:pc?+pc[1]:0,Et=!Je&&/gecko\/(\d+)/i.test(jn);Et&&+(/Firefox\/(\d+)/.exec(jn)||[0,0])[1];const gc=!Je&&/Chrome\/(\d+)/.exec(jn),Ae=!!gc,pS=gc?+gc[1]:0,Pe=!Je&&!!Ht&&/Apple Computer/.test(Ht.vendor),li=Pe&&(/Mobile\/\w+/.test(jn)||!!Ht&&Ht.maxTouchPoints>2),ot=li||(Ht?/Mac/.test(Ht.platform):!1),mS=Ht?/Win/.test(Ht.platform):!1,kt=/Android \d/.test(jn),No=!!Fh&&"webkitFontSmoothing"in Fh.documentElement.style,gS=No?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function yS(t){return{left:0,right:t.documentElement.clientWidth,top:0,bottom:t.documentElement.clientHeight}}function Vt(t,e){return typeof t=="number"?t:t[e]}function kS(t){let e=t.getBoundingClientRect(),n=e.width/t.offsetWidth||1,r=e.height/t.offsetHeight||1;return{left:e.left,right:e.left+t.clientWidth*n,top:e.top,bottom:e.top+t.clientHeight*r}}function _h(t,e,n){let r=t.someProp("scrollThreshold")||0,i=t.someProp("scrollMargin")||5,o=t.dom.ownerDocument;for(let s=n||t.dom;s;s=go(s)){if(s.nodeType!=1)continue;let l=s,a=l==o.body,u=a?yS(o):kS(l),c=0,d=0;if(e.topu.bottom-Vt(r,"bottom")&&(d=e.bottom-e.top>u.bottom-u.top?e.top+Vt(i,"top")-u.top:e.bottom-u.bottom+Vt(i,"bottom")),e.leftu.right-Vt(r,"right")&&(c=e.right-u.right+Vt(i,"right")),c||d)if(a)o.defaultView.scrollBy(c,d);else{let f=l.scrollLeft,h=l.scrollTop;d&&(l.scrollTop+=d),c&&(l.scrollLeft+=c);let p=l.scrollLeft-f,y=l.scrollTop-h;e={left:e.left-p,top:e.top-y,right:e.right-p,bottom:e.bottom-y}}if(a||/^(fixed|sticky)$/.test(getComputedStyle(s).position))break}}function vS(t){let e=t.dom.getBoundingClientRect(),n=Math.max(0,e.top),r,i;for(let o=(e.left+e.right)/2,s=n+1;s=n-20){r=l,i=a.top;break}}return{refDOM:r,refTop:i,stack:Fy(t.dom)}}function Fy(t){let e=[],n=t.ownerDocument;for(let r=t;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),t!=n);r=go(r));return e}function SS({refDOM:t,refTop:e,stack:n}){let r=t?t.getBoundingClientRect().top:0;_y(n,r==0?0:r-e)}function _y(t,e){for(let n=0;n=l){s=Math.max(p.bottom,s),l=Math.min(p.top,l);let y=p.left>e.left?p.left-e.left:p.right=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!a&&p.left<=e.left&&p.right>=e.left&&(a=c,u={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!n&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(o=d+1)}}return!n&&a&&(n=a,i=u,r=0),n&&n.nodeType==3?xS(n,i):!n||r&&n.nodeType==1?{node:t,offset:o}:Hy(n,i)}function xS(t,e){let n=t.nodeValue.length,r=document.createRange();for(let i=0;i=(o.left+o.right)/2?1:0)}}return{node:t,offset:0}}function _d(t,e){return t.left>=e.left-1&&t.left<=e.right+1&&t.top>=e.top-1&&t.top<=e.bottom+1}function CS(t,e){let n=t.parentNode;return n&&/^li$/i.test(n.nodeName)&&e.left(s.left+s.right)/2?1:-1}return t.docView.posFromDOM(r,i,o)}function MS(t,e,n,r){let i=-1;for(let o=e,s=!1;o!=t.dom;){let l=t.docView.nearestDesc(o,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent&&!s||!l.contentDOM)){let a=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&!s&&(s=!0,a.left>r.left||a.top>r.top?i=l.posBefore:(a.right-1?i:t.docView.posFromDOM(e,n,-1)}function $y(t,e,n){let r=t.childNodes.length;if(r&&n.tope.top&&i++}let u;No&&i&&r.nodeType==1&&(u=r.childNodes[i-1]).nodeType==1&&u.contentEditable=="false"&&u.getBoundingClientRect().top>=e.top&&i--,r==t.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=t.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=MS(t,r,i,e))}l==null&&(l=ES(t,s,e));let a=t.docView.nearestDesc(s,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function Hh(t){return t.top=0&&i==r.nodeValue.length?(a--,c=1):n<0?a--:u++,Mi(ln(Kt(r,a,u),c),c<0)}if(!t.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&i&&(n<0||i==Pt(r))){let a=r.childNodes[i-1];if(a.nodeType==1)return Ya(a.getBoundingClientRect(),!1)}if(o==null&&i=0)}if(o==null&&i&&(n<0||i==Pt(r))){let a=r.childNodes[i-1],u=a.nodeType==3?Kt(a,Pt(a)-(s?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(u)return Mi(ln(u,1),!1)}if(o==null&&i=0)}function Mi(t,e){if(t.width==0)return t;let n=e?t.left:t.right;return{top:t.top,bottom:t.bottom,left:n,right:n}}function Ya(t,e){if(t.height==0)return t;let n=e?t.top:t.bottom;return{top:n,bottom:n,left:t.left,right:t.right}}function Vy(t,e,n){let r=t.state,i=t.root.activeElement;r!=e&&t.updateState(e),i!=t.dom&&t.focus();try{return n()}finally{r!=e&&t.updateState(r),i!=t.dom&&i&&i.focus()}}function NS(t,e,n){let r=e.selection,i=n=="up"?r.$from:r.$to;return Vy(t,e,()=>{let{node:o}=t.docView.domFromPos(i.pos,n=="up"?-1:1);for(;;){let l=t.docView.nearestDesc(o,!0);if(!l)break;if(l.node.isBlock){o=l.contentDOM||l.dom;break}o=l.dom.parentNode}let s=jy(t,i.pos,1);for(let l=o.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=Kt(l,0,l.nodeValue.length).getClientRects();else continue;for(let u=0;uc.top+1&&(n=="up"?s.top-c.top>(c.bottom-s.top)*2:c.bottom-s.bottom>(s.bottom-c.top)*2))return!1}}return!0})}const AS=/[\u0590-\u08ac]/;function bS(t,e,n){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,l=t.domSelection();return!AS.test(r.parent.textContent)||!l.modify?n=="left"||n=="backward"?o:s:Vy(t,e,()=>{let{focusNode:a,focusOffset:u,anchorNode:c,anchorOffset:d}=t.domSelectionRange(),f=l.caretBidiLevel;l.modify("move",n,"character");let h=r.depth?t.docView.domAfterPos(r.before()):t.dom,{focusNode:p,focusOffset:y}=t.domSelectionRange(),v=p&&!h.contains(p.nodeType==1?p:p.parentNode)||a==p&&u==y;try{l.collapse(c,d),a&&(a!=c||u!=d)&&l.extend&&l.extend(a,u)}catch{}return f!=null&&(l.caretBidiLevel=f),v})}let $h=null,jh=null,Vh=!1;function RS(t,e,n){return $h==e&&jh==n?Vh:($h=e,jh=n,Vh=n=="up"||n=="down"?NS(t,e,n):bS(t,e,n))}const dt=0,Uh=1,Zn=2,$t=3;class Ao{constructor(e,n,r,i){this.parent=e,this.children=n,this.dom=r,this.contentDOM=i,this.dirty=dt,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,n,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let n=0;nLe(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(n==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&n==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,n=!1){for(let r=!0,i=e;i;i=i.parentNode){let o=this.getDesc(i),s;if(o&&(!n||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){let n=e.pmViewDesc;for(let r=n;r;r=r.parent)if(r==this)return n}posFromDOM(e,n,r){for(let i=e;i;i=i.parentNode){let o=this.getDesc(i);if(o)return o.localPosFromDOM(e,n,r)}return-1}descAt(e){for(let n=0,r=0;ne||s instanceof Wy){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,n);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof Uy&&o.side>=0;r--);if(n<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&n&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,n):{node:this.contentDOM,offset:o?Le(o.dom)+1:0}}else{let o,s=!0;for(;o=r=c&&n<=u-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,n,c);e=s;for(let d=l;d>0;d--){let f=this.children[d-1];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(1)){i=Le(f.dom)+1;break}e-=f.size}i==-1&&(i=0)}if(i>-1&&(u>n||l==this.children.length-1)){n=u;for(let c=l+1;ch&&sn){let h=l;l=a,a=h}let f=document.createRange();f.setEnd(a.node,a.offset),f.setStart(l.node,l.offset),u.removeAllRanges(),u.addRange(f)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,n){for(let r=0,i=0;i=r:er){let l=r+o.border,a=s-o.border;if(e>=l&&n<=a){this.dirty=e==r||n==s?Zn:Uh,e==l&&n==a&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=$t:o.markDirty(e-l,n-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?Zn:$t}r=s}this.dirty=Zn}markParentsDirty(){let e=1;for(let n=this.parent;n;n=n.parent,e++){let r=e==1?Zn:Uh;n.dirty{if(!o)return i;if(o.parent)return o.parent.posBeforeChild(o)})),!n.type.spec.raw){if(s.nodeType!=1){let l=document.createElement("span");l.appendChild(s),s=l}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=n,this.widget=n,o=this}matchesWidget(e){return this.dirty==dt&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let n=this.widget.spec.stopEvent;return n?n(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}}class IS extends Ao{constructor(e,n,r,i){super(e,[],n,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,n){return e!=this.textDOM?this.posAtStart+(n?this.size:0):this.posAtStart+n}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}}class yr extends Ao{constructor(e,n,r,i){super(e,[],r,i),this.mark=n}static create(e,n,r,i){let o=i.nodeViews[n.type.name],s=o&&o(n,i,r);return(!s||!s.dom)&&(s=zt.renderSpec(document,n.type.spec.toDOM(n,r))),new yr(e,n,s.dom,s.contentDOM||s.dom)}parseRule(){return this.dirty&$t||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=$t&&this.mark.eq(e)}markDirty(e,n){if(super.markDirty(e,n),this.dirty!=dt){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(o=vc(o,0,e,r));for(let l=0;l{if(!a)return s;if(a.parent)return a.parent.posBeforeChild(a)},r,i),c=u&&u.dom,d=u&&u.contentDOM;if(n.isText){if(!c)c=document.createTextNode(n.text);else if(c.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else c||({dom:c,contentDOM:d}=zt.renderSpec(document,n.type.spec.toDOM(n)));!d&&!n.isText&&c.nodeName!="BR"&&(c.hasAttribute("contenteditable")||(c.contentEditable="false"),n.type.spec.draggable&&(c.draggable=!0));let f=c;return c=qy(c,r,n),u?a=new LS(e,n,r,i,c,d||null,f,u,o,s+1):n.isText?new oa(e,n,r,i,c,f,o):new Rn(e,n,r,i,c,d||null,f,o,s+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let n=this.children.length-1;n>=0;n--){let r=this.children[n];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>C.empty)}return e}matchesNode(e,n,r){return this.dirty==dt&&e.eq(this.node)&&kc(n,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,n){let r=this.node.inlineContent,i=n,o=e.composing?this.localCompositionInfo(e,n):null,s=o&&o.pos>-1?o:null,l=o&&o.pos<0,a=new PS(this,s&&s.node,e);FS(this.node,this.innerDeco,(u,c,d)=>{u.spec.marks?a.syncToMarks(u.spec.marks,r,e):u.type.side>=0&&!d&&a.syncToMarks(c==this.node.childCount?U.none:this.node.child(c).marks,r,e),a.placeWidget(u,e,i)},(u,c,d,f)=>{a.syncToMarks(u.marks,r,e);let h;a.findNodeMatch(u,c,d,f)||l&&e.state.selection.from>i&&e.state.selection.to-1&&a.updateNodeAt(u,c,d,h,e)||a.updateNextNode(u,c,d,e,f,i)||a.addNode(u,c,d,e,i),i+=u.nodeSize}),a.syncToMarks([],r,e),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==Zn)&&(s&&this.protectLocalComposition(e,s),Ky(this.contentDOM,this.children,e),li&&_S(this.dom))}localCompositionInfo(e,n){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof P)||rn+this.node.content.size)return null;let o=e.domSelectionRange(),s=HS(o.focusNode,o.focusOffset);if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let l=s.nodeValue,a=$S(this.node.content,l,r-n,i-n);return a<0?null:{node:s,pos:a,text:l}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:n,pos:r,text:i}){if(this.getDesc(n))return;let o=n;for(;o.parentNode!=this.contentDOM;o=o.parentNode){for(;o.previousSibling;)o.parentNode.removeChild(o.previousSibling);for(;o.nextSibling;)o.parentNode.removeChild(o.nextSibling);o.pmViewDesc&&(o.pmViewDesc=void 0)}let s=new IS(this,o,n,i);e.input.compositionNodes.push(s),this.children=vc(this.children,r,r+i.length,e,s)}update(e,n,r,i){return this.dirty==$t||!e.sameMarkup(this.node)?!1:(this.updateInner(e,n,r,i),!0)}updateInner(e,n,r,i){this.updateOuterDeco(n),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=dt}updateOuterDeco(e){if(kc(e,this.outerDeco))return;let n=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Jy(this.dom,this.nodeDOM,yc(this.outerDeco,this.node,n),yc(e,this.node,n)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}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}}function Wh(t,e,n,r,i){qy(r,e,t);let o=new Rn(void 0,t,e,n,r,r,r,i,0);return o.contentDOM&&o.updateChildren(i,0),o}class oa extends Rn{constructor(e,n,r,i,o,s,l){super(e,n,r,i,o,null,s,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,n,r,i){return this.dirty==$t||this.dirty!=dt&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(n),(this.dirty!=dt||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=dt,!0)}inParent(){let e=this.parent.contentDOM;for(let n=this.nodeDOM;n;n=n.parentNode)if(n==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,n,r){return e==this.nodeDOM?this.posAtStart+Math.min(n,this.node.text.length):super.localPosFromDOM(e,n,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,n,r){let i=this.node.cut(e,n),o=document.createTextNode(i.text);return new oa(this.parent,i,this.outerDeco,this.innerDeco,o,o,r)}markDirty(e,n){super.markDirty(e,n),this.dom!=this.nodeDOM&&(e==0||n==this.nodeDOM.nodeValue.length)&&(this.dirty=$t)}get domAtom(){return!1}}class Wy extends Ao{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==dt&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class LS extends Rn{constructor(e,n,r,i,o,s,l,a,u,c){super(e,n,r,i,o,s,l,u,c),this.spec=a}update(e,n,r,i){if(this.dirty==$t)return!1;if(this.spec.update){let o=this.spec.update(e,n,r);return o&&this.updateInner(e,n,r,i),o}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,n,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,n,r,i){this.spec.setSelection?this.spec.setSelection(e,n,r):super.setSelection(e,n,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}function Ky(t,e,n){let r=t.firstChild,i=!1;for(let o=0;o>1,s=Math.min(o,e.length);for(;i-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let a=yr.create(this.top,e[o],n,r);this.top.children.splice(this.index,0,a),this.top=a,this.changed=!0}this.index=0,o++}}findNodeMatch(e,n,r,i){let o=-1,s;if(i>=this.preMatch.index&&(s=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&s.matchesNode(e,n,r))o=this.top.children.indexOf(s,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let u=n.children[r-1];if(u instanceof yr)n=u,r=u.children.length;else{l=u,r--;break}}else{if(n==e)break e;r=n.parent.children.indexOf(n),n=n.parent}let a=l.node;if(a){if(a!=t.child(i-1))break;--i,o.set(l,i),s.push(l)}}return{index:i,matched:o,matches:s.reverse()}}function BS(t,e){return t.type.side-e.type.side}function FS(t,e,n,r){let i=e.locals(t),o=0;if(i.length==0){for(let u=0;uo;)l.push(i[s++]);let p=o+f.nodeSize;if(f.isText){let v=p;s!v.inline):l.slice();r(f,y,e.forChild(o,f),h),o=p}}function _S(t){if(t.nodeName=="UL"||t.nodeName=="OL"){let e=t.style.cssText;t.style.cssText=e+"; list-style: square !important",window.getComputedStyle(t).listStyle,t.style.cssText=e}}function HS(t,e){for(;;){if(t.nodeType==3)return t;if(t.nodeType==1&&e>0){if(t.childNodes.length>e&&t.childNodes[e].nodeType==3)return t.childNodes[e];t=t.childNodes[e-1],e=Pt(t)}else if(t.nodeType==1&&e=n){if(o>=r&&a.slice(r-e.length-l,r-l)==e)return r-e.length;let u=l=0&&u+e.length+l>=n)return l+u;if(n==r&&a.length>=r+e.length-l&&a.slice(r-l,r-l+e.length)==e)return r}}return-1}function vc(t,e,n,r,i){let o=[];for(let s=0,l=0;s=n||c<=e?o.push(a):(un&&o.push(a.slice(n-u,a.size,r)))}return o}function Hd(t,e=null){let n=t.domSelectionRange(),r=t.state.doc;if(!n.focusNode)return null;let i=t.docView.nearestDesc(n.focusNode),o=i&&i.size==0,s=t.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(s<0)return null;let l=r.resolve(s),a,u;if(ia(n)){for(a=l;i&&!i.node;)i=i.parent;let c=i.node;if(i&&c.isAtom&&L.isSelectable(c)&&i.parent&&!(c.isInline&&dS(n.focusNode,n.focusOffset,i.dom))){let d=i.posBefore;u=new L(s==d?l:r.resolve(d))}}else{let c=t.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(c<0)return null;a=r.resolve(c)}if(!u){let c=e=="pointer"||t.state.selection.head{(n.anchorNode!=r||n.anchorOffset!=i)&&(e.removeEventListener("selectionchange",t.input.hideSelectionGuard),setTimeout(()=>{(!Qy(t)||t.state.selection.visible)&&t.dom.classList.remove("ProseMirror-hideselection")},20))})}function VS(t){let e=t.domSelection(),n=document.createRange(),r=t.cursorWrapper.dom,i=r.nodeName=="IMG";i?n.setEnd(r.parentNode,Le(r)+1):n.setEnd(r,0),n.collapse(!1),e.removeAllRanges(),e.addRange(n),!i&&!t.state.selection.visible&&Je&&bn<=11&&(r.disabled=!0,r.disabled=!1)}function Gy(t,e){if(e instanceof L){let n=t.docView.descAt(e.from);n!=t.lastSelectedViewDesc&&(Gh(t),n&&n.selectNode(),t.lastSelectedViewDesc=n)}else Gh(t)}function Gh(t){t.lastSelectedViewDesc&&(t.lastSelectedViewDesc.parent&&t.lastSelectedViewDesc.deselectNode(),t.lastSelectedViewDesc=void 0)}function $d(t,e,n,r){return t.someProp("createSelectionBetween",i=>i(t,e,n))||P.between(e,n,r)}function Yh(t){return t.editable&&!t.hasFocus()?!1:Yy(t)}function Yy(t){let e=t.domSelectionRange();if(!e.anchorNode)return!1;try{return t.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(t.editable||t.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function US(t){let e=t.docView.domFromPos(t.state.selection.anchor,0),n=t.domSelectionRange();return gr(e.node,e.offset,n.anchorNode,n.anchorOffset)}function Sc(t,e){let{$anchor:n,$head:r}=t.selection,i=e>0?n.max(r):n.min(r),o=i.parent.inlineContent?i.depth?t.doc.resolve(e>0?i.after():i.before()):null:i;return o&&_.findFrom(o,e)}function cn(t,e){return t.dispatch(t.state.tr.setSelection(e).scrollIntoView()),!0}function Xh(t,e,n){let r=t.state.selection;if(r instanceof P)if(n.indexOf("s")>-1){let{$head:i}=r,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!o||o.isText||!o.isLeaf)return!1;let s=t.state.doc.resolve(i.pos+o.nodeSize*(e<0?-1:1));return cn(t,new P(r.$anchor,s))}else if(r.empty){if(t.endOfTextblock(e>0?"forward":"backward")){let i=Sc(t.state,e);return i&&i instanceof L?cn(t,i):!1}else if(!(ot&&n.indexOf("m")>-1)){let i=r.$head,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,s;if(!o||o.isText)return!1;let l=e<0?i.pos-o.nodeSize:i.pos;return o.isAtom||(s=t.docView.descAt(l))&&!s.contentDOM?L.isSelectable(o)?cn(t,new L(e<0?t.state.doc.resolve(i.pos-o.nodeSize):i)):No?cn(t,new P(t.state.doc.resolve(e<0?l:l+o.nodeSize))):!1:!1}}else return!1;else{if(r instanceof L&&r.node.isInline)return cn(t,new P(e>0?r.$to:r.$from));{let i=Sc(t.state,e);return i?cn(t,i):!1}}}function el(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function Ki(t,e){let n=t.pmViewDesc;return n&&n.size==0&&(e<0||t.nextSibling||t.nodeName!="BR")}function Cr(t,e){return e<0?WS(t):KS(t)}function WS(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let i,o,s=!1;for(Et&&n.nodeType==1&&r0){if(n.nodeType!=1)break;{let l=n.childNodes[r-1];if(Ki(l,-1))i=n,o=--r;else if(l.nodeType==3)n=l,r=n.nodeValue.length;else break}}else{if(Xy(n))break;{let l=n.previousSibling;for(;l&&Ki(l,-1);)i=n.parentNode,o=Le(l),l=l.previousSibling;if(l)n=l,r=el(n);else{if(n=n.parentNode,n==t.dom)break;r=0}}}s?wc(t,n,r):i&&wc(t,i,o)}function KS(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let i=el(n),o,s;for(;;)if(r{t.state==i&&Yt(t)},50)}function Zh(t,e){let n=t.state.doc.resolve(e);if(!(Ae||mS)&&n.parent.inlineContent){let i=t.coordsAtPos(e);if(e>n.start()){let o=t.coordsAtPos(e-1),s=(o.top+o.bottom)/2;if(s>i.top&&s1)return o.lefti.top&&s1)return o.left>i.left?"ltr":"rtl"}}return getComputedStyle(t.dom).direction=="rtl"?"rtl":"ltr"}function ep(t,e,n){let r=t.state.selection;if(r instanceof P&&!r.empty||n.indexOf("s")>-1||ot&&n.indexOf("m")>-1)return!1;let{$from:i,$to:o}=r;if(!i.parent.inlineContent||t.endOfTextblock(e<0?"up":"down")){let s=Sc(t.state,e);if(s&&s instanceof L)return cn(t,s)}if(!i.parent.inlineContent){let s=e<0?i:o,l=r instanceof xt?_.near(s,e):_.findFrom(s,e);return l?cn(t,l):!1}return!1}function tp(t,e){if(!(t.state.selection instanceof P))return!0;let{$head:n,$anchor:r,empty:i}=t.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(t.endOfTextblock(e>0?"forward":"backward"))return!0;let o=!n.textOffset&&(e<0?n.nodeBefore:n.nodeAfter);if(o&&!o.isText){let s=t.state.tr;return e<0?s.delete(n.pos-o.nodeSize,n.pos):s.delete(n.pos,n.pos+o.nodeSize),t.dispatch(s),!0}return!1}function np(t,e,n){t.domObserver.stop(),e.contentEditable=n,t.domObserver.start()}function QS(t){if(!Pe||t.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:n}=t.domSelectionRange();if(e&&e.nodeType==1&&n==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;np(t,r,"true"),setTimeout(()=>np(t,r,"false"),20)}return!1}function GS(t){let e="";return t.ctrlKey&&(e+="c"),t.metaKey&&(e+="m"),t.altKey&&(e+="a"),t.shiftKey&&(e+="s"),e}function YS(t,e){let n=e.keyCode,r=GS(e);if(n==8||ot&&n==72&&r=="c")return tp(t,-1)||Cr(t,-1);if(n==46&&!e.shiftKey||ot&&n==68&&r=="c")return tp(t,1)||Cr(t,1);if(n==13||n==27)return!0;if(n==37||ot&&n==66&&r=="c"){let i=n==37?Zh(t,t.state.selection.from)=="ltr"?-1:1:-1;return Xh(t,i,r)||Cr(t,i)}else if(n==39||ot&&n==70&&r=="c"){let i=n==39?Zh(t,t.state.selection.from)=="ltr"?1:-1:1;return Xh(t,i,r)||Cr(t,i)}else{if(n==38||ot&&n==80&&r=="c")return ep(t,-1,r)||Cr(t,-1);if(n==40||ot&&n==78&&r=="c")return QS(t)||ep(t,1,r)||Cr(t,1);if(r==(ot?"m":"c")&&(n==66||n==73||n==89||n==90))return!0}return!1}function Zy(t,e){t.someProp("transformCopied",h=>{e=h(e,t)});let n=[],{content:r,openStart:i,openEnd:o}=e;for(;i>1&&o>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,o--;let h=r.firstChild;n.push(h.type.name,h.attrs!=h.type.defaultAttrs?h.attrs:null),r=h.content}let s=t.someProp("clipboardSerializer")||zt.fromSchema(t.state.schema),l=o0(),a=l.createElement("div");a.appendChild(s.serializeFragment(r,{document:l}));let u=a.firstChild,c,d=0;for(;u&&u.nodeType==1&&(c=i0[u.nodeName.toLowerCase()]);){for(let h=c.length-1;h>=0;h--){let p=l.createElement(c[h]);for(;a.firstChild;)p.appendChild(a.firstChild);a.appendChild(p),d++}u=a.firstChild}u&&u.nodeType==1&&u.setAttribute("data-pm-slice",`${i} ${o}${d?` -${d}`:""} ${JSON.stringify(n)}`);let f=t.someProp("clipboardTextSerializer",h=>h(e,t))||e.content.textBetween(0,e.content.size,` `);return{dom:a,text:f}}function e0(t,e,n,r,i){let o=i.parent.type.spec.code,s,l;if(!n&&!e)return null;let a=e&&(r||o||!n);if(a){if(t.someProp("transformPastedText",f=>{e=f(e,o||r,t)}),o)return e?new A(C.from(t.state.schema.text(e.replace(/\r\n?/g,` @@ -211,7 +211,7 @@ margin: 0; padding: 0; } - #root > div { + #root > div:nth-of-type(1) { overflow: auto; height: 100%; position: absolute; diff --git a/example/src/Examples/Advanced/Editor/index.html b/example/src/Examples/Advanced/Editor/index.html index 05379ea..ace51b5 100644 --- a/example/src/Examples/Advanced/Editor/index.html +++ b/example/src/Examples/Advanced/Editor/index.html @@ -10,7 +10,7 @@ margin: 0; padding: 0; } - #root > div { + #root > div:nth-of-type(1) { overflow: auto; height: 100%; position: absolute; diff --git a/example/src/Examples/Advanced/Editor/tsconfig.json b/example/src/Examples/Advanced/Editor/tsconfig.json index 6ffb2cd..c25ef59 100644 --- a/example/src/Examples/Advanced/Editor/tsconfig.json +++ b/example/src/Examples/Advanced/Editor/tsconfig.json @@ -19,7 +19,7 @@ "skipLibCheck": true, "strict": true, "paths": { - "tentap": ["../../../../../src/Editor/useTenTap"] + "tentap": ["../../../../../src/webEditorUtils"] } }, } \ No newline at end of file diff --git a/example/src/Examples/Advanced/Editor/vite.config.ts b/example/src/Examples/Advanced/Editor/vite.config.ts index 9281880..dd293dc 100644 --- a/example/src/Examples/Advanced/Editor/vite.config.ts +++ b/example/src/Examples/Advanced/Editor/vite.config.ts @@ -14,10 +14,7 @@ export default defineConfig({ alias: [ { find: 'tentap', - replacement: resolve( - __dirname, - '../../../../../src/Editor/useTenTap.tsx' - ), + replacement: resolve(__dirname, '../../../../../src/webEditorUtils'), }, ], }, diff --git a/example/src/Examples/Basic.tsx b/example/src/Examples/Basic.tsx index 01a87ed..9e7b971 100644 --- a/example/src/Examples/Basic.tsx +++ b/example/src/Examples/Basic.tsx @@ -17,7 +17,7 @@ import { TenTapStartKit, Toolbar, UnderlineBridge, - useEditor, + useNativeEditor, } from 'tentap'; import { ColorKeyboard } from '../../../src/RichText/Keyboard/ColorKeyboard'; import { CustomKeyboard } from '../../../src/RichText/Keyboard'; @@ -34,7 +34,7 @@ const exampleStyles = StyleSheet.create({ }); export const Basic = ({}: NativeStackScreenProps) => { - const editor = useEditor({ + const editor = useNativeEditor({ initialContent: `

This is a basic example of implementing images.

s

`, plugins: [ TenTapStartKit, diff --git a/example/src/Examples/CustomKeyboardExample/index.tsx b/example/src/Examples/CustomKeyboardExample/index.tsx index 3f9a559..be89d7b 100644 --- a/example/src/Examples/CustomKeyboardExample/index.tsx +++ b/example/src/Examples/CustomKeyboardExample/index.tsx @@ -11,7 +11,7 @@ import { RichText, TenTapStartKit, Toolbar, - useEditor, + useNativeEditor, type ToolbarItem, } from 'tentap'; import { CustomKeyboard } from '../../../../src/RichText/Keyboard'; @@ -34,7 +34,7 @@ export const CustomKeyboardExample = ({}: NativeStackScreenProps< any, any >) => { - const editor = useEditor({ + const editor = useNativeEditor({ plugins: [TenTapStartKit], }); const TapRef = useRef(null); diff --git a/example/src/Examples/EditorStickToKeyboardExample.tsx b/example/src/Examples/EditorStickToKeyboardExample.tsx index 13180aa..7b3b626 100644 --- a/example/src/Examples/EditorStickToKeyboardExample.tsx +++ b/example/src/Examples/EditorStickToKeyboardExample.tsx @@ -14,7 +14,7 @@ import { RichText, TenTapStartKit, Toolbar, - useEditor, + useNativeEditor, CoreBridge, } from 'tentap'; import { CustomKeyboard } from '../../../src/RichText/Keyboard'; @@ -59,7 +59,7 @@ export const EditorStickToKeyboardExample = ({}: NativeStackScreenProps< any, any >) => { - const editor = useEditor({ + const editor = useNativeEditor({ plugins: [TenTapStartKit, CoreBridge], initialContent: '

Initial lovely message...

', }); diff --git a/src/Editor/build/index.html b/src/Editor/build/index.html deleted file mode 100644 index 9732730..0000000 --- a/src/Editor/build/index.html +++ /dev/null @@ -1,160 +0,0 @@ - - - - - - RichTextEditor - - - - -
- - diff --git a/src/RichText/Keyboard/index.tsx b/src/RichText/Keyboard/index.tsx index cb0c56e..d189744 100644 --- a/src/RichText/Keyboard/index.tsx +++ b/src/RichText/Keyboard/index.tsx @@ -4,7 +4,7 @@ import { CustomKeyboardAndroid } from './CustomKeyboard.android'; import { CustomKeyboardIOS } from './CustomKeyboard.ios'; import type { CustomKeyboardExtension } from './CustomKeyboardExtension'; import type { EditorInstance } from '../../types'; -import { useEditorState } from '../useEditorState'; +import { useNativeEditorState } from '../useNativeEditorState'; interface CustomKeyboardProps { rootRef: React.RefObject; @@ -20,7 +20,7 @@ export const CustomKeyboard = ({ rootRef, editor, }: CustomKeyboardProps) => { - const editorState = useEditorState(editor); + const editorState = useNativeEditorState(editor); useEffect(() => { if (editorState.isFocused) { diff --git a/src/RichText/RichText.tsx b/src/RichText/RichText.tsx index b282467..7368681 100644 --- a/src/RichText/RichText.tsx +++ b/src/RichText/RichText.tsx @@ -7,7 +7,7 @@ import { } from 'react-native-webview'; // @ts-ignore -import editorHTML from '../Editor/build/index.html'; +import editorHTML from '../simpleWebEditor/build/index.html'; import { type EditorMessage, EditorMessageType } from '../types/Messaging'; import { useKeyboard } from '../utils'; diff --git a/src/RichText/Toolbar/Toolbar.tsx b/src/RichText/Toolbar/Toolbar.tsx index 225ef3a..0317844 100644 --- a/src/RichText/Toolbar/Toolbar.tsx +++ b/src/RichText/Toolbar/Toolbar.tsx @@ -1,5 +1,5 @@ import { FlatList, Image, TouchableOpacity, StyleSheet } from 'react-native'; -import { useEditorState } from '../useEditorState'; +import { useNativeEditorState } from '../useNativeEditorState'; import React from 'react'; import { DEFAULT_TOOLBAR_ITEMS, type ToolbarItem } from './actions'; import { EditLinkBar } from './EditLinkBar'; @@ -57,7 +57,7 @@ export function Toolbar({ setActiveKeyboard, activeKeyboard, }: ToolbarProps) { - const editorState = useEditorState(editor); + const editorState = useNativeEditorState(editor); const { isKeyboardUp } = useKeyboard(); const [toolbarContext, setToolbarContext] = React.useState( ToolbarContext.Main diff --git a/src/RichText/Toolbar/actions.ts b/src/RichText/Toolbar/actions.ts index 2cce5ab..52be409 100644 --- a/src/RichText/Toolbar/actions.ts +++ b/src/RichText/Toolbar/actions.ts @@ -1,7 +1,7 @@ import { Images } from '../../assets'; import { EditorActionType } from '../../types/Actions'; import type { EditorInstance } from '../../types'; -import { type EditorState } from '../../types/EditorState'; +import { type EditorNativeState } from '../../types/EditorNativeState'; import { ToolbarContext } from './Toolbar'; import { ColorKeyboard } from '../Keyboard/ColorKeyboard'; @@ -17,7 +17,7 @@ export const ToolbarItems = { type ArgsToolbarCB = { editor: EditorInstance; - editorState: EditorState; + editorState: EditorNativeState; setToolbarContext: ( ToolbarContext: ToolbarContext | ((prev: ToolbarContext) => ToolbarContext) ) => void; diff --git a/src/RichText/index.ts b/src/RichText/index.ts index 2c171ba..dfd4eee 100644 --- a/src/RichText/index.ts +++ b/src/RichText/index.ts @@ -1,5 +1,5 @@ export * from './RichText'; -export * from './useEditor'; -export * from './useEditorState'; +export * from './useNativeEditor'; +export * from './useNativeEditorState'; export * from './Toolbar'; export * from './Keyboard/CustomKeyboard.ios'; diff --git a/src/RichText/useEditor.tsx b/src/RichText/useNativeEditor.tsx similarity index 81% rename from src/RichText/useEditor.tsx rename to src/RichText/useNativeEditor.tsx index 29763f0..f9c1fdc 100644 --- a/src/RichText/useEditor.tsx +++ b/src/RichText/useNativeEditor.tsx @@ -5,28 +5,28 @@ import { EditorMessageType, } from '../types/Messaging'; import { EditorUpdateSettings } from '../types/Actions'; -import { type EditorState } from '../types/EditorState'; +import { type EditorNativeState } from '../types/EditorNativeState'; import { EditorHelper } from './EditorHelper'; import type { EditorInstance } from '../types'; -import type TenTapBridge from '../Editor/plugins/base'; +import type TenTapBridge from '../bridges/base'; type Subscription = (cb: (val: T) => void) => () => void; -export const useEditor = (options?: { +export const useNativeEditor = (options?: { plugins?: TenTapBridge[]; initialContent?: string; }): EditorInstance => { const webviewRef = useRef(null); // Till we will implement default per plugin - const editorStateRef = useRef({}); - const editorStateSubsRef = useRef<((state: EditorState) => void)[]>([]); + const editorStateRef = useRef({}); + const editorStateSubsRef = useRef<((state: EditorNativeState) => void)[]>([]); - const _updateEditorState = (editorState: EditorState) => { + const _updateEditorState = (editorState: EditorNativeState) => { editorStateRef.current = editorState; editorStateSubsRef.current.forEach((sub) => sub(editorState)); }; - const _subscribeToEditorStateUpdate: Subscription = (cb) => { + const _subscribeToEditorStateUpdate: Subscription = (cb) => { editorStateSubsRef.current.push(cb); return () => { editorStateSubsRef.current = editorStateSubsRef.current.filter( @@ -79,6 +79,7 @@ export const useEditor = (options?: { const editorInstanceExtendByPlugins = (options?.plugins || []).reduce( (acc, cur) => { + if (!cur.extendEditorInstance) return acc; return Object.assign(acc, cur.extendEditorInstance(sendAction)); }, editorInstance diff --git a/src/RichText/useEditorState.tsx b/src/RichText/useNativeEditorState.tsx similarity index 83% rename from src/RichText/useEditorState.tsx rename to src/RichText/useNativeEditorState.tsx index 33c3d28..251b7e5 100644 --- a/src/RichText/useEditorState.tsx +++ b/src/RichText/useNativeEditorState.tsx @@ -1,7 +1,7 @@ import { useEffect, useState } from 'react'; import type { EditorInstance } from '../types'; -export const useEditorState = (editor: EditorInstance) => { +export const useNativeEditorState = (editor: EditorInstance) => { const [editorState, setEditorState] = useState(editor.getEditorState()); useEffect(() => { diff --git a/src/Editor/plugins/HighlightSelection.ts b/src/bridges/HighlightSelection.ts similarity index 100% rename from src/Editor/plugins/HighlightSelection.ts rename to src/bridges/HighlightSelection.ts diff --git a/src/Editor/plugins/StarterKit.ts b/src/bridges/StarterKit.ts similarity index 98% rename from src/Editor/plugins/StarterKit.ts rename to src/bridges/StarterKit.ts index f43bc09..692f93e 100644 --- a/src/Editor/plugins/StarterKit.ts +++ b/src/bridges/StarterKit.ts @@ -39,8 +39,8 @@ type TenTapStartKitEditorInstance = { redo: () => void; }; -declare module '../../types/EditorState' { - interface EditorState extends TenTapStartKitEditorState {} +declare module '../types/EditorNativeState' { + interface EditorNativeState extends TenTapStartKitEditorState {} interface EditorInstance extends TenTapStartKitEditorInstance {} } diff --git a/src/Editor/plugins/base.ts b/src/bridges/base.ts similarity index 87% rename from src/Editor/plugins/base.ts rename to src/bridges/base.ts index 7efd0bc..c67ac93 100644 --- a/src/Editor/plugins/base.ts +++ b/src/bridges/base.ts @@ -3,20 +3,20 @@ import { Editor, type AnyExtension } from '@tiptap/core'; interface TenTapBridge { name: string; tiptapExtension?: AnyExtension | AnyExtension[]; - onBridgeMessage: ( + onBridgeMessage?: ( editor: Editor, message: M, sendMessageBack: (message: M) => void ) => boolean; onEditorMessage?: (message: M) => boolean; - extendEditorState: (editor: Editor) => T; - extendEditorInstance: (sendBridgeMessage: (message: M) => void) => E; + extendEditorState?: (editor: Editor) => T; + extendEditorInstance?: (sendBridgeMessage: (message: M) => void) => E; extendCSS?: string | undefined; } type CreateTenTapBridgeArgs = Omit< TenTapBridge & { forceName?: string }, - 'name' + 'name' | 'sendMessage' >; class TenTapBridge { diff --git a/src/Editor/plugins/color.ts b/src/bridges/color.ts similarity index 92% rename from src/Editor/plugins/color.ts rename to src/bridges/color.ts index bb08d62..514e003 100644 --- a/src/Editor/plugins/color.ts +++ b/src/bridges/color.ts @@ -10,8 +10,8 @@ type ColorEditorInstance = { setColor: (color: string) => void; }; -declare module '../../types/EditorState' { - interface EditorState extends ColorEditorState {} +declare module '../types/EditorNativeState' { + interface EditorNativeState extends ColorEditorState {} interface EditorInstance extends ColorEditorInstance {} } diff --git a/src/Editor/plugins/core.ts b/src/bridges/core.ts similarity index 93% rename from src/Editor/plugins/core.ts rename to src/bridges/core.ts index e88b210..70cc7fa 100644 --- a/src/Editor/plugins/core.ts +++ b/src/bridges/core.ts @@ -1,5 +1,5 @@ import TenTapBridge from './base'; -import { asyncMessages } from '../../RichText/AsyncMessages'; +import { asyncMessages } from '../RichText/AsyncMessages'; type CoreEditorState = {}; @@ -8,8 +8,8 @@ type CoreEditorInstance = { setContent: (content: string) => void; }; -declare module '../../types/EditorState' { - interface EditorState extends CoreEditorState {} +declare module '../types/EditorNativeState' { + interface EditorNativeState extends CoreEditorState {} interface EditorInstance extends CoreEditorInstance {} } diff --git a/src/Editor/plugins/highlight.ts b/src/bridges/highlight.ts similarity index 92% rename from src/Editor/plugins/highlight.ts rename to src/bridges/highlight.ts index a09eed1..ef6e660 100644 --- a/src/Editor/plugins/highlight.ts +++ b/src/bridges/highlight.ts @@ -10,8 +10,8 @@ type HighlightEditorInstance = { setHighlight: (color: string) => void; }; -declare module '../../types/EditorState' { - interface EditorState extends HighlightEditorState {} +declare module '../types/EditorNativeState' { + interface EditorNativeState extends HighlightEditorState {} interface EditorInstance extends HighlightEditorInstance {} } diff --git a/src/Editor/plugins/image.ts b/src/bridges/image.ts similarity index 91% rename from src/Editor/plugins/image.ts rename to src/bridges/image.ts index 1136592..6be2633 100644 --- a/src/Editor/plugins/image.ts +++ b/src/bridges/image.ts @@ -7,8 +7,8 @@ type ImageEditorInstance = { setImage: (src: string) => void; }; -declare module '../../types/EditorState' { - interface EditorState extends ImageEditorState {} +declare module '../types/EditorNativeState' { + interface EditorNativeState extends ImageEditorState {} interface EditorInstance extends ImageEditorInstance {} } diff --git a/src/Editor/plugins/link.ts b/src/bridges/link.ts similarity index 94% rename from src/Editor/plugins/link.ts rename to src/bridges/link.ts index 8029291..4aca50b 100644 --- a/src/Editor/plugins/link.ts +++ b/src/bridges/link.ts @@ -11,8 +11,8 @@ type LinkEditorInstance = { setLink: (link: string | null) => void; }; -declare module '../../types/EditorState' { - interface EditorState extends LinkEditorState {} +declare module '../types/EditorNativeState' { + interface EditorNativeState extends LinkEditorState {} interface EditorInstance extends LinkEditorInstance {} } diff --git a/src/Editor/plugins/tasklist.ts b/src/bridges/tasklist.ts similarity index 94% rename from src/Editor/plugins/tasklist.ts rename to src/bridges/tasklist.ts index 6970c20..7bf1b08 100644 --- a/src/Editor/plugins/tasklist.ts +++ b/src/bridges/tasklist.ts @@ -11,8 +11,8 @@ type TaskListEditorInstance = { toggleTaskList: () => void; }; -declare module '../../types/EditorState' { - interface EditorState extends TaskListEditorState {} +declare module '../types/EditorNativeState' { + interface EditorNativeState extends TaskListEditorState {} interface EditorInstance extends TaskListEditorInstance {} } diff --git a/src/Editor/plugins/underline.ts b/src/bridges/underline.ts similarity index 91% rename from src/Editor/plugins/underline.ts rename to src/bridges/underline.ts index b9b88e5..259f17c 100644 --- a/src/Editor/plugins/underline.ts +++ b/src/bridges/underline.ts @@ -10,8 +10,8 @@ type UnderlineEditorInstance = { toggleUnderline: () => void; }; -declare module '../../types/EditorState' { - interface EditorState extends UnderlineEditorState {} +declare module '../types/EditorNativeState' { + interface EditorNativeState extends UnderlineEditorState {} interface EditorInstance extends UnderlineEditorInstance {} } diff --git a/src/index.tsx b/src/index.tsx index 3136d25..5fdc7ff 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,13 +1,14 @@ export { default as TenTapView } from './TenTapViewNativeComponent'; export * from './TenTapViewNativeComponent'; export * from './RichText'; -export * from './Editor/plugins/StarterKit'; -export * from './Editor/plugins/underline'; -export * from './Editor/plugins/tasklist'; -export * from './Editor/plugins/link'; -export * from './Editor/plugins/color'; -export * from './Editor/plugins/highlight'; -export * from './Editor/plugins/core'; -export * from './Editor/plugins/image'; +export { default as TenTapBridge } from './bridges/base'; +export * from './bridges/StarterKit'; +export * from './bridges/underline'; +export * from './bridges/tasklist'; +export * from './bridges/link'; +export * from './bridges/color'; +export * from './bridges/highlight'; +export * from './bridges/core'; +export * from './bridges/image'; export * from './types'; export * from './utils'; diff --git a/src/Editor/Tiptap.tsx b/src/simpleWebEditor/Tiptap.tsx similarity index 100% rename from src/Editor/Tiptap.tsx rename to src/simpleWebEditor/Tiptap.tsx diff --git a/src/Editor/index.d.ts b/src/simpleWebEditor/index.d.ts similarity index 100% rename from src/Editor/index.d.ts rename to src/simpleWebEditor/index.d.ts diff --git a/src/Editor/index.html b/src/simpleWebEditor/index.html similarity index 94% rename from src/Editor/index.html rename to src/simpleWebEditor/index.html index 05379ea..ace51b5 100644 --- a/src/Editor/index.html +++ b/src/simpleWebEditor/index.html @@ -10,7 +10,7 @@ margin: 0; padding: 0; } - #root > div { + #root > div:nth-of-type(1) { overflow: auto; height: 100%; position: absolute; diff --git a/src/Editor/index.tsx b/src/simpleWebEditor/index.tsx similarity index 100% rename from src/Editor/index.tsx rename to src/simpleWebEditor/index.tsx diff --git a/src/Editor/tsconfig.json b/src/simpleWebEditor/tsconfig.json similarity index 100% rename from src/Editor/tsconfig.json rename to src/simpleWebEditor/tsconfig.json diff --git a/src/Editor/utils/focusListener.ts b/src/simpleWebEditor/utils/focusListener.ts similarity index 100% rename from src/Editor/utils/focusListener.ts rename to src/simpleWebEditor/utils/focusListener.ts diff --git a/src/Editor/utils/index.ts b/src/simpleWebEditor/utils/index.ts similarity index 100% rename from src/Editor/utils/index.ts rename to src/simpleWebEditor/utils/index.ts diff --git a/src/types/EditorState.ts b/src/types/EditorNativeState.ts similarity index 65% rename from src/types/EditorState.ts rename to src/types/EditorNativeState.ts index 2e92054..e4ec329 100644 --- a/src/types/EditorState.ts +++ b/src/types/EditorNativeState.ts @@ -1,8 +1,8 @@ import type { RefObject } from 'react'; import type WebView from 'react-native-webview'; -import type TenTapBridge from '../Editor/plugins/base'; +import type TenTapBridge from '../bridges/base'; -export interface EditorState { +export interface EditorNativeState { isFocused: boolean; isReady: boolean; } @@ -14,8 +14,8 @@ export interface EditorInstance { initialContent?: string; webviewRef: RefObject; updateScrollThresholdAndMargin: (offset: number) => void; - getEditorState: () => EditorState; - _updateEditorState: (state: EditorState) => void; - _subscribeToEditorStateUpdate: Subscription; + getEditorState: () => EditorNativeState; + _updateEditorState: (state: EditorNativeState) => void; + _subscribeToEditorStateUpdate: Subscription; plugins?: TenTapBridge[]; } diff --git a/src/types/Messaging.ts b/src/types/Messaging.ts index 04ef686..1f39981 100644 --- a/src/types/Messaging.ts +++ b/src/types/Messaging.ts @@ -1,4 +1,4 @@ -import type { EditorState } from './EditorState'; +import type { EditorNativeState } from './EditorNativeState'; export enum EditorMessageType { Action = 'action', @@ -13,7 +13,7 @@ export interface EditorActionMessage { export interface EditorStateUpdateMessage { type: EditorMessageType.StateUpdate; - payload: EditorState; + payload: EditorNativeState; } export type EditorMessage = EditorActionMessage | EditorStateUpdateMessage; diff --git a/src/types/index.ts b/src/types/index.ts index b3a7f45..efe1800 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,3 +1,3 @@ -export * from './EditorState'; +export * from './EditorNativeState'; export * from './Messaging'; export * from './Actions'; diff --git a/src/webEditorUtils/index.ts b/src/webEditorUtils/index.ts new file mode 100644 index 0000000..74013ef --- /dev/null +++ b/src/webEditorUtils/index.ts @@ -0,0 +1 @@ +export * from './useTenTap'; \ No newline at end of file diff --git a/src/Editor/useTenTap.tsx b/src/webEditorUtils/useTenTap.tsx similarity index 75% rename from src/Editor/useTenTap.tsx rename to src/webEditorUtils/useTenTap.tsx index 3b97ff4..a4907d5 100644 --- a/src/Editor/useTenTap.tsx +++ b/src/webEditorUtils/useTenTap.tsx @@ -2,18 +2,18 @@ import debounce from 'lodash/debounce'; import { useEffect } from 'react'; import { useEditor } from '@tiptap/react'; import { Editor } from '@tiptap/core'; -import { EditorMessage, EditorMessageType } from '../types/Messaging'; +import { type EditorMessage, EditorMessageType } from '../types/Messaging'; import { EditorUpdateSettings } from '../types/Actions'; -import focusListener from './utils/focusListener'; -import { TenTapStartKit } from './plugins/StarterKit'; -import { UnderlineBridge } from './plugins/underline'; -import { EditorState } from '../types/EditorState'; -import { TaskListBridge } from './plugins/tasklist'; -import { LinkBridge } from './plugins/link'; -import { ColorBridge } from './plugins/color'; -import { HighlightBridge } from './plugins/highlight'; -import { CoreBridge } from './plugins/core'; -import { ImageBridge } from './plugins/image'; +import focusListener from '../simpleWebEditor/utils/focusListener'; +import { TenTapStartKit } from '../bridges/StarterKit'; +import { UnderlineBridge } from '../bridges/underline'; +import { type EditorNativeState } from '../types/EditorNativeState'; +import { TaskListBridge } from '../bridges/tasklist'; +import { LinkBridge } from '../bridges/link'; +import { ColorBridge } from '../bridges/color'; +import { HighlightBridge } from '../bridges/highlight'; +import { CoreBridge } from '../bridges/core'; +import { ImageBridge } from '../bridges/image'; const tenTapExtensions = [ TenTapStartKit, @@ -39,7 +39,7 @@ const extensions = tenTapExtensions const content = window.initialContent || ''; -const sendMessage = (message: EditorMessage) => { +export const sendMessage = (message: EditorMessage) => { // @ts-ignore TODO fix type window.ReactNativeWebView?.postMessage(JSON.stringify(message)); }; @@ -53,7 +53,7 @@ const sendStateUpdate = debounce((editor: Editor) => { const state = tenTapExtensions.reduce((acc, e) => { return Object.assign(acc, e.extendEditorState(editor)); - }, payload) as EditorState; + }, payload) as EditorNativeState; sendMessage({ type: EditorMessageType.StateUpdate, @@ -61,6 +61,10 @@ const sendStateUpdate = debounce((editor: Editor) => { }); }, 10); +// Wrapper for tiptap editor that will add specific mobile functionality and support tentap bridges +// args: +// tiptapOptions - all the options that tiptap editor accepts +// bridges - array of bridges that will be used to extend the editor export const useTenTap = () => { const editor = useEditor({ extensions, @@ -77,7 +81,7 @@ export const useTenTap = () => { // Subscribe to editor message const handleEditorAction = (action: any) => { tenTapExtensions.forEach((e) => { - e.onBridgeMessage(editor, action, sendMessage); + e.onBridgeMessage && e.onBridgeMessage(editor, action, sendMessage); }); if (action.type === EditorUpdateSettings.UpdateScrollThresholdAndMargin) { editor.setOptions({ diff --git a/tsconfig.json b/tsconfig.json index 0bd7b51..d4cf248 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -25,5 +25,5 @@ "target": "esnext", "verbatimModuleSyntax": true, }, - "exclude": ["./src/Editor","./website", "./example/src/Examples/Advanced/Editor"] + "exclude": ["src/simpleWebEditor","./website", "./example/src/Examples/Advanced/Editor"] } diff --git a/vite.config.ts b/vite.config.ts index 5207bb9..7fb260d 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,7 +3,7 @@ import react from '@vitejs/plugin-react'; import { viteSingleFile } from 'vite-plugin-singlefile'; export default defineConfig({ - root: 'src/Editor', + root: 'src/simpleWebEditor', build: { outDir: 'build', }, diff --git a/website/docs/examples/_category_.json b/website/docs/examples/_category_.json new file mode 100644 index 0000000..7170e1e --- /dev/null +++ b/website/docs/examples/_category_.json @@ -0,0 +1,7 @@ +{ + "label": "Examples", + "position": 4, + "link": { + "type": "generated-index" + } +} diff --git a/website/docs/examples/basic.md b/website/docs/examples/basic.md new file mode 100644 index 0000000..4d337f5 --- /dev/null +++ b/website/docs/examples/basic.md @@ -0,0 +1,5 @@ +--- +sidebar_position: 1 +--- + +# Basic example diff --git a/website/sidebars.ts b/website/sidebars.ts index 71dd9f4..c1b44b0 100644 --- a/website/sidebars.ts +++ b/website/sidebars.ts @@ -4,6 +4,7 @@ const sidebars: SidebarsConfig = { tutorialSidebar: { Introduction: ['intro'], Setup: ['setup/installation'], + examples: ['examples/basic'], }, };