tiptop-editor 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16604,7 +16604,7 @@ const md = (e, t) => {
16604
16604
  isOpen: t,
16605
16605
  onOpenChange: r,
16606
16606
  children: [
16607
- /* @__PURE__ */ b.jsx(At, { children: /* @__PURE__ */ b.jsx("div", { className: "flex items-center gap-0.5", children: /* @__PURE__ */ b.jsx(
16607
+ /* @__PURE__ */ b.jsx(At, { children: /* @__PURE__ */ b.jsx("div", { className: "z-1 flex items-center gap-0.5", children: /* @__PURE__ */ b.jsx(
16608
16608
  Ze,
16609
16609
  {
16610
16610
  size: "sm",
@@ -16915,7 +16915,7 @@ const md = (e, t) => {
16915
16915
  e.off("selectionUpdate", i), e.off("transaction", i);
16916
16916
  };
16917
16917
  }, [e, t, r]), /* @__PURE__ */ b.jsxs(Nt, { placement: "bottom", children: [
16918
- /* @__PURE__ */ b.jsx(At, { children: /* @__PURE__ */ b.jsx("div", { className: "flex items-center gap-0.5", children: /* @__PURE__ */ b.jsx(
16918
+ /* @__PURE__ */ b.jsx(At, { children: /* @__PURE__ */ b.jsx("div", { className: "z-1 flex items-center gap-0.5", children: /* @__PURE__ */ b.jsx(
16919
16919
  Ze,
16920
16920
  {
16921
16921
  size: "sm",
@@ -17026,7 +17026,7 @@ const md = (e, t) => {
17026
17026
  [e]
17027
17027
  );
17028
17028
  return /* @__PURE__ */ b.jsxs(Nt, { placement: "bottom", children: [
17029
- /* @__PURE__ */ b.jsx(At, { children: /* @__PURE__ */ b.jsx("div", { className: "flex items-center gap-0.5", children: /* @__PURE__ */ b.jsx(
17029
+ /* @__PURE__ */ b.jsx(At, { children: /* @__PURE__ */ b.jsx("div", { className: "z-1 flex items-center gap-0.5", children: /* @__PURE__ */ b.jsx(
17030
17030
  Ze,
17031
17031
  {
17032
17032
  size: "sm",
@@ -46,7 +46,7 @@ ${b}
46
46
  `);S.trim()&&(t.customNestedParser?$=t.customNestedParser(S):$=r.blockTokens(S))}const I=t.createToken(g,$);l.push(I)}if(l.length!==0)return{items:l,raw:c}}function Nb(e,t,r,o){if(!e||!Array.isArray(e.content))return"";const a=typeof r=="function"?r(o):r,[n,...s]=e.content,i=t.renderChildren([n]),l=[`${a}${i}`];return s&&s.length>0&&s.forEach(c=>{const d=t.renderChildren([c]);if(d){const u=d.split(`
47
47
  `).map(f=>f?t.indent(f):"").join(`
48
48
  `);l.push(u)}}),l.join(`
49
- `)}var wr=class Zc extends Ac{constructor(){super(...arguments),this.type="node"}static create(t={}){const r=typeof t=="function"?t():t;return new Zc(r)}configure(t){return super.configure(t)}extend(t){const r=typeof t=="function"?t():t;return super.extend(r)}},zb=class{constructor({editor:e,element:t,view:r,options:o,shouldShow:a}){this.preventHide=!1,this.isVisible=!1,this.shouldShow=({view:n,state:s})=>{const{selection:i}=s,{$anchor:l,empty:c}=i,d=l.depth===1,u=l.parent.isTextblock&&!l.parent.type.spec.code&&!l.parent.textContent&&l.parent.childCount===0&&!this.getTextContent(l.parent);return!(!n.hasFocus()||!c||!d||!u||!this.editor.isEditable)},this.floatingUIOptions={strategy:"absolute",placement:"right",offset:8,flip:{},shift:{},arrow:!1,size:!1,autoPlacement:!1,hide:!1,inline:!1},this.updateHandler=(n,s,i,l)=>{const{composing:c}=n;if(c||!s&&!i)return;if(!this.getShouldShow(l)){this.hide();return}this.updatePosition(),this.show()},this.mousedownHandler=()=>{this.preventHide=!0},this.focusHandler=()=>{setTimeout(()=>this.update(this.editor.view))},this.blurHandler=({event:n})=>{var s;if(this.preventHide){this.preventHide=!1;return}n?.relatedTarget&&((s=this.element.parentNode)!=null&&s.contains(n.relatedTarget))||n?.relatedTarget!==this.editor.view.dom&&this.hide()},this.editor=e,this.element=t,this.view=r,this.floatingUIOptions={...this.floatingUIOptions,...o},this.element.tabIndex=0,a&&(this.shouldShow=a),this.element.addEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.editor.on("focus",this.focusHandler),this.editor.on("blur",this.blurHandler),this.update(r,r.state),this.getShouldShow()&&this.show()}getTextContent(e){return Kv(e,{textSerializers:Pc(this.editor.schema)})}get middlewares(){const e=[];return this.floatingUIOptions.flip&&e.push(je.flip(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&e.push(je.shift(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&e.push(je.offset(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&e.push(je.arrow(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&e.push(je.size(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&e.push(je.autoPlacement(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&e.push(je.hide(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&e.push(je.inline(typeof this.floatingUIOptions.inline!="boolean"?this.floatingUIOptions.inline:void 0)),e}getShouldShow(e){var t;const{state:r}=this.view,{selection:o}=r,{ranges:a}=o,n=Math.min(...a.map(l=>l.$from.pos)),s=Math.max(...a.map(l=>l.$to.pos));return(t=this.shouldShow)==null?void 0:t.call(this,{editor:this.editor,view:this.view,state:r,oldState:e,from:n,to:s})}updatePosition(){const{selection:e}=this.editor.state,t=Sc(this.view,e.from,e.to),r={getBoundingClientRect:()=>t,getClientRects:()=>[t]};je.computePosition(r,this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:o,y:a,strategy:n})=>{this.element.style.width="max-content",this.element.style.position=n,this.element.style.left=`${o}px`,this.element.style.top=`${a}px`,this.isVisible&&this.floatingUIOptions.onUpdate&&this.floatingUIOptions.onUpdate()})}update(e,t){const r=!t?.selection.eq(e.state.selection),o=!t?.doc.eq(e.state.doc);this.updateHandler(e,r,o,t)}show(){var e;this.isVisible||(this.element.style.visibility="visible",this.element.style.opacity="1",(e=this.view.dom.parentElement)==null||e.appendChild(this.element),this.floatingUIOptions.onShow&&this.floatingUIOptions.onShow(),this.isVisible=!0)}hide(){this.isVisible&&(this.element.style.visibility="hidden",this.element.style.opacity="0",this.element.remove(),this.floatingUIOptions.onHide&&this.floatingUIOptions.onHide(),this.isVisible=!1)}destroy(){this.hide(),this.element.removeEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.editor.off("focus",this.focusHandler),this.editor.off("blur",this.blurHandler),this.floatingUIOptions.onDestroy&&this.floatingUIOptions.onDestroy()}},zc=e=>new W.Plugin({key:typeof e.pluginKey=="string"?new W.PluginKey(e.pluginKey):e.pluginKey,view:t=>new zb({view:t,...e})});Te.create({name:"floatingMenu",addOptions(){return{element:null,options:{},pluginKey:"floatingMenu",shouldShow:null}},addProseMirrorPlugins(){return this.options.element?[zc({pluginKey:this.options.pluginKey,editor:this.editor,element:this.options.element,options:this.options.options,shouldShow:this.options.shouldShow})]:[]}});var Ic=p.forwardRef(({pluginKey:e="bubbleMenu",editor:t,updateDelay:r,resizeDelay:o,shouldShow:a=null,options:n,children:s,...i},l)=>{const c=p.useRef(document.createElement("div"));typeof l=="function"?l(c.current):l&&(l.current=c.current);const{editor:d}=et.useCurrentEditor();return p.useEffect(()=>{const u=c.current;if(u.style.visibility="hidden",u.style.position="absolute",t?.isDestroyed||d?.isDestroyed)return;const f=t||d;if(!f){console.warn("BubbleMenu component is not rendered inside of an editor component or does not have editor prop.");return}const h=Qc.BubbleMenuPlugin({updateDelay:r,resizeDelay:o,editor:f,element:u,pluginKey:e,shouldShow:a,options:n});return f.registerPlugin(h),()=>{f.unregisterPlugin(e),window.requestAnimationFrame(()=>{u.parentNode&&u.parentNode.removeChild(u)})}},[t,d]),bt.createPortal(m.jsx("div",{...i,children:s}),c.current)});p.forwardRef(({pluginKey:e="floatingMenu",editor:t,shouldShow:r=null,options:o,children:a,...n},s)=>{const i=p.useRef(document.createElement("div"));typeof s=="function"?s(i.current):s&&(s.current=i.current);const{editor:l}=et.useCurrentEditor();return p.useEffect(()=>{const c=i.current;if(c.style.visibility="hidden",c.style.position="absolute",t?.isDestroyed||l?.isDestroyed)return;const d=t||l;if(!d){console.warn("FloatingMenu component is not rendered inside of an editor component or does not have editor prop.");return}const u=zc({editor:d,element:c,pluginKey:e,shouldShow:r,options:o});return d.registerPlugin(u),()=>{d.unregisterPlugin(e),window.requestAnimationFrame(()=>{c.parentNode&&c.parentNode.removeChild(c)})}},[t,l]),bt.createPortal(m.jsx("div",{...n,children:a}),i.current)});const $e=p.memo(({name:e,className:t,strokeWidth:r})=>{const o=ed.icons[e];return o?m.jsx(o,{className:gr("w-4 h-4",t),strokeWidth:r||2.5}):null});$e.displayName="Icon";const Ib=({editor:e,buttonKey:t,tooltipText:r,isIconOnly:o=!1,color:a="default",variant:n="light",isDisabled:s=!1,icon:i="AtSign",iconClass:l,text:c="Button",withActive:d=!1,onPressed:u})=>{const[f,h]=p.useState(()=>e.isActive(t));p.useEffect(()=>{const v=()=>h(e.isActive(t));return e.on("selectionUpdate",v),e.on("transaction",v),()=>{e.off("selectionUpdate",v),e.off("transaction",v)}},[e,t]);const g=p.useCallback(()=>{u?.()},[u]);return m.jsx(Vt,{delay:250,closeDelay:0,content:r,isDisabled:r==null,children:m.jsx(Ze,{size:"sm","data-active":d?f:!1,color:a,variant:n,isIconOnly:o,isDisabled:s,className:"text-foreground-500 hover:text-foreground data-[active=true]:bg-divider/45 data-[active=true]:text-primary data-[active=true]:hover:bg-divider/45 data-[active=true]:hover:text-foreground",onPress:g,children:o?m.jsx($e,{name:i,className:l}):c})})},Xt=p.memo(Ib),Db=La.createLowlight(La.all),Dc=td.configure({lowlight:Db}),_c=rd.extend({renderHTML(){return["div",Yt(this.options.HTMLAttributes,{"data-type":this.name}),["hr"]]}}),jc=e=>{const{state:t}=e,{selection:r,doc:o}=t,{empty:a,from:n,to:s}=r,i=!o.textBetween(n,s).length&&$a(r),l=r instanceof W.NodeSelection;return!(a||i||l)},_b=e=>{const{state:t}=e,{selection:r,doc:o}=t;if(!(r instanceof W.TextSelection))return!1;let a=!1;return o.nodesBetween(r.from,r.to,n=>n.isText?(a=!0,!1):!0),a},jb=e=>e.state.selection instanceof he.CellSelection,Ob=e=>[Dc.name,_c.name].some(r=>e.isActive(r)),Oc=e=>{const{state:t}=e,{selection:r}=t,o=["paragraph","code","heading","blockquote","taskList","orderedList"];if(!(r instanceof W.NodeSelection))return;const a=r.node;if(a)return o.includes(a.type.name)&&a.textContent},Lb=e=>{const{state:t}=e,{selection:r}=t,o=["horizontalRule","imageUploader"];if(!(r instanceof W.NodeSelection))return;const a=r.node;if(a)return!o.includes(a.type.name)},Fb=e=>{const{state:t}=e,{selection:r}=t;if(!(r instanceof W.NodeSelection))return;const o=r.node;if(!o)return;let a=!1;return o.marks.length?!0:(o.descendants(n=>n.marks?.length?(a=!0,!1):!0),a)},Kb=e=>{const{state:t}=e,{selection:r}=t;if(!(r instanceof W.NodeSelection))return;const o=r.node;if(o)return o.textContent.trim().length>0},Bb=e=>{const{selection:t,doc:r}=e;let o;if(t instanceof W.NodeSelection)o=t.node;else{const a=r.resolve(t.from);o=a.nodeAfter||a.parent}return o?o.type.name==="imageUploader"&&o.attrs?.id&&o.attrs?.uploading:!1},Rb=e=>{const{state:t}=e,{selection:r,doc:o}=t,a=r instanceof W.NodeSelection?r:W.NodeSelection.create(o,r.from),n=a.node,s=a.from;if(!n)return;const i=n.toJSON();e.chain().focus().command(({tr:l,dispatch:c,state:d})=>{const u=s+n.nodeSize,f=d.schema.nodeFromJSON(i);return l.insert(u,f),c&&c(l),!0}).run(),setTimeout(()=>{e.view.updateState(e.state);const l=s+n.nodeSize,c=W.NodeSelection.create(e.state.doc,l);e.view.dispatch(e.state.tr.setSelection(c))},0)},Hb=e=>{const{state:t}=e,{selection:r}=t;if(!(r instanceof W.NodeSelection))return;const o=r.node;if(!o)return;const a=o.textContent;a&&navigator.clipboard.writeText(a).catch(n=>{console.error("Failed to copy to clipboard:",n)})},Ub=e=>{const{state:t}=e,{selection:r}=t;if(!(r instanceof W.NodeSelection))return;const{from:o,to:a}=r,{node:n}=r,{attrs:s}=n;if(n.type.name==="imageUploader"&&s.id&&s.uploading){e?.storage.imageUploaderExtension.cancelUpload(e,s.id),e.view.focus(),s?.uploading;return}e.chain().focus().deleteRange({from:o,to:a}).run(),e.view.focus()},Vb=e=>{const{state:t}=e,{selection:r}=t;if(!(r instanceof W.NodeSelection))return;const o=r.node,a=r.from;if(!o)return;const n=o.textContent;if(!n.trim()){e.chain().focus().command(({tr:s,dispatch:i})=>{const l=t.schema.nodes.paragraph.create();return s.replaceWith(a,a+o.nodeSize,l),i&&i(s),!0}).run();return}e.chain().focus().command(({tr:s,dispatch:i,state:l})=>{const c=l.schema.text(n),d=l.schema.nodes.paragraph.create(null,c);return s.replaceWith(a,a+o.nodeSize,d),i&&i(s),!0}).run(),setTimeout(()=>{e.view.updateState(e.state);try{const s=W.NodeSelection.create(e.state.doc,a);e.view.dispatch(e.state.tr.setSelection(s))}catch{e.commands.setTextSelection(a)}},0)},Wb=(e,t)=>{const{state:r}=e,{selection:o}=r,a=()=>{const s={paragraph:()=>e.chain().focus().setNode("paragraph").run(),heading1:()=>e.chain().focus().toggleHeading({level:1}).run(),heading2:()=>e.chain().focus().toggleHeading({level:2}).run(),heading3:()=>e.chain().focus().toggleHeading({level:3}).run(),blockquote:()=>e.chain().focus().toggleBlockquote().run(),codeBlock:()=>e.chain().focus().toggleCodeBlock().run(),bulletList:()=>e.chain().focus().toggleBulletList().run(),orderedList:()=>e.chain().focus().toggleOrderedList().run(),taskList:()=>e.chain().focus().toggleTaskList().run(),table:()=>e.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run(),horizontalRule:()=>{const{from:i,to:l}=o;return e.chain().focus().deleteRange({from:i,to:l}).insertContent({type:"horizontalRule"}).run()}}[t.key];s&&s()};if(o instanceof W.NodeSelection){const n=o.node,s=o.from;if(!n)return;if(t.key==="horizontalRule"){e.chain().focus().deleteRange({from:s,to:s+n.nodeSize}).insertContent({type:"horizontalRule"}).run();return}if(t.key==="table"){e.chain().focus().deleteRange({from:s,to:s+n.nodeSize}).insertTable({rows:3,cols:3,withHeaderRow:!0}).run();return}const i=s+1,l=s+n.nodeSize-1;e.commands.setTextSelection({from:i,to:l}),a(),["bulletList","orderedList","taskList"].includes(t.key)||setTimeout(()=>{try{const c=W.NodeSelection.create(e.state.doc,s);e.view.dispatch(e.state.tr.setSelection(c))}catch{e.commands.setTextSelection(s)}},0)}else a()},Gb=(e,t)=>{e&&t!==null&&e.chain().focus().extendMarkRange("link").setLink({href:t}).run()},qb=e=>{if(!e)return;e.getAttributes("link")?.href&&e.chain().focus().extendMarkRange("link").unsetLink().run()},Yb=async({file:e,url:t,onProgress:r,signal:o})=>new Promise((a,n)=>{const s=new XMLHttpRequest;o&&o.addEventListener("abort",()=>{s.abort(),n(new Error("AbortError"))}),s.upload.addEventListener("progress",l=>{if(l.lengthComputable){const c=Math.round(l.loaded/l.total*100);if(!r(c)){s.abort(),n(new Error("AbortError"));return}}}),s.addEventListener("load",()=>{if(s.status>=200&&s.status<300)try{const l=JSON.parse(s.responseText);a(l)}catch{n(new Error("Invalid JSON response"))}else n(new Error(`Upload failed with status ${s.status}`))}),s.addEventListener("error",()=>{n(new Error("Network error during upload"))}),s.addEventListener("abort",()=>{n(new Error("AbortError"))});const i=new FormData;i.append("file",e),s.open("POST",t),s.send(i)}),Xb=(e,t)=>(Array.isArray(t)?t:t.split(".").filter(Boolean)).reduce((o,a)=>{if(!(o==null||typeof o!="object"))return o[a]},e),Jb=()=>`upload-${Date.now()}-${Math.random().toString(36).substring(2,8)}`,fo=(e,t,r)=>{const{state:o,view:a}=e,{doc:n}=o;let s=null;if(typeof t.pos=="number")s=t.pos;else if(t.id){let l=null;n.descendants((c,d)=>c.type.name==="imageUploader"&&c.attrs.id===t.id?(l=d,!1):!0),s=l}if(s===null){console.log("Could not find imageUploader node to update");return}const i=o.tr.setNodeMarkup(s,void 0,{...o.doc.nodeAt(s)?.attrs,...r});a.dispatch(i)};function Zb(e,t,r,o){const a=r+t.nodeSize,n=t.textContent,s=[];e.nodesBetween(r+1,a-1,(d,u)=>{if(d.isText&&d.text)for(let f=0;f<d.text.length;f++)s.push(u+f);return!0});const i=[],l=/\S+/g;let c;for(;(c=l.exec(n))!==null;){const d=c.index,u=c.index+c[0].length;i.push({index:i.length,text:c[0],absFrom:s[d]??r+1+d,absTo:s[u-1]!==void 0?s[u-1]+1:r+1+u})}return{index:o,type:t.type.name,text:n,absFrom:r,absTo:a,words:i,charMap:s}}const ho=e=>{const{doc:t}=e.state,r=[];return t.forEach((o,a,n)=>{r.push(Zb(t,o,a,n))}),{nodes:r}};function Lc(e,t){const r=t.nodeIndex!==void 0?e.nodes[t.nodeIndex]:void 0;if(!r)return null;if(t.wordIndex!==void 0){const o=r.words[t.wordIndex];return o?{absFrom:o.absFrom,absTo:o.absTo}:null}if(t.wordRange!==void 0){const[o,a]=t.wordRange,n=r.words[o],s=r.words[a];return!n||!s?null:{absFrom:n.absFrom,absTo:s.absTo}}if(t.charFrom!==void 0&&t.charTo!==void 0){const o=r.charMap[t.charFrom]??r.absFrom+1+t.charFrom,a=t.charTo>0&&r.charMap[t.charTo-1]!==void 0?r.charMap[t.charTo-1]+1:r.absFrom+1+t.charTo;return{absFrom:o,absTo:a}}return{absFrom:r.absFrom+1,absTo:r.absTo-1}}function Fc(e,t,r){const{schema:o,doc:a}=e.state;if(typeof r=="string"){if(!r)return null;const s=a.resolve(t).marks();return Ne.Fragment.from(o.text(r,s.length?s:void 0))}if(!r.length)return null;const n=r.map(s=>o.nodeFromJSON(s));return Ne.Fragment.from(n)}const Aa=(e,t)=>{const r=ho(e),o=Lc(r,t);if(!o)return!1;const a=Fc(e,o.absFrom,t.replacement),n=a?e.state.tr.replaceWith(o.absFrom,o.absTo,a):e.state.tr.delete(o.absFrom,o.absTo);return e.view.dispatch(n),!0},Kc=(e,t)=>{if(t.length===0)return!0;if(t.length===1)return Aa(e,t[0]);const r=ho(e),o=[];for(const n of t){const s=Lc(r,n);s&&o.push({...s,replacement:n.replacement})}if(o.length===0)return!1;o.sort((n,s)=>s.absFrom-n.absFrom);let a=e.state.tr;for(const n of o){const s=Fc(e,n.absFrom,n.replacement);a=s?a.replaceWith(n.absFrom,n.absTo,s):a.delete(n.absFrom,n.absTo)}return e.view.dispatch(a),!0},Qb=({editor:e})=>{const[t,r]=p.useState(!1),[o,a]=p.useState(""),[n,s]=p.useState(!1),i=p.useCallback(()=>e.getAttributes("link")?.href||"",[e]);p.useEffect(()=>{const f=()=>{const h=i();a(h),s(e.isActive("link",{href:h}))};return e.on("selectionUpdate",f),e.on("transaction",f),()=>{e.off("selectionUpdate",f),e.off("transaction",f)}},[e,i]);const l=p.useCallback(()=>{o&&(Gb(e,o),s(!0))},[e,o]),c=p.useCallback(()=>{o&&window.open(o,"_blank","noopener,noreferrer,nofollow")},[o]),d=p.useCallback(()=>{qb(e),a(""),s(!1),r(!1)},[e]),u=p.useCallback(f=>{f.key==="Enter"&&o&&(f.preventDefault(),l())},[l,o]);return m.jsxs(Nt,{placement:"bottom",isOpen:t,onOpenChange:r,children:[m.jsx(At,{children:m.jsx("div",{className:"flex items-center gap-0.5",children:m.jsx(Ze,{size:"sm","data-active":n,color:"default",variant:"light",isIconOnly:!0,isDisabled:!1,"aria-label":"Link menu",className:"text-foreground-500 hover:text-foreground data-[active=true]:bg-divider/45 data-[active=true]:text-primary data-[active=true]:hover:bg-divider/45 data-[active=true]:hover:text-foreground",onPress:()=>r(f=>!f),children:m.jsx(Vt,{content:"Link",delay:250,closeDelay:0,children:m.jsx("div",{className:"w-full h-full flex items-center justify-center",children:m.jsx($e,{name:"Link"})})})})})}),m.jsx(Mt,{className:"p-1.5",children:m.jsxs("div",{className:"flex items-center gap-1",children:[m.jsx("div",{className:"relative flex flex-wrap items-stretch",children:m.jsx("input",{className:"block w-full h-8 text-sm font-normal leading-1.5 px-2 py-1.5 bg-none appearance-none outline-none",placeholder:"Enter a link...",autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",autoFocus:!0,type:"url",value:o,onChange:f=>a(f.target.value),onKeyDown:u})}),m.jsx(Xt,{isIconOnly:!0,isDisabled:!o,editor:e,buttonKey:"validate",tooltipText:"Set link",icon:"CornerDownLeft",withActive:!1,onPressed:l}),m.jsx(Oe,{orientation:"vertical",className:"h-6"}),m.jsxs("div",{className:"flex items-center gap-1.5",children:[m.jsx(Xt,{isIconOnly:!0,isDisabled:!o,editor:e,buttonKey:"open_in_new_tab",tooltipText:"Open link",icon:"ExternalLink",withActive:!1,onPressed:c}),m.jsx(Xt,{isIconOnly:!0,isDisabled:!o,color:"danger",buttonKey:"remove_link",iconClass:"text-danger",editor:e,tooltipText:"Remove link",icon:"Trash",withActive:!1,onPressed:d})]})]})})]})},em=p.memo(Qb),Bc=({color:e,bgColor:t,buttonType:r})=>m.jsx("span",{className:"relative w-5 h-5 flex items-center justify-center border rounded-full transition-transform duration-200 ease-in-out",style:{borderColor:`hsla(var(${e}), 1)`,backgroundColor:`hsla(var(${t}), 0.7)`},children:r==="text"&&m.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",style:{color:`hsla(var(${e}), 1)`},children:m.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M12.8944 5.55279C12.725 5.214 12.3787 5 12 5C11.6212 5 11.2749 5.214 11.1055 5.55279L5.10555 17.5528C4.85856 18.0468 5.05878 18.6474 5.55276 18.8944C6.04674 19.1414 6.64741 18.9412 6.8944 18.4472L8.64957 14.9369C8.75862 14.9777 8.87671 15 9 15H15C15.1233 15 15.2413 14.9777 15.3504 14.9369L17.1055 18.4472C17.3525 18.9412 17.9532 19.1414 18.4472 18.8944C18.9412 18.6474 19.1414 18.0468 18.8944 17.5528L12.8944 5.55279ZM14.3819 13L12 8.23607L9.61801 13H14.3819Z",fill:"currentColor"})})}),tm=({editor:e,buttonType:t,hsl:r,color:o,bgColor:a,tooltipText:n,tooltipDisabled:s=!1})=>{const i=t==="text"?e.getAttributes("textStyle")?.color===r:e.getAttributes("highlight")?.color===r,l=p.useCallback(()=>{t==="text"?i?e.commands.unsetColor():e.commands.setColor(r):e.commands.toggleHighlight({color:r})},[e,t,r,i]);return m.jsx(Vt,{content:n,delay:250,closeDelay:0,isDisabled:s,children:m.jsx(Ze,{size:"sm",isIconOnly:!0,color:"default",variant:"light",isDisabled:!1,"aria-label":n,"data-active":i,className:"text-foreground-500 data-[active=true]:bg-divider/45 data-[active=true]:hover:bg-divider/45",onPress:l,children:m.jsx("div",{className:"w-full h-full flex items-center justify-center",children:m.jsx(Bc,{color:o,bgColor:a,buttonType:t})})})})},rm=p.memo(tm),Na=[{key:"text",buttonType:"text",title:"Text color",colors:[{hsl:"hsl()",color:"--heroui-foreground",bgColor:"--heroui-background",tooltipText:"Default text"},{hsl:"hsl(0, 0%, 61%)",color:"--text-color-gray",bgColor:"",tooltipText:"Gray text"},{hsl:"hsl(18, 35%, 58%)",color:"--text-color-brown",bgColor:"",tooltipText:"Brown text"},{hsl:"hsl(25, 53%, 53%)",color:"--text-color-orange",bgColor:"",tooltipText:"Orange text"},{hsl:"hsl(36, 54%, 55%)",color:"--text-color-yellow",bgColor:"",tooltipText:"Yellow text"},{hsl:"hsl(145, 32%, 47%)",color:"--text-color-green",bgColor:"",tooltipText:"Green text"},{hsl:"hsl(202, 64%, 52%)",color:"--text-color-blue",bgColor:"",tooltipText:"Blue text"},{hsl:"hsl(270, 55%, 62%)",color:"--text-color-purple",bgColor:"",tooltipText:"Purple text"},{hsl:"hsl(329, 57%, 58%)",color:"--text-color-pink",bgColor:"",tooltipText:"Pink text"},{hsl:"hsl(1, 69%, 60%)",color:"--text-color-red",bgColor:"",tooltipText:"Red text"}]},{key:"highlight",buttonType:"highlight",title:"Highlight color",colors:[{hsl:"hsl()",color:"--heroui-background",bgColor:"--heroui-background",tooltipText:"Default background"},{hsl:"hsl(0, 0%, 61%)",color:"--text-color-gray",bgColor:"--text-color-gray",tooltipText:"Gray background"},{hsl:"hsl(18, 35%, 58%)",color:"--text-color-brown",bgColor:"--text-color-brown",tooltipText:"Brown background"},{hsl:"hsl(25, 53%, 53%)",color:"--text-color-orange",bgColor:"--text-color-orange",tooltipText:"Orange background"},{hsl:"hsl(36, 54%, 55%)",color:"--text-color-yellow",bgColor:"--text-color-yellow",tooltipText:"Yellow background"},{hsl:"hsl(145, 32%, 47%)",color:"--text-color-green",bgColor:"--text-color-green",tooltipText:"Green background"},{hsl:"hsl(202, 64%, 52%)",color:"--text-color-blue",bgColor:"--text-color-blue",tooltipText:"Blue background"},{hsl:"hsl(270, 55%, 62%)",color:"--text-color-purple",bgColor:"--text-color-purple",tooltipText:"Purple background"},{hsl:"hsl(329, 57%, 58%)",color:"--text-color-pink",bgColor:"--text-color-pink",tooltipText:"Pink background"},{hsl:"hsl(1, 69%, 60%)",color:"--text-color-red",bgColor:"--text-color-red",tooltipText:"Red background"}]}],Rc=[{key:"typography",title:"Typography",commands:[{key:"paragraph",title:"Paragraph",icon:"Type",description:"",command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("paragraph").run()}},{key:"heading1",title:"Heading 1",icon:"Heading1",description:"",command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:1}).run()}},{key:"heading2",title:"Heading 2",icon:"Heading2",description:"",command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:2}).run()}},{key:"heading3",title:"Heading 3",icon:"Heading3",description:"",command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:3}).run()}}]},{key:"format",title:"Format",commands:[{key:"bulletList",title:"Bulleted list",icon:"List",description:"",command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleList("bulletList","listItem").run()}},{key:"orderedList",title:"Ordered list",icon:"ListOrdered",description:"",command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleList("orderedList","listItem").run()}},{key:"taskList",title:"Todo list",icon:"ListTodo",description:"",command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleList("taskList","taskItem").run()}},{key:"blockquote",title:"Blockquote",icon:"Quote",description:"",command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleBlockquote().run()}},{key:"codeBlock",title:"Code block",icon:"SquareCode",description:"",command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleCodeBlock().run()}}]},{key:"insert",title:"Insert",commands:[{key:"horizontalRule",title:"Separator",icon:"Minus",description:"",command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setHorizontalRule().run()}},{key:"imageUploader",title:"Image",icon:"Image",description:"",command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).insertImageUploader().run()}},{key:"table",title:"Table",icon:"Table2",description:"",command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).insertTable({rows:3,cols:3,withHeaderRow:!0}).run()}}]}],om=({editor:e})=>{const t=p.useCallback(()=>e.getAttributes("textStyle")?.color||"",[e]),r=p.useCallback(()=>e.getAttributes("highlight")?.color||"",[e]),[o,a]=p.useState(t),[n,s]=p.useState(r);return p.useEffect(()=>{const i=()=>{a(t()),s(r())};return e.on("selectionUpdate",i),e.on("transaction",i),()=>{e.off("selectionUpdate",i),e.off("transaction",i)}},[e,t,r]),m.jsxs(Nt,{placement:"bottom",children:[m.jsx(At,{children:m.jsx("div",{className:"flex items-center gap-0.5",children:m.jsx(Ze,{size:"sm",color:"default",variant:"light",isIconOnly:!0,isDisabled:!1,"aria-label":"Color menu",className:"text-foreground-500",children:m.jsx(Vt,{content:"Color",delay:250,closeDelay:0,children:m.jsx("div",{className:"w-full h-full flex items-center justify-center",children:m.jsx("span",{className:"relative w-5 h-5 flex items-center justify-center border border-divider rounded-full transition-transform duration-200 ease-in-out",style:{borderColor:o||"hsla(var(--heroui-foreground), 0.5)",backgroundColor:n||"hsla(var(--heroui-foreground), 0.5)"},children:m.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",style:{color:o||"hsla(var(--heroui-foreground), 0.5)"},children:m.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M12.8944 5.55279C12.725 5.214 12.3787 5 12 5C11.6212 5 11.2749 5.214 11.1055 5.55279L5.10555 17.5528C4.85856 18.0468 5.05878 18.6474 5.55276 18.8944C6.04674 19.1414 6.64741 18.9412 6.8944 18.4472L8.64957 14.9369C8.75862 14.9777 8.87671 15 9 15H15C15.1233 15 15.2413 14.9777 15.3504 14.9369L17.1055 18.4472C17.3525 18.9412 17.9532 19.1414 18.4472 18.8944C18.9412 18.6474 19.1414 18.0468 18.8944 17.5528L12.8944 5.55279ZM14.3819 13L12 8.23607L9.61801 13H14.3819Z"})})})})})})})}),m.jsx(Mt,{className:"px-1.5 py-2",children:m.jsx("div",{className:"flex flex-col gap-2",children:Na.map(i=>m.jsxs("div",{className:"flex flex-col gap-1",children:[m.jsx("p",{className:"text-xs font-semibold leading-normal capitalize text-foreground px-1",children:i.title}),m.jsx("div",{className:"grid grid-cols-5 grid-rows-2 gap-0.5",children:i.colors.map(l=>m.jsx(rm,{hsl:l.hsl,editor:e,color:l.color,bgColor:l.bgColor,tooltipText:l.tooltipText,buttonType:i.buttonType},l.color))})]},i.key))})})]})},am=p.memo(om),nm=({editor:e})=>{const t=p.useCallback(()=>e.isActive("subscript")||e.isActive("superscript")||e.isActive({textAlign:"left"})||e.isActive({textAlign:"center"})||e.isActive({textAlign:"right"})||e.isActive({textAlign:"justify"}),[e]),[r,o]=p.useState(t);p.useEffect(()=>{const s=()=>o(t());return e.on("selectionUpdate",s),e.on("transaction",s),()=>{e.off("selectionUpdate",s),e.off("transaction",s)}},[e,t]);const a=p.useMemo(()=>[{key:"superscript",icon:"Superscript",tooltipText:"Superscript",command:()=>e.chain().focus().toggleSuperscript().run()},{key:"subscript",icon:"Subscript",tooltipText:"Subscript",command:()=>e.chain().focus().toggleSubscript().run()}],[e]),n=p.useMemo(()=>[{key:"left",icon:"AlignLeft",tooltipText:"Align left",command:()=>e.chain().focus().setTextAlign("left").run()},{key:"center",icon:"AlignCenter",tooltipText:"Align center",command:()=>e.chain().focus().setTextAlign("center").run()},{key:"right",icon:"AlignRight",tooltipText:"Align right",command:()=>e.chain().focus().setTextAlign("right").run()},{key:"justify",icon:"AlignJustify",tooltipText:"Align justify",command:()=>e.chain().focus().setTextAlign("justify").run()}],[e]);return m.jsxs(Nt,{placement:"bottom",children:[m.jsx(At,{children:m.jsx("div",{className:"flex items-center gap-0.5",children:m.jsx(Ze,{size:"sm","data-active":r,color:"default",variant:"light",isIconOnly:!0,isDisabled:!1,"aria-label":"More options",className:`text-foreground-500 hover:text-foreground
49
+ `)}var wr=class Zc extends Ac{constructor(){super(...arguments),this.type="node"}static create(t={}){const r=typeof t=="function"?t():t;return new Zc(r)}configure(t){return super.configure(t)}extend(t){const r=typeof t=="function"?t():t;return super.extend(r)}},zb=class{constructor({editor:e,element:t,view:r,options:o,shouldShow:a}){this.preventHide=!1,this.isVisible=!1,this.shouldShow=({view:n,state:s})=>{const{selection:i}=s,{$anchor:l,empty:c}=i,d=l.depth===1,u=l.parent.isTextblock&&!l.parent.type.spec.code&&!l.parent.textContent&&l.parent.childCount===0&&!this.getTextContent(l.parent);return!(!n.hasFocus()||!c||!d||!u||!this.editor.isEditable)},this.floatingUIOptions={strategy:"absolute",placement:"right",offset:8,flip:{},shift:{},arrow:!1,size:!1,autoPlacement:!1,hide:!1,inline:!1},this.updateHandler=(n,s,i,l)=>{const{composing:c}=n;if(c||!s&&!i)return;if(!this.getShouldShow(l)){this.hide();return}this.updatePosition(),this.show()},this.mousedownHandler=()=>{this.preventHide=!0},this.focusHandler=()=>{setTimeout(()=>this.update(this.editor.view))},this.blurHandler=({event:n})=>{var s;if(this.preventHide){this.preventHide=!1;return}n?.relatedTarget&&((s=this.element.parentNode)!=null&&s.contains(n.relatedTarget))||n?.relatedTarget!==this.editor.view.dom&&this.hide()},this.editor=e,this.element=t,this.view=r,this.floatingUIOptions={...this.floatingUIOptions,...o},this.element.tabIndex=0,a&&(this.shouldShow=a),this.element.addEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.editor.on("focus",this.focusHandler),this.editor.on("blur",this.blurHandler),this.update(r,r.state),this.getShouldShow()&&this.show()}getTextContent(e){return Kv(e,{textSerializers:Pc(this.editor.schema)})}get middlewares(){const e=[];return this.floatingUIOptions.flip&&e.push(je.flip(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&e.push(je.shift(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&e.push(je.offset(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&e.push(je.arrow(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&e.push(je.size(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&e.push(je.autoPlacement(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&e.push(je.hide(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&e.push(je.inline(typeof this.floatingUIOptions.inline!="boolean"?this.floatingUIOptions.inline:void 0)),e}getShouldShow(e){var t;const{state:r}=this.view,{selection:o}=r,{ranges:a}=o,n=Math.min(...a.map(l=>l.$from.pos)),s=Math.max(...a.map(l=>l.$to.pos));return(t=this.shouldShow)==null?void 0:t.call(this,{editor:this.editor,view:this.view,state:r,oldState:e,from:n,to:s})}updatePosition(){const{selection:e}=this.editor.state,t=Sc(this.view,e.from,e.to),r={getBoundingClientRect:()=>t,getClientRects:()=>[t]};je.computePosition(r,this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:o,y:a,strategy:n})=>{this.element.style.width="max-content",this.element.style.position=n,this.element.style.left=`${o}px`,this.element.style.top=`${a}px`,this.isVisible&&this.floatingUIOptions.onUpdate&&this.floatingUIOptions.onUpdate()})}update(e,t){const r=!t?.selection.eq(e.state.selection),o=!t?.doc.eq(e.state.doc);this.updateHandler(e,r,o,t)}show(){var e;this.isVisible||(this.element.style.visibility="visible",this.element.style.opacity="1",(e=this.view.dom.parentElement)==null||e.appendChild(this.element),this.floatingUIOptions.onShow&&this.floatingUIOptions.onShow(),this.isVisible=!0)}hide(){this.isVisible&&(this.element.style.visibility="hidden",this.element.style.opacity="0",this.element.remove(),this.floatingUIOptions.onHide&&this.floatingUIOptions.onHide(),this.isVisible=!1)}destroy(){this.hide(),this.element.removeEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.editor.off("focus",this.focusHandler),this.editor.off("blur",this.blurHandler),this.floatingUIOptions.onDestroy&&this.floatingUIOptions.onDestroy()}},zc=e=>new W.Plugin({key:typeof e.pluginKey=="string"?new W.PluginKey(e.pluginKey):e.pluginKey,view:t=>new zb({view:t,...e})});Te.create({name:"floatingMenu",addOptions(){return{element:null,options:{},pluginKey:"floatingMenu",shouldShow:null}},addProseMirrorPlugins(){return this.options.element?[zc({pluginKey:this.options.pluginKey,editor:this.editor,element:this.options.element,options:this.options.options,shouldShow:this.options.shouldShow})]:[]}});var Ic=p.forwardRef(({pluginKey:e="bubbleMenu",editor:t,updateDelay:r,resizeDelay:o,shouldShow:a=null,options:n,children:s,...i},l)=>{const c=p.useRef(document.createElement("div"));typeof l=="function"?l(c.current):l&&(l.current=c.current);const{editor:d}=et.useCurrentEditor();return p.useEffect(()=>{const u=c.current;if(u.style.visibility="hidden",u.style.position="absolute",t?.isDestroyed||d?.isDestroyed)return;const f=t||d;if(!f){console.warn("BubbleMenu component is not rendered inside of an editor component or does not have editor prop.");return}const h=Qc.BubbleMenuPlugin({updateDelay:r,resizeDelay:o,editor:f,element:u,pluginKey:e,shouldShow:a,options:n});return f.registerPlugin(h),()=>{f.unregisterPlugin(e),window.requestAnimationFrame(()=>{u.parentNode&&u.parentNode.removeChild(u)})}},[t,d]),bt.createPortal(m.jsx("div",{...i,children:s}),c.current)});p.forwardRef(({pluginKey:e="floatingMenu",editor:t,shouldShow:r=null,options:o,children:a,...n},s)=>{const i=p.useRef(document.createElement("div"));typeof s=="function"?s(i.current):s&&(s.current=i.current);const{editor:l}=et.useCurrentEditor();return p.useEffect(()=>{const c=i.current;if(c.style.visibility="hidden",c.style.position="absolute",t?.isDestroyed||l?.isDestroyed)return;const d=t||l;if(!d){console.warn("FloatingMenu component is not rendered inside of an editor component or does not have editor prop.");return}const u=zc({editor:d,element:c,pluginKey:e,shouldShow:r,options:o});return d.registerPlugin(u),()=>{d.unregisterPlugin(e),window.requestAnimationFrame(()=>{c.parentNode&&c.parentNode.removeChild(c)})}},[t,l]),bt.createPortal(m.jsx("div",{...n,children:a}),i.current)});const $e=p.memo(({name:e,className:t,strokeWidth:r})=>{const o=ed.icons[e];return o?m.jsx(o,{className:gr("w-4 h-4",t),strokeWidth:r||2.5}):null});$e.displayName="Icon";const Ib=({editor:e,buttonKey:t,tooltipText:r,isIconOnly:o=!1,color:a="default",variant:n="light",isDisabled:s=!1,icon:i="AtSign",iconClass:l,text:c="Button",withActive:d=!1,onPressed:u})=>{const[f,h]=p.useState(()=>e.isActive(t));p.useEffect(()=>{const v=()=>h(e.isActive(t));return e.on("selectionUpdate",v),e.on("transaction",v),()=>{e.off("selectionUpdate",v),e.off("transaction",v)}},[e,t]);const g=p.useCallback(()=>{u?.()},[u]);return m.jsx(Vt,{delay:250,closeDelay:0,content:r,isDisabled:r==null,children:m.jsx(Ze,{size:"sm","data-active":d?f:!1,color:a,variant:n,isIconOnly:o,isDisabled:s,className:"text-foreground-500 hover:text-foreground data-[active=true]:bg-divider/45 data-[active=true]:text-primary data-[active=true]:hover:bg-divider/45 data-[active=true]:hover:text-foreground",onPress:g,children:o?m.jsx($e,{name:i,className:l}):c})})},Xt=p.memo(Ib),Db=La.createLowlight(La.all),Dc=td.configure({lowlight:Db}),_c=rd.extend({renderHTML(){return["div",Yt(this.options.HTMLAttributes,{"data-type":this.name}),["hr"]]}}),jc=e=>{const{state:t}=e,{selection:r,doc:o}=t,{empty:a,from:n,to:s}=r,i=!o.textBetween(n,s).length&&$a(r),l=r instanceof W.NodeSelection;return!(a||i||l)},_b=e=>{const{state:t}=e,{selection:r,doc:o}=t;if(!(r instanceof W.TextSelection))return!1;let a=!1;return o.nodesBetween(r.from,r.to,n=>n.isText?(a=!0,!1):!0),a},jb=e=>e.state.selection instanceof he.CellSelection,Ob=e=>[Dc.name,_c.name].some(r=>e.isActive(r)),Oc=e=>{const{state:t}=e,{selection:r}=t,o=["paragraph","code","heading","blockquote","taskList","orderedList"];if(!(r instanceof W.NodeSelection))return;const a=r.node;if(a)return o.includes(a.type.name)&&a.textContent},Lb=e=>{const{state:t}=e,{selection:r}=t,o=["horizontalRule","imageUploader"];if(!(r instanceof W.NodeSelection))return;const a=r.node;if(a)return!o.includes(a.type.name)},Fb=e=>{const{state:t}=e,{selection:r}=t;if(!(r instanceof W.NodeSelection))return;const o=r.node;if(!o)return;let a=!1;return o.marks.length?!0:(o.descendants(n=>n.marks?.length?(a=!0,!1):!0),a)},Kb=e=>{const{state:t}=e,{selection:r}=t;if(!(r instanceof W.NodeSelection))return;const o=r.node;if(o)return o.textContent.trim().length>0},Bb=e=>{const{selection:t,doc:r}=e;let o;if(t instanceof W.NodeSelection)o=t.node;else{const a=r.resolve(t.from);o=a.nodeAfter||a.parent}return o?o.type.name==="imageUploader"&&o.attrs?.id&&o.attrs?.uploading:!1},Rb=e=>{const{state:t}=e,{selection:r,doc:o}=t,a=r instanceof W.NodeSelection?r:W.NodeSelection.create(o,r.from),n=a.node,s=a.from;if(!n)return;const i=n.toJSON();e.chain().focus().command(({tr:l,dispatch:c,state:d})=>{const u=s+n.nodeSize,f=d.schema.nodeFromJSON(i);return l.insert(u,f),c&&c(l),!0}).run(),setTimeout(()=>{e.view.updateState(e.state);const l=s+n.nodeSize,c=W.NodeSelection.create(e.state.doc,l);e.view.dispatch(e.state.tr.setSelection(c))},0)},Hb=e=>{const{state:t}=e,{selection:r}=t;if(!(r instanceof W.NodeSelection))return;const o=r.node;if(!o)return;const a=o.textContent;a&&navigator.clipboard.writeText(a).catch(n=>{console.error("Failed to copy to clipboard:",n)})},Ub=e=>{const{state:t}=e,{selection:r}=t;if(!(r instanceof W.NodeSelection))return;const{from:o,to:a}=r,{node:n}=r,{attrs:s}=n;if(n.type.name==="imageUploader"&&s.id&&s.uploading){e?.storage.imageUploaderExtension.cancelUpload(e,s.id),e.view.focus(),s?.uploading;return}e.chain().focus().deleteRange({from:o,to:a}).run(),e.view.focus()},Vb=e=>{const{state:t}=e,{selection:r}=t;if(!(r instanceof W.NodeSelection))return;const o=r.node,a=r.from;if(!o)return;const n=o.textContent;if(!n.trim()){e.chain().focus().command(({tr:s,dispatch:i})=>{const l=t.schema.nodes.paragraph.create();return s.replaceWith(a,a+o.nodeSize,l),i&&i(s),!0}).run();return}e.chain().focus().command(({tr:s,dispatch:i,state:l})=>{const c=l.schema.text(n),d=l.schema.nodes.paragraph.create(null,c);return s.replaceWith(a,a+o.nodeSize,d),i&&i(s),!0}).run(),setTimeout(()=>{e.view.updateState(e.state);try{const s=W.NodeSelection.create(e.state.doc,a);e.view.dispatch(e.state.tr.setSelection(s))}catch{e.commands.setTextSelection(a)}},0)},Wb=(e,t)=>{const{state:r}=e,{selection:o}=r,a=()=>{const s={paragraph:()=>e.chain().focus().setNode("paragraph").run(),heading1:()=>e.chain().focus().toggleHeading({level:1}).run(),heading2:()=>e.chain().focus().toggleHeading({level:2}).run(),heading3:()=>e.chain().focus().toggleHeading({level:3}).run(),blockquote:()=>e.chain().focus().toggleBlockquote().run(),codeBlock:()=>e.chain().focus().toggleCodeBlock().run(),bulletList:()=>e.chain().focus().toggleBulletList().run(),orderedList:()=>e.chain().focus().toggleOrderedList().run(),taskList:()=>e.chain().focus().toggleTaskList().run(),table:()=>e.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run(),horizontalRule:()=>{const{from:i,to:l}=o;return e.chain().focus().deleteRange({from:i,to:l}).insertContent({type:"horizontalRule"}).run()}}[t.key];s&&s()};if(o instanceof W.NodeSelection){const n=o.node,s=o.from;if(!n)return;if(t.key==="horizontalRule"){e.chain().focus().deleteRange({from:s,to:s+n.nodeSize}).insertContent({type:"horizontalRule"}).run();return}if(t.key==="table"){e.chain().focus().deleteRange({from:s,to:s+n.nodeSize}).insertTable({rows:3,cols:3,withHeaderRow:!0}).run();return}const i=s+1,l=s+n.nodeSize-1;e.commands.setTextSelection({from:i,to:l}),a(),["bulletList","orderedList","taskList"].includes(t.key)||setTimeout(()=>{try{const c=W.NodeSelection.create(e.state.doc,s);e.view.dispatch(e.state.tr.setSelection(c))}catch{e.commands.setTextSelection(s)}},0)}else a()},Gb=(e,t)=>{e&&t!==null&&e.chain().focus().extendMarkRange("link").setLink({href:t}).run()},qb=e=>{if(!e)return;e.getAttributes("link")?.href&&e.chain().focus().extendMarkRange("link").unsetLink().run()},Yb=async({file:e,url:t,onProgress:r,signal:o})=>new Promise((a,n)=>{const s=new XMLHttpRequest;o&&o.addEventListener("abort",()=>{s.abort(),n(new Error("AbortError"))}),s.upload.addEventListener("progress",l=>{if(l.lengthComputable){const c=Math.round(l.loaded/l.total*100);if(!r(c)){s.abort(),n(new Error("AbortError"));return}}}),s.addEventListener("load",()=>{if(s.status>=200&&s.status<300)try{const l=JSON.parse(s.responseText);a(l)}catch{n(new Error("Invalid JSON response"))}else n(new Error(`Upload failed with status ${s.status}`))}),s.addEventListener("error",()=>{n(new Error("Network error during upload"))}),s.addEventListener("abort",()=>{n(new Error("AbortError"))});const i=new FormData;i.append("file",e),s.open("POST",t),s.send(i)}),Xb=(e,t)=>(Array.isArray(t)?t:t.split(".").filter(Boolean)).reduce((o,a)=>{if(!(o==null||typeof o!="object"))return o[a]},e),Jb=()=>`upload-${Date.now()}-${Math.random().toString(36).substring(2,8)}`,fo=(e,t,r)=>{const{state:o,view:a}=e,{doc:n}=o;let s=null;if(typeof t.pos=="number")s=t.pos;else if(t.id){let l=null;n.descendants((c,d)=>c.type.name==="imageUploader"&&c.attrs.id===t.id?(l=d,!1):!0),s=l}if(s===null){console.log("Could not find imageUploader node to update");return}const i=o.tr.setNodeMarkup(s,void 0,{...o.doc.nodeAt(s)?.attrs,...r});a.dispatch(i)};function Zb(e,t,r,o){const a=r+t.nodeSize,n=t.textContent,s=[];e.nodesBetween(r+1,a-1,(d,u)=>{if(d.isText&&d.text)for(let f=0;f<d.text.length;f++)s.push(u+f);return!0});const i=[],l=/\S+/g;let c;for(;(c=l.exec(n))!==null;){const d=c.index,u=c.index+c[0].length;i.push({index:i.length,text:c[0],absFrom:s[d]??r+1+d,absTo:s[u-1]!==void 0?s[u-1]+1:r+1+u})}return{index:o,type:t.type.name,text:n,absFrom:r,absTo:a,words:i,charMap:s}}const ho=e=>{const{doc:t}=e.state,r=[];return t.forEach((o,a,n)=>{r.push(Zb(t,o,a,n))}),{nodes:r}};function Lc(e,t){const r=t.nodeIndex!==void 0?e.nodes[t.nodeIndex]:void 0;if(!r)return null;if(t.wordIndex!==void 0){const o=r.words[t.wordIndex];return o?{absFrom:o.absFrom,absTo:o.absTo}:null}if(t.wordRange!==void 0){const[o,a]=t.wordRange,n=r.words[o],s=r.words[a];return!n||!s?null:{absFrom:n.absFrom,absTo:s.absTo}}if(t.charFrom!==void 0&&t.charTo!==void 0){const o=r.charMap[t.charFrom]??r.absFrom+1+t.charFrom,a=t.charTo>0&&r.charMap[t.charTo-1]!==void 0?r.charMap[t.charTo-1]+1:r.absFrom+1+t.charTo;return{absFrom:o,absTo:a}}return{absFrom:r.absFrom+1,absTo:r.absTo-1}}function Fc(e,t,r){const{schema:o,doc:a}=e.state;if(typeof r=="string"){if(!r)return null;const s=a.resolve(t).marks();return Ne.Fragment.from(o.text(r,s.length?s:void 0))}if(!r.length)return null;const n=r.map(s=>o.nodeFromJSON(s));return Ne.Fragment.from(n)}const Aa=(e,t)=>{const r=ho(e),o=Lc(r,t);if(!o)return!1;const a=Fc(e,o.absFrom,t.replacement),n=a?e.state.tr.replaceWith(o.absFrom,o.absTo,a):e.state.tr.delete(o.absFrom,o.absTo);return e.view.dispatch(n),!0},Kc=(e,t)=>{if(t.length===0)return!0;if(t.length===1)return Aa(e,t[0]);const r=ho(e),o=[];for(const n of t){const s=Lc(r,n);s&&o.push({...s,replacement:n.replacement})}if(o.length===0)return!1;o.sort((n,s)=>s.absFrom-n.absFrom);let a=e.state.tr;for(const n of o){const s=Fc(e,n.absFrom,n.replacement);a=s?a.replaceWith(n.absFrom,n.absTo,s):a.delete(n.absFrom,n.absTo)}return e.view.dispatch(a),!0},Qb=({editor:e})=>{const[t,r]=p.useState(!1),[o,a]=p.useState(""),[n,s]=p.useState(!1),i=p.useCallback(()=>e.getAttributes("link")?.href||"",[e]);p.useEffect(()=>{const f=()=>{const h=i();a(h),s(e.isActive("link",{href:h}))};return e.on("selectionUpdate",f),e.on("transaction",f),()=>{e.off("selectionUpdate",f),e.off("transaction",f)}},[e,i]);const l=p.useCallback(()=>{o&&(Gb(e,o),s(!0))},[e,o]),c=p.useCallback(()=>{o&&window.open(o,"_blank","noopener,noreferrer,nofollow")},[o]),d=p.useCallback(()=>{qb(e),a(""),s(!1),r(!1)},[e]),u=p.useCallback(f=>{f.key==="Enter"&&o&&(f.preventDefault(),l())},[l,o]);return m.jsxs(Nt,{placement:"bottom",isOpen:t,onOpenChange:r,children:[m.jsx(At,{children:m.jsx("div",{className:"z-1 flex items-center gap-0.5",children:m.jsx(Ze,{size:"sm","data-active":n,color:"default",variant:"light",isIconOnly:!0,isDisabled:!1,"aria-label":"Link menu",className:"text-foreground-500 hover:text-foreground data-[active=true]:bg-divider/45 data-[active=true]:text-primary data-[active=true]:hover:bg-divider/45 data-[active=true]:hover:text-foreground",onPress:()=>r(f=>!f),children:m.jsx(Vt,{content:"Link",delay:250,closeDelay:0,children:m.jsx("div",{className:"w-full h-full flex items-center justify-center",children:m.jsx($e,{name:"Link"})})})})})}),m.jsx(Mt,{className:"p-1.5",children:m.jsxs("div",{className:"flex items-center gap-1",children:[m.jsx("div",{className:"relative flex flex-wrap items-stretch",children:m.jsx("input",{className:"block w-full h-8 text-sm font-normal leading-1.5 px-2 py-1.5 bg-none appearance-none outline-none",placeholder:"Enter a link...",autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",autoFocus:!0,type:"url",value:o,onChange:f=>a(f.target.value),onKeyDown:u})}),m.jsx(Xt,{isIconOnly:!0,isDisabled:!o,editor:e,buttonKey:"validate",tooltipText:"Set link",icon:"CornerDownLeft",withActive:!1,onPressed:l}),m.jsx(Oe,{orientation:"vertical",className:"h-6"}),m.jsxs("div",{className:"flex items-center gap-1.5",children:[m.jsx(Xt,{isIconOnly:!0,isDisabled:!o,editor:e,buttonKey:"open_in_new_tab",tooltipText:"Open link",icon:"ExternalLink",withActive:!1,onPressed:c}),m.jsx(Xt,{isIconOnly:!0,isDisabled:!o,color:"danger",buttonKey:"remove_link",iconClass:"text-danger",editor:e,tooltipText:"Remove link",icon:"Trash",withActive:!1,onPressed:d})]})]})})]})},em=p.memo(Qb),Bc=({color:e,bgColor:t,buttonType:r})=>m.jsx("span",{className:"relative w-5 h-5 flex items-center justify-center border rounded-full transition-transform duration-200 ease-in-out",style:{borderColor:`hsla(var(${e}), 1)`,backgroundColor:`hsla(var(${t}), 0.7)`},children:r==="text"&&m.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",style:{color:`hsla(var(${e}), 1)`},children:m.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M12.8944 5.55279C12.725 5.214 12.3787 5 12 5C11.6212 5 11.2749 5.214 11.1055 5.55279L5.10555 17.5528C4.85856 18.0468 5.05878 18.6474 5.55276 18.8944C6.04674 19.1414 6.64741 18.9412 6.8944 18.4472L8.64957 14.9369C8.75862 14.9777 8.87671 15 9 15H15C15.1233 15 15.2413 14.9777 15.3504 14.9369L17.1055 18.4472C17.3525 18.9412 17.9532 19.1414 18.4472 18.8944C18.9412 18.6474 19.1414 18.0468 18.8944 17.5528L12.8944 5.55279ZM14.3819 13L12 8.23607L9.61801 13H14.3819Z",fill:"currentColor"})})}),tm=({editor:e,buttonType:t,hsl:r,color:o,bgColor:a,tooltipText:n,tooltipDisabled:s=!1})=>{const i=t==="text"?e.getAttributes("textStyle")?.color===r:e.getAttributes("highlight")?.color===r,l=p.useCallback(()=>{t==="text"?i?e.commands.unsetColor():e.commands.setColor(r):e.commands.toggleHighlight({color:r})},[e,t,r,i]);return m.jsx(Vt,{content:n,delay:250,closeDelay:0,isDisabled:s,children:m.jsx(Ze,{size:"sm",isIconOnly:!0,color:"default",variant:"light",isDisabled:!1,"aria-label":n,"data-active":i,className:"text-foreground-500 data-[active=true]:bg-divider/45 data-[active=true]:hover:bg-divider/45",onPress:l,children:m.jsx("div",{className:"w-full h-full flex items-center justify-center",children:m.jsx(Bc,{color:o,bgColor:a,buttonType:t})})})})},rm=p.memo(tm),Na=[{key:"text",buttonType:"text",title:"Text color",colors:[{hsl:"hsl()",color:"--heroui-foreground",bgColor:"--heroui-background",tooltipText:"Default text"},{hsl:"hsl(0, 0%, 61%)",color:"--text-color-gray",bgColor:"",tooltipText:"Gray text"},{hsl:"hsl(18, 35%, 58%)",color:"--text-color-brown",bgColor:"",tooltipText:"Brown text"},{hsl:"hsl(25, 53%, 53%)",color:"--text-color-orange",bgColor:"",tooltipText:"Orange text"},{hsl:"hsl(36, 54%, 55%)",color:"--text-color-yellow",bgColor:"",tooltipText:"Yellow text"},{hsl:"hsl(145, 32%, 47%)",color:"--text-color-green",bgColor:"",tooltipText:"Green text"},{hsl:"hsl(202, 64%, 52%)",color:"--text-color-blue",bgColor:"",tooltipText:"Blue text"},{hsl:"hsl(270, 55%, 62%)",color:"--text-color-purple",bgColor:"",tooltipText:"Purple text"},{hsl:"hsl(329, 57%, 58%)",color:"--text-color-pink",bgColor:"",tooltipText:"Pink text"},{hsl:"hsl(1, 69%, 60%)",color:"--text-color-red",bgColor:"",tooltipText:"Red text"}]},{key:"highlight",buttonType:"highlight",title:"Highlight color",colors:[{hsl:"hsl()",color:"--heroui-background",bgColor:"--heroui-background",tooltipText:"Default background"},{hsl:"hsl(0, 0%, 61%)",color:"--text-color-gray",bgColor:"--text-color-gray",tooltipText:"Gray background"},{hsl:"hsl(18, 35%, 58%)",color:"--text-color-brown",bgColor:"--text-color-brown",tooltipText:"Brown background"},{hsl:"hsl(25, 53%, 53%)",color:"--text-color-orange",bgColor:"--text-color-orange",tooltipText:"Orange background"},{hsl:"hsl(36, 54%, 55%)",color:"--text-color-yellow",bgColor:"--text-color-yellow",tooltipText:"Yellow background"},{hsl:"hsl(145, 32%, 47%)",color:"--text-color-green",bgColor:"--text-color-green",tooltipText:"Green background"},{hsl:"hsl(202, 64%, 52%)",color:"--text-color-blue",bgColor:"--text-color-blue",tooltipText:"Blue background"},{hsl:"hsl(270, 55%, 62%)",color:"--text-color-purple",bgColor:"--text-color-purple",tooltipText:"Purple background"},{hsl:"hsl(329, 57%, 58%)",color:"--text-color-pink",bgColor:"--text-color-pink",tooltipText:"Pink background"},{hsl:"hsl(1, 69%, 60%)",color:"--text-color-red",bgColor:"--text-color-red",tooltipText:"Red background"}]}],Rc=[{key:"typography",title:"Typography",commands:[{key:"paragraph",title:"Paragraph",icon:"Type",description:"",command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("paragraph").run()}},{key:"heading1",title:"Heading 1",icon:"Heading1",description:"",command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:1}).run()}},{key:"heading2",title:"Heading 2",icon:"Heading2",description:"",command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:2}).run()}},{key:"heading3",title:"Heading 3",icon:"Heading3",description:"",command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:3}).run()}}]},{key:"format",title:"Format",commands:[{key:"bulletList",title:"Bulleted list",icon:"List",description:"",command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleList("bulletList","listItem").run()}},{key:"orderedList",title:"Ordered list",icon:"ListOrdered",description:"",command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleList("orderedList","listItem").run()}},{key:"taskList",title:"Todo list",icon:"ListTodo",description:"",command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleList("taskList","taskItem").run()}},{key:"blockquote",title:"Blockquote",icon:"Quote",description:"",command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleBlockquote().run()}},{key:"codeBlock",title:"Code block",icon:"SquareCode",description:"",command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleCodeBlock().run()}}]},{key:"insert",title:"Insert",commands:[{key:"horizontalRule",title:"Separator",icon:"Minus",description:"",command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setHorizontalRule().run()}},{key:"imageUploader",title:"Image",icon:"Image",description:"",command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).insertImageUploader().run()}},{key:"table",title:"Table",icon:"Table2",description:"",command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).insertTable({rows:3,cols:3,withHeaderRow:!0}).run()}}]}],om=({editor:e})=>{const t=p.useCallback(()=>e.getAttributes("textStyle")?.color||"",[e]),r=p.useCallback(()=>e.getAttributes("highlight")?.color||"",[e]),[o,a]=p.useState(t),[n,s]=p.useState(r);return p.useEffect(()=>{const i=()=>{a(t()),s(r())};return e.on("selectionUpdate",i),e.on("transaction",i),()=>{e.off("selectionUpdate",i),e.off("transaction",i)}},[e,t,r]),m.jsxs(Nt,{placement:"bottom",children:[m.jsx(At,{children:m.jsx("div",{className:"z-1 flex items-center gap-0.5",children:m.jsx(Ze,{size:"sm",color:"default",variant:"light",isIconOnly:!0,isDisabled:!1,"aria-label":"Color menu",className:"text-foreground-500",children:m.jsx(Vt,{content:"Color",delay:250,closeDelay:0,children:m.jsx("div",{className:"w-full h-full flex items-center justify-center",children:m.jsx("span",{className:"relative w-5 h-5 flex items-center justify-center border border-divider rounded-full transition-transform duration-200 ease-in-out",style:{borderColor:o||"hsla(var(--heroui-foreground), 0.5)",backgroundColor:n||"hsla(var(--heroui-foreground), 0.5)"},children:m.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",style:{color:o||"hsla(var(--heroui-foreground), 0.5)"},children:m.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M12.8944 5.55279C12.725 5.214 12.3787 5 12 5C11.6212 5 11.2749 5.214 11.1055 5.55279L5.10555 17.5528C4.85856 18.0468 5.05878 18.6474 5.55276 18.8944C6.04674 19.1414 6.64741 18.9412 6.8944 18.4472L8.64957 14.9369C8.75862 14.9777 8.87671 15 9 15H15C15.1233 15 15.2413 14.9777 15.3504 14.9369L17.1055 18.4472C17.3525 18.9412 17.9532 19.1414 18.4472 18.8944C18.9412 18.6474 19.1414 18.0468 18.8944 17.5528L12.8944 5.55279ZM14.3819 13L12 8.23607L9.61801 13H14.3819Z"})})})})})})})}),m.jsx(Mt,{className:"px-1.5 py-2",children:m.jsx("div",{className:"flex flex-col gap-2",children:Na.map(i=>m.jsxs("div",{className:"flex flex-col gap-1",children:[m.jsx("p",{className:"text-xs font-semibold leading-normal capitalize text-foreground px-1",children:i.title}),m.jsx("div",{className:"grid grid-cols-5 grid-rows-2 gap-0.5",children:i.colors.map(l=>m.jsx(rm,{hsl:l.hsl,editor:e,color:l.color,bgColor:l.bgColor,tooltipText:l.tooltipText,buttonType:i.buttonType},l.color))})]},i.key))})})]})},am=p.memo(om),nm=({editor:e})=>{const t=p.useCallback(()=>e.isActive("subscript")||e.isActive("superscript")||e.isActive({textAlign:"left"})||e.isActive({textAlign:"center"})||e.isActive({textAlign:"right"})||e.isActive({textAlign:"justify"}),[e]),[r,o]=p.useState(t);p.useEffect(()=>{const s=()=>o(t());return e.on("selectionUpdate",s),e.on("transaction",s),()=>{e.off("selectionUpdate",s),e.off("transaction",s)}},[e,t]);const a=p.useMemo(()=>[{key:"superscript",icon:"Superscript",tooltipText:"Superscript",command:()=>e.chain().focus().toggleSuperscript().run()},{key:"subscript",icon:"Subscript",tooltipText:"Subscript",command:()=>e.chain().focus().toggleSubscript().run()}],[e]),n=p.useMemo(()=>[{key:"left",icon:"AlignLeft",tooltipText:"Align left",command:()=>e.chain().focus().setTextAlign("left").run()},{key:"center",icon:"AlignCenter",tooltipText:"Align center",command:()=>e.chain().focus().setTextAlign("center").run()},{key:"right",icon:"AlignRight",tooltipText:"Align right",command:()=>e.chain().focus().setTextAlign("right").run()},{key:"justify",icon:"AlignJustify",tooltipText:"Align justify",command:()=>e.chain().focus().setTextAlign("justify").run()}],[e]);return m.jsxs(Nt,{placement:"bottom",children:[m.jsx(At,{children:m.jsx("div",{className:"z-1 flex items-center gap-0.5",children:m.jsx(Ze,{size:"sm","data-active":r,color:"default",variant:"light",isIconOnly:!0,isDisabled:!1,"aria-label":"More options",className:`text-foreground-500 hover:text-foreground
50
50
  data-[active=true]:bg-divider/45 data-[active=true]:text-primary
51
51
  data-[active=true]:hover:bg-divider/45 data-[active=true]:hover:text-foreground`,children:m.jsx(Vt,{content:"More options",delay:250,closeDelay:0,children:m.jsx("div",{className:"w-full h-full flex items-center justify-center",children:m.jsx($e,{name:"EllipsisVertical"})})})})})}),m.jsx(Mt,{className:"p-1.5",children:m.jsxs("div",{className:"flex h-8 items-center gap-1.5",children:[a.map(s=>m.jsx(Xt,{editor:e,isIconOnly:!0,withActive:!0,buttonKey:s.key,tooltipText:s.tooltipText,icon:s.icon,onPressed:s.command},s.key)),m.jsx(Oe,{orientation:"vertical",className:"h-6"}),n.map(s=>m.jsx(Xt,{editor:e,isIconOnly:!0,withActive:!0,buttonKey:{textAlign:s.key},tooltipText:s.tooltipText,icon:s.icon,onPressed:s.command},s.key))]})})]})},sm=p.memo(nm),im=({editor:e})=>{const[t,r]=p.useState(!1),[,o]=p.useState(0);p.useEffect(()=>{const s=()=>o(i=>i+1);return e.on("selectionUpdate",s),e.on("transaction",s),()=>{e.off("selectionUpdate",s),e.off("transaction",s)}},[e]);const a=e.isActive("table"),n=p.useMemo(()=>{const s=i=>i();return[{key:"columns",actions:[{key:"add-column-before",label:"Col before",command:()=>e.chain().focus().addColumnBefore().run(),canRun:()=>s(()=>e.can().chain().focus().addColumnBefore().run())},{key:"add-column-after",label:"Col after",command:()=>e.chain().focus().addColumnAfter().run(),canRun:()=>s(()=>e.can().chain().focus().addColumnAfter().run())},{key:"delete-column",label:"Delete col",command:()=>e.chain().focus().deleteColumn().run(),canRun:()=>s(()=>e.can().chain().focus().deleteColumn().run())}]},{key:"rows",actions:[{key:"add-row-before",label:"Row above",command:()=>e.chain().focus().addRowBefore().run(),canRun:()=>s(()=>e.can().chain().focus().addRowBefore().run())},{key:"add-row-after",label:"Row below",command:()=>e.chain().focus().addRowAfter().run(),canRun:()=>s(()=>e.can().chain().focus().addRowAfter().run())},{key:"delete-row",label:"Delete row",command:()=>e.chain().focus().deleteRow().run(),canRun:()=>s(()=>e.can().chain().focus().deleteRow().run())}]},{key:"cells",actions:[{key:"merge-cells",label:"Merge",command:()=>e.chain().focus().mergeCells().run(),canRun:()=>s(()=>e.can().chain().focus().mergeCells().run())},{key:"split-cell",label:"Split",command:()=>e.chain().focus().splitCell().run(),canRun:()=>s(()=>e.can().chain().focus().splitCell().run())},{key:"toggle-header-row",label:"Header row",command:()=>e.chain().focus().toggleHeaderRow().run(),canRun:()=>s(()=>e.can().chain().focus().toggleHeaderRow().run())},{key:"toggle-header-column",label:"Header col",command:()=>e.chain().focus().toggleHeaderColumn().run(),canRun:()=>s(()=>e.can().chain().focus().toggleHeaderColumn().run())}]}]},[e]);return a?m.jsxs(Nt,{placement:"bottom",isOpen:t,onOpenChange:r,children:[m.jsx(At,{children:m.jsx(Ze,{size:"sm",color:"default",variant:"light",isIconOnly:!0,"aria-label":"Table controls",className:"text-foreground-500 hover:text-foreground data-[active=true]:bg-divider/45 data-[active=true]:text-primary data-[active=true]:hover:bg-divider/45 data-[active=true]:hover:text-foreground",children:m.jsx(Vt,{content:"Table controls",delay:250,closeDelay:0,children:m.jsx("div",{className:"w-full h-full flex items-center justify-center",children:m.jsx($e,{name:"Table2"})})})})}),m.jsx(Mt,{className:"p-1.5",children:m.jsxs("div",{className:"flex flex-col gap-1",children:[n.map((s,i)=>m.jsxs(p.Fragment,{children:[m.jsx("div",{className:"grid grid-cols-2 gap-1",children:s.actions.map(l=>m.jsx(Ze,{size:"sm",color:"default",variant:"light",isDisabled:!l.canRun(),className:"justify-start text-foreground-500 hover:text-foreground",onPress:()=>{l.command(),r(!1)},children:l.label},l.key))}),i<n.length-1?m.jsx(Oe,{className:"my-0.5"}):null]},s.key)),m.jsx(Ze,{size:"sm",color:"danger",variant:"light",isDisabled:!e.can().chain().focus().deleteTable().run(),className:"justify-start text-danger",onPress:()=>{e.chain().focus().deleteTable().run(),r(!1)},children:"Delete table"})]})})]}):null},Hc=p.memo(im),lm=({editor:e,prepend:t,append:r})=>{const[o,a]=p.useState(!1),[n,s]=p.useState(!1),[i,l]=p.useState(()=>e.isActive("table")),c=p.useRef(null),d=p.useMemo(()=>[{icon:"Bold",buttonKey:"bold",tooltipText:"Bold",command:()=>e.chain().focus().toggleMark("bold").run()},{icon:"Italic",buttonKey:"italic",tooltipText:"Italic",command:()=>e.chain().focus().toggleMark("italic").run()},{icon:"Underline",buttonKey:"underline",tooltipText:"Underline",command:()=>e.chain().focus().toggleMark("underline").run()},{icon:"Strikethrough",buttonKey:"strike",tooltipText:"Strikethrough",command:()=>e.chain().focus().toggleMark("strike").run()},{icon:"CodeXml",buttonKey:"code",tooltipText:"Code",command:()=>e.chain().focus().toggleMark("code").run()}],[e]),u=p.useCallback(()=>jc(e)&&_b(e)&&!Ob(e),[e]),f=p.useCallback(()=>{c.current&&clearTimeout(c.current),a(!0),setTimeout(()=>s(!0),10)},[]),h=p.useCallback(()=>{s(!1),c.current=setTimeout(()=>a(!1),200)},[]);return p.useEffect(()=>{const g=()=>l(e.isActive("table"));return e.on("selectionUpdate",g),e.on("transaction",g),()=>{e.off("selectionUpdate",g),e.off("transaction",g)}},[e]),p.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]),m.jsx(Ic,{editor:e,updateDelay:200,options:{offset:3,onShow:f,onHide:h},shouldShow:u,children:m.jsxs("div",{className:`bubble-menu transition-all duration-200 ease-in-out
52
52
  ${o&&n?"opacity-100":"opacity-0"}`,children:[t&&m.jsxs("div",{className:"flex items-center gap-1",children:[t,m.jsx(Oe,{orientation:"vertical",className:"h-6"})]}),d.map(g=>m.jsx("div",{className:"flex items-center gap-0.5",children:m.jsx(Xt,{isIconOnly:!0,withActive:!0,editor:e,buttonKey:g.buttonKey,tooltipText:g.tooltipText,icon:g.icon,onPressed:g.command})},g.buttonKey)),m.jsx(Oe,{orientation:"vertical",className:"h-6"}),m.jsx(em,{editor:e}),m.jsx(am,{editor:e}),m.jsx(Oe,{orientation:"vertical",className:"h-6"}),i&&m.jsxs(m.Fragment,{children:[m.jsx(Hc,{editor:e}),m.jsx(Oe,{orientation:"vertical",className:"h-6"})]}),r&&m.jsxs("div",{className:"flex items-center gap-1",children:[r,m.jsx(Oe,{orientation:"vertical",className:"h-6"})]}),m.jsx(sm,{editor:e})]})})},cm=p.memo(lm),dm=({editor:e,prepend:t,append:r})=>{const o=p.useCallback(()=>e.isActive("table")&&(jb(e)||!jc(e)),[e]);return m.jsx(Ic,{editor:e,updateDelay:200,options:{offset:3},shouldShow:o,children:m.jsxs("div",{className:"bubble-menu",children:[t&&m.jsxs(m.Fragment,{children:[m.jsx("div",{className:"flex items-center gap-1",children:t}),m.jsx(Oe,{orientation:"vertical",className:"h-6"})]}),m.jsx(Hc,{editor:e}),r&&m.jsxs(m.Fragment,{children:[m.jsx(Oe,{orientation:"vertical",className:"h-6"}),m.jsx("div",{className:"flex items-center gap-1",children:r})]})]})})},um=p.memo(dm),fm=({editor:e,onCloseMenu:t})=>{const r=(o,a)=>{switch(o){case"text":e.chain().focus().setColor(a).run();break;case"highlight":e.chain().focus().setHighlight({color:a}).run();break;default:return}t()};return m.jsx(dc,{label:"Color list",variant:"flat",classNames:{list:"p-0",base:"p-0"},children:Na.map((o,a)=>m.jsx(Eg,{title:o.title,showDivider:a!==Na.length-1,children:o.colors.map(n=>m.jsx(sc,{startContent:m.jsx(Bc,{buttonType:o.buttonType,color:n.color,bgColor:n.bgColor}),className:"text-foreground-500 hover:text-foreground outline-none",onPress:()=>r(o.key,n.hsl),children:n.tooltipText},`${o.key}_${n.color}`))},o.key))})},hm=()=>m.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",className:"w-5 h-5",children:m.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M5.70711 5.29289C5.31658 4.90237 4.68342 4.90237 4.29289 5.29289L1.29289 8.29289C0.902369 8.68342 0.902369 9.31658 1.29289 9.70711C1.68342 10.0976 2.31658 10.0976 2.70711 9.70711L4 8.41421V16C4 16.7956 4.31607 17.5587 4.87868 18.1213C5.44129 18.6839 6.20435 19 7 19H13C13.5523 19 14 18.5523 14 18C14 17.4477 13.5523 17 13 17H7C6.73478 17 6.48043 16.8946 6.29289 16.7071C6.10536 16.5196 6 16.2652 6 16V8.41421L7.29289 9.70711C7.68342 10.0976 8.31658 10.0976 8.70711 9.70711C9.09763 9.31658 9.09763 8.68342 8.70711 8.29289L5.70711 5.29289ZM15.2929 14.2929C15.6834 13.9024 16.3166 13.9024 16.7071 14.2929L18 15.5858V8C18 7.73478 17.8946 7.48043 17.7071 7.29289C17.5196 7.10536 17.2652 7 17 7H11C10.4477 7 10 6.55228 10 6C10 5.44772 10.4477 5 11 5H17C17.7957 5 18.5587 5.31607 19.1213 5.87868C19.6839 6.44129 20 7.20435 20 8V15.5858L21.2929 14.2929C21.6834 13.9024 22.3166 13.9024 22.7071 14.2929C23.0976 14.6834 23.0976 15.3166 22.7071 15.7071L19.7071 18.7071C19.3166 19.0976 18.6834 19.0976 18.2929 18.7071L15.2929 15.7071C14.9024 15.3166 14.9024 14.6834 15.2929 14.2929Z",fill:"currentColor"})}),pm=["imageUploader"],gm=Rc.flatMap(e=>e.commands).filter(e=>!pm.includes(e.key)),vm=({editor:e})=>{const[t,r]=p.useState(-1),[o,a]=p.useState(!1),[n,s]=p.useState(!1),[i,l]=p.useState(!1),c=p.useMemo(()=>Bb(e.state)?["duplicate_node"]:[],[e.state]),d=p.useCallback(({pos:h})=>{r(h)},[]),u=p.useCallback(()=>{a(!o);const{state:h,view:g}=e,v=window.getSelection();v&&!v.isCollapsed&&v.removeAllRanges();const b=h.tr.setSelection(W.NodeSelection.create(h.doc,t));g.dispatch(b)},[o,e,t]),f=p.useCallback((h,g)=>{const v=h.state.doc.resolve(g),b=v.nodeAfter||v.parent,w=g+b.nodeSize;h.chain().focus(w,{scrollIntoView:!0}).insertContentAt(w,{type:"paragraph",content:[{type:"text",text:"/"}]}).setTextSelection(w+2).run()},[]);return m.jsx(od,{editor:e,computePositionConfig:{placement:"left"},onNodeChange:d,children:m.jsxs("div",{className:"flex items-center pr-3",children:[m.jsx("button",{className:"w-6 h-8 rounded-2xl flex justify-center items-center px-0 py-2 bg-transparent hover:bg-default-100 cursor-grab text-foreground-500 hover:text-foreground transition-all",onClick:()=>f(e,t),children:m.jsx($e,{name:"Plus"})}),m.jsxs(ag,{placement:"right",isOpen:o,onOpenChange:a,children:[m.jsx(Qp,{children:m.jsx("button",{className:"w-6 h-8 rounded-2xl flex justify-center items-center px-0 py-2 bg-transparent hover:bg-default-100 cursor-grab text-foreground-500 hover:text-foreground transition-all",onClick:u,children:m.jsx($e,{name:"GripVertical"})})}),m.jsxs(Zp,{variant:"flat",closeOnSelect:!1,disabledKeys:c,classNames:{base:"w-[225px]"},children:[m.jsxs(fl,{showDivider:!!Oc(e),children:[Oc(e)?m.jsx(Wt,{isReadOnly:!0,textValue:"color",className:"text-foreground-500 hover:text-foreground outline-none p-0 h-8 flex justify-center",children:m.jsxs(Nt,{placement:"right",isOpen:n,shouldCloseOnBlur:!1,triggerScaleOnOpen:!1,onOpenChange:h=>s(h),children:[m.jsx(At,{children:m.jsxs("div",{className:"w-full h-8 px-2 py-1.5 flex items-center justify-between",onClick:()=>{l(!1),s(!0)},children:[m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx($e,{name:"PaintBucket"}),m.jsx("p",{children:"Color"})]}),m.jsx($e,{name:"ChevronRight"})]})}),m.jsx(Mt,{children:m.jsx(fm,{editor:e,onCloseMenu:()=>{s(!1),setTimeout(()=>{a(!1)},100)}})})]})},"color"):null,Lb(e)?m.jsx(Wt,{isReadOnly:!0,textValue:"turn_into",className:"text-foreground-500 hover:text-foreground outline-none p-0 h-8 flex justify-center",children:m.jsxs(Nt,{placement:"right",shouldCloseOnBlur:!1,triggerScaleOnOpen:!1,isOpen:i,onOpenChange:h=>l(h),children:[m.jsx(At,{children:m.jsxs("div",{className:"w-full h-8 px-2 py-1.5 flex items-center justify-between",onClick:()=>{s(!1),l(!i)},children:[m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx(hm,{}),m.jsx("p",{children:"Transform into"})]}),m.jsx($e,{name:"ChevronRight"})]})}),m.jsx(Mt,{children:m.jsx(dc,{label:"Turn into list",variant:"flat",classNames:{list:"p-0",base:"p-0"},children:gm.map(h=>m.jsx(sc,{startContent:m.jsx($e,{name:h.icon}),className:"text-foreground-500 hover:text-foreground outline-none",onPress:()=>{Wb(e,h),l(!1),setTimeout(()=>{a(!1)},100)},children:h.title},h.key))})})]})},"turn_into"):null,Fb(e)?m.jsx(Wt,{textValue:"reset_formatting",className:"text-foreground-500 hover:text-foreground outline-none p-0 h-8 flex justify-center",onPress:()=>Vb(e),children:m.jsx("div",{className:"w-full h-8 px-2 py-1.5 flex items-center justify-between",children:m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx($e,{name:"RotateCcw"}),m.jsx("p",{children:"Reset formatting"})]})})},"reset_formatting"):null]}),m.jsxs(fl,{showDivider:!0,children:[m.jsx(Wt,{textValue:"duplicate_node",className:"text-foreground-500 hover:text-foreground outline-none p-0 h-8 flex justify-center",onPress:()=>Rb(e),children:m.jsxs("div",{className:"w-full h-8 px-2 py-1.5 flex items-center justify-between",children:[m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx($e,{name:"Copy"}),m.jsx("p",{children:"Duplicate block"})]}),m.jsx(wa,{keys:["command"],children:"D"})]})},"duplicate_node"),Kb(e)?m.jsx(Wt,{closeOnSelect:!0,textValue:"copy_to_clipboard",className:"text-foreground-500 hover:text-foreground outline-none p-0 h-8 flex justify-center",onPress:()=>Hb(e),children:m.jsxs("div",{className:"w-full h-8 px-2 py-1.5 flex items-center justify-between",children:[m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx($e,{name:"Clipboard"}),m.jsx("p",{children:"Copy to clipboard"})]}),m.jsx(wa,{keys:["command"],children:"C"})]})},"copy_to_clipboard"):null]}),m.jsx(Wt,{textValue:"delete",className:"text-foreground-500 hover:text-foreground outline-none p-0 h-8 flex justify-center",onPress:()=>Ub(e),children:m.jsxs("div",{className:"w-full h-8 px-2 py-1.5 flex items-center justify-between",children:[m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx($e,{name:"Trash"}),m.jsx("p",{children:"Delete"})]}),m.jsx(wa,{children:"Del"})]})},"delete")]})]})]})})},za=p.createContext(null),bm=()=>p.useContext(za);var mm=wr.create({name:"tableCell",addOptions(){return{HTMLAttributes:{}}},content:"block+",addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:e=>{var t,r;const o=e.getAttribute("colwidth"),a=o?o.split(",").map(n=>parseInt(n,10)):null;if(!a){const n=(t=e.closest("table"))==null?void 0:t.querySelectorAll("colgroup > col"),s=Array.from(((r=e.parentElement)==null?void 0:r.children)||[]).indexOf(e);if(s&&s>-1&&n&&n[s]){const i=n[s].getAttribute("width");return i?[parseInt(i,10)]:null}}return a}}}},tableRole:"cell",isolating:!0,parseHTML(){return[{tag:"td"}]},renderHTML({HTMLAttributes:e}){return["td",Yt(this.options.HTMLAttributes,e),0]}}),wm=wr.create({name:"tableHeader",addOptions(){return{HTMLAttributes:{}}},content:"block+",addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:e=>{const t=e.getAttribute("colwidth");return t?t.split(",").map(o=>parseInt(o,10)):null}}}},tableRole:"header_cell",isolating:!0,parseHTML(){return[{tag:"th"}]},renderHTML({HTMLAttributes:e}){return["th",Yt(this.options.HTMLAttributes,e),0]}}),ym=wr.create({name:"tableRow",addOptions(){return{HTMLAttributes:{}}},content:"(tableCell | tableHeader)*",tableRole:"row",parseHTML(){return[{tag:"tr"}]},renderHTML({HTMLAttributes:e}){return["tr",Yt(this.options.HTMLAttributes,e),0]}});function Ia(e,t){return t?["width",`${Math.max(t,e)}px`]:["min-width",`${e}px`]}function Uc(e,t,r,o,a,n){var s;let i=0,l=!0,c=t.firstChild;const d=e.firstChild;if(d!==null)for(let f=0,h=0;f<d.childCount;f+=1){const{colspan:g,colwidth:v}=d.child(f).attrs;for(let b=0;b<g;b+=1,h+=1){const w=a===h?n:v&&v[b],$=w?`${w}px`:"";if(i+=w||o,w||(l=!1),c){if(c.style.width!==$){const[E,I]=Ia(o,w);c.style.setProperty(E,I)}c=c.nextSibling}else{const E=document.createElement("col"),[I,S]=Ia(o,w);E.style.setProperty(I,S),t.appendChild(E)}}}for(;c;){const f=c.nextSibling;(s=c.parentNode)==null||s.removeChild(c),c=f}const u=e.attrs.style&&typeof e.attrs.style=="string"&&/\bwidth\s*:/i.test(e.attrs.style);l&&!u?(r.style.width=`${i}px`,r.style.minWidth=""):(r.style.width="",r.style.minWidth=`${i}px`)}var xm=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")),e.attrs.style&&(this.table.style.cssText=e.attrs.style),this.colgroup=this.table.appendChild(document.createElement("colgroup")),Uc(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,Uc(e,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(e){const t=e.target,r=this.dom.contains(t),o=this.contentDOM.contains(t);return!!(r&&!o&&(e.type==="attributes"||e.type==="childList"||e.type==="characterData"))}};function km(e,t,r,o){let a=0,n=!0;const s=[],i=e.firstChild;if(!i)return{};for(let u=0,f=0;u<i.childCount;u+=1){const{colspan:h,colwidth:g}=i.child(u).attrs;for(let v=0;v<h;v+=1,f+=1){const b=r===f?o:g&&g[v];a+=b||t,b||(n=!1);const[w,$]=Ia(t,b);s.push(["col",{style:`${w}: ${$}`}])}}const l=n?`${a}px`:"",c=n?"":`${a}px`;return{colgroup:["colgroup",{},...s],tableWidth:l,tableMinWidth:c}}function Vc(e,t){return e.createAndFill()}function $m(e){if(e.cached.tableNodeTypes)return e.cached.tableNodeTypes;const t={};return Object.keys(e.nodes).forEach(r=>{const o=e.nodes[r];o.spec.tableRole&&(t[o.spec.tableRole]=o)}),e.cached.tableNodeTypes=t,t}function Pm(e,t,r,o,a){const n=$m(e),s=[],i=[];for(let c=0;c<r;c+=1){const d=Vc(n.cell);if(d&&i.push(d),o){const u=Vc(n.header_cell);u&&s.push(u)}}const l=[];for(let c=0;c<t;c+=1)l.push(n.row.createChecked(null,o&&c===0?s:i));return n.table.createChecked(null,l)}function Em(e){return e instanceof he.CellSelection}var po=({editor:e})=>{const{selection:t}=e.state;if(!Em(t))return!1;let r=0;const o=xc(t.ranges[0].$from,n=>n.type.name==="table");return o?.node.descendants(n=>{if(n.type.name==="table")return!1;["tableCell","tableHeader"].includes(n.type.name)&&(r+=1)}),r===t.ranges.length?(e.commands.deleteTable(),!0):!1},Cm="";function Sm(e){return(e||"").replace(/\s+/g," ").trim()}function Tm(e,t,r={}){var o;const a=(o=r.cellLineSeparator)!=null?o:Cm;if(!e||!e.content||e.content.length===0)return"";const n=[];e.content.forEach(g=>{const v=[];g.content&&g.content.forEach(b=>{let w="";b.content&&Array.isArray(b.content)&&b.content.length>1?w=b.content.map(S=>t.renderChildren(S)).join(a):w=b.content?t.renderChildren(b.content):"";const $=Sm(w),E=b.type==="tableHeader";v.push({text:$,isHeader:E})}),n.push(v)});const s=n.reduce((g,v)=>Math.max(g,v.length),0);if(s===0)return"";const i=new Array(s).fill(0);n.forEach(g=>{var v;for(let b=0;b<s;b+=1){const $=(((v=g[b])==null?void 0:v.text)||"").length;$>i[b]&&(i[b]=$),i[b]<3&&(i[b]=3)}});const l=(g,v)=>g+" ".repeat(Math.max(0,v-g.length)),c=n[0],d=c.some(g=>g.isHeader);let u=`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiptop-editor",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "Notion-like editor built with Tiptap v3 and HeroUI",
5
5
  "type": "module",
6
6
  "main": "./dist/tiptop-editor.umd.js",