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