@kerebron/legacy-compat 0.7.7 → 0.7.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/kerebron-light.css +1 -1
- package/dist/kerebron.cjs +2 -2
- package/dist/kerebron.css +1 -1
- package/dist/kerebron.js +247 -150
- package/dist/kerebron3.cjs.map +1 -1
- package/dist/kerebron3.js.map +1 -1
- package/package.json +1 -1
package/dist/kerebron.cjs
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
`);return{dom:l,text:d,slice:e}}function parseFromClipboard(t,e,A,n,r){let o=r.parent.type.spec.code,s,a;if(!A&&!e)return null;let l=e&&(n||o||!A);if(l){if(t.someProp("transformPastedText",d=>{e=d(e,o||n,t)}),o)return e?new Slice(Fragment.from(t.state.schema.text(e.replace(/\r\n?/g,`
|
|
9
9
|
`))),0,0):Slice.empty;let I=t.someProp("clipboardTextParser",d=>d(e,r,n,t));if(I)a=I;else{let d=r.marks(),{schema:h}=t.state,u=DOMSerializer.fromSchema(h);s=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(B=>{let E=s.appendChild(document.createElement("p"));B&&E.appendChild(u.serializeNode(h.text(B,d)))})}}else t.someProp("transformPastedHTML",I=>{A=I(A,t)}),s=readHTML(A),webkit&&restoreReplacedSpaces(s);let g=s&&s.querySelector("[data-pm-slice]"),c=g&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(g.getAttribute("data-pm-slice")||"");if(c&&c[3])for(let I=+c[3];I>0;I--){let d=s.firstChild;for(;d&&d.nodeType!=1;)d=d.nextSibling;if(!d)break;s=d}if(a||(a=(t.someProp("clipboardParser")||t.someProp("domParser")||DOMParser$1.fromSchema(t.state.schema)).parseSlice(s,{preserveWhitespace:!!(l||c),context:r,ruleFromNode(d){return d.nodeName=="BR"&&!d.nextSibling&&d.parentNode&&!inlineParents.test(d.parentNode.nodeName)?{ignore:!0}:null}})),c)a=addContext(closeSlice$1(a,+c[1],+c[2]),c[4]);else if(a=Slice.maxOpen(normalizeSiblings$1(a.content,r),!0),a.openStart||a.openEnd){let I=0,d=0;for(let h=a.content.firstChild;I<a.openStart&&!h.type.spec.isolating;I++,h=h.firstChild);for(let h=a.content.lastChild;d<a.openEnd&&!h.type.spec.isolating;d++,h=h.lastChild);a=closeSlice$1(a,I,d)}return t.someProp("transformPasted",I=>{a=I(a,t)}),a}const inlineParents=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function normalizeSiblings$1(t,e){if(t.childCount<2)return t;for(let A=e.depth;A>=0;A--){let r=e.node(A).contentMatchAt(e.index(A)),o,s=[];if(t.forEach(a=>{if(!s)return;let l=r.findWrapping(a.type),g;if(!l)return s=null;if(g=s.length&&o.length&&addToSibling$1(l,o,a,s[s.length-1],0))s[s.length-1]=g;else{s.length&&(s[s.length-1]=closeRight$1(s[s.length-1],o.length));let c=withWrappers$1(a,l);s.push(c),r=r.matchType(c.type),o=l}}),s)return Fragment.from(s)}return t}function withWrappers$1(t,e,A=0){for(let n=e.length-1;n>=A;n--)t=e[n].create(null,Fragment.from(t));return t}function addToSibling$1(t,e,A,n,r){if(r<t.length&&r<e.length&&t[r]==e[r]){let o=addToSibling$1(t,e,A,n.lastChild,r+1);if(o)return n.copy(n.content.replaceChild(n.childCount-1,o));if(n.contentMatchAt(n.childCount).matchType(r==t.length-1?A.type:t[r+1]))return n.copy(n.content.append(Fragment.from(withWrappers$1(A,t,r+1))))}}function closeRight$1(t,e){if(e==0)return t;let A=t.content.replaceChild(t.childCount-1,closeRight$1(t.lastChild,e-1)),n=t.contentMatchAt(t.childCount).fillBefore(Fragment.empty,!0);return t.copy(A.append(n))}function closeRange$1(t,e,A,n,r,o){let s=e<0?t.firstChild:t.lastChild,a=s.content;return t.childCount>1&&(o=0),r<n-1&&(a=closeRange$1(a,e,A,n,r+1,o)),r>=A&&(a=e<0?s.contentMatchAt(0).fillBefore(a,o<=r).append(a):a.append(s.contentMatchAt(s.childCount).fillBefore(Fragment.empty,!0))),t.replaceChild(e<0?0:t.childCount-1,s.copy(a))}function closeSlice$1(t,e,A){return e<t.openStart&&(t=new Slice(closeRange$1(t.content,-1,e,t.openStart,0,t.openEnd),e,t.openEnd)),A<t.openEnd&&(t=new Slice(closeRange$1(t.content,1,A,t.openEnd,0,0),t.openStart,A)),t}const wrapMap={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};let _detachedDoc=null;function detachedDoc(){return _detachedDoc||(_detachedDoc=document.implementation.createHTMLDocument("title"))}let _policy=null;function maybeWrapTrusted(t){let e=window.trustedTypes;return e?(_policy||(_policy=e.defaultPolicy||e.createPolicy("ProseMirrorClipboard",{createHTML:A=>A})),_policy.createHTML(t)):t}function readHTML(t){let e=/^(\s*<meta [^>]*>)*/.exec(t);e&&(t=t.slice(e[0].length));let A=detachedDoc().createElement("div"),n=/<([a-z][^>\s]+)/i.exec(t),r;if((r=n&&wrapMap[n[1].toLowerCase()])&&(t=r.map(o=>"<"+o+">").join("")+t+r.map(o=>"</"+o+">").reverse().join("")),A.innerHTML=maybeWrapTrusted(t),r)for(let o=0;o<r.length;o++)A=A.querySelector(r[o])||A;return A}function restoreReplacedSpaces(t){let e=t.querySelectorAll(chrome?"span:not([class]):not([style])":"span.Apple-converted-space");for(let A=0;A<e.length;A++){let n=e[A];n.childNodes.length==1&&n.textContent==" "&&n.parentNode&&n.parentNode.replaceChild(t.ownerDocument.createTextNode(" "),n)}}function addContext(t,e){if(!t.size)return t;let A=t.content.firstChild.type.schema,n;try{n=JSON.parse(e)}catch{return t}let{content:r,openStart:o,openEnd:s}=t;for(let a=n.length-2;a>=0;a-=2){let l=A.nodes[n[a]];if(!l||l.hasRequiredAttrs())break;r=Fragment.from(l.create(n[a+1],r)),o++,s++}return new Slice(r,o,s)}const handlers={},editHandlers={},passiveHandlers={touchstart:!0,touchmove:!0};class InputState{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:"",button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function initInput(t){for(let e in handlers){let A=handlers[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=n=>{eventBelongsToView(t,n)&&!runCustomHandler(t,n)&&(t.editable||!(n.type in editHandlers))&&A(t,n)},passiveHandlers[e]?{passive:!0}:void 0)}safari&&t.dom.addEventListener("input",()=>null),ensureListeners(t)}function setSelectionOrigin(t,e){t.input.lastSelectionOrigin=e,t.input.lastSelectionTime=Date.now()}function destroyInput(t){t.domObserver.stop();for(let e in t.input.eventHandlers)t.dom.removeEventListener(e,t.input.eventHandlers[e]);clearTimeout(t.input.composingTimeout),clearTimeout(t.input.lastIOSEnterFallbackTimeout)}function ensureListeners(t){t.someProp("handleDOMEvents",e=>{for(let A in e)t.input.eventHandlers[A]||t.dom.addEventListener(A,t.input.eventHandlers[A]=n=>runCustomHandler(t,n))})}function runCustomHandler(t,e){return t.someProp("handleDOMEvents",A=>{let n=A[e.type];return n?n(t,e)||e.defaultPrevented:!1})}function eventBelongsToView(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let A=e.target;A!=t.dom;A=A.parentNode)if(!A||A.nodeType==11||A.pmViewDesc&&A.pmViewDesc.stopEvent(e))return!1;return!0}function dispatchEvent(t,e){!runCustomHandler(t,e)&&handlers[e.type]&&(t.editable||!(e.type in editHandlers))&&handlers[e.type](t,e)}editHandlers.keydown=(t,e)=>{let A=e;if(t.input.shiftKey=A.keyCode==16||A.shiftKey,!inOrNearComposition(t,A)&&(t.input.lastKeyCode=A.keyCode,t.input.lastKeyCodeTime=Date.now(),!(android&&chrome&&A.keyCode==13)))if(A.keyCode!=229&&t.domObserver.forceFlush(),ios&&A.keyCode==13&&!A.ctrlKey&&!A.altKey&&!A.metaKey){let n=Date.now();t.input.lastIOSEnter=n,t.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{t.input.lastIOSEnter==n&&(t.someProp("handleKeyDown",r=>r(t,keyEvent(13,"Enter"))),t.input.lastIOSEnter=0)},200)}else t.someProp("handleKeyDown",n=>n(t,A))||captureKeyDown(t,A)?A.preventDefault():setSelectionOrigin(t,"key")};editHandlers.keyup=(t,e)=>{e.keyCode==16&&(t.input.shiftKey=!1)};editHandlers.keypress=(t,e)=>{let A=e;if(inOrNearComposition(t,A)||!A.charCode||A.ctrlKey&&!A.altKey||mac$3&&A.metaKey)return;if(t.someProp("handleKeyPress",r=>r(t,A))){A.preventDefault();return}let n=t.state.selection;if(!(n instanceof TextSelection)||!n.$from.sameParent(n.$to)){let r=String.fromCharCode(A.charCode),o=()=>t.state.tr.insertText(r).scrollIntoView();!/[\r\n]/.test(r)&&!t.someProp("handleTextInput",s=>s(t,n.$from.pos,n.$to.pos,r,o))&&t.dispatch(o()),A.preventDefault()}};function eventCoords(t){return{left:t.clientX,top:t.clientY}}function isNear(t,e){let A=e.x-t.clientX,n=e.y-t.clientY;return A*A+n*n<100}function runHandlerOnContext(t,e,A,n,r){if(n==-1)return!1;let o=t.state.doc.resolve(n);for(let s=o.depth+1;s>0;s--)if(t.someProp(e,a=>s>o.depth?a(t,A,o.nodeAfter,o.before(s),r,!0):a(t,A,o.node(s),o.before(s),r,!1)))return!0;return!1}function updateSelection(t,e,A){if(t.focused||t.focus(),t.state.selection.eq(e))return;let n=t.state.tr.setSelection(e);n.setMeta("pointer",!0),t.dispatch(n)}function selectClickedLeaf(t,e){if(e==-1)return!1;let A=t.state.doc.resolve(e),n=A.nodeAfter;return n&&n.isAtom&&NodeSelection.isSelectable(n)?(updateSelection(t,new NodeSelection(A)),!0):!1}function selectClickedNode(t,e){if(e==-1)return!1;let A=t.state.selection,n,r;A instanceof NodeSelection&&(n=A.node);let o=t.state.doc.resolve(e);for(let s=o.depth+1;s>0;s--){let a=s>o.depth?o.nodeAfter:o.node(s);if(NodeSelection.isSelectable(a)){n&&A.$from.depth>0&&s>=A.$from.depth&&o.before(A.$from.depth+1)==A.$from.pos?r=o.before(A.$from.depth):r=o.before(s);break}}return r!=null?(updateSelection(t,NodeSelection.create(t.state.doc,r)),!0):!1}function handleSingleClick(t,e,A,n,r){return runHandlerOnContext(t,"handleClickOn",e,A,n)||t.someProp("handleClick",o=>o(t,e,n))||(r?selectClickedNode(t,A):selectClickedLeaf(t,A))}function handleDoubleClick(t,e,A,n){return runHandlerOnContext(t,"handleDoubleClickOn",e,A,n)||t.someProp("handleDoubleClick",r=>r(t,e,n))}function handleTripleClick$1(t,e,A,n){return runHandlerOnContext(t,"handleTripleClickOn",e,A,n)||t.someProp("handleTripleClick",r=>r(t,e,n))||defaultTripleClick(t,A,n)}function defaultTripleClick(t,e,A){if(A.button!=0)return!1;let n=t.state.doc;if(e==-1)return n.inlineContent?(updateSelection(t,TextSelection.create(n,0,n.content.size)),!0):!1;let r=n.resolve(e);for(let o=r.depth+1;o>0;o--){let s=o>r.depth?r.nodeAfter:r.node(o),a=r.before(o);if(s.inlineContent)updateSelection(t,TextSelection.create(n,a+1,a+1+s.content.size));else if(NodeSelection.isSelectable(s))updateSelection(t,NodeSelection.create(n,a));else continue;return!0}}function forceDOMFlush(t){return endComposition(t)}const selectNodeModifier=mac$3?"metaKey":"ctrlKey";handlers.mousedown=(t,e)=>{let A=e;t.input.shiftKey=A.shiftKey;let n=forceDOMFlush(t),r=Date.now(),o="singleClick";r-t.input.lastClick.time<500&&isNear(A,t.input.lastClick)&&!A[selectNodeModifier]&&t.input.lastClick.button==A.button&&(t.input.lastClick.type=="singleClick"?o="doubleClick":t.input.lastClick.type=="doubleClick"&&(o="tripleClick")),t.input.lastClick={time:r,x:A.clientX,y:A.clientY,type:o,button:A.button};let s=t.posAtCoords(eventCoords(A));s&&(o=="singleClick"?(t.input.mouseDown&&t.input.mouseDown.done(),t.input.mouseDown=new MouseDown(t,s,A,!!n)):(o=="doubleClick"?handleDoubleClick:handleTripleClick$1)(t,s.pos,s.inside,A)?A.preventDefault():setSelectionOrigin(t,"pointer"))};class MouseDown{constructor(e,A,n,r){this.view=e,this.pos=A,this.event=n,this.flushed=r,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!n[selectNodeModifier],this.allowDefault=n.shiftKey;let o,s;if(A.inside>-1)o=e.state.doc.nodeAt(A.inside),s=A.inside;else{let c=e.state.doc.resolve(A.pos);o=c.parent,s=c.depth?c.before():0}const a=r?null:n.target,l=a?e.docView.nearestDesc(a,!0):null;this.target=l&&l.dom.nodeType==1?l.dom:null;let{selection:g}=e.state;(n.button==0&&o.type.spec.draggable&&o.type.spec.selectable!==!1||g instanceof NodeSelection&&g.from<=s&&g.to>s)&&(this.mightDrag={node:o,pos:s,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&gecko&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),setSelectionOrigin(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>selectionToDOM(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let A=this.pos;this.view.state.doc!=this.startDoc&&(A=this.view.posAtCoords(eventCoords(e))),this.updateAllowDefault(e),this.allowDefault||!A?setSelectionOrigin(this.view,"pointer"):handleSingleClick(this.view,A.pos,A.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||safari&&this.mightDrag&&!this.mightDrag.node.isAtom||chrome&&!this.view.state.selection.visible&&Math.min(Math.abs(A.pos-this.view.state.selection.from),Math.abs(A.pos-this.view.state.selection.to))<=2)?(updateSelection(this.view,Selection.near(this.view.state.doc.resolve(A.pos))),e.preventDefault()):setSelectionOrigin(this.view,"pointer")}move(e){this.updateAllowDefault(e),setSelectionOrigin(this.view,"pointer"),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}}handlers.touchstart=t=>{t.input.lastTouch=Date.now(),forceDOMFlush(t),setSelectionOrigin(t,"pointer")};handlers.touchmove=t=>{t.input.lastTouch=Date.now(),setSelectionOrigin(t,"pointer")};handlers.contextmenu=t=>forceDOMFlush(t);function inOrNearComposition(t,e){return t.composing?!0:safari&&Math.abs(e.timeStamp-t.input.compositionEndedAt)<500?(t.input.compositionEndedAt=-2e8,!0):!1}const timeoutComposition=android?5e3:-1;editHandlers.compositionstart=editHandlers.compositionupdate=t=>{if(!t.composing){t.domObserver.flush();let{state:e}=t,A=e.selection.$to;if(e.selection instanceof TextSelection&&(e.storedMarks||!A.textOffset&&A.parentOffset&&A.nodeBefore.marks.some(n=>n.type.spec.inclusive===!1)))t.markCursor=t.state.storedMarks||A.marks(),endComposition(t,!0),t.markCursor=null;else if(endComposition(t,!e.selection.empty),gecko&&e.selection.empty&&A.parentOffset&&!A.textOffset&&A.nodeBefore.marks.length){let n=t.domSelectionRange();for(let r=n.focusNode,o=n.focusOffset;r&&r.nodeType==1&&o!=0;){let s=o<0?r.lastChild:r.childNodes[o-1];if(!s)break;if(s.nodeType==3){let a=t.domSelection();a&&a.collapse(s,s.nodeValue.length);break}else r=s,o=-1}}t.input.composing=!0}scheduleComposeEnd(t,timeoutComposition)};editHandlers.compositionend=(t,e)=>{t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=e.timeStamp,t.input.compositionPendingChanges=t.domObserver.pendingRecords().length?t.input.compositionID:0,t.input.compositionNode=null,t.input.compositionPendingChanges&&Promise.resolve().then(()=>t.domObserver.flush()),t.input.compositionID++,scheduleComposeEnd(t,20))};function scheduleComposeEnd(t,e){clearTimeout(t.input.composingTimeout),e>-1&&(t.input.composingTimeout=setTimeout(()=>endComposition(t),e))}function clearComposition(t){for(t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=timestampFromCustomEvent());t.input.compositionNodes.length>0;)t.input.compositionNodes.pop().markParentsDirty()}function findCompositionNode(t){let e=t.domSelectionRange();if(!e.focusNode)return null;let A=textNodeBefore$1(e.focusNode,e.focusOffset),n=textNodeAfter$1(e.focusNode,e.focusOffset);if(A&&n&&A!=n){let r=n.pmViewDesc,o=t.domObserver.lastChangedTextNode;if(A==o||n==o)return o;if(!r||!r.isText(n.nodeValue))return n;if(t.input.compositionNode==n){let s=A.pmViewDesc;if(!(!s||!s.isText(A.nodeValue)))return n}}return A||n}function timestampFromCustomEvent(){let t=document.createEvent("Event");return t.initEvent("event",!0,!0),t.timeStamp}function endComposition(t,e=!1){if(!(android&&t.domObserver.flushingSoon>=0)){if(t.domObserver.forceFlush(),clearComposition(t),e||t.docView&&t.docView.dirty){let A=selectionFromDOM(t),n=t.state.selection;return A&&!A.eq(n)?t.dispatch(t.state.tr.setSelection(A)):(t.markCursor||e)&&!n.$from.node(n.$from.sharedDepth(n.to)).inlineContent?t.dispatch(t.state.tr.deleteSelection()):t.updateState(t.state),!0}return!1}}function captureCopy(t,e){if(!t.dom.parentNode)return;let A=t.dom.parentNode.appendChild(document.createElement("div"));A.appendChild(e),A.style.cssText="position: fixed; left: -10000px; top: 10px";let n=getSelection(),r=document.createRange();r.selectNodeContents(e),t.dom.blur(),n.removeAllRanges(),n.addRange(r),setTimeout(()=>{A.parentNode&&A.parentNode.removeChild(A),t.focus()},50)}const brokenClipboardAPI=ie$1&&ie_version<15||ios&&webkit_version<604;handlers.copy=editHandlers.cut=(t,e)=>{let A=e,n=t.state.selection,r=A.type=="cut";if(n.empty)return;let o=brokenClipboardAPI?null:A.clipboardData,s=n.content(),{dom:a,text:l}=serializeForClipboard(t,s);o?(A.preventDefault(),o.clearData(),o.setData("text/html",a.innerHTML),o.setData("text/plain",l)):captureCopy(t,a),r&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function sliceSingleNode$1(t){return t.openStart==0&&t.openEnd==0&&t.content.childCount==1?t.content.firstChild:null}function capturePaste(t,e){if(!t.dom.parentNode)return;let A=t.input.shiftKey||t.state.selection.$from.parent.type.spec.code,n=t.dom.parentNode.appendChild(document.createElement(A?"textarea":"div"));A||(n.contentEditable="true"),n.style.cssText="position: fixed; left: -10000px; top: 10px",n.focus();let r=t.input.shiftKey&&t.input.lastKeyCode!=45;setTimeout(()=>{t.focus(),n.parentNode&&n.parentNode.removeChild(n),A?doPaste(t,n.value,null,r,e):doPaste(t,n.textContent,n.innerHTML,r,e)},50)}function doPaste(t,e,A,n,r){let o=parseFromClipboard(t,e,A,n,t.state.selection.$from);if(t.someProp("handlePaste",l=>l(t,r,o||Slice.empty)))return!0;if(!o)return!1;let s=sliceSingleNode$1(o),a=s?t.state.tr.replaceSelectionWith(s,n):t.state.tr.replaceSelection(o);return t.dispatch(a.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function getText$1(t){let e=t.getData("text/plain")||t.getData("Text");if(e)return e;let A=t.getData("text/uri-list");return A?A.replace(/\r?\n/g," "):""}editHandlers.paste=(t,e)=>{let A=e;if(t.composing&&!android)return;let n=brokenClipboardAPI?null:A.clipboardData,r=t.input.shiftKey&&t.input.lastKeyCode!=45;n&&doPaste(t,getText$1(n),n.getData("text/html"),r,A)?A.preventDefault():capturePaste(t,A)};class Dragging{constructor(e,A,n){this.slice=e,this.move=A,this.node=n}}const dragCopyModifier=mac$3?"altKey":"ctrlKey";function dragMoves(t,e){let A=t.someProp("dragCopies",n=>!n(e));return A??!e[dragCopyModifier]}handlers.dragstart=(t,e)=>{let A=e,n=t.input.mouseDown;if(n&&n.done(),!A.dataTransfer)return;let r=t.state.selection,o=r.empty?null:t.posAtCoords(eventCoords(A)),s;if(!(o&&o.pos>=r.from&&o.pos<=(r instanceof NodeSelection?r.to-1:r.to))){if(n&&n.mightDrag)s=NodeSelection.create(t.state.doc,n.mightDrag.pos);else if(A.target&&A.target.nodeType==1){let I=t.docView.nearestDesc(A.target,!0);I&&I.node.type.spec.draggable&&I!=t.docView&&(s=NodeSelection.create(t.state.doc,I.posBefore))}}let a=(s||t.state.selection).content(),{dom:l,text:g,slice:c}=serializeForClipboard(t,a);(!A.dataTransfer.files.length||!chrome||chrome_version>120)&&A.dataTransfer.clearData(),A.dataTransfer.setData(brokenClipboardAPI?"Text":"text/html",l.innerHTML),A.dataTransfer.effectAllowed="copyMove",brokenClipboardAPI||A.dataTransfer.setData("text/plain",g),t.dragging=new Dragging(c,dragMoves(t,A),s)};handlers.dragend=t=>{let e=t.dragging;window.setTimeout(()=>{t.dragging==e&&(t.dragging=null)},50)};editHandlers.dragover=editHandlers.dragenter=(t,e)=>e.preventDefault();editHandlers.drop=(t,e)=>{let A=e,n=t.dragging;if(t.dragging=null,!A.dataTransfer)return;let r=t.posAtCoords(eventCoords(A));if(!r)return;let o=t.state.doc.resolve(r.pos),s=n&&n.slice;s?t.someProp("transformPasted",u=>{s=u(s,t)}):s=parseFromClipboard(t,getText$1(A.dataTransfer),brokenClipboardAPI?null:A.dataTransfer.getData("text/html"),!1,o);let a=!!(n&&dragMoves(t,A));if(t.someProp("handleDrop",u=>u(t,A,s||Slice.empty,a))){A.preventDefault();return}if(!s)return;A.preventDefault();let l=s?dropPoint(t.state.doc,o.pos,s):o.pos;l==null&&(l=o.pos);let g=t.state.tr;if(a){let{node:u}=n;u?u.replace(g):g.deleteSelection()}let c=g.mapping.map(l),I=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,d=g.doc;if(I?g.replaceRangeWith(c,c,s.content.firstChild):g.replaceRange(c,c,s),g.doc.eq(d))return;let h=g.doc.resolve(c);if(I&&NodeSelection.isSelectable(s.content.firstChild)&&h.nodeAfter&&h.nodeAfter.sameMarkup(s.content.firstChild))g.setSelection(new NodeSelection(h));else{let u=g.mapping.map(l);g.mapping.maps[g.mapping.maps.length-1].forEach((B,E,f,Q)=>u=Q),g.setSelection(selectionBetween(t,h,g.doc.resolve(u)))}t.focus(),t.dispatch(g.setMeta("uiEvent","drop"))};handlers.focus=t=>{t.input.lastFocus=Date.now(),t.focused||(t.domObserver.stop(),t.dom.classList.add("ProseMirror-focused"),t.domObserver.start(),t.focused=!0,setTimeout(()=>{t.docView&&t.hasFocus()&&!t.domObserver.currentSelection.eq(t.domSelectionRange())&&selectionToDOM(t)},20))};handlers.blur=(t,e)=>{let A=e;t.focused&&(t.domObserver.stop(),t.dom.classList.remove("ProseMirror-focused"),t.domObserver.start(),A.relatedTarget&&t.dom.contains(A.relatedTarget)&&t.domObserver.currentSelection.clear(),t.focused=!1)};handlers.beforeinput=(t,e)=>{if(chrome&&android&&e.inputType=="deleteContentBackward"){t.domObserver.flushSoon();let{domChangeCount:n}=t.input;setTimeout(()=>{if(t.input.domChangeCount!=n||(t.dom.blur(),t.focus(),t.someProp("handleKeyDown",o=>o(t,keyEvent(8,"Backspace")))))return;let{$cursor:r}=t.state.selection;r&&r.pos>0&&t.dispatch(t.state.tr.delete(r.pos-1,r.pos).scrollIntoView())},50)}};for(let t in editHandlers)handlers[t]=editHandlers[t];function compareObjs(t,e){if(t==e)return!0;for(let A in t)if(t[A]!==e[A])return!1;for(let A in e)if(!(A in t))return!1;return!0}class WidgetType{constructor(e,A){this.toDOM=e,this.spec=A||noSpec,this.side=this.spec.side||0}map(e,A,n,r){let{pos:o,deleted:s}=e.mapResult(A.from+r,this.side<0?-1:1);return s?null:new Decoration(o-n,o-n,this)}valid(){return!0}eq(e){return this==e||e instanceof WidgetType&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&compareObjs(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class InlineType{constructor(e,A){this.attrs=e,this.spec=A||noSpec}map(e,A,n,r){let o=e.map(A.from+r,this.spec.inclusiveStart?-1:1)-n,s=e.map(A.to+r,this.spec.inclusiveEnd?1:-1)-n;return o>=s?null:new Decoration(o,s,this)}valid(e,A){return A.from<A.to}eq(e){return this==e||e instanceof InlineType&&compareObjs(this.attrs,e.attrs)&&compareObjs(this.spec,e.spec)}static is(e){return e.type instanceof InlineType}destroy(){}}class NodeType{constructor(e,A){this.attrs=e,this.spec=A||noSpec}map(e,A,n,r){let o=e.mapResult(A.from+r,1);if(o.deleted)return null;let s=e.mapResult(A.to+r,-1);return s.deleted||s.pos<=o.pos?null:new Decoration(o.pos-n,s.pos-n,this)}valid(e,A){let{index:n,offset:r}=e.content.findIndex(A.from),o;return r==A.from&&!(o=e.child(n)).isText&&r+o.nodeSize==A.to}eq(e){return this==e||e instanceof NodeType&&compareObjs(this.attrs,e.attrs)&&compareObjs(this.spec,e.spec)}destroy(){}}class Decoration{constructor(e,A,n){this.from=e,this.to=A,this.type=n}copy(e,A){return new Decoration(e,A,this.type)}eq(e,A=0){return this.type.eq(e.type)&&this.from+A==e.from&&this.to+A==e.to}map(e,A,n){return this.type.map(e,this,A,n)}static widget(e,A,n){return new Decoration(e,e,new WidgetType(A,n))}static inline(e,A,n,r){return new Decoration(e,A,new InlineType(n,r))}static node(e,A,n,r){return new Decoration(e,A,new NodeType(n,r))}get spec(){return this.type.spec}get inline(){return this.type instanceof InlineType}get widget(){return this.type instanceof WidgetType}}const none=[],noSpec={};class DecorationSet{constructor(e,A){this.local=e.length?e:none,this.children=A.length?A:none}static create(e,A){return A.length?buildTree(A,e,0,noSpec):empty$1}find(e,A,n){let r=[];return this.findInner(e??0,A??1e9,r,0,n),r}findInner(e,A,n,r,o){for(let s=0;s<this.local.length;s++){let a=this.local[s];a.from<=A&&a.to>=e&&(!o||o(a.spec))&&n.push(a.copy(a.from+r,a.to+r))}for(let s=0;s<this.children.length;s+=3)if(this.children[s]<A&&this.children[s+1]>e){let a=this.children[s]+1;this.children[s+2].findInner(e-a,A-a,n,r+a,o)}}map(e,A,n){return this==empty$1||e.maps.length==0?this:this.mapInner(e,A,0,0,n||noSpec)}mapInner(e,A,n,r,o){let s;for(let a=0;a<this.local.length;a++){let l=this.local[a].map(e,n,r);l&&l.type.valid(A,l)?(s||(s=[])).push(l):o.onRemove&&o.onRemove(this.local[a].spec)}return this.children.length?mapChildren(this.children,s||[],e,A,n,r,o):s?new DecorationSet(s.sort(byPos),none):empty$1}add(e,A){return A.length?this==empty$1?DecorationSet.create(e,A):this.addInner(e,A,0):this}addInner(e,A,n){let r,o=0;e.forEach((a,l)=>{let g=l+n,c;if(c=takeSpansForNode(A,a,g)){for(r||(r=this.children.slice());o<r.length&&r[o]<l;)o+=3;r[o]==l?r[o+2]=r[o+2].addInner(a,c,g+1):r.splice(o,0,l,l+a.nodeSize,buildTree(c,a,g+1,noSpec)),o+=3}});let s=moveSpans(o?withoutNulls(A):A,-n);for(let a=0;a<s.length;a++)s[a].type.valid(e,s[a])||s.splice(a--,1);return new DecorationSet(s.length?this.local.concat(s).sort(byPos):this.local,r||this.children)}remove(e){return e.length==0||this==empty$1?this:this.removeInner(e,0)}removeInner(e,A){let n=this.children,r=this.local;for(let o=0;o<n.length;o+=3){let s,a=n[o]+A,l=n[o+1]+A;for(let c=0,I;c<e.length;c++)(I=e[c])&&I.from>a&&I.to<l&&(e[c]=null,(s||(s=[])).push(I));if(!s)continue;n==this.children&&(n=this.children.slice());let g=n[o+2].removeInner(s,a+1);g!=empty$1?n[o+2]=g:(n.splice(o,3),o-=3)}if(r.length){for(let o=0,s;o<e.length;o++)if(s=e[o])for(let a=0;a<r.length;a++)r[a].eq(s,A)&&(r==this.local&&(r=this.local.slice()),r.splice(a--,1))}return n==this.children&&r==this.local?this:r.length||n.length?new DecorationSet(r,n):empty$1}forChild(e,A){if(this==empty$1)return this;if(A.isLeaf)return DecorationSet.empty;let n,r;for(let a=0;a<this.children.length;a+=3)if(this.children[a]>=e){this.children[a]==e&&(n=this.children[a+2]);break}let o=e+1,s=o+A.content.size;for(let a=0;a<this.local.length;a++){let l=this.local[a];if(l.from<s&&l.to>o&&l.type instanceof InlineType){let g=Math.max(o,l.from)-o,c=Math.min(s,l.to)-o;g<c&&(r||(r=[])).push(l.copy(g,c))}}if(r){let a=new DecorationSet(r.sort(byPos),none);return n?new DecorationGroup([a,n]):a}return n||empty$1}eq(e){if(this==e)return!0;if(!(e instanceof DecorationSet)||this.local.length!=e.local.length||this.children.length!=e.children.length)return!1;for(let A=0;A<this.local.length;A++)if(!this.local[A].eq(e.local[A]))return!1;for(let A=0;A<this.children.length;A+=3)if(this.children[A]!=e.children[A]||this.children[A+1]!=e.children[A+1]||!this.children[A+2].eq(e.children[A+2]))return!1;return!0}locals(e){return removeOverlap(this.localsInner(e))}localsInner(e){if(this==empty$1)return none;if(e.inlineContent||!this.local.some(InlineType.is))return this.local;let A=[];for(let n=0;n<this.local.length;n++)this.local[n].type instanceof InlineType||A.push(this.local[n]);return A}forEachSet(e){e(this)}}DecorationSet.empty=new DecorationSet([],[]);DecorationSet.removeOverlap=removeOverlap;const empty$1=DecorationSet.empty;class DecorationGroup{constructor(e){this.members=e}map(e,A){const n=this.members.map(r=>r.map(e,A,noSpec));return DecorationGroup.from(n)}forChild(e,A){if(A.isLeaf)return DecorationSet.empty;let n=[];for(let r=0;r<this.members.length;r++){let o=this.members[r].forChild(e,A);o!=empty$1&&(o instanceof DecorationGroup?n=n.concat(o.members):n.push(o))}return DecorationGroup.from(n)}eq(e){if(!(e instanceof DecorationGroup)||e.members.length!=this.members.length)return!1;for(let A=0;A<this.members.length;A++)if(!this.members[A].eq(e.members[A]))return!1;return!0}locals(e){let A,n=!0;for(let r=0;r<this.members.length;r++){let o=this.members[r].localsInner(e);if(o.length)if(!A)A=o;else{n&&(A=A.slice(),n=!1);for(let s=0;s<o.length;s++)A.push(o[s])}}return A?removeOverlap(n?A:A.sort(byPos)):none}static from(e){switch(e.length){case 0:return empty$1;case 1:return e[0];default:return new DecorationGroup(e.every(A=>A instanceof DecorationSet)?e:e.reduce((A,n)=>A.concat(n instanceof DecorationSet?n:n.members),[]))}}forEachSet(e){for(let A=0;A<this.members.length;A++)this.members[A].forEachSet(e)}}function mapChildren(t,e,A,n,r,o,s){let a=t.slice();for(let g=0,c=o;g<A.maps.length;g++){let I=0;A.maps[g].forEach((d,h,u,B)=>{let E=B-u-(h-d);for(let f=0;f<a.length;f+=3){let Q=a[f+1];if(Q<0||d>Q+c-I)continue;let p=a[f]+c-I;h>=p?a[f+1]=d<=p?-2:-1:d>=c&&E&&(a[f]+=E,a[f+1]+=E)}I+=E}),c=A.maps[g].map(c,-1)}let l=!1;for(let g=0;g<a.length;g+=3)if(a[g+1]<0){if(a[g+1]==-2){l=!0,a[g+1]=-1;continue}let c=A.map(t[g]+o),I=c-r;if(I<0||I>=n.content.size){l=!0;continue}let d=A.map(t[g+1]+o,-1),h=d-r,{index:u,offset:B}=n.content.findIndex(I),E=n.maybeChild(u);if(E&&B==I&&B+E.nodeSize==h){let f=a[g+2].mapInner(A,E,c+1,t[g]+o+1,s);f!=empty$1?(a[g]=I,a[g+1]=h,a[g+2]=f):(a[g+1]=-2,l=!0)}else l=!0}if(l){let g=mapAndGatherRemainingDecorations(a,t,e,A,r,o,s),c=buildTree(g,n,0,s);e=c.local;for(let I=0;I<a.length;I+=3)a[I+1]<0&&(a.splice(I,3),I-=3);for(let I=0,d=0;I<c.children.length;I+=3){let h=c.children[I];for(;d<a.length&&a[d]<h;)d+=3;a.splice(d,0,c.children[I],c.children[I+1],c.children[I+2])}}return new DecorationSet(e.sort(byPos),a)}function moveSpans(t,e){if(!e||!t.length)return t;let A=[];for(let n=0;n<t.length;n++){let r=t[n];A.push(new Decoration(r.from+e,r.to+e,r.type))}return A}function mapAndGatherRemainingDecorations(t,e,A,n,r,o,s){function a(l,g){for(let c=0;c<l.local.length;c++){let I=l.local[c].map(n,r,g);I?A.push(I):s.onRemove&&s.onRemove(l.local[c].spec)}for(let c=0;c<l.children.length;c+=3)a(l.children[c+2],l.children[c]+g+1)}for(let l=0;l<t.length;l+=3)t[l+1]==-1&&a(t[l+2],e[l]+o+1);return A}function takeSpansForNode(t,e,A){if(e.isLeaf)return null;let n=A+e.nodeSize,r=null;for(let o=0,s;o<t.length;o++)(s=t[o])&&s.from>A&&s.to<n&&((r||(r=[])).push(s),t[o]=null);return r}function withoutNulls(t){let e=[];for(let A=0;A<t.length;A++)t[A]!=null&&e.push(t[A]);return e}function buildTree(t,e,A,n){let r=[],o=!1;e.forEach((a,l)=>{let g=takeSpansForNode(t,a,l+A);if(g){o=!0;let c=buildTree(g,a,A+l+1,n);c!=empty$1&&r.push(l,l+a.nodeSize,c)}});let s=moveSpans(o?withoutNulls(t):t,-A).sort(byPos);for(let a=0;a<s.length;a++)s[a].type.valid(e,s[a])||(n.onRemove&&n.onRemove(s[a].spec),s.splice(a--,1));return s.length||r.length?new DecorationSet(s,r):empty$1}function byPos(t,e){return t.from-e.from||t.to-e.to}function removeOverlap(t){let e=t;for(let A=0;A<e.length-1;A++){let n=e[A];if(n.from!=n.to)for(let r=A+1;r<e.length;r++){let o=e[r];if(o.from==n.from){o.to!=n.to&&(e==t&&(e=t.slice()),e[r]=o.copy(o.from,n.to),insertAhead(e,r+1,o.copy(n.to,o.to)));continue}else{o.from<n.to&&(e==t&&(e=t.slice()),e[A]=n.copy(n.from,o.from),insertAhead(e,r,n.copy(o.from,n.to)));break}}}return e}function insertAhead(t,e,A){for(;e<t.length&&byPos(A,t[e])>0;)e++;t.splice(e,0,A)}function viewDecorations(t){let e=[];return t.someProp("decorations",A=>{let n=A(t.state);n&&n!=empty$1&&e.push(n)}),t.cursorWrapper&&e.push(DecorationSet.create(t.state.doc,[t.cursorWrapper.deco])),DecorationGroup.from(e)}const observeOptions={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},useCharData=ie$1&&ie_version<=11;class SelectionState{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}}class DOMObserver{constructor(e,A){this.view=e,this.handleDOMChange=A,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new SelectionState,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(n=>{for(let r=0;r<n.length;r++)this.queue.push(n[r]);ie$1&&ie_version<=11&&n.some(r=>r.type=="childList"&&r.removedNodes.length||r.type=="characterData"&&r.oldValue.length>r.target.nodeValue.length)?this.flushSoon():this.flush()}),useCharData&&(this.onCharData=n=>{this.queue.push({target:n.target,type:"characterData",oldValue:n.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,observeOptions)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let A=0;A<e.length;A++)this.queue.push(e[A]);window.setTimeout(()=>this.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(hasFocusAndSelection(this.view)){if(this.suppressingSelectionUpdates)return selectionToDOM(this.view);if(ie$1&&ie_version<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&isEquivalentPosition(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let A=new Set,n;for(let o=e.focusNode;o;o=parentNode(o))A.add(o);for(let o=e.anchorNode;o;o=parentNode(o))if(A.has(o)){n=o;break}let r=n&&this.view.docView.nearestDesc(n);if(r&&r.ignoreMutation({type:"selection",target:n.nodeType==3?n.parentNode:n}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let A=this.pendingRecords();A.length&&(this.queue=[]);let n=e.domSelectionRange(),r=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(n)&&hasFocusAndSelection(e)&&!this.ignoreSelectionChange(n),o=-1,s=-1,a=!1,l=[];if(e.editable)for(let c=0;c<A.length;c++){let I=this.registerMutation(A[c],l);I&&(o=o<0?I.from:Math.min(I.from,o),s=s<0?I.to:Math.max(I.to,s),I.typeOver&&(a=!0))}if(gecko&&l.length){let c=l.filter(I=>I.nodeName=="BR");if(c.length==2){let[I,d]=c;I.parentNode&&I.parentNode.parentNode==d.parentNode?d.remove():I.remove()}else{let{focusNode:I}=this.currentSelection;for(let d of c){let h=d.parentNode;h&&h.nodeName=="LI"&&(!I||blockParent(e,I)!=h)&&d.remove()}}}let g=null;o<0&&r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&selectionCollapsed(n)&&(g=selectionFromDOM(e))&&g.eq(Selection.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,selectionToDOM(e),this.currentSelection.set(n),e.scrollToSelection()):(o>-1||r)&&(o>-1&&(e.docView.markDirty(o,s),checkCSS(e)),this.handleDOMChange(o,s,a,l),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(n)||selectionToDOM(e),this.currentSelection.set(n))}registerMutation(e,A){if(A.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(n==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!n||n.ignoreMutation(e))return null;if(e.type=="childList"){for(let c=0;c<e.addedNodes.length;c++){let I=e.addedNodes[c];A.push(I),I.nodeType==3&&(this.lastChangedTextNode=I)}if(n.contentDOM&&n.contentDOM!=n.dom&&!n.contentDOM.contains(e.target))return{from:n.posBefore,to:n.posAfter};let r=e.previousSibling,o=e.nextSibling;if(ie$1&&ie_version<=11&&e.addedNodes.length)for(let c=0;c<e.addedNodes.length;c++){let{previousSibling:I,nextSibling:d}=e.addedNodes[c];(!I||Array.prototype.indexOf.call(e.addedNodes,I)<0)&&(r=I),(!d||Array.prototype.indexOf.call(e.addedNodes,d)<0)&&(o=d)}let s=r&&r.parentNode==e.target?domIndex(r)+1:0,a=n.localPosFromDOM(e.target,s,-1),l=o&&o.parentNode==e.target?domIndex(o):e.target.childNodes.length,g=n.localPosFromDOM(e.target,l,1);return{from:a,to:g}}else return e.type=="attributes"?{from:n.posAtStart-n.border,to:n.posAtEnd+n.border}:(this.lastChangedTextNode=e.target,{from:n.posAtStart,to:n.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}}let cssChecked=new WeakMap,cssCheckWarned=!1;function checkCSS(t){if(!cssChecked.has(t)&&(cssChecked.set(t,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(t.dom).whiteSpace)!==-1)){if(t.requiresGeckoHackNode=gecko,cssCheckWarned)return;console.warn("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package."),cssCheckWarned=!0}}function rangeToSelectionRange(t,e){let A=e.startContainer,n=e.startOffset,r=e.endContainer,o=e.endOffset,s=t.domAtPos(t.state.selection.anchor);return isEquivalentPosition(s.node,s.offset,r,o)&&([A,n,r,o]=[r,o,A,n]),{anchorNode:A,anchorOffset:n,focusNode:r,focusOffset:o}}function safariShadowSelectionRange(t,e){if(e.getComposedRanges){let r=e.getComposedRanges(t.root)[0];if(r)return rangeToSelectionRange(t,r)}let A;function n(r){r.preventDefault(),r.stopImmediatePropagation(),A=r.getTargetRanges()[0]}return t.dom.addEventListener("beforeinput",n,!0),document.execCommand("indent"),t.dom.removeEventListener("beforeinput",n,!0),A?rangeToSelectionRange(t,A):null}function blockParent(t,e){for(let A=e.parentNode;A&&A!=t.dom;A=A.parentNode){let n=t.docView.nearestDesc(A,!0);if(n&&n.node.isBlock)return A}return null}function parseBetween(t,e,A){let{node:n,fromOffset:r,toOffset:o,from:s,to:a}=t.docView.parseRange(e,A),l=t.domSelectionRange(),g,c=l.anchorNode;if(c&&t.dom.contains(c.nodeType==1?c:c.parentNode)&&(g=[{node:c,offset:l.anchorOffset}],selectionCollapsed(l)||g.push({node:l.focusNode,offset:l.focusOffset})),chrome&&t.input.lastKeyCode===8)for(let E=o;E>r;E--){let f=n.childNodes[E-1],Q=f.pmViewDesc;if(f.nodeName=="BR"&&!Q){o=E;break}if(!Q||Q.size)break}let I=t.state.doc,d=t.someProp("domParser")||DOMParser$1.fromSchema(t.state.schema),h=I.resolve(s),u=null,B=d.parse(n,{topNode:h.parent,topMatch:h.parent.contentMatchAt(h.index()),topOpen:!0,from:r,to:o,preserveWhitespace:h.parent.type.whitespace=="pre"?"full":!0,findPositions:g,ruleFromNode,context:h});if(g&&g[0].pos!=null){let E=g[0].pos,f=g[1]&&g[1].pos;f==null&&(f=E),u={anchor:E+s,head:f+s}}return{doc:B,sel:u,from:s,to:a}}function ruleFromNode(t){let e=t.pmViewDesc;if(e)return e.parseRule();if(t.nodeName=="BR"&&t.parentNode){if(safari&&/^(ul|ol)$/i.test(t.parentNode.nodeName)){let A=document.createElement("div");return A.appendChild(document.createElement("li")),{skip:A}}else if(t.parentNode.lastChild==t||safari&&/^(tr|table)$/i.test(t.parentNode.nodeName))return{ignore:!0}}else if(t.nodeName=="IMG"&&t.getAttribute("mark-placeholder"))return{ignore:!0};return null}const isInline=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function readDOMChange(t,e,A,n,r){let o=t.input.compositionPendingChanges||(t.composing?t.input.compositionID:0);if(t.input.compositionPendingChanges=0,e<0){let _=t.input.lastSelectionTime>Date.now()-50?t.input.lastSelectionOrigin:null,k=selectionFromDOM(t,_);if(k&&!t.state.selection.eq(k)){if(chrome&&android&&t.input.lastKeyCode===13&&Date.now()-100<t.input.lastKeyCodeTime&&t.someProp("handleKeyDown",F=>F(t,keyEvent(13,"Enter"))))return;let S=t.state.tr.setSelection(k);_=="pointer"?S.setMeta("pointer",!0):_=="key"&&S.scrollIntoView(),o&&S.setMeta("composition",o),t.dispatch(S)}return}let s=t.state.doc.resolve(e),a=s.sharedDepth(A);e=s.before(a+1),A=t.state.doc.resolve(A).after(a+1);let l=t.state.selection,g=parseBetween(t,e,A),c=t.state.doc,I=c.slice(g.from,g.to),d,h;t.input.lastKeyCode===8&&Date.now()-100<t.input.lastKeyCodeTime?(d=t.state.selection.to,h="end"):(d=t.state.selection.from,h="start"),t.input.lastKeyCode=null;let u=findDiff(I.content,g.doc.content,g.from,d,h);if(u&&t.input.domChangeCount++,(ios&&t.input.lastIOSEnter>Date.now()-225||android)&&r.some(_=>_.nodeType==1&&!isInline.test(_.nodeName))&&(!u||u.endA>=u.endB)&&t.someProp("handleKeyDown",_=>_(t,keyEvent(13,"Enter")))){t.input.lastIOSEnter=0;return}if(!u)if(n&&l instanceof TextSelection&&!l.empty&&l.$head.sameParent(l.$anchor)&&!t.composing&&!(g.sel&&g.sel.anchor!=g.sel.head))u={start:l.from,endA:l.to,endB:l.to};else{if(g.sel){let _=resolveSelection(t,t.state.doc,g.sel);if(_&&!_.eq(t.state.selection)){let k=t.state.tr.setSelection(_);o&&k.setMeta("composition",o),t.dispatch(k)}}return}t.state.selection.from<t.state.selection.to&&u.start==u.endB&&t.state.selection instanceof TextSelection&&(u.start>t.state.selection.from&&u.start<=t.state.selection.from+2&&t.state.selection.from>=g.from?u.start=t.state.selection.from:u.endA<t.state.selection.to&&u.endA>=t.state.selection.to-2&&t.state.selection.to<=g.to&&(u.endB+=t.state.selection.to-u.endA,u.endA=t.state.selection.to)),ie$1&&ie_version<=11&&u.endB==u.start+1&&u.endA==u.start&&u.start>g.from&&g.doc.textBetween(u.start-g.from-1,u.start-g.from+1)==" "&&(u.start--,u.endA--,u.endB--);let B=g.doc.resolveNoCache(u.start-g.from),E=g.doc.resolveNoCache(u.endB-g.from),f=c.resolve(u.start),Q=B.sameParent(E)&&B.parent.inlineContent&&f.end()>=u.endA,p;if((ios&&t.input.lastIOSEnter>Date.now()-225&&(!Q||r.some(_=>_.nodeName=="DIV"||_.nodeName=="P"))||!Q&&B.pos<g.doc.content.size&&(!B.sameParent(E)||!B.parent.inlineContent)&&!/\S/.test(g.doc.textBetween(B.pos,E.pos,"",""))&&(p=Selection.findFrom(g.doc.resolve(B.pos+1),1,!0))&&p.head>B.pos)&&t.someProp("handleKeyDown",_=>_(t,keyEvent(13,"Enter")))){t.input.lastIOSEnter=0;return}if(t.state.selection.anchor>u.start&&looksLikeBackspace(c,u.start,u.endA,B,E)&&t.someProp("handleKeyDown",_=>_(t,keyEvent(8,"Backspace")))){android&&chrome&&t.domObserver.suppressSelectionUpdates();return}chrome&&u.endB==u.start&&(t.input.lastChromeDelete=Date.now()),android&&!Q&&B.start()!=E.start()&&E.parentOffset==0&&B.depth==E.depth&&g.sel&&g.sel.anchor==g.sel.head&&g.sel.head==u.endA&&(u.endB-=2,E=g.doc.resolveNoCache(u.endB-g.from),setTimeout(()=>{t.someProp("handleKeyDown",function(_){return _(t,keyEvent(13,"Enter"))})},20));let m=u.start,y=u.endA,w=_=>{let k=_||t.state.tr.replace(m,y,g.doc.slice(u.start-g.from,u.endB-g.from));if(g.sel){let S=resolveSelection(t,k.doc,g.sel);S&&!(chrome&&t.composing&&S.empty&&(u.start!=u.endB||t.input.lastChromeDelete<Date.now()-100)&&(S.head==m||S.head==k.mapping.map(y)-1)||ie$1&&S.empty&&S.head==m)&&k.setSelection(S)}return o&&k.setMeta("composition",o),k.scrollIntoView()},D;if(Q){if(B.pos==E.pos){ie$1&&ie_version<=11&&B.parentOffset==0&&(t.domObserver.suppressSelectionUpdates(),setTimeout(()=>selectionToDOM(t),20));let _=w(t.state.tr.delete(m,y)),k=c.resolve(u.start).marksAcross(c.resolve(u.endA));k&&_.ensureMarks(k),t.dispatch(_)}else if(u.endA==u.endB&&(D=isMarkChange(B.parent.content.cut(B.parentOffset,E.parentOffset),f.parent.content.cut(f.parentOffset,u.endA-f.start())))){let _=w(t.state.tr);D.type=="add"?_.addMark(m,y,D.mark):_.removeMark(m,y,D.mark),t.dispatch(_)}else if(B.parent.child(B.index()).isText&&B.index()==E.index()-(E.textOffset?0:1)){let _=B.parent.textBetween(B.parentOffset,E.parentOffset),k=()=>w(t.state.tr.insertText(_,m,y));t.someProp("handleTextInput",S=>S(t,m,y,_,k))||t.dispatch(k())}}else t.dispatch(w())}function resolveSelection(t,e,A){return Math.max(A.anchor,A.head)>e.content.size?null:selectionBetween(t,e.resolve(A.anchor),e.resolve(A.head))}function isMarkChange(t,e){let A=t.firstChild.marks,n=e.firstChild.marks,r=A,o=n,s,a,l;for(let c=0;c<n.length;c++)r=n[c].removeFromSet(r);for(let c=0;c<A.length;c++)o=A[c].removeFromSet(o);if(r.length==1&&o.length==0)a=r[0],s="add",l=c=>c.mark(a.addToSet(c.marks));else if(r.length==0&&o.length==1)a=o[0],s="remove",l=c=>c.mark(a.removeFromSet(c.marks));else return null;let g=[];for(let c=0;c<e.childCount;c++)g.push(l(e.child(c)));if(Fragment.from(g).eq(t))return{mark:a,type:s}}function looksLikeBackspace(t,e,A,n,r){if(A-e<=r.pos-n.pos||skipClosingAndOpening(n,!0,!1)<r.pos)return!1;let o=t.resolve(e);if(!n.parent.isTextblock){let a=o.nodeAfter;return a!=null&&A==e+a.nodeSize}if(o.parentOffset<o.parent.content.size||!o.parent.isTextblock)return!1;let s=t.resolve(skipClosingAndOpening(o,!0,!0));return!s.parent.isTextblock||s.pos>A||skipClosingAndOpening(s,!0,!1)<A?!1:n.parent.content.cut(n.parentOffset).eq(s.parent.content)}function skipClosingAndOpening(t,e,A){let n=t.depth,r=e?t.end():t.pos;for(;n>0&&(e||t.indexAfter(n)==t.node(n).childCount);)n--,r++,e=!1;if(A){let o=t.node(n).maybeChild(t.indexAfter(n));for(;o&&!o.isLeaf;)o=o.firstChild,r++}return r}function findDiff(t,e,A,n,r){let o=t.findDiffStart(e,A);if(o==null)return null;let{a:s,b:a}=t.findDiffEnd(e,A+t.size,A+e.size);if(r=="end"){let l=Math.max(0,o-Math.min(s,a));n-=s+l-o}if(s<o&&t.size<e.size){let l=n<=o&&n>=s?o-n:0;o-=l,o&&o<e.size&&isSurrogatePair(e.textBetween(o-1,o+1))&&(o+=l?1:-1),a=o+(a-s),s=o}else if(a<o){let l=n<=o&&n>=a?o-n:0;o-=l,o&&o<t.size&&isSurrogatePair(t.textBetween(o-1,o+1))&&(o+=l?1:-1),s=o+(s-a),a=o}return{start:o,endA:s,endB:a}}function isSurrogatePair(t){if(t.length!=2)return!1;let e=t.charCodeAt(0),A=t.charCodeAt(1);return e>=56320&&e<=57343&&A>=55296&&A<=56319}class EditorView{constructor(e,A){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new InputState,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=A,this.state=A.state,this.directPlugins=A.plugins||[],this.directPlugins.forEach(checkStateComponent$1),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):typeof e=="function"?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=getEditable$1(this),updateCursorWrapper(this),this.nodeViews=buildNodeViews$1(this),this.docView=docViewDesc(this.state.doc,computeDocDeco(this),viewDecorations(this),this.dom,this),this.domObserver=new DOMObserver(this,(n,r,o,s)=>readDOMChange(this,n,r,o,s)),this.domObserver.start(),initInput(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let A in e)this._props[A]=e[A];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&ensureListeners(this);let A=this._props;this._props=e,e.plugins&&(e.plugins.forEach(checkStateComponent$1),this.directPlugins=e.plugins),this.updateStateInner(e.state,A)}setProps(e){let A={};for(let n in this._props)A[n]=this._props[n];A.state=this.state;for(let n in e)A[n]=e[n];this.update(A)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,A){var n;let r=this.state,o=!1,s=!1;e.storedMarks&&this.composing&&(clearComposition(this),s=!0),this.state=e;let a=r.plugins!=e.plugins||this._props.plugins!=A.plugins;if(a||this._props.plugins!=A.plugins||this._props.nodeViews!=A.nodeViews){let h=buildNodeViews$1(this);changedNodeViews$1(h,this.nodeViews)&&(this.nodeViews=h,o=!0)}(a||A.handleDOMEvents!=this._props.handleDOMEvents)&&ensureListeners(this),this.editable=getEditable$1(this),updateCursorWrapper(this);let l=viewDecorations(this),g=computeDocDeco(this),c=r.plugins!=e.plugins&&!r.doc.eq(e.doc)?"reset":e.scrollToSelection>r.scrollToSelection?"to selection":"preserve",I=o||!this.docView.matchesNode(e.doc,g,l);(I||!e.selection.eq(r.selection))&&(s=!0);let d=c=="preserve"&&s&&this.dom.style.overflowAnchor==null&&storeScrollPos(this);if(s){this.domObserver.stop();let h=I&&(ie$1||chrome)&&!this.composing&&!r.selection.empty&&!e.selection.empty&&selectionContextChanged(r.selection,e.selection);if(I){let u=chrome?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=findCompositionNode(this)),(o||!this.docView.update(e.doc,g,l,this))&&(this.docView.updateOuterDeco(g),this.docView.destroy(),this.docView=docViewDesc(e.doc,g,l,this.dom,this)),u&&!this.trackWrites&&(h=!0)}h||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&anchorInRightPlace(this))?selectionToDOM(this,h):(syncNodeSelection(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(r),!((n=this.dragging)===null||n===void 0)&&n.node&&!r.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,r),c=="reset"?this.dom.scrollTop=0:c=="to selection"?this.scrollToSelection():d&&resetScrollPos(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))){if(!this.someProp("handleScrollToSelection",A=>A(this)))if(this.state.selection instanceof NodeSelection){let A=this.docView.domAfterPos(this.state.selection.from);A.nodeType==1&&scrollRectIntoView(this,A.getBoundingClientRect(),e)}else scrollRectIntoView(this,this.coordsAtPos(this.state.selection.head,1),e)}}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let A=0;A<this.directPlugins.length;A++){let n=this.directPlugins[A];n.spec.view&&this.pluginViews.push(n.spec.view(this))}for(let A=0;A<this.state.plugins.length;A++){let n=this.state.plugins[A];n.spec.view&&this.pluginViews.push(n.spec.view(this))}}else for(let A=0;A<this.pluginViews.length;A++){let n=this.pluginViews[A];n.update&&n.update(this,e)}}updateDraggedNode(e,A){let n=e.node,r=-1;if(this.state.doc.nodeAt(n.from)==n.node)r=n.from;else{let o=n.from+(this.state.doc.content.size-A.doc.content.size);(o>0&&this.state.doc.nodeAt(o))==n.node&&(r=o)}this.dragging=new Dragging(e.slice,e.move,r<0?void 0:NodeSelection.create(this.state.doc,r))}someProp(e,A){let n=this._props&&this._props[e],r;if(n!=null&&(r=A?A(n):n))return r;for(let s=0;s<this.directPlugins.length;s++){let a=this.directPlugins[s].props[e];if(a!=null&&(r=A?A(a):a))return r}let o=this.state.plugins;if(o)for(let s=0;s<o.length;s++){let a=o[s].props[e];if(a!=null&&(r=A?A(a):a))return r}}hasFocus(){if(ie$1){let e=this.root.activeElement;if(e==this.dom)return!0;if(!e||!this.dom.contains(e))return!1;for(;e&&this.dom!=e&&this.dom.contains(e);){if(e.contentEditable=="false")return!1;e=e.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&focusPreventScroll(this.dom),selectionToDOM(this),this.domObserver.start()}get root(){let e=this._root;if(e==null){for(let A=this.dom.parentNode;A;A=A.parentNode)if(A.nodeType==9||A.nodeType==11&&A.host)return A.getSelection||(Object.getPrototypeOf(A).getSelection=()=>A.ownerDocument.getSelection()),this._root=A}return e||document}updateRoot(){this._root=null}posAtCoords(e){return posAtCoords(this,e)}coordsAtPos(e,A=1){return coordsAtPos(this,e,A)}domAtPos(e,A=0){return this.docView.domFromPos(e,A)}nodeDOM(e){let A=this.docView.descAt(e);return A?A.nodeDOM:null}posAtDOM(e,A,n=-1){let r=this.docView.posFromDOM(e,A,n);if(r==null)throw new RangeError("DOM position not inside the editor");return r}endOfTextblock(e,A){return endOfTextblock(this,A||this.state,e)}pasteHTML(e,A){return doPaste(this,"",e,!1,A||new ClipboardEvent("paste"))}pasteText(e,A){return doPaste(this,e,null,!0,A||new ClipboardEvent("paste"))}serializeForClipboard(e){return serializeForClipboard(this,e)}destroy(){this.docView&&(destroyInput(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],viewDecorations(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,clearReusedRange())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return dispatchEvent(this,e)}domSelectionRange(){let e=this.domSelection();return e?safari&&this.root.nodeType===11&&deepActiveElement(this.dom.ownerDocument)==this.dom&&safariShadowSelectionRange(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}EditorView.prototype.dispatch=function(t){let e=this._props.dispatchTransaction;e?e.call(this,t):this.updateState(this.state.apply(t))};function computeDocDeco(t){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(t.editable),t.someProp("attributes",A=>{if(typeof A=="function"&&(A=A(t.state)),A)for(let n in A)n=="class"?e.class+=" "+A[n]:n=="style"?e.style=(e.style?e.style+";":"")+A[n]:!e[n]&&n!="contenteditable"&&n!="nodeName"&&(e[n]=String(A[n]))}),e.translate||(e.translate="no"),[Decoration.node(0,t.state.doc.content.size,e)]}function updateCursorWrapper(t){if(t.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),t.cursorWrapper={dom:e,deco:Decoration.widget(t.state.selection.from,e,{raw:!0,marks:t.markCursor})}}else t.cursorWrapper=null}function getEditable$1(t){return!t.someProp("editable",e=>e(t.state)===!1)}function selectionContextChanged(t,e){let A=Math.min(t.$anchor.sharedDepth(t.head),e.$anchor.sharedDepth(e.head));return t.$anchor.start(A)!=e.$anchor.start(A)}function buildNodeViews$1(t){let e=Object.create(null);function A(n){for(let r in n)Object.prototype.hasOwnProperty.call(e,r)||(e[r]=n[r])}return t.someProp("nodeViews",A),t.someProp("markViews",A),e}function changedNodeViews$1(t,e){let A=0,n=0;for(let r in t){if(t[r]!=e[r])return!0;A++}for(let r in e)n++;return A!=n}function checkStateComponent$1(t){if(t.spec.state||t.spec.filterTransaction||t.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}const MAX_MATCH=500;class InputRule{constructor(e,A,n={}){this.regex=e,this.regex=e,this.handler=typeof A=="string"?stringHandler(A):A,this.undoable=n.undoable!==!1,this.inCode=n.inCode||!1}}function stringHandler(t){return function(e,A,n,r,o){e||(e=A.tr);let s=t;if(n[1]){const a=n[0].lastIndexOf(n[1]);s+=n[0].slice(a+n[1].length),r+=a;const l=r-o;l>0&&(s=n[0].slice(a-l,a)+s,r=o)}return e.insertText(s,r,o)}}class InputRulesPlugin extends Plugin{constructor(e){super({key:new PluginKey("input-rules"),state:{init(){return null},apply(A,n){const r=A.getMeta(this);return r||(A.selectionSet||A.docChanged?null:n)}},props:{handleTextInput(A,n,r,o){const s=runInputRulesRange(n,r,o),a=l=>{A.dispatch(l)};return s(A.state,a,A)},handleDOMEvents:{compositionend:A=>{setTimeout(()=>{const{$cursor:n}=A.state.selection;if(n){const r=runInputRulesRange(n.pos,n.pos,""),o=s=>{A.dispatch(s)};return r(A.state,o,A)}})}}},rules:e,isInputRules:!0})}}const runInputRulesTexts=()=>{const t=(e,A,n)=>{const o=e.plugins.find(g=>g.spec.isInputRules);if(!o)return!1;const s=o.spec.rules;if(n?.composing)return!1;let a=e.doc,l=e.tr;for(let g=0;g<s.length;g++){const c=s[g],I=[];if(a.descendants((d,h)=>{d.isText&&I.push({pos:h,node:d})}),I.length===0)return!1;for(let d=I.length-1;d>=0;d--){const{pos:h,node:u}=I[d];if(!u.isText||!u.text)continue;let B=u.text;if(u.type.spec.code){if(!c.inCode)continue}else if(c.inCode==="only")continue;const E=c.regex.exec(B);if(!E)continue;const f=E.index,Q=h+f,p=h+f+E[0].length;let m=c.handler(l,e,E,Q,p);m&&(l=m,a=l.doc,c.undoable&&l.setMeta(o,{transform:l,from:Q,to:p,text:B}))}}return A&&A(l),l.docChanged};return t.displayName="runInputRulesTexts",t},runInputRulesRange=(t,e,A)=>{const n=(r,o,s)=>{const l=r.plugins.find(h=>h.spec.isInputRules);if(!l)return!1;const g=l.spec.rules;if(s?.composing)return!1;const c=r.doc.resolve(t),I=c.parent.textBetween(Math.max(0,c.parentOffset-MAX_MATCH),c.parentOffset,null,"")+A;let d=r.tr;for(let h=0;h<g.length;h++){const u=g[h];if(c.parent.type.spec.code){if(!u.inCode)continue}else if(u.inCode==="only")continue;const B=u.regex.exec(I);if(!B)continue;const E=u.handler(d,r,B,d.mapping.map(t-(B[0].length-A.length)),d.mapping.map(e));if(E){d=E,u.undoable&&d.setMeta(l,{transform:d,from:t,to:e,text:A});break}}return d.docChanged?(o?.(d),!0):!1};return n.displayName="runInputRulesRange",n},undoInputRuleCommand=(t,e)=>{const n=t.plugins.find(o=>o.spec.isInputRules);if(!n)return!1;const r=n.getState(t);if(!r)return!1;if(e){const o=t.tr,s=r.transform;for(let a=s.steps.length-1;a>=0;a--)o.step(s.steps[a].invert(s.docs[a]));if(r.text){const a=o.doc.resolve(r.from).marks();o.replaceWith(r.from,r.to,t.schema.text(r.text,a))}else o.delete(r.from,r.to);e(o)}return!0},base={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},shift={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},mac$2=typeof navigator<"u"&&/Mac/.test(navigator.platform),ie=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(let t=0;t<10;t++)base[48+t]=base[96+t]=String(t);for(let t=1;t<=24;t++)base[t+111]="F"+t;for(let t=65;t<=90;t++)base[t]=String.fromCharCode(t+32),shift[t]=String.fromCharCode(t);for(const t in base)Object.prototype.hasOwnProperty.call(shift,t)||(shift[t]=base[t]);function keyName(t){let A=!(mac$2&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||ie&&t.shiftKey&&t.key&&t.key.length==1||t.key=="Unidentified")&&t.key||(t.shiftKey?shift:base)[t.keyCode]||t.key||"Unidentified";return A=="Esc"&&(A="Escape"),A=="Del"&&(A="Delete"),A=="Left"&&(A="ArrowLeft"),A=="Up"&&(A="ArrowUp"),A=="Right"&&(A="ArrowRight"),A=="Down"&&(A="ArrowDown"),A}const mac$1=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator?.platform),windows=typeof navigator<"u"&&/Win/.test(navigator?.platform);function normalizeKeyName(t){let e=t.split(/-(?!$)/),A=e[e.length-1];A=="Space"&&(A=" ");let n,r,o,s;for(let a=0;a<e.length-1;a++){let l=e[a];if(/^(cmd|meta|m)$/i.test(l))s=!0;else if(/^a(lt)?$/i.test(l))n=!0;else if(/^(c|ctrl|control)$/i.test(l))r=!0;else if(/^s(hift)?$/i.test(l))o=!0;else if(/^mod$/i.test(l))mac$1?s=!0:r=!0;else throw new Error("Unrecognized modifier name: "+l)}return n&&(A="Alt-"+A),r&&(A="Ctrl-"+A),s&&(A="Meta-"+A),o&&(A="Shift-"+A),A}function normalize(t){let e=Object.create(null);for(let A in t)e[normalizeKeyName(A)]=t[A];return e}function modifiers(t,e,A=!0){return e.altKey&&(t="Alt-"+t),e.ctrlKey&&(t="Ctrl-"+t),e.metaKey&&(t="Meta-"+t),A&&e.shiftKey&&(t="Shift-"+t),t}class KeymapPlugin extends Plugin{constructor(e){super({key:new PluginKey("keymap"),props:{handleKeyDown:keydownHandler(e)}})}}function keydownHandler(t){let e=normalize(t);return function(A,n){let r=keyName(n),o,s=e[modifiers(r,n)];if(s&&s(A.state,A.dispatch,A))return!0;if(r.length==1&&r!=" "){if(n.shiftKey){let a=e[modifiers(r,n,!1)];if(a&&a(A.state,A.dispatch,A))return!0}if((n.altKey||n.metaKey||n.ctrlKey)&&!(windows&&n.ctrlKey&&n.altKey)&&(o=base[n.keyCode])&&o!=r){let a=e[modifiers(o,n)];if(a&&a(A.state,A.dispatch,A))return!0}}return!1}}function firstCommand$1(...t){const e=function(A,n,r){for(let o=0;o<t.length;o++)if(t[o](A,n,r))return t[o].displayName!=="first"&&console.debug("firstCommand: ",t[o].displayName||t[o]),!0;return!1};return e.displayName="first",e}function getHtmlAttributes(t,e){const A={};if(t.attributes)for(const[n,r]of Object.entries(t.attributes))typeof e.attrs[n]<"u"?A[n]=e.attrs[n]:r.toDom?A[n]=r.toDom(e):A[n]=r.default;return A}function setHtmlAttributes(t,e){const A={};if(t.attributes)for(const[n,r]of Object.entries(t.attributes))r.fromDom?A[n]=r.fromDom(e):A[n]=r.default;return A}function addAttributesToSchema(t,e){if(e.attributes){t.attrs||(t.attrs={});for(const[A,n]of Object.entries(e.attributes))t.attrs[A]=n,n.toDom||(n.toDom=r=>r.attrs[A])}}class TrackSelecionPlugin extends Plugin{constructor(e){super({key:new PluginKey("track-selection"),view(A){return{update(n,r){const o=n.state,s=r.selection,a=o.selection;if(!s.eq(a)){const l=new CustomEvent("selection",{detail:{selection:a}});e.dispatchEvent(l)}}}}})}}function splitExtensions(t){const e=Array.from(t).filter(r=>r.type==="extension"),A=Array.from(t).filter(r=>r.type==="node"),n=Array.from(t).filter(r=>r.type==="mark");return{baseExtensions:e,nodeExtensions:A,markExtensions:n}}class ExtensionManager{constructor(e,A=!1){this.editorKits=e,this.debug=A,this.extensions=new Set,this.plugins=[],this.nodeViews={},this.converters={};const n=e.reduce((r,o)=>r.concat(o.getExtensions()),[]);this.setupExtensions(new Set(n))}getExtension(e){const{baseExtensions:A}=splitExtensions(this.extensions);for(const n of A)if(n.name===e)return n}initPlugins(e,A){const n=[],r=new Map,o=(a,l)=>{for(const g in a){if(!a[g])continue;const c=e.commandFactories[a[g]];if(!c){console.warn(`No command constructor: ${a[g]}`);continue}const I=c(),d=r.get(g);d?r.set(g,firstCommand$1(I,d)):r.set(g,I)}};let s={};for(const a of this.extensions){if(a.setEditor(e),a.type==="node"){const l=A.nodes[a.name];n.push(...a.getInputRules(l)),this.plugins.push(...a.getProseMirrorPlugins()),e.mergeCommandFactories(a.getCommandFactories(e,l),a.name),o(a.getKeyboardShortcuts(e),a.name),s={...s,...a.getConverters(e,A)};const g=a.getNodeView(e);g&&(this.nodeViews[a.name]=g)}if(a.type==="mark"){const l=A.marks[a.name];n.push(...a.getInputRules(l)),e.mergeCommandFactories(a.getCommandFactories(e,l),a.name),o(a.getKeyboardShortcuts(e),a.name)}a.type==="extension"&&(this.plugins.push(...a.getProseMirrorPlugins()),e.mergeCommandFactories(a.getCommandFactories(e),a.name),o(a.getKeyboardShortcuts(e),a.name),s={...s,...a.getConverters(e,A)})}if(this.debug)for(const a in r){const l=r.get(a);if(!l)continue;const g=(c,I,d)=>(console.debug(`Key: ${a}`),!0);r.set(a,firstCommand$1(g,l))}this.converters=s,this.plugins.push(new InputRulesPlugin(n)),this.plugins.push(new KeymapPlugin(Object.fromEntries(r))),this.plugins.push(new TrackSelecionPlugin(e))}setupExtensions(e){const A=new Map,n=a=>{for(const l of a){if("name"in l){const g=A.get(l.name);if(g&&"type"in g&&l.type!==g.type)throw new Error(`Duplicate mark/node: ${l.name}`);A.set(l.name,l)}if("requires"in l){const g=Array.from(l.requires).filter(c=>typeof c!="string");n(new Set(g))}}};n(e);const r=new Set,o=a=>{this.debug&&console.info(`Initialize ${a.type} ${a.name}`),this.extensions.add(a)};function s(a){if(!("name"in a&&r.has(a.name))){if("requires"in a){const g=(a.requires||[]).map(c=>typeof c=="string"?c:"name"in c?c.name:"");for(const c of g)if(!r.has(c)){const I=A.get(c);if(!I)throw new Error(`Required extension for (${"name"in a?a.name:a}) not found: ${c}`);s(I)}}"name"in a&&(o(a),r.add(a.name),A.delete(a.name))}}for(const a of A.values())s(a);if(A.size>0)throw new Error("Not all extensions initialized: "+Array.from(A.keys()).join(", "))}getSchemaByResolvedExtensions(){const{nodeExtensions:e,markExtensions:A,baseExtensions:n}=splitExtensions(this.extensions),r={};let o="";for(const l of e){if(r[l.name]=l.getNodeSpec(),r[l.name].EMPTY_DOC){if(o)throw new Error(`Multiple topNodes: ${l.name}, ${o}`);o=l.name}addAttributesToSchema(r[l.name],l)}const s={};for(const l of A)s[l.name]=l.getMarkSpec(),addAttributesToSchema(s[l.name],l);const a={topNode:o||"doc",nodes:r,marks:s};for(const l of n)"setupSpec"in n&&l.setupSpec(a);return new Schema(a)}created(e,A){const{baseExtensions:n}=splitExtensions(this.extensions);for(const r of n)if(Array.isArray(r.conflicts)){for(const o of r.conflicts)if(this.getExtension(o))throw new Error(`Extension conflict: ${r.name} vs ${o}`)}this.initPlugins(e,A);for(const r of this.extensions)r.created()}}function createChainableState(t,e){let{selection:A}=t,{doc:n}=t,{storedMarks:r}=t;return{...e,apply:e.apply.bind(e),applyTransaction:e.applyTransaction.bind(e),plugins:e.plugins,schema:e.schema,reconfigure:e.reconfigure.bind(e),toJSON:e.toJSON.bind(e),get storedMarks(){return r},get selection(){return A},get doc(){return n},get tr(){return A=t.selection,n=t.doc,r=t.storedMarks,t}}}const wrapInList=(t,e=null)=>function(A,n,r){let{$from:o,$to:s}=A.selection,a=o.blockRange(s);if(!a)return!1;let l=n?A.tr:null;return wrapRangeInList(l,a,t,e).apply(this,[A,n])?(n&&n(l.scrollIntoView()),!0):!1},wrapRangeInList=(t,e,A,n=null)=>()=>{let o=!1,s=e,a=e.$from.doc;if(e.depth>=2&&e.$from.node(e.depth-1).type.compatibleContent(A)&&e.startIndex==0){if(e.$from.index(e.depth-1)==0)return!1;let g=a.resolve(e.start-2);s=new NodeRange(g,g,e.depth),e.endIndex<e.parent.childCount&&(e=new NodeRange(e.$from,a.resolve(e.$to.end(e.depth)),e.depth)),o=!0}let l=findWrapping(s,A,n,e);return l?(t&&doWrapInList(t,e,l,o,A),!0):!1};function doWrapInList(t,e,A,n,r){let o=Fragment.empty;for(let c=A.length-1;c>=0;c--)o=Fragment.from(A[c].type.create(A[c].attrs,o));t.step(new ReplaceAroundStep(e.start-(n?2:0),e.end,e.start,e.end,new Slice(o,0,0),A.length,!0));let s=0;for(let c=0;c<A.length;c++)A[c].type==r&&(s=c+1);let a=A.length-s,l=e.start+A.length-(n?2:0),g=e.parent;for(let c=e.startIndex,I=e.endIndex,d=!0;c<I;c++,d=!1)!d&&canSplit(t.doc,l,a)&&(t.split(l,a),l+=2*a),l+=g.child(c).nodeSize;return t}const deleteSelection=()=>(t,e)=>t.selection.empty?!1:(e&&e(t.tr.deleteSelection().scrollIntoView()),!0);function atBlockStart(t,e){let{$cursor:A}=t.selection;return!A||(e?!e.endOfTextblock("backward",t):A.parentOffset>0)?null:A}const joinBackward=()=>(t,e,A)=>{let n=atBlockStart(t,A);if(!n)return!1;let r=findCutBefore(n);if(!r){let s=n.blockRange(),a=s&&liftTarget(s);return a==null?!1:(e&&e(t.tr.lift(s,a).scrollIntoView()),!0)}let o=r.nodeBefore;if(deleteBarrier(t,r,e,-1))return!0;if(n.parent.content.size==0&&(textblockAt(o,"end")||NodeSelection.isSelectable(o)))for(let s=n.depth;;s--){let a=replaceStep(t.doc,n.before(s),n.after(s),Slice.empty);if(a&&a.slice.size<a.to-a.from){if(e){let l=t.tr.step(a);l.setSelection(textblockAt(o,"end")?Selection.findFrom(l.doc.resolve(l.mapping.map(r.pos,-1)),-1):NodeSelection.create(l.doc,r.pos-o.nodeSize)),e(l.scrollIntoView())}return!0}if(s==1||n.node(s-1).childCount>1)break}return o.isAtom&&r.depth==n.depth-1?(e&&e(t.tr.delete(r.pos-o.nodeSize,r.pos).scrollIntoView()),!0):!1},joinTextblockBackward=()=>(t,e,A)=>{let n=atBlockStart(t,A);if(!n)return!1;let r=findCutBefore(n);return r?joinTextblocksAround(t,r,e):!1},joinTextblockForward=()=>(t,e,A)=>{let n=atBlockEnd(t,A);if(!n)return!1;let r=findCutAfter(n);return r?joinTextblocksAround(t,r,e):!1};function joinTextblocksAround(t,e,A){let n=e.nodeBefore,r=n,o=e.pos-1;for(;!r.isTextblock;o--){if(r.type.spec.isolating)return!1;let c=r.lastChild;if(!c)return!1;r=c}let s=e.nodeAfter,a=s,l=e.pos+1;for(;!a.isTextblock;l++){if(a.type.spec.isolating)return!1;let c=a.firstChild;if(!c)return!1;a=c}let g=replaceStep(t.doc,o,l,Slice.empty);if(!g||g.from!=o||g instanceof ReplaceStep&&g.slice.size>=l-o)return!1;if(A){let c=t.tr.step(g);c.setSelection(TextSelection.create(c.doc,o)),A(c.scrollIntoView())}return!0}function textblockAt(t,e,A=!1){for(let n=t;n;n=e=="start"?n.firstChild:n.lastChild){if(n.isTextblock)return!0;if(A&&n.childCount!=1)return!1}return!1}const selectNodeBackward=()=>(t,e,A)=>{let{$head:n,empty:r}=t.selection,o=n;if(!r)return!1;if(n.parent.isTextblock){if(A?!A.endOfTextblock("backward",t):n.parentOffset>0)return!1;o=findCutBefore(n)}let s=o&&o.nodeBefore;return!s||!NodeSelection.isSelectable(s)?!1:(e&&e(t.tr.setSelection(NodeSelection.create(t.doc,o.pos-s.nodeSize)).scrollIntoView()),!0)};function findCutBefore(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){if(t.index(e)>0)return t.doc.resolve(t.before(e+1));if(t.node(e).type.spec.isolating)break}return null}function atBlockEnd(t,e){let{$cursor:A}=t.selection;return!A||(e?!e.endOfTextblock("forward",t):A.parentOffset<A.parent.content.size)?null:A}const joinForward=()=>(t,e,A)=>{let n=atBlockEnd(t,A);if(!n)return!1;let r=findCutAfter(n);if(!r)return!1;let o=r.nodeAfter;if(deleteBarrier(t,r,e,1))return!0;if(n.parent.content.size==0&&(textblockAt(o,"start")||NodeSelection.isSelectable(o))){let s=replaceStep(t.doc,n.before(),n.after(),Slice.empty);if(s&&s.slice.size<s.to-s.from){if(e){let a=t.tr.step(s);a.setSelection(textblockAt(o,"start")?Selection.findFrom(a.doc.resolve(a.mapping.map(r.pos)),1):NodeSelection.create(a.doc,a.mapping.map(r.pos))),e(a.scrollIntoView())}return!0}}return o.isAtom&&r.depth==n.depth-1?(e&&e(t.tr.delete(r.pos,r.pos+o.nodeSize).scrollIntoView()),!0):!1},selectNodeForward=()=>(t,e,A)=>{let{$head:n,empty:r}=t.selection,o=n;if(!r)return!1;if(n.parent.isTextblock){if(A?!A.endOfTextblock("forward",t):n.parentOffset<n.parent.content.size)return!1;o=findCutAfter(n)}let s=o&&o.nodeAfter;return!s||!NodeSelection.isSelectable(s)?!1:(e&&e(t.tr.setSelection(NodeSelection.create(t.doc,o.pos)).scrollIntoView()),!0)};function findCutAfter(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){let A=t.node(e);if(t.index(e)+1<A.childCount)return t.doc.resolve(t.after(e+1));if(A.type.spec.isolating)break}return null}const joinUp=()=>(t,e)=>{let A=t.selection,n=A instanceof NodeSelection,r;if(n){if(A.node.isTextblock||!canJoin(t.doc,A.from))return!1;r=A.from}else if(r=joinPoint(t.doc,A.from,-1),r==null)return!1;if(e){let o=t.tr.join(r);n&&o.setSelection(NodeSelection.create(o.doc,r-t.doc.resolve(r).nodeBefore.nodeSize)),e(o.scrollIntoView())}return!0},joinDown=()=>(t,e)=>{let A=t.selection,n;if(A instanceof NodeSelection){if(A.node.isTextblock||!canJoin(t.doc,A.to))return!1;n=A.to}else if(n=joinPoint(t.doc,A.to,1),n==null)return!1;return e&&e(t.tr.join(n).scrollIntoView()),!0},lift=()=>(t,e)=>{let{$from:A,$to:n}=t.selection,r=A.blockRange(n),o=r&&liftTarget(r);return o==null?!1:(e&&e(t.tr.lift(r,o).scrollIntoView()),!0)},newlineInCode=()=>{const t=(e,A)=>{let{$head:n,$anchor:r}=e.selection;return!n.parent.type.spec.code||!n.sameParent(r)?!1:(A&&A(e.tr.insertText(`
|
|
10
|
-
`).scrollIntoView()),!0)};return t.displayName="newlineInCode()",t};function defaultBlockAt(t){console.log("defaultBlockAt",t);for(let e=0;e<t.edgeCount;e++){let{type:A}=t.edge(e);if(A.isTextblock&&!A.hasRequiredAttrs())return A}return null}const exitCode=()=>(t,e)=>{let{$head:A,$anchor:n}=t.selection;if(!A.parent.type.spec.code||!A.sameParent(n))return!1;let r=A.node(-1),o=A.indexAfter(-1),s=defaultBlockAt(r.contentMatchAt(o));if(!s||!r.canReplaceWith(o,o,s))return!1;if(e){let a=A.after(),l=t.tr.replaceWith(a,a,s.createAndFill());l.setSelection(Selection.near(l.doc.resolve(a),1)),e(l.scrollIntoView())}return!0},createParagraphNear=()=>{const t=(e,A)=>{let n=e.selection,{$from:r,$to:o}=n;if(n instanceof AllSelection||r.parent.inlineContent||o.parent.inlineContent)return!1;let s=defaultBlockAt(o.parent.contentMatchAt(o.indexAfter()));if(!s||!s.isTextblock)return!1;if(A){let a=(!r.parentOffset&&o.index()<o.parent.childCount?r:o).pos,l=e.tr.insert(a,s.createAndFill());l.setSelection(TextSelection.create(l.doc,a+1)),A(l.scrollIntoView())}return!0};return t.displayName="createParagraphNear()",t},liftEmptyBlock=()=>{const t=(e,A)=>{let{$cursor:n}=e.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let s=n.before();if(canSplit(e.doc,s))return A&&A(e.tr.split(s).scrollIntoView()),!0}let r=n.blockRange(),o=r&&liftTarget(r);return o==null?!1:(A&&A(e.tr.lift(r,o).scrollIntoView()),!0)};return t.displayName="liftEmptyBlock()",t},splitBlockAs=t=>{const e=(A,n)=>{let{$from:r,$to:o}=A.selection;if(A.selection instanceof NodeSelection&&A.selection.node.isBlock)return!r.parentOffset||!canSplit(A.doc,r.pos)?!1:(n&&n(A.tr.split(r.pos).scrollIntoView()),!0);if(!r.depth)return!1;let s=[],a,l,g=!1,c=!1;for(let u=r.depth;;u--)if(r.node(u).isBlock){g=r.end(u)==r.pos+(r.depth-u),c=r.start(u)==r.pos-(r.depth-u),l=defaultBlockAt(r.node(u-1).contentMatchAt(r.indexAfter(u-1)));let E=t&&t(o.parent,g,r);s.unshift(E||(g&&l?{type:l}:null)),a=u;break}else{if(u==1)return!1;s.unshift(null)}let I=A.tr;(A.selection instanceof TextSelection||A.selection instanceof AllSelection)&&I.deleteSelection();let d=I.mapping.map(r.pos),h=canSplit(I.doc,d,s.length,s);if(h||(s[0]=l?{type:l}:null,h=canSplit(I.doc,d,s.length,s)),I.split(d,s.length,s),!g&&c&&r.node(a).type!=l){let u=I.mapping.map(r.before(a)),B=I.doc.resolve(u);l&&r.node(a-1).canReplaceWith(B.index(),B.index()+1,l)&&I.setNodeMarkup(I.mapping.map(r.before(a)),l)}return n&&n(I.scrollIntoView()),!0};return e.displayName="splitBlockAs()",e},splitBlock=()=>splitBlockAs(),splitBlockKeepMarks=()=>(t,e)=>splitBlockAs().apply(void 0,[t,e&&(A=>{let n=t.storedMarks||t.selection.$to.parentOffset&&t.selection.$from.marks();n&&A.ensureMarks(n),e(A)})]),selectParentNode=()=>(t,e)=>{let{$from:A,to:n}=t.selection,r,o=A.sharedDepth(n);return o==0?!1:(r=A.before(o),e&&e(t.tr.setSelection(NodeSelection.create(t.doc,r))),!0)},selectAll$1=()=>(t,e)=>(e&&e(t.tr.setSelection(new AllSelection(t.doc))),!0);function joinMaybeClear(t,e,A){let n=e.nodeBefore,r=e.nodeAfter,o=e.index();return!n||!r||!n.type.compatibleContent(r.type)?!1:!n.content.size&&e.parent.canReplace(o-1,o)?(A&&A(t.tr.delete(e.pos-n.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(o,o+1)||!(r.isTextblock||canJoin(t.doc,e.pos))?!1:(A&&A(t.tr.join(e.pos).scrollIntoView()),!0)}function deleteBarrier(t,e,A,n){let r=e.nodeBefore,o=e.nodeAfter,s,a,l=r.type.spec.isolating||o.type.spec.isolating;if(!l&&joinMaybeClear(t,e,A))return!0;let g=!l&&e.parent.canReplace(e.index(),e.index()+1);if(g&&(s=(a=r.contentMatchAt(r.childCount)).findWrapping(o.type))&&a.matchType(s[0]||o.type).validEnd){if(A){let h=e.pos+o.nodeSize,u=Fragment.empty;for(let f=s.length-1;f>=0;f--)u=Fragment.from(s[f].create(null,u));u=Fragment.from(r.copy(u));let B=t.tr.step(new ReplaceAroundStep(e.pos-1,h,e.pos,h,new Slice(u,1,0),s.length,!0)),E=B.doc.resolve(h+2*s.length);E.nodeAfter&&E.nodeAfter.type==r.type&&canJoin(B.doc,E.pos)&&B.join(E.pos),A(B.scrollIntoView())}return!0}let c=o.type.spec.isolating||n>0&&l?null:Selection.findFrom(e,1),I=c&&c.$from.blockRange(c.$to),d=I&&liftTarget(I);if(d!=null&&d>=e.depth)return A&&A(t.tr.lift(I,d).scrollIntoView()),!0;if(g&&textblockAt(o,"start",!0)&&textblockAt(r,"end")){let h=r,u=[];for(;u.push(h),!h.isTextblock;)h=h.lastChild;let B=o,E=1;for(;!B.isTextblock;B=B.firstChild)E++;if(h.canReplace(h.childCount,h.childCount,B.content)){if(A){let f=Fragment.empty;for(let p=u.length-1;p>=0;p--)f=Fragment.from(u[p].copy(f));let Q=t.tr.step(new ReplaceAroundStep(e.pos-u.length,e.pos+o.nodeSize,e.pos+E,e.pos+o.nodeSize-E,new Slice(f,u.length,0),0,!0));A(Q.scrollIntoView())}return!0}}return!1}function selectTextblockSide(t){return function(e,A){let n=e.selection,r=t<0?n.$from:n.$to,o=r.depth;for(;r.node(o).isInline;){if(!o)return!1;o--}return r.node(o).isTextblock?(A&&A(e.tr.setSelection(TextSelection.create(e.doc,t<0?r.start(o):r.end(o)))),!0):!1}}const wrapIn=(t,e=null)=>function(A,n){let{$from:r,$to:o}=A.selection,s=r.blockRange(o),a=s&&findWrapping(s,t,e);return a?(n&&n(A.tr.wrap(s,a).scrollIntoView()),!0):!1},setBlockType=(t,e=null)=>function(A,n){let r=!1;for(let o=0;o<A.selection.ranges.length&&!r;o++){let{$from:{pos:s},$to:{pos:a}}=A.selection.ranges[o];A.doc.nodesBetween(s,a,(l,g)=>{if(r)return!1;if(!(!l.isTextblock||l.hasMarkup(t,e)))if(l.type==t)r=!0;else{let c=A.doc.resolve(g),I=c.index();r=c.parent.canReplaceWith(I,I+1,t)}})}if(!r)return!1;if(n){let o=A.tr;for(let s=0;s<A.selection.ranges.length;s++){let{$from:{pos:a},$to:{pos:l}}=A.selection.ranges[s];o.setBlockType(a,l,t,e)}n(o.scrollIntoView())}return!0};function markApplies(t,e,A,n){for(let r=0;r<e.length;r++){let{$from:o,$to:s}=e[r],a=o.depth==0?t.inlineContent&&t.type.allowsMarkType(A):!1;if(t.nodesBetween(o.pos,s.pos,(l,g)=>{if(a||!n&&l.isAtom&&l.isInline&&g>=o.pos&&g+l.nodeSize<=s.pos)return!1;a=l.inlineContent&&l.type.allowsMarkType(A)}),a)return!0}return!1}function removeInlineAtoms(t){let e=[];for(let A=0;A<t.length;A++){let{$from:n,$to:r}=t[A];n.doc.nodesBetween(n.pos,r.pos,(o,s)=>{if(o.isAtom&&o.content.size&&o.isInline&&s>=n.pos&&s+o.nodeSize<=r.pos)return s+1>n.pos&&e.push(new SelectionRange(n,n.doc.resolve(s+1))),n=n.doc.resolve(s+1+o.content.size),!1}),n.pos<r.pos&&e.push(new SelectionRange(n,r))}return e}function toggleMark(t,e=null,A){let n=(A&&A.removeWhenPresent)!==!1,r=(A&&A.enterInlineAtoms)!==!1,o=!(A&&A.includeWhitespace);return function(s,a){let{empty:l,$cursor:g,ranges:c}=s.selection;if(l&&!g||!markApplies(s.doc,c,t,r))return!1;if(a)if(g)t.isInSet(s.storedMarks||g.marks())?a(s.tr.removeStoredMark(t)):a(s.tr.addStoredMark(t.create(e)));else{let I,d=s.tr;r||(c=removeInlineAtoms(c)),n?I=!c.some(h=>s.doc.rangeHasMark(h.$from.pos,h.$to.pos,t)):I=!c.every(h=>{let u=!1;return d.doc.nodesBetween(h.$from.pos,h.$to.pos,(B,E,f)=>{if(u)return!1;u=!t.isInSet(B.marks)&&!!f&&f.type.allowsMarkType(t)&&!(B.isText&&/^\s*$/.test(B.textBetween(Math.max(0,h.$from.pos-E),Math.min(B.nodeSize,h.$to.pos-E))))}),!u});for(let h=0;h<c.length;h++){let{$from:u,$to:B}=c[h];if(!I)d.removeMark(u.pos,B.pos,t);else{let E=u.pos,f=B.pos,Q=u.nodeAfter,p=B.nodeBefore,m=o&&Q&&Q.isText?/^\s*/.exec(Q.text)[0].length:0,y=o&&p&&p.isText?/\s*$/.exec(p.text)[0].length:0;E+m<f&&(E+=m,f-=y),d.addMark(E,f,t.create(e))}}a(d.scrollIntoView())}return!0}}const undoInputRule=()=>undoInputRuleCommand,command=t=>(...e)=>t.apply(void 0,e),baseCommandFactories={wrapInList,wrapRangeInList,deleteSelection,joinBackward,joinTextblockBackward,joinTextblockForward,joinForward,joinUp,joinDown,lift,newlineInCode,exitCode,createParagraphNear,liftEmptyBlock,splitBlockAs,splitBlock,splitBlockKeepMarks,selectAll:selectAll$1,selectParentNode,selectNodeBackward,selectNodeForward,selectTextblockStart:()=>selectTextblockSide(-1),selectTextblockEnd:()=>selectTextblockSide(1),wrapIn,setBlockType,toggleMark,undoInputRule,runInputRulesRange,runInputRulesTexts,command};function firstCommand(...t){const e=function(A,n,r){for(let o=0;o<t.length;o++)if(t[o](A,n,r))return t[o].displayName!=="first"&&console.debug("firstCommand: ",t[o].displayName||t[o]),!0;return!1};return e.displayName="first",e}const backspace=firstCommand(baseCommandFactories.undoInputRule(),baseCommandFactories.deleteSelection(),baseCommandFactories.joinBackward(),baseCommandFactories.selectNodeBackward()),del=firstCommand(baseCommandFactories.deleteSelection(),baseCommandFactories.joinForward(),baseCommandFactories.selectNodeForward()),enter=firstCommand(baseCommandFactories.newlineInCode(),baseCommandFactories.createParagraphNear(),baseCommandFactories.liftEmptyBlock(),baseCommandFactories.splitBlock()),keyCommandFactories={backspace:()=>backspace,del:()=>del,enter:()=>enter},replaceRangeText=(t,e)=>(A,n)=>{const r=A.tr,o=r.mapping.map(t.from),s=r.mapping.map(t.to),a=Fragment.from(A.schema.text(e)),l=new Slice(a,0,0);return r.replace(o,s,l),n&&n(r),!0},replaceRangeSlice=(t,e)=>(A,n)=>{const r=A.tr,o=r.mapping.map(t.from),s=r.mapping.map(t.to);return r.replace(o,s,e),n&&n(r),!0};function getTopMostBlockStartForOffset(t,e){const{doc:A}=t,n=A.resolve(e),r=n.before(n.depth);return n.depth===1?r:n.start(1)}function getTopMostBlockEndForOffset(t,e){const{doc:A}=t;return A.resolve(e).end(1)}function getAdjacentTopBlock(t,e){const{doc:A}=t;if(e<0||e>A.content.size)throw new RangeError("Offset is outside the document");const n=A.resolve(e);return n.pos===n.start(n.depth)?getTopMostBlockStartForOffset(t,e):getTopMostBlockEndForOffset(t,e)}const insertBlockBefore=(t,e)=>(A,n)=>{const r=A.tr,o=getTopMostBlockStartForOffset(A,r.mapping.map(t));return r.insert(o,e),n&&n(r),!0},insertBlockAfter=(t,e)=>(A,n)=>{const r=A.tr,o=getTopMostBlockEndForOffset(A,r.mapping.map(t));return r.insert(o,e),n&&n(r),!0},insertBlockSmart=(t,e)=>(A,n)=>{const r=A.tr,o=getAdjacentTopBlock(A,r.mapping.map(t));return r.insert(o,e),n&&n(r),!0},replaceCommandFactories={replaceRangeText,replaceRangeSlice,insertBlockBefore,insertBlockAfter,insertBlockSmart};class CommandManager{constructor(e){this.editor=e,this.commandFactories={},this.run={},this.debug=!0,this.mergeCommandFactories(baseCommandFactories,"baseCommand"),this.mergeCommandFactories(keyCommandFactories,"key"),this.mergeCommandFactories(replaceCommandFactories,"replace")}mergeCommandFactories(e,A){for(const n in e){const r=e[n];r&&this.overwriteCommandFactory(A,n,r)}}overwriteCommandFactory(e,A,n){if(this.debug){const r=(...o)=>{const s=n(...o);return(l,g,c)=>(g&&console.debug(`Command: ${e}.${A}`,...o),s.apply({editor:this.editor},[l,g,c]))};this.commandFactories[A]=r}else this.commandFactories[A]=n;this.run[A]=(...r)=>{const o=this.commandFactories[A],s=o(...r),a=this.editor.state,l=this.editor.view;return l instanceof EditorView?s.apply({editor:this.editor},[a,l.dispatch,l]):s.apply({editor:this.editor},[a,l.dispatch])}}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,A=!0){const{commandFactories:n,editor:r}=this,o=this.editor.state,{view:s}=r,a=[],l=!!e,g=e||o.tr,c=createChainableState(g,o),I=()=>{},d={...Object.fromEntries(Object.entries(n).map(([h,u])=>[h,(...E)=>{const Q=u(...E).apply({editor:this.editor},[c,A?I:void 0]);return a.push(Q),d}])),run:()=>(!l&&A&&!g.getMeta("preventDispatch")&&s.dispatch(g),a.every(h=>h===!0)),chain:()=>this.createChain(g,A)};return d}createCan(e){return this.createChain(e,!1)}}class SmartOutput{constructor(){this._rowPos=0,this._colPos=0,this._pos=0,this.chunks=[],this.metas=[]}log(e,A){if(e.length===0)return;this.chunks.push(e),this.metas.push({pos:this._pos,colPos:this._colPos,rowPos:this._rowPos,item:A});const n=e.split(`
|
|
10
|
+
`).scrollIntoView()),!0)};return t.displayName="newlineInCode()",t};function defaultBlockAt(t){console.log("defaultBlockAt",t);for(let e=0;e<t.edgeCount;e++){let{type:A}=t.edge(e);if(A.isTextblock&&!A.hasRequiredAttrs())return A}return null}const exitCode=()=>(t,e)=>{let{$head:A,$anchor:n}=t.selection;if(!A.parent.type.spec.code||!A.sameParent(n))return!1;let r=A.node(-1),o=A.indexAfter(-1),s=defaultBlockAt(r.contentMatchAt(o));if(!s||!r.canReplaceWith(o,o,s))return!1;if(e){let a=A.after(),l=t.tr.replaceWith(a,a,s.createAndFill());l.setSelection(Selection.near(l.doc.resolve(a),1)),e(l.scrollIntoView())}return!0},createParagraphNear=()=>{const t=(e,A)=>{let n=e.selection,{$from:r,$to:o}=n;if(n instanceof AllSelection||r.parent.inlineContent||o.parent.inlineContent)return!1;let s=defaultBlockAt(o.parent.contentMatchAt(o.indexAfter()));if(!s||!s.isTextblock)return!1;if(A){let a=(!r.parentOffset&&o.index()<o.parent.childCount?r:o).pos,l=e.tr.insert(a,s.createAndFill());l.setSelection(TextSelection.create(l.doc,a+1)),A(l.scrollIntoView())}return!0};return t.displayName="createParagraphNear()",t},liftEmptyBlock=()=>{const t=(e,A)=>{let{$cursor:n}=e.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let s=n.before();if(canSplit(e.doc,s))return A&&A(e.tr.split(s).scrollIntoView()),!0}let r=n.blockRange(),o=r&&liftTarget(r);return o==null?!1:(A&&A(e.tr.lift(r,o).scrollIntoView()),!0)};return t.displayName="liftEmptyBlock()",t},splitBlockAs=t=>{const e=(A,n)=>{let{$from:r,$to:o}=A.selection;if(A.selection instanceof NodeSelection&&A.selection.node.isBlock)return!r.parentOffset||!canSplit(A.doc,r.pos)?!1:(n&&n(A.tr.split(r.pos).scrollIntoView()),!0);if(!r.depth)return!1;let s=[],a,l,g=!1,c=!1;for(let u=r.depth;;u--)if(r.node(u).isBlock){g=r.end(u)==r.pos+(r.depth-u),c=r.start(u)==r.pos-(r.depth-u),l=defaultBlockAt(r.node(u-1).contentMatchAt(r.indexAfter(u-1)));let E=t&&t(o.parent,g,r);s.unshift(E||(g&&l?{type:l}:null)),a=u;break}else{if(u==1)return!1;s.unshift(null)}let I=A.tr;(A.selection instanceof TextSelection||A.selection instanceof AllSelection)&&I.deleteSelection();let d=I.mapping.map(r.pos),h=canSplit(I.doc,d,s.length,s);if(h||(s[0]=l?{type:l}:null,h=canSplit(I.doc,d,s.length,s)),I.split(d,s.length,s),!g&&c&&r.node(a).type!=l){let u=I.mapping.map(r.before(a)),B=I.doc.resolve(u);l&&r.node(a-1).canReplaceWith(B.index(),B.index()+1,l)&&I.setNodeMarkup(I.mapping.map(r.before(a)),l)}return n&&n(I.scrollIntoView()),!0};return e.displayName="splitBlockAs()",e},splitBlock=()=>splitBlockAs(),splitBlockKeepMarks=()=>(t,e)=>splitBlockAs().apply(void 0,[t,e&&(A=>{let n=t.storedMarks||t.selection.$to.parentOffset&&t.selection.$from.marks();n&&A.ensureMarks(n),e(A)})]),selectParentNode=()=>(t,e)=>{let{$from:A,to:n}=t.selection,r,o=A.sharedDepth(n);return o==0?!1:(r=A.before(o),e&&e(t.tr.setSelection(NodeSelection.create(t.doc,r))),!0)},selectAll$1=()=>(t,e)=>(e&&e(t.tr.setSelection(new AllSelection(t.doc))),!0);function joinMaybeClear(t,e,A){let n=e.nodeBefore,r=e.nodeAfter,o=e.index();return!n||!r||!n.type.compatibleContent(r.type)?!1:!n.content.size&&e.parent.canReplace(o-1,o)?(A&&A(t.tr.delete(e.pos-n.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(o,o+1)||!(r.isTextblock||canJoin(t.doc,e.pos))?!1:(A&&A(t.tr.join(e.pos).scrollIntoView()),!0)}function deleteBarrier(t,e,A,n){let r=e.nodeBefore,o=e.nodeAfter,s,a,l=r.type.spec.isolating||o.type.spec.isolating;if(!l&&joinMaybeClear(t,e,A))return!0;let g=!l&&e.parent.canReplace(e.index(),e.index()+1);if(g&&(s=(a=r.contentMatchAt(r.childCount)).findWrapping(o.type))&&a.matchType(s[0]||o.type).validEnd){if(A){let h=e.pos+o.nodeSize,u=Fragment.empty;for(let f=s.length-1;f>=0;f--)u=Fragment.from(s[f].create(null,u));u=Fragment.from(r.copy(u));let B=t.tr.step(new ReplaceAroundStep(e.pos-1,h,e.pos,h,new Slice(u,1,0),s.length,!0)),E=B.doc.resolve(h+2*s.length);E.nodeAfter&&E.nodeAfter.type==r.type&&canJoin(B.doc,E.pos)&&B.join(E.pos),A(B.scrollIntoView())}return!0}let c=o.type.spec.isolating||n>0&&l?null:Selection.findFrom(e,1),I=c&&c.$from.blockRange(c.$to),d=I&&liftTarget(I);if(d!=null&&d>=e.depth)return A&&A(t.tr.lift(I,d).scrollIntoView()),!0;if(g&&textblockAt(o,"start",!0)&&textblockAt(r,"end")){let h=r,u=[];for(;u.push(h),!h.isTextblock;)h=h.lastChild;let B=o,E=1;for(;!B.isTextblock;B=B.firstChild)E++;if(h.canReplace(h.childCount,h.childCount,B.content)){if(A){let f=Fragment.empty;for(let p=u.length-1;p>=0;p--)f=Fragment.from(u[p].copy(f));let Q=t.tr.step(new ReplaceAroundStep(e.pos-u.length,e.pos+o.nodeSize,e.pos+E,e.pos+o.nodeSize-E,new Slice(f,u.length,0),0,!0));A(Q.scrollIntoView())}return!0}}return!1}function selectTextblockSide(t){return function(e,A){let n=e.selection,r=t<0?n.$from:n.$to,o=r.depth;for(;r.node(o).isInline;){if(!o)return!1;o--}return r.node(o).isTextblock?(A&&A(e.tr.setSelection(TextSelection.create(e.doc,t<0?r.start(o):r.end(o)))),!0):!1}}const wrapIn=(t,e=null)=>function(A,n){let{$from:r,$to:o}=A.selection,s=r.blockRange(o),a=s&&findWrapping(s,t,e);return a?(n&&n(A.tr.wrap(s,a).scrollIntoView()),!0):!1},setBlockType=(t,e=null)=>function(A,n){let r=!1;for(let o=0;o<A.selection.ranges.length&&!r;o++){let{$from:{pos:s},$to:{pos:a}}=A.selection.ranges[o];A.doc.nodesBetween(s,a,(l,g)=>{if(r)return!1;if(!(!l.isTextblock||l.hasMarkup(t,e)))if(l.type==t)r=!0;else{let c=A.doc.resolve(g),I=c.index();r=c.parent.canReplaceWith(I,I+1,t)}})}if(!r)return!1;if(n){let o=A.tr;for(let s=0;s<A.selection.ranges.length;s++){let{$from:{pos:a},$to:{pos:l}}=A.selection.ranges[s];o.setBlockType(a,l,t,e)}n(o.scrollIntoView())}return!0};function markApplies(t,e,A,n){for(let r=0;r<e.length;r++){let{$from:o,$to:s}=e[r],a=o.depth==0?t.inlineContent&&t.type.allowsMarkType(A):!1;if(t.nodesBetween(o.pos,s.pos,(l,g)=>{if(a||!n&&l.isAtom&&l.isInline&&g>=o.pos&&g+l.nodeSize<=s.pos)return!1;a=l.inlineContent&&l.type.allowsMarkType(A)}),a)return!0}return!1}function removeInlineAtoms(t){let e=[];for(let A=0;A<t.length;A++){let{$from:n,$to:r}=t[A];n.doc.nodesBetween(n.pos,r.pos,(o,s)=>{if(o.isAtom&&o.content.size&&o.isInline&&s>=n.pos&&s+o.nodeSize<=r.pos)return s+1>n.pos&&e.push(new SelectionRange(n,n.doc.resolve(s+1))),n=n.doc.resolve(s+1+o.content.size),!1}),n.pos<r.pos&&e.push(new SelectionRange(n,r))}return e}function toggleMark(t,e=null,A){let n=(A&&A.removeWhenPresent)!==!1,r=(A&&A.enterInlineAtoms)!==!1,o=!(A&&A.includeWhitespace);return function(s,a){let{empty:l,$cursor:g,ranges:c}=s.selection;if(l&&!g||!markApplies(s.doc,c,t,r))return!1;if(a)if(g)t.isInSet(s.storedMarks||g.marks())?a(s.tr.removeStoredMark(t)):a(s.tr.addStoredMark(t.create(e)));else{let I,d=s.tr;r||(c=removeInlineAtoms(c)),n?I=!c.some(h=>s.doc.rangeHasMark(h.$from.pos,h.$to.pos,t)):I=!c.every(h=>{let u=!1;return d.doc.nodesBetween(h.$from.pos,h.$to.pos,(B,E,f)=>{if(u)return!1;u=!t.isInSet(B.marks)&&!!f&&f.type.allowsMarkType(t)&&!(B.isText&&/^\s*$/.test(B.textBetween(Math.max(0,h.$from.pos-E),Math.min(B.nodeSize,h.$to.pos-E))))}),!u});for(let h=0;h<c.length;h++){let{$from:u,$to:B}=c[h];if(!I)d.removeMark(u.pos,B.pos,t);else{let E=u.pos,f=B.pos,Q=u.nodeAfter,p=B.nodeBefore,m=o&&Q&&Q.isText?/^\s*/.exec(Q.text)[0].length:0,y=o&&p&&p.isText?/\s*$/.exec(p.text)[0].length:0;E+m<f&&(E+=m,f-=y),d.addMark(E,f,t.create(e))}}a(d.scrollIntoView())}return!0}}const undoInputRule=()=>undoInputRuleCommand,command=t=>(...e)=>t.apply(void 0,e),baseCommandFactories={wrapInList,wrapRangeInList,deleteSelection,joinBackward,joinTextblockBackward,joinTextblockForward,joinForward,joinUp,joinDown,lift,newlineInCode,exitCode,createParagraphNear,liftEmptyBlock,splitBlockAs,splitBlock,splitBlockKeepMarks,selectAll:selectAll$1,selectParentNode,selectNodeBackward,selectNodeForward,selectTextblockStart:()=>selectTextblockSide(-1),selectTextblockEnd:()=>selectTextblockSide(1),wrapIn,setBlockType,toggleMark,undoInputRule,runInputRulesRange,runInputRulesTexts,command};function firstCommand(...t){const e=function(A,n,r){for(let o=0;o<t.length;o++)if(t[o](A,n,r))return t[o].displayName!=="first"&&console.debug("firstCommand: ",t[o].displayName||t[o]),!0;return!1};return e.displayName="first",e}const backspace=firstCommand(baseCommandFactories.undoInputRule(),baseCommandFactories.deleteSelection(),baseCommandFactories.joinBackward(),baseCommandFactories.selectNodeBackward()),del=firstCommand(baseCommandFactories.deleteSelection(),baseCommandFactories.joinForward(),baseCommandFactories.selectNodeForward()),enter=firstCommand(baseCommandFactories.newlineInCode(),baseCommandFactories.createParagraphNear(),baseCommandFactories.liftEmptyBlock(),baseCommandFactories.splitBlock()),keyCommandFactories={backspace:()=>backspace,del:()=>del,enter:()=>enter},replaceRangeText=(t,e)=>(A,n)=>{const r=A.tr,o=r.mapping.map(t.from),s=r.mapping.map(t.to),a=Fragment.from(A.schema.text(e)),l=new Slice(a,0,0);return r.replace(o,s,l),n&&n(r),!0},replaceRangeSlice=(t,e)=>(A,n)=>{const r=A.tr,o=r.mapping.map(t.from),s=r.mapping.map(t.to);return r.replace(o,s,e),n&&n(r),!0};function getTopMostBlockStartForOffset(t,e){const{doc:A}=t,n=A.resolve(e),r=n.before(n.depth);return n.depth===1?r:n.start(1)}function getTopMostBlockEndForOffset(t,e){const{doc:A}=t;return A.resolve(e).end(1)}function getAdjacentTopBlock(t,e){const{doc:A}=t;if(e<0||e>A.content.size)throw new RangeError("Offset is outside the document");const n=A.resolve(e);return n.pos===n.start(n.depth)?getTopMostBlockStartForOffset(t,e):getTopMostBlockEndForOffset(t,e)}const insertBlockBefore=(t,e)=>(A,n)=>{const r=A.tr,o=getTopMostBlockStartForOffset(A,r.mapping.map(t));return r.insert(o,e),n&&n(r),!0},insertBlockAfter=(t,e)=>(A,n)=>{const r=A.tr,o=getTopMostBlockEndForOffset(A,r.mapping.map(t));return r.insert(o,e),n&&n(r),!0},insertBlockSmart=(t,e)=>(A,n)=>{const r=A.tr,o=getAdjacentTopBlock(A,r.mapping.map(t));return r.insert(o,e),n&&n(r),!0},replaceCommandFactories={replaceRangeText,replaceRangeSlice,insertBlockBefore,insertBlockAfter,insertBlockSmart};class CommandManager{constructor(e){this.editor=e,this.commandFactories={},this.run={},this.debug=!0,this.mergeCommandFactories(baseCommandFactories,"baseCommand"),this.mergeCommandFactories(keyCommandFactories,"key"),this.mergeCommandFactories(replaceCommandFactories,"replace")}mergeCommandFactories(e,A){for(const n in e){const r=e[n];r&&this.overwriteCommandFactory(A,n,r)}}overwriteCommandFactory(e,A,n){if(this.debug){const r=(...o)=>{const s=n(...o);return(l,g,c)=>(g&&console.debug(`Command: ${e}.${A}`,...o),s.apply({editor:this.editor},[l,g,c]))};this.commandFactories[A]=r}else this.commandFactories[A]=n;this.run[A]=(...r)=>{const o=this.commandFactories[A],s=o(...r),a=this.editor.state,l=this.editor.view;return l instanceof EditorView?s.apply({editor:this.editor},[a,l.dispatch,l]):s.apply({editor:this.editor},[a,l.dispatch])}}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,A=!0){const{commandFactories:n,editor:r}=this,o=this.editor.state,{view:s}=r,a=[],l=!!e,g=e||o.tr;g.setMeta("isCommand",!0);const c=createChainableState(g,o),I=()=>{},d={...Object.fromEntries(Object.entries(n).map(([h,u])=>[h,(...E)=>{const Q=u(...E).apply({editor:this.editor},[c,A?I:void 0]);return a.push(Q),d}])),run:()=>(!l&&A&&!g.getMeta("preventDispatch")&&s.dispatch(g),a.every(h=>h===!0)),chain:()=>this.createChain(g,A)};return d}createCan(e){return this.createChain(e,!1)}}class SmartOutput{constructor(){this._rowPos=0,this._colPos=0,this._pos=0,this.chunks=[],this.metas=[]}log(e,A){if(e.length===0)return;this.chunks.push(e),this.metas.push({pos:this._pos,colPos:this._colPos,rowPos:this._rowPos,item:A});const n=e.split(`
|
|
11
11
|
`);n.length===1?this._colPos+=n[n.length-1].length:(this._rowPos+=n.length-1,this._colPos=n[n.length-1].length),this._pos+=e.length}getMetas(){return this.metas}get chunkPos(){return this.chunks.length}rollback(e){this.chunks.splice(e),this.metas.splice(e)}get rowPos(){return this._rowPos}get colPos(){return this._colPos}get pos(){return this._pos}backspace(e){const A=[],n=[];for(;e>0&&this.chunks[0].length>0;){const r=this.metas.pop();let o=this.chunks.pop();if(!o||!r)break;const s=o.length;o=o.substring(0,Math.max(0,o.length-e)),A.unshift(r),n.unshift(o),e-=s-o.length}this.chunks.push(...n),this.metas.push(...A)}endsWith(e){return this.chunks.join("").endsWith(e)}toString(){return this.chunks.join("")}getSourceMap(e){const A=[];let n=-1,r=-1,o=0,s=0,a=0,l=0;for(const c of this.metas){for(;c.rowPos>=A.length;)A.push([]);if(n!=c.rowPos||r!=c.colPos){const I=A[c.rowPos];n!=c.rowPos&&(l=0);const d=e(c.rowPos,c.colPos,c.pos,c.item);d&&(I.push([c.colPos-l,d.sourceNo-o,d.sourceRowPos-s,d.sourceColPos-a]),l=c.colPos,o=d.sourceNo,s=d.sourceRowPos,a=d.sourceColPos)}n=c.rowPos,r=c.colPos}const g=A.map(c=>c.map(I=>encode(I)).join(",")).join(";");return{version:3,file:"",sourceRoot:"",sources:[],sourcesContent:[],names:[],mappings:g}}}const integer_to_char={};"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".split("").forEach(function(t,e){integer_to_char[e]=t});function encode(t){if(typeof t=="number")return encode_integer(t);let e="";for(let A=0;A<t.length;A+=1)e+=encode_integer(t[A]);return e}function encode_integer(t){let e="";t<0?t=-t<<1|1:t<<=1;do{let A=t&31;t>>>=5,t>0&&(A|=32),e+=integer_to_char[A]}while(t>0);return e}function trimText(t,e=20){return t=t.replaceAll(`
|
|
12
12
|
`,"\\n"),t.length<=e?t:t.slice(0,e)+"..."}function nodeToTreeStringOutput(t,e,A=0,n=0){let r="";for(let s=0;s<A;s++)r+=" ";if(Array.isArray(e)){for(const s of e)t.log(r,{node:s,pos:n}),nodeToTreeStringOutput(t,s,A+1,n);return}let o="";if("type"in e){o+=` - [${e.type.name}] `,o+=`pos: ${n}, `,o+=`nodeSize: ${e.nodeSize}, `,o+=`epos: ${n+e.nodeSize}, `,e.content&&(o+=`fragment.size: ${e.content.size}, `),t.log(r+o+`
|
|
13
13
|
`,{node:e,pos:n});let s="";if(e.marks)for(const a of e.marks)s+=`(${a.type.name}), `;s&&t.log(r+" "+s+`
|
|
@@ -193,5 +193,5 @@ ${JSON.stringify(r,null,2)}`),new Error("Language.load failed: no language funct
|
|
|
193
193
|
`),I+=h.nodeSize;continue}break}if(c.length>1){const h=n.mapping.map(a),u=n.mapping.map(a+I);let B=c.join("").replace(/\n+$/gm,`
|
|
194
194
|
`);const E=B.split(`
|
|
195
195
|
`);let f=0;for(f=0;f<E.length&&!E[f].trim();f++);E.splice(0,f),B=E.join(`
|
|
196
|
-
`);const Q=A.text(B),p=A.nodes.code_block.createAndFill({lang:g.attrs.lang},[Q]);p&&(n=n.replaceRangeWith(h,u,p))}a+=I}return e&&e(n),n.docChanged},ANY_LIST=["ordered_list","bullet_list"],fixListsLevels=(t,e)=>{const A=t.doc,n=t.schema,r=n.nodes.bullet_list,o=n.nodes.list_item,s=n.nodes.paragraph,a=t.tr;let l=0,g=[],c=[],I=0;function d(h,u=0,B=0){let E=0;for(let f=0;f<h.length;f++){const Q=h[f];if(!ANY_LIST.includes(Q.type.name))d(Q.children,u+E+1,B+1);else{const p=Q.attrs.odtMarginLeft||0;if(l===0&&(c=[],I=0,g.length>=l))for(let m=0;m<g.length;m++)I<g.length&&p>g[I]&&(c[l+I]=g[I],I++);if(c[l+I]=p,l++,d(Q.children,u+E,B+1),l--,l===0&&!Q.attrs.toc){g=c;for(let m=0;m<I;m++){const y=r.create({type:"none"},o.create(null,Fragment.from([s.create(),Q])));a.replaceWith(a.mapping.map(u+E),a.mapping.map(u+E+Q.nodeSize),y)}}}E+=Q.nodeSize}}return d(A.children),e&&e(a),a.docChanged};function getDefaultsPostProcessFilters({doc:t,filesMap:e}){return[convertCodeParagraphsToCodeBlocks,fixListsLevels,fixContinuedLists,convertMathMl,mergeCodeBlocks]}async function urlRewrite(t,e,A,n){const r=[];A.doc.descendants((a,l)=>{a.type.name==="image"&&r.push({node:a,pos:l})});const o=[];A.doc.descendants((a,l)=>{a.marks.find(g=>g.type.name==="link")&&o.push({node:a,pos:l})});const s=A.tr;for(const{node:a,pos:l}of o){const g=a.marks.find(I=>I.type.name==="link");if(!g)continue;let c=g.attrs.href||"";if(c=await t(c,{type:"A",dest:"kerebron"}),c!==g.attrs.href){const I=a.marks.map(u=>u.type.name==="link"?A.schema.marks.link.create({...u.attrs,href:c}):u),d=A.schema.nodes[a.type.name];let h;d.isText?h=A.schema.text(a.text||"",I):h=d.create(a.attrs,a.content,I),s.replaceWith(s.mapping.map(l),s.mapping.map(l+a.nodeSize),h)}}for(const{node:a,pos:l}of r){let g=a.attrs.src||"";if(g=await t(g,{type:"IMG",dest:"kerebron",filesMap:e}),g!==a.attrs.src){const I=A.schema.nodes[a.type.name].create({...a.attrs,src:g},a.content,a.marks);s.replaceWith(s.mapping.map(l),s.mapping.map(l+a.nodeSize),I)}}return n(s),s.docChanged}async function init(t){const e=await Promise.resolve().then(()=>require("./odt_parser.internal-C8Sm3VVG.cjs")),A=await WebAssembly.instantiate(t,{"./odt_parser.internal.js":e});return e.__wbg_set_wasm(A.instance.exports),A.instance.exports.__wbindgen_start(),e.init_debug(),A.instance,e}let odtWasm;class ExtensionOdt extends Extension{constructor(e={}){super(e),this.config=e,this.name="odt"}getConverters(e,A){const n={fromDoc:async r=>{throw new Error("Not implemented")},toDoc:async r=>{const o=e.config.assetLoad;if(!o)throw new Error("No assetLoad");if(!odtWasm){const I=this.config.debug?await o("odt-wasm/odt-parser-debug.wasm"):await o("odt-wasm/odt-parser.wasm");odtWasm=await init(I)}const{doc:s,filesMap:a}=n.odtToJson(r,odtWasm),l=getDefaultsPostProcessFilters({doc:s,filesMap:a}).concat(this.config.postProcessCommands||[]);let g=EditorState.create({doc:s});const c=I=>{g=g.apply(I)};if(this.urlFromRewriter&&await urlRewrite(this.urlFromRewriter,a,g,c),l.length>0)for(const I of l)I(g,d=>c(d));if(this.config.debug){const I=new CustomEvent("odt:pmdoc:filtered",{detail:{doc:g.doc}});this.editor.dispatchEvent(I)}return g.doc},odtToJson:(r,o)=>{const s=o.unzip(r),a={};for(const d of s.keys())a[d]=Uint8Array.from(s.get(d));const l=o.parse_styles(s.get("styles.xml")),g=o.parse_content(s.get("content.xml"));if(this.config.debug){const d=new CustomEvent("odt:parsed",{detail:{stylesTree:l,contentTree:g,filesMap:a}});this.editor.dispatchEvent(d)}const c=new OdtParser(e.schema,this.config);c.filesMap=a;const I=c.parse({...a,contentTree:g,stylesTree:l});if(this.config.debug){const d=new CustomEvent("odt:pmdoc",{detail:{doc:I}});this.editor.dispatchEvent(d)}return{doc:I,stylesTree:l,contentTree:g,filesMap:a}}};return{"application/vnd.oasis.opendocument.text":n}}}function createCell(t,e){return t.createAndFill()}function getTableNodeTypes(t){if(t.cached.tableNodeTypes)return t.cached.tableNodeTypes;const e={};return Object.keys(t.nodes).forEach(A=>{const n=t.nodes[A];n.spec.tableRole&&(e[n.spec.tableRole]=n)}),t.cached.tableNodeTypes=e,e}function createTable(t,e,A,n,r){const o=getTableNodeTypes(t),s=[],a=[];for(let I=0;I<A;I+=1){const d=createCell(o.cell);if(d&&a.push(d),n){const h=createCell(o.header_cell);h&&s.push(h)}}const l=[];for(let I=0;I<e;I+=1)l.push(o.row.createChecked(null,n&&I===0?s:a));const g={},c=t.spec.nodes.get("table");for(const[I,d]of Object.entries(c.attrs||{}))typeof d.default<"u"&&(g[I]=d.default);return o.table.createChecked(g,l)}let readFromCache,addToCache;if(typeof WeakMap<"u"){const t=new WeakMap;readFromCache=e=>t.get(e),addToCache=(e,A)=>(t.set(e,A),A)}else{const t=[];let A=0;readFromCache=n=>{for(let r=0;r<t.length;r+=2)if(t[r]==n)return t[r+1]},addToCache=(n,r)=>(A==10&&(A=0),t[A++]=n,t[A++]=r)}class TableMap{constructor(e,A,n,r){this.width=e,this.height=A,this.map=n,this.problems=r}findCell(e){for(let A=0;A<this.map.length;A++){const n=this.map[A];if(n!=e)continue;const r=A%this.width,o=A/this.width|0;let s=r+1,a=o+1;for(let l=1;s<this.width&&this.map[A+l]==n;l++)s++;for(let l=1;a<this.height&&this.map[A+this.width*l]==n;l++)a++;return{left:r,top:o,right:s,bottom:a}}throw new RangeError(`No cell with offset ${e} found`)}colCount(e){for(let A=0;A<this.map.length;A++)if(this.map[A]==e)return A%this.width;throw new RangeError(`No cell with offset ${e} found`)}nextCell(e,A,n){const{left:r,right:o,top:s,bottom:a}=this.findCell(e);return A=="horiz"?(n<0?r==0:o==this.width)?null:this.map[s*this.width+(n<0?r-1:o)]:(n<0?s==0:a==this.height)?null:this.map[r+this.width*(n<0?s-1:a)]}rectBetween(e,A){const{left:n,right:r,top:o,bottom:s}=this.findCell(e),{left:a,right:l,top:g,bottom:c}=this.findCell(A);return{left:Math.min(n,a),top:Math.min(o,g),right:Math.max(r,l),bottom:Math.max(s,c)}}cellsInRect(e){const A=[],n={};for(let r=e.top;r<e.bottom;r++)for(let o=e.left;o<e.right;o++){const s=r*this.width+o,a=this.map[s];n[a]||(n[a]=!0,!(o==e.left&&o&&this.map[s-1]==a||r==e.top&&r&&this.map[s-this.width]==a)&&A.push(a))}return A}positionAt(e,A,n){for(let r=0,o=0;;r++){const s=o+n.child(r).nodeSize;if(r==e){let a=A+e*this.width;const l=(e+1)*this.width;for(;a<l&&this.map[a]<o;)a++;return a==l?s-1:this.map[a]}o=s}}static get(e){return readFromCache(e)||addToCache(e,computeMap(e))}}function computeMap(t){if(t.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+t.type.name);const e=findWidth(t),A=t.childCount,n=[];let r=0,o=null;const s=[];for(let g=0,c=e*A;g<c;g++)n[g]=0;for(let g=0,c=0;g<A;g++){const I=t.child(g);c++;for(let u=0;;u++){for(;r<n.length&&n[r]!=0;)r++;if(u==I.childCount)break;const B=I.child(u),{colspan:E,rowspan:f,colwidth:Q}=B.attrs;for(let p=0;p<f;p++){if(p+g>=A){(o||(o=[])).push({type:"overlong_rowspan",pos:c,n:f-p});break}const m=r+p*e;for(let y=0;y<E;y++){n[m+y]==0?n[m+y]=c:(o||(o=[])).push({type:"collision",row:g,pos:c,n:E-y});const w=Q&&Q[y];if(w){const D=(m+y)%e*2,_=s[D];_==null||_!=w&&s[D+1]==1?(s[D]=w,s[D+1]=1):_==w&&s[D+1]++}}}r+=E,c+=B.nodeSize}const d=(g+1)*e;let h=0;for(;r<d;)n[r++]==0&&h++;h&&(o||(o=[])).push({type:"missing",row:g,n:h}),c++}(e===0||A===0)&&(o||(o=[])).push({type:"zero_sized"});const a=new TableMap(e,A,n,o);let l=!1;for(let g=0;!l&&g<s.length;g+=2)s[g]!=null&&s[g+1]<A&&(l=!0);return l&&findBadColWidths(a,s,t),a}function findWidth(t){let e=-1,A=!1;for(let n=0;n<t.childCount;n++){const r=t.child(n);let o=0;if(A)for(let s=0;s<n;s++){const a=t.child(s);for(let l=0;l<a.childCount;l++){const g=a.child(l);s+g.attrs.rowspan>n&&(o+=g.attrs.colspan)}}for(let s=0;s<r.childCount;s++){const a=r.child(s);o+=a.attrs.colspan,a.attrs.rowspan>1&&(A=!0)}e==-1?e=o:e!=o&&(e=Math.max(e,o))}return e}function findBadColWidths(t,e,A){t.problems||(t.problems=[]);const n={};for(let r=0;r<t.map.length;r++){const o=t.map[r];if(n[o])continue;n[o]=!0;const s=A.nodeAt(o);if(!s)throw new RangeError(`No cell with offset ${o} found`);let a=null;const l=s.attrs;for(let g=0;g<l.colspan;g++){const c=(r+g)%t.width,I=e[c*2];I!=null&&(!l.colwidth||l.colwidth[g]!=I)&&((a||(a=freshColWidth(l)))[g]=I)}a&&t.problems.unshift({type:"colwidth mismatch",pos:o,colwidth:a})}}function freshColWidth(t){if(t.colwidth)return t.colwidth.slice();const e=[];for(let A=0;A<t.colspan;A++)e.push(0);return e}function tableNodeTypes(t){let e=t.cached.tableNodeTypes;if(!e){e=t.cached.tableNodeTypes={};for(const A in t.nodes){const n=t.nodes[A],r=n.spec.tableRole;r&&(e[r]=n)}}return e}const tableEditingKey=new PluginKey("selectingCells");function cellAround(t){for(let e=t.depth-1;e>0;e--)if(t.node(e).type.spec.tableRole=="row")return t.node(0).resolve(t.before(e+1));return null}function cellWrapping(t){for(let e=t.depth;e>0;e--){const A=t.node(e).type.spec.tableRole;if(A==="cell"||A==="header_cell")return t.node(e)}return null}function isInTable(t){const e=t.selection.$head;for(let A=e.depth;A>0;A--)if(e.node(A).type.spec.tableRole=="row")return!0;return!1}function selectionCell(t){const e=t.selection;if("$anchorCell"in e&&e.$anchorCell)return e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell;if("node"in e&&e.node&&e.node.type.spec.tableRole=="cell")return e.$anchor;const A=cellAround(e.$head)||cellNear(e.$head);if(A)return A;throw new RangeError(`No cell found around position ${e.head}`)}function cellNear(t){for(let e=t.nodeAfter,A=t.pos;e;e=e.firstChild,A++){const n=e.type.spec.tableRole;if(n=="cell"||n=="header_cell")return t.doc.resolve(A)}for(let e=t.nodeBefore,A=t.pos;e;e=e.lastChild,A--){const n=e.type.spec.tableRole;if(n=="cell"||n=="header_cell")return t.doc.resolve(A-e.nodeSize)}}function pointsAtCell(t){return t.parent.type.spec.tableRole=="row"&&!!t.nodeAfter}function moveCellForward(t){return t.node(0).resolve(t.pos+t.nodeAfter.nodeSize)}function inSameTable(t,e){return t.depth==e.depth&&t.pos>=e.start(-1)&&t.pos<=e.end(-1)}function nextCell(t,e,A){const n=t.node(-1),r=TableMap.get(n),o=t.start(-1),s=r.nextCell(t.pos-o,e,A);return s==null?null:t.node(0).resolve(o+s)}function removeColSpan(t,e,A=1){const n={...t,colspan:t.colspan-A};return n.colwidth&&(n.colwidth=n.colwidth.slice(),n.colwidth.splice(e,A),n.colwidth.some(r=>r>0)||(n.colwidth=null)),n}function addColSpan(t,e,A=1){const n={...t,colspan:t.colspan+A};if(n.colwidth){n.colwidth=n.colwidth.slice();for(let r=0;r<A;r++)n.colwidth.splice(e,0,0)}return n}function columnIsHeader(t,e,A){const n=tableNodeTypes(e.type.schema).header_cell;for(let r=0;r<t.height;r++)if(e.nodeAt(t.map[A+r*t.width]).type!=n)return!1;return!0}class CellSelection extends Selection{constructor(e,A=e){const n=e.node(-1),r=TableMap.get(n),o=e.start(-1),s=r.rectBetween(e.pos-o,A.pos-o),a=e.node(0),l=r.cellsInRect(s).filter(c=>c!=A.pos-o);l.unshift(A.pos-o);const g=l.map(c=>{const I=n.nodeAt(c);if(!I)throw RangeError(`No cell with offset ${c} found`);const d=o+c+1;return new SelectionRange(a.resolve(d),a.resolve(d+I.content.size))});super(g[0].$from,g[0].$to,g),this.$anchorCell=e,this.$headCell=A}map(e,A){const n=e.resolve(A.map(this.$anchorCell.pos)),r=e.resolve(A.map(this.$headCell.pos));if(pointsAtCell(n)&&pointsAtCell(r)&&inSameTable(n,r)){const o=this.$anchorCell.node(-1)!=n.node(-1);return o&&this.isRowSelection()?CellSelection.rowSelection(n,r):o&&this.isColSelection()?CellSelection.colSelection(n,r):new CellSelection(n,r)}return TextSelection.between(n,r)}content(){const e=this.$anchorCell.node(-1),A=TableMap.get(e),n=this.$anchorCell.start(-1),r=A.rectBetween(this.$anchorCell.pos-n,this.$headCell.pos-n),o={},s=[];for(let l=r.top;l<r.bottom;l++){const g=[];for(let c=l*A.width+r.left,I=r.left;I<r.right;I++,c++){const d=A.map[c];if(o[d])continue;o[d]=!0;const h=A.findCell(d);let u=e.nodeAt(d);if(!u)throw RangeError(`No cell with offset ${d} found`);const B=r.left-h.left,E=h.right-r.right;if(B>0||E>0){let f=u.attrs;if(B>0&&(f=removeColSpan(f,0,B)),E>0&&(f=removeColSpan(f,f.colspan-E,E)),h.left<r.left){if(u=u.type.createAndFill(f),!u)throw RangeError(`Could not create cell with attrs ${JSON.stringify(f)}`)}else u=u.type.create(f,u.content)}if(h.top<r.top||h.bottom>r.bottom){const f={...u.attrs,rowspan:Math.min(h.bottom,r.bottom)-Math.max(h.top,r.top)};h.top<r.top?u=u.type.createAndFill(f):u=u.type.create(f,u.content)}g.push(u)}s.push(e.child(l).copy(Fragment.from(g)))}const a=this.isColSelection()&&this.isRowSelection()?e:s;return new Slice(Fragment.from(a),1,1)}replace(e,A=Slice.empty){const n=e.steps.length,r=this.ranges;for(let s=0;s<r.length;s++){const{$from:a,$to:l}=r[s],g=e.mapping.slice(n);e.replace(g.map(a.pos),g.map(l.pos),s?Slice.empty:A)}const o=Selection.findFrom(e.doc.resolve(e.mapping.slice(n).map(this.to)),-1);o&&e.setSelection(o)}replaceWith(e,A){this.replace(e,new Slice(Fragment.from(A),0,0))}forEachCell(e){const A=this.$anchorCell.node(-1),n=TableMap.get(A),r=this.$anchorCell.start(-1),o=n.cellsInRect(n.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r));for(let s=0;s<o.length;s++)e(A.nodeAt(o[s]),r+o[s])}isColSelection(){const e=this.$anchorCell.index(-1),A=this.$headCell.index(-1);if(Math.min(e,A)>0)return!1;const n=e+this.$anchorCell.nodeAfter.attrs.rowspan,r=A+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(n,r)==this.$headCell.node(-1).childCount}static colSelection(e,A=e){const n=e.node(-1),r=TableMap.get(n),o=e.start(-1),s=r.findCell(e.pos-o),a=r.findCell(A.pos-o),l=e.node(0);return s.top<=a.top?(s.top>0&&(e=l.resolve(o+r.map[s.left])),a.bottom<r.height&&(A=l.resolve(o+r.map[r.width*(r.height-1)+a.right-1]))):(a.top>0&&(A=l.resolve(o+r.map[a.left])),s.bottom<r.height&&(e=l.resolve(o+r.map[r.width*(r.height-1)+s.right-1]))),new CellSelection(e,A)}isRowSelection(){const e=this.$anchorCell.node(-1),A=TableMap.get(e),n=this.$anchorCell.start(-1),r=A.colCount(this.$anchorCell.pos-n),o=A.colCount(this.$headCell.pos-n);if(Math.min(r,o)>0)return!1;const s=r+this.$anchorCell.nodeAfter.attrs.colspan,a=o+this.$headCell.nodeAfter.attrs.colspan;return Math.max(s,a)==A.width}eq(e){return e instanceof CellSelection&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,A=e){const n=e.node(-1),r=TableMap.get(n),o=e.start(-1),s=r.findCell(e.pos-o),a=r.findCell(A.pos-o),l=e.node(0);return s.left<=a.left?(s.left>0&&(e=l.resolve(o+r.map[s.top*r.width])),a.right<r.width&&(A=l.resolve(o+r.map[r.width*(a.top+1)-1]))):(a.left>0&&(A=l.resolve(o+r.map[a.top*r.width])),s.right<r.width&&(e=l.resolve(o+r.map[r.width*(s.top+1)-1]))),new CellSelection(e,A)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(e,A){return new CellSelection(e.resolve(A.anchor),e.resolve(A.head))}static create(e,A,n=A){return new CellSelection(e.resolve(A),e.resolve(n))}getBookmark(){return new CellBookmark(this.$anchorCell.pos,this.$headCell.pos)}}CellSelection.prototype.visible=!1;Selection.jsonID("cell",CellSelection);class CellBookmark{constructor(e,A){this.anchor=e,this.head=A}map(e){return new CellBookmark(e.map(this.anchor),e.map(this.head))}resolve(e){const A=e.resolve(this.anchor),n=e.resolve(this.head);return A.parent.type.spec.tableRole=="row"&&n.parent.type.spec.tableRole=="row"&&A.index()<A.parent.childCount&&n.index()<n.parent.childCount&&inSameTable(A,n)?new CellSelection(A,n):Selection.near(n,1)}}function drawCellSelection(t){if(!(t.selection instanceof CellSelection))return null;const e=[];return t.selection.forEachCell((A,n)=>{e.push(Decoration.node(n,n+A.nodeSize,{class:"selectedCell"}))}),DecorationSet.create(t.doc,e)}function isCellBoundarySelection({$from:t,$to:e}){if(t.pos==e.pos||t.pos<e.pos-6)return!1;let A=t.pos,n=e.pos,r=t.depth;for(;r>=0&&!(t.after(r+1)<t.end(r));r--,A++);for(let o=e.depth;o>=0&&!(e.before(o+1)>e.start(o));o--,n--);return A==n&&/row|table/.test(t.node(r).type.spec.tableRole)}function isTextSelectionAcrossCells({$from:t,$to:e}){let A,n;for(let r=t.depth;r>0;r--){const o=t.node(r);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){A=o;break}}for(let r=e.depth;r>0;r--){const o=e.node(r);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){n=o;break}}return A!==n&&e.parentOffset===0}function normalizeSelection(t,e,A){const n=(e||t).selection,r=(e||t).doc;let o,s;if(n instanceof NodeSelection&&(s=n.node.type.spec.tableRole)){if(s=="cell"||s=="header_cell")o=CellSelection.create(r,n.from);else if(s=="row"){const a=r.resolve(n.from+1);o=CellSelection.rowSelection(a,a)}else if(!A){const a=TableMap.get(n.node),l=n.from+1,g=l+a.map[a.width*a.height-1];o=CellSelection.create(r,l+1,g)}}else n instanceof TextSelection&&isCellBoundarySelection(n)?o=TextSelection.create(r,n.from):n instanceof TextSelection&&isTextSelectionAcrossCells(n)&&(o=TextSelection.create(r,n.$from.start(),n.$from.end()));return o&&(e||(e=t.tr)).setSelection(o),e}class TableView{constructor(e,A){this.node=e,this.defaultCellMinWidth=A,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.table.style.setProperty("--default-cell-min-width",`${A}px`),this.colgroup=this.table.appendChild(document.createElement("colgroup")),updateColumnsOnResize(e,this.colgroup,this.table,A),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(e){return e.type!=this.node.type?!1:(this.node=e,updateColumnsOnResize(e,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(e){return e.type=="attributes"&&(e.target==this.table||this.colgroup.contains(e.target))}}function updateColumnsOnResize(t,e,A,n,r,o){let s=0,a=!0,l=e.firstChild;const g=t.firstChild;if(g){for(let c=0,I=0;c<g.childCount;c++){const{colspan:d,colwidth:h}=g.child(c).attrs;for(let u=0;u<d;u++,I++){const B=r==I?o:h&&h[u],E=B?B+"px":"";if(s+=B||n,B||(a=!1),l)l.style.width!=E&&(l.style.width=E),l=l.nextSibling;else{const f=document.createElement("col");f.style.width=E,e.appendChild(f)}}}for(;l;){const c=l.nextSibling;l.parentNode?.removeChild(l),l=c}a?(A.style.width=s+"px",A.style.minWidth=""):(A.style.width="",A.style.minWidth=s+"px")}}const columnResizingPluginKey=new PluginKey("tableColumnResizing");function columnResizing({handleWidth:t=5,cellMinWidth:e=25,defaultCellMinWidth:A=100,View:n=TableView,lastColumnResizable:r=!0}={}){const o=new Plugin({key:columnResizingPluginKey,state:{init(s,a){const l=o.spec?.props?.nodeViews,g=tableNodeTypes(a.schema).table.name;return n&&l&&(l[g]=(c,I)=>new n(c,A,I)),new ResizeState(-1,!1)},apply(s,a){return a.apply(s)}},props:{attributes:s=>{const a=columnResizingPluginKey.getState(s);return a&&a.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(s,a)=>{handleMouseMove(s,a,t,r)},mouseleave:s=>{handleMouseLeave(s)},mousedown:(s,a)=>{handleMouseDown$1(s,a,e,A)}},decorations:s=>{const a=columnResizingPluginKey.getState(s);if(a&&a.activeHandle>-1)return handleDecorations(s,a.activeHandle)},nodeViews:{}}});return o}class ResizeState{constructor(e,A){this.activeHandle=e,this.dragging=A}apply(e){const A=e.getMeta(columnResizingPluginKey);if(A&&A.setHandle!=null)return new ResizeState(A.setHandle,!1);if(A&&A.setDragging!==void 0)return new ResizeState(this.activeHandle,A.setDragging);if(this.activeHandle>-1&&e.docChanged){let n=e.mapping.map(this.activeHandle,-1);return pointsAtCell(e.doc.resolve(n))||(n=-1),new ResizeState(n,this.dragging)}return this}}function handleMouseMove(t,e,A,n){if(!t.editable)return;const r=columnResizingPluginKey.getState(t.state);if(r&&!r.dragging){const o=domCellAround(e.target);let s=-1;if(o){const{left:a,right:l}=o.getBoundingClientRect();e.clientX-a<=A?s=edgeCell(t,e,"left",A):l-e.clientX<=A&&(s=edgeCell(t,e,"right",A))}if(s!=r.activeHandle){if(!n&&s!==-1){const a=t.state.doc.resolve(s),l=a.node(-1),g=TableMap.get(l),c=a.start(-1);if(g.colCount(a.pos-c)+a.nodeAfter.attrs.colspan-1==g.width-1)return}updateHandle(t,s)}}}function handleMouseLeave(t){if(!t.editable)return;const e=columnResizingPluginKey.getState(t.state);e&&e.activeHandle>-1&&!e.dragging&&updateHandle(t,-1)}function handleMouseDown$1(t,e,A,n){if(!t.editable)return!1;const r=t.dom.ownerDocument.defaultView||globalThis,o=columnResizingPluginKey.getState(t.state);if(!o||o.activeHandle==-1||o.dragging)return!1;const s=t.state.doc.nodeAt(o.activeHandle),a=currentColWidth(t,o.activeHandle,s.attrs);t.dispatch(t.state.tr.setMeta(columnResizingPluginKey,{setDragging:{startX:e.clientX,startWidth:a}}));function l(c){r.removeEventListener("mouseup",l),r.removeEventListener("mousemove",g);const I=columnResizingPluginKey.getState(t.state);I?.dragging&&(updateColumnWidth(t,I.activeHandle,draggedWidth(I.dragging,c,A)),t.dispatch(t.state.tr.setMeta(columnResizingPluginKey,{setDragging:null})))}function g(c){if(!c.which)return l(c);const I=columnResizingPluginKey.getState(t.state);if(I&&I.dragging){const d=draggedWidth(I.dragging,c,A);displayColumnWidth(t,I.activeHandle,d,n)}}return displayColumnWidth(t,o.activeHandle,a,n),r.addEventListener("mouseup",l),r.addEventListener("mousemove",g),e.preventDefault(),!0}function currentColWidth(t,e,{colspan:A,colwidth:n}){const r=n&&n[n.length-1];if(r)return r;const o=t.domAtPos(e);let a=o.node.childNodes[o.offset].offsetWidth,l=A;if(n)for(let g=0;g<A;g++)n[g]&&(a-=n[g],l--);return a/l}function domCellAround(t){for(;t&&t.nodeName!="TD"&&t.nodeName!="TH";)t=t.classList&&t.classList.contains("ProseMirror")?null:t.parentNode;return t}function edgeCell(t,e,A,n){const r=A=="right"?-n:n,o=t.posAtCoords({left:e.clientX+r,top:e.clientY});if(!o)return-1;const{pos:s}=o,a=cellAround(t.state.doc.resolve(s));if(!a)return-1;if(A=="right")return a.pos;const l=TableMap.get(a.node(-1)),g=a.start(-1),c=l.map.indexOf(a.pos-g);return c%l.width==0?-1:g+l.map[c-1]}function draggedWidth(t,e,A){const n=e.clientX-t.startX;return Math.max(A,t.startWidth+n)}function updateHandle(t,e){t.dispatch(t.state.tr.setMeta(columnResizingPluginKey,{setHandle:e}))}function updateColumnWidth(t,e,A){const n=t.state.doc.resolve(e),r=n.node(-1),o=TableMap.get(r),s=n.start(-1),a=o.colCount(n.pos-s)+n.nodeAfter.attrs.colspan-1,l=t.state.tr;for(let g=0;g<o.height;g++){const c=g*o.width+a;if(g&&o.map[c]==o.map[c-o.width])continue;const I=o.map[c],d=r.nodeAt(I).attrs,h=d.colspan==1?0:a-o.colCount(I);if(d.colwidth&&d.colwidth[h]==A)continue;const u=d.colwidth?d.colwidth.slice():zeroes(d.colspan);u[h]=A,l.setNodeMarkup(s+I,null,{...d,colwidth:u})}l.docChanged&&t.dispatch(l)}function displayColumnWidth(t,e,A,n){const r=t.state.doc.resolve(e),o=r.node(-1),s=r.start(-1),a=TableMap.get(o).colCount(r.pos-s)+r.nodeAfter.attrs.colspan-1;let l=t.domAtPos(r.start(-1)).node;for(;l&&l.nodeName!="TABLE";)l=l.parentNode;l&&updateColumnsOnResize(o,l.firstChild,l,n,a,A)}function zeroes(t){return Array(t).fill(0)}function handleDecorations(t,e){const A=[],n=t.doc.resolve(e),r=n.node(-1);if(!r)return DecorationSet.empty;const o=TableMap.get(r),s=n.start(-1),a=o.colCount(n.pos-s)+n.nodeAfter.attrs.colspan-1;for(let l=0;l<o.height;l++){const g=a+l*o.width;if((a==o.width-1||o.map[g]!=o.map[g+1])&&(l==0||o.map[g]!=o.map[g-o.width])){const c=o.map[g],I=s+c+r.nodeAt(c).nodeSize-1,d=document.createElement("div");d.className="column-resize-handle",columnResizingPluginKey.getState(t)?.dragging&&A.push(Decoration.node(s+c,s+c+r.nodeAt(c).nodeSize,{class:"column-resize-dragging"})),A.push(Decoration.widget(I,d))}}return DecorationSet.create(t.doc,A)}const fixTablesKey=new PluginKey("fix-tables");function changedDescendants(t,e,A,n){const r=t.childCount,o=e.childCount;e:for(let s=0,a=0;s<o;s++){const l=e.child(s);for(let g=a,c=Math.min(r,s+3);g<c;g++)if(t.child(g)==l){a=g+1,A+=l.nodeSize;continue e}n(l,A),a<r&&t.child(a).sameMarkup(l)?changedDescendants(t.child(a),l,A+1,n):l.nodesBetween(0,l.content.size,n,A+1),A+=l.nodeSize}}function fixTables(t,e){let A;const n=(r,o)=>{r.type.spec.tableRole=="table"&&(A=fixTable(t,r,o,A))};return e?e.doc!=t.doc&&changedDescendants(e.doc,t.doc,0,n):t.doc.descendants(n),A}function fixTable(t,e,A,n){const r=TableMap.get(e);if(!r.problems)return n;n||(n=t.tr);const o=[];for(let l=0;l<r.height;l++)o.push(0);for(let l=0;l<r.problems.length;l++){const g=r.problems[l];if(g.type=="collision"){const c=e.nodeAt(g.pos);if(!c)continue;const I=c.attrs;for(let d=0;d<I.rowspan;d++)o[g.row+d]+=g.n;n.setNodeMarkup(n.mapping.map(A+1+g.pos),null,removeColSpan(I,I.colspan-g.n,g.n))}else if(g.type=="missing")o[g.row]+=g.n;else if(g.type=="overlong_rowspan"){const c=e.nodeAt(g.pos);if(!c)continue;n.setNodeMarkup(n.mapping.map(A+1+g.pos),null,{...c.attrs,rowspan:c.attrs.rowspan-g.n})}else if(g.type=="colwidth mismatch"){const c=e.nodeAt(g.pos);if(!c)continue;n.setNodeMarkup(n.mapping.map(A+1+g.pos),null,{...c.attrs,colwidth:g.colwidth})}else if(g.type=="zero_sized"){const c=n.mapping.map(A);n.delete(c,c+e.nodeSize)}}let s,a;for(let l=0;l<o.length;l++)o[l]&&(s==null&&(s=l),a=l);for(let l=0,g=A+1;l<r.height;l++){const c=e.child(l),I=g+c.nodeSize,d=o[l];if(d>0){let h="cell";c.firstChild&&(h=c.firstChild.type.spec.tableRole);const u=[];for(let E=0;E<d;E++){const f=tableNodeTypes(t.schema)[h].createAndFill();f&&u.push(f)}const B=(l==0||s==l-1)&&a==l?g+1:I-1;n.insert(n.mapping.map(B),u)}g=I}return n.setMeta(fixTablesKey,{fixTables:!0})}function selectedRect(t){const e=t.selection,A=selectionCell(t),n=A.node(-1),r=A.start(-1),o=TableMap.get(n);return{...e instanceof CellSelection?o.rectBetween(e.$anchorCell.pos-r,e.$headCell.pos-r):o.findCell(A.pos-r),tableStart:r,map:o,table:n}}function addColumn(t,{map:e,tableStart:A,table:n},r){let o=r>0?-1:0;columnIsHeader(e,n,r+o)&&(o=r==0||r==e.width?null:0);for(let s=0;s<e.height;s++){const a=s*e.width+r;if(r>0&&r<e.width&&e.map[a-1]==e.map[a]){const l=e.map[a],g=n.nodeAt(l);t.setNodeMarkup(t.mapping.map(A+l),null,addColSpan(g.attrs,r-e.colCount(l))),s+=g.attrs.rowspan-1}else{const l=o==null?tableNodeTypes(n.type.schema).cell:n.nodeAt(e.map[a+o]).type,g=e.positionAt(s,r,n);t.insert(t.mapping.map(A+g),l.createAndFill())}}return t}function addColumnBefore(t,e){if(!isInTable(t))return!1;if(e){const A=selectedRect(t);e(addColumn(t.tr,A,A.left))}return!0}function addColumnAfter(t,e){if(!isInTable(t))return!1;if(e){const A=selectedRect(t);e(addColumn(t.tr,A,A.right))}return!0}function removeColumn(t,{map:e,table:A,tableStart:n},r){const o=t.mapping.maps.length;for(let s=0;s<e.height;){const a=s*e.width+r,l=e.map[a],g=A.nodeAt(l),c=g.attrs;if(r>0&&e.map[a-1]==l||r<e.width-1&&e.map[a+1]==l)t.setNodeMarkup(t.mapping.slice(o).map(n+l),null,removeColSpan(c,r-e.colCount(l)));else{const I=t.mapping.slice(o).map(n+l);t.delete(I,I+g.nodeSize)}s+=c.rowspan}}function deleteColumn(t,e){if(!isInTable(t))return!1;if(e){const A=selectedRect(t),n=t.tr;if(A.left==0&&A.right==A.map.width)return!1;for(let r=A.right-1;removeColumn(n,A,r),r!=A.left;r--){const o=A.tableStart?n.doc.nodeAt(A.tableStart-1):n.doc;if(!o)throw RangeError("No table found");A.table=o,A.map=TableMap.get(o)}e(n)}return!0}function rowIsHeader(t,e,A){const n=tableNodeTypes(e.type.schema).header_cell;for(let r=0;r<t.width;r++)if(e.nodeAt(t.map[r+A*t.width])?.type!=n)return!1;return!0}function addRow(t,{map:e,tableStart:A,table:n},r){let o=A;for(let l=0;l<r;l++)o+=n.child(l).nodeSize;const s=[];let a=r>0?-1:0;rowIsHeader(e,n,r+a)&&(a=r==0||r==e.height?null:0);for(let l=0,g=e.width*r;l<e.width;l++,g++)if(r>0&&r<e.height&&e.map[g]==e.map[g-e.width]){const c=e.map[g],I=n.nodeAt(c).attrs;t.setNodeMarkup(A+c,null,{...I,rowspan:I.rowspan+1}),l+=I.colspan-1}else{const I=(a==null?tableNodeTypes(n.type.schema).cell:n.nodeAt(e.map[g+a*e.width])?.type)?.createAndFill();I&&s.push(I)}return t.insert(o,tableNodeTypes(n.type.schema).row.create(null,s)),t}function addRowBefore(t,e){if(!isInTable(t))return!1;if(e){const A=selectedRect(t);e(addRow(t.tr,A,A.top))}return!0}function addRowAfter(t,e){if(!isInTable(t))return!1;if(e){const A=selectedRect(t);e(addRow(t.tr,A,A.bottom))}return!0}function removeRow(t,{map:e,table:A,tableStart:n},r){let o=0;for(let g=0;g<r;g++)o+=A.child(g).nodeSize;const s=o+A.child(r).nodeSize,a=t.mapping.maps.length;t.delete(o+n,s+n);const l=new Set;for(let g=0,c=r*e.width;g<e.width;g++,c++){const I=e.map[c];if(!l.has(I)){if(l.add(I),r>0&&I==e.map[c-e.width]){const d=A.nodeAt(I).attrs;t.setNodeMarkup(t.mapping.slice(a).map(I+n),null,{...d,rowspan:d.rowspan-1}),g+=d.colspan-1}else if(r<e.height&&I==e.map[c+e.width]){const d=A.nodeAt(I),h=d.attrs,u=d.type.create({...h,rowspan:d.attrs.rowspan-1},d.content),B=e.positionAt(r+1,g,A);t.insert(t.mapping.slice(a).map(n+B),u),g+=h.colspan-1}}}}function deleteRow(t,e){if(!isInTable(t))return!1;if(e){const A=selectedRect(t),n=t.tr;if(A.top==0&&A.bottom==A.map.height)return!1;for(let r=A.bottom-1;removeRow(n,A,r),r!=A.top;r--){const o=A.tableStart?n.doc.nodeAt(A.tableStart-1):n.doc;if(!o)throw RangeError("No table found");A.table=o,A.map=TableMap.get(A.table)}e(n)}return!0}function isEmpty(t){const e=t.content;return e.childCount==1&&e.child(0).isTextblock&&e.child(0).childCount==0}function cellsOverlapRectangle({width:t,height:e,map:A},n){let r=n.top*t+n.left,o=r,s=(n.bottom-1)*t+n.left,a=r+(n.right-n.left-1);for(let l=n.top;l<n.bottom;l++){if(n.left>0&&A[o]==A[o-1]||n.right<t&&A[a]==A[a+1])return!0;o+=t,a+=t}for(let l=n.left;l<n.right;l++){if(n.top>0&&A[r]==A[r-t]||n.bottom<e&&A[s]==A[s+t])return!0;r++,s++}return!1}function mergeCells(t,e){const A=t.selection;if(!(A instanceof CellSelection)||A.$anchorCell.pos==A.$headCell.pos)return!1;const n=selectedRect(t),{map:r}=n;if(cellsOverlapRectangle(r,n))return!1;if(e){const o=t.tr,s={};let a=Fragment.empty,l,g;for(let c=n.top;c<n.bottom;c++)for(let I=n.left;I<n.right;I++){const d=r.map[c*r.width+I],h=n.table.nodeAt(d);if(!(s[d]||!h))if(s[d]=!0,l==null)l=d,g=h;else{isEmpty(h)||(a=a.append(h.content));const u=o.mapping.map(d+n.tableStart);o.delete(u,u+h.nodeSize)}}if(l==null||g==null)return!0;if(o.setNodeMarkup(l+n.tableStart,null,{...addColSpan(g.attrs,g.attrs.colspan,n.right-n.left-g.attrs.colspan),rowspan:n.bottom-n.top}),a.size){const c=l+1+g.content.size,I=isEmpty(g)?l+1:c;o.replaceWith(I+n.tableStart,c+n.tableStart,a)}o.setSelection(new CellSelection(o.doc.resolve(l+n.tableStart))),e(o)}return!0}function splitCell(t,e){const A=tableNodeTypes(t.schema);return splitCellWithType(({node:n})=>A[n.type.spec.tableRole])(t,e)}const splitCellWithType=t=>(e,A)=>{const n=e.selection;let r,o;if(n instanceof CellSelection){if(n.$anchorCell.pos!=n.$headCell.pos)return!1;r=n.$anchorCell.nodeAfter,o=n.$anchorCell.pos}else{if(r=cellWrapping(n.$from),!r)return!1;o=cellAround(n.$from)?.pos}if(r==null||o==null||r.attrs.colspan==1&&r.attrs.rowspan==1)return!1;if(A){let s=r.attrs;const a=[],l=s.colwidth;s.rowspan>1&&(s={...s,rowspan:1}),s.colspan>1&&(s={...s,colspan:1});const g=selectedRect(e),c=e.tr;for(let d=0;d<g.right-g.left;d++)a.push(l?{...s,colwidth:l&&l[d]?[l[d]]:null}:s);let I;for(let d=g.top;d<g.bottom;d++){let h=g.map.positionAt(d,g.left,g.table);d==g.top&&(h+=r.nodeSize);for(let u=g.left,B=0;u<g.right;u++,B++)u==g.left&&d==g.top||c.insert(I=c.mapping.map(h+g.tableStart,1),t({node:r,row:d,col:u}).createAndFill(a[B]))}c.setNodeMarkup(o,t({node:r,row:g.top,col:g.left}),a[0]),n instanceof CellSelection&&c.setSelection(new CellSelection(c.doc.resolve(n.$anchorCell.pos),I?c.doc.resolve(I):void 0)),A(c)}return!0},setCellAttr=(t,e)=>function(A,n){if(!isInTable(A))return!1;const r=selectionCell(A);if(r.nodeAfter.attrs[t]===e)return!1;if(n){const o=A.tr;A.selection instanceof CellSelection?A.selection.forEachCell((s,a)=>{s.attrs[t]!==e&&o.setNodeMarkup(a,null,{...s.attrs,[t]:e})}):o.setNodeMarkup(r.pos,null,{...r.nodeAfter.attrs,[t]:e}),n(o)}return!0};function deprecated_toggleHeader(t){return function(e,A){if(!isInTable(e))return!1;if(A){const n=tableNodeTypes(e.schema),r=selectedRect(e),o=e.tr,s=r.map.cellsInRect(t=="column"?{left:r.left,top:0,right:r.right,bottom:r.map.height}:t=="row"?{left:0,top:r.top,right:r.map.width,bottom:r.bottom}:r),a=s.map(l=>r.table.nodeAt(l));for(let l=0;l<s.length;l++)a[l].type==n.header_cell&&o.setNodeMarkup(r.tableStart+s[l],n.cell,a[l].attrs);if(o.steps.length==0)for(let l=0;l<s.length;l++)o.setNodeMarkup(r.tableStart+s[l],n.header_cell,a[l].attrs);A(o)}return!0}}function isHeaderEnabledByType(t,e,A){const n=e.map.cellsInRect({left:0,top:0,right:t=="row"?e.map.width:1,bottom:t=="column"?e.map.height:1});for(let r=0;r<n.length;r++){const o=e.table.nodeAt(n[r]);if(o&&o.type!==A.header_cell)return!1}return!0}const toggleHeader=(t,e)=>(e=e||{useDeprecatedLogic:!1},e.useDeprecatedLogic?deprecated_toggleHeader(t):function(A,n){if(!isInTable(A))return!1;if(n){const r=tableNodeTypes(A.schema),o=selectedRect(A),s=A.tr,a=isHeaderEnabledByType("row",o,r),l=isHeaderEnabledByType("column",o,r),c=(t==="column"?a:t==="row"?l:!1)?1:0,I=t=="column"?{left:0,top:c,right:1,bottom:o.map.height}:t=="row"?{left:c,top:0,right:o.map.width,bottom:1}:o,d=t=="column"?l?r.cell:r.header_cell:t=="row"?a?r.cell:r.header_cell:r.cell;o.map.cellsInRect(I).forEach(h=>{const u=h+o.tableStart,B=s.doc.nodeAt(u);B&&s.setNodeMarkup(u,d,B.attrs)}),n(s)}return!0}),toggleHeaderRow=toggleHeader("row",{useDeprecatedLogic:!0}),toggleHeaderColumn=toggleHeader("column",{useDeprecatedLogic:!0}),toggleHeaderCell=toggleHeader("cell",{useDeprecatedLogic:!0});function findNextCell(t,e){if(e<0){const A=t.nodeBefore;if(A)return t.pos-A.nodeSize;for(let n=t.index(-1)-1,r=t.before();n>=0;n--){const o=t.node(-1).child(n),s=o.lastChild;if(s)return r-1-s.nodeSize;r-=o.nodeSize}}else{if(t.index()<t.parent.childCount-1)return t.pos+t.nodeAfter.nodeSize;const A=t.node(-1);for(let n=t.indexAfter(-1),r=t.after();n<A.childCount;n++){const o=A.child(n);if(o.childCount)return r+1;r+=o.nodeSize}}return null}const goToNextCell=t=>function(e,A){if(!isInTable(e))return!1;const n=findNextCell(selectionCell(e),t);if(n==null)return!1;if(A){const r=e.doc.resolve(n);A(e.tr.setSelection(TextSelection.between(r,moveCellForward(r))).scrollIntoView())}return!0};function deleteTable(t,e){const A=t.selection.$anchor;for(let n=A.depth;n>0;n--)if(A.node(n).type.spec.tableRole=="table")return e&&e(t.tr.delete(A.before(n),A.after(n)).scrollIntoView()),!0;return!1}function deleteCellSelection(t,e){const A=t.selection;if(!(A instanceof CellSelection))return!1;if(e){const n=t.tr,r=tableNodeTypes(t.schema).cell.createAndFill().content;A.forEachCell((o,s)=>{o.content.eq(r)||n.replace(n.mapping.map(s+1),n.mapping.map(s+o.nodeSize-1),new Slice(r,0,0))}),n.docChanged&&e(n)}return!0}function pastedCells(t){if(!t.size)return null;let{content:e,openStart:A,openEnd:n}=t;for(;e.childCount==1&&(A>0&&n>0||e.child(0).type.spec.tableRole=="table");)A--,n--,e=e.child(0).content;const r=e.child(0),o=r.type.spec.tableRole,s=r.type.schema,a=[];if(o=="row")for(let l=0;l<e.childCount;l++){let g=e.child(l).content;const c=l?0:Math.max(0,A-1),I=l<e.childCount-1?0:Math.max(0,n-1);(c||I)&&(g=fitSlice(tableNodeTypes(s).row,new Slice(g,c,I)).content),a.push(g)}else if(o=="cell"||o=="header_cell")a.push(A||n?fitSlice(tableNodeTypes(s).row,new Slice(e,A,n)).content:e);else return null;return ensureRectangular(s,a)}function ensureRectangular(t,e){const A=[];for(let r=0;r<e.length;r++){const o=e[r];for(let s=o.childCount-1;s>=0;s--){const{rowspan:a,colspan:l}=o.child(s).attrs;for(let g=r;g<r+a;g++)A[g]=(A[g]||0)+l}}let n=0;for(let r=0;r<A.length;r++)n=Math.max(n,A[r]);for(let r=0;r<A.length;r++)if(r>=e.length&&e.push(Fragment.empty),A[r]<n){const o=tableNodeTypes(t).cell.createAndFill(),s=[];for(let a=A[r];a<n;a++)s.push(o);e[r]=e[r].append(Fragment.from(s))}return{height:e.length,width:n,rows:e}}function fitSlice(t,e){const A=t.createAndFill();return new Transform(A).replace(0,A.content.size,e).doc}function clipCells({width:t,height:e,rows:A},n,r){if(t!=n){const o=[],s=[];for(let a=0;a<A.length;a++){const l=A[a],g=[];for(let c=o[a]||0,I=0;c<n;I++){let d=l.child(I%l.childCount);c+d.attrs.colspan>n&&(d=d.type.createChecked(removeColSpan(d.attrs,d.attrs.colspan,c+d.attrs.colspan-n),d.content)),g.push(d),c+=d.attrs.colspan;for(let h=1;h<d.attrs.rowspan;h++)o[a+h]=(o[a+h]||0)+d.attrs.colspan}s.push(Fragment.from(g))}A=s,t=n}if(e!=r){const o=[];for(let s=0,a=0;s<r;s++,a++){const l=[],g=A[a%e];for(let c=0;c<g.childCount;c++){let I=g.child(c);s+I.attrs.rowspan>r&&(I=I.type.create({...I.attrs,rowspan:Math.max(1,r-I.attrs.rowspan)},I.content)),l.push(I)}o.push(Fragment.from(l))}A=o,e=r}return{width:t,height:e,rows:A}}function growTable(t,e,A,n,r,o,s){const a=t.doc.type.schema,l=tableNodeTypes(a);let g,c;if(r>e.width)for(let I=0,d=0;I<e.height;I++){const h=A.child(I);d+=h.nodeSize;const u=[];let B;h.lastChild==null||h.lastChild.type==l.cell?B=g||(g=l.cell.createAndFill()):B=c||(c=l.header_cell.createAndFill());for(let E=e.width;E<r;E++)u.push(B);t.insert(t.mapping.slice(s).map(d-1+n),u)}if(o>e.height){const I=[];for(let u=0,B=(e.height-1)*e.width;u<Math.max(e.width,r);u++){const E=u>=e.width?!1:A.nodeAt(e.map[B+u]).type==l.header_cell;I.push(E?c||(c=l.header_cell.createAndFill()):g||(g=l.cell.createAndFill()))}const d=l.row.create(null,Fragment.from(I)),h=[];for(let u=e.height;u<o;u++)h.push(d);t.insert(t.mapping.slice(s).map(n+A.nodeSize-2),h)}return!!(g||c)}function isolateHorizontal(t,e,A,n,r,o,s,a){if(s==0||s==e.height)return!1;let l=!1;for(let g=r;g<o;g++){const c=s*e.width+g,I=e.map[c];if(e.map[c-e.width]==I){l=!0;const d=A.nodeAt(I),{top:h,left:u}=e.findCell(I);t.setNodeMarkup(t.mapping.slice(a).map(I+n),null,{...d.attrs,rowspan:s-h}),t.insert(t.mapping.slice(a).map(e.positionAt(s,u,A)),d.type.createAndFill({...d.attrs,rowspan:h+d.attrs.rowspan-s})),g+=d.attrs.colspan-1}}return l}function isolateVertical(t,e,A,n,r,o,s,a){if(s==0||s==e.width)return!1;let l=!1;for(let g=r;g<o;g++){const c=g*e.width+s,I=e.map[c];if(e.map[c-1]==I){l=!0;const d=A.nodeAt(I),h=e.colCount(I),u=t.mapping.slice(a).map(I+n);t.setNodeMarkup(u,null,removeColSpan(d.attrs,s-h,d.attrs.colspan-(s-h))),t.insert(u+d.nodeSize,d.type.createAndFill(removeColSpan(d.attrs,0,s-h))),g+=d.attrs.rowspan-1}}return l}function insertCells(t,e,A,n,r){let o=A?t.doc.nodeAt(A-1):t.doc;if(!o)throw new Error("No table found");let s=TableMap.get(o);const{top:a,left:l}=n,g=l+r.width,c=a+r.height,I=t.tr;let d=0;function h(){if(o=A?I.doc.nodeAt(A-1):I.doc,!o)throw new Error("No table found");s=TableMap.get(o),d=I.mapping.maps.length}growTable(I,s,o,A,g,c,d)&&h(),isolateHorizontal(I,s,o,A,l,g,a,d)&&h(),isolateHorizontal(I,s,o,A,l,g,c,d)&&h(),isolateVertical(I,s,o,A,a,c,l,d)&&h(),isolateVertical(I,s,o,A,a,c,g,d)&&h();for(let u=a;u<c;u++){const B=s.positionAt(u,l,o),E=s.positionAt(u,g,o);I.replace(I.mapping.slice(d).map(B+A),I.mapping.slice(d).map(E+A),new Slice(r.rows[u-a],0,0))}h(),I.setSelection(new CellSelection(I.doc.resolve(A+s.positionAt(a,l,o)),I.doc.resolve(A+s.positionAt(c-1,g-1,o)))),e(I)}const handleKeyDown=keydownHandler({ArrowLeft:arrow("horiz",-1),ArrowRight:arrow("horiz",1),"Shift-ArrowLeft":shiftArrow("horiz",-1),"Shift-ArrowRight":shiftArrow("horiz",1),"Shift-ArrowUp":shiftArrow("vert",-1),"Shift-ArrowDown":shiftArrow("vert",1),Backspace:deleteCellSelection,"Mod-Backspace":deleteCellSelection,Delete:deleteCellSelection,"Mod-Delete":deleteCellSelection});function maybeSetSelection(t,e,A){return A.eq(t.selection)?!1:(e&&e(t.tr.setSelection(A).scrollIntoView()),!0)}function arrow(t,e){return(A,n,r)=>{if(!r)return!1;const o=A.selection;return o instanceof CellSelection?maybeSetSelection(A,n,Selection.near(o.$headCell,e)):atEndOfCell(r,t,e)==null?!1:maybeSetSelection(A,n,Selection.near(A.doc.resolve(o.head+e),e))}}function shiftArrow(t,e){return(A,n,r)=>{if(!r)return!1;const o=A.selection;let s;if(o instanceof CellSelection)s=o;else{const l=atEndOfCell(r,t,e);if(l==null)return!1;s=new CellSelection(A.doc.resolve(l))}const a=nextCell(s.$headCell,t,e);return a?maybeSetSelection(A,n,new CellSelection(s.$anchorCell,a)):!1}}function handleTripleClick(t,e){const A=t.state.doc,n=cellAround(A.resolve(e));return n?(t.dispatch(t.state.tr.setSelection(new CellSelection(n))),!0):!1}function handlePaste(t,e,A){if(!isInTable(t.state))return!1;let n=pastedCells(A);const r=t.state.selection;if(r instanceof CellSelection){n||(n={width:1,height:1,rows:[Fragment.from(fitSlice(tableNodeTypes(t.state.schema).cell,A))]});const o=r.$anchorCell.node(-1),s=r.$anchorCell.start(-1),a=TableMap.get(o).rectBetween(r.$anchorCell.pos-s,r.$headCell.pos-s);return n=clipCells(n,a.right-a.left,a.bottom-a.top),insertCells(t.state,t.dispatch,s,a,n),!0}else if(n){const o=selectionCell(t.state),s=o.start(-1);return insertCells(t.state,t.dispatch,s,TableMap.get(o.node(-1)).findCell(o.pos-s),n),!0}else return!1}function handleMouseDown(t,e){if(e.ctrlKey||e.metaKey)return;const A=domInCell(t,e.target);let n;if(e.shiftKey&&t.state.selection instanceof CellSelection)r(t.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&A&&(n=cellAround(t.state.selection.$anchor))!=null&&cellUnderMouse(t,e)?.pos!=n.pos)r(n,e),e.preventDefault();else if(!A)return;function r(a,l){let g=cellUnderMouse(t,l);const c=tableEditingKey.getState(t.state)==null;if(!g||!inSameTable(a,g))if(c)g=a;else return;const I=new CellSelection(a,g);if(c||!t.state.selection.eq(I)){const d=t.state.tr.setSelection(I);c&&d.setMeta(tableEditingKey,a.pos),t.dispatch(d)}}function o(){t.root.removeEventListener("mouseup",o),t.root.removeEventListener("dragstart",o),t.root.removeEventListener("mousemove",s),tableEditingKey.getState(t.state)!=null&&t.dispatch(t.state.tr.setMeta(tableEditingKey,-1))}function s(a){const l=a,g=tableEditingKey.getState(t.state);let c;if(g!=null)c=t.state.doc.resolve(g);else if(domInCell(t,l.target)!=A&&(c=cellUnderMouse(t,e),!c))return o();c&&r(c,l)}t.root.addEventListener("mouseup",o),t.root.addEventListener("dragstart",o),t.root.addEventListener("mousemove",s)}function atEndOfCell(t,e,A){if(!(t.state.selection instanceof TextSelection))return null;const{$head:n}=t.state.selection;for(let r=n.depth-1;r>=0;r--){const o=n.node(r);if((A<0?n.index(r):n.indexAfter(r))!=(A<0?0:o.childCount))return null;if(o.type.spec.tableRole=="cell"||o.type.spec.tableRole=="header_cell"){const a=n.before(r),l=e=="vert"?A>0?"down":"up":A>0?"right":"left";return t.endOfTextblock(l)?a:null}}return null}function domInCell(t,e){for(;e&&e!=t.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function cellUnderMouse(t,e){const A=t.posAtCoords({left:e.clientX,top:e.clientY});return A&&A?cellAround(t.state.doc.resolve(A.pos)):null}function tableEditing({allowTableNodeSelection:t=!1}={}){return new Plugin({key:tableEditingKey,state:{init(){return null},apply(e,A){const n=e.getMeta(tableEditingKey);if(n!=null)return n==-1?null:n;if(A==null||!e.docChanged)return A;const{deleted:r,pos:o}=e.mapping.mapResult(A);return r?null:o}},props:{decorations:drawCellSelection,handleDOMEvents:{mousedown:handleMouseDown},createSelectionBetween(e){return tableEditingKey.getState(e.state)!=null?e.state.selection:null},handleTripleClick,handleKeyDown,handlePaste},appendTransaction(e,A,n){return normalizeSelection(n,fixTables(n,A),t)}})}class NodeTable extends Node$2{constructor(){super(...arguments),this.name="table",this.requires=["doc"],this.attributes={class:{default:"table",fromDom(e){return e.hasAttribute("class")?e.getAttribute("class"):void 0}}}}getNodeSpec(){return{content:"table_row+",tableRole:"table",isolating:!0,group:"block",parseDOM:[{tag:"table",getAttrs:e=>setHtmlAttributes(this,e)}],toDOM:e=>["table",getHtmlAttributes(this,e),["tbody",0]]}}getCommandFactories(e,A){return{addColumnAfter:()=>(r,o)=>addColumnAfter(r,o),addColumnBefore:()=>(r,o)=>addColumnBefore(r,o),addRowAfter:()=>(r,o)=>addRowAfter(r,o),addRowBefore:()=>(r,o)=>addRowBefore(r,o),deleteColumn:()=>(r,o)=>deleteColumn(r,o),deleteRow:()=>(r,o)=>deleteRow(r,o),deleteTable:()=>(r,o)=>deleteTable(r,o),goToNextCell:r=>goToNextCell(r),mergeCells:()=>(r,o)=>mergeCells(r,o),setCellAttr:(...r)=>setCellAttr(...r),splitCell:()=>(r,o)=>splitCell(r,o),toggleHeader:(...r)=>toggleHeader(...r),toggleHeaderCell:()=>(r,o)=>toggleHeaderCell(r,o),toggleHeaderRow:()=>(r,o)=>toggleHeaderRow(r,o),toggleHeaderColumn:()=>(r,o)=>toggleHeaderColumn(r,o),insertTable:({rows:r=3,cols:o=3,withHeaderRow:s=!0}={})=>(a,l)=>{const g=a.tr,c=createTable(e.schema,r,o,s);if(l){const I=g.selection.from+1;g.replaceSelectionWith(c).scrollIntoView().setSelection(TextSelection.near(g.doc.resolve(I)))}return!0},setCellSelection:r=>(o,s)=>{if(s){const a=CellSelection.create(o.doc,r.anchorCell,r.headCell);o.tr.setSelection(a)}return!0}}}getKeyboardShortcuts(){return{}}getProseMirrorPlugins(){return[columnResizing(),tableEditing()]}}class NodeTableRow extends Node$2{constructor(){super(...arguments),this.name="table_row",this.requires=["table"]}getNodeSpec(){return{content:"(table_cell | table_header)*",tableRole:"row",parseDOM:[{tag:"tr"}],toDOM(){return["tr",0]}}}getCommandFactories(e,A){return{}}getKeyboardShortcuts(){return{}}}function getCellAttrs$1(t){if(typeof t=="string")return{};const e=t.getAttribute("data-colwidth"),A=e&&/^\d+(,\d+)*$/.test(e)?e.split(",").map(r=>Number(r)):null,n=Number(t.getAttribute("colspan")||1);return{colspan:n,rowspan:Number(t.getAttribute("rowspan")||1),colwidth:A&&A.length==n?A:null}}function setCellAttrs$1(t){return{colspan:t.attrs.colspan!=1?t.attrs.colspan:void 0,rowspan:t.attrs.rowspan!=1?t.attrs.rowspan:void 0,"data-colwidth":t.attrs.colwidth?.join(",")}}class NodeTableHeader extends Node$2{constructor(){super(...arguments),this.name="table_header",this.requires=["table"]}getNodeSpec(){return{content:"block+",attrs:{colspan:{default:1},rowspan:{default:1},colwidth:{default:void 0}},tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:e=>getCellAttrs$1(e)}],toDOM:e=>["th",setCellAttrs$1(e),0]}}}function getCellAttrs(t){if(typeof t=="string")return{};const e=t.getAttribute("data-colwidth"),A=e&&/^\d+(,\d+)*$/.test(e)?e.split(",").map(r=>Number(r)):null,n=Number(t.getAttribute("colspan")||1);return{colspan:n,rowspan:Number(t.getAttribute("rowspan")||1),colwidth:A&&A.length==n?A:null}}function setCellAttrs(t){return{colspan:t.attrs.colspan!=1?t.attrs.colspan:void 0,rowspan:t.attrs.rowspan!=1?t.attrs.rowspan:void 0,"data-colwidth":t.attrs.colwidth?.join(",")}}class NodeTableCell extends Node$2{constructor(){super(...arguments),this.name="table_cell",this.requires=["table_row"]}getNodeSpec(){return{content:"block+",attrs:{colspan:{default:1},rowspan:{default:1},colwidth:{default:void 0}},tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:e=>getCellAttrs(e)}],toDOM(e){return["td",setCellAttrs(e),0]}}}getCommandFactories(e,A){return{}}getKeyboardShortcuts(){return{}}}class ExtensionTables extends Extension{constructor(){super(...arguments),this.name="extension-tables",this.requires=[new NodeTable,new NodeTableHeader,new NodeTableRow,new NodeTableCell]}}function escapeForRegEx(t){return t.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")}function createDefaultMatcher(t={}){const e=t.char||"@",A=t.allowToIncludeChar||!1,n=t.allowedPrefixes||[" "],r=t.startOfLine||!1;return o=>{const s=t.allowSpaces&&!A,a=escapeForRegEx(e),l=new RegExp(`\\s${a}$`),g=r?"^":"",c=A?"":a,I=s?new RegExp(`${g}${a}.*?(?=\\s${c}|$)`,"gm"):new RegExp(`${g}(?:^)?${a}[^\\s${c}]*`,"gm"),d=o.nodeBefore?.isText&&o.nodeBefore.text;if(!d)return null;const h=o.pos-d.length,u=Array.from(d.matchAll(I)).pop();if(!u||u.input===void 0||u.index===void 0)return null;const B=u.input.slice(Math.max(0,u.index-1),u.index),E=new RegExp(`^[${n?.join("")}\0]?$`).test(B);if(n!==null&&!E)return null;const f=h+u.index;let Q=f+u[0].length;return s&&l.test(d.slice(Q-1,Q+1))&&(u[0]+=" ",Q+=1),f<o.pos&&Q>=o.pos?{range:{from:f,to:Q},query:u[0],text:u[0]}:null}}const CSS_PREFIX="kb-autocomplete";class DefaultRenderer extends EventTarget{constructor(e){super(),this.editor=e,this.items=[],this.pos=-1,this.command=()=>{}}onStart(e){this.command=e.command,this.wrapper&&this.wrapper.parentElement?.removeChild(this.wrapper);const A="root"in this.editor.view?this.editor.view.root:document||document;this.wrapper=document.createElement("ul"),this.wrapper.classList.add(CSS_PREFIX+"__wrapper"),A.appendChild(this.wrapper),this.items.splice(0,this.items.length,...e.items),this.recreateList(e)}onUpdate(e){this.command=e.command,this.items.splice(0,this.items.length,...e.items),this.recreateList(e)}onExit(){this.wrapper&&(this.wrapper.parentNode?.removeChild(this.wrapper),this.wrapper=void 0),this.dispatchEvent(new Event("close")),this.pos=-1}onKeyDown(e){return!this.wrapper||this.items.length===0?!1:e.event.key==="Escape"&&this.wrapper?(this.wrapper.parentNode?.removeChild(this.wrapper),this.wrapper=void 0,!0):e.event.key==="ArrowUp"?(this.pos>-1&&(this.pos=this.pos-1,this.recreateList()),!0):e.event.key==="ArrowDown"?(this.pos<this.items.length-1&&(this.pos++,this.recreateList()),!0):e.event.key==="Enter"&&this.pos>-1&&this.pos<this.items.length?(this.command(this.items[this.pos]),this.items.splice(0,this.items.length),this.onExit(),!0):!1}createListItem(e,A){const n=document.createElement("li");return A===this.pos&&n.classList.add("active"),n.innerText=""+e,n.style.cursor="pointer",n.addEventListener("click",()=>{this.command(e)}),n}recreateList(e){if(!this.wrapper)return;this.wrapper.innerHTML="";for(let n=0;n<this.items.length;n++){const r=this.items[n];this.wrapper.appendChild(this.createListItem(r,n))}this.items.length===0?this.wrapper.style.display="none":this.wrapper.style.display="";const A=e?.clientRect?.();if(A?.height){const n=A.left,r=A.bottom;this.wrapper.style.left=n+"px",this.wrapper.style.top=r+"px"}}}const AutocompletePluginKey=new PluginKey("autocomplete");class AutocompletePlugin extends Plugin{constructor(e,A){let n;const r=e.renderer||new DefaultRenderer(A);super({key:AutocompletePluginKey,view(){return{update:async(o,s)=>{const a=this.key?.getState(s),l=this.key?.getState(o.state),g=a.active&&l.active&&a.range.from!==l.range.from,c=!a.active&&l.active,I=a.active&&!l.active,d=!c&&!I&&a.query!==l.query,h=c||g&&d,u=d||g;let B=I||g&&d;if(!h&&!u&&!B)return;const E=B&&!h?a:l,f=o.dom.querySelector(`[data-decoration-id="${E.decorationId}"]`);if(n={range:E.range,query:E.query,text:E.text,items:[],command:Q=>e.onSelect?e.onSelect(Q,E.range):()=>{},decorationNode:f,clientRect:f?()=>{const{decorationId:Q}=this.key?.getState(A.state);return o.dom.querySelector(`[data-decoration-id="${Q}"]`)?.getBoundingClientRect()||null}:null},h&&r?.onBeforeStart?.(n),u&&r?.onBeforeUpdate?.(n),(u||h)&&e.getItems){try{const Q={state:E,range:E.range,isActive:!0};n.items=await e.getItems(E.query,Q)}catch(Q){if(Q.isLSP)n.items=[],console.error("LSP error config.getItems()",Q.message,e.getItems);else throw Q}n.items.length===0&&(B=!0)}B&&r?.onExit?.(n),u&&r?.onUpdate?.(n),h&&r?.onStart?.(n)},destroy:()=>{n&&r?.onExit?.(n)}}},state:{init(){return{manual:!1,active:!1,range:{from:0,to:0},query:null,text:null,composing:!1}},apply(o,s,a,l){const{composing:c}=A.view,{selection:I}=o,{empty:d,from:h}=I,u={...s},B=o.getMeta(AutocompletePluginKey);if(!B&&!o.isGeneric)return u;if(B?.type==="deactivate")return console.info("Deactivate autocomplete"),u.active=!1,u;if(B?.type==="activate")return console.info("Trigger manual autocomplete"),u.range={from:I.from,to:I.to},u.active=!0,u.manual=!0,u.query=null,u;u.composing=c;const E=I.$anchor.parent;if(!["code_block"].includes(E?.type.name)&&(d||A.view.composing)){(h<s.range.from||h>s.range.to)&&!c&&!s.composing&&(u.active=!1);const f=e.matchers||[createDefaultMatcher()];let Q;for(const m of f)if(Q=m(I.$from),Q)break;const p=`id_${Math.floor(Math.random()*4294967295)}`;Q&&(!e.allow||e.allow({state:l,range:Q.range,isActive:s.active}))?(console.info("Trigger matcher autocomplete",Q),u.active=!0,u.decorationId=s.decorationId?s.decorationId:p,u.range=Q.range,u.query=Q.query,u.text=Q.text):u.active=!1}else u.active=!1;return u.manual=!1,u.active||(u.decorationId=null,u.range={from:0,to:0},u.query=null,u.text=null),u}},props:{handleKeyDown(o,s){const{active:a,range:l}=this.getState(o.state);if(s.key===" "&&s.ctrlKey){const g=o.state.tr.setMeta(AutocompletePluginKey,{type:"activate"});return console.info("Manual autocomplete key"),o.dispatch(g),!0}return a&&r?.onKeyDown?.({view:o,event:s,range:l})||!1},decorations(o){const{active:s,range:a,decorationId:l}=this.getState(o);if(!s)return null;const g=document.createElement("span");return g.className=e.decorationClass||"kb-autocomplete--decor",g.setAttribute("data-decoration-id",l),DecorationSet.create(o.doc,[Decoration.widget(a.from,g)])}}}),r.addEventListener("close",()=>{const o=A.state.tr.setMeta(AutocompletePluginKey,{type:"deactivate"});console.info("Manual autocomplete deactivate"),A.view.dispatch(o)})}}class ExtensionAutocomplete extends Extension{constructor(e){super(e),this.config=e,this.name="autocomplete"}getProseMirrorPlugins(){return[new AutocompletePlugin(this.config,this.editor)]}}class AdvancedEditorKit{constructor(e){this.menu=e}name="advanced-editor";getExtensions(){return[new ExtensionBasicEditor,new ExtensionMarkdown,new ExtensionOdt,new ExtensionTables,new ExtensionDevToolkit,new ExtensionCustomMenu(this.menu),new ExtensionCodeJar,new ExtensionAutocomplete]}}const createAssetLoad=t=>async e=>{const n=t.toString()+"/"+e,r=await fetch(n);if(r.status>=400)throw new Error(`Error fetching ${r.status}`);return new Uint8Array(await r.arrayBuffer())};var GOOD_LEAF_SIZE=200,RopeSequence=function t(){};RopeSequence.prototype.append=function t(e){return e.length?(e=RopeSequence.from(e),!this.length&&e||e.length<GOOD_LEAF_SIZE&&this.leafAppend(e)||this.length<GOOD_LEAF_SIZE&&e.leafPrepend(this)||this.appendInner(e)):this};RopeSequence.prototype.prepend=function t(e){return e.length?RopeSequence.from(e).append(this):this};RopeSequence.prototype.appendInner=function t(e){return new Append(this,e)};RopeSequence.prototype.slice=function t(e,A){return e===void 0&&(e=0),A===void 0&&(A=this.length),e>=A?RopeSequence.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,A))};RopeSequence.prototype.get=function t(e){if(!(e<0||e>=this.length))return this.getInner(e)};RopeSequence.prototype.forEach=function t(e,A,n){A===void 0&&(A=0),n===void 0&&(n=this.length),A<=n?this.forEachInner(e,A,n,0):this.forEachInvertedInner(e,A,n,0)};RopeSequence.prototype.map=function t(e,A,n){A===void 0&&(A=0),n===void 0&&(n=this.length);var r=[];return this.forEach(function(o,s){return r.push(e(o,s))},A,n),r};RopeSequence.from=function t(e){return e instanceof RopeSequence?e:e&&e.length?new Leaf(e):RopeSequence.empty};var Leaf=(function(t){function e(n){t.call(this),this.values=n}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var A={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(r,o){return r==0&&o==this.length?this:new e(this.values.slice(r,o))},e.prototype.getInner=function(r){return this.values[r]},e.prototype.forEachInner=function(r,o,s,a){for(var l=o;l<s;l++)if(r(this.values[l],a+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,o,s,a){for(var l=o-1;l>=s;l--)if(r(this.values[l],a+l)===!1)return!1},e.prototype.leafAppend=function(r){if(this.length+r.length<=GOOD_LEAF_SIZE)return new e(this.values.concat(r.flatten()))},e.prototype.leafPrepend=function(r){if(this.length+r.length<=GOOD_LEAF_SIZE)return new e(r.flatten().concat(this.values))},A.length.get=function(){return this.values.length},A.depth.get=function(){return 0},Object.defineProperties(e.prototype,A),e})(RopeSequence);RopeSequence.empty=new Leaf([]);var Append=(function(t){function e(A,n){t.call(this),this.left=A,this.right=n,this.length=A.length+n.length,this.depth=Math.max(A.depth,n.depth)+1}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(n){return n<this.left.length?this.left.get(n):this.right.get(n-this.left.length)},e.prototype.forEachInner=function(n,r,o,s){var a=this.left.length;if(r<a&&this.left.forEachInner(n,r,Math.min(o,a),s)===!1||o>a&&this.right.forEachInner(n,Math.max(r-a,0),Math.min(this.length,o)-a,s+a)===!1)return!1},e.prototype.forEachInvertedInner=function(n,r,o,s){var a=this.left.length;if(r>a&&this.right.forEachInvertedInner(n,r-a,Math.max(o,a)-a,s+a)===!1||o<a&&this.left.forEachInvertedInner(n,Math.min(r,a),o,s)===!1)return!1},e.prototype.sliceInner=function(n,r){if(n==0&&r==this.length)return this;var o=this.left.length;return r<=o?this.left.slice(n,r):n>=o?this.right.slice(n-o,r-o):this.left.slice(n,o).append(this.right.slice(0,r-o))},e.prototype.leafAppend=function(n){var r=this.right.leafAppend(n);if(r)return new e(this.left,r)},e.prototype.leafPrepend=function(n){var r=this.left.leafPrepend(n);if(r)return new e(r,this.right)},e.prototype.appendInner=function(n){return this.left.depth>=Math.max(this.right.depth,n.depth)+1?new e(this.left,new e(this.right,n)):new e(this,n)},e})(RopeSequence);const max_empty_items=500;class Branch{constructor(e,A){this.items=e,this.eventCount=A}popEvent(e,A){if(this.eventCount==0)return null;let n=this.items.length;for(;;n--)if(this.items.get(n-1).selection){--n;break}let r,o;A&&(r=this.remapping(n,this.items.length),o=r.maps.length);let s=e.tr,a,l,g=[],c=[];return this.items.forEach((I,d)=>{if(!I.step){r||(r=this.remapping(n,d+1),o=r.maps.length),o--,c.push(I);return}if(r){c.push(new Item(I.map));let h=I.step.map(r.slice(o)),u;h&&s.maybeStep(h).doc&&(u=s.mapping.maps[s.mapping.maps.length-1],g.push(new Item(u,void 0,void 0,g.length+c.length))),o--,u&&r.appendMap(u,o)}else s.maybeStep(I.step);if(I.selection)return a=r?I.selection.map(r.slice(o)):I.selection,l=new Branch(this.items.slice(0,n).append(c.reverse().concat(g)),this.eventCount-1),!1},this.items.length,0),{remaining:l,transform:s,selection:a}}addTransform(e,A,n,r){let o=[],s=this.eventCount,a=this.items,l=!r&&a.length?a.get(a.length-1):null;for(let c=0;c<e.steps.length;c++){let I=e.steps[c].invert(e.docs[c]),d=new Item(e.mapping.maps[c],I,A),h;(h=l&&l.merge(d))&&(d=h,c?o.pop():a=a.slice(0,a.length-1)),o.push(d),A&&(s++,A=void 0),r||(l=d)}let g=s-n.depth;return g>DEPTH_OVERFLOW&&(a=cutOffEvents(a,g),s-=g),new Branch(a.append(o),s)}remapping(e,A){let n=new Mapping;return this.items.forEach((r,o)=>{let s=r.mirrorOffset!=null&&o-r.mirrorOffset>=e?n.maps.length-r.mirrorOffset:void 0;n.appendMap(r.map,s)},e,A),n}addMaps(e){return this.eventCount==0?this:new Branch(this.items.append(e.map(A=>new Item(A))),this.eventCount)}rebased(e,A){if(!this.eventCount)return this;let n=[],r=Math.max(0,this.items.length-A),o=e.mapping,s=e.steps.length,a=this.eventCount;this.items.forEach(d=>{d.selection&&a--},r);let l=A;this.items.forEach(d=>{let h=o.getMirror(--l);if(h==null)return;s=Math.min(s,h);let u=o.maps[h];if(d.step){let B=e.steps[h].invert(e.docs[h]),E=d.selection&&d.selection.map(o.slice(l+1,h));E&&a++,n.push(new Item(u,B,E))}else n.push(new Item(u))},r);let g=[];for(let d=A;d<s;d++)g.push(new Item(o.maps[d]));let c=this.items.slice(0,r).append(g).append(n),I=new Branch(c,a);return I.emptyItemCount()>max_empty_items&&(I=I.compress(this.items.length-n.length)),I}emptyItemCount(){let e=0;return this.items.forEach(A=>{A.step||e++}),e}compress(e=this.items.length){let A=this.remapping(0,e),n=A.maps.length,r=[],o=0;return this.items.forEach((s,a)=>{if(a>=e)r.push(s),s.selection&&o++;else if(s.step){let l=s.step.map(A.slice(n)),g=l&&l.getMap();if(n--,g&&A.appendMap(g,n),l){let c=s.selection&&s.selection.map(A.slice(n));c&&o++;let I=new Item(g.invert(),l,c),d,h=r.length-1;(d=r.length&&r[h].merge(I))?r[h]=d:r.push(I)}}else s.map&&n--},this.items.length,0),new Branch(RopeSequence.from(r.reverse()),o)}}Branch.empty=new Branch(RopeSequence.empty,0);function cutOffEvents(t,e){let A;return t.forEach((n,r)=>{if(n.selection&&e--==0)return A=r,!1}),t.slice(A)}class Item{constructor(e,A,n,r){this.map=e,this.step=A,this.selection=n,this.mirrorOffset=r}merge(e){if(this.step&&e.step&&!e.selection){let A=e.step.merge(this.step);if(A)return new Item(A.getMap().invert(),A,this.selection)}}}class HistoryState{constructor(e,A,n,r,o){this.done=e,this.undone=A,this.prevRanges=n,this.prevTime=r,this.prevComposition=o}}const DEPTH_OVERFLOW=20;function applyTransaction(t,e,A,n){let r=A.getMeta(historyKey),o;if(r)return r.historyState;A.getMeta(closeHistoryKey)&&(t=new HistoryState(t.done,t.undone,null,0,-1));let s=A.getMeta("appendedTransaction");if(A.steps.length==0)return t;if(s&&s.getMeta(historyKey))return s.getMeta(historyKey).redo?new HistoryState(t.done.addTransform(A,void 0,n,mustPreserveItems(e)),t.undone,rangesFor(A.mapping.maps),t.prevTime,t.prevComposition):new HistoryState(t.done,t.undone.addTransform(A,void 0,n,mustPreserveItems(e)),null,t.prevTime,t.prevComposition);if(A.getMeta("addToHistory")!==!1&&!(s&&s.getMeta("addToHistory")===!1)){let a=A.getMeta("composition"),l=t.prevTime==0||!s&&t.prevComposition!=a&&(t.prevTime<(A.time||0)-n.newGroupDelay||!isAdjacentTo(A,t.prevRanges)),g=s?mapRanges(t.prevRanges,A.mapping):rangesFor(A.mapping.maps);return new HistoryState(t.done.addTransform(A,l?e.selection.getBookmark():void 0,n,mustPreserveItems(e)),Branch.empty,g,A.time,a??t.prevComposition)}else return(o=A.getMeta("rebased"))?new HistoryState(t.done.rebased(A,o),t.undone.rebased(A,o),mapRanges(t.prevRanges,A.mapping),t.prevTime,t.prevComposition):new HistoryState(t.done.addMaps(A.mapping.maps),t.undone.addMaps(A.mapping.maps),mapRanges(t.prevRanges,A.mapping),t.prevTime,t.prevComposition)}function isAdjacentTo(t,e){if(!e)return!1;if(!t.docChanged)return!0;let A=!1;return t.mapping.maps[0].forEach((n,r)=>{for(let o=0;o<e.length;o+=2)n<=e[o+1]&&r>=e[o]&&(A=!0)}),A}function rangesFor(t){let e=[];for(let A=t.length-1;A>=0&&e.length==0;A--)t[A].forEach((n,r,o,s)=>e.push(o,s));return e}function mapRanges(t,e){if(!t)return null;let A=[];for(let n=0;n<t.length;n+=2){let r=e.map(t[n],1),o=e.map(t[n+1],-1);r<=o&&A.push(r,o)}return A}function histTransaction(t,e,A){let n=mustPreserveItems(e),r=historyKey.get(e).spec.config,o=(A?t.undone:t.done).popEvent(e,n);if(!o)return null;let s=o.selection.resolve(o.transform.doc),a=(A?t.done:t.undone).addTransform(o.transform,e.selection.getBookmark(),r,n),l=new HistoryState(A?a:o.remaining,A?o.remaining:a,null,0,-1);return o.transform.setSelection(s).setMeta(historyKey,{redo:A,historyState:l})}let cachedPreserveItems=!1,cachedPreserveItemsPlugins=null;function mustPreserveItems(t){let e=t.plugins;if(cachedPreserveItemsPlugins!=e){cachedPreserveItems=!1,cachedPreserveItemsPlugins=e;for(let A=0;A<e.length;A++)if(e[A].spec.historyPreserveItems){cachedPreserveItems=!0;break}}return cachedPreserveItems}const historyKey=new PluginKey("history"),closeHistoryKey=new PluginKey("closeHistory");function history$1(t={}){return t={depth:t.depth||100,newGroupDelay:t.newGroupDelay||500},new Plugin({key:historyKey,state:{init(){return new HistoryState(Branch.empty,Branch.empty,null,0,-1)},apply(e,A,n){return applyTransaction(A,n,e,t)}},config:t,props:{handleDOMEvents:{beforeinput(e,A){let n=A.inputType,r=n=="historyUndo"?undo:n=="historyRedo"?redo:null;return r?(A.preventDefault(),r(e.state,e.dispatch)):!1}}}})}function buildCommand(t,e){return(A,n)=>{let r=historyKey.getState(A);if(!r||(t?r.undone:r.done).eventCount==0)return!1;if(n){let o=histTransaction(r,A,t);o&&n(e?o.scrollIntoView():o)}return!0}}const undo=buildCommand(!1,!0),redo=buildCommand(!0,!0);class ExtensionHistory extends Extension{name="history";options={depth:100,newGroupDelay:500};getCommandFactories(e){return{undo:()=>undo,redo:()=>redo}}getKeyboardShortcuts(){const e=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator?.platform):!1,A={"Mod-z":"undo","Mod-y":"redo"};return e||(A["Mod-y"]="redo"),A}getProseMirrorPlugins(){return[history$1(this.options)]}}const __viteBrowserExternal=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));exports.AdvancedEditorKit=AdvancedEditorKit;exports.CoreEditor=CoreEditor;exports.ExtensionHistory=ExtensionHistory;exports.createAssetLoad=createAssetLoad;
|
|
196
|
+
`);const Q=A.text(B),p=A.nodes.code_block.createAndFill({lang:g.attrs.lang},[Q]);p&&(n=n.replaceRangeWith(h,u,p))}a+=I}return e&&e(n),n.docChanged},ANY_LIST=["ordered_list","bullet_list"],fixListsLevels=(t,e)=>{const A=t.doc,n=t.schema,r=n.nodes.bullet_list,o=n.nodes.list_item,s=n.nodes.paragraph,a=t.tr;let l=0,g=[],c=[],I=0;function d(h,u=0,B=0){let E=0;for(let f=0;f<h.length;f++){const Q=h[f];if(!ANY_LIST.includes(Q.type.name))d(Q.children,u+E+1,B+1);else{const p=Q.attrs.odtMarginLeft||0;if(l===0&&(c=[],I=0,g.length>=l))for(let m=0;m<g.length;m++)I<g.length&&p>g[I]&&(c[l+I]=g[I],I++);if(c[l+I]=p,l++,d(Q.children,u+E,B+1),l--,l===0&&!Q.attrs.toc){g=c;for(let m=0;m<I;m++){const y=r.create({type:"none"},o.create(null,Fragment.from([s.create(),Q])));a.replaceWith(a.mapping.map(u+E),a.mapping.map(u+E+Q.nodeSize),y)}}}E+=Q.nodeSize}}return d(A.children),e&&e(a),a.docChanged};function getDefaultsPostProcessFilters({doc:t,filesMap:e}){return[convertCodeParagraphsToCodeBlocks,fixListsLevels,fixContinuedLists,convertMathMl,mergeCodeBlocks]}async function urlRewrite(t,e,A,n){const r=[];A.doc.descendants((a,l)=>{a.type.name==="image"&&r.push({node:a,pos:l})});const o=[];A.doc.descendants((a,l)=>{a.marks.find(g=>g.type.name==="link")&&o.push({node:a,pos:l})});const s=A.tr;for(const{node:a,pos:l}of o){const g=a.marks.find(I=>I.type.name==="link");if(!g)continue;let c=g.attrs.href||"";if(c=await t(c,{type:"A",dest:"kerebron"}),c!==g.attrs.href){const I=a.marks.map(u=>u.type.name==="link"?A.schema.marks.link.create({...u.attrs,href:c}):u),d=A.schema.nodes[a.type.name];let h;d.isText?h=A.schema.text(a.text||"",I):h=d.create(a.attrs,a.content,I),s.replaceWith(s.mapping.map(l),s.mapping.map(l+a.nodeSize),h)}}for(const{node:a,pos:l}of r){let g=a.attrs.src||"";if(g=await t(g,{type:"IMG",dest:"kerebron",filesMap:e}),g!==a.attrs.src){const I=A.schema.nodes[a.type.name].create({...a.attrs,src:g},a.content,a.marks);s.replaceWith(s.mapping.map(l),s.mapping.map(l+a.nodeSize),I)}}return n(s),s.docChanged}async function init(t){const e=await Promise.resolve().then(()=>require("./odt_parser.internal-C8Sm3VVG.cjs")),A=await WebAssembly.instantiate(t,{"./odt_parser.internal.js":e});return e.__wbg_set_wasm(A.instance.exports),A.instance.exports.__wbindgen_start(),e.init_debug(),A.instance,e}let odtWasm;class ExtensionOdt extends Extension{constructor(e={}){super(e),this.config=e,this.name="odt"}getConverters(e,A){const n={fromDoc:async r=>{throw new Error("Not implemented")},toDoc:async r=>{const o=e.config.assetLoad;if(!o)throw new Error("No assetLoad");if(!odtWasm){const I=this.config.debug?await o("odt-wasm/odt-parser-debug.wasm"):await o("odt-wasm/odt-parser.wasm");odtWasm=await init(I)}const{doc:s,filesMap:a}=n.odtToJson(r,odtWasm),l=getDefaultsPostProcessFilters({doc:s,filesMap:a}).concat(this.config.postProcessCommands||[]);let g=EditorState.create({doc:s});const c=I=>{g=g.apply(I)};if(this.urlFromRewriter&&await urlRewrite(this.urlFromRewriter,a,g,c),l.length>0)for(const I of l)I(g,d=>c(d));if(this.config.debug){const I=new CustomEvent("odt:pmdoc:filtered",{detail:{doc:g.doc}});this.editor.dispatchEvent(I)}return g.doc},odtToJson:(r,o)=>{const s=o.unzip(r),a={};for(const d of s.keys())a[d]=Uint8Array.from(s.get(d));const l=o.parse_styles(s.get("styles.xml")),g=o.parse_content(s.get("content.xml"));if(this.config.debug){const d=new CustomEvent("odt:parsed",{detail:{stylesTree:l,contentTree:g,filesMap:a}});this.editor.dispatchEvent(d)}const c=new OdtParser(e.schema,this.config);c.filesMap=a;const I=c.parse({...a,contentTree:g,stylesTree:l});if(this.config.debug){const d=new CustomEvent("odt:pmdoc",{detail:{doc:I}});this.editor.dispatchEvent(d)}return{doc:I,stylesTree:l,contentTree:g,filesMap:a}}};return{"application/vnd.oasis.opendocument.text":n}}}function createCell(t,e){return t.createAndFill()}function getTableNodeTypes(t){if(t.cached.tableNodeTypes)return t.cached.tableNodeTypes;const e={};return Object.keys(t.nodes).forEach(A=>{const n=t.nodes[A];n.spec.tableRole&&(e[n.spec.tableRole]=n)}),t.cached.tableNodeTypes=e,e}function createTable(t,e,A,n,r){const o=getTableNodeTypes(t),s=[],a=[];for(let I=0;I<A;I+=1){const d=createCell(o.cell);if(d&&a.push(d),n){const h=createCell(o.header_cell);h&&s.push(h)}}const l=[];for(let I=0;I<e;I+=1)l.push(o.row.createChecked(null,n&&I===0?s:a));const g={},c=t.spec.nodes.get("table");for(const[I,d]of Object.entries(c.attrs||{}))typeof d.default<"u"&&(g[I]=d.default);return o.table.createChecked(g,l)}let readFromCache,addToCache;if(typeof WeakMap<"u"){const t=new WeakMap;readFromCache=e=>t.get(e),addToCache=(e,A)=>(t.set(e,A),A)}else{const t=[];let A=0;readFromCache=n=>{for(let r=0;r<t.length;r+=2)if(t[r]==n)return t[r+1]},addToCache=(n,r)=>(A==10&&(A=0),t[A++]=n,t[A++]=r)}class TableMap{constructor(e,A,n,r){this.width=e,this.height=A,this.map=n,this.problems=r}findCell(e){for(let A=0;A<this.map.length;A++){const n=this.map[A];if(n!=e)continue;const r=A%this.width,o=A/this.width|0;let s=r+1,a=o+1;for(let l=1;s<this.width&&this.map[A+l]==n;l++)s++;for(let l=1;a<this.height&&this.map[A+this.width*l]==n;l++)a++;return{left:r,top:o,right:s,bottom:a}}throw new RangeError(`No cell with offset ${e} found`)}colCount(e){for(let A=0;A<this.map.length;A++)if(this.map[A]==e)return A%this.width;throw new RangeError(`No cell with offset ${e} found`)}nextCell(e,A,n){const{left:r,right:o,top:s,bottom:a}=this.findCell(e);return A=="horiz"?(n<0?r==0:o==this.width)?null:this.map[s*this.width+(n<0?r-1:o)]:(n<0?s==0:a==this.height)?null:this.map[r+this.width*(n<0?s-1:a)]}rectBetween(e,A){const{left:n,right:r,top:o,bottom:s}=this.findCell(e),{left:a,right:l,top:g,bottom:c}=this.findCell(A);return{left:Math.min(n,a),top:Math.min(o,g),right:Math.max(r,l),bottom:Math.max(s,c)}}cellsInRect(e){const A=[],n={};for(let r=e.top;r<e.bottom;r++)for(let o=e.left;o<e.right;o++){const s=r*this.width+o,a=this.map[s];n[a]||(n[a]=!0,!(o==e.left&&o&&this.map[s-1]==a||r==e.top&&r&&this.map[s-this.width]==a)&&A.push(a))}return A}positionAt(e,A,n){for(let r=0,o=0;;r++){const s=o+n.child(r).nodeSize;if(r==e){let a=A+e*this.width;const l=(e+1)*this.width;for(;a<l&&this.map[a]<o;)a++;return a==l?s-1:this.map[a]}o=s}}static get(e){return readFromCache(e)||addToCache(e,computeMap(e))}}function computeMap(t){if(t.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+t.type.name);const e=findWidth(t),A=t.childCount,n=[];let r=0,o=null;const s=[];for(let g=0,c=e*A;g<c;g++)n[g]=0;for(let g=0,c=0;g<A;g++){const I=t.child(g);c++;for(let u=0;;u++){for(;r<n.length&&n[r]!=0;)r++;if(u==I.childCount)break;const B=I.child(u),{colspan:E,rowspan:f,colwidth:Q}=B.attrs;for(let p=0;p<f;p++){if(p+g>=A){(o||(o=[])).push({type:"overlong_rowspan",pos:c,n:f-p});break}const m=r+p*e;for(let y=0;y<E;y++){n[m+y]==0?n[m+y]=c:(o||(o=[])).push({type:"collision",row:g,pos:c,n:E-y});const w=Q&&Q[y];if(w){const D=(m+y)%e*2,_=s[D];_==null||_!=w&&s[D+1]==1?(s[D]=w,s[D+1]=1):_==w&&s[D+1]++}}}r+=E,c+=B.nodeSize}const d=(g+1)*e;let h=0;for(;r<d;)n[r++]==0&&h++;h&&(o||(o=[])).push({type:"missing",row:g,n:h}),c++}(e===0||A===0)&&(o||(o=[])).push({type:"zero_sized"});const a=new TableMap(e,A,n,o);let l=!1;for(let g=0;!l&&g<s.length;g+=2)s[g]!=null&&s[g+1]<A&&(l=!0);return l&&findBadColWidths(a,s,t),a}function findWidth(t){let e=-1,A=!1;for(let n=0;n<t.childCount;n++){const r=t.child(n);let o=0;if(A)for(let s=0;s<n;s++){const a=t.child(s);for(let l=0;l<a.childCount;l++){const g=a.child(l);s+g.attrs.rowspan>n&&(o+=g.attrs.colspan)}}for(let s=0;s<r.childCount;s++){const a=r.child(s);o+=a.attrs.colspan,a.attrs.rowspan>1&&(A=!0)}e==-1?e=o:e!=o&&(e=Math.max(e,o))}return e}function findBadColWidths(t,e,A){t.problems||(t.problems=[]);const n={};for(let r=0;r<t.map.length;r++){const o=t.map[r];if(n[o])continue;n[o]=!0;const s=A.nodeAt(o);if(!s)throw new RangeError(`No cell with offset ${o} found`);let a=null;const l=s.attrs;for(let g=0;g<l.colspan;g++){const c=(r+g)%t.width,I=e[c*2];I!=null&&(!l.colwidth||l.colwidth[g]!=I)&&((a||(a=freshColWidth(l)))[g]=I)}a&&t.problems.unshift({type:"colwidth mismatch",pos:o,colwidth:a})}}function freshColWidth(t){if(t.colwidth)return t.colwidth.slice();const e=[];for(let A=0;A<t.colspan;A++)e.push(0);return e}function tableNodeTypes(t){let e=t.cached.tableNodeTypes;if(!e){e=t.cached.tableNodeTypes={};for(const A in t.nodes){const n=t.nodes[A],r=n.spec.tableRole;r&&(e[r]=n)}}return e}const tableEditingKey=new PluginKey("selectingCells");function cellAround(t){for(let e=t.depth-1;e>0;e--)if(t.node(e).type.spec.tableRole=="row")return t.node(0).resolve(t.before(e+1));return null}function cellWrapping(t){for(let e=t.depth;e>0;e--){const A=t.node(e).type.spec.tableRole;if(A==="cell"||A==="header_cell")return t.node(e)}return null}function isInTable(t){const e=t.selection.$head;for(let A=e.depth;A>0;A--)if(e.node(A).type.spec.tableRole=="row")return!0;return!1}function selectionCell(t){const e=t.selection;if("$anchorCell"in e&&e.$anchorCell)return e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell;if("node"in e&&e.node&&e.node.type.spec.tableRole=="cell")return e.$anchor;const A=cellAround(e.$head)||cellNear(e.$head);if(A)return A;throw new RangeError(`No cell found around position ${e.head}`)}function cellNear(t){for(let e=t.nodeAfter,A=t.pos;e;e=e.firstChild,A++){const n=e.type.spec.tableRole;if(n=="cell"||n=="header_cell")return t.doc.resolve(A)}for(let e=t.nodeBefore,A=t.pos;e;e=e.lastChild,A--){const n=e.type.spec.tableRole;if(n=="cell"||n=="header_cell")return t.doc.resolve(A-e.nodeSize)}}function pointsAtCell(t){return t.parent.type.spec.tableRole=="row"&&!!t.nodeAfter}function moveCellForward(t){return t.node(0).resolve(t.pos+t.nodeAfter.nodeSize)}function inSameTable(t,e){return t.depth==e.depth&&t.pos>=e.start(-1)&&t.pos<=e.end(-1)}function nextCell(t,e,A){const n=t.node(-1),r=TableMap.get(n),o=t.start(-1),s=r.nextCell(t.pos-o,e,A);return s==null?null:t.node(0).resolve(o+s)}function removeColSpan(t,e,A=1){const n={...t,colspan:t.colspan-A};return n.colwidth&&(n.colwidth=n.colwidth.slice(),n.colwidth.splice(e,A),n.colwidth.some(r=>r>0)||(n.colwidth=null)),n}function addColSpan(t,e,A=1){const n={...t,colspan:t.colspan+A};if(n.colwidth){n.colwidth=n.colwidth.slice();for(let r=0;r<A;r++)n.colwidth.splice(e,0,0)}return n}function columnIsHeader(t,e,A){const n=tableNodeTypes(e.type.schema).header_cell;for(let r=0;r<t.height;r++)if(e.nodeAt(t.map[A+r*t.width]).type!=n)return!1;return!0}class CellSelection extends Selection{constructor(e,A=e){const n=e.node(-1),r=TableMap.get(n),o=e.start(-1),s=r.rectBetween(e.pos-o,A.pos-o),a=e.node(0),l=r.cellsInRect(s).filter(c=>c!=A.pos-o);l.unshift(A.pos-o);const g=l.map(c=>{const I=n.nodeAt(c);if(!I)throw RangeError(`No cell with offset ${c} found`);const d=o+c+1;return new SelectionRange(a.resolve(d),a.resolve(d+I.content.size))});super(g[0].$from,g[0].$to,g),this.$anchorCell=e,this.$headCell=A}map(e,A){const n=e.resolve(A.map(this.$anchorCell.pos)),r=e.resolve(A.map(this.$headCell.pos));if(pointsAtCell(n)&&pointsAtCell(r)&&inSameTable(n,r)){const o=this.$anchorCell.node(-1)!=n.node(-1);return o&&this.isRowSelection()?CellSelection.rowSelection(n,r):o&&this.isColSelection()?CellSelection.colSelection(n,r):new CellSelection(n,r)}return TextSelection.between(n,r)}content(){const e=this.$anchorCell.node(-1),A=TableMap.get(e),n=this.$anchorCell.start(-1),r=A.rectBetween(this.$anchorCell.pos-n,this.$headCell.pos-n),o={},s=[];for(let l=r.top;l<r.bottom;l++){const g=[];for(let c=l*A.width+r.left,I=r.left;I<r.right;I++,c++){const d=A.map[c];if(o[d])continue;o[d]=!0;const h=A.findCell(d);let u=e.nodeAt(d);if(!u)throw RangeError(`No cell with offset ${d} found`);const B=r.left-h.left,E=h.right-r.right;if(B>0||E>0){let f=u.attrs;if(B>0&&(f=removeColSpan(f,0,B)),E>0&&(f=removeColSpan(f,f.colspan-E,E)),h.left<r.left){if(u=u.type.createAndFill(f),!u)throw RangeError(`Could not create cell with attrs ${JSON.stringify(f)}`)}else u=u.type.create(f,u.content)}if(h.top<r.top||h.bottom>r.bottom){const f={...u.attrs,rowspan:Math.min(h.bottom,r.bottom)-Math.max(h.top,r.top)};h.top<r.top?u=u.type.createAndFill(f):u=u.type.create(f,u.content)}g.push(u)}s.push(e.child(l).copy(Fragment.from(g)))}const a=this.isColSelection()&&this.isRowSelection()?e:s;return new Slice(Fragment.from(a),1,1)}replace(e,A=Slice.empty){const n=e.steps.length,r=this.ranges;for(let s=0;s<r.length;s++){const{$from:a,$to:l}=r[s],g=e.mapping.slice(n);e.replace(g.map(a.pos),g.map(l.pos),s?Slice.empty:A)}const o=Selection.findFrom(e.doc.resolve(e.mapping.slice(n).map(this.to)),-1);o&&e.setSelection(o)}replaceWith(e,A){this.replace(e,new Slice(Fragment.from(A),0,0))}forEachCell(e){const A=this.$anchorCell.node(-1),n=TableMap.get(A),r=this.$anchorCell.start(-1),o=n.cellsInRect(n.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r));for(let s=0;s<o.length;s++)e(A.nodeAt(o[s]),r+o[s])}isColSelection(){const e=this.$anchorCell.index(-1),A=this.$headCell.index(-1);if(Math.min(e,A)>0)return!1;const n=e+this.$anchorCell.nodeAfter.attrs.rowspan,r=A+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(n,r)==this.$headCell.node(-1).childCount}static colSelection(e,A=e){const n=e.node(-1),r=TableMap.get(n),o=e.start(-1),s=r.findCell(e.pos-o),a=r.findCell(A.pos-o),l=e.node(0);return s.top<=a.top?(s.top>0&&(e=l.resolve(o+r.map[s.left])),a.bottom<r.height&&(A=l.resolve(o+r.map[r.width*(r.height-1)+a.right-1]))):(a.top>0&&(A=l.resolve(o+r.map[a.left])),s.bottom<r.height&&(e=l.resolve(o+r.map[r.width*(r.height-1)+s.right-1]))),new CellSelection(e,A)}isRowSelection(){const e=this.$anchorCell.node(-1),A=TableMap.get(e),n=this.$anchorCell.start(-1),r=A.colCount(this.$anchorCell.pos-n),o=A.colCount(this.$headCell.pos-n);if(Math.min(r,o)>0)return!1;const s=r+this.$anchorCell.nodeAfter.attrs.colspan,a=o+this.$headCell.nodeAfter.attrs.colspan;return Math.max(s,a)==A.width}eq(e){return e instanceof CellSelection&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,A=e){const n=e.node(-1),r=TableMap.get(n),o=e.start(-1),s=r.findCell(e.pos-o),a=r.findCell(A.pos-o),l=e.node(0);return s.left<=a.left?(s.left>0&&(e=l.resolve(o+r.map[s.top*r.width])),a.right<r.width&&(A=l.resolve(o+r.map[r.width*(a.top+1)-1]))):(a.left>0&&(A=l.resolve(o+r.map[a.top*r.width])),s.right<r.width&&(e=l.resolve(o+r.map[r.width*(s.top+1)-1]))),new CellSelection(e,A)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(e,A){return new CellSelection(e.resolve(A.anchor),e.resolve(A.head))}static create(e,A,n=A){return new CellSelection(e.resolve(A),e.resolve(n))}getBookmark(){return new CellBookmark(this.$anchorCell.pos,this.$headCell.pos)}}CellSelection.prototype.visible=!1;Selection.jsonID("cell",CellSelection);class CellBookmark{constructor(e,A){this.anchor=e,this.head=A}map(e){return new CellBookmark(e.map(this.anchor),e.map(this.head))}resolve(e){const A=e.resolve(this.anchor),n=e.resolve(this.head);return A.parent.type.spec.tableRole=="row"&&n.parent.type.spec.tableRole=="row"&&A.index()<A.parent.childCount&&n.index()<n.parent.childCount&&inSameTable(A,n)?new CellSelection(A,n):Selection.near(n,1)}}function drawCellSelection(t){if(!(t.selection instanceof CellSelection))return null;const e=[];return t.selection.forEachCell((A,n)=>{e.push(Decoration.node(n,n+A.nodeSize,{class:"selectedCell"}))}),DecorationSet.create(t.doc,e)}function isCellBoundarySelection({$from:t,$to:e}){if(t.pos==e.pos||t.pos<e.pos-6)return!1;let A=t.pos,n=e.pos,r=t.depth;for(;r>=0&&!(t.after(r+1)<t.end(r));r--,A++);for(let o=e.depth;o>=0&&!(e.before(o+1)>e.start(o));o--,n--);return A==n&&/row|table/.test(t.node(r).type.spec.tableRole)}function isTextSelectionAcrossCells({$from:t,$to:e}){let A,n;for(let r=t.depth;r>0;r--){const o=t.node(r);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){A=o;break}}for(let r=e.depth;r>0;r--){const o=e.node(r);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){n=o;break}}return A!==n&&e.parentOffset===0}function normalizeSelection(t,e,A){const n=(e||t).selection,r=(e||t).doc;let o,s;if(n instanceof NodeSelection&&(s=n.node.type.spec.tableRole)){if(s=="cell"||s=="header_cell")o=CellSelection.create(r,n.from);else if(s=="row"){const a=r.resolve(n.from+1);o=CellSelection.rowSelection(a,a)}else if(!A){const a=TableMap.get(n.node),l=n.from+1,g=l+a.map[a.width*a.height-1];o=CellSelection.create(r,l+1,g)}}else n instanceof TextSelection&&isCellBoundarySelection(n)?o=TextSelection.create(r,n.from):n instanceof TextSelection&&isTextSelectionAcrossCells(n)&&(o=TextSelection.create(r,n.$from.start(),n.$from.end()));return o&&(e||(e=t.tr)).setSelection(o),e}class TableView{constructor(e,A){this.node=e,this.defaultCellMinWidth=A,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.table.style.setProperty("--default-cell-min-width",`${A}px`),this.colgroup=this.table.appendChild(document.createElement("colgroup")),updateColumnsOnResize(e,this.colgroup,this.table,A),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(e){return e.type!=this.node.type?!1:(this.node=e,updateColumnsOnResize(e,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(e){return e.type=="attributes"&&(e.target==this.table||this.colgroup.contains(e.target))}}function updateColumnsOnResize(t,e,A,n,r,o){let s=0,a=!0,l=e.firstChild;const g=t.firstChild;if(g){for(let c=0,I=0;c<g.childCount;c++){const{colspan:d,colwidth:h}=g.child(c).attrs;for(let u=0;u<d;u++,I++){const B=r==I?o:h&&h[u],E=B?B+"px":"";if(s+=B||n,B||(a=!1),l)l.style.width!=E&&(l.style.width=E),l=l.nextSibling;else{const f=document.createElement("col");f.style.width=E,e.appendChild(f)}}}for(;l;){const c=l.nextSibling;l.parentNode?.removeChild(l),l=c}a?(A.style.width=s+"px",A.style.minWidth=""):(A.style.width="",A.style.minWidth=s+"px")}}const columnResizingPluginKey=new PluginKey("tableColumnResizing");function columnResizing({handleWidth:t=5,cellMinWidth:e=25,defaultCellMinWidth:A=100,View:n=TableView,lastColumnResizable:r=!0}={}){const o=new Plugin({key:columnResizingPluginKey,state:{init(s,a){const l=o.spec?.props?.nodeViews,g=tableNodeTypes(a.schema).table.name;return n&&l&&(l[g]=(c,I)=>new n(c,A,I)),new ResizeState(-1,!1)},apply(s,a){return a.apply(s)}},props:{attributes:s=>{const a=columnResizingPluginKey.getState(s);return a&&a.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(s,a)=>{handleMouseMove(s,a,t,r)},mouseleave:s=>{handleMouseLeave(s)},mousedown:(s,a)=>{handleMouseDown$1(s,a,e,A)}},decorations:s=>{const a=columnResizingPluginKey.getState(s);if(a&&a.activeHandle>-1)return handleDecorations(s,a.activeHandle)},nodeViews:{}}});return o}class ResizeState{constructor(e,A){this.activeHandle=e,this.dragging=A}apply(e){const A=e.getMeta(columnResizingPluginKey);if(A&&A.setHandle!=null)return new ResizeState(A.setHandle,!1);if(A&&A.setDragging!==void 0)return new ResizeState(this.activeHandle,A.setDragging);if(this.activeHandle>-1&&e.docChanged){let n=e.mapping.map(this.activeHandle,-1);return pointsAtCell(e.doc.resolve(n))||(n=-1),new ResizeState(n,this.dragging)}return this}}function handleMouseMove(t,e,A,n){if(!t.editable)return;const r=columnResizingPluginKey.getState(t.state);if(r&&!r.dragging){const o=domCellAround(e.target);let s=-1;if(o){const{left:a,right:l}=o.getBoundingClientRect();e.clientX-a<=A?s=edgeCell(t,e,"left",A):l-e.clientX<=A&&(s=edgeCell(t,e,"right",A))}if(s!=r.activeHandle){if(!n&&s!==-1){const a=t.state.doc.resolve(s),l=a.node(-1),g=TableMap.get(l),c=a.start(-1);if(g.colCount(a.pos-c)+a.nodeAfter.attrs.colspan-1==g.width-1)return}updateHandle(t,s)}}}function handleMouseLeave(t){if(!t.editable)return;const e=columnResizingPluginKey.getState(t.state);e&&e.activeHandle>-1&&!e.dragging&&updateHandle(t,-1)}function handleMouseDown$1(t,e,A,n){if(!t.editable)return!1;const r=t.dom.ownerDocument.defaultView||globalThis,o=columnResizingPluginKey.getState(t.state);if(!o||o.activeHandle==-1||o.dragging)return!1;const s=t.state.doc.nodeAt(o.activeHandle),a=currentColWidth(t,o.activeHandle,s.attrs);t.dispatch(t.state.tr.setMeta(columnResizingPluginKey,{setDragging:{startX:e.clientX,startWidth:a}}));function l(c){r.removeEventListener("mouseup",l),r.removeEventListener("mousemove",g);const I=columnResizingPluginKey.getState(t.state);I?.dragging&&(updateColumnWidth(t,I.activeHandle,draggedWidth(I.dragging,c,A)),t.dispatch(t.state.tr.setMeta(columnResizingPluginKey,{setDragging:null})))}function g(c){if(!c.which)return l(c);const I=columnResizingPluginKey.getState(t.state);if(I&&I.dragging){const d=draggedWidth(I.dragging,c,A);displayColumnWidth(t,I.activeHandle,d,n)}}return displayColumnWidth(t,o.activeHandle,a,n),r.addEventListener("mouseup",l),r.addEventListener("mousemove",g),e.preventDefault(),!0}function currentColWidth(t,e,{colspan:A,colwidth:n}){const r=n&&n[n.length-1];if(r)return r;const o=t.domAtPos(e);let a=o.node.childNodes[o.offset].offsetWidth,l=A;if(n)for(let g=0;g<A;g++)n[g]&&(a-=n[g],l--);return a/l}function domCellAround(t){for(;t&&t.nodeName!="TD"&&t.nodeName!="TH";)t=t.classList&&t.classList.contains("ProseMirror")?null:t.parentNode;return t}function edgeCell(t,e,A,n){const r=A=="right"?-n:n,o=t.posAtCoords({left:e.clientX+r,top:e.clientY});if(!o)return-1;const{pos:s}=o,a=cellAround(t.state.doc.resolve(s));if(!a)return-1;if(A=="right")return a.pos;const l=TableMap.get(a.node(-1)),g=a.start(-1),c=l.map.indexOf(a.pos-g);return c%l.width==0?-1:g+l.map[c-1]}function draggedWidth(t,e,A){const n=e.clientX-t.startX;return Math.max(A,t.startWidth+n)}function updateHandle(t,e){t.dispatch(t.state.tr.setMeta(columnResizingPluginKey,{setHandle:e}))}function updateColumnWidth(t,e,A){const n=t.state.doc.resolve(e),r=n.node(-1),o=TableMap.get(r),s=n.start(-1),a=o.colCount(n.pos-s)+n.nodeAfter.attrs.colspan-1,l=t.state.tr;for(let g=0;g<o.height;g++){const c=g*o.width+a;if(g&&o.map[c]==o.map[c-o.width])continue;const I=o.map[c],d=r.nodeAt(I).attrs,h=d.colspan==1?0:a-o.colCount(I);if(d.colwidth&&d.colwidth[h]==A)continue;const u=d.colwidth?d.colwidth.slice():zeroes(d.colspan);u[h]=A,l.setNodeMarkup(s+I,null,{...d,colwidth:u})}l.docChanged&&t.dispatch(l)}function displayColumnWidth(t,e,A,n){const r=t.state.doc.resolve(e),o=r.node(-1),s=r.start(-1),a=TableMap.get(o).colCount(r.pos-s)+r.nodeAfter.attrs.colspan-1;let l=t.domAtPos(r.start(-1)).node;for(;l&&l.nodeName!="TABLE";)l=l.parentNode;l&&updateColumnsOnResize(o,l.firstChild,l,n,a,A)}function zeroes(t){return Array(t).fill(0)}function handleDecorations(t,e){const A=[],n=t.doc.resolve(e),r=n.node(-1);if(!r)return DecorationSet.empty;const o=TableMap.get(r),s=n.start(-1),a=o.colCount(n.pos-s)+n.nodeAfter.attrs.colspan-1;for(let l=0;l<o.height;l++){const g=a+l*o.width;if((a==o.width-1||o.map[g]!=o.map[g+1])&&(l==0||o.map[g]!=o.map[g-o.width])){const c=o.map[g],I=s+c+r.nodeAt(c).nodeSize-1,d=document.createElement("div");d.className="column-resize-handle",columnResizingPluginKey.getState(t)?.dragging&&A.push(Decoration.node(s+c,s+c+r.nodeAt(c).nodeSize,{class:"column-resize-dragging"})),A.push(Decoration.widget(I,d))}}return DecorationSet.create(t.doc,A)}const fixTablesKey=new PluginKey("fix-tables");function changedDescendants(t,e,A,n){const r=t.childCount,o=e.childCount;e:for(let s=0,a=0;s<o;s++){const l=e.child(s);for(let g=a,c=Math.min(r,s+3);g<c;g++)if(t.child(g)==l){a=g+1,A+=l.nodeSize;continue e}n(l,A),a<r&&t.child(a).sameMarkup(l)?changedDescendants(t.child(a),l,A+1,n):l.nodesBetween(0,l.content.size,n,A+1),A+=l.nodeSize}}function fixTables(t,e){let A;const n=(r,o)=>{r.type.spec.tableRole=="table"&&(A=fixTable(t,r,o,A))};return e?e.doc!=t.doc&&changedDescendants(e.doc,t.doc,0,n):t.doc.descendants(n),A}function fixTable(t,e,A,n){const r=TableMap.get(e);if(!r.problems)return n;n||(n=t.tr);const o=[];for(let l=0;l<r.height;l++)o.push(0);for(let l=0;l<r.problems.length;l++){const g=r.problems[l];if(g.type=="collision"){const c=e.nodeAt(g.pos);if(!c)continue;const I=c.attrs;for(let d=0;d<I.rowspan;d++)o[g.row+d]+=g.n;n.setNodeMarkup(n.mapping.map(A+1+g.pos),null,removeColSpan(I,I.colspan-g.n,g.n))}else if(g.type=="missing")o[g.row]+=g.n;else if(g.type=="overlong_rowspan"){const c=e.nodeAt(g.pos);if(!c)continue;n.setNodeMarkup(n.mapping.map(A+1+g.pos),null,{...c.attrs,rowspan:c.attrs.rowspan-g.n})}else if(g.type=="colwidth mismatch"){const c=e.nodeAt(g.pos);if(!c)continue;n.setNodeMarkup(n.mapping.map(A+1+g.pos),null,{...c.attrs,colwidth:g.colwidth})}else if(g.type=="zero_sized"){const c=n.mapping.map(A);n.delete(c,c+e.nodeSize)}}let s,a;for(let l=0;l<o.length;l++)o[l]&&(s==null&&(s=l),a=l);for(let l=0,g=A+1;l<r.height;l++){const c=e.child(l),I=g+c.nodeSize,d=o[l];if(d>0){let h="cell";c.firstChild&&(h=c.firstChild.type.spec.tableRole);const u=[];for(let E=0;E<d;E++){const f=tableNodeTypes(t.schema)[h].createAndFill();f&&u.push(f)}const B=(l==0||s==l-1)&&a==l?g+1:I-1;n.insert(n.mapping.map(B),u)}g=I}return n.setMeta(fixTablesKey,{fixTables:!0})}function selectedRect(t){const e=t.selection,A=selectionCell(t),n=A.node(-1),r=A.start(-1),o=TableMap.get(n);return{...e instanceof CellSelection?o.rectBetween(e.$anchorCell.pos-r,e.$headCell.pos-r):o.findCell(A.pos-r),tableStart:r,map:o,table:n}}function addColumn(t,{map:e,tableStart:A,table:n},r){let o=r>0?-1:0;columnIsHeader(e,n,r+o)&&(o=r==0||r==e.width?null:0);for(let s=0;s<e.height;s++){const a=s*e.width+r;if(r>0&&r<e.width&&e.map[a-1]==e.map[a]){const l=e.map[a],g=n.nodeAt(l);t.setNodeMarkup(t.mapping.map(A+l),null,addColSpan(g.attrs,r-e.colCount(l))),s+=g.attrs.rowspan-1}else{const l=o==null?tableNodeTypes(n.type.schema).cell:n.nodeAt(e.map[a+o]).type,g=e.positionAt(s,r,n);t.insert(t.mapping.map(A+g),l.createAndFill())}}return t}function addColumnBefore(t,e){if(!isInTable(t))return!1;if(e){const A=selectedRect(t);e(addColumn(t.tr,A,A.left))}return!0}function addColumnAfter(t,e){if(!isInTable(t))return!1;if(e){const A=selectedRect(t);e(addColumn(t.tr,A,A.right))}return!0}function removeColumn(t,{map:e,table:A,tableStart:n},r){const o=t.mapping.maps.length;for(let s=0;s<e.height;){const a=s*e.width+r,l=e.map[a],g=A.nodeAt(l),c=g.attrs;if(r>0&&e.map[a-1]==l||r<e.width-1&&e.map[a+1]==l)t.setNodeMarkup(t.mapping.slice(o).map(n+l),null,removeColSpan(c,r-e.colCount(l)));else{const I=t.mapping.slice(o).map(n+l);t.delete(I,I+g.nodeSize)}s+=c.rowspan}}function deleteColumn(t,e){if(!isInTable(t))return!1;if(e){const A=selectedRect(t),n=t.tr;if(A.left==0&&A.right==A.map.width)return!1;for(let r=A.right-1;removeColumn(n,A,r),r!=A.left;r--){const o=A.tableStart?n.doc.nodeAt(A.tableStart-1):n.doc;if(!o)throw RangeError("No table found");A.table=o,A.map=TableMap.get(o)}e(n)}return!0}function rowIsHeader(t,e,A){const n=tableNodeTypes(e.type.schema).header_cell;for(let r=0;r<t.width;r++)if(e.nodeAt(t.map[r+A*t.width])?.type!=n)return!1;return!0}function addRow(t,{map:e,tableStart:A,table:n},r){let o=A;for(let l=0;l<r;l++)o+=n.child(l).nodeSize;const s=[];let a=r>0?-1:0;rowIsHeader(e,n,r+a)&&(a=r==0||r==e.height?null:0);for(let l=0,g=e.width*r;l<e.width;l++,g++)if(r>0&&r<e.height&&e.map[g]==e.map[g-e.width]){const c=e.map[g],I=n.nodeAt(c).attrs;t.setNodeMarkup(A+c,null,{...I,rowspan:I.rowspan+1}),l+=I.colspan-1}else{const I=(a==null?tableNodeTypes(n.type.schema).cell:n.nodeAt(e.map[g+a*e.width])?.type)?.createAndFill();I&&s.push(I)}return t.insert(o,tableNodeTypes(n.type.schema).row.create(null,s)),t}function addRowBefore(t,e){if(!isInTable(t))return!1;if(e){const A=selectedRect(t);e(addRow(t.tr,A,A.top))}return!0}function addRowAfter(t,e){if(!isInTable(t))return!1;if(e){const A=selectedRect(t);e(addRow(t.tr,A,A.bottom))}return!0}function removeRow(t,{map:e,table:A,tableStart:n},r){let o=0;for(let g=0;g<r;g++)o+=A.child(g).nodeSize;const s=o+A.child(r).nodeSize,a=t.mapping.maps.length;t.delete(o+n,s+n);const l=new Set;for(let g=0,c=r*e.width;g<e.width;g++,c++){const I=e.map[c];if(!l.has(I)){if(l.add(I),r>0&&I==e.map[c-e.width]){const d=A.nodeAt(I).attrs;t.setNodeMarkup(t.mapping.slice(a).map(I+n),null,{...d,rowspan:d.rowspan-1}),g+=d.colspan-1}else if(r<e.height&&I==e.map[c+e.width]){const d=A.nodeAt(I),h=d.attrs,u=d.type.create({...h,rowspan:d.attrs.rowspan-1},d.content),B=e.positionAt(r+1,g,A);t.insert(t.mapping.slice(a).map(n+B),u),g+=h.colspan-1}}}}function deleteRow(t,e){if(!isInTable(t))return!1;if(e){const A=selectedRect(t),n=t.tr;if(A.top==0&&A.bottom==A.map.height)return!1;for(let r=A.bottom-1;removeRow(n,A,r),r!=A.top;r--){const o=A.tableStart?n.doc.nodeAt(A.tableStart-1):n.doc;if(!o)throw RangeError("No table found");A.table=o,A.map=TableMap.get(A.table)}e(n)}return!0}function isEmpty(t){const e=t.content;return e.childCount==1&&e.child(0).isTextblock&&e.child(0).childCount==0}function cellsOverlapRectangle({width:t,height:e,map:A},n){let r=n.top*t+n.left,o=r,s=(n.bottom-1)*t+n.left,a=r+(n.right-n.left-1);for(let l=n.top;l<n.bottom;l++){if(n.left>0&&A[o]==A[o-1]||n.right<t&&A[a]==A[a+1])return!0;o+=t,a+=t}for(let l=n.left;l<n.right;l++){if(n.top>0&&A[r]==A[r-t]||n.bottom<e&&A[s]==A[s+t])return!0;r++,s++}return!1}function mergeCells(t,e){const A=t.selection;if(!(A instanceof CellSelection)||A.$anchorCell.pos==A.$headCell.pos)return!1;const n=selectedRect(t),{map:r}=n;if(cellsOverlapRectangle(r,n))return!1;if(e){const o=t.tr,s={};let a=Fragment.empty,l,g;for(let c=n.top;c<n.bottom;c++)for(let I=n.left;I<n.right;I++){const d=r.map[c*r.width+I],h=n.table.nodeAt(d);if(!(s[d]||!h))if(s[d]=!0,l==null)l=d,g=h;else{isEmpty(h)||(a=a.append(h.content));const u=o.mapping.map(d+n.tableStart);o.delete(u,u+h.nodeSize)}}if(l==null||g==null)return!0;if(o.setNodeMarkup(l+n.tableStart,null,{...addColSpan(g.attrs,g.attrs.colspan,n.right-n.left-g.attrs.colspan),rowspan:n.bottom-n.top}),a.size){const c=l+1+g.content.size,I=isEmpty(g)?l+1:c;o.replaceWith(I+n.tableStart,c+n.tableStart,a)}o.setSelection(new CellSelection(o.doc.resolve(l+n.tableStart))),e(o)}return!0}function splitCell(t,e){const A=tableNodeTypes(t.schema);return splitCellWithType(({node:n})=>A[n.type.spec.tableRole])(t,e)}const splitCellWithType=t=>(e,A)=>{const n=e.selection;let r,o;if(n instanceof CellSelection){if(n.$anchorCell.pos!=n.$headCell.pos)return!1;r=n.$anchorCell.nodeAfter,o=n.$anchorCell.pos}else{if(r=cellWrapping(n.$from),!r)return!1;o=cellAround(n.$from)?.pos}if(r==null||o==null||r.attrs.colspan==1&&r.attrs.rowspan==1)return!1;if(A){let s=r.attrs;const a=[],l=s.colwidth;s.rowspan>1&&(s={...s,rowspan:1}),s.colspan>1&&(s={...s,colspan:1});const g=selectedRect(e),c=e.tr;for(let d=0;d<g.right-g.left;d++)a.push(l?{...s,colwidth:l&&l[d]?[l[d]]:null}:s);let I;for(let d=g.top;d<g.bottom;d++){let h=g.map.positionAt(d,g.left,g.table);d==g.top&&(h+=r.nodeSize);for(let u=g.left,B=0;u<g.right;u++,B++)u==g.left&&d==g.top||c.insert(I=c.mapping.map(h+g.tableStart,1),t({node:r,row:d,col:u}).createAndFill(a[B]))}c.setNodeMarkup(o,t({node:r,row:g.top,col:g.left}),a[0]),n instanceof CellSelection&&c.setSelection(new CellSelection(c.doc.resolve(n.$anchorCell.pos),I?c.doc.resolve(I):void 0)),A(c)}return!0},setCellAttr=(t,e)=>function(A,n){if(!isInTable(A))return!1;const r=selectionCell(A);if(r.nodeAfter.attrs[t]===e)return!1;if(n){const o=A.tr;A.selection instanceof CellSelection?A.selection.forEachCell((s,a)=>{s.attrs[t]!==e&&o.setNodeMarkup(a,null,{...s.attrs,[t]:e})}):o.setNodeMarkup(r.pos,null,{...r.nodeAfter.attrs,[t]:e}),n(o)}return!0};function deprecated_toggleHeader(t){return function(e,A){if(!isInTable(e))return!1;if(A){const n=tableNodeTypes(e.schema),r=selectedRect(e),o=e.tr,s=r.map.cellsInRect(t=="column"?{left:r.left,top:0,right:r.right,bottom:r.map.height}:t=="row"?{left:0,top:r.top,right:r.map.width,bottom:r.bottom}:r),a=s.map(l=>r.table.nodeAt(l));for(let l=0;l<s.length;l++)a[l].type==n.header_cell&&o.setNodeMarkup(r.tableStart+s[l],n.cell,a[l].attrs);if(o.steps.length==0)for(let l=0;l<s.length;l++)o.setNodeMarkup(r.tableStart+s[l],n.header_cell,a[l].attrs);A(o)}return!0}}function isHeaderEnabledByType(t,e,A){const n=e.map.cellsInRect({left:0,top:0,right:t=="row"?e.map.width:1,bottom:t=="column"?e.map.height:1});for(let r=0;r<n.length;r++){const o=e.table.nodeAt(n[r]);if(o&&o.type!==A.header_cell)return!1}return!0}const toggleHeader=(t,e)=>(e=e||{useDeprecatedLogic:!1},e.useDeprecatedLogic?deprecated_toggleHeader(t):function(A,n){if(!isInTable(A))return!1;if(n){const r=tableNodeTypes(A.schema),o=selectedRect(A),s=A.tr,a=isHeaderEnabledByType("row",o,r),l=isHeaderEnabledByType("column",o,r),c=(t==="column"?a:t==="row"?l:!1)?1:0,I=t=="column"?{left:0,top:c,right:1,bottom:o.map.height}:t=="row"?{left:c,top:0,right:o.map.width,bottom:1}:o,d=t=="column"?l?r.cell:r.header_cell:t=="row"?a?r.cell:r.header_cell:r.cell;o.map.cellsInRect(I).forEach(h=>{const u=h+o.tableStart,B=s.doc.nodeAt(u);B&&s.setNodeMarkup(u,d,B.attrs)}),n(s)}return!0}),toggleHeaderRow=toggleHeader("row",{useDeprecatedLogic:!0}),toggleHeaderColumn=toggleHeader("column",{useDeprecatedLogic:!0}),toggleHeaderCell=toggleHeader("cell",{useDeprecatedLogic:!0});function findNextCell(t,e){if(e<0){const A=t.nodeBefore;if(A)return t.pos-A.nodeSize;for(let n=t.index(-1)-1,r=t.before();n>=0;n--){const o=t.node(-1).child(n),s=o.lastChild;if(s)return r-1-s.nodeSize;r-=o.nodeSize}}else{if(t.index()<t.parent.childCount-1)return t.pos+t.nodeAfter.nodeSize;const A=t.node(-1);for(let n=t.indexAfter(-1),r=t.after();n<A.childCount;n++){const o=A.child(n);if(o.childCount)return r+1;r+=o.nodeSize}}return null}const goToNextCell=t=>function(e,A){if(!isInTable(e))return!1;const n=findNextCell(selectionCell(e),t);if(n==null)return!1;if(A){const r=e.doc.resolve(n);A(e.tr.setSelection(TextSelection.between(r,moveCellForward(r))).scrollIntoView())}return!0};function deleteTable(t,e){const A=t.selection.$anchor;for(let n=A.depth;n>0;n--)if(A.node(n).type.spec.tableRole=="table")return e&&e(t.tr.delete(A.before(n),A.after(n)).scrollIntoView()),!0;return!1}function deleteCellSelection(t,e){const A=t.selection;if(!(A instanceof CellSelection))return!1;if(e){const n=t.tr,r=tableNodeTypes(t.schema).cell.createAndFill().content;A.forEachCell((o,s)=>{o.content.eq(r)||n.replace(n.mapping.map(s+1),n.mapping.map(s+o.nodeSize-1),new Slice(r,0,0))}),n.docChanged&&e(n)}return!0}function pastedCells(t){if(!t.size)return null;let{content:e,openStart:A,openEnd:n}=t;for(;e.childCount==1&&(A>0&&n>0||e.child(0).type.spec.tableRole=="table");)A--,n--,e=e.child(0).content;const r=e.child(0),o=r.type.spec.tableRole,s=r.type.schema,a=[];if(o=="row")for(let l=0;l<e.childCount;l++){let g=e.child(l).content;const c=l?0:Math.max(0,A-1),I=l<e.childCount-1?0:Math.max(0,n-1);(c||I)&&(g=fitSlice(tableNodeTypes(s).row,new Slice(g,c,I)).content),a.push(g)}else if(o=="cell"||o=="header_cell")a.push(A||n?fitSlice(tableNodeTypes(s).row,new Slice(e,A,n)).content:e);else return null;return ensureRectangular(s,a)}function ensureRectangular(t,e){const A=[];for(let r=0;r<e.length;r++){const o=e[r];for(let s=o.childCount-1;s>=0;s--){const{rowspan:a,colspan:l}=o.child(s).attrs;for(let g=r;g<r+a;g++)A[g]=(A[g]||0)+l}}let n=0;for(let r=0;r<A.length;r++)n=Math.max(n,A[r]);for(let r=0;r<A.length;r++)if(r>=e.length&&e.push(Fragment.empty),A[r]<n){const o=tableNodeTypes(t).cell.createAndFill(),s=[];for(let a=A[r];a<n;a++)s.push(o);e[r]=e[r].append(Fragment.from(s))}return{height:e.length,width:n,rows:e}}function fitSlice(t,e){const A=t.createAndFill();return new Transform(A).replace(0,A.content.size,e).doc}function clipCells({width:t,height:e,rows:A},n,r){if(t!=n){const o=[],s=[];for(let a=0;a<A.length;a++){const l=A[a],g=[];for(let c=o[a]||0,I=0;c<n;I++){let d=l.child(I%l.childCount);c+d.attrs.colspan>n&&(d=d.type.createChecked(removeColSpan(d.attrs,d.attrs.colspan,c+d.attrs.colspan-n),d.content)),g.push(d),c+=d.attrs.colspan;for(let h=1;h<d.attrs.rowspan;h++)o[a+h]=(o[a+h]||0)+d.attrs.colspan}s.push(Fragment.from(g))}A=s,t=n}if(e!=r){const o=[];for(let s=0,a=0;s<r;s++,a++){const l=[],g=A[a%e];for(let c=0;c<g.childCount;c++){let I=g.child(c);s+I.attrs.rowspan>r&&(I=I.type.create({...I.attrs,rowspan:Math.max(1,r-I.attrs.rowspan)},I.content)),l.push(I)}o.push(Fragment.from(l))}A=o,e=r}return{width:t,height:e,rows:A}}function growTable(t,e,A,n,r,o,s){const a=t.doc.type.schema,l=tableNodeTypes(a);let g,c;if(r>e.width)for(let I=0,d=0;I<e.height;I++){const h=A.child(I);d+=h.nodeSize;const u=[];let B;h.lastChild==null||h.lastChild.type==l.cell?B=g||(g=l.cell.createAndFill()):B=c||(c=l.header_cell.createAndFill());for(let E=e.width;E<r;E++)u.push(B);t.insert(t.mapping.slice(s).map(d-1+n),u)}if(o>e.height){const I=[];for(let u=0,B=(e.height-1)*e.width;u<Math.max(e.width,r);u++){const E=u>=e.width?!1:A.nodeAt(e.map[B+u]).type==l.header_cell;I.push(E?c||(c=l.header_cell.createAndFill()):g||(g=l.cell.createAndFill()))}const d=l.row.create(null,Fragment.from(I)),h=[];for(let u=e.height;u<o;u++)h.push(d);t.insert(t.mapping.slice(s).map(n+A.nodeSize-2),h)}return!!(g||c)}function isolateHorizontal(t,e,A,n,r,o,s,a){if(s==0||s==e.height)return!1;let l=!1;for(let g=r;g<o;g++){const c=s*e.width+g,I=e.map[c];if(e.map[c-e.width]==I){l=!0;const d=A.nodeAt(I),{top:h,left:u}=e.findCell(I);t.setNodeMarkup(t.mapping.slice(a).map(I+n),null,{...d.attrs,rowspan:s-h}),t.insert(t.mapping.slice(a).map(e.positionAt(s,u,A)),d.type.createAndFill({...d.attrs,rowspan:h+d.attrs.rowspan-s})),g+=d.attrs.colspan-1}}return l}function isolateVertical(t,e,A,n,r,o,s,a){if(s==0||s==e.width)return!1;let l=!1;for(let g=r;g<o;g++){const c=g*e.width+s,I=e.map[c];if(e.map[c-1]==I){l=!0;const d=A.nodeAt(I),h=e.colCount(I),u=t.mapping.slice(a).map(I+n);t.setNodeMarkup(u,null,removeColSpan(d.attrs,s-h,d.attrs.colspan-(s-h))),t.insert(u+d.nodeSize,d.type.createAndFill(removeColSpan(d.attrs,0,s-h))),g+=d.attrs.rowspan-1}}return l}function insertCells(t,e,A,n,r){let o=A?t.doc.nodeAt(A-1):t.doc;if(!o)throw new Error("No table found");let s=TableMap.get(o);const{top:a,left:l}=n,g=l+r.width,c=a+r.height,I=t.tr;let d=0;function h(){if(o=A?I.doc.nodeAt(A-1):I.doc,!o)throw new Error("No table found");s=TableMap.get(o),d=I.mapping.maps.length}growTable(I,s,o,A,g,c,d)&&h(),isolateHorizontal(I,s,o,A,l,g,a,d)&&h(),isolateHorizontal(I,s,o,A,l,g,c,d)&&h(),isolateVertical(I,s,o,A,a,c,l,d)&&h(),isolateVertical(I,s,o,A,a,c,g,d)&&h();for(let u=a;u<c;u++){const B=s.positionAt(u,l,o),E=s.positionAt(u,g,o);I.replace(I.mapping.slice(d).map(B+A),I.mapping.slice(d).map(E+A),new Slice(r.rows[u-a],0,0))}h(),I.setSelection(new CellSelection(I.doc.resolve(A+s.positionAt(a,l,o)),I.doc.resolve(A+s.positionAt(c-1,g-1,o)))),e(I)}const handleKeyDown=keydownHandler({ArrowLeft:arrow("horiz",-1),ArrowRight:arrow("horiz",1),"Shift-ArrowLeft":shiftArrow("horiz",-1),"Shift-ArrowRight":shiftArrow("horiz",1),"Shift-ArrowUp":shiftArrow("vert",-1),"Shift-ArrowDown":shiftArrow("vert",1),Backspace:deleteCellSelection,"Mod-Backspace":deleteCellSelection,Delete:deleteCellSelection,"Mod-Delete":deleteCellSelection});function maybeSetSelection(t,e,A){return A.eq(t.selection)?!1:(e&&e(t.tr.setSelection(A).scrollIntoView()),!0)}function arrow(t,e){return(A,n,r)=>{if(!r)return!1;const o=A.selection;return o instanceof CellSelection?maybeSetSelection(A,n,Selection.near(o.$headCell,e)):atEndOfCell(r,t,e)==null?!1:maybeSetSelection(A,n,Selection.near(A.doc.resolve(o.head+e),e))}}function shiftArrow(t,e){return(A,n,r)=>{if(!r)return!1;const o=A.selection;let s;if(o instanceof CellSelection)s=o;else{const l=atEndOfCell(r,t,e);if(l==null)return!1;s=new CellSelection(A.doc.resolve(l))}const a=nextCell(s.$headCell,t,e);return a?maybeSetSelection(A,n,new CellSelection(s.$anchorCell,a)):!1}}function handleTripleClick(t,e){const A=t.state.doc,n=cellAround(A.resolve(e));return n?(t.dispatch(t.state.tr.setSelection(new CellSelection(n))),!0):!1}function handlePaste(t,e,A){if(!isInTable(t.state))return!1;let n=pastedCells(A);const r=t.state.selection;if(r instanceof CellSelection){n||(n={width:1,height:1,rows:[Fragment.from(fitSlice(tableNodeTypes(t.state.schema).cell,A))]});const o=r.$anchorCell.node(-1),s=r.$anchorCell.start(-1),a=TableMap.get(o).rectBetween(r.$anchorCell.pos-s,r.$headCell.pos-s);return n=clipCells(n,a.right-a.left,a.bottom-a.top),insertCells(t.state,t.dispatch,s,a,n),!0}else if(n){const o=selectionCell(t.state),s=o.start(-1);return insertCells(t.state,t.dispatch,s,TableMap.get(o.node(-1)).findCell(o.pos-s),n),!0}else return!1}function handleMouseDown(t,e){if(e.ctrlKey||e.metaKey)return;const A=domInCell(t,e.target);let n;if(e.shiftKey&&t.state.selection instanceof CellSelection)r(t.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&A&&(n=cellAround(t.state.selection.$anchor))!=null&&cellUnderMouse(t,e)?.pos!=n.pos)r(n,e),e.preventDefault();else if(!A)return;function r(a,l){let g=cellUnderMouse(t,l);const c=tableEditingKey.getState(t.state)==null;if(!g||!inSameTable(a,g))if(c)g=a;else return;const I=new CellSelection(a,g);if(c||!t.state.selection.eq(I)){const d=t.state.tr.setSelection(I);c&&d.setMeta(tableEditingKey,a.pos),t.dispatch(d)}}function o(){t.root.removeEventListener("mouseup",o),t.root.removeEventListener("dragstart",o),t.root.removeEventListener("mousemove",s),tableEditingKey.getState(t.state)!=null&&t.dispatch(t.state.tr.setMeta(tableEditingKey,-1))}function s(a){const l=a,g=tableEditingKey.getState(t.state);let c;if(g!=null)c=t.state.doc.resolve(g);else if(domInCell(t,l.target)!=A&&(c=cellUnderMouse(t,e),!c))return o();c&&r(c,l)}t.root.addEventListener("mouseup",o),t.root.addEventListener("dragstart",o),t.root.addEventListener("mousemove",s)}function atEndOfCell(t,e,A){if(!(t.state.selection instanceof TextSelection))return null;const{$head:n}=t.state.selection;for(let r=n.depth-1;r>=0;r--){const o=n.node(r);if((A<0?n.index(r):n.indexAfter(r))!=(A<0?0:o.childCount))return null;if(o.type.spec.tableRole=="cell"||o.type.spec.tableRole=="header_cell"){const a=n.before(r),l=e=="vert"?A>0?"down":"up":A>0?"right":"left";return t.endOfTextblock(l)?a:null}}return null}function domInCell(t,e){for(;e&&e!=t.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function cellUnderMouse(t,e){const A=t.posAtCoords({left:e.clientX,top:e.clientY});return A&&A?cellAround(t.state.doc.resolve(A.pos)):null}function tableEditing({allowTableNodeSelection:t=!1}={}){return new Plugin({key:tableEditingKey,state:{init(){return null},apply(e,A){const n=e.getMeta(tableEditingKey);if(n!=null)return n==-1?null:n;if(A==null||!e.docChanged)return A;const{deleted:r,pos:o}=e.mapping.mapResult(A);return r?null:o}},props:{decorations:drawCellSelection,handleDOMEvents:{mousedown:handleMouseDown},createSelectionBetween(e){return tableEditingKey.getState(e.state)!=null?e.state.selection:null},handleTripleClick,handleKeyDown,handlePaste},appendTransaction(e,A,n){return normalizeSelection(n,fixTables(n,A),t)}})}class NodeTable extends Node$2{constructor(){super(...arguments),this.name="table",this.requires=["doc"],this.attributes={class:{default:"table",fromDom(e){return e.hasAttribute("class")?e.getAttribute("class"):void 0}}}}getNodeSpec(){return{content:"table_row+",tableRole:"table",isolating:!0,group:"block",parseDOM:[{tag:"table",getAttrs:e=>setHtmlAttributes(this,e)}],toDOM:e=>["table",getHtmlAttributes(this,e),["tbody",0]]}}getCommandFactories(e,A){return{addColumnAfter:()=>(r,o)=>addColumnAfter(r,o),addColumnBefore:()=>(r,o)=>addColumnBefore(r,o),addRowAfter:()=>(r,o)=>addRowAfter(r,o),addRowBefore:()=>(r,o)=>addRowBefore(r,o),deleteColumn:()=>(r,o)=>deleteColumn(r,o),deleteRow:()=>(r,o)=>deleteRow(r,o),deleteTable:()=>(r,o)=>deleteTable(r,o),goToNextCell:r=>goToNextCell(r),mergeCells:()=>(r,o)=>mergeCells(r,o),setCellAttr:(...r)=>setCellAttr(...r),splitCell:()=>(r,o)=>splitCell(r,o),toggleHeader:(...r)=>toggleHeader(...r),toggleHeaderCell:()=>(r,o)=>toggleHeaderCell(r,o),toggleHeaderRow:()=>(r,o)=>toggleHeaderRow(r,o),toggleHeaderColumn:()=>(r,o)=>toggleHeaderColumn(r,o),insertTable:({rows:r=3,cols:o=3,withHeaderRow:s=!0}={})=>(a,l)=>{const g=a.tr,c=createTable(e.schema,r,o,s);if(l){const I=g.selection.from+1;g.replaceSelectionWith(c).scrollIntoView().setSelection(TextSelection.near(g.doc.resolve(I)))}return!0},setCellSelection:r=>(o,s)=>{if(s){const a=CellSelection.create(o.doc,r.anchorCell,r.headCell);o.tr.setSelection(a)}return!0}}}getKeyboardShortcuts(){return{}}getProseMirrorPlugins(){return[columnResizing(),tableEditing()]}}class NodeTableRow extends Node$2{constructor(){super(...arguments),this.name="table_row",this.requires=["table"]}getNodeSpec(){return{content:"(table_cell | table_header)*",tableRole:"row",parseDOM:[{tag:"tr"}],toDOM(){return["tr",0]}}}getCommandFactories(e,A){return{}}getKeyboardShortcuts(){return{}}}function getCellAttrs$1(t){if(typeof t=="string")return{};const e=t.getAttribute("data-colwidth"),A=e&&/^\d+(,\d+)*$/.test(e)?e.split(",").map(r=>Number(r)):null,n=Number(t.getAttribute("colspan")||1);return{colspan:n,rowspan:Number(t.getAttribute("rowspan")||1),colwidth:A&&A.length==n?A:null}}function setCellAttrs$1(t){return{colspan:t.attrs.colspan!=1?t.attrs.colspan:void 0,rowspan:t.attrs.rowspan!=1?t.attrs.rowspan:void 0,"data-colwidth":t.attrs.colwidth?.join(",")}}class NodeTableHeader extends Node$2{constructor(){super(...arguments),this.name="table_header",this.requires=["table"]}getNodeSpec(){return{content:"block+",attrs:{colspan:{default:1},rowspan:{default:1},colwidth:{default:void 0}},tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:e=>getCellAttrs$1(e)}],toDOM:e=>["th",setCellAttrs$1(e),0]}}}function getCellAttrs(t){if(typeof t=="string")return{};const e=t.getAttribute("data-colwidth"),A=e&&/^\d+(,\d+)*$/.test(e)?e.split(",").map(r=>Number(r)):null,n=Number(t.getAttribute("colspan")||1);return{colspan:n,rowspan:Number(t.getAttribute("rowspan")||1),colwidth:A&&A.length==n?A:null}}function setCellAttrs(t){return{colspan:t.attrs.colspan!=1?t.attrs.colspan:void 0,rowspan:t.attrs.rowspan!=1?t.attrs.rowspan:void 0,"data-colwidth":t.attrs.colwidth?.join(",")}}class NodeTableCell extends Node$2{constructor(){super(...arguments),this.name="table_cell",this.requires=["table_row"]}getNodeSpec(){return{content:"block+",attrs:{colspan:{default:1},rowspan:{default:1},colwidth:{default:void 0}},tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:e=>getCellAttrs(e)}],toDOM(e){return["td",setCellAttrs(e),0]}}}getCommandFactories(e,A){return{}}getKeyboardShortcuts(){return{}}}class ExtensionTables extends Extension{constructor(){super(...arguments),this.name="extension-tables",this.requires=[new NodeTable,new NodeTableHeader,new NodeTableRow,new NodeTableCell]}}const CSS_PREFIX="kb-autocomplete";class DefaultRenderer extends EventTarget{constructor(e){super(),this.editor=e,this.items=[],this.pos=-1,this.command=()=>{},this.keyDownHandler=A=>{this.onKeyDown({event:A})&&(A.stopPropagation(),A.preventDefault())}}onUpdate(e){this.command=e.command,this.items.splice(0,this.items.length,...e.items),this.props=e,this.refresh()}destroy(){document.body.removeEventListener("keydown",this.keyDownHandler,{capture:!0}),this.wrapper&&(this.wrapper.parentNode?.removeChild(this.wrapper),this.wrapper=void 0,this.dispatchEvent(new Event("close"))),this.pos=-1}onKeyDown(e){if(!this.wrapper||this.items.length===0)return!1;if(e.event.key==="Escape"&&this.wrapper)return this.wrapper.parentNode?.removeChild(this.wrapper),this.wrapper=void 0,!0;if(e.event.key==="ArrowUp"&&this.pos>-1)return this.pos=this.pos-1,this.refresh(),!0;if(e.event.key==="ArrowDown"&&this.pos<this.items.length-1)return this.pos++,this.refresh(),!0;if(e.event.key==="Enter"&&this.pos>-1&&this.pos<this.items.length){const A=this.items[this.pos];return this.items.splice(0,this.items.length),this.destroy(),this.command(A),!0}return!1}createListItem(e,A){const n=document.createElement("li");return A===this.pos&&n.classList.add("active"),n.innerText=""+e,n.style.cursor="pointer",n.addEventListener("click",()=>{this.destroy(),this.command(e)}),n}refresh(){if(this.wrapper||(this.wrapper=document.createElement("dialog"),this.wrapper.classList.add(CSS_PREFIX+"__wrapper"),document.body.appendChild(this.wrapper),this.list=document.createElement("ul"),this.wrapper.appendChild(this.list)),document.body.removeEventListener("keydown",this.keyDownHandler,{capture:!0}),!this.list)return;this.list.innerHTML="";for(let n=0;n<this.items.length;n++){const r=this.items[n];this.list.appendChild(this.createListItem(r,n))}this.items.length>0&&document.body.addEventListener("keydown",this.keyDownHandler,{capture:!0});let e=!1;this.items.length===0||(e=!0);const A=this.props?.clientRect?.();if(A?.height){const n=A.left,r=A.bottom;this.wrapper.style.left=n+"px",this.wrapper.style.top=r+"px"}else e=!1;if(e){if(!this.wrapper.open){const n=document.activeElement,r=n instanceof HTMLElement?n:null;this.wrapper.show(),requestAnimationFrame(()=>{r&&r.isConnected&&r.focus()})}}else this.wrapper.open&&this.wrapper.close()}}function escapeForRegEx(t){return t.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")}function createDefaultMatcher(t={}){const e=t.char||"@",A=t.allowToIncludeChar||!1,n=t.allowedPrefixes||[" "],r=t.startOfLine||!1;return o=>{const s=t.allowSpaces&&!A,a=escapeForRegEx(e),l=new RegExp(`\\s${a}$`),g=r?"^":"",c=A?"":a,I=s?new RegExp(`${g}${a}.*?(?=\\s${c}|$)`,"gm"):new RegExp(`${g}(?:^)?${a}[^\\s${c}]*`,"gm"),d=o.nodeBefore?.isText&&o.nodeBefore.text;if(!d)return;const h=o.pos-d.length,u=Array.from(d.matchAll(I)).pop();if(!u||u.input===void 0||u.index===void 0)return;const B=u.input.slice(Math.max(0,u.index-1),u.index),E=new RegExp(`^[${n?.join("")}\0]?$`).test(B);if(n!==null&&!E)return;const f=h+u.index;let Q=f+u[0].length;if(s&&l.test(d.slice(Q-1,Q+1))&&(u[0]+=" ",Q+=1),f<o.pos&&Q>=o.pos)return{range:{from:f,to:Q},query:u[0]}}}const AutocompletePluginKey=new PluginKey("autocomplete");function matchSource(t,e){let A;const n=t.$anchor.parent;for(const r of e){if(!r.matchers)continue;const o=r.matchers;if(!["code_blocxk"].includes(n.type.name))for(const s of o){const a=s(t.$from);if(a)return A={source:r,match:a},A}}}class AutocompletePlugin extends Plugin{constructor(e,A){super({key:AutocompletePluginKey,state:{init(){return{autocompleteSources:[],manual:!1,active:void 0,composing:!1}},apply(n,r,o,s){const a=n.getMeta(AutocompletePluginKey),l={...r};!a&&n.isGeneric;const{editable:g,composing:c}=A.view,{selection:I}=n,d=()=>{l.active&&(l.active.renderer.destroy(),l.active=void 0),l.decorationId=void 0},h=B=>{if(B&&(!B.source.allow||B.source.allow({range:B.match.range,isActive:!!l.active}))){const{source:E,match:f}=B;console.info("Trigger matcher autocomplete",f);let Q=l.active?.renderer;l.active?.source!==E&&Q&&(Q.destroy(),Q=void 0),Q||(Q=new DefaultRenderer(A),Q.addEventListener("close",()=>{const m=A.state.tr.setMeta(AutocompletePluginKey,{deactivate:!0});console.info("Manual autocomplete deactivate"),A.view.dispatch(m)})),l.active={renderer:Q,source:E,match:f};const p=`id_${Math.floor(Math.random()*4294967295)}`;l.decorationId=l.decorationId||p}else d()};if(a?.addAutocompleteSource){const B={...a.addAutocompleteSource.autocompleteSource};return!B.matchers&&B.triggerKeys?.length===1&&(B.matchers=[createDefaultMatcher({char:B.triggerKeys[0]})]),l.autocompleteSources.push(B),l}if(a?.activate){console.info("Trigger manual autocomplete");const B=matchSource(I,l.autocompleteSources);return h(B),l.manual=!0,l}if(a?.deactivate)return console.info("Deactivate autocomplete"),d(),l;if(!g||!I.empty&&!A.view.composing)return d(),l;if(l.active&&!c&&!l.composing&&(I.from<l.active.match.range.from||I.from>l.active.match.range.to)&&d(),l.composing=c,n.getMeta("isCommand"))return l;const u=matchSource(I,l.autocompleteSources);return h(u),l.manual=!1,l}},view(){return{update:async(n,r)=>{const o=this.key?.getState(r),s=this.key?.getState(n.state),a=o.active&&s.active&&o.active.match.range.from!==s.active.match.range.from,l=!o.active?.match&&s.active?.match,g=o.active?.match&&!s.active?.match,c=!l&&!g&&o.active?.match.query!==s.active?.match.query;if(g&&o.active){o.active.renderer.destroy();return}if(s.active&&(o.active?.match.query!==s.active.match.query||a)){n.dom.querySelector(`[data-decoration-id="${s.decorationId}"]`);const B=s.active.source.onSelect,E=s.active.match.range,f={match:s.active.match,items:[],command:Q=>B(Q,E),clientRect:()=>{const{decorationId:Q}=s;return n.dom.querySelector(`[data-decoration-id="${Q}"]`)?.getBoundingClientRect()||null}};s.active.renderer.onUpdate(f);try{const Q={range:s.active.match.range,isActive:!!s.active},p=await s.active.source.getItems(s.active.match.query,Q);s.active.renderer.onUpdate({...f,items:p})}catch(Q){if(Q.isLSP)console.error("LSP error config.getItems()",Q.message,s.active.source.getItems);else throw Q}}},destroy:()=>{const n=AutocompletePluginKey.getState(A.state);if(!n)return;const{active:r}=n;r&&r.renderer.destroy()}}},props:{handleKeyDown(n,r){const o=this.getState(n.state),{autocompleteSources:s}=o;for(const a of s){const l=[...a.triggerKeys||[]];for(const g of l){let c=g.toLowerCase();if(c.startsWith("ctrl+")){if(!r.ctrlKey)continue;c=c.substring(5)}if(c===r.key){const I=n.state.tr.setMeta(AutocompletePluginKey,{activate:!0});return console.info("Manual autocomplete key "+g),n.dispatch(I),!1}}}return!1},decorations(n){const{active:r,decorationId:o}=this.getState(n)||{};if(!r||!o)return null;const s=document.createElement("span");return s.className=e.decorationClass||"kb-autocomplete--decor",s.setAttribute("data-decoration-id",o),DecorationSet.create(n.doc,[Decoration.widget(r.match.range.from,s,{class:s.className,decorationId:o,refresh:()=>r.renderer.refresh()})])}}})}}class ExtensionAutocomplete extends Extension{constructor(e={}){super(e),this.config=e,this.name="autocomplete"}getCommandFactories(){return{addAutocompleteSource:A=>(n,r)=>{const o=n.tr;return o.setMeta(AutocompletePluginKey,{addAutocompleteSource:{autocompleteSource:A}}),r&&r(o),!0}}}getProseMirrorPlugins(){return[new AutocompletePlugin(this.config,this.editor)]}}class AdvancedEditorKit{constructor(e){this.menu=e}name="advanced-editor";getExtensions(){return[new ExtensionBasicEditor,new ExtensionMarkdown,new ExtensionOdt,new ExtensionTables,new ExtensionDevToolkit,new ExtensionCustomMenu(this.menu),new ExtensionCodeJar,new ExtensionAutocomplete]}}const createAssetLoad=t=>async e=>{const n=t.toString()+"/"+e,r=await fetch(n);if(r.status>=400)throw new Error(`Error fetching ${r.status}`);return new Uint8Array(await r.arrayBuffer())};var GOOD_LEAF_SIZE=200,RopeSequence=function t(){};RopeSequence.prototype.append=function t(e){return e.length?(e=RopeSequence.from(e),!this.length&&e||e.length<GOOD_LEAF_SIZE&&this.leafAppend(e)||this.length<GOOD_LEAF_SIZE&&e.leafPrepend(this)||this.appendInner(e)):this};RopeSequence.prototype.prepend=function t(e){return e.length?RopeSequence.from(e).append(this):this};RopeSequence.prototype.appendInner=function t(e){return new Append(this,e)};RopeSequence.prototype.slice=function t(e,A){return e===void 0&&(e=0),A===void 0&&(A=this.length),e>=A?RopeSequence.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,A))};RopeSequence.prototype.get=function t(e){if(!(e<0||e>=this.length))return this.getInner(e)};RopeSequence.prototype.forEach=function t(e,A,n){A===void 0&&(A=0),n===void 0&&(n=this.length),A<=n?this.forEachInner(e,A,n,0):this.forEachInvertedInner(e,A,n,0)};RopeSequence.prototype.map=function t(e,A,n){A===void 0&&(A=0),n===void 0&&(n=this.length);var r=[];return this.forEach(function(o,s){return r.push(e(o,s))},A,n),r};RopeSequence.from=function t(e){return e instanceof RopeSequence?e:e&&e.length?new Leaf(e):RopeSequence.empty};var Leaf=(function(t){function e(n){t.call(this),this.values=n}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var A={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(r,o){return r==0&&o==this.length?this:new e(this.values.slice(r,o))},e.prototype.getInner=function(r){return this.values[r]},e.prototype.forEachInner=function(r,o,s,a){for(var l=o;l<s;l++)if(r(this.values[l],a+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,o,s,a){for(var l=o-1;l>=s;l--)if(r(this.values[l],a+l)===!1)return!1},e.prototype.leafAppend=function(r){if(this.length+r.length<=GOOD_LEAF_SIZE)return new e(this.values.concat(r.flatten()))},e.prototype.leafPrepend=function(r){if(this.length+r.length<=GOOD_LEAF_SIZE)return new e(r.flatten().concat(this.values))},A.length.get=function(){return this.values.length},A.depth.get=function(){return 0},Object.defineProperties(e.prototype,A),e})(RopeSequence);RopeSequence.empty=new Leaf([]);var Append=(function(t){function e(A,n){t.call(this),this.left=A,this.right=n,this.length=A.length+n.length,this.depth=Math.max(A.depth,n.depth)+1}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(n){return n<this.left.length?this.left.get(n):this.right.get(n-this.left.length)},e.prototype.forEachInner=function(n,r,o,s){var a=this.left.length;if(r<a&&this.left.forEachInner(n,r,Math.min(o,a),s)===!1||o>a&&this.right.forEachInner(n,Math.max(r-a,0),Math.min(this.length,o)-a,s+a)===!1)return!1},e.prototype.forEachInvertedInner=function(n,r,o,s){var a=this.left.length;if(r>a&&this.right.forEachInvertedInner(n,r-a,Math.max(o,a)-a,s+a)===!1||o<a&&this.left.forEachInvertedInner(n,Math.min(r,a),o,s)===!1)return!1},e.prototype.sliceInner=function(n,r){if(n==0&&r==this.length)return this;var o=this.left.length;return r<=o?this.left.slice(n,r):n>=o?this.right.slice(n-o,r-o):this.left.slice(n,o).append(this.right.slice(0,r-o))},e.prototype.leafAppend=function(n){var r=this.right.leafAppend(n);if(r)return new e(this.left,r)},e.prototype.leafPrepend=function(n){var r=this.left.leafPrepend(n);if(r)return new e(r,this.right)},e.prototype.appendInner=function(n){return this.left.depth>=Math.max(this.right.depth,n.depth)+1?new e(this.left,new e(this.right,n)):new e(this,n)},e})(RopeSequence);const max_empty_items=500;class Branch{constructor(e,A){this.items=e,this.eventCount=A}popEvent(e,A){if(this.eventCount==0)return null;let n=this.items.length;for(;;n--)if(this.items.get(n-1).selection){--n;break}let r,o;A&&(r=this.remapping(n,this.items.length),o=r.maps.length);let s=e.tr,a,l,g=[],c=[];return this.items.forEach((I,d)=>{if(!I.step){r||(r=this.remapping(n,d+1),o=r.maps.length),o--,c.push(I);return}if(r){c.push(new Item(I.map));let h=I.step.map(r.slice(o)),u;h&&s.maybeStep(h).doc&&(u=s.mapping.maps[s.mapping.maps.length-1],g.push(new Item(u,void 0,void 0,g.length+c.length))),o--,u&&r.appendMap(u,o)}else s.maybeStep(I.step);if(I.selection)return a=r?I.selection.map(r.slice(o)):I.selection,l=new Branch(this.items.slice(0,n).append(c.reverse().concat(g)),this.eventCount-1),!1},this.items.length,0),{remaining:l,transform:s,selection:a}}addTransform(e,A,n,r){let o=[],s=this.eventCount,a=this.items,l=!r&&a.length?a.get(a.length-1):null;for(let c=0;c<e.steps.length;c++){let I=e.steps[c].invert(e.docs[c]),d=new Item(e.mapping.maps[c],I,A),h;(h=l&&l.merge(d))&&(d=h,c?o.pop():a=a.slice(0,a.length-1)),o.push(d),A&&(s++,A=void 0),r||(l=d)}let g=s-n.depth;return g>DEPTH_OVERFLOW&&(a=cutOffEvents(a,g),s-=g),new Branch(a.append(o),s)}remapping(e,A){let n=new Mapping;return this.items.forEach((r,o)=>{let s=r.mirrorOffset!=null&&o-r.mirrorOffset>=e?n.maps.length-r.mirrorOffset:void 0;n.appendMap(r.map,s)},e,A),n}addMaps(e){return this.eventCount==0?this:new Branch(this.items.append(e.map(A=>new Item(A))),this.eventCount)}rebased(e,A){if(!this.eventCount)return this;let n=[],r=Math.max(0,this.items.length-A),o=e.mapping,s=e.steps.length,a=this.eventCount;this.items.forEach(d=>{d.selection&&a--},r);let l=A;this.items.forEach(d=>{let h=o.getMirror(--l);if(h==null)return;s=Math.min(s,h);let u=o.maps[h];if(d.step){let B=e.steps[h].invert(e.docs[h]),E=d.selection&&d.selection.map(o.slice(l+1,h));E&&a++,n.push(new Item(u,B,E))}else n.push(new Item(u))},r);let g=[];for(let d=A;d<s;d++)g.push(new Item(o.maps[d]));let c=this.items.slice(0,r).append(g).append(n),I=new Branch(c,a);return I.emptyItemCount()>max_empty_items&&(I=I.compress(this.items.length-n.length)),I}emptyItemCount(){let e=0;return this.items.forEach(A=>{A.step||e++}),e}compress(e=this.items.length){let A=this.remapping(0,e),n=A.maps.length,r=[],o=0;return this.items.forEach((s,a)=>{if(a>=e)r.push(s),s.selection&&o++;else if(s.step){let l=s.step.map(A.slice(n)),g=l&&l.getMap();if(n--,g&&A.appendMap(g,n),l){let c=s.selection&&s.selection.map(A.slice(n));c&&o++;let I=new Item(g.invert(),l,c),d,h=r.length-1;(d=r.length&&r[h].merge(I))?r[h]=d:r.push(I)}}else s.map&&n--},this.items.length,0),new Branch(RopeSequence.from(r.reverse()),o)}}Branch.empty=new Branch(RopeSequence.empty,0);function cutOffEvents(t,e){let A;return t.forEach((n,r)=>{if(n.selection&&e--==0)return A=r,!1}),t.slice(A)}class Item{constructor(e,A,n,r){this.map=e,this.step=A,this.selection=n,this.mirrorOffset=r}merge(e){if(this.step&&e.step&&!e.selection){let A=e.step.merge(this.step);if(A)return new Item(A.getMap().invert(),A,this.selection)}}}class HistoryState{constructor(e,A,n,r,o){this.done=e,this.undone=A,this.prevRanges=n,this.prevTime=r,this.prevComposition=o}}const DEPTH_OVERFLOW=20;function applyTransaction(t,e,A,n){let r=A.getMeta(historyKey),o;if(r)return r.historyState;A.getMeta(closeHistoryKey)&&(t=new HistoryState(t.done,t.undone,null,0,-1));let s=A.getMeta("appendedTransaction");if(A.steps.length==0)return t;if(s&&s.getMeta(historyKey))return s.getMeta(historyKey).redo?new HistoryState(t.done.addTransform(A,void 0,n,mustPreserveItems(e)),t.undone,rangesFor(A.mapping.maps),t.prevTime,t.prevComposition):new HistoryState(t.done,t.undone.addTransform(A,void 0,n,mustPreserveItems(e)),null,t.prevTime,t.prevComposition);if(A.getMeta("addToHistory")!==!1&&!(s&&s.getMeta("addToHistory")===!1)){let a=A.getMeta("composition"),l=t.prevTime==0||!s&&t.prevComposition!=a&&(t.prevTime<(A.time||0)-n.newGroupDelay||!isAdjacentTo(A,t.prevRanges)),g=s?mapRanges(t.prevRanges,A.mapping):rangesFor(A.mapping.maps);return new HistoryState(t.done.addTransform(A,l?e.selection.getBookmark():void 0,n,mustPreserveItems(e)),Branch.empty,g,A.time,a??t.prevComposition)}else return(o=A.getMeta("rebased"))?new HistoryState(t.done.rebased(A,o),t.undone.rebased(A,o),mapRanges(t.prevRanges,A.mapping),t.prevTime,t.prevComposition):new HistoryState(t.done.addMaps(A.mapping.maps),t.undone.addMaps(A.mapping.maps),mapRanges(t.prevRanges,A.mapping),t.prevTime,t.prevComposition)}function isAdjacentTo(t,e){if(!e)return!1;if(!t.docChanged)return!0;let A=!1;return t.mapping.maps[0].forEach((n,r)=>{for(let o=0;o<e.length;o+=2)n<=e[o+1]&&r>=e[o]&&(A=!0)}),A}function rangesFor(t){let e=[];for(let A=t.length-1;A>=0&&e.length==0;A--)t[A].forEach((n,r,o,s)=>e.push(o,s));return e}function mapRanges(t,e){if(!t)return null;let A=[];for(let n=0;n<t.length;n+=2){let r=e.map(t[n],1),o=e.map(t[n+1],-1);r<=o&&A.push(r,o)}return A}function histTransaction(t,e,A){let n=mustPreserveItems(e),r=historyKey.get(e).spec.config,o=(A?t.undone:t.done).popEvent(e,n);if(!o)return null;let s=o.selection.resolve(o.transform.doc),a=(A?t.done:t.undone).addTransform(o.transform,e.selection.getBookmark(),r,n),l=new HistoryState(A?a:o.remaining,A?o.remaining:a,null,0,-1);return o.transform.setSelection(s).setMeta(historyKey,{redo:A,historyState:l})}let cachedPreserveItems=!1,cachedPreserveItemsPlugins=null;function mustPreserveItems(t){let e=t.plugins;if(cachedPreserveItemsPlugins!=e){cachedPreserveItems=!1,cachedPreserveItemsPlugins=e;for(let A=0;A<e.length;A++)if(e[A].spec.historyPreserveItems){cachedPreserveItems=!0;break}}return cachedPreserveItems}const historyKey=new PluginKey("history"),closeHistoryKey=new PluginKey("closeHistory");function history$1(t={}){return t={depth:t.depth||100,newGroupDelay:t.newGroupDelay||500},new Plugin({key:historyKey,state:{init(){return new HistoryState(Branch.empty,Branch.empty,null,0,-1)},apply(e,A,n){return applyTransaction(A,n,e,t)}},config:t,props:{handleDOMEvents:{beforeinput(e,A){let n=A.inputType,r=n=="historyUndo"?undo:n=="historyRedo"?redo:null;return r?(A.preventDefault(),r(e.state,e.dispatch)):!1}}}})}function buildCommand(t,e){return(A,n)=>{let r=historyKey.getState(A);if(!r||(t?r.undone:r.done).eventCount==0)return!1;if(n){let o=histTransaction(r,A,t);o&&n(e?o.scrollIntoView():o)}return!0}}const undo=buildCommand(!1,!0),redo=buildCommand(!0,!0);class ExtensionHistory extends Extension{name="history";options={depth:100,newGroupDelay:500};getCommandFactories(e){return{undo:()=>undo,redo:()=>redo}}getKeyboardShortcuts(){const e=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator?.platform):!1,A={"Mod-z":"undo","Mod-y":"redo"};return e||(A["Mod-y"]="redo"),A}getProseMirrorPlugins(){return[history$1(this.options)]}}const __viteBrowserExternal=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));exports.AdvancedEditorKit=AdvancedEditorKit;exports.CoreEditor=CoreEditor;exports.ExtensionHistory=ExtensionHistory;exports.createAssetLoad=createAssetLoad;
|
|
197
197
|
//# sourceMappingURL=kerebron3.cjs.map
|