UNPKG

reactjs-tiptap-editor

Version:

A modern WYSIWYG rich text editor based on tiptap and shadcn ui for React

2 lines 170 kB
"use strict";var co=Object.create;var hi=Object.defineProperty;var ao=Object.getOwnPropertyDescriptor;var ho=Object.getOwnPropertyNames;var uo=Object.getPrototypeOf,fo=Object.prototype.hasOwnProperty;var go=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ho(t))!fo.call(e,s)&&s!==n&&hi(e,s,{get:()=>t[s],enumerable:!(i=ao(t,s))||i.enumerable});return e};var po=(e,t,n)=>(n=e!=null?co(uo(e)):{},go(t||!e||!e.__esModule?hi(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react/jsx-runtime"),w=require("react"),E=require("./clsx-CXbNJWDD.cjs"),F=require("./index-Cs6cp0Y6.cjs"),Y=require("@tiptap/pm/state"),Ki=require("./Table-BmDopO43.cjs"),Wi=require("react-dom"),p=require("./index-BnVcq33n.cjs"),te=require("./select-CYyIeImH.cjs"),Ce=require("./Callout.cjs"),ot=require("./Katex-ClqcEnN_.cjs"),L=require("./index-BsFvo9PG.cjs"),Jt=require("./delete-node-CosiBes5.cjs"),di=require("./Column.cjs");require("./theme.cjs");const Ae=require("./Drawer-FUeUKshi.cjs"),ui=require("easydrawer"),Le=require("./shortId-Bfj8TyNr.cjs"),kt=require("./separator-BLp6xpSY.cjs"),Ft=require("./popover-DIMT3pae.cjs"),ee=require("./Excalidraw.cjs"),Vt=require("./Iframe-EVWXCqe4.cjs"),mo=require("katex"),Ue=require("lucide-react"),Cn=require("./textarea-Cn75Cm2n.cjs"),De=require("./LinkEditBlock-DZXk4ln_.cjs"),xo=require("./ImageGif.cjs"),kn=require("./Mermaid.cjs"),wo=require("./Bold.cjs"),bo=require("./Code.cjs");require("./index-CjhjjJsN.cjs");const yo=require("./Color.cjs"),So=require("./Highlight.cjs"),Co=require("./Italic.cjs"),ko=require("./SlashCommandNodeView-CZoM3ZlS.cjs"),vo=require("./Strike.cjs"),Yi=require("./TextAlign.cjs"),_o=require("./TextUnderline.cjs"),an=require("./Twitter-BbMD3Ybp.cjs"),hn=require("@tiptap/pm/view"),Eo=require("@tiptap/pm/model"),Io=require("./Clear.cjs"),ne=require("./Indent-q9cEWAa_.cjs"),U=require("./dropdown-menu-C_F7LEy5.cjs");function To(e,t){const n=Math.min(e.top,t.top),i=Math.max(e.bottom,t.bottom),s=Math.min(e.left,t.left),r=Math.max(e.right,t.right)-s,l=i-n,c=s,a=n;return new DOMRect(c,a,r,l)}var Ao=class{constructor({editor:e,element:t,view:n,updateDelay:i=250,resizeDelay:s=60,shouldShow:o,appendTo:r,getReferencedVirtualElement:l,options:c}){this.preventHide=!1,this.isVisible=!1,this.scrollTarget=window,this.floatingUIOptions={strategy:"absolute",placement:"top",offset:8,flip:{},shift:{},arrow:!1,size:!1,autoPlacement:!1,hide:!1,inline:!1,onShow:void 0,onHide:void 0,onUpdate:void 0,onDestroy:void 0},this.shouldShow=({view:h,state:d,from:f,to:g})=>{const{doc:m,selection:x}=d,{empty:b}=x,y=!m.textBetween(f,g).length&&E.isTextSelection(d.selection),I=this.element.contains(document.activeElement);return!(!(h.hasFocus()||I)||b||y||!this.editor.isEditable)},this.mousedownHandler=()=>{this.preventHide=!0},this.dragstartHandler=()=>{this.hide()},this.resizeHandler=()=>{this.resizeDebounceTimer&&clearTimeout(this.resizeDebounceTimer),this.resizeDebounceTimer=window.setTimeout(()=>{this.updatePosition()},this.resizeDelay)},this.focusHandler=()=>{setTimeout(()=>this.update(this.editor.view))},this.blurHandler=({event:h})=>{var d;if(this.editor.isDestroyed){this.destroy();return}if(this.preventHide){this.preventHide=!1;return}h!=null&&h.relatedTarget&&((d=this.element.parentNode)!=null&&d.contains(h.relatedTarget))||(h==null?void 0:h.relatedTarget)!==this.editor.view.dom&&this.hide()},this.handleDebouncedUpdate=(h,d)=>{const f=!(d!=null&&d.selection.eq(h.state.selection)),g=!(d!=null&&d.doc.eq(h.state.doc));!f&&!g||(this.updateDebounceTimer&&clearTimeout(this.updateDebounceTimer),this.updateDebounceTimer=window.setTimeout(()=>{this.updateHandler(h,f,g,d)},this.updateDelay))},this.updateHandler=(h,d,f,g)=>{const{composing:m}=h;if(m||!d&&!f)return;if(!this.getShouldShow(g)){this.hide();return}this.updatePosition(),this.show()},this.transactionHandler=({transaction:h})=>{h.getMeta("bubbleMenu")==="updatePosition"&&this.updatePosition()};var a;this.editor=e,this.element=t,this.view=n,this.updateDelay=i,this.resizeDelay=s,this.appendTo=r,this.scrollTarget=(a=c==null?void 0:c.scrollTarget)!=null?a:window,this.getReferencedVirtualElement=l,this.floatingUIOptions={...this.floatingUIOptions,...c},this.element.tabIndex=0,o&&(this.shouldShow=o),this.element.addEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.view.dom.addEventListener("dragstart",this.dragstartHandler),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(n,n.state),this.getShouldShow()&&(this.show(),this.updatePosition())}get middlewares(){const e=[];return this.floatingUIOptions.flip&&e.push(F.flip(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&e.push(F.shift(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&e.push(F.offset(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&e.push(F.arrow(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&e.push(F.size(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&e.push(F.autoPlacement(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&e.push(F.hide(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&e.push(F.inline(typeof this.floatingUIOptions.inline!="boolean"?this.floatingUIOptions.inline:void 0)),e}get virtualElement(){var e;const{selection:t}=this.editor.state,n=(e=this.getReferencedVirtualElement)==null?void 0:e.call(this);if(n)return n;const i=E.posToDOMRect(this.view,t.from,t.to);let s={getBoundingClientRect:()=>i,getClientRects:()=>[i]};if(t instanceof Y.NodeSelection){let o=this.view.nodeDOM(t.from);const r=o.dataset.nodeViewWrapper?o:o.querySelector("[data-node-view-wrapper]");r&&(o=r),o&&(s={getBoundingClientRect:()=>o.getBoundingClientRect(),getClientRects:()=>[o.getBoundingClientRect()]})}if(t instanceof Ki.CellSelection){const{$anchorCell:o,$headCell:r}=t,l=o?o.pos:r.pos,c=r?r.pos:o.pos,a=this.view.nodeDOM(l),h=this.view.nodeDOM(c);if(!a||!h)return;const d=a===h?a.getBoundingClientRect():To(a.getBoundingClientRect(),h.getBoundingClientRect());s={getBoundingClientRect:()=>d,getClientRects:()=>[d]}}return s}updatePosition(){const e=this.virtualElement;e&&F.computePosition(e,this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:t,y:n,strategy:i})=>{this.element.style.width="max-content",this.element.style.position=i,this.element.style.left=`${t}px`,this.element.style.top=`${n}px`,this.isVisible&&this.floatingUIOptions.onUpdate&&this.floatingUIOptions.onUpdate()})}update(e,t){const{state:n}=e,i=n.selection.from!==n.selection.to;if(this.updateDelay>0&&i){this.handleDebouncedUpdate(e,t);return}const s=!(t!=null&&t.selection.eq(e.state.selection)),o=!(t!=null&&t.doc.eq(e.state.doc));this.updateHandler(e,s,o,t)}getShouldShow(e){var t;const{state:n}=this.view,{selection:i}=n,{ranges:s}=i,o=Math.min(...s.map(c=>c.$from.pos)),r=Math.max(...s.map(c=>c.$to.pos));return((t=this.shouldShow)==null?void 0:t.call(this,{editor:this.editor,element:this.element,view:this.view,state:n,oldState:e,from:o,to:r}))||!1}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}),this.view.dom.removeEventListener("dragstart",this.dragstartHandler),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()}},Gi=e=>new Y.Plugin({key:typeof e.pluginKey=="string"?new Y.PluginKey(e.pluginKey):e.pluginKey,view:t=>new Ao({view:t,...e})});E.Extension.create({name:"bubbleMenu",addOptions(){return{element:null,pluginKey:"bubbleMenu",updateDelay:void 0,appendTo:void 0,shouldShow:null}},addProseMirrorPlugins(){return this.options.element?[Gi({pluginKey:this.options.pluginKey,editor:this.editor,element:this.options.element,updateDelay:this.options.updateDelay,options:this.options.options,appendTo:this.options.appendTo,getReferencedVirtualElement:this.options.getReferencedVirtualElement,shouldShow:this.options.shouldShow})]:[]}});var Do=class{constructor({editor:e,element:t,view:n,options:i,appendTo:s,shouldShow:o}){this.preventHide=!1,this.isVisible=!1,this.shouldShow=({view:r,state:l})=>{const{selection:c}=l,{$anchor:a,empty:h}=c,d=a.depth===1,f=a.parent.isTextblock&&!a.parent.type.spec.code&&!a.parent.textContent&&a.parent.childCount===0&&!this.getTextContent(a.parent);return!(!r.hasFocus()||!h||!d||!f||!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=(r,l,c,a)=>{const{composing:h}=r;if(h||!l&&!c)return;if(!this.getShouldShow(a)){this.hide();return}this.updatePosition(),this.show()},this.mousedownHandler=()=>{this.preventHide=!0},this.focusHandler=()=>{setTimeout(()=>this.update(this.editor.view))},this.blurHandler=({event:r})=>{var l;if(this.preventHide){this.preventHide=!1;return}r!=null&&r.relatedTarget&&((l=this.element.parentNode)!=null&&l.contains(r.relatedTarget))||(r==null?void 0:r.relatedTarget)!==this.editor.view.dom&&this.hide()},this.editor=e,this.element=t,this.view=n,this.appendTo=s,this.floatingUIOptions={...this.floatingUIOptions,...i},this.element.tabIndex=0,o&&(this.shouldShow=o),this.element.addEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.editor.on("focus",this.focusHandler),this.editor.on("blur",this.blurHandler),this.update(n,n.state),this.getShouldShow()&&(this.show(),this.updatePosition())}getTextContent(e){return E.getText(e,{textSerializers:E.getTextSerializersFromSchema(this.editor.schema)})}get middlewares(){const e=[];return this.floatingUIOptions.flip&&e.push(F.flip(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&e.push(F.shift(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&e.push(F.offset(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&e.push(F.arrow(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&e.push(F.size(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&e.push(F.autoPlacement(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&e.push(F.hide(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&e.push(F.inline(typeof this.floatingUIOptions.inline!="boolean"?this.floatingUIOptions.inline:void 0)),e}getShouldShow(e){var t;const{state:n}=this.view,{selection:i}=n,{ranges:s}=i,o=Math.min(...s.map(c=>c.$from.pos)),r=Math.max(...s.map(c=>c.$to.pos));return(t=this.shouldShow)==null?void 0:t.call(this,{editor:this.editor,view:this.view,state:n,oldState:e,from:o,to:r})}updatePosition(){const{selection:e}=this.editor.state,t=E.posToDOMRect(this.view,e.from,e.to),n={getBoundingClientRect:()=>t,getClientRects:()=>[t]};F.computePosition(n,this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:i,y:s,strategy:o})=>{this.element.style.width="max-content",this.element.style.position=o,this.element.style.left=`${i}px`,this.element.style.top=`${s}px`,this.isVisible&&this.floatingUIOptions.onUpdate&&this.floatingUIOptions.onUpdate()})}update(e,t){const n=!(t!=null&&t.selection.eq(e.state.selection)),i=!(t!=null&&t.doc.eq(e.state.doc));this.updateHandler(e,n,i,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}),this.editor.off("focus",this.focusHandler),this.editor.off("blur",this.blurHandler),this.floatingUIOptions.onDestroy&&this.floatingUIOptions.onDestroy()}},Ji=e=>new Y.Plugin({key:typeof e.pluginKey=="string"?new Y.PluginKey(e.pluginKey):e.pluginKey,view:t=>new Do({view:t,...e})});E.Extension.create({name:"floatingMenu",addOptions(){return{element:null,options:{},pluginKey:"floatingMenu",appendTo:void 0,shouldShow:null}},addProseMirrorPlugins(){return this.options.element?[Ji({pluginKey:this.options.pluginKey,editor:this.editor,element:this.options.element,options:this.options.options,appendTo:this.options.appendTo,shouldShow:this.options.shouldShow})]:[]}});var Z=w.forwardRef(({pluginKey:e="bubbleMenu",editor:t,updateDelay:n,resizeDelay:i,appendTo:s,shouldShow:o=null,getReferencedVirtualElement:r,options:l,children:c,...a},h)=>{const d=w.useRef(document.createElement("div"));typeof h=="function"?h(d.current):h&&(h.current=d.current);const{editor:f}=E.useCurrentEditor(),g=t||f,m={updateDelay:n,resizeDelay:i,appendTo:s,pluginKey:e,shouldShow:o,getReferencedVirtualElement:r,options:l},x=w.useRef(m);return x.current=m,w.useEffect(()=>{if(g!=null&&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 b=d.current;b.style.visibility="hidden",b.style.position="absolute";const y=Gi({...x.current,editor:g,element:b});g.registerPlugin(y);const I=x.current.pluginKey;return()=>{g.unregisterPlugin(I),window.requestAnimationFrame(()=>{b.parentNode&&b.parentNode.removeChild(b)})}},[g]),Wi.createPortal(u.jsx("div",{...a,children:c}),d.current)});w.forwardRef(({pluginKey:e="floatingMenu",editor:t,appendTo:n,shouldShow:i=null,options:s,children:o,...r},l)=>{const c=w.useRef(document.createElement("div"));typeof l=="function"?l(c.current):l&&(l.current=c.current);const{editor:a}=E.useCurrentEditor();return w.useEffect(()=>{const h=c.current;if(h.style.visibility="hidden",h.style.position="absolute",t!=null&&t.isDestroyed||a!=null&&a.isDestroyed)return;const d=t||a;if(!d){console.warn("FloatingMenu component is not rendered inside of an editor component or does not have editor prop.");return}const f=Ji({editor:d,element:h,pluginKey:e,appendTo:n,shouldShow:i,options:s});return d.registerPlugin(f),()=>{d.unregisterPlugin(e),window.requestAnimationFrame(()=>{h.parentNode&&h.parentNode.removeChild(h)})}},[t,a,n,e,i,s]),Wi.createPortal(u.jsx("div",{...r,children:o}),c.current)});const Mo=[{value:"note",label:"Note",icon:"Info"},{value:"tip",label:"Tip",icon:"Lightbulb"},{value:"important",label:"Important",icon:"AlertCircle"},{value:"warning",label:"Warning",icon:"TriangleAlert"},{value:"caution",label:"Caution",icon:"OctagonAlert"}];function jo(){const e=p.useEditableEditor(),t=p.useEditorInstance(),{t:n}=L.useLocale(),{type:i,title:s,body:o}=ot.useAttributes(t,Ce.Callout.name,{type:"note",title:"",body:""}),[r,l]=w.useState(!1),[c,a]=w.useState("note"),[h,d]=w.useState(""),[f,g]=w.useState("");w.useEffect(()=>{r&&(a(i||"note"),d(s||""),g(o||""))},[r,i,s,o]);const m=w.useCallback(()=>{t&&(t.chain().updateAttributes(Ce.Callout.name,{type:c,title:h,body:f}).focus().run(),l(!1))},[t,c,h,f]),x=w.useCallback(()=>{l(!1)},[]),b=w.useCallback(()=>{Jt.deleteNode(Ce.Callout.name,t)},[t]),y=w.useCallback(()=>t.isActive(Ce.Callout.name),[t]);return e?u.jsx(Z,{editor:t,options:{placement:"top",offset:8,flip:!0},pluginKey:"RichTextBubbleCallout",shouldShow:y,children:u.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[u.jsxs(p.Dialog,{onOpenChange:l,open:r,children:[u.jsx(p.DialogTrigger,{asChild:!0,children:u.jsx(p.ActionButton,{icon:"Pencil",tooltip:n("editor.callout.edit.title")})}),u.jsxs(p.DialogContent,{children:[u.jsx(p.DialogTitle,{children:n("editor.callout.edit.title")}),u.jsxs("div",{className:"richtext-space-y-4 richtext-py-4",children:[u.jsxs("div",{className:"richtext-space-y-2",children:[u.jsx(p.Label,{children:n("editor.callout.dialog.type")}),u.jsxs(te.Select,{onValueChange:a,value:c,children:[u.jsx(te.SelectTrigger,{children:u.jsx(te.SelectValue,{className:"richtext-text-accent",placeholder:n("editor.callout.dialog.type.placeholder")})}),u.jsx(te.SelectContent,{children:Mo.map(I=>u.jsx(te.SelectItem,{value:I.value,children:n(`editor.callout.type.${I.value}`)},I.value))})]})]}),u.jsxs("div",{className:"richtext-space-y-2",children:[u.jsx(p.Label,{children:n("editor.callout.dialog.title.label")}),u.jsx(p.Input,{onChange:I=>d(I.target.value),placeholder:n("editor.callout.dialog.title.placeholder"),type:"text",value:h})]}),u.jsxs("div",{className:"richtext-space-y-2",children:[u.jsx(p.Label,{children:n("editor.callout.dialog.body.label")}),u.jsx(p.Input,{onChange:I=>g(I.target.value),placeholder:n("editor.callout.dialog.body.placeholder"),type:"text",value:f})]})]}),u.jsxs(p.DialogFooter,{children:[u.jsx(p.Button,{onClick:x,variant:"outline",children:n("editor.callout.dialog.button.cancel")}),u.jsx(p.Button,{onClick:m,children:n("editor.callout.dialog.button.apply")})]})]})]}),u.jsx(p.ActionButton,{action:b,icon:"Trash2",tooltip:n("editor.delete")})]})}):u.jsx(u.Fragment,{})}function Oo(){const e=p.useEditableEditor(),t=p.useEditorInstance(),{t:n}=L.useLocale(),i=w.useCallback(()=>t.isActive(di.MultipleColumnNode.name),[t]),s=w.useCallback(()=>Jt.deleteNode(di.MultipleColumnNode.name,t),[t]),o=w.useCallback(()=>t.chain().focus().addColBefore().run(),[t]),r=w.useCallback(()=>t.chain().focus().addColAfter().run(),[t]),l=w.useCallback(()=>t.chain().focus().deleteCol().run(),[t]);return e?u.jsx(Z,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleColumns",shouldShow:i,children:u.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[u.jsx(p.ActionButton,{action:o,icon:"ColumnAddLeft",tooltip:n("editor.table.menu.insertColumnBefore")}),u.jsx(p.ActionButton,{action:r,icon:"ColumnAddRight",tooltip:n("editor.table.menu.insertColumnAfter")}),u.jsx(p.ActionButton,{action:l,icon:"DeleteColumn",tooltip:n("editor.table.menu.deleteColumn")}),u.jsx(p.ActionButton,{action:s,icon:"Trash2",tooltip:n("editor.table.menu.delete_column")})]})}):u.jsx(u.Fragment,{})}function Ro(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,o)=>({type:`image-${s}`,component:p.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[o],action:()=>e.commands.updateImage({width:L.IMAGE_SIZE[s]}),isActive:()=>e.isActive("image",{width:L.IMAGE_SIZE[s]})}}))}function No(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,o)=>({type:`image-${s}`,component:p.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[o],action:()=>e.commands.updateImageGif({width:L.IMAGE_SIZE[s]}),isActive:()=>e.isActive("image",{width:L.IMAGE_SIZE[s]})}}))}function Bo(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:p.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var o,r;return(r=(o=e.commands)==null?void 0:o.setAlignImage)==null?void 0:r.call(o,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function Lo(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:p.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var o,r;return(r=(o=e.commands)==null?void 0:o.setAlignImageGif)==null?void 0:r.call(o,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function Uo(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:p.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var o,r;return(r=(o=e.commands)==null?void 0:o.setAlignImageMermaid)==null?void 0:r.call(o,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function Po(e,t){const n=["left","center","right"],i={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return n.map(s=>({type:`image-${s}`,component:p.ActionButton,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:i[s],action:()=>{var o,r;return(r=(o=e.commands)==null?void 0:o.setAlignImageDrawer)==null?void 0:r.call(o,s)},isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function Vo(e){return[{type:"flex-start",icon:"AlignLeft",tooltip:"Align left"},{type:"center",icon:"AlignCenter",tooltip:"Align center"},{type:"flex-end",icon:"AlignRight",tooltip:"Align right"}].map(n=>({type:`video-align-${n.type}`,component:p.ActionButton,componentProps:{tooltip:n.tooltip,icon:n.icon,action:()=>e.commands.updateVideo({align:n.type}),isActive:()=>e.getAttributes("video").align===n.type}}))}function Fo(e,t){const n=["size-small","size-medium","size-large"],i=["SizeS","SizeM","SizeL"];return n.map((s,o)=>({type:`video-${s}`,component:p.ActionButton,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:i[o],action:()=>e.commands.updateVideo({width:L.VIDEO_SIZE[s]}),isActive:()=>e.isActive("video",{width:L.VIDEO_SIZE[s]})}}))}function Ho(e,t){return[{type:"flipX",component:p.ActionButton,componentProps:{editor:e,tooltip:t("editor.tooltip.flipX"),icon:"FlipX",action:()=>{const n=e.getAttributes("image"),{flipX:i}=n;e.chain().focus(void 0,{scrollIntoView:!1}).updateImage({flipX:!i}).run()}}},{type:"flipY",component:p.ActionButton,componentProps:{editor:e,tooltip:t("editor.tooltip.flipY"),icon:"FlipY",action:()=>{const n=e.getAttributes("image"),{flipY:i}=n;e.chain().focus(void 0,{scrollIntoView:!1}).updateImage({flipY:!i}).run()}}},...Ro(e,t),...Bo(e,t),{type:"remove",component:p.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;E.deleteSelection(n,i)}}}]}function $o(e,t){return[...No(e,t),...Lo(e,t),{type:"remove",component:p.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;E.deleteSelection(n,i)}}}]}function zo(e,t){return[...Uo(e,t),{type:"edit",component:p.ActionButton,componentProps:{editor:e,tooltip:t("editor.edit"),icon:"Pencil",action:()=>!0}},{type:"remove",component:p.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;E.deleteSelection(n,i)}}}]}function qo(e,t){return[...Po(e,t),{type:"edit",component:p.ActionButton,componentProps:{editor:e,tooltip:t("editor.edit"),icon:"Pencil",action:()=>!0}},{type:"remove",component:p.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;E.deleteSelection(n,i)}}}]}function Ko(e,t){return[...Fo(e,t),...Vo(e),{type:"remove",component:p.ActionButton,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:n,dispatch:i}=e.view;E.deleteSelection(n,i)}}}]}let ie=!1;function Wo({editor:e,attrs:t,extension:n}){const[i,s]=w.useState(!1),o=w.useRef(null),r=w.useRef(null),{alt:l,align:c}=t,a=n==null?void 0:n.options.upload,h=()=>{(async()=>{const S=document.querySelector("#easydrawer");S&&(o.current=new ui.Editor(S,{wheelEventsEnabled:!1,disableZoom:!0}),r.current=ui.makeDropdownToolbar(o.current),r.current.addDefaultToolWidgets(),o.current.loadFromSVG(decodeURIComponent(l)))})()};w.useEffect(()=>{i&&setTimeout(()=>{h()},200)},[i]);const d=async()=>{if(o.current){const T=o.current.toSVG(),S=T.outerHTML,C=`drawer-${Le.shortId()}.svg`;let R=Le.i(T.outerHTML);if(a){const H=p.dataURLtoFile(R,C);R=await a(H)}e==null||e.chain().focus().setDrawer({type:"drawer",src:R,alt:encodeURIComponent(S),width:426,height:212},!!S).run(),e==null||e.commands.setAlignImageDrawer(c)}s(!1)},f=T=>{const S=o.current.toolController.getPrimaryTools()[2],C=r.current.getWidgetById("pen-1");S&&C&&(S.setColor(T),C.serializeState())},g=T=>{const S=o.current.toolController.getPrimaryTools()[2],C=r.current.getWidgetById("pen-1");S&&C&&(S.setThickness(T),C.serializeState())},m=T=>{const S=o.current.toolController.getPrimaryTools()[3],C=r.current.getWidgetById("pen-2");S&&C&&(S.setColor(T),C.serializeState())},x=T=>{const S=r.current.getWidgetById("shape");S&&S.setShapeType(T)},b=T=>{const S=o.current.toolController.getPrimaryTools()[5],C=r.current.getWidgetById("shape");S&&C&&(S.setColor(T),C.serializeState())},y=T=>{const S=o.current.toolController.getPrimaryTools()[5],C=r.current.getWidgetById("shape");S&&C&&(S.setThickness(T),C.serializeState())},I=T=>{const S=o.current.toolController.getPrimaryTools()[5],C=r.current.getWidgetById("shape");S&&C&&(S.setBorderColor(T),C.serializeState())},M=()=>{if(ie){for(;o.current.history.redoStackSize>0;)o.current.history.redo();ie=!1;return}o.current.history.undo()},k=()=>{ie||o.current.history.redo()},B=()=>{if(!ie){for(;o.current.history.undoStackSize>0;)M();ie=!0}};return u.jsxs(p.Dialog,{onOpenChange:s,open:i,children:[u.jsx(p.DialogTrigger,{asChild:!0,children:u.jsx(p.ActionButton,{action:()=>s(!0),icon:"Pencil",tooltip:"Edit Drawer"})}),u.jsxs(p.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[u.jsx(p.DialogTitle,{children:"Edit Drawer"}),u.jsxs("div",{style:{height:"100%",borderWidth:1,background:"white",position:"relative"},children:[u.jsx("div",{className:"richtext-size-full",id:"easydrawer"}),u.jsx(Ae.ControlDrawer,{changeBorderColorShape:I,changeColorShape:b,changeShape:x,onClear:B,onRedo:k,onThicknessChange:y,onUndo:M,refEditor:o,setColorHighlight:m,setColorPen:f,setThicknessPen:g})]}),u.jsx(p.DialogFooter,{children:u.jsx(p.Button,{onClick:d,type:"button",children:"Save changes"})})]})]})}function Yo({item:e,disabled:t,editor:n}){var s;const i=e.component;return i?u.jsx(w.Fragment,{children:e.type==="divider"?u.jsx(kt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):u.jsx(i,{...e.componentProps,disabled:t||((s=e==null?void 0:e.componentProps)==null?void 0:s.disabled),editor:n})}):u.jsx(u.Fragment,{})}function Go(){const{lang:e,t}=L.useLocale(),n=p.useEditableEditor(),i=p.useEditorInstance(),s=ot.useAttributes(i,Ae.Drawer.name),o=p.useExtension(Ae.Drawer.name),r=({editor:c})=>{const{selection:a}=c.view.state,{$from:h,to:d}=a;let f=!1;return c.view.state.doc.nodesBetween(h.pos,d,g=>{if(g.type.name===Ae.Drawer.name)return f=!0,!1}),f},l=w.useMemo(()=>qo(i,t),[i,e,t]);return n?u.jsx(Z,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleDrawer",shouldShow:r,children:l!=null&&l.length?u.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:l==null?void 0:l.map((c,a)=>c.type==="edit"&&(s!=null&&s.src)?u.jsx(Wo,{attrs:s,editor:i,extension:o},`bubbleMenu-drawer-${a}`):u.jsx(Yo,{editor:i,item:c},`bubbleMenu-drawer-${a}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}const Xi=({width:e,maxWidth:t,height:n,onOk:i,children:s})=>{const{t:o}=L.useLocale(),[r,l]=w.useState({width:"",height:"",maxWidth:""});w.useEffect(()=>{l({width:e,height:n,maxWidth:t})},[n,t,e]);function c(a){a.preventDefault(),a.stopPropagation(),i(r)}return u.jsxs(Ft.Popover,{modal:!0,children:[u.jsx(Ft.PopoverTrigger,{asChild:!0,children:s}),u.jsx(Ft.PopoverContent,{children:u.jsxs("form",{className:"richtext-flex richtext-flex-col richtext-gap-2",onSubmit:c,children:[u.jsx(p.Label,{className:"mb-[6px]",children:"Width"}),u.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:u.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:u.jsx(p.Input,{onChange:a=>l({...r,width:a.target.value}),required:!0,type:"number",value:r.width})})}),u.jsx(p.Label,{className:"mb-[6px]",children:"Max Width"}),u.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:u.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:u.jsx(p.Input,{onChange:a=>l({...r,maxWidth:a.target.value}),required:!0,type:"number",value:r.maxWidth})})}),u.jsx(p.Label,{className:"mb-[6px]",children:"Height"}),u.jsx("div",{className:"richtext-flex richtext-w-full richtext-max-w-sm richtext-items-center richtext-gap-1.5",children:u.jsx("div",{className:"richtext-relative richtext-w-full richtext-max-w-sm richtext-items-center",children:u.jsx(p.Input,{onChange:a=>l({...r,height:a.target.value}),required:!0,type:"number",value:r.height})})}),u.jsx(p.Button,{className:"richtext-mt-2 richtext-self-end",type:"submit",children:o("editor.link.dialog.button.apply")})]})})]})},Dt=new Map;function Jo(e){const t=e.options.element;Dt.has("width")||Dt.set("width",t.clientWidth),Dt.has("width")&&Dt.get("width")<=0&&Dt.set("width",t.clientWidth);const n={attributes:!0,childList:!0,subtree:!0},i=function(){Dt.set("width",t.clientWidth)},s=new MutationObserver(i);return s.observe(t,n),e.on("destroy",()=>{s.disconnect()}),{width:Dt.get("width")}}function Xo(){const e=p.useEditableEditor(),t=p.useEditorInstance(),{t:n}=L.useLocale(),{width:i}=Jo(t),s=ot.useAttributes(t,ee.Excalidraw.name,{defaultShowPicker:!1,createUser:"",width:0,height:0}),{defaultShowPicker:o,createUser:r,width:l,height:c}=s,a=w.useCallback(g=>{t.chain().updateAttributes(ee.Excalidraw.name,g).setNodeSelection(t.state.selection.from).focus().run()},[t]),h=w.useCallback(()=>{const g=p.EVENTS.EXCALIDRAW(t.id);p.emit(g,s)},[t,s]),d=w.useCallback(()=>t.isActive(ee.Excalidraw.name),[t]),f=w.useCallback(()=>Jt.deleteNode(ee.Excalidraw.name,t),[t]);return w.useEffect(()=>{o&&(h(),t.chain().updateAttributes(ee.Excalidraw.name,{defaultShowPicker:!1}).focus().run())},[r,o,t,h]),e?u.jsx(Z,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleExcalidraw",shouldShow:d,children:u.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[u.jsx(p.ActionButton,{action:h,icon:"Pencil",tooltip:n("editor.edit")}),u.jsx(Xi,{height:c,maxWidth:i,onOk:a,width:l,children:u.jsx(p.ActionButton,{icon:"Settings",tooltip:n("editor.settings")})}),u.jsx(p.ActionButton,{action:f,icon:"Trash2",tooltip:n("editor.delete")})]})}):u.jsx(u.Fragment,{})}function Zo(){const e=p.useEditableEditor(),t=p.useEditorInstance(),{t:n}=L.useLocale(),{width:i,height:s,src:o}=ot.useAttributes(t,Vt.Iframe.name,{width:0,height:0,src:"",defaultShowPicker:!1}),[r,l]=w.useState(!1),[c,a]=w.useState(""),h=w.useCallback(b=>{var y;(y=b==null?void 0:b.preventDefault)==null||y.call(b),l(!1)},[l]);w.useEffect(()=>{r&&a(o)},[r,o]);const d=w.useCallback(b=>{var I;(I=b==null?void 0:b.preventDefault)==null||I.call(b);const y=Vt.getServiceSrc(c);t.chain().updateAttributes(Vt.Iframe.name,{src:(y==null?void 0:y.src)||c}).setNodeSelection(t.state.selection.from).focus().run(),l(!1)},[t,c,l]),f=w.useCallback(()=>{window.open(o,"_blank")},[o]),g=w.useCallback(b=>{t.chain().updateAttributes(Vt.Iframe.name,b).setNodeSelection(t.state.selection.from).focus().run()},[t]),m=w.useCallback(()=>t.isActive(Vt.Iframe.name)&&!o,[t,o]),x=w.useCallback(()=>Jt.deleteNode(Vt.Iframe.name,t),[t]);return e?u.jsx(u.Fragment,{children:u.jsx(Z,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleIframe",shouldShow:m,children:u.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[u.jsx(p.ActionButton,{action:f,icon:"Eye",tooltip:"Visit Link"}),u.jsxs(p.Dialog,{onOpenChange:l,open:r,children:[u.jsx(p.DialogTrigger,{asChild:!0,children:u.jsx(p.ActionButton,{icon:"Pencil",tooltip:"Open Edit Link"})}),u.jsxs(p.DialogContent,{children:[u.jsx(p.DialogHeader,{children:u.jsx(p.DialogTitle,{children:"Edit Link Iframe"})}),u.jsx(p.Input,{autoFocus:!0,onInput:b=>a(b.target.value),placeholder:"Enter link",type:"url",value:c}),u.jsxs(p.DialogFooter,{children:[u.jsx(p.Button,{onClick:h,type:"button",children:"Cancel"}),u.jsx(p.Button,{onClick:d,type:"button",children:"OK"})]})]})]}),u.jsx(Xi,{height:s,onOk:g,width:i,children:u.jsx(p.ActionButton,{icon:"Settings",tooltip:n("editor.settings")})}),u.jsx(p.ActionButton,{action:x,icon:"Trash2",tooltip:n("editor.delete")})]})})}):u.jsx(u.Fragment,{})}function Qo({children:e,visible:t,toggleVisible:n}){const{t:i}=L.useLocale(),s=p.useEditorInstance(),o=ot.useAttributes(s,ot.Katex.name,{text:"",macros:""}),{text:r,macros:l}=o,[c,a]=w.useState(decodeURIComponent(r||"")),[h,d]=w.useState(decodeURIComponent(l||""));w.useEffect(()=>{t&&(a(decodeURIComponent(r||"")),d(decodeURIComponent(l||"")))},[t]);const f=w.useCallback(()=>{s.chain().focus().setKatex({text:encodeURIComponent(c),macros:encodeURIComponent(h)}).run(),a(""),d(""),n(!1)},[s,c,h,n]),g=w.useMemo(()=>{try{return mo.renderToString(c,{macros:ot.safeJSONParse(h||"")})}catch{return c}},[c,h]),m=w.useMemo(()=>`${c}`.trim()?g:null,[c,g]);return u.jsxs(p.Dialog,{onOpenChange:n,open:t,children:[u.jsx(p.DialogTrigger,{asChild:!0,children:e}),u.jsxs(p.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[u.jsx(p.DialogTitle,{children:i("editor.formula.dialog.text")}),u.jsx("div",{style:{height:"100%",border:"1px solid hsl(var(--border))"},children:u.jsxs("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[u.jsxs("div",{className:"richtext-flex-1",children:[u.jsx(p.Label,{className:"mb-[6px]",children:"Expression"}),u.jsx(Cn.Textarea,{autoFocus:!0,className:"richtext-mb-[10px]",onChange:x=>a(x.target.value),placeholder:"Text",required:!0,rows:10,value:c,style:{color:"hsl(var(--foreground))"}}),u.jsx(p.Label,{className:"mb-[6px]",children:"Macros"}),u.jsx(Cn.Textarea,{onChange:x=>d(x.target.value),placeholder:"Macros",rows:10,value:h,style:{color:"hsl(var(--foreground))"}})]}),u.jsx("div",{className:"richtext-flex richtext-flex-1 richtext-items-center richtext-justify-center richtext-rounded-[10px] richtext-p-[10px]",dangerouslySetInnerHTML:{__html:m||""},style:{height:"100%",borderWidth:1,minHeight:500,background:"#fff"}})]})}),u.jsx(p.DialogFooter,{children:u.jsx(p.Button,{onClick:f,type:"button",children:"Save changes"})})]})]})}function tr(){const e=p.useEditableEditor(),t=p.useEditorInstance(),[n,i]=w.useState(!1),s=w.useCallback(()=>t.isActive(ot.Katex.name),[t]),o=w.useCallback(()=>Jt.deleteNode(ot.Katex.name,t),[t]);return e?u.jsx(Z,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleKatex",shouldShow:s,children:u.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[u.jsx(Qo,{toggleVisible:i,visible:n,children:u.jsx(p.ActionButton,{action:()=>i(!n),tooltip:"Edit",children:u.jsx(Ue.Pencil,{size:16})})}),u.jsx(p.ActionButton,{action:o,tooltip:"Delete",children:u.jsx(Ue.Trash2,{size:16})})]})}):u.jsx(u.Fragment,{})}function er(e){const{t}=L.useLocale();return u.jsxs("div",{className:"richtext-flex richtext-flex-nowrap",children:[u.jsx(p.ActionButton,{disabled:!(e!=null&&e.link),icon:"ExternalLink",tooltip:t("editor.link.open.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{window.open(e==null?void 0:e.link,"_blank")}}),u.jsx(p.ActionButton,{icon:"Pencil",tooltip:t("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e==null||e.onEdit()}}),u.jsx(p.ActionButton,{icon:"Unlink",tooltip:t("editor.link.unlink.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e==null||e.onClear()}})]})}function nr(){const e=p.useEditableEditor(),t=p.useEditorInstance(),[n,i]=w.useState(!1),s=ot.useAttributes(t,De.Link.name),o=s==null?void 0:s.href,r=w.useCallback(({editor:h})=>h.isActive(De.Link.name),[]),l=(h,d,f)=>{const g=t.state.selection,{from:m}=g,x=(d==null?void 0:d.length)??0,b=m+x;t.chain().extendMarkRange("link").insertContent({type:"text",text:d,marks:[{type:"link",attrs:{href:h,target:f?"_blank":""}}]}).setLink({href:h}).setTextSelection({from:m,to:b}).focus().run(),i(!1)},c=w.useCallback(()=>{t.chain().extendMarkRange("link").unsetLink().focus().run(),i(!1)},[t]),a=()=>{i(!1)};return e?u.jsx(Z,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleLink",shouldShow:r,children:u.jsx(u.Fragment,{children:n?u.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-4 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:u.jsx(De.LinkEditBlock,{editor:t,onClose:a,onSetLink:l})}):u.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:u.jsx(er,{editor:t,link:o,onClear:c,onEdit:()=>{i(!0)}})})})}):u.jsx(u.Fragment,{})}function Hn({item:e,disabled:t,editor:n}){const i=e.component;return i?u.jsx(w.Fragment,{children:e.type==="divider"?u.jsx(kt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):u.jsx(i,{...e.componentProps,disabled:t||(e==null?void 0:e.componentdisabled),editor:n})}):u.jsx(u.Fragment,{})}function ir(e){return e.type.name===p.Image.name}function sr(e){return e.type.name===xo.ImageGif.name}function or(e){return e.type.name===p.Video.name}function rr(){const{lang:e,t}=L.useLocale(),n=p.useEditableEditor(),i=p.useEditorInstance(),s=({editor:r})=>{const{selection:l}=r.view.state,{$from:c,to:a}=l;let h=!1;return r.view.state.doc.nodesBetween(c.pos,a,d=>{if(ir(d))return h=!0,!1}),h},o=w.useMemo(()=>Ho(i,t),[i,e,t]);return n?u.jsx(Z,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleImage",shouldShow:s,children:o!=null&&o.length?u.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:o==null?void 0:o.map((r,l)=>u.jsx(Hn,{editor:i,item:r},`bubbleMenu-image-${l}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}function lr(){const{lang:e,t}=L.useLocale(),n=p.useEditableEditor(),i=p.useEditorInstance(),s=({editor:r})=>{const{selection:l}=r.view.state,{$from:c,to:a}=l;let h=!1;return r.view.state.doc.nodesBetween(c.pos,a,d=>{if(sr(d))return h=!0,!1}),h},o=w.useMemo(()=>$o(i,t),[i,t,e]);return n?u.jsx(Z,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleImageGif",shouldShow:s,children:o!=null&&o.length?u.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:o==null?void 0:o.map((r,l)=>u.jsx(Hn,{editor:i,item:r},`bubbleMenu-image-gif-${l}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}function cr(){const{t:e}=L.useLocale(),t=p.useEditableEditor(),n=p.useEditorInstance(),i=({editor:o})=>{const{selection:r}=o.view.state,{$from:l,to:c}=r;let a=!1;return o.view.state.doc.nodesBetween(l.pos,c,h=>{if(or(h))return a=!0,!1}),a},s=w.useMemo(()=>Ko(n,e),[n,e]);return t?u.jsx(Z,{editor:n,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleVideo",shouldShow:i,children:s!=null&&s.length?u.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:s==null?void 0:s.map((o,r)=>u.jsx(Hn,{editor:n,item:o},`bubbleMenu-video-${r}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}const fi=`graph TB a-->b`,ar=({editor:e,attrs:t,extension:n})=>{const{alt:i,align:s}=t,[o,r]=w.useState(decodeURIComponent(i??fi)),[l,c]=w.useState(""),[a,h]=w.useState(!1),d=w.useRef(null),[f,g]=w.useState(null),m=n==null?void 0:n.options.upload,x=w.useCallback(M=>{M&&import("mermaid").then(k=>{g(k.default)})},[]),b=async M=>{try{const{svg:k}=await f.render("mermaid-svg",M);c(k)}catch{c("")}},y=()=>{f.initialize({darkMode:!1,startOnLoad:!1,fontSize:12,theme:"base"}),b(o)};w.useEffect(()=>{f&&a&&y()},[f,a]),w.useEffect(()=>{f&&a&&b(o)},[f,o]);const I=async()=>{if(o!==""){if(o){const M=d.current.querySelector("svg"),{width:k,height:B}=M.getBoundingClientRect(),T=`mermaid-${Le.shortId()}.svg`;let S=Le.i(M.outerHTML);if(m){const C=p.dataURLtoFile(S,T);S=await m(C)}e==null||e.chain().focus().setMermaid({type:"mermaid",src:S,alt:encodeURIComponent(o),width:k,height:B},!!o).run(),e==null||e.commands.setAlignImageMermaid(s)}h(!1)}};return u.jsxs(p.Dialog,{onOpenChange:h,open:a,children:[u.jsx(p.DialogTrigger,{asChild:!0,children:u.jsx(p.ActionButton,{action:()=>h(!0),icon:"Pencil",tooltip:"Edit Mermaid"})}),u.jsxs(p.DialogContent,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[u.jsx(p.DialogTitle,{children:"Edit Mermaid"}),u.jsx("div",{ref:x,style:{height:"100%",border:"1px solid hsl(var(--border))"},children:u.jsxs("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[u.jsx(Cn.Textarea,{autoFocus:!0,className:"richtext-flex-1",defaultValue:fi,onChange:M=>r(M.target.value),placeholder:"Text",required:!0,rows:10,value:o,style:{color:"hsl(var(--foreground))"}}),u.jsx("div",{className:"richtext-flex richtext-flex-1 richtext-items-center richtext-justify-center richtext-rounded-[10px] richtext-p-[10px]",dangerouslySetInnerHTML:{__html:l},ref:d,style:{height:"100%",border:"1px solid hsl(var(--border))",minHeight:500}})]})}),u.jsx(p.DialogFooter,{children:u.jsx(p.Button,{onClick:I,type:"button",children:"Save changes"})})]})]})};function hr({item:e,disabled:t,editor:n}){var s;const i=e.component;return i?u.jsx(w.Fragment,{children:e.type==="divider"?u.jsx(kt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):u.jsx(i,{...e.componentProps,disabled:t||((s=e==null?void 0:e.componentProps)==null?void 0:s.disabled),editor:n})}):u.jsx(u.Fragment,{})}function dr(e){return e.type.name===kn.Mermaid.name}function ur(){const{lang:e,t}=L.useLocale(),n=p.useEditableEditor(),i=p.useEditorInstance(),s=ot.useAttributes(i,kn.Mermaid.name),o=p.useExtension(kn.Mermaid.name),r=({editor:c})=>{const{selection:a}=c.view.state,{$from:h,to:d}=a;let f=!1;return c.view.state.doc.nodesBetween(h.pos,d,g=>{if(dr(g))return f=!0,!1}),f},l=w.useMemo(()=>zo(i,t),[i,e,t]);return n?u.jsx(Z,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleMermaid",shouldShow:r,children:l!=null&&l.length?u.jsx("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:l==null?void 0:l.map((c,a)=>c.type==="edit"&&(s!=null&&s.src)?u.jsx(ar,{attrs:s,editor:i,extension:o},`bubbleMenu-mermaid-${a}`):u.jsx(hr,{editor:i,item:c},`bubbleMenu-mermaid-${a}`))}):u.jsx(u.Fragment,{})}):u.jsx(u.Fragment,{})}function fr({hiddenActions:e=[]}){var x,b,y,I,M,k,B,T,S,C,R,H,tt,Tt,At,v,ft,Se;const{t}=L.useLocale(),n=p.useEditableEditor(),i=p.useEditorInstance(),s=({editor:Pt})=>E.isActive(Pt.view.state,Ki.Table.name),o=Pt=>e.includes(Pt);function r(){i.chain().focus().addColumnBefore().run()}function l(){i.chain().focus().addColumnAfter().run()}function c(){i.chain().focus().deleteColumn().run()}function a(){i.chain().focus().addRowBefore().run()}function h(){i.chain().focus().addRowAfter().run()}function d(){i.chain().focus().deleteRow().run()}function f(){i.chain().focus().mergeCells().run()}function g(){i==null||i.chain().focus().splitCell().run()}function m(){i.chain().focus().deleteTable().run()}return n?u.jsx(Z,{editor:i,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTable",shouldShow:s,children:u.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[!o("addColumnBefore")&&u.jsx(p.ActionButton,{action:r,disabled:!((b=(x=i==null?void 0:i.can())==null?void 0:x.addColumnBefore)!=null&&b.call(x)),icon:"BetweenHorizonalEnd",tooltip:t("editor.table.menu.insertColumnBefore"),tooltipOptions:{sideOffset:15}}),!o("addColumnAfter")&&u.jsx(p.ActionButton,{action:l,disabled:!((I=(y=i==null?void 0:i.can())==null?void 0:y.addColumnAfter)!=null&&I.call(y)),icon:"BetweenHorizonalStart",tooltip:t("editor.table.menu.insertColumnAfter"),tooltipOptions:{sideOffset:15}}),!o("deleteColumn")&&u.jsx(p.ActionButton,{action:c,disabled:!((k=i==null?void 0:(M=i.can()).deleteColumn)!=null&&k.call(M)),icon:"DeleteColumn",tooltip:t("editor.table.menu.deleteColumn"),tooltipOptions:{sideOffset:15}}),u.jsx(kt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!o("addRowAbove")&&u.jsx(p.ActionButton,{action:a,disabled:!((T=i==null?void 0:(B=i.can()).addRowBefore)!=null&&T.call(B)),icon:"BetweenVerticalEnd",tooltip:t("editor.table.menu.insertRowAbove"),tooltipOptions:{sideOffset:15}}),!o("addRowBelow")&&u.jsx(p.ActionButton,{action:h,disabled:!((C=(S=i==null?void 0:i.can())==null?void 0:S.addRowAfter)!=null&&C.call(S)),icon:"BetweenVerticalStart",tooltip:t("editor.table.menu.insertRowBelow"),tooltipOptions:{sideOffset:15}}),!o("deleteRow")&&u.jsx(p.ActionButton,{action:d,disabled:!((H=(R=i==null?void 0:i.can())==null?void 0:R.deleteRow)!=null&&H.call(R)),icon:"DeleteRow",tooltip:t("editor.table.menu.deleteRow"),tooltipOptions:{sideOffset:15}}),u.jsx(kt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!o("mergeCells")&&u.jsx(p.ActionButton,{action:f,disabled:!((Tt=(tt=i==null?void 0:i.can())==null?void 0:tt.mergeCells)!=null&&Tt.call(tt)),icon:"TableCellsMerge",tooltip:t("editor.table.menu.mergeCells"),tooltipOptions:{sideOffset:15}}),!o("splitCells")&&u.jsx(p.ActionButton,{action:g,disabled:!((v=(At=i==null?void 0:i.can())==null?void 0:At.splitCell)!=null&&v.call(At)),icon:"TableCellsSplit",tooltip:t("editor.table.menu.splitCells"),tooltipOptions:{sideOffset:15}}),u.jsx(kt.Separator,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!o("deleteTable")&&u.jsx(p.ActionButton,{action:m,disabled:!((Se=(ft=i==null?void 0:i.can())==null?void 0:ft.deleteTable)!=null&&Se.call(ft)),icon:"Trash2",tooltip:t("editor.table.menu.deleteTable"),tooltipOptions:{sideOffset:15}})]})}):u.jsx(u.Fragment,{})}function gr(){const{t:e}=L.useLocale(),[t,n]=w.useState(!1),i=p.useEditorInstance(),s=w.useMemo(()=>{var r,l;return(l=(r=ko.renderCommandListDefault({t:e}))==null?void 0:r[0])==null?void 0:l.commands},[e]),o=w.useMemo(()=>{var l;return(l=s==null?void 0:s.find(c=>{var a;retu