diff --git a/django_prose_editor/static/django_prose_editor/editor.css b/django_prose_editor/static/django_prose_editor/editor.css index 752d763..7a58785 100644 --- a/django_prose_editor/static/django_prose_editor/editor.css +++ b/django_prose_editor/static/django_prose_editor/editor.css @@ -1 +1,2 @@ .ProseMirror{color:#000!important;padding:1rem 1.75rem;outline:none!important;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Open Sans,Helvetica Neue,sans-serif;margin:0!important}.ProseMirror *{color:#000!important}.ProseMirror p{font-size:16px!important}.ProseMirror h1{display:block!important;font-size:2em!important;margin-block-start:.67em!important;margin-block-end:.67em!important;margin-inline-start:0px!important;margin-inline-end:0px!important;font-weight:700!important}.ProseMirror h2{padding:0;display:block!important;font-size:1.5em!important;margin-block-start:.83em!important;margin-block-end:.83em!important;margin-inline-start:0px!important;margin-inline-end:0px!important;font-weight:700!important;background:white!important}.ProseMirror h3{display:block!important;font-size:1.17em!important;margin-block-start:1em!important;margin-block-end:1em!important;margin-inline-start:0px!important;margin-inline-end:0px!important;font-weight:700!important;padding:0!important}.ProseMirror>*+*{margin-top:.75em!important}.ProseMirror p.is-editor-empty:first-child:before{content:attr(data-placeholder);float:left;color:#a8a8a8;pointer-events:none;height:0}.ProseMirror ol{padding-left:0!important;list-style-type:decimal!important}.ProseMirror ol li::marker{font-size:16px!important}.ProseMirror ol>li>ol{padding-left:10px!important;margin-left:10px!important;list-style-type:lower-latin!important}.ProseMirror ol>li>ol>li>ol{padding-left:10px!important;margin-left:10px!important;list-style-type:lower-roman!important}.ProseMirror ol>li>ol>li>ol>li>ol{padding-left:10px!important;margin-left:10px!important;list-style-type:upper-latin!important}.ProseMirror ol>li>ol>li>ol>li>ol>li>ol{padding-left:10px!important;margin-left:10px!important;list-style-type:upper-roman!important}.ProseMirror ul{list-style-type:disc!important;margin-block-start:0!important;margin-block-end:0!important;margin-inline-start:0px!important;margin-inline-end:0px!important}.ProseMirror ul li{list-style:disc!important}.ProseMirror ul>li>ul{padding-left:10px!important;margin-left:10px!important;list-style-type:disc!important}.ProseMirror{margin:1rem 0}.ProseMirror h1,.ProseMirror h2,.ProseMirror h3,.ProseMirror h4,.ProseMirror h5,.ProseMirror h6{line-height:1.1;text-transform:none;padding:0}.ProseMirror pre{background:#0d0d0d!important;color:#fff!important;font-family:JetBrainsMono,monospace!important;padding:.75rem 1rem!important;border-radius:.5rem!important}.ProseMirror pre code{color:#fff!important;padding:0!important;background:none!important;font-size:.8rem!important}.ProseMirror img{max-width:100%;height:auto}.ProseMirror blockquote{padding-left:1rem;border-left:2px solid rgba(13,13,13,.1)}.ProseMirror hr{border:none;border-top:2px solid rgba(13,13,13,.1);margin:2rem 0}.ProseMirror a{text-decoration:underline}.ProseMirror table{border-collapse:collapse;table-layout:fixed;width:100%;margin:0;overflow:hidden}.ProseMirror table td,.ProseMirror table th,.ProseMirror table[show_borders=false]:hover td,.ProseMirror table[show_borders=false]:hover th{min-width:1em;border:2px solid #ced4da;padding:3px 5px;vertical-align:top;box-sizing:border-box;position:relative}.ProseMirror table[show_borders=false] td,.ProseMirror table[show_borders=false] th{border:none;box-sizing:border-box}.ProseMirror table td>*,.ProseMirror table th>*{margin-bottom:0}.ProseMirror table th{font-weight:700;text-align:left;background-color:#f1f3f5}.ProseMirror tr{background-color:#fff!important}.ProseMirror table .selectedCell:after{z-index:2;position:absolute;content:"";inset:0;background:rgba(200,200,255,.4);pointer-events:none}.ProseMirror table .column-resize-handle{position:absolute;right:-2px;top:0;bottom:-2px;width:4px;background-color:#adf;pointer-events:none}.tableWrapper{overflow-x:auto}.resize-cursor{cursor:ew-resize;cursor:col-resize}:root{--prose-editor-font-size: 14px;--prose-menubar-font-size: 14px}.ProseMirror{padding:0 6px;border:1px solid var(--border-color);border-radius:4px}.prose-editor *,.prose-editor *:before,.prose-editor *:after{box-sizing:inherit}.prose-editor{font-size:var(--prose-editor-font-size);box-sizing:border-box;position:relative;flex-grow:1}.prose-editor+textarea{display:none}.prose-menubar{font-size:var(--prose-menubar-font-size);background:white;display:inline-flex;gap:8px;flex-wrap:wrap;margin-bottom:2px}.prose-menubar__group{display:flex;gap:2px}.prose-menubar__button{cursor:pointer;padding:0 .25em;min-width:2em;transition:all .25s;border:1px solid;border-radius:.25em;text-align:center}.prose-menubar__button:hover{filter:brightness(110%)}.prose-menubar__button.active{background-color:var(--primary)}.prose-menubar__button.disabled{background-color:#acc0cc;filter:brightness(100%);cursor:not-allowed;opacity:.3}.prose-menubar__button--history-undo,.prose-menubar__button--history-redo{background-image:url(./history-arrow-HHQ2TDW5.svg);background-repeat:no-repeat;background-size:1.25em;background-position:center}.prose-menubar__button--history-redo{transform:scaleX(-1)}.ProseMirror{position:relative}.ProseMirror{word-wrap:break-word;white-space:pre-wrap;white-space:break-spaces;font-variant-ligatures:none;font-feature-settings:"liga" 0}.ProseMirror pre{white-space:pre-wrap}.ProseMirror li{position:relative}.ProseMirror-hideselection *::selection{background:transparent}.ProseMirror-hideselection *::-moz-selection{background:transparent}.ProseMirror-hideselection{caret-color:transparent}.ProseMirror [draggable][contenteditable=false]{-webkit-user-select:text;-moz-user-select:text;user-select:text}.ProseMirror-selectednode{outline:2px solid #8cf}li.ProseMirror-selectednode{outline:none}li.ProseMirror-selectednode:after{content:"";position:absolute;inset:-2px -2px -2px -32px;border:2px solid #8cf;pointer-events:none}img.ProseMirror-separator{display:inline!important;border:none!important;margin:0!important} +/*# sourceMappingURL=editor.css.map */ diff --git a/django_prose_editor/static/django_prose_editor/editor.js b/django_prose_editor/static/django_prose_editor/editor.js index e3591d5..3ce879c 100644 --- a/django_prose_editor/static/django_prose_editor/editor.js +++ b/django_prose_editor/static/django_prose_editor/editor.js @@ -1,12 +1,12 @@ -var DjangoProseEditor=(()=>{var Ut=Object.defineProperty;var Ro=Object.getOwnPropertyDescriptor;var vo=Object.getOwnPropertyNames,zr=Object.getOwnPropertySymbols;var Fr=Object.prototype.hasOwnProperty,Po=Object.prototype.propertyIsEnumerable;var Br=(r,e,t)=>e in r?Ut(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,On=(r,e)=>{for(var t in e||(e={}))Fr.call(e,t)&&Br(r,t,e[t]);if(zr)for(var t of zr(e))Po.call(e,t)&&Br(r,t,e[t]);return r};var zo=(r,e)=>{for(var t in e)Ut(r,t,{get:e[t],enumerable:!0})},Bo=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of vo(e))!Fr.call(r,i)&&i!==t&&Ut(r,i,{get:()=>e[i],enumerable:!(n=Ro(e,i))||n.enumerable});return r};var Fo=r=>Bo(Ut({},"__esModule",{value:!0}),r);var Rc={};zo(Rc,{createEditor:()=>Io});function B(r){this.content=r}B.prototype={constructor:B,find:function(r){for(var e=0;e>1}};B.from=function(r){if(r instanceof B)return r;var e=[];if(r)for(var t in r)e.push(t,r[t]);return new B(e)};var wn=B;function $r(r,e,t){for(let n=0;;n++){if(n==r.childCount||n==e.childCount)return r.childCount==e.childCount?null:t;let i=r.child(n),s=e.child(n);if(i==s){t+=i.nodeSize;continue}if(!i.sameMarkup(s))return t;if(i.isText&&i.text!=s.text){for(let o=0;i.text[o]==s.text[o];o++)t++;return t}if(i.content.size||s.content.size){let o=$r(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function jr(r,e,t,n){for(let i=r.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:t,b:n};let o=r.child(--i),l=e.child(--s),a=o.nodeSize;if(o==l){t-=a,n-=a;continue}if(!o.sameMarkup(l))return{a:t,b:n};if(o.isText&&o.text!=l.text){let f=0,c=Math.min(o.text.length,l.text.length);for(;fe&&n(a,i+l,s||null,o)!==!1&&a.content.size){let c=l+1;a.nodesBetween(Math.max(0,e-c),Math.min(a.content.size,t-c),n,i+c)}l=f}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,i){let s="",o=!0;return this.nodesBetween(e,t,(l,a)=>{let f=l.isText?l.text.slice(Math.max(e,a)-a,t-a):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&f||l.isTextblock)&&n&&(o?o=!1:s+=n),s+=f},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,n=e.firstChild,i=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(n)&&(i[i.length-1]=t.withText(t.text+n.text),s=1);se)for(let s=0,o=0;oe&&((ot)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,t-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,t-o-1))),n.push(l),i+=l.nodeSize),o=a}return new g(n,i)}cutByIndex(e,t){return e==t?g.empty:e==0&&t==this.content.length?this:new g(this.content.slice(e,t))}replaceChild(e,t){let n=this.content[e];if(n==t)return this;let i=this.content.slice(),s=this.size+t.nodeSize-n.nodeSize;return i[e]=t,new g(i,s)}addToStart(e){return new g([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new g(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let n=0,i=0;;n++){let s=this.child(n),o=i+s.nodeSize;if(o>=e)return o==e||t>0?_t(n+1,o):_t(n,i);i=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return g.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new g(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return g.empty;let t,n=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),n=!0),t&&t.push(s)}}return t||(t=e.slice()),n||t.push(this),t}removeFromSet(e){for(let t=0;tn.type.rank-i.type.rank),t}};C.none=[];var Ke=class extends Error{},b=class{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let n=Ur(this.content,e+this.openStart,t);return n&&new b(n,this.openStart,this.openEnd)}removeBetween(e,t){return new b(Hr(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return b.empty;let n=t.openStart||0,i=t.openEnd||0;if(typeof n!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new b(g.fromJSON(e,t.content),n,i)}static maxOpen(e,t=!0){let n=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)n++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)i++;return new b(e,n,i)}};b.empty=new b(g.empty,0,0);function Hr(r,e,t){let{index:n,offset:i}=r.findIndex(e),s=r.maybeChild(n),{index:o,offset:l}=r.findIndex(t);if(i==e||s.isText){if(l!=t&&!r.child(o).isText)throw new RangeError("Removing non-flat range");return r.cut(0,e).append(r.cut(t))}if(n!=o)throw new RangeError("Removing non-flat range");return r.replaceChild(n,s.copy(Hr(s.content,e-i-1,t-i-1)))}function Ur(r,e,t,n){let{index:i,offset:s}=r.findIndex(e),o=r.maybeChild(i);if(s==e||o.isText)return n&&!n.canReplace(i,i,t)?null:r.cut(0,e).append(t).append(r.cut(e));let l=Ur(o.content,e-s-1,t);return l&&r.replaceChild(i,o.copy(l))}function Vo(r,e,t){if(t.openStart>r.depth)throw new Ke("Inserted content deeper than insertion position");if(r.depth-t.openStart!=e.depth-t.openEnd)throw new Ke("Inconsistent open depths");return _r(r,e,t,0)}function _r(r,e,t,n){let i=r.index(n),s=r.node(n);if(i==e.index(n)&&n=0&&r.isText&&r.sameMarkup(e[t])?e[t]=r.withText(e[t].text+r.text):e.push(r)}function Mt(r,e,t,n){let i=(e||r).node(t),s=0,o=e?e.index(t):i.childCount;r&&(s=r.index(t),r.depth>t?s++:r.textOffset&&(We(r.nodeAfter,n),s++));for(let l=s;li&&In(r,e,i+1),o=n.depth>i&&In(t,n,i+1),l=[];return Mt(null,r,i,l),s&&o&&e.index(i)==t.index(i)?(Yr(s,o),We(qe(s,Gr(r,e,t,n,i+1)),l)):(s&&We(qe(s,Gt(r,e,i+1)),l),Mt(e,t,i,l),o&&We(qe(o,Gt(t,n,i+1)),l)),Mt(n,null,i,l),new g(l)}function Gt(r,e,t){let n=[];if(Mt(null,r,t,n),r.depth>t){let i=In(r,e,t+1);We(qe(i,Gt(r,e,t+1)),n)}return Mt(e,null,t,n),new g(n)}function Lo(r,e){let t=e.depth-r.openStart,i=e.node(t).copy(r.content);for(let s=t-1;s>=0;s--)i=e.node(s).copy(g.from(i));return{start:i.resolveNoCache(r.openStart+t),end:i.resolveNoCache(i.content.size-r.openEnd-t)}}var $e=class{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let n=this.pos-this.path[this.path.length-1],i=e.child(t);return n?e.child(t).cut(n):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let s=0;s0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new je(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let n=[],i=0,s=t;for(let o=e;;){let{index:l,offset:a}=o.content.findIndex(s),f=s-a;if(n.push(o,l,i+a),!f||(o=o.child(l),o.isText))break;s=f-1,i+=a+1}return new $e(t,n,s)}static resolveCached(e,t){for(let i=0;ie&&this.nodesBetween(e,t,s=>(n.isInSet(s.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),Xr(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,n=g.empty,i=0,s=n.childCount){let o=this.contentMatchAt(e).matchFragment(n,i,s),l=o&&o.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let a=i;at.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let n=null;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");n=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,n)}let i=g.fromJSON(e,t.content);return e.nodeType(t.type).create(t.attrs,i,n)}};_.prototype.text=void 0;var it=class extends _{constructor(e,t,n,i){if(super(e,t,null,i),!n)throw new RangeError("Empty text nodes are not allowed");this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Xr(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new it(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new it(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function Xr(r,e){for(let t=r.length-1;t>=0;t--)e=r[t].type.name+"("+e+")";return e}var be=class{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let n=new An(e,t);if(n.next==null)return be.empty;let i=Qr(n);n.next&&n.err("Unexpected trailing text");let s=_o(Uo(i));return Yo(s,n),s}matchType(e){for(let t=0;tf.createAndFill()));for(let f=0;f=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(n){e.push(n);for(let i=0;i{let s=i+(n.validEnd?"*":" ")+" ";for(let o=0;o"+e.indexOf(n.next[o].next);return s}).join(` -`)}};be.empty=new be(!0);var An=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function Qr(r){let e=[];do e.push(qo(r));while(r.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function qo(r){let e=[];do e.push(Ko(r));while(r.next&&r.next!=")"&&r.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function Ko(r){let e=Ho(r);for(;;)if(r.eat("+"))e={type:"plus",expr:e};else if(r.eat("*"))e={type:"star",expr:e};else if(r.eat("?"))e={type:"opt",expr:e};else if(r.eat("{"))e=$o(r,e);else break;return e}function Vr(r){/\D/.test(r.next)&&r.err("Expected number, got '"+r.next+"'");let e=Number(r.next);return r.pos++,e}function $o(r,e){let t=Vr(r),n=t;return r.eat(",")&&(r.next!="}"?n=Vr(r):n=-1),r.eat("}")||r.err("Unclosed braced range"),{type:"range",min:t,max:n,expr:e}}function jo(r,e){let t=r.nodeTypes,n=t[e];if(n)return[n];let i=[];for(let s in t){let o=t[s];o.groups.indexOf(e)>-1&&i.push(o)}return i.length==0&&r.err("No node type or group '"+e+"' found"),i}function Ho(r){if(r.eat("(")){let e=Qr(r);return r.eat(")")||r.err("Missing closing paren"),e}else if(/\W/.test(r.next))r.err("Unexpected token '"+r.next+"'");else{let e=jo(r,r.next).map(t=>(r.inline==null?r.inline=t.isInline:r.inline!=t.isInline&&r.err("Mixing inline and block content"),{type:"name",value:t}));return r.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Uo(r){let e=[[]];return i(s(r,0),t()),e;function t(){return e.push([])-1}function n(o,l,a){let f={term:a,to:l};return e[o].push(f),f}function i(o,l){o.forEach(a=>a.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((a,f)=>a.concat(s(f,l)),[]);if(o.type=="seq")for(let a=0;;a++){let f=s(o.exprs[a],l);if(a==o.exprs.length-1)return f;i(f,l=t())}else if(o.type=="star"){let a=t();return n(l,a),i(s(o.expr,a),a),[n(a)]}else if(o.type=="plus"){let a=t();return i(s(o.expr,l),a),i(s(o.expr,a),a),[n(a)]}else{if(o.type=="opt")return[n(l)].concat(s(o.expr,l));if(o.type=="range"){let a=l;for(let f=0;f{r[o].forEach(({term:l,to:a})=>{if(!l)return;let f;for(let c=0;c{f||i.push([l,f=[]]),f.indexOf(c)==-1&&f.push(c)})})});let s=e[n.join(",")]=new be(n.indexOf(r.length-1)>-1);for(let o=0;o-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tn[s]=new st(s,t,o));let i=t.spec.topNode||"doc";if(!n[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!n.text)throw new RangeError("Every schema needs a 'text' type");for(let s in n.text.attrs)throw new RangeError("The text node type should not have attributes");return n}},Rn=class{constructor(e){this.hasDefault=Object.prototype.hasOwnProperty.call(e,"default"),this.default=e.default}get isRequired(){return!this.hasDefault}},He=class{constructor(e,t,n,i){this.name=e,this.rank=t,this.schema=n,this.spec=i,this.attrs=ni(i.attrs),this.excluded=null;let s=ei(this.attrs);this.instance=s?new C(this,s):null}create(e=null){return!e&&this.instance?this.instance:new C(this,ti(this.attrs,e))}static compile(e,t){let n=Object.create(null),i=0;return e.forEach((s,o)=>n[s]=new He(s,i++,t,o)),n}removeFromSet(e){for(var t=0;t-1}},Ue=class{constructor(e){this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=wn.from(e.nodes),t.marks=wn.from(e.marks||{}),this.nodes=st.compile(this.spec.nodes,this),this.marks=He.compile(this.spec.marks,this);let n=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let s=this.nodes[i],o=s.spec.content||"",l=s.spec.marks;s.contentMatch=n[o]||(n[o]=be.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.markSet=l=="_"?null:l?Jr(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:Jr(this,o.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,n,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof st){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,n,i)}text(e,t){let n=this.nodes.text;return new it(n,n.defaultAttrs,e,C.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return _.fromJSON(this,e)}markFromJSON(e){return C.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function Jr(r,e){let t=[];for(let n=0;n-1)&&t.push(o=a)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[n]+"'")}return t}var ae=class{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[],t.forEach(n=>{n.tag?this.tags.push(n):n.style&&this.styles.push(n)}),this.normalizeLists=!this.tags.some(n=>{if(!/^(ul|ol)\b/.test(n.tag)||!n.node)return!1;let i=e.nodes[n.node];return i.contentMatch.matchType(i)})}parse(e,t={}){let n=new Zt(this,t,!1);return n.addAll(e,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new Zt(this,t,!0);return n.addAll(e,t.from,t.to),b.maxOpen(n.finish())}matchTag(e,t,n){for(let i=n?this.tags.indexOf(n)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(o.getAttrs){let a=o.getAttrs(t);if(a===!1)continue;o.attrs=a||void 0}return o}}}static schemaRules(e){let t=[];function n(i){let s=i.priority==null?50:i.priority,o=0;for(;o{n(o=qr(o)),o.mark||o.ignore||o.clearMark||(o.mark=i)})}for(let i in e.nodes){let s=e.nodes[i].spec.parseDOM;s&&s.forEach(o=>{n(o=qr(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new ae(e,ae.schemaRules(e)))}},ri={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Go={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},ii={ol:!0,ul:!0},Xt=1,Qt=2,Ct=4;function Wr(r,e,t){return e!=null?(e?Xt:0)|(e==="full"?Qt:0):r&&r.whitespace=="pre"?Xt|Qt:t&~Ct}var rt=class{constructor(e,t,n,i,s,o,l){this.type=e,this.attrs=t,this.marks=n,this.pendingMarks=i,this.solid=s,this.options=l,this.content=[],this.activeMarks=C.none,this.stashMarks=[],this.match=o||(l&Ct?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(g.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let n=this.type.contentMatch,i;return(i=n.findWrapping(e.type))?(this.match=n,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Xt)){let n=this.content[this.content.length-1],i;if(n&&n.isText&&(i=/[ \t\r\n\u000c]+$/.exec(n.text))){let s=n;n.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-i[0].length))}}let t=g.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(g.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}popFromStashMark(e){for(let t=this.stashMarks.length-1;t>=0;t--)if(e.eq(this.stashMarks[t]))return this.stashMarks.splice(t,1)[0]}applyPending(e){for(let t=0,n=this.pendingMarks;tthis.addAll(e)),o&&this.sync(l),this.needsBlock=a}else this.withStyleRules(e,()=>{this.addElementByRule(e,s,s.consuming===!1?i:void 0)})}leafFallback(e){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` -`))}ignoreFallback(e){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(e){let t=C.none,n=C.none;for(let i=0;i{o.clearMark(l)&&(n=l.addToSet(n))}):t=this.parser.schema.marks[o.mark].create(o.attrs).addToSet(t),o.consuming===!1)s=o;else break}return[t,n]}addElementByRule(e,t,n){let i,s,o;t.node?(s=this.parser.schema.nodes[t.node],s.isLeaf?this.insertNode(s.create(t.attrs))||this.leafFallback(e):i=this.enter(s,t.attrs||null,t.preserveWhitespace)):(o=this.parser.schema.marks[t.mark].create(t.attrs),this.addPendingMark(o));let l=this.top;if(s&&s.isLeaf)this.findInside(e);else if(n)this.addElement(e,n);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a));else{let a=e;typeof t.contentElement=="string"?a=e.querySelector(t.contentElement):typeof t.contentElement=="function"?a=t.contentElement(e):t.contentElement&&(a=t.contentElement),this.findAround(e,a,!0),this.addAll(a)}i&&this.sync(l)&&this.open--,o&&this.removePendingMark(o,l)}addAll(e,t,n){let i=t||0;for(let s=t?e.childNodes[t]:e.firstChild,o=n==null?null:e.childNodes[n];s!=o;s=s.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(s);this.findAtPoint(e,i)}findPlace(e){let t,n;for(let i=this.open;i>=0;i--){let s=this.nodes[i],o=s.findWrapping(e);if(o&&(!t||t.length>o.length)&&(t=o,n=s,!o.length)||s.solid)break}if(!t)return!1;this.sync(n);for(let i=0;ithis.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let i=n.length-1;i>=0;i--)e+=n[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),n=this.options.context,i=!this.isOpen&&(!n||n.parent.type==this.nodes[0].type),s=-(n?n.depth+1:0)+(i?0:1),o=(l,a)=>{for(;l>=0;l--){let f=t[l];if(f==""){if(l==t.length-1||l==0)continue;for(;a>=s;a--)if(o(l-1,a))return!0;return!1}else{let c=a>0||a==0&&i?this.nodes[a].type:n&&a>=s?n.node(a-s).type:null;if(!c||c.name!=f&&c.groups.indexOf(f)==-1)return!1;a--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let t in this.parser.schema.nodes){let n=this.parser.schema.nodes[t];if(n.isTextblock&&n.defaultAttrs)return n}}addPendingMark(e){let t=tl(e,this.top.pendingMarks);t&&this.top.stashMarks.push(t),this.top.pendingMarks=e.addToSet(this.top.pendingMarks)}removePendingMark(e,t){for(let n=this.open;n>=0;n--){let i=this.nodes[n];if(i.pendingMarks.lastIndexOf(e)>-1)i.pendingMarks=e.removeFromSet(i.pendingMarks);else{i.activeMarks=e.removeFromSet(i.activeMarks);let o=i.popFromStashMark(e);o&&i.type&&i.type.allowsMarkType(o.type)&&(i.activeMarks=o.addToSet(i.activeMarks))}if(i==t)break}}};function Xo(r){for(let e=r.firstChild,t=null;e;e=e.nextSibling){let n=e.nodeType==1?e.nodeName.toLowerCase():null;n&&ii.hasOwnProperty(n)&&t?(t.appendChild(e),e=t):n=="li"?t=e:n&&(t=null)}}function Qo(r,e){return(r.matches||r.msMatchesSelector||r.webkitMatchesSelector||r.mozMatchesSelector).call(r,e)}function Zo(r){let e=/\s*([\w-]+)\s*:\s*([^;]+)/g,t,n=[];for(;t=e.exec(r);)n.push(t[1],t[2].trim());return n}function qr(r){let e={};for(let t in r)e[t]=r[t];return e}function el(r,e){let t=e.schema.nodes;for(let n in t){let i=t[n];if(!i.allowsMarkType(r))continue;let s=[],o=l=>{s.push(l);for(let a=0;a{if(s.length||o.marks.length){let l=0,a=0;for(;l=0;i--){let s=this.serializeMark(e.marks[i],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(n),n=s.dom)}return n}serializeMark(e,t,n={}){let i=this.marks[e.type.name];return i&&j.renderSpec(En(n),i(e,t))}static renderSpec(e,t,n=null){if(typeof t=="string")return{dom:e.createTextNode(t)};if(t.nodeType!=null)return{dom:t};if(t.dom&&t.dom.nodeType!=null)return t;let i=t[0],s=i.indexOf(" ");s>0&&(n=i.slice(0,s),i=i.slice(s+1));let o,l=n?e.createElementNS(n,i):e.createElement(i),a=t[1],f=1;if(a&&typeof a=="object"&&a.nodeType==null&&!Array.isArray(a)){f=2;for(let c in a)if(a[c]!=null){let h=c.indexOf(" ");h>0?l.setAttributeNS(c.slice(0,h),c.slice(h+1),a[c]):l.setAttribute(c,a[c])}}for(let c=f;cf)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}else{let{dom:u,contentDOM:p}=j.renderSpec(e,h,n);if(l.appendChild(u),p){if(o)throw new RangeError("Multiple content holes");o=p}}}return{dom:l,contentDOM:o}}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new j(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=Kr(e.nodes);return t.text||(t.text=n=>n.text),t}static marksFromSchema(e){return Kr(e.marks)}};function Kr(r){let e={};for(let t in r){let n=r[t].spec.toDOM;n&&(e[t]=n)}return e}function En(r){return r.document||window.document}var li=65535,ai=Math.pow(2,16);function nl(r,e){return r+e*ai}function si(r){return r&li}function rl(r){return(r-(r&li))/ai}var fi=1,ci=2,en=4,hi=8,Nt=class{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(this.delInfo&hi)>0}get deletedBefore(){return(this.delInfo&(fi|en))>0}get deletedAfter(){return(this.delInfo&(ci|en))>0}get deletedAcross(){return(this.delInfo&en)>0}},L=class{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&L.empty)return L.empty}recover(e){let t=0,n=si(e);if(!this.inverted)for(let i=0;ie)break;let f=this.ranges[l+s],c=this.ranges[l+o],h=a+f;if(e<=h){let u=f?e==a?-1:e==h?1:t:t,p=a+i+(u<0?0:c);if(n)return p;let d=e==(t<0?a:h)?null:nl(l/3,e-a),m=e==a?ci:e==h?fi:en;return(t<0?e!=a:e!=h)&&(m|=hi),new Nt(p,m,d)}i+=c-f}return n?e+i:new Nt(e+i,0,null)}touches(e,t){let n=0,i=si(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;le)break;let f=this.ranges[l+s],c=a+f;if(e<=c&&l==i*3)return!0;n+=this.ranges[l+o]-f}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let i=0,s=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?n-i-1:void 0)}}invert(){let e=new ke;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;ns&&a!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return T.fromReplace(e,this.from,this.to,s)}invert(){return new X(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new fe(t.pos,n.pos,this.mark)}merge(e){return e instanceof fe&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new fe(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new fe(t.from,t.to,e.markFromJSON(t.mark))}};v.jsonID("addMark",fe);var X=class extends v{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new b(Vn(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return T.fromReplace(e,this.from,this.to,n)}invert(){return new fe(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new X(t.pos,n.pos,this.mark)}merge(e){return e instanceof X&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new X(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new X(t.from,t.to,e.markFromJSON(t.mark))}};v.jsonID("removeMark",X);var ce=class extends v{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return T.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return T.fromReplace(e,this.pos,this.pos+1,new b(g.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let n=this.mark.addToSet(t.marks);if(n.length==t.marks.length){for(let i=0;in.pos?null:new D(t.pos,n.pos,i,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new D(t.from,t.to,t.gapFrom,t.gapTo,b.fromJSON(e,t.slice),t.insert,!!t.structure)}};v.jsonID("replaceAround",D);function Bn(r,e,t){let n=r.resolve(e),i=t-e,s=n.depth;for(;i>0&&s>0&&n.indexAfter(s)==n.node(s).childCount;)s--,i--;if(i>0){let o=n.node(s).maybeChild(n.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}function il(r,e,t,n){let i=[],s=[],o,l;r.doc.nodesBetween(e,t,(a,f,c)=>{if(!a.isInline)return;let h=a.marks;if(!n.isInSet(h)&&c.type.allowsMarkType(n.type)){let u=Math.max(f,e),p=Math.min(f+a.nodeSize,t),d=n.addToSet(h);for(let m=0;mr.step(a)),s.forEach(a=>r.step(a))}function sl(r,e,t,n){let i=[],s=0;r.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline)return;s++;let a=null;if(n instanceof He){let f=o.marks,c;for(;c=n.isInSet(f);)(a||(a=[])).push(c),f=c.removeFromSet(f)}else n?n.isInSet(o.marks)&&(a=[n]):a=o.marks;if(a&&a.length){let f=Math.min(l+o.nodeSize,t);for(let c=0;cr.step(new X(o.from,o.to,o.style)))}function ol(r,e,t,n=t.contentMatch){let i=r.doc.nodeAt(e),s=[],o=e+1;for(let l=0;l=0;l--)r.step(s[l])}function ll(r,e,t){return(e==0||r.canReplace(e,r.childCount))&&(t==r.childCount||r.canReplace(0,t))}function lt(r){let t=r.parent.content.cutByIndex(r.startIndex,r.endIndex);for(let n=r.depth;;--n){let i=r.$from.node(n),s=r.$from.index(n),o=r.$to.indexAfter(n);if(nt;d--)m||n.index(d)>0?(m=!0,c=g.from(n.node(d).copy(c)),h++):a--;let u=g.empty,p=0;for(let d=s,m=!1;d>t;d--)m||i.after(d+1)=0;o--){if(n.size){let l=t[o].type.contentMatch.matchFragment(n);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}n=g.from(t[o].type.create(t[o].attrs,n))}let i=e.start,s=e.end;r.step(new D(i,s,i,s,new b(n,0,0),t.length,!0))}function ul(r,e,t,n,i){if(!n.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=r.steps.length;r.doc.nodesBetween(e,t,(o,l)=>{if(o.isTextblock&&!o.hasMarkup(n,i)&&dl(r.doc,r.mapping.slice(s).map(l),n)){r.clearIncompatible(r.mapping.slice(s).map(l,1),n);let a=r.mapping.slice(s),f=a.map(l,1),c=a.map(l+o.nodeSize,1);return r.step(new D(f,c,f+1,c-1,new b(g.from(n.create(i,null,o.marks)),0,0),1,!0)),!1}})}function dl(r,e,t){let n=r.resolve(e),i=n.index();return n.parent.canReplaceWith(i,i+1,t)}function pl(r,e,t,n,i){let s=r.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let o=t.create(n,null,i||s.marks);if(s.isLeaf)return r.replaceWith(e,e+s.nodeSize,o);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);r.step(new D(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new b(g.from(o),0,0),1,!0))}function Re(r,e,t=1,n){let i=r.resolve(e),s=i.depth-t,o=n&&n[n.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let f=i.depth-1,c=t-2;f>s;f--,c--){let h=i.node(f),u=i.index(f);if(h.type.spec.isolating)return!1;let p=h.content.cutByIndex(u,h.childCount),d=n&&n[c+1];d&&(p=p.replaceChild(0,d.type.create(d.attrs)));let m=n&&n[c]||h;if(!h.canReplace(u+1,h.childCount)||!m.type.validContent(p))return!1}let l=i.indexAfter(s),a=n&&n[0];return i.node(s).canReplaceWith(l,l,a?a.type:i.node(s+1).type)}function ml(r,e,t=1,n){let i=r.doc.resolve(e),s=g.empty,o=g.empty;for(let l=i.depth,a=i.depth-t,f=t-1;l>a;l--,f--){s=g.from(i.node(l).copy(s));let c=n&&n[f];o=g.from(c?c.type.create(c.attrs,o):i.node(l).copy(o))}r.step(new A(e,e,new b(s.append(o),t,t),!0))}function Tt(r,e){let t=r.resolve(e),n=t.index();return gl(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(n,n+1)}function gl(r,e){return!!(r&&e&&!r.isLeaf&&r.canAppend(e))}function yl(r,e,t){let n=new A(e-t,e+t,b.empty,!0);r.step(n)}function bl(r,e,t){let n=r.resolve(e);if(n.parent.canReplaceWith(n.index(),n.index(),t))return e;if(n.parentOffset==0)for(let i=n.depth-1;i>=0;i--){let s=n.index(i);if(n.node(i).canReplaceWith(s,s,t))return n.before(i+1);if(s>0)return null}if(n.parentOffset==n.parent.content.size)for(let i=n.depth-1;i>=0;i--){let s=n.indexAfter(i);if(n.node(i).canReplaceWith(s,s,t))return n.after(i+1);if(s=0;o--){let l=o==n.depth?0:n.pos<=(n.start(o+1)+n.end(o+1))/2?-1:1,a=n.index(o)+(l>0?1:0),f=n.node(o),c=!1;if(s==1)c=f.canReplace(a,a,i);else{let h=f.contentMatchAt(a).findWrapping(i.firstChild.type);c=h&&f.canReplaceWith(a,a,h[0])}if(c)return l==0?n.pos:l<0?n.before(o+1):n.after(o+1)}return null}function sn(r,e,t=e,n=b.empty){if(e==t&&!n.size)return null;let i=r.resolve(e),s=r.resolve(t);return ui(i,s,n)?new A(e,t,n):new Fn(i,s,n).fit()}function ui(r,e,t){return!t.openStart&&!t.openEnd&&r.start()==e.start()&&r.parent.canReplace(r.index(),e.index(),t.content)}var Fn=class{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=g.empty;for(let i=0;i<=e.depth;i++){let s=e.node(i);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=g.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let f=this.findFittable();f?this.placeNodes(f):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,n=this.$from,i=this.close(e<0?this.$to:n.doc.resolve(e));if(!i)return null;let s=this.placed,o=n.depth,l=i.depth;for(;o&&l&&s.childCount==1;)s=s.firstChild.content,o--,l--;let a=new b(s,o,l);return e>-1?new D(n.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||n.pos!=this.$to.pos?new A(n.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,i=this.unplaced.openEnd;n1&&(i=0),s.type.spec.isolating&&i<=n){e=n;break}t=s.content}for(let t=1;t<=2;t++)for(let n=t==1?e:this.unplaced.openStart;n>=0;n--){let i,s=null;n?(s=Pn(this.unplaced.content,n-1).firstChild,i=s.content):i=this.unplaced.content;let o=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:f}=this.frontier[l],c,h=null;if(t==1&&(o?f.matchType(o.type)||(h=f.fillBefore(g.from(o),!1)):s&&a.compatibleContent(s.type)))return{sliceDepth:n,frontierDepth:l,parent:s,inject:h};if(t==2&&o&&(c=f.findWrapping(o.type)))return{sliceDepth:n,frontierDepth:l,parent:s,wrap:c};if(s&&f.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced,i=Pn(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new b(e,t+1,Math.max(n,i.size+t>=e.size-n?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,i=Pn(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new b(Ot(e,t-1,1),t-1,s?t-1:n)}else this.unplaced=new b(Ot(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:i,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let m=0;m1||a==0||m.content.size)&&(h=y,c.push(di(m.mark(u.allowedMarks(m.marks)),f==1?a:0,f==l.childCount?p:-1)))}let d=f==l.childCount;d||(p=-1),this.placed=wt(this.placed,t,g.from(c)),this.frontier[t].match=h,d&&p<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,y=l;m1&&i==this.$to.end(--n);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:i}=this.frontier[t],s=t=0;l--){let{match:a,type:f}=this.frontier[l],c=zn(e,l,f,a,!0);if(!c||c.childCount)continue e}return{depth:t,fit:o,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=wt(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let i=e.node(n),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(n));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,t=null,n){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=wt(this.placed,this.depth,g.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(g.empty,!0);t.childCount&&(this.placed=wt(this.placed,this.frontier.length,t))}};function Ot(r,e,t){return e==0?r.cutByIndex(t,r.childCount):r.replaceChild(0,r.firstChild.copy(Ot(r.firstChild.content,e-1,t)))}function wt(r,e,t){return e==0?r.append(t):r.replaceChild(r.childCount-1,r.lastChild.copy(wt(r.lastChild.content,e-1,t)))}function Pn(r,e){for(let t=0;t1&&(n=n.replaceChild(0,di(n.firstChild,e-1,n.childCount==1?t-1:0))),e>0&&(n=r.type.contentMatch.fillBefore(n).append(n),t<=0&&(n=n.append(r.type.contentMatch.matchFragment(n).fillBefore(g.empty,!0)))),r.copy(n)}function zn(r,e,t,n,i){let s=r.node(e),o=i?r.indexAfter(e):r.index(e);if(o==s.childCount&&!t.compatibleContent(s.type))return null;let l=n.fillBefore(s.content,!0,o);return l&&!kl(t,s.content,o)?l:null}function kl(r,e,t){for(let n=t;n0;u--,p--){let d=i.node(u).type.spec;if(d.defining||d.definingAsContext||d.isolating)break;o.indexOf(u)>-1?l=u:i.before(u)==p&&o.splice(1,0,-u)}let a=o.indexOf(l),f=[],c=n.openStart;for(let u=n.content,p=0;;p++){let d=u.firstChild;if(f.push(d),p==n.openStart)break;u=d.content}for(let u=c-1;u>=0;u--){let p=f[u],d=xl(p.type);if(d&&!p.sameMarkup(i.node(Math.abs(l)-1)))c=u;else if(d||!p.type.isTextblock)break}for(let u=n.openStart;u>=0;u--){let p=(u+c+1)%(n.openStart+1),d=f[p];if(!!d)for(let m=0;m=0&&(r.replace(e,t,n),!(r.steps.length>h));u--){let p=o[u];p<0||(e=i.before(p),t=s.after(p))}}function pi(r,e,t,n,i){if(en){let s=i.contentMatchAt(0),o=s.fillBefore(r).append(r);r=o.append(s.matchFragment(o).fillBefore(g.empty,!0))}return r}function Ml(r,e,t,n){if(!n.isInline&&e==t&&r.doc.resolve(e).parent.content.size){let i=bl(r.doc,e,n.type);i!=null&&(e=t=i)}r.replaceRange(e,t,new b(g.from(n),0,0))}function Cl(r,e,t){let n=r.doc.resolve(e),i=r.doc.resolve(t),s=mi(n,i);for(let o=0;o0&&(a||n.node(l-1).canReplace(n.index(l-1),i.indexAfter(l-1))))return r.delete(n.before(l),i.after(l))}for(let o=1;o<=n.depth&&o<=i.depth;o++)if(e-n.start(o)==n.depth-o&&t>n.end(o)&&i.end(o)-t!=i.depth-o)return r.delete(n.before(o),t);r.delete(e,t)}function mi(r,e){let t=[],n=Math.min(r.depth,e.depth);for(let i=n;i>=0;i--){let s=r.start(i);if(se.pos+(e.depth-i)||r.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==r.depth&&i==e.depth&&r.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&t.push(i)}return t}var Ie=class extends v{constructor(e,t,n){super(),this.pos=e,this.attr=t,this.value=n}apply(e){let t=e.nodeAt(this.pos);if(!t)return T.fail("No node at attribute step's position");let n=Object.create(null);for(let s in t.attrs)n[s]=t.attrs[s];n[this.attr]=this.value;let i=t.type.create(n,null,t.marks);return T.fromReplace(e,this.pos,this.pos+1,new b(g.from(i),0,t.isLeaf?0:1))}getMap(){return L.empty}invert(e){return new Ie(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Ie(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new Ie(t.pos,t.attr,t.value)}};v.jsonID("attr",Ie);var _e=class extends v{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return T.ok(n)}getMap(){return L.empty}invert(e){return new _e(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new _e(t.attr,t.value)}};v.jsonID("docAttr",_e);var ot=class extends Error{};ot=function r(e){let t=Error.call(this,e);return t.__proto__=r.prototype,t};ot.prototype=Object.create(Error.prototype);ot.prototype.constructor=ot;ot.prototype.name="TransformError";var tn=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new ke}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new ot(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,n=b.empty){let i=sn(this.doc,e,t,n);return i&&this.step(i),this}replaceWith(e,t,n){return this.replace(e,t,new b(g.from(n),0,0))}delete(e,t){return this.replace(e,t,b.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return Sl(this,e,t,n),this}replaceRangeWith(e,t,n){return Ml(this,e,t,n),this}deleteRange(e,t){return Cl(this,e,t),this}lift(e,t){return al(this,e,t),this}join(e,t=1){return yl(this,e,t),this}wrap(e,t){return hl(this,e,t),this}setBlockType(e,t=e,n,i=null){return ul(this,e,t,n,i),this}setNodeMarkup(e,t,n=null,i){return pl(this,e,t,n,i),this}setNodeAttribute(e,t,n){return this.step(new Ie(e,t,n)),this}setDocAttribute(e,t){return this.step(new _e(e,t)),this}addNodeMark(e,t){return this.step(new ce(e,t)),this}removeNodeMark(e,t){if(!(t instanceof C)){let n=this.doc.nodeAt(e);if(!n)throw new RangeError("No node at position "+e);if(t=t.isInSet(n.marks),!t)return this}return this.step(new Ae(e,t)),this}split(e,t=1,n){return ml(this,e,t,n),this}addMark(e,t,n){return il(this,e,t,n),this}removeMark(e,t,n){return sl(this,e,t,n),this}clearIncompatible(e,t,n){return ol(this,e,t,n),this}};var Ln=Object.create(null),S=class{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new Wn(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t=0;s--){let o=t<0?at(e.node(0),e.node(s),e.before(s+1),e.index(s),t,n):at(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,n);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new P(e.node(0))}static atStart(e){return at(e,e,0,0,1)||new P(e)}static atEnd(e){return at(e,e,e.content.size,e.childCount,-1)||new P(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=Ln[t.type];if(!n)throw new RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in Ln)throw new RangeError("Duplicate use of selection JSON ID "+e);return Ln[e]=t,t.prototype.jsonID=e,t}getBookmark(){return O.between(this.$anchor,this.$head).getBookmark()}};S.prototype.visible=!0;var Wn=class{constructor(e,t){this.$from=e,this.$to=t}},gi=!1;function yi(r){!gi&&!r.parent.inlineContent&&(gi=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+r.parent.type.name+")"))}var O=class extends S{constructor(e,t=e){yi(e),yi(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let n=e.resolve(t.map(this.head));if(!n.parent.inlineContent)return S.near(n);let i=e.resolve(t.map(this.anchor));return new O(i.parent.inlineContent?i:n,n)}replace(e,t=b.empty){if(super.replace(e,t),t==b.empty){let n=this.$from.marksAcross(this.$to);n&&e.ensureMarks(n)}}eq(e){return e instanceof O&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new ft(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new O(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,n=t){let i=e.resolve(t);return new this(i,n==t?i:e.resolve(n))}static between(e,t,n){let i=e.pos-t.pos;if((!n||i)&&(n=i>=0?1:-1),!t.parent.inlineContent){let s=S.findFrom(t,n,!0)||S.findFrom(t,-n,!0);if(s)t=s.$head;else return S.near(t,n)}return e.parent.inlineContent||(i==0?e=t:(e=(S.findFrom(e,-n,!0)||S.findFrom(e,n,!0)).$anchor,e.pos0?0:1);i>0?o=0;o+=i){let l=e.child(o);if(l.isAtom){if(!s&&x.isSelectable(l))return x.create(r,t-(i<0?l.nodeSize:0))}else{let a=at(r,l,t+i,i<0?l.childCount:0,i,s);if(a)return a}t+=l.nodeSize*i}return null}function bi(r,e,t){let n=r.steps.length-1;if(n{o==null&&(o=c)}),r.setSelection(S.near(r.doc.resolve(o),t))}var ki=1,on=2,xi=4,qn=class extends tn{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=on,this}ensureMarks(e){return C.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&on)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~on,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let n=this.selection;return t&&(e=e.mark(this.storedMarks||(n.empty?n.$from.marks():n.$from.marksAcross(n.$to)||C.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(n==null&&(n=t),n=n==null?t:n,!e)return this.deleteRange(t,n);let s=this.storedMarks;if(!s){let o=this.doc.resolve(t);s=n==t?o.marks():o.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,i.text(e,s)),this.selection.empty||this.setSelection(S.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=xi,this}get scrolledIntoView(){return(this.updated&xi)>0}};function Si(r,e){return!e||!r?r:r.bind(e)}var Ye=class{constructor(e,t,n){this.name=e,this.init=Si(t.init,n),this.apply=Si(t.apply,n)}},wl=[new Ye("doc",{init(r){return r.doc||r.schema.topNodeType.createAndFill()},apply(r){return r.doc}}),new Ye("selection",{init(r,e){return r.selection||S.atStart(e.doc)},apply(r){return r.selection}}),new Ye("storedMarks",{init(r){return r.storedMarks||null},apply(r,e,t,n){return n.selection.$cursor?r.storedMarks:null}}),new Ye("scrollToSelection",{init(){return 0},apply(r,e){return r.scrolledIntoView?e+1:e}})],Dt=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=wl.slice(),t&&t.forEach(n=>{if(this.pluginsByKey[n.key])throw new RangeError("Adding different instances of a keyed plugin ("+n.key+")");this.plugins.push(n),this.pluginsByKey[n.key]=n,n.spec.state&&this.fields.push(new Ye(n.key,n.spec.state,n))})}},xe=class{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let n=0;nn.toJSON())),e&&typeof e=="object")for(let n in e){if(n=="doc"||n=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[n],s=i.spec.state;s&&s.toJSON&&(t[n]=s.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,n){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Dt(e.schema,e.plugins),s=new xe(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=_.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=S.fromJSON(s.doc,t.selection);else if(o.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(n)for(let l in n){let a=n[l],f=a.spec.state;if(a.key==o.name&&f&&f.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[o.name]=f.fromJSON.call(a,e,t[l],s);return}}s[o.name]=o.init(e,s)}}),s}};function Mi(r,e,t){for(let n in r){let i=r[n];i instanceof Function?i=i.bind(e):n=="handleDOMEvents"&&(i=Mi(i,e,{})),t[n]=i}return t}var H=class{constructor(e){this.spec=e,this.props={},e.props&&Mi(e.props,this,this.props),this.key=e.key?e.key.key:Ci("plugin")}getState(e){return e[this.key]}},Jn=Object.create(null);function Ci(r){return r in Jn?r+"$"+ ++Jn[r]:(Jn[r]=0,r+"$")}var It=class{constructor(e="key"){this.key=Ci(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var wi=(r,e)=>r.selection.empty?!1:(e&&e(r.tr.deleteSelection().scrollIntoView()),!0);function Nl(r,e){let{$cursor:t}=r.selection;return!t||(e?!e.endOfTextblock("backward",r):t.parentOffset>0)?null:t}var Tl=(r,e,t)=>{let n=Nl(r,t);if(!n)return!1;let i=Ni(n);if(!i){let o=n.blockRange(),l=o&<(o);return l==null?!1:(e&&e(r.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(!s.type.spec.isolating&&Di(r,i,e))return!0;if(n.parent.content.size==0&&(ct(s,"end")||x.isSelectable(s))){let o=sn(r.doc,n.before(),n.after(),b.empty);if(o&&o.slice.size{let{$head:n,empty:i}=r.selection,s=n;if(!i)return!1;if(n.parent.isTextblock){if(t?!t.endOfTextblock("backward",r):n.parentOffset>0)return!1;s=Ni(n)}let o=s&&s.nodeBefore;return!o||!x.isSelectable(o)?!1:(e&&e(r.tr.setSelection(x.create(r.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function Ni(r){if(!r.parent.type.spec.isolating)for(let e=r.depth-1;e>=0;e--){if(r.index(e)>0)return r.doc.resolve(r.before(e+1));if(r.node(e).type.spec.isolating)break}return null}function El(r,e){let{$cursor:t}=r.selection;return!t||(e?!e.endOfTextblock("forward",r):t.parentOffset{let n=El(r,t);if(!n)return!1;let i=Ti(n);if(!i)return!1;let s=i.nodeAfter;if(Di(r,i,e))return!0;if(n.parent.content.size==0&&(ct(s,"start")||x.isSelectable(s))){let o=sn(r.doc,n.before(),n.after(),b.empty);if(o&&o.slice.size{let{$head:n,empty:i}=r.selection,s=n;if(!i)return!1;if(n.parent.isTextblock){if(t?!t.endOfTextblock("forward",r):n.parentOffset=0;e--){let t=r.node(e);if(r.index(e)+1{let{$head:t,$anchor:n}=r.selection;return!t.parent.type.spec.code||!t.sameParent(n)?!1:(e&&e(r.tr.insertText(` -`).scrollIntoView()),!0)};function $n(r){for(let e=0;e{let{$head:t,$anchor:n}=r.selection;if(!t.parent.type.spec.code||!t.sameParent(n))return!1;let i=t.node(-1),s=t.indexAfter(-1),o=$n(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(e){let l=t.after(),a=r.tr.replaceWith(l,l,o.createAndFill());a.setSelection(S.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},vl=(r,e)=>{let t=r.selection,{$from:n,$to:i}=t;if(t instanceof P||n.parent.inlineContent||i.parent.inlineContent)return!1;let s=$n(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let o=(!n.parentOffset&&i.index(){let{$cursor:t}=r.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let s=t.before();if(Re(r.doc,s))return e&&e(r.tr.split(s).scrollIntoView()),!0}let n=t.blockRange(),i=n&<(n);return i==null?!1:(e&&e(r.tr.lift(n,i).scrollIntoView()),!0)};function zl(r){return(e,t)=>{let{$from:n,$to:i}=e.selection;if(e.selection instanceof x&&e.selection.node.isBlock)return!n.parentOffset||!Re(e.doc,n.pos)?!1:(t&&t(e.tr.split(n.pos).scrollIntoView()),!0);if(!n.parent.isBlock)return!1;if(t){let s=i.parentOffset==i.parent.content.size,o=e.tr;(e.selection instanceof O||e.selection instanceof P)&&o.deleteSelection();let l=n.depth==0?null:$n(n.node(-1).contentMatchAt(n.indexAfter(-1))),a=r&&r(i.parent,s),f=a?[a]:s&&l?[{type:l}]:void 0,c=Re(o.doc,o.mapping.map(n.pos),1,f);if(!f&&!c&&Re(o.doc,o.mapping.map(n.pos),1,l?[{type:l}]:void 0)&&(l&&(f=[{type:l}]),c=!0),c&&(o.split(o.mapping.map(n.pos),1,f),!s&&!n.parentOffset&&n.parent.type!=l)){let h=o.mapping.map(n.before()),u=o.doc.resolve(h);l&&n.node(-1).canReplaceWith(u.index(),u.index()+1,l)&&o.setNodeMarkup(o.mapping.map(n.before()),l)}t(o.scrollIntoView())}return!0}}var Bl=zl();var Fl=(r,e)=>(e&&e(r.tr.setSelection(new P(r.doc))),!0);function Vl(r,e,t){let n=e.nodeBefore,i=e.nodeAfter,s=e.index();return!n||!i||!n.type.compatibleContent(i.type)?!1:!n.content.size&&e.parent.canReplace(s-1,s)?(t&&t(r.tr.delete(e.pos-n.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(i.isTextblock||Tt(r.doc,e.pos))?!1:(t&&t(r.tr.clearIncompatible(e.pos,n.type,n.contentMatchAt(n.childCount)).join(e.pos).scrollIntoView()),!0)}function Di(r,e,t){let n=e.nodeBefore,i=e.nodeAfter,s,o;if(n.type.spec.isolating||i.type.spec.isolating)return!1;if(Vl(r,e,t))return!0;let l=e.parent.canReplace(e.index(),e.index()+1);if(l&&(s=(o=n.contentMatchAt(n.childCount)).findWrapping(i.type))&&o.matchType(s[0]||i.type).validEnd){if(t){let h=e.pos+i.nodeSize,u=g.empty;for(let m=s.length-1;m>=0;m--)u=g.from(s[m].create(null,u));u=g.from(n.copy(u));let p=r.tr.step(new D(e.pos-1,h,e.pos,h,new b(u,1,0),s.length,!0)),d=h+2*s.length;Tt(p.doc,d)&&p.join(d),t(p.scrollIntoView())}return!0}let a=S.findFrom(e,1),f=a&&a.$from.blockRange(a.$to),c=f&<(f);if(c!=null&&c>=e.depth)return t&&t(r.tr.lift(f,c).scrollIntoView()),!0;if(l&&ct(i,"start",!0)&&ct(n,"end")){let h=n,u=[];for(;u.push(h),!h.isTextblock;)h=h.lastChild;let p=i,d=1;for(;!p.isTextblock;p=p.firstChild)d++;if(h.canReplace(h.childCount,h.childCount,p.content)){if(t){let m=g.empty;for(let k=u.length-1;k>=0;k--)m=g.from(u[k].copy(m));let y=r.tr.step(new D(e.pos-u.length,e.pos+i.nodeSize,e.pos+d,e.pos+i.nodeSize-d,new b(m,u.length,0),0,!0));t(y.scrollIntoView())}return!0}}return!1}function Ei(r){return function(e,t){let n=e.selection,i=r<0?n.$from:n.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return i.node(s).isTextblock?(t&&t(e.tr.setSelection(O.create(e.doc,r<0?i.start(s):i.end(s)))),!0):!1}}var Ll=Ei(-1),Jl=Ei(1);function ln(r,e=null){return function(t,n){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=o&&nn(o,r,e);return l?(n&&n(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function Hn(r,e=null){return function(t,n){let i=!1;for(let s=0;s{if(i)return!1;if(!(!a.isTextblock||a.hasMarkup(r,e)))if(a.type==r)i=!0;else{let c=t.doc.resolve(f),h=c.index();i=c.parent.canReplaceWith(h,h+1,r)}})}if(!i)return!1;if(n){let s=t.tr;for(let o=0;o{if(o)return!1;o=l.inlineContent&&l.type.allowsMarkType(t)}),o)return!0}return!1}function ne(r,e=null){return function(t,n){let{empty:i,$cursor:s,ranges:o}=t.selection;if(i&&!s||!Wl(t.doc,o,r))return!1;if(n)if(s)r.isInSet(t.storedMarks||s.marks())?n(t.tr.removeStoredMark(r)):n(t.tr.addStoredMark(r.create(e)));else{let l=!1,a=t.tr;for(let f=0;!l&&f{let s=o=>{this[i](o)};return e.dom.addEventListener(i,s),{name:i,handler:s}})}destroy(){this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){this.cursorPos!=null&&t.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),t=!e.parent.inlineContent,n;if(t){let l=e.nodeBefore,a=e.nodeAfter;if(l||a){let f=this.editorView.nodeDOM(this.cursorPos-(l?l.nodeSize:0));if(f){let c=f.getBoundingClientRect(),h=l?c.bottom:c.top;l&&a&&(h=(h+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2),n={left:c.left,right:c.right,top:h-this.width/2,bottom:h+this.width/2}}}}if(!n){let l=this.editorView.coordsAtPos(this.cursorPos);n={left:l.left-this.width/2,right:l.left+this.width/2,top:l.top,bottom:l.bottom}}let i=this.editorView.dom.offsetParent;this.element||(this.element=i.appendChild(document.createElement("div")),this.class&&(this.element.className=this.class),this.element.style.cssText="position: absolute; z-index: 50; pointer-events: none;",this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle("prosemirror-dropcursor-block",t),this.element.classList.toggle("prosemirror-dropcursor-inline",!t);let s,o;if(!i||i==document.body&&getComputedStyle(i).position=="static")s=-pageXOffset,o=-pageYOffset;else{let l=i.getBoundingClientRect();s=l.left-i.scrollLeft,o=l.top-i.scrollTop}this.element.style.left=n.left-s+"px",this.element.style.top=n.top-o+"px",this.element.style.width=n.right-n.left+"px",this.element.style.height=n.bottom-n.top+"px"}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),n=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),i=n&&n.type.spec.disableDropCursor,s=typeof i=="function"?i(this.editorView,t,e):i;if(t&&!s){let o=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let l=rn(this.editorView.state.doc,o,this.editorView.dragging.slice);l!=null&&(o=l)}this.setCursor(o),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){(e.target==this.editorView.dom||!this.editorView.dom.contains(e.relatedTarget))&&this.setCursor(null)}};var Me={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:"'"},fn={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Kl=typeof navigator!="undefined"&&/Mac/.test(navigator.platform),$l=typeof navigator!="undefined"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(R=0;R<10;R++)Me[48+R]=Me[96+R]=String(R);var R;for(R=1;R<=24;R++)Me[R+111]="F"+R;var R;for(R=65;R<=90;R++)Me[R]=String.fromCharCode(R+32),fn[R]=String.fromCharCode(R);var R;for(an in Me)fn.hasOwnProperty(an)||(fn[an]=Me[an]);var an;function vi(r){var e=Kl&&r.metaKey&&r.shiftKey&&!r.ctrlKey&&!r.altKey||$l&&r.shiftKey&&r.key&&r.key.length==1||r.key=="Unidentified",t=!e&&r.key||(r.shiftKey?fn:Me)[r.keyCode]||r.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}var jl=typeof navigator!="undefined"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function Hl(r){let e=r.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let n,i,s,o;for(let l=0;l127)&&(s=Me[n.keyCode])&&s!=i){let l=e[_n(s,n)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var J=function(r){for(var e=0;;e++)if(r=r.previousSibling,!r)return e},zt=function(r){let e=r.assignedSlot||r.parentNode;return e&&e.nodeType==11?e.host:e},Pi=null,Oe=function(r,e,t){let n=Pi||(Pi=document.createRange());return n.setEnd(r,t==null?r.nodeValue.length:t),n.setStart(r,e||0),n},tt=function(r,e,t,n){return t&&(zi(r,e,t,n,-1)||zi(r,e,t,n,1))},_l=/^(img|br|input|textarea|hr)$/i;function zi(r,e,t,n,i){for(;;){if(r==t&&e==n)return!0;if(e==(i<0?0:he(r))){let s=r.parentNode;if(!s||s.nodeType!=1||br(r)||_l.test(r.nodeName)||r.contentEditable=="false")return!1;e=J(r)+(i<0?0:1),r=s}else if(r.nodeType==1){if(r=r.childNodes[e+(i<0?-1:0)],r.contentEditable=="false")return!1;e=i<0?he(r):0}else return!1}}function he(r){return r.nodeType==3?r.nodeValue.length:r.childNodes.length}function Yl(r,e,t){for(let n=e==0,i=e==he(r);n||i;){if(r==t)return!0;let s=J(r);if(r=r.parentNode,!r)return!1;n=n&&s==0,i=i&&s==he(r)}}function br(r){let e;for(let t=r;t&&!(e=t.pmViewDesc);t=t.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==r||e.contentDOM==r)}var yn=function(r){return r.focusNode&&tt(r.focusNode,r.focusOffset,r.anchorNode,r.anchorOffset)};function Ge(r,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=r,t.key=t.code=e,t}function Gl(r){let e=r.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function Xl(r,e,t){if(r.caretPositionFromPoint)try{let n=r.caretPositionFromPoint(e,t);if(n)return{node:n.offsetNode,offset:n.offset}}catch(n){}if(r.caretRangeFromPoint){let n=r.caretRangeFromPoint(e,t);if(n)return{node:n.startContainer,offset:n.startOffset}}}var me=typeof navigator!="undefined"?navigator:null,Bi=typeof document!="undefined"?document:null,Fe=me&&me.userAgent||"",tr=/Edge\/(\d+)/.exec(Fe),ps=/MSIE \d/.exec(Fe),nr=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Fe),U=!!(ps||nr||tr),Be=ps?document.documentMode:nr?+nr[1]:tr?+tr[1]:0,ie=!U&&/gecko\/(\d+)/i.test(Fe);ie&&+(/Firefox\/(\d+)/.exec(Fe)||[0,0])[1];var rr=!U&&/Chrome\/(\d+)/.exec(Fe),V=!!rr,Ql=rr?+rr[1]:0,q=!U&&!!me&&/Apple Computer/.test(me.vendor),mt=q&&(/Mobile\/\w+/.test(Fe)||!!me&&me.maxTouchPoints>2),Q=mt||(me?/Mac/.test(me.platform):!1),Zl=me?/Win/.test(me.platform):!1,re=/Android \d/.test(Fe),Jt=!!Bi&&"webkitFontSmoothing"in Bi.documentElement.style,ea=Jt?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function ta(r){return{left:0,right:r.documentElement.clientWidth,top:0,bottom:r.documentElement.clientHeight}}function Ce(r,e){return typeof r=="number"?r:r[e]}function na(r){let e=r.getBoundingClientRect(),t=e.width/r.offsetWidth||1,n=e.height/r.offsetHeight||1;return{left:e.left,right:e.left+r.clientWidth*t,top:e.top,bottom:e.top+r.clientHeight*n}}function Fi(r,e,t){let n=r.someProp("scrollThreshold")||0,i=r.someProp("scrollMargin")||5,s=r.dom.ownerDocument;for(let o=t||r.dom;o;o=zt(o)){if(o.nodeType!=1)continue;let l=o,a=l==s.body,f=a?ta(s):na(l),c=0,h=0;if(e.topf.bottom-Ce(n,"bottom")&&(h=e.bottom-e.top>f.bottom-f.top?e.top+Ce(i,"top")-f.top:e.bottom-f.bottom+Ce(i,"bottom")),e.leftf.right-Ce(n,"right")&&(c=e.right-f.right+Ce(i,"right")),c||h)if(a)s.defaultView.scrollBy(c,h);else{let u=l.scrollLeft,p=l.scrollTop;h&&(l.scrollTop+=h),c&&(l.scrollLeft+=c);let d=l.scrollLeft-u,m=l.scrollTop-p;e={left:e.left-d,top:e.top-m,right:e.right-d,bottom:e.bottom-m}}if(a||/^(fixed|sticky)$/.test(getComputedStyle(o).position))break}}function ra(r){let e=r.dom.getBoundingClientRect(),t=Math.max(0,e.top),n,i;for(let s=(e.left+e.right)/2,o=t+1;o=t-20){n=l,i=a.top;break}}return{refDOM:n,refTop:i,stack:ms(r.dom)}}function ms(r){let e=[],t=r.ownerDocument;for(let n=r;n&&(e.push({dom:n,top:n.scrollTop,left:n.scrollLeft}),r!=t);n=zt(n));return e}function ia({refDOM:r,refTop:e,stack:t}){let n=r?r.getBoundingClientRect().top:0;gs(t,n==0?0:n-e)}function gs(r,e){for(let t=0;t=l){o=Math.max(d.bottom,o),l=Math.min(d.top,l);let m=d.left>e.left?d.left-e.left:d.right=(d.left+d.right)/2?1:0));continue}}else d.top>e.top&&!a&&d.left<=e.left&&d.right>=e.left&&(a=c,f={left:Math.max(d.left,Math.min(d.right,e.left)),top:d.top});!t&&(e.left>=d.right&&e.top>=d.top||e.left>=d.left&&e.top>=d.bottom)&&(s=h+1)}}return!t&&a&&(t=a,i=f,n=0),t&&t.nodeType==3?oa(t,i):!t||n&&t.nodeType==1?{node:r,offset:s}:ys(t,i)}function oa(r,e){let t=r.nodeValue.length,n=document.createRange();for(let i=0;i=(s.left+s.right)/2?1:0)}}return{node:r,offset:0}}function kr(r,e){return r.left>=e.left-1&&r.left<=e.right+1&&r.top>=e.top-1&&r.top<=e.bottom+1}function la(r,e){let t=r.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(o.left+o.right)/2?1:-1}return r.docView.posFromDOM(n,i,s)}function fa(r,e,t,n){let i=-1;for(let s=e,o=!1;s!=r.dom;){let l=r.docView.nearestDesc(s,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent&&!o||!l.contentDOM)){let a=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&!o&&(o=!0,a.left>n.left||a.top>n.top?i=l.posBefore:(a.right-1?i:r.docView.posFromDOM(e,t,-1)}function bs(r,e,t){let n=r.childNodes.length;if(n&&t.tope.top&&i++}let f;Jt&&i&&n.nodeType==1&&(f=n.childNodes[i-1]).nodeType==1&&f.contentEditable=="false"&&f.getBoundingClientRect().top>=e.top&&i--,n==r.dom&&i==n.childNodes.length-1&&n.lastChild.nodeType==1&&e.top>n.lastChild.getBoundingClientRect().bottom?l=r.state.doc.content.size:(i==0||n.nodeType!=1||n.childNodes[i-1].nodeName!="BR")&&(l=fa(r,n,i,e))}l==null&&(l=aa(r,o,e));let a=r.docView.nearestDesc(o,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function Vi(r){return r.top=0&&i==n.nodeValue.length?(a--,c=1):t<0?a--:f++,Rt(ve(Oe(n,a,f),c),c<0)}if(!r.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==he(n))){let a=n.childNodes[i-1];if(a.nodeType==1)return Xn(a.getBoundingClientRect(),!1)}if(s==null&&i=0)}if(s==null&&i&&(t<0||i==he(n))){let a=n.childNodes[i-1],f=a.nodeType==3?Oe(a,he(a)-(o?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(f)return Rt(ve(f,1),!1)}if(s==null&&i=0)}function Rt(r,e){if(r.width==0)return r;let t=e?r.left:r.right;return{top:r.top,bottom:r.bottom,left:t,right:t}}function Xn(r,e){if(r.height==0)return r;let t=e?r.top:r.bottom;return{top:t,bottom:t,left:r.left,right:r.right}}function xs(r,e,t){let n=r.state,i=r.root.activeElement;n!=e&&r.updateState(e),i!=r.dom&&r.focus();try{return t()}finally{n!=e&&r.updateState(n),i!=r.dom&&i&&i.focus()}}function ua(r,e,t){let n=e.selection,i=t=="up"?n.$from:n.$to;return xs(r,e,()=>{let{node:s}=r.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=r.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let o=ks(r,i.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=Oe(l,0,l.nodeValue.length).getClientRects();else continue;for(let f=0;fc.top+1&&(t=="up"?o.top-c.top>(c.bottom-o.top)*2:c.bottom-o.bottom>(o.bottom-c.top)*2))return!1}}return!0})}var da=/[\u0590-\u08ac]/;function pa(r,e,t){let{$head:n}=e.selection;if(!n.parent.isTextblock)return!1;let i=n.parentOffset,s=!i,o=i==n.parent.content.size,l=r.domSelection();return!da.test(n.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:xs(r,e,()=>{let{focusNode:a,focusOffset:f,anchorNode:c,anchorOffset:h}=r.domSelectionRange(),u=l.caretBidiLevel;l.modify("move",t,"character");let p=n.depth?r.docView.domAfterPos(n.before()):r.dom,{focusNode:d,focusOffset:m}=r.domSelectionRange(),y=d&&!p.contains(d.nodeType==1?d:d.parentNode)||a==d&&f==m;try{l.collapse(c,h),a&&(a!=c||f!=h)&&l.extend&&l.extend(a,f)}catch(k){}return u!=null&&(l.caretBidiLevel=u),y})}var Li=null,Ji=null,Wi=!1;function ma(r,e,t){return Li==e&&Ji==t?Wi:(Li=e,Ji=t,Wi=t=="up"||t=="down"?ua(r,e,t):pa(r,e,t))}var Z=0,qi=1,Xe=2,ge=3,nt=class{constructor(e,t,n,i){this.parent=e,this.children=t,this.dom=n,this.contentDOM=i,this.dirty=Z,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tJ(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!1;break}if(s.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!0;break}if(s.nextSibling)break}}return(i==null?n>0:i)?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),o;if(s&&(!t||s.node))if(n&&(o=s.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))n=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let n=t;n;n=n.parent)if(n==this)return t}posFromDOM(e,t,n){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,t,n)}return-1}descAt(e){for(let t=0,n=0;te||o instanceof hn){i=e-s;break}s=l}if(i)return this.children[n].domFromPos(i-this.children[n].border,t);for(let s;n&&!(s=this.children[n-1]).size&&s instanceof cn&&s.side>=0;n--);if(t<=0){let s,o=!0;for(;s=n?this.children[n-1]:null,!(!s||s.dom.parentNode==this.contentDOM);n--,o=!1);return s&&t&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?J(s.dom)+1:0}}else{let s,o=!0;for(;s=n=c&&t<=f-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,c);e=o;for(let h=l;h>0;h--){let u=this.children[h-1];if(u.size&&u.dom.parentNode==this.contentDOM&&!u.emptyChildAt(1)){i=J(u.dom)+1;break}e-=u.size}i==-1&&(i=0)}if(i>-1&&(f>t||l==this.children.length-1)){t=f;for(let c=l+1;cp&&ot){let p=l;l=a,a=p}let u=document.createRange();u.setEnd(a.node,a.offset),u.setStart(l.node,l.offset),f.removeAllRanges(),f.addRange(u)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let n=0,i=0;i=n:en){let l=n+s.border,a=o-s.border;if(e>=l&&t<=a){this.dirty=e==n||t==o?Xe:qi,e==l&&t==a&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=ge:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?Xe:ge}n=o}this.dirty=Xe}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=e==1?Xe:qi;t.dirty{if(!s)return i;if(s.parent)return s.parent.posBeforeChild(s)})),!t.type.spec.raw){if(o.nodeType!=1){let l=document.createElement("span");l.appendChild(o),o=l}o.contentEditable="false",o.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=t,this.widget=t,s=this}matchesWidget(e){return this.dirty==Z&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}},ir=class extends nt{constructor(e,t,n,i){super(e,[],t,null),this.textDOM=n,this.text=i}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}},Ne=class extends nt{constructor(e,t,n,i){super(e,[],n,i),this.mark=t}static create(e,t,n,i){let s=i.nodeViews[t.type.name],o=s&&s(t,i,n);return(!o||!o.dom)&&(o=j.renderSpec(document,t.type.spec.toDOM(t,n))),new Ne(e,t,o.dom,o.contentDOM||o.dom)}parseRule(){return this.dirty&ge||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=ge&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=Z){let n=this.parent;for(;!n.node;)n=n.parent;n.dirty0&&(s=fr(s,0,e,n));for(let l=0;l{if(!a)return o;if(a.parent)return a.parent.posBeforeChild(a)},n,i),c=f&&f.dom,h=f&&f.contentDOM;if(t.isText){if(!c)c=document.createTextNode(t.text);else if(c.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else c||({dom:c,contentDOM:h}=j.renderSpec(document,t.type.spec.toDOM(t)));!h&&!t.isText&&c.nodeName!="BR"&&(c.hasAttribute("contenteditable")||(c.contentEditable="false"),t.type.spec.draggable&&(c.draggable=!0));let u=c;return c=Cs(c,n,t),f?a=new sr(e,t,n,i,c,h||null,u,f,s,o+1):t.isText?new gt(e,t,n,i,c,u,s):new de(e,t,n,i,c,h||null,u,s,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let n=this.children[t];if(this.dom.contains(n.dom.parentNode)){e.contentElement=n.dom.parentNode;break}}e.contentElement||(e.getContent=()=>g.empty)}return e}matchesNode(e,t,n){return this.dirty==Z&&e.eq(this.node)&&lr(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let n=this.node.inlineContent,i=t,s=e.composing?this.localCompositionInfo(e,t):null,o=s&&s.pos>-1?s:null,l=s&&s.pos<0,a=new ar(this,o&&o.node,e);ka(this.node,this.innerDeco,(f,c,h)=>{f.spec.marks?a.syncToMarks(f.spec.marks,n,e):f.type.side>=0&&!h&&a.syncToMarks(c==this.node.childCount?C.none:this.node.child(c).marks,n,e),a.placeWidget(f,e,i)},(f,c,h,u)=>{a.syncToMarks(f.marks,n,e);let p;a.findNodeMatch(f,c,h,u)||l&&e.state.selection.from>i&&e.state.selection.to-1&&a.updateNodeAt(f,c,h,p,e)||a.updateNextNode(f,c,h,e,u,i)||a.addNode(f,c,h,e,i),i+=f.nodeSize}),a.syncToMarks([],n,e),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==Xe)&&(o&&this.protectLocalComposition(e,o),Ss(this.contentDOM,this.children,e),mt&&xa(this.dom))}localCompositionInfo(e,t){let{from:n,to:i}=e.state.selection;if(!(e.state.selection instanceof O)||nt+this.node.content.size)return null;let s=e.domSelectionRange(),o=Sa(s.focusNode,s.focusOffset);if(!o||!this.dom.contains(o.parentNode))return null;if(this.node.inlineContent){let l=o.nodeValue,a=Ma(this.node.content,l,n-t,i-t);return a<0?null:{node:o,pos:a,text:l}}else return{node:o,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:n,text:i}){if(this.getDesc(t))return;let s=t;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let o=new ir(this,s,t,i);e.input.compositionNodes.push(o),this.children=fr(this.children,n,n+i.length,e,o)}update(e,t,n,i){return this.dirty==ge||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,n,i),!0)}updateInner(e,t,n,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=Z}updateOuterDeco(e){if(lr(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,n=this.dom;this.dom=Ms(this.dom,this.nodeDOM,or(this.outerDeco,this.node,t),or(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable")}get domAtom(){return this.node.isAtom}};function Ki(r,e,t,n,i){Cs(n,e,r);let s=new de(void 0,r,e,t,n,n,n,i,0);return s.contentDOM&&s.updateChildren(i,0),s}var gt=class extends de{constructor(e,t,n,i,s,o,l){super(e,t,n,i,s,null,o,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,i){return this.dirty==ge||this.dirty!=Z&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=Z||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=Z,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,n){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,n)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,n){let i=this.node.cut(e,t),s=document.createTextNode(i.text);return new gt(this.parent,i,this.outerDeco,this.innerDeco,s,s,n)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=ge)}get domAtom(){return!1}},hn=class extends nt{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Z&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},sr=class extends de{constructor(e,t,n,i,s,o,l,a,f,c){super(e,t,n,i,s,o,l,f,c),this.spec=a}update(e,t,n,i){if(this.dirty==ge)return!1;if(this.spec.update){let s=this.spec.update(e,t,n);return s&&this.updateInner(e,t,n,i),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,n,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,i){this.spec.setSelection?this.spec.setSelection(e,t,n):super.setSelection(e,t,n,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function Ss(r,e,t){let n=r.firstChild,i=!1;for(let s=0;s>1,o=Math.min(s,e.length);for(;i-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let a=Ne.create(this.top,e[s],t,n);this.top.children.splice(this.index,0,a),this.top=a,this.changed=!0}this.index=0,s++}}findNodeMatch(e,t,n,i){let s=-1,o;if(i>=this.preMatch.index&&(o=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&o.matchesNode(e,t,n))s=this.top.children.indexOf(o,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(n){let f=t.children[n-1];if(f instanceof Ne)t=f,n=f.children.length;else{l=f,n--;break}}else{if(t==e)break e;n=t.parent.children.indexOf(t),t=t.parent}let a=l.node;if(!!a){if(a!=r.child(i-1))break;--i,s.set(l,i),o.push(l)}}return{index:i,matched:s,matches:o.reverse()}}function ba(r,e){return r.type.side-e.type.side}function ka(r,e,t,n){let i=e.locals(r),s=0;if(i.length==0){for(let f=0;fs;)l.push(i[o++]);let d=s+u.nodeSize;if(u.isText){let y=d;o!y.inline):l.slice();n(u,m,e.forChild(s,u),p),s=d}}function xa(r){if(r.nodeName=="UL"||r.nodeName=="OL"){let e=r.style.cssText;r.style.cssText=e+"; list-style: square !important",window.getComputedStyle(r).listStyle,r.style.cssText=e}}function Sa(r,e){for(;;){if(r.nodeType==3)return r;if(r.nodeType==1&&e>0){if(r.childNodes.length>e&&r.childNodes[e].nodeType==3)return r.childNodes[e];r=r.childNodes[e-1],e=he(r)}else if(r.nodeType==1&&e=t){if(s>=n&&a.slice(n-e.length-l,n-l)==e)return n-e.length;let f=l=0&&f+e.length+l>=t)return l+f;if(t==n&&a.length>=n+e.length-l&&a.slice(n-l,n-l+e.length)==e)return n}}return-1}function fr(r,e,t,n,i){let s=[];for(let o=0,l=0;o=t||c<=e?s.push(a):(ft&&s.push(a.slice(t-f,a.size,n)))}return s}function xr(r,e=null){let t=r.domSelectionRange(),n=r.state.doc;if(!t.focusNode)return null;let i=r.docView.nearestDesc(t.focusNode),s=i&&i.size==0,o=r.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(o<0)return null;let l=n.resolve(o),a,f;if(yn(t)){for(a=l;i&&!i.node;)i=i.parent;let c=i.node;if(i&&c.isAtom&&x.isSelectable(c)&&i.parent&&!(c.isInline&&Yl(t.focusNode,t.focusOffset,i.dom))){let h=i.posBefore;f=new x(o==h?l:n.resolve(h))}}else{let c=r.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(c<0)return null;a=n.resolve(c)}if(!f){let c=e=="pointer"||r.state.selection.head{(t.anchorNode!=n||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",r.input.hideSelectionGuard),setTimeout(()=>{(!Os(r)||r.state.selection.visible)&&r.dom.classList.remove("ProseMirror-hideselection")},20))})}function Oa(r){let e=r.domSelection(),t=document.createRange(),n=r.cursorWrapper.dom,i=n.nodeName=="IMG";i?t.setEnd(n.parentNode,J(n)+1):t.setEnd(n,0),t.collapse(!1),e.removeAllRanges(),e.addRange(t),!i&&!r.state.selection.visible&&U&&Be<=11&&(n.disabled=!0,n.disabled=!1)}function ws(r,e){if(e instanceof x){let t=r.docView.descAt(e.from);t!=r.lastSelectedViewDesc&&(_i(r),t&&t.selectNode(),r.lastSelectedViewDesc=t)}else _i(r)}function _i(r){r.lastSelectedViewDesc&&(r.lastSelectedViewDesc.parent&&r.lastSelectedViewDesc.deselectNode(),r.lastSelectedViewDesc=void 0)}function Sr(r,e,t,n){return r.someProp("createSelectionBetween",i=>i(r,e,t))||O.between(e,t,n)}function Yi(r){return r.editable&&!r.hasFocus()?!1:Ns(r)}function Ns(r){let e=r.domSelectionRange();if(!e.anchorNode)return!1;try{return r.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(r.editable||r.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch(t){return!1}}function wa(r){let e=r.docView.domFromPos(r.state.selection.anchor,0),t=r.domSelectionRange();return tt(e.node,e.offset,t.anchorNode,t.anchorOffset)}function cr(r,e){let{$anchor:t,$head:n}=r.selection,i=e>0?t.max(n):t.min(n),s=i.parent.inlineContent?i.depth?r.doc.resolve(e>0?i.after():i.before()):null:i;return s&&S.findFrom(s,e)}function Pe(r,e){return r.dispatch(r.state.tr.setSelection(e).scrollIntoView()),!0}function Gi(r,e,t){let n=r.state.selection;if(n instanceof O)if(t.indexOf("s")>-1){let{$head:i}=n,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let o=r.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return Pe(r,new O(n.$anchor,o))}else if(n.empty){if(r.endOfTextblock(e>0?"forward":"backward")){let i=cr(r.state,e);return i&&i instanceof x?Pe(r,i):!1}else if(!(Q&&t.indexOf("m")>-1)){let i=n.$head,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,o;if(!s||s.isText)return!1;let l=e<0?i.pos-s.nodeSize:i.pos;return s.isAtom||(o=r.docView.descAt(l))&&!o.contentDOM?x.isSelectable(s)?Pe(r,new x(e<0?r.state.doc.resolve(i.pos-s.nodeSize):i)):Jt?Pe(r,new O(r.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(n instanceof x&&n.node.isInline)return Pe(r,new O(e>0?n.$to:n.$from));{let i=cr(r.state,e);return i?Pe(r,i):!1}}}function un(r){return r.nodeType==3?r.nodeValue.length:r.childNodes.length}function Pt(r,e){let t=r.pmViewDesc;return t&&t.size==0&&(e<0||r.nextSibling||r.nodeName!="BR")}function ut(r,e){return e<0?Na(r):Ta(r)}function Na(r){let e=r.domSelectionRange(),t=e.focusNode,n=e.focusOffset;if(!t)return;let i,s,o=!1;for(ie&&t.nodeType==1&&n0){if(t.nodeType!=1)break;{let l=t.childNodes[n-1];if(Pt(l,-1))i=t,s=--n;else if(l.nodeType==3)t=l,n=t.nodeValue.length;else break}}else{if(Ts(t))break;{let l=t.previousSibling;for(;l&&Pt(l,-1);)i=t.parentNode,s=J(l),l=l.previousSibling;if(l)t=l,n=un(t);else{if(t=t.parentNode,t==r.dom)break;n=0}}}o?hr(r,t,n):i&&hr(r,i,s)}function Ta(r){let e=r.domSelectionRange(),t=e.focusNode,n=e.focusOffset;if(!t)return;let i=un(t),s,o;for(;;)if(n{r.state==i&&we(r)},50)}function Xi(r,e){let t=r.state.doc.resolve(e);if(!(V||Zl)&&t.parent.inlineContent){let i=r.coordsAtPos(e);if(e>t.start()){let s=r.coordsAtPos(e-1),o=(s.top+s.bottom)/2;if(o>i.top&&o1)return s.lefti.top&&o1)return s.left>i.left?"ltr":"rtl"}}return getComputedStyle(r.dom).direction=="rtl"?"rtl":"ltr"}function Qi(r,e,t){let n=r.state.selection;if(n instanceof O&&!n.empty||t.indexOf("s")>-1||Q&&t.indexOf("m")>-1)return!1;let{$from:i,$to:s}=n;if(!i.parent.inlineContent||r.endOfTextblock(e<0?"up":"down")){let o=cr(r.state,e);if(o&&o instanceof x)return Pe(r,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=n instanceof P?S.near(o,e):S.findFrom(o,e);return l?Pe(r,l):!1}return!1}function Zi(r,e){if(!(r.state.selection instanceof O))return!0;let{$head:t,$anchor:n,empty:i}=r.state.selection;if(!t.sameParent(n))return!0;if(!i)return!1;if(r.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(s&&!s.isText){let o=r.state.tr;return e<0?o.delete(t.pos-s.nodeSize,t.pos):o.delete(t.pos,t.pos+s.nodeSize),r.dispatch(o),!0}return!1}function es(r,e,t){r.domObserver.stop(),e.contentEditable=t,r.domObserver.start()}function Ia(r){if(!q||r.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=r.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let n=e.firstChild;es(r,n,"true"),setTimeout(()=>es(r,n,"false"),20)}return!1}function Aa(r){let e="";return r.ctrlKey&&(e+="c"),r.metaKey&&(e+="m"),r.altKey&&(e+="a"),r.shiftKey&&(e+="s"),e}function Ra(r,e){let t=e.keyCode,n=Aa(e);if(t==8||Q&&t==72&&n=="c")return Zi(r,-1)||ut(r,-1);if(t==46&&!e.shiftKey||Q&&t==68&&n=="c")return Zi(r,1)||ut(r,1);if(t==13||t==27)return!0;if(t==37||Q&&t==66&&n=="c"){let i=t==37?Xi(r,r.state.selection.from)=="ltr"?-1:1:-1;return Gi(r,i,n)||ut(r,i)}else if(t==39||Q&&t==70&&n=="c"){let i=t==39?Xi(r,r.state.selection.from)=="ltr"?1:-1:1;return Gi(r,i,n)||ut(r,i)}else{if(t==38||Q&&t==80&&n=="c")return Qi(r,-1,n)||ut(r,-1);if(t==40||Q&&t==78&&n=="c")return Ia(r)||Qi(r,1,n)||ut(r,1);if(n==(Q?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Ds(r,e){r.someProp("transformCopied",p=>{e=p(e,r)});let t=[],{content:n,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&n.childCount==1&&n.firstChild.childCount==1;){i--,s--;let p=n.firstChild;t.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),n=p.content}let o=r.someProp("clipboardSerializer")||j.fromSchema(r.state.schema),l=Ps(),a=l.createElement("div");a.appendChild(o.serializeFragment(n,{document:l}));let f=a.firstChild,c,h=0;for(;f&&f.nodeType==1&&(c=vs[f.nodeName.toLowerCase()]);){for(let p=c.length-1;p>=0;p--){let d=l.createElement(c[p]);for(;a.firstChild;)d.appendChild(a.firstChild);a.appendChild(d),h++}f=a.firstChild}f&&f.nodeType==1&&f.setAttribute("data-pm-slice",`${i} ${s}${h?` -${h}`:""} ${JSON.stringify(t)}`);let u=r.someProp("clipboardTextSerializer",p=>p(e,r))||e.content.textBetween(0,e.content.size,` +var DjangoProseEditor=(()=>{var Ut=Object.defineProperty;var Po=Object.getOwnPropertyDescriptor;var zo=Object.getOwnPropertyNames,Br=Object.getOwnPropertySymbols;var Lr=Object.prototype.hasOwnProperty,Bo=Object.prototype.propertyIsEnumerable;var Fr=(r,e,t)=>e in r?Ut(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,wn=(r,e)=>{for(var t in e||(e={}))Lr.call(e,t)&&Fr(r,t,e[t]);if(Br)for(var t of Br(e))Bo.call(e,t)&&Fr(r,t,e[t]);return r};var Fo=(r,e)=>{for(var t in e)Ut(r,t,{get:e[t],enumerable:!0})},Lo=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of zo(e))!Lr.call(r,i)&&i!==t&&Ut(r,i,{get:()=>e[i],enumerable:!(n=Po(e,i))||n.enumerable});return r};var Vo=r=>Lo(Ut({},"__esModule",{value:!0}),r);var Bc={};Fo(Bc,{createEditor:()=>Ro});function B(r){this.content=r}B.prototype={constructor:B,find:function(r){for(var e=0;e>1}};B.from=function(r){if(r instanceof B)return r;var e=[];if(r)for(var t in r)e.push(t,r[t]);return new B(e)};var Tn=B;function Hr(r,e,t){for(let n=0;;n++){if(n==r.childCount||n==e.childCount)return r.childCount==e.childCount?null:t;let i=r.child(n),s=e.child(n);if(i==s){t+=i.nodeSize;continue}if(!i.sameMarkup(s))return t;if(i.isText&&i.text!=s.text){for(let o=0;i.text[o]==s.text[o];o++)t++;return t}if(i.content.size||s.content.size){let o=Hr(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function jr(r,e,t,n){for(let i=r.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:t,b:n};let o=r.child(--i),l=e.child(--s),a=o.nodeSize;if(o==l){t-=a,n-=a;continue}if(!o.sameMarkup(l))return{a:t,b:n};if(o.isText&&o.text!=l.text){let f=0,c=Math.min(o.text.length,l.text.length);for(;fe&&n(a,i+l,s||null,o)!==!1&&a.content.size){let c=l+1;a.nodesBetween(Math.max(0,e-c),Math.min(a.content.size,t-c),n,i+c)}l=f}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,i){let s="",o=!0;return this.nodesBetween(e,t,(l,a)=>{let f=l.isText?l.text.slice(Math.max(e,a)-a,t-a):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&f||l.isTextblock)&&n&&(o?o=!1:s+=n),s+=f},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,n=e.firstChild,i=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(n)&&(i[i.length-1]=t.withText(t.text+n.text),s=1);se)for(let s=0,o=0;oe&&((ot)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,t-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,t-o-1))),n.push(l),i+=l.nodeSize),o=a}return new g(n,i)}cutByIndex(e,t){return e==t?g.empty:e==0&&t==this.content.length?this:new g(this.content.slice(e,t))}replaceChild(e,t){let n=this.content[e];if(n==t)return this;let i=this.content.slice(),s=this.size+t.nodeSize-n.nodeSize;return i[e]=t,new g(i,s)}addToStart(e){return new g([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new g(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let n=0,i=0;;n++){let s=this.child(n),o=i+s.nodeSize;if(o>=e)return o==e||t>0?_t(n+1,o):_t(n,i);i=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return g.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new g(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return g.empty;let t,n=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),n=!0),t&&t.push(s)}}return t||(t=e.slice()),n||t.push(this),t}removeFromSet(e){for(let t=0;tn.type.rank-i.type.rank),t}};C.none=[];var Ke=class extends Error{},b=class{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let n=_r(this.content,e+this.openStart,t);return n&&new b(n,this.openStart,this.openEnd)}removeBetween(e,t){return new b(Ur(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return b.empty;let n=t.openStart||0,i=t.openEnd||0;if(typeof n!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new b(g.fromJSON(e,t.content),n,i)}static maxOpen(e,t=!0){let n=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)n++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)i++;return new b(e,n,i)}};b.empty=new b(g.empty,0,0);function Ur(r,e,t){let{index:n,offset:i}=r.findIndex(e),s=r.maybeChild(n),{index:o,offset:l}=r.findIndex(t);if(i==e||s.isText){if(l!=t&&!r.child(o).isText)throw new RangeError("Removing non-flat range");return r.cut(0,e).append(r.cut(t))}if(n!=o)throw new RangeError("Removing non-flat range");return r.replaceChild(n,s.copy(Ur(s.content,e-i-1,t-i-1)))}function _r(r,e,t,n){let{index:i,offset:s}=r.findIndex(e),o=r.maybeChild(i);if(s==e||o.isText)return n&&!n.canReplace(i,i,t)?null:r.cut(0,e).append(t).append(r.cut(e));let l=_r(o.content,e-s-1,t);return l&&r.replaceChild(i,o.copy(l))}function Jo(r,e,t){if(t.openStart>r.depth)throw new Ke("Inserted content deeper than insertion position");if(r.depth-t.openStart!=e.depth-t.openEnd)throw new Ke("Inconsistent open depths");return Yr(r,e,t,0)}function Yr(r,e,t,n){let i=r.index(n),s=r.node(n);if(i==e.index(n)&&n=0&&r.isText&&r.sameMarkup(e[t])?e[t]=r.withText(e[t].text+r.text):e.push(r)}function Mt(r,e,t,n){let i=(e||r).node(t),s=0,o=e?e.index(t):i.childCount;r&&(s=r.index(t),r.depth>t?s++:r.textOffset&&(We(r.nodeAfter,n),s++));for(let l=s;li&&An(r,e,i+1),o=n.depth>i&&An(t,n,i+1),l=[];return Mt(null,r,i,l),s&&o&&e.index(i)==t.index(i)?(Gr(s,o),We(qe(s,Xr(r,e,t,n,i+1)),l)):(s&&We(qe(s,Gt(r,e,i+1)),l),Mt(e,t,i,l),o&&We(qe(o,Gt(t,n,i+1)),l)),Mt(n,null,i,l),new g(l)}function Gt(r,e,t){let n=[];if(Mt(null,r,t,n),r.depth>t){let i=An(r,e,t+1);We(qe(i,Gt(r,e,t+1)),n)}return Mt(e,null,t,n),new g(n)}function Wo(r,e){let t=e.depth-r.openStart,i=e.node(t).copy(r.content);for(let s=t-1;s>=0;s--)i=e.node(s).copy(g.from(i));return{start:i.resolveNoCache(r.openStart+t),end:i.resolveNoCache(i.content.size-r.openEnd-t)}}var $e=class{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let n=this.pos-this.path[this.path.length-1],i=e.child(t);return n?e.child(t).cut(n):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let s=0;s0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new He(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let n=[],i=0,s=t;for(let o=e;;){let{index:l,offset:a}=o.content.findIndex(s),f=s-a;if(n.push(o,l,i+a),!f||(o=o.child(l),o.isText))break;s=f-1,i+=a+1}return new $e(t,n,s)}static resolveCached(e,t){for(let i=0;ie&&this.nodesBetween(e,t,s=>(n.isInSet(s.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),Qr(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,n=g.empty,i=0,s=n.childCount){let o=this.contentMatchAt(e).matchFragment(n,i,s),l=o&&o.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let a=i;at.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let n=null;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");n=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,n)}let i=g.fromJSON(e,t.content);return e.nodeType(t.type).create(t.attrs,i,n)}};_.prototype.text=void 0;var it=class extends _{constructor(e,t,n,i){if(super(e,t,null,i),!n)throw new RangeError("Empty text nodes are not allowed");this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Qr(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new it(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new it(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function Qr(r,e){for(let t=r.length-1;t>=0;t--)e=r[t].type.name+"("+e+")";return e}var ke=class{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let n=new Rn(e,t);if(n.next==null)return ke.empty;let i=Zr(n);n.next&&n.err("Unexpected trailing text");let s=Go(Yo(i));return Xo(s,n),s}matchType(e){for(let t=0;tf.createAndFill()));for(let f=0;f=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(n){e.push(n);for(let i=0;i{let s=i+(n.validEnd?"*":" ")+" ";for(let o=0;o"+e.indexOf(n.next[o].next);return s}).join(` +`)}};ke.empty=new ke(!0);var Rn=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function Zr(r){let e=[];do e.push($o(r));while(r.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function $o(r){let e=[];do e.push(Ho(r));while(r.next&&r.next!=")"&&r.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function Ho(r){let e=_o(r);for(;;)if(r.eat("+"))e={type:"plus",expr:e};else if(r.eat("*"))e={type:"star",expr:e};else if(r.eat("?"))e={type:"opt",expr:e};else if(r.eat("{"))e=jo(r,e);else break;return e}function Vr(r){/\D/.test(r.next)&&r.err("Expected number, got '"+r.next+"'");let e=Number(r.next);return r.pos++,e}function jo(r,e){let t=Vr(r),n=t;return r.eat(",")&&(r.next!="}"?n=Vr(r):n=-1),r.eat("}")||r.err("Unclosed braced range"),{type:"range",min:t,max:n,expr:e}}function Uo(r,e){let t=r.nodeTypes,n=t[e];if(n)return[n];let i=[];for(let s in t){let o=t[s];o.groups.indexOf(e)>-1&&i.push(o)}return i.length==0&&r.err("No node type or group '"+e+"' found"),i}function _o(r){if(r.eat("(")){let e=Zr(r);return r.eat(")")||r.err("Missing closing paren"),e}else if(/\W/.test(r.next))r.err("Unexpected token '"+r.next+"'");else{let e=Uo(r,r.next).map(t=>(r.inline==null?r.inline=t.isInline:r.inline!=t.isInline&&r.err("Mixing inline and block content"),{type:"name",value:t}));return r.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Yo(r){let e=[[]];return i(s(r,0),t()),e;function t(){return e.push([])-1}function n(o,l,a){let f={term:a,to:l};return e[o].push(f),f}function i(o,l){o.forEach(a=>a.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((a,f)=>a.concat(s(f,l)),[]);if(o.type=="seq")for(let a=0;;a++){let f=s(o.exprs[a],l);if(a==o.exprs.length-1)return f;i(f,l=t())}else if(o.type=="star"){let a=t();return n(l,a),i(s(o.expr,a),a),[n(a)]}else if(o.type=="plus"){let a=t();return i(s(o.expr,l),a),i(s(o.expr,a),a),[n(a)]}else{if(o.type=="opt")return[n(l)].concat(s(o.expr,l));if(o.type=="range"){let a=l;for(let f=0;f{r[o].forEach(({term:l,to:a})=>{if(!l)return;let f;for(let c=0;c{f||i.push([l,f=[]]),f.indexOf(c)==-1&&f.push(c)})})});let s=e[n.join(",")]=new ke(n.indexOf(r.length-1)>-1);for(let o=0;o-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tn[s]=new st(s,t,o));let i=t.spec.topNode||"doc";if(!n[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!n.text)throw new RangeError("Every schema needs a 'text' type");for(let s in n.text.attrs)throw new RangeError("The text node type should not have attributes");return n}},vn=class{constructor(e){this.hasDefault=Object.prototype.hasOwnProperty.call(e,"default"),this.default=e.default}get isRequired(){return!this.hasDefault}},je=class{constructor(e,t,n,i){this.name=e,this.rank=t,this.schema=n,this.spec=i,this.attrs=ri(i.attrs),this.excluded=null;let s=ti(this.attrs);this.instance=s?new C(this,s):null}create(e=null){return!e&&this.instance?this.instance:new C(this,ni(this.attrs,e))}static compile(e,t){let n=Object.create(null),i=0;return e.forEach((s,o)=>n[s]=new je(s,i++,t,o)),n}removeFromSet(e){for(var t=0;t-1}},Ue=class{constructor(e){this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=Tn.from(e.nodes),t.marks=Tn.from(e.marks||{}),this.nodes=st.compile(this.spec.nodes,this),this.marks=je.compile(this.spec.marks,this);let n=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let s=this.nodes[i],o=s.spec.content||"",l=s.spec.marks;s.contentMatch=n[o]||(n[o]=ke.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.markSet=l=="_"?null:l?Wr(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:Wr(this,o.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,n,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof st){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,n,i)}text(e,t){let n=this.nodes.text;return new it(n,n.defaultAttrs,e,C.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return _.fromJSON(this,e)}markFromJSON(e){return C.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function Wr(r,e){let t=[];for(let n=0;n-1)&&t.push(o=a)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[n]+"'")}return t}var ae=class{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[],t.forEach(n=>{n.tag?this.tags.push(n):n.style&&this.styles.push(n)}),this.normalizeLists=!this.tags.some(n=>{if(!/^(ul|ol)\b/.test(n.tag)||!n.node)return!1;let i=e.nodes[n.node];return i.contentMatch.matchType(i)})}parse(e,t={}){let n=new Zt(this,t,!1);return n.addAll(e,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new Zt(this,t,!0);return n.addAll(e,t.from,t.to),b.maxOpen(n.finish())}matchTag(e,t,n){for(let i=n?this.tags.indexOf(n)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(o.getAttrs){let a=o.getAttrs(t);if(a===!1)continue;o.attrs=a||void 0}return o}}}static schemaRules(e){let t=[];function n(i){let s=i.priority==null?50:i.priority,o=0;for(;o{n(o=Kr(o)),o.mark||o.ignore||o.clearMark||(o.mark=i)})}for(let i in e.nodes){let s=e.nodes[i].spec.parseDOM;s&&s.forEach(o=>{n(o=Kr(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new ae(e,ae.schemaRules(e)))}},ii={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Qo={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},si={ol:!0,ul:!0},Xt=1,Qt=2,Ct=4;function qr(r,e,t){return e!=null?(e?Xt:0)|(e==="full"?Qt:0):r&&r.whitespace=="pre"?Xt|Qt:t&~Ct}var rt=class{constructor(e,t,n,i,s,o,l){this.type=e,this.attrs=t,this.marks=n,this.pendingMarks=i,this.solid=s,this.options=l,this.content=[],this.activeMarks=C.none,this.stashMarks=[],this.match=o||(l&Ct?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(g.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let n=this.type.contentMatch,i;return(i=n.findWrapping(e.type))?(this.match=n,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Xt)){let n=this.content[this.content.length-1],i;if(n&&n.isText&&(i=/[ \t\r\n\u000c]+$/.exec(n.text))){let s=n;n.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-i[0].length))}}let t=g.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(g.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}popFromStashMark(e){for(let t=this.stashMarks.length-1;t>=0;t--)if(e.eq(this.stashMarks[t]))return this.stashMarks.splice(t,1)[0]}applyPending(e){for(let t=0,n=this.pendingMarks;tthis.addAll(e)),o&&this.sync(l),this.needsBlock=a}else this.withStyleRules(e,()=>{this.addElementByRule(e,s,s.consuming===!1?i:void 0)})}leafFallback(e){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` +`))}ignoreFallback(e){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(e){let t=C.none,n=C.none;for(let i=0;i{o.clearMark(l)&&(n=l.addToSet(n))}):t=this.parser.schema.marks[o.mark].create(o.attrs).addToSet(t),o.consuming===!1)s=o;else break}return[t,n]}addElementByRule(e,t,n){let i,s,o;t.node?(s=this.parser.schema.nodes[t.node],s.isLeaf?this.insertNode(s.create(t.attrs))||this.leafFallback(e):i=this.enter(s,t.attrs||null,t.preserveWhitespace)):(o=this.parser.schema.marks[t.mark].create(t.attrs),this.addPendingMark(o));let l=this.top;if(s&&s.isLeaf)this.findInside(e);else if(n)this.addElement(e,n);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a));else{let a=e;typeof t.contentElement=="string"?a=e.querySelector(t.contentElement):typeof t.contentElement=="function"?a=t.contentElement(e):t.contentElement&&(a=t.contentElement),this.findAround(e,a,!0),this.addAll(a)}i&&this.sync(l)&&this.open--,o&&this.removePendingMark(o,l)}addAll(e,t,n){let i=t||0;for(let s=t?e.childNodes[t]:e.firstChild,o=n==null?null:e.childNodes[n];s!=o;s=s.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(s);this.findAtPoint(e,i)}findPlace(e){let t,n;for(let i=this.open;i>=0;i--){let s=this.nodes[i],o=s.findWrapping(e);if(o&&(!t||t.length>o.length)&&(t=o,n=s,!o.length)||s.solid)break}if(!t)return!1;this.sync(n);for(let i=0;ithis.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let i=n.length-1;i>=0;i--)e+=n[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),n=this.options.context,i=!this.isOpen&&(!n||n.parent.type==this.nodes[0].type),s=-(n?n.depth+1:0)+(i?0:1),o=(l,a)=>{for(;l>=0;l--){let f=t[l];if(f==""){if(l==t.length-1||l==0)continue;for(;a>=s;a--)if(o(l-1,a))return!0;return!1}else{let c=a>0||a==0&&i?this.nodes[a].type:n&&a>=s?n.node(a-s).type:null;if(!c||c.name!=f&&c.groups.indexOf(f)==-1)return!1;a--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let t in this.parser.schema.nodes){let n=this.parser.schema.nodes[t];if(n.isTextblock&&n.defaultAttrs)return n}}addPendingMark(e){let t=rl(e,this.top.pendingMarks);t&&this.top.stashMarks.push(t),this.top.pendingMarks=e.addToSet(this.top.pendingMarks)}removePendingMark(e,t){for(let n=this.open;n>=0;n--){let i=this.nodes[n];if(i.pendingMarks.lastIndexOf(e)>-1)i.pendingMarks=e.removeFromSet(i.pendingMarks);else{i.activeMarks=e.removeFromSet(i.activeMarks);let o=i.popFromStashMark(e);o&&i.type&&i.type.allowsMarkType(o.type)&&(i.activeMarks=o.addToSet(i.activeMarks))}if(i==t)break}}};function Zo(r){for(let e=r.firstChild,t=null;e;e=e.nextSibling){let n=e.nodeType==1?e.nodeName.toLowerCase():null;n&&si.hasOwnProperty(n)&&t?(t.appendChild(e),e=t):n=="li"?t=e:n&&(t=null)}}function el(r,e){return(r.matches||r.msMatchesSelector||r.webkitMatchesSelector||r.mozMatchesSelector).call(r,e)}function tl(r){let e=/\s*([\w-]+)\s*:\s*([^;]+)/g,t,n=[];for(;t=e.exec(r);)n.push(t[1],t[2].trim());return n}function Kr(r){let e={};for(let t in r)e[t]=r[t];return e}function nl(r,e){let t=e.schema.nodes;for(let n in t){let i=t[n];if(!i.allowsMarkType(r))continue;let s=[],o=l=>{s.push(l);for(let a=0;a{if(s.length||o.marks.length){let l=0,a=0;for(;l=0;i--){let s=this.serializeMark(e.marks[i],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(n),n=s.dom)}return n}serializeMark(e,t,n={}){let i=this.marks[e.type.name];return i&&V.renderSpec(In(n),i(e,t))}static renderSpec(e,t,n=null){if(typeof t=="string")return{dom:e.createTextNode(t)};if(t.nodeType!=null)return{dom:t};if(t.dom&&t.dom.nodeType!=null)return t;let i=t[0],s=i.indexOf(" ");s>0&&(n=i.slice(0,s),i=i.slice(s+1));let o,l=n?e.createElementNS(n,i):e.createElement(i),a=t[1],f=1;if(a&&typeof a=="object"&&a.nodeType==null&&!Array.isArray(a)){f=2;for(let c in a)if(a[c]!=null){let h=c.indexOf(" ");h>0?l.setAttributeNS(c.slice(0,h),c.slice(h+1),a[c]):l.setAttribute(c,a[c])}}for(let c=f;cf)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}else{let{dom:u,contentDOM:p}=V.renderSpec(e,h,n);if(l.appendChild(u),p){if(o)throw new RangeError("Multiple content holes");o=p}}}return{dom:l,contentDOM:o}}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new V(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=$r(e.nodes);return t.text||(t.text=n=>n.text),t}static marksFromSchema(e){return $r(e.marks)}};function $r(r){let e={};for(let t in r){let n=r[t].spec.toDOM;n&&(e[t]=n)}return e}function In(r){return r.document||window.document}var ai=65535,fi=Math.pow(2,16);function il(r,e){return r+e*fi}function oi(r){return r&ai}function sl(r){return(r-(r&ai))/fi}var ci=1,hi=2,en=4,ui=8,Tt=class{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(this.delInfo&ui)>0}get deletedBefore(){return(this.delInfo&(ci|en))>0}get deletedAfter(){return(this.delInfo&(hi|en))>0}get deletedAcross(){return(this.delInfo&en)>0}},J=class{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&J.empty)return J.empty}recover(e){let t=0,n=oi(e);if(!this.inverted)for(let i=0;ie)break;let f=this.ranges[l+s],c=this.ranges[l+o],h=a+f;if(e<=h){let u=f?e==a?-1:e==h?1:t:t,p=a+i+(u<0?0:c);if(n)return p;let d=e==(t<0?a:h)?null:il(l/3,e-a),m=e==a?hi:e==h?ci:en;return(t<0?e!=a:e!=h)&&(m|=ui),new Tt(p,m,d)}i+=c-f}return n?e+i:new Tt(e+i,0,null)}touches(e,t){let n=0,i=oi(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;le)break;let f=this.ranges[l+s],c=a+f;if(e<=c&&l==i*3)return!0;n+=this.ranges[l+o]-f}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let i=0,s=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?n-i-1:void 0)}}invert(){let e=new xe;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;ns&&a!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return N.fromReplace(e,this.from,this.to,s)}invert(){return new X(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new fe(t.pos,n.pos,this.mark)}merge(e){return e instanceof fe&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new fe(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new fe(t.from,t.to,e.markFromJSON(t.mark))}};v.jsonID("addMark",fe);var X=class extends v{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new b(Vn(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return N.fromReplace(e,this.from,this.to,n)}invert(){return new fe(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new X(t.pos,n.pos,this.mark)}merge(e){return e instanceof X&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new X(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new X(t.from,t.to,e.markFromJSON(t.mark))}};v.jsonID("removeMark",X);var ce=class extends v{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return N.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return N.fromReplace(e,this.pos,this.pos+1,new b(g.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let n=this.mark.addToSet(t.marks);if(n.length==t.marks.length){for(let i=0;in.pos?null:new D(t.pos,n.pos,i,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new D(t.from,t.to,t.gapFrom,t.gapTo,b.fromJSON(e,t.slice),t.insert,!!t.structure)}};v.jsonID("replaceAround",D);function Fn(r,e,t){let n=r.resolve(e),i=t-e,s=n.depth;for(;i>0&&s>0&&n.indexAfter(s)==n.node(s).childCount;)s--,i--;if(i>0){let o=n.node(s).maybeChild(n.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}function ol(r,e,t,n){let i=[],s=[],o,l;r.doc.nodesBetween(e,t,(a,f,c)=>{if(!a.isInline)return;let h=a.marks;if(!n.isInSet(h)&&c.type.allowsMarkType(n.type)){let u=Math.max(f,e),p=Math.min(f+a.nodeSize,t),d=n.addToSet(h);for(let m=0;mr.step(a)),s.forEach(a=>r.step(a))}function ll(r,e,t,n){let i=[],s=0;r.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline)return;s++;let a=null;if(n instanceof je){let f=o.marks,c;for(;c=n.isInSet(f);)(a||(a=[])).push(c),f=c.removeFromSet(f)}else n?n.isInSet(o.marks)&&(a=[n]):a=o.marks;if(a&&a.length){let f=Math.min(l+o.nodeSize,t);for(let c=0;cr.step(new X(o.from,o.to,o.style)))}function al(r,e,t,n=t.contentMatch){let i=r.doc.nodeAt(e),s=[],o=e+1;for(let l=0;l=0;l--)r.step(s[l])}function fl(r,e,t){return(e==0||r.canReplace(e,r.childCount))&&(t==r.childCount||r.canReplace(0,t))}function lt(r){let t=r.parent.content.cutByIndex(r.startIndex,r.endIndex);for(let n=r.depth;;--n){let i=r.$from.node(n),s=r.$from.index(n),o=r.$to.indexAfter(n);if(nt;d--)m||n.index(d)>0?(m=!0,c=g.from(n.node(d).copy(c)),h++):a--;let u=g.empty,p=0;for(let d=s,m=!1;d>t;d--)m||i.after(d+1)=0;o--){if(n.size){let l=t[o].type.contentMatch.matchFragment(n);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}n=g.from(t[o].type.create(t[o].attrs,n))}let i=e.start,s=e.end;r.step(new D(i,s,i,s,new b(n,0,0),t.length,!0))}function pl(r,e,t,n,i){if(!n.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=r.steps.length;r.doc.nodesBetween(e,t,(o,l)=>{if(o.isTextblock&&!o.hasMarkup(n,i)&&ml(r.doc,r.mapping.slice(s).map(l),n)){r.clearIncompatible(r.mapping.slice(s).map(l,1),n);let a=r.mapping.slice(s),f=a.map(l,1),c=a.map(l+o.nodeSize,1);return r.step(new D(f,c,f+1,c-1,new b(g.from(n.create(i,null,o.marks)),0,0),1,!0)),!1}})}function ml(r,e,t){let n=r.resolve(e),i=n.index();return n.parent.canReplaceWith(i,i+1,t)}function gl(r,e,t,n,i){let s=r.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let o=t.create(n,null,i||s.marks);if(s.isLeaf)return r.replaceWith(e,e+s.nodeSize,o);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);r.step(new D(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new b(g.from(o),0,0),1,!0))}function ve(r,e,t=1,n){let i=r.resolve(e),s=i.depth-t,o=n&&n[n.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let f=i.depth-1,c=t-2;f>s;f--,c--){let h=i.node(f),u=i.index(f);if(h.type.spec.isolating)return!1;let p=h.content.cutByIndex(u,h.childCount),d=n&&n[c+1];d&&(p=p.replaceChild(0,d.type.create(d.attrs)));let m=n&&n[c]||h;if(!h.canReplace(u+1,h.childCount)||!m.type.validContent(p))return!1}let l=i.indexAfter(s),a=n&&n[0];return i.node(s).canReplaceWith(l,l,a?a.type:i.node(s+1).type)}function yl(r,e,t=1,n){let i=r.doc.resolve(e),s=g.empty,o=g.empty;for(let l=i.depth,a=i.depth-t,f=t-1;l>a;l--,f--){s=g.from(i.node(l).copy(s));let c=n&&n[f];o=g.from(c?c.type.create(c.attrs,o):i.node(l).copy(o))}r.step(new A(e,e,new b(s.append(o),t,t),!0))}function Nt(r,e){let t=r.resolve(e),n=t.index();return bl(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(n,n+1)}function bl(r,e){return!!(r&&e&&!r.isLeaf&&r.canAppend(e))}function kl(r,e,t){let n=new A(e-t,e+t,b.empty,!0);r.step(n)}function xl(r,e,t){let n=r.resolve(e);if(n.parent.canReplaceWith(n.index(),n.index(),t))return e;if(n.parentOffset==0)for(let i=n.depth-1;i>=0;i--){let s=n.index(i);if(n.node(i).canReplaceWith(s,s,t))return n.before(i+1);if(s>0)return null}if(n.parentOffset==n.parent.content.size)for(let i=n.depth-1;i>=0;i--){let s=n.indexAfter(i);if(n.node(i).canReplaceWith(s,s,t))return n.after(i+1);if(s=0;o--){let l=o==n.depth?0:n.pos<=(n.start(o+1)+n.end(o+1))/2?-1:1,a=n.index(o)+(l>0?1:0),f=n.node(o),c=!1;if(s==1)c=f.canReplace(a,a,i);else{let h=f.contentMatchAt(a).findWrapping(i.firstChild.type);c=h&&f.canReplaceWith(a,a,h[0])}if(c)return l==0?n.pos:l<0?n.before(o+1):n.after(o+1)}return null}function sn(r,e,t=e,n=b.empty){if(e==t&&!n.size)return null;let i=r.resolve(e),s=r.resolve(t);return di(i,s,n)?new A(e,t,n):new Ln(i,s,n).fit()}function di(r,e,t){return!t.openStart&&!t.openEnd&&r.start()==e.start()&&r.parent.canReplace(r.index(),e.index(),t.content)}var Ln=class{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=g.empty;for(let i=0;i<=e.depth;i++){let s=e.node(i);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=g.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let f=this.findFittable();f?this.placeNodes(f):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,n=this.$from,i=this.close(e<0?this.$to:n.doc.resolve(e));if(!i)return null;let s=this.placed,o=n.depth,l=i.depth;for(;o&&l&&s.childCount==1;)s=s.firstChild.content,o--,l--;let a=new b(s,o,l);return e>-1?new D(n.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||n.pos!=this.$to.pos?new A(n.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,i=this.unplaced.openEnd;n1&&(i=0),s.type.spec.isolating&&i<=n){e=n;break}t=s.content}for(let t=1;t<=2;t++)for(let n=t==1?e:this.unplaced.openStart;n>=0;n--){let i,s=null;n?(s=zn(this.unplaced.content,n-1).firstChild,i=s.content):i=this.unplaced.content;let o=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:f}=this.frontier[l],c,h=null;if(t==1&&(o?f.matchType(o.type)||(h=f.fillBefore(g.from(o),!1)):s&&a.compatibleContent(s.type)))return{sliceDepth:n,frontierDepth:l,parent:s,inject:h};if(t==2&&o&&(c=f.findWrapping(o.type)))return{sliceDepth:n,frontierDepth:l,parent:s,wrap:c};if(s&&f.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced,i=zn(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new b(e,t+1,Math.max(n,i.size+t>=e.size-n?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,i=zn(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new b(Ot(e,t-1,1),t-1,s?t-1:n)}else this.unplaced=new b(Ot(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:i,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let m=0;m1||a==0||m.content.size)&&(h=y,c.push(pi(m.mark(u.allowedMarks(m.marks)),f==1?a:0,f==l.childCount?p:-1)))}let d=f==l.childCount;d||(p=-1),this.placed=wt(this.placed,t,g.from(c)),this.frontier[t].match=h,d&&p<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,y=l;m1&&i==this.$to.end(--n);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:i}=this.frontier[t],s=t=0;l--){let{match:a,type:f}=this.frontier[l],c=Bn(e,l,f,a,!0);if(!c||c.childCount)continue e}return{depth:t,fit:o,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=wt(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let i=e.node(n),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(n));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,t=null,n){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=wt(this.placed,this.depth,g.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(g.empty,!0);t.childCount&&(this.placed=wt(this.placed,this.frontier.length,t))}};function Ot(r,e,t){return e==0?r.cutByIndex(t,r.childCount):r.replaceChild(0,r.firstChild.copy(Ot(r.firstChild.content,e-1,t)))}function wt(r,e,t){return e==0?r.append(t):r.replaceChild(r.childCount-1,r.lastChild.copy(wt(r.lastChild.content,e-1,t)))}function zn(r,e){for(let t=0;t1&&(n=n.replaceChild(0,pi(n.firstChild,e-1,n.childCount==1?t-1:0))),e>0&&(n=r.type.contentMatch.fillBefore(n).append(n),t<=0&&(n=n.append(r.type.contentMatch.matchFragment(n).fillBefore(g.empty,!0)))),r.copy(n)}function Bn(r,e,t,n,i){let s=r.node(e),o=i?r.indexAfter(e):r.index(e);if(o==s.childCount&&!t.compatibleContent(s.type))return null;let l=n.fillBefore(s.content,!0,o);return l&&!Sl(t,s.content,o)?l:null}function Sl(r,e,t){for(let n=t;n0;u--,p--){let d=i.node(u).type.spec;if(d.defining||d.definingAsContext||d.isolating)break;o.indexOf(u)>-1?l=u:i.before(u)==p&&o.splice(1,0,-u)}let a=o.indexOf(l),f=[],c=n.openStart;for(let u=n.content,p=0;;p++){let d=u.firstChild;if(f.push(d),p==n.openStart)break;u=d.content}for(let u=c-1;u>=0;u--){let p=f[u],d=Ml(p.type);if(d&&!p.sameMarkup(i.node(Math.abs(l)-1)))c=u;else if(d||!p.type.isTextblock)break}for(let u=n.openStart;u>=0;u--){let p=(u+c+1)%(n.openStart+1),d=f[p];if(!!d)for(let m=0;m=0&&(r.replace(e,t,n),!(r.steps.length>h));u--){let p=o[u];p<0||(e=i.before(p),t=s.after(p))}}function mi(r,e,t,n,i){if(en){let s=i.contentMatchAt(0),o=s.fillBefore(r).append(r);r=o.append(s.matchFragment(o).fillBefore(g.empty,!0))}return r}function Ol(r,e,t,n){if(!n.isInline&&e==t&&r.doc.resolve(e).parent.content.size){let i=xl(r.doc,e,n.type);i!=null&&(e=t=i)}r.replaceRange(e,t,new b(g.from(n),0,0))}function wl(r,e,t){let n=r.doc.resolve(e),i=r.doc.resolve(t),s=gi(n,i);for(let o=0;o0&&(a||n.node(l-1).canReplace(n.index(l-1),i.indexAfter(l-1))))return r.delete(n.before(l),i.after(l))}for(let o=1;o<=n.depth&&o<=i.depth;o++)if(e-n.start(o)==n.depth-o&&t>n.end(o)&&i.end(o)-t!=i.depth-o)return r.delete(n.before(o),t);r.delete(e,t)}function gi(r,e){let t=[],n=Math.min(r.depth,e.depth);for(let i=n;i>=0;i--){let s=r.start(i);if(se.pos+(e.depth-i)||r.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==r.depth&&i==e.depth&&r.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&t.push(i)}return t}var Ae=class extends v{constructor(e,t,n){super(),this.pos=e,this.attr=t,this.value=n}apply(e){let t=e.nodeAt(this.pos);if(!t)return N.fail("No node at attribute step's position");let n=Object.create(null);for(let s in t.attrs)n[s]=t.attrs[s];n[this.attr]=this.value;let i=t.type.create(n,null,t.marks);return N.fromReplace(e,this.pos,this.pos+1,new b(g.from(i),0,t.isLeaf?0:1))}getMap(){return J.empty}invert(e){return new Ae(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Ae(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new Ae(t.pos,t.attr,t.value)}};v.jsonID("attr",Ae);var _e=class extends v{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return N.ok(n)}getMap(){return J.empty}invert(e){return new _e(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new _e(t.attr,t.value)}};v.jsonID("docAttr",_e);var ot=class extends Error{};ot=function r(e){let t=Error.call(this,e);return t.__proto__=r.prototype,t};ot.prototype=Object.create(Error.prototype);ot.prototype.constructor=ot;ot.prototype.name="TransformError";var tn=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new xe}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new ot(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,n=b.empty){let i=sn(this.doc,e,t,n);return i&&this.step(i),this}replaceWith(e,t,n){return this.replace(e,t,new b(g.from(n),0,0))}delete(e,t){return this.replace(e,t,b.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return Cl(this,e,t,n),this}replaceRangeWith(e,t,n){return Ol(this,e,t,n),this}deleteRange(e,t){return wl(this,e,t),this}lift(e,t){return cl(this,e,t),this}join(e,t=1){return kl(this,e,t),this}wrap(e,t){return dl(this,e,t),this}setBlockType(e,t=e,n,i=null){return pl(this,e,t,n,i),this}setNodeMarkup(e,t,n=null,i){return gl(this,e,t,n,i),this}setNodeAttribute(e,t,n){return this.step(new Ae(e,t,n)),this}setDocAttribute(e,t){return this.step(new _e(e,t)),this}addNodeMark(e,t){return this.step(new ce(e,t)),this}removeNodeMark(e,t){if(!(t instanceof C)){let n=this.doc.nodeAt(e);if(!n)throw new RangeError("No node at position "+e);if(t=t.isInSet(n.marks),!t)return this}return this.step(new Re(e,t)),this}split(e,t=1,n){return yl(this,e,t,n),this}addMark(e,t,n){return ol(this,e,t,n),this}removeMark(e,t,n){return ll(this,e,t,n),this}clearIncompatible(e,t,n){return al(this,e,t,n),this}};var Jn=Object.create(null),S=class{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new qn(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t=0;s--){let o=t<0?at(e.node(0),e.node(s),e.before(s+1),e.index(s),t,n):at(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,n);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new P(e.node(0))}static atStart(e){return at(e,e,0,0,1)||new P(e)}static atEnd(e){return at(e,e,e.content.size,e.childCount,-1)||new P(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=Jn[t.type];if(!n)throw new RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in Jn)throw new RangeError("Duplicate use of selection JSON ID "+e);return Jn[e]=t,t.prototype.jsonID=e,t}getBookmark(){return O.between(this.$anchor,this.$head).getBookmark()}};S.prototype.visible=!0;var qn=class{constructor(e,t){this.$from=e,this.$to=t}},yi=!1;function bi(r){!yi&&!r.parent.inlineContent&&(yi=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+r.parent.type.name+")"))}var O=class extends S{constructor(e,t=e){bi(e),bi(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let n=e.resolve(t.map(this.head));if(!n.parent.inlineContent)return S.near(n);let i=e.resolve(t.map(this.anchor));return new O(i.parent.inlineContent?i:n,n)}replace(e,t=b.empty){if(super.replace(e,t),t==b.empty){let n=this.$from.marksAcross(this.$to);n&&e.ensureMarks(n)}}eq(e){return e instanceof O&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new ft(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new O(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,n=t){let i=e.resolve(t);return new this(i,n==t?i:e.resolve(n))}static between(e,t,n){let i=e.pos-t.pos;if((!n||i)&&(n=i>=0?1:-1),!t.parent.inlineContent){let s=S.findFrom(t,n,!0)||S.findFrom(t,-n,!0);if(s)t=s.$head;else return S.near(t,n)}return e.parent.inlineContent||(i==0?e=t:(e=(S.findFrom(e,-n,!0)||S.findFrom(e,n,!0)).$anchor,e.pos0?0:1);i>0?o=0;o+=i){let l=e.child(o);if(l.isAtom){if(!s&&x.isSelectable(l))return x.create(r,t-(i<0?l.nodeSize:0))}else{let a=at(r,l,t+i,i<0?l.childCount:0,i,s);if(a)return a}t+=l.nodeSize*i}return null}function ki(r,e,t){let n=r.steps.length-1;if(n{o==null&&(o=c)}),r.setSelection(S.near(r.doc.resolve(o),t))}var xi=1,on=2,Si=4,Kn=class extends tn{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=on,this}ensureMarks(e){return C.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&on)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~on,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let n=this.selection;return t&&(e=e.mark(this.storedMarks||(n.empty?n.$from.marks():n.$from.marksAcross(n.$to)||C.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(n==null&&(n=t),n=n==null?t:n,!e)return this.deleteRange(t,n);let s=this.storedMarks;if(!s){let o=this.doc.resolve(t);s=n==t?o.marks():o.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,i.text(e,s)),this.selection.empty||this.setSelection(S.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=Si,this}get scrolledIntoView(){return(this.updated&Si)>0}};function Mi(r,e){return!e||!r?r:r.bind(e)}var Ye=class{constructor(e,t,n){this.name=e,this.init=Mi(t.init,n),this.apply=Mi(t.apply,n)}},Nl=[new Ye("doc",{init(r){return r.doc||r.schema.topNodeType.createAndFill()},apply(r){return r.doc}}),new Ye("selection",{init(r,e){return r.selection||S.atStart(e.doc)},apply(r){return r.selection}}),new Ye("storedMarks",{init(r){return r.storedMarks||null},apply(r,e,t,n){return n.selection.$cursor?r.storedMarks:null}}),new Ye("scrollToSelection",{init(){return 0},apply(r,e){return r.scrolledIntoView?e+1:e}})],Dt=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Nl.slice(),t&&t.forEach(n=>{if(this.pluginsByKey[n.key])throw new RangeError("Adding different instances of a keyed plugin ("+n.key+")");this.plugins.push(n),this.pluginsByKey[n.key]=n,n.spec.state&&this.fields.push(new Ye(n.key,n.spec.state,n))})}},Se=class{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let n=0;nn.toJSON())),e&&typeof e=="object")for(let n in e){if(n=="doc"||n=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[n],s=i.spec.state;s&&s.toJSON&&(t[n]=s.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,n){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Dt(e.schema,e.plugins),s=new Se(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=_.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=S.fromJSON(s.doc,t.selection);else if(o.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(n)for(let l in n){let a=n[l],f=a.spec.state;if(a.key==o.name&&f&&f.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[o.name]=f.fromJSON.call(a,e,t[l],s);return}}s[o.name]=o.init(e,s)}}),s}};function Ci(r,e,t){for(let n in r){let i=r[n];i instanceof Function?i=i.bind(e):n=="handleDOMEvents"&&(i=Ci(i,e,{})),t[n]=i}return t}var j=class{constructor(e){this.spec=e,this.props={},e.props&&Ci(e.props,this,this.props),this.key=e.key?e.key.key:Oi("plugin")}getState(e){return e[this.key]}},Wn=Object.create(null);function Oi(r){return r in Wn?r+"$"+ ++Wn[r]:(Wn[r]=0,r+"$")}var It=class{constructor(e="key"){this.key=Oi(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var Ti=(r,e)=>r.selection.empty?!1:(e&&e(r.tr.deleteSelection().scrollIntoView()),!0);function Dl(r,e){let{$cursor:t}=r.selection;return!t||(e?!e.endOfTextblock("backward",r):t.parentOffset>0)?null:t}var El=(r,e,t)=>{let n=Dl(r,t);if(!n)return!1;let i=Ni(n);if(!i){let o=n.blockRange(),l=o&<(o);return l==null?!1:(e&&e(r.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(!s.type.spec.isolating&&Ei(r,i,e))return!0;if(n.parent.content.size==0&&(ct(s,"end")||x.isSelectable(s))){let o=sn(r.doc,n.before(),n.after(),b.empty);if(o&&o.slice.size{let{$head:n,empty:i}=r.selection,s=n;if(!i)return!1;if(n.parent.isTextblock){if(t?!t.endOfTextblock("backward",r):n.parentOffset>0)return!1;s=Ni(n)}let o=s&&s.nodeBefore;return!o||!x.isSelectable(o)?!1:(e&&e(r.tr.setSelection(x.create(r.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function Ni(r){if(!r.parent.type.spec.isolating)for(let e=r.depth-1;e>=0;e--){if(r.index(e)>0)return r.doc.resolve(r.before(e+1));if(r.node(e).type.spec.isolating)break}return null}function Al(r,e){let{$cursor:t}=r.selection;return!t||(e?!e.endOfTextblock("forward",r):t.parentOffset{let n=Al(r,t);if(!n)return!1;let i=Di(n);if(!i)return!1;let s=i.nodeAfter;if(Ei(r,i,e))return!0;if(n.parent.content.size==0&&(ct(s,"start")||x.isSelectable(s))){let o=sn(r.doc,n.before(),n.after(),b.empty);if(o&&o.slice.size{let{$head:n,empty:i}=r.selection,s=n;if(!i)return!1;if(n.parent.isTextblock){if(t?!t.endOfTextblock("forward",r):n.parentOffset=0;e--){let t=r.node(e);if(r.index(e)+1{let{$head:t,$anchor:n}=r.selection;return!t.parent.type.spec.code||!t.sameParent(n)?!1:(e&&e(r.tr.insertText(` +`).scrollIntoView()),!0)};function Hn(r){for(let e=0;e{let{$head:t,$anchor:n}=r.selection;if(!t.parent.type.spec.code||!t.sameParent(n))return!1;let i=t.node(-1),s=t.indexAfter(-1),o=Hn(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(e){let l=t.after(),a=r.tr.replaceWith(l,l,o.createAndFill());a.setSelection(S.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},zl=(r,e)=>{let t=r.selection,{$from:n,$to:i}=t;if(t instanceof P||n.parent.inlineContent||i.parent.inlineContent)return!1;let s=Hn(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let o=(!n.parentOffset&&i.index(){let{$cursor:t}=r.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let s=t.before();if(ve(r.doc,s))return e&&e(r.tr.split(s).scrollIntoView()),!0}let n=t.blockRange(),i=n&<(n);return i==null?!1:(e&&e(r.tr.lift(n,i).scrollIntoView()),!0)};function Fl(r){return(e,t)=>{let{$from:n,$to:i}=e.selection;if(e.selection instanceof x&&e.selection.node.isBlock)return!n.parentOffset||!ve(e.doc,n.pos)?!1:(t&&t(e.tr.split(n.pos).scrollIntoView()),!0);if(!n.parent.isBlock)return!1;if(t){let s=i.parentOffset==i.parent.content.size,o=e.tr;(e.selection instanceof O||e.selection instanceof P)&&o.deleteSelection();let l=n.depth==0?null:Hn(n.node(-1).contentMatchAt(n.indexAfter(-1))),a=r&&r(i.parent,s),f=a?[a]:s&&l?[{type:l}]:void 0,c=ve(o.doc,o.mapping.map(n.pos),1,f);if(!f&&!c&&ve(o.doc,o.mapping.map(n.pos),1,l?[{type:l}]:void 0)&&(l&&(f=[{type:l}]),c=!0),c&&(o.split(o.mapping.map(n.pos),1,f),!s&&!n.parentOffset&&n.parent.type!=l)){let h=o.mapping.map(n.before()),u=o.doc.resolve(h);l&&n.node(-1).canReplaceWith(u.index(),u.index()+1,l)&&o.setNodeMarkup(o.mapping.map(n.before()),l)}t(o.scrollIntoView())}return!0}}var Ll=Fl();var Vl=(r,e)=>(e&&e(r.tr.setSelection(new P(r.doc))),!0);function Jl(r,e,t){let n=e.nodeBefore,i=e.nodeAfter,s=e.index();return!n||!i||!n.type.compatibleContent(i.type)?!1:!n.content.size&&e.parent.canReplace(s-1,s)?(t&&t(r.tr.delete(e.pos-n.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(i.isTextblock||Nt(r.doc,e.pos))?!1:(t&&t(r.tr.clearIncompatible(e.pos,n.type,n.contentMatchAt(n.childCount)).join(e.pos).scrollIntoView()),!0)}function Ei(r,e,t){let n=e.nodeBefore,i=e.nodeAfter,s,o;if(n.type.spec.isolating||i.type.spec.isolating)return!1;if(Jl(r,e,t))return!0;let l=e.parent.canReplace(e.index(),e.index()+1);if(l&&(s=(o=n.contentMatchAt(n.childCount)).findWrapping(i.type))&&o.matchType(s[0]||i.type).validEnd){if(t){let h=e.pos+i.nodeSize,u=g.empty;for(let m=s.length-1;m>=0;m--)u=g.from(s[m].create(null,u));u=g.from(n.copy(u));let p=r.tr.step(new D(e.pos-1,h,e.pos,h,new b(u,1,0),s.length,!0)),d=h+2*s.length;Nt(p.doc,d)&&p.join(d),t(p.scrollIntoView())}return!0}let a=S.findFrom(e,1),f=a&&a.$from.blockRange(a.$to),c=f&<(f);if(c!=null&&c>=e.depth)return t&&t(r.tr.lift(f,c).scrollIntoView()),!0;if(l&&ct(i,"start",!0)&&ct(n,"end")){let h=n,u=[];for(;u.push(h),!h.isTextblock;)h=h.lastChild;let p=i,d=1;for(;!p.isTextblock;p=p.firstChild)d++;if(h.canReplace(h.childCount,h.childCount,p.content)){if(t){let m=g.empty;for(let k=u.length-1;k>=0;k--)m=g.from(u[k].copy(m));let y=r.tr.step(new D(e.pos-u.length,e.pos+i.nodeSize,e.pos+d,e.pos+i.nodeSize-d,new b(m,u.length,0),0,!0));t(y.scrollIntoView())}return!0}}return!1}function Ii(r){return function(e,t){let n=e.selection,i=r<0?n.$from:n.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return i.node(s).isTextblock?(t&&t(e.tr.setSelection(O.create(e.doc,r<0?i.start(s):i.end(s)))),!0):!1}}var Wl=Ii(-1),ql=Ii(1);function ln(r,e=null){return function(t,n){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=o&&nn(o,r,e);return l?(n&&n(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function Un(r,e=null){return function(t,n){let i=!1;for(let s=0;s{if(i)return!1;if(!(!a.isTextblock||a.hasMarkup(r,e)))if(a.type==r)i=!0;else{let c=t.doc.resolve(f),h=c.index();i=c.parent.canReplaceWith(h,h+1,r)}})}if(!i)return!1;if(n){let s=t.tr;for(let o=0;o{if(o)return!1;o=l.inlineContent&&l.type.allowsMarkType(t)}),o)return!0}return!1}function ne(r,e=null){return function(t,n){let{empty:i,$cursor:s,ranges:o}=t.selection;if(i&&!s||!Kl(t.doc,o,r))return!1;if(n)if(s)r.isInSet(t.storedMarks||s.marks())?n(t.tr.removeStoredMark(r)):n(t.tr.addStoredMark(r.create(e)));else{let l=!1,a=t.tr;for(let f=0;!l&&f{let s=o=>{this[i](o)};return e.dom.addEventListener(i,s),{name:i,handler:s}})}destroy(){this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){this.cursorPos!=null&&t.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),t=!e.parent.inlineContent,n;if(t){let l=e.nodeBefore,a=e.nodeAfter;if(l||a){let f=this.editorView.nodeDOM(this.cursorPos-(l?l.nodeSize:0));if(f){let c=f.getBoundingClientRect(),h=l?c.bottom:c.top;l&&a&&(h=(h+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2),n={left:c.left,right:c.right,top:h-this.width/2,bottom:h+this.width/2}}}}if(!n){let l=this.editorView.coordsAtPos(this.cursorPos);n={left:l.left-this.width/2,right:l.left+this.width/2,top:l.top,bottom:l.bottom}}let i=this.editorView.dom.offsetParent;this.element||(this.element=i.appendChild(document.createElement("div")),this.class&&(this.element.className=this.class),this.element.style.cssText="position: absolute; z-index: 50; pointer-events: none;",this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle("prosemirror-dropcursor-block",t),this.element.classList.toggle("prosemirror-dropcursor-inline",!t);let s,o;if(!i||i==document.body&&getComputedStyle(i).position=="static")s=-pageXOffset,o=-pageYOffset;else{let l=i.getBoundingClientRect();s=l.left-i.scrollLeft,o=l.top-i.scrollTop}this.element.style.left=n.left-s+"px",this.element.style.top=n.top-o+"px",this.element.style.width=n.right-n.left+"px",this.element.style.height=n.bottom-n.top+"px"}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),n=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),i=n&&n.type.spec.disableDropCursor,s=typeof i=="function"?i(this.editorView,t,e):i;if(t&&!s){let o=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let l=rn(this.editorView.state.doc,o,this.editorView.dragging.slice);l!=null&&(o=l)}this.setCursor(o),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){(e.target==this.editorView.dom||!this.editorView.dom.contains(e.relatedTarget))&&this.setCursor(null)}};var Ce={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:"'"},fn={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Hl=typeof navigator!="undefined"&&/Mac/.test(navigator.platform),jl=typeof navigator!="undefined"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(R=0;R<10;R++)Ce[48+R]=Ce[96+R]=String(R);var R;for(R=1;R<=24;R++)Ce[R+111]="F"+R;var R;for(R=65;R<=90;R++)Ce[R]=String.fromCharCode(R+32),fn[R]=String.fromCharCode(R);var R;for(an in Ce)fn.hasOwnProperty(an)||(fn[an]=Ce[an]);var an;function Pi(r){var e=Hl&&r.metaKey&&r.shiftKey&&!r.ctrlKey&&!r.altKey||jl&&r.shiftKey&&r.key&&r.key.length==1||r.key=="Unidentified",t=!e&&r.key||(r.shiftKey?fn:Ce)[r.keyCode]||r.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}var Ul=typeof navigator!="undefined"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function _l(r){let e=r.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let n,i,s,o;for(let l=0;l127)&&(s=Ce[n.keyCode])&&s!=i){let l=e[Yn(s,n)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var W=function(r){for(var e=0;;e++)if(r=r.previousSibling,!r)return e},zt=function(r){let e=r.assignedSlot||r.parentNode;return e&&e.nodeType==11?e.host:e},zi=null,we=function(r,e,t){let n=zi||(zi=document.createRange());return n.setEnd(r,t==null?r.nodeValue.length:t),n.setStart(r,e||0),n},tt=function(r,e,t,n){return t&&(Bi(r,e,t,n,-1)||Bi(r,e,t,n,1))},Gl=/^(img|br|input|textarea|hr)$/i;function Bi(r,e,t,n,i){for(;;){if(r==t&&e==n)return!0;if(e==(i<0?0:he(r))){let s=r.parentNode;if(!s||s.nodeType!=1||kr(r)||Gl.test(r.nodeName)||r.contentEditable=="false")return!1;e=W(r)+(i<0?0:1),r=s}else if(r.nodeType==1){if(r=r.childNodes[e+(i<0?-1:0)],r.contentEditable=="false")return!1;e=i<0?he(r):0}else return!1}}function he(r){return r.nodeType==3?r.nodeValue.length:r.childNodes.length}function Xl(r,e,t){for(let n=e==0,i=e==he(r);n||i;){if(r==t)return!0;let s=W(r);if(r=r.parentNode,!r)return!1;n=n&&s==0,i=i&&s==he(r)}}function kr(r){let e;for(let t=r;t&&!(e=t.pmViewDesc);t=t.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==r||e.contentDOM==r)}var yn=function(r){return r.focusNode&&tt(r.focusNode,r.focusOffset,r.anchorNode,r.anchorOffset)};function Ge(r,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=r,t.key=t.code=e,t}function Ql(r){let e=r.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function Zl(r,e,t){if(r.caretPositionFromPoint)try{let n=r.caretPositionFromPoint(e,t);if(n)return{node:n.offsetNode,offset:n.offset}}catch(n){}if(r.caretRangeFromPoint){let n=r.caretRangeFromPoint(e,t);if(n)return{node:n.startContainer,offset:n.startOffset}}}var me=typeof navigator!="undefined"?navigator:null,Fi=typeof document!="undefined"?document:null,Le=me&&me.userAgent||"",nr=/Edge\/(\d+)/.exec(Le),ms=/MSIE \d/.exec(Le),rr=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Le),U=!!(ms||rr||nr),Fe=ms?document.documentMode:rr?+rr[1]:nr?+nr[1]:0,ie=!U&&/gecko\/(\d+)/i.test(Le);ie&&+(/Firefox\/(\d+)/.exec(Le)||[0,0])[1];var ir=!U&&/Chrome\/(\d+)/.exec(Le),L=!!ir,ea=ir?+ir[1]:0,K=!U&&!!me&&/Apple Computer/.test(me.vendor),mt=K&&(/Mobile\/\w+/.test(Le)||!!me&&me.maxTouchPoints>2),Q=mt||(me?/Mac/.test(me.platform):!1),ta=me?/Win/.test(me.platform):!1,re=/Android \d/.test(Le),Jt=!!Fi&&"webkitFontSmoothing"in Fi.documentElement.style,na=Jt?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function ra(r){return{left:0,right:r.documentElement.clientWidth,top:0,bottom:r.documentElement.clientHeight}}function Oe(r,e){return typeof r=="number"?r:r[e]}function ia(r){let e=r.getBoundingClientRect(),t=e.width/r.offsetWidth||1,n=e.height/r.offsetHeight||1;return{left:e.left,right:e.left+r.clientWidth*t,top:e.top,bottom:e.top+r.clientHeight*n}}function Li(r,e,t){let n=r.someProp("scrollThreshold")||0,i=r.someProp("scrollMargin")||5,s=r.dom.ownerDocument;for(let o=t||r.dom;o;o=zt(o)){if(o.nodeType!=1)continue;let l=o,a=l==s.body,f=a?ra(s):ia(l),c=0,h=0;if(e.topf.bottom-Oe(n,"bottom")&&(h=e.bottom-e.top>f.bottom-f.top?e.top+Oe(i,"top")-f.top:e.bottom-f.bottom+Oe(i,"bottom")),e.leftf.right-Oe(n,"right")&&(c=e.right-f.right+Oe(i,"right")),c||h)if(a)s.defaultView.scrollBy(c,h);else{let u=l.scrollLeft,p=l.scrollTop;h&&(l.scrollTop+=h),c&&(l.scrollLeft+=c);let d=l.scrollLeft-u,m=l.scrollTop-p;e={left:e.left-d,top:e.top-m,right:e.right-d,bottom:e.bottom-m}}if(a||/^(fixed|sticky)$/.test(getComputedStyle(o).position))break}}function sa(r){let e=r.dom.getBoundingClientRect(),t=Math.max(0,e.top),n,i;for(let s=(e.left+e.right)/2,o=t+1;o=t-20){n=l,i=a.top;break}}return{refDOM:n,refTop:i,stack:gs(r.dom)}}function gs(r){let e=[],t=r.ownerDocument;for(let n=r;n&&(e.push({dom:n,top:n.scrollTop,left:n.scrollLeft}),r!=t);n=zt(n));return e}function oa({refDOM:r,refTop:e,stack:t}){let n=r?r.getBoundingClientRect().top:0;ys(t,n==0?0:n-e)}function ys(r,e){for(let t=0;t=l){o=Math.max(d.bottom,o),l=Math.min(d.top,l);let m=d.left>e.left?d.left-e.left:d.right=(d.left+d.right)/2?1:0));continue}}else d.top>e.top&&!a&&d.left<=e.left&&d.right>=e.left&&(a=c,f={left:Math.max(d.left,Math.min(d.right,e.left)),top:d.top});!t&&(e.left>=d.right&&e.top>=d.top||e.left>=d.left&&e.top>=d.bottom)&&(s=h+1)}}return!t&&a&&(t=a,i=f,n=0),t&&t.nodeType==3?aa(t,i):!t||n&&t.nodeType==1?{node:r,offset:s}:bs(t,i)}function aa(r,e){let t=r.nodeValue.length,n=document.createRange();for(let i=0;i=(s.left+s.right)/2?1:0)}}return{node:r,offset:0}}function xr(r,e){return r.left>=e.left-1&&r.left<=e.right+1&&r.top>=e.top-1&&r.top<=e.bottom+1}function fa(r,e){let t=r.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(o.left+o.right)/2?1:-1}return r.docView.posFromDOM(n,i,s)}function ha(r,e,t,n){let i=-1;for(let s=e,o=!1;s!=r.dom;){let l=r.docView.nearestDesc(s,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent&&!o||!l.contentDOM)){let a=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&!o&&(o=!0,a.left>n.left||a.top>n.top?i=l.posBefore:(a.right-1?i:r.docView.posFromDOM(e,t,-1)}function ks(r,e,t){let n=r.childNodes.length;if(n&&t.tope.top&&i++}let f;Jt&&i&&n.nodeType==1&&(f=n.childNodes[i-1]).nodeType==1&&f.contentEditable=="false"&&f.getBoundingClientRect().top>=e.top&&i--,n==r.dom&&i==n.childNodes.length-1&&n.lastChild.nodeType==1&&e.top>n.lastChild.getBoundingClientRect().bottom?l=r.state.doc.content.size:(i==0||n.nodeType!=1||n.childNodes[i-1].nodeName!="BR")&&(l=ha(r,n,i,e))}l==null&&(l=ca(r,o,e));let a=r.docView.nearestDesc(o,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function Vi(r){return r.top=0&&i==n.nodeValue.length?(a--,c=1):t<0?a--:f++,Rt(Pe(we(n,a,f),c),c<0)}if(!r.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==he(n))){let a=n.childNodes[i-1];if(a.nodeType==1)return Qn(a.getBoundingClientRect(),!1)}if(s==null&&i=0)}if(s==null&&i&&(t<0||i==he(n))){let a=n.childNodes[i-1],f=a.nodeType==3?we(a,he(a)-(o?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(f)return Rt(Pe(f,1),!1)}if(s==null&&i=0)}function Rt(r,e){if(r.width==0)return r;let t=e?r.left:r.right;return{top:r.top,bottom:r.bottom,left:t,right:t}}function Qn(r,e){if(r.height==0)return r;let t=e?r.top:r.bottom;return{top:t,bottom:t,left:r.left,right:r.right}}function Ss(r,e,t){let n=r.state,i=r.root.activeElement;n!=e&&r.updateState(e),i!=r.dom&&r.focus();try{return t()}finally{n!=e&&r.updateState(n),i!=r.dom&&i&&i.focus()}}function pa(r,e,t){let n=e.selection,i=t=="up"?n.$from:n.$to;return Ss(r,e,()=>{let{node:s}=r.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=r.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let o=xs(r,i.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=we(l,0,l.nodeValue.length).getClientRects();else continue;for(let f=0;fc.top+1&&(t=="up"?o.top-c.top>(c.bottom-o.top)*2:c.bottom-o.bottom>(o.bottom-c.top)*2))return!1}}return!0})}var ma=/[\u0590-\u08ac]/;function ga(r,e,t){let{$head:n}=e.selection;if(!n.parent.isTextblock)return!1;let i=n.parentOffset,s=!i,o=i==n.parent.content.size,l=r.domSelection();return!ma.test(n.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:Ss(r,e,()=>{let{focusNode:a,focusOffset:f,anchorNode:c,anchorOffset:h}=r.domSelectionRange(),u=l.caretBidiLevel;l.modify("move",t,"character");let p=n.depth?r.docView.domAfterPos(n.before()):r.dom,{focusNode:d,focusOffset:m}=r.domSelectionRange(),y=d&&!p.contains(d.nodeType==1?d:d.parentNode)||a==d&&f==m;try{l.collapse(c,h),a&&(a!=c||f!=h)&&l.extend&&l.extend(a,f)}catch(k){}return u!=null&&(l.caretBidiLevel=u),y})}var Ji=null,Wi=null,qi=!1;function ya(r,e,t){return Ji==e&&Wi==t?qi:(Ji=e,Wi=t,qi=t=="up"||t=="down"?pa(r,e,t):ga(r,e,t))}var Z=0,Ki=1,Xe=2,ge=3,nt=class{constructor(e,t,n,i){this.parent=e,this.children=t,this.dom=n,this.contentDOM=i,this.dirty=Z,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tW(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!1;break}if(s.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!0;break}if(s.nextSibling)break}}return(i==null?n>0:i)?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),o;if(s&&(!t||s.node))if(n&&(o=s.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))n=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let n=t;n;n=n.parent)if(n==this)return t}posFromDOM(e,t,n){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,t,n)}return-1}descAt(e){for(let t=0,n=0;te||o instanceof hn){i=e-s;break}s=l}if(i)return this.children[n].domFromPos(i-this.children[n].border,t);for(let s;n&&!(s=this.children[n-1]).size&&s instanceof cn&&s.side>=0;n--);if(t<=0){let s,o=!0;for(;s=n?this.children[n-1]:null,!(!s||s.dom.parentNode==this.contentDOM);n--,o=!1);return s&&t&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?W(s.dom)+1:0}}else{let s,o=!0;for(;s=n=c&&t<=f-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,c);e=o;for(let h=l;h>0;h--){let u=this.children[h-1];if(u.size&&u.dom.parentNode==this.contentDOM&&!u.emptyChildAt(1)){i=W(u.dom)+1;break}e-=u.size}i==-1&&(i=0)}if(i>-1&&(f>t||l==this.children.length-1)){t=f;for(let c=l+1;cp&&ot){let p=l;l=a,a=p}let u=document.createRange();u.setEnd(a.node,a.offset),u.setStart(l.node,l.offset),f.removeAllRanges(),f.addRange(u)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let n=0,i=0;i=n:en){let l=n+s.border,a=o-s.border;if(e>=l&&t<=a){this.dirty=e==n||t==o?Xe:Ki,e==l&&t==a&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=ge:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?Xe:ge}n=o}this.dirty=Xe}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=e==1?Xe:Ki;t.dirty{if(!s)return i;if(s.parent)return s.parent.posBeforeChild(s)})),!t.type.spec.raw){if(o.nodeType!=1){let l=document.createElement("span");l.appendChild(o),o=l}o.contentEditable="false",o.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=t,this.widget=t,s=this}matchesWidget(e){return this.dirty==Z&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}},sr=class extends nt{constructor(e,t,n,i){super(e,[],t,null),this.textDOM=n,this.text=i}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}},Ne=class extends nt{constructor(e,t,n,i){super(e,[],n,i),this.mark=t}static create(e,t,n,i){let s=i.nodeViews[t.type.name],o=s&&s(t,i,n);return(!o||!o.dom)&&(o=V.renderSpec(document,t.type.spec.toDOM(t,n))),new Ne(e,t,o.dom,o.contentDOM||o.dom)}parseRule(){return this.dirty&ge||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=ge&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=Z){let n=this.parent;for(;!n.node;)n=n.parent;n.dirty0&&(s=cr(s,0,e,n));for(let l=0;l{if(!a)return o;if(a.parent)return a.parent.posBeforeChild(a)},n,i),c=f&&f.dom,h=f&&f.contentDOM;if(t.isText){if(!c)c=document.createTextNode(t.text);else if(c.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else c||({dom:c,contentDOM:h}=V.renderSpec(document,t.type.spec.toDOM(t)));!h&&!t.isText&&c.nodeName!="BR"&&(c.hasAttribute("contenteditable")||(c.contentEditable="false"),t.type.spec.draggable&&(c.draggable=!0));let u=c;return c=Os(c,n,t),f?a=new or(e,t,n,i,c,h||null,u,f,s,o+1):t.isText?new gt(e,t,n,i,c,u,s):new de(e,t,n,i,c,h||null,u,s,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let n=this.children[t];if(this.dom.contains(n.dom.parentNode)){e.contentElement=n.dom.parentNode;break}}e.contentElement||(e.getContent=()=>g.empty)}return e}matchesNode(e,t,n){return this.dirty==Z&&e.eq(this.node)&&ar(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let n=this.node.inlineContent,i=t,s=e.composing?this.localCompositionInfo(e,t):null,o=s&&s.pos>-1?s:null,l=s&&s.pos<0,a=new fr(this,o&&o.node,e);Sa(this.node,this.innerDeco,(f,c,h)=>{f.spec.marks?a.syncToMarks(f.spec.marks,n,e):f.type.side>=0&&!h&&a.syncToMarks(c==this.node.childCount?C.none:this.node.child(c).marks,n,e),a.placeWidget(f,e,i)},(f,c,h,u)=>{a.syncToMarks(f.marks,n,e);let p;a.findNodeMatch(f,c,h,u)||l&&e.state.selection.from>i&&e.state.selection.to-1&&a.updateNodeAt(f,c,h,p,e)||a.updateNextNode(f,c,h,e,u,i)||a.addNode(f,c,h,e,i),i+=f.nodeSize}),a.syncToMarks([],n,e),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==Xe)&&(o&&this.protectLocalComposition(e,o),Ms(this.contentDOM,this.children,e),mt&&Ma(this.dom))}localCompositionInfo(e,t){let{from:n,to:i}=e.state.selection;if(!(e.state.selection instanceof O)||nt+this.node.content.size)return null;let s=e.domSelectionRange(),o=Ca(s.focusNode,s.focusOffset);if(!o||!this.dom.contains(o.parentNode))return null;if(this.node.inlineContent){let l=o.nodeValue,a=Oa(this.node.content,l,n-t,i-t);return a<0?null:{node:o,pos:a,text:l}}else return{node:o,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:n,text:i}){if(this.getDesc(t))return;let s=t;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let o=new sr(this,s,t,i);e.input.compositionNodes.push(o),this.children=cr(this.children,n,n+i.length,e,o)}update(e,t,n,i){return this.dirty==ge||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,n,i),!0)}updateInner(e,t,n,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=Z}updateOuterDeco(e){if(ar(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,n=this.dom;this.dom=Cs(this.dom,this.nodeDOM,lr(this.outerDeco,this.node,t),lr(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable")}get domAtom(){return this.node.isAtom}};function $i(r,e,t,n,i){Os(n,e,r);let s=new de(void 0,r,e,t,n,n,n,i,0);return s.contentDOM&&s.updateChildren(i,0),s}var gt=class extends de{constructor(e,t,n,i,s,o,l){super(e,t,n,i,s,null,o,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,i){return this.dirty==ge||this.dirty!=Z&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=Z||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=Z,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,n){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,n)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,n){let i=this.node.cut(e,t),s=document.createTextNode(i.text);return new gt(this.parent,i,this.outerDeco,this.innerDeco,s,s,n)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=ge)}get domAtom(){return!1}},hn=class extends nt{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Z&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},or=class extends de{constructor(e,t,n,i,s,o,l,a,f,c){super(e,t,n,i,s,o,l,f,c),this.spec=a}update(e,t,n,i){if(this.dirty==ge)return!1;if(this.spec.update){let s=this.spec.update(e,t,n);return s&&this.updateInner(e,t,n,i),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,n,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,i){this.spec.setSelection?this.spec.setSelection(e,t,n):super.setSelection(e,t,n,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function Ms(r,e,t){let n=r.firstChild,i=!1;for(let s=0;s>1,o=Math.min(s,e.length);for(;i-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let a=Ne.create(this.top,e[s],t,n);this.top.children.splice(this.index,0,a),this.top=a,this.changed=!0}this.index=0,s++}}findNodeMatch(e,t,n,i){let s=-1,o;if(i>=this.preMatch.index&&(o=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&o.matchesNode(e,t,n))s=this.top.children.indexOf(o,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(n){let f=t.children[n-1];if(f instanceof Ne)t=f,n=f.children.length;else{l=f,n--;break}}else{if(t==e)break e;n=t.parent.children.indexOf(t),t=t.parent}let a=l.node;if(!!a){if(a!=r.child(i-1))break;--i,s.set(l,i),o.push(l)}}return{index:i,matched:s,matches:o.reverse()}}function xa(r,e){return r.type.side-e.type.side}function Sa(r,e,t,n){let i=e.locals(r),s=0;if(i.length==0){for(let f=0;fs;)l.push(i[o++]);let d=s+u.nodeSize;if(u.isText){let y=d;o!y.inline):l.slice();n(u,m,e.forChild(s,u),p),s=d}}function Ma(r){if(r.nodeName=="UL"||r.nodeName=="OL"){let e=r.style.cssText;r.style.cssText=e+"; list-style: square !important",window.getComputedStyle(r).listStyle,r.style.cssText=e}}function Ca(r,e){for(;;){if(r.nodeType==3)return r;if(r.nodeType==1&&e>0){if(r.childNodes.length>e&&r.childNodes[e].nodeType==3)return r.childNodes[e];r=r.childNodes[e-1],e=he(r)}else if(r.nodeType==1&&e=t){if(s>=n&&a.slice(n-e.length-l,n-l)==e)return n-e.length;let f=l=0&&f+e.length+l>=t)return l+f;if(t==n&&a.length>=n+e.length-l&&a.slice(n-l,n-l+e.length)==e)return n}}return-1}function cr(r,e,t,n,i){let s=[];for(let o=0,l=0;o=t||c<=e?s.push(a):(ft&&s.push(a.slice(t-f,a.size,n)))}return s}function Sr(r,e=null){let t=r.domSelectionRange(),n=r.state.doc;if(!t.focusNode)return null;let i=r.docView.nearestDesc(t.focusNode),s=i&&i.size==0,o=r.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(o<0)return null;let l=n.resolve(o),a,f;if(yn(t)){for(a=l;i&&!i.node;)i=i.parent;let c=i.node;if(i&&c.isAtom&&x.isSelectable(c)&&i.parent&&!(c.isInline&&Xl(t.focusNode,t.focusOffset,i.dom))){let h=i.posBefore;f=new x(o==h?l:n.resolve(h))}}else{let c=r.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(c<0)return null;a=n.resolve(c)}if(!f){let c=e=="pointer"||r.state.selection.head{(t.anchorNode!=n||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",r.input.hideSelectionGuard),setTimeout(()=>{(!ws(r)||r.state.selection.visible)&&r.dom.classList.remove("ProseMirror-hideselection")},20))})}function Ta(r){let e=r.domSelection(),t=document.createRange(),n=r.cursorWrapper.dom,i=n.nodeName=="IMG";i?t.setEnd(n.parentNode,W(n)+1):t.setEnd(n,0),t.collapse(!1),e.removeAllRanges(),e.addRange(t),!i&&!r.state.selection.visible&&U&&Fe<=11&&(n.disabled=!0,n.disabled=!1)}function Ts(r,e){if(e instanceof x){let t=r.docView.descAt(e.from);t!=r.lastSelectedViewDesc&&(Yi(r),t&&t.selectNode(),r.lastSelectedViewDesc=t)}else Yi(r)}function Yi(r){r.lastSelectedViewDesc&&(r.lastSelectedViewDesc.parent&&r.lastSelectedViewDesc.deselectNode(),r.lastSelectedViewDesc=void 0)}function Mr(r,e,t,n){return r.someProp("createSelectionBetween",i=>i(r,e,t))||O.between(e,t,n)}function Gi(r){return r.editable&&!r.hasFocus()?!1:Ns(r)}function Ns(r){let e=r.domSelectionRange();if(!e.anchorNode)return!1;try{return r.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(r.editable||r.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch(t){return!1}}function Na(r){let e=r.docView.domFromPos(r.state.selection.anchor,0),t=r.domSelectionRange();return tt(e.node,e.offset,t.anchorNode,t.anchorOffset)}function hr(r,e){let{$anchor:t,$head:n}=r.selection,i=e>0?t.max(n):t.min(n),s=i.parent.inlineContent?i.depth?r.doc.resolve(e>0?i.after():i.before()):null:i;return s&&S.findFrom(s,e)}function ze(r,e){return r.dispatch(r.state.tr.setSelection(e).scrollIntoView()),!0}function Xi(r,e,t){let n=r.state.selection;if(n instanceof O)if(t.indexOf("s")>-1){let{$head:i}=n,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let o=r.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return ze(r,new O(n.$anchor,o))}else if(n.empty){if(r.endOfTextblock(e>0?"forward":"backward")){let i=hr(r.state,e);return i&&i instanceof x?ze(r,i):!1}else if(!(Q&&t.indexOf("m")>-1)){let i=n.$head,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,o;if(!s||s.isText)return!1;let l=e<0?i.pos-s.nodeSize:i.pos;return s.isAtom||(o=r.docView.descAt(l))&&!o.contentDOM?x.isSelectable(s)?ze(r,new x(e<0?r.state.doc.resolve(i.pos-s.nodeSize):i)):Jt?ze(r,new O(r.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(n instanceof x&&n.node.isInline)return ze(r,new O(e>0?n.$to:n.$from));{let i=hr(r.state,e);return i?ze(r,i):!1}}}function un(r){return r.nodeType==3?r.nodeValue.length:r.childNodes.length}function Pt(r,e){let t=r.pmViewDesc;return t&&t.size==0&&(e<0||r.nextSibling||r.nodeName!="BR")}function ut(r,e){return e<0?Da(r):Ea(r)}function Da(r){let e=r.domSelectionRange(),t=e.focusNode,n=e.focusOffset;if(!t)return;let i,s,o=!1;for(ie&&t.nodeType==1&&n0){if(t.nodeType!=1)break;{let l=t.childNodes[n-1];if(Pt(l,-1))i=t,s=--n;else if(l.nodeType==3)t=l,n=t.nodeValue.length;else break}}else{if(Ds(t))break;{let l=t.previousSibling;for(;l&&Pt(l,-1);)i=t.parentNode,s=W(l),l=l.previousSibling;if(l)t=l,n=un(t);else{if(t=t.parentNode,t==r.dom)break;n=0}}}o?ur(r,t,n):i&&ur(r,i,s)}function Ea(r){let e=r.domSelectionRange(),t=e.focusNode,n=e.focusOffset;if(!t)return;let i=un(t),s,o;for(;;)if(n{r.state==i&&Te(r)},50)}function Qi(r,e){let t=r.state.doc.resolve(e);if(!(L||ta)&&t.parent.inlineContent){let i=r.coordsAtPos(e);if(e>t.start()){let s=r.coordsAtPos(e-1),o=(s.top+s.bottom)/2;if(o>i.top&&o1)return s.lefti.top&&o1)return s.left>i.left?"ltr":"rtl"}}return getComputedStyle(r.dom).direction=="rtl"?"rtl":"ltr"}function Zi(r,e,t){let n=r.state.selection;if(n instanceof O&&!n.empty||t.indexOf("s")>-1||Q&&t.indexOf("m")>-1)return!1;let{$from:i,$to:s}=n;if(!i.parent.inlineContent||r.endOfTextblock(e<0?"up":"down")){let o=hr(r.state,e);if(o&&o instanceof x)return ze(r,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=n instanceof P?S.near(o,e):S.findFrom(o,e);return l?ze(r,l):!1}return!1}function es(r,e){if(!(r.state.selection instanceof O))return!0;let{$head:t,$anchor:n,empty:i}=r.state.selection;if(!t.sameParent(n))return!0;if(!i)return!1;if(r.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(s&&!s.isText){let o=r.state.tr;return e<0?o.delete(t.pos-s.nodeSize,t.pos):o.delete(t.pos,t.pos+s.nodeSize),r.dispatch(o),!0}return!1}function ts(r,e,t){r.domObserver.stop(),e.contentEditable=t,r.domObserver.start()}function Ra(r){if(!K||r.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=r.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let n=e.firstChild;ts(r,n,"true"),setTimeout(()=>ts(r,n,"false"),20)}return!1}function va(r){let e="";return r.ctrlKey&&(e+="c"),r.metaKey&&(e+="m"),r.altKey&&(e+="a"),r.shiftKey&&(e+="s"),e}function Pa(r,e){let t=e.keyCode,n=va(e);if(t==8||Q&&t==72&&n=="c")return es(r,-1)||ut(r,-1);if(t==46&&!e.shiftKey||Q&&t==68&&n=="c")return es(r,1)||ut(r,1);if(t==13||t==27)return!0;if(t==37||Q&&t==66&&n=="c"){let i=t==37?Qi(r,r.state.selection.from)=="ltr"?-1:1:-1;return Xi(r,i,n)||ut(r,i)}else if(t==39||Q&&t==70&&n=="c"){let i=t==39?Qi(r,r.state.selection.from)=="ltr"?1:-1:1;return Xi(r,i,n)||ut(r,i)}else{if(t==38||Q&&t==80&&n=="c")return Zi(r,-1,n)||ut(r,-1);if(t==40||Q&&t==78&&n=="c")return Ra(r)||Zi(r,1,n)||ut(r,1);if(n==(Q?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Es(r,e){r.someProp("transformCopied",p=>{e=p(e,r)});let t=[],{content:n,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&n.childCount==1&&n.firstChild.childCount==1;){i--,s--;let p=n.firstChild;t.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),n=p.content}let o=r.someProp("clipboardSerializer")||V.fromSchema(r.state.schema),l=zs(),a=l.createElement("div");a.appendChild(o.serializeFragment(n,{document:l}));let f=a.firstChild,c,h=0;for(;f&&f.nodeType==1&&(c=Ps[f.nodeName.toLowerCase()]);){for(let p=c.length-1;p>=0;p--){let d=l.createElement(c[p]);for(;a.firstChild;)d.appendChild(a.firstChild);a.appendChild(d),h++}f=a.firstChild}f&&f.nodeType==1&&f.setAttribute("data-pm-slice",`${i} ${s}${h?` -${h}`:""} ${JSON.stringify(t)}`);let u=r.someProp("clipboardTextSerializer",p=>p(e,r))||e.content.textBetween(0,e.content.size,` -`);return{dom:a,text:u}}function Es(r,e,t,n,i){let s=i.parent.type.spec.code,o,l;if(!t&&!e)return null;let a=e&&(n||s||!t);if(a){if(r.someProp("transformPastedText",u=>{e=u(e,s||n,r)}),s)return e?new b(g.from(r.state.schema.text(e.replace(/\r\n?/g,` -`))),0,0):b.empty;let h=r.someProp("clipboardTextParser",u=>u(e,i,n,r));if(h)l=h;else{let u=i.marks(),{schema:p}=r.state,d=j.fromSchema(p);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let y=o.appendChild(document.createElement("p"));m&&y.appendChild(d.serializeNode(p.text(m,u)))})}}else r.someProp("transformPastedHTML",h=>{t=h(t,r)}),o=za(t),Jt&&Ba(o);let f=o&&o.querySelector("[data-pm-slice]"),c=f&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(f.getAttribute("data-pm-slice")||"");if(c&&c[3])for(let h=+c[3];h>0;h--){let u=o.firstChild;for(;u&&u.nodeType!=1;)u=u.nextSibling;if(!u)break;o=u}if(l||(l=(r.someProp("clipboardParser")||r.someProp("domParser")||ae.fromSchema(r.state.schema)).parseSlice(o,{preserveWhitespace:!!(a||c),context:i,ruleFromNode(u){return u.nodeName=="BR"&&!u.nextSibling&&u.parentNode&&!va.test(u.parentNode.nodeName)?{ignore:!0}:null}})),c)l=Fa(ts(l,+c[1],+c[2]),c[4]);else if(l=b.maxOpen(Pa(l.content,i),!0),l.openStart||l.openEnd){let h=0,u=0;for(let p=l.content.firstChild;h{l=h(l,r)}),l}var va=/^(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 Pa(r,e){if(r.childCount<2)return r;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),s,o=[];if(r.forEach(l=>{if(!o)return;let a=i.findWrapping(l.type),f;if(!a)return o=null;if(f=o.length&&s.length&&As(a,s,l,o[o.length-1],0))o[o.length-1]=f;else{o.length&&(o[o.length-1]=Rs(o[o.length-1],s.length));let c=Is(l,a);o.push(c),i=i.matchType(c.type),s=a}}),o)return g.from(o)}return r}function Is(r,e,t=0){for(let n=e.length-1;n>=t;n--)r=e[n].create(null,g.from(r));return r}function As(r,e,t,n,i){if(i1&&(s=0),i=t&&(l=e<0?o.contentMatchAt(0).fillBefore(l,s<=i).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(g.empty,!0))),r.replaceChild(e<0?0:r.childCount-1,o.copy(l))}function ts(r,e,t){return e]*>)*/.exec(r);e&&(r=r.slice(e[0].length));let t=Ps().createElement("div"),n=/<([a-z][^>\s]+)/i.exec(r),i;if((i=n&&vs[n[1].toLowerCase()])&&(r=i.map(s=>"<"+s+">").join("")+r+i.map(s=>"").reverse().join("")),t.innerHTML=r,i)for(let s=0;s=0;l-=2){let a=t.nodes[n[l]];if(!a||a.hasRequiredAttrs())break;i=g.from(a.create(n[l+1],i)),s++,o++}return new b(i,s,o)}var K={},$={},Va={touchstart:!0,touchmove:!0},dr=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:""},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastAndroidDelete=0,this.composing=!1,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 La(r){for(let e in K){let t=K[e];r.dom.addEventListener(e,r.input.eventHandlers[e]=n=>{Wa(r,n)&&!Mr(r,n)&&(r.editable||!(n.type in $))&&t(r,n)},Va[e]?{passive:!0}:void 0)}q&&r.dom.addEventListener("input",()=>null),pr(r)}function ze(r,e){r.input.lastSelectionOrigin=e,r.input.lastSelectionTime=Date.now()}function Ja(r){r.domObserver.stop();for(let e in r.input.eventHandlers)r.dom.removeEventListener(e,r.input.eventHandlers[e]);clearTimeout(r.input.composingTimeout),clearTimeout(r.input.lastIOSEnterFallbackTimeout)}function pr(r){r.someProp("handleDOMEvents",e=>{for(let t in e)r.input.eventHandlers[t]||r.dom.addEventListener(t,r.input.eventHandlers[t]=n=>Mr(r,n))})}function Mr(r,e){return r.someProp("handleDOMEvents",t=>{let n=t[e.type];return n?n(r,e)||e.defaultPrevented:!1})}function Wa(r,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=r.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function qa(r,e){!Mr(r,e)&&K[e.type]&&(r.editable||!(e.type in $))&&K[e.type](r,e)}$.keydown=(r,e)=>{let t=e;if(r.input.shiftKey=t.keyCode==16||t.shiftKey,!Bs(r,t)&&(r.input.lastKeyCode=t.keyCode,r.input.lastKeyCodeTime=Date.now(),!(re&&V&&t.keyCode==13)))if(t.keyCode!=229&&r.domObserver.forceFlush(),mt&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let n=Date.now();r.input.lastIOSEnter=n,r.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{r.input.lastIOSEnter==n&&(r.someProp("handleKeyDown",i=>i(r,Ge(13,"Enter"))),r.input.lastIOSEnter=0)},200)}else r.someProp("handleKeyDown",n=>n(r,t))||Ra(r,t)?t.preventDefault():ze(r,"key")};$.keyup=(r,e)=>{e.keyCode==16&&(r.input.shiftKey=!1)};$.keypress=(r,e)=>{let t=e;if(Bs(r,t)||!t.charCode||t.ctrlKey&&!t.altKey||Q&&t.metaKey)return;if(r.someProp("handleKeyPress",i=>i(r,t))){t.preventDefault();return}let n=r.state.selection;if(!(n instanceof O)||!n.$from.sameParent(n.$to)){let i=String.fromCharCode(t.charCode);!/[\r\n]/.test(i)&&!r.someProp("handleTextInput",s=>s(r,n.$from.pos,n.$to.pos,i))&&r.dispatch(r.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function bn(r){return{left:r.clientX,top:r.clientY}}function Ka(r,e){let t=e.x-r.clientX,n=e.y-r.clientY;return t*t+n*n<100}function Cr(r,e,t,n,i){if(n==-1)return!1;let s=r.state.doc.resolve(n);for(let o=s.depth+1;o>0;o--)if(r.someProp(e,l=>o>s.depth?l(r,t,s.nodeAfter,s.before(o),i,!0):l(r,t,s.node(o),s.before(o),i,!1)))return!0;return!1}function pt(r,e,t){r.focused||r.focus();let n=r.state.tr.setSelection(e);t=="pointer"&&n.setMeta("pointer",!0),r.dispatch(n)}function $a(r,e){if(e==-1)return!1;let t=r.state.doc.resolve(e),n=t.nodeAfter;return n&&n.isAtom&&x.isSelectable(n)?(pt(r,new x(t),"pointer"),!0):!1}function ja(r,e){if(e==-1)return!1;let t=r.state.selection,n,i;t instanceof x&&(n=t.node);let s=r.state.doc.resolve(e);for(let o=s.depth+1;o>0;o--){let l=o>s.depth?s.nodeAfter:s.node(o);if(x.isSelectable(l)){n&&t.$from.depth>0&&o>=t.$from.depth&&s.before(t.$from.depth+1)==t.$from.pos?i=s.before(t.$from.depth):i=s.before(o);break}}return i!=null?(pt(r,x.create(r.state.doc,i),"pointer"),!0):!1}function Ha(r,e,t,n,i){return Cr(r,"handleClickOn",e,t,n)||r.someProp("handleClick",s=>s(r,e,n))||(i?ja(r,t):$a(r,t))}function Ua(r,e,t,n){return Cr(r,"handleDoubleClickOn",e,t,n)||r.someProp("handleDoubleClick",i=>i(r,e,n))}function _a(r,e,t,n){return Cr(r,"handleTripleClickOn",e,t,n)||r.someProp("handleTripleClick",i=>i(r,e,n))||Ya(r,t,n)}function Ya(r,e,t){if(t.button!=0)return!1;let n=r.state.doc;if(e==-1)return n.inlineContent?(pt(r,O.create(n,0,n.content.size),"pointer"),!0):!1;let i=n.resolve(e);for(let s=i.depth+1;s>0;s--){let o=s>i.depth?i.nodeAfter:i.node(s),l=i.before(s);if(o.inlineContent)pt(r,O.create(n,l+1,l+1+o.content.size),"pointer");else if(x.isSelectable(o))pt(r,x.create(n,l),"pointer");else continue;return!0}}function Or(r){return dn(r)}var zs=Q?"metaKey":"ctrlKey";K.mousedown=(r,e)=>{let t=e;r.input.shiftKey=t.shiftKey;let n=Or(r),i=Date.now(),s="singleClick";i-r.input.lastClick.time<500&&Ka(t,r.input.lastClick)&&!t[zs]&&(r.input.lastClick.type=="singleClick"?s="doubleClick":r.input.lastClick.type=="doubleClick"&&(s="tripleClick")),r.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:s};let o=r.posAtCoords(bn(t));!o||(s=="singleClick"?(r.input.mouseDown&&r.input.mouseDown.done(),r.input.mouseDown=new mr(r,o,t,!!n)):(s=="doubleClick"?Ua:_a)(r,o.pos,o.inside,t)?t.preventDefault():ze(r,"pointer"))};var mr=class{constructor(e,t,n,i){this.view=e,this.pos=t,this.event=n,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!n[zs],this.allowDefault=n.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let c=e.state.doc.resolve(t.pos);s=c.parent,o=c.depth?c.before():0}let l=i?null:n.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a?a.dom:null;let{selection:f}=e.state;(n.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||f instanceof x&&f.from<=o&&f.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&ie&&!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)),ze(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(()=>we(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(bn(e))),this.updateAllowDefault(e),this.allowDefault||!t?ze(this.view,"pointer"):Ha(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||q&&this.mightDrag&&!this.mightDrag.node.isAtom||V&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(pt(this.view,S.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):ze(this.view,"pointer")}move(e){this.updateAllowDefault(e),ze(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)}};K.touchstart=r=>{r.input.lastTouch=Date.now(),Or(r),ze(r,"pointer")};K.touchmove=r=>{r.input.lastTouch=Date.now(),ze(r,"pointer")};K.contextmenu=r=>Or(r);function Bs(r,e){return r.composing?!0:q&&Math.abs(e.timeStamp-r.input.compositionEndedAt)<500?(r.input.compositionEndedAt=-2e8,!0):!1}var Ga=re?5e3:-1;$.compositionstart=$.compositionupdate=r=>{if(!r.composing){r.domObserver.flush();let{state:e}=r,t=e.selection.$from;if(e.selection.empty&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(n=>n.type.spec.inclusive===!1)))r.markCursor=r.state.storedMarks||t.marks(),dn(r,!0),r.markCursor=null;else if(dn(r),ie&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let n=r.domSelectionRange();for(let i=n.focusNode,s=n.focusOffset;i&&i.nodeType==1&&s!=0;){let o=s<0?i.lastChild:i.childNodes[s-1];if(!o)break;if(o.nodeType==3){r.domSelection().collapse(o,o.nodeValue.length);break}else i=o,s=-1}}r.input.composing=!0}Fs(r,Ga)};$.compositionend=(r,e)=>{r.composing&&(r.input.composing=!1,r.input.compositionEndedAt=e.timeStamp,r.input.compositionPendingChanges=r.domObserver.pendingRecords().length?r.input.compositionID:0,r.input.compositionPendingChanges&&Promise.resolve().then(()=>r.domObserver.flush()),r.input.compositionID++,Fs(r,20))};function Fs(r,e){clearTimeout(r.input.composingTimeout),e>-1&&(r.input.composingTimeout=setTimeout(()=>dn(r),e))}function Vs(r){for(r.composing&&(r.input.composing=!1,r.input.compositionEndedAt=Xa());r.input.compositionNodes.length>0;)r.input.compositionNodes.pop().markParentsDirty()}function Xa(){let r=document.createEvent("Event");return r.initEvent("event",!0,!0),r.timeStamp}function dn(r,e=!1){if(!(re&&r.domObserver.flushingSoon>=0)){if(r.domObserver.forceFlush(),Vs(r),e||r.docView&&r.docView.dirty){let t=xr(r);return t&&!t.eq(r.state.selection)?r.dispatch(r.state.tr.setSelection(t)):r.updateState(r.state),!0}return!1}}function Qa(r,e){if(!r.dom.parentNode)return;let t=r.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let n=getSelection(),i=document.createRange();i.selectNodeContents(e),r.dom.blur(),n.removeAllRanges(),n.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),r.focus()},50)}var Bt=U&&Be<15||mt&&ea<604;K.copy=$.cut=(r,e)=>{let t=e,n=r.state.selection,i=t.type=="cut";if(n.empty)return;let s=Bt?null:t.clipboardData,o=n.content(),{dom:l,text:a}=Ds(r,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",a)):Qa(r,l),i&&r.dispatch(r.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function Za(r){return r.openStart==0&&r.openEnd==0&&r.content.childCount==1?r.content.firstChild:null}function ef(r,e){if(!r.dom.parentNode)return;let t=r.input.shiftKey||r.state.selection.$from.parent.type.spec.code,n=r.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(n.contentEditable="true"),n.style.cssText="position: fixed; left: -10000px; top: 10px",n.focus();let i=r.input.shiftKey&&r.input.lastKeyCode!=45;setTimeout(()=>{r.focus(),n.parentNode&&n.parentNode.removeChild(n),t?Ft(r,n.value,null,i,e):Ft(r,n.textContent,n.innerHTML,i,e)},50)}function Ft(r,e,t,n,i){let s=Es(r,e,t,n,r.state.selection.$from);if(r.someProp("handlePaste",a=>a(r,i,s||b.empty)))return!0;if(!s)return!1;let o=Za(s),l=o?r.state.tr.replaceSelectionWith(o,n):r.state.tr.replaceSelection(s);return r.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Ls(r){let e=r.getData("text/plain")||r.getData("Text");if(e)return e;let t=r.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}$.paste=(r,e)=>{let t=e;if(r.composing&&!re)return;let n=Bt?null:t.clipboardData,i=r.input.shiftKey&&r.input.lastKeyCode!=45;n&&Ft(r,Ls(n),n.getData("text/html"),i,t)?t.preventDefault():ef(r,t)};var pn=class{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}},Js=Q?"altKey":"ctrlKey";K.dragstart=(r,e)=>{let t=e,n=r.input.mouseDown;if(n&&n.done(),!t.dataTransfer)return;let i=r.state.selection,s=i.empty?null:r.posAtCoords(bn(t)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof x?i.to-1:i.to))){if(n&&n.mightDrag)o=x.create(r.state.doc,n.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let c=r.docView.nearestDesc(t.target,!0);c&&c.node.type.spec.draggable&&c!=r.docView&&(o=x.create(r.state.doc,c.posBefore))}}let l=(o||r.state.selection).content(),{dom:a,text:f}=Ds(r,l);t.dataTransfer.clearData(),t.dataTransfer.setData(Bt?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",Bt||t.dataTransfer.setData("text/plain",f),r.dragging=new pn(l,!t[Js],o)};K.dragend=r=>{let e=r.dragging;window.setTimeout(()=>{r.dragging==e&&(r.dragging=null)},50)};$.dragover=$.dragenter=(r,e)=>e.preventDefault();$.drop=(r,e)=>{let t=e,n=r.dragging;if(r.dragging=null,!t.dataTransfer)return;let i=r.posAtCoords(bn(t));if(!i)return;let s=r.state.doc.resolve(i.pos),o=n&&n.slice;o?r.someProp("transformPasted",d=>{o=d(o,r)}):o=Es(r,Ls(t.dataTransfer),Bt?null:t.dataTransfer.getData("text/html"),!1,s);let l=!!(n&&!t[Js]);if(r.someProp("handleDrop",d=>d(r,t,o||b.empty,l))){t.preventDefault();return}if(!o)return;t.preventDefault();let a=o?rn(r.state.doc,s.pos,o):s.pos;a==null&&(a=s.pos);let f=r.state.tr;if(l){let{node:d}=n;d?d.replace(f):f.deleteSelection()}let c=f.mapping.map(a),h=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,u=f.doc;if(h?f.replaceRangeWith(c,c,o.content.firstChild):f.replaceRange(c,c,o),f.doc.eq(u))return;let p=f.doc.resolve(c);if(h&&x.isSelectable(o.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(o.content.firstChild))f.setSelection(new x(p));else{let d=f.mapping.map(a);f.mapping.maps[f.mapping.maps.length-1].forEach((m,y,k,I)=>d=I),f.setSelection(Sr(r,p,f.doc.resolve(d)))}r.focus(),r.dispatch(f.setMeta("uiEvent","drop"))};K.focus=r=>{r.input.lastFocus=Date.now(),r.focused||(r.domObserver.stop(),r.dom.classList.add("ProseMirror-focused"),r.domObserver.start(),r.focused=!0,setTimeout(()=>{r.docView&&r.hasFocus()&&!r.domObserver.currentSelection.eq(r.domSelectionRange())&&we(r)},20))};K.blur=(r,e)=>{let t=e;r.focused&&(r.domObserver.stop(),r.dom.classList.remove("ProseMirror-focused"),r.domObserver.start(),t.relatedTarget&&r.dom.contains(t.relatedTarget)&&r.domObserver.currentSelection.clear(),r.focused=!1)};K.beforeinput=(r,e)=>{if(V&&re&&e.inputType=="deleteContentBackward"){r.domObserver.flushSoon();let{domChangeCount:n}=r.input;setTimeout(()=>{if(r.input.domChangeCount!=n||(r.dom.blur(),r.focus(),r.someProp("handleKeyDown",s=>s(r,Ge(8,"Backspace")))))return;let{$cursor:i}=r.state.selection;i&&i.pos>0&&r.dispatch(r.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let r in $)K[r]=$[r];function Vt(r,e){if(r==e)return!0;for(let t in r)if(r[t]!==e[t])return!1;for(let t in e)if(!(t in r))return!1;return!0}var yt=class{constructor(e,t){this.toDOM=e,this.spec=t||Ze,this.side=this.spec.side||0}map(e,t,n,i){let{pos:s,deleted:o}=e.mapResult(t.from+i,this.side<0?-1:1);return o?null:new W(s-n,s-n,this)}valid(){return!0}eq(e){return this==e||e instanceof yt&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Vt(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},pe=class{constructor(e,t){this.attrs=e,this.spec=t||Ze}map(e,t,n,i){let s=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-n,o=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-n;return s>=o?null:new W(s,o,this)}valid(e,t){return t.from=e&&(!s||s(l.spec))&&n.push(l.copy(l.from+i,l.to+i))}for(let o=0;oe){let l=this.children[o]+1;this.children[o+2].findInner(e-l,t-l,n,i+l,s)}}map(e,t,n){return this==F||e.maps.length==0?this:this.mapInner(e,t,0,0,n||Ze)}mapInner(e,t,n,i,s){let o;for(let l=0;l{let f=a+n,c;if(!!(c=qs(t,l,f))){for(i||(i=this.children.slice());sl&&h.to=e){this.children[l]==e&&(n=this.children[l+2]);break}let s=e+1,o=s+t.content.size;for(let l=0;ls&&a.type instanceof pe){let f=Math.max(s,a.from)-s,c=Math.min(o,a.to)-s;fi.map(e,t,Ze));return ue.from(n)}forChild(e,t){if(t.isLeaf)return E.empty;let n=[];for(let i=0;it instanceof E)?e:e.reduce((t,n)=>t.concat(n instanceof E?n:n.members),[]))}}};function tf(r,e,t,n,i,s,o){let l=r.slice();for(let f=0,c=s;f{let y=m-d-(p-u);for(let k=0;kI+c-h)continue;let se=l[k]+c-h;p>=se?l[k+1]=u<=se?-2:-1:u>=c&&y&&(l[k]+=y,l[k+1]+=y)}h+=y}),c=t.maps[f].map(c,-1)}let a=!1;for(let f=0;f=n.content.size){a=!0;continue}let u=t.map(r[f+1]+s,-1),p=u-i,{index:d,offset:m}=n.content.findIndex(h),y=n.maybeChild(d);if(y&&m==h&&m+y.nodeSize==p){let k=l[f+2].mapInner(t,y,c+1,r[f]+s+1,o);k!=F?(l[f]=h,l[f+1]=p,l[f+2]=k):(l[f+1]=-2,a=!0)}else a=!0}if(a){let f=nf(l,r,e,t,i,s,o),c=mn(f,n,0,o);e=c.local;for(let h=0;ht&&o.to{let f=qs(r,l,a+t);if(f){s=!0;let c=mn(f,l,t+a+1,n);c!=F&&i.push(a,a+l.nodeSize,c)}});let o=Ws(s?Ks(r):r,-t).sort(et);for(let l=0;l0;)e++;r.splice(e,0,t)}function Zn(r){let e=[];return r.someProp("decorations",t=>{let n=t(r.state);n&&n!=F&&e.push(n)}),r.cursorWrapper&&e.push(E.create(r.state.doc,[r.cursorWrapper.deco])),ue.from(e)}var rf={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},sf=U&&Be<=11,gr=class{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}},yr=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new gr,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.observer=window.MutationObserver&&new window.MutationObserver(n=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),sf&&(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,rf)),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 t=0;tthis.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(!!Yi(this.view)){if(this.suppressingSelectionUpdates)return we(this.view);if(U&&Be<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&tt(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 t=new Set,n;for(let s=e.focusNode;s;s=zt(s))t.add(s);for(let s=e.anchorNode;s;s=zt(s))if(t.has(s)){n=s;break}let i=n&&this.view.docView.nearestDesc(n);if(i&&i.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 t=this.pendingRecords();t.length&&(this.queue=[]);let n=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(n)&&Yi(e)&&!this.ignoreSelectionChange(n),s=-1,o=-1,l=!1,a=[];if(e.editable)for(let c=0;c1){let c=a.filter(h=>h.nodeName=="BR");if(c.length==2){let h=c[0],u=c[1];h.parentNode&&h.parentNode.parentNode==u.parentNode?u.remove():h.remove()}}let f=null;s<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(s>-1&&(e.docView.markDirty(s,o),of(e)),this.handleDOMChange(s,o,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(n)||we(e),this.currentSelection.set(n))}registerMutation(e,t){if(t.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;ci;y--){let k=n.childNodes[y-1],I=k.pmViewDesc;if(k.nodeName=="BR"&&!I){s=y;break}if(!I||I.size)break}let h=r.state.doc,u=r.someProp("domParser")||ae.fromSchema(r.state.schema),p=h.resolve(o),d=null,m=u.parse(n,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:i,to:s,preserveWhitespace:p.parent.type.whitespace=="pre"?"full":!0,findPositions:f,ruleFromNode:ff,context:p});if(f&&f[0].pos!=null){let y=f[0].pos,k=f[1]&&f[1].pos;k==null&&(k=y),d={anchor:y+o,head:k+o}}return{doc:m,sel:d,from:o,to:l}}function ff(r){let e=r.pmViewDesc;if(e)return e.parseRule();if(r.nodeName=="BR"&&r.parentNode){if(q&&/^(ul|ol)$/i.test(r.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(r.parentNode.lastChild==r||q&&/^(tr|table)$/i.test(r.parentNode.nodeName))return{ignore:!0}}else if(r.nodeName=="IMG"&&r.getAttribute("mark-placeholder"))return{ignore:!0};return null}var cf=/^(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 hf(r,e,t,n,i){let s=r.input.compositionPendingChanges||(r.composing?r.input.compositionID:0);if(r.input.compositionPendingChanges=0,e<0){let M=r.input.lastSelectionTime>Date.now()-50?r.input.lastSelectionOrigin:null,Ee=xr(r,M);if(Ee&&!r.state.selection.eq(Ee)){if(V&&re&&r.input.lastKeyCode===13&&Date.now()-100Ao(r,Ge(13,"Enter"))))return;let Ht=r.state.tr.setSelection(Ee);M=="pointer"?Ht.setMeta("pointer",!0):M=="key"&&Ht.scrollIntoView(),s&&Ht.setMeta("composition",s),r.dispatch(Ht)}return}let o=r.state.doc.resolve(e),l=o.sharedDepth(t);e=o.before(l+1),t=r.state.doc.resolve(t).after(l+1);let a=r.state.selection,f=af(r,e,t),c=r.state.doc,h=c.slice(f.from,f.to),u,p;r.input.lastKeyCode===8&&Date.now()-100Date.now()-225||re)&&i.some(M=>M.nodeType==1&&!cf.test(M.nodeName))&&(!d||d.endA>=d.endB)&&r.someProp("handleKeyDown",M=>M(r,Ge(13,"Enter")))){r.input.lastIOSEnter=0;return}if(!d)if(n&&a instanceof O&&!a.empty&&a.$head.sameParent(a.$anchor)&&!r.composing&&!(f.sel&&f.sel.anchor!=f.sel.head))d={start:a.from,endA:a.to,endB:a.to};else{if(f.sel){let M=ls(r,r.state.doc,f.sel);if(M&&!M.eq(r.state.selection)){let Ee=r.state.tr.setSelection(M);s&&Ee.setMeta("composition",s),r.dispatch(Ee)}}return}if(V&&r.cursorWrapper&&f.sel&&f.sel.anchor==r.cursorWrapper.deco.from&&f.sel.head==f.sel.anchor){let M=d.endB-d.start;f.sel={anchor:f.sel.anchor+M,head:f.sel.anchor+M}}r.input.domChangeCount++,r.state.selection.fromr.state.selection.from&&d.start<=r.state.selection.from+2&&r.state.selection.from>=f.from?d.start=r.state.selection.from:d.endA=r.state.selection.to-2&&r.state.selection.to<=f.to&&(d.endB+=r.state.selection.to-d.endA,d.endA=r.state.selection.to)),U&&Be<=11&&d.endB==d.start+1&&d.endA==d.start&&d.start>f.from&&f.doc.textBetween(d.start-f.from-1,d.start-f.from+1)==" \xA0"&&(d.start--,d.endA--,d.endB--);let m=f.doc.resolveNoCache(d.start-f.from),y=f.doc.resolveNoCache(d.endB-f.from),k=c.resolve(d.start),I=m.sameParent(y)&&m.parent.inlineContent&&k.end()>=d.endA,se;if((mt&&r.input.lastIOSEnter>Date.now()-225&&(!I||i.some(M=>M.nodeName=="DIV"||M.nodeName=="P"))||!I&&m.posM(r,Ge(13,"Enter")))){r.input.lastIOSEnter=0;return}if(r.state.selection.anchor>d.start&&df(c,d.start,d.endA,m,y)&&r.someProp("handleKeyDown",M=>M(r,Ge(8,"Backspace")))){re&&V&&r.domObserver.suppressSelectionUpdates();return}V&&re&&d.endB==d.start&&(r.input.lastAndroidDelete=Date.now()),re&&!I&&m.start()!=y.start()&&y.parentOffset==0&&m.depth==y.depth&&f.sel&&f.sel.anchor==f.sel.head&&f.sel.head==d.endA&&(d.endB-=2,y=f.doc.resolveNoCache(d.endB-f.from),setTimeout(()=>{r.someProp("handleKeyDown",function(M){return M(r,Ge(13,"Enter"))})},20));let oe=d.start,te=d.endA,w,G,le;if(I){if(m.pos==y.pos)U&&Be<=11&&m.parentOffset==0&&(r.domObserver.suppressSelectionUpdates(),setTimeout(()=>we(r),20)),w=r.state.tr.delete(oe,te),G=c.resolve(d.start).marksAcross(c.resolve(d.endA));else if(d.endA==d.endB&&(le=uf(m.parent.content.cut(m.parentOffset,y.parentOffset),k.parent.content.cut(k.parentOffset,d.endA-k.start()))))w=r.state.tr,le.type=="add"?w.addMark(oe,te,le.mark):w.removeMark(oe,te,le.mark);else if(m.parent.child(m.index()).isText&&m.index()==y.index()-(y.textOffset?0:1)){let M=m.parent.textBetween(m.parentOffset,y.parentOffset);if(r.someProp("handleTextInput",Ee=>Ee(r,oe,te,M)))return;w=r.state.tr.insertText(M,oe,te)}}if(w||(w=r.state.tr.replace(oe,te,f.doc.slice(d.start-f.from,d.endB-f.from))),f.sel){let M=ls(r,w.doc,f.sel);M&&!(V&&re&&r.composing&&M.empty&&(d.start!=d.endB||r.input.lastAndroidDeletee.content.size?null:Sr(r,e.resolve(t.anchor),e.resolve(t.head))}function uf(r,e){let t=r.firstChild.marks,n=e.firstChild.marks,i=t,s=n,o,l,a;for(let c=0;cc.mark(l.addToSet(c.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",a=c=>c.mark(l.removeFromSet(c.marks));else return null;let f=[];for(let c=0;ct||er(o,!0,!1)0&&(e||r.indexAfter(n)==r.node(n).childCount);)n--,i++,e=!1;if(t){let s=r.node(n).maybeChild(r.indexAfter(n));for(;s&&!s.isLeaf;)s=s.firstChild,i++}return i}function pf(r,e,t,n,i){let s=r.findDiffStart(e,t);if(s==null)return null;let{a:o,b:l}=r.findDiffEnd(e,t+r.size,t+e.size);if(i=="end"){let a=Math.max(0,s-Math.min(o,l));n-=o+a-s}if(o=o?s-n:0;s-=a,s&&s=l?s-n:0;s-=a,s&&s=56320&&e<=57343&&t>=55296&&t<=56319}var gn=class{constructor(e,t){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 dr,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(ds),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=hs(this),cs(this),this.nodeViews=us(this),this.docView=Ki(this.state.doc,fs(this),Zn(this),this.dom,this),this.domObserver=new yr(this,(n,i,s,o)=>hf(this,n,i,s,o)),this.domObserver.start(),La(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 t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&pr(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(ds),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let n in this._props)t[n]=this._props[n];t.state=this.state;for(let n in e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var n;let i=this.state,s=!1,o=!1;e.storedMarks&&this.composing&&(Vs(this),o=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let p=us(this);gf(p,this.nodeViews)&&(this.nodeViews=p,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&pr(this),this.editable=hs(this),cs(this);let a=Zn(this),f=fs(this),c=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",h=s||!this.docView.matchesNode(e.doc,f,a);(h||!e.selection.eq(i.selection))&&(o=!0);let u=c=="preserve"&&o&&this.dom.style.overflowAnchor==null&&ra(this);if(o){this.domObserver.stop();let p=h&&(U||V)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&mf(i.selection,e.selection);if(h){let d=V?this.trackWrites=this.domSelectionRange().focusNode:null;(s||!this.docView.update(e.doc,f,a,this))&&(this.docView.updateOuterDeco([]),this.docView.destroy(),this.docView=Ki(e.doc,f,a,this.dom,this)),d&&!this.trackWrites&&(p=!0)}p||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&wa(this))?we(this,p):(ws(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),((n=this.dragging)===null||n===void 0?void 0:n.node)&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),c=="reset"?this.dom.scrollTop=0:c=="to selection"?this.scrollToSelection():u&&ia(u)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof x){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&Fi(this,t.getBoundingClientRect(),e)}else Fi(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 t=0;t0&&this.state.doc.nodeAt(s))==n.node&&(i=s)}this.dragging=new pn(e.slice,e.move,i<0?void 0:x.create(this.state.doc,i))}someProp(e,t){let n=this._props&&this._props[e],i;if(n!=null&&(i=t?t(n):n))return i;for(let o=0;ot.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return ca(this,e)}coordsAtPos(e,t=1){return ks(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,n=-1){let i=this.docView.posFromDOM(e,t,n);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return ma(this,t||this.state,e)}pasteHTML(e,t){return Ft(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return Ft(this,e,null,!0,t||new ClipboardEvent("paste"))}destroy(){!this.docView||(Ja(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Zn(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null)}get isDestroyed(){return this.docView==null}dispatchEvent(e){return qa(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){return q&&this.root.nodeType===11&&Gl(this.dom.ownerDocument)==this.dom?lf(this):this.domSelection()}domSelection(){return this.root.getSelection()}};function fs(r){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(r.editable),r.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(r.state)),t)for(let n in t)n=="class"?e.class+=" "+t[n]:n=="style"?e.style=(e.style?e.style+";":"")+t[n]:!e[n]&&n!="contenteditable"&&n!="nodeName"&&(e[n]=String(t[n]))}),e.translate||(e.translate="no"),[W.node(0,r.state.doc.content.size,e)]}function cs(r){if(r.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),r.cursorWrapper={dom:e,deco:W.widget(r.state.selection.head,e,{raw:!0,marks:r.markCursor})}}else r.cursorWrapper=null}function hs(r){return!r.someProp("editable",e=>e(r.state)===!1)}function mf(r,e){let t=Math.min(r.$anchor.sharedDepth(r.head),e.$anchor.sharedDepth(e.head));return r.$anchor.start(t)!=e.$anchor.start(t)}function us(r){let e=Object.create(null);function t(n){for(let i in n)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=n[i])}return r.someProp("nodeViews",t),r.someProp("markViews",t),e}function gf(r,e){let t=0,n=0;for(let i in r){if(r[i]!=e[i])return!0;t++}for(let i in e)n++;return t!=n}function ds(r){if(r.spec.state||r.spec.filterTransaction||r.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}var N=class extends S{constructor(e){super(e,e)}map(e,t){let n=e.resolve(t.map(this.head));return N.valid(n)?new N(n):S.near(n)}content(){return b.empty}eq(e){return e instanceof N&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new N(e.resolve(t.pos))}getBookmark(){return new Wt(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!yf(e)||!bf(e))return!1;let n=t.type.spec.allowGapCursor;if(n!=null)return n;let i=t.contentMatchAt(e.index()).defaultType;return i&&i.isTextblock}static findGapCursorFrom(e,t,n=!1){e:for(;;){if(!n&&N.valid(e))return e;let i=e.pos,s=null;for(let o=e.depth;;o--){let l=e.node(o);if(t>0?e.indexAfter(o)0){s=l.child(t>0?e.indexAfter(o):e.index(o)-1);break}else if(o==0)return null;i+=t;let a=e.doc.resolve(i);if(N.valid(a))return a}for(;;){let o=t>0?s.firstChild:s.lastChild;if(!o){if(s.isAtom&&!s.isText&&!x.isSelectable(s)){e=e.doc.resolve(i+s.nodeSize*t),n=!1;continue e}break}s=o,i+=t;let l=e.doc.resolve(i);if(N.valid(l))return l}return null}}};N.prototype.visible=!1;N.findFrom=N.findGapCursorFrom;S.jsonID("gapcursor",N);var Wt=class{constructor(e){this.pos=e}map(e){return new Wt(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return N.valid(t)?new N(t):S.near(t)}};function yf(r){for(let e=r.depth;e>=0;e--){let t=r.index(e),n=r.node(e);if(t==0){if(n.type.spec.isolating)return!0;continue}for(let i=n.child(t-1);;i=i.lastChild){if(i.childCount==0&&!i.inlineContent||i.isAtom||i.type.spec.isolating)return!0;if(i.inlineContent)return!1}}return!0}function bf(r){for(let e=r.depth;e>=0;e--){let t=r.indexAfter(e),n=r.node(e);if(t==n.childCount){if(n.type.spec.isolating)return!0;continue}for(let i=n.child(t);;i=i.firstChild){if(i.childCount==0&&!i.inlineContent||i.isAtom||i.type.spec.isolating)return!0;if(i.inlineContent)return!1}}return!0}function $s(){return new H({props:{decorations:Mf,createSelectionBetween(r,e,t){return e.pos==t.pos&&N.valid(t)?new N(t):null},handleClick:xf,handleKeyDown:kf,handleDOMEvents:{beforeinput:Sf}}})}var kf=Gn({ArrowLeft:kn("horiz",-1),ArrowRight:kn("horiz",1),ArrowUp:kn("vert",-1),ArrowDown:kn("vert",1)});function kn(r,e){let t=r=="vert"?e>0?"down":"up":e>0?"right":"left";return function(n,i,s){let o=n.selection,l=e>0?o.$to:o.$from,a=o.empty;if(o instanceof O){if(!s.endOfTextblock(t)||l.depth==0)return!1;a=!1,l=n.doc.resolve(e>0?l.after():l.before())}let f=N.findGapCursorFrom(l,e,a);return f?(i&&i(n.tr.setSelection(new N(f))),!0):!1}}function xf(r,e,t){if(!r||!r.editable)return!1;let n=r.state.doc.resolve(e);if(!N.valid(n))return!1;let i=r.posAtCoords({left:t.clientX,top:t.clientY});return i&&i.inside>-1&&x.isSelectable(r.state.doc.nodeAt(i.inside))?!1:(r.dispatch(r.state.tr.setSelection(new N(n))),!0)}function Sf(r,e){if(e.inputType!="insertCompositionText"||!(r.state.selection instanceof N))return!1;let{$from:t}=r.state.selection,n=t.parent.contentMatchAt(t.index()).findWrapping(r.state.schema.nodes.text);if(!n)return!1;let i=g.empty;for(let o=n.length-1;o>=0;o--)i=g.from(n[o].createAndFill(null,i));let s=r.state.tr.replace(t.pos,t.pos,new b(i,0,0));return s.setSelection(O.near(s.doc.resolve(t.pos+1))),r.dispatch(s),!1}function Mf(r){if(!(r.selection instanceof N))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",E.create(r.doc,[W.widget(r.selection.head,e,{key:"gapcursor"})])}var xn=200,z=function(){};z.prototype.append=function(e){return e.length?(e=z.from(e),!this.length&&e||e.length=t?z.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};z.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};z.prototype.forEach=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length),t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)};z.prototype.map=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length);var i=[];return this.forEach(function(s,o){return i.push(e(s,o))},t,n),i};z.from=function(e){return e instanceof z?e:e&&e.length?new js(e):z.empty};var js=function(r){function e(n){r.call(this),this.values=n}r&&(e.__proto__=r),e.prototype=Object.create(r&&r.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,s){return i==0&&s==this.length?this:new e(this.values.slice(i,s))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,s,o,l){for(var a=s;a=o;a--)if(i(this.values[a],l+a)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=xn)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=xn)return new e(i.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e}(z);z.empty=new js([]);var Cf=function(r){function e(t,n){r.call(this),this.left=t,this.right=n,this.length=t.length+n.length,this.depth=Math.max(t.depth,n.depth)+1}return r&&(e.__proto__=r),e.prototype=Object.create(r&&r.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(n){return nl&&this.right.forEachInner(n,Math.max(i-l,0),Math.min(this.length,s)-l,o+l)===!1)return!1},e.prototype.forEachInvertedInner=function(n,i,s,o){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(n,i-l,Math.max(s,l)-l,o+l)===!1||s=s?this.right.slice(n-s,i-s):this.left.slice(n,s).append(this.right.slice(0,i-s))},e.prototype.leafAppend=function(n){var i=this.right.leafAppend(n);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(n){var i=this.left.leafPrepend(n);if(i)return new e(i,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}(z),Nr=z;var Of=500,Y=class{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let n=this.items.length;for(;;n--)if(this.items.get(n-1).selection){--n;break}let i,s;t&&(i=this.remapping(n,this.items.length),s=i.maps.length);let o=e.tr,l,a,f=[],c=[];return this.items.forEach((h,u)=>{if(!h.step){i||(i=this.remapping(n,u+1),s=i.maps.length),s--,c.push(h);return}if(i){c.push(new ee(h.map));let p=h.step.map(i.slice(s)),d;p&&o.maybeStep(p).doc&&(d=o.mapping.maps[o.mapping.maps.length-1],f.push(new ee(d,void 0,void 0,f.length+c.length))),s--,d&&i.appendMap(d,s)}else o.maybeStep(h.step);if(h.selection)return l=i?h.selection.map(i.slice(s)):h.selection,a=new Y(this.items.slice(0,n).append(c.reverse().concat(f)),this.eventCount-1),!1},this.items.length,0),{remaining:a,transform:o,selection:l}}addTransform(e,t,n,i){let s=[],o=this.eventCount,l=this.items,a=!i&&l.length?l.get(l.length-1):null;for(let c=0;cNf&&(l=wf(l,f),o-=f),new Y(l.append(s),o)}remapping(e,t){let n=new ke;return this.items.forEach((i,s)=>{let o=i.mirrorOffset!=null&&s-i.mirrorOffset>=e?n.maps.length-i.mirrorOffset:void 0;n.appendMap(i.map,o)},e,t),n}addMaps(e){return this.eventCount==0?this:new Y(this.items.append(e.map(t=>new ee(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let n=[],i=Math.max(0,this.items.length-t),s=e.mapping,o=e.steps.length,l=this.eventCount;this.items.forEach(u=>{u.selection&&l--},i);let a=t;this.items.forEach(u=>{let p=s.getMirror(--a);if(p==null)return;o=Math.min(o,p);let d=s.maps[p];if(u.step){let m=e.steps[p].invert(e.docs[p]),y=u.selection&&u.selection.map(s.slice(a+1,p));y&&l++,n.push(new ee(d,m,y))}else n.push(new ee(d))},i);let f=[];for(let u=t;uOf&&(h=h.compress(this.items.length-n.length)),h}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),n=t.maps.length,i=[],s=0;return this.items.forEach((o,l)=>{if(l>=e)i.push(o),o.selection&&s++;else if(o.step){let a=o.step.map(t.slice(n)),f=a&&a.getMap();if(n--,f&&t.appendMap(f,n),a){let c=o.selection&&o.selection.map(t.slice(n));c&&s++;let h=new ee(f.invert(),a,c),u,p=i.length-1;(u=i.length&&i[p].merge(h))?i[p]=u:i.push(h)}}else o.map&&n--},this.items.length,0),new Y(Nr.from(i.reverse()),s)}};Y.empty=new Y(Nr.empty,0);function wf(r,e){let t;return r.forEach((n,i)=>{if(n.selection&&e--==0)return t=i,!1}),r.slice(t)}var ee=class{constructor(e,t,n,i){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new ee(t.getMap().invert(),t,this.selection)}}},ye=class{constructor(e,t,n,i,s){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=i,this.prevComposition=s}},Nf=20;function Tf(r,e,t,n){let i=t.getMeta(Ve),s;if(i)return i.historyState;t.getMeta(Ef)&&(r=new ye(r.done,r.undone,null,0,-1));let o=t.getMeta("appendedTransaction");if(t.steps.length==0)return r;if(o&&o.getMeta(Ve))return o.getMeta(Ve).redo?new ye(r.done.addTransform(t,void 0,n,Sn(e)),r.undone,Hs(t.mapping.maps[t.steps.length-1]),r.prevTime,r.prevComposition):new ye(r.done,r.undone.addTransform(t,void 0,n,Sn(e)),null,r.prevTime,r.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(o&&o.getMeta("addToHistory")===!1)){let l=t.getMeta("composition"),a=r.prevTime==0||!o&&r.prevComposition!=l&&(r.prevTime<(t.time||0)-n.newGroupDelay||!Df(t,r.prevRanges)),f=o?Tr(r.prevRanges,t.mapping):Hs(t.mapping.maps[t.steps.length-1]);return new ye(r.done.addTransform(t,a?e.selection.getBookmark():void 0,n,Sn(e)),Y.empty,f,t.time,l==null?r.prevComposition:l)}else return(s=t.getMeta("rebased"))?new ye(r.done.rebased(t,s),r.undone.rebased(t,s),Tr(r.prevRanges,t.mapping),r.prevTime,r.prevComposition):new ye(r.done.addMaps(t.mapping.maps),r.undone.addMaps(t.mapping.maps),Tr(r.prevRanges,t.mapping),r.prevTime,r.prevComposition)}function Df(r,e){if(!e)return!1;if(!r.docChanged)return!0;let t=!1;return r.mapping.maps[0].forEach((n,i)=>{for(let s=0;s=e[s]&&(t=!0)}),t}function Hs(r){let e=[];return r.forEach((t,n,i,s)=>e.push(i,s)),e}function Tr(r,e){if(!r)return null;let t=[];for(let n=0;n{let t=Ve.getState(r);return!t||t.done.eventCount==0?!1:(e&&_s(t,r,e,!1),!0)},bt=(r,e)=>{let t=Ve.getState(r);return!t||t.undone.eventCount==0?!1:(e&&_s(t,r,e,!0),!0)};var If=["p",0],Af=["blockquote",0],Rf=["hr"],vf=["pre",["code",0]],Pf=["br"],Te={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return If}},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM(){return Af}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return Rf}},heading:{attrs:{level:{default:1}},content:"inline*",group:"block",defining:!0,parseDOM:[{tag:"h1",attrs:{level:1}},{tag:"h2",attrs:{level:2}},{tag:"h3",attrs:{level:3}},{tag:"h4",attrs:{level:4}},{tag:"h5",attrs:{level:5}},{tag:"h6",attrs:{level:6}}],toDOM(r){return["h"+r.attrs.level,0]}},code_block:{content:"text*",marks:"",group:"block",code:!0,defining:!0,parseDOM:[{tag:"pre",preserveWhitespace:"full"}],toDOM(){return vf}},text:{group:"inline"},image:{inline:!0,attrs:{src:{},alt:{default:null},title:{default:null}},group:"inline",draggable:!0,parseDOM:[{tag:"img[src]",getAttrs(r){return{src:r.getAttribute("src"),title:r.getAttribute("title"),alt:r.getAttribute("alt")}}}],toDOM(r){let{src:e,alt:t,title:n}=r.attrs;return["img",{src:e,alt:t,title:n}]}},hard_break:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM(){return Pf}}},zf=["em",0],Bf=["strong",0],Ff=["code",0],Kt={link:{attrs:{href:{},title:{default:null}},inclusive:!1,parseDOM:[{tag:"a[href]",getAttrs(r){return{href:r.getAttribute("href"),title:r.getAttribute("title")}}}],toDOM(r){let{href:e,title:t}=r.attrs;return["a",{href:e,title:t},0]}},em:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"},{style:"font-style=normal",clearMark:r=>r.type.name=="em"}],toDOM(){return zf}},strong:{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:r=>r.style.fontWeight!="normal"&&null},{style:"font-weight=400",clearMark:r=>r.type.name=="strong"},{style:"font-weight",getAttrs:r=>/^(bold(er)?|[5-9]\d{2,})$/.test(r)&&null}],toDOM(){return Bf}},code:{parseDOM:[{tag:"code"}],toDOM(){return Ff}}},Mh=new Ue({nodes:Te,marks:Kt});var Vf=["ol",0],Lf=["ul",0],Jf=["li",0],Wf={attrs:{order:{default:1}},parseDOM:[{tag:"ol",getAttrs(r){return{order:r.hasAttribute("start")?+r.getAttribute("start"):1}}}],toDOM(r){return r.attrs.order==1?Vf:["ol",{start:r.attrs.order},0]}},qf={parseDOM:[{tag:"ul"}],toDOM(){return Lf}},Kf={parseDOM:[{tag:"li"}],toDOM(){return Jf},defining:!0};function Er(r,e){let t={};for(let n in r)t[n]=r[n];for(let n in e)t[n]=e[n];return t}function Gs(r,e,t){return r.append({ordered_list:Er(Wf,{content:"list_item+",group:t}),bullet_list:Er(qf,{content:"list_item+",group:t}),list_item:Er(Kf,{content:e})})}function kt(r,e=null){return function(t,n){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=!1,a=o;if(!o)return!1;if(o.depth>=2&&i.node(o.depth-1).type.compatibleContent(r)&&o.startIndex==0){if(i.index(o.depth-1)==0)return!1;let c=t.doc.resolve(o.start-2);a=new je(c,c,o.depth),o.endIndex=0;c--)s=g.from(t[c].type.create(t[c].attrs,s));r.step(new D(e.start-(n?2:0),e.end,e.start,e.end,new b(s,0,0),t.length,!0));let o=0;for(let c=0;c=i.depth-3;k--)h=g.from(i.node(k).copy(h));let p=i.indexAfter(-1){if(y>-1)return!1;k.isTextblock&&k.content.size==0&&(y=I+1)}),y>-1&&m.setSelection(S.near(m.doc.resolve(y))),n(m.scrollIntoView())}return!0}let a=s.pos==i.end()?l.contentMatchAt(0).defaultType:null,f=t.tr.delete(i.pos,s.pos),c=a?[e?{type:r,attrs:e}:null,{type:a}]:void 0;return Re(f.doc,i.pos,2,c)?(n&&n(f.split(i.pos,2,c).scrollIntoView()),!0):!1}}function Qs(r){return function(e,t){let{$from:n,$to:i}=e.selection,s=n.blockRange(i,o=>o.childCount>0&&o.firstChild.type==r);return s?t?n.node(s.depth-1).type==r?jf(e,t,r,s):Hf(e,t,s):!0:!1}}function jf(r,e,t,n){let i=r.tr,s=n.end,o=n.$to.end(n.depth);sm;d--)p-=i.child(d).nodeSize,n.delete(p-1,p+1);let s=n.doc.resolve(t.start),o=s.nodeAfter;if(n.mapping.map(t.end)!=t.start+s.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,a=t.endIndex==i.childCount,f=s.node(-1),c=s.index(-1);if(!f.canReplace(c+(l?0:1),c+1,o.content.append(a?g.empty:g.from(i))))return!1;let h=s.pos,u=h+o.nodeSize;return n.step(new D(h-(l?1:0),u+(a?1:0),h+1,u-1,new b((l?g.empty:g.from(i.copy(g.empty))).append(a?g.empty:g.from(i.copy(g.empty))),l?0:1,a?0:1),l?0:1)),e(n.scrollIntoView()),!0}function Zs(r){return function(e,t){let{$from:n,$to:i}=e.selection,s=n.blockRange(i,f=>f.childCount>0&&f.firstChild.type==r);if(!s)return!1;let o=s.startIndex;if(o==0)return!1;let l=s.parent,a=l.child(o-1);if(a.type!=r)return!1;if(t){let f=a.lastChild&&a.lastChild.type==l.type,c=g.from(f?r.create():null),h=new b(g.from(r.create(null,g.from(l.type.create(null,c)))),f?3:1,0),u=s.start,p=s.end;t(e.tr.step(new D(u-(f?3:1),p,u,p,h,1,!0)).scrollIntoView())}return!0}}var Le=class{constructor(e,t,n={}){this.match=e,this.match=e,this.handler=typeof t=="string"?Uf(t):t,this.undoable=n.undoable!==!1,this.inCode=n.inCode||!1}};function Uf(r){return function(e,t,n,i){let s=r;if(t[1]){let o=t[0].lastIndexOf(t[1]);s+=t[0].slice(o+t[1].length),n+=o;let l=n-i;l>0&&(s=t[0].slice(o-l,o)+s,n=i)}return e.tr.insertText(s,n,i)}}var eo=(r,e)=>{let t=r.plugins;for(let n=0;n=0;a--)o.step(l.steps[a].invert(l.docs[a]));if(s.text){let a=o.doc.resolve(s.from).marks();o.replaceWith(s.from,s.to,r.schema.text(s.text,a))}else o.delete(s.from,s.to);e(o)}return!0}}return!1},Dh=new Le(/--$/,"\u2014"),Eh=new Le(/\.\.\.$/,"\u2026"),Ih=new Le(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C"),Ah=new Le(/"$/,"\u201D"),Rh=new Le(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018"),vh=new Le(/'$/,"\u2019");function _f(r,e){let t=Object.keys(e);return t.length?!!t.filter(n=>e[n]===r[n]).length:!0}function Ir(r,e,t={}){return r.find(n=>n.type===e&&_f(n.attrs,t))}function Yf(r,e,t={}){return!!Ir(r,e,t)}function Ar(r,e,t={}){if(!r||!e)return;let n=r.parent.childAfter(r.parentOffset);if(!n.node)return;let i=Ir(n.node.marks,e,t);if(!i)return;let s=r.index(),o=r.start()+n.offset,l=s+1,a=o+n.node.nodeSize;for(Ir(n.node.marks,e,t);s>0&&i.isInSet(r.parent.child(s-1).marks);)s-=1,o-=r.parent.child(s).nodeSize;for(;l=e||G<0||h&&le>=s}function k(){var w=Cn();if(y(w))return I(w);l=setTimeout(k,m(w))}function I(w){return l=void 0,u&&n?p(w):(n=i=void 0,o)}function se(){l!==void 0&&clearTimeout(l),f=0,n=a=i=l=void 0}function oe(){return l===void 0?o:I(Cn())}function te(){var w=Cn(),G=y(w);if(n=arguments,i=this,a=w,G){if(l===void 0)return d(a);if(h)return clearTimeout(l),l=setTimeout(k,e),p(a)}return l===void 0&&(l=setTimeout(k,e)),o}return te.cancel=se,te.flush=oe,te}var uo=Nc;var De=(r,e=null)=>{let t=document.createElement(r);if(e)for(let[n,i]of Object.entries(e))/^data-|^aria-|^role/.test(n)?t.setAttribute(n,i):t[n]=i;return t};function po(r,e){let t=document.createElement("article");return t.innerHTML=e,ae.fromSchema(r).parse(t)}var mo=(r,e,t)=>{let n=j.fromSchema(r),i=function(){let o=De("article");return o.appendChild(n.serializeFragment(e.state.doc.content)),o.innerHTML};return uo(()=>{let o=i();t.value!==o&&(t.value=o,t.dispatchEvent(new InputEvent("input",{bubbles:!0,cancelable:!0})))},250)};var go=r=>{let{$from:e,$to:t}=r,n=e.pos,i=t.pos,s=e.nodeAfter,o=t.nodeBefore,l=s&&s.isText?/^\s*/.exec(s.text)[0].length:0,a=o&&o.isText?/\s*$/.exec(o.text)[0].length:0;return n+lnew Promise(e=>{let t=document.createElement("div");t.innerHTML=` +`);return{dom:a,text:u}}function Is(r,e,t,n,i){let s=i.parent.type.spec.code,o,l;if(!t&&!e)return null;let a=e&&(n||s||!t);if(a){if(r.someProp("transformPastedText",u=>{e=u(e,s||n,r)}),s)return e?new b(g.from(r.state.schema.text(e.replace(/\r\n?/g,` +`))),0,0):b.empty;let h=r.someProp("clipboardTextParser",u=>u(e,i,n,r));if(h)l=h;else{let u=i.marks(),{schema:p}=r.state,d=V.fromSchema(p);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let y=o.appendChild(document.createElement("p"));m&&y.appendChild(d.serializeNode(p.text(m,u)))})}}else r.someProp("transformPastedHTML",h=>{t=h(t,r)}),o=Fa(t),Jt&&La(o);let f=o&&o.querySelector("[data-pm-slice]"),c=f&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(f.getAttribute("data-pm-slice")||"");if(c&&c[3])for(let h=+c[3];h>0;h--){let u=o.firstChild;for(;u&&u.nodeType!=1;)u=u.nextSibling;if(!u)break;o=u}if(l||(l=(r.someProp("clipboardParser")||r.someProp("domParser")||ae.fromSchema(r.state.schema)).parseSlice(o,{preserveWhitespace:!!(a||c),context:i,ruleFromNode(u){return u.nodeName=="BR"&&!u.nextSibling&&u.parentNode&&!za.test(u.parentNode.nodeName)?{ignore:!0}:null}})),c)l=Va(ns(l,+c[1],+c[2]),c[4]);else if(l=b.maxOpen(Ba(l.content,i),!0),l.openStart||l.openEnd){let h=0,u=0;for(let p=l.content.firstChild;h{l=h(l,r)}),l}var za=/^(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 Ba(r,e){if(r.childCount<2)return r;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),s,o=[];if(r.forEach(l=>{if(!o)return;let a=i.findWrapping(l.type),f;if(!a)return o=null;if(f=o.length&&s.length&&Rs(a,s,l,o[o.length-1],0))o[o.length-1]=f;else{o.length&&(o[o.length-1]=vs(o[o.length-1],s.length));let c=As(l,a);o.push(c),i=i.matchType(c.type),s=a}}),o)return g.from(o)}return r}function As(r,e,t=0){for(let n=e.length-1;n>=t;n--)r=e[n].create(null,g.from(r));return r}function Rs(r,e,t,n,i){if(i1&&(s=0),i=t&&(l=e<0?o.contentMatchAt(0).fillBefore(l,s<=i).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(g.empty,!0))),r.replaceChild(e<0?0:r.childCount-1,o.copy(l))}function ns(r,e,t){return e]*>)*/.exec(r);e&&(r=r.slice(e[0].length));let t=zs().createElement("div"),n=/<([a-z][^>\s]+)/i.exec(r),i;if((i=n&&Ps[n[1].toLowerCase()])&&(r=i.map(s=>"<"+s+">").join("")+r+i.map(s=>"").reverse().join("")),t.innerHTML=r,i)for(let s=0;s=0;l-=2){let a=t.nodes[n[l]];if(!a||a.hasRequiredAttrs())break;i=g.from(a.create(n[l+1],i)),s++,o++}return new b(i,s,o)}var $={},H={},Ja={touchstart:!0,touchmove:!0},pr=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:""},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastAndroidDelete=0,this.composing=!1,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 Wa(r){for(let e in $){let t=$[e];r.dom.addEventListener(e,r.input.eventHandlers[e]=n=>{Ka(r,n)&&!Cr(r,n)&&(r.editable||!(n.type in H))&&t(r,n)},Ja[e]?{passive:!0}:void 0)}K&&r.dom.addEventListener("input",()=>null),mr(r)}function Be(r,e){r.input.lastSelectionOrigin=e,r.input.lastSelectionTime=Date.now()}function qa(r){r.domObserver.stop();for(let e in r.input.eventHandlers)r.dom.removeEventListener(e,r.input.eventHandlers[e]);clearTimeout(r.input.composingTimeout),clearTimeout(r.input.lastIOSEnterFallbackTimeout)}function mr(r){r.someProp("handleDOMEvents",e=>{for(let t in e)r.input.eventHandlers[t]||r.dom.addEventListener(t,r.input.eventHandlers[t]=n=>Cr(r,n))})}function Cr(r,e){return r.someProp("handleDOMEvents",t=>{let n=t[e.type];return n?n(r,e)||e.defaultPrevented:!1})}function Ka(r,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=r.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function $a(r,e){!Cr(r,e)&&$[e.type]&&(r.editable||!(e.type in H))&&$[e.type](r,e)}H.keydown=(r,e)=>{let t=e;if(r.input.shiftKey=t.keyCode==16||t.shiftKey,!Fs(r,t)&&(r.input.lastKeyCode=t.keyCode,r.input.lastKeyCodeTime=Date.now(),!(re&&L&&t.keyCode==13)))if(t.keyCode!=229&&r.domObserver.forceFlush(),mt&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let n=Date.now();r.input.lastIOSEnter=n,r.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{r.input.lastIOSEnter==n&&(r.someProp("handleKeyDown",i=>i(r,Ge(13,"Enter"))),r.input.lastIOSEnter=0)},200)}else r.someProp("handleKeyDown",n=>n(r,t))||Pa(r,t)?t.preventDefault():Be(r,"key")};H.keyup=(r,e)=>{e.keyCode==16&&(r.input.shiftKey=!1)};H.keypress=(r,e)=>{let t=e;if(Fs(r,t)||!t.charCode||t.ctrlKey&&!t.altKey||Q&&t.metaKey)return;if(r.someProp("handleKeyPress",i=>i(r,t))){t.preventDefault();return}let n=r.state.selection;if(!(n instanceof O)||!n.$from.sameParent(n.$to)){let i=String.fromCharCode(t.charCode);!/[\r\n]/.test(i)&&!r.someProp("handleTextInput",s=>s(r,n.$from.pos,n.$to.pos,i))&&r.dispatch(r.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function bn(r){return{left:r.clientX,top:r.clientY}}function Ha(r,e){let t=e.x-r.clientX,n=e.y-r.clientY;return t*t+n*n<100}function Or(r,e,t,n,i){if(n==-1)return!1;let s=r.state.doc.resolve(n);for(let o=s.depth+1;o>0;o--)if(r.someProp(e,l=>o>s.depth?l(r,t,s.nodeAfter,s.before(o),i,!0):l(r,t,s.node(o),s.before(o),i,!1)))return!0;return!1}function pt(r,e,t){r.focused||r.focus();let n=r.state.tr.setSelection(e);t=="pointer"&&n.setMeta("pointer",!0),r.dispatch(n)}function ja(r,e){if(e==-1)return!1;let t=r.state.doc.resolve(e),n=t.nodeAfter;return n&&n.isAtom&&x.isSelectable(n)?(pt(r,new x(t),"pointer"),!0):!1}function Ua(r,e){if(e==-1)return!1;let t=r.state.selection,n,i;t instanceof x&&(n=t.node);let s=r.state.doc.resolve(e);for(let o=s.depth+1;o>0;o--){let l=o>s.depth?s.nodeAfter:s.node(o);if(x.isSelectable(l)){n&&t.$from.depth>0&&o>=t.$from.depth&&s.before(t.$from.depth+1)==t.$from.pos?i=s.before(t.$from.depth):i=s.before(o);break}}return i!=null?(pt(r,x.create(r.state.doc,i),"pointer"),!0):!1}function _a(r,e,t,n,i){return Or(r,"handleClickOn",e,t,n)||r.someProp("handleClick",s=>s(r,e,n))||(i?Ua(r,t):ja(r,t))}function Ya(r,e,t,n){return Or(r,"handleDoubleClickOn",e,t,n)||r.someProp("handleDoubleClick",i=>i(r,e,n))}function Ga(r,e,t,n){return Or(r,"handleTripleClickOn",e,t,n)||r.someProp("handleTripleClick",i=>i(r,e,n))||Xa(r,t,n)}function Xa(r,e,t){if(t.button!=0)return!1;let n=r.state.doc;if(e==-1)return n.inlineContent?(pt(r,O.create(n,0,n.content.size),"pointer"),!0):!1;let i=n.resolve(e);for(let s=i.depth+1;s>0;s--){let o=s>i.depth?i.nodeAfter:i.node(s),l=i.before(s);if(o.inlineContent)pt(r,O.create(n,l+1,l+1+o.content.size),"pointer");else if(x.isSelectable(o))pt(r,x.create(n,l),"pointer");else continue;return!0}}function wr(r){return dn(r)}var Bs=Q?"metaKey":"ctrlKey";$.mousedown=(r,e)=>{let t=e;r.input.shiftKey=t.shiftKey;let n=wr(r),i=Date.now(),s="singleClick";i-r.input.lastClick.time<500&&Ha(t,r.input.lastClick)&&!t[Bs]&&(r.input.lastClick.type=="singleClick"?s="doubleClick":r.input.lastClick.type=="doubleClick"&&(s="tripleClick")),r.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:s};let o=r.posAtCoords(bn(t));!o||(s=="singleClick"?(r.input.mouseDown&&r.input.mouseDown.done(),r.input.mouseDown=new gr(r,o,t,!!n)):(s=="doubleClick"?Ya:Ga)(r,o.pos,o.inside,t)?t.preventDefault():Be(r,"pointer"))};var gr=class{constructor(e,t,n,i){this.view=e,this.pos=t,this.event=n,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!n[Bs],this.allowDefault=n.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let c=e.state.doc.resolve(t.pos);s=c.parent,o=c.depth?c.before():0}let l=i?null:n.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a?a.dom:null;let{selection:f}=e.state;(n.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||f instanceof x&&f.from<=o&&f.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&ie&&!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)),Be(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(()=>Te(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(bn(e))),this.updateAllowDefault(e),this.allowDefault||!t?Be(this.view,"pointer"):_a(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||K&&this.mightDrag&&!this.mightDrag.node.isAtom||L&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(pt(this.view,S.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):Be(this.view,"pointer")}move(e){this.updateAllowDefault(e),Be(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)}};$.touchstart=r=>{r.input.lastTouch=Date.now(),wr(r),Be(r,"pointer")};$.touchmove=r=>{r.input.lastTouch=Date.now(),Be(r,"pointer")};$.contextmenu=r=>wr(r);function Fs(r,e){return r.composing?!0:K&&Math.abs(e.timeStamp-r.input.compositionEndedAt)<500?(r.input.compositionEndedAt=-2e8,!0):!1}var Qa=re?5e3:-1;H.compositionstart=H.compositionupdate=r=>{if(!r.composing){r.domObserver.flush();let{state:e}=r,t=e.selection.$from;if(e.selection.empty&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(n=>n.type.spec.inclusive===!1)))r.markCursor=r.state.storedMarks||t.marks(),dn(r,!0),r.markCursor=null;else if(dn(r),ie&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let n=r.domSelectionRange();for(let i=n.focusNode,s=n.focusOffset;i&&i.nodeType==1&&s!=0;){let o=s<0?i.lastChild:i.childNodes[s-1];if(!o)break;if(o.nodeType==3){r.domSelection().collapse(o,o.nodeValue.length);break}else i=o,s=-1}}r.input.composing=!0}Ls(r,Qa)};H.compositionend=(r,e)=>{r.composing&&(r.input.composing=!1,r.input.compositionEndedAt=e.timeStamp,r.input.compositionPendingChanges=r.domObserver.pendingRecords().length?r.input.compositionID:0,r.input.compositionPendingChanges&&Promise.resolve().then(()=>r.domObserver.flush()),r.input.compositionID++,Ls(r,20))};function Ls(r,e){clearTimeout(r.input.composingTimeout),e>-1&&(r.input.composingTimeout=setTimeout(()=>dn(r),e))}function Vs(r){for(r.composing&&(r.input.composing=!1,r.input.compositionEndedAt=Za());r.input.compositionNodes.length>0;)r.input.compositionNodes.pop().markParentsDirty()}function Za(){let r=document.createEvent("Event");return r.initEvent("event",!0,!0),r.timeStamp}function dn(r,e=!1){if(!(re&&r.domObserver.flushingSoon>=0)){if(r.domObserver.forceFlush(),Vs(r),e||r.docView&&r.docView.dirty){let t=Sr(r);return t&&!t.eq(r.state.selection)?r.dispatch(r.state.tr.setSelection(t)):r.updateState(r.state),!0}return!1}}function ef(r,e){if(!r.dom.parentNode)return;let t=r.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let n=getSelection(),i=document.createRange();i.selectNodeContents(e),r.dom.blur(),n.removeAllRanges(),n.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),r.focus()},50)}var Bt=U&&Fe<15||mt&&na<604;$.copy=H.cut=(r,e)=>{let t=e,n=r.state.selection,i=t.type=="cut";if(n.empty)return;let s=Bt?null:t.clipboardData,o=n.content(),{dom:l,text:a}=Es(r,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",a)):ef(r,l),i&&r.dispatch(r.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function tf(r){return r.openStart==0&&r.openEnd==0&&r.content.childCount==1?r.content.firstChild:null}function nf(r,e){if(!r.dom.parentNode)return;let t=r.input.shiftKey||r.state.selection.$from.parent.type.spec.code,n=r.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(n.contentEditable="true"),n.style.cssText="position: fixed; left: -10000px; top: 10px",n.focus();let i=r.input.shiftKey&&r.input.lastKeyCode!=45;setTimeout(()=>{r.focus(),n.parentNode&&n.parentNode.removeChild(n),t?Ft(r,n.value,null,i,e):Ft(r,n.textContent,n.innerHTML,i,e)},50)}function Ft(r,e,t,n,i){let s=Is(r,e,t,n,r.state.selection.$from);if(r.someProp("handlePaste",a=>a(r,i,s||b.empty)))return!0;if(!s)return!1;let o=tf(s),l=o?r.state.tr.replaceSelectionWith(o,n):r.state.tr.replaceSelection(s);return r.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Js(r){let e=r.getData("text/plain")||r.getData("Text");if(e)return e;let t=r.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}H.paste=(r,e)=>{let t=e;if(r.composing&&!re)return;let n=Bt?null:t.clipboardData,i=r.input.shiftKey&&r.input.lastKeyCode!=45;n&&Ft(r,Js(n),n.getData("text/html"),i,t)?t.preventDefault():nf(r,t)};var pn=class{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}},Ws=Q?"altKey":"ctrlKey";$.dragstart=(r,e)=>{let t=e,n=r.input.mouseDown;if(n&&n.done(),!t.dataTransfer)return;let i=r.state.selection,s=i.empty?null:r.posAtCoords(bn(t)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof x?i.to-1:i.to))){if(n&&n.mightDrag)o=x.create(r.state.doc,n.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let c=r.docView.nearestDesc(t.target,!0);c&&c.node.type.spec.draggable&&c!=r.docView&&(o=x.create(r.state.doc,c.posBefore))}}let l=(o||r.state.selection).content(),{dom:a,text:f}=Es(r,l);t.dataTransfer.clearData(),t.dataTransfer.setData(Bt?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",Bt||t.dataTransfer.setData("text/plain",f),r.dragging=new pn(l,!t[Ws],o)};$.dragend=r=>{let e=r.dragging;window.setTimeout(()=>{r.dragging==e&&(r.dragging=null)},50)};H.dragover=H.dragenter=(r,e)=>e.preventDefault();H.drop=(r,e)=>{let t=e,n=r.dragging;if(r.dragging=null,!t.dataTransfer)return;let i=r.posAtCoords(bn(t));if(!i)return;let s=r.state.doc.resolve(i.pos),o=n&&n.slice;o?r.someProp("transformPasted",d=>{o=d(o,r)}):o=Is(r,Js(t.dataTransfer),Bt?null:t.dataTransfer.getData("text/html"),!1,s);let l=!!(n&&!t[Ws]);if(r.someProp("handleDrop",d=>d(r,t,o||b.empty,l))){t.preventDefault();return}if(!o)return;t.preventDefault();let a=o?rn(r.state.doc,s.pos,o):s.pos;a==null&&(a=s.pos);let f=r.state.tr;if(l){let{node:d}=n;d?d.replace(f):f.deleteSelection()}let c=f.mapping.map(a),h=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,u=f.doc;if(h?f.replaceRangeWith(c,c,o.content.firstChild):f.replaceRange(c,c,o),f.doc.eq(u))return;let p=f.doc.resolve(c);if(h&&x.isSelectable(o.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(o.content.firstChild))f.setSelection(new x(p));else{let d=f.mapping.map(a);f.mapping.maps[f.mapping.maps.length-1].forEach((m,y,k,I)=>d=I),f.setSelection(Mr(r,p,f.doc.resolve(d)))}r.focus(),r.dispatch(f.setMeta("uiEvent","drop"))};$.focus=r=>{r.input.lastFocus=Date.now(),r.focused||(r.domObserver.stop(),r.dom.classList.add("ProseMirror-focused"),r.domObserver.start(),r.focused=!0,setTimeout(()=>{r.docView&&r.hasFocus()&&!r.domObserver.currentSelection.eq(r.domSelectionRange())&&Te(r)},20))};$.blur=(r,e)=>{let t=e;r.focused&&(r.domObserver.stop(),r.dom.classList.remove("ProseMirror-focused"),r.domObserver.start(),t.relatedTarget&&r.dom.contains(t.relatedTarget)&&r.domObserver.currentSelection.clear(),r.focused=!1)};$.beforeinput=(r,e)=>{if(L&&re&&e.inputType=="deleteContentBackward"){r.domObserver.flushSoon();let{domChangeCount:n}=r.input;setTimeout(()=>{if(r.input.domChangeCount!=n||(r.dom.blur(),r.focus(),r.someProp("handleKeyDown",s=>s(r,Ge(8,"Backspace")))))return;let{$cursor:i}=r.state.selection;i&&i.pos>0&&r.dispatch(r.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let r in H)$[r]=H[r];function Lt(r,e){if(r==e)return!0;for(let t in r)if(r[t]!==e[t])return!1;for(let t in e)if(!(t in r))return!1;return!0}var yt=class{constructor(e,t){this.toDOM=e,this.spec=t||Ze,this.side=this.spec.side||0}map(e,t,n,i){let{pos:s,deleted:o}=e.mapResult(t.from+i,this.side<0?-1:1);return o?null:new q(s-n,s-n,this)}valid(){return!0}eq(e){return this==e||e instanceof yt&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Lt(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},pe=class{constructor(e,t){this.attrs=e,this.spec=t||Ze}map(e,t,n,i){let s=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-n,o=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-n;return s>=o?null:new q(s,o,this)}valid(e,t){return t.from=e&&(!s||s(l.spec))&&n.push(l.copy(l.from+i,l.to+i))}for(let o=0;oe){let l=this.children[o]+1;this.children[o+2].findInner(e-l,t-l,n,i+l,s)}}map(e,t,n){return this==F||e.maps.length==0?this:this.mapInner(e,t,0,0,n||Ze)}mapInner(e,t,n,i,s){let o;for(let l=0;l{let f=a+n,c;if(!!(c=Ks(t,l,f))){for(i||(i=this.children.slice());sl&&h.to=e){this.children[l]==e&&(n=this.children[l+2]);break}let s=e+1,o=s+t.content.size;for(let l=0;ls&&a.type instanceof pe){let f=Math.max(s,a.from)-s,c=Math.min(o,a.to)-s;fi.map(e,t,Ze));return ue.from(n)}forChild(e,t){if(t.isLeaf)return E.empty;let n=[];for(let i=0;it instanceof E)?e:e.reduce((t,n)=>t.concat(n instanceof E?n:n.members),[]))}}};function rf(r,e,t,n,i,s,o){let l=r.slice();for(let f=0,c=s;f{let y=m-d-(p-u);for(let k=0;kI+c-h)continue;let se=l[k]+c-h;p>=se?l[k+1]=u<=se?-2:-1:u>=c&&y&&(l[k]+=y,l[k+1]+=y)}h+=y}),c=t.maps[f].map(c,-1)}let a=!1;for(let f=0;f=n.content.size){a=!0;continue}let u=t.map(r[f+1]+s,-1),p=u-i,{index:d,offset:m}=n.content.findIndex(h),y=n.maybeChild(d);if(y&&m==h&&m+y.nodeSize==p){let k=l[f+2].mapInner(t,y,c+1,r[f]+s+1,o);k!=F?(l[f]=h,l[f+1]=p,l[f+2]=k):(l[f+1]=-2,a=!0)}else a=!0}if(a){let f=sf(l,r,e,t,i,s,o),c=mn(f,n,0,o);e=c.local;for(let h=0;ht&&o.to{let f=Ks(r,l,a+t);if(f){s=!0;let c=mn(f,l,t+a+1,n);c!=F&&i.push(a,a+l.nodeSize,c)}});let o=qs(s?$s(r):r,-t).sort(et);for(let l=0;l0;)e++;r.splice(e,0,t)}function er(r){let e=[];return r.someProp("decorations",t=>{let n=t(r.state);n&&n!=F&&e.push(n)}),r.cursorWrapper&&e.push(E.create(r.state.doc,[r.cursorWrapper.deco])),ue.from(e)}var of={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},lf=U&&Fe<=11,yr=class{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}},br=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new yr,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.observer=window.MutationObserver&&new window.MutationObserver(n=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),lf&&(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,of)),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 t=0;tthis.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(!!Gi(this.view)){if(this.suppressingSelectionUpdates)return Te(this.view);if(U&&Fe<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&tt(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 t=new Set,n;for(let s=e.focusNode;s;s=zt(s))t.add(s);for(let s=e.anchorNode;s;s=zt(s))if(t.has(s)){n=s;break}let i=n&&this.view.docView.nearestDesc(n);if(i&&i.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 t=this.pendingRecords();t.length&&(this.queue=[]);let n=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(n)&&Gi(e)&&!this.ignoreSelectionChange(n),s=-1,o=-1,l=!1,a=[];if(e.editable)for(let c=0;c1){let c=a.filter(h=>h.nodeName=="BR");if(c.length==2){let h=c[0],u=c[1];h.parentNode&&h.parentNode.parentNode==u.parentNode?u.remove():h.remove()}}let f=null;s<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(s>-1&&(e.docView.markDirty(s,o),af(e)),this.handleDOMChange(s,o,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(n)||Te(e),this.currentSelection.set(n))}registerMutation(e,t){if(t.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;ci;y--){let k=n.childNodes[y-1],I=k.pmViewDesc;if(k.nodeName=="BR"&&!I){s=y;break}if(!I||I.size)break}let h=r.state.doc,u=r.someProp("domParser")||ae.fromSchema(r.state.schema),p=h.resolve(o),d=null,m=u.parse(n,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:i,to:s,preserveWhitespace:p.parent.type.whitespace=="pre"?"full":!0,findPositions:f,ruleFromNode:hf,context:p});if(f&&f[0].pos!=null){let y=f[0].pos,k=f[1]&&f[1].pos;k==null&&(k=y),d={anchor:y+o,head:k+o}}return{doc:m,sel:d,from:o,to:l}}function hf(r){let e=r.pmViewDesc;if(e)return e.parseRule();if(r.nodeName=="BR"&&r.parentNode){if(K&&/^(ul|ol)$/i.test(r.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(r.parentNode.lastChild==r||K&&/^(tr|table)$/i.test(r.parentNode.nodeName))return{ignore:!0}}else if(r.nodeName=="IMG"&&r.getAttribute("mark-placeholder"))return{ignore:!0};return null}var uf=/^(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 df(r,e,t,n,i){let s=r.input.compositionPendingChanges||(r.composing?r.input.compositionID:0);if(r.input.compositionPendingChanges=0,e<0){let M=r.input.lastSelectionTime>Date.now()-50?r.input.lastSelectionOrigin:null,Ie=Sr(r,M);if(Ie&&!r.state.selection.eq(Ie)){if(L&&re&&r.input.lastKeyCode===13&&Date.now()-100vo(r,Ge(13,"Enter"))))return;let jt=r.state.tr.setSelection(Ie);M=="pointer"?jt.setMeta("pointer",!0):M=="key"&&jt.scrollIntoView(),s&&jt.setMeta("composition",s),r.dispatch(jt)}return}let o=r.state.doc.resolve(e),l=o.sharedDepth(t);e=o.before(l+1),t=r.state.doc.resolve(t).after(l+1);let a=r.state.selection,f=cf(r,e,t),c=r.state.doc,h=c.slice(f.from,f.to),u,p;r.input.lastKeyCode===8&&Date.now()-100Date.now()-225||re)&&i.some(M=>M.nodeType==1&&!uf.test(M.nodeName))&&(!d||d.endA>=d.endB)&&r.someProp("handleKeyDown",M=>M(r,Ge(13,"Enter")))){r.input.lastIOSEnter=0;return}if(!d)if(n&&a instanceof O&&!a.empty&&a.$head.sameParent(a.$anchor)&&!r.composing&&!(f.sel&&f.sel.anchor!=f.sel.head))d={start:a.from,endA:a.to,endB:a.to};else{if(f.sel){let M=as(r,r.state.doc,f.sel);if(M&&!M.eq(r.state.selection)){let Ie=r.state.tr.setSelection(M);s&&Ie.setMeta("composition",s),r.dispatch(Ie)}}return}if(L&&r.cursorWrapper&&f.sel&&f.sel.anchor==r.cursorWrapper.deco.from&&f.sel.head==f.sel.anchor){let M=d.endB-d.start;f.sel={anchor:f.sel.anchor+M,head:f.sel.anchor+M}}r.input.domChangeCount++,r.state.selection.fromr.state.selection.from&&d.start<=r.state.selection.from+2&&r.state.selection.from>=f.from?d.start=r.state.selection.from:d.endA=r.state.selection.to-2&&r.state.selection.to<=f.to&&(d.endB+=r.state.selection.to-d.endA,d.endA=r.state.selection.to)),U&&Fe<=11&&d.endB==d.start+1&&d.endA==d.start&&d.start>f.from&&f.doc.textBetween(d.start-f.from-1,d.start-f.from+1)==" \xA0"&&(d.start--,d.endA--,d.endB--);let m=f.doc.resolveNoCache(d.start-f.from),y=f.doc.resolveNoCache(d.endB-f.from),k=c.resolve(d.start),I=m.sameParent(y)&&m.parent.inlineContent&&k.end()>=d.endA,se;if((mt&&r.input.lastIOSEnter>Date.now()-225&&(!I||i.some(M=>M.nodeName=="DIV"||M.nodeName=="P"))||!I&&m.posM(r,Ge(13,"Enter")))){r.input.lastIOSEnter=0;return}if(r.state.selection.anchor>d.start&&mf(c,d.start,d.endA,m,y)&&r.someProp("handleKeyDown",M=>M(r,Ge(8,"Backspace")))){re&&L&&r.domObserver.suppressSelectionUpdates();return}L&&re&&d.endB==d.start&&(r.input.lastAndroidDelete=Date.now()),re&&!I&&m.start()!=y.start()&&y.parentOffset==0&&m.depth==y.depth&&f.sel&&f.sel.anchor==f.sel.head&&f.sel.head==d.endA&&(d.endB-=2,y=f.doc.resolveNoCache(d.endB-f.from),setTimeout(()=>{r.someProp("handleKeyDown",function(M){return M(r,Ge(13,"Enter"))})},20));let oe=d.start,te=d.endA,w,G,le;if(I){if(m.pos==y.pos)U&&Fe<=11&&m.parentOffset==0&&(r.domObserver.suppressSelectionUpdates(),setTimeout(()=>Te(r),20)),w=r.state.tr.delete(oe,te),G=c.resolve(d.start).marksAcross(c.resolve(d.endA));else if(d.endA==d.endB&&(le=pf(m.parent.content.cut(m.parentOffset,y.parentOffset),k.parent.content.cut(k.parentOffset,d.endA-k.start()))))w=r.state.tr,le.type=="add"?w.addMark(oe,te,le.mark):w.removeMark(oe,te,le.mark);else if(m.parent.child(m.index()).isText&&m.index()==y.index()-(y.textOffset?0:1)){let M=m.parent.textBetween(m.parentOffset,y.parentOffset);if(r.someProp("handleTextInput",Ie=>Ie(r,oe,te,M)))return;w=r.state.tr.insertText(M,oe,te)}}if(w||(w=r.state.tr.replace(oe,te,f.doc.slice(d.start-f.from,d.endB-f.from))),f.sel){let M=as(r,w.doc,f.sel);M&&!(L&&re&&r.composing&&M.empty&&(d.start!=d.endB||r.input.lastAndroidDeletee.content.size?null:Mr(r,e.resolve(t.anchor),e.resolve(t.head))}function pf(r,e){let t=r.firstChild.marks,n=e.firstChild.marks,i=t,s=n,o,l,a;for(let c=0;cc.mark(l.addToSet(c.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",a=c=>c.mark(l.removeFromSet(c.marks));else return null;let f=[];for(let c=0;ct||tr(o,!0,!1)0&&(e||r.indexAfter(n)==r.node(n).childCount);)n--,i++,e=!1;if(t){let s=r.node(n).maybeChild(r.indexAfter(n));for(;s&&!s.isLeaf;)s=s.firstChild,i++}return i}function gf(r,e,t,n,i){let s=r.findDiffStart(e,t);if(s==null)return null;let{a:o,b:l}=r.findDiffEnd(e,t+r.size,t+e.size);if(i=="end"){let a=Math.max(0,s-Math.min(o,l));n-=o+a-s}if(o=o?s-n:0;s-=a,s&&s=l?s-n:0;s-=a,s&&s=56320&&e<=57343&&t>=55296&&t<=56319}var gn=class{constructor(e,t){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 pr,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(ps),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=us(this),hs(this),this.nodeViews=ds(this),this.docView=$i(this.state.doc,cs(this),er(this),this.dom,this),this.domObserver=new br(this,(n,i,s,o)=>df(this,n,i,s,o)),this.domObserver.start(),Wa(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 t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&mr(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(ps),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let n in this._props)t[n]=this._props[n];t.state=this.state;for(let n in e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var n;let i=this.state,s=!1,o=!1;e.storedMarks&&this.composing&&(Vs(this),o=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let p=ds(this);bf(p,this.nodeViews)&&(this.nodeViews=p,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&mr(this),this.editable=us(this),hs(this);let a=er(this),f=cs(this),c=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",h=s||!this.docView.matchesNode(e.doc,f,a);(h||!e.selection.eq(i.selection))&&(o=!0);let u=c=="preserve"&&o&&this.dom.style.overflowAnchor==null&&sa(this);if(o){this.domObserver.stop();let p=h&&(U||L)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&yf(i.selection,e.selection);if(h){let d=L?this.trackWrites=this.domSelectionRange().focusNode:null;(s||!this.docView.update(e.doc,f,a,this))&&(this.docView.updateOuterDeco([]),this.docView.destroy(),this.docView=$i(e.doc,f,a,this.dom,this)),d&&!this.trackWrites&&(p=!0)}p||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Na(this))?Te(this,p):(Ts(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),((n=this.dragging)===null||n===void 0?void 0:n.node)&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),c=="reset"?this.dom.scrollTop=0:c=="to selection"?this.scrollToSelection():u&&oa(u)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof x){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&Li(this,t.getBoundingClientRect(),e)}else Li(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 t=0;t0&&this.state.doc.nodeAt(s))==n.node&&(i=s)}this.dragging=new pn(e.slice,e.move,i<0?void 0:x.create(this.state.doc,i))}someProp(e,t){let n=this._props&&this._props[e],i;if(n!=null&&(i=t?t(n):n))return i;for(let o=0;ot.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return ua(this,e)}coordsAtPos(e,t=1){return xs(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,n=-1){let i=this.docView.posFromDOM(e,t,n);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return ya(this,t||this.state,e)}pasteHTML(e,t){return Ft(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return Ft(this,e,null,!0,t||new ClipboardEvent("paste"))}destroy(){!this.docView||(qa(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],er(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null)}get isDestroyed(){return this.docView==null}dispatchEvent(e){return $a(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){return K&&this.root.nodeType===11&&Ql(this.dom.ownerDocument)==this.dom?ff(this):this.domSelection()}domSelection(){return this.root.getSelection()}};function cs(r){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(r.editable),r.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(r.state)),t)for(let n in t)n=="class"?e.class+=" "+t[n]:n=="style"?e.style=(e.style?e.style+";":"")+t[n]:!e[n]&&n!="contenteditable"&&n!="nodeName"&&(e[n]=String(t[n]))}),e.translate||(e.translate="no"),[q.node(0,r.state.doc.content.size,e)]}function hs(r){if(r.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),r.cursorWrapper={dom:e,deco:q.widget(r.state.selection.head,e,{raw:!0,marks:r.markCursor})}}else r.cursorWrapper=null}function us(r){return!r.someProp("editable",e=>e(r.state)===!1)}function yf(r,e){let t=Math.min(r.$anchor.sharedDepth(r.head),e.$anchor.sharedDepth(e.head));return r.$anchor.start(t)!=e.$anchor.start(t)}function ds(r){let e=Object.create(null);function t(n){for(let i in n)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=n[i])}return r.someProp("nodeViews",t),r.someProp("markViews",t),e}function bf(r,e){let t=0,n=0;for(let i in r){if(r[i]!=e[i])return!0;t++}for(let i in e)n++;return t!=n}function ps(r){if(r.spec.state||r.spec.filterTransaction||r.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}var T=class extends S{constructor(e){super(e,e)}map(e,t){let n=e.resolve(t.map(this.head));return T.valid(n)?new T(n):S.near(n)}content(){return b.empty}eq(e){return e instanceof T&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new T(e.resolve(t.pos))}getBookmark(){return new Wt(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!kf(e)||!xf(e))return!1;let n=t.type.spec.allowGapCursor;if(n!=null)return n;let i=t.contentMatchAt(e.index()).defaultType;return i&&i.isTextblock}static findGapCursorFrom(e,t,n=!1){e:for(;;){if(!n&&T.valid(e))return e;let i=e.pos,s=null;for(let o=e.depth;;o--){let l=e.node(o);if(t>0?e.indexAfter(o)0){s=l.child(t>0?e.indexAfter(o):e.index(o)-1);break}else if(o==0)return null;i+=t;let a=e.doc.resolve(i);if(T.valid(a))return a}for(;;){let o=t>0?s.firstChild:s.lastChild;if(!o){if(s.isAtom&&!s.isText&&!x.isSelectable(s)){e=e.doc.resolve(i+s.nodeSize*t),n=!1;continue e}break}s=o,i+=t;let l=e.doc.resolve(i);if(T.valid(l))return l}return null}}};T.prototype.visible=!1;T.findFrom=T.findGapCursorFrom;S.jsonID("gapcursor",T);var Wt=class{constructor(e){this.pos=e}map(e){return new Wt(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return T.valid(t)?new T(t):S.near(t)}};function kf(r){for(let e=r.depth;e>=0;e--){let t=r.index(e),n=r.node(e);if(t==0){if(n.type.spec.isolating)return!0;continue}for(let i=n.child(t-1);;i=i.lastChild){if(i.childCount==0&&!i.inlineContent||i.isAtom||i.type.spec.isolating)return!0;if(i.inlineContent)return!1}}return!0}function xf(r){for(let e=r.depth;e>=0;e--){let t=r.indexAfter(e),n=r.node(e);if(t==n.childCount){if(n.type.spec.isolating)return!0;continue}for(let i=n.child(t);;i=i.firstChild){if(i.childCount==0&&!i.inlineContent||i.isAtom||i.type.spec.isolating)return!0;if(i.inlineContent)return!1}}return!0}function Hs(){return new j({props:{decorations:Of,createSelectionBetween(r,e,t){return e.pos==t.pos&&T.valid(t)?new T(t):null},handleClick:Mf,handleKeyDown:Sf,handleDOMEvents:{beforeinput:Cf}}})}var Sf=Xn({ArrowLeft:kn("horiz",-1),ArrowRight:kn("horiz",1),ArrowUp:kn("vert",-1),ArrowDown:kn("vert",1)});function kn(r,e){let t=r=="vert"?e>0?"down":"up":e>0?"right":"left";return function(n,i,s){let o=n.selection,l=e>0?o.$to:o.$from,a=o.empty;if(o instanceof O){if(!s.endOfTextblock(t)||l.depth==0)return!1;a=!1,l=n.doc.resolve(e>0?l.after():l.before())}let f=T.findGapCursorFrom(l,e,a);return f?(i&&i(n.tr.setSelection(new T(f))),!0):!1}}function Mf(r,e,t){if(!r||!r.editable)return!1;let n=r.state.doc.resolve(e);if(!T.valid(n))return!1;let i=r.posAtCoords({left:t.clientX,top:t.clientY});return i&&i.inside>-1&&x.isSelectable(r.state.doc.nodeAt(i.inside))?!1:(r.dispatch(r.state.tr.setSelection(new T(n))),!0)}function Cf(r,e){if(e.inputType!="insertCompositionText"||!(r.state.selection instanceof T))return!1;let{$from:t}=r.state.selection,n=t.parent.contentMatchAt(t.index()).findWrapping(r.state.schema.nodes.text);if(!n)return!1;let i=g.empty;for(let o=n.length-1;o>=0;o--)i=g.from(n[o].createAndFill(null,i));let s=r.state.tr.replace(t.pos,t.pos,new b(i,0,0));return s.setSelection(O.near(s.doc.resolve(t.pos+1))),r.dispatch(s),!1}function Of(r){if(!(r.selection instanceof T))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",E.create(r.doc,[q.widget(r.selection.head,e,{key:"gapcursor"})])}var xn=200,z=function(){};z.prototype.append=function(e){return e.length?(e=z.from(e),!this.length&&e||e.length=t?z.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};z.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};z.prototype.forEach=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length),t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)};z.prototype.map=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length);var i=[];return this.forEach(function(s,o){return i.push(e(s,o))},t,n),i};z.from=function(e){return e instanceof z?e:e&&e.length?new js(e):z.empty};var js=function(r){function e(n){r.call(this),this.values=n}r&&(e.__proto__=r),e.prototype=Object.create(r&&r.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,s){return i==0&&s==this.length?this:new e(this.values.slice(i,s))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,s,o,l){for(var a=s;a=o;a--)if(i(this.values[a],l+a)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=xn)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=xn)return new e(i.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e}(z);z.empty=new js([]);var wf=function(r){function e(t,n){r.call(this),this.left=t,this.right=n,this.length=t.length+n.length,this.depth=Math.max(t.depth,n.depth)+1}return r&&(e.__proto__=r),e.prototype=Object.create(r&&r.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(n){return nl&&this.right.forEachInner(n,Math.max(i-l,0),Math.min(this.length,s)-l,o+l)===!1)return!1},e.prototype.forEachInvertedInner=function(n,i,s,o){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(n,i-l,Math.max(s,l)-l,o+l)===!1||s=s?this.right.slice(n-s,i-s):this.left.slice(n,s).append(this.right.slice(0,i-s))},e.prototype.leafAppend=function(n){var i=this.right.leafAppend(n);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(n){var i=this.left.leafPrepend(n);if(i)return new e(i,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}(z),Nr=z;var Tf=500,Y=class{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let n=this.items.length;for(;;n--)if(this.items.get(n-1).selection){--n;break}let i,s;t&&(i=this.remapping(n,this.items.length),s=i.maps.length);let o=e.tr,l,a,f=[],c=[];return this.items.forEach((h,u)=>{if(!h.step){i||(i=this.remapping(n,u+1),s=i.maps.length),s--,c.push(h);return}if(i){c.push(new ee(h.map));let p=h.step.map(i.slice(s)),d;p&&o.maybeStep(p).doc&&(d=o.mapping.maps[o.mapping.maps.length-1],f.push(new ee(d,void 0,void 0,f.length+c.length))),s--,d&&i.appendMap(d,s)}else o.maybeStep(h.step);if(h.selection)return l=i?h.selection.map(i.slice(s)):h.selection,a=new Y(this.items.slice(0,n).append(c.reverse().concat(f)),this.eventCount-1),!1},this.items.length,0),{remaining:a,transform:o,selection:l}}addTransform(e,t,n,i){let s=[],o=this.eventCount,l=this.items,a=!i&&l.length?l.get(l.length-1):null;for(let c=0;cDf&&(l=Nf(l,f),o-=f),new Y(l.append(s),o)}remapping(e,t){let n=new xe;return this.items.forEach((i,s)=>{let o=i.mirrorOffset!=null&&s-i.mirrorOffset>=e?n.maps.length-i.mirrorOffset:void 0;n.appendMap(i.map,o)},e,t),n}addMaps(e){return this.eventCount==0?this:new Y(this.items.append(e.map(t=>new ee(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let n=[],i=Math.max(0,this.items.length-t),s=e.mapping,o=e.steps.length,l=this.eventCount;this.items.forEach(u=>{u.selection&&l--},i);let a=t;this.items.forEach(u=>{let p=s.getMirror(--a);if(p==null)return;o=Math.min(o,p);let d=s.maps[p];if(u.step){let m=e.steps[p].invert(e.docs[p]),y=u.selection&&u.selection.map(s.slice(a+1,p));y&&l++,n.push(new ee(d,m,y))}else n.push(new ee(d))},i);let f=[];for(let u=t;uTf&&(h=h.compress(this.items.length-n.length)),h}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),n=t.maps.length,i=[],s=0;return this.items.forEach((o,l)=>{if(l>=e)i.push(o),o.selection&&s++;else if(o.step){let a=o.step.map(t.slice(n)),f=a&&a.getMap();if(n--,f&&t.appendMap(f,n),a){let c=o.selection&&o.selection.map(t.slice(n));c&&s++;let h=new ee(f.invert(),a,c),u,p=i.length-1;(u=i.length&&i[p].merge(h))?i[p]=u:i.push(h)}}else o.map&&n--},this.items.length,0),new Y(Nr.from(i.reverse()),s)}};Y.empty=new Y(Nr.empty,0);function Nf(r,e){let t;return r.forEach((n,i)=>{if(n.selection&&e--==0)return t=i,!1}),r.slice(t)}var ee=class{constructor(e,t,n,i){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new ee(t.getMap().invert(),t,this.selection)}}},ye=class{constructor(e,t,n,i,s){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=i,this.prevComposition=s}},Df=20;function Ef(r,e,t,n){let i=t.getMeta(Ve),s;if(i)return i.historyState;t.getMeta(Af)&&(r=new ye(r.done,r.undone,null,0,-1));let o=t.getMeta("appendedTransaction");if(t.steps.length==0)return r;if(o&&o.getMeta(Ve))return o.getMeta(Ve).redo?new ye(r.done.addTransform(t,void 0,n,Sn(e)),r.undone,Us(t.mapping.maps[t.steps.length-1]),r.prevTime,r.prevComposition):new ye(r.done,r.undone.addTransform(t,void 0,n,Sn(e)),null,r.prevTime,r.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(o&&o.getMeta("addToHistory")===!1)){let l=t.getMeta("composition"),a=r.prevTime==0||!o&&r.prevComposition!=l&&(r.prevTime<(t.time||0)-n.newGroupDelay||!If(t,r.prevRanges)),f=o?Dr(r.prevRanges,t.mapping):Us(t.mapping.maps[t.steps.length-1]);return new ye(r.done.addTransform(t,a?e.selection.getBookmark():void 0,n,Sn(e)),Y.empty,f,t.time,l==null?r.prevComposition:l)}else return(s=t.getMeta("rebased"))?new ye(r.done.rebased(t,s),r.undone.rebased(t,s),Dr(r.prevRanges,t.mapping),r.prevTime,r.prevComposition):new ye(r.done.addMaps(t.mapping.maps),r.undone.addMaps(t.mapping.maps),Dr(r.prevRanges,t.mapping),r.prevTime,r.prevComposition)}function If(r,e){if(!e)return!1;if(!r.docChanged)return!0;let t=!1;return r.mapping.maps[0].forEach((n,i)=>{for(let s=0;s=e[s]&&(t=!0)}),t}function Us(r){let e=[];return r.forEach((t,n,i,s)=>e.push(i,s)),e}function Dr(r,e){if(!r)return null;let t=[];for(let n=0;n{let t=Ve.getState(r);return!t||t.done.eventCount==0?!1:(e&&Ys(t,r,e,!1),!0)},bt=(r,e)=>{let t=Ve.getState(r);return!t||t.undone.eventCount==0?!1:(e&&Ys(t,r,e,!0),!0)};var Rf=["p",0],vf=["blockquote",0],Pf=["hr"],zf=["pre",["code",0]],Bf=["br"],De={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return Rf}},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM(){return vf}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return Pf}},heading:{attrs:{level:{default:1}},content:"inline*",group:"block",defining:!0,parseDOM:[{tag:"h1",attrs:{level:1}},{tag:"h2",attrs:{level:2}},{tag:"h3",attrs:{level:3}},{tag:"h4",attrs:{level:4}},{tag:"h5",attrs:{level:5}},{tag:"h6",attrs:{level:6}}],toDOM(r){return["h"+r.attrs.level,0]}},code_block:{content:"text*",marks:"",group:"block",code:!0,defining:!0,parseDOM:[{tag:"pre",preserveWhitespace:"full"}],toDOM(){return zf}},text:{group:"inline"},image:{inline:!0,attrs:{src:{},alt:{default:null},title:{default:null}},group:"inline",draggable:!0,parseDOM:[{tag:"img[src]",getAttrs(r){return{src:r.getAttribute("src"),title:r.getAttribute("title"),alt:r.getAttribute("alt")}}}],toDOM(r){let{src:e,alt:t,title:n}=r.attrs;return["img",{src:e,alt:t,title:n}]}},hard_break:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM(){return Bf}}},Ff=["em",0],Lf=["strong",0],Vf=["code",0],Kt={link:{attrs:{href:{},title:{default:null}},inclusive:!1,parseDOM:[{tag:"a[href]",getAttrs(r){return{href:r.getAttribute("href"),title:r.getAttribute("title")}}}],toDOM(r){let{href:e,title:t}=r.attrs;return["a",{href:e,title:t},0]}},em:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"},{style:"font-style=normal",clearMark:r=>r.type.name=="em"}],toDOM(){return Ff}},strong:{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:r=>r.style.fontWeight!="normal"&&null},{style:"font-weight=400",clearMark:r=>r.type.name=="strong"},{style:"font-weight",getAttrs:r=>/^(bold(er)?|[5-9]\d{2,})$/.test(r)&&null}],toDOM(){return Lf}},code:{parseDOM:[{tag:"code"}],toDOM(){return Vf}}},Th=new Ue({nodes:De,marks:Kt});var Jf=["ol",0],Wf=["ul",0],qf=["li",0],Kf={attrs:{order:{default:1}},parseDOM:[{tag:"ol",getAttrs(r){return{order:r.hasAttribute("start")?+r.getAttribute("start"):1}}}],toDOM(r){return r.attrs.order==1?Jf:["ol",{start:r.attrs.order},0]}},$f={parseDOM:[{tag:"ul"}],toDOM(){return Wf}},Hf={parseDOM:[{tag:"li"}],toDOM(){return qf},defining:!0};function Ir(r,e){let t={};for(let n in r)t[n]=r[n];for(let n in e)t[n]=e[n];return t}function Xs(r,e,t){return r.append({ordered_list:Ir(Kf,{content:"list_item+",group:t}),bullet_list:Ir($f,{content:"list_item+",group:t}),list_item:Ir(Hf,{content:e})})}function kt(r,e=null){return function(t,n){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=!1,a=o;if(!o)return!1;if(o.depth>=2&&i.node(o.depth-1).type.compatibleContent(r)&&o.startIndex==0){if(i.index(o.depth-1)==0)return!1;let c=t.doc.resolve(o.start-2);a=new He(c,c,o.depth),o.endIndex=0;c--)s=g.from(t[c].type.create(t[c].attrs,s));r.step(new D(e.start-(n?2:0),e.end,e.start,e.end,new b(s,0,0),t.length,!0));let o=0;for(let c=0;c=i.depth-3;k--)h=g.from(i.node(k).copy(h));let p=i.indexAfter(-1){if(y>-1)return!1;k.isTextblock&&k.content.size==0&&(y=I+1)}),y>-1&&m.setSelection(S.near(m.doc.resolve(y))),n(m.scrollIntoView())}return!0}let a=s.pos==i.end()?l.contentMatchAt(0).defaultType:null,f=t.tr.delete(i.pos,s.pos),c=a?[e?{type:r,attrs:e}:null,{type:a}]:void 0;return ve(f.doc,i.pos,2,c)?(n&&n(f.split(i.pos,2,c).scrollIntoView()),!0):!1}}function Zs(r){return function(e,t){let{$from:n,$to:i}=e.selection,s=n.blockRange(i,o=>o.childCount>0&&o.firstChild.type==r);return s?t?n.node(s.depth-1).type==r?Uf(e,t,r,s):_f(e,t,s):!0:!1}}function Uf(r,e,t,n){let i=r.tr,s=n.end,o=n.$to.end(n.depth);sm;d--)p-=i.child(d).nodeSize,n.delete(p-1,p+1);let s=n.doc.resolve(t.start),o=s.nodeAfter;if(n.mapping.map(t.end)!=t.start+s.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,a=t.endIndex==i.childCount,f=s.node(-1),c=s.index(-1);if(!f.canReplace(c+(l?0:1),c+1,o.content.append(a?g.empty:g.from(i))))return!1;let h=s.pos,u=h+o.nodeSize;return n.step(new D(h-(l?1:0),u+(a?1:0),h+1,u-1,new b((l?g.empty:g.from(i.copy(g.empty))).append(a?g.empty:g.from(i.copy(g.empty))),l?0:1,a?0:1),l?0:1)),e(n.scrollIntoView()),!0}function eo(r){return function(e,t){let{$from:n,$to:i}=e.selection,s=n.blockRange(i,f=>f.childCount>0&&f.firstChild.type==r);if(!s)return!1;let o=s.startIndex;if(o==0)return!1;let l=s.parent,a=l.child(o-1);if(a.type!=r)return!1;if(t){let f=a.lastChild&&a.lastChild.type==l.type,c=g.from(f?r.create():null),h=new b(g.from(r.create(null,g.from(l.type.create(null,c)))),f?3:1,0),u=s.start,p=s.end;t(e.tr.step(new D(u-(f?3:1),p,u,p,h,1,!0)).scrollIntoView())}return!0}}var Je=class{constructor(e,t,n={}){this.match=e,this.match=e,this.handler=typeof t=="string"?Yf(t):t,this.undoable=n.undoable!==!1,this.inCode=n.inCode||!1}};function Yf(r){return function(e,t,n,i){let s=r;if(t[1]){let o=t[0].lastIndexOf(t[1]);s+=t[0].slice(o+t[1].length),n+=o;let l=n-i;l>0&&(s=t[0].slice(o-l,o)+s,n=i)}return e.tr.insertText(s,n,i)}}var to=(r,e)=>{let t=r.plugins;for(let n=0;n=0;a--)o.step(l.steps[a].invert(l.docs[a]));if(s.text){let a=o.doc.resolve(s.from).marks();o.replaceWith(s.from,s.to,r.schema.text(s.text,a))}else o.delete(s.from,s.to);e(o)}return!0}}return!1},Rh=new Je(/--$/,"\u2014"),vh=new Je(/\.\.\.$/,"\u2026"),Ph=new Je(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C"),zh=new Je(/"$/,"\u201D"),Bh=new Je(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018"),Fh=new Je(/'$/,"\u2019");function Gf(r,e){let t=Object.keys(e);return t.length?!!t.filter(n=>e[n]===r[n]).length:!0}function Ar(r,e,t={}){return r.find(n=>n.type===e&&Gf(n.attrs,t))}function Xf(r,e,t={}){return!!Ar(r,e,t)}function Rr(r,e,t={}){if(!r||!e)return;let n=r.parent.childAfter(r.parentOffset);if(!n.node)return;let i=Ar(n.node.marks,e,t);if(!i)return;let s=r.index(),o=r.start()+n.offset,l=s+1,a=o+n.node.nodeSize;for(Ar(n.node.marks,e,t);s>0&&i.isInSet(r.parent.child(s-1).marks);)s-=1,o-=r.parent.child(s).nodeSize;for(;l=e||G<0||h&&le>=s}function k(){var w=Cn();if(y(w))return I(w);l=setTimeout(k,m(w))}function I(w){return l=void 0,u&&n?p(w):(n=i=void 0,o)}function se(){l!==void 0&&clearTimeout(l),f=0,n=a=i=l=void 0}function oe(){return l===void 0?o:I(Cn())}function te(){var w=Cn(),G=y(w);if(n=arguments,i=this,a=w,G){if(l===void 0)return d(a);if(h)return clearTimeout(l),l=setTimeout(k,e),p(a)}return l===void 0&&(l=setTimeout(k,e)),o}return te.cancel=se,te.flush=oe,te}var po=Dc;var be=(r,e=null)=>{let t=document.createElement(r);if(e)for(let[n,i]of Object.entries(e))/^data-|^aria-|^role/.test(n)?t.setAttribute(n,i):t[n]=i;return t};function On(r,e){let t=document.createElement("article");return t.innerHTML=e,ae.fromSchema(r).parse(t)}function mo(r){let{schema:e,doc:t}=r.state,n=V.fromSchema(e),i=be("article");return i.appendChild(n.serializeFragment(t.content)),i.innerHTML}var go=(r,e,t)=>{let n=V.fromSchema(r),i=function(){let o=be("article");return o.appendChild(n.serializeFragment(e.state.doc.content)),o.innerHTML};return po(()=>{let o=i();t.value!==o&&(t.value=o,t.dispatchEvent(new InputEvent("input",{bubbles:!0,cancelable:!0})))},250)};var yo=r=>{let{$from:e,$to:t}=r,n=e.pos,i=t.pos,s=e.nodeAfter,o=t.nodeBefore,l=s&&s.isText?/^\s*/.exec(s.text)[0].length:0,a=o&&o.isText?/\s*$/.exec(o.text)[0].length:0;return n+lnew Promise(e=>{let t=document.createElement("div");t.innerHTML=`

@@ -15,4 +15,13 @@ var DjangoProseEditor=(()=>{var Ut=Object.defineProperty;var Ro=Object.getOwnPro
- `,document.body.append(t);let n=t.querySelector("dialog"),i=t.querySelector("form");i.href.value=r.href||"",i.title.value=r.title||"",n.addEventListener("close",()=>{t.remove(),e(null)}),t.querySelector("button[type=submit]").addEventListener("click",s=>{s.preventDefault(),t.remove(),e(i.href.value?{href:i.href.value,title:i.title.value}:null)}),n.showModal()}),St=(r,e)=>{let{$from:t,empty:n}=r.selection,i=r.schema.marks.link;if(n&&!i.isInSet(t.marks()))return!1;if(e){let s=t.marks().find(o=>o.type===i);Tc((s==null?void 0:s.attrs)||{}).then(o=>{if(o){let l;if(n)l=Ar(t,i),e(r.tr.removeMark(l.from,l.to,i).addMark(l.from,l.to,i.create(o)));else{let{from:a,to:f}=go(r.selection);e(r.tr.addMark(a,f,i.create(o)))}}})}return!0},yo=(r,e)=>{let t=r.schema.marks.link,{$from:n,from:i,to:s}=r.selection,o=Ar(n,t);return o&&o.from<=i&&o.to>=s?(e&&e(r.tr.removeMark(o.from,o.to,t)),!0):!1};var bo=typeof navigator!="undefined"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1,ko=r=>(e,t)=>{r[e]=t};function xo(r){let e={},t,n=ko(e);if(n("Mod-z",qt),n("Shift-Mod-z",bt),n("Backspace",eo),bo||n("Mod-y",bt),t=r.nodes.hard_break){let i=t,s=At(jn,(o,l)=>(l&&l(o.tr.replaceSelectionWith(i.create()).scrollIntoView()),!0));n("Mod-Enter",s),n("Shift-Enter",s),bo&&n("Ctrl-Enter",s)}return(t=r.nodes.bullet_list)&&n("Shift-Ctrl-8",kt(t)),(t=r.nodes.ordered_list)&&n("Shift-Ctrl-9",kt(t)),(t=r.nodes.blockquote)&&n("Ctrl->",ln(t)),(t=r.nodes.list_item)&&(n("Enter",Xs(t)),n("Mod-[",Qs(t)),n("Mod-]",Zs(t))),e}function So(r){let e={},t,n=ko(e);return(t=r.marks.strong)&&(n("Mod-b",ne(t)),n("Mod-B",ne(t))),(t=r.marks.em)&&(n("Mod-i",ne(t)),n("Mod-I",ne(t))),(t=r.marks.underline)&&(n("Mod-Shift-u",ne(t)),n("Mod-Shift-U",ne(t))),(t=r.marks.strikethrough)&&(n("Mod-Shift-s",ne(t)),n("Mod-Shift-S",ne(t))),(t=r.marks.link)&&(n("Mod-k",St),n("Mod-K",St)),e}function Mo(r){return new H({view(e){let t=new vr(r,e);return e.dom.parentNode.insertBefore(t.dom,e.dom),t}})}function Co(r,e){let{from:t,$from:n,to:i,empty:s}=r.selection;return s?e.isInSet(r.storedMarks||n.marks()):r.doc.rangeHasMark(t,i,e)}function Je(r,e=""){return De("span",{className:"prose-menubar__button",style:e,textContent:r})}function Oo(r){let e=t=>({command:Hn(r.nodes.heading,{level:t}),dom:Je(`H${t}`),active(n){return n.selection.$from.parent.hasMarkup(r.nodes.heading,{level:t})}});return[e(1),e(2),e(3),{command:Hn(r.nodes.paragraph),dom:Je("P"),active(t){return t.selection.$from.parent.hasMarkup(r.nodes.paragraph)}}]}function wo(r){return[{command:kt(r.nodes.bullet_list),dom:Je("ul"),active(e){return!1}},{command:kt(r.nodes.ordered_list),dom:Je("ol"),active(e){return!1}},{command:ln(r.nodes.blockquote),dom:Je("\u201D"),active(e){return!1}}]}function No(r){let e=(i,s,o)=>({command:ne(i),dom:Je(s,o),active:l=>Co(l,i)}),t=e(r.marks.sub,"sub","");t.dom.innerHTML="x";let n=e(r.marks.sup,"sup","");return n.dom.innerHTML="x",[e(r.marks.strong,"B","font-weight:bold"),e(r.marks.em,"I","font-style:italic"),e(r.marks.underline,"U","text-decoration:underline"),e(r.marks.strikethrough,"S","text-decoration:line-through"),t,n]}function To(r){return[{command:St,dom:Je("link"),active:St},{command:yo,dom:Je("unlink"),active:e=>Co(e,r.marks.link)}]}function Do(){return[{command:qt,dom:De("span",{className:"prose-menubar__button prose-menubar__button--history-undo"}),active(r){return!1}},{command:bt,dom:De("span",{className:"prose-menubar__button prose-menubar__button--history-redo"}),active(r){return!1}}]}var vr=class{constructor(e,t){this.items=e.flatMap(n=>n),this.editorView=t,this.dom=De("div",{className:"prose-menubar"}),e.filter(n=>n.length).forEach(n=>{let i=De("div",{className:"prose-menubar__group"});this.dom.append(i),n.forEach(({dom:s})=>i.append(s))}),this.update(),this.dom.addEventListener("mousedown",n=>{n.preventDefault(),t.focus(),this.items.forEach(({command:i,dom:s})=>{s.contains(n.target)&&i(t.state,t.dispatch,t)})})}update(){this.items.forEach(({command:e,dom:t,active:n})=>{let i=e(this.editorView.state,null,this.editorView);t.classList.toggle("disabled",!i),t.classList.toggle("active",n(this.editorView.state)||!1)})}destroy(){this.dom.remove()}};function Eo(){return new H({view(r){return new Pr(r)}})}var Pr=class{constructor(e){this.editorView=e,this.editorView.dom.setAttribute("spellcheck","false")}update(){}destroy(){this.editorView.dom.removeAttribute("spellcheck")}};var Dc=["u",0],Ec=["s",0],Ic=["sub",0],Ac=["sup",0];function Io(r){let e={nodes:{doc:Te.doc,paragraph:Te.paragraph,heading:Te.heading,blockquote:Te.blockquote,horizontal_rule:Te.horizontal_rule,text:Te.text,hard_break:Te.hard_break},marks:{link:Kt.link,strong:Kt.strong,em:Kt.em,underline:{parseDOM:[{tag:"u"},{style:"text-decoration:underline"}],toDOM(){return Dc}},strikethrough:{parseDOM:[{tag:"s"},{style:"text-decoration:line-through"}],toDOM(){return Ec}},sub:{parseDOM:[{tag:"sub"}],toDOM(){return Ic}},sup:{parseDOM:[{tag:"sup"}],toDOM(){return Ac}}}},t=new Ue(e);t=new Ue({nodes:Gs(t.spec.nodes,"paragraph block*","block"),marks:t.spec.marks});let n=On(On({},xo(t)),So(t)),i=[Yn(n),Yn(Ai),Ri(),$s(),Ys(),Mo([Oo(t),wo(t),To(t),No(t),Do()]),Eo()],s=De("div",{className:"prose-editor"});r.before(s);let o=new gn(s,{state:xe.create({doc:po(t,r.value),plugins:i}),dispatchTransaction:a=>{o.updateState(o.state.apply(a)),l()}}),l=mo(t,o,r);return()=>{try{o.destroy()}catch(a){}s.remove()}}return Fo(Rc);})(); + `,document.body.append(t);let n=t.querySelector("dialog"),i=t.querySelector("form");i.href.value=r.href||"",i.title.value=r.title||"",n.addEventListener("close",()=>{t.remove(),e(null)}),t.querySelector("button[type=submit]").addEventListener("click",s=>{s.preventDefault(),t.remove(),e(i.href.value?{href:i.href.value,title:i.title.value}:null)}),n.showModal()}),St=(r,e)=>{let{$from:t,empty:n}=r.selection,i=r.schema.marks.link;if(n&&!i.isInSet(t.marks()))return!1;if(e){let s=t.marks().find(o=>o.type===i);Ec((s==null?void 0:s.attrs)||{}).then(o=>{if(o){let l;if(n)l=Rr(t,i),e(r.tr.removeMark(l.from,l.to,i).addMark(l.from,l.to,i.create(o)));else{let{from:a,to:f}=yo(r.selection);e(r.tr.addMark(a,f,i.create(o)))}}})}return!0},bo=(r,e)=>{let t=r.schema.marks.link,{$from:n,from:i,to:s}=r.selection,o=Rr(n,t);return o&&o.from<=i&&o.to>=s?(e&&e(r.tr.removeMark(o.from,o.to,t)),!0):!1},Ic=r=>new Promise(e=>{let t=document.createElement("div");t.innerHTML=` + +
+

+ + +
+
+ `,document.body.append(t);let n=t.querySelector("dialog"),i=t.querySelector("form");i.html.value=r,n.addEventListener("close",()=>{t.remove(),e(null)}),t.querySelector("button[type=submit]").addEventListener("click",s=>{s.preventDefault(),t.remove(),e(i.html.value)}),n.showModal()}),ko=r=>(e,t)=>(t&&Ic(mo(r)).then(n=>{if(n){let i=On(r.state.schema,n);t(e.tr.replaceWith(0,e.tr.doc.content.size,i))}}),!0);var xo=typeof navigator!="undefined"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1,So=r=>(e,t)=>{r[e]=t};function Mo(r){let e={},t,n=So(e);if(n("Mod-z",qt),n("Shift-Mod-z",bt),n("Backspace",to),xo||n("Mod-y",bt),t=r.nodes.hard_break){let i=t,s=At(jn,(o,l)=>(l&&l(o.tr.replaceSelectionWith(i.create()).scrollIntoView()),!0));n("Mod-Enter",s),n("Shift-Enter",s),xo&&n("Ctrl-Enter",s)}return(t=r.nodes.bullet_list)&&n("Shift-Ctrl-8",kt(t)),(t=r.nodes.ordered_list)&&n("Shift-Ctrl-9",kt(t)),(t=r.nodes.blockquote)&&n("Ctrl->",ln(t)),(t=r.nodes.list_item)&&(n("Enter",Qs(t)),n("Mod-[",Zs(t)),n("Mod-]",eo(t))),e}function Co(r){let e={},t,n=So(e);return(t=r.marks.strong)&&(n("Mod-b",ne(t)),n("Mod-B",ne(t))),(t=r.marks.em)&&(n("Mod-i",ne(t)),n("Mod-I",ne(t))),(t=r.marks.underline)&&(n("Mod-Shift-u",ne(t)),n("Mod-Shift-U",ne(t))),(t=r.marks.strikethrough)&&(n("Mod-Shift-s",ne(t)),n("Mod-Shift-S",ne(t))),(t=r.marks.link)&&(n("Mod-k",St),n("Mod-K",St)),e}function Oo(r){return new j({view(e){let t=new Pr(r,e);return e.dom.parentNode.insertBefore(t.dom,e.dom),t}})}function wo(r,e){let{from:t,$from:n,to:i,empty:s}=r.selection;return s?e.isInSet(r.storedMarks||n.marks()):r.doc.rangeHasMark(t,i,e)}function Ee(r,e=""){return be("span",{className:"prose-menubar__button",style:e,textContent:r})}function To(r){let e=t=>({command:Un(r.nodes.heading,{level:t}),dom:Ee(`H${t}`),active(n){return n.selection.$from.parent.hasMarkup(r.nodes.heading,{level:t})}});return[e(1),e(2),e(3),{command:Un(r.nodes.paragraph),dom:Ee("P"),active(t){return t.selection.$from.parent.hasMarkup(r.nodes.paragraph)}}]}function No(r){return[{command:kt(r.nodes.bullet_list),dom:Ee("ul"),active(e){return!1}},{command:kt(r.nodes.ordered_list),dom:Ee("ol"),active(e){return!1}},{command:ln(r.nodes.blockquote),dom:Ee("\u201D"),active(e){return!1}}]}function Do(r){let e=(i,s,o)=>({command:ne(i),dom:Ee(s,o),active:l=>wo(l,i)}),t=e(r.marks.sub,"sub","");t.dom.innerHTML="x";let n=e(r.marks.sup,"sup","");return n.dom.innerHTML="x",[e(r.marks.strong,"B","font-weight:bold"),e(r.marks.em,"I","font-style:italic"),e(r.marks.underline,"U","text-decoration:underline"),e(r.marks.strikethrough,"S","text-decoration:line-through"),t,n]}function Eo(r){return[{command:St,dom:Ee("link"),active:St},{command:bo,dom:Ee("unlink"),active:e=>wo(e,r.marks.link)}]}function Io(){return[{command:qt,dom:be("span",{className:"prose-menubar__button prose-menubar__button--history-undo"}),active(r){return!1}},{command:bt,dom:be("span",{className:"prose-menubar__button prose-menubar__button--history-redo"}),active(r){return!1}}]}function Ac(r){return[{command:ko(r),dom:Ee("html"),active:()=>!1}]}var Pr=class{constructor(e,t){e.push(Ac(t)),this.items=e.flatMap(n=>n),this.editorView=t,this.dom=be("div",{className:"prose-menubar"}),e.filter(n=>n.length).forEach(n=>{let i=be("div",{className:"prose-menubar__group"});this.dom.append(i),n.forEach(({dom:s})=>i.append(s))}),this.update(),this.dom.addEventListener("mousedown",n=>{n.preventDefault(),t.focus(),this.items.forEach(({command:i,dom:s})=>{s.contains(n.target)&&i(t.state,t.dispatch,t)})})}update(){this.items.forEach(({command:e,dom:t,active:n})=>{let i=e(this.editorView.state,null,this.editorView);t.classList.toggle("disabled",!i),t.classList.toggle("active",n(this.editorView.state)||!1)})}destroy(){this.dom.remove()}};function Ao(){return new j({view(r){return new zr(r)}})}var zr=class{constructor(e){this.editorView=e,this.editorView.dom.setAttribute("spellcheck","false")}update(){}destroy(){this.editorView.dom.removeAttribute("spellcheck")}};var Rc=["u",0],vc=["s",0],Pc=["sub",0],zc=["sup",0];function Ro(r){let e={nodes:{doc:De.doc,paragraph:De.paragraph,heading:De.heading,blockquote:De.blockquote,horizontal_rule:De.horizontal_rule,text:De.text,hard_break:De.hard_break},marks:{link:Kt.link,strong:Kt.strong,em:Kt.em,underline:{parseDOM:[{tag:"u"},{style:"text-decoration:underline"}],toDOM(){return Rc}},strikethrough:{parseDOM:[{tag:"s"},{style:"text-decoration:line-through"}],toDOM(){return vc}},sub:{parseDOM:[{tag:"sub"}],toDOM(){return Pc}},sup:{parseDOM:[{tag:"sup"}],toDOM(){return zc}}}},t=new Ue(e);t=new Ue({nodes:Xs(t.spec.nodes,"paragraph block*","block"),marks:t.spec.marks});let n=wn(wn({},Mo(t)),Co(t)),i=[Gn(n),Gn(Ri),vi(),Hs(),Gs(),Oo([To(t),No(t),Eo(t),Do(t),Io()]),Ao()],s=be("div",{className:"prose-editor"});r.before(s);let o=new gn(s,{state:Se.create({doc:On(t,r.value),plugins:i}),dispatchTransaction:a=>{o.updateState(o.state.apply(a)),l()}}),l=go(t,o,r);return()=>{try{o.destroy()}catch(a){}s.remove()}}return Vo(Bc);})(); +//# sourceMappingURL=editor.js.map diff --git a/esbuild.js b/esbuild.js index f6a5dc4..82c24c9 100644 --- a/esbuild.js +++ b/esbuild.js @@ -25,7 +25,7 @@ esbuild globalName: "DjangoProseEditor", plugins: [postcss()], outfile: "django_prose_editor/static/django_prose_editor/editor.js", - // sourcemap: true, + sourcemap: true, watch, }) .then((...args) => { diff --git a/src/commands.js b/src/commands.js index 4f0b4d7..18fb121 100644 --- a/src/commands.js +++ b/src/commands.js @@ -1,5 +1,5 @@ import { getMarkRange } from "./extendMarkRange.js" -import { trimmedRangeFromSelection } from "./utils.js" +import { getHTML, parseHTML, trimmedRangeFromSelection } from "./utils.js" const linkDialog = (attrs) => { return new Promise((resolve) => { @@ -80,3 +80,45 @@ export const removeLink = (state, dispatch) => { } return false } + +const htmlDialog = (html) => { + return new Promise((resolve) => { + const div = document.createElement("div") + div.innerHTML = ` + +
+

+ + +
+
+ ` + document.body.append(div) + const dialog = div.querySelector("dialog") + const form = div.querySelector("form") + form.html.value = html + + dialog.addEventListener("close", () => { + div.remove() + resolve(null) + }) + div.querySelector("button[type=submit]").addEventListener("click", (e) => { + e.preventDefault() + div.remove() + resolve(form.html.value) + }) + dialog.showModal() + }) +} + +export const updateHTML = (editorViewInstance) => (state, dispatch) => { + if (dispatch) { + htmlDialog(getHTML(editorViewInstance)).then((html) => { + if (html) { + const doc = parseHTML(editorViewInstance.state.schema, html) + dispatch(state.tr.replaceWith(0, state.tr.doc.content.size, doc)) + } + }) + } + return true +} diff --git a/src/menu.js b/src/menu.js index c66bfb2..ca17a03 100644 --- a/src/menu.js +++ b/src/menu.js @@ -3,7 +3,7 @@ import { undo, redo } from "prosemirror-history" import { wrapInList } from "prosemirror-schema-list" import { Plugin } from "prosemirror-state" -import { addLink, removeLink } from "./commands.js" +import { addLink, removeLink, updateHTML } from "./commands.js" import { crel } from "./utils.js" export function menuPlugin(items) { @@ -142,8 +142,19 @@ export function historyMenuItems() { ] } +export function htmlMenuItem(editorViewInstance) { + return [ + { + command: updateHTML(editorViewInstance), + dom: menuButtonDOM("html"), + active: () => false, + }, + ] +} + class MenuView { constructor(itemGroups, editorView) { + itemGroups.push(htmlMenuItem(editorView)) this.items = itemGroups.flatMap((group) => group) this.editorView = editorView diff --git a/src/utils.js b/src/utils.js index 5f411c8..ceb38f0 100644 --- a/src/utils.js +++ b/src/utils.js @@ -20,6 +20,14 @@ export function parseHTML(schema, html) { return DOMParser.fromSchema(schema).parse(container) } +export function getHTML(editorViewInstance) { + const { schema, doc } = editorViewInstance.state + const serializer = DOMSerializer.fromSchema(schema) + const container = crel("article") + container.appendChild(serializer.serializeFragment(doc.content)) + return container.innerHTML +} + export const createDebouncedBackWriter = ( schema, editorViewInstance,