"use strict";const b=require("./jsx-runtime-nZSsnGb7.cjs"),c=require("react");require("@synnaxlabs/x");const l=require("./css-CloSmhZB.cjs"),m=require("./types-DI2vtOGs.cjs"),K=require("./Box-CNUz5BsV.cjs"),$=e=>{const t=c.useRef(m.executeInitialSetter(e)),n=c.useCallback(s=>{t.current=m.executeSetter(s,t.current)},[]);return[t,n]},I=e=>{const t=c.useRef(e);return t.current=e,t},U=e=>{const t=c.useRef(!1),n=c.useRef(null);return t.current||(n.current=e(),t.current=!0),n},N=(...e)=>c.useCallback(t=>e.forEach(n=>{n!=null&&(typeof n=="function"?n(t):n.current=t)},t),[]),W=e=>{const t=c.useRef(null),[n,s]=c.useState(()=>{const o=m.executeInitialSetter(e);return t.current=o,o}),u=c.useCallback(o=>{s(f=>(t.current=m.executeSetter(o,f),t.current))},[]);return[n,u,t]},O=e=>{const t=c.useRef(void 0),n=t.current;return t.current=e,n},X=e=>c.isValidElement(e)&&!("hydrate"in e.props),k="://",G=`https${k}`,Y=(e,t=!1)=>e==null?e:t&&!e.includes(k)?G+e:e,B=e=>{if(c.Children.count(e)!==1){const t=c.Children.toArray(e).filter(n=>typeof n!="boolean");if(t.length!==1)return!1;e=t[0]}return typeof e=="string"?e.length===1:!!(X(e)&&typeof e.props=="object"&&e.props!=null&&!("children"in e.props)&&!("role"in e.props))},F=(e,t,n,s,u)=>t??(u!=null||s==="link"?"a":n??e??"p"),J=(e,t,n)=>{const s={...e,fontWeight:t};return n!=null&&(s.WebkitLineClamp=n),s},g=({level:e="p",className:t,style:n,weight:s,defaultEl:u,el:o,variant:f,overflow:E,href:x,autoFormatHref:C,status:a,lineClamp:S,...i})=>b.jsxRuntimeExports.jsx(K.Box$1,{direction:"x",el:F(e,o,u,f,x),style:J(n,s,S),className:l.CSS(l.CSS.B("text"),f!=null&&l.CSS.BM("text",f),l.CSS.BM("text",e),E!=null&&l.CSS.BM("text","overflow",E),S!=null&&l.CSS.BM("text","line-clamp"),a!=null&&l.CSS.M("status",a),t),square:B(i.children),gap:"small",href:Y(x,C),...i}),R=e=>{e!=null&&(e.style.display="none",e.offsetHeight,e.style.display="")},Q=["Escape","Enter"],w=l.CSS.BM("text","editable"),Z=10,j="renamed",q="escaped",D="start-editing",L=(e,t)=>{let n=0;const s=()=>{n++;const u=document.querySelector(`#${CSS.escape(e)}.${w}`);if(u==null||!u.classList.contains(w)){if(n<Z)setTimeout(()=>s(),100);else throw new Error(`Could not find element with id ${e}`);return}u.dispatchEvent(new Event(D)),u.setAttribute("contenteditable","true"),t!=null&&(u.addEventListener(j,o=>t(T(o.target),!0)),u.addEventListener(q,o=>t(T(o.target),!1)))};s()},ee=e=>new Promise(t=>{L(e,(s,u)=>t([s,u]))}),T=e=>e.innerText.trim(),te=(e,t)=>e==null||t==null?!1:e.maxInlineSize===t.maxInlineSize,h=({onChange:e,value:t,className:n,useEditableState:s=c.useState,allowDoubleClick:u=!0,onDoubleClick:o,allowEmpty:f=!1,style:E,outline:x=!0,...C})=>{const[a,S]=s(!1),i=c.useRef(null),M=I(t),y=c.useRef(E),A=c.useRef(t);(y.current!=null&&!te(E,y.current)||t!==A.current)&&(R(i.current),y.current=E,A.current=t);const P=r=>{u&&(S(!0),R(i.current)),o?.(r)},_=(r,p=!1)=>{const d=T(r);M.current===d&&(d.length>0||f)||(p||d.length===0&&!f?(r.innerText=t,r.dispatchEvent(new Event(q))):(e?.(d),M.current=d,r.dispatchEvent(new Event(j))))},V=r=>{if(i.current==null||(R(i.current),!a||!Q.includes(r.key)))return;r.stopPropagation(),r.preventDefault();const p=i.current;i.current!=null&&(S(!1),_(p,r.key==="Escape"),p.blur())},H=r=>r.preventDefault();c.useLayoutEffect(()=>{if(i.current==null||!a)return;R(i.current);const{current:r}=i;r.focus();const p=document.createRange();p.selectNodeContents(r);const d=window.getSelection();d?.removeAllRanges(),d?.addRange(p)},[a]),i.current!==null&&!a&&(i.current.innerHTML=t);const v=c.useCallback(r=>{r?.addEventListener(D,()=>S(!0))},[]),z=N(i,v);return b.jsxRuntimeExports.jsx(g,{ref:z,className:l.CSS(n,l.CSS.BM("text","editable"),x&&l.CSS.M("outline")),onBlur:()=>{S(!1);const r=i.current;r!=null&&_(r)},onKeyDown:V,onKeyUp:H,onDoubleClick:P,contentEditable:a,suppressContentEditableWarning:!0,style:E,...C,children:t})},ne=({onChange:e,disabled:t=!1,value:n,allowDoubleClick:s,...u})=>t||e==null||e===!1?b.jsxRuntimeExports.jsx(g,{...u,children:n}):(e===!0&&(e=()=>{}),b.jsxRuntimeExports.jsx(h,{allowDoubleClick:s,onChange:e,value:n,...u}));exports.Editable=h;exports.MaybeEditable=ne;exports.Text=g;exports.asyncEdit=ee;exports.edit=L;exports.isSquare=B;exports.triggerReflow=R;exports.useCombinedRefs=N;exports.useCombinedStateAndRef=W;exports.useInitializerRef=U;exports.usePrevious=O;exports.useStateRef=$;exports.useSyncedRef=I;
