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