import{s as U}from"./chunk-LvLJmgfZ.js";import{t as Z}from"./react-Bj1aDYRI.js";import{t as ee}from"./react-dom-CSu739Rf.js";import{b as te,i as re,n as ie,t as ae,v as N,y as ne}from"./click-outside-container-BU5ChL3W.js";import{t as oe}from"./dist-CLyRge8R.js";var le=ee(),r=U(Z(),1),de=()=>t=>t.targetX,se=()=>t=>t.targetY,ue=()=>t=>t.targetWidth,ce=()=>t=>t.targetHeight,ge=()=>t=>t.targetY+10,me=()=>t=>Math.max(0,(t.targetHeight-28)/2);const ve=oe("div")({name:"DataGridOverlayEditorStyle",class:"gdg-d19meir1",propsAsIs:!1,vars:{"d19meir1-0":[se(),"px"],"d19meir1-1":[de(),"px"],"d19meir1-2":[ue(),"px"],"d19meir1-3":[ce(),"px"],"d19meir1-4":[ge(),"px"],"d19meir1-5":[me(),"px"]}});function fe(){let[t,n]=r.useState();return[t??void 0,n]}function pe(){let[t,n]=fe(),[a,p]=r.useState(0),[v,C]=r.useState(!0);return r.useLayoutEffect(()=>{if(t===void 0||!("IntersectionObserver"in window))return;let o=new IntersectionObserver(l=>{l.length!==0&&C(l[0].isIntersecting)},{threshold:1});return o.observe(t),()=>o.disconnect()},[t]),r.useEffect(()=>{if(v||t===void 0)return;let o,l=()=>{let{right:w}=t.getBoundingClientRect();p(O=>Math.min(O+window.innerWidth-w-10,0)),o=requestAnimationFrame(l)};return o=requestAnimationFrame(l),()=>{o!==void 0&&cancelAnimationFrame(o)}},[t,v]),{ref:n,style:r.useMemo(()=>({transform:`translateX(${a}px)`}),[a])}}var he=t=>{let{target:n,content:a,onFinishEditing:p,forceEditMode:v,initialValue:C,imageEditorOverride:o,markdownDivCreateNode:l,highlight:w,className:O,theme:R,id:q,cell:f,bloom:c,portalElementRef:h,validateCell:d,getCellRenderer:F,provideEditor:y,isOutsideClick:B,customEventTarget:G,activation:S}=t,[s,T]=r.useState(v?a:void 0),P=r.useRef(s??a);P.current=s??a;let[E,I]=r.useState(()=>d===void 0?!0:!(N(a)&&(d==null?void 0:d(f,a,P.current))===!1)),g=r.useCallback((e,i)=>{p(E?e:void 0,i)},[E,p]),j=r.useCallback(e=>{if(d!==void 0&&e!==void 0&&N(e)){let i=d(f,e,P.current);i===!1?I(!1):(typeof i=="object"&&(e=i),I(!0))}T(e)},[f,d]),b=r.useRef(!1),m=r.useRef(void 0),L=r.useCallback(()=>{g(s,[0,0]),b.current=!0},[s,g]),_=r.useCallback((e,i)=>{g(e,i??m.current??[0,0]),b.current=!0},[g]),$=r.useCallback(async e=>{let i=!1;e.key==="Escape"?(e.stopPropagation(),e.preventDefault(),m.current=[0,0]):e.key==="Enter"&&!e.shiftKey?(e.stopPropagation(),e.preventDefault(),m.current=[0,1],i=!0):e.key==="Tab"&&(e.stopPropagation(),e.preventDefault(),m.current=[e.shiftKey?-1:1,0],i=!0),window.setTimeout(()=>{!b.current&&m.current!==void 0&&(g(i?s:void 0,m.current),b.current=!0)},0)},[g,s]),D=s??a,[u,z]=r.useMemo(()=>{var x,Y;if(ne(a))return[];let e={...a,location:f,activation:S},i=y==null?void 0:y(e);return i===void 0?[(Y=(x=F(a))==null?void 0:x.provideEditor)==null?void 0:Y.call(x,e),!1]:[i,!1]},[f,a,F,y,S]),{ref:J,style:Q}=pe(),A=!0,H,K=!0,k;if(u!==void 0){A=u.disablePadding!==!0,K=u.disableStyling!==!0;let e=te(u);e&&(k=u.styleOverride);let i=e?u.editor:u;H=r.createElement(i,{portalElementRef:h,isHighlighted:w,activation:S,onChange:j,value:D,initialValue:C,onFinishedEditing:_,validatedSelection:N(D)?D.selectionRange:void 0,forceEditMode:v,target:n,imageEditorOverride:o,markdownDivCreateNode:l,isValid:E,theme:R})}k={...k,...Q};let V=(h==null?void 0:h.current)??document.getElementById("portal");if(V===null)return console.error('Cannot open Data Grid overlay editor, because portal not found. Please, either provide a portalElementRef or add `<div id="portal" />` as the last child of your `<body>`.'),null;let M=K?"gdg-style":"gdg-unstyle";E||(M+=" gdg-invalid"),A&&(M+=" gdg-pad");let W=(c==null?void 0:c[0])??1,X=(c==null?void 0:c[1])??1;return(0,le.createPortal)(r.createElement(ie.Provider,{value:R},r.createElement(ae,{style:re(R),className:O,onClickOutside:L,isOutsideClick:B,customEventTarget:G},r.createElement(ve,{ref:J,id:q,className:M,style:k,as:z===!0?"label":void 0,targetX:n.x-W,targetY:n.y-X,targetWidth:n.width+W*2,targetHeight:n.height+X*2},r.createElement("div",{className:"gdg-clip-region",onKeyDown:$},H)))),V)};export{he as default};
