tiptop-editor 1.6.1 → 1.6.2
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.
package/dist/tiptop-editor.es.js
CHANGED
|
@@ -26025,7 +26025,7 @@ const Ad = (e, t) => {
|
|
|
26025
26025
|
e.off("selectionUpdate", l), e.off("transaction", l);
|
|
26026
26026
|
};
|
|
26027
26027
|
}, [e, t, r]), /* @__PURE__ */ h.jsxs(Nt, { placement: "bottom", children: [
|
|
26028
|
-
/* @__PURE__ */ h.jsx(It, { children: /* @__PURE__ */ h.jsx(
|
|
26028
|
+
/* @__PURE__ */ h.jsx(It, { children: /* @__PURE__ */ h.jsx(
|
|
26029
26029
|
et,
|
|
26030
26030
|
{
|
|
26031
26031
|
size: "sm",
|
|
@@ -26065,7 +26065,7 @@ const Ad = (e, t) => {
|
|
|
26065
26065
|
}
|
|
26066
26066
|
) }) })
|
|
26067
26067
|
}
|
|
26068
|
-
) })
|
|
26068
|
+
) }),
|
|
26069
26069
|
/* @__PURE__ */ h.jsx(At, { className: "px-1.5 py-2", children: /* @__PURE__ */ h.jsx("div", { className: "flex flex-col gap-2", children: wa.map((l) => /* @__PURE__ */ h.jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
26070
26070
|
/* @__PURE__ */ h.jsx("p", { className: "text-xs font-semibold leading-normal capitalize text-foreground px-1", children: l.title }),
|
|
26071
26071
|
/* @__PURE__ */ h.jsx("div", { className: "grid grid-cols-5 grid-rows-2 gap-0.5", children: l.colors.map((i) => /* @__PURE__ */ h.jsx(
|
|
@@ -26136,7 +26136,7 @@ const Ad = (e, t) => {
|
|
|
26136
26136
|
[e]
|
|
26137
26137
|
);
|
|
26138
26138
|
return /* @__PURE__ */ h.jsxs(Nt, { placement: "bottom", children: [
|
|
26139
|
-
/* @__PURE__ */ h.jsx(It, { children: /* @__PURE__ */ h.jsx(
|
|
26139
|
+
/* @__PURE__ */ h.jsx(It, { children: /* @__PURE__ */ h.jsx(
|
|
26140
26140
|
et,
|
|
26141
26141
|
{
|
|
26142
26142
|
size: "sm",
|
|
@@ -26147,11 +26147,11 @@ const Ad = (e, t) => {
|
|
|
26147
26147
|
isDisabled: !1,
|
|
26148
26148
|
"aria-label": "More options",
|
|
26149
26149
|
className: `text-foreground-500 hover:text-foreground
|
|
26150
|
-
|
|
26151
|
-
|
|
26150
|
+
data-[active=true]:bg-divider/45 data-[active=true]:text-primary
|
|
26151
|
+
data-[active=true]:hover:bg-divider/45 data-[active=true]:hover:text-foreground`,
|
|
26152
26152
|
children: /* @__PURE__ */ h.jsx(tr, { content: "More options", delay: 250, closeDelay: 0, children: /* @__PURE__ */ h.jsx("div", { className: "w-full h-full flex items-center justify-center", children: /* @__PURE__ */ h.jsx(Pe, { name: "EllipsisVertical" }) }) })
|
|
26153
26153
|
}
|
|
26154
|
-
) })
|
|
26154
|
+
) }),
|
|
26155
26155
|
/* @__PURE__ */ h.jsx(At, { className: "p-1.5", children: /* @__PURE__ */ h.jsxs("div", { className: "flex h-8 items-center gap-1.5", children: [
|
|
26156
26156
|
a.map((s) => /* @__PURE__ */ h.jsx(
|
|
26157
26157
|
Gt,
|
|
@@ -37,9 +37,9 @@ ${b}
|
|
|
37
37
|
`);l+=d.type==="paragraph"?`
|
|
38
38
|
|
|
39
39
|
${g}`:`
|
|
40
|
-
${g}`}}),l}var yr=class fc extends Bd{constructor(){super(...arguments),this.type="node"}static create(t={}){const r=typeof t=="function"?t():t;return new fc(r)}configure(t){return super.configure(t)}extend(t){const r=typeof t=="function"?t():t;return super.extend(r)}},iv=class{constructor({editor:e,element:t,view:r,pluginKey:a="floatingMenu",updateDelay:o=250,resizeDelay:n=60,options:s,appendTo:i,shouldShow:l}){this.preventHide=!1,this.isVisible=!1,this.scrollTarget=window,this.shouldShow=({view:c,state:u})=>{const{selection:p}=u,{$anchor:f,empty:g}=p,m=f.depth===1,b=f.parent.isTextblock&&!f.parent.type.spec.code&&!f.parent.textContent&&f.parent.childCount===0&&!this.getTextContent(f.parent);return!(!c.hasFocus()||!g||!m||!b||!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=(c,u,p,f)=>{const{composing:g}=c;if(g||!u&&!p)return;if(!this.getShouldShow(f)){this.hide();return}this.updatePosition(),this.show()},this.mousedownHandler=()=>{this.preventHide=!0},this.focusHandler=()=>{setTimeout(()=>this.update(this.editor.view))},this.blurHandler=({event:c})=>{var u;if(this.preventHide){this.preventHide=!1;return}c?.relatedTarget&&((u=this.element.parentNode)!=null&&u.contains(c.relatedTarget))||c?.relatedTarget!==this.editor.view.dom&&this.hide()},this.transactionHandler=({transaction:c})=>{const u=c.getMeta(this.pluginKey);u==="updatePosition"?this.updatePosition():u&&typeof u=="object"&&u.type==="updateOptions"&&this.updateOptions(u.options)},this.resizeHandler=()=>{this.resizeDebounceTimer&&clearTimeout(this.resizeDebounceTimer),this.resizeDebounceTimer=window.setTimeout(()=>{this.updatePosition()},this.resizeDelay)};var d;this.editor=e,this.element=t,this.view=r,this.pluginKey=a,this.updateDelay=o,this.resizeDelay=n,this.appendTo=i,this.scrollTarget=(d=s?.scrollTarget)!=null?d:window,this.floatingUIOptions={...this.floatingUIOptions,...s},this.element.tabIndex=0,l&&(this.shouldShow=l),this.element.addEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.editor.on("focus",this.focusHandler),this.editor.on("blur",this.blurHandler),this.editor.on("transaction",this.transactionHandler),window.addEventListener("resize",this.resizeHandler),this.scrollTarget.addEventListener("scroll",this.resizeHandler),this.update(r,r.state),this.getShouldShow()&&(this.show(),this.updatePosition())}getTextContent(e){return gm(e,{textSerializers:Nd(this.editor.schema)})}get middlewares(){const e=[];return this.floatingUIOptions.flip&&e.push(Le.flip(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&e.push(Le.shift(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&e.push(Le.offset(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&e.push(Le.arrow(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&e.push(Le.size(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&e.push(Le.autoPlacement(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&e.push(Le.hide(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&e.push(Le.inline(typeof this.floatingUIOptions.inline!="boolean"?this.floatingUIOptions.inline:void 0)),e}getShouldShow(e){var t;const{state:r}=this.view,{selection:a}=r,{ranges:o}=a,n=Math.min(...o.map(l=>l.$from.pos)),s=Math.max(...o.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})}updateOptions(e){var t;if(e.updateDelay!==void 0&&(this.updateDelay=e.updateDelay),e.resizeDelay!==void 0&&(this.resizeDelay=e.resizeDelay),e.appendTo!==void 0&&(this.appendTo=e.appendTo),e.shouldShow!==void 0&&e.shouldShow&&(this.shouldShow=e.shouldShow),e.options!==void 0){const r=(t=e.options.scrollTarget)!=null?t:window;r!==this.scrollTarget&&(this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.scrollTarget=r,this.scrollTarget.addEventListener("scroll",this.resizeHandler)),this.floatingUIOptions={...this.floatingUIOptions,...e.options}}}updatePosition(){const{selection:e}=this.editor.state,t=jd(this.view,e.from,e.to),r={getBoundingClientRect:()=>t,getClientRects:()=>[t]};Le.computePosition(r,this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:a,y:o,strategy:n,middlewareData:s})=>{var i,l;if((i=s.hide)!=null&&i.referenceHidden||(l=s.hide)!=null&&l.escaped){this.element.style.visibility="hidden";return}this.element.style.visibility="visible",this.element.style.width="max-content",this.element.style.position=n,this.element.style.left=`${a}px`,this.element.style.top=`${o}px`,this.isVisible&&this.floatingUIOptions.onUpdate&&this.floatingUIOptions.onUpdate()})}update(e,t){const r=!t?.selection.eq(e.state.selection),a=!t?.doc.eq(e.state.doc);this.updateHandler(e,r,a,t)}show(){var e;if(this.isVisible)return;this.element.style.visibility="visible",this.element.style.opacity="1";const t=typeof this.appendTo=="function"?this.appendTo():this.appendTo;(e=t??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}),window.removeEventListener("resize",this.resizeHandler),this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.editor.off("focus",this.focusHandler),this.editor.off("blur",this.blurHandler),this.editor.off("transaction",this.transactionHandler),this.floatingUIOptions.onDestroy&&this.floatingUIOptions.onDestroy()}},Kd=e=>new X.Plugin({key:typeof e.pluginKey=="string"?new X.PluginKey(e.pluginKey):e.pluginKey,view:t=>new iv({view:t,...e})});ze.create({name:"floatingMenu",addOptions(){return{element:null,options:{},pluginKey:"floatingMenu",updateDelay:void 0,resizeDelay:void 0,appendTo:void 0,shouldShow:null}},addCommands(){return{updateFloatingMenuPosition:()=>({tr:e,dispatch:t})=>(t&&e.setMeta(this.options.pluginKey,"updatePosition"),!0)}},addProseMirrorPlugins(){return this.options.element?[Kd({pluginKey:this.options.pluginKey,editor:this.editor,element:this.options.element,updateDelay:this.options.updateDelay,resizeDelay:this.options.resizeDelay,options:this.options.options,appendTo:this.options.appendTo,shouldShow:this.options.shouldShow})]:[]}});function Wd(e,t){return e??new X.PluginKey(t)}var lv=typeof window<"u"?h.useLayoutEffect:h.useEffect,Rd=new Set(["left","opacity","position","top","visibility","width"]),dv=new Set(["animationIterationCount","aspectRatio","borderImageOutset","borderImageSlice","borderImageWidth","columnCount","columns","fillOpacity","flex","flexGrow","flexShrink","fontWeight","gridArea","gridColumn","gridColumnEnd","gridColumnStart","gridRow","gridRowEnd","gridRowStart","lineClamp","lineHeight","opacity","order","orphans","scale","stopOpacity","strokeDasharray","strokeDashoffset","strokeMiterlimit","strokeOpacity","strokeWidth","tabSize","widows","zIndex","zoom"]),cv=new Set(["children","className","style"]),uv=new Set(["tabIndex"]),fv=new Set(["accessKey","autoCapitalize","contentEditable","contextMenu","dir","draggable","enterKeyHint","hidden","id","lang","nonce","role","slot","spellCheck","tabIndex","title","translate"]),pv={Blur:"focusout",DoubleClick:"dblclick",Focus:"focusin",MouseEnter:"mouseenter",MouseLeave:"mouseleave"};function jo(e,t){return/^on[A-Z]/.test(e)&&typeof t=="function"}function hv(e){return e.startsWith("aria-")||e.startsWith("data-"),e}function gv(e){return e.startsWith("aria-")||e.startsWith("data-")||fv.has(e)}function Hd(e){return e.startsWith("--")?e:e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}function bv(e){var t;const r=e.endsWith("Capture"),o=(r?e.slice(0,-7):e).slice(2);return{eventName:(t=pv[o])!=null?t:o.toLowerCase(),options:r?{capture:!0}:void 0}}function mv(e,t){let r=t.defaultPrevented,a=!1;const o=Object.create(t);return Object.defineProperties(o,{nativeEvent:{value:t},currentTarget:{value:e},target:{value:t.target},persist:{value:()=>{}},isDefaultPrevented:{value:()=>r},isPropagationStopped:{value:()=>a},preventDefault:{value:()=>{r=!0,t.preventDefault()}},stopPropagation:{value:()=>{a=!0,t.stopPropagation()}}}),o}function Oo(e){return uv.has(e)}function Vd(e,t,r){if(t==="tabIndex"){e.tabIndex=Number(r);return}e[t]=r}function vv(e,t){if(t==="tabIndex"){e.removeAttribute("tabindex");return}const r=e[t];if(typeof r=="boolean"){e[t]=!1;return}if(typeof r=="number"){e[t]=0;return}e[t]=""}function wv(e,t){return typeof t!="number"||t===0||e.startsWith("--")||dv.has(e)?String(t):`${t}px`}function xv(e,t){Rd.has(t)||e.style.removeProperty(Hd(t))}function yv(e,t,r){Rd.has(t)||e.style.setProperty(Hd(t),wv(t,r))}function kv(e,t,r){new Set([...Object.keys(t),...Object.keys(r)]).forEach(o=>{if(cv.has(o)||!gv(o)||jo(o,t[o])||jo(o,r[o]))return;const n=t[o],s=r[o];if(n===s)return;const i=hv(o);if(s==null||s===!1){Oo(o)&&vv(e,o),e.removeAttribute(i);return}if(s===!0){Oo(o)&&Vd(e,o,!0),e.setAttribute(i,"");return}if(Oo(o)){Vd(e,o,s);return}e.setAttribute(i,String(s))})}function $v(e,t,r){if(t!==r){if(r){e.className=r;return}e.removeAttribute("class")}}function Cv(e,t,r){const a=t??{},o=r??{};new Set([...Object.keys(a),...Object.keys(o)]).forEach(s=>{const i=a[s],l=o[s];if(i!==l){if(l==null){xv(e,s);return}yv(e,s,l)}})}function Pv(e,t,r){t.forEach(({eventName:o,listener:n,options:s})=>{e.removeEventListener(o,n,s)});const a=[];return Object.entries(r).forEach(([o,n])=>{if(!jo(o,n))return;const{eventName:s,options:i}=bv(o),l=d=>{n(mv(e,d))};e.addEventListener(s,l,i),a.push({eventName:s,listener:l,options:i})}),a}function Ud(e,t){const r=h.useRef({}),a=h.useRef([]);lv(()=>{const o=r.current;return $v(e,o.className,t.className),Cv(e,o.style,t.style),kv(e,o,t),a.current=Pv(e,a.current,t),r.current=t,()=>{a.current.forEach(({eventName:n,listener:s,options:i})=>{e.removeEventListener(n,s,i)}),a.current=[]}},[e,t])}var Gd=h.forwardRef(({pluginKey:e,editor:t,updateDelay:r,resizeDelay:a,appendTo:o,shouldShow:n=null,getReferencedVirtualElement:s,options:i,children:l,...d},c)=>{const u=h.useRef(document.createElement("div")),p=h.useRef(Wd(e,"bubbleMenu")).current;Ud(u.current,d),typeof c=="function"?c(u.current):c&&(c.current=u.current);const{editor:f}=rt.useCurrentEditor(),g=t||f,m={updateDelay:r,resizeDelay:a,appendTo:o,pluginKey:p,shouldShow:n,getReferencedVirtualElement:s,options:i},b=h.useRef(m);b.current=m;const[x,k]=h.useState(!1),C=h.useRef(!0);return h.useEffect(()=>{if(g?.isDestroyed)return;if(!g){console.warn("BubbleMenu component is not rendered inside of an editor component or does not have editor prop.");return}const E=u.current;E.style.visibility="hidden",E.style.position="absolute";const P=pc.BubbleMenuPlugin({...b.current,editor:g,element:E});g.registerPlugin(P);const _=b.current.pluginKey;return C.current=!0,k(!0),()=>{k(!1),g.unregisterPlugin(_),window.requestAnimationFrame(()=>{E.parentNode&&E.parentNode.removeChild(E)})}},[g]),h.useEffect(()=>{if(!(!x||!g||g.isDestroyed)){if(C.current){C.current=!1;return}g.view.dispatch(g.state.tr.setMeta(p,{type:"updateOptions",options:b.current}))}},[x,g,r,a,n,i,o,s,p]),yt.createPortal(l,u.current)});h.forwardRef(({pluginKey:e,editor:t,updateDelay:r,resizeDelay:a,appendTo:o,shouldShow:n=null,options:s,children:i,...l},d)=>{const c=h.useRef(document.createElement("div")),u=h.useRef(Wd(e,"floatingMenu")).current;Ud(c.current,l),typeof d=="function"?d(c.current):d&&(d.current=c.current);const{editor:p}=rt.useCurrentEditor(),f=t||p,g={updateDelay:r,resizeDelay:a,appendTo:o,pluginKey:u,shouldShow:n,options:s},m=h.useRef(g);m.current=g;const[b,x]=h.useState(!1),k=h.useRef(!0);return h.useEffect(()=>{if(f?.isDestroyed)return;if(!f){console.warn("FloatingMenu component is not rendered inside of an editor component or does not have editor prop.");return}const C=c.current;C.style.visibility="hidden",C.style.position="absolute";const E=Kd({...m.current,editor:f,element:C});f.registerPlugin(E);const P=m.current.pluginKey;return k.current=!0,x(!0),()=>{x(!1),f.unregisterPlugin(P),window.requestAnimationFrame(()=>{C.parentNode&&C.parentNode.removeChild(C)})}},[f]),h.useEffect(()=>{if(!(!b||!f||f.isDestroyed)){if(k.current){k.current=!1;return}f.view.dispatch(f.state.tr.setMeta(u,{type:"updateOptions",options:m.current}))}},[b,f,r,a,n,s,o,u]),yt.createPortal(i,c.current)});const Pe=h.memo(({name:e,className:t,strokeWidth:r})=>{const a=hc.icons[e];return a?v.jsx(a,{className:pe("w-4 h-4",t),strokeWidth:r||2.5}):null});Pe.displayName="Icon";const Ev=({editor:e,buttonKey:t,tooltipText:r,isIconOnly:a=!1,color:o="default",variant:n="light",isDisabled:s=!1,icon:i="AtSign",iconClass:l,text:d="Button",withActive:c=!1,onPressed:u})=>{const[p,f]=h.useState(()=>e.isActive(t));h.useEffect(()=>{const m=()=>f(e.isActive(t));return e.on("selectionUpdate",m),e.on("transaction",m),()=>{e.off("selectionUpdate",m),e.off("transaction",m)}},[e,t]);const g=h.useCallback(()=>{u?.()},[u]);return v.jsx(Gt,{delay:250,closeDelay:0,content:r,isDisabled:r==null,children:v.jsx(Qe,{size:"sm","data-active":c?p:!1,color:o,variant:n,isIconOnly:a,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:a?v.jsx(Pe,{name:i,className:l}):d})})},Zt=h.memo(Ev),Sv=Vo.createLowlight(Vo.all),qd=gc.configure({lowlight:Sv}),Yd=bc.extend({renderHTML(){return["div",Jt(this.options.HTMLAttributes,{"data-type":this.name}),["hr"]]}}),Xd=e=>{const{state:t}=e,{selection:r,doc:a}=t,{empty:o,from:n,to:s}=r,i=!a.textBetween(n,s).length&&Mo(r),l=r instanceof X.NodeSelection;return!(o||i||l)},Tv=e=>{const{state:t}=e,{selection:r,doc:a}=t;if(!(r instanceof X.TextSelection))return!1;let o=!1;return a.nodesBetween(r.from,r.to,n=>n.isText?(o=!0,!1):!0),o},Mv=e=>e.state.selection instanceof ge.CellSelection,zv=e=>[qd.name,Yd.name].some(r=>e.isActive(r)),Jd=e=>{const{state:t}=e,{selection:r}=t,a=["paragraph","code","heading","blockquote","taskList","orderedList"];if(!(r instanceof X.NodeSelection))return;const o=r.node;if(o)return a.includes(o.type.name)&&o.textContent},_v=e=>{const{state:t}=e,{selection:r}=t,a=["horizontalRule","imageUploader"];if(!(r instanceof X.NodeSelection))return;const o=r.node;if(o)return!a.includes(o.type.name)},Av=e=>{const{state:t}=e,{selection:r}=t;if(!(r instanceof X.NodeSelection))return;const a=r.node;if(!a)return;let o=!1;return a.marks.length?!0:(a.descendants(n=>n.marks?.length?(o=!0,!1):!0),o)},Nv=e=>{const{state:t}=e,{selection:r}=t;if(!(r instanceof X.NodeSelection))return;const a=r.node;if(a)return a.textContent.trim().length>0},Iv=e=>{const{selection:t,doc:r}=e;let a;if(t instanceof X.NodeSelection)a=t.node;else{const o=r.resolve(t.from);a=o.nodeAfter||o.parent}return a?a.type.name==="imageUploader"&&a.attrs?.id&&a.attrs?.uploading:!1},Dv=e=>{const{state:t}=e,{selection:r,doc:a}=t,o=r instanceof X.NodeSelection?r:X.NodeSelection.create(a,r.from),n=o.node,s=o.from;if(!n)return;const i=n.toJSON();e.chain().focus().command(({tr:l,dispatch:d,state:c})=>{const u=s+n.nodeSize,p=c.schema.nodeFromJSON(i);return l.insert(u,p),d&&d(l),!0}).run(),setTimeout(()=>{e.view.updateState(e.state);const l=s+n.nodeSize,d=X.NodeSelection.create(e.state.doc,l);e.view.dispatch(e.state.tr.setSelection(d))},0)},jv=e=>{const{state:t}=e,{selection:r}=t;if(!(r instanceof X.NodeSelection))return;const a=r.node;if(!a)return;const o=a.textContent;o&&navigator.clipboard.writeText(o).catch(n=>{console.error("Failed to copy to clipboard:",n)})},Ov=e=>{const{state:t}=e,{selection:r}=t;if(!(r instanceof X.NodeSelection))return;const{from:a,to:o}=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:a,to:o}).run(),e.view.focus()},Lv=e=>{const{state:t}=e,{selection:r}=t;if(!(r instanceof X.NodeSelection))return;const a=r.node,o=r.from;if(!a)return;const n=a.textContent;if(!n.trim()){e.chain().focus().command(({tr:s,dispatch:i})=>{const l=t.schema.nodes.paragraph.create();return s.replaceWith(o,o+a.nodeSize,l),i&&i(s),!0}).run();return}e.chain().focus().command(({tr:s,dispatch:i,state:l})=>{const d=l.schema.text(n),c=l.schema.nodes.paragraph.create(null,d);return s.replaceWith(o,o+a.nodeSize,c),i&&i(s),!0}).run(),setTimeout(()=>{e.view.updateState(e.state);try{const s=X.NodeSelection.create(e.state.doc,o);e.view.dispatch(e.state.tr.setSelection(s))}catch{e.commands.setTextSelection(o)}},0)},Bv=(e,t)=>{const{state:r}=e,{selection:a}=r,o=()=>{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}=a;return e.chain().focus().deleteRange({from:i,to:l}).insertContent({type:"horizontalRule"}).run()}}[t.key];s&&s()};if(a instanceof X.NodeSelection){const n=a.node,s=a.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}),o(),["bulletList","orderedList","taskList"].includes(t.key)||setTimeout(()=>{try{const d=X.NodeSelection.create(e.state.doc,s);e.view.dispatch(e.state.tr.setSelection(d))}catch{e.commands.setTextSelection(s)}},0)}else o()},Fv=(e,t)=>{e&&t!==null&&e.chain().focus().extendMarkRange("link").setLink({href:t}).run()},Kv=e=>{if(!e)return;e.getAttributes("link")?.href&&e.chain().focus().extendMarkRange("link").unsetLink().run()},Wv=async({file:e,url:t,onProgress:r,signal:a})=>new Promise((o,n)=>{const s=new XMLHttpRequest;a&&a.addEventListener("abort",()=>{s.abort(),n(new Error("AbortError"))}),s.upload.addEventListener("progress",l=>{if(l.lengthComputable){const d=Math.round(l.loaded/l.total*100);if(!r(d)){s.abort(),n(new Error("AbortError"));return}}}),s.addEventListener("load",()=>{if(s.status>=200&&s.status<300)try{const l=JSON.parse(s.responseText);o(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)}),Rv=(e,t)=>(Array.isArray(t)?t:t.split(".").filter(Boolean)).reduce((a,o)=>{if(!(a==null||typeof a!="object"))return a[o]},e),Hv=()=>`upload-${Date.now()}-${Math.random().toString(36).substring(2,8)}`,ga=(e,t,r)=>{const{state:a,view:o}=e,{doc:n}=a;let s=null;if(typeof t.pos=="number")s=t.pos;else if(t.id){let l=null;n.descendants((d,c)=>d.type.name==="imageUploader"&&d.attrs.id===t.id?(l=c,!1):!0),s=l}if(s===null){console.log("Could not find imageUploader node to update");return}const i=a.tr.setNodeMarkup(s,void 0,{...a.doc.nodeAt(s)?.attrs,...r});o.dispatch(i)};function Vv(e,t,r,a){const o=r+t.nodeSize,n=t.textContent,s=[];e.nodesBetween(r+1,o-1,(c,u)=>{if(c.isText&&c.text)for(let p=0;p<c.text.length;p++)s.push(u+p);return!0});const i=[],l=/\S+/g;let d;for(;(d=l.exec(n))!==null;){const c=d.index,u=d.index+d[0].length;i.push({index:i.length,text:d[0],absFrom:s[c]??r+1+c,absTo:s[u-1]!==void 0?s[u-1]+1:r+1+u})}return{index:a,type:t.type.name,text:n,absFrom:r,absTo:o,words:i,charMap:s}}const ba=e=>{const{doc:t}=e.state,r=[];return t.forEach((a,o,n)=>{r.push(Vv(t,a,o,n))}),{nodes:r}};function Zd(e,t){const r=t.nodeIndex!==void 0?e.nodes[t.nodeIndex]:void 0;if(!r)return null;if(t.wordIndex!==void 0){const a=r.words[t.wordIndex];return a?{absFrom:a.absFrom,absTo:a.absTo}:null}if(t.wordRange!==void 0){const[a,o]=t.wordRange,n=r.words[a],s=r.words[o];return!n||!s?null:{absFrom:n.absFrom,absTo:s.absTo}}if(t.charFrom!==void 0&&t.charTo!==void 0){const a=r.charMap[t.charFrom]??r.absFrom+1+t.charFrom,o=t.charTo>0&&r.charMap[t.charTo-1]!==void 0?r.charMap[t.charTo-1]+1:r.absFrom+1+t.charTo;return{absFrom:a,absTo:o}}return{absFrom:r.absFrom+1,absTo:r.absTo-1}}function Qd(e,t,r){const{schema:a,doc:o}=e.state;if(typeof r=="string"){if(!r)return null;const s=o.resolve(t).marks();return Ie.Fragment.from(a.text(r,s.length?s:void 0))}if(!r.length)return null;const n=r.map(s=>a.nodeFromJSON(s));return Ie.Fragment.from(n)}const Lo=(e,t)=>{const r=ba(e),a=Zd(r,t);if(!a)return!1;const o=Qd(e,a.absFrom,t.replacement),n=o?e.state.tr.replaceWith(a.absFrom,a.absTo,o):e.state.tr.delete(a.absFrom,a.absTo);return e.view.dispatch(n),!0},ec=(e,t)=>{if(t.length===0)return!0;if(t.length===1)return Lo(e,t[0]);const r=ba(e),a=[];for(const n of t){const s=Zd(r,n);s&&a.push({...s,replacement:n.replacement})}if(a.length===0)return!1;a.sort((n,s)=>s.absFrom-n.absFrom);let o=e.state.tr;for(const n of a){const s=Qd(e,n.absFrom,n.replacement);o=s?o.replaceWith(n.absFrom,n.absTo,s):o.delete(n.absFrom,n.absTo)}return e.view.dispatch(o),!0},Uv=({editor:e})=>{const[t,r]=h.useState(!1),[a,o]=h.useState(""),[n,s]=h.useState(!1),i=h.useCallback(()=>e.getAttributes("link")?.href||"",[e]);h.useEffect(()=>{const p=()=>{const f=i();o(f),s(e.isActive("link",{href:f}))};return e.on("selectionUpdate",p),e.on("transaction",p),()=>{e.off("selectionUpdate",p),e.off("transaction",p)}},[e,i]);const l=h.useCallback(()=>{a&&(Fv(e,a),s(!0))},[e,a]),d=h.useCallback(()=>{a&&window.open(a,"_blank","noopener,noreferrer,nofollow")},[a]),c=h.useCallback(()=>{Kv(e),o(""),s(!1),r(!1)},[e]),u=h.useCallback(p=>{p.key==="Enter"&&a&&(p.preventDefault(),l())},[l,a]);return v.jsxs(Nt,{placement:"bottom",isOpen:t,onOpenChange:r,children:[v.jsx(At,{children:v.jsx("div",{className:"z-2 flex items-center gap-0.5",children:v.jsx(Qe,{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(p=>!p),children:v.jsx(Gt,{content:"Link",delay:250,closeDelay:0,children:v.jsx("div",{className:"w-full h-full flex items-center justify-center",children:v.jsx(Pe,{name:"Link"})})})})})}),v.jsx(_t,{className:"p-1.5",children:v.jsxs("div",{className:"flex items-center gap-1",children:[v.jsx("div",{className:"relative flex flex-wrap items-stretch",children:v.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:a,onChange:p=>o(p.target.value),onKeyDown:u})}),v.jsx(Zt,{isIconOnly:!0,isDisabled:!a,editor:e,buttonKey:"validate",tooltipText:"Set link",icon:"CornerDownLeft",withActive:!1,onPressed:l}),v.jsx(Be,{orientation:"vertical",className:"h-6"}),v.jsxs("div",{className:"flex items-center gap-1.5",children:[v.jsx(Zt,{isIconOnly:!0,isDisabled:!a,editor:e,buttonKey:"open_in_new_tab",tooltipText:"Open link",icon:"ExternalLink",withActive:!1,onPressed:d}),v.jsx(Zt,{isIconOnly:!0,isDisabled:!a,color:"danger",buttonKey:"remove_link",iconClass:"text-danger",editor:e,tooltipText:"Remove link",icon:"Trash",withActive:!1,onPressed:c})]})]})})]})},Gv=h.memo(Uv),tc=({color:e,bgColor:t,buttonType:r})=>v.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"&&v.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:v.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"})})}),qv=({editor:e,buttonType:t,hsl:r,color:a,bgColor:o,tooltipText:n,tooltipDisabled:s=!1})=>{const i=t==="text"?e.getAttributes("textStyle")?.color===r:e.getAttributes("highlight")?.color===r,l=h.useCallback(()=>{t==="text"?i?e.commands.unsetColor():e.commands.setColor(r):e.commands.toggleHighlight({color:r})},[e,t,r,i]);return v.jsx(Gt,{content:n,delay:250,closeDelay:0,isDisabled:s,children:v.jsx(Qe,{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:v.jsx("div",{className:"w-full h-full flex items-center justify-center",children:v.jsx(tc,{color:a,bgColor:o,buttonType:t})})})})},Yv=h.memo(qv),Bo=[{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()}}]}],Xv=({editor:e})=>{const t=h.useCallback(()=>e.getAttributes("textStyle")?.color||"",[e]),r=h.useCallback(()=>e.getAttributes("highlight")?.color||"",[e]),[a,o]=h.useState(t),[n,s]=h.useState(r);return h.useEffect(()=>{const i=()=>{o(t()),s(r())};return e.on("selectionUpdate",i),e.on("transaction",i),()=>{e.off("selectionUpdate",i),e.off("transaction",i)}},[e,t,r]),v.jsxs(Nt,{placement:"bottom",children:[v.jsx(At,{children:v.jsx("div",{className:"z-2 flex items-center gap-0.5",children:v.jsx(Qe,{size:"sm",color:"default",variant:"light",isIconOnly:!0,isDisabled:!1,"aria-label":"Color menu",className:"text-foreground-500",children:v.jsx(Gt,{content:"Color",delay:250,closeDelay:0,children:v.jsx("div",{className:"w-full h-full flex items-center justify-center",children:v.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:a||"hsla(var(--heroui-foreground), 0.5)",backgroundColor:n||"hsla(var(--heroui-foreground), 0.5)"},children:v.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",style:{color:a||"hsla(var(--heroui-foreground), 0.5)"},children:v.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"})})})})})})})}),v.jsx(_t,{className:"px-1.5 py-2",children:v.jsx("div",{className:"flex flex-col gap-2",children:Bo.map(i=>v.jsxs("div",{className:"flex flex-col gap-1",children:[v.jsx("p",{className:"text-xs font-semibold leading-normal capitalize text-foreground px-1",children:i.title}),v.jsx("div",{className:"grid grid-cols-5 grid-rows-2 gap-0.5",children:i.colors.map(l=>v.jsx(Yv,{hsl:l.hsl,editor:e,color:l.color,bgColor:l.bgColor,tooltipText:l.tooltipText,buttonType:i.buttonType},l.color))})]},i.key))})})]})},Jv=h.memo(Xv),Zv=({editor:e})=>{const t=h.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,a]=h.useState(t);h.useEffect(()=>{const s=()=>a(t());return e.on("selectionUpdate",s),e.on("transaction",s),()=>{e.off("selectionUpdate",s),e.off("transaction",s)}},[e,t]);const o=h.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=h.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 v.jsxs(Nt,{placement:"bottom",children:[v.jsx(At,{children:v.jsx("div",{className:"z-2 flex items-center gap-0.5",children:v.jsx(Qe,{size:"sm","data-active":r,color:"default",variant:"light",isIconOnly:!0,isDisabled:!1,"aria-label":"More options",className:`text-foreground-500 hover:text-foreground
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
${g}`}}),l}var yr=class fc extends Bd{constructor(){super(...arguments),this.type="node"}static create(t={}){const r=typeof t=="function"?t():t;return new fc(r)}configure(t){return super.configure(t)}extend(t){const r=typeof t=="function"?t():t;return super.extend(r)}},iv=class{constructor({editor:e,element:t,view:r,pluginKey:a="floatingMenu",updateDelay:o=250,resizeDelay:n=60,options:s,appendTo:i,shouldShow:l}){this.preventHide=!1,this.isVisible=!1,this.scrollTarget=window,this.shouldShow=({view:c,state:u})=>{const{selection:p}=u,{$anchor:f,empty:g}=p,m=f.depth===1,b=f.parent.isTextblock&&!f.parent.type.spec.code&&!f.parent.textContent&&f.parent.childCount===0&&!this.getTextContent(f.parent);return!(!c.hasFocus()||!g||!m||!b||!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=(c,u,p,f)=>{const{composing:g}=c;if(g||!u&&!p)return;if(!this.getShouldShow(f)){this.hide();return}this.updatePosition(),this.show()},this.mousedownHandler=()=>{this.preventHide=!0},this.focusHandler=()=>{setTimeout(()=>this.update(this.editor.view))},this.blurHandler=({event:c})=>{var u;if(this.preventHide){this.preventHide=!1;return}c?.relatedTarget&&((u=this.element.parentNode)!=null&&u.contains(c.relatedTarget))||c?.relatedTarget!==this.editor.view.dom&&this.hide()},this.transactionHandler=({transaction:c})=>{const u=c.getMeta(this.pluginKey);u==="updatePosition"?this.updatePosition():u&&typeof u=="object"&&u.type==="updateOptions"&&this.updateOptions(u.options)},this.resizeHandler=()=>{this.resizeDebounceTimer&&clearTimeout(this.resizeDebounceTimer),this.resizeDebounceTimer=window.setTimeout(()=>{this.updatePosition()},this.resizeDelay)};var d;this.editor=e,this.element=t,this.view=r,this.pluginKey=a,this.updateDelay=o,this.resizeDelay=n,this.appendTo=i,this.scrollTarget=(d=s?.scrollTarget)!=null?d:window,this.floatingUIOptions={...this.floatingUIOptions,...s},this.element.tabIndex=0,l&&(this.shouldShow=l),this.element.addEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.editor.on("focus",this.focusHandler),this.editor.on("blur",this.blurHandler),this.editor.on("transaction",this.transactionHandler),window.addEventListener("resize",this.resizeHandler),this.scrollTarget.addEventListener("scroll",this.resizeHandler),this.update(r,r.state),this.getShouldShow()&&(this.show(),this.updatePosition())}getTextContent(e){return gm(e,{textSerializers:Nd(this.editor.schema)})}get middlewares(){const e=[];return this.floatingUIOptions.flip&&e.push(Le.flip(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&e.push(Le.shift(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&e.push(Le.offset(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&e.push(Le.arrow(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&e.push(Le.size(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&e.push(Le.autoPlacement(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&e.push(Le.hide(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&e.push(Le.inline(typeof this.floatingUIOptions.inline!="boolean"?this.floatingUIOptions.inline:void 0)),e}getShouldShow(e){var t;const{state:r}=this.view,{selection:a}=r,{ranges:o}=a,n=Math.min(...o.map(l=>l.$from.pos)),s=Math.max(...o.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})}updateOptions(e){var t;if(e.updateDelay!==void 0&&(this.updateDelay=e.updateDelay),e.resizeDelay!==void 0&&(this.resizeDelay=e.resizeDelay),e.appendTo!==void 0&&(this.appendTo=e.appendTo),e.shouldShow!==void 0&&e.shouldShow&&(this.shouldShow=e.shouldShow),e.options!==void 0){const r=(t=e.options.scrollTarget)!=null?t:window;r!==this.scrollTarget&&(this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.scrollTarget=r,this.scrollTarget.addEventListener("scroll",this.resizeHandler)),this.floatingUIOptions={...this.floatingUIOptions,...e.options}}}updatePosition(){const{selection:e}=this.editor.state,t=jd(this.view,e.from,e.to),r={getBoundingClientRect:()=>t,getClientRects:()=>[t]};Le.computePosition(r,this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:a,y:o,strategy:n,middlewareData:s})=>{var i,l;if((i=s.hide)!=null&&i.referenceHidden||(l=s.hide)!=null&&l.escaped){this.element.style.visibility="hidden";return}this.element.style.visibility="visible",this.element.style.width="max-content",this.element.style.position=n,this.element.style.left=`${a}px`,this.element.style.top=`${o}px`,this.isVisible&&this.floatingUIOptions.onUpdate&&this.floatingUIOptions.onUpdate()})}update(e,t){const r=!t?.selection.eq(e.state.selection),a=!t?.doc.eq(e.state.doc);this.updateHandler(e,r,a,t)}show(){var e;if(this.isVisible)return;this.element.style.visibility="visible",this.element.style.opacity="1";const t=typeof this.appendTo=="function"?this.appendTo():this.appendTo;(e=t??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}),window.removeEventListener("resize",this.resizeHandler),this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.editor.off("focus",this.focusHandler),this.editor.off("blur",this.blurHandler),this.editor.off("transaction",this.transactionHandler),this.floatingUIOptions.onDestroy&&this.floatingUIOptions.onDestroy()}},Kd=e=>new X.Plugin({key:typeof e.pluginKey=="string"?new X.PluginKey(e.pluginKey):e.pluginKey,view:t=>new iv({view:t,...e})});ze.create({name:"floatingMenu",addOptions(){return{element:null,options:{},pluginKey:"floatingMenu",updateDelay:void 0,resizeDelay:void 0,appendTo:void 0,shouldShow:null}},addCommands(){return{updateFloatingMenuPosition:()=>({tr:e,dispatch:t})=>(t&&e.setMeta(this.options.pluginKey,"updatePosition"),!0)}},addProseMirrorPlugins(){return this.options.element?[Kd({pluginKey:this.options.pluginKey,editor:this.editor,element:this.options.element,updateDelay:this.options.updateDelay,resizeDelay:this.options.resizeDelay,options:this.options.options,appendTo:this.options.appendTo,shouldShow:this.options.shouldShow})]:[]}});function Wd(e,t){return e??new X.PluginKey(t)}var lv=typeof window<"u"?h.useLayoutEffect:h.useEffect,Rd=new Set(["left","opacity","position","top","visibility","width"]),dv=new Set(["animationIterationCount","aspectRatio","borderImageOutset","borderImageSlice","borderImageWidth","columnCount","columns","fillOpacity","flex","flexGrow","flexShrink","fontWeight","gridArea","gridColumn","gridColumnEnd","gridColumnStart","gridRow","gridRowEnd","gridRowStart","lineClamp","lineHeight","opacity","order","orphans","scale","stopOpacity","strokeDasharray","strokeDashoffset","strokeMiterlimit","strokeOpacity","strokeWidth","tabSize","widows","zIndex","zoom"]),cv=new Set(["children","className","style"]),uv=new Set(["tabIndex"]),fv=new Set(["accessKey","autoCapitalize","contentEditable","contextMenu","dir","draggable","enterKeyHint","hidden","id","lang","nonce","role","slot","spellCheck","tabIndex","title","translate"]),pv={Blur:"focusout",DoubleClick:"dblclick",Focus:"focusin",MouseEnter:"mouseenter",MouseLeave:"mouseleave"};function jo(e,t){return/^on[A-Z]/.test(e)&&typeof t=="function"}function hv(e){return e.startsWith("aria-")||e.startsWith("data-"),e}function gv(e){return e.startsWith("aria-")||e.startsWith("data-")||fv.has(e)}function Hd(e){return e.startsWith("--")?e:e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}function bv(e){var t;const r=e.endsWith("Capture"),o=(r?e.slice(0,-7):e).slice(2);return{eventName:(t=pv[o])!=null?t:o.toLowerCase(),options:r?{capture:!0}:void 0}}function mv(e,t){let r=t.defaultPrevented,a=!1;const o=Object.create(t);return Object.defineProperties(o,{nativeEvent:{value:t},currentTarget:{value:e},target:{value:t.target},persist:{value:()=>{}},isDefaultPrevented:{value:()=>r},isPropagationStopped:{value:()=>a},preventDefault:{value:()=>{r=!0,t.preventDefault()}},stopPropagation:{value:()=>{a=!0,t.stopPropagation()}}}),o}function Oo(e){return uv.has(e)}function Vd(e,t,r){if(t==="tabIndex"){e.tabIndex=Number(r);return}e[t]=r}function vv(e,t){if(t==="tabIndex"){e.removeAttribute("tabindex");return}const r=e[t];if(typeof r=="boolean"){e[t]=!1;return}if(typeof r=="number"){e[t]=0;return}e[t]=""}function wv(e,t){return typeof t!="number"||t===0||e.startsWith("--")||dv.has(e)?String(t):`${t}px`}function xv(e,t){Rd.has(t)||e.style.removeProperty(Hd(t))}function yv(e,t,r){Rd.has(t)||e.style.setProperty(Hd(t),wv(t,r))}function kv(e,t,r){new Set([...Object.keys(t),...Object.keys(r)]).forEach(o=>{if(cv.has(o)||!gv(o)||jo(o,t[o])||jo(o,r[o]))return;const n=t[o],s=r[o];if(n===s)return;const i=hv(o);if(s==null||s===!1){Oo(o)&&vv(e,o),e.removeAttribute(i);return}if(s===!0){Oo(o)&&Vd(e,o,!0),e.setAttribute(i,"");return}if(Oo(o)){Vd(e,o,s);return}e.setAttribute(i,String(s))})}function $v(e,t,r){if(t!==r){if(r){e.className=r;return}e.removeAttribute("class")}}function Cv(e,t,r){const a=t??{},o=r??{};new Set([...Object.keys(a),...Object.keys(o)]).forEach(s=>{const i=a[s],l=o[s];if(i!==l){if(l==null){xv(e,s);return}yv(e,s,l)}})}function Pv(e,t,r){t.forEach(({eventName:o,listener:n,options:s})=>{e.removeEventListener(o,n,s)});const a=[];return Object.entries(r).forEach(([o,n])=>{if(!jo(o,n))return;const{eventName:s,options:i}=bv(o),l=d=>{n(mv(e,d))};e.addEventListener(s,l,i),a.push({eventName:s,listener:l,options:i})}),a}function Ud(e,t){const r=h.useRef({}),a=h.useRef([]);lv(()=>{const o=r.current;return $v(e,o.className,t.className),Cv(e,o.style,t.style),kv(e,o,t),a.current=Pv(e,a.current,t),r.current=t,()=>{a.current.forEach(({eventName:n,listener:s,options:i})=>{e.removeEventListener(n,s,i)}),a.current=[]}},[e,t])}var Gd=h.forwardRef(({pluginKey:e,editor:t,updateDelay:r,resizeDelay:a,appendTo:o,shouldShow:n=null,getReferencedVirtualElement:s,options:i,children:l,...d},c)=>{const u=h.useRef(document.createElement("div")),p=h.useRef(Wd(e,"bubbleMenu")).current;Ud(u.current,d),typeof c=="function"?c(u.current):c&&(c.current=u.current);const{editor:f}=rt.useCurrentEditor(),g=t||f,m={updateDelay:r,resizeDelay:a,appendTo:o,pluginKey:p,shouldShow:n,getReferencedVirtualElement:s,options:i},b=h.useRef(m);b.current=m;const[x,k]=h.useState(!1),C=h.useRef(!0);return h.useEffect(()=>{if(g?.isDestroyed)return;if(!g){console.warn("BubbleMenu component is not rendered inside of an editor component or does not have editor prop.");return}const E=u.current;E.style.visibility="hidden",E.style.position="absolute";const P=pc.BubbleMenuPlugin({...b.current,editor:g,element:E});g.registerPlugin(P);const _=b.current.pluginKey;return C.current=!0,k(!0),()=>{k(!1),g.unregisterPlugin(_),window.requestAnimationFrame(()=>{E.parentNode&&E.parentNode.removeChild(E)})}},[g]),h.useEffect(()=>{if(!(!x||!g||g.isDestroyed)){if(C.current){C.current=!1;return}g.view.dispatch(g.state.tr.setMeta(p,{type:"updateOptions",options:b.current}))}},[x,g,r,a,n,i,o,s,p]),yt.createPortal(l,u.current)});h.forwardRef(({pluginKey:e,editor:t,updateDelay:r,resizeDelay:a,appendTo:o,shouldShow:n=null,options:s,children:i,...l},d)=>{const c=h.useRef(document.createElement("div")),u=h.useRef(Wd(e,"floatingMenu")).current;Ud(c.current,l),typeof d=="function"?d(c.current):d&&(d.current=c.current);const{editor:p}=rt.useCurrentEditor(),f=t||p,g={updateDelay:r,resizeDelay:a,appendTo:o,pluginKey:u,shouldShow:n,options:s},m=h.useRef(g);m.current=g;const[b,x]=h.useState(!1),k=h.useRef(!0);return h.useEffect(()=>{if(f?.isDestroyed)return;if(!f){console.warn("FloatingMenu component is not rendered inside of an editor component or does not have editor prop.");return}const C=c.current;C.style.visibility="hidden",C.style.position="absolute";const E=Kd({...m.current,editor:f,element:C});f.registerPlugin(E);const P=m.current.pluginKey;return k.current=!0,x(!0),()=>{x(!1),f.unregisterPlugin(P),window.requestAnimationFrame(()=>{C.parentNode&&C.parentNode.removeChild(C)})}},[f]),h.useEffect(()=>{if(!(!b||!f||f.isDestroyed)){if(k.current){k.current=!1;return}f.view.dispatch(f.state.tr.setMeta(u,{type:"updateOptions",options:m.current}))}},[b,f,r,a,n,s,o,u]),yt.createPortal(i,c.current)});const Pe=h.memo(({name:e,className:t,strokeWidth:r})=>{const a=hc.icons[e];return a?v.jsx(a,{className:pe("w-4 h-4",t),strokeWidth:r||2.5}):null});Pe.displayName="Icon";const Ev=({editor:e,buttonKey:t,tooltipText:r,isIconOnly:a=!1,color:o="default",variant:n="light",isDisabled:s=!1,icon:i="AtSign",iconClass:l,text:d="Button",withActive:c=!1,onPressed:u})=>{const[p,f]=h.useState(()=>e.isActive(t));h.useEffect(()=>{const m=()=>f(e.isActive(t));return e.on("selectionUpdate",m),e.on("transaction",m),()=>{e.off("selectionUpdate",m),e.off("transaction",m)}},[e,t]);const g=h.useCallback(()=>{u?.()},[u]);return v.jsx(Gt,{delay:250,closeDelay:0,content:r,isDisabled:r==null,children:v.jsx(Qe,{size:"sm","data-active":c?p:!1,color:o,variant:n,isIconOnly:a,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:a?v.jsx(Pe,{name:i,className:l}):d})})},Zt=h.memo(Ev),Sv=Vo.createLowlight(Vo.all),qd=gc.configure({lowlight:Sv}),Yd=bc.extend({renderHTML(){return["div",Jt(this.options.HTMLAttributes,{"data-type":this.name}),["hr"]]}}),Xd=e=>{const{state:t}=e,{selection:r,doc:a}=t,{empty:o,from:n,to:s}=r,i=!a.textBetween(n,s).length&&Mo(r),l=r instanceof X.NodeSelection;return!(o||i||l)},Tv=e=>{const{state:t}=e,{selection:r,doc:a}=t;if(!(r instanceof X.TextSelection))return!1;let o=!1;return a.nodesBetween(r.from,r.to,n=>n.isText?(o=!0,!1):!0),o},Mv=e=>e.state.selection instanceof ge.CellSelection,zv=e=>[qd.name,Yd.name].some(r=>e.isActive(r)),Jd=e=>{const{state:t}=e,{selection:r}=t,a=["paragraph","code","heading","blockquote","taskList","orderedList"];if(!(r instanceof X.NodeSelection))return;const o=r.node;if(o)return a.includes(o.type.name)&&o.textContent},_v=e=>{const{state:t}=e,{selection:r}=t,a=["horizontalRule","imageUploader"];if(!(r instanceof X.NodeSelection))return;const o=r.node;if(o)return!a.includes(o.type.name)},Av=e=>{const{state:t}=e,{selection:r}=t;if(!(r instanceof X.NodeSelection))return;const a=r.node;if(!a)return;let o=!1;return a.marks.length?!0:(a.descendants(n=>n.marks?.length?(o=!0,!1):!0),o)},Nv=e=>{const{state:t}=e,{selection:r}=t;if(!(r instanceof X.NodeSelection))return;const a=r.node;if(a)return a.textContent.trim().length>0},Iv=e=>{const{selection:t,doc:r}=e;let a;if(t instanceof X.NodeSelection)a=t.node;else{const o=r.resolve(t.from);a=o.nodeAfter||o.parent}return a?a.type.name==="imageUploader"&&a.attrs?.id&&a.attrs?.uploading:!1},Dv=e=>{const{state:t}=e,{selection:r,doc:a}=t,o=r instanceof X.NodeSelection?r:X.NodeSelection.create(a,r.from),n=o.node,s=o.from;if(!n)return;const i=n.toJSON();e.chain().focus().command(({tr:l,dispatch:d,state:c})=>{const u=s+n.nodeSize,p=c.schema.nodeFromJSON(i);return l.insert(u,p),d&&d(l),!0}).run(),setTimeout(()=>{e.view.updateState(e.state);const l=s+n.nodeSize,d=X.NodeSelection.create(e.state.doc,l);e.view.dispatch(e.state.tr.setSelection(d))},0)},jv=e=>{const{state:t}=e,{selection:r}=t;if(!(r instanceof X.NodeSelection))return;const a=r.node;if(!a)return;const o=a.textContent;o&&navigator.clipboard.writeText(o).catch(n=>{console.error("Failed to copy to clipboard:",n)})},Ov=e=>{const{state:t}=e,{selection:r}=t;if(!(r instanceof X.NodeSelection))return;const{from:a,to:o}=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:a,to:o}).run(),e.view.focus()},Lv=e=>{const{state:t}=e,{selection:r}=t;if(!(r instanceof X.NodeSelection))return;const a=r.node,o=r.from;if(!a)return;const n=a.textContent;if(!n.trim()){e.chain().focus().command(({tr:s,dispatch:i})=>{const l=t.schema.nodes.paragraph.create();return s.replaceWith(o,o+a.nodeSize,l),i&&i(s),!0}).run();return}e.chain().focus().command(({tr:s,dispatch:i,state:l})=>{const d=l.schema.text(n),c=l.schema.nodes.paragraph.create(null,d);return s.replaceWith(o,o+a.nodeSize,c),i&&i(s),!0}).run(),setTimeout(()=>{e.view.updateState(e.state);try{const s=X.NodeSelection.create(e.state.doc,o);e.view.dispatch(e.state.tr.setSelection(s))}catch{e.commands.setTextSelection(o)}},0)},Bv=(e,t)=>{const{state:r}=e,{selection:a}=r,o=()=>{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}=a;return e.chain().focus().deleteRange({from:i,to:l}).insertContent({type:"horizontalRule"}).run()}}[t.key];s&&s()};if(a instanceof X.NodeSelection){const n=a.node,s=a.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}),o(),["bulletList","orderedList","taskList"].includes(t.key)||setTimeout(()=>{try{const d=X.NodeSelection.create(e.state.doc,s);e.view.dispatch(e.state.tr.setSelection(d))}catch{e.commands.setTextSelection(s)}},0)}else o()},Fv=(e,t)=>{e&&t!==null&&e.chain().focus().extendMarkRange("link").setLink({href:t}).run()},Kv=e=>{if(!e)return;e.getAttributes("link")?.href&&e.chain().focus().extendMarkRange("link").unsetLink().run()},Wv=async({file:e,url:t,onProgress:r,signal:a})=>new Promise((o,n)=>{const s=new XMLHttpRequest;a&&a.addEventListener("abort",()=>{s.abort(),n(new Error("AbortError"))}),s.upload.addEventListener("progress",l=>{if(l.lengthComputable){const d=Math.round(l.loaded/l.total*100);if(!r(d)){s.abort(),n(new Error("AbortError"));return}}}),s.addEventListener("load",()=>{if(s.status>=200&&s.status<300)try{const l=JSON.parse(s.responseText);o(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)}),Rv=(e,t)=>(Array.isArray(t)?t:t.split(".").filter(Boolean)).reduce((a,o)=>{if(!(a==null||typeof a!="object"))return a[o]},e),Hv=()=>`upload-${Date.now()}-${Math.random().toString(36).substring(2,8)}`,ga=(e,t,r)=>{const{state:a,view:o}=e,{doc:n}=a;let s=null;if(typeof t.pos=="number")s=t.pos;else if(t.id){let l=null;n.descendants((d,c)=>d.type.name==="imageUploader"&&d.attrs.id===t.id?(l=c,!1):!0),s=l}if(s===null){console.log("Could not find imageUploader node to update");return}const i=a.tr.setNodeMarkup(s,void 0,{...a.doc.nodeAt(s)?.attrs,...r});o.dispatch(i)};function Vv(e,t,r,a){const o=r+t.nodeSize,n=t.textContent,s=[];e.nodesBetween(r+1,o-1,(c,u)=>{if(c.isText&&c.text)for(let p=0;p<c.text.length;p++)s.push(u+p);return!0});const i=[],l=/\S+/g;let d;for(;(d=l.exec(n))!==null;){const c=d.index,u=d.index+d[0].length;i.push({index:i.length,text:d[0],absFrom:s[c]??r+1+c,absTo:s[u-1]!==void 0?s[u-1]+1:r+1+u})}return{index:a,type:t.type.name,text:n,absFrom:r,absTo:o,words:i,charMap:s}}const ba=e=>{const{doc:t}=e.state,r=[];return t.forEach((a,o,n)=>{r.push(Vv(t,a,o,n))}),{nodes:r}};function Zd(e,t){const r=t.nodeIndex!==void 0?e.nodes[t.nodeIndex]:void 0;if(!r)return null;if(t.wordIndex!==void 0){const a=r.words[t.wordIndex];return a?{absFrom:a.absFrom,absTo:a.absTo}:null}if(t.wordRange!==void 0){const[a,o]=t.wordRange,n=r.words[a],s=r.words[o];return!n||!s?null:{absFrom:n.absFrom,absTo:s.absTo}}if(t.charFrom!==void 0&&t.charTo!==void 0){const a=r.charMap[t.charFrom]??r.absFrom+1+t.charFrom,o=t.charTo>0&&r.charMap[t.charTo-1]!==void 0?r.charMap[t.charTo-1]+1:r.absFrom+1+t.charTo;return{absFrom:a,absTo:o}}return{absFrom:r.absFrom+1,absTo:r.absTo-1}}function Qd(e,t,r){const{schema:a,doc:o}=e.state;if(typeof r=="string"){if(!r)return null;const s=o.resolve(t).marks();return Ie.Fragment.from(a.text(r,s.length?s:void 0))}if(!r.length)return null;const n=r.map(s=>a.nodeFromJSON(s));return Ie.Fragment.from(n)}const Lo=(e,t)=>{const r=ba(e),a=Zd(r,t);if(!a)return!1;const o=Qd(e,a.absFrom,t.replacement),n=o?e.state.tr.replaceWith(a.absFrom,a.absTo,o):e.state.tr.delete(a.absFrom,a.absTo);return e.view.dispatch(n),!0},ec=(e,t)=>{if(t.length===0)return!0;if(t.length===1)return Lo(e,t[0]);const r=ba(e),a=[];for(const n of t){const s=Zd(r,n);s&&a.push({...s,replacement:n.replacement})}if(a.length===0)return!1;a.sort((n,s)=>s.absFrom-n.absFrom);let o=e.state.tr;for(const n of a){const s=Qd(e,n.absFrom,n.replacement);o=s?o.replaceWith(n.absFrom,n.absTo,s):o.delete(n.absFrom,n.absTo)}return e.view.dispatch(o),!0},Uv=({editor:e})=>{const[t,r]=h.useState(!1),[a,o]=h.useState(""),[n,s]=h.useState(!1),i=h.useCallback(()=>e.getAttributes("link")?.href||"",[e]);h.useEffect(()=>{const p=()=>{const f=i();o(f),s(e.isActive("link",{href:f}))};return e.on("selectionUpdate",p),e.on("transaction",p),()=>{e.off("selectionUpdate",p),e.off("transaction",p)}},[e,i]);const l=h.useCallback(()=>{a&&(Fv(e,a),s(!0))},[e,a]),d=h.useCallback(()=>{a&&window.open(a,"_blank","noopener,noreferrer,nofollow")},[a]),c=h.useCallback(()=>{Kv(e),o(""),s(!1),r(!1)},[e]),u=h.useCallback(p=>{p.key==="Enter"&&a&&(p.preventDefault(),l())},[l,a]);return v.jsxs(Nt,{placement:"bottom",isOpen:t,onOpenChange:r,children:[v.jsx(At,{children:v.jsx("div",{className:"z-2 flex items-center gap-0.5",children:v.jsx(Qe,{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(p=>!p),children:v.jsx(Gt,{content:"Link",delay:250,closeDelay:0,children:v.jsx("div",{className:"w-full h-full flex items-center justify-center",children:v.jsx(Pe,{name:"Link"})})})})})}),v.jsx(_t,{className:"p-1.5",children:v.jsxs("div",{className:"flex items-center gap-1",children:[v.jsx("div",{className:"relative flex flex-wrap items-stretch",children:v.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:a,onChange:p=>o(p.target.value),onKeyDown:u})}),v.jsx(Zt,{isIconOnly:!0,isDisabled:!a,editor:e,buttonKey:"validate",tooltipText:"Set link",icon:"CornerDownLeft",withActive:!1,onPressed:l}),v.jsx(Be,{orientation:"vertical",className:"h-6"}),v.jsxs("div",{className:"flex items-center gap-1.5",children:[v.jsx(Zt,{isIconOnly:!0,isDisabled:!a,editor:e,buttonKey:"open_in_new_tab",tooltipText:"Open link",icon:"ExternalLink",withActive:!1,onPressed:d}),v.jsx(Zt,{isIconOnly:!0,isDisabled:!a,color:"danger",buttonKey:"remove_link",iconClass:"text-danger",editor:e,tooltipText:"Remove link",icon:"Trash",withActive:!1,onPressed:c})]})]})})]})},Gv=h.memo(Uv),tc=({color:e,bgColor:t,buttonType:r})=>v.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"&&v.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:v.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"})})}),qv=({editor:e,buttonType:t,hsl:r,color:a,bgColor:o,tooltipText:n,tooltipDisabled:s=!1})=>{const i=t==="text"?e.getAttributes("textStyle")?.color===r:e.getAttributes("highlight")?.color===r,l=h.useCallback(()=>{t==="text"?i?e.commands.unsetColor():e.commands.setColor(r):e.commands.toggleHighlight({color:r})},[e,t,r,i]);return v.jsx(Gt,{content:n,delay:250,closeDelay:0,isDisabled:s,children:v.jsx(Qe,{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:v.jsx("div",{className:"w-full h-full flex items-center justify-center",children:v.jsx(tc,{color:a,bgColor:o,buttonType:t})})})})},Yv=h.memo(qv),Bo=[{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()}}]}],Xv=({editor:e})=>{const t=h.useCallback(()=>e.getAttributes("textStyle")?.color||"",[e]),r=h.useCallback(()=>e.getAttributes("highlight")?.color||"",[e]),[a,o]=h.useState(t),[n,s]=h.useState(r);return h.useEffect(()=>{const i=()=>{o(t()),s(r())};return e.on("selectionUpdate",i),e.on("transaction",i),()=>{e.off("selectionUpdate",i),e.off("transaction",i)}},[e,t,r]),v.jsxs(Nt,{placement:"bottom",children:[v.jsx(At,{children:v.jsx(Qe,{size:"sm",color:"default",variant:"light",isIconOnly:!0,isDisabled:!1,"aria-label":"Color menu",className:"text-foreground-500",children:v.jsx(Gt,{content:"Color",delay:250,closeDelay:0,children:v.jsx("div",{className:"w-full h-full flex items-center justify-center",children:v.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:a||"hsla(var(--heroui-foreground), 0.5)",backgroundColor:n||"hsla(var(--heroui-foreground), 0.5)"},children:v.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",style:{color:a||"hsla(var(--heroui-foreground), 0.5)"},children:v.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"})})})})})})}),v.jsx(_t,{className:"px-1.5 py-2",children:v.jsx("div",{className:"flex flex-col gap-2",children:Bo.map(i=>v.jsxs("div",{className:"flex flex-col gap-1",children:[v.jsx("p",{className:"text-xs font-semibold leading-normal capitalize text-foreground px-1",children:i.title}),v.jsx("div",{className:"grid grid-cols-5 grid-rows-2 gap-0.5",children:i.colors.map(l=>v.jsx(Yv,{hsl:l.hsl,editor:e,color:l.color,bgColor:l.bgColor,tooltipText:l.tooltipText,buttonType:i.buttonType},l.color))})]},i.key))})})]})},Jv=h.memo(Xv),Zv=({editor:e})=>{const t=h.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,a]=h.useState(t);h.useEffect(()=>{const s=()=>a(t());return e.on("selectionUpdate",s),e.on("transaction",s),()=>{e.off("selectionUpdate",s),e.off("transaction",s)}},[e,t]);const o=h.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=h.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 v.jsxs(Nt,{placement:"bottom",children:[v.jsx(At,{children:v.jsx(Qe,{size:"sm","data-active":r,color:"default",variant:"light",isIconOnly:!0,isDisabled:!1,"aria-label":"More options",className:`text-foreground-500 hover:text-foreground
|
|
41
|
+
data-[active=true]:bg-divider/45 data-[active=true]:text-primary
|
|
42
|
+
data-[active=true]:hover:bg-divider/45 data-[active=true]:hover:text-foreground`,children:v.jsx(Gt,{content:"More options",delay:250,closeDelay:0,children:v.jsx("div",{className:"w-full h-full flex items-center justify-center",children:v.jsx(Pe,{name:"EllipsisVertical"})})})})}),v.jsx(_t,{className:"p-1.5",children:v.jsxs("div",{className:"flex h-8 items-center gap-1.5",children:[o.map(s=>v.jsx(Zt,{editor:e,isIconOnly:!0,withActive:!0,buttonKey:s.key,tooltipText:s.tooltipText,icon:s.icon,onPressed:s.command},s.key)),v.jsx(Be,{orientation:"vertical",className:"h-6"}),n.map(s=>v.jsx(Zt,{editor:e,isIconOnly:!0,withActive:!0,buttonKey:{textAlign:s.key},tooltipText:s.tooltipText,icon:s.icon,onPressed:s.command},s.key))]})})]})},Qv=h.memo(Zv),e0=({editor:e})=>{const[t,r]=h.useState(!1),[,a]=h.useState(0);h.useEffect(()=>{const s=()=>a(i=>i+1);return e.on("selectionUpdate",s),e.on("transaction",s),()=>{e.off("selectionUpdate",s),e.off("transaction",s)}},[e]);const o=e.isActive("table"),n=h.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 o?v.jsxs(Nt,{placement:"bottom",isOpen:t,onOpenChange:r,children:[v.jsx(At,{children:v.jsx(Qe,{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:v.jsx(Gt,{content:"Table controls",delay:250,closeDelay:0,children:v.jsx("div",{className:"w-full h-full flex items-center justify-center",children:v.jsx(Pe,{name:"Table2"})})})})}),v.jsx(_t,{className:"p-1.5",children:v.jsxs("div",{className:"flex flex-col gap-1",children:[n.map((s,i)=>v.jsxs(h.Fragment,{children:[v.jsx("div",{className:"grid grid-cols-2 gap-1",children:s.actions.map(l=>v.jsx(Qe,{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?v.jsx(Be,{className:"my-0.5"}):null]},s.key)),v.jsx(Qe,{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},ac=h.memo(e0),t0=({editor:e,prepend:t,append:r})=>{const[a,o]=h.useState(!1),[n,s]=h.useState(!1),[i,l]=h.useState(()=>e.isActive("table")),d=h.useRef(null),c=h.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=h.useCallback(()=>Xd(e)&&Tv(e)&&!zv(e),[e]),p=h.useCallback(()=>{d.current&&clearTimeout(d.current),o(!0),setTimeout(()=>s(!0),10)},[]),f=h.useCallback(()=>{s(!1),d.current=setTimeout(()=>o(!1),200)},[]);return h.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]),h.useEffect(()=>()=>{d.current&&clearTimeout(d.current)},[]),v.jsx(Gd,{editor:e,updateDelay:200,options:{offset:3,onShow:p,onHide:f},shouldShow:u,children:v.jsxs("div",{className:`bubble-menu transition-all duration-200 ease-in-out
|
|
43
43
|
${a&&n?"opacity-100":"opacity-0"}`,children:[t&&v.jsxs("div",{className:"flex items-center gap-1",children:[t,v.jsx(Be,{orientation:"vertical",className:"h-6"})]}),c.map(g=>v.jsx("div",{className:"flex items-center gap-0.5",children:v.jsx(Zt,{isIconOnly:!0,withActive:!0,editor:e,buttonKey:g.buttonKey,tooltipText:g.tooltipText,icon:g.icon,onPressed:g.command})},g.buttonKey)),v.jsx(Be,{orientation:"vertical",className:"h-6"}),v.jsx(Gv,{editor:e}),v.jsx(Jv,{editor:e}),v.jsx(Be,{orientation:"vertical",className:"h-6"}),i&&v.jsxs(v.Fragment,{children:[v.jsx(ac,{editor:e}),v.jsx(Be,{orientation:"vertical",className:"h-6"})]}),r&&v.jsxs("div",{className:"flex items-center gap-1",children:[r,v.jsx(Be,{orientation:"vertical",className:"h-6"})]}),v.jsx(Qv,{editor:e})]})})},r0=h.memo(t0),a0=({editor:e,prepend:t,append:r})=>{const a=h.useCallback(()=>e.isActive("table")&&(Mv(e)||!Xd(e)),[e]);return v.jsx(Gd,{editor:e,updateDelay:200,options:{offset:3},shouldShow:a,children:v.jsxs("div",{className:"bubble-menu",children:[t&&v.jsxs(v.Fragment,{children:[v.jsx("div",{className:"flex items-center gap-1",children:t}),v.jsx(Be,{orientation:"vertical",className:"h-6"})]}),v.jsx(ac,{editor:e}),r&&v.jsxs(v.Fragment,{children:[v.jsx(Be,{orientation:"vertical",className:"h-6"}),v.jsx("div",{className:"flex items-center gap-1",children:r})]})]})})},o0=h.memo(a0),n0=({editor:e,onCloseMenu:t})=>{const r=(a,o)=>{switch(a){case"text":e.chain().focus().setColor(o).run();break;case"highlight":e.chain().focus().setHighlight({color:o}).run();break;default:return}t()};return v.jsx(vd,{label:"Color list",variant:"flat",classNames:{list:"p-0",base:"p-0"},children:Bo.map((a,o)=>v.jsx(Qg,{title:a.title,showDivider:o!==Bo.length-1,children:a.colors.map(n=>v.jsx(hd,{startContent:v.jsx(tc,{buttonType:a.buttonType,color:n.color,bgColor:n.bgColor}),className:"text-foreground-500 hover:text-foreground outline-none",onPress:()=>r(a.key,n.hsl),children:n.tooltipText},`${a.key}_${n.color}`))},a.key))})},s0=()=>v.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:v.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"})}),i0=["imageUploader"],l0=rc.flatMap(e=>e.commands).filter(e=>!i0.includes(e.key)),d0=({editor:e})=>{const[t,r]=h.useState(-1),[a,o]=h.useState(!1),[n,s]=h.useState(!1),[i,l]=h.useState(!1),d=h.useMemo(()=>Iv(e.state)?["duplicate_node"]:[],[e.state]),c=h.useCallback(({pos:f})=>{r(f)},[]),u=h.useCallback(()=>{o(!a);const{state:f,view:g}=e,m=window.getSelection();m&&!m.isCollapsed&&m.removeAllRanges();const b=f.tr.setSelection(X.NodeSelection.create(f.doc,t));g.dispatch(b)},[a,e,t]),p=h.useCallback((f,g)=>{const m=f.state.doc.resolve(g),b=m.nodeAfter||m.parent,x=g+b.nodeSize;f.chain().focus(x,{scrollIntoView:!0}).insertContentAt(x,{type:"paragraph",content:[{type:"text",text:"/"}]}).setTextSelection(x+2).run()},[]);return v.jsx(mc,{editor:e,computePositionConfig:{placement:"left"},onNodeChange:c,children:v.jsxs("div",{className:"flex items-center pr-3",children:[v.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:()=>p(e,t),children:v.jsx(Pe,{name:"Plus"})}),v.jsxs(Ag,{placement:"right",isOpen:a,onOpenChange:o,children:[v.jsx(Sg,{children:v.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:v.jsx(Pe,{name:"GripVertical"})})}),v.jsxs(Eg,{variant:"flat",closeOnSelect:!1,disabledKeys:d,classNames:{base:"w-[225px]"},children:[v.jsxs(xl,{showDivider:!!Jd(e),children:[Jd(e)?v.jsx(qt,{isReadOnly:!0,textValue:"color",className:"text-foreground-500 hover:text-foreground outline-none p-0 h-8 flex justify-center",children:v.jsxs(Nt,{placement:"right",isOpen:n,shouldCloseOnBlur:!1,triggerScaleOnOpen:!1,onOpenChange:f=>s(f),children:[v.jsx(At,{children:v.jsxs("div",{className:"w-full h-8 px-2 py-1.5 flex items-center justify-between",onClick:()=>{l(!1),s(!0)},children:[v.jsxs("div",{className:"flex items-center gap-2",children:[v.jsx(Pe,{name:"PaintBucket"}),v.jsx("p",{children:"Color"})]}),v.jsx(Pe,{name:"ChevronRight"})]})}),v.jsx(_t,{children:v.jsx(n0,{editor:e,onCloseMenu:()=>{s(!1),setTimeout(()=>{o(!1)},100)}})})]})},"color"):null,_v(e)?v.jsx(qt,{isReadOnly:!0,textValue:"turn_into",className:"text-foreground-500 hover:text-foreground outline-none p-0 h-8 flex justify-center",children:v.jsxs(Nt,{placement:"right",shouldCloseOnBlur:!1,triggerScaleOnOpen:!1,isOpen:i,onOpenChange:f=>l(f),children:[v.jsx(At,{children:v.jsxs("div",{className:"w-full h-8 px-2 py-1.5 flex items-center justify-between",onClick:()=>{s(!1),l(!i)},children:[v.jsxs("div",{className:"flex items-center gap-2",children:[v.jsx(s0,{}),v.jsx("p",{children:"Transform into"})]}),v.jsx(Pe,{name:"ChevronRight"})]})}),v.jsx(_t,{children:v.jsx(vd,{label:"Turn into list",variant:"flat",classNames:{list:"p-0",base:"p-0"},children:l0.map(f=>v.jsx(hd,{startContent:v.jsx(Pe,{name:f.icon}),className:"text-foreground-500 hover:text-foreground outline-none",onPress:()=>{Bv(e,f),l(!1),setTimeout(()=>{o(!1)},100)},children:f.title},f.key))})})]})},"turn_into"):null,Av(e)?v.jsx(qt,{textValue:"reset_formatting",className:"text-foreground-500 hover:text-foreground outline-none p-0 h-8 flex justify-center",onPress:()=>Lv(e),children:v.jsx("div",{className:"w-full h-8 px-2 py-1.5 flex items-center justify-between",children:v.jsxs("div",{className:"flex items-center gap-2",children:[v.jsx(Pe,{name:"RotateCcw"}),v.jsx("p",{children:"Reset formatting"})]})})},"reset_formatting"):null]}),v.jsxs(xl,{showDivider:!0,children:[v.jsx(qt,{textValue:"duplicate_node",className:"text-foreground-500 hover:text-foreground outline-none p-0 h-8 flex justify-center",onPress:()=>Dv(e),children:v.jsxs("div",{className:"w-full h-8 px-2 py-1.5 flex items-center justify-between",children:[v.jsxs("div",{className:"flex items-center gap-2",children:[v.jsx(Pe,{name:"Copy"}),v.jsx("p",{children:"Duplicate block"})]}),v.jsx(Po,{keys:["command"],children:"D"})]})},"duplicate_node"),Nv(e)?v.jsx(qt,{closeOnSelect:!0,textValue:"copy_to_clipboard",className:"text-foreground-500 hover:text-foreground outline-none p-0 h-8 flex justify-center",onPress:()=>jv(e),children:v.jsxs("div",{className:"w-full h-8 px-2 py-1.5 flex items-center justify-between",children:[v.jsxs("div",{className:"flex items-center gap-2",children:[v.jsx(Pe,{name:"Clipboard"}),v.jsx("p",{children:"Copy to clipboard"})]}),v.jsx(Po,{keys:["command"],children:"C"})]})},"copy_to_clipboard"):null]}),v.jsx(qt,{textValue:"delete",className:"text-foreground-500 hover:text-foreground outline-none p-0 h-8 flex justify-center",onPress:()=>Ov(e),children:v.jsxs("div",{className:"w-full h-8 px-2 py-1.5 flex items-center justify-between",children:[v.jsxs("div",{className:"flex items-center gap-2",children:[v.jsx(Pe,{name:"Trash"}),v.jsx("p",{children:"Delete"})]}),v.jsx(Po,{children:"Del"})]})},"delete")]})]})]})})},Fo=h.createContext(null),c0=()=>h.useContext(Fo);var u0=yr.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 a=e.getAttribute("colwidth"),o=a?a.split(",").map(n=>parseInt(n,10)):null;if(!o){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 o}}}},tableRole:"cell",isolating:!0,parseHTML(){return[{tag:"td"}]},renderHTML({HTMLAttributes:e}){return["td",Jt(this.options.HTMLAttributes,e),0]}}),f0=yr.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(a=>parseInt(a,10)):null}}}},tableRole:"header_cell",isolating:!0,parseHTML(){return[{tag:"th"}]},renderHTML({HTMLAttributes:e}){return["th",Jt(this.options.HTMLAttributes,e),0]}}),p0=yr.create({name:"tableRow",addOptions(){return{HTMLAttributes:{}}},content:"(tableCell | tableHeader)*",tableRole:"row",parseHTML(){return[{tag:"tr"}]},renderHTML({HTMLAttributes:e}){return["tr",Jt(this.options.HTMLAttributes,e),0]}});function Ko(e,t){return t?["width",`${Math.max(t,e)}px`]:["min-width",`${e}px`]}function oc(e,t,r,a,o,n){var s;let i=0,l=!0,d=t.firstChild;const c=e.firstChild;if(c!==null)for(let p=0,f=0;p<c.childCount;p+=1){const{colspan:g,colwidth:m}=c.child(p).attrs;for(let b=0;b<g;b+=1,f+=1){const x=o===f?n:m&&m[b],k=x?`${x}px`:"";if(i+=x||a,x||(l=!1),d){if(d.style.width!==k){const[C,E]=Ko(a,x);d.style.setProperty(C,E)}d=d.nextSibling}else{const C=document.createElement("col"),[E,P]=Ko(a,x);C.style.setProperty(E,P),t.appendChild(C)}}}for(;d;){const p=d.nextSibling;(s=d.parentNode)==null||s.removeChild(d),d=p}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 h0=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")),oc(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,oc(e,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(e){const t=e.target,r=this.dom.contains(t),a=this.contentDOM.contains(t);return!!(r&&!a&&(e.type==="attributes"||e.type==="childList"||e.type==="characterData"))}};function g0(e,t,r,a){let o=0,n=!0;const s=[],i=e.firstChild;if(!i)return{};for(let u=0,p=0;u<i.childCount;u+=1){const{colspan:f,colwidth:g}=i.child(u).attrs;for(let m=0;m<f;m+=1,p+=1){const b=r===p?a:g&&g[m];o+=b||t,b||(n=!1);const[x,k]=Ko(t,b);s.push(["col",{style:`${x}: ${k}`}])}}const l=n?`${o}px`:"",d=n?"":`${o}px`;return{colgroup:["colgroup",{},...s],tableWidth:l,tableMinWidth:d}}function nc(e,t){return e.createAndFill()}function b0(e){if(e.cached.tableNodeTypes)return e.cached.tableNodeTypes;const t={};return Object.keys(e.nodes).forEach(r=>{const a=e.nodes[r];a.spec.tableRole&&(t[a.spec.tableRole]=a)}),e.cached.tableNodeTypes=t,t}function m0(e,t,r,a,o){const n=b0(e),s=[],i=[];for(let d=0;d<r;d+=1){const c=nc(n.cell);if(c&&i.push(c),a){const u=nc(n.header_cell);u&&s.push(u)}}const l=[];for(let d=0;d<t;d+=1)l.push(n.row.createChecked(null,a&&d===0?s:i));return n.table.createChecked(null,l)}function v0(e){return e instanceof ge.CellSelection}var ma=({editor:e})=>{const{selection:t}=e.state;if(!v0(t))return!1;let r=0;const a=Md(t.ranges[0].$from,n=>n.type.name==="table");return a?.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},w0="";function x0(e){return(e||"").replace(/\s+/g," ").trim()}function y0(e,t,r={}){var a;const o=(a=r.cellLineSeparator)!=null?a:w0;if(!e||!e.content||e.content.length===0)return"";const n=[];e.content.forEach(g=>{const m=[];g.content&&g.content.forEach(b=>{let x="";b.content&&Array.isArray(b.content)&&b.content.length>1?x=b.content.map(P=>t.renderChildren(P)).join(o):x=b.content?t.renderChildren(b.content):"";const k=x0(x),C=b.type==="tableHeader";m.push({text:k,isHeader:C})}),n.push(m)});const s=n.reduce((g,m)=>Math.max(g,m.length),0);if(s===0)return"";const i=new Array(s).fill(0);n.forEach(g=>{var m;for(let b=0;b<s;b+=1){const k=(((m=g[b])==null?void 0:m.text)||"").length;k>i[b]&&(i[b]=k),i[b]<3&&(i[b]=3)}});const l=(g,m)=>g+" ".repeat(Math.max(0,m-g.length)),d=n[0],c=d.some(g=>g.isHeader);let u=`
|
|
44
44
|
`;const p=new Array(s).fill(0).map((g,m)=>c&&d[m]&&d[m].text||"");return u+=`| ${p.map((g,m)=>l(g,i[m])).join(" | ")} |
|
|
45
45
|
`,u+=`| ${i.map(g=>"-".repeat(Math.max(3,g))).join(" | ")} |
|