reactjs-tiptap-editor
Version:
A modern WYSIWYG rich text editor based on tiptap and shadcn ui for React
2 lines (1 loc) • 25 kB
JavaScript
;const Mt=require("@tiptap/pm/state"),Rt=require("@tiptap/pm/view"),Jt=require("./clsx-CXbNJWDD.cjs"),_t=["top","right","bottom","left"],At=["start","end"],Ot=_t.reduce((t,e)=>t.concat(e,e+"-"+At[0],e+"-"+At[1]),[]),j=Math.min,M=Math.max,rt=Math.round,H=t=>({x:t,y:t}),Qt={left:"right",right:"left",bottom:"top",top:"bottom"},Zt={start:"end",end:"start"};function ht(t,e,o){return M(t,j(e,o))}function Y(t,e){return typeof t=="function"?t(e):t}function F(t){return t.split("-")[0]}function q(t){return t.split("-")[1]}function Nt(t){return t==="x"?"y":"x"}function wt(t){return t==="y"?"height":"width"}const te=new Set(["top","bottom"]);function V(t){return te.has(F(t))?"y":"x"}function xt(t){return Nt(V(t))}function Ft(t,e,o){o===void 0&&(o=!1);const n=q(t),i=xt(t),s=wt(i);let r=i==="x"?n===(o?"end":"start")?"right":"left":n==="start"?"bottom":"top";return e.reference[s]>e.floating[s]&&(r=lt(r)),[r,lt(r)]}function ee(t){const e=lt(t);return[ct(t),e,ct(e)]}function ct(t){return t.replace(/start|end/g,e=>Zt[e])}const Ct=["left","right"],Pt=["right","left"],ne=["top","bottom"],oe=["bottom","top"];function ie(t,e,o){switch(t){case"top":case"bottom":return o?e?Pt:Ct:e?Ct:Pt;case"left":case"right":return e?ne:oe;default:return[]}}function se(t,e,o,n){const i=q(t);let s=ie(F(t),o==="start",n);return i&&(s=s.map(r=>r+"-"+i),e&&(s=s.concat(s.map(ct)))),s}function lt(t){return t.replace(/left|right|bottom|top/g,e=>Qt[e])}function re(t){return{top:0,right:0,bottom:0,left:0,...t}}function yt(t){return typeof t!="number"?re(t):{top:t,right:t,bottom:t,left:t}}function Q(t){const{x:e,y:o,width:n,height:i}=t;return{width:n,height:i,top:o,left:e,right:e+n,bottom:o+i,x:e,y:o}}function Et(t,e,o){let{reference:n,floating:i}=t;const s=V(e),r=xt(e),c=wt(r),f=F(e),a=s==="y",u=n.x+n.width/2-i.width/2,l=n.y+n.height/2-i.height/2,w=n[c]/2-i[c]/2;let g;switch(f){case"top":g={x:u,y:n.y-i.height};break;case"bottom":g={x:u,y:n.y+n.height};break;case"right":g={x:n.x+n.width,y:l};break;case"left":g={x:n.x-i.width,y:l};break;default:g={x:n.x,y:n.y}}switch(q(e)){case"start":g[r]-=w*(o&&a?-1:1);break;case"end":g[r]+=w*(o&&a?-1:1);break}return g}const ce=async(t,e,o)=>{const{placement:n="bottom",strategy:i="absolute",middleware:s=[],platform:r}=o,c=s.filter(Boolean),f=await(r.isRTL==null?void 0:r.isRTL(e));let a=await r.getElementRects({reference:t,floating:e,strategy:i}),{x:u,y:l}=Et(a,n,f),w=n,g={},p=0;for(let v=0;v<c.length;v++){const{name:d,fn:m}=c[v],{x:S,y:A,data:E,reset:O}=await m({x:u,y:l,initialPlacement:n,placement:w,strategy:i,middlewareData:g,rects:a,platform:r,elements:{reference:t,floating:e}});u=S??u,l=A??l,g={...g,[d]:{...g[d],...E}},O&&p<=50&&(p++,typeof O=="object"&&(O.placement&&(w=O.placement),O.rects&&(a=O.rects===!0?await r.getElementRects({reference:t,floating:e,strategy:i}):O.rects),{x:u,y:l}=Et(a,w,f)),v=-1)}return{x:u,y:l,placement:w,strategy:i,middlewareData:g}};async function Z(t,e){var o;e===void 0&&(e={});const{x:n,y:i,platform:s,rects:r,elements:c,strategy:f}=t,{boundary:a="clippingAncestors",rootBoundary:u="viewport",elementContext:l="floating",altBoundary:w=!1,padding:g=0}=Y(e,t),p=yt(g),d=c[w?l==="floating"?"reference":"floating":l],m=Q(await s.getClippingRect({element:(o=await(s.isElement==null?void 0:s.isElement(d)))==null||o?d:d.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(c.floating)),boundary:a,rootBoundary:u,strategy:f})),S=l==="floating"?{x:n,y:i,width:r.floating.width,height:r.floating.height}:r.reference,A=await(s.getOffsetParent==null?void 0:s.getOffsetParent(c.floating)),E=await(s.isElement==null?void 0:s.isElement(A))?await(s.getScale==null?void 0:s.getScale(A))||{x:1,y:1}:{x:1,y:1},O=Q(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:c,rect:S,offsetParent:A,strategy:f}):S);return{top:(m.top-O.top+p.top)/E.y,bottom:(O.bottom-m.bottom+p.bottom)/E.y,left:(m.left-O.left+p.left)/E.x,right:(O.right-m.right+p.right)/E.x}}const le=t=>({name:"arrow",options:t,async fn(e){const{x:o,y:n,placement:i,rects:s,platform:r,elements:c,middlewareData:f}=e,{element:a,padding:u=0}=Y(t,e)||{};if(a==null)return{};const l=yt(u),w={x:o,y:n},g=xt(i),p=wt(g),v=await r.getDimensions(a),d=g==="y",m=d?"top":"left",S=d?"bottom":"right",A=d?"clientHeight":"clientWidth",E=s.reference[p]+s.reference[g]-w[g]-s.floating[p],O=w[g]-s.reference[g],y=await(r.getOffsetParent==null?void 0:r.getOffsetParent(a));let b=y?y[A]:0;(!b||!await(r.isElement==null?void 0:r.isElement(y)))&&(b=c.floating[A]||s.floating[p]);const C=E/2-O/2,P=b/2-v[p]/2-1,h=j(l[m],P),R=j(l[S],P),D=h,k=b-v[p]-R,L=b/2-v[p]/2+C,x=ht(D,L,k),$=!f.arrow&&q(i)!=null&&L!==x&&s.reference[p]/2-(L<D?h:R)-v[p]/2<0,T=$?L<D?L-D:L-k:0;return{[g]:w[g]+T,data:{[g]:x,centerOffset:L-x-T,...$&&{alignmentOffset:T}},reset:$}}});function ae(t,e,o){return(t?[...o.filter(i=>q(i)===t),...o.filter(i=>q(i)!==t)]:o.filter(i=>F(i)===i)).filter(i=>t?q(i)===t||(e?ct(i)!==i:!1):!0)}const fe=function(t){return t===void 0&&(t={}),{name:"autoPlacement",options:t,async fn(e){var o,n,i;const{rects:s,middlewareData:r,placement:c,platform:f,elements:a}=e,{crossAxis:u=!1,alignment:l,allowedPlacements:w=Ot,autoAlignment:g=!0,...p}=Y(t,e),v=l!==void 0||w===Ot?ae(l||null,g,w):w,d=await Z(e,p),m=((o=r.autoPlacement)==null?void 0:o.index)||0,S=v[m];if(S==null)return{};const A=Ft(S,s,await(f.isRTL==null?void 0:f.isRTL(a.floating)));if(c!==S)return{reset:{placement:v[0]}};const E=[d[F(S)],d[A[0]],d[A[1]]],O=[...((n=r.autoPlacement)==null?void 0:n.overflows)||[],{placement:S,overflows:E}],y=v[m+1];if(y)return{data:{index:m+1,overflows:O},reset:{placement:y}};const b=O.map(h=>{const R=q(h.placement);return[h.placement,R&&u?h.overflows.slice(0,2).reduce((D,k)=>D+k,0):h.overflows[0],h.overflows]}).sort((h,R)=>h[1]-R[1]),P=((i=b.filter(h=>h[2].slice(0,q(h[0])?2:3).every(R=>R<=0))[0])==null?void 0:i[0])||b[0][0];return P!==c?{data:{index:m+1,overflows:O},reset:{placement:P}}:{}}}},ue=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var o,n;const{placement:i,middlewareData:s,rects:r,initialPlacement:c,platform:f,elements:a}=e,{mainAxis:u=!0,crossAxis:l=!0,fallbackPlacements:w,fallbackStrategy:g="bestFit",fallbackAxisSideDirection:p="none",flipAlignment:v=!0,...d}=Y(t,e);if((o=s.arrow)!=null&&o.alignmentOffset)return{};const m=F(i),S=V(c),A=F(c)===c,E=await(f.isRTL==null?void 0:f.isRTL(a.floating)),O=w||(A||!v?[lt(c)]:ee(c)),y=p!=="none";!w&&y&&O.push(...se(c,v,p,E));const b=[c,...O],C=await Z(e,d),P=[];let h=((n=s.flip)==null?void 0:n.overflows)||[];if(u&&P.push(C[m]),l){const L=Ft(i,r,E);P.push(C[L[0]],C[L[1]])}if(h=[...h,{placement:i,overflows:P}],!P.every(L=>L<=0)){var R,D;const L=(((R=s.flip)==null?void 0:R.index)||0)+1,x=b[L];if(x&&(!(l==="alignment"?S!==V(x):!1)||h.every(B=>V(B.placement)===S?B.overflows[0]>0:!0)))return{data:{index:L,overflows:h},reset:{placement:x}};let $=(D=h.filter(T=>T.overflows[0]<=0).sort((T,B)=>T.overflows[1]-B.overflows[1])[0])==null?void 0:D.placement;if(!$)switch(g){case"bestFit":{var k;const T=(k=h.filter(B=>{if(y){const _=V(B.placement);return _===S||_==="y"}return!0}).map(B=>[B.placement,B.overflows.filter(_=>_>0).reduce((_,U)=>_+U,0)]).sort((B,_)=>B[1]-_[1])[0])==null?void 0:k[0];T&&($=T);break}case"initialPlacement":$=c;break}if(i!==$)return{reset:{placement:$}}}return{}}}};function Dt(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function Tt(t){return _t.some(e=>t[e]>=0)}const de=function(t){return t===void 0&&(t={}),{name:"hide",options:t,async fn(e){const{rects:o}=e,{strategy:n="referenceHidden",...i}=Y(t,e);switch(n){case"referenceHidden":{const s=await Z(e,{...i,elementContext:"reference"}),r=Dt(s,o.reference);return{data:{referenceHiddenOffsets:r,referenceHidden:Tt(r)}}}case"escaped":{const s=await Z(e,{...i,altBoundary:!0}),r=Dt(s,o.floating);return{data:{escapedOffsets:r,escaped:Tt(r)}}}default:return{}}}}};function qt(t){const e=j(...t.map(s=>s.left)),o=j(...t.map(s=>s.top)),n=M(...t.map(s=>s.right)),i=M(...t.map(s=>s.bottom));return{x:e,y:o,width:n-e,height:i-o}}function me(t){const e=t.slice().sort((i,s)=>i.y-s.y),o=[];let n=null;for(let i=0;i<e.length;i++){const s=e[i];!n||s.y-n.y>n.height/2?o.push([s]):o[o.length-1].push(s),n=s}return o.map(i=>Q(qt(i)))}const ge=function(t){return t===void 0&&(t={}),{name:"inline",options:t,async fn(e){const{placement:o,elements:n,rects:i,platform:s,strategy:r}=e,{padding:c=2,x:f,y:a}=Y(t,e),u=Array.from(await(s.getClientRects==null?void 0:s.getClientRects(n.reference))||[]),l=me(u),w=Q(qt(u)),g=yt(c);function p(){if(l.length===2&&l[0].left>l[1].right&&f!=null&&a!=null)return l.find(d=>f>d.left-g.left&&f<d.right+g.right&&a>d.top-g.top&&a<d.bottom+g.bottom)||w;if(l.length>=2){if(V(o)==="y"){const h=l[0],R=l[l.length-1],D=F(o)==="top",k=h.top,L=R.bottom,x=D?h.left:R.left,$=D?h.right:R.right,T=$-x,B=L-k;return{top:k,bottom:L,left:x,right:$,width:T,height:B,x,y:k}}const d=F(o)==="left",m=M(...l.map(h=>h.right)),S=j(...l.map(h=>h.left)),A=l.filter(h=>d?h.left===S:h.right===m),E=A[0].top,O=A[A.length-1].bottom,y=S,b=m,C=b-y,P=O-E;return{top:E,bottom:O,left:y,right:b,width:C,height:P,x:y,y:E}}return w}const v=await s.getElementRects({reference:{getBoundingClientRect:p},floating:n.floating,strategy:r});return i.reference.x!==v.reference.x||i.reference.y!==v.reference.y||i.reference.width!==v.reference.width||i.reference.height!==v.reference.height?{reset:{rects:v}}:{}}}},he=new Set(["left","top"]);async function pe(t,e){const{placement:o,platform:n,elements:i}=t,s=await(n.isRTL==null?void 0:n.isRTL(i.floating)),r=F(o),c=q(o),f=V(o)==="y",a=he.has(r)?-1:1,u=s&&f?-1:1,l=Y(e,t);let{mainAxis:w,crossAxis:g,alignmentAxis:p}=typeof l=="number"?{mainAxis:l,crossAxis:0,alignmentAxis:null}:{mainAxis:l.mainAxis||0,crossAxis:l.crossAxis||0,alignmentAxis:l.alignmentAxis};return c&&typeof p=="number"&&(g=c==="end"?p*-1:p),f?{x:g*u,y:w*a}:{x:w*a,y:g*u}}const we=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var o,n;const{x:i,y:s,placement:r,middlewareData:c}=e,f=await pe(e,t);return r===((o=c.offset)==null?void 0:o.placement)&&(n=c.arrow)!=null&&n.alignmentOffset?{}:{x:i+f.x,y:s+f.y,data:{...f,placement:r}}}}},xe=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){const{x:o,y:n,placement:i}=e,{mainAxis:s=!0,crossAxis:r=!1,limiter:c={fn:d=>{let{x:m,y:S}=d;return{x:m,y:S}}},...f}=Y(t,e),a={x:o,y:n},u=await Z(e,f),l=V(F(i)),w=Nt(l);let g=a[w],p=a[l];if(s){const d=w==="y"?"top":"left",m=w==="y"?"bottom":"right",S=g+u[d],A=g-u[m];g=ht(S,g,A)}if(r){const d=l==="y"?"top":"left",m=l==="y"?"bottom":"right",S=p+u[d],A=p-u[m];p=ht(S,p,A)}const v=c.fn({...e,[w]:g,[l]:p});return{...v,data:{x:v.x-o,y:v.y-n,enabled:{[w]:s,[l]:r}}}}}},ye=function(t){return t===void 0&&(t={}),{name:"size",options:t,async fn(e){var o,n;const{placement:i,rects:s,platform:r,elements:c}=e,{apply:f=()=>{},...a}=Y(t,e),u=await Z(e,a),l=F(i),w=q(i),g=V(i)==="y",{width:p,height:v}=s.floating;let d,m;l==="top"||l==="bottom"?(d=l,m=w===(await(r.isRTL==null?void 0:r.isRTL(c.floating))?"start":"end")?"left":"right"):(m=l,d=w==="end"?"top":"bottom");const S=v-u.top-u.bottom,A=p-u.left-u.right,E=j(v-u[d],S),O=j(p-u[m],A),y=!e.middlewareData.shift;let b=E,C=O;if((o=e.middlewareData.shift)!=null&&o.enabled.x&&(C=A),(n=e.middlewareData.shift)!=null&&n.enabled.y&&(b=S),y&&!w){const h=M(u.left,0),R=M(u.right,0),D=M(u.top,0),k=M(u.bottom,0);g?C=p-2*(h!==0||R!==0?h+R:M(u.left,u.right)):b=v-2*(D!==0||k!==0?D+k:M(u.top,u.bottom))}await f({...e,availableWidth:C,availableHeight:b});const P=await r.getDimensions(c.floating);return p!==P.width||v!==P.height?{reset:{rects:!0}}:{}}}};function at(){return typeof window<"u"}function et(t){return It(t)?(t.nodeName||"").toLowerCase():"#document"}function N(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function z(t){var e;return(e=(It(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function It(t){return at()?t instanceof Node||t instanceof N(t).Node:!1}function I(t){return at()?t instanceof Element||t instanceof N(t).Element:!1}function X(t){return at()?t instanceof HTMLElement||t instanceof N(t).HTMLElement:!1}function Lt(t){return!at()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof N(t).ShadowRoot}const ve=new Set(["inline","contents"]);function it(t){const{overflow:e,overflowX:o,overflowY:n,display:i}=W(t);return/auto|scroll|overlay|hidden|clip/.test(e+n+o)&&!ve.has(i)}const be=new Set(["table","td","th"]);function Se(t){return be.has(et(t))}const Re=[":popover-open",":modal"];function ft(t){return Re.some(e=>{try{return t.matches(e)}catch{return!1}})}const Ae=["transform","translate","scale","rotate","perspective"],Oe=["transform","translate","scale","rotate","perspective","filter"],Ce=["paint","layout","strict","content"];function vt(t){const e=bt(),o=I(t)?W(t):t;return Ae.some(n=>o[n]?o[n]!=="none":!1)||(o.containerType?o.containerType!=="normal":!1)||!e&&(o.backdropFilter?o.backdropFilter!=="none":!1)||!e&&(o.filter?o.filter!=="none":!1)||Oe.some(n=>(o.willChange||"").includes(n))||Ce.some(n=>(o.contain||"").includes(n))}function Pe(t){let e=K(t);for(;X(e)&&!tt(e);){if(vt(e))return e;if(ft(e))return null;e=K(e)}return null}function bt(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Ee=new Set(["html","body","#document"]);function tt(t){return Ee.has(et(t))}function W(t){return N(t).getComputedStyle(t)}function ut(t){return I(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function K(t){if(et(t)==="html")return t;const e=t.assignedSlot||t.parentNode||Lt(t)&&t.host||z(t);return Lt(e)?e.host:e}function Wt(t){const e=K(t);return tt(e)?t.ownerDocument?t.ownerDocument.body:t.body:X(e)&&it(e)?e:Wt(e)}function Vt(t,e,o){var n;e===void 0&&(e=[]);const i=Wt(t),s=i===((n=t.ownerDocument)==null?void 0:n.body),r=N(i);return s?(pt(r),e.concat(r,r.visualViewport||[],it(i)?i:[],[])):e.concat(i,Vt(i,[]))}function pt(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function Ht(t){const e=W(t);let o=parseFloat(e.width)||0,n=parseFloat(e.height)||0;const i=X(t),s=i?t.offsetWidth:o,r=i?t.offsetHeight:n,c=rt(o)!==s||rt(n)!==r;return c&&(o=s,n=r),{width:o,height:n,$:c}}function jt(t){return I(t)?t:t.contextElement}function J(t){const e=jt(t);if(!X(e))return H(1);const o=e.getBoundingClientRect(),{width:n,height:i,$:s}=Ht(e);let r=(s?rt(o.width):o.width)/n,c=(s?rt(o.height):o.height)/i;return(!r||!Number.isFinite(r))&&(r=1),(!c||!Number.isFinite(c))&&(c=1),{x:r,y:c}}const De=H(0);function Xt(t){const e=N(t);return!bt()||!e.visualViewport?De:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function Te(t,e,o){return e===void 0&&(e=!1),!o||e&&o!==N(t)?!1:e}function ot(t,e,o,n){e===void 0&&(e=!1),o===void 0&&(o=!1);const i=t.getBoundingClientRect(),s=jt(t);let r=H(1);e&&(n?I(n)&&(r=J(n)):r=J(t));const c=Te(s,o,n)?Xt(s):H(0);let f=(i.left+c.x)/r.x,a=(i.top+c.y)/r.y,u=i.width/r.x,l=i.height/r.y;if(s){const w=N(s),g=n&&I(n)?N(n):n;let p=w,v=pt(p);for(;v&&n&&g!==p;){const d=J(v),m=v.getBoundingClientRect(),S=W(v),A=m.left+(v.clientLeft+parseFloat(S.paddingLeft))*d.x,E=m.top+(v.clientTop+parseFloat(S.paddingTop))*d.y;f*=d.x,a*=d.y,u*=d.x,l*=d.y,f+=A,a+=E,p=N(v),v=pt(p)}}return Q({width:u,height:l,x:f,y:a})}function dt(t,e){const o=ut(t).scrollLeft;return e?e.left+o:ot(z(t)).left+o}function Yt(t,e){const o=t.getBoundingClientRect(),n=o.left+e.scrollLeft-dt(t,o),i=o.top+e.scrollTop;return{x:n,y:i}}function Le(t){let{elements:e,rect:o,offsetParent:n,strategy:i}=t;const s=i==="fixed",r=z(n),c=e?ft(e.floating):!1;if(n===r||c&&s)return o;let f={scrollLeft:0,scrollTop:0},a=H(1);const u=H(0),l=X(n);if((l||!l&&!s)&&((et(n)!=="body"||it(r))&&(f=ut(n)),X(n))){const g=ot(n);a=J(n),u.x=g.x+n.clientLeft,u.y=g.y+n.clientTop}const w=r&&!l&&!s?Yt(r,f):H(0);return{width:o.width*a.x,height:o.height*a.y,x:o.x*a.x-f.scrollLeft*a.x+u.x+w.x,y:o.y*a.y-f.scrollTop*a.y+u.y+w.y}}function $e(t){return Array.from(t.getClientRects())}function ke(t){const e=z(t),o=ut(t),n=t.ownerDocument.body,i=M(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),s=M(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight);let r=-o.scrollLeft+dt(t);const c=-o.scrollTop;return W(n).direction==="rtl"&&(r+=M(e.clientWidth,n.clientWidth)-i),{width:i,height:s,x:r,y:c}}const $t=25;function Be(t,e){const o=N(t),n=z(t),i=o.visualViewport;let s=n.clientWidth,r=n.clientHeight,c=0,f=0;if(i){s=i.width,r=i.height;const u=bt();(!u||u&&e==="fixed")&&(c=i.offsetLeft,f=i.offsetTop)}const a=dt(n);if(a<=0){const u=n.ownerDocument,l=u.body,w=getComputedStyle(l),g=u.compatMode==="CSS1Compat"&&parseFloat(w.marginLeft)+parseFloat(w.marginRight)||0,p=Math.abs(n.clientWidth-l.clientWidth-g);p<=$t&&(s-=p)}else a<=$t&&(s+=a);return{width:s,height:r,x:c,y:f}}const Me=new Set(["absolute","fixed"]);function _e(t,e){const o=ot(t,!0,e==="fixed"),n=o.top+t.clientTop,i=o.left+t.clientLeft,s=X(t)?J(t):H(1),r=t.clientWidth*s.x,c=t.clientHeight*s.y,f=i*s.x,a=n*s.y;return{width:r,height:c,x:f,y:a}}function kt(t,e,o){let n;if(e==="viewport")n=Be(t,o);else if(e==="document")n=ke(z(t));else if(I(e))n=_e(e,o);else{const i=Xt(t);n={x:e.x-i.x,y:e.y-i.y,width:e.width,height:e.height}}return Q(n)}function zt(t,e){const o=K(t);return o===e||!I(o)||tt(o)?!1:W(o).position==="fixed"||zt(o,e)}function Ne(t,e){const o=e.get(t);if(o)return o;let n=Vt(t,[]).filter(c=>I(c)&&et(c)!=="body"),i=null;const s=W(t).position==="fixed";let r=s?K(t):t;for(;I(r)&&!tt(r);){const c=W(r),f=vt(r);!f&&c.position==="fixed"&&(i=null),(s?!f&&!i:!f&&c.position==="static"&&!!i&&Me.has(i.position)||it(r)&&!f&&zt(t,r))?n=n.filter(u=>u!==r):i=c,r=K(r)}return e.set(t,n),n}function Fe(t){let{element:e,boundary:o,rootBoundary:n,strategy:i}=t;const r=[...o==="clippingAncestors"?ft(e)?[]:Ne(e,this._c):[].concat(o),n],c=r[0],f=r.reduce((a,u)=>{const l=kt(e,u,i);return a.top=M(l.top,a.top),a.right=j(l.right,a.right),a.bottom=j(l.bottom,a.bottom),a.left=M(l.left,a.left),a},kt(e,c,i));return{width:f.right-f.left,height:f.bottom-f.top,x:f.left,y:f.top}}function qe(t){const{width:e,height:o}=Ht(t);return{width:e,height:o}}function Ie(t,e,o){const n=X(e),i=z(e),s=o==="fixed",r=ot(t,!0,s,e);let c={scrollLeft:0,scrollTop:0};const f=H(0);function a(){f.x=dt(i)}if(n||!n&&!s)if((et(e)!=="body"||it(i))&&(c=ut(e)),n){const g=ot(e,!0,s,e);f.x=g.x+e.clientLeft,f.y=g.y+e.clientTop}else i&&a();s&&!n&&i&&a();const u=i&&!n&&!s?Yt(i,c):H(0),l=r.left+c.scrollLeft-f.x-u.x,w=r.top+c.scrollTop-f.y-u.y;return{x:l,y:w,width:r.width,height:r.height}}function gt(t){return W(t).position==="static"}function Bt(t,e){if(!X(t)||W(t).position==="fixed")return null;if(e)return e(t);let o=t.offsetParent;return z(t)===o&&(o=o.ownerDocument.body),o}function Kt(t,e){const o=N(t);if(ft(t))return o;if(!X(t)){let i=K(t);for(;i&&!tt(i);){if(I(i)&&!gt(i))return i;i=K(i)}return o}let n=Bt(t,e);for(;n&&Se(n)&>(n);)n=Bt(n,e);return n&&tt(n)&>(n)&&!vt(n)?o:n||Pe(t)||o}const We=async function(t){const e=this.getOffsetParent||Kt,o=this.getDimensions,n=await o(t.floating);return{reference:Ie(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:n.width,height:n.height}}};function Ve(t){return W(t).direction==="rtl"}const He={convertOffsetParentRelativeRectToViewportRelativeRect:Le,getDocumentElement:z,getClippingRect:Fe,getOffsetParent:Kt,getElementRects:We,getClientRects:$e,getDimensions:qe,getScale:J,isElement:I,isRTL:Ve},je=we,Xe=fe,Ye=xe,ze=ue,Ke=ye,Ue=de,Ge=le,Je=ge,Qe=(t,e,o)=>{const n=new Map,i={platform:He,...o},s={...i.platform,_c:n};return ce(t,e,{...i,platform:s})};function Ze(t){var e;const{char:o,allowSpaces:n,allowToIncludeChar:i,allowedPrefixes:s,startOfLine:r,$position:c}=t,f=n&&!i,a=Jt.escapeForRegEx(o),u=new RegExp(`\\s${a}$`),l=r?"^":"",w=i?"":a,g=f?new RegExp(`${l}${a}.*?(?=\\s${w}|$)`,"gm"):new RegExp(`${l}(?:^)?${a}[^\\s${w}]*`,"gm"),p=((e=c.nodeBefore)==null?void 0:e.isText)&&c.nodeBefore.text;if(!p)return null;const v=c.pos-p.length,d=Array.from(p.matchAll(g)).pop();if(!d||d.input===void 0||d.index===void 0)return null;const m=d.input.slice(Math.max(0,d.index-1),d.index),S=new RegExp(`^[${s==null?void 0:s.join("")}\0]?$`).test(m);if(s!==null&&!S)return null;const A=v+d.index;let E=A+d[0].length;return f&&u.test(p.slice(E-1,E+1))&&(d[0]+=" ",E+=1),A<c.pos&&E>=c.pos?{range:{from:A,to:E},query:d[0].slice(o.length),text:d[0]}:null}var tn=new Mt.PluginKey("suggestion");function Ut({pluginKey:t=tn,editor:e,char:o="@",allowSpaces:n=!1,allowToIncludeChar:i=!1,allowedPrefixes:s=[" "],startOfLine:r=!1,decorationTag:c="span",decorationClass:f="suggestion",decorationContent:a="",decorationEmptyClass:u="is-empty",command:l=()=>null,items:w=()=>[],render:g=()=>({}),allow:p=()=>!0,findSuggestionMatch:v=Ze}){let d;const m=g==null?void 0:g(),S=()=>{const y=e.state.selection.$anchor.pos,b=e.view.coordsAtPos(y),{top:C,right:P,bottom:h,left:R}=b;try{return new DOMRect(R,C,P-R,h-C)}catch{return null}},A=(y,b)=>b?()=>{const C=t.getState(e.state),P=C==null?void 0:C.decorationId,h=y.dom.querySelector(`[data-decoration-id="${P}"]`);return(h==null?void 0:h.getBoundingClientRect())||null}:S;function E(y,b){var C;try{const h=t.getState(y.state),R=h!=null&&h.decorationId?y.dom.querySelector(`[data-decoration-id="${h.decorationId}"]`):null,D={editor:e,range:(h==null?void 0:h.range)||{from:0,to:0},query:(h==null?void 0:h.query)||null,text:(h==null?void 0:h.text)||null,items:[],command:k=>l({editor:e,range:(h==null?void 0:h.range)||{from:0,to:0},props:k}),decorationNode:R,clientRect:A(y,R)};(C=m==null?void 0:m.onExit)==null||C.call(m,D)}catch{}const P=y.state.tr.setMeta(b,{exit:!0});y.dispatch(P)}const O=new Mt.Plugin({key:t,view(){return{update:async(y,b)=>{var C,P,h,R,D,k,L;const x=(C=this.key)==null?void 0:C.getState(b),$=(P=this.key)==null?void 0:P.getState(y.state),T=x.active&&$.active&&x.range.from!==$.range.from,B=!x.active&&$.active,_=x.active&&!$.active,U=!B&&!_&&x.query!==$.query,nt=B||T&&U,st=U||T,mt=_||T&&U;if(!nt&&!st&&!mt)return;const G=mt&&!nt?x:$,St=y.dom.querySelector(`[data-decoration-id="${G.decorationId}"]`);d={editor:e,range:G.range,query:G.query,text:G.text,items:[],command:Gt=>l({editor:e,range:G.range,props:Gt}),decorationNode:St,clientRect:A(y,St)},nt&&((h=m==null?void 0:m.onBeforeStart)==null||h.call(m,d)),st&&((R=m==null?void 0:m.onBeforeUpdate)==null||R.call(m,d)),(st||nt)&&(d.items=await w({editor:e,query:G.query})),mt&&((D=m==null?void 0:m.onExit)==null||D.call(m,d)),st&&((k=m==null?void 0:m.onUpdate)==null||k.call(m,d)),nt&&((L=m==null?void 0:m.onStart)==null||L.call(m,d))},destroy:()=>{var y;d&&((y=m==null?void 0:m.onExit)==null||y.call(m,d))}}},state:{init(){return{active:!1,range:{from:0,to:0},query:null,text:null,composing:!1}},apply(y,b,C,P){const{isEditable:h}=e,{composing:R}=e.view,{selection:D}=y,{empty:k,from:L}=D,x={...b},$=y.getMeta(t);if($&&$.exit)return x.active=!1,x.decorationId=null,x.range={from:0,to:0},x.query=null,x.text=null,x;if(x.composing=R,h&&(k||e.view.composing)){(L<b.range.from||L>b.range.to)&&!R&&!b.composing&&(x.active=!1);const T=v({char:o,allowSpaces:n,allowToIncludeChar:i,allowedPrefixes:s,startOfLine:r,$position:D.$from}),B=`id_${Math.floor(Math.random()*4294967295)}`;T&&p({editor:e,state:P,range:T.range,isActive:b.active})?(x.active=!0,x.decorationId=b.decorationId?b.decorationId:B,x.range=T.range,x.query=T.query,x.text=T.text):x.active=!1}else x.active=!1;return x.active||(x.decorationId=null,x.range={from:0,to:0},x.query=null,x.text=null),x}},props:{handleKeyDown(y,b){var C,P,h,R;const{active:D,range:k}=O.getState(y.state);if(!D)return!1;if(b.key==="Escape"||b.key==="Esc"){const x=O.getState(y.state),$=(C=d==null?void 0:d.decorationNode)!=null?C:null,T=$??(x!=null&&x.decorationId?y.dom.querySelector(`[data-decoration-id="${x.decorationId}"]`):null);if(((P=m==null?void 0:m.onKeyDown)==null?void 0:P.call(m,{view:y,event:b,range:x.range}))||!1)return!0;const _={editor:e,range:x.range,query:x.query,text:x.text,items:[],command:U=>l({editor:e,range:x.range,props:U}),decorationNode:T,clientRect:T?()=>T.getBoundingClientRect()||null:null};return(h=m==null?void 0:m.onExit)==null||h.call(m,_),E(y,t),!0}return((R=m==null?void 0:m.onKeyDown)==null?void 0:R.call(m,{view:y,event:b,range:k}))||!1},decorations(y){const{active:b,range:C,decorationId:P,query:h}=O.getState(y);if(!b)return null;const R=!(h!=null&&h.length),D=[f];return R&&D.push(u),Rt.DecorationSet.create(y.doc,[Rt.Decoration.inline(C.from,C.to,{nodeName:c,class:D.join(" "),"data-decoration-id":P,"data-decoration-content":a})])}}});return O}var en=Ut;exports.Suggestion=Ut;exports.arrow=Ge;exports.autoPlacement=Xe;exports.computePosition=Qe;exports.flip=ze;exports.hide=Ue;exports.index_default=en;exports.inline=Je;exports.offset=je;exports.shift=Ye;exports.size=Ke;