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