"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[7882],{47882:(le,F,o)=>{o.r(F),o.d(F,{default:()=>q});var t=o(96540),X=o(40961),K=o(11421),P=o(78086),g=o(69321),W=o(25704);const Y=()=>n=>n.targetX,j=()=>n=>n.targetY,z=()=>n=>n.targetWidth,L=()=>n=>n.targetHeight,$=()=>n=>n.targetY+10,J=()=>n=>Math.max(0,(n.targetHeight-28)/2),Q=(0,W.I)("div")({name:"DataGridOverlayEditorStyle",class:"gdg-d19meir1",propsAsIs:!1,vars:{"d19meir1-0":[j(),"px"],"d19meir1-1":[Y(),"px"],"d19meir1-2":[z(),"px"],"d19meir1-3":[L(),"px"],"d19meir1-4":[$(),"px"],"d19meir1-5":[J(),"px"]}});function U(){const[n,s]=t.useState();return[n??void 0,s]}function Z(){const[n,s]=U(),[r,y]=t.useState(0),[m,O]=t.useState(!0);t.useLayoutEffect(()=>{if(n===void 0||!("IntersectionObserver"in window))return;const a=new IntersectionObserver(d=>{d.length!==0&&O(d[0].isIntersecting)},{threshold:1});return a.observe(n),()=>a.disconnect()},[n]),t.useEffect(()=>{if(m||n===void 0)return;let a;const d=()=>{const{right:x}=n.getBoundingClientRect();y(p=>Math.min(p+window.innerWidth-x-10,0)),a=requestAnimationFrame(d)};return a=requestAnimationFrame(d),()=>{a!==void 0&&cancelAnimationFrame(a)}},[n,m]);const b=t.useMemo(()=>({transform:`translateX(${r}px)`}),[r]);return{ref:s,style:b}}const q=n=>{const{target:s,content:r,onFinishEditing:y,forceEditMode:m,initialValue:O,imageEditorOverride:b,markdownDivCreateNode:a,highlight:d,className:x,theme:p,id:_,cell:S,bloom:M,validateCell:h,getCellRenderer:N,provideEditor:V,isOutsideClick:ee}=n,[l,te]=t.useState(m?r:void 0),k=t.useRef(l??r);k.current=l??r;const[v,D]=t.useState(()=>h===void 0?!0:!((0,g.Bc)(r)&&h?.(S,r,k.current)===!1)),c=t.useCallback((e,i)=>{y(v?e:void 0,i)},[v,y]),ne=t.useCallback(e=>{if(h!==void 0&&e!==void 0&&(0,g.Bc)(e)){const i=h(S,e,k.current);i===!1?D(!1):(typeof i=="object"&&(e=i),D(!0))}te(e)},[S,h]),E=t.useRef(!1),f=t.useRef(void 0),re=t.useCallback(()=>{c(l,[0,0]),E.current=!0},[l,c]),ie=t.useCallback((e,i)=>{c(e,i??f.current??[0,0]),E.current=!0},[c]),se=t.useCallback(async e=>{let i=!1;e.key==="Escape"?(e.stopPropagation(),e.preventDefault(),f.current=[0,0]):e.key==="Enter"&&!e.shiftKey?(e.stopPropagation(),e.preventDefault(),f.current=[0,1],i=!0):e.key==="Tab"&&(e.stopPropagation(),e.preventDefault(),f.current=[e.shiftKey?-1:1,0],i=!0),window.setTimeout(()=>{!E.current&&f.current!==void 0&&(c(i?l:void 0,f.current),E.current=!0)},0)},[c,l]),R=l??r,[u,ae]=t.useMemo(()=>{if((0,g.pg)(r))return[];const e=V?.(r);return e!==void 0?[e,!1]:[N(r)?.provideEditor?.(r),!1]},[r,N,V]),{ref:oe,style:de}=Z();let w=!0,A,B=!0,C;if(u!==void 0){w=u.disablePadding!==!0,B=u.disableStyling!==!0;const e=(0,g.zT)(u);e&&(C=u.styleOverride);const i=e?u.editor:u;A=t.createElement(i,{isHighlighted:d,onChange:ne,value:R,initialValue:O,onFinishedEditing:ie,validatedSelection:(0,g.Bc)(R)?R.selectionRange:void 0,forceEditMode:m,target:s,imageEditorOverride:b,markdownDivCreateNode:a,isValid:v,theme:p})}C={...C,...de};const G=document.getElementById("portal");if(G===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 I=B?"gdg-style":"gdg-unstyle";v||(I+=" gdg-invalid"),w&&(I+=" gdg-pad");const H=M?.[0]??1,T=M?.[1]??1;return(0,X.createPortal)(t.createElement(P.Dx.Provider,{value:p},t.createElement(K.A,{style:(0,P.zc)(p),className:x,onClickOutside:re,isOutsideClick:ee},t.createElement(Q,{ref:oe,id:_,className:I,style:C,as:ae===!0?"label":void 0,targetX:s.x-H,targetY:s.y-T,targetWidth:s.width+H*2,targetHeight:s.height+T*2},t.createElement("div",{className:"gdg-clip-region",onKeyDown:se},A)))),G)}}}]);

//# sourceMappingURL=7882.1a3cc418752c83396970.js.map