@mohaq/directus-extension-tiptap
Version:
Tiptap rich text editor interface and display for directus
1 lines • 537 kB
JavaScript
import{defineInterface as e,defineDisplay as t}from"@directus/extensions-sdk";import{defineComponent as n,ref as o,onMounted as r,onBeforeUnmount as i,h as s,markRaw as a,getCurrentInstance as l,watchEffect as c,nextTick as d,unref as p,customRef as u,computed as h,openBlock as f,createElementBlock as m,createElementVNode as g,createStaticVNode as v,watch as y,resolveComponent as b,resolveDirective as w,normalizeClass as k,createVNode as x,withCtx as C,withDirectives as M,createBlock as S,createCommentVNode as A,createTextVNode as T,toDisplayString as O,Fragment as L,renderList as E,resolveDynamicComponent as N,isRef as H,Suspense as D,normalizeProps as _,guardReactiveProps as V}from"vue";import{useI18n as R}from"vue-i18n";function $(e){this.content=e}function I(e,t,n){for(let o=0;;o++){if(o==e.childCount||o==t.childCount)return e.childCount==t.childCount?null:n;let r=e.child(o),i=t.child(o);if(r!=i){if(!r.sameMarkup(i))return n;if(r.isText&&r.text!=i.text){for(let e=0;r.text[e]==i.text[e];e++)n++;return n}if(r.content.size||i.content.size){let e=I(r.content,i.content,n+1);if(null!=e)return e}n+=r.nodeSize}else n+=r.nodeSize}}function B(e,t,n,o){for(let r=e.childCount,i=t.childCount;;){if(0==r||0==i)return r==i?null:{a:n,b:o};let s=e.child(--r),a=t.child(--i),l=s.nodeSize;if(s!=a){if(!s.sameMarkup(a))return{a:n,b:o};if(s.isText&&s.text!=a.text){let e=0,t=Math.min(s.text.length,a.text.length);for(;e<t&&s.text[s.text.length-e-1]==a.text[a.text.length-e-1];)e++,n--,o--;return{a:n,b:o}}if(s.content.size||a.content.size){let e=B(s.content,a.content,n-1,o-1);if(e)return e}n-=l,o-=l}else n-=l,o-=l}}$.prototype={constructor:$,find:function(e){for(var t=0;t<this.content.length;t+=2)if(this.content[t]===e)return t;return-1},get:function(e){var t=this.find(e);return-1==t?void 0:this.content[t+1]},update:function(e,t,n){var o=n&&n!=e?this.remove(n):this,r=o.find(e),i=o.content.slice();return-1==r?i.push(n||e,t):(i[r+1]=t,n&&(i[r]=n)),new $(i)},remove:function(e){var t=this.find(e);if(-1==t)return this;var n=this.content.slice();return n.splice(t,2),new $(n)},addToStart:function(e,t){return new $([e,t].concat(this.remove(e).content))},addToEnd:function(e,t){var n=this.remove(e).content.slice();return n.push(e,t),new $(n)},addBefore:function(e,t,n){var o=this.remove(t),r=o.content.slice(),i=o.find(e);return r.splice(-1==i?r.length:i,0,t,n),new $(r)},forEach:function(e){for(var t=0;t<this.content.length;t+=2)e(this.content[t],this.content[t+1])},prepend:function(e){return(e=$.from(e)).size?new $(e.content.concat(this.subtract(e).content)):this},append:function(e){return(e=$.from(e)).size?new $(this.subtract(e).content.concat(e.content)):this},subtract:function(e){var t=this;e=$.from(e);for(var n=0;n<e.content.length;n+=2)t=t.remove(e.content[n]);return t},toObject:function(){var e={};return this.forEach(function(t,n){e[t]=n}),e},get size(){return this.content.length>>1}},$.from=function(e){if(e instanceof $)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new $(t)};class z{constructor(e,t){if(this.content=e,this.size=t||0,null==t)for(let t=0;t<e.length;t++)this.size+=e[t].nodeSize}nodesBetween(e,t,n,o=0,r){for(let i=0,s=0;s<t;i++){let a=this.content[i],l=s+a.nodeSize;if(l>e&&!1!==n(a,o+s,r||null,i)&&a.content.size){let r=s+1;a.nodesBetween(Math.max(0,e-r),Math.min(a.content.size,t-r),n,o+r)}s=l}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,o){let r="",i=!0;return this.nodesBetween(e,t,(s,a)=>{let l=s.isText?s.text.slice(Math.max(e,a)-a,t-a):s.isLeaf?o?"function"==typeof o?o(s):o:s.type.spec.leafText?s.type.spec.leafText(s):"":"";s.isBlock&&(s.isLeaf&&l||s.isTextblock)&&n&&(i?i=!1:r+=n),r+=l},0),r}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,n=e.firstChild,o=this.content.slice(),r=0;for(t.isText&&t.sameMarkup(n)&&(o[o.length-1]=t.withText(t.text+n.text),r=1);r<e.content.length;r++)o.push(e.content[r]);return new z(o,this.size+e.size)}cut(e,t=this.size){if(0==e&&t==this.size)return this;let n=[],o=0;if(t>e)for(let r=0,i=0;i<t;r++){let s=this.content[r],a=i+s.nodeSize;a>e&&((i<e||a>t)&&(s=s.isText?s.cut(Math.max(0,e-i),Math.min(s.text.length,t-i)):s.cut(Math.max(0,e-i-1),Math.min(s.content.size,t-i-1))),n.push(s),o+=s.nodeSize),i=a}return new z(n,o)}cutByIndex(e,t){return e==t?z.empty:0==e&&t==this.content.length?this:new z(this.content.slice(e,t))}replaceChild(e,t){let n=this.content[e];if(n==t)return this;let o=this.content.slice(),r=this.size+t.nodeSize-n.nodeSize;return o[e]=t,new z(o,r)}addToStart(e){return new z([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new z(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw new RangeError("Index "+e+" out of range for "+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,n=0;t<this.content.length;t++){let o=this.content[t];e(o,n,t),n+=o.nodeSize}}findDiffStart(e,t=0){return I(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return B(this,e,t,n)}findIndex(e){if(0==e)return j(0,e);if(e==this.size)return j(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let o=n+this.child(t).nodeSize;if(o>=e)return o==e?j(t+1,o):j(t,n);n=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return z.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new z(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return z.empty;let t,n=0;for(let o=0;o<e.length;o++){let r=e[o];n+=r.nodeSize,o&&r.isText&&e[o-1].sameMarkup(r)?(t||(t=e.slice(0,o)),t[t.length-1]=r.withText(t[t.length-1].text+r.text)):t&&t.push(r)}return new z(t||e,n)}static from(e){if(!e)return z.empty;if(e instanceof z)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new z([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}z.empty=new z([],0);const P={index:0,offset:0};function j(e,t){return P.index=e,P.offset=t,P}function F(e,t){if(e===t)return!0;if(!e||"object"!=typeof e||!t||"object"!=typeof t)return!1;let n=Array.isArray(e);if(Array.isArray(t)!=n)return!1;if(n){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!F(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!F(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}let W=class e{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let o=0;o<e.length;o++){let r=e[o];if(this.eq(r))return e;if(this.type.excludes(r.type))t||(t=e.slice(0,o));else{if(r.type.excludes(this.type))return e;!n&&r.type.rank>this.type.rank&&(t||(t=e.slice(0,o)),t.push(this),n=!0),t&&t.push(r)}}return t||(t=e.slice()),n||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&F(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Mark.fromJSON");let n=e.marks[t.type];if(!n)throw new RangeError(`There is no mark type ${t.type} in this schema`);let o=n.create(t.attrs);return n.checkAttrs(o.attrs),o}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}static setFrom(t){if(!t||Array.isArray(t)&&0==t.length)return e.none;if(t instanceof e)return[t];let n=t.slice();return n.sort((e,t)=>e.type.rank-t.type.rank),n}};W.none=[];class q extends Error{}class K{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let n=J(this.content,e+this.openStart,t);return n&&new K(n,this.openStart,this.openEnd)}removeBetween(e,t){return new K(U(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 K.empty;let n=t.openStart||0,o=t.openEnd||0;if("number"!=typeof n||"number"!=typeof o)throw new RangeError("Invalid input for Slice.fromJSON");return new K(z.fromJSON(e,t.content),n,o)}static maxOpen(e,t=!0){let n=0,o=0;for(let o=e.firstChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.firstChild)n++;for(let n=e.lastChild;n&&!n.isLeaf&&(t||!n.type.spec.isolating);n=n.lastChild)o++;return new K(e,n,o)}}function U(e,t,n){let{index:o,offset:r}=e.findIndex(t),i=e.maybeChild(o),{index:s,offset:a}=e.findIndex(n);if(r==t||i.isText){if(a!=n&&!e.child(s).isText)throw new RangeError("Removing non-flat range");return e.cut(0,t).append(e.cut(n))}if(o!=s)throw new RangeError("Removing non-flat range");return e.replaceChild(o,i.copy(U(i.content,t-r-1,n-r-1)))}function J(e,t,n,o){let{index:r,offset:i}=e.findIndex(t),s=e.maybeChild(r);if(i==t||s.isText)return o&&!o.canReplace(r,r,n)?null:e.cut(0,t).append(n).append(e.cut(t));let a=J(s.content,t-i-1,n);return a&&e.replaceChild(r,s.copy(a))}function Z(e,t,n){if(n.openStart>e.depth)throw new q("Inserted content deeper than insertion position");if(e.depth-n.openStart!=t.depth-n.openEnd)throw new q("Inconsistent open depths");return G(e,t,n,0)}function G(e,t,n,o){let r=e.index(o),i=e.node(o);if(r==t.index(o)&&o<e.depth-n.openStart){let s=G(e,t,n,o+1);return i.copy(i.content.replaceChild(r,s))}if(n.content.size){if(n.openStart||n.openEnd||e.depth!=o||t.depth!=o){let{start:r,end:s}=function(e,t){let n=t.depth-e.openStart,o=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)o=t.node(e).copy(z.from(o));return{start:o.resolveNoCache(e.openStart+n),end:o.resolveNoCache(o.content.size-e.openEnd-n)}}(n,e);return te(i,ne(e,r,s,t,o))}{let o=e.parent,r=o.content;return te(o,r.cut(0,e.parentOffset).append(n.content).append(r.cut(t.parentOffset)))}}return te(i,oe(e,t,o))}function Q(e,t){if(!t.type.compatibleContent(e.type))throw new q("Cannot join "+t.type.name+" onto "+e.type.name)}function X(e,t,n){let o=e.node(n);return Q(o,t.node(n)),o}function Y(e,t){let n=t.length-1;n>=0&&e.isText&&e.sameMarkup(t[n])?t[n]=e.withText(t[n].text+e.text):t.push(e)}function ee(e,t,n,o){let r=(t||e).node(n),i=0,s=t?t.index(n):r.childCount;e&&(i=e.index(n),e.depth>n?i++:e.textOffset&&(Y(e.nodeAfter,o),i++));for(let e=i;e<s;e++)Y(r.child(e),o);t&&t.depth==n&&t.textOffset&&Y(t.nodeBefore,o)}function te(e,t){return e.type.checkContent(t),e.copy(t)}function ne(e,t,n,o,r){let i=e.depth>r&&X(e,t,r+1),s=o.depth>r&&X(n,o,r+1),a=[];return ee(null,e,r,a),i&&s&&t.index(r)==n.index(r)?(Q(i,s),Y(te(i,ne(e,t,n,o,r+1)),a)):(i&&Y(te(i,oe(e,t,r+1)),a),ee(t,n,r,a),s&&Y(te(s,oe(n,o,r+1)),a)),ee(o,null,r,a),new z(a)}function oe(e,t,n){let o=[];if(ee(null,e,n,o),e.depth>n){Y(te(X(e,t,n+1),oe(e,t,n+1)),o)}return ee(t,null,n,o),new z(o)}K.empty=new K(z.empty,0,0);class re{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return null==e?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[3*this.resolveDepth(e)]}index(e){return this.path[3*this.resolveDepth(e)+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e!=this.depth||this.textOffset?1:0)}start(e){return 0==(e=this.resolveDepth(e))?0:this.path[3*e-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(!(e=this.resolveDepth(e)))throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[3*e-1]}after(e){if(!(e=this.resolveDepth(e)))throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[3*e-1]+this.path[3*e].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let n=this.pos-this.path[this.path.length-1],o=e.child(t);return n?e.child(t).cut(n):o}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):0==e?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[3*t],o=0==t?0:this.path[3*t-1]+1;for(let t=0;t<e;t++)o+=n.child(t).nodeSize;return o}marks(){let e=this.parent,t=this.index();if(0==e.content.size)return W.none;if(this.textOffset)return e.child(t).marks;let n=e.maybeChild(t-1),o=e.maybeChild(t);if(!n){let e=n;n=o,o=e}let r=n.marks;for(var i=0;i<r.length;i++)!1!==r[i].type.spec.inclusive||o&&r[i].isInSet(o.marks)||(r=r[i--].removeFromSet(r));return r}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let n=t.marks,o=e.parent.maybeChild(e.index());for(var r=0;r<n.length;r++)!1!==n[r].type.spec.inclusive||o&&n[r].isInSet(o.marks)||(n=n[r--].removeFromSet(n));return n}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this);for(let n=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);n>=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new le(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let t=1;t<=this.depth;t++)e+=(e?"/":"")+this.node(t).type.name+"_"+this.index(t-1);return e+":"+this.parentOffset}static resolve(e,t){if(!(t>=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let n=[],o=0,r=t;for(let t=e;;){let{index:e,offset:i}=t.content.findIndex(r),s=r-i;if(n.push(t,e,o+i),!s)break;if(t=t.child(e),t.isText)break;r=s-1,o+=i+1}return new re(t,n,r)}static resolveCached(e,t){let n=ae.get(e);if(n)for(let e=0;e<n.elts.length;e++){let o=n.elts[e];if(o.pos==t)return o}else ae.set(e,n=new ie);let o=n.elts[n.i]=re.resolve(e,t);return n.i=(n.i+1)%se,o}}class ie{constructor(){this.elts=[],this.i=0}}const se=12,ae=new WeakMap;class le{constructor(e,t,n){this.$from=e,this.$to=t,this.depth=n}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}const ce=Object.create(null);let de=class e{constructor(e,t,n,o=W.none){this.type=e,this.attrs=t,this.marks=o,this.content=n||z.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,n,o=0){this.content.nodesBetween(e,t,n,o,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,t,n,o){return this.content.textBetween(e,t,n,o)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,n){return this.type==e&&F(this.attrs,t||e.defaultAttrs||ce)&&W.sameSet(this.marks,n||W.none)}copy(t=null){return t==this.content?this:new e(this.type,this.attrs,t,this.marks)}mark(t){return t==this.marks?this:new e(this.type,this.attrs,this.content,t)}cut(e,t=this.content.size){return 0==e&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,n=!1){if(e==t)return K.empty;let o=this.resolve(e),r=this.resolve(t),i=n?0:o.sharedDepth(t),s=o.start(i),a=o.node(i).content.cut(o.pos-s,r.pos-s);return new K(a,o.depth-i,r.depth-i)}replace(e,t,n){return Z(this.resolve(e),this.resolve(t),n)}nodeAt(e){for(let t=this;;){let{index:n,offset:o}=t.content.findIndex(e);if(t=t.maybeChild(n),!t)return null;if(o==e||t.isText)return t;e-=o+1}}childAfter(e){let{index:t,offset:n}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:n}}childBefore(e){if(0==e)return{node:null,index:0,offset:0};let{index:t,offset:n}=this.content.findIndex(e);if(n<e)return{node:this.content.child(t),index:t,offset:n};let o=this.content.child(t-1);return{node:o,index:t-1,offset:n-o.nodeSize}}resolve(e){return re.resolveCached(this,e)}resolveNoCache(e){return re.resolve(this,e)}rangeHasMark(e,t,n){let o=!1;return t>e&&this.nodesBetween(e,t,e=>(n.isInSet(e.marks)&&(o=!0),!o)),o}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()+")"),ue(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,n=z.empty,o=0,r=n.childCount){let i=this.contentMatchAt(e).matchFragment(n,o,r),s=i&&i.matchFragment(this.content,t);if(!s||!s.validEnd)return!1;for(let e=o;e<r;e++)if(!this.type.allowsMarks(n.child(e).marks))return!1;return!0}canReplaceWith(e,t,n,o){if(o&&!this.type.allowsMarks(o))return!1;let r=this.contentMatchAt(e).matchType(n),i=r&&r.matchFragment(this.content,t);return!!i&&i.validEnd}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=W.none;for(let t=0;t<this.marks.length;t++){let n=this.marks[t];n.type.checkAttrs(n.attrs),e=n.addToSet(e)}if(!W.sameSet(e,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(e=>e.type.name)}`);this.content.forEach(e=>e.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(e=>e.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let n;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");n=t.marks.map(e.markFromJSON)}if("text"==t.type){if("string"!=typeof t.text)throw new RangeError("Invalid text node in JSON");return e.text(t.text,n)}let o=z.fromJSON(e,t.content),r=e.nodeType(t.type).create(t.attrs,o,n);return r.type.checkAttrs(r.attrs),r}};de.prototype.text=void 0;class pe extends de{constructor(e,t,n,o){if(super(e,t,null,o),!n)throw new RangeError("Empty text nodes are not allowed");this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):ue(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 pe(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new pe(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return 0==e&&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 ue(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+"("+t+")";return t}class he{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let n=new fe(e,t);if(null==n.next)return he.empty;let o=me(n);n.next&&n.err("Unexpected trailing text");let r=function(e){let t=Object.create(null);return n(ke(e,0));function n(o){let r=[];o.forEach(t=>{e[t].forEach(({term:t,to:n})=>{if(!t)return;let o;for(let e=0;e<r.length;e++)r[e][0]==t&&(o=r[e][1]);ke(e,n).forEach(e=>{o||r.push([t,o=[]]),-1==o.indexOf(e)&&o.push(e)})})});let i=t[o.join(",")]=new he(o.indexOf(e.length-1)>-1);for(let e=0;e<r.length;e++){let o=r[e][1].sort(we);i.next.push({type:r[e][0],next:t[o.join(",")]||n(o)})}return i}}(function(e){let t=[[]];return r(i(e,0),n()),t;function n(){return t.push([])-1}function o(e,n,o){let r={term:o,to:n};return t[e].push(r),r}function r(e,t){e.forEach(e=>e.to=t)}function i(e,t){if("choice"==e.type)return e.exprs.reduce((e,n)=>e.concat(i(n,t)),[]);if("seq"!=e.type){if("star"==e.type){let s=n();return o(t,s),r(i(e.expr,s),s),[o(s)]}if("plus"==e.type){let s=n();return r(i(e.expr,t),s),r(i(e.expr,s),s),[o(s)]}if("opt"==e.type)return[o(t)].concat(i(e.expr,t));if("range"==e.type){let s=t;for(let t=0;t<e.min;t++){let t=n();r(i(e.expr,s),t),s=t}if(-1==e.max)r(i(e.expr,s),s);else for(let t=e.min;t<e.max;t++){let t=n();o(s,t),r(i(e.expr,s),t),s=t}return[o(s)]}if("name"==e.type)return[o(t,void 0,e.value)];throw new Error("Unknown expr type")}for(let o=0;;o++){let s=i(e.exprs[o],t);if(o==e.exprs.length-1)return s;r(s,t=n())}}}(o));return function(e,t){for(let n=0,o=[e];n<o.length;n++){let e=o[n],r=!e.validEnd,i=[];for(let t=0;t<e.next.length;t++){let{type:n,next:s}=e.next[t];i.push(n.name),!r||n.isText||n.hasRequiredAttrs()||(r=!1),-1==o.indexOf(s)&&o.push(s)}r&&t.err("Only non-generatable nodes ("+i.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}(r,n),r}matchType(e){for(let t=0;t<this.next.length;t++)if(this.next[t].type==e)return this.next[t].next;return null}matchFragment(e,t=0,n=e.childCount){let o=this;for(let r=t;o&&r<n;r++)o=o.matchType(e.child(r).type);return o}get inlineContent(){return 0!=this.next.length&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:t}=this.next[e];if(!t.isText&&!t.hasRequiredAttrs())return t}return null}compatible(e){for(let t=0;t<this.next.length;t++)for(let n=0;n<e.next.length;n++)if(this.next[t].type==e.next[n].type)return!0;return!1}fillBefore(e,t=!1,n=0){let o=[this];return function r(i,s){let a=i.matchFragment(e,n);if(a&&(!t||a.validEnd))return z.from(s.map(e=>e.createAndFill()));for(let e=0;e<i.next.length;e++){let{type:t,next:n}=i.next[e];if(!t.isText&&!t.hasRequiredAttrs()&&-1==o.indexOf(n)){o.push(n);let e=r(n,s.concat(t));if(e)return e}}return null}(this,[])}findWrapping(e){for(let t=0;t<this.wrapCache.length;t+=2)if(this.wrapCache[t]==e)return this.wrapCache[t+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),n=[{match:this,type:null,via:null}];for(;n.length;){let o=n.shift(),r=o.match;if(r.matchType(e)){let e=[];for(let t=o;t.type;t=t.via)e.push(t.type);return e.reverse()}for(let e=0;e<r.next.length;e++){let{type:i,next:s}=r.next[e];i.isLeaf||i.hasRequiredAttrs()||i.name in t||o.type&&!s.validEnd||(n.push({match:i.contentMatch,type:i,via:o}),t[i.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];return function t(n){e.push(n);for(let o=0;o<n.next.length;o++)-1==e.indexOf(n.next[o].next)&&t(n.next[o].next)}(this),e.map((t,n)=>{let o=n+(t.validEnd?"*":" ")+" ";for(let n=0;n<t.next.length;n++)o+=(n?", ":"")+t.next[n].type.name+"->"+e.indexOf(t.next[n].next);return o}).join("\n")}}he.empty=new he(!0);class fe{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 me(e){let t=[];do{t.push(ge(e))}while(e.eat("|"));return 1==t.length?t[0]:{type:"choice",exprs:t}}function ge(e){let t=[];do{t.push(ve(e))}while(e.next&&")"!=e.next&&"|"!=e.next);return 1==t.length?t[0]:{type:"seq",exprs:t}}function ve(e){let t=function(e){if(e.eat("(")){let t=me(e);return e.eat(")")||e.err("Missing closing paren"),t}if(!/\W/.test(e.next)){let t=function(e,t){let n=e.nodeTypes,o=n[t];if(o)return[o];let r=[];for(let e in n){let o=n[e];o.isInGroup(t)&&r.push(o)}0==r.length&&e.err("No node type or group '"+t+"' found");return r}(e,e.next).map(t=>(null==e.inline?e.inline=t.isInline:e.inline!=t.isInline&&e.err("Mixing inline and block content"),{type:"name",value:t}));return e.pos++,1==t.length?t[0]:{type:"choice",exprs:t}}e.err("Unexpected token '"+e.next+"'")}(e);for(;;)if(e.eat("+"))t={type:"plus",expr:t};else if(e.eat("*"))t={type:"star",expr:t};else if(e.eat("?"))t={type:"opt",expr:t};else{if(!e.eat("{"))break;t=be(e,t)}return t}function ye(e){/\D/.test(e.next)&&e.err("Expected number, got '"+e.next+"'");let t=Number(e.next);return e.pos++,t}function be(e,t){let n=ye(e),o=n;return e.eat(",")&&(o="}"!=e.next?ye(e):-1),e.eat("}")||e.err("Unclosed braced range"),{type:"range",min:n,max:o,expr:t}}function we(e,t){return t-e}function ke(e,t){let n=[];return function t(o){let r=e[o];if(1==r.length&&!r[0].term)return t(r[0].to);n.push(o);for(let e=0;e<r.length;e++){let{term:o,to:i}=r[e];o||-1!=n.indexOf(i)||t(i)}}(t),n.sort(we)}function xe(e){let t=Object.create(null);for(let n in e){let o=e[n];if(!o.hasDefault)return null;t[n]=o.default}return t}function Ce(e,t){let n=Object.create(null);for(let o in e){let r=t&&t[o];if(void 0===r){let t=e[o];if(!t.hasDefault)throw new RangeError("No value supplied for attribute "+o);r=t.default}n[o]=r}return n}function Me(e,t,n,o){for(let o in t)if(!(o in e))throw new RangeError(`Unsupported attribute ${o} for ${n} of type ${o}`);for(let n in e){let o=e[n];o.validate&&o.validate(t[n])}}function Se(e,t){let n=Object.create(null);if(t)for(let o in t)n[o]=new Te(e,o,t[o]);return n}let Ae=class e{constructor(e,t,n){this.name=e,this.schema=t,this.spec=n,this.markSet=null,this.groups=n.group?n.group.split(" "):[],this.attrs=Se(e,n.attrs),this.defaultAttrs=xe(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(n.inline||"text"==e),this.isText="text"==e}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==he.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:Ce(this.attrs,e)}create(e=null,t,n){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new de(this,this.computeAttrs(e),z.from(t),W.setFrom(n))}createChecked(e=null,t,n){return t=z.from(t),this.checkContent(t),new de(this,this.computeAttrs(e),t,W.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),(t=z.from(t)).size){let e=this.contentMatch.fillBefore(t);if(!e)return null;t=e.append(t)}let o=this.contentMatch.matchFragment(t),r=o&&o.fillBefore(z.empty,!0);return r?new de(this,e,t.append(r),W.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let t=0;t<e.childCount;t++)if(!this.allowsMarks(e.child(t).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw new RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){Me(this.attrs,e,"node",this.name)}allowsMarkType(e){return null==this.markSet||this.markSet.indexOf(e)>-1}allowsMarks(e){if(null==this.markSet)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){if(null==this.markSet)return e;let t;for(let n=0;n<e.length;n++)this.allowsMarkType(e[n].type)?t&&t.push(e[n]):t||(t=e.slice(0,n));return t?t.length?t:W.none:e}static compile(t,n){let o=Object.create(null);t.forEach((t,r)=>o[t]=new e(t,n,r));let r=n.spec.topNode||"doc";if(!o[r])throw new RangeError("Schema is missing its top node type ('"+r+"')");if(!o.text)throw new RangeError("Every schema needs a 'text' type");for(let e in o.text.attrs)throw new RangeError("The text node type should not have attributes");return o}};class Te{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,"default"),this.default=n.default,this.validate="string"==typeof n.validate?function(e,t,n){let o=n.split("|");return n=>{let r=null===n?"null":typeof n;if(o.indexOf(r)<0)throw new RangeError(`Expected value of type ${o} for attribute ${t} on type ${e}, got ${r}`)}}(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}}class Oe{constructor(e,t,n,o){this.name=e,this.rank=t,this.schema=n,this.spec=o,this.attrs=Se(e,o.attrs),this.excluded=null;let r=xe(this.attrs);this.instance=r?new W(this,r):null}create(e=null){return!e&&this.instance?this.instance:new W(this,Ce(this.attrs,e))}static compile(e,t){let n=Object.create(null),o=0;return e.forEach((e,r)=>n[e]=new Oe(e,o++,t,r)),n}removeFromSet(e){for(var t=0;t<e.length;t++)e[t].type==this&&(e=e.slice(0,t).concat(e.slice(t+1)),t--);return e}isInSet(e){for(let t=0;t<e.length;t++)if(e[t].type==this)return e[t]}checkAttrs(e){Me(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class Le{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let n in e)t[n]=e[n];t.nodes=$.from(e.nodes),t.marks=$.from(e.marks||{}),this.nodes=Ae.compile(this.spec.nodes,this),this.marks=Oe.compile(this.spec.marks,this);let n=Object.create(null);for(let e in this.nodes){if(e in this.marks)throw new RangeError(e+" can not be both a node and a mark");let t=this.nodes[e],o=t.spec.content||"",r=t.spec.marks;if(t.contentMatch=n[o]||(n[o]=he.parse(o,this.nodes)),t.inlineContent=t.contentMatch.inlineContent,t.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!t.isInline||!t.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=t}t.markSet="_"==r?null:r?Ee(this,r.split(" ")):""!=r&&t.inlineContent?null:[]}for(let e in this.marks){let t=this.marks[e],n=t.spec.excludes;t.excluded=null==n?[t]:""==n?[]:Ee(this,n.split(" "))}this.nodeFromJSON=e=>de.fromJSON(this,e),this.markFromJSON=e=>W.fromJSON(this,e),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,n,o){if("string"==typeof e)e=this.nodeType(e);else{if(!(e instanceof Ae))throw new RangeError("Invalid node type: "+e);if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}return e.createChecked(t,n,o)}text(e,t){let n=this.nodes.text;return new pe(n,n.defaultAttrs,e,W.setFrom(t))}mark(e,t){return"string"==typeof e&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function Ee(e,t){let n=[];for(let o=0;o<t.length;o++){let r=t[o],i=e.marks[r],s=i;if(i)n.push(i);else for(let t in e.marks){let o=e.marks[t];("_"==r||o.spec.group&&o.spec.group.split(" ").indexOf(r)>-1)&&n.push(s=o)}if(!s)throw new SyntaxError("Unknown mark type: '"+t[o]+"'")}return n}class Ne{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(e=>{if(function(e){return null!=e.tag}(e))this.tags.push(e);else if(function(e){return null!=e.style}(e)){let t=/[^=]*/.exec(e.style)[0];n.indexOf(t)<0&&n.push(t),this.styles.push(e)}}),this.normalizeLists=!this.tags.some(t=>{if(!/^(ul|ol)\b/.test(t.tag)||!t.node)return!1;let n=e.nodes[t.node];return n.contentMatch.matchType(n)})}parse(e,t={}){let n=new $e(this,t,!1);return n.addAll(e,W.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new $e(this,t,!0);return n.addAll(e,W.none,t.from,t.to),K.maxOpen(n.finish())}matchTag(e,t,n){for(let o=n?this.tags.indexOf(n)+1:0;o<this.tags.length;o++){let n=this.tags[o];if(Ie(e,n.tag)&&(void 0===n.namespace||e.namespaceURI==n.namespace)&&(!n.context||t.matchesContext(n.context))){if(n.getAttrs){let t=n.getAttrs(e);if(!1===t)continue;n.attrs=t||void 0}return n}}}matchStyle(e,t,n,o){for(let r=o?this.styles.indexOf(o)+1:0;r<this.styles.length;r++){let o=this.styles[r],i=o.style;if(!(0!=i.indexOf(e)||o.context&&!n.matchesContext(o.context)||i.length>e.length&&(61!=i.charCodeAt(e.length)||i.slice(e.length+1)!=t))){if(o.getAttrs){let e=o.getAttrs(t);if(!1===e)continue;o.attrs=e||void 0}return o}}}static schemaRules(e){let t=[];function n(e){let n=null==e.priority?50:e.priority,o=0;for(;o<t.length;o++){let e=t[o];if((null==e.priority?50:e.priority)<n)break}t.splice(o,0,e)}for(let t in e.marks){let o=e.marks[t].spec.parseDOM;o&&o.forEach(e=>{n(e=Be(e)),e.mark||e.ignore||e.clearMark||(e.mark=t)})}for(let t in e.nodes){let o=e.nodes[t].spec.parseDOM;o&&o.forEach(e=>{n(e=Be(e)),e.node||e.ignore||e.mark||(e.node=t)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new Ne(e,Ne.schemaRules(e)))}}const He={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},De={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},_e={ol:!0,ul:!0};function Ve(e,t,n){return null!=t?(t?1:0)|("full"===t?2:0):e&&"pre"==e.whitespace?3:-5&n}class Re{constructor(e,t,n,o,r,i){this.type=e,this.attrs=t,this.marks=n,this.solid=o,this.options=i,this.content=[],this.activeMarks=W.none,this.match=r||(4&i?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(z.from(e));if(!t){let t,n=this.type.contentMatch;return(t=n.findWrapping(e.type))?(this.match=n,t):null}this.match=this.type.contentMatch.matchFragment(t)}return this.match.findWrapping(e.type)}finish(e){if(!(1&this.options)){let e,t=this.content[this.content.length-1];if(t&&t.isText&&(e=/[ \t\r\n\u000c]+$/.exec(t.text))){let n=t;t.text.length==e[0].length?this.content.pop():this.content[this.content.length-1]=n.withText(n.text.slice(0,n.text.length-e[0].length))}}let t=z.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(z.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!He.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class $e{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let o,r=t.topNode,i=Ve(null,t.preserveWhitespace,0)|(n?4:0);o=r?new Re(r.type,r.attrs,W.none,!0,t.topMatch||r.type.contentMatch,i):new Re(n?null:e.schema.topNodeType,null,W.none,!0,null,i),this.nodes=[o],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){3==e.nodeType?this.addTextNode(e,t):1==e.nodeType&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,o=this.top,r=2&o.options?"full":this.localPreserveWS||(1&o.options)>0;if("full"===r||o.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(r)n="full"!==r?n.replace(/\r?\n|\r/g," "):n.replace(/\r\n?/g,"\n");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let t=o.content[o.content.length-1],r=e.previousSibling;(!t||r&&"BR"==r.nodeName||t.isText&&/[ \t\r\n\u000c]$/.test(t.text))&&(n=n.slice(1))}n&&this.insertNode(this.parser.schema.text(n),t,!/\S/.test(n)),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let o=this.localPreserveWS,r=this.top;("PRE"==e.tagName||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let i,s=e.nodeName.toLowerCase();_e.hasOwnProperty(s)&&this.parser.normalizeLists&&function(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let e=1==t.nodeType?t.nodeName.toLowerCase():null;e&&_e.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):"li"==e?n=t:e&&(n=null)}}(e);let a=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(i=this.parser.matchTag(e,this,n));e:if(a?a.ignore:De.hasOwnProperty(s))this.findInside(e),this.ignoreFallback(e,t);else if(!a||a.skip||a.closeParent){a&&a.closeParent?this.open=Math.max(0,this.open-1):a&&a.skip.nodeType&&(e=a.skip);let n,o=this.needsBlock;if(He.hasOwnProperty(s))r.content.length&&r.content[0].isInline&&this.open&&(this.open--,r=this.top),n=!0,r.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let i=a&&a.skip?t:this.readStyles(e,t);i&&this.addAll(e,i),n&&this.sync(r),this.needsBlock=o}else{let n=this.readStyles(e,t);n&&this.addElementByRule(e,a,n,!1===a.consuming?i:void 0)}this.localPreserveWS=o}leafFallback(e,t){"BR"==e.nodeName&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode("\n"),t)}ignoreFallback(e,t){"BR"!=e.nodeName||this.top.type&&this.top.type.inlineContent||this.findPlace(this.parser.schema.text("-"),t,!0)}readStyles(e,t){let n=e.style;if(n&&n.length)for(let e=0;e<this.parser.matchedStyles.length;e++){let o=this.parser.matchedStyles[e],r=n.getPropertyValue(o);if(r)for(let e;;){let n=this.parser.matchStyle(o,r,this,e);if(!n)break;if(n.ignore)return null;if(t=n.clearMark?t.filter(e=>!n.clearMark(e)):t.concat(this.parser.schema.marks[n.mark].create(n.attrs)),!1!==n.consuming)break;e=n}}return t}addElementByRule(e,t,n,o){let r,i;if(t.node)if(i=this.parser.schema.nodes[t.node],i.isLeaf)this.insertNode(i.create(t.attrs),n,"BR"==e.nodeName)||this.leafFallback(e,n);else{let e=this.enter(i,t.attrs||null,n,t.preserveWhitespace);e&&(r=!0,n=e)}else{let e=this.parser.schema.marks[t.mark];n=n.concat(e.create(t.attrs))}let s=this.top;if(i&&i.isLeaf)this.findInside(e);else if(o)this.addElement(e,n,o);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(e=>this.insertNode(e,n,!1));else{let o=e;"string"==typeof t.contentElement?o=e.querySelector(t.contentElement):"function"==typeof t.contentElement?o=t.contentElement(e):t.contentElement&&(o=t.contentElement),this.findAround(e,o,!0),this.addAll(o,n),this.findAround(e,o,!1)}r&&this.sync(s)&&this.open--}addAll(e,t,n,o){let r=n||0;for(let i=n?e.childNodes[n]:e.firstChild,s=null==o?null:e.childNodes[o];i!=s;i=i.nextSibling,++r)this.findAtPoint(e,r),this.addDOM(i,t);this.findAtPoint(e,r)}findPlace(e,t,n){let o,r;for(let t=this.open,i=0;t>=0;t--){let s=this.nodes[t],a=s.findWrapping(e);if(a&&(!o||o.length>a.length+i)&&(o=a,r=s,!a.length))break;if(s.solid){if(n)break;i+=2}}if(!o)return null;this.sync(r);for(let e=0;e<o.length;e++)t=this.enterInner(o[e],null,t,!1);return t}insertNode(e,t,n){if(e.isInline&&this.needsBlock&&!this.top.type){let e=this.textblockFromContext();e&&(t=this.enterInner(e,null,t))}let o=this.findPlace(e,t,n);if(o){this.closeExtra();let t=this.top;t.match&&(t.match=t.match.matchType(e.type));let n=W.none;for(let r of o.concat(e.marks))(t.type?t.type.allowsMarkType(r.type):ze(r.type,e.type))&&(n=r.addToSet(n));return t.content.push(e.mark(n)),!0}return!1}enter(e,t,n,o){let r=this.findPlace(e.create(t),n,!1);return r&&(r=this.enterInner(e,t,n,!0,o)),r}enterInner(e,t,n,o=!1,r){this.closeExtra();let i=this.top;i.match=i.match&&i.match.matchType(e);let s=Ve(e,r,i.options);4&i.options&&0==i.content.length&&(s|=4);let a=W.none;return n=n.filter(t=>!(i.type?i.type.allowsMarkType(t.type):ze(t.type,e))||(a=t.addToSet(a),!1)),this.nodes.push(new Re(e,t,a,o,null,s)),this.open++,n}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.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;this.localPreserveWS&&(this.nodes[t].options|=1)}return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let t=n.length-1;t>=0;t--)e+=n[t].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&this.find[n].offset==t&&(this.find[n].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)null==this.find[t].pos&&1==e.nodeType&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,n){if(e!=t&&this.find)for(let o=0;o<this.find.length;o++)if(null==this.find[o].pos&&1==e.nodeType&&e.contains(this.find[o].node)){t.compareDocumentPosition(this.find[o].node)&(n?2:4)&&(this.find[o].pos=this.currentPos)}}findInText(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].node==e&&(this.find[t].pos=this.currentPos-(e.nodeValue.length-this.find[t].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),n=this.options.context,o=!(this.isOpen||n&&n.parent.type!=this.nodes[0].type),r=-(n?n.depth+1:0)+(o?0:1),i=(e,s)=>{for(;e>=0;e--){let a=t[e];if(""==a){if(e==t.length-1||0==e)continue;for(;s>=r;s--)if(i(e-1,s))return!0;return!1}{let e=s>0||0==s&&o?this.nodes[s].type:n&&s>=r?n.node(s-r).type:null;if(!e||e.name!=a&&!e.isInGroup(a))return!1;s--}}return!0};return i(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let e in this.parser.schema.nodes){let t=this.parser.schema.nodes[e];if(t.isTextblock&&t.defaultAttrs)return t}}}function Ie(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function Be(e){let t={};for(let n in e)t[n]=e[n];return t}function ze(e,t){let n=t.schema.nodes;for(let o in n){let r=n[o];if(!r.allowsMarkType(e))continue;let i=[],s=e=>{i.push(e);for(let n=0;n<e.edgeCount;n++){let{type:o,next:r}=e.edge(n);if(o==t)return!0;if(i.indexOf(r)<0&&s(r))return!0}};if(s(r.contentMatch))return!0}}class Pe{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=Fe(t).createDocumentFragment());let o=n,r=[];return e.forEach(e=>{if(r.length||e.marks.length){let n=0,i=0;for(;n<r.length&&i<e.marks.length;){let t=e.marks[i];if(this.marks[t.type.name]){if(!t.eq(r[n][0])||!1===t.type.spec.spanning)break;n++,i++}else i++}for(;n<r.length;)o=r.pop()[1];for(;i<e.marks.length;){let n=e.marks[i++],s=this.serializeMark(n,e.isInline,t);s&&(r.push([n,o]),o.appendChild(s.dom),o=s.contentDOM||s.dom)}}o.appendChild(this.serializeNodeInner(e,t))}),n}serializeNodeInner(e,t){let{dom:n,contentDOM:o}=Ke(Fe(t),this.nodes[e.type.name](e),null,e.attrs);if(o){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,o)}return n}serializeNode(e,t={}){let n=this.serializeNodeInner(e,t);for(let o=e.marks.length-1;o>=0;o--){let r=this.serializeMark(e.marks[o],e.isInline,t);r&&((r.contentDOM||r.dom).appendChild(n),n=r.dom)}return n}serializeMark(e,t,n={}){let o=this.marks[e.type.name];return o&&Ke(Fe(n),o(e,t),null,e.attrs)}static renderSpec(e,t,n=null,o){return Ke(e,t,n,o)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new Pe(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=je(e.nodes);return t.text||(t.text=e=>e.text),t}static marksFromSchema(e){return je(e.marks)}}function je(e){let t={};for(let n in e){let o=e[n].spec.toDOM;o&&(t[n]=o)}return t}function Fe(e){return e.document||window.document}const We=new WeakMap;function qe(e){let t=We.get(e);return void 0===t&&We.set(e,t=function(e){let t=null;function n(e){if(e&&"object"==typeof e)if(Array.isArray(e))if("string"==typeof e[0])t||(t=[]),t.push(e);else for(let t=0;t<e.length;t++)n(e[t]);else for(let t in e)n(e[t])}return n(e),t}(e)),t}function Ke(e,t,n,o){if("string"==typeof t)return{dom:e.createTextNode(t)};if(null!=t.nodeType)return{dom:t};if(t.dom&&null!=t.dom.nodeType)return t;let r,i=t[0];if("string"!=typeof i)throw new RangeError("Invalid array passed to renderSpec");if(o&&(r=qe(o))&&r.indexOf(t)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let s,a=i.indexOf(" ");a>0&&(n=i.slice(0,a),i=i.slice(a+1));let l=n?e.createElementNS(n,i):e.createElement(i),c=t[1],d=1;if(c&&"object"==typeof c&&null==c.nodeType&&!Array.isArray(c)){d=2;for(let e in c)if(null!=c[e]){let t=e.indexOf(" ");t>0?l.setAttributeNS(e.slice(0,t),e.slice(t+1),c[e]):"style"==e&&l.style?l.style.cssText=c[e]:l.setAttribute(e,c[e])}}for(let r=d;r<t.length;r++){let i=t[r];if(0===i){if(r<t.length-1||r>d)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}{let{dom:t,contentDOM:r}=Ke(e,i,n,o);if(l.appendChild(t),r){if(s)throw new RangeError("Multiple content holes");s=r}}}return{dom:l,contentDOM:s}}const Ue=Math.pow(2,16);function Je(e,t){return e+t*Ue}function Ze(e){return 65535&e}class Ge{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(8&this.delInfo)>0}get deletedBefore(){return(5&this.delInfo)>0}get deletedAfter(){return(6&this.delInfo)>0}get deletedAcross(){return(4&this.delInfo)>0}}class Qe{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&Qe.empty)return Qe.empty}recover(e){let t=0,n=Ze(e);if(!this.inverted)for(let e=0;e<n;e++)t+=this.ranges[3*e+2]-this.ranges[3*e+1];return this.ranges[3*n]+t+function(e){return(e-(65535&e))/Ue}(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,n){let o=0,r=this.inverted?2:1,i=this.inverted?1:2;for(let s=0;s<this.ranges.length;s+=3){let a=this.ranges[s]-(this.inverted?o:0);if(a>e)break;let l=this.ranges[s+r],c=this.ranges[s+i],d=a+l;if(e<=d){let r=a+o+((l?e==a?-1:e==d?1:t:t)<0?0:c);if(n)return r;let i=e==(t<0?a:d)?null:Je(s/3,e-a),p=e==a?2:e==d?1:4;return(t<0?e!=a:e!=d)&&(p|=8),new Ge(r,p,i)}o+=c-l}return n?e+o:new Ge(e+o,0,null)}touches(e,t){let n=0,o=Ze(t),r=this.inverted?2:1,i=this.inverted?1:2;for(let t=0;t<this.ranges.length;t+=3){let s=this.ranges[t]-(this.inverted?n:0);if(s>e)break;let a=this.ranges[t+r];if(e<=s+a&&t==3*o)return!0;n+=this.ranges[t+i]-a}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let o=0,r=0;o<this.ranges.length;o+=3){let i=this.ranges[o],s=i-(this.inverted?r:0),a=i+(this.inverted?0:r),l=this.ranges[o+t],c=this.ranges[o+n];e(s,s+l,a,a+c),r+=c-l}}invert(){return new Qe(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return 0==e?Qe.empty:new Qe(e<0?[0,-e,0]:[0,0,e])}}Qe.empty=new Qe([]);class Xe{constructor(e,t,n=0,o=(e?e.length:0)){this.mirror=t,this.from=n,this.to=o,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(e=0,t=this.maps.length){return new Xe(this._maps,this.mirror,e,t)}appendMap(e,t){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(e),null!=t&&this.setMirror(this._maps.length-1,t)}appendMapping(e){for(let t=0,n=this._maps.length;t<e._maps.length;t++){let o=e.getMirror(t);this.appendMap(e._maps[t],null!=o&&o<t?n+o:void 0)}}getMirror(e){if(this.mirror)for(let t=0;t<this.mirror.length;t++)if(this.mirror[t]==e)return this.mirror[t+(t%2?-1:1)]}setMirror(e,t){this.mirror||(this.mirror=[]),this.mirror.push(e,t)}appendMappingInverted(e){for(let t=e.maps.length-1,n=this._maps.length+e._maps.length;t>=0;t--){let o=e.getMirror(t);this.appendMap(e._maps[t].invert(),null!=o&&o>t?n-o-1:void 0)}}invert(){let e=new Xe;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;n<this.to;n++)e=this._maps[n].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,n){let o=0;for(let n=this.from;n<this.to;n++){let r=this._maps[n].mapResult(e,t);if(null!=r.recover){let t=this.getMirror(n);if(null!=t&&t>n&&t<this.to){n=t,e=this._maps[t].recover(r.recover);continue}}o|=r.delInfo,e=r.pos}return n?e:new Ge(e,o,null)}}const Ye=Object.create(null);class et{getMap(){return Qe.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let n=Ye[t.stepType];if(!n)throw new RangeError(`No step type ${t.stepType} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in Ye)throw new RangeError("Duplicate use of step JSON ID "+e);return Ye[e]=t,t.prototype.jsonID=e,t}}class tt{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new tt(e,null)}static fail(e){return new tt(null,e)}static fromReplace(e,t,n,o){try{return tt.ok(e.replace(t,n,o))}catch(e){if(e instanceof q)return tt.fail(e.message);throw e}}}function nt(e,t,n){let o=[];for(let r=0;r<e.childCount;r++){let i=e.child(r);i.content.size&&(i=i.copy(nt(i.content,t,i))),i