diff --git a/src/editor.css b/src/editor.css new file mode 100644 index 0000000..9b99dd9 --- /dev/null +++ b/src/editor.css @@ -0,0 +1,337 @@ +.ProseMirror { + position: relative; +} + +.ProseMirror { + word-wrap: break-word; + white-space: pre-wrap; + white-space: break-spaces; + -webkit-font-variant-ligatures: none; + font-variant-ligatures: none; + font-feature-settings: "liga" 0; /* the above doesn't seem to work in Edge */ +} + +.ProseMirror pre { + white-space: pre-wrap; +} + +.ProseMirror li { + position: relative; +} + +.ProseMirror-hideselection *::selection { background: transparent; } +.ProseMirror-hideselection *::-moz-selection { background: transparent; } +.ProseMirror-hideselection { caret-color: transparent; } + +/* See https://github.com/ProseMirror/prosemirror/issues/1421#issuecomment-1759320191 */ +.ProseMirror [draggable][contenteditable=false] { user-select: text } + +.ProseMirror-selectednode { + outline: 2px solid #8cf; +} + +/* Make sure li selections wrap around markers */ + +li.ProseMirror-selectednode { + outline: none; +} + +li.ProseMirror-selectednode:after { + content: ""; + position: absolute; + left: -32px; + right: -2px; top: -2px; bottom: -2px; + border: 2px solid #8cf; + pointer-events: none; +} + +/* Protect against generic img rules */ + +img.ProseMirror-separator { + display: inline !important; + border: none !important; + margin: 0 !important; +} +.ProseMirror-textblock-dropdown { + min-width: 3em; +} + +.ProseMirror-menu { + margin: 0 -4px; + line-height: 1; +} + +.ProseMirror-tooltip .ProseMirror-menu { + width: -webkit-fit-content; + width: fit-content; + white-space: pre; +} + +.ProseMirror-menuitem { + margin-right: 3px; + display: inline-block; +} + +.ProseMirror-menuseparator { + border-right: 1px solid #ddd; + margin-right: 3px; +} + +.ProseMirror-menu-dropdown, .ProseMirror-menu-dropdown-menu { + font-size: 90%; + white-space: nowrap; +} + +.ProseMirror-menu-dropdown { + vertical-align: 1px; + cursor: pointer; + position: relative; + padding-right: 15px; +} + +.ProseMirror-menu-dropdown-wrap { + padding: 1px 0 1px 4px; + display: inline-block; + position: relative; +} + +.ProseMirror-menu-dropdown:after { + content: ""; + border-left: 4px solid transparent; + border-right: 4px solid transparent; + border-top: 4px solid currentColor; + opacity: .6; + position: absolute; + right: 4px; + top: calc(50% - 2px); +} + +.ProseMirror-menu-dropdown-menu, .ProseMirror-menu-submenu { + position: absolute; + background: white; + color: #666; + border: 1px solid #aaa; + padding: 2px; +} + +.ProseMirror-menu-dropdown-menu { + z-index: 15; + min-width: 6em; +} + +.ProseMirror-menu-dropdown-item { + cursor: pointer; + padding: 2px 8px 2px 4px; +} + +.ProseMirror-menu-dropdown-item:hover { + background: #f2f2f2; +} + +.ProseMirror-menu-submenu-wrap { + position: relative; + margin-right: -4px; +} + +.ProseMirror-menu-submenu-label:after { + content: ""; + border-top: 4px solid transparent; + border-bottom: 4px solid transparent; + border-left: 4px solid currentColor; + opacity: .6; + position: absolute; + right: 4px; + top: calc(50% - 4px); +} + +.ProseMirror-menu-submenu { + display: none; + min-width: 4em; + left: 100%; + top: -3px; +} + +.ProseMirror-menu-active { + background: #eee; + border-radius: 4px; +} + +.ProseMirror-menu-disabled { + opacity: .3; +} + +.ProseMirror-menu-submenu-wrap:hover .ProseMirror-menu-submenu, .ProseMirror-menu-submenu-wrap-active .ProseMirror-menu-submenu { + display: block; +} + +.ProseMirror-menubar { + border-top-left-radius: inherit; + border-top-right-radius: inherit; + position: relative; + min-height: 1em; + color: #666; + padding: 1px 6px; + top: 0; left: 0; right: 0; + border-bottom: 1px solid silver; + background: white; + z-index: 10; + -moz-box-sizing: border-box; + box-sizing: border-box; + overflow: visible; +} + +.ProseMirror-icon { + display: inline-block; + line-height: .8; + vertical-align: -2px; /* Compensate for padding */ + padding: 2px 8px; + cursor: pointer; +} + +.ProseMirror-menu-disabled.ProseMirror-icon { + cursor: default; +} + +.ProseMirror-icon svg { + fill: currentColor; + height: 1em; +} + +.ProseMirror-icon span { + vertical-align: text-top; +} +.ProseMirror-gapcursor { + display: none; + pointer-events: none; + position: absolute; +} + +.ProseMirror-gapcursor:after { + content: ""; + display: block; + position: absolute; + top: -2px; + width: 20px; + border-top: 1px solid black; + animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite; +} + +@keyframes ProseMirror-cursor-blink { + to { + visibility: hidden; + } +} + +.ProseMirror-focused .ProseMirror-gapcursor { + display: block; +} +/* Add space around the hr to make clicking it easier */ + +.ProseMirror-example-setup-style hr { + padding: 2px 10px; + border: none; + margin: 1em 0; +} + +.ProseMirror-example-setup-style hr:after { + content: ""; + display: block; + height: 1px; + background-color: silver; + line-height: 2px; +} + +.ProseMirror ul, .ProseMirror ol { + padding-left: 30px; +} + +.ProseMirror blockquote { + padding-left: 1em; + border-left: 3px solid #eee; + margin-left: 0; margin-right: 0; +} + +.ProseMirror-example-setup-style img { + cursor: default; +} + +.ProseMirror-prompt { + background: white; + padding: 5px 10px 5px 15px; + border: 1px solid silver; + position: fixed; + border-radius: 3px; + z-index: 11; + box-shadow: -.5px 2px 5px rgba(0, 0, 0, .2); +} + +.ProseMirror-prompt h5 { + margin: 0; + font-weight: normal; + font-size: 100%; + color: #444; +} + +.ProseMirror-prompt input[type="text"], +.ProseMirror-prompt textarea { + background: #eee; + border: none; + outline: none; +} + +.ProseMirror-prompt input[type="text"] { + padding: 0 4px; +} + +.ProseMirror-prompt-close { + position: absolute; + left: 2px; top: 1px; + color: #666; + border: none; background: transparent; padding: 0; +} + +.ProseMirror-prompt-close:after { + content: "✕"; + font-size: 12px; +} + +.ProseMirror-invalid { + background: #ffc; + border: 1px solid #cc7; + border-radius: 4px; + padding: 5px 10px; + position: absolute; + min-width: 10em; +} + +.ProseMirror-prompt-buttons { + margin-top: 5px; + display: none; +} +#editor, .editor { + background: white; + color: black; + background-clip: padding-box; + border-radius: 4px; + border: 2px solid rgba(0, 0, 0, 0.2); + padding: 5px 0; + margin-bottom: 23px; +} + +.ProseMirror p:first-child, +.ProseMirror h1:first-child, +.ProseMirror h2:first-child, +.ProseMirror h3:first-child, +.ProseMirror h4:first-child, +.ProseMirror h5:first-child, +.ProseMirror h6:first-child { + margin-top: 10px; +} + +.ProseMirror { + padding: 4px 8px 4px 14px; + line-height: 1.2; + outline: none; +} + +.ProseMirror p { margin-bottom: 1em } diff --git a/src/prosemirror-k2k.html b/src/prosemirror-k2k.html new file mode 100644 index 0000000..ca6c7e1 --- /dev/null +++ b/src/prosemirror-k2k.html @@ -0,0 +1,96 @@ + + + + + + + ProseMirror Kommentator 2000 + + + + + +
+ +
+
+ +
+
+
+ + Art. 1 + + Verhandlungen + + +

(Art. 13, 16 Abs. 1 und 4, 17 RVOG)

+
+
+ + +

 Die Sitzungen des Bundesrates finden in der Regel einmal jede Woche statt.

+
+
+
+
+ + Art. 2 + + Geschäftsplanung + + +

(Art. 25 Abs. 2 Bst. a, 32 Bst. b und 33 RVOG)

+
+
+ + 1 + +

 Mit der Geschäftsplanung wird sichergestellt, dass die Geschäfte im Bundesrat + entsprechend ihrer Bedeutung und Dringlichkeit behandelt werden können.

+
+
+ + 2 + +

 Die Bundespräsidentin oder der Bundespräsident legt mit der Bundeskanzlei und den + Departementen die wichtigsten Geschäfte und Themenschwerpunkte für ein Quartal oder + Semester fest.

+
+
+
+
+
+ + + + + +
+ + + + + + \ No newline at end of file diff --git a/src/prosemirror-k2k.js b/src/prosemirror-k2k.js new file mode 100644 index 0000000..7552dbf --- /dev/null +++ b/src/prosemirror-k2k.js @@ -0,0 +1,80 @@ +(function (prosemirrorModel, prosemirrorTransform, prosemirrorCommands, prosemirrorKeymap, prosemirrorState, prosemirrorView, prosemirrorHistory) { + 'use strict'; + + // noteSchema{ + const noteSchema = new prosemirrorModel.Schema({ + nodes: { + text: {}, + article: { + content: "(num | heading | akn_paragraph)+", + toDOM() { return ["article", 0] }, + parseDOM: [{ tag: "article" }] + }, + num: { + content: "bold", + toDOM() { return ["num", 0] }, + parseDOM: [{ tag: "num" }] + }, + bold: { + content: "text*", + toDOM() { return ["b", 0] }, + parseDOM: [{ tag: "b" }] + }, + heading: { + content: "text*", + toDOM() { return ["heading", 0] }, + parseDOM: [{ tag: "heading" }] + }, + akn_paragraph: { + content: "content", + toDOM() { return ["paragraph", 0] }, + parseDOM: [{ tag: "paragraph" }] + }, + content: { + content: "paragraph", + toDOM() { return ["content", 0] }, + parseDOM: [{ tag: "content" }] + }, + paragraph: { + content: "text*", + toDOM() { return ["p", 0] }, + parseDOM: [{ tag: "p" }] + }, + doc: { + content: "article+" + } + } + }); + + function makeNoteGroup(state, dispatch) { + // Get a range around the selected blocks + let range = state.selection.$from.blockRange(state.selection.$to); + // See if it is possible to wrap that range in a note group + let wrapping = prosemirrorTransform.findWrapping(range, noteSchema.nodes.notegroup); + // If not, the command doesn't apply + if (!wrapping) return false + // Otherwise, dispatch a transaction, using the `wrap` method to + // create the step that does the actual wrapping. + if (dispatch) dispatch(state.tr.wrap(range, wrapping).scrollIntoView()); + return true + } + // } + + let histKeymap = prosemirrorKeymap.keymap({ "Mod-z": prosemirrorHistory.undo, "Mod-y": prosemirrorHistory.redo }); + + function start(place, content, schema, plugins = []) { + let doc = prosemirrorModel.DOMParser.fromSchema(schema).parse(content); + return new prosemirrorView.EditorView(place, { + state: prosemirrorState.EditorState.create({ + doc, + plugins: plugins.concat([histKeymap, prosemirrorKeymap.keymap(prosemirrorCommands.baseKeymap), prosemirrorHistory.history()]) + }) + }) + } + + function id(str) { return document.getElementById(str) } + + start(id("k2k-editor"), id("k2k-content"), noteSchema, [prosemirrorKeymap.keymap({ "Ctrl-Space": makeNoteGroup })]); + +})(PM.model, PM.transform, PM.commands, PM.keymap, PM.state, PM.view, PM.history); + diff --git a/src/prosemirror.js b/src/prosemirror.js new file mode 100644 index 0000000..adb0232 --- /dev/null +++ b/src/prosemirror.js @@ -0,0 +1,2 @@ +!function(){"use strict";function e(e){this.content=e}function t(e,n,r){for(let o=0;;o++){if(o==e.childCount||o==n.childCount)return e.childCount==n.childCount?null:r;let i=e.child(o),s=n.child(o);if(i!=s){if(!i.sameMarkup(s))return r;if(i.isText&&i.text!=s.text){for(let e=0;i.text[e]==s.text[e];e++)r++;return r}if(i.content.size||s.content.size){let e=t(i.content,s.content,r+1);if(null!=e)return e}r+=i.nodeSize}else r+=i.nodeSize}}function n(e,t,r,o){for(let i=e.childCount,s=t.childCount;;){if(0==i||0==s)return i==s?null:{a:r,b:o};let l=e.child(--i),a=t.child(--s),h=l.nodeSize;if(l!=a){if(!l.sameMarkup(a))return{a:r,b:o};if(l.isText&&l.text!=a.text){let e=0,t=Math.min(l.text.length,a.text.length);for(;e>1}},e.from=function(t){if(t instanceof e)return t;var n=[];if(t)for(var r in t)n.push(r,t[r]);return new e(n)};class r{constructor(e,t){if(this.content=e,this.size=t||0,null==t)for(let t=0;te&&!1!==n(l,r+s,o||null,i)&&l.content.size){let o=s+1;l.nodesBetween(Math.max(0,e-o),Math.min(l.content.size,t-o),n,r+o)}s=a}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let o="",i=!0;return this.nodesBetween(e,t,((s,l)=>{let a=s.isText?s.text.slice(Math.max(e,l)-l,t-l):s.isLeaf?r?"function"==typeof r?r(s):r:s.type.spec.leafText?s.type.spec.leafText(s):"":"";s.isBlock&&(s.isLeaf&&a||s.isTextblock)&&n&&(i?i=!1:o+=n),o+=a}),0),o}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,n=e.firstChild,o=this.content.slice(),i=0;for(t.isText&&t.sameMarkup(n)&&(o[o.length-1]=t.withText(t.text+n.text),i=1);ie)for(let r=0,i=0;ie&&((it)&&(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=l}return new r(n,o)}cutByIndex(e,t){return e==t?r.empty:0==e&&t==this.content.length?this:new r(this.content.slice(e,t))}replaceChild(e,t){let n=this.content[e];if(n==t)return this;let o=this.content.slice(),i=this.size+t.nodeSize-n.nodeSize;return o[e]=t,new r(o,i)}addToStart(e){return new r([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new r(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let n=0,r=0;;n++){let o=r+this.child(n).nodeSize;if(o>=e)return o==e||t>0?i(n+1,o):i(n,r);r=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 r.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new r(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return r.empty;let t,n=0;for(let r=0;rthis.type.rank&&(t||(t=e.slice(0,r)),t.push(this),n=!0),t&&t.push(o)}}return t||(t=e.slice()),n||t.push(this),t}removeFromSet(e){for(let t=0;te.type.rank-t.type.rank)),t}}l.none=[];class a extends Error{}class h{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=d(this.content,e+this.openStart,t);return n&&new h(n,this.openStart,this.openEnd)}removeBetween(e,t){return new h(c(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 h.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 h(r.fromJSON(e,t.content),n,o)}static maxOpen(e,t=!0){let n=0,r=0;for(let r=e.firstChild;r&&!r.isLeaf&&(t||!r.type.spec.isolating);r=r.firstChild)n++;for(let n=e.lastChild;n&&!n.isLeaf&&(t||!n.type.spec.isolating);n=n.lastChild)r++;return new h(e,n,r)}}function c(e,t,n){let{index:r,offset:o}=e.findIndex(t),i=e.maybeChild(r),{index:s,offset:l}=e.findIndex(n);if(o==t||i.isText){if(l!=n&&!e.child(s).isText)throw new RangeError("Removing non-flat range");return e.cut(0,t).append(e.cut(n))}if(r!=s)throw new RangeError("Removing non-flat range");return e.replaceChild(r,i.copy(c(i.content,t-o-1,n-o-1)))}function d(e,t,n,r){let{index:o,offset:i}=e.findIndex(t),s=e.maybeChild(o);if(i==t||s.isText)return r&&!r.canReplace(o,o,n)?null:e.cut(0,t).append(n).append(e.cut(t));let l=d(s.content,t-i-1,n);return l&&e.replaceChild(o,s.copy(l))}function p(e,t,n){if(n.openStart>e.depth)throw new a("Inserted content deeper than insertion position");if(e.depth-n.openStart!=t.depth-n.openEnd)throw new a("Inconsistent open depths");return u(e,t,n,0)}function u(e,t,n,o){let i=e.index(o),s=e.node(o);if(i==t.index(o)&&o=0;e--)o=t.node(e).copy(r.from(o));return{start:o.resolveNoCache(e.openStart+n),end:o.resolveNoCache(o.content.size-e.openEnd-n)}}(n,e);return w(s,v(e,i,l,t,o))}{let r=e.parent,o=r.content;return w(r,o.cut(0,e.parentOffset).append(n.content).append(o.cut(t.parentOffset)))}}return w(s,k(e,t,o))}function f(e,t){if(!t.type.compatibleContent(e.type))throw new a("Cannot join "+t.type.name+" onto "+e.type.name)}function m(e,t,n){let r=e.node(n);return f(r,t.node(n)),r}function g(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 y(e,t,n,r){let o=(t||e).node(n),i=0,s=t?t.index(n):o.childCount;e&&(i=e.index(n),e.depth>n?i++:e.textOffset&&(g(e.nodeAfter,r),i++));for(let e=i;ei&&m(e,t,i+1),l=o.depth>i&&m(n,o,i+1),a=[];return y(null,e,i,a),s&&l&&t.index(i)==n.index(i)?(f(s,l),g(w(s,v(e,t,n,o,i+1)),a)):(s&&g(w(s,k(e,t,i+1)),a),y(t,n,i,a),l&&g(w(l,k(n,o,i+1)),a)),y(o,null,i,a),new r(a)}function k(e,t,n){let o=[];if(y(null,e,n,o),e.depth>n){g(w(m(e,t,n+1),k(e,t,n+1)),o)}return y(t,null,n,o),new r(o)}h.empty=new h(r.empty,0,0);class b{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],r=e.child(t);return n?e.child(t).cut(n):r}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],r=0==t?0:this.path[3*t-1]+1;for(let t=0;t0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new C(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let n=[],r=0,o=t;for(let t=e;;){let{index:e,offset:i}=t.content.findIndex(o),s=o-i;if(n.push(t,e,r+i),!s)break;if(t=t.child(e),t.isText)break;o=s-1,r+=i+1}return new b(t,n,o)}static resolveCached(e,t){for(let n=0;ne&&this.nodesBetween(e,t,(e=>(n.isInSet(e.marks)&&(r=!0),!r))),r}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()+")"),T(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=r.empty,o=0,i=n.childCount){let s=this.contentMatchAt(e).matchFragment(n,o,i),l=s&&s.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let e=o;ee.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=null;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");n=t.marks.map(e.markFromJSON)}if("text"==t.type){if("string"!=typeof t.text)throw new RangeError("Invalid text node in JSON");return e.text(t.text,n)}let o=r.fromJSON(e,t.content);return e.nodeType(t.type).create(t.attrs,o,n)}}N.prototype.text=void 0;class D extends N{constructor(e,t,n,r){if(super(e,t,null,r),!n)throw new RangeError("Empty text nodes are not allowed");this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):T(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 D(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new D(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 T(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+"("+t+")";return t}class E{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let n=new A(e,t);if(null==n.next)return E.empty;let r=I(n);n.next&&n.err("Unexpected trailing text");let o=function(e){let t=Object.create(null);return n($(e,0));function n(r){let o=[];r.forEach((t=>{e[t].forEach((({term:t,to:n})=>{if(!t)return;let r;for(let e=0;e{r||o.push([t,r=[]]),-1==r.indexOf(e)&&r.push(e)}))}))}));let i=t[r.join(",")]=new E(r.indexOf(e.length-1)>-1);for(let e=0;ee.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 r(t,s),o(i(e.expr,s),s),[r(s)]}if("plus"==e.type){let s=n();return o(i(e.expr,t),s),o(i(e.expr,s),s),[r(s)]}if("opt"==e.type)return[r(t)].concat(i(e.expr,t));if("range"==e.type){let s=t;for(let t=0;te.createAndFill())));for(let e=0;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 r=0;r{let r=n+(t.validEnd?"*":" ")+" ";for(let n=0;n"+e.indexOf(t.next[n].next);return r})).join("\n")}}E.empty=new E(!0);class A{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 I(e){let t=[];do{t.push(R(e))}while(e.eat("|"));return 1==t.length?t[0]:{type:"choice",exprs:t}}function R(e){let t=[];do{t.push(z(e))}while(e.next&&")"!=e.next&&"|"!=e.next);return 1==t.length?t[0]:{type:"seq",exprs:t}}function z(e){let t=function(e){if(e.eat("(")){let t=I(e);return e.eat(")")||e.err("Missing closing paren"),t}if(!/\W/.test(e.next)){let t=function(e,t){let n=e.nodeTypes,r=n[t];if(r)return[r];let o=[];for(let e in n){let r=n[e];r.groups.indexOf(t)>-1&&o.push(r)}0==o.length&&e.err("No node type or group '"+t+"' found");return o}(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=B(e,t)}return t}function P(e){/\D/.test(e.next)&&e.err("Expected number, got '"+e.next+"'");let t=Number(e.next);return e.pos++,t}function B(e,t){let n=P(e),r=n;return e.eat(",")&&(r="}"!=e.next?P(e):-1),e.eat("}")||e.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:t}}function V(e,t){return t-e}function $(e,t){let n=[];return function t(r){let o=e[r];if(1==o.length&&!o[0].term)return t(o[0].to);n.push(r);for(let e=0;e-1}allowsMarks(e){if(null==this.markSet)return!0;for(let t=0;tn[e]=new _(e,t,r)));let r=t.spec.topNode||"doc";if(!n[r])throw new RangeError("Schema is missing its top node type ('"+r+"')");if(!n.text)throw new RangeError("Every schema needs a 'text' type");for(let e in n.text.attrs)throw new RangeError("The text node type should not have attributes");return n}}class J{constructor(e){this.hasDefault=Object.prototype.hasOwnProperty.call(e,"default"),this.default=e.default}get isRequired(){return!this.hasDefault}}class W{constructor(e,t,n,r){this.name=e,this.rank=t,this.schema=n,this.spec=r,this.attrs=L(r.attrs),this.excluded=null;let o=F(this.attrs);this.instance=o?new l(this,o):null}create(e=null){return!e&&this.instance?this.instance:new l(this,q(this.attrs,e))}static compile(e,t){let n=Object.create(null),r=0;return e.forEach(((e,o)=>n[e]=new W(e,r++,t,o))),n}removeFromSet(e){for(var t=0;t-1}}class j{constructor(t){this.cached=Object.create(null);let n=this.spec={};for(let e in t)n[e]=t[e];n.nodes=e.from(t.nodes),n.marks=e.from(t.marks||{}),this.nodes=_.compile(this.spec.nodes,this),this.marks=W.compile(this.spec.marks,this);let r=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],n=t.spec.content||"",o=t.spec.marks;t.contentMatch=r[n]||(r[n]=E.parse(n,this.nodes)),t.inlineContent=t.contentMatch.inlineContent,t.markSet="_"==o?null:o?K(this,o.split(" ")):""!=o&&t.inlineContent?null:[]}for(let e in this.marks){let t=this.marks[e],n=t.spec.excludes;t.excluded=null==n?[t]:""==n?[]:K(this,n.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,n,r){if("string"==typeof e)e=this.nodeType(e);else{if(!(e instanceof _))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,r)}text(e,t){let n=this.nodes.text;return new D(n,n.defaultAttrs,e,l.setFrom(t))}mark(e,t){return"string"==typeof e&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return N.fromJSON(this,e)}markFromJSON(e){return l.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function K(e,t){let n=[];for(let r=0;r-1)&&n.push(s=r)}if(!s)throw new SyntaxError("Unknown mark type: '"+t[r]+"'")}return n}class H{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[],t.forEach((e=>{e.tag?this.tags.push(e):e.style&&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 Z(this,t,!1);return n.addAll(e,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new Z(this,t,!0);return n.addAll(e,t.from,t.to),h.maxOpen(n.finish())}matchTag(e,t,n){for(let r=n?this.tags.indexOf(n)+1:0;re.length&&(61!=i.charCodeAt(e.length)||i.slice(e.length+1)!=t))){if(r.getAttrs){let e=r.getAttrs(t);if(!1===e)continue;r.attrs=e||void 0}return r}}}static schemaRules(e){let t=[];function n(e){let n=null==e.priority?50:e.priority,r=0;for(;r{n(e=te(e)),e.mark||e.ignore||e.clearMark||(e.mark=t)}))}for(let t in e.nodes){let r=e.nodes[t].spec.parseDOM;r&&r.forEach((e=>{n(e=te(e)),e.node||e.ignore||e.mark||(e.node=t)}))}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new H(e,H.schemaRules(e)))}}const U={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},G={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Q={ol:!0,ul:!0};function X(e,t,n){return null!=t?(t?1:0)|("full"===t?2:0):e&&"pre"==e.whitespace?3:-5&n}class Y{constructor(e,t,n,r,o,i,s){this.type=e,this.attrs=t,this.marks=n,this.pendingMarks=r,this.solid=o,this.options=s,this.content=[],this.activeMarks=l.none,this.stashMarks=[],this.match=i||(4&s?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(r.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=r.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(r.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}popFromStashMark(e){for(let t=this.stashMarks.length-1;t>=0;t--)if(e.eq(this.stashMarks[t]))return this.stashMarks.splice(t,1)[0]}applyPending(e){for(let t=0,n=this.pendingMarks;tthis.addAll(e))),t&&this.sync(n),this.needsBlock=i}else this.withStyleRules(e,(()=>{this.addElementByRule(e,o,!1===o.consuming?n:void 0)}))}leafFallback(e){"BR"==e.nodeName&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode("\n"))}ignoreFallback(e){"BR"!=e.nodeName||this.top.type&&this.top.type.inlineContent||this.findPlace(this.parser.schema.text("-"))}readStyles(e){let t=l.none,n=l.none;for(let r=0;r{i.clearMark(e)&&(n=e.addToSet(n))})):t=this.parser.schema.marks[i.mark].create(i.attrs).addToSet(t),!1!==i.consuming)break;o=i}return[t,n]}addElementByRule(e,t,n){let r,o,i;if(t.node)o=this.parser.schema.nodes[t.node],o.isLeaf?this.insertNode(o.create(t.attrs))||this.leafFallback(e):r=this.enter(o,t.attrs||null,t.preserveWhitespace);else{i=this.parser.schema.marks[t.mark].create(t.attrs),this.addPendingMark(i)}let s=this.top;if(o&&o.isLeaf)this.findInside(e);else if(n)this.addElement(e,n);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach((e=>this.insertNode(e)));else{let n=e;"string"==typeof t.contentElement?n=e.querySelector(t.contentElement):"function"==typeof t.contentElement?n=t.contentElement(e):t.contentElement&&(n=t.contentElement),this.findAround(e,n,!0),this.addAll(n)}r&&this.sync(s)&&this.open--,i&&this.removePendingMark(i,s)}addAll(e,t,n){let r=t||0;for(let o=t?e.childNodes[t]:e.firstChild,i=null==n?null:e.childNodes[n];o!=i;o=o.nextSibling,++r)this.findAtPoint(e,r),this.addDOM(o);this.findAtPoint(e,r)}findPlace(e){let t,n;for(let r=this.open;r>=0;r--){let o=this.nodes[r],i=o.findWrapping(e);if(i&&(!t||t.length>i.length)&&(t=i,n=o,!i.length))break;if(o.solid)break}if(!t)return!1;this.sync(n);for(let e=0;ethis.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let 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-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),n=this.options.context,r=!(this.isOpen||n&&n.parent.type!=this.nodes[0].type),o=-(n?n.depth+1:0)+(r?0:1),i=(e,s)=>{for(;e>=0;e--){let l=t[e];if(""==l){if(e==t.length-1||0==e)continue;for(;s>=o;s--)if(i(e-1,s))return!0;return!1}{let e=s>0||0==s&&r?this.nodes[s].type:n&&s>=o?n.node(s-o).type:null;if(!e||e.name!=l&&-1==e.groups.indexOf(l))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}}addPendingMark(e){let t=function(e,t){for(let n=0;n=0;n--){let r=this.nodes[n];if(r.pendingMarks.lastIndexOf(e)>-1)r.pendingMarks=e.removeFromSet(r.pendingMarks);else{r.activeMarks=e.removeFromSet(r.activeMarks);let t=r.popFromStashMark(e);t&&r.type&&r.type.allowsMarkType(t.type)&&(r.activeMarks=t.addToSet(r.activeMarks))}if(r==t)break}}}function ee(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function te(e){let t={};for(let n in e)t[n]=e[n];return t}function ne(e,t){let n=t.schema.nodes;for(let r in n){let o=n[r];if(!o.allowsMarkType(e))continue;let i=[],s=e=>{i.push(e);for(let n=0;n{if(o.length||e.marks.length){let n=0,i=0;for(;n=0;r--){let o=this.serializeMark(e.marks[r],e.isInline,t);o&&((o.contentDOM||o.dom).appendChild(n),n=o.dom)}return n}serializeMark(e,t,n={}){let r=this.marks[e.type.name];return r&&re.renderSpec(ie(n),r(e,t))}static renderSpec(e,t,n=null){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,o=t[0],i=o.indexOf(" ");i>0&&(n=o.slice(0,i),o=o.slice(i+1));let s=n?e.createElementNS(n,o):e.createElement(o),l=t[1],a=1;if(l&&"object"==typeof l&&null==l.nodeType&&!Array.isArray(l)){a=2;for(let e in l)if(null!=l[e]){let t=e.indexOf(" ");t>0?s.setAttributeNS(e.slice(0,t),e.slice(t+1),l[e]):s.setAttribute(e,l[e])}}for(let o=a;oa)throw new RangeError("Content hole must be the only child of its parent node");return{dom:s,contentDOM:s}}{let{dom:t,contentDOM:o}=re.renderSpec(e,i,n);if(s.appendChild(t),o){if(r)throw new RangeError("Multiple content holes");r=o}}}return{dom:s,contentDOM:r}}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new re(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=oe(e.nodes);return t.text||(t.text=e=>e.text),t}static marksFromSchema(e){return oe(e.marks)}}function oe(e){let t={};for(let n in e){let r=e[n].spec.toDOM;r&&(t[n]=r)}return t}function ie(e){return e.document||window.document}var se=Object.freeze({__proto__:null,ContentMatch:E,DOMParser:H,DOMSerializer:re,Fragment:r,Mark:l,MarkType:W,Node:N,NodeRange:C,NodeType:_,ReplaceError:a,ResolvedPos:b,Schema:j,Slice:h});const le=Math.pow(2,16);function ae(e){return 65535&e}class he{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 ce{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&ce.empty)return ce.empty}recover(e){let t=0,n=ae(e);if(!this.inverted)for(let e=0;ee)break;let a=this.ranges[s+o],h=this.ranges[s+i],c=l+a;if(e<=c){let o=l+r+((a?e==l?-1:e==c?1:t:t)<0?0:h);if(n)return o;let i=e==(t<0?l:c)?null:s/3+(e-l)*le,d=e==l?2:e==c?1:4;return(t<0?e!=l:e!=c)&&(d|=8),new he(o,d,i)}r+=h-a}return n?e+r:new he(e+r,0,null)}touches(e,t){let n=0,r=ae(t),o=this.inverted?2:1,i=this.inverted?1:2;for(let t=0;te)break;let l=this.ranges[t+o];if(e<=s+l&&t==3*r)return!0;n+=this.ranges[t+i]-l}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,o=0;r=0;t--){let r=e.getMirror(t);this.appendMap(e.maps[t].invert(),null!=r&&r>t?n-r-1:void 0)}}invert(){let e=new de;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;nn&&te.isAtom&&t.type.allowsMarkType(this.mark.type)?e.mark(this.mark.addToSet(e.marks)):e),r),t.openStart,t.openEnd);return fe.fromReplace(e,this.from,this.to,o)}invert(){return new ye(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new ge(t.pos,n.pos,this.mark)}merge(e){return e instanceof ge&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new ge(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("number"!=typeof t.from||"number"!=typeof t.to)throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new ge(t.from,t.to,e.markFromJSON(t.mark))}}ue.jsonID("addMark",ge);class ye extends ue{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new h(me(t.content,(e=>e.mark(this.mark.removeFromSet(e.marks))),e),t.openStart,t.openEnd);return fe.fromReplace(e,this.from,this.to,n)}invert(){return new ge(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new ye(t.pos,n.pos,this.mark)}merge(e){return e instanceof ye&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new ye(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("number"!=typeof t.from||"number"!=typeof t.to)throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new ye(t.from,t.to,e.markFromJSON(t.mark))}}ue.jsonID("removeMark",ye);class we extends ue{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return fe.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return fe.fromReplace(e,this.pos,this.pos+1,new h(r.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let e=this.mark.addToSet(t.marks);if(e.length==t.marks.length){for(let n=0;nn.pos?null:new be(t.pos,n.pos,r,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("number"!=typeof t.from||"number"!=typeof t.to||"number"!=typeof t.gapFrom||"number"!=typeof t.gapTo||"number"!=typeof t.insert)throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new be(t.from,t.to,t.gapFrom,t.gapTo,h.fromJSON(e,t.slice),t.insert,!!t.structure)}}function xe(e,t,n){let r=e.resolve(t),o=n-t,i=r.depth;for(;o>0&&i>0&&r.indexAfter(i)==r.node(i).childCount;)i--,o--;if(o>0){let e=r.node(i).maybeChild(r.indexAfter(i));for(;o>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,o--}}return!1}function Se(e,t,n){return(0==t||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function Me(e){let t=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let n=e.depth;;--n){let r=e.$from.node(n),o=e.$from.index(n),i=e.$to.indexAfter(n);if(ni;e--,t--){let n=o.node(e),i=o.index(e);if(n.type.spec.isolating)return!1;let s=n.content.cutByIndex(i,n.childCount),l=r&&r[t+1];l&&(s=s.replaceChild(0,l.type.create(l.attrs)));let a=r&&r[t]||n;if(!n.canReplace(i+1,n.childCount)||!a.type.validContent(s))return!1}let l=o.indexAfter(i),a=r&&r[0];return o.node(i).canReplaceWith(l,l,a?a.type:o.node(i+1).type)}function De(e,t){let n=e.resolve(t),r=n.index();return Te(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function Te(e,t){return!(!e||!t||e.isLeaf||!e.canAppend(t))}function Ee(e,t,n=-1){let r=e.resolve(t);for(let e=r.depth;;e--){let o,i,s=r.index(e);if(e==r.depth?(o=r.nodeBefore,i=r.nodeAfter):n>0?(o=r.node(e+1),s++,i=r.node(e).maybeChild(s)):(o=r.node(e).maybeChild(s-1),i=r.node(e+1)),o&&!o.isTextblock&&Te(o,i)&&r.node(e).canReplace(s,s+1))return t;if(0==e)break;t=n<0?r.before(e):r.after(e)}}function Ae(e,t,n){let r=e.resolve(t);if(r.parent.canReplaceWith(r.index(),r.index(),n))return t;if(0==r.parentOffset)for(let e=r.depth-1;e>=0;e--){let t=r.index(e);if(r.node(e).canReplaceWith(t,t,n))return r.before(e+1);if(t>0)return null}if(r.parentOffset==r.parent.content.size)for(let e=r.depth-1;e>=0;e--){let t=r.indexAfter(e);if(r.node(e).canReplaceWith(t,t,n))return r.after(e+1);if(t=0;t--){let n=t==r.depth?0:r.pos<=(r.start(t+1)+r.end(t+1))/2?-1:1,i=r.index(t)+(n>0?1:0),s=r.node(t),l=!1;if(1==e)l=s.canReplace(i,i,o);else{let e=s.contentMatchAt(i).findWrapping(o.firstChild.type);l=e&&s.canReplaceWith(i,i,e[0])}if(l)return 0==n?r.pos:n<0?r.before(t+1):r.after(t+1)}return null}function Re(e,t,n=t,r=h.empty){if(t==n&&!r.size)return null;let o=e.resolve(t),i=e.resolve(n);return ze(o,i,r)?new ke(t,n,r):new Pe(o,i,r).fit()}function ze(e,t,n){return!n.openStart&&!n.openEnd&&e.start()==t.start()&&e.parent.canReplace(e.index(),t.index(),n.content)}ue.jsonID("replaceAround",be);class Pe{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=r.empty;for(let t=0;t<=e.depth;t++){let n=e.node(t);this.frontier.push({type:n.type,match:n.contentMatchAt(e.indexAfter(t))})}for(let t=e.depth;t>0;t--)this.placed=r.from(e.node(t).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let e=this.findFittable();e?this.placeNodes(e):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,n=this.$from,r=this.close(e<0?this.$to:n.doc.resolve(e));if(!r)return null;let o=this.placed,i=n.depth,s=r.depth;for(;i&&s&&1==o.childCount;)o=o.firstChild.content,i--,s--;let l=new h(o,i,s);return e>-1?new be(n.pos,e,this.$to.pos,this.$to.end(),l,t):l.size||n.pos!=this.$to.pos?new ke(n.pos,r.pos,l):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,r=this.unplaced.openEnd;n1&&(r=0),o.type.spec.isolating&&r<=n){e=n;break}t=o.content}for(let t=1;t<=2;t++)for(let n=1==t?e:this.unplaced.openStart;n>=0;n--){let e,o=null;n?(o=$e(this.unplaced.content,n-1).firstChild,e=o.content):e=this.unplaced.content;let i=e.firstChild;for(let e=this.depth;e>=0;e--){let s,{type:l,match:a}=this.frontier[e],h=null;if(1==t&&(i?a.matchType(i.type)||(h=a.fillBefore(r.from(i),!1)):o&&l.compatibleContent(o.type)))return{sliceDepth:n,frontierDepth:e,parent:o,inject:h};if(2==t&&i&&(s=a.findWrapping(i.type)))return{sliceDepth:n,frontierDepth:e,parent:o,wrap:s};if(o&&a.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=$e(e,t);return!(!r.childCount||r.firstChild.isLeaf)&&(this.unplaced=new h(e,t+1,Math.max(n,r.size+t>=e.size-n?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=$e(e,t);if(r.childCount<=1&&t>0){let o=e.size-t<=t+r.size;this.unplaced=new h(Be(e,t-1,1),t-1,o?t-1:n)}else this.unplaced=new h(Be(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:o,wrap:i}){for(;this.depth>t;)this.closeFrontierNode();if(i)for(let e=0;e1||0==a||e.content.size)&&(p=t,d.push(Fe(e.mark(u.allowedMarks(e.marks)),1==c?a:0,c==l.childCount?f:-1)))}let m=c==l.childCount;m||(f=-1),this.placed=Ve(this.placed,t,r.from(d)),this.frontier[t].match=p,m&&f<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let e=0,t=l;e1&&r==this.$to.end(--n);)++r;return r}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:r}=this.frontier[t],o=t=0;n--){let{match:t,type:r}=this.frontier[n],o=qe(e,n,r,t,!0);if(!o||o.childCount)continue e}return{depth:t,fit:i,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=Ve(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let t=e.node(n),r=t.type.contentMatch.fillBefore(t.content,!0,e.index(n));this.openFrontierNode(t.type,t.attrs,r)}return e}openFrontierNode(e,t=null,n){let o=this.frontier[this.depth];o.match=o.match.matchType(e),this.placed=Ve(this.placed,this.depth,r.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let e=this.frontier.pop().match.fillBefore(r.empty,!0);e.childCount&&(this.placed=Ve(this.placed,this.frontier.length,e))}}function Be(e,t,n){return 0==t?e.cutByIndex(n,e.childCount):e.replaceChild(0,e.firstChild.copy(Be(e.firstChild.content,t-1,n)))}function Ve(e,t,n){return 0==t?e.append(n):e.replaceChild(e.childCount-1,e.lastChild.copy(Ve(e.lastChild.content,t-1,n)))}function $e(e,t){for(let n=0;n1&&(o=o.replaceChild(0,Fe(o.firstChild,t-1,1==o.childCount?n-1:0))),t>0&&(o=e.type.contentMatch.fillBefore(o).append(o),n<=0&&(o=o.append(e.type.contentMatch.matchFragment(o).fillBefore(r.empty,!0)))),e.copy(o)}function qe(e,t,n,r,o){let i=e.node(t),s=o?e.indexAfter(t):e.index(t);if(s==i.childCount&&!n.compatibleContent(i.type))return null;let l=r.fillBefore(i.content,!0,s);return l&&!function(e,t,n){for(let r=n;ro){let t=i.contentMatchAt(0),n=t.fillBefore(e).append(e);e=n.append(t.matchFragment(n).fillBefore(r.empty,!0))}return e}function _e(e,t){let n=[];for(let r=Math.min(e.depth,t.depth);r>=0;r--){let o=e.start(r);if(ot.pos+(t.depth-r)||e.node(r).type.spec.isolating||t.node(r).type.spec.isolating)break;(o==t.start(r)||r==e.depth&&r==t.depth&&e.parent.inlineContent&&t.parent.inlineContent&&r&&t.start(r-1)==o-1)&&n.push(r)}return n}class Je extends ue{constructor(e,t,n){super(),this.pos=e,this.attr=t,this.value=n}apply(e){let t=e.nodeAt(this.pos);if(!t)return fe.fail("No node at attribute step's position");let n=Object.create(null);for(let e in t.attrs)n[e]=t.attrs[e];n[this.attr]=this.value;let o=t.type.create(n,null,t.marks);return fe.fromReplace(e,this.pos,this.pos+1,new h(r.from(o),0,t.isLeaf?0:1))}getMap(){return ce.empty}invert(e){return new Je(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 Je(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if("number"!=typeof t.pos||"string"!=typeof t.attr)throw new RangeError("Invalid input for AttrStep.fromJSON");return new Je(t.pos,t.attr,t.value)}}ue.jsonID("attr",Je);class We extends ue{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let n in e.attrs)t[n]=e.attrs[n];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return fe.ok(n)}getMap(){return ce.empty}invert(e){return new We(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("string"!=typeof t.attr)throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new We(t.attr,t.value)}}ue.jsonID("docAttr",We);let je=class extends Error{};je=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},(je.prototype=Object.create(Error.prototype)).constructor=je,je.prototype.name="TransformError";class Ke{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new de}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new je(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,n=h.empty){let r=Re(this.doc,e,t,n);return r&&this.step(r),this}replaceWith(e,t,n){return this.replace(e,t,new h(r.from(n),0,0))}delete(e,t){return this.replace(e,t,h.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return function(e,t,n,r){if(!r.size)return e.deleteRange(t,n);let o=e.doc.resolve(t),i=e.doc.resolve(n);if(ze(o,i,r))return e.step(new ke(t,n,r));let s=_e(o,e.doc.resolve(n));0==s[s.length-1]&&s.pop();let l=-(o.depth+1);s.unshift(l);for(let e=o.depth,t=o.pos-1;e>0;e--,t--){let n=o.node(e).type.spec;if(n.defining||n.definingAsContext||n.isolating)break;s.indexOf(e)>-1?l=e:o.before(e)==t&&s.splice(1,0,-e)}let a=s.indexOf(l),c=[],d=r.openStart;for(let e=r.content,t=0;;t++){let n=e.firstChild;if(c.push(n),t==r.openStart)break;e=n.content}for(let e=d-1;e>=0;e--){let t=c[e],n=(p=t.type).spec.defining||p.spec.definingForContent;if(n&&!t.sameMarkup(o.node(Math.abs(l)-1)))d=e;else if(n||!t.type.isTextblock)break}var p;for(let t=r.openStart;t>=0;t--){let l=(t+d+1)%(r.openStart+1),p=c[l];if(p)for(let t=0;t=0&&(e.replace(t,n,r),!(e.steps.length>u));l--){let e=s[l];e<0||(t=o.before(e),n=i.after(e))}}(this,e,t,n),this}replaceRangeWith(e,t,n){return function(e,t,n,o){if(!o.isInline&&t==n&&e.doc.resolve(t).parent.content.size){let r=Ae(e.doc,t,o.type);null!=r&&(t=n=r)}e.replaceRange(t,n,new h(r.from(o),0,0))}(this,e,t,n),this}deleteRange(e,t){return function(e,t,n){let r=e.doc.resolve(t),o=e.doc.resolve(n),i=_e(r,o);for(let t=0;t0&&(s||r.node(n-1).canReplace(r.index(n-1),o.indexAfter(n-1))))return e.delete(r.before(n),o.after(n))}for(let i=1;i<=r.depth&&i<=o.depth;i++)if(t-r.start(i)==r.depth-i&&n>r.end(i)&&o.end(i)-n!=o.depth-i)return e.delete(r.before(i),n);e.delete(t,n)}(this,e,t),this}lift(e,t){return function(e,t,n){let{$from:o,$to:i,depth:s}=t,l=o.before(s+1),a=i.after(s+1),c=l,d=a,p=r.empty,u=0;for(let e=s,t=!1;e>n;e--)t||o.index(e)>0?(t=!0,p=r.from(o.node(e).copy(p)),u++):c--;let f=r.empty,m=0;for(let e=s,t=!1;e>n;e--)t||i.after(e+1)=0;e--){if(o.size){let t=n[e].type.contentMatch.matchFragment(o);if(!t||!t.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}o=r.from(n[e].type.create(n[e].attrs,o))}let i=t.start,s=t.end;e.step(new be(i,s,i,s,new h(o,0,0),n.length,!0))}(this,e,t),this}setBlockType(e,t=e,n,o=null){return function(e,t,n,o,i){if(!o.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=e.steps.length;e.doc.nodesBetween(t,n,((t,n)=>{if(t.isTextblock&&!t.hasMarkup(o,i)&&function(e,t,n){let r=e.resolve(t),o=r.index();return r.parent.canReplaceWith(o,o+1,n)}(e.doc,e.mapping.slice(s).map(n),o)){e.clearIncompatible(e.mapping.slice(s).map(n,1),o);let l=e.mapping.slice(s),a=l.map(n,1),c=l.map(n+t.nodeSize,1);return e.step(new be(a,c,a+1,c-1,new h(r.from(o.create(i,null,t.marks)),0,0),1,!0)),!1}}))}(this,e,t,n,o),this}setNodeMarkup(e,t,n=null,o){return function(e,t,n,o,i){let s=e.doc.nodeAt(t);if(!s)throw new RangeError("No node at given position");n||(n=s.type);let l=n.create(o,null,i||s.marks);if(s.isLeaf)return e.replaceWith(t,t+s.nodeSize,l);if(!n.validContent(s.content))throw new RangeError("Invalid content for node type "+n.name);e.step(new be(t,t+s.nodeSize,t+1,t+s.nodeSize-1,new h(r.from(l),0,0),1,!0))}(this,e,t,n,o),this}setNodeAttribute(e,t,n){return this.step(new Je(e,t,n)),this}setDocAttribute(e,t){return this.step(new We(e,t)),this}addNodeMark(e,t){return this.step(new we(e,t)),this}removeNodeMark(e,t){if(!(t instanceof l)){let n=this.doc.nodeAt(e);if(!n)throw new RangeError("No node at position "+e);if(!(t=t.isInSet(n.marks)))return this}return this.step(new ve(e,t)),this}split(e,t=1,n){return function(e,t,n=1,o){let i=e.doc.resolve(t),s=r.empty,l=r.empty;for(let e=i.depth,t=i.depth-n,a=n-1;e>t;e--,a--){s=r.from(i.node(e).copy(s));let t=o&&o[a];l=r.from(t?t.type.create(t.attrs,l):i.node(e).copy(l))}e.step(new ke(t,t,new h(s.append(l),n,n),!0))}(this,e,t,n),this}addMark(e,t,n){return function(e,t,n,r){let o,i,s=[],l=[];e.doc.nodesBetween(t,n,((e,a,h)=>{if(!e.isInline)return;let c=e.marks;if(!r.isInSet(c)&&h.type.allowsMarkType(r.type)){let h=Math.max(a,t),d=Math.min(a+e.nodeSize,n),p=r.addToSet(c);for(let e=0;ee.step(t))),l.forEach((t=>e.step(t)))}(this,e,t,n),this}removeMark(e,t,n){return function(e,t,n,r){let o=[],i=0;e.doc.nodesBetween(t,n,((e,s)=>{if(!e.isInline)return;i++;let l=null;if(r instanceof W){let t,n=e.marks;for(;t=r.isInSet(n);)(l||(l=[])).push(t),n=t.removeFromSet(n)}else r?r.isInSet(e.marks)&&(l=[r]):l=e.marks;if(l&&l.length){let r=Math.min(s+e.nodeSize,n);for(let e=0;ee.step(new ye(t.from,t.to,t.style))))}(this,e,t,n),this}clearIncompatible(e,t,n){return function(e,t,n,o=n.contentMatch){let i=e.doc.nodeAt(t),s=[],l=t+1;for(let t=0;t=0;t--)e.step(s[t])}(this,e,t,n),this}}var He=Object.freeze({__proto__:null,AddMarkStep:ge,AddNodeMarkStep:we,AttrStep:Je,DocAttrStep:We,MapResult:he,Mapping:de,RemoveMarkStep:ye,RemoveNodeMarkStep:ve,ReplaceAroundStep:be,ReplaceStep:ke,Step:ue,StepMap:ce,StepResult:fe,Transform:Ke,get TransformError(){return je},canJoin:De,canSplit:Ne,dropPoint:Ie,findWrapping:Ce,insertPoint:Ae,joinPoint:Ee,liftTarget:Me,replaceStep:Re});const Ue=Object.create(null);class Ge{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new Qe(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;r--){let o=t<0?it(e.node(0),e.node(r),e.before(r+1),e.index(r),t,n):it(e.node(0),e.node(r),e.after(r+1),e.index(r)+1,t,n);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new rt(e.node(0))}static atStart(e){return it(e,e,0,0,1)||new rt(e)}static atEnd(e){return it(e,e,e.content.size,e.childCount,-1)||new rt(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=Ue[t.type];if(!n)throw new RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in Ue)throw new RangeError("Duplicate use of selection JSON ID "+e);return Ue[e]=t,t.prototype.jsonID=e,t}getBookmark(){return Ze.between(this.$anchor,this.$head).getBookmark()}}Ge.prototype.visible=!0;class Qe{constructor(e,t){this.$from=e,this.$to=t}}let Xe=!1;function Ye(e){Xe||e.parent.inlineContent||(Xe=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+e.parent.type.name+")"))}class Ze extends Ge{constructor(e,t=e){Ye(e),Ye(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let n=e.resolve(t.map(this.head));if(!n.parent.inlineContent)return Ge.near(n);let r=e.resolve(t.map(this.anchor));return new Ze(r.parent.inlineContent?r:n,n)}replace(e,t=h.empty){if(super.replace(e,t),t==h.empty){let t=this.$from.marksAcross(this.$to);t&&e.ensureMarks(t)}}eq(e){return e instanceof Ze&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new et(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if("number"!=typeof t.anchor||"number"!=typeof t.head)throw new RangeError("Invalid input for TextSelection.fromJSON");return new Ze(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,n=t){let r=e.resolve(t);return new this(r,n==t?r:e.resolve(n))}static between(e,t,n){let r=e.pos-t.pos;if(n&&!r||(n=r>=0?1:-1),!t.parent.inlineContent){let e=Ge.findFrom(t,n,!0)||Ge.findFrom(t,-n,!0);if(!e)return Ge.near(t,n);t=e.$head}return e.parent.inlineContent||(0==r||(e=(Ge.findFrom(e,-n,!0)||Ge.findFrom(e,n,!0)).$anchor).posnew rt(e)};function it(e,t,n,r,o,i=!1){if(t.inlineContent)return Ze.create(e,n);for(let s=r-(o>0?0:1);o>0?s=0;s+=o){let r=t.child(s);if(r.isAtom){if(!i&&tt.isSelectable(r))return tt.create(e,n-(o<0?r.nodeSize:0))}else{let t=it(e,r,n+o,o<0?r.childCount:0,o,i);if(t)return t}n+=r.nodeSize*o}return null}function st(e,t,n){let r=e.steps.length-1;if(r{null==o&&(o=r)})),e.setSelection(Ge.near(e.doc.resolve(o),n)))}class lt extends Ke{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|=2,this}ensureMarks(e){return l.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(2&this.updated)>0}addStep(e,t){super.addStep(e,t),this.updated=-3&this.updated,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let n=this.selection;return t&&(e=e.mark(this.storedMarks||(n.empty?n.$from.marks():n.$from.marksAcross(n.$to)||l.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let r=this.doc.type.schema;if(null==t)return e?this.replaceSelectionWith(r.text(e),!0):this.deleteSelection();{if(null==n&&(n=t),n=null==n?t:n,!e)return this.deleteRange(t,n);let o=this.storedMarks;if(!o){let e=this.doc.resolve(t);o=n==t?e.marks():e.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,r.text(e,o)),this.selection.empty||this.setSelection(Ge.near(this.selection.$to)),this}}setMeta(e,t){return this.meta["string"==typeof e?e:e.key]=t,this}getMeta(e){return this.meta["string"==typeof e?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=4,this}get scrolledIntoView(){return(4&this.updated)>0}}function at(e,t){return t&&e?e.bind(t):e}class ht{constructor(e,t,n){this.name=e,this.init=at(t.init,n),this.apply=at(t.apply,n)}}const ct=[new ht("doc",{init:e=>e.doc||e.schema.topNodeType.createAndFill(),apply:e=>e.doc}),new ht("selection",{init:(e,t)=>e.selection||Ge.atStart(t.doc),apply:e=>e.selection}),new ht("storedMarks",{init:e=>e.storedMarks||null,apply:(e,t,n,r)=>r.selection.$cursor?e.storedMarks:null}),new ht("scrollToSelection",{init:()=>0,apply:(e,t)=>e.scrolledIntoView?t+1:t})];class dt{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=ct.slice(),t&&t.forEach((e=>{if(this.pluginsByKey[e.key])throw new RangeError("Adding different instances of a keyed plugin ("+e.key+")");this.plugins.push(e),this.pluginsByKey[e.key]=e,e.spec.state&&this.fields.push(new ht(e.key,e.spec.state,e))}))}}class pt{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let n=0;ne.toJSON()))),e&&"object"==typeof e)for(let n in e){if("doc"==n||"selection"==n)throw new RangeError("The JSON fields `doc` and `selection` are reserved");let r=e[n],o=r.spec.state;o&&o.toJSON&&(t[n]=o.toJSON.call(r,this[r.key]))}return t}static fromJSON(e,t,n){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let r=new dt(e.schema,e.plugins),o=new pt(r);return r.fields.forEach((r=>{if("doc"==r.name)o.doc=N.fromJSON(e.schema,t.doc);else if("selection"==r.name)o.selection=Ge.fromJSON(o.doc,t.selection);else if("storedMarks"==r.name)t.storedMarks&&(o.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(n)for(let i in n){let s=n[i],l=s.spec.state;if(s.key==r.name&&l&&l.fromJSON&&Object.prototype.hasOwnProperty.call(t,i))return void(o[r.name]=l.fromJSON.call(s,e,t[i],o))}o[r.name]=r.init(e,o)}})),o}}function ut(e,t,n){for(let r in e){let o=e[r];o instanceof Function?o=o.bind(t):"handleDOMEvents"==r&&(o=ut(o,t,{})),n[r]=o}return n}class ft{constructor(e){this.spec=e,this.props={},e.props&&ut(e.props,this,this.props),this.key=e.key?e.key.key:gt("plugin")}getState(e){return e[this.key]}}const mt=Object.create(null);function gt(e){return e in mt?e+"$"+ ++mt[e]:(mt[e]=0,e+"$")}class yt{constructor(e="key"){this.key=gt(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}var wt=Object.freeze({__proto__:null,AllSelection:rt,EditorState:pt,NodeSelection:tt,Plugin:ft,PluginKey:yt,Selection:Ge,SelectionRange:Qe,TextSelection:Ze,Transaction:lt});const vt=function(e){for(var t=0;;t++)if(!(e=e.previousSibling))return t},kt=function(e){let t=e.assignedSlot||e.parentNode;return t&&11==t.nodeType?t.host:t};let bt=null;const xt=function(e,t,n){let r=bt||(bt=document.createRange());return r.setEnd(e,null==n?e.nodeValue.length:n),r.setStart(e,t||0),r},St=function(e,t,n,r){return n&&(Ct(e,t,n,r,-1)||Ct(e,t,n,r,1))},Mt=/^(img|br|input|textarea|hr)$/i;function Ct(e,t,n,r,o){for(;;){if(e==n&&t==r)return!0;if(t==(o<0?0:Ot(e))){let n=e.parentNode;if(!n||1!=n.nodeType||Nt(e)||Mt.test(e.nodeName)||"false"==e.contentEditable)return!1;t=vt(e)+(o<0?0:1),e=n}else{if(1!=e.nodeType)return!1;if("false"==(e=e.childNodes[t+(o<0?-1:0)]).contentEditable)return!1;t=o<0?Ot(e):0}}}function Ot(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function Nt(e){let t;for(let n=e;n&&!(t=n.pmViewDesc);n=n.parentNode);return t&&t.node&&t.node.isBlock&&(t.dom==e||t.contentDOM==e)}const Dt=function(e){return e.focusNode&&St(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)};function Tt(e,t){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=e,n.key=n.code=t,n}const Et="undefined"!=typeof navigator?navigator:null,At="undefined"!=typeof document?document:null,It=Et&&Et.userAgent||"",Rt=/Edge\/(\d+)/.exec(It),zt=/MSIE \d/.exec(It),Pt=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(It),Bt=!!(zt||Pt||Rt),Vt=zt?document.documentMode:Pt?+Pt[1]:Rt?+Rt[1]:0,$t=!Bt&&/gecko\/(\d+)/i.test(It);$t&&(/Firefox\/(\d+)/.exec(It)||[0,0])[1];const Ft=!Bt&&/Chrome\/(\d+)/.exec(It),qt=!!Ft,Lt=Ft?+Ft[1]:0,_t=!Bt&&!!Et&&/Apple Computer/.test(Et.vendor),Jt=_t&&(/Mobile\/\w+/.test(It)||!!Et&&Et.maxTouchPoints>2),Wt=Jt||!!Et&&/Mac/.test(Et.platform),jt=!!Et&&/Win/.test(Et.platform),Kt=/Android \d/.test(It),Ht=!!At&&"webkitFontSmoothing"in At.documentElement.style,Ut=Ht?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Gt(e){return{left:0,right:e.documentElement.clientWidth,top:0,bottom:e.documentElement.clientHeight}}function Qt(e,t){return"number"==typeof e?e:e[t]}function Xt(e){let t=e.getBoundingClientRect(),n=t.width/e.offsetWidth||1,r=t.height/e.offsetHeight||1;return{left:t.left,right:t.left+e.clientWidth*n,top:t.top,bottom:t.top+e.clientHeight*r}}function Yt(e,t,n){let r=e.someProp("scrollThreshold")||0,o=e.someProp("scrollMargin")||5,i=e.dom.ownerDocument;for(let s=n||e.dom;s;s=kt(s)){if(1!=s.nodeType)continue;let e=s,n=e==i.body,l=n?Gt(i):Xt(e),a=0,h=0;if(t.topl.bottom-Qt(r,"bottom")&&(h=t.bottom-t.top>l.bottom-l.top?t.top+Qt(o,"top")-l.top:t.bottom-l.bottom+Qt(o,"bottom")),t.leftl.right-Qt(r,"right")&&(a=t.right-l.right+Qt(o,"right")),a||h)if(n)i.defaultView.scrollBy(a,h);else{let n=e.scrollLeft,r=e.scrollTop;h&&(e.scrollTop+=h),a&&(e.scrollLeft+=a);let o=e.scrollLeft-n,i=e.scrollTop-r;t={left:t.left-o,top:t.top-i,right:t.right-o,bottom:t.bottom-i}}if(n||/^(fixed|sticky)$/.test(getComputedStyle(s).position))break}}function Zt(e){let t=[],n=e.ownerDocument;for(let r=e;r&&(t.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),e!=n);r=kt(r));return t}function en(e,t){for(let n=0;n=h){a=Math.max(u.bottom,a),h=Math.min(u.top,h);let e=u.left>t.left?u.left-t.left:u.right=(u.left+u.right)/2?1:0));continue}}else u.top>t.top&&!o&&u.left<=t.left&&u.right>=t.left&&(o=c,i={left:Math.max(u.left,Math.min(u.right,t.left)),top:u.top});!n&&(t.left>=u.right&&t.top>=u.top||t.left>=u.left&&t.top>=u.bottom)&&(l=d+1)}}return!n&&o&&(n=o,r=i,s=0),n&&3==n.nodeType?function(e,t){let n=e.nodeValue.length,r=document.createRange();for(let o=0;o=(n.left+n.right)/2?1:0)}}return{node:e,offset:0}}(n,r):!n||s&&1==n.nodeType?{node:e,offset:l}:nn(n,r)}function rn(e,t){return e.left>=t.left-1&&e.left<=t.right+1&&e.top>=t.top-1&&e.top<=t.bottom+1}function on(e,t,n){let r=e.childNodes.length;if(r&&n.topt.top&&o++}let r;Ht&&o&&1==n.nodeType&&1==(r=n.childNodes[o-1]).nodeType&&"false"==r.contentEditable&&r.getBoundingClientRect().top>=t.top&&o--,n==e.dom&&o==n.childNodes.length-1&&1==n.lastChild.nodeType&&t.top>n.lastChild.getBoundingClientRect().bottom?s=e.state.doc.content.size:0!=o&&1==n.nodeType&&"BR"==n.childNodes[o-1].nodeName||(s=function(e,t,n,r){let o=-1;for(let n=t,i=!1;n!=e.dom;){let t=e.docView.nearestDesc(n,!0);if(!t)return null;if(1==t.dom.nodeType&&(t.node.isBlock&&t.parent&&!i||!t.contentDOM)){let e=t.dom.getBoundingClientRect();if(t.node.isBlock&&t.parent&&!i&&(i=!0,e.left>r.left||e.top>r.top?o=t.posBefore:(e.right-1?o:e.docView.posFromDOM(t,n,-1)}(e,n,o,t))}null==s&&(s=function(e,t,n){let{node:r,offset:o}=nn(t,n),i=-1;if(1==r.nodeType&&!r.firstChild){let e=r.getBoundingClientRect();i=e.left!=e.right&&n.left>(e.left+e.right)/2?1:-1}return e.docView.posFromDOM(r,o,i)}(e,l,t));let a=e.docView.nearestDesc(l,!0);return{pos:s,inside:a?a.posAtStart-a.border:-1}}function ln(e){return e.top=0&&o==r.nodeValue.length?(e--,i=1):n<0?e--:t++,dn(an(xt(r,e,t),i),i<0)}{let e=an(xt(r,o,o),n);if($t&&o&&/\s/.test(r.nodeValue[o-1])&&o=0)}if(null==i&&o&&(n<0||o==Ot(r))){let e=r.childNodes[o-1],t=3==e.nodeType?xt(e,Ot(e)-(s?0:1)):1!=e.nodeType||"BR"==e.nodeName&&e.nextSibling?null:e;if(t)return dn(an(t,1),!1)}if(null==i&&o=0)}function dn(e,t){if(0==e.width)return e;let n=t?e.left:e.right;return{top:e.top,bottom:e.bottom,left:n,right:n}}function pn(e,t){if(0==e.height)return e;let n=t?e.top:e.bottom;return{top:n,bottom:n,left:e.left,right:e.right}}function un(e,t,n){let r=e.state,o=e.root.activeElement;r!=t&&e.updateState(t),o!=e.dom&&e.focus();try{return n()}finally{r!=t&&e.updateState(r),o!=e.dom&&o&&o.focus()}}const fn=/[\u0590-\u08ac]/;let mn=null,gn=null,yn=!1;function wn(e,t,n){return mn==t&&gn==n?yn:(mn=t,gn=n,yn="up"==n||"down"==n?function(e,t,n){let r=t.selection,o="up"==n?r.$from:r.$to;return un(e,t,(()=>{let{node:t}=e.docView.domFromPos(o.pos,"up"==n?-1:1);for(;;){let n=e.docView.nearestDesc(t,!0);if(!n)break;if(n.node.isBlock){t=n.contentDOM||n.dom;break}t=n.dom.parentNode}let r=cn(e,o.pos,1);for(let e=t.firstChild;e;e=e.nextSibling){let t;if(1==e.nodeType)t=e.getClientRects();else{if(3!=e.nodeType)continue;t=xt(e,0,e.nodeValue.length).getClientRects()}for(let e=0;eo.top+1&&("up"==n?r.top-o.top>2*(o.bottom-r.top):o.bottom-r.bottom>2*(r.bottom-o.top)))return!1}}return!0}))}(e,t,n):function(e,t,n){let{$head:r}=t.selection;if(!r.parent.isTextblock)return!1;let o=r.parentOffset,i=!o,s=o==r.parent.content.size,l=e.domSelection();return fn.test(r.parent.textContent)&&l.modify?un(e,t,(()=>{let{focusNode:t,focusOffset:o,anchorNode:i,anchorOffset:s}=e.domSelectionRange(),a=l.caretBidiLevel;l.modify("move",n,"character");let h=r.depth?e.docView.domAfterPos(r.before()):e.dom,{focusNode:c,focusOffset:d}=e.domSelectionRange(),p=c&&!h.contains(1==c.nodeType?c:c.parentNode)||t==c&&o==d;try{l.collapse(i,s),t&&(t!=i||o!=s)&&l.extend&&l.extend(t,o)}catch(e){}return null!=a&&(l.caretBidiLevel=a),p})):"left"==n||"backward"==n?i:s}(e,t,n))}class vn{constructor(e,t,n,r){this.parent=e,this.children=t,this.dom=n,this.contentDOM=r,this.dirty=0,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tvt(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))r=2&e.compareDocumentPosition(this.contentDOM);else if(this.dom.firstChild){if(0==t)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!1;break}if(t.previousSibling)break}if(null==r&&t==e.childNodes.length)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!0;break}if(t.nextSibling)break}}return(null==r?n>0:r)?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,r=e;r;r=r.parentNode){let o,i=this.getDesc(r);if(i&&(!t||i.node)){if(!n||!(o=i.nodeDOM)||(1==o.nodeType?o.contains(1==e.nodeType?e:e.parentNode):o==e))return i;n=!1}}}getDesc(e){let t=e.pmViewDesc;for(let e=t;e;e=e.parent)if(e==this)return t}posFromDOM(e,t,n){for(let r=e;r;r=r.parentNode){let o=this.getDesc(r);if(o)return o.localPosFromDOM(e,t,n)}return-1}descAt(e){for(let t=0,n=0;te||o instanceof On){r=e-t;break}t=i}if(r)return this.children[n].domFromPos(r-this.children[n].border,t);for(let e;n&&!(e=this.children[n-1]).size&&e instanceof kn&&e.side>=0;n--);if(t<=0){let e,r=!0;for(;e=n?this.children[n-1]:null,e&&e.dom.parentNode!=this.contentDOM;n--,r=!1);return e&&t&&r&&!e.border&&!e.domAtom?e.domFromPos(e.size,t):{node:this.contentDOM,offset:e?vt(e.dom)+1:0}}{let e,r=!0;for(;e=n=o&&t<=l-n.border&&n.node&&n.contentDOM&&this.contentDOM.contains(n.contentDOM))return n.parseRange(e,t,o);e=i;for(let t=s;t>0;t--){let n=this.children[t-1];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(1)){r=vt(n.dom)+1;break}e-=n.size}-1==r&&(r=0)}if(r>-1&&(l>t||s==this.children.length-1)){t=l;for(let e=s+1;el&&it){let e=s;s=l,l=e}let n=document.createRange();n.setEnd(l.node,l.offset),n.setStart(s.node,s.offset),a.removeAllRanges(),a.addRange(n)}}ignoreMutation(e){return!this.contentDOM&&"selection"!=e.type}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let n=0,r=0;r=n:en){let r=n+o.border,s=i-o.border;if(e>=r&&t<=s)return this.dirty=e==n||t==i?2:1,void(e!=r||t!=s||!o.contentLost&&o.dom.parentNode==this.contentDOM?o.markDirty(e-r,t-r):o.dirty=3);o.dirty=o.dom!=o.contentDOM||o.dom.parentNode!=this.contentDOM||o.children.length?3:2}n=i}this.dirty=2}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=1==e?2:1;t.dirtyo?o.parent?o.parent.posBeforeChild(o):void 0:r))),!t.type.spec.raw){if(1!=i.nodeType){let e=document.createElement("span");e.appendChild(i),i=e}i.contentEditable="false",i.classList.add("ProseMirror-widget")}super(e,[],i,null),this.widget=t,this.widget=t,o=this}matchesWidget(e){return 0==this.dirty&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return!!t&&t(e)}ignoreMutation(e){return"selection"!=e.type||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}}class bn extends vn{constructor(e,t,n,r){super(e,[],t,null),this.textDOM=n,this.text=r}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"characterData"===e.type&&e.target.nodeValue==e.oldValue}}class xn extends vn{constructor(e,t,n,r){super(e,[],n,r),this.mark=t}static create(e,t,n,r){let o=r.nodeViews[t.type.name],i=o&&o(t,r,n);return i&&i.dom||(i=re.renderSpec(document,t.type.spec.toDOM(t,n))),new xn(e,t,i.dom,i.contentDOM||i.dom)}parseRule(){return 3&this.dirty||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return 3!=this.dirty&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),0!=this.dirty){let e=this.parent;for(;!e.node;)e=e.parent;e.dirty0&&(o=Fn(o,0,e,n));for(let e=0;es?s.parent?s.parent.posBeforeChild(s):void 0:i),n,r),h=a&&a.dom,c=a&&a.contentDOM;if(t.isText)if(h){if(3!=h.nodeType)throw new RangeError("Text must be rendered as a DOM text node")}else h=document.createTextNode(t.text);else h||({dom:h,contentDOM:c}=re.renderSpec(document,t.type.spec.toDOM(t)));c||t.isText||"BR"==h.nodeName||(h.hasAttribute("contenteditable")||(h.contentEditable="false"),t.type.spec.draggable&&(h.draggable=!0));let d=h;return h=zn(h,n,t),a?s=new Nn(e,t,n,r,h,c||null,d,a,o,i+1):t.isText?new Cn(e,t,n,r,h,d,o):new Sn(e,t,n,r,h,c||null,d,o,i+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if("pre"==this.node.type.whitespace&&(e.preserveWhitespace="full"),this.contentDOM)if(this.contentLost){for(let t=this.children.length-1;t>=0;t--){let n=this.children[t];if(this.dom.contains(n.dom.parentNode)){e.contentElement=n.dom.parentNode;break}}e.contentElement||(e.getContent=()=>r.empty)}else e.contentElement=this.contentDOM;else e.getContent=()=>this.node.content;return e}matchesNode(e,t,n){return 0==this.dirty&&e.eq(this.node)&&Pn(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let n=this.node.inlineContent,r=t,o=e.composing?this.localCompositionInfo(e,t):null,i=o&&o.pos>-1?o:null,s=o&&o.pos<0,a=new Vn(this,i&&i.node,e);!function(e,t,n,r){let o=t.locals(e),i=0;if(0==o.length){for(let n=0;ni;)l.push(o[s++]);let f=i+p.nodeSize;if(p.isText){let e=f;s!e.inline)):l.slice(),t.forChild(i,p),u),i=f}}(this.node,this.innerDeco,((t,o,i)=>{t.spec.marks?a.syncToMarks(t.spec.marks,n,e):t.type.side>=0&&!i&&a.syncToMarks(o==this.node.childCount?l.none:this.node.child(o).marks,n,e),a.placeWidget(t,e,r)}),((t,i,l,h)=>{let c;a.syncToMarks(t.marks,n,e),a.findNodeMatch(t,i,l,h)||s&&e.state.selection.from>r&&e.state.selection.to-1&&a.updateNodeAt(t,i,l,c,e)||a.updateNextNode(t,i,l,e,h,r)||a.addNode(t,i,l,e,r),r+=t.nodeSize})),a.syncToMarks([],n,e),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||2==this.dirty)&&(i&&this.protectLocalComposition(e,i),Dn(this.contentDOM,this.children,e),Jt&&function(e){if("UL"==e.nodeName||"OL"==e.nodeName){let t=e.style.cssText;e.style.cssText=t+"; list-style: square !important",window.getComputedStyle(e).listStyle,e.style.cssText=t}}(this.dom))}localCompositionInfo(e,t){let{from:n,to:r}=e.state.selection;if(!(e.state.selection instanceof Ze)||nt+this.node.content.size)return null;let o=e.domSelectionRange(),i=function(e,t){for(;;){if(3==e.nodeType)return e;if(1==e.nodeType&&t>0){if(e.childNodes.length>t&&3==e.childNodes[t].nodeType)return e.childNodes[t];t=Ot(e=e.childNodes[t-1])}else{if(!(1==e.nodeType&&t=n){if(i>=r&&a.slice(r-t.length-l,r-l)==t)return r-t.length;let e=l=0&&e+t.length+l>=n)return l+e;if(n==r&&a.length>=r+t.length-l&&a.slice(r-l,r-l+t.length)==t)return r}}return-1}(this.node.content,e,n-t,r-t);return o<0?null:{node:i,pos:o,text:e}}return{node:i,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:n,text:r}){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 i=new bn(this,o,t,r);e.input.compositionNodes.push(i),this.children=Fn(this.children,n,n+r.length,e,i)}update(e,t,n,r){return!(3==this.dirty||!e.sameMarkup(this.node))&&(this.updateInner(e,t,n,r),!0)}updateInner(e,t,n,r){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(r,this.posAtStart),this.dirty=0}updateOuterDeco(e){if(Pn(e,this.outerDeco))return;let t=1!=this.nodeDOM.nodeType,n=this.dom;this.dom=In(this.dom,this.nodeDOM,An(this.outerDeco,this.node,t),An(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){1==this.nodeDOM.nodeType&&this.nodeDOM.classList.add("ProseMirror-selectednode"),!this.contentDOM&&this.node.type.spec.draggable||(this.dom.draggable=!0)}deselectNode(){1==this.nodeDOM.nodeType&&this.nodeDOM.classList.remove("ProseMirror-selectednode"),!this.contentDOM&&this.node.type.spec.draggable||this.dom.removeAttribute("draggable")}get domAtom(){return this.node.isAtom}}function Mn(e,t,n,r,o){zn(r,t,e);let i=new Sn(void 0,e,t,n,r,r,r,o,0);return i.contentDOM&&i.updateChildren(o,0),i}class Cn extends Sn{constructor(e,t,n,r,o,i,s){super(e,t,n,r,o,null,i,s,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,r){return!(3==this.dirty||0!=this.dirty&&!this.inParent()||!e.sameMarkup(this.node))&&(this.updateOuterDeco(t),0==this.dirty&&e.text==this.node.text||e.text==this.nodeDOM.nodeValue||(this.nodeDOM.nodeValue=e.text,r.trackWrites==this.nodeDOM&&(r.trackWrites=null)),this.node=e,this.dirty=0,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,n){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,n)}ignoreMutation(e){return"characterData"!=e.type&&"selection"!=e.type}slice(e,t,n){let r=this.node.cut(e,t),o=document.createTextNode(r.text);return new Cn(this.parent,r,this.outerDeco,this.innerDeco,o,o,n)}markDirty(e,t){super.markDirty(e,t),this.dom==this.nodeDOM||0!=e&&t!=this.nodeDOM.nodeValue.length||(this.dirty=3)}get domAtom(){return!1}}class On extends vn{parseRule(){return{ignore:!0}}matchesHack(e){return 0==this.dirty&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return"IMG"==this.dom.nodeName}}class Nn extends Sn{constructor(e,t,n,r,o,i,s,l,a,h){super(e,t,n,r,o,i,s,a,h),this.spec=l}update(e,t,n,r){if(3==this.dirty)return!1;if(this.spec.update){let o=this.spec.update(e,t,n);return o&&this.updateInner(e,t,n,r),o}return!(!this.contentDOM&&!e.isLeaf)&&super.update(e,t,n,r)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,r){this.spec.setSelection?this.spec.setSelection(e,t,n):super.setSelection(e,t,n,r)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return!!this.spec.stopEvent&&this.spec.stopEvent(e)}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}function Dn(e,t,n){let r=e.firstChild,o=!1;for(let i=0;i0;){let l;for(;;)if(r){let e=n.children[r-1];if(!(e instanceof xn)){l=e,r--;break}n=e,r=e.children.length}else{if(n==t)break e;r=n.parent.children.indexOf(n),n=n.parent}let a=l.node;if(a){if(a!=e.child(o-1))break;--o,i.set(l,o),s.push(l)}}return{index:o,matched:i,matches:s.reverse()}}(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let n=e;n>1,i=Math.min(o,e.length);for(;r-1)r>this.index&&(this.changed=!0,this.destroyBetween(this.index,r)),this.top=this.top.children[this.index];else{let r=xn.create(this.top,e[o],t,n);this.top.children.splice(this.index,0,r),this.top=r,this.changed=!0}this.index=0,o++}}findNodeMatch(e,t,n,r){let o,i=-1;if(r>=this.preMatch.index&&(o=this.preMatch.matches[r-this.preMatch.index]).parent==this.top&&o.matchesNode(e,t,n))i=this.top.children.indexOf(o,this.index);else for(let r=this.index,o=Math.min(this.top.children.length,r+5);r=n||c<=t?i.push(a):(hn&&i.push(a.slice(n-h,a.size,r)))}return i}function qn(e,t=null){let n=e.domSelectionRange(),r=e.state.doc;if(!n.focusNode)return null;let o=e.docView.nearestDesc(n.focusNode),i=o&&0==o.size,s=e.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(s<0)return null;let l,a,h=r.resolve(s);if(Dt(n)){for(l=h;o&&!o.node;)o=o.parent;let e=o.node;if(o&&e.isAtom&&tt.isSelectable(e)&&o.parent&&(!e.isInline||!function(e,t,n){for(let r=0==t,o=t==Ot(e);r||o;){if(e==n)return!0;let t=vt(e);if(!(e=e.parentNode))return!1;r=r&&0==t,o=o&&t==Ot(e)}}(n.focusNode,n.focusOffset,o.dom))){let e=o.posBefore;a=new tt(s==e?h:r.resolve(e))}}else{let t=e.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(t<0)return null;l=r.resolve(t)}if(!a){a=Gn(e,l,h,"pointer"==t||e.state.selection.head{n.anchorNode==r&&n.anchorOffset==o||(t.removeEventListener("selectionchange",e.input.hideSelectionGuard),setTimeout((()=>{Ln(e)&&!e.state.selection.visible||e.dom.classList.remove("ProseMirror-hideselection")}),20))})}(e))}e.domObserver.setCurSelection(),e.domObserver.connectSelection()}}const Jn=_t||qt&&Lt<63;function Wn(e,t){let{node:n,offset:r}=e.docView.domFromPos(t,0),o=rr(e,t,n)))||Ze.between(t,n,r)}function Qn(e){return!(e.editable&&!e.hasFocus())&&Xn(e)}function Xn(e){let t=e.domSelectionRange();if(!t.anchorNode)return!1;try{return e.dom.contains(3==t.anchorNode.nodeType?t.anchorNode.parentNode:t.anchorNode)&&(e.editable||e.dom.contains(3==t.focusNode.nodeType?t.focusNode.parentNode:t.focusNode))}catch(e){return!1}}function Yn(e,t){let{$anchor:n,$head:r}=e.selection,o=t>0?n.max(r):n.min(r),i=o.parent.inlineContent?o.depth?e.doc.resolve(t>0?o.after():o.before()):null:o;return i&&Ge.findFrom(i,t)}function Zn(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function er(e,t,n){let r=e.state.selection;if(!(r instanceof Ze)){if(r instanceof tt&&r.node.isInline)return Zn(e,new Ze(t>0?r.$to:r.$from));{let n=Yn(e.state,t);return!!n&&Zn(e,n)}}if(n.indexOf("s")>-1){let{$head:n}=r,o=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter;if(!o||o.isText||!o.isLeaf)return!1;let i=e.state.doc.resolve(n.pos+o.nodeSize*(t<0?-1:1));return Zn(e,new Ze(r.$anchor,i))}if(!r.empty)return!1;if(e.endOfTextblock(t>0?"forward":"backward")){let n=Yn(e.state,t);return!!(n&&n instanceof tt)&&Zn(e,n)}if(!(Wt&&n.indexOf("m")>-1)){let n,o=r.$head,i=o.textOffset?null:t<0?o.nodeBefore:o.nodeAfter;if(!i||i.isText)return!1;let s=t<0?o.pos-i.nodeSize:o.pos;return!!(i.isAtom||(n=e.docView.descAt(s))&&!n.contentDOM)&&(tt.isSelectable(i)?Zn(e,new tt(t<0?e.state.doc.resolve(o.pos-i.nodeSize):o)):!!Ht&&Zn(e,new Ze(e.state.doc.resolve(t<0?s:s+i.nodeSize))))}}function tr(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function nr(e,t){let n=e.pmViewDesc;return n&&0==n.size&&(t<0||e.nextSibling||"BR"!=e.nodeName)}function rr(e,t){return t<0?function(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let o,i,s=!1;$t&&1==n.nodeType&&r0){if(1!=n.nodeType)break;{let e=n.childNodes[r-1];if(nr(e,-1))o=n,i=--r;else{if(3!=e.nodeType)break;n=e,r=n.nodeValue.length}}}else{if(or(n))break;{let t=n.previousSibling;for(;t&&nr(t,-1);)o=n.parentNode,i=vt(t),t=t.previousSibling;if(t)n=t,r=tr(n);else{if(n=n.parentNode,n==e.dom)break;r=0}}}s?ir(e,n,r):o&&ir(e,o,i)}(e):function(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let o,i,s=tr(n);for(;;)if(r{e.state==o&&_n(e)}),50)}function sr(e,t){let n=e.state.doc.resolve(t);if(!qt&&!jt&&n.parent.inlineContent){let r=e.coordsAtPos(t);if(t>n.start()){let n=e.coordsAtPos(t-1),o=(n.top+n.bottom)/2;if(o>r.top&&o1)return n.leftr.top&&o1)return n.left>r.left?"ltr":"rtl"}}return"rtl"==getComputedStyle(e.dom).direction?"rtl":"ltr"}function lr(e,t,n){let r=e.state.selection;if(r instanceof Ze&&!r.empty||n.indexOf("s")>-1)return!1;if(Wt&&n.indexOf("m")>-1)return!1;let{$from:o,$to:i}=r;if(!o.parent.inlineContent||e.endOfTextblock(t<0?"up":"down")){let n=Yn(e.state,t);if(n&&n instanceof tt)return Zn(e,n)}if(!o.parent.inlineContent){let n=t<0?o:i,s=r instanceof rt?Ge.near(n,t):Ge.findFrom(n,t);return!!s&&Zn(e,s)}return!1}function ar(e,t){if(!(e.state.selection instanceof Ze))return!0;let{$head:n,$anchor:r,empty:o}=e.state.selection;if(!n.sameParent(r))return!0;if(!o)return!1;if(e.endOfTextblock(t>0?"forward":"backward"))return!0;let i=!n.textOffset&&(t<0?n.nodeBefore:n.nodeAfter);if(i&&!i.isText){let r=e.state.tr;return t<0?r.delete(n.pos-i.nodeSize,n.pos):r.delete(n.pos,n.pos+i.nodeSize),e.dispatch(r),!0}return!1}function hr(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function cr(e,t){let n=t.keyCode,r=function(e){let t="";return e.ctrlKey&&(t+="c"),e.metaKey&&(t+="m"),e.altKey&&(t+="a"),e.shiftKey&&(t+="s"),t}(t);if(8==n||Wt&&72==n&&"c"==r)return ar(e,-1)||rr(e,-1);if(46==n&&!t.shiftKey||Wt&&68==n&&"c"==r)return ar(e,1)||rr(e,1);if(13==n||27==n)return!0;if(37==n||Wt&&66==n&&"c"==r){let t=37==n?"ltr"==sr(e,e.state.selection.from)?-1:1:-1;return er(e,t,r)||rr(e,t)}if(39==n||Wt&&70==n&&"c"==r){let t=39==n?"ltr"==sr(e,e.state.selection.from)?1:-1:1;return er(e,t,r)||rr(e,t)}return 38==n||Wt&&80==n&&"c"==r?lr(e,-1,r)||rr(e,-1):40==n||Wt&&78==n&&"c"==r?function(e){if(!_t||e.state.selection.$head.parentOffset>0)return!1;let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(t&&1==t.nodeType&&0==n&&t.firstChild&&"false"==t.firstChild.contentEditable){let n=t.firstChild;hr(e,n,"true"),setTimeout((()=>hr(e,n,"false")),20)}return!1}(e)||lr(e,1,r)||rr(e,1):r==(Wt?"m":"c")&&(66==n||73==n||89==n||90==n)}function dr(e,t){e.someProp("transformCopied",(n=>{t=n(t,e)}));let n=[],{content:r,openStart:o,openEnd:i}=t;for(;o>1&&i>1&&1==r.childCount&&1==r.firstChild.childCount;){o--,i--;let e=r.firstChild;n.push(e.type.name,e.attrs!=e.type.defaultAttrs?e.attrs:null),r=e.content}let s=e.someProp("clipboardSerializer")||re.fromSchema(e.state.schema),l=br(),a=l.createElement("div");a.appendChild(s.serializeFragment(r,{document:l}));let h,c=a.firstChild,d=0;for(;c&&1==c.nodeType&&(h=vr[c.nodeName.toLowerCase()]);){for(let e=h.length-1;e>=0;e--){let t=l.createElement(h[e]);for(;a.firstChild;)t.appendChild(a.firstChild);a.appendChild(t),d++}c=a.firstChild}return c&&1==c.nodeType&&c.setAttribute("data-pm-slice",`${o} ${i}${d?` -${d}`:""} ${JSON.stringify(n)}`),{dom:a,text:e.someProp("clipboardTextSerializer",(n=>n(t,e)))||t.content.textBetween(0,t.content.size,"\n\n")}}function pr(e,t,n,o,i){let s,l,a=i.parent.type.spec.code;if(!n&&!t)return null;let c=t&&(o||a||!n);if(c){if(e.someProp("transformPastedText",(n=>{t=n(t,a||o,e)})),a)return t?new h(r.from(e.state.schema.text(t.replace(/\r\n?/g,"\n"))),0,0):h.empty;let n=e.someProp("clipboardTextParser",(n=>n(t,i,o,e)));if(n)l=n;else{let n=i.marks(),{schema:r}=e.state,o=re.fromSchema(r);s=document.createElement("div"),t.split(/(?:\r\n?|\n)+/).forEach((e=>{let t=s.appendChild(document.createElement("p"));e&&t.appendChild(o.serializeNode(r.text(e,n)))}))}}else e.someProp("transformPastedHTML",(t=>{n=t(n,e)})),s=function(e){let t=/^(\s*]*>)*/.exec(e);t&&(e=e.slice(t[0].length));let n,r=br().createElement("div"),o=/<([a-z][^>\s]+)/i.exec(e);(n=o&&vr[o[1].toLowerCase()])&&(e=n.map((e=>"<"+e+">")).join("")+e+n.map((e=>"")).reverse().join(""));if(r.innerHTML=e,n)for(let e=0;e0;e--){let e=s.firstChild;for(;e&&1!=e.nodeType;)e=e.nextSibling;if(!e)break;s=e}if(!l){let t=e.someProp("clipboardParser")||e.someProp("domParser")||H.fromSchema(e.state.schema);l=t.parseSlice(s,{preserveWhitespace:!(!c&&!p),context:i,ruleFromNode:e=>"BR"!=e.nodeName||e.nextSibling||!e.parentNode||ur.test(e.parentNode.nodeName)?null:{ignore:!0}})}if(p)l=function(e,t){if(!e.size)return e;let n,o=e.content.firstChild.type.schema;try{n=JSON.parse(t)}catch(t){return e}let{content:i,openStart:s,openEnd:l}=e;for(let e=n.length-2;e>=0;e-=2){let t=o.nodes[n[e]];if(!t||t.hasRequiredAttrs())break;i=r.from(t.create(n[e+1],i)),s++,l++}return new h(i,s,l)}(wr(l,+p[1],+p[2]),p[4]);else if(l=h.maxOpen(function(e,t){if(e.childCount<2)return e;for(let n=t.depth;n>=0;n--){let o,i=t.node(n).contentMatchAt(t.index(n)),s=[];if(e.forEach((e=>{if(!s)return;let t,n=i.findWrapping(e.type);if(!n)return s=null;if(t=s.length&&o.length&&mr(n,o,e,s[s.length-1],0))s[s.length-1]=t;else{s.length&&(s[s.length-1]=gr(s[s.length-1],o.length));let t=fr(e,n);s.push(t),i=i.matchType(t.type),o=n}})),s)return r.from(s)}return e}(l.content,i),!0),l.openStart||l.openEnd){let e=0,t=0;for(let t=l.content.firstChild;e{l=t(l,e)})),l}const ur=/^(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 fr(e,t,n=0){for(let o=t.length-1;o>=n;o--)e=t[o].create(null,r.from(e));return e}function mr(e,t,n,o,i){if(i1&&(s=0),i=n&&(a=t<0?l.contentMatchAt(0).fillBefore(a,s<=i).append(a):a.append(l.contentMatchAt(l.childCount).fillBefore(r.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,l.copy(a))}function wr(e,t,n){return t{for(let n in t)e.input.eventHandlers[n]||e.dom.addEventListener(n,e.input.eventHandlers[n]=t=>Dr(e,t))}))}function Dr(e,t){return e.someProp("handleDOMEvents",(n=>{let r=n[t.type];return!!r&&(r(e,t)||t.defaultPrevented)}))}function Tr(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let n=t.target;n!=e.dom;n=n.parentNode)if(!n||11==n.nodeType||n.pmViewDesc&&n.pmViewDesc.stopEvent(t))return!1;return!0}function Er(e){return{left:e.clientX,top:e.clientY}}function Ar(e,t,n,r,o){if(-1==r)return!1;let i=e.state.doc.resolve(r);for(let r=i.depth+1;r>0;r--)if(e.someProp(t,(t=>r>i.depth?t(e,n,i.nodeAfter,i.before(r),o,!0):t(e,n,i.node(r),i.before(r),o,!1))))return!0;return!1}function Ir(e,t,n){e.focused||e.focus();let r=e.state.tr.setSelection(t);"pointer"==n&&r.setMeta("pointer",!0),e.dispatch(r)}function Rr(e,t,n,r,o){return Ar(e,"handleClickOn",t,n,r)||e.someProp("handleClick",(n=>n(e,t,r)))||(o?function(e,t){if(-1==t)return!1;let n,r,o=e.state.selection;o instanceof tt&&(n=o.node);let i=e.state.doc.resolve(t);for(let e=i.depth+1;e>0;e--){let t=e>i.depth?i.nodeAfter:i.node(e);if(tt.isSelectable(t)){r=n&&o.$from.depth>0&&e>=o.$from.depth&&i.before(o.$from.depth+1)==o.$from.pos?i.before(o.$from.depth):i.before(e);break}}return null!=r&&(Ir(e,tt.create(e.state.doc,r),"pointer"),!0)}(e,n):function(e,t){if(-1==t)return!1;let n=e.state.doc.resolve(t),r=n.nodeAfter;return!!(r&&r.isAtom&&tt.isSelectable(r))&&(Ir(e,new tt(n),"pointer"),!0)}(e,n))}function zr(e,t,n,r){return Ar(e,"handleDoubleClickOn",t,n,r)||e.someProp("handleDoubleClick",(n=>n(e,t,r)))}function Pr(e,t,n,r){return Ar(e,"handleTripleClickOn",t,n,r)||e.someProp("handleTripleClick",(n=>n(e,t,r)))||function(e,t,n){if(0!=n.button)return!1;let r=e.state.doc;if(-1==t)return!!r.inlineContent&&(Ir(e,Ze.create(r,0,r.content.size),"pointer"),!0);let o=r.resolve(t);for(let t=o.depth+1;t>0;t--){let n=t>o.depth?o.nodeAfter:o.node(t),i=o.before(t);if(n.inlineContent)Ir(e,Ze.create(r,i+1,i+1+n.content.size),"pointer");else{if(!tt.isSelectable(n))continue;Ir(e,tt.create(r,i),"pointer")}return!0}}(e,n,r)}function Br(e){return Jr(e)}Sr.keydown=(e,t)=>{let n=t;if(e.input.shiftKey=16==n.keyCode||n.shiftKey,!Fr(e,n)&&(e.input.lastKeyCode=n.keyCode,e.input.lastKeyCodeTime=Date.now(),!Kt||!qt||13!=n.keyCode))if(229!=n.keyCode&&e.domObserver.forceFlush(),!Jt||13!=n.keyCode||n.ctrlKey||n.altKey||n.metaKey)e.someProp("handleKeyDown",(t=>t(e,n)))||cr(e,n)?n.preventDefault():Or(e,"key");else{let t=Date.now();e.input.lastIOSEnter=t,e.input.lastIOSEnterFallbackTimeout=setTimeout((()=>{e.input.lastIOSEnter==t&&(e.someProp("handleKeyDown",(t=>t(e,Tt(13,"Enter")))),e.input.lastIOSEnter=0)}),200)}},Sr.keyup=(e,t)=>{16==t.keyCode&&(e.input.shiftKey=!1)},Sr.keypress=(e,t)=>{let n=t;if(Fr(e,n)||!n.charCode||n.ctrlKey&&!n.altKey||Wt&&n.metaKey)return;if(e.someProp("handleKeyPress",(t=>t(e,n))))return void n.preventDefault();let r=e.state.selection;if(!(r instanceof Ze&&r.$from.sameParent(r.$to))){let t=String.fromCharCode(n.charCode);/[\r\n]/.test(t)||e.someProp("handleTextInput",(n=>n(e,r.$from.pos,r.$to.pos,t)))||e.dispatch(e.state.tr.insertText(t).scrollIntoView()),n.preventDefault()}};const Vr=Wt?"metaKey":"ctrlKey";xr.mousedown=(e,t)=>{let n=t;e.input.shiftKey=n.shiftKey;let r=Br(e),o=Date.now(),i="singleClick";o-e.input.lastClick.time<500&&function(e,t){let n=t.x-e.clientX,r=t.y-e.clientY;return n*n+r*r<100}(n,e.input.lastClick)&&!n[Vr]&&("singleClick"==e.input.lastClick.type?i="doubleClick":"doubleClick"==e.input.lastClick.type&&(i="tripleClick")),e.input.lastClick={time:o,x:n.clientX,y:n.clientY,type:i};let s=e.posAtCoords(Er(n));s&&("singleClick"==i?(e.input.mouseDown&&e.input.mouseDown.done(),e.input.mouseDown=new $r(e,s,n,!!r)):("doubleClick"==i?zr:Pr)(e,s.pos,s.inside,n)?n.preventDefault():Or(e,"pointer"))};class $r{constructor(e,t,n,r){let o,i;if(this.view=e,this.pos=t,this.event=n,this.flushed=r,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!n[Vr],this.allowDefault=n.shiftKey,t.inside>-1)o=e.state.doc.nodeAt(t.inside),i=t.inside;else{let n=e.state.doc.resolve(t.pos);o=n.parent,i=n.depth?n.before():0}const s=r?null:n.target,l=s?e.docView.nearestDesc(s,!0):null;this.target=l?l.dom:null;let{selection:a}=e.state;(0==n.button&&o.type.spec.draggable&&!1!==o.type.spec.selectable||a instanceof tt&&a.from<=i&&a.to>i)&&(this.mightDrag={node:o,pos:i,addAttr:!(!this.target||this.target.draggable),setUneditable:!(!this.target||!$t||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)),Or(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((()=>_n(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(Er(e))),this.updateAllowDefault(e),this.allowDefault||!t?Or(this.view,"pointer"):Rr(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():0==e.button&&(this.flushed||_t&&this.mightDrag&&!this.mightDrag.node.isAtom||qt&&!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)?(Ir(this.view,Ge.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):Or(this.view,"pointer")}move(e){this.updateAllowDefault(e),Or(this.view,"pointer"),0==e.buttons&&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)}}function Fr(e,t){return!!e.composing||!!(_t&&Math.abs(t.timeStamp-e.input.compositionEndedAt)<500)&&(e.input.compositionEndedAt=-2e8,!0)}xr.touchstart=e=>{e.input.lastTouch=Date.now(),Br(e),Or(e,"pointer")},xr.touchmove=e=>{e.input.lastTouch=Date.now(),Or(e,"pointer")},xr.contextmenu=e=>Br(e);const qr=Kt?5e3:-1;function Lr(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout((()=>Jr(e)),t))}function _r(e){for(e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=function(){let e=document.createEvent("Event");return e.initEvent("event",!0,!0),e.timeStamp}());e.input.compositionNodes.length>0;)e.input.compositionNodes.pop().markParentsDirty()}function Jr(e,t=!1){if(!(Kt&&e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),_r(e),t||e.docView&&e.docView.dirty){let t=qn(e);return t&&!t.eq(e.state.selection)?e.dispatch(e.state.tr.setSelection(t)):e.updateState(e.state),!0}return!1}}Sr.compositionstart=Sr.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$from;if(t.selection.empty&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some((e=>!1===e.type.spec.inclusive))))e.markCursor=e.state.storedMarks||n.marks(),Jr(e,!0),e.markCursor=null;else if(Jr(e),$t&&t.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let t=e.domSelectionRange();for(let n=t.focusNode,r=t.focusOffset;n&&1==n.nodeType&&0!=r;){let t=r<0?n.lastChild:n.childNodes[r-1];if(!t)break;if(3==t.nodeType){e.domSelection().collapse(t,t.nodeValue.length);break}n=t,r=-1}}e.input.composing=!0}Lr(e,qr)},Sr.compositionend=(e,t)=>{e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=t.timeStamp,e.input.compositionPendingChanges=e.domObserver.pendingRecords().length?e.input.compositionID:0,e.input.compositionPendingChanges&&Promise.resolve().then((()=>e.domObserver.flush())),e.input.compositionID++,Lr(e,20))};const Wr=Bt&&Vt<15||Jt&&Ut<604;function jr(e,t,n,r,o){let i=pr(e,t,n,r,e.state.selection.$from);if(e.someProp("handlePaste",(t=>t(e,o,i||h.empty))))return!0;if(!i)return!1;let s=function(e){return 0==e.openStart&&0==e.openEnd&&1==e.content.childCount?e.content.firstChild:null}(i),l=s?e.state.tr.replaceSelectionWith(s,r):e.state.tr.replaceSelection(i);return e.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Kr(e){let t=e.getData("text/plain")||e.getData("Text");if(t)return t;let n=e.getData("text/uri-list");return n?n.replace(/\r?\n/g," "):""}xr.copy=Sr.cut=(e,t)=>{let n=t,r=e.state.selection,o="cut"==n.type;if(r.empty)return;let i=Wr?null:n.clipboardData,s=r.content(),{dom:l,text:a}=dr(e,s);i?(n.preventDefault(),i.clearData(),i.setData("text/html",l.innerHTML),i.setData("text/plain",a)):function(e,t){if(!e.dom.parentNode)return;let n=e.dom.parentNode.appendChild(document.createElement("div"));n.appendChild(t),n.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),o=document.createRange();o.selectNodeContents(t),e.dom.blur(),r.removeAllRanges(),r.addRange(o),setTimeout((()=>{n.parentNode&&n.parentNode.removeChild(n),e.focus()}),50)}(e,l),o&&e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))},Sr.paste=(e,t)=>{let n=t;if(e.composing&&!Kt)return;let r=Wr?null:n.clipboardData,o=e.input.shiftKey&&45!=e.input.lastKeyCode;r&&jr(e,Kr(r),r.getData("text/html"),o,n)?n.preventDefault():function(e,t){if(!e.dom.parentNode)return;let n=e.input.shiftKey||e.state.selection.$from.parent.type.spec.code,r=e.dom.parentNode.appendChild(document.createElement(n?"textarea":"div"));n||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let o=e.input.shiftKey&&45!=e.input.lastKeyCode;setTimeout((()=>{e.focus(),r.parentNode&&r.parentNode.removeChild(r),n?jr(e,r.value,null,o,t):jr(e,r.textContent,r.innerHTML,o,t)}),50)}(e,n)};class Hr{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}}const Ur=Wt?"altKey":"ctrlKey";xr.dragstart=(e,t)=>{let n=t,r=e.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let o,i=e.state.selection,s=i.empty?null:e.posAtCoords(Er(n));if(s&&s.pos>=i.from&&s.pos<=(i instanceof tt?i.to-1:i.to));else if(r&&r.mightDrag)o=tt.create(e.state.doc,r.mightDrag.pos);else if(n.target&&1==n.target.nodeType){let t=e.docView.nearestDesc(n.target,!0);t&&t.node.type.spec.draggable&&t!=e.docView&&(o=tt.create(e.state.doc,t.posBefore))}let l=(o||e.state.selection).content(),{dom:a,text:h}=dr(e,l);n.dataTransfer.clearData(),n.dataTransfer.setData(Wr?"Text":"text/html",a.innerHTML),n.dataTransfer.effectAllowed="copyMove",Wr||n.dataTransfer.setData("text/plain",h),e.dragging=new Hr(l,!n[Ur],o)},xr.dragend=e=>{let t=e.dragging;window.setTimeout((()=>{e.dragging==t&&(e.dragging=null)}),50)},Sr.dragover=Sr.dragenter=(e,t)=>t.preventDefault(),Sr.drop=(e,t)=>{let n=t,r=e.dragging;if(e.dragging=null,!n.dataTransfer)return;let o=e.posAtCoords(Er(n));if(!o)return;let i=e.state.doc.resolve(o.pos),s=r&&r.slice;s?e.someProp("transformPasted",(t=>{s=t(s,e)})):s=pr(e,Kr(n.dataTransfer),Wr?null:n.dataTransfer.getData("text/html"),!1,i);let l=!(!r||n[Ur]);if(e.someProp("handleDrop",(t=>t(e,n,s||h.empty,l))))return void n.preventDefault();if(!s)return;n.preventDefault();let a=s?Ie(e.state.doc,i.pos,s):i.pos;null==a&&(a=i.pos);let c=e.state.tr;if(l){let{node:e}=r;e?e.replace(c):c.deleteSelection()}let d=c.mapping.map(a),p=0==s.openStart&&0==s.openEnd&&1==s.content.childCount,u=c.doc;if(p?c.replaceRangeWith(d,d,s.content.firstChild):c.replaceRange(d,d,s),c.doc.eq(u))return;let f=c.doc.resolve(d);if(p&&tt.isSelectable(s.content.firstChild)&&f.nodeAfter&&f.nodeAfter.sameMarkup(s.content.firstChild))c.setSelection(new tt(f));else{let t=c.mapping.map(a);c.mapping.maps[c.mapping.maps.length-1].forEach(((e,n,r,o)=>t=o)),c.setSelection(Gn(e,f,c.doc.resolve(t)))}e.focus(),e.dispatch(c.setMeta("uiEvent","drop"))},xr.focus=e=>{e.input.lastFocus=Date.now(),e.focused||(e.domObserver.stop(),e.dom.classList.add("ProseMirror-focused"),e.domObserver.start(),e.focused=!0,setTimeout((()=>{e.docView&&e.hasFocus()&&!e.domObserver.currentSelection.eq(e.domSelectionRange())&&_n(e)}),20))},xr.blur=(e,t)=>{let n=t;e.focused&&(e.domObserver.stop(),e.dom.classList.remove("ProseMirror-focused"),e.domObserver.start(),n.relatedTarget&&e.dom.contains(n.relatedTarget)&&e.domObserver.currentSelection.clear(),e.focused=!1)},xr.beforeinput=(e,t)=>{if(qt&&Kt&&"deleteContentBackward"==t.inputType){e.domObserver.flushSoon();let{domChangeCount:t}=e.input;setTimeout((()=>{if(e.input.domChangeCount!=t)return;if(e.dom.blur(),e.focus(),e.someProp("handleKeyDown",(t=>t(e,Tt(8,"Backspace")))))return;let{$cursor:n}=e.state.selection;n&&n.pos>0&&e.dispatch(e.state.tr.delete(n.pos-1,n.pos).scrollIntoView())}),50)}};for(let e in Sr)xr[e]=Sr[e];function Gr(e,t){if(e==t)return!0;for(let n in e)if(e[n]!==t[n])return!1;for(let n in t)if(!(n in e))return!1;return!0}class Qr{constructor(e,t){this.toDOM=e,this.spec=t||to,this.side=this.spec.side||0}map(e,t,n,r){let{pos:o,deleted:i}=e.mapResult(t.from+r,this.side<0?-1:1);return i?null:new Zr(o-n,o-n,this)}valid(){return!0}eq(e){return this==e||e instanceof Qr&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Gr(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class Xr{constructor(e,t){this.attrs=e,this.spec=t||to}map(e,t,n,r){let o=e.map(t.from+r,this.spec.inclusiveStart?-1:1)-n,i=e.map(t.to+r,this.spec.inclusiveEnd?1:-1)-n;return o>=i?null:new Zr(o,i,this)}valid(e,t){return t.from=e&&(!o||o(s.spec))&&n.push(s.copy(s.from+r,s.to+r))}for(let i=0;ie){let s=this.children[i]+1;this.children[i+2].findInner(e-s,t-s,n,r+s,o)}}map(e,t,n){return this==ro||0==e.maps.length?this:this.mapInner(e,t,0,0,n||to)}mapInner(e,t,n,r,o){let i;for(let s=0;s{let s=i-o-(n-e);for(let o=0;oi+t-r)continue;let a=l[o]+t-r;n>=a?l[o+1]=e<=a?-2:-1:e>=t&&s&&(l[o]+=s,l[o+1]+=s)}r+=s})),t=n.maps[e].map(t,-1)}let a=!1;for(let t=0;t=r.content.size){a=!0;continue}let d=n.map(e[t+1]+i,-1)-o,{index:p,offset:u}=r.content.findIndex(c),f=r.maybeChild(p);if(f&&u==c&&u+f.nodeSize==d){let r=l[t+2].mapInner(n,f,h+1,e[t]+i+1,s);r!=ro?(l[t]=c,l[t+1]=d,l[t+2]=r):(l[t+1]=-2,a=!0)}else a=!0}if(a){let a=function(e,t,n,r,o,i,s){function l(e,t){for(let i=0;i{let s,l=i+n;if(s=so(t,e,l)){for(r||(r=this.children.slice());oi&&t.to=e){this.children[t]==e&&(n=this.children[t+2]);break}let o=e+1,i=o+t.content.size;for(let e=0;eo&&t.type instanceof Xr){let e=Math.max(o,t.from)-o,n=Math.min(i,t.to)-o;en.map(e,t,to)));return oo.from(n)}forChild(e,t){if(t.isLeaf)return no.empty;let n=[];for(let r=0;re instanceof no))?e:e.reduce(((e,t)=>e.concat(t instanceof no?t:t.members)),[]))}}}function io(e,t){if(!t||!e.length)return e;let n=[];for(let r=0;rn&&t.to{let l=so(e,t,s+n);if(l){i=!0;let e=ao(l,t,n+s+1,r);e!=ro&&o.push(s,s+t.nodeSize,e)}}));let s=io(i?lo(e):e,-n).sort(ho);for(let e=0;e0;)t++;e.splice(t,0,n)}function uo(e){let t=[];return e.someProp("decorations",(n=>{let r=n(e.state);r&&r!=ro&&t.push(r)})),e.cursorWrapper&&t.push(no.create(e.state.doc,[e.cursorWrapper.deco])),oo.from(t)}const fo={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},mo=Bt&&Vt<=11;class go{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}}class yo{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new go,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.observer=window.MutationObserver&&new window.MutationObserver((e=>{for(let t=0;t"childList"==e.type&&e.removedNodes.length||"characterData"==e.type&&e.oldValue.length>e.target.nodeValue.length))?this.flushSoon():this.flush()})),mo&&(this.onCharData=e=>{this.queue.push({target:e.target,type:"characterData",oldValue:e.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,fo)),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(Qn(this.view)){if(this.suppressingSelectionUpdates)return _n(this.view);if(Bt&&Vt<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&St(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,n=new Set;for(let t=e.focusNode;t;t=kt(t))n.add(t);for(let r=e.anchorNode;r;r=kt(r))if(n.has(r)){t=r;break}let r=t&&this.view.docView.nearestDesc(t);return r&&r.ignoreMutation({type:"selection",target:3==t.nodeType?t.parentNode:t})?(this.setCurSelection(),!0):void 0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let n=e.domSelectionRange(),r=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(n)&&Qn(e)&&!this.ignoreSelectionChange(n),o=-1,i=-1,s=!1,l=[];if(e.editable)for(let e=0;e1){let e=l.filter((e=>"BR"==e.nodeName));if(2==e.length){let t=e[0],n=e[1];t.parentNode&&t.parentNode.parentNode==n.parentNode?n.remove():t.remove()}}let a=null;o<0&&r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||r)&&(o>-1&&(e.docView.markDirty(o,i),function(e){if(wo.has(e))return;if(wo.set(e,null),-1!==["normal","nowrap","pre-line"].indexOf(getComputedStyle(e.dom).whiteSpace)){if(e.requiresGeckoHackNode=$t,vo)return;console.warn("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package."),vo=!0}}(e)),this.handleDOMChange(o,i,s,l),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(n)||_n(e),this.currentSelection.set(n))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if("attributes"==e.type&&(n==this.view.docView||"contenteditable"==e.attributeName||"style"==e.attributeName&&!e.oldValue&&!e.target.getAttribute("style")))return null;if(!n||n.ignoreMutation(e))return null;if("childList"==e.type){for(let n=0;nDate.now()-50?e.input.lastSelectionOrigin:null,n=qn(e,t);if(n&&!e.state.selection.eq(n)){if(qt&&Kt&&13===e.input.lastKeyCode&&Date.now()-100t(e,Tt(13,"Enter")))))return;let r=e.state.tr.setSelection(n);"pointer"==t?r.setMeta("pointer",!0):"key"==t&&r.scrollIntoView(),s&&r.setMeta("composition",s),e.dispatch(r)}return}let l=e.state.doc.resolve(t),a=l.sharedDepth(n);t=l.before(a+1),n=e.state.doc.resolve(n).after(a+1);let h,c,d=e.state.selection,p=function(e,t,n){let r,{node:o,fromOffset:i,toOffset:s,from:l,to:a}=e.docView.parseRange(t,n),h=e.domSelectionRange(),c=h.anchorNode;if(c&&e.dom.contains(1==c.nodeType?c:c.parentNode)&&(r=[{node:c,offset:h.anchorOffset}],Dt(h)||r.push({node:h.focusNode,offset:h.focusOffset})),qt&&8===e.input.lastKeyCode)for(let e=s;e>i;e--){let t=o.childNodes[e-1],n=t.pmViewDesc;if("BR"==t.nodeName&&!n){s=e;break}if(!n||n.size)break}let d=e.state.doc,p=e.someProp("domParser")||H.fromSchema(e.state.schema),u=d.resolve(l),f=null,m=p.parse(o,{topNode:u.parent,topMatch:u.parent.contentMatchAt(u.index()),topOpen:!0,from:i,to:s,preserveWhitespace:"pre"!=u.parent.type.whitespace||"full",findPositions:r,ruleFromNode:ko,context:u});if(r&&null!=r[0].pos){let e=r[0].pos,t=r[1]&&r[1].pos;null==t&&(t=e),f={anchor:e+l,head:t+l}}return{doc:m,sel:f,from:l,to:a}}(e,t,n),u=e.state.doc,f=u.slice(p.from,p.to);8===e.input.lastKeyCode&&Date.now()-100=s?i-r:0;i-=e,i&&i=l?i-r:0;i-=t,i&&iDate.now()-225||Kt)&&i.some((e=>1==e.nodeType&&!bo.test(e.nodeName)))&&(!m||m.endA>=m.endB)&&e.someProp("handleKeyDown",(t=>t(e,Tt(13,"Enter")))))return void(e.input.lastIOSEnter=0);if(!m){if(!(o&&d instanceof Ze&&!d.empty&&d.$head.sameParent(d.$anchor))||e.composing||p.sel&&p.sel.anchor!=p.sel.head){if(p.sel){let t=So(e,e.state.doc,p.sel);if(t&&!t.eq(e.state.selection)){let n=e.state.tr.setSelection(t);s&&n.setMeta("composition",s),e.dispatch(n)}}return}m={start:d.from,endA:d.to,endB:d.to}}if(qt&&e.cursorWrapper&&p.sel&&p.sel.anchor==e.cursorWrapper.deco.from&&p.sel.head==p.sel.anchor){let e=m.endB-m.start;p.sel={anchor:p.sel.anchor+e,head:p.sel.anchor+e}}e.input.domChangeCount++,e.state.selection.frome.state.selection.from&&m.start<=e.state.selection.from+2&&e.state.selection.from>=p.from?m.start=e.state.selection.from:m.endA=e.state.selection.to-2&&e.state.selection.to<=p.to&&(m.endB+=e.state.selection.to-m.endA,m.endA=e.state.selection.to)),Bt&&Vt<=11&&m.endB==m.start+1&&m.endA==m.start&&m.start>p.from&&"  "==p.doc.textBetween(m.start-p.from-1,m.start-p.from+1)&&(m.start--,m.endA--,m.endB--);let g,y=p.doc.resolveNoCache(m.start-p.from),w=p.doc.resolveNoCache(m.endB-p.from),v=u.resolve(m.start),k=y.sameParent(w)&&y.parent.inlineContent&&v.end()>=m.endA;if((Jt&&e.input.lastIOSEnter>Date.now()-225&&(!k||i.some((e=>"DIV"==e.nodeName||"P"==e.nodeName)))||!k&&y.post(e,Tt(13,"Enter")))))return void(e.input.lastIOSEnter=0);if(e.state.selection.anchor>m.start&&function(e,t,n,r,o){if(!r.parent.isTextblock||n-t<=o.pos-r.pos||Mo(r,!0,!1)n||Mo(s,!0,!1)t(e,Tt(8,"Backspace")))))return void(Kt&&qt&&e.domObserver.suppressSelectionUpdates());qt&&Kt&&m.endB==m.start&&(e.input.lastAndroidDelete=Date.now()),Kt&&!k&&y.start()!=w.start()&&0==w.parentOffset&&y.depth==w.depth&&p.sel&&p.sel.anchor==p.sel.head&&p.sel.head==m.endA&&(m.endB-=2,w=p.doc.resolveNoCache(m.endB-p.from),setTimeout((()=>{e.someProp("handleKeyDown",(function(t){return t(e,Tt(13,"Enter"))}))}),20));let b,x,S,M=m.start,C=m.endA;if(k)if(y.pos==w.pos)Bt&&Vt<=11&&0==y.parentOffset&&(e.domObserver.suppressSelectionUpdates(),setTimeout((()=>_n(e)),20)),b=e.state.tr.delete(M,C),x=u.resolve(m.start).marksAcross(u.resolve(m.endA));else if(m.endA==m.endB&&(S=function(e,t){let n,o,i,s=e.firstChild.marks,l=t.firstChild.marks,a=s,h=l;for(let e=0;ee.mark(o.addToSet(e.marks));else{if(0!=a.length||1!=h.length)return null;o=h[0],n="remove",i=e=>e.mark(o.removeFromSet(e.marks))}let c=[];for(let e=0;en(e,M,C,t))))return;b=e.state.tr.insertText(t,M,C)}if(b||(b=e.state.tr.replace(M,C,p.doc.slice(m.start-p.from,m.endB-p.from))),p.sel){let t=So(e,b.doc,p.sel);t&&!(qt&&Kt&&e.composing&&t.empty&&(m.start!=m.endB||e.input.lastAndroidDeletet.content.size?null:Gn(e,t.resolve(n.anchor),t.resolve(n.head))}function Mo(e,t,n){let r=e.depth,o=t?e.end():e.pos;for(;r>0&&(t||e.indexAfter(r)==e.node(r).childCount);)r--,o++,t=!1;if(n){let t=e.node(r).maybeChild(e.indexAfter(r));for(;t&&!t.isLeaf;)t=t.firstChild,o++}return o}function Co(e){if(2!=e.length)return!1;let t=e.charCodeAt(0),n=e.charCodeAt(1);return t>=56320&&t<=57343&&n>=55296&&n<=56319}const Oo=dr,No=pr,Do=Jr;function To(e){let t=Object.create(null);return t.class="ProseMirror",t.contenteditable=String(e.editable),e.someProp("attributes",(n=>{if("function"==typeof n&&(n=n(e.state)),n)for(let e in n)"class"==e?t.class+=" "+n[e]:"style"==e?t.style=(t.style?t.style+";":"")+n[e]:t[e]||"contenteditable"==e||"nodeName"==e||(t[e]=String(n[e]))})),t.translate||(t.translate="no"),[Zr.node(0,e.state.doc.content.size,t)]}function Eo(e){if(e.markCursor){let t=document.createElement("img");t.className="ProseMirror-separator",t.setAttribute("mark-placeholder","true"),t.setAttribute("alt",""),e.cursorWrapper={dom:t,deco:Zr.widget(e.state.selection.head,t,{raw:!0,marks:e.markCursor})}}else e.cursorWrapper=null}function Ao(e){return!e.someProp("editable",(t=>!1===t(e.state)))}function Io(e){let t=Object.create(null);function n(e){for(let n in e)Object.prototype.hasOwnProperty.call(t,n)||(t[n]=e[n])}return e.someProp("nodeViews",n),e.someProp("markViews",n),t}function Ro(e){if(e.spec.state||e.spec.filterTransaction||e.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}for(var zo=Object.freeze({__proto__:null,Decoration:Zr,DecorationSet:no,EditorView: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 Cr,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Ro),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):"function"==typeof e?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=Ao(this),Eo(this),this.nodeViews=Io(this),this.docView=Mn(this.state.doc,To(this),uo(this),this.dom,this),this.domObserver=new yo(this,((e,t,n,r)=>xo(this,e,t,n,r))),this.domObserver.start(),function(e){for(let t in xr){let n=xr[t];e.dom.addEventListener(t,e.input.eventHandlers[t]=t=>{!Tr(e,t)||Dr(e,t)||!e.editable&&t.type in Sr||n(e,t)},Mr[t]?{passive:!0}:void 0)}_t&&e.dom.addEventListener("input",(()=>null)),Nr(e)}(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&&Nr(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Ro),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let e in this._props)t[e]=this._props[e];t.state=this.state;for(let n in e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var n;let r=this.state,o=!1,i=!1;e.storedMarks&&this.composing&&(_r(this),i=!0),this.state=e;let s=r.plugins!=e.plugins||this._props.plugins!=t.plugins;if(s||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let e=Io(this);(function(e,t){let n=0,r=0;for(let r in e){if(e[r]!=t[r])return!0;n++}for(let e in t)r++;return n!=r})(e,this.nodeViews)&&(this.nodeViews=e,o=!0)}(s||t.handleDOMEvents!=this._props.handleDOMEvents)&&Nr(this),this.editable=Ao(this),Eo(this);let l=uo(this),a=To(this),h=r.plugins==e.plugins||r.doc.eq(e.doc)?e.scrollToSelection>r.scrollToSelection?"to selection":"preserve":"reset",c=o||!this.docView.matchesNode(e.doc,a,l);!c&&e.selection.eq(r.selection)||(i=!0);let d="preserve"==h&&i&&null==this.dom.style.overflowAnchor&&function(e){let t,n,r=e.dom.getBoundingClientRect(),o=Math.max(0,r.top);for(let i=(r.left+r.right)/2,s=o+1;s=o-20){t=r,n=l.top;break}}return{refDOM:t,refTop:n,stack:Zt(e.dom)}}(this);if(i){this.domObserver.stop();let t=c&&(Bt||qt)&&!this.composing&&!r.selection.empty&&!e.selection.empty&&function(e,t){let n=Math.min(e.$anchor.sharedDepth(e.head),t.$anchor.sharedDepth(t.head));return e.$anchor.start(n)!=t.$anchor.start(n)}(r.selection,e.selection);if(c){let n=qt?this.trackWrites=this.domSelectionRange().focusNode:null;!o&&this.docView.update(e.doc,a,l,this)||(this.docView.updateOuterDeco([]),this.docView.destroy(),this.docView=Mn(e.doc,a,l,this.dom,this)),n&&!this.trackWrites&&(t=!0)}t||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&function(e){let t=e.docView.domFromPos(e.state.selection.anchor,0),n=e.domSelectionRange();return St(t.node,t.offset,n.anchorNode,n.anchorOffset)}(this))?_n(this,t):(Hn(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(r),(null===(n=this.dragging)||void 0===n?void 0:n.node)&&!r.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,r),"reset"==h?this.dom.scrollTop=0:"to selection"==h?this.scrollToSelection():d&&function({refDOM:e,refTop:t,stack:n}){let r=e?e.getBoundingClientRect().top:0;en(n,0==r?0:r-t)}(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(this.someProp("handleScrollToSelection",(e=>e(this))));else if(this.state.selection instanceof tt){let t=this.docView.domAfterPos(this.state.selection.from);1==t.nodeType&&Yt(this,t.getBoundingClientRect(),e)}else Yt(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)for(let t=0;t0&&this.state.doc.nodeAt(e))==n.node&&(r=e)}this.dragging=new Hr(e.slice,e.move,r<0?void 0:tt.create(this.state.doc,r))}someProp(e,t){let n,r=this._props&&this._props[e];if(null!=r&&(n=t?t(r):r))return n;for(let r=0;re.ownerDocument.getSelection()),this._root=e;return e||document}updateRoot(){this._root=null}posAtCoords(e){return sn(this,e)}coordsAtPos(e,t=1){return cn(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,n=-1){let r=this.docView.posFromDOM(e,t,n);if(null==r)throw new RangeError("DOM position not inside the editor");return r}endOfTextblock(e,t){return wn(this,t||this.state,e)}pasteHTML(e,t){return jr(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return jr(this,e,null,!0,t||new ClipboardEvent("paste"))}destroy(){this.docView&&(!function(e){e.domObserver.stop();for(let t in e.input.eventHandlers)e.dom.removeEventListener(t,e.input.eventHandlers[t]);clearTimeout(e.input.composingTimeout),clearTimeout(e.input.lastIOSEnterFallbackTimeout)}(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],uo(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null)}get isDestroyed(){return null==this.docView}dispatchEvent(e){return function(e,t){Dr(e,t)||!xr[t.type]||!e.editable&&t.type in Sr||xr[t.type](e,t)}(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){return _t&&11===this.root.nodeType&&function(e){let t=e.activeElement;for(;t&&t.shadowRoot;)t=t.shadowRoot.activeElement;return t}(this.dom.ownerDocument)==this.dom?function(e){let t;function n(e){e.preventDefault(),e.stopImmediatePropagation(),t=e.getTargetRanges()[0]}e.dom.addEventListener("beforeinput",n,!0),document.execCommand("indent"),e.dom.removeEventListener("beforeinput",n,!0);let r=t.startContainer,o=t.startOffset,i=t.endContainer,s=t.endOffset,l=e.domAtPos(e.state.selection.anchor);return St(l.node,l.offset,i,s)&&([r,o,i,s]=[i,s,r,o]),{anchorNode:r,anchorOffset:o,focusNode:i,focusOffset:s}}(this):this.domSelection()}domSelection(){return this.root.getSelection()}},__endComposition:Do,__parseFromClipboard:No,__serializeForClipboard:Oo}),Po={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:"'"},Bo={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Vo="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),$o="undefined"!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),Fo=0;Fo<10;Fo++)Po[48+Fo]=Po[96+Fo]=String(Fo);for(Fo=1;Fo<=24;Fo++)Po[Fo+111]="F"+Fo;for(Fo=65;Fo<=90;Fo++)Po[Fo]=String.fromCharCode(Fo+32),Bo[Fo]=String.fromCharCode(Fo);for(var qo in Po)Bo.hasOwnProperty(qo)||(Bo[qo]=Po[qo]);const Lo="undefined"!=typeof navigator&&/Mac|iP(hone|[oa]d)/.test(navigator.platform);function _o(e){let t,n,r,o,i=e.split(/-(?!$)/),s=i[i.length-1];"Space"==s&&(s=" ");for(let e=0;e127)&&(r=Po[n.keyCode])&&r!=o){let o=t[Jo(r,n)];if(o&&o(e.state,e.dispatch,e))return!0}}return!1}}var Ko=Object.freeze({__proto__:null,keydownHandler:jo,keymap:Wo});class Ho{constructor(e,t,n={}){var r;this.match=e,this.match=e,this.handler="string"==typeof t?(r=t,function(e,t,n,o){let i=r;if(t[1]){let e=t[0].lastIndexOf(t[1]);i+=t[0].slice(e+t[1].length);let r=(n+=e)-o;r>0&&(i=t[0].slice(e-r,e)+i,n=o)}return e.tr.insertText(i,n,o)}):t,this.undoable=!1!==n.undoable,this.inCode=n.inCode||!1}}const Uo=500;function Go({rules:e}){let t=new ft({state:{init:()=>null,apply(e,t){let n=e.getMeta(this);return n||(e.selectionSet||e.docChanged?null:t)}},props:{handleTextInput:(n,r,o,i)=>Qo(n,r,o,i,e,t),handleDOMEvents:{compositionend:n=>{setTimeout((()=>{let{$cursor:r}=n.state.selection;r&&Qo(n,r.pos,r.pos,"",e,t)}))}}},isInputRules:!0});return t}function Qo(e,t,n,r,o,i){if(e.composing)return!1;let s=e.state,l=s.doc.resolve(t),a=l.parent.textBetween(Math.max(0,l.parentOffset-Uo),l.parentOffset,null,"")+r;for(let h=0;h{let n=e.plugins;for(let r=0;r=0;e--)n.step(r.steps[e].invert(r.docs[e]));if(o.text){let t=n.doc.resolve(o.from).marks();n.replaceWith(o.from,o.to,e.schema.text(o.text,t))}else n.delete(o.from,o.to);t(n)}return!0}}return!1},Yo=new Ho(/--$/,"—"),Zo=new Ho(/\.\.\.$/,"…"),ei=new Ho(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"“"),ti=new Ho(/"$/,"”"),ni=new Ho(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"‘"),ri=new Ho(/'$/,"’"),oi=[ei,ti,ni,ri];function ii(e,t,n=null,r){return new Ho(e,((e,o,i,s)=>{let l=n instanceof Function?n(o):n,a=e.tr.delete(i,s),h=a.doc.resolve(i).blockRange(),c=h&&Ce(h,t,l);if(!c)return null;a.wrap(h,c);let d=a.doc.resolve(i-1).nodeBefore;return d&&d.type==t&&De(a.doc,i-1)&&(!r||r(o,d))&&a.join(i-1),a}))}function si(e,t,n=null){return new Ho(e,((e,r,o,i)=>{let s=e.doc.resolve(o),l=n instanceof Function?n(r):n;return s.node(-1).canReplaceWith(s.index(-1),s.indexAfter(-1),t)?e.tr.delete(o,i).setBlockType(o,o,t,l):null}))}var li=Object.freeze({__proto__:null,InputRule:Ho,closeDoubleQuote:ti,closeSingleQuote:ri,ellipsis:Zo,emDash:Yo,inputRules:Go,openDoubleQuote:ei,openSingleQuote:ni,smartQuotes:oi,textblockTypeInputRule:si,undoInputRule:Xo,wrappingInputRule:ii}),ai=200,hi=function(){};hi.prototype.append=function(e){return e.length?(e=hi.from(e),!this.length&&e||e.length=t?hi.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},hi.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},hi.prototype.forEach=function(e,t,n){void 0===t&&(t=0),void 0===n&&(n=this.length),t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)},hi.prototype.map=function(e,t,n){void 0===t&&(t=0),void 0===n&&(n=this.length);var r=[];return this.forEach((function(t,n){return r.push(e(t,n))}),t,n),r},hi.from=function(e){return e instanceof hi?e:e&&e.length?new ci(e):hi.empty};var ci=function(e){function t(t){e.call(this),this.values=t}e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t;var n={length:{configurable:!0},depth:{configurable:!0}};return t.prototype.flatten=function(){return this.values},t.prototype.sliceInner=function(e,n){return 0==e&&n==this.length?this:new t(this.values.slice(e,n))},t.prototype.getInner=function(e){return this.values[e]},t.prototype.forEachInner=function(e,t,n,r){for(var o=t;o=n;o--)if(!1===e(this.values[o],r+o))return!1},t.prototype.leafAppend=function(e){if(this.length+e.length<=ai)return new t(this.values.concat(e.flatten()))},t.prototype.leafPrepend=function(e){if(this.length+e.length<=ai)return new t(e.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(t.prototype,n),t}(hi);hi.empty=new ci([]);var di=function(e){function t(t,n){e.call(this),this.left=t,this.right=n,this.length=t.length+n.length,this.depth=Math.max(t.depth,n.depth)+1}return e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t,t.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},t.prototype.getInner=function(e){return eo&&!1===this.right.forEachInner(e,Math.max(t-o,0),Math.min(this.length,n)-o,r+o))&&void 0)},t.prototype.forEachInvertedInner=function(e,t,n,r){var o=this.left.length;return!(t>o&&!1===this.right.forEachInvertedInner(e,t-o,Math.max(n,o)-o,r+o))&&(!(n=n?this.right.slice(e-n,t-n):this.left.slice(e,n).append(this.right.slice(0,t-n))},t.prototype.leafAppend=function(e){var n=this.right.leafAppend(e);if(n)return new t(this.left,n)},t.prototype.leafPrepend=function(e){var n=this.left.leafPrepend(e);if(n)return new t(n,this.right)},t.prototype.appendInner=function(e){return this.left.depth>=Math.max(this.right.depth,e.depth)+1?new t(this.left,new t(this.right,e)):new t(this,e)},t}(hi);class pi{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(0==this.eventCount)return null;let n,r,o=this.items.length;for(;;o--){if(this.items.get(o-1).selection){--o;break}}t&&(n=this.remapping(o,this.items.length),r=n.maps.length);let i,s,l=e.tr,a=[],h=[];return this.items.forEach(((e,t)=>{if(!e.step)return n||(n=this.remapping(o,t+1),r=n.maps.length),r--,void h.push(e);if(n){h.push(new ui(e.map));let t,o=e.step.map(n.slice(r));o&&l.maybeStep(o).doc&&(t=l.mapping.maps[l.mapping.maps.length-1],a.push(new ui(t,void 0,void 0,a.length+h.length))),r--,t&&n.appendMap(t,r)}else l.maybeStep(e.step);return e.selection?(i=n?e.selection.map(n.slice(r)):e.selection,s=new pi(this.items.slice(0,o).append(h.reverse().concat(a)),this.eventCount-1),!1):void 0}),this.items.length,0),{remaining:s,transform:l,selection:i}}addTransform(e,t,n,r){let o=[],i=this.eventCount,s=this.items,l=!r&&s.length?s.get(s.length-1):null;for(let n=0;nmi&&(s=function(e,t){let n;return e.forEach(((e,r)=>{if(e.selection&&0==t--)return n=r,!1})),e.slice(n)}(s,a),i-=a),new pi(s.append(o),i)}remapping(e,t){let n=new de;return this.items.forEach(((t,r)=>{let o=null!=t.mirrorOffset&&r-t.mirrorOffset>=e?n.maps.length-t.mirrorOffset:void 0;n.appendMap(t.map,o)}),e,t),n}addMaps(e){return 0==this.eventCount?this:new pi(this.items.append(e.map((e=>new ui(e)))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let n=[],r=Math.max(0,this.items.length-t),o=e.mapping,i=e.steps.length,s=this.eventCount;this.items.forEach((e=>{e.selection&&s--}),r);let l=t;this.items.forEach((t=>{let r=o.getMirror(--l);if(null==r)return;i=Math.min(i,r);let a=o.maps[r];if(t.step){let i=e.steps[r].invert(e.docs[r]),h=t.selection&&t.selection.map(o.slice(l+1,r));h&&s++,n.push(new ui(a,i,h))}else n.push(new ui(a))}),r);let a=[];for(let e=t;e500&&(c=c.compress(this.items.length-n.length)),c}emptyItemCount(){let e=0;return this.items.forEach((t=>{t.step||e++})),e}compress(e=this.items.length){let t=this.remapping(0,e),n=t.maps.length,r=[],o=0;return this.items.forEach(((i,s)=>{if(s>=e)r.push(i),i.selection&&o++;else if(i.step){let e=i.step.map(t.slice(n)),s=e&&e.getMap();if(n--,s&&t.appendMap(s,n),e){let l=i.selection&&i.selection.map(t.slice(n));l&&o++;let a,h=new ui(s.invert(),e,l),c=r.length-1;(a=r.length&&r[c].merge(h))?r[c]=a:r.push(h)}}else i.map&&n--}),this.items.length,0),new pi(hi.from(r.reverse()),o)}}pi.empty=new pi(hi.empty,0);class ui{constructor(e,t,n,r){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=r}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new ui(t.getMap().invert(),t,this.selection)}}}class fi{constructor(e,t,n,r,o){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=r,this.prevComposition=o}}const mi=20;function gi(e){let t=[];return e.forEach(((e,n,r,o)=>t.push(r,o))),t}function yi(e,t){if(!e)return null;let n=[];for(let r=0;rnew fi(pi.empty,pi.empty,null,0,-1),apply:(t,n,r)=>function(e,t,n,r){let o,i=n.getMeta(xi);if(i)return i.historyState;n.getMeta(Si)&&(e=new fi(e.done,e.undone,null,0,-1));let s=n.getMeta("appendedTransaction");if(0==n.steps.length)return e;if(s&&s.getMeta(xi))return s.getMeta(xi).redo?new fi(e.done.addTransform(n,void 0,r,bi(t)),e.undone,gi(n.mapping.maps[n.steps.length-1]),e.prevTime,e.prevComposition):new fi(e.done,e.undone.addTransform(n,void 0,r,bi(t)),null,e.prevTime,e.prevComposition);if(!1===n.getMeta("addToHistory")||s&&!1===s.getMeta("addToHistory"))return(o=n.getMeta("rebased"))?new fi(e.done.rebased(n,o),e.undone.rebased(n,o),yi(e.prevRanges,n.mapping),e.prevTime,e.prevComposition):new fi(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),yi(e.prevRanges,n.mapping),e.prevTime,e.prevComposition);{let o=n.getMeta("composition"),i=0==e.prevTime||!s&&e.prevComposition!=o&&(e.prevTime<(n.time||0)-r.newGroupDelay||!function(e,t){if(!t)return!1;if(!e.docChanged)return!0;let n=!1;return e.mapping.maps[0].forEach(((e,r)=>{for(let o=0;o=t[o]&&(n=!0)})),n}(n,e.prevRanges)),l=s?yi(e.prevRanges,n.mapping):gi(n.mapping.maps[n.steps.length-1]);return new fi(e.done.addTransform(n,i?t.selection.getBookmark():void 0,r,bi(t)),pi.empty,l,n.time,null==o?e.prevComposition:o)}}(n,r,t,e)},config:e,props:{handleDOMEvents:{beforeinput(e,t){let n=t.inputType,r="historyUndo"==n?Ci:"historyRedo"==n?Oi:null;return!!r&&(t.preventDefault(),r(e.state,e.dispatch))}}}})}const Ci=(e,t)=>{let n=xi.getState(e);return!(!n||0==n.done.eventCount)&&(t&&wi(n,e,t,!1),!0)},Oi=(e,t)=>{let n=xi.getState(e);return!(!n||0==n.undone.eventCount)&&(t&&wi(n,e,t,!0),!0)};var Ni=Object.freeze({__proto__:null,closeHistory:function(e){return e.setMeta(Si,!0)},history:Mi,redo:Oi,redoDepth:function(e){let t=xi.getState(e);return t?t.undone.eventCount:0},undo:Ci,undoDepth:function(e){let t=xi.getState(e);return t?t.done.eventCount:0}});const Di=(e,t)=>!e.selection.empty&&(t&&t(e.tr.deleteSelection().scrollIntoView()),!0);function Ti(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock("backward",e):n.parentOffset>0)?null:n}const Ei=(e,t,n)=>{let r=Ti(e,n);if(!r)return!1;let o=zi(r);if(!o){let n=r.blockRange(),o=n&&Me(n);return null!=o&&(t&&t(e.tr.lift(n,o).scrollIntoView()),!0)}let i=o.nodeBefore;if(!i.type.spec.isolating&&Xi(e,o,t))return!0;if(0==r.parent.content.size&&(Ii(i,"end")||tt.isSelectable(i))){let n=Re(e.doc,r.before(),r.after(),h.empty);if(n&&n.slice.size=s-o)return!1;if(n){let t=e.tr.step(l);t.setSelection(Ze.create(t.doc,o)),n(t.scrollIntoView())}return!0}function Ii(e,t,n=!1){for(let r=e;r;r="start"==t?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&1!=r.childCount)return!1}return!1}const Ri=(e,t,n)=>{let{$head:r,empty:o}=e.selection,i=r;if(!o)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("backward",e):r.parentOffset>0)return!1;i=zi(r)}let s=i&&i.nodeBefore;return!(!s||!tt.isSelectable(s))&&(t&&t(e.tr.setSelection(tt.create(e.doc,i.pos-s.nodeSize)).scrollIntoView()),!0)};function zi(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){if(e.index(t)>0)return e.doc.resolve(e.before(t+1));if(e.node(t).type.spec.isolating)break}return null}function Pi(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock("forward",e):n.parentOffset{let r=Pi(e,n);if(!r)return!1;let o=$i(r);if(!o)return!1;let i=o.nodeAfter;if(Xi(e,o,t))return!0;if(0==r.parent.content.size&&(Ii(i,"start")||tt.isSelectable(i))){let n=Re(e.doc,r.before(),r.after(),h.empty);if(n&&n.slice.size{let{$head:r,empty:o}=e.selection,i=r;if(!o)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("forward",e):r.parentOffset=0;t--){let n=e.node(t);if(e.index(t)+1{let n,r=e.selection,o=r instanceof tt;if(o){if(r.node.isTextblock||!De(e.doc,r.from))return!1;n=r.from}else if(n=Ee(e.doc,r.from,-1),null==n)return!1;if(t){let r=e.tr.join(n);o&&r.setSelection(tt.create(r.doc,n-e.doc.resolve(n).nodeBefore.nodeSize)),t(r.scrollIntoView())}return!0},qi=(e,t)=>{let n,r=e.selection;if(r instanceof tt){if(r.node.isTextblock||!De(e.doc,r.to))return!1;n=r.to}else if(n=Ee(e.doc,r.to,1),null==n)return!1;return t&&t(e.tr.join(n).scrollIntoView()),!0},Li=(e,t)=>{let{$from:n,$to:r}=e.selection,o=n.blockRange(r),i=o&&Me(o);return null!=i&&(t&&t(e.tr.lift(o,i).scrollIntoView()),!0)},_i=(e,t)=>{let{$head:n,$anchor:r}=e.selection;return!(!n.parent.type.spec.code||!n.sameParent(r))&&(t&&t(e.tr.insertText("\n").scrollIntoView()),!0)};function Ji(e){for(let t=0;t{let{$head:n,$anchor:r}=e.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let o=n.node(-1),i=n.indexAfter(-1),s=Ji(o.contentMatchAt(i));if(!s||!o.canReplaceWith(i,i,s))return!1;if(t){let r=n.after(),o=e.tr.replaceWith(r,r,s.createAndFill());o.setSelection(Ge.near(o.doc.resolve(r),1)),t(o.scrollIntoView())}return!0},ji=(e,t)=>{let n=e.selection,{$from:r,$to:o}=n;if(n instanceof rt||r.parent.inlineContent||o.parent.inlineContent)return!1;let i=Ji(o.parent.contentMatchAt(o.indexAfter()));if(!i||!i.isTextblock)return!1;if(t){let n=(!r.parentOffset&&o.index(){let{$cursor:n}=e.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let r=n.before();if(Ne(e.doc,r))return t&&t(e.tr.split(r).scrollIntoView()),!0}let r=n.blockRange(),o=r&&Me(r);return null!=o&&(t&&t(e.tr.lift(r,o).scrollIntoView()),!0)};function Hi(e){return(t,n)=>{let{$from:r,$to:o}=t.selection;if(t.selection instanceof tt&&t.selection.node.isBlock)return!(!r.parentOffset||!Ne(t.doc,r.pos))&&(n&&n(t.tr.split(r.pos).scrollIntoView()),!0);if(!r.parent.isBlock)return!1;if(n){let i=o.parentOffset==o.parent.content.size,s=t.tr;(t.selection instanceof Ze||t.selection instanceof rt)&&s.deleteSelection();let l=0==r.depth?null:Ji(r.node(-1).contentMatchAt(r.indexAfter(-1))),a=e&&e(o.parent,i),h=a?[a]:i&&l?[{type:l}]:void 0,c=Ne(s.doc,s.mapping.map(r.pos),1,h);if(h||c||!Ne(s.doc,s.mapping.map(r.pos),1,l?[{type:l}]:void 0)||(l&&(h=[{type:l}]),c=!0),c&&(s.split(s.mapping.map(r.pos),1,h),!i&&!r.parentOffset&&r.parent.type!=l)){let e=s.mapping.map(r.before()),t=s.doc.resolve(e);l&&r.node(-1).canReplaceWith(t.index(),t.index()+1,l)&&s.setNodeMarkup(s.mapping.map(r.before()),l)}n(s.scrollIntoView())}return!0}}const Ui=Hi(),Gi=(e,t)=>{let n,{$from:r,to:o}=e.selection,i=r.sharedDepth(o);return 0!=i&&(n=r.before(i),t&&t(e.tr.setSelection(tt.create(e.doc,n))),!0)},Qi=(e,t)=>(t&&t(e.tr.setSelection(new rt(e.doc))),!0);function Xi(e,t,n){let o,i,s=t.nodeBefore,l=t.nodeAfter;if(s.type.spec.isolating||l.type.spec.isolating)return!1;if(function(e,t,n){let r=t.nodeBefore,o=t.nodeAfter,i=t.index();return!(!(r&&o&&r.type.compatibleContent(o.type))||(!r.content.size&&t.parent.canReplace(i-1,i)?(n&&n(e.tr.delete(t.pos-r.nodeSize,t.pos).scrollIntoView()),0):!t.parent.canReplace(i,i+1)||!o.isTextblock&&!De(e.doc,t.pos)||(n&&n(e.tr.clearIncompatible(t.pos,r.type,r.contentMatchAt(r.childCount)).join(t.pos).scrollIntoView()),0)))}(e,t,n))return!0;let a=t.parent.canReplace(t.index(),t.index()+1);if(a&&(o=(i=s.contentMatchAt(s.childCount)).findWrapping(l.type))&&i.matchType(o[0]||l.type).validEnd){if(n){let i=t.pos+l.nodeSize,a=r.empty;for(let e=o.length-1;e>=0;e--)a=r.from(o[e].create(null,a));a=r.from(s.copy(a));let c=e.tr.step(new be(t.pos-1,i,t.pos,i,new h(a,1,0),o.length,!0)),d=i+2*o.length;De(c.doc,d)&&c.join(d),n(c.scrollIntoView())}return!0}let c=Ge.findFrom(t,1),d=c&&c.$from.blockRange(c.$to),p=d&&Me(d);if(null!=p&&p>=t.depth)return n&&n(e.tr.lift(d,p).scrollIntoView()),!0;if(a&&Ii(l,"start",!0)&&Ii(s,"end")){let o=s,i=[];for(;i.push(o),!o.isTextblock;)o=o.lastChild;let a=l,c=1;for(;!a.isTextblock;a=a.firstChild)c++;if(o.canReplace(o.childCount,o.childCount,a.content)){if(n){let o=r.empty;for(let e=i.length-1;e>=0;e--)o=r.from(i[e].copy(o));n(e.tr.step(new be(t.pos-i.length,t.pos+l.nodeSize,t.pos+c,t.pos+l.nodeSize-c,new h(o,i.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function Yi(e){return function(t,n){let r=t.selection,o=e<0?r.$from:r.$to,i=o.depth;for(;o.node(i).isInline;){if(!i)return!1;i--}return!!o.node(i).isTextblock&&(n&&n(t.tr.setSelection(Ze.create(t.doc,e<0?o.start(i):o.end(i)))),!0)}}const Zi=Yi(-1),es=Yi(1);function ts(e,t=null){return function(n,r){let{$from:o,$to:i}=n.selection,s=o.blockRange(i),l=s&&Ce(s,e,t);return!!l&&(r&&r(n.tr.wrap(s,l).scrollIntoView()),!0)}}function ns(e,t=null){return function(n,r){let o=!1;for(let r=0;r{if(o)return!1;if(r.isTextblock&&!r.hasMarkup(e,t))if(r.type==e)o=!0;else{let t=n.doc.resolve(i),r=t.index();o=t.parent.canReplaceWith(r,r+1,e)}}))}if(!o)return!1;if(r){let o=n.tr;for(let r=0;r{if(s)return!1;s=e.inlineContent&&e.type.allowsMarkType(n)})),s)return!0}return!1}(n.doc,s,e))return!1;if(r)if(i)e.isInSet(n.storedMarks||i.marks())?r(n.tr.removeStoredMark(e)):r(n.tr.addStoredMark(e.create(t)));else{let o=!1,i=n.tr;for(let t=0;!o&&t{if(!n.isGeneric)return e(n);let r=[];for(let e=0;er.push(n,o)))}let o=[];for(let e=0;ee-t));for(let e=o.length-1;e>=0;e--)De(n.doc,o[e])&&n.join(o[e]);e(n)}}function ss(...e){return function(t,n,r){for(let o=0;ot.indexOf(e.type.name)>-1:t;return(t,r,o)=>e(t,r&&is(r,n),o)},baseKeymap:ds,chainCommands:ss,createParagraphNear:ji,deleteSelection:Di,exitCode:Wi,joinBackward:Ei,joinDown:qi,joinForward:Bi,joinTextblockBackward:(e,t,n)=>{let r=Ti(e,n);if(!r)return!1;let o=zi(r);return!!o&&Ai(e,o,t)},joinTextblockForward:(e,t,n)=>{let r=Pi(e,n);if(!r)return!1;let o=$i(r);return!!o&&Ai(e,o,t)},joinUp:Fi,lift:Li,liftEmptyBlock:Ki,macBaseKeymap:cs,newlineInCode:_i,pcBaseKeymap:hs,selectAll:Qi,selectNodeBackward:Ri,selectNodeForward:Vi,selectParentNode:Gi,selectTextblockEnd:es,selectTextblockStart:Zi,setBlockType:ns,splitBlock:Ui,splitBlockAs:Hi,splitBlockKeepMarks:(e,t)=>Ui(e,t&&(n=>{let r=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();r&&n.ensureMarks(r),t(n)})),toggleMark:rs,wrapIn:ts});const us=["p",0],fs=["blockquote",0],ms=["hr"],gs=["pre",["code",0]],ys=["br"],ws={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM:()=>us},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM:()=>fs},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM:()=>ms},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:e=>["h"+e.attrs.level,0]},code_block:{content:"text*",marks:"",group:"block",code:!0,defining:!0,parseDOM:[{tag:"pre",preserveWhitespace:"full"}],toDOM:()=>gs},text:{group:"inline"},image:{inline:!0,attrs:{src:{},alt:{default:null},title:{default:null}},group:"inline",draggable:!0,parseDOM:[{tag:"img[src]",getAttrs:e=>({src:e.getAttribute("src"),title:e.getAttribute("title"),alt:e.getAttribute("alt")})}],toDOM(e){let{src:t,alt:n,title:r}=e.attrs;return["img",{src:t,alt:n,title:r}]}},hard_break:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM:()=>ys}},vs=["em",0],ks=["strong",0],bs=["code",0],xs={link:{attrs:{href:{},title:{default:null}},inclusive:!1,parseDOM:[{tag:"a[href]",getAttrs:e=>({href:e.getAttribute("href"),title:e.getAttribute("title")})}],toDOM(e){let{href:t,title:n}=e.attrs;return["a",{href:t,title:n},0]}},em:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"},{style:"font-style=normal",clearMark:e=>"em"==e.type.name}],toDOM:()=>vs},strong:{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:e=>"normal"!=e.style.fontWeight&&null},{style:"font-weight=400",clearMark:e=>"strong"==e.type.name},{style:"font-weight",getAttrs:e=>/^(bold(er)?|[5-9]\d{2,})$/.test(e)&&null}],toDOM:()=>ks},code:{parseDOM:[{tag:"code"}],toDOM:()=>bs}},Ss=new j({nodes:ws,marks:xs});var Ms=Object.freeze({__proto__:null,marks:xs,nodes:ws,schema:Ss});const Cs=["ol",0],Os=["ul",0],Ns=["li",0],Ds={attrs:{order:{default:1}},parseDOM:[{tag:"ol",getAttrs:e=>({order:e.hasAttribute("start")?+e.getAttribute("start"):1})}],toDOM:e=>1==e.attrs.order?Cs:["ol",{start:e.attrs.order},0]},Ts={parseDOM:[{tag:"ul"}],toDOM:()=>Os},Es={parseDOM:[{tag:"li"}],toDOM:()=>Ns,defining:!0};function As(e,t){let n={};for(let t in e)n[t]=e[t];for(let e in t)n[e]=t[e];return n}function Is(e,t=null){return function(n,o){let{$from:i,$to:s}=n.selection,l=i.blockRange(s),a=!1,c=l;if(!l)return!1;if(l.depth>=2&&i.node(l.depth-1).type.compatibleContent(e)&&0==l.startIndex){if(0==i.index(l.depth-1))return!1;let e=n.doc.resolve(l.start-2);c=new C(e,e,l.depth),l.endIndex=0;e--)s=r.from(n[e].type.create(n[e].attrs,s));e.step(new be(t.start-(o?2:0),t.end,t.start,t.end,new h(s,0,0),n.length,!0));let l=0;for(let e=0;e=i.depth-3;e--)t=r.from(i.node(e).copy(t));let l=i.indexAfter(-1){if(d>-1)return!1;e.isTextblock&&0==e.content.size&&(d=t+1)})),d>-1&&c.setSelection(Ge.near(c.doc.resolve(d))),o(c.scrollIntoView())}return!0}let c=s.pos==i.end()?a.contentMatchAt(0).defaultType:null,d=n.tr.delete(i.pos,s.pos),p=c?[t?{type:e,attrs:t}:null,{type:c}]:void 0;return!!Ne(d.doc,i.pos,2,p)&&(o&&o(d.split(i.pos,2,p).scrollIntoView()),!0)}}function zs(e){return function(t,n){let{$from:o,$to:i}=t.selection,s=o.blockRange(i,(t=>t.childCount>0&&t.firstChild.type==e));return!!s&&(!n||(o.node(s.depth-1).type==e?function(e,t,n,o){let i=e.tr,s=o.end,l=o.$to.end(o.depth);sr;t--)e-=i.child(t).nodeSize,o.delete(e-1,e+1);let s=o.doc.resolve(n.start),l=s.nodeAfter;if(o.mapping.map(n.end)!=n.start+s.nodeAfter.nodeSize)return!1;let a=0==n.startIndex,c=n.endIndex==i.childCount,d=s.node(-1),p=s.index(-1);if(!d.canReplace(p+(a?0:1),p+1,l.content.append(c?r.empty:r.from(i))))return!1;let u=s.pos,f=u+l.nodeSize;return o.step(new be(u-(a?1:0),f+(c?1:0),u+1,f-1,new h((a?r.empty:r.from(i.copy(r.empty))).append(c?r.empty:r.from(i.copy(r.empty))),a?0:1,c?0:1),a?0:1)),t(o.scrollIntoView()),!0}(t,n,s)))}}function Ps(e){return function(t,n){let{$from:o,$to:i}=t.selection,s=o.blockRange(i,(t=>t.childCount>0&&t.firstChild.type==e));if(!s)return!1;let l=s.startIndex;if(0==l)return!1;let a=s.parent,c=a.child(l-1);if(c.type!=e)return!1;if(n){let o=c.lastChild&&c.lastChild.type==a.type,i=r.from(o?e.create():null),l=new h(r.from(e.create(null,r.from(a.type.create(null,i)))),o?3:1,0),d=s.start,p=s.end;n(t.tr.step(new be(d-(o?3:1),p,d,p,l,1,!0)).scrollIntoView())}return!0}}var Bs=Object.freeze({__proto__:null,addListNodes:function(e,t,n){return e.append({ordered_list:As(Ds,{content:"list_item+",group:n}),bullet_list:As(Ts,{content:"list_item+",group:n}),list_item:As(Es,{content:t})})},bulletList:Ts,liftListItem:zs,listItem:Es,orderedList:Ds,sinkListItem:Ps,splitListItem:Rs,wrapInList:Is});function Vs(e={}){return new ft({view:t=>new $s(t,e)})}class $s{constructor(e,t){var n;this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.width=null!==(n=t.width)&&void 0!==n?n:1,this.color=!1===t.color?void 0:t.color||"black",this.class=t.class,this.handlers=["dragover","dragend","drop","dragleave"].map((t=>{let n=e=>{this[t](e)};return e.dom.addEventListener(t,n),{name:t,handler:n}}))}destroy(){this.handlers.forEach((({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t)))}update(e,t){null!=this.cursorPos&&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,null==e?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e,t=this.editorView.state.doc.resolve(this.cursorPos),n=!t.parent.inlineContent;if(n){let n=t.nodeBefore,r=t.nodeAfter;if(n||r){let t=this.editorView.nodeDOM(this.cursorPos-(n?n.nodeSize:0));if(t){let o=t.getBoundingClientRect(),i=n?o.bottom:o.top;n&&r&&(i=(i+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2),e={left:o.left,right:o.right,top:i-this.width/2,bottom:i+this.width/2}}}}if(!e){let t=this.editorView.coordsAtPos(this.cursorPos);e={left:t.left-this.width/2,right:t.left+this.width/2,top:t.top,bottom:t.bottom}}let r,o,i=this.editorView.dom.offsetParent;if(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",n),this.element.classList.toggle("prosemirror-dropcursor-inline",!n),!i||i==document.body&&"static"==getComputedStyle(i).position)r=-pageXOffset,o=-pageYOffset;else{let e=i.getBoundingClientRect();r=e.left-i.scrollLeft,o=e.top-i.scrollTop}this.element.style.left=e.left-r+"px",this.element.style.top=e.top-o+"px",this.element.style.width=e.right-e.left+"px",this.element.style.height=e.bottom-e.top+"px"}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout((()=>this.setCursor(null)),e)}dragover(e){if(!this.editorView.editable)return;let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),n=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),r=n&&n.type.spec.disableDropCursor,o="function"==typeof r?r(this.editorView,t,e):r;if(t&&!o){let e=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let t=Ie(this.editorView.state.doc,e,this.editorView.dragging.slice);null!=t&&(e=t)}this.setCursor(e),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 Fs=Object.freeze({__proto__:null,dropCursor:Vs});class qs extends Ge{constructor(e){super(e,e)}map(e,t){let n=e.resolve(t.map(this.head));return qs.valid(n)?new qs(n):Ge.near(n)}content(){return h.empty}eq(e){return e instanceof qs&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,t){if("number"!=typeof t.pos)throw new RangeError("Invalid input for GapCursor.fromJSON");return new qs(e.resolve(t.pos))}getBookmark(){return new Ls(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!function(e){for(let t=e.depth;t>=0;t--){let n=e.index(t),r=e.node(t);if(0!=n)for(let e=r.child(n-1);;e=e.lastChild){if(0==e.childCount&&!e.inlineContent||e.isAtom||e.type.spec.isolating)return!0;if(e.inlineContent)return!1}else if(r.type.spec.isolating)return!0}return!0}(e)||!function(e){for(let t=e.depth;t>=0;t--){let n=e.indexAfter(t),r=e.node(t);if(n!=r.childCount)for(let e=r.child(n);;e=e.firstChild){if(0==e.childCount&&!e.inlineContent||e.isAtom||e.type.spec.isolating)return!0;if(e.inlineContent)return!1}else if(r.type.spec.isolating)return!0}return!0}(e))return!1;let n=t.type.spec.allowGapCursor;if(null!=n)return n;let r=t.contentMatchAt(e.index()).defaultType;return r&&r.isTextblock}static findGapCursorFrom(e,t,n=!1){e:for(;;){if(!n&&qs.valid(e))return e;let r=e.pos,o=null;for(let n=e.depth;;n--){let i=e.node(n);if(t>0?e.indexAfter(n)0){o=i.child(t>0?e.indexAfter(n):e.index(n)-1);break}if(0==n)return null;r+=t;let s=e.doc.resolve(r);if(qs.valid(s))return s}for(;;){let i=t>0?o.firstChild:o.lastChild;if(!i){if(o.isAtom&&!o.isText&&!tt.isSelectable(o)){e=e.doc.resolve(r+o.nodeSize*t),n=!1;continue e}break}o=i,r+=t;let s=e.doc.resolve(r);if(qs.valid(s))return s}return null}}}qs.prototype.visible=!1,qs.findFrom=qs.findGapCursorFrom,Ge.jsonID("gapcursor",qs);class Ls{constructor(e){this.pos=e}map(e){return new Ls(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return qs.valid(t)?new qs(t):Ge.near(t)}}function _s(){return new ft({props:{decorations:Hs,createSelectionBetween:(e,t,n)=>t.pos==n.pos&&qs.valid(n)?new qs(n):null,handleClick:js,handleKeyDown:Js,handleDOMEvents:{beforeinput:Ks}}})}const Js=jo({ArrowLeft:Ws("horiz",-1),ArrowRight:Ws("horiz",1),ArrowUp:Ws("vert",-1),ArrowDown:Ws("vert",1)});function Ws(e,t){const n="vert"==e?t>0?"down":"up":t>0?"right":"left";return function(e,r,o){let i=e.selection,s=t>0?i.$to:i.$from,l=i.empty;if(i instanceof Ze){if(!o.endOfTextblock(n)||0==s.depth)return!1;l=!1,s=e.doc.resolve(t>0?s.after():s.before())}let a=qs.findGapCursorFrom(s,t,l);return!!a&&(r&&r(e.tr.setSelection(new qs(a))),!0)}}function js(e,t,n){if(!e||!e.editable)return!1;let r=e.state.doc.resolve(t);if(!qs.valid(r))return!1;let o=e.posAtCoords({left:n.clientX,top:n.clientY});return!(o&&o.inside>-1&&tt.isSelectable(e.state.doc.nodeAt(o.inside)))&&(e.dispatch(e.state.tr.setSelection(new qs(r))),!0)}function Ks(e,t){if("insertCompositionText"!=t.inputType||!(e.state.selection instanceof qs))return!1;let{$from:n}=e.state.selection,o=n.parent.contentMatchAt(n.index()).findWrapping(e.state.schema.nodes.text);if(!o)return!1;let i=r.empty;for(let e=o.length-1;e>=0;e--)i=r.from(o[e].createAndFill(null,i));let s=e.state.tr.replace(n.pos,n.pos,new h(i,0,0));return s.setSelection(Ze.near(s.doc.resolve(n.pos+1))),e.dispatch(s),!1}function Hs(e){if(!(e.selection instanceof qs))return null;let t=document.createElement("div");return t.className="ProseMirror-gapcursor",no.create(e.doc,[Zr.widget(e.selection.head,t,{key:"gapcursor"})])}var Us=Object.freeze({__proto__:null,GapCursor:qs,gapCursor:_s});function Gs(){var e=arguments[0];"string"==typeof e&&(e=document.createElement(e));var t=1,n=arguments[1];if(n&&"object"==typeof n&&null==n.nodeType&&!Array.isArray(n)){for(var r in n)if(Object.prototype.hasOwnProperty.call(n,r)){var o=n[r];"string"==typeof o?e.setAttribute(r,o):null!=o&&(e[r]=o)}t++}for(;t{r.preventDefault(),n.classList.contains(el+"-disabled")||t.run(e.state,e.dispatch,e,r)})),{dom:n,update:function(e){if(t.select){let r=t.select(e);if(n.style.display=r?"":"none",!r)return!1}let r=!0;if(t.enable&&(r=t.enable(e)||!1,vl(n,el+"-disabled",!r)),t.active){let o=r&&t.active(e)||!1;vl(n,el+"-active",o)}return!0}}}}function nl(e,t){return e._props.translate?e._props.translate(t):t}let rl={time:0,node:null};function ol(e){rl.time=Date.now(),rl.node=e.target}function il(e){return Date.now()-100{i&&i.close()&&(i=null,n.removeEventListener("mousedown",s))};return r.addEventListener("mousedown",(e=>{e.preventDefault(),ol(e),i?l():(i=this.expand(o,t.dom),n.addEventListener("mousedown",s=()=>{il(o)||l()}))})),{dom:o,update:function(e){let n=t.update(e);return o.style.display=n?"":"none",n}}}expand(e,t){let n=Gs("div",{class:el+"-dropdown-menu "+(this.options.class||"")},t),r=!1;return e.appendChild(n),{close:function(){return!r&&(r=!0,e.removeChild(n),!0)},node:n}}}function ll(e,t){let n=[],r=[];for(let o=0;o{let r=!1;for(let o=0;o{e.preventDefault(),ol(e),vl(o,el+"-submenu-wrap-active",!1),i||n.addEventListener("mousedown",i=()=>{il(o)||(o.classList.remove(el+"-submenu-wrap-active"),n.removeEventListener("mousedown",i),i=null)})})),{dom:o,update:function(e){let n=t.update(e);return o.style.display=n?"":"none",n}}}}function cl(e,t){let n=document.createDocumentFragment(),r=[],o=[];for(let i=0;iFi(e),icon:dl.join}),ul=new tl({title:"Lift out of enclosing block",run:Li,select:e=>Li(e),icon:dl.lift}),fl=new tl({title:"Select parent node",run:Gi,select:e=>Gi(e),icon:dl.selectParentNode});let ml=new tl({title:"Undo last change",run:Ci,enable:e=>Ci(e),icon:dl.undo}),gl=new tl({title:"Redo last undone change",run:Oi,enable:e=>Oi(e),icon:dl.redo});function yl(e,t){let n={run:(n,r)=>ts(e,t.attrs)(n,r),select:n=>ts(e,t.attrs)(n)};for(let e in t)n[e]=t[e];return new tl(n)}function wl(e,t){let n=ns(e,t.attrs),r={run:n,enable:e=>n(e),active(n){let{$from:r,to:o,node:i}=n.selection;return i?i.hasMarkup(e,t.attrs):o<=r.end()&&r.parent.hasMarkup(e,t.attrs)}};for(let e in t)r[e]=t[e];return new tl(r)}function vl(e,t,n){n?e.classList.add(t):e.classList.remove(t)}const kl="ProseMirror-menubar";function bl(e){return new ft({view:t=>new xl(t,e)})}class xl{constructor(e,t){this.editorView=e,this.options=t,this.spacer=null,this.maxHeight=0,this.widthForMaxHeight=0,this.floating=!1,this.scrollHandler=null,this.wrapper=Gs("div",{class:kl+"-wrapper"}),this.menu=this.wrapper.appendChild(Gs("div",{class:kl})),this.menu.className=kl,e.dom.parentNode&&e.dom.parentNode.replaceChild(this.wrapper,e.dom),this.wrapper.appendChild(e.dom);let{dom:n,update:r}=cl(this.editorView,this.options.content);if(this.contentUpdate=r,this.menu.appendChild(n),this.update(),t.floating&&!function(){if("undefined"==typeof navigator)return!1;let e=navigator.userAgent;return!/Edge\/\d/.test(e)&&/AppleWebKit/.test(e)&&/Mobile\/\w+/.test(e)}()){this.updateFloat();let e=function(e){let t=[e.ownerDocument.defaultView||window];for(let n=e.parentNode;n;n=n.parentNode)t.push(n);return t}(this.wrapper);this.scrollHandler=t=>{let n=this.editorView.root;(n.body||n).contains(this.wrapper)?this.updateFloat(t.target.getBoundingClientRect?t.target:void 0):e.forEach((e=>e.removeEventListener("scroll",this.scrollHandler)))},e.forEach((e=>e.addEventListener("scroll",this.scrollHandler)))}}update(){this.contentUpdate(this.editorView.state),this.floating?this.updateScrollCursor():(this.menu.offsetWidth!=this.widthForMaxHeight&&(this.widthForMaxHeight=this.menu.offsetWidth,this.maxHeight=0),this.menu.offsetHeight>this.maxHeight&&(this.maxHeight=this.menu.offsetHeight,this.menu.style.minHeight=this.maxHeight+"px"))}updateScrollCursor(){let e=this.editorView.root.getSelection();if(!e.focusNode)return;let t=e.getRangeAt(0).getClientRects(),n=t[function(e){return e.anchorNode==e.focusNode?e.anchorOffset>e.focusOffset:e.anchorNode.compareDocumentPosition(e.focusNode)==Node.DOCUMENT_POSITION_FOLLOWING}(e)?0:t.length-1];if(!n)return;let r=this.menu.getBoundingClientRect();if(n.topr.top){let e=function(e){for(let t=e.parentNode;t;t=t.parentNode)if(t.scrollHeight>t.clientHeight)return t}(this.wrapper);e&&(e.scrollTop-=r.bottom-n.top)}}updateFloat(e){let t=this.wrapper,n=t.getBoundingClientRect(),r=e?Math.max(0,e.getBoundingClientRect().top):0;if(this.floating)if(n.top>=r||n.bottom(this.editorView.dom.ownerDocument.defaultView||window).innerHeight?"none":"",e&&(this.menu.style.top=r+"px")}else if(n.top=this.menu.offsetHeight+10){this.floating=!0;let n=this.menu.getBoundingClientRect();this.menu.style.left=n.left+"px",this.menu.style.width=n.width+"px",e&&(this.menu.style.top=r+"px"),this.menu.style.position="fixed",this.spacer=Gs("div",{class:kl+"-spacer",style:`height: ${n.height}px`}),t.insertBefore(this.spacer,this.menu)}}destroy(){this.wrapper.parentNode&&this.wrapper.parentNode.replaceChild(this.editorView.dom,this.wrapper)}}var Sl=Object.freeze({__proto__:null,Dropdown:sl,DropdownSubmenu:hl,MenuItem:tl,blockTypeItem:wl,icons:dl,joinUpItem:pl,liftItem:ul,menuBar:bl,redoItem:gl,renderGrouped:cl,selectParentNodeItem:fl,undoItem:ml,wrapItem:yl});const Ml="ProseMirror-prompt";function Cl(e){let t=document.body.appendChild(document.createElement("div"));t.className=Ml;let n=e=>{t.contains(e.target)||r()};setTimeout((()=>window.addEventListener("mousedown",n)),50);let r=()=>{window.removeEventListener("mousedown",n),t.parentNode&&t.parentNode.removeChild(t)},o=[];for(let t in e.fields)o.push(e.fields[t].render());let i=document.createElement("button");i.type="submit",i.className=Ml+"-submit",i.textContent="OK";let s=document.createElement("button");s.type="button",s.className=Ml+"-cancel",s.textContent="Cancel",s.addEventListener("click",r);let l=t.appendChild(document.createElement("form"));e.title&&(l.appendChild(document.createElement("h5")).textContent=e.title),o.forEach((e=>{l.appendChild(document.createElement("div")).appendChild(e)}));let a=l.appendChild(document.createElement("div"));a.className=Ml+"-buttons",a.appendChild(i),a.appendChild(document.createTextNode(" ")),a.appendChild(s);let h=t.getBoundingClientRect();t.style.top=(window.innerHeight-h.height)/2+"px",t.style.left=(window.innerWidth-h.width)/2+"px";let c=()=>{let t=function(e,t){let n=Object.create(null),r=0;for(let o in e){let i=e[o],s=t[r++],l=i.read(s),a=i.validate(l);if(a)return Ol(s,a),null;n[o]=i.clean(l)}return n}(e.fields,o);t&&(r(),e.callback(t))};l.addEventListener("submit",(e=>{e.preventDefault(),c()})),l.addEventListener("keydown",(e=>{27==e.keyCode?(e.preventDefault(),r()):13!=e.keyCode||e.ctrlKey||e.metaKey||e.shiftKey?9==e.keyCode&&window.setTimeout((()=>{t.contains(document.activeElement)||r()}),500):(e.preventDefault(),c())}));let d=l.elements[0];d&&d.focus()}function Ol(e,t){let n=e.parentNode,r=n.appendChild(document.createElement("div"));r.style.left=e.offsetLeft+e.offsetWidth+2+"px",r.style.top=e.offsetTop-5+"px",r.className="ProseMirror-invalid",r.textContent=t,setTimeout((()=>n.removeChild(r)),1500)}class Nl{constructor(e){this.options=e}read(e){return e.value}validateType(e){return null}validate(e){return!e&&this.options.required?"Required field":this.validateType(e)||(this.options.validate?this.options.validate(e):null)}clean(e){return this.options.clean?this.options.clean(e):e}}class Dl extends Nl{render(){let e=document.createElement("input");return e.type="text",e.placeholder=this.options.label,e.value=this.options.value||"",e.autocomplete="off",e}}function Tl(e,t){let n=e.selection.$from;for(let e=n.depth;e>=0;e--){let r=n.index(e);if(n.node(e).canReplaceWith(r,r,t))return!0}return!1}function El(e,t){let n={label:t.title,run:e};for(let e in t)n[e]=t[e];return t.enable||t.select||(n[t.enable?"enable":"select"]=t=>e(t)),new tl(n)}function Al(e,t){let{from:n,$from:r,to:o,empty:i}=e.selection;return i?!!t.isInSet(e.storedMarks||r.marks()):e.doc.rangeHasMark(n,o,t)}function Il(e,t){let n={active:t=>Al(t,e)};for(let e in t)n[e]=t[e];return El(rs(e),n)}function Rl(e,t){return El(Is(e,t.attrs),t)}function zl(e){let t,n={};var r;let o;var i;if((t=e.marks.strong)&&(n.toggleStrong=Il(t,{title:"Toggle strong style",icon:dl.strong})),(t=e.marks.em)&&(n.toggleEm=Il(t,{title:"Toggle emphasis",icon:dl.em})),(t=e.marks.code)&&(n.toggleCode=Il(t,{title:"Toggle code font",icon:dl.code})),(t=e.marks.link)&&(n.toggleLink=(r=t,new tl({title:"Add or remove link",icon:dl.link,active:e=>Al(e,r),enable:e=>!e.selection.empty,run(e,t,n){if(Al(e,r))return rs(r)(e,t),!0;Cl({title:"Create a link",fields:{href:new Dl({label:"Link target",required:!0}),title:new Dl({label:"Title"})},callback(e){rs(r,e)(n.state,n.dispatch),n.focus()}})}}))),(o=e.nodes.image)&&(n.insertImage=(i=o,new tl({title:"Insert image",label:"Image",enable:e=>Tl(e,i),run(e,t,n){let{from:r,to:o}=e.selection,s=null;e.selection instanceof tt&&e.selection.node.type==i&&(s=e.selection.node.attrs),Cl({title:"Insert image",fields:{src:new Dl({label:"Location",required:!0,value:s&&s.src}),title:new Dl({label:"Title",value:s&&s.title}),alt:new Dl({label:"Description",value:s?s.alt:e.doc.textBetween(r,o," ")})},callback(e){n.dispatch(n.state.tr.replaceSelectionWith(i.createAndFill(e))),n.focus()}})}}))),(o=e.nodes.bullet_list)&&(n.wrapBulletList=Rl(o,{title:"Wrap in bullet list",icon:dl.bulletList})),(o=e.nodes.ordered_list)&&(n.wrapOrderedList=Rl(o,{title:"Wrap in ordered list",icon:dl.orderedList})),(o=e.nodes.blockquote)&&(n.wrapBlockQuote=yl(o,{title:"Wrap in block quote",icon:dl.blockquote})),(o=e.nodes.paragraph)&&(n.makeParagraph=wl(o,{title:"Change to paragraph",label:"Plain"})),(o=e.nodes.code_block)&&(n.makeCodeBlock=wl(o,{title:"Change to code block",label:"Code"})),o=e.nodes.heading)for(let e=1;e<=10;e++)n["makeHead"+e]=wl(o,{title:"Change to heading "+e,label:"Level "+e,attrs:{level:e}});if(o=e.nodes.horizontal_rule){let e=o;n.insertHorizontalRule=new tl({title:"Insert horizontal rule",label:"Horizontal rule",enable:t=>Tl(t,e),run(t,n){n(t.tr.replaceSelectionWith(e.create()))}})}let s=e=>e.filter((e=>e));return n.insertMenu=new sl(s([n.insertImage,n.insertHorizontalRule]),{label:"Insert"}),n.typeMenu=new sl(s([n.makeParagraph,n.makeCodeBlock,n.makeHead1&&new hl(s([n.makeHead1,n.makeHead2,n.makeHead3,n.makeHead4,n.makeHead5,n.makeHead6]),{label:"Heading"})]),{label:"Type..."}),n.inlineMenu=[s([n.toggleStrong,n.toggleEm,n.toggleCode,n.toggleLink])],n.blockMenu=[s([n.wrapBulletList,n.wrapOrderedList,n.wrapBlockQuote,pl,ul,fl])],n.fullMenu=n.inlineMenu.concat([[n.insertMenu,n.typeMenu]],[[ml,gl]],n.blockMenu),n}const Pl="undefined"!=typeof navigator&&/Mac|iP(hone|[oa]d)/.test(navigator.platform);function Bl(e,t){let n,r={};function o(e,n){if(t){let n=t[e];if(!1===n)return;n&&(e=n)}r[e]=n}if(o("Mod-z",Ci),o("Shift-Mod-z",Oi),o("Backspace",Xo),Pl||o("Mod-y",Oi),o("Alt-ArrowUp",Fi),o("Alt-ArrowDown",qi),o("Mod-BracketLeft",Li),o("Escape",Gi),(n=e.marks.strong)&&(o("Mod-b",rs(n)),o("Mod-B",rs(n))),(n=e.marks.em)&&(o("Mod-i",rs(n)),o("Mod-I",rs(n))),(n=e.marks.code)&&o("Mod-`",rs(n)),(n=e.nodes.bullet_list)&&o("Shift-Ctrl-8",Is(n)),(n=e.nodes.ordered_list)&&o("Shift-Ctrl-9",Is(n)),(n=e.nodes.blockquote)&&o("Ctrl->",ts(n)),n=e.nodes.hard_break){let e=n,t=ss(Wi,((t,n)=>(n&&n(t.tr.replaceSelectionWith(e.create()).scrollIntoView()),!0)));o("Mod-Enter",t),o("Shift-Enter",t),Pl&&o("Ctrl-Enter",t)}if((n=e.nodes.list_item)&&(o("Enter",Rs(n)),o("Mod-[",zs(n)),o("Mod-]",Ps(n))),(n=e.nodes.paragraph)&&o("Shift-Ctrl-0",ns(n)),(n=e.nodes.code_block)&&o("Shift-Ctrl-\\",ns(n)),n=e.nodes.heading)for(let e=1;e<=6;e++)o("Shift-Ctrl-"+e,ns(n,{level:e}));if(n=e.nodes.horizontal_rule){let e=n;o("Mod-_",((t,n)=>(n&&n(t.tr.replaceSelectionWith(e.create()).scrollIntoView()),!0)))}return r}function Vl(e){let t,n=oi.concat(Zo,Yo);return(t=e.nodes.blockquote)&&n.push(ii(/^\s*>\s$/,t)),(t=e.nodes.ordered_list)&&n.push(function(e){return ii(/^(\d+)\.\s$/,e,(e=>({order:+e[1]})),((e,t)=>t.childCount+t.attrs.order==+e[1]))}(t)),(t=e.nodes.bullet_list)&&n.push(function(e){return ii(/^\s*([-+*])\s$/,e)}(t)),(t=e.nodes.code_block)&&n.push(function(e){return si(/^```$/,e)}(t)),(t=e.nodes.heading)&&n.push(function(e,t){return si(new RegExp("^(#{1,"+t+"})\\s$"),e,(e=>({level:e[1].length})))}(t,6)),Go({rules:n})}var $l=Object.freeze({__proto__:null,buildInputRules:Vl,buildKeymap:Bl,buildMenuItems:zl,exampleSetup:function(e){let t=[Vl(e.schema),Wo(Bl(e.schema,e.mapKeys)),Wo(ds),Vs(),_s()];return!1!==e.menuBar&&t.push(bl({floating:!1!==e.floatingMenu,content:e.menuContent||zl(e.schema).fullMenu})),!1!==e.history&&t.push(Mi()),t.concat(new ft({props:{attributes:{class:"ProseMirror-example-setup-style"}}}))}});window.PM={model:se,transform:He,state:wt,view:zo,keymap:Ko,inputrules:li,history:Ni,commands:ps,schema_basic:Ms,schema_list:Bs,dropcursor:Fs,menu:Sl,example_setup:$l,gapcursor:Us}}(); +