@fileverse-dev/ddoc 1.0.6 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.es.js CHANGED
@@ -36722,7 +36722,7 @@ const o4 = Je.create({
36722
36722
  onPublish: e,
36723
36723
  togglePreviewMode: r
36724
36724
  });
36725
- return o ? /* @__PURE__ */ _.jsx("div", { "data-cy": "single-webpage", className: "h-screen w-screen bg-[#f9fbfd]", children: /* @__PURE__ */ _.jsx("div", { className: "h-full flex flex-col overflow-scroll no-scrollbar", children: /* @__PURE__ */ _.jsxs("div", { className: "w-full h-screen", children: [
36725
+ return o ? /* @__PURE__ */ _.jsx("div", { "data-cy": "single-webpage", className: "bg-[#f9fbfd]", children: /* @__PURE__ */ _.jsx("div", { className: "h-full flex flex-col overflow-scroll no-scrollbar", children: /* @__PURE__ */ _.jsxs("div", { className: "w-full h-screen", children: [
36726
36726
  /* @__PURE__ */ _.jsx("div", { className: "h-fit relative bg-[#ffffff]", children: /* @__PURE__ */ _.jsxs("div", { className: "flex items-center justify-center pl-4 pr-4 border-b-1 border gap-2 h-16", children: [
36727
36727
  /* @__PURE__ */ _.jsx("div", { className: "grow", children: /* @__PURE__ */ _.jsx(
36728
36728
  Mw,
@@ -36734,17 +36734,16 @@ const o4 = Je.create({
36734
36734
  ) }),
36735
36735
  !n && /* @__PURE__ */ _.jsx("div", { className: "grow relative", children: /* @__PURE__ */ _.jsx(wA, { editor: o }) }),
36736
36736
  /* @__PURE__ */ _.jsx("div", { children: /* @__PURE__ */ _.jsx(ya, { onClick: () => r(n), children: n ? "Edit" : "Preview" }) }),
36737
- e && /* @__PURE__ */ _.jsx(
36738
- "div",
36737
+ e && /* @__PURE__ */ _.jsx("div", { children: /* @__PURE__ */ _.jsx(
36738
+ ya,
36739
36739
  {
36740
36740
  onClick: () => e({
36741
36741
  metaData: l,
36742
36742
  editorJSONData: o.getJSON()
36743
36743
  }),
36744
- className: "cursor-pointer",
36745
- children: /* @__PURE__ */ _.jsx(ya, { children: "Publish" })
36744
+ children: "Publish"
36746
36745
  }
36747
- )
36746
+ ) })
36748
36747
  ] }) }),
36749
36748
  /* @__PURE__ */ _.jsx("main", { className: "h-screen lg:h-full w-full rounded-[8px] flex flex-col justify-start items-center gap-2", children: /* @__PURE__ */ _.jsx(
36750
36749
  "div",
package/dist/index.umd.js CHANGED
@@ -356,4 +356,4 @@ Use Chrome, Firefox or Internet Explorer 11`)}}).call(this)}).call(this,s("_proc
356
356
  .block-interactivity-`.concat(n,` {pointer-events: none;}
357
357
  .allow-interactivity-`).concat(n,` {pointer-events: all;}
358
358
  `)},IR=0,_s=[];function PR(n){var e=le.useRef([]),t=le.useRef([0,0]),r=le.useRef(),i=le.useState(IR++)[0],s=le.useState(function(){return ov()})[0],o=le.useRef(n);le.useEffect(function(){o.current=n},[n]),le.useEffect(function(){if(n.inert){document.body.classList.add("block-interactivity-".concat(i));var g=rR([n.lockRef.current],(n.shards||[]).map(hv),!0).filter(Boolean);return g.forEach(function(v){return v.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),g.forEach(function(v){return v.classList.remove("allow-interactivity-".concat(i))})}}},[n.inert,n.lockRef.current,n.shards]);var l=le.useCallback(function(g,v){if("touches"in g&&g.touches.length===2)return!o.current.allowPinchZoom;var w=xc(g),S=t.current,C="deltaX"in g?g.deltaX:S[0]-w[0],y="deltaY"in g?g.deltaY:S[1]-w[1],k,E=g.target,T=Math.abs(C)>Math.abs(y)?"h":"v";if("touches"in g&&T==="h"&&E.type==="range")return!1;var N=cv(T,E);if(!N)return!0;if(N?k=T:(k=T==="v"?"h":"v",N=cv(T,E)),!N)return!1;if(!r.current&&"changedTouches"in g&&(C||y)&&(r.current=k),!k)return!0;var _=r.current||k;return DR(_,v,g,_==="h"?C:y,!0)},[]),a=le.useCallback(function(g){var v=g;if(!(!_s.length||_s[_s.length-1]!==s)){var w="deltaY"in v?fv(v):xc(v),S=e.current.filter(function(k){return k.name===v.type&&k.target===v.target&&RR(k.delta,w)})[0];if(S&&S.should){v.cancelable&&v.preventDefault();return}if(!S){var C=(o.current.shards||[]).map(hv).filter(Boolean).filter(function(k){return k.contains(v.target)}),y=C.length>0?l(v,C[0]):!o.current.noIsolation;y&&v.cancelable&&v.preventDefault()}}},[]),c=le.useCallback(function(g,v,w,S){var C={name:g,delta:v,target:w,should:S};e.current.push(C),setTimeout(function(){e.current=e.current.filter(function(y){return y!==C})},1)},[]),u=le.useCallback(function(g){t.current=xc(g),r.current=void 0},[]),d=le.useCallback(function(g){c(g.type,fv(g),g.target,l(g,n.lockRef.current))},[]),f=le.useCallback(function(g){c(g.type,xc(g),g.target,l(g,n.lockRef.current))},[]);le.useEffect(function(){return _s.push(s),n.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:f}),document.addEventListener("wheel",a,Os),document.addEventListener("touchmove",a,Os),document.addEventListener("touchstart",u,Os),function(){_s=_s.filter(function(g){return g!==s}),document.removeEventListener("wheel",a,Os),document.removeEventListener("touchmove",a,Os),document.removeEventListener("touchstart",u,Os)}},[]);var h=n.removeScrollBar,p=n.inert;return le.createElement(le.Fragment,null,p?le.createElement(s,{styles:LR(i)}):null,h?le.createElement(ER,{gapMode:"margin"}):null)}const FR=fR(sv,PR);var pv=le.forwardRef(function(n,e){return le.createElement(wc,Zn({},n,{ref:e,sideCar:FR}))});pv.classNames=wc.classNames;const mv="Popover",[gv,r4]=v1(mv,[G1]),oh=G1(),[BR,Ns]=gv(mv),$R=n=>{const{__scopePopover:e,children:t,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=n,l=oh(e),a=O.useRef(null),[c,u]=O.useState(!1),[d=!1,f]=ZD({prop:r,defaultProp:i,onChange:s});return O.createElement(qD,l,O.createElement(BR,{scope:e,contentId:LN(),triggerRef:a,open:d,onOpenChange:f,onOpenToggle:O.useCallback(()=>f(h=>!h),[f]),hasCustomAnchor:c,onCustomAnchorAdd:O.useCallback(()=>u(!0),[]),onCustomAnchorRemove:O.useCallback(()=>u(!1),[]),modal:o},t))},jR="PopoverTrigger",HR=O.forwardRef((n,e)=>{const{__scopePopover:t,...r}=n,i=Ns(jR,t),s=oh(t),o=Ai(e,i.triggerRef),l=O.createElement(Mi.button,dt({type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":bv(i.open)},r,{ref:o,onClick:Ur(n.onClick,i.onOpenToggle)}));return i.hasCustomAnchor?l:O.createElement(KD,dt({asChild:!0},s),l)}),VR="PopoverPortal",[i4,zR]=gv(VR,{forceMount:void 0}),Yo="PopoverContent",UR=O.forwardRef((n,e)=>{const t=zR(Yo,n.__scopePopover),{forceMount:r=t.forceMount,...i}=n,s=Ns(Yo,n.__scopePopover);return O.createElement(ev,{present:r||s.open},s.modal?O.createElement(WR,dt({},i,{ref:e})):O.createElement(qR,dt({},i,{ref:e})))}),WR=O.forwardRef((n,e)=>{const t=Ns(Yo,n.__scopePopover),r=O.useRef(null),i=Ai(e,r),s=O.useRef(!1);return O.useEffect(()=>{const o=r.current;if(o)return nR(o)},[]),O.createElement(pv,{as:$f,allowPinchZoom:!0},O.createElement(yv,dt({},n,{ref:i,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Ur(n.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=t.triggerRef.current)===null||l===void 0||l.focus()}),onPointerDownOutside:Ur(n.onPointerDownOutside,o=>{const l=o.detail.originalEvent,a=l.button===0&&l.ctrlKey===!0,c=l.button===2||a;s.current=c},{checkForDefaultPrevented:!1}),onFocusOutside:Ur(n.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})))}),qR=O.forwardRef((n,e)=>{const t=Ns(Yo,n.__scopePopover),r=O.useRef(!1),i=O.useRef(!1);return O.createElement(yv,dt({},n,{ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var o;if((o=n.onCloseAutoFocus)===null||o===void 0||o.call(n,s),!s.defaultPrevented){var l;r.current||(l=t.triggerRef.current)===null||l===void 0||l.focus(),s.preventDefault()}r.current=!1,i.current=!1},onInteractOutside:s=>{var o,l;(o=n.onInteractOutside)===null||o===void 0||o.call(n,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const a=s.target;((l=t.triggerRef.current)===null||l===void 0?void 0:l.contains(a))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&i.current&&s.preventDefault()}}))}),yv=O.forwardRef((n,e)=>{const{__scopePopover:t,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,disableOutsidePointerEvents:o,onEscapeKeyDown:l,onPointerDownOutside:a,onFocusOutside:c,onInteractOutside:u,...d}=n,f=Ns(Yo,t),h=oh(t);return SN(),O.createElement(EN,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s},O.createElement(CN,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:u,onEscapeKeyDown:l,onPointerDownOutside:a,onFocusOutside:c,onDismiss:()=>f.onOpenChange(!1)},O.createElement(JD,dt({"data-state":bv(f.open),role:"dialog",id:f.contentId},h,d,{ref:e,style:{...d.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}}))))}),KR="PopoverClose",JR=O.forwardRef((n,e)=>{const{__scopePopover:t,...r}=n,i=Ns(KR,t);return O.createElement(Mi.button,dt({type:"button"},r,{ref:e,onClick:Ur(n.onClick,()=>i.onOpenChange(!1))}))});function bv(n){return n?"open":"closed"}const GR=$R,YR=HR,ZR=UR,kc=JR,Sc=({children:n,isActive:e,onClick:t,disabled:r,className:i})=>{const s=Fe("flex items-center gap-2 p-1.5 text-xs font-medium text-neutral-500 text-left w-full rounded-md border border-transparent transition-all",!e&&!r,"hover:border-neutral-200 hover:bg-neutral-100",e&&!r&&"bg-neutral-200 text-neutral-800",r&&"text-neutral-300 cursor-not-allowed",i);return D.jsx("button",{className:s,disabled:r,onClick:t,children:n})},XR=(n,e,t)=>{const r=O.useCallback(()=>{const l=n.chain();l.setNodeSelection(t).unsetAllMarks(),(e==null?void 0:e.type.name)!=="paragraph"&&l.setParagraph(),l.run()},[n,t,e==null?void 0:e.type.name]),i=O.useCallback(()=>{n.commands.setNodeSelection(t);const{$anchor:l}=n.state.selection,a=l.node(1)||n.state.selection.node;n.chain().setMeta("hideDragHandle",!0).insertContentAt(t+((e==null?void 0:e.nodeSize)||0),a.toJSON()).run()},[n,t,e==null?void 0:e.nodeSize]),s=O.useCallback(()=>{n.chain().setMeta("hideDragHandle",!0).setNodeSelection(t).run(),document.execCommand("copy"),alert("copied")},[n,t]),o=O.useCallback(()=>{n.chain().setMeta("hideDragHandle",!0).setNodeSelection(t).deleteSelection().run()},[n,t]);return{resetTextFormatting:r,duplicateNode:i,copyNodeToClipboard:s,deleteNode:o}},QR=({node:n,getPos:e,editor:t,deleteNode:r})=>{const[i,s]=O.useState(!1),o=XR(t,n,e()),l=Ul(),a=["https://twitter.com","https://x.com"],c=O.useMemo(()=>{const{content:_}=n.content;return _[0].type.name==="table"},[n.content]),u=O.useMemo(()=>{var A;const{content:_}=n.content;return(A=_[0].content.content[0])==null?void 0:A.text},[n.content]),d=O.useMemo(()=>{var A;const{content:_}=n.content;return(A=_[0].content.content[1])==null?void 0:A.text},[n.content]),f=O.useMemo(()=>{const{content:_}=n.content;return _[0].content.content.find(A=>{var R;return(R=A==null?void 0:A.text)==null?void 0:R.match(/\/status\/([0-9]*)/)})},[n.content]),h=()=>{if(!u)return;let _=u;if(u.includes("<iframe"))_=d;else switch(!0){case/youtu\.?be(?:\.com)?\/(?:.*v(?:\/|=)|(?:.*\/)?)([a-zA-Z0-9-_]+)/.test(u):{const V=u.match(/youtu\.?be(?:\.com)?\/(?:.*v(?:\/|=)|(?:.*\/)?)([a-zA-Z0-9-_]+)/);V&&V.length>0&&(_=`https://www.youtube.com/embed/${V[1]}`);break}case/vimeo\.com\/([a-zA-Z0-9-_]+)/.test(u):{const V=u.match(/vimeo\.com\/([a-zA-Z0-9-_]+)/);V&&V.length>0&&(_=`https://player.vimeo.com/video/${V[1]}`);break}default:return}const A=640,R=360,P=e(),$=P+n.nodeSize;_&&(t==null||t.chain().focus(P).deleteRange({from:P===0?P:P+1,to:$}).setIframe({src:_,width:A,height:R}).run())},p=_=>{const A=_.match(/\/status\/([0-9]*)/);return A&&A.length>0?A[1]:null},g=()=>{if(!u)return;let _=u;const A=a.some(V=>u.includes(V)),R=p(u);A&&R?_=R:f&&(_=p(f.text));const P=e(),$=P+n.nodeSize;_&&(t==null||t.chain().focus(P).deleteRange({from:P===2?P:P+1,to:$}).setTweetEmbed({tweetId:_}).run())},v=()=>{const _=e()+n.nodeSize;t.commands.insertContentAt(_,{type:"dBlock",content:[{type:"paragraph"}]})},w=()=>{const _=e();t.commands.insertContentAt(_,{type:"dBlock",content:[{type:"paragraph"}]})},S=()=>{r()},C=_=>{_.altKey?k():y()},y=()=>{v()},k=()=>{w()},E=_=>{_.altKey&&S()},N=y1(()=>{if(a.some(_=>u.includes(_))||f!=null&&f.text){g();return}else{h();return}},1e3);return O.useEffect(()=>{u&&N()},[u]),D.jsxs(bo,{as:"div",className:Fe("flex gap-2 group w-full relative justify-center items-start",l&&"pointer-events-none",c&&"2xl:ml-4 pointer-events-auto"),children:[D.jsxs("section",{className:"lg:flex gap-1 hidden","aria-label":"left-menu",contentEditable:!1,children:[D.jsx(T0,{content:D.jsxs("div",{className:"flex flex-col w-40",children:[D.jsx("div",{className:"text-xs",children:"Click to add below"}),D.jsx("div",{className:"text-xs",children:"Opt + Click to add above"})]}),children:D.jsx("div",{className:`d-block-button cursor-pointer ${!l&&"group-hover:opacity-100"}`,contentEditable:!1,onClick:C,children:D.jsx(nT,{size:18})})}),D.jsxs(GR,{open:i,onOpenChange:s,children:[D.jsx(YR,{asChild:!0,children:D.jsx("div",{className:`d-block-button cursor-pointer ${!l&&"group-hover:opacity-100"}`,contentEditable:!1,draggable:!0,"data-drag-handle":!0,onClick:E,children:D.jsx(YE,{size:18})})}),D.jsx(ZR,{side:"bottom",align:"start",sideOffset:8,className:"z-10",children:D.jsxs(ld,{className:"p-2 flex flex-col min-w-[16rem]",children:[D.jsx(kc,{children:D.jsxs(Sc,{onClick:o.resetTextFormatting,children:[D.jsx(rT,{size:18}),"Clear formatting"]})}),D.jsx(kc,{children:D.jsxs(Sc,{onClick:o.copyNodeToClipboard,children:[D.jsx(qE,{size:18}),"Copy to clipboard"]})}),D.jsx(kc,{children:D.jsxs(Sc,{onClick:o.duplicateNode,children:[D.jsx(JE,{size:18}),"Duplicate"]})}),D.jsx(vo.Divider,{horizontal:!0}),D.jsx(kc,{children:D.jsxs(Sc,{onClick:o.deleteNode,className:"text-red-500 hover:bg-red-500 bg-opacity-10 hover:bg-opacity-20",children:[D.jsx(oT,{size:18}),"Delete"]})})]})})]})]}),D.jsx(Kg,{className:Fe("node-view-content w-full",{"is-table min-w-auto":c})})]})},e5=Ve.create({name:"dBlock",priority:1e3,group:"dBlock",content:"(block|columns)",draggable:!0,selectable:!1,inline:!1,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:'div[data-type="d-block"]'}]},renderHTML({HTMLAttributes:n}){return["div",Ce(n,{"data-type":"d-block"}),0]},addCommands(){return{setDBlock:n=>({state:e,chain:t})=>{const{selection:{from:r}}=e,i=n!==void 0||n!==null?r:n;return t().insertContentAt(i,{type:this.name,content:[{type:"paragraph"}]}).focus(i+2).run()},mergeDBlocksIntoList:n=>({state:e,dispatch:t})=>{if(!t)throw new Error("Dispatch function is not provided.");const{from:r,to:i}=e.selection;let s=e.tr;const o=[];if(e.doc.nodesBetween(r,i,a=>{if(a.type.name===this.name){const c=e.schema.nodes.listItem.create(null,a.content);c&&o.push(c)}}),o.length===0)return!1;const l=e.schema.nodes[n].create(null,o);return l?(s=s.replaceRangeWith(r,i,l),t(s),!0):!1},splitListToDBlocks:n=>({state:e,dispatch:t})=>{if(!t)throw new Error("Dispatch function is not provided.");const{from:r,to:i}=e.selection;let s=e.tr;return e.doc.nodesBetween(r,i,(o,l)=>{if(o.type.name===n){const a=e.schema.nodes[this.name].create(null,o.content);s=s.insert(l,a)}}),t(s),!0}}},addNodeView(){return hi(QR)},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setDBlock(),Enter:({editor:n})=>{var c;const{selection:{$head:e,from:t,to:r},doc:i}=n.state,s=e.node(e.depth-1);if((s==null?void 0:s.type.name)!=="dBlock")return!1;let o=-1,l="";i.descendants((u,d)=>{if(o!==-1)return!1;if(u.type.name===this.name)return;const[f,h]=[d,d+u.nodeSize];return f<=t&&r<=h&&(o=h,l=u.type.name),!1});const a=(c=i.slice(t,o))==null?void 0:c.toJSON().content;try{return l==="codeBlock"?n.chain().insertContentAt({from:t,to:o},`
359
- `).focus(o+1).run():["columns","heading"].includes(l)?n.chain().insertContent({type:"dBlock",content:[{type:"paragraph"}]}).focus().run():n.chain().insertContentAt({from:t,to:o},{type:this.name,content:a}).focus(t+4).run()}catch(u){return console.error(`Error inserting content into dBlock node: ${u}`),!1}}}}});let lh,ah;if(typeof WeakMap<"u"){let n=new WeakMap;lh=e=>n.get(e),ah=(e,t)=>(n.set(e,t),t)}else{let n=[],e=10,t=0;lh=r=>{for(let i=0;i<n.length;i+=2)if(n[i]==r)return n[i+1]},ah=(r,i)=>(t==e&&(t=0),n[t++]=r,n[t++]=i)}class Ds{constructor(e,t,r,i){this.left=e,this.top=t,this.right=r,this.bottom=i}}class et{constructor(e,t,r,i){this.width=e,this.height=t,this.map=r,this.problems=i}findCell(e){for(let t=0;t<this.map.length;t++){let r=this.map[t];if(r!=e)continue;let i=t%this.width,s=t/this.width|0,o=i+1,l=s+1;for(let a=1;o<this.width&&this.map[t+a]==r;a++)o++;for(let a=1;l<this.height&&this.map[t+this.width*a]==r;a++)l++;return new Ds(i,s,o,l)}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,r){let{left:i,right:s,top:o,bottom:l}=this.findCell(e);return t=="horiz"?(r<0?i==0:s==this.width)?null:this.map[o*this.width+(r<0?i-1:s)]:(r<0?o==0:l==this.height)?null:this.map[i+this.width*(r<0?o-1:l)]}rectBetween(e,t){let{left:r,right:i,top:s,bottom:o}=this.findCell(e),{left:l,right:a,top:c,bottom:u}=this.findCell(t);return new Ds(Math.min(r,l),Math.min(s,c),Math.max(i,a),Math.max(o,u))}cellsInRect(e){let t=[],r={};for(let i=e.top;i<e.bottom;i++)for(let s=e.left;s<e.right;s++){let o=i*this.width+s,l=this.map[o];r[l]||(r[l]=!0,(s!=e.left||!s||this.map[o-1]!=l)&&(i!=e.top||!i||this.map[o-this.width]!=l)&&t.push(l))}return t}positionAt(e,t,r){for(let i=0,s=0;;i++){let o=s+r.child(i).nodeSize;if(i==e){let l=t+e*this.width,a=(e+1)*this.width;for(;l<a&&this.map[l]<s;)l++;return l==a?o-1:this.map[l]}s=o}}static get(e){return lh(e)||ah(e,t5(e))}}function t5(n){if(n.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+n.type.name);let e=n5(n),t=n.childCount,r=[],i=0,s=null,o=[];for(let c=0,u=e*t;c<u;c++)r[c]=0;for(let c=0,u=0;c<t;c++){let d=n.child(c);u++;for(let p=0;;p++){for(;i<r.length&&r[i]!=0;)i++;if(p==d.childCount)break;let g=d.child(p),{colspan:v,rowspan:w,colwidth:S}=g.attrs;for(let C=0;C<w;C++){if(C+c>=t){(s||(s=[])).push({type:"overlong_rowspan",pos:u,n:w-C});break}let y=i+C*e;for(let k=0;k<v;k++){r[y+k]==0?r[y+k]=u:(s||(s=[])).push({type:"collision",row:c,pos:u,n:v-k});let E=S&&S[k];if(E){let T=(y+k)%e*2,N=o[T];N==null||N!=E&&o[T+1]==1?(o[T]=E,o[T+1]=1):N==E&&o[T+1]++}}}i+=v,u+=g.nodeSize}let f=(c+1)*e,h=0;for(;i<f;)r[i++]==0&&h++;h&&(s||(s=[])).push({type:"missing",row:c,n:h}),u++}let l=new et(e,t,r,s),a=!1;for(let c=0;!a&&c<o.length;c+=2)o[c]!=null&&o[c+1]<t&&(a=!0);return a&&r5(l,o,n),l}function n5(n){let e=-1,t=!1;for(let r=0;r<n.childCount;r++){let i=n.child(r),s=0;if(t)for(let o=0;o<r;o++){let l=n.child(o);for(let a=0;a<l.childCount;a++){let c=l.child(a);o+c.attrs.rowspan>r&&(s+=c.attrs.colspan)}}for(let o=0;o<i.childCount;o++){let l=i.child(o);s+=l.attrs.colspan,l.attrs.rowspan>1&&(t=!0)}e==-1?e=s:e!=s&&(e=Math.max(e,s))}return e}function r5(n,e,t){n.problems||(n.problems=[]);for(let r=0,i={};r<n.map.length;r++){let s=n.map[r];if(i[s])continue;i[s]=!0;let o=t.nodeAt(s),l=null;for(let a=0;a<o.attrs.colspan;a++){let c=(r+a)%n.width,u=e[c*2];u!=null&&(!o.attrs.colwidth||o.attrs.colwidth[a]!=u)&&((l||(l=i5(o.attrs)))[a]=u)}l&&n.problems.unshift({type:"colwidth mismatch",pos:s,colwidth:l})}}function i5(n){if(n.colwidth)return n.colwidth.slice();let e=[];for(let t=0;t<n.colspan;t++)e.push(0);return e}function Mt(n){let e=n.cached.tableNodeTypes;if(!e){e=n.cached.tableNodeTypes={};for(let t in n.nodes){let r=n.nodes[t],i=r.spec.tableRole;i&&(e[i]=r)}}return e}const Gr=new We("selectingCells");function Rs(n){for(let e=n.depth-1;e>0;e--)if(n.node(e).type.spec.tableRole=="row")return n.node(0).resolve(n.before(e+1));return null}function s5(n){for(let e=n.depth;e>0;e--){const t=n.node(e).type.spec.tableRole;if(t==="cell"||t==="header_cell")return n.node(e)}return null}function Tn(n){let e=n.selection.$head;for(let t=e.depth;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return!0;return!1}function Ec(n){let e=n.selection;return e.$anchorCell?e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell:e.node&&e.node.type.spec.tableRole=="cell"?e.$anchor:Rs(e.$head)||o5(e.$head)}function o5(n){for(let e=n.nodeAfter,t=n.pos;e;e=e.firstChild,t++){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t)}for(let e=n.nodeBefore,t=n.pos;e;e=e.lastChild,t--){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t-e.nodeSize)}}function ch(n){return n.parent.type.spec.tableRole=="row"&&n.nodeAfter}function l5(n){return n.node(0).resolve(n.pos+n.nodeAfter.nodeSize)}function uh(n,e){return n.depth==e.depth&&n.pos>=e.start(-1)&&n.pos<=e.end(-1)}function vv(n,e,t){let r=n.start(-1),s=et.get(n.node(-1)).nextCell(n.pos-r,e,t);return s==null?null:n.node(0).resolve(r+s)}function wt(n,e,t){let r={};for(let i in n)r[i]=n[i];return r[e]=t,r}function _i(n,e,t=1){let r=wt(n,"colspan",n.colspan-t);return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,t),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}function wv(n,e,t=1){let r=wt(n,"colspan",n.colspan+t);if(r.colwidth){r.colwidth=r.colwidth.slice();for(let i=0;i<t;i++)r.colwidth.splice(e,0,0)}return r}function a5(n,e,t){let r=Mt(e.type.schema).header_cell;for(let i=0;i<n.height;i++)if(e.nodeAt(n.map[t+i*n.width]).type!=r)return!1;return!0}class Se extends ue{constructor(e,t=e){let r=e.node(-1),i=et.get(r),s=e.start(-1),o=i.rectBetween(e.pos-s,t.pos-s),l=e.node(0),a=i.cellsInRect(o).filter(u=>u!=t.pos-s);a.unshift(t.pos-s);let c=a.map(u=>{let d=r.nodeAt(u),f=u+s+1;return new Jc(l.resolve(f),l.resolve(f+d.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=e,this.$headCell=t}map(e,t){let r=e.resolve(t.map(this.$anchorCell.pos)),i=e.resolve(t.map(this.$headCell.pos));if(ch(r)&&ch(i)&&uh(r,i)){let s=this.$anchorCell.node(-1)!=r.node(-1);return s&&this.isRowSelection()?Se.rowSelection(r,i):s&&this.isColSelection()?Se.colSelection(r,i):new Se(r,i)}return ce.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=et.get(e),r=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),s={},o=[];for(let a=i.top;a<i.bottom;a++){let c=[];for(let u=a*t.width+i.left,d=i.left;d<i.right;d++,u++){let f=t.map[u];if(!s[f]){s[f]=!0;let h=t.findCell(f),p=e.nodeAt(f),g=i.left-h.left,v=h.right-i.right;if(g>0||v>0){let w=p.attrs;g>0&&(w=_i(w,0,g)),v>0&&(w=_i(w,w.colspan-v,v)),h.left<i.left?p=p.type.createAndFill(w):p=p.type.create(w,p.content)}if(h.top<i.top||h.bottom>i.bottom){let w=wt(p.attrs,"rowspan",Math.min(h.bottom,i.bottom)-Math.max(h.top,i.top));h.top<i.top?p=p.type.createAndFill(w):p=p.type.create(w,p.content)}c.push(p)}}o.push(e.child(a).copy(W.from(c)))}const l=this.isColSelection()&&this.isRowSelection()?e:o;return new Y(W.from(l),1,1)}replace(e,t=Y.empty){let r=e.steps.length,i=this.ranges;for(let o=0;o<i.length;o++){let{$from:l,$to:a}=i[o],c=e.mapping.slice(r);e.replace(c.map(l.pos),c.map(a.pos),o?Y.empty:t)}let s=ue.findFrom(e.doc.resolve(e.mapping.slice(r).map(this.to)),-1);s&&e.setSelection(s)}replaceWith(e,t){this.replace(e,new Y(W.from(t),0,0))}forEachCell(e){let t=this.$anchorCell.node(-1),r=et.get(t),i=this.$anchorCell.start(-1),s=r.cellsInRect(r.rectBetween(this.$anchorCell.pos-i,this.$headCell.pos-i));for(let o=0;o<s.length;o++)e(t.nodeAt(s[o]),i+s[o])}isColSelection(){let e=this.$anchorCell.index(-1),t=this.$headCell.index(-1);if(Math.min(e,t)>0)return!1;let r=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(e,t=e){let r=et.get(e.node(-1)),i=e.start(-1),s=r.findCell(e.pos-i),o=r.findCell(t.pos-i),l=e.node(0);return s.top<=o.top?(s.top>0&&(e=l.resolve(i+r.map[s.left])),o.bottom<r.height&&(t=l.resolve(i+r.map[r.width*(r.height-1)+o.right-1]))):(o.top>0&&(t=l.resolve(i+r.map[o.left])),s.bottom<r.height&&(e=l.resolve(i+r.map[r.width*(r.height-1)+s.right-1]))),new Se(e,t)}isRowSelection(){let e=et.get(this.$anchorCell.node(-1)),t=this.$anchorCell.start(-1),r=e.colCount(this.$anchorCell.pos-t),i=e.colCount(this.$headCell.pos-t);if(Math.min(r,i)>0)return!1;let s=r+this.$anchorCell.nodeAfter.attrs.colspan,o=i+this.$headCell.nodeAfter.attrs.colspan;return Math.max(s,o)==e.width}eq(e){return e instanceof Se&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,t=e){let r=et.get(e.node(-1)),i=e.start(-1),s=r.findCell(e.pos-i),o=r.findCell(t.pos-i),l=e.node(0);return s.left<=o.left?(s.left>0&&(e=l.resolve(i+r.map[s.top*r.width])),o.right<r.width&&(t=l.resolve(i+r.map[r.width*(o.top+1)-1]))):(o.left>0&&(t=l.resolve(i+r.map[o.top*r.width])),s.right<r.width&&(e=l.resolve(i+r.map[r.width*(s.top+1)-1]))),new Se(e,t)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(e,t){return new Se(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){return new Se(e.resolve(t),e.resolve(r))}getBookmark(){return new dh(this.$anchorCell.pos,this.$headCell.pos)}}Se.prototype.visible=!1,ue.jsonID("cell",Se);class dh{constructor(e,t){this.anchor=e,this.head=t}map(e){return new dh(e.map(this.anchor),e.map(this.head))}resolve(e){let t=e.resolve(this.anchor),r=e.resolve(this.head);return t.parent.type.spec.tableRole=="row"&&r.parent.type.spec.tableRole=="row"&&t.index()<t.parent.childCount&&r.index()<r.parent.childCount&&uh(t,r)?new Se(t,r):ue.near(r,1)}}function c5(n){if(!(n.selection instanceof Se))return null;let e=[];return n.selection.forEachCell((t,r)=>{e.push(ut.node(r,r+t.nodeSize,{class:"selectedCell"}))}),He.create(n.doc,e)}function u5({$from:n,$to:e}){if(n.pos==e.pos||n.pos<n.pos-6)return!1;let t=n.pos,r=e.pos,i=n.depth;for(;i>=0&&!(n.after(i+1)<n.end(i));i--,t++);for(let s=e.depth;s>=0&&!(e.before(s+1)>e.start(s));s--,r--);return t==r&&/row|table/.test(n.node(i).type.spec.tableRole)}function d5({$from:n,$to:e}){let t,r;for(let i=n.depth;i>0;i--){let s=n.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){t=s;break}}for(let i=e.depth;i>0;i--){let s=e.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){r=s;break}}return t!==r&&e.parentOffset===0}function f5(n,e,t){let r=(e||n).selection,i=(e||n).doc,s,o;if(r instanceof se&&(o=r.node.type.spec.tableRole)){if(o=="cell"||o=="header_cell")s=Se.create(i,r.from);else if(o=="row"){let l=i.resolve(r.from+1);s=Se.rowSelection(l,l)}else if(!t){let l=et.get(r.node),a=r.from+1,c=a+l.map[l.width*l.height-1];s=Se.create(i,a+1,c)}}else r instanceof ce&&u5(r)?s=ce.create(i,r.from):r instanceof ce&&d5(r)&&(s=ce.create(i,r.$from.start(),r.$from.end()));return s&&(e||(e=n.tr)).setSelection(s),e}function h5(n){if(!n.size)return null;let{content:e,openStart:t,openEnd:r}=n;for(;e.childCount==1&&(t>0&&r>0||e.firstChild.type.spec.tableRole=="table");)t--,r--,e=e.firstChild.content;let i=e.firstChild,s=i.type.spec.tableRole,o=i.type.schema,l=[];if(s=="row")for(let a=0;a<e.childCount;a++){let c=e.child(a).content,u=a?0:Math.max(0,t-1),d=a<e.childCount-1?0:Math.max(0,r-1);(u||d)&&(c=fh(Mt(o).row,new Y(c,u,d)).content),l.push(c)}else if(s=="cell"||s=="header_cell")l.push(t||r?fh(Mt(o).row,new Y(e,t,r)).content:e);else return null;return p5(o,l)}function p5(n,e){let t=[];for(let i=0;i<e.length;i++){let s=e[i];for(let o=s.childCount-1;o>=0;o--){let{rowspan:l,colspan:a}=s.child(o).attrs;for(let c=i;c<i+l;c++)t[c]=(t[c]||0)+a}}let r=0;for(let i=0;i<t.length;i++)r=Math.max(r,t[i]);for(let i=0;i<t.length;i++)if(i>=e.length&&e.push(W.empty),t[i]<r){let s=Mt(n).cell.createAndFill(),o=[];for(let l=t[i];l<r;l++)o.push(s);e[i]=e[i].append(W.from(o))}return{height:e.length,width:r,rows:e}}function fh(n,e){let t=n.createAndFill();return new qc(t).replace(0,t.content.size,e).doc}function m5({width:n,height:e,rows:t},r,i){if(n!=r){let s=[],o=[];for(let l=0;l<t.length;l++){let a=t[l],c=[];for(let u=s[l]||0,d=0;u<r;d++){let f=a.child(d%a.childCount);u+f.attrs.colspan>r&&(f=f.type.create(_i(f.attrs,f.attrs.colspan,u+f.attrs.colspan-r),f.content)),c.push(f),u+=f.attrs.colspan;for(let h=1;h<f.attrs.rowspan;h++)s[l+h]=(s[l+h]||0)+f.attrs.colspan}o.push(W.from(c))}t=o,n=r}if(e!=i){let s=[];for(let o=0,l=0;o<i;o++,l++){let a=[],c=t[l%e];for(let u=0;u<c.childCount;u++){let d=c.child(u);o+d.attrs.rowspan>i&&(d=d.type.create(wt(d.attrs,"rowspan",Math.max(1,i-d.attrs.rowspan)),d.content)),a.push(d)}s.push(W.from(a))}t=s,e=i}return{width:n,height:e,rows:t}}function g5(n,e,t,r,i,s,o){let l=n.doc.type.schema,a=Mt(l),c,u;if(i>e.width)for(let d=0,f=0;d<e.height;d++){let h=t.child(d);f+=h.nodeSize;let p=[],g;h.lastChild==null||h.lastChild.type==a.cell?g=c||(c=a.cell.createAndFill()):g=u||(u=a.header_cell.createAndFill());for(let v=e.width;v<i;v++)p.push(g);n.insert(n.mapping.slice(o).map(f-1+r),p)}if(s>e.height){let d=[];for(let p=0,g=(e.height-1)*e.width;p<Math.max(e.width,i);p++){let v=p>=e.width?!1:t.nodeAt(e.map[g+p]).type==a.header_cell;d.push(v?u||(u=a.header_cell.createAndFill()):c||(c=a.cell.createAndFill()))}let f=a.row.create(null,W.from(d)),h=[];for(let p=e.height;p<s;p++)h.push(f);n.insert(n.mapping.slice(o).map(r+t.nodeSize-2),h)}return!!(c||u)}function Cv(n,e,t,r,i,s,o,l){if(o==0||o==e.height)return!1;let a=!1;for(let c=i;c<s;c++){let u=o*e.width+c,d=e.map[u];if(e.map[u-e.width]==d){a=!0;let f=t.nodeAt(d),{top:h,left:p}=e.findCell(d);n.setNodeMarkup(n.mapping.slice(l).map(d+r),null,wt(f.attrs,"rowspan",o-h)),n.insert(n.mapping.slice(l).map(e.positionAt(o,p,t)),f.type.createAndFill(wt(f.attrs,"rowspan",h+f.attrs.rowspan-o))),c+=f.attrs.colspan-1}}return a}function xv(n,e,t,r,i,s,o,l){if(o==0||o==e.width)return!1;let a=!1;for(let c=i;c<s;c++){let u=c*e.width+o,d=e.map[u];if(e.map[u-1]==d){a=!0;let f=t.nodeAt(d),h=e.colCount(d),p=n.mapping.slice(l).map(d+r);n.setNodeMarkup(p,null,_i(f.attrs,o-h,f.attrs.colspan-(o-h))),n.insert(p+f.nodeSize,f.type.createAndFill(_i(f.attrs,0,o-h))),c+=f.attrs.rowspan-1}}return a}function kv(n,e,t,r,i){let s=t?n.doc.nodeAt(t-1):n.doc,o=et.get(s),{top:l,left:a}=r,c=a+i.width,u=l+i.height,d=n.tr,f=0;function h(){s=t?d.doc.nodeAt(t-1):d.doc,o=et.get(s),f=d.mapping.maps.length}g5(d,o,s,t,c,u,f)&&h(),Cv(d,o,s,t,a,c,l,f)&&h(),Cv(d,o,s,t,a,c,u,f)&&h(),xv(d,o,s,t,l,u,a,f)&&h(),xv(d,o,s,t,l,u,c,f)&&h();for(let p=l;p<u;p++){let g=o.positionAt(p,a,s),v=o.positionAt(p,c,s);d.replace(d.mapping.slice(f).map(g+t),d.mapping.slice(f).map(v+t),new Y(i.rows[p-l],0,0))}h(),d.setSelection(new Se(d.doc.resolve(t+o.positionAt(l,a,s)),d.doc.resolve(t+o.positionAt(u-1,c-1,s)))),e(d)}const y5=ku({ArrowLeft:Ac("horiz",-1),ArrowRight:Ac("horiz",1),ArrowUp:Ac("vert",-1),ArrowDown:Ac("vert",1),"Shift-ArrowLeft":Mc("horiz",-1),"Shift-ArrowRight":Mc("horiz",1),"Shift-ArrowUp":Mc("vert",-1),"Shift-ArrowDown":Mc("vert",1),Backspace:Oc,"Mod-Backspace":Oc,Delete:Oc,"Mod-Delete":Oc});function Tc(n,e,t){return t.eq(n.selection)?!1:(e&&e(n.tr.setSelection(t).scrollIntoView()),!0)}function Ac(n,e){return(t,r,i)=>{let s=t.selection;if(s instanceof Se)return Tc(t,r,ue.near(s.$headCell,e));if(n!="horiz"&&!s.empty)return!1;let o=Sv(i,n,e);if(o==null)return!1;if(n=="horiz")return Tc(t,r,ue.near(t.doc.resolve(s.head+e),e));{let l=t.doc.resolve(o),a=vv(l,n,e),c;return a?c=ue.near(a,1):e<0?c=ue.near(t.doc.resolve(l.before(-1)),-1):c=ue.near(t.doc.resolve(l.after(-1)),1),Tc(t,r,c)}}}function Mc(n,e){return(t,r,i)=>{let s=t.selection;if(!(s instanceof Se)){let l=Sv(i,n,e);if(l==null)return!1;s=new Se(t.doc.resolve(l))}let o=vv(s.$headCell,n,e);return o?Tc(t,r,new Se(s.$anchorCell,o)):!1}}function Oc(n,e){let t=n.selection;if(!(t instanceof Se))return!1;if(e){let r=n.tr,i=Mt(n.schema).cell.createAndFill().content;t.forEachCell((s,o)=>{s.content.eq(i)||r.replace(r.mapping.map(o+1),r.mapping.map(o+s.nodeSize-1),new Y(i,0,0))}),r.docChanged&&e(r)}return!0}function b5(n,e){let t=n.state.doc,r=Rs(t.resolve(e));return r?(n.dispatch(n.state.tr.setSelection(new Se(r))),!0):!1}function v5(n,e,t){if(!Tn(n.state))return!1;let r=h5(t),i=n.state.selection;if(i instanceof Se){r||(r={width:1,height:1,rows:[W.from(fh(Mt(n.state.schema).cell,t))]});let s=i.$anchorCell.node(-1),o=i.$anchorCell.start(-1),l=et.get(s).rectBetween(i.$anchorCell.pos-o,i.$headCell.pos-o);return r=m5(r,l.right-l.left,l.bottom-l.top),kv(n.state,n.dispatch,o,l,r),!0}else if(r){let s=Ec(n.state),o=s.start(-1);return kv(n.state,n.dispatch,o,et.get(s.node(-1)).findCell(s.pos-o),r),!0}else return!1}function w5(n,e){if(e.ctrlKey||e.metaKey)return;let t=Ev(n,e.target),r;if(e.shiftKey&&n.state.selection instanceof Se)i(n.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&t&&(r=Rs(n.state.selection.$anchor))!=null&&hh(n,e).pos!=r.pos)i(r,e),e.preventDefault();else if(!t)return;function i(l,a){let c=hh(n,a),u=Gr.getState(n.state)==null;if(!c||!uh(l,c))if(u)c=l;else return;let d=new Se(l,c);if(u||!n.state.selection.eq(d)){let f=n.state.tr.setSelection(d);u&&f.setMeta(Gr,l.pos),n.dispatch(f)}}function s(){n.root.removeEventListener("mouseup",s),n.root.removeEventListener("dragstart",s),n.root.removeEventListener("mousemove",o),Gr.getState(n.state)!=null&&n.dispatch(n.state.tr.setMeta(Gr,-1))}function o(l){let a=Gr.getState(n.state),c;if(a!=null)c=n.state.doc.resolve(a);else if(Ev(n,l.target)!=t&&(c=hh(n,e),!c))return s();c&&i(c,l)}n.root.addEventListener("mouseup",s),n.root.addEventListener("dragstart",s),n.root.addEventListener("mousemove",o)}function Sv(n,e,t){if(!(n.state.selection instanceof ce))return null;let{$head:r}=n.state.selection;for(let i=r.depth-1;i>=0;i--){let s=r.node(i);if((t<0?r.index(i):r.indexAfter(i))!=(t<0?0:s.childCount))return null;if(s.type.spec.tableRole=="cell"||s.type.spec.tableRole=="header_cell"){let l=r.before(i),a=e=="vert"?t>0?"down":"up":t>0?"right":"left";return n.endOfTextblock(a)?l:null}}return null}function Ev(n,e){for(;e&&e!=n.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e}function hh(n,e){let t=n.posAtCoords({left:e.clientX,top:e.clientY});return t&&t?Rs(n.state.doc.resolve(t.pos)):null}const C5=new We("fix-tables");function Tv(n,e,t,r){let i=n.childCount,s=e.childCount;e:for(let o=0,l=0;o<s;o++){let a=e.child(o);for(let c=l,u=Math.min(i,o+3);c<u;c++)if(n.child(c)==a){l=c+1,t+=a.nodeSize;continue e}r(a,t),l<i&&n.child(l).sameMarkup(a)?Tv(n.child(l),a,t+1,r):a.nodesBetween(0,a.content.size,r,t+1),t+=a.nodeSize}}function Av(n,e){let t,r=(i,s)=>{i.type.spec.tableRole=="table"&&(t=x5(n,i,s,t))};return e?e.doc!=n.doc&&Tv(e.doc,n.doc,0,r):n.doc.descendants(r),t}function x5(n,e,t,r){let i=et.get(e);if(!i.problems)return r;r||(r=n.tr);let s=[];for(let a=0;a<i.height;a++)s.push(0);for(let a=0;a<i.problems.length;a++){let c=i.problems[a];if(c.type=="collision"){let u=e.nodeAt(c.pos);for(let d=0;d<u.attrs.rowspan;d++)s[c.row+d]+=c.n;r.setNodeMarkup(r.mapping.map(t+1+c.pos),null,_i(u.attrs,u.attrs.colspan-c.n,c.n))}else if(c.type=="missing")s[c.row]+=c.n;else if(c.type=="overlong_rowspan"){let u=e.nodeAt(c.pos);r.setNodeMarkup(r.mapping.map(t+1+c.pos),null,wt(u.attrs,"rowspan",u.attrs.rowspan-c.n))}else if(c.type=="colwidth mismatch"){let u=e.nodeAt(c.pos);r.setNodeMarkup(r.mapping.map(t+1+c.pos),null,wt(u.attrs,"colwidth",c.colwidth))}}let o,l;for(let a=0;a<s.length;a++)s[a]&&(o==null&&(o=a),l=a);for(let a=0,c=t+1;a<i.height;a++){let u=e.child(a),d=c+u.nodeSize,f=s[a];if(f>0){let h="cell";u.firstChild&&(h=u.firstChild.type.spec.tableRole);let p=[];for(let v=0;v<f;v++)p.push(Mt(n.schema)[h].createAndFill());let g=(a==0||o==a-1)&&l==a?c+1:d-1;r.insert(r.mapping.map(g),p)}c=d}return r.setMeta(C5,{fixTables:!0})}function Xn(n){let e=n.selection,t=Ec(n),r=t.node(-1),i=t.start(-1),s=et.get(r),o;return e instanceof Se?o=s.rectBetween(e.$anchorCell.pos-i,e.$headCell.pos-i):o=s.findCell(t.pos-i),o.tableStart=i,o.map=s,o.table=r,o}function Mv(n,{map:e,tableStart:t,table:r},i){let s=i>0?-1:0;a5(e,r,i+s)&&(s=i==0||i==e.width?null:0);for(let o=0;o<e.height;o++){let l=o*e.width+i;if(i>0&&i<e.width&&e.map[l-1]==e.map[l]){let a=e.map[l],c=r.nodeAt(a);n.setNodeMarkup(n.mapping.map(t+a),null,wv(c.attrs,i-e.colCount(a))),o+=c.attrs.rowspan-1}else{let a=s==null?Mt(r.type.schema).cell:r.nodeAt(e.map[l+s]).type,c=e.positionAt(o,i,r);n.insert(n.mapping.map(t+c),a.createAndFill())}}return n}function k5(n,e){if(!Tn(n))return!1;if(e){let t=Xn(n);e(Mv(n.tr,t,t.left))}return!0}function S5(n,e){if(!Tn(n))return!1;if(e){let t=Xn(n);e(Mv(n.tr,t,t.right))}return!0}function E5(n,{map:e,table:t,tableStart:r},i){let s=n.mapping.maps.length;for(let o=0;o<e.height;){let l=o*e.width+i,a=e.map[l],c=t.nodeAt(a);if(i>0&&e.map[l-1]==a||i<e.width-1&&e.map[l+1]==a)n.setNodeMarkup(n.mapping.slice(s).map(r+a),null,_i(c.attrs,i-e.colCount(a)));else{let u=n.mapping.slice(s).map(r+a);n.delete(u,u+c.nodeSize)}o+=c.attrs.rowspan}}function T5(n,e){if(!Tn(n))return!1;if(e){let t=Xn(n),r=n.tr;if(t.left==0&&t.right==t.map.width)return!1;for(let i=t.right-1;E5(r,t,i),i!=t.left;i--)t.table=t.tableStart?r.doc.nodeAt(t.tableStart-1):r.doc,t.map=et.get(t.table);e(r)}return!0}function A5(n,e,t){let r=Mt(e.type.schema).header_cell;for(let i=0;i<n.width;i++)if(e.nodeAt(n.map[i+t*n.width]).type!=r)return!1;return!0}function Ov(n,{map:e,tableStart:t,table:r},i){let s=t;for(let a=0;a<i;a++)s+=r.child(a).nodeSize;let o=[],l=i>0?-1:0;A5(e,r,i+l)&&(l=i==0||i==e.height?null:0);for(let a=0,c=e.width*i;a<e.width;a++,c++)if(i>0&&i<e.height&&e.map[c]==e.map[c-e.width]){let u=e.map[c],d=r.nodeAt(u).attrs;n.setNodeMarkup(t+u,null,wt(d,"rowspan",d.rowspan+1)),a+=d.colspan-1}else{let u=l==null?Mt(r.type.schema).cell:r.nodeAt(e.map[c+l*e.width]).type;o.push(u.createAndFill())}return n.insert(s,Mt(r.type.schema).row.create(null,o)),n}function M5(n,e){if(!Tn(n))return!1;if(e){let t=Xn(n);e(Ov(n.tr,t,t.top))}return!0}function O5(n,e){if(!Tn(n))return!1;if(e){let t=Xn(n);e(Ov(n.tr,t,t.bottom))}return!0}function _5(n,{map:e,table:t,tableStart:r},i){let s=0;for(let a=0;a<i;a++)s+=t.child(a).nodeSize;let o=s+t.child(i).nodeSize,l=n.mapping.maps.length;n.delete(s+r,o+r);for(let a=0,c=i*e.width;a<e.width;a++,c++){let u=e.map[c];if(i>0&&u==e.map[c-e.width]){let d=t.nodeAt(u).attrs;n.setNodeMarkup(n.mapping.slice(l).map(u+r),null,wt(d,"rowspan",d.rowspan-1)),a+=d.colspan-1}else if(i<e.width&&u==e.map[c+e.width]){let d=t.nodeAt(u),f=d.type.create(wt(d.attrs,"rowspan",d.attrs.rowspan-1),d.content),h=e.positionAt(i+1,a,t);n.insert(n.mapping.slice(l).map(r+h),f),a+=d.attrs.colspan-1}}}function N5(n,e){if(!Tn(n))return!1;if(e){let t=Xn(n),r=n.tr;if(t.top==0&&t.bottom==t.map.height)return!1;for(let i=t.bottom-1;_5(r,t,i),i!=t.top;i--)t.table=t.tableStart?r.doc.nodeAt(t.tableStart-1):r.doc,t.map=et.get(t.table);e(r)}return!0}function _v(n){let e=n.content;return e.childCount==1&&e.firstChild.isTextblock&&e.firstChild.childCount==0}function D5({width:n,height:e,map:t},r){let i=r.top*n+r.left,s=i,o=(r.bottom-1)*n+r.left,l=i+(r.right-r.left-1);for(let a=r.top;a<r.bottom;a++){if(r.left>0&&t[s]==t[s-1]||r.right<n&&t[l]==t[l+1])return!0;s+=n,l+=n}for(let a=r.left;a<r.right;a++){if(r.top>0&&t[i]==t[i-n]||r.bottom<e&&t[o]==t[o+n])return!0;i++,o++}return!1}function Nv(n,e){let t=n.selection;if(!(t instanceof Se)||t.$anchorCell.pos==t.$headCell.pos)return!1;let r=Xn(n),{map:i}=r;if(D5(i,r))return!1;if(e){let s=n.tr,o={},l=W.empty,a,c;for(let u=r.top;u<r.bottom;u++)for(let d=r.left;d<r.right;d++){let f=i.map[u*i.width+d],h=r.table.nodeAt(f);if(!o[f])if(o[f]=!0,a==null)a=f,c=h;else{_v(h)||(l=l.append(h.content));let p=s.mapping.map(f+r.tableStart);s.delete(p,p+h.nodeSize)}}if(s.setNodeMarkup(a+r.tableStart,null,wt(wv(c.attrs,c.attrs.colspan,r.right-r.left-c.attrs.colspan),"rowspan",r.bottom-r.top)),l.size){let u=a+1+c.content.size,d=_v(c)?a+1:u;s.replaceWith(d+r.tableStart,u+r.tableStart,l)}s.setSelection(new Se(s.doc.resolve(a+r.tableStart))),e(s)}return!0}function Dv(n,e){const t=Mt(n.schema);return R5(({node:r})=>t[r.type.spec.tableRole])(n,e)}function R5(n){return(e,t)=>{let r=e.selection,i,s;if(r instanceof Se){if(r.$anchorCell.pos!=r.$headCell.pos)return!1;i=r.$anchorCell.nodeAfter,s=r.$anchorCell.pos}else{if(i=s5(r.$from),!i)return!1;s=Rs(r.$from).pos}if(i.attrs.colspan==1&&i.attrs.rowspan==1)return!1;if(t){let o=i.attrs,l=[],a=o.colwidth;o.rowspan>1&&(o=wt(o,"rowspan",1)),o.colspan>1&&(o=wt(o,"colspan",1));let c=Xn(e),u=e.tr;for(let f=0;f<c.right-c.left;f++)l.push(a?wt(o,"colwidth",a&&a[f]?[a[f]]:null):o);let d;for(let f=c.top;f<c.bottom;f++){let h=c.map.positionAt(f,c.left,c.table);f==c.top&&(h+=i.nodeSize);for(let p=c.left,g=0;p<c.right;p++,g++)p==c.left&&f==c.top||u.insert(d=u.mapping.map(h+c.tableStart,1),n({node:i,row:f,col:p}).createAndFill(l[g]))}u.setNodeMarkup(s,n({node:i,row:c.top,col:c.left}),l[0]),r instanceof Se&&u.setSelection(new Se(u.doc.resolve(r.$anchorCell.pos),d&&u.doc.resolve(d))),t(u)}return!0}}function L5(n,e){return function(t,r){if(!Tn(t))return!1;let i=Ec(t);if(i.nodeAfter.attrs[n]===e)return!1;if(r){let s=t.tr;t.selection instanceof Se?t.selection.forEachCell((o,l)=>{o.attrs[n]!==e&&s.setNodeMarkup(l,null,wt(o.attrs,n,e))}):s.setNodeMarkup(i.pos,null,wt(i.nodeAfter.attrs,n,e)),r(s)}return!0}}function I5(n){return function(e,t){if(!Tn(e))return!1;if(t){let r=Mt(e.schema),i=Xn(e),s=e.tr,o=i.map.cellsInRect(n=="column"?new Ds(i.left,0,i.right,i.map.height):n=="row"?new Ds(0,i.top,i.map.width,i.bottom):i),l=o.map(a=>i.table.nodeAt(a));for(let a=0;a<o.length;a++)l[a].type==r.header_cell&&s.setNodeMarkup(i.tableStart+o[a],r.cell,l[a].attrs);if(s.steps.length==0)for(let a=0;a<o.length;a++)s.setNodeMarkup(i.tableStart+o[a],r.header_cell,l[a].attrs);t(s)}return!0}}function Rv(n,e,t){const r=e.map.cellsInRect({left:0,top:0,right:n=="row"?e.map.width:1,bottom:n=="column"?e.map.height:1});for(let i=0;i<r.length;i++){const s=e.table.nodeAt(r[i]);if(s&&s.type!==t.header_cell)return!1}return!0}function Zo(n,e){return e=e||{useDeprecatedLogic:!1},e.useDeprecatedLogic?I5(n):function(t,r){if(!Tn(t))return!1;if(r){let i=Mt(t.schema),s=Xn(t),o=t.tr,l=Rv("row",s,i),a=Rv("column",s,i),u=(n==="column"?l:n==="row"?a:!1)?1:0,d=n=="column"?new Ds(0,u,1,s.map.height):n=="row"?new Ds(u,0,s.map.width,1):s,f=n=="column"?a?i.cell:i.header_cell:n=="row"?l?i.cell:i.header_cell:i.cell;s.map.cellsInRect(d).forEach(h=>{const p=h+s.tableStart,g=o.doc.nodeAt(p);g&&o.setNodeMarkup(p,f,g.attrs)}),r(o)}return!0}}Zo("row",{useDeprecatedLogic:!0}),Zo("column",{useDeprecatedLogic:!0});let P5=Zo("cell",{useDeprecatedLogic:!0});function F5(n,e){if(e<0){let t=n.nodeBefore;if(t)return n.pos-t.nodeSize;for(let r=n.index(-1)-1,i=n.before();r>=0;r--){let s=n.node(-1).child(r);if(s.childCount)return i-1-s.lastChild.nodeSize;i-=s.nodeSize}}else{if(n.index()<n.parent.childCount-1)return n.pos+n.nodeAfter.nodeSize;let t=n.node(-1);for(let r=n.indexAfter(-1),i=n.after();r<t.childCount;r++){let s=t.child(r);if(s.childCount)return i+1;i+=s.nodeSize}}}function Lv(n){return function(e,t){if(!Tn(e))return!1;let r=F5(Ec(e),n);if(r!=null){if(t){let i=e.doc.resolve(r);t(e.tr.setSelection(ce.between(i,l5(i))).scrollIntoView())}return!0}}}function B5(n,e){let t=n.selection.$anchor;for(let r=t.depth;r>0;r--)if(t.node(r).type.spec.tableRole=="table")return e&&e(n.tr.delete(t.before(r),t.after(r)).scrollIntoView()),!0;return!1}let $5=class{constructor(e,t){this.node=e,this.cellMinWidth=t,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")),ph(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(e){return e.type!=this.node.type?!1:(this.node=e,ph(e,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(e){return e.type=="attributes"&&(e.target==this.table||this.colgroup.contains(e.target))}};function ph(n,e,t,r,i,s){let o=0,l=!0,a=e.firstChild,c=n.firstChild;for(let u=0,d=0;u<c.childCount;u++){let{colspan:f,colwidth:h}=c.child(u).attrs;for(let p=0;p<f;p++,d++){let g=i==d?s:h&&h[p],v=g?g+"px":"";o+=g||r,g||(l=!1),a?(a.style.width!=v&&(a.style.width=v),a=a.nextSibling):e.appendChild(document.createElement("col")).style.width=v}}for(;a;){let u=a.nextSibling;a.parentNode.removeChild(a),a=u}l?(t.style.width=o+"px",t.style.minWidth=""):(t.style.width="",t.style.minWidth=o+"px")}const mn=new We("tableColumnResizing");function j5({handleWidth:n=5,cellMinWidth:e=25,View:t=$5,lastColumnResizable:r=!0}={}){return new je({key:mn,state:{init(s,o){return this.spec.props.nodeViews[Mt(o.schema).table.name]=(l,a)=>new t(l,e,a),new Xo(-1,!1)},apply(s,o){return o.apply(s)}},props:{attributes(s){return mn.getState(s).activeHandle>-1?{class:"resize-cursor"}:null},handleDOMEvents:{mousemove(s,o){H5(s,o,n,e,r)},mouseleave(s){V5(s)},mousedown(s,o){z5(s,o,e)}},decorations(s){let o=mn.getState(s);if(o.activeHandle>-1)return G5(s,o.activeHandle)},nodeViews:{}}})}class Xo{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(e){let t=this,r=e.getMeta(mn);if(r&&r.setHandle!=null)return new Xo(r.setHandle,null);if(r&&r.setDragging!==void 0)return new Xo(t.activeHandle,r.setDragging);if(t.activeHandle>-1&&e.docChanged){let i=e.mapping.map(t.activeHandle,-1);ch(e.doc.resolve(i))||(i=null),t=new Xo(i,t.dragging)}return t}}function H5(n,e,t,r,i){let s=mn.getState(n.state);if(!s.dragging){let o=W5(e.target),l=-1;if(o){let{left:a,right:c}=o.getBoundingClientRect();e.clientX-a<=t?l=Iv(n,e,"left"):c-e.clientX<=t&&(l=Iv(n,e,"right"))}if(l!=s.activeHandle){if(!i&&l!==-1){let a=n.state.doc.resolve(l),c=a.node(-1),u=et.get(c),d=a.start(-1);if(u.colCount(a.pos-d)+a.nodeAfter.attrs.colspan-1==u.width-1)return}Fv(n,l)}}}function V5(n){let e=mn.getState(n.state);e.activeHandle>-1&&!e.dragging&&Fv(n,-1)}function z5(n,e,t){let r=mn.getState(n.state);if(r.activeHandle==-1||r.dragging)return!1;let i=n.state.doc.nodeAt(r.activeHandle),s=U5(n,r.activeHandle,i.attrs);n.dispatch(n.state.tr.setMeta(mn,{setDragging:{startX:e.clientX,startWidth:s}}));function o(a){window.removeEventListener("mouseup",o),window.removeEventListener("mousemove",l);let c=mn.getState(n.state);c.dragging&&(q5(n,c.activeHandle,Pv(c.dragging,a,t)),n.dispatch(n.state.tr.setMeta(mn,{setDragging:null})))}function l(a){if(!a.which)return o(a);let c=mn.getState(n.state),u=Pv(c.dragging,a,t);K5(n,c.activeHandle,u,t)}return window.addEventListener("mouseup",o),window.addEventListener("mousemove",l),e.preventDefault(),!0}function U5(n,e,{colspan:t,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let s=n.domAtPos(e),l=s.node.childNodes[s.offset].offsetWidth,a=t;if(r)for(let c=0;c<t;c++)r[c]&&(l-=r[c],a--);return l/a}function W5(n){for(;n&&n.nodeName!="TD"&&n.nodeName!="TH";)n=n.classList.contains("ProseMirror")?null:n.parentNode;return n}function Iv(n,e,t){let r=n.posAtCoords({left:e.clientX,top:e.clientY});if(!r)return-1;let{pos:i}=r,s=Rs(n.state.doc.resolve(i));if(!s)return-1;if(t=="right")return s.pos;let o=et.get(s.node(-1)),l=s.start(-1),a=o.map.indexOf(s.pos-l);return a%o.width==0?-1:l+o.map[a-1]}function Pv(n,e,t){let r=e.clientX-n.startX;return Math.max(t,n.startWidth+r)}function Fv(n,e){n.dispatch(n.state.tr.setMeta(mn,{setHandle:e}))}function q5(n,e,t){let r=n.state.doc.resolve(e),i=r.node(-1),s=et.get(i),o=r.start(-1),l=s.colCount(r.pos-o)+r.nodeAfter.attrs.colspan-1,a=n.state.tr;for(let c=0;c<s.height;c++){let u=c*s.width+l;if(c&&s.map[u]==s.map[u-s.width])continue;let d=s.map[u],{attrs:f}=i.nodeAt(d),h=f.colspan==1?0:l-s.colCount(d);if(f.colwidth&&f.colwidth[h]==t)continue;let p=f.colwidth?f.colwidth.slice():J5(f.colspan);p[h]=t,a.setNodeMarkup(o+d,null,wt(f,"colwidth",p))}a.docChanged&&n.dispatch(a)}function K5(n,e,t,r){let i=n.state.doc.resolve(e),s=i.node(-1),o=i.start(-1),l=et.get(s).colCount(i.pos-o)+i.nodeAfter.attrs.colspan-1,a=n.domAtPos(i.start(-1)).node;for(;a.nodeName!="TABLE";)a=a.parentNode;ph(s,a.firstChild,a,r,l,t)}function J5(n){let e=[];for(let t=0;t<n;t++)e.push(0);return e}function G5(n,e){let t=[],r=n.doc.resolve(e),i=r.node(-1),s=et.get(i),o=r.start(-1),l=s.colCount(r.pos-o)+r.nodeAfter.attrs.colspan;for(let a=0;a<s.height;a++){let c=l+a*s.width-1;if((l==s.width||s.map[c]!=s.map[c+1])&&(a==0||s.map[c-1]!=s.map[c-1-s.width])){let u=s.map[c],d=o+u+i.nodeAt(u).nodeSize-1,f=document.createElement("div");f.className="column-resize-handle",t.push(ut.widget(d,f))}}return He.create(n.doc,t)}function Y5({allowTableNodeSelection:n=!1}={}){return new je({key:Gr,state:{init(){return null},apply(e,t){let r=e.getMeta(Gr);if(r!=null)return r==-1?null:r;if(t==null||!e.docChanged)return t;let{deleted:i,pos:s}=e.mapping.mapResult(t);return i?null:s}},props:{decorations:c5,handleDOMEvents:{mousedown:w5},createSelectionBetween(e){if(Gr.getState(e.state)!=null)return e.state.selection},handleTripleClick:b5,handleKeyDown:y5,handlePaste:v5},appendTransaction(e,t,r){return f5(r,Av(r,t),n)}})}function Bv(n,e,t,r,i,s){var u;let o=0,l=!0,a=e.firstChild;const c=n.firstChild;if(c)for(let d=0,f=0;d<c.childCount;d+=1){const{colspan:h,colwidth:p}=c.child(d).attrs;for(let g=0;g<h;g+=1,f+=1){const v=i===f?s:p&&p[g],w=v?`${v}px`:"";o+=v||r,v||(l=!1),a?(a.style.width!==w&&(a.style.width=w),a=a.nextSibling):e.appendChild(document.createElement("col")).style.width=w}}for(;a;){const d=a.nextSibling;(u=a==null?void 0:a.parentNode)==null||u.removeChild(a),a=d}l?(t.style.width=`${o}px`,t.style.minWidth=""):(t.style.width="",t.style.minWidth=`${o}px`)}class Z5{constructor(e,t){vr(this,"node");vr(this,"cellMinWidth");vr(this,"dom");vr(this,"table");vr(this,"colgroup");vr(this,"contentDOM");this.node=e,this.cellMinWidth=t,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")),Bv(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(e){return e.type!==this.node.type?!1:(this.node=e,Bv(e,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(e){return e.type==="attributes"&&(e.target===this.table||this.colgroup.contains(e.target))}}function $v(n,e){return n.createAndFill()}function X5(n){if(n.cached.tableNodeTypes)return n.cached.tableNodeTypes;const e={};return Object.keys(n.nodes).forEach(t=>{const r=n.nodes[t];r.spec.tableRole&&(e[r.spec.tableRole]=r)}),n.cached.tableNodeTypes=e,e}function Q5(n,e,t,r,i){const s=X5(n),o=[],l=[];for(let c=0;c<t;c+=1){const u=$v(s.cell);if(u&&l.push(u),r){const d=$v(s.header_cell);d&&o.push(d)}}const a=[];for(let c=0;c<e;c+=1)a.push(s.row.createChecked(null,r&&c===0?o:l));return s.table.createChecked(null,a)}function eL(n){return n instanceof Se}const _c=({editor:n})=>{const{selection:e}=n.state;if(!eL(e))return!1;let t=0;const r=Ru(e.ranges[0].$from,s=>s.type.name==="table");return r==null||r.node.descendants(s=>{if(s.type.name==="table")return!1;["tableCell","tableHeader"].includes(s.type.name)&&(t+=1)}),t===e.ranges.length?(n.commands.deleteTable(),!0):!1},tL=Ve.create({name:"table",addOptions(){return{HTMLAttributes:{},resizable:!1,handleWidth:5,cellMinWidth:25,View:Z5,lastColumnResizable:!0,allowTableNodeSelection:!1}},content:"tableRow+",tableRole:"table",isolating:!0,group:"block",parseHTML(){return[{tag:"table"}]},renderHTML({node:n,HTMLAttributes:e}){let t=0,r=!0;try{n.content.firstChild.content.forEach(s=>{if(s.attrs.colwidth)s.attrs.colwidth.forEach(o=>{o?t+=o:(r=!1,t+=this.options.cellMinWidth)});else{r=!1;const o=s.attrs.colspan?s.attrs.colspan:1;t+=this.options.cellMinWidth*o}})}catch{r=!1}return r&&t>0?e.style=`width: ${t}px;`:t&&t>0?e.style=`min-width: ${t}px`:e.style=null,["div",{class:"table-wrapper"},["table",Ce(this.options.HTMLAttributes,e),["tbody",0]]]},addCommands(){return{insertTable:({rows:n=3,cols:e=3,withHeaderRow:t=!0}={})=>({tr:r,dispatch:i,editor:s})=>{const{selection:o}=r,l=Q5(s.schema,n,e,t);if(i){const a=r.selection.anchor+1;r.replaceRangeWith(o.from-1,o.to,l).scrollIntoView().setSelection(ce.near(r.doc.resolve(a)))}return!0},addColumnBefore:()=>({state:n,dispatch:e})=>k5(n,e),addColumnAfter:()=>({state:n,dispatch:e})=>S5(n,e),deleteColumn:()=>({state:n,dispatch:e})=>T5(n,e),addRowBefore:()=>({state:n,dispatch:e})=>M5(n,e),addRowAfter:()=>({state:n,dispatch:e})=>O5(n,e),deleteRow:()=>({state:n,dispatch:e})=>N5(n,e),deleteTable:()=>({state:n,dispatch:e})=>B5(n,e),mergeCells:()=>({state:n,dispatch:e})=>Nv(n,e),splitCell:()=>({state:n,dispatch:e})=>Dv(n,e),toggleHeaderColumn:()=>({state:n,dispatch:e})=>Zo("column")(n,e),toggleHeaderRow:()=>({state:n,dispatch:e})=>Zo("row")(n,e),toggleHeaderCell:()=>({state:n,dispatch:e})=>P5(n,e),mergeOrSplit:()=>({state:n,dispatch:e})=>Nv(n,e)?!0:Dv(n,e),setCellAttribute:(n,e)=>({state:t,dispatch:r})=>L5(n,e)(t,r),goToNextCell:()=>({state:n,dispatch:e})=>Lv(1)(n,e),goToPreviousCell:()=>({state:n,dispatch:e})=>Lv(-1)(n,e),fixTables:()=>({state:n,dispatch:e})=>(e&&Av(n),!0),setCellSelection:n=>({tr:e,dispatch:t})=>{if(t){const r=Se.create(e.doc,n.anchorCell,n.headCell);e.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:_c,"Mod-Backspace":_c,Delete:_c,"Mod-Delete":_c}},addProseMirrorPlugins(){return[...this.options.resizable&&this.editor.isEditable?[j5({handleWidth:this.options.handleWidth,cellMinWidth:this.options.cellMinWidth,View:this.options.View,lastColumnResizable:this.options.lastColumnResizable})]:[],Y5({allowTableNodeSelection:this.options.allowTableNodeSelection})]},extendNodeSchema(n){const e={name:n.name,options:n.options,storage:n.storage};return{tableRole:ge(re(n,"tableRole",e))}}});function jv(n,e){if(n==null)return{};var t={},r=Object.keys(n),i,s;for(s=0;s<r.length;s++)i=r[s],!(e.indexOf(i)>=0)&&(t[i]=n[i]);return t}var Hv=typeof window<"u"&&typeof document<"u";function mh(n,e){n&&(typeof n=="function"&&n(e),{}.hasOwnProperty.call(n,"current")&&(n.current=e))}function Vv(){return Hv&&document.createElement("div")}function nL(n){var e={"data-placement":n.placement};return n.referenceHidden&&(e["data-reference-hidden"]=""),n.escaped&&(e["data-escaped"]=""),e}function zv(n,e){if(n===e)return!0;if(typeof n=="object"&&n!=null&&typeof e=="object"&&e!=null){if(Object.keys(n).length!==Object.keys(e).length)return!1;for(var t in n)if(e.hasOwnProperty(t)){if(!zv(n[t],e[t]))return!1}else return!1;return!0}else return!1}function rL(n){var e=[];return n.forEach(function(t){e.find(function(r){return zv(t,r)})||e.push(t)}),e}function iL(n,e){var t,r;return Object.assign({},e,{popperOptions:Object.assign({},n.popperOptions,e.popperOptions,{modifiers:rL([].concat(((t=n.popperOptions)==null?void 0:t.modifiers)||[],((r=e.popperOptions)==null?void 0:r.modifiers)||[]))})})}var gh=Hv?O.useLayoutEffect:O.useEffect;function sL(n){var e=O.useRef();return e.current||(e.current=typeof n=="function"?n():n),e.current}function Uv(n,e,t){t.split(/\s+/).forEach(function(r){r&&n.classList[e](r)})}var oL={name:"className",defaultValue:"",fn:function(e){var t=e.popper.firstElementChild,r=function(){var l;return!!((l=e.props.render)!=null&&l.$$tippy)};function i(){if(e.props.className&&!r()){process.env.NODE_ENV!=="production"&&console.warn(["@tippyjs/react: Cannot use `className` prop in conjunction with","`render` prop. Place the className on the element you are","rendering."].join(" "));return}Uv(t,"add",e.props.className)}function s(){r()&&Uv(t,"remove",e.props.className)}return{onCreate:i,onBeforeUpdate:s,onAfterUpdate:i}}};function lL(n){function e(t){var r=t.children,i=t.content,s=t.visible,o=t.singleton,l=t.render,a=t.reference,c=t.disabled,u=c===void 0?!1:c,d=t.ignoreAttributes,f=d===void 0?!0:d;t.__source,t.__self;var h=jv(t,["children","content","visible","singleton","render","reference","disabled","ignoreAttributes","__source","__self"]),p=s!==void 0,g=o!==void 0,v=O.useState(!1),w=v[0],S=v[1],C=O.useState({}),y=C[0],k=C[1],E=O.useState(),T=E[0],N=E[1],_=sL(function(){return{container:Vv(),renders:1}}),A=Object.assign({ignoreAttributes:f},h,{content:_.container});p&&(process.env.NODE_ENV!=="production"&&["trigger","hideOnClick","showOnCreate"].forEach(function(V){A[V]!==void 0&&console.warn(["@tippyjs/react: Cannot specify `"+V+"` prop in","controlled mode (`visible` prop)"].join(" "))}),A.trigger="manual",A.hideOnClick=!1),g&&(u=!0);var R=A,P=A.plugins||[];l&&(R=Object.assign({},A,{plugins:g&&o.data!=null?[].concat(P,[{fn:function(){return{onTrigger:function(J,G){var ie=o.data.children.find(function(X){var we=X.instance;return we.reference===G.currentTarget});J.state.$$activeSingletonInstance=ie.instance,N(ie.content)}}}}]):P,render:function(){return{popper:_.container}}}));var $=[a].concat(r?[r.type]:[]);return gh(function(){var V=a;a&&a.hasOwnProperty("current")&&(V=a.current);var U=n(V||_.ref||Vv(),Object.assign({},R,{plugins:[oL].concat(A.plugins||[])}));return _.instance=U,u&&U.disable(),s&&U.show(),g&&o.hook({instance:U,content:i,props:R,setSingletonContent:N}),S(!0),function(){U.destroy(),o==null||o.cleanup(U)}},$),gh(function(){var V;if(_.renders===1){_.renders++;return}var U=_.instance;U.setProps(iL(U.props,R)),(V=U.popperInstance)==null||V.forceUpdate(),u?U.disable():U.enable(),p&&(s?U.show():U.hide()),g&&o.hook({instance:U,content:i,props:R,setSingletonContent:N})}),gh(function(){var V;if(l){var U=_.instance;U.setProps({popperOptions:Object.assign({},U.props.popperOptions,{modifiers:[].concat((((V=U.props.popperOptions)==null?void 0:V.modifiers)||[]).filter(function(J){var G=J.name;return G!=="$$tippyReact"}),[{name:"$$tippyReact",enabled:!0,phase:"beforeWrite",requires:["computeStyles"],fn:function(G){var ie,X=G.state,we=(ie=X.modifiersData)==null?void 0:ie.hide;(y.placement!==X.placement||y.referenceHidden!==(we==null?void 0:we.isReferenceHidden)||y.escaped!==(we==null?void 0:we.hasPopperEscaped))&&k({placement:X.placement,referenceHidden:we==null?void 0:we.isReferenceHidden,escaped:we==null?void 0:we.hasPopperEscaped}),X.attributes.popper={}}}])})})}},[y.placement,y.referenceHidden,y.escaped].concat($)),O.createElement(O.Fragment,null,r?O.cloneElement(r,{ref:function(U){_.ref=U,mh(r.ref,U)}}):null,w&&nn.createPortal(l?l(nL(y),T,_.instance):i,_.container))}return e}var aL=function(n,e){return O.forwardRef(function(r,i){var s=r.children,o=jv(r,["children"]);return O.createElement(n,Object.assign({},e,o),s?O.cloneElement(s,{ref:function(a){mh(i,a),mh(s.ref,a)}}):null)})},cL=aL(lL(fi));const uL=[{name:"Add row above",action:n=>n.chain().focus().addRowBefore().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M22 14a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v7h2v-2h4v2h2v-2h4v2h2v-2h4v2h2v-7M4 14h4v3H4v-3m6 0h4v3h-4v-3m10 0v3h-4v-3h4m-9-4h2V7h3V5h-3V2h-2v3H8v2h3v3Z"})})},{name:"Add row below",action:n=>n.chain().focus().addRowAfter().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M22 10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V3h2v2h4V3h2v2h4V3h2v2h4V3h2v7M4 10h4V7H4v3m6 0h4V7h-4v3m10 0V7h-4v3h4m-9 4h2v3h3v2h-3v3h-2v-3H8v-2h3v-3Z"})})},{name:"Add left column",action:n=>n.chain().focus().addColumnBefore().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M13 2a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h9V2h-9m7 8v4h-7v-4h7m0 6v4h-7v-4h7m0-12v4h-7V4h7M9 11H6V8H4v3H1v2h3v3h2v-3h3v-2Z"})})},{name:"Add right column",action:n=>n.chain().focus().addColumnAfter().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M11 2a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H2V2h9m-7 8v4h7v-4H4m0 6v4h7v-4H4M4 4v4h7V4H4m11 7h3V8h2v3h3v2h-3v3h-2v-3h-3v-2Z"})})},{name:"Remove row",action:n=>n.chain().focus().deleteRow().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M9.41 13L12 15.59L14.59 13L16 14.41L13.41 17L16 19.59L14.59 21L12 18.41L9.41 21L8 19.59L10.59 17L8 14.41L9.41 13M22 9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v3M4 9h4V6H4v3m6 0h4V6h-4v3m6 0h4V6h-4v3Z"})})},{name:"Remove column",action:n=>n.chain().focus().deleteColumn().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M4 2h7a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2m0 8v4h7v-4H4m0 6v4h7v-4H4M4 4v4h7V4H4m13.59 8L15 9.41L16.41 8L19 10.59L21.59 8L23 9.41L20.41 12L23 14.59L21.59 16L19 13.41L16.41 16L15 14.59L17.59 12Z"})})},{name:"Toggle header row",action:n=>n.chain().focus().toggleHeaderRow().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M22 14a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-4a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v4M4 14h4v-4H4v4m6 0h4v-4h-4v4m6 0h4v-4h-4v4Z"})})},{name:"Toggle header column",action:n=>n.chain().focus().toggleHeaderColumn().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M8 2h8a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2m0 8v4h8v-4H8m0 6v4h8v-4H8M8 4v4h8V4H8Z"})})},{name:"Toggle header cell",action:n=>n.chain().focus().toggleHeaderCell().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M21 19a1 1 0 0 1-1 1h-1v-2h2v1m-6 1v-2h2v2h-2m-4 0v-2h2v2h-2m-4 0v-2h2v2H7m-3 0a1 1 0 0 1-1-1v-1h2v2H4M19 4H5a2 2 0 0 0-2 2v2h18V6c0-1.11-.89-2-2-2M5 14H3v2h2v-2m0-4H3v2h2v-2m16 0h-2v2h2v-2m0 4h-2v2h2v-2m-10 2v-2h2v2h-2m0-4v-2h2v2h-2"})})},{name:"Remove table",action:n=>n.chain().focus().deleteTable().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M12.35 20H10v-3h2.09c.12-.72.37-1.39.72-2H10v-3h4v1.54c.58-.54 1.25-.93 2-1.19V12h4v.35c.75.26 1.42.65 2 1.19V5c0-1.1-.9-2-2-2H4c-1.1 0-2 .9-2 2v15c0 1.1.9 2 2 2h9.54c-.54-.58-.93-1.25-1.19-2M16 7h4v3h-4V7m-6 0h4v3h-4V7M8 20H4v-3h4v3m0-5H4v-3h4v3m0-5H4V7h4v3m6.46 5.88l1.42-1.42L18 16.59l2.12-2.13l1.42 1.42L19.41 18l2.13 2.12l-1.42 1.42L18 19.41l-2.12 2.13l-1.42-1.42L16.59 18l-2.13-2.12"})})}],Wv=({node:n,getPos:e,selected:t,editor:r})=>{const[i,s]=O.useState(!1),o=Ul(),l=O.useRef(null),a=()=>{const{from:u,to:d}=r.state.selection,f=e(),h=f+n.nodeSize;s(f<=u&&d<=h)};O.useEffect(()=>(r.on("selectionUpdate",a),setTimeout(a,100),()=>{r.off("selectionUpdate",a)}));const c=()=>{var f,h;let u=(f=l.current)==null?void 0:f.clientTop;u&&(u+=5);let d=(h=l.current)==null?void 0:h.clientLeft;return d&&(d+=5),{top:`${u}px`,left:`${d}px`}};return D.jsxs(bo,{className:"group",children:[D.jsx(Kg,{as:"span"}),(i||t)&&D.jsx(cL,{appendTo:document.body,trigger:"click",interactive:!0,animation:"shift-toward-subtle",placement:"right-start",content:D.jsx("article",{className:"dropdown",contentEditable:!1,children:D.jsx("ul",{tabIndex:0,className:"dropdown-content fixed menu menu-compact p-2 shadow bg-base-100 rounded-box w-56",style:c(),children:uL.map(u=>D.jsx("li",{children:D.jsxs("button",{type:"button",className:"button",onClick:()=>u.action(r),children:[D.jsx("span",{children:u.icon}),D.jsx("span",{children:u.name})]})},u.name))})}),children:D.jsx("label",{tabIndex:0,className:Fe("trigger-button",{hidden:o}),contentEditable:!1,children:D.jsx(GE,{fontSize:"small"})})})]})},dL=Ve.create({name:"tableCell",addOptions(){return{HTMLAttributes:{}}},content:"block+",addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:n=>{const e=n.getAttribute("colwidth");return e?[parseInt(e,10)]:null}}}},tableRole:"cell",isolating:!0,parseHTML(){return[{tag:"td"}]},renderHTML({HTMLAttributes:n}){return["td",Ce(this.options.HTMLAttributes,n),0]},addNodeView(){return hi(Wv,{as:"td",className:"relative"})}}),fL=Ve.create({name:"tableHeader",addOptions(){return{HTMLAttributes:{}}},content:"block+",addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:n=>{const e=n.getAttribute("colwidth");return e?[parseInt(e,10)]:null}}}},tableRole:"header_cell",isolating:!0,parseHTML(){return[{tag:"th"}]},renderHTML({HTMLAttributes:n}){return["th",Ce(this.options.HTMLAttributes,n),0]},addNodeView(){return hi(Wv,{as:"th",className:"relative"})}}),qv=n=>(n.stopPropagation(),n.preventDefault(),n),hL=function(n){const e=n.scrollHeight>n.clientHeight,r=window.getComputedStyle(n).overflowY.indexOf("hidden")!==-1;return e&&!r},Kv=function(n){return!n||n===document.body?document.body:hL(n)?n:Kv(n.parentNode)},yh=(n,e,t)=>{const r=document.createElement(n);if(!r)throw new Error(`Element with name ${n} can't be created.`);return e&&Object.entries(e).forEach(([i,s])=>r.setAttribute(i,s)),t&&Object.entries(t).forEach(([i,s])=>r.addEventListener(i,s)),r},pL=Ve.create({name:"tableRow",addOptions(){return{HTMLAttributes:{}}},content:"(tableCell | tableHeader)*",tableRole:"row",parseHTML(){return[{tag:"tr"}]},renderHTML({HTMLAttributes:n}){return["tr",Ce(this.options.HTMLAttributes,n),0]},addNodeView(){return({editor:n,HTMLAttributes:e,getPos:t})=>{const r=()=>t(),i=Kv(n.options.element);let s=!1;const o={deleteRow:()=>{this.editor.chain().deleteNode("tableRow").focus().run()},selectRow:()=>{const w=r(),S=n.state.doc.resolve(w),C=new se(S);n.view.dispatch(n.state.tr.setSelection(C))}},l=()=>{s=!0},a=()=>{s=!1},c=yh("section",{class:"absolute hidden flex items-center w-2 bg-gray-200 z-50 cursor-pointer border-1 border-indigo-600 rounded-l opacity-25 hover:opacity-100",contenteditable:"false"},{click:w=>{w&&qv(w),o.selectRow()},mouseenter:()=>{l()},mouseover:()=>{l()},mouseleave:()=>{a(),f()}}),u=yh("button",{class:"text-sm px-1 absolute -translate-x-[125%] hover:active:-translate-x-[125%] mr-2"},{click:w=>{w&&qv(w),o.deleteRow()}}),d=()=>{g(),c.classList.remove("hidden")},f=()=>{setTimeout(()=>{s||c.classList.add("hidden")},100)},h=yh("tr",{...e},{mouseenter:d,mouseover:d,mouseleave:f});c.append(u),document.body.append(c);let p="";const g=()=>{setTimeout(()=>{const w=h.getBoundingClientRect(),S=JSON.stringify(w);p!==S&&(c.style.top=`${w.top+document.documentElement.scrollTop}px`,c.style.left=`${w.x+document.documentElement.scrollLeft-8}px`,c.style.height=`${w.height+1}px`,p=S)})};return setTimeout(()=>{g()},100),n.on("selectionUpdate",g),n.on("update",g),i==null||i.addEventListener("scroll",g),document.addEventListener("scroll",g),{dom:h,contentDOM:h,destroy:()=>{c.remove(),n.off("selectionUpdate",g),n.off("update",g),i==null||i.removeEventListener("scroll",g),document.removeEventListener("scroll",g)}}}}}),mL=[tL.configure({resizable:!0}),dL,fL,pL],gL=Hb.extend({content:"(dBlock|columns)+"});function Jv({types:n,node:e}){return e!=null&&e.type?Array.isArray(n)&&n.includes(e.type)||e.type===n:!1}const yL=Ue.create({name:"trailingNode",addOptions(){return{node:"paragraph",notAfter:["paragraph"]}},addProseMirrorPlugins(){const n=new We(this.name),e=Object.entries(this.editor.schema.nodes).map(([,t])=>t).filter(t=>this.options.notAfter.includes(t.name));return[new je({key:n,appendTransaction:(t,r,i)=>{const{doc:s,tr:o,schema:l}=i,a=n.getState(i),c=s.content.size,u=l.nodes[this.options.node];if(a)return o.insert(c,u.create())},state:{init:(t,r)=>{const i=r.tr.doc.lastChild;return!Jv({node:i,types:e})},apply:(t,r)=>{var s,o,l;if(!t.docChanged)return r;const i=(l=(o=(s=t.doc.lastChild)==null?void 0:s.content)==null?void 0:o.content)==null?void 0:l[0];return!Jv({node:i,types:e})}}})]}}),bL=({node:n,editor:e,getPos:t})=>{const[r,i]=O.useState(""),s=Ul(),o=["https://twitter.com","https://x.com"],l=()=>{switch(n.attrs.data){case"twitter":return D.jsx(f0,{});case"iframe":return D.jsx(h0,{});default:return D.jsx(sT,{})}},a=()=>{switch(n.attrs.data){case"twitter":return"Embed a Twitter tweet";case"iframe":return"Embed a video";default:return"Embed an URL"}},c=()=>{if(!r){alert("Please enter a url");return}let p=r;if(r.includes("<iframe")){const C=r.match(/src="([^"]*)"/);C&&C.length>0&&(p=C[1])}else switch(!0){case/youtu\.?be(?:\.com)?\/(?:.*v(?:\/|=)|(?:.*\/)?)([a-zA-Z0-9-_]+)/.test(r):{const C=r.match(/youtu\.?be(?:\.com)?\/(?:.*v(?:\/|=)|(?:.*\/)?)([a-zA-Z0-9-_]+)/);C&&C.length>0&&(p=`https://www.youtube.com/embed/${C[1]}`);break}case/vimeo\.com\/([a-zA-Z0-9-_]+)/.test(r):{const C=r.match(/vimeo\.com\/([a-zA-Z0-9-_]+)/);C&&C.length>0&&(p=`https://player.vimeo.com/video/${C[1]}`);break}default:{alert("Please enter a valid url");return}}const g=640,v=360,w=t(),S=w+n.nodeSize;p&&(e==null||e.chain().focus(w).deleteRange({from:w,to:S}).setIframe({src:p,width:g,height:v}).run())},u=()=>{if(!r){alert("Please enter a url");return}let p=r;const g=o.some(y=>r.includes(y)),v=r.match(/\/status\/([0-9]*)/),w=v&&v.length>0;if(g&&w)p=v[1];else{alert("invalid url");return}const S=t(),C=S+n.nodeSize;p&&(e==null||e.chain().focus(S).deleteRange({from:S,to:C}).setTweetEmbed({tweetId:p}).run())},f=y1(()=>{switch(n.attrs.data){case"twitter":u();break;default:c();break}},500);O.useEffect(()=>{r&&f()},[r]),O.useEffect(()=>{e==null||e.chain().focus()},[]);const h=O.useRef(null);return O.useEffect(()=>{var p;(p=h.current)==null||p.focus()},[]),D.jsx(bo,{as:"div",className:"flex gap-2 group w-full relative justify-center items-start",children:!s&&D.jsxs("div",{className:"relative w-full",children:[D.jsx("div",{className:"absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none",children:l()}),D.jsx("input",{ref:h,value:r,placeholder:a(),onChange:p=>i(p.target.value),onClick:p=>p.stopPropagation(),className:"bg-stone-200 p-3 pl-10 rounded-xl w-full hover:bg-stone-300 cursor-pointer transition-all ease-in-out"})]})})},vL=Ve.create({name:"actionButton",group:"block",content:"block*",atom:!0,draggable:!0,addOptions(){return{HTMLAttributes:{class:"rounded-lg bg-stone-500"}}},addAttributes(){return{data:{default:null}}},addNodeView(){return hi(bL)},parseHTML(){return[{tag:"div[data-action-node]"}]},renderHTML({HTMLAttributes:n}){return console.log("action"),["div",Ce(n,{"data-action-node":""}),0]},addCommands(){return{setActionButton:n=>({commands:e})=>e.insertContent({type:this.name,attrs:{data:n},content:[]})}}}),wL=[u_,a_.configure({strike:{HTMLAttributes:{class:"select-text pointer-events-auto"}},bold:{HTMLAttributes:{class:"select-text pointer-events-auto"}},italic:{HTMLAttributes:{class:"select-text pointer-events-auto"}},heading:{HTMLAttributes:{class:"select-text pointer-events-auto"}},paragraph:{HTMLAttributes:{class:"select-text pointer-events-auto"}},bulletList:{HTMLAttributes:{class:"flex flex-col items-start list-disc list-outside space-y-4 ml-6"}},orderedList:{HTMLAttributes:{class:"flex flex-col items-start list-decimal list-outside space-y-4 ml-6"}},listItem:{HTMLAttributes:{class:"leading-normal"}},blockquote:{HTMLAttributes:{class:"rounded-lg bg-stone-100 p-5 font-serif italic text-stone-800"}},codeBlock:{HTMLAttributes:{class:"rounded-lg bg-transparent border border-[#DDE2E4] p-5 font-mono font-medium text-stone-800"}},code:{HTMLAttributes:{class:"rounded-md bg-stone-200 p-1.5 font-mono font-medium text-black text-sm",spellcheck:"false"}},history:!1,gapcursor:!1,dropcursor:!1,document:!1,horizontalRule:!1}),d_.configure({types:["heading","paragraph"]}),X_,L_.configure({HTMLAttributes:{class:"text-blue-500 font-bold transition-colors cursor-pointer select-text pointer-events-auto"},openOnClick:!0}),I_.configure({placeholder:()=>"",includeChildren:!0,showOnlyCurrent:!0}),B_.configure({multicolor:!0}),Z_,V_.configure({HTMLAttributes:{class:"select-text pointer-events-auto"}}),c_,tN,$_.configure({HTMLAttributes:{class:"not-prose space-y-4 ml-2"}}),H_.configure({HTMLAttributes:{class:"flex items-start"},nested:!0}),Vb.configure({width:3,color:"#d1d5db"}),zb,e5,yL,gL,...mL,uN.configure({uploadFn:ST}),eN,nN,oN,vL.extend({addInputRules(){return[Gv(/^(?:twt|###|___\s|\*\*\*\s)$/,"twitter",this.type),Gv(/^(?:ytb|@@@|___\s|\*\*\*\s)$/,"iframe",this.type)]}}),Q_],Gv=(n,e,t)=>new io({find:n,handler:({state:r,range:i,commands:s})=>{const o={data:e},{tr:l}=r,a=i.from,c=i.to;l.insert(a-1,t.create(o)).delete(l.mapping.map(a),l.mapping.map(c)),s.focus(c-1)}}),Yv=["#30bced","#6eeb83","#fa69d1","#ecd444","#ee6352","#db3041","#0ad7f2","#1bff39"],CL=({isPreviewMode:n,data:e,enableCollaboration:t,collaborationId:r})=>{const[i,s]=O.useState({plugin:{title:null}}),[o]=O.useState(new as),l=O.useRef(null),a=[...wL,d3.configure({document:o})];O.useEffect(()=>{if(r&&t){const f=new BO(r||"default-room",o,{signaling:["wss://fileverse-signaling-server-0529292ff51c.herokuapp.com/"]});return l.current=f,()=>{f.destroy(),o.destroy()}}},[r,o]),O.useEffect(()=>{t&&r&&(a.some(h=>h.name==="collaborationCursor")||a.push(f3.configure({provider:l.current,user:{color:Yv[Math.floor(Math.random()*Yv.length)]}})))},[l.current]);const c=FE({extensions:a,editorProps:$O,autofocus:"start"}),u=O.useRef(null),d=f=>{var h;(h=u.current)!=null&&h.contains(f.target)||c==null||c.chain().focus().run()};return O.useEffect(()=>{c==null||c.chain().focus()},[]),O.useEffect(()=>{c==null||c.setEditable(!n)},[n]),O.useEffect(()=>{e&&c&&(c==null||c.commands.setContent(e.editorJSONData),s(e.metaData))},[e,c]),{editor:c,pluginMetaData:i,setPluginMetaData:s,focusEditor:d,ref:u}},xL=({isPreviewMode:n=!1,onPublish:e,data:t,togglePreviewMode:r,enableCollaboration:i,collaborationId:s})=>{const{editor:o,pluginMetaData:l,focusEditor:a,setPluginMetaData:c,ref:u}=CL({isPreviewMode:n,data:t,enableCollaboration:i,collaborationId:s,onPublish:e,togglePreviewMode:r});return o?D.jsx("div",{"data-cy":"single-webpage",className:"h-screen w-screen bg-[#f9fbfd]",children:D.jsx("div",{className:"h-full flex flex-col overflow-scroll no-scrollbar",children:D.jsxs("div",{className:"w-full h-screen",children:[D.jsx("div",{className:"h-fit relative bg-[#ffffff]",children:D.jsxs("div",{className:"flex items-center justify-center pl-4 pr-4 border-b-1 border gap-2 h-16",children:[D.jsx("div",{className:"grow",children:D.jsx(iw,{isPreviewMode:n,metaData:l,setMetaData:c})}),!n&&D.jsx("div",{className:"grow relative",children:D.jsx(jT,{editor:o})}),D.jsx("div",{children:D.jsx(zl,{onClick:()=>r(n),children:n?"Edit":"Preview"})}),e&&D.jsx("div",{onClick:()=>e({metaData:l,editorJSONData:o.getJSON()}),className:"cursor-pointer",children:D.jsx(zl,{children:"Publish"})})]})}),D.jsx("main",{className:"h-screen lg:h-full w-full rounded-[8px] flex flex-col justify-start items-center gap-2",children:D.jsx("div",{onClick:a,className:"w-full flex justify-center relative",children:D.jsx("div",{className:"p-12 sm:p-[96px] mt-4 min-h-[900px] shadow-inner bg-white overflow-scroll no-scrollbar rounded-md w-full sm:w-[70%] max-w-[856px]",children:D.jsxs("div",{ref:u,className:"w-full pt-4 h-full",children:[!n&&D.jsxs("div",{children:[D.jsx(NT,{editor:o}),D.jsx(BT,{editor:o,appendTo:u})]}),D.jsx($T,{isPreviewMode:n,children:D.jsx(IE,{editor:o})})]})})})})]})})}):D.jsxs("div",{className:"w-screen h-screen flex flex-col gap-4 justify-center items-center",children:[D.jsx(N0,{}),D.jsx("p",{children:"Loading Editor..."})]})};Bt.DdocEditor=xL,Object.defineProperty(Bt,Symbol.toStringTag,{value:"Module"})});
359
+ `).focus(o+1).run():["columns","heading"].includes(l)?n.chain().insertContent({type:"dBlock",content:[{type:"paragraph"}]}).focus().run():n.chain().insertContentAt({from:t,to:o},{type:this.name,content:a}).focus(t+4).run()}catch(u){return console.error(`Error inserting content into dBlock node: ${u}`),!1}}}}});let lh,ah;if(typeof WeakMap<"u"){let n=new WeakMap;lh=e=>n.get(e),ah=(e,t)=>(n.set(e,t),t)}else{let n=[],e=10,t=0;lh=r=>{for(let i=0;i<n.length;i+=2)if(n[i]==r)return n[i+1]},ah=(r,i)=>(t==e&&(t=0),n[t++]=r,n[t++]=i)}class Ds{constructor(e,t,r,i){this.left=e,this.top=t,this.right=r,this.bottom=i}}class et{constructor(e,t,r,i){this.width=e,this.height=t,this.map=r,this.problems=i}findCell(e){for(let t=0;t<this.map.length;t++){let r=this.map[t];if(r!=e)continue;let i=t%this.width,s=t/this.width|0,o=i+1,l=s+1;for(let a=1;o<this.width&&this.map[t+a]==r;a++)o++;for(let a=1;l<this.height&&this.map[t+this.width*a]==r;a++)l++;return new Ds(i,s,o,l)}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,r){let{left:i,right:s,top:o,bottom:l}=this.findCell(e);return t=="horiz"?(r<0?i==0:s==this.width)?null:this.map[o*this.width+(r<0?i-1:s)]:(r<0?o==0:l==this.height)?null:this.map[i+this.width*(r<0?o-1:l)]}rectBetween(e,t){let{left:r,right:i,top:s,bottom:o}=this.findCell(e),{left:l,right:a,top:c,bottom:u}=this.findCell(t);return new Ds(Math.min(r,l),Math.min(s,c),Math.max(i,a),Math.max(o,u))}cellsInRect(e){let t=[],r={};for(let i=e.top;i<e.bottom;i++)for(let s=e.left;s<e.right;s++){let o=i*this.width+s,l=this.map[o];r[l]||(r[l]=!0,(s!=e.left||!s||this.map[o-1]!=l)&&(i!=e.top||!i||this.map[o-this.width]!=l)&&t.push(l))}return t}positionAt(e,t,r){for(let i=0,s=0;;i++){let o=s+r.child(i).nodeSize;if(i==e){let l=t+e*this.width,a=(e+1)*this.width;for(;l<a&&this.map[l]<s;)l++;return l==a?o-1:this.map[l]}s=o}}static get(e){return lh(e)||ah(e,t5(e))}}function t5(n){if(n.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+n.type.name);let e=n5(n),t=n.childCount,r=[],i=0,s=null,o=[];for(let c=0,u=e*t;c<u;c++)r[c]=0;for(let c=0,u=0;c<t;c++){let d=n.child(c);u++;for(let p=0;;p++){for(;i<r.length&&r[i]!=0;)i++;if(p==d.childCount)break;let g=d.child(p),{colspan:v,rowspan:w,colwidth:S}=g.attrs;for(let C=0;C<w;C++){if(C+c>=t){(s||(s=[])).push({type:"overlong_rowspan",pos:u,n:w-C});break}let y=i+C*e;for(let k=0;k<v;k++){r[y+k]==0?r[y+k]=u:(s||(s=[])).push({type:"collision",row:c,pos:u,n:v-k});let E=S&&S[k];if(E){let T=(y+k)%e*2,N=o[T];N==null||N!=E&&o[T+1]==1?(o[T]=E,o[T+1]=1):N==E&&o[T+1]++}}}i+=v,u+=g.nodeSize}let f=(c+1)*e,h=0;for(;i<f;)r[i++]==0&&h++;h&&(s||(s=[])).push({type:"missing",row:c,n:h}),u++}let l=new et(e,t,r,s),a=!1;for(let c=0;!a&&c<o.length;c+=2)o[c]!=null&&o[c+1]<t&&(a=!0);return a&&r5(l,o,n),l}function n5(n){let e=-1,t=!1;for(let r=0;r<n.childCount;r++){let i=n.child(r),s=0;if(t)for(let o=0;o<r;o++){let l=n.child(o);for(let a=0;a<l.childCount;a++){let c=l.child(a);o+c.attrs.rowspan>r&&(s+=c.attrs.colspan)}}for(let o=0;o<i.childCount;o++){let l=i.child(o);s+=l.attrs.colspan,l.attrs.rowspan>1&&(t=!0)}e==-1?e=s:e!=s&&(e=Math.max(e,s))}return e}function r5(n,e,t){n.problems||(n.problems=[]);for(let r=0,i={};r<n.map.length;r++){let s=n.map[r];if(i[s])continue;i[s]=!0;let o=t.nodeAt(s),l=null;for(let a=0;a<o.attrs.colspan;a++){let c=(r+a)%n.width,u=e[c*2];u!=null&&(!o.attrs.colwidth||o.attrs.colwidth[a]!=u)&&((l||(l=i5(o.attrs)))[a]=u)}l&&n.problems.unshift({type:"colwidth mismatch",pos:s,colwidth:l})}}function i5(n){if(n.colwidth)return n.colwidth.slice();let e=[];for(let t=0;t<n.colspan;t++)e.push(0);return e}function Mt(n){let e=n.cached.tableNodeTypes;if(!e){e=n.cached.tableNodeTypes={};for(let t in n.nodes){let r=n.nodes[t],i=r.spec.tableRole;i&&(e[i]=r)}}return e}const Gr=new We("selectingCells");function Rs(n){for(let e=n.depth-1;e>0;e--)if(n.node(e).type.spec.tableRole=="row")return n.node(0).resolve(n.before(e+1));return null}function s5(n){for(let e=n.depth;e>0;e--){const t=n.node(e).type.spec.tableRole;if(t==="cell"||t==="header_cell")return n.node(e)}return null}function Tn(n){let e=n.selection.$head;for(let t=e.depth;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return!0;return!1}function Ec(n){let e=n.selection;return e.$anchorCell?e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell:e.node&&e.node.type.spec.tableRole=="cell"?e.$anchor:Rs(e.$head)||o5(e.$head)}function o5(n){for(let e=n.nodeAfter,t=n.pos;e;e=e.firstChild,t++){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t)}for(let e=n.nodeBefore,t=n.pos;e;e=e.lastChild,t--){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t-e.nodeSize)}}function ch(n){return n.parent.type.spec.tableRole=="row"&&n.nodeAfter}function l5(n){return n.node(0).resolve(n.pos+n.nodeAfter.nodeSize)}function uh(n,e){return n.depth==e.depth&&n.pos>=e.start(-1)&&n.pos<=e.end(-1)}function vv(n,e,t){let r=n.start(-1),s=et.get(n.node(-1)).nextCell(n.pos-r,e,t);return s==null?null:n.node(0).resolve(r+s)}function wt(n,e,t){let r={};for(let i in n)r[i]=n[i];return r[e]=t,r}function _i(n,e,t=1){let r=wt(n,"colspan",n.colspan-t);return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,t),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}function wv(n,e,t=1){let r=wt(n,"colspan",n.colspan+t);if(r.colwidth){r.colwidth=r.colwidth.slice();for(let i=0;i<t;i++)r.colwidth.splice(e,0,0)}return r}function a5(n,e,t){let r=Mt(e.type.schema).header_cell;for(let i=0;i<n.height;i++)if(e.nodeAt(n.map[t+i*n.width]).type!=r)return!1;return!0}class Se extends ue{constructor(e,t=e){let r=e.node(-1),i=et.get(r),s=e.start(-1),o=i.rectBetween(e.pos-s,t.pos-s),l=e.node(0),a=i.cellsInRect(o).filter(u=>u!=t.pos-s);a.unshift(t.pos-s);let c=a.map(u=>{let d=r.nodeAt(u),f=u+s+1;return new Jc(l.resolve(f),l.resolve(f+d.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=e,this.$headCell=t}map(e,t){let r=e.resolve(t.map(this.$anchorCell.pos)),i=e.resolve(t.map(this.$headCell.pos));if(ch(r)&&ch(i)&&uh(r,i)){let s=this.$anchorCell.node(-1)!=r.node(-1);return s&&this.isRowSelection()?Se.rowSelection(r,i):s&&this.isColSelection()?Se.colSelection(r,i):new Se(r,i)}return ce.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=et.get(e),r=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),s={},o=[];for(let a=i.top;a<i.bottom;a++){let c=[];for(let u=a*t.width+i.left,d=i.left;d<i.right;d++,u++){let f=t.map[u];if(!s[f]){s[f]=!0;let h=t.findCell(f),p=e.nodeAt(f),g=i.left-h.left,v=h.right-i.right;if(g>0||v>0){let w=p.attrs;g>0&&(w=_i(w,0,g)),v>0&&(w=_i(w,w.colspan-v,v)),h.left<i.left?p=p.type.createAndFill(w):p=p.type.create(w,p.content)}if(h.top<i.top||h.bottom>i.bottom){let w=wt(p.attrs,"rowspan",Math.min(h.bottom,i.bottom)-Math.max(h.top,i.top));h.top<i.top?p=p.type.createAndFill(w):p=p.type.create(w,p.content)}c.push(p)}}o.push(e.child(a).copy(W.from(c)))}const l=this.isColSelection()&&this.isRowSelection()?e:o;return new Y(W.from(l),1,1)}replace(e,t=Y.empty){let r=e.steps.length,i=this.ranges;for(let o=0;o<i.length;o++){let{$from:l,$to:a}=i[o],c=e.mapping.slice(r);e.replace(c.map(l.pos),c.map(a.pos),o?Y.empty:t)}let s=ue.findFrom(e.doc.resolve(e.mapping.slice(r).map(this.to)),-1);s&&e.setSelection(s)}replaceWith(e,t){this.replace(e,new Y(W.from(t),0,0))}forEachCell(e){let t=this.$anchorCell.node(-1),r=et.get(t),i=this.$anchorCell.start(-1),s=r.cellsInRect(r.rectBetween(this.$anchorCell.pos-i,this.$headCell.pos-i));for(let o=0;o<s.length;o++)e(t.nodeAt(s[o]),i+s[o])}isColSelection(){let e=this.$anchorCell.index(-1),t=this.$headCell.index(-1);if(Math.min(e,t)>0)return!1;let r=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(e,t=e){let r=et.get(e.node(-1)),i=e.start(-1),s=r.findCell(e.pos-i),o=r.findCell(t.pos-i),l=e.node(0);return s.top<=o.top?(s.top>0&&(e=l.resolve(i+r.map[s.left])),o.bottom<r.height&&(t=l.resolve(i+r.map[r.width*(r.height-1)+o.right-1]))):(o.top>0&&(t=l.resolve(i+r.map[o.left])),s.bottom<r.height&&(e=l.resolve(i+r.map[r.width*(r.height-1)+s.right-1]))),new Se(e,t)}isRowSelection(){let e=et.get(this.$anchorCell.node(-1)),t=this.$anchorCell.start(-1),r=e.colCount(this.$anchorCell.pos-t),i=e.colCount(this.$headCell.pos-t);if(Math.min(r,i)>0)return!1;let s=r+this.$anchorCell.nodeAfter.attrs.colspan,o=i+this.$headCell.nodeAfter.attrs.colspan;return Math.max(s,o)==e.width}eq(e){return e instanceof Se&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,t=e){let r=et.get(e.node(-1)),i=e.start(-1),s=r.findCell(e.pos-i),o=r.findCell(t.pos-i),l=e.node(0);return s.left<=o.left?(s.left>0&&(e=l.resolve(i+r.map[s.top*r.width])),o.right<r.width&&(t=l.resolve(i+r.map[r.width*(o.top+1)-1]))):(o.left>0&&(t=l.resolve(i+r.map[o.top*r.width])),s.right<r.width&&(e=l.resolve(i+r.map[r.width*(s.top+1)-1]))),new Se(e,t)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(e,t){return new Se(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){return new Se(e.resolve(t),e.resolve(r))}getBookmark(){return new dh(this.$anchorCell.pos,this.$headCell.pos)}}Se.prototype.visible=!1,ue.jsonID("cell",Se);class dh{constructor(e,t){this.anchor=e,this.head=t}map(e){return new dh(e.map(this.anchor),e.map(this.head))}resolve(e){let t=e.resolve(this.anchor),r=e.resolve(this.head);return t.parent.type.spec.tableRole=="row"&&r.parent.type.spec.tableRole=="row"&&t.index()<t.parent.childCount&&r.index()<r.parent.childCount&&uh(t,r)?new Se(t,r):ue.near(r,1)}}function c5(n){if(!(n.selection instanceof Se))return null;let e=[];return n.selection.forEachCell((t,r)=>{e.push(ut.node(r,r+t.nodeSize,{class:"selectedCell"}))}),He.create(n.doc,e)}function u5({$from:n,$to:e}){if(n.pos==e.pos||n.pos<n.pos-6)return!1;let t=n.pos,r=e.pos,i=n.depth;for(;i>=0&&!(n.after(i+1)<n.end(i));i--,t++);for(let s=e.depth;s>=0&&!(e.before(s+1)>e.start(s));s--,r--);return t==r&&/row|table/.test(n.node(i).type.spec.tableRole)}function d5({$from:n,$to:e}){let t,r;for(let i=n.depth;i>0;i--){let s=n.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){t=s;break}}for(let i=e.depth;i>0;i--){let s=e.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){r=s;break}}return t!==r&&e.parentOffset===0}function f5(n,e,t){let r=(e||n).selection,i=(e||n).doc,s,o;if(r instanceof se&&(o=r.node.type.spec.tableRole)){if(o=="cell"||o=="header_cell")s=Se.create(i,r.from);else if(o=="row"){let l=i.resolve(r.from+1);s=Se.rowSelection(l,l)}else if(!t){let l=et.get(r.node),a=r.from+1,c=a+l.map[l.width*l.height-1];s=Se.create(i,a+1,c)}}else r instanceof ce&&u5(r)?s=ce.create(i,r.from):r instanceof ce&&d5(r)&&(s=ce.create(i,r.$from.start(),r.$from.end()));return s&&(e||(e=n.tr)).setSelection(s),e}function h5(n){if(!n.size)return null;let{content:e,openStart:t,openEnd:r}=n;for(;e.childCount==1&&(t>0&&r>0||e.firstChild.type.spec.tableRole=="table");)t--,r--,e=e.firstChild.content;let i=e.firstChild,s=i.type.spec.tableRole,o=i.type.schema,l=[];if(s=="row")for(let a=0;a<e.childCount;a++){let c=e.child(a).content,u=a?0:Math.max(0,t-1),d=a<e.childCount-1?0:Math.max(0,r-1);(u||d)&&(c=fh(Mt(o).row,new Y(c,u,d)).content),l.push(c)}else if(s=="cell"||s=="header_cell")l.push(t||r?fh(Mt(o).row,new Y(e,t,r)).content:e);else return null;return p5(o,l)}function p5(n,e){let t=[];for(let i=0;i<e.length;i++){let s=e[i];for(let o=s.childCount-1;o>=0;o--){let{rowspan:l,colspan:a}=s.child(o).attrs;for(let c=i;c<i+l;c++)t[c]=(t[c]||0)+a}}let r=0;for(let i=0;i<t.length;i++)r=Math.max(r,t[i]);for(let i=0;i<t.length;i++)if(i>=e.length&&e.push(W.empty),t[i]<r){let s=Mt(n).cell.createAndFill(),o=[];for(let l=t[i];l<r;l++)o.push(s);e[i]=e[i].append(W.from(o))}return{height:e.length,width:r,rows:e}}function fh(n,e){let t=n.createAndFill();return new qc(t).replace(0,t.content.size,e).doc}function m5({width:n,height:e,rows:t},r,i){if(n!=r){let s=[],o=[];for(let l=0;l<t.length;l++){let a=t[l],c=[];for(let u=s[l]||0,d=0;u<r;d++){let f=a.child(d%a.childCount);u+f.attrs.colspan>r&&(f=f.type.create(_i(f.attrs,f.attrs.colspan,u+f.attrs.colspan-r),f.content)),c.push(f),u+=f.attrs.colspan;for(let h=1;h<f.attrs.rowspan;h++)s[l+h]=(s[l+h]||0)+f.attrs.colspan}o.push(W.from(c))}t=o,n=r}if(e!=i){let s=[];for(let o=0,l=0;o<i;o++,l++){let a=[],c=t[l%e];for(let u=0;u<c.childCount;u++){let d=c.child(u);o+d.attrs.rowspan>i&&(d=d.type.create(wt(d.attrs,"rowspan",Math.max(1,i-d.attrs.rowspan)),d.content)),a.push(d)}s.push(W.from(a))}t=s,e=i}return{width:n,height:e,rows:t}}function g5(n,e,t,r,i,s,o){let l=n.doc.type.schema,a=Mt(l),c,u;if(i>e.width)for(let d=0,f=0;d<e.height;d++){let h=t.child(d);f+=h.nodeSize;let p=[],g;h.lastChild==null||h.lastChild.type==a.cell?g=c||(c=a.cell.createAndFill()):g=u||(u=a.header_cell.createAndFill());for(let v=e.width;v<i;v++)p.push(g);n.insert(n.mapping.slice(o).map(f-1+r),p)}if(s>e.height){let d=[];for(let p=0,g=(e.height-1)*e.width;p<Math.max(e.width,i);p++){let v=p>=e.width?!1:t.nodeAt(e.map[g+p]).type==a.header_cell;d.push(v?u||(u=a.header_cell.createAndFill()):c||(c=a.cell.createAndFill()))}let f=a.row.create(null,W.from(d)),h=[];for(let p=e.height;p<s;p++)h.push(f);n.insert(n.mapping.slice(o).map(r+t.nodeSize-2),h)}return!!(c||u)}function Cv(n,e,t,r,i,s,o,l){if(o==0||o==e.height)return!1;let a=!1;for(let c=i;c<s;c++){let u=o*e.width+c,d=e.map[u];if(e.map[u-e.width]==d){a=!0;let f=t.nodeAt(d),{top:h,left:p}=e.findCell(d);n.setNodeMarkup(n.mapping.slice(l).map(d+r),null,wt(f.attrs,"rowspan",o-h)),n.insert(n.mapping.slice(l).map(e.positionAt(o,p,t)),f.type.createAndFill(wt(f.attrs,"rowspan",h+f.attrs.rowspan-o))),c+=f.attrs.colspan-1}}return a}function xv(n,e,t,r,i,s,o,l){if(o==0||o==e.width)return!1;let a=!1;for(let c=i;c<s;c++){let u=c*e.width+o,d=e.map[u];if(e.map[u-1]==d){a=!0;let f=t.nodeAt(d),h=e.colCount(d),p=n.mapping.slice(l).map(d+r);n.setNodeMarkup(p,null,_i(f.attrs,o-h,f.attrs.colspan-(o-h))),n.insert(p+f.nodeSize,f.type.createAndFill(_i(f.attrs,0,o-h))),c+=f.attrs.rowspan-1}}return a}function kv(n,e,t,r,i){let s=t?n.doc.nodeAt(t-1):n.doc,o=et.get(s),{top:l,left:a}=r,c=a+i.width,u=l+i.height,d=n.tr,f=0;function h(){s=t?d.doc.nodeAt(t-1):d.doc,o=et.get(s),f=d.mapping.maps.length}g5(d,o,s,t,c,u,f)&&h(),Cv(d,o,s,t,a,c,l,f)&&h(),Cv(d,o,s,t,a,c,u,f)&&h(),xv(d,o,s,t,l,u,a,f)&&h(),xv(d,o,s,t,l,u,c,f)&&h();for(let p=l;p<u;p++){let g=o.positionAt(p,a,s),v=o.positionAt(p,c,s);d.replace(d.mapping.slice(f).map(g+t),d.mapping.slice(f).map(v+t),new Y(i.rows[p-l],0,0))}h(),d.setSelection(new Se(d.doc.resolve(t+o.positionAt(l,a,s)),d.doc.resolve(t+o.positionAt(u-1,c-1,s)))),e(d)}const y5=ku({ArrowLeft:Ac("horiz",-1),ArrowRight:Ac("horiz",1),ArrowUp:Ac("vert",-1),ArrowDown:Ac("vert",1),"Shift-ArrowLeft":Mc("horiz",-1),"Shift-ArrowRight":Mc("horiz",1),"Shift-ArrowUp":Mc("vert",-1),"Shift-ArrowDown":Mc("vert",1),Backspace:Oc,"Mod-Backspace":Oc,Delete:Oc,"Mod-Delete":Oc});function Tc(n,e,t){return t.eq(n.selection)?!1:(e&&e(n.tr.setSelection(t).scrollIntoView()),!0)}function Ac(n,e){return(t,r,i)=>{let s=t.selection;if(s instanceof Se)return Tc(t,r,ue.near(s.$headCell,e));if(n!="horiz"&&!s.empty)return!1;let o=Sv(i,n,e);if(o==null)return!1;if(n=="horiz")return Tc(t,r,ue.near(t.doc.resolve(s.head+e),e));{let l=t.doc.resolve(o),a=vv(l,n,e),c;return a?c=ue.near(a,1):e<0?c=ue.near(t.doc.resolve(l.before(-1)),-1):c=ue.near(t.doc.resolve(l.after(-1)),1),Tc(t,r,c)}}}function Mc(n,e){return(t,r,i)=>{let s=t.selection;if(!(s instanceof Se)){let l=Sv(i,n,e);if(l==null)return!1;s=new Se(t.doc.resolve(l))}let o=vv(s.$headCell,n,e);return o?Tc(t,r,new Se(s.$anchorCell,o)):!1}}function Oc(n,e){let t=n.selection;if(!(t instanceof Se))return!1;if(e){let r=n.tr,i=Mt(n.schema).cell.createAndFill().content;t.forEachCell((s,o)=>{s.content.eq(i)||r.replace(r.mapping.map(o+1),r.mapping.map(o+s.nodeSize-1),new Y(i,0,0))}),r.docChanged&&e(r)}return!0}function b5(n,e){let t=n.state.doc,r=Rs(t.resolve(e));return r?(n.dispatch(n.state.tr.setSelection(new Se(r))),!0):!1}function v5(n,e,t){if(!Tn(n.state))return!1;let r=h5(t),i=n.state.selection;if(i instanceof Se){r||(r={width:1,height:1,rows:[W.from(fh(Mt(n.state.schema).cell,t))]});let s=i.$anchorCell.node(-1),o=i.$anchorCell.start(-1),l=et.get(s).rectBetween(i.$anchorCell.pos-o,i.$headCell.pos-o);return r=m5(r,l.right-l.left,l.bottom-l.top),kv(n.state,n.dispatch,o,l,r),!0}else if(r){let s=Ec(n.state),o=s.start(-1);return kv(n.state,n.dispatch,o,et.get(s.node(-1)).findCell(s.pos-o),r),!0}else return!1}function w5(n,e){if(e.ctrlKey||e.metaKey)return;let t=Ev(n,e.target),r;if(e.shiftKey&&n.state.selection instanceof Se)i(n.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&t&&(r=Rs(n.state.selection.$anchor))!=null&&hh(n,e).pos!=r.pos)i(r,e),e.preventDefault();else if(!t)return;function i(l,a){let c=hh(n,a),u=Gr.getState(n.state)==null;if(!c||!uh(l,c))if(u)c=l;else return;let d=new Se(l,c);if(u||!n.state.selection.eq(d)){let f=n.state.tr.setSelection(d);u&&f.setMeta(Gr,l.pos),n.dispatch(f)}}function s(){n.root.removeEventListener("mouseup",s),n.root.removeEventListener("dragstart",s),n.root.removeEventListener("mousemove",o),Gr.getState(n.state)!=null&&n.dispatch(n.state.tr.setMeta(Gr,-1))}function o(l){let a=Gr.getState(n.state),c;if(a!=null)c=n.state.doc.resolve(a);else if(Ev(n,l.target)!=t&&(c=hh(n,e),!c))return s();c&&i(c,l)}n.root.addEventListener("mouseup",s),n.root.addEventListener("dragstart",s),n.root.addEventListener("mousemove",o)}function Sv(n,e,t){if(!(n.state.selection instanceof ce))return null;let{$head:r}=n.state.selection;for(let i=r.depth-1;i>=0;i--){let s=r.node(i);if((t<0?r.index(i):r.indexAfter(i))!=(t<0?0:s.childCount))return null;if(s.type.spec.tableRole=="cell"||s.type.spec.tableRole=="header_cell"){let l=r.before(i),a=e=="vert"?t>0?"down":"up":t>0?"right":"left";return n.endOfTextblock(a)?l:null}}return null}function Ev(n,e){for(;e&&e!=n.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e}function hh(n,e){let t=n.posAtCoords({left:e.clientX,top:e.clientY});return t&&t?Rs(n.state.doc.resolve(t.pos)):null}const C5=new We("fix-tables");function Tv(n,e,t,r){let i=n.childCount,s=e.childCount;e:for(let o=0,l=0;o<s;o++){let a=e.child(o);for(let c=l,u=Math.min(i,o+3);c<u;c++)if(n.child(c)==a){l=c+1,t+=a.nodeSize;continue e}r(a,t),l<i&&n.child(l).sameMarkup(a)?Tv(n.child(l),a,t+1,r):a.nodesBetween(0,a.content.size,r,t+1),t+=a.nodeSize}}function Av(n,e){let t,r=(i,s)=>{i.type.spec.tableRole=="table"&&(t=x5(n,i,s,t))};return e?e.doc!=n.doc&&Tv(e.doc,n.doc,0,r):n.doc.descendants(r),t}function x5(n,e,t,r){let i=et.get(e);if(!i.problems)return r;r||(r=n.tr);let s=[];for(let a=0;a<i.height;a++)s.push(0);for(let a=0;a<i.problems.length;a++){let c=i.problems[a];if(c.type=="collision"){let u=e.nodeAt(c.pos);for(let d=0;d<u.attrs.rowspan;d++)s[c.row+d]+=c.n;r.setNodeMarkup(r.mapping.map(t+1+c.pos),null,_i(u.attrs,u.attrs.colspan-c.n,c.n))}else if(c.type=="missing")s[c.row]+=c.n;else if(c.type=="overlong_rowspan"){let u=e.nodeAt(c.pos);r.setNodeMarkup(r.mapping.map(t+1+c.pos),null,wt(u.attrs,"rowspan",u.attrs.rowspan-c.n))}else if(c.type=="colwidth mismatch"){let u=e.nodeAt(c.pos);r.setNodeMarkup(r.mapping.map(t+1+c.pos),null,wt(u.attrs,"colwidth",c.colwidth))}}let o,l;for(let a=0;a<s.length;a++)s[a]&&(o==null&&(o=a),l=a);for(let a=0,c=t+1;a<i.height;a++){let u=e.child(a),d=c+u.nodeSize,f=s[a];if(f>0){let h="cell";u.firstChild&&(h=u.firstChild.type.spec.tableRole);let p=[];for(let v=0;v<f;v++)p.push(Mt(n.schema)[h].createAndFill());let g=(a==0||o==a-1)&&l==a?c+1:d-1;r.insert(r.mapping.map(g),p)}c=d}return r.setMeta(C5,{fixTables:!0})}function Xn(n){let e=n.selection,t=Ec(n),r=t.node(-1),i=t.start(-1),s=et.get(r),o;return e instanceof Se?o=s.rectBetween(e.$anchorCell.pos-i,e.$headCell.pos-i):o=s.findCell(t.pos-i),o.tableStart=i,o.map=s,o.table=r,o}function Mv(n,{map:e,tableStart:t,table:r},i){let s=i>0?-1:0;a5(e,r,i+s)&&(s=i==0||i==e.width?null:0);for(let o=0;o<e.height;o++){let l=o*e.width+i;if(i>0&&i<e.width&&e.map[l-1]==e.map[l]){let a=e.map[l],c=r.nodeAt(a);n.setNodeMarkup(n.mapping.map(t+a),null,wv(c.attrs,i-e.colCount(a))),o+=c.attrs.rowspan-1}else{let a=s==null?Mt(r.type.schema).cell:r.nodeAt(e.map[l+s]).type,c=e.positionAt(o,i,r);n.insert(n.mapping.map(t+c),a.createAndFill())}}return n}function k5(n,e){if(!Tn(n))return!1;if(e){let t=Xn(n);e(Mv(n.tr,t,t.left))}return!0}function S5(n,e){if(!Tn(n))return!1;if(e){let t=Xn(n);e(Mv(n.tr,t,t.right))}return!0}function E5(n,{map:e,table:t,tableStart:r},i){let s=n.mapping.maps.length;for(let o=0;o<e.height;){let l=o*e.width+i,a=e.map[l],c=t.nodeAt(a);if(i>0&&e.map[l-1]==a||i<e.width-1&&e.map[l+1]==a)n.setNodeMarkup(n.mapping.slice(s).map(r+a),null,_i(c.attrs,i-e.colCount(a)));else{let u=n.mapping.slice(s).map(r+a);n.delete(u,u+c.nodeSize)}o+=c.attrs.rowspan}}function T5(n,e){if(!Tn(n))return!1;if(e){let t=Xn(n),r=n.tr;if(t.left==0&&t.right==t.map.width)return!1;for(let i=t.right-1;E5(r,t,i),i!=t.left;i--)t.table=t.tableStart?r.doc.nodeAt(t.tableStart-1):r.doc,t.map=et.get(t.table);e(r)}return!0}function A5(n,e,t){let r=Mt(e.type.schema).header_cell;for(let i=0;i<n.width;i++)if(e.nodeAt(n.map[i+t*n.width]).type!=r)return!1;return!0}function Ov(n,{map:e,tableStart:t,table:r},i){let s=t;for(let a=0;a<i;a++)s+=r.child(a).nodeSize;let o=[],l=i>0?-1:0;A5(e,r,i+l)&&(l=i==0||i==e.height?null:0);for(let a=0,c=e.width*i;a<e.width;a++,c++)if(i>0&&i<e.height&&e.map[c]==e.map[c-e.width]){let u=e.map[c],d=r.nodeAt(u).attrs;n.setNodeMarkup(t+u,null,wt(d,"rowspan",d.rowspan+1)),a+=d.colspan-1}else{let u=l==null?Mt(r.type.schema).cell:r.nodeAt(e.map[c+l*e.width]).type;o.push(u.createAndFill())}return n.insert(s,Mt(r.type.schema).row.create(null,o)),n}function M5(n,e){if(!Tn(n))return!1;if(e){let t=Xn(n);e(Ov(n.tr,t,t.top))}return!0}function O5(n,e){if(!Tn(n))return!1;if(e){let t=Xn(n);e(Ov(n.tr,t,t.bottom))}return!0}function _5(n,{map:e,table:t,tableStart:r},i){let s=0;for(let a=0;a<i;a++)s+=t.child(a).nodeSize;let o=s+t.child(i).nodeSize,l=n.mapping.maps.length;n.delete(s+r,o+r);for(let a=0,c=i*e.width;a<e.width;a++,c++){let u=e.map[c];if(i>0&&u==e.map[c-e.width]){let d=t.nodeAt(u).attrs;n.setNodeMarkup(n.mapping.slice(l).map(u+r),null,wt(d,"rowspan",d.rowspan-1)),a+=d.colspan-1}else if(i<e.width&&u==e.map[c+e.width]){let d=t.nodeAt(u),f=d.type.create(wt(d.attrs,"rowspan",d.attrs.rowspan-1),d.content),h=e.positionAt(i+1,a,t);n.insert(n.mapping.slice(l).map(r+h),f),a+=d.attrs.colspan-1}}}function N5(n,e){if(!Tn(n))return!1;if(e){let t=Xn(n),r=n.tr;if(t.top==0&&t.bottom==t.map.height)return!1;for(let i=t.bottom-1;_5(r,t,i),i!=t.top;i--)t.table=t.tableStart?r.doc.nodeAt(t.tableStart-1):r.doc,t.map=et.get(t.table);e(r)}return!0}function _v(n){let e=n.content;return e.childCount==1&&e.firstChild.isTextblock&&e.firstChild.childCount==0}function D5({width:n,height:e,map:t},r){let i=r.top*n+r.left,s=i,o=(r.bottom-1)*n+r.left,l=i+(r.right-r.left-1);for(let a=r.top;a<r.bottom;a++){if(r.left>0&&t[s]==t[s-1]||r.right<n&&t[l]==t[l+1])return!0;s+=n,l+=n}for(let a=r.left;a<r.right;a++){if(r.top>0&&t[i]==t[i-n]||r.bottom<e&&t[o]==t[o+n])return!0;i++,o++}return!1}function Nv(n,e){let t=n.selection;if(!(t instanceof Se)||t.$anchorCell.pos==t.$headCell.pos)return!1;let r=Xn(n),{map:i}=r;if(D5(i,r))return!1;if(e){let s=n.tr,o={},l=W.empty,a,c;for(let u=r.top;u<r.bottom;u++)for(let d=r.left;d<r.right;d++){let f=i.map[u*i.width+d],h=r.table.nodeAt(f);if(!o[f])if(o[f]=!0,a==null)a=f,c=h;else{_v(h)||(l=l.append(h.content));let p=s.mapping.map(f+r.tableStart);s.delete(p,p+h.nodeSize)}}if(s.setNodeMarkup(a+r.tableStart,null,wt(wv(c.attrs,c.attrs.colspan,r.right-r.left-c.attrs.colspan),"rowspan",r.bottom-r.top)),l.size){let u=a+1+c.content.size,d=_v(c)?a+1:u;s.replaceWith(d+r.tableStart,u+r.tableStart,l)}s.setSelection(new Se(s.doc.resolve(a+r.tableStart))),e(s)}return!0}function Dv(n,e){const t=Mt(n.schema);return R5(({node:r})=>t[r.type.spec.tableRole])(n,e)}function R5(n){return(e,t)=>{let r=e.selection,i,s;if(r instanceof Se){if(r.$anchorCell.pos!=r.$headCell.pos)return!1;i=r.$anchorCell.nodeAfter,s=r.$anchorCell.pos}else{if(i=s5(r.$from),!i)return!1;s=Rs(r.$from).pos}if(i.attrs.colspan==1&&i.attrs.rowspan==1)return!1;if(t){let o=i.attrs,l=[],a=o.colwidth;o.rowspan>1&&(o=wt(o,"rowspan",1)),o.colspan>1&&(o=wt(o,"colspan",1));let c=Xn(e),u=e.tr;for(let f=0;f<c.right-c.left;f++)l.push(a?wt(o,"colwidth",a&&a[f]?[a[f]]:null):o);let d;for(let f=c.top;f<c.bottom;f++){let h=c.map.positionAt(f,c.left,c.table);f==c.top&&(h+=i.nodeSize);for(let p=c.left,g=0;p<c.right;p++,g++)p==c.left&&f==c.top||u.insert(d=u.mapping.map(h+c.tableStart,1),n({node:i,row:f,col:p}).createAndFill(l[g]))}u.setNodeMarkup(s,n({node:i,row:c.top,col:c.left}),l[0]),r instanceof Se&&u.setSelection(new Se(u.doc.resolve(r.$anchorCell.pos),d&&u.doc.resolve(d))),t(u)}return!0}}function L5(n,e){return function(t,r){if(!Tn(t))return!1;let i=Ec(t);if(i.nodeAfter.attrs[n]===e)return!1;if(r){let s=t.tr;t.selection instanceof Se?t.selection.forEachCell((o,l)=>{o.attrs[n]!==e&&s.setNodeMarkup(l,null,wt(o.attrs,n,e))}):s.setNodeMarkup(i.pos,null,wt(i.nodeAfter.attrs,n,e)),r(s)}return!0}}function I5(n){return function(e,t){if(!Tn(e))return!1;if(t){let r=Mt(e.schema),i=Xn(e),s=e.tr,o=i.map.cellsInRect(n=="column"?new Ds(i.left,0,i.right,i.map.height):n=="row"?new Ds(0,i.top,i.map.width,i.bottom):i),l=o.map(a=>i.table.nodeAt(a));for(let a=0;a<o.length;a++)l[a].type==r.header_cell&&s.setNodeMarkup(i.tableStart+o[a],r.cell,l[a].attrs);if(s.steps.length==0)for(let a=0;a<o.length;a++)s.setNodeMarkup(i.tableStart+o[a],r.header_cell,l[a].attrs);t(s)}return!0}}function Rv(n,e,t){const r=e.map.cellsInRect({left:0,top:0,right:n=="row"?e.map.width:1,bottom:n=="column"?e.map.height:1});for(let i=0;i<r.length;i++){const s=e.table.nodeAt(r[i]);if(s&&s.type!==t.header_cell)return!1}return!0}function Zo(n,e){return e=e||{useDeprecatedLogic:!1},e.useDeprecatedLogic?I5(n):function(t,r){if(!Tn(t))return!1;if(r){let i=Mt(t.schema),s=Xn(t),o=t.tr,l=Rv("row",s,i),a=Rv("column",s,i),u=(n==="column"?l:n==="row"?a:!1)?1:0,d=n=="column"?new Ds(0,u,1,s.map.height):n=="row"?new Ds(u,0,s.map.width,1):s,f=n=="column"?a?i.cell:i.header_cell:n=="row"?l?i.cell:i.header_cell:i.cell;s.map.cellsInRect(d).forEach(h=>{const p=h+s.tableStart,g=o.doc.nodeAt(p);g&&o.setNodeMarkup(p,f,g.attrs)}),r(o)}return!0}}Zo("row",{useDeprecatedLogic:!0}),Zo("column",{useDeprecatedLogic:!0});let P5=Zo("cell",{useDeprecatedLogic:!0});function F5(n,e){if(e<0){let t=n.nodeBefore;if(t)return n.pos-t.nodeSize;for(let r=n.index(-1)-1,i=n.before();r>=0;r--){let s=n.node(-1).child(r);if(s.childCount)return i-1-s.lastChild.nodeSize;i-=s.nodeSize}}else{if(n.index()<n.parent.childCount-1)return n.pos+n.nodeAfter.nodeSize;let t=n.node(-1);for(let r=n.indexAfter(-1),i=n.after();r<t.childCount;r++){let s=t.child(r);if(s.childCount)return i+1;i+=s.nodeSize}}}function Lv(n){return function(e,t){if(!Tn(e))return!1;let r=F5(Ec(e),n);if(r!=null){if(t){let i=e.doc.resolve(r);t(e.tr.setSelection(ce.between(i,l5(i))).scrollIntoView())}return!0}}}function B5(n,e){let t=n.selection.$anchor;for(let r=t.depth;r>0;r--)if(t.node(r).type.spec.tableRole=="table")return e&&e(n.tr.delete(t.before(r),t.after(r)).scrollIntoView()),!0;return!1}let $5=class{constructor(e,t){this.node=e,this.cellMinWidth=t,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")),ph(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(e){return e.type!=this.node.type?!1:(this.node=e,ph(e,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(e){return e.type=="attributes"&&(e.target==this.table||this.colgroup.contains(e.target))}};function ph(n,e,t,r,i,s){let o=0,l=!0,a=e.firstChild,c=n.firstChild;for(let u=0,d=0;u<c.childCount;u++){let{colspan:f,colwidth:h}=c.child(u).attrs;for(let p=0;p<f;p++,d++){let g=i==d?s:h&&h[p],v=g?g+"px":"";o+=g||r,g||(l=!1),a?(a.style.width!=v&&(a.style.width=v),a=a.nextSibling):e.appendChild(document.createElement("col")).style.width=v}}for(;a;){let u=a.nextSibling;a.parentNode.removeChild(a),a=u}l?(t.style.width=o+"px",t.style.minWidth=""):(t.style.width="",t.style.minWidth=o+"px")}const mn=new We("tableColumnResizing");function j5({handleWidth:n=5,cellMinWidth:e=25,View:t=$5,lastColumnResizable:r=!0}={}){return new je({key:mn,state:{init(s,o){return this.spec.props.nodeViews[Mt(o.schema).table.name]=(l,a)=>new t(l,e,a),new Xo(-1,!1)},apply(s,o){return o.apply(s)}},props:{attributes(s){return mn.getState(s).activeHandle>-1?{class:"resize-cursor"}:null},handleDOMEvents:{mousemove(s,o){H5(s,o,n,e,r)},mouseleave(s){V5(s)},mousedown(s,o){z5(s,o,e)}},decorations(s){let o=mn.getState(s);if(o.activeHandle>-1)return G5(s,o.activeHandle)},nodeViews:{}}})}class Xo{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(e){let t=this,r=e.getMeta(mn);if(r&&r.setHandle!=null)return new Xo(r.setHandle,null);if(r&&r.setDragging!==void 0)return new Xo(t.activeHandle,r.setDragging);if(t.activeHandle>-1&&e.docChanged){let i=e.mapping.map(t.activeHandle,-1);ch(e.doc.resolve(i))||(i=null),t=new Xo(i,t.dragging)}return t}}function H5(n,e,t,r,i){let s=mn.getState(n.state);if(!s.dragging){let o=W5(e.target),l=-1;if(o){let{left:a,right:c}=o.getBoundingClientRect();e.clientX-a<=t?l=Iv(n,e,"left"):c-e.clientX<=t&&(l=Iv(n,e,"right"))}if(l!=s.activeHandle){if(!i&&l!==-1){let a=n.state.doc.resolve(l),c=a.node(-1),u=et.get(c),d=a.start(-1);if(u.colCount(a.pos-d)+a.nodeAfter.attrs.colspan-1==u.width-1)return}Fv(n,l)}}}function V5(n){let e=mn.getState(n.state);e.activeHandle>-1&&!e.dragging&&Fv(n,-1)}function z5(n,e,t){let r=mn.getState(n.state);if(r.activeHandle==-1||r.dragging)return!1;let i=n.state.doc.nodeAt(r.activeHandle),s=U5(n,r.activeHandle,i.attrs);n.dispatch(n.state.tr.setMeta(mn,{setDragging:{startX:e.clientX,startWidth:s}}));function o(a){window.removeEventListener("mouseup",o),window.removeEventListener("mousemove",l);let c=mn.getState(n.state);c.dragging&&(q5(n,c.activeHandle,Pv(c.dragging,a,t)),n.dispatch(n.state.tr.setMeta(mn,{setDragging:null})))}function l(a){if(!a.which)return o(a);let c=mn.getState(n.state),u=Pv(c.dragging,a,t);K5(n,c.activeHandle,u,t)}return window.addEventListener("mouseup",o),window.addEventListener("mousemove",l),e.preventDefault(),!0}function U5(n,e,{colspan:t,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let s=n.domAtPos(e),l=s.node.childNodes[s.offset].offsetWidth,a=t;if(r)for(let c=0;c<t;c++)r[c]&&(l-=r[c],a--);return l/a}function W5(n){for(;n&&n.nodeName!="TD"&&n.nodeName!="TH";)n=n.classList.contains("ProseMirror")?null:n.parentNode;return n}function Iv(n,e,t){let r=n.posAtCoords({left:e.clientX,top:e.clientY});if(!r)return-1;let{pos:i}=r,s=Rs(n.state.doc.resolve(i));if(!s)return-1;if(t=="right")return s.pos;let o=et.get(s.node(-1)),l=s.start(-1),a=o.map.indexOf(s.pos-l);return a%o.width==0?-1:l+o.map[a-1]}function Pv(n,e,t){let r=e.clientX-n.startX;return Math.max(t,n.startWidth+r)}function Fv(n,e){n.dispatch(n.state.tr.setMeta(mn,{setHandle:e}))}function q5(n,e,t){let r=n.state.doc.resolve(e),i=r.node(-1),s=et.get(i),o=r.start(-1),l=s.colCount(r.pos-o)+r.nodeAfter.attrs.colspan-1,a=n.state.tr;for(let c=0;c<s.height;c++){let u=c*s.width+l;if(c&&s.map[u]==s.map[u-s.width])continue;let d=s.map[u],{attrs:f}=i.nodeAt(d),h=f.colspan==1?0:l-s.colCount(d);if(f.colwidth&&f.colwidth[h]==t)continue;let p=f.colwidth?f.colwidth.slice():J5(f.colspan);p[h]=t,a.setNodeMarkup(o+d,null,wt(f,"colwidth",p))}a.docChanged&&n.dispatch(a)}function K5(n,e,t,r){let i=n.state.doc.resolve(e),s=i.node(-1),o=i.start(-1),l=et.get(s).colCount(i.pos-o)+i.nodeAfter.attrs.colspan-1,a=n.domAtPos(i.start(-1)).node;for(;a.nodeName!="TABLE";)a=a.parentNode;ph(s,a.firstChild,a,r,l,t)}function J5(n){let e=[];for(let t=0;t<n;t++)e.push(0);return e}function G5(n,e){let t=[],r=n.doc.resolve(e),i=r.node(-1),s=et.get(i),o=r.start(-1),l=s.colCount(r.pos-o)+r.nodeAfter.attrs.colspan;for(let a=0;a<s.height;a++){let c=l+a*s.width-1;if((l==s.width||s.map[c]!=s.map[c+1])&&(a==0||s.map[c-1]!=s.map[c-1-s.width])){let u=s.map[c],d=o+u+i.nodeAt(u).nodeSize-1,f=document.createElement("div");f.className="column-resize-handle",t.push(ut.widget(d,f))}}return He.create(n.doc,t)}function Y5({allowTableNodeSelection:n=!1}={}){return new je({key:Gr,state:{init(){return null},apply(e,t){let r=e.getMeta(Gr);if(r!=null)return r==-1?null:r;if(t==null||!e.docChanged)return t;let{deleted:i,pos:s}=e.mapping.mapResult(t);return i?null:s}},props:{decorations:c5,handleDOMEvents:{mousedown:w5},createSelectionBetween(e){if(Gr.getState(e.state)!=null)return e.state.selection},handleTripleClick:b5,handleKeyDown:y5,handlePaste:v5},appendTransaction(e,t,r){return f5(r,Av(r,t),n)}})}function Bv(n,e,t,r,i,s){var u;let o=0,l=!0,a=e.firstChild;const c=n.firstChild;if(c)for(let d=0,f=0;d<c.childCount;d+=1){const{colspan:h,colwidth:p}=c.child(d).attrs;for(let g=0;g<h;g+=1,f+=1){const v=i===f?s:p&&p[g],w=v?`${v}px`:"";o+=v||r,v||(l=!1),a?(a.style.width!==w&&(a.style.width=w),a=a.nextSibling):e.appendChild(document.createElement("col")).style.width=w}}for(;a;){const d=a.nextSibling;(u=a==null?void 0:a.parentNode)==null||u.removeChild(a),a=d}l?(t.style.width=`${o}px`,t.style.minWidth=""):(t.style.width="",t.style.minWidth=`${o}px`)}class Z5{constructor(e,t){vr(this,"node");vr(this,"cellMinWidth");vr(this,"dom");vr(this,"table");vr(this,"colgroup");vr(this,"contentDOM");this.node=e,this.cellMinWidth=t,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")),Bv(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(e){return e.type!==this.node.type?!1:(this.node=e,Bv(e,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(e){return e.type==="attributes"&&(e.target===this.table||this.colgroup.contains(e.target))}}function $v(n,e){return n.createAndFill()}function X5(n){if(n.cached.tableNodeTypes)return n.cached.tableNodeTypes;const e={};return Object.keys(n.nodes).forEach(t=>{const r=n.nodes[t];r.spec.tableRole&&(e[r.spec.tableRole]=r)}),n.cached.tableNodeTypes=e,e}function Q5(n,e,t,r,i){const s=X5(n),o=[],l=[];for(let c=0;c<t;c+=1){const u=$v(s.cell);if(u&&l.push(u),r){const d=$v(s.header_cell);d&&o.push(d)}}const a=[];for(let c=0;c<e;c+=1)a.push(s.row.createChecked(null,r&&c===0?o:l));return s.table.createChecked(null,a)}function eL(n){return n instanceof Se}const _c=({editor:n})=>{const{selection:e}=n.state;if(!eL(e))return!1;let t=0;const r=Ru(e.ranges[0].$from,s=>s.type.name==="table");return r==null||r.node.descendants(s=>{if(s.type.name==="table")return!1;["tableCell","tableHeader"].includes(s.type.name)&&(t+=1)}),t===e.ranges.length?(n.commands.deleteTable(),!0):!1},tL=Ve.create({name:"table",addOptions(){return{HTMLAttributes:{},resizable:!1,handleWidth:5,cellMinWidth:25,View:Z5,lastColumnResizable:!0,allowTableNodeSelection:!1}},content:"tableRow+",tableRole:"table",isolating:!0,group:"block",parseHTML(){return[{tag:"table"}]},renderHTML({node:n,HTMLAttributes:e}){let t=0,r=!0;try{n.content.firstChild.content.forEach(s=>{if(s.attrs.colwidth)s.attrs.colwidth.forEach(o=>{o?t+=o:(r=!1,t+=this.options.cellMinWidth)});else{r=!1;const o=s.attrs.colspan?s.attrs.colspan:1;t+=this.options.cellMinWidth*o}})}catch{r=!1}return r&&t>0?e.style=`width: ${t}px;`:t&&t>0?e.style=`min-width: ${t}px`:e.style=null,["div",{class:"table-wrapper"},["table",Ce(this.options.HTMLAttributes,e),["tbody",0]]]},addCommands(){return{insertTable:({rows:n=3,cols:e=3,withHeaderRow:t=!0}={})=>({tr:r,dispatch:i,editor:s})=>{const{selection:o}=r,l=Q5(s.schema,n,e,t);if(i){const a=r.selection.anchor+1;r.replaceRangeWith(o.from-1,o.to,l).scrollIntoView().setSelection(ce.near(r.doc.resolve(a)))}return!0},addColumnBefore:()=>({state:n,dispatch:e})=>k5(n,e),addColumnAfter:()=>({state:n,dispatch:e})=>S5(n,e),deleteColumn:()=>({state:n,dispatch:e})=>T5(n,e),addRowBefore:()=>({state:n,dispatch:e})=>M5(n,e),addRowAfter:()=>({state:n,dispatch:e})=>O5(n,e),deleteRow:()=>({state:n,dispatch:e})=>N5(n,e),deleteTable:()=>({state:n,dispatch:e})=>B5(n,e),mergeCells:()=>({state:n,dispatch:e})=>Nv(n,e),splitCell:()=>({state:n,dispatch:e})=>Dv(n,e),toggleHeaderColumn:()=>({state:n,dispatch:e})=>Zo("column")(n,e),toggleHeaderRow:()=>({state:n,dispatch:e})=>Zo("row")(n,e),toggleHeaderCell:()=>({state:n,dispatch:e})=>P5(n,e),mergeOrSplit:()=>({state:n,dispatch:e})=>Nv(n,e)?!0:Dv(n,e),setCellAttribute:(n,e)=>({state:t,dispatch:r})=>L5(n,e)(t,r),goToNextCell:()=>({state:n,dispatch:e})=>Lv(1)(n,e),goToPreviousCell:()=>({state:n,dispatch:e})=>Lv(-1)(n,e),fixTables:()=>({state:n,dispatch:e})=>(e&&Av(n),!0),setCellSelection:n=>({tr:e,dispatch:t})=>{if(t){const r=Se.create(e.doc,n.anchorCell,n.headCell);e.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:_c,"Mod-Backspace":_c,Delete:_c,"Mod-Delete":_c}},addProseMirrorPlugins(){return[...this.options.resizable&&this.editor.isEditable?[j5({handleWidth:this.options.handleWidth,cellMinWidth:this.options.cellMinWidth,View:this.options.View,lastColumnResizable:this.options.lastColumnResizable})]:[],Y5({allowTableNodeSelection:this.options.allowTableNodeSelection})]},extendNodeSchema(n){const e={name:n.name,options:n.options,storage:n.storage};return{tableRole:ge(re(n,"tableRole",e))}}});function jv(n,e){if(n==null)return{};var t={},r=Object.keys(n),i,s;for(s=0;s<r.length;s++)i=r[s],!(e.indexOf(i)>=0)&&(t[i]=n[i]);return t}var Hv=typeof window<"u"&&typeof document<"u";function mh(n,e){n&&(typeof n=="function"&&n(e),{}.hasOwnProperty.call(n,"current")&&(n.current=e))}function Vv(){return Hv&&document.createElement("div")}function nL(n){var e={"data-placement":n.placement};return n.referenceHidden&&(e["data-reference-hidden"]=""),n.escaped&&(e["data-escaped"]=""),e}function zv(n,e){if(n===e)return!0;if(typeof n=="object"&&n!=null&&typeof e=="object"&&e!=null){if(Object.keys(n).length!==Object.keys(e).length)return!1;for(var t in n)if(e.hasOwnProperty(t)){if(!zv(n[t],e[t]))return!1}else return!1;return!0}else return!1}function rL(n){var e=[];return n.forEach(function(t){e.find(function(r){return zv(t,r)})||e.push(t)}),e}function iL(n,e){var t,r;return Object.assign({},e,{popperOptions:Object.assign({},n.popperOptions,e.popperOptions,{modifiers:rL([].concat(((t=n.popperOptions)==null?void 0:t.modifiers)||[],((r=e.popperOptions)==null?void 0:r.modifiers)||[]))})})}var gh=Hv?O.useLayoutEffect:O.useEffect;function sL(n){var e=O.useRef();return e.current||(e.current=typeof n=="function"?n():n),e.current}function Uv(n,e,t){t.split(/\s+/).forEach(function(r){r&&n.classList[e](r)})}var oL={name:"className",defaultValue:"",fn:function(e){var t=e.popper.firstElementChild,r=function(){var l;return!!((l=e.props.render)!=null&&l.$$tippy)};function i(){if(e.props.className&&!r()){process.env.NODE_ENV!=="production"&&console.warn(["@tippyjs/react: Cannot use `className` prop in conjunction with","`render` prop. Place the className on the element you are","rendering."].join(" "));return}Uv(t,"add",e.props.className)}function s(){r()&&Uv(t,"remove",e.props.className)}return{onCreate:i,onBeforeUpdate:s,onAfterUpdate:i}}};function lL(n){function e(t){var r=t.children,i=t.content,s=t.visible,o=t.singleton,l=t.render,a=t.reference,c=t.disabled,u=c===void 0?!1:c,d=t.ignoreAttributes,f=d===void 0?!0:d;t.__source,t.__self;var h=jv(t,["children","content","visible","singleton","render","reference","disabled","ignoreAttributes","__source","__self"]),p=s!==void 0,g=o!==void 0,v=O.useState(!1),w=v[0],S=v[1],C=O.useState({}),y=C[0],k=C[1],E=O.useState(),T=E[0],N=E[1],_=sL(function(){return{container:Vv(),renders:1}}),A=Object.assign({ignoreAttributes:f},h,{content:_.container});p&&(process.env.NODE_ENV!=="production"&&["trigger","hideOnClick","showOnCreate"].forEach(function(V){A[V]!==void 0&&console.warn(["@tippyjs/react: Cannot specify `"+V+"` prop in","controlled mode (`visible` prop)"].join(" "))}),A.trigger="manual",A.hideOnClick=!1),g&&(u=!0);var R=A,P=A.plugins||[];l&&(R=Object.assign({},A,{plugins:g&&o.data!=null?[].concat(P,[{fn:function(){return{onTrigger:function(J,G){var ie=o.data.children.find(function(X){var we=X.instance;return we.reference===G.currentTarget});J.state.$$activeSingletonInstance=ie.instance,N(ie.content)}}}}]):P,render:function(){return{popper:_.container}}}));var $=[a].concat(r?[r.type]:[]);return gh(function(){var V=a;a&&a.hasOwnProperty("current")&&(V=a.current);var U=n(V||_.ref||Vv(),Object.assign({},R,{plugins:[oL].concat(A.plugins||[])}));return _.instance=U,u&&U.disable(),s&&U.show(),g&&o.hook({instance:U,content:i,props:R,setSingletonContent:N}),S(!0),function(){U.destroy(),o==null||o.cleanup(U)}},$),gh(function(){var V;if(_.renders===1){_.renders++;return}var U=_.instance;U.setProps(iL(U.props,R)),(V=U.popperInstance)==null||V.forceUpdate(),u?U.disable():U.enable(),p&&(s?U.show():U.hide()),g&&o.hook({instance:U,content:i,props:R,setSingletonContent:N})}),gh(function(){var V;if(l){var U=_.instance;U.setProps({popperOptions:Object.assign({},U.props.popperOptions,{modifiers:[].concat((((V=U.props.popperOptions)==null?void 0:V.modifiers)||[]).filter(function(J){var G=J.name;return G!=="$$tippyReact"}),[{name:"$$tippyReact",enabled:!0,phase:"beforeWrite",requires:["computeStyles"],fn:function(G){var ie,X=G.state,we=(ie=X.modifiersData)==null?void 0:ie.hide;(y.placement!==X.placement||y.referenceHidden!==(we==null?void 0:we.isReferenceHidden)||y.escaped!==(we==null?void 0:we.hasPopperEscaped))&&k({placement:X.placement,referenceHidden:we==null?void 0:we.isReferenceHidden,escaped:we==null?void 0:we.hasPopperEscaped}),X.attributes.popper={}}}])})})}},[y.placement,y.referenceHidden,y.escaped].concat($)),O.createElement(O.Fragment,null,r?O.cloneElement(r,{ref:function(U){_.ref=U,mh(r.ref,U)}}):null,w&&nn.createPortal(l?l(nL(y),T,_.instance):i,_.container))}return e}var aL=function(n,e){return O.forwardRef(function(r,i){var s=r.children,o=jv(r,["children"]);return O.createElement(n,Object.assign({},e,o),s?O.cloneElement(s,{ref:function(a){mh(i,a),mh(s.ref,a)}}):null)})},cL=aL(lL(fi));const uL=[{name:"Add row above",action:n=>n.chain().focus().addRowBefore().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M22 14a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v7h2v-2h4v2h2v-2h4v2h2v-2h4v2h2v-7M4 14h4v3H4v-3m6 0h4v3h-4v-3m10 0v3h-4v-3h4m-9-4h2V7h3V5h-3V2h-2v3H8v2h3v3Z"})})},{name:"Add row below",action:n=>n.chain().focus().addRowAfter().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M22 10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V3h2v2h4V3h2v2h4V3h2v2h4V3h2v7M4 10h4V7H4v3m6 0h4V7h-4v3m10 0V7h-4v3h4m-9 4h2v3h3v2h-3v3h-2v-3H8v-2h3v-3Z"})})},{name:"Add left column",action:n=>n.chain().focus().addColumnBefore().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M13 2a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h9V2h-9m7 8v4h-7v-4h7m0 6v4h-7v-4h7m0-12v4h-7V4h7M9 11H6V8H4v3H1v2h3v3h2v-3h3v-2Z"})})},{name:"Add right column",action:n=>n.chain().focus().addColumnAfter().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M11 2a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H2V2h9m-7 8v4h7v-4H4m0 6v4h7v-4H4M4 4v4h7V4H4m11 7h3V8h2v3h3v2h-3v3h-2v-3h-3v-2Z"})})},{name:"Remove row",action:n=>n.chain().focus().deleteRow().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M9.41 13L12 15.59L14.59 13L16 14.41L13.41 17L16 19.59L14.59 21L12 18.41L9.41 21L8 19.59L10.59 17L8 14.41L9.41 13M22 9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v3M4 9h4V6H4v3m6 0h4V6h-4v3m6 0h4V6h-4v3Z"})})},{name:"Remove column",action:n=>n.chain().focus().deleteColumn().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M4 2h7a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2m0 8v4h7v-4H4m0 6v4h7v-4H4M4 4v4h7V4H4m13.59 8L15 9.41L16.41 8L19 10.59L21.59 8L23 9.41L20.41 12L23 14.59L21.59 16L19 13.41L16.41 16L15 14.59L17.59 12Z"})})},{name:"Toggle header row",action:n=>n.chain().focus().toggleHeaderRow().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M22 14a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-4a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v4M4 14h4v-4H4v4m6 0h4v-4h-4v4m6 0h4v-4h-4v4Z"})})},{name:"Toggle header column",action:n=>n.chain().focus().toggleHeaderColumn().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M8 2h8a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2m0 8v4h8v-4H8m0 6v4h8v-4H8M8 4v4h8V4H8Z"})})},{name:"Toggle header cell",action:n=>n.chain().focus().toggleHeaderCell().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M21 19a1 1 0 0 1-1 1h-1v-2h2v1m-6 1v-2h2v2h-2m-4 0v-2h2v2h-2m-4 0v-2h2v2H7m-3 0a1 1 0 0 1-1-1v-1h2v2H4M19 4H5a2 2 0 0 0-2 2v2h18V6c0-1.11-.89-2-2-2M5 14H3v2h2v-2m0-4H3v2h2v-2m16 0h-2v2h2v-2m0 4h-2v2h2v-2m-10 2v-2h2v2h-2m0-4v-2h2v2h-2"})})},{name:"Remove table",action:n=>n.chain().focus().deleteTable().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M12.35 20H10v-3h2.09c.12-.72.37-1.39.72-2H10v-3h4v1.54c.58-.54 1.25-.93 2-1.19V12h4v.35c.75.26 1.42.65 2 1.19V5c0-1.1-.9-2-2-2H4c-1.1 0-2 .9-2 2v15c0 1.1.9 2 2 2h9.54c-.54-.58-.93-1.25-1.19-2M16 7h4v3h-4V7m-6 0h4v3h-4V7M8 20H4v-3h4v3m0-5H4v-3h4v3m0-5H4V7h4v3m6.46 5.88l1.42-1.42L18 16.59l2.12-2.13l1.42 1.42L19.41 18l2.13 2.12l-1.42 1.42L18 19.41l-2.12 2.13l-1.42-1.42L16.59 18l-2.13-2.12"})})}],Wv=({node:n,getPos:e,selected:t,editor:r})=>{const[i,s]=O.useState(!1),o=Ul(),l=O.useRef(null),a=()=>{const{from:u,to:d}=r.state.selection,f=e(),h=f+n.nodeSize;s(f<=u&&d<=h)};O.useEffect(()=>(r.on("selectionUpdate",a),setTimeout(a,100),()=>{r.off("selectionUpdate",a)}));const c=()=>{var f,h;let u=(f=l.current)==null?void 0:f.clientTop;u&&(u+=5);let d=(h=l.current)==null?void 0:h.clientLeft;return d&&(d+=5),{top:`${u}px`,left:`${d}px`}};return D.jsxs(bo,{className:"group",children:[D.jsx(Kg,{as:"span"}),(i||t)&&D.jsx(cL,{appendTo:document.body,trigger:"click",interactive:!0,animation:"shift-toward-subtle",placement:"right-start",content:D.jsx("article",{className:"dropdown",contentEditable:!1,children:D.jsx("ul",{tabIndex:0,className:"dropdown-content fixed menu menu-compact p-2 shadow bg-base-100 rounded-box w-56",style:c(),children:uL.map(u=>D.jsx("li",{children:D.jsxs("button",{type:"button",className:"button",onClick:()=>u.action(r),children:[D.jsx("span",{children:u.icon}),D.jsx("span",{children:u.name})]})},u.name))})}),children:D.jsx("label",{tabIndex:0,className:Fe("trigger-button",{hidden:o}),contentEditable:!1,children:D.jsx(GE,{fontSize:"small"})})})]})},dL=Ve.create({name:"tableCell",addOptions(){return{HTMLAttributes:{}}},content:"block+",addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:n=>{const e=n.getAttribute("colwidth");return e?[parseInt(e,10)]:null}}}},tableRole:"cell",isolating:!0,parseHTML(){return[{tag:"td"}]},renderHTML({HTMLAttributes:n}){return["td",Ce(this.options.HTMLAttributes,n),0]},addNodeView(){return hi(Wv,{as:"td",className:"relative"})}}),fL=Ve.create({name:"tableHeader",addOptions(){return{HTMLAttributes:{}}},content:"block+",addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:n=>{const e=n.getAttribute("colwidth");return e?[parseInt(e,10)]:null}}}},tableRole:"header_cell",isolating:!0,parseHTML(){return[{tag:"th"}]},renderHTML({HTMLAttributes:n}){return["th",Ce(this.options.HTMLAttributes,n),0]},addNodeView(){return hi(Wv,{as:"th",className:"relative"})}}),qv=n=>(n.stopPropagation(),n.preventDefault(),n),hL=function(n){const e=n.scrollHeight>n.clientHeight,r=window.getComputedStyle(n).overflowY.indexOf("hidden")!==-1;return e&&!r},Kv=function(n){return!n||n===document.body?document.body:hL(n)?n:Kv(n.parentNode)},yh=(n,e,t)=>{const r=document.createElement(n);if(!r)throw new Error(`Element with name ${n} can't be created.`);return e&&Object.entries(e).forEach(([i,s])=>r.setAttribute(i,s)),t&&Object.entries(t).forEach(([i,s])=>r.addEventListener(i,s)),r},pL=Ve.create({name:"tableRow",addOptions(){return{HTMLAttributes:{}}},content:"(tableCell | tableHeader)*",tableRole:"row",parseHTML(){return[{tag:"tr"}]},renderHTML({HTMLAttributes:n}){return["tr",Ce(this.options.HTMLAttributes,n),0]},addNodeView(){return({editor:n,HTMLAttributes:e,getPos:t})=>{const r=()=>t(),i=Kv(n.options.element);let s=!1;const o={deleteRow:()=>{this.editor.chain().deleteNode("tableRow").focus().run()},selectRow:()=>{const w=r(),S=n.state.doc.resolve(w),C=new se(S);n.view.dispatch(n.state.tr.setSelection(C))}},l=()=>{s=!0},a=()=>{s=!1},c=yh("section",{class:"absolute hidden flex items-center w-2 bg-gray-200 z-50 cursor-pointer border-1 border-indigo-600 rounded-l opacity-25 hover:opacity-100",contenteditable:"false"},{click:w=>{w&&qv(w),o.selectRow()},mouseenter:()=>{l()},mouseover:()=>{l()},mouseleave:()=>{a(),f()}}),u=yh("button",{class:"text-sm px-1 absolute -translate-x-[125%] hover:active:-translate-x-[125%] mr-2"},{click:w=>{w&&qv(w),o.deleteRow()}}),d=()=>{g(),c.classList.remove("hidden")},f=()=>{setTimeout(()=>{s||c.classList.add("hidden")},100)},h=yh("tr",{...e},{mouseenter:d,mouseover:d,mouseleave:f});c.append(u),document.body.append(c);let p="";const g=()=>{setTimeout(()=>{const w=h.getBoundingClientRect(),S=JSON.stringify(w);p!==S&&(c.style.top=`${w.top+document.documentElement.scrollTop}px`,c.style.left=`${w.x+document.documentElement.scrollLeft-8}px`,c.style.height=`${w.height+1}px`,p=S)})};return setTimeout(()=>{g()},100),n.on("selectionUpdate",g),n.on("update",g),i==null||i.addEventListener("scroll",g),document.addEventListener("scroll",g),{dom:h,contentDOM:h,destroy:()=>{c.remove(),n.off("selectionUpdate",g),n.off("update",g),i==null||i.removeEventListener("scroll",g),document.removeEventListener("scroll",g)}}}}}),mL=[tL.configure({resizable:!0}),dL,fL,pL],gL=Hb.extend({content:"(dBlock|columns)+"});function Jv({types:n,node:e}){return e!=null&&e.type?Array.isArray(n)&&n.includes(e.type)||e.type===n:!1}const yL=Ue.create({name:"trailingNode",addOptions(){return{node:"paragraph",notAfter:["paragraph"]}},addProseMirrorPlugins(){const n=new We(this.name),e=Object.entries(this.editor.schema.nodes).map(([,t])=>t).filter(t=>this.options.notAfter.includes(t.name));return[new je({key:n,appendTransaction:(t,r,i)=>{const{doc:s,tr:o,schema:l}=i,a=n.getState(i),c=s.content.size,u=l.nodes[this.options.node];if(a)return o.insert(c,u.create())},state:{init:(t,r)=>{const i=r.tr.doc.lastChild;return!Jv({node:i,types:e})},apply:(t,r)=>{var s,o,l;if(!t.docChanged)return r;const i=(l=(o=(s=t.doc.lastChild)==null?void 0:s.content)==null?void 0:o.content)==null?void 0:l[0];return!Jv({node:i,types:e})}}})]}}),bL=({node:n,editor:e,getPos:t})=>{const[r,i]=O.useState(""),s=Ul(),o=["https://twitter.com","https://x.com"],l=()=>{switch(n.attrs.data){case"twitter":return D.jsx(f0,{});case"iframe":return D.jsx(h0,{});default:return D.jsx(sT,{})}},a=()=>{switch(n.attrs.data){case"twitter":return"Embed a Twitter tweet";case"iframe":return"Embed a video";default:return"Embed an URL"}},c=()=>{if(!r){alert("Please enter a url");return}let p=r;if(r.includes("<iframe")){const C=r.match(/src="([^"]*)"/);C&&C.length>0&&(p=C[1])}else switch(!0){case/youtu\.?be(?:\.com)?\/(?:.*v(?:\/|=)|(?:.*\/)?)([a-zA-Z0-9-_]+)/.test(r):{const C=r.match(/youtu\.?be(?:\.com)?\/(?:.*v(?:\/|=)|(?:.*\/)?)([a-zA-Z0-9-_]+)/);C&&C.length>0&&(p=`https://www.youtube.com/embed/${C[1]}`);break}case/vimeo\.com\/([a-zA-Z0-9-_]+)/.test(r):{const C=r.match(/vimeo\.com\/([a-zA-Z0-9-_]+)/);C&&C.length>0&&(p=`https://player.vimeo.com/video/${C[1]}`);break}default:{alert("Please enter a valid url");return}}const g=640,v=360,w=t(),S=w+n.nodeSize;p&&(e==null||e.chain().focus(w).deleteRange({from:w,to:S}).setIframe({src:p,width:g,height:v}).run())},u=()=>{if(!r){alert("Please enter a url");return}let p=r;const g=o.some(y=>r.includes(y)),v=r.match(/\/status\/([0-9]*)/),w=v&&v.length>0;if(g&&w)p=v[1];else{alert("invalid url");return}const S=t(),C=S+n.nodeSize;p&&(e==null||e.chain().focus(S).deleteRange({from:S,to:C}).setTweetEmbed({tweetId:p}).run())},f=y1(()=>{switch(n.attrs.data){case"twitter":u();break;default:c();break}},500);O.useEffect(()=>{r&&f()},[r]),O.useEffect(()=>{e==null||e.chain().focus()},[]);const h=O.useRef(null);return O.useEffect(()=>{var p;(p=h.current)==null||p.focus()},[]),D.jsx(bo,{as:"div",className:"flex gap-2 group w-full relative justify-center items-start",children:!s&&D.jsxs("div",{className:"relative w-full",children:[D.jsx("div",{className:"absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none",children:l()}),D.jsx("input",{ref:h,value:r,placeholder:a(),onChange:p=>i(p.target.value),onClick:p=>p.stopPropagation(),className:"bg-stone-200 p-3 pl-10 rounded-xl w-full hover:bg-stone-300 cursor-pointer transition-all ease-in-out"})]})})},vL=Ve.create({name:"actionButton",group:"block",content:"block*",atom:!0,draggable:!0,addOptions(){return{HTMLAttributes:{class:"rounded-lg bg-stone-500"}}},addAttributes(){return{data:{default:null}}},addNodeView(){return hi(bL)},parseHTML(){return[{tag:"div[data-action-node]"}]},renderHTML({HTMLAttributes:n}){return console.log("action"),["div",Ce(n,{"data-action-node":""}),0]},addCommands(){return{setActionButton:n=>({commands:e})=>e.insertContent({type:this.name,attrs:{data:n},content:[]})}}}),wL=[u_,a_.configure({strike:{HTMLAttributes:{class:"select-text pointer-events-auto"}},bold:{HTMLAttributes:{class:"select-text pointer-events-auto"}},italic:{HTMLAttributes:{class:"select-text pointer-events-auto"}},heading:{HTMLAttributes:{class:"select-text pointer-events-auto"}},paragraph:{HTMLAttributes:{class:"select-text pointer-events-auto"}},bulletList:{HTMLAttributes:{class:"flex flex-col items-start list-disc list-outside space-y-4 ml-6"}},orderedList:{HTMLAttributes:{class:"flex flex-col items-start list-decimal list-outside space-y-4 ml-6"}},listItem:{HTMLAttributes:{class:"leading-normal"}},blockquote:{HTMLAttributes:{class:"rounded-lg bg-stone-100 p-5 font-serif italic text-stone-800"}},codeBlock:{HTMLAttributes:{class:"rounded-lg bg-transparent border border-[#DDE2E4] p-5 font-mono font-medium text-stone-800"}},code:{HTMLAttributes:{class:"rounded-md bg-stone-200 p-1.5 font-mono font-medium text-black text-sm",spellcheck:"false"}},history:!1,gapcursor:!1,dropcursor:!1,document:!1,horizontalRule:!1}),d_.configure({types:["heading","paragraph"]}),X_,L_.configure({HTMLAttributes:{class:"text-blue-500 font-bold transition-colors cursor-pointer select-text pointer-events-auto"},openOnClick:!0}),I_.configure({placeholder:()=>"",includeChildren:!0,showOnlyCurrent:!0}),B_.configure({multicolor:!0}),Z_,V_.configure({HTMLAttributes:{class:"select-text pointer-events-auto"}}),c_,tN,$_.configure({HTMLAttributes:{class:"not-prose space-y-4 ml-2"}}),H_.configure({HTMLAttributes:{class:"flex items-start"},nested:!0}),Vb.configure({width:3,color:"#d1d5db"}),zb,e5,yL,gL,...mL,uN.configure({uploadFn:ST}),eN,nN,oN,vL.extend({addInputRules(){return[Gv(/^(?:twt|###|___\s|\*\*\*\s)$/,"twitter",this.type),Gv(/^(?:ytb|@@@|___\s|\*\*\*\s)$/,"iframe",this.type)]}}),Q_],Gv=(n,e,t)=>new io({find:n,handler:({state:r,range:i,commands:s})=>{const o={data:e},{tr:l}=r,a=i.from,c=i.to;l.insert(a-1,t.create(o)).delete(l.mapping.map(a),l.mapping.map(c)),s.focus(c-1)}}),Yv=["#30bced","#6eeb83","#fa69d1","#ecd444","#ee6352","#db3041","#0ad7f2","#1bff39"],CL=({isPreviewMode:n,data:e,enableCollaboration:t,collaborationId:r})=>{const[i,s]=O.useState({plugin:{title:null}}),[o]=O.useState(new as),l=O.useRef(null),a=[...wL,d3.configure({document:o})];O.useEffect(()=>{if(r&&t){const f=new BO(r||"default-room",o,{signaling:["wss://fileverse-signaling-server-0529292ff51c.herokuapp.com/"]});return l.current=f,()=>{f.destroy(),o.destroy()}}},[r,o]),O.useEffect(()=>{t&&r&&(a.some(h=>h.name==="collaborationCursor")||a.push(f3.configure({provider:l.current,user:{color:Yv[Math.floor(Math.random()*Yv.length)]}})))},[l.current]);const c=FE({extensions:a,editorProps:$O,autofocus:"start"}),u=O.useRef(null),d=f=>{var h;(h=u.current)!=null&&h.contains(f.target)||c==null||c.chain().focus().run()};return O.useEffect(()=>{c==null||c.chain().focus()},[]),O.useEffect(()=>{c==null||c.setEditable(!n)},[n]),O.useEffect(()=>{e&&c&&(c==null||c.commands.setContent(e.editorJSONData),s(e.metaData))},[e,c]),{editor:c,pluginMetaData:i,setPluginMetaData:s,focusEditor:d,ref:u}},xL=({isPreviewMode:n=!1,onPublish:e,data:t,togglePreviewMode:r,enableCollaboration:i,collaborationId:s})=>{const{editor:o,pluginMetaData:l,focusEditor:a,setPluginMetaData:c,ref:u}=CL({isPreviewMode:n,data:t,enableCollaboration:i,collaborationId:s,onPublish:e,togglePreviewMode:r});return o?D.jsx("div",{"data-cy":"single-webpage",className:"bg-[#f9fbfd]",children:D.jsx("div",{className:"h-full flex flex-col overflow-scroll no-scrollbar",children:D.jsxs("div",{className:"w-full h-screen",children:[D.jsx("div",{className:"h-fit relative bg-[#ffffff]",children:D.jsxs("div",{className:"flex items-center justify-center pl-4 pr-4 border-b-1 border gap-2 h-16",children:[D.jsx("div",{className:"grow",children:D.jsx(iw,{isPreviewMode:n,metaData:l,setMetaData:c})}),!n&&D.jsx("div",{className:"grow relative",children:D.jsx(jT,{editor:o})}),D.jsx("div",{children:D.jsx(zl,{onClick:()=>r(n),children:n?"Edit":"Preview"})}),e&&D.jsx("div",{children:D.jsx(zl,{onClick:()=>e({metaData:l,editorJSONData:o.getJSON()}),children:"Publish"})})]})}),D.jsx("main",{className:"h-screen lg:h-full w-full rounded-[8px] flex flex-col justify-start items-center gap-2",children:D.jsx("div",{onClick:a,className:"w-full flex justify-center relative",children:D.jsx("div",{className:"p-12 sm:p-[96px] mt-4 min-h-[900px] shadow-inner bg-white overflow-scroll no-scrollbar rounded-md w-full sm:w-[70%] max-w-[856px]",children:D.jsxs("div",{ref:u,className:"w-full pt-4 h-full",children:[!n&&D.jsxs("div",{children:[D.jsx(NT,{editor:o}),D.jsx(BT,{editor:o,appendTo:u})]}),D.jsx($T,{isPreviewMode:n,children:D.jsx(IE,{editor:o})})]})})})})]})})}):D.jsxs("div",{className:"w-screen h-screen flex flex-col gap-4 justify-center items-center",children:[D.jsx(N0,{}),D.jsx("p",{children:"Loading Editor..."})]})};Bt.DdocEditor=xL,Object.defineProperty(Bt,Symbol.toStringTag,{value:"Module"})});
@@ -11,14 +11,13 @@ export interface DdocProps {
11
11
  onPublish: (data: Data) => void;
12
12
  data?: Data;
13
13
  }
14
- interface Data {
14
+ export interface Data {
15
15
  metaData: PluginMetaData;
16
16
  editorJSONData: JSONContent;
17
17
  }
18
- interface Plugin {
18
+ export interface Plugin {
19
19
  title: string | null;
20
20
  }
21
21
  export interface PluginMetaData {
22
22
  plugin: Plugin;
23
23
  }
24
- export {};
package/package.json CHANGED
@@ -2,10 +2,10 @@
2
2
  "name": "@fileverse-dev/ddoc",
3
3
  "private": false,
4
4
  "description": "DDoc",
5
- "version": "1.0.6",
5
+ "version": "1.0.8",
6
6
  "main": "dist/index.umd.js",
7
7
  "module": "dist/index.es.js",
8
- "types": "dist/index.d.ts",
8
+ "types": "dist/packages/ddoc/types.d.ts",
9
9
  "exports": {
10
10
  ".": {
11
11
  "import": "./dist/index.es.js",