diff --git a/django_prose_editor/static/django_prose_editor/editor.js b/django_prose_editor/static/django_prose_editor/editor.js index 58ce207..661d4fd 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 Rt=Object.defineProperty;var zs=Object.getOwnPropertyDescriptor;var Bs=Object.getOwnPropertyNames,Br=Object.getOwnPropertySymbols;var Vr=Object.prototype.hasOwnProperty,Fs=Object.prototype.propertyIsEnumerable;var Fr=(n,e,t)=>e in n?Rt(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Sn=(n,e)=>{for(var t in e||(e={}))Vr.call(e,t)&&Fr(n,t,e[t]);if(Br)for(var t of Br(e))Fs.call(e,t)&&Fr(n,t,e[t]);return n};var Vs=(n,e)=>{for(var t in e)Rt(n,t,{get:e[t],enumerable:!0})},Ls=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Bs(e))!Vr.call(n,i)&&i!==t&&Rt(n,i,{get:()=>e[i],enumerable:!(r=zs(e,i))||r.enumerable});return n};var Js=n=>Ls(Rt({},"__esModule",{value:!0}),n);var Vf={};Vs(Vf,{createEditor:()=>Ps});function v(n){this.content=n}v.prototype={constructor:v,find:function(n){for(var e=0;e>1}};v.from=function(n){if(n instanceof v)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new v(e)};var Mn=v;function Hr(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),o=e.child(r);if(i==o){t+=i.nodeSize;continue}if(!i.sameMarkup(o))return t;if(i.isText&&i.text!=o.text){for(let s=0;i.text[s]==o.text[s];s++)t++;return t}if(i.content.size||o.content.size){let s=Hr(i.content,o.content,t+1);if(s!=null)return s}t+=i.nodeSize}}function jr(n,e,t,r){for(let i=n.childCount,o=e.childCount;;){if(i==0||o==0)return i==o?null:{a:t,b:r};let s=n.child(--i),l=e.child(--o),a=s.nodeSize;if(s==l){t-=a,r-=a;continue}if(!s.sameMarkup(l))return{a:t,b:r};if(s.isText&&s.text!=l.text){let c=0,f=Math.min(s.text.length,l.text.length);for(;ce&&r(a,i+l,o||null,s)!==!1&&a.content.size){let f=l+1;a.nodesBetween(Math.max(0,e-f),Math.min(a.content.size,t-f),r,i+f)}l=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let o="",s=!0;return this.nodesBetween(e,t,(l,a)=>{let c=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&&c||l.isTextblock)&&r&&(s?s=!1:o+=r),o+=c},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),o=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),o=1);oe)for(let o=0,s=0;se&&((st)&&(l.isText?l=l.cut(Math.max(0,e-s),Math.min(l.text.length,t-s)):l=l.cut(Math.max(0,e-s-1),Math.min(l.content.size,t-s-1))),r.push(l),i+=l.nodeSize),s=a}return new n(r,i)}cutByIndex(e,t){return e==t?n.empty:e==0&&t==this.content.length?this:new n(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),o=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new n(i,o)}addToStart(e){return new n([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new n(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 r=0,i=0;;r++){let o=this.child(r),s=i+o.nodeSize;if(s>=e)return s==e||t>0?zt(r+1,s):zt(r,i);i=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return n.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new n(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return n.empty;let t,r=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(o)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}};O.none=[];var Ie=class extends Error{},b=class n{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=Ur(this.content,e+this.openStart,t);return r&&new n(r,this.openStart,this.openEnd)}removeBetween(e,t){return new n(_r(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 n.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new n(y.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let o=e.firstChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.lastChild)i++;return new n(e,r,i)}};b.empty=new b(y.empty,0,0);function _r(n,e,t){let{index:r,offset:i}=n.findIndex(e),o=n.maybeChild(r),{index:s,offset:l}=n.findIndex(t);if(i==e||o.isText){if(l!=t&&!n.child(s).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=s)throw new RangeError("Removing non-flat range");return n.replaceChild(r,o.copy(_r(o.content,e-i-1,t-i-1)))}function Ur(n,e,t,r){let{index:i,offset:o}=n.findIndex(e),s=n.maybeChild(i);if(o==e||s.isText)return r&&!r.canReplace(i,i,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=Ur(s.content,e-o-1,t);return l&&n.replaceChild(i,s.copy(l))}function Ws(n,e,t){if(t.openStart>n.depth)throw new Ie("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Ie("Inconsistent open depths");return Gr(n,e,t,0)}function Gr(n,e,t,r){let i=n.index(r),o=n.node(r);if(i==e.index(r)&&r=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function lt(n,e,t,r){let i=(e||n).node(t),o=0,s=e?e.index(t):i.childCount;n&&(o=n.index(t),n.depth>t?o++:n.textOffset&&(De(n.nodeAfter,r),o++));for(let l=o;li&&Tn(n,e,i+1),s=r.depth>i&&Tn(t,r,i+1),l=[];return lt(null,n,i,l),o&&s&&e.index(i)==t.index(i)?(Yr(o,s),De(Ee(o,Xr(n,e,t,r,i+1)),l)):(o&&De(Ee(o,Ft(n,e,i+1)),l),lt(e,t,i,l),s&&De(Ee(s,Ft(t,r,i+1)),l)),lt(r,null,i,l),new y(l)}function Ft(n,e,t){let r=[];if(lt(null,n,t,r),n.depth>t){let i=Tn(n,e,t+1);De(Ee(i,Ft(n,e,t+1)),r)}return lt(e,null,t,r),new y(r)}function qs(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let o=t-1;o>=0;o--)i=e.node(o).copy(y.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}var Vt=class n{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,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 r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):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 r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let o=0;o0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new Ae(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,o=t;for(let s=e;;){let{index:l,offset:a}=s.content.findIndex(o),c=o-a;if(r.push(s,l,i+a),!c||(s=s.child(l),s.isText))break;o=c-1,i+=a+1}return new n(t,r,o)}static resolveCached(e,t){for(let i=0;ie&&this.nodesBetween(e,t,o=>(r.isInSet(o.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),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,r=y.empty,i=0,o=r.childCount){let s=this.contentMatchAt(e).matchFragment(r,i,o),l=s&&s.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 r=null;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=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,r)}let i=y.fromJSON(e,t.content);return e.nodeType(t.type).create(t.attrs,i,r)}};re.prototype.text=void 0;var Dn=class n extends re{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):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 n(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new n(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(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}var ve=class n{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new En(e,t);if(r.next==null)return n.empty;let i=Zr(r);r.next&&r.err("Unexpected trailing text");let o=Xs(Ys(i));return Qs(o,r),o}matchType(e){for(let t=0;tc.createAndFill()));for(let c=0;c=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(r){e.push(r);for(let i=0;i{let o=i+(r.validEnd?"*":" ")+" ";for(let s=0;s"+e.indexOf(r.next[s].next);return o}).join(` -`)}};ve.empty=new ve(!0);var En=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(n){let e=[];do e.push(Hs(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function Hs(n){let e=[];do e.push(js(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function js(n){let e=Gs(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=_s(n,e);else break;return e}function Lr(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function _s(n,e){let t=Lr(n),r=t;return n.eat(",")&&(n.next!="}"?r=Lr(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function Us(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let o in t){let s=t[o];s.groups.indexOf(e)>-1&&i.push(s)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function Gs(n){if(n.eat("(")){let e=Zr(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=Us(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Ys(n){let e=[[]];return i(o(n,0),t()),e;function t(){return e.push([])-1}function r(s,l,a){let c={term:a,to:l};return e[s].push(c),c}function i(s,l){s.forEach(a=>a.to=l)}function o(s,l){if(s.type=="choice")return s.exprs.reduce((a,c)=>a.concat(o(c,l)),[]);if(s.type=="seq")for(let a=0;;a++){let c=o(s.exprs[a],l);if(a==s.exprs.length-1)return c;i(c,l=t())}else if(s.type=="star"){let a=t();return r(l,a),i(o(s.expr,a),a),[r(a)]}else if(s.type=="plus"){let a=t();return i(o(s.expr,l),a),i(o(s.expr,a),a),[r(a)]}else{if(s.type=="opt")return[r(l)].concat(o(s.expr,l));if(s.type=="range"){let a=l;for(let c=0;c{n[s].forEach(({term:l,to:a})=>{if(!l)return;let c;for(let f=0;f{c||i.push([l,c=[]]),c.indexOf(f)==-1&&c.push(f)})})});let o=e[r.join(",")]=new ve(r.indexOf(n.length-1)>-1);for(let s=0;s-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[o]=new n(o,t,s));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let o in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}},In=class{constructor(e){this.hasDefault=Object.prototype.hasOwnProperty.call(e,"default"),this.default=e.default}get isRequired(){return!this.hasDefault}},ct=class n{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=ri(i.attrs),this.excluded=null;let o=ti(this.attrs);this.instance=o?new O(this,o):null}create(e=null){return!e&&this.instance?this.instance:new O(this,ni(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((o,s)=>r[o]=new n(o,i++,t,s)),r}removeFromSet(e){for(var t=0;t-1}},Pe=class{constructor(e){this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=Mn.from(e.nodes),t.marks=Mn.from(e.marks||{}),this.nodes=Lt.compile(this.spec.nodes,this),this.marks=ct.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let o=this.nodes[i],s=o.spec.content||"",l=o.spec.marks;o.contentMatch=r[s]||(r[s]=ve.parse(s,this.nodes)),o.inlineContent=o.contentMatch.inlineContent,o.markSet=l=="_"?null:l?Wr(this,l.split(" ")):l==""||!o.inlineContent?[]:null}for(let i in this.marks){let o=this.marks[i],s=o.spec.excludes;o.excluded=s==null?[o]:s==""?[]:Wr(this,s.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Lt){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,r,i)}text(e,t){let r=this.nodes.text;return new Dn(r,r.defaultAttrs,e,O.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return re.fromJSON(this,e)}markFromJSON(e){return O.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function Wr(n,e){let t=[];for(let r=0;r-1)&&t.push(s=a)}if(!s)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}var Re=class n{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[],t.forEach(r=>{r.tag?this.tags.push(r):r.style&&this.styles.push(r)}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let i=e.nodes[r.node];return i.contentMatch.matchType(i)})}parse(e,t={}){let r=new qt(this,t,!1);return r.addAll(e,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new qt(this,t,!0);return r.addAll(e,t.from,t.to),b.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(s.getAttrs){let a=s.getAttrs(t);if(a===!1)continue;s.attrs=a||void 0}return s}}}static schemaRules(e){let t=[];function r(i){let o=i.priority==null?50:i.priority,s=0;for(;s{r(s=Kr(s)),s.mark||s.ignore||s.clearMark||(s.mark=i)})}for(let i in e.nodes){let o=e.nodes[i].spec.parseDOM;o&&o.forEach(s=>{r(s=Kr(s)),s.node||s.ignore||s.mark||(s.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new n(e,n.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},Zs={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},oi={ol:!0,ul:!0},Jt=1,Wt=2,at=4;function qr(n,e,t){return e!=null?(e?Jt:0)|(e==="full"?Wt:0):n&&n.whitespace=="pre"?Jt|Wt:t&~at}var je=class{constructor(e,t,r,i,o,s,l){this.type=e,this.attrs=t,this.marks=r,this.pendingMarks=i,this.solid=o,this.options=l,this.content=[],this.activeMarks=O.none,this.stashMarks=[],this.match=s||(l&at?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(y.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Jt)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-i[0].length))}}let t=y.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(y.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,r=this.pendingMarks;tthis.addAll(e)),s&&this.sync(l),this.needsBlock=a}else this.withStyleRules(e,()=>{this.addElementByRule(e,o,o.consuming===!1?i:void 0)})}leafFallback(e){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` -`))}ignoreFallback(e){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(e){let t=O.none,r=O.none;for(let i=0;i{s.clearMark(l)&&(r=l.addToSet(r))}):t=this.parser.schema.marks[s.mark].create(s.attrs).addToSet(t),s.consuming===!1)o=s;else break}return[t,r]}addElementByRule(e,t,r){let i,o,s;t.node?(o=this.parser.schema.nodes[t.node],o.isLeaf?this.insertNode(o.create(t.attrs))||this.leafFallback(e):i=this.enter(o,t.attrs||null,t.preserveWhitespace)):(s=this.parser.schema.marks[t.mark].create(t.attrs),this.addPendingMark(s));let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(r)this.addElement(e,r);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--,s&&this.removePendingMark(s,l)}addAll(e,t,r){let i=t||0;for(let o=t?e.childNodes[t]:e.firstChild,s=r==null?null:e.childNodes[r];o!=s;o=o.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(o);this.findAtPoint(e,i)}findPlace(e){let t,r;for(let i=this.open;i>=0;i--){let o=this.nodes[i],s=o.findWrapping(e);if(s&&(!t||t.length>s.length)&&(t=s,r=o,!s.length)||o.solid)break}if(!t)return!1;this.sync(r);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 r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(i?0:1),s=(l,a)=>{for(;l>=0;l--){let c=t[l];if(c==""){if(l==t.length-1||l==0)continue;for(;a>=o;a--)if(s(l-1,a))return!0;return!1}else{let f=a>0||a==0&&i?this.nodes[a].type:r&&a>=o?r.node(a-o).type:null;if(!f||f.name!=c&&f.groups.indexOf(c)==-1)return!1;a--}}return!0};return s(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}addPendingMark(e){let t=il(e,this.top.pendingMarks);t&&this.top.stashMarks.push(t),this.top.pendingMarks=e.addToSet(this.top.pendingMarks)}removePendingMark(e,t){for(let r=this.open;r>=0;r--){let i=this.nodes[r];if(i.pendingMarks.lastIndexOf(e)>-1)i.pendingMarks=e.removeFromSet(i.pendingMarks);else{i.activeMarks=e.removeFromSet(i.activeMarks);let s=i.popFromStashMark(e);s&&i.type&&i.type.allowsMarkType(s.type)&&(i.activeMarks=s.addToSet(i.activeMarks))}if(i==t)break}}};function el(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&oi.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function tl(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function nl(n){let e=/\s*([\w-]+)\s*:\s*([^;]+)/g,t,r=[];for(;t=e.exec(n);)r.push(t[1],t[2].trim());return r}function Kr(n){let e={};for(let t in n)e[t]=n[t];return e}function rl(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let o=[],s=l=>{o.push(l);for(let a=0;a{if(o.length||s.marks.length){let l=0,a=0;for(;l=0;i--){let o=this.serializeMark(e.marks[i],e.isInline,t);o&&((o.contentDOM||o.dom).appendChild(r),r=o.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&n.renderSpec(Nn(r),i(e,t))}static renderSpec(e,t,r=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],o=i.indexOf(" ");o>0&&(r=i.slice(0,o),i=i.slice(o+1));let s,l=r?e.createElementNS(r,i):e.createElement(i),a=t[1],c=1;if(a&&typeof a=="object"&&a.nodeType==null&&!Array.isArray(a)){c=2;for(let f in a)if(a[f]!=null){let h=f.indexOf(" ");h>0?l.setAttributeNS(f.slice(0,h),f.slice(h+1),a[f]):l.setAttribute(f,a[f])}}for(let f=c;fc)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}else{let{dom:d,contentDOM:p}=n.renderSpec(e,h,r);if(l.appendChild(d),p){if(s)throw new RangeError("Multiple content holes");s=p}}}return{dom:l,contentDOM:s}}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new n(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=$r(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return $r(e.marks)}};function $r(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function Nn(n){return n.document||window.document}var ai=65535,ci=Math.pow(2,16);function ol(n,e){return n+e*ci}function si(n){return n&ai}function sl(n){return(n-(n&ai))/ci}var fi=1,hi=2,Kt=4,di=8,dt=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&di)>0}get deletedBefore(){return(this.delInfo&(fi|Kt))>0}get deletedAfter(){return(this.delInfo&(hi|Kt))>0}get deletedAcross(){return(this.delInfo&Kt)>0}},he=class n{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&n.empty)return n.empty}recover(e){let t=0,r=si(e);if(!this.inverted)for(let i=0;ie)break;let c=this.ranges[l+o],f=this.ranges[l+s],h=a+c;if(e<=h){let d=c?e==a?-1:e==h?1:t:t,p=a+i+(d<0?0:f);if(r)return p;let u=e==(t<0?a:h)?null:ol(l/3,e-a),m=e==a?hi:e==h?fi:Kt;return(t<0?e!=a:e!=h)&&(m|=di),new dt(p,m,u)}i+=f-c}return r?e+i:new dt(e+i,0,null)}touches(e,t){let r=0,i=si(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let c=this.ranges[l+o],f=a+c;if(e<=f&&l==i*3)return!0;r+=this.ranges[l+s]-c}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new n;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;ro&&a!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return I.fromReplace(e,this.from,this.to,o)}invert(){return new ze(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(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 n(t.from,t.to,e.markFromJSON(t.mark))}};D.jsonID("addMark",pt);var ze=class n extends D{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new b(Bn(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return I.fromReplace(e,this.from,this.to,r)}invert(){return new pt(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(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 n(t.from,t.to,e.markFromJSON(t.mark))}};D.jsonID("removeMark",ze);var mt=class n extends D{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return I.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return I.fromReplace(e,this.pos,this.pos+1,new b(y.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new n(t.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,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 n(t.from,t.to,t.gapFrom,t.gapTo,b.fromJSON(e,t.slice),t.insert,!!t.structure)}};D.jsonID("replaceAround",E);function Rn(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function ll(n,e,t,r){let i=[],o=[],s,l;n.doc.nodesBetween(e,t,(a,c,f)=>{if(!a.isInline)return;let h=a.marks;if(!r.isInSet(h)&&f.type.allowsMarkType(r.type)){let d=Math.max(c,e),p=Math.min(c+a.nodeSize,t),u=r.addToSet(h);for(let m=0;mn.step(a)),o.forEach(a=>n.step(a))}function al(n,e,t,r){let i=[],o=0;n.doc.nodesBetween(e,t,(s,l)=>{if(!s.isInline)return;o++;let a=null;if(r instanceof ct){let c=s.marks,f;for(;f=r.isInSet(c);)(a||(a=[])).push(f),c=f.removeFromSet(c)}else r?r.isInSet(s.marks)&&(a=[r]):a=s.marks;if(a&&a.length){let c=Math.min(l+s.nodeSize,t);for(let f=0;fn.step(new ze(s.from,s.to,s.style)))}function cl(n,e,t,r=t.contentMatch){let i=n.doc.nodeAt(e),o=[],s=e+1;for(let l=0;l=0;l--)n.step(o[l])}function fl(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function Ue(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),o=n.$from.index(r),s=n.$to.indexAfter(r);if(rt;u--)m||r.index(u)>0?(m=!0,f=y.from(r.node(u).copy(f)),h++):a--;let d=y.empty,p=0;for(let u=o,m=!1;u>t;u--)m||i.after(u+1)=0;s--){if(r.size){let l=t[s].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=y.from(t[s].type.create(t[s].attrs,r))}let i=e.start,o=e.end;n.step(new E(i,o,i,o,new b(r,0,0),t.length,!0))}function ml(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=n.steps.length;n.doc.nodesBetween(e,t,(s,l)=>{if(s.isTextblock&&!s.hasMarkup(r,i)&&gl(n.doc,n.mapping.slice(o).map(l),r)){n.clearIncompatible(n.mapping.slice(o).map(l,1),r);let a=n.mapping.slice(o),c=a.map(l,1),f=a.map(l+s.nodeSize,1);return n.step(new E(c,f,c+1,f-1,new b(y.from(r.create(i,null,s.marks)),0,0),1,!0)),!1}})}function gl(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function yl(n,e,t,r,i){let o=n.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");t||(t=o.type);let s=t.create(r,null,i||o.marks);if(o.isLeaf)return n.replaceWith(e,e+o.nodeSize,s);if(!t.validContent(o.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new E(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new b(y.from(s),0,0),1,!0))}function ke(n,e,t=1,r){let i=n.resolve(e),o=i.depth-t,s=r&&r[r.length-1]||i.parent;if(o<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!s.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let c=i.depth-1,f=t-2;c>o;c--,f--){let h=i.node(c),d=i.index(c);if(h.type.spec.isolating)return!1;let p=h.content.cutByIndex(d,h.childCount),u=r&&r[f+1];u&&(p=p.replaceChild(0,u.type.create(u.attrs)));let m=r&&r[f]||h;if(!h.canReplace(d+1,h.childCount)||!m.type.validContent(p))return!1}let l=i.indexAfter(o),a=r&&r[0];return i.node(o).canReplaceWith(l,l,a?a.type:i.node(o+1).type)}function bl(n,e,t=1,r){let i=n.doc.resolve(e),o=y.empty,s=y.empty;for(let l=i.depth,a=i.depth-t,c=t-1;l>a;l--,c--){o=y.from(i.node(l).copy(o));let f=r&&r[c];s=y.from(f?f.type.create(f.attrs,s):i.node(l).copy(s))}n.step(new K(e,e,new b(o.append(s),t,t),!0))}function yt(n,e){let t=n.resolve(e),r=t.index();return kl(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function kl(n,e){return!!(n&&e&&!n.isLeaf&&n.canAppend(e))}function xl(n,e,t){let r=new K(e-t,e+t,b.empty,!0);n.step(r)}function Sl(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let o=r.index(i);if(r.node(i).canReplaceWith(o,o,t))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,t))return r.after(i+1);if(o=0;s--){let l=s==r.depth?0:r.pos<=(r.start(s+1)+r.end(s+1))/2?-1:1,a=r.index(s)+(l>0?1:0),c=r.node(s),f=!1;if(o==1)f=c.canReplace(a,a,i);else{let h=c.contentMatchAt(a).findWrapping(i.firstChild.type);f=h&&c.canReplaceWith(a,a,h[0])}if(f)return l==0?r.pos:l<0?r.before(s+1):r.after(s+1)}return null}function Gt(n,e,t=e,r=b.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),o=n.resolve(t);return ui(i,o,r)?new K(e,t,r):new zn(i,o,r).fit()}function ui(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}var zn=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=y.empty;for(let i=0;i<=e.depth;i++){let o=e.node(i);this.frontier.push({type:o.type,match:o.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=y.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let c=this.findFittable();c?this.placeNodes(c):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let a=new b(o,s,l);return e>-1?new E(r.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||r.pos!=this.$to.pos?new K(r.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),o.type.spec.isolating&&i<=r){e=r;break}t=o.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=vn(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:c}=this.frontier[l],f,h=null;if(t==1&&(s?c.matchType(s.type)||(h=c.fillBefore(y.from(s),!1)):o&&a.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:h};if(t==2&&s&&(f=c.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:f};if(o&&c.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=vn(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new b(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=vn(e,t);if(i.childCount<=1&&t>0){let o=e.size-t<=t+i.size;this.unplaced=new b(ft(e,t-1,1),t-1,o?t-1:r)}else this.unplaced=new b(ft(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:o}){for(;this.depth>t;)this.closeFrontierNode();if(o)for(let m=0;m1||a==0||m.content.size)&&(h=g,f.push(pi(m.mark(d.allowedMarks(m.marks)),c==1?a:0,c==l.childCount?p:-1)))}let u=c==l.childCount;u||(p=-1),this.placed=ht(this.placed,t,y.from(f)),this.frontier[t].match=h,u&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],o=t=0;l--){let{match:a,type:c}=this.frontier[l],f=Pn(e,l,c,a,!0);if(!f||f.childCount)continue e}return{depth:t,fit:s,move:o?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=ht(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=ht(this.placed,this.depth,y.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(y.empty,!0);t.childCount&&(this.placed=ht(this.placed,this.frontier.length,t))}};function ft(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(ft(n.firstChild.content,e-1,t)))}function ht(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(ht(n.lastChild.content,e-1,t)))}function vn(n,e){for(let t=0;t1&&(r=r.replaceChild(0,pi(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(y.empty,!0)))),n.copy(r)}function Pn(n,e,t,r,i){let o=n.node(e),s=i?n.indexAfter(e):n.index(e);if(s==o.childCount&&!t.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!Ml(t,o.content,s)?l:null}function Ml(n,e,t){for(let r=t;r0;d--,p--){let u=i.node(d).type.spec;if(u.defining||u.definingAsContext||u.isolating)break;s.indexOf(d)>-1?l=d:i.before(d)==p&&s.splice(1,0,-d)}let a=s.indexOf(l),c=[],f=r.openStart;for(let d=r.content,p=0;;p++){let u=d.firstChild;if(c.push(u),p==r.openStart)break;d=u.content}for(let d=f-1;d>=0;d--){let p=c[d],u=Cl(p.type);if(u&&!p.sameMarkup(i.node(Math.abs(l)-1)))f=d;else if(u||!p.type.isTextblock)break}for(let d=r.openStart;d>=0;d--){let p=(d+f+1)%(r.openStart+1),u=c[p];if(u)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>h));d--){let p=s[d];p<0||(e=i.before(p),t=o.after(p))}}function mi(n,e,t,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(n).append(n);n=s.append(o.matchFragment(s).fillBefore(y.empty,!0))}return n}function wl(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Sl(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new b(y.from(r),0,0))}function Nl(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),o=gi(r,i);for(let s=0;s0&&(a||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&t>r.end(s)&&i.end(s)-t!=i.depth-s)return n.delete(r.before(s),t);n.delete(e,t)}function gi(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let o=n.start(i);if(oe.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&t.push(i)}return t}var $t=class n extends D{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return I.fail("No node at attribute step's position");let r=Object.create(null);for(let o in t.attrs)r[o]=t.attrs[o];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return I.fromReplace(e,this.pos,this.pos+1,new b(y.from(i),0,t.isLeaf?0:1))}getMap(){return he.empty}invert(e){return new n(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 n(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 n(t.pos,t.attr,t.value)}};D.jsonID("attr",$t);var Ht=class n extends D{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 r=e.type.create(t,e.content,e.marks);return I.ok(r)}getMap(){return he.empty}invert(e){return new n(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 n(t.attr,t.value)}};D.jsonID("docAttr",Ht);var _e=class extends Error{};_e=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};_e.prototype=Object.create(Error.prototype);_e.prototype.constructor=_e;_e.prototype.name="TransformError";var jt=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new ut}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new _e(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,r=b.empty){let i=Gt(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new b(y.from(r),0,0))}delete(e,t){return this.replace(e,t,b.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return Ol(this,e,t,r),this}replaceRangeWith(e,t,r){return wl(this,e,t,r),this}deleteRange(e,t){return Nl(this,e,t),this}lift(e,t){return hl(this,e,t),this}join(e,t=1){return xl(this,e,t),this}wrap(e,t){return pl(this,e,t),this}setBlockType(e,t=e,r,i=null){return ml(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return yl(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new $t(e,t,r)),this}setDocAttribute(e,t){return this.step(new Ht(e,t)),this}addNodeMark(e,t){return this.step(new mt(e,t)),this}removeNodeMark(e,t){if(!(t instanceof O)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t=t.isInSet(r.marks),!t)return this}return this.step(new gt(e,t)),this}split(e,t=1,r){return bl(this,e,t,r),this}addMark(e,t,r){return ll(this,e,t,r),this}removeMark(e,t,r){return al(this,e,t,r),this}clearIncompatible(e,t,r){return cl(this,e,t,r),this}};var Fn=Object.create(null),S=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new Ln(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;o--){let s=t<0?Ge(e.node(0),e.node(o),e.before(o+1),e.index(o),t,r):Ge(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,t,r);if(s)return s}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new $(e.node(0))}static atStart(e){return Ge(e,e,0,0,1)||new $(e)}static atEnd(e){return Ge(e,e,e.content.size,e.childCount,-1)||new $(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=Fn[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in Fn)throw new RangeError("Duplicate use of selection JSON ID "+e);return Fn[e]=t,t.prototype.jsonID=e,t}getBookmark(){return w.between(this.$anchor,this.$head).getBookmark()}};S.prototype.visible=!0;var Ln=class{constructor(e,t){this.$from=e,this.$to=t}},yi=!1;function bi(n){!yi&&!n.parent.inlineContent&&(yi=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}var w=class n 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 r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return S.near(r);let i=e.resolve(t.map(this.anchor));return new n(i.parent.inlineContent?i:r,r)}replace(e,t=b.empty){if(super.replace(e,t),t==b.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof n&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Xt(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 n(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let o=S.findFrom(t,r,!0)||S.findFrom(t,-r,!0);if(o)t=o.$head;else return S.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(S.findFrom(e,-r,!0)||S.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?s=0;s+=i){let l=e.child(s);if(l.isAtom){if(!o&&x.isSelectable(l))return x.create(n,t-(i<0?l.nodeSize:0))}else{let a=Ge(n,l,t+i,i<0?l.childCount:0,i,o);if(a)return a}t+=l.nodeSize*i}return null}function ki(n,e,t){let r=n.steps.length-1;if(r{s==null&&(s=f)}),n.setSelection(S.near(n.doc.resolve(s),t))}var xi=1,Yt=2,Si=4,Wn=class extends jt{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|=Yt,this}ensureMarks(e){return O.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&Yt)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Yt,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||O.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r==null?t:r,!e)return this.deleteRange(t,r);let o=this.storedMarks;if(!o){let s=this.doc.resolve(t);o=r==t?s.marks():s.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,o)),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(n,e){return!e||!n?n:n.bind(e)}var Be=class{constructor(e,t,r){this.name=e,this.init=Mi(t.init,r),this.apply=Mi(t.apply,r)}},Dl=[new Be("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new Be("selection",{init(n,e){return n.selection||S.atStart(e.doc)},apply(n){return n.selection}}),new Be("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new Be("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})],bt=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Dl.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new Be(r.key,r.spec.state,r))})}},Qt=class n{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 r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],o=i.spec.state;o&&o.toJSON&&(t[r]=o.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new bt(e.schema,e.plugins),o=new n(i);return i.fields.forEach(s=>{if(s.name=="doc")o.doc=re.fromJSON(e.schema,t.doc);else if(s.name=="selection")o.selection=S.fromJSON(o.doc,t.selection);else if(s.name=="storedMarks")t.storedMarks&&(o.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let a=r[l],c=a.spec.state;if(a.key==s.name&&c&&c.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){o[s.name]=c.fromJSON.call(a,e,t[l],o);return}}o[s.name]=s.init(e,o)}}),o}};function Ci(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Ci(i,e,{})),t[r]=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]}},Vn=Object.create(null);function Oi(n){return n in Vn?n+"$"+ ++Vn[n]:(Vn[n]=0,n+"$")}var kt=class{constructor(e="key"){this.key=Oi(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var Ni=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function El(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}var Il=(n,e,t)=>{let r=El(n,t);if(!r)return!1;let i=Ti(r);if(!i){let s=r.blockRange(),l=s&&Ue(s);return l==null?!1:(e&&e(n.tr.lift(s,l).scrollIntoView()),!0)}let o=i.nodeBefore;if(!o.type.spec.isolating&&Ei(n,i,e))return!0;if(r.parent.content.size==0&&(Ye(o,"end")||x.isSelectable(o))){let s=Gt(n.doc,r.before(),r.after(),b.empty);if(s&&s.slice.size{let{$head:r,empty:i}=n.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;o=Ti(r)}let s=o&&o.nodeBefore;return!s||!x.isSelectable(s)?!1:(e&&e(n.tr.setSelection(x.create(n.doc,o.pos-s.nodeSize)).scrollIntoView()),!0)};function Ti(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){if(n.index(e)>0)return n.doc.resolve(n.before(e+1));if(n.node(e).type.spec.isolating)break}return null}function vl(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=vl(n,t);if(!r)return!1;let i=Di(r);if(!i)return!1;let o=i.nodeAfter;if(Ei(n,i,e))return!0;if(r.parent.content.size==0&&(Ye(o,"start")||x.isSelectable(o))){let s=Gt(n.doc,r.before(),r.after(),b.empty);if(s&&s.slice.size{let{$head:r,empty:i}=n.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):r.parentOffset=0;e--){let t=n.node(e);if(n.index(e)+1{let{$head:t,$anchor:r}=n.selection;return!t.parent.type.spec.code||!t.sameParent(r)?!1:(e&&e(n.tr.insertText(` -`).scrollIntoView()),!0)};function Kn(n){for(let e=0;e{let{$head:t,$anchor:r}=n.selection;if(!t.parent.type.spec.code||!t.sameParent(r))return!1;let i=t.node(-1),o=t.indexAfter(-1),s=Kn(i.contentMatchAt(o));if(!s||!i.canReplaceWith(o,o,s))return!1;if(e){let l=t.after(),a=n.tr.replaceWith(l,l,s.createAndFill());a.setSelection(S.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},Bl=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof $||r.parent.inlineContent||i.parent.inlineContent)return!1;let o=Kn(i.parent.contentMatchAt(i.indexAfter()));if(!o||!o.isTextblock)return!1;if(e){let s=(!r.parentOffset&&i.index(){let{$cursor:t}=n.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let o=t.before();if(ke(n.doc,o))return e&&e(n.tr.split(o).scrollIntoView()),!0}let r=t.blockRange(),i=r&&Ue(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function Vl(n){return(e,t)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof x&&e.selection.node.isBlock)return!r.parentOffset||!ke(e.doc,r.pos)?!1:(t&&t(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.parent.isBlock)return!1;if(t){let o=i.parentOffset==i.parent.content.size,s=e.tr;(e.selection instanceof w||e.selection instanceof $)&&s.deleteSelection();let l=r.depth==0?null:Kn(r.node(-1).contentMatchAt(r.indexAfter(-1))),a=n&&n(i.parent,o),c=a?[a]:o&&l?[{type:l}]:void 0,f=ke(s.doc,s.mapping.map(r.pos),1,c);if(!c&&!f&&ke(s.doc,s.mapping.map(r.pos),1,l?[{type:l}]:void 0)&&(l&&(c=[{type:l}]),f=!0),f&&(s.split(s.mapping.map(r.pos),1,c),!o&&!r.parentOffset&&r.parent.type!=l)){let h=s.mapping.map(r.before()),d=s.doc.resolve(h);l&&r.node(-1).canReplaceWith(d.index(),d.index()+1,l)&&s.setNodeMarkup(s.mapping.map(r.before()),l)}t(s.scrollIntoView())}return!0}}var Ll=Vl();var Jl=(n,e)=>(e&&e(n.tr.setSelection(new $(n.doc))),!0);function Wl(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,o=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(o-1,o)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(o,o+1)||!(i.isTextblock||yt(n.doc,e.pos))?!1:(t&&t(n.tr.clearIncompatible(e.pos,r.type,r.contentMatchAt(r.childCount)).join(e.pos).scrollIntoView()),!0)}function Ei(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,o,s;if(r.type.spec.isolating||i.type.spec.isolating)return!1;if(Wl(n,e,t))return!0;let l=e.parent.canReplace(e.index(),e.index()+1);if(l&&(o=(s=r.contentMatchAt(r.childCount)).findWrapping(i.type))&&s.matchType(o[0]||i.type).validEnd){if(t){let h=e.pos+i.nodeSize,d=y.empty;for(let m=o.length-1;m>=0;m--)d=y.from(o[m].create(null,d));d=y.from(r.copy(d));let p=n.tr.step(new E(e.pos-1,h,e.pos,h,new b(d,1,0),o.length,!0)),u=h+2*o.length;yt(p.doc,u)&&p.join(u),t(p.scrollIntoView())}return!0}let a=S.findFrom(e,1),c=a&&a.$from.blockRange(a.$to),f=c&&Ue(c);if(f!=null&&f>=e.depth)return t&&t(n.tr.lift(c,f).scrollIntoView()),!0;if(l&&Ye(i,"start",!0)&&Ye(r,"end")){let h=r,d=[];for(;d.push(h),!h.isTextblock;)h=h.lastChild;let p=i,u=1;for(;!p.isTextblock;p=p.firstChild)u++;if(h.canReplace(h.childCount,h.childCount,p.content)){if(t){let m=y.empty;for(let k=d.length-1;k>=0;k--)m=y.from(d[k].copy(m));let g=n.tr.step(new E(e.pos-d.length,e.pos+i.nodeSize,e.pos+u,e.pos+i.nodeSize-u,new b(m,d.length,0),0,!0));t(g.scrollIntoView())}return!0}}return!1}function Ii(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,o=i.depth;for(;i.node(o).isInline;){if(!o)return!1;o--}return i.node(o).isTextblock?(t&&t(e.tr.setSelection(w.create(e.doc,n<0?i.start(o):i.end(o)))),!0):!1}}var ql=Ii(-1),Kl=Ii(1);function Zt(n,e=null){return function(t,r){let{$from:i,$to:o}=t.selection,s=i.blockRange(o),l=s&&_t(s,n,e);return l?(r&&r(t.tr.wrap(s,l).scrollIntoView()),!0):!1}}function Hn(n,e=null){return function(t,r){let i=!1;for(let o=0;o{if(i)return!1;if(!(!a.isTextblock||a.hasMarkup(n,e)))if(a.type==n)i=!0;else{let f=t.doc.resolve(c),h=f.index();i=f.parent.canReplaceWith(h,h+1,n)}})}if(!i)return!1;if(r){let o=t.tr;for(let s=0;s{if(s)return!1;s=l.inlineContent&&l.type.allowsMarkType(t)}),s)return!0}return!1}function G(n,e=null){return function(t,r){let{empty:i,$cursor:o,ranges:s}=t.selection;if(i&&!o||!$l(t.doc,s,n))return!1;if(r)if(o)n.isInSet(t.storedMarks||o.marks())?r(t.tr.removeStoredMark(n)):r(t.tr.addStoredMark(n.create(e)));else{let l=!1,a=t.tr;for(let c=0;!l&&c{let o=s=>{this[i](s)};return e.dom.addEventListener(i,o),{name:i,handler:o}})}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,r;if(t){let l=e.nodeBefore,a=e.nodeAfter;if(l||a){let c=this.editorView.nodeDOM(this.cursorPos-(l?l.nodeSize:0));if(c){let f=c.getBoundingClientRect(),h=l?f.bottom:f.top;l&&a&&(h=(h+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2),r={left:f.left,right:f.right,top:h-this.width/2,bottom:h+this.width/2}}}}if(!r){let l=this.editorView.coordsAtPos(this.cursorPos);r={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 o,s;if(!i||i==document.body&&getComputedStyle(i).position=="static")o=-pageXOffset,s=-pageYOffset;else{let l=i.getBoundingClientRect();o=l.left-i.scrollLeft,s=l.top-i.scrollTop}this.element.style.left=r.left-o+"px",this.element.style.top=r.top-s+"px",this.element.style.width=r.right-r.left+"px",this.element.style.height=r.bottom-r.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}),r=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),i=r&&r.type.spec.disableDropCursor,o=typeof i=="function"?i(this.editorView,t,e):i;if(t&&!o){let s=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let l=Ut(this.editorView.state.doc,s,this.editorView.dragging.slice);l!=null&&(s=l)}this.setCursor(s),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 ue={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:"'"},tn={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},jl=typeof navigator!="undefined"&&/Mac/.test(navigator.platform),_l=typeof navigator!="undefined"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(T=0;T<10;T++)ue[48+T]=ue[96+T]=String(T);var T;for(T=1;T<=24;T++)ue[T+111]="F"+T;var T;for(T=65;T<=90;T++)ue[T]=String.fromCharCode(T+32),tn[T]=String.fromCharCode(T);var T;for(en in ue)tn.hasOwnProperty(en)||(tn[en]=ue[en]);var en;function Ri(n){var e=jl&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||_l&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?tn:ue)[n.keyCode]||n.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 Gl(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,o,s;for(let l=0;l127)&&(o=ue[r.keyCode])&&o!=i){let l=e[_n(o,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var B=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},Ot=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},zi=null,me=function(n,e,t){let r=zi||(zi=document.createRange());return r.setEnd(n,t==null?n.nodeValue.length:t),r.setStart(n,e||0),r},Ke=function(n,e,t,r){return t&&(Bi(n,e,t,r,-1)||Bi(n,e,t,r,1))},Xl=/^(img|br|input|textarea|hr)$/i;function Bi(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:oe(n))){let o=n.parentNode;if(!o||o.nodeType!=1||br(n)||Xl.test(n.nodeName)||n.contentEditable=="false")return!1;e=B(n)+(i<0?0:1),n=o}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?oe(n):0}else return!1}}function oe(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Ql(n,e,t){for(let r=e==0,i=e==oe(n);r||i;){if(n==t)return!0;let o=B(n);if(n=n.parentNode,!n)return!1;r=r&&o==0,i=i&&o==oe(n)}}function br(n){let e;for(let t=n;t&&!(e=t.pmViewDesc);t=t.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==n||e.contentDOM==n)}var un=function(n){return n.focusNode&&Ke(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)};function Fe(n,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=n,t.key=t.code=e,t}function Zl(n){let e=n.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function ea(n,e,t){if(n.caretPositionFromPoint)try{let r=n.caretPositionFromPoint(e,t);if(r)return{node:r.offsetNode,offset:r.offset}}catch(r){}if(n.caretRangeFromPoint){let r=n.caretRangeFromPoint(e,t);if(r)return{node:r.startContainer,offset:r.startOffset}}}var se=typeof navigator!="undefined"?navigator:null,Fi=typeof document!="undefined"?document:null,we=se&&se.userAgent||"",er=/Edge\/(\d+)/.exec(we),mo=/MSIE \d/.exec(we),tr=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(we),W=!!(mo||tr||er),Ce=mo?document.documentMode:tr?+tr[1]:er?+er[1]:0,X=!W&&/gecko\/(\d+)/i.test(we);X&&+(/Firefox\/(\d+)/.exec(we)||[0,0])[1];var nr=!W&&/Chrome\/(\d+)/.exec(we),R=!!nr,ta=nr?+nr[1]:0,F=!W&&!!se&&/Apple Computer/.test(se.vendor),tt=F&&(/Mobile\/\w+/.test(we)||!!se&&se.maxTouchPoints>2),j=tt||(se?/Mac/.test(se.platform):!1),na=se?/Win/.test(se.platform):!1,Y=/Android \d/.test(we),Dt=!!Fi&&"webkitFontSmoothing"in Fi.documentElement.style,ra=Dt?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function ia(n){return{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function pe(n,e){return typeof n=="number"?n:n[e]}function oa(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function Vi(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,o=n.dom.ownerDocument;for(let s=t||n.dom;s;s=Ot(s)){if(s.nodeType!=1)continue;let l=s,a=l==o.body,c=a?ia(o):oa(l),f=0,h=0;if(e.topc.bottom-pe(r,"bottom")&&(h=e.bottom-e.top>c.bottom-c.top?e.top+pe(i,"top")-c.top:e.bottom-c.bottom+pe(i,"bottom")),e.leftc.right-pe(r,"right")&&(f=e.right-c.right+pe(i,"right")),f||h)if(a)o.defaultView.scrollBy(f,h);else{let d=l.scrollLeft,p=l.scrollTop;h&&(l.scrollTop+=h),f&&(l.scrollLeft+=f);let u=l.scrollLeft-d,m=l.scrollTop-p;e={left:e.left-u,top:e.top-m,right:e.right-u,bottom:e.bottom-m}}if(a||/^(fixed|sticky)$/.test(getComputedStyle(s).position))break}}function sa(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let o=(e.left+e.right)/2,s=t+1;s=t-20){r=l,i=a.top;break}}return{refDOM:r,refTop:i,stack:go(n.dom)}}function go(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=Ot(r));return e}function la({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;yo(t,r==0?0:r-e)}function yo(n,e){for(let t=0;t=l){s=Math.max(u.bottom,s),l=Math.min(u.top,l);let m=u.left>e.left?u.left-e.left:u.right=(u.left+u.right)/2?1:0));continue}}else u.top>e.top&&!a&&u.left<=e.left&&u.right>=e.left&&(a=f,c={left:Math.max(u.left,Math.min(u.right,e.left)),top:u.top});!t&&(e.left>=u.right&&e.top>=u.top||e.left>=u.left&&e.top>=u.bottom)&&(o=h+1)}}return!t&&a&&(t=a,i=c,r=0),t&&t.nodeType==3?ca(t,i):!t||r&&t.nodeType==1?{node:n,offset:o}:bo(t,i)}function ca(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i=(o.left+o.right)/2?1:0)}}return{node:n,offset:0}}function kr(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function fa(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(s.left+s.right)/2?1:-1}return n.docView.posFromDOM(r,i,o)}function da(n,e,t,r){let i=-1;for(let o=e,s=!1;o!=n.dom;){let l=n.docView.nearestDesc(o,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent&&!s||!l.contentDOM)){let a=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&!s&&(s=!0,a.left>r.left||a.top>r.top?i=l.posBefore:(a.right-1?i:n.docView.posFromDOM(e,t,-1)}function ko(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let c;Dt&&i&&r.nodeType==1&&(c=r.childNodes[i-1]).nodeType==1&&c.contentEditable=="false"&&c.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=da(n,r,i,e))}l==null&&(l=ha(n,s,e));let a=n.docView.nearestDesc(s,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function Li(n){return n.top=0&&i==r.nodeValue.length?(a--,f=1):t<0?a--:c++,St(xe(me(r,a,c),f),f<0)}if(!n.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&i&&(t<0||i==oe(r))){let a=r.childNodes[i-1];if(a.nodeType==1)return Yn(a.getBoundingClientRect(),!1)}if(o==null&&i=0)}if(o==null&&i&&(t<0||i==oe(r))){let a=r.childNodes[i-1],c=a.nodeType==3?me(a,oe(a)-(s?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(c)return St(xe(c,1),!1)}if(o==null&&i=0)}function St(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function Yn(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function So(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function ma(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return So(n,e,()=>{let{node:o}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(o,!0);if(!l)break;if(l.node.isBlock){o=l.contentDOM||l.dom;break}o=l.dom.parentNode}let s=xo(n,i.pos,1);for(let l=o.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=me(l,0,l.nodeValue.length).getClientRects();else continue;for(let c=0;cf.top+1&&(t=="up"?s.top-f.top>(f.bottom-s.top)*2:f.bottom-s.bottom>(s.bottom-f.top)*2))return!1}}return!0})}var ga=/[\u0590-\u08ac]/;function ya(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,l=n.domSelection();return!ga.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?o:s:So(n,e,()=>{let{focusNode:a,focusOffset:c,anchorNode:f,anchorOffset:h}=n.domSelectionRange(),d=l.caretBidiLevel;l.modify("move",t,"character");let p=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:u,focusOffset:m}=n.domSelectionRange(),g=u&&!p.contains(u.nodeType==1?u:u.parentNode)||a==u&&c==m;try{l.collapse(f,h),a&&(a!=f||c!=h)&&l.extend&&l.extend(a,c)}catch(k){}return d!=null&&(l.caretBidiLevel=d),g})}var Ji=null,Wi=null,qi=!1;function ba(n,e,t){return Ji==e&&Wi==t?qi:(Ji=e,Wi=t,qi=t=="up"||t=="down"?ma(n,e,t):ya(n,e,t))}var _=0,Ki=1,Ve=2,le=3,$e=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=_,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tB(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.nextSibling)break}}return(i==null?r>0:i)?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let o=this.getDesc(i),s;if(o&&(!t||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let o=this.getDesc(i);if(o)return o.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||s instanceof on){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof nn&&o.side>=0;r--);if(t<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&t&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,t):{node:this.contentDOM,offset:o?B(o.dom)+1:0}}else{let o,s=!0;for(;o=r=f&&t<=c-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,f);e=s;for(let h=l;h>0;h--){let d=this.children[h-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=B(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(c>t||l==this.children.length-1)){t=c;for(let f=l+1;fp&&st){let p=l;l=a,a=p}let d=document.createRange();d.setEnd(a.node,a.offset),d.setStart(l.node,l.offset),c.removeAllRanges(),c.addRange(d)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let r=0,i=0;i=r:er){let l=r+o.border,a=s-o.border;if(e>=l&&t<=a){this.dirty=e==r||t==s?Ve:Ki,e==l&&t==a&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=le:o.markDirty(e-l,t-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?Ve:le}r=s}this.dirty=Ve}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?Ve:Ki;t.dirty{if(!o)return i;if(o.parent)return o.parent.posBeforeChild(o)})),!t.type.spec.raw){if(s.nodeType!=1){let l=document.createElement("span");l.appendChild(s),s=l}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=t,this.widget=t,o=this}matchesWidget(e){return this.dirty==_&&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}},rr=class extends $e{constructor(e,t,r,i){super(e,[],t,null),this.textDOM=r,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}},nt=class n extends $e{constructor(e,t,r,i){super(e,[],r,i),this.mark=t}static create(e,t,r,i){let o=i.nodeViews[t.type.name],s=o&&o(t,i,r);return(!s||!s.dom)&&(s=ie.renderSpec(document,t.type.spec.toDOM(t,r))),new n(e,t,s.dom,s.contentDOM||s.dom)}parseRule(){return this.dirty&le||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=le&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=_){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(o=ar(o,0,e,r));for(let l=0;l{if(!a)return s;if(a.parent)return a.parent.posBeforeChild(a)},r,i),f=c&&c.dom,h=c&&c.contentDOM;if(t.isText){if(!f)f=document.createTextNode(t.text);else if(f.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else f||({dom:f,contentDOM:h}=ie.renderSpec(document,t.type.spec.toDOM(t)));!h&&!t.isText&&f.nodeName!="BR"&&(f.hasAttribute("contenteditable")||(f.contentEditable="false"),t.type.spec.draggable&&(f.draggable=!0));let d=f;return f=Oo(f,r,t),c?a=new ir(e,t,r,i,f,h||null,d,c,o,s+1):t.isText?new rn(e,t,r,i,f,d,o):new n(e,t,r,i,f,h||null,d,o,s+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>y.empty)}return e}matchesNode(e,t,r){return this.dirty==_&&e.eq(this.node)&&sr(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let r=this.node.inlineContent,i=t,o=e.composing?this.localCompositionInfo(e,t):null,s=o&&o.pos>-1?o:null,l=o&&o.pos<0,a=new lr(this,s&&s.node,e);Ma(this.node,this.innerDeco,(c,f,h)=>{c.spec.marks?a.syncToMarks(c.spec.marks,r,e):c.type.side>=0&&!h&&a.syncToMarks(f==this.node.childCount?O.none:this.node.child(f).marks,r,e),a.placeWidget(c,e,i)},(c,f,h,d)=>{a.syncToMarks(c.marks,r,e);let p;a.findNodeMatch(c,f,h,d)||l&&e.state.selection.from>i&&e.state.selection.to-1&&a.updateNodeAt(c,f,h,p,e)||a.updateNextNode(c,f,h,e,d,i)||a.addNode(c,f,h,e,i),i+=c.nodeSize}),a.syncToMarks([],r,e),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==Ve)&&(s&&this.protectLocalComposition(e,s),Mo(this.contentDOM,this.children,e),tt&&Ca(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof w)||rt+this.node.content.size)return null;let o=e.domSelectionRange(),s=Oa(o.focusNode,o.focusOffset);if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let l=s.nodeValue,a=wa(this.node.content,l,r-t,i-t);return a<0?null:{node:s,pos:a,text:l}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let o=t;for(;o.parentNode!=this.contentDOM;o=o.parentNode){for(;o.previousSibling;)o.parentNode.removeChild(o.previousSibling);for(;o.nextSibling;)o.parentNode.removeChild(o.nextSibling);o.pmViewDesc&&(o.pmViewDesc=void 0)}let s=new rr(this,o,t,i);e.input.compositionNodes.push(s),this.children=ar(this.children,r,r+i.length,e,s)}update(e,t,r,i){return this.dirty==le||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,r,i),!0)}updateInner(e,t,r,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=_}updateOuterDeco(e){if(sr(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Co(this.dom,this.nodeDOM,or(this.outerDeco,this.node,t),or(e,this.node,t)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable")}get domAtom(){return this.node.isAtom}};function $i(n,e,t,r,i){Oo(r,e,n);let o=new Oe(void 0,n,e,t,r,r,r,i,0);return o.contentDOM&&o.updateChildren(i,0),o}var rn=class n extends Oe{constructor(e,t,r,i,o,s,l){super(e,t,r,i,o,null,s,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,i){return this.dirty==le||this.dirty!=_&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=_||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=_,!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,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,r){let i=this.node.cut(e,t),o=document.createTextNode(i.text);return new n(this.parent,i,this.outerDeco,this.innerDeco,o,o,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=le)}get domAtom(){return!1}},on=class extends $e{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==_&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},ir=class extends Oe{constructor(e,t,r,i,o,s,l,a,c,f){super(e,t,r,i,o,s,l,c,f),this.spec=a}update(e,t,r,i){if(this.dirty==le)return!1;if(this.spec.update){let o=this.spec.update(e,t,r);return o&&this.updateInner(e,t,r,i),o}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,r,i){this.spec.setSelection?this.spec.setSelection(e,t,r):super.setSelection(e,t,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function Mo(n,e,t){let r=n.firstChild,i=!1;for(let o=0;o>1,s=Math.min(o,e.length);for(;i-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let a=nt.create(this.top,e[o],t,r);this.top.children.splice(this.index,0,a),this.top=a,this.changed=!0}this.index=0,o++}}findNodeMatch(e,t,r,i){let o=-1,s;if(i>=this.preMatch.index&&(s=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&s.matchesNode(e,t,r))o=this.top.children.indexOf(s,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let c=t.children[r-1];if(c instanceof nt)t=c,r=c.children.length;else{l=c,r--;break}}else{if(t==e)break e;r=t.parent.children.indexOf(t),t=t.parent}let a=l.node;if(a){if(a!=n.child(i-1))break;--i,o.set(l,i),s.push(l)}}return{index:i,matched:o,matches:s.reverse()}}function Sa(n,e){return n.type.side-e.type.side}function Ma(n,e,t,r){let i=e.locals(n),o=0;if(i.length==0){for(let c=0;co;)l.push(i[s++]);let u=o+d.nodeSize;if(d.isText){let g=u;s!g.inline):l.slice();r(d,m,e.forChild(o,d),p),o=u}}function Ca(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function Oa(n,e){for(;;){if(n.nodeType==3)return n;if(n.nodeType==1&&e>0){if(n.childNodes.length>e&&n.childNodes[e].nodeType==3)return n.childNodes[e];n=n.childNodes[e-1],e=oe(n)}else if(n.nodeType==1&&e=t){if(o>=r&&a.slice(r-e.length-l,r-l)==e)return r-e.length;let c=l=0&&c+e.length+l>=t)return l+c;if(t==r&&a.length>=r+e.length-l&&a.slice(r-l,r-l+e.length)==e)return r}}return-1}function ar(n,e,t,r,i){let o=[];for(let s=0,l=0;s=t||f<=e?o.push(a):(ct&&o.push(a.slice(t-c,a.size,r)))}return o}function xr(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),o=i&&i.size==0,s=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(s<0)return null;let l=r.resolve(s),a,c;if(un(t)){for(a=l;i&&!i.node;)i=i.parent;let f=i.node;if(i&&f.isAtom&&x.isSelectable(f)&&i.parent&&!(f.isInline&&Ql(t.focusNode,t.focusOffset,i.dom))){let h=i.posBefore;c=new x(s==h?l:r.resolve(h))}}else{let f=n.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(f<0)return null;a=r.resolve(f)}if(!c){let f=e=="pointer"||n.state.selection.head{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!wo(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function Ta(n){let e=n.domSelection(),t=document.createRange(),r=n.cursorWrapper.dom,i=r.nodeName=="IMG";i?t.setEnd(r.parentNode,B(r)+1):t.setEnd(r,0),t.collapse(!1),e.removeAllRanges(),e.addRange(t),!i&&!n.state.selection.visible&&W&&Ce<=11&&(r.disabled=!0,r.disabled=!1)}function No(n,e){if(e instanceof x){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(Gi(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else Gi(n)}function Gi(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function Sr(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||w.between(e,t,r)}function Yi(n){return n.editable&&!n.hasFocus()?!1:To(n)}function To(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch(t){return!1}}function Da(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return Ke(e.node,e.offset,t.anchorNode,t.anchorOffset)}function cr(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),o=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return o&&S.findFrom(o,e)}function Se(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function Xi(n,e,t){let r=n.state.selection;if(r instanceof w)if(t.indexOf("s")>-1){let{$head:i}=r,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!o||o.isText||!o.isLeaf)return!1;let s=n.state.doc.resolve(i.pos+o.nodeSize*(e<0?-1:1));return Se(n,new w(r.$anchor,s))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=cr(n.state,e);return i&&i instanceof x?Se(n,i):!1}else if(!(j&&t.indexOf("m")>-1)){let i=r.$head,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,s;if(!o||o.isText)return!1;let l=e<0?i.pos-o.nodeSize:i.pos;return o.isAtom||(s=n.docView.descAt(l))&&!s.contentDOM?x.isSelectable(o)?Se(n,new x(e<0?n.state.doc.resolve(i.pos-o.nodeSize):i)):Dt?Se(n,new w(n.state.doc.resolve(e<0?l:l+o.nodeSize))):!1:!1}}else return!1;else{if(r instanceof x&&r.node.isInline)return Se(n,new w(e>0?r.$to:r.$from));{let i=cr(n.state,e);return i?Se(n,i):!1}}}function sn(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Ct(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function Qe(n,e){return e<0?Ea(n):Ia(n)}function Ea(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,o,s=!1;for(X&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(Ct(l,-1))i=t,o=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(Do(t))break;{let l=t.previousSibling;for(;l&&Ct(l,-1);)i=t.parentNode,o=B(l),l=l.previousSibling;if(l)t=l,r=sn(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}s?fr(n,t,r):i&&fr(n,i,o)}function Ia(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=sn(t),o,s;for(;;)if(r{n.state==i&&ge(n)},50)}function Qi(n,e){let t=n.state.doc.resolve(e);if(!(R||na)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let o=n.coordsAtPos(e-1),s=(o.top+o.bottom)/2;if(s>i.top&&s1)return o.lefti.top&&s1)return o.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function Zi(n,e,t){let r=n.state.selection;if(r instanceof w&&!r.empty||t.indexOf("s")>-1||j&&t.indexOf("m")>-1)return!1;let{$from:i,$to:o}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let s=cr(n.state,e);if(s&&s instanceof x)return Se(n,s)}if(!i.parent.inlineContent){let s=e<0?i:o,l=r instanceof $?S.near(s,e):S.findFrom(s,e);return l?Se(n,l):!1}return!1}function eo(n,e){if(!(n.state.selection instanceof w))return!0;let{$head:t,$anchor:r,empty:i}=n.state.selection;if(!t.sameParent(r))return!0;if(!i)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let o=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(o&&!o.isText){let s=n.state.tr;return e<0?s.delete(t.pos-o.nodeSize,t.pos):s.delete(t.pos,t.pos+o.nodeSize),n.dispatch(s),!0}return!1}function to(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function Pa(n){if(!F||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;to(n,r,"true"),setTimeout(()=>to(n,r,"false"),20)}return!1}function Ra(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function za(n,e){let t=e.keyCode,r=Ra(e);if(t==8||j&&t==72&&r=="c")return eo(n,-1)||Qe(n,-1);if(t==46&&!e.shiftKey||j&&t==68&&r=="c")return eo(n,1)||Qe(n,1);if(t==13||t==27)return!0;if(t==37||j&&t==66&&r=="c"){let i=t==37?Qi(n,n.state.selection.from)=="ltr"?-1:1:-1;return Xi(n,i,r)||Qe(n,i)}else if(t==39||j&&t==70&&r=="c"){let i=t==39?Qi(n,n.state.selection.from)=="ltr"?1:-1:1;return Xi(n,i,r)||Qe(n,i)}else{if(t==38||j&&t==80&&r=="c")return Zi(n,-1,r)||Qe(n,-1);if(t==40||j&&t==78&&r=="c")return Pa(n)||Zi(n,1,r)||Qe(n,1);if(r==(j?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Eo(n,e){n.someProp("transformCopied",p=>{e=p(e,n)});let t=[],{content:r,openStart:i,openEnd:o}=e;for(;i>1&&o>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,o--;let p=r.firstChild;t.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),r=p.content}let s=n.someProp("clipboardSerializer")||ie.fromSchema(n.state.schema),l=zo(),a=l.createElement("div");a.appendChild(s.serializeFragment(r,{document:l}));let c=a.firstChild,f,h=0;for(;c&&c.nodeType==1&&(f=Ro[c.nodeName.toLowerCase()]);){for(let p=f.length-1;p>=0;p--){let u=l.createElement(f[p]);for(;a.firstChild;)u.appendChild(a.firstChild);a.appendChild(u),h++}c=a.firstChild}c&&c.nodeType==1&&c.setAttribute("data-pm-slice",`${i} ${o}${h?` -${h}`:""} ${JSON.stringify(t)}`);let d=n.someProp("clipboardTextSerializer",p=>p(e,n))||e.content.textBetween(0,e.content.size,` +var DjangoProseEditor=(()=>{var Rt=Object.defineProperty;var Bs=Object.getOwnPropertyDescriptor;var Fs=Object.getOwnPropertyNames,Br=Object.getOwnPropertySymbols;var Vr=Object.prototype.hasOwnProperty,Vs=Object.prototype.propertyIsEnumerable;var Fr=(n,e,t)=>e in n?Rt(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Sn=(n,e)=>{for(var t in e||(e={}))Vr.call(e,t)&&Fr(n,t,e[t]);if(Br)for(var t of Br(e))Vs.call(e,t)&&Fr(n,t,e[t]);return n};var Ls=(n,e)=>{for(var t in e)Rt(n,t,{get:e[t],enumerable:!0})},Js=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Fs(e))!Vr.call(n,i)&&i!==t&&Rt(n,i,{get:()=>e[i],enumerable:!(r=Bs(e,i))||r.enumerable});return n};var Ws=n=>Js(Rt({},"__esModule",{value:!0}),n);var Vf={};Ls(Vf,{createEditor:()=>Rs});function v(n){this.content=n}v.prototype={constructor:v,find:function(n){for(var e=0;e>1}};v.from=function(n){if(n instanceof v)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new v(e)};var Mn=v;function $r(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),o=e.child(r);if(i==o){t+=i.nodeSize;continue}if(!i.sameMarkup(o))return t;if(i.isText&&i.text!=o.text){for(let s=0;i.text[s]==o.text[s];s++)t++;return t}if(i.content.size||o.content.size){let s=$r(i.content,o.content,t+1);if(s!=null)return s}t+=i.nodeSize}}function jr(n,e,t,r){for(let i=n.childCount,o=e.childCount;;){if(i==0||o==0)return i==o?null:{a:t,b:r};let s=n.child(--i),l=e.child(--o),a=s.nodeSize;if(s==l){t-=a,r-=a;continue}if(!s.sameMarkup(l))return{a:t,b:r};if(s.isText&&s.text!=l.text){let c=0,f=Math.min(s.text.length,l.text.length);for(;ce&&r(a,i+l,o||null,s)!==!1&&a.content.size){let f=l+1;a.nodesBetween(Math.max(0,e-f),Math.min(a.content.size,t-f),r,i+f)}l=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let o="",s=!0;return this.nodesBetween(e,t,(l,a)=>{let c=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&&c||l.isTextblock)&&r&&(s?s=!1:o+=r),o+=c},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),o=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),o=1);oe)for(let o=0,s=0;se&&((st)&&(l.isText?l=l.cut(Math.max(0,e-s),Math.min(l.text.length,t-s)):l=l.cut(Math.max(0,e-s-1),Math.min(l.content.size,t-s-1))),r.push(l),i+=l.nodeSize),s=a}return new n(r,i)}cutByIndex(e,t){return e==t?n.empty:e==0&&t==this.content.length?this:new n(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),o=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new n(i,o)}addToStart(e){return new n([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new n(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 r=0,i=0;;r++){let o=this.child(r),s=i+o.nodeSize;if(s>=e)return s==e||t>0?zt(r+1,s):zt(r,i);i=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return n.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new n(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return n.empty;let t,r=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(o)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}};O.none=[];var Ie=class extends Error{},b=class n{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=Ur(this.content,e+this.openStart,t);return r&&new n(r,this.openStart,this.openEnd)}removeBetween(e,t){return new n(_r(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 n.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new n(y.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let o=e.firstChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.lastChild)i++;return new n(e,r,i)}};b.empty=new b(y.empty,0,0);function _r(n,e,t){let{index:r,offset:i}=n.findIndex(e),o=n.maybeChild(r),{index:s,offset:l}=n.findIndex(t);if(i==e||o.isText){if(l!=t&&!n.child(s).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=s)throw new RangeError("Removing non-flat range");return n.replaceChild(r,o.copy(_r(o.content,e-i-1,t-i-1)))}function Ur(n,e,t,r){let{index:i,offset:o}=n.findIndex(e),s=n.maybeChild(i);if(o==e||s.isText)return r&&!r.canReplace(i,i,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=Ur(s.content,e-o-1,t);return l&&n.replaceChild(i,s.copy(l))}function qs(n,e,t){if(t.openStart>n.depth)throw new Ie("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Ie("Inconsistent open depths");return Gr(n,e,t,0)}function Gr(n,e,t,r){let i=n.index(r),o=n.node(r);if(i==e.index(r)&&r=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function lt(n,e,t,r){let i=(e||n).node(t),o=0,s=e?e.index(t):i.childCount;n&&(o=n.index(t),n.depth>t?o++:n.textOffset&&(De(n.nodeAfter,r),o++));for(let l=o;li&&Tn(n,e,i+1),s=r.depth>i&&Tn(t,r,i+1),l=[];return lt(null,n,i,l),o&&s&&e.index(i)==t.index(i)?(Yr(o,s),De(Ee(o,Xr(n,e,t,r,i+1)),l)):(o&&De(Ee(o,Ft(n,e,i+1)),l),lt(e,t,i,l),s&&De(Ee(s,Ft(t,r,i+1)),l)),lt(r,null,i,l),new y(l)}function Ft(n,e,t){let r=[];if(lt(null,n,t,r),n.depth>t){let i=Tn(n,e,t+1);De(Ee(i,Ft(n,e,t+1)),r)}return lt(e,null,t,r),new y(r)}function Ks(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let o=t-1;o>=0;o--)i=e.node(o).copy(y.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}var Vt=class n{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,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 r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):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 r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let o=0;o0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new Ae(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,o=t;for(let s=e;;){let{index:l,offset:a}=s.content.findIndex(o),c=o-a;if(r.push(s,l,i+a),!c||(s=s.child(l),s.isText))break;o=c-1,i+=a+1}return new n(t,r,o)}static resolveCached(e,t){for(let i=0;ie&&this.nodesBetween(e,t,o=>(r.isInSet(o.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),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,r=y.empty,i=0,o=r.childCount){let s=this.contentMatchAt(e).matchFragment(r,i,o),l=s&&s.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 r=null;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=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,r)}let i=y.fromJSON(e,t.content);return e.nodeType(t.type).create(t.attrs,i,r)}};re.prototype.text=void 0;var Dn=class n extends re{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):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 n(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new n(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(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}var ve=class n{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new En(e,t);if(r.next==null)return n.empty;let i=Zr(r);r.next&&r.err("Unexpected trailing text");let o=Qs(Xs(i));return Zs(o,r),o}matchType(e){for(let t=0;tc.createAndFill()));for(let c=0;c=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(r){e.push(r);for(let i=0;i{let o=i+(r.validEnd?"*":" ")+" ";for(let s=0;s"+e.indexOf(r.next[s].next);return o}).join(` +`)}};ve.empty=new ve(!0);var En=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(n){let e=[];do e.push(js(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function js(n){let e=[];do e.push(_s(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function _s(n){let e=Ys(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=Us(n,e);else break;return e}function Lr(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function Us(n,e){let t=Lr(n),r=t;return n.eat(",")&&(n.next!="}"?r=Lr(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function Gs(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let o in t){let s=t[o];s.groups.indexOf(e)>-1&&i.push(s)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function Ys(n){if(n.eat("(")){let e=Zr(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=Gs(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Xs(n){let e=[[]];return i(o(n,0),t()),e;function t(){return e.push([])-1}function r(s,l,a){let c={term:a,to:l};return e[s].push(c),c}function i(s,l){s.forEach(a=>a.to=l)}function o(s,l){if(s.type=="choice")return s.exprs.reduce((a,c)=>a.concat(o(c,l)),[]);if(s.type=="seq")for(let a=0;;a++){let c=o(s.exprs[a],l);if(a==s.exprs.length-1)return c;i(c,l=t())}else if(s.type=="star"){let a=t();return r(l,a),i(o(s.expr,a),a),[r(a)]}else if(s.type=="plus"){let a=t();return i(o(s.expr,l),a),i(o(s.expr,a),a),[r(a)]}else{if(s.type=="opt")return[r(l)].concat(o(s.expr,l));if(s.type=="range"){let a=l;for(let c=0;c{n[s].forEach(({term:l,to:a})=>{if(!l)return;let c;for(let f=0;f{c||i.push([l,c=[]]),c.indexOf(f)==-1&&c.push(f)})})});let o=e[r.join(",")]=new ve(r.indexOf(n.length-1)>-1);for(let s=0;s-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[o]=new n(o,t,s));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let o in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}},In=class{constructor(e){this.hasDefault=Object.prototype.hasOwnProperty.call(e,"default"),this.default=e.default}get isRequired(){return!this.hasDefault}},ct=class n{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=ri(i.attrs),this.excluded=null;let o=ti(this.attrs);this.instance=o?new O(this,o):null}create(e=null){return!e&&this.instance?this.instance:new O(this,ni(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((o,s)=>r[o]=new n(o,i++,t,s)),r}removeFromSet(e){for(var t=0;t-1}},Pe=class{constructor(e){this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=Mn.from(e.nodes),t.marks=Mn.from(e.marks||{}),this.nodes=Lt.compile(this.spec.nodes,this),this.marks=ct.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let o=this.nodes[i],s=o.spec.content||"",l=o.spec.marks;o.contentMatch=r[s]||(r[s]=ve.parse(s,this.nodes)),o.inlineContent=o.contentMatch.inlineContent,o.markSet=l=="_"?null:l?Wr(this,l.split(" ")):l==""||!o.inlineContent?[]:null}for(let i in this.marks){let o=this.marks[i],s=o.spec.excludes;o.excluded=s==null?[o]:s==""?[]:Wr(this,s.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Lt){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,r,i)}text(e,t){let r=this.nodes.text;return new Dn(r,r.defaultAttrs,e,O.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return re.fromJSON(this,e)}markFromJSON(e){return O.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function Wr(n,e){let t=[];for(let r=0;r-1)&&t.push(s=a)}if(!s)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}var Re=class n{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[],t.forEach(r=>{r.tag?this.tags.push(r):r.style&&this.styles.push(r)}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let i=e.nodes[r.node];return i.contentMatch.matchType(i)})}parse(e,t={}){let r=new qt(this,t,!1);return r.addAll(e,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new qt(this,t,!0);return r.addAll(e,t.from,t.to),b.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(s.getAttrs){let a=s.getAttrs(t);if(a===!1)continue;s.attrs=a||void 0}return s}}}static schemaRules(e){let t=[];function r(i){let o=i.priority==null?50:i.priority,s=0;for(;s{r(s=Kr(s)),s.mark||s.ignore||s.clearMark||(s.mark=i)})}for(let i in e.nodes){let o=e.nodes[i].spec.parseDOM;o&&o.forEach(s=>{r(s=Kr(s)),s.node||s.ignore||s.mark||(s.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new n(e,n.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},el={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},oi={ol:!0,ul:!0},Jt=1,Wt=2,at=4;function qr(n,e,t){return e!=null?(e?Jt:0)|(e==="full"?Wt:0):n&&n.whitespace=="pre"?Jt|Wt:t&~at}var je=class{constructor(e,t,r,i,o,s,l){this.type=e,this.attrs=t,this.marks=r,this.pendingMarks=i,this.solid=o,this.options=l,this.content=[],this.activeMarks=O.none,this.stashMarks=[],this.match=s||(l&at?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(y.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Jt)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-i[0].length))}}let t=y.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(y.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,r=this.pendingMarks;tthis.addAll(e)),s&&this.sync(l),this.needsBlock=a}else this.withStyleRules(e,()=>{this.addElementByRule(e,o,o.consuming===!1?i:void 0)})}leafFallback(e){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` +`))}ignoreFallback(e){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(e){let t=O.none,r=O.none;for(let i=0;i{s.clearMark(l)&&(r=l.addToSet(r))}):t=this.parser.schema.marks[s.mark].create(s.attrs).addToSet(t),s.consuming===!1)o=s;else break}return[t,r]}addElementByRule(e,t,r){let i,o,s;t.node?(o=this.parser.schema.nodes[t.node],o.isLeaf?this.insertNode(o.create(t.attrs))||this.leafFallback(e):i=this.enter(o,t.attrs||null,t.preserveWhitespace)):(s=this.parser.schema.marks[t.mark].create(t.attrs),this.addPendingMark(s));let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(r)this.addElement(e,r);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--,s&&this.removePendingMark(s,l)}addAll(e,t,r){let i=t||0;for(let o=t?e.childNodes[t]:e.firstChild,s=r==null?null:e.childNodes[r];o!=s;o=o.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(o);this.findAtPoint(e,i)}findPlace(e){let t,r;for(let i=this.open;i>=0;i--){let o=this.nodes[i],s=o.findWrapping(e);if(s&&(!t||t.length>s.length)&&(t=s,r=o,!s.length)||o.solid)break}if(!t)return!1;this.sync(r);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 r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(i?0:1),s=(l,a)=>{for(;l>=0;l--){let c=t[l];if(c==""){if(l==t.length-1||l==0)continue;for(;a>=o;a--)if(s(l-1,a))return!0;return!1}else{let f=a>0||a==0&&i?this.nodes[a].type:r&&a>=o?r.node(a-o).type:null;if(!f||f.name!=c&&f.groups.indexOf(c)==-1)return!1;a--}}return!0};return s(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}addPendingMark(e){let t=ol(e,this.top.pendingMarks);t&&this.top.stashMarks.push(t),this.top.pendingMarks=e.addToSet(this.top.pendingMarks)}removePendingMark(e,t){for(let r=this.open;r>=0;r--){let i=this.nodes[r];if(i.pendingMarks.lastIndexOf(e)>-1)i.pendingMarks=e.removeFromSet(i.pendingMarks);else{i.activeMarks=e.removeFromSet(i.activeMarks);let s=i.popFromStashMark(e);s&&i.type&&i.type.allowsMarkType(s.type)&&(i.activeMarks=s.addToSet(i.activeMarks))}if(i==t)break}}};function tl(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&oi.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function nl(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function rl(n){let e=/\s*([\w-]+)\s*:\s*([^;]+)/g,t,r=[];for(;t=e.exec(n);)r.push(t[1],t[2].trim());return r}function Kr(n){let e={};for(let t in n)e[t]=n[t];return e}function il(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let o=[],s=l=>{o.push(l);for(let a=0;a{if(o.length||s.marks.length){let l=0,a=0;for(;l=0;i--){let o=this.serializeMark(e.marks[i],e.isInline,t);o&&((o.contentDOM||o.dom).appendChild(r),r=o.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&n.renderSpec(Nn(r),i(e,t))}static renderSpec(e,t,r=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],o=i.indexOf(" ");o>0&&(r=i.slice(0,o),i=i.slice(o+1));let s,l=r?e.createElementNS(r,i):e.createElement(i),a=t[1],c=1;if(a&&typeof a=="object"&&a.nodeType==null&&!Array.isArray(a)){c=2;for(let f in a)if(a[f]!=null){let h=f.indexOf(" ");h>0?l.setAttributeNS(f.slice(0,h),f.slice(h+1),a[f]):l.setAttribute(f,a[f])}}for(let f=c;fc)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}else{let{dom:d,contentDOM:p}=n.renderSpec(e,h,r);if(l.appendChild(d),p){if(s)throw new RangeError("Multiple content holes");s=p}}}return{dom:l,contentDOM:s}}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new n(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=Hr(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return Hr(e.marks)}};function Hr(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function Nn(n){return n.document||window.document}var ai=65535,ci=Math.pow(2,16);function sl(n,e){return n+e*ci}function si(n){return n&ai}function ll(n){return(n-(n&ai))/ci}var fi=1,hi=2,Kt=4,di=8,dt=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&di)>0}get deletedBefore(){return(this.delInfo&(fi|Kt))>0}get deletedAfter(){return(this.delInfo&(hi|Kt))>0}get deletedAcross(){return(this.delInfo&Kt)>0}},he=class n{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&n.empty)return n.empty}recover(e){let t=0,r=si(e);if(!this.inverted)for(let i=0;ie)break;let c=this.ranges[l+o],f=this.ranges[l+s],h=a+c;if(e<=h){let d=c?e==a?-1:e==h?1:t:t,p=a+i+(d<0?0:f);if(r)return p;let u=e==(t<0?a:h)?null:sl(l/3,e-a),m=e==a?hi:e==h?fi:Kt;return(t<0?e!=a:e!=h)&&(m|=di),new dt(p,m,u)}i+=f-c}return r?e+i:new dt(e+i,0,null)}touches(e,t){let r=0,i=si(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let c=this.ranges[l+o],f=a+c;if(e<=f&&l==i*3)return!0;r+=this.ranges[l+s]-c}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new n;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;ro&&a!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return I.fromReplace(e,this.from,this.to,o)}invert(){return new ze(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(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 n(t.from,t.to,e.markFromJSON(t.mark))}};D.jsonID("addMark",pt);var ze=class n extends D{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new b(Bn(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return I.fromReplace(e,this.from,this.to,r)}invert(){return new pt(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(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 n(t.from,t.to,e.markFromJSON(t.mark))}};D.jsonID("removeMark",ze);var mt=class n extends D{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return I.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return I.fromReplace(e,this.pos,this.pos+1,new b(y.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new n(t.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,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 n(t.from,t.to,t.gapFrom,t.gapTo,b.fromJSON(e,t.slice),t.insert,!!t.structure)}};D.jsonID("replaceAround",E);function Rn(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function al(n,e,t,r){let i=[],o=[],s,l;n.doc.nodesBetween(e,t,(a,c,f)=>{if(!a.isInline)return;let h=a.marks;if(!r.isInSet(h)&&f.type.allowsMarkType(r.type)){let d=Math.max(c,e),p=Math.min(c+a.nodeSize,t),u=r.addToSet(h);for(let m=0;mn.step(a)),o.forEach(a=>n.step(a))}function cl(n,e,t,r){let i=[],o=0;n.doc.nodesBetween(e,t,(s,l)=>{if(!s.isInline)return;o++;let a=null;if(r instanceof ct){let c=s.marks,f;for(;f=r.isInSet(c);)(a||(a=[])).push(f),c=f.removeFromSet(c)}else r?r.isInSet(s.marks)&&(a=[r]):a=s.marks;if(a&&a.length){let c=Math.min(l+s.nodeSize,t);for(let f=0;fn.step(new ze(s.from,s.to,s.style)))}function fl(n,e,t,r=t.contentMatch){let i=n.doc.nodeAt(e),o=[],s=e+1;for(let l=0;l=0;l--)n.step(o[l])}function hl(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function Ue(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),o=n.$from.index(r),s=n.$to.indexAfter(r);if(rt;u--)m||r.index(u)>0?(m=!0,f=y.from(r.node(u).copy(f)),h++):a--;let d=y.empty,p=0;for(let u=o,m=!1;u>t;u--)m||i.after(u+1)=0;s--){if(r.size){let l=t[s].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=y.from(t[s].type.create(t[s].attrs,r))}let i=e.start,o=e.end;n.step(new E(i,o,i,o,new b(r,0,0),t.length,!0))}function gl(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=n.steps.length;n.doc.nodesBetween(e,t,(s,l)=>{if(s.isTextblock&&!s.hasMarkup(r,i)&&yl(n.doc,n.mapping.slice(o).map(l),r)){n.clearIncompatible(n.mapping.slice(o).map(l,1),r);let a=n.mapping.slice(o),c=a.map(l,1),f=a.map(l+s.nodeSize,1);return n.step(new E(c,f,c+1,f-1,new b(y.from(r.create(i,null,s.marks)),0,0),1,!0)),!1}})}function yl(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function bl(n,e,t,r,i){let o=n.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");t||(t=o.type);let s=t.create(r,null,i||o.marks);if(o.isLeaf)return n.replaceWith(e,e+o.nodeSize,s);if(!t.validContent(o.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new E(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new b(y.from(s),0,0),1,!0))}function ke(n,e,t=1,r){let i=n.resolve(e),o=i.depth-t,s=r&&r[r.length-1]||i.parent;if(o<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!s.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let c=i.depth-1,f=t-2;c>o;c--,f--){let h=i.node(c),d=i.index(c);if(h.type.spec.isolating)return!1;let p=h.content.cutByIndex(d,h.childCount),u=r&&r[f+1];u&&(p=p.replaceChild(0,u.type.create(u.attrs)));let m=r&&r[f]||h;if(!h.canReplace(d+1,h.childCount)||!m.type.validContent(p))return!1}let l=i.indexAfter(o),a=r&&r[0];return i.node(o).canReplaceWith(l,l,a?a.type:i.node(o+1).type)}function kl(n,e,t=1,r){let i=n.doc.resolve(e),o=y.empty,s=y.empty;for(let l=i.depth,a=i.depth-t,c=t-1;l>a;l--,c--){o=y.from(i.node(l).copy(o));let f=r&&r[c];s=y.from(f?f.type.create(f.attrs,s):i.node(l).copy(s))}n.step(new K(e,e,new b(o.append(s),t,t),!0))}function yt(n,e){let t=n.resolve(e),r=t.index();return xl(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function xl(n,e){return!!(n&&e&&!n.isLeaf&&n.canAppend(e))}function Sl(n,e,t){let r=new K(e-t,e+t,b.empty,!0);n.step(r)}function Ml(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let o=r.index(i);if(r.node(i).canReplaceWith(o,o,t))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,t))return r.after(i+1);if(o=0;s--){let l=s==r.depth?0:r.pos<=(r.start(s+1)+r.end(s+1))/2?-1:1,a=r.index(s)+(l>0?1:0),c=r.node(s),f=!1;if(o==1)f=c.canReplace(a,a,i);else{let h=c.contentMatchAt(a).findWrapping(i.firstChild.type);f=h&&c.canReplaceWith(a,a,h[0])}if(f)return l==0?r.pos:l<0?r.before(s+1):r.after(s+1)}return null}function Gt(n,e,t=e,r=b.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),o=n.resolve(t);return ui(i,o,r)?new K(e,t,r):new zn(i,o,r).fit()}function ui(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}var zn=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=y.empty;for(let i=0;i<=e.depth;i++){let o=e.node(i);this.frontier.push({type:o.type,match:o.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=y.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let c=this.findFittable();c?this.placeNodes(c):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let a=new b(o,s,l);return e>-1?new E(r.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||r.pos!=this.$to.pos?new K(r.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),o.type.spec.isolating&&i<=r){e=r;break}t=o.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=vn(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:c}=this.frontier[l],f,h=null;if(t==1&&(s?c.matchType(s.type)||(h=c.fillBefore(y.from(s),!1)):o&&a.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:h};if(t==2&&s&&(f=c.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:f};if(o&&c.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=vn(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new b(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=vn(e,t);if(i.childCount<=1&&t>0){let o=e.size-t<=t+i.size;this.unplaced=new b(ft(e,t-1,1),t-1,o?t-1:r)}else this.unplaced=new b(ft(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:o}){for(;this.depth>t;)this.closeFrontierNode();if(o)for(let m=0;m1||a==0||m.content.size)&&(h=g,f.push(pi(m.mark(d.allowedMarks(m.marks)),c==1?a:0,c==l.childCount?p:-1)))}let u=c==l.childCount;u||(p=-1),this.placed=ht(this.placed,t,y.from(f)),this.frontier[t].match=h,u&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],o=t=0;l--){let{match:a,type:c}=this.frontier[l],f=Pn(e,l,c,a,!0);if(!f||f.childCount)continue e}return{depth:t,fit:s,move:o?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=ht(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=ht(this.placed,this.depth,y.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(y.empty,!0);t.childCount&&(this.placed=ht(this.placed,this.frontier.length,t))}};function ft(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(ft(n.firstChild.content,e-1,t)))}function ht(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(ht(n.lastChild.content,e-1,t)))}function vn(n,e){for(let t=0;t1&&(r=r.replaceChild(0,pi(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(y.empty,!0)))),n.copy(r)}function Pn(n,e,t,r,i){let o=n.node(e),s=i?n.indexAfter(e):n.index(e);if(s==o.childCount&&!t.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!Cl(t,o.content,s)?l:null}function Cl(n,e,t){for(let r=t;r0;d--,p--){let u=i.node(d).type.spec;if(u.defining||u.definingAsContext||u.isolating)break;s.indexOf(d)>-1?l=d:i.before(d)==p&&s.splice(1,0,-d)}let a=s.indexOf(l),c=[],f=r.openStart;for(let d=r.content,p=0;;p++){let u=d.firstChild;if(c.push(u),p==r.openStart)break;d=u.content}for(let d=f-1;d>=0;d--){let p=c[d],u=Ol(p.type);if(u&&!p.sameMarkup(i.node(Math.abs(l)-1)))f=d;else if(u||!p.type.isTextblock)break}for(let d=r.openStart;d>=0;d--){let p=(d+f+1)%(r.openStart+1),u=c[p];if(u)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>h));d--){let p=s[d];p<0||(e=i.before(p),t=o.after(p))}}function mi(n,e,t,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(n).append(n);n=s.append(o.matchFragment(s).fillBefore(y.empty,!0))}return n}function Nl(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Ml(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new b(y.from(r),0,0))}function Tl(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),o=gi(r,i);for(let s=0;s0&&(a||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&t>r.end(s)&&i.end(s)-t!=i.depth-s)return n.delete(r.before(s),t);n.delete(e,t)}function gi(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let o=n.start(i);if(oe.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&t.push(i)}return t}var Ht=class n extends D{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return I.fail("No node at attribute step's position");let r=Object.create(null);for(let o in t.attrs)r[o]=t.attrs[o];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return I.fromReplace(e,this.pos,this.pos+1,new b(y.from(i),0,t.isLeaf?0:1))}getMap(){return he.empty}invert(e){return new n(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 n(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 n(t.pos,t.attr,t.value)}};D.jsonID("attr",Ht);var $t=class n extends D{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 r=e.type.create(t,e.content,e.marks);return I.ok(r)}getMap(){return he.empty}invert(e){return new n(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 n(t.attr,t.value)}};D.jsonID("docAttr",$t);var _e=class extends Error{};_e=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};_e.prototype=Object.create(Error.prototype);_e.prototype.constructor=_e;_e.prototype.name="TransformError";var jt=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new ut}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new _e(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,r=b.empty){let i=Gt(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new b(y.from(r),0,0))}delete(e,t){return this.replace(e,t,b.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return wl(this,e,t,r),this}replaceRangeWith(e,t,r){return Nl(this,e,t,r),this}deleteRange(e,t){return Tl(this,e,t),this}lift(e,t){return dl(this,e,t),this}join(e,t=1){return Sl(this,e,t),this}wrap(e,t){return ml(this,e,t),this}setBlockType(e,t=e,r,i=null){return gl(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return bl(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new Ht(e,t,r)),this}setDocAttribute(e,t){return this.step(new $t(e,t)),this}addNodeMark(e,t){return this.step(new mt(e,t)),this}removeNodeMark(e,t){if(!(t instanceof O)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t=t.isInSet(r.marks),!t)return this}return this.step(new gt(e,t)),this}split(e,t=1,r){return kl(this,e,t,r),this}addMark(e,t,r){return al(this,e,t,r),this}removeMark(e,t,r){return cl(this,e,t,r),this}clearIncompatible(e,t,r){return fl(this,e,t,r),this}};var Fn=Object.create(null),S=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new Ln(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;o--){let s=t<0?Ge(e.node(0),e.node(o),e.before(o+1),e.index(o),t,r):Ge(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,t,r);if(s)return s}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new H(e.node(0))}static atStart(e){return Ge(e,e,0,0,1)||new H(e)}static atEnd(e){return Ge(e,e,e.content.size,e.childCount,-1)||new H(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=Fn[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in Fn)throw new RangeError("Duplicate use of selection JSON ID "+e);return Fn[e]=t,t.prototype.jsonID=e,t}getBookmark(){return w.between(this.$anchor,this.$head).getBookmark()}};S.prototype.visible=!0;var Ln=class{constructor(e,t){this.$from=e,this.$to=t}},yi=!1;function bi(n){!yi&&!n.parent.inlineContent&&(yi=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}var w=class n 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 r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return S.near(r);let i=e.resolve(t.map(this.anchor));return new n(i.parent.inlineContent?i:r,r)}replace(e,t=b.empty){if(super.replace(e,t),t==b.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof n&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Xt(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 n(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let o=S.findFrom(t,r,!0)||S.findFrom(t,-r,!0);if(o)t=o.$head;else return S.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(S.findFrom(e,-r,!0)||S.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?s=0;s+=i){let l=e.child(s);if(l.isAtom){if(!o&&x.isSelectable(l))return x.create(n,t-(i<0?l.nodeSize:0))}else{let a=Ge(n,l,t+i,i<0?l.childCount:0,i,o);if(a)return a}t+=l.nodeSize*i}return null}function ki(n,e,t){let r=n.steps.length-1;if(r{s==null&&(s=f)}),n.setSelection(S.near(n.doc.resolve(s),t))}var xi=1,Yt=2,Si=4,Wn=class extends jt{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|=Yt,this}ensureMarks(e){return O.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&Yt)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Yt,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||O.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r==null?t:r,!e)return this.deleteRange(t,r);let o=this.storedMarks;if(!o){let s=this.doc.resolve(t);o=r==t?s.marks():s.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,o)),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(n,e){return!e||!n?n:n.bind(e)}var Be=class{constructor(e,t,r){this.name=e,this.init=Mi(t.init,r),this.apply=Mi(t.apply,r)}},El=[new Be("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new Be("selection",{init(n,e){return n.selection||S.atStart(e.doc)},apply(n){return n.selection}}),new Be("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new Be("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})],bt=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=El.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new Be(r.key,r.spec.state,r))})}},Qt=class n{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 r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],o=i.spec.state;o&&o.toJSON&&(t[r]=o.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new bt(e.schema,e.plugins),o=new n(i);return i.fields.forEach(s=>{if(s.name=="doc")o.doc=re.fromJSON(e.schema,t.doc);else if(s.name=="selection")o.selection=S.fromJSON(o.doc,t.selection);else if(s.name=="storedMarks")t.storedMarks&&(o.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let a=r[l],c=a.spec.state;if(a.key==s.name&&c&&c.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){o[s.name]=c.fromJSON.call(a,e,t[l],o);return}}o[s.name]=s.init(e,o)}}),o}};function Ci(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Ci(i,e,{})),t[r]=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]}},Vn=Object.create(null);function Oi(n){return n in Vn?n+"$"+ ++Vn[n]:(Vn[n]=0,n+"$")}var kt=class{constructor(e="key"){this.key=Oi(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var Ni=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function Il(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}var Al=(n,e,t)=>{let r=Il(n,t);if(!r)return!1;let i=Ti(r);if(!i){let s=r.blockRange(),l=s&&Ue(s);return l==null?!1:(e&&e(n.tr.lift(s,l).scrollIntoView()),!0)}let o=i.nodeBefore;if(!o.type.spec.isolating&&Ei(n,i,e))return!0;if(r.parent.content.size==0&&(Ye(o,"end")||x.isSelectable(o))){let s=Gt(n.doc,r.before(),r.after(),b.empty);if(s&&s.slice.size{let{$head:r,empty:i}=n.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;o=Ti(r)}let s=o&&o.nodeBefore;return!s||!x.isSelectable(s)?!1:(e&&e(n.tr.setSelection(x.create(n.doc,o.pos-s.nodeSize)).scrollIntoView()),!0)};function Ti(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){if(n.index(e)>0)return n.doc.resolve(n.before(e+1));if(n.node(e).type.spec.isolating)break}return null}function Pl(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=Pl(n,t);if(!r)return!1;let i=Di(r);if(!i)return!1;let o=i.nodeAfter;if(Ei(n,i,e))return!0;if(r.parent.content.size==0&&(Ye(o,"start")||x.isSelectable(o))){let s=Gt(n.doc,r.before(),r.after(),b.empty);if(s&&s.slice.size{let{$head:r,empty:i}=n.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):r.parentOffset=0;e--){let t=n.node(e);if(n.index(e)+1{let{$head:t,$anchor:r}=n.selection;return!t.parent.type.spec.code||!t.sameParent(r)?!1:(e&&e(n.tr.insertText(` +`).scrollIntoView()),!0)};function Kn(n){for(let e=0;e{let{$head:t,$anchor:r}=n.selection;if(!t.parent.type.spec.code||!t.sameParent(r))return!1;let i=t.node(-1),o=t.indexAfter(-1),s=Kn(i.contentMatchAt(o));if(!s||!i.canReplaceWith(o,o,s))return!1;if(e){let l=t.after(),a=n.tr.replaceWith(l,l,s.createAndFill());a.setSelection(S.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},Fl=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof H||r.parent.inlineContent||i.parent.inlineContent)return!1;let o=Kn(i.parent.contentMatchAt(i.indexAfter()));if(!o||!o.isTextblock)return!1;if(e){let s=(!r.parentOffset&&i.index(){let{$cursor:t}=n.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let o=t.before();if(ke(n.doc,o))return e&&e(n.tr.split(o).scrollIntoView()),!0}let r=t.blockRange(),i=r&&Ue(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function Ll(n){return(e,t)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof x&&e.selection.node.isBlock)return!r.parentOffset||!ke(e.doc,r.pos)?!1:(t&&t(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.parent.isBlock)return!1;if(t){let o=i.parentOffset==i.parent.content.size,s=e.tr;(e.selection instanceof w||e.selection instanceof H)&&s.deleteSelection();let l=r.depth==0?null:Kn(r.node(-1).contentMatchAt(r.indexAfter(-1))),a=n&&n(i.parent,o),c=a?[a]:o&&l?[{type:l}]:void 0,f=ke(s.doc,s.mapping.map(r.pos),1,c);if(!c&&!f&&ke(s.doc,s.mapping.map(r.pos),1,l?[{type:l}]:void 0)&&(l&&(c=[{type:l}]),f=!0),f&&(s.split(s.mapping.map(r.pos),1,c),!o&&!r.parentOffset&&r.parent.type!=l)){let h=s.mapping.map(r.before()),d=s.doc.resolve(h);l&&r.node(-1).canReplaceWith(d.index(),d.index()+1,l)&&s.setNodeMarkup(s.mapping.map(r.before()),l)}t(s.scrollIntoView())}return!0}}var Jl=Ll();var Wl=(n,e)=>(e&&e(n.tr.setSelection(new H(n.doc))),!0);function ql(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,o=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(o-1,o)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(o,o+1)||!(i.isTextblock||yt(n.doc,e.pos))?!1:(t&&t(n.tr.clearIncompatible(e.pos,r.type,r.contentMatchAt(r.childCount)).join(e.pos).scrollIntoView()),!0)}function Ei(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,o,s;if(r.type.spec.isolating||i.type.spec.isolating)return!1;if(ql(n,e,t))return!0;let l=e.parent.canReplace(e.index(),e.index()+1);if(l&&(o=(s=r.contentMatchAt(r.childCount)).findWrapping(i.type))&&s.matchType(o[0]||i.type).validEnd){if(t){let h=e.pos+i.nodeSize,d=y.empty;for(let m=o.length-1;m>=0;m--)d=y.from(o[m].create(null,d));d=y.from(r.copy(d));let p=n.tr.step(new E(e.pos-1,h,e.pos,h,new b(d,1,0),o.length,!0)),u=h+2*o.length;yt(p.doc,u)&&p.join(u),t(p.scrollIntoView())}return!0}let a=S.findFrom(e,1),c=a&&a.$from.blockRange(a.$to),f=c&&Ue(c);if(f!=null&&f>=e.depth)return t&&t(n.tr.lift(c,f).scrollIntoView()),!0;if(l&&Ye(i,"start",!0)&&Ye(r,"end")){let h=r,d=[];for(;d.push(h),!h.isTextblock;)h=h.lastChild;let p=i,u=1;for(;!p.isTextblock;p=p.firstChild)u++;if(h.canReplace(h.childCount,h.childCount,p.content)){if(t){let m=y.empty;for(let k=d.length-1;k>=0;k--)m=y.from(d[k].copy(m));let g=n.tr.step(new E(e.pos-d.length,e.pos+i.nodeSize,e.pos+u,e.pos+i.nodeSize-u,new b(m,d.length,0),0,!0));t(g.scrollIntoView())}return!0}}return!1}function Ii(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,o=i.depth;for(;i.node(o).isInline;){if(!o)return!1;o--}return i.node(o).isTextblock?(t&&t(e.tr.setSelection(w.create(e.doc,n<0?i.start(o):i.end(o)))),!0):!1}}var Kl=Ii(-1),Hl=Ii(1);function Zt(n,e=null){return function(t,r){let{$from:i,$to:o}=t.selection,s=i.blockRange(o),l=s&&_t(s,n,e);return l?(r&&r(t.tr.wrap(s,l).scrollIntoView()),!0):!1}}function $n(n,e=null){return function(t,r){let i=!1;for(let o=0;o{if(i)return!1;if(!(!a.isTextblock||a.hasMarkup(n,e)))if(a.type==n)i=!0;else{let f=t.doc.resolve(c),h=f.index();i=f.parent.canReplaceWith(h,h+1,n)}})}if(!i)return!1;if(r){let o=t.tr;for(let s=0;s{if(s)return!1;s=l.inlineContent&&l.type.allowsMarkType(t)}),s)return!0}return!1}function G(n,e=null){return function(t,r){let{empty:i,$cursor:o,ranges:s}=t.selection;if(i&&!o||!$l(t.doc,s,n))return!1;if(r)if(o)n.isInSet(t.storedMarks||o.marks())?r(t.tr.removeStoredMark(n)):r(t.tr.addStoredMark(n.create(e)));else{let l=!1,a=t.tr;for(let c=0;!l&&c{let o=s=>{this[i](s)};return e.dom.addEventListener(i,o),{name:i,handler:o}})}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,r;if(t){let l=e.nodeBefore,a=e.nodeAfter;if(l||a){let c=this.editorView.nodeDOM(this.cursorPos-(l?l.nodeSize:0));if(c){let f=c.getBoundingClientRect(),h=l?f.bottom:f.top;l&&a&&(h=(h+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2),r={left:f.left,right:f.right,top:h-this.width/2,bottom:h+this.width/2}}}}if(!r){let l=this.editorView.coordsAtPos(this.cursorPos);r={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 o,s;if(!i||i==document.body&&getComputedStyle(i).position=="static")o=-pageXOffset,s=-pageYOffset;else{let l=i.getBoundingClientRect();o=l.left-i.scrollLeft,s=l.top-i.scrollTop}this.element.style.left=r.left-o+"px",this.element.style.top=r.top-s+"px",this.element.style.width=r.right-r.left+"px",this.element.style.height=r.bottom-r.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}),r=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),i=r&&r.type.spec.disableDropCursor,o=typeof i=="function"?i(this.editorView,t,e):i;if(t&&!o){let s=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let l=Ut(this.editorView.state.doc,s,this.editorView.dragging.slice);l!=null&&(s=l)}this.setCursor(s),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 ue={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:"'"},tn={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},_l=typeof navigator!="undefined"&&/Mac/.test(navigator.platform),Ul=typeof navigator!="undefined"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(T=0;T<10;T++)ue[48+T]=ue[96+T]=String(T);var T;for(T=1;T<=24;T++)ue[T+111]="F"+T;var T;for(T=65;T<=90;T++)ue[T]=String.fromCharCode(T+32),tn[T]=String.fromCharCode(T);var T;for(en in ue)tn.hasOwnProperty(en)||(tn[en]=ue[en]);var en;function Ri(n){var e=_l&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||Ul&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?tn:ue)[n.keyCode]||n.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 Gl=typeof navigator!="undefined"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function Yl(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,o,s;for(let l=0;l127)&&(o=ue[r.keyCode])&&o!=i){let l=e[_n(o,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var B=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},Ot=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},zi=null,me=function(n,e,t){let r=zi||(zi=document.createRange());return r.setEnd(n,t==null?n.nodeValue.length:t),r.setStart(n,e||0),r},Ke=function(n,e,t,r){return t&&(Bi(n,e,t,r,-1)||Bi(n,e,t,r,1))},Ql=/^(img|br|input|textarea|hr)$/i;function Bi(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:oe(n))){let o=n.parentNode;if(!o||o.nodeType!=1||br(n)||Ql.test(n.nodeName)||n.contentEditable=="false")return!1;e=B(n)+(i<0?0:1),n=o}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?oe(n):0}else return!1}}function oe(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Zl(n,e,t){for(let r=e==0,i=e==oe(n);r||i;){if(n==t)return!0;let o=B(n);if(n=n.parentNode,!n)return!1;r=r&&o==0,i=i&&o==oe(n)}}function br(n){let e;for(let t=n;t&&!(e=t.pmViewDesc);t=t.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==n||e.contentDOM==n)}var un=function(n){return n.focusNode&&Ke(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)};function Fe(n,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=n,t.key=t.code=e,t}function ea(n){let e=n.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function ta(n,e,t){if(n.caretPositionFromPoint)try{let r=n.caretPositionFromPoint(e,t);if(r)return{node:r.offsetNode,offset:r.offset}}catch(r){}if(n.caretRangeFromPoint){let r=n.caretRangeFromPoint(e,t);if(r)return{node:r.startContainer,offset:r.startOffset}}}var se=typeof navigator!="undefined"?navigator:null,Fi=typeof document!="undefined"?document:null,we=se&&se.userAgent||"",er=/Edge\/(\d+)/.exec(we),mo=/MSIE \d/.exec(we),tr=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(we),W=!!(mo||tr||er),Ce=mo?document.documentMode:tr?+tr[1]:er?+er[1]:0,X=!W&&/gecko\/(\d+)/i.test(we);X&&+(/Firefox\/(\d+)/.exec(we)||[0,0])[1];var nr=!W&&/Chrome\/(\d+)/.exec(we),R=!!nr,na=nr?+nr[1]:0,F=!W&&!!se&&/Apple Computer/.test(se.vendor),tt=F&&(/Mobile\/\w+/.test(we)||!!se&&se.maxTouchPoints>2),j=tt||(se?/Mac/.test(se.platform):!1),ra=se?/Win/.test(se.platform):!1,Y=/Android \d/.test(we),Dt=!!Fi&&"webkitFontSmoothing"in Fi.documentElement.style,ia=Dt?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function oa(n){return{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function pe(n,e){return typeof n=="number"?n:n[e]}function sa(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function Vi(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,o=n.dom.ownerDocument;for(let s=t||n.dom;s;s=Ot(s)){if(s.nodeType!=1)continue;let l=s,a=l==o.body,c=a?oa(o):sa(l),f=0,h=0;if(e.topc.bottom-pe(r,"bottom")&&(h=e.bottom-e.top>c.bottom-c.top?e.top+pe(i,"top")-c.top:e.bottom-c.bottom+pe(i,"bottom")),e.leftc.right-pe(r,"right")&&(f=e.right-c.right+pe(i,"right")),f||h)if(a)o.defaultView.scrollBy(f,h);else{let d=l.scrollLeft,p=l.scrollTop;h&&(l.scrollTop+=h),f&&(l.scrollLeft+=f);let u=l.scrollLeft-d,m=l.scrollTop-p;e={left:e.left-u,top:e.top-m,right:e.right-u,bottom:e.bottom-m}}if(a||/^(fixed|sticky)$/.test(getComputedStyle(s).position))break}}function la(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let o=(e.left+e.right)/2,s=t+1;s=t-20){r=l,i=a.top;break}}return{refDOM:r,refTop:i,stack:go(n.dom)}}function go(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=Ot(r));return e}function aa({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;yo(t,r==0?0:r-e)}function yo(n,e){for(let t=0;t=l){s=Math.max(u.bottom,s),l=Math.min(u.top,l);let m=u.left>e.left?u.left-e.left:u.right=(u.left+u.right)/2?1:0));continue}}else u.top>e.top&&!a&&u.left<=e.left&&u.right>=e.left&&(a=f,c={left:Math.max(u.left,Math.min(u.right,e.left)),top:u.top});!t&&(e.left>=u.right&&e.top>=u.top||e.left>=u.left&&e.top>=u.bottom)&&(o=h+1)}}return!t&&a&&(t=a,i=c,r=0),t&&t.nodeType==3?fa(t,i):!t||r&&t.nodeType==1?{node:n,offset:o}:bo(t,i)}function fa(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i=(o.left+o.right)/2?1:0)}}return{node:n,offset:0}}function kr(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function ha(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(s.left+s.right)/2?1:-1}return n.docView.posFromDOM(r,i,o)}function ua(n,e,t,r){let i=-1;for(let o=e,s=!1;o!=n.dom;){let l=n.docView.nearestDesc(o,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent&&!s||!l.contentDOM)){let a=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&!s&&(s=!0,a.left>r.left||a.top>r.top?i=l.posBefore:(a.right-1?i:n.docView.posFromDOM(e,t,-1)}function ko(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let c;Dt&&i&&r.nodeType==1&&(c=r.childNodes[i-1]).nodeType==1&&c.contentEditable=="false"&&c.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=ua(n,r,i,e))}l==null&&(l=da(n,s,e));let a=n.docView.nearestDesc(s,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function Li(n){return n.top=0&&i==r.nodeValue.length?(a--,f=1):t<0?a--:c++,St(xe(me(r,a,c),f),f<0)}if(!n.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&i&&(t<0||i==oe(r))){let a=r.childNodes[i-1];if(a.nodeType==1)return Yn(a.getBoundingClientRect(),!1)}if(o==null&&i=0)}if(o==null&&i&&(t<0||i==oe(r))){let a=r.childNodes[i-1],c=a.nodeType==3?me(a,oe(a)-(s?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(c)return St(xe(c,1),!1)}if(o==null&&i=0)}function St(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function Yn(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function So(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function ga(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return So(n,e,()=>{let{node:o}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(o,!0);if(!l)break;if(l.node.isBlock){o=l.contentDOM||l.dom;break}o=l.dom.parentNode}let s=xo(n,i.pos,1);for(let l=o.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=me(l,0,l.nodeValue.length).getClientRects();else continue;for(let c=0;cf.top+1&&(t=="up"?s.top-f.top>(f.bottom-s.top)*2:f.bottom-s.bottom>(s.bottom-f.top)*2))return!1}}return!0})}var ya=/[\u0590-\u08ac]/;function ba(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,l=n.domSelection();return!ya.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?o:s:So(n,e,()=>{let{focusNode:a,focusOffset:c,anchorNode:f,anchorOffset:h}=n.domSelectionRange(),d=l.caretBidiLevel;l.modify("move",t,"character");let p=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:u,focusOffset:m}=n.domSelectionRange(),g=u&&!p.contains(u.nodeType==1?u:u.parentNode)||a==u&&c==m;try{l.collapse(f,h),a&&(a!=f||c!=h)&&l.extend&&l.extend(a,c)}catch(k){}return d!=null&&(l.caretBidiLevel=d),g})}var Ji=null,Wi=null,qi=!1;function ka(n,e,t){return Ji==e&&Wi==t?qi:(Ji=e,Wi=t,qi=t=="up"||t=="down"?ga(n,e,t):ba(n,e,t))}var _=0,Ki=1,Ve=2,le=3,He=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=_,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tB(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.nextSibling)break}}return(i==null?r>0:i)?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let o=this.getDesc(i),s;if(o&&(!t||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let o=this.getDesc(i);if(o)return o.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||s instanceof on){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof nn&&o.side>=0;r--);if(t<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&t&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,t):{node:this.contentDOM,offset:o?B(o.dom)+1:0}}else{let o,s=!0;for(;o=r=f&&t<=c-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,f);e=s;for(let h=l;h>0;h--){let d=this.children[h-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=B(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(c>t||l==this.children.length-1)){t=c;for(let f=l+1;fp&&st){let p=l;l=a,a=p}let d=document.createRange();d.setEnd(a.node,a.offset),d.setStart(l.node,l.offset),c.removeAllRanges(),c.addRange(d)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let r=0,i=0;i=r:er){let l=r+o.border,a=s-o.border;if(e>=l&&t<=a){this.dirty=e==r||t==s?Ve:Ki,e==l&&t==a&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=le:o.markDirty(e-l,t-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?Ve:le}r=s}this.dirty=Ve}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?Ve:Ki;t.dirty{if(!o)return i;if(o.parent)return o.parent.posBeforeChild(o)})),!t.type.spec.raw){if(s.nodeType!=1){let l=document.createElement("span");l.appendChild(s),s=l}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=t,this.widget=t,o=this}matchesWidget(e){return this.dirty==_&&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}},rr=class extends He{constructor(e,t,r,i){super(e,[],t,null),this.textDOM=r,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}},nt=class n extends He{constructor(e,t,r,i){super(e,[],r,i),this.mark=t}static create(e,t,r,i){let o=i.nodeViews[t.type.name],s=o&&o(t,i,r);return(!s||!s.dom)&&(s=ie.renderSpec(document,t.type.spec.toDOM(t,r))),new n(e,t,s.dom,s.contentDOM||s.dom)}parseRule(){return this.dirty&le||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=le&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=_){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(o=ar(o,0,e,r));for(let l=0;l{if(!a)return s;if(a.parent)return a.parent.posBeforeChild(a)},r,i),f=c&&c.dom,h=c&&c.contentDOM;if(t.isText){if(!f)f=document.createTextNode(t.text);else if(f.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else f||({dom:f,contentDOM:h}=ie.renderSpec(document,t.type.spec.toDOM(t)));!h&&!t.isText&&f.nodeName!="BR"&&(f.hasAttribute("contenteditable")||(f.contentEditable="false"),t.type.spec.draggable&&(f.draggable=!0));let d=f;return f=Oo(f,r,t),c?a=new ir(e,t,r,i,f,h||null,d,c,o,s+1):t.isText?new rn(e,t,r,i,f,d,o):new n(e,t,r,i,f,h||null,d,o,s+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>y.empty)}return e}matchesNode(e,t,r){return this.dirty==_&&e.eq(this.node)&&sr(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let r=this.node.inlineContent,i=t,o=e.composing?this.localCompositionInfo(e,t):null,s=o&&o.pos>-1?o:null,l=o&&o.pos<0,a=new lr(this,s&&s.node,e);Ca(this.node,this.innerDeco,(c,f,h)=>{c.spec.marks?a.syncToMarks(c.spec.marks,r,e):c.type.side>=0&&!h&&a.syncToMarks(f==this.node.childCount?O.none:this.node.child(f).marks,r,e),a.placeWidget(c,e,i)},(c,f,h,d)=>{a.syncToMarks(c.marks,r,e);let p;a.findNodeMatch(c,f,h,d)||l&&e.state.selection.from>i&&e.state.selection.to-1&&a.updateNodeAt(c,f,h,p,e)||a.updateNextNode(c,f,h,e,d,i)||a.addNode(c,f,h,e,i),i+=c.nodeSize}),a.syncToMarks([],r,e),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==Ve)&&(s&&this.protectLocalComposition(e,s),Mo(this.contentDOM,this.children,e),tt&&Oa(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof w)||rt+this.node.content.size)return null;let o=e.domSelectionRange(),s=wa(o.focusNode,o.focusOffset);if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let l=s.nodeValue,a=Na(this.node.content,l,r-t,i-t);return a<0?null:{node:s,pos:a,text:l}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let o=t;for(;o.parentNode!=this.contentDOM;o=o.parentNode){for(;o.previousSibling;)o.parentNode.removeChild(o.previousSibling);for(;o.nextSibling;)o.parentNode.removeChild(o.nextSibling);o.pmViewDesc&&(o.pmViewDesc=void 0)}let s=new rr(this,o,t,i);e.input.compositionNodes.push(s),this.children=ar(this.children,r,r+i.length,e,s)}update(e,t,r,i){return this.dirty==le||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,r,i),!0)}updateInner(e,t,r,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=_}updateOuterDeco(e){if(sr(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Co(this.dom,this.nodeDOM,or(this.outerDeco,this.node,t),or(e,this.node,t)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable")}get domAtom(){return this.node.isAtom}};function Hi(n,e,t,r,i){Oo(r,e,n);let o=new Oe(void 0,n,e,t,r,r,r,i,0);return o.contentDOM&&o.updateChildren(i,0),o}var rn=class n extends Oe{constructor(e,t,r,i,o,s,l){super(e,t,r,i,o,null,s,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,i){return this.dirty==le||this.dirty!=_&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=_||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=_,!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,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,r){let i=this.node.cut(e,t),o=document.createTextNode(i.text);return new n(this.parent,i,this.outerDeco,this.innerDeco,o,o,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=le)}get domAtom(){return!1}},on=class extends He{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==_&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},ir=class extends Oe{constructor(e,t,r,i,o,s,l,a,c,f){super(e,t,r,i,o,s,l,c,f),this.spec=a}update(e,t,r,i){if(this.dirty==le)return!1;if(this.spec.update){let o=this.spec.update(e,t,r);return o&&this.updateInner(e,t,r,i),o}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,r,i){this.spec.setSelection?this.spec.setSelection(e,t,r):super.setSelection(e,t,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function Mo(n,e,t){let r=n.firstChild,i=!1;for(let o=0;o>1,s=Math.min(o,e.length);for(;i-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let a=nt.create(this.top,e[o],t,r);this.top.children.splice(this.index,0,a),this.top=a,this.changed=!0}this.index=0,o++}}findNodeMatch(e,t,r,i){let o=-1,s;if(i>=this.preMatch.index&&(s=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&s.matchesNode(e,t,r))o=this.top.children.indexOf(s,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let c=t.children[r-1];if(c instanceof nt)t=c,r=c.children.length;else{l=c,r--;break}}else{if(t==e)break e;r=t.parent.children.indexOf(t),t=t.parent}let a=l.node;if(a){if(a!=n.child(i-1))break;--i,o.set(l,i),s.push(l)}}return{index:i,matched:o,matches:s.reverse()}}function Ma(n,e){return n.type.side-e.type.side}function Ca(n,e,t,r){let i=e.locals(n),o=0;if(i.length==0){for(let c=0;co;)l.push(i[s++]);let u=o+d.nodeSize;if(d.isText){let g=u;s!g.inline):l.slice();r(d,m,e.forChild(o,d),p),o=u}}function Oa(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function wa(n,e){for(;;){if(n.nodeType==3)return n;if(n.nodeType==1&&e>0){if(n.childNodes.length>e&&n.childNodes[e].nodeType==3)return n.childNodes[e];n=n.childNodes[e-1],e=oe(n)}else if(n.nodeType==1&&e=t){if(o>=r&&a.slice(r-e.length-l,r-l)==e)return r-e.length;let c=l=0&&c+e.length+l>=t)return l+c;if(t==r&&a.length>=r+e.length-l&&a.slice(r-l,r-l+e.length)==e)return r}}return-1}function ar(n,e,t,r,i){let o=[];for(let s=0,l=0;s=t||f<=e?o.push(a):(ct&&o.push(a.slice(t-c,a.size,r)))}return o}function xr(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),o=i&&i.size==0,s=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(s<0)return null;let l=r.resolve(s),a,c;if(un(t)){for(a=l;i&&!i.node;)i=i.parent;let f=i.node;if(i&&f.isAtom&&x.isSelectable(f)&&i.parent&&!(f.isInline&&Zl(t.focusNode,t.focusOffset,i.dom))){let h=i.posBefore;c=new x(s==h?l:r.resolve(h))}}else{let f=n.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(f<0)return null;a=r.resolve(f)}if(!c){let f=e=="pointer"||n.state.selection.head{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!wo(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function Da(n){let e=n.domSelection(),t=document.createRange(),r=n.cursorWrapper.dom,i=r.nodeName=="IMG";i?t.setEnd(r.parentNode,B(r)+1):t.setEnd(r,0),t.collapse(!1),e.removeAllRanges(),e.addRange(t),!i&&!n.state.selection.visible&&W&&Ce<=11&&(r.disabled=!0,r.disabled=!1)}function No(n,e){if(e instanceof x){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(Gi(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else Gi(n)}function Gi(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function Sr(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||w.between(e,t,r)}function Yi(n){return n.editable&&!n.hasFocus()?!1:To(n)}function To(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch(t){return!1}}function Ea(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return Ke(e.node,e.offset,t.anchorNode,t.anchorOffset)}function cr(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),o=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return o&&S.findFrom(o,e)}function Se(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function Xi(n,e,t){let r=n.state.selection;if(r instanceof w)if(t.indexOf("s")>-1){let{$head:i}=r,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!o||o.isText||!o.isLeaf)return!1;let s=n.state.doc.resolve(i.pos+o.nodeSize*(e<0?-1:1));return Se(n,new w(r.$anchor,s))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=cr(n.state,e);return i&&i instanceof x?Se(n,i):!1}else if(!(j&&t.indexOf("m")>-1)){let i=r.$head,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,s;if(!o||o.isText)return!1;let l=e<0?i.pos-o.nodeSize:i.pos;return o.isAtom||(s=n.docView.descAt(l))&&!s.contentDOM?x.isSelectable(o)?Se(n,new x(e<0?n.state.doc.resolve(i.pos-o.nodeSize):i)):Dt?Se(n,new w(n.state.doc.resolve(e<0?l:l+o.nodeSize))):!1:!1}}else return!1;else{if(r instanceof x&&r.node.isInline)return Se(n,new w(e>0?r.$to:r.$from));{let i=cr(n.state,e);return i?Se(n,i):!1}}}function sn(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Ct(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function Qe(n,e){return e<0?Ia(n):Aa(n)}function Ia(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,o,s=!1;for(X&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(Ct(l,-1))i=t,o=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(Do(t))break;{let l=t.previousSibling;for(;l&&Ct(l,-1);)i=t.parentNode,o=B(l),l=l.previousSibling;if(l)t=l,r=sn(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}s?fr(n,t,r):i&&fr(n,i,o)}function Aa(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=sn(t),o,s;for(;;)if(r{n.state==i&&ge(n)},50)}function Qi(n,e){let t=n.state.doc.resolve(e);if(!(R||ra)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let o=n.coordsAtPos(e-1),s=(o.top+o.bottom)/2;if(s>i.top&&s1)return o.lefti.top&&s1)return o.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function Zi(n,e,t){let r=n.state.selection;if(r instanceof w&&!r.empty||t.indexOf("s")>-1||j&&t.indexOf("m")>-1)return!1;let{$from:i,$to:o}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let s=cr(n.state,e);if(s&&s instanceof x)return Se(n,s)}if(!i.parent.inlineContent){let s=e<0?i:o,l=r instanceof H?S.near(s,e):S.findFrom(s,e);return l?Se(n,l):!1}return!1}function eo(n,e){if(!(n.state.selection instanceof w))return!0;let{$head:t,$anchor:r,empty:i}=n.state.selection;if(!t.sameParent(r))return!0;if(!i)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let o=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(o&&!o.isText){let s=n.state.tr;return e<0?s.delete(t.pos-o.nodeSize,t.pos):s.delete(t.pos,t.pos+o.nodeSize),n.dispatch(s),!0}return!1}function to(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function Ra(n){if(!F||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;to(n,r,"true"),setTimeout(()=>to(n,r,"false"),20)}return!1}function za(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function Ba(n,e){let t=e.keyCode,r=za(e);if(t==8||j&&t==72&&r=="c")return eo(n,-1)||Qe(n,-1);if(t==46&&!e.shiftKey||j&&t==68&&r=="c")return eo(n,1)||Qe(n,1);if(t==13||t==27)return!0;if(t==37||j&&t==66&&r=="c"){let i=t==37?Qi(n,n.state.selection.from)=="ltr"?-1:1:-1;return Xi(n,i,r)||Qe(n,i)}else if(t==39||j&&t==70&&r=="c"){let i=t==39?Qi(n,n.state.selection.from)=="ltr"?1:-1:1;return Xi(n,i,r)||Qe(n,i)}else{if(t==38||j&&t==80&&r=="c")return Zi(n,-1,r)||Qe(n,-1);if(t==40||j&&t==78&&r=="c")return Ra(n)||Zi(n,1,r)||Qe(n,1);if(r==(j?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Eo(n,e){n.someProp("transformCopied",p=>{e=p(e,n)});let t=[],{content:r,openStart:i,openEnd:o}=e;for(;i>1&&o>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,o--;let p=r.firstChild;t.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),r=p.content}let s=n.someProp("clipboardSerializer")||ie.fromSchema(n.state.schema),l=zo(),a=l.createElement("div");a.appendChild(s.serializeFragment(r,{document:l}));let c=a.firstChild,f,h=0;for(;c&&c.nodeType==1&&(f=Ro[c.nodeName.toLowerCase()]);){for(let p=f.length-1;p>=0;p--){let u=l.createElement(f[p]);for(;a.firstChild;)u.appendChild(a.firstChild);a.appendChild(u),h++}c=a.firstChild}c&&c.nodeType==1&&c.setAttribute("data-pm-slice",`${i} ${o}${h?` -${h}`:""} ${JSON.stringify(t)}`);let d=n.someProp("clipboardTextSerializer",p=>p(e,n))||e.content.textBetween(0,e.content.size,` `);return{dom:a,text:d}}function Io(n,e,t,r,i){let o=i.parent.type.spec.code,s,l;if(!t&&!e)return null;let a=e&&(r||o||!t);if(a){if(n.someProp("transformPastedText",d=>{e=d(e,o||r,n)}),o)return e?new b(y.from(n.state.schema.text(e.replace(/\r\n?/g,` -`))),0,0):b.empty;let h=n.someProp("clipboardTextParser",d=>d(e,i,r,n));if(h)l=h;else{let d=i.marks(),{schema:p}=n.state,u=ie.fromSchema(p);s=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=s.appendChild(document.createElement("p"));m&&g.appendChild(u.serializeNode(p.text(m,d)))})}}else n.someProp("transformPastedHTML",h=>{t=h(t,n)}),s=Va(t),Dt&&La(s);let c=s&&s.querySelector("[data-pm-slice]"),f=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(f&&f[3])for(let h=+f[3];h>0;h--){let d=s.firstChild;for(;d&&d.nodeType!=1;)d=d.nextSibling;if(!d)break;s=d}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||Re.fromSchema(n.state.schema)).parseSlice(s,{preserveWhitespace:!!(a||f),context:i,ruleFromNode(d){return d.nodeName=="BR"&&!d.nextSibling&&d.parentNode&&!Ba.test(d.parentNode.nodeName)?{ignore:!0}:null}})),f)l=Ja(no(l,+f[1],+f[2]),f[4]);else if(l=b.maxOpen(Fa(l.content,i),!0),l.openStart||l.openEnd){let h=0,d=0;for(let p=l.content.firstChild;h{l=h(l,n)}),l}var Ba=/^(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 Fa(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),o,s=[];if(n.forEach(l=>{if(!s)return;let a=i.findWrapping(l.type),c;if(!a)return s=null;if(c=s.length&&o.length&&vo(a,o,l,s[s.length-1],0))s[s.length-1]=c;else{s.length&&(s[s.length-1]=Po(s[s.length-1],o.length));let f=Ao(l,a);s.push(f),i=i.matchType(f.type),o=a}}),s)return y.from(s)}return n}function Ao(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,y.from(n));return n}function vo(n,e,t,r,i){if(i1&&(o=0),i=t&&(l=e<0?s.contentMatchAt(0).fillBefore(l,o<=i).append(l):l.append(s.contentMatchAt(s.childCount).fillBefore(y.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,s.copy(l))}function no(n,e,t){return e]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=zo().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&Ro[r[1].toLowerCase()])&&(n=i.map(o=>"<"+o+">").join("")+n+i.map(o=>"").reverse().join("")),t.innerHTML=n,i)for(let o=0;o=0;l-=2){let a=t.nodes[r[l]];if(!a||a.hasRequiredAttrs())break;i=y.from(a.create(r[l+1],i)),o++,s++}return new b(i,o,s)}var V={},L={},Wa={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 qa(n){for(let e in V){let t=V[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{$a(n,r)&&!Mr(n,r)&&(n.editable||!(r.type in L))&&t(n,r)},Wa[e]?{passive:!0}:void 0)}F&&n.dom.addEventListener("input",()=>null),ur(n)}function Me(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function Ka(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function ur(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>Mr(n,r))})}function Mr(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function $a(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function Ha(n,e){!Mr(n,e)&&V[e.type]&&(n.editable||!(e.type in L))&&V[e.type](n,e)}L.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!Fo(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(Y&&R&&t.keyCode==13)))if(t.keyCode!=229&&n.domObserver.forceFlush(),tt&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let r=Date.now();n.input.lastIOSEnter=r,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==r&&(n.someProp("handleKeyDown",i=>i(n,Fe(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||za(n,t)?t.preventDefault():Me(n,"key")};L.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};L.keypress=(n,e)=>{let t=e;if(Fo(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||j&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof w)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(t.charCode);!/[\r\n]/.test(i)&&!n.someProp("handleTextInput",o=>o(n,r.$from.pos,r.$to.pos,i))&&n.dispatch(n.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function pn(n){return{left:n.clientX,top:n.clientY}}function ja(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function Cr(n,e,t,r,i){if(r==-1)return!1;let o=n.state.doc.resolve(r);for(let s=o.depth+1;s>0;s--)if(n.someProp(e,l=>s>o.depth?l(n,t,o.nodeAfter,o.before(s),i,!0):l(n,t,o.node(s),o.before(s),i,!1)))return!0;return!1}function et(n,e,t){n.focused||n.focus();let r=n.state.tr.setSelection(e);t=="pointer"&&r.setMeta("pointer",!0),n.dispatch(r)}function _a(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&x.isSelectable(r)?(et(n,new x(t),"pointer"),!0):!1}function Ua(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof x&&(r=t.node);let o=n.state.doc.resolve(e);for(let s=o.depth+1;s>0;s--){let l=s>o.depth?o.nodeAfter:o.node(s);if(x.isSelectable(l)){r&&t.$from.depth>0&&s>=t.$from.depth&&o.before(t.$from.depth+1)==t.$from.pos?i=o.before(t.$from.depth):i=o.before(s);break}}return i!=null?(et(n,x.create(n.state.doc,i),"pointer"),!0):!1}function Ga(n,e,t,r,i){return Cr(n,"handleClickOn",e,t,r)||n.someProp("handleClick",o=>o(n,e,r))||(i?Ua(n,t):_a(n,t))}function Ya(n,e,t,r){return Cr(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function Xa(n,e,t,r){return Cr(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||Qa(n,t,r)}function Qa(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(et(n,w.create(r,0,r.content.size),"pointer"),!0):!1;let i=r.resolve(e);for(let o=i.depth+1;o>0;o--){let s=o>i.depth?i.nodeAfter:i.node(o),l=i.before(o);if(s.inlineContent)et(n,w.create(r,l+1,l+1+s.content.size),"pointer");else if(x.isSelectable(s))et(n,x.create(r,l),"pointer");else continue;return!0}}function Or(n){return ln(n)}var Bo=j?"metaKey":"ctrlKey";V.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=Or(n),i=Date.now(),o="singleClick";i-n.input.lastClick.time<500&&ja(t,n.input.lastClick)&&!t[Bo]&&(n.input.lastClick.type=="singleClick"?o="doubleClick":n.input.lastClick.type=="doubleClick"&&(o="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:o};let s=n.posAtCoords(pn(t));s&&(o=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new pr(n,s,t,!!r)):(o=="doubleClick"?Ya:Xa)(n,s.pos,s.inside,t)?t.preventDefault():Me(n,"pointer"))};var pr=class{constructor(e,t,r,i){this.view=e,this.pos=t,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[Bo],this.allowDefault=r.shiftKey;let o,s;if(t.inside>-1)o=e.state.doc.nodeAt(t.inside),s=t.inside;else{let f=e.state.doc.resolve(t.pos);o=f.parent,s=f.depth?f.before():0}let l=i?null:r.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a?a.dom:null;let{selection:c}=e.state;(r.button==0&&o.type.spec.draggable&&o.type.spec.selectable!==!1||c instanceof x&&c.from<=s&&c.to>s)&&(this.mightDrag={node:o,pos:s,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&X&&!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)),Me(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(()=>ge(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(pn(e))),this.updateAllowDefault(e),this.allowDefault||!t?Me(this.view,"pointer"):Ga(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||F&&this.mightDrag&&!this.mightDrag.node.isAtom||R&&!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)?(et(this.view,S.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):Me(this.view,"pointer")}move(e){this.updateAllowDefault(e),Me(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)}};V.touchstart=n=>{n.input.lastTouch=Date.now(),Or(n),Me(n,"pointer")};V.touchmove=n=>{n.input.lastTouch=Date.now(),Me(n,"pointer")};V.contextmenu=n=>Or(n);function Fo(n,e){return n.composing?!0:F&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}var Za=Y?5e3:-1;L.compositionstart=L.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$from;if(e.selection.empty&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))n.markCursor=n.state.storedMarks||t.marks(),ln(n,!0),n.markCursor=null;else if(ln(n),X&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let i=r.focusNode,o=r.focusOffset;i&&i.nodeType==1&&o!=0;){let s=o<0?i.lastChild:i.childNodes[o-1];if(!s)break;if(s.nodeType==3){n.domSelection().collapse(s,s.nodeValue.length);break}else i=s,o=-1}}n.input.composing=!0}Vo(n,Za)};L.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,Vo(n,20))};function Vo(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>ln(n),e))}function Lo(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=ec());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function ec(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function ln(n,e=!1){if(!(Y&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),Lo(n),e||n.docView&&n.docView.dirty){let t=xr(n);return t&&!t.eq(n.state.selection)?n.dispatch(n.state.tr.setSelection(t)):n.updateState(n.state),!0}return!1}}function tc(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),n.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}var wt=W&&Ce<15||tt&&ra<604;V.copy=L.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let o=wt?null:t.clipboardData,s=r.content(),{dom:l,text:a}=Eo(n,s);o?(t.preventDefault(),o.clearData(),o.setData("text/html",l.innerHTML),o.setData("text/plain",a)):tc(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function nc(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function rc(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,r=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),r.parentNode&&r.parentNode.removeChild(r),t?Nt(n,r.value,null,i,e):Nt(n,r.textContent,r.innerHTML,i,e)},50)}function Nt(n,e,t,r,i){let o=Io(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",a=>a(n,i,o||b.empty)))return!0;if(!o)return!1;let s=nc(o),l=s?n.state.tr.replaceSelectionWith(s,r):n.state.tr.replaceSelection(o);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Jo(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}L.paste=(n,e)=>{let t=e;if(n.composing&&!Y)return;let r=wt?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&Nt(n,Jo(r),r.getData("text/html"),i,t)?t.preventDefault():rc(n,t)};var an=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}},Wo=j?"altKey":"ctrlKey";V.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=n.state.selection,o=i.empty?null:n.posAtCoords(pn(t)),s;if(!(o&&o.pos>=i.from&&o.pos<=(i instanceof x?i.to-1:i.to))){if(r&&r.mightDrag)s=x.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let f=n.docView.nearestDesc(t.target,!0);f&&f.node.type.spec.draggable&&f!=n.docView&&(s=x.create(n.state.doc,f.posBefore))}}let l=(s||n.state.selection).content(),{dom:a,text:c}=Eo(n,l);t.dataTransfer.clearData(),t.dataTransfer.setData(wt?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",wt||t.dataTransfer.setData("text/plain",c),n.dragging=new an(l,!t[Wo],s)};V.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};L.dragover=L.dragenter=(n,e)=>e.preventDefault();L.drop=(n,e)=>{let t=e,r=n.dragging;if(n.dragging=null,!t.dataTransfer)return;let i=n.posAtCoords(pn(t));if(!i)return;let o=n.state.doc.resolve(i.pos),s=r&&r.slice;s?n.someProp("transformPasted",u=>{s=u(s,n)}):s=Io(n,Jo(t.dataTransfer),wt?null:t.dataTransfer.getData("text/html"),!1,o);let l=!!(r&&!t[Wo]);if(n.someProp("handleDrop",u=>u(n,t,s||b.empty,l))){t.preventDefault();return}if(!s)return;t.preventDefault();let a=s?Ut(n.state.doc,o.pos,s):o.pos;a==null&&(a=o.pos);let c=n.state.tr;if(l){let{node:u}=r;u?u.replace(c):c.deleteSelection()}let f=c.mapping.map(a),h=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,d=c.doc;if(h?c.replaceRangeWith(f,f,s.content.firstChild):c.replaceRange(f,f,s),c.doc.eq(d))return;let p=c.doc.resolve(f);if(h&&x.isSelectable(s.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(s.content.firstChild))c.setSelection(new x(p));else{let u=c.mapping.map(a);c.mapping.maps[c.mapping.maps.length-1].forEach((m,g,k,N)=>u=N),c.setSelection(Sr(n,p,c.doc.resolve(u)))}n.focus(),n.dispatch(c.setMeta("uiEvent","drop"))};V.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&ge(n)},20))};V.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)};V.beforeinput=(n,e)=>{if(R&&Y&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:r}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=r||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",o=>o(n,Fe(8,"Backspace")))))return;let{$cursor:i}=n.state.selection;i&&i.pos>0&&n.dispatch(n.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let n in L)V[n]=L[n];function Tt(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}var cn=class n{constructor(e,t){this.toDOM=e,this.spec=t||We,this.side=this.spec.side||0}map(e,t,r,i){let{pos:o,deleted:s}=e.mapResult(t.from+i,this.side<0?-1:1);return s?null:new ae(o-r,o-r,this)}valid(){return!0}eq(e){return this==e||e instanceof n&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Tt(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},Je=class n{constructor(e,t){this.attrs=e,this.spec=t||We}map(e,t,r,i){let o=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,s=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return o>=s?null:new ae(o,s,this)}valid(e,t){return t.from=e&&(!o||o(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let s=0;se){let l=this.children[s]+1;this.children[s+2].findInner(e-l,t-l,r,i+l,o)}}map(e,t,r){return this==P||e.maps.length==0?this:this.mapInner(e,t,0,0,r||We)}mapInner(e,t,r,i,o){let s;for(let l=0;l{let c=a+r,f;if(f=Ko(t,l,c)){for(i||(i=this.children.slice());ol&&h.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let o=e+1,s=o+t.content.size;for(let l=0;lo&&a.type instanceof Je){let c=Math.max(o,a.from)-o,f=Math.min(s,a.to)-o;ci.map(e,t,We));return n.from(r)}forChild(e,t){if(t.isLeaf)return q.empty;let r=[];for(let i=0;it instanceof q)?e:e.reduce((t,r)=>t.concat(r instanceof q?r:r.members),[]))}}};function ic(n,e,t,r,i,o,s){let l=n.slice();for(let c=0,f=o;c{let g=m-u-(p-d);for(let k=0;kN+f-h)continue;let ee=l[k]+f-h;p>=ee?l[k+1]=d<=ee?-2:-1:d>=f&&g&&(l[k]+=g,l[k+1]+=g)}h+=g}),f=t.maps[c].map(f,-1)}let a=!1;for(let c=0;c=r.content.size){a=!0;continue}let d=t.map(n[c+1]+o,-1),p=d-i,{index:u,offset:m}=r.content.findIndex(h),g=r.maybeChild(u);if(g&&m==h&&m+g.nodeSize==p){let k=l[c+2].mapInner(t,g,f+1,n[c]+o+1,s);k!=P?(l[c]=h,l[c+1]=p,l[c+2]=k):(l[c+1]=-2,a=!0)}else a=!0}if(a){let c=oc(l,n,e,t,i,o,s),f=hn(c,r,0,s);e=f.local;for(let h=0;ht&&s.to{let c=Ko(n,l,a+t);if(c){o=!0;let f=hn(c,l,t+a+1,r);f!=P&&i.push(a,a+l.nodeSize,f)}});let s=qo(o?$o(n):n,-t).sort(qe);for(let l=0;l0;)e++;n.splice(e,0,t)}function Qn(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=P&&e.push(r)}),n.cursorWrapper&&e.push(q.create(n.state.doc,[n.cursorWrapper.deco])),fn.from(e)}var sc={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},lc=W&&Ce<=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(r=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),lc&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.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,sc)),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 ge(this.view);if(W&&Ce<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Ke(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,r;for(let o=e.focusNode;o;o=Ot(o))t.add(o);for(let o=e.anchorNode;o;o=Ot(o))if(t.has(o)){r=o;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))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 r=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&Yi(e)&&!this.ignoreSelectionChange(r),o=-1,s=-1,l=!1,a=[];if(e.editable)for(let f=0;f1){let f=a.filter(h=>h.nodeName=="BR");if(f.length==2){let h=f[0],d=f[1];h.parentNode&&h.parentNode.parentNode==d.parentNode?d.remove():h.remove()}}let c=null;o<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(o>-1&&(e.docView.markDirty(o,s),ac(e)),this.handleDOMChange(o,s,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||ge(e),this.currentSelection.set(r))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let f=0;fi;g--){let k=r.childNodes[g-1],N=k.pmViewDesc;if(k.nodeName=="BR"&&!N){o=g;break}if(!N||N.size)break}let h=n.state.doc,d=n.someProp("domParser")||Re.fromSchema(n.state.schema),p=h.resolve(s),u=null,m=d.parse(r,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:i,to:o,preserveWhitespace:p.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:hc,context:p});if(c&&c[0].pos!=null){let g=c[0].pos,k=c[1]&&c[1].pos;k==null&&(k=g),u={anchor:g+s,head:k+s}}return{doc:m,sel:u,from:s,to:l}}function hc(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(F&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||F&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}var dc=/^(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 uc(n,e,t,r,i){let o=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let M=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,be=xr(n,M);if(be&&!n.state.selection.eq(be)){if(R&&Y&&n.input.lastKeyCode===13&&Date.now()-100Rs(n,Fe(13,"Enter"))))return;let Pt=n.state.tr.setSelection(be);M=="pointer"?Pt.setMeta("pointer",!0):M=="key"&&Pt.scrollIntoView(),o&&Pt.setMeta("composition",o),n.dispatch(Pt)}return}let s=n.state.doc.resolve(e),l=s.sharedDepth(t);e=s.before(l+1),t=n.state.doc.resolve(t).after(l+1);let a=n.state.selection,c=fc(n,e,t),f=n.state.doc,h=f.slice(c.from,c.to),d,p;n.input.lastKeyCode===8&&Date.now()-100Date.now()-225||Y)&&i.some(M=>M.nodeType==1&&!dc.test(M.nodeName))&&(!u||u.endA>=u.endB)&&n.someProp("handleKeyDown",M=>M(n,Fe(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!u)if(r&&a instanceof w&&!a.empty&&a.$head.sameParent(a.$anchor)&&!n.composing&&!(c.sel&&c.sel.anchor!=c.sel.head))u={start:a.from,endA:a.to,endB:a.to};else{if(c.sel){let M=lo(n,n.state.doc,c.sel);if(M&&!M.eq(n.state.selection)){let be=n.state.tr.setSelection(M);o&&be.setMeta("composition",o),n.dispatch(be)}}return}if(R&&n.cursorWrapper&&c.sel&&c.sel.anchor==n.cursorWrapper.deco.from&&c.sel.head==c.sel.anchor){let M=u.endB-u.start;c.sel={anchor:c.sel.anchor+M,head:c.sel.anchor+M}}n.input.domChangeCount++,n.state.selection.fromn.state.selection.from&&u.start<=n.state.selection.from+2&&n.state.selection.from>=c.from?u.start=n.state.selection.from:u.endA=n.state.selection.to-2&&n.state.selection.to<=c.to&&(u.endB+=n.state.selection.to-u.endA,u.endA=n.state.selection.to)),W&&Ce<=11&&u.endB==u.start+1&&u.endA==u.start&&u.start>c.from&&c.doc.textBetween(u.start-c.from-1,u.start-c.from+1)==" \xA0"&&(u.start--,u.endA--,u.endB--);let m=c.doc.resolveNoCache(u.start-c.from),g=c.doc.resolveNoCache(u.endB-c.from),k=f.resolve(u.start),N=m.sameParent(g)&&m.parent.inlineContent&&k.end()>=u.endA,ee;if((tt&&n.input.lastIOSEnter>Date.now()-225&&(!N||i.some(M=>M.nodeName=="DIV"||M.nodeName=="P"))||!N&&m.posM(n,Fe(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>u.start&&mc(f,u.start,u.endA,m,g)&&n.someProp("handleKeyDown",M=>M(n,Fe(8,"Backspace")))){Y&&R&&n.domObserver.suppressSelectionUpdates();return}R&&Y&&u.endB==u.start&&(n.input.lastAndroidDelete=Date.now()),Y&&!N&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&c.sel&&c.sel.anchor==c.sel.head&&c.sel.head==u.endA&&(u.endB-=2,g=c.doc.resolveNoCache(u.endB-c.from),setTimeout(()=>{n.someProp("handleKeyDown",function(M){return M(n,Fe(13,"Enter"))})},20));let te=u.start,U=u.endA,C,H,ne;if(N){if(m.pos==g.pos)W&&Ce<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>ge(n),20)),C=n.state.tr.delete(te,U),H=f.resolve(u.start).marksAcross(f.resolve(u.endA));else if(u.endA==u.endB&&(ne=pc(m.parent.content.cut(m.parentOffset,g.parentOffset),k.parent.content.cut(k.parentOffset,u.endA-k.start()))))C=n.state.tr,ne.type=="add"?C.addMark(te,U,ne.mark):C.removeMark(te,U,ne.mark);else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let M=m.parent.textBetween(m.parentOffset,g.parentOffset);if(n.someProp("handleTextInput",be=>be(n,te,U,M)))return;C=n.state.tr.insertText(M,te,U)}}if(C||(C=n.state.tr.replace(te,U,c.doc.slice(u.start-c.from,u.endB-c.from))),c.sel){let M=lo(n,C.doc,c.sel);M&&!(R&&Y&&n.composing&&M.empty&&(u.start!=u.endB||n.input.lastAndroidDeletee.content.size?null:Sr(n,e.resolve(t.anchor),e.resolve(t.head))}function pc(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,o=r,s,l,a;for(let f=0;ff.mark(l.addToSet(f.marks));else if(i.length==0&&o.length==1)l=o[0],s="remove",a=f=>f.mark(l.removeFromSet(f.marks));else return null;let c=[];for(let f=0;ft||Zn(s,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let o=n.node(r).maybeChild(n.indexAfter(r));for(;o&&!o.isLeaf;)o=o.firstChild,i++}return i}function gc(n,e,t,r,i){let o=n.findDiffStart(e,t);if(o==null)return null;let{a:s,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let a=Math.max(0,o-Math.min(s,l));r-=s+a-o}if(s=s?o-r:0;o-=a,o&&o=l?o-r:0;o-=a,o&&o=56320&&e<=57343&&t>=55296&&t<=56319}var dn=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(po),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=ho(this),fo(this),this.nodeViews=uo(this),this.docView=$i(this.state.doc,co(this),Qn(this),this.dom,this),this.domObserver=new yr(this,(r,i,o,s)=>uc(this,r,i,o,s)),this.domObserver.start(),qa(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&&ur(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(po),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let r in this._props)t[r]=this._props[r];t.state=this.state;for(let r in e)t[r]=e[r];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var r;let i=this.state,o=!1,s=!1;e.storedMarks&&this.composing&&(Lo(this),s=!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=uo(this);bc(p,this.nodeViews)&&(this.nodeViews=p,o=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&ur(this),this.editable=ho(this),fo(this);let a=Qn(this),c=co(this),f=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",h=o||!this.docView.matchesNode(e.doc,c,a);(h||!e.selection.eq(i.selection))&&(s=!0);let d=f=="preserve"&&s&&this.dom.style.overflowAnchor==null&&sa(this);if(s){this.domObserver.stop();let p=h&&(W||R)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&yc(i.selection,e.selection);if(h){let u=R?this.trackWrites=this.domSelectionRange().focusNode:null;(o||!this.docView.update(e.doc,c,a,this))&&(this.docView.updateOuterDeco([]),this.docView.destroy(),this.docView=$i(e.doc,c,a,this.dom,this)),u&&!this.trackWrites&&(p=!0)}p||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Da(this))?ge(this,p):(No(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),f=="reset"?this.dom.scrollTop=0:f=="to selection"?this.scrollToSelection():d&&la(d)}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&&Vi(this,t.getBoundingClientRect(),e)}else Vi(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(o))==r.node&&(i=o)}this.dragging=new an(e.slice,e.move,i<0?void 0:x.create(this.state.doc,i))}someProp(e,t){let r=this._props&&this._props[e],i;if(r!=null&&(i=t?t(r):r))return i;for(let s=0;st.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return ua(this,e)}coordsAtPos(e,t=1){return xo(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,r=-1){let i=this.docView.posFromDOM(e,t,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return ba(this,t||this.state,e)}pasteHTML(e,t){return Nt(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return Nt(this,e,null,!0,t||new ClipboardEvent("paste"))}destroy(){this.docView&&(Ka(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Qn(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 Ha(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){return F&&this.root.nodeType===11&&Zl(this.dom.ownerDocument)==this.dom?cc(this):this.domSelection()}domSelection(){return this.root.getSelection()}};function co(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let r in t)r=="class"?e.class+=" "+t[r]:r=="style"?e.style=(e.style?e.style+";":"")+t[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(t[r]))}),e.translate||(e.translate="no"),[ae.node(0,n.state.doc.content.size,e)]}function fo(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:ae.widget(n.state.selection.head,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function ho(n){return!n.someProp("editable",e=>e(n.state)===!1)}function yc(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function uo(n){let e=Object.create(null);function t(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function bc(n,e){let t=0,r=0;for(let i in n){if(n[i]!=e[i])return!0;t++}for(let i in e)r++;return t!=r}function po(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}var z=class n extends S{constructor(e){super(e,e)}map(e,t){let r=e.resolve(t.map(this.head));return n.valid(r)?new n(r):S.near(r)}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 Nr(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!kc(e)||!xc(e))return!1;let r=t.type.spec.allowGapCursor;if(r!=null)return r;let i=t.contentMatchAt(e.index()).defaultType;return i&&i.isTextblock}static findGapCursorFrom(e,t,r=!1){e:for(;;){if(!r&&n.valid(e))return e;let i=e.pos,o=null;for(let s=e.depth;;s--){let l=e.node(s);if(t>0?e.indexAfter(s)0){o=l.child(t>0?e.indexAfter(s):e.index(s)-1);break}else if(s==0)return null;i+=t;let a=e.doc.resolve(i);if(n.valid(a))return a}for(;;){let s=t>0?o.firstChild:o.lastChild;if(!s){if(o.isAtom&&!o.isText&&!x.isSelectable(o)){e=e.doc.resolve(i+o.nodeSize*t),r=!1;continue e}break}o=s,i+=t;let l=e.doc.resolve(i);if(n.valid(l))return l}return null}}};z.prototype.visible=!1;z.findFrom=z.findGapCursorFrom;S.jsonID("gapcursor",z);var Nr=class n{constructor(e){this.pos=e}map(e){return new n(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return z.valid(t)?new z(t):S.near(t)}};function kc(n){for(let e=n.depth;e>=0;e--){let t=n.index(e),r=n.node(e);if(t==0){if(r.type.spec.isolating)return!0;continue}for(let i=r.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 xc(n){for(let e=n.depth;e>=0;e--){let t=n.indexAfter(e),r=n.node(e);if(t==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let i=r.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 Ho(){return new J({props:{decorations:Oc,createSelectionBetween(n,e,t){return e.pos==t.pos&&z.valid(t)?new z(t):null},handleClick:Mc,handleKeyDown:Sc,handleDOMEvents:{beforeinput:Cc}}})}var Sc=Gn({ArrowLeft:mn("horiz",-1),ArrowRight:mn("horiz",1),ArrowUp:mn("vert",-1),ArrowDown:mn("vert",1)});function mn(n,e){let t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,i,o){let s=r.selection,l=e>0?s.$to:s.$from,a=s.empty;if(s instanceof w){if(!o.endOfTextblock(t)||l.depth==0)return!1;a=!1,l=r.doc.resolve(e>0?l.after():l.before())}let c=z.findGapCursorFrom(l,e,a);return c?(i&&i(r.tr.setSelection(new z(c))),!0):!1}}function Mc(n,e,t){if(!n||!n.editable)return!1;let r=n.state.doc.resolve(e);if(!z.valid(r))return!1;let i=n.posAtCoords({left:t.clientX,top:t.clientY});return i&&i.inside>-1&&x.isSelectable(n.state.doc.nodeAt(i.inside))?!1:(n.dispatch(n.state.tr.setSelection(new z(r))),!0)}function Cc(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof z))return!1;let{$from:t}=n.state.selection,r=t.parent.contentMatchAt(t.index()).findWrapping(n.state.schema.nodes.text);if(!r)return!1;let i=y.empty;for(let s=r.length-1;s>=0;s--)i=y.from(r[s].createAndFill(null,i));let o=n.state.tr.replace(t.pos,t.pos,new b(i,0,0));return o.setSelection(w.near(o.doc.resolve(t.pos+1))),n.dispatch(o),!1}function Oc(n){if(!(n.selection instanceof z))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",q.create(n.doc,[ae.widget(n.selection.head,e,{key:"gapcursor"})])}var gn=200,A=function(){};A.prototype.append=function(e){return e.length?(e=A.from(e),!this.length&&e||e.length=t?A.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};A.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};A.prototype.forEach=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length),t<=r?this.forEachInner(e,t,r,0):this.forEachInvertedInner(e,t,r,0)};A.prototype.map=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length);var i=[];return this.forEach(function(o,s){return i.push(e(o,s))},t,r),i};A.from=function(e){return e instanceof A?e:e&&e.length?new jo(e):A.empty};var jo=function(n){function e(r){n.call(this),this.values=r}n&&(e.__proto__=n),e.prototype=Object.create(n&&n.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,o){return i==0&&o==this.length?this:new e(this.values.slice(i,o))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,o,s,l){for(var a=o;a=s;a--)if(i(this.values[a],l+a)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=gn)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=gn)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}(A);A.empty=new jo([]);var wc=function(n){function e(t,r){n.call(this),this.left=t,this.right=r,this.length=t.length+r.length,this.depth=Math.max(t.depth,r.depth)+1}return n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(r){return rl&&this.right.forEachInner(r,Math.max(i-l,0),Math.min(this.length,o)-l,s+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,o,s){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(r,i-l,Math.max(o,l)-l,s+l)===!1||o=o?this.right.slice(r-o,i-o):this.left.slice(r,o).append(this.right.slice(0,i-o))},e.prototype.leafAppend=function(r){var i=this.right.leafAppend(r);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(r){var i=this.left.leafPrepend(r);if(i)return new e(i,this.right)},e.prototype.appendInner=function(r){return this.left.depth>=Math.max(this.right.depth,r.depth)+1?new e(this.left,new e(this.right,r)):new e(this,r)},e}(A),Tr=A;var Nc=500,He=class n{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,o;t&&(i=this.remapping(r,this.items.length),o=i.maps.length);let s=e.tr,l,a,c=[],f=[];return this.items.forEach((h,d)=>{if(!h.step){i||(i=this.remapping(r,d+1),o=i.maps.length),o--,f.push(h);return}if(i){f.push(new ce(h.map));let p=h.step.map(i.slice(o)),u;p&&s.maybeStep(p).doc&&(u=s.mapping.maps[s.mapping.maps.length-1],c.push(new ce(u,void 0,void 0,c.length+f.length))),o--,u&&i.appendMap(u,o)}else s.maybeStep(h.step);if(h.selection)return l=i?h.selection.map(i.slice(o)):h.selection,a=new n(this.items.slice(0,r).append(f.reverse().concat(c)),this.eventCount-1),!1},this.items.length,0),{remaining:a,transform:s,selection:l}}addTransform(e,t,r,i){let o=[],s=this.eventCount,l=this.items,a=!i&&l.length?l.get(l.length-1):null;for(let f=0;fDc&&(l=Tc(l,c),s-=c),new n(l.append(o),s)}remapping(e,t){let r=new ut;return this.items.forEach((i,o)=>{let s=i.mirrorOffset!=null&&o-i.mirrorOffset>=e?r.maps.length-i.mirrorOffset:void 0;r.appendMap(i.map,s)},e,t),r}addMaps(e){return this.eventCount==0?this:new n(this.items.append(e.map(t=>new ce(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-t),o=e.mapping,s=e.steps.length,l=this.eventCount;this.items.forEach(d=>{d.selection&&l--},i);let a=t;this.items.forEach(d=>{let p=o.getMirror(--a);if(p==null)return;s=Math.min(s,p);let u=o.maps[p];if(d.step){let m=e.steps[p].invert(e.docs[p]),g=d.selection&&d.selection.map(o.slice(a+1,p));g&&l++,r.push(new ce(u,m,g))}else r.push(new ce(u))},i);let c=[];for(let d=t;dNc&&(h=h.compress(this.items.length-r.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),r=t.maps.length,i=[],o=0;return this.items.forEach((s,l)=>{if(l>=e)i.push(s),s.selection&&o++;else if(s.step){let a=s.step.map(t.slice(r)),c=a&&a.getMap();if(r--,c&&t.appendMap(c,r),a){let f=s.selection&&s.selection.map(t.slice(r));f&&o++;let h=new ce(c.invert(),a,f),d,p=i.length-1;(d=i.length&&i[p].merge(h))?i[p]=d:i.push(h)}}else s.map&&r--},this.items.length,0),new n(Tr.from(i.reverse()),o)}};He.empty=new He(Tr.empty,0);function Tc(n,e){let t;return n.forEach((r,i)=>{if(r.selection&&e--==0)return t=i,!1}),n.slice(t)}var ce=class n{constructor(e,t,r,i){this.map=e,this.step=t,this.selection=r,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new n(t.getMap().invert(),t,this.selection)}}},fe=class{constructor(e,t,r,i,o){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=i,this.prevComposition=o}},Dc=20;function Ec(n,e,t,r){let i=t.getMeta(Ne),o;if(i)return i.historyState;t.getMeta(Ac)&&(n=new fe(n.done,n.undone,null,0,-1));let s=t.getMeta("appendedTransaction");if(t.steps.length==0)return n;if(s&&s.getMeta(Ne))return s.getMeta(Ne).redo?new fe(n.done.addTransform(t,void 0,r,yn(e)),n.undone,_o(t.mapping.maps[t.steps.length-1]),n.prevTime,n.prevComposition):new fe(n.done,n.undone.addTransform(t,void 0,r,yn(e)),null,n.prevTime,n.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(s&&s.getMeta("addToHistory")===!1)){let l=t.getMeta("composition"),a=n.prevTime==0||!s&&n.prevComposition!=l&&(n.prevTime<(t.time||0)-r.newGroupDelay||!Ic(t,n.prevRanges)),c=s?Dr(n.prevRanges,t.mapping):_o(t.mapping.maps[t.steps.length-1]);return new fe(n.done.addTransform(t,a?e.selection.getBookmark():void 0,r,yn(e)),He.empty,c,t.time,l==null?n.prevComposition:l)}else return(o=t.getMeta("rebased"))?new fe(n.done.rebased(t,o),n.undone.rebased(t,o),Dr(n.prevRanges,t.mapping),n.prevTime,n.prevComposition):new fe(n.done.addMaps(t.mapping.maps),n.undone.addMaps(t.mapping.maps),Dr(n.prevRanges,t.mapping),n.prevTime,n.prevComposition)}function Ic(n,e){if(!e)return!1;if(!n.docChanged)return!0;let t=!1;return n.mapping.maps[0].forEach((r,i)=>{for(let o=0;o=e[o]&&(t=!0)}),t}function _o(n){let e=[];return n.forEach((t,r,i,o)=>e.push(i,o)),e}function Dr(n,e){if(!n)return null;let t=[];for(let r=0;r{let t=Ne.getState(n);return!t||t.done.eventCount==0?!1:(e&&Go(t,n,e,!1),!0)},rt=(n,e)=>{let t=Ne.getState(n);return!t||t.undone.eventCount==0?!1:(e&&Go(t,n,e,!0),!0)};var vc=["p",0],Pc=["blockquote",0],Rc=["hr"],zc=["pre",["code",0]],Bc=["br"],ye={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return vc}},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM(){return Pc}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return Rc}},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(n){return["h"+n.attrs.level,0]}},code_block:{content:"text*",marks:"",group:"block",code:!0,defining:!0,parseDOM:[{tag:"pre",preserveWhitespace:"full"}],toDOM(){return zc}},text:{group:"inline"},image:{inline:!0,attrs:{src:{},alt:{default:null},title:{default:null}},group:"inline",draggable:!0,parseDOM:[{tag:"img[src]",getAttrs(n){return{src:n.getAttribute("src"),title:n.getAttribute("title"),alt:n.getAttribute("alt")}}}],toDOM(n){let{src:e,alt:t,title:r}=n.attrs;return["img",{src:e,alt:t,title:r}]}},hard_break:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM(){return Bc}}},Fc=["em",0],Vc=["strong",0],Lc=["code",0],It={link:{attrs:{href:{},title:{default:null}},inclusive:!1,parseDOM:[{tag:"a[href]",getAttrs(n){return{href:n.getAttribute("href"),title:n.getAttribute("title")}}}],toDOM(n){let{href:e,title:t}=n.attrs;return["a",{href:e,title:t},0]}},em:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"},{style:"font-style=normal",clearMark:n=>n.type.name=="em"}],toDOM(){return Fc}},strong:{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:n=>n.style.fontWeight!="normal"&&null},{style:"font-weight=400",clearMark:n=>n.type.name=="strong"},{style:"font-weight",getAttrs:n=>/^(bold(er)?|[5-9]\d{2,})$/.test(n)&&null}],toDOM(){return Vc}},code:{parseDOM:[{tag:"code"}],toDOM(){return Lc}}},Dh=new Pe({nodes:ye,marks:It});var Jc=["ol",0],Wc=["ul",0],qc=["li",0],Kc={attrs:{order:{default:1}},parseDOM:[{tag:"ol",getAttrs(n){return{order:n.hasAttribute("start")?+n.getAttribute("start"):1}}}],toDOM(n){return n.attrs.order==1?Jc:["ol",{start:n.attrs.order},0]}},$c={parseDOM:[{tag:"ul"}],toDOM(){return Wc}},Hc={parseDOM:[{tag:"li"}],toDOM(){return qc},defining:!0};function Ir(n,e){let t={};for(let r in n)t[r]=n[r];for(let r in e)t[r]=e[r];return t}function Xo(n,e,t){return n.append({ordered_list:Ir(Kc,{content:"list_item+",group:t}),bullet_list:Ir($c,{content:"list_item+",group:t}),list_item:Ir(Hc,{content:e})})}function it(n,e=null){return function(t,r){let{$from:i,$to:o}=t.selection,s=i.blockRange(o),l=!1,a=s;if(!s)return!1;if(s.depth>=2&&i.node(s.depth-1).type.compatibleContent(n)&&s.startIndex==0){if(i.index(s.depth-1)==0)return!1;let f=t.doc.resolve(s.start-2);a=new Ae(f,f,s.depth),s.endIndex=0;f--)o=y.from(t[f].type.create(t[f].attrs,o));n.step(new E(e.start-(r?2:0),e.end,e.start,e.end,new b(o,0,0),t.length,!0));let s=0;for(let f=0;f=i.depth-3;k--)h=y.from(i.node(k).copy(h));let p=i.indexAfter(-1){if(g>-1)return!1;k.isTextblock&&k.content.size==0&&(g=N+1)}),g>-1&&m.setSelection(S.near(m.doc.resolve(g))),r(m.scrollIntoView())}return!0}let a=o.pos==i.end()?l.contentMatchAt(0).defaultType:null,c=t.tr.delete(i.pos,o.pos),f=a?[e?{type:n,attrs:e}:null,{type:a}]:void 0;return ke(c.doc,i.pos,2,f)?(r&&r(c.split(i.pos,2,f).scrollIntoView()),!0):!1}}function Zo(n){return function(e,t){let{$from:r,$to:i}=e.selection,o=r.blockRange(i,s=>s.childCount>0&&s.firstChild.type==n);return o?t?r.node(o.depth-1).type==n?_c(e,t,n,o):Uc(e,t,o):!0:!1}}function _c(n,e,t,r){let i=n.tr,o=r.end,s=r.$to.end(r.depth);om;u--)p-=i.child(u).nodeSize,r.delete(p-1,p+1);let o=r.doc.resolve(t.start),s=o.nodeAfter;if(r.mapping.map(t.end)!=t.start+o.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,a=t.endIndex==i.childCount,c=o.node(-1),f=o.index(-1);if(!c.canReplace(f+(l?0:1),f+1,s.content.append(a?y.empty:y.from(i))))return!1;let h=o.pos,d=h+s.nodeSize;return r.step(new E(h-(l?1:0),d+(a?1:0),h+1,d-1,new b((l?y.empty:y.from(i.copy(y.empty))).append(a?y.empty:y.from(i.copy(y.empty))),l?0:1,a?0:1),l?0:1)),e(r.scrollIntoView()),!0}function es(n){return function(e,t){let{$from:r,$to:i}=e.selection,o=r.blockRange(i,c=>c.childCount>0&&c.firstChild.type==n);if(!o)return!1;let s=o.startIndex;if(s==0)return!1;let l=o.parent,a=l.child(s-1);if(a.type!=n)return!1;if(t){let c=a.lastChild&&a.lastChild.type==l.type,f=y.from(c?n.create():null),h=new b(y.from(n.create(null,y.from(l.type.create(null,f)))),c?3:1,0),d=o.start,p=o.end;t(e.tr.step(new E(d-(c?3:1),p,d,p,h,1,!0)).scrollIntoView())}return!0}}var Te=class{constructor(e,t,r={}){this.match=e,this.match=e,this.handler=typeof t=="string"?Gc(t):t,this.undoable=r.undoable!==!1,this.inCode=r.inCode||!1}};function Gc(n){return function(e,t,r,i){let o=n;if(t[1]){let s=t[0].lastIndexOf(t[1]);o+=t[0].slice(s+t[1].length),r+=s;let l=r-i;l>0&&(o=t[0].slice(s-l,s)+o,r=i)}return e.tr.insertText(o,r,i)}}var ts=(n,e)=>{let t=n.plugins;for(let r=0;r=0;a--)s.step(l.steps[a].invert(l.docs[a]));if(o.text){let a=s.doc.resolve(o.from).marks();s.replaceWith(o.from,o.to,n.schema.text(o.text,a))}else s.delete(o.from,o.to);e(s)}return!0}}return!1},Rh=new Te(/--$/,"\u2014"),zh=new Te(/\.\.\.$/,"\u2026"),Bh=new Te(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C"),Fh=new Te(/"$/,"\u201D"),Vh=new Te(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018"),Lh=new Te(/'$/,"\u2019");function Yc(n,e){let t=Object.keys(e);return t.length?!!t.filter(r=>e[r]===n[r]).length:!0}function Ar(n,e,t={}){return n.find(r=>r.type===e&&Yc(r.attrs,t))}function Xc(n,e,t={}){return!!Ar(n,e,t)}function vr(n,e,t={}){if(!n||!e)return;let r=n.parent.childAfter(n.parentOffset);if(!r.node)return;let i=Ar(r.node.marks,e,t);if(!i)return;let o=n.index(),s=n.start()+r.offset,l=o+1,a=s+r.node.nodeSize;for(Ar(r.node.marks,e,t);o>0&&i.isInSet(n.parent.child(o-1).marks);)o-=1,s-=n.parent.child(o).nodeSize;for(;l=e||H<0||h&&ne>=o}function k(){var C=kn();if(g(C))return N(C);l=setTimeout(k,m(C))}function N(C){return l=void 0,d&&r?p(C):(r=i=void 0,s)}function ee(){l!==void 0&&clearTimeout(l),c=0,r=a=i=l=void 0}function te(){return l===void 0?s:N(kn())}function U(){var C=kn(),H=g(C);if(r=arguments,i=this,a=C,H){if(l===void 0)return u(a);if(h)return clearTimeout(l),l=setTimeout(k,e),p(a)}return l===void 0&&(l=setTimeout(k,e)),s}return U.cancel=ee,U.flush=te,U}var ps=Ef;var Q=(n,e=null)=>{let t=document.createElement(n);if(e)for(let[r,i]of Object.entries(e))/^data-|^aria-|^role/.test(r)?t.setAttribute(r,i):t[r]=i;return t};function xn(n,e){let t=document.createElement("article");return t.innerHTML=e,Re.fromSchema(n).parse(t)}function ms(n){let{schema:e,doc:t}=n.state,r=ie.fromSchema(e),i=Q("article");return i.appendChild(r.serializeFragment(t.content)),i.innerHTML}var gs=(n,e,t)=>{let r=ie.fromSchema(n),i=function(){let s=Q("article");return s.appendChild(r.serializeFragment(e.state.doc.content)),s.innerHTML};return ps(()=>{let s=i();t.value!==s&&(t.value=s,t.dispatchEvent(new InputEvent("input",{bubbles:!0,cancelable:!0})))},250)};var ys=n=>{let{$from:e,$to:t}=n,r=e.pos,i=t.pos,o=e.nodeAfter,s=t.nodeBefore,l=o&&o.isText?/^\s*/.exec(o.text)[0].length:0,a=s&&s.isText?/\s*$/.exec(s.text)[0].length:0;return r+lnew Promise(e=>{let t=document.createElement("div");t.innerHTML=` +`))),0,0):b.empty;let h=n.someProp("clipboardTextParser",d=>d(e,i,r,n));if(h)l=h;else{let d=i.marks(),{schema:p}=n.state,u=ie.fromSchema(p);s=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=s.appendChild(document.createElement("p"));m&&g.appendChild(u.serializeNode(p.text(m,d)))})}}else n.someProp("transformPastedHTML",h=>{t=h(t,n)}),s=La(t),Dt&&Ja(s);let c=s&&s.querySelector("[data-pm-slice]"),f=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(f&&f[3])for(let h=+f[3];h>0;h--){let d=s.firstChild;for(;d&&d.nodeType!=1;)d=d.nextSibling;if(!d)break;s=d}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||Re.fromSchema(n.state.schema)).parseSlice(s,{preserveWhitespace:!!(a||f),context:i,ruleFromNode(d){return d.nodeName=="BR"&&!d.nextSibling&&d.parentNode&&!Fa.test(d.parentNode.nodeName)?{ignore:!0}:null}})),f)l=Wa(no(l,+f[1],+f[2]),f[4]);else if(l=b.maxOpen(Va(l.content,i),!0),l.openStart||l.openEnd){let h=0,d=0;for(let p=l.content.firstChild;h{l=h(l,n)}),l}var Fa=/^(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 Va(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),o,s=[];if(n.forEach(l=>{if(!s)return;let a=i.findWrapping(l.type),c;if(!a)return s=null;if(c=s.length&&o.length&&vo(a,o,l,s[s.length-1],0))s[s.length-1]=c;else{s.length&&(s[s.length-1]=Po(s[s.length-1],o.length));let f=Ao(l,a);s.push(f),i=i.matchType(f.type),o=a}}),s)return y.from(s)}return n}function Ao(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,y.from(n));return n}function vo(n,e,t,r,i){if(i1&&(o=0),i=t&&(l=e<0?s.contentMatchAt(0).fillBefore(l,o<=i).append(l):l.append(s.contentMatchAt(s.childCount).fillBefore(y.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,s.copy(l))}function no(n,e,t){return e]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=zo().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&Ro[r[1].toLowerCase()])&&(n=i.map(o=>"<"+o+">").join("")+n+i.map(o=>"").reverse().join("")),t.innerHTML=n,i)for(let o=0;o=0;l-=2){let a=t.nodes[r[l]];if(!a||a.hasRequiredAttrs())break;i=y.from(a.create(r[l+1],i)),o++,s++}return new b(i,o,s)}var V={},L={},qa={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 Ka(n){for(let e in V){let t=V[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{$a(n,r)&&!Mr(n,r)&&(n.editable||!(r.type in L))&&t(n,r)},qa[e]?{passive:!0}:void 0)}F&&n.dom.addEventListener("input",()=>null),ur(n)}function Me(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function Ha(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function ur(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>Mr(n,r))})}function Mr(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function $a(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function ja(n,e){!Mr(n,e)&&V[e.type]&&(n.editable||!(e.type in L))&&V[e.type](n,e)}L.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!Fo(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(Y&&R&&t.keyCode==13)))if(t.keyCode!=229&&n.domObserver.forceFlush(),tt&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let r=Date.now();n.input.lastIOSEnter=r,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==r&&(n.someProp("handleKeyDown",i=>i(n,Fe(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||Ba(n,t)?t.preventDefault():Me(n,"key")};L.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};L.keypress=(n,e)=>{let t=e;if(Fo(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||j&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof w)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(t.charCode);!/[\r\n]/.test(i)&&!n.someProp("handleTextInput",o=>o(n,r.$from.pos,r.$to.pos,i))&&n.dispatch(n.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function pn(n){return{left:n.clientX,top:n.clientY}}function _a(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function Cr(n,e,t,r,i){if(r==-1)return!1;let o=n.state.doc.resolve(r);for(let s=o.depth+1;s>0;s--)if(n.someProp(e,l=>s>o.depth?l(n,t,o.nodeAfter,o.before(s),i,!0):l(n,t,o.node(s),o.before(s),i,!1)))return!0;return!1}function et(n,e,t){n.focused||n.focus();let r=n.state.tr.setSelection(e);t=="pointer"&&r.setMeta("pointer",!0),n.dispatch(r)}function Ua(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&x.isSelectable(r)?(et(n,new x(t),"pointer"),!0):!1}function Ga(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof x&&(r=t.node);let o=n.state.doc.resolve(e);for(let s=o.depth+1;s>0;s--){let l=s>o.depth?o.nodeAfter:o.node(s);if(x.isSelectable(l)){r&&t.$from.depth>0&&s>=t.$from.depth&&o.before(t.$from.depth+1)==t.$from.pos?i=o.before(t.$from.depth):i=o.before(s);break}}return i!=null?(et(n,x.create(n.state.doc,i),"pointer"),!0):!1}function Ya(n,e,t,r,i){return Cr(n,"handleClickOn",e,t,r)||n.someProp("handleClick",o=>o(n,e,r))||(i?Ga(n,t):Ua(n,t))}function Xa(n,e,t,r){return Cr(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function Qa(n,e,t,r){return Cr(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||Za(n,t,r)}function Za(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(et(n,w.create(r,0,r.content.size),"pointer"),!0):!1;let i=r.resolve(e);for(let o=i.depth+1;o>0;o--){let s=o>i.depth?i.nodeAfter:i.node(o),l=i.before(o);if(s.inlineContent)et(n,w.create(r,l+1,l+1+s.content.size),"pointer");else if(x.isSelectable(s))et(n,x.create(r,l),"pointer");else continue;return!0}}function Or(n){return ln(n)}var Bo=j?"metaKey":"ctrlKey";V.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=Or(n),i=Date.now(),o="singleClick";i-n.input.lastClick.time<500&&_a(t,n.input.lastClick)&&!t[Bo]&&(n.input.lastClick.type=="singleClick"?o="doubleClick":n.input.lastClick.type=="doubleClick"&&(o="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:o};let s=n.posAtCoords(pn(t));s&&(o=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new pr(n,s,t,!!r)):(o=="doubleClick"?Xa:Qa)(n,s.pos,s.inside,t)?t.preventDefault():Me(n,"pointer"))};var pr=class{constructor(e,t,r,i){this.view=e,this.pos=t,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[Bo],this.allowDefault=r.shiftKey;let o,s;if(t.inside>-1)o=e.state.doc.nodeAt(t.inside),s=t.inside;else{let f=e.state.doc.resolve(t.pos);o=f.parent,s=f.depth?f.before():0}let l=i?null:r.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a?a.dom:null;let{selection:c}=e.state;(r.button==0&&o.type.spec.draggable&&o.type.spec.selectable!==!1||c instanceof x&&c.from<=s&&c.to>s)&&(this.mightDrag={node:o,pos:s,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&X&&!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)),Me(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(()=>ge(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(pn(e))),this.updateAllowDefault(e),this.allowDefault||!t?Me(this.view,"pointer"):Ya(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||F&&this.mightDrag&&!this.mightDrag.node.isAtom||R&&!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)?(et(this.view,S.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):Me(this.view,"pointer")}move(e){this.updateAllowDefault(e),Me(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)}};V.touchstart=n=>{n.input.lastTouch=Date.now(),Or(n),Me(n,"pointer")};V.touchmove=n=>{n.input.lastTouch=Date.now(),Me(n,"pointer")};V.contextmenu=n=>Or(n);function Fo(n,e){return n.composing?!0:F&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}var ec=Y?5e3:-1;L.compositionstart=L.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$from;if(e.selection.empty&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))n.markCursor=n.state.storedMarks||t.marks(),ln(n,!0),n.markCursor=null;else if(ln(n),X&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let i=r.focusNode,o=r.focusOffset;i&&i.nodeType==1&&o!=0;){let s=o<0?i.lastChild:i.childNodes[o-1];if(!s)break;if(s.nodeType==3){n.domSelection().collapse(s,s.nodeValue.length);break}else i=s,o=-1}}n.input.composing=!0}Vo(n,ec)};L.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,Vo(n,20))};function Vo(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>ln(n),e))}function Lo(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=tc());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function tc(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function ln(n,e=!1){if(!(Y&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),Lo(n),e||n.docView&&n.docView.dirty){let t=xr(n);return t&&!t.eq(n.state.selection)?n.dispatch(n.state.tr.setSelection(t)):n.updateState(n.state),!0}return!1}}function nc(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),n.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}var wt=W&&Ce<15||tt&&ia<604;V.copy=L.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let o=wt?null:t.clipboardData,s=r.content(),{dom:l,text:a}=Eo(n,s);o?(t.preventDefault(),o.clearData(),o.setData("text/html",l.innerHTML),o.setData("text/plain",a)):nc(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function rc(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function ic(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,r=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),r.parentNode&&r.parentNode.removeChild(r),t?Nt(n,r.value,null,i,e):Nt(n,r.textContent,r.innerHTML,i,e)},50)}function Nt(n,e,t,r,i){let o=Io(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",a=>a(n,i,o||b.empty)))return!0;if(!o)return!1;let s=rc(o),l=s?n.state.tr.replaceSelectionWith(s,r):n.state.tr.replaceSelection(o);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Jo(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}L.paste=(n,e)=>{let t=e;if(n.composing&&!Y)return;let r=wt?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&Nt(n,Jo(r),r.getData("text/html"),i,t)?t.preventDefault():ic(n,t)};var an=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}},Wo=j?"altKey":"ctrlKey";V.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=n.state.selection,o=i.empty?null:n.posAtCoords(pn(t)),s;if(!(o&&o.pos>=i.from&&o.pos<=(i instanceof x?i.to-1:i.to))){if(r&&r.mightDrag)s=x.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let f=n.docView.nearestDesc(t.target,!0);f&&f.node.type.spec.draggable&&f!=n.docView&&(s=x.create(n.state.doc,f.posBefore))}}let l=(s||n.state.selection).content(),{dom:a,text:c}=Eo(n,l);t.dataTransfer.clearData(),t.dataTransfer.setData(wt?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",wt||t.dataTransfer.setData("text/plain",c),n.dragging=new an(l,!t[Wo],s)};V.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};L.dragover=L.dragenter=(n,e)=>e.preventDefault();L.drop=(n,e)=>{let t=e,r=n.dragging;if(n.dragging=null,!t.dataTransfer)return;let i=n.posAtCoords(pn(t));if(!i)return;let o=n.state.doc.resolve(i.pos),s=r&&r.slice;s?n.someProp("transformPasted",u=>{s=u(s,n)}):s=Io(n,Jo(t.dataTransfer),wt?null:t.dataTransfer.getData("text/html"),!1,o);let l=!!(r&&!t[Wo]);if(n.someProp("handleDrop",u=>u(n,t,s||b.empty,l))){t.preventDefault();return}if(!s)return;t.preventDefault();let a=s?Ut(n.state.doc,o.pos,s):o.pos;a==null&&(a=o.pos);let c=n.state.tr;if(l){let{node:u}=r;u?u.replace(c):c.deleteSelection()}let f=c.mapping.map(a),h=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,d=c.doc;if(h?c.replaceRangeWith(f,f,s.content.firstChild):c.replaceRange(f,f,s),c.doc.eq(d))return;let p=c.doc.resolve(f);if(h&&x.isSelectable(s.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(s.content.firstChild))c.setSelection(new x(p));else{let u=c.mapping.map(a);c.mapping.maps[c.mapping.maps.length-1].forEach((m,g,k,N)=>u=N),c.setSelection(Sr(n,p,c.doc.resolve(u)))}n.focus(),n.dispatch(c.setMeta("uiEvent","drop"))};V.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&ge(n)},20))};V.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)};V.beforeinput=(n,e)=>{if(R&&Y&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:r}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=r||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",o=>o(n,Fe(8,"Backspace")))))return;let{$cursor:i}=n.state.selection;i&&i.pos>0&&n.dispatch(n.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let n in L)V[n]=L[n];function Tt(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}var cn=class n{constructor(e,t){this.toDOM=e,this.spec=t||We,this.side=this.spec.side||0}map(e,t,r,i){let{pos:o,deleted:s}=e.mapResult(t.from+i,this.side<0?-1:1);return s?null:new ae(o-r,o-r,this)}valid(){return!0}eq(e){return this==e||e instanceof n&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Tt(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},Je=class n{constructor(e,t){this.attrs=e,this.spec=t||We}map(e,t,r,i){let o=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,s=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return o>=s?null:new ae(o,s,this)}valid(e,t){return t.from=e&&(!o||o(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let s=0;se){let l=this.children[s]+1;this.children[s+2].findInner(e-l,t-l,r,i+l,o)}}map(e,t,r){return this==P||e.maps.length==0?this:this.mapInner(e,t,0,0,r||We)}mapInner(e,t,r,i,o){let s;for(let l=0;l{let c=a+r,f;if(f=Ko(t,l,c)){for(i||(i=this.children.slice());ol&&h.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let o=e+1,s=o+t.content.size;for(let l=0;lo&&a.type instanceof Je){let c=Math.max(o,a.from)-o,f=Math.min(s,a.to)-o;ci.map(e,t,We));return n.from(r)}forChild(e,t){if(t.isLeaf)return q.empty;let r=[];for(let i=0;it instanceof q)?e:e.reduce((t,r)=>t.concat(r instanceof q?r:r.members),[]))}}};function oc(n,e,t,r,i,o,s){let l=n.slice();for(let c=0,f=o;c{let g=m-u-(p-d);for(let k=0;kN+f-h)continue;let ee=l[k]+f-h;p>=ee?l[k+1]=d<=ee?-2:-1:d>=f&&g&&(l[k]+=g,l[k+1]+=g)}h+=g}),f=t.maps[c].map(f,-1)}let a=!1;for(let c=0;c=r.content.size){a=!0;continue}let d=t.map(n[c+1]+o,-1),p=d-i,{index:u,offset:m}=r.content.findIndex(h),g=r.maybeChild(u);if(g&&m==h&&m+g.nodeSize==p){let k=l[c+2].mapInner(t,g,f+1,n[c]+o+1,s);k!=P?(l[c]=h,l[c+1]=p,l[c+2]=k):(l[c+1]=-2,a=!0)}else a=!0}if(a){let c=sc(l,n,e,t,i,o,s),f=hn(c,r,0,s);e=f.local;for(let h=0;ht&&s.to{let c=Ko(n,l,a+t);if(c){o=!0;let f=hn(c,l,t+a+1,r);f!=P&&i.push(a,a+l.nodeSize,f)}});let s=qo(o?Ho(n):n,-t).sort(qe);for(let l=0;l0;)e++;n.splice(e,0,t)}function Qn(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=P&&e.push(r)}),n.cursorWrapper&&e.push(q.create(n.state.doc,[n.cursorWrapper.deco])),fn.from(e)}var lc={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},ac=W&&Ce<=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(r=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),ac&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.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,lc)),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 ge(this.view);if(W&&Ce<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Ke(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,r;for(let o=e.focusNode;o;o=Ot(o))t.add(o);for(let o=e.anchorNode;o;o=Ot(o))if(t.has(o)){r=o;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))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 r=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&Yi(e)&&!this.ignoreSelectionChange(r),o=-1,s=-1,l=!1,a=[];if(e.editable)for(let f=0;f1){let f=a.filter(h=>h.nodeName=="BR");if(f.length==2){let h=f[0],d=f[1];h.parentNode&&h.parentNode.parentNode==d.parentNode?d.remove():h.remove()}}let c=null;o<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(o>-1&&(e.docView.markDirty(o,s),cc(e)),this.handleDOMChange(o,s,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||ge(e),this.currentSelection.set(r))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let f=0;fi;g--){let k=r.childNodes[g-1],N=k.pmViewDesc;if(k.nodeName=="BR"&&!N){o=g;break}if(!N||N.size)break}let h=n.state.doc,d=n.someProp("domParser")||Re.fromSchema(n.state.schema),p=h.resolve(s),u=null,m=d.parse(r,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:i,to:o,preserveWhitespace:p.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:dc,context:p});if(c&&c[0].pos!=null){let g=c[0].pos,k=c[1]&&c[1].pos;k==null&&(k=g),u={anchor:g+s,head:k+s}}return{doc:m,sel:u,from:s,to:l}}function dc(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(F&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||F&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}var uc=/^(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 pc(n,e,t,r,i){let o=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let M=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,be=xr(n,M);if(be&&!n.state.selection.eq(be)){if(R&&Y&&n.input.lastKeyCode===13&&Date.now()-100zs(n,Fe(13,"Enter"))))return;let Pt=n.state.tr.setSelection(be);M=="pointer"?Pt.setMeta("pointer",!0):M=="key"&&Pt.scrollIntoView(),o&&Pt.setMeta("composition",o),n.dispatch(Pt)}return}let s=n.state.doc.resolve(e),l=s.sharedDepth(t);e=s.before(l+1),t=n.state.doc.resolve(t).after(l+1);let a=n.state.selection,c=hc(n,e,t),f=n.state.doc,h=f.slice(c.from,c.to),d,p;n.input.lastKeyCode===8&&Date.now()-100Date.now()-225||Y)&&i.some(M=>M.nodeType==1&&!uc.test(M.nodeName))&&(!u||u.endA>=u.endB)&&n.someProp("handleKeyDown",M=>M(n,Fe(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!u)if(r&&a instanceof w&&!a.empty&&a.$head.sameParent(a.$anchor)&&!n.composing&&!(c.sel&&c.sel.anchor!=c.sel.head))u={start:a.from,endA:a.to,endB:a.to};else{if(c.sel){let M=lo(n,n.state.doc,c.sel);if(M&&!M.eq(n.state.selection)){let be=n.state.tr.setSelection(M);o&&be.setMeta("composition",o),n.dispatch(be)}}return}if(R&&n.cursorWrapper&&c.sel&&c.sel.anchor==n.cursorWrapper.deco.from&&c.sel.head==c.sel.anchor){let M=u.endB-u.start;c.sel={anchor:c.sel.anchor+M,head:c.sel.anchor+M}}n.input.domChangeCount++,n.state.selection.fromn.state.selection.from&&u.start<=n.state.selection.from+2&&n.state.selection.from>=c.from?u.start=n.state.selection.from:u.endA=n.state.selection.to-2&&n.state.selection.to<=c.to&&(u.endB+=n.state.selection.to-u.endA,u.endA=n.state.selection.to)),W&&Ce<=11&&u.endB==u.start+1&&u.endA==u.start&&u.start>c.from&&c.doc.textBetween(u.start-c.from-1,u.start-c.from+1)==" \xA0"&&(u.start--,u.endA--,u.endB--);let m=c.doc.resolveNoCache(u.start-c.from),g=c.doc.resolveNoCache(u.endB-c.from),k=f.resolve(u.start),N=m.sameParent(g)&&m.parent.inlineContent&&k.end()>=u.endA,ee;if((tt&&n.input.lastIOSEnter>Date.now()-225&&(!N||i.some(M=>M.nodeName=="DIV"||M.nodeName=="P"))||!N&&m.posM(n,Fe(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>u.start&&gc(f,u.start,u.endA,m,g)&&n.someProp("handleKeyDown",M=>M(n,Fe(8,"Backspace")))){Y&&R&&n.domObserver.suppressSelectionUpdates();return}R&&Y&&u.endB==u.start&&(n.input.lastAndroidDelete=Date.now()),Y&&!N&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&c.sel&&c.sel.anchor==c.sel.head&&c.sel.head==u.endA&&(u.endB-=2,g=c.doc.resolveNoCache(u.endB-c.from),setTimeout(()=>{n.someProp("handleKeyDown",function(M){return M(n,Fe(13,"Enter"))})},20));let te=u.start,U=u.endA,C,$,ne;if(N){if(m.pos==g.pos)W&&Ce<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>ge(n),20)),C=n.state.tr.delete(te,U),$=f.resolve(u.start).marksAcross(f.resolve(u.endA));else if(u.endA==u.endB&&(ne=mc(m.parent.content.cut(m.parentOffset,g.parentOffset),k.parent.content.cut(k.parentOffset,u.endA-k.start()))))C=n.state.tr,ne.type=="add"?C.addMark(te,U,ne.mark):C.removeMark(te,U,ne.mark);else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let M=m.parent.textBetween(m.parentOffset,g.parentOffset);if(n.someProp("handleTextInput",be=>be(n,te,U,M)))return;C=n.state.tr.insertText(M,te,U)}}if(C||(C=n.state.tr.replace(te,U,c.doc.slice(u.start-c.from,u.endB-c.from))),c.sel){let M=lo(n,C.doc,c.sel);M&&!(R&&Y&&n.composing&&M.empty&&(u.start!=u.endB||n.input.lastAndroidDeletee.content.size?null:Sr(n,e.resolve(t.anchor),e.resolve(t.head))}function mc(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,o=r,s,l,a;for(let f=0;ff.mark(l.addToSet(f.marks));else if(i.length==0&&o.length==1)l=o[0],s="remove",a=f=>f.mark(l.removeFromSet(f.marks));else return null;let c=[];for(let f=0;ft||Zn(s,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let o=n.node(r).maybeChild(n.indexAfter(r));for(;o&&!o.isLeaf;)o=o.firstChild,i++}return i}function yc(n,e,t,r,i){let o=n.findDiffStart(e,t);if(o==null)return null;let{a:s,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let a=Math.max(0,o-Math.min(s,l));r-=s+a-o}if(s=s?o-r:0;o-=a,o&&o=l?o-r:0;o-=a,o&&o=56320&&e<=57343&&t>=55296&&t<=56319}var dn=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(po),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=ho(this),fo(this),this.nodeViews=uo(this),this.docView=Hi(this.state.doc,co(this),Qn(this),this.dom,this),this.domObserver=new yr(this,(r,i,o,s)=>pc(this,r,i,o,s)),this.domObserver.start(),Ka(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&&ur(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(po),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let r in this._props)t[r]=this._props[r];t.state=this.state;for(let r in e)t[r]=e[r];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var r;let i=this.state,o=!1,s=!1;e.storedMarks&&this.composing&&(Lo(this),s=!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=uo(this);kc(p,this.nodeViews)&&(this.nodeViews=p,o=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&ur(this),this.editable=ho(this),fo(this);let a=Qn(this),c=co(this),f=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",h=o||!this.docView.matchesNode(e.doc,c,a);(h||!e.selection.eq(i.selection))&&(s=!0);let d=f=="preserve"&&s&&this.dom.style.overflowAnchor==null&&la(this);if(s){this.domObserver.stop();let p=h&&(W||R)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&bc(i.selection,e.selection);if(h){let u=R?this.trackWrites=this.domSelectionRange().focusNode:null;(o||!this.docView.update(e.doc,c,a,this))&&(this.docView.updateOuterDeco([]),this.docView.destroy(),this.docView=Hi(e.doc,c,a,this.dom,this)),u&&!this.trackWrites&&(p=!0)}p||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Ea(this))?ge(this,p):(No(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),f=="reset"?this.dom.scrollTop=0:f=="to selection"?this.scrollToSelection():d&&aa(d)}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&&Vi(this,t.getBoundingClientRect(),e)}else Vi(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(o))==r.node&&(i=o)}this.dragging=new an(e.slice,e.move,i<0?void 0:x.create(this.state.doc,i))}someProp(e,t){let r=this._props&&this._props[e],i;if(r!=null&&(i=t?t(r):r))return i;for(let s=0;st.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return pa(this,e)}coordsAtPos(e,t=1){return xo(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,r=-1){let i=this.docView.posFromDOM(e,t,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return ka(this,t||this.state,e)}pasteHTML(e,t){return Nt(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return Nt(this,e,null,!0,t||new ClipboardEvent("paste"))}destroy(){this.docView&&(Ha(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Qn(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 ja(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){return F&&this.root.nodeType===11&&ea(this.dom.ownerDocument)==this.dom?fc(this):this.domSelection()}domSelection(){return this.root.getSelection()}};function co(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let r in t)r=="class"?e.class+=" "+t[r]:r=="style"?e.style=(e.style?e.style+";":"")+t[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(t[r]))}),e.translate||(e.translate="no"),[ae.node(0,n.state.doc.content.size,e)]}function fo(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:ae.widget(n.state.selection.head,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function ho(n){return!n.someProp("editable",e=>e(n.state)===!1)}function bc(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function uo(n){let e=Object.create(null);function t(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function kc(n,e){let t=0,r=0;for(let i in n){if(n[i]!=e[i])return!0;t++}for(let i in e)r++;return t!=r}function po(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}var z=class n extends S{constructor(e){super(e,e)}map(e,t){let r=e.resolve(t.map(this.head));return n.valid(r)?new n(r):S.near(r)}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 Nr(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!xc(e)||!Sc(e))return!1;let r=t.type.spec.allowGapCursor;if(r!=null)return r;let i=t.contentMatchAt(e.index()).defaultType;return i&&i.isTextblock}static findGapCursorFrom(e,t,r=!1){e:for(;;){if(!r&&n.valid(e))return e;let i=e.pos,o=null;for(let s=e.depth;;s--){let l=e.node(s);if(t>0?e.indexAfter(s)0){o=l.child(t>0?e.indexAfter(s):e.index(s)-1);break}else if(s==0)return null;i+=t;let a=e.doc.resolve(i);if(n.valid(a))return a}for(;;){let s=t>0?o.firstChild:o.lastChild;if(!s){if(o.isAtom&&!o.isText&&!x.isSelectable(o)){e=e.doc.resolve(i+o.nodeSize*t),r=!1;continue e}break}o=s,i+=t;let l=e.doc.resolve(i);if(n.valid(l))return l}return null}}};z.prototype.visible=!1;z.findFrom=z.findGapCursorFrom;S.jsonID("gapcursor",z);var Nr=class n{constructor(e){this.pos=e}map(e){return new n(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return z.valid(t)?new z(t):S.near(t)}};function xc(n){for(let e=n.depth;e>=0;e--){let t=n.index(e),r=n.node(e);if(t==0){if(r.type.spec.isolating)return!0;continue}for(let i=r.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 Sc(n){for(let e=n.depth;e>=0;e--){let t=n.indexAfter(e),r=n.node(e);if(t==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let i=r.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 $o(){return new J({props:{decorations:wc,createSelectionBetween(n,e,t){return e.pos==t.pos&&z.valid(t)?new z(t):null},handleClick:Cc,handleKeyDown:Mc,handleDOMEvents:{beforeinput:Oc}}})}var Mc=Gn({ArrowLeft:mn("horiz",-1),ArrowRight:mn("horiz",1),ArrowUp:mn("vert",-1),ArrowDown:mn("vert",1)});function mn(n,e){let t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,i,o){let s=r.selection,l=e>0?s.$to:s.$from,a=s.empty;if(s instanceof w){if(!o.endOfTextblock(t)||l.depth==0)return!1;a=!1,l=r.doc.resolve(e>0?l.after():l.before())}let c=z.findGapCursorFrom(l,e,a);return c?(i&&i(r.tr.setSelection(new z(c))),!0):!1}}function Cc(n,e,t){if(!n||!n.editable)return!1;let r=n.state.doc.resolve(e);if(!z.valid(r))return!1;let i=n.posAtCoords({left:t.clientX,top:t.clientY});return i&&i.inside>-1&&x.isSelectable(n.state.doc.nodeAt(i.inside))?!1:(n.dispatch(n.state.tr.setSelection(new z(r))),!0)}function Oc(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof z))return!1;let{$from:t}=n.state.selection,r=t.parent.contentMatchAt(t.index()).findWrapping(n.state.schema.nodes.text);if(!r)return!1;let i=y.empty;for(let s=r.length-1;s>=0;s--)i=y.from(r[s].createAndFill(null,i));let o=n.state.tr.replace(t.pos,t.pos,new b(i,0,0));return o.setSelection(w.near(o.doc.resolve(t.pos+1))),n.dispatch(o),!1}function wc(n){if(!(n.selection instanceof z))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",q.create(n.doc,[ae.widget(n.selection.head,e,{key:"gapcursor"})])}var gn=200,A=function(){};A.prototype.append=function(e){return e.length?(e=A.from(e),!this.length&&e||e.length=t?A.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};A.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};A.prototype.forEach=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length),t<=r?this.forEachInner(e,t,r,0):this.forEachInvertedInner(e,t,r,0)};A.prototype.map=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length);var i=[];return this.forEach(function(o,s){return i.push(e(o,s))},t,r),i};A.from=function(e){return e instanceof A?e:e&&e.length?new jo(e):A.empty};var jo=function(n){function e(r){n.call(this),this.values=r}n&&(e.__proto__=n),e.prototype=Object.create(n&&n.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,o){return i==0&&o==this.length?this:new e(this.values.slice(i,o))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,o,s,l){for(var a=o;a=s;a--)if(i(this.values[a],l+a)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=gn)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=gn)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}(A);A.empty=new jo([]);var Nc=function(n){function e(t,r){n.call(this),this.left=t,this.right=r,this.length=t.length+r.length,this.depth=Math.max(t.depth,r.depth)+1}return n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(r){return rl&&this.right.forEachInner(r,Math.max(i-l,0),Math.min(this.length,o)-l,s+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,o,s){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(r,i-l,Math.max(o,l)-l,s+l)===!1||o=o?this.right.slice(r-o,i-o):this.left.slice(r,o).append(this.right.slice(0,i-o))},e.prototype.leafAppend=function(r){var i=this.right.leafAppend(r);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(r){var i=this.left.leafPrepend(r);if(i)return new e(i,this.right)},e.prototype.appendInner=function(r){return this.left.depth>=Math.max(this.right.depth,r.depth)+1?new e(this.left,new e(this.right,r)):new e(this,r)},e}(A),Tr=A;var Tc=500,$e=class n{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,o;t&&(i=this.remapping(r,this.items.length),o=i.maps.length);let s=e.tr,l,a,c=[],f=[];return this.items.forEach((h,d)=>{if(!h.step){i||(i=this.remapping(r,d+1),o=i.maps.length),o--,f.push(h);return}if(i){f.push(new ce(h.map));let p=h.step.map(i.slice(o)),u;p&&s.maybeStep(p).doc&&(u=s.mapping.maps[s.mapping.maps.length-1],c.push(new ce(u,void 0,void 0,c.length+f.length))),o--,u&&i.appendMap(u,o)}else s.maybeStep(h.step);if(h.selection)return l=i?h.selection.map(i.slice(o)):h.selection,a=new n(this.items.slice(0,r).append(f.reverse().concat(c)),this.eventCount-1),!1},this.items.length,0),{remaining:a,transform:s,selection:l}}addTransform(e,t,r,i){let o=[],s=this.eventCount,l=this.items,a=!i&&l.length?l.get(l.length-1):null;for(let f=0;fEc&&(l=Dc(l,c),s-=c),new n(l.append(o),s)}remapping(e,t){let r=new ut;return this.items.forEach((i,o)=>{let s=i.mirrorOffset!=null&&o-i.mirrorOffset>=e?r.maps.length-i.mirrorOffset:void 0;r.appendMap(i.map,s)},e,t),r}addMaps(e){return this.eventCount==0?this:new n(this.items.append(e.map(t=>new ce(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-t),o=e.mapping,s=e.steps.length,l=this.eventCount;this.items.forEach(d=>{d.selection&&l--},i);let a=t;this.items.forEach(d=>{let p=o.getMirror(--a);if(p==null)return;s=Math.min(s,p);let u=o.maps[p];if(d.step){let m=e.steps[p].invert(e.docs[p]),g=d.selection&&d.selection.map(o.slice(a+1,p));g&&l++,r.push(new ce(u,m,g))}else r.push(new ce(u))},i);let c=[];for(let d=t;dTc&&(h=h.compress(this.items.length-r.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),r=t.maps.length,i=[],o=0;return this.items.forEach((s,l)=>{if(l>=e)i.push(s),s.selection&&o++;else if(s.step){let a=s.step.map(t.slice(r)),c=a&&a.getMap();if(r--,c&&t.appendMap(c,r),a){let f=s.selection&&s.selection.map(t.slice(r));f&&o++;let h=new ce(c.invert(),a,f),d,p=i.length-1;(d=i.length&&i[p].merge(h))?i[p]=d:i.push(h)}}else s.map&&r--},this.items.length,0),new n(Tr.from(i.reverse()),o)}};$e.empty=new $e(Tr.empty,0);function Dc(n,e){let t;return n.forEach((r,i)=>{if(r.selection&&e--==0)return t=i,!1}),n.slice(t)}var ce=class n{constructor(e,t,r,i){this.map=e,this.step=t,this.selection=r,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new n(t.getMap().invert(),t,this.selection)}}},fe=class{constructor(e,t,r,i,o){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=i,this.prevComposition=o}},Ec=20;function Ic(n,e,t,r){let i=t.getMeta(Ne),o;if(i)return i.historyState;t.getMeta(vc)&&(n=new fe(n.done,n.undone,null,0,-1));let s=t.getMeta("appendedTransaction");if(t.steps.length==0)return n;if(s&&s.getMeta(Ne))return s.getMeta(Ne).redo?new fe(n.done.addTransform(t,void 0,r,yn(e)),n.undone,_o(t.mapping.maps[t.steps.length-1]),n.prevTime,n.prevComposition):new fe(n.done,n.undone.addTransform(t,void 0,r,yn(e)),null,n.prevTime,n.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(s&&s.getMeta("addToHistory")===!1)){let l=t.getMeta("composition"),a=n.prevTime==0||!s&&n.prevComposition!=l&&(n.prevTime<(t.time||0)-r.newGroupDelay||!Ac(t,n.prevRanges)),c=s?Dr(n.prevRanges,t.mapping):_o(t.mapping.maps[t.steps.length-1]);return new fe(n.done.addTransform(t,a?e.selection.getBookmark():void 0,r,yn(e)),$e.empty,c,t.time,l==null?n.prevComposition:l)}else return(o=t.getMeta("rebased"))?new fe(n.done.rebased(t,o),n.undone.rebased(t,o),Dr(n.prevRanges,t.mapping),n.prevTime,n.prevComposition):new fe(n.done.addMaps(t.mapping.maps),n.undone.addMaps(t.mapping.maps),Dr(n.prevRanges,t.mapping),n.prevTime,n.prevComposition)}function Ac(n,e){if(!e)return!1;if(!n.docChanged)return!0;let t=!1;return n.mapping.maps[0].forEach((r,i)=>{for(let o=0;o=e[o]&&(t=!0)}),t}function _o(n){let e=[];return n.forEach((t,r,i,o)=>e.push(i,o)),e}function Dr(n,e){if(!n)return null;let t=[];for(let r=0;r{let t=Ne.getState(n);return!t||t.done.eventCount==0?!1:(e&&Go(t,n,e,!1),!0)},rt=(n,e)=>{let t=Ne.getState(n);return!t||t.undone.eventCount==0?!1:(e&&Go(t,n,e,!0),!0)};var Pc=["p",0],Rc=["blockquote",0],zc=["hr"],Bc=["pre",["code",0]],Fc=["br"],ye={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return Pc}},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM(){return Rc}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return zc}},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(n){return["h"+n.attrs.level,0]}},code_block:{content:"text*",marks:"",group:"block",code:!0,defining:!0,parseDOM:[{tag:"pre",preserveWhitespace:"full"}],toDOM(){return Bc}},text:{group:"inline"},image:{inline:!0,attrs:{src:{},alt:{default:null},title:{default:null}},group:"inline",draggable:!0,parseDOM:[{tag:"img[src]",getAttrs(n){return{src:n.getAttribute("src"),title:n.getAttribute("title"),alt:n.getAttribute("alt")}}}],toDOM(n){let{src:e,alt:t,title:r}=n.attrs;return["img",{src:e,alt:t,title:r}]}},hard_break:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM(){return Fc}}},Vc=["em",0],Lc=["strong",0],Jc=["code",0],It={link:{attrs:{href:{},title:{default:null}},inclusive:!1,parseDOM:[{tag:"a[href]",getAttrs(n){return{href:n.getAttribute("href"),title:n.getAttribute("title")}}}],toDOM(n){let{href:e,title:t}=n.attrs;return["a",{href:e,title:t},0]}},em:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"},{style:"font-style=normal",clearMark:n=>n.type.name=="em"}],toDOM(){return Vc}},strong:{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:n=>n.style.fontWeight!="normal"&&null},{style:"font-weight=400",clearMark:n=>n.type.name=="strong"},{style:"font-weight",getAttrs:n=>/^(bold(er)?|[5-9]\d{2,})$/.test(n)&&null}],toDOM(){return Lc}},code:{parseDOM:[{tag:"code"}],toDOM(){return Jc}}},Dh=new Pe({nodes:ye,marks:It});var Wc=["ol",0],qc=["ul",0],Kc=["li",0],Hc={attrs:{order:{default:1}},parseDOM:[{tag:"ol",getAttrs(n){return{order:n.hasAttribute("start")?+n.getAttribute("start"):1}}}],toDOM(n){return n.attrs.order==1?Wc:["ol",{start:n.attrs.order},0]}},$c={parseDOM:[{tag:"ul"}],toDOM(){return qc}},jc={parseDOM:[{tag:"li"}],toDOM(){return Kc},defining:!0};function Ir(n,e){let t={};for(let r in n)t[r]=n[r];for(let r in e)t[r]=e[r];return t}function Xo(n,e,t){return n.append({ordered_list:Ir(Hc,{content:"list_item+",group:t}),bullet_list:Ir($c,{content:"list_item+",group:t}),list_item:Ir(jc,{content:e})})}function it(n,e=null){return function(t,r){let{$from:i,$to:o}=t.selection,s=i.blockRange(o),l=!1,a=s;if(!s)return!1;if(s.depth>=2&&i.node(s.depth-1).type.compatibleContent(n)&&s.startIndex==0){if(i.index(s.depth-1)==0)return!1;let f=t.doc.resolve(s.start-2);a=new Ae(f,f,s.depth),s.endIndex=0;f--)o=y.from(t[f].type.create(t[f].attrs,o));n.step(new E(e.start-(r?2:0),e.end,e.start,e.end,new b(o,0,0),t.length,!0));let s=0;for(let f=0;f=i.depth-3;k--)h=y.from(i.node(k).copy(h));let p=i.indexAfter(-1){if(g>-1)return!1;k.isTextblock&&k.content.size==0&&(g=N+1)}),g>-1&&m.setSelection(S.near(m.doc.resolve(g))),r(m.scrollIntoView())}return!0}let a=o.pos==i.end()?l.contentMatchAt(0).defaultType:null,c=t.tr.delete(i.pos,o.pos),f=a?[e?{type:n,attrs:e}:null,{type:a}]:void 0;return ke(c.doc,i.pos,2,f)?(r&&r(c.split(i.pos,2,f).scrollIntoView()),!0):!1}}function Zo(n){return function(e,t){let{$from:r,$to:i}=e.selection,o=r.blockRange(i,s=>s.childCount>0&&s.firstChild.type==n);return o?t?r.node(o.depth-1).type==n?Uc(e,t,n,o):Gc(e,t,o):!0:!1}}function Uc(n,e,t,r){let i=n.tr,o=r.end,s=r.$to.end(r.depth);om;u--)p-=i.child(u).nodeSize,r.delete(p-1,p+1);let o=r.doc.resolve(t.start),s=o.nodeAfter;if(r.mapping.map(t.end)!=t.start+o.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,a=t.endIndex==i.childCount,c=o.node(-1),f=o.index(-1);if(!c.canReplace(f+(l?0:1),f+1,s.content.append(a?y.empty:y.from(i))))return!1;let h=o.pos,d=h+s.nodeSize;return r.step(new E(h-(l?1:0),d+(a?1:0),h+1,d-1,new b((l?y.empty:y.from(i.copy(y.empty))).append(a?y.empty:y.from(i.copy(y.empty))),l?0:1,a?0:1),l?0:1)),e(r.scrollIntoView()),!0}function es(n){return function(e,t){let{$from:r,$to:i}=e.selection,o=r.blockRange(i,c=>c.childCount>0&&c.firstChild.type==n);if(!o)return!1;let s=o.startIndex;if(s==0)return!1;let l=o.parent,a=l.child(s-1);if(a.type!=n)return!1;if(t){let c=a.lastChild&&a.lastChild.type==l.type,f=y.from(c?n.create():null),h=new b(y.from(n.create(null,y.from(l.type.create(null,f)))),c?3:1,0),d=o.start,p=o.end;t(e.tr.step(new E(d-(c?3:1),p,d,p,h,1,!0)).scrollIntoView())}return!0}}var Te=class{constructor(e,t,r={}){this.match=e,this.match=e,this.handler=typeof t=="string"?Yc(t):t,this.undoable=r.undoable!==!1,this.inCode=r.inCode||!1}};function Yc(n){return function(e,t,r,i){let o=n;if(t[1]){let s=t[0].lastIndexOf(t[1]);o+=t[0].slice(s+t[1].length),r+=s;let l=r-i;l>0&&(o=t[0].slice(s-l,s)+o,r=i)}return e.tr.insertText(o,r,i)}}var ts=(n,e)=>{let t=n.plugins;for(let r=0;r=0;a--)s.step(l.steps[a].invert(l.docs[a]));if(o.text){let a=s.doc.resolve(o.from).marks();s.replaceWith(o.from,o.to,n.schema.text(o.text,a))}else s.delete(o.from,o.to);e(s)}return!0}}return!1},Rh=new Te(/--$/,"\u2014"),zh=new Te(/\.\.\.$/,"\u2026"),Bh=new Te(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C"),Fh=new Te(/"$/,"\u201D"),Vh=new Te(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018"),Lh=new Te(/'$/,"\u2019");function Xc(n,e){let t=Object.keys(e);return t.length?!!t.filter(r=>e[r]===n[r]).length:!0}function Ar(n,e,t={}){return n.find(r=>r.type===e&&Xc(r.attrs,t))}function Qc(n,e,t={}){return!!Ar(n,e,t)}function vr(n,e,t={}){if(!n||!e)return;let r=n.parent.childAfter(n.parentOffset);if(!r.node)return;let i=Ar(r.node.marks,e,t);if(!i)return;let o=n.index(),s=n.start()+r.offset,l=o+1,a=s+r.node.nodeSize;for(Ar(r.node.marks,e,t);o>0&&i.isInSet(n.parent.child(o-1).marks);)o-=1,s-=n.parent.child(o).nodeSize;for(;l=e||$<0||h&&ne>=o}function k(){var C=kn();if(g(C))return N(C);l=setTimeout(k,m(C))}function N(C){return l=void 0,d&&r?p(C):(r=i=void 0,s)}function ee(){l!==void 0&&clearTimeout(l),c=0,r=a=i=l=void 0}function te(){return l===void 0?s:N(kn())}function U(){var C=kn(),$=g(C);if(r=arguments,i=this,a=C,$){if(l===void 0)return u(a);if(h)return clearTimeout(l),l=setTimeout(k,e),p(a)}return l===void 0&&(l=setTimeout(k,e)),s}return U.cancel=ee,U.flush=te,U}var ps=If;var Q=(n,e=null)=>{let t=document.createElement(n);if(e)for(let[r,i]of Object.entries(e))/^data-|^aria-|^role/.test(r)?t.setAttribute(r,i):t[r]=i;return t};function xn(n,e){let t=document.createElement("article");return t.innerHTML=e,Re.fromSchema(n).parse(t)}function ms(n){let{schema:e,doc:t}=n,r=ie.fromSchema(e),i=Q("article");return i.appendChild(r.serializeFragment(t.content)),i.innerHTML}var gs=(n,e,t)=>{let r=ie.fromSchema(n),i=function(){let s=Q("article");return s.appendChild(r.serializeFragment(e.state.doc.content)),s.innerHTML};return ps(()=>{let s=i();t.value!==s&&(t.value=s,t.dispatchEvent(new InputEvent("input",{bubbles:!0,cancelable:!0})))},250)},ys=n=>{let{$from:e,$to:t}=n,r=e.pos,i=t.pos,o=e.nodeAfter,s=t.nodeBefore,l=o&&o.isText?/^\s*/.exec(o.text)[0].length:0,a=s&&s.isText?/\s*$/.exec(s.text)[0].length:0;return r+lnew Promise(e=>{let t=document.createElement("div");t.innerHTML=`

@@ -15,7 +15,7 @@ var DjangoProseEditor=(()=>{var Rt=Object.defineProperty;var zs=Object.getOwnPro
- `,document.body.append(t);let r=t.querySelector("dialog"),i=t.querySelector("form");i.href.value=n.href||"",i.title.value=n.title||"",r.querySelector("button[value=cancel]").addEventListener("click",()=>{r.close()}),r.addEventListener("close",()=>{t.remove(),e(null)}),t.querySelector("button[type=submit]").addEventListener("click",o=>{o.preventDefault(),i.reportValidity()&&(t.remove(),e(i.href.value?{href:i.href.value,title:i.title.value}:null))}),r.showModal()}),st=(n,e)=>{let{$from:t,empty:r}=n.selection,i=n.schema.marks.link;if(r&&!i.isInSet(t.marks()))return!1;if(e){let o=t.marks().find(s=>s.type===i);If((o==null?void 0:o.attrs)||{}).then(s=>{if(s){let l;if(r)l=vr(t,i),e(n.tr.removeMark(l.from,l.to,i).addMark(l.from,l.to,i.create(s)));else{let{from:a,to:c}=ys(n.selection);e(n.tr.addMark(a,c,i.create(s)))}}})}return!0},bs=(n,e)=>{let t=n.schema.marks.link,{$from:r,from:i,to:o}=n.selection,s=vr(r,t);return s&&s.from<=i&&s.to>=o?(e&&e(n.tr.removeMark(s.from,s.to,t)),!0):!1},Af=n=>new Promise(e=>{let t=document.createElement("div");t.innerHTML=` + `,document.body.append(t);let r=t.querySelector("dialog"),i=t.querySelector("form");i.href.value=n.href||"",i.title.value=n.title||"",r.querySelector("button[value=cancel]").addEventListener("click",()=>{r.close()}),r.addEventListener("close",()=>{t.remove(),e(null)}),t.querySelector("button[type=submit]").addEventListener("click",o=>{o.preventDefault(),i.reportValidity()&&(t.remove(),e(i.href.value?{href:i.href.value,title:i.title.value}:null))}),r.showModal()}),st=(n,e)=>{let{$from:t,empty:r}=n.selection,i=n.schema.marks.link;if(r&&!i.isInSet(t.marks()))return!1;if(e){let o=t.marks().find(s=>s.type===i);Af((o==null?void 0:o.attrs)||{}).then(s=>{if(s){let l;if(r)l=vr(t,i),e(n.tr.removeMark(l.from,l.to,i).addMark(l.from,l.to,i.create(s)));else{let{from:a,to:c}=ys(n.selection);e(n.tr.addMark(a,c,i.create(s)))}}})}return!0},bs=(n,e)=>{let t=n.schema.marks.link,{$from:r,from:i,to:o}=n.selection,s=vr(r,t);return s&&s.from<=i&&s.to>=o?(e&&e(n.tr.removeMark(s.from,s.to,t)),!0):!1},vf=n=>new Promise(e=>{let t=document.createElement("div");t.innerHTML=`

@@ -23,4 +23,4 @@ var DjangoProseEditor=(()=>{var Rt=Object.defineProperty;var zs=Object.getOwnPro
- `,document.body.append(t);let r=t.querySelector("dialog"),i=t.querySelector("form");i.html.value=n,r.querySelector("button[value=cancel]").addEventListener("click",()=>{r.close()}),r.addEventListener("close",()=>{t.remove(),e(null)}),t.querySelector("button[type=submit]").addEventListener("click",o=>{o.preventDefault(),i.reportValidity()&&(t.remove(),e(i.html.value))}),r.showModal()}),ks=n=>(e,t)=>(t&&Af(ms(n)).then(r=>{if(r){let i=xn(n.state.schema,r);t(e.tr.replaceWith(0,e.tr.doc.content.size,i))}}),!0),xs=(n,e)=>(e&&e(n.tr.replaceSelectionWith(n.schema.nodes.horizontal_rule.create())),!0);var Ss=typeof navigator!="undefined"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1,Ms=n=>(e,t)=>{n[e]=t};function Cs(n){let e={},t,r=Ms(e);if(r("Mod-z",Et),r("Shift-Mod-z",rt),r("Backspace",ts),Ss||r("Mod-y",rt),t=n.nodes.hard_break){let i=t,o=xt($n,(s,l)=>(l&&l(s.tr.replaceSelectionWith(i.create()).scrollIntoView()),!0));r("Mod-Enter",o),r("Shift-Enter",o),Ss&&r("Ctrl-Enter",o)}return(t=n.nodes.bullet_list)&&r("Shift-Ctrl-8",it(t)),(t=n.nodes.ordered_list)&&r("Shift-Ctrl-9",it(t)),(t=n.nodes.blockquote)&&r("Ctrl->",Zt(t)),(t=n.nodes.list_item)&&(r("Enter",Qo(t)),r("Mod-[",Zo(t)),r("Mod-]",es(t))),e}function Os(n){let e={},t,r=Ms(e);return(t=n.marks.strong)&&(r("Mod-b",G(t)),r("Mod-B",G(t))),(t=n.marks.em)&&(r("Mod-i",G(t)),r("Mod-I",G(t))),(t=n.marks.underline)&&(r("Mod-Shift-u",G(t)),r("Mod-Shift-U",G(t))),(t=n.marks.strikethrough)&&(r("Mod-Shift-s",G(t)),r("Mod-Shift-S",G(t))),(t=n.marks.link)&&(r("Mod-k",st),r("Mod-K",st)),e}function ws(n){return new J({view(e){let t=new Rr(n,e);return e.dom.parentNode.insertBefore(t.dom,e.dom),t}})}function Ns(n,e){let{from:t,$from:r,to:i,empty:o}=n.selection;return o?e.isInSet(n.storedMarks||r.marks()):n.doc.rangeHasMark(t,i,e)}function vf(n){let e=Q("span",{className:"prose-menubar__button prose-menubar__button--heading"});return e.append(Q("span",{className:"material-icons",textContent:"title",title:`heading ${n}`}),Q("span",{className:"level",textContent:`${n}`})),e}function Z(n,e){return Q("span",{className:"prose-menubar__button material-icons",textContent:n,title:e})}function Ts(n){let e=t=>({command:Hn(n.nodes.heading,{level:t}),dom:vf(t),active(r){return r.selection.$from.parent.hasMarkup(n.nodes.heading,{level:t})}});return[e(1),e(2),e(3),{command:Hn(n.nodes.paragraph),dom:Z("notes","paragraph"),active(t){return t.selection.$from.parent.hasMarkup(n.nodes.paragraph)}}]}function Ds(n){return[{command:it(n.nodes.bullet_list),dom:Z("format_list_bulleted","unordered list"),active(e){return!1}},{command:it(n.nodes.ordered_list),dom:Z("format_list_numbered","ordered list"),active(e){return!1}},{command:Zt(n.nodes.blockquote),dom:Z("format_quote","blockquote"),active(e){return!1}},{command:xs,dom:Z("horizontal_rule","horizontal rule"),active(e){return!1}}]}function Es(n){let e=(t,r,i)=>({command:G(t),dom:Z(r,i),active:o=>Ns(o,t)});return[e(n.marks.strong,"format_bold","bold"),e(n.marks.em,"format_italic","italic"),e(n.marks.underline,"format_underline","underline"),e(n.marks.strikethrough,"format_strikethrough","strikethrough"),e(n.marks.sub,"subscript","subscript"),e(n.marks.sup,"superscript","superscript")]}function Is(n){return[{command:st,dom:Z("insert_link","insert link"),active:st},{command:bs,dom:Z("link_off","remove link"),active:e=>Ns(e,n.marks.link)}]}function As(){return[{command:Et,dom:Z("undo","undo"),active(n){return!1}},{command:rt,dom:Z("redo","redo"),active(n){return!1}}]}function Pf(n){return[{command:ks(n),dom:Z("code","edit HTML"),active:()=>!1}]}var Rr=class{constructor(e,t){e.push(Pf(t)),this.items=e.flatMap(r=>r),this.editorView=t,this.dom=Q("div",{className:"prose-menubar"}),e.filter(r=>r.length).forEach(r=>{let i=Q("div",{className:"prose-menubar__group"});this.dom.append(i),r.forEach(({dom:o})=>i.append(o))}),this.update(),this.dom.addEventListener("mousedown",r=>{r.preventDefault(),t.focus(),this.items.forEach(({command:i,dom:o})=>{o.contains(r.target)&&i(t.state,t.dispatch,t)})})}update(){this.items.forEach(({command:e,dom:t,active:r})=>{let i=e(this.editorView.state,null,this.editorView);t.classList.toggle("disabled",!i),t.classList.toggle("active",r(this.editorView.state)||!1)})}destroy(){this.dom.remove()}};function vs(){return new J({view(n){return new zr(n)}})}var zr=class{constructor(e){this.editorView=e,this.editorView.dom.setAttribute("spellcheck","false")}update(){}destroy(){this.editorView.dom.removeAttribute("spellcheck")}};var Rf=["u",0],zf=["s",0],Bf=["sub",0],Ff=["sup",0];function Ps(n){let e={nodes:{doc:ye.doc,paragraph:ye.paragraph,heading:ye.heading,blockquote:ye.blockquote,horizontal_rule:ye.horizontal_rule,text:ye.text,hard_break:ye.hard_break},marks:{link:It.link,strong:It.strong,em:It.em,underline:{parseDOM:[{tag:"u"},{style:"text-decoration:underline"}],toDOM(){return Rf}},strikethrough:{parseDOM:[{tag:"s"},{style:"text-decoration:line-through"}],toDOM(){return zf}},sub:{parseDOM:[{tag:"sub"}],toDOM(){return Bf}},sup:{parseDOM:[{tag:"sup"}],toDOM(){return Ff}}}},t=new Pe(e);t=new Pe({nodes:Xo(t.spec.nodes,"paragraph block*","block"),marks:t.spec.marks});let r=Sn(Sn({},Cs(t)),Os(t)),i=[Un(r),Un(vi),Pi(),Ho(),Yo(),ws([Ts(t),Ds(t),Is(t),Es(t),As()]),vs()],o=Q("div",{className:"prose-editor"});n.before(o);let s=new dn(o,{state:Qt.create({doc:xn(t,n.value),plugins:i}),dispatchTransaction:a=>{s.updateState(s.state.apply(a)),l()}}),l=gs(t,s,n);return()=>{try{s.destroy()}catch(a){}o.remove()}}return Js(Vf);})(); + `,document.body.append(t);let r=t.querySelector("dialog"),i=t.querySelector("form");i.html.value=n,r.querySelector("button[value=cancel]").addEventListener("click",()=>{r.close()}),r.addEventListener("close",()=>{t.remove(),e(null)}),t.querySelector("button[type=submit]").addEventListener("click",o=>{o.preventDefault(),i.reportValidity()&&(t.remove(),e(i.html.value))}),r.showModal()}),ks=(n,e)=>(e&&vf(ms(n)).then(t=>{if(t){let r=xn(n.schema,t);e(n.tr.replaceWith(0,n.tr.doc.content.size,r))}}),!0),xs=(n,e)=>(e&&e(n.tr.replaceSelectionWith(n.schema.nodes.horizontal_rule.create())),!0);var Ss=typeof navigator!="undefined"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1,Ms=n=>(e,t)=>{n[e]=t};function Cs(n){let e={},t,r=Ms(e);if(r("Mod-z",Et),r("Shift-Mod-z",rt),r("Backspace",ts),Ss||r("Mod-y",rt),t=n.nodes.hard_break){let i=t,o=xt(Hn,(s,l)=>(l&&l(s.tr.replaceSelectionWith(i.create()).scrollIntoView()),!0));r("Mod-Enter",o),r("Shift-Enter",o),Ss&&r("Ctrl-Enter",o)}return(t=n.nodes.bullet_list)&&r("Shift-Ctrl-8",it(t)),(t=n.nodes.ordered_list)&&r("Shift-Ctrl-9",it(t)),(t=n.nodes.blockquote)&&r("Ctrl->",Zt(t)),(t=n.nodes.list_item)&&(r("Enter",Qo(t)),r("Mod-[",Zo(t)),r("Mod-]",es(t))),e}function Os(n){let e={},t,r=Ms(e);return(t=n.marks.strong)&&(r("Mod-b",G(t)),r("Mod-B",G(t))),(t=n.marks.em)&&(r("Mod-i",G(t)),r("Mod-I",G(t))),(t=n.marks.underline)&&(r("Mod-Shift-u",G(t)),r("Mod-Shift-U",G(t))),(t=n.marks.strikethrough)&&(r("Mod-Shift-s",G(t)),r("Mod-Shift-S",G(t))),(t=n.marks.link)&&(r("Mod-k",st),r("Mod-K",st)),e}function ws(n){return new J({view(e){let t=new Rr(n,e);return e.dom.parentNode.insertBefore(t.dom,e.dom),t}})}function Ns(n,e){let{from:t,$from:r,to:i,empty:o}=n.selection;return o?e.isInSet(n.storedMarks||r.marks()):n.doc.rangeHasMark(t,i,e)}function Pf(n){let e=Q("span",{className:"prose-menubar__button prose-menubar__button--heading"});return e.append(Q("span",{className:"material-icons",textContent:"title",title:`heading ${n}`}),Q("span",{className:"level",textContent:`${n}`})),e}function Z(n,e){return Q("span",{className:"prose-menubar__button material-icons",textContent:n,title:e})}function Ts(n){let e=t=>({command:$n(n.nodes.heading,{level:t}),dom:Pf(t),active(r){return r.selection.$from.parent.hasMarkup(n.nodes.heading,{level:t})}});return[e(1),e(2),e(3),{command:$n(n.nodes.paragraph),dom:Z("notes","paragraph"),active(t){return t.selection.$from.parent.hasMarkup(n.nodes.paragraph)}}]}function Ds(n){return[{command:it(n.nodes.bullet_list),dom:Z("format_list_bulleted","unordered list"),active(e){return!1}},{command:it(n.nodes.ordered_list),dom:Z("format_list_numbered","ordered list"),active(e){return!1}},{command:Zt(n.nodes.blockquote),dom:Z("format_quote","blockquote"),active(e){return!1}},{command:xs,dom:Z("horizontal_rule","horizontal rule"),active(e){return!1}}]}function Es(n){let e=(t,r,i)=>({command:G(t),dom:Z(r,i),active:o=>Ns(o,t)});return[e(n.marks.strong,"format_bold","bold"),e(n.marks.em,"format_italic","italic"),e(n.marks.underline,"format_underline","underline"),e(n.marks.strikethrough,"format_strikethrough","strikethrough"),e(n.marks.sub,"subscript","subscript"),e(n.marks.sup,"superscript","superscript")]}function Is(n){return[{command:st,dom:Z("insert_link","insert link"),active:st},{command:bs,dom:Z("link_off","remove link"),active:e=>Ns(e,n.marks.link)}]}function As(){return[{command:Et,dom:Z("undo","undo"),active(n){return!1}},{command:rt,dom:Z("redo","redo"),active(n){return!1}}]}function vs(){return[{command:ks,dom:Z("code","edit HTML"),active:()=>!1}]}var Rr=class{constructor(e,t){this.items=e.flatMap(r=>r),this.editorView=t,this.dom=Q("div",{className:"prose-menubar"}),e.filter(r=>r.length).forEach(r=>{let i=Q("div",{className:"prose-menubar__group"});this.dom.append(i),r.forEach(({dom:o})=>i.append(o))}),this.update(),this.dom.addEventListener("mousedown",r=>{r.preventDefault(),t.focus(),this.items.forEach(({command:i,dom:o})=>{o.contains(r.target)&&i(t.state,t.dispatch,t)})})}update(){this.items.forEach(({command:e,dom:t,active:r})=>{let i=e(this.editorView.state,null,this.editorView);t.classList.toggle("disabled",!i),t.classList.toggle("active",r(this.editorView.state)||!1)})}destroy(){this.dom.remove()}};function Ps(){return new J({view(n){return new zr(n)}})}var zr=class{constructor(e){this.editorView=e,this.editorView.dom.setAttribute("spellcheck","false")}update(){}destroy(){this.editorView.dom.removeAttribute("spellcheck")}};var Rf=["u",0],zf=["s",0],Bf=["sub",0],Ff=["sup",0];function Rs(n){let e={nodes:{doc:ye.doc,paragraph:ye.paragraph,heading:ye.heading,blockquote:ye.blockquote,horizontal_rule:ye.horizontal_rule,text:ye.text,hard_break:ye.hard_break},marks:{link:It.link,strong:It.strong,em:It.em,underline:{parseDOM:[{tag:"u"},{style:"text-decoration:underline"}],toDOM(){return Rf}},strikethrough:{parseDOM:[{tag:"s"},{style:"text-decoration:line-through"}],toDOM(){return zf}},sub:{parseDOM:[{tag:"sub"}],toDOM(){return Bf}},sup:{parseDOM:[{tag:"sup"}],toDOM(){return Ff}}}},t=new Pe(e);t=new Pe({nodes:Xo(t.spec.nodes,"paragraph block*","block"),marks:t.spec.marks});let r=Sn(Sn({},Cs(t)),Os(t)),i=[Un(r),Un(vi),Pi(),$o(),Yo(),ws([Ts(t),Ds(t),Is(t),Es(t),As(),vs()]),Ps()],o=Q("div",{className:"prose-editor"});n.before(o);let s=new dn(o,{state:Qt.create({doc:xn(t,n.value),plugins:i}),dispatchTransaction:a=>{s.updateState(s.state.apply(a)),l()}}),l=gs(t,s,n);return()=>{try{s.destroy()}catch(a){}o.remove()}}return Ws(Vf);})(); diff --git a/src/commands.js b/src/commands.js index b46d848..5d07656 100644 --- a/src/commands.js +++ b/src/commands.js @@ -125,11 +125,11 @@ const htmlDialog = (html) => { }) } -export const updateHTML = (editorViewInstance) => (state, dispatch) => { +export const updateHTML = (state, dispatch) => { if (dispatch) { - htmlDialog(getHTML(editorViewInstance)).then((html) => { + htmlDialog(getHTML(state)).then((html) => { if (html) { - const doc = parseHTML(editorViewInstance.state.schema, html) + const doc = parseHTML(state.schema, html) dispatch(state.tr.replaceWith(0, state.tr.doc.content.size, doc)) } }) diff --git a/src/editor.js b/src/editor.js index cbc04b7..077a265 100644 --- a/src/editor.js +++ b/src/editor.js @@ -22,6 +22,7 @@ import { linkMenuItems, historyMenuItems, markMenuItems, + htmlMenuItem, } from "./menu.js" import { noSpellCheck } from "./nospellcheck.js" import { crel, createDebouncedBackWriter, parseHTML } from "./utils.js" @@ -96,6 +97,7 @@ export function createEditor(textarea) { linkMenuItems(schema), markMenuItems(schema), historyMenuItems(), + htmlMenuItem(), ]), noSpellCheck(), ] diff --git a/src/menu.js b/src/menu.js index 738fe30..f13e571 100644 --- a/src/menu.js +++ b/src/menu.js @@ -160,10 +160,10 @@ export function historyMenuItems() { ] } -export function htmlMenuItem(editorViewInstance) { +export function htmlMenuItem() { return [ { - command: updateHTML(editorViewInstance), + command: updateHTML, dom: materialButton("code", "edit HTML"), active: () => false, }, @@ -172,7 +172,6 @@ export function htmlMenuItem(editorViewInstance) { 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 c317f24..ac92dd9 100644 --- a/src/utils.js +++ b/src/utils.js @@ -18,8 +18,8 @@ export function parseHTML(schema, html) { return DOMParser.fromSchema(schema).parse(container) } -export function getHTML(editorViewInstance) { - const { schema, doc } = editorViewInstance.state +export function getHTML(state) { + const { schema, doc } = state const serializer = DOMSerializer.fromSchema(schema) const container = crel("article") container.appendChild(serializer.serializeFragment(doc.content))