import{s as y}from"./chunk-LvLJmgfZ.js";import{t as j}from"./react-Bj1aDYRI.js";import{At as L,E as T,Mt as C,f as F,jt as x}from"./cells-CJLUCcQg.js";import{t as b}from"./compiler-runtime-B3qBwwSJ.js";import{t as E}from"./cn-DYvqRARy.js";import{t as H}from"./jsx-runtime-Blw4afVn.js";import{t as K}from"./tooltip-4bZlU7jl.js";import{r as w}from"./button-DDGiD1NW.js";import{t as k}from"./useLifecycle-lLOBhc-1.js";import{r as M}from"./input-JxFwu-3G.js";import{r as D}from"./dist-CPjTeT8p.js";import{r as I}from"./useTheme-Bxv9B31g.js";import{r as P,t as A}from"./esm-B30N1GS0.js";var R=b(),p=y(j(),1),d=y(H(),1),W=[D(),P({syntaxHighlighting:!0,highlightSpecialChars:!1,history:!1,drawSelection:!1,defaultKeymap:!1,historyKeymap:!1})];const B=(0,p.memo)(s=>{let e=(0,R.c)(8),{code:r,className:a}=s,{theme:i}=I(),o;e[0]===a?o=e[1]:(o=E(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)(A,{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,d.jsx)("div",{className:o,children:t}),e[5]=o,e[6]=t,e[7]=n):n=e[7],n});B.displayName="TinyCode";var N=b();const _=s=>{let e=(0,N.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 h=n.onBlur,v=t.current;if(v)return v.addEventListener("blur",h),()=>{v.removeEventListener("blur",h)}},e[6]=n.onBlur,e[7]=u),k(u);let m=n.value,g=n.onChange,c;e[8]===a?c=e[9]:(c=w.onEnter(h=>{w.stopPropagation()(h),a==null||a()}),e[8]=a,e[9]=c);let f;return e[10]!==n.onChange||e[11]!==n.value||e[12]!==i||e[13]!==o||e[14]!==c?(f=(0,d.jsx)(M,{"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]=f):f=e[15],f},q=s=>{let e=(0,N.c)(12),{value:r,cellId:a,className:i}=s,{updateCellName:o}=T(),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(x(r))return null;let n=t.focusing?"":"text-ellipsis",u;e[3]!==i||e[4]!==n?(u=E("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)(K,{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:z,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||x(t)){e(t);return}e(L(t,F()))}};return{value:x(r)?"":r,focusing:i,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 z(s){s.stopPropagation(),s.key==="Enter"&&s.target instanceof HTMLElement&&s.target.blur()}export{_ as n,B as r,q as t};
