@prismicio/editor-fields 0.4.86-alpha.jp-fix-navigation-icon.1 → 0.4.87

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,6 +19,6 @@ interface Props<TContent extends ExtendedRichTextContent> {
19
19
  shouldReturnEmptyContent?: boolean;
20
20
  icon?: IconName;
21
21
  }
22
- export declare function RichTextField<TContent extends ExtendedRichTextContent>(props: Props<TContent>): JSX.Element;
22
+ export declare function RichTextField<TContent extends ExtendedRichTextContent>(props: Props<TContent>): JSX.Element | null;
23
23
  export declare function isTransactionFromExternalUpdate(transaction: Transaction): boolean;
24
24
  export {};
package/dist/index.cjs.js CHANGED
@@ -209,7 +209,7 @@ img.ProseMirror-separator {
209
209
 
210
210
  `);return!o||!a?!1:e.chain().command(({tr:s})=>(s.delete(r.pos-2,r.pos),!0)).exitCode().run()},ArrowDown:({editor:e})=>{if(!this.options.exitOnArrowDown)return!1;const{state:t}=e,{selection:n,doc:r}=t,{$from:i,empty:o}=n;if(!o||i.parent.type!==this.type||!(i.parentOffset===i.parent.nodeSize-2))return!1;const s=i.after();return s===void 0?!1:r.nodeAt(s)?e.commands.command(({tr:c})=>(c.setSelection(ke.near(r.resolve(s))),!0)):e.commands.exitCode()}}},addInputRules(){return[sI({find:Mze,type:this.type,getAttributes:e=>({language:e[1]})}),sI({find:Fze,type:this.type,getAttributes:e=>({language:e[1]})})]},addProseMirrorPlugins(){return[new cn({key:new En("codeBlockVSCodeHandler"),props:{handlePaste:(e,t)=>{if(!t.clipboardData||this.editor.isActive(this.type.name))return!1;const n=t.clipboardData.getData("text/plain"),r=t.clipboardData.getData("vscode-editor-data"),i=r?JSON.parse(r):void 0,o=i==null?void 0:i.mode;if(!n||!o)return!1;const{tr:a,schema:s}=e.state,l=s.text(n.replace(/\r\n?/g,`
211
211
  `));return a.replaceSelectionWith(this.type.create({language:o},l)),a.selection.$from.parent.type!==this.type&&a.setSelection(_e.near(a.doc.resolve(Math.max(0,a.selection.from-2)))),a.setMeta("paste",!0),e.dispatch(a),!0}}})]}}),d0=jze.extend({name:"preformatted",addAttributes(){return{language:{default:null,parseHTML:e=>{var o;const{languageClassPrefix:t}=this.options,i=[...((o=e.firstElementChild)==null?void 0:o.classList)||[]].filter(a=>a.startsWith(t)).map(a=>a.replace(t,""))[0];return i||null},renderHTML:e=>e.language?{class:this.options.languageClassPrefix+e.language}:null}}},parseHTML(){return[{tag:"pre",preserveWhitespace:"full"}]},renderHTML({HTMLAttributes:e}){return["pre",Nt(this.options.HTMLAttributes),["code",e,0]]}}).configure({exitOnTripleEnter:!1}),Dze={fromPrismic(e,t,n){return function(r){var o;const i=du.converter.fromPrismic(e,t,n)(d0.name,r,!0);return(o=t.nodes[d0.name])==null?void 0:o.create(Za.fromPrismic(r),i)}},toPrismic(e){return du.converter.toPrismic(e,he.RichTextNodeType.preformatted,Za.toPrismic(e))}},Lze=new nv([he.RichTextNodeType.preformatted],d0.name,d0,Dze,"",!0),cte=Lze;function ute(e){const{editor:t,getPos:n,node:r}=e,[i,o]=R.useState(!1);return R.useEffect(()=>{function a(){const{from:l,to:c}=t.state.selection,u=n(),f=n()+r.nodeSize,p=l<=u&&c>=f;o(p)}function s(){o(!1)}return t.on("blur",s),t.on("selectionUpdate",a),()=>{t.off("blur",s),t.off("selectionUpdate",a)}},[t,n,r.nodeSize]),{selected:i}}function Pze(e,t,n){const{node:r}=e,i=r.attrs.content,o=Ke.useStableCallback(e.updateAttributes);function a(g){o({content:g})}const[s,l]=R.useState(!1),c=Ke.useDebounceState({initialState:(i==null?void 0:i.embed_url)??"",startTransition:R.startTransition});function u(g){c.set(g)}Ke.useOnChange(i==null?void 0:i.embed_url,g=>{c.debouncedValue===c.value&&c.set(g??"")});function f(){a(void 0),c.set("")}function p(){s||f()}const h=R.useRef(null),{onKeyDown:m}=Bze(e,c.value,t,n);return{inputRef:t,containerRef:n,onKeyDown:m,url:c,urlChanged:u,onContentChange:a,content:e.node.attrs.content,setIsFocused:l,errorBoundary:h,onError:p,clearField:f}}function Bze(e,t,n,r){const{editor:i,getPos:o,node:a}=e,[s,l]=R.useState(!0);R.useEffect(()=>{!s||!e.editor.isFocused||setTimeout(()=>{var u;return(u=n.current)==null?void 0:u.focus()})},[n,s,e.editor.isFocused]);function c(u){const f=o(),p=o()+a.nodeSize;u.code==="Enter"&&(l(!1),i.chain().insertContentAt(p,{type:"paragraph"}).focus(p+1).run()),u.code==="Backspace"&&t===""&&i.chain().deleteRange({from:f,to:p}).focus(p+1).run(),u.code==="ArrowUp"&&(l(!1),i.chain().focus(f-1).run()),u.code==="ArrowDown"&&(l(!1),i.chain().focus(p+1).run())}return{containerRef:r,inputRef:n,onKeyDown:c}}function Uze(e){const t=R.useRef(null),n=R.useRef(null),{onKeyDown:r,url:i,urlChanged:o,onContentChange:a,content:s,setIsFocused:l,errorBoundary:c,onError:u,clearField:f}=Pze(e,t,n),{selected:p}=ute(e),h=!e.editor.isEditable;return d.jsx(Mee,{className:"custom-embed",children:d.jsxs("div",{contentEditable:"false",suppressContentEditableWarning:!0,children:[d.jsxs(A.Box,{flexGrow:1,alignItems:"center",children:[d.jsx(A.Icon,{size:"small",name:"cloud",color:"grey11"}),d.jsx(A.Box,{flexGrow:1,height:40,ref:n,children:d.jsx(ic,{id:"id",ref:t,value:i.value,variant:bi.toURL(i.value)?"link":"normal",placeholder:"Paste your link here",onValueChange:o,onKeyDown:r,readOnly:h,onFocus:()=>l(!0),onBlur:()=>{var g;l(!1),i.value===""&&a(void 0);const m=!!((g=c.current)!=null&&g.state.error);(!bi.toURL(i.value)||m)&&f()}})})]}),bi.toURL(i.value)&&d.jsx(SG,{selected:p,debouncedUrl:i.debouncedValue,onContentChange:a,content:s,errorBoundary:c,onError:u})]})})}const wI=Cn.create({name:"embed",group:"block",atom:!0,content:"block*",marks:"",addAttributes(){return{content:{default:void 0}}},addCommands(){return{setEmbed:()=>({tr:e,dispatch:t})=>{const n=this.type.create();return t&&e.replaceSelectionWith(n),!0}}},parseHTML(){return[{tag:"embed"}]},renderHTML(){return["embed"]},addNodeView(){return jee(Uze)}}),Nze={fromPrismic(e){return function(t){var n;return(n=e.nodes[wI.name])==null?void 0:n.create({content:t.data})}},toPrismic(e){return e.attrs.content===void 0?{type:"embed",data:{type:"embed",embed_url:"",__TYPE__:"EmbedContent",all:[]}}:{type:"embed",data:{...e.attrs.content}}}},dte=new nVe([he.RichTextNodeType.embed],wI.name,wI,Nze),Wze=Cn.create({name:"heading",addOptions(){return{levels:[1,2,3,4,5,6],HTMLAttributes:{}}},content:"inline*",group:"block",defining:!0,addAttributes(){return{level:{default:1,rendered:!1}}},parseHTML(){return this.options.levels.map(e=>({tag:`h${e}`,attrs:{level:e}}))},renderHTML({node:e,HTMLAttributes:t}){return[`h${this.options.levels.includes(e.attrs.level)?e.attrs.level:this.options.levels[0]}`,Nt(this.options.HTMLAttributes,t),0]},addCommands(){return{setHeading:e=>({commands:t})=>this.options.levels.includes(e.level)?t.setNode(this.name,e):!1,toggleHeading:e=>({commands:t})=>this.options.levels.includes(e.level)?t.toggleNode(this.name,"paragraph",e):!1}},addKeyboardShortcuts(){return this.options.levels.reduce((e,t)=>({...e,[`Mod-Alt-${t}`]:()=>this.editor.commands.toggleHeading({level:t})}),{})},addInputRules(){return this.options.levels.map(e=>sI({find:new RegExp(`^(#{${Math.min(...this.options.levels)},${e}})\\s$`),type:this.type,getAttributes:{level:e}}))}}),xI="heading";function DS(e){switch(e){case 1:return he.RichTextNodeType.heading1;case 2:return he.RichTextNodeType.heading2;case 3:return he.RichTextNodeType.heading3;case 4:return he.RichTextNodeType.heading4;case 5:return he.RichTextNodeType.heading5;case 6:return he.RichTextNodeType.heading6}}function uU(e){return{fullName:DS(e),level:e}}const fte=[1,2,3,4,5,6];function pte(e,t=fte){const n=new RegExp(`^heading([${t.join(",")}]){1}$`),r=e.match(n);if(!r||!r[1])return;const i=parseInt(r[1]);return{fullName:DS(i),level:i}}function hte(e,t){const n=e.level;if(t.includes(n))return{fullName:DS(n),level:n}}const Kze=e=>{const t=e[0]??1;return{fromPrismic(n,r,i){return function(o){var l;const a=du.converter.fromPrismic(n,r,i)(xI,o),s=pte(o.type,e)||uU(t);return(l=r.nodes[xI])==null?void 0:l.create({level:s.level,...Za.fromPrismic(o)},a)}},toPrismic(n){const{fullName:r}=hte(n.attrs,e)||uU(t);return du.converter.toPrismic(n,r,Za.toPrismic(n))}}};function qze(e){return e?e.size?Array.from(e.values()).reduce((n,r)=>{const i=pte(r);return i?[...n,i.level]:n},[]).sort((n,r)=>n-r):[]:fte}function Vze(e){return Wze.extend({name:"heading"}).configure({levels:e})}const bc={name:xI,build:e=>{const t=qze(e);if(!t)return;const n=t.map(r=>DS(r));return new iVe(n,Vze(t),t,Kze(t),r=>{const i=hte(r,t);return i&&`Heading ${i.level}`})}};function zze(e){const{content:t,thumbnail:n,imageViewProps:{getPos:r,updateAttributes:i,editor:o,node:a}}=e,[s,l]=R.useTransition();function c(g){l(()=>i({content:g}))}function u(g){const y=Uv(g),b=r()+a.nodeSize;c({...t,...y}),o.chain().focus(b+1).run()}function f({croppedImages:g}){if(!t)return;const y=g[n.name];if(!y)return;const b=PJ({content:t,croppedImage:y});b!==t&&c(b)}function p(){const g=r(),y=r()+a.nodeSize;o.chain().deleteRange({from:g,to:y}).focus(y).run()}const{uploadImage:h,isUploadingImage:m}=ZJ({onMediaSelected:u});return{onMediaSelected:u,onCropperDialogClose:f,isUpdating:s,updateContent:c,onClear:p,uploadImage:h,isUploadingImage:m}}function Qze(e){const{node:t}=e,n=t.attrs.content,{selected:r}=ute(e),i=R.useRef(null),o={width:void 0,height:void 0,name:Xp},{onMediaSelected:a,onCropperDialogClose:s,isUpdating:l,updateContent:c,onClear:u,uploadImage:f,isUploadingImage:p}=zze({content:n,thumbnail:o,imageViewProps:e}),[h,m]=R.useState(!1),g="Feature image",y=(n==null?void 0:n.width)===0&&(n==null?void 0:n.height)===0,b=n&&!y?[`${n.width}×${n.height}px`]:[],x={thumbnail:o,contentView:n,labels:ET(o,n,n)};R.useLayoutEffect(()=>{var C;const S=(C=i==null?void 0:i.current)==null?void 0:C.closest(`.${mte}`);Ld.isHTMLElement(S)&&S.style.removeProperty("min-height")},[]);const w=p||l,v=!e.editor.isEditable;return d.jsx(Mee,{children:d.jsx(jJ,{ref:i,isMediaDialogOpen:h,selected:r,onMediaSelected:a,onMediaDialogOpenChange:m,children:d.jsx(R.Suspense,{fallback:Gze,children:n!=null&&n.url?d.jsx(JJ,{allContentViews:[n],content:n,contentView:n,fieldLabel:g,imageLabel:b,initialImages:[x],isUpdating:w,thumbnailName:o.name,onClear:u,onContentChange:c,onCropperDialogClose:s,onMediaDialogOpenChange:m,readOnly:v}):d.jsx(DJ,{uploadImage:f,isUploading:p,disabled:h,children:d.jsx(IG,{fieldLabel:g,isUpdating:w,readOnly:!1,onMediaDialogOpenChange:m})})})})})}const mte="imageViewNodeWrapper",Ate=144,Hze=94;function Yze(e){return(e?Hze:Ate)+12+12+1+1}const Gze=d.jsx("div",{style:{height:Ate}}),TI=Cn.create({name:"image",group:"block",atom:!0,addAttributes(){return{content:{default:void 0}}},addCommands(){return{setImage:()=>e=>{const{dispatch:t,tr:n}=e,r=this.type.create();return t&&n.replaceSelectionWith(r),!0}}},parseHTML(){return[{tag:"image"}]},renderHTML({HTMLAttributes:e}){return["image",e]},addNodeView(){return function(t){const n=t.node.attrs.content===void 0;return jee(Qze,{attrs:{style:`min-height: ${Yze(n)}px`,class:mte}})(t)}}}),Jze={fromPrismic(e){return function(t){var n;return(n=e.nodes[TI.name])==null?void 0:n.create({content:t.data})}},toPrismic(e){if(e.attrs.content!==void 0)return{type:"image",data:{...e.attrs.content}}}},gte=new rVe([he.RichTextNodeType.image],TI.name,TI,Jze),Zze=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/,Xze=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g,eQe=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/,tQe=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g,nQe=Zg.create({name:"italic",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"em"},{tag:"i",getAttrs:e=>e.style.fontStyle!=="normal"&&null},{style:"font-style=normal",clearMark:e=>e.type.name===this.name},{style:"font-style=italic"}]},renderHTML({HTMLAttributes:e}){return["em",Nt(this.options.HTMLAttributes,e),0]},addCommands(){return{setItalic:()=>({commands:e})=>e.setMark(this.name),toggleItalic:()=>({commands:e})=>e.toggleMark(this.name),unsetItalic:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-i":()=>this.editor.commands.toggleItalic(),"Mod-I":()=>this.editor.commands.toggleItalic()}},addInputRules(){return[Jy({find:Zze,type:this.type}),Jy({find:eQe,type:this.type})]},addPasteRules(){return[Xy({find:Xze,type:this.type}),Xy({find:tQe,type:this.type})]}});class rQe{constructor(t,n,r){Ve(this,"extType",Ad.Mark);Ve(this,"richTextNodeTypes",[he.RichTextNodeType.em]);this.name=t,this.component=n,this.converter=r}}const vte="em",yte=nQe.extend({name:vte}),iQe={fromPrismic(e){return function(){var t;return(t=e.marks[yte.name])==null?void 0:t.create()}},toPrismic(){}},oQe=new rQe(vte,yte,iQe),RD=oQe;class aQe{constructor(t,n,r){Ve(this,"extType",Ad.Mark);Ve(this,"richTextNodeTypes",[]);this.name=t,this.component=n,this.converter=r}}const bte="label",II=Zg.create({name:bte,priority:1e3,keepOnSplit:!1,inclusive:!1,addOptions(){return{htmlAttributes:{style:"background-color: hsl(251, 89%, 96%); border: 1px dashed rgba(68, 53, 146, 0.4); border-radius: 0px 2px 2px 2px"}}},addAttributes(){return{label:{default:""}}},addCommands(){return{setLabel:e=>({chain:t})=>t().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMark(this.name,e).run(),unsetLabel:()=>({chain:e})=>e().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMeta("preventAutolink",!0).run()}},renderHTML({HTMLAttributes:e}){return["span",Nt(this.options.htmlAttributes,e),0]}}),sQe={fromPrismic(e){return function(t){var i;const n=t.data,r={type:II.name,label:n};return(i=e.marks[II.name])==null?void 0:i.create(r)}},toPrismic(e){return e.attrs.label}},kD=new aQe(bte,II,sQe);class lQe{constructor(t,n,r){Ve(this,"extType",Ad.Mark);Ve(this,"richTextNodeTypes",[he.RichTextNodeType.hyperlink]);this.name=t,this.component=n,this.converter=r}}const Cte="hyperlink",ja=Zg.create({name:Cte,priority:1e3,keepOnSplit:!1,inclusive:!1,addOptions(){return{openOnClick:!1,linkOnPaste:!0,autolink:!0,protocols:[],htmlAttributes:{target:"_blank",rel:"noopener noreferrer nofollow",class:null,id:""},validate:void 0}},addAttributes(){return{href:{default:""},id:{default:""},target:{default:"_blank"},rel:{default:"noopener noreferrer nofollow"},class:{default:null},media:{default:null}}},parseHTML(){return[{tag:'a[href]:not([href *= "javascript:" i])'}]},renderHTML({HTMLAttributes:e}){return["a",Nt(this.options.htmlAttributes,e),0]},addCommands(){return{setWebLink:e=>({chain:t})=>t().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMark(this.name,e).setMeta("preventAutolink",!0).run(),setDocumentLink:e=>({chain:t})=>t().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMark(this.name,e).setMeta("preventAutolink",!0).run(),setMediaLink:e=>({chain:t})=>{const n=_I(QJ({media:e.media}).value);return t().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMark(this.name,{media:n}).setMeta("preventAutolink",!0).run()},unsetLink:()=>({chain:e})=>e().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMeta("preventAutolink",!0).run()}}}),cQe={fromPrismic(e){return function(t){var r,i,o,a;const n=t.data;if(n.__TYPE__==="DocumentLink"){const s={type:ja.name,id:n.id};return(r=e.marks[ja.name])==null?void 0:r.create(s)}if(n.__TYPE__==="ImageLink"){const s={type:ja.name,media:_I(n)};return(i=e.marks[ja.name])==null?void 0:i.create(s)}if(n.__TYPE__==="FileLink"){const s={type:ja.name,media:_I(n)};return(o=e.marks[ja.name])==null?void 0:o.create(s)}if(n.__TYPE__==="ExternalLink"){const s={type:ja.name,url:n.url,href:n.url,target:n.target};return(a=e.marks[ja.name])==null?void 0:a.create(s)}}},toPrismic(e){return e.attrs.media?wte(e.attrs.media):e.attrs.id?{__TYPE__:"DocumentLink",id:e.attrs.id}:{__TYPE__:"ExternalLink",url:e.attrs.href,target:e.attrs.target}}},Ste=new lQe(Cte,ja,cQe);function _I(e){return JSON.stringify(e)}function wte(e){return JSON.parse(e)}const uQe="listItem",dU="textStyle",fU=/^(\d+)\.\s$/,dQe=Cn.create({name:"orderedList",addOptions(){return{itemTypeName:"listItem",HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}},group:"block list",content(){return`${this.options.itemTypeName}+`},addAttributes(){return{start:{default:1,parseHTML:e=>e.hasAttribute("start")?parseInt(e.getAttribute("start")||"",10):1},type:{default:void 0,parseHTML:e=>e.getAttribute("type")}}},parseHTML(){return[{tag:"ol"}]},renderHTML({HTMLAttributes:e}){const{start:t,...n}=e;return t===1?["ol",Nt(this.options.HTMLAttributes,n),0]:["ol",Nt(this.options.HTMLAttributes,e),0]},addCommands(){return{toggleOrderedList:()=>({commands:e,chain:t})=>this.options.keepAttributes?t().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(uQe,this.editor.getAttributes(dU)).run():e.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-7":()=>this.editor.commands.toggleOrderedList()}},addInputRules(){let e=Zy({find:fU,type:this.type,getAttributes:t=>({start:+t[1]}),joinPredicate:(t,n)=>n.childCount+n.attrs.start===+t[1]});return(this.options.keepMarks||this.options.keepAttributes)&&(e=Zy({find:fU,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:t=>({start:+t[1],...this.editor.getAttributes(dU)}),joinPredicate:(t,n)=>n.childCount+n.attrs.start===+t[1],editor:this.editor})),[e]}}),EI=dQe.extend({name:"orderedList",addAttributes(){return{start:{default:1,parseHTML:e=>e.hasAttribute("start")?parseInt(e.getAttribute("start")||"",10):1}}},renderHTML({HTMLAttributes:e}){const{start:t,...n}=e;return t===1?["ol",Nt(this.options.HTMLAttributes,n),0]:["ol",Nt(this.options.HTMLAttributes,e),0]},addCommands(){return{toggleOrderedList:()=>({commands:e})=>e.toggleList(this.name,this.options.itemTypeName)}},addKeyboardShortcuts(){return{"Mod-Shift-7":()=>this.editor.commands.toggleOrderedList()}}}).configure({itemTypeName:"listItem"}),fQe={fromPrismic(e,t,n){return function(r){var o;const i=Sf.converter.fromPrismic(e,t,n)(r);if(i)return(o=t.nodes[EI.name])==null?void 0:o.create(Za.fromPrismic(r),i)}},toPrismic(e){return Tl.children.map(e,t=>Sf.converter.toPrismic(t,he.RichTextNodeType.orderedList).filter(Ui.isDefined)).flat()}},pQe=new SD([he.RichTextNodeType.orderedList],EI.name,EI,fQe),f0=pQe,xte=65535,Tte=Math.pow(2,16);function hQe(e,t){return e+t*Tte}function pU(e){return e&xte}function mQe(e){return(e-(e&xte))/Tte}const Ite=1,_te=2,oy=4,Ete=8;class RI{constructor(t,n,r){this.pos=t,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&Ete)>0}get deletedBefore(){return(this.delInfo&(Ite|oy))>0}get deletedAfter(){return(this.delInfo&(_te|oy))>0}get deletedAcross(){return(this.delInfo&oy)>0}}class gi{constructor(t,n=!1){if(this.ranges=t,this.inverted=n,!t.length&&gi.empty)return gi.empty}recover(t){let n=0,r=pU(t);if(!this.inverted)for(let i=0;i<r;i++)n+=this.ranges[i*3+2]-this.ranges[i*3+1];return this.ranges[r*3]+n+mQe(t)}mapResult(t,n=1){return this._map(t,n,!1)}map(t,n=1){return this._map(t,n,!0)}_map(t,n,r){let i=0,o=this.inverted?2:1,a=this.inverted?1:2;for(let s=0;s<this.ranges.length;s+=3){let l=this.ranges[s]-(this.inverted?i:0);if(l>t)break;let c=this.ranges[s+o],u=this.ranges[s+a],f=l+c;if(t<=f){let p=c?t==l?-1:t==f?1:n:n,h=l+i+(p<0?0:u);if(r)return h;let m=t==(n<0?l:f)?null:hQe(s/3,t-l),g=t==l?_te:t==f?Ite:oy;return(n<0?t!=l:t!=f)&&(g|=Ete),new RI(h,g,m)}i+=u-c}return r?t+i:new RI(t+i,0,null)}touches(t,n){let r=0,i=pU(n),o=this.inverted?2:1,a=this.inverted?1:2;for(let s=0;s<this.ranges.length;s+=3){let l=this.ranges[s]-(this.inverted?r:0);if(l>t)break;let c=this.ranges[s+o],u=l+c;if(t<=u&&s==i*3)return!0;r+=this.ranges[s+a]-c}return!1}forEach(t){let n=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i<this.ranges.length;i+=3){let a=this.ranges[i],s=a-(this.inverted?o:0),l=a+(this.inverted?0:o),c=this.ranges[i+n],u=this.ranges[i+r];t(s,s+c,l,l+u),o+=u-c}}invert(){return new gi(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(t){return t==0?gi.empty:new gi(t<0?[0,-t,0]:[0,0,t])}}gi.empty=new gi([]);class zh{constructor(t=[],n,r=0,i=t.length){this.maps=t,this.mirror=n,this.from=r,this.to=i}slice(t=0,n=this.maps.length){return new zh(this.maps,this.mirror,t,n)}copy(){return new zh(this.maps.slice(),this.mirror&&this.mirror.slice(),this.from,this.to)}appendMap(t,n){this.to=this.maps.push(t),n!=null&&this.setMirror(this.maps.length-1,n)}appendMapping(t){for(let n=0,r=this.maps.length;n<t.maps.length;n++){let i=t.getMirror(n);this.appendMap(t.maps[n],i!=null&&i<n?r+i:void 0)}}getMirror(t){if(this.mirror){for(let n=0;n<this.mirror.length;n++)if(this.mirror[n]==t)return this.mirror[n+(n%2?-1:1)]}}setMirror(t,n){this.mirror||(this.mirror=[]),this.mirror.push(t,n)}appendMappingInverted(t){for(let n=t.maps.length-1,r=this.maps.length+t.maps.length;n>=0;n--){let i=t.getMirror(n);this.appendMap(t.maps[n].invert(),i!=null&&i>n?r-i-1:void 0)}}invert(){let t=new zh;return t.appendMappingInverted(this),t}map(t,n=1){if(this.mirror)return this._map(t,n,!0);for(let r=this.from;r<this.to;r++)t=this.maps[r].map(t,n);return t}mapResult(t,n=1){return this._map(t,n,!1)}_map(t,n,r){let i=0;for(let o=this.from;o<this.to;o++){let a=this.maps[o],s=a.mapResult(t,n);if(s.recover!=null){let l=this.getMirror(o);if(l!=null&&l>o&&l<this.to){o=l,t=this.maps[l].recover(s.recover);continue}}i|=s.delInfo,t=s.pos}return r?t:new RI(t,i,null)}}const Nx=Object.create(null);class vr{getMap(){return gi.empty}merge(t){return null}static fromJSON(t,n){if(!n||!n.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=Nx[n.stepType];if(!r)throw new RangeError(`No step type ${n.stepType} defined`);return r.fromJSON(t,n)}static jsonID(t,n){if(t in Nx)throw new RangeError("Duplicate use of step JSON ID "+t);return Nx[t]=n,n.prototype.jsonID=t,n}}class rn{constructor(t,n){this.doc=t,this.failed=n}static ok(t){return new rn(t,null)}static fail(t){return new rn(null,t)}static fromReplace(t,n,r,i){try{return rn.ok(t.replace(n,r,i))}catch(o){if(o instanceof iu)return rn.fail(o.message);throw o}}}function $D(e,t,n){let r=[];for(let i=0;i<e.childCount;i++){let o=e.child(i);o.content.size&&(o=o.copy($D(o.content,t,o))),o.isInline&&(o=t(o,n,i)),r.push(o)}return U.fromArray(r)}class rl extends vr{constructor(t,n,r){super(),this.from=t,this.to=n,this.mark=r}apply(t){let n=t.slice(this.from,this.to),r=t.resolve(this.from),i=r.node(r.sharedDepth(this.to)),o=new W($D(n.content,(a,s)=>!a.isAtom||!s.type.allowsMarkType(this.mark.type)?a:a.mark(this.mark.addToSet(a.marks)),i),n.openStart,n.openEnd);return rn.fromReplace(t,this.from,this.to,o)}invert(){return new Vo(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new rl(n.pos,r.pos,this.mark)}merge(t){return t instanceof rl&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new rl(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new rl(n.from,n.to,t.markFromJSON(n.mark))}}vr.jsonID("addMark",rl);class Vo extends vr{constructor(t,n,r){super(),this.from=t,this.to=n,this.mark=r}apply(t){let n=t.slice(this.from,this.to),r=new W($D(n.content,i=>i.mark(this.mark.removeFromSet(i.marks)),t),n.openStart,n.openEnd);return rn.fromReplace(t,this.from,this.to,r)}invert(){return new rl(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new Vo(n.pos,r.pos,this.mark)}merge(t){return t instanceof Vo&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new Vo(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Vo(n.from,n.to,t.markFromJSON(n.mark))}}vr.jsonID("removeMark",Vo);class il extends vr{constructor(t,n){super(),this.pos=t,this.mark=n}apply(t){let n=t.nodeAt(this.pos);if(!n)return rn.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return rn.fromReplace(t,this.pos,this.pos+1,new W(U.from(r),0,n.isLeaf?0:1))}invert(t){let n=t.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let i=0;i<n.marks.length;i++)if(!n.marks[i].isInSet(r))return new il(this.pos,n.marks[i]);return new il(this.pos,this.mark)}}return new xf(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new il(n.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new il(n.pos,t.markFromJSON(n.mark))}}vr.jsonID("addNodeMark",il);class xf extends vr{constructor(t,n){super(),this.pos=t,this.mark=n}apply(t){let n=t.nodeAt(this.pos);if(!n)return rn.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.removeFromSet(n.marks));return rn.fromReplace(t,this.pos,this.pos+1,new W(U.from(r),0,n.isLeaf?0:1))}invert(t){let n=t.nodeAt(this.pos);return!n||!this.mark.isInSet(n.marks)?this:new il(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new xf(n.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new xf(n.pos,t.markFromJSON(n.mark))}}vr.jsonID("removeNodeMark",xf);class br extends vr{constructor(t,n,r,i=!1){super(),this.from=t,this.to=n,this.slice=r,this.structure=i}apply(t){return this.structure&&kI(t,this.from,this.to)?rn.fail("Structure replace would overwrite content"):rn.fromReplace(t,this.from,this.to,this.slice)}getMap(){return new gi([this.from,this.to-this.from,this.slice.size])}invert(t){return new br(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deletedAcross&&r.deletedAcross?null:new br(n.pos,Math.max(n.pos,r.pos),this.slice)}merge(t){if(!(t instanceof br)||t.structure||this.structure)return null;if(this.from+this.slice.size==t.from&&!this.slice.openEnd&&!t.slice.openStart){let n=this.slice.size+t.slice.size==0?W.empty:new W(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new br(this.from,this.to+(t.to-t.from),n,this.structure)}else if(t.to==this.from&&!this.slice.openStart&&!t.slice.openEnd){let n=this.slice.size+t.slice.size==0?W.empty:new W(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new br(t.from,this.to,n,this.structure)}else return null}toJSON(){let t={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new br(n.from,n.to,W.fromJSON(t,n.slice),!!n.structure)}}vr.jsonID("replace",br);class Go extends vr{constructor(t,n,r,i,o,a,s=!1){super(),this.from=t,this.to=n,this.gapFrom=r,this.gapTo=i,this.slice=o,this.insert=a,this.structure=s}apply(t){if(this.structure&&(kI(t,this.from,this.gapFrom)||kI(t,this.gapTo,this.to)))return rn.fail("Structure gap-replace would overwrite content");let n=t.slice(this.gapFrom,this.gapTo);if(n.openStart||n.openEnd)return rn.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,n.content);return r?rn.fromReplace(t,this.from,this.to,r):rn.fail("Content does not fit in gap")}getMap(){return new gi([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let n=this.gapTo-this.gapFrom;return new Go(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1),i=this.from==this.gapFrom?n.pos:t.map(this.gapFrom,-1),o=this.to==this.gapTo?r.pos:t.map(this.gapTo,1);return n.deletedAcross&&r.deletedAcross||i<n.pos||o>r.pos?null:new Go(n.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let t={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Go(n.from,n.to,n.gapFrom,n.gapTo,W.fromJSON(t,n.slice),n.insert,!!n.structure)}}vr.jsonID("replaceAround",Go);function kI(e,t,n){let r=e.resolve(t),i=n-t,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let a=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!a||a.isLeaf)return!0;a=a.firstChild,i--}}return!1}function AQe(e,t,n,r){let i=[],o=[],a,s;e.doc.nodesBetween(t,n,(l,c,u)=>{if(!l.isInline)return;let f=l.marks;if(!r.isInSet(f)&&u.type.allowsMarkType(r.type)){let p=Math.max(c,t),h=Math.min(c+l.nodeSize,n),m=r.addToSet(f);for(let g=0;g<f.length;g++)f[g].isInSet(m)||(a&&a.to==p&&a.mark.eq(f[g])?a.to=h:i.push(a=new Vo(p,h,f[g])));s&&s.to==p?s.to=h:o.push(s=new rl(p,h,r))}}),i.forEach(l=>e.step(l)),o.forEach(l=>e.step(l))}function gQe(e,t,n,r){let i=[],o=0;e.doc.nodesBetween(t,n,(a,s)=>{if(!a.isInline)return;o++;let l=null;if(r instanceof Qg){let c=a.marks,u;for(;u=r.isInSet(c);)(l||(l=[])).push(u),c=u.removeFromSet(c)}else r?r.isInSet(a.marks)&&(l=[r]):l=a.marks;if(l&&l.length){let c=Math.min(s+a.nodeSize,n);for(let u=0;u<l.length;u++){let f=l[u],p;for(let h=0;h<i.length;h++){let m=i[h];m.step==o-1&&f.eq(i[h].style)&&(p=m)}p?(p.to=c,p.step=o):i.push({style:f,from:Math.max(s,t),to:c,step:o})}}}),i.forEach(a=>e.step(new Vo(a.from,a.to,a.style)))}function OD(e,t,n,r=n.contentMatch,i=!0){let o=e.doc.nodeAt(t),a=[],s=t+1;for(let l=0;l<o.childCount;l++){let c=o.child(l),u=s+c.nodeSize,f=r.matchType(c.type);if(!f)a.push(new br(s,u,W.empty));else{r=f;for(let p=0;p<c.marks.length;p++)n.allowsMarkType(c.marks[p].type)||e.step(new Vo(s,u,c.marks[p]));if(i&&c.isText&&n.whitespace!="pre"){let p,h=/\r?\n|\r/g,m;for(;p=h.exec(c.text);)m||(m=new W(U.from(n.schema.text(" ",n.allowedMarks(c.marks))),0,0)),a.push(new br(s+p.index,s+p.index+p[0].length,m))}}s=u}if(!r.validEnd){let l=r.fillBefore(U.empty,!0);e.replace(s,s,new W(l,0,0))}for(let l=a.length-1;l>=0;l--)e.step(a[l])}function vQe(e,t,n){let{$from:r,$to:i,depth:o}=t,a=r.before(o+1),s=i.after(o+1),l=a,c=s,u=U.empty,f=0;for(let m=o,g=!1;m>n;m--)g||r.index(m)>0?(g=!0,u=U.from(r.node(m).copy(u)),f++):l--;let p=U.empty,h=0;for(let m=o,g=!1;m>n;m--)g||i.after(m+1)<i.end(m)?(g=!0,p=U.from(i.node(m).copy(p)),h++):c++;e.step(new Go(l,c,a,s,new W(u.append(p),f,h),u.size-f,!0))}function yQe(e,t,n){let r=U.empty;for(let a=n.length-1;a>=0;a--){if(r.size){let s=n[a].type.contentMatch.matchFragment(r);if(!s||!s.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=U.from(n[a].type.create(n[a].attrs,r))}let i=t.start,o=t.end;e.step(new Go(i,o,i,o,new W(r,0,0),n.length,!0))}function bQe(e,t,n,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=e.steps.length;e.doc.nodesBetween(t,n,(a,s)=>{let l=typeof i=="function"?i(a):i;if(a.isTextblock&&!a.hasMarkup(r,l)&&CQe(e.doc,e.mapping.slice(o).map(s),r)){let c=null;if(r.schema.linebreakReplacement){let h=r.whitespace=="pre",m=!!r.contentMatch.matchType(r.schema.linebreakReplacement);h&&!m?c=!1:!h&&m&&(c=!0)}c===!1&&kte(e,a,s,o),OD(e,e.mapping.slice(o).map(s,1),r,void 0,c===null);let u=e.mapping.slice(o),f=u.map(s,1),p=u.map(s+a.nodeSize,1);return e.step(new Go(f,p,f+1,p-1,new W(U.from(r.create(l,null,a.marks)),0,0),1,!0)),c===!0&&Rte(e,a,s,o),!1}})}function Rte(e,t,n,r){t.forEach((i,o)=>{if(i.isText){let a,s=/\r?\n|\r/g;for(;a=s.exec(i.text);){let l=e.mapping.slice(r).map(n+1+o+a.index);e.replaceWith(l,l+1,t.type.schema.linebreakReplacement.create())}}})}function kte(e,t,n,r){t.forEach((i,o)=>{if(i.type==i.type.schema.linebreakReplacement){let a=e.mapping.slice(r).map(n+1+o);e.replaceWith(a,a+1,t.type.schema.text(`
212
- `))}})}function CQe(e,t,n){let r=e.resolve(t),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function SQe(e,t,n,r,i){let o=e.doc.nodeAt(t);if(!o)throw new RangeError("No node at given position");n||(n=o.type);let a=n.create(r,null,i||o.marks);if(o.isLeaf)return e.replaceWith(t,t+o.nodeSize,a);if(!n.validContent(o.content))throw new RangeError("Invalid content for node type "+n.name);e.step(new Go(t,t+o.nodeSize,t+1,t+o.nodeSize-1,new W(U.from(a),0,0),1,!0))}function wQe(e,t,n=1,r){let i=e.doc.resolve(t),o=U.empty,a=U.empty;for(let s=i.depth,l=i.depth-n,c=n-1;s>l;s--,c--){o=U.from(i.node(s).copy(o));let u=r&&r[c];a=U.from(u?u.type.create(u.attrs,a):i.node(s).copy(a))}e.step(new br(t,t,new W(o.append(a),n,n),!0))}function xQe(e,t,n){let r=null,{linebreakReplacement:i}=e.doc.type.schema,o=e.doc.resolve(t-n),a=o.node().type;if(i&&a.inlineContent){let u=a.whitespace=="pre",f=!!a.contentMatch.matchType(i);u&&!f?r=!1:!u&&f&&(r=!0)}let s=e.steps.length;if(r===!1){let u=e.doc.resolve(t+n);kte(e,u.node(),u.before(),s)}a.inlineContent&&OD(e,t+n-1,a,o.node().contentMatchAt(o.index()),r==null);let l=e.mapping.slice(s),c=l.map(t-n);if(e.step(new br(c,l.map(t+n,-1),W.empty,!0)),r===!0){let u=e.doc.resolve(c);Rte(e,u.node(),u.before(),e.steps.length)}return e}function TQe(e,t,n){let r=e.resolve(t);if(r.parent.canReplaceWith(r.index(),r.index(),n))return t;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,n))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,n))return r.after(i+1);if(o<r.node(i).childCount)return null}return null}function IQe(e,t,n=t,r=W.empty){if(t==n&&!r.size)return null;let i=e.resolve(t),o=e.resolve(n);return $te(i,o,r)?new br(t,n,r):new _Qe(i,o,r).fit()}function $te(e,t,n){return!n.openStart&&!n.openEnd&&e.start()==t.start()&&e.parent.canReplace(e.index(),t.index(),n.content)}class _Qe{constructor(t,n,r){this.$from=t,this.$to=n,this.unplaced=r,this.frontier=[],this.placed=U.empty;for(let i=0;i<=t.depth;i++){let o=t.node(i);this.frontier.push({type:o.type,match:o.contentMatchAt(t.indexAfter(i))})}for(let i=t.depth;i>0;i--)this.placed=U.from(t.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let c=this.findFittable();c?this.placeNodes(c):this.openMore()||this.dropNode()}let t=this.mustMoveInline(),n=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(t<0?this.$to:r.doc.resolve(t));if(!i)return null;let o=this.placed,a=r.depth,s=i.depth;for(;a&&s&&o.childCount==1;)o=o.firstChild.content,a--,s--;let l=new W(o,a,s);return t>-1?new Go(r.pos,t,this.$to.pos,this.$to.end(),l,n):l.size||r.pos!=this.$to.pos?new br(r.pos,i.pos,l):null}findFittable(){let t=this.unplaced.openStart;for(let n=this.unplaced.content,r=0,i=this.unplaced.openEnd;r<t;r++){let o=n.firstChild;if(n.childCount>1&&(i=0),o.type.spec.isolating&&i<=r){t=r;break}n=o.content}for(let n=1;n<=2;n++)for(let r=n==1?t:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=Wx(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let a=i.firstChild;for(let s=this.depth;s>=0;s--){let{type:l,match:c}=this.frontier[s],u,f=null;if(n==1&&(a?c.matchType(a.type)||(f=c.fillBefore(U.from(a),!1)):o&&l.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:s,parent:o,inject:f};if(n==2&&a&&(u=c.findWrapping(a.type)))return{sliceDepth:r,frontierDepth:s,parent:o,wrap:u};if(o&&c.matchType(o.type))break}}}openMore(){let{content:t,openStart:n,openEnd:r}=this.unplaced,i=Wx(t,n);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new W(t,n+1,Math.max(r,i.size+n>=t.size-r?n+1:0)),!0)}dropNode(){let{content:t,openStart:n,openEnd:r}=this.unplaced,i=Wx(t,n);if(i.childCount<=1&&n>0){let o=t.size-n<=n+i.size;this.unplaced=new W(Fh(t,n-1,1),n-1,o?n-1:r)}else this.unplaced=new W(Fh(t,n,1),n,r)}placeNodes({sliceDepth:t,frontierDepth:n,parent:r,inject:i,wrap:o}){for(;this.depth>n;)this.closeFrontierNode();if(o)for(let g=0;g<o.length;g++)this.openFrontierNode(o[g]);let a=this.unplaced,s=r?r.content:a.content,l=a.openStart-t,c=0,u=[],{match:f,type:p}=this.frontier[n];if(i){for(let g=0;g<i.childCount;g++)u.push(i.child(g));f=f.matchFragment(i)}let h=s.size+t-(a.content.size-a.openEnd);for(;c<s.childCount;){let g=s.child(c),y=f.matchType(g.type);if(!y)break;c++,(c>1||l==0||g.content.size)&&(f=y,u.push(Ote(g.mark(p.allowedMarks(g.marks)),c==1?l:0,c==s.childCount?h:-1)))}let m=c==s.childCount;m||(h=-1),this.placed=jh(this.placed,n,U.from(u)),this.frontier[n].match=f,m&&h<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let g=0,y=s;g<h;g++){let b=y.lastChild;this.frontier.push({type:b.type,match:b.contentMatchAt(b.childCount)}),y=b.content}this.unplaced=m?t==0?W.empty:new W(Fh(a.content,t-1,1),t-1,h<0?a.openEnd:t-1):new W(Fh(a.content,t,c),a.openStart,a.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let t=this.frontier[this.depth],n;if(!t.type.isTextblock||!Kx(this.$to,this.$to.depth,t.type,t.match,!1)||this.$to.depth==this.depth&&(n=this.findCloseLevel(this.$to))&&n.depth==this.depth)return-1;let{depth:r}=this.$to,i=this.$to.after(r);for(;r>1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(t){e:for(let n=Math.min(this.depth,t.depth);n>=0;n--){let{match:r,type:i}=this.frontier[n],o=n<t.depth&&t.end(n+1)==t.pos+(t.depth-(n+1)),a=Kx(t,n,i,r,o);if(a){for(let s=n-1;s>=0;s--){let{match:l,type:c}=this.frontier[s],u=Kx(t,s,c,l,!0);if(!u||u.childCount)continue e}return{depth:n,fit:a,move:o?t.doc.resolve(t.after(n+1)):t}}}}close(t){let n=this.findCloseLevel(t);if(!n)return null;for(;this.depth>n.depth;)this.closeFrontierNode();n.fit.childCount&&(this.placed=jh(this.placed,n.depth,n.fit)),t=n.move;for(let r=n.depth+1;r<=t.depth;r++){let i=t.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,t.index(r));this.openFrontierNode(i.type,i.attrs,o)}return t}openFrontierNode(t,n=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(t),this.placed=jh(this.placed,this.depth,U.from(t.create(n,r))),this.frontier.push({type:t,match:t.contentMatch})}closeFrontierNode(){let n=this.frontier.pop().match.fillBefore(U.empty,!0);n.childCount&&(this.placed=jh(this.placed,this.frontier.length,n))}}function Fh(e,t,n){return t==0?e.cutByIndex(n,e.childCount):e.replaceChild(0,e.firstChild.copy(Fh(e.firstChild.content,t-1,n)))}function jh(e,t,n){return t==0?e.append(n):e.replaceChild(e.childCount-1,e.lastChild.copy(jh(e.lastChild.content,t-1,n)))}function Wx(e,t){for(let n=0;n<t;n++)e=e.firstChild.content;return e}function Ote(e,t,n){if(t<=0)return e;let r=e.content;return t>1&&(r=r.replaceChild(0,Ote(r.firstChild,t-1,r.childCount==1?n-1:0))),t>0&&(r=e.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(e.type.contentMatch.matchFragment(r).fillBefore(U.empty,!0)))),e.copy(r)}function Kx(e,t,n,r,i){let o=e.node(t),a=i?e.indexAfter(t):e.index(t);if(a==o.childCount&&!n.compatibleContent(o.type))return null;let s=r.fillBefore(o.content,!0,a);return s&&!EQe(n,o.content,a)?s:null}function EQe(e,t,n){for(let r=n;r<t.childCount;r++)if(!e.allowsMarks(t.child(r).marks))return!0;return!1}function RQe(e){return e.spec.defining||e.spec.definingForContent}function kQe(e,t,n,r){if(!r.size)return e.deleteRange(t,n);let i=e.doc.resolve(t),o=e.doc.resolve(n);if($te(i,o,r))return e.step(new br(t,n,r));let a=Fte(i,e.doc.resolve(n));a[a.length-1]==0&&a.pop();let s=-(i.depth+1);a.unshift(s);for(let p=i.depth,h=i.pos-1;p>0;p--,h--){let m=i.node(p).type.spec;if(m.defining||m.definingAsContext||m.isolating)break;a.indexOf(p)>-1?s=p:i.before(p)==h&&a.splice(1,0,-p)}let l=a.indexOf(s),c=[],u=r.openStart;for(let p=r.content,h=0;;h++){let m=p.firstChild;if(c.push(m),h==r.openStart)break;p=m.content}for(let p=u-1;p>=0;p--){let h=c[p],m=RQe(h.type);if(m&&!h.sameMarkup(i.node(Math.abs(s)-1)))u=p;else if(m||!h.type.isTextblock)break}for(let p=r.openStart;p>=0;p--){let h=(p+u+1)%(r.openStart+1),m=c[h];if(m)for(let g=0;g<a.length;g++){let y=a[(g+l)%a.length],b=!0;y<0&&(b=!1,y=-y);let x=i.node(y-1),w=i.index(y-1);if(x.canReplaceWith(w,w,m.type,m.marks))return e.replace(i.before(y),b?o.after(y):n,new W(Mte(r.content,0,r.openStart,h),h,r.openEnd))}}let f=e.steps.length;for(let p=a.length-1;p>=0&&(e.replace(t,n,r),!(e.steps.length>f));p--){let h=a[p];h<0||(t=i.before(h),n=o.after(h))}}function Mte(e,t,n,r,i){if(t<n){let o=e.firstChild;e=e.replaceChild(0,o.copy(Mte(o.content,t+1,n,r,o)))}if(t>r){let o=i.contentMatchAt(0),a=o.fillBefore(e).append(e);e=a.append(o.matchFragment(a).fillBefore(U.empty,!0))}return e}function $Qe(e,t,n,r){if(!r.isInline&&t==n&&e.doc.resolve(t).parent.content.size){let i=TQe(e.doc,t,r.type);i!=null&&(t=n=i)}e.replaceRange(t,n,new W(U.from(r),0,0))}function OQe(e,t,n){let r=e.doc.resolve(t),i=e.doc.resolve(n),o=Fte(r,i);for(let a=0;a<o.length;a++){let s=o[a],l=a==o.length-1;if(l&&s==0||r.node(s).type.contentMatch.validEnd)return e.delete(r.start(s),i.end(s));if(s>0&&(l||r.node(s-1).canReplace(r.index(s-1),i.indexAfter(s-1))))return e.delete(r.before(s),i.after(s))}for(let a=1;a<=r.depth&&a<=i.depth;a++)if(t-r.start(a)==r.depth-a&&n>r.end(a)&&i.end(a)-n!=i.depth-a&&r.start(a-1)==i.start(a-1)&&r.node(a-1).canReplace(r.index(a-1),i.index(a-1)))return e.delete(r.before(a),n);e.delete(t,n)}function Fte(e,t){let n=[],r=Math.min(e.depth,t.depth);for(let i=r;i>=0;i--){let o=e.start(i);if(o<e.pos-(e.depth-i)||t.end(i)>t.pos+(t.depth-i)||e.node(i).type.spec.isolating||t.node(i).type.spec.isolating)break;(o==t.start(i)||i==e.depth&&i==t.depth&&e.parent.inlineContent&&t.parent.inlineContent&&i&&t.start(i-1)==o-1)&&n.push(i)}return n}class zd extends vr{constructor(t,n,r){super(),this.pos=t,this.attr=n,this.value=r}apply(t){let n=t.nodeAt(this.pos);if(!n)return rn.fail("No node at attribute step's position");let r=Object.create(null);for(let o in n.attrs)r[o]=n.attrs[o];r[this.attr]=this.value;let i=n.type.create(r,null,n.marks);return rn.fromReplace(t,this.pos,this.pos+1,new W(U.from(i),0,n.isLeaf?0:1))}getMap(){return gi.empty}invert(t){return new zd(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new zd(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new zd(n.pos,n.attr,n.value)}}vr.jsonID("attr",zd);class Wm extends vr{constructor(t,n){super(),this.attr=t,this.value=n}apply(t){let n=Object.create(null);for(let i in t.attrs)n[i]=t.attrs[i];n[this.attr]=this.value;let r=t.type.create(n,t.content,t.marks);return rn.ok(r)}getMap(){return gi.empty}invert(t){return new Wm(this.attr,t.attrs[this.attr])}map(t){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new Wm(n.attr,n.value)}}vr.jsonID("docAttr",Wm);let Tf=class extends Error{};Tf=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n};Tf.prototype=Object.create(Error.prototype);Tf.prototype.constructor=Tf;Tf.prototype.name="TransformError";class MQe{constructor(t){this.doc=t,this.steps=[],this.docs=[],this.mapping=new zh}get before(){return this.docs.length?this.docs[0]:this.doc}step(t){let n=this.maybeStep(t);if(n.failed)throw new Tf(n.failed);return this}maybeStep(t){let n=t.apply(this.doc);return n.failed||this.addStep(t,n.doc),n}get docChanged(){return this.steps.length>0}addStep(t,n){this.docs.push(this.doc),this.steps.push(t),this.mapping.appendMap(t.getMap()),this.doc=n}replace(t,n=t,r=W.empty){let i=IQe(this.doc,t,n,r);return i&&this.step(i),this}replaceWith(t,n,r){return this.replace(t,n,new W(U.from(r),0,0))}delete(t,n){return this.replace(t,n,W.empty)}insert(t,n){return this.replaceWith(t,t,n)}replaceRange(t,n,r){return kQe(this,t,n,r),this}replaceRangeWith(t,n,r){return $Qe(this,t,n,r),this}deleteRange(t,n){return OQe(this,t,n),this}lift(t,n){return vQe(this,t,n),this}join(t,n=1){return xQe(this,t,n),this}wrap(t,n){return yQe(this,t,n),this}setBlockType(t,n=t,r,i=null){return bQe(this,t,n,r,i),this}setNodeMarkup(t,n,r=null,i){return SQe(this,t,n,r,i),this}setNodeAttribute(t,n,r){return this.step(new zd(t,n,r)),this}setDocAttribute(t,n){return this.step(new Wm(t,n)),this}addNodeMark(t,n){return this.step(new il(t,n)),this}removeNodeMark(t,n){if(!(n instanceof dt)){let r=this.doc.nodeAt(t);if(!r)throw new RangeError("No node at position "+t);if(n=n.isInSet(r.marks),!n)return this}return this.step(new xf(t,n)),this}split(t,n=1,r){return wQe(this,t,n,r),this}addMark(t,n,r){return AQe(this,t,n,r),this}removeMark(t,n,r){return gQe(this,t,n,r),this}clearIncompatible(t,n,r){return OD(this,t,n,r),this}}var $I,OI;if(typeof WeakMap<"u"){let e=new WeakMap;$I=t=>e.get(t),OI=(t,n)=>(e.set(t,n),n)}else{const e=[];let n=0;$I=r=>{for(let i=0;i<e.length;i+=2)if(e[i]==r)return e[i+1]},OI=(r,i)=>(n==10&&(n=0),e[n++]=r,e[n++]=i)}var Ct=class{constructor(e,t,n,r){this.width=e,this.height=t,this.map=n,this.problems=r}findCell(e){for(let t=0;t<this.map.length;t++){const n=this.map[t];if(n!=e)continue;const r=t%this.width,i=t/this.width|0;let o=r+1,a=i+1;for(let s=1;o<this.width&&this.map[t+s]==n;s++)o++;for(let s=1;a<this.height&&this.map[t+this.width*s]==n;s++)a++;return{left:r,top:i,right:o,bottom:a}}throw new RangeError(`No cell with offset ${e} found`)}colCount(e){for(let t=0;t<this.map.length;t++)if(this.map[t]==e)return t%this.width;throw new RangeError(`No cell with offset ${e} found`)}nextCell(e,t,n){const{left:r,right:i,top:o,bottom:a}=this.findCell(e);return t=="horiz"?(n<0?r==0:i==this.width)?null:this.map[o*this.width+(n<0?r-1:i)]:(n<0?o==0:a==this.height)?null:this.map[r+this.width*(n<0?o-1:a)]}rectBetween(e,t){const{left:n,right:r,top:i,bottom:o}=this.findCell(e),{left:a,right:s,top:l,bottom:c}=this.findCell(t);return{left:Math.min(n,a),top:Math.min(i,l),right:Math.max(r,s),bottom:Math.max(o,c)}}cellsInRect(e){const t=[],n={};for(let r=e.top;r<e.bottom;r++)for(let i=e.left;i<e.right;i++){const o=r*this.width+i,a=this.map[o];n[a]||(n[a]=!0,!(i==e.left&&i&&this.map[o-1]==a||r==e.top&&r&&this.map[o-this.width]==a)&&t.push(a))}return t}positionAt(e,t,n){for(let r=0,i=0;;r++){const o=i+n.child(r).nodeSize;if(r==e){let a=t+e*this.width;const s=(e+1)*this.width;for(;a<s&&this.map[a]<i;)a++;return a==s?o-1:this.map[a]}i=o}}static get(e){return $I(e)||OI(e,FQe(e))}};function FQe(e){if(e.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+e.type.name);const t=jQe(e),n=e.childCount,r=[];let i=0,o=null;const a=[];for(let c=0,u=t*n;c<u;c++)r[c]=0;for(let c=0,u=0;c<n;c++){const f=e.child(c);u++;for(let m=0;;m++){for(;i<r.length&&r[i]!=0;)i++;if(m==f.childCount)break;const g=f.child(m),{colspan:y,rowspan:b,colwidth:x}=g.attrs;for(let w=0;w<b;w++){if(w+c>=n){(o||(o=[])).push({type:"overlong_rowspan",pos:u,n:b-w});break}const v=i+w*t;for(let S=0;S<y;S++){r[v+S]==0?r[v+S]=u:(o||(o=[])).push({type:"collision",row:c,pos:u,n:y-S});const C=x&&x[S];if(C){const T=(v+S)%t*2,E=a[T];E==null||E!=C&&a[T+1]==1?(a[T]=C,a[T+1]=1):E==C&&a[T+1]++}}}i+=y,u+=g.nodeSize}const p=(c+1)*t;let h=0;for(;i<p;)r[i++]==0&&h++;h&&(o||(o=[])).push({type:"missing",row:c,n:h}),u++}(t===0||n===0)&&(o||(o=[])).push({type:"zero_sized"});const s=new Ct(t,n,r,o);let l=!1;for(let c=0;!l&&c<a.length;c+=2)a[c]!=null&&a[c+1]<n&&(l=!0);return l&&DQe(s,a,e),s}function jQe(e){let t=-1,n=!1;for(let r=0;r<e.childCount;r++){const i=e.child(r);let o=0;if(n)for(let a=0;a<r;a++){const s=e.child(a);for(let l=0;l<s.childCount;l++){const c=s.child(l);a+c.attrs.rowspan>r&&(o+=c.attrs.colspan)}}for(let a=0;a<i.childCount;a++){const s=i.child(a);o+=s.attrs.colspan,s.attrs.rowspan>1&&(n=!0)}t==-1?t=o:t!=o&&(t=Math.max(t,o))}return t}function DQe(e,t,n){e.problems||(e.problems=[]);const r={};for(let i=0;i<e.map.length;i++){const o=e.map[i];if(r[o])continue;r[o]=!0;const a=n.nodeAt(o);if(!a)throw new RangeError(`No cell with offset ${o} found`);let s=null;const l=a.attrs;for(let c=0;c<l.colspan;c++){const u=(i+c)%e.width,f=t[u*2];f!=null&&(!l.colwidth||l.colwidth[c]!=f)&&((s||(s=LQe(l)))[c]=f)}s&&e.problems.unshift({type:"colwidth mismatch",pos:o,colwidth:s})}}function LQe(e){if(e.colwidth)return e.colwidth.slice();const t=[];for(let n=0;n<e.colspan;n++)t.push(0);return t}function fr(e){let t=e.cached.tableNodeTypes;if(!t){t=e.cached.tableNodeTypes={};for(const n in e.nodes){const r=e.nodes[n],i=r.spec.tableRole;i&&(t[i]=r)}}return t}var Js=new En("selectingCells");function eh(e){for(let t=e.depth-1;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return e.node(0).resolve(e.before(t+1));return null}function PQe(e){for(let t=e.depth;t>0;t--){const n=e.node(t).type.spec.tableRole;if(n==="cell"||n==="header_cell")return e.node(t)}return null}function Tr(e){const t=e.selection.$head;for(let n=t.depth;n>0;n--)if(t.node(n).type.spec.tableRole=="row")return!0;return!1}function LS(e){const t=e.selection;if("$anchorCell"in t&&t.$anchorCell)return t.$anchorCell.pos>t.$headCell.pos?t.$anchorCell:t.$headCell;if("node"in t&&t.node&&t.node.type.spec.tableRole=="cell")return t.$anchor;const n=eh(t.$head)||BQe(t.$head);if(n)return n;throw new RangeError(`No cell found around position ${t.head}`)}function BQe(e){for(let t=e.nodeAfter,n=e.pos;t;t=t.firstChild,n++){const r=t.type.spec.tableRole;if(r=="cell"||r=="header_cell")return e.doc.resolve(n)}for(let t=e.nodeBefore,n=e.pos;t;t=t.lastChild,n--){const r=t.type.spec.tableRole;if(r=="cell"||r=="header_cell")return e.doc.resolve(n-t.nodeSize)}}function MI(e){return e.parent.type.spec.tableRole=="row"&&!!e.nodeAfter}function UQe(e){return e.node(0).resolve(e.pos+e.nodeAfter.nodeSize)}function MD(e,t){return e.depth==t.depth&&e.pos>=t.start(-1)&&e.pos<=t.end(-1)}function jte(e,t,n){const r=e.node(-1),i=Ct.get(r),o=e.start(-1),a=i.nextCell(e.pos-o,t,n);return a==null?null:e.node(0).resolve(o+a)}function pu(e,t,n=1){const r={...e,colspan:e.colspan-n};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(t,n),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}function Dte(e,t,n=1){const r={...e,colspan:e.colspan+n};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let i=0;i<n;i++)r.colwidth.splice(t,0,0)}return r}function NQe(e,t,n){const r=fr(t.type.schema).header_cell;for(let i=0;i<e.height;i++)if(t.nodeAt(e.map[n+i*e.width]).type!=r)return!1;return!0}var at=class Da extends ke{constructor(t,n=t){const r=t.node(-1),i=Ct.get(r),o=t.start(-1),a=i.rectBetween(t.pos-o,n.pos-o),s=t.node(0),l=i.cellsInRect(a).filter(u=>u!=n.pos-o);l.unshift(n.pos-o);const c=l.map(u=>{const f=r.nodeAt(u);if(!f)throw RangeError(`No cell with offset ${u} found`);const p=o+u+1;return new kZ(s.resolve(p),s.resolve(p+f.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=t,this.$headCell=n}map(t,n){const r=t.resolve(n.map(this.$anchorCell.pos)),i=t.resolve(n.map(this.$headCell.pos));if(MI(r)&&MI(i)&&MD(r,i)){const o=this.$anchorCell.node(-1)!=r.node(-1);return o&&this.isRowSelection()?Da.rowSelection(r,i):o&&this.isColSelection()?Da.colSelection(r,i):new Da(r,i)}return _e.between(r,i)}content(){const t=this.$anchorCell.node(-1),n=Ct.get(t),r=this.$anchorCell.start(-1),i=n.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),o={},a=[];for(let l=i.top;l<i.bottom;l++){const c=[];for(let u=l*n.width+i.left,f=i.left;f<i.right;f++,u++){const p=n.map[u];if(o[p])continue;o[p]=!0;const h=n.findCell(p);let m=t.nodeAt(p);if(!m)throw RangeError(`No cell with offset ${p} found`);const g=i.left-h.left,y=h.right-i.right;if(g>0||y>0){let b=m.attrs;if(g>0&&(b=pu(b,0,g)),y>0&&(b=pu(b,b.colspan-y,y)),h.left<i.left){if(m=m.type.createAndFill(b),!m)throw RangeError(`Could not create cell with attrs ${JSON.stringify(b)}`)}else m=m.type.create(b,m.content)}if(h.top<i.top||h.bottom>i.bottom){const b={...m.attrs,rowspan:Math.min(h.bottom,i.bottom)-Math.max(h.top,i.top)};h.top<i.top?m=m.type.createAndFill(b):m=m.type.create(b,m.content)}c.push(m)}a.push(t.child(l).copy(U.from(c)))}const s=this.isColSelection()&&this.isRowSelection()?t:a;return new W(U.from(s),1,1)}replace(t,n=W.empty){const r=t.steps.length,i=this.ranges;for(let a=0;a<i.length;a++){const{$from:s,$to:l}=i[a],c=t.mapping.slice(r);t.replace(c.map(s.pos),c.map(l.pos),a?W.empty:n)}const o=ke.findFrom(t.doc.resolve(t.mapping.slice(r).map(this.to)),-1);o&&t.setSelection(o)}replaceWith(t,n){this.replace(t,new W(U.from(n),0,0))}forEachCell(t){const n=this.$anchorCell.node(-1),r=Ct.get(n),i=this.$anchorCell.start(-1),o=r.cellsInRect(r.rectBetween(this.$anchorCell.pos-i,this.$headCell.pos-i));for(let a=0;a<o.length;a++)t(n.nodeAt(o[a]),i+o[a])}isColSelection(){const t=this.$anchorCell.index(-1),n=this.$headCell.index(-1);if(Math.min(t,n)>0)return!1;const r=t+this.$anchorCell.nodeAfter.attrs.rowspan,i=n+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(t,n=t){const r=t.node(-1),i=Ct.get(r),o=t.start(-1),a=i.findCell(t.pos-o),s=i.findCell(n.pos-o),l=t.node(0);return a.top<=s.top?(a.top>0&&(t=l.resolve(o+i.map[a.left])),s.bottom<i.height&&(n=l.resolve(o+i.map[i.width*(i.height-1)+s.right-1]))):(s.top>0&&(n=l.resolve(o+i.map[s.left])),a.bottom<i.height&&(t=l.resolve(o+i.map[i.width*(i.height-1)+a.right-1]))),new Da(t,n)}isRowSelection(){const t=this.$anchorCell.node(-1),n=Ct.get(t),r=this.$anchorCell.start(-1),i=n.colCount(this.$anchorCell.pos-r),o=n.colCount(this.$headCell.pos-r);if(Math.min(i,o)>0)return!1;const a=i+this.$anchorCell.nodeAfter.attrs.colspan,s=o+this.$headCell.nodeAfter.attrs.colspan;return Math.max(a,s)==n.width}eq(t){return t instanceof Da&&t.$anchorCell.pos==this.$anchorCell.pos&&t.$headCell.pos==this.$headCell.pos}static rowSelection(t,n=t){const r=t.node(-1),i=Ct.get(r),o=t.start(-1),a=i.findCell(t.pos-o),s=i.findCell(n.pos-o),l=t.node(0);return a.left<=s.left?(a.left>0&&(t=l.resolve(o+i.map[a.top*i.width])),s.right<i.width&&(n=l.resolve(o+i.map[i.width*(s.top+1)-1]))):(s.left>0&&(n=l.resolve(o+i.map[s.top*i.width])),a.right<i.width&&(t=l.resolve(o+i.map[i.width*(a.top+1)-1]))),new Da(t,n)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(t,n){return new Da(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,r=n){return new Da(t.resolve(n),t.resolve(r))}getBookmark(){return new WQe(this.$anchorCell.pos,this.$headCell.pos)}};at.prototype.visible=!1;ke.jsonID("cell",at);var WQe=class Lte{constructor(t,n){this.anchor=t,this.head=n}map(t){return new Lte(t.map(this.anchor),t.map(this.head))}resolve(t){const n=t.resolve(this.anchor),r=t.resolve(this.head);return n.parent.type.spec.tableRole=="row"&&r.parent.type.spec.tableRole=="row"&&n.index()<n.parent.childCount&&r.index()<r.parent.childCount&&MD(n,r)?new at(n,r):ke.near(r,1)}};function KQe(e){if(!(e.selection instanceof at))return null;const t=[];return e.selection.forEachCell((n,r)=>{t.push(fn.node(r,r+n.nodeSize,{class:"selectedCell"}))}),vt.create(e.doc,t)}function qQe({$from:e,$to:t}){if(e.pos==t.pos||e.pos<t.pos-6)return!1;let n=e.pos,r=t.pos,i=e.depth;for(;i>=0&&!(e.after(i+1)<e.end(i));i--,n++);for(let o=t.depth;o>=0&&!(t.before(o+1)>t.start(o));o--,r--);return n==r&&/row|table/.test(e.node(i).type.spec.tableRole)}function VQe({$from:e,$to:t}){let n,r;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"){n=o;break}}for(let i=t.depth;i>0;i--){const o=t.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){r=o;break}}return n!==r&&t.parentOffset===0}function zQe(e,t,n){const r=(t||e).selection,i=(t||e).doc;let o,a;if(r instanceof Se&&(a=r.node.type.spec.tableRole)){if(a=="cell"||a=="header_cell")o=at.create(i,r.from);else if(a=="row"){const s=i.resolve(r.from+1);o=at.rowSelection(s,s)}else if(!n){const s=Ct.get(r.node),l=r.from+1,c=l+s.map[s.width*s.height-1];o=at.create(i,l+1,c)}}else r instanceof _e&&qQe(r)?o=_e.create(i,r.from):r instanceof _e&&VQe(r)&&(o=_e.create(i,r.$from.start(),r.$from.end()));return o&&(t||(t=e.tr)).setSelection(o),t}var QQe=new En("fix-tables");function Pte(e,t,n,r){const i=e.childCount,o=t.childCount;e:for(let a=0,s=0;a<o;a++){const l=t.child(a);for(let c=s,u=Math.min(i,a+3);c<u;c++)if(e.child(c)==l){s=c+1,n+=l.nodeSize;continue e}r(l,n),s<i&&e.child(s).sameMarkup(l)?Pte(e.child(s),l,n+1,r):l.nodesBetween(0,l.content.size,r,n+1),n+=l.nodeSize}}function Bte(e,t){let n;const r=(i,o)=>{i.type.spec.tableRole=="table"&&(n=HQe(e,i,o,n))};return t?t.doc!=e.doc&&Pte(t.doc,e.doc,0,r):e.doc.descendants(r),n}function HQe(e,t,n,r){const i=Ct.get(t);if(!i.problems)return r;r||(r=e.tr);const o=[];for(let l=0;l<i.height;l++)o.push(0);for(let l=0;l<i.problems.length;l++){const c=i.problems[l];if(c.type=="collision"){const u=t.nodeAt(c.pos);if(!u)continue;const f=u.attrs;for(let p=0;p<f.rowspan;p++)o[c.row+p]+=c.n;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,pu(f,f.colspan-c.n,c.n))}else if(c.type=="missing")o[c.row]+=c.n;else if(c.type=="overlong_rowspan"){const u=t.nodeAt(c.pos);if(!u)continue;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,{...u.attrs,rowspan:u.attrs.rowspan-c.n})}else if(c.type=="colwidth mismatch"){const u=t.nodeAt(c.pos);if(!u)continue;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,{...u.attrs,colwidth:c.colwidth})}else if(c.type=="zero_sized"){const u=r.mapping.map(n);r.delete(u,u+t.nodeSize)}}let a,s;for(let l=0;l<o.length;l++)o[l]&&(a==null&&(a=l),s=l);for(let l=0,c=n+1;l<i.height;l++){const u=t.child(l),f=c+u.nodeSize,p=o[l];if(p>0){let h="cell";u.firstChild&&(h=u.firstChild.type.spec.tableRole);const m=[];for(let y=0;y<p;y++){const b=fr(e.schema)[h].createAndFill();b&&m.push(b)}const g=(l==0||a==l-1)&&s==l?c+1:f-1;r.insert(r.mapping.map(g),m)}c=f}return r.setMeta(QQe,{fixTables:!0})}function $r(e){const t=e.selection,n=LS(e),r=n.node(-1),i=n.start(-1),o=Ct.get(r);return{...t instanceof at?o.rectBetween(t.$anchorCell.pos-i,t.$headCell.pos-i):o.findCell(n.pos-i),tableStart:i,map:o,table:r}}function FD(e,{map:t,tableStart:n,table:r},i){let o=i>0?-1:0;NQe(t,r,i+o)&&(o=i==0||i==t.width?null:0);for(let a=0;a<t.height;a++){const s=a*t.width+i;if(i>0&&i<t.width&&t.map[s-1]==t.map[s]){const l=t.map[s],c=r.nodeAt(l);e.setNodeMarkup(e.mapping.map(n+l),null,Dte(c.attrs,i-t.colCount(l))),a+=c.attrs.rowspan-1}else{const l=o==null?fr(r.type.schema).cell:r.nodeAt(t.map[s+o]).type,c=t.positionAt(a,i,r);e.insert(e.mapping.map(n+c),l.createAndFill())}}return e}function YQe(e,t){if(!Tr(e))return!1;if(t){const n=$r(e);t(FD(e.tr,n,n.left))}return!0}function GQe(e,t){if(!Tr(e))return!1;if(t){const n=$r(e);t(FD(e.tr,n,n.right))}return!0}function JQe(e,{map:t,table:n,tableStart:r},i){const o=e.mapping.maps.length;for(let a=0;a<t.height;){const s=a*t.width+i,l=t.map[s],c=n.nodeAt(l),u=c.attrs;if(i>0&&t.map[s-1]==l||i<t.width-1&&t.map[s+1]==l)e.setNodeMarkup(e.mapping.slice(o).map(r+l),null,pu(u,i-t.colCount(l)));else{const f=e.mapping.slice(o).map(r+l);e.delete(f,f+c.nodeSize)}a+=u.rowspan}}function ZQe(e,t){if(!Tr(e))return!1;if(t){const n=$r(e),r=e.tr;if(n.left==0&&n.right==n.map.width)return!1;for(let i=n.right-1;JQe(r,n,i),i!=n.left;i--){const o=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!o)throw RangeError("No table found");n.table=o,n.map=Ct.get(o)}t(r)}return!0}function XQe(e,t,n){var r;const i=fr(t.type.schema).header_cell;for(let o=0;o<e.width;o++)if(((r=t.nodeAt(e.map[o+n*e.width]))==null?void 0:r.type)!=i)return!1;return!0}function jD(e,{map:t,tableStart:n,table:r},i){var o;let a=n;for(let c=0;c<i;c++)a+=r.child(c).nodeSize;const s=[];let l=i>0?-1:0;XQe(t,r,i+l)&&(l=i==0||i==t.height?null:0);for(let c=0,u=t.width*i;c<t.width;c++,u++)if(i>0&&i<t.height&&t.map[u]==t.map[u-t.width]){const f=t.map[u],p=r.nodeAt(f).attrs;e.setNodeMarkup(n+f,null,{...p,rowspan:p.rowspan+1}),c+=p.colspan-1}else{const f=l==null?fr(r.type.schema).cell:(o=r.nodeAt(t.map[u+l*t.width]))==null?void 0:o.type,p=f==null?void 0:f.createAndFill();p&&s.push(p)}return e.insert(a,fr(r.type.schema).row.create(null,s)),e}function eHe(e,t){if(!Tr(e))return!1;if(t){const n=$r(e);t(jD(e.tr,n,n.top))}return!0}function tHe(e,t){if(!Tr(e))return!1;if(t){const n=$r(e);t(jD(e.tr,n,n.bottom))}return!0}function nHe(e,{map:t,table:n,tableStart:r},i){let o=0;for(let c=0;c<i;c++)o+=n.child(c).nodeSize;const a=o+n.child(i).nodeSize,s=e.mapping.maps.length;e.delete(o+r,a+r);const l=new Set;for(let c=0,u=i*t.width;c<t.width;c++,u++){const f=t.map[u];if(!l.has(f)){if(l.add(f),i>0&&f==t.map[u-t.width]){const p=n.nodeAt(f).attrs;e.setNodeMarkup(e.mapping.slice(s).map(f+r),null,{...p,rowspan:p.rowspan-1}),c+=p.colspan-1}else if(i<t.height&&f==t.map[u+t.width]){const p=n.nodeAt(f),h=p.attrs,m=p.type.create({...h,rowspan:p.attrs.rowspan-1},p.content),g=t.positionAt(i+1,c,n);e.insert(e.mapping.slice(s).map(r+g),m),c+=h.colspan-1}}}}function rHe(e,t){if(!Tr(e))return!1;if(t){const n=$r(e),r=e.tr;if(n.top==0&&n.bottom==n.map.height)return!1;for(let i=n.bottom-1;nHe(r,n,i),i!=n.top;i--){const o=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!o)throw RangeError("No table found");n.table=o,n.map=Ct.get(n.table)}t(r)}return!0}function hU(e){const t=e.content;return t.childCount==1&&t.child(0).isTextblock&&t.child(0).childCount==0}function iHe({width:e,height:t,map:n},r){let i=r.top*e+r.left,o=i,a=(r.bottom-1)*e+r.left,s=i+(r.right-r.left-1);for(let l=r.top;l<r.bottom;l++){if(r.left>0&&n[o]==n[o-1]||r.right<e&&n[s]==n[s+1])return!0;o+=e,s+=e}for(let l=r.left;l<r.right;l++){if(r.top>0&&n[i]==n[i-e]||r.bottom<t&&n[a]==n[a+e])return!0;i++,a++}return!1}function mU(e,t){const n=e.selection;if(!(n instanceof at)||n.$anchorCell.pos==n.$headCell.pos)return!1;const r=$r(e),{map:i}=r;if(iHe(i,r))return!1;if(t){const o=e.tr,a={};let s=U.empty,l,c;for(let u=r.top;u<r.bottom;u++)for(let f=r.left;f<r.right;f++){const p=i.map[u*i.width+f],h=r.table.nodeAt(p);if(!(a[p]||!h))if(a[p]=!0,l==null)l=p,c=h;else{hU(h)||(s=s.append(h.content));const m=o.mapping.map(p+r.tableStart);o.delete(m,m+h.nodeSize)}}if(l==null||c==null)return!0;if(o.setNodeMarkup(l+r.tableStart,null,{...Dte(c.attrs,c.attrs.colspan,r.right-r.left-c.attrs.colspan),rowspan:r.bottom-r.top}),s.size){const u=l+1+c.content.size,f=hU(c)?l+1:u;o.replaceWith(f+r.tableStart,u+r.tableStart,s)}o.setSelection(new at(o.doc.resolve(l+r.tableStart))),t(o)}return!0}function AU(e,t){const n=fr(e.schema);return oHe(({node:r})=>n[r.type.spec.tableRole])(e,t)}function oHe(e){return(t,n)=>{var r;const i=t.selection;let o,a;if(i instanceof at){if(i.$anchorCell.pos!=i.$headCell.pos)return!1;o=i.$anchorCell.nodeAfter,a=i.$anchorCell.pos}else{if(o=PQe(i.$from),!o)return!1;a=(r=eh(i.$from))==null?void 0:r.pos}if(o==null||a==null||o.attrs.colspan==1&&o.attrs.rowspan==1)return!1;if(n){let s=o.attrs;const l=[],c=s.colwidth;s.rowspan>1&&(s={...s,rowspan:1}),s.colspan>1&&(s={...s,colspan:1});const u=$r(t),f=t.tr;for(let h=0;h<u.right-u.left;h++)l.push(c?{...s,colwidth:c&&c[h]?[c[h]]:null}:s);let p;for(let h=u.top;h<u.bottom;h++){let m=u.map.positionAt(h,u.left,u.table);h==u.top&&(m+=o.nodeSize);for(let g=u.left,y=0;g<u.right;g++,y++)g==u.left&&h==u.top||f.insert(p=f.mapping.map(m+u.tableStart,1),e({node:o,row:h,col:g}).createAndFill(l[y]))}f.setNodeMarkup(a,e({node:o,row:u.top,col:u.left}),l[0]),i instanceof at&&f.setSelection(new at(f.doc.resolve(i.$anchorCell.pos),p?f.doc.resolve(p):void 0)),n(f)}return!0}}function aHe(e,t){return function(n,r){if(!Tr(n))return!1;const i=LS(n);if(i.nodeAfter.attrs[e]===t)return!1;if(r){const o=n.tr;n.selection instanceof at?n.selection.forEachCell((a,s)=>{a.attrs[e]!==t&&o.setNodeMarkup(s,null,{...a.attrs,[e]:t})}):o.setNodeMarkup(i.pos,null,{...i.nodeAfter.attrs,[e]:t}),r(o)}return!0}}function sHe(e){return function(t,n){if(!Tr(t))return!1;if(n){const r=fr(t.schema),i=$r(t),o=t.tr,a=i.map.cellsInRect(e=="column"?{left:i.left,top:0,right:i.right,bottom:i.map.height}:e=="row"?{left:0,top:i.top,right:i.map.width,bottom:i.bottom}:i),s=a.map(l=>i.table.nodeAt(l));for(let l=0;l<a.length;l++)s[l].type==r.header_cell&&o.setNodeMarkup(i.tableStart+a[l],r.cell,s[l].attrs);if(o.steps.length==0)for(let l=0;l<a.length;l++)o.setNodeMarkup(i.tableStart+a[l],r.header_cell,s[l].attrs);n(o)}return!0}}function gU(e,t,n){const r=t.map.cellsInRect({left:0,top:0,right:e=="row"?t.map.width:1,bottom:e=="column"?t.map.height:1});for(let i=0;i<r.length;i++){const o=t.table.nodeAt(r[i]);if(o&&o.type!==n.header_cell)return!1}return!0}function Km(e,t){return t=t||{useDeprecatedLogic:!1},t.useDeprecatedLogic?sHe(e):function(n,r){if(!Tr(n))return!1;if(r){const i=fr(n.schema),o=$r(n),a=n.tr,s=gU("row",o,i),l=gU("column",o,i),u=(e==="column"?s:e==="row"?l:!1)?1:0,f=e=="column"?{left:0,top:u,right:1,bottom:o.map.height}:e=="row"?{left:u,top:0,right:o.map.width,bottom:1}:o,p=e=="column"?l?i.cell:i.header_cell:e=="row"?s?i.cell:i.header_cell:i.cell;o.map.cellsInRect(f).forEach(h=>{const m=h+o.tableStart,g=a.doc.nodeAt(m);g&&a.setNodeMarkup(m,p,g.attrs)}),r(a)}return!0}}Km("row",{useDeprecatedLogic:!0});Km("column",{useDeprecatedLogic:!0});var lHe=Km("cell",{useDeprecatedLogic:!0});function cHe(e,t){if(t<0){const n=e.nodeBefore;if(n)return e.pos-n.nodeSize;for(let r=e.index(-1)-1,i=e.before();r>=0;r--){const o=e.node(-1).child(r),a=o.lastChild;if(a)return i-1-a.nodeSize;i-=o.nodeSize}}else{if(e.index()<e.parent.childCount-1)return e.pos+e.nodeAfter.nodeSize;const n=e.node(-1);for(let r=e.indexAfter(-1),i=e.after();r<n.childCount;r++){const o=n.child(r);if(o.childCount)return i+1;i+=o.nodeSize}}return null}function vU(e){return function(t,n){if(!Tr(t))return!1;const r=cHe(LS(t),e);if(r==null)return!1;if(n){const i=t.doc.resolve(r);n(t.tr.setSelection(_e.between(i,UQe(i))).scrollIntoView())}return!0}}function uHe(e,t){const n=e.selection.$anchor;for(let r=n.depth;r>0;r--)if(n.node(r).type.spec.tableRole=="table")return t&&t(e.tr.delete(n.before(r),n.after(r)).scrollIntoView()),!0;return!1}function Fv(e,t){const n=e.selection;if(!(n instanceof at))return!1;if(t){const r=e.tr,i=fr(e.schema).cell.createAndFill().content;n.forEachCell((o,a)=>{o.content.eq(i)||r.replace(r.mapping.map(a+1),r.mapping.map(a+o.nodeSize-1),new W(i,0,0))}),r.docChanged&&t(r)}return!0}function dHe(e){if(!e.size)return null;let{content:t,openStart:n,openEnd:r}=e;for(;t.childCount==1&&(n>0&&r>0||t.child(0).type.spec.tableRole=="table");)n--,r--,t=t.child(0).content;const i=t.child(0),o=i.type.spec.tableRole,a=i.type.schema,s=[];if(o=="row")for(let l=0;l<t.childCount;l++){let c=t.child(l).content;const u=l?0:Math.max(0,n-1),f=l<t.childCount-1?0:Math.max(0,r-1);(u||f)&&(c=FI(fr(a).row,new W(c,u,f)).content),s.push(c)}else if(o=="cell"||o=="header_cell")s.push(n||r?FI(fr(a).row,new W(t,n,r)).content:t);else return null;return fHe(a,s)}function fHe(e,t){const n=[];for(let i=0;i<t.length;i++){const o=t[i];for(let a=o.childCount-1;a>=0;a--){const{rowspan:s,colspan:l}=o.child(a).attrs;for(let c=i;c<i+s;c++)n[c]=(n[c]||0)+l}}let r=0;for(let i=0;i<n.length;i++)r=Math.max(r,n[i]);for(let i=0;i<n.length;i++)if(i>=t.length&&t.push(U.empty),n[i]<r){const o=fr(e).cell.createAndFill(),a=[];for(let s=n[i];s<r;s++)a.push(o);t[i]=t[i].append(U.from(a))}return{height:t.length,width:r,rows:t}}function FI(e,t){const n=e.createAndFill();return new MQe(n).replace(0,n.content.size,t).doc}function pHe({width:e,height:t,rows:n},r,i){if(e!=r){const o=[],a=[];for(let s=0;s<n.length;s++){const l=n[s],c=[];for(let u=o[s]||0,f=0;u<r;f++){let p=l.child(f%l.childCount);u+p.attrs.colspan>r&&(p=p.type.createChecked(pu(p.attrs,p.attrs.colspan,u+p.attrs.colspan-r),p.content)),c.push(p),u+=p.attrs.colspan;for(let h=1;h<p.attrs.rowspan;h++)o[s+h]=(o[s+h]||0)+p.attrs.colspan}a.push(U.from(c))}n=a,e=r}if(t!=i){const o=[];for(let a=0,s=0;a<i;a++,s++){const l=[],c=n[s%t];for(let u=0;u<c.childCount;u++){let f=c.child(u);a+f.attrs.rowspan>i&&(f=f.type.create({...f.attrs,rowspan:Math.max(1,i-f.attrs.rowspan)},f.content)),l.push(f)}o.push(U.from(l))}n=o,t=i}return{width:e,height:t,rows:n}}function hHe(e,t,n,r,i,o,a){const s=e.doc.type.schema,l=fr(s);let c,u;if(i>t.width)for(let f=0,p=0;f<t.height;f++){const h=n.child(f);p+=h.nodeSize;const m=[];let g;h.lastChild==null||h.lastChild.type==l.cell?g=c||(c=l.cell.createAndFill()):g=u||(u=l.header_cell.createAndFill());for(let y=t.width;y<i;y++)m.push(g);e.insert(e.mapping.slice(a).map(p-1+r),m)}if(o>t.height){const f=[];for(let m=0,g=(t.height-1)*t.width;m<Math.max(t.width,i);m++){const y=m>=t.width?!1:n.nodeAt(t.map[g+m]).type==l.header_cell;f.push(y?u||(u=l.header_cell.createAndFill()):c||(c=l.cell.createAndFill()))}const p=l.row.create(null,U.from(f)),h=[];for(let m=t.height;m<o;m++)h.push(p);e.insert(e.mapping.slice(a).map(r+n.nodeSize-2),h)}return!!(c||u)}function yU(e,t,n,r,i,o,a,s){if(a==0||a==t.height)return!1;let l=!1;for(let c=i;c<o;c++){const u=a*t.width+c,f=t.map[u];if(t.map[u-t.width]==f){l=!0;const p=n.nodeAt(f),{top:h,left:m}=t.findCell(f);e.setNodeMarkup(e.mapping.slice(s).map(f+r),null,{...p.attrs,rowspan:a-h}),e.insert(e.mapping.slice(s).map(t.positionAt(a,m,n)),p.type.createAndFill({...p.attrs,rowspan:h+p.attrs.rowspan-a})),c+=p.attrs.colspan-1}}return l}function bU(e,t,n,r,i,o,a,s){if(a==0||a==t.width)return!1;let l=!1;for(let c=i;c<o;c++){const u=c*t.width+a,f=t.map[u];if(t.map[u-1]==f){l=!0;const p=n.nodeAt(f),h=t.colCount(f),m=e.mapping.slice(s).map(f+r);e.setNodeMarkup(m,null,pu(p.attrs,a-h,p.attrs.colspan-(a-h))),e.insert(m+p.nodeSize,p.type.createAndFill(pu(p.attrs,0,a-h))),c+=p.attrs.rowspan-1}}return l}function CU(e,t,n,r,i){let o=n?e.doc.nodeAt(n-1):e.doc;if(!o)throw new Error("No table found");let a=Ct.get(o);const{top:s,left:l}=r,c=l+i.width,u=s+i.height,f=e.tr;let p=0;function h(){if(o=n?f.doc.nodeAt(n-1):f.doc,!o)throw new Error("No table found");a=Ct.get(o),p=f.mapping.maps.length}hHe(f,a,o,n,c,u,p)&&h(),yU(f,a,o,n,l,c,s,p)&&h(),yU(f,a,o,n,l,c,u,p)&&h(),bU(f,a,o,n,s,u,l,p)&&h(),bU(f,a,o,n,s,u,c,p)&&h();for(let m=s;m<u;m++){const g=a.positionAt(m,l,o),y=a.positionAt(m,c,o);f.replace(f.mapping.slice(p).map(g+n),f.mapping.slice(p).map(y+n),new W(i.rows[m-s],0,0))}h(),f.setSelection(new at(f.doc.resolve(n+a.positionAt(s,l,o)),f.doc.resolve(n+a.positionAt(u-1,c-1,o)))),t(f)}var mHe=pX({ArrowLeft:jv("horiz",-1),ArrowRight:jv("horiz",1),ArrowUp:jv("vert",-1),ArrowDown:jv("vert",1),"Shift-ArrowLeft":Dv("horiz",-1),"Shift-ArrowRight":Dv("horiz",1),"Shift-ArrowUp":Dv("vert",-1),"Shift-ArrowDown":Dv("vert",1),Backspace:Fv,"Mod-Backspace":Fv,Delete:Fv,"Mod-Delete":Fv});function ay(e,t,n){return n.eq(e.selection)?!1:(t&&t(e.tr.setSelection(n).scrollIntoView()),!0)}function jv(e,t){return(n,r,i)=>{if(!i)return!1;const o=n.selection;if(o instanceof at)return ay(n,r,ke.near(o.$headCell,t));if(e!="horiz"&&!o.empty)return!1;const a=Ute(i,e,t);if(a==null)return!1;if(e=="horiz")return ay(n,r,ke.near(n.doc.resolve(o.head+t),t));{const s=n.doc.resolve(a),l=jte(s,e,t);let c;return l?c=ke.near(l,1):t<0?c=ke.near(n.doc.resolve(s.before(-1)),-1):c=ke.near(n.doc.resolve(s.after(-1)),1),ay(n,r,c)}}}function Dv(e,t){return(n,r,i)=>{if(!i)return!1;const o=n.selection;let a;if(o instanceof at)a=o;else{const l=Ute(i,e,t);if(l==null)return!1;a=new at(n.doc.resolve(l))}const s=jte(a.$headCell,e,t);return s?ay(n,r,new at(a.$anchorCell,s)):!1}}function AHe(e,t){const n=e.state.doc,r=eh(n.resolve(t));return r?(e.dispatch(e.state.tr.setSelection(new at(r))),!0):!1}function gHe(e,t,n){if(!Tr(e.state))return!1;let r=dHe(n);const i=e.state.selection;if(i instanceof at){r||(r={width:1,height:1,rows:[U.from(FI(fr(e.state.schema).cell,n))]});const o=i.$anchorCell.node(-1),a=i.$anchorCell.start(-1),s=Ct.get(o).rectBetween(i.$anchorCell.pos-a,i.$headCell.pos-a);return r=pHe(r,s.right-s.left,s.bottom-s.top),CU(e.state,e.dispatch,a,s,r),!0}else if(r){const o=LS(e.state),a=o.start(-1);return CU(e.state,e.dispatch,a,Ct.get(o.node(-1)).findCell(o.pos-a),r),!0}else return!1}function vHe(e,t){var n;if(t.ctrlKey||t.metaKey)return;const r=SU(e,t.target);let i;if(t.shiftKey&&e.state.selection instanceof at)o(e.state.selection.$anchorCell,t),t.preventDefault();else if(t.shiftKey&&r&&(i=eh(e.state.selection.$anchor))!=null&&((n=qx(e,t))==null?void 0:n.pos)!=i.pos)o(i,t),t.preventDefault();else if(!r)return;function o(l,c){let u=qx(e,c);const f=Js.getState(e.state)==null;if(!u||!MD(l,u))if(f)u=l;else return;const p=new at(l,u);if(f||!e.state.selection.eq(p)){const h=e.state.tr.setSelection(p);f&&h.setMeta(Js,l.pos),e.dispatch(h)}}function a(){e.root.removeEventListener("mouseup",a),e.root.removeEventListener("dragstart",a),e.root.removeEventListener("mousemove",s),Js.getState(e.state)!=null&&e.dispatch(e.state.tr.setMeta(Js,-1))}function s(l){const c=l,u=Js.getState(e.state);let f;if(u!=null)f=e.state.doc.resolve(u);else if(SU(e,c.target)!=r&&(f=qx(e,t),!f))return a();f&&o(f,c)}e.root.addEventListener("mouseup",a),e.root.addEventListener("dragstart",a),e.root.addEventListener("mousemove",s)}function Ute(e,t,n){if(!(e.state.selection instanceof _e))return null;const{$head:r}=e.state.selection;for(let i=r.depth-1;i>=0;i--){const o=r.node(i);if((n<0?r.index(i):r.indexAfter(i))!=(n<0?0:o.childCount))return null;if(o.type.spec.tableRole=="cell"||o.type.spec.tableRole=="header_cell"){const s=r.before(i),l=t=="vert"?n>0?"down":"up":n>0?"right":"left";return e.endOfTextblock(l)?s:null}}return null}function SU(e,t){for(;t&&t!=e.dom;t=t.parentNode)if(t.nodeName=="TD"||t.nodeName=="TH")return t;return null}function qx(e,t){const n=e.posAtCoords({left:t.clientX,top:t.clientY});return n&&n?eh(e.state.doc.resolve(n.pos)):null}var Nte=class{constructor(t,n){this.node=t,this.defaultCellMinWidth=n,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.table.style.setProperty("--default-cell-min-width",`${n}px`),this.colgroup=this.table.appendChild(document.createElement("colgroup")),jI(t,this.colgroup,this.table,n),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(t){return t.type!=this.node.type?!1:(this.node=t,jI(t,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(t){return t.type=="attributes"&&(t.target==this.table||this.colgroup.contains(t.target))}};function jI(e,t,n,r,i,o){var a;let s=0,l=!0,c=t.firstChild;const u=e.firstChild;if(u){for(let f=0,p=0;f<u.childCount;f++){const{colspan:h,colwidth:m}=u.child(f).attrs;for(let g=0;g<h;g++,p++){const y=i==p?o:m&&m[g],b=y?y+"px":"";if(s+=y||r,y||(l=!1),c)c.style.width!=b&&(c.style.width=b),c=c.nextSibling;else{const x=document.createElement("col");x.style.width=b,t.appendChild(x)}}}for(;c;){const f=c.nextSibling;(a=c.parentNode)==null||a.removeChild(c),c=f}l?(n.style.width=s+"px",n.style.minWidth=""):(n.style.width="",n.style.minWidth=s+"px")}}var Vr=new En("tableColumnResizing");function Wte({handleWidth:e=5,cellMinWidth:t=25,defaultCellMinWidth:n=100,View:r=Nte,lastColumnResizable:i=!0}={}){const o=new cn({key:Vr,state:{init(a,s){var l,c;const u=(c=(l=o.spec)==null?void 0:l.props)==null?void 0:c.nodeViews,f=fr(s.schema).table.name;return r&&u&&(u[f]=(p,h)=>new r(p,n,h)),new yHe(-1,!1)},apply(a,s){return s.apply(a)}},props:{attributes:a=>{const s=Vr.getState(a);return s&&s.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(a,s)=>{bHe(a,s,e,i)},mouseleave:a=>{CHe(a)},mousedown:(a,s)=>{SHe(a,s,t,n)}},decorations:a=>{const s=Vr.getState(a);if(s&&s.activeHandle>-1)return _He(a,s.activeHandle)},nodeViews:{}}});return o}var yHe=class sy{constructor(t,n){this.activeHandle=t,this.dragging=n}apply(t){const n=this,r=t.getMeta(Vr);if(r&&r.setHandle!=null)return new sy(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new sy(n.activeHandle,r.setDragging);if(n.activeHandle>-1&&t.docChanged){let i=t.mapping.map(n.activeHandle,-1);return MI(t.doc.resolve(i))||(i=-1),new sy(i,n.dragging)}return n}};function bHe(e,t,n,r){if(!e.editable)return;const i=Vr.getState(e.state);if(i&&!i.dragging){const o=xHe(t.target);let a=-1;if(o){const{left:s,right:l}=o.getBoundingClientRect();t.clientX-s<=n?a=wU(e,t,"left",n):l-t.clientX<=n&&(a=wU(e,t,"right",n))}if(a!=i.activeHandle){if(!r&&a!==-1){const s=e.state.doc.resolve(a),l=s.node(-1),c=Ct.get(l),u=s.start(-1);if(c.colCount(s.pos-u)+s.nodeAfter.attrs.colspan-1==c.width-1)return}Kte(e,a)}}}function CHe(e){if(!e.editable)return;const t=Vr.getState(e.state);t&&t.activeHandle>-1&&!t.dragging&&Kte(e,-1)}function SHe(e,t,n,r){var i;if(!e.editable)return!1;const o=(i=e.dom.ownerDocument.defaultView)!=null?i:window,a=Vr.getState(e.state);if(!a||a.activeHandle==-1||a.dragging)return!1;const s=e.state.doc.nodeAt(a.activeHandle),l=wHe(e,a.activeHandle,s.attrs);e.dispatch(e.state.tr.setMeta(Vr,{setDragging:{startX:t.clientX,startWidth:l}}));function c(f){o.removeEventListener("mouseup",c),o.removeEventListener("mousemove",u);const p=Vr.getState(e.state);p!=null&&p.dragging&&(THe(e,p.activeHandle,xU(p.dragging,f,n)),e.dispatch(e.state.tr.setMeta(Vr,{setDragging:null})))}function u(f){if(!f.which)return c(f);const p=Vr.getState(e.state);if(p&&p.dragging){const h=xU(p.dragging,f,n);TU(e,p.activeHandle,h,r)}}return TU(e,a.activeHandle,l,r),o.addEventListener("mouseup",c),o.addEventListener("mousemove",u),t.preventDefault(),!0}function wHe(e,t,{colspan:n,colwidth:r}){const i=r&&r[r.length-1];if(i)return i;const o=e.domAtPos(t);let s=o.node.childNodes[o.offset].offsetWidth,l=n;if(r)for(let c=0;c<n;c++)r[c]&&(s-=r[c],l--);return s/l}function xHe(e){for(;e&&e.nodeName!="TD"&&e.nodeName!="TH";)e=e.classList&&e.classList.contains("ProseMirror")?null:e.parentNode;return e}function wU(e,t,n,r){const i=n=="right"?-r:r,o=e.posAtCoords({left:t.clientX+i,top:t.clientY});if(!o)return-1;const{pos:a}=o,s=eh(e.state.doc.resolve(a));if(!s)return-1;if(n=="right")return s.pos;const l=Ct.get(s.node(-1)),c=s.start(-1),u=l.map.indexOf(s.pos-c);return u%l.width==0?-1:c+l.map[u-1]}function xU(e,t,n){const r=t.clientX-e.startX;return Math.max(n,e.startWidth+r)}function Kte(e,t){e.dispatch(e.state.tr.setMeta(Vr,{setHandle:t}))}function THe(e,t,n){const r=e.state.doc.resolve(t),i=r.node(-1),o=Ct.get(i),a=r.start(-1),s=o.colCount(r.pos-a)+r.nodeAfter.attrs.colspan-1,l=e.state.tr;for(let c=0;c<o.height;c++){const u=c*o.width+s;if(c&&o.map[u]==o.map[u-o.width])continue;const f=o.map[u],p=i.nodeAt(f).attrs,h=p.colspan==1?0:s-o.colCount(f);if(p.colwidth&&p.colwidth[h]==n)continue;const m=p.colwidth?p.colwidth.slice():IHe(p.colspan);m[h]=n,l.setNodeMarkup(a+f,null,{...p,colwidth:m})}l.docChanged&&e.dispatch(l)}function TU(e,t,n,r){const i=e.state.doc.resolve(t),o=i.node(-1),a=i.start(-1),s=Ct.get(o).colCount(i.pos-a)+i.nodeAfter.attrs.colspan-1;let l=e.domAtPos(i.start(-1)).node;for(;l&&l.nodeName!="TABLE";)l=l.parentNode;l&&jI(o,l.firstChild,l,r,s,n)}function IHe(e){return Array(e).fill(0)}function _He(e,t){var n;const r=[],i=e.doc.resolve(t),o=i.node(-1);if(!o)return vt.empty;const a=Ct.get(o),s=i.start(-1),l=a.colCount(i.pos-s)+i.nodeAfter.attrs.colspan-1;for(let c=0;c<a.height;c++){const u=l+c*a.width;if((l==a.width-1||a.map[u]!=a.map[u+1])&&(c==0||a.map[u]!=a.map[u-a.width])){const f=a.map[u],p=s+f+o.nodeAt(f).nodeSize-1,h=document.createElement("div");h.className="column-resize-handle",(n=Vr.getState(e))!=null&&n.dragging&&r.push(fn.node(s+f,s+f+o.nodeAt(f).nodeSize,{class:"column-resize-dragging"})),r.push(fn.widget(p,h))}}return vt.create(e.doc,r)}function qte({allowTableNodeSelection:e=!1}={}){return new cn({key:Js,state:{init(){return null},apply(t,n){const r=t.getMeta(Js);if(r!=null)return r==-1?null:r;if(n==null||!t.docChanged)return n;const{deleted:i,pos:o}=t.mapping.mapResult(n);return i?null:o}},props:{decorations:KQe,handleDOMEvents:{mousedown:vHe},createSelectionBetween(t){return Js.getState(t.state)!=null?t.state.selection:null},handleTripleClick:AHe,handleKeyDown:mHe,handlePaste:gHe},appendTransaction(t,n,r){return zQe(r,Bte(r,n),e)}})}function DI(e,t){return t?["width",`${Math.max(t,e)}px`]:["min-width",`${e}px`]}function IU(e,t,n,r,i,o){var a;let s=0,l=!0,c=t.firstChild;const u=e.firstChild;if(u!==null)for(let f=0,p=0;f<u.childCount;f+=1){const{colspan:h,colwidth:m}=u.child(f).attrs;for(let g=0;g<h;g+=1,p+=1){const y=i===p?o:m&&m[g],b=y?`${y}px`:"";if(s+=y||r,y||(l=!1),c){if(c.style.width!==b){const[x,w]=DI(r,y);c.style.setProperty(x,w)}c=c.nextSibling}else{const x=document.createElement("col"),[w,v]=DI(r,y);x.style.setProperty(w,v),t.appendChild(x)}}}for(;c;){const f=c.nextSibling;(a=c.parentNode)===null||a===void 0||a.removeChild(c),c=f}l?(n.style.width=`${s}px`,n.style.minWidth=""):(n.style.width="",n.style.minWidth=`${s}px`)}let EHe=class{constructor(t,n){this.node=t,this.cellMinWidth=n,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")),IU(t,this.colgroup,this.table,n),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(t){return t.type!==this.node.type?!1:(this.node=t,IU(t,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(t){return t.type==="attributes"&&(t.target===this.table||this.colgroup.contains(t.target))}};function RHe(e,t,n,r){let i=0,o=!0;const a=[],s=e.firstChild;if(!s)return{};for(let f=0,p=0;f<s.childCount;f+=1){const{colspan:h,colwidth:m}=s.child(f).attrs;for(let g=0;g<h;g+=1,p+=1){const y=n===p?r:m&&m[g];i+=y||t,y||(o=!1);const[b,x]=DI(t,y);a.push(["col",{style:`${b}: ${x}`}])}}const l=o?`${i}px`:"",c=o?"":`${i}px`;return{colgroup:["colgroup",{},...a],tableWidth:l,tableMinWidth:c}}function _U(e,t){return t?e.createChecked(null,t):e.createAndFill()}function kHe(e){if(e.cached.tableNodeTypes)return e.cached.tableNodeTypes;const t={};return Object.keys(e.nodes).forEach(n=>{const r=e.nodes[n];r.spec.tableRole&&(t[r.spec.tableRole]=r)}),e.cached.tableNodeTypes=t,t}function $He(e,t,n,r,i){const o=kHe(e),a=[],s=[];for(let c=0;c<n;c+=1){const u=_U(o.cell,i);if(u&&s.push(u),r){const f=_U(o.header_cell,i);f&&a.push(f)}}const l=[];for(let c=0;c<t;c+=1)l.push(o.row.createChecked(null,r&&c===0?a:s));return o.table.createChecked(null,l)}function OHe(e){return e instanceof at}const Lv=({editor:e})=>{const{selection:t}=e.state;if(!OHe(t))return!1;let n=0;const r=nee(t.ranges[0].$from,o=>o.type.name==="table");return r==null||r.node.descendants(o=>{if(o.type.name==="table")return!1;["tableCell","tableHeader"].includes(o.type.name)&&(n+=1)}),n===t.ranges.length?(e.commands.deleteTable(),!0):!1},MHe=Cn.create({name:"table",addOptions(){return{HTMLAttributes:{},resizable:!1,handleWidth:5,cellMinWidth:25,View:EHe,lastColumnResizable:!0,allowTableNodeSelection:!1}},content:"tableRow+",tableRole:"table",isolating:!0,group:"block",parseHTML(){return[{tag:"table"}]},renderHTML({node:e,HTMLAttributes:t}){const{colgroup:n,tableWidth:r,tableMinWidth:i}=RHe(e,this.options.cellMinWidth);return["table",Nt(this.options.HTMLAttributes,t,{style:r?`width: ${r}`:`min-width: ${i}`}),n,["tbody",0]]},addCommands(){return{insertTable:({rows:e=3,cols:t=3,withHeaderRow:n=!0}={})=>({tr:r,dispatch:i,editor:o})=>{const a=$He(o.schema,e,t,n);if(i){const s=r.selection.from+1;r.replaceSelectionWith(a).scrollIntoView().setSelection(_e.near(r.doc.resolve(s)))}return!0},addColumnBefore:()=>({state:e,dispatch:t})=>YQe(e,t),addColumnAfter:()=>({state:e,dispatch:t})=>GQe(e,t),deleteColumn:()=>({state:e,dispatch:t})=>ZQe(e,t),addRowBefore:()=>({state:e,dispatch:t})=>eHe(e,t),addRowAfter:()=>({state:e,dispatch:t})=>tHe(e,t),deleteRow:()=>({state:e,dispatch:t})=>rHe(e,t),deleteTable:()=>({state:e,dispatch:t})=>uHe(e,t),mergeCells:()=>({state:e,dispatch:t})=>mU(e,t),splitCell:()=>({state:e,dispatch:t})=>AU(e,t),toggleHeaderColumn:()=>({state:e,dispatch:t})=>Km("column")(e,t),toggleHeaderRow:()=>({state:e,dispatch:t})=>Km("row")(e,t),toggleHeaderCell:()=>({state:e,dispatch:t})=>lHe(e,t),mergeOrSplit:()=>({state:e,dispatch:t})=>mU(e,t)?!0:AU(e,t),setCellAttribute:(e,t)=>({state:n,dispatch:r})=>aHe(e,t)(n,r),goToNextCell:()=>({state:e,dispatch:t})=>vU(1)(e,t),goToPreviousCell:()=>({state:e,dispatch:t})=>vU(-1)(e,t),fixTables:()=>({state:e,dispatch:t})=>(t&&Bte(e),!0),setCellSelection:e=>({tr:t,dispatch:n})=>{if(n){const r=at.create(t.doc,e.anchorCell,e.headCell);t.setSelection(r)}return!0}}},addKeyboardShortcuts(){return{Tab:()=>this.editor.commands.goToNextCell()?!0:this.editor.can().addRowAfter()?this.editor.chain().addRowAfter().goToNextCell().run():!1,"Shift-Tab":()=>this.editor.commands.goToPreviousCell(),Backspace:Lv,"Mod-Backspace":Lv,Delete:Lv,"Mod-Delete":Lv}},addProseMirrorPlugins(){return[...this.options.resizable&&this.editor.isEditable?[Wte({handleWidth:this.options.handleWidth,cellMinWidth:this.options.cellMinWidth,defaultCellMinWidth:this.options.cellMinWidth,View:this.options.View,lastColumnResizable:this.options.lastColumnResizable})]:[],qte({allowTableNodeSelection:this.options.allowTableNodeSelection})]},extendNodeSchema(e){const t={name:e.name,options:e.options,storage:e.storage};return{tableRole:Ne(de(e,"tableRole",t))}}});function FHe(e){return new cn({key:new En("tableCellFocus"),props:{decorations(t){const{doc:n,selection:r}=t,{isEditable:i,isFocused:o}=e;if(!i||!o||r instanceof at)return vt.create(n,[]);const a=[],{anchor:s}=r;return n.descendants((l,c)=>l.isText||!(s>=c&&s<=c+l.nodeSize-1)?!1:l.type.name==="tableCell"||l.type.name==="tableHeader"?(a.push(fn.node(c,c+l.nodeSize,{class:"focusedCell"})),!1):!0),vt.create(n,a)}}})}function Vte(e,t,n,r){switch(n.type){case"hyperlink":case"paragraph":case"strong":case"em":return Gr.converter.fromPrismic(e,t,r)(n);default:return}}function zte(e){const{title:t,className:n,onClick:r,tabIndex:i,onMouseDown:o,contentEditable:a,...s}=e,l=document.createElement("button");return l.className=n,l.setAttribute("type","button"),l.setAttribute("title",t),l.setAttribute("aria-label",t),l.setAttribute("tabIndex","0"),a!=null&&l.setAttribute("contentEditable",String(a)),o&&l.addEventListener("mousedown",c=>{const u=c.currentTarget;o(c,u)}),l.addEventListener("click",c=>{const u=c.currentTarget;r(c,u)}),Object.entries(s).forEach(([c,u])=>{l.setAttribute(c,u.toString())}),l}function Qte(e){const t=document.createElement("div");return t.innerHTML=e,t.firstChild?t.firstChild:null}class lo extends CustomEvent{constructor({name:t,detail:n}){super(t,{detail:n})}static dispatch(t,n){const{editor:r,...i}=n;r.view.dom.dispatchEvent(new lo({name:t,detail:i}))}static listen(t,n){const{editor:r,callback:i}=n,o=new AbortController;return r.view.dom.addEventListener(t,a=>{const{detail:s}=a;s&&i(s)},{signal:o.signal}),()=>o.abort()}}const jHe=50,DHe=25;function PS(e,t){const n=e.nodes[t];if(!n)throw new Error(`Unwanted state: ${t} not found in schema.`);return n}function uc(e){return md(t=>t.type.spec.tableRole&&t.type.spec.tableRole==="table")(e)}function Hte(e){return md(t=>t.type.name==="tableRow")(e)}function Yte(e){return md(t=>t.type.name==="tableCell"||t.type.name==="tableHeader")(e)}const LHe={cell:Yte,row:Hte,table:uc};function DD(e,...t){const n={};for(let r=0;r<t.length;r++){const i=t[r];i&&(n[i]=LHe[i](e))}return n}function Gte(e){var n;const t=(n=uc(e.state.selection))==null?void 0:n.node;return t&&t.firstChild&&t.type.name==="table"?t.firstChild.childCount:0}function Jte(e){var n;const t=(n=uc(e.state.selection))==null?void 0:n.node;return t&&t.type.name==="table"?t.childCount:0}function Vx(e){return Gte(e)>=DHe}function zx(e){return Jte(e)>=jHe}function LD(e,t){const{index:n,tr:r}=t,i=uc(r.selection);if(!i)return r;const o=Ct.get(i.node),a=e==="row";if(n<0||n>=(a?o.height:o.width))return r;const s=a?0:n,l=a?n:0,c=a?o.width:n+1,u=a?n+1:o.height,f=o.map[l*o.width+s],p=o.map[(u-1)*o.width+(c-1)];if(!f||!p)return r;const h=i.start+f,m=i.start+p,g=r.doc.resolve(h),y=r.doc.resolve(m);return r.setSelection(new at(y,g))}function PHe(e){return LD("row",e)}function BHe(e){return LD("column",e)}function UHe(e){const{direction:t,state:n}=e,{map:r,table:i,tableStart:o,top:a}=$r(n);if(t==="up"&&a===0||t==="down"&&a>=r.height-1)return;const{tr:s}=n,l=t==="up"?a-1:a+1;let c=o;for(let h=0;h<a;h++)c+=i.child(h).nodeSize;let u=o;for(let h=0;h<l;h++)u+=i.child(h).nodeSize;const f=i.child(a),p=i.child(l);switch(t){case"up":s.replaceWith(c,c+f.nodeSize,p),s.replaceWith(u,u+p.nodeSize,f);break;case"down":s.replaceWith(u,u+p.nodeSize,f),s.replaceWith(c,c+f.nodeSize,p);break}return{tr:s,index:l}}function NHe(e){const{direction:t,state:n}=e,{map:r,table:i,left:o}=$r(n);if(t==="left"&&o===0||t==="right"&&o>=r.width-1)return;const{tr:a}=n,s=t==="left"?o-1:o+1;for(let l=0;l<i.children.length;l++){const c=i.children[l];if(!c)return;const u=c.child(o),f=r.map[l*r.width+o];if(!f)return;const p=c.child(s),h=r.map[l*r.width+s];if(!h)return;switch(t){case"left":{a.replaceWith(f,f+u.nodeSize,p),a.replaceWith(h,h+p.nodeSize,u);break}case"right":{a.replaceWith(h,h+p.nodeSize,u),a.replaceWith(f,f+u.nodeSize,p);break}}}return{tr:a,index:s}}const Zte="data-prismic-table-handle";function WHe(e){return t=>{const n=uc(t);if(n){const r=Ct.get(n.node);return(Array.isArray(e)?e:Array.from([e])).reduce((o,a)=>{if(a>=0&&a<=r.width-1){const s=r.cellsInRect({left:a,right:a+1,top:0,bottom:r.height});return o.concat(s.flatMap(l=>{const c=n.node.nodeAt(l),u=l+n.start;return{pos:u,start:u+1,node:c}}))}return o},[])}return null}}function KHe(e){return t=>{const n=uc(t);if(n){const r=Ct.get(n.node);return(Array.isArray(e)?e:Array.from([e])).reduce((o,a)=>{if(a>=0&&a<=r.height-1){const s=r.cellsInRect({left:0,right:r.width,top:a,bottom:a+1});return o.concat(s.map(l=>{const c=n.node.nodeAt(l),u=l+n.start;return{pos:u,start:u+1,node:c}}))}return o},[])}return null}}function EU(e){const{element:t,type:n}=e,r=t.querySelector(`[${Zte}="${n}"]`);if(!r)throw new Error(`No ${n} handle found`);return r}function RU(e){const{type:t,editor:n,index:r}=e,i=zte({title:`Select ${t} & show options`,className:Lee(A.tableFieldStyles.tableHandle,A.tableFieldStyles[`table${Pt.capitalize(t)}Handle`]),[Zte]:t,"aria-expanded":!1,onMouseDown:a=>{a.preventDefault(),a.stopImmediatePropagation(),n.view.dispatch(LD(t,{index:r,tr:n.state.tr}))},onClick:(a,s)=>{a.preventDefault(),a.stopImmediatePropagation(),lo.dispatch("handleClick",{type:t,editor:n,referenceElement:s})}}),o=Qte(A.rawDragIndicatorIcon);return o&&i.appendChild(o),i}class qHe{constructor(t){Ve(this,"abortController",new AbortController);Ve(this,"currentRowHandle",null);Ve(this,"currentColumnHandle",null);Ve(this,"showCurrentHandles",t=>{try{const n=t.target,r=t.currentTarget;zHe(r),this.hidePreviousHandles();const i=kU("cell",n),o=this.getRowHandle(i),a=this.getColumnHandle(r,i);this.displayHandle(o),this.displayHandle(a),this.currentColumnHandle=a,this.currentRowHandle=o}catch{}});Ve(this,"hidePreviousHandles",()=>{this.currentRowHandle&&this.hideHandle(this.currentRowHandle),this.currentColumnHandle&&this.hideHandle(this.currentColumnHandle)});this.view=t,this.update(this.view)}update(t){this.attachEventListeners(t.dom)}destroy(){this.abortController.abort()}attachEventListeners(t){this.abortController.signal.aborted||this.abortController.abort(),this.abortController=new AbortController;const{signal:n}=this.abortController;t.querySelectorAll("table").forEach(r=>{r.addEventListener("mouseover",this.showCurrentHandles,{signal:n}),r.addEventListener("mouseleave",this.hidePreviousHandles,{signal:n})})}getRowHandle(t){const n=kU("row",t),r=EU({element:n,type:"row"});if(!r)throw new Error("No row handle found");return r}getColumnHandle(t,n){const r=n.cellIndex+1,i=t.querySelector(`tr > th:nth-child(${r}), tr > td:nth-child(${r})`);if(!i)throw new Error("No header cell found");const o=EU({element:i,type:"column"});if(!o)throw new Error("No column handle found");return o}displayHandle(t){t.classList.add(A.tableFieldStyles.tableHandleVisible)}hideHandle(t){t.classList.remove(A.tableFieldStyles.tableHandleVisible)}}const VHe={cell:["TD","TH"],row:["TR"]};function kU(e,t){const n=VHe[e];for(const r of n){const i=t.closest(r);if(i)return i}throw new Error(`Failed to find closest ${e}`)}function zHe(e){if(!e||e.tagName!=="TABLE")throw new Error("Element is not a table")}function QHe(e){return new cn({key:new En("tableCellHandles"),view:t=>new qHe(t),state:{init:(t,n)=>$U({editor:e,state:n}),apply:(t,n,r,i)=>t.docChanged?$U({editor:e,state:i}):n.map(t.mapping,t.doc)},props:{decorations(t){return this.getState(t)}}})}function $U(e){const{editor:t,state:n}=e,r=[],i=WHe(0)(n.selection);i&&i.forEach(({pos:a},s)=>{r.push(fn.widget(a+1,()=>RU({type:"row",editor:t,index:s})))});const o=KHe(0)(n.selection);return o&&o.forEach(({pos:a},s)=>{r.push(fn.widget(a+1,()=>RU({type:"column",editor:t,index:s})))}),vt.create(n.doc,r)}const HHe=Cn.create({name:"tableCell",addOptions(){return{HTMLAttributes:{}}},content:"block+",addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:e=>{const t=e.getAttribute("colwidth");return t?t.split(",").map(r=>parseInt(r,10)):null}}}},tableRole:"cell",isolating:!0,parseHTML(){return[{tag:"td"}]},renderHTML({HTMLAttributes:e}){return["td",Nt(this.options.HTMLAttributes,e),0]}}),PD=$.object({key:$.string().nullish(),colspan:$.number().nullish(),rowspan:$.number().nullish(),colwidth:$.array($.number()).nullish()}),Xte=HHe.extend({name:"tableCell",addAttributes(){var e;return{...(e=this.parent)==null?void 0:e.call(this),key:{default:null},"aria-label":{default:"Start typing to edit text"}}}}),OU={fromPrismic(e,t,n){return function(r){const i=PS(t,Xte.name),o=r.columnWidth?[r.columnWidth]:null;return i.create({colspan:1,rowspan:1,colwidth:o,key:r.key},r.content.value.flatMap(a=>Vte(e,t,a,n)??[]))}},toPrismic(e){const t=[];e.content.forEach(i=>{const o=Gr.converter.toPrismic(i);le.TextBlock.is(o)&&t.push(o)});const n=PD.parse(e.attrs),[r]=n.colwidth??[];return{key:n.key??crypto.randomUUID(),type:"tableCell",content:{__TYPE__:"StructuredTextContent",value:t},columnWidth:r}}},YHe=Cn.create({name:"tableHeader",addOptions(){return{HTMLAttributes:{}}},content:"block+",addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:e=>{const t=e.getAttribute("colwidth");return t?t.split(",").map(r=>parseInt(r,10)):null}}}},tableRole:"header_cell",isolating:!0,parseHTML(){return[{tag:"th"}]},renderHTML({HTMLAttributes:e}){return["th",Nt(this.options.HTMLAttributes,e),0]}}),ene=YHe.extend({name:"tableHeader",addAttributes(){var e;return{...(e=this.parent)==null?void 0:e.call(this),key:{default:null},"aria-label":{default:"Start typing to edit text"}}}}),MU={fromPrismic(e,t,n){return function(r){const i=PS(t,ene.name),o=r.columnWidth?[r.columnWidth]:null;return i.create({colspan:1,rowspan:1,colwidth:o,key:r.key},r.content.value.flatMap(a=>Vte(e,t,a,n)??[]))}},toPrismic(e){const t=[];e.content.forEach(i=>{const o=Gr.converter.toPrismic(i);le.TextBlock.is(o)&&t.push(o)});const n=PD.parse(e.attrs),[r]=n.colwidth??[];return{key:n.key??crypto.randomUUID(),type:"tableHeader",content:{__TYPE__:"StructuredTextContent",value:t},columnWidth:r}}},tne=Cn.create({name:"tableRow",addOptions(){return{HTMLAttributes:{}}},content:"(tableCell | tableHeader)*",tableRole:"row",parseHTML(){return[{tag:"tr"}]},renderHTML({HTMLAttributes:e}){return["tr",Nt(this.options.HTMLAttributes,e),0]}}),GHe=tne.extend({name:"tableRow",addAttributes(){var e;return{...(e=this.parent)==null?void 0:e.call(this),key:{default:null}}}}),FU={fromPrismic(e,t,n){return function(r){return PS(t,tne.name).create({key:r.key},r.content.map(o=>{switch(o.type){case"tableHeader":return MU.fromPrismic(e,t,n)(o);case"tableCell":return OU.fromPrismic(e,t,n)(o)}}))}},toPrismic(e){const t=PD.parse(e.attrs),n=[];return e.content.forEach(r=>{switch(r.type.name){case"tableHeader":{n.push(MU.toPrismic(r));break}case"tableCell":{n.push(OU.toPrismic(r));break}}}),{key:t.key??crypto.randomUUID(),type:"tableRow",content:n}}};class JHe extends Nte{constructor(n,r){const{node:i,editor:o}=n,{defaultCellMinWidth:a}=r;super(i,a);Ve(this,"tableWrapper");Ve(this,"selectionOverlay");this.tableWrapper=this.dom;const s=document.createElement("div");s.setAttribute("data-testid","table-container"),s.className=A.tableFieldStyles.tableWithControls;const l=document.createElement("div");l.classList.add(A.tableFieldStyles.tableShrinkContainer),this.selectionOverlay=new ZHe(o,this.table),this.dom.appendChild(this.selectionOverlay.view),n.editor.options.editable&&this.dom.appendChild(jU({editor:o,type:"column",onAfterCommand:()=>s.scrollLeft=s.scrollWidth})),l.appendChild(this.dom),s.appendChild(l),n.editor.options.editable&&l.appendChild(jU({editor:o,type:"row"})),this.dom=s}destroy(){this.selectionOverlay.destroy()}ignoreMutation(n){var i;const r=n.target;return r!==this.tableWrapper&&"closest"in r&&((i=r.closest)!=null&&i.call(r,".tableWrapper"))?!0:super.ignoreMutation(n)}}class ZHe{constructor(t,n){Ve(this,"view");Ve(this,"selectionAnchorCell",null);Ve(this,"selectionHeadCell",null);Ve(this,"onTransaction",t=>{const n=t.transaction.getMeta(Vr);n&&"setDragging"in n&&(t.editor.commands.focus(),this.onSelectionUpdate())});Ve(this,"onFocus",()=>{this.onSelectionUpdate()});Ve(this,"onBlur",()=>{this.selectionHeadCell===this.selectionAnchorCell&&this.clearSelectionOverlay()});Ve(this,"onSelectionUpdate",()=>{const{selection:t}=this.editor.state;let n=null,r=null;if(t instanceof _e){const i=Yte(t);n=r=Qx(this.editor.view,i==null?void 0:i.pos)}else t instanceof at?(n=Qx(this.editor.view,t.$headCell.pos),r=Qx(this.editor.view,t.$anchorCell.pos)):this.clearSelectionOverlay();!r||!n||(this.selectionAnchorCell=r,this.selectionHeadCell=n,this.renderSelectionOverlay())});Ve(this,"tableHeightObserver",null);Ve(this,"tableMinWidthObserver",null);Ve(this,"previousTableHeight",null);this.editor=t,this.table=n;const r=document.createElement("div");r.setAttribute("contentEditable","false"),r.classList.add(A.tableFieldStyles.tableSelectionOverlay),r.setAttribute("aria-label","Table selection overlay"),this.view=r,t.on("transaction",this.onTransaction),t.on("focus",this.onFocus),t.on("blur",this.onBlur),t.on("selectionUpdate",this.onSelectionUpdate),this.connectTableSizeObservers()}destroy(){this.editor.off("transaction",this.onTransaction),this.editor.off("focus",this.onFocus),this.editor.off("blur",this.onBlur),this.editor.off("selectionUpdate",this.onSelectionUpdate),this.clearSelectionOverlay(),this.disconnectTableSizeObservers()}clearSelectionOverlay(){const{style:t}=this.view;t.width="0px",t.height="0px",requestAnimationFrame(()=>{t.display="none"}),this.selectionAnchorCell=null,this.selectionHeadCell=null}renderSelectionOverlay(){if(!this.selectionAnchorCell||!this.selectionHeadCell)return;const t=this.selectionAnchorCell.getBoundingClientRect(),n=this.selectionHeadCell.getBoundingClientRect(),r=this.table.getBoundingClientRect(),i=Math.min(t.left,n.left)-r.left,o=Math.min(t.top,n.top)-r.top,a=Math.max(t.right,n.right)-r.left,s=Math.max(t.bottom,n.bottom)-r.top,l=$r(this.editor.state),c=XHe(l),{style:u}=this.view;u.left=`${i}px`,u.top=`${o}px`,u.width=`${a-i+c.width}px`,u.height=`${s-o+c.height}px`,u.borderRadius=eYe(l),requestAnimationFrame(()=>{u.display="block"})}connectTableSizeObservers(){this.disconnectTableSizeObservers(),this.tableHeightObserver??(this.tableHeightObserver=new ResizeObserver(t=>{for(const n of t){const r=n.contentRect.height;r!==this.previousTableHeight&&(this.renderSelectionOverlay(),this.previousTableHeight=r)}})),this.tableMinWidthObserver??(this.tableMinWidthObserver=new MutationObserver(()=>{this.renderSelectionOverlay()})),this.tableHeightObserver.observe(this.table),this.tableMinWidthObserver.observe(this.table,{attributes:!0,attributeFilter:["style"]})}disconnectTableSizeObservers(){var t,n;(t=this.tableHeightObserver)==null||t.disconnect(),(n=this.tableMinWidthObserver)==null||n.disconnect()}}function Qx(e,t){if(!t)return null;const n=e.nodeDOM(t);return n instanceof HTMLElement?n:null}function XHe(e){let{width:t,height:n}={width:1,height:1};return e.right===e.map.width&&(t=0),e.bottom===e.map.height&&(n=0),{width:t,height:n}}function eYe(e){let{tl:t,tr:n,br:r,bl:i}={tl:2,tr:2,br:2,bl:2};return e.top===0&&(e.left===0&&(t=6),e.right===e.map.width&&(n=6)),e.bottom===e.map.height&&(e.right===e.map.width&&(i=6),e.left===0&&(r=6)),`${t}px ${n}px ${i}px ${r}px`}function jU(e){const{type:t,editor:n,onAfterCommand:r}=e,i=Pt.capitalize(t),o=zte({title:`Add ${t}`,className:A.tableFieldStyles[`addTable${i}Button`],contentEditable:!1,onClick:()=>{n.commands[`add${i}ToEnd`](),r==null||r()}}),a=Qte(A.rawAddIcon);return a&&o.appendChild(a),o}const p0=MHe.extend({name:"table",selectable:!1,addOptions(){var e;return{...(e=this.parent)==null?void 0:e.call(this),resizable:!0,defaultCellMinWidth:120,View:null}},addCommands(){var e;return{...(e=this.parent)==null?void 0:e.call(this),addRowAfter:()=>t=>{var r,i,o;const{editor:n}=t;return zx(n)?(lo.dispatch("addAtLimit",{editor:n,type:"row"}),!1):((o=(r=this.parent)==null?void 0:(i=r.call(this)).addRowAfter)==null?void 0:o.call(i)(t))??!1},addRowBefore:()=>t=>{var r,i,o;const{editor:n}=t;return zx(n)?(lo.dispatch("addAtLimit",{editor:n,type:"row"}),!1):((o=(r=this.parent)==null?void 0:(i=r.call(this)).addRowBefore)==null?void 0:o.call(i)(t))??!1},addRowToEnd:()=>({dispatch:t,state:n,editor:r})=>{if(!Tr(n))return!1;if(zx(r))return lo.dispatch("addAtLimit",{editor:r,type:"row"}),!1;if(t){const i=$r(n),o=i.map.height;t(jD(n.tr,i,o))}return!0},addColumnAfter:()=>t=>{var r,i,o;const{editor:n}=t;return Vx(n)?(lo.dispatch("addAtLimit",{editor:n,type:"column"}),!1):((o=(r=this.parent)==null?void 0:(i=r.call(this)).addColumnAfter)==null?void 0:o.call(i)(t))??!1},addColumnBefore:()=>t=>{var r,i,o;const{editor:n}=t;return Vx(n)?(lo.dispatch("addAtLimit",{editor:n,type:"column"}),!1):((o=(r=this.parent)==null?void 0:(i=r.call(this)).addColumnBefore)==null?void 0:o.call(i)(t))??!1},addColumnToEnd:()=>({dispatch:t,state:n,editor:r})=>{if(!Tr(n))return!1;if(Vx(r))return lo.dispatch("addAtLimit",{editor:r,type:"column"}),!1;if(t){const i=$r(n),o=i.map.width;t(FD(n.tr,i,o))}return!0},moveRow:t=>({dispatch:n,state:r})=>{if(!Tr(r))return!1;if(n){tYe();const i=UHe({direction:t,state:r});if(!i)return!1;const o=PHe(i);n(o)}return!0},moveColumn:t=>({dispatch:n,state:r})=>{if(!Tr(r))return!1;if(n){const i=NHe({direction:t,state:r});if(!i)return!1;const o=BHe(i);n(o)}return!0}}},addNodeView(){return e=>new JHe(e,this.options)},addKeyboardShortcuts(){var e;return{...(e=this.parent)==null?void 0:e.call(this),Backspace:()=>!1,"Mod-Backspace":()=>!1,Delete:()=>!1,"Mod-Delete":()=>!1}},addProseMirrorPlugins(){return[...this.options.resizable&&this.editor.isEditable?[Wte(this.options)]:[],qte(this.options),QHe(this.editor),FHe(this.editor),nYe()]}});function tYe(){if(!window.getSelection)return;const e=window.getSelection();e!=null&&e.empty?e.empty():e!=null&&e.removeAllRanges&&e.removeAllRanges()}function nYe(){return new cn({filterTransaction(e,t){if(tGe(e))return!0;for(const n of e.steps){const r=n.toJSON();if(r.stepType!=="replace")continue;const i=rYe(t,r.from);if(i&&(i.type.name===p0.name||r.from+r.to===t.doc.content.size))return!1}return!0}})}function rYe(e,t){try{return e.doc.nodeAt(t)}catch{return null}}const iYe={fromPrismic(e,t,n){return function(r){return PS(t,p0.name).create({},r.content.map(o=>FU.fromPrismic(e,t,n)(o)))}},toPrismic(e){var n;const t=((n=e.content.firstChild)==null?void 0:n.type.name)===p0.name?e.content.firstChild:e;return{type:"table",content:Tl.children.map(t,r=>FU.toPrismic(r))}}},oYe=new oVe([Nc.table],Nc.table,[p0,GHe,ene,Xte],iYe),nne=[wD,RD,Ste],rne=[...nne,kD];function ine(e){return Y7e(e)?[...nne,Gr,oYe].filter(Ui.isDefined):[Gr,u0,f0,bc.build(e),cte,dte,gte,...rne].filter(Ui.isDefined)}const one=[{nodeType:he.RichTextNodeType.paragraph,icon:"textFields",isActive:e=>e.isActive(Gr.name)&&!e.isActive(u0.name)&&!e.isActive(f0.name),runCommands:qt((e,t)=>e.clearNodes().setDirection(ao(t))),shortText:"par",text:"Paragraph"},{nodeType:he.RichTextNodeType.heading1,icon:"looks1",isActive:e=>e.isActive(bc.name,{level:1}),runCommands:qt((e,t)=>e.setHeading({level:1}).setDirection(ao(t))),shortText:"h1",text:"Heading 1"},{nodeType:he.RichTextNodeType.heading2,icon:"looks2",isActive:e=>e.isActive(bc.name,{level:2}),runCommands:qt((e,t)=>e.setHeading({level:2}).setDirection(ao(t))),shortText:"h2",text:"Heading 2"},{nodeType:he.RichTextNodeType.heading3,icon:"looks3",isActive:e=>e.isActive(bc.name,{level:3}),runCommands:qt((e,t)=>e.setHeading({level:3}).setDirection(ao(t))),shortText:"h3",text:"Heading 3"},{nodeType:he.RichTextNodeType.heading4,icon:"looks4",isActive:e=>e.isActive(bc.name,{level:4}),runCommands:qt((e,t)=>e.setHeading({level:4}).setDirection(ao(t))),shortText:"h4",text:"Heading 4"},{nodeType:he.RichTextNodeType.heading5,icon:"looks5",isActive:e=>e.isActive(bc.name,{level:5}),runCommands:qt((e,t)=>e.setHeading({level:5}).setDirection(ao(t))),shortText:"h5",text:"Heading 5"},{nodeType:he.RichTextNodeType.heading6,icon:"looks6",isActive:e=>e.isActive(bc.name,{level:6}),runCommands:qt((e,t)=>e.setHeading({level:6}).setDirection(ao(t))),shortText:"h6",text:"Heading 6"},{nodeType:he.RichTextNodeType.list,icon:"formatListBulleted",isActive:e=>e.isActive(u0.name),runCommands:qt((e,t)=>e.toggleBulletList().setDirection(ao(t))),shortText:"bull",text:"Bulleted list"},{nodeType:he.RichTextNodeType.orderedList,icon:"formatListNumbered",isActive:e=>e.isActive(f0.name),runCommands:qt((e,t)=>e.toggleOrderedList().setDirection(ao(t))),shortText:"num",text:"Numbered list"},{nodeType:he.RichTextNodeType.preformatted,icon:"dataObject",isActive:e=>e.isActive(cte.name),runCommands:qt((e,t)=>e.setCodeBlock().setDirection(ao(t))),shortText:"code",text:"Code"},{nodeType:he.RichTextNodeType.embed,icon:"cloud",isActive:e=>e.isActive(dte.name),runCommands:qt(e=>e.setEmbed()),shortText:"emb",text:"Embed"},{nodeType:he.RichTextNodeType.image,icon:"image",isActive:e=>e.isActive(gte.name),runCommands:qt(e=>e.setImage()),shortText:"img",text:"Image"}],aYe=[{nodeType:he.RichTextNodeType.strong,icon:"formatBold",isActive:e=>e.isActive(wD.name),runCommands:qt(e=>e.toggleBold())},{nodeType:he.RichTextNodeType.em,icon:"formatItalic",isActive:e=>e.isActive(RD.name),runCommands:qt(e=>e.toggleItalic())}],sYe=[{nodeType:he.RichTextNodeType.rtl,icon:"formatTextDirectionRToL",isActive:e=>e.isActive({[Ba]:Oc}),runCommands:qt((e,t)=>e.toggleDirection(ao(t)))}];function qt(e){return(t,n={})=>{let r=n.can===!0?t.can().chain():t.chain().focus();return n.deleteRange!==void 0&&(r=r.deleteRange(n.deleteRange)),n.can?lYe(t,r,e):e(r,t).run()}}function ao(e){const t=e.state.selection.$from.parent.attrs;return Za.parseNodeAttrsDirection(t)}function ly(e,t){return e.filter(n=>t.includes(n.nodeType))}function lYe(e,t,n){try{return n(t,e).run()}catch{return!1}}function cYe(e){const{items:t,editor:n}=e;return t.length===0?null:d.jsxs(d.Fragment,{children:[t.map(r=>d.jsx(A.ToolbarToggleButton,{disabled:!r.runCommands(n,{can:!0}),onPressedChange:()=>{r.runCommands(n)},pressed:r.isActive(n),startIcon:r.icon},r.nodeType)),d.jsx(A.ToolbarSeparator,{})]})}function uYe(e){const{labels:t,editor:n}=e,r=n.getAttributes("label").label;return d.jsxs(d.Fragment,{children:[d.jsxs(A.DropdownMenu,{children:[d.jsx(A.DropdownMenuTrigger,{disabled:t.length===0,children:d.jsx(A.Button,{endIcon:"arrowDropDown",size:"small",color:"grey",children:DU(r??"Labels")})}),d.jsx(A.DropdownMenuContent,{align:"start",asPortal:!1,maxHeight:256,avoidCollisions:!1,children:t.map((i,o)=>{const a=r===i;return d.jsx(A.DropdownMenuItem,{onSelect:()=>a?n.commands.unsetLabel():dYe(n,i),endIcon:a&&d.jsx(A.Icon,{name:"check",size:"extraSmall"}),children:DU(i)},`${i}-${o}`)})})]}),d.jsx(A.ToolbarSeparator,{})]})}function dYe(e,t){qt(r=>r.setLabel({label:t}))(e)}function DU(e){return Pt.overflow(e,20)}function fYe(e){const{editor:t}=e,n=t.getAttributes("label");if(!n.label)return null;const r=n.label;return d.jsx(A.Box,{backgroundColor:"purple9",padding:{block:2,inline:4},alignItems:"center",borderRadius:{topLeft:2,topRight:2,bottomRight:2},maxWidth:125,children:d.jsx(A.Text,{color:"white",variant:"small",noWrap:!0,children:r})})}function pYe(e){const{disabled:t,showWebLinkModal:n,showDocumentsLinkModal:r,showMediaLinkModal:i}=hYe(e);return d.jsxs(d.Fragment,{children:[d.jsxs(A.ToolbarButtonGroup,{density:"compact",children:[d.jsx(A.ToolbarButton,{disabled:t,startIcon:"link",onClick:n},he.RichTextNodeType.hyperlink),d.jsxs(A.DropdownMenu,{children:[d.jsx(A.DropdownMenuTrigger,{children:d.jsx(A.ToolbarButton,{startIcon:"arrowDropDown"})}),d.jsxs(A.DropdownMenuContent,{align:"end",asPortal:!1,children:[d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"public"}),onSelect:n,children:"Link to web page"}),d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"description"}),onSelect:r,children:"Link to document"}),d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"image"}),onSelect:i,children:"Link to media"})]})]})]}),d.jsx(A.ToolbarSeparator,{})]})}function hYe(e){const{editor:t,setModal:n}=e;function r(){n("webLink")}function i(){n("documentLink")}function o(){n("mediaLink")}return{disabled:!qt(s=>s.setWebLink({href:""}))(t,{can:!0}),showWebLinkModal:r,showDocumentsLinkModal:i,showMediaLinkModal:o}}function mYe(e){const{docId:t,onEdit:n,onUnlink:r}=e,i=AYe(t),o=ye();if(!i)return null;const a=i.versions[0],s=ND({status:a==null?void 0:a.status,releaseId:(a==null?void 0:a.status)==="release"?a.release_id:void 0,documentId:i.id,versionId:a==null?void 0:a.version_id,baseUrl:o.baseUrl}),l=(a==null?void 0:a.preview_summary)??"",c=(a==null?void 0:a.custom_type_label)??"";return d.jsx(ru,{url:s,title:i.title,subTitle:c,description:l,onEdit:n,onUnlink:r,largeIconName:"description"})}function AYe(e){const t=ye();t.searchDocuments||Rt("searchDocuments");const{coreApiBaseUrl:n,authStrategy:r}=t;return it.useRequest(qg,[n,r,e])}function gYe(e){const{editor:t}=e,{searchDocuments:n}=ye(),r=t.getAttributes(he.RichTextNodeType.hyperlink);if(r.id&&n){const i=r.id;return d.jsx(vYe,{docId:i,...e})}if(r.href){const i=r.href;return d.jsx(yYe,{url:i,...e})}if(r.media){const i=wte(r.media);return d.jsx(bYe,{media:i,...e})}return null}function vYe(e){const{editor:t,onEditDocumentLink:n,docId:r}=e;return d.jsx(A.ErrorBoundary,{renderError:()=>d.jsx(ru,{title:"Failed to Load Linked Document Data",error:!0,onEdit:n,onUnlink:()=>Kc(t)}),children:d.jsx(R.Suspense,{fallback:d.jsx(ru,{loading:!0,onEdit:n,onUnlink:()=>Kc(t)}),children:d.jsx(mYe,{docId:r,onEdit:n,onUnlink:()=>Kc(t)})})})}function yYe(e){const{url:t,editor:n,onEditWebLink:r}=e,i=bi.toURL(t);return i?d.jsx(ru,{url:t,title:bi.getUrlTitle(i),subTitle:t,onEdit:r,onUnlink:()=>Kc(n)}):d.jsx(ru,{url:t,subTitle:t,onEdit:r,onUnlink:()=>Kc(n)})}function bYe(e){const{media:t,editor:n,onEditMediaLink:r}=e;return le.FilledImageLinkContent.is(t)?d.jsx(zJ,{url:t.url,title:t.name,subTitle:`${t.width} x ${t.height} pixels`,onEdit:r,onUnlink:()=>Kc(n)}):le.FilledFileLinkContent.is(t)?d.jsx(ru,{url:t.url,title:t.name,subTitle:CYe({filename:t.name}),largeIconName:"insertDriveFile",onEdit:r,onUnlink:()=>Kc(n)}):null}function Kc(e){qt(n=>n.unsetLink())(e)}function CYe(e){const{filename:t}=e,n=t.split(".").pop();return n?n.toLowerCase():""}function SYe(e){const{open:t}=e,{onOpenChange:n,onSelectDocument:r}=wYe(e);return d.jsx(WJ,{open:t,onOpenChange:n,onSelectDocument:r})}function wYe(e){const{editor:t,setOpen:n}=e;function r(o){qt(s=>s.extendMarkRange(he.RichTextNodeType.hyperlink).setDocumentLink({id:o}))(t),n(!1)}function i(o){n(o)}return{onSelectDocument:r,onOpenChange:i}}function xYe(e){const{open:t}=e,{onOpenChange:n,onMediaSelected:r}=TYe(e);return d.jsx(Uj,{open:t,onOpenChange:n,onMediaSelected:r,assetType:"all"})}function TYe(e){const{editor:t,setOpen:n}=e;function r(i){qt(a=>a.extendMarkRange(he.RichTextNodeType.hyperlink).setMediaLink({media:i}))(t),n(!1)}return{onMediaSelected:r,onOpenChange:n}}function IYe(e){const{open:t,setOpen:n}=e,{url:r,setUrl:i,openInNewTab:o,setOpenInNewTab:a,disabled:s,onUpdate:l}=_Ye(e);return d.jsxs(A.Dialog,{open:t,onOpenChange:n,size:"small",noDescription:!0,children:[d.jsx(A.DialogHeader,{title:"Set Link URL"}),d.jsxs(A.DialogContent,{padding:16,children:[d.jsx(A.FormInput,{value:r,onValueChange:i,placeholder:"Paste URL",icon:"public"}),r&&d.jsx(A.InlineLabel,{value:"Open in new tab",children:d.jsx(A.Checkbox,{checked:o,onCheckedChange:a})})]}),d.jsxs(A.DialogActions,{children:[d.jsx(A.DialogCancelButton,{}),d.jsx(A.DialogActionButton,{onClick:l,disabled:s,children:"Update"})]})]})}function _Ye(e){const{editor:t,open:n,setOpen:r}=e,i=EYe(t),[o,a]=R.useState(i.url),[s,l]=R.useState(i.openInNewTab);Ke.useOnChange(n,()=>{n&&(a(i.url),l(i.openInNewTab))});const c=!o||o===i.url&&s===i.openInNewTab;function u(){const f=s?"_blank":"_self";qt(p=>p.extendMarkRange(he.RichTextNodeType.hyperlink).setWebLink({href:o,target:f}))(t),r(!1)}return{url:o,setUrl:a,openInNewTab:s,disabled:c,setOpenInNewTab:l,onUpdate:u}}function EYe(e){const t=e.getAttributes(he.RichTextNodeType.hyperlink);return{url:t.href??"",openInNewTab:t.target==="_blank"}}function RYe(e){const{items:t,editor:n}=e;return t.length===0?null:d.jsxs(d.Fragment,{children:[d.jsx(A.ToolbarToggleButtonGroup,{onValueChange:r=>{t.forEach(i=>{(i.isActive(n)&&!r.includes(i.nodeType)||!i.isActive(n)&&r.includes(i.nodeType))&&i.runCommands(n)})},type:"multiple",value:t.filter(r=>r.isActive(n)).map(r=>r.nodeType),children:t.map(r=>d.jsx(A.ToolbarToggleButtonGroupItem,{disabled:!r.runCommands(n,{can:!0}),startIcon:r.icon,value:r.nodeType},r.nodeType))},"mark"),d.jsx(A.ToolbarSeparator,{})]})}function kYe(e){var r;const{items:t,editor:n}=e;return t.length===0?null:d.jsxs(d.Fragment,{children:[d.jsxs(A.DropdownMenu,{children:[d.jsx(A.DropdownMenuTrigger,{disabled:t.length===1,children:d.jsx(A.Button,{endIcon:"arrowDropDown",size:"small",color:"grey",children:((r=t.find(i=>i.isActive(n)))==null?void 0:r.text)??""})}),d.jsx(A.DropdownMenuContent,{align:"start",asPortal:!1,maxHeight:256,avoidCollisions:!1,children:t.map(i=>d.jsx(A.DropdownMenuItem,{onSelect:()=>{i.runCommands(n)},children:i.text},i.nodeType))})]}),d.jsx(A.ToolbarSeparator,{})]})}function Hx(e){return{duration:100,hideOnClick:!0,offset:e,placement:"top-start",appendTo:document.querySelector("body > div")??"parent"}}function $Ye(e){const{editor:t,nodeTypes:n,labels:r,hideDisabledOptions:i=!1}=e,[o,a]=R.useState(),s=n.includes(he.RichTextNodeType.hyperlink),l=!o,{shouldShowBubbleMenu:c,shouldShowPopover:u}=MYe({editor:t}),[f,p]=R.useState(!0);R.useEffect(()=>{p(!1)},[]);function h(y){a(y?"webLink":void 0)}function m(y){a(y?"documentLink":void 0)}function g(y){a(y?"mediaLink":void 0)}return f?null:d.jsxs(d.Fragment,{children:[d.jsx($x,{editor:t,tippyOptions:Hx([-48,0]),shouldShow:c,children:l&&d.jsx(OYe,{editor:t,nodeTypes:n,labels:r,setModal:a,hideDisabledOptions:i})}),d.jsx($x,{editor:t,tippyOptions:Hx([-48,0]),shouldShow:y=>u(y,"hyperlink"),children:l&&d.jsx(gYe,{editor:t,onEditWebLink:()=>a("webLink"),onEditDocumentLink:()=>a("documentLink"),onEditMediaLink:()=>a("mediaLink")})}),d.jsx($x,{editor:t,tippyOptions:Hx([0,0]),shouldShow:y=>u(y,"label"),children:d.jsx(fYe,{editor:t})}),s&&d.jsxs(d.Fragment,{children:[d.jsx(IYe,{open:o==="webLink",setOpen:h,editor:t}),d.jsx(SYe,{open:o==="documentLink",setOpen:m,editor:t}),d.jsx(xYe,{open:o==="mediaLink",setOpen:g,editor:t})]})]})}function OYe(e){const{editor:t,nodeTypes:n,labels:r,setModal:i,hideDisabledOptions:o}=e,a=n.includes("hyperlink"),s=r.length>0,l=ly(one,n),c=ly(aYe,n),u=ly(sYe,n),f=o&&l.length===1?0:l.length;return Number(a)+Number(s)+f+c.length+u.length===0?null:d.jsxs(A.Toolbar,{children:[f>0&&d.jsx(kYe,{items:l,editor:t}),s&&d.jsx(uYe,{labels:r,editor:t}),d.jsx(RYe,{items:c,editor:t}),a&&d.jsx(pYe,{editor:t,setModal:i}),d.jsx(cYe,{items:u,editor:t}),d.jsx(A.ToolbarButton,{onClick:()=>{t.chain().focus().clearNodes().unsetAllMarks().run()},startIcon:"formatClear"},"clear")]})}function MYe(e){const{editor:t}=e;function n(i){const{view:o,state:a,from:s,to:l}=i;if(!o.hasFocus())return!1;const{doc:c,selection:u}=a;return!(t.isActive(he.RichTextNodeType.preformatted)||u.empty||c.textBetween(s,l).length===0)}function r(i,o){const{view:a,state:s,from:l,to:c}=i,u=a.state.doc.nodeAt(l),{doc:f,selection:p}=s;return!p.empty||f.textBetween(l,c).length>0?!1:!!(u!=null&&u.marks.some(m=>m.type.name===o))}return{shouldShowBubbleMenu:n,shouldShowPopover:r}}const FYe=["id","data-state","aria-expanded","aria-controls","aria-haspopup"],ane=R.forwardRef(function(t,n){const{targetTriggerElementRef:r,style:i,...o}=t;return R.useEffect(()=>{if(r.current)for(const[a,s]of Object.entries(o))jYe(a,s)&&DYe(r.current,a,s)},[o,r]),d.jsx("div",{ref:n,style:i})});function jYe(e,t){return FYe.includes(e)?typeof t=="boolean"||typeof t=="number"||typeof t=="string":!1}function DYe(e,t,n){n!=null&&n!==""?e.setAttribute(t,n.toString()):e.removeAttribute(t)}function LYe(e){const{table:t,row:n}=DD(e.state.selection,"table","row");return!t||!n?{isFirstRow:!1,isLastRow:!1}:{isFirstRow:t.node.firstChild===n.node,isLastRow:t.node.lastChild===n.node}}function PYe(e){const{table:t,row:n}=DD(e.state.selection,"table","row");return!t||!n?!1:t.node.child(1)===n.node}const sne=e=>{var r;const t=(r=uc(e.state.selection))==null?void 0:r.node;if(!t||t.type.name!=="table")return!1;const n=t.firstChild;if(!n||n.type.name!=="tableRow")return!1;for(let i=0;i<n.childCount;i++){const o=n.child(i);if((o==null?void 0:o.type.name)!=="tableHeader")return!1}return!0},BYe=e=>Jte(e)===1;function UYe(e){const{table:t,cell:n}=DD(e.state.selection,"table","cell");return!t||!n?!1:t.node.child(0).child(1)===n.node}function NYe(e){var r;const t=(r=Hte(e.state.selection))==null?void 0:r.node,n=e.state.selection.$from.index(-1);return t?{isFirstColumn:n===0,isLastColumn:n===t.childCount-1}:{isFirstColumn:!1,isLastColumn:!1}}const lne=e=>{var n;const t=(n=uc(e.state.selection))==null?void 0:n.node;if(!t||t.type.name!=="table")return!1;for(let r=0;r<t.childCount;r++){const o=t.child(r).firstChild;if((o==null?void 0:o.type.name)!=="tableHeader")return!1}return!0},WYe=e=>Gte(e)===1;function KYe(e){const{editor:t,open:n,onOpenChange:r,floatingStyle:i,triggerRef:o,targetTriggerElementRef:a}=e,s=lne(t),l=WYe(t),c=NYe(t);function u(y){const b=sne(t);t.commands.deleteColumn(),r(!1),l&&s&&(f(y),b||t.commands.toggleHeaderRow())}function f(y){y.preventDefault(),t.commands.toggleHeaderColumn()}function p(){s&&c.isFirstColumn?t.chain().toggleHeaderColumn().addColumnBefore().toggleHeaderColumn().run():t.commands.addColumnBefore(),r(!1)}function h(){t.commands.addColumnAfter(),r(!1)}function m(){const y=s&&UYe(t),b=t.chain();y?b.toggleHeaderColumn().moveColumn("left").toggleHeaderColumn():b.moveColumn("left"),b.run(),r(!1)}function g(){const y=s&&c.isFirstColumn,b=t.chain();y?b.toggleHeaderColumn().moveColumn("right").toggleHeaderColumn():b.moveColumn("right"),b.run(),r(!1)}return d.jsxs(A.DropdownMenu,{open:n,onOpenChange:r,modal:!0,children:[d.jsx(A.DropdownMenuTrigger,{children:d.jsx(ane,{ref:o,targetTriggerElementRef:a,style:i})}),d.jsxs(A.DropdownMenuContent,{align:"start",side:"bottom",sideOffset:4,children:[d.jsx(A.DropdownMenuLabel,{children:d.jsx(A.Text,{color:"grey11",variant:"small",children:"Column options"})}),c.isFirstColumn&&d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"viewDay"}),onSelect:f,disabled:l,children:d.jsxs(A.Box,{gap:12,alignItems:"center",children:["Header Column",d.jsx(A.Switch,{size:"extraSmall",checked:s})]})}),d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"arrowBack"}),onSelect:p,children:"Insert Left"}),d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"arrowForward"}),onSelect:h,children:"Insert Right"}),d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"moveLeft"}),onSelect:m,disabled:c.isFirstColumn,children:"Move Left"}),d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"moveRight"}),onSelect:g,disabled:c.isLastColumn,children:"Move Right"}),d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"delete"}),onSelect:u,disabled:l,children:"Delete Column"})]})]})}function qYe(e){const{editor:t,open:n,onOpenChange:r,floatingStyle:i,triggerRef:o,targetTriggerElementRef:a}=e,s=sne(t),l=BYe(t),c=LYe(t);function u(y){const b=lne(t);t.commands.deleteRow(),r(!1),l&&s&&(f(y),b||t.commands.toggleHeaderColumn())}function f(y){y.preventDefault(),t.commands.toggleHeaderRow()}function p(){s&&c.isFirstRow?t.chain().toggleHeaderRow().addRowBefore().toggleHeaderRow().run():t.commands.addRowBefore(),r(!1)}function h(){t.commands.addRowAfter(),r(!1)}function m(){const y=s&&PYe(t),b=t.chain();y?b.toggleHeaderRow().moveRow("up").toggleHeaderRow():b.moveRow("up"),b.run(),r(!1)}function g(){const y=s&&c.isFirstRow,b=t.chain();y?b.toggleHeaderRow().moveRow("down").toggleHeaderRow():b.moveRow("down"),b.run(),r(!1)}return d.jsxs(A.DropdownMenu,{open:n,onOpenChange:r,modal:!0,children:[d.jsx(A.DropdownMenuTrigger,{children:d.jsx(ane,{ref:o,targetTriggerElementRef:a,style:i})}),d.jsxs(A.DropdownMenuContent,{align:"start",side:"right",sideOffset:4,children:[d.jsx(A.DropdownMenuLabel,{children:d.jsx(A.Text,{color:"grey11",variant:"small",children:"Row options"})}),c.isFirstRow&&d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"viewDay"}),onSelect:f,disabled:l,children:d.jsxs(A.Box,{gap:12,alignItems:"center",children:[d.jsx(A.Text,{noWrap:!0,children:"Header row"}),d.jsx(A.Switch,{size:"extraSmall",checked:s})]})}),d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"arrowUpward"}),onSelect:p,children:"Insert Above"}),d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"arrowDownward"}),onSelect:h,children:"Insert Below"}),d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"moveUp"}),onSelect:m,disabled:c.isFirstRow,children:"Move Up"}),d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"moveDown"}),onSelect:g,disabled:c.isLastRow,children:"Move Down"}),d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"delete"}),onSelect:u,disabled:l,children:"Delete Row"})]})]})}function VYe(e){return d.jsxs(d.Fragment,{children:[d.jsx(zYe,{...e}),d.jsx(QYe,{...e})]})}function zYe(e){const{editor:t}=e,{triggerElementRef:n,open:r,onOpenChange:i,floatingStyle:o,floatingRef:a}=cne("row",t);return d.jsx(qYe,{open:r,editor:t,triggerRef:a,targetTriggerElementRef:n,onOpenChange:i,floatingStyle:o})}function QYe(e){const{editor:t}=e,{triggerElementRef:n,open:r,onOpenChange:i,floatingStyle:o,floatingRef:a}=cne("column",t);return d.jsx(KYe,{open:r,editor:t,triggerRef:a,targetTriggerElementRef:n,onOpenChange:i,floatingStyle:o})}function cne(e,t){const n=R.useRef(),[r,i]=R.useState(!1),{strategy:o,floating:a,reference:s,x:l,y:c}=ate({open:r,onOpenChange:i,placement:e==="column"?"bottom-start":"right-start",strategy:"fixed"});return R.useEffect(()=>lo.listen("handleClick",{editor:t,callback:u=>{u.type===e&&(s(u.referenceElement),n.current=u.referenceElement,i(!0))}}),[t,s,e]),{open:r,onOpenChange:i,triggerElementRef:n,floatingRef:a,floatingStyle:{top:c??"",left:l??"",position:o,display:r?"flex":"none"}}}function HYe(e){const{editor:t}=e,{open:n,onOpenChange:r}=YYe(t);return d.jsx(A.Toast,{title:"You've reached the limit (50 rows / 25 columns).",action:{title:"Need more?",onClick:()=>window.open("https://community.prismic.io/t/how-should-the-table-field-evolve-your-call/18542","_blank")},open:n,onOpenChange:r,anchor:d.jsx(A.Box,{position:"fixed",left:0,right:0,bottom:72}),cancel:{onClick:()=>r(!1)}})}function YYe(e){const[t,n]=R.useState(!1),{onAnalyticsEvent:r}=ye();return R.useEffect(()=>lo.listen("addAtLimit",{editor:e,callback:i=>{r==null||r("Table Limit Reached",{type:i.type}),n(!0)}}),[e,r]),{open:t,onOpenChange:n}}function BD(e){const{content:t,field:n,id:r,readOnly:i,padding:o="normal",scroll:a="hidden",shouldReturnEmptyContent:s=!1,icon:l,onContentChange:c}=e,{useThreads:u,CustomThreads:f}=ye(),p=r.split(":")[2]||r,h=eGe({fieldId:p}),m=u==null?void 0:u().threads,g=GYe({field:n,conditionalExtensions:h}),y=R.useRef(),b=R.useRef(!1),x=R.useMemo(()=>{var S;if(t)return(S=AI.converter(g.nodeExtensions).fromPrismic(p,g.schema,g.nodeTypes,t,m))==null?void 0:S.toJSON()},[g,t,p,m]),v=W7e({content:x,editable:!i,editorProps:{attributes:{class:Lee((()=>o==="zero"?A.contentEditableNoPaddingClass:l?A.contentEditableClassWithIcon:A.contentEditableClass)(),A.contentEditableMultilinePlaceholderClass),id:r,tabIndex:"0"}},extensions:g.allComponents,injectCSS:!1,onUpdate({editor:S}){let C;S.isEmpty&&!s?C=void 0:C=AI.converter(g.nodeExtensions).toPrismic(S.state.doc),y.current={content:C},b.current=!0,c(C)}},[g,i]);return Ke.useStableLayoutEffect(()=>{const S=b.current;if(b.current=!1,S||y.current&&y.current.content===t)return;const C=v.state.selection,T=v.state.doc.content.size;v.chain().command(nGe).setContent(x??null,!1).run(),rGe({editor:v,previousContentSize:T,previousSelection:C})},[t]),d.jsxs(A.Field,{display:a==="x-auto"?"grid":"flex",children:[l&&d.jsx(A.FieldIcon,{name:l}),d.jsx(A.FieldLabel,{htmlFor:r,children:Br(n)}),d.jsxs(A.FieldControl,{children:[v.isEditable&&d.jsx($Ye,{editor:v,nodeTypes:g.names,labels:g.labels,hideDisabledOptions:!0}),v.isEditable&&g.names.includes("table")&&d.jsxs(d.Fragment,{children:[d.jsx(VYe,{editor:v}),d.jsx(HYe,{editor:v})]}),d.jsx(O7e,{editor:v,style:{width:"100%"}}),f&&d.jsx(f,{editor:v,threads:m})]})]})}function GYe({field:e,conditionalExtensions:t}){var r,i;const n=`${((r=e.config)==null?void 0:r.multi)??""}-${((i=e.config)==null?void 0:i.single)??""}`;return R.useMemo(()=>{var g;const{extensions:o,nodeTypes:a}=sVe(e.config),s=o.filter(JYe),l=o.flatMap(y=>y.richTextNodeTypes);a.has(zB)&&l.push(zB);const c=o.flatMap(y=>y.component),u=o.filter(ZYe).map(y=>y.name),f=[...t,...c,...Rze(e,s),UVe.configure({supportedExtensionNames:u}),K9e],p=f.map(y=>y.name),h=Uqe(f),m=XYe((g=e.config)==null?void 0:g.labels);return{allComponents:f,extensionNames:p,nodeTypes:a,nodeExtensions:s,names:l,schema:h,labels:m}},[n])}function JYe(e){return e.extType===Ad.Node}function ZYe(e){return!(e.extType!==Ad.Node||e.nodeType!==$c.Text||e.lockedFormat)}function XYe(e){return Array.from(e??[])}function eGe(e){const{fieldId:t}=e,{useCollaborativeComments:n,hasSharedCollaborativeHistory:r}=ye(),i=n==null?void 0:n({field:t});return i?[i.configure({history:!r})]:r?[]:[L9e]}function tGe(e){return e.getMeta(h0.key)===h0.value}function nGe(e){const{tr:t}=e;return t.setMeta(h0.key,h0.value),!0}const h0={key:"source",value:"external-update"};function rGe(e){var i,o,a,s;const{editor:t,previousContentSize:n,previousSelection:r}=e;if(t.commands.setTextSelection({from:r.from,to:r.to}),r.$anchor.parentOffset!==t.state.selection.$anchor.parentOffset||r.$head.parentOffset!==t.state.selection.$head.parentOffset||((i=r.$from.nodeBefore)==null?void 0:i.textContent)!==((o=t.state.selection.$from.nodeBefore)==null?void 0:o.textContent)&&((a=r.$from.nodeAfter)==null?void 0:a.textContent)!==((s=t.state.selection.$from.nodeAfter)==null?void 0:s.textContent)){const l=n-t.state.doc.content.size;t.commands.setTextSelection({from:r.from-l,to:r.to-l})}}function une(e){var c,u;const{content:t,field:n,id:r,onContentChange:i,readOnly:o}=e,a=R.useRef(),s=t==null?void 0:t.value,l=R.useMemo(()=>{var f,p,h;return((p=(f=a.current)==null?void 0:f.plainText)==null?void 0:p.value)===s?(h=a.current)==null?void 0:h.richText:iGe(s)},[s]);return d.jsx(BD,{id:r,icon:"notes",field:{type:"StructuredText",config:{label:Br(n),multi:"paragraph",placeholder:(c=n.config)==null?void 0:c.placeholder,useAsTitle:(u=n.config)==null?void 0:u.useAsTitle}},content:l,onContentChange:f=>{const p=oGe(f);a.current={richText:f,plainText:p},i(p)},readOnly:o})}function iGe(e){if(e)return{__TYPE__:"StructuredTextContent",value:e.split(`
212
+ `))}})}function CQe(e,t,n){let r=e.resolve(t),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function SQe(e,t,n,r,i){let o=e.doc.nodeAt(t);if(!o)throw new RangeError("No node at given position");n||(n=o.type);let a=n.create(r,null,i||o.marks);if(o.isLeaf)return e.replaceWith(t,t+o.nodeSize,a);if(!n.validContent(o.content))throw new RangeError("Invalid content for node type "+n.name);e.step(new Go(t,t+o.nodeSize,t+1,t+o.nodeSize-1,new W(U.from(a),0,0),1,!0))}function wQe(e,t,n=1,r){let i=e.doc.resolve(t),o=U.empty,a=U.empty;for(let s=i.depth,l=i.depth-n,c=n-1;s>l;s--,c--){o=U.from(i.node(s).copy(o));let u=r&&r[c];a=U.from(u?u.type.create(u.attrs,a):i.node(s).copy(a))}e.step(new br(t,t,new W(o.append(a),n,n),!0))}function xQe(e,t,n){let r=null,{linebreakReplacement:i}=e.doc.type.schema,o=e.doc.resolve(t-n),a=o.node().type;if(i&&a.inlineContent){let u=a.whitespace=="pre",f=!!a.contentMatch.matchType(i);u&&!f?r=!1:!u&&f&&(r=!0)}let s=e.steps.length;if(r===!1){let u=e.doc.resolve(t+n);kte(e,u.node(),u.before(),s)}a.inlineContent&&OD(e,t+n-1,a,o.node().contentMatchAt(o.index()),r==null);let l=e.mapping.slice(s),c=l.map(t-n);if(e.step(new br(c,l.map(t+n,-1),W.empty,!0)),r===!0){let u=e.doc.resolve(c);Rte(e,u.node(),u.before(),e.steps.length)}return e}function TQe(e,t,n){let r=e.resolve(t);if(r.parent.canReplaceWith(r.index(),r.index(),n))return t;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,n))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,n))return r.after(i+1);if(o<r.node(i).childCount)return null}return null}function IQe(e,t,n=t,r=W.empty){if(t==n&&!r.size)return null;let i=e.resolve(t),o=e.resolve(n);return $te(i,o,r)?new br(t,n,r):new _Qe(i,o,r).fit()}function $te(e,t,n){return!n.openStart&&!n.openEnd&&e.start()==t.start()&&e.parent.canReplace(e.index(),t.index(),n.content)}class _Qe{constructor(t,n,r){this.$from=t,this.$to=n,this.unplaced=r,this.frontier=[],this.placed=U.empty;for(let i=0;i<=t.depth;i++){let o=t.node(i);this.frontier.push({type:o.type,match:o.contentMatchAt(t.indexAfter(i))})}for(let i=t.depth;i>0;i--)this.placed=U.from(t.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let c=this.findFittable();c?this.placeNodes(c):this.openMore()||this.dropNode()}let t=this.mustMoveInline(),n=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(t<0?this.$to:r.doc.resolve(t));if(!i)return null;let o=this.placed,a=r.depth,s=i.depth;for(;a&&s&&o.childCount==1;)o=o.firstChild.content,a--,s--;let l=new W(o,a,s);return t>-1?new Go(r.pos,t,this.$to.pos,this.$to.end(),l,n):l.size||r.pos!=this.$to.pos?new br(r.pos,i.pos,l):null}findFittable(){let t=this.unplaced.openStart;for(let n=this.unplaced.content,r=0,i=this.unplaced.openEnd;r<t;r++){let o=n.firstChild;if(n.childCount>1&&(i=0),o.type.spec.isolating&&i<=r){t=r;break}n=o.content}for(let n=1;n<=2;n++)for(let r=n==1?t:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=Wx(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let a=i.firstChild;for(let s=this.depth;s>=0;s--){let{type:l,match:c}=this.frontier[s],u,f=null;if(n==1&&(a?c.matchType(a.type)||(f=c.fillBefore(U.from(a),!1)):o&&l.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:s,parent:o,inject:f};if(n==2&&a&&(u=c.findWrapping(a.type)))return{sliceDepth:r,frontierDepth:s,parent:o,wrap:u};if(o&&c.matchType(o.type))break}}}openMore(){let{content:t,openStart:n,openEnd:r}=this.unplaced,i=Wx(t,n);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new W(t,n+1,Math.max(r,i.size+n>=t.size-r?n+1:0)),!0)}dropNode(){let{content:t,openStart:n,openEnd:r}=this.unplaced,i=Wx(t,n);if(i.childCount<=1&&n>0){let o=t.size-n<=n+i.size;this.unplaced=new W(Fh(t,n-1,1),n-1,o?n-1:r)}else this.unplaced=new W(Fh(t,n,1),n,r)}placeNodes({sliceDepth:t,frontierDepth:n,parent:r,inject:i,wrap:o}){for(;this.depth>n;)this.closeFrontierNode();if(o)for(let g=0;g<o.length;g++)this.openFrontierNode(o[g]);let a=this.unplaced,s=r?r.content:a.content,l=a.openStart-t,c=0,u=[],{match:f,type:p}=this.frontier[n];if(i){for(let g=0;g<i.childCount;g++)u.push(i.child(g));f=f.matchFragment(i)}let h=s.size+t-(a.content.size-a.openEnd);for(;c<s.childCount;){let g=s.child(c),y=f.matchType(g.type);if(!y)break;c++,(c>1||l==0||g.content.size)&&(f=y,u.push(Ote(g.mark(p.allowedMarks(g.marks)),c==1?l:0,c==s.childCount?h:-1)))}let m=c==s.childCount;m||(h=-1),this.placed=jh(this.placed,n,U.from(u)),this.frontier[n].match=f,m&&h<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let g=0,y=s;g<h;g++){let b=y.lastChild;this.frontier.push({type:b.type,match:b.contentMatchAt(b.childCount)}),y=b.content}this.unplaced=m?t==0?W.empty:new W(Fh(a.content,t-1,1),t-1,h<0?a.openEnd:t-1):new W(Fh(a.content,t,c),a.openStart,a.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let t=this.frontier[this.depth],n;if(!t.type.isTextblock||!Kx(this.$to,this.$to.depth,t.type,t.match,!1)||this.$to.depth==this.depth&&(n=this.findCloseLevel(this.$to))&&n.depth==this.depth)return-1;let{depth:r}=this.$to,i=this.$to.after(r);for(;r>1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(t){e:for(let n=Math.min(this.depth,t.depth);n>=0;n--){let{match:r,type:i}=this.frontier[n],o=n<t.depth&&t.end(n+1)==t.pos+(t.depth-(n+1)),a=Kx(t,n,i,r,o);if(a){for(let s=n-1;s>=0;s--){let{match:l,type:c}=this.frontier[s],u=Kx(t,s,c,l,!0);if(!u||u.childCount)continue e}return{depth:n,fit:a,move:o?t.doc.resolve(t.after(n+1)):t}}}}close(t){let n=this.findCloseLevel(t);if(!n)return null;for(;this.depth>n.depth;)this.closeFrontierNode();n.fit.childCount&&(this.placed=jh(this.placed,n.depth,n.fit)),t=n.move;for(let r=n.depth+1;r<=t.depth;r++){let i=t.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,t.index(r));this.openFrontierNode(i.type,i.attrs,o)}return t}openFrontierNode(t,n=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(t),this.placed=jh(this.placed,this.depth,U.from(t.create(n,r))),this.frontier.push({type:t,match:t.contentMatch})}closeFrontierNode(){let n=this.frontier.pop().match.fillBefore(U.empty,!0);n.childCount&&(this.placed=jh(this.placed,this.frontier.length,n))}}function Fh(e,t,n){return t==0?e.cutByIndex(n,e.childCount):e.replaceChild(0,e.firstChild.copy(Fh(e.firstChild.content,t-1,n)))}function jh(e,t,n){return t==0?e.append(n):e.replaceChild(e.childCount-1,e.lastChild.copy(jh(e.lastChild.content,t-1,n)))}function Wx(e,t){for(let n=0;n<t;n++)e=e.firstChild.content;return e}function Ote(e,t,n){if(t<=0)return e;let r=e.content;return t>1&&(r=r.replaceChild(0,Ote(r.firstChild,t-1,r.childCount==1?n-1:0))),t>0&&(r=e.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(e.type.contentMatch.matchFragment(r).fillBefore(U.empty,!0)))),e.copy(r)}function Kx(e,t,n,r,i){let o=e.node(t),a=i?e.indexAfter(t):e.index(t);if(a==o.childCount&&!n.compatibleContent(o.type))return null;let s=r.fillBefore(o.content,!0,a);return s&&!EQe(n,o.content,a)?s:null}function EQe(e,t,n){for(let r=n;r<t.childCount;r++)if(!e.allowsMarks(t.child(r).marks))return!0;return!1}function RQe(e){return e.spec.defining||e.spec.definingForContent}function kQe(e,t,n,r){if(!r.size)return e.deleteRange(t,n);let i=e.doc.resolve(t),o=e.doc.resolve(n);if($te(i,o,r))return e.step(new br(t,n,r));let a=Fte(i,e.doc.resolve(n));a[a.length-1]==0&&a.pop();let s=-(i.depth+1);a.unshift(s);for(let p=i.depth,h=i.pos-1;p>0;p--,h--){let m=i.node(p).type.spec;if(m.defining||m.definingAsContext||m.isolating)break;a.indexOf(p)>-1?s=p:i.before(p)==h&&a.splice(1,0,-p)}let l=a.indexOf(s),c=[],u=r.openStart;for(let p=r.content,h=0;;h++){let m=p.firstChild;if(c.push(m),h==r.openStart)break;p=m.content}for(let p=u-1;p>=0;p--){let h=c[p],m=RQe(h.type);if(m&&!h.sameMarkup(i.node(Math.abs(s)-1)))u=p;else if(m||!h.type.isTextblock)break}for(let p=r.openStart;p>=0;p--){let h=(p+u+1)%(r.openStart+1),m=c[h];if(m)for(let g=0;g<a.length;g++){let y=a[(g+l)%a.length],b=!0;y<0&&(b=!1,y=-y);let x=i.node(y-1),w=i.index(y-1);if(x.canReplaceWith(w,w,m.type,m.marks))return e.replace(i.before(y),b?o.after(y):n,new W(Mte(r.content,0,r.openStart,h),h,r.openEnd))}}let f=e.steps.length;for(let p=a.length-1;p>=0&&(e.replace(t,n,r),!(e.steps.length>f));p--){let h=a[p];h<0||(t=i.before(h),n=o.after(h))}}function Mte(e,t,n,r,i){if(t<n){let o=e.firstChild;e=e.replaceChild(0,o.copy(Mte(o.content,t+1,n,r,o)))}if(t>r){let o=i.contentMatchAt(0),a=o.fillBefore(e).append(e);e=a.append(o.matchFragment(a).fillBefore(U.empty,!0))}return e}function $Qe(e,t,n,r){if(!r.isInline&&t==n&&e.doc.resolve(t).parent.content.size){let i=TQe(e.doc,t,r.type);i!=null&&(t=n=i)}e.replaceRange(t,n,new W(U.from(r),0,0))}function OQe(e,t,n){let r=e.doc.resolve(t),i=e.doc.resolve(n),o=Fte(r,i);for(let a=0;a<o.length;a++){let s=o[a],l=a==o.length-1;if(l&&s==0||r.node(s).type.contentMatch.validEnd)return e.delete(r.start(s),i.end(s));if(s>0&&(l||r.node(s-1).canReplace(r.index(s-1),i.indexAfter(s-1))))return e.delete(r.before(s),i.after(s))}for(let a=1;a<=r.depth&&a<=i.depth;a++)if(t-r.start(a)==r.depth-a&&n>r.end(a)&&i.end(a)-n!=i.depth-a&&r.start(a-1)==i.start(a-1)&&r.node(a-1).canReplace(r.index(a-1),i.index(a-1)))return e.delete(r.before(a),n);e.delete(t,n)}function Fte(e,t){let n=[],r=Math.min(e.depth,t.depth);for(let i=r;i>=0;i--){let o=e.start(i);if(o<e.pos-(e.depth-i)||t.end(i)>t.pos+(t.depth-i)||e.node(i).type.spec.isolating||t.node(i).type.spec.isolating)break;(o==t.start(i)||i==e.depth&&i==t.depth&&e.parent.inlineContent&&t.parent.inlineContent&&i&&t.start(i-1)==o-1)&&n.push(i)}return n}class zd extends vr{constructor(t,n,r){super(),this.pos=t,this.attr=n,this.value=r}apply(t){let n=t.nodeAt(this.pos);if(!n)return rn.fail("No node at attribute step's position");let r=Object.create(null);for(let o in n.attrs)r[o]=n.attrs[o];r[this.attr]=this.value;let i=n.type.create(r,null,n.marks);return rn.fromReplace(t,this.pos,this.pos+1,new W(U.from(i),0,n.isLeaf?0:1))}getMap(){return gi.empty}invert(t){return new zd(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new zd(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new zd(n.pos,n.attr,n.value)}}vr.jsonID("attr",zd);class Wm extends vr{constructor(t,n){super(),this.attr=t,this.value=n}apply(t){let n=Object.create(null);for(let i in t.attrs)n[i]=t.attrs[i];n[this.attr]=this.value;let r=t.type.create(n,t.content,t.marks);return rn.ok(r)}getMap(){return gi.empty}invert(t){return new Wm(this.attr,t.attrs[this.attr])}map(t){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new Wm(n.attr,n.value)}}vr.jsonID("docAttr",Wm);let Tf=class extends Error{};Tf=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n};Tf.prototype=Object.create(Error.prototype);Tf.prototype.constructor=Tf;Tf.prototype.name="TransformError";class MQe{constructor(t){this.doc=t,this.steps=[],this.docs=[],this.mapping=new zh}get before(){return this.docs.length?this.docs[0]:this.doc}step(t){let n=this.maybeStep(t);if(n.failed)throw new Tf(n.failed);return this}maybeStep(t){let n=t.apply(this.doc);return n.failed||this.addStep(t,n.doc),n}get docChanged(){return this.steps.length>0}addStep(t,n){this.docs.push(this.doc),this.steps.push(t),this.mapping.appendMap(t.getMap()),this.doc=n}replace(t,n=t,r=W.empty){let i=IQe(this.doc,t,n,r);return i&&this.step(i),this}replaceWith(t,n,r){return this.replace(t,n,new W(U.from(r),0,0))}delete(t,n){return this.replace(t,n,W.empty)}insert(t,n){return this.replaceWith(t,t,n)}replaceRange(t,n,r){return kQe(this,t,n,r),this}replaceRangeWith(t,n,r){return $Qe(this,t,n,r),this}deleteRange(t,n){return OQe(this,t,n),this}lift(t,n){return vQe(this,t,n),this}join(t,n=1){return xQe(this,t,n),this}wrap(t,n){return yQe(this,t,n),this}setBlockType(t,n=t,r,i=null){return bQe(this,t,n,r,i),this}setNodeMarkup(t,n,r=null,i){return SQe(this,t,n,r,i),this}setNodeAttribute(t,n,r){return this.step(new zd(t,n,r)),this}setDocAttribute(t,n){return this.step(new Wm(t,n)),this}addNodeMark(t,n){return this.step(new il(t,n)),this}removeNodeMark(t,n){if(!(n instanceof dt)){let r=this.doc.nodeAt(t);if(!r)throw new RangeError("No node at position "+t);if(n=n.isInSet(r.marks),!n)return this}return this.step(new xf(t,n)),this}split(t,n=1,r){return wQe(this,t,n,r),this}addMark(t,n,r){return AQe(this,t,n,r),this}removeMark(t,n,r){return gQe(this,t,n,r),this}clearIncompatible(t,n,r){return OD(this,t,n,r),this}}var $I,OI;if(typeof WeakMap<"u"){let e=new WeakMap;$I=t=>e.get(t),OI=(t,n)=>(e.set(t,n),n)}else{const e=[];let n=0;$I=r=>{for(let i=0;i<e.length;i+=2)if(e[i]==r)return e[i+1]},OI=(r,i)=>(n==10&&(n=0),e[n++]=r,e[n++]=i)}var Ct=class{constructor(e,t,n,r){this.width=e,this.height=t,this.map=n,this.problems=r}findCell(e){for(let t=0;t<this.map.length;t++){const n=this.map[t];if(n!=e)continue;const r=t%this.width,i=t/this.width|0;let o=r+1,a=i+1;for(let s=1;o<this.width&&this.map[t+s]==n;s++)o++;for(let s=1;a<this.height&&this.map[t+this.width*s]==n;s++)a++;return{left:r,top:i,right:o,bottom:a}}throw new RangeError(`No cell with offset ${e} found`)}colCount(e){for(let t=0;t<this.map.length;t++)if(this.map[t]==e)return t%this.width;throw new RangeError(`No cell with offset ${e} found`)}nextCell(e,t,n){const{left:r,right:i,top:o,bottom:a}=this.findCell(e);return t=="horiz"?(n<0?r==0:i==this.width)?null:this.map[o*this.width+(n<0?r-1:i)]:(n<0?o==0:a==this.height)?null:this.map[r+this.width*(n<0?o-1:a)]}rectBetween(e,t){const{left:n,right:r,top:i,bottom:o}=this.findCell(e),{left:a,right:s,top:l,bottom:c}=this.findCell(t);return{left:Math.min(n,a),top:Math.min(i,l),right:Math.max(r,s),bottom:Math.max(o,c)}}cellsInRect(e){const t=[],n={};for(let r=e.top;r<e.bottom;r++)for(let i=e.left;i<e.right;i++){const o=r*this.width+i,a=this.map[o];n[a]||(n[a]=!0,!(i==e.left&&i&&this.map[o-1]==a||r==e.top&&r&&this.map[o-this.width]==a)&&t.push(a))}return t}positionAt(e,t,n){for(let r=0,i=0;;r++){const o=i+n.child(r).nodeSize;if(r==e){let a=t+e*this.width;const s=(e+1)*this.width;for(;a<s&&this.map[a]<i;)a++;return a==s?o-1:this.map[a]}i=o}}static get(e){return $I(e)||OI(e,FQe(e))}};function FQe(e){if(e.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+e.type.name);const t=jQe(e),n=e.childCount,r=[];let i=0,o=null;const a=[];for(let c=0,u=t*n;c<u;c++)r[c]=0;for(let c=0,u=0;c<n;c++){const f=e.child(c);u++;for(let m=0;;m++){for(;i<r.length&&r[i]!=0;)i++;if(m==f.childCount)break;const g=f.child(m),{colspan:y,rowspan:b,colwidth:x}=g.attrs;for(let w=0;w<b;w++){if(w+c>=n){(o||(o=[])).push({type:"overlong_rowspan",pos:u,n:b-w});break}const v=i+w*t;for(let S=0;S<y;S++){r[v+S]==0?r[v+S]=u:(o||(o=[])).push({type:"collision",row:c,pos:u,n:y-S});const C=x&&x[S];if(C){const T=(v+S)%t*2,E=a[T];E==null||E!=C&&a[T+1]==1?(a[T]=C,a[T+1]=1):E==C&&a[T+1]++}}}i+=y,u+=g.nodeSize}const p=(c+1)*t;let h=0;for(;i<p;)r[i++]==0&&h++;h&&(o||(o=[])).push({type:"missing",row:c,n:h}),u++}(t===0||n===0)&&(o||(o=[])).push({type:"zero_sized"});const s=new Ct(t,n,r,o);let l=!1;for(let c=0;!l&&c<a.length;c+=2)a[c]!=null&&a[c+1]<n&&(l=!0);return l&&DQe(s,a,e),s}function jQe(e){let t=-1,n=!1;for(let r=0;r<e.childCount;r++){const i=e.child(r);let o=0;if(n)for(let a=0;a<r;a++){const s=e.child(a);for(let l=0;l<s.childCount;l++){const c=s.child(l);a+c.attrs.rowspan>r&&(o+=c.attrs.colspan)}}for(let a=0;a<i.childCount;a++){const s=i.child(a);o+=s.attrs.colspan,s.attrs.rowspan>1&&(n=!0)}t==-1?t=o:t!=o&&(t=Math.max(t,o))}return t}function DQe(e,t,n){e.problems||(e.problems=[]);const r={};for(let i=0;i<e.map.length;i++){const o=e.map[i];if(r[o])continue;r[o]=!0;const a=n.nodeAt(o);if(!a)throw new RangeError(`No cell with offset ${o} found`);let s=null;const l=a.attrs;for(let c=0;c<l.colspan;c++){const u=(i+c)%e.width,f=t[u*2];f!=null&&(!l.colwidth||l.colwidth[c]!=f)&&((s||(s=LQe(l)))[c]=f)}s&&e.problems.unshift({type:"colwidth mismatch",pos:o,colwidth:s})}}function LQe(e){if(e.colwidth)return e.colwidth.slice();const t=[];for(let n=0;n<e.colspan;n++)t.push(0);return t}function fr(e){let t=e.cached.tableNodeTypes;if(!t){t=e.cached.tableNodeTypes={};for(const n in e.nodes){const r=e.nodes[n],i=r.spec.tableRole;i&&(t[i]=r)}}return t}var Js=new En("selectingCells");function eh(e){for(let t=e.depth-1;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return e.node(0).resolve(e.before(t+1));return null}function PQe(e){for(let t=e.depth;t>0;t--){const n=e.node(t).type.spec.tableRole;if(n==="cell"||n==="header_cell")return e.node(t)}return null}function Tr(e){const t=e.selection.$head;for(let n=t.depth;n>0;n--)if(t.node(n).type.spec.tableRole=="row")return!0;return!1}function LS(e){const t=e.selection;if("$anchorCell"in t&&t.$anchorCell)return t.$anchorCell.pos>t.$headCell.pos?t.$anchorCell:t.$headCell;if("node"in t&&t.node&&t.node.type.spec.tableRole=="cell")return t.$anchor;const n=eh(t.$head)||BQe(t.$head);if(n)return n;throw new RangeError(`No cell found around position ${t.head}`)}function BQe(e){for(let t=e.nodeAfter,n=e.pos;t;t=t.firstChild,n++){const r=t.type.spec.tableRole;if(r=="cell"||r=="header_cell")return e.doc.resolve(n)}for(let t=e.nodeBefore,n=e.pos;t;t=t.lastChild,n--){const r=t.type.spec.tableRole;if(r=="cell"||r=="header_cell")return e.doc.resolve(n-t.nodeSize)}}function MI(e){return e.parent.type.spec.tableRole=="row"&&!!e.nodeAfter}function UQe(e){return e.node(0).resolve(e.pos+e.nodeAfter.nodeSize)}function MD(e,t){return e.depth==t.depth&&e.pos>=t.start(-1)&&e.pos<=t.end(-1)}function jte(e,t,n){const r=e.node(-1),i=Ct.get(r),o=e.start(-1),a=i.nextCell(e.pos-o,t,n);return a==null?null:e.node(0).resolve(o+a)}function pu(e,t,n=1){const r={...e,colspan:e.colspan-n};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(t,n),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}function Dte(e,t,n=1){const r={...e,colspan:e.colspan+n};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let i=0;i<n;i++)r.colwidth.splice(t,0,0)}return r}function NQe(e,t,n){const r=fr(t.type.schema).header_cell;for(let i=0;i<e.height;i++)if(t.nodeAt(e.map[n+i*e.width]).type!=r)return!1;return!0}var at=class Da extends ke{constructor(t,n=t){const r=t.node(-1),i=Ct.get(r),o=t.start(-1),a=i.rectBetween(t.pos-o,n.pos-o),s=t.node(0),l=i.cellsInRect(a).filter(u=>u!=n.pos-o);l.unshift(n.pos-o);const c=l.map(u=>{const f=r.nodeAt(u);if(!f)throw RangeError(`No cell with offset ${u} found`);const p=o+u+1;return new kZ(s.resolve(p),s.resolve(p+f.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=t,this.$headCell=n}map(t,n){const r=t.resolve(n.map(this.$anchorCell.pos)),i=t.resolve(n.map(this.$headCell.pos));if(MI(r)&&MI(i)&&MD(r,i)){const o=this.$anchorCell.node(-1)!=r.node(-1);return o&&this.isRowSelection()?Da.rowSelection(r,i):o&&this.isColSelection()?Da.colSelection(r,i):new Da(r,i)}return _e.between(r,i)}content(){const t=this.$anchorCell.node(-1),n=Ct.get(t),r=this.$anchorCell.start(-1),i=n.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),o={},a=[];for(let l=i.top;l<i.bottom;l++){const c=[];for(let u=l*n.width+i.left,f=i.left;f<i.right;f++,u++){const p=n.map[u];if(o[p])continue;o[p]=!0;const h=n.findCell(p);let m=t.nodeAt(p);if(!m)throw RangeError(`No cell with offset ${p} found`);const g=i.left-h.left,y=h.right-i.right;if(g>0||y>0){let b=m.attrs;if(g>0&&(b=pu(b,0,g)),y>0&&(b=pu(b,b.colspan-y,y)),h.left<i.left){if(m=m.type.createAndFill(b),!m)throw RangeError(`Could not create cell with attrs ${JSON.stringify(b)}`)}else m=m.type.create(b,m.content)}if(h.top<i.top||h.bottom>i.bottom){const b={...m.attrs,rowspan:Math.min(h.bottom,i.bottom)-Math.max(h.top,i.top)};h.top<i.top?m=m.type.createAndFill(b):m=m.type.create(b,m.content)}c.push(m)}a.push(t.child(l).copy(U.from(c)))}const s=this.isColSelection()&&this.isRowSelection()?t:a;return new W(U.from(s),1,1)}replace(t,n=W.empty){const r=t.steps.length,i=this.ranges;for(let a=0;a<i.length;a++){const{$from:s,$to:l}=i[a],c=t.mapping.slice(r);t.replace(c.map(s.pos),c.map(l.pos),a?W.empty:n)}const o=ke.findFrom(t.doc.resolve(t.mapping.slice(r).map(this.to)),-1);o&&t.setSelection(o)}replaceWith(t,n){this.replace(t,new W(U.from(n),0,0))}forEachCell(t){const n=this.$anchorCell.node(-1),r=Ct.get(n),i=this.$anchorCell.start(-1),o=r.cellsInRect(r.rectBetween(this.$anchorCell.pos-i,this.$headCell.pos-i));for(let a=0;a<o.length;a++)t(n.nodeAt(o[a]),i+o[a])}isColSelection(){const t=this.$anchorCell.index(-1),n=this.$headCell.index(-1);if(Math.min(t,n)>0)return!1;const r=t+this.$anchorCell.nodeAfter.attrs.rowspan,i=n+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(t,n=t){const r=t.node(-1),i=Ct.get(r),o=t.start(-1),a=i.findCell(t.pos-o),s=i.findCell(n.pos-o),l=t.node(0);return a.top<=s.top?(a.top>0&&(t=l.resolve(o+i.map[a.left])),s.bottom<i.height&&(n=l.resolve(o+i.map[i.width*(i.height-1)+s.right-1]))):(s.top>0&&(n=l.resolve(o+i.map[s.left])),a.bottom<i.height&&(t=l.resolve(o+i.map[i.width*(i.height-1)+a.right-1]))),new Da(t,n)}isRowSelection(){const t=this.$anchorCell.node(-1),n=Ct.get(t),r=this.$anchorCell.start(-1),i=n.colCount(this.$anchorCell.pos-r),o=n.colCount(this.$headCell.pos-r);if(Math.min(i,o)>0)return!1;const a=i+this.$anchorCell.nodeAfter.attrs.colspan,s=o+this.$headCell.nodeAfter.attrs.colspan;return Math.max(a,s)==n.width}eq(t){return t instanceof Da&&t.$anchorCell.pos==this.$anchorCell.pos&&t.$headCell.pos==this.$headCell.pos}static rowSelection(t,n=t){const r=t.node(-1),i=Ct.get(r),o=t.start(-1),a=i.findCell(t.pos-o),s=i.findCell(n.pos-o),l=t.node(0);return a.left<=s.left?(a.left>0&&(t=l.resolve(o+i.map[a.top*i.width])),s.right<i.width&&(n=l.resolve(o+i.map[i.width*(s.top+1)-1]))):(s.left>0&&(n=l.resolve(o+i.map[s.top*i.width])),a.right<i.width&&(t=l.resolve(o+i.map[i.width*(a.top+1)-1]))),new Da(t,n)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(t,n){return new Da(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,r=n){return new Da(t.resolve(n),t.resolve(r))}getBookmark(){return new WQe(this.$anchorCell.pos,this.$headCell.pos)}};at.prototype.visible=!1;ke.jsonID("cell",at);var WQe=class Lte{constructor(t,n){this.anchor=t,this.head=n}map(t){return new Lte(t.map(this.anchor),t.map(this.head))}resolve(t){const n=t.resolve(this.anchor),r=t.resolve(this.head);return n.parent.type.spec.tableRole=="row"&&r.parent.type.spec.tableRole=="row"&&n.index()<n.parent.childCount&&r.index()<r.parent.childCount&&MD(n,r)?new at(n,r):ke.near(r,1)}};function KQe(e){if(!(e.selection instanceof at))return null;const t=[];return e.selection.forEachCell((n,r)=>{t.push(fn.node(r,r+n.nodeSize,{class:"selectedCell"}))}),vt.create(e.doc,t)}function qQe({$from:e,$to:t}){if(e.pos==t.pos||e.pos<t.pos-6)return!1;let n=e.pos,r=t.pos,i=e.depth;for(;i>=0&&!(e.after(i+1)<e.end(i));i--,n++);for(let o=t.depth;o>=0&&!(t.before(o+1)>t.start(o));o--,r--);return n==r&&/row|table/.test(e.node(i).type.spec.tableRole)}function VQe({$from:e,$to:t}){let n,r;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"){n=o;break}}for(let i=t.depth;i>0;i--){const o=t.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){r=o;break}}return n!==r&&t.parentOffset===0}function zQe(e,t,n){const r=(t||e).selection,i=(t||e).doc;let o,a;if(r instanceof Se&&(a=r.node.type.spec.tableRole)){if(a=="cell"||a=="header_cell")o=at.create(i,r.from);else if(a=="row"){const s=i.resolve(r.from+1);o=at.rowSelection(s,s)}else if(!n){const s=Ct.get(r.node),l=r.from+1,c=l+s.map[s.width*s.height-1];o=at.create(i,l+1,c)}}else r instanceof _e&&qQe(r)?o=_e.create(i,r.from):r instanceof _e&&VQe(r)&&(o=_e.create(i,r.$from.start(),r.$from.end()));return o&&(t||(t=e.tr)).setSelection(o),t}var QQe=new En("fix-tables");function Pte(e,t,n,r){const i=e.childCount,o=t.childCount;e:for(let a=0,s=0;a<o;a++){const l=t.child(a);for(let c=s,u=Math.min(i,a+3);c<u;c++)if(e.child(c)==l){s=c+1,n+=l.nodeSize;continue e}r(l,n),s<i&&e.child(s).sameMarkup(l)?Pte(e.child(s),l,n+1,r):l.nodesBetween(0,l.content.size,r,n+1),n+=l.nodeSize}}function Bte(e,t){let n;const r=(i,o)=>{i.type.spec.tableRole=="table"&&(n=HQe(e,i,o,n))};return t?t.doc!=e.doc&&Pte(t.doc,e.doc,0,r):e.doc.descendants(r),n}function HQe(e,t,n,r){const i=Ct.get(t);if(!i.problems)return r;r||(r=e.tr);const o=[];for(let l=0;l<i.height;l++)o.push(0);for(let l=0;l<i.problems.length;l++){const c=i.problems[l];if(c.type=="collision"){const u=t.nodeAt(c.pos);if(!u)continue;const f=u.attrs;for(let p=0;p<f.rowspan;p++)o[c.row+p]+=c.n;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,pu(f,f.colspan-c.n,c.n))}else if(c.type=="missing")o[c.row]+=c.n;else if(c.type=="overlong_rowspan"){const u=t.nodeAt(c.pos);if(!u)continue;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,{...u.attrs,rowspan:u.attrs.rowspan-c.n})}else if(c.type=="colwidth mismatch"){const u=t.nodeAt(c.pos);if(!u)continue;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,{...u.attrs,colwidth:c.colwidth})}else if(c.type=="zero_sized"){const u=r.mapping.map(n);r.delete(u,u+t.nodeSize)}}let a,s;for(let l=0;l<o.length;l++)o[l]&&(a==null&&(a=l),s=l);for(let l=0,c=n+1;l<i.height;l++){const u=t.child(l),f=c+u.nodeSize,p=o[l];if(p>0){let h="cell";u.firstChild&&(h=u.firstChild.type.spec.tableRole);const m=[];for(let y=0;y<p;y++){const b=fr(e.schema)[h].createAndFill();b&&m.push(b)}const g=(l==0||a==l-1)&&s==l?c+1:f-1;r.insert(r.mapping.map(g),m)}c=f}return r.setMeta(QQe,{fixTables:!0})}function $r(e){const t=e.selection,n=LS(e),r=n.node(-1),i=n.start(-1),o=Ct.get(r);return{...t instanceof at?o.rectBetween(t.$anchorCell.pos-i,t.$headCell.pos-i):o.findCell(n.pos-i),tableStart:i,map:o,table:r}}function FD(e,{map:t,tableStart:n,table:r},i){let o=i>0?-1:0;NQe(t,r,i+o)&&(o=i==0||i==t.width?null:0);for(let a=0;a<t.height;a++){const s=a*t.width+i;if(i>0&&i<t.width&&t.map[s-1]==t.map[s]){const l=t.map[s],c=r.nodeAt(l);e.setNodeMarkup(e.mapping.map(n+l),null,Dte(c.attrs,i-t.colCount(l))),a+=c.attrs.rowspan-1}else{const l=o==null?fr(r.type.schema).cell:r.nodeAt(t.map[s+o]).type,c=t.positionAt(a,i,r);e.insert(e.mapping.map(n+c),l.createAndFill())}}return e}function YQe(e,t){if(!Tr(e))return!1;if(t){const n=$r(e);t(FD(e.tr,n,n.left))}return!0}function GQe(e,t){if(!Tr(e))return!1;if(t){const n=$r(e);t(FD(e.tr,n,n.right))}return!0}function JQe(e,{map:t,table:n,tableStart:r},i){const o=e.mapping.maps.length;for(let a=0;a<t.height;){const s=a*t.width+i,l=t.map[s],c=n.nodeAt(l),u=c.attrs;if(i>0&&t.map[s-1]==l||i<t.width-1&&t.map[s+1]==l)e.setNodeMarkup(e.mapping.slice(o).map(r+l),null,pu(u,i-t.colCount(l)));else{const f=e.mapping.slice(o).map(r+l);e.delete(f,f+c.nodeSize)}a+=u.rowspan}}function ZQe(e,t){if(!Tr(e))return!1;if(t){const n=$r(e),r=e.tr;if(n.left==0&&n.right==n.map.width)return!1;for(let i=n.right-1;JQe(r,n,i),i!=n.left;i--){const o=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!o)throw RangeError("No table found");n.table=o,n.map=Ct.get(o)}t(r)}return!0}function XQe(e,t,n){var r;const i=fr(t.type.schema).header_cell;for(let o=0;o<e.width;o++)if(((r=t.nodeAt(e.map[o+n*e.width]))==null?void 0:r.type)!=i)return!1;return!0}function jD(e,{map:t,tableStart:n,table:r},i){var o;let a=n;for(let c=0;c<i;c++)a+=r.child(c).nodeSize;const s=[];let l=i>0?-1:0;XQe(t,r,i+l)&&(l=i==0||i==t.height?null:0);for(let c=0,u=t.width*i;c<t.width;c++,u++)if(i>0&&i<t.height&&t.map[u]==t.map[u-t.width]){const f=t.map[u],p=r.nodeAt(f).attrs;e.setNodeMarkup(n+f,null,{...p,rowspan:p.rowspan+1}),c+=p.colspan-1}else{const f=l==null?fr(r.type.schema).cell:(o=r.nodeAt(t.map[u+l*t.width]))==null?void 0:o.type,p=f==null?void 0:f.createAndFill();p&&s.push(p)}return e.insert(a,fr(r.type.schema).row.create(null,s)),e}function eHe(e,t){if(!Tr(e))return!1;if(t){const n=$r(e);t(jD(e.tr,n,n.top))}return!0}function tHe(e,t){if(!Tr(e))return!1;if(t){const n=$r(e);t(jD(e.tr,n,n.bottom))}return!0}function nHe(e,{map:t,table:n,tableStart:r},i){let o=0;for(let c=0;c<i;c++)o+=n.child(c).nodeSize;const a=o+n.child(i).nodeSize,s=e.mapping.maps.length;e.delete(o+r,a+r);const l=new Set;for(let c=0,u=i*t.width;c<t.width;c++,u++){const f=t.map[u];if(!l.has(f)){if(l.add(f),i>0&&f==t.map[u-t.width]){const p=n.nodeAt(f).attrs;e.setNodeMarkup(e.mapping.slice(s).map(f+r),null,{...p,rowspan:p.rowspan-1}),c+=p.colspan-1}else if(i<t.height&&f==t.map[u+t.width]){const p=n.nodeAt(f),h=p.attrs,m=p.type.create({...h,rowspan:p.attrs.rowspan-1},p.content),g=t.positionAt(i+1,c,n);e.insert(e.mapping.slice(s).map(r+g),m),c+=h.colspan-1}}}}function rHe(e,t){if(!Tr(e))return!1;if(t){const n=$r(e),r=e.tr;if(n.top==0&&n.bottom==n.map.height)return!1;for(let i=n.bottom-1;nHe(r,n,i),i!=n.top;i--){const o=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!o)throw RangeError("No table found");n.table=o,n.map=Ct.get(n.table)}t(r)}return!0}function hU(e){const t=e.content;return t.childCount==1&&t.child(0).isTextblock&&t.child(0).childCount==0}function iHe({width:e,height:t,map:n},r){let i=r.top*e+r.left,o=i,a=(r.bottom-1)*e+r.left,s=i+(r.right-r.left-1);for(let l=r.top;l<r.bottom;l++){if(r.left>0&&n[o]==n[o-1]||r.right<e&&n[s]==n[s+1])return!0;o+=e,s+=e}for(let l=r.left;l<r.right;l++){if(r.top>0&&n[i]==n[i-e]||r.bottom<t&&n[a]==n[a+e])return!0;i++,a++}return!1}function mU(e,t){const n=e.selection;if(!(n instanceof at)||n.$anchorCell.pos==n.$headCell.pos)return!1;const r=$r(e),{map:i}=r;if(iHe(i,r))return!1;if(t){const o=e.tr,a={};let s=U.empty,l,c;for(let u=r.top;u<r.bottom;u++)for(let f=r.left;f<r.right;f++){const p=i.map[u*i.width+f],h=r.table.nodeAt(p);if(!(a[p]||!h))if(a[p]=!0,l==null)l=p,c=h;else{hU(h)||(s=s.append(h.content));const m=o.mapping.map(p+r.tableStart);o.delete(m,m+h.nodeSize)}}if(l==null||c==null)return!0;if(o.setNodeMarkup(l+r.tableStart,null,{...Dte(c.attrs,c.attrs.colspan,r.right-r.left-c.attrs.colspan),rowspan:r.bottom-r.top}),s.size){const u=l+1+c.content.size,f=hU(c)?l+1:u;o.replaceWith(f+r.tableStart,u+r.tableStart,s)}o.setSelection(new at(o.doc.resolve(l+r.tableStart))),t(o)}return!0}function AU(e,t){const n=fr(e.schema);return oHe(({node:r})=>n[r.type.spec.tableRole])(e,t)}function oHe(e){return(t,n)=>{var r;const i=t.selection;let o,a;if(i instanceof at){if(i.$anchorCell.pos!=i.$headCell.pos)return!1;o=i.$anchorCell.nodeAfter,a=i.$anchorCell.pos}else{if(o=PQe(i.$from),!o)return!1;a=(r=eh(i.$from))==null?void 0:r.pos}if(o==null||a==null||o.attrs.colspan==1&&o.attrs.rowspan==1)return!1;if(n){let s=o.attrs;const l=[],c=s.colwidth;s.rowspan>1&&(s={...s,rowspan:1}),s.colspan>1&&(s={...s,colspan:1});const u=$r(t),f=t.tr;for(let h=0;h<u.right-u.left;h++)l.push(c?{...s,colwidth:c&&c[h]?[c[h]]:null}:s);let p;for(let h=u.top;h<u.bottom;h++){let m=u.map.positionAt(h,u.left,u.table);h==u.top&&(m+=o.nodeSize);for(let g=u.left,y=0;g<u.right;g++,y++)g==u.left&&h==u.top||f.insert(p=f.mapping.map(m+u.tableStart,1),e({node:o,row:h,col:g}).createAndFill(l[y]))}f.setNodeMarkup(a,e({node:o,row:u.top,col:u.left}),l[0]),i instanceof at&&f.setSelection(new at(f.doc.resolve(i.$anchorCell.pos),p?f.doc.resolve(p):void 0)),n(f)}return!0}}function aHe(e,t){return function(n,r){if(!Tr(n))return!1;const i=LS(n);if(i.nodeAfter.attrs[e]===t)return!1;if(r){const o=n.tr;n.selection instanceof at?n.selection.forEachCell((a,s)=>{a.attrs[e]!==t&&o.setNodeMarkup(s,null,{...a.attrs,[e]:t})}):o.setNodeMarkup(i.pos,null,{...i.nodeAfter.attrs,[e]:t}),r(o)}return!0}}function sHe(e){return function(t,n){if(!Tr(t))return!1;if(n){const r=fr(t.schema),i=$r(t),o=t.tr,a=i.map.cellsInRect(e=="column"?{left:i.left,top:0,right:i.right,bottom:i.map.height}:e=="row"?{left:0,top:i.top,right:i.map.width,bottom:i.bottom}:i),s=a.map(l=>i.table.nodeAt(l));for(let l=0;l<a.length;l++)s[l].type==r.header_cell&&o.setNodeMarkup(i.tableStart+a[l],r.cell,s[l].attrs);if(o.steps.length==0)for(let l=0;l<a.length;l++)o.setNodeMarkup(i.tableStart+a[l],r.header_cell,s[l].attrs);n(o)}return!0}}function gU(e,t,n){const r=t.map.cellsInRect({left:0,top:0,right:e=="row"?t.map.width:1,bottom:e=="column"?t.map.height:1});for(let i=0;i<r.length;i++){const o=t.table.nodeAt(r[i]);if(o&&o.type!==n.header_cell)return!1}return!0}function Km(e,t){return t=t||{useDeprecatedLogic:!1},t.useDeprecatedLogic?sHe(e):function(n,r){if(!Tr(n))return!1;if(r){const i=fr(n.schema),o=$r(n),a=n.tr,s=gU("row",o,i),l=gU("column",o,i),u=(e==="column"?s:e==="row"?l:!1)?1:0,f=e=="column"?{left:0,top:u,right:1,bottom:o.map.height}:e=="row"?{left:u,top:0,right:o.map.width,bottom:1}:o,p=e=="column"?l?i.cell:i.header_cell:e=="row"?s?i.cell:i.header_cell:i.cell;o.map.cellsInRect(f).forEach(h=>{const m=h+o.tableStart,g=a.doc.nodeAt(m);g&&a.setNodeMarkup(m,p,g.attrs)}),r(a)}return!0}}Km("row",{useDeprecatedLogic:!0});Km("column",{useDeprecatedLogic:!0});var lHe=Km("cell",{useDeprecatedLogic:!0});function cHe(e,t){if(t<0){const n=e.nodeBefore;if(n)return e.pos-n.nodeSize;for(let r=e.index(-1)-1,i=e.before();r>=0;r--){const o=e.node(-1).child(r),a=o.lastChild;if(a)return i-1-a.nodeSize;i-=o.nodeSize}}else{if(e.index()<e.parent.childCount-1)return e.pos+e.nodeAfter.nodeSize;const n=e.node(-1);for(let r=e.indexAfter(-1),i=e.after();r<n.childCount;r++){const o=n.child(r);if(o.childCount)return i+1;i+=o.nodeSize}}return null}function vU(e){return function(t,n){if(!Tr(t))return!1;const r=cHe(LS(t),e);if(r==null)return!1;if(n){const i=t.doc.resolve(r);n(t.tr.setSelection(_e.between(i,UQe(i))).scrollIntoView())}return!0}}function uHe(e,t){const n=e.selection.$anchor;for(let r=n.depth;r>0;r--)if(n.node(r).type.spec.tableRole=="table")return t&&t(e.tr.delete(n.before(r),n.after(r)).scrollIntoView()),!0;return!1}function Fv(e,t){const n=e.selection;if(!(n instanceof at))return!1;if(t){const r=e.tr,i=fr(e.schema).cell.createAndFill().content;n.forEachCell((o,a)=>{o.content.eq(i)||r.replace(r.mapping.map(a+1),r.mapping.map(a+o.nodeSize-1),new W(i,0,0))}),r.docChanged&&t(r)}return!0}function dHe(e){if(!e.size)return null;let{content:t,openStart:n,openEnd:r}=e;for(;t.childCount==1&&(n>0&&r>0||t.child(0).type.spec.tableRole=="table");)n--,r--,t=t.child(0).content;const i=t.child(0),o=i.type.spec.tableRole,a=i.type.schema,s=[];if(o=="row")for(let l=0;l<t.childCount;l++){let c=t.child(l).content;const u=l?0:Math.max(0,n-1),f=l<t.childCount-1?0:Math.max(0,r-1);(u||f)&&(c=FI(fr(a).row,new W(c,u,f)).content),s.push(c)}else if(o=="cell"||o=="header_cell")s.push(n||r?FI(fr(a).row,new W(t,n,r)).content:t);else return null;return fHe(a,s)}function fHe(e,t){const n=[];for(let i=0;i<t.length;i++){const o=t[i];for(let a=o.childCount-1;a>=0;a--){const{rowspan:s,colspan:l}=o.child(a).attrs;for(let c=i;c<i+s;c++)n[c]=(n[c]||0)+l}}let r=0;for(let i=0;i<n.length;i++)r=Math.max(r,n[i]);for(let i=0;i<n.length;i++)if(i>=t.length&&t.push(U.empty),n[i]<r){const o=fr(e).cell.createAndFill(),a=[];for(let s=n[i];s<r;s++)a.push(o);t[i]=t[i].append(U.from(a))}return{height:t.length,width:r,rows:t}}function FI(e,t){const n=e.createAndFill();return new MQe(n).replace(0,n.content.size,t).doc}function pHe({width:e,height:t,rows:n},r,i){if(e!=r){const o=[],a=[];for(let s=0;s<n.length;s++){const l=n[s],c=[];for(let u=o[s]||0,f=0;u<r;f++){let p=l.child(f%l.childCount);u+p.attrs.colspan>r&&(p=p.type.createChecked(pu(p.attrs,p.attrs.colspan,u+p.attrs.colspan-r),p.content)),c.push(p),u+=p.attrs.colspan;for(let h=1;h<p.attrs.rowspan;h++)o[s+h]=(o[s+h]||0)+p.attrs.colspan}a.push(U.from(c))}n=a,e=r}if(t!=i){const o=[];for(let a=0,s=0;a<i;a++,s++){const l=[],c=n[s%t];for(let u=0;u<c.childCount;u++){let f=c.child(u);a+f.attrs.rowspan>i&&(f=f.type.create({...f.attrs,rowspan:Math.max(1,i-f.attrs.rowspan)},f.content)),l.push(f)}o.push(U.from(l))}n=o,t=i}return{width:e,height:t,rows:n}}function hHe(e,t,n,r,i,o,a){const s=e.doc.type.schema,l=fr(s);let c,u;if(i>t.width)for(let f=0,p=0;f<t.height;f++){const h=n.child(f);p+=h.nodeSize;const m=[];let g;h.lastChild==null||h.lastChild.type==l.cell?g=c||(c=l.cell.createAndFill()):g=u||(u=l.header_cell.createAndFill());for(let y=t.width;y<i;y++)m.push(g);e.insert(e.mapping.slice(a).map(p-1+r),m)}if(o>t.height){const f=[];for(let m=0,g=(t.height-1)*t.width;m<Math.max(t.width,i);m++){const y=m>=t.width?!1:n.nodeAt(t.map[g+m]).type==l.header_cell;f.push(y?u||(u=l.header_cell.createAndFill()):c||(c=l.cell.createAndFill()))}const p=l.row.create(null,U.from(f)),h=[];for(let m=t.height;m<o;m++)h.push(p);e.insert(e.mapping.slice(a).map(r+n.nodeSize-2),h)}return!!(c||u)}function yU(e,t,n,r,i,o,a,s){if(a==0||a==t.height)return!1;let l=!1;for(let c=i;c<o;c++){const u=a*t.width+c,f=t.map[u];if(t.map[u-t.width]==f){l=!0;const p=n.nodeAt(f),{top:h,left:m}=t.findCell(f);e.setNodeMarkup(e.mapping.slice(s).map(f+r),null,{...p.attrs,rowspan:a-h}),e.insert(e.mapping.slice(s).map(t.positionAt(a,m,n)),p.type.createAndFill({...p.attrs,rowspan:h+p.attrs.rowspan-a})),c+=p.attrs.colspan-1}}return l}function bU(e,t,n,r,i,o,a,s){if(a==0||a==t.width)return!1;let l=!1;for(let c=i;c<o;c++){const u=c*t.width+a,f=t.map[u];if(t.map[u-1]==f){l=!0;const p=n.nodeAt(f),h=t.colCount(f),m=e.mapping.slice(s).map(f+r);e.setNodeMarkup(m,null,pu(p.attrs,a-h,p.attrs.colspan-(a-h))),e.insert(m+p.nodeSize,p.type.createAndFill(pu(p.attrs,0,a-h))),c+=p.attrs.rowspan-1}}return l}function CU(e,t,n,r,i){let o=n?e.doc.nodeAt(n-1):e.doc;if(!o)throw new Error("No table found");let a=Ct.get(o);const{top:s,left:l}=r,c=l+i.width,u=s+i.height,f=e.tr;let p=0;function h(){if(o=n?f.doc.nodeAt(n-1):f.doc,!o)throw new Error("No table found");a=Ct.get(o),p=f.mapping.maps.length}hHe(f,a,o,n,c,u,p)&&h(),yU(f,a,o,n,l,c,s,p)&&h(),yU(f,a,o,n,l,c,u,p)&&h(),bU(f,a,o,n,s,u,l,p)&&h(),bU(f,a,o,n,s,u,c,p)&&h();for(let m=s;m<u;m++){const g=a.positionAt(m,l,o),y=a.positionAt(m,c,o);f.replace(f.mapping.slice(p).map(g+n),f.mapping.slice(p).map(y+n),new W(i.rows[m-s],0,0))}h(),f.setSelection(new at(f.doc.resolve(n+a.positionAt(s,l,o)),f.doc.resolve(n+a.positionAt(u-1,c-1,o)))),t(f)}var mHe=pX({ArrowLeft:jv("horiz",-1),ArrowRight:jv("horiz",1),ArrowUp:jv("vert",-1),ArrowDown:jv("vert",1),"Shift-ArrowLeft":Dv("horiz",-1),"Shift-ArrowRight":Dv("horiz",1),"Shift-ArrowUp":Dv("vert",-1),"Shift-ArrowDown":Dv("vert",1),Backspace:Fv,"Mod-Backspace":Fv,Delete:Fv,"Mod-Delete":Fv});function ay(e,t,n){return n.eq(e.selection)?!1:(t&&t(e.tr.setSelection(n).scrollIntoView()),!0)}function jv(e,t){return(n,r,i)=>{if(!i)return!1;const o=n.selection;if(o instanceof at)return ay(n,r,ke.near(o.$headCell,t));if(e!="horiz"&&!o.empty)return!1;const a=Ute(i,e,t);if(a==null)return!1;if(e=="horiz")return ay(n,r,ke.near(n.doc.resolve(o.head+t),t));{const s=n.doc.resolve(a),l=jte(s,e,t);let c;return l?c=ke.near(l,1):t<0?c=ke.near(n.doc.resolve(s.before(-1)),-1):c=ke.near(n.doc.resolve(s.after(-1)),1),ay(n,r,c)}}}function Dv(e,t){return(n,r,i)=>{if(!i)return!1;const o=n.selection;let a;if(o instanceof at)a=o;else{const l=Ute(i,e,t);if(l==null)return!1;a=new at(n.doc.resolve(l))}const s=jte(a.$headCell,e,t);return s?ay(n,r,new at(a.$anchorCell,s)):!1}}function AHe(e,t){const n=e.state.doc,r=eh(n.resolve(t));return r?(e.dispatch(e.state.tr.setSelection(new at(r))),!0):!1}function gHe(e,t,n){if(!Tr(e.state))return!1;let r=dHe(n);const i=e.state.selection;if(i instanceof at){r||(r={width:1,height:1,rows:[U.from(FI(fr(e.state.schema).cell,n))]});const o=i.$anchorCell.node(-1),a=i.$anchorCell.start(-1),s=Ct.get(o).rectBetween(i.$anchorCell.pos-a,i.$headCell.pos-a);return r=pHe(r,s.right-s.left,s.bottom-s.top),CU(e.state,e.dispatch,a,s,r),!0}else if(r){const o=LS(e.state),a=o.start(-1);return CU(e.state,e.dispatch,a,Ct.get(o.node(-1)).findCell(o.pos-a),r),!0}else return!1}function vHe(e,t){var n;if(t.ctrlKey||t.metaKey)return;const r=SU(e,t.target);let i;if(t.shiftKey&&e.state.selection instanceof at)o(e.state.selection.$anchorCell,t),t.preventDefault();else if(t.shiftKey&&r&&(i=eh(e.state.selection.$anchor))!=null&&((n=qx(e,t))==null?void 0:n.pos)!=i.pos)o(i,t),t.preventDefault();else if(!r)return;function o(l,c){let u=qx(e,c);const f=Js.getState(e.state)==null;if(!u||!MD(l,u))if(f)u=l;else return;const p=new at(l,u);if(f||!e.state.selection.eq(p)){const h=e.state.tr.setSelection(p);f&&h.setMeta(Js,l.pos),e.dispatch(h)}}function a(){e.root.removeEventListener("mouseup",a),e.root.removeEventListener("dragstart",a),e.root.removeEventListener("mousemove",s),Js.getState(e.state)!=null&&e.dispatch(e.state.tr.setMeta(Js,-1))}function s(l){const c=l,u=Js.getState(e.state);let f;if(u!=null)f=e.state.doc.resolve(u);else if(SU(e,c.target)!=r&&(f=qx(e,t),!f))return a();f&&o(f,c)}e.root.addEventListener("mouseup",a),e.root.addEventListener("dragstart",a),e.root.addEventListener("mousemove",s)}function Ute(e,t,n){if(!(e.state.selection instanceof _e))return null;const{$head:r}=e.state.selection;for(let i=r.depth-1;i>=0;i--){const o=r.node(i);if((n<0?r.index(i):r.indexAfter(i))!=(n<0?0:o.childCount))return null;if(o.type.spec.tableRole=="cell"||o.type.spec.tableRole=="header_cell"){const s=r.before(i),l=t=="vert"?n>0?"down":"up":n>0?"right":"left";return e.endOfTextblock(l)?s:null}}return null}function SU(e,t){for(;t&&t!=e.dom;t=t.parentNode)if(t.nodeName=="TD"||t.nodeName=="TH")return t;return null}function qx(e,t){const n=e.posAtCoords({left:t.clientX,top:t.clientY});return n&&n?eh(e.state.doc.resolve(n.pos)):null}var Nte=class{constructor(t,n){this.node=t,this.defaultCellMinWidth=n,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.table.style.setProperty("--default-cell-min-width",`${n}px`),this.colgroup=this.table.appendChild(document.createElement("colgroup")),jI(t,this.colgroup,this.table,n),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(t){return t.type!=this.node.type?!1:(this.node=t,jI(t,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(t){return t.type=="attributes"&&(t.target==this.table||this.colgroup.contains(t.target))}};function jI(e,t,n,r,i,o){var a;let s=0,l=!0,c=t.firstChild;const u=e.firstChild;if(u){for(let f=0,p=0;f<u.childCount;f++){const{colspan:h,colwidth:m}=u.child(f).attrs;for(let g=0;g<h;g++,p++){const y=i==p?o:m&&m[g],b=y?y+"px":"";if(s+=y||r,y||(l=!1),c)c.style.width!=b&&(c.style.width=b),c=c.nextSibling;else{const x=document.createElement("col");x.style.width=b,t.appendChild(x)}}}for(;c;){const f=c.nextSibling;(a=c.parentNode)==null||a.removeChild(c),c=f}l?(n.style.width=s+"px",n.style.minWidth=""):(n.style.width="",n.style.minWidth=s+"px")}}var Vr=new En("tableColumnResizing");function Wte({handleWidth:e=5,cellMinWidth:t=25,defaultCellMinWidth:n=100,View:r=Nte,lastColumnResizable:i=!0}={}){const o=new cn({key:Vr,state:{init(a,s){var l,c;const u=(c=(l=o.spec)==null?void 0:l.props)==null?void 0:c.nodeViews,f=fr(s.schema).table.name;return r&&u&&(u[f]=(p,h)=>new r(p,n,h)),new yHe(-1,!1)},apply(a,s){return s.apply(a)}},props:{attributes:a=>{const s=Vr.getState(a);return s&&s.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(a,s)=>{bHe(a,s,e,i)},mouseleave:a=>{CHe(a)},mousedown:(a,s)=>{SHe(a,s,t,n)}},decorations:a=>{const s=Vr.getState(a);if(s&&s.activeHandle>-1)return _He(a,s.activeHandle)},nodeViews:{}}});return o}var yHe=class sy{constructor(t,n){this.activeHandle=t,this.dragging=n}apply(t){const n=this,r=t.getMeta(Vr);if(r&&r.setHandle!=null)return new sy(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new sy(n.activeHandle,r.setDragging);if(n.activeHandle>-1&&t.docChanged){let i=t.mapping.map(n.activeHandle,-1);return MI(t.doc.resolve(i))||(i=-1),new sy(i,n.dragging)}return n}};function bHe(e,t,n,r){if(!e.editable)return;const i=Vr.getState(e.state);if(i&&!i.dragging){const o=xHe(t.target);let a=-1;if(o){const{left:s,right:l}=o.getBoundingClientRect();t.clientX-s<=n?a=wU(e,t,"left",n):l-t.clientX<=n&&(a=wU(e,t,"right",n))}if(a!=i.activeHandle){if(!r&&a!==-1){const s=e.state.doc.resolve(a),l=s.node(-1),c=Ct.get(l),u=s.start(-1);if(c.colCount(s.pos-u)+s.nodeAfter.attrs.colspan-1==c.width-1)return}Kte(e,a)}}}function CHe(e){if(!e.editable)return;const t=Vr.getState(e.state);t&&t.activeHandle>-1&&!t.dragging&&Kte(e,-1)}function SHe(e,t,n,r){var i;if(!e.editable)return!1;const o=(i=e.dom.ownerDocument.defaultView)!=null?i:window,a=Vr.getState(e.state);if(!a||a.activeHandle==-1||a.dragging)return!1;const s=e.state.doc.nodeAt(a.activeHandle),l=wHe(e,a.activeHandle,s.attrs);e.dispatch(e.state.tr.setMeta(Vr,{setDragging:{startX:t.clientX,startWidth:l}}));function c(f){o.removeEventListener("mouseup",c),o.removeEventListener("mousemove",u);const p=Vr.getState(e.state);p!=null&&p.dragging&&(THe(e,p.activeHandle,xU(p.dragging,f,n)),e.dispatch(e.state.tr.setMeta(Vr,{setDragging:null})))}function u(f){if(!f.which)return c(f);const p=Vr.getState(e.state);if(p&&p.dragging){const h=xU(p.dragging,f,n);TU(e,p.activeHandle,h,r)}}return TU(e,a.activeHandle,l,r),o.addEventListener("mouseup",c),o.addEventListener("mousemove",u),t.preventDefault(),!0}function wHe(e,t,{colspan:n,colwidth:r}){const i=r&&r[r.length-1];if(i)return i;const o=e.domAtPos(t);let s=o.node.childNodes[o.offset].offsetWidth,l=n;if(r)for(let c=0;c<n;c++)r[c]&&(s-=r[c],l--);return s/l}function xHe(e){for(;e&&e.nodeName!="TD"&&e.nodeName!="TH";)e=e.classList&&e.classList.contains("ProseMirror")?null:e.parentNode;return e}function wU(e,t,n,r){const i=n=="right"?-r:r,o=e.posAtCoords({left:t.clientX+i,top:t.clientY});if(!o)return-1;const{pos:a}=o,s=eh(e.state.doc.resolve(a));if(!s)return-1;if(n=="right")return s.pos;const l=Ct.get(s.node(-1)),c=s.start(-1),u=l.map.indexOf(s.pos-c);return u%l.width==0?-1:c+l.map[u-1]}function xU(e,t,n){const r=t.clientX-e.startX;return Math.max(n,e.startWidth+r)}function Kte(e,t){e.dispatch(e.state.tr.setMeta(Vr,{setHandle:t}))}function THe(e,t,n){const r=e.state.doc.resolve(t),i=r.node(-1),o=Ct.get(i),a=r.start(-1),s=o.colCount(r.pos-a)+r.nodeAfter.attrs.colspan-1,l=e.state.tr;for(let c=0;c<o.height;c++){const u=c*o.width+s;if(c&&o.map[u]==o.map[u-o.width])continue;const f=o.map[u],p=i.nodeAt(f).attrs,h=p.colspan==1?0:s-o.colCount(f);if(p.colwidth&&p.colwidth[h]==n)continue;const m=p.colwidth?p.colwidth.slice():IHe(p.colspan);m[h]=n,l.setNodeMarkup(a+f,null,{...p,colwidth:m})}l.docChanged&&e.dispatch(l)}function TU(e,t,n,r){const i=e.state.doc.resolve(t),o=i.node(-1),a=i.start(-1),s=Ct.get(o).colCount(i.pos-a)+i.nodeAfter.attrs.colspan-1;let l=e.domAtPos(i.start(-1)).node;for(;l&&l.nodeName!="TABLE";)l=l.parentNode;l&&jI(o,l.firstChild,l,r,s,n)}function IHe(e){return Array(e).fill(0)}function _He(e,t){var n;const r=[],i=e.doc.resolve(t),o=i.node(-1);if(!o)return vt.empty;const a=Ct.get(o),s=i.start(-1),l=a.colCount(i.pos-s)+i.nodeAfter.attrs.colspan-1;for(let c=0;c<a.height;c++){const u=l+c*a.width;if((l==a.width-1||a.map[u]!=a.map[u+1])&&(c==0||a.map[u]!=a.map[u-a.width])){const f=a.map[u],p=s+f+o.nodeAt(f).nodeSize-1,h=document.createElement("div");h.className="column-resize-handle",(n=Vr.getState(e))!=null&&n.dragging&&r.push(fn.node(s+f,s+f+o.nodeAt(f).nodeSize,{class:"column-resize-dragging"})),r.push(fn.widget(p,h))}}return vt.create(e.doc,r)}function qte({allowTableNodeSelection:e=!1}={}){return new cn({key:Js,state:{init(){return null},apply(t,n){const r=t.getMeta(Js);if(r!=null)return r==-1?null:r;if(n==null||!t.docChanged)return n;const{deleted:i,pos:o}=t.mapping.mapResult(n);return i?null:o}},props:{decorations:KQe,handleDOMEvents:{mousedown:vHe},createSelectionBetween(t){return Js.getState(t.state)!=null?t.state.selection:null},handleTripleClick:AHe,handleKeyDown:mHe,handlePaste:gHe},appendTransaction(t,n,r){return zQe(r,Bte(r,n),e)}})}function DI(e,t){return t?["width",`${Math.max(t,e)}px`]:["min-width",`${e}px`]}function IU(e,t,n,r,i,o){var a;let s=0,l=!0,c=t.firstChild;const u=e.firstChild;if(u!==null)for(let f=0,p=0;f<u.childCount;f+=1){const{colspan:h,colwidth:m}=u.child(f).attrs;for(let g=0;g<h;g+=1,p+=1){const y=i===p?o:m&&m[g],b=y?`${y}px`:"";if(s+=y||r,y||(l=!1),c){if(c.style.width!==b){const[x,w]=DI(r,y);c.style.setProperty(x,w)}c=c.nextSibling}else{const x=document.createElement("col"),[w,v]=DI(r,y);x.style.setProperty(w,v),t.appendChild(x)}}}for(;c;){const f=c.nextSibling;(a=c.parentNode)===null||a===void 0||a.removeChild(c),c=f}l?(n.style.width=`${s}px`,n.style.minWidth=""):(n.style.width="",n.style.minWidth=`${s}px`)}let EHe=class{constructor(t,n){this.node=t,this.cellMinWidth=n,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")),IU(t,this.colgroup,this.table,n),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(t){return t.type!==this.node.type?!1:(this.node=t,IU(t,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(t){return t.type==="attributes"&&(t.target===this.table||this.colgroup.contains(t.target))}};function RHe(e,t,n,r){let i=0,o=!0;const a=[],s=e.firstChild;if(!s)return{};for(let f=0,p=0;f<s.childCount;f+=1){const{colspan:h,colwidth:m}=s.child(f).attrs;for(let g=0;g<h;g+=1,p+=1){const y=n===p?r:m&&m[g];i+=y||t,y||(o=!1);const[b,x]=DI(t,y);a.push(["col",{style:`${b}: ${x}`}])}}const l=o?`${i}px`:"",c=o?"":`${i}px`;return{colgroup:["colgroup",{},...a],tableWidth:l,tableMinWidth:c}}function _U(e,t){return t?e.createChecked(null,t):e.createAndFill()}function kHe(e){if(e.cached.tableNodeTypes)return e.cached.tableNodeTypes;const t={};return Object.keys(e.nodes).forEach(n=>{const r=e.nodes[n];r.spec.tableRole&&(t[r.spec.tableRole]=r)}),e.cached.tableNodeTypes=t,t}function $He(e,t,n,r,i){const o=kHe(e),a=[],s=[];for(let c=0;c<n;c+=1){const u=_U(o.cell,i);if(u&&s.push(u),r){const f=_U(o.header_cell,i);f&&a.push(f)}}const l=[];for(let c=0;c<t;c+=1)l.push(o.row.createChecked(null,r&&c===0?a:s));return o.table.createChecked(null,l)}function OHe(e){return e instanceof at}const Lv=({editor:e})=>{const{selection:t}=e.state;if(!OHe(t))return!1;let n=0;const r=nee(t.ranges[0].$from,o=>o.type.name==="table");return r==null||r.node.descendants(o=>{if(o.type.name==="table")return!1;["tableCell","tableHeader"].includes(o.type.name)&&(n+=1)}),n===t.ranges.length?(e.commands.deleteTable(),!0):!1},MHe=Cn.create({name:"table",addOptions(){return{HTMLAttributes:{},resizable:!1,handleWidth:5,cellMinWidth:25,View:EHe,lastColumnResizable:!0,allowTableNodeSelection:!1}},content:"tableRow+",tableRole:"table",isolating:!0,group:"block",parseHTML(){return[{tag:"table"}]},renderHTML({node:e,HTMLAttributes:t}){const{colgroup:n,tableWidth:r,tableMinWidth:i}=RHe(e,this.options.cellMinWidth);return["table",Nt(this.options.HTMLAttributes,t,{style:r?`width: ${r}`:`min-width: ${i}`}),n,["tbody",0]]},addCommands(){return{insertTable:({rows:e=3,cols:t=3,withHeaderRow:n=!0}={})=>({tr:r,dispatch:i,editor:o})=>{const a=$He(o.schema,e,t,n);if(i){const s=r.selection.from+1;r.replaceSelectionWith(a).scrollIntoView().setSelection(_e.near(r.doc.resolve(s)))}return!0},addColumnBefore:()=>({state:e,dispatch:t})=>YQe(e,t),addColumnAfter:()=>({state:e,dispatch:t})=>GQe(e,t),deleteColumn:()=>({state:e,dispatch:t})=>ZQe(e,t),addRowBefore:()=>({state:e,dispatch:t})=>eHe(e,t),addRowAfter:()=>({state:e,dispatch:t})=>tHe(e,t),deleteRow:()=>({state:e,dispatch:t})=>rHe(e,t),deleteTable:()=>({state:e,dispatch:t})=>uHe(e,t),mergeCells:()=>({state:e,dispatch:t})=>mU(e,t),splitCell:()=>({state:e,dispatch:t})=>AU(e,t),toggleHeaderColumn:()=>({state:e,dispatch:t})=>Km("column")(e,t),toggleHeaderRow:()=>({state:e,dispatch:t})=>Km("row")(e,t),toggleHeaderCell:()=>({state:e,dispatch:t})=>lHe(e,t),mergeOrSplit:()=>({state:e,dispatch:t})=>mU(e,t)?!0:AU(e,t),setCellAttribute:(e,t)=>({state:n,dispatch:r})=>aHe(e,t)(n,r),goToNextCell:()=>({state:e,dispatch:t})=>vU(1)(e,t),goToPreviousCell:()=>({state:e,dispatch:t})=>vU(-1)(e,t),fixTables:()=>({state:e,dispatch:t})=>(t&&Bte(e),!0),setCellSelection:e=>({tr:t,dispatch:n})=>{if(n){const r=at.create(t.doc,e.anchorCell,e.headCell);t.setSelection(r)}return!0}}},addKeyboardShortcuts(){return{Tab:()=>this.editor.commands.goToNextCell()?!0:this.editor.can().addRowAfter()?this.editor.chain().addRowAfter().goToNextCell().run():!1,"Shift-Tab":()=>this.editor.commands.goToPreviousCell(),Backspace:Lv,"Mod-Backspace":Lv,Delete:Lv,"Mod-Delete":Lv}},addProseMirrorPlugins(){return[...this.options.resizable&&this.editor.isEditable?[Wte({handleWidth:this.options.handleWidth,cellMinWidth:this.options.cellMinWidth,defaultCellMinWidth:this.options.cellMinWidth,View:this.options.View,lastColumnResizable:this.options.lastColumnResizable})]:[],qte({allowTableNodeSelection:this.options.allowTableNodeSelection})]},extendNodeSchema(e){const t={name:e.name,options:e.options,storage:e.storage};return{tableRole:Ne(de(e,"tableRole",t))}}});function FHe(e){return new cn({key:new En("tableCellFocus"),props:{decorations(t){const{doc:n,selection:r}=t,{isEditable:i,isFocused:o}=e;if(!i||!o||r instanceof at)return vt.create(n,[]);const a=[],{anchor:s}=r;return n.descendants((l,c)=>l.isText||!(s>=c&&s<=c+l.nodeSize-1)?!1:l.type.name==="tableCell"||l.type.name==="tableHeader"?(a.push(fn.node(c,c+l.nodeSize,{class:"focusedCell"})),!1):!0),vt.create(n,a)}}})}function Vte(e,t,n,r){switch(n.type){case"hyperlink":case"paragraph":case"strong":case"em":return Gr.converter.fromPrismic(e,t,r)(n);default:return}}function zte(e){const{title:t,className:n,onClick:r,tabIndex:i,onMouseDown:o,contentEditable:a,...s}=e,l=document.createElement("button");return l.className=n,l.setAttribute("type","button"),l.setAttribute("title",t),l.setAttribute("aria-label",t),l.setAttribute("tabIndex","0"),a!=null&&l.setAttribute("contentEditable",String(a)),o&&l.addEventListener("mousedown",c=>{const u=c.currentTarget;o(c,u)}),l.addEventListener("click",c=>{const u=c.currentTarget;r(c,u)}),Object.entries(s).forEach(([c,u])=>{l.setAttribute(c,u.toString())}),l}function Qte(e){const t=document.createElement("div");return t.innerHTML=e,t.firstChild?t.firstChild:null}class lo extends CustomEvent{constructor({name:t,detail:n}){super(t,{detail:n})}static dispatch(t,n){const{editor:r,...i}=n;r.view.dom.dispatchEvent(new lo({name:t,detail:i}))}static listen(t,n){const{editor:r,callback:i}=n,o=new AbortController;return r.view.dom.addEventListener(t,a=>{const{detail:s}=a;s&&i(s)},{signal:o.signal}),()=>o.abort()}}const jHe=50,DHe=25;function PS(e,t){const n=e.nodes[t];if(!n)throw new Error(`Unwanted state: ${t} not found in schema.`);return n}function uc(e){return md(t=>t.type.spec.tableRole&&t.type.spec.tableRole==="table")(e)}function Hte(e){return md(t=>t.type.name==="tableRow")(e)}function Yte(e){return md(t=>t.type.name==="tableCell"||t.type.name==="tableHeader")(e)}const LHe={cell:Yte,row:Hte,table:uc};function DD(e,...t){const n={};for(let r=0;r<t.length;r++){const i=t[r];i&&(n[i]=LHe[i](e))}return n}function Gte(e){var n;const t=(n=uc(e.state.selection))==null?void 0:n.node;return t&&t.firstChild&&t.type.name==="table"?t.firstChild.childCount:0}function Jte(e){var n;const t=(n=uc(e.state.selection))==null?void 0:n.node;return t&&t.type.name==="table"?t.childCount:0}function Vx(e){return Gte(e)>=DHe}function zx(e){return Jte(e)>=jHe}function LD(e,t){const{index:n,tr:r}=t,i=uc(r.selection);if(!i)return r;const o=Ct.get(i.node),a=e==="row";if(n<0||n>=(a?o.height:o.width))return r;const s=a?0:n,l=a?n:0,c=a?o.width:n+1,u=a?n+1:o.height,f=o.map[l*o.width+s],p=o.map[(u-1)*o.width+(c-1)];if(!f||!p)return r;const h=i.start+f,m=i.start+p,g=r.doc.resolve(h),y=r.doc.resolve(m);return r.setSelection(new at(y,g))}function PHe(e){return LD("row",e)}function BHe(e){return LD("column",e)}function UHe(e){const{direction:t,state:n}=e,{map:r,table:i,tableStart:o,top:a}=$r(n);if(t==="up"&&a===0||t==="down"&&a>=r.height-1)return;const{tr:s}=n,l=t==="up"?a-1:a+1;let c=o;for(let h=0;h<a;h++)c+=i.child(h).nodeSize;let u=o;for(let h=0;h<l;h++)u+=i.child(h).nodeSize;const f=i.child(a),p=i.child(l);switch(t){case"up":s.replaceWith(c,c+f.nodeSize,p),s.replaceWith(u,u+p.nodeSize,f);break;case"down":s.replaceWith(u,u+p.nodeSize,f),s.replaceWith(c,c+f.nodeSize,p);break}return{tr:s,index:l}}function NHe(e){const{direction:t,state:n}=e,{map:r,table:i,left:o}=$r(n);if(t==="left"&&o===0||t==="right"&&o>=r.width-1)return;const{tr:a}=n,s=t==="left"?o-1:o+1;for(let l=0;l<i.children.length;l++){const c=i.children[l];if(!c)return;const u=c.child(o),f=r.map[l*r.width+o];if(!f)return;const p=c.child(s),h=r.map[l*r.width+s];if(!h)return;switch(t){case"left":{a.replaceWith(f,f+u.nodeSize,p),a.replaceWith(h,h+p.nodeSize,u);break}case"right":{a.replaceWith(h,h+p.nodeSize,u),a.replaceWith(f,f+u.nodeSize,p);break}}}return{tr:a,index:s}}const Zte="data-prismic-table-handle";function WHe(e){return t=>{const n=uc(t);if(n){const r=Ct.get(n.node);return(Array.isArray(e)?e:Array.from([e])).reduce((o,a)=>{if(a>=0&&a<=r.width-1){const s=r.cellsInRect({left:a,right:a+1,top:0,bottom:r.height});return o.concat(s.flatMap(l=>{const c=n.node.nodeAt(l),u=l+n.start;return{pos:u,start:u+1,node:c}}))}return o},[])}return null}}function KHe(e){return t=>{const n=uc(t);if(n){const r=Ct.get(n.node);return(Array.isArray(e)?e:Array.from([e])).reduce((o,a)=>{if(a>=0&&a<=r.height-1){const s=r.cellsInRect({left:0,right:r.width,top:a,bottom:a+1});return o.concat(s.map(l=>{const c=n.node.nodeAt(l),u=l+n.start;return{pos:u,start:u+1,node:c}}))}return o},[])}return null}}function EU(e){const{element:t,type:n}=e,r=t.querySelector(`[${Zte}="${n}"]`);if(!r)throw new Error(`No ${n} handle found`);return r}function RU(e){const{type:t,editor:n,index:r}=e,i=zte({title:`Select ${t} & show options`,className:Lee(A.tableFieldStyles.tableHandle,A.tableFieldStyles[`table${Pt.capitalize(t)}Handle`]),[Zte]:t,"aria-expanded":!1,onMouseDown:a=>{a.preventDefault(),a.stopImmediatePropagation(),n.view.dispatch(LD(t,{index:r,tr:n.state.tr}))},onClick:(a,s)=>{a.preventDefault(),a.stopImmediatePropagation(),lo.dispatch("handleClick",{type:t,editor:n,referenceElement:s})}}),o=Qte(A.rawDragIndicatorIcon);return o&&i.appendChild(o),i}class qHe{constructor(t){Ve(this,"abortController",new AbortController);Ve(this,"currentRowHandle",null);Ve(this,"currentColumnHandle",null);Ve(this,"showCurrentHandles",t=>{try{const n=t.target,r=t.currentTarget;zHe(r),this.hidePreviousHandles();const i=kU("cell",n),o=this.getRowHandle(i),a=this.getColumnHandle(r,i);this.displayHandle(o),this.displayHandle(a),this.currentColumnHandle=a,this.currentRowHandle=o}catch{}});Ve(this,"hidePreviousHandles",()=>{this.currentRowHandle&&this.hideHandle(this.currentRowHandle),this.currentColumnHandle&&this.hideHandle(this.currentColumnHandle)});this.view=t,this.update(this.view)}update(t){this.attachEventListeners(t.dom)}destroy(){this.abortController.abort()}attachEventListeners(t){this.abortController.signal.aborted||this.abortController.abort(),this.abortController=new AbortController;const{signal:n}=this.abortController;t.querySelectorAll("table").forEach(r=>{r.addEventListener("mouseover",this.showCurrentHandles,{signal:n}),r.addEventListener("mouseleave",this.hidePreviousHandles,{signal:n})})}getRowHandle(t){const n=kU("row",t),r=EU({element:n,type:"row"});if(!r)throw new Error("No row handle found");return r}getColumnHandle(t,n){const r=n.cellIndex+1,i=t.querySelector(`tr > th:nth-child(${r}), tr > td:nth-child(${r})`);if(!i)throw new Error("No header cell found");const o=EU({element:i,type:"column"});if(!o)throw new Error("No column handle found");return o}displayHandle(t){t.classList.add(A.tableFieldStyles.tableHandleVisible)}hideHandle(t){t.classList.remove(A.tableFieldStyles.tableHandleVisible)}}const VHe={cell:["TD","TH"],row:["TR"]};function kU(e,t){const n=VHe[e];for(const r of n){const i=t.closest(r);if(i)return i}throw new Error(`Failed to find closest ${e}`)}function zHe(e){if(!e||e.tagName!=="TABLE")throw new Error("Element is not a table")}function QHe(e){return new cn({key:new En("tableCellHandles"),view:t=>new qHe(t),state:{init:(t,n)=>$U({editor:e,state:n}),apply:(t,n,r,i)=>t.docChanged?$U({editor:e,state:i}):n.map(t.mapping,t.doc)},props:{decorations(t){return this.getState(t)}}})}function $U(e){const{editor:t,state:n}=e,r=[],i=WHe(0)(n.selection);i&&i.forEach(({pos:a},s)=>{r.push(fn.widget(a+1,()=>RU({type:"row",editor:t,index:s})))});const o=KHe(0)(n.selection);return o&&o.forEach(({pos:a},s)=>{r.push(fn.widget(a+1,()=>RU({type:"column",editor:t,index:s})))}),vt.create(n.doc,r)}const HHe=Cn.create({name:"tableCell",addOptions(){return{HTMLAttributes:{}}},content:"block+",addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:e=>{const t=e.getAttribute("colwidth");return t?t.split(",").map(r=>parseInt(r,10)):null}}}},tableRole:"cell",isolating:!0,parseHTML(){return[{tag:"td"}]},renderHTML({HTMLAttributes:e}){return["td",Nt(this.options.HTMLAttributes,e),0]}}),PD=$.object({key:$.string().nullish(),colspan:$.number().nullish(),rowspan:$.number().nullish(),colwidth:$.array($.number()).nullish()}),Xte=HHe.extend({name:"tableCell",addAttributes(){var e;return{...(e=this.parent)==null?void 0:e.call(this),key:{default:null},"aria-label":{default:"Start typing to edit text"}}}}),OU={fromPrismic(e,t,n){return function(r){const i=PS(t,Xte.name),o=r.columnWidth?[r.columnWidth]:null;return i.create({colspan:1,rowspan:1,colwidth:o,key:r.key},r.content.value.flatMap(a=>Vte(e,t,a,n)??[]))}},toPrismic(e){const t=[];e.content.forEach(i=>{const o=Gr.converter.toPrismic(i);le.TextBlock.is(o)&&t.push(o)});const n=PD.parse(e.attrs),[r]=n.colwidth??[];return{key:n.key??crypto.randomUUID(),type:"tableCell",content:{__TYPE__:"StructuredTextContent",value:t},columnWidth:r}}},YHe=Cn.create({name:"tableHeader",addOptions(){return{HTMLAttributes:{}}},content:"block+",addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:e=>{const t=e.getAttribute("colwidth");return t?t.split(",").map(r=>parseInt(r,10)):null}}}},tableRole:"header_cell",isolating:!0,parseHTML(){return[{tag:"th"}]},renderHTML({HTMLAttributes:e}){return["th",Nt(this.options.HTMLAttributes,e),0]}}),ene=YHe.extend({name:"tableHeader",addAttributes(){var e;return{...(e=this.parent)==null?void 0:e.call(this),key:{default:null},"aria-label":{default:"Start typing to edit text"}}}}),MU={fromPrismic(e,t,n){return function(r){const i=PS(t,ene.name),o=r.columnWidth?[r.columnWidth]:null;return i.create({colspan:1,rowspan:1,colwidth:o,key:r.key},r.content.value.flatMap(a=>Vte(e,t,a,n)??[]))}},toPrismic(e){const t=[];e.content.forEach(i=>{const o=Gr.converter.toPrismic(i);le.TextBlock.is(o)&&t.push(o)});const n=PD.parse(e.attrs),[r]=n.colwidth??[];return{key:n.key??crypto.randomUUID(),type:"tableHeader",content:{__TYPE__:"StructuredTextContent",value:t},columnWidth:r}}},tne=Cn.create({name:"tableRow",addOptions(){return{HTMLAttributes:{}}},content:"(tableCell | tableHeader)*",tableRole:"row",parseHTML(){return[{tag:"tr"}]},renderHTML({HTMLAttributes:e}){return["tr",Nt(this.options.HTMLAttributes,e),0]}}),GHe=tne.extend({name:"tableRow",addAttributes(){var e;return{...(e=this.parent)==null?void 0:e.call(this),key:{default:null}}}}),FU={fromPrismic(e,t,n){return function(r){return PS(t,tne.name).create({key:r.key},r.content.map(o=>{switch(o.type){case"tableHeader":return MU.fromPrismic(e,t,n)(o);case"tableCell":return OU.fromPrismic(e,t,n)(o)}}))}},toPrismic(e){const t=PD.parse(e.attrs),n=[];return e.content.forEach(r=>{switch(r.type.name){case"tableHeader":{n.push(MU.toPrismic(r));break}case"tableCell":{n.push(OU.toPrismic(r));break}}}),{key:t.key??crypto.randomUUID(),type:"tableRow",content:n}}};class JHe extends Nte{constructor(n,r){const{node:i,editor:o}=n,{defaultCellMinWidth:a}=r;super(i,a);Ve(this,"tableWrapper");Ve(this,"selectionOverlay");this.tableWrapper=this.dom;const s=document.createElement("div");s.setAttribute("data-testid","table-container"),s.className=A.tableFieldStyles.tableWithControls;const l=document.createElement("div");l.classList.add(A.tableFieldStyles.tableShrinkContainer),this.selectionOverlay=new ZHe(o,this.table),this.dom.appendChild(this.selectionOverlay.view),n.editor.options.editable&&this.dom.appendChild(jU({editor:o,type:"column",onAfterCommand:()=>s.scrollLeft=s.scrollWidth})),l.appendChild(this.dom),s.appendChild(l),n.editor.options.editable&&l.appendChild(jU({editor:o,type:"row"})),this.dom=s}destroy(){this.selectionOverlay.destroy()}ignoreMutation(n){var i;const r=n.target;return r!==this.tableWrapper&&"closest"in r&&((i=r.closest)!=null&&i.call(r,".tableWrapper"))?!0:super.ignoreMutation(n)}}class ZHe{constructor(t,n){Ve(this,"view");Ve(this,"selectionAnchorCell",null);Ve(this,"selectionHeadCell",null);Ve(this,"onTransaction",t=>{const n=t.transaction.getMeta(Vr);n&&"setDragging"in n&&(t.editor.commands.focus(),this.onSelectionUpdate())});Ve(this,"onFocus",()=>{this.onSelectionUpdate()});Ve(this,"onBlur",()=>{this.selectionHeadCell===this.selectionAnchorCell&&this.clearSelectionOverlay()});Ve(this,"onSelectionUpdate",()=>{const{selection:t}=this.editor.state;let n=null,r=null;if(t instanceof _e){const i=Yte(t);n=r=Qx(this.editor.view,i==null?void 0:i.pos)}else t instanceof at?(n=Qx(this.editor.view,t.$headCell.pos),r=Qx(this.editor.view,t.$anchorCell.pos)):this.clearSelectionOverlay();!r||!n||(this.selectionAnchorCell=r,this.selectionHeadCell=n,this.renderSelectionOverlay())});Ve(this,"tableHeightObserver",null);Ve(this,"tableMinWidthObserver",null);Ve(this,"previousTableHeight",null);this.editor=t,this.table=n;const r=document.createElement("div");r.setAttribute("contentEditable","false"),r.classList.add(A.tableFieldStyles.tableSelectionOverlay),r.setAttribute("aria-label","Table selection overlay"),this.view=r,t.on("transaction",this.onTransaction),t.on("focus",this.onFocus),t.on("blur",this.onBlur),t.on("selectionUpdate",this.onSelectionUpdate),this.connectTableSizeObservers()}destroy(){this.editor.off("transaction",this.onTransaction),this.editor.off("focus",this.onFocus),this.editor.off("blur",this.onBlur),this.editor.off("selectionUpdate",this.onSelectionUpdate),this.clearSelectionOverlay(),this.disconnectTableSizeObservers()}clearSelectionOverlay(){const{style:t}=this.view;t.width="0px",t.height="0px",requestAnimationFrame(()=>{t.display="none"}),this.selectionAnchorCell=null,this.selectionHeadCell=null}renderSelectionOverlay(){if(!this.selectionAnchorCell||!this.selectionHeadCell)return;const t=this.selectionAnchorCell.getBoundingClientRect(),n=this.selectionHeadCell.getBoundingClientRect(),r=this.table.getBoundingClientRect(),i=Math.min(t.left,n.left)-r.left,o=Math.min(t.top,n.top)-r.top,a=Math.max(t.right,n.right)-r.left,s=Math.max(t.bottom,n.bottom)-r.top,l=$r(this.editor.state),c=XHe(l),{style:u}=this.view;u.left=`${i}px`,u.top=`${o}px`,u.width=`${a-i+c.width}px`,u.height=`${s-o+c.height}px`,u.borderRadius=eYe(l),requestAnimationFrame(()=>{u.display="block"})}connectTableSizeObservers(){this.disconnectTableSizeObservers(),this.tableHeightObserver??(this.tableHeightObserver=new ResizeObserver(t=>{for(const n of t){const r=n.contentRect.height;r!==this.previousTableHeight&&(this.renderSelectionOverlay(),this.previousTableHeight=r)}})),this.tableMinWidthObserver??(this.tableMinWidthObserver=new MutationObserver(()=>{this.renderSelectionOverlay()})),this.tableHeightObserver.observe(this.table),this.tableMinWidthObserver.observe(this.table,{attributes:!0,attributeFilter:["style"]})}disconnectTableSizeObservers(){var t,n;(t=this.tableHeightObserver)==null||t.disconnect(),(n=this.tableMinWidthObserver)==null||n.disconnect()}}function Qx(e,t){if(!t)return null;const n=e.nodeDOM(t);return n instanceof HTMLElement?n:null}function XHe(e){let{width:t,height:n}={width:1,height:1};return e.right===e.map.width&&(t=0),e.bottom===e.map.height&&(n=0),{width:t,height:n}}function eYe(e){let{tl:t,tr:n,br:r,bl:i}={tl:2,tr:2,br:2,bl:2};return e.top===0&&(e.left===0&&(t=6),e.right===e.map.width&&(n=6)),e.bottom===e.map.height&&(e.right===e.map.width&&(i=6),e.left===0&&(r=6)),`${t}px ${n}px ${i}px ${r}px`}function jU(e){const{type:t,editor:n,onAfterCommand:r}=e,i=Pt.capitalize(t),o=zte({title:`Add ${t}`,className:A.tableFieldStyles[`addTable${i}Button`],contentEditable:!1,onClick:()=>{n.commands[`add${i}ToEnd`](),r==null||r()}}),a=Qte(A.rawAddIcon);return a&&o.appendChild(a),o}const p0=MHe.extend({name:"table",selectable:!1,addOptions(){var e;return{...(e=this.parent)==null?void 0:e.call(this),resizable:!0,defaultCellMinWidth:120,View:null}},addCommands(){var e;return{...(e=this.parent)==null?void 0:e.call(this),addRowAfter:()=>t=>{var r,i,o;const{editor:n}=t;return zx(n)?(lo.dispatch("addAtLimit",{editor:n,type:"row"}),!1):((o=(r=this.parent)==null?void 0:(i=r.call(this)).addRowAfter)==null?void 0:o.call(i)(t))??!1},addRowBefore:()=>t=>{var r,i,o;const{editor:n}=t;return zx(n)?(lo.dispatch("addAtLimit",{editor:n,type:"row"}),!1):((o=(r=this.parent)==null?void 0:(i=r.call(this)).addRowBefore)==null?void 0:o.call(i)(t))??!1},addRowToEnd:()=>({dispatch:t,state:n,editor:r})=>{if(!Tr(n))return!1;if(zx(r))return lo.dispatch("addAtLimit",{editor:r,type:"row"}),!1;if(t){const i=$r(n),o=i.map.height;t(jD(n.tr,i,o))}return!0},addColumnAfter:()=>t=>{var r,i,o;const{editor:n}=t;return Vx(n)?(lo.dispatch("addAtLimit",{editor:n,type:"column"}),!1):((o=(r=this.parent)==null?void 0:(i=r.call(this)).addColumnAfter)==null?void 0:o.call(i)(t))??!1},addColumnBefore:()=>t=>{var r,i,o;const{editor:n}=t;return Vx(n)?(lo.dispatch("addAtLimit",{editor:n,type:"column"}),!1):((o=(r=this.parent)==null?void 0:(i=r.call(this)).addColumnBefore)==null?void 0:o.call(i)(t))??!1},addColumnToEnd:()=>({dispatch:t,state:n,editor:r})=>{if(!Tr(n))return!1;if(Vx(r))return lo.dispatch("addAtLimit",{editor:r,type:"column"}),!1;if(t){const i=$r(n),o=i.map.width;t(FD(n.tr,i,o))}return!0},moveRow:t=>({dispatch:n,state:r})=>{if(!Tr(r))return!1;if(n){tYe();const i=UHe({direction:t,state:r});if(!i)return!1;const o=PHe(i);n(o)}return!0},moveColumn:t=>({dispatch:n,state:r})=>{if(!Tr(r))return!1;if(n){const i=NHe({direction:t,state:r});if(!i)return!1;const o=BHe(i);n(o)}return!0}}},addNodeView(){return e=>new JHe(e,this.options)},addKeyboardShortcuts(){var e;return{...(e=this.parent)==null?void 0:e.call(this),Backspace:()=>!1,"Mod-Backspace":()=>!1,Delete:()=>!1,"Mod-Delete":()=>!1}},addProseMirrorPlugins(){return[...this.options.resizable&&this.editor.isEditable?[Wte(this.options)]:[],qte(this.options),QHe(this.editor),FHe(this.editor),nYe()]}});function tYe(){if(!window.getSelection)return;const e=window.getSelection();e!=null&&e.empty?e.empty():e!=null&&e.removeAllRanges&&e.removeAllRanges()}function nYe(){return new cn({filterTransaction(e,t){if(tGe(e))return!0;for(const n of e.steps){const r=n.toJSON();if(r.stepType!=="replace")continue;const i=rYe(t,r.from);if(i&&(i.type.name===p0.name||r.from+r.to===t.doc.content.size))return!1}return!0}})}function rYe(e,t){try{return e.doc.nodeAt(t)}catch{return null}}const iYe={fromPrismic(e,t,n){return function(r){return PS(t,p0.name).create({},r.content.map(o=>FU.fromPrismic(e,t,n)(o)))}},toPrismic(e){var n;const t=((n=e.content.firstChild)==null?void 0:n.type.name)===p0.name?e.content.firstChild:e;return{type:"table",content:Tl.children.map(t,r=>FU.toPrismic(r))}}},oYe=new oVe([Nc.table],Nc.table,[p0,GHe,ene,Xte],iYe),nne=[wD,RD,Ste],rne=[...nne,kD];function ine(e){return Y7e(e)?[...nne,Gr,oYe].filter(Ui.isDefined):[Gr,u0,f0,bc.build(e),cte,dte,gte,...rne].filter(Ui.isDefined)}const one=[{nodeType:he.RichTextNodeType.paragraph,icon:"textFields",isActive:e=>e.isActive(Gr.name)&&!e.isActive(u0.name)&&!e.isActive(f0.name),runCommands:qt((e,t)=>e.clearNodes().setDirection(ao(t))),shortText:"par",text:"Paragraph"},{nodeType:he.RichTextNodeType.heading1,icon:"looks1",isActive:e=>e.isActive(bc.name,{level:1}),runCommands:qt((e,t)=>e.setHeading({level:1}).setDirection(ao(t))),shortText:"h1",text:"Heading 1"},{nodeType:he.RichTextNodeType.heading2,icon:"looks2",isActive:e=>e.isActive(bc.name,{level:2}),runCommands:qt((e,t)=>e.setHeading({level:2}).setDirection(ao(t))),shortText:"h2",text:"Heading 2"},{nodeType:he.RichTextNodeType.heading3,icon:"looks3",isActive:e=>e.isActive(bc.name,{level:3}),runCommands:qt((e,t)=>e.setHeading({level:3}).setDirection(ao(t))),shortText:"h3",text:"Heading 3"},{nodeType:he.RichTextNodeType.heading4,icon:"looks4",isActive:e=>e.isActive(bc.name,{level:4}),runCommands:qt((e,t)=>e.setHeading({level:4}).setDirection(ao(t))),shortText:"h4",text:"Heading 4"},{nodeType:he.RichTextNodeType.heading5,icon:"looks5",isActive:e=>e.isActive(bc.name,{level:5}),runCommands:qt((e,t)=>e.setHeading({level:5}).setDirection(ao(t))),shortText:"h5",text:"Heading 5"},{nodeType:he.RichTextNodeType.heading6,icon:"looks6",isActive:e=>e.isActive(bc.name,{level:6}),runCommands:qt((e,t)=>e.setHeading({level:6}).setDirection(ao(t))),shortText:"h6",text:"Heading 6"},{nodeType:he.RichTextNodeType.list,icon:"formatListBulleted",isActive:e=>e.isActive(u0.name),runCommands:qt((e,t)=>e.toggleBulletList().setDirection(ao(t))),shortText:"bull",text:"Bulleted list"},{nodeType:he.RichTextNodeType.orderedList,icon:"formatListNumbered",isActive:e=>e.isActive(f0.name),runCommands:qt((e,t)=>e.toggleOrderedList().setDirection(ao(t))),shortText:"num",text:"Numbered list"},{nodeType:he.RichTextNodeType.preformatted,icon:"dataObject",isActive:e=>e.isActive(cte.name),runCommands:qt((e,t)=>e.setCodeBlock().setDirection(ao(t))),shortText:"code",text:"Code"},{nodeType:he.RichTextNodeType.embed,icon:"cloud",isActive:e=>e.isActive(dte.name),runCommands:qt(e=>e.setEmbed()),shortText:"emb",text:"Embed"},{nodeType:he.RichTextNodeType.image,icon:"image",isActive:e=>e.isActive(gte.name),runCommands:qt(e=>e.setImage()),shortText:"img",text:"Image"}],aYe=[{nodeType:he.RichTextNodeType.strong,icon:"formatBold",isActive:e=>e.isActive(wD.name),runCommands:qt(e=>e.toggleBold())},{nodeType:he.RichTextNodeType.em,icon:"formatItalic",isActive:e=>e.isActive(RD.name),runCommands:qt(e=>e.toggleItalic())}],sYe=[{nodeType:he.RichTextNodeType.rtl,icon:"formatTextDirectionRToL",isActive:e=>e.isActive({[Ba]:Oc}),runCommands:qt((e,t)=>e.toggleDirection(ao(t)))}];function qt(e){return(t,n={})=>{let r=n.can===!0?t.can().chain():t.chain().focus();return n.deleteRange!==void 0&&(r=r.deleteRange(n.deleteRange)),n.can?lYe(t,r,e):e(r,t).run()}}function ao(e){const t=e.state.selection.$from.parent.attrs;return Za.parseNodeAttrsDirection(t)}function ly(e,t){return e.filter(n=>t.includes(n.nodeType))}function lYe(e,t,n){try{return n(t,e).run()}catch{return!1}}function cYe(e){const{items:t,editor:n}=e;return t.length===0?null:d.jsxs(d.Fragment,{children:[t.map(r=>d.jsx(A.ToolbarToggleButton,{disabled:!r.runCommands(n,{can:!0}),onPressedChange:()=>{r.runCommands(n)},pressed:r.isActive(n),startIcon:r.icon},r.nodeType)),d.jsx(A.ToolbarSeparator,{})]})}function uYe(e){const{labels:t,editor:n}=e,r=n.getAttributes("label").label;return d.jsxs(d.Fragment,{children:[d.jsxs(A.DropdownMenu,{children:[d.jsx(A.DropdownMenuTrigger,{disabled:t.length===0,children:d.jsx(A.Button,{endIcon:"arrowDropDown",size:"small",color:"grey",children:DU(r??"Labels")})}),d.jsx(A.DropdownMenuContent,{align:"start",asPortal:!1,maxHeight:256,avoidCollisions:!1,children:t.map((i,o)=>{const a=r===i;return d.jsx(A.DropdownMenuItem,{onSelect:()=>a?n.commands.unsetLabel():dYe(n,i),endIcon:a&&d.jsx(A.Icon,{name:"check",size:"extraSmall"}),children:DU(i)},`${i}-${o}`)})})]}),d.jsx(A.ToolbarSeparator,{})]})}function dYe(e,t){qt(r=>r.setLabel({label:t}))(e)}function DU(e){return Pt.overflow(e,20)}function fYe(e){const{editor:t}=e,n=t.getAttributes("label");if(!n.label)return null;const r=n.label;return d.jsx(A.Box,{backgroundColor:"purple9",padding:{block:2,inline:4},alignItems:"center",borderRadius:{topLeft:2,topRight:2,bottomRight:2},maxWidth:125,children:d.jsx(A.Text,{color:"white",variant:"small",noWrap:!0,children:r})})}function pYe(e){const{disabled:t,showWebLinkModal:n,showDocumentsLinkModal:r,showMediaLinkModal:i}=hYe(e);return d.jsxs(d.Fragment,{children:[d.jsxs(A.ToolbarButtonGroup,{density:"compact",children:[d.jsx(A.ToolbarButton,{disabled:t,startIcon:"link",onClick:n},he.RichTextNodeType.hyperlink),d.jsxs(A.DropdownMenu,{children:[d.jsx(A.DropdownMenuTrigger,{children:d.jsx(A.ToolbarButton,{startIcon:"arrowDropDown"})}),d.jsxs(A.DropdownMenuContent,{align:"end",asPortal:!1,children:[d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"public"}),onSelect:n,children:"Link to web page"}),d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"description"}),onSelect:r,children:"Link to document"}),d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"image"}),onSelect:i,children:"Link to media"})]})]})]}),d.jsx(A.ToolbarSeparator,{})]})}function hYe(e){const{editor:t,setModal:n}=e;function r(){n("webLink")}function i(){n("documentLink")}function o(){n("mediaLink")}return{disabled:!qt(s=>s.setWebLink({href:""}))(t,{can:!0}),showWebLinkModal:r,showDocumentsLinkModal:i,showMediaLinkModal:o}}function mYe(e){const{docId:t,onEdit:n,onUnlink:r}=e,i=AYe(t),o=ye();if(!i)return null;const a=i.versions[0],s=ND({status:a==null?void 0:a.status,releaseId:(a==null?void 0:a.status)==="release"?a.release_id:void 0,documentId:i.id,versionId:a==null?void 0:a.version_id,baseUrl:o.baseUrl}),l=(a==null?void 0:a.preview_summary)??"",c=(a==null?void 0:a.custom_type_label)??"";return d.jsx(ru,{url:s,title:i.title,subTitle:c,description:l,onEdit:n,onUnlink:r,largeIconName:"description"})}function AYe(e){const t=ye();t.searchDocuments||Rt("searchDocuments");const{coreApiBaseUrl:n,authStrategy:r}=t;return it.useRequest(qg,[n,r,e])}function gYe(e){const{editor:t}=e,{searchDocuments:n}=ye(),r=t.getAttributes(he.RichTextNodeType.hyperlink);if(r.id&&n){const i=r.id;return d.jsx(vYe,{docId:i,...e})}if(r.href){const i=r.href;return d.jsx(yYe,{url:i,...e})}if(r.media){const i=wte(r.media);return d.jsx(bYe,{media:i,...e})}return null}function vYe(e){const{editor:t,onEditDocumentLink:n,docId:r}=e;return d.jsx(A.ErrorBoundary,{renderError:()=>d.jsx(ru,{title:"Failed to Load Linked Document Data",error:!0,onEdit:n,onUnlink:()=>Kc(t)}),children:d.jsx(R.Suspense,{fallback:d.jsx(ru,{loading:!0,onEdit:n,onUnlink:()=>Kc(t)}),children:d.jsx(mYe,{docId:r,onEdit:n,onUnlink:()=>Kc(t)})})})}function yYe(e){const{url:t,editor:n,onEditWebLink:r}=e,i=bi.toURL(t);return i?d.jsx(ru,{url:t,title:bi.getUrlTitle(i),subTitle:t,onEdit:r,onUnlink:()=>Kc(n)}):d.jsx(ru,{url:t,subTitle:t,onEdit:r,onUnlink:()=>Kc(n)})}function bYe(e){const{media:t,editor:n,onEditMediaLink:r}=e;return le.FilledImageLinkContent.is(t)?d.jsx(zJ,{url:t.url,title:t.name,subTitle:`${t.width} x ${t.height} pixels`,onEdit:r,onUnlink:()=>Kc(n)}):le.FilledFileLinkContent.is(t)?d.jsx(ru,{url:t.url,title:t.name,subTitle:CYe({filename:t.name}),largeIconName:"insertDriveFile",onEdit:r,onUnlink:()=>Kc(n)}):null}function Kc(e){qt(n=>n.unsetLink())(e)}function CYe(e){const{filename:t}=e,n=t.split(".").pop();return n?n.toLowerCase():""}function SYe(e){const{open:t}=e,{onOpenChange:n,onSelectDocument:r}=wYe(e);return d.jsx(WJ,{open:t,onOpenChange:n,onSelectDocument:r})}function wYe(e){const{editor:t,setOpen:n}=e;function r(o){qt(s=>s.extendMarkRange(he.RichTextNodeType.hyperlink).setDocumentLink({id:o}))(t),n(!1)}function i(o){n(o)}return{onSelectDocument:r,onOpenChange:i}}function xYe(e){const{open:t}=e,{onOpenChange:n,onMediaSelected:r}=TYe(e);return d.jsx(Uj,{open:t,onOpenChange:n,onMediaSelected:r,assetType:"all"})}function TYe(e){const{editor:t,setOpen:n}=e;function r(i){qt(a=>a.extendMarkRange(he.RichTextNodeType.hyperlink).setMediaLink({media:i}))(t),n(!1)}return{onMediaSelected:r,onOpenChange:n}}function IYe(e){const{open:t,setOpen:n}=e,{url:r,setUrl:i,openInNewTab:o,setOpenInNewTab:a,disabled:s,onUpdate:l}=_Ye(e);return d.jsxs(A.Dialog,{open:t,onOpenChange:n,size:"small",noDescription:!0,children:[d.jsx(A.DialogHeader,{title:"Set Link URL"}),d.jsxs(A.DialogContent,{padding:16,children:[d.jsx(A.FormInput,{value:r,onValueChange:i,placeholder:"Paste URL",icon:"public"}),r&&d.jsx(A.InlineLabel,{value:"Open in new tab",children:d.jsx(A.Checkbox,{checked:o,onCheckedChange:a})})]}),d.jsxs(A.DialogActions,{children:[d.jsx(A.DialogCancelButton,{}),d.jsx(A.DialogActionButton,{onClick:l,disabled:s,children:"Update"})]})]})}function _Ye(e){const{editor:t,open:n,setOpen:r}=e,i=EYe(t),[o,a]=R.useState(i.url),[s,l]=R.useState(i.openInNewTab);Ke.useOnChange(n,()=>{n&&(a(i.url),l(i.openInNewTab))});const c=!o||o===i.url&&s===i.openInNewTab;function u(){const f=s?"_blank":"_self";qt(p=>p.extendMarkRange(he.RichTextNodeType.hyperlink).setWebLink({href:o,target:f}))(t),r(!1)}return{url:o,setUrl:a,openInNewTab:s,disabled:c,setOpenInNewTab:l,onUpdate:u}}function EYe(e){const t=e.getAttributes(he.RichTextNodeType.hyperlink);return{url:t.href??"",openInNewTab:t.target==="_blank"}}function RYe(e){const{items:t,editor:n}=e;return t.length===0?null:d.jsxs(d.Fragment,{children:[d.jsx(A.ToolbarToggleButtonGroup,{onValueChange:r=>{t.forEach(i=>{(i.isActive(n)&&!r.includes(i.nodeType)||!i.isActive(n)&&r.includes(i.nodeType))&&i.runCommands(n)})},type:"multiple",value:t.filter(r=>r.isActive(n)).map(r=>r.nodeType),children:t.map(r=>d.jsx(A.ToolbarToggleButtonGroupItem,{disabled:!r.runCommands(n,{can:!0}),startIcon:r.icon,value:r.nodeType},r.nodeType))},"mark"),d.jsx(A.ToolbarSeparator,{})]})}function kYe(e){var r;const{items:t,editor:n}=e;return t.length===0?null:d.jsxs(d.Fragment,{children:[d.jsxs(A.DropdownMenu,{children:[d.jsx(A.DropdownMenuTrigger,{disabled:t.length===1,children:d.jsx(A.Button,{endIcon:"arrowDropDown",size:"small",color:"grey",children:((r=t.find(i=>i.isActive(n)))==null?void 0:r.text)??""})}),d.jsx(A.DropdownMenuContent,{align:"start",asPortal:!1,maxHeight:256,avoidCollisions:!1,children:t.map(i=>d.jsx(A.DropdownMenuItem,{onSelect:()=>{i.runCommands(n)},children:i.text},i.nodeType))})]}),d.jsx(A.ToolbarSeparator,{})]})}function Hx(e){return{duration:100,hideOnClick:!0,offset:e,placement:"top-start",appendTo:document.querySelector("body > div")??"parent"}}function $Ye(e){const{editor:t,nodeTypes:n,labels:r,hideDisabledOptions:i=!1}=e,[o,a]=R.useState(),s=n.includes(he.RichTextNodeType.hyperlink),l=!o,{shouldShowBubbleMenu:c,shouldShowPopover:u}=MYe({editor:t}),[f,p]=R.useState(!0);R.useEffect(()=>{p(!1)},[]);function h(y){a(y?"webLink":void 0)}function m(y){a(y?"documentLink":void 0)}function g(y){a(y?"mediaLink":void 0)}return f?null:d.jsxs(d.Fragment,{children:[d.jsx($x,{editor:t,tippyOptions:Hx([-48,0]),shouldShow:c,children:l&&d.jsx(OYe,{editor:t,nodeTypes:n,labels:r,setModal:a,hideDisabledOptions:i})}),d.jsx($x,{editor:t,tippyOptions:Hx([-48,0]),shouldShow:y=>u(y,"hyperlink"),children:l&&d.jsx(gYe,{editor:t,onEditWebLink:()=>a("webLink"),onEditDocumentLink:()=>a("documentLink"),onEditMediaLink:()=>a("mediaLink")})}),d.jsx($x,{editor:t,tippyOptions:Hx([0,0]),shouldShow:y=>u(y,"label"),children:d.jsx(fYe,{editor:t})}),s&&d.jsxs(d.Fragment,{children:[d.jsx(IYe,{open:o==="webLink",setOpen:h,editor:t}),d.jsx(SYe,{open:o==="documentLink",setOpen:m,editor:t}),d.jsx(xYe,{open:o==="mediaLink",setOpen:g,editor:t})]})]})}function OYe(e){const{editor:t,nodeTypes:n,labels:r,setModal:i,hideDisabledOptions:o}=e,a=n.includes("hyperlink"),s=r.length>0,l=ly(one,n),c=ly(aYe,n),u=ly(sYe,n),f=o&&l.length===1?0:l.length;return Number(a)+Number(s)+f+c.length+u.length===0?null:d.jsxs(A.Toolbar,{children:[f>0&&d.jsx(kYe,{items:l,editor:t}),s&&d.jsx(uYe,{labels:r,editor:t}),d.jsx(RYe,{items:c,editor:t}),a&&d.jsx(pYe,{editor:t,setModal:i}),d.jsx(cYe,{items:u,editor:t}),d.jsx(A.ToolbarButton,{onClick:()=>{t.chain().focus().clearNodes().unsetAllMarks().run()},startIcon:"formatClear"},"clear")]})}function MYe(e){const{editor:t}=e;function n(i){const{view:o,state:a,from:s,to:l}=i;if(!o.hasFocus())return!1;const{doc:c,selection:u}=a;return!(t.isActive(he.RichTextNodeType.preformatted)||u.empty||c.textBetween(s,l).length===0)}function r(i,o){const{view:a,state:s,from:l,to:c}=i,u=a.state.doc.nodeAt(l),{doc:f,selection:p}=s;return!p.empty||f.textBetween(l,c).length>0?!1:!!(u!=null&&u.marks.some(m=>m.type.name===o))}return{shouldShowBubbleMenu:n,shouldShowPopover:r}}const FYe=["id","data-state","aria-expanded","aria-controls","aria-haspopup"],ane=R.forwardRef(function(t,n){const{targetTriggerElementRef:r,style:i,...o}=t;return R.useEffect(()=>{if(r.current)for(const[a,s]of Object.entries(o))jYe(a,s)&&DYe(r.current,a,s)},[o,r]),d.jsx("div",{ref:n,style:i})});function jYe(e,t){return FYe.includes(e)?typeof t=="boolean"||typeof t=="number"||typeof t=="string":!1}function DYe(e,t,n){n!=null&&n!==""?e.setAttribute(t,n.toString()):e.removeAttribute(t)}function LYe(e){const{table:t,row:n}=DD(e.state.selection,"table","row");return!t||!n?{isFirstRow:!1,isLastRow:!1}:{isFirstRow:t.node.firstChild===n.node,isLastRow:t.node.lastChild===n.node}}function PYe(e){const{table:t,row:n}=DD(e.state.selection,"table","row");return!t||!n?!1:t.node.child(1)===n.node}const sne=e=>{var r;const t=(r=uc(e.state.selection))==null?void 0:r.node;if(!t||t.type.name!=="table")return!1;const n=t.firstChild;if(!n||n.type.name!=="tableRow")return!1;for(let i=0;i<n.childCount;i++){const o=n.child(i);if((o==null?void 0:o.type.name)!=="tableHeader")return!1}return!0},BYe=e=>Jte(e)===1;function UYe(e){const{table:t,cell:n}=DD(e.state.selection,"table","cell");return!t||!n?!1:t.node.child(0).child(1)===n.node}function NYe(e){var r;const t=(r=Hte(e.state.selection))==null?void 0:r.node,n=e.state.selection.$from.index(-1);return t?{isFirstColumn:n===0,isLastColumn:n===t.childCount-1}:{isFirstColumn:!1,isLastColumn:!1}}const lne=e=>{var n;const t=(n=uc(e.state.selection))==null?void 0:n.node;if(!t||t.type.name!=="table")return!1;for(let r=0;r<t.childCount;r++){const o=t.child(r).firstChild;if((o==null?void 0:o.type.name)!=="tableHeader")return!1}return!0},WYe=e=>Gte(e)===1;function KYe(e){const{editor:t,open:n,onOpenChange:r,floatingStyle:i,triggerRef:o,targetTriggerElementRef:a}=e,s=lne(t),l=WYe(t),c=NYe(t);function u(y){const b=sne(t);t.commands.deleteColumn(),r(!1),l&&s&&(f(y),b||t.commands.toggleHeaderRow())}function f(y){y.preventDefault(),t.commands.toggleHeaderColumn()}function p(){s&&c.isFirstColumn?t.chain().toggleHeaderColumn().addColumnBefore().toggleHeaderColumn().run():t.commands.addColumnBefore(),r(!1)}function h(){t.commands.addColumnAfter(),r(!1)}function m(){const y=s&&UYe(t),b=t.chain();y?b.toggleHeaderColumn().moveColumn("left").toggleHeaderColumn():b.moveColumn("left"),b.run(),r(!1)}function g(){const y=s&&c.isFirstColumn,b=t.chain();y?b.toggleHeaderColumn().moveColumn("right").toggleHeaderColumn():b.moveColumn("right"),b.run(),r(!1)}return d.jsxs(A.DropdownMenu,{open:n,onOpenChange:r,modal:!0,children:[d.jsx(A.DropdownMenuTrigger,{children:d.jsx(ane,{ref:o,targetTriggerElementRef:a,style:i})}),d.jsxs(A.DropdownMenuContent,{align:"start",side:"bottom",sideOffset:4,children:[d.jsx(A.DropdownMenuLabel,{children:d.jsx(A.Text,{color:"grey11",variant:"small",children:"Column options"})}),c.isFirstColumn&&d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"viewDay"}),onSelect:f,disabled:l,children:d.jsxs(A.Box,{gap:12,alignItems:"center",children:["Header Column",d.jsx(A.Switch,{size:"extraSmall",checked:s})]})}),d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"arrowBack"}),onSelect:p,children:"Insert Left"}),d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"arrowForward"}),onSelect:h,children:"Insert Right"}),d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"moveLeft"}),onSelect:m,disabled:c.isFirstColumn,children:"Move Left"}),d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"moveRight"}),onSelect:g,disabled:c.isLastColumn,children:"Move Right"}),d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"delete"}),onSelect:u,disabled:l,children:"Delete Column"})]})]})}function qYe(e){const{editor:t,open:n,onOpenChange:r,floatingStyle:i,triggerRef:o,targetTriggerElementRef:a}=e,s=sne(t),l=BYe(t),c=LYe(t);function u(y){const b=lne(t);t.commands.deleteRow(),r(!1),l&&s&&(f(y),b||t.commands.toggleHeaderColumn())}function f(y){y.preventDefault(),t.commands.toggleHeaderRow()}function p(){s&&c.isFirstRow?t.chain().toggleHeaderRow().addRowBefore().toggleHeaderRow().run():t.commands.addRowBefore(),r(!1)}function h(){t.commands.addRowAfter(),r(!1)}function m(){const y=s&&PYe(t),b=t.chain();y?b.toggleHeaderRow().moveRow("up").toggleHeaderRow():b.moveRow("up"),b.run(),r(!1)}function g(){const y=s&&c.isFirstRow,b=t.chain();y?b.toggleHeaderRow().moveRow("down").toggleHeaderRow():b.moveRow("down"),b.run(),r(!1)}return d.jsxs(A.DropdownMenu,{open:n,onOpenChange:r,modal:!0,children:[d.jsx(A.DropdownMenuTrigger,{children:d.jsx(ane,{ref:o,targetTriggerElementRef:a,style:i})}),d.jsxs(A.DropdownMenuContent,{align:"start",side:"right",sideOffset:4,children:[d.jsx(A.DropdownMenuLabel,{children:d.jsx(A.Text,{color:"grey11",variant:"small",children:"Row options"})}),c.isFirstRow&&d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"viewDay"}),onSelect:f,disabled:l,children:d.jsxs(A.Box,{gap:12,alignItems:"center",children:[d.jsx(A.Text,{noWrap:!0,children:"Header row"}),d.jsx(A.Switch,{size:"extraSmall",checked:s})]})}),d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"arrowUpward"}),onSelect:p,children:"Insert Above"}),d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"arrowDownward"}),onSelect:h,children:"Insert Below"}),d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"moveUp"}),onSelect:m,disabled:c.isFirstRow,children:"Move Up"}),d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"moveDown"}),onSelect:g,disabled:c.isLastRow,children:"Move Down"}),d.jsx(A.DropdownMenuItem,{startIcon:d.jsx(A.Icon,{name:"delete"}),onSelect:u,disabled:l,children:"Delete Row"})]})]})}function VYe(e){return d.jsxs(d.Fragment,{children:[d.jsx(zYe,{...e}),d.jsx(QYe,{...e})]})}function zYe(e){const{editor:t}=e,{triggerElementRef:n,open:r,onOpenChange:i,floatingStyle:o,floatingRef:a}=cne("row",t);return d.jsx(qYe,{open:r,editor:t,triggerRef:a,targetTriggerElementRef:n,onOpenChange:i,floatingStyle:o})}function QYe(e){const{editor:t}=e,{triggerElementRef:n,open:r,onOpenChange:i,floatingStyle:o,floatingRef:a}=cne("column",t);return d.jsx(KYe,{open:r,editor:t,triggerRef:a,targetTriggerElementRef:n,onOpenChange:i,floatingStyle:o})}function cne(e,t){const n=R.useRef(),[r,i]=R.useState(!1),{strategy:o,floating:a,reference:s,x:l,y:c}=ate({open:r,onOpenChange:i,placement:e==="column"?"bottom-start":"right-start",strategy:"fixed"});return R.useEffect(()=>lo.listen("handleClick",{editor:t,callback:u=>{u.type===e&&(s(u.referenceElement),n.current=u.referenceElement,i(!0))}}),[t,s,e]),{open:r,onOpenChange:i,triggerElementRef:n,floatingRef:a,floatingStyle:{top:c??"",left:l??"",position:o,display:r?"flex":"none"}}}function HYe(e){const{editor:t}=e,{open:n,onOpenChange:r}=YYe(t);return d.jsx(A.Toast,{title:"You've reached the limit (50 rows / 25 columns).",action:{title:"Need more?",onClick:()=>window.open("https://community.prismic.io/t/how-should-the-table-field-evolve-your-call/18542","_blank")},open:n,onOpenChange:r,anchor:d.jsx(A.Box,{position:"fixed",left:0,right:0,bottom:72}),cancel:{onClick:()=>r(!1)}})}function YYe(e){const[t,n]=R.useState(!1),{onAnalyticsEvent:r}=ye();return R.useEffect(()=>lo.listen("addAtLimit",{editor:e,callback:i=>{r==null||r("Table Limit Reached",{type:i.type}),n(!0)}}),[e,r]),{open:t,onOpenChange:n}}function BD(e){const{content:t,field:n,id:r,readOnly:i,padding:o="normal",scroll:a="hidden",shouldReturnEmptyContent:s=!1,icon:l,onContentChange:c}=e,{useThreads:u,CustomThreads:f}=ye(),p=r.split(":")[2]||r,h=eGe({fieldId:p}),m=u==null?void 0:u().threads,g=GYe({field:n,conditionalExtensions:h}),y=R.useRef(),b=R.useRef(!1),x=R.useMemo(()=>{var S;if(t)return(S=AI.converter(g.nodeExtensions).fromPrismic(p,g.schema,g.nodeTypes,t,m))==null?void 0:S.toJSON()},[g,t,p,m]),v=W7e({content:x,editable:!i,editorProps:{attributes:{class:Lee((()=>o==="zero"?A.contentEditableNoPaddingClass:l?A.contentEditableClassWithIcon:A.contentEditableClass)(),A.contentEditableMultilinePlaceholderClass),id:r,tabIndex:"0"}},extensions:g.allComponents,injectCSS:!1,onUpdate({editor:S}){let C;S.isEmpty&&!s?C=void 0:C=AI.converter(g.nodeExtensions).toPrismic(S.state.doc),y.current={content:C},b.current=!0,c(C)},immediatelyRender:typeof window<"u"},[g,i]);return Ke.useStableLayoutEffect(()=>{if(!v)return;const S=b.current;if(b.current=!1,S||y.current&&y.current.content===t)return;const C=v.state.selection,T=v.state.doc.content.size;v.chain().command(nGe).setContent(x??null,!1).run(),rGe({editor:v,previousContentSize:T,previousSelection:C})},[t]),v?d.jsxs(A.Field,{display:a==="x-auto"?"grid":"flex",children:[l&&d.jsx(A.FieldIcon,{name:l}),d.jsx(A.FieldLabel,{htmlFor:r,children:Br(n)}),d.jsxs(A.FieldControl,{children:[v.isEditable&&d.jsx($Ye,{editor:v,nodeTypes:g.names,labels:g.labels,hideDisabledOptions:!0}),v.isEditable&&g.names.includes("table")&&d.jsxs(d.Fragment,{children:[d.jsx(VYe,{editor:v}),d.jsx(HYe,{editor:v})]}),d.jsx(O7e,{editor:v,style:{width:"100%"}}),f&&d.jsx(f,{editor:v,threads:m})]})]}):null}function GYe({field:e,conditionalExtensions:t}){var r,i;const n=`${((r=e.config)==null?void 0:r.multi)??""}-${((i=e.config)==null?void 0:i.single)??""}`;return R.useMemo(()=>{var g;const{extensions:o,nodeTypes:a}=sVe(e.config),s=o.filter(JYe),l=o.flatMap(y=>y.richTextNodeTypes);a.has(zB)&&l.push(zB);const c=o.flatMap(y=>y.component),u=o.filter(ZYe).map(y=>y.name),f=[...t,...c,...Rze(e,s),UVe.configure({supportedExtensionNames:u}),K9e],p=f.map(y=>y.name),h=Uqe(f),m=XYe((g=e.config)==null?void 0:g.labels);return{allComponents:f,extensionNames:p,nodeTypes:a,nodeExtensions:s,names:l,schema:h,labels:m}},[n])}function JYe(e){return e.extType===Ad.Node}function ZYe(e){return!(e.extType!==Ad.Node||e.nodeType!==$c.Text||e.lockedFormat)}function XYe(e){return Array.from(e??[])}function eGe(e){const{fieldId:t}=e,{useCollaborativeComments:n,hasSharedCollaborativeHistory:r}=ye(),i=n==null?void 0:n({field:t});return i?[i.configure({history:!r})]:r?[]:[L9e]}function tGe(e){return e.getMeta(h0.key)===h0.value}function nGe(e){const{tr:t}=e;return t.setMeta(h0.key,h0.value),!0}const h0={key:"source",value:"external-update"};function rGe(e){var i,o,a,s;const{editor:t,previousContentSize:n,previousSelection:r}=e;if(t.commands.setTextSelection({from:r.from,to:r.to}),r.$anchor.parentOffset!==t.state.selection.$anchor.parentOffset||r.$head.parentOffset!==t.state.selection.$head.parentOffset||((i=r.$from.nodeBefore)==null?void 0:i.textContent)!==((o=t.state.selection.$from.nodeBefore)==null?void 0:o.textContent)&&((a=r.$from.nodeAfter)==null?void 0:a.textContent)!==((s=t.state.selection.$from.nodeAfter)==null?void 0:s.textContent)){const l=n-t.state.doc.content.size;t.commands.setTextSelection({from:r.from-l,to:r.to-l})}}function une(e){var c,u;const{content:t,field:n,id:r,onContentChange:i,readOnly:o}=e,a=R.useRef(),s=t==null?void 0:t.value,l=R.useMemo(()=>{var f,p,h;return((p=(f=a.current)==null?void 0:f.plainText)==null?void 0:p.value)===s?(h=a.current)==null?void 0:h.richText:iGe(s)},[s]);return d.jsx(BD,{id:r,icon:"notes",field:{type:"StructuredText",config:{label:Br(n),multi:"paragraph",placeholder:(c=n.config)==null?void 0:c.placeholder,useAsTitle:(u=n.config)==null?void 0:u.useAsTitle}},content:l,onContentChange:f=>{const p=oGe(f);a.current={richText:f,plainText:p},i(p)},readOnly:o})}function iGe(e){if(e)return{__TYPE__:"StructuredTextContent",value:e.split(`
213
213
  `).map(t=>({type:"paragraph",content:{text:t}}))}}function oGe(e){const t=e==null?void 0:e.value.map(n=>"content"in n?n.content.text:"").join(`
214
214
  `);if(t)return{__TYPE__:"FieldContent",type:"Text",value:t}}function dne(e){if(le.isRepeatableContent(e))return e;if(le.isLinkContent(e))return{__TYPE__:"RepeatableContent",type:"Link",value:[e]}}function fne(e){if(le.isLinkContent(e))return e;if(le.isRepeatableContent(e)){const[t]=e.value;if(le.isLinkContent(t))return t}}function aGe(e){var s;const{content:t,id:n,field:r,onContentChange:i,readOnly:o}=e,a={id:n,readOnly:o,onContentChange:i};return(s=r.config)!=null&&s.repeat?d.jsx(_Ke,{...a,field:r,content:dne(t)}):d.jsx(Nj,{...a,field:r,content:fne(t)})}const sGe=({content:e,field:t,id:n,onContentChange:r,readOnly:i})=>{var s,l;const o=Number(e==null?void 0:e.value),a=Number.isFinite(o)?o:void 0;return d.jsxs(A.Field,{children:[d.jsx(A.FieldIcon,{name:"pin"}),d.jsx(A.FieldLabel,{htmlFor:n,children:Br(t)}),d.jsx(A.FieldControl,{children:d.jsx(A.NumberInput,{id:n,value:a,min:(s=t.config)==null?void 0:s.min,max:(l=t.config)==null?void 0:l.max,padding:CG,placeholder:Zp(t),readOnly:i,onValueChange:c=>r(lGe(c))})})]})};function lGe(e){return e===void 0?void 0:{__TYPE__:"FieldContent",type:"Number",value:String(e)}}function cGe(e){const{content:t,field:n,id:r,readOnly:i,onContentChange:o}=e,{placeholder:a,options:s}=n.config??{},l=!!(s!=null&&s.includes("")),c=fGe(n),u=uGe({content:t,placeholder:a,defaultValue:c,canHaveEmptyValue:l}),f=a&&c===void 0||a===void 0&&!l;return d.jsxs(A.Field,{children:[d.jsx(A.FieldIcon,{name:"arrowDropDownCircle"}),d.jsx(A.FieldLabel,{htmlFor:r,children:Br(n)}),d.jsx(A.FieldControl,{children:d.jsxs(A.Select,{id:r,size:"large",color:"grey",value:u,disabled:i,renderTrigger:()=>d.jsx(A.SelectGhostTrigger,{id:r}),onValueChange:p=>{o(dGe({value:p,placeholder:a}))},children:[f&&d.jsx(A.SelectItem,{value:a||m0,children:a||""}),s==null?void 0:s.map(p=>d.jsx(A.SelectItem,{value:p||m0,children:p},p))]})})]})}function uGe(e){const{content:t,placeholder:n,defaultValue:r,canHaveEmptyValue:i}=e;let{value:o}=t??{};return o===""&&i?m0:(o===""&&(o=void 0),o??r??n??"")}function dGe(e){const{placeholder:t}=e;let{value:n}=e;if(n!==t)return n===m0&&(n=""),{__TYPE__:"FieldContent",type:"Select",value:n}}function fGe(e){var t,n;return((t=e.config)==null?void 0:t.default_value)===void 0||(n=e.config.options)==null?void 0:n[0]}const m0=" ",LU=pne(2,3),pGe={__TYPE__:"TableContent",content:pne(1,1)};function hGe(e){const{field:t,content:n,onContentChange:r,...i}=e;function o(a){if(!a)return r(pGe);e.onContentChange(gGe(a))}return d.jsx(BD,{...i,field:vGe(t),content:mGe(n),onContentChange:o,shouldReturnEmptyContent:!0,scroll:"x-auto",padding:"zero"})}function pne(e,t){return Array.from({length:e},()=>({key:crypto.randomUUID(),type:"tableRow",content:Array.from({length:t},()=>({key:crypto.randomUUID(),type:"tableCell",content:{__TYPE__:"StructuredTextContent",value:[{type:"paragraph",content:{text:""}}]}}))}))}function mGe(e){return{__TYPE__:"StructuredTextContent",value:[{type:"table",content:AGe(e)}]}}function AGe(e){const t=le.TableContent.decode(e);return t._tag==="Left"||!t.right.content.some(r=>r.content.some(i=>i.content.value.some(({type:o})=>o)))?LU:t.right.content}function gGe(e){return{__TYPE__:"TableContent",content:e.value.flatMap(t=>t.type==="table"?t.content:[])}}function vGe(e){var t;return{...he.TableCell,config:{...he.TableCell.config,label:(t=e.config)==null?void 0:t.label,allowTargetBlank:!0,multi:[he.TableCell.config.multi,Nc.table].join(",")}}}function yGe(e){const{id:t,readOnly:n,field:r,content:i,onContentChange:o}=e,a=i!=null&&i.value?PI.dateFromISOString(i.value):void 0;return d.jsxs(A.Field,{children:[d.jsx(A.FieldIcon,{name:"event"}),d.jsx(A.FieldLabel,{id:t,children:Br(r)}),d.jsx(A.FieldControl,{children:d.jsx(A.Box,{padding:{left:4,right:12},width:"100%",flexDirection:"column",justifyContent:"center",children:d.jsx(A.DateInput,{mode:"date-time","aria-labelledby":t,disabled:n,value:a,onValueChange:s=>{o(bGe(s))}})})})]})}function bGe(e){if(e)return{__TYPE__:"FieldContent",type:"Timestamp",value:CGe(e)}}function CGe(e){const t=`${e.getUTCFullYear()}`.padStart(4,"0"),n=`${e.getUTCMonth()+1}`.padStart(2,"0"),r=`${e.getUTCDate()}`.padStart(2,"0"),i=`${e.getUTCHours()}`.padStart(2,"0"),o=`${e.getUTCMinutes()}`.padStart(2,"0");return`${t}-${n}-${r}T${i}:${o}:00+00:00`}function BS(e){const{id:t,readOnly:n,content:r,nestableWidget:i}=e,o=Ke.useStableCallback(e.onContentChange),a=uN(),s=R.useMemo(()=>{const l={id:t,readOnly:n,onContentChange:o};return i.type==="Boolean"?d.jsx(IBe,{...l,field:i,content:le.isBooleanContent(r)?r:void 0}):i.type==="Date"?d.jsx(kBe,{...l,field:i,content:le.isDateContent(r)?r:void 0}):i.type==="Timestamp"?d.jsx(yGe,{...l,field:i,content:le.isTimestampContent(r)?r:void 0}):i.type==="Image"?d.jsx(LKe,{...l,field:i,content:le.isImageContent(r)?r:void 0}):i.type==="Link"?d.jsx(aGe,{...l,field:i,content:r}):i.type==="Number"?d.jsx(sGe,{...l,field:i,content:le.isNumberContent(r)?r:void 0}):i.type==="StructuredText"?d.jsx(BD,{...l,field:i,content:le.isRichTextContent(r)?r:void 0}):i.type==="Select"?d.jsx(cGe,{...l,field:i,content:le.isSelectContent(r)?r:void 0}):i.type==="Text"?d.jsx(une,{...l,field:i,content:le.isTextContent(r)?r:void 0}):i.type==="Embed"?d.jsx(NBe,{...l,field:i,content:le.isEmbedContent(r)?r:void 0}):i.type==="Color"?d.jsx(EBe,{...l,field:i,content:le.isColorContent(r)?r:void 0}):i.type==="GeoPoint"?d.jsx(KBe,{...l,field:i,content:le.isGeoPointContent(r)?r:void 0}):i.type==="IntegrationFields"?d.jsx(GKe,{...l,field:i,content:le.isIntegrationFieldContent(r)?r:void 0}):i.type==="Table"?d.jsx(hGe,{...l,field:i,content:le.isTableContent(r)?r:void 0}):null},[r,t,i,o,n]);return d.jsx(a,{id:t,children:s})}function hne(e){const{id:t,readOnly:n,content:r,widget:i}=e,o=Ke.useStableCallback(e.onContentChange);return R.useMemo(()=>{const a={id:t,readOnly:n,onContentChange:o};return i.type==="Group"?d.jsx(Ej,{...a,group:i,content:le.isGroupContent(r)?r:void 0}):d.jsx(BS,{...a,nestableWidget:i,content:le.isNestableContent(r)?r:void 0})},[r,t,i,o,n])}function UD(e){const{id:t,title:n,addItemButtonTitle:r,content:i,onContentChange:o,readOnly:a,repeatable:s=!0,repeatableZone:l}=e,c=Object.entries(l),u=R.useRef([mne()]).current;let f=i??u;!s&&f.length>1&&(f=f.slice(0,1));const{scrollOffsetTop:p}=ye();function h(x){return x.key}function m(x){const w=A0([],crypto.randomUUID()),[v]=yBe.repeatableContentWithDefaultNestableContentValues(l,[w]);v&&o(Et.insertAtIndex(f,x,v))}function g(x){const{index:w,offset:v}=x;o(Et.move(f,w,w+v))}function y(x){o(Et.removeIndex(f,x))}function b(x,w,v,S){const C=wGe(x,[v,S]),T=SGe(f,[w,C]);o(T)}return Object.keys(l).length===0?null:d.jsx(A.Group,{title:n??"Repeatable zone",addItemButtonTitle:r??"Add item in repeatable zone",items:f,maxItems:s?void 0:1,getItemKey:h,onAddItem:m,dnd:{scrollOffsetTop:p,onReorder:o,renderDragPreview:({index:x})=>d.jsx(xGe,{title:n??"Repeatable zone",index:x}),renderDropIndicator:TGe},readOnly:a,children:(x,w)=>{const v=new Map(x.value),S=h(x);return d.jsx(A.LazyRender,{keepLoaded:!0,loadWhenSearching:!0,children:d.jsx(A.GroupItem,{index:w,title:`${w+1} • Item`,onMove:g,onDelete:y,readOnly:a,children:c.map(([C,T])=>d.jsx(hne,{id:`${t}[${S}].${C}`,content:v.get(C),widget:T,onContentChange:E=>b(x,w,C,E),readOnly:a},C))})})}})}function SGe(e,t){const[n,r]=t;return r?e.map((i,o)=>o===n?r:i):e.filter((i,o)=>o!==n)}function wGe(e,t){const[n,r]=t;if(!r){const o=e.value.filter(([a])=>a!==n);return A0(o,e.key)}const i=Array.from(new Map(e.value).set(n,r));return A0(i,e.key)}function A0(e,t){return{__TYPE__:"GroupItemContent",value:e,key:t}}function mne(){return A0([],crypto.randomUUID())}function xGe(e){const{title:t,index:n}=e;return d.jsxs(A.Box,{padding:{block:8,inline:12},backgroundColor:"grey3",border:!0,borderRadius:6,alignItems:"center",justifyContent:"space-between",width:"100%",children:[d.jsxs("div",{children:[d.jsx(A.Text,{variant:"smallBold",color:"grey11",children:t??"Repeatable zone"}),d.jsxs(A.Text,{variant:"small",color:"grey11",children:[n+1," • Item"]})]}),d.jsx(A.Icon,{name:"dragIndicator",size:"small",color:"grey8"})]})}function TGe(e){const{isDropTarget:t,itemIndex:n,position:r}=e,i=t?d.jsx(A.Line,{color:"purple",thickness:2,sx:{position:"absolute",left:0,right:0,bottom:n===0&&r==="before"?0:void 0}},"line"):void 0;return d.jsx(A.AnimatedElement,{enterDuration:150,children:i})}function IGe(e,t){let n=e;return n=RGe(n,t),n=_Ge(n,t),n=EGe(n,t),n=kGe(n,t),n}function _Ge(e,t){return he.flattenSections(t).reduce((r,[i,o])=>!e[i]&&o.type==="Group"?{...r,[i]:Ane()}:r,e)}function EGe(e,t){return le.traverseDocument({document:e,customType:t})({transformWidget({model:n,content:r}){return n?r:void 0},transformSlice(n){return n.model?n.content:void 0}})}function RGe(e,t){return le.traverseDocument({document:e,customType:t})({transformWidget({model:n,content:r}){if((n==null?void 0:n.type)==="Link"){const{repeat:i}=n.config??{};switch(r.__TYPE__){case"LinkContent":return i?dne(r)??r:r;case"RepeatableContent":return i?r:fne(r)??r;default:return r}}return r}})}function kGe(e,t){return le.fillDocumentWithDefaultValues(t,e)}function Ane(){return{__TYPE__:"GroupContentType",value:[mne()]}}const gne={unclassified:{title:"Draft",color:"amber"},published:{title:"Live",color:"green"},release:{title:"Planned",color:"purple"},archived:{title:"Archived",color:"grey"}},LI={unclassified:["unclassified","published"],archived:["unclassified","published"],release:["release","published"],published:["published","unclassified"]};function ND(e){const{documentId:t,versionId:n,baseUrl:r,status:i,releaseId:o}=e,a={s:i,v:n,r:o},s=bi.createRouteParams({params:a}),l=new URLSearchParams(s).toString();return new URL(`pages/${t}?${l}`,r)}function $Ge(e){const{children:t,...n}=e;return d.jsx(Sn.QueryErrorResetBoundary,{children:({reset:r})=>d.jsx(A.ErrorBoundary,{...n,onReset:r,children:t})})}function OGe(e){const{href:t,tracking:n}=e;return d.jsx(A.Box,{justifyContent:"center",padding:{block:6},children:d.jsxs(A.Text,{href:t,variant:"smallBold",color:"grey11",onClick:()=>void n.track({event:"shared-onboarding:follow-tutorial",source:n.source}),children:["Or watch our in-depth course",d.jsx(A.Icon,{name:"playCircle",color:"grey11",size:"small",sx:{marginLeft:4}})]})})}function MGe(e){const{step:t,stepIndex:n,isOpen:r,onActionClick:i,onClose:o,contentRef:a}=e,[s,l]=R.useState(!1),[c,u]=R.useState(e.isStepComplete);R.useEffect(()=>{r&&u(e.isStepComplete)},[e.isStepComplete,r]);async function f(){if(r)try{l(!0),await i(c)}finally{l(!1)}}return d.jsxs(A.Dialog,{open:r,onOpenChange:o,size:"small",children:[d.jsx(A.DialogHeader,{title:"Onboarding"}),d.jsxs(A.DialogContent,{children:[d.jsx(A.ScrollArea,{children:d.jsxs(A.Box,{ref:a,as:"article",flexDirection:"column",padding:16,gap:16,children:[d.jsx(A.DialogDescription,{asChild:!0,children:d.jsxs("section",{children:[d.jsxs(A.Text,{sx:{marginBottom:4},color:"purple9",variant:"bold",children:["Step ",n+1]}),d.jsx(A.Text,{variant:"h3",children:t.title}),t.content]})}),t.videoUrl&&d.jsx(A.Video,{src:t.videoUrl,sizing:"contain",borderRadius:4,autoPlay:!0,loop:!0})]})}),d.jsxs(A.DialogActions,{children:[d.jsx(A.DialogCancelButton,{size:"medium",children:"Close"}),!t.defaultCompleted&&d.jsx(A.DialogActionButton,{size:"medium",onClick:f,loading:s,color:c?"darkGrey":"purple",children:c?"Undo step":"Complete step"})]})]})]})}function FGe(e){const{steps:t,completedSteps:n,onToggleStep:r,tracking:i,stepOverrides:o}=e,[a,s]=R.useState(!1),[l,c]=R.useState(t[0]),u=R.useRef(null);if(!l)return null;const f=t.findIndex(({id:y})=>y===l.id);function p(y){return n.includes(y.id)}function h(y){c(y),s(!0),i.track({event:"shared-onboarding:step-opened",stepId:y.id,stepTitle:y.title,source:i.source})}async function m(y=!1){var b;if(l&&(await r(l),!y)){(b=u.current)==null||b.animate([{opacity:0},{opacity:1}],{duration:400});const x=g();x?h(x):s(!1)}}function g(){let y=f+1;for(;y<t.length;){const b=t[y];if(b&&!p(b))return b;y++}}return d.jsxs(d.Fragment,{children:[d.jsx(MGe,{contentRef:u,isOpen:a,step:l,stepIndex:f,isStepComplete:p(l),onClose:()=>s(!1),onActionClick:m}),d.jsxs(A.DropdownMenu,{children:[d.jsx(A.DropdownMenuTrigger,{children:d.jsx(A.Button,{size:"large",color:"grey",sx:{width:"100%"},renderStartIcon:jGe,children:n.length>0?"Continue":"Start now"})}),d.jsxs(A.DropdownMenuContent,{side:"right",minWidth:256,collisionPadding:8,children:[d.jsx(A.DropdownMenuLabel,{children:d.jsx(A.Text,{variant:"small",color:"grey11",sx:{marginInline:8},children:"Progress"})}),t.map((y,b)=>{const x=p(y);return d.jsx(A.DropdownMenuItem,{onSelect:(o==null?void 0:o[y.id])??(()=>h(y)),description:y.description,completed:x,endAdornment:d.jsx(A.Icon,{name:"chevronRight",size:"small",color:"grey11"}),children:`${b+1} ${y.title}`},y.id)})]})]})]})}function jGe(){return d.jsx(A.Icon,{name:"arrowForward",size:"small",color:"grey11"})}function DGe(e){const{steps:t,completedSteps:n,tutorialLink:r,tracking:i,onToggleStep:o,onClose:a,stepOverrides:s}=e,l=n.length===t.length;return d.jsx(A.Card,{variant:l?"elevated":"animated-light",paddingBlock:16,onClose:a,children:d.jsxs(A.CardContent,{children:[d.jsxs("div",{children:[d.jsx(A.Text,{variant:"bold",children:`Build your first page in ${t.length.toString()} simple steps`}),d.jsx(A.Text,{color:"grey11",variant:"small",children:"Render a live page with content coming from Prismic."})]}),d.jsx(A.ProgressBar,{value:n.length,max:t.length,displayLabel:!0,getValueLabel:(c,u)=>`${c}/${u}`}),d.jsx(FGe,{steps:t,completedSteps:n,onToggleStep:o,tracking:i,stepOverrides:s}),r&&d.jsx(OGe,{href:r,tracking:i})]})})}function LGe(e){const{framework:t,projectName:n,starterId:r,repositoryName:i}=e,{frameworkNameLabel:o,createProjectCodeSnippet:a}=PGe(e),s=[{id:"createPrismicProject",title:"Create your Prismic project",description:"Create and set up your project",defaultCompleted:!0,content:d.jsx(A.Text,{children:"A Prismic project is a space for managing and organizing the content of your website."})},{id:"chooseLocale",title:"Select your main locale",description:"Choose your first locale",defaultCompleted:!!r,content:d.jsx(A.Text,{children:"Locales allow you to create and manage multilingual versions of your content within a single Prismic project."})},{id:"createProject",title:`Create a ${o}project`,description:"Create and set up your project",videoUrl:"https://res.cloudinary.com/dmtf1daqp/video/upload/v1727768069/DEV_TOOLS/ONBOARDING_GUIDE/Pagebuilder_onboarding_step_3_puh6fx.mp4",content:d.jsxs(d.Fragment,{children:[d.jsx(A.Text,{sx:{marginBottom:16},children:"Now that you have a Prismic project to manage the content of your website, let's create the code project that will be querying your content."}),!!a&&d.jsx(lm,{code:`${a} ${i??"<my-project>"}`,language:"bash"}),d.jsx(A.Text,{variant:"small",sx:{marginTop:16},children:"(example for Next.js below)"})]})},{id:"setupSliceMachine",title:"Set up & run Slice Machine",description:"Prepare the code to fetch content",videoUrl:"https://res.cloudinary.com/dmtf1daqp/video/upload/v1727768069/DEV_TOOLS/ONBOARDING_GUIDE/page_builder_onboarding_step_4_yl8fb8.mp4",content:d.jsxs(d.Fragment,{children:[d.jsx(A.Text,{sx:{marginBottom:16},children:`Slice Machine is the Prismic tool for creating your content models.
215
215
  Install it in your ${o}project by running these commands:`}),d.jsx(lm,{code:`cd ${n??"<your project name>"}
package/dist/index.es.js CHANGED
@@ -67070,11 +67070,15 @@ function cP(e) {
67070
67070
  C.isEmpty && !s ? b = void 0 : b = LE.converter(
67071
67071
  A.nodeExtensions
67072
67072
  ).toPrismic(C.state.doc), v.current = { content: b }, y.current = !0, c(b);
67073
- }
67073
+ },
67074
+ // Prevents any hydration warnings when the consumer is Next.js
67075
+ immediatelyRender: typeof window < "u"
67074
67076
  },
67075
67077
  [A, i]
67076
67078
  );
67077
67079
  return foe(() => {
67080
+ if (!g)
67081
+ return;
67078
67082
  const C = y.current;
67079
67083
  if (y.current = !1, C || v.current && v.current.content === t)
67080
67084
  return;
@@ -67084,7 +67088,7 @@ function cP(e) {
67084
67088
  previousContentSize: T,
67085
67089
  previousSelection: b
67086
67090
  });
67087
- }, [t]), /* @__PURE__ */ R(ji, { display: a === "x-auto" ? "grid" : "flex", children: [
67091
+ }, [t]), g ? /* @__PURE__ */ R(ji, { display: a === "x-auto" ? "grid" : "flex", children: [
67088
67092
  l && /* @__PURE__ */ f(wr, { name: l }),
67089
67093
  /* @__PURE__ */ f(qi, { htmlFor: r, children: ni(n) }),
67090
67094
  /* @__PURE__ */ R(Vi, { children: [
@@ -67104,7 +67108,7 @@ function cP(e) {
67104
67108
  /* @__PURE__ */ f(TQe, { editor: g, style: { width: "100%" } }),
67105
67109
  d && /* @__PURE__ */ f(d, { editor: g, threads: m })
67106
67110
  ] })
67107
- ] });
67111
+ ] }) : null;
67108
67112
  }
67109
67113
  function KZe({
67110
67114
  field: e,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "dependencies": {
3
3
  "@floating-ui/react-dom-interactions": "0.9.3",
4
4
  "@prismicio/client": "7.15.1",
5
- "@prismicio/editor-support": "0.4.86-alpha.jp-fix-navigation-icon.1",
5
+ "@prismicio/editor-support": "0.4.87",
6
6
  "@prismicio/richtext": "2.1.1",
7
7
  "@prismicio/types-internal": "3.16.0",
8
8
  "@tiptap/core": "2.11.5",
@@ -41,7 +41,7 @@
41
41
  "devDependencies": {
42
42
  "@liveblocks/client": "3.1.2",
43
43
  "@liveblocks/react": "3.1.2",
44
- "@prismicio/editor-ui": "^0.4.86-alpha.jp-fix-navigation-icon.1",
44
+ "@prismicio/editor-ui": "^0.4.87",
45
45
  "@testing-library/react": "15.0.7",
46
46
  "@types/react": "18.0.18",
47
47
  "@types/react-dom": "18.3.0",
@@ -75,7 +75,7 @@
75
75
  "module": "./dist/index.es.js",
76
76
  "name": "@prismicio/editor-fields",
77
77
  "peerDependencies": {
78
- "@prismicio/editor-ui": "^0.4.86-alpha.jp-fix-navigation-icon.1",
78
+ "@prismicio/editor-ui": "^0.4.87",
79
79
  "@tanstack/react-query": "5.55.4",
80
80
  "react": "18",
81
81
  "react-dom": "18"
@@ -92,6 +92,5 @@
92
92
  },
93
93
  "sideEffects": false,
94
94
  "types": "./dist/index.d.ts",
95
- "version": "0.4.86-alpha.jp-fix-navigation-icon.1",
96
- "stableVersion": "0.4.85"
95
+ "version": "0.4.87"
97
96
  }