decocms
Version:
Deco CMS — Self-hostable MCP Gateway for managing AI connections and tools
2 lines (1 loc) • 21.6 kB
JavaScript
import{B as H,v as U,ab as S,H as X,ac as Z,f as R,ad as J,ae as Q,p as z}from"./usage-stats-CLeyhHyT.js";import{gE as M,hp as C,gD as P,hq as x,hr as L,hs as V,ht as K,hu as _,gG as A,eX as N,r as p,cd as B}from"./index-DoEtSiIe.js";import{C as k}from"./index-DJ-fS83G.js";function tt(t,e){const i=Math.min(t.top,e.top),s=Math.max(t.bottom,e.bottom),l=Math.min(t.left,e.left),r=Math.max(t.right,e.right)-l,n=s-i;return new DOMRect(l,i,r,n)}var et=class{get middlewares(){const t=[];return this.floatingUIOptions.flip&&t.push(M(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&t.push(C(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&t.push(P(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&t.push(x(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&t.push(L(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&t.push(V(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&t.push(K(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&t.push(_(typeof this.floatingUIOptions.inline!="boolean"?this.floatingUIOptions.inline:void 0)),t}get virtualElement(){var t,e;const{selection:i}=this.editor.state,s=(t=this.getReferencedVirtualElement)===null||t===void 0?void 0:t.call(this);if(s)return s;if(!(!((e=this.view)===null||e===void 0||(e=e.dom)===null||e===void 0)&&e.parentNode))return;const l=S(this.view,i.from,i.to);let r={getBoundingClientRect:()=>l,getClientRects:()=>[l]};if(i instanceof X){let n=this.view.nodeDOM(i.from);const d=n.dataset.nodeViewWrapper?n:n.querySelector("[data-node-view-wrapper]");d&&(n=d),n&&(r={getBoundingClientRect:()=>n.getBoundingClientRect(),getClientRects:()=>[n.getBoundingClientRect()]})}if(i instanceof k){const{$anchorCell:n,$headCell:d}=i,g=n?n.pos:d.pos,f=d?d.pos:n.pos,u=this.view.nodeDOM(g),o=this.view.nodeDOM(f);if(!u||!o)return;const a=u===o?u.getBoundingClientRect():tt(u.getBoundingClientRect(),o.getBoundingClientRect());r={getBoundingClientRect:()=>a,getClientRects:()=>[a]}}return r}constructor({editor:t,element:e,view:i,pluginKey:s="bubbleMenu",updateDelay:l=250,resizeDelay:r=60,shouldShow:n,appendTo:d,getReferencedVirtualElement:g,options:f}){var u;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:o,state:a,from:h,to:c})=>{const{doc:m,selection:y}=a,{empty:O}=y,b=!m.textBetween(h,c).length&&Z(a.selection),v=this.element.contains(document.activeElement);return!(!(o.hasFocus()||v)||O||b||!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:o})=>{var a;if(this.editor.isDestroyed){this.destroy();return}if(this.preventHide){this.preventHide=!1;return}o?.relatedTarget&&(!((a=this.element.parentNode)===null||a===void 0)&&a.contains(o.relatedTarget))||o?.relatedTarget!==this.editor.view.dom&&this.hide()},this.handleDebouncedUpdate=(o,a)=>{const h=!a?.selection.eq(o.state.selection),c=!a?.doc.eq(o.state.doc);!h&&!c||(this.updateDebounceTimer&&clearTimeout(this.updateDebounceTimer),this.updateDebounceTimer=window.setTimeout(()=>{this.updateHandler(o,h,c,a)},this.updateDelay))},this.updateHandler=(o,a,h,c)=>{const{composing:m}=o;if(!(m||!a&&!h)){if(!this.getShouldShow(c)){this.hide();return}this.show(),this.updatePosition()}},this.transactionHandler=({transaction:o})=>{const a=o.getMeta(this.pluginKey);a==="updatePosition"?this.updatePosition():a&&typeof a=="object"&&a.type==="updateOptions"?this.updateOptions(a.options):a==="hide"?this.hide():a==="show"&&(this.updatePosition(),this.show())},this.editor=t,this.element=e,this.view=i,this.pluginKey=s,this.updateDelay=l,this.resizeDelay=r,this.appendTo=d,this.scrollTarget=(u=f?.scrollTarget)!==null&&u!==void 0?u:window,this.getReferencedVirtualElement=g,this.floatingUIOptions={...this.floatingUIOptions,...f},this.element.tabIndex=0,n&&(this.shouldShow=n),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(i,i.state),this.getShouldShow()&&(this.show(),this.updatePosition())}updatePosition(){if(!this.isVisible)return;const t=this.virtualElement;t&&A(t,this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:e,y:i,strategy:s,middlewareData:l})=>{var r,n;if(!(!this.isVisible||this.editor.isDestroyed||!this.element.isConnected)){if(!((r=l.hide)===null||r===void 0)&&r.referenceHidden||!((n=l.hide)===null||n===void 0)&&n.escaped){this.element.style.visibility="hidden";return}this.element.style.visibility="visible",this.element.style.width="max-content",this.element.style.position=s,this.element.style.left=`${e}px`,this.element.style.top=`${i}px`,this.isVisible&&this.floatingUIOptions.onUpdate&&this.floatingUIOptions.onUpdate()}})}update(t,e){const{state:i}=t,s=i.selection.from!==i.selection.to;if(this.updateDelay>0&&s){this.handleDebouncedUpdate(t,e);return}const l=!e?.selection.eq(t.state.selection),r=!e?.doc.eq(t.state.doc);this.updateHandler(t,l,r,e)}getShouldShow(t){var e;const{state:i}=this.view,{selection:s}=i,{ranges:l}=s,r=Math.min(...l.map(d=>d.$from.pos)),n=Math.max(...l.map(d=>d.$to.pos));return((e=this.shouldShow)===null||e===void 0?void 0:e.call(this,{editor:this.editor,element:this.element,view:this.view,state:i,oldState:t,from:r,to:n}))||!1}show(){var t;if(this.isVisible)return;this.element.style.visibility="visible",this.element.style.opacity="1";const e=typeof this.appendTo=="function"?this.appendTo():this.appendTo;(t=e??this.view.dom.parentElement)===null||t===void 0||t.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)}updateOptions(t){if(t.updateDelay!==void 0&&(this.updateDelay=t.updateDelay),t.resizeDelay!==void 0&&(this.resizeDelay=t.resizeDelay),t.appendTo!==void 0&&(this.appendTo=t.appendTo),t.getReferencedVirtualElement!==void 0&&(this.getReferencedVirtualElement=t.getReferencedVirtualElement),t.shouldShow!==void 0&&t.shouldShow&&(this.shouldShow=t.shouldShow),t.options!==void 0){var e;const i=(e=t.options.scrollTarget)!==null&&e!==void 0?e:window;i!==this.scrollTarget&&(this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.scrollTarget=i,this.scrollTarget.addEventListener("scroll",this.resizeHandler)),this.floatingUIOptions={...this.floatingUIOptions,...t.options}}}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()}};const $=t=>new H({key:typeof t.pluginKey=="string"?new U(t.pluginKey):t.pluginKey,view:e=>new et({view:e,...t})});R.create({name:"bubbleMenu",addOptions(){return{element:null,pluginKey:"bubbleMenu",updateDelay:void 0,appendTo:void 0,shouldShow:null}},addProseMirrorPlugins(){return this.options.element?[$({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 it=class{getTextContent(t){return J(t,{textSerializers:Q(this.editor.schema)})}get middlewares(){const t=[];return this.floatingUIOptions.flip&&t.push(M(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&t.push(C(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&t.push(P(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&t.push(x(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&t.push(L(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&t.push(V(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&t.push(K(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&t.push(_(typeof this.floatingUIOptions.inline!="boolean"?this.floatingUIOptions.inline:void 0)),t}constructor({editor:t,element:e,view:i,pluginKey:s="floatingMenu",updateDelay:l=250,resizeDelay:r=60,options:n,appendTo:d,shouldShow:g}){var f;this.preventHide=!1,this.isVisible=!1,this.scrollTarget=window,this.shouldShow=({view:u,state:o})=>{const{selection:a}=o,{$anchor:h,empty:c}=a,m=h.depth===1,y=h.parent.isTextblock&&!h.parent.type.spec.code&&!h.parent.textContent&&h.parent.childCount===0&&!this.getTextContent(h.parent);return!(!u.hasFocus()||!c||!m||!y||!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=(u,o,a,h)=>{const{composing:c}=u;if(!(c||!o&&!a)){if(!this.getShouldShow(h)){this.hide();return}this.updatePosition(),this.show()}},this.mousedownHandler=()=>{this.preventHide=!0},this.focusHandler=()=>{setTimeout(()=>this.update(this.editor.view))},this.blurHandler=({event:u})=>{var o;if(this.preventHide){this.preventHide=!1;return}u?.relatedTarget&&(!((o=this.element.parentNode)===null||o===void 0)&&o.contains(u.relatedTarget))||u?.relatedTarget!==this.editor.view.dom&&this.hide()},this.transactionHandler=({transaction:u})=>{const o=u.getMeta(this.pluginKey);o==="updatePosition"?this.updatePosition():o&&typeof o=="object"&&o.type==="updateOptions"?this.updateOptions(o.options):o==="hide"?this.hide():o==="show"&&(this.updatePosition(),this.show())},this.resizeHandler=()=>{this.resizeDebounceTimer&&clearTimeout(this.resizeDebounceTimer),this.resizeDebounceTimer=window.setTimeout(()=>{this.updatePosition()},this.resizeDelay)},this.editor=t,this.element=e,this.view=i,this.pluginKey=s,this.updateDelay=l,this.resizeDelay=r,this.appendTo=d,this.scrollTarget=(f=n?.scrollTarget)!==null&&f!==void 0?f:window,this.floatingUIOptions={...this.floatingUIOptions,...n},this.element.tabIndex=0,g&&(this.shouldShow=g),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(i,i.state),this.getShouldShow()&&(this.show(),this.updatePosition())}getShouldShow(t){var e;const{state:i}=this.view,{selection:s}=i,{ranges:l}=s,r=Math.min(...l.map(d=>d.$from.pos)),n=Math.max(...l.map(d=>d.$to.pos));return(e=this.shouldShow)===null||e===void 0?void 0:e.call(this,{editor:this.editor,view:this.view,state:i,oldState:t,from:r,to:n})}updateOptions(t){if(t.updateDelay!==void 0&&(this.updateDelay=t.updateDelay),t.resizeDelay!==void 0&&(this.resizeDelay=t.resizeDelay),t.appendTo!==void 0&&(this.appendTo=t.appendTo),t.shouldShow!==void 0&&t.shouldShow&&(this.shouldShow=t.shouldShow),t.options!==void 0){var e;const i=(e=t.options.scrollTarget)!==null&&e!==void 0?e:window;i!==this.scrollTarget&&(this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.scrollTarget=i,this.scrollTarget.addEventListener("scroll",this.resizeHandler)),this.floatingUIOptions={...this.floatingUIOptions,...t.options}}}updatePosition(){var t;if(!(!((t=this.view)===null||t===void 0||(t=t.dom)===null||t===void 0)&&t.parentNode))return;const{selection:e}=this.editor.state,i=S(this.view,e.from,e.to);A({getBoundingClientRect:()=>i,getClientRects:()=>[i]},this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:s,y:l,strategy:r,middlewareData:n})=>{var d,g;if(!((d=n.hide)===null||d===void 0)&&d.referenceHidden||!((g=n.hide)===null||g===void 0)&&g.escaped){this.element.style.visibility="hidden";return}this.element.style.visibility="visible",this.element.style.width="max-content",this.element.style.position=r,this.element.style.left=`${s}px`,this.element.style.top=`${l}px`,this.isVisible&&this.floatingUIOptions.onUpdate&&this.floatingUIOptions.onUpdate()})}update(t,e){const i=!e?.selection.eq(t.state.selection),s=!e?.doc.eq(t.state.doc);this.updateHandler(t,i,s,e)}show(){var t;if(this.isVisible)return;this.element.style.visibility="visible",this.element.style.opacity="1";const e=typeof this.appendTo=="function"?this.appendTo():this.appendTo;(t=e??this.view.dom.parentElement)===null||t===void 0||t.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()}};const F=t=>new H({key:typeof t.pluginKey=="string"?new U(t.pluginKey):t.pluginKey,view:e=>new it({view:e,...t})});R.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:t,dispatch:e})=>(e&&t.setMeta(this.options.pluginKey,"updatePosition"),!0)}},addProseMirrorPlugins(){return this.options.element?[F({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 W(t,e){return t??new U(e)}const st=typeof window<"u"?p.useLayoutEffect:p.useEffect,q=new Set(["left","opacity","position","top","visibility","width"]),nt=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"]),ot=new Set(["children","className","style"]),rt=new Set(["tabIndex"]),lt=new Set(["accessKey","autoCapitalize","contentEditable","contextMenu","dir","draggable","enterKeyHint","hidden","id","lang","nonce","role","slot","spellCheck","tabIndex","title","translate"]),at={Blur:"focusout",DoubleClick:"dblclick",Focus:"focusin",MouseEnter:"mouseenter",MouseLeave:"mouseleave"};function T(t,e){return/^on[A-Z]/.test(t)&&typeof e=="function"}function dt(t){return t.startsWith("aria-")||t.startsWith("data-"),t}function ut(t){return t.startsWith("aria-")||t.startsWith("data-")||lt.has(t)}function j(t){return t.startsWith("--")?t:t.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}function ht(t){var e;const i=t.endsWith("Capture"),s=(i?t.slice(0,-7):t).slice(2);return{eventName:(e=at[s])!==null&&e!==void 0?e:s.toLowerCase(),options:i?{capture:!0}:void 0}}function ct(t,e){let i=e.defaultPrevented,s=!1;const l=Object.create(e);return Object.defineProperties(l,{nativeEvent:{value:e},currentTarget:{value:t},target:{value:e.target},persist:{value:()=>{}},isDefaultPrevented:{value:()=>i},isPropagationStopped:{value:()=>s},preventDefault:{value:()=>{i=!0,e.preventDefault()}},stopPropagation:{value:()=>{s=!0,e.stopPropagation()}}}),l}function E(t){return rt.has(t)}function D(t,e,i){if(e==="tabIndex"){t.tabIndex=Number(i);return}t[e]=i}function ft(t,e){if(e==="tabIndex"){t.removeAttribute("tabindex");return}const i=t[e];if(typeof i=="boolean"){t[e]=!1;return}if(typeof i=="number"){t[e]=0;return}t[e]=""}function pt(t,e){return typeof e!="number"||e===0||t.startsWith("--")||nt.has(t)?String(e):`${e}px`}function gt(t,e){q.has(e)||t.style.removeProperty(j(e))}function mt(t,e,i){q.has(e)||t.style.setProperty(j(e),pt(e,i))}function vt(t,e,i){new Set([...Object.keys(e),...Object.keys(i)]).forEach(s=>{if(ot.has(s)||!ut(s)||T(s,e[s])||T(s,i[s]))return;const l=e[s],r=i[s];if(l===r)return;const n=dt(s);if(r==null||r===!1){E(s)&&ft(t,s),t.removeAttribute(n);return}if(r===!0){E(s)&&D(t,s,!0),t.setAttribute(n,"");return}if(E(s)){D(t,s,r);return}t.setAttribute(n,String(r))})}function yt(t,e,i){if(e!==i){if(i){t.className=i;return}t.removeAttribute("class")}}function bt(t,e,i){const s=e??{},l=i??{};new Set([...Object.keys(s),...Object.keys(l)]).forEach(r=>{const n=s[r],d=l[r];if(n!==d){if(d==null){gt(t,r);return}mt(t,r,d)}})}function wt(t,e,i){e.forEach(({eventName:l,listener:r,options:n})=>{t.removeEventListener(l,r,n)});const s=[];return Object.entries(i).forEach(([l,r])=>{if(!T(l,r))return;const{eventName:n,options:d}=ht(l),g=f=>{r(ct(t,f))};t.addEventListener(n,g,d),s.push({eventName:n,listener:g,options:d})}),s}function Y(t,e){const i=p.useRef({}),s=p.useRef([]);st(()=>{const l=i.current;return yt(t,l.className,e.className),bt(t,l.style,e.style),vt(t,l,e),s.current=wt(t,s.current,e),i.current=e,()=>{s.current.forEach(({eventName:r,listener:n,options:d})=>{t.removeEventListener(r,n,d)}),s.current=[]}},[t,e])}const Tt=N.forwardRef(({pluginKey:t,editor:e,updateDelay:i,resizeDelay:s,appendTo:l,shouldShow:r=null,getReferencedVirtualElement:n,options:d,children:g,...f},u)=>{const o=p.useRef(document.createElement("div")),a=p.useRef(W(t,"bubbleMenu")).current;Y(o.current,f),typeof u=="function"?u(o.current):u&&(u.current=o.current);const{editor:h}=z(),c=e||h,m={updateDelay:i,resizeDelay:s,appendTo:l,pluginKey:a,shouldShow:r,getReferencedVirtualElement:n,options:d},y=p.useRef(m);y.current=m;const[O,b]=p.useState(!1),v=p.useRef(!0);return p.useEffect(()=>{if(c?.isDestroyed)return;if(!c){console.warn("BubbleMenu component is not rendered inside of an editor component or does not have editor prop.");return}const w=o.current;w.style.visibility="hidden",w.style.position="absolute";const I=$({...y.current,editor:c,element:w});c.registerPlugin(I);const G=y.current.pluginKey;return v.current=!0,b(!0),()=>{b(!1),c.unregisterPlugin(G),window.requestAnimationFrame(()=>{w.parentNode&&w.parentNode.removeChild(w)})}},[c]),p.useEffect(()=>{if(!(!O||!c||c.isDestroyed)){if(v.current){v.current=!1;return}c.view.dispatch(c.state.tr.setMeta(a,{type:"updateOptions",options:y.current}))}},[O,c,i,s,r,d,l,n,a]),B.createPortal(g,o.current)});N.forwardRef(({pluginKey:t,editor:e,updateDelay:i,resizeDelay:s,appendTo:l,shouldShow:r=null,options:n,children:d,...g},f)=>{const u=p.useRef(document.createElement("div")),o=p.useRef(W(t,"floatingMenu")).current;Y(u.current,g),typeof f=="function"?f(u.current):f&&(f.current=u.current);const{editor:a}=z(),h=e||a,c={updateDelay:i,resizeDelay:s,appendTo:l,pluginKey:o,shouldShow:r,options:n},m=p.useRef(c);m.current=c;const[y,O]=p.useState(!1),b=p.useRef(!0);return p.useEffect(()=>{if(h?.isDestroyed)return;if(!h){console.warn("FloatingMenu component is not rendered inside of an editor component or does not have editor prop.");return}const v=u.current;v.style.visibility="hidden",v.style.position="absolute";const w=F({...m.current,editor:h,element:v});h.registerPlugin(w);const I=m.current.pluginKey;return b.current=!0,O(!0),()=>{O(!1),h.unregisterPlugin(I),window.requestAnimationFrame(()=>{v.parentNode&&v.parentNode.removeChild(v)})}},[h]),p.useEffect(()=>{if(!(!y||!h||h.isDestroyed)){if(b.current){b.current=!1;return}h.view.dispatch(h.state.tr.setMeta(o,{type:"updateOptions",options:m.current}))}},[y,h,i,s,r,n,l,o]),B.createPortal(d,u.current)});export{Tt as B};