import{s as y}from"./chunk-LvLJmgfZ.js";import{t as T}from"./react-Bj1aDYRI.js";import{Mt as L,Nt as C,Pt as x,T as j,p as F}from"./cells-CCtxWKxf.js";import{t as b}from"./compiler-runtime-B3qBwwSJ.js";import{t as H}from"./useLifecycle-BDXC6oVR.js";import{t as K}from"./jsx-runtime-CP2fAiZX.js";import{r as E}from"./button-BmOH9agK.js";import{t as w}from"./cn-d_A4rA-x.js";import{r as k}from"./input-BPldEXfy.js";import{r as M}from"./dist-51xFOPFs.js";import{r as D}from"./useTheme-CwdqVOYu.js";import{t as I}from"./tooltip-DOQlecCr.js";import{r as P,t as R}from"./esm-BQUzYly2.js";var W=b(),p=y(T(),1),d=y(K(),1),_=[M(),P({syntaxHighlighting:!0,highlightSpecialChars:!1,history:!1,drawSelection:!1,defaultKeymap:!1,historyKeymap:!1})];const N=(0,p.memo)(s=>{let e=(0,W.c)(8),{code:r,className:a}=s,{theme:i}=D(),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=i==="dark"?"dark":"light",t;e[2]!==r||e[3]!==l?(t=(0,d.jsx)(R,{minHeight:"10px",theme:l,height:"100%",className:"tiny-code",editable:!1,basicSetup:!1,extensions:_,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,d.jsx)("div",{className:o,children:t}),e[5]=o,e[6]=t,e[7]=n):n=e[7],n});N.displayName="TinyCode";var B=b();const q=s=>{let e=(0,B.c)(16),r,a,i,o,l;e[0]===s?(r=e[1],a=e[2],i=e[3],o=e[4],l=e[5]):({value:l,onChange:r,placeholder:i,onEnterKey:a,...o}=s,e[0]=s,e[1]=r,e[2]=a,e[3]=i,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 f=n.onBlur,v=t.current;if(v)return v.addEventListener("blur",f),()=>{v.removeEventListener("blur",f)}},e[6]=n.onBlur,e[7]=u),H(u);let m=n.value,g=n.onChange,c;e[8]===a?c=e[9]:(c=E.onEnter(f=>{E.stopPropagation()(f),a==null||a()}),e[8]=a,e[9]=c);let h;return e[10]!==n.onChange||e[11]!==n.value||e[12]!==i||e[13]!==o||e[14]!==c?(h=(0,d.jsx)(k,{"data-testid":"cell-name-input",value:m,onChange:g,ref:t,placeholder:i,className:"shadow-none! hover:shadow-none focus:shadow-none focus-visible:shadow-none",onKeyDown:c,...o}),e[10]=n.onChange,e[11]=n.value,e[12]=i,e[13]=o,e[14]=c,e[15]=h):h=e[15],h},z=s=>{let e=(0,B.c)(12),{value:r,cellId:a,className:i}=s,{updateCellName:o}=j(),l;e[0]!==a||e[1]!==o?(l=g=>o({cellId:a,name:g}),e[0]=a,e[1]=o,e[2]=l):l=e[2];let t=S(r,l);if(C(r))return null;let n=t.focusing?"":"text-ellipsis",u;e[3]!==i||e[4]!==n?(u=w("outline-hidden border hover:border-cyan-500/40 focus:border-cyan-500/40",n,i),e[3]=i,e[4]=n,e[5]=u):u=e[5];let m;return e[6]!==t.onBlur||e[7]!==t.onChange||e[8]!==t.onFocus||e[9]!==u||e[10]!==r?(m=(0,d.jsx)(I,{content:"Click to rename",children:(0,d.jsx)("span",{className:u,contentEditable:!0,suppressContentEditableWarning:!0,onChange:t.onChange,onBlur:t.onBlur,onFocus:t.onFocus,onKeyDown:A,children:r})}),e[6]=t.onBlur,e[7]=t.onChange,e[8]=t.onFocus,e[9]=u,e[10]=r,e[11]=m):m=e[11],m};function S(s,e){let[r,a]=(0,p.useState)(s),[i,o]=(0,p.useState)(!1),l=t=>{if(t!==s){if(!t||C(t)){e(t);return}e(L(t,F()))}};return{value:C(r)?"":r,focusing:i,onChange:t=>{let n=t.target.value;a(x(n))},onBlur:t=>{if(t.target instanceof HTMLInputElement){let n=t.target.value;l(x(n))}else t.target instanceof HTMLSpanElement&&(l(x(t.target.innerText.trim())),t.target.scrollLeft=0,o(!1))},onFocus:()=>{o(!0)}}}function A(s){s.stopPropagation(),s.key==="Enter"&&s.target instanceof HTMLElement&&s.target.blur()}export{q as n,N as r,z as t};
