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