react-window 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -0
- package/dist/react-window.cjs +1 -1
- package/dist/react-window.cjs.map +1 -1
- package/dist/react-window.d.ts +205 -2
- package/dist/react-window.js +1103 -750
- package/dist/react-window.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -173,6 +173,27 @@ particularly if your row components are stateful.
|
|
|
173
173
|
Refer to the <a href="https://react.dev/learn/rendering-lists#keeping-list-items-in-order-with-key">React documentation</a> for more info.</p>
|
|
174
174
|
<p>⚠️ This prop cannot be auto-memoized because it is called during render.
|
|
175
175
|
It is important to always <code>useCallback</code> for this prop; do not use an inline function.</p>
|
|
176
|
+
</td>
|
|
177
|
+
</tr>
|
|
178
|
+
<tr>
|
|
179
|
+
<td>scrollElement</td>
|
|
180
|
+
<td><p>Element that scrolls the list, for lists that scroll along with other content (e.g. the page):</p>
|
|
181
|
+
<ul>
|
|
182
|
+
<li>"window" to scroll with the page</li>
|
|
183
|
+
<li>an ancestor element that scrolls (e.g. stored with a <code>useState</code> ref callback); <code>null</code> until it has mounted</li>
|
|
184
|
+
</ul>
|
|
185
|
+
<p>The list renders at its full height and only renders the rows visible within the scroll element's viewport.
|
|
186
|
+
Its position within the scroll element is measured whenever it renders, scrolls, or resizes,
|
|
187
|
+
and whenever content before it is resized, inserted, or removed (e.g. an image loading above the list).</p>
|
|
188
|
+
<ul>
|
|
189
|
+
<li><code>scrollToRow</code> scrolls the scroll element</li>
|
|
190
|
+
<li><code>defaultHeight</code> is used as the viewport height until the scroll element has been measured (e.g. during server rendering)</li>
|
|
191
|
+
<li>percentage row heights are relative to the scroll element's viewport height</li>
|
|
192
|
+
<li><code>defaultScrollOffset</code> is ignored</li>
|
|
193
|
+
</ul>
|
|
194
|
+
<p>ℹ️ While the scroll element is <code>null</code>, the list renders the first rows (as it does during server rendering).</p>
|
|
195
|
+
<p>⚠️ The list itself doesn't scroll, so its <code>onScroll</code> handler isn't called;
|
|
196
|
+
listen to the scroll element's "scroll" events instead (or use the <code>useIsScrolling</code> hook).</p>
|
|
176
197
|
</td>
|
|
177
198
|
</tr>
|
|
178
199
|
<tr>
|
|
@@ -376,6 +397,29 @@ particularly if your cell components are stateful.
|
|
|
376
397
|
Refer to the <a href="https://react.dev/learn/rendering-lists#keeping-list-items-in-order-with-key">React documentation</a> for more info.</p>
|
|
377
398
|
<p>⚠️ This prop cannot be auto-memoized because it is called during render.
|
|
378
399
|
It is important to always <code>useCallback</code> for this prop; do not use an inline function.</p>
|
|
400
|
+
</td>
|
|
401
|
+
</tr>
|
|
402
|
+
<tr>
|
|
403
|
+
<td>scrollElement</td>
|
|
404
|
+
<td><p>Element that scrolls the grid, for grids that scroll along with other content (e.g. the page):</p>
|
|
405
|
+
<ul>
|
|
406
|
+
<li>"window" to scroll with the page</li>
|
|
407
|
+
<li>an ancestor element that scrolls (e.g. stored with a <code>useState</code> ref callback); <code>null</code> until it has mounted</li>
|
|
408
|
+
</ul>
|
|
409
|
+
<p>The grid renders at its full height and only renders the rows (and columns) visible within the scroll element's viewport.
|
|
410
|
+
Its position within the scroll element is measured whenever it renders, scrolls, or resizes,
|
|
411
|
+
and whenever content before it is resized, inserted, or removed (e.g. an image loading above the grid).</p>
|
|
412
|
+
<ul>
|
|
413
|
+
<li>columns scroll with the scroll element too if the grid is as wide as its content (e.g. <code>style={{ width: "max-content" }}</code>);
|
|
414
|
+
otherwise the grid fills the width of its parent and its columns scroll within it</li>
|
|
415
|
+
<li><code>scrollToCell</code>, <code>scrollToColumn</code> and <code>scrollToRow</code> scroll whichever element scrolls each axis</li>
|
|
416
|
+
<li><code>defaultHeight</code> and <code>defaultWidth</code> are used as the viewport size until the scroll element has been measured (e.g. during server rendering)</li>
|
|
417
|
+
<li>percentage row heights and column widths are relative to the scroll element's viewport</li>
|
|
418
|
+
<li><code>defaultScrollLeft</code> and <code>defaultScrollTop</code> are ignored</li>
|
|
419
|
+
</ul>
|
|
420
|
+
<p>ℹ️ While the scroll element is <code>null</code>, the grid renders the first rows (as it does during server rendering).</p>
|
|
421
|
+
<p>⚠️ The grid's <code>onScroll</code> handler is only called when the grid scrolls its own columns;
|
|
422
|
+
listen to the scroll element's "scroll" events instead (or use the <code>useIsScrolling</code> hook).</p>
|
|
379
423
|
</td>
|
|
380
424
|
</tr>
|
|
381
425
|
<tr>
|
package/dist/react-window.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ee=require("react/jsx-runtime"),n=require("react"),W=typeof window<"u"?n.useLayoutEffect:n.useEffect;function ue(e){let t=e;for(;t;){if(t.dir)return t.dir==="rtl";t=t.parentElement}return!1}function xe(e,t){const[s,o]=n.useState(t==="rtl");return W(()=>{t?o(t==="rtl"):e&&o(ue(e))},[t,e]),s}function we(){return()=>{}}function de(){return n.useSyncExternalStore(we,()=>!1,()=>!0)}function oe(e){return e?.ownerDocument.defaultView??window}function he(e){return oe(e).ResizeObserver??(typeof ResizeObserver<"u"?ResizeObserver:void 0)}function ne(e){if(e!==void 0)switch(typeof e){case"number":return e;case"string":{if(e.endsWith("px"))return parseFloat(e);break}}}function Ie({box:e,defaultHeight:t,defaultWidth:s,disabled:o,element:r,mode:l,style:i}){const{styleHeight:a,styleWidth:f}=n.useMemo(()=>({styleHeight:ne(i?.height),styleWidth:ne(i?.width)}),[i?.height,i?.width]),[p,u]=n.useState({height:t,width:s}),c=o||l==="only-height"&&a!==void 0||l==="only-width"&&f!==void 0||a!==void 0&&f!==void 0;return W(()=>{if(r===null||c)return;const d=he(r);if(!d)return;const b=new d(h=>{for(const w of h){const{contentRect:v,target:m}=w;r===m&&u(x=>x.height===v.height&&x.width===v.width?x:{height:v.height,width:v.width})}});return b.observe(r,{box:e}),()=>{b?.unobserve(r)}},[e,c,r,a,f]),n.useMemo(()=>({height:a??p.height,width:f??p.width}),[p,a,f])}function Q(e){const t=n.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return W(()=>{t.current=e},[e]),n.useCallback((...s)=>t.current?.(...s),[t])}const le=new WeakMap;function Oe(e=!1,t=document){let s=le.get(t);if(s===void 0||e){const o=t.createElement("div"),r=o.style;r.width="50px",r.height="50px",r.overflow="scroll",r.direction="rtl";const l=t.createElement("div"),i=l.style;i.width="100px",i.height="100px",o.appendChild(l),t.body.appendChild(o),o.scrollLeft>0?s="positive-descending":(o.scrollLeft=1,o.scrollLeft===0?s="negative":s="positive-ascending"),t.body.removeChild(o),le.set(t,s)}return s}function J({containerElement:e,direction:t,isRtl:s,scrollOffset:o}){if(t==="horizontal"&&s)switch(Oe(!1,e?.ownerDocument??document)){case"negative":return-o;case"positive-descending":{if(e){const{clientWidth:r,scrollWidth:l}=e;return l-r-o}break}}return o}function H(e,t="Assertion error"){if(!e)throw console.error(t),Error(t)}function D(e,t){if(e===t)return!0;if(!!e!=!!t||(H(e!==void 0),H(t!==void 0),Object.keys(e).length!==Object.keys(t).length))return!1;for(const s in e)if(!Object.hasOwn(t,s)||!Object.is(t[s],e[s]))return!1;return!0}function ve({cachedBounds:e,itemCount:t,itemSize:s}){if(t===0)return 0;if(typeof s=="number")return t*s;{const o=e.get(e.size===0?0:e.size-1);H(o!==void 0,"Unexpected bounds cache miss");const r=(o.scrollOffset+o.size)/e.size;return t*r}}function me({align:e,cachedBounds:t,index:s,itemCount:o,itemSize:r,containerScrollOffset:l,containerSize:i}){if(s<0||s>=o)throw RangeError(`Invalid index specified: ${s}`,{cause:`Index ${s} is not within the range of 0 - ${o-1}`});const a=t.get(s),f=ve({cachedBounds:t,itemCount:o,itemSize:r}),p=Math.max(0,Math.min(f-i,a.scrollOffset)),u=Math.max(0,a.scrollOffset-i+a.size),c=a.size>i?l>=a.scrollOffset&&l<=u:l>=u&&l<=a.scrollOffset;switch(e==="smart"&&(e=c?"auto":"center"),e){case"start":return p;case"end":return u;case"center":return Math.max(0,Math.min(f-i,a.scrollOffset+a.size/2-i/2));case"auto":default:return c?l:l<u?u:p}}function re({cachedBounds:e,containerScrollOffset:t,containerSize:s,itemCount:o,overscanCount:r}){const l=o-1;if(o===0)return{startIndexVisible:0,stopIndexVisible:-1,startIndexOverscan:0,stopIndexOverscan:-1};let i,a;const{itemSize:f}=e;if(f!==void 0&&f>0)i=Math.max(0,Math.min(l,Math.floor(t/f))),a=Math.max(i,Math.min(l,Math.ceil((t+s)/f)-1));else{let p=0,u=Math.min(l,Math.max(0,e.size-1));for(;p<u;){const c=Math.floor((p+u)/2),d=e.get(c);d.scrollOffset+d.size>t?u=c:p=c+1}for(;p<l;){const c=e.get(p);if(c.scrollOffset+c.size>t)break;p++}for(i=p,a=p;a<l;){const c=e.get(a);if(c.scrollOffset+c.size>=t+s)break;a++}}return{startIndexVisible:i,stopIndexVisible:a,startIndexOverscan:Math.max(0,i-r),stopIndexOverscan:Math.min(l,a+r)}}function Se({itemCount:e,itemProps:t,itemSize:s}){const o=new Map;return{itemSize:typeof s=="number"?s:void 0,get(r){if(H(r<e,`Invalid index ${r}`),typeof s=="number"){H(r>=0,`Invalid index ${r}`);let i=o.get(r);return i===void 0&&(i={size:s,scrollOffset:r*s},o.set(r,i)),i}for(;o.size-1<r;){const i=o.size,a=s(i,t);if(i===0)o.set(i,{size:a,scrollOffset:0});else{const f=o.get(i-1);H(f!==void 0,`Unexpected bounds cache miss for index ${r}`),o.set(i,{scrollOffset:f.scrollOffset+f.size,size:a})}}const l=o.get(r);return H(l!==void 0,`Unexpected bounds cache miss for index ${r}`),l},set(r,l){o.set(r,l)},get size(){return o.size}}}function ze({itemCount:e,itemProps:t,itemSize:s}){return n.useMemo(()=>Se({itemCount:e,itemProps:t,itemSize:s}),[e,t,s])}function ye({containerSize:e,itemSize:t}){let s;switch(typeof t){case"string":{H(t.endsWith("%"),`Invalid item size: "${t}"; string values must be percentages (e.g. "100%")`),H(e!==void 0,"Container size must be defined if a percentage item size is specified"),s=e*parseFloat(t)/100;break}default:{s=t;break}}return s}function ie({containerElement:e,containerStyle:t,defaultContainerSize:s=0,defaultScrollOffset:o=0,direction:r,isRtl:l=!1,itemCount:i,itemProps:a,itemSize:f,onResize:p,overscanCount:u}){const{height:c=s,width:d=s}=Ie({defaultHeight:r==="vertical"?s:void 0,defaultWidth:r==="horizontal"?s:void 0,element:e,mode:r==="vertical"?"only-height":"only-width",style:t}),b=n.useRef({height:0,width:0}),h=r==="vertical"?c:d,w=ye({containerSize:h,itemSize:f});W(()=>{if(typeof p=="function"){const g=b.current;(g.height!==c||g.width!==d)&&(p({height:c,width:d},{...g}),g.height=c,g.width=d)}},[c,p,d]);const v=ze({itemCount:i,itemProps:a,itemSize:w}),m=de(),[x]=n.useState(()=>m?0:o),N=n.useCallback(g=>v.get(g),[v]),[z,_]=n.useState(()=>re({cachedBounds:v,containerScrollOffset:x,containerSize:h,itemCount:i,overscanCount:u})),{startIndexVisible:L,startIndexOverscan:j,stopIndexVisible:O,stopIndexOverscan:P}={startIndexVisible:Math.min(i-1,z.startIndexVisible),startIndexOverscan:Math.min(i-1,z.startIndexOverscan),stopIndexVisible:Math.min(i-1,z.stopIndexVisible),stopIndexOverscan:Math.min(i-1,z.stopIndexOverscan)},A=n.useCallback(()=>ve({cachedBounds:v,itemCount:i,itemSize:w}),[v,i,w]),G=n.useCallback(g=>{const I=J({containerElement:e,direction:r,isRtl:l,scrollOffset:g});return re({cachedBounds:v,containerScrollOffset:I,containerSize:h,itemCount:i,overscanCount:u})},[v,e,h,r,l,i,u]),Y=n.useRef(!1);W(()=>{if(!e||i===0||Y.current||(Y.current=!0,o<=0))return;const g=r==="horizontal"&&ue(e);if(J({containerElement:e,direction:r,isRtl:g,scrollOffset:r==="vertical"?e.scrollTop:e.scrollLeft})!==0)return;const y=J({containerElement:e,direction:r,isRtl:g,scrollOffset:o});typeof e.scrollTo=="function"?e.scrollTo({behavior:"instant",[r==="vertical"?"top":"left"]:y}):r==="vertical"?e.scrollTop=y:e.scrollLeft=y},[e,i]),W(()=>{const g=e?G(r==="vertical"?e.scrollTop:e.scrollLeft):re({cachedBounds:v,containerScrollOffset:x,containerSize:h,itemCount:i,overscanCount:u});_(I=>D(g,I)?I:g)},[v,e,h,r,G,x,i,u]),W(()=>{if(!e)return;const g=()=>{_(I=>{const{scrollLeft:y,scrollTop:T}=e,k=J({containerElement:e,direction:r,isRtl:l,scrollOffset:r==="vertical"?T:y}),E=re({cachedBounds:v,containerScrollOffset:k,containerSize:h,itemCount:i,overscanCount:u});return D(E,I)?I:E})};return e.addEventListener("scroll",g),()=>{e.removeEventListener("scroll",g)}},[v,e,h,r,l,i,u]);const S=Q(({align:g="auto",containerScrollOffset:I,index:y})=>{let T=me({align:g,cachedBounds:v,containerScrollOffset:J({containerElement:e,direction:r,isRtl:l,scrollOffset:I}),containerSize:h,index:y,itemCount:i,itemSize:w});if(e){if(T=J({containerElement:e,direction:r,isRtl:l,scrollOffset:T}),typeof e.scrollTo!="function"){const k=G(T);D(z,k)||_(k)}return T}});return{getCellBounds:N,getEstimatedSize:A,scrollToIndex:S,startIndexOverscan:j,startIndexVisible:L,stopIndexOverscan:P,stopIndexVisible:O}}function pe(e){const[t,s]=n.useState(e);return D(t,e)?t:(s(e),e)}function be(e,t){const{ariaAttributes:s,style:o,...r}=e,{ariaAttributes:l,style:i,...a}=t;return D(s,l)&&D(o,i)&&D(r,a)}function Re({cellComponent:e,cellProps:t,children:s,className:o,columnCount:r,columnKey:l,columnWidth:i,defaultHeight:a=0,defaultScrollLeft:f=0,defaultScrollTop:p=0,defaultWidth:u=0,dir:c,gridRef:d,onCellsRendered:b,onResize:h,overscanCount:w=3,rowCount:v,rowHeight:m,rowKey:x,style:N,tagName:z="div",..._}){const L=pe(t),j=n.useMemo(()=>n.memo(e,be),[e]),[O,P]=n.useState(null),A=xe(O,c),{getCellBounds:G,getEstimatedSize:Y,startIndexOverscan:S,startIndexVisible:g,scrollToIndex:I,stopIndexOverscan:y,stopIndexVisible:T}=ie({containerElement:O,containerStyle:N,defaultContainerSize:u,defaultScrollOffset:f,direction:"horizontal",isRtl:A,itemCount:r,itemProps:L,itemSize:i,onResize:h,overscanCount:w}),{getCellBounds:k,getEstimatedSize:E,startIndexOverscan:C,startIndexVisible:se,scrollToIndex:X,stopIndexOverscan:q,stopIndexVisible:V}=ie({containerElement:O,containerStyle:N,defaultContainerSize:a,defaultScrollOffset:p,direction:"vertical",itemCount:v,itemProps:L,itemSize:m,onResize:h,overscanCount:w});n.useImperativeHandle(d,()=>({get element(){return O},scrollToCell({behavior:F="auto",columnAlign:R="auto",columnIndex:B,rowAlign:U="auto",rowIndex:$}){const K=I({align:R,containerScrollOffset:O?.scrollLeft??0,index:B}),ge=X({align:U,containerScrollOffset:O?.scrollTop??0,index:$});typeof O?.scrollTo=="function"&&O.scrollTo({behavior:F,left:K,top:ge})},scrollToColumn({align:F="auto",behavior:R="auto",index:B}){const U=I({align:F,containerScrollOffset:O?.scrollLeft??0,index:B});typeof O?.scrollTo=="function"&&O.scrollTo({behavior:R,left:U})},scrollToRow({align:F="auto",behavior:R="auto",index:B}){const U=X({align:F,containerScrollOffset:O?.scrollTop??0,index:B});typeof O?.scrollTo=="function"&&O.scrollTo({behavior:R,top:U})}}),[O,I,X]),n.useEffect(()=>{S>=0&&y>=0&&C>=0&&q>=0&&b&&b({columnStartIndex:g,columnStopIndex:T,rowStartIndex:se,rowStopIndex:V},{columnStartIndex:S,columnStopIndex:y,rowStartIndex:C,rowStopIndex:q})},[b,S,g,y,T,C,se,q,V]);const M=n.useMemo(()=>{const F=[];if(r>0&&v>0)for(let R=C;R<=q;R++){const B=k(R),U=[];for(let $=S;$<=y;$++){const K=G($);U.push(n.createElement(j,{...L,ariaAttributes:{"aria-colindex":$+1,role:"gridcell"},columnIndex:$,key:l?l({columnIndex:$,data:L,rowIndex:R}):$,rowIndex:R,style:{position:"absolute",left:A?void 0:0,right:A?0:void 0,transform:`translate(${A?-K.scrollOffset:K.scrollOffset}px, ${B.scrollOffset}px)`,height:B.size,width:K.size}}))}F.push(ee.jsx("div",{role:"row","aria-rowindex":R+1,children:U},x?x({data:L,rowIndex:R}):R))}return F},[j,L,r,l,S,y,G,k,A,v,x,C,q]),Z=ee.jsx("div",{"aria-hidden":!0,style:{height:E(),width:Y(),zIndex:-1}});return n.createElement(z,{"aria-colcount":r,"aria-rowcount":v,role:"grid",..._,className:o,dir:c,ref:P,style:{position:"relative",maxHeight:"100%",maxWidth:"100%",flexGrow:1,overflow:"auto",...N}},M,s,Z)}const Te=n.useState,Me=n.useRef;function Ae({callback:e,element:t,enabled:s=!0}){const o=Q(e);n.useEffect(()=>{if(!s||!t)return;const r=oe(t);let l=r.requestAnimationFrame(()=>{l=r.requestAnimationFrame(o)});return()=>{r.cancelAnimationFrame(l)}},[t,s,o])}function Le(e){return e!=null&&typeof e=="object"&&"getAverageRowHeight"in e&&typeof e.getAverageRowHeight=="function"}function ke({element:e,getCellBounds:t,isDynamicRowHeight:s,rowCount:o,rowElements:r,scrollToIndex:l}){const i=n.useRef(null),a=n.useRef(void 0),f=Q(()=>{i.current=null,a.current!==void 0&&(a.current.view.cancelAnimationFrame(a.current.id),a.current=void 0)}),p=Q(()=>{const c=oe(e);a.current={id:c.requestAnimationFrame(u),view:c}}),u=Q(()=>{a.current=void 0;const c=i.current;if(!c)return;if(!e||!s||c.index>=o||performance.now()>=c.deadline){f();return}const d=l({align:c.align,containerScrollOffset:e.scrollTop,index:c.index});if(d!==void 0){const b=Math.max(0,Math.min(d,e.scrollHeight-e.clientHeight));if(Math.abs(b-e.scrollTop)>1)c.stableFrames=0,e.scrollTo({behavior:"instant",top:b});else{const h=r.current;if(!(h.some(m=>m.getAttribute(te)===`${c.index}`)&&h.every(m=>{const x=Number(m.getAttribute(te));return Math.abs(t(x).size-m.offsetHeight)<=1})))c.stableFrames=0;else if(++c.stableFrames>=2){f();return}}}p()});return W(()=>{if(!e)return;const c=d=>{switch(d.key){case"ArrowUp":case"ArrowDown":case"PageUp":case"PageDown":case"Home":case"End":case" ":f()}};return e.addEventListener("wheel",f,{passive:!0}),e.addEventListener("touchstart",f,{passive:!0}),e.addEventListener("pointerdown",f),e.addEventListener("keydown",c),()=>{f(),e.removeEventListener("wheel",f),e.removeEventListener("touchstart",f),e.removeEventListener("pointerdown",f),e.removeEventListener("keydown",c)}},[f,e]),n.useCallback(({align:c="auto",behavior:d="auto",index:b})=>{s&&c==="smart"&&(c=l({align:"auto",containerScrollOffset:e?.scrollTop??0,index:b})===(e?.scrollTop??0)?"auto":"center");const h=l({align:c,containerScrollOffset:e?.scrollTop??0,index:b});f(),typeof e?.scrollTo=="function"&&(s&&(i.current={align:c,index:b,deadline:performance.now()+1e3,stableFrames:0},p()),e.scrollTo({behavior:s?"instant":d,top:h}))},[f,e,s,p,l])}const te="data-react-window-index",ce="data-react-window-sizer";function Ee({children:e,className:t,defaultHeight:s=0,defaultScrollOffset:o=0,listRef:r,onResize:l,onRowsRendered:i,overscanCount:a=3,rowComponent:f,rowCount:p,rowHeight:u,rowKey:c,rowProps:d,tagName:b="div",style:h,...w}){const v=pe(d),m=n.useMemo(()=>n.memo(f,be),[f]),[x,N]=n.useState(null),z=Le(u),_=n.useMemo(()=>z?V=>u.getRowHeight(V)??u.getAverageRowHeight():u,[z,u]),L=de(),[j,O]=n.useState(()=>L&&z),P=n.useRef(u);W(()=>{j&&P.current!==u&&O(!1)},[j,u]),Ae({callback:()=>O(!1),element:x,enabled:j});const{getCellBounds:A,getEstimatedSize:G,scrollToIndex:Y,startIndexOverscan:S,startIndexVisible:g,stopIndexOverscan:I,stopIndexVisible:y}=ie({containerElement:x,containerStyle:h,defaultContainerSize:s,defaultScrollOffset:o,direction:"vertical",itemCount:p,itemProps:v,itemSize:_,onResize:l,overscanCount:a}),T=n.useRef([]),k=ke({element:x,getCellBounds:A,isDynamicRowHeight:z,rowCount:p,rowElements:T,scrollToIndex:Y});n.useImperativeHandle(r,()=>({get element(){return x},scrollToRow:k}),[x,k]),W(()=>{if(!x)return;const V=Array.from(x.children).slice(0,S<0?0:I-S+1).filter((M,Z)=>{if(M.hasAttribute(ce))return!1;const F=`${S+Z}`;return M.setAttribute(te,F),!0});if(T.current=V,z)return u.observeRowElements(V)},[m,x,z,p,u,c,v,S,I]),n.useEffect(()=>{S>=0&&I>=0&&i&&i({startIndex:g,stopIndex:y},{startIndex:S,stopIndex:I})},[i,S,g,I,y]);const E=j&&z&&S===0,C=n.useMemo(()=>{const V=[];if(p>0)for(let M=S;M<=I;M++){const Z=A(M);V.push(n.createElement(m,{...v,ariaAttributes:{"aria-posinset":M+1,"aria-setsize":p,role:"listitem"},key:c?c(M,v):M,index:M,style:E?{width:"100%"}:{position:"absolute",left:0,transform:`translateY(${Z.scrollOffset}px)`,height:z?void 0:Z.size,width:"100%"}}))}return V},[m,A,z,E,p,c,v,S,I]),se=ee.jsx("div",{"aria-hidden":!0,[ce]:"",style:{position:E?"absolute":void 0,top:E?0:void 0,height:G(),width:"100%",zIndex:-1}},"sizer"),X=ee.jsx(n.Fragment,{children:e},"children"),q=ee.jsx(n.Fragment,{children:C},"rows");return n.createElement(b,{role:"list",...w,className:t,ref:N,style:{position:"relative",maxHeight:"100%",flexGrow:1,overflowY:"auto",...h}},...E?[X,q]:[q,X],se)}function ae(e){const t=new Map;return e!==void 0&&e.forEach((s,o)=>{Number.isFinite(s)&&s>0&&t.set(o,s)}),t}function Ve({defaultRowHeight:e,initialRowHeights:t,key:s}){const[o,r]=n.useState(()=>({key:s,map:ae(t)}));o.key!==s&&r({key:s,map:ae(t)});const{map:l}=o,i=n.useCallback(()=>{let d=0;return l.forEach(b=>{d+=b}),d===0?e:d/l.size},[e,l]),a=n.useCallback(d=>{const b=l.get(d);return b!==void 0?b:e},[e,l]),f=n.useCallback((d,b)=>{r(h=>{if(h.map.get(d)===b)return h;const w=new Map(h.map);return w.set(d,b),{...h,map:w}})},[]),p=Q(d=>{d.length!==0&&d.forEach(b=>{const{borderBoxSize:h,target:w}=b,v=w.getAttribute(te);H(v!==null,`Invalid ${te} attribute value`);const m=parseInt(v),{blockSize:x}=h[0];x&&f(m,x)})}),u=n.useRef(null);n.useEffect(()=>()=>{u.current?.resizeObserver.disconnect(),u.current=null},[]);const c=n.useCallback(d=>{const b=[];return d.forEach(h=>{const w=oe(h);if(u.current?.view!==w){u.current?.resizeObserver.disconnect();const m=he(h);u.current=m?{resizeObserver:new m(p),view:w}:null}const v=u.current?.resizeObserver;v&&(v.observe(h),b.push([h,v]))}),()=>{b.forEach(([h,w])=>w.unobserve(h))}},[p]);return n.useMemo(()=>({getAverageRowHeight:i,getRowHeight:a,setRowHeight:f,observeRowElements:c}),[i,a,f,c])}const Fe=n.useState,We=n.useRef,fe=new WeakMap;function He(e=!1,t=typeof document<"u"?document:void 0){if(t===void 0)return 0;let s=fe.get(t);if(s===void 0||e){const o=t.createElement("div"),r=o.style;r.width="50px",r.height="50px",r.overflow="scroll",t.body.appendChild(o),s=o.offsetWidth-o.clientWidth,t.body.removeChild(o),fe.set(t,s)}return s}exports.Grid=Re;exports.List=Ee;exports.getScrollbarSize=He;exports.useDynamicRowHeight=Ve;exports.useGridCallbackRef=Te;exports.useGridRef=Me;exports.useListCallbackRef=Fe;exports.useListRef=We;
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const le=require("react/jsx-runtime"),l=require("react"),B=typeof window<"u"?l.useLayoutEffect:l.useEffect;function Se(e){let t=e;for(;t;){if(t.dir)return t.dir==="rtl";t=t.parentElement}return!1}function Ie(e,t){const[r,o]=l.useState(t==="rtl");return B(()=>{t?o(t==="rtl"):e&&o(Se(e))},[t,e]),r}function Le(){return()=>{}}function Oe(){return l.useSyncExternalStore(Le,()=>!1,()=>!0)}function X(e){return e?.ownerDocument.defaultView??window}function ue(e){return X(e).ResizeObserver??(typeof ResizeObserver<"u"?ResizeObserver:void 0)}function ve(e){if(e!==void 0)switch(typeof e){case"number":return e;case"string":{if(e.endsWith("px"))return parseFloat(e);break}}}function Ae({box:e,defaultHeight:t,defaultWidth:r,disabled:o,element:s,mode:i,style:n}){const{styleHeight:v,styleWidth:h}=l.useMemo(()=>({styleHeight:ve(n?.height),styleWidth:ve(n?.width)}),[n?.height,n?.width]),[g,u]=l.useState({height:t,width:r}),d=o||i==="only-height"&&v!==void 0||i==="only-width"&&h!==void 0||v!==void 0&&h!==void 0;return B(()=>{if(s===null||d)return;const f=ue(s);if(!f)return;const c=new f(a=>{for(const b of a){const{contentRect:w,target:m}=b;s===m&&u(x=>x.height===w.height&&x.width===w.width?x:{height:w.height,width:w.width})}});return c.observe(s,{box:e}),()=>{c?.unobserve(s)}},[e,d,s,v,h]),l.useMemo(()=>({height:v??g.height,width:h??g.width}),[g,v,h])}function re(e){const t=l.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return B(()=>{t.current=e},[e]),l.useCallback((...r)=>t.current?.(...r),[t])}const he=new WeakMap;function Ee(e=!1,t=document){let r=he.get(t);if(r===void 0||e){const o=t.createElement("div"),s=o.style;s.width="50px",s.height="50px",s.overflow="scroll",s.direction="rtl";const i=t.createElement("div"),n=i.style;n.width="100px",n.height="100px",o.appendChild(i),t.body.appendChild(o),o.scrollLeft>0?r="positive-descending":(o.scrollLeft=1,o.scrollLeft===0?r="negative":r="positive-ascending"),t.body.removeChild(o),he.set(t,r)}return r}function se({containerElement:e,direction:t,isRtl:r,scrollOffset:o}){if(t==="horizontal"&&r)switch(Ee(!1,e?.ownerDocument??document)){case"negative":return-o;case"positive-descending":{if(e){const{clientWidth:s,scrollWidth:i}=e;return i-s-o}break}}return o}function ke({container:e,element:t,onChange:r}){const o=X(t),s=ue(t),i=o.MutationObserver??(typeof MutationObserver<"u"?MutationObserver:void 0),n=s?new s(r):void 0,v=d=>!d.isConnected||(d.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_FOLLOWING)!==0,h=i?new i(d=>{d.some(c=>Array.from(c.addedNodes).some(v)||c.removedNodes.length>0&&c.nextSibling!==null&&v(c.nextSibling))&&(u(),r())}):void 0,g=new Set,u=()=>{for(const f of g)n?.unobserve(f);g.clear(),h?.disconnect();let d=t;for(;d!==e;){const f=d.parentElement;if(f===null)break;if(n)for(let c=d.previousElementSibling;c!==null;c=c.previousElementSibling)g.add(c),n.observe(c);h?.observe(f,{childList:!0}),d=f}};return u(),()=>{n?.disconnect(),h?.disconnect()}}function oe(e){return e.window===e}function Ve(e,t){return t==="window"?e?X(e):null:t??null}function de(e,t){return oe(e)?t==="vertical"?e.scrollY:e.scrollX:t==="vertical"?e.scrollTop:e.scrollLeft}function We(e,t){const r=oe(e)?e.document.scrollingElement??e.document.documentElement:e;return t==="vertical"?r.scrollHeight-r.clientHeight:r.scrollWidth-r.clientWidth}function ne(e,t){e&&typeof e.scrollTo=="function"&&e.scrollTo(t)}function Fe(e,t){const{overflowX:r,overflowY:o}=X(e).getComputedStyle(e),s=t==="vertical"?o:r;return s==="visible"||s==="clip"?!1:t==="vertical"?e.scrollHeight-e.clientHeight>1:e.scrollWidth-e.clientWidth>1}function ge({containerElement:e,direction:t,isRtl:r,scrollTarget:o}){const s=t==="vertical";let i,n;if(oe(o)){const{documentElement:x}=o.document;i=0,n=s?x.clientHeight:x.clientWidth}else{const x=o.getBoundingClientRect();i=s?x.top+o.clientTop:x.left+o.clientLeft,n=s?o.clientHeight:o.clientWidth}const v=i+n,h=e.getBoundingClientRect(),g=s?h.top+e.clientTop:h.left+e.clientLeft,u=s?e.clientHeight:e.clientWidth,d=g+u,f=se({containerElement:e,direction:t,isRtl:r,scrollOffset:s?e.scrollTop:e.scrollLeft}),a=!s&&r?d-v:i-g,b=a+n,w=Math.max(0,a),m=Math.min(u,b);return{offset:f+w,size:Math.max(0,m-w),viewportOffset:f+a,viewportSize:n}}function be({direction:e,isRtl:t,scrollTarget:r,viewportSize:o}){const s=oe(r)?r.document.documentElement:r,i=X(s).getComputedStyle(s),n=g=>{const u=parseFloat(g??"");return!Number.isFinite(u)||u<0?0:g.endsWith("px")?u:g.endsWith("%")?u*o/100:0};if(e==="vertical")return{end:n(i.scrollPaddingBottom),start:n(i.scrollPaddingTop)};const v=n(i.scrollPaddingLeft),h=n(i.scrollPaddingRight);return t?{end:v,start:h}:{end:h,start:v}}function $(e,t="Assertion error"){if(!e)throw console.error(t),Error(t)}function K(e,t){if(e===t)return!0;if(!!e!=!!t||($(e!==void 0),$(t!==void 0),Object.keys(e).length!==Object.keys(t).length))return!1;for(const r in e)if(!Object.hasOwn(t,r)||!Object.is(t[r],e[r]))return!1;return!0}function ze({cachedBounds:e,itemCount:t,itemSize:r}){if(t===0)return 0;if(typeof r=="number")return t*r;{const o=e.get(e.size===0?0:e.size-1);$(o!==void 0,"Unexpected bounds cache miss");const s=(o.scrollOffset+o.size)/e.size;return t*s}}function pe({align:e,cachedBounds:t,clamp:r=!0,index:o,itemCount:s,itemSize:i,containerScrollOffset:n,containerSize:v}){if(o<0||o>=s)throw RangeError(`Invalid index specified: ${o}`,{cause:`Index ${o} is not within the range of 0 - ${s-1}`});const h=t.get(o),g=ze({cachedBounds:t,itemCount:s,itemSize:i}),u=a=>r?Math.max(0,Math.min(g-v,a)):a,d=u(h.scrollOffset),f=r?Math.max(0,h.scrollOffset-v+h.size):h.scrollOffset-v+h.size,c=h.size>v?n>=h.scrollOffset&&n<=f:n>=f&&n<=h.scrollOffset;switch(e==="smart"&&(e=c?"auto":"center"),e){case"start":return d;case"end":return f;case"center":return u(h.scrollOffset+h.size/2-v/2);case"auto":default:return c?n:n<f?f:d}}function ie({cachedBounds:e,containerScrollOffset:t,containerSize:r,itemCount:o,overscanCount:s}){const i=o-1;if(o===0)return{startIndexVisible:0,stopIndexVisible:-1,startIndexOverscan:0,stopIndexOverscan:-1};let n,v;const{itemSize:h}=e;if(h!==void 0)h>0?(n=Math.max(0,Math.min(i,Math.floor(t/h))),v=Math.max(n,Math.min(i,Math.ceil((t+r)/h)-1))):(n=0,v=0);else{let g=0,u=Math.min(i,Math.max(0,e.size-1));for(;g<u;){const d=Math.floor((g+u)/2),f=e.get(d);f.scrollOffset+f.size>t?u=d:g=d+1}for(;g<i;){const d=e.get(g);if(d.scrollOffset+d.size>t)break;g++}for(n=g,v=g;v<i;){const d=e.get(v);if(d.scrollOffset+d.size>=t+r)break;v++}}return{startIndexVisible:n,stopIndexVisible:v,startIndexOverscan:Math.max(0,n-s),stopIndexOverscan:Math.min(i,v+s)}}function He({itemCount:e,itemProps:t,itemSize:r}){const o=new Map;return{itemSize:typeof r=="number"?r:void 0,get(s){if($(s<e,`Invalid index ${s}`),typeof r=="number")return $(s>=0,`Invalid index ${s}`),{size:r,scrollOffset:s*r};for(;o.size-1<s;){const n=o.size,v=r(n,t);if(n===0)o.set(n,{size:v,scrollOffset:0});else{const h=o.get(n-1);$(h!==void 0,`Unexpected bounds cache miss for index ${s}`),o.set(n,{scrollOffset:h.scrollOffset+h.size,size:v})}}const i=o.get(s);return $(i!==void 0,`Unexpected bounds cache miss for index ${s}`),i},set(s,i){o.set(s,i)},get size(){return o.size}}}function Ce({itemCount:e,itemProps:t,itemSize:r}){return l.useMemo(()=>He({itemCount:e,itemProps:t,itemSize:r}),[e,t,r])}function Ne({containerSize:e,itemSize:t}){let r;switch(typeof t){case"string":{$(t.endsWith("%"),`Invalid item size: "${t}"; string values must be percentages (e.g. "100%")`),$(e!==void 0,"Container size must be defined if a percentage item size is specified"),r=e*parseFloat(t)/100;break}default:{r=t;break}}return typeof r=="number"&&!(Number.isFinite(r)&&r>0)&&(r=0),r}function ae({containerElement:e,containerStyle:t,defaultContainerSize:r=0,defaultScrollOffset:o=0,direction:s,isRtl:i=!1,itemCount:n,itemProps:v,itemSize:h,onResize:g,overscanCount:u,scrollElement:d}){const f=d!==void 0,c=f?Ve(e,d):e,{height:a=r,width:b=r}=Ae({defaultHeight:s==="vertical"?r:void 0,defaultWidth:s==="horizontal"?r:void 0,element:e,mode:s==="vertical"?"only-height":"only-width",style:t}),w=l.useRef({height:0,width:0}),[m,x]=l.useState(r),S=f?m:s==="vertical"?a:b,W=Ne({containerSize:S,itemSize:h});B(()=>{if(typeof g=="function"){const z=w.current;(z.height!==a||z.width!==b)&&(g({height:a,width:b},{...z}),z.height=a,z.width=b)}},[a,g,b]);const R=Ce({itemCount:n,itemProps:v,itemSize:W}),N=Oe(),[L]=l.useState(()=>N||f?0:o),j=l.useCallback(z=>R.get(z),[R]),[F,G]=l.useState(()=>ie({cachedBounds:R,containerScrollOffset:L,containerSize:S,itemCount:n,overscanCount:u})),{startIndexVisible:P,startIndexOverscan:Y,stopIndexVisible:Q,stopIndexOverscan:M}={startIndexVisible:Math.min(n-1,F.startIndexVisible),startIndexOverscan:Math.min(n-1,F.startIndexOverscan),stopIndexVisible:Math.min(n-1,F.stopIndexVisible),stopIndexOverscan:Math.min(n-1,F.stopIndexOverscan)},I=l.useCallback(()=>ze({cachedBounds:R,itemCount:n,itemSize:W}),[R,n,W]),H=l.useCallback(z=>{const p=se({containerElement:e,direction:s,isRtl:i,scrollOffset:z});return ie({cachedBounds:R,containerScrollOffset:p,containerSize:S,itemCount:n,overscanCount:u})},[R,e,S,s,i,n,u]),O=l.useRef(!1);B(()=>{if(!e||n===0||f||O.current||(O.current=!0,o<=0))return;const z=s==="horizontal"&&Se(e);if(se({containerElement:e,direction:s,isRtl:z,scrollOffset:s==="vertical"?e.scrollTop:e.scrollLeft})!==0)return;const A=se({containerElement:e,direction:s,isRtl:z,scrollOffset:o});typeof e.scrollTo=="function"?e.scrollTo({behavior:"instant",[s==="vertical"?"top":"left"]:A}):s==="vertical"?e.scrollTop=A:e.scrollLeft=A},[e,n]),B(()=>{if(f&&e&&c)return;const z=e&&!f?H(s==="vertical"?e.scrollTop:e.scrollLeft):ie({cachedBounds:R,containerScrollOffset:L,containerSize:S,itemCount:n,overscanCount:u});G(p=>K(z,p)?p:z)},[R,e,S,s,H,L,f,n,u,c]),B(()=>{if(!e||f)return;const z=()=>{G(p=>{const{scrollLeft:A,scrollTop:C}=e,E=se({containerElement:e,direction:s,isRtl:i,scrollOffset:s==="vertical"?C:A}),_=ie({cachedBounds:R,containerScrollOffset:E,containerSize:S,itemCount:n,overscanCount:u});return K(_,p)?p:_})};return e.addEventListener("scroll",z),()=>{e.removeEventListener("scroll",z)}},[R,e,S,s,i,f,n,u]);const Z=re(()=>{if(!e||!c)return;const{offset:z,size:p,viewportSize:A}=ge({containerElement:e,direction:s,isRtl:i,scrollTarget:c});x(A);const C=ie({cachedBounds:R,containerScrollOffset:z,containerSize:p,itemCount:n,overscanCount:u});G(E=>K(C,E)?E:C)});B(()=>{f&&Z()}),B(()=>{if(!f||!e||!c)return;const z=X(e),p=()=>Z();c.addEventListener("scroll",p,{passive:!0}),e.addEventListener("scroll",p,{passive:!0}),z.addEventListener("resize",p);let A;const C=ue(e);C&&!oe(c)&&(A=new C(p),A.observe(c));const E=ke({container:oe(c)?c.document.documentElement:c,element:e,onChange:p});return()=>{c.removeEventListener("scroll",p),e.removeEventListener("scroll",p),z.removeEventListener("resize",p),A?.disconnect(),E()}},[e,f,c,Z]);const ee=re(({align:z="auto",index:p})=>{const A=({clamp:k,containerScrollOffset:V,containerSize:T,padding:y})=>{if(y.start===0&&y.end===0)return pe({align:z,cachedBounds:R,clamp:k,containerScrollOffset:V,containerSize:T,index:p,itemCount:n,itemSize:W});const q=pe({align:z,cachedBounds:R,clamp:!1,containerScrollOffset:V+y.start,containerSize:Math.max(0,T-y.start-y.end),index:p,itemCount:n,itemSize:W})-y.start;return k?Math.max(0,Math.min(I()-T,q)):q};if(f&&e&&c&&!Fe(e,s)){const{viewportOffset:k,viewportSize:V}=ge({containerElement:e,direction:s,isRtl:i,scrollTarget:c}),y=A({clamp:!1,containerScrollOffset:k,containerSize:V,padding:be({direction:s,isRtl:i,scrollTarget:c,viewportSize:V})})-k,q=s==="horizontal"&&i?-y:y;return{scrollOffset:de(c,s)+q,scrollTarget:c}}const C=e?s==="vertical"?e.scrollTop:e.scrollLeft:0,E=f&&e?s==="vertical"?e.clientHeight:e.clientWidth:S;let _=A({clamp:!0,containerScrollOffset:se({containerElement:e,direction:s,isRtl:i,scrollOffset:C}),containerSize:E,padding:e?be({direction:s,isRtl:i,scrollTarget:e,viewportSize:E}):{end:0,start:0}});if(e&&(!f||c)){if(_=se({containerElement:e,direction:s,isRtl:i,scrollOffset:_}),!f&&typeof e.scrollTo!="function"){const k=H(_);K(F,k)||G(k)}return{scrollOffset:_,scrollTarget:e}}});return{getCellBounds:j,getEstimatedSize:I,getScrollPositionForIndex:ee,scrollTarget:c,startIndexOverscan:Y,startIndexVisible:P,stopIndexOverscan:M,stopIndexVisible:Q}}function Re(e){const[t,r]=l.useState(e);return K(t,e)?t:(r(e),e)}function ye(e,t){const{ariaAttributes:r,style:o,...s}=e,{ariaAttributes:i,style:n,...v}=t;return K(r,i)&&K(o,n)&&K(s,v)}function je({cellComponent:e,cellProps:t,children:r,className:o,columnCount:s,columnKey:i,columnWidth:n,defaultHeight:v=0,defaultScrollLeft:h=0,defaultScrollTop:g=0,defaultWidth:u=0,dir:d,gridRef:f,onCellsRendered:c,onResize:a,overscanCount:b=3,rowCount:w,rowHeight:m,rowKey:x,scrollElement:S,style:W,tagName:R="div",...N}){const L=Re(t),j=l.useMemo(()=>l.memo(e,ye),[e]),[F,G]=l.useState(null),P=Ie(F,d),{getCellBounds:Y,getEstimatedSize:Q,startIndexOverscan:M,startIndexVisible:I,getScrollPositionForIndex:H,stopIndexOverscan:O,stopIndexVisible:Z}=ae({containerElement:F,containerStyle:W,defaultContainerSize:u,defaultScrollOffset:h,direction:"horizontal",isRtl:P,itemCount:s,itemProps:L,itemSize:n,onResize:a,overscanCount:b,scrollElement:S}),{getCellBounds:ee,getEstimatedSize:z,startIndexOverscan:p,startIndexVisible:A,getScrollPositionForIndex:C,stopIndexOverscan:E,stopIndexVisible:_}=ae({containerElement:F,containerStyle:W,defaultContainerSize:v,defaultScrollOffset:g,direction:"vertical",itemCount:w,itemProps:L,itemSize:m,onResize:a,overscanCount:b,scrollElement:S});l.useImperativeHandle(f,()=>({get element(){return F},scrollToCell({behavior:T="auto",columnAlign:y="auto",columnIndex:q,rowAlign:D="auto",rowIndex:J}){const U=H({align:y,index:q}),te=C({align:D,index:J});U&&te&&U.scrollTarget===te.scrollTarget?ne(te.scrollTarget,{behavior:T,left:U.scrollOffset,top:te.scrollOffset}):(U&&ne(U.scrollTarget,{behavior:T,left:U.scrollOffset}),te&&ne(te.scrollTarget,{behavior:T,top:te.scrollOffset}))},scrollToColumn({align:T="auto",behavior:y="auto",index:q}){const D=H({align:T,index:q});D&&ne(D.scrollTarget,{behavior:y,left:D.scrollOffset})},scrollToRow({align:T="auto",behavior:y="auto",index:q}){const D=C({align:T,index:q});D&&ne(D.scrollTarget,{behavior:y,top:D.scrollOffset})}}),[F,H,C]),l.useEffect(()=>{M>=0&&O>=0&&p>=0&&E>=0&&c&&c({columnStartIndex:I,columnStopIndex:Z,rowStartIndex:A,rowStopIndex:_},{columnStartIndex:M,columnStopIndex:O,rowStartIndex:p,rowStopIndex:E})},[c,M,I,O,Z,p,A,E,_]);const k=l.useMemo(()=>{const T=[];if(s>0&&w>0)for(let y=p;y<=E;y++){const q=ee(y),D=[];for(let J=M;J<=O;J++){const U=Y(J);D.push(l.createElement(j,{...L,ariaAttributes:{"aria-colindex":J+1,role:"gridcell"},columnIndex:J,key:i?i({columnIndex:J,data:L,rowIndex:y}):J,rowIndex:y,style:{position:"absolute",left:P?void 0:0,right:P?0:void 0,transform:`translate(${P?-U.scrollOffset:U.scrollOffset}px, ${q.scrollOffset}px)`,height:q.size,width:U.size}}))}T.push(le.jsx("div",{role:"row","aria-rowindex":y+1,children:D},x?x({data:L,rowIndex:y}):y))}return T},[j,L,s,i,M,O,Y,ee,P,w,x,p,E]),V=le.jsx("div",{"aria-hidden":!0,style:{height:z(),width:Q(),zIndex:-1}});return l.createElement(R,{"aria-colcount":s,"aria-rowcount":w,role:"grid",...N,className:o,dir:d,ref:G,style:{position:"relative",...S===void 0&&{maxHeight:"100%",maxWidth:"100%"},flexGrow:1,overflow:"auto",...W}},k,r,V)}const Pe=l.useState,Be=l.useRef,Me="data-react-window-index",_e="data-index";function fe(e){const t=e.getAttribute(Me)??e.getAttribute(_e);return t!==null&&/^\d+$/.test(t)?Number(t):void 0}function Te({direction:e,element:t,getCellBounds:r,isDynamicSize:o,itemCount:s,itemElements:i,scrollTarget:n,getScrollPositionForIndex:v}){const h=e==="vertical",g=l.useRef(null),u=l.useRef(void 0),d=re(()=>{g.current=null,u.current!==void 0&&(u.current.view.cancelAnimationFrame(u.current.id),u.current=void 0)}),f=re(()=>{const a=X(t);u.current={id:a.requestAnimationFrame(c),view:a}}),c=re(()=>{u.current=void 0;const a=g.current;if(!a)return;if(!t||!o||a.index>=s||performance.now()>=a.deadline){d();return}const b=v({align:a.align,index:a.index});if(b!==void 0){const{scrollOffset:w,scrollTarget:m}=b,x=Math.max(0,Math.min(w,We(m,e)));if(Math.abs(x-de(m,e))>1)a.stableFrames=0,m.scrollTo({behavior:"instant",[h?"top":"left"]:x});else{const S=i.current;if(!(S.some(N=>fe(N)===a.index)&&S.every(N=>{const L=fe(N);if(L===void 0||L>=s)return!0;const j=h?N.offsetHeight:N.offsetWidth;return Math.abs(r(L).size-j)<=1})))a.stableFrames=0;else if(++a.stableFrames>=2){d();return}}}f()});return B(()=>{const a=n??t;if(!a)return;const b=w=>{switch(w.key){case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":case"PageUp":case"PageDown":case"Home":case"End":case" ":d()}};return a.addEventListener("wheel",d,{passive:!0}),a.addEventListener("touchstart",d,{passive:!0}),a.addEventListener("pointerdown",d),a.addEventListener("keydown",b),()=>{d(),a.removeEventListener("wheel",d),a.removeEventListener("touchstart",d),a.removeEventListener("pointerdown",d),a.removeEventListener("keydown",b)}},[d,t,n]),l.useCallback(({align:a="auto",behavior:b="auto",index:w})=>{if(o&&a==="smart"){const x=v({align:"auto",index:w});a=x===void 0||x.scrollOffset===de(x.scrollTarget,e)?"auto":"center"}const m=v({align:a,index:w});if(d(),m&&typeof m.scrollTarget.scrollTo=="function"){const{scrollOffset:x,scrollTarget:S}=m;o&&(g.current={align:a,index:w,deadline:performance.now()+1e3,stableFrames:0},f()),S.scrollTo({behavior:o?"instant":b,[h?"top":"left"]:x})}},[d,e,o,h,f,v])}function qe({callback:e,element:t,enabled:r=!0}){const o=re(e);l.useEffect(()=>{if(!r||!t)return;const s=X(t);let i=s.requestAnimationFrame(()=>{i=s.requestAnimationFrame(o)});return()=>{s.cancelAnimationFrame(i)}},[t,r,o])}function ce(e){return e!=null&&typeof e=="object"&&"getAverageRowHeight"in e&&typeof e.getAverageRowHeight=="function"}const we="data-react-window-sizer";function De({children:e,className:t,defaultHeight:r=0,defaultScrollOffset:o=0,listRef:s,onResize:i,onRowsRendered:n,overscanCount:v=3,rowComponent:h,rowCount:g,rowHeight:u,rowKey:d,rowProps:f,scrollElement:c,tagName:a="div",style:b,...w}){const m=Re(f),x=l.useMemo(()=>l.memo(h,ye),[h]),[S,W]=l.useState(null),R=ce(u),N=l.useMemo(()=>R?k=>u.getRowHeight(k)??u.getAverageRowHeight():u,[R,u]),L=Oe(),[j,F]=l.useState(()=>L&&R),G=l.useRef(u);B(()=>{j&&G.current!==u&&F(!1)},[j,u]),qe({callback:()=>F(!1),element:S,enabled:j});const{getCellBounds:P,getEstimatedSize:Y,scrollTarget:Q,getScrollPositionForIndex:M,startIndexOverscan:I,startIndexVisible:H,stopIndexOverscan:O,stopIndexVisible:Z}=ae({containerElement:S,containerStyle:b,defaultContainerSize:r,defaultScrollOffset:o,direction:"vertical",itemCount:g,itemProps:m,itemSize:N,onResize:i,overscanCount:v,scrollElement:c}),ee=l.useRef([]),z=Te({direction:"vertical",element:S,getCellBounds:P,isDynamicSize:R,itemCount:g,itemElements:ee,scrollTarget:Q,getScrollPositionForIndex:M});l.useImperativeHandle(s,()=>({get element(){return S},scrollToRow:z}),[S,z]),B(()=>{if(!S)return;const k=Array.from(S.children).slice(0,I<0?0:O-I+1).filter((V,T)=>{if(V.hasAttribute(we))return!1;const y=`${I+T}`;return V.setAttribute(Me,y),!0});if(ee.current=k,R)return u.observeRowElements(k)},[x,S,R,g,u,d,m,I,O]),l.useEffect(()=>{I>=0&&O>=0&&n&&n({startIndex:H,stopIndex:Z},{startIndex:I,stopIndex:O})},[n,I,H,O,Z]);const p=j&&R&&I===0,A=l.useMemo(()=>{const k=[];if(g>0)for(let V=I;V<=O;V++){const T=P(V);k.push(l.createElement(x,{...m,ariaAttributes:{"aria-posinset":V+1,"aria-setsize":g,role:"listitem"},key:d?d(V,m):V,index:V,style:p?{width:"100%"}:{position:"absolute",left:0,transform:`translateY(${T.scrollOffset}px)`,height:R?void 0:T.size,width:"100%"}}))}return k},[x,P,R,p,g,d,m,I,O]),C=le.jsx("div",{"aria-hidden":!0,[we]:"",style:{position:p?"absolute":void 0,top:p?0:void 0,height:Y(),width:"100%",zIndex:-1}},"sizer"),E=le.jsx(l.Fragment,{children:e},"children"),_=le.jsx(l.Fragment,{children:A},"rows");return l.createElement(a,{role:"list",...w,className:t,ref:W,style:{position:"relative",flexGrow:1,...c===void 0&&{maxHeight:"100%",overflowY:"auto"},...b}},...p?[E,_]:[_,E],C)}function me(e){const t=new Map;return e!==void 0&&e.forEach((r,o)=>{Number.isFinite(r)&&r>0&&t.set(o,r)}),t}function Ge({defaultRowHeight:e,initialRowHeights:t,key:r}){const[o,s]=l.useState(()=>({key:r,map:me(t)}));o.key!==r&&s({key:r,map:me(t)});const{map:i}=o,n=l.useCallback(()=>{let f=0;return i.forEach(c=>{f+=c}),f===0?e:f/i.size},[e,i]),v=l.useCallback(f=>{const c=i.get(f);return c!==void 0?c:e},[e,i]),h=l.useCallback((f,c)=>{s(a=>{if(a.map.get(f)===c)return a;const b=new Map(a.map);return b.set(f,c),{...a,map:b}})},[]),g=re(f=>{f.length!==0&&f.forEach(c=>{const{borderBoxSize:a,target:b}=c,w=fe(b);if(w===void 0)return;const{blockSize:m}=a[0];m&&h(w,m)})}),u=l.useRef(null);l.useEffect(()=>()=>{u.current?.resizeObserver.disconnect(),u.current=null},[]);const d=l.useCallback(f=>{const c=[];return f.forEach(a=>{const b=X(a);if(u.current?.view!==b){u.current?.resizeObserver.disconnect();const m=ue(a);u.current=m?{resizeObserver:new m(g),view:b}:null}const w=u.current?.resizeObserver;w&&(w.observe(a),c.push([a,w]))}),()=>{c.forEach(([a,b])=>b.unobserve(a))}},[g]);return l.useMemo(()=>({getAverageRowHeight:n,getRowHeight:v,setRowHeight:h,observeRowElements:d}),[n,v,h,d])}const Ue=l.useState,$e=l.useRef,Xe={};function Ye({count:e,defaultScrollOffset:t=0,defaultSize:r=0,dir:o,direction:s="vertical",element:i,itemSize:n,onItemsRendered:v,overscanCount:h=3,scrollElement:g}){const u=ce(n);$(!u||s==="vertical","Dynamic item sizes are only supported for vertical content");const d=l.useMemo(()=>ce(n)?M=>n.getRowHeight(M)??n.getAverageRowHeight():n,[n]),f=Ie(i,o),{getCellBounds:c,getEstimatedSize:a,scrollTarget:b,getScrollPositionForIndex:w,startIndexOverscan:m,startIndexVisible:x,stopIndexOverscan:S,stopIndexVisible:W}=ae({containerElement:i,defaultContainerSize:r,defaultScrollOffset:t,direction:s,isRtl:s==="horizontal"&&f,itemCount:e,itemProps:Xe,itemSize:d,onResize:void 0,overscanCount:h,scrollElement:g}),R=l.useRef(new Set),N=l.useRef(new WeakSet),L=l.useRef([]),j=l.useRef({dynamicRowHeight:null,unobserve:new Map}),F=l.useCallback(M=>{M!==null&&R.current.add(M)},[]),G=i;B(()=>{const M=R.current,I=j.current,H=ce(n)?n:null;I.dynamicRowHeight?.observeRowElements!==H?.observeRowElements&&(I.unobserve.forEach(O=>O()),I.unobserve.clear()),I.dynamicRowHeight=H,M.forEach(O=>{if(!O.isConnected)M.delete(O),I.unobserve.get(O)?.(),I.unobserve.delete(O);else if(H&&G!==null&&!I.unobserve.has(O)){if(fe(O)===void 0){N.current.has(O)||(N.current.add(O),console.warn("useVirtualizer: Items passed to measureElement must specify their index with a data-index attribute",O));return}I.unobserve.set(O,H.observeRowElements([O]))}}),L.current=Array.from(M)}),l.useEffect(()=>{const M=j.current;return()=>{M.unobserve.forEach(I=>I()),M.unobserve.clear(),M.dynamicRowHeight=null}},[]);const P=Te({direction:s,element:i,getCellBounds:c,isDynamicSize:u,itemCount:e,itemElements:L,scrollTarget:b,getScrollPositionForIndex:w});l.useEffect(()=>{m>=0&&S>=0&&v&&v({startIndex:x,stopIndex:W},{startIndex:m,stopIndex:S})},[v,m,x,S,W]);const Y=l.useMemo(()=>{const M=[];if(e>0)for(let I=m;I<=S;I++){const{scrollOffset:H,size:O}=c(I);M.push({index:I,offset:H,size:O})}return M},[e,c,m,S]),Q=a();return l.useMemo(()=>({items:Y,measureElement:F,scrollToIndex:P,totalSize:Q,visibleRange:{startIndex:x,stopIndex:W}}),[Y,F,P,x,W,Q])}function Ze(e,{delay:t=150}={}){const[r,o]=l.useState(!1);return B(()=>{if(!e)return;const s=e==="window"?window:X(e),i=e==="window"?s:e,n="onscrollend"in s;let v,h=0;const g=()=>{performance.now()-h>=t?(v=void 0,o(!1)):v=s.requestAnimationFrame(g)},u=()=>{o(!0),n||(h=performance.now(),v===void 0&&(v=s.requestAnimationFrame(g)))},d=()=>{o(!1)};return i.addEventListener("scroll",u,{passive:!0}),n&&i.addEventListener("scrollend",d),()=>{i.removeEventListener("scroll",u),i.removeEventListener("scrollend",d),v!==void 0&&s.cancelAnimationFrame(v),o(!1)}},[t,e]),r}const xe=new WeakMap;function Je(e=!1,t=typeof document<"u"?document:void 0){if(t===void 0)return 0;let r=xe.get(t);if(r===void 0||e){const o=t.createElement("div"),s=o.style;s.width="50px",s.height="50px",s.overflow="scroll",t.body.appendChild(o),r=o.offsetWidth-o.clientWidth,t.body.removeChild(o),xe.set(t,r)}return r}exports.Grid=je;exports.List=De;exports.getScrollbarSize=Je;exports.useDynamicRowHeight=Ge;exports.useGridCallbackRef=Pe;exports.useGridRef=Be;exports.useIsScrolling=Ze;exports.useListCallbackRef=Ue;exports.useListRef=$e;exports.useVirtualizer=Ye;
|
|
2
2
|
//# sourceMappingURL=react-window.cjs.map
|