import{s as g}from"./chunk-DZLz74EQ.js";import{t as L}from"./react-BcIddLXZ.js";import{E as T,ht as C,m as j,mt as x,pt as F}from"./cells-B6jS0AIj.js";import{n as E,t as H}from"./jsx-runtime-DvsdsEjx.js";import{t as w}from"./cn-C5VTNYKf.js";import{r as b}from"./button-nRVaalxL.js";import{r as K}from"./dist-ClBFnEcy.js";import{r as _}from"./useTheme-BMknLtnH.js";import{r as k}from"./input-BPw9p_8N.js";import{t as D}from"./tooltip-BQKXsEoT.js";import{t as I}from"./useLifecycle-CuZnZLRp.js";import{r as M,t as P}from"./esm-ChGlv0th.js";var R=g(E(),1),p=g(L(),1),f=g(H(),1),W=[K(),M({syntaxHighlighting:!0,highlightSpecialChars:!1,history:!1,drawSelection:!1,defaultKeymap:!1,historyKeymap:!1})];const B=(0,p.memo)(i=>{let e=(0,R.c)(8),{code:r,className:a}=i,{theme:s}=_(),o;e[0]===a?o=e[1]:(o=w(a,"text-muted-foreground flex flex-col overflow-hidden"),e[0]=a,e[1]=o);let l=s==="dark"?"dark":"light",t;e[2]!==r||e[3]!==l?(t=(0,f.jsx)(P,{minHeight:"10px",theme:l,height:"100%",className:"tiny-code",editable:!1,basicSetup:!1,extensions:W,value:r}),e[2]=r,e[3]=l,e[4]=t):t=e[4];let n;return e[5]!==o||e[6]!==t?(n=(0,f.jsx)("div",{className:o,children:t}),e[5]=o,e[6]=t,e[7]=n):n=e[7],n});B.displayName="TinyCode";var N=g(E(),1);const q=i=>{let e=(0,N.c)(16),r,a,s,o,l;e[0]===i?(r=e[1],a=e[2],s=e[3],o=e[4],l=e[5]):({value:l,onChange:r,placeholder:s,onEnterKey:a,...o}=i,e[0]=i,e[1]=r,e[2]=a,e[3]=s,e[4]=o,e[5]=l);let t=(0,p.useRef)(null),n=S(l,r),u;e[6]===n.onBlur?u=e[7]:(u=()=>{let m=n.onBlur,d=t.current;if(d)return d.addEventListener("blur",m),()=>{d.removeEventListener("blur",m)}},e[6]=n.onBlur,e[7]=u),I(u);let v=n.value,y=n.onChange,h;e[8]===a?h=e[9]:(h=b.onEnter(m=>{b.stopPropagation()(m),a==null||a()}),e[8]=a,e[9]=h);let c;return e[10]!==n.onChange||e[11]!==n.value||e[12]!==s||e[13]!==o||e[14]!==h?(c=(0,f.jsx)(k,{"data-testid":"cell-name-input",value:v,onChange:y,ref:t,placeholder:s,className:"shadow-none! hover:shadow-none focus:shadow-none focus-visible:shadow-none",onKeyDown:h,...o}),e[10]=n.onChange,e[11]=n.value,e[12]=s,e[13]=o,e[14]=h,e[15]=c):c=e[15],c},z=i=>{let e=(0,N.c)(13),{value:r,cellId:a,className:s}=i,{updateCellName:o}=T(),l;e[0]!==a||e[1]!==o?(l=d=>o({cellId:a,name:d}),e[0]=a,e[1]=o,e[2]=l):l=e[2];let t=S(r,l);if(x(r))return null;let n=t.focusing?"":"text-ellipsis",u;e[3]!==s||e[4]!==n?(u=w("outline-hidden border hover:border-cyan-500/40 focus:border-cyan-500/40",n,s),e[3]=s,e[4]=n,e[5]=u):u=e[5];let v=t.onChange,y=t.onBlur,h=t.onFocus,c;e[6]===Symbol.for("react.memo_cache_sentinel")?(c=b.onEnter(A),e[6]=c):c=e[6];let m;return e[7]!==t.onBlur||e[8]!==t.onChange||e[9]!==t.onFocus||e[10]!==u||e[11]!==r?(m=(0,f.jsx)(D,{content:"Click to rename",children:(0,f.jsx)("span",{className:u,contentEditable:!0,suppressContentEditableWarning:!0,onChange:v,onBlur:y,onFocus:h,onKeyDown:c,children:r})}),e[7]=t.onBlur,e[8]=t.onChange,e[9]=t.onFocus,e[10]=u,e[11]=r,e[12]=m):m=e[12],m};function S(i,e){let[r,a]=(0,p.useState)(i),[s,o]=(0,p.useState)(!1),l=t=>{if(t!==i){if(!t||x(t)){e(t);return}e(F(t,j()))}};return{value:x(r)?"":r,focusing:s,onChange:t=>{let n=t.target.value;a(C(n))},onBlur:t=>{if(t.target instanceof HTMLInputElement){let n=t.target.value;l(C(n))}else t.target instanceof HTMLSpanElement&&(l(C(t.target.innerText.trim())),t.target.scrollLeft=0,o(!1))},onFocus:()=>{o(!0)}}}function A(i){i.target instanceof HTMLElement&&i.target.blur()}export{q as n,B as r,z as t};
