UNPKG

siegel

Version:

Web application development ecosystem

1 lines 1.41 kB
import{useLayoutEffect as t,useState as e,useRef as i}from"react";let l=({scrollTop:t,itemHeight:e,preloadedItemsBySide:i,maxItemsCount:l,tableHeight:o})=>{let r=Math.min(Math.ceil((t+o)/e)+i,l);return{from:Math.max(Math.min(Math.ceil(t/e),r-Math.ceil(o/e))-i,0),to:r}},o=(t,e)=>({children:[{value:"",attributes:{className:e}}],attributes:{key:`____${t?"top":"bottom"}_virtualization_expander_row_cell`}});function r(o){let{rootAttributes:r,state:{showPerPage:n},props:{withFooter:a,onScroll:u,entities:{sorted:c},virtualization:{itemHeight:m,preloadedItemsBySide:s=20,scrollUpdateInterval:h=250,tableHeight:p=innerHeight}}}=o;r.ref=i(null);let[d,f]=e({scrollTop:0,timeoutID:0}),{scrollTop:g}=d,_=a?Math.min(n,c.length):c.length;return{slideWindowRange:l({scrollTop:g,itemHeight:m,tableHeight:p,preloadedItemsBySide:s,maxItemsCount:_}),maxItemsCount:_,useVirtualizationScrolling:function(e){t(()=>{let{from:t,to:i}=l({itemHeight:m,preloadedItemsBySide:s,scrollTop:g,tableHeight:p,maxItemsCount:e}),{rows:o}=r.ref.current.firstChild.tBodies[0];return o[0].cells[0].style.height=`${t*m}px`,o[o.length-1].cells[0].style.height=`${(e-i)*m}px`,()=>{clearTimeout(d.timeoutID),d.timeoutID=0}},[g,n,e])},onScrollHandler:function(t){if(u?.(t),!(t.defaultPrevented||d.timeoutID)){let e=t.target;d.timeoutID=setTimeout(()=>{f({scrollTop:e.scrollTop,timeoutID:0})},h)}}}}export{r as applyVirtualization,o as getExpanderRow};