diff --git a/.eslintrc.json b/.eslintrc.json index e9f139bf..5f078776 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -17,6 +17,7 @@ }, "rules": { "no-console": ["error", { "allow": ["error"] }], + "react/prop-types": "off", "react-hooks/exhaustive-deps": [ "warn", { diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 3e38b99a..492152d4 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -48,8 +48,5 @@ jobs: - name: Install dependencies run: yarn - - uses: browser-actions/setup-chrome@v1 - - uses: browser-actions/setup-firefox@v1 - - name: Test run: yarn test diff --git a/.vscode/settings.json b/.vscode/settings.json index 99a85deb..49a56e08 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,10 +3,8 @@ "**/.yarn": true, "**/.pnp.*": true }, - // "typescript.tsdk": ".yarn/sdks/typescript/lib", + "typescript.tsdk": "node_modules/typescript/lib", "typescript.enablePromptUseWorkspaceTsdk": true, - // "prettier.prettierPath": ".yarn/sdks/prettier/index.js", - // "eslint.nodePath": ".yarn/sdks", "editor.formatOnSave": true, "[javascript][typescript]": { "editor.defaultFormatter": "esbenp.prettier-vscode", diff --git a/README.md b/README.md index 4d1693e6..01879877 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,8 @@ yarn add @nytimes/react-prosemirror - [`useEditorEventListener`](#useeditoreventlistener-1) - [`useEditorEffect`](#useeditoreffect-1) - [`NodeViewComponentProps`](#nodeviewcomponentprops) + - [`useStopEvent`](#usestopevent) + - [`useSelectNode`](#useselectnode) - [`widget`](#widget) @@ -573,12 +575,13 @@ export function SelectionWidget() { ```tsx type NodeViewComponentProps = { - decorations: readonly Decoration[]; - innerDecorations: DecorationSource; - node: Node; - children?: ReactNode | ReactNode[]; - isSelected: boolean; - pos: number; + nodeProps: { + decorations: readonly Decoration[]; + innerDecorations: DecorationSource; + node: Node; + children?: ReactNode | ReactNode[]; + getPos: () => number; + }; } & HTMLAttributes; ``` @@ -594,6 +597,27 @@ and should pass them through to their top-level DOM element. In addition to accepting these props, all node view components _must_ forward their ref to their top-level DOM element. +### `useStopEvent` + +```tsx +type useStopEvent = (stopEvent: (view: EditorView, event: Event) => boolean): void +``` + +This hook can be used within a node view component to register a +[stopEvent handler](https://prosemirror.net/docs/ref/#view.NodeView.stopEvent). +Events for which this returns true are not handled by the editor. + +### `useSelectNode` + +```tsx +type useSelectNode = (selectNode: () => void, deselectNode?: () => void): void +``` + +This hook can be used within a node view component to register +[selectNode and deselectNode handlers](https://prosemirror.net/docs/ref/#view.NodeView.selectNode). +The selectNode handler will only be called when a NodeSelection is created whose +node is this one. + ### `widget` ```tsx diff --git a/demo/main.tsx b/demo/main.tsx index f848801a..4e636d4d 100644 --- a/demo/main.tsx +++ b/demo/main.tsx @@ -19,6 +19,8 @@ import React, { Ref, StrictMode, forwardRef, + useCallback, + useMemo, useState, } from "react"; import { createRoot } from "react-dom/client"; @@ -196,7 +198,7 @@ const Footnote = forwardRef(function Footnote( }); const TestWidget = forwardRef(function TestWidget( - { widget, pos, ...props }: WidgetViewComponentProps, + { widget, getPos, ...props }: WidgetViewComponentProps, ref: ForwardedRef ) { return ( @@ -303,6 +305,25 @@ function DemoEditor() { const [state, setState] = useState(editorState); const [showReactNodeViews, setShowReactNodeViews] = useState(true); + const nodeViews = useMemo( + () => + showReactNodeViews + ? { + paragraph: Paragraph, + list: List, + list_item: ListItem, + footnote: Footnote, + } + : undefined, + [showReactNodeViews] + ); + + const dispatchTransaction = useCallback(function (tr) { + setState((prev) => { + return prev.apply(tr); + }); + }, []); + return (

React ProseMirror Demo

@@ -324,25 +345,12 @@ function DemoEditor() { key={`${showReactNodeViews}`} className="ProseMirror" state={state} - dispatchTransaction={function (tr) { - setState((prev) => { - return prev.apply(tr); - }); - }} + dispatchTransaction={dispatchTransaction} plugins={plugins} - nodeViews={ - showReactNodeViews - ? { - paragraph: Paragraph, - list: List, - list_item: ListItem, - footnote: Footnote, - } - : undefined - } + nodeViews={nodeViews} customNodeViews={showReactNodeViews ? undefined : customNodeViews} > - } /> +
); diff --git a/docs/assets/index-B1RmUjDz.js b/docs/assets/index-B1RmUjDz.js deleted file mode 100644 index 6e5adc65..00000000 --- a/docs/assets/index-B1RmUjDz.js +++ /dev/null @@ -1,53 +0,0 @@ -(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const o of i)if(o.type==="childList")for(const s of o.addedNodes)s.tagName==="LINK"&&s.rel==="modulepreload"&&r(s)}).observe(document,{childList:!0,subtree:!0});function t(i){const o={};return i.integrity&&(o.integrity=i.integrity),i.referrerPolicy&&(o.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?o.credentials="include":i.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function r(i){if(i.ep)return;i.ep=!0;const o=t(i);fetch(i.href,o)}})();function G1(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var nm={exports:{}},Hl={},rm={exports:{}},B={};/** - * @license React - * react.production.min.js - * - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */var _o=Symbol.for("react.element"),X1=Symbol.for("react.portal"),Z1=Symbol.for("react.fragment"),eS=Symbol.for("react.strict_mode"),tS=Symbol.for("react.profiler"),nS=Symbol.for("react.provider"),rS=Symbol.for("react.context"),iS=Symbol.for("react.forward_ref"),oS=Symbol.for("react.suspense"),sS=Symbol.for("react.memo"),lS=Symbol.for("react.lazy"),yd=Symbol.iterator;function aS(n){return n===null||typeof n!="object"?null:(n=yd&&n[yd]||n["@@iterator"],typeof n=="function"?n:null)}var im={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},om=Object.assign,sm={};function ui(n,e,t){this.props=n,this.context=e,this.refs=sm,this.updater=t||im}ui.prototype.isReactComponent={};ui.prototype.setState=function(n,e){if(typeof n!="object"&&typeof n!="function"&&n!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,n,e,"setState")};ui.prototype.forceUpdate=function(n){this.updater.enqueueForceUpdate(this,n,"forceUpdate")};function lm(){}lm.prototype=ui.prototype;function Wc(n,e,t){this.props=n,this.context=e,this.refs=sm,this.updater=t||im}var Uc=Wc.prototype=new lm;Uc.constructor=Wc;om(Uc,ui.prototype);Uc.isPureReactComponent=!0;var Sd=Array.isArray,am=Object.prototype.hasOwnProperty,Hc={current:null},um={key:!0,ref:!0,__self:!0,__source:!0};function cm(n,e,t){var r,i={},o=null,s=null;if(e!=null)for(r in e.ref!==void 0&&(s=e.ref),e.key!==void 0&&(o=""+e.key),e)am.call(e,r)&&!um.hasOwnProperty(r)&&(i[r]=e[r]);var l=arguments.length-2;if(l===1)i.children=t;else if(1>1}};de.from=function(n){if(n instanceof de)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new de(e)};function dm(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),o=e.child(r);if(i==o){t+=i.nodeSize;continue}if(!i.sameMarkup(o))return t;if(i.isText&&i.text!=o.text){for(let s=0;i.text[s]==o.text[s];s++)t++;return t}if(i.content.size||o.content.size){let s=dm(i.content,o.content,t+1);if(s!=null)return s}t+=i.nodeSize}}function hm(n,e,t,r){for(let i=n.childCount,o=e.childCount;;){if(i==0||o==0)return i==o?null:{a:t,b:r};let s=n.child(--i),l=e.child(--o),a=s.nodeSize;if(s==l){t-=a,r-=a;continue}if(!s.sameMarkup(l))return{a:t,b:r};if(s.isText&&s.text!=l.text){let u=0,c=Math.min(s.text.length,l.text.length);for(;ue&&r(a,i+l,o||null,s)!==!1&&a.content.size){let c=l+1;a.nodesBetween(Math.max(0,e-c),Math.min(a.content.size,t-c),r,i+c)}l=u}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let o="",s=!0;return this.nodesBetween(e,t,(l,a)=>{let u=l.isText?l.text.slice(Math.max(e,a)-a,t-a):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&u||l.isTextblock)&&r&&(s?s=!1:o+=r),o+=u},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),o=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),o=1);oe)for(let o=0,s=0;se&&((st)&&(l.isText?l=l.cut(Math.max(0,e-s),Math.min(l.text.length,t-s)):l=l.cut(Math.max(0,e-s-1),Math.min(l.content.size,t-s-1))),r.push(l),i+=l.nodeSize),s=a}return new v(r,i)}cutByIndex(e,t){return e==t?v.empty:e==0&&t==this.content.length?this:new v(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),o=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new v(i,o)}addToStart(e){return new v([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new v(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let o=this.child(r),s=i+o.nodeSize;if(s>=e)return s==e||t>0?ss(r+1,s):ss(r,i);i=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return v.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new v(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return v.empty;let t,r=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(o)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}}W.none=[];class Mn extends Error{}class k{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=mm(this.content,e+this.openStart,t);return r&&new k(r,this.openStart,this.openEnd)}removeBetween(e,t){return new k(pm(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return k.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new k(v.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let o=e.firstChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.lastChild)i++;return new k(e,r,i)}}k.empty=new k(v.empty,0,0);function pm(n,e,t){let{index:r,offset:i}=n.findIndex(e),o=n.maybeChild(r),{index:s,offset:l}=n.findIndex(t);if(i==e||o.isText){if(l!=t&&!n.child(s).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=s)throw new RangeError("Removing non-flat range");return n.replaceChild(r,o.copy(pm(o.content,e-i-1,t-i-1)))}function mm(n,e,t,r){let{index:i,offset:o}=n.findIndex(e),s=n.maybeChild(i);if(o==e||s.isText)return n.cut(0,e).append(t).append(n.cut(e));let l=mm(s.content,e-o-1,t);return l&&n.replaceChild(i,s.copy(l))}function wS(n,e,t){if(t.openStart>n.depth)throw new Mn("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Mn("Inconsistent open depths");return gm(n,e,t,0)}function gm(n,e,t,r){let i=n.index(r),o=n.node(r);if(i==e.index(r)&&r=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function Qi(n,e,t,r){let i=(e||n).node(t),o=0,s=e?e.index(t):i.childCount;n&&(o=n.index(t),n.depth>t?o++:n.textOffset&&(Yn(n.nodeAfter,r),o++));for(let l=o;li&&yu(n,e,i+1),s=r.depth>i&&yu(t,r,i+1),l=[];return Qi(null,n,i,l),o&&s&&e.index(i)==t.index(i)?(ym(o,s),Yn(Gn(o,Sm(n,e,t,r,i+1)),l)):(o&&Yn(Gn(o,al(n,e,i+1)),l),Qi(e,t,i,l),s&&Yn(Gn(s,al(t,r,i+1)),l)),Qi(r,null,i,l),new v(l)}function al(n,e,t){let r=[];if(Qi(null,n,t,r),n.depth>t){let i=yu(n,e,t+1);Yn(Gn(i,al(n,e,t+1)),r)}return Qi(e,null,t,r),new v(r)}function kS(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let o=t-1;o>=0;o--)i=e.node(o).copy(v.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}class fo{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let o=0;o0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new CS(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,o=t;for(let s=e;;){let{index:l,offset:a}=s.content.findIndex(o),u=o-a;if(r.push(s,l,i+a),!u||(s=s.child(l),s.isText))break;o=u-1,i+=a+1}return new fo(t,r,o)}static resolveCached(e,t){let r=kd.get(e);if(r)for(let o=0;oe&&this.nodesBetween(e,t,o=>(r.isInSet(o.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),wm(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=v.empty,i=0,o=r.childCount){let s=this.contentMatchAt(e).matchFragment(r,i,o),l=s&&s.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let a=i;at.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=v.fromJSON(e,t.content),o=e.nodeType(t.type).create(t.attrs,i,r);return o.type.checkAttrs(o.attrs),o}}Dt.prototype.text=void 0;class ul extends Dt{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):wm(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 ul(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new ul(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function wm(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}class nr{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new MS(e,t);if(r.next==null)return nr.empty;let i=km(r);r.next&&r.err("Unexpected trailing text");let o=bS(AS(i));return IS(o,r),o}matchType(e){for(let t=0;tu.createAndFill()));for(let u=0;u=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(r){e.push(r);for(let i=0;i{let o=i+(r.validEnd?"*":" ")+" ";for(let s=0;s"+e.indexOf(r.next[s].next);return o}).join(` -`)}}nr.empty=new nr(!0);class MS{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 km(n){let e=[];do e.push(ES(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function ES(n){let e=[];do e.push(OS(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function OS(n){let e=RS(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=DS(n,e);else break;return e}function vd(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function DS(n,e){let t=vd(n),r=t;return n.eat(",")&&(n.next!="}"?r=vd(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function TS(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let o in t){let s=t[o];s.groups.indexOf(e)>-1&&i.push(s)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function RS(n){if(n.eat("(")){let e=km(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=TS(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function AS(n){let e=[[]];return i(o(n,0),t()),e;function t(){return e.push([])-1}function r(s,l,a){let u={term:a,to:l};return e[s].push(u),u}function i(s,l){s.forEach(a=>a.to=l)}function o(s,l){if(s.type=="choice")return s.exprs.reduce((a,u)=>a.concat(o(u,l)),[]);if(s.type=="seq")for(let a=0;;a++){let u=o(s.exprs[a],l);if(a==s.exprs.length-1)return u;i(u,l=t())}else if(s.type=="star"){let a=t();return r(l,a),i(o(s.expr,a),a),[r(a)]}else if(s.type=="plus"){let a=t();return i(o(s.expr,l),a),i(o(s.expr,a),a),[r(a)]}else{if(s.type=="opt")return[r(l)].concat(o(s.expr,l));if(s.type=="range"){let a=l;for(let u=0;u{n[s].forEach(({term:l,to:a})=>{if(!l)return;let u;for(let c=0;c{u||i.push([l,u=[]]),u.indexOf(c)==-1&&u.push(c)})})});let o=e[r.join(",")]=new nr(r.indexOf(n.length-1)>-1);for(let s=0;s-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[o]=new Em(o,t,s));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let o in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function zS(n,e,t){let r=t.split("|");return i=>{let o=i===null?"null":typeof i;if(r.indexOf(o)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${o}`)}}class PS{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?zS(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}}class Wo{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=Mm(e,i.attrs),this.excluded=null;let o=xm(this.attrs);this.instance=o?new W(this,o):null}create(e=null){return!e&&this.instance?this.instance:new W(this,Cm(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((o,s)=>r[o]=new Wo(o,i++,t,s)),r}removeFromSet(e){for(var t=0;t-1}}class Om{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=de.from(e.nodes),t.marks=de.from(e.marks||{}),this.nodes=Cd.compile(this.spec.nodes,this),this.marks=Wo.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let o=this.nodes[i],s=o.spec.content||"",l=o.spec.marks;if(o.contentMatch=r[s]||(r[s]=nr.parse(s,this.nodes)),o.inlineContent=o.contentMatch.inlineContent,o.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!o.isInline||!o.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=o}o.markSet=l=="_"?null:l?Nd(this,l.split(" ")):l==""||!o.inlineContent?[]:null}for(let i in this.marks){let o=this.marks[i],s=o.spec.excludes;o.excluded=s==null?[o]:s==""?[]:Nd(this,s.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Cd){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,r,i)}text(e,t){let r=this.nodes.text;return new ul(r,r.defaultAttrs,e,W.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return Dt.fromJSON(this,e)}markFromJSON(e){return W.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function Nd(n,e){let t=[];for(let r=0;r-1)&&t.push(s=a)}if(!s)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function FS(n){return n.tag!=null}function LS(n){return n.style!=null}class ho{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(FS(i))this.tags.push(i);else if(LS(i)){let o=/[^=]*/.exec(i.style)[0];r.indexOf(o)<0&&r.push(o),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let o=e.nodes[i.node];return o.contentMatch.matchType(o)})}parse(e,t={}){let r=new Ed(this,t,!1);return r.addAll(e,W.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new Ed(this,t,!0);return r.addAll(e,W.none,t.from,t.to),k.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(s.getAttrs){let a=s.getAttrs(t);if(a===!1)continue;s.attrs=a||void 0}return s}}}static schemaRules(e){let t=[];function r(i){let o=i.priority==null?50:i.priority,s=0;for(;s{r(s=Od(s)),s.mark||s.ignore||s.clearMark||(s.mark=i)})}for(let i in e.nodes){let o=e.nodes[i].spec.parseDOM;o&&o.forEach(s=>{r(s=Od(s)),s.node||s.ignore||s.mark||(s.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new ho(e,ho.schemaRules(e)))}}const Dm={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},$S={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Tm={ol:!0,ul:!0},cl=1,fl=2,Yi=4;function Md(n,e,t){return e!=null?(e?cl:0)|(e==="full"?fl:0):n&&n.whitespace=="pre"?cl|fl:t&~Yi}class ls{constructor(e,t,r,i,o,s){this.type=e,this.attrs=t,this.marks=r,this.solid=i,this.options=s,this.content=[],this.activeMarks=W.none,this.match=o||(s&Yi?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(v.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&cl)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-i[0].length))}}let t=v.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(v.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Dm.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class Ed{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0;let i=t.topNode,o,s=Md(null,t.preserveWhitespace,0)|(r?Yi:0);i?o=new ls(i.type,i.attrs,W.none,!0,t.topMatch||i.type.contentMatch,s):r?o=new ls(null,null,W.none,!0,null,s):o=new ls(e.schema.topNodeType,null,W.none,!0,null,s),this.nodes=[o],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,i=this.top;if(i.options&fl||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(i.options&cl)i.options&fl?r=r.replace(/\r\n?/g,` -`):r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let o=i.content[i.content.length-1],s=e.previousSibling;(!o||s&&s.nodeName=="BR"||o.isText&&/[ \t\r\n\u000c]$/.test(o.text))&&(r=r.slice(1))}r&&this.insertNode(this.parser.schema.text(r),t),this.findInText(e)}else this.findInside(e)}addElement(e,t,r){let i=e.nodeName.toLowerCase(),o;Tm.hasOwnProperty(i)&&this.parser.normalizeLists&&BS(e);let s=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(o=this.parser.matchTag(e,this,r));if(s?s.ignore:$S.hasOwnProperty(i))this.findInside(e),this.ignoreFallback(e,t);else if(!s||s.skip||s.closeParent){s&&s.closeParent?this.open=Math.max(0,this.open-1):s&&s.skip.nodeType&&(e=s.skip);let l,a=this.top,u=this.needsBlock;if(Dm.hasOwnProperty(i))a.content.length&&a.content[0].isInline&&this.open&&(this.open--,a=this.top),l=!0,a.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);return}let c=s&&s.skip?t:this.readStyles(e,t);c&&this.addAll(e,c),l&&this.sync(a),this.needsBlock=u}else{let l=this.readStyles(e,t);l&&this.addElementByRule(e,s,l,s.consuming===!1?o:void 0)}}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` -`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let r=e.style;if(r&&r.length)for(let i=0;i!a.clearMark(u)):t=t.concat(this.parser.schema.marks[a.mark].create(a.attrs)),a.consuming===!1)l=a;else break}}return t}addElementByRule(e,t,r,i){let o,s;if(t.node)if(s=this.parser.schema.nodes[t.node],s.isLeaf)this.insertNode(s.create(t.attrs),r)||this.leafFallback(e,r);else{let a=this.enter(s,t.attrs||null,r,t.preserveWhitespace);a&&(o=!0,r=a)}else{let a=this.parser.schema.marks[t.mark];r=r.concat(a.create(t.attrs))}let l=this.top;if(s&&s.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a,r));else{let a=e;typeof t.contentElement=="string"?a=e.querySelector(t.contentElement):typeof t.contentElement=="function"?a=t.contentElement(e):t.contentElement&&(a=t.contentElement),this.findAround(e,a,!0),this.addAll(a,r)}o&&this.sync(l)&&this.open--}addAll(e,t,r,i){let o=r||0;for(let s=r?e.childNodes[r]:e.firstChild,l=i==null?null:e.childNodes[i];s!=l;s=s.nextSibling,++o)this.findAtPoint(e,o),this.addDOM(s,t);this.findAtPoint(e,o)}findPlace(e,t){let r,i;for(let o=this.open;o>=0;o--){let s=this.nodes[o],l=s.findWrapping(e);if(l&&(!r||r.length>l.length)&&(r=l,i=s,!l.length)||s.solid)break}if(!r)return null;this.sync(i);for(let o=0;o(s.type?s.type.allowsMarkType(u.type):Dd(u.type,e))?(a=u.addToSet(a),!1):!0),this.nodes.push(new ls(e,t,a,i,null,l)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(i?0:1),s=(l,a)=>{for(;l>=0;l--){let u=t[l];if(u==""){if(l==t.length-1||l==0)continue;for(;a>=o;a--)if(s(l-1,a))return!0;return!1}else{let c=a>0||a==0&&i?this.nodes[a].type:r&&a>=o?r.node(a-o).type:null;if(!c||c.name!=u&&c.groups.indexOf(u)==-1)return!1;a--}}return!0};return s(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}}function BS(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&Tm.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function VS(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function Od(n){let e={};for(let t in n)e[t]=n[t];return e}function Dd(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let o=[],s=l=>{o.push(l);for(let a=0;a{if(o.length||s.marks.length){let l=0,a=0;for(;l=0;i--){let o=this.serializeMark(e.marks[i],e.isInline,t);o&&((o.contentDOM||o.dom).appendChild(r),r=o.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&Is(ya(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return Is(e,t,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new ci(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=Td(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return Td(e.marks)}}function Td(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function ya(n){return n.document||window.document}const Rd=new WeakMap;function JS(n){let e=Rd.get(n);return e===void 0&&Rd.set(n,e=_S(n)),e}function _S(n){let e=null;function t(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let s=i.indexOf(" ");s>0&&(t=i.slice(0,s),i=i.slice(s+1));let l,a=t?n.createElementNS(t,i):n.createElement(i),u=e[1],c=1;if(u&&typeof u=="object"&&u.nodeType==null&&!Array.isArray(u)){c=2;for(let f in u)if(u[f]!=null){let d=f.indexOf(" ");d>0?a.setAttributeNS(f.slice(0,d),f.slice(d+1),u[f]):a.setAttribute(f,u[f])}}for(let f=c;fc)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}else{let{dom:p,contentDOM:h}=Is(n,d,t,r);if(a.appendChild(p),h){if(l)throw new RangeError("Multiple content holes");l=h}}}return{dom:a,contentDOM:l}}const Rm=65535,Am=Math.pow(2,16);function WS(n,e){return n+e*Am}function Ad(n){return n&Rm}function US(n){return(n-(n&Rm))/Am}const bm=1,Im=2,zs=4,zm=8;let bd=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&zm)>0}get deletedBefore(){return(this.delInfo&(bm|zs))>0}get deletedAfter(){return(this.delInfo&(Im|zs))>0}get deletedAcross(){return(this.delInfo&zs)>0}},Ur=class gr{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&gr.empty)return gr.empty}recover(e){let t=0,r=Ad(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],f=a+u;if(e<=f){let d=u?e==a?-1:e==f?1:t:t,p=a+i+(d<0?0:c);if(r)return p;let h=e==(t<0?a:f)?null:WS(l/3,e-a),m=e==a?Im:e==f?bm:zs;return(t<0?e!=a:e!=f)&&(m|=zm),new bd(p,m,h)}i+=c-u}return r?e+i:new bd(e+i,0,null)}touches(e,t){let r=0,i=Ad(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return Fe.fromReplace(e,this.from,this.to,o)}invert(){return new Fm(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new Ci(t.pos,r.pos,this.mark)}merge(e){return e instanceof Ci&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Ci(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Ci(t.from,t.to,e.markFromJSON(t.mark))}};He.jsonID("addMark",Pm);let Fm=class Ni extends He{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new k(Kc(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return Fe.fromReplace(e,this.from,this.to,r)}invert(){return new Pm(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new Ni(t.pos,r.pos,this.mark)}merge(e){return e instanceof Ni&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Ni(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Ni(t.from,t.to,e.markFromJSON(t.mark))}};He.jsonID("removeMark",Fm);let Lm=class Mi extends He{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 r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return Fe.fromReplace(e,this.pos,this.pos+1,new k(v.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new Ps(t.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Ps(t.from,t.to,t.gapFrom,t.gapTo,k.fromJSON(e,t.slice),t.insert,!!t.structure)}};He.jsonID("replaceAround",dl);function wu(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function HS(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function Qc(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),o=n.$from.index(r),s=n.$to.indexAfter(r);if(ro;u--,c--){let f=i.node(u),d=i.index(u);if(f.type.spec.isolating)return!1;let p=f.content.cutByIndex(d,f.childCount),h=r&&r[c]||f;if(h!=f&&(p=p.replaceChild(0,h.type.create(h.attrs))),!f.canReplace(d+1,f.childCount)||!h.type.validContent(p))return!1}let l=i.indexAfter(o),a=r&&r[0];return i.node(o).canReplaceWith(l,l,a?a.type:i.node(o+1).type)}function Bm(n,e){let t=n.resolve(e),r=t.index();return jS(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function jS(n,e){return!!(n&&e&&!n.isLeaf&&n.canAppend(e))}function Vm(n,e,t=e,r=k.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),o=n.resolve(t);return KS(i,o,r)?new qc(e,t,r):new qS(i,o,r).fit()}function KS(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}let qS=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=v.empty;for(let i=0;i<=e.depth;i++){let o=e.node(i);this.frontier.push({type:o.type,match:o.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=v.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let u=this.findFittable();u?this.placeNodes(u):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let a=new k(o,s,l);return e>-1?new dl(r.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||r.pos!=this.$to.pos?new qc(r.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),o.type.spec.isolating&&i<=r){e=r;break}t=o.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=wa(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:u}=this.frontier[l],c,f=null;if(t==1&&(s?u.matchType(s.type)||(f=u.fillBefore(v.from(s),!1)):o&&a.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:f};if(t==2&&s&&(c=u.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:c};if(o&&u.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=wa(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new k(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=wa(e,t);if(i.childCount<=1&&t>0){let o=e.size-t<=t+i.size;this.unplaced=new k(Ei(e,t-1,1),t-1,o?t-1:r)}else this.unplaced=new k(Ei(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:o}){for(;this.depth>t;)this.closeFrontierNode();if(o)for(let m=0;m1||a==0||m.content.size)&&(f=w,c.push(Jm(m.mark(d.allowedMarks(m.marks)),u==1?a:0,u==l.childCount?p:-1)))}let h=u==l.childCount;h||(p=-1),this.placed=Oi(this.placed,t,v.from(c)),this.frontier[t].match=f,h&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,w=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],o=t=0;l--){let{match:a,type:u}=this.frontier[l],c=ka(e,l,u,a,!0);if(!c||c.childCount)continue e}return{depth:t,fit:s,move:o?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Oi(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Oi(this.placed,this.depth,v.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(v.empty,!0);t.childCount&&(this.placed=Oi(this.placed,this.frontier.length,t))}};function Ei(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Ei(n.firstChild.content,e-1,t)))}function Oi(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Oi(n.lastChild.content,e-1,t)))}function wa(n,e){for(let t=0;t1&&(r=r.replaceChild(0,Jm(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(v.empty,!0)))),n.copy(r)}function ka(n,e,t,r,i){let o=n.node(e),s=i?n.indexAfter(e):n.index(e);if(s==o.childCount&&!t.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!QS(t,o.content,s)?l:null}function QS(n,e,t){for(let r=t;r0}get deletedBefore(){return(this.delInfo&(Um|$s))>0}get deletedAfter(){return(this.delInfo&(Hm|$s))>0}get deletedAcross(){return(this.delInfo&$s)>0}},Hr=class yr{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&yr.empty)return yr.empty}recover(e){let t=0,r=Id(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],f=a+u;if(e<=f){let d=u?e==a?-1:e==f?1:t:t,p=a+i+(d<0?0:c);if(r)return p;let h=e==(t<0?a:f)?null:GS(l/3,e-a),m=e==a?Hm:e==f?Um:$s;return(t<0?e!=a:e!=f)&&(m|=jm),new ku(p,m,h)}i+=c-u}return r?e+i:new ku(e+i,0,null)}touches(e,t){let r=0,i=Id(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new Bs;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;ro&&a!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return Le.fromReplace(e,this.from,this.to,o)}invert(){return new Uo(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new Ti(t.pos,r.pos,this.mark)}merge(e){return e instanceof Ti&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Ti(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Ti(t.from,t.to,e.markFromJSON(t.mark))}};je.jsonID("addMark",Gc);let Uo=class Ri extends je{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new k(Yc(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return Le.fromReplace(e,this.from,this.to,r)}invert(){return new Gc(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new Ri(t.pos,r.pos,this.mark)}merge(e){return e instanceof Ri&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Ri(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Ri(t.from,t.to,e.markFromJSON(t.mark))}};je.jsonID("removeMark",Uo);let Xc=class Ai extends je{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Le.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return Le.fromReplace(e,this.pos,this.pos+1,new k(v.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new Vs(t.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Vs(t.from,t.to,t.gapFrom,t.gapTo,k.fromJSON(e,t.slice),t.insert,!!t.structure)}};je.jsonID("replaceAround",ur);function xu(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function ew(n,e,t,r){let i=[],o=[],s,l;n.doc.nodesBetween(e,t,(a,u,c)=>{if(!a.isInline)return;let f=a.marks;if(!r.isInSet(f)&&c.type.allowsMarkType(r.type)){let d=Math.max(u,e),p=Math.min(u+a.nodeSize,t),h=r.addToSet(f);for(let m=0;mn.step(a)),o.forEach(a=>n.step(a))}function tw(n,e,t,r){let i=[],o=0;n.doc.nodesBetween(e,t,(s,l)=>{if(!s.isInline)return;o++;let a=null;if(r instanceof Wo){let u=s.marks,c;for(;c=r.isInSet(u);)(a||(a=[])).push(c),u=c.removeFromSet(u)}else r?r.isInSet(s.marks)&&(a=[r]):a=s.marks;if(a&&a.length){let u=Math.min(l+s.nodeSize,t);for(let c=0;cn.step(new Uo(s.from,s.to,s.style)))}function nw(n,e,t,r=t.contentMatch){let i=n.doc.nodeAt(e),o=[],s=e+1;for(let l=0;l=0;l--)n.step(o[l])}function rw(n,e,t){let{$from:r,$to:i,depth:o}=e,s=r.before(o+1),l=i.after(o+1),a=s,u=l,c=v.empty,f=0;for(let h=o,m=!1;h>t;h--)m||r.index(h)>0?(m=!0,c=v.from(r.node(h).copy(c)),f++):a--;let d=v.empty,p=0;for(let h=o,m=!1;h>t;h--)m||i.after(h+1)=0;s--){if(r.size){let l=t[s].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=v.from(t[s].type.create(t[s].attrs,r))}let i=e.start,o=e.end;n.step(new ur(i,o,i,o,new k(r,0,0),t.length,!0))}function ow(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=n.steps.length;n.doc.nodesBetween(e,t,(s,l)=>{if(s.isTextblock&&!s.hasMarkup(r,i)&&sw(n.doc,n.mapping.slice(o).map(l),r)){n.clearIncompatible(n.mapping.slice(o).map(l,1),r);let a=n.mapping.slice(o),u=a.map(l,1),c=a.map(l+s.nodeSize,1);return n.step(new ur(u,c,u+1,c-1,new k(v.from(r.create(i,null,s.marks)),0,0),1,!0)),!1}})}function sw(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function lw(n,e,t,r,i){let o=n.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");t||(t=o.type);let s=t.create(r,null,i||o.marks);if(o.isLeaf)return n.replaceWith(e,e+o.nodeSize,s);if(!t.validContent(o.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new ur(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new k(v.from(s),0,0),1,!0))}function aw(n,e,t=1,r){let i=n.doc.resolve(e),o=v.empty,s=v.empty;for(let l=i.depth,a=i.depth-t,u=t-1;l>a;l--,u--){o=v.from(i.node(l).copy(o));let c=r&&r[u];s=v.from(c?c.type.create(c.attrs,s):i.node(l).copy(s))}n.step(new Dn(e,e,new k(o.append(s),t,t),!0))}function uw(n,e,t){let r=new Dn(e-t,e+t,k.empty,!0);n.step(r)}function cw(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let o=r.index(i);if(r.node(i).canReplaceWith(o,o,t))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,t))return r.after(i+1);if(o0;i--)this.placed=v.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let u=this.findFittable();u?this.placeNodes(u):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let a=new k(o,s,l);return e>-1?new ur(r.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||r.pos!=this.$to.pos?new Dn(r.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),o.type.spec.isolating&&i<=r){e=r;break}t=o.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=xa(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:u}=this.frontier[l],c,f=null;if(t==1&&(s?u.matchType(s.type)||(f=u.fillBefore(v.from(s),!1)):o&&a.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:f};if(t==2&&s&&(c=u.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:c};if(o&&u.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=xa(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new k(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=xa(e,t);if(i.childCount<=1&&t>0){let o=e.size-t<=t+i.size;this.unplaced=new k(bi(e,t-1,1),t-1,o?t-1:r)}else this.unplaced=new k(bi(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:o}){for(;this.depth>t;)this.closeFrontierNode();if(o)for(let m=0;m1||a==0||m.content.size)&&(f=w,c.push(qm(m.mark(d.allowedMarks(m.marks)),u==1?a:0,u==l.childCount?p:-1)))}let h=u==l.childCount;h||(p=-1),this.placed=Ii(this.placed,t,v.from(c)),this.frontier[t].match=f,h&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,w=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],o=t=0;l--){let{match:a,type:u}=this.frontier[l],c=Ca(e,l,u,a,!0);if(!c||c.childCount)continue e}return{depth:t,fit:s,move:o?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Ii(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Ii(this.placed,this.depth,v.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(v.empty,!0);t.childCount&&(this.placed=Ii(this.placed,this.frontier.length,t))}};function bi(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(bi(n.firstChild.content,e-1,t)))}function Ii(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Ii(n.lastChild.content,e-1,t)))}function xa(n,e){for(let t=0;t1&&(r=r.replaceChild(0,qm(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(v.empty,!0)))),n.copy(r)}function Ca(n,e,t,r,i){let o=n.node(e),s=i?n.indexAfter(e):n.index(e);if(s==o.childCount&&!t.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!hw(t,o.content,s)?l:null}function hw(n,e,t){for(let r=t;r0;d--,p--){let h=i.node(d).type.spec;if(h.defining||h.definingAsContext||h.isolating)break;s.indexOf(d)>-1?l=d:i.before(d)==p&&s.splice(1,0,-d)}let a=s.indexOf(l),u=[],c=r.openStart;for(let d=r.content,p=0;;p++){let h=d.firstChild;if(u.push(h),p==r.openStart)break;d=h.content}for(let d=c-1;d>=0;d--){let p=u[d].type,h=pw(p);if(h&&i.node(a).type!=p)c=d;else if(h||!p.isTextblock)break}for(let d=r.openStart;d>=0;d--){let p=(d+c+1)%(r.openStart+1),h=u[p];if(h)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>f));d--){let p=s[d];p<0||(e=i.before(p),t=o.after(p))}}function Qm(n,e,t,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(n).append(n);n=s.append(o.matchFragment(s).fillBefore(v.empty,!0))}return n}function gw(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=cw(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new k(v.from(r),0,0))}function yw(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),o=Ym(r,i);for(let s=0;s0&&(a||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&t>r.end(s)&&i.end(s)-t!=i.depth-s)return n.delete(r.before(s),t);n.delete(e,t)}function Ym(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let o=n.start(i);if(oe.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&t.push(i)}return t}let Gm=class Js extends je{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return Le.fail("No node at attribute step's position");let r=Object.create(null);for(let o in t.attrs)r[o]=t.attrs[o];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return Le.fromReplace(e,this.pos,this.pos+1,new k(v.from(i),0,t.isLeaf?0:1))}getMap(){return Hr.empty}invert(e){return new Js(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 Js(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new Js(t.pos,t.attr,t.value)}};je.jsonID("attr",Gm);let jr=class extends Error{};jr=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};jr.prototype=Object.create(Error.prototype);jr.prototype.constructor=jr;jr.prototype.name="TransformError";let Sw=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new ZS}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new jr(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=k.empty){let i=fw(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new k(v.from(r),0,0))}delete(e,t){return this.replace(e,t,k.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return mw(this,e,t,r),this}replaceRangeWith(e,t,r){return gw(this,e,t,r),this}deleteRange(e,t){return yw(this,e,t),this}lift(e,t){return rw(this,e,t),this}join(e,t=1){return uw(this,e,t),this}wrap(e,t){return iw(this,e,t),this}setBlockType(e,t=e,r,i=null){return ow(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return lw(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new Gm(e,t,r)),this}addNodeMark(e,t){return this.step(new Xc(e,t)),this}removeNodeMark(e,t){if(!(t instanceof W)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t=t.isInSet(r.marks),!t)return this}return this.step(new Zc(e,t)),this}split(e,t=1,r){return aw(this,e,t,r),this}addMark(e,t,r){return ew(this,e,t,r),this}removeMark(e,t,r){return tw(this,e,t,r),this}clearIncompatible(e,t,r){return nw(this,e,t,r),this}};const Na=Object.create(null);class P{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new Xm(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t=0;o--){let s=t<0?Sr(e.node(0),e.node(o),e.before(o+1),e.index(o),t,r):Sr(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,t,r);if(s)return s}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Xe(e.node(0))}static atStart(e){return Sr(e,e,0,0,1)||new Xe(e)}static atEnd(e){return Sr(e,e,e.content.size,e.childCount,-1)||new Xe(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=Na[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in Na)throw new RangeError("Duplicate use of selection JSON ID "+e);return Na[e]=t,t.prototype.jsonID=e,t}getBookmark(){return $.between(this.$anchor,this.$head).getBookmark()}}P.prototype.visible=!0;class Xm{constructor(e,t){this.$from=e,this.$to=t}}let zd=!1;function Pd(n){!zd&&!n.parent.inlineContent&&(zd=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}class $ extends P{constructor(e,t=e){Pd(e),Pd(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return P.near(r);let i=e.resolve(t.map(this.anchor));return new $(i.parent.inlineContent?i:r,r)}replace(e,t=k.empty){if(super.replace(e,t),t==k.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof $&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new jl(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new $(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let o=P.findFrom(t,r,!0)||P.findFrom(t,-r,!0);if(o)t=o.$head;else return P.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(P.findFrom(e,-r,!0)||P.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?s=0;s+=i){let l=e.child(s);if(l.isAtom){if(!o&&z.isSelectable(l))return z.create(n,t-(i<0?l.nodeSize:0))}else{let a=Sr(n,l,t+i,i<0?l.childCount:0,i,o);if(a)return a}t+=l.nodeSize*i}return null}function Fd(n,e,t){let r=n.steps.length-1;if(r{s==null&&(s=c)}),n.setSelection(P.near(n.doc.resolve(s),t))}const Ld=1,as=2,$d=4;class kw extends Sw{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|=as,this}ensureMarks(e){return W.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&as)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~as,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||W.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r??t,!e)return this.deleteRange(t,r);let o=this.storedMarks;if(!o){let s=this.doc.resolve(t);o=r==t?s.marks():s.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,o)),this.selection.empty||this.setSelection(P.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=$d,this}get scrolledIntoView(){return(this.updated&$d)>0}}function Bd(n,e){return!e||!n?n:n.bind(e)}class zi{constructor(e,t,r){this.name=e,this.init=Bd(t.init,r),this.apply=Bd(t.apply,r)}}const vw=[new zi("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new zi("selection",{init(n,e){return n.selection||P.atStart(e.doc)},apply(n){return n.selection}}),new zi("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new zi("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})];class Ma{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=vw.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new zi(r.key,r.spec.state,r))})}}class un{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],o=i.spec.state;o&&o.toJSON&&(t[r]=o.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Ma(e.schema,e.plugins),o=new un(i);return i.fields.forEach(s=>{if(s.name=="doc")o.doc=Dt.fromJSON(e.schema,t.doc);else if(s.name=="selection")o.selection=P.fromJSON(o.doc,t.selection);else if(s.name=="storedMarks")t.storedMarks&&(o.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let a=r[l],u=a.spec.state;if(a.key==s.name&&u&&u.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){o[s.name]=u.fromJSON.call(a,e,t[l],o);return}}o[s.name]=s.init(e,o)}}),o}}function Zm(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Zm(i,e,{})),t[r]=i}return t}class Lt{constructor(e){this.spec=e,this.props={},e.props&&Zm(e.props,this,this.props),this.key=e.key?e.key.key:eg("plugin")}getState(e){return e[this.key]}}const Ea=Object.create(null);function eg(n){return n in Ea?n+"$"+ ++Ea[n]:(Ea[n]=0,n+"$")}class Ho{constructor(e="key"){this.key=eg(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const tg=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function xw(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}const Cw=(n,e,t)=>{let r=xw(n,t);if(!r)return!1;let i=ng(r);if(!i){let s=r.blockRange(),l=s&&Qc(s);return l==null?!1:(e&&e(n.tr.lift(s,l).scrollIntoView()),!0)}let o=i.nodeBefore;if(!o.type.spec.isolating&&ig(n,i,e))return!0;if(r.parent.content.size==0&&(Kr(o,"end")||z.isSelectable(o))){let s=Vm(n.doc,r.before(),r.after(),k.empty);if(s&&s.slice.size{let{$head:r,empty:i}=n.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;o=ng(r)}let s=o&&o.nodeBefore;return!s||!z.isSelectable(s)?!1:(e&&e(n.tr.setSelection(z.create(n.doc,o.pos-s.nodeSize)).scrollIntoView()),!0)};function ng(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){if(n.index(e)>0)return n.doc.resolve(n.before(e+1));if(n.node(e).type.spec.isolating)break}return null}function Mw(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=Mw(n,t);if(!r)return!1;let i=rg(r);if(!i)return!1;let o=i.nodeAfter;if(ig(n,i,e))return!0;if(r.parent.content.size==0&&(Kr(o,"start")||z.isSelectable(o))){let s=Vm(n.doc,r.before(),r.after(),k.empty);if(s&&s.slice.size{let{$head:r,empty:i}=n.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):r.parentOffset=0;e--){let t=n.node(e);if(n.index(e)+1{let{$head:t,$anchor:r}=n.selection;return!t.parent.type.spec.code||!t.sameParent(r)?!1:(e&&e(n.tr.insertText(` -`).scrollIntoView()),!0)};function tf(n){for(let e=0;e{let{$head:t,$anchor:r}=n.selection;if(!t.parent.type.spec.code||!t.sameParent(r))return!1;let i=t.node(-1),o=t.indexAfter(-1),s=tf(i.contentMatchAt(o));if(!s||!i.canReplaceWith(o,o,s))return!1;if(e){let l=t.after(),a=n.tr.replaceWith(l,l,s.createAndFill());a.setSelection(P.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},Rw=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof Xe||r.parent.inlineContent||i.parent.inlineContent)return!1;let o=tf(i.parent.contentMatchAt(i.indexAfter()));if(!o||!o.isTextblock)return!1;if(e){let s=(!r.parentOffset&&i.index(){let{$cursor:t}=n.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let o=t.before();if(Fs(n.doc,o))return e&&e(n.tr.split(o).scrollIntoView()),!0}let r=t.blockRange(),i=r&&Qc(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function bw(n){return(e,t)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof z&&e.selection.node.isBlock)return!r.parentOffset||!Fs(e.doc,r.pos)?!1:(t&&t(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.parent.isBlock)return!1;if(t){let o=i.parentOffset==i.parent.content.size,s=e.tr;(e.selection instanceof $||e.selection instanceof Xe)&&s.deleteSelection();let l=r.depth==0?null:tf(r.node(-1).contentMatchAt(r.indexAfter(-1))),a=o&&l?[{type:l}]:void 0,u=Fs(s.doc,s.mapping.map(r.pos),1,a);if(!a&&!u&&Fs(s.doc,s.mapping.map(r.pos),1,l?[{type:l}]:void 0)&&(l&&(a=[{type:l}]),u=!0),u&&(s.split(s.mapping.map(r.pos),1,a),!o&&!r.parentOffset&&r.parent.type!=l)){let c=s.mapping.map(r.before()),f=s.doc.resolve(c);l&&r.node(-1).canReplaceWith(f.index(),f.index()+1,l)&&s.setNodeMarkup(s.mapping.map(r.before()),l)}t(s.scrollIntoView())}return!0}}const Iw=bw(),zw=(n,e)=>(e&&e(n.tr.setSelection(new Xe(n.doc))),!0);function Pw(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,o=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(o-1,o)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(o,o+1)||!(i.isTextblock||Bm(n.doc,e.pos))?!1:(t&&t(n.tr.clearIncompatible(e.pos,r.type,r.contentMatchAt(r.childCount)).join(e.pos).scrollIntoView()),!0)}function ig(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,o,s;if(r.type.spec.isolating||i.type.spec.isolating)return!1;if(Pw(n,e,t))return!0;let l=e.parent.canReplace(e.index(),e.index()+1);if(l&&(o=(s=r.contentMatchAt(r.childCount)).findWrapping(i.type))&&s.matchType(o[0]||i.type).validEnd){if(t){let f=e.pos+i.nodeSize,d=v.empty;for(let m=o.length-1;m>=0;m--)d=v.from(o[m].create(null,d));d=v.from(r.copy(d));let p=n.tr.step(new dl(e.pos-1,f,e.pos,f,new k(d,1,0),o.length,!0)),h=f+2*o.length;Bm(p.doc,h)&&p.join(h),t(p.scrollIntoView())}return!0}let a=P.findFrom(e,1),u=a&&a.$from.blockRange(a.$to),c=u&&Qc(u);if(c!=null&&c>=e.depth)return t&&t(n.tr.lift(u,c).scrollIntoView()),!0;if(l&&Kr(i,"start",!0)&&Kr(r,"end")){let f=r,d=[];for(;d.push(f),!f.isTextblock;)f=f.lastChild;let p=i,h=1;for(;!p.isTextblock;p=p.firstChild)h++;if(f.canReplace(f.childCount,f.childCount,p.content)){if(t){let m=v.empty;for(let g=d.length-1;g>=0;g--)m=v.from(d[g].copy(m));let w=n.tr.step(new dl(e.pos-d.length,e.pos+i.nodeSize,e.pos+h,e.pos+i.nodeSize-h,new k(m,d.length,0),0,!0));t(w.scrollIntoView())}return!0}}return!1}function og(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,o=i.depth;for(;i.node(o).isInline;){if(!o)return!1;o--}return i.node(o).isTextblock?(t&&t(e.tr.setSelection($.create(e.doc,n<0?i.start(o):i.end(o)))),!0):!1}}const Fw=og(-1),Lw=og(1);function $w(n,e,t){for(let r=0;r{if(s)return!1;s=l.inlineContent&&l.type.allowsMarkType(t)}),s)return!0}return!1}function Vd(n,e=null){return function(t,r){let{empty:i,$cursor:o,ranges:s}=t.selection;if(i&&!o||!$w(t.doc,s,n))return!1;if(r)if(o)n.isInSet(t.storedMarks||o.marks())?r(t.tr.removeStoredMark(n)):r(t.tr.addStoredMark(n.create(e)));else{let l=!1,a=t.tr;for(let u=0;!l&&u",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},_d=typeof navigator<"u"&&/Chrome\/(\d+)/.exec(navigator.userAgent),Jw=typeof navigator<"u"&&/Mac/.test(navigator.platform),_w=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),Ww=Jw||_d&&+_d[1]<57;for(var pe=0;pe<10;pe++)bt[48+pe]=bt[96+pe]=String(pe);for(var pe=1;pe<=24;pe++)bt[pe+111]="F"+pe;for(var pe=65;pe<=90;pe++)bt[pe]=String.fromCharCode(pe+32),hl[pe]=String.fromCharCode(pe);for(var Da in bt)hl.hasOwnProperty(Da)||(hl[Da]=bt[Da]);function rf(n){var e=Ww&&(n.ctrlKey||n.altKey||n.metaKey)||_w&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?hl:bt)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}const Uw=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function Hw(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,o,s;for(let l=0;l127)&&(o=bt[r.keyCode])&&o!=i){let l=e[Ta(o,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}const lg=65535,ag=Math.pow(2,16);function qw(n,e){return n+e*ag}function Wd(n){return n&lg}function Qw(n){return(n-(n&lg))/ag}const ug=1,cg=2,_s=4,fg=8;let Ud=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&fg)>0}get deletedBefore(){return(this.delInfo&(ug|_s))>0}get deletedAfter(){return(this.delInfo&(cg|_s))>0}get deletedAcross(){return(this.delInfo&_s)>0}},qr=class wr{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&wr.empty)return wr.empty}recover(e){let t=0,r=Wd(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],f=a+u;if(e<=f){let d=u?e==a?-1:e==f?1:t:t,p=a+i+(d<0?0:c);if(r)return p;let h=e==(t<0?a:f)?null:qw(l/3,e-a),m=e==a?cg:e==f?ug:_s;return(t<0?e!=a:e!=f)&&(m|=fg),new Ud(p,m,h)}i+=c-u}return r?e+i:new Ud(e+i,0,null)}touches(e,t){let r=0,i=Wd(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return $e.fromReplace(e,this.from,this.to,o)}invert(){return new hg(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new Fi(t.pos,r.pos,this.mark)}merge(e){return e instanceof Fi&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Fi(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Fi(t.from,t.to,e.markFromJSON(t.mark))}};Ke.jsonID("addMark",dg);let hg=class Li extends Ke{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new k(of(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return $e.fromReplace(e,this.from,this.to,r)}invert(){return new dg(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new Li(t.pos,r.pos,this.mark)}merge(e){return e instanceof Li&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Li(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Li(t.from,t.to,e.markFromJSON(t.mark))}};Ke.jsonID("removeMark",hg);let pg=class $i extends Ke{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return $e.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return $e.fromReplace(e,this.pos,this.pos+1,new k(v.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new Ws(t.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Ws(t.from,t.to,t.gapFrom,t.gapTo,k.fromJSON(e,t.slice),t.insert,!!t.structure)}};Ke.jsonID("replaceAround",Gw);function Nu(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function Xw(n,e,t){let r=n.resolve(e);if(!t.content.size)return e;let i=t.content;for(let o=0;o=0;s--){let l=s==r.depth?0:r.pos<=(r.start(s+1)+r.end(s+1))/2?-1:1,a=r.index(s)+(l>0?1:0),u=r.node(s),c=!1;if(o==1)c=u.canReplace(a,a,i);else{let f=u.contentMatchAt(a).findWrapping(i.firstChild.type);c=f&&u.canReplaceWith(a,a,f[0])}if(c)return l==0?r.pos:l<0?r.before(s+1):r.after(s+1)}return null}let Zw=class Us extends Ke{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return $e.fail("No node at attribute step's position");let r=Object.create(null);for(let o in t.attrs)r[o]=t.attrs[o];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return $e.fromReplace(e,this.pos,this.pos+1,new k(v.from(i),0,t.isLeaf?0:1))}getMap(){return qr.empty}invert(e){return new Us(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 Us(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new Us(t.pos,t.attr,t.value)}};Ke.jsonID("attr",Zw);let mo=class extends Error{};mo=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};mo.prototype=Object.create(Error.prototype);mo.prototype.constructor=mo;mo.prototype.name="TransformError";const me=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},go=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e};let Mu=null;const Vt=function(n,e,t){let r=Mu||(Mu=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},ek=function(){Mu=null},rr=function(n,e,t,r){return t&&(Hd(n,e,t,r,-1)||Hd(n,e,t,r,1))},tk=/^(img|br|input|textarea|hr)$/i;function Hd(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:st(n))){let o=n.parentNode;if(!o||o.nodeType!=1||jo(n)||tk.test(n.nodeName)||n.contentEditable=="false")return!1;e=me(n)+(i<0?0:1),n=o}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?st(n):0}else return!1}}function st(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function nk(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=st(n)}else if(n.parentNode&&!jo(n))e=me(n),n=n.parentNode;else return null}}function rk(n,e){for(;;){if(n.nodeType==3&&e2),rt=Qr||(It?/Mac/.test(It.platform):!1),lk=It?/Win/.test(It.platform):!1,St=/Android \d/.test(Tn),Ko=!!jd&&"webkitFontSmoothing"in jd.documentElement.style,ak=Ko?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function uk(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function $t(n,e){return typeof n=="number"?n:n[e]}function ck(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function Kd(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,o=n.dom.ownerDocument;for(let s=t||n.dom;s;s=go(s)){if(s.nodeType!=1)continue;let l=s,a=l==o.body,u=a?uk(o):ck(l),c=0,f=0;if(e.topu.bottom-$t(r,"bottom")&&(f=e.bottom-e.top>u.bottom-u.top?e.top+$t(i,"top")-u.top:e.bottom-u.bottom+$t(i,"bottom")),e.leftu.right-$t(r,"right")&&(c=e.right-u.right+$t(i,"right")),c||f)if(a)o.defaultView.scrollBy(c,f);else{let d=l.scrollLeft,p=l.scrollTop;f&&(l.scrollTop+=f),c&&(l.scrollLeft+=c);let h=l.scrollLeft-d,m=l.scrollTop-p;e={left:e.left-h,top:e.top-m,right:e.right-h,bottom:e.bottom-m}}if(a||/^(fixed|sticky)$/.test(getComputedStyle(s).position))break}}function fk(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let o=(e.left+e.right)/2,s=t+1;s=t-20){r=l,i=a.top;break}}return{refDOM:r,refTop:i,stack:Sg(n.dom)}}function Sg(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=go(r));return e}function dk({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;wg(t,r==0?0:r-e)}function wg(n,e){for(let t=0;t=l){s=Math.max(h.bottom,s),l=Math.min(h.top,l);let m=h.left>e.left?h.left-e.left:h.right=(h.left+h.right)/2?1:0));continue}}else h.top>e.top&&!a&&h.left<=e.left&&h.right>=e.left&&(a=c,u={left:Math.max(h.left,Math.min(h.right,e.left)),top:h.top});!t&&(e.left>=h.right&&e.top>=h.top||e.left>=h.left&&e.top>=h.bottom)&&(o=f+1)}}return!t&&a&&(t=a,i=u,r=0),t&&t.nodeType==3?pk(t,i):!t||r&&t.nodeType==1?{node:n,offset:o}:kg(t,i)}function pk(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i=(o.left+o.right)/2?1:0)}}return{node:n,offset:0}}function sf(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function mk(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(s.left+s.right)/2?1:-1}return n.docView.posFromDOM(r,i,o)}function yk(n,e,t,r){let i=-1;for(let o=e,s=!1;o!=n.dom;){let l=n.docView.nearestDesc(o,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)){let a=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&(!s&&a.left>r.left||a.top>r.top?i=l.posBefore:(!s&&a.right-1?i:n.docView.posFromDOM(e,t,-1)}function vg(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let u;Ko&&i&&r.nodeType==1&&(u=r.childNodes[i-1]).nodeType==1&&u.contentEditable=="false"&&u.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=yk(n,r,i,e))}l==null&&(l=gk(n,s,e));let a=n.docView.nearestDesc(s,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function qd(n){return n.top=0&&i==r.nodeValue.length?(a--,c=1):t<0?a--:u++,hi(en(Vt(r,a,u),c),c<0)}if(!n.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&i&&(t<0||i==st(r))){let a=r.childNodes[i-1];if(a.nodeType==1)return Aa(a.getBoundingClientRect(),!1)}if(o==null&&i=0)}if(o==null&&i&&(t<0||i==st(r))){let a=r.childNodes[i-1],u=a.nodeType==3?Vt(a,st(a)-(s?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(u)return hi(en(u,1),!1)}if(o==null&&i=0)}function hi(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function Aa(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function Cg(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function kk(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Cg(n,e,()=>{let{node:o}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(o,!0);if(!l)break;if(l.node.isBlock){o=l.contentDOM||l.dom;break}o=l.dom.parentNode}let s=xg(n,i.pos,1);for(let l=o.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=Vt(l,0,l.nodeValue.length).getClientRects();else continue;for(let u=0;uc.top+1&&(t=="up"?s.top-c.top>(c.bottom-s.top)*2:c.bottom-s.bottom>(s.bottom-c.top)*2))return!1}}return!0})}const vk=/[\u0590-\u08ac]/;function xk(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,l=n.domSelection();return l?!vk.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?o:s:Cg(n,e,()=>{let{focusNode:a,focusOffset:u,anchorNode:c,anchorOffset:f}=n.domSelectionRange(),d=l.caretBidiLevel;l.modify("move",t,"character");let p=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:h,focusOffset:m}=n.domSelectionRange(),w=h&&!p.contains(h.nodeType==1?h:h.parentNode)||a==h&&u==m;try{l.collapse(c,f),a&&(a!=c||u!=f)&&l.extend&&l.extend(a,u)}catch{}return d!=null&&(l.caretBidiLevel=d),w}):r.pos==r.start()||r.pos==r.end()}let Qd=null,Yd=null,Gd=!1;function Ck(n,e,t){return Qd==e&&Yd==t?Gd:(Qd=e,Yd=t,Gd=t=="up"||t=="down"?kk(n,e,t):xk(n,e,t))}const ut=0,Xd=1,Hn=2,zt=3;let qo=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=ut,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tme(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let o=this.getDesc(i),s;if(o&&(!t||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let o=this.getDesc(i);if(o)return o.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||s instanceof Dg){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof Ng&&o.side>=0;r--);if(t<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&t&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,t):{node:this.contentDOM,offset:o?me(o.dom)+1:0}}else{let o,s=!0;for(;o=r=c&&t<=u-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,c);e=s;for(let f=l;f>0;f--){let d=this.children[f-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=me(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(u>t||l==this.children.length-1)){t=u;for(let c=l+1;cp&&st){let p=l;l=a,a=p}let d=document.createRange();d.setEnd(a.node,a.offset),d.setStart(l.node,l.offset),u.removeAllRanges(),u.addRange(d)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let r=0,i=0;i=r:er){let l=r+o.border,a=s-o.border;if(e>=l&&t<=a){this.dirty=e==r||t==s?Hn:Xd,e==l&&t==a&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=zt:o.markDirty(e-l,t-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?Hn:zt}r=s}this.dirty=Hn}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?Hn:Xd;t.dirty{if(!o)return i;if(o.parent)return o.parent.posBeforeChild(o)})),!t.type.spec.raw){if(s.nodeType!=1){let l=document.createElement("span");l.appendChild(s),s=l}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=t,this.widget=t,o=this}matchesWidget(e){return this.dirty==ut&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}},Nk=class extends qo{constructor(e,t,r,i){super(e,[],t,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}},pl=class Tu extends qo{constructor(e,t,r,i){super(e,[],r,i),this.mark=t}static create(e,t,r,i){let o=i.nodeViews[t.type.name],s=o&&o(t,i,r);return(!s||!s.dom)&&(s=ci.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new Tu(e,t,s.dom,s.contentDOM||s.dom)}parseRule(){return this.dirty&zt||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=zt&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=ut){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(o=bu(o,0,e,r));for(let l=0;l{if(!a)return s;if(a.parent)return a.parent.posBeforeChild(a)},r,i),c=u&&u.dom,f=u&&u.contentDOM;if(t.isText){if(!c)c=document.createTextNode(t.text);else if(c.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else c||({dom:c,contentDOM:f}=ci.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!f&&!t.isText&&c.nodeName!="BR"&&(c.hasAttribute("contenteditable")||(c.contentEditable="false"),t.type.spec.draggable&&(c.draggable=!0));let d=c;return c=Ag(c,r,t),u?a=new Mk(e,t,r,i,c,f||null,d,u,o,s+1):t.isText?new Eg(e,t,r,i,c,d,o):new Mg(e,t,r,i,c,f||null,d,o,s+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>v.empty)}return e}matchesNode(e,t,r){return this.dirty==ut&&e.eq(this.node)&&Au(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let r=this.node.inlineContent,i=t,o=e.composing?this.localCompositionInfo(e,t):null,s=o&&o.pos>-1?o:null,l=o&&o.pos<0,a=new Ok(this,s&&s.node,e);Rk(this.node,this.innerDeco,(u,c,f)=>{u.spec.marks?a.syncToMarks(u.spec.marks,r,e):u.type.side>=0&&!f&&a.syncToMarks(c==this.node.childCount?W.none:this.node.child(c).marks,r,e),a.placeWidget(u,e,i)},(u,c,f,d)=>{a.syncToMarks(u.marks,r,e);let p;a.findNodeMatch(u,c,f,d)||l&&e.state.selection.from>i&&e.state.selection.to-1&&a.updateNodeAt(u,c,f,p,e)||a.updateNextNode(u,c,f,e,d,i)||a.addNode(u,c,f,e,i),i+=u.nodeSize}),a.syncToMarks([],r,e),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==Hn)&&(s&&this.protectLocalComposition(e,s),Tg(this.contentDOM,this.children,e),Qr&&Ak(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof $)||rt+this.node.content.size)return null;let o=e.input.compositionNode;if(!o||!this.dom.contains(o.parentNode))return null;if(this.node.inlineContent){let s=o.nodeValue,l=bk(this.node.content,s,r-t,i-t);return l<0?null:{node:o,pos:l,text:s}}else return{node:o,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let o=t;for(;o.parentNode!=this.contentDOM;o=o.parentNode){for(;o.previousSibling;)o.parentNode.removeChild(o.previousSibling);for(;o.nextSibling;)o.parentNode.removeChild(o.nextSibling);o.pmViewDesc&&(o.pmViewDesc=void 0)}let s=new Nk(this,o,t,i);e.input.compositionNodes.push(s),this.children=bu(this.children,r,r+i.length,e,s)}update(e,t,r,i){return this.dirty==zt||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,r,i),!0)}updateInner(e,t,r,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=ut}updateOuterDeco(e){if(Au(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Rg(this.dom,this.nodeDOM,Ru(this.outerDeco,this.node,t),Ru(e,this.node,t)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}};function Zd(n,e,t,r,i){Ag(r,e,n);let o=new Pr(void 0,n,e,t,r,r,r,i,0);return o.contentDOM&&o.updateChildren(i,0),o}let Eg=class Og extends Pr{constructor(e,t,r,i,o,s,l){super(e,t,r,i,o,null,s,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,i){return this.dirty==zt||this.dirty!=ut&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=ut||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=ut,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,r){let i=this.node.cut(e,t),o=document.createTextNode(i.text);return new Og(this.parent,i,this.outerDeco,this.innerDeco,o,o,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=zt)}get domAtom(){return!1}isText(e){return this.node.text==e}},Dg=class extends qo{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==ut&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}};class Mk extends Pr{constructor(e,t,r,i,o,s,l,a,u,c){super(e,t,r,i,o,s,l,u,c),this.spec=a}update(e,t,r,i){if(this.dirty==zt)return!1;if(this.spec.update){let o=this.spec.update(e,t,r);return o&&this.updateInner(e,t,r,i),o}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,r,i){this.spec.setSelection?this.spec.setSelection(e,t,r):super.setSelection(e,t,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}function Tg(n,e,t){let r=n.firstChild,i=!1;for(let o=0;o>1,s=Math.min(o,e.length);for(;i-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let a=pl.create(this.top,e[o],t,r);this.top.children.splice(this.index,0,a),this.top=a,this.changed=!0}this.index=0,o++}}findNodeMatch(e,t,r,i){let o=-1,s;if(i>=this.preMatch.index&&(s=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&s.matchesNode(e,t,r))o=this.top.children.indexOf(s,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let u=t.children[r-1];if(u instanceof pl)t=u,r=u.children.length;else{l=u,r--;break}}else{if(t==e)break e;r=t.parent.children.indexOf(t),t=t.parent}let a=l.node;if(a){if(a!=n.child(i-1))break;--i,o.set(l,i),s.push(l)}}return{index:i,matched:o,matches:s.reverse()}}function Tk(n,e){return n.type.side-e.type.side}function Rk(n,e,t,r){let i=e.locals(n),o=0;if(i.length==0){for(let u=0;uo;)l.push(i[s++]);let h=o+d.nodeSize;if(d.isText){let w=h;s!w.inline):l.slice();r(d,m,e.forChild(o,d),p),o=h}}function Ak(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function bk(n,e,t,r){for(let i=0,o=0;i=t){if(o>=r&&a.slice(r-e.length-l,r-l)==e)return r-e.length;let u=l=0&&u+e.length+l>=t)return l+u;if(t==r&&a.length>=r+e.length-l&&a.slice(r-l,r-l+e.length)==e)return r}}return-1}function bu(n,e,t,r,i){let o=[];for(let s=0,l=0;s=t||c<=e?o.push(a):(ut&&o.push(a.slice(t-u,a.size,r)))}return o}function lf(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),o=i&&i.size==0,s=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(s<0)return null;let l=r.resolve(s),a,u;if(Kl(t)){for(a=l;i&&!i.node;)i=i.parent;let c=i.node;if(i&&c.isAtom&&z.isSelectable(c)&&i.parent&&!(c.isInline&&ik(t.focusNode,t.focusOffset,i.dom))){let f=i.posBefore;u=new z(s==f?l:r.resolve(f))}}else{let c=n.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(c<0)return null;a=r.resolve(c)}if(!u){let c=e=="pointer"||n.state.selection.head{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!bg(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function zk(n){let e=n.domSelection(),t=document.createRange();if(!e)return;let r=n.cursorWrapper.dom,i=r.nodeName=="IMG";i?t.setStart(r.parentNode,me(r)+1):t.setStart(r,0),t.collapse(!0),e.removeAllRanges(),e.addRange(t),!i&&!n.state.selection.visible&&Je&&mn<=11&&(r.disabled=!0,r.disabled=!1)}function Ig(n,e){if(e instanceof z){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(ih(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else ih(n)}function ih(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function af(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||$.between(e,t,r)}function oh(n){return n.editable&&!n.hasFocus()?!1:zg(n)}function zg(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function Pk(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return rr(e.node,e.offset,t.anchorNode,t.anchorOffset)}function Iu(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),o=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return o&&P.findFrom(o,e)}function tn(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function sh(n,e,t){let r=n.state.selection;if(r instanceof $)if(t.indexOf("s")>-1){let{$head:i}=r,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!o||o.isText||!o.isLeaf)return!1;let s=n.state.doc.resolve(i.pos+o.nodeSize*(e<0?-1:1));return tn(n,new $(r.$anchor,s))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=Iu(n.state,e);return i&&i instanceof z?tn(n,i):!1}else if(!(rt&&t.indexOf("m")>-1)){let i=r.$head,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,s;if(!o||o.isText)return!1;let l=e<0?i.pos-o.nodeSize:i.pos;return o.isAtom||(s=n.docView.descAt(l))&&!s.contentDOM?z.isSelectable(o)?tn(n,new z(e<0?n.state.doc.resolve(i.pos-o.nodeSize):i)):Ko?tn(n,new $(n.state.doc.resolve(e<0?l:l+o.nodeSize))):!1:!1}}else return!1;else{if(r instanceof z&&r.node.isInline)return tn(n,new $(e>0?r.$to:r.$from));{let i=Iu(n.state,e);return i?tn(n,i):!1}}}function ml(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Xi(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function pr(n,e){return e<0?Fk(n):Lk(n)}function Fk(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,o,s=!1;for(xt&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(Xi(l,-1))i=t,o=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(Pg(t))break;{let l=t.previousSibling;for(;l&&Xi(l,-1);)i=t.parentNode,o=me(l),l=l.previousSibling;if(l)t=l,r=ml(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}s?zu(n,t,r):i&&zu(n,i,o)}function Lk(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=ml(t),o,s;for(;;)if(r{n.state==i&&jt(n)},50)}function lh(n,e){let t=n.state.doc.resolve(e);if(!(Ce||lk)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let o=n.coordsAtPos(e-1),s=(o.top+o.bottom)/2;if(s>i.top&&s1)return o.lefti.top&&s1)return o.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function ah(n,e,t){let r=n.state.selection;if(r instanceof $&&!r.empty||t.indexOf("s")>-1||rt&&t.indexOf("m")>-1)return!1;let{$from:i,$to:o}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let s=Iu(n.state,e);if(s&&s instanceof z)return tn(n,s)}if(!i.parent.inlineContent){let s=e<0?i:o,l=r instanceof Xe?P.near(s,e):P.findFrom(s,e);return l?tn(n,l):!1}return!1}function uh(n,e){if(!(n.state.selection instanceof $))return!0;let{$head:t,$anchor:r,empty:i}=n.state.selection;if(!t.sameParent(r))return!0;if(!i)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let o=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(o&&!o.isText){let s=n.state.tr;return e<0?s.delete(t.pos-o.nodeSize,t.pos):s.delete(t.pos,t.pos+o.nodeSize),n.dispatch(s),!0}return!1}function ch(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function Vk(n){if(!Re||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;ch(n,r,"true"),setTimeout(()=>ch(n,r,"false"),20)}return!1}function Jk(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function _k(n,e){let t=e.keyCode,r=Jk(e);if(t==8||rt&&t==72&&r=="c")return uh(n,-1)||pr(n,-1);if(t==46&&!e.shiftKey||rt&&t==68&&r=="c")return uh(n,1)||pr(n,1);if(t==13||t==27)return!0;if(t==37||rt&&t==66&&r=="c"){let i=t==37?lh(n,n.state.selection.from)=="ltr"?-1:1:-1;return sh(n,i,r)||pr(n,i)}else if(t==39||rt&&t==70&&r=="c"){let i=t==39?lh(n,n.state.selection.from)=="ltr"?1:-1:1;return sh(n,i,r)||pr(n,i)}else{if(t==38||rt&&t==80&&r=="c")return ah(n,-1,r)||pr(n,-1);if(t==40||rt&&t==78&&r=="c")return Vk(n)||ah(n,1,r)||pr(n,1);if(r==(rt?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Fg(n,e){n.someProp("transformCopied",p=>{e=p(e,n)});let t=[],{content:r,openStart:i,openEnd:o}=e;for(;i>1&&o>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,o--;let p=r.firstChild;t.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),r=p.content}let s=n.someProp("clipboardSerializer")||ci.fromSchema(n.state.schema),l=_g(),a=l.createElement("div");a.appendChild(s.serializeFragment(r,{document:l}));let u=a.firstChild,c,f=0;for(;u&&u.nodeType==1&&(c=Jg[u.nodeName.toLowerCase()]);){for(let p=c.length-1;p>=0;p--){let h=l.createElement(c[p]);for(;a.firstChild;)h.appendChild(a.firstChild);a.appendChild(h),f++}u=a.firstChild}u&&u.nodeType==1&&u.setAttribute("data-pm-slice",`${i} ${o}${f?` -${f}`:""} ${JSON.stringify(t)}`);let d=n.someProp("clipboardTextSerializer",p=>p(e,n))||e.content.textBetween(0,e.content.size,` - -`);return{dom:a,text:d,slice:e}}function Lg(n,e,t,r,i){let o=i.parent.type.spec.code,s,l;if(!t&&!e)return null;let a=e&&(r||o||!t);if(a){if(n.someProp("transformPastedText",d=>{e=d(e,o||r,n)}),o)return e?new k(v.from(n.state.schema.text(e.replace(/\r\n?/g,` -`))),0,0):k.empty;let f=n.someProp("clipboardTextParser",d=>d(e,i,r,n));if(f)l=f;else{let d=i.marks(),{schema:p}=n.state,h=ci.fromSchema(p);s=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let w=s.appendChild(document.createElement("p"));m&&w.appendChild(h.serializeNode(p.text(m,d)))})}}else n.someProp("transformPastedHTML",f=>{t=f(t,n)}),s=jk(t),Ko&&Kk(s);let u=s&&s.querySelector("[data-pm-slice]"),c=u&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(u.getAttribute("data-pm-slice")||"");if(c&&c[3])for(let f=+c[3];f>0;f--){let d=s.firstChild;for(;d&&d.nodeType!=1;)d=d.nextSibling;if(!d)break;s=d}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||ho.fromSchema(n.state.schema)).parseSlice(s,{preserveWhitespace:!!(a||c),context:i,ruleFromNode(d){return d.nodeName=="BR"&&!d.nextSibling&&d.parentNode&&!Wk.test(d.parentNode.nodeName)?{ignore:!0}:null}})),c)l=qk(fh(l,+c[1],+c[2]),c[4]);else if(l=k.maxOpen(Uk(l.content,i),!0),l.openStart||l.openEnd){let f=0,d=0;for(let p=l.content.firstChild;f{l=f(l,n)}),l}const Wk=/^(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 Uk(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),o,s=[];if(n.forEach(l=>{if(!s)return;let a=i.findWrapping(l.type),u;if(!a)return s=null;if(u=s.length&&o.length&&Bg(a,o,l,s[s.length-1],0))s[s.length-1]=u;else{s.length&&(s[s.length-1]=Vg(s[s.length-1],o.length));let c=$g(l,a);s.push(c),i=i.matchType(c.type),o=a}}),s)return v.from(s)}return n}function $g(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,v.from(n));return n}function Bg(n,e,t,r,i){if(i1&&(o=0),i=t&&(l=e<0?s.contentMatchAt(0).fillBefore(l,o<=i).append(l):l.append(s.contentMatchAt(s.childCount).fillBefore(v.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,s.copy(l))}function fh(n,e,t){return et}).createHTML(n):n}function jk(n){let e=/^(\s*]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=_g().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&Jg[r[1].toLowerCase()])&&(n=i.map(o=>"<"+o+">").join("")+n+i.map(o=>"").reverse().join("")),t.innerHTML=Hk(n),i)for(let o=0;o=0;l-=2){let a=t.nodes[r[l]];if(!a||a.hasRequiredAttrs())break;i=v.from(a.create(r[l+1],i)),o++,s++}return new k(i,o,s)}const Ae={},be={},Qk={touchstart:!0,touchmove:!0};class Yk{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:""},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastAndroidDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function Gk(n){for(let e in Ae){let t=Ae[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{Zk(n,r)&&!uf(n,r)&&(n.editable||!(r.type in be))&&t(n,r)},Qk[e]?{passive:!0}:void 0)}Re&&n.dom.addEventListener("input",()=>null),Fu(n)}function cn(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function Xk(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function Fu(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>uf(n,r))})}function uf(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function Zk(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function ev(n,e){!uf(n,e)&&Ae[e.type]&&(n.editable||!(e.type in be))&&Ae[e.type](n,e)}be.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!Ug(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(St&&Ce&&t.keyCode==13)))if(n.domObserver.selectionChanged(n.domSelectionRange())?n.domObserver.flush():t.keyCode!=229&&n.domObserver.forceFlush(),Qr&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let r=Date.now();n.input.lastIOSEnter=r,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==r&&(n.someProp("handleKeyDown",i=>i(n,Wn(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||_k(n,t)?t.preventDefault():cn(n,"key")};be.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};be.keypress=(n,e)=>{let t=e;if(Ug(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||rt&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof $)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(t.charCode);!/[\r\n]/.test(i)&&!n.someProp("handleTextInput",o=>o(n,r.$from.pos,r.$to.pos,i))&&n.dispatch(n.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function ql(n){return{left:n.clientX,top:n.clientY}}function tv(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function cf(n,e,t,r,i){if(r==-1)return!1;let o=n.state.doc.resolve(r);for(let s=o.depth+1;s>0;s--)if(n.someProp(e,l=>s>o.depth?l(n,t,o.nodeAfter,o.before(s),i,!0):l(n,t,o.node(s),o.before(s),i,!1)))return!0;return!1}function Fr(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let r=n.state.tr.setSelection(e);r.setMeta("pointer",!0),n.dispatch(r)}function nv(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&z.isSelectable(r)?(Fr(n,new z(t)),!0):!1}function rv(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof z&&(r=t.node);let o=n.state.doc.resolve(e);for(let s=o.depth+1;s>0;s--){let l=s>o.depth?o.nodeAfter:o.node(s);if(z.isSelectable(l)){r&&t.$from.depth>0&&s>=t.$from.depth&&o.before(t.$from.depth+1)==t.$from.pos?i=o.before(t.$from.depth):i=o.before(s);break}}return i!=null?(Fr(n,z.create(n.state.doc,i)),!0):!1}function iv(n,e,t,r,i){return cf(n,"handleClickOn",e,t,r)||n.someProp("handleClick",o=>o(n,e,r))||(i?rv(n,t):nv(n,t))}function ov(n,e,t,r){return cf(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function sv(n,e,t,r){return cf(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||lv(n,t,r)}function lv(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(Fr(n,$.create(r,0,r.content.size)),!0):!1;let i=r.resolve(e);for(let o=i.depth+1;o>0;o--){let s=o>i.depth?i.nodeAfter:i.node(o),l=i.before(o);if(s.inlineContent)Fr(n,$.create(r,l+1,l+1+s.content.size));else if(z.isSelectable(s))Fr(n,z.create(r,l));else continue;return!0}}function ff(n){return gl(n)}const Wg=rt?"metaKey":"ctrlKey";Ae.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=ff(n),i=Date.now(),o="singleClick";i-n.input.lastClick.time<500&&tv(t,n.input.lastClick)&&!t[Wg]&&(n.input.lastClick.type=="singleClick"?o="doubleClick":n.input.lastClick.type=="doubleClick"&&(o="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:o};let s=n.posAtCoords(ql(t));s&&(o=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new av(n,s,t,!!r)):(o=="doubleClick"?ov:sv)(n,s.pos,s.inside,t)?t.preventDefault():cn(n,"pointer"))};class av{constructor(e,t,r,i){this.view=e,this.pos=t,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[Wg],this.allowDefault=r.shiftKey;let o,s;if(t.inside>-1)o=e.state.doc.nodeAt(t.inside),s=t.inside;else{let c=e.state.doc.resolve(t.pos);o=c.parent,s=c.depth?c.before():0}const l=i?null:r.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a&&a.dom.nodeType==1?a.dom:null;let{selection:u}=e.state;(r.button==0&&o.type.spec.draggable&&o.type.spec.selectable!==!1||u instanceof z&&u.from<=s&&u.to>s)&&(this.mightDrag={node:o,pos:s,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&xt&&!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)),cn(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(()=>jt(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(ql(e))),this.updateAllowDefault(e),this.allowDefault||!t?cn(this.view,"pointer"):iv(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||Re&&this.mightDrag&&!this.mightDrag.node.isAtom||Ce&&!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)?(Fr(this.view,P.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):cn(this.view,"pointer")}move(e){this.updateAllowDefault(e),cn(this.view,"pointer"),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}}Ae.touchstart=n=>{n.input.lastTouch=Date.now(),ff(n),cn(n,"pointer")};Ae.touchmove=n=>{n.input.lastTouch=Date.now(),cn(n,"pointer")};Ae.contextmenu=n=>ff(n);function Ug(n,e){return n.composing?!0:Re&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}const uv=St?5e3:-1;be.compositionstart=be.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof $&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))n.markCursor=n.state.storedMarks||t.marks(),gl(n,!0),n.markCursor=null;else if(gl(n,!e.selection.empty),xt&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let i=r.focusNode,o=r.focusOffset;i&&i.nodeType==1&&o!=0;){let s=o<0?i.lastChild:i.childNodes[o-1];if(!s)break;if(s.nodeType==3){let l=n.domSelection();l&&l.collapse(s,s.nodeValue.length);break}else i=s,o=-1}}n.input.composing=!0}Hg(n,uv)};be.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionNode=null,n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,Hg(n,20))};function Hg(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>gl(n),e))}function jg(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=fv());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function cv(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=nk(e.focusNode,e.focusOffset),r=rk(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,o=n.domObserver.lastChangedTextNode;if(t==o||r==o)return o;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let s=t.pmViewDesc;if(!(!s||!s.isText(t.nodeValue)))return r}}return t||r}function fv(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function gl(n,e=!1){if(!(St&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),jg(n),e||n.docView&&n.docView.dirty){let t=lf(n);return t&&!t.eq(n.state.selection)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!n.state.selection.empty?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function dv(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),n.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}const yo=Je&&mn<15||Qr&&ak<604;Ae.copy=be.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let o=yo?null:t.clipboardData,s=r.content(),{dom:l,text:a}=Fg(n,s);o?(t.preventDefault(),o.clearData(),o.setData("text/html",l.innerHTML),o.setData("text/plain",a)):dv(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function hv(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function pv(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,r=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),r.parentNode&&r.parentNode.removeChild(r),t?So(n,r.value,null,i,e):So(n,r.textContent,r.innerHTML,i,e)},50)}function So(n,e,t,r,i){let o=Lg(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",a=>a(n,i,o||k.empty)))return!0;if(!o)return!1;let s=hv(o),l=s?n.state.tr.replaceSelectionWith(s,r):n.state.tr.replaceSelection(o);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Kg(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}be.paste=(n,e)=>{let t=e;if(n.composing&&!St)return;let r=yo?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&So(n,Kg(r),r.getData("text/html"),i,t)?t.preventDefault():pv(n,t)};class qg{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}}const Qg=rt?"altKey":"ctrlKey";Ae.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=n.state.selection,o=i.empty?null:n.posAtCoords(ql(t)),s;if(!(o&&o.pos>=i.from&&o.pos<=(i instanceof z?i.to-1:i.to))){if(r&&r.mightDrag)s=z.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let f=n.docView.nearestDesc(t.target,!0);f&&f.node.type.spec.draggable&&f!=n.docView&&(s=z.create(n.state.doc,f.posBefore))}}let l=(s||n.state.selection).content(),{dom:a,text:u,slice:c}=Fg(n,l);(!t.dataTransfer.files.length||!Ce||yg>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(yo?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",yo||t.dataTransfer.setData("text/plain",u),n.dragging=new qg(c,!t[Qg],s)};Ae.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};be.dragover=be.dragenter=(n,e)=>e.preventDefault();be.drop=(n,e)=>{let t=e,r=n.dragging;if(n.dragging=null,!t.dataTransfer)return;let i=n.posAtCoords(ql(t));if(!i)return;let o=n.state.doc.resolve(i.pos),s=r&&r.slice;s?n.someProp("transformPasted",h=>{s=h(s,n)}):s=Lg(n,Kg(t.dataTransfer),yo?null:t.dataTransfer.getData("text/html"),!1,o);let l=!!(r&&!t[Qg]);if(n.someProp("handleDrop",h=>h(n,t,s||k.empty,l))){t.preventDefault();return}if(!s)return;t.preventDefault();let a=s?Xw(n.state.doc,o.pos,s):o.pos;a==null&&(a=o.pos);let u=n.state.tr;if(l){let{node:h}=r;h?h.replace(u):u.deleteSelection()}let c=u.mapping.map(a),f=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,d=u.doc;if(f?u.replaceRangeWith(c,c,s.content.firstChild):u.replaceRange(c,c,s),u.doc.eq(d))return;let p=u.doc.resolve(c);if(f&&z.isSelectable(s.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(s.content.firstChild))u.setSelection(new z(p));else{let h=u.mapping.map(a);u.mapping.maps[u.mapping.maps.length-1].forEach((m,w,g,y)=>h=y),u.setSelection(af(n,p,u.doc.resolve(h)))}n.focus(),n.dispatch(u.setMeta("uiEvent","drop"))};Ae.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&jt(n)},20))};Ae.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)};Ae.beforeinput=(n,e)=>{if(Ce&&St&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:r}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=r||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",o=>o(n,Wn(8,"Backspace")))))return;let{$cursor:i}=n.state.selection;i&&i.pos>0&&n.dispatch(n.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let n in be)Ae[n]=be[n];function wo(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}class yl{constructor(e,t){this.toDOM=e,this.spec=t||Xn,this.side=this.spec.side||0}map(e,t,r,i){let{pos:o,deleted:s}=e.mapResult(t.from+i,this.side<0?-1:1);return s?null:new ge(o-r,o-r,this)}valid(){return!0}eq(e){return this==e||e instanceof yl&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&wo(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class gn{constructor(e,t){this.attrs=e,this.spec=t||Xn}map(e,t,r,i){let o=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,s=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return o>=s?null:new ge(o,s,this)}valid(e,t){return t.from=e&&(!o||o(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let s=0;se){let l=this.children[s]+1;this.children[s+2].findInner(e-l,t-l,r,i+l,o)}}map(e,t,r){return this==ve||e.maps.length==0?this:this.mapInner(e,t,0,0,r||Xn)}mapInner(e,t,r,i,o){let s;for(let l=0;l{let u=a+r,c;if(c=Xg(t,l,u)){for(i||(i=this.children.slice());ol&&f.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let o=e+1,s=o+t.content.size;for(let l=0;lo&&a.type instanceof gn){let u=Math.max(o,a.from)-o,c=Math.min(s,a.to)-o;ui.map(e,t,Xn));return vr.from(r)}forChild(e,t){if(t.isLeaf)return _.empty;let r=[];for(let i=0;it instanceof _)?e:e.reduce((t,r)=>t.concat(r instanceof _?r:r.members),[]))}}forEachSet(e){for(let t=0;t{let w=m-h-(p-d);for(let g=0;gy+c-f)continue;let S=l[g]+c-f;p>=S?l[g+1]=d<=S?-2:-1:d>=c&&w&&(l[g]+=w,l[g+1]+=w)}f+=w}),c=t.maps[u].map(c,-1)}let a=!1;for(let u=0;u=r.content.size){a=!0;continue}let d=t.map(n[u+1]+o,-1),p=d-i,{index:h,offset:m}=r.content.findIndex(f),w=r.maybeChild(h);if(w&&m==f&&m+w.nodeSize==p){let g=l[u+2].mapInner(t,w,c+1,n[u]+o+1,s);g!=ve?(l[u]=f,l[u+1]=p,l[u+2]=g):(l[u+1]=-2,a=!0)}else a=!0}if(a){let u=gv(l,n,e,t,i,o,s),c=Sl(u,r,0,s);e=c.local;for(let f=0;ft&&s.to{let u=Xg(n,l,a+t);if(u){o=!0;let c=Sl(u,l,t+a+1,r);c!=ve&&i.push(a,a+l.nodeSize,c)}});let s=Gg(o?Zg(n):n,-t).sort(Zn);for(let l=0;l0;)e++;n.splice(e,0,t)}function Ia(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=ve&&e.push(r)}),n.cursorWrapper&&e.push(_.create(n.state.doc,[n.cursorWrapper.deco])),Yg.from(e)}const yv={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Sv=Je&&mn<=11;let wv=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}};class kv{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new wv,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),Sv&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,yv)),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(oh(this.view)){if(this.suppressingSelectionUpdates)return jt(this.view);if(Je&&mn<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&rr(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,r;for(let o=e.focusNode;o;o=go(o))t.add(o);for(let o=e.anchorNode;o;o=go(o))if(t.has(o)){r=o;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}selectionChanged(e){return!this.suppressingSelectionUpdates&&!this.currentSelection.eq(e)&&oh(this.view)&&!this.ignoreSelectionChange(e)}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let r=e.domSelectionRange(),i=this.selectionChanged(r),o=-1,s=-1,l=!1,a=[];if(e.editable)for(let c=0;cf.nodeName=="BR");if(c.length==2){let[f,d]=c;f.parentNode&&f.parentNode.parentNode==d.parentNode?d.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let d of c){let p=d.parentNode;p&&p.nodeName=="LI"&&(!f||Cv(e,f)!=p)&&d.remove()}}}let u=null;o<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(o>-1&&(e.docView.markDirty(o,s),vv(e)),this.handleDOMChange(o,s,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||jt(e),this.currentSelection.set(r))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let c=0;ci;w--){let g=r.childNodes[w-1],y=g.pmViewDesc;if(g.nodeName=="BR"&&!y){o=w;break}if(!y||y.size)break}let f=n.state.doc,d=n.someProp("domParser")||ho.fromSchema(n.state.schema),p=f.resolve(s),h=null,m=d.parse(r,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:i,to:o,preserveWhitespace:p.parent.type.whitespace=="pre"?"full":!0,findPositions:u,ruleFromNode:Mv,context:p});if(u&&u[0].pos!=null){let w=u[0].pos,g=u[1]&&u[1].pos;g==null&&(g=w),h={anchor:w+s,head:g+s}}return{doc:m,sel:h,from:s,to:l}}function Mv(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(Re&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||Re&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}const Ev=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function Ov(n,e,t,r,i){let o=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let I=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,D=lf(n,I);if(D&&!n.state.selection.eq(D)){if(Ce&&St&&n.input.lastKeyCode===13&&Date.now()-100pt(n,Wn(13,"Enter"))))return;let H=n.state.tr.setSelection(D);I=="pointer"?H.setMeta("pointer",!0):I=="key"&&H.scrollIntoView(),o&&H.setMeta("composition",o),n.dispatch(H)}return}let s=n.state.doc.resolve(e),l=s.sharedDepth(t);e=s.before(l+1),t=n.state.doc.resolve(t).after(l+1);let a=n.state.selection,u=Nv(n,e,t),c=n.state.doc,f=c.slice(u.from,u.to),d,p;n.input.lastKeyCode===8&&Date.now()-100Date.now()-225||St)&&i.some(I=>I.nodeType==1&&!Ev.test(I.nodeName))&&(!h||h.endA>=h.endB)&&n.someProp("handleKeyDown",I=>I(n,Wn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!h)if(r&&a instanceof $&&!a.empty&&a.$head.sameParent(a.$anchor)&&!n.composing&&!(u.sel&&u.sel.anchor!=u.sel.head))h={start:a.from,endA:a.to,endB:a.to};else{if(u.sel){let I=yh(n,n.state.doc,u.sel);if(I&&!I.eq(n.state.selection)){let D=n.state.tr.setSelection(I);o&&D.setMeta("composition",o),n.dispatch(D)}}return}n.state.selection.fromn.state.selection.from&&h.start<=n.state.selection.from+2&&n.state.selection.from>=u.from?h.start=n.state.selection.from:h.endA=n.state.selection.to-2&&n.state.selection.to<=u.to&&(h.endB+=n.state.selection.to-h.endA,h.endA=n.state.selection.to)),Je&&mn<=11&&h.endB==h.start+1&&h.endA==h.start&&h.start>u.from&&u.doc.textBetween(h.start-u.from-1,h.start-u.from+1)=="  "&&(h.start--,h.endA--,h.endB--);let m=u.doc.resolveNoCache(h.start-u.from),w=u.doc.resolveNoCache(h.endB-u.from),g=c.resolve(h.start),y=m.sameParent(w)&&m.parent.inlineContent&&g.end()>=h.endA,S;if((Qr&&n.input.lastIOSEnter>Date.now()-225&&(!y||i.some(I=>I.nodeName=="DIV"||I.nodeName=="P"))||!y&&m.posI(n,Wn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>h.start&&Tv(c,h.start,h.endA,m,w)&&n.someProp("handleKeyDown",I=>I(n,Wn(8,"Backspace")))){St&&Ce&&n.domObserver.suppressSelectionUpdates();return}Ce&&St&&h.endB==h.start&&(n.input.lastAndroidDelete=Date.now()),St&&!y&&m.start()!=w.start()&&w.parentOffset==0&&m.depth==w.depth&&u.sel&&u.sel.anchor==u.sel.head&&u.sel.head==h.endA&&(h.endB-=2,w=u.doc.resolveNoCache(h.endB-u.from),setTimeout(()=>{n.someProp("handleKeyDown",function(I){return I(n,Wn(13,"Enter"))})},20));let x=h.start,M=h.endA,E,O,R;if(y){if(m.pos==w.pos)Je&&mn<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>jt(n),20)),E=n.state.tr.delete(x,M),O=c.resolve(h.start).marksAcross(c.resolve(h.endA));else if(h.endA==h.endB&&(R=Dv(m.parent.content.cut(m.parentOffset,w.parentOffset),g.parent.content.cut(g.parentOffset,h.endA-g.start()))))E=n.state.tr,R.type=="add"?E.addMark(x,M,R.mark):E.removeMark(x,M,R.mark);else if(m.parent.child(m.index()).isText&&m.index()==w.index()-(w.textOffset?0:1)){let I=m.parent.textBetween(m.parentOffset,w.parentOffset);if(n.someProp("handleTextInput",D=>D(n,x,M,I)))return;E=n.state.tr.insertText(I,x,M)}}if(E||(E=n.state.tr.replace(x,M,u.doc.slice(h.start-u.from,h.endB-u.from))),u.sel){let I=yh(n,E.doc,u.sel);I&&!(Ce&&St&&n.composing&&I.empty&&(h.start!=h.endB||n.input.lastAndroidDeletee.content.size?null:af(n,e.resolve(t.anchor),e.resolve(t.head))}function Dv(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,o=r,s,l,a;for(let c=0;cc.mark(l.addToSet(c.marks));else if(i.length==0&&o.length==1)l=o[0],s="remove",a=c=>c.mark(l.removeFromSet(c.marks));else return null;let u=[];for(let c=0;ct||za(s,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let o=n.node(r).maybeChild(n.indexAfter(r));for(;o&&!o.isLeaf;)o=o.firstChild,i++}return i}function Rv(n,e,t,r,i){let o=n.findDiffStart(e,t);if(o==null)return null;let{a:s,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let a=Math.max(0,o-Math.min(s,l));r-=s+a-o}if(s=s?o-r:0;o-=a,o&&o=l?o-r:0;o-=a,o&&o=56320&&e<=57343&&t>=55296&&t<=56319}class Av{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 Yk,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Ch),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):typeof e=="function"?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=vh(this),kh(this),this.nodeViews=xh(this),this.docView=Zd(this.state.doc,wh(this),Ia(this),this.dom,this),this.domObserver=new kv(this,(r,i,o,s)=>Ov(this,r,i,o,s)),this.domObserver.start(),Gk(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&&Fu(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Ch),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let r in this._props)t[r]=this._props[r];t.state=this.state;for(let r in e)t[r]=e[r];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var r;let i=this.state,o=!1,s=!1;e.storedMarks&&this.composing&&(jg(this),s=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let p=xh(this);Iv(p,this.nodeViews)&&(this.nodeViews=p,o=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&Fu(this),this.editable=vh(this),kh(this);let a=Ia(this),u=wh(this),c=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",f=o||!this.docView.matchesNode(e.doc,u,a);(f||!e.selection.eq(i.selection))&&(s=!0);let d=c=="preserve"&&s&&this.dom.style.overflowAnchor==null&&fk(this);if(s){this.domObserver.stop();let p=f&&(Je||Ce)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&bv(i.selection,e.selection);if(f){let h=Ce?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=cv(this)),(o||!this.docView.update(e.doc,u,a,this))&&(this.docView.updateOuterDeco(u),this.docView.destroy(),this.docView=Zd(e.doc,u,a,this.dom,this)),h&&!this.trackWrites&&(p=!0)}p||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Pk(this))?jt(this,p):(Ig(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),c=="reset"?this.dom.scrollTop=0:c=="to selection"?this.scrollToSelection():d&&dk(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof z){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&Kd(this,t.getBoundingClientRect(),e)}else Kd(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t0&&this.state.doc.nodeAt(o))==r.node&&(i=o)}this.dragging=new qg(e.slice,e.move,i<0?void 0:z.create(this.state.doc,i))}someProp(e,t){let r=this._props&&this._props[e],i;if(r!=null&&(i=t?t(r):r))return i;for(let s=0;st.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Sk(this,e)}coordsAtPos(e,t=1){return xg(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,r=-1){let i=this.docView.posFromDOM(e,t,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return Ck(this,t||this.state,e)}pasteHTML(e,t){return So(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return So(this,e,null,!0,t||new ClipboardEvent("paste"))}destroy(){this.docView&&(Xk(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Ia(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,ek())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return ev(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){let e=this.domSelection();return e?Re&&this.root.nodeType===11&&ok(this.dom.ownerDocument)==this.dom&&xv(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function wh(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let r in t)r=="class"?e.class+=" "+t[r]:r=="style"?e.style=(e.style?e.style+";":"")+t[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(t[r]))}),e.translate||(e.translate="no"),[ge.node(0,n.state.doc.content.size,e)]}function kh(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:ge.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function vh(n){return!n.someProp("editable",e=>e(n.state)===!1)}function bv(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function xh(n){let e=Object.create(null);function t(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function Iv(n,e){let t=0,r=0;for(let i in n){if(n[i]!=e[i])return!0;t++}for(let i in e)r++;return t!=r}function Ch(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}class ee extends P{constructor(e){super(e,e)}map(e,t){let r=e.resolve(t.map(this.head));return ee.valid(r)?new ee(r):P.near(r)}content(){return k.empty}eq(e){return e instanceof ee&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new ee(e.resolve(t.pos))}getBookmark(){return new pf(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!zv(e)||!Pv(e))return!1;let r=t.type.spec.allowGapCursor;if(r!=null)return r;let i=t.contentMatchAt(e.index()).defaultType;return i&&i.isTextblock}static findGapCursorFrom(e,t,r=!1){e:for(;;){if(!r&&ee.valid(e))return e;let i=e.pos,o=null;for(let s=e.depth;;s--){let l=e.node(s);if(t>0?e.indexAfter(s)0){o=l.child(t>0?e.indexAfter(s):e.index(s)-1);break}else if(s==0)return null;i+=t;let a=e.doc.resolve(i);if(ee.valid(a))return a}for(;;){let s=t>0?o.firstChild:o.lastChild;if(!s){if(o.isAtom&&!o.isText&&!z.isSelectable(o)){e=e.doc.resolve(i+o.nodeSize*t),r=!1;continue e}break}o=s,i+=t;let l=e.doc.resolve(i);if(ee.valid(l))return l}return null}}}ee.prototype.visible=!1;ee.findFrom=ee.findGapCursorFrom;P.jsonID("gapcursor",ee);class pf{constructor(e){this.pos=e}map(e){return new pf(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return ee.valid(t)?new ee(t):P.near(t)}}function zv(n){for(let e=n.depth;e>=0;e--){let t=n.index(e),r=n.node(e);if(t==0){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(t-1);;i=i.lastChild){if(i.childCount==0&&!i.inlineContent||i.isAtom||i.type.spec.isolating)return!0;if(i.inlineContent)return!1}}return!0}function Pv(n){for(let e=n.depth;e>=0;e--){let t=n.indexAfter(e),r=n.node(e);if(t==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(t);;i=i.firstChild){if(i.childCount==0&&!i.inlineContent||i.isAtom||i.type.spec.isolating)return!0;if(i.inlineContent)return!1}}return!0}function Fv(){return new Lt({props:{decorations:Vv,createSelectionBetween(n,e,t){return e.pos==t.pos&&ee.valid(t)?new ee(t):null},handleClick:$v,handleKeyDown:Lv,handleDOMEvents:{beforeinput:Bv}}})}const Lv=Kw({ArrowLeft:us("horiz",-1),ArrowRight:us("horiz",1),ArrowUp:us("vert",-1),ArrowDown:us("vert",1)});function us(n,e){const t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,i,o){let s=r.selection,l=e>0?s.$to:s.$from,a=s.empty;if(s instanceof $){if(!o.endOfTextblock(t)||l.depth==0)return!1;a=!1,l=r.doc.resolve(e>0?l.after():l.before())}let u=ee.findGapCursorFrom(l,e,a);return u?(i&&i(r.tr.setSelection(new ee(u))),!0):!1}}function $v(n,e,t){if(!n||!n.editable)return!1;let r=n.state.doc.resolve(e);if(!ee.valid(r))return!1;let i=n.posAtCoords({left:t.clientX,top:t.clientY});return i&&i.inside>-1&&z.isSelectable(n.state.doc.nodeAt(i.inside))?!1:(n.dispatch(n.state.tr.setSelection(new ee(r))),!0)}function Bv(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof ee))return!1;let{$from:t}=n.state.selection,r=t.parent.contentMatchAt(t.index()).findWrapping(n.state.schema.nodes.text);if(!r)return!1;let i=v.empty;for(let s=r.length-1;s>=0;s--)i=v.from(r[s].createAndFill(null,i));let o=n.state.tr.replace(t.pos,t.pos,new k(i,0,0));return o.setSelection($.near(o.doc.resolve(t.pos+1))),n.dispatch(o),!1}function Vv(n){if(!(n.selection instanceof ee))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",_.create(n.doc,[ge.widget(n.selection.head,e,{key:"gapcursor"})])}const ey=65535,ty=Math.pow(2,16);function Jv(n,e){return n+e*ty}function Nh(n){return n&ey}function _v(n){return(n-(n&ey))/ty}const ny=1,ry=2,Hs=4,iy=8;let Mh=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&iy)>0}get deletedBefore(){return(this.delInfo&(ny|Hs))>0}get deletedAfter(){return(this.delInfo&(ry|Hs))>0}get deletedAcross(){return(this.delInfo&Hs)>0}},Yr=class xr{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&xr.empty)return xr.empty}recover(e){let t=0,r=Nh(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],f=a+u;if(e<=f){let d=u?e==a?-1:e==f?1:t:t,p=a+i+(d<0?0:c);if(r)return p;let h=e==(t<0?a:f)?null:Jv(l/3,e-a),m=e==a?ry:e==f?ny:Hs;return(t<0?e!=a:e!=f)&&(m|=iy),new Mh(p,m,h)}i+=c-u}return r?e+i:new Mh(e+i,0,null)}touches(e,t){let r=0,i=Nh(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return Be.fromReplace(e,this.from,this.to,o)}invert(){return new sy(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new Vi(t.pos,r.pos,this.mark)}merge(e){return e instanceof Vi&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Vi(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Vi(t.from,t.to,e.markFromJSON(t.mark))}};qe.jsonID("addMark",oy);let sy=class Ji extends qe{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new k(mf(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return Be.fromReplace(e,this.from,this.to,r)}invert(){return new oy(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new Ji(t.pos,r.pos,this.mark)}merge(e){return e instanceof Ji&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Ji(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Ji(t.from,t.to,e.markFromJSON(t.mark))}};qe.jsonID("removeMark",sy);let ly=class _i extends qe{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Be.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return Be.fromReplace(e,this.pos,this.pos+1,new k(v.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new js(t.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new js(t.from,t.to,t.gapFrom,t.gapTo,k.fromJSON(e,t.slice),t.insert,!!t.structure)}};qe.jsonID("replaceAround",Uv);function $u(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function Hv(n,e,t=null,r=n){let i=jv(n,e),o=i&&Kv(r,e);return o?i.map(Eh).concat({type:e,attrs:t}).concat(o.map(Eh)):null}function Eh(n){return{type:n,attrs:null}}function jv(n,e){let{parent:t,startIndex:r,endIndex:i}=n,o=t.contentMatchAt(r).findWrapping(e);if(!o)return null;let s=o.length?o[0]:e;return t.canReplaceWith(r,i,s)?o:null}function Kv(n,e){let{parent:t,startIndex:r,endIndex:i}=n,o=t.child(r),s=e.contentMatch.findWrapping(o.type);if(!s)return null;let a=(s.length?s[s.length-1]:e).contentMatch;for(let u=r;a&&u0&&(o=t[0].slice(s-l,s)+o,r=i)}return e.tr.insertText(o,r,i)}}const Xv=500;function Zv({rules:n}){let e=new Lt({state:{init(){return null},apply(t,r){let i=t.getMeta(this);return i||(t.selectionSet||t.docChanged?null:r)}},props:{handleTextInput(t,r,i,o){return Oh(t,r,i,o,n,e)},handleDOMEvents:{compositionend:t=>{setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&Oh(t,r.pos,r.pos,"",n,e)})}}},isInputRules:!0});return e}function Oh(n,e,t,r,i,o){if(n.composing)return!1;let s=n.state,l=s.doc.resolve(e),a=l.parent.textBetween(Math.max(0,l.parentOffset-Xv),l.parentOffset,null,"")+r;for(let u=0;u{let a=t instanceof Function?t(o):t,u=i.tr.delete(s,l),c=u.doc.resolve(s),f=c.blockRange(),d=f&&Hv(f,e,a);if(!d)return null;u.wrap(f,d);let p=u.doc.resolve(s-1).nodeBefore;return p&&p.type==e&&qv(u.doc,s-1)&&!r&&u.join(s-1),u})}const tx=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function nx(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,o,s;for(let l=0;l127)&&(o=bt[r.keyCode])&&o!=i){let l=e[Fa(o,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}const sx=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function lx(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,o,s;for(let l=0;l127)&&(o=bt[r.keyCode])&&o!=i){let l=e[La(o,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}const uy=65535,cy=Math.pow(2,16);function cx(n,e){return n+e*cy}function Dh(n){return n&uy}function fx(n){return(n-(n&uy))/cy}const fy=1,dy=2,qs=4,hy=8;class Bu{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&hy)>0}get deletedBefore(){return(this.delInfo&(fy|qs))>0}get deletedAfter(){return(this.delInfo&(dy|qs))>0}get deletedAcross(){return(this.delInfo&qs)>0}}class Ye{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&Ye.empty)return Ye.empty}recover(e){let t=0,r=Dh(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],f=a+u;if(e<=f){let d=u?e==a?-1:e==f?1:t:t,p=a+i+(d<0?0:c);if(r)return p;let h=e==(t<0?a:f)?null:cx(l/3,e-a),m=e==a?dy:e==f?fy:qs;return(t<0?e!=a:e!=f)&&(m|=hy),new Bu(p,m,h)}i+=c-u}return r?e+i:new Bu(e+i,0,null)}touches(e,t){let r=0,i=Dh(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new Zi;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;ro&&a!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return oe.fromReplace(e,this.from,this.to,o)}invert(){return new Ot(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new fn(t.pos,r.pos,this.mark)}merge(e){return e instanceof fn&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new fn(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new fn(t.from,t.to,e.markFromJSON(t.mark))}}Ee.jsonID("addMark",fn);class Ot extends Ee{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new k(gf(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return oe.fromReplace(e,this.from,this.to,r)}invert(){return new fn(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new Ot(t.pos,r.pos,this.mark)}merge(e){return e instanceof Ot&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Ot(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Ot(t.from,t.to,e.markFromJSON(t.mark))}}Ee.jsonID("removeMark",Ot);class dn extends Ee{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return oe.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return oe.fromReplace(e,this.pos,this.pos+1,new k(v.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new Tt(t.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Tt(t.from,t.to,t.gapFrom,t.gapTo,k.fromJSON(e,t.slice),t.insert,!!t.structure)}}Ee.jsonID("replaceAround",Tt);function Vu(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function dx(n,e,t,r){let i=[],o=[],s,l;n.doc.nodesBetween(e,t,(a,u,c)=>{if(!a.isInline)return;let f=a.marks;if(!r.isInSet(f)&&c.type.allowsMarkType(r.type)){let d=Math.max(u,e),p=Math.min(u+a.nodeSize,t),h=r.addToSet(f);for(let m=0;mn.step(a)),o.forEach(a=>n.step(a))}function hx(n,e,t,r){let i=[],o=0;n.doc.nodesBetween(e,t,(s,l)=>{if(!s.isInline)return;o++;let a=null;if(r instanceof Wo){let u=s.marks,c;for(;c=r.isInSet(u);)(a||(a=[])).push(c),u=c.removeFromSet(u)}else r?r.isInSet(s.marks)&&(a=[r]):a=s.marks;if(a&&a.length){let u=Math.min(l+s.nodeSize,t);for(let c=0;cn.step(new Ot(s.from,s.to,s.style)))}function px(n,e,t,r=t.contentMatch){let i=n.doc.nodeAt(e),o=[],s=e+1;for(let l=0;l=0;l--)n.step(o[l])}function mx(n,e,t){let{$from:r,$to:i,depth:o}=e,s=r.before(o+1),l=i.after(o+1),a=s,u=l,c=v.empty,f=0;for(let h=o,m=!1;h>t;h--)m||r.index(h)>0?(m=!0,c=v.from(r.node(h).copy(c)),f++):a--;let d=v.empty,p=0;for(let h=o,m=!1;h>t;h--)m||i.after(h+1)=0;s--){if(r.size){let l=t[s].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=v.from(t[s].type.create(t[s].attrs,r))}let i=e.start,o=e.end;n.step(new Tt(i,o,i,o,new k(r,0,0),t.length,!0))}function yx(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=n.steps.length;n.doc.nodesBetween(e,t,(s,l)=>{if(s.isTextblock&&!s.hasMarkup(r,i)&&Sx(n.doc,n.mapping.slice(o).map(l),r)){n.clearIncompatible(n.mapping.slice(o).map(l,1),r);let a=n.mapping.slice(o),u=a.map(l,1),c=a.map(l+s.nodeSize,1);return n.step(new Tt(u,c,u+1,c-1,new k(v.from(r.create(i,null,s.marks)),0,0),1,!0)),!1}})}function Sx(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function wx(n,e,t,r,i){let o=n.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");t||(t=o.type);let s=t.create(r,null,i||o.marks);if(o.isLeaf)return n.replaceWith(e,e+o.nodeSize,s);if(!t.validContent(o.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new Tt(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new k(v.from(s),0,0),1,!0))}function kx(n,e,t=1,r){let i=n.doc.resolve(e),o=v.empty,s=v.empty;for(let l=i.depth,a=i.depth-t,u=t-1;l>a;l--,u--){o=v.from(i.node(l).copy(o));let c=r&&r[u];s=v.from(c?c.type.create(c.attrs,s):i.node(l).copy(s))}n.step(new De(e,e,new k(o.append(s),t,t),!0))}function vx(n,e,t){let r=new De(e-t,e+t,k.empty,!0);n.step(r)}function xx(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let o=r.index(i);if(r.node(i).canReplaceWith(o,o,t))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,t))return r.after(i+1);if(o0;i--)this.placed=v.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let u=this.findFittable();u?this.placeNodes(u):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let a=new k(o,s,l);return e>-1?new Tt(r.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||r.pos!=this.$to.pos?new De(r.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),o.type.spec.isolating&&i<=r){e=r;break}t=o.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=Ba(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:u}=this.frontier[l],c,f=null;if(t==1&&(s?u.matchType(s.type)||(f=u.fillBefore(v.from(s),!1)):o&&a.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:f};if(t==2&&s&&(c=u.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:c};if(o&&u.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Ba(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new k(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Ba(e,t);if(i.childCount<=1&&t>0){let o=e.size-t<=t+i.size;this.unplaced=new k(Wi(e,t-1,1),t-1,o?t-1:r)}else this.unplaced=new k(Wi(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:o}){for(;this.depth>t;)this.closeFrontierNode();if(o)for(let m=0;m1||a==0||m.content.size)&&(f=w,c.push(my(m.mark(d.allowedMarks(m.marks)),u==1?a:0,u==l.childCount?p:-1)))}let h=u==l.childCount;h||(p=-1),this.placed=Ui(this.placed,t,v.from(c)),this.frontier[t].match=f,h&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,w=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],o=t=0;l--){let{match:a,type:u}=this.frontier[l],c=Va(e,l,u,a,!0);if(!c||c.childCount)continue e}return{depth:t,fit:s,move:o?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Ui(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Ui(this.placed,this.depth,v.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(v.empty,!0);t.childCount&&(this.placed=Ui(this.placed,this.frontier.length,t))}}function Wi(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Wi(n.firstChild.content,e-1,t)))}function Ui(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Ui(n.lastChild.content,e-1,t)))}function Ba(n,e){for(let t=0;t1&&(r=r.replaceChild(0,my(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(v.empty,!0)))),n.copy(r)}function Va(n,e,t,r,i){let o=n.node(e),s=i?n.indexAfter(e):n.index(e);if(s==o.childCount&&!t.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!Mx(t,o.content,s)?l:null}function Mx(n,e,t){for(let r=t;r0;d--,p--){let h=i.node(d).type.spec;if(h.defining||h.definingAsContext||h.isolating)break;s.indexOf(d)>-1?l=d:i.before(d)==p&&s.splice(1,0,-d)}let a=s.indexOf(l),u=[],c=r.openStart;for(let d=r.content,p=0;;p++){let h=d.firstChild;if(u.push(h),p==r.openStart)break;d=h.content}for(let d=c-1;d>=0;d--){let p=u[d],h=Ex(p.type);if(h&&!p.sameMarkup(i.node(Math.abs(l)-1)))c=d;else if(h||!p.type.isTextblock)break}for(let d=r.openStart;d>=0;d--){let p=(d+c+1)%(r.openStart+1),h=u[p];if(h)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>f));d--){let p=s[d];p<0||(e=i.before(p),t=o.after(p))}}function gy(n,e,t,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(n).append(n);n=s.append(o.matchFragment(s).fillBefore(v.empty,!0))}return n}function Dx(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=xx(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new k(v.from(r),0,0))}function Tx(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),o=yy(r,i);for(let s=0;s0&&(a||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&t>r.end(s)&&i.end(s)-t!=i.depth-s)return n.delete(r.before(s),t);n.delete(e,t)}function yy(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let o=n.start(i);if(oe.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&t.push(i)}return t}class Lr extends Ee{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return oe.fail("No node at attribute step's position");let r=Object.create(null);for(let o in t.attrs)r[o]=t.attrs[o];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return oe.fromReplace(e,this.pos,this.pos+1,new k(v.from(i),0,t.isLeaf?0:1))}getMap(){return Ye.empty}invert(e){return new Lr(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 Lr(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new Lr(t.pos,t.attr,t.value)}}Ee.jsonID("attr",Lr);class vo extends Ee{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return oe.ok(r)}getMap(){return Ye.empty}invert(e){return new vo(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new vo(t.attr,t.value)}}Ee.jsonID("docAttr",vo);let Xr=class extends Error{};Xr=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Xr.prototype=Object.create(Error.prototype);Xr.prototype.constructor=Xr;Xr.prototype.name="TransformError";class Rx{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Zi}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Xr(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=k.empty){let i=Cx(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new k(v.from(r),0,0))}delete(e,t){return this.replace(e,t,k.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return Ox(this,e,t,r),this}replaceRangeWith(e,t,r){return Dx(this,e,t,r),this}deleteRange(e,t){return Tx(this,e,t),this}lift(e,t){return mx(this,e,t),this}join(e,t=1){return vx(this,e,t),this}wrap(e,t){return gx(this,e,t),this}setBlockType(e,t=e,r,i=null){return yx(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return wx(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new Lr(e,t,r)),this}setDocAttribute(e,t){return this.step(new vo(e,t)),this}addNodeMark(e,t){return this.step(new dn(e,t)),this}removeNodeMark(e,t){if(!(t instanceof W)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t=t.isInSet(r.marks),!t)return this}return this.step(new Gr(e,t)),this}split(e,t=1,r){return kx(this,e,t,r),this}addMark(e,t,r){return dx(this,e,t,r),this}removeMark(e,t,r){return hx(this,e,t,r),this}clearIncompatible(e,t,r){return px(this,e,t,r),this}}var Ju,_u;if(typeof WeakMap<"u"){let n=new WeakMap;Ju=e=>n.get(e),_u=(e,t)=>(n.set(e,t),t)}else{const n=[];let t=0;Ju=r=>{for(let i=0;i(t==10&&(t=0),n[t++]=r,n[t++]=i)}var re=class{constructor(n,e,t,r){this.width=n,this.height=e,this.map=t,this.problems=r}findCell(n){for(let e=0;e=t){(o||(o=[])).push({type:"overlong_rowspan",pos:c,n:g-S});break}const x=i+S*e;for(let M=0;Mr&&(o+=u.attrs.colspan)}}for(let s=0;s1&&(t=!0)}e==-1?e=o:e!=o&&(e=Math.max(e,o))}return e}function Ix(n,e,t){n.problems||(n.problems=[]);const r={};for(let i=0;iNumber(s)):null,i=Number(n.getAttribute("colspan")||1),o={colspan:i,rowspan:Number(n.getAttribute("rowspan")||1),colwidth:r&&r.length==i?r:null};for(const s in e){const l=e[s].getFromDOM,a=l&&l(n);a!=null&&(o[s]=a)}return o}function Rh(n,e){const t={};n.attrs.colspan!=1&&(t.colspan=n.attrs.colspan),n.attrs.rowspan!=1&&(t.rowspan=n.attrs.rowspan),n.attrs.colwidth&&(t["data-colwidth"]=n.attrs.colwidth.join(","));for(const r in e){const i=e[r].setDOMAttr;i&&i(n.attrs[r],t)}return t}function Px(n){const e=n.cellAttributes||{},t={colspan:{default:1},rowspan:{default:1},colwidth:{default:null}};for(const r in e)t[r]={default:e[r].default};return{table:{content:"table_row+",tableRole:"table",isolating:!0,group:n.tableGroup,parseDOM:[{tag:"table"}],toDOM(){return["table",["tbody",0]]}},table_row:{content:"(table_cell | table_header)*",tableRole:"row",parseDOM:[{tag:"tr"}],toDOM(){return["tr",0]}},table_cell:{content:n.cellContent,attrs:t,tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:r=>Th(r,e)}],toDOM(r){return["td",Rh(r,e),0]}},table_header:{content:n.cellContent,attrs:t,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>Th(r,e)}],toDOM(r){return["th",Rh(r,e),0]}}}}function Pt(n){let e=n.cached.tableNodeTypes;if(!e){e=n.cached.tableNodeTypes={};for(const t in n.nodes){const r=n.nodes[t],i=r.spec.tableRole;i&&(e[i]=r)}}return e}var sn=new Ho("selectingCells");function Qo(n){for(let e=n.depth-1;e>0;e--)if(n.node(e).type.spec.tableRole=="row")return n.node(0).resolve(n.before(e+1));return null}function yf(n){const e=n.selection.$head;for(let t=e.depth;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return!0;return!1}function Sy(n){const e=n.selection;if("$anchorCell"in e&&e.$anchorCell)return e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell;if("node"in e&&e.node&&e.node.type.spec.tableRole=="cell")return e.$anchor;const t=Qo(e.$head)||Fx(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function Fx(n){for(let e=n.nodeAfter,t=n.pos;e;e=e.firstChild,t++){const r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t)}for(let e=n.nodeBefore,t=n.pos;e;e=e.lastChild,t--){const r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t-e.nodeSize)}}function Wu(n){return n.parent.type.spec.tableRole=="row"&&!!n.nodeAfter}function Sf(n,e){return n.depth==e.depth&&n.pos>=e.start(-1)&&n.pos<=e.end(-1)}function wy(n,e,t){const r=n.node(-1),i=re.get(r),o=n.start(-1),s=i.nextCell(n.pos-o,e,t);return s==null?null:n.node(0).resolve(o+s)}function Zr(n,e,t=1){const r={...n,colspan:n.colspan-t};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,t),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}var ce=class Bt extends P{constructor(e,t=e){const r=e.node(-1),i=re.get(r),o=e.start(-1),s=i.rectBetween(e.pos-o,t.pos-o),l=e.node(0),a=i.cellsInRect(s).filter(c=>c!=t.pos-o);a.unshift(t.pos-o);const u=a.map(c=>{const f=r.nodeAt(c);if(!f)throw RangeError(`No cell with offset ${c} found`);const d=o+c+1;return new Xm(l.resolve(d),l.resolve(d+f.content.size))});super(u[0].$from,u[0].$to,u),this.$anchorCell=e,this.$headCell=t}map(e,t){const r=e.resolve(t.map(this.$anchorCell.pos)),i=e.resolve(t.map(this.$headCell.pos));if(Wu(r)&&Wu(i)&&Sf(r,i)){const o=this.$anchorCell.node(-1)!=r.node(-1);return o&&this.isRowSelection()?Bt.rowSelection(r,i):o&&this.isColSelection()?Bt.colSelection(r,i):new Bt(r,i)}return $.between(r,i)}content(){const e=this.$anchorCell.node(-1),t=re.get(e),r=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),o={},s=[];for(let a=i.top;a0||w>0){let g=h.attrs;if(m>0&&(g=Zr(g,0,m)),w>0&&(g=Zr(g,g.colspan-w,w)),p.lefti.bottom){const g={...h.attrs,rowspan:Math.min(p.bottom,i.bottom)-Math.max(p.top,i.top)};p.top0)return!1;const r=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(e,t=e){const r=e.node(-1),i=re.get(r),o=e.start(-1),s=i.findCell(e.pos-o),l=i.findCell(t.pos-o),a=e.node(0);return s.top<=l.top?(s.top>0&&(e=a.resolve(o+i.map[s.left])),l.bottom0&&(t=a.resolve(o+i.map[l.left])),s.bottom0)return!1;const s=i+this.$anchorCell.nodeAfter.attrs.colspan,l=o+this.$headCell.nodeAfter.attrs.colspan;return Math.max(s,l)==t.width}eq(e){return e instanceof Bt&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,t=e){const r=e.node(-1),i=re.get(r),o=e.start(-1),s=i.findCell(e.pos-o),l=i.findCell(t.pos-o),a=e.node(0);return s.left<=l.left?(s.left>0&&(e=a.resolve(o+i.map[s.top*i.width])),l.right0&&(t=a.resolve(o+i.map[l.top*i.width])),s.right{e.push(ge.node(r,r+t.nodeSize,{class:"selectedCell"}))}),_.create(n.doc,e)}function Bx({$from:n,$to:e}){if(n.pos==e.pos||n.pos=0&&!(n.after(i+1)=0&&!(e.before(o+1)>e.start(o));o--,r--);return t==r&&/row|table/.test(n.node(i).type.spec.tableRole)}function Vx({$from:n,$to:e}){let t,r;for(let i=n.depth;i>0;i--){const o=n.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){t=o;break}}for(let i=e.depth;i>0;i--){const o=e.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){r=o;break}}return t!==r&&e.parentOffset===0}function Jx(n,e,t){const r=(e||n).selection,i=(e||n).doc;let o,s;if(r instanceof z&&(s=r.node.type.spec.tableRole)){if(s=="cell"||s=="header_cell")o=ce.create(i,r.from);else if(s=="row"){const l=i.resolve(r.from+1);o=ce.rowSelection(l,l)}else if(!t){const l=re.get(r.node),a=r.from+1,u=a+l.map[l.width*l.height-1];o=ce.create(i,a+1,u)}}else r instanceof $&&Bx(r)?o=$.create(i,r.from):r instanceof $&&Vx(r)&&(o=$.create(i,r.$from.start(),r.$from.end()));return o&&(e||(e=n.tr)).setSelection(o),e}var _x=new Ho("fix-tables");function vy(n,e,t,r){const i=n.childCount,o=e.childCount;e:for(let s=0,l=0;s{i.type.spec.tableRole=="table"&&(t=Ux(n,i,o,t))};return e?e.doc!=n.doc&&vy(e.doc,n.doc,0,r):n.doc.descendants(r),t}function Ux(n,e,t,r){const i=re.get(e);if(!i.problems)return r;r||(r=n.tr);const o=[];for(let a=0;a0){let p="cell";c.firstChild&&(p=c.firstChild.type.spec.tableRole);const h=[];for(let w=0;w0&&r>0||e.child(0).type.spec.tableRole=="table");)t--,r--,e=e.child(0).content;const i=e.child(0),o=i.type.spec.tableRole,s=i.type.schema,l=[];if(o=="row")for(let a=0;a=0;s--){const{rowspan:l,colspan:a}=o.child(s).attrs;for(let u=i;u=e.length&&e.push(v.empty),t[i]r&&(d=d.type.createChecked(Zr(d.attrs,d.attrs.colspan,c+d.attrs.colspan-r),d.content)),u.push(d),c+=d.attrs.colspan;for(let p=1;pi&&(f=f.type.create({...f.attrs,rowspan:Math.max(1,i-f.attrs.rowspan)},f.content)),a.push(f)}o.push(v.from(a))}t=o,e=i}return{width:n,height:e,rows:t}}function qx(n,e,t,r,i,o,s){const l=n.doc.type.schema,a=Pt(l);let u,c;if(i>e.width)for(let f=0,d=0;fe.height){const f=[];for(let h=0,m=(e.height-1)*e.width;h=e.width?!1:t.nodeAt(e.map[m+h]).type==a.header_cell;f.push(w?c||(c=a.header_cell.createAndFill()):u||(u=a.cell.createAndFill()))}const d=a.row.create(null,v.from(f)),p=[];for(let h=e.height;h{if(!i)return!1;const o=t.selection;if(o instanceof ce)return Qs(t,r,P.near(o.$headCell,e));if(n!="horiz"&&!o.empty)return!1;const s=xy(i,n,e);if(s==null)return!1;if(n=="horiz")return Qs(t,r,P.near(t.doc.resolve(o.head+e),e));{const l=t.doc.resolve(s),a=wy(l,n,e);let u;return a?u=P.near(a,1):e<0?u=P.near(t.doc.resolve(l.before(-1)),-1):u=P.near(t.doc.resolve(l.after(-1)),1),Qs(t,r,u)}}}function fs(n,e){return(t,r,i)=>{if(!i)return!1;const o=t.selection;let s;if(o instanceof ce)s=o;else{const a=xy(i,n,e);if(a==null)return!1;s=new ce(t.doc.resolve(a))}const l=wy(s.$headCell,n,e);return l?Qs(t,r,new ce(s.$anchorCell,l)):!1}}function ds(n,e){const t=n.selection;if(!(t instanceof ce))return!1;if(e){const r=n.tr,i=Pt(n.schema).cell.createAndFill().content;t.forEachCell((o,s)=>{o.content.eq(i)||r.replace(r.mapping.map(s+1),r.mapping.map(s+o.nodeSize-1),new k(i,0,0))}),r.docChanged&&e(r)}return!0}function Yx(n,e){const t=n.state.doc,r=Qo(t.resolve(e));return r?(n.dispatch(n.state.tr.setSelection(new ce(r))),!0):!1}function Gx(n,e,t){if(!yf(n.state))return!1;let r=Hx(t);const i=n.state.selection;if(i instanceof ce){r||(r={width:1,height:1,rows:[v.from(Uu(Pt(n.state.schema).cell,t))]});const o=i.$anchorCell.node(-1),s=i.$anchorCell.start(-1),l=re.get(o).rectBetween(i.$anchorCell.pos-s,i.$headCell.pos-s);return r=Kx(r,l.right-l.left,l.bottom-l.top),Ih(n.state,n.dispatch,s,l,r),!0}else if(r){const o=Sy(n.state),s=o.start(-1);return Ih(n.state,n.dispatch,s,re.get(o.node(-1)).findCell(o.pos-s),r),!0}else return!1}function Xx(n,e){var t;if(e.ctrlKey||e.metaKey)return;const r=zh(n,e.target);let i;if(e.shiftKey&&n.state.selection instanceof ce)o(n.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=Qo(n.state.selection.$anchor))!=null&&((t=Ja(n,e))==null?void 0:t.pos)!=i.pos)o(i,e),e.preventDefault();else if(!r)return;function o(a,u){let c=Ja(n,u);const f=sn.getState(n.state)==null;if(!c||!Sf(a,c))if(f)c=a;else return;const d=new ce(a,c);if(f||!n.state.selection.eq(d)){const p=n.state.tr.setSelection(d);f&&p.setMeta(sn,a.pos),n.dispatch(p)}}function s(){n.root.removeEventListener("mouseup",s),n.root.removeEventListener("dragstart",s),n.root.removeEventListener("mousemove",l),sn.getState(n.state)!=null&&n.dispatch(n.state.tr.setMeta(sn,-1))}function l(a){const u=a,c=sn.getState(n.state);let f;if(c!=null)f=n.state.doc.resolve(c);else if(zh(n,u.target)!=r&&(f=Ja(n,e),!f))return s();f&&o(f,u)}n.root.addEventListener("mouseup",s),n.root.addEventListener("dragstart",s),n.root.addEventListener("mousemove",l)}function xy(n,e,t){if(!(n.state.selection instanceof $))return null;const{$head:r}=n.state.selection;for(let i=r.depth-1;i>=0;i--){const o=r.node(i);if((t<0?r.index(i):r.indexAfter(i))!=(t<0?0:o.childCount))return null;if(o.type.spec.tableRole=="cell"||o.type.spec.tableRole=="header_cell"){const l=r.before(i),a=e=="vert"?t>0?"down":"up":t>0?"right":"left";return n.endOfTextblock(a)?l:null}}return null}function zh(n,e){for(;e&&e!=n.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function Ja(n,e){const t=n.posAtCoords({left:e.clientX,top:e.clientY});return t&&t?Qo(n.state.doc.resolve(t.pos)):null}var Zx=class{constructor(n,e){this.node=n,this.cellMinWidth=e,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.colgroup=this.table.appendChild(document.createElement("colgroup")),Hu(n,this.colgroup,this.table,e),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(n){return n.type!=this.node.type?!1:(this.node=n,Hu(n,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(n){return n.type=="attributes"&&(n.target==this.table||this.colgroup.contains(n.target))}};function Hu(n,e,t,r,i,o){var s;let l=0,a=!0,u=e.firstChild;const c=n.firstChild;if(c){for(let f=0,d=0;fnew t(l,e,a),new tC(-1,!1)},apply(o,s){return s.apply(o)}},props:{attributes:o=>{const s=lt.getState(o);return s&&s.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(o,s)=>{nC(o,s,n,e,r)},mouseleave:o=>{rC(o)},mousedown:(o,s)=>{iC(o,s,e)}},decorations:o=>{const s=lt.getState(o);if(s&&s.activeHandle>-1)return cC(o,s.activeHandle)},nodeViews:{}}});return i}var tC=class Ys{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(e){const t=this,r=e.getMeta(lt);if(r&&r.setHandle!=null)return new Ys(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new Ys(t.activeHandle,r.setDragging);if(t.activeHandle>-1&&e.docChanged){let i=e.mapping.map(t.activeHandle,-1);return Wu(e.doc.resolve(i))||(i=-1),new Ys(i,t.dragging)}return t}};function nC(n,e,t,r,i){const o=lt.getState(n.state);if(o&&!o.dragging){const s=sC(e.target);let l=-1;if(s){const{left:a,right:u}=s.getBoundingClientRect();e.clientX-a<=t?l=Ph(n,e,"left",t):u-e.clientX<=t&&(l=Ph(n,e,"right",t))}if(l!=o.activeHandle){if(!i&&l!==-1){const a=n.state.doc.resolve(l),u=a.node(-1),c=re.get(u),f=a.start(-1);if(c.colCount(a.pos-f)+a.nodeAfter.attrs.colspan-1==c.width-1)return}Cy(n,l)}}}function rC(n){const e=lt.getState(n.state);e&&e.activeHandle>-1&&!e.dragging&&Cy(n,-1)}function iC(n,e,t){var r;const i=(r=n.dom.ownerDocument.defaultView)!=null?r:window,o=lt.getState(n.state);if(!o||o.activeHandle==-1||o.dragging)return!1;const s=n.state.doc.nodeAt(o.activeHandle),l=oC(n,o.activeHandle,s.attrs);n.dispatch(n.state.tr.setMeta(lt,{setDragging:{startX:e.clientX,startWidth:l}}));function a(c){i.removeEventListener("mouseup",a),i.removeEventListener("mousemove",u);const f=lt.getState(n.state);f!=null&&f.dragging&&(lC(n,f.activeHandle,Fh(f.dragging,c,t)),n.dispatch(n.state.tr.setMeta(lt,{setDragging:null})))}function u(c){if(!c.which)return a(c);const f=lt.getState(n.state);if(f&&f.dragging){const d=Fh(f.dragging,c,t);aC(n,f.activeHandle,d,t)}}return i.addEventListener("mouseup",a),i.addEventListener("mousemove",u),e.preventDefault(),!0}function oC(n,e,{colspan:t,colwidth:r}){const i=r&&r[r.length-1];if(i)return i;const o=n.domAtPos(e);let l=o.node.childNodes[o.offset].offsetWidth,a=t;if(r)for(let u=0;ui.table.nodeAt(a));for(let a=0;a{const h=p+o.tableStart,m=s.doc.nodeAt(h);m&&s.setNodeMarkup(h,d,m.attrs)}),r(s)}return!0}}wf("row",{useDeprecatedLogic:!0});wf("column",{useDeprecatedLogic:!0});wf("cell",{useDeprecatedLogic:!0});function dC({allowTableNodeSelection:n=!1}={}){return new Lt({key:sn,state:{init(){return null},apply(e,t){const r=e.getMeta(sn);if(r!=null)return r==-1?null:r;if(t==null||!e.docChanged)return t;const{deleted:i,pos:o}=e.mapping.mapResult(t);return i?null:o}},props:{decorations:$x,handleDOMEvents:{mousedown:Xx},createSelectionBetween(e){return sn.getState(e.state)!=null?e.state.selection:null},handleTripleClick:Yx,handleKeyDown:Qx,handlePaste:Gx},appendTransaction(e,t,r){return Jx(r,Wx(r,t),n)}})}var My={exports:{}},tt={},Ey={exports:{}},Oy={};/** - * @license React - * scheduler.production.min.js - * - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */(function(n){function e(A,F){var L=A.length;A.push(F);e:for(;0>>1,ae=A[te];if(0>>1;tei(pa,L))Fni(rs,pa)?(A[te]=rs,A[Fn]=L,te=Fn):(A[te]=pa,A[Pn]=L,te=Pn);else if(Fni(rs,L))A[te]=rs,A[Fn]=L,te=Fn;else break e}}return F}function i(A,F){var L=A.sortIndex-F.sortIndex;return L!==0?L:A.id-F.id}if(typeof performance=="object"&&typeof performance.now=="function"){var o=performance;n.unstable_now=function(){return o.now()}}else{var s=Date,l=s.now();n.unstable_now=function(){return s.now()-l}}var a=[],u=[],c=1,f=null,d=3,p=!1,h=!1,m=!1,w=typeof setTimeout=="function"?setTimeout:null,g=typeof clearTimeout=="function"?clearTimeout:null,y=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function S(A){for(var F=t(u);F!==null;){if(F.callback===null)r(u);else if(F.startTime<=A)r(u),F.sortIndex=F.expirationTime,e(a,F);else break;F=t(u)}}function x(A){if(m=!1,S(A),!h)if(t(a)!==null)h=!0,da(M);else{var F=t(u);F!==null&&ha(x,F.startTime-A)}}function M(A,F){h=!1,m&&(m=!1,g(R),R=-1),p=!0;var L=d;try{for(S(F),f=t(a);f!==null&&(!(f.expirationTime>F)||A&&!H());){var te=f.callback;if(typeof te=="function"){f.callback=null,d=f.priorityLevel;var ae=te(f.expirationTime<=F);F=n.unstable_now(),typeof ae=="function"?f.callback=ae:f===t(a)&&r(a),S(F)}else r(a);f=t(a)}if(f!==null)var ns=!0;else{var Pn=t(u);Pn!==null&&ha(x,Pn.startTime-F),ns=!1}return ns}finally{f=null,d=L,p=!1}}var E=!1,O=null,R=-1,I=5,D=-1;function H(){return!(n.unstable_now()-DA||125te?(A.sortIndex=L,e(u,A),t(a)===null&&A===t(u)&&(m?(g(R),R=-1):m=!0,ha(x,L-te))):(A.sortIndex=ae,e(a,A),h||p||(h=!0,da(M))),A},n.unstable_shouldYield=H,n.unstable_wrapCallback=function(A){var F=d;return function(){var L=d;d=F;try{return A.apply(this,arguments)}finally{d=L}}}})(Oy);Ey.exports=Oy;var hC=Ey.exports;/** - * @license React - * react-dom.production.min.js - * - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */var Dy=C,et=hC;function N(n){for(var e="https://reactjs.org/docs/error-decoder.html?invariant="+n,t=1;t"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),ju=Object.prototype.hasOwnProperty,pC=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,$h={},Bh={};function mC(n){return ju.call(Bh,n)?!0:ju.call($h,n)?!1:pC.test(n)?Bh[n]=!0:($h[n]=!0,!1)}function gC(n,e,t,r){if(t!==null&&t.type===0)return!1;switch(typeof e){case"function":case"symbol":return!0;case"boolean":return r?!1:t!==null?!t.acceptsBooleans:(n=n.toLowerCase().slice(0,5),n!=="data-"&&n!=="aria-");default:return!1}}function yC(n,e,t,r){if(e===null||typeof e>"u"||gC(n,e,t,r))return!0;if(r)return!1;if(t!==null)switch(t.type){case 3:return!e;case 4:return e===!1;case 5:return isNaN(e);case 6:return isNaN(e)||1>e}return!1}function ze(n,e,t,r,i,o,s){this.acceptsBooleans=e===2||e===3||e===4,this.attributeName=r,this.attributeNamespace=i,this.mustUseProperty=t,this.propertyName=n,this.type=e,this.sanitizeURL=o,this.removeEmptyString=s}var Se={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(n){Se[n]=new ze(n,0,!1,n,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(n){var e=n[0];Se[e]=new ze(e,1,!1,n[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(n){Se[n]=new ze(n,2,!1,n.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(n){Se[n]=new ze(n,2,!1,n,null,!1,!1)});"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(n){Se[n]=new ze(n,3,!1,n.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(n){Se[n]=new ze(n,3,!0,n,null,!1,!1)});["capture","download"].forEach(function(n){Se[n]=new ze(n,4,!1,n,null,!1,!1)});["cols","rows","size","span"].forEach(function(n){Se[n]=new ze(n,6,!1,n,null,!1,!1)});["rowSpan","start"].forEach(function(n){Se[n]=new ze(n,5,!1,n.toLowerCase(),null,!1,!1)});var kf=/[\-:]([a-z])/g;function vf(n){return n[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(n){var e=n.replace(kf,vf);Se[e]=new ze(e,1,!1,n,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(n){var e=n.replace(kf,vf);Se[e]=new ze(e,1,!1,n,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(n){var e=n.replace(kf,vf);Se[e]=new ze(e,1,!1,n,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(n){Se[n]=new ze(n,1,!1,n.toLowerCase(),null,!1,!1)});Se.xlinkHref=new ze("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(n){Se[n]=new ze(n,1,!1,n.toLowerCase(),null,!0,!0)});function xf(n,e,t,r){var i=Se.hasOwnProperty(e)?Se[e]:null;(i!==null?i.type!==0:r||!(2l||i[s]!==o[l]){var a=` -`+i[s].replace(" at new "," at ");return n.displayName&&a.includes("")&&(a=a.replace("",n.displayName)),a}while(1<=s&&0<=l);break}}}finally{Wa=!1,Error.prepareStackTrace=t}return(n=n?n.displayName||n.name:"")?Hi(n):""}function SC(n){switch(n.tag){case 5:return Hi(n.type);case 16:return Hi("Lazy");case 13:return Hi("Suspense");case 19:return Hi("SuspenseList");case 0:case 2:case 15:return n=Ua(n.type,!1),n;case 11:return n=Ua(n.type.render,!1),n;case 1:return n=Ua(n.type,!0),n;default:return""}}function Yu(n){if(n==null)return null;if(typeof n=="function")return n.displayName||n.name||null;if(typeof n=="string")return n;switch(n){case Nr:return"Fragment";case Cr:return"Portal";case Ku:return"Profiler";case Cf:return"StrictMode";case qu:return"Suspense";case Qu:return"SuspenseList"}if(typeof n=="object")switch(n.$$typeof){case Ay:return(n.displayName||"Context")+".Consumer";case Ry:return(n._context.displayName||"Context")+".Provider";case Nf:var e=n.render;return n=n.displayName,n||(n=e.displayName||e.name||"",n=n!==""?"ForwardRef("+n+")":"ForwardRef"),n;case Mf:return e=n.displayName||null,e!==null?e:Yu(n.type)||"Memo";case nn:e=n._payload,n=n._init;try{return Yu(n(e))}catch{}}return null}function wC(n){var e=n.type;switch(n.tag){case 24:return"Cache";case 9:return(e.displayName||"Context")+".Consumer";case 10:return(e._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return n=e.render,n=n.displayName||n.name||"",e.displayName||(n!==""?"ForwardRef("+n+")":"ForwardRef");case 7:return"Fragment";case 5:return e;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return Yu(e);case 8:return e===Cf?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e}return null}function En(n){switch(typeof n){case"boolean":case"number":case"string":case"undefined":return n;case"object":return n;default:return""}}function Iy(n){var e=n.type;return(n=n.nodeName)&&n.toLowerCase()==="input"&&(e==="checkbox"||e==="radio")}function kC(n){var e=Iy(n)?"checked":"value",t=Object.getOwnPropertyDescriptor(n.constructor.prototype,e),r=""+n[e];if(!n.hasOwnProperty(e)&&typeof t<"u"&&typeof t.get=="function"&&typeof t.set=="function"){var i=t.get,o=t.set;return Object.defineProperty(n,e,{configurable:!0,get:function(){return i.call(this)},set:function(s){r=""+s,o.call(this,s)}}),Object.defineProperty(n,e,{enumerable:t.enumerable}),{getValue:function(){return r},setValue:function(s){r=""+s},stopTracking:function(){n._valueTracker=null,delete n[e]}}}}function ps(n){n._valueTracker||(n._valueTracker=kC(n))}function zy(n){if(!n)return!1;var e=n._valueTracker;if(!e)return!0;var t=e.getValue(),r="";return n&&(r=Iy(n)?n.checked?"true":"false":n.value),n=r,n!==t?(e.setValue(n),!0):!1}function wl(n){if(n=n||(typeof document<"u"?document:void 0),typeof n>"u")return null;try{return n.activeElement||n.body}catch{return n.body}}function Gu(n,e){var t=e.checked;return X({},e,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:t??n._wrapperState.initialChecked})}function Jh(n,e){var t=e.defaultValue==null?"":e.defaultValue,r=e.checked!=null?e.checked:e.defaultChecked;t=En(e.value!=null?e.value:t),n._wrapperState={initialChecked:r,initialValue:t,controlled:e.type==="checkbox"||e.type==="radio"?e.checked!=null:e.value!=null}}function Py(n,e){e=e.checked,e!=null&&xf(n,"checked",e,!1)}function Xu(n,e){Py(n,e);var t=En(e.value),r=e.type;if(t!=null)r==="number"?(t===0&&n.value===""||n.value!=t)&&(n.value=""+t):n.value!==""+t&&(n.value=""+t);else if(r==="submit"||r==="reset"){n.removeAttribute("value");return}e.hasOwnProperty("value")?Zu(n,e.type,t):e.hasOwnProperty("defaultValue")&&Zu(n,e.type,En(e.defaultValue)),e.checked==null&&e.defaultChecked!=null&&(n.defaultChecked=!!e.defaultChecked)}function _h(n,e,t){if(e.hasOwnProperty("value")||e.hasOwnProperty("defaultValue")){var r=e.type;if(!(r!=="submit"&&r!=="reset"||e.value!==void 0&&e.value!==null))return;e=""+n._wrapperState.initialValue,t||e===n.value||(n.value=e),n.defaultValue=e}t=n.name,t!==""&&(n.name=""),n.defaultChecked=!!n._wrapperState.initialChecked,t!==""&&(n.name=t)}function Zu(n,e,t){(e!=="number"||wl(n.ownerDocument)!==n)&&(t==null?n.defaultValue=""+n._wrapperState.initialValue:n.defaultValue!==""+t&&(n.defaultValue=""+t))}var ji=Array.isArray;function $r(n,e,t,r){if(n=n.options,e){e={};for(var i=0;i"+e.valueOf().toString()+"",e=ms.firstChild;n.firstChild;)n.removeChild(n.firstChild);for(;e.firstChild;)n.appendChild(e.firstChild)}});function Co(n,e){if(e){var t=n.firstChild;if(t&&t===n.lastChild&&t.nodeType===3){t.nodeValue=e;return}}n.textContent=e}var eo={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},vC=["Webkit","ms","Moz","O"];Object.keys(eo).forEach(function(n){vC.forEach(function(e){e=e+n.charAt(0).toUpperCase()+n.substring(1),eo[e]=eo[n]})});function By(n,e,t){return e==null||typeof e=="boolean"||e===""?"":t||typeof e!="number"||e===0||eo.hasOwnProperty(n)&&eo[n]?(""+e).trim():e+"px"}function Vy(n,e){n=n.style;for(var t in e)if(e.hasOwnProperty(t)){var r=t.indexOf("--")===0,i=By(t,e[t],r);t==="float"&&(t="cssFloat"),r?n.setProperty(t,i):n[t]=i}}var xC=X({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function nc(n,e){if(e){if(xC[n]&&(e.children!=null||e.dangerouslySetInnerHTML!=null))throw Error(N(137,n));if(e.dangerouslySetInnerHTML!=null){if(e.children!=null)throw Error(N(60));if(typeof e.dangerouslySetInnerHTML!="object"||!("__html"in e.dangerouslySetInnerHTML))throw Error(N(61))}if(e.style!=null&&typeof e.style!="object")throw Error(N(62))}}function rc(n,e){if(n.indexOf("-")===-1)return typeof e.is=="string";switch(n){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var ic=null;function Ef(n){return n=n.target||n.srcElement||window,n.correspondingUseElement&&(n=n.correspondingUseElement),n.nodeType===3?n.parentNode:n}var oc=null,Br=null,Vr=null;function Hh(n){if(n=Xo(n)){if(typeof oc!="function")throw Error(N(280));var e=n.stateNode;e&&(e=Zl(e),oc(n.stateNode,n.type,e))}}function Jy(n){Br?Vr?Vr.push(n):Vr=[n]:Br=n}function _y(){if(Br){var n=Br,e=Vr;if(Vr=Br=null,Hh(n),e)for(n=0;n>>=0,n===0?32:31-(IC(n)/zC|0)|0}var gs=64,ys=4194304;function Ki(n){switch(n&-n){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return n&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return n&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return n}}function Cl(n,e){var t=n.pendingLanes;if(t===0)return 0;var r=0,i=n.suspendedLanes,o=n.pingedLanes,s=t&268435455;if(s!==0){var l=s&~i;l!==0?r=Ki(l):(o&=s,o!==0&&(r=Ki(o)))}else s=t&~i,s!==0?r=Ki(s):o!==0&&(r=Ki(o));if(r===0)return 0;if(e!==0&&e!==r&&!(e&i)&&(i=r&-r,o=e&-e,i>=o||i===16&&(o&4194240)!==0))return e;if(r&4&&(r|=t&16),e=n.entangledLanes,e!==0)for(n=n.entanglements,e&=r;0t;t++)e.push(n);return e}function Yo(n,e,t){n.pendingLanes|=e,e!==536870912&&(n.suspendedLanes=0,n.pingedLanes=0),n=n.eventTimes,e=31-kt(e),n[e]=t}function $C(n,e){var t=n.pendingLanes&~e;n.pendingLanes=e,n.suspendedLanes=0,n.pingedLanes=0,n.expiredLanes&=e,n.mutableReadLanes&=e,n.entangledLanes&=e,e=n.entanglements;var r=n.eventTimes;for(n=n.expirationTimes;0=no),ep=" ",tp=!1;function a0(n,e){switch(n){case"keyup":return dN.indexOf(e.keyCode)!==-1;case"keydown":return e.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function u0(n){return n=n.detail,typeof n=="object"&&"data"in n?n.data:null}var Mr=!1;function pN(n,e){switch(n){case"compositionend":return u0(e);case"keypress":return e.which!==32?null:(tp=!0,ep);case"textInput":return n=e.data,n===ep&&tp?null:n;default:return null}}function mN(n,e){if(Mr)return n==="compositionend"||!zf&&a0(n,e)?(n=s0(),Xs=Af=hn=null,Mr=!1,n):null;switch(n){case"paste":return null;case"keypress":if(!(e.ctrlKey||e.altKey||e.metaKey)||e.ctrlKey&&e.altKey){if(e.char&&1=e)return{node:t,offset:e-n};n=r}e:{for(;t;){if(t.nextSibling){t=t.nextSibling;break e}t=t.parentNode}t=void 0}t=op(t)}}function h0(n,e){return n&&e?n===e?!0:n&&n.nodeType===3?!1:e&&e.nodeType===3?h0(n,e.parentNode):"contains"in n?n.contains(e):n.compareDocumentPosition?!!(n.compareDocumentPosition(e)&16):!1:!1}function p0(){for(var n=window,e=wl();e instanceof n.HTMLIFrameElement;){try{var t=typeof e.contentWindow.location.href=="string"}catch{t=!1}if(t)n=e.contentWindow;else break;e=wl(n.document)}return e}function Pf(n){var e=n&&n.nodeName&&n.nodeName.toLowerCase();return e&&(e==="input"&&(n.type==="text"||n.type==="search"||n.type==="tel"||n.type==="url"||n.type==="password")||e==="textarea"||n.contentEditable==="true")}function NN(n){var e=p0(),t=n.focusedElem,r=n.selectionRange;if(e!==t&&t&&t.ownerDocument&&h0(t.ownerDocument.documentElement,t)){if(r!==null&&Pf(t)){if(e=r.start,n=r.end,n===void 0&&(n=e),"selectionStart"in t)t.selectionStart=e,t.selectionEnd=Math.min(n,t.value.length);else if(n=(e=t.ownerDocument||document)&&e.defaultView||window,n.getSelection){n=n.getSelection();var i=t.textContent.length,o=Math.min(r.start,i);r=r.end===void 0?o:Math.min(r.end,i),!n.extend&&o>r&&(i=r,r=o,o=i),i=sp(t,o);var s=sp(t,r);i&&s&&(n.rangeCount!==1||n.anchorNode!==i.node||n.anchorOffset!==i.offset||n.focusNode!==s.node||n.focusOffset!==s.offset)&&(e=e.createRange(),e.setStart(i.node,i.offset),n.removeAllRanges(),o>r?(n.addRange(e),n.extend(s.node,s.offset)):(e.setEnd(s.node,s.offset),n.addRange(e)))}}for(e=[],n=t;n=n.parentNode;)n.nodeType===1&&e.push({element:n,left:n.scrollLeft,top:n.scrollTop});for(typeof t.focus=="function"&&t.focus(),t=0;t=document.documentMode,Er=null,fc=null,io=null,dc=!1;function lp(n,e,t){var r=t.window===t?t.document:t.nodeType===9?t:t.ownerDocument;dc||Er==null||Er!==wl(r)||(r=Er,"selectionStart"in r&&Pf(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),io&&To(io,r)||(io=r,r=El(fc,"onSelect"),0Tr||(n.current=Sc[Tr],Sc[Tr]=null,Tr--)}function j(n,e){Tr++,Sc[Tr]=n.current,n.current=e}var On={},Me=An(On),_e=An(!1),ir=On;function ti(n,e){var t=n.type.contextTypes;if(!t)return On;var r=n.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===e)return r.__reactInternalMemoizedMaskedChildContext;var i={},o;for(o in t)i[o]=e[o];return r&&(n=n.stateNode,n.__reactInternalMemoizedUnmaskedChildContext=e,n.__reactInternalMemoizedMaskedChildContext=i),i}function We(n){return n=n.childContextTypes,n!=null}function Dl(){q(_e),q(Me)}function pp(n,e,t){if(Me.current!==On)throw Error(N(168));j(Me,e),j(_e,t)}function C0(n,e,t){var r=n.stateNode;if(e=e.childContextTypes,typeof r.getChildContext!="function")return t;r=r.getChildContext();for(var i in r)if(!(i in e))throw Error(N(108,wC(n)||"Unknown",i));return X({},t,r)}function Tl(n){return n=(n=n.stateNode)&&n.__reactInternalMemoizedMergedChildContext||On,ir=Me.current,j(Me,n),j(_e,_e.current),!0}function mp(n,e,t){var r=n.stateNode;if(!r)throw Error(N(169));t?(n=C0(n,e,ir),r.__reactInternalMemoizedMergedChildContext=n,q(_e),q(Me),j(Me,n)):q(_e),j(_e,t)}var Wt=null,ea=!1,iu=!1;function N0(n){Wt===null?Wt=[n]:Wt.push(n)}function FN(n){ea=!0,N0(n)}function bn(){if(!iu&&Wt!==null){iu=!0;var n=0,e=U;try{var t=Wt;for(U=1;n>=s,i-=s,Ut=1<<32-kt(e)+i|t<R?(I=O,O=null):I=O.sibling;var D=d(g,O,S[R],x);if(D===null){O===null&&(O=I);break}n&&O&&D.alternate===null&&e(g,O),y=o(D,y,R),E===null?M=D:E.sibling=D,E=D,O=I}if(R===S.length)return t(g,O),Q&&Jn(g,R),M;if(O===null){for(;RR?(I=O,O=null):I=O.sibling;var H=d(g,O,D.value,x);if(H===null){O===null&&(O=I);break}n&&O&&H.alternate===null&&e(g,O),y=o(H,y,R),E===null?M=H:E.sibling=H,E=H,O=I}if(D.done)return t(g,O),Q&&Jn(g,R),M;if(O===null){for(;!D.done;R++,D=S.next())D=f(g,D.value,x),D!==null&&(y=o(D,y,R),E===null?M=D:E.sibling=D,E=D);return Q&&Jn(g,R),M}for(O=r(g,O);!D.done;R++,D=S.next())D=p(O,g,R,D.value,x),D!==null&&(n&&D.alternate!==null&&O.delete(D.key===null?R:D.key),y=o(D,y,R),E===null?M=D:E.sibling=D,E=D);return n&&O.forEach(function(pt){return e(g,pt)}),Q&&Jn(g,R),M}function w(g,y,S,x){if(typeof S=="object"&&S!==null&&S.type===Nr&&S.key===null&&(S=S.props.children),typeof S=="object"&&S!==null){switch(S.$$typeof){case hs:e:{for(var M=S.key,E=y;E!==null;){if(E.key===M){if(M=S.type,M===Nr){if(E.tag===7){t(g,E.sibling),y=i(E,S.props.children),y.return=g,g=y;break e}}else if(E.elementType===M||typeof M=="object"&&M!==null&&M.$$typeof===nn&&xp(M)===E.type){t(g,E.sibling),y=i(E,S.props),y.ref=wi(g,E,S),y.return=g,g=y;break e}t(g,E);break}else e(g,E);E=E.sibling}S.type===Nr?(y=tr(S.props.children,g.mode,x,S.key),y.return=g,g=y):(x=sl(S.type,S.key,S.props,null,g.mode,x),x.ref=wi(g,y,S),x.return=g,g=x)}return s(g);case Cr:e:{for(E=S.key;y!==null;){if(y.key===E)if(y.tag===4&&y.stateNode.containerInfo===S.containerInfo&&y.stateNode.implementation===S.implementation){t(g,y.sibling),y=i(y,S.children||[]),y.return=g,g=y;break e}else{t(g,y);break}else e(g,y);y=y.sibling}y=du(S,g.mode,x),y.return=g,g=y}return s(g);case nn:return E=S._init,w(g,y,E(S._payload),x)}if(ji(S))return h(g,y,S,x);if(pi(S))return m(g,y,S,x);Ns(g,S)}return typeof S=="string"&&S!==""||typeof S=="number"?(S=""+S,y!==null&&y.tag===6?(t(g,y.sibling),y=i(y,S),y.return=g,g=y):(t(g,y),y=fu(S,g.mode,x),y.return=g,g=y),s(g)):t(g,y)}return w}var ri=b0(!0),I0=b0(!1),Zo={},At=An(Zo),Io=An(Zo),zo=An(Zo);function Qn(n){if(n===Zo)throw Error(N(174));return n}function Uf(n,e){switch(j(zo,e),j(Io,n),j(At,Zo),n=e.nodeType,n){case 9:case 11:e=(e=e.documentElement)?e.namespaceURI:tc(null,"");break;default:n=n===8?e.parentNode:e,e=n.namespaceURI||null,n=n.tagName,e=tc(e,n)}q(At),j(At,e)}function ii(){q(At),q(Io),q(zo)}function z0(n){Qn(zo.current);var e=Qn(At.current),t=tc(e,n.type);e!==t&&(j(Io,n),j(At,t))}function Hf(n){Io.current===n&&(q(At),q(Io))}var Y=An(0);function Pl(n){for(var e=n;e!==null;){if(e.tag===13){var t=e.memoizedState;if(t!==null&&(t=t.dehydrated,t===null||t.data==="$?"||t.data==="$!"))return e}else if(e.tag===19&&e.memoizedProps.revealOrder!==void 0){if(e.flags&128)return e}else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===n)break;for(;e.sibling===null;){if(e.return===null||e.return===n)return null;e=e.return}e.sibling.return=e.return,e=e.sibling}return null}var ou=[];function jf(){for(var n=0;nt?t:4,n(!0);var r=su.transition;su.transition={};try{n(!1),e()}finally{U=t,su.transition=r}}function Y0(){return dt().memoizedState}function VN(n,e,t){var r=Cn(n);if(t={lane:r,action:t,hasEagerState:!1,eagerState:null,next:null},G0(n))X0(e,t);else if(t=D0(n,e,t,r),t!==null){var i=Te();vt(t,n,r,i),Z0(t,e,r)}}function JN(n,e,t){var r=Cn(n),i={lane:r,action:t,hasEagerState:!1,eagerState:null,next:null};if(G0(n))X0(e,i);else{var o=n.alternate;if(n.lanes===0&&(o===null||o.lanes===0)&&(o=e.lastRenderedReducer,o!==null))try{var s=e.lastRenderedState,l=o(s,t);if(i.hasEagerState=!0,i.eagerState=l,Ct(l,s)){var a=e.interleaved;a===null?(i.next=i,_f(e)):(i.next=a.next,a.next=i),e.interleaved=i;return}}catch{}finally{}t=D0(n,e,i,r),t!==null&&(i=Te(),vt(t,n,r,i),Z0(t,e,r))}}function G0(n){var e=n.alternate;return n===G||e!==null&&e===G}function X0(n,e){oo=Fl=!0;var t=n.pending;t===null?e.next=e:(e.next=t.next,t.next=e),n.pending=e}function Z0(n,e,t){if(t&4194240){var r=e.lanes;r&=n.pendingLanes,t|=r,e.lanes=t,Df(n,t)}}var Ll={readContext:ft,useCallback:we,useContext:we,useEffect:we,useImperativeHandle:we,useInsertionEffect:we,useLayoutEffect:we,useMemo:we,useReducer:we,useRef:we,useState:we,useDebugValue:we,useDeferredValue:we,useTransition:we,useMutableSource:we,useSyncExternalStore:we,useId:we,unstable_isNewReconciler:!1},_N={readContext:ft,useCallback:function(n,e){return Mt().memoizedState=[n,e===void 0?null:e],n},useContext:ft,useEffect:Np,useImperativeHandle:function(n,e,t){return t=t!=null?t.concat([n]):null,nl(4194308,4,H0.bind(null,e,n),t)},useLayoutEffect:function(n,e){return nl(4194308,4,n,e)},useInsertionEffect:function(n,e){return nl(4,2,n,e)},useMemo:function(n,e){var t=Mt();return e=e===void 0?null:e,n=n(),t.memoizedState=[n,e],n},useReducer:function(n,e,t){var r=Mt();return e=t!==void 0?t(e):e,r.memoizedState=r.baseState=e,n={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:n,lastRenderedState:e},r.queue=n,n=n.dispatch=VN.bind(null,G,n),[r.memoizedState,n]},useRef:function(n){var e=Mt();return n={current:n},e.memoizedState=n},useState:Cp,useDebugValue:Gf,useDeferredValue:function(n){return Mt().memoizedState=n},useTransition:function(){var n=Cp(!1),e=n[0];return n=BN.bind(null,n[1]),Mt().memoizedState=n,[e,n]},useMutableSource:function(){},useSyncExternalStore:function(n,e,t){var r=G,i=Mt();if(Q){if(t===void 0)throw Error(N(407));t=t()}else{if(t=e(),fe===null)throw Error(N(349));sr&30||L0(r,e,t)}i.memoizedState=t;var o={value:t,getSnapshot:e};return i.queue=o,Np(B0.bind(null,r,o,n),[n]),r.flags|=2048,Lo(9,$0.bind(null,r,o,t,e),void 0,null),t},useId:function(){var n=Mt(),e=fe.identifierPrefix;if(Q){var t=Ht,r=Ut;t=(r&~(1<<32-kt(r)-1)).toString(32)+t,e=":"+e+"R"+t,t=Po++,0<\/script>",n=n.removeChild(n.firstChild)):typeof r.is=="string"?n=s.createElement(t,{is:r.is}):(n=s.createElement(t),t==="select"&&(s=n,r.multiple?s.multiple=!0:r.size&&(s.size=r.size))):n=s.createElementNS(n,t),n[Et]=e,n[bo]=r,a1(n,e,!1,!1),e.stateNode=n;e:{switch(s=rc(t,r),t){case"dialog":K("cancel",n),K("close",n),i=r;break;case"iframe":case"object":case"embed":K("load",n),i=r;break;case"video":case"audio":for(i=0;isi&&(e.flags|=128,r=!0,ki(o,!1),e.lanes=4194304)}else{if(!r)if(n=Pl(s),n!==null){if(e.flags|=128,r=!0,t=n.updateQueue,t!==null&&(e.updateQueue=t,e.flags|=4),ki(o,!0),o.tail===null&&o.tailMode==="hidden"&&!s.alternate&&!Q)return ke(e),null}else 2*ne()-o.renderingStartTime>si&&t!==1073741824&&(e.flags|=128,r=!0,ki(o,!1),e.lanes=4194304);o.isBackwards?(s.sibling=e.child,e.child=s):(t=o.last,t!==null?t.sibling=s:e.child=s,o.last=s)}return o.tail!==null?(e=o.tail,o.rendering=e,o.tail=e.sibling,o.renderingStartTime=ne(),e.sibling=null,t=Y.current,j(Y,r?t&1|2:t&1),e):(ke(e),null);case 22:case 23:return rd(),r=e.memoizedState!==null,n!==null&&n.memoizedState!==null!==r&&(e.flags|=8192),r&&e.mode&1?Qe&1073741824&&(ke(e),e.subtreeFlags&6&&(e.flags|=8192)):ke(e),null;case 24:return null;case 25:return null}throw Error(N(156,e.tag))}function YN(n,e){switch(Lf(e),e.tag){case 1:return We(e.type)&&Dl(),n=e.flags,n&65536?(e.flags=n&-65537|128,e):null;case 3:return ii(),q(_e),q(Me),jf(),n=e.flags,n&65536&&!(n&128)?(e.flags=n&-65537|128,e):null;case 5:return Hf(e),null;case 13:if(q(Y),n=e.memoizedState,n!==null&&n.dehydrated!==null){if(e.alternate===null)throw Error(N(340));ni()}return n=e.flags,n&65536?(e.flags=n&-65537|128,e):null;case 19:return q(Y),null;case 4:return ii(),null;case 10:return Jf(e.type._context),null;case 22:case 23:return rd(),null;case 24:return null;default:return null}}var Es=!1,xe=!1,GN=typeof WeakSet=="function"?WeakSet:Set,T=null;function Ir(n,e){var t=n.ref;if(t!==null)if(typeof t=="function")try{t(null)}catch(r){Z(n,e,r)}else t.current=null}function Rc(n,e,t){try{t()}catch(r){Z(n,e,r)}}var Ip=!1;function XN(n,e){if(hc=Nl,n=p0(),Pf(n)){if("selectionStart"in n)var t={start:n.selectionStart,end:n.selectionEnd};else e:{t=(t=n.ownerDocument)&&t.defaultView||window;var r=t.getSelection&&t.getSelection();if(r&&r.rangeCount!==0){t=r.anchorNode;var i=r.anchorOffset,o=r.focusNode;r=r.focusOffset;try{t.nodeType,o.nodeType}catch{t=null;break e}var s=0,l=-1,a=-1,u=0,c=0,f=n,d=null;t:for(;;){for(var p;f!==t||i!==0&&f.nodeType!==3||(l=s+i),f!==o||r!==0&&f.nodeType!==3||(a=s+r),f.nodeType===3&&(s+=f.nodeValue.length),(p=f.firstChild)!==null;)d=f,f=p;for(;;){if(f===n)break t;if(d===t&&++u===i&&(l=s),d===o&&++c===r&&(a=s),(p=f.nextSibling)!==null)break;f=d,d=f.parentNode}f=p}t=l===-1||a===-1?null:{start:l,end:a}}else t=null}t=t||{start:0,end:0}}else t=null;for(pc={focusedElem:n,selectionRange:t},Nl=!1,T=e;T!==null;)if(e=T,n=e.child,(e.subtreeFlags&1028)!==0&&n!==null)n.return=e,T=n;else for(;T!==null;){e=T;try{var h=e.alternate;if(e.flags&1024)switch(e.tag){case 0:case 11:case 15:break;case 1:if(h!==null){var m=h.memoizedProps,w=h.memoizedState,g=e.stateNode,y=g.getSnapshotBeforeUpdate(e.elementType===e.type?m:gt(e.type,m),w);g.__reactInternalSnapshotBeforeUpdate=y}break;case 3:var S=e.stateNode.containerInfo;S.nodeType===1?S.textContent="":S.nodeType===9&&S.documentElement&&S.removeChild(S.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(N(163))}}catch(x){Z(e,e.return,x)}if(n=e.sibling,n!==null){n.return=e.return,T=n;break}T=e.return}return h=Ip,Ip=!1,h}function so(n,e,t){var r=e.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var i=r=r.next;do{if((i.tag&n)===n){var o=i.destroy;i.destroy=void 0,o!==void 0&&Rc(e,t,o)}i=i.next}while(i!==r)}}function ra(n,e){if(e=e.updateQueue,e=e!==null?e.lastEffect:null,e!==null){var t=e=e.next;do{if((t.tag&n)===n){var r=t.create;t.destroy=r()}t=t.next}while(t!==e)}}function Ac(n){var e=n.ref;if(e!==null){var t=n.stateNode;switch(n.tag){case 5:n=t;break;default:n=t}typeof e=="function"?e(n):e.current=n}}function f1(n){var e=n.alternate;e!==null&&(n.alternate=null,f1(e)),n.child=null,n.deletions=null,n.sibling=null,n.tag===5&&(e=n.stateNode,e!==null&&(delete e[Et],delete e[bo],delete e[yc],delete e[zN],delete e[PN])),n.stateNode=null,n.return=null,n.dependencies=null,n.memoizedProps=null,n.memoizedState=null,n.pendingProps=null,n.stateNode=null,n.updateQueue=null}function d1(n){return n.tag===5||n.tag===3||n.tag===4}function zp(n){e:for(;;){for(;n.sibling===null;){if(n.return===null||d1(n.return))return null;n=n.return}for(n.sibling.return=n.return,n=n.sibling;n.tag!==5&&n.tag!==6&&n.tag!==18;){if(n.flags&2||n.child===null||n.tag===4)continue e;n.child.return=n,n=n.child}if(!(n.flags&2))return n.stateNode}}function bc(n,e,t){var r=n.tag;if(r===5||r===6)n=n.stateNode,e?t.nodeType===8?t.parentNode.insertBefore(n,e):t.insertBefore(n,e):(t.nodeType===8?(e=t.parentNode,e.insertBefore(n,t)):(e=t,e.appendChild(n)),t=t._reactRootContainer,t!=null||e.onclick!==null||(e.onclick=Ol));else if(r!==4&&(n=n.child,n!==null))for(bc(n,e,t),n=n.sibling;n!==null;)bc(n,e,t),n=n.sibling}function Ic(n,e,t){var r=n.tag;if(r===5||r===6)n=n.stateNode,e?t.insertBefore(n,e):t.appendChild(n);else if(r!==4&&(n=n.child,n!==null))for(Ic(n,e,t),n=n.sibling;n!==null;)Ic(n,e,t),n=n.sibling}var he=null,yt=!1;function Zt(n,e,t){for(t=t.child;t!==null;)h1(n,e,t),t=t.sibling}function h1(n,e,t){if(Rt&&typeof Rt.onCommitFiberUnmount=="function")try{Rt.onCommitFiberUnmount(Ql,t)}catch{}switch(t.tag){case 5:xe||Ir(t,e);case 6:var r=he,i=yt;he=null,Zt(n,e,t),he=r,yt=i,he!==null&&(yt?(n=he,t=t.stateNode,n.nodeType===8?n.parentNode.removeChild(t):n.removeChild(t)):he.removeChild(t.stateNode));break;case 18:he!==null&&(yt?(n=he,t=t.stateNode,n.nodeType===8?ru(n.parentNode,t):n.nodeType===1&&ru(n,t),Oo(n)):ru(he,t.stateNode));break;case 4:r=he,i=yt,he=t.stateNode.containerInfo,yt=!0,Zt(n,e,t),he=r,yt=i;break;case 0:case 11:case 14:case 15:if(!xe&&(r=t.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){i=r=r.next;do{var o=i,s=o.destroy;o=o.tag,s!==void 0&&(o&2||o&4)&&Rc(t,e,s),i=i.next}while(i!==r)}Zt(n,e,t);break;case 1:if(!xe&&(Ir(t,e),r=t.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=t.memoizedProps,r.state=t.memoizedState,r.componentWillUnmount()}catch(l){Z(t,e,l)}Zt(n,e,t);break;case 21:Zt(n,e,t);break;case 22:t.mode&1?(xe=(r=xe)||t.memoizedState!==null,Zt(n,e,t),xe=r):Zt(n,e,t);break;default:Zt(n,e,t)}}function Pp(n){var e=n.updateQueue;if(e!==null){n.updateQueue=null;var t=n.stateNode;t===null&&(t=n.stateNode=new GN),e.forEach(function(r){var i=lM.bind(null,n,r);t.has(r)||(t.add(r),r.then(i,i))})}}function mt(n,e){var t=e.deletions;if(t!==null)for(var r=0;ri&&(i=s),r&=~o}if(r=i,r=ne()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*eM(r/1960))-r,10n?16:n,pn===null)var r=!1;else{if(n=pn,pn=null,Vl=0,V&6)throw Error(N(331));var i=V;for(V|=4,T=n.current;T!==null;){var o=T,s=o.child;if(T.flags&16){var l=o.deletions;if(l!==null){for(var a=0;ane()-td?er(n,0):ed|=t),Ue(n,e)}function v1(n,e){e===0&&(n.mode&1?(e=ys,ys<<=1,!(ys&130023424)&&(ys=4194304)):e=1);var t=Te();n=Yt(n,e),n!==null&&(Yo(n,e,t),Ue(n,t))}function sM(n){var e=n.memoizedState,t=0;e!==null&&(t=e.retryLane),v1(n,t)}function lM(n,e){var t=0;switch(n.tag){case 13:var r=n.stateNode,i=n.memoizedState;i!==null&&(t=i.retryLane);break;case 19:r=n.stateNode;break;default:throw Error(N(314))}r!==null&&r.delete(e),v1(n,t)}var x1;x1=function(n,e,t){if(n!==null)if(n.memoizedProps!==e.pendingProps||_e.current)Ve=!0;else{if(!(n.lanes&t)&&!(e.flags&128))return Ve=!1,qN(n,e,t);Ve=!!(n.flags&131072)}else Ve=!1,Q&&e.flags&1048576&&M0(e,Al,e.index);switch(e.lanes=0,e.tag){case 2:var r=e.type;rl(n,e),n=e.pendingProps;var i=ti(e,Me.current);_r(e,t),i=qf(null,e,r,n,i,t);var o=Qf();return e.flags|=1,typeof i=="object"&&i!==null&&typeof i.render=="function"&&i.$$typeof===void 0?(e.tag=1,e.memoizedState=null,e.updateQueue=null,We(r)?(o=!0,Tl(e)):o=!1,e.memoizedState=i.state!==null&&i.state!==void 0?i.state:null,Wf(e),i.updater=ta,e.stateNode=i,i._reactInternals=e,Cc(e,r,n,t),e=Ec(null,e,r,!0,o,t)):(e.tag=0,Q&&o&&Ff(e),Oe(null,e,i,t),e=e.child),e;case 16:r=e.elementType;e:{switch(rl(n,e),n=e.pendingProps,i=r._init,r=i(r._payload),e.type=r,i=e.tag=uM(r),n=gt(r,n),i){case 0:e=Mc(null,e,r,n,t);break e;case 1:e=Rp(null,e,r,n,t);break e;case 11:e=Dp(null,e,r,n,t);break e;case 14:e=Tp(null,e,r,gt(r.type,n),t);break e}throw Error(N(306,r,""))}return e;case 0:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:gt(r,i),Mc(n,e,r,i,t);case 1:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:gt(r,i),Rp(n,e,r,i,t);case 3:e:{if(o1(e),n===null)throw Error(N(387));r=e.pendingProps,o=e.memoizedState,i=o.element,T0(n,e),zl(e,r,null,t);var s=e.memoizedState;if(r=s.element,o.isDehydrated)if(o={element:r,isDehydrated:!1,cache:s.cache,pendingSuspenseBoundaries:s.pendingSuspenseBoundaries,transitions:s.transitions},e.updateQueue.baseState=o,e.memoizedState=o,e.flags&256){i=oi(Error(N(423)),e),e=Ap(n,e,r,t,i);break e}else if(r!==i){i=oi(Error(N(424)),e),e=Ap(n,e,r,t,i);break e}else for(Ge=kn(e.stateNode.containerInfo.firstChild),Ze=e,Q=!0,wt=null,t=I0(e,null,r,t),e.child=t;t;)t.flags=t.flags&-3|4096,t=t.sibling;else{if(ni(),r===i){e=Gt(n,e,t);break e}Oe(n,e,r,t)}e=e.child}return e;case 5:return z0(e),n===null&&kc(e),r=e.type,i=e.pendingProps,o=n!==null?n.memoizedProps:null,s=i.children,mc(r,i)?s=null:o!==null&&mc(r,o)&&(e.flags|=32),i1(n,e),Oe(n,e,s,t),e.child;case 6:return n===null&&kc(e),null;case 13:return s1(n,e,t);case 4:return Uf(e,e.stateNode.containerInfo),r=e.pendingProps,n===null?e.child=ri(e,null,r,t):Oe(n,e,r,t),e.child;case 11:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:gt(r,i),Dp(n,e,r,i,t);case 7:return Oe(n,e,e.pendingProps,t),e.child;case 8:return Oe(n,e,e.pendingProps.children,t),e.child;case 12:return Oe(n,e,e.pendingProps.children,t),e.child;case 10:e:{if(r=e.type._context,i=e.pendingProps,o=e.memoizedProps,s=i.value,j(bl,r._currentValue),r._currentValue=s,o!==null)if(Ct(o.value,s)){if(o.children===i.children&&!_e.current){e=Gt(n,e,t);break e}}else for(o=e.child,o!==null&&(o.return=e);o!==null;){var l=o.dependencies;if(l!==null){s=o.child;for(var a=l.firstContext;a!==null;){if(a.context===r){if(o.tag===1){a=Kt(-1,t&-t),a.tag=2;var u=o.updateQueue;if(u!==null){u=u.shared;var c=u.pending;c===null?a.next=a:(a.next=c.next,c.next=a),u.pending=a}}o.lanes|=t,a=o.alternate,a!==null&&(a.lanes|=t),vc(o.return,t,e),l.lanes|=t;break}a=a.next}}else if(o.tag===10)s=o.type===e.type?null:o.child;else if(o.tag===18){if(s=o.return,s===null)throw Error(N(341));s.lanes|=t,l=s.alternate,l!==null&&(l.lanes|=t),vc(s,t,e),s=o.sibling}else s=o.child;if(s!==null)s.return=o;else for(s=o;s!==null;){if(s===e){s=null;break}if(o=s.sibling,o!==null){o.return=s.return,s=o;break}s=s.return}o=s}Oe(n,e,i.children,t),e=e.child}return e;case 9:return i=e.type,r=e.pendingProps.children,_r(e,t),i=ft(i),r=r(i),e.flags|=1,Oe(n,e,r,t),e.child;case 14:return r=e.type,i=gt(r,e.pendingProps),i=gt(r.type,i),Tp(n,e,r,i,t);case 15:return n1(n,e,e.type,e.pendingProps,t);case 17:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:gt(r,i),rl(n,e),e.tag=1,We(r)?(n=!0,Tl(e)):n=!1,_r(e,t),A0(e,r,i),Cc(e,r,i,t),Ec(null,e,r,!0,n,t);case 19:return l1(n,e,t);case 22:return r1(n,e,t)}throw Error(N(156,e.tag))};function C1(n,e){return Qy(n,e)}function aM(n,e,t,r){this.tag=n,this.key=t,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=e,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function at(n,e,t,r){return new aM(n,e,t,r)}function od(n){return n=n.prototype,!(!n||!n.isReactComponent)}function uM(n){if(typeof n=="function")return od(n)?1:0;if(n!=null){if(n=n.$$typeof,n===Nf)return 11;if(n===Mf)return 14}return 2}function Nn(n,e){var t=n.alternate;return t===null?(t=at(n.tag,e,n.key,n.mode),t.elementType=n.elementType,t.type=n.type,t.stateNode=n.stateNode,t.alternate=n,n.alternate=t):(t.pendingProps=e,t.type=n.type,t.flags=0,t.subtreeFlags=0,t.deletions=null),t.flags=n.flags&14680064,t.childLanes=n.childLanes,t.lanes=n.lanes,t.child=n.child,t.memoizedProps=n.memoizedProps,t.memoizedState=n.memoizedState,t.updateQueue=n.updateQueue,e=n.dependencies,t.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext},t.sibling=n.sibling,t.index=n.index,t.ref=n.ref,t}function sl(n,e,t,r,i,o){var s=2;if(r=n,typeof n=="function")od(n)&&(s=1);else if(typeof n=="string")s=5;else e:switch(n){case Nr:return tr(t.children,i,o,e);case Cf:s=8,i|=8;break;case Ku:return n=at(12,t,e,i|2),n.elementType=Ku,n.lanes=o,n;case qu:return n=at(13,t,e,i),n.elementType=qu,n.lanes=o,n;case Qu:return n=at(19,t,e,i),n.elementType=Qu,n.lanes=o,n;case by:return oa(t,i,o,e);default:if(typeof n=="object"&&n!==null)switch(n.$$typeof){case Ry:s=10;break e;case Ay:s=9;break e;case Nf:s=11;break e;case Mf:s=14;break e;case nn:s=16,r=null;break e}throw Error(N(130,n==null?n:typeof n,""))}return e=at(s,t,e,i),e.elementType=n,e.type=r,e.lanes=o,e}function tr(n,e,t,r){return n=at(7,n,r,e),n.lanes=t,n}function oa(n,e,t,r){return n=at(22,n,r,e),n.elementType=by,n.lanes=t,n.stateNode={isHidden:!1},n}function fu(n,e,t){return n=at(6,n,null,e),n.lanes=t,n}function du(n,e,t){return e=at(4,n.children!==null?n.children:[],n.key,e),e.lanes=t,e.stateNode={containerInfo:n.containerInfo,pendingChildren:null,implementation:n.implementation},e}function cM(n,e,t,r,i){this.tag=e,this.containerInfo=n,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=ja(0),this.expirationTimes=ja(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=ja(0),this.identifierPrefix=r,this.onRecoverableError=i,this.mutableSourceEagerHydrationData=null}function sd(n,e,t,r,i,o,s,l,a){return n=new cM(n,e,t,l,a),e===1?(e=1,o===!0&&(e|=8)):e=0,o=at(3,null,null,e),n.current=o,o.stateNode=n,o.memoizedState={element:r,isDehydrated:t,cache:null,transitions:null,pendingSuspenseBoundaries:null},Wf(o),n}function fM(n,e,t){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(O1)}catch(n){console.error(n)}}O1(),My.exports=tt;var li=My.exports,D1,Wp=li;D1=Wp.createRoot,Wp.hydrateRoot;const es=C.createContext(null),T1=C.createContext(null);function gM(n){const e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(const r in t)r=="class"?e.class+=" "+t[r]:r=="style"?e.style=(e.style?e.style+";":"")+t[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(t[r]))}),e.translate||(e.translate="no"),[ge.node(0,n.state.doc.content.size,e)]}const yM=[],SM={},$c=_.empty;class Un{constructor(e){this.members=e}map(e,t){const r=this.members.map(i=>i.map(e,t,SM));return Un.from(r)}forChild(e,t){if(t.isLeaf)return _.empty;let r=[];for(let i=0;it instanceof _)?e:e.reduce((t,r)=>t.concat(r instanceof _?r:r.members),[]))}}forEachSet(e){for(let t=0;t0;)e++;n.splice(e,0,t)}function kM(n,e){const t=[];return n.someProp("decorations",r=>{const i=r(n.state);i&&i!=$c&&t.push(i)}),e&&t.push(_.create(n.state.doc,[e])),Un.from(t)}const cd=function(n){for(let e=0;;e++)if(n=n.previousSibling,!n)return e},Hp=function(n){const e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},vM=function(n,e,t,r){return t&&(jp(n,e,t,r,-1)||jp(n,e,t,r,1))},xM=/^(img|br|input|textarea|hr)$/i;function jp(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:Wl(n))){const o=n.parentNode;if(!o||o.nodeType!=1||NM(n)||xM.test(n.nodeName)||n.contentEditable=="false")return!1;e=cd(n)+(i<0?0:1),n=o}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?Wl(n):0}else return!1}}function Wl(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function CM(n,e,t){for(let r=e==0,i=e==Wl(n);r||i;){if(n==t)return!0;const o=cd(n);if(n=n.parentNode,!n)return!1;r=r&&o==0,i=i&&o==Wl(n)}return!1}function NM(n){let e;for(let t=n;t&&!(e=t.pmViewDesc);t=t.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==n||e.contentDOM==n)}const A1=function(n){return n.focusNode&&vM(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)},b1=C.createContext(null);function MM(n,e){const t=C.useContext(b1);C.useLayoutEffect(()=>t(n),e)}function I1(n,e){const{view:t}=C.useContext(es);MM(()=>{if(t)return n(t)},e&&[t,...e])}const EM=C.forwardRef(function({widget:e,pos:t,...r},i){const[o,s]=C.useState(!0),l=C.useRef(null);return C.useImperativeHandle(i,()=>l.current,[]),I1(a=>{if(!a||!l.current)return;a.domObserver.disconnectSelection();const u=a.domSelection(),c=document.createRange(),f=l.current;f.nodeName=="IMG"&&f.parentNode?c.setEnd(f.parentNode,cd(f)+1):c.setEnd(f,0),c.collapse(!1),u.removeAllRanges(),u.addRange(c),s(!1),a.domObserver.connectSelection()},[]),o?b.jsx("img",{ref:l,className:"ProseMirror-separator","mark-placeholder":"true",alt:"",...r}):null});function OM(n,e){if(n==e)return!0;for(const t in n)if(n[t]!==e[t])return!1;for(const t in e)if(!(t in n))return!1;return!0}const DM={side:0};class Bo{constructor(e,t){this.Component=e,this.spec=t??DM,this.side=this.spec.side??0}map(e,t,r,i){const{pos:o,deleted:s}=e.mapResult(t.from+i,this.side<0?-1:1);return s?null:new ge(o-r,o-r,this)}valid(){return!0}eq(e){return this==e||e instanceof Bo&&(this.spec.key&&this.spec.key==e.spec.key||this.Component==e.Component&&OM(this.spec,e.spec))}destroy(){}}function z1(n,e,t){return new ge(n,n,new Bo(e,t))}function hu(){return Math.floor(Math.random()*16777215).toString(16)}const Vo=new Ho("@nytimes/react-prosemirror/reactKeys");function TM(){let n=!1;return new Lt({key:Vo,state:{init(e,t){const r={posToKey:new Map,keyToPos:new Map};return t.doc.descendants((i,o)=>{const s=hu();return r.posToKey.set(o,s),r.keyToPos.set(s,o),!0}),r},apply(e,t,r,i){if(!e.docChanged||n)return t;const o=e.getMeta(Vo),s=(o==null?void 0:o.type)==="bustKey"&&o.payload.key,l={posToKey:new Map,keyToPos:new Map},a=Array.from(t.posToKey.entries()).sort(([u],[c])=>u-c);for(const[u,c]of a){const{pos:f,deleted:d}=e.mapping.mapResult(u);if(d)continue;let p=c;s===c&&(p=hu()),l.posToKey.set(f,p),l.keyToPos.set(p,f)}return i.doc.descendants((u,c)=>{if(l.posToKey.has(c))return!0;const f=hu();return l.posToKey.set(c,f),l.keyToPos.set(f,c),!0}),l}},props:{handleDOMEvents:{compositionstart:()=>{n=!0},compositionend:()=>{n=!1}}}})}function pu(n,e,t={}){var s;if(e===null)return!1;const r=t.from??n.state.selection.from,i=t.to??n.state.selection.to;if(n.someProp("handleTextInput",l=>l(n,r,i,e)))return!0;const{tr:o}=n.state;if(t.marks&&o.ensureMarks(t.marks),o.insertText(e,r,i),t.bust){const l=n.state.doc.resolve(r),a=l.sharedDepth(i),u=l.start(a),c=(s=Vo.getState(n.state))==null?void 0:s.posToKey.get(u-1);o.setMeta(Vo,{type:"bustKey",payload:{key:c}})}return n.dispatch(o),!0}function RM(n){let e=null,t=null;return new Lt({props:{handleDOMEvents:{compositionstart(r){var s;const{state:i}=r;r.dispatch(i.tr.deleteSelection());const o=i.selection.$from;return i.selection.empty&&(i.storedMarks||!o.textOffset&&o.parentOffset&&((s=o.nodeBefore)!=null&&s.marks.some(l=>l.type.spec.inclusive===!1)))&&n(z1(i.selection.from,EM,{key:"cursor-wrapper",marks:i.storedMarks??o.marks()})),t=i.storedMarks??o.marks(),r.input.composing=!0,!0},compositionupdate(){return!0},compositionend(r){if(r.input.composing=!1,e!==null)return pu(r,e,{bust:!0,marks:t}),e=null,t=null,n(null),!0},beforeinput(r,i){var o,s;switch(i.preventDefault(),i.inputType){case"insertCompositionText":{if(i.data===null)break;e=i.data;break}case"insertReplacementText":{const l=i.getTargetRanges();(s=(o=i.dataTransfer)==null?void 0:o.items[0])==null||s.getAsString(a=>{for(const u of l){const c=r.posAtDOM(u.startContainer,u.startOffset,1),f=r.posAtDOM(u.endContainer,u.endOffset,1);pu(r,a,{from:c,to:f})}});break}case"insertText":{pu(r,i.data);break}case"deleteWordBackward":case"deleteContentBackward":case"deleteWordForward":case"deleteContentForward":case"deleteContent":{const l=i.getTargetRanges(),{tr:a}=r.state;for(const u of l){const c=r.posAtDOM(u.startContainer,u.startOffset),f=r.posAtDOM(u.endContainer,u.endOffset),{doc:d}=r.state,p=d.resolve(c).marksAcross(d.resolve(f));a.delete(c,f).setStoredMarks(p)}r.dispatch(a);break}}return!0}}}})}const Ft=typeof navigator<"u"?navigator:null,Kp=typeof document<"u"?document:null,In=Ft&&Ft.userAgent||"",Bc=/Edge\/(\d+)/.exec(In),P1=/MSIE \d/.exec(In),Vc=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(In),ca=!!(P1||Vc||Bc),AM=P1?document.documentMode:Vc?+Vc[1]:Bc?+Bc[1]:0,F1=!ca&&/gecko\/(\d+)/i.test(In),bM=F1&&+(/Firefox\/(\d+)/.exec(In)||[0,0])[1],Jc=!ca&&/Chrome\/(\d+)/.exec(In),IM=!!Jc,zM=Jc?+Jc[1]:0,L1=!ca&&!!Ft&&/Apple Computer/.test(Ft.vendor),$1=L1&&(/Mobile\/\w+/.test(In)||!!Ft&&Ft.maxTouchPoints>2),PM=$1||(Ft?/Mac/.test(Ft.platform):!1),FM=Ft?/Win/.test(Ft.platform):!1,LM=/Android \d/.test(In),B1=!!Kp&&"webkitFontSmoothing"in Kp.documentElement.style,$M=B1?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,Ne={ie:ca,ie_version:AM,gecko:F1,gecko_version:bM,chrome:IM,chrome_version:zM,safari:L1,ios:$1,mac:PM,windows:FM,android:LM,webkit:B1,webkit_version:$M};function mu(n){return n.editable&&!n.hasFocus()?!1:BM(n)}function BM(n){var t,r;const e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(((t=e.focusNode)==null?void 0:t.nodeType)==3?(r=e.focusNode)==null?void 0:r.parentNode:e.focusNode))}catch{return!1}}function VM(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||$.between(e,t,r)}function qp(n,e=null){const t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode);const o=i&&i.size==0,s=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(s<0)return null;const l=r.resolve(s);let a,u;if(A1(t)){for(a=l;i&&!i.node;)i=i.parent;const c=i.node;if(i&&c.isAtom&&z.isSelectable(c)&&i.parent&&!(c.isInline&&CM(t.focusNode,t.focusOffset,i.dom))){const f=i.posBefore;u=new z(s==f?l:r.resolve(f))}}else{const c=n.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(c<0)return null;a=r.resolve(c)}if(!u){const c=e=="pointer"||n.state.selection.head{(r.anchorNode!=i||r.anchorOffset!=o)&&(t.removeEventListener("selectionchange",e.input.hideSelectionGuard),setTimeout(()=>{(!V1(e)||e.state.selection.visible)&&e.dom.classList.remove("ProseMirror-hideselection")},20))})}const em=Ne.safari||Ne.chrome&&Ne.chrome_version<63;function Ts(n,e=!1){const t=n,r=t.state.selection;if(WM(t,r),!!V1(t)){if(!e&&t.input.mouseDown&&t.input.mouseDown.allowDefault&&Ne.chrome){const i=t.domSelectionRange(),o=t.domObserver.currentSelection;if(i.anchorNode&&o.anchorNode&&Ul(i.anchorNode,i.anchorOffset,o.anchorNode,o.anchorOffset)){t.input.mouseDown.delayedSelectionSync=!0,t.domObserver.setCurSelection();return}}if(t.domObserver.disconnectSelection(),t.cursorWrapper)HM(t);else{const{anchor:i,head:o}=r;let s,l;em&&!(r instanceof $)&&(r.$from.parent.inlineContent||(s=Xp(t,r.from)),!r.empty&&!r.$from.parent.inlineContent&&(l=Xp(t,r.to))),t.docView.setSelection(i,o,t.root,e),em&&(s&&Zp(s),l&&Zp(l)),r.visible?t.dom.classList.remove("ProseMirror-hideselection"):(t.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&jM(t))}t.domObserver.setCurSelection(),t.domObserver.connectSelection()}}class KM{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 qM{constructor(e){this.view=e,this.flushingSoon=-1,this.currentSelection=new KM,this.suppressingSelectionUpdates=!1,this.view=e,this.onSelectionChange=this.onSelectionChange.bind(this)}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}stop(){this.disconnectSelection()}start(){this.connectSelection()}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;const t=new Set;let r;for(let o=e.focusNode;o;o=Hp(o))t.add(o);for(let o=e.anchorNode;o;o=Hp(o))if(t.has(o)){r=o;break}const i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:(r==null?void 0:r.nodeType)==3?r==null?void 0:r.parentNode:r}))return this.setCurSelection(),!0}registerMutation(){}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}updateSelection(){const{view:e}=this,t=e.input.compositionPendingChanges||(e.composing?e.input.compositionID:0);e.input.compositionPendingChanges=0;const r=e.input.lastSelectionTime>Date.now()-50?e.input.lastSelectionOrigin:null,i=qp(e,r);if(i&&!e.state.selection.eq(i)){const o=e.state.tr.setSelection(i);r=="pointer"?o.setMeta("pointer",!0):r=="key"&&o.scrollIntoView(),t&&o.setMeta("composition",t),e.dispatch(o)}}selectionToDOM(){const{view:e}=this;Ts(e);const t=e.domSelectionRange();this.currentSelection.set(t)}flush(){const{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;const t=e.domSelectionRange(),r=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(t)&&mu(e)&&!this.ignoreSelectionChange(t);let i=null;r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}onSelectionChange(){if(mu(this.view)&&!this.view.composing){if(this.suppressingSelectionUpdates)return Ts(this.view);if(Ne.ie&&Ne.ie_version<=11&&!this.view.state.selection.empty){const e=this.view.domSelectionRange();if(e.focusNode&&Ul(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}}const ai=0,tm=1,Rs=2,Jo=3;class ts{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=ai,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;ton(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){const o=this.getDesc(i);let s;if(o&&(!t||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}getDesc(e){const t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){const o=this.getDesc(i);if(o)return o.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||s instanceof hd){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof fd&&o.side>=0;r--);if(t<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&t&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,t):{node:this.contentDOM,offset:o?on(o.dom)+1:0}}else{let o,s=!0;for(;o=r=c&&t<=u-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,c);e=s;for(let f=l;f>0;f--){const d=this.children[f-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=on(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(u>t||l==this.children.length-1)){t=u;for(let c=l+1;ch&&st){const h=l;l=a,a=h}const p=document.createRange();p.setEnd(a.node,a.offset),p.setStart(l.node,l.offset),u.removeAllRanges(),u.addRange(p)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let r=0,i=0;i=r:er){const l=r+o.border,a=s-o.border;if(e>=l&&t<=a){this.dirty=e==r||t==s?Rs:tm,e==l&&t==a&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=Jo:o.markDirty(e-l,t-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?Rs:Jo}r=s}this.dirty=Rs}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){const r=e==1?Rs:tm;t.dirtythis.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){const r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>v.empty)}return e}matchesNode(e,t,r){return this.dirty==ai&&e.eq(this.node)&&XM(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}update(e,t,r,i){return!0}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}class GM extends dd{constructor(e,t,r,i,o,s,l){super(e,t,r,i,o,s,null,l,()=>!1)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,i){return!0}inParent(){const e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Jo)}get domAtom(){return!1}}class hd extends ts{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==ai&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}function XM(n,e){if(n.length!=e.length)return!1;for(let t=0;t{u=!!a.call(this,s,l)}),u||l.defaultPrevented)return!0}return!1};e[r]=o}return new Lt({key:new Ho("@nytimes/react-prosemirror/componentEventListeners"),props:{handleDOMEvents:e}})}function eE(){const[n,e]=C.useState(new Map),t=C.useCallback((o,s)=>{const l=n.get(o)??[];l.unshift(s),n.has(o)||(n.set(o,l),e(new Map(n)))},[n]),r=C.useCallback((o,s)=>{const l=n.get(o);l==null||l.splice(l.indexOf(s),1)},[n]),i=C.useMemo(()=>ZM(n),[n]);return{registerEventListener:t,unregisterEventListener:r,componentEventListenersPlugin:i}}function J1(){const[,n]=C.useReducer(e=>e+1,0);return n}function tE(n){const e=Object.create(null);function t(r){for(const i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function nE(n,e){let t=0,r=0;for(const i in n){if(n[i]!=e[i])return!0;t++}for(const i in e)r++;return t!=r}class rE extends Av{constructor(e,t){super(e,{state:un.create({schema:t.state.schema,plugins:t.state.plugins}),plugins:t.plugins}),this.shouldUpdatePluginViews=!1,this.shouldUpdatePluginViews=!0,this._props=t,this.oldProps={state:t.state},this.state=t.state,this.domObserver.stop(),this.domObserver=new qM(this),this.domObserver.start(),this.docView.dom.replaceChildren(),this.docView=t.docView}get needsRedraw(){if(this.oldProps.state.plugins===this._props.state.plugins&&this._props.plugins===this.oldProps.plugins)return!1;const e=tE(this);return nE(this.nodeViews,e)}pureSetProps(e){this._props={...this._props,...e},this.state=this._props.state}runPendingEffects(){const e=this.props;this._props=this.oldProps,this.state=this._props.state,this.update(e)}update(e){super.update(e),this.oldProps=e}updatePluginViews(e){this.shouldUpdatePluginViews&&super.updatePluginViews(e)}destroy(){this.dom=document.createElement("div"),super.destroy()}}const iE=new Om({nodes:{doc:{content:"text*"},text:{inline:!0}}}),oE=un.create({schema:iE});function sE(n,e){const[t,r]=C.useState(null),[i,o]=C.useState(null),s=J1(),l=e.defaultState??oE,[a,u]=C.useState(l),c=e.state??a,{componentEventListenersPlugin:f,registerEventListener:d,unregisterEventListener:p}=eE(),h=C.useCallback(x=>{li.flushSync(()=>{o(x)})},[]),m=C.useMemo(()=>[...e.plugins??[],f,RM(h)],[e.plugins,f,h]);function w(x){li.flushSync(()=>{e.state||u(M=>M.apply(x)),e.dispatchTransaction&&e.dispatchTransaction.call(this,x)})}const g=document.createElement("div"),y=C.useRef(new dd(void 0,[],c.doc,[],_.empty,g,null,g,()=>!1)),S={...e,state:c,plugins:m,dispatchTransaction:w,docView:y.current};return C.useLayoutEffect(()=>()=>{t==null||t.destroy()},[t]),C.useLayoutEffect(()=>{if(t&&t.dom!==n&&r(null),!!n&&!t){const x=new rE({mount:n},S);r(x),x.dom.addEventListener("compositionend",s);return}}),C.useLayoutEffect(()=>{if(t!=null&&t.needsRedraw){r(null);return}else t==null||t.domObserver.selectionToDOM(),t==null||t.runPendingEffects()}),t==null||t.pureSetProps(S),C.useMemo(()=>({view:t,state:c,registerEventListener:d,unregisterEventListener:p,cursorWrapper:i,docViewDescRef:y}),[t,c,d,p,i])}function lE({children:n}){const e=C.useRef(new Set).current,t=C.useRef(new Set).current,r=C.useRef(!1),i=J1(),o=C.useRef(!0),s=C.useCallback(()=>{o.current||(i(),o.current=!0)},[i]),l=C.useCallback(a=>{let u;const c=()=>{u=a()};return e.add(c),s(),()=>{e.delete(c),u&&(r.current?(t.add(u),s()):u())}},[e,t,s]);return C.useLayoutEffect(()=>(o.current=!1,e.forEach(a=>a()),e.clear(),()=>{t.forEach(a=>a()),t.clear()})),C.useLayoutEffect(()=>(r.current=!0,()=>{r.current=!1}),[]),b.jsx(b1.Provider,{value:l,children:n})}const ht=C.createContext([]);function _1(n,e,t,r,i,o,s){const l=C.useRef(o),a=C.useRef(()=>!1),u=C.useCallback(d=>{a.current=d},[]),c=C.useContext(ht),f=[];return C.useLayoutEffect(()=>{if(!n||!t.current)return;const d=f[0];l.current?(l.current.parent=void 0,l.current.children=f,l.current.node=n,l.current.outerDeco=i,l.current.innerDeco=r,l.current.dom=(e==null?void 0:e.current)??t.current,l.current.dom.pmViewDesc=l.current,l.current.contentDOM=(s==null?void 0:s.current)??l.current.contentDOM??(d==null?void 0:d.dom.parentElement)??null,l.current.nodeDOM=t.current):l.current=new dd(void 0,f,n,i,r,(e==null?void 0:e.current)??t.current,(d==null?void 0:d.dom.parentElement)??null,t.current,p=>!!a.current(p)),c.push(l.current);for(const p of f)p.parent=l.current}),{childDescriptors:f,setStopEvent:u}}function aE(n,e){return n.type.side-e.type.side}function uE(n,e,t,r){const i=e.locals(n);let o=0;if(i.length==0){for(let u=0;uo;)l.push(i[s++]);let d=o+c.nodeSize;if(c.isText){let h=d;s!h.inline):l.slice();r(c,p,e.forChild(o,c),o,f),o=d}}function fa(){const{state:n}=C.useContext(es);return n}function W1(){const n=fa();return Vo.getState(n)}var U1={exports:{}};/*! - Copyright (c) 2018 Jed Watson. - Licensed under the MIT License (MIT), see - http://jedwatson.github.io/classnames -*/(function(n){(function(){var e={}.hasOwnProperty;function t(){for(var r=[],i=0;i{var t;return((t=e[1])==null?void 0:t.toUpperCase())??""})}function hE(n){const e=new CSSStyleSheet;e.insertRule(`* { ${n} }`);const r=e.cssRules[0].style,i={};for(let o=0;o0&&(e.step=r);break}case"disabled":{e.disabled=r!=null;break}case"rows":{const i=parseInt(r,10);Number.isNaN(i)||(e.rows=r);break}default:{e[t]=r;break}}return e}const pd=C.forwardRef(function({outputSpec:e,children:t,...r},i){if(typeof e=="string")return b.jsx(b.Fragment,{children:e});if(!Array.isArray(e))throw new Error("@nytimes/react-prosemirror only supports strings and arrays in toDOM");const s=e[0].replace(" ",":"),l=e[1];let a={ref:i,...r},u=1;l&&typeof l=="object"&&l.nodeType==null&&!Array.isArray(l)&&(u=2,a=H1(j1(l),a));const c=[];for(let f=u;fu)throw new RangeError("Content hole must be the only child of its parent node");return C.createElement(s,a,t)}c.push(b.jsx(pd,{ref:void 0,outputSpec:d,children:t}))}return C.createElement(s,a,...c)}),K1=C.forwardRef(function({mark:e,children:t},r){var a,u;const i=C.useContext(ht),o=[],s=C.useRef(null);C.useImperativeHandle(r,()=>s.current,[]);const l=(u=(a=e.type.spec).toDOM)==null?void 0:u.call(a,e,!0);if(!l)throw new Error(`Mark spec for ${e.type.name} is missing toDOM`);return C.useLayoutEffect(()=>{if(!s.current)return;const c=o[0],f=new YM(void 0,o,e,s.current,(c==null?void 0:c.dom.parentElement)??s.current);i.push(f);for(const d of o)d.parent=f}),b.jsx(pd,{ref:s,outputSpec:l,children:b.jsx(ht.Provider,{value:o,children:t})})});function pE({widget:n,pos:e}){const t=C.useContext(ht),r=C.useRef(null),i=C.useRef(e);return i.current=e,I1(o=>{if(!r.current)return;const s=n.type.toDOM;let l=typeof s=="function"?s(o,()=>i.current):s;if(!n.type.spec.raw){if(l.nodeType!=1){const a=document.createElement("span");a.appendChild(l),l=a}l.contentEditable="false",l.classList.add("ProseMirror-widget")}r.current.firstElementChild!==l&&r.current.replaceChildren(l)}),C.useLayoutEffect(()=>{if(!r.current)return;const o=new fd(void 0,n,r.current);t.push(o)}),b.jsx("span",{ref:r})}const mE=C.createContext(null);function q1({outerDeco:n,pos:e,node:t,innerDeco:r,...i}){var R,I;const o=C.useRef(null),s=C.useRef(null),l=C.useRef(null),a=C.useRef(t),u=C.useRef(n),c=C.useRef(r),f=C.useRef(e);f.current=e;const d=C.useRef(null),p=C.useRef(null),h=fa(),{nodeViews:m}=C.useContext(T1),{view:w}=C.useContext(es);let g=null;const y=m[t.type.name],S=w==null?void 0:w.someProp("nodeViews",D=>D==null?void 0:D[t.type.name]);C.useLayoutEffect(()=>{if(!p.current||!d.current)return;const{dom:D}=p.current;return s.current=d.current,d.current.appendChild(D),()=>{var H,pt;(pt=(H=p.current)==null?void 0:H.destroy)==null||pt.call(H)}},[]),C.useLayoutEffect(()=>{if(!S||!p.current)return;const{destroy:D,update:H}=p.current;if(((H==null?void 0:H.call(p.current,t,n,r))??!0)||(D==null||D.call(p.current),!d.current))return;a.current=t,u.current=n,c.current=r,p.current=S(a.current,w,()=>f.current,u.current,c.current);const{dom:zn}=p.current;s.current=d.current,d.current.appendChild(zn)},[S,w,r,t,n]);const{childDescriptors:x,setStopEvent:M}=_1(t,o,s,r,n,void 0,l);if(y)g=b.jsx(y,{...i,ref:s,nodeProps:{node:t,pos:e,decorations:n,innerDecorations:r,isSelected:h.selection instanceof z&&h.selection.node===t},children:b.jsx(co,{pos:e,node:t,innerDecorations:r})});else if(S){p.current||(p.current=S(a.current,w,()=>f.current,u.current,c.current));const{contentDOM:D}=p.current;l.current=D??null,g=C.createElement(t.isInline?"span":"div",{ref:d,contentEditable:!!D,suppressContentEditableWarning:!0},D&&li.createPortal(b.jsx(co,{pos:e,node:t,innerDecorations:r}),D))}else{const D=(I=(R=t.type.spec).toDOM)==null?void 0:I.call(R,t);D&&(g=b.jsx(pd,{...i,ref:s,outputSpec:D,children:b.jsx(co,{pos:e,node:t,innerDecorations:r})}))}if(!g)throw new Error(`Node spec for ${t.type.name} is missing toDOM`);const E=C.cloneElement(n.reduce(md,g),n.some(D=>D.type.attrs.nodeName)?{ref:o}:void 0),O=t.marks.reduce((D,H)=>b.jsx(K1,{mark:H,children:D}),E);return b.jsx(mE.Provider,{value:M,children:b.jsx(ht.Provider,{value:x,children:C.cloneElement(O,t.marks.length||n.some(D=>D.type.attrs.nodeName)?{ref:o}:void 0)})})}function gE(){const n=C.useContext(ht),e=C.useRef(null),[t,r]=C.useState(!1);return C.useLayoutEffect(()=>{var s;const i=n[n.length-1];if((Ne.safari||Ne.chrome)&&((s=i==null?void 0:i.dom)==null?void 0:s.contentEditable)=="false"){r(!0);return}if(!e.current)return;const o=new hd(void 0,[],e.current,null);n.push(o)}),t?b.jsx("img",{ref:e,className:"ProseMirror-separator"}):null}class yE extends C.Component{constructor(){super(...arguments),this.viewDescRef=null}updateEffect(){const{decorations:e,siblingDescriptors:t,node:r}=this.props,i=li.findDOMNode(this);if(!i)return;let o=i;for(;o.firstChild;)o=o.firstChild;!this.viewDescRef||this.viewDescRef instanceof QM?this.viewDescRef=new GM(void 0,[],r,e,_.empty,i,o):(this.viewDescRef.parent=void 0,this.viewDescRef.children=[],this.viewDescRef.node=r,this.viewDescRef.outerDeco=e,this.viewDescRef.innerDeco=_.empty,this.viewDescRef.dom=i,this.viewDescRef.dom.pmViewDesc=this.viewDescRef,this.viewDescRef.nodeDOM=o),t.push(this.viewDescRef)}componentDidMount(){this.updateEffect()}componentDidUpdate(){this.updateEffect()}render(){const{node:e,decorations:t}=this.props;return t.reduce(md,e.text)}}function SE(){const n=C.useContext(ht),e=C.useRef(null);return C.useLayoutEffect(()=>{if(!e.current)return;const t=new hd(void 0,[],e.current,null);n.push(t)}),b.jsx("br",{ref:e,className:"ProseMirror-trailingBreak"})}function wE({widget:n,pos:e}){const t=C.useContext(ht),r=C.useRef(null);C.useLayoutEffect(()=>{if(!r.current)return;const o=new fd(void 0,n,r.current);t.push(o)});const{Component:i}=n.type;return i&&b.jsx(i,{ref:r,widget:n,pos:e,contentEditable:!1})}function md(n,e){const{nodeName:t,...r}=e.type.attrs,i=j1(r);return t||typeof n=="string"?C.createElement(t??"span",i,n):C.cloneElement(n,H1(n.props,i))}function _c({innerPos:n,childViews:e}){const{view:t}=C.useContext(es),r=fa(),i=W1(),o=e.reduce((s,l)=>{var c;const a=s[s.length-1];if(!a)return[[l]];const u=a[a.length-1];return u?!l.marks.length&&!u.marks.length||l.marks.length&&u.marks.length&&((c=l.marks[0])!=null&&c.eq(u.marks[0]))?[...s.slice(0,s.length-1),[...a.slice(0,a.length),l]]:[...s,[l]]:[...s.slice(0,s.length),[l]]},[]);return b.jsx(b.Fragment,{children:o.map(s=>{const l=s[0];if(!l)return null;const a=l.marks[0];return a?b.jsx(K1,{mark:a,children:b.jsx(_c,{innerPos:n,childViews:s.map(u=>({...u,marks:u.marks.slice(1)}))},uo(r==null?void 0:r.doc,n,l,i==null?void 0:i.posToKey))},uo(r==null?void 0:r.doc,n,l,i==null?void 0:i.posToKey)):s.map(u=>{const c=n+u.offset,f=u.type==="widget"?b.jsx(wE,{widget:u.widget,pos:c}):u.type==="native-widget"?b.jsx(pE,{widget:u.widget,pos:c}):u.node.isText?b.jsx(ht.Consumer,{children:d=>b.jsx(yE,{view:t,node:u.node,pos:c,siblingDescriptors:d,decorations:u.outerDeco})}):b.jsx(q1,{node:u.node,pos:c,outerDeco:u.outerDeco,innerDeco:u.innerDeco});return C.cloneElement(f,{key:uo(r.doc,n,u,i==null?void 0:i.posToKey)})})})})}function uo(n,e,t,r){const i=e+t.offset,o=r==null?void 0:r.get(i);if(t.type==="widget"||t.type==="native-widget")return t.widget.type.spec.key?t.widget.type.spec.key:(console.warn(`Widget at position ${i} doesn't have a key specified. This has negative performance implications.`),`${o}-${t.index}`);if(o)return o;if(!n)return i;const s=n.resolve(i).start()-1,l=r==null?void 0:r.get(s);return l?`${l}-${t.offset}`:i}function kE(n){const e=n[n.length-1];if((e==null?void 0:e.type)!=="widget"&&(e==null?void 0:e.type)!=="native-widget"||e.widget.type.side>=0)return;let t=null;for(let i=n.length-2;i>=0;i--){const o=n[i];if((o==null?void 0:o.type)==="node"){t=o;break}}if(!t||!t.node.isInline)return;const r=t.marks;e.marks=e.marks.reduce((i,o)=>o.addToSet(i),r)}function vE(n){const e=n[n.length-1];if((e==null?void 0:e.type)!=="node"||!e.node.isInline)return;const t=e.marks;for(let r=n.length-2;r>=0;r--){const i=n[r];if((i==null?void 0:i.type)!=="widget"&&(i==null?void 0:i.type)!=="native-widget"||i.widget.type.side<0)break;i.marks=i.marks.reduce((o,s)=>s.addToSet(o),t)}}function xE(n,e,t,r){return n.length?n.every(i=>i.type!=="node"||i.node.isInline)?[b.jsx(_c,{childViews:n,innerPos:e},uo(t,e,n[0],r))]:n.map(i=>{if(i.type==="node"){const o=e+i.offset,s=(r==null?void 0:r.get(o))??o;return b.jsx(q1,{outerDeco:i.outerDeco,node:i.node,innerDeco:i.innerDeco,pos:o},s)}else return b.jsx(_c,{childViews:[i],innerPos:e},uo(t,e,i,r))}):[]}function co({pos:n,node:e,innerDecorations:t}){const r=fa(),i=W1();if(!e)return null;const o=n+1,s=[];uE(e,t,(u,c,f,d)=>{const p=u.type.spec.marks??[];c?s.push({type:"native-widget",widget:u,marks:p,offset:f,index:d}):s.push({type:"widget",widget:u,marks:p,offset:f,index:d}),kE(s)},(u,c,f,d)=>{s.push({type:"node",node:u,marks:u.marks,innerDeco:f,outerDeco:c,offset:d}),vE(s)});const l=xE(s,o,r.doc,i==null?void 0:i.posToKey),a=s[s.length-1];return(!a||a.type!=="node"||a.node.isInline&&!a.node.isText||/\n$/.test(a.node.text))&&l.push(b.jsx(gE,{},"trailing-hack-img"),b.jsx(SE,{},"trailing-hack-br")),b.jsx(b.Fragment,{children:l})}const CE=C.forwardRef(function({className:e,node:t,innerDeco:r,outerDeco:i,as:o,viewDesc:s,...l},a){const u=C.useRef(null);C.useImperativeHandle(a,()=>u.current,[]);const{childDescriptors:c}=_1(t,u,u,r,i,s),f={...l,ref:u,className:e,suppressContentEditableWarning:!0},d=o?C.cloneElement(o,f,b.jsx(ht.Provider,{value:c,children:b.jsx(co,{pos:-1,node:t,innerDecorations:r})})):C.createElement("div",f,b.jsx(ht.Provider,{value:c,children:b.jsx(co,{pos:-1,node:t,innerDecorations:r})}));if(!t)return d;const p=i.filter(m=>!m.inline);return p.length?p.reduce(md,d):d}),Q1=C.createContext(null);function NE({as:n,...e},t){const r=C.useRef(null),{setMount:i,...o}=C.useContext(Q1);return C.useImperativeHandle(t,()=>r.current,[]),b.jsx(ht.Provider,{value:[],children:b.jsx(CE,{ref:s=>{r.current=s,i(s)},...e,...o,as:n})})}const ME=C.forwardRef(NE);function EE({className:n,children:e,nodeViews:t={},customNodeViews:r,...i}){var c;const[o,s]=C.useState(null),l=sE(o,{...i,nodeViews:r}),a=l.view?kM(l.view,l.cursorWrapper):_.empty,u=l.view?gM(l.view):[];return b.jsx(es.Provider,{value:l,children:b.jsx(T1.Provider,{value:{nodeViews:t},children:b.jsx(Q1.Provider,{value:{className:n,setMount:s,node:(c=l.view)==null?void 0:c.state.doc,innerDeco:a,outerDeco:u,viewDesc:l.docViewDescRef.current},children:e})})})}function OE(n){return b.jsx(lE,{children:b.jsx(EE,{...n})})}const J=new Om({nodes:{doc:{content:"block+"},paragraph:{group:"block",content:"inline*",toDOM(){return["p",0]}},...Px({cellContent:"inline*",cellAttributes:{},tableGroup:"block"}),footnote:{group:"inline",content:"text*",inline:!0,atom:!0,attrs:{number:{default:0}}},list:{group:"block",content:"list_item+",toDOM(){return["ul",0]}},list_item:{content:"paragraph+",toDOM(){return["li",0]}},image:{group:"block",toDOM(){return["div",["img",{src:"https://smoores.gitlab.io/storyteller/img/Storyteller_Logo.png",height:150,width:150}]]}},text:{group:"inline"}},marks:{em:{toDOM(){return["em",0]}},strong:{toDOM(){return["strong",0]}}}}),DE=un.create({schema:J,doc:J.nodes.doc.create({},[J.nodes.paragraph.create({},[J.text("This ",[J.marks.em.create()]),J.text("is",[J.marks.em.create(),J.marks.strong.create()]),J.text(" the first paragraph")]),J.nodes.paragraph.create({},[J.text("This is the second paragraph"),J.nodes.footnote.create({number:1},J.text("Footnote"))]),J.nodes.paragraph.create(),J.nodes.image.create(),J.nodes.image.create(),J.nodes.paragraph.create({},J.text("This is the third paragraph 🫵")),J.nodes.table.create({},[J.nodes.table_row.create({},[J.nodes.table_header.create({},J.text("h1")),J.nodes.table_header.create({},J.text("h2"))]),J.nodes.table_row.create({},[J.nodes.table_cell.create({},J.text("c1")),J.nodes.table_cell.create({},J.text("c2"))])])]),plugins:[TM(),Zv({rules:[ex(/^\s*([-+*])\s$/,J.nodes.list)]}),eC(),dC()]}),TE=C.forwardRef(function({children:e,nodeProps:t,...r},i){return b.jsx("p",{ref:i,...r,children:e})}),RE=C.forwardRef(function({children:e,nodeProps:t,...r},i){return b.jsx("ul",{ref:i,...r,children:e})}),AE=C.forwardRef(function({children:e,nodeProps:t,...r},i){return b.jsx("li",{ref:i,...r,children:e})}),bE=C.forwardRef(function({nodeProps:e,...t},r){return b.jsx("span",{ref:r,...t,suppressContentEditableWarning:!0,contentEditable:"false",children:b.jsx("button",{children:e.node.attrs.number})})}),IE=C.forwardRef(function({widget:e,pos:t,...r},i){return b.jsx("span",{...r,ref:i,style:{display:"block",backgroundColor:"blue",width:"4px",height:"4px",position:"absolute",transform:"translateX(-2px)"},children:"Widget"})}),zE=new Lt({view(n){const e=n.coordsAtPos(n.state.selection.from),t=document.createElement("div");return t.style.width="4px",t.style.height="4px",t.style.position="absolute",t.style.top=`${e.top-2}px`,t.style.left=`${e.left-2}px`,t.style.backgroundColor="blue",document.body.appendChild(t),{update(r){const i=r.coordsAtPos(r.state.selection.from);t.style.top=`${i.top-2}px`,t.style.left=`${i.left-2}px`},destroy(){document.body.removeChild(t)}}}});new Lt({props:{decorations(n){return _.create(n.doc,[z1(n.selection.from,IE,{side:0,key:"widget-plugin-widget"})])}},view(n){const e=n.coordsAtPos(n.state.selection.from),t=document.createElement("div");return t.style.width="4px",t.style.height="4px",t.style.position="absolute",t.style.top=`${e.top-2}px`,t.style.left=`${e.left-2}px`,t.style.backgroundColor="blue",document.body.appendChild(t),{update(r){const i=r.coordsAtPos(r.state.selection.from);t.style.top=`${i.top-2}px`,t.style.left=`${i.left-2}px`},destroy(){document.body.removeChild(t)}}}});const PE=[ix({...Vw,"Mod-i":Vd(J.marks.em),"Mod-b":Vd(J.marks.strong)}),zE,Fv()],FE={paragraph:()=>{const n=document.createElement("p");return{dom:n,contentDOM:n}}};function LE(){const[n,e]=C.useState(DE),[t,r]=C.useState(!0);return b.jsxs("main",{children:[b.jsx("h1",{children:"React ProseMirror Demo"}),b.jsxs("button",{onClick:()=>{t?r(i=>!i):window.location.reload()},children:["Switch to"," ",t?"ProseMirror node views":"React node views (requires reload)"]}),b.jsx(OE,{className:"ProseMirror",state:n,dispatchTransaction:function(i){e(o=>o.apply(i))},plugins:PE,nodeViews:t?{paragraph:TE,list:RE,list_item:AE,footnote:bE}:void 0,customNodeViews:t?void 0:FE,children:b.jsx(ME,{as:b.jsx("article",{})})},`${t}`)]})}const $E=D1(document.getElementById("root"));$E.render(b.jsx(C.StrictMode,{children:b.jsx(LE,{})})); diff --git a/docs/assets/index-k0PL4xKq.js b/docs/assets/index-k0PL4xKq.js new file mode 100644 index 00000000..2b1c782d --- /dev/null +++ b/docs/assets/index-k0PL4xKq.js @@ -0,0 +1,53 @@ +(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const o of i)if(o.type==="childList")for(const s of o.addedNodes)s.tagName==="LINK"&&s.rel==="modulepreload"&&r(s)}).observe(document,{childList:!0,subtree:!0});function t(i){const o={};return i.integrity&&(o.integrity=i.integrity),i.referrerPolicy&&(o.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?o.credentials="include":i.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function r(i){if(i.ep)return;i.ep=!0;const o=t(i);fetch(i.href,o)}})();function nS(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var um={exports:{}},Xl={},cm={exports:{}},V={};/** + * @license React + * react.production.min.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */var Ko=Symbol.for("react.element"),rS=Symbol.for("react.portal"),iS=Symbol.for("react.fragment"),oS=Symbol.for("react.strict_mode"),sS=Symbol.for("react.profiler"),lS=Symbol.for("react.provider"),aS=Symbol.for("react.context"),uS=Symbol.for("react.forward_ref"),cS=Symbol.for("react.suspense"),fS=Symbol.for("react.memo"),dS=Symbol.for("react.lazy"),Cd=Symbol.iterator;function hS(n){return n===null||typeof n!="object"?null:(n=Cd&&n[Cd]||n["@@iterator"],typeof n=="function"?n:null)}var fm={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},dm=Object.assign,hm={};function hi(n,e,t){this.props=n,this.context=e,this.refs=hm,this.updater=t||fm}hi.prototype.isReactComponent={};hi.prototype.setState=function(n,e){if(typeof n!="object"&&typeof n!="function"&&n!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,n,e,"setState")};hi.prototype.forceUpdate=function(n){this.updater.enqueueForceUpdate(this,n,"forceUpdate")};function pm(){}pm.prototype=hi.prototype;function Yc(n,e,t){this.props=n,this.context=e,this.refs=hm,this.updater=t||fm}var Gc=Yc.prototype=new pm;Gc.constructor=Yc;dm(Gc,hi.prototype);Gc.isPureReactComponent=!0;var Nd=Array.isArray,mm=Object.prototype.hasOwnProperty,Xc={current:null},gm={key:!0,ref:!0,__self:!0,__source:!0};function ym(n,e,t){var r,i={},o=null,s=null;if(e!=null)for(r in e.ref!==void 0&&(s=e.ref),e.key!==void 0&&(o=""+e.key),e)mm.call(e,r)&&!gm.hasOwnProperty(r)&&(i[r]=e[r]);var l=arguments.length-2;if(l===1)i.children=t;else if(1>1}};pe.from=function(n){if(n instanceof pe)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new pe(e)};function wm(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),o=e.child(r);if(i==o){t+=i.nodeSize;continue}if(!i.sameMarkup(o))return t;if(i.isText&&i.text!=o.text){for(let s=0;i.text[s]==o.text[s];s++)t++;return t}if(i.content.size||o.content.size){let s=wm(i.content,o.content,t+1);if(s!=null)return s}t+=i.nodeSize}}function km(n,e,t,r){for(let i=n.childCount,o=e.childCount;;){if(i==0||o==0)return i==o?null:{a:t,b:r};let s=n.child(--i),l=e.child(--o),a=s.nodeSize;if(s==l){t-=a,r-=a;continue}if(!s.sameMarkup(l))return{a:t,b:r};if(s.isText&&s.text!=l.text){let u=0,c=Math.min(s.text.length,l.text.length);for(;ue&&r(a,i+l,o||null,s)!==!1&&a.content.size){let c=l+1;a.nodesBetween(Math.max(0,e-c),Math.min(a.content.size,t-c),r,i+c)}l=u}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let o="",s=!0;return this.nodesBetween(e,t,(l,a)=>{let u=l.isText?l.text.slice(Math.max(e,a)-a,t-a):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&u||l.isTextblock)&&r&&(s?s=!1:o+=r),o+=u},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),o=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),o=1);oe)for(let o=0,s=0;se&&((st)&&(l.isText?l=l.cut(Math.max(0,e-s),Math.min(l.text.length,t-s)):l=l.cut(Math.max(0,e-s-1),Math.min(l.content.size,t-s-1))),r.push(l),i+=l.nodeSize),s=a}return new C(r,i)}cutByIndex(e,t){return e==t?C.empty:e==0&&t==this.content.length?this:new C(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),o=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new C(i,o)}addToStart(e){return new C([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new C(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let o=this.child(r),s=i+o.nodeSize;if(s>=e)return s==e||t>0?fs(r+1,s):fs(r,i);i=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return C.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new C(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return C.empty;let t,r=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(o)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}}W.none=[];class Dn extends Error{}class v{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=xm(this.content,e+this.openStart,t);return r&&new v(r,this.openStart,this.openEnd)}removeBetween(e,t){return new v(vm(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 v.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new v(C.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let o=e.firstChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.lastChild)i++;return new v(e,r,i)}}v.empty=new v(C.empty,0,0);function vm(n,e,t){let{index:r,offset:i}=n.findIndex(e),o=n.maybeChild(r),{index:s,offset:l}=n.findIndex(t);if(i==e||o.isText){if(l!=t&&!n.child(s).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=s)throw new RangeError("Removing non-flat range");return n.replaceChild(r,o.copy(vm(o.content,e-i-1,t-i-1)))}function xm(n,e,t,r){let{index:i,offset:o}=n.findIndex(e),s=n.maybeChild(i);if(o==e||s.isText)return n.cut(0,e).append(t).append(n.cut(e));let l=xm(s.content,e-o-1,t);return l&&n.replaceChild(i,s.copy(l))}function NS(n,e,t){if(t.openStart>n.depth)throw new Dn("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Dn("Inconsistent open depths");return Cm(n,e,t,0)}function Cm(n,e,t,r){let i=n.index(r),o=n.node(r);if(i==e.index(r)&&r=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function eo(n,e,t,r){let i=(e||n).node(t),o=0,s=e?e.index(t):i.childCount;n&&(o=n.index(t),n.depth>t?o++:n.textOffset&&(Zn(n.nodeAfter,r),o++));for(let l=o;li&&Mu(n,e,i+1),s=r.depth>i&&Mu(t,r,i+1),l=[];return eo(null,n,i,l),o&&s&&e.index(i)==t.index(i)?(Nm(o,s),Zn(er(o,Mm(n,e,t,r,i+1)),l)):(o&&Zn(er(o,pl(n,e,i+1)),l),eo(e,t,i,l),s&&Zn(er(s,pl(t,r,i+1)),l)),eo(r,null,i,l),new C(l)}function pl(n,e,t){let r=[];if(eo(null,n,t,r),n.depth>t){let i=Mu(n,e,t+1);Zn(er(i,pl(n,e,t+1)),r)}return eo(e,null,t,r),new C(r)}function MS(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let o=t-1;o>=0;o--)i=e.node(o).copy(C.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}class go{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let o=0;o0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new DS(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,o=t;for(let s=e;;){let{index:l,offset:a}=s.content.findIndex(o),u=o-a;if(r.push(s,l,i+a),!u||(s=s.child(l),s.isText))break;o=u-1,i+=a+1}return new go(t,r,o)}static resolveCached(e,t){let r=Ed.get(e);if(r)for(let o=0;oe&&this.nodesBetween(e,t,o=>(r.isInSet(o.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),Em(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=C.empty,i=0,o=r.childCount){let s=this.contentMatchAt(e).matchFragment(r,i,o),l=s&&s.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let a=i;at.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=C.fromJSON(e,t.content),o=e.nodeType(t.type).create(t.attrs,i,r);return o.type.checkAttrs(o.attrs),o}}Tt.prototype.text=void 0;class ml extends Tt{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Em(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 ml(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new ml(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function Em(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}class or{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new RS(e,t);if(r.next==null)return or.empty;let i=Om(r);r.next&&r.err("Unexpected trailing text");let o=LS(FS(i));return $S(o,r),o}matchType(e){for(let t=0;tu.createAndFill()));for(let u=0;u=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(r){e.push(r);for(let i=0;i{let o=i+(r.validEnd?"*":" ")+" ";for(let s=0;s"+e.indexOf(r.next[s].next);return o}).join(` +`)}}or.empty=new or(!0);class RS{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 Om(n){let e=[];do e.push(AS(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function AS(n){let e=[];do e.push(bS(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function bS(n){let e=PS(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=IS(n,e);else break;return e}function Od(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function IS(n,e){let t=Od(n),r=t;return n.eat(",")&&(n.next!="}"?r=Od(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function zS(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let o in t){let s=t[o];s.groups.indexOf(e)>-1&&i.push(s)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function PS(n){if(n.eat("(")){let e=Om(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=zS(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function FS(n){let e=[[]];return i(o(n,0),t()),e;function t(){return e.push([])-1}function r(s,l,a){let u={term:a,to:l};return e[s].push(u),u}function i(s,l){s.forEach(a=>a.to=l)}function o(s,l){if(s.type=="choice")return s.exprs.reduce((a,u)=>a.concat(o(u,l)),[]);if(s.type=="seq")for(let a=0;;a++){let u=o(s.exprs[a],l);if(a==s.exprs.length-1)return u;i(u,l=t())}else if(s.type=="star"){let a=t();return r(l,a),i(o(s.expr,a),a),[r(a)]}else if(s.type=="plus"){let a=t();return i(o(s.expr,l),a),i(o(s.expr,a),a),[r(a)]}else{if(s.type=="opt")return[r(l)].concat(o(s.expr,l));if(s.type=="range"){let a=l;for(let u=0;u{n[s].forEach(({term:l,to:a})=>{if(!l)return;let u;for(let c=0;c{u||i.push([l,u=[]]),u.indexOf(c)==-1&&u.push(c)})})});let o=e[r.join(",")]=new or(r.indexOf(n.length-1)>-1);for(let s=0;s-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[o]=new Im(o,t,s));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let o in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function VS(n,e,t){let r=t.split("|");return i=>{let o=i===null?"null":typeof i;if(r.indexOf(o)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${o}`)}}class BS{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?VS(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}}class qo{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=bm(e,i.attrs),this.excluded=null;let o=Tm(this.attrs);this.instance=o?new W(this,o):null}create(e=null){return!e&&this.instance?this.instance:new W(this,Rm(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((o,s)=>r[o]=new qo(o,i++,t,s)),r}removeFromSet(e){for(var t=0;t-1}}class zm{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=pe.from(e.nodes),t.marks=pe.from(e.marks||{}),this.nodes=Td.compile(this.spec.nodes,this),this.marks=qo.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let o=this.nodes[i],s=o.spec.content||"",l=o.spec.marks;if(o.contentMatch=r[s]||(r[s]=or.parse(s,this.nodes)),o.inlineContent=o.contentMatch.inlineContent,o.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!o.isInline||!o.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=o}o.markSet=l=="_"?null:l?Rd(this,l.split(" ")):l==""||!o.inlineContent?[]:null}for(let i in this.marks){let o=this.marks[i],s=o.spec.excludes;o.excluded=s==null?[o]:s==""?[]:Rd(this,s.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Td){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,r,i)}text(e,t){let r=this.nodes.text;return new ml(r,r.defaultAttrs,e,W.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return Tt.fromJSON(this,e)}markFromJSON(e){return W.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function Rd(n,e){let t=[];for(let r=0;r-1)&&t.push(s=a)}if(!s)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function JS(n){return n.tag!=null}function _S(n){return n.style!=null}class yo{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(JS(i))this.tags.push(i);else if(_S(i)){let o=/[^=]*/.exec(i.style)[0];r.indexOf(o)<0&&r.push(o),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let o=e.nodes[i.node];return o.contentMatch.matchType(o)})}parse(e,t={}){let r=new bd(this,t,!1);return r.addAll(e,W.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new bd(this,t,!0);return r.addAll(e,W.none,t.from,t.to),v.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(s.getAttrs){let a=s.getAttrs(t);if(a===!1)continue;s.attrs=a||void 0}return s}}}static schemaRules(e){let t=[];function r(i){let o=i.priority==null?50:i.priority,s=0;for(;s{r(s=Id(s)),s.mark||s.ignore||s.clearMark||(s.mark=i)})}for(let i in e.nodes){let o=e.nodes[i].spec.parseDOM;o&&o.forEach(s=>{r(s=Id(s)),s.node||s.ignore||s.mark||(s.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new yo(e,yo.schemaRules(e)))}}const Pm={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},WS={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Fm={ol:!0,ul:!0},gl=1,yl=2,to=4;function Ad(n,e,t){return e!=null?(e?gl:0)|(e==="full"?yl:0):n&&n.whitespace=="pre"?gl|yl:t&~to}class ds{constructor(e,t,r,i,o,s){this.type=e,this.attrs=t,this.marks=r,this.solid=i,this.options=s,this.content=[],this.activeMarks=W.none,this.match=o||(s&to?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(C.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&gl)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-i[0].length))}}let t=C.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(C.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Pm.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class bd{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0;let i=t.topNode,o,s=Ad(null,t.preserveWhitespace,0)|(r?to:0);i?o=new ds(i.type,i.attrs,W.none,!0,t.topMatch||i.type.contentMatch,s):r?o=new ds(null,null,W.none,!0,null,s):o=new ds(e.schema.topNodeType,null,W.none,!0,null,s),this.nodes=[o],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,i=this.top;if(i.options&yl||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(i.options&gl)i.options&yl?r=r.replace(/\r\n?/g,` +`):r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let o=i.content[i.content.length-1],s=e.previousSibling;(!o||s&&s.nodeName=="BR"||o.isText&&/[ \t\r\n\u000c]$/.test(o.text))&&(r=r.slice(1))}r&&this.insertNode(this.parser.schema.text(r),t),this.findInText(e)}else this.findInside(e)}addElement(e,t,r){let i=e.nodeName.toLowerCase(),o;Fm.hasOwnProperty(i)&&this.parser.normalizeLists&&US(e);let s=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(o=this.parser.matchTag(e,this,r));if(s?s.ignore:WS.hasOwnProperty(i))this.findInside(e),this.ignoreFallback(e,t);else if(!s||s.skip||s.closeParent){s&&s.closeParent?this.open=Math.max(0,this.open-1):s&&s.skip.nodeType&&(e=s.skip);let l,a=this.top,u=this.needsBlock;if(Pm.hasOwnProperty(i))a.content.length&&a.content[0].isInline&&this.open&&(this.open--,a=this.top),l=!0,a.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);return}let c=s&&s.skip?t:this.readStyles(e,t);c&&this.addAll(e,c),l&&this.sync(a),this.needsBlock=u}else{let l=this.readStyles(e,t);l&&this.addElementByRule(e,s,l,s.consuming===!1?o:void 0)}}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` +`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let r=e.style;if(r&&r.length)for(let i=0;i!a.clearMark(u)):t=t.concat(this.parser.schema.marks[a.mark].create(a.attrs)),a.consuming===!1)l=a;else break}}return t}addElementByRule(e,t,r,i){let o,s;if(t.node)if(s=this.parser.schema.nodes[t.node],s.isLeaf)this.insertNode(s.create(t.attrs),r)||this.leafFallback(e,r);else{let a=this.enter(s,t.attrs||null,r,t.preserveWhitespace);a&&(o=!0,r=a)}else{let a=this.parser.schema.marks[t.mark];r=r.concat(a.create(t.attrs))}let l=this.top;if(s&&s.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a,r));else{let a=e;typeof t.contentElement=="string"?a=e.querySelector(t.contentElement):typeof t.contentElement=="function"?a=t.contentElement(e):t.contentElement&&(a=t.contentElement),this.findAround(e,a,!0),this.addAll(a,r)}o&&this.sync(l)&&this.open--}addAll(e,t,r,i){let o=r||0;for(let s=r?e.childNodes[r]:e.firstChild,l=i==null?null:e.childNodes[i];s!=l;s=s.nextSibling,++o)this.findAtPoint(e,o),this.addDOM(s,t);this.findAtPoint(e,o)}findPlace(e,t){let r,i;for(let o=this.open;o>=0;o--){let s=this.nodes[o],l=s.findWrapping(e);if(l&&(!r||r.length>l.length)&&(r=l,i=s,!l.length)||s.solid)break}if(!r)return null;this.sync(i);for(let o=0;o(s.type?s.type.allowsMarkType(u.type):zd(u.type,e))?(a=u.addToSet(a),!1):!0),this.nodes.push(new ds(e,t,a,i,null,l)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(i?0:1),s=(l,a)=>{for(;l>=0;l--){let u=t[l];if(u==""){if(l==t.length-1||l==0)continue;for(;a>=o;a--)if(s(l-1,a))return!0;return!1}else{let c=a>0||a==0&&i?this.nodes[a].type:r&&a>=o?r.node(a-o).type:null;if(!c||c.name!=u&&c.groups.indexOf(u)==-1)return!1;a--}}return!0};return s(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}}function US(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&Fm.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function HS(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function Id(n){let e={};for(let t in n)e[t]=n[t];return e}function zd(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let o=[],s=l=>{o.push(l);for(let a=0;a{if(o.length||s.marks.length){let l=0,a=0;for(;l=0;i--){let o=this.serializeMark(e.marks[i],e.isInline,t);o&&((o.contentDOM||o.dom).appendChild(r),r=o.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&Vs(va(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return Vs(e,t,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new pi(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=Pd(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return Pd(e.marks)}}function Pd(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function va(n){return n.document||window.document}const Fd=new WeakMap;function jS(n){let e=Fd.get(n);return e===void 0&&Fd.set(n,e=KS(n)),e}function KS(n){let e=null;function t(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let s=i.indexOf(" ");s>0&&(t=i.slice(0,s),i=i.slice(s+1));let l,a=t?n.createElementNS(t,i):n.createElement(i),u=e[1],c=1;if(u&&typeof u=="object"&&u.nodeType==null&&!Array.isArray(u)){c=2;for(let f in u)if(u[f]!=null){let d=f.indexOf(" ");d>0?a.setAttributeNS(f.slice(0,d),f.slice(d+1),u[f]):a.setAttribute(f,u[f])}}for(let f=c;fc)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}else{let{dom:p,contentDOM:h}=Vs(n,d,t,r);if(a.appendChild(p),h){if(l)throw new RangeError("Multiple content holes");l=h}}}return{dom:a,contentDOM:l}}const Lm=65535,$m=Math.pow(2,16);function qS(n,e){return n+e*$m}function Ld(n){return n&Lm}function QS(n){return(n-(n&Lm))/$m}const Vm=1,Bm=2,Bs=4,Jm=8;let $d=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&Jm)>0}get deletedBefore(){return(this.delInfo&(Vm|Bs))>0}get deletedAfter(){return(this.delInfo&(Bm|Bs))>0}get deletedAcross(){return(this.delInfo&Bs)>0}},qr=class kr{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&kr.empty)return kr.empty}recover(e){let t=0,r=Ld(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],f=a+u;if(e<=f){let d=u?e==a?-1:e==f?1:t:t,p=a+i+(d<0?0:c);if(r)return p;let h=e==(t<0?a:f)?null:qS(l/3,e-a),m=e==a?Bm:e==f?Vm:Bs;return(t<0?e!=a:e!=f)&&(m|=Jm),new $d(p,m,h)}i+=c-u}return r?e+i:new $d(e+i,0,null)}touches(e,t){let r=0,i=Ld(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return $e.fromReplace(e,this.from,this.to,o)}invert(){return new Wm(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new Di(t.pos,r.pos,this.mark)}merge(e){return e instanceof Di&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Di(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Di(t.from,t.to,e.markFromJSON(t.mark))}};Ke.jsonID("addMark",_m);let Wm=class Ti extends Ke{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new v(ef(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return $e.fromReplace(e,this.from,this.to,r)}invert(){return new _m(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new Ti(t.pos,r.pos,this.mark)}merge(e){return e instanceof Ti&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Ti(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Ti(t.from,t.to,e.markFromJSON(t.mark))}};Ke.jsonID("removeMark",Wm);let Um=class Ri extends Ke{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return $e.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return $e.fromReplace(e,this.pos,this.pos+1,new v(C.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new Js(t.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Js(t.from,t.to,t.gapFrom,t.gapTo,v.fromJSON(e,t.slice),t.insert,!!t.structure)}};Ke.jsonID("replaceAround",Sl);function Ou(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function YS(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function nf(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),o=n.$from.index(r),s=n.$to.indexAfter(r);if(ro;u--,c--){let f=i.node(u),d=i.index(u);if(f.type.spec.isolating)return!1;let p=f.content.cutByIndex(d,f.childCount),h=r&&r[c]||f;if(h!=f&&(p=p.replaceChild(0,h.type.create(h.attrs))),!f.canReplace(d+1,f.childCount)||!h.type.validContent(p))return!1}let l=i.indexAfter(o),a=r&&r[0];return i.node(o).canReplaceWith(l,l,a?a.type:i.node(o+1).type)}function jm(n,e){let t=n.resolve(e),r=t.index();return GS(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function GS(n,e){return!!(n&&e&&!n.isLeaf&&n.canAppend(e))}function Km(n,e,t=e,r=v.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),o=n.resolve(t);return XS(i,o,r)?new tf(e,t,r):new ZS(i,o,r).fit()}function XS(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}let ZS=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=C.empty;for(let i=0;i<=e.depth;i++){let o=e.node(i);this.frontier.push({type:o.type,match:o.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=C.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let u=this.findFittable();u?this.placeNodes(u):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let a=new v(o,s,l);return e>-1?new Sl(r.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||r.pos!=this.$to.pos?new tf(r.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),o.type.spec.isolating&&i<=r){e=r;break}t=o.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=Ca(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:u}=this.frontier[l],c,f=null;if(t==1&&(s?u.matchType(s.type)||(f=u.fillBefore(C.from(s),!1)):o&&a.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:f};if(t==2&&s&&(c=u.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:c};if(o&&u.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Ca(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new v(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Ca(e,t);if(i.childCount<=1&&t>0){let o=e.size-t<=t+i.size;this.unplaced=new v(Ai(e,t-1,1),t-1,o?t-1:r)}else this.unplaced=new v(Ai(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:o}){for(;this.depth>t;)this.closeFrontierNode();if(o)for(let m=0;m1||a==0||m.content.size)&&(f=w,c.push(qm(m.mark(d.allowedMarks(m.marks)),u==1?a:0,u==l.childCount?p:-1)))}let h=u==l.childCount;h||(p=-1),this.placed=bi(this.placed,t,C.from(c)),this.frontier[t].match=f,h&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,w=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],o=t=0;l--){let{match:a,type:u}=this.frontier[l],c=Na(e,l,u,a,!0);if(!c||c.childCount)continue e}return{depth:t,fit:s,move:o?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=bi(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=bi(this.placed,this.depth,C.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(C.empty,!0);t.childCount&&(this.placed=bi(this.placed,this.frontier.length,t))}};function Ai(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Ai(n.firstChild.content,e-1,t)))}function bi(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(bi(n.lastChild.content,e-1,t)))}function Ca(n,e){for(let t=0;t1&&(r=r.replaceChild(0,qm(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(C.empty,!0)))),n.copy(r)}function Na(n,e,t,r,i){let o=n.node(e),s=i?n.indexAfter(e):n.index(e);if(s==o.childCount&&!t.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!ew(t,o.content,s)?l:null}function ew(n,e,t){for(let r=t;r0}get deletedBefore(){return(this.delInfo&(Gm|Us))>0}get deletedAfter(){return(this.delInfo&(Xm|Us))>0}get deletedAcross(){return(this.delInfo&Us)>0}},Qr=class vr{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&vr.empty)return vr.empty}recover(e){let t=0,r=Vd(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],f=a+u;if(e<=f){let d=u?e==a?-1:e==f?1:t:t,p=a+i+(d<0?0:c);if(r)return p;let h=e==(t<0?a:f)?null:nw(l/3,e-a),m=e==a?Xm:e==f?Gm:Us;return(t<0?e!=a:e!=f)&&(m|=Zm),new Du(p,m,h)}i+=c-u}return r?e+i:new Du(e+i,0,null)}touches(e,t){let r=0,i=Vd(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new Hs;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;ro&&a!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return Ve.fromReplace(e,this.from,this.to,o)}invert(){return new Qo(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new zi(t.pos,r.pos,this.mark)}merge(e){return e instanceof zi&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new zi(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new zi(t.from,t.to,e.markFromJSON(t.mark))}};qe.jsonID("addMark",of);let Qo=class Pi extends qe{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new v(rf(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return Ve.fromReplace(e,this.from,this.to,r)}invert(){return new of(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new Pi(t.pos,r.pos,this.mark)}merge(e){return e instanceof Pi&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Pi(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Pi(t.from,t.to,e.markFromJSON(t.mark))}};qe.jsonID("removeMark",Qo);let sf=class Fi extends qe{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Ve.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return Ve.fromReplace(e,this.pos,this.pos+1,new v(C.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new js(t.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new js(t.from,t.to,t.gapFrom,t.gapTo,v.fromJSON(e,t.slice),t.insert,!!t.structure)}};qe.jsonID("replaceAround",dr);function Ru(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function ow(n,e,t,r){let i=[],o=[],s,l;n.doc.nodesBetween(e,t,(a,u,c)=>{if(!a.isInline)return;let f=a.marks;if(!r.isInSet(f)&&c.type.allowsMarkType(r.type)){let d=Math.max(u,e),p=Math.min(u+a.nodeSize,t),h=r.addToSet(f);for(let m=0;mn.step(a)),o.forEach(a=>n.step(a))}function sw(n,e,t,r){let i=[],o=0;n.doc.nodesBetween(e,t,(s,l)=>{if(!s.isInline)return;o++;let a=null;if(r instanceof qo){let u=s.marks,c;for(;c=r.isInSet(u);)(a||(a=[])).push(c),u=c.removeFromSet(u)}else r?r.isInSet(s.marks)&&(a=[r]):a=s.marks;if(a&&a.length){let u=Math.min(l+s.nodeSize,t);for(let c=0;cn.step(new Qo(s.from,s.to,s.style)))}function lw(n,e,t,r=t.contentMatch){let i=n.doc.nodeAt(e),o=[],s=e+1;for(let l=0;l=0;l--)n.step(o[l])}function aw(n,e,t){let{$from:r,$to:i,depth:o}=e,s=r.before(o+1),l=i.after(o+1),a=s,u=l,c=C.empty,f=0;for(let h=o,m=!1;h>t;h--)m||r.index(h)>0?(m=!0,c=C.from(r.node(h).copy(c)),f++):a--;let d=C.empty,p=0;for(let h=o,m=!1;h>t;h--)m||i.after(h+1)=0;s--){if(r.size){let l=t[s].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=C.from(t[s].type.create(t[s].attrs,r))}let i=e.start,o=e.end;n.step(new dr(i,o,i,o,new v(r,0,0),t.length,!0))}function cw(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=n.steps.length;n.doc.nodesBetween(e,t,(s,l)=>{if(s.isTextblock&&!s.hasMarkup(r,i)&&fw(n.doc,n.mapping.slice(o).map(l),r)){n.clearIncompatible(n.mapping.slice(o).map(l,1),r);let a=n.mapping.slice(o),u=a.map(l,1),c=a.map(l+s.nodeSize,1);return n.step(new dr(u,c,u+1,c-1,new v(C.from(r.create(i,null,s.marks)),0,0),1,!0)),!1}})}function fw(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function dw(n,e,t,r,i){let o=n.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");t||(t=o.type);let s=t.create(r,null,i||o.marks);if(o.isLeaf)return n.replaceWith(e,e+o.nodeSize,s);if(!t.validContent(o.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new dr(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new v(C.from(s),0,0),1,!0))}function hw(n,e,t=1,r){let i=n.doc.resolve(e),o=C.empty,s=C.empty;for(let l=i.depth,a=i.depth-t,u=t-1;l>a;l--,u--){o=C.from(i.node(l).copy(o));let c=r&&r[u];s=C.from(c?c.type.create(c.attrs,s):i.node(l).copy(s))}n.step(new An(e,e,new v(o.append(s),t,t),!0))}function pw(n,e,t){let r=new An(e-t,e+t,v.empty,!0);n.step(r)}function mw(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let o=r.index(i);if(r.node(i).canReplaceWith(o,o,t))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,t))return r.after(i+1);if(o0;i--)this.placed=C.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let u=this.findFittable();u?this.placeNodes(u):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let a=new v(o,s,l);return e>-1?new dr(r.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||r.pos!=this.$to.pos?new An(r.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),o.type.spec.isolating&&i<=r){e=r;break}t=o.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=Ea(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:u}=this.frontier[l],c,f=null;if(t==1&&(s?u.matchType(s.type)||(f=u.fillBefore(C.from(s),!1)):o&&a.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:f};if(t==2&&s&&(c=u.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:c};if(o&&u.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Ea(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new v(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Ea(e,t);if(i.childCount<=1&&t>0){let o=e.size-t<=t+i.size;this.unplaced=new v(Li(e,t-1,1),t-1,o?t-1:r)}else this.unplaced=new v(Li(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:o}){for(;this.depth>t;)this.closeFrontierNode();if(o)for(let m=0;m1||a==0||m.content.size)&&(f=w,c.push(tg(m.mark(d.allowedMarks(m.marks)),u==1?a:0,u==l.childCount?p:-1)))}let h=u==l.childCount;h||(p=-1),this.placed=$i(this.placed,t,C.from(c)),this.frontier[t].match=f,h&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,w=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],o=t=0;l--){let{match:a,type:u}=this.frontier[l],c=Oa(e,l,u,a,!0);if(!c||c.childCount)continue e}return{depth:t,fit:s,move:o?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=$i(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=$i(this.placed,this.depth,C.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(C.empty,!0);t.childCount&&(this.placed=$i(this.placed,this.frontier.length,t))}};function Li(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Li(n.firstChild.content,e-1,t)))}function $i(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy($i(n.lastChild.content,e-1,t)))}function Ea(n,e){for(let t=0;t1&&(r=r.replaceChild(0,tg(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(C.empty,!0)))),n.copy(r)}function Oa(n,e,t,r,i){let o=n.node(e),s=i?n.indexAfter(e):n.index(e);if(s==o.childCount&&!t.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!Sw(t,o.content,s)?l:null}function Sw(n,e,t){for(let r=t;r0;d--,p--){let h=i.node(d).type.spec;if(h.defining||h.definingAsContext||h.isolating)break;s.indexOf(d)>-1?l=d:i.before(d)==p&&s.splice(1,0,-d)}let a=s.indexOf(l),u=[],c=r.openStart;for(let d=r.content,p=0;;p++){let h=d.firstChild;if(u.push(h),p==r.openStart)break;d=h.content}for(let d=c-1;d>=0;d--){let p=u[d].type,h=ww(p);if(h&&i.node(a).type!=p)c=d;else if(h||!p.isTextblock)break}for(let d=r.openStart;d>=0;d--){let p=(d+c+1)%(r.openStart+1),h=u[p];if(h)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>f));d--){let p=s[d];p<0||(e=i.before(p),t=o.after(p))}}function ng(n,e,t,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(n).append(n);n=s.append(o.matchFragment(s).fillBefore(C.empty,!0))}return n}function vw(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=mw(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new v(C.from(r),0,0))}function xw(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),o=rg(r,i);for(let s=0;s0&&(a||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&t>r.end(s)&&i.end(s)-t!=i.depth-s)return n.delete(r.before(s),t);n.delete(e,t)}function rg(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let o=n.start(i);if(oe.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&t.push(i)}return t}let ig=class Ks extends qe{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return Ve.fail("No node at attribute step's position");let r=Object.create(null);for(let o in t.attrs)r[o]=t.attrs[o];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return Ve.fromReplace(e,this.pos,this.pos+1,new v(C.from(i),0,t.isLeaf?0:1))}getMap(){return Qr.empty}invert(e){return new Ks(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 Ks(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new Ks(t.pos,t.attr,t.value)}};qe.jsonID("attr",ig);let Yr=class extends Error{};Yr=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Yr.prototype=Object.create(Error.prototype);Yr.prototype.constructor=Yr;Yr.prototype.name="TransformError";let Cw=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new iw}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Yr(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=v.empty){let i=gw(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new v(C.from(r),0,0))}delete(e,t){return this.replace(e,t,v.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return kw(this,e,t,r),this}replaceRangeWith(e,t,r){return vw(this,e,t,r),this}deleteRange(e,t){return xw(this,e,t),this}lift(e,t){return aw(this,e,t),this}join(e,t=1){return pw(this,e,t),this}wrap(e,t){return uw(this,e,t),this}setBlockType(e,t=e,r,i=null){return cw(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return dw(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new ig(e,t,r)),this}addNodeMark(e,t){return this.step(new sf(e,t)),this}removeNodeMark(e,t){if(!(t instanceof W)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t=t.isInSet(r.marks),!t)return this}return this.step(new lf(e,t)),this}split(e,t=1,r){return hw(this,e,t,r),this}addMark(e,t,r){return ow(this,e,t,r),this}removeMark(e,t,r){return sw(this,e,t,r),this}clearIncompatible(e,t,r){return lw(this,e,t,r),this}};const Da=Object.create(null);class P{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new og(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t=0;o--){let s=t<0?xr(e.node(0),e.node(o),e.before(o+1),e.index(o),t,r):xr(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,t,r);if(s)return s}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new et(e.node(0))}static atStart(e){return xr(e,e,0,0,1)||new et(e)}static atEnd(e){return xr(e,e,e.content.size,e.childCount,-1)||new et(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=Da[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in Da)throw new RangeError("Duplicate use of selection JSON ID "+e);return Da[e]=t,t.prototype.jsonID=e,t}getBookmark(){return $.between(this.$anchor,this.$head).getBookmark()}}P.prototype.visible=!0;class og{constructor(e,t){this.$from=e,this.$to=t}}let Bd=!1;function Jd(n){!Bd&&!n.parent.inlineContent&&(Bd=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}class $ extends P{constructor(e,t=e){Jd(e),Jd(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return P.near(r);let i=e.resolve(t.map(this.anchor));return new $(i.parent.inlineContent?i:r,r)}replace(e,t=v.empty){if(super.replace(e,t),t==v.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof $&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Zl(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new $(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let o=P.findFrom(t,r,!0)||P.findFrom(t,-r,!0);if(o)t=o.$head;else return P.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(P.findFrom(e,-r,!0)||P.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?s=0;s+=i){let l=e.child(s);if(l.isAtom){if(!o&&I.isSelectable(l))return I.create(n,t-(i<0?l.nodeSize:0))}else{let a=xr(n,l,t+i,i<0?l.childCount:0,i,o);if(a)return a}t+=l.nodeSize*i}return null}function _d(n,e,t){let r=n.steps.length-1;if(r{s==null&&(s=c)}),n.setSelection(P.near(n.doc.resolve(s),t))}const Wd=1,hs=2,Ud=4;class Mw extends Cw{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|=hs,this}ensureMarks(e){return W.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&hs)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~hs,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||W.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r??t,!e)return this.deleteRange(t,r);let o=this.storedMarks;if(!o){let s=this.doc.resolve(t);o=r==t?s.marks():s.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,o)),this.selection.empty||this.setSelection(P.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=Ud,this}get scrolledIntoView(){return(this.updated&Ud)>0}}function Hd(n,e){return!e||!n?n:n.bind(e)}class Vi{constructor(e,t,r){this.name=e,this.init=Hd(t.init,r),this.apply=Hd(t.apply,r)}}const Ew=[new Vi("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new Vi("selection",{init(n,e){return n.selection||P.atStart(e.doc)},apply(n){return n.selection}}),new Vi("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new Vi("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})];class Ta{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Ew.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new Vi(r.key,r.spec.state,r))})}}class dn{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],o=i.spec.state;o&&o.toJSON&&(t[r]=o.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Ta(e.schema,e.plugins),o=new dn(i);return i.fields.forEach(s=>{if(s.name=="doc")o.doc=Tt.fromJSON(e.schema,t.doc);else if(s.name=="selection")o.selection=P.fromJSON(o.doc,t.selection);else if(s.name=="storedMarks")t.storedMarks&&(o.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let a=r[l],u=a.spec.state;if(a.key==s.name&&u&&u.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){o[s.name]=u.fromJSON.call(a,e,t[l],o);return}}o[s.name]=s.init(e,o)}}),o}}function sg(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=sg(i,e,{})),t[r]=i}return t}class $t{constructor(e){this.spec=e,this.props={},e.props&&sg(e.props,this,this.props),this.key=e.key?e.key.key:lg("plugin")}getState(e){return e[this.key]}}const Ra=Object.create(null);function lg(n){return n in Ra?n+"$"+ ++Ra[n]:(Ra[n]=0,n+"$")}class Yo{constructor(e="key"){this.key=lg(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const ag=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function Ow(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}const Dw=(n,e,t)=>{let r=Ow(n,t);if(!r)return!1;let i=ug(r);if(!i){let s=r.blockRange(),l=s&&nf(s);return l==null?!1:(e&&e(n.tr.lift(s,l).scrollIntoView()),!0)}let o=i.nodeBefore;if(!o.type.spec.isolating&&fg(n,i,e))return!0;if(r.parent.content.size==0&&(Gr(o,"end")||I.isSelectable(o))){let s=Km(n.doc,r.before(),r.after(),v.empty);if(s&&s.slice.size{let{$head:r,empty:i}=n.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;o=ug(r)}let s=o&&o.nodeBefore;return!s||!I.isSelectable(s)?!1:(e&&e(n.tr.setSelection(I.create(n.doc,o.pos-s.nodeSize)).scrollIntoView()),!0)};function ug(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){if(n.index(e)>0)return n.doc.resolve(n.before(e+1));if(n.node(e).type.spec.isolating)break}return null}function Rw(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=Rw(n,t);if(!r)return!1;let i=cg(r);if(!i)return!1;let o=i.nodeAfter;if(fg(n,i,e))return!0;if(r.parent.content.size==0&&(Gr(o,"start")||I.isSelectable(o))){let s=Km(n.doc,r.before(),r.after(),v.empty);if(s&&s.slice.size{let{$head:r,empty:i}=n.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):r.parentOffset=0;e--){let t=n.node(e);if(n.index(e)+1{let{$head:t,$anchor:r}=n.selection;return!t.parent.type.spec.code||!t.sameParent(r)?!1:(e&&e(n.tr.insertText(` +`).scrollIntoView()),!0)};function uf(n){for(let e=0;e{let{$head:t,$anchor:r}=n.selection;if(!t.parent.type.spec.code||!t.sameParent(r))return!1;let i=t.node(-1),o=t.indexAfter(-1),s=uf(i.contentMatchAt(o));if(!s||!i.canReplaceWith(o,o,s))return!1;if(e){let l=t.after(),a=n.tr.replaceWith(l,l,s.createAndFill());a.setSelection(P.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},Pw=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof et||r.parent.inlineContent||i.parent.inlineContent)return!1;let o=uf(i.parent.contentMatchAt(i.indexAfter()));if(!o||!o.isTextblock)return!1;if(e){let s=(!r.parentOffset&&i.index(){let{$cursor:t}=n.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let o=t.before();if(_s(n.doc,o))return e&&e(n.tr.split(o).scrollIntoView()),!0}let r=t.blockRange(),i=r&&nf(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function Lw(n){return(e,t)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof I&&e.selection.node.isBlock)return!r.parentOffset||!_s(e.doc,r.pos)?!1:(t&&t(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.parent.isBlock)return!1;if(t){let o=i.parentOffset==i.parent.content.size,s=e.tr;(e.selection instanceof $||e.selection instanceof et)&&s.deleteSelection();let l=r.depth==0?null:uf(r.node(-1).contentMatchAt(r.indexAfter(-1))),a=o&&l?[{type:l}]:void 0,u=_s(s.doc,s.mapping.map(r.pos),1,a);if(!a&&!u&&_s(s.doc,s.mapping.map(r.pos),1,l?[{type:l}]:void 0)&&(l&&(a=[{type:l}]),u=!0),u&&(s.split(s.mapping.map(r.pos),1,a),!o&&!r.parentOffset&&r.parent.type!=l)){let c=s.mapping.map(r.before()),f=s.doc.resolve(c);l&&r.node(-1).canReplaceWith(f.index(),f.index()+1,l)&&s.setNodeMarkup(s.mapping.map(r.before()),l)}t(s.scrollIntoView())}return!0}}const $w=Lw(),Vw=(n,e)=>(e&&e(n.tr.setSelection(new et(n.doc))),!0);function Bw(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,o=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(o-1,o)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(o,o+1)||!(i.isTextblock||jm(n.doc,e.pos))?!1:(t&&t(n.tr.clearIncompatible(e.pos,r.type,r.contentMatchAt(r.childCount)).join(e.pos).scrollIntoView()),!0)}function fg(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,o,s;if(r.type.spec.isolating||i.type.spec.isolating)return!1;if(Bw(n,e,t))return!0;let l=e.parent.canReplace(e.index(),e.index()+1);if(l&&(o=(s=r.contentMatchAt(r.childCount)).findWrapping(i.type))&&s.matchType(o[0]||i.type).validEnd){if(t){let f=e.pos+i.nodeSize,d=C.empty;for(let m=o.length-1;m>=0;m--)d=C.from(o[m].create(null,d));d=C.from(r.copy(d));let p=n.tr.step(new Sl(e.pos-1,f,e.pos,f,new v(d,1,0),o.length,!0)),h=f+2*o.length;jm(p.doc,h)&&p.join(h),t(p.scrollIntoView())}return!0}let a=P.findFrom(e,1),u=a&&a.$from.blockRange(a.$to),c=u&&nf(u);if(c!=null&&c>=e.depth)return t&&t(n.tr.lift(u,c).scrollIntoView()),!0;if(l&&Gr(i,"start",!0)&&Gr(r,"end")){let f=r,d=[];for(;d.push(f),!f.isTextblock;)f=f.lastChild;let p=i,h=1;for(;!p.isTextblock;p=p.firstChild)h++;if(f.canReplace(f.childCount,f.childCount,p.content)){if(t){let m=C.empty;for(let g=d.length-1;g>=0;g--)m=C.from(d[g].copy(m));let w=n.tr.step(new Sl(e.pos-d.length,e.pos+i.nodeSize,e.pos+h,e.pos+i.nodeSize-h,new v(m,d.length,0),0,!0));t(w.scrollIntoView())}return!0}}return!1}function dg(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,o=i.depth;for(;i.node(o).isInline;){if(!o)return!1;o--}return i.node(o).isTextblock?(t&&t(e.tr.setSelection($.create(e.doc,n<0?i.start(o):i.end(o)))),!0):!1}}const Jw=dg(-1),_w=dg(1);function Ww(n,e,t){for(let r=0;r{if(s)return!1;s=l.inlineContent&&l.type.allowsMarkType(t)}),s)return!0}return!1}function jd(n,e=null){return function(t,r){let{empty:i,$cursor:o,ranges:s}=t.selection;if(i&&!o||!Ww(t.doc,s,n))return!1;if(r)if(o)n.isInSet(t.storedMarks||o.marks())?r(t.tr.removeStoredMark(n)):r(t.tr.addStoredMark(n.create(e)));else{let l=!1,a=t.tr;for(let u=0;!l&&u",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},qd=typeof navigator<"u"&&/Chrome\/(\d+)/.exec(navigator.userAgent),jw=typeof navigator<"u"&&/Mac/.test(navigator.platform),Kw=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),qw=jw||qd&&+qd[1]<57;for(var ge=0;ge<10;ge++)It[48+ge]=It[96+ge]=String(ge);for(var ge=1;ge<=24;ge++)It[ge+111]="F"+ge;for(var ge=65;ge<=90;ge++)It[ge]=String.fromCharCode(ge+32),wl[ge]=String.fromCharCode(ge);for(var ba in It)wl.hasOwnProperty(ba)||(wl[ba]=It[ba]);function ff(n){var e=qw&&(n.ctrlKey||n.altKey||n.metaKey)||Kw&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?wl:It)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}const Qw=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function Yw(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,o,s;for(let l=0;l127)&&(o=It[r.keyCode])&&o!=i){let l=e[Ia(o,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}const pg=65535,mg=Math.pow(2,16);function Zw(n,e){return n+e*mg}function Qd(n){return n&pg}function ek(n){return(n-(n&pg))/mg}const gg=1,yg=2,qs=4,Sg=8;let Yd=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&Sg)>0}get deletedBefore(){return(this.delInfo&(gg|qs))>0}get deletedAfter(){return(this.delInfo&(yg|qs))>0}get deletedAcross(){return(this.delInfo&qs)>0}},Xr=class Cr{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&Cr.empty)return Cr.empty}recover(e){let t=0,r=Qd(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],f=a+u;if(e<=f){let d=u?e==a?-1:e==f?1:t:t,p=a+i+(d<0?0:c);if(r)return p;let h=e==(t<0?a:f)?null:Zw(l/3,e-a),m=e==a?yg:e==f?gg:qs;return(t<0?e!=a:e!=f)&&(m|=Sg),new Yd(p,m,h)}i+=c-u}return r?e+i:new Yd(e+i,0,null)}touches(e,t){let r=0,i=Qd(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return Be.fromReplace(e,this.from,this.to,o)}invert(){return new kg(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new Ji(t.pos,r.pos,this.mark)}merge(e){return e instanceof Ji&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Ji(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Ji(t.from,t.to,e.markFromJSON(t.mark))}};Qe.jsonID("addMark",wg);let kg=class _i extends Qe{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new v(df(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return Be.fromReplace(e,this.from,this.to,r)}invert(){return new wg(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new _i(t.pos,r.pos,this.mark)}merge(e){return e instanceof _i&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new _i(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new _i(t.from,t.to,e.markFromJSON(t.mark))}};Qe.jsonID("removeMark",kg);let vg=class Wi extends Qe{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Be.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return Be.fromReplace(e,this.pos,this.pos+1,new v(C.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new Qs(t.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Qs(t.from,t.to,t.gapFrom,t.gapTo,v.fromJSON(e,t.slice),t.insert,!!t.structure)}};Qe.jsonID("replaceAround",nk);function bu(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function rk(n,e,t){let r=n.resolve(e);if(!t.content.size)return e;let i=t.content;for(let o=0;o=0;s--){let l=s==r.depth?0:r.pos<=(r.start(s+1)+r.end(s+1))/2?-1:1,a=r.index(s)+(l>0?1:0),u=r.node(s),c=!1;if(o==1)c=u.canReplace(a,a,i);else{let f=u.contentMatchAt(a).findWrapping(i.firstChild.type);c=f&&u.canReplaceWith(a,a,f[0])}if(c)return l==0?r.pos:l<0?r.before(s+1):r.after(s+1)}return null}let ik=class Ys extends Qe{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return Be.fail("No node at attribute step's position");let r=Object.create(null);for(let o in t.attrs)r[o]=t.attrs[o];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return Be.fromReplace(e,this.pos,this.pos+1,new v(C.from(i),0,t.isLeaf?0:1))}getMap(){return Xr.empty}invert(e){return new Ys(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 Ys(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new Ys(t.pos,t.attr,t.value)}};Qe.jsonID("attr",ik);let wo=class extends Error{};wo=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};wo.prototype=Object.create(Error.prototype);wo.prototype.constructor=wo;wo.prototype.name="TransformError";const ye=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},ko=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e};let Iu=null;const _t=function(n,e,t){let r=Iu||(Iu=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},ok=function(){Iu=null},sr=function(n,e,t,r){return t&&(Gd(n,e,t,r,-1)||Gd(n,e,t,r,1))},sk=/^(img|br|input|textarea|hr)$/i;function Gd(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:at(n))){let o=n.parentNode;if(!o||o.nodeType!=1||Go(n)||sk.test(n.nodeName)||n.contentEditable=="false")return!1;e=ye(n)+(i<0?0:1),n=o}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?at(n):0}else return!1}}function at(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function lk(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=at(n)}else if(n.parentNode&&!Go(n))e=ye(n),n=n.parentNode;else return null}}function ak(n,e){for(;;){if(n.nodeType==3&&e2),ot=Zr||(zt?/Mac/.test(zt.platform):!1),dk=zt?/Win/.test(zt.platform):!1,wt=/Android \d/.test(bn),Xo=!!Xd&&"webkitFontSmoothing"in Xd.documentElement.style,hk=Xo?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function pk(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function Bt(n,e){return typeof n=="number"?n:n[e]}function mk(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function Zd(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,o=n.dom.ownerDocument;for(let s=t||n.dom;s;s=ko(s)){if(s.nodeType!=1)continue;let l=s,a=l==o.body,u=a?pk(o):mk(l),c=0,f=0;if(e.topu.bottom-Bt(r,"bottom")&&(f=e.bottom-e.top>u.bottom-u.top?e.top+Bt(i,"top")-u.top:e.bottom-u.bottom+Bt(i,"bottom")),e.leftu.right-Bt(r,"right")&&(c=e.right-u.right+Bt(i,"right")),c||f)if(a)o.defaultView.scrollBy(c,f);else{let d=l.scrollLeft,p=l.scrollTop;f&&(l.scrollTop+=f),c&&(l.scrollLeft+=c);let h=l.scrollLeft-d,m=l.scrollTop-p;e={left:e.left-h,top:e.top-m,right:e.right-h,bottom:e.bottom-m}}if(a||/^(fixed|sticky)$/.test(getComputedStyle(s).position))break}}function gk(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let o=(e.left+e.right)/2,s=t+1;s=t-20){r=l,i=a.top;break}}return{refDOM:r,refTop:i,stack:Mg(n.dom)}}function Mg(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=ko(r));return e}function yk({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;Eg(t,r==0?0:r-e)}function Eg(n,e){for(let t=0;t=l){s=Math.max(h.bottom,s),l=Math.min(h.top,l);let m=h.left>e.left?h.left-e.left:h.right=(h.left+h.right)/2?1:0));continue}}else h.top>e.top&&!a&&h.left<=e.left&&h.right>=e.left&&(a=c,u={left:Math.max(h.left,Math.min(h.right,e.left)),top:h.top});!t&&(e.left>=h.right&&e.top>=h.top||e.left>=h.left&&e.top>=h.bottom)&&(o=f+1)}}return!t&&a&&(t=a,i=u,r=0),t&&t.nodeType==3?wk(t,i):!t||r&&t.nodeType==1?{node:n,offset:o}:Og(t,i)}function wk(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i=(o.left+o.right)/2?1:0)}}return{node:n,offset:0}}function hf(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function kk(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(s.left+s.right)/2?1:-1}return n.docView.posFromDOM(r,i,o)}function xk(n,e,t,r){let i=-1;for(let o=e,s=!1;o!=n.dom;){let l=n.docView.nearestDesc(o,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)){let a=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&(!s&&a.left>r.left||a.top>r.top?i=l.posBefore:(!s&&a.right-1?i:n.docView.posFromDOM(e,t,-1)}function Dg(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let u;Xo&&i&&r.nodeType==1&&(u=r.childNodes[i-1]).nodeType==1&&u.contentEditable=="false"&&u.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=xk(n,r,i,e))}l==null&&(l=vk(n,s,e));let a=n.docView.nearestDesc(s,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function eh(n){return n.top=0&&i==r.nodeValue.length?(a--,c=1):t<0?a--:u++,Si(nn(_t(r,a,u),c),c<0)}if(!n.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&i&&(t<0||i==at(r))){let a=r.childNodes[i-1];if(a.nodeType==1)return Pa(a.getBoundingClientRect(),!1)}if(o==null&&i=0)}if(o==null&&i&&(t<0||i==at(r))){let a=r.childNodes[i-1],u=a.nodeType==3?_t(a,at(a)-(s?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(u)return Si(nn(u,1),!1)}if(o==null&&i=0)}function Si(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function Pa(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function Rg(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function Mk(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Rg(n,e,()=>{let{node:o}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(o,!0);if(!l)break;if(l.node.isBlock){o=l.contentDOM||l.dom;break}o=l.dom.parentNode}let s=Tg(n,i.pos,1);for(let l=o.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=_t(l,0,l.nodeValue.length).getClientRects();else continue;for(let u=0;uc.top+1&&(t=="up"?s.top-c.top>(c.bottom-s.top)*2:c.bottom-s.bottom>(s.bottom-c.top)*2))return!1}}return!0})}const Ek=/[\u0590-\u08ac]/;function Ok(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,l=n.domSelection();return l?!Ek.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?o:s:Rg(n,e,()=>{let{focusNode:a,focusOffset:u,anchorNode:c,anchorOffset:f}=n.domSelectionRange(),d=l.caretBidiLevel;l.modify("move",t,"character");let p=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:h,focusOffset:m}=n.domSelectionRange(),w=h&&!p.contains(h.nodeType==1?h:h.parentNode)||a==h&&u==m;try{l.collapse(c,f),a&&(a!=c||u!=f)&&l.extend&&l.extend(a,u)}catch{}return d!=null&&(l.caretBidiLevel=d),w}):r.pos==r.start()||r.pos==r.end()}let th=null,nh=null,rh=!1;function Dk(n,e,t){return th==e&&nh==t?rh:(th=e,nh=t,rh=t=="up"||t=="down"?Mk(n,e,t):Ok(n,e,t))}const ft=0,ih=1,qn=2,Pt=3;let Zo=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=ft,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tye(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let o=this.getDesc(i),s;if(o&&(!t||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let o=this.getDesc(i);if(o)return o.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||s instanceof Pg){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof Ag&&o.side>=0;r--);if(t<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&t&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,t):{node:this.contentDOM,offset:o?ye(o.dom)+1:0}}else{let o,s=!0;for(;o=r=c&&t<=u-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,c);e=s;for(let f=l;f>0;f--){let d=this.children[f-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=ye(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(u>t||l==this.children.length-1)){t=u;for(let c=l+1;cp&&st){let p=l;l=a,a=p}let d=document.createRange();d.setEnd(a.node,a.offset),d.setStart(l.node,l.offset),u.removeAllRanges(),u.addRange(d)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let r=0,i=0;i=r:er){let l=r+o.border,a=s-o.border;if(e>=l&&t<=a){this.dirty=e==r||t==s?qn:ih,e==l&&t==a&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=Pt:o.markDirty(e-l,t-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?qn:Pt}r=s}this.dirty=qn}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?qn:ih;t.dirty{if(!o)return i;if(o.parent)return o.parent.posBeforeChild(o)})),!t.type.spec.raw){if(s.nodeType!=1){let l=document.createElement("span");l.appendChild(s),s=l}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=t,this.widget=t,o=this}matchesWidget(e){return this.dirty==ft&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}},Tk=class extends Zo{constructor(e,t,r,i){super(e,[],t,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}},kl=class Lu extends Zo{constructor(e,t,r,i){super(e,[],r,i),this.mark=t}static create(e,t,r,i){let o=i.nodeViews[t.type.name],s=o&&o(t,i,r);return(!s||!s.dom)&&(s=pi.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new Lu(e,t,s.dom,s.contentDOM||s.dom)}parseRule(){return this.dirty&Pt||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Pt&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=ft){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(o=Bu(o,0,e,r));for(let l=0;l{if(!a)return s;if(a.parent)return a.parent.posBeforeChild(a)},r,i),c=u&&u.dom,f=u&&u.contentDOM;if(t.isText){if(!c)c=document.createTextNode(t.text);else if(c.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else c||({dom:c,contentDOM:f}=pi.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!f&&!t.isText&&c.nodeName!="BR"&&(c.hasAttribute("contenteditable")||(c.contentEditable="false"),t.type.spec.draggable&&(c.draggable=!0));let d=c;return c=$g(c,r,t),u?a=new Rk(e,t,r,i,c,f||null,d,u,o,s+1):t.isText?new Ig(e,t,r,i,c,d,o):new bg(e,t,r,i,c,f||null,d,o,s+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>C.empty)}return e}matchesNode(e,t,r){return this.dirty==ft&&e.eq(this.node)&&Vu(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let r=this.node.inlineContent,i=t,o=e.composing?this.localCompositionInfo(e,t):null,s=o&&o.pos>-1?o:null,l=o&&o.pos<0,a=new bk(this,s&&s.node,e);Pk(this.node,this.innerDeco,(u,c,f)=>{u.spec.marks?a.syncToMarks(u.spec.marks,r,e):u.type.side>=0&&!f&&a.syncToMarks(c==this.node.childCount?W.none:this.node.child(c).marks,r,e),a.placeWidget(u,e,i)},(u,c,f,d)=>{a.syncToMarks(u.marks,r,e);let p;a.findNodeMatch(u,c,f,d)||l&&e.state.selection.from>i&&e.state.selection.to-1&&a.updateNodeAt(u,c,f,p,e)||a.updateNextNode(u,c,f,e,d,i)||a.addNode(u,c,f,e,i),i+=u.nodeSize}),a.syncToMarks([],r,e),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==qn)&&(s&&this.protectLocalComposition(e,s),Fg(this.contentDOM,this.children,e),Zr&&Fk(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof $)||rt+this.node.content.size)return null;let o=e.input.compositionNode;if(!o||!this.dom.contains(o.parentNode))return null;if(this.node.inlineContent){let s=o.nodeValue,l=Lk(this.node.content,s,r-t,i-t);return l<0?null:{node:o,pos:l,text:s}}else return{node:o,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let o=t;for(;o.parentNode!=this.contentDOM;o=o.parentNode){for(;o.previousSibling;)o.parentNode.removeChild(o.previousSibling);for(;o.nextSibling;)o.parentNode.removeChild(o.nextSibling);o.pmViewDesc&&(o.pmViewDesc=void 0)}let s=new Tk(this,o,t,i);e.input.compositionNodes.push(s),this.children=Bu(this.children,r,r+i.length,e,s)}update(e,t,r,i){return this.dirty==Pt||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,r,i),!0)}updateInner(e,t,r,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=ft}updateOuterDeco(e){if(Vu(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Lg(this.dom,this.nodeDOM,$u(this.outerDeco,this.node,t),$u(e,this.node,t)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}};function oh(n,e,t,r,i){$g(r,e,n);let o=new Vr(void 0,n,e,t,r,r,r,i,0);return o.contentDOM&&o.updateChildren(i,0),o}let Ig=class zg extends Vr{constructor(e,t,r,i,o,s,l){super(e,t,r,i,o,null,s,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,i){return this.dirty==Pt||this.dirty!=ft&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=ft||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=ft,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,r){let i=this.node.cut(e,t),o=document.createTextNode(i.text);return new zg(this.parent,i,this.outerDeco,this.innerDeco,o,o,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Pt)}get domAtom(){return!1}isText(e){return this.node.text==e}},Pg=class extends Zo{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==ft&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}};class Rk extends Vr{constructor(e,t,r,i,o,s,l,a,u,c){super(e,t,r,i,o,s,l,u,c),this.spec=a}update(e,t,r,i){if(this.dirty==Pt)return!1;if(this.spec.update){let o=this.spec.update(e,t,r);return o&&this.updateInner(e,t,r,i),o}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,r,i){this.spec.setSelection?this.spec.setSelection(e,t,r):super.setSelection(e,t,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}function Fg(n,e,t){let r=n.firstChild,i=!1;for(let o=0;o>1,s=Math.min(o,e.length);for(;i-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let a=kl.create(this.top,e[o],t,r);this.top.children.splice(this.index,0,a),this.top=a,this.changed=!0}this.index=0,o++}}findNodeMatch(e,t,r,i){let o=-1,s;if(i>=this.preMatch.index&&(s=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&s.matchesNode(e,t,r))o=this.top.children.indexOf(s,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let u=t.children[r-1];if(u instanceof kl)t=u,r=u.children.length;else{l=u,r--;break}}else{if(t==e)break e;r=t.parent.children.indexOf(t),t=t.parent}let a=l.node;if(a){if(a!=n.child(i-1))break;--i,o.set(l,i),s.push(l)}}return{index:i,matched:o,matches:s.reverse()}}function zk(n,e){return n.type.side-e.type.side}function Pk(n,e,t,r){let i=e.locals(n),o=0;if(i.length==0){for(let u=0;uo;)l.push(i[s++]);let h=o+d.nodeSize;if(d.isText){let w=h;s!w.inline):l.slice();r(d,m,e.forChild(o,d),p),o=h}}function Fk(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function Lk(n,e,t,r){for(let i=0,o=0;i=t){if(o>=r&&a.slice(r-e.length-l,r-l)==e)return r-e.length;let u=l=0&&u+e.length+l>=t)return l+u;if(t==r&&a.length>=r+e.length-l&&a.slice(r-l,r-l+e.length)==e)return r}}return-1}function Bu(n,e,t,r,i){let o=[];for(let s=0,l=0;s=t||c<=e?o.push(a):(ut&&o.push(a.slice(t-u,a.size,r)))}return o}function pf(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),o=i&&i.size==0,s=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(s<0)return null;let l=r.resolve(s),a,u;if(ea(t)){for(a=l;i&&!i.node;)i=i.parent;let c=i.node;if(i&&c.isAtom&&I.isSelectable(c)&&i.parent&&!(c.isInline&&uk(t.focusNode,t.focusOffset,i.dom))){let f=i.posBefore;u=new I(s==f?l:r.resolve(f))}}else{let c=n.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(c<0)return null;a=r.resolve(c)}if(!u){let c=e=="pointer"||n.state.selection.head{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!Vg(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function Vk(n){let e=n.domSelection(),t=document.createRange();if(!e)return;let r=n.cursorWrapper.dom,i=r.nodeName=="IMG";i?t.setStart(r.parentNode,ye(r)+1):t.setStart(r,0),t.collapse(!0),e.removeAllRanges(),e.addRange(t),!i&&!n.state.selection.visible&&We&&Sn<=11&&(r.disabled=!0,r.disabled=!1)}function Bg(n,e){if(e instanceof I){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(ch(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else ch(n)}function ch(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function mf(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||$.between(e,t,r)}function fh(n){return n.editable&&!n.hasFocus()?!1:Jg(n)}function Jg(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function Bk(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return sr(e.node,e.offset,t.anchorNode,t.anchorOffset)}function Ju(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),o=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return o&&P.findFrom(o,e)}function rn(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function dh(n,e,t){let r=n.state.selection;if(r instanceof $)if(t.indexOf("s")>-1){let{$head:i}=r,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!o||o.isText||!o.isLeaf)return!1;let s=n.state.doc.resolve(i.pos+o.nodeSize*(e<0?-1:1));return rn(n,new $(r.$anchor,s))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=Ju(n.state,e);return i&&i instanceof I?rn(n,i):!1}else if(!(ot&&t.indexOf("m")>-1)){let i=r.$head,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,s;if(!o||o.isText)return!1;let l=e<0?i.pos-o.nodeSize:i.pos;return o.isAtom||(s=n.docView.descAt(l))&&!s.contentDOM?I.isSelectable(o)?rn(n,new I(e<0?n.state.doc.resolve(i.pos-o.nodeSize):i)):Xo?rn(n,new $(n.state.doc.resolve(e<0?l:l+o.nodeSize))):!1:!1}}else return!1;else{if(r instanceof I&&r.node.isInline)return rn(n,new $(e>0?r.$to:r.$from));{let i=Ju(n.state,e);return i?rn(n,i):!1}}}function vl(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function ro(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function Sr(n,e){return e<0?Jk(n):_k(n)}function Jk(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,o,s=!1;for(Ct&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(ro(l,-1))i=t,o=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(_g(t))break;{let l=t.previousSibling;for(;l&&ro(l,-1);)i=t.parentNode,o=ye(l),l=l.previousSibling;if(l)t=l,r=vl(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}s?_u(n,t,r):i&&_u(n,i,o)}function _k(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=vl(t),o,s;for(;;)if(r{n.state==i&&qt(n)},50)}function hh(n,e){let t=n.state.doc.resolve(e);if(!(Me||dk)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let o=n.coordsAtPos(e-1),s=(o.top+o.bottom)/2;if(s>i.top&&s1)return o.lefti.top&&s1)return o.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function ph(n,e,t){let r=n.state.selection;if(r instanceof $&&!r.empty||t.indexOf("s")>-1||ot&&t.indexOf("m")>-1)return!1;let{$from:i,$to:o}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let s=Ju(n.state,e);if(s&&s instanceof I)return rn(n,s)}if(!i.parent.inlineContent){let s=e<0?i:o,l=r instanceof et?P.near(s,e):P.findFrom(s,e);return l?rn(n,l):!1}return!1}function mh(n,e){if(!(n.state.selection instanceof $))return!0;let{$head:t,$anchor:r,empty:i}=n.state.selection;if(!t.sameParent(r))return!0;if(!i)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let o=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(o&&!o.isText){let s=n.state.tr;return e<0?s.delete(t.pos-o.nodeSize,t.pos):s.delete(t.pos,t.pos+o.nodeSize),n.dispatch(s),!0}return!1}function gh(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function Hk(n){if(!be||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;gh(n,r,"true"),setTimeout(()=>gh(n,r,"false"),20)}return!1}function jk(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function Kk(n,e){let t=e.keyCode,r=jk(e);if(t==8||ot&&t==72&&r=="c")return mh(n,-1)||Sr(n,-1);if(t==46&&!e.shiftKey||ot&&t==68&&r=="c")return mh(n,1)||Sr(n,1);if(t==13||t==27)return!0;if(t==37||ot&&t==66&&r=="c"){let i=t==37?hh(n,n.state.selection.from)=="ltr"?-1:1:-1;return dh(n,i,r)||Sr(n,i)}else if(t==39||ot&&t==70&&r=="c"){let i=t==39?hh(n,n.state.selection.from)=="ltr"?1:-1:1;return dh(n,i,r)||Sr(n,i)}else{if(t==38||ot&&t==80&&r=="c")return ph(n,-1,r)||Sr(n,-1);if(t==40||ot&&t==78&&r=="c")return Hk(n)||ph(n,1,r)||Sr(n,1);if(r==(ot?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Wg(n,e){n.someProp("transformCopied",p=>{e=p(e,n)});let t=[],{content:r,openStart:i,openEnd:o}=e;for(;i>1&&o>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,o--;let p=r.firstChild;t.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),r=p.content}let s=n.someProp("clipboardSerializer")||pi.fromSchema(n.state.schema),l=Qg(),a=l.createElement("div");a.appendChild(s.serializeFragment(r,{document:l}));let u=a.firstChild,c,f=0;for(;u&&u.nodeType==1&&(c=qg[u.nodeName.toLowerCase()]);){for(let p=c.length-1;p>=0;p--){let h=l.createElement(c[p]);for(;a.firstChild;)h.appendChild(a.firstChild);a.appendChild(h),f++}u=a.firstChild}u&&u.nodeType==1&&u.setAttribute("data-pm-slice",`${i} ${o}${f?` -${f}`:""} ${JSON.stringify(t)}`);let d=n.someProp("clipboardTextSerializer",p=>p(e,n))||e.content.textBetween(0,e.content.size,` + +`);return{dom:a,text:d,slice:e}}function Ug(n,e,t,r,i){let o=i.parent.type.spec.code,s,l;if(!t&&!e)return null;let a=e&&(r||o||!t);if(a){if(n.someProp("transformPastedText",d=>{e=d(e,o||r,n)}),o)return e?new v(C.from(n.state.schema.text(e.replace(/\r\n?/g,` +`))),0,0):v.empty;let f=n.someProp("clipboardTextParser",d=>d(e,i,r,n));if(f)l=f;else{let d=i.marks(),{schema:p}=n.state,h=pi.fromSchema(p);s=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let w=s.appendChild(document.createElement("p"));m&&w.appendChild(h.serializeNode(p.text(m,d)))})}}else n.someProp("transformPastedHTML",f=>{t=f(t,n)}),s=Gk(t),Xo&&Xk(s);let u=s&&s.querySelector("[data-pm-slice]"),c=u&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(u.getAttribute("data-pm-slice")||"");if(c&&c[3])for(let f=+c[3];f>0;f--){let d=s.firstChild;for(;d&&d.nodeType!=1;)d=d.nextSibling;if(!d)break;s=d}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||yo.fromSchema(n.state.schema)).parseSlice(s,{preserveWhitespace:!!(a||c),context:i,ruleFromNode(d){return d.nodeName=="BR"&&!d.nextSibling&&d.parentNode&&!qk.test(d.parentNode.nodeName)?{ignore:!0}:null}})),c)l=Zk(yh(l,+c[1],+c[2]),c[4]);else if(l=v.maxOpen(Qk(l.content,i),!0),l.openStart||l.openEnd){let f=0,d=0;for(let p=l.content.firstChild;f{l=f(l,n)}),l}const qk=/^(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 Qk(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),o,s=[];if(n.forEach(l=>{if(!s)return;let a=i.findWrapping(l.type),u;if(!a)return s=null;if(u=s.length&&o.length&&jg(a,o,l,s[s.length-1],0))s[s.length-1]=u;else{s.length&&(s[s.length-1]=Kg(s[s.length-1],o.length));let c=Hg(l,a);s.push(c),i=i.matchType(c.type),o=a}}),s)return C.from(s)}return n}function Hg(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,C.from(n));return n}function jg(n,e,t,r,i){if(i1&&(o=0),i=t&&(l=e<0?s.contentMatchAt(0).fillBefore(l,o<=i).append(l):l.append(s.contentMatchAt(s.childCount).fillBefore(C.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,s.copy(l))}function yh(n,e,t){return et}).createHTML(n):n}function Gk(n){let e=/^(\s*]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=Qg().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&qg[r[1].toLowerCase()])&&(n=i.map(o=>"<"+o+">").join("")+n+i.map(o=>"").reverse().join("")),t.innerHTML=Yk(n),i)for(let o=0;o=0;l-=2){let a=t.nodes[r[l]];if(!a||a.hasRequiredAttrs())break;i=C.from(a.create(r[l+1],i)),o++,s++}return new v(i,o,s)}const Ie={},ze={},ev={touchstart:!0,touchmove:!0};class tv{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:""},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastAndroidDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function nv(n){for(let e in Ie){let t=Ie[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{iv(n,r)&&!gf(n,r)&&(n.editable||!(r.type in ze))&&t(n,r)},ev[e]?{passive:!0}:void 0)}be&&n.dom.addEventListener("input",()=>null),Uu(n)}function hn(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function rv(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function Uu(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>gf(n,r))})}function gf(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function iv(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function ov(n,e){!gf(n,e)&&Ie[e.type]&&(n.editable||!(e.type in ze))&&Ie[e.type](n,e)}ze.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!Gg(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(wt&&Me&&t.keyCode==13)))if(n.domObserver.selectionChanged(n.domSelectionRange())?n.domObserver.flush():t.keyCode!=229&&n.domObserver.forceFlush(),Zr&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let r=Date.now();n.input.lastIOSEnter=r,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==r&&(n.someProp("handleKeyDown",i=>i(n,Kn(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||Kk(n,t)?t.preventDefault():hn(n,"key")};ze.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};ze.keypress=(n,e)=>{let t=e;if(Gg(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||ot&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof $)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(t.charCode);!/[\r\n]/.test(i)&&!n.someProp("handleTextInput",o=>o(n,r.$from.pos,r.$to.pos,i))&&n.dispatch(n.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function ta(n){return{left:n.clientX,top:n.clientY}}function sv(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function yf(n,e,t,r,i){if(r==-1)return!1;let o=n.state.doc.resolve(r);for(let s=o.depth+1;s>0;s--)if(n.someProp(e,l=>s>o.depth?l(n,t,o.nodeAfter,o.before(s),i,!0):l(n,t,o.node(s),o.before(s),i,!1)))return!0;return!1}function Br(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let r=n.state.tr.setSelection(e);r.setMeta("pointer",!0),n.dispatch(r)}function lv(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&I.isSelectable(r)?(Br(n,new I(t)),!0):!1}function av(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof I&&(r=t.node);let o=n.state.doc.resolve(e);for(let s=o.depth+1;s>0;s--){let l=s>o.depth?o.nodeAfter:o.node(s);if(I.isSelectable(l)){r&&t.$from.depth>0&&s>=t.$from.depth&&o.before(t.$from.depth+1)==t.$from.pos?i=o.before(t.$from.depth):i=o.before(s);break}}return i!=null?(Br(n,I.create(n.state.doc,i)),!0):!1}function uv(n,e,t,r,i){return yf(n,"handleClickOn",e,t,r)||n.someProp("handleClick",o=>o(n,e,r))||(i?av(n,t):lv(n,t))}function cv(n,e,t,r){return yf(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function fv(n,e,t,r){return yf(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||dv(n,t,r)}function dv(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(Br(n,$.create(r,0,r.content.size)),!0):!1;let i=r.resolve(e);for(let o=i.depth+1;o>0;o--){let s=o>i.depth?i.nodeAfter:i.node(o),l=i.before(o);if(s.inlineContent)Br(n,$.create(r,l+1,l+1+s.content.size));else if(I.isSelectable(s))Br(n,I.create(r,l));else continue;return!0}}function Sf(n){return xl(n)}const Yg=ot?"metaKey":"ctrlKey";Ie.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=Sf(n),i=Date.now(),o="singleClick";i-n.input.lastClick.time<500&&sv(t,n.input.lastClick)&&!t[Yg]&&(n.input.lastClick.type=="singleClick"?o="doubleClick":n.input.lastClick.type=="doubleClick"&&(o="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:o};let s=n.posAtCoords(ta(t));s&&(o=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new hv(n,s,t,!!r)):(o=="doubleClick"?cv:fv)(n,s.pos,s.inside,t)?t.preventDefault():hn(n,"pointer"))};class hv{constructor(e,t,r,i){this.view=e,this.pos=t,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[Yg],this.allowDefault=r.shiftKey;let o,s;if(t.inside>-1)o=e.state.doc.nodeAt(t.inside),s=t.inside;else{let c=e.state.doc.resolve(t.pos);o=c.parent,s=c.depth?c.before():0}const l=i?null:r.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a&&a.dom.nodeType==1?a.dom:null;let{selection:u}=e.state;(r.button==0&&o.type.spec.draggable&&o.type.spec.selectable!==!1||u instanceof I&&u.from<=s&&u.to>s)&&(this.mightDrag={node:o,pos:s,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Ct&&!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)),hn(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(()=>qt(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(ta(e))),this.updateAllowDefault(e),this.allowDefault||!t?hn(this.view,"pointer"):uv(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||be&&this.mightDrag&&!this.mightDrag.node.isAtom||Me&&!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)?(Br(this.view,P.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):hn(this.view,"pointer")}move(e){this.updateAllowDefault(e),hn(this.view,"pointer"),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}}Ie.touchstart=n=>{n.input.lastTouch=Date.now(),Sf(n),hn(n,"pointer")};Ie.touchmove=n=>{n.input.lastTouch=Date.now(),hn(n,"pointer")};Ie.contextmenu=n=>Sf(n);function Gg(n,e){return n.composing?!0:be&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}const pv=wt?5e3:-1;ze.compositionstart=ze.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof $&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))n.markCursor=n.state.storedMarks||t.marks(),xl(n,!0),n.markCursor=null;else if(xl(n,!e.selection.empty),Ct&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let i=r.focusNode,o=r.focusOffset;i&&i.nodeType==1&&o!=0;){let s=o<0?i.lastChild:i.childNodes[o-1];if(!s)break;if(s.nodeType==3){let l=n.domSelection();l&&l.collapse(s,s.nodeValue.length);break}else i=s,o=-1}}n.input.composing=!0}Xg(n,pv)};ze.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionNode=null,n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,Xg(n,20))};function Xg(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>xl(n),e))}function Zg(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=gv());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function mv(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=lk(e.focusNode,e.focusOffset),r=ak(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,o=n.domObserver.lastChangedTextNode;if(t==o||r==o)return o;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let s=t.pmViewDesc;if(!(!s||!s.isText(t.nodeValue)))return r}}return t||r}function gv(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function xl(n,e=!1){if(!(wt&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),Zg(n),e||n.docView&&n.docView.dirty){let t=pf(n);return t&&!t.eq(n.state.selection)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!n.state.selection.empty?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function yv(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),n.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}const vo=We&&Sn<15||Zr&&hk<604;Ie.copy=ze.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let o=vo?null:t.clipboardData,s=r.content(),{dom:l,text:a}=Wg(n,s);o?(t.preventDefault(),o.clearData(),o.setData("text/html",l.innerHTML),o.setData("text/plain",a)):yv(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function Sv(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function wv(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,r=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),r.parentNode&&r.parentNode.removeChild(r),t?xo(n,r.value,null,i,e):xo(n,r.textContent,r.innerHTML,i,e)},50)}function xo(n,e,t,r,i){let o=Ug(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",a=>a(n,i,o||v.empty)))return!0;if(!o)return!1;let s=Sv(o),l=s?n.state.tr.replaceSelectionWith(s,r):n.state.tr.replaceSelection(o);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function ey(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}ze.paste=(n,e)=>{let t=e;if(n.composing&&!wt)return;let r=vo?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&xo(n,ey(r),r.getData("text/html"),i,t)?t.preventDefault():wv(n,t)};class ty{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}}const ny=ot?"altKey":"ctrlKey";Ie.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=n.state.selection,o=i.empty?null:n.posAtCoords(ta(t)),s;if(!(o&&o.pos>=i.from&&o.pos<=(i instanceof I?i.to-1:i.to))){if(r&&r.mightDrag)s=I.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let f=n.docView.nearestDesc(t.target,!0);f&&f.node.type.spec.draggable&&f!=n.docView&&(s=I.create(n.state.doc,f.posBefore))}}let l=(s||n.state.selection).content(),{dom:a,text:u,slice:c}=Wg(n,l);(!t.dataTransfer.files.length||!Me||Ng>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(vo?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",vo||t.dataTransfer.setData("text/plain",u),n.dragging=new ty(c,!t[ny],s)};Ie.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};ze.dragover=ze.dragenter=(n,e)=>e.preventDefault();ze.drop=(n,e)=>{let t=e,r=n.dragging;if(n.dragging=null,!t.dataTransfer)return;let i=n.posAtCoords(ta(t));if(!i)return;let o=n.state.doc.resolve(i.pos),s=r&&r.slice;s?n.someProp("transformPasted",h=>{s=h(s,n)}):s=Ug(n,ey(t.dataTransfer),vo?null:t.dataTransfer.getData("text/html"),!1,o);let l=!!(r&&!t[ny]);if(n.someProp("handleDrop",h=>h(n,t,s||v.empty,l))){t.preventDefault();return}if(!s)return;t.preventDefault();let a=s?rk(n.state.doc,o.pos,s):o.pos;a==null&&(a=o.pos);let u=n.state.tr;if(l){let{node:h}=r;h?h.replace(u):u.deleteSelection()}let c=u.mapping.map(a),f=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,d=u.doc;if(f?u.replaceRangeWith(c,c,s.content.firstChild):u.replaceRange(c,c,s),u.doc.eq(d))return;let p=u.doc.resolve(c);if(f&&I.isSelectable(s.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(s.content.firstChild))u.setSelection(new I(p));else{let h=u.mapping.map(a);u.mapping.maps[u.mapping.maps.length-1].forEach((m,w,g,y)=>h=y),u.setSelection(mf(n,p,u.doc.resolve(h)))}n.focus(),n.dispatch(u.setMeta("uiEvent","drop"))};Ie.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&qt(n)},20))};Ie.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)};Ie.beforeinput=(n,e)=>{if(Me&&wt&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:r}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=r||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",o=>o(n,Kn(8,"Backspace")))))return;let{$cursor:i}=n.state.selection;i&&i.pos>0&&n.dispatch(n.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let n in ze)Ie[n]=ze[n];function Co(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}class Cl{constructor(e,t){this.toDOM=e,this.spec=t||tr,this.side=this.spec.side||0}map(e,t,r,i){let{pos:o,deleted:s}=e.mapResult(t.from+i,this.side<0?-1:1);return s?null:new Se(o-r,o-r,this)}valid(){return!0}eq(e){return this==e||e instanceof Cl&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Co(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class wn{constructor(e,t){this.attrs=e,this.spec=t||tr}map(e,t,r,i){let o=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,s=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return o>=s?null:new Se(o,s,this)}valid(e,t){return t.from=e&&(!o||o(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let s=0;se){let l=this.children[s]+1;this.children[s+2].findInner(e-l,t-l,r,i+l,o)}}map(e,t,r){return this==Ce||e.maps.length==0?this:this.mapInner(e,t,0,0,r||tr)}mapInner(e,t,r,i,o){let s;for(let l=0;l{let u=a+r,c;if(c=oy(t,l,u)){for(i||(i=this.children.slice());ol&&f.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let o=e+1,s=o+t.content.size;for(let l=0;lo&&a.type instanceof wn){let u=Math.max(o,a.from)-o,c=Math.min(s,a.to)-o;ui.map(e,t,tr));return Mr.from(r)}forChild(e,t){if(t.isLeaf)return _.empty;let r=[];for(let i=0;it instanceof _)?e:e.reduce((t,r)=>t.concat(r instanceof _?r:r.members),[]))}}forEachSet(e){for(let t=0;t{let w=m-h-(p-d);for(let g=0;gy+c-f)continue;let S=l[g]+c-f;p>=S?l[g+1]=d<=S?-2:-1:d>=c&&w&&(l[g]+=w,l[g+1]+=w)}f+=w}),c=t.maps[u].map(c,-1)}let a=!1;for(let u=0;u=r.content.size){a=!0;continue}let d=t.map(n[u+1]+o,-1),p=d-i,{index:h,offset:m}=r.content.findIndex(f),w=r.maybeChild(h);if(w&&m==f&&m+w.nodeSize==p){let g=l[u+2].mapInner(t,w,c+1,n[u]+o+1,s);g!=Ce?(l[u]=f,l[u+1]=p,l[u+2]=g):(l[u+1]=-2,a=!0)}else a=!0}if(a){let u=vv(l,n,e,t,i,o,s),c=Nl(u,r,0,s);e=c.local;for(let f=0;ft&&s.to{let u=oy(n,l,a+t);if(u){o=!0;let c=Nl(u,l,t+a+1,r);c!=Ce&&i.push(a,a+l.nodeSize,c)}});let s=iy(o?sy(n):n,-t).sort(nr);for(let l=0;l0;)e++;n.splice(e,0,t)}function La(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=Ce&&e.push(r)}),n.cursorWrapper&&e.push(_.create(n.state.doc,[n.cursorWrapper.deco])),ry.from(e)}const xv={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Cv=We&&Sn<=11;let Nv=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}};class Mv{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Nv,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),Cv&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,xv)),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(fh(this.view)){if(this.suppressingSelectionUpdates)return qt(this.view);if(We&&Sn<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&sr(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,r;for(let o=e.focusNode;o;o=ko(o))t.add(o);for(let o=e.anchorNode;o;o=ko(o))if(t.has(o)){r=o;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}selectionChanged(e){return!this.suppressingSelectionUpdates&&!this.currentSelection.eq(e)&&fh(this.view)&&!this.ignoreSelectionChange(e)}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let r=e.domSelectionRange(),i=this.selectionChanged(r),o=-1,s=-1,l=!1,a=[];if(e.editable)for(let c=0;cf.nodeName=="BR");if(c.length==2){let[f,d]=c;f.parentNode&&f.parentNode.parentNode==d.parentNode?d.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let d of c){let p=d.parentNode;p&&p.nodeName=="LI"&&(!f||Dv(e,f)!=p)&&d.remove()}}}let u=null;o<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(o>-1&&(e.docView.markDirty(o,s),Ev(e)),this.handleDOMChange(o,s,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||qt(e),this.currentSelection.set(r))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let c=0;ci;w--){let g=r.childNodes[w-1],y=g.pmViewDesc;if(g.nodeName=="BR"&&!y){o=w;break}if(!y||y.size)break}let f=n.state.doc,d=n.someProp("domParser")||yo.fromSchema(n.state.schema),p=f.resolve(s),h=null,m=d.parse(r,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:i,to:o,preserveWhitespace:p.parent.type.whitespace=="pre"?"full":!0,findPositions:u,ruleFromNode:Rv,context:p});if(u&&u[0].pos!=null){let w=u[0].pos,g=u[1]&&u[1].pos;g==null&&(g=w),h={anchor:w+s,head:g+s}}return{doc:m,sel:h,from:s,to:l}}function Rv(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(be&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||be&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}const Av=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function bv(n,e,t,r,i){let o=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let b=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,z=pf(n,b);if(z&&!n.state.selection.eq(z)){if(Me&&wt&&n.input.lastKeyCode===13&&Date.now()-100Vt(n,Kn(13,"Enter"))))return;let ae=n.state.tr.setSelection(z);b=="pointer"?ae.setMeta("pointer",!0):b=="key"&&ae.scrollIntoView(),o&&ae.setMeta("composition",o),n.dispatch(ae)}return}let s=n.state.doc.resolve(e),l=s.sharedDepth(t);e=s.before(l+1),t=n.state.doc.resolve(t).after(l+1);let a=n.state.selection,u=Tv(n,e,t),c=n.state.doc,f=c.slice(u.from,u.to),d,p;n.input.lastKeyCode===8&&Date.now()-100Date.now()-225||wt)&&i.some(b=>b.nodeType==1&&!Av.test(b.nodeName))&&(!h||h.endA>=h.endB)&&n.someProp("handleKeyDown",b=>b(n,Kn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!h)if(r&&a instanceof $&&!a.empty&&a.$head.sameParent(a.$anchor)&&!n.composing&&!(u.sel&&u.sel.anchor!=u.sel.head))h={start:a.from,endA:a.to,endB:a.to};else{if(u.sel){let b=Ch(n,n.state.doc,u.sel);if(b&&!b.eq(n.state.selection)){let z=n.state.tr.setSelection(b);o&&z.setMeta("composition",o),n.dispatch(z)}}return}n.state.selection.fromn.state.selection.from&&h.start<=n.state.selection.from+2&&n.state.selection.from>=u.from?h.start=n.state.selection.from:h.endA=n.state.selection.to-2&&n.state.selection.to<=u.to&&(h.endB+=n.state.selection.to-h.endA,h.endA=n.state.selection.to)),We&&Sn<=11&&h.endB==h.start+1&&h.endA==h.start&&h.start>u.from&&u.doc.textBetween(h.start-u.from-1,h.start-u.from+1)=="  "&&(h.start--,h.endA--,h.endB--);let m=u.doc.resolveNoCache(h.start-u.from),w=u.doc.resolveNoCache(h.endB-u.from),g=c.resolve(h.start),y=m.sameParent(w)&&m.parent.inlineContent&&g.end()>=h.endA,S;if((Zr&&n.input.lastIOSEnter>Date.now()-225&&(!y||i.some(b=>b.nodeName=="DIV"||b.nodeName=="P"))||!y&&m.posb(n,Kn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>h.start&&zv(c,h.start,h.endA,m,w)&&n.someProp("handleKeyDown",b=>b(n,Kn(8,"Backspace")))){wt&&Me&&n.domObserver.suppressSelectionUpdates();return}Me&&wt&&h.endB==h.start&&(n.input.lastAndroidDelete=Date.now()),wt&&!y&&m.start()!=w.start()&&w.parentOffset==0&&m.depth==w.depth&&u.sel&&u.sel.anchor==u.sel.head&&u.sel.head==h.endA&&(h.endB-=2,w=u.doc.resolveNoCache(h.endB-u.from),setTimeout(()=>{n.someProp("handleKeyDown",function(b){return b(n,Kn(13,"Enter"))})},20));let x=h.start,N=h.endA,M,O,D;if(y){if(m.pos==w.pos)We&&Sn<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>qt(n),20)),M=n.state.tr.delete(x,N),O=c.resolve(h.start).marksAcross(c.resolve(h.endA));else if(h.endA==h.endB&&(D=Iv(m.parent.content.cut(m.parentOffset,w.parentOffset),g.parent.content.cut(g.parentOffset,h.endA-g.start()))))M=n.state.tr,D.type=="add"?M.addMark(x,N,D.mark):M.removeMark(x,N,D.mark);else if(m.parent.child(m.index()).isText&&m.index()==w.index()-(w.textOffset?0:1)){let b=m.parent.textBetween(m.parentOffset,w.parentOffset);if(n.someProp("handleTextInput",z=>z(n,x,N,b)))return;M=n.state.tr.insertText(b,x,N)}}if(M||(M=n.state.tr.replace(x,N,u.doc.slice(h.start-u.from,h.endB-u.from))),u.sel){let b=Ch(n,M.doc,u.sel);b&&!(Me&&wt&&n.composing&&b.empty&&(h.start!=h.endB||n.input.lastAndroidDeletee.content.size?null:mf(n,e.resolve(t.anchor),e.resolve(t.head))}function Iv(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,o=r,s,l,a;for(let c=0;cc.mark(l.addToSet(c.marks));else if(i.length==0&&o.length==1)l=o[0],s="remove",a=c=>c.mark(l.removeFromSet(c.marks));else return null;let u=[];for(let c=0;ct||$a(s,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let o=n.node(r).maybeChild(n.indexAfter(r));for(;o&&!o.isLeaf;)o=o.firstChild,i++}return i}function Pv(n,e,t,r,i){let o=n.findDiffStart(e,t);if(o==null)return null;let{a:s,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let a=Math.max(0,o-Math.min(s,l));r-=s+a-o}if(s=s?o-r:0;o-=a,o&&o=l?o-r:0;o-=a,o&&o=56320&&e<=57343&&t>=55296&&t<=56319}class Fv{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 tv,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Th),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):typeof e=="function"?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=Oh(this),Eh(this),this.nodeViews=Dh(this),this.docView=oh(this.state.doc,Mh(this),La(this),this.dom,this),this.domObserver=new Mv(this,(r,i,o,s)=>bv(this,r,i,o,s)),this.domObserver.start(),nv(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&&Uu(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Th),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let r in this._props)t[r]=this._props[r];t.state=this.state;for(let r in e)t[r]=e[r];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var r;let i=this.state,o=!1,s=!1;e.storedMarks&&this.composing&&(Zg(this),s=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let p=Dh(this);$v(p,this.nodeViews)&&(this.nodeViews=p,o=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&Uu(this),this.editable=Oh(this),Eh(this);let a=La(this),u=Mh(this),c=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",f=o||!this.docView.matchesNode(e.doc,u,a);(f||!e.selection.eq(i.selection))&&(s=!0);let d=c=="preserve"&&s&&this.dom.style.overflowAnchor==null&&gk(this);if(s){this.domObserver.stop();let p=f&&(We||Me)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Lv(i.selection,e.selection);if(f){let h=Me?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=mv(this)),(o||!this.docView.update(e.doc,u,a,this))&&(this.docView.updateOuterDeco(u),this.docView.destroy(),this.docView=oh(e.doc,u,a,this.dom,this)),h&&!this.trackWrites&&(p=!0)}p||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Bk(this))?qt(this,p):(Bg(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),c=="reset"?this.dom.scrollTop=0:c=="to selection"?this.scrollToSelection():d&&yk(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof I){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&Zd(this,t.getBoundingClientRect(),e)}else Zd(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t0&&this.state.doc.nodeAt(o))==r.node&&(i=o)}this.dragging=new ty(e.slice,e.move,i<0?void 0:I.create(this.state.doc,i))}someProp(e,t){let r=this._props&&this._props[e],i;if(r!=null&&(i=t?t(r):r))return i;for(let s=0;st.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Ck(this,e)}coordsAtPos(e,t=1){return Tg(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,r=-1){let i=this.docView.posFromDOM(e,t,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return Dk(this,t||this.state,e)}pasteHTML(e,t){return xo(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return xo(this,e,null,!0,t||new ClipboardEvent("paste"))}destroy(){this.docView&&(rv(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],La(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,ok())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return ov(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){let e=this.domSelection();return e?be&&this.root.nodeType===11&&ck(this.dom.ownerDocument)==this.dom&&Ov(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function Mh(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let r in t)r=="class"?e.class+=" "+t[r]:r=="style"?e.style=(e.style?e.style+";":"")+t[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(t[r]))}),e.translate||(e.translate="no"),[Se.node(0,n.state.doc.content.size,e)]}function Eh(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:Se.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function Oh(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Lv(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function Dh(n){let e=Object.create(null);function t(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function $v(n,e){let t=0,r=0;for(let i in n){if(n[i]!=e[i])return!0;t++}for(let i in e)r++;return t!=r}function Th(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}class ee extends P{constructor(e){super(e,e)}map(e,t){let r=e.resolve(t.map(this.head));return ee.valid(r)?new ee(r):P.near(r)}content(){return v.empty}eq(e){return e instanceof ee&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new ee(e.resolve(t.pos))}getBookmark(){return new vf(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!Vv(e)||!Bv(e))return!1;let r=t.type.spec.allowGapCursor;if(r!=null)return r;let i=t.contentMatchAt(e.index()).defaultType;return i&&i.isTextblock}static findGapCursorFrom(e,t,r=!1){e:for(;;){if(!r&&ee.valid(e))return e;let i=e.pos,o=null;for(let s=e.depth;;s--){let l=e.node(s);if(t>0?e.indexAfter(s)0){o=l.child(t>0?e.indexAfter(s):e.index(s)-1);break}else if(s==0)return null;i+=t;let a=e.doc.resolve(i);if(ee.valid(a))return a}for(;;){let s=t>0?o.firstChild:o.lastChild;if(!s){if(o.isAtom&&!o.isText&&!I.isSelectable(o)){e=e.doc.resolve(i+o.nodeSize*t),r=!1;continue e}break}o=s,i+=t;let l=e.doc.resolve(i);if(ee.valid(l))return l}return null}}}ee.prototype.visible=!1;ee.findFrom=ee.findGapCursorFrom;P.jsonID("gapcursor",ee);class vf{constructor(e){this.pos=e}map(e){return new vf(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return ee.valid(t)?new ee(t):P.near(t)}}function Vv(n){for(let e=n.depth;e>=0;e--){let t=n.index(e),r=n.node(e);if(t==0){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(t-1);;i=i.lastChild){if(i.childCount==0&&!i.inlineContent||i.isAtom||i.type.spec.isolating)return!0;if(i.inlineContent)return!1}}return!0}function Bv(n){for(let e=n.depth;e>=0;e--){let t=n.indexAfter(e),r=n.node(e);if(t==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(t);;i=i.firstChild){if(i.childCount==0&&!i.inlineContent||i.isAtom||i.type.spec.isolating)return!0;if(i.inlineContent)return!1}}return!0}function Jv(){return new $t({props:{decorations:Hv,createSelectionBetween(n,e,t){return e.pos==t.pos&&ee.valid(t)?new ee(t):null},handleClick:Wv,handleKeyDown:_v,handleDOMEvents:{beforeinput:Uv}}})}const _v=Xw({ArrowLeft:ps("horiz",-1),ArrowRight:ps("horiz",1),ArrowUp:ps("vert",-1),ArrowDown:ps("vert",1)});function ps(n,e){const t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,i,o){let s=r.selection,l=e>0?s.$to:s.$from,a=s.empty;if(s instanceof $){if(!o.endOfTextblock(t)||l.depth==0)return!1;a=!1,l=r.doc.resolve(e>0?l.after():l.before())}let u=ee.findGapCursorFrom(l,e,a);return u?(i&&i(r.tr.setSelection(new ee(u))),!0):!1}}function Wv(n,e,t){if(!n||!n.editable)return!1;let r=n.state.doc.resolve(e);if(!ee.valid(r))return!1;let i=n.posAtCoords({left:t.clientX,top:t.clientY});return i&&i.inside>-1&&I.isSelectable(n.state.doc.nodeAt(i.inside))?!1:(n.dispatch(n.state.tr.setSelection(new ee(r))),!0)}function Uv(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof ee))return!1;let{$from:t}=n.state.selection,r=t.parent.contentMatchAt(t.index()).findWrapping(n.state.schema.nodes.text);if(!r)return!1;let i=C.empty;for(let s=r.length-1;s>=0;s--)i=C.from(r[s].createAndFill(null,i));let o=n.state.tr.replace(t.pos,t.pos,new v(i,0,0));return o.setSelection($.near(o.doc.resolve(t.pos+1))),n.dispatch(o),!1}function Hv(n){if(!(n.selection instanceof ee))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",_.create(n.doc,[Se.widget(n.selection.head,e,{key:"gapcursor"})])}const ly=65535,ay=Math.pow(2,16);function jv(n,e){return n+e*ay}function Rh(n){return n&ly}function Kv(n){return(n-(n&ly))/ay}const uy=1,cy=2,Gs=4,fy=8;let Ah=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&fy)>0}get deletedBefore(){return(this.delInfo&(uy|Gs))>0}get deletedAfter(){return(this.delInfo&(cy|Gs))>0}get deletedAcross(){return(this.delInfo&Gs)>0}},ei=class Er{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&Er.empty)return Er.empty}recover(e){let t=0,r=Rh(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],f=a+u;if(e<=f){let d=u?e==a?-1:e==f?1:t:t,p=a+i+(d<0?0:c);if(r)return p;let h=e==(t<0?a:f)?null:jv(l/3,e-a),m=e==a?cy:e==f?uy:Gs;return(t<0?e!=a:e!=f)&&(m|=fy),new Ah(p,m,h)}i+=c-u}return r?e+i:new Ah(e+i,0,null)}touches(e,t){let r=0,i=Rh(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return Je.fromReplace(e,this.from,this.to,o)}invert(){return new hy(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new Hi(t.pos,r.pos,this.mark)}merge(e){return e instanceof Hi&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Hi(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Hi(t.from,t.to,e.markFromJSON(t.mark))}};Ye.jsonID("addMark",dy);let hy=class ji extends Ye{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new v(xf(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return Je.fromReplace(e,this.from,this.to,r)}invert(){return new dy(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new ji(t.pos,r.pos,this.mark)}merge(e){return e instanceof ji&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new ji(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new ji(t.from,t.to,e.markFromJSON(t.mark))}};Ye.jsonID("removeMark",hy);let py=class Ki extends Ye{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Je.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return Je.fromReplace(e,this.pos,this.pos+1,new v(C.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new Xs(t.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Xs(t.from,t.to,t.gapFrom,t.gapTo,v.fromJSON(e,t.slice),t.insert,!!t.structure)}};Ye.jsonID("replaceAround",Qv);function ju(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function Yv(n,e,t=null,r=n){let i=Gv(n,e),o=i&&Xv(r,e);return o?i.map(bh).concat({type:e,attrs:t}).concat(o.map(bh)):null}function bh(n){return{type:n,attrs:null}}function Gv(n,e){let{parent:t,startIndex:r,endIndex:i}=n,o=t.contentMatchAt(r).findWrapping(e);if(!o)return null;let s=o.length?o[0]:e;return t.canReplaceWith(r,i,s)?o:null}function Xv(n,e){let{parent:t,startIndex:r,endIndex:i}=n,o=t.child(r),s=e.contentMatch.findWrapping(o.type);if(!s)return null;let a=(s.length?s[s.length-1]:e).contentMatch;for(let u=r;a&&u0&&(o=t[0].slice(s-l,s)+o,r=i)}return e.tr.insertText(o,r,i)}}const rx=500;function ix({rules:n}){let e=new $t({state:{init(){return null},apply(t,r){let i=t.getMeta(this);return i||(t.selectionSet||t.docChanged?null:r)}},props:{handleTextInput(t,r,i,o){return Ih(t,r,i,o,n,e)},handleDOMEvents:{compositionend:t=>{setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&Ih(t,r.pos,r.pos,"",n,e)})}}},isInputRules:!0});return e}function Ih(n,e,t,r,i,o){if(n.composing)return!1;let s=n.state,l=s.doc.resolve(e),a=l.parent.textBetween(Math.max(0,l.parentOffset-rx),l.parentOffset,null,"")+r;for(let u=0;u{let a=t instanceof Function?t(o):t,u=i.tr.delete(s,l),c=u.doc.resolve(s),f=c.blockRange(),d=f&&Yv(f,e,a);if(!d)return null;u.wrap(f,d);let p=u.doc.resolve(s-1).nodeBefore;return p&&p.type==e&&Zv(u.doc,s-1)&&!r&&u.join(s-1),u})}const sx=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function lx(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,o,s;for(let l=0;l127)&&(o=It[r.keyCode])&&o!=i){let l=e[Ba(o,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}const fx=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function dx(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,o,s;for(let l=0;l127)&&(o=It[r.keyCode])&&o!=i){let l=e[Ja(o,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}const gy=65535,yy=Math.pow(2,16);function mx(n,e){return n+e*yy}function zh(n){return n&gy}function gx(n){return(n-(n&gy))/yy}const Sy=1,wy=2,el=4,ky=8;class Ku{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&ky)>0}get deletedBefore(){return(this.delInfo&(Sy|el))>0}get deletedAfter(){return(this.delInfo&(wy|el))>0}get deletedAcross(){return(this.delInfo&el)>0}}class Xe{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&Xe.empty)return Xe.empty}recover(e){let t=0,r=zh(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],f=a+u;if(e<=f){let d=u?e==a?-1:e==f?1:t:t,p=a+i+(d<0?0:c);if(r)return p;let h=e==(t<0?a:f)?null:mx(l/3,e-a),m=e==a?wy:e==f?Sy:el;return(t<0?e!=a:e!=f)&&(m|=ky),new Ku(p,m,h)}i+=c-u}return r?e+i:new Ku(e+i,0,null)}touches(e,t){let r=0,i=zh(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new io;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;ro&&a!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return oe.fromReplace(e,this.from,this.to,o)}invert(){return new Dt(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new pn(t.pos,r.pos,this.mark)}merge(e){return e instanceof pn&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new pn(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new pn(t.from,t.to,e.markFromJSON(t.mark))}}De.jsonID("addMark",pn);class Dt extends De{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new v(Cf(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return oe.fromReplace(e,this.from,this.to,r)}invert(){return new pn(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new Dt(t.pos,r.pos,this.mark)}merge(e){return e instanceof Dt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Dt(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Dt(t.from,t.to,e.markFromJSON(t.mark))}}De.jsonID("removeMark",Dt);class mn extends De{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return oe.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return oe.fromReplace(e,this.pos,this.pos+1,new v(C.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new Rt(t.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Rt(t.from,t.to,t.gapFrom,t.gapTo,v.fromJSON(e,t.slice),t.insert,!!t.structure)}}De.jsonID("replaceAround",Rt);function qu(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function yx(n,e,t,r){let i=[],o=[],s,l;n.doc.nodesBetween(e,t,(a,u,c)=>{if(!a.isInline)return;let f=a.marks;if(!r.isInSet(f)&&c.type.allowsMarkType(r.type)){let d=Math.max(u,e),p=Math.min(u+a.nodeSize,t),h=r.addToSet(f);for(let m=0;mn.step(a)),o.forEach(a=>n.step(a))}function Sx(n,e,t,r){let i=[],o=0;n.doc.nodesBetween(e,t,(s,l)=>{if(!s.isInline)return;o++;let a=null;if(r instanceof qo){let u=s.marks,c;for(;c=r.isInSet(u);)(a||(a=[])).push(c),u=c.removeFromSet(u)}else r?r.isInSet(s.marks)&&(a=[r]):a=s.marks;if(a&&a.length){let u=Math.min(l+s.nodeSize,t);for(let c=0;cn.step(new Dt(s.from,s.to,s.style)))}function wx(n,e,t,r=t.contentMatch){let i=n.doc.nodeAt(e),o=[],s=e+1;for(let l=0;l=0;l--)n.step(o[l])}function kx(n,e,t){let{$from:r,$to:i,depth:o}=e,s=r.before(o+1),l=i.after(o+1),a=s,u=l,c=C.empty,f=0;for(let h=o,m=!1;h>t;h--)m||r.index(h)>0?(m=!0,c=C.from(r.node(h).copy(c)),f++):a--;let d=C.empty,p=0;for(let h=o,m=!1;h>t;h--)m||i.after(h+1)=0;s--){if(r.size){let l=t[s].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=C.from(t[s].type.create(t[s].attrs,r))}let i=e.start,o=e.end;n.step(new Rt(i,o,i,o,new v(r,0,0),t.length,!0))}function xx(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=n.steps.length;n.doc.nodesBetween(e,t,(s,l)=>{if(s.isTextblock&&!s.hasMarkup(r,i)&&Cx(n.doc,n.mapping.slice(o).map(l),r)){n.clearIncompatible(n.mapping.slice(o).map(l,1),r);let a=n.mapping.slice(o),u=a.map(l,1),c=a.map(l+s.nodeSize,1);return n.step(new Rt(u,c,u+1,c-1,new v(C.from(r.create(i,null,s.marks)),0,0),1,!0)),!1}})}function Cx(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function Nx(n,e,t,r,i){let o=n.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");t||(t=o.type);let s=t.create(r,null,i||o.marks);if(o.isLeaf)return n.replaceWith(e,e+o.nodeSize,s);if(!t.validContent(o.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new Rt(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new v(C.from(s),0,0),1,!0))}function Mx(n,e,t=1,r){let i=n.doc.resolve(e),o=C.empty,s=C.empty;for(let l=i.depth,a=i.depth-t,u=t-1;l>a;l--,u--){o=C.from(i.node(l).copy(o));let c=r&&r[u];s=C.from(c?c.type.create(c.attrs,s):i.node(l).copy(s))}n.step(new Re(e,e,new v(o.append(s),t,t),!0))}function Ex(n,e,t){let r=new Re(e-t,e+t,v.empty,!0);n.step(r)}function Ox(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let o=r.index(i);if(r.node(i).canReplaceWith(o,o,t))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,t))return r.after(i+1);if(o0;i--)this.placed=C.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let u=this.findFittable();u?this.placeNodes(u):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let a=new v(o,s,l);return e>-1?new Rt(r.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||r.pos!=this.$to.pos?new Re(r.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),o.type.spec.isolating&&i<=r){e=r;break}t=o.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=Wa(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:u}=this.frontier[l],c,f=null;if(t==1&&(s?u.matchType(s.type)||(f=u.fillBefore(C.from(s),!1)):o&&a.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:f};if(t==2&&s&&(c=u.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:c};if(o&&u.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Wa(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new v(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Wa(e,t);if(i.childCount<=1&&t>0){let o=e.size-t<=t+i.size;this.unplaced=new v(qi(e,t-1,1),t-1,o?t-1:r)}else this.unplaced=new v(qi(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:o}){for(;this.depth>t;)this.closeFrontierNode();if(o)for(let m=0;m1||a==0||m.content.size)&&(f=w,c.push(xy(m.mark(d.allowedMarks(m.marks)),u==1?a:0,u==l.childCount?p:-1)))}let h=u==l.childCount;h||(p=-1),this.placed=Qi(this.placed,t,C.from(c)),this.frontier[t].match=f,h&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,w=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],o=t=0;l--){let{match:a,type:u}=this.frontier[l],c=Ua(e,l,u,a,!0);if(!c||c.childCount)continue e}return{depth:t,fit:s,move:o?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Qi(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Qi(this.placed,this.depth,C.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(C.empty,!0);t.childCount&&(this.placed=Qi(this.placed,this.frontier.length,t))}}function qi(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(qi(n.firstChild.content,e-1,t)))}function Qi(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Qi(n.lastChild.content,e-1,t)))}function Wa(n,e){for(let t=0;t1&&(r=r.replaceChild(0,xy(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(C.empty,!0)))),n.copy(r)}function Ua(n,e,t,r,i){let o=n.node(e),s=i?n.indexAfter(e):n.index(e);if(s==o.childCount&&!t.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!Rx(t,o.content,s)?l:null}function Rx(n,e,t){for(let r=t;r0;d--,p--){let h=i.node(d).type.spec;if(h.defining||h.definingAsContext||h.isolating)break;s.indexOf(d)>-1?l=d:i.before(d)==p&&s.splice(1,0,-d)}let a=s.indexOf(l),u=[],c=r.openStart;for(let d=r.content,p=0;;p++){let h=d.firstChild;if(u.push(h),p==r.openStart)break;d=h.content}for(let d=c-1;d>=0;d--){let p=u[d],h=Ax(p.type);if(h&&!p.sameMarkup(i.node(Math.abs(l)-1)))c=d;else if(h||!p.type.isTextblock)break}for(let d=r.openStart;d>=0;d--){let p=(d+c+1)%(r.openStart+1),h=u[p];if(h)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>f));d--){let p=s[d];p<0||(e=i.before(p),t=o.after(p))}}function Cy(n,e,t,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(n).append(n);n=s.append(o.matchFragment(s).fillBefore(C.empty,!0))}return n}function Ix(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Ox(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new v(C.from(r),0,0))}function zx(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),o=Ny(r,i);for(let s=0;s0&&(a||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&t>r.end(s)&&i.end(s)-t!=i.depth-s)return n.delete(r.before(s),t);n.delete(e,t)}function Ny(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let o=n.start(i);if(oe.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&t.push(i)}return t}class Jr extends De{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return oe.fail("No node at attribute step's position");let r=Object.create(null);for(let o in t.attrs)r[o]=t.attrs[o];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return oe.fromReplace(e,this.pos,this.pos+1,new v(C.from(i),0,t.isLeaf?0:1))}getMap(){return Xe.empty}invert(e){return new Jr(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 Jr(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new Jr(t.pos,t.attr,t.value)}}De.jsonID("attr",Jr);class Mo extends De{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return oe.ok(r)}getMap(){return Xe.empty}invert(e){return new Mo(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new Mo(t.attr,t.value)}}De.jsonID("docAttr",Mo);let ni=class extends Error{};ni=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};ni.prototype=Object.create(Error.prototype);ni.prototype.constructor=ni;ni.prototype.name="TransformError";class Px{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new io}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new ni(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=v.empty){let i=Dx(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new v(C.from(r),0,0))}delete(e,t){return this.replace(e,t,v.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return bx(this,e,t,r),this}replaceRangeWith(e,t,r){return Ix(this,e,t,r),this}deleteRange(e,t){return zx(this,e,t),this}lift(e,t){return kx(this,e,t),this}join(e,t=1){return Ex(this,e,t),this}wrap(e,t){return vx(this,e,t),this}setBlockType(e,t=e,r,i=null){return xx(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return Nx(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new Jr(e,t,r)),this}setDocAttribute(e,t){return this.step(new Mo(e,t)),this}addNodeMark(e,t){return this.step(new mn(e,t)),this}removeNodeMark(e,t){if(!(t instanceof W)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t=t.isInSet(r.marks),!t)return this}return this.step(new ti(e,t)),this}split(e,t=1,r){return Mx(this,e,t,r),this}addMark(e,t,r){return yx(this,e,t,r),this}removeMark(e,t,r){return Sx(this,e,t,r),this}clearIncompatible(e,t,r){return wx(this,e,t,r),this}}var Qu,Yu;if(typeof WeakMap<"u"){let n=new WeakMap;Qu=e=>n.get(e),Yu=(e,t)=>(n.set(e,t),t)}else{const n=[];let t=0;Qu=r=>{for(let i=0;i(t==10&&(t=0),n[t++]=r,n[t++]=i)}var re=class{constructor(n,e,t,r){this.width=n,this.height=e,this.map=t,this.problems=r}findCell(n){for(let e=0;e=t){(o||(o=[])).push({type:"overlong_rowspan",pos:c,n:g-S});break}const x=i+S*e;for(let N=0;Nr&&(o+=u.attrs.colspan)}}for(let s=0;s1&&(t=!0)}e==-1?e=o:e!=o&&(e=Math.max(e,o))}return e}function $x(n,e,t){n.problems||(n.problems=[]);const r={};for(let i=0;iNumber(s)):null,i=Number(n.getAttribute("colspan")||1),o={colspan:i,rowspan:Number(n.getAttribute("rowspan")||1),colwidth:r&&r.length==i?r:null};for(const s in e){const l=e[s].getFromDOM,a=l&&l(n);a!=null&&(o[s]=a)}return o}function Fh(n,e){const t={};n.attrs.colspan!=1&&(t.colspan=n.attrs.colspan),n.attrs.rowspan!=1&&(t.rowspan=n.attrs.rowspan),n.attrs.colwidth&&(t["data-colwidth"]=n.attrs.colwidth.join(","));for(const r in e){const i=e[r].setDOMAttr;i&&i(n.attrs[r],t)}return t}function Bx(n){const e=n.cellAttributes||{},t={colspan:{default:1},rowspan:{default:1},colwidth:{default:null}};for(const r in e)t[r]={default:e[r].default};return{table:{content:"table_row+",tableRole:"table",isolating:!0,group:n.tableGroup,parseDOM:[{tag:"table"}],toDOM(){return["table",["tbody",0]]}},table_row:{content:"(table_cell | table_header)*",tableRole:"row",parseDOM:[{tag:"tr"}],toDOM(){return["tr",0]}},table_cell:{content:n.cellContent,attrs:t,tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:r=>Ph(r,e)}],toDOM(r){return["td",Fh(r,e),0]}},table_header:{content:n.cellContent,attrs:t,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>Ph(r,e)}],toDOM(r){return["th",Fh(r,e),0]}}}}function Ft(n){let e=n.cached.tableNodeTypes;if(!e){e=n.cached.tableNodeTypes={};for(const t in n.nodes){const r=n.nodes[t],i=r.spec.tableRole;i&&(e[i]=r)}}return e}var an=new Yo("selectingCells");function es(n){for(let e=n.depth-1;e>0;e--)if(n.node(e).type.spec.tableRole=="row")return n.node(0).resolve(n.before(e+1));return null}function Nf(n){const e=n.selection.$head;for(let t=e.depth;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return!0;return!1}function My(n){const e=n.selection;if("$anchorCell"in e&&e.$anchorCell)return e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell;if("node"in e&&e.node&&e.node.type.spec.tableRole=="cell")return e.$anchor;const t=es(e.$head)||Jx(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function Jx(n){for(let e=n.nodeAfter,t=n.pos;e;e=e.firstChild,t++){const r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t)}for(let e=n.nodeBefore,t=n.pos;e;e=e.lastChild,t--){const r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t-e.nodeSize)}}function Gu(n){return n.parent.type.spec.tableRole=="row"&&!!n.nodeAfter}function Mf(n,e){return n.depth==e.depth&&n.pos>=e.start(-1)&&n.pos<=e.end(-1)}function Ey(n,e,t){const r=n.node(-1),i=re.get(r),o=n.start(-1),s=i.nextCell(n.pos-o,e,t);return s==null?null:n.node(0).resolve(o+s)}function ri(n,e,t=1){const r={...n,colspan:n.colspan-t};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,t),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}var fe=class Jt extends P{constructor(e,t=e){const r=e.node(-1),i=re.get(r),o=e.start(-1),s=i.rectBetween(e.pos-o,t.pos-o),l=e.node(0),a=i.cellsInRect(s).filter(c=>c!=t.pos-o);a.unshift(t.pos-o);const u=a.map(c=>{const f=r.nodeAt(c);if(!f)throw RangeError(`No cell with offset ${c} found`);const d=o+c+1;return new og(l.resolve(d),l.resolve(d+f.content.size))});super(u[0].$from,u[0].$to,u),this.$anchorCell=e,this.$headCell=t}map(e,t){const r=e.resolve(t.map(this.$anchorCell.pos)),i=e.resolve(t.map(this.$headCell.pos));if(Gu(r)&&Gu(i)&&Mf(r,i)){const o=this.$anchorCell.node(-1)!=r.node(-1);return o&&this.isRowSelection()?Jt.rowSelection(r,i):o&&this.isColSelection()?Jt.colSelection(r,i):new Jt(r,i)}return $.between(r,i)}content(){const e=this.$anchorCell.node(-1),t=re.get(e),r=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),o={},s=[];for(let a=i.top;a0||w>0){let g=h.attrs;if(m>0&&(g=ri(g,0,m)),w>0&&(g=ri(g,g.colspan-w,w)),p.lefti.bottom){const g={...h.attrs,rowspan:Math.min(p.bottom,i.bottom)-Math.max(p.top,i.top)};p.top0)return!1;const r=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(e,t=e){const r=e.node(-1),i=re.get(r),o=e.start(-1),s=i.findCell(e.pos-o),l=i.findCell(t.pos-o),a=e.node(0);return s.top<=l.top?(s.top>0&&(e=a.resolve(o+i.map[s.left])),l.bottom0&&(t=a.resolve(o+i.map[l.left])),s.bottom0)return!1;const s=i+this.$anchorCell.nodeAfter.attrs.colspan,l=o+this.$headCell.nodeAfter.attrs.colspan;return Math.max(s,l)==t.width}eq(e){return e instanceof Jt&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,t=e){const r=e.node(-1),i=re.get(r),o=e.start(-1),s=i.findCell(e.pos-o),l=i.findCell(t.pos-o),a=e.node(0);return s.left<=l.left?(s.left>0&&(e=a.resolve(o+i.map[s.top*i.width])),l.right0&&(t=a.resolve(o+i.map[l.top*i.width])),s.right{e.push(Se.node(r,r+t.nodeSize,{class:"selectedCell"}))}),_.create(n.doc,e)}function Ux({$from:n,$to:e}){if(n.pos==e.pos||n.pos=0&&!(n.after(i+1)=0&&!(e.before(o+1)>e.start(o));o--,r--);return t==r&&/row|table/.test(n.node(i).type.spec.tableRole)}function Hx({$from:n,$to:e}){let t,r;for(let i=n.depth;i>0;i--){const o=n.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){t=o;break}}for(let i=e.depth;i>0;i--){const o=e.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){r=o;break}}return t!==r&&e.parentOffset===0}function jx(n,e,t){const r=(e||n).selection,i=(e||n).doc;let o,s;if(r instanceof I&&(s=r.node.type.spec.tableRole)){if(s=="cell"||s=="header_cell")o=fe.create(i,r.from);else if(s=="row"){const l=i.resolve(r.from+1);o=fe.rowSelection(l,l)}else if(!t){const l=re.get(r.node),a=r.from+1,u=a+l.map[l.width*l.height-1];o=fe.create(i,a+1,u)}}else r instanceof $&&Ux(r)?o=$.create(i,r.from):r instanceof $&&Hx(r)&&(o=$.create(i,r.$from.start(),r.$from.end()));return o&&(e||(e=n.tr)).setSelection(o),e}var Kx=new Yo("fix-tables");function Dy(n,e,t,r){const i=n.childCount,o=e.childCount;e:for(let s=0,l=0;s{i.type.spec.tableRole=="table"&&(t=Qx(n,i,o,t))};return e?e.doc!=n.doc&&Dy(e.doc,n.doc,0,r):n.doc.descendants(r),t}function Qx(n,e,t,r){const i=re.get(e);if(!i.problems)return r;r||(r=n.tr);const o=[];for(let a=0;a0){let p="cell";c.firstChild&&(p=c.firstChild.type.spec.tableRole);const h=[];for(let w=0;w0&&r>0||e.child(0).type.spec.tableRole=="table");)t--,r--,e=e.child(0).content;const i=e.child(0),o=i.type.spec.tableRole,s=i.type.schema,l=[];if(o=="row")for(let a=0;a=0;s--){const{rowspan:l,colspan:a}=o.child(s).attrs;for(let u=i;u=e.length&&e.push(C.empty),t[i]r&&(d=d.type.createChecked(ri(d.attrs,d.attrs.colspan,c+d.attrs.colspan-r),d.content)),u.push(d),c+=d.attrs.colspan;for(let p=1;pi&&(f=f.type.create({...f.attrs,rowspan:Math.max(1,i-f.attrs.rowspan)},f.content)),a.push(f)}o.push(C.from(a))}t=o,e=i}return{width:n,height:e,rows:t}}function Zx(n,e,t,r,i,o,s){const l=n.doc.type.schema,a=Ft(l);let u,c;if(i>e.width)for(let f=0,d=0;fe.height){const f=[];for(let h=0,m=(e.height-1)*e.width;h=e.width?!1:t.nodeAt(e.map[m+h]).type==a.header_cell;f.push(w?c||(c=a.header_cell.createAndFill()):u||(u=a.cell.createAndFill()))}const d=a.row.create(null,C.from(f)),p=[];for(let h=e.height;h{if(!i)return!1;const o=t.selection;if(o instanceof fe)return tl(t,r,P.near(o.$headCell,e));if(n!="horiz"&&!o.empty)return!1;const s=Ty(i,n,e);if(s==null)return!1;if(n=="horiz")return tl(t,r,P.near(t.doc.resolve(o.head+e),e));{const l=t.doc.resolve(s),a=Ey(l,n,e);let u;return a?u=P.near(a,1):e<0?u=P.near(t.doc.resolve(l.before(-1)),-1):u=P.near(t.doc.resolve(l.after(-1)),1),tl(t,r,u)}}}function gs(n,e){return(t,r,i)=>{if(!i)return!1;const o=t.selection;let s;if(o instanceof fe)s=o;else{const a=Ty(i,n,e);if(a==null)return!1;s=new fe(t.doc.resolve(a))}const l=Ey(s.$headCell,n,e);return l?tl(t,r,new fe(s.$anchorCell,l)):!1}}function ys(n,e){const t=n.selection;if(!(t instanceof fe))return!1;if(e){const r=n.tr,i=Ft(n.schema).cell.createAndFill().content;t.forEachCell((o,s)=>{o.content.eq(i)||r.replace(r.mapping.map(s+1),r.mapping.map(s+o.nodeSize-1),new v(i,0,0))}),r.docChanged&&e(r)}return!0}function tC(n,e){const t=n.state.doc,r=es(t.resolve(e));return r?(n.dispatch(n.state.tr.setSelection(new fe(r))),!0):!1}function nC(n,e,t){if(!Nf(n.state))return!1;let r=Yx(t);const i=n.state.selection;if(i instanceof fe){r||(r={width:1,height:1,rows:[C.from(Xu(Ft(n.state.schema).cell,t))]});const o=i.$anchorCell.node(-1),s=i.$anchorCell.start(-1),l=re.get(o).rectBetween(i.$anchorCell.pos-s,i.$headCell.pos-s);return r=Xx(r,l.right-l.left,l.bottom-l.top),Vh(n.state,n.dispatch,s,l,r),!0}else if(r){const o=My(n.state),s=o.start(-1);return Vh(n.state,n.dispatch,s,re.get(o.node(-1)).findCell(o.pos-s),r),!0}else return!1}function rC(n,e){var t;if(e.ctrlKey||e.metaKey)return;const r=Bh(n,e.target);let i;if(e.shiftKey&&n.state.selection instanceof fe)o(n.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=es(n.state.selection.$anchor))!=null&&((t=Ha(n,e))==null?void 0:t.pos)!=i.pos)o(i,e),e.preventDefault();else if(!r)return;function o(a,u){let c=Ha(n,u);const f=an.getState(n.state)==null;if(!c||!Mf(a,c))if(f)c=a;else return;const d=new fe(a,c);if(f||!n.state.selection.eq(d)){const p=n.state.tr.setSelection(d);f&&p.setMeta(an,a.pos),n.dispatch(p)}}function s(){n.root.removeEventListener("mouseup",s),n.root.removeEventListener("dragstart",s),n.root.removeEventListener("mousemove",l),an.getState(n.state)!=null&&n.dispatch(n.state.tr.setMeta(an,-1))}function l(a){const u=a,c=an.getState(n.state);let f;if(c!=null)f=n.state.doc.resolve(c);else if(Bh(n,u.target)!=r&&(f=Ha(n,e),!f))return s();f&&o(f,u)}n.root.addEventListener("mouseup",s),n.root.addEventListener("dragstart",s),n.root.addEventListener("mousemove",l)}function Ty(n,e,t){if(!(n.state.selection instanceof $))return null;const{$head:r}=n.state.selection;for(let i=r.depth-1;i>=0;i--){const o=r.node(i);if((t<0?r.index(i):r.indexAfter(i))!=(t<0?0:o.childCount))return null;if(o.type.spec.tableRole=="cell"||o.type.spec.tableRole=="header_cell"){const l=r.before(i),a=e=="vert"?t>0?"down":"up":t>0?"right":"left";return n.endOfTextblock(a)?l:null}}return null}function Bh(n,e){for(;e&&e!=n.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function Ha(n,e){const t=n.posAtCoords({left:e.clientX,top:e.clientY});return t&&t?es(n.state.doc.resolve(t.pos)):null}var iC=class{constructor(n,e){this.node=n,this.cellMinWidth=e,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.colgroup=this.table.appendChild(document.createElement("colgroup")),Zu(n,this.colgroup,this.table,e),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(n){return n.type!=this.node.type?!1:(this.node=n,Zu(n,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(n){return n.type=="attributes"&&(n.target==this.table||this.colgroup.contains(n.target))}};function Zu(n,e,t,r,i,o){var s;let l=0,a=!0,u=e.firstChild;const c=n.firstChild;if(c){for(let f=0,d=0;fnew t(l,e,a),new sC(-1,!1)},apply(o,s){return s.apply(o)}},props:{attributes:o=>{const s=ut.getState(o);return s&&s.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(o,s)=>{lC(o,s,n,e,r)},mouseleave:o=>{aC(o)},mousedown:(o,s)=>{uC(o,s,e)}},decorations:o=>{const s=ut.getState(o);if(s&&s.activeHandle>-1)return mC(o,s.activeHandle)},nodeViews:{}}});return i}var sC=class nl{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(e){const t=this,r=e.getMeta(ut);if(r&&r.setHandle!=null)return new nl(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new nl(t.activeHandle,r.setDragging);if(t.activeHandle>-1&&e.docChanged){let i=e.mapping.map(t.activeHandle,-1);return Gu(e.doc.resolve(i))||(i=-1),new nl(i,t.dragging)}return t}};function lC(n,e,t,r,i){const o=ut.getState(n.state);if(o&&!o.dragging){const s=fC(e.target);let l=-1;if(s){const{left:a,right:u}=s.getBoundingClientRect();e.clientX-a<=t?l=Jh(n,e,"left",t):u-e.clientX<=t&&(l=Jh(n,e,"right",t))}if(l!=o.activeHandle){if(!i&&l!==-1){const a=n.state.doc.resolve(l),u=a.node(-1),c=re.get(u),f=a.start(-1);if(c.colCount(a.pos-f)+a.nodeAfter.attrs.colspan-1==c.width-1)return}Ry(n,l)}}}function aC(n){const e=ut.getState(n.state);e&&e.activeHandle>-1&&!e.dragging&&Ry(n,-1)}function uC(n,e,t){var r;const i=(r=n.dom.ownerDocument.defaultView)!=null?r:window,o=ut.getState(n.state);if(!o||o.activeHandle==-1||o.dragging)return!1;const s=n.state.doc.nodeAt(o.activeHandle),l=cC(n,o.activeHandle,s.attrs);n.dispatch(n.state.tr.setMeta(ut,{setDragging:{startX:e.clientX,startWidth:l}}));function a(c){i.removeEventListener("mouseup",a),i.removeEventListener("mousemove",u);const f=ut.getState(n.state);f!=null&&f.dragging&&(dC(n,f.activeHandle,_h(f.dragging,c,t)),n.dispatch(n.state.tr.setMeta(ut,{setDragging:null})))}function u(c){if(!c.which)return a(c);const f=ut.getState(n.state);if(f&&f.dragging){const d=_h(f.dragging,c,t);hC(n,f.activeHandle,d,t)}}return i.addEventListener("mouseup",a),i.addEventListener("mousemove",u),e.preventDefault(),!0}function cC(n,e,{colspan:t,colwidth:r}){const i=r&&r[r.length-1];if(i)return i;const o=n.domAtPos(e);let l=o.node.childNodes[o.offset].offsetWidth,a=t;if(r)for(let u=0;ui.table.nodeAt(a));for(let a=0;a{const h=p+o.tableStart,m=s.doc.nodeAt(h);m&&s.setNodeMarkup(h,d,m.attrs)}),r(s)}return!0}}Ef("row",{useDeprecatedLogic:!0});Ef("column",{useDeprecatedLogic:!0});Ef("cell",{useDeprecatedLogic:!0});function yC({allowTableNodeSelection:n=!1}={}){return new $t({key:an,state:{init(){return null},apply(e,t){const r=e.getMeta(an);if(r!=null)return r==-1?null:r;if(t==null||!e.docChanged)return t;const{deleted:i,pos:o}=e.mapping.mapResult(t);return i?null:o}},props:{decorations:Wx,handleDOMEvents:{mousedown:rC},createSelectionBetween(e){return an.getState(e.state)!=null?e.state.selection:null},handleTripleClick:tC,handleKeyDown:eC,handlePaste:nC},appendTransaction(e,t,r){return jx(r,qx(r,t),n)}})}var by={exports:{}},rt={},Iy={exports:{}},zy={};/** + * @license React + * scheduler.production.min.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */(function(n){function e(T,F){var L=T.length;T.push(F);e:for(;0>>1,ue=T[te];if(0>>1;tei(Sa,L))Bni(us,Sa)?(T[te]=us,T[Bn]=L,te=Bn):(T[te]=Sa,T[Vn]=L,te=Vn);else if(Bni(us,L))T[te]=us,T[Bn]=L,te=Bn;else break e}}return F}function i(T,F){var L=T.sortIndex-F.sortIndex;return L!==0?L:T.id-F.id}if(typeof performance=="object"&&typeof performance.now=="function"){var o=performance;n.unstable_now=function(){return o.now()}}else{var s=Date,l=s.now();n.unstable_now=function(){return s.now()-l}}var a=[],u=[],c=1,f=null,d=3,p=!1,h=!1,m=!1,w=typeof setTimeout=="function"?setTimeout:null,g=typeof clearTimeout=="function"?clearTimeout:null,y=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function S(T){for(var F=t(u);F!==null;){if(F.callback===null)r(u);else if(F.startTime<=T)r(u),F.sortIndex=F.expirationTime,e(a,F);else break;F=t(u)}}function x(T){if(m=!1,S(T),!h)if(t(a)!==null)h=!0,he(N);else{var F=t(u);F!==null&&$n(x,F.startTime-T)}}function N(T,F){h=!1,m&&(m=!1,g(D),D=-1),p=!0;var L=d;try{for(S(F),f=t(a);f!==null&&(!(f.expirationTime>F)||T&&!ae());){var te=f.callback;if(typeof te=="function"){f.callback=null,d=f.priorityLevel;var ue=te(f.expirationTime<=F);F=n.unstable_now(),typeof ue=="function"?f.callback=ue:f===t(a)&&r(a),S(F)}else r(a);f=t(a)}if(f!==null)var as=!0;else{var Vn=t(u);Vn!==null&&$n(x,Vn.startTime-F),as=!1}return as}finally{f=null,d=L,p=!1}}var M=!1,O=null,D=-1,b=5,z=-1;function ae(){return!(n.unstable_now()-zT||125te?(T.sortIndex=L,e(u,T),t(a)===null&&T===t(u)&&(m?(g(D),D=-1):m=!0,$n(x,L-te))):(T.sortIndex=ue,e(a,T),h||p||(h=!0,he(N))),T},n.unstable_shouldYield=ae,n.unstable_wrapCallback=function(T){var F=d;return function(){var L=d;d=F;try{return T.apply(this,arguments)}finally{d=L}}}})(zy);Iy.exports=zy;var SC=Iy.exports;/** + * @license React + * react-dom.production.min.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */var Py=k,nt=SC;function E(n){for(var e="https://reactjs.org/docs/error-decoder.html?invariant="+n,t=1;t"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),ec=Object.prototype.hasOwnProperty,wC=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,Uh={},Hh={};function kC(n){return ec.call(Hh,n)?!0:ec.call(Uh,n)?!1:wC.test(n)?Hh[n]=!0:(Uh[n]=!0,!1)}function vC(n,e,t,r){if(t!==null&&t.type===0)return!1;switch(typeof e){case"function":case"symbol":return!0;case"boolean":return r?!1:t!==null?!t.acceptsBooleans:(n=n.toLowerCase().slice(0,5),n!=="data-"&&n!=="aria-");default:return!1}}function xC(n,e,t,r){if(e===null||typeof e>"u"||vC(n,e,t,r))return!0;if(r)return!1;if(t!==null)switch(t.type){case 3:return!e;case 4:return e===!1;case 5:return isNaN(e);case 6:return isNaN(e)||1>e}return!1}function Fe(n,e,t,r,i,o,s){this.acceptsBooleans=e===2||e===3||e===4,this.attributeName=r,this.attributeNamespace=i,this.mustUseProperty=t,this.propertyName=n,this.type=e,this.sanitizeURL=o,this.removeEmptyString=s}var ke={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(n){ke[n]=new Fe(n,0,!1,n,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(n){var e=n[0];ke[e]=new Fe(e,1,!1,n[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(n){ke[n]=new Fe(n,2,!1,n.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(n){ke[n]=new Fe(n,2,!1,n,null,!1,!1)});"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(n){ke[n]=new Fe(n,3,!1,n.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(n){ke[n]=new Fe(n,3,!0,n,null,!1,!1)});["capture","download"].forEach(function(n){ke[n]=new Fe(n,4,!1,n,null,!1,!1)});["cols","rows","size","span"].forEach(function(n){ke[n]=new Fe(n,6,!1,n,null,!1,!1)});["rowSpan","start"].forEach(function(n){ke[n]=new Fe(n,5,!1,n.toLowerCase(),null,!1,!1)});var Of=/[\-:]([a-z])/g;function Df(n){return n[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(n){var e=n.replace(Of,Df);ke[e]=new Fe(e,1,!1,n,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(n){var e=n.replace(Of,Df);ke[e]=new Fe(e,1,!1,n,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(n){var e=n.replace(Of,Df);ke[e]=new Fe(e,1,!1,n,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(n){ke[n]=new Fe(n,1,!1,n.toLowerCase(),null,!1,!1)});ke.xlinkHref=new Fe("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(n){ke[n]=new Fe(n,1,!1,n.toLowerCase(),null,!0,!0)});function Tf(n,e,t,r){var i=ke.hasOwnProperty(e)?ke[e]:null;(i!==null?i.type!==0:r||!(2l||i[s]!==o[l]){var a=` +`+i[s].replace(" at new "," at ");return n.displayName&&a.includes("")&&(a=a.replace("",n.displayName)),a}while(1<=s&&0<=l);break}}}finally{Ka=!1,Error.prepareStackTrace=t}return(n=n?n.displayName||n.name:"")?Yi(n):""}function CC(n){switch(n.tag){case 5:return Yi(n.type);case 16:return Yi("Lazy");case 13:return Yi("Suspense");case 19:return Yi("SuspenseList");case 0:case 2:case 15:return n=qa(n.type,!1),n;case 11:return n=qa(n.type.render,!1),n;case 1:return n=qa(n.type,!0),n;default:return""}}function ic(n){if(n==null)return null;if(typeof n=="function")return n.displayName||n.name||null;if(typeof n=="string")return n;switch(n){case Dr:return"Fragment";case Or:return"Portal";case tc:return"Profiler";case Rf:return"StrictMode";case nc:return"Suspense";case rc:return"SuspenseList"}if(typeof n=="object")switch(n.$$typeof){case $y:return(n.displayName||"Context")+".Consumer";case Ly:return(n._context.displayName||"Context")+".Provider";case Af:var e=n.render;return n=n.displayName,n||(n=e.displayName||e.name||"",n=n!==""?"ForwardRef("+n+")":"ForwardRef"),n;case bf:return e=n.displayName||null,e!==null?e:ic(n.type)||"Memo";case on:e=n._payload,n=n._init;try{return ic(n(e))}catch{}}return null}function NC(n){var e=n.type;switch(n.tag){case 24:return"Cache";case 9:return(e.displayName||"Context")+".Consumer";case 10:return(e._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return n=e.render,n=n.displayName||n.name||"",e.displayName||(n!==""?"ForwardRef("+n+")":"ForwardRef");case 7:return"Fragment";case 5:return e;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return ic(e);case 8:return e===Rf?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e}return null}function Tn(n){switch(typeof n){case"boolean":case"number":case"string":case"undefined":return n;case"object":return n;default:return""}}function By(n){var e=n.type;return(n=n.nodeName)&&n.toLowerCase()==="input"&&(e==="checkbox"||e==="radio")}function MC(n){var e=By(n)?"checked":"value",t=Object.getOwnPropertyDescriptor(n.constructor.prototype,e),r=""+n[e];if(!n.hasOwnProperty(e)&&typeof t<"u"&&typeof t.get=="function"&&typeof t.set=="function"){var i=t.get,o=t.set;return Object.defineProperty(n,e,{configurable:!0,get:function(){return i.call(this)},set:function(s){r=""+s,o.call(this,s)}}),Object.defineProperty(n,e,{enumerable:t.enumerable}),{getValue:function(){return r},setValue:function(s){r=""+s},stopTracking:function(){n._valueTracker=null,delete n[e]}}}}function ws(n){n._valueTracker||(n._valueTracker=MC(n))}function Jy(n){if(!n)return!1;var e=n._valueTracker;if(!e)return!0;var t=e.getValue(),r="";return n&&(r=By(n)?n.checked?"true":"false":n.value),n=r,n!==t?(e.setValue(n),!0):!1}function Ml(n){if(n=n||(typeof document<"u"?document:void 0),typeof n>"u")return null;try{return n.activeElement||n.body}catch{return n.body}}function oc(n,e){var t=e.checked;return X({},e,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:t??n._wrapperState.initialChecked})}function Kh(n,e){var t=e.defaultValue==null?"":e.defaultValue,r=e.checked!=null?e.checked:e.defaultChecked;t=Tn(e.value!=null?e.value:t),n._wrapperState={initialChecked:r,initialValue:t,controlled:e.type==="checkbox"||e.type==="radio"?e.checked!=null:e.value!=null}}function _y(n,e){e=e.checked,e!=null&&Tf(n,"checked",e,!1)}function sc(n,e){_y(n,e);var t=Tn(e.value),r=e.type;if(t!=null)r==="number"?(t===0&&n.value===""||n.value!=t)&&(n.value=""+t):n.value!==""+t&&(n.value=""+t);else if(r==="submit"||r==="reset"){n.removeAttribute("value");return}e.hasOwnProperty("value")?lc(n,e.type,t):e.hasOwnProperty("defaultValue")&&lc(n,e.type,Tn(e.defaultValue)),e.checked==null&&e.defaultChecked!=null&&(n.defaultChecked=!!e.defaultChecked)}function qh(n,e,t){if(e.hasOwnProperty("value")||e.hasOwnProperty("defaultValue")){var r=e.type;if(!(r!=="submit"&&r!=="reset"||e.value!==void 0&&e.value!==null))return;e=""+n._wrapperState.initialValue,t||e===n.value||(n.value=e),n.defaultValue=e}t=n.name,t!==""&&(n.name=""),n.defaultChecked=!!n._wrapperState.initialChecked,t!==""&&(n.name=t)}function lc(n,e,t){(e!=="number"||Ml(n.ownerDocument)!==n)&&(t==null?n.defaultValue=""+n._wrapperState.initialValue:n.defaultValue!==""+t&&(n.defaultValue=""+t))}var Gi=Array.isArray;function _r(n,e,t,r){if(n=n.options,e){e={};for(var i=0;i"+e.valueOf().toString()+"",e=ks.firstChild;n.firstChild;)n.removeChild(n.firstChild);for(;e.firstChild;)n.appendChild(e.firstChild)}});function Oo(n,e){if(e){var t=n.firstChild;if(t&&t===n.lastChild&&t.nodeType===3){t.nodeValue=e;return}}n.textContent=e}var oo={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},EC=["Webkit","ms","Moz","O"];Object.keys(oo).forEach(function(n){EC.forEach(function(e){e=e+n.charAt(0).toUpperCase()+n.substring(1),oo[e]=oo[n]})});function jy(n,e,t){return e==null||typeof e=="boolean"||e===""?"":t||typeof e!="number"||e===0||oo.hasOwnProperty(n)&&oo[n]?(""+e).trim():e+"px"}function Ky(n,e){n=n.style;for(var t in e)if(e.hasOwnProperty(t)){var r=t.indexOf("--")===0,i=jy(t,e[t],r);t==="float"&&(t="cssFloat"),r?n.setProperty(t,i):n[t]=i}}var OC=X({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function cc(n,e){if(e){if(OC[n]&&(e.children!=null||e.dangerouslySetInnerHTML!=null))throw Error(E(137,n));if(e.dangerouslySetInnerHTML!=null){if(e.children!=null)throw Error(E(60));if(typeof e.dangerouslySetInnerHTML!="object"||!("__html"in e.dangerouslySetInnerHTML))throw Error(E(61))}if(e.style!=null&&typeof e.style!="object")throw Error(E(62))}}function fc(n,e){if(n.indexOf("-")===-1)return typeof e.is=="string";switch(n){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var dc=null;function If(n){return n=n.target||n.srcElement||window,n.correspondingUseElement&&(n=n.correspondingUseElement),n.nodeType===3?n.parentNode:n}var hc=null,Wr=null,Ur=null;function Gh(n){if(n=rs(n)){if(typeof hc!="function")throw Error(E(280));var e=n.stateNode;e&&(e=sa(e),hc(n.stateNode,n.type,e))}}function qy(n){Wr?Ur?Ur.push(n):Ur=[n]:Wr=n}function Qy(){if(Wr){var n=Wr,e=Ur;if(Ur=Wr=null,Gh(n),e)for(n=0;n>>=0,n===0?32:31-($C(n)/VC|0)|0}var vs=64,xs=4194304;function Xi(n){switch(n&-n){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return n&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return n&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return n}}function Tl(n,e){var t=n.pendingLanes;if(t===0)return 0;var r=0,i=n.suspendedLanes,o=n.pingedLanes,s=t&268435455;if(s!==0){var l=s&~i;l!==0?r=Xi(l):(o&=s,o!==0&&(r=Xi(o)))}else s=t&~i,s!==0?r=Xi(s):o!==0&&(r=Xi(o));if(r===0)return 0;if(e!==0&&e!==r&&!(e&i)&&(i=r&-r,o=e&-e,i>=o||i===16&&(o&4194240)!==0))return e;if(r&4&&(r|=t&16),e=n.entangledLanes,e!==0)for(n=n.entanglements,e&=r;0t;t++)e.push(n);return e}function ts(n,e,t){n.pendingLanes|=e,e!==536870912&&(n.suspendedLanes=0,n.pingedLanes=0),n=n.eventTimes,e=31-vt(e),n[e]=t}function WC(n,e){var t=n.pendingLanes&~e;n.pendingLanes=e,n.suspendedLanes=0,n.pingedLanes=0,n.expiredLanes&=e,n.mutableReadLanes&=e,n.entangledLanes&=e,e=n.entanglements;var r=n.eventTimes;for(n=n.expirationTimes;0=lo),sp=" ",lp=!1;function m0(n,e){switch(n){case"keyup":return yN.indexOf(e.keyCode)!==-1;case"keydown":return e.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function g0(n){return n=n.detail,typeof n=="object"&&"data"in n?n.data:null}var Tr=!1;function wN(n,e){switch(n){case"compositionend":return g0(e);case"keypress":return e.which!==32?null:(lp=!0,sp);case"textInput":return n=e.data,n===sp&&lp?null:n;default:return null}}function kN(n,e){if(Tr)return n==="compositionend"||!Jf&&m0(n,e)?(n=h0(),il=$f=gn=null,Tr=!1,n):null;switch(n){case"paste":return null;case"keypress":if(!(e.ctrlKey||e.altKey||e.metaKey)||e.ctrlKey&&e.altKey){if(e.char&&1=e)return{node:t,offset:e-n};n=r}e:{for(;t;){if(t.nextSibling){t=t.nextSibling;break e}t=t.parentNode}t=void 0}t=fp(t)}}function k0(n,e){return n&&e?n===e?!0:n&&n.nodeType===3?!1:e&&e.nodeType===3?k0(n,e.parentNode):"contains"in n?n.contains(e):n.compareDocumentPosition?!!(n.compareDocumentPosition(e)&16):!1:!1}function v0(){for(var n=window,e=Ml();e instanceof n.HTMLIFrameElement;){try{var t=typeof e.contentWindow.location.href=="string"}catch{t=!1}if(t)n=e.contentWindow;else break;e=Ml(n.document)}return e}function _f(n){var e=n&&n.nodeName&&n.nodeName.toLowerCase();return e&&(e==="input"&&(n.type==="text"||n.type==="search"||n.type==="tel"||n.type==="url"||n.type==="password")||e==="textarea"||n.contentEditable==="true")}function TN(n){var e=v0(),t=n.focusedElem,r=n.selectionRange;if(e!==t&&t&&t.ownerDocument&&k0(t.ownerDocument.documentElement,t)){if(r!==null&&_f(t)){if(e=r.start,n=r.end,n===void 0&&(n=e),"selectionStart"in t)t.selectionStart=e,t.selectionEnd=Math.min(n,t.value.length);else if(n=(e=t.ownerDocument||document)&&e.defaultView||window,n.getSelection){n=n.getSelection();var i=t.textContent.length,o=Math.min(r.start,i);r=r.end===void 0?o:Math.min(r.end,i),!n.extend&&o>r&&(i=r,r=o,o=i),i=dp(t,o);var s=dp(t,r);i&&s&&(n.rangeCount!==1||n.anchorNode!==i.node||n.anchorOffset!==i.offset||n.focusNode!==s.node||n.focusOffset!==s.offset)&&(e=e.createRange(),e.setStart(i.node,i.offset),n.removeAllRanges(),o>r?(n.addRange(e),n.extend(s.node,s.offset)):(e.setEnd(s.node,s.offset),n.addRange(e)))}}for(e=[],n=t;n=n.parentNode;)n.nodeType===1&&e.push({element:n,left:n.scrollLeft,top:n.scrollTop});for(typeof t.focus=="function"&&t.focus(),t=0;t=document.documentMode,Rr=null,wc=null,uo=null,kc=!1;function hp(n,e,t){var r=t.window===t?t.document:t.nodeType===9?t:t.ownerDocument;kc||Rr==null||Rr!==Ml(r)||(r=Rr,"selectionStart"in r&&_f(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),uo&&Io(uo,r)||(uo=r,r=bl(wc,"onSelect"),0Ir||(n.current=Ec[Ir],Ec[Ir]=null,Ir--)}function H(n,e){Ir++,Ec[Ir]=n.current,n.current=e}var Rn={},Oe=zn(Rn),Ue=zn(!1),lr=Rn;function oi(n,e){var t=n.type.contextTypes;if(!t)return Rn;var r=n.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===e)return r.__reactInternalMemoizedMaskedChildContext;var i={},o;for(o in t)i[o]=e[o];return r&&(n=n.stateNode,n.__reactInternalMemoizedUnmaskedChildContext=e,n.__reactInternalMemoizedMaskedChildContext=i),i}function He(n){return n=n.childContextTypes,n!=null}function zl(){q(Ue),q(Oe)}function kp(n,e,t){if(Oe.current!==Rn)throw Error(E(168));H(Oe,e),H(Ue,t)}function R0(n,e,t){var r=n.stateNode;if(e=e.childContextTypes,typeof r.getChildContext!="function")return t;r=r.getChildContext();for(var i in r)if(!(i in e))throw Error(E(108,NC(n)||"Unknown",i));return X({},t,r)}function Pl(n){return n=(n=n.stateNode)&&n.__reactInternalMemoizedMergedChildContext||Rn,lr=Oe.current,H(Oe,n),H(Ue,Ue.current),!0}function vp(n,e,t){var r=n.stateNode;if(!r)throw Error(E(169));t?(n=R0(n,e,lr),r.__reactInternalMemoizedMergedChildContext=n,q(Ue),q(Oe),H(Oe,n)):q(Ue),H(Ue,t)}var Ht=null,la=!1,au=!1;function A0(n){Ht===null?Ht=[n]:Ht.push(n)}function JN(n){la=!0,A0(n)}function Pn(){if(!au&&Ht!==null){au=!0;var n=0,e=U;try{var t=Ht;for(U=1;n>=s,i-=s,jt=1<<32-vt(e)+i|t<D?(b=O,O=null):b=O.sibling;var z=d(g,O,S[D],x);if(z===null){O===null&&(O=b);break}n&&O&&z.alternate===null&&e(g,O),y=o(z,y,D),M===null?N=z:M.sibling=z,M=z,O=b}if(D===S.length)return t(g,O),Q&&Hn(g,D),N;if(O===null){for(;DD?(b=O,O=null):b=O.sibling;var ae=d(g,O,z.value,x);if(ae===null){O===null&&(O=b);break}n&&O&&ae.alternate===null&&e(g,O),y=o(ae,y,D),M===null?N=ae:M.sibling=ae,M=ae,O=b}if(z.done)return t(g,O),Q&&Hn(g,D),N;if(O===null){for(;!z.done;D++,z=S.next())z=f(g,z.value,x),z!==null&&(y=o(z,y,D),M===null?N=z:M.sibling=z,M=z);return Q&&Hn(g,D),N}for(O=r(g,O);!z.done;D++,z=S.next())z=p(O,g,D,z.value,x),z!==null&&(n&&z.alternate!==null&&O.delete(z.key===null?D:z.key),y=o(z,y,D),M===null?N=z:M.sibling=z,M=z);return n&&O.forEach(function(Vt){return e(g,Vt)}),Q&&Hn(g,D),N}function w(g,y,S,x){if(typeof S=="object"&&S!==null&&S.type===Dr&&S.key===null&&(S=S.props.children),typeof S=="object"&&S!==null){switch(S.$$typeof){case Ss:e:{for(var N=S.key,M=y;M!==null;){if(M.key===N){if(N=S.type,N===Dr){if(M.tag===7){t(g,M.sibling),y=i(M,S.props.children),y.return=g,g=y;break e}}else if(M.elementType===N||typeof N=="object"&&N!==null&&N.$$typeof===on&&Dp(N)===M.type){t(g,M.sibling),y=i(M,S.props),y.ref=Ni(g,M,S),y.return=g,g=y;break e}t(g,M);break}else e(g,M);M=M.sibling}S.type===Dr?(y=ir(S.props.children,g.mode,x,S.key),y.return=g,g=y):(x=dl(S.type,S.key,S.props,null,g.mode,x),x.ref=Ni(g,y,S),x.return=g,g=x)}return s(g);case Or:e:{for(M=S.key;y!==null;){if(y.key===M)if(y.tag===4&&y.stateNode.containerInfo===S.containerInfo&&y.stateNode.implementation===S.implementation){t(g,y.sibling),y=i(y,S.children||[]),y.return=g,g=y;break e}else{t(g,y);break}else e(g,y);y=y.sibling}y=gu(S,g.mode,x),y.return=g,g=y}return s(g);case on:return M=S._init,w(g,y,M(S._payload),x)}if(Gi(S))return h(g,y,S,x);if(wi(S))return m(g,y,S,x);Ts(g,S)}return typeof S=="string"&&S!==""||typeof S=="number"?(S=""+S,y!==null&&y.tag===6?(t(g,y.sibling),y=i(y,S),y.return=g,g=y):(t(g,y),y=mu(S,g.mode,x),y.return=g,g=y),s(g)):t(g,y)}return w}var li=V0(!0),B0=V0(!1),is={},bt=zn(is),Lo=zn(is),$o=zn(is);function Xn(n){if(n===is)throw Error(E(174));return n}function Gf(n,e){switch(H($o,e),H(Lo,n),H(bt,is),n=e.nodeType,n){case 9:case 11:e=(e=e.documentElement)?e.namespaceURI:uc(null,"");break;default:n=n===8?e.parentNode:e,e=n.namespaceURI||null,n=n.tagName,e=uc(e,n)}q(bt),H(bt,e)}function ai(){q(bt),q(Lo),q($o)}function J0(n){Xn($o.current);var e=Xn(bt.current),t=uc(e,n.type);e!==t&&(H(Lo,n),H(bt,t))}function Xf(n){Lo.current===n&&(q(bt),q(Lo))}var Y=zn(0);function Jl(n){for(var e=n;e!==null;){if(e.tag===13){var t=e.memoizedState;if(t!==null&&(t=t.dehydrated,t===null||t.data==="$?"||t.data==="$!"))return e}else if(e.tag===19&&e.memoizedProps.revealOrder!==void 0){if(e.flags&128)return e}else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===n)break;for(;e.sibling===null;){if(e.return===null||e.return===n)return null;e=e.return}e.sibling.return=e.return,e=e.sibling}return null}var uu=[];function Zf(){for(var n=0;nt?t:4,n(!0);var r=cu.transition;cu.transition={};try{n(!1),e()}finally{U=t,cu.transition=r}}function r1(){return pt().memoizedState}function HN(n,e,t){var r=En(n);if(t={lane:r,action:t,hasEagerState:!1,eagerState:null,next:null},i1(n))o1(e,t);else if(t=P0(n,e,t,r),t!==null){var i=Ae();xt(t,n,r,i),s1(t,e,r)}}function jN(n,e,t){var r=En(n),i={lane:r,action:t,hasEagerState:!1,eagerState:null,next:null};if(i1(n))o1(e,i);else{var o=n.alternate;if(n.lanes===0&&(o===null||o.lanes===0)&&(o=e.lastRenderedReducer,o!==null))try{var s=e.lastRenderedState,l=o(s,t);if(i.hasEagerState=!0,i.eagerState=l,Nt(l,s)){var a=e.interleaved;a===null?(i.next=i,Qf(e)):(i.next=a.next,a.next=i),e.interleaved=i;return}}catch{}finally{}t=P0(n,e,i,r),t!==null&&(i=Ae(),xt(t,n,r,i),s1(t,e,r))}}function i1(n){var e=n.alternate;return n===G||e!==null&&e===G}function o1(n,e){co=_l=!0;var t=n.pending;t===null?e.next=e:(e.next=t.next,t.next=e),n.pending=e}function s1(n,e,t){if(t&4194240){var r=e.lanes;r&=n.pendingLanes,t|=r,e.lanes=t,Pf(n,t)}}var Wl={readContext:ht,useCallback:ve,useContext:ve,useEffect:ve,useImperativeHandle:ve,useInsertionEffect:ve,useLayoutEffect:ve,useMemo:ve,useReducer:ve,useRef:ve,useState:ve,useDebugValue:ve,useDeferredValue:ve,useTransition:ve,useMutableSource:ve,useSyncExternalStore:ve,useId:ve,unstable_isNewReconciler:!1},KN={readContext:ht,useCallback:function(n,e){return Et().memoizedState=[n,e===void 0?null:e],n},useContext:ht,useEffect:Rp,useImperativeHandle:function(n,e,t){return t=t!=null?t.concat([n]):null,al(4194308,4,X0.bind(null,e,n),t)},useLayoutEffect:function(n,e){return al(4194308,4,n,e)},useInsertionEffect:function(n,e){return al(4,2,n,e)},useMemo:function(n,e){var t=Et();return e=e===void 0?null:e,n=n(),t.memoizedState=[n,e],n},useReducer:function(n,e,t){var r=Et();return e=t!==void 0?t(e):e,r.memoizedState=r.baseState=e,n={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:n,lastRenderedState:e},r.queue=n,n=n.dispatch=HN.bind(null,G,n),[r.memoizedState,n]},useRef:function(n){var e=Et();return n={current:n},e.memoizedState=n},useState:Tp,useDebugValue:id,useDeferredValue:function(n){return Et().memoizedState=n},useTransition:function(){var n=Tp(!1),e=n[0];return n=UN.bind(null,n[1]),Et().memoizedState=n,[e,n]},useMutableSource:function(){},useSyncExternalStore:function(n,e,t){var r=G,i=Et();if(Q){if(t===void 0)throw Error(E(407));t=t()}else{if(t=e(),de===null)throw Error(E(349));ur&30||U0(r,e,t)}i.memoizedState=t;var o={value:t,getSnapshot:e};return i.queue=o,Rp(j0.bind(null,r,o,n),[n]),r.flags|=2048,Jo(9,H0.bind(null,r,o,t,e),void 0,null),t},useId:function(){var n=Et(),e=de.identifierPrefix;if(Q){var t=Kt,r=jt;t=(r&~(1<<32-vt(r)-1)).toString(32)+t,e=":"+e+"R"+t,t=Vo++,0<\/script>",n=n.removeChild(n.firstChild)):typeof r.is=="string"?n=s.createElement(t,{is:r.is}):(n=s.createElement(t),t==="select"&&(s=n,r.multiple?s.multiple=!0:r.size&&(s.size=r.size))):n=s.createElementNS(n,t),n[Ot]=e,n[Fo]=r,m1(n,e,!1,!1),e.stateNode=n;e:{switch(s=fc(t,r),t){case"dialog":K("cancel",n),K("close",n),i=r;break;case"iframe":case"object":case"embed":K("load",n),i=r;break;case"video":case"audio":for(i=0;ici&&(e.flags|=128,r=!0,Mi(o,!1),e.lanes=4194304)}else{if(!r)if(n=Jl(s),n!==null){if(e.flags|=128,r=!0,t=n.updateQueue,t!==null&&(e.updateQueue=t,e.flags|=4),Mi(o,!0),o.tail===null&&o.tailMode==="hidden"&&!s.alternate&&!Q)return xe(e),null}else 2*ne()-o.renderingStartTime>ci&&t!==1073741824&&(e.flags|=128,r=!0,Mi(o,!1),e.lanes=4194304);o.isBackwards?(s.sibling=e.child,e.child=s):(t=o.last,t!==null?t.sibling=s:e.child=s,o.last=s)}return o.tail!==null?(e=o.tail,o.rendering=e,o.tail=e.sibling,o.renderingStartTime=ne(),e.sibling=null,t=Y.current,H(Y,r?t&1|2:t&1),e):(xe(e),null);case 22:case 23:return cd(),r=e.memoizedState!==null,n!==null&&n.memoizedState!==null!==r&&(e.flags|=8192),r&&e.mode&1?Ge&1073741824&&(xe(e),e.subtreeFlags&6&&(e.flags|=8192)):xe(e),null;case 24:return null;case 25:return null}throw Error(E(156,e.tag))}function tM(n,e){switch(Uf(e),e.tag){case 1:return He(e.type)&&zl(),n=e.flags,n&65536?(e.flags=n&-65537|128,e):null;case 3:return ai(),q(Ue),q(Oe),Zf(),n=e.flags,n&65536&&!(n&128)?(e.flags=n&-65537|128,e):null;case 5:return Xf(e),null;case 13:if(q(Y),n=e.memoizedState,n!==null&&n.dehydrated!==null){if(e.alternate===null)throw Error(E(340));si()}return n=e.flags,n&65536?(e.flags=n&-65537|128,e):null;case 19:return q(Y),null;case 4:return ai(),null;case 10:return qf(e.type._context),null;case 22:case 23:return cd(),null;case 24:return null;default:return null}}var As=!1,Ne=!1,nM=typeof WeakSet=="function"?WeakSet:Set,R=null;function Lr(n,e){var t=n.ref;if(t!==null)if(typeof t=="function")try{t(null)}catch(r){Z(n,e,r)}else t.current=null}function $c(n,e,t){try{t()}catch(r){Z(n,e,r)}}var Vp=!1;function rM(n,e){if(vc=Rl,n=v0(),_f(n)){if("selectionStart"in n)var t={start:n.selectionStart,end:n.selectionEnd};else e:{t=(t=n.ownerDocument)&&t.defaultView||window;var r=t.getSelection&&t.getSelection();if(r&&r.rangeCount!==0){t=r.anchorNode;var i=r.anchorOffset,o=r.focusNode;r=r.focusOffset;try{t.nodeType,o.nodeType}catch{t=null;break e}var s=0,l=-1,a=-1,u=0,c=0,f=n,d=null;t:for(;;){for(var p;f!==t||i!==0&&f.nodeType!==3||(l=s+i),f!==o||r!==0&&f.nodeType!==3||(a=s+r),f.nodeType===3&&(s+=f.nodeValue.length),(p=f.firstChild)!==null;)d=f,f=p;for(;;){if(f===n)break t;if(d===t&&++u===i&&(l=s),d===o&&++c===r&&(a=s),(p=f.nextSibling)!==null)break;f=d,d=f.parentNode}f=p}t=l===-1||a===-1?null:{start:l,end:a}}else t=null}t=t||{start:0,end:0}}else t=null;for(xc={focusedElem:n,selectionRange:t},Rl=!1,R=e;R!==null;)if(e=R,n=e.child,(e.subtreeFlags&1028)!==0&&n!==null)n.return=e,R=n;else for(;R!==null;){e=R;try{var h=e.alternate;if(e.flags&1024)switch(e.tag){case 0:case 11:case 15:break;case 1:if(h!==null){var m=h.memoizedProps,w=h.memoizedState,g=e.stateNode,y=g.getSnapshotBeforeUpdate(e.elementType===e.type?m:yt(e.type,m),w);g.__reactInternalSnapshotBeforeUpdate=y}break;case 3:var S=e.stateNode.containerInfo;S.nodeType===1?S.textContent="":S.nodeType===9&&S.documentElement&&S.removeChild(S.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(E(163))}}catch(x){Z(e,e.return,x)}if(n=e.sibling,n!==null){n.return=e.return,R=n;break}R=e.return}return h=Vp,Vp=!1,h}function fo(n,e,t){var r=e.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var i=r=r.next;do{if((i.tag&n)===n){var o=i.destroy;i.destroy=void 0,o!==void 0&&$c(e,t,o)}i=i.next}while(i!==r)}}function ca(n,e){if(e=e.updateQueue,e=e!==null?e.lastEffect:null,e!==null){var t=e=e.next;do{if((t.tag&n)===n){var r=t.create;t.destroy=r()}t=t.next}while(t!==e)}}function Vc(n){var e=n.ref;if(e!==null){var t=n.stateNode;switch(n.tag){case 5:n=t;break;default:n=t}typeof e=="function"?e(n):e.current=n}}function S1(n){var e=n.alternate;e!==null&&(n.alternate=null,S1(e)),n.child=null,n.deletions=null,n.sibling=null,n.tag===5&&(e=n.stateNode,e!==null&&(delete e[Ot],delete e[Fo],delete e[Mc],delete e[VN],delete e[BN])),n.stateNode=null,n.return=null,n.dependencies=null,n.memoizedProps=null,n.memoizedState=null,n.pendingProps=null,n.stateNode=null,n.updateQueue=null}function w1(n){return n.tag===5||n.tag===3||n.tag===4}function Bp(n){e:for(;;){for(;n.sibling===null;){if(n.return===null||w1(n.return))return null;n=n.return}for(n.sibling.return=n.return,n=n.sibling;n.tag!==5&&n.tag!==6&&n.tag!==18;){if(n.flags&2||n.child===null||n.tag===4)continue e;n.child.return=n,n=n.child}if(!(n.flags&2))return n.stateNode}}function Bc(n,e,t){var r=n.tag;if(r===5||r===6)n=n.stateNode,e?t.nodeType===8?t.parentNode.insertBefore(n,e):t.insertBefore(n,e):(t.nodeType===8?(e=t.parentNode,e.insertBefore(n,t)):(e=t,e.appendChild(n)),t=t._reactRootContainer,t!=null||e.onclick!==null||(e.onclick=Il));else if(r!==4&&(n=n.child,n!==null))for(Bc(n,e,t),n=n.sibling;n!==null;)Bc(n,e,t),n=n.sibling}function Jc(n,e,t){var r=n.tag;if(r===5||r===6)n=n.stateNode,e?t.insertBefore(n,e):t.appendChild(n);else if(r!==4&&(n=n.child,n!==null))for(Jc(n,e,t),n=n.sibling;n!==null;)Jc(n,e,t),n=n.sibling}var me=null,St=!1;function tn(n,e,t){for(t=t.child;t!==null;)k1(n,e,t),t=t.sibling}function k1(n,e,t){if(At&&typeof At.onCommitFiberUnmount=="function")try{At.onCommitFiberUnmount(na,t)}catch{}switch(t.tag){case 5:Ne||Lr(t,e);case 6:var r=me,i=St;me=null,tn(n,e,t),me=r,St=i,me!==null&&(St?(n=me,t=t.stateNode,n.nodeType===8?n.parentNode.removeChild(t):n.removeChild(t)):me.removeChild(t.stateNode));break;case 18:me!==null&&(St?(n=me,t=t.stateNode,n.nodeType===8?lu(n.parentNode,t):n.nodeType===1&&lu(n,t),Ao(n)):lu(me,t.stateNode));break;case 4:r=me,i=St,me=t.stateNode.containerInfo,St=!0,tn(n,e,t),me=r,St=i;break;case 0:case 11:case 14:case 15:if(!Ne&&(r=t.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){i=r=r.next;do{var o=i,s=o.destroy;o=o.tag,s!==void 0&&(o&2||o&4)&&$c(t,e,s),i=i.next}while(i!==r)}tn(n,e,t);break;case 1:if(!Ne&&(Lr(t,e),r=t.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=t.memoizedProps,r.state=t.memoizedState,r.componentWillUnmount()}catch(l){Z(t,e,l)}tn(n,e,t);break;case 21:tn(n,e,t);break;case 22:t.mode&1?(Ne=(r=Ne)||t.memoizedState!==null,tn(n,e,t),Ne=r):tn(n,e,t);break;default:tn(n,e,t)}}function Jp(n){var e=n.updateQueue;if(e!==null){n.updateQueue=null;var t=n.stateNode;t===null&&(t=n.stateNode=new nM),e.forEach(function(r){var i=dM.bind(null,n,r);t.has(r)||(t.add(r),r.then(i,i))})}}function gt(n,e){var t=e.deletions;if(t!==null)for(var r=0;ri&&(i=s),r&=~o}if(r=i,r=ne()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*oM(r/1960))-r,10n?16:n,yn===null)var r=!1;else{if(n=yn,yn=null,jl=0,B&6)throw Error(E(331));var i=B;for(B|=4,R=n.current;R!==null;){var o=R,s=o.child;if(R.flags&16){var l=o.deletions;if(l!==null){for(var a=0;ane()-ad?rr(n,0):ld|=t),je(n,e)}function D1(n,e){e===0&&(n.mode&1?(e=xs,xs<<=1,!(xs&130023424)&&(xs=4194304)):e=1);var t=Ae();n=Xt(n,e),n!==null&&(ts(n,e,t),je(n,t))}function fM(n){var e=n.memoizedState,t=0;e!==null&&(t=e.retryLane),D1(n,t)}function dM(n,e){var t=0;switch(n.tag){case 13:var r=n.stateNode,i=n.memoizedState;i!==null&&(t=i.retryLane);break;case 19:r=n.stateNode;break;default:throw Error(E(314))}r!==null&&r.delete(e),D1(n,t)}var T1;T1=function(n,e,t){if(n!==null)if(n.memoizedProps!==e.pendingProps||Ue.current)_e=!0;else{if(!(n.lanes&t)&&!(e.flags&128))return _e=!1,ZN(n,e,t);_e=!!(n.flags&131072)}else _e=!1,Q&&e.flags&1048576&&b0(e,Ll,e.index);switch(e.lanes=0,e.tag){case 2:var r=e.type;ul(n,e),n=e.pendingProps;var i=oi(e,Oe.current);jr(e,t),i=td(null,e,r,n,i,t);var o=nd();return e.flags|=1,typeof i=="object"&&i!==null&&typeof i.render=="function"&&i.$$typeof===void 0?(e.tag=1,e.memoizedState=null,e.updateQueue=null,He(r)?(o=!0,Pl(e)):o=!1,e.memoizedState=i.state!==null&&i.state!==void 0?i.state:null,Yf(e),i.updater=aa,e.stateNode=i,i._reactInternals=e,Ac(e,r,n,t),e=zc(null,e,r,!0,o,t)):(e.tag=0,Q&&o&&Wf(e),Te(null,e,i,t),e=e.child),e;case 16:r=e.elementType;e:{switch(ul(n,e),n=e.pendingProps,i=r._init,r=i(r._payload),e.type=r,i=e.tag=pM(r),n=yt(r,n),i){case 0:e=Ic(null,e,r,n,t);break e;case 1:e=Fp(null,e,r,n,t);break e;case 11:e=zp(null,e,r,n,t);break e;case 14:e=Pp(null,e,r,yt(r.type,n),t);break e}throw Error(E(306,r,""))}return e;case 0:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:yt(r,i),Ic(n,e,r,i,t);case 1:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:yt(r,i),Fp(n,e,r,i,t);case 3:e:{if(d1(e),n===null)throw Error(E(387));r=e.pendingProps,o=e.memoizedState,i=o.element,F0(n,e),Bl(e,r,null,t);var s=e.memoizedState;if(r=s.element,o.isDehydrated)if(o={element:r,isDehydrated:!1,cache:s.cache,pendingSuspenseBoundaries:s.pendingSuspenseBoundaries,transitions:s.transitions},e.updateQueue.baseState=o,e.memoizedState=o,e.flags&256){i=ui(Error(E(423)),e),e=Lp(n,e,r,t,i);break e}else if(r!==i){i=ui(Error(E(424)),e),e=Lp(n,e,r,t,i);break e}else for(Ze=Cn(e.stateNode.containerInfo.firstChild),tt=e,Q=!0,kt=null,t=B0(e,null,r,t),e.child=t;t;)t.flags=t.flags&-3|4096,t=t.sibling;else{if(si(),r===i){e=Zt(n,e,t);break e}Te(n,e,r,t)}e=e.child}return e;case 5:return J0(e),n===null&&Dc(e),r=e.type,i=e.pendingProps,o=n!==null?n.memoizedProps:null,s=i.children,Cc(r,i)?s=null:o!==null&&Cc(r,o)&&(e.flags|=32),f1(n,e),Te(n,e,s,t),e.child;case 6:return n===null&&Dc(e),null;case 13:return h1(n,e,t);case 4:return Gf(e,e.stateNode.containerInfo),r=e.pendingProps,n===null?e.child=li(e,null,r,t):Te(n,e,r,t),e.child;case 11:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:yt(r,i),zp(n,e,r,i,t);case 7:return Te(n,e,e.pendingProps,t),e.child;case 8:return Te(n,e,e.pendingProps.children,t),e.child;case 12:return Te(n,e,e.pendingProps.children,t),e.child;case 10:e:{if(r=e.type._context,i=e.pendingProps,o=e.memoizedProps,s=i.value,H($l,r._currentValue),r._currentValue=s,o!==null)if(Nt(o.value,s)){if(o.children===i.children&&!Ue.current){e=Zt(n,e,t);break e}}else for(o=e.child,o!==null&&(o.return=e);o!==null;){var l=o.dependencies;if(l!==null){s=o.child;for(var a=l.firstContext;a!==null;){if(a.context===r){if(o.tag===1){a=Qt(-1,t&-t),a.tag=2;var u=o.updateQueue;if(u!==null){u=u.shared;var c=u.pending;c===null?a.next=a:(a.next=c.next,c.next=a),u.pending=a}}o.lanes|=t,a=o.alternate,a!==null&&(a.lanes|=t),Tc(o.return,t,e),l.lanes|=t;break}a=a.next}}else if(o.tag===10)s=o.type===e.type?null:o.child;else if(o.tag===18){if(s=o.return,s===null)throw Error(E(341));s.lanes|=t,l=s.alternate,l!==null&&(l.lanes|=t),Tc(s,t,e),s=o.sibling}else s=o.child;if(s!==null)s.return=o;else for(s=o;s!==null;){if(s===e){s=null;break}if(o=s.sibling,o!==null){o.return=s.return,s=o;break}s=s.return}o=s}Te(n,e,i.children,t),e=e.child}return e;case 9:return i=e.type,r=e.pendingProps.children,jr(e,t),i=ht(i),r=r(i),e.flags|=1,Te(n,e,r,t),e.child;case 14:return r=e.type,i=yt(r,e.pendingProps),i=yt(r.type,i),Pp(n,e,r,i,t);case 15:return u1(n,e,e.type,e.pendingProps,t);case 17:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:yt(r,i),ul(n,e),e.tag=1,He(r)?(n=!0,Pl(e)):n=!1,jr(e,t),$0(e,r,i),Ac(e,r,i,t),zc(null,e,r,!0,n,t);case 19:return p1(n,e,t);case 22:return c1(n,e,t)}throw Error(E(156,e.tag))};function R1(n,e){return n0(n,e)}function hM(n,e,t,r){this.tag=n,this.key=t,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=e,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function ct(n,e,t,r){return new hM(n,e,t,r)}function dd(n){return n=n.prototype,!(!n||!n.isReactComponent)}function pM(n){if(typeof n=="function")return dd(n)?1:0;if(n!=null){if(n=n.$$typeof,n===Af)return 11;if(n===bf)return 14}return 2}function On(n,e){var t=n.alternate;return t===null?(t=ct(n.tag,e,n.key,n.mode),t.elementType=n.elementType,t.type=n.type,t.stateNode=n.stateNode,t.alternate=n,n.alternate=t):(t.pendingProps=e,t.type=n.type,t.flags=0,t.subtreeFlags=0,t.deletions=null),t.flags=n.flags&14680064,t.childLanes=n.childLanes,t.lanes=n.lanes,t.child=n.child,t.memoizedProps=n.memoizedProps,t.memoizedState=n.memoizedState,t.updateQueue=n.updateQueue,e=n.dependencies,t.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext},t.sibling=n.sibling,t.index=n.index,t.ref=n.ref,t}function dl(n,e,t,r,i,o){var s=2;if(r=n,typeof n=="function")dd(n)&&(s=1);else if(typeof n=="string")s=5;else e:switch(n){case Dr:return ir(t.children,i,o,e);case Rf:s=8,i|=8;break;case tc:return n=ct(12,t,e,i|2),n.elementType=tc,n.lanes=o,n;case nc:return n=ct(13,t,e,i),n.elementType=nc,n.lanes=o,n;case rc:return n=ct(19,t,e,i),n.elementType=rc,n.lanes=o,n;case Vy:return da(t,i,o,e);default:if(typeof n=="object"&&n!==null)switch(n.$$typeof){case Ly:s=10;break e;case $y:s=9;break e;case Af:s=11;break e;case bf:s=14;break e;case on:s=16,r=null;break e}throw Error(E(130,n==null?n:typeof n,""))}return e=ct(s,t,e,i),e.elementType=n,e.type=r,e.lanes=o,e}function ir(n,e,t,r){return n=ct(7,n,r,e),n.lanes=t,n}function da(n,e,t,r){return n=ct(22,n,r,e),n.elementType=Vy,n.lanes=t,n.stateNode={isHidden:!1},n}function mu(n,e,t){return n=ct(6,n,null,e),n.lanes=t,n}function gu(n,e,t){return e=ct(4,n.children!==null?n.children:[],n.key,e),e.lanes=t,e.stateNode={containerInfo:n.containerInfo,pendingChildren:null,implementation:n.implementation},e}function mM(n,e,t,r,i){this.tag=e,this.containerInfo=n,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Ya(0),this.expirationTimes=Ya(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Ya(0),this.identifierPrefix=r,this.onRecoverableError=i,this.mutableSourceEagerHydrationData=null}function hd(n,e,t,r,i,o,s,l,a){return n=new mM(n,e,t,l,a),e===1?(e=1,o===!0&&(e|=8)):e=0,o=ct(3,null,null,e),n.current=o,o.stateNode=n,o.memoizedState={element:r,isDehydrated:t,cache:null,transitions:null,pendingSuspenseBoundaries:null},Yf(o),n}function gM(n,e,t){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(z1)}catch(n){console.error(n)}}z1(),by.exports=rt;var fi=by.exports,P1,Qp=fi;P1=Qp.createRoot,Qp.hydrateRoot;const yi=k.createContext(null),vM=k.createContext(null),F1=k.createContext(null),zs=new WeakMap;function xM(n){const e=Object.create(null);e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",i=>{if(typeof i=="function"&&(i=i(n.state)),i)for(const o in i)o=="class"?e.class+=" "+i[o]:o=="style"?e.style=(e.style?e.style+";":"")+i[o]:!e[o]&&o!="contenteditable"&&o!="nodeName"&&(e[o]=String(i[o]))}),e.translate||(e.translate="no");const t=[Se.node(0,n.state.doc.content.size,e)],r=zs.get(n);return!r||r[0].to!==n.state.doc.content.size||!r[0].type.eq(t[0].type)?(zs.set(n,t),t):r}const CM=[],NM={},jc=_.empty;class fn{constructor(e){this.members=e}map(e,t){const r=this.members.map(i=>i.map(e,t,NM));return fn.from(r)}forChild(e,t){if(t.isLeaf)return _.empty;let r=[];for(let i=0;it instanceof _)?e:e.reduce((t,r)=>t.concat(r instanceof _?r:r.members),[]))}}forEachSet(e){for(let t=0;t0;)e++;n.splice(e,0,t)}const yu=new WeakMap;function EM(n,e){const t=[];n.someProp("decorations",s=>{const l=s(n.state);l&&l!=jc&&t.push(l)}),e&&t.push(_.create(n.state.doc,[e]));const r=yu.get(n);if(!r){const s=fn.from(t);return yu.set(n,s),s}let i=0,o=!0;if(r.forEachSet(s=>{t[i++]!==s&&(o=!1)}),i!==t.length&&(o=!1),!o){const s=fn.from(t);return yu.set(n,s),s}return r}const yd=function(n){for(let e=0;;e++)if(n=n.previousSibling,!n)return e},Gp=function(n){const e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},OM=function(n,e,t,r){return t&&(Xp(n,e,t,r,-1)||Xp(n,e,t,r,1))},DM=/^(img|br|input|textarea|hr)$/i;function Xp(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:Ql(n))){const o=n.parentNode;if(!o||o.nodeType!=1||RM(n)||DM.test(n.nodeName)||n.contentEditable=="false")return!1;e=yd(n)+(i<0?0:1),n=o}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?Ql(n):0}else return!1}}function Ql(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function TM(n,e,t){for(let r=e==0,i=e==Ql(n);r||i;){if(n==t)return!0;const o=yd(n);if(n=n.parentNode,!n)return!1;r=r&&o==0,i=i&&o==Ql(n)}return!1}function RM(n){let e;for(let t=n;t&&!(e=t.pmViewDesc);t=t.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==n||e.contentDOM==n)}const $1=function(n){return n.focusNode&&OM(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)},V1=k.createContext(null);function AM(n,e){const t=k.useContext(V1);k.useLayoutEffect(()=>t(n),e)}function B1(n,e){const{view:t}=k.useContext(yi);AM(()=>{if(t)return n(t)},e&&[t,...e])}const bM=k.forwardRef(function({widget:e,getPos:t,...r},i){const[o,s]=k.useState(!0),l=k.useRef(null);return k.useImperativeHandle(i,()=>l.current,[]),B1(a=>{if(!a||!l.current)return;a.domObserver.disconnectSelection();const u=a.domSelection(),c=document.createRange(),f=l.current;f.nodeName=="IMG"&&f.parentNode?c.setEnd(f.parentNode,yd(f)+1):c.setEnd(f,0),c.collapse(!1),u.removeAllRanges(),u.addRange(c),s(!1),a.domObserver.connectSelection()},[]),o?A.jsx("img",{ref:l,className:"ProseMirror-separator","mark-placeholder":"true",alt:"",...r}):null});function IM(n,e){if(n==e)return!0;for(const t in n)if(n[t]!==e[t])return!1;for(const t in e)if(!(t in n))return!1;return!0}const zM={side:0};class Wo{constructor(e,t){this.Component=e,this.spec=t??zM,this.side=this.spec.side??0}map(e,t,r,i){const{pos:o,deleted:s}=e.mapResult(t.from+i,this.side<0?-1:1);return s?null:new Se(o-r,o-r,this)}valid(){return!0}eq(e){return this==e||e instanceof Wo&&(this.spec.key&&this.spec.key==e.spec.key||this.Component==e.Component&&IM(this.spec,e.spec))}destroy(){}}function J1(n,e,t){return new Se(n,n,new Wo(e,t))}function Su(){return Math.floor(Math.random()*0xffffffffffff).toString(16)}const Uo=new Yo("@nytimes/react-prosemirror/reactKeys");function PM(){let n=!1;return new $t({key:Uo,state:{init(e,t){const r={posToKey:new Map,keyToPos:new Map};return t.doc.descendants((i,o)=>{const s=Su();return r.posToKey.set(o,s),r.keyToPos.set(s,o),!0}),r},apply(e,t,r,i){if(!e.docChanged||n)return t;const o=e.getMeta(Uo),s=(o==null?void 0:o.type)==="bustKey"&&o.payload.key,l={posToKey:new Map,keyToPos:new Map},a=Array.from(t.posToKey.entries()).sort(([u],[c])=>u-c);for(const[u,c]of a){const{pos:f,deleted:d}=e.mapping.mapResult(u);if(d)continue;let p=c;s===c&&(p=Su()),l.posToKey.set(f,p),l.keyToPos.set(p,f)}return i.doc.descendants((u,c)=>{if(l.posToKey.has(c))return!0;const f=Su();return l.posToKey.set(c,f),l.keyToPos.set(f,c),!0}),l}},props:{handleDOMEvents:{compositionstart:()=>{n=!0},compositionend:()=>{n=!1}}}})}function wu(n,e,t={}){var s;if(e===null)return!1;const r=t.from??n.state.selection.from,i=t.to??n.state.selection.to;if(n.someProp("handleTextInput",l=>l(n,r,i,e)))return!0;const{tr:o}=n.state;if(t.marks&&o.ensureMarks(t.marks),o.insertText(e,r,i),t.bust){const l=n.state.doc.resolve(r),a=l.sharedDepth(i),u=l.start(a),c=(s=Uo.getState(n.state))==null?void 0:s.posToKey.get(u-1);o.setMeta(Uo,{type:"bustKey",payload:{key:c}})}return n.dispatch(o),!0}function FM(n){let e=null,t=null;return new $t({props:{handleDOMEvents:{compositionstart(r){var s;const{state:i}=r;r.dispatch(i.tr.deleteSelection());const o=i.selection.$from;return i.selection.empty&&(i.storedMarks||!o.textOffset&&o.parentOffset&&((s=o.nodeBefore)!=null&&s.marks.some(l=>l.type.spec.inclusive===!1)))&&n(J1(i.selection.from,bM,{key:"cursor-wrapper",marks:i.storedMarks??o.marks()})),t=i.storedMarks??o.marks(),r.input.composing=!0,!0},compositionupdate(){return!0},compositionend(r){if(r.input.composing=!1,e!==null)return wu(r,e,{bust:!0,marks:t}),e=null,t=null,n(null),!0},beforeinput(r,i){var o,s;switch(i.preventDefault(),i.inputType){case"insertCompositionText":{if(i.data===null)break;e=i.data;break}case"insertReplacementText":{const l=i.getTargetRanges();(s=(o=i.dataTransfer)==null?void 0:o.items[0])==null||s.getAsString(a=>{for(const u of l){const c=r.posAtDOM(u.startContainer,u.startOffset,1),f=r.posAtDOM(u.endContainer,u.endOffset,1);wu(r,a,{from:c,to:f})}});break}case"insertText":{wu(r,i.data);break}case"deleteWordBackward":case"deleteContentBackward":case"deleteWordForward":case"deleteContentForward":case"deleteContent":{const l=i.getTargetRanges(),{tr:a}=r.state;for(const u of l){const c=r.posAtDOM(u.startContainer,u.startOffset),f=r.posAtDOM(u.endContainer,u.endOffset),{doc:d}=r.state,p=d.resolve(c).marksAcross(d.resolve(f));a.delete(c,f).setStoredMarks(p)}r.dispatch(a);break}}return!0}}}})}const Lt=typeof navigator<"u"?navigator:null,Zp=typeof document<"u"?document:null,Fn=Lt&&Lt.userAgent||"",Kc=/Edge\/(\d+)/.exec(Fn),_1=/MSIE \d/.exec(Fn),qc=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Fn),ya=!!(_1||qc||Kc),LM=_1?document.documentMode:qc?+qc[1]:Kc?+Kc[1]:0,W1=!ya&&/gecko\/(\d+)/i.test(Fn),$M=W1&&+(/Firefox\/(\d+)/.exec(Fn)||[0,0])[1],Qc=!ya&&/Chrome\/(\d+)/.exec(Fn),VM=!!Qc,BM=Qc?+Qc[1]:0,U1=!ya&&!!Lt&&/Apple Computer/.test(Lt.vendor),H1=U1&&(/Mobile\/\w+/.test(Fn)||!!Lt&&Lt.maxTouchPoints>2),JM=H1||(Lt?/Mac/.test(Lt.platform):!1),_M=Lt?/Win/.test(Lt.platform):!1,WM=/Android \d/.test(Fn),j1=!!Zp&&"webkitFontSmoothing"in Zp.documentElement.style,UM=j1?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,Ee={ie:ya,ie_version:LM,gecko:W1,gecko_version:$M,chrome:VM,chrome_version:BM,safari:U1,ios:H1,mac:JM,windows:_M,android:WM,webkit:j1,webkit_version:UM};function ku(n){return n.editable&&!n.hasFocus()?!1:HM(n)}function HM(n){var t,r;const e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(((t=e.focusNode)==null?void 0:t.nodeType)==3?(r=e.focusNode)==null?void 0:r.parentNode:e.focusNode))}catch{return!1}}function jM(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||$.between(e,t,r)}function em(n,e=null){const t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode);const o=i&&i.size==0;let s=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(s<0)return null;let l=r.resolve(s),a,u;if($1(t)){for(a=s;i&&!i.node;)i=i.parent;const f=i.node;if(i&&f.isAtom&&I.isSelectable(f)&&i.parent&&!(f.isInline&&TM(t.focusNode,t.focusOffset,i.dom))){const d=i.posBefore;u=new I(s==d?l:r.resolve(d))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let f=s,d=s;for(let p=0;p{(r.anchorNode!=i||r.anchorOffset!=o)&&(t.removeEventListener("selectionchange",e.input.hideSelectionGuard),setTimeout(()=>{(!K1(e)||e.state.selection.visible)&&e.dom.classList.remove("ProseMirror-hideselection")},20))})}const sm=Ee.safari||Ee.chrome&&Ee.chrome_version<63;function Ps(n,e=!1){const t=n,r=t.state.selection;if(QM(t,r),!!K1(t)){if(!e&&t.input.mouseDown&&t.input.mouseDown.allowDefault&&Ee.chrome){const i=t.domSelectionRange(),o=t.domObserver.currentSelection;if(i.anchorNode&&o.anchorNode&&Yl(i.anchorNode,i.anchorOffset,o.anchorNode,o.anchorOffset)){t.input.mouseDown.delayedSelectionSync=!0,t.domObserver.setCurSelection();return}}if(t.domObserver.disconnectSelection(),t.cursorWrapper)GM(t);else{const{anchor:i,head:o}=r;let s,l;sm&&!(r instanceof $)&&(r.$from.parent.inlineContent||(s=im(t,r.from)),!r.empty&&!r.$from.parent.inlineContent&&(l=im(t,r.to))),t.docView.setSelection(i,o,t.root,e),sm&&(s&&om(s),l&&om(l)),r.visible?t.dom.classList.remove("ProseMirror-hideselection"):(t.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&XM(t))}t.domObserver.setCurSelection(),t.domObserver.connectSelection()}}class ZM{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 eE{constructor(e){this.view=e,this.flushingSoon=-1,this.currentSelection=new ZM,this.suppressingSelectionUpdates=!1,this.view=e,this.onSelectionChange=this.onSelectionChange.bind(this)}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}stop(){this.disconnectSelection()}start(){this.connectSelection()}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;const t=new Set;let r;for(let o=e.focusNode;o;o=Gp(o))t.add(o);for(let o=e.anchorNode;o;o=Gp(o))if(t.has(o)){r=o;break}const i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:(r==null?void 0:r.nodeType)==3?r==null?void 0:r.parentNode:r}))return this.setCurSelection(),!0}registerMutation(){}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}updateSelection(){const{view:e}=this,t=e.input.compositionPendingChanges||(e.composing?e.input.compositionID:0);e.input.compositionPendingChanges=0;const r=e.input.lastSelectionTime>Date.now()-50?e.input.lastSelectionOrigin:null,i=em(e,r);if(i&&!e.state.selection.eq(i)){const o=e.state.tr.setSelection(i);r=="pointer"?o.setMeta("pointer",!0):r=="key"&&o.scrollIntoView(),t&&o.setMeta("composition",t),e.dispatch(o)}}selectionToDOM(){const{view:e}=this;Ps(e);const t=e.domSelectionRange();this.currentSelection.set(t)}flush(){const{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;const t=e.domSelectionRange(),r=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(t)&&ku(e)&&!this.ignoreSelectionChange(t);let i=null;r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}onSelectionChange(){if(ku(this.view)&&!this.view.composing){if(this.suppressingSelectionUpdates)return Ps(this.view);if(Ee.ie&&Ee.ie_version<=11&&!this.view.state.selection.empty){const e=this.view.domSelectionRange();if(e.focusNode&&Yl(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}}function gr(n,e){return n instanceof jo?1:e instanceof jo?-1:n.getPos()-e.getPos()}const di=0,lm=1,Fs=2,Ho=3;class ss{constructor(e,t,r,i,o){this.parent=e,this.children=t,this.getPos=r,this.dom=i,this.contentDOM=o,this.dirty=di,i.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tln(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){const o=this.getDesc(i);let s;if(o&&(!t||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}getDesc(e){const t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){const o=this.getDesc(i);if(o)return o.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||s instanceof jo){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof Sd&&o.side>=0;r--);if(t<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&t&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,t):{node:this.contentDOM,offset:o?ln(o.dom)+1:0}}else{let o,s=!0;for(;o=r=c&&t<=u-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,c);e=s;for(let f=l;f>0;f--){const d=this.children[f-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=ln(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(u>t||l==this.children.length-1)){t=u;for(let c=l+1;ch&&st){const h=l;l=a,a=h}const p=document.createRange();p.setEnd(a.node,a.offset),p.setStart(l.node,l.offset),u.removeAllRanges(),u.addRange(p)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let r=0,i=0;i=r:er){const l=r+o.border,a=s-o.border;if(e>=l&&t<=a){this.dirty=e==r||t==s?Fs:lm,e==l&&t==a&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=Ho:o.markDirty(e-l,t-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?Fs:Ho}r=s}this.dirty=Fs}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){const r=e==1?Fs:lm;t.dirtythis.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){const r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>C.empty)}return e}matchesNode(e,t,r){return this.dirty==di&&e.eq(this.node)&&rE(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}update(e,t,r,i){return!0}get domAtom(){return this.node.isAtom}}class nE extends wd{constructor(e,t,r,i,o,s,l,a){super(e,t,r,i,o,s,l,null,a,()=>!1,()=>{},()=>{})}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,i){return!0}inParent(){const e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Ho)}get domAtom(){return!1}}class jo extends ss{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==di&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}function rE(n,e){if(n.length!=e.length)return!1;for(let t=0;t{u=!!a.call(this,s,l)}),u||l.defaultPrevented)return!0}return!1};e[r]=o}return new $t({key:new Yo("@nytimes/react-prosemirror/componentEventListeners"),props:{handleDOMEvents:e}})}function oE(){const[n,e]=k.useState(new Map),t=k.useCallback((o,s)=>{const l=n.get(o)??[];l.unshift(s),n.has(o)||(n.set(o,l),e(new Map(n)))},[n]),r=k.useCallback((o,s)=>{const l=n.get(o);l==null||l.splice(l.indexOf(s),1)},[n]),i=k.useMemo(()=>iE(n),[n]);return{registerEventListener:t,unregisterEventListener:r,componentEventListenersPlugin:i}}function q1(){const[,n]=k.useReducer(e=>e+1,0);return n}function sE(n){const e=Object.create(null);function t(r){for(const i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function lE(n,e){let t=0,r=0;for(const i in n){if(n[i]!=e[i])return!0;t++}for(const i in e)r++;return t!=r}function aE(n,e){for(const t of Object.keys(n))if(n[t]!==e[t])return!0;return!1}function am(n){return!n.someProp("editable",e=>e(n.state)===!1)}class uE extends Fv{constructor(e,t){super(e,{state:dn.create({schema:t.state.schema,plugins:t.state.plugins}),plugins:t.plugins}),this.shouldUpdatePluginViews=!1,this.shouldUpdatePluginViews=!0,this._props=t,this.oldProps={state:t.state},this.state=t.state,this.domObserver.stop(),this.domObserver=new eE(this),this.domObserver.start(),this.editable=am(this),this.docView.dom.replaceChildren(),this.docView=t.docView}get needsRedraw(){if(this.oldProps.state.plugins===this._props.state.plugins&&this._props.plugins===this.oldProps.plugins)return!1;const e=sE(this);return lE(this.nodeViews,e)}pureSetProps(e){this._props={...this._props,...e},this.state=this._props.state,this.editable=am(this)}runPendingEffects(){if(aE(this.props,this.oldProps)){const e=this.props;this._props=this.oldProps,this.state=this._props.state,this.update(e)}}update(e){super.update(e),this.oldProps=e}updatePluginViews(e){this.shouldUpdatePluginViews&&super.updatePluginViews(e)}destroy(){this.dom=document.createElement("div"),super.destroy()}}const cE=new zm({nodes:{doc:{content:"text*"},text:{inline:!0}}}),fE=dn.create({schema:cE});function dE(n,e){const[t,r]=k.useState(null),[i,o]=k.useState(null),s=q1(),l=e.defaultState??fE,[a,u]=k.useState(l),c=e.state??a,{componentEventListenersPlugin:f,registerEventListener:d,unregisterEventListener:p}=oE(),h=k.useCallback(N=>{fi.flushSync(()=>{o(N)})},[]),m=k.useMemo(()=>[...e.plugins??[],f,FM(h)],[e.plugins,f,h]),w=k.useCallback(function(M){fi.flushSync(()=>{e.state||u(O=>O.apply(M)),e.dispatchTransaction&&e.dispatchTransaction.call(this,M)})},[e.dispatchTransaction,e.state]),g=document.createElement("div"),y=k.useRef(new wd(void 0,[],()=>-1,c.doc,[],_.empty,g,null,g,()=>!1,()=>{},()=>{})),S={...e,state:c,plugins:m,dispatchTransaction:w,docView:y.current};return k.useLayoutEffect(()=>()=>{t==null||t.destroy()},[t]),k.useLayoutEffect(()=>{if(t&&t.dom!==n&&r(null),!!n&&!t){const N=new uE({mount:n},S);r(N),N.dom.addEventListener("compositionend",s);return}}),k.useLayoutEffect(()=>{if(t!=null&&t.needsRedraw){r(null);return}else t==null||t.domObserver.selectionToDOM(),t==null||t.runPendingEffects()}),t==null||t.pureSetProps(S),{editor:k.useMemo(()=>({view:t,registerEventListener:d,unregisterEventListener:p,cursorWrapper:i,docViewDescRef:y}),[t,d,p,i]),state:c}}function hE({children:n}){const e=k.useRef(new Set).current,t=k.useRef(new Set).current,r=k.useRef(!1),i=q1(),o=k.useRef(!0),s=k.useCallback(()=>{o.current||(i(),o.current=!0)},[i]),l=k.useCallback(a=>{let u;const c=()=>{u=a()};return e.add(c),s(),()=>{e.delete(c),u&&(r.current?(t.add(u),s()):u())}},[e,t,s]);return k.useLayoutEffect(()=>(o.current=!1,e.forEach(a=>a()),e.clear(),()=>{t.forEach(a=>a()),t.clear()})),k.useLayoutEffect(()=>(r.current=!0,()=>{r.current=!1}),[]),A.jsx(V1.Provider,{value:l,children:n})}const mt=k.createContext({parentRef:{current:void 0},siblingsRef:{current:[]}});function Q1(n,e,t,r,i,o,s,l){const{view:a}=k.useContext(yi),[u,c]=k.useState(!0),f=k.useRef(s),d=k.useRef(()=>!1),p=k.useCallback(x=>{d.current=x},[]),h=k.useRef(()=>{!r.current||!n||(r.current.nodeType==1&&r.current.classList.add("ProseMirror-selectednode"),(l!=null&&l.current||!n.type.spec.draggable)&&(((t==null?void 0:t.current)??r.current).draggable=!0))}),m=k.useRef(()=>{!r.current||!n||r.current.nodeType==1&&(r.current.classList.remove("ProseMirror-selectednode"),(l!=null&&l.current||!n.type.spec.draggable)&&((t==null?void 0:t.current)??r.current).removeAttribute("draggable"))}),w=k.useCallback((x,N)=>{h.current=x,m.current=N},[]),{siblingsRef:g,parentRef:y}=k.useContext(mt),S=k.useRef([]);return k.useLayoutEffect(()=>{const x=g.current;return()=>{if(f.current&&x.includes(f.current)){const N=x.indexOf(f.current);x.splice(N,1)}}},[g]),k.useLayoutEffect(()=>{var N;if(!n||!r.current)return;const x=S.current[0];f.current?(f.current.parent=y.current,f.current.children=S.current,f.current.node=n,f.current.getPos=e,f.current.outerDeco=o,f.current.innerDeco=i,f.current.dom=(t==null?void 0:t.current)??r.current,f.current.dom.pmViewDesc=f.current,f.current.contentDOM=(l==null?void 0:l.current)??f.current.contentDOM??(x==null?void 0:x.dom.parentElement)??null,f.current.nodeDOM=r.current):f.current=new wd(y.current,S.current,e,n,o,i,(t==null?void 0:t.current)??r.current,(x==null?void 0:x.dom.parentElement)??null,r.current,M=>!!d.current(M),()=>h.current(),()=>m.current()),c(f.current.contentDOM!==null),g.current.includes(f.current)||g.current.push(f.current),g.current.sort(gr);for(const M of S.current)if(M.parent=f.current,M instanceof Gl){const O=(N=f.current.contentDOM)==null?void 0:N.firstChild;if(!O)throw new Error("Started a composition but couldn't find the text node it belongs to.");let D=O;for(;D.firstChild;)D=D.firstChild;if(!D||!(D instanceof Text))throw new Error("Started a composition but couldn't find the text node it belongs to.");M.dom=O,M.textDOM=D,M.text=D.data,M.textDOM.pmViewDesc=M,a==null||a.input.compositionNodes.push(M)}return()=>{var M,O,D,b;((M=f.current)==null?void 0:M.children[0])instanceof Gl&&!(a!=null&&a.composing)&&((b=(O=f.current)==null?void 0:O.children[0].dom.parentNode)==null||b.removeChild((D=f.current)==null?void 0:D.children[0].dom))}}),{hasContentDOM:u,childDescriptors:S,nodeViewDescRef:f,setStopEvent:p,setSelectNode:w}}function pE(n,e){return n.type.side-e.type.side}function mE(n,e,t,r){const i=e.locals(n);let o=0;if(i.length==0){for(let u=0;uo;)l.push(i[s++]);let d=o+c.nodeSize;if(c.isText){let h=d;s!h.inline):l.slice();r(c,p,e.forChild(o,c),o,f),o=d}}function gE(){const{view:n}=k.useContext(yi);return n&&Uo.getState(n.state)}var Y1={exports:{}};/*! + Copyright (c) 2018 Jed Watson. + Licensed under the MIT License (MIT), see + http://jedwatson.github.io/classnames +*/(function(n){(function(){var e={}.hasOwnProperty;function t(){for(var r=[],i=0;i{var t;return((t=e[1])==null?void 0:t.toUpperCase())??""})}function kE(n){const e=new CSSStyleSheet;e.insertRule(`* { ${n} }`);const r=e.cssRules[0].style,i={};for(let o=0;o0&&(e.step=r);break}case"disabled":{e.disabled=r!=null;break}case"rows":{const i=parseInt(r,10);Number.isNaN(i)||(e.rows=r);break}default:{e[t]=r;break}}return e}const kd=k.memo(k.forwardRef(function({outputSpec:e,children:t,...r},i){if(typeof e=="string")return A.jsx(A.Fragment,{children:e});if(!Array.isArray(e))throw new Error("@nytimes/react-prosemirror only supports strings and arrays in toDOM");const s=e[0].replace(" ",":"),l=e[1];let a={ref:i,...r},u=1;l&&typeof l=="object"&&l.nodeType==null&&!Array.isArray(l)&&(u=2,a=G1(X1(l),a));const c=[];for(let f=u;fu)throw new RangeError("Content hole must be the only child of its parent node");return k.createElement(s,a,t)}c.push(A.jsx(kd,{outputSpec:d,children:t}))}return k.createElement(s,a,...c)})),Z1=k.memo(k.forwardRef(function({mark:e,getPos:t,children:r},i){const{siblingsRef:o,parentRef:s}=k.useContext(mt),l=k.useRef(void 0),a=k.useRef([]),u=k.useRef(null);k.useImperativeHandle(i,()=>u.current,[]);const c=k.useMemo(()=>{var d,p;return(p=(d=e.type.spec).toDOM)==null?void 0:p.call(d,e,!0)},[e]);if(!c)throw new Error(`Mark spec for ${e.type.name} is missing toDOM`);k.useLayoutEffect(()=>{const d=o.current;return()=>{if(l.current&&d.includes(l.current)){const p=d.indexOf(l.current);d.splice(p,1)}}},[o]),k.useLayoutEffect(()=>{if(!u.current)return;const d=a.current[0];l.current?(l.current.parent=s.current,l.current.dom=u.current,l.current.contentDOM=(d==null?void 0:d.dom.parentElement)??u.current,l.current.mark=e,l.current.getPos=()=>t.current()):l.current=new tE(s.current,a.current,()=>t.current(),e,u.current,(d==null?void 0:d.dom.parentElement)??u.current),o.current.includes(l.current)||o.current.push(l.current),o.current.sort(gr);for(const p of a.current)p.parent=l.current});const f=k.useMemo(()=>({parentRef:l,siblingsRef:a}),[a,l]);return A.jsx(kd,{ref:u,outputSpec:c,children:A.jsx(mt.Provider,{value:f,children:r})})}));function vE({widget:n,getPos:e}){const{siblingsRef:t,parentRef:r}=k.useContext(mt),i=k.useRef(null),o=k.useRef(null);return k.useLayoutEffect(()=>{const s=t.current;return()=>{if(i.current&&s.includes(i.current)){const l=s.indexOf(i.current);s.splice(l,1)}}},[t]),B1(s=>{if(!o.current)return;const l=n.type.toDOM;let a=typeof l=="function"?l(s,()=>e.current()):l;if(!n.type.spec.raw){if(a.nodeType!=1){const u=document.createElement("span");u.appendChild(a),a=u}a.contentEditable="false",a.classList.add("ProseMirror-widget")}o.current.firstElementChild!==a&&o.current.replaceChildren(a)}),k.useLayoutEffect(()=>{o.current&&(i.current?(i.current.parent=r.current,i.current.widget=n,i.current.getPos=()=>e.current(),i.current.dom=o.current):i.current=new Sd(r.current,()=>e.current(),n,o.current),t.current.includes(i.current)||t.current.push(i.current),t.current.sort(gr))}),A.jsx("span",{ref:o})}const xE=k.createContext(null),CE=k.createContext(null),eS=k.memo(function({outerDeco:e,getPos:t,node:r,innerDeco:i,...o}){const s=k.useRef(null),l=k.useRef(null),a=k.useRef(null),u=k.useRef(()=>t.current()).current,c=k.useRef(r),f=k.useRef(e),d=k.useRef(i),p=k.useRef(null),h=k.useRef(null),{nodeViews:m}=k.useContext(F1),{view:w}=k.useContext(yi);let g=null;const y=m[r.type.name],S=k.useMemo(()=>{var j,he;return(he=(j=r.type.spec).toDOM)==null?void 0:he.call(j,r)},[r]),x=w==null?void 0:w.someProp("nodeViews",j=>j==null?void 0:j[r.type.name]);k.useLayoutEffect(()=>{if(!h.current||!p.current)return;const{dom:j}=h.current;return l.current=p.current,p.current.appendChild(j),()=>{var he,$n;($n=(he=h.current)==null?void 0:he.destroy)==null||$n.call(he)}},[]),k.useLayoutEffect(()=>{if(!x||!h.current)return;const{destroy:j,update:he}=h.current;if(((he==null?void 0:he.call(h.current,r,e,i))??!0)||(j==null||j.call(h.current),!p.current))return;c.current=r,f.current=e,d.current=i,h.current=x(c.current,w,()=>t.current(),f.current,d.current);const{dom:T}=h.current;l.current=p.current,p.current.appendChild(T)},[x,w,i,r,e,t]);const{hasContentDOM:N,childDescriptors:M,setStopEvent:O,setSelectNode:D,nodeViewDescRef:b}=Q1(r,()=>t.current(),s,l,i,e,void 0,a),z={...o,...!N&&{contentEditable:!1}},ae=k.useMemo(()=>({node:r,getPos:u,decorations:e,innerDecorations:i}),[u,i,r,e]);if(y)g=A.jsx(y,{...z,ref:l,nodeProps:ae,children:A.jsx(mo,{getPos:t,node:r,innerDecorations:i})});else if(x){h.current||(h.current=x(c.current,w,()=>t.current(),f.current,d.current));const{contentDOM:j}=h.current;a.current=j??null,g=k.createElement(r.isInline?"span":"div",{ref:p,contentEditable:!!j,suppressContentEditableWarning:!0},j&&fi.createPortal(A.jsx(mo,{getPos:t,node:r,innerDecorations:i}),j))}else S&&(g=A.jsx(kd,{...z,ref:l,outputSpec:S,children:A.jsx(mo,{getPos:t,node:r,innerDecorations:i})}));if(!g)throw new Error(`Node spec for ${r.type.name} is missing toDOM`);const Vt=k.cloneElement(e.reduce(vd,g),e.some(j=>j.type.attrs.nodeName)?{ref:s}:void 0),Ln=r.marks.reduce((j,he)=>A.jsx(Z1,{getPos:t,mark:he,children:j}),Vt),ls=k.useMemo(()=>({parentRef:b,siblingsRef:M}),[M,b]);return A.jsx(xE.Provider,{value:D,children:A.jsx(CE.Provider,{value:O,children:A.jsx(mt.Provider,{value:ls,children:k.cloneElement(Ln,r.marks.length||e.some(j=>j.type.attrs.nodeName)?{ref:s}:void 0)})})})});function NE({getPos:n}){const{siblingsRef:e,parentRef:t}=k.useContext(mt),r=k.useRef(null),i=k.useRef(null),[o,s]=k.useState(!1);return k.useLayoutEffect(()=>{const l=e.current;return()=>{if(r.current&&l.includes(r.current)){const a=l.indexOf(r.current);l.splice(a,1)}}},[e]),k.useLayoutEffect(()=>{var a;const l=e.current[e.current.length-1];if((Ee.safari||Ee.chrome)&&((a=l==null?void 0:l.dom)==null?void 0:a.contentEditable)=="false"){s(!0);return}i.current&&(r.current?(r.current.parent=t.current,r.current.dom=i.current,r.current.getPos=()=>n.current()):r.current=new jo(t.current,[],()=>n.current(),i.current,null),e.current.includes(r.current)||e.current.push(r.current),e.current.sort(gr))}),o?A.jsx("img",{ref:i,className:"ProseMirror-separator"}):null}function ME(n,e){if(n===e)return!0;if(!n||!e)return!1;const t=Object.keys(n),r=Object.keys(e),i=t.length;if(r.length!==i)return!1;for(let o=0;oo.current(),document.createElement("div"),document.createTextNode(s.text??""),s.text??"");return}let a=l;for(;a.firstChild;)a=a.firstChild;!this.viewDescRef||this.viewDescRef instanceof Gl?this.viewDescRef=new nE(void 0,[],()=>o.current(),s,t,_.empty,l,a):(this.viewDescRef.parent=i.current,this.viewDescRef.children=[],this.viewDescRef.node=s,this.viewDescRef.getPos=()=>o.current(),this.viewDescRef.outerDeco=t,this.viewDescRef.innerDeco=_.empty,this.viewDescRef.dom=l,this.viewDescRef.dom.pmViewDesc=this.viewDescRef,this.viewDescRef.nodeDOM=a),r.current.includes(this.viewDescRef)||r.current.push(this.viewDescRef),r.current.sort(gr)}shouldComponentUpdate(e){return!ME(this.props,e)}componentDidMount(){this.updateEffect()}componentDidUpdate(){this.updateEffect()}componentWillUnmount(){const{siblingsRef:e}=this.props;if(this.viewDescRef&&e.current.includes(this.viewDescRef)){const t=e.current.indexOf(this.viewDescRef);e.current.splice(t,1)}}render(){const{view:e,getPos:t,node:r,decorations:i}=this.props;return e!=null&&e.composing&&e.state.selection.from>=t.current()&&e.state.selection.from<=t.current()+r.nodeSize?this.renderRef:(this.renderRef=i.reduce(vd,r.text),this.renderRef)}}function OE({getPos:n}){const{siblingsRef:e,parentRef:t}=k.useContext(mt),r=k.useRef(null),i=k.useRef(null);return k.useLayoutEffect(()=>{const o=e.current;return()=>{if(r.current&&o.includes(r.current)){const s=o.indexOf(r.current);o.splice(s,1)}}},[e]),k.useLayoutEffect(()=>{i.current&&(r.current?(r.current.parent=t.current,r.current.dom=i.current,r.current.getPos=()=>n.current()):r.current=new jo(t.current,[],()=>n.current(),i.current,null),e.current.includes(r.current)||e.current.push(r.current),e.current.sort(gr))}),A.jsx("br",{ref:i,className:"ProseMirror-trailingBreak"})}function DE({widget:n,getPos:e}){const{siblingsRef:t,parentRef:r}=k.useContext(mt),i=k.useRef(null),o=k.useRef(()=>e.current()).current,s=k.useRef(null);k.useLayoutEffect(()=>{const a=t.current;return()=>{if(i.current&&a.includes(i.current)){const u=a.indexOf(i.current);a.splice(u,1)}}},[t]),k.useLayoutEffect(()=>{s.current&&(i.current?(i.current.parent=r.current,i.current.widget=n,i.current.getPos=()=>e.current(),i.current.dom=s.current):i.current=new Sd(r.current,()=>e.current(),n,s.current),t.current.includes(i.current)||t.current.push(i.current),t.current.sort(gr))});const{Component:l}=n.type;return l&&A.jsx(l,{ref:s,widget:n,getPos:o,contentEditable:!1})}function vd(n,e){const{nodeName:t,...r}=e.type.attrs,i=X1(r);return t||typeof n=="string"?k.createElement(t??"span",i,n):k.cloneElement(n,G1(n.props,i))}function xu(n,e){var t,r,i;return n.type===e.type&&n.marks.every(o=>o.isInSet(e.marks))&&e.marks.every(o=>o.isInSet(n.marks))&&n.key===e.key&&(n.type==="node"?((t=n.outerDeco)==null?void 0:t.length)===((r=e.outerDeco)==null?void 0:r.length)&&((i=n.outerDeco)==null?void 0:i.every(o=>{var s;return(s=e.outerDeco)==null?void 0:s.some(l=>o.from===l.from&&o.to&&l.to&&o.type.eq(l.type))}))&&n.innerDeco.eq(e.innerDeco):!0)&&n.node===e.node&&n.widget===e.widget}const TE=k.memo(function({child:e,getInnerPos:t}){const{view:r}=k.useContext(yi),i=k.useRef(()=>t.current()+e.offset);return i.current=()=>t.current()+e.offset,e.type==="widget"?A.jsx(DE,{widget:e.widget,getPos:i},e.key):e.type==="native-widget"?A.jsx(vE,{widget:e.widget,getPos:i},e.key):e.node.isText?A.jsx(mt.Consumer,{children:({siblingsRef:o,parentRef:s})=>A.jsx(EE,{view:r,node:e.node,getPos:i,siblingsRef:o,parentRef:s,decorations:e.outerDeco})},e.key):A.jsx(eS,{node:e.node,getPos:i,outerDeco:e.outerDeco,innerDeco:e.innerDeco},e.key)}),RE=k.memo(function({childViews:e,getInnerPos:t}){const r=e[0],i=k.useRef(()=>t.current()+r.offset);i.current=()=>t.current()+r.offset;const o=r.marks[0];return o?A.jsx(Z1,{getPos:i,mark:o,children:A.jsx(xd,{getInnerPos:t,childViews:e.map(s=>({...s,marks:s.marks.slice(1)}))},r.key)},r.key):A.jsx(A.Fragment,{children:e.map(s=>A.jsx(TE,{child:s,getInnerPos:t},s.key))})}),xd=k.memo(function({getInnerPos:e,childViews:t}){const r=t.reduce((i,o)=>{var a;const s=i[i.length-1];if(!s)return[[o]];const l=s[s.length-1];return l?!o.marks.length&&!l.marks.length||o.marks.length&&l.marks.length&&((a=o.marks[0])!=null&&a.eq(l.marks[0]))?[...i.slice(0,i.length-1),[...s.slice(0,s.length),o]]:[...i,[o]]:[...i.slice(0,i.length),[o]]},[]);return A.jsx(A.Fragment,{children:r.map(i=>{const o=i[0];return o?A.jsx(RE,{childViews:i,getInnerPos:e},o.key):null})})});function Cu(n,e,t,r,i,o){const s=n+e,l=r==null?void 0:r.get(s);if(t==="widget"||t==="native-widget")return i.type.spec.key?i.type.spec.key:(console.warn(`Widget at position ${s} doesn't have a key specified. This may cause issues.`),`${l}-${o}`);if(l)return l;const a=n-1,u=r==null?void 0:r.get(a);return u?`${u}-${e}`:s}function AE(n,e){if(!e||e.widget.type.side>=0||!n||!n.node.isInline)return;const t=n.marks;e.marks=e.marks.reduce((r,i)=>i.addToSet(r),t)}function bE(n,e){if(!e.node.isInline)return;const t=e.marks;for(let r=n.length-1;r>=0;r--){const i=n[r];i.widget.type.side<0||(i.marks=i.marks.reduce((o,s)=>s.addToSet(o),t))}}const IE=k.memo(function({child:e,getInnerPos:t}){const r=k.useRef(()=>t.current()+e.offset);return r.current=()=>t.current()+e.offset,e.type==="node"?A.jsx(eS,{outerDeco:e.outerDeco,node:e.node,innerDeco:e.innerDeco,getPos:r},e.key):A.jsx(xd,{childViews:[e],getInnerPos:t},e.key)});function zE(n,e){return n.length?n.every(t=>t.type!=="node"||t.node.isInline)?[A.jsx(xd,{childViews:n,getInnerPos:e},n[0].key)]:n.map(t=>A.jsx(IE,{child:t,getInnerPos:e},t.key)):[]}const mo=k.memo(function({getPos:e,node:t,innerDecorations:r}){const i=gE(),o=k.useRef(()=>e.current()+1),s=k.useRef(new Map).current;if(!t)return null;const l=new Set;let a=[],u=null;mE(t,r,(p,h,m,w)=>{const g=p.type.spec.marks??[];let y;if(h){y=Cu(o.current(),m,"native-widget",i==null?void 0:i.posToKey,p,w);const x={type:"native-widget",widget:p,marks:g,offset:m,index:w,key:y},N=s.get(y);N&&xu(N,x)?N.offset=m:s.set(y,x),l.add(y)}else{y=Cu(o.current(),m,"widget",i==null?void 0:i.posToKey,p,w);const x={type:"widget",widget:p,marks:g,offset:m,index:w,key:y},N=s.get(y);N&&xu(N,x)?N.offset=m:s.set(y,x),l.add(y)}const S=s.get(y);a.push(S),AE(u,s.get(y))},(p,h,m,w)=>{const g=Cu(o.current(),w,"node",i==null?void 0:i.posToKey),y={type:"node",node:p,marks:p.marks,innerDeco:m,outerDeco:h,offset:w,key:g},S=s.get(g);S&&xu(S,y)?(S.offset=w,u=S):(s.set(g,y),u=y),l.add(g),bE(a,u),a=[]});for(const p of s.keys())l.has(p)||s.delete(p);const c=Array.from(s.values()).sort((p,h)=>p.offset-h.offset),f=zE(c,o),d=c[c.length-1];return(!d||d.type!=="node"||d.node.isInline&&!d.node.isText||/\n$/.test(d.node.text))&&f.push(A.jsx(NE,{getPos:o},"trailing-hack-img"),A.jsx(OE,{getPos:o},"trailing-hack-br")),A.jsx(A.Fragment,{children:f})}),Nu={current(){return-1}},PE=k.memo(k.forwardRef(function({className:e,node:t,innerDeco:r,outerDeco:i,as:o,viewDesc:s,...l},a){const u=k.useRef(null);k.useImperativeHandle(a,()=>u.current,[]);const{childDescriptors:c,nodeViewDescRef:f}=Q1(t,()=>Nu.current(),u,u,r,i,s),d=k.useMemo(()=>({parentRef:f,siblingsRef:c}),[c,f]),p={...l,ref:u,className:e,suppressContentEditableWarning:!0},h=o?k.cloneElement(o,p,A.jsx(mt.Provider,{value:d,children:A.jsx(mo,{getPos:Nu,node:t,innerDecorations:r})})):k.createElement("div",p,A.jsx(mt.Provider,{value:d,children:A.jsx(mo,{getPos:Nu,node:t,innerDecorations:r})}));if(!t)return h;const m=i.filter(g=>!g.inline);return m.length?m.reduce(vd,h):h})),tS=k.createContext(null);function FE({as:n,...e},t){const r=k.useRef([]),i=k.useRef(null),{setMount:o,...s}=k.useContext(tS),l=k.useRef(void 0);k.useImperativeHandle(t,()=>i.current,[]);const a=k.useMemo(()=>({parentRef:l,siblingsRef:r}),[r,l]);return A.jsx(mt.Provider,{value:a,children:A.jsx(PE,{ref:u=>{i.current=u,o(u)},...e,...s,as:n})})}const LE=k.forwardRef(FE),$E=[];function VE({className:n,children:e,nodeViews:t,customNodeViews:r,...i}){var p;const[o,s]=k.useState(null),{editor:l,state:a}=dE(o,{...i,nodeViews:r}),u=l.view?EM(l.view,l.cursorWrapper):_.empty,c=l.view?xM(l.view):$E,f=k.useMemo(()=>({nodeViews:t??{}}),[t]),d=k.useMemo(()=>{var h;return{className:n,setMount:s,node:(h=l.view)==null?void 0:h.state.doc,innerDeco:u,outerDeco:c,viewDesc:l.docViewDescRef.current}},[n,l.docViewDescRef,(p=l.view)==null?void 0:p.state.doc,u,c]);return A.jsx(yi.Provider,{value:l,children:A.jsx(vM.Provider,{value:a,children:A.jsx(F1.Provider,{value:f,children:A.jsx(tS.Provider,{value:d,children:e})})})})}function BE(n){return A.jsx(hE,{children:A.jsx(VE,{...n})})}const J=new zm({nodes:{doc:{content:"block+"},paragraph:{group:"block",content:"inline*",toDOM(){return["p",0]}},...Bx({cellContent:"inline*",cellAttributes:{},tableGroup:"block"}),footnote:{group:"inline",content:"text*",inline:!0,atom:!0,attrs:{number:{default:0}}},list:{group:"block",content:"list_item+",toDOM(){return["ul",0]}},list_item:{content:"paragraph+",toDOM(){return["li",0]}},image:{group:"block",toDOM(){return["div",["img",{src:"https://smoores.gitlab.io/storyteller/img/Storyteller_Logo.png",height:150,width:150}]]}},text:{group:"inline"}},marks:{em:{toDOM(){return["em",0]}},strong:{toDOM(){return["strong",0]}}}}),JE=dn.create({schema:J,doc:J.nodes.doc.create({},[J.nodes.paragraph.create({},[J.text("This ",[J.marks.em.create()]),J.text("is",[J.marks.em.create(),J.marks.strong.create()]),J.text(" the first paragraph")]),J.nodes.paragraph.create({},[J.text("This is the second paragraph"),J.nodes.footnote.create({number:1},J.text("Footnote"))]),J.nodes.paragraph.create(),J.nodes.image.create(),J.nodes.image.create(),J.nodes.paragraph.create({},J.text("This is the third paragraph 🫵")),J.nodes.table.create({},[J.nodes.table_row.create({},[J.nodes.table_header.create({},J.text("h1")),J.nodes.table_header.create({},J.text("h2"))]),J.nodes.table_row.create({},[J.nodes.table_cell.create({},J.text("c1")),J.nodes.table_cell.create({},J.text("c2"))])])]),plugins:[PM(),ix({rules:[ox(/^\s*([-+*])\s$/,J.nodes.list)]}),oC(),yC()]}),_E=k.forwardRef(function({children:e,nodeProps:t,...r},i){return A.jsx("p",{ref:i,...r,children:e})}),WE=k.forwardRef(function({children:e,nodeProps:t,...r},i){return A.jsx("ul",{ref:i,...r,children:e})}),UE=k.forwardRef(function({children:e,nodeProps:t,...r},i){return A.jsx("li",{ref:i,...r,children:e})}),HE=k.forwardRef(function({nodeProps:e,...t},r){return A.jsx("span",{ref:r,...t,suppressContentEditableWarning:!0,contentEditable:"false",children:A.jsx("button",{children:e.node.attrs.number})})}),jE=k.forwardRef(function({widget:e,getPos:t,...r},i){return A.jsx("span",{...r,ref:i,style:{display:"block",backgroundColor:"blue",width:"4px",height:"4px",position:"absolute",transform:"translateX(-2px)"},children:"Widget"})}),KE=new $t({view(n){const e=n.coordsAtPos(n.state.selection.from),t=document.createElement("div");return t.style.width="4px",t.style.height="4px",t.style.position="absolute",t.style.top=`${e.top-2}px`,t.style.left=`${e.left-2}px`,t.style.backgroundColor="blue",document.body.appendChild(t),{update(r){const i=r.coordsAtPos(r.state.selection.from);t.style.top=`${i.top-2}px`,t.style.left=`${i.left-2}px`},destroy(){document.body.removeChild(t)}}}});new $t({props:{decorations(n){return _.create(n.doc,[J1(n.selection.from,jE,{side:0,key:"widget-plugin-widget"})])}},view(n){const e=n.coordsAtPos(n.state.selection.from),t=document.createElement("div");return t.style.width="4px",t.style.height="4px",t.style.position="absolute",t.style.top=`${e.top-2}px`,t.style.left=`${e.left-2}px`,t.style.backgroundColor="blue",document.body.appendChild(t),{update(r){const i=r.coordsAtPos(r.state.selection.from);t.style.top=`${i.top-2}px`,t.style.left=`${i.left-2}px`},destroy(){document.body.removeChild(t)}}}});const qE=[ux({...Hw,"Mod-i":jd(J.marks.em),"Mod-b":jd(J.marks.strong)}),KE,Jv()],QE={paragraph:()=>{const n=document.createElement("p");return{dom:n,contentDOM:n}}};function YE(){const[n,e]=k.useState(JE),[t,r]=k.useState(!0),i=k.useMemo(()=>t?{paragraph:_E,list:WE,list_item:UE,footnote:HE}:void 0,[t]),o=k.useCallback(function(s){e(l=>l.apply(s))},[]);return A.jsxs("main",{children:[A.jsx("h1",{children:"React ProseMirror Demo"}),A.jsxs("button",{onClick:()=>{t?r(s=>!s):window.location.reload()},children:["Switch to"," ",t?"ProseMirror node views":"React node views (requires reload)"]}),A.jsx(BE,{className:"ProseMirror",state:n,dispatchTransaction:o,plugins:qE,nodeViews:i,customNodeViews:t?void 0:QE,children:A.jsx(LE,{})},`${t}`)]})}const GE=P1(document.getElementById("root"));GE.render(A.jsx(k.StrictMode,{children:A.jsx(YE,{})})); diff --git a/docs/index.html b/docs/index.html index 9d395534..20869618 100644 --- a/docs/index.html +++ b/docs/index.html @@ -5,7 +5,7 @@ React-ProseMirror Demo - + diff --git a/package.json b/package.json index 264f9bc8..b8d191b1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nytimes/react-prosemirror", - "version": "0.7.0-next.9", + "version": "0.7.0-next.10", "license": "Apache-2.0", "type": "module", "main": "dist/cjs/index.js", @@ -57,7 +57,9 @@ "@vitejs/plugin-react": "^4.3.1", "@wdio/browser-runner": "^9.0.9", "@wdio/cli": "^9.0.9", + "@wdio/dot-reporter": "^9.1.0", "@wdio/mocha-framework": "^9.0.8", + "@wdio/spec-reporter": "^9.1.0", "@wdio/types": "^9.0.8", "@yarnpkg/sdks": "^3.0.0-rc.38", "concurrently": "^7.6.0", diff --git a/src/components/ChildNodeViews.tsx b/src/components/ChildNodeViews.tsx index 411fb23d..4c78685a 100644 --- a/src/components/ChildNodeViews.tsx +++ b/src/components/ChildNodeViews.tsx @@ -1,17 +1,21 @@ import { Mark, Node } from "prosemirror-model"; import { Decoration, DecorationSource } from "prosemirror-view"; import React, { + MutableRefObject, ReactNode, cloneElement, createElement, + memo, useContext, + useRef, } from "react"; import { ChildDescriptorsContext } from "../contexts/ChildDescriptorsContext.js"; import { EditorContext } from "../contexts/EditorContext.js"; import { ReactWidgetDecoration } from "../decorations/ReactWidgetType.js"; +import { InternalDecorationSource } from "../decorations/internalTypes.js"; import { iterDeco } from "../decorations/iterDeco.js"; -import { useEditorState } from "../hooks/useEditorState.js"; +// import { useEditorState } from "../hooks/useEditorState.js"; import { useReactKeys } from "../hooks/useReactKeys.js"; import { htmlAttrsToReactProps, mergeReactProps } from "../props.js"; @@ -42,12 +46,37 @@ export function wrapInDeco(reactNode: JSX.Element | string, deco: Decoration) { return cloneElement(reactNode, mergeReactProps(reactNode.props, props)); } +function areChildrenEqual(a: Child, b: Child) { + return ( + a.type === b.type && + a.marks.every((mark) => mark.isInSet(b.marks)) && + b.marks.every((mark) => mark.isInSet(a.marks)) && + a.key === b.key && + (a.type === "node" + ? a.outerDeco?.length === (b as ChildNode).outerDeco?.length && + a.outerDeco?.every((prevDeco) => + (b as ChildNode).outerDeco?.some( + (nextDeco) => + prevDeco.from === nextDeco.from && + prevDeco.to && + nextDeco.to && + (prevDeco as any).type.eq((nextDeco as any).type) + ) + ) && + (a.innerDeco as InternalDecorationSource).eq((b as ChildNode).innerDeco) + : true) && + (a as ChildNode).node === (b as ChildNode).node && + (a as ChildWidget).widget === (b as ChildWidget).widget + ); +} + type ChildWidget = { type: "widget"; widget: ReactWidgetDecoration; marks: readonly Mark[]; offset: number; index: number; + key: string; }; type ChildNativeWidget = { @@ -56,6 +85,7 @@ type ChildNativeWidget = { marks: readonly Mark[]; offset: number; index: number; + key: string; }; type ChildNode = { @@ -65,25 +95,112 @@ type ChildNode = { innerDeco: DecorationSource; outerDeco: readonly Decoration[]; offset: number; -}; - -type ChildTrailingHack = { - type: "trailinghack"; - offset: 0; + key: string; }; type Child = ChildNode | ChildWidget | ChildNativeWidget; type SharedMarksProps = { - innerPos: number; + getInnerPos: MutableRefObject<() => number>; childViews: Child[]; }; -function InlineView({ innerPos, childViews }: SharedMarksProps) { +const ChildView = memo(function ChildView({ + child, + getInnerPos, +}: { + child: Child; + getInnerPos: MutableRefObject<() => number>; +}) { const { view } = useContext(EditorContext); - const editorState = useEditorState(); - const reactKeys = useReactKeys(); + const getChildPos = useRef(() => getInnerPos.current() + child.offset); + getChildPos.current = () => getInnerPos.current() + child.offset; + + return child.type === "widget" ? ( + + ) : child.type === "native-widget" ? ( + + ) : child.node.isText ? ( + + {({ siblingsRef, parentRef }) => ( + + )} + + ) : ( + + ); +}); + +const InlinePartition = memo(function InlinePartition({ + childViews, + getInnerPos, +}: { + childViews: [Child, ...Child[]]; + getInnerPos: MutableRefObject<() => number>; +}) { + const firstChild = childViews[0]; + const getFirstChildPos = useRef( + () => getInnerPos.current() + firstChild.offset + ); + getFirstChildPos.current = () => getInnerPos.current() + firstChild.offset; + + const firstMark = firstChild.marks[0]; + if (!firstMark) { + return ( + <> + {childViews.map((child) => { + return ( + + ); + })} + + ); + } + + return ( + + ({ + ...child, + marks: child.marks.slice(1), + }))} + /> + + ); +}); +const InlineView = memo(function InlineView({ + getInnerPos, + childViews, +}: SharedMarksProps) { + // const editorState = useEditorState(); const partitioned = childViews.reduce((acc, child) => { const lastPartition = acc[acc.length - 1]; if (!lastPartition) { @@ -115,160 +232,95 @@ function InlineView({ innerPos, childViews }: SharedMarksProps) { {partitioned.map((childViews) => { const firstChild = childViews[0]; if (!firstChild) return null; - - const firstMark = firstChild.marks[0]; - if (!firstMark) { - return childViews.map((child) => { - const childPos = innerPos + child.offset; - - const childElement = - child.type === "widget" ? ( - - ) : child.type === "native-widget" ? ( - - ) : child.node.isText ? ( - - {(siblingDescriptors) => ( - - )} - - ) : ( - - ); - - return cloneElement(childElement, { - key: createKey( - editorState.doc, - innerPos, - child, - reactKeys?.posToKey - ), - }); - }); - } - return ( - - ({ - ...child, - marks: child.marks.slice(1), - }))} - /> - + ); })} ); -} +}); function createKey( - doc: Node | undefined, innerPos: number, - child: Child | ChildTrailingHack, - posToKey: Map | undefined + offset: number, + type: Child["type"], + posToKey: Map | undefined, + widget?: ReactWidgetDecoration | Decoration, + index?: number ) { - const pos = innerPos + child.offset; + const pos = innerPos + offset; const key = posToKey?.get(pos); - if (child.type === "widget" || child.type === "native-widget") { + if (type === "widget" || type === "native-widget") { // eslint-disable-next-line @typescript-eslint/no-explicit-any - if ((child.widget as any).type.spec.key) + if ((widget as any).type.spec.key) // eslint-disable-next-line @typescript-eslint/no-explicit-any - return (child.widget as any).type.spec.key; + return (widget as any).type.spec.key; // eslint-disable-next-line no-console console.warn( - `Widget at position ${pos} doesn't have a key specified. This has negative performance implications.` + `Widget at position ${pos} doesn't have a key specified. This may cause issues.` ); - return `${key}-${child.index}`; + return `${key}-${index}`; } if (key) return key; - if (!doc) return pos; + // if (!doc) return pos; - const parentPos = doc.resolve(pos).start() - 1; + const parentPos = innerPos - 1; const parentKey = posToKey?.get(parentPos); - if (parentKey) return `${parentKey}-${child.offset}`; + if (parentKey) return `${parentKey}-${offset}`; return pos; } -function adjustWidgetMarksForward(children: Child[]) { - const lastChild = children[children.length - 1]; +function adjustWidgetMarksForward( + lastNodeChild: ChildNode | null, + widgetChild: ChildWidget | ChildNativeWidget | null +) { if ( - (lastChild?.type !== "widget" && lastChild?.type !== "native-widget") || + !widgetChild || // Using internal Decoration property, "type" // eslint-disable-next-line @typescript-eslint/no-explicit-any - (lastChild.widget as any).type.side >= 0 + (widgetChild.widget as any).type.side >= 0 ) return; - let lastNodeChild: ChildNode | null = null; - for (let i = children.length - 2; i >= 0; i--) { - const child = children[i]; - if (child?.type === "node") { - lastNodeChild = child; - break; - } - } - if (!lastNodeChild || !lastNodeChild.node.isInline) return; const marksToSpread = lastNodeChild.marks; - lastChild.marks = lastChild.marks.reduce( + widgetChild.marks = widgetChild.marks.reduce( (acc, mark) => mark.addToSet(acc), marksToSpread ); } -function adjustWidgetMarksBack(children: Child[]) { - const lastChild = children[children.length - 1]; - if (lastChild?.type !== "node" || !lastChild.node.isInline) return; +function adjustWidgetMarksBack( + widgetChildren: Array, + nodeChild: ChildNode +) { + if (!nodeChild.node.isInline) return; + + const marksToSpread = nodeChild.marks; + for (let i = widgetChildren.length - 1; i >= 0; i--) { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const child = widgetChildren[i]!; - const marksToSpread = lastChild.marks; - for (let i = children.length - 2; i >= 0; i--) { - const child = children[i]; if ( - (child?.type !== "widget" && child?.type !== "native-widget") || // Using internal Decoration property, "type" // eslint-disable-next-line @typescript-eslint/no-explicit-any (child.widget as any).type.side < 0 - ) - break; + ) { + continue; + } child.marks = child.marks.reduce( (acc, mark) => mark.addToSet(acc), @@ -277,77 +329,92 @@ function adjustWidgetMarksBack(children: Child[]) { } } -function createChildElements( - children: Child[], - innerPos: number, - doc: Node | undefined, - posToKey: Map | undefined -): ReactNode[] { - if (!children.length) return []; - - if (children.every((child) => child.type !== "node" || child.node.isInline)) { - return [ - , - ]; - } +const ChildElement = memo( + function ChildElement({ + child, + getInnerPos, + }: { + child: Child; + getInnerPos: MutableRefObject<() => number>; + }) { + const getNodePos = useRef(() => getInnerPos.current() + child.offset); + getNodePos.current = () => getInnerPos.current() + child.offset; - return children.map((child) => { if (child.type === "node") { - const pos = innerPos + child.offset; - const key = posToKey?.get(pos) ?? pos; return ( ); } else { return ( ); } + } + /** + * It's safe to skip re-rendering a ChildElement component as long + * as its child prop is shallowly equivalent to the previous render. + * posToKey will be updated on every doc update, but if the child + * hasn't changed, it will still have the same key. + */ + // (prevProps, nextProps) => areChildrenEqual(prevProps.child, nextProps.child) +); + +function createChildElements( + children: Child[], + getInnerPos: MutableRefObject<() => number> +): ReactNode[] { + if (!children.length) return []; + + if (children.every((child) => child.type !== "node" || child.node.isInline)) { + return [ + , + ]; + } + + return children.map((child) => { + return ( + + ); }); } -export function ChildNodeViews({ - pos, +export const ChildNodeViews = memo(function ChildNodeViews({ + getPos, node, innerDecorations, }: { - pos: number; + getPos: MutableRefObject<() => number>; node: Node | undefined; innerDecorations: DecorationSource; }) { - const editorState = useEditorState(); + // const editorState = useEditorState(); const reactKeys = useReactKeys(); + const getInnerPos = useRef(() => getPos.current() + 1); + + const childMap = useRef(new Map()).current; + if (!node) return null; - const innerPos = pos + 1; - const children: Child[] = []; + const keysSeen = new Set(); + + let widgetChildren: Array = []; + let lastNodeChild: ChildNode | null = null; iterDeco( node, @@ -355,45 +422,105 @@ export function ChildNodeViews({ (widget, isNative, offset, index) => { // eslint-disable-next-line @typescript-eslint/no-explicit-any const widgetMarks = ((widget as any).type.spec.marks as Mark[]) ?? []; + let key; if (isNative) { - children.push({ + key = createKey( + getInnerPos.current(), + offset, + "native-widget", + reactKeys?.posToKey, + widget, + index + ); + const child = { type: "native-widget", - widget: widget, + widget, marks: widgetMarks, offset, index, - }); + key, + } as const; + const prevChild = childMap.get(key); + if (prevChild && areChildrenEqual(prevChild, child)) { + prevChild.offset = offset; + } else { + childMap.set(key, child); + } + keysSeen.add(key); } else { - children.push({ + key = createKey( + getInnerPos.current(), + offset, + "widget", + reactKeys?.posToKey, + widget, + index + ); + const child = { type: "widget", widget: widget as ReactWidgetDecoration, marks: widgetMarks, offset, index, - }); + key, + } as const; + const prevChild = childMap.get(key); + if (prevChild && areChildrenEqual(prevChild, child)) { + prevChild.offset = offset; + } else { + childMap.set(key, child); + } + keysSeen.add(key); } - adjustWidgetMarksForward(children); + const child = childMap.get(key) as ChildWidget | ChildNativeWidget; + widgetChildren.push(child); + adjustWidgetMarksForward( + lastNodeChild, + childMap.get(key) as ChildWidget | ChildNativeWidget + ); }, (childNode, outerDeco, innerDeco, offset) => { - children.push({ + const key = createKey( + getInnerPos.current(), + offset, + "node", + reactKeys?.posToKey + ); + const child = { type: "node", node: childNode, marks: childNode.marks, innerDeco, outerDeco, offset, - }); - adjustWidgetMarksBack(children); + key, + } as const; + const prevChild = childMap.get(key); + if (prevChild && areChildrenEqual(prevChild, child)) { + prevChild.offset = offset; + lastNodeChild = prevChild as ChildNode; + } else { + childMap.set(key, child); + lastNodeChild = child; + } + keysSeen.add(key); + adjustWidgetMarksBack(widgetChildren, lastNodeChild); + widgetChildren = []; } ); - const childElements = createChildElements( - children, - innerPos, - editorState.doc, - reactKeys?.posToKey + for (const key of childMap.keys()) { + if (!keysSeen.has(key)) { + childMap.delete(key); + } + } + + const children = Array.from(childMap.values()).sort( + (a, b) => a.offset - b.offset ); + const childElements = createChildElements(children, getInnerPos); + const lastChild = children[children.length - 1]; if ( @@ -405,10 +532,10 @@ export function ChildNodeViews({ /\n$/.test(lastChild.node.text!) ) { childElements.push( - , - + , + ); } return <>{childElements}; -} +}); diff --git a/src/components/CursorWrapper.tsx b/src/components/CursorWrapper.tsx index 1ff0a104..890186e1 100644 --- a/src/components/CursorWrapper.tsx +++ b/src/components/CursorWrapper.tsx @@ -13,7 +13,7 @@ import { WidgetViewComponentProps } from "./WidgetViewComponentProps.js"; export const CursorWrapper = forwardRef< HTMLImageElement, WidgetViewComponentProps ->(function CursorWrapper({ widget, pos, ...props }, ref) { +>(function CursorWrapper({ widget, getPos, ...props }, ref) { const [shouldRender, setShouldRender] = useState(true); const innerRef = useRef(null); diff --git a/src/components/DocNodeView.tsx b/src/components/DocNodeView.tsx index a99dd331..25473e8c 100644 --- a/src/components/DocNodeView.tsx +++ b/src/components/DocNodeView.tsx @@ -11,7 +11,9 @@ import React, { cloneElement, createElement, forwardRef, + memo, useImperativeHandle, + useMemo, useRef, } from "react"; @@ -21,6 +23,12 @@ import { NodeViewDesc } from "../viewdesc.js"; import { ChildNodeViews, wrapInDeco } from "./ChildNodeViews.js"; +const getPos = { + current() { + return -1; + }, +}; + export type DocNodeViewProps = { className?: string; node: Node | undefined; @@ -30,68 +38,87 @@ export type DocNodeViewProps = { viewDesc?: NodeViewDesc; } & Omit, HTMLDivElement>, "ref">; -export const DocNodeView = forwardRef(function DocNodeView( - { - className, - node, - innerDeco, - outerDeco, - as, - viewDesc, - ...elementProps - }: DocNodeViewProps, - ref: ForwardedRef -) { - const innerRef = useRef(null); +export const DocNodeView = memo( + forwardRef(function DocNodeView( + { + className, + node, + innerDeco, + outerDeco, + as, + viewDesc, + ...elementProps + }: DocNodeViewProps, + ref: ForwardedRef + ) { + const innerRef = useRef(null); + + useImperativeHandle( + ref, + () => { + return innerRef.current; + }, + [] + ); - useImperativeHandle( - ref, - () => { - return innerRef.current; - }, - [] - ); + const { childDescriptors, nodeViewDescRef } = useNodeViewDescriptor( + node, + () => getPos.current(), + innerRef, + innerRef, + innerDeco, + outerDeco, + viewDesc + ); - const { childDescriptors } = useNodeViewDescriptor( - node, - innerRef, - innerRef, - innerDeco, - outerDeco, - viewDesc - ); + const childContextValue = useMemo( + () => ({ + parentRef: nodeViewDescRef, + siblingsRef: childDescriptors, + }), + [childDescriptors, nodeViewDescRef] + ); - const props = { - ...elementProps, - ref: innerRef, - className, - suppressContentEditableWarning: true, - }; + const props = { + ...elementProps, + ref: innerRef, + className, + suppressContentEditableWarning: true, + }; - const element = as - ? cloneElement( - as, - props, - - - - ) - : createElement( - "div", - props, - - - - ); + const element = as + ? cloneElement( + as, + props, + + + + ) + : createElement( + "div", + props, + + + + ); - if (!node) return element; + if (!node) return element; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const nodeDecorations = outerDeco.filter((deco) => !(deco as any).inline); - if (!nodeDecorations.length) { - return element; - } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const nodeDecorations = outerDeco.filter((deco) => !(deco as any).inline); + if (!nodeDecorations.length) { + return element; + } - const wrapped = nodeDecorations.reduce(wrapInDeco, element); - return wrapped; -}); + const wrapped = nodeDecorations.reduce(wrapInDeco, element); + return wrapped; + }) +); diff --git a/src/components/MarkView.tsx b/src/components/MarkView.tsx index fb40834e..e95c76f0 100644 --- a/src/components/MarkView.tsx +++ b/src/components/MarkView.tsx @@ -1,67 +1,108 @@ import { Mark } from "prosemirror-model"; import React, { + MutableRefObject, ReactNode, forwardRef, + memo, useContext, useImperativeHandle, useLayoutEffect, + useMemo, useRef, } from "react"; import { ChildDescriptorsContext } from "../contexts/ChildDescriptorsContext.js"; -import { MarkViewDesc, ViewDesc } from "../viewdesc.js"; +import { MarkViewDesc, ViewDesc, sortViewDescs } from "../viewdesc.js"; import { OutputSpec } from "./OutputSpec.js"; type Props = { mark: Mark; + getPos: MutableRefObject<() => number>; children: ReactNode; }; -export const MarkView = forwardRef(function MarkView( - { mark, children }: Props, - ref -) { - const siblingDescriptors = useContext(ChildDescriptorsContext); - const childDescriptors: ViewDesc[] = []; - const domRef = useRef(null); +export const MarkView = memo( + forwardRef(function MarkView({ mark, getPos, children }: Props, ref) { + const { siblingsRef, parentRef } = useContext(ChildDescriptorsContext); + const viewDescRef = useRef(undefined); - useImperativeHandle( - ref, - () => { - return domRef.current; - }, - [] - ); + const childDescriptors = useRef([]); + const domRef = useRef(null); - const outputSpec = mark.type.spec.toDOM?.(mark, true); - if (!outputSpec) - throw new Error(`Mark spec for ${mark.type.name} is missing toDOM`); + useImperativeHandle( + ref, + () => { + return domRef.current; + }, + [] + ); - useLayoutEffect(() => { - if (!domRef.current) return; + const outputSpec = useMemo( + () => mark.type.spec.toDOM?.(mark, true), + [mark] + ); + if (!outputSpec) + throw new Error(`Mark spec for ${mark.type.name} is missing toDOM`); - const firstChildDesc = childDescriptors[0]; + useLayoutEffect(() => { + const siblings = siblingsRef.current; + return () => { + if (!viewDescRef.current) return; + if (siblings.includes(viewDescRef.current)) { + const index = siblings.indexOf(viewDescRef.current); + siblings.splice(index, 1); + } + }; + }, [siblingsRef]); - const desc = new MarkViewDesc( - undefined, - childDescriptors, - mark, - domRef.current, - firstChildDesc?.dom.parentElement ?? domRef.current - ); - siblingDescriptors.push(desc); + useLayoutEffect(() => { + if (!domRef.current) return; + + const firstChildDesc = childDescriptors.current[0]; + + if (!viewDescRef.current) { + viewDescRef.current = new MarkViewDesc( + parentRef.current, + childDescriptors.current, + () => getPos.current(), + mark, + domRef.current, + firstChildDesc?.dom.parentElement ?? domRef.current + ); + } else { + viewDescRef.current.parent = parentRef.current; + viewDescRef.current.dom = domRef.current; + viewDescRef.current.contentDOM = + firstChildDesc?.dom.parentElement ?? domRef.current; + viewDescRef.current.mark = mark; + viewDescRef.current.getPos = () => getPos.current(); + } + if (!siblingsRef.current.includes(viewDescRef.current)) { + siblingsRef.current.push(viewDescRef.current); + } - for (const childDesc of childDescriptors) { - childDesc.parent = desc; - } - }); + siblingsRef.current.sort(sortViewDescs); - return ( - - - {children} - - - ); -}); + for (const childDesc of childDescriptors.current) { + childDesc.parent = viewDescRef.current; + } + }); + + const childContextValue = useMemo( + () => ({ + parentRef: viewDescRef, + siblingsRef: childDescriptors, + }), + [childDescriptors, viewDescRef] + ); + + return ( + + + {children} + + + ); + }) +); diff --git a/src/components/NativeWidgetView.tsx b/src/components/NativeWidgetView.tsx index 97c40327..6954ccec 100644 --- a/src/components/NativeWidgetView.tsx +++ b/src/components/NativeWidgetView.tsx @@ -1,20 +1,36 @@ import { Decoration, EditorView } from "prosemirror-view"; -import React, { useContext, useLayoutEffect, useRef } from "react"; +import React, { + MutableRefObject, + useContext, + useLayoutEffect, + useRef, +} from "react"; import { ChildDescriptorsContext } from "../contexts/ChildDescriptorsContext.js"; import { useEditorEffect } from "../hooks/useEditorEffect.js"; -import { WidgetViewDesc } from "../viewdesc.js"; +import { WidgetViewDesc, sortViewDescs } from "../viewdesc.js"; type Props = { widget: Decoration; - pos: number; + getPos: MutableRefObject<() => number>; }; -export function NativeWidgetView({ widget, pos }: Props) { - const siblingDescriptors = useContext(ChildDescriptorsContext); +export function NativeWidgetView({ widget, getPos }: Props) { + const { siblingsRef, parentRef } = useContext(ChildDescriptorsContext); + const viewDescRef = useRef(null); + const rootDomRef = useRef(null); - const posRef = useRef(pos); - posRef.current = pos; + + useLayoutEffect(() => { + const siblings = siblingsRef.current; + return () => { + if (!viewDescRef.current) return; + if (siblings.includes(viewDescRef.current)) { + const index = siblings.indexOf(viewDescRef.current); + siblings.splice(index, 1); + } + }; + }, [siblingsRef]); useEditorEffect((view) => { if (!rootDomRef.current) return; @@ -24,7 +40,7 @@ export function NativeWidgetView({ widget, pos }: Props) { | HTMLElement | ((view: EditorView, getPos: () => number) => HTMLElement); let dom = - typeof toDOM === "function" ? toDOM(view, () => posRef.current) : toDOM; + typeof toDOM === "function" ? toDOM(view, () => getPos.current()) : toDOM; // eslint-disable-next-line @typescript-eslint/no-explicit-any if (!(widget as any).type.spec.raw) { if (dom.nodeType != 1) { @@ -43,8 +59,23 @@ export function NativeWidgetView({ widget, pos }: Props) { useLayoutEffect(() => { if (!rootDomRef.current) return; - const desc = new WidgetViewDesc(undefined, widget, rootDomRef.current); - siblingDescriptors.push(desc); + if (!viewDescRef.current) { + viewDescRef.current = new WidgetViewDesc( + parentRef.current, + () => getPos.current(), + widget, + rootDomRef.current + ); + } else { + viewDescRef.current.parent = parentRef.current; + viewDescRef.current.widget = widget; + viewDescRef.current.getPos = () => getPos.current(); + viewDescRef.current.dom = rootDomRef.current; + } + if (!siblingsRef.current.includes(viewDescRef.current)) { + siblingsRef.current.push(viewDescRef.current); + } + siblingsRef.current.sort(sortViewDescs); }); return ; diff --git a/src/components/NodeView.tsx b/src/components/NodeView.tsx index c1c6be53..09914c6e 100644 --- a/src/components/NodeView.tsx +++ b/src/components/NodeView.tsx @@ -1,5 +1,4 @@ import { DOMOutputSpec, Node } from "prosemirror-model"; -import { NodeSelection } from "prosemirror-state"; import { Decoration, DecorationSource, @@ -7,11 +6,14 @@ import { } from "prosemirror-view"; import React, { ForwardRefExoticComponent, + MutableRefObject, RefAttributes, cloneElement, createElement, + memo, useContext, useLayoutEffect, + useMemo, useRef, } from "react"; import { createPortal } from "react-dom"; @@ -19,8 +21,8 @@ import { createPortal } from "react-dom"; import { ChildDescriptorsContext } from "../contexts/ChildDescriptorsContext.js"; import { EditorContext } from "../contexts/EditorContext.js"; import { NodeViewContext } from "../contexts/NodeViewContext.js"; +import { SelectNodeContext } from "../contexts/SelectNodeContext.js"; import { StopEventContext } from "../contexts/StopEventContext.js"; -import { useEditorState } from "../hooks/useEditorState.js"; import { useNodeViewDescriptor } from "../hooks/useNodeViewDescriptor.js"; import { ChildNodeViews, wrapInDeco } from "./ChildNodeViews.js"; @@ -30,14 +32,14 @@ import { OutputSpec } from "./OutputSpec.js"; type NodeViewProps = { outerDeco: readonly Decoration[]; - pos: number; + getPos: MutableRefObject<() => number>; node: Node; innerDeco: DecorationSource; }; -export function NodeView({ +export const NodeView = memo(function NodeView({ outerDeco, - pos, + getPos, node, innerDeco, ...props @@ -45,16 +47,15 @@ export function NodeView({ const domRef = useRef(null); const nodeDomRef = useRef(null); const contentDomRef = useRef(null); + const getPosFunc = useRef(() => getPos.current()).current; // this is ill-conceived; should revisit const initialNode = useRef(node); const initialOuterDeco = useRef(outerDeco); const initialInnerDeco = useRef(innerDeco); - const posRef = useRef(pos); - posRef.current = pos; const customNodeViewRootRef = useRef(null); const customNodeViewRef = useRef(null); - const state = useEditorState(); + // const state = useEditorState(); const { nodeViews } = useContext(NodeViewContext); const { view } = useContext(EditorContext); @@ -66,6 +67,11 @@ export function NodeView({ > | undefined = nodeViews[node.type.name]; + const outputSpec: DOMOutputSpec | undefined = useMemo( + () => node.type.spec.toDOM?.(node), + [node] + ); + // TODO: Would be great to pull all of the custom node view stuff into // a hook const customNodeView = view?.someProp( @@ -108,17 +114,24 @@ export function NodeView({ // this line if customNodeView is set // eslint-disable-next-line @typescript-eslint/no-non-null-assertion view!, - () => posRef.current, + () => getPos.current(), initialOuterDeco.current, initialInnerDeco.current ); const { dom } = customNodeViewRef.current; nodeDomRef.current = customNodeViewRootRef.current; customNodeViewRootRef.current.appendChild(dom); - }, [customNodeView, view, innerDeco, node, outerDeco]); + }, [customNodeView, view, innerDeco, node, outerDeco, getPos]); - const { childDescriptors, setStopEvent } = useNodeViewDescriptor( + const { + hasContentDOM, + childDescriptors, + setStopEvent, + setSelectNode, + nodeViewDescRef, + } = useNodeViewDescriptor( node, + () => getPos.current(), domRef, nodeDomRef, innerDeco, @@ -127,22 +140,31 @@ export function NodeView({ contentDomRef ); + const finalProps = { + ...props, + ...(!hasContentDOM && { + contentEditable: false, + }), + }; + + const nodeProps = useMemo( + () => ({ + node: node, + getPos: getPosFunc, + decorations: outerDeco, + innerDecorations: innerDeco, + }), + [getPosFunc, innerDeco, node, outerDeco] + ); + if (Component) { element = ( - - + + ); } else if (customNodeView) { @@ -153,7 +175,7 @@ export function NodeView({ // this line if customNodeView is set // eslint-disable-next-line @typescript-eslint/no-non-null-assertion view!, - () => posRef.current, + () => getPos.current(), initialOuterDeco.current, initialInnerDeco.current ); @@ -169,17 +191,23 @@ export function NodeView({ }, contentDOM && createPortal( - , + , contentDOM ) ); } else { - const outputSpec: DOMOutputSpec | undefined = node.type.spec.toDOM?.(node); - if (outputSpec) { element = ( - - + + ); } @@ -203,25 +231,39 @@ export function NodeView({ // TODO: Should we only be wrapping non-inline elements? Inline elements have // already been wrapped in ChildNodeViews/InlineView? const markedElement = node.marks.reduce( - (element, mark) => {element}, + (element, mark) => ( + + {element} + + ), decoratedElement ); + const childContextValue = useMemo( + () => ({ + parentRef: nodeViewDescRef, + siblingsRef: childDescriptors, + }), + [childDescriptors, nodeViewDescRef] + ); + return ( - - - {cloneElement( - markedElement, - node.marks.length || - // eslint-disable-next-line @typescript-eslint/no-explicit-any - outerDeco.some((d) => (d as any).type.attrs.nodeName) - ? { ref: domRef } - : // If all of the node decorations were attr-only, then - // we've already passed the domRef to the NodeView component - // as a prop - undefined - )} - - + + + + {cloneElement( + markedElement, + node.marks.length || + // eslint-disable-next-line @typescript-eslint/no-explicit-any + outerDeco.some((d) => (d as any).type.attrs.nodeName) + ? { ref: domRef } + : // If all of the node decorations were attr-only, then + // we've already passed the domRef to the NodeView component + // as a prop + undefined + )} + + + ); -} +}); diff --git a/src/components/NodeViewComponentProps.tsx b/src/components/NodeViewComponentProps.tsx index 2e3df52b..2096af82 100644 --- a/src/components/NodeViewComponentProps.tsx +++ b/src/components/NodeViewComponentProps.tsx @@ -8,7 +8,6 @@ export type NodeViewComponentProps = { innerDecorations: DecorationSource; node: Node; children?: ReactNode | ReactNode[]; - isSelected: boolean; - pos: number; + getPos: () => number; }; } & HTMLAttributes; diff --git a/src/components/OutputSpec.tsx b/src/components/OutputSpec.tsx index 4d8c536a..85530e76 100644 --- a/src/components/OutputSpec.tsx +++ b/src/components/OutputSpec.tsx @@ -1,5 +1,11 @@ import { DOMOutputSpec } from "prosemirror-model"; -import React, { HTMLProps, ReactNode, createElement, forwardRef } from "react"; +import React, { + HTMLProps, + ReactNode, + createElement, + forwardRef, + memo, +} from "react"; import { htmlAttrsToReactProps, mergeReactProps } from "../props.js"; @@ -8,57 +14,57 @@ type Props = HTMLProps & { children?: ReactNode; }; -const ForwardedOutputSpec = forwardRef(function OutputSpec( - { outputSpec, children, ...propOverrides }: Props, - ref -) { - if (typeof outputSpec === "string") { - return <>{outputSpec}; - } +const ForwardedOutputSpec = memo( + forwardRef(function OutputSpec( + { outputSpec, children, ...propOverrides }: Props, + ref + ) { + if (typeof outputSpec === "string") { + return <>{outputSpec}; + } - if (!Array.isArray(outputSpec)) { - throw new Error( - "@nytimes/react-prosemirror only supports strings and arrays in toDOM" - ); - } + if (!Array.isArray(outputSpec)) { + throw new Error( + "@nytimes/react-prosemirror only supports strings and arrays in toDOM" + ); + } - const tagSpec = outputSpec[0] as string; - const tagName = tagSpec.replace(" ", ":"); - const attrs = outputSpec[1]; + const tagSpec = outputSpec[0] as string; + const tagName = tagSpec.replace(" ", ":"); + const attrs = outputSpec[1]; - let props: HTMLProps = { - ref, - ...propOverrides, - }; - let start = 1; - if ( - attrs && - typeof attrs === "object" && - attrs.nodeType == null && - !Array.isArray(attrs) - ) { - start = 2; - props = mergeReactProps(htmlAttrsToReactProps(attrs), props); - } + let props: HTMLProps = { + ref, + ...propOverrides, + }; + let start = 1; + if ( + attrs && + typeof attrs === "object" && + attrs.nodeType == null && + !Array.isArray(attrs) + ) { + start = 2; + props = mergeReactProps(htmlAttrsToReactProps(attrs), props); + } - const content: ReactNode[] = []; - for (let i = start; i < outputSpec.length; i++) { - const child = outputSpec[i] as DOMOutputSpec | 0; - if (child === 0) { - if (i < outputSpec.length - 1 || i > start) { - throw new RangeError( - "Content hole must be the only child of its parent node" - ); + const content: ReactNode[] = []; + for (let i = start; i < outputSpec.length; i++) { + const child = outputSpec[i] as DOMOutputSpec | 0; + if (child === 0) { + if (i < outputSpec.length - 1 || i > start) { + throw new RangeError( + "Content hole must be the only child of its parent node" + ); + } + return createElement(tagName, props, children); } - return createElement(tagName, props, children); + content.push( + {children} + ); } - content.push( - - {children} - - ); - } - return createElement(tagName, props, ...content); -}); + return createElement(tagName, props, ...content); + }) +); export { ForwardedOutputSpec as OutputSpec }; diff --git a/src/components/ProseMirror.tsx b/src/components/ProseMirror.tsx index 020a00fe..f7a6eaaf 100644 --- a/src/components/ProseMirror.tsx +++ b/src/components/ProseMirror.tsx @@ -1,12 +1,18 @@ -import { DecorationSet, NodeViewConstructor } from "prosemirror-view"; +import { + Decoration, + DecorationSet, + NodeViewConstructor, +} from "prosemirror-view"; import React, { ForwardRefExoticComponent, ReactNode, RefAttributes, + useMemo, useState, } from "react"; import { EditorContext } from "../contexts/EditorContext.js"; +import { EditorStateContext } from "../contexts/EditorStateContext.js"; import { NodeViewContext } from "../contexts/NodeViewContext.js"; import { computeDocDeco } from "../decorations/computeDocDeco.js"; import { viewDecorations } from "../decorations/viewDecorations.js"; @@ -34,16 +40,18 @@ export type Props = Omit & { }; }; +const EMPTY_OUTER_DECOS: Decoration[] = []; + function ProseMirrorInner({ className, children, - nodeViews = {}, + nodeViews, customNodeViews, ...props }: Props) { const [mount, setMount] = useState(null); - const editor = useEditor(mount, { + const { editor, state } = useEditor(mount, { ...props, nodeViews: customNodeViews, }); @@ -52,28 +60,44 @@ function ProseMirrorInner({ ? viewDecorations(editor.view, editor.cursorWrapper) : (DecorationSet.empty as unknown as DecorationSet); - const outerDecos = editor.view ? computeDocDeco(editor.view) : []; + const outerDecos = editor.view + ? computeDocDeco(editor.view) + : EMPTY_OUTER_DECOS; + + const nodeViewContextValue = useMemo( + () => ({ + nodeViews: nodeViews ?? {}, + }), + [nodeViews] + ); + + const docNodeViewContextValue = useMemo( + () => ({ + className: className, + setMount: setMount, + node: editor.view?.state.doc, + innerDeco: innerDecos, + outerDeco: outerDecos, + viewDesc: editor.docViewDescRef.current, + }), + [ + className, + editor.docViewDescRef, + editor.view?.state.doc, + innerDecos, + outerDecos, + ] + ); return ( - - - {children} - - + + + + {children} + + + ); } diff --git a/src/components/ProseMirrorDoc.tsx b/src/components/ProseMirrorDoc.tsx index d8e18365..44dd014d 100644 --- a/src/components/ProseMirrorDoc.tsx +++ b/src/components/ProseMirrorDoc.tsx @@ -7,10 +7,12 @@ import React, { forwardRef, useContext, useImperativeHandle, + useMemo, useRef, } from "react"; import { ChildDescriptorsContext } from "../contexts/ChildDescriptorsContext.js"; +import { ViewDesc } from "../viewdesc.js"; import { DocNodeView, DocNodeViewProps } from "./DocNodeView.js"; @@ -30,8 +32,10 @@ function ProseMirrorDoc( { as, ...props }: Props, ref: ForwardedRef ) { + const childDescriptors = useRef([]); const innerRef = useRef(null); const { setMount, ...docProps } = useContext(DocNodeViewContext); + const viewDescRef = useRef(undefined); useImperativeHandle( ref, @@ -41,8 +45,16 @@ function ProseMirrorDoc( [] ); + const childContextValue = useMemo( + () => ({ + parentRef: viewDescRef, + siblingsRef: childDescriptors, + }), + [childDescriptors, viewDescRef] + ); + return ( - + { innerRef.current = el; diff --git a/src/components/SeparatorHackView.tsx b/src/components/SeparatorHackView.tsx index b61caf63..f9b51fd6 100644 --- a/src/components/SeparatorHackView.tsx +++ b/src/components/SeparatorHackView.tsx @@ -1,19 +1,41 @@ -import React, { useContext, useLayoutEffect, useRef, useState } from "react"; +import React, { + MutableRefObject, + useContext, + useLayoutEffect, + useRef, + useState, +} from "react"; import { browser } from "../browser.js"; import { ChildDescriptorsContext } from "../contexts/ChildDescriptorsContext.js"; -import { TrailingHackViewDesc } from "../viewdesc.js"; +import { TrailingHackViewDesc, sortViewDescs } from "../viewdesc.js"; -export function SeparatorHackView() { - const siblingDescriptors = useContext(ChildDescriptorsContext); +type Props = { + getPos: MutableRefObject<() => number>; +}; + +export function SeparatorHackView({ getPos }: Props) { + const { siblingsRef, parentRef } = useContext(ChildDescriptorsContext); + const viewDescRef = useRef(null); const ref = useRef(null); const [shouldRender, setShouldRender] = useState(false); + useLayoutEffect(() => { + const siblings = siblingsRef.current; + return () => { + if (!viewDescRef.current) return; + if (siblings.includes(viewDescRef.current)) { + const index = siblings.indexOf(viewDescRef.current); + siblings.splice(index, 1); + } + }; + }, [siblingsRef]); + // There's no risk of an infinite loop here, because // we call setShouldRender conditionally // eslint-disable-next-line react-hooks/exhaustive-deps useLayoutEffect(() => { - const lastSibling = siblingDescriptors[siblingDescriptors.length - 1]; + const lastSibling = siblingsRef.current[siblingsRef.current.length - 1]; if ( (browser.safari || browser.chrome) && (lastSibling?.dom as HTMLElement)?.contentEditable == "false" @@ -24,8 +46,23 @@ export function SeparatorHackView() { if (!ref.current) return; - const desc = new TrailingHackViewDesc(undefined, [], ref.current, null); - siblingDescriptors.push(desc); + if (!viewDescRef.current) { + viewDescRef.current = new TrailingHackViewDesc( + parentRef.current, + [], + () => getPos.current(), + ref.current, + null + ); + } else { + viewDescRef.current.parent = parentRef.current; + viewDescRef.current.dom = ref.current; + viewDescRef.current.getPos = () => getPos.current(); + } + if (!siblingsRef.current.includes(viewDescRef.current)) { + siblingsRef.current.push(viewDescRef.current); + } + siblingsRef.current.sort(sortViewDescs); }); return shouldRender ? ( diff --git a/src/components/TextNodeView.tsx b/src/components/TextNodeView.tsx index 90c707c3..4747befc 100644 --- a/src/components/TextNodeView.tsx +++ b/src/components/TextNodeView.tsx @@ -1,25 +1,68 @@ import { Node } from "prosemirror-model"; import { Decoration, DecorationSet, EditorView } from "prosemirror-view"; -import { Component } from "react"; +import { Component, MutableRefObject } from "react"; import { findDOMNode } from "react-dom"; -import { CompositionViewDesc, TextViewDesc, ViewDesc } from "../viewdesc.js"; +import { + CompositionViewDesc, + TextViewDesc, + ViewDesc, + sortViewDescs, +} from "../viewdesc.js"; import { wrapInDeco } from "./ChildNodeViews.js"; +function shallowEqual( + objA: Record, + objB: Record +): boolean { + if (objA === objB) { + return true; + } + + if (!objA || !objB) { + return false; + } + + const aKeys = Object.keys(objA); + const bKeys = Object.keys(objB); + const len = aKeys.length; + + if (bKeys.length !== len) { + return false; + } + + for (let i = 0; i < len; i++) { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const key = aKeys[i]!; + + if ( + objA[key] !== objB[key] || + !Object.prototype.hasOwnProperty.call(objB, key) + ) { + return false; + } + } + + return true; +} + type Props = { view: EditorView | null; node: Node; - pos: number; - siblingDescriptors: ViewDesc[]; + getPos: MutableRefObject<() => number>; + siblingsRef: MutableRefObject; + parentRef: MutableRefObject; decorations: readonly Decoration[]; }; export class TextNodeView extends Component { - private viewDescRef: null | TextViewDesc = null; + private viewDescRef: null | TextViewDesc | CompositionViewDesc = null; + private renderRef: null | JSX.Element = null; updateEffect() { - const { decorations, siblingDescriptors, node } = this.props; + const { view, decorations, siblingsRef, parentRef, getPos, node } = + this.props; // There simply is no other way to ref a text node // eslint-disable-next-line react/no-find-dom-node const dom = findDOMNode(this); @@ -28,6 +71,21 @@ export class TextNodeView extends Component { // when a composition was started that produces a new text node. // Otherwise we just rely on re-rendering the renderRef if (!dom) { + if (!view?.composing) return; + + this.viewDescRef = new CompositionViewDesc( + parentRef.current, + () => getPos.current(), + // These are just placeholders/dummies. We can't + // actually find the correct DOM nodes from here, + // so we let our parent do it. + // Passing a valid element here just so that the + // ViewDesc constructor doesn't blow up. + document.createElement("div"), + document.createTextNode(node.text ?? ""), + node.text ?? "" + ); + return; } @@ -40,6 +98,7 @@ export class TextNodeView extends Component { this.viewDescRef = new TextViewDesc( undefined, [], + () => getPos.current(), node, decorations, DecorationSet.empty, @@ -47,9 +106,10 @@ export class TextNodeView extends Component { textNode ); } else { - this.viewDescRef.parent = undefined; + this.viewDescRef.parent = parentRef.current; this.viewDescRef.children = []; this.viewDescRef.node = node; + this.viewDescRef.getPos = () => getPos.current(); this.viewDescRef.outerDeco = decorations; this.viewDescRef.innerDeco = DecorationSet.empty; this.viewDescRef.dom = dom; @@ -58,7 +118,15 @@ export class TextNodeView extends Component { this.viewDescRef.nodeDOM = textNode; } - siblingDescriptors.push(this.viewDescRef); + if (!siblingsRef.current.includes(this.viewDescRef)) { + siblingsRef.current.push(this.viewDescRef); + } + + siblingsRef.current.sort(sortViewDescs); + } + + shouldComponentUpdate(nextProps: Props): boolean { + return !shallowEqual(this.props, nextProps); } componentDidMount(): void { @@ -69,9 +137,36 @@ export class TextNodeView extends Component { this.updateEffect(); } + componentWillUnmount(): void { + const { siblingsRef } = this.props; + if (!this.viewDescRef) return; + if (siblingsRef.current.includes(this.viewDescRef)) { + const index = siblingsRef.current.indexOf(this.viewDescRef); + siblingsRef.current.splice(index, 1); + } + } + render() { - const { node, decorations } = this.props; + const { view, getPos, node, decorations } = this.props; + + // During a composition, it's crucial that we don't try to + // update the DOM that the user is working in. If there's + // an active composition and the selection is in this node, + // we freeze the DOM of this element so that it doesn't + // interrupt the composition + if ( + view?.composing && + view.state.selection.from >= getPos.current() && + view.state.selection.from <= getPos.current() + node.nodeSize + ) { + return this.renderRef; + } + + this.renderRef = decorations.reduce( + wrapInDeco, + node.text as unknown as JSX.Element + ); - return decorations.reduce(wrapInDeco, node.text as unknown as JSX.Element); + return this.renderRef; } } diff --git a/src/components/TrailingHackView.tsx b/src/components/TrailingHackView.tsx index 49c305f6..e6f5f4e1 100644 --- a/src/components/TrailingHackView.tsx +++ b/src/components/TrailingHackView.tsx @@ -1,17 +1,54 @@ -import React, { useContext, useLayoutEffect, useRef } from "react"; +import React, { + MutableRefObject, + useContext, + useLayoutEffect, + useRef, +} from "react"; import { ChildDescriptorsContext } from "../contexts/ChildDescriptorsContext.js"; -import { TrailingHackViewDesc } from "../viewdesc.js"; +import { TrailingHackViewDesc, sortViewDescs } from "../viewdesc.js"; + +type Props = { + getPos: MutableRefObject<() => number>; +}; + +export function TrailingHackView({ getPos }: Props) { + const { siblingsRef, parentRef } = useContext(ChildDescriptorsContext); + const viewDescRef = useRef(null); -export function TrailingHackView() { - const siblingDescriptors = useContext(ChildDescriptorsContext); const ref = useRef<(HTMLBRElement & HTMLImageElement) | null>(null); + useLayoutEffect(() => { + const siblings = siblingsRef.current; + return () => { + if (!viewDescRef.current) return; + if (siblings.includes(viewDescRef.current)) { + const index = siblings.indexOf(viewDescRef.current); + siblings.splice(index, 1); + } + }; + }, [siblingsRef]); + useLayoutEffect(() => { if (!ref.current) return; - const desc = new TrailingHackViewDesc(undefined, [], ref.current, null); - siblingDescriptors.push(desc); + if (!viewDescRef.current) { + viewDescRef.current = new TrailingHackViewDesc( + parentRef.current, + [], + () => getPos.current(), + ref.current, + null + ); + } else { + viewDescRef.current.parent = parentRef.current; + viewDescRef.current.dom = ref.current; + viewDescRef.current.getPos = () => getPos.current(); + } + if (!siblingsRef.current.includes(viewDescRef.current)) { + siblingsRef.current.push(viewDescRef.current); + } + siblingsRef.current.sort(sortViewDescs); }); return
; diff --git a/src/components/WidgetView.tsx b/src/components/WidgetView.tsx index 72c05038..982ab247 100644 --- a/src/components/WidgetView.tsx +++ b/src/components/WidgetView.tsx @@ -1,23 +1,57 @@ -import React, { useContext, useLayoutEffect, useRef } from "react"; +import React, { + MutableRefObject, + useContext, + useLayoutEffect, + useRef, +} from "react"; import { ChildDescriptorsContext } from "../contexts/ChildDescriptorsContext.js"; import { ReactWidgetDecoration } from "../decorations/ReactWidgetType.js"; -import { WidgetViewDesc } from "../viewdesc.js"; +import { WidgetViewDesc, sortViewDescs } from "../viewdesc.js"; type Props = { widget: ReactWidgetDecoration; - pos: number; + getPos: MutableRefObject<() => number>; }; -export function WidgetView({ widget, pos }: Props) { - const siblingDescriptors = useContext(ChildDescriptorsContext); +export function WidgetView({ widget, getPos }: Props) { + const { siblingsRef, parentRef } = useContext(ChildDescriptorsContext); + const viewDescRef = useRef(null); + const getPosFunc = useRef(() => getPos.current()).current; + const domRef = useRef(null); + useLayoutEffect(() => { + const siblings = siblingsRef.current; + return () => { + if (!viewDescRef.current) return; + if (siblings.includes(viewDescRef.current)) { + const index = siblings.indexOf(viewDescRef.current); + siblings.splice(index, 1); + } + }; + }, [siblingsRef]); + useLayoutEffect(() => { if (!domRef.current) return; - const desc = new WidgetViewDesc(undefined, widget, domRef.current); - siblingDescriptors.push(desc); + if (!viewDescRef.current) { + viewDescRef.current = new WidgetViewDesc( + parentRef.current, + () => getPos.current(), + widget, + domRef.current + ); + } else { + viewDescRef.current.parent = parentRef.current; + viewDescRef.current.widget = widget; + viewDescRef.current.getPos = () => getPos.current(); + viewDescRef.current.dom = domRef.current; + } + if (!siblingsRef.current.includes(viewDescRef.current)) { + siblingsRef.current.push(viewDescRef.current); + } + siblingsRef.current.sort(sortViewDescs); }); const { Component } = widget.type; @@ -27,7 +61,7 @@ export function WidgetView({ widget, pos }: Props) { ) diff --git a/src/components/WidgetViewComponentProps.ts b/src/components/WidgetViewComponentProps.ts index 0ae5ecd1..8748876f 100644 --- a/src/components/WidgetViewComponentProps.ts +++ b/src/components/WidgetViewComponentProps.ts @@ -4,5 +4,5 @@ import { ReactWidgetDecoration } from "../decorations/ReactWidgetType.js"; export type WidgetViewComponentProps = { widget: ReactWidgetDecoration; - pos: number; + getPos: () => number; } & HTMLAttributes; diff --git a/src/components/__tests__/ProseMirror.composition.test.tsx b/src/components/__tests__/ProseMirror.composition.test.tsx index 1f91bdcd..d0f8ecd6 100644 --- a/src/components/__tests__/ProseMirror.composition.test.tsx +++ b/src/components/__tests__/ProseMirror.composition.test.tsx @@ -1,280 +1,298 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-non-null-assertion */ -import { fireEvent } from "@testing-library/react"; -import { EditorState, Plugin } from "prosemirror-state"; -import { code, doc, em, p, schema, strong } from "prosemirror-test-builder"; -import { - Decoration, - DecorationSet, - // @ts-expect-error This is an internal export - __endComposition, -} from "prosemirror-view"; -import React, { forwardRef } from "react"; - -import { widget } from "../../decorations/ReactWidgetType.js"; -import { tempEditor } from "../../testing/editorViewTestHelpers.js"; -import { WidgetViewComponentProps } from "../WidgetViewComponentProps.js"; - -// function endComposition(view: EditorView, forceUpdate?: boolean) { -// act(() => { -// __endComposition(view, forceUpdate); -// }); -// } +import { doc, em, p, strong } from "prosemirror-test-builder"; +// @ts-expect-error This is an internal export +import { EditorView, __endComposition } from "prosemirror-view"; -// function event(pm: EditorView, type: string) { -// act(() => { -// pm.dom.dispatchEvent(new CompositionEvent(type)); -// }); -// } - -// function edit(node: Text, text = "", from = node.nodeValue!.length, to = from) { -// const val = node.nodeValue!; -// node.nodeValue = val.slice(0, from) + text + val.slice(to); -// document.getSelection()!.collapse(node, from + text.length); -// return node; -// } +import { + findTextNode, + tempEditor, +} from "../../testing/editorViewTestHelpers.js"; -// function hasCompositionNode(_pm: EditorView) { -// let { focusNode } = document.getSelection()!; -// while (focusNode && !focusNode.pmViewDesc) focusNode = focusNode.parentNode; -// return ( -// focusNode && focusNode.pmViewDesc!.constructor.name == "CompositionViewDesc" -// ); -// } +function endComposition(view: EditorView, forceUpdate?: boolean) { + __endComposition(view, forceUpdate); +} -// function compose( -// pm: EditorView, -// start: () => Text, -// update: ((node: Text) => void)[], -// options: any = {} -// ) { -// event(pm, "compositionstart"); -// expect(pm.composing).toBeTruthy(); -// let node: Text; -// const sel = document.getSelection()!; -// for (let i = -1; i < update.length; i++) { -// if (i < 0) node = start(); -// else update[i]!(node!); -// const { focusNode, focusOffset } = sel; -// act(() => { -// (pm as any).domObserver.flush(); -// }); - -// if (options.cancel && i == update.length - 1) { -// expect(hasCompositionNode(pm)).toBeFalsy(); -// } else { -// expect( -// node!.parentNode! && pm.dom.contains(node!.parentNode!) -// ).toBeTruthy(); -// expect(sel.focusNode).toBe(focusNode); -// expect(sel.focusOffset).toBe(focusOffset); -// } -// } -// event(pm, "compositionend"); -// if (options.end) { -// options.end(node!); -// (pm as any).domObserver.flush(); -// } -// endComposition(pm); -// expect(pm.composing).toBeFalsy(); -// expect(hasCompositionNode(pm)).toBeFalsy(); -// } +function event(pm: EditorView, type: string) { + pm.dom.dispatchEvent(new CompositionEvent(type)); +} -function wordDeco(state: EditorState) { - const re = /[^\s]+/g, - deco: Decoration[] = []; - state.doc.descendants((node, pos) => { - if (node.isText) - for (let m; (m = re.exec(node.text!)); ) - deco.push( - Decoration.inline(pos + m.index, pos + m.index + m[0].length, { - class: "word", - }) - ); - }); - return DecorationSet.create(state.doc, deco); +function edit(node: Text, text = "", from = node.nodeValue!.length, to = from) { + const val = node.nodeValue!; + node.nodeValue = val.slice(0, from) + text + val.slice(to); + document.getSelection()!.collapse(node, from + text.length); + return node; } -const wordHighlighter = new Plugin({ - props: { decorations: wordDeco }, -}); +function hasCompositionNode(_pm: EditorView) { + let { focusNode } = document.getSelection()!; + while (focusNode && !focusNode.pmViewDesc) focusNode = focusNode.parentNode; + return ( + focusNode && focusNode.pmViewDesc!.constructor.name == "CompositionViewDesc" + ); +} -const Widget = forwardRef( - function Widget({ widget, pos, ...props }, ref) { - return ( - - × - - ); +function compose( + pm: EditorView, + start: () => Text, + update: ((node: Text) => void)[], + options: any = {} +) { + event(pm, "compositionstart"); + expect(pm.composing).toBeTruthy(); + let node: Text; + const sel = document.getSelection()!; + for (let i = -1; i < update.length; i++) { + if (i < 0) node = start(); + else update[i]!(node!); + const { focusNode, focusOffset } = sel; + // @ts-expect-error Internal property + pm.domObserver.flush(); + + if (options.cancel && i == update.length - 1) { + expect(hasCompositionNode(pm)).toBeFalsy(); + } else { + expect( + node!.parentNode! && pm.dom.contains(node!.parentNode!) + ).toBeTruthy(); + expect(sel.focusNode === focusNode).toBeTruthy(); + expect(sel.focusOffset === focusOffset).toBeTruthy(); + if (options.node) expect(hasCompositionNode(pm)).toBeTruthy(); + } } -); - -function widgets(positions: number[], sides: number[]) { - return new Plugin({ - state: { - init(config) { - const deco = positions.map((p, i) => - widget(p, Widget, { side: sides[i] }) - ); - return config.doc - ? DecorationSet.create(config.doc, deco) - : DecorationSet.empty; - }, - apply(tr, deco) { - return deco.map(tr.mapping, tr.doc); - }, - }, - props: { - decorations(this: Plugin, state) { - return this.getState(state); - }, - }, - }); + event(pm, "compositionend"); + if (options.end) { + options.end(node!); + // @ts-expect-error Internal property + pm.domObserver.flush(); + } + endComposition(pm); + expect(pm.composing).toBeFalsy(); + expect(hasCompositionNode(pm)).toBeFalsy(); } -function insertComposition(dom: Element) { - fireEvent.keyDown(dom, { key: "Dead", code: "Quote" }); - fireEvent.compositionStart(dom); - fireEvent.compositionUpdate(dom, { data: "´" }); - fireEvent( - dom, - new InputEvent("beforeinput", { - isComposing: true, - inputType: "insertCompositionText", - data: "´", - }) - ); - fireEvent.input(dom, { - isComposing: true, - inputType: "insertCompositionText", - data: "´", - }); - fireEvent.keyUp(dom, { key: "´", code: "Quote", isComposing: true }); - - fireEvent.keyDown(dom, { key: "é", code: "KeyE", isComposing: true }); - fireEvent.compositionUpdate(dom, { data: "é" }); - fireEvent( - dom, - new InputEvent("beforeinput", { - isComposing: true, - inputType: "insertCompositionText", - data: "é", - }) - ); - fireEvent.compositionEnd(dom, { - inputType: "insertCompositionText", - data: "é", - }); - fireEvent.input(dom, { - isComposing: true, - inputType: "insertCompositionText", - data: "é", - }); - fireEvent.keyUp(dom, { key: "e", code: "KeyE" }); -} +// function wordDeco(state: EditorState) { +// const re = /\w+/g, +// deco: Decoration[] = []; +// state.doc.descendants((node, pos) => { +// if (node.isText) +// for (let m; (m = re.exec(node.text!)); ) +// deco.push( +// Decoration.inline(pos + m.index, pos + m.index + m[0].length, { +// class: "word", +// }) +// ); +// }); +// return DecorationSet.create(state.doc, deco); +// } + +// const wordHighlighter = new Plugin({ +// props: { decorations: wordDeco }, +// }); -describe("EditorView composition", () => { +// const Widget = forwardRef(function Widget( +// { widget, pos, ...props }: WidgetViewComponentProps, +// ref: Ref +// ) { +// return ( +// +// × +// +// ); +// }); + +// function widgets(positions: number[], sides: number[]) { +// return new Plugin({ +// state: { +// init(state) { +// const deco = positions.map((p, i) => +// widget(p, Widget, { side: sides[i] }) +// ); +// return DecorationSet.create(state.doc!, deco); +// }, +// apply(tr, deco) { +// return deco.map(tr.mapping, tr.doc); +// }, +// }, +// props: { +// decorations(this: Plugin, state) { +// return this.getState(state); +// }, +// }, +// }); +// } + +// These unfortunately aren't working at the moment, though +// composition seems to be working generally. +describe.skip("EditorView composition", () => { it("supports composition in an empty block", () => { - const { view } = tempEditor({ doc: doc(p("")) }); - insertComposition(view.dom); - expect(view.state.doc).toEqualNode(doc(p("é"))); + const { view: pm } = tempEditor({ doc: doc(p("")) }); + compose( + pm, + () => edit(pm.dom.firstChild!.appendChild(document.createTextNode("a"))), + [(n) => edit(n, "b"), (n) => edit(n, "c")], + { node: true } + ); + expect(pm.state.doc).toEqualNode(doc(p("abc"))); }); it("supports composition at end of block", () => { - const { view } = tempEditor({ doc: doc(p("foo")) }); - insertComposition(view.dom); - expect(view.state.doc).toEqualNode(doc(p("fooé"))); + const { view: pm } = tempEditor({ doc: doc(p("foo")) }); + compose(pm, () => edit(findTextNode(pm.dom, "foo")!), [ + (n) => edit(n, "!"), + (n) => edit(n, "?"), + ]); + expect(pm.state.doc).toEqualNode(doc(p("foo!?"))); + }); + + it("supports composition at end of block in a new node", () => { + const { view: pm } = tempEditor({ doc: doc(p("foo")) }); + compose( + pm, + () => edit(pm.dom.firstChild!.appendChild(document.createTextNode("!"))), + [(n) => edit(n, "?")], + // $$FORK: We don't use composition view descriptors except for in initially empty nodes + { node: false } + ); + expect(pm.state.doc).toEqualNode(doc(p("foo!?"))); }); it("supports composition at start of block in a new node", () => { - const { view } = tempEditor({ doc: doc(p("foo")) }); - insertComposition(view.dom); - expect(view.state.doc).toEqualNode(doc(p("éfoo"))); + const { view: pm } = tempEditor({ doc: doc(p("foo")) }); + compose( + pm, + () => { + const p = pm.dom.firstChild!; + return edit(p.insertBefore(document.createTextNode("!"), p.firstChild)); + }, + [(n) => edit(n, "?")], + // $$FORK: We don't use composition view descriptors except for in initially empty nodes + { node: false } + ); + expect(pm.state.doc).toEqualNode(doc(p("!?foo"))); }); it("supports composition inside existing text", () => { - const { view } = tempEditor({ doc: doc(p("foo")) }); - insertComposition(view.dom); - expect(view.state.doc).toEqualNode(doc(p("féoo"))); + const { view: pm } = tempEditor({ doc: doc(p("foo")) }); + compose(pm, () => edit(findTextNode(pm.dom, "foo")!), [ + (n) => edit(n, "x", 1), + (n) => edit(n, "y", 2), + (n) => edit(n, "z", 3), + ]); + expect(pm.state.doc).toEqualNode(doc(p("fxyzoo"))); }); - // TODO: Deal with Android style compositions + // TODO: Offset out of bound // eslint-disable-next-line jest/no-disabled-tests - // it.skip("can deal with Android-style newline-after-composition", () => { - // const { view: pm } = tempEditor({ doc: doc(p("abcdef")) }); - // compose( - // pm, - // () => edit(findTextNode(pm.dom, "abcdef")!), - // [(n) => edit(n, "x", 3), (n) => edit(n, "y", 4)], - // { - // end: (n: Text) => { - // const line = pm.dom.appendChild(document.createElement("div")); - // line.textContent = "def"; - // n.nodeValue = "abcxy"; - // document.getSelection()!.collapse(line, 0); - // }, - // } - // ); - // expect(pm.state.doc).toEqualNode(doc(p("abcxy"), p("def"))); - // }); + it.skip("can deal with Android-style newline-after-composition", () => { + const { view: pm } = tempEditor({ doc: doc(p("abcdef")) }); + compose( + pm, + () => edit(findTextNode(pm.dom, "abcdef")!), + [(n) => edit(n, "x", 3), (n) => edit(n, "y", 4)], + { + end: (n: Text) => { + const line = pm.dom.appendChild(document.createElement("div")); + line.textContent = "def"; + n.nodeValue = "abcxy"; + document.getSelection()!.collapse(line, 0); + }, + } + ); + expect(pm.state.doc).toEqualNode(doc(p("abcxy"), p("def"))); + }); it("handles replacement of existing words", () => { - const { view } = tempEditor({ doc: doc(p("one two three")) }); - insertComposition(view.dom); - expect(view.state.doc).toEqualNode(doc(p("one é three"))); + const { view: pm } = tempEditor({ doc: doc(p("one two three")) }); + compose( + pm, + () => edit(findTextNode(pm.dom, "one two three")!, "five", 4, 7), + [(n) => edit(n, "seven", 4, 8), (n) => edit(n, "zero", 4, 9)] + ); + expect(pm.state.doc).toEqualNode(doc(p("one zero three"))); }); it("handles composition inside marks", () => { - const { view } = tempEditor({ doc: doc(p("one ", em("two"))) }); - insertComposition(view.dom); - expect(view.state.doc).toEqualNode(doc(p("one ", em("twoé")))); + const { view: pm } = tempEditor({ doc: doc(p("one ", em("two"))) }); + compose(pm, () => edit(findTextNode(pm.dom, "two")!, "o"), [ + (n) => edit(n, "o"), + (n) => edit(n, "w"), + ]); + expect(pm.state.doc).toEqualNode(doc(p("one ", em("twooow")))); }); - it("handles composition in a mark that has multiple children", () => { - const { view } = tempEditor({ - doc: doc(p("one ", em("two", strong(" three")))), + it.skip("handles composition in a mark that has multiple children", () => { + const { view: pm } = tempEditor({ + doc: doc(p("one ", em("two", strong(" three")))), }); - insertComposition(view.dom); - expect(view.state.doc).toEqualNode( - doc(p("one ", em("twoé", strong(" three")))) + compose(pm, () => edit(findTextNode(pm.dom, "two")!, "o"), [ + (n) => edit(n, "o"), + (n) => edit(n, "w"), + ]); + expect(pm.state.doc).toEqualNode( + doc(p("one ", em("twooow", strong(" three")))) ); }); - it("supports composition in a cursor wrapper", () => { - const { view } = tempEditor({ doc: doc(p("")) }); - view.dispatch(view.state.tr.addStoredMark(schema.marks.em!.create())); - insertComposition(view.dom); - expect(view.state.doc).toEqualNode(doc(p(em("é")))); - }); + // it("supports composition in a cursor wrapper", () => { + // const { view: pm } = tempEditor({ doc: doc(p("")) }); + // pm.dispatch(pm.state.tr.addStoredMark(schema.marks.em.create())); + // compose( + // pm, + // () => + // edit(pm.dom.firstChild!.appendChild(document.createTextNode("")), "a"), + // [(n) => edit(n, "b"), (n) => edit(n, "c")], + // { node: true } + // ); + // ist(pm.state.doc, doc(p(em("abc"))), eq); + // }); - it("handles composition in a multi-child mark with a cursor wrapper", () => { - const { view } = tempEditor({ - doc: doc(p("one ", em("two", strong(" three")))), - }); - view.dispatch(view.state.tr.addStoredMark(schema.marks.code!.create())); - insertComposition(view.dom); - expect(view.state.doc).toEqualNode( - doc(p("one ", em("two", code("é"), strong(" three")))) - ); - }); + // it("handles composition in a multi-child mark with a cursor wrapper", () => { + // const { view: pm } = requireFocus( + // tempEditor({ doc: doc(p("one ", em("two", strong(" three")))) }) + // ); + // pm.dispatch(pm.state.tr.addStoredMark(schema.marks.code.create())); + // const emNode = pm.dom.querySelector("em")!; + // compose( + // pm, + // () => + // edit( + // emNode.insertBefore( + // document.createTextNode(""), + // emNode.querySelector("strong") + // ), + // "o" + // ), + // [(n) => edit(n, "o"), (n) => edit(n, "w")], + // { node: true } + // ); + // ist( + // pm.state.doc, + // doc(p("one ", em("two", code("oow"), strong(" three")))), + // eq + // ); + // }); - it("doesn't get interrupted by changes in decorations", () => { - const { view } = tempEditor({ - doc: doc(p("foo ...")), - plugins: [wordHighlighter], - }); - insertComposition(view.dom); - expect(view.state.doc).toEqualNode(doc(p("foo é"))); - }); + // it("doesn't get interrupted by changes in decorations", () => { + // const { view: pm } = requireFocus( + // tempEditor({ doc: doc(p("foo ...")), plugins: [wordHighlighter] }) + // ); + // compose(pm, () => edit(findTextNode(pm.dom, " ...")!), [ + // (n) => edit(n, "hi", 1, 4), + // ]); + // ist(pm.state.doc, doc(p("foo hi")), eq); + // }); - it("works inside highlighted text", () => { - const { view } = tempEditor({ - doc: doc(p("one two")), - plugins: [wordHighlighter], - }); - insertComposition(view.dom); - expect(view.state.doc).toEqualNode(doc(p("oneé two"))); - }); + // it("works inside highlighted text", () => { + // const { view: pm } = requireFocus( + // tempEditor({ doc: doc(p("one two")), plugins: [wordHighlighter] }) + // ); + // compose(pm, () => edit(findTextNode(pm.dom, "one")!, "x"), [ + // (n) => edit(n, "y"), + // (n) => edit(n, "."), + // ]); + // ist(pm.state.doc, doc(p("onexy. two")), eq); + // }); // it("can handle compositions spanning multiple nodes", () => { // const { view: pm } = requireFocus( @@ -295,14 +313,25 @@ describe("EditorView composition", () => { // ist(pm.state.doc, doc(p("xyzone twoabc")), eq); // }); - it("doesn't overwrite widgets next to the composition", () => { - const { view } = tempEditor({ - doc: doc(p("")), - plugins: [widgets([1, 1], [-1, 1])], - }); - insertComposition(view.dom); - expect(view.state.doc).toEqualNode(doc(p("é"))); - }); + // it("doesn't overwrite widgets next to the composition", () => { + // const { view: pm } = requireFocus( + // tempEditor({ doc: doc(p("")), plugins: [widgets([1, 1], [-1, 1])] }) + // ); + // compose( + // pm, + // () => { + // const p = pm.dom.firstChild!; + // return edit(p.insertBefore(document.createTextNode("a"), p.lastChild)); + // }, + // [(n) => edit(n, "b", 0, 1)], + // { + // end: () => { + // ist(pm.dom.querySelectorAll("var").length, 2); + // }, + // } + // ); + // ist(pm.state.doc, doc(p("b")), eq); + // }); // it("cancels composition when a change fully overlaps with it", () => { // const { view: pm } = requireFocus( @@ -360,7 +389,7 @@ describe("EditorView composition", () => { // event(pm, "compositionstart"); // const one = findTextNode(pm.dom, "one")!; // edit(one, "!"); - // (pm as any).domObserver.flush(); + // pm.domObserver.flush(); // event(pm, "compositionend"); // one.nodeValue = "one!!"; // const L2 = pm.dom.lastChild; @@ -368,12 +397,12 @@ describe("EditorView composition", () => { // const two = findTextNode(pm.dom, "two")!; // ist(pm.dom.lastChild, L2); // edit(two, "."); - // (pm as any).domObserver.flush(); + // pm.domObserver.flush(); // ist(document.getSelection()!.focusNode, two); // ist(document.getSelection()!.focusOffset, 4); // ist(pm.composing); // event(pm, "compositionend"); - // (pm as any).domObserver.flush(); + // pm.domObserver.flush(); // ist(pm.state.doc, doc(p("one!!"), p("two.")), eq); // }); diff --git a/src/components/__tests__/ProseMirror.draw-decoration.test.tsx b/src/components/__tests__/ProseMirror.draw-decoration.test.tsx index dfa9e043..91c55950 100644 --- a/src/components/__tests__/ProseMirror.draw-decoration.test.tsx +++ b/src/components/__tests__/ProseMirror.draw-decoration.test.tsx @@ -36,13 +36,15 @@ import { tempEditor } from "../../testing/editorViewTestHelpers.js"; import { NodeViewComponentProps } from "../NodeViewComponentProps.js"; import { WidgetViewComponentProps } from "../WidgetViewComponentProps.js"; -const Widget = forwardRef(function Widget(props, ref) { - return ( - - ); -}); +const Widget = forwardRef( + function Widget({ widget, getPos, ...props }, ref) { + return ( + + ); + } +); function make(str: string | Decoration): Decoration { if (typeof str != "string") return str; @@ -94,8 +96,8 @@ describe("Decoration drawing", () => { plugins: [decoPlugin(["2-5-foo"])], }); const found = view.dom.querySelector(".foo")!; - expect(found).not.toBeNull(); - expect(found.textContent).toBe("oob"); + await expect(found).not.toBeNull(); + await expect(found.textContent).toBe("oob"); }); it("draws wrapping decorations", async () => { @@ -183,7 +185,7 @@ describe("Decoration drawing", () => { widget( 4, forwardRef(function B( - props, + { widget, getPos, ...props }, ref ) { return ( @@ -197,7 +199,7 @@ describe("Decoration drawing", () => { widget( 4, forwardRef(function A( - props, + { widget, getPos, ...props }, ref ) { return ( @@ -211,7 +213,7 @@ describe("Decoration drawing", () => { widget( 4, forwardRef(function C( - props, + { widget, getPos, ...props }, ref ) { return ( @@ -254,8 +256,8 @@ describe("Decoration drawing", () => { it("calls widget destroy methods", async () => { let destroyed = false; - const DestroyableWidget = forwardRef( - function DestroyableWidget(props, ref) { + const DestroyableWidget = forwardRef( + function DestroyableWidget({ widget, getPos, ...props }, ref) { useEffect(() => { destroyed = true; }); @@ -587,7 +589,7 @@ describe("Decoration drawing", () => { widget( 4, forwardRef(function Img( - props, + { widget, getPos, ...props }, ref ) { return ( @@ -613,7 +615,7 @@ describe("Decoration drawing", () => { widget( 4, forwardRef(function Img( - props, + { widget, getPos, ...props }, ref ) { return ( @@ -627,7 +629,7 @@ describe("Decoration drawing", () => { widget( 4, forwardRef(function BR( - props, + { widget, getPos, ...props }, ref ) { return
} />; @@ -639,7 +641,7 @@ describe("Decoration drawing", () => { widget( 7, forwardRef( - function Span(props, ref) { + function Span({ widget, getPos, ...props }, ref) { return ; } ), @@ -674,7 +676,7 @@ describe("Decoration drawing", () => { widget( 2, forwardRef(function Img( - props, + { widget, getPos, ...props }, ref ) { return ( @@ -697,7 +699,7 @@ describe("Decoration drawing", () => { widget( 3, forwardRef(function Span( - props, + { widget, getPos, ...props }, ref ) { useEditorEffect((view) => { @@ -726,10 +728,10 @@ describe("Decoration drawing", () => { 3, forwardRef( function Widget( - { pos, ...props }: WidgetViewComponentProps, + { widget, getPos, ...props }: WidgetViewComponentProps, ref ) { - expect(pos).toBe(3); + expect(getPos()).toBe(3); return ( + ); + } + ), + }, + }); + + const button = screen.getByText("Click me"); + await $("#button").click(); + expect(document.activeElement === button).toBeTruthy(); + }); }); diff --git a/src/contexts/ChildDescriptorsContext.ts b/src/contexts/ChildDescriptorsContext.ts index b6f71b15..4c94ebcf 100644 --- a/src/contexts/ChildDescriptorsContext.ts +++ b/src/contexts/ChildDescriptorsContext.ts @@ -1,5 +1,13 @@ -import { createContext } from "react"; +import { MutableRefObject, createContext } from "react"; import { ViewDesc } from "../viewdesc.js"; -export const ChildDescriptorsContext = createContext([]); +export const ChildDescriptorsContext = createContext<{ + parentRef: MutableRefObject; + siblingsRef: MutableRefObject; +}>({ + parentRef: { current: undefined }, + siblingsRef: { + current: [], + }, +}); diff --git a/src/contexts/EditorContext.ts b/src/contexts/EditorContext.ts index 1534b07e..866a50f6 100644 --- a/src/contexts/EditorContext.ts +++ b/src/contexts/EditorContext.ts @@ -1,4 +1,3 @@ -import type { EditorState } from "prosemirror-state"; import type { DOMEventMap, EditorView } from "prosemirror-view"; import { createContext } from "react"; @@ -6,7 +5,6 @@ import type { EventHandler } from "../plugins/componentEventListeners"; export interface EditorContextValue { view: EditorView | null; - state: EditorState; registerEventListener( eventType: EventType, handler: EventHandler diff --git a/src/contexts/EditorStateContext.ts b/src/contexts/EditorStateContext.ts new file mode 100644 index 00000000..31edf8dd --- /dev/null +++ b/src/contexts/EditorStateContext.ts @@ -0,0 +1,6 @@ +import { EditorState } from "prosemirror-state"; +import { createContext } from "react"; + +export const EditorStateContext = createContext( + null as unknown as EditorState +); diff --git a/src/contexts/SelectNodeContext.ts b/src/contexts/SelectNodeContext.ts new file mode 100644 index 00000000..49a40d91 --- /dev/null +++ b/src/contexts/SelectNodeContext.ts @@ -0,0 +1,10 @@ +import { createContext } from "react"; + +type SelectNodeContextValue = ( + selectNode: () => void, + deselectNode: () => void +) => void; + +export const SelectNodeContext = createContext( + null as unknown as SelectNodeContextValue +); diff --git a/src/decorations/computeDocDeco.ts b/src/decorations/computeDocDeco.ts index 82eb5ef0..bd43fc1e 100644 --- a/src/decorations/computeDocDeco.ts +++ b/src/decorations/computeDocDeco.ts @@ -1,5 +1,18 @@ import { Decoration, EditorView } from "prosemirror-view"; +const DocDecorationsCache = new WeakMap(); + +/** + * Produces the outer decorations for the doc node, based + * on the attributes editor prop. + * + * The return value of this function is memoized; if it is to + * return an equivalent value to the last time it was called for + * a given EditorView, it will return exactly that previous value. + * + * This makes it safe to call in a React render function, even + * if its result is used in a dependencies array for a hook. + */ export function computeDocDeco(view: EditorView) { const attrs = Object.create(null); attrs.class = "ProseMirror"; @@ -22,5 +35,26 @@ export function computeDocDeco(view: EditorView) { }); if (!attrs.translate) attrs.translate = "no"; - return [Decoration.node(0, view.state.doc.content.size, attrs)]; + const next: [Decoration] = [ + Decoration.node(0, view.state.doc.content.size, attrs), + ]; + + const previous = DocDecorationsCache.get(view); + if (!previous) { + DocDecorationsCache.set(view, next); + return next; + } + + if (previous[0].to !== view.state.doc.content.size) { + DocDecorationsCache.set(view, next); + return next; + } + + // @ts-expect-error Internal property (Decoration.type) + if (!previous[0].type.eq(next[0].type)) { + DocDecorationsCache.set(view, next); + return next; + } + + return previous; } diff --git a/src/decorations/viewDecorations.tsx b/src/decorations/viewDecorations.tsx index 4e2f3159..14d220b9 100644 --- a/src/decorations/viewDecorations.tsx +++ b/src/decorations/viewDecorations.tsx @@ -179,6 +179,19 @@ function insertAhead(array: Decoration[], i: number, deco: Decoration) { array.splice(i, 0, deco); } +const ViewDecorationsCache = new WeakMap(); + +/** + * Produces the DecorationSource for the current state, based + * on the decorations editor prop. + * + * The return value of this function is memoized; if it is to + * return an equivalent value to the last time it was called for + * a given EditorView, it will return exactly that previous value. + * + * This makes it safe to call in a React render function, even + * if its result is used in a dependencies array for a hook. + */ export function viewDecorations( view: EditorView, cursorWrapper: Decoration | null @@ -196,5 +209,27 @@ export function viewDecorations( DecorationSet.create(view.state.doc, [cursorWrapper]) ); } - return DecorationGroup.from(found); + const previous = ViewDecorationsCache.get(view); + if (!previous) { + const result = DecorationGroup.from(found); + ViewDecorationsCache.set(view, result); + return result; + } + let numPrevious = 0; + let areSetsEqual = true; + previous.forEachSet((set) => { + const next = found[numPrevious++]; + if (next !== set) { + areSetsEqual = false; + } + }); + if (numPrevious !== found.length) { + areSetsEqual = false; + } + if (!areSetsEqual) { + const result = DecorationGroup.from(found); + ViewDecorationsCache.set(view, result); + return result; + } + return previous; } diff --git a/src/hooks/__tests__/useEditorViewLayoutEffect.test.tsx b/src/hooks/__tests__/useEditorViewLayoutEffect.test.tsx index de8991be..fb40191a 100644 --- a/src/hooks/__tests__/useEditorViewLayoutEffect.test.tsx +++ b/src/hooks/__tests__/useEditorViewLayoutEffect.test.tsx @@ -6,6 +6,7 @@ import React from "react"; import { LayoutGroup } from "../../components/LayoutGroup.js"; import { EditorContext } from "../../contexts/EditorContext.js"; +import { EditorStateContext } from "../../contexts/EditorStateContext.js"; import { useEditorEffect } from "../useEditorEffect.js"; function TestComponent({ @@ -15,7 +16,8 @@ function TestComponent({ effect: () => void; dependencies?: unknown[]; }) { - useEditorEffect(effect, [effect, ...dependencies]); + // eslint-disable-next-line react-hooks/exhaustive-deps + useEditorEffect(effect, dependencies); return null; } @@ -32,12 +34,13 @@ describe("useEditorViewLayoutEffect", () => { - + + + ); @@ -53,32 +56,28 @@ describe("useEditorViewLayoutEffect", () => { const registerEventListener = () => {}; const unregisterEventListener = () => {}; + const contextValue = { + view: editorView, + registerEventListener, + unregisterEventListener, + }; + const { rerender } = render( - - + + + + {" "} ); rerender( - - + + + + ); @@ -98,12 +97,13 @@ describe("useEditorViewLayoutEffect", () => { - + + + ); @@ -113,12 +113,13 @@ describe("useEditorViewLayoutEffect", () => { - + + + ); diff --git a/src/hooks/useEditor.ts b/src/hooks/useEditor.ts index c372c70c..73132024 100644 --- a/src/hooks/useEditor.ts +++ b/src/hooks/useEditor.ts @@ -48,6 +48,17 @@ function changedNodeViews(a: NodeViewSet, b: NodeViewSet) { return nA != nB; } +function changedProps(a: DirectEditorProps, b: DirectEditorProps) { + for (const prop of Object.keys(a) as (keyof DirectEditorProps)[]) { + if (a[prop] !== b[prop]) return true; + } + return false; +} + +function getEditable(view: ReactEditorView) { + return !view.someProp("editable", (value) => value(view.state) === false); +} + // @ts-expect-error We're making use of knowledge of internal methods here export class ReactEditorView extends EditorView { private shouldUpdatePluginViews = false; @@ -88,7 +99,7 @@ export class ReactEditorView extends EditorView { // @ts-expect-error We're making use of knowledge of internal attributes here this.domObserver.start(); - // updateCursorWrapper(this); + this.editable = getEditable(this); // Destroy the DOM created by the default // ProseMirror ViewDesc implementation; we @@ -137,6 +148,8 @@ export class ReactEditorView extends EditorView { ...props, }; this.state = this._props.state; + + this.editable = getEditable(this); } /** @@ -144,10 +157,12 @@ export class ReactEditorView extends EditorView { * calls to pureSetProps. */ runPendingEffects() { - const newProps = this.props; - this._props = this.oldProps; - this.state = this._props.state; - this.update(newProps); + if (changedProps(this.props, this.oldProps)) { + const newProps = this.props; + this._props = this.oldProps; + this.state = this._props.state; + this.update(newProps); + } } update(props: DirectEditorProps) { @@ -254,17 +269,20 @@ export function useEditor( [options.plugins, componentEventListenersPlugin, setCursorWrapper] ); - function dispatchTransaction(this: EditorView, tr: Transaction) { - flushSync(() => { - if (!options.state) { - setState((s) => s.apply(tr)); - } - - if (options.dispatchTransaction) { - options.dispatchTransaction.call(this, tr); - } - }); - } + const dispatchTransaction = useCallback( + function dispatchTransaction(this: EditorView, tr: Transaction) { + flushSync(() => { + if (!options.state) { + setState((s) => s.apply(tr)); + } + + if (options.dispatchTransaction) { + options.dispatchTransaction.call(this, tr); + } + }); + }, + [options.dispatchTransaction, options.state] + ); const tempDom = document.createElement("div"); @@ -272,13 +290,20 @@ export function useEditor( new NodeViewDesc( undefined, [], + () => -1, state.doc, [], DecorationSet.empty, tempDom, null, tempDom, - () => false + () => false, + () => { + /* The doc node can't have a node selection*/ + }, + () => { + /* The doc node can't have a node selection*/ + } ) ); @@ -338,15 +363,16 @@ export function useEditor( view?.pureSetProps(directEditorProps); - return useMemo( + const editor = useMemo( () => ({ view: view as EditorView | null, - state: state, registerEventListener, unregisterEventListener, cursorWrapper, docViewDescRef, }), - [view, state, registerEventListener, unregisterEventListener, cursorWrapper] + [view, registerEventListener, unregisterEventListener, cursorWrapper] ); + + return { editor, state }; } diff --git a/src/hooks/useEditorState.ts b/src/hooks/useEditorState.ts index 0202491f..ad3a7cf4 100644 --- a/src/hooks/useEditorState.ts +++ b/src/hooks/useEditorState.ts @@ -1,13 +1,13 @@ import type { EditorState } from "prosemirror-state"; import { useContext } from "react"; -import { EditorContext } from "../contexts/EditorContext.js"; +import { EditorStateContext } from "../contexts/EditorStateContext.js"; /** * Provides access to the current EditorState value. */ export function useEditorState(): EditorState { - const { state: editorState } = useContext(EditorContext); + const editorState = useContext(EditorStateContext); return editorState; } diff --git a/src/hooks/useNodeViewDescriptor.ts b/src/hooks/useNodeViewDescriptor.ts index 7a1de37e..d588e912 100644 --- a/src/hooks/useNodeViewDescriptor.ts +++ b/src/hooks/useNodeViewDescriptor.ts @@ -6,13 +6,21 @@ import { useContext, useLayoutEffect, useRef, + useState, } from "react"; import { ChildDescriptorsContext } from "../contexts/ChildDescriptorsContext.js"; -import { NodeViewDesc, ViewDesc } from "../viewdesc.js"; +import { EditorContext } from "../contexts/EditorContext.js"; +import { + CompositionViewDesc, + NodeViewDesc, + ViewDesc, + sortViewDescs, +} from "../viewdesc.js"; export function useNodeViewDescriptor( node: Node | undefined, + getPos: () => number, domRef: undefined | MutableRefObject, nodeDomRef: MutableRefObject, innerDecorations: DecorationSource, @@ -20,6 +28,8 @@ export function useNodeViewDescriptor( viewDesc?: NodeViewDesc, contentDOMRef?: MutableRefObject ) { + const { view } = useContext(EditorContext); + const [hasContentDOM, setHasContentDOM] = useState(true); const nodeViewDescRef = useRef(viewDesc); const stopEvent = useRef<(event: Event) => boolean | undefined>(() => false); const setStopEvent = useCallback( @@ -28,30 +38,70 @@ export function useNodeViewDescriptor( }, [] ); - const siblingDescriptors = useContext(ChildDescriptorsContext); - const childDescriptors: ViewDesc[] = []; + const selectNode = useRef<() => void>(() => { + if (!nodeDomRef.current || !node) return; + if (nodeDomRef.current.nodeType == 1) + nodeDomRef.current.classList.add("ProseMirror-selectednode"); + if (contentDOMRef?.current || !node.type.spec.draggable) + (domRef?.current ?? nodeDomRef.current).draggable = true; + }); + const deselectNode = useRef<() => void>(() => { + if (!nodeDomRef.current || !node) return; + if (nodeDomRef.current.nodeType == 1) { + (nodeDomRef.current as HTMLElement).classList.remove( + "ProseMirror-selectednode" + ); + if (contentDOMRef?.current || !node.type.spec.draggable) + (domRef?.current ?? nodeDomRef.current).removeAttribute("draggable"); + } + }); + const setSelectNode = useCallback( + (newSelectNode: () => void, newDeselectNode: () => void) => { + selectNode.current = newSelectNode; + deselectNode.current = newDeselectNode; + }, + [] + ); + const { siblingsRef, parentRef } = useContext(ChildDescriptorsContext); + const childDescriptors = useRef([]); + + useLayoutEffect(() => { + const siblings = siblingsRef.current; + return () => { + if (!nodeViewDescRef.current) return; + if (siblings.includes(nodeViewDescRef.current)) { + const index = siblings.indexOf(nodeViewDescRef.current); + siblings.splice(index, 1); + } + }; + }, [siblingsRef]); + // eslint-disable-next-line react-hooks/exhaustive-deps useLayoutEffect(() => { if (!node || !nodeDomRef.current) return; - const firstChildDesc = childDescriptors[0]; + const firstChildDesc = childDescriptors.current[0]; if (!nodeViewDescRef.current) { nodeViewDescRef.current = new NodeViewDesc( - undefined, - childDescriptors, + parentRef.current, + childDescriptors.current, + getPos, node, outerDecorations, innerDecorations, domRef?.current ?? nodeDomRef.current, firstChildDesc?.dom.parentElement ?? null, nodeDomRef.current, - (event) => !!stopEvent.current(event) + (event) => !!stopEvent.current(event), + () => selectNode.current(), + () => deselectNode.current() ); } else { - nodeViewDescRef.current.parent = undefined; - nodeViewDescRef.current.children = childDescriptors; + nodeViewDescRef.current.parent = parentRef.current; + nodeViewDescRef.current.children = childDescriptors.current; nodeViewDescRef.current.node = node; + nodeViewDescRef.current.getPos = getPos; nodeViewDescRef.current.outerDeco = outerDecorations; nodeViewDescRef.current.innerDeco = innerDecorations; nodeViewDescRef.current.dom = domRef?.current ?? nodeDomRef.current; @@ -68,12 +118,65 @@ export function useNodeViewDescriptor( null; nodeViewDescRef.current.nodeDOM = nodeDomRef.current; } - siblingDescriptors.push(nodeViewDescRef.current); + setHasContentDOM(nodeViewDescRef.current.contentDOM !== null); - for (const childDesc of childDescriptors) { + if (!siblingsRef.current.includes(nodeViewDescRef.current)) { + siblingsRef.current.push(nodeViewDescRef.current); + } + + siblingsRef.current.sort(sortViewDescs); + + for (const childDesc of childDescriptors.current) { childDesc.parent = nodeViewDescRef.current; + + // Because TextNodeViews can't locate the DOM nodes + // for compositions, we need to override them here + if (childDesc instanceof CompositionViewDesc) { + const compositionTopDOM = + nodeViewDescRef.current.contentDOM?.firstChild; + if (!compositionTopDOM) + throw new Error( + `Started a composition but couldn't find the text node it belongs to.` + ); + + let textDOM = compositionTopDOM; + while (textDOM.firstChild) { + textDOM = textDOM.firstChild as Element | Text; + } + + if (!textDOM || !(textDOM instanceof Text)) + throw new Error( + `Started a composition but couldn't find the text node it belongs to.` + ); + + childDesc.dom = compositionTopDOM; + childDesc.textDOM = textDOM; + childDesc.text = textDOM.data; + // @ts-expect-error ??? + childDesc.textDOM.pmViewDesc = childDesc; + + // @ts-expect-error ??? + view?.input.compositionNodes.push(childDesc); + } } + + return () => { + if ( + nodeViewDescRef.current?.children[0] instanceof CompositionViewDesc && + !view?.composing + ) { + nodeViewDescRef.current?.children[0].dom.parentNode?.removeChild( + nodeViewDescRef.current?.children[0].dom + ); + } + }; }); - return { childDescriptors, setStopEvent }; + return { + hasContentDOM, + childDescriptors, + nodeViewDescRef, + setStopEvent, + setSelectNode, + }; } diff --git a/src/hooks/useReactKeys.ts b/src/hooks/useReactKeys.ts index cb5b7fdd..0f3b9b97 100644 --- a/src/hooks/useReactKeys.ts +++ b/src/hooks/useReactKeys.ts @@ -1,8 +1,9 @@ -import { reactKeysPluginKey } from "../plugins/reactKeys.js"; +import { useContext } from "react"; -import { useEditorState } from "./useEditorState.js"; +import { EditorContext } from "../contexts/EditorContext.js"; +import { reactKeysPluginKey } from "../plugins/reactKeys.js"; export function useReactKeys() { - const state = useEditorState(); - return reactKeysPluginKey.getState(state); + const { view } = useContext(EditorContext); + return view && reactKeysPluginKey.getState(view.state); } diff --git a/src/hooks/useSelectNode.ts b/src/hooks/useSelectNode.ts new file mode 100644 index 00000000..f92f1a5d --- /dev/null +++ b/src/hooks/useSelectNode.ts @@ -0,0 +1,23 @@ +import { useContext } from "react"; + +import { SelectNodeContext } from "../contexts/SelectNodeContext.js"; + +import { useEditorEffect } from "./useEditorEffect.js"; +import { useEditorEventCallback } from "./useEditorEventCallback.js"; + +export function useSelectNode( + selectNode: () => void, + deselectNode?: () => void +) { + const register = useContext(SelectNodeContext); + const selectNodeMemo = useEditorEventCallback(selectNode); + const deselectNodeMemo = useEditorEventCallback( + deselectNode ?? + (() => { + // empty + }) + ); + return useEditorEffect(() => { + register(selectNodeMemo, deselectNodeMemo); + }, [deselectNodeMemo, register, selectNodeMemo]); +} diff --git a/src/index.ts b/src/index.ts index 8b4f9bda..3e190da4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,6 +7,7 @@ export { useEditorEventCallback } from "./hooks/useEditorEventCallback.js"; export { useEditorEventListener } from "./hooks/useEditorEventListener.js"; export { useEditorState } from "./hooks/useEditorState.js"; export { useStopEvent } from "./hooks/useStopEvent.js"; +export { useSelectNode } from "./hooks/useSelectNode.js"; export { reactKeys } from "./plugins/reactKeys.js"; export { widget } from "./decorations/ReactWidgetType.js"; diff --git a/src/plugins/reactKeys.ts b/src/plugins/reactKeys.ts index dc2e53c8..bb1438e8 100644 --- a/src/plugins/reactKeys.ts +++ b/src/plugins/reactKeys.ts @@ -2,7 +2,7 @@ import { Node } from "prosemirror-model"; import { Plugin, PluginKey } from "prosemirror-state"; export function createNodeKey() { - const key = Math.floor(Math.random() * 0xffffff).toString(16); + const key = Math.floor(Math.random() * 0xffffffffffff).toString(16); return key; } @@ -39,11 +39,12 @@ export function reactKeys() { return next; }, /** - * Keeps node keys (mostly) stable across transactions. + * Keeps node keys stable across transactions. * - * To accomplish this, we map each node position backwards - * through the transaction to identify its previous position, - * and thereby retrieve its previous key. + * To accomplish this, we map each node position forwards + * through the transaction to identify its current position, + * and assign its key to that new position, dropping it if the + * node was deleted. */ apply(tr, value, _, newState) { if (!tr.docChanged || composing) return value; diff --git a/src/selection/selectionFromDOM.ts b/src/selection/selectionFromDOM.ts index a821559d..a3db372c 100644 --- a/src/selection/selectionFromDOM.ts +++ b/src/selection/selectionFromDOM.ts @@ -25,16 +25,17 @@ export function selectionFromDOM( const domSel = view.domSelectionRange(), doc = view.state.doc; if (!domSel.focusNode) return null; - // @ts-expect-error Internel property + // @ts-expect-error Internal method let nearestDesc = view.docView.nearestDesc(domSel.focusNode); const inWidget = nearestDesc && nearestDesc.size == 0; - // @ts-expect-error Internel property - const head = view.docView.posFromDOM(domSel.focusNode, domSel.focusOffset, 1); + // @ts-expect-error Internal method + let head = view.docView.posFromDOM(domSel.focusNode, domSel.focusOffset, 1); if (head < 0) return null; - const $head = doc.resolve(head); - let $anchor, selection; + let $head = doc.resolve(head), + anchor, + selection; if (selectionCollapsed(domSel)) { - $anchor = $head; + anchor = head; while (nearestDesc && !nearestDesc.node) nearestDesc = nearestDesc.parent; const nearestDescNode = (nearestDesc as NodeViewDesc).node; if ( @@ -51,16 +52,42 @@ export function selectionFromDOM( selection = new NodeSelection(head == pos ? $head : doc.resolve(pos)); } } else { - // @ts-expect-error Internal property - const anchor = view.docView.posFromDOM( + if ( // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - domSel.anchorNode!, - domSel.anchorOffset, - 1 - ); + domSel instanceof view.dom.ownerDocument.defaultView!.Selection && + domSel.rangeCount > 1 + ) { + let min = head, + max = head; + for (let i = 0; i < domSel.rangeCount; i++) { + const range = domSel.getRangeAt(i); + min = Math.min( + min, + // @ts-expect-error Internal method + view.docView.posFromDOM(range.startContainer, range.startOffset, 1) + ); + max = Math.max( + max, + // @ts-expect-error Internal method + view.docView.posFromDOM(range.endContainer, range.endOffset, -1) + ); + } + if (min < 0) return null; + [anchor, head] = + max == view.state.selection.anchor ? [max, min] : [min, max]; + $head = doc.resolve(head); + } else { + // @ts-expect-error Internal method + anchor = view.docView.posFromDOM( + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + domSel.anchorNode!, + domSel.anchorOffset, + 1 + ); + } if (anchor < 0) return null; - $anchor = doc.resolve(anchor); } + const $anchor = doc.resolve(anchor); if (!selection) { const bias = diff --git a/src/testing/editorViewTestHelpers.tsx b/src/testing/editorViewTestHelpers.tsx index 0bdd53db..75d16716 100644 --- a/src/testing/editorViewTestHelpers.tsx +++ b/src/testing/editorViewTestHelpers.tsx @@ -9,6 +9,7 @@ import React from "react"; import { Props, ProseMirror } from "../components/ProseMirror.js"; import { ProseMirrorDoc } from "../components/ProseMirrorDoc.js"; +import { DOMNode } from "../dom.js"; import { useEditorEffect } from "../hooks/useEditorEffect.js"; import { reactKeys } from "../plugins/reactKeys.js"; @@ -53,7 +54,7 @@ export function tempEditor({ controlled?: boolean; } & Omit): { view: EditorViewT; - rerender: (props: Omit) => void; + rerender: (props?: Omit) => void; unmount: () => void; } { startDoc = startDoc ?? doc(p()); @@ -88,7 +89,9 @@ export function tempEditor({ ); - function rerenderEditor({ ...newProps }: Omit) { + function rerenderEditor({ + ...newProps + }: Omit = {}) { rerender( number, public dom: DOMNode, // This is the node that holds the child views. It may be null for // descs that don't have children. @@ -628,10 +635,11 @@ export class ViewDesc { export class WidgetViewDesc extends ViewDesc { constructor( parent: ViewDesc | undefined, - readonly widget: Decoration, + getPos: () => number, + public widget: Decoration, dom: DOMNode ) { - super(parent, [], dom, null); + super(parent, [], getPos, dom, null); this.widget = widget; } @@ -669,11 +677,12 @@ export class WidgetViewDesc extends ViewDesc { export class CompositionViewDesc extends ViewDesc { constructor( parent: ViewDesc | undefined, + getPos: () => number, dom: DOMNode, public textDOM: Text, public text: string ) { - super(parent, [], dom, null); + super(parent, [], getPos, dom, null); } get size() { @@ -703,11 +712,12 @@ export class MarkViewDesc extends ViewDesc { constructor( parent: ViewDesc | undefined, children: ViewDesc[], - readonly mark: Mark, + getPos: () => number, + public mark: Mark, dom: DOMNode, contentDOM: HTMLElement ) { - super(parent, children, dom, contentDOM); + super(parent, children, getPos, dom, contentDOM); } parseRule() { @@ -743,15 +753,18 @@ export class NodeViewDesc extends ViewDesc { constructor( parent: ViewDesc | undefined, children: ViewDesc[], + getPos: () => number, public node: Node, public outerDeco: readonly Decoration[], public innerDeco: DecorationSource, dom: DOMNode, contentDOM: HTMLElement | null, public nodeDOM: DOMNode, - public stopEvent: (event: Event) => boolean + public stopEvent: (event: Event) => boolean, + public selectNode: () => void, + public deselectNode: () => void ) { - super(parent, children, dom, contentDOM); + super(parent, children, getPos, dom, contentDOM); } updateOuterDeco() { @@ -824,25 +837,6 @@ export class NodeViewDesc extends ViewDesc { return true; } - // Mark this node as being the selected node. - selectNode() { - if (this.nodeDOM.nodeType == 1) - (this.nodeDOM as HTMLElement).classList.add("ProseMirror-selectednode"); - if (this.contentDOM || !this.node.type.spec.draggable) - (this.dom as HTMLElement).draggable = true; - } - - // Remove selected node marking from this node. - deselectNode() { - if (this.nodeDOM.nodeType == 1) { - (this.nodeDOM as HTMLElement).classList.remove( - "ProseMirror-selectednode" - ); - if (this.contentDOM || !this.node.type.spec.draggable) - (this.dom as HTMLElement).removeAttribute("draggable"); - } - } - get domAtom() { return this.node.isAtom; } @@ -852,6 +846,7 @@ export class TextViewDesc extends NodeViewDesc { constructor( parent: ViewDesc | undefined, children: ViewDesc[], + getPos: () => number, node: Node, outerDeco: readonly Decoration[], innerDeco: DecorationSource, @@ -861,13 +856,20 @@ export class TextViewDesc extends NodeViewDesc { super( parent, children, + getPos, node, outerDeco, innerDeco, dom, null, nodeDOM, - () => false + () => false, + () => { + /* Text nodes can't have node selections */ + }, + () => { + /* Text nodes can't have node selections */ + } ); } diff --git a/wdio.conf.ts b/wdio.conf.ts index 6f1ccbaa..87342cbb 100644 --- a/wdio.conf.ts +++ b/wdio.conf.ts @@ -129,13 +129,13 @@ export const config: WebdriverIO.Config = { // Test reporter for stdout. // The only one supported by default is 'dot' // see also: https://webdriver.io/docs/dot-reporter - // reporters: ['dot'], + reporters: ["spec"], // Options to be passed to Mocha. // See the full list at http://mochajs.org/ mochaOpts: { ui: "bdd", - timeout: 3600000, + timeout: 60000, }, // diff --git a/yarn.lock b/yarn.lock index d2fda0d5..213658d1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1944,7 +1944,9 @@ __metadata: "@vitejs/plugin-react": ^4.3.1 "@wdio/browser-runner": ^9.0.9 "@wdio/cli": ^9.0.9 + "@wdio/dot-reporter": ^9.1.0 "@wdio/mocha-framework": ^9.0.8 + "@wdio/spec-reporter": ^9.1.0 "@wdio/types": ^9.0.8 "@yarnpkg/sdks": ^3.0.0-rc.38 classnames: ^2.3.2 @@ -3251,6 +3253,17 @@ __metadata: languageName: node linkType: hard +"@wdio/dot-reporter@npm:^9.1.0": + version: 9.1.0 + resolution: "@wdio/dot-reporter@npm:9.1.0" + dependencies: + "@wdio/reporter": 9.1.0 + "@wdio/types": 9.1.0 + chalk: ^5.0.1 + checksum: 7bea6e022b8de1fd4509f4bd34d0460923628bed68928fd383f4bcb7d2005e4476cafa186ca609756035f338ba83ffbc48602f3173dd11c9200e2d0698a1451f + languageName: node + linkType: hard + "@wdio/globals@npm:9.0.9": version: 9.0.9 resolution: "@wdio/globals@npm:9.0.9" @@ -3294,6 +3307,18 @@ __metadata: languageName: node linkType: hard +"@wdio/logger@npm:9.1.0": + version: 9.1.0 + resolution: "@wdio/logger@npm:9.1.0" + dependencies: + chalk: ^5.1.2 + loglevel: ^1.6.0 + loglevel-plugin-prefix: ^0.8.4 + strip-ansi: ^7.1.0 + checksum: 52c3574c644fbc623565e913d0cb943bd45284148f4c93b378b3dc835a8d9e263680310f190ab240e76f60f00d6254e1063cc3a7db38ec7cfcf6dc7797a9e434 + languageName: node + linkType: hard + "@wdio/logger@npm:^8.38.0": version: 8.38.0 resolution: "@wdio/logger@npm:8.38.0" @@ -3336,6 +3361,19 @@ __metadata: languageName: node linkType: hard +"@wdio/reporter@npm:9.1.0": + version: 9.1.0 + resolution: "@wdio/reporter@npm:9.1.0" + dependencies: + "@types/node": ^20.1.0 + "@wdio/logger": 9.1.0 + "@wdio/types": 9.1.0 + diff: ^7.0.0 + object-inspect: ^1.12.0 + checksum: 6afb1984c8f437e5c88e213fc1c857c29c873599f9375c4e859c86fe97a85cd95050ee363db039a5b55e1598f6ab13a3577db4775698215ba1b748fe8fa236c6 + languageName: node + linkType: hard + "@wdio/runner@npm:9.0.9": version: 9.0.9 resolution: "@wdio/runner@npm:9.0.9" @@ -3355,6 +3393,19 @@ __metadata: languageName: node linkType: hard +"@wdio/spec-reporter@npm:^9.1.0": + version: 9.1.0 + resolution: "@wdio/spec-reporter@npm:9.1.0" + dependencies: + "@wdio/reporter": 9.1.0 + "@wdio/types": 9.1.0 + chalk: ^5.1.2 + easy-table: ^1.2.0 + pretty-ms: ^9.0.0 + checksum: 9c74032d8ec9259e89e057dc310f71f8af84d50ecada98e29fb8ccea4643c1a1a746c4873d5365475e79749bbe4ccbe443f9d24bf31ae8f22dfdabc1f0cdcc72 + languageName: node + linkType: hard + "@wdio/types@npm:9.0.8, @wdio/types@npm:^9.0.8": version: 9.0.8 resolution: "@wdio/types@npm:9.0.8" @@ -3364,6 +3415,15 @@ __metadata: languageName: node linkType: hard +"@wdio/types@npm:9.1.0": + version: 9.1.0 + resolution: "@wdio/types@npm:9.1.0" + dependencies: + "@types/node": ^20.1.0 + checksum: 14632e3b4dd041d5ccacace3e333ddc1854853ddae853dc6a846601fb7da1d31003f3a1b66afda45e943af0b42537f80e30375def810e946318343f15769f3f4 + languageName: node + linkType: hard + "@wdio/utils@npm:9.0.8": version: 9.0.8 resolution: "@wdio/utils@npm:9.0.8" @@ -4368,7 +4428,7 @@ __metadata: languageName: node linkType: hard -"chalk@npm:^5.1.2, chalk@npm:^5.2.0": +"chalk@npm:^5.0.1, chalk@npm:^5.1.2, chalk@npm:^5.2.0": version: 5.3.0 resolution: "chalk@npm:5.3.0" checksum: 623922e077b7d1e9dedaea6f8b9e9352921f8ae3afe739132e0e00c275971bdd331268183b2628cf4ab1727c45ea1f28d7e24ac23ce1db1eb653c414ca8a5a80 @@ -4570,6 +4630,13 @@ __metadata: languageName: node linkType: hard +"clone@npm:^1.0.2": + version: 1.0.4 + resolution: "clone@npm:1.0.4" + checksum: d06418b7335897209e77bdd430d04f882189582e67bd1f75a04565f3f07f5b3f119a9d670c943b6697d0afb100f03b866b3b8a1f91d4d02d72c4ecf2bb64b5dd + languageName: node + linkType: hard + "co@npm:^4.6.0": version: 4.6.0 resolution: "co@npm:4.6.0" @@ -5046,6 +5113,15 @@ __metadata: languageName: node linkType: hard +"defaults@npm:^1.0.3": + version: 1.0.4 + resolution: "defaults@npm:1.0.4" + dependencies: + clone: ^1.0.2 + checksum: 3a88b7a587fc076b84e60affad8b85245c01f60f38fc1d259e7ac1d89eb9ce6abb19e27215de46b98568dd5bc48471730b327637e6f20b0f1bc85cf00440c80a + languageName: node + linkType: hard + "defer-to-connect@npm:^2.0.0": version: 2.0.1 resolution: "defer-to-connect@npm:2.0.1" @@ -5172,6 +5248,13 @@ __metadata: languageName: node linkType: hard +"diff@npm:^7.0.0": + version: 7.0.0 + resolution: "diff@npm:7.0.0" + checksum: 5db0d339476b18dfbc8a08a7504fbcc74789eec626c8d20cf2cdd1871f1448962888128f4447c8f50a1e41a80decfe5e8489c375843b8cf1d42b7c2b611da4e1 + languageName: node + linkType: hard + "dir-glob@npm:^3.0.1": version: 3.0.1 resolution: "dir-glob@npm:3.0.1" @@ -5267,6 +5350,19 @@ __metadata: languageName: node linkType: hard +"easy-table@npm:^1.2.0": + version: 1.2.0 + resolution: "easy-table@npm:1.2.0" + dependencies: + ansi-regex: ^5.0.1 + wcwidth: ^1.0.1 + dependenciesMeta: + wcwidth: + optional: true + checksum: 66961b19751a68d2d30ce9b74ef750c374cc3112bbcac3d1ed5a939e43c035ecf6b1954098df2d5b05f1e853ab2b67de893794390dcbf0abe1f157fddeb52174 + languageName: node + linkType: hard + "edge-paths@npm:^3.0.5": version: 3.0.5 resolution: "edge-paths@npm:3.0.5" @@ -10109,6 +10205,13 @@ __metadata: languageName: node linkType: hard +"object-inspect@npm:^1.12.0": + version: 1.13.2 + resolution: "object-inspect@npm:1.13.2" + checksum: 9f850b3c045db60e0e97746e809ee4090d6ce62195af17dd1e9438ac761394a7d8ec4f7906559aea5424eaf61e35d3e53feded2ccd5f62fcc7d9670d3c8eb353 + languageName: node + linkType: hard + "object-inspect@npm:^1.12.2, object-inspect@npm:^1.9.0": version: 1.12.3 resolution: "object-inspect@npm:1.12.3" @@ -13136,6 +13239,15 @@ __metadata: languageName: node linkType: hard +"wcwidth@npm:^1.0.1": + version: 1.0.1 + resolution: "wcwidth@npm:1.0.1" + dependencies: + defaults: ^1.0.3 + checksum: 814e9d1ddcc9798f7377ffa448a5a3892232b9275ebb30a41b529607691c0491de47cba426e917a4d08ded3ee7e9ba2f3fe32e62ee3cd9c7d3bafb7754bd553c + languageName: node + linkType: hard + "web-streams-polyfill@npm:^3.0.3": version: 3.3.3 resolution: "web-streams-polyfill@npm:3.3.3"