virtua 0.4.0 → 0.4.2
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 +31 -4
- package/lib/core/resizer.d.ts +4 -3
- package/lib/core/scroller.d.ts +5 -0
- package/lib/core/store.d.ts +3 -3
- package/lib/index.d.ts +4 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +1 -1
- package/lib/index.mjs.map +1 -1
- package/lib/react/ListItem.d.ts +22 -0
- package/lib/react/VList.d.ts +3 -10
- package/lib/react/WVList.d.ts +75 -0
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ If you want to check the difference with the alternatives right away, [see compa
|
|
|
11
11
|
This project is a challenge to rethink virtualization. The goals are...
|
|
12
12
|
|
|
13
13
|
- **Zero configuration:** This library is designed to give the best performance without configuration. It also handles common hard things in the real world (dynamic size measurement, scroll position adjustment in bottom-up scrolling and imperative scrolling, etc).
|
|
14
|
-
- **Fast:** Scrolling without frame drop needs optimization in many aspects (reduce CPU usage, reduce GC, [reduce layout recalculation](https://gist.github.com/paulirish/5d52fb081b3570c81e3a), optimize for frameworks, etc). We are trying to combine the best of them.
|
|
14
|
+
- **Fast:** Scrolling without frame drop needs optimization in many aspects (reduce CPU usage, reduce GC, [reduce layout recalculation](https://gist.github.com/paulirish/5d52fb081b3570c81e3a), optimize with CSS, optimize for frameworks, etc). We are trying to combine the best of them.
|
|
15
15
|
- **Small:** Its bundle size should be small as much as possible to be friendly with modern web development. Currently each components are ~3kB gzipped and the total is [~4kB gzipped](https://bundlephobia.com/package/virtua).
|
|
16
16
|
- **Flexible:** Aiming to support many usecases - fixed size, dynamic size, horizontal scrolling, reverse scrolling, rtl direction, sticky, infinite scrolling, placeholder, scrollTo, dnd, table, and more. See [live demo](#demo).
|
|
17
17
|
- **Framework agnostic (WIP):** Currently only for [React](https://react.dev/) but we could support [Vue](https://vuejs.org/), [Svelte](https://svelte.dev/), [Solid](https://www.solidjs.com/), [Angular](https://angular.io/), [Web Components](https://developer.mozilla.org/en-US/docs/Web/API/Web_components) and more in the future.
|
|
@@ -110,6 +110,33 @@ export const App = () => {
|
|
|
110
110
|
};
|
|
111
111
|
```
|
|
112
112
|
|
|
113
|
+
### Window scroll
|
|
114
|
+
|
|
115
|
+
```tsx
|
|
116
|
+
import { WVList } from "virtua";
|
|
117
|
+
|
|
118
|
+
export const App = () => {
|
|
119
|
+
return (
|
|
120
|
+
<div style={{ padding: 200 }}>
|
|
121
|
+
<WVList>
|
|
122
|
+
{Array.from({ length: 1000 }).map((_, i) => (
|
|
123
|
+
<div
|
|
124
|
+
key={i}
|
|
125
|
+
style={{
|
|
126
|
+
height: Math.floor(Math.random() * 10) * 10 + 10,
|
|
127
|
+
borderBottom: "solid 1px gray",
|
|
128
|
+
background: "white",
|
|
129
|
+
}}
|
|
130
|
+
>
|
|
131
|
+
{i}
|
|
132
|
+
</div>
|
|
133
|
+
))}
|
|
134
|
+
</WVList>
|
|
135
|
+
</div>
|
|
136
|
+
);
|
|
137
|
+
};
|
|
138
|
+
```
|
|
139
|
+
|
|
113
140
|
### React Server Components (RSC) support
|
|
114
141
|
|
|
115
142
|
This library is marked as a Client Component. You can render RSC as children of VList.
|
|
@@ -150,12 +177,12 @@ WIP
|
|
|
150
177
|
|
|
151
178
|
| | [virtua](https://github.com/inokawa/virtua) | [react-virtuoso](https://github.com/petyosi/react-virtuoso) | [react-window](https://github.com/bvaughn/react-window) | [react-virtualized](https://github.com/bvaughn/react-virtualized) | [@tanstack/react-virtual](https://github.com/TanStack/virtual) | [react-cool-virtual](https://github.com/wellyshen/react-cool-virtual) |
|
|
152
179
|
| :------------------------------------------------- | :------------------------------------------------------- | :---------------------------------------------------------------- | :------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------ | :-------------------------------------------------------------------- |
|
|
153
|
-
| Bundle size | [4.
|
|
180
|
+
| Bundle size | [4.8kB gzipped](https://bundlephobia.com/package/virtua) | [16.3kB gzipped](https://bundlephobia.com/package/react-virtuoso) | [6.4kB gzipped](https://bundlephobia.com/package/react-window) | [27.3kB gzipped](https://bundlephobia.com/package/react-virtualized) | [2.3kB gzipped](https://bundlephobia.com/package/@tanstack/react-virtual) | [3.1kB gzipped](https://bundlephobia.com/package/react-cool-virtual) |
|
|
154
181
|
| Vertical scroll | ✅ | ✅ | ✅ | ✅ | 🟠 (needs customization) | 🟠 (needs customization) |
|
|
155
182
|
| Horizontal scroll | ✅ | ❌ | ✅ | ✅ | 🟠 (needs customization) | 🟠 (needs customization) |
|
|
156
|
-
| Grid (Virtualization for two dimension) | ✅
|
|
183
|
+
| Grid (Virtualization for two dimension) | ✅ (VGrid) | ❌ | ✅ (FixedSizeGrid / VariableSizeGrid) | ✅ ([Grid](https://github.com/bvaughn/react-virtualized/blob/master/docs/Grid.md)) | 🟠 (needs customization) | 🟠 (needs customization) |
|
|
157
184
|
| Table | 🟠 (needs customization) | ✅ (TableVirtuoso) | 🟠 (needs customization) | ✅ ([Table](https://github.com/bvaughn/react-virtualized/blob/master/docs/Table.md)) | 🟠 (needs customization) | 🟠 (needs customization) |
|
|
158
|
-
| Window scroller |
|
|
185
|
+
| Window scroller | ✅ (WVList) | ✅ | ❌ | ✅ ([WindowScroller](https://github.com/bvaughn/react-virtualized/blob/master/docs/WindowScroller.md)) | ✅ | ❌ |
|
|
159
186
|
| Dynamic list size | ✅ | ✅ | 🟠 (needs [AutoSizer](https://github.com/bvaughn/react-virtualized/blob/master/docs/AutoSizer.md)) | 🟠 (needs [AutoSizer](https://github.com/bvaughn/react-virtualized/blob/master/docs/AutoSizer.md)) | ✅ | ✅ |
|
|
160
187
|
| Dynamic item size | ✅ | ✅ | 🟠 (needs additional codes and has wrong destination when scrolling to item imperatively) | 🟠 (needs [CellMeasurer](https://github.com/bvaughn/react-virtualized/blob/master/docs/CellMeasurer.md) and has wrong destination when scrolling to item imperatively) | 🟠 (has wrong destination when scrolling to item imperatively) | 🟠 (has wrong destination when scrolling to item imperatively) |
|
|
161
188
|
| Reverse scroll | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
package/lib/core/resizer.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { VirtualStore } from "./store";
|
|
2
|
-
export
|
|
2
|
+
export interface ListResizer {
|
|
3
3
|
_observeRoot(root: HTMLElement): () => void;
|
|
4
4
|
_observeItem(el: HTMLElement, i: number): () => void;
|
|
5
|
-
}
|
|
6
|
-
export
|
|
5
|
+
}
|
|
6
|
+
export declare const createResizer: (store: VirtualStore, isHorizontal: boolean) => ListResizer;
|
|
7
|
+
export declare const createWindowResizer: (store: VirtualStore, isHorizontal: boolean) => ListResizer;
|
|
7
8
|
export declare const createGridResizer: (vStore: VirtualStore, hStore: VirtualStore) => {
|
|
8
9
|
_observeRoot(root: HTMLElement): () => void;
|
|
9
10
|
_observeItem(el: HTMLElement, rowIndex: number, colIndex: number): () => void;
|
package/lib/core/scroller.d.ts
CHANGED
|
@@ -7,3 +7,8 @@ export type Scroller = {
|
|
|
7
7
|
_fixScrollJump: (jump: ScrollJump) => void;
|
|
8
8
|
};
|
|
9
9
|
export declare const createScroller: (store: VirtualStore, isHorizontal: boolean, isRtl: boolean) => Scroller;
|
|
10
|
+
export type WindowScroller = {
|
|
11
|
+
_initRoot: (rootElement: HTMLElement) => () => void;
|
|
12
|
+
_fixScrollJump: (jump: ScrollJump) => void;
|
|
13
|
+
};
|
|
14
|
+
export declare const createWindowScroller: (store: VirtualStore, isHorizontal: boolean) => WindowScroller;
|
package/lib/core/store.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export type ScrollJump = Readonly<number>;
|
|
2
2
|
export type ItemResize = Readonly<[index: number, size: number]>;
|
|
3
3
|
type ItemsRange = Readonly<[startIndex: number, endIndex: number]>;
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const SCROLL_IDLE = 0;
|
|
5
5
|
export declare const SCROLL_DOWN = 1;
|
|
6
6
|
export declare const SCROLL_UP = 2;
|
|
7
7
|
export declare const SCROLL_MANUAL = 3;
|
|
8
|
-
type ScrollDirection = typeof
|
|
8
|
+
type ScrollDirection = typeof SCROLL_IDLE | typeof SCROLL_DOWN | typeof SCROLL_UP | typeof SCROLL_MANUAL;
|
|
9
9
|
export declare const ACTION_ITEM_RESIZE = 1;
|
|
10
10
|
export declare const ACTION_WINDOW_RESIZE = 2;
|
|
11
11
|
export declare const ACTION_SCROLL = 3;
|
|
@@ -22,7 +22,7 @@ export type VirtualStore = {
|
|
|
22
22
|
_getScrollOffset(): number;
|
|
23
23
|
_getViewportSize(): number;
|
|
24
24
|
_getScrollSize(): number;
|
|
25
|
-
|
|
25
|
+
_getCorrectedScrollSize(): number;
|
|
26
26
|
_getJumpCount(): number;
|
|
27
27
|
_flushJump(): ScrollJump | undefined;
|
|
28
28
|
_getItemIndexForScrollTo(offset: number): number;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export { VList } from "./react/VList";
|
|
2
|
-
export type { VListProps, VListHandle,
|
|
2
|
+
export type { VListProps, VListHandle, ScrollMode } from "./react/VList";
|
|
3
3
|
export { VGrid } from "./react/VGrid";
|
|
4
4
|
export type { VGridProps, VGridHandle, CustomCellComponent, CustomCellComponentProps, } from "./react/VGrid";
|
|
5
|
+
export { WVList } from "./react/WVList";
|
|
6
|
+
export type { WVListProps } from "./react/WVList";
|
|
5
7
|
export type { WindowComponentAttributes, CustomWindowComponent, CustomWindowComponentProps, } from "./react/DefaultWindow";
|
|
8
|
+
export type { CustomItemComponent, CustomItemComponentProps, } from "./react/ListItem";
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
var e=require("react/jsx-runtime"),t=require("react"),r=require("react-dom");const n=Math.min,o=Math.max,l=Math.abs,i=Date.now,s=setTimeout,c=e=>null!=e,u=(e,t)=>Array.from({length:e},((e,r)=>t(r))),a=e=>{let t,r;return(...n)=>(t||(t=!0,r=e(...n)),r)},_=-1,d=(e,t)=>{const r=e.t[t];return r===_?e.o:r},h=(e,t,r)=>{if(!e.l)return 0;if(e.i>=t)return r?e.u[t]+d(e,t):e.u[t];let n=e.i,o=e.u[n];for(;n<=t&&(e.u[n]=o,n!==t||r);)o+=d(e,n),n++;return e.i=t,o},f=(e,t)=>h(e,t),g=(e,t,r)=>{let l=0;if(r>=0)for(;t<e.l-1;){const n=d(e,t++);if((l+=n)>=r){l-n/2>=r&&t--;break}}else for(;t>0;){const n=d(e,--t);if((l-=n)<=r){l+n/2<r&&t++;break}}return n(o(t,0),e.l-1)},m=(e,t,r,n)=>g(e,r,t-n),w=(e,t,r)=>({o:r?r.o:t,l:e,i:r?n(r.i,e-1):0,t:u(e,(e=>{const t=r&&r.t[e];return c(t)?t:_})),u:u(e,(e=>{if(0===e)return 0;const t=r&&r.u[e];return c(t)?t:_}))}),v=e=>e.reduce(((e,[t])=>e+t),0),S=(e,t)=>t.map((([t,r])=>[r-d(e,t),t])),p=(e,t,r=0,i,u,a)=>{const p=!t,z=t||40;let b,I,x=z*o(r-1,0),y=0,R=0,T=w(e,z),k=0,M=!1,C=[0,r];const O=new Set,H=()=>(e=>h(e,e.l-1,!0))(T),D=e=>{const t=k;return k=e,0!==k&&(0===t&&(1===k||2===k)||void 0)};return{_(){const[e,t]=C,r=f(T,e),n=m(T,y,e,r),o=g(T,n,x);return e===n&&t===o?C:C=[n,o]},h:e=>T.t[e]===_,g:e=>((e,t,r)=>{for(let n=t;n<=r;n++)if(e.t[n]===_)return!0;return!1})(T,o(0,e-2),n(T.l-1,e+2)),m(e){const t=f(T,e);return i?t+o(0,x-H()):t},v:e=>d(T,e),S:()=>y,p:()=>x,I:()=>H(),R:()=>o(H(),x),T:()=>R,k(){const e=b;return b=void 0,e},M:e=>m(T,e,0,0),C:()=>(I&&I[1](),new Promise(((e,t)=>{let r=!1;const n=()=>{r||(r=!0,e(),I=void 0)};I=[n,t],s(n,250)}))),O:e=>(O.add(e),()=>{O.delete(e)}),H(e,t){let r,o,i=!1;switch(e){case 1:{const e=t.filter((([e,t])=>T.t[e]!==t));if(!e.length)break;let o=0;if(2===k)o=v(S(T,e));else if(3===k){const t=S(T,e),[r]=C;0===y||(o=H()<=y+x?v(t):v(t.filter((([,e])=>e<r))))}o&&(b=o,R++);let l=!1;e.forEach((([e,t])=>{((e,t,r)=>{const o=e.t[t]===_;return e.t[t]=r,e.i=n(t,e.i),o})(T,e,t)&&(l=!0)})),p&&l&&!y&&(e=>{const t=e.t.filter((e=>e!==_)),r=t[0];e.o=t.every((e=>e===r))?r:(e=>{const t=[...e].sort(((e,t)=>e-t)),r=e.length/2|0;return t.length%2==0?(t[r-1]+t[r])/2:t[r]})(t)})(T),M=r=i=!0;break}case 2:i=x!==t,x=t;break;case 3:case 4:if(y===t)break;if(3===e){const e=(()=>{const e=M;return M=!1,e})();0!==k&&e||3===k||(o=D(y>t?2:1)),r=l(y-t)>x}y=t,i=!0;break;case 5:o=D(t?3:0)}i&&(O.forEach((e=>{e(r)})),3===e&&a(y)),I&&1===e&&I[0](),c(o)&&u(o)},D:()=>k,W(e){T.l!==e&&(T=w(e,z,T))}}},z="undefined"!=typeof window?t.useLayoutEffect:t.useEffect,b="current",I=e=>{const r=t.useRef(e);return z((()=>{r[b]=e}),[e]),r},x=(e,n,o)=>{const[l,i]=t.useState(n),s=I(n);if(t.useLayoutEffect((()=>{const t=()=>{i((()=>s[b]()))};return e.O((e=>{e?r.flushSync(t):t()}))}),[]),o){const e=n();l!==e&&i(e)}return l},y=a((e=>{const t="scrollLeft",r=e[t];e[t]=1;const n=e[t]<1;return e[t]=r,n})),R=(e,t,r)=>{let l;const u=t?"scrollLeft":"scrollTop",a=()=>l?t?l.scrollWidth:l.scrollHeight:0,_=(t,r)=>y(l)||r?-t:e.I()-e.p()-t,d=(e,n)=>{l&&(t&&r&&(e=_(e,n)),n?l[u]+=e:l[u]=e)},h=async(t,r)=>{const n=()=>{let t=r();const n=a(),o=e.p();return n-(t+o)<=0&&(t=n-o),t};for(;e.H(4,n()),e.g(t);)try{await e.C()}catch(e){return}d(n()),e.H(5,!0)};return{$(n){l=n;const o=()=>{let o=n[u];t&&r&&(o=_(o)),e.H(3,o)},a=(()=>{let t;const r=()=>{c(t)&&clearTimeout(t)},n=()=>{r(),t=s((()=>{t=null,o(),e.H(5,!1)}),150)};return n.q=r,n})(),d=()=>{o(),a()},h=(()=>{let r=i()-50;return(...n)=>{const o=i();r+50<o&&(r=o,(r=>{if(0!==e.D()&&!r.ctrlKey&&(t?r.deltaX:r.deltaY)){const t=e.S();t>0&&t<e.I()-e.p()&&a()}})(...n))}})();return n.addEventListener("scroll",d),n.addEventListener("wheel",h,{passive:!0}),()=>{n.removeEventListener("scroll",d),n.removeEventListener("wheel",h),a.q()}},J:a,L(t){t=o(t,0),h(e.M(t),(()=>t))},A(t,r){t=o(n(t,r-1),0),h(t,(()=>e.m(t)))},B:e=>{d(e,!0)}}},T=e=>{const r=t.useRef();return r[b]||(r[b]=e())},k=(e,t)=>{let r;const n=t?"width":"height",o=new WeakMap,l=a((()=>new ResizeObserver((t=>{const l=[];for(const{target:i,contentRect:s}of t)if(i===r)e.H(2,s[n]);else{const e=o.get(i);c(e)&&l.push([e,s[n]])}l.length&&e.H(1,l)}))));return{F(e){r=e;const t=l();return t.observe(e),()=>{t.disconnect()}},U(e,t){const r=l();return o.set(e,t),r.observe(e),()=>{o.delete(e),r.unobserve(e)}}}},M=(e,t)=>{let r;const n="height",l="width",i=new WeakMap,s=new Set,c=new Set,u=new Map,_=(e,t)=>`${e}-${t}`,d=a((()=>new ResizeObserver((a=>{const d=new Set,h=new Set;for(const{target:o,contentRect:s}of a)if(o===r)e.H(2,s[n]),t.H(2,s[l]);else{const e=i.get(o);if(e){const[t,r]=e,o=_(t,r),i=u.get(o),c=[s[n],s[l]];let a,f;i?(i[0]!==c[0]&&(a=!0),i[1]!==c[1]&&(f=!0)):a=f=!0,a&&d.add(t),f&&h.add(r),(a||f)&&u.set(o,c)}}if(d.size){const t=[];d.forEach((e=>{let r=0;c.forEach((t=>{const n=u.get(_(e,t));n&&(r=o(r,n[0]))})),r&&t.push([e,r])})),e.H(1,t)}if(h.size){const e=[];h.forEach((t=>{let r=0;s.forEach((e=>{const n=u.get(_(e,t));n&&(r=o(r,n[1]))})),r&&e.push([t,r])})),t.H(1,e)}}))));return{F(e){r=e;const t=d();return t.observe(e),()=>{t.disconnect()}},U(e,t,r){const n=d();return i.set(e,[t,r]),s.add(t),c.add(r),n.observe(e),()=>{i.delete(e),n.unobserve(e)}}}},C=t.forwardRef((({children:r,attrs:n,width:o,height:l,scrolling:i},s)=>e.jsx("div",{ref:s,...n,children:e.jsx("div",{style:t.useMemo((()=>({position:"relative",visibility:"hidden",width:null!=o?o:"100%",height:null!=l?l:"100%",pointerEvents:i?"none":"auto"})),[o,l,i]),children:r})}))),O=t.memo((({j:r,P:n,V:o,G:l,K:i,N:s,X:c})=>{const u=t.useRef(null),a=x(o,(()=>o.m(l)),!0),_=x(o,(()=>o.h(l)),!0);return z((()=>n.U(u[b],l)),[l]),e.jsx(i,{ref:u,style:t.useMemo((()=>{const e=c?"right":"left",t={margin:0,padding:0,position:"absolute",[s?"height":"width"]:"100%",[s?"top":e]:0,[s?e:"top"]:a,visibility:_?"hidden":"visible"};return s&&(t.display="flex"),t}),[a,_]),children:r})})),H=({j:r,Y:n,V:o,K:l,Z:i,ee:s,N:c})=>{const u=x(o,o.I);return e.jsx(l,{ref:n,width:c?u:void 0,height:c?void 0:u,scrolling:i,attrs:t.useMemo((()=>({...s,style:{overflow:c?"auto hidden":"hidden auto",contain:"strict",width:"100%",height:"100%",padding:0,margin:0,...s.style}})),[s]),children:r})},D=t.forwardRef((({children:r,overscan:l=4,initialItemSize:i,initialItemCount:s,horizontal:u,mode:a,element:_=C,itemElement:d="div",onScroll:h,onScrollStop:f,onRangeChange:g,...m},w)=>{const v=t.useMemo((()=>{const e=[];return t.Children.forEach(r,(t=>{(e=>!c(e)||"boolean"==typeof e)(t)||e.push(t)})),e}),[r]),S=v.length,y=I(h),M=I(f),[D,W]=t.useState(!1),[$,q,E,J,L]=T((()=>{const e=!!u,t="rtl"===a,r=p(S,i,s,"reverse"===a,(e=>{W(e),e||M[b]&&M[b]()}),(e=>{y[b]&&y[b](e)}));return[r,k(r,e),R(r,e,t),e,t]}));$.W(S);const[A,B]=x($,$._),F=x($,$.T),U=t.useRef(null);z((()=>{const e=U[b],t=q.F(e),r=E.$(e);return()=>{t(),r()}}),[]),z((()=>{const e=$.k();e&&E.B(e)}),[F]),t.useEffect((()=>{g&&g({start:A,end:B,count:S})}),[A,B]),t.useImperativeHandle(w,(()=>({get scrollOffset(){return $.S()},get scrollSize(){return E.J()},get viewportSize(){return $.p()},scrollToIndex(e){E.A(e,S)},scrollTo:E.L,scrollBy(e){E.L($.S()+e)}})),[S]);const j=o(A-l,0),P=n(B+l,S-1),V=t.useMemo((()=>{const t=[];for(let r=j;r<=P;r++){const n=v[r];c(n)&&t.push(e.jsx(O,{P:q,V:$,G:r,K:d,j:n,N:J,X:L},(null==n?void 0:n.key)||r))}return t}),[v,j,P]);return e.jsx(H,{Y:U,V:$,K:_,Z:D,j:V,ee:m,N:J})})),W=(e,t)=>`${e}-${t}`,$=t.memo((({j:r,P:n,te:o,re:l,ne:i,oe:s,K:c,X:u})=>{const a=t.useRef(null),_=x(o,(()=>o.m(i)),!0),d=x(l,(()=>l.m(s)),!0),h=x(o,(()=>o.h(i)),!0),f=x(l,(()=>l.h(s)),!0),g=x(o,(()=>o.v(i)),!0),m=x(l,(()=>l.v(s)),!0);return z((()=>n.U(a[b],i,s)),[s,i]),e.jsx(c,{ref:a,style:t.useMemo((()=>({display:"grid",margin:0,padding:0,position:"absolute",top:_,[u?"right":"left"]:d,visibility:h||f?"hidden":"visible",minHeight:g,minWidth:m})),[_,d,m,g,h,f]),children:r})})),q=({j:r,Y:n,le:o,ie:l,K:i,Z:s,ee:c})=>{const u=x(o,o.I),a=x(l,l.I);return e.jsx(i,{ref:n,width:a,height:u,scrolling:s,attrs:t.useMemo((()=>({...c,style:{overflow:"auto",contain:"strict",width:"100%",height:"100%",padding:0,margin:0,...c.style}})),[c]),children:r})},E=t.forwardRef((({children:r,row:l,col:i,cellHeight:s=40,cellWidth:c=100,overscan:u=2,initialRowCount:a,initialColCount:_,rtl:d,element:h=C,cellElement:f="div",...g},m)=>{const[w,v]=t.useState(!1),[S,I]=t.useState(!1),[y,k,O,H,D,E]=T((()=>{const e=!!d,t=()=>{},r=p(l,s,a,!1,v,t),n=p(i,c,_,!1,I,t);return[r,n,M(r,n),R(r,!1,e),R(n,!0,e),e]}));y.W(l),k.W(i);const[J,L]=x(y,y._),[A,B]=x(k,k._),F=x(y,y.T),U=x(k,k.T),j=t.useRef(null);z((()=>{const e=j[b],t=O.F(e),r=H.$(e),n=D.$(e);return()=>{t(),r(),n()}}),[]),z((()=>{const e=y.k();e&&H.B(e)}),[F]),z((()=>{const e=k.k();e&&D.B(e)}),[U]),t.useImperativeHandle(m,(()=>({get scrollOffset(){return[k.S(),y.S()]},get scrollSize(){return[D.J(),H.J()]},get viewportSize(){return[k.p(),y.p()]},scrollToIndex(e,t){D.A(e,i),H.A(t,l)},scrollTo(e,t){D.L(e),H.L(t)},scrollBy(e,t){D.L(k.S()+e),H.L(y.S()+t)}})),[l,i]);const P=t.useMemo((()=>{const e=new Map;return(t,n)=>{let o=e.get(W(t,n));return o||e.set(W(t,n),o=r({rowIndex:t,colIndex:n})),o}}),[r]),V=o(J-u,0),G=n(L+u,l-1),K=o(A-u,0),N=n(B+u,i-1),Q=t.useMemo((()=>{const t=[];for(let r=V;r<=G;r++)for(let n=K;n<=N;n++)t.push(e.jsx($,{P:O,te:y,re:k,ne:r,oe:n,K:f,j:P(r,n),X:E},W(r,n)));return t}),[P,V,G,K,N]);return e.jsx(q,{Y:j,le:y,ie:k,K:h,Z:w||S,j:Q,ee:g})}));exports.VGrid=E,exports.VList=D;
|
|
2
|
+
var e=require("react/jsx-runtime"),t=require("react"),r=require("react-dom");const n=Math.min,o=Math.max,i=Math.abs,l=Date.now,s=setTimeout,c=e=>null!=e,u=(e,t)=>Array.from({length:e},((e,r)=>t(r))),a=(e,t)=>{let r;const n=()=>{c(r)&&clearTimeout(r)},o=()=>{n(),r=s((()=>{r=null,e()}),t)};return o.t=n,o},d=e=>{let t,r;return(...n)=>(t||(t=!0,r=e(...n)),r)},_=-1,h=(e,t)=>{const r=e.o[t];return r===_?e.i:r},f=(e,t,r)=>{if(!e.l)return 0;if(e.u>=t)return r?e._[t]+h(e,t):e._[t];let n=e.u,o=e._[n];for(;n<=t&&(e._[n]=o,n!==t||r);)o+=h(e,n),n++;return e.u=t,o},g=(e,t)=>f(e,t),w=(e,t,r)=>{let i=0;if(r>=0)for(;t<e.l-1;){const n=h(e,t++);if((i+=n)>=r){i-n/2>=r&&t--;break}}else for(;t>0;){const n=h(e,--t);if((i-=n)<=r){i+n/2<r&&t++;break}}return n(o(t,0),e.l-1)},m=(e,t,r,n)=>w(e,r,t-n),v=(e,t,r)=>({i:r?r.i:t,l:e,u:r?n(r.u,e-1):0,o:u(e,(e=>{const t=r&&r.o[e];return c(t)?t:_})),_:u(e,(e=>{if(0===e)return 0;const t=r&&r._[e];return c(t)?t:_}))}),p=e=>e.reduce(((e,[t])=>e+t),0),S=(e,t)=>t.map((([t,r])=>[r-h(e,t),t])),z=(e,t,r=0,l,u,a)=>{const d=!t,z=t||40;let b,I,x=z*o(r-1,0),R=0,y=0,k=v(e,z),T=0,C=!1,H=[0,r];const M=new Set,O=()=>(e=>f(e,e.l-1,!0))(k),W=e=>{const t=T;return T=e,0!==T&&(0===t&&(1===T||2===T)||void 0)};return{h(){const[e,t]=H,r=g(k,e),n=m(k,R,e,r),o=w(k,n,x);return e===n&&t===o?H:H=[n,o]},g:e=>k.o[e]===_,m:e=>((e,t,r)=>{for(let n=t;n<=r;n++)if(e.o[n]===_)return!0;return!1})(k,o(0,e-2),n(k.l-1,e+2)),v(e){const t=g(k,e);return l?t+o(0,x-O()):t},p:e=>h(k,e),S:()=>R,I:()=>x,R:()=>O(),k:()=>o(O(),x),T:()=>y,C(){const e=b;return b=void 0,e},H:e=>m(k,e,0,0),M:()=>(I&&I[1](),new Promise(((e,t)=>{let r=!1;const n=()=>{r||(r=!0,e(),I=void 0)};I=[n,t],s(n,250)}))),O:e=>(M.add(e),()=>{M.delete(e)}),W(e,t){let r,o,l=!1;switch(e){case 1:{const e=t.filter((([e,t])=>k.o[e]!==t));if(!e.length)break;let o=0;if(2===T)o=p(S(k,e));else if(3===T){const t=S(k,e),[r]=H;0===R||(o=O()<=R+x?p(t):p(t.filter((([,e])=>e<r))))}o&&(b=o,y++);let i=!1;e.forEach((([e,t])=>{((e,t,r)=>{const o=e.o[t]===_;return e.o[t]=r,e.u=n(t,e.u),o})(k,e,t)&&(i=!0)})),d&&i&&!R&&(e=>{const t=e.o.filter((e=>e!==_)),r=t[0];e.i=t.every((e=>e===r))?r:(e=>{const t=[...e].sort(((e,t)=>e-t)),r=e.length/2|0;return t.length%2==0?(t[r-1]+t[r])/2:t[r]})(t)})(k),C=r=l=!0;break}case 2:l=x!==t,x=t;break;case 3:case 4:if(R===t)break;if(3===e){const e=(()=>{const e=C;return C=!1,e})();0!==T&&e||3===T||(o=W(R>t?2:1)),r=i(R-t)>x}R=t,l=!0;break;case 5:o=W(t?3:0)}l&&(M.forEach((e=>{e(r)})),3===e&&a(R)),I&&1===e&&I[0](),c(o)&&u(o)},J:()=>T,L(e){k.l!==e&&(k=v(e,z,k))}}},b="undefined"!=typeof window?t.useLayoutEffect:t.useEffect,I="current",x=e=>!c(e)||"boolean"==typeof e,R=e=>{const r=t.useRef(e);return b((()=>{r[I]=e}),[e]),r},y=(e,n,o)=>{const[i,l]=t.useState(n),s=R(n);if(t.useLayoutEffect((()=>{const t=()=>{l((()=>s[I]()))};return e.O((e=>{e?r.flushSync(t):t()}))}),[]),o){const e=n();i!==e&&l(e)}return i},k=/*#__PURE__*/d((e=>{const t="scrollLeft",r=e[t];e[t]=1;const n=e[t]<1;return e[t]=r,n})),T=(e,t,r)=>(()=>{let n=l()-50;return(...o)=>{const i=l();n+50<i&&(n=i,(n=>{if(0!==e.J()&&!n.ctrlKey&&(t?n.deltaX:n.deltaY)){const t=e.S();t>0&&t<e.R()-e.I()&&r()}})(...o))}})(),C=(e,t,r)=>{let i;const l=t?"scrollLeft":"scrollTop",s=()=>i?t?i.scrollWidth:i.scrollHeight:0,c=(n,o)=>t&&r?k(i)||o?-n:e.R()-e.I()-n:n,u=async(t,r)=>{if(!i)return;const n=()=>{let t=r();const n=s(),o=e.I();return n-(t+o)<=0&&(t=n-o),t};for(;e.W(4,n()),e.m(t);)try{await e.M()}catch(e){return}i[l]=c(n()),e.W(5,!0)};return{$(r){i=r;const n=()=>{e.W(3,c(r[l]))},o=a((()=>{n(),e.W(5,!1)}),150),s=()=>{n(),o()},u=T(e,t,o);return r.addEventListener("scroll",s),r.addEventListener("wheel",u,{passive:!0}),()=>{r.removeEventListener("scroll",s),r.removeEventListener("wheel",u),o.t()}},q:s,D(t){t=o(t,0),u(e.H(t),(()=>t))},A(t,r){t=o(n(t,r-1),0),u(t,(()=>e.v(t)))},B:e=>{i&&(i[l]+=c(e,!0))}}},H=(e,t)=>{const r=t?"scrollX":"scrollY",n=t?"offsetLeft":"offsetTop";return{$(o){let i=!1;const l=(e,t)=>{const r=t+e[n],o=e.offsetParent;return e!==document.body&&o?l(o,r):r},s=()=>{i&&e.W(3,window[r]-l(o,0))},c=a((()=>{s(),e.W(5,!1)}),150),u=()=>{s(),c()},d=T(e,t,c),_=new IntersectionObserver((([e])=>{i=e.isIntersecting}));return _.observe(o),window.addEventListener("scroll",u),window.addEventListener("wheel",d,{passive:!0}),()=>{_.disconnect(),window.removeEventListener("scroll",u),window.removeEventListener("wheel",d),c.t()}},B:e=>{window.scrollBy(t?e:0,t?0:e)}}},M=e=>{const r=t.useRef();return r[I]||(r[I]=e())},O=(e,t)=>{let r;const n=t?"width":"height",o=new WeakMap,i=d((()=>new ResizeObserver((t=>{const i=[];for(const{target:l,contentRect:s}of t)if(l===r)e.W(2,s[n]);else{const e=o.get(l);c(e)&&i.push([e,s[n]])}i.length&&e.W(1,i)}))));return{F(e){r=e;const t=i();return t.observe(e),()=>{t.disconnect()}},U(e,t){const r=i();return o.set(e,t),r.observe(e),()=>{o.delete(e),r.unobserve(e)}}}},W=(e,t)=>{const r=t?"width":"height",n=t?"innerWidth":"innerHeight",o=new WeakMap,i=d((()=>new ResizeObserver((t=>{const n=[];for(const{target:e,contentRect:i}of t){const t=o.get(e);c(t)&&n.push([t,i[r]])}n.length&&e.W(1,n)}))));return{F(){const t=()=>{e.W(2,window[n])};return window.addEventListener("resize",t),t(),()=>{window.removeEventListener("resize",t)}},U(e,t){const r=i();return o.set(e,t),r.observe(e),()=>{o.delete(e),r.unobserve(e)}}}},E=(e,t)=>{let r;const n="height",i="width",l=new WeakMap,s=new Set,c=new Set,u=new Map,a=(e,t)=>`${e}-${t}`,_=d((()=>new ResizeObserver((d=>{const _=new Set,h=new Set;for(const{target:o,contentRect:s}of d)if(o===r)e.W(2,s[n]),t.W(2,s[i]);else{const e=l.get(o);if(e){const[t,r]=e,o=a(t,r),l=u.get(o),c=[s[n],s[i]];let d,f;l?(l[0]!==c[0]&&(d=!0),l[1]!==c[1]&&(f=!0)):d=f=!0,d&&_.add(t),f&&h.add(r),(d||f)&&u.set(o,c)}}if(_.size){const t=[];_.forEach((e=>{let r=0;c.forEach((t=>{const n=u.get(a(e,t));n&&(r=o(r,n[0]))})),r&&t.push([e,r])})),e.W(1,t)}if(h.size){const e=[];h.forEach((t=>{let r=0;s.forEach((e=>{const n=u.get(a(e,t));n&&(r=o(r,n[1]))})),r&&e.push([t,r])})),t.W(1,e)}}))));return{F(e){r=e;const t=_();return t.observe(e),()=>{t.disconnect()}},U(e,t,r){const n=_();return l.set(e,[t,r]),s.add(t),c.add(r),n.observe(e),()=>{l.delete(e),n.unobserve(e)}}}},J=t.forwardRef((({children:r,attrs:n,width:o,height:i,scrolling:l},s)=>e.jsx("div",{ref:s,...n,children:e.jsx("div",{style:t.useMemo((()=>({position:"relative",visibility:"hidden",width:null!=o?o:"100%",height:null!=i?i:"100%",pointerEvents:l?"none":"auto"})),[o,i,l]),children:r})}))),L=t.memo((({j:r,P:n,V:o,X:i,Y:l,G:s,K:c})=>{const u=t.useRef(null),a=y(o,(()=>o.v(i)),!0),d=y(o,(()=>o.g(i)),!0);return b((()=>n.U(u[I],i)),[i]),e.jsx(l,{ref:u,style:t.useMemo((()=>{const e=c?"right":"left",t={margin:0,padding:0,position:"absolute",[s?"height":"width"]:"100%",[s?"top":e]:0,[s?e:"top"]:a,visibility:d?"hidden":"visible"};return s&&(t.display="flex"),t}),[a,d]),children:r})})),$=({j:r,N:n,V:o,Y:i,Z:l,ee:s,G:c})=>{const u=y(o,o.k);return e.jsx(i,{ref:n,width:c?u:void 0,height:c?void 0:u,scrolling:l,attrs:t.useMemo((()=>({...s,style:{overflow:c?"auto hidden":"hidden auto",display:c?"inline-block":"block",contain:"strict",width:"100%",height:"100%",padding:0,margin:0,...s.style}})),[s]),children:r})},q=t.forwardRef((({children:r,overscan:i=4,initialItemSize:l,initialItemCount:s,horizontal:u,mode:a,element:d=J,itemElement:_="div",onScroll:h,onScrollStop:f,onRangeChange:g,...w},m)=>{const v=t.useMemo((()=>{const e=[];return t.Children.forEach(r,(t=>{x(t)||e.push(t)})),e}),[r]),p=v.length,S=R(h),k=R(f),[T,H]=t.useState(!1),[W,E,q,D,A]=M((()=>{const e=!!u,t="rtl"===a,r=z(p,l,s,"reverse"===a,(e=>{H(e),e||k[I]&&k[I]()}),(e=>{S[I]&&S[I](e)}));return[r,O(r,e),C(r,e,t),e,t]}));W.L(p);const[B,F]=y(W,W.h),U=y(W,W.T),j=t.useRef(null);b((()=>{const e=j[I],t=E.F(e),r=q.$(e);return()=>{t(),r()}}),[]),b((()=>{const e=W.C();e&&q.B(e)}),[U]),t.useEffect((()=>{g&&g({start:B,end:F,count:p})}),[B,F]),t.useImperativeHandle(m,(()=>({get scrollOffset(){return W.S()},get scrollSize(){return q.q()},get viewportSize(){return W.I()},scrollToIndex(e){q.A(e,p)},scrollTo:q.D,scrollBy(e){q.D(W.S()+e)}})),[p]);const P=o(B-i,0),V=n(F+i,p-1),X=t.useMemo((()=>{const t=[];for(let r=P;r<=V;r++){const n=v[r];c(n)&&t.push(e.jsx(L,{P:E,V:W,X:r,Y:_,j:n,G:D,K:A},(null==n?void 0:n.key)||r))}return t}),[v,P,V]);return e.jsx($,{N:j,V:W,Y:d,Z:T,j:X,ee:w,G:D})})),D=(e,t)=>`${e}-${t}`,A=t.memo((({j:r,P:n,te:o,re:i,ne:l,oe:s,Y:c,K:u})=>{const a=t.useRef(null),d=y(o,(()=>o.v(l)),!0),_=y(i,(()=>i.v(s)),!0),h=y(o,(()=>o.g(l)),!0),f=y(i,(()=>i.g(s)),!0),g=y(o,(()=>o.p(l)),!0),w=y(i,(()=>i.p(s)),!0);return b((()=>n.U(a[I],l,s)),[s,l]),e.jsx(c,{ref:a,style:t.useMemo((()=>({display:"grid",margin:0,padding:0,position:"absolute",top:d,[u?"right":"left"]:_,visibility:h||f?"hidden":"visible",minHeight:g,minWidth:w})),[d,_,w,g,h,f]),children:r})})),B=({j:r,N:n,ie:o,le:i,Y:l,Z:s,ee:c})=>{const u=y(o,o.k),a=y(i,i.k);return e.jsx(l,{ref:n,width:a,height:u,scrolling:s,attrs:t.useMemo((()=>({...c,style:{overflow:"auto",contain:"strict",width:"100%",height:"100%",padding:0,margin:0,...c.style}})),[c]),children:r})},F=t.forwardRef((({children:r,row:i,col:l,cellHeight:s=40,cellWidth:c=100,overscan:u=2,initialRowCount:a,initialColCount:d,rtl:_,element:h=J,cellElement:f="div",...g},w)=>{const[m,v]=t.useState(!1),[p,S]=t.useState(!1),[x,R,k,T,H,O]=M((()=>{const e=!!_,t=()=>{},r=z(i,s,a,!1,v,t),n=z(l,c,d,!1,S,t);return[r,n,E(r,n),C(r,!1,e),C(n,!0,e),e]}));x.L(i),R.L(l);const[W,L]=y(x,x.h),[$,q]=y(R,R.h),F=y(x,x.T),U=y(R,R.T),j=t.useRef(null);b((()=>{const e=j[I],t=k.F(e),r=T.$(e),n=H.$(e);return()=>{t(),r(),n()}}),[]),b((()=>{const e=x.C();e&&T.B(e)}),[F]),b((()=>{const e=R.C();e&&H.B(e)}),[U]),t.useImperativeHandle(w,(()=>({get scrollOffset(){return[R.S(),x.S()]},get scrollSize(){return[H.q(),T.q()]},get viewportSize(){return[R.I(),x.I()]},scrollToIndex(e,t){H.A(e,l),T.A(t,i)},scrollTo(e,t){H.D(e),T.D(t)},scrollBy(e,t){H.D(R.S()+e),T.D(x.S()+t)}})),[i,l]);const P=t.useMemo((()=>{const e=new Map;return(t,n)=>{let o=e.get(D(t,n));return o||e.set(D(t,n),o=r({rowIndex:t,colIndex:n})),o}}),[r]),V=o(W-u,0),X=n(L+u,i-1),Y=o($-u,0),G=n(q+u,l-1),K=t.useMemo((()=>{const t=[];for(let r=V;r<=X;r++)for(let n=Y;n<=G;n++)t.push(e.jsx(A,{P:k,te:x,re:R,ne:r,oe:n,Y:f,j:P(r,n),K:O},D(r,n)));return t}),[P,V,X,Y,G]);return e.jsx(B,{N:j,ie:x,le:R,Y:h,Z:m||p,j:K,ee:g})})),U=({j:r,N:n,V:o,Y:i,Z:l,ee:s,G:c})=>{const u=y(o,o.k);return e.jsx(i,{ref:n,width:c?u:void 0,height:c?void 0:u,scrolling:l,attrs:t.useMemo((()=>({...s,style:{overflow:"visible",display:c?"inline-block":"block",width:c?"auto":"100%",height:c?"100%":"auto",padding:0,margin:0,...s.style}})),[s]),children:r})};exports.VGrid=F,exports.VList=q,exports.WVList=({children:r,overscan:i=4,initialItemSize:l,initialItemCount:s,horizontal:u,element:a=J,itemElement:d="div",onScroll:_,onScrollStop:h,onRangeChange:f,...g})=>{const w=t.useMemo((()=>{const e=[];return t.Children.forEach(r,(t=>{x(t)||e.push(t)})),e}),[r]),m=w.length,v=R(_),p=R(h),[S,k]=t.useState(!1),[T,C,O,E]=M((()=>{const e=!!u,t=z(m,l,s,!1,(e=>{k(e),e||p[I]&&p[I]()}),(e=>{v[I]&&v[I](e)}));return[t,W(t,e),H(t,e),e]}));T.L(m);const[$,q]=y(T,T.h),D=y(T,T.T),A=t.useRef(null);b((()=>{const e=A[I],t=C.F(e),r=O.$(e);return()=>{t(),r()}}),[]),b((()=>{const e=T.C();e&&O.B(e)}),[D]),t.useEffect((()=>{f&&f({start:$,end:q,count:m})}),[$,q]);const B=o($-i,0),F=n(q+i,m-1),j=t.useMemo((()=>{const t=[];for(let r=B;r<=F;r++){const n=w[r];c(n)&&t.push(e.jsx(L,{P:C,V:T,X:r,Y:d,j:n,G:E,K:!1},(null==n?void 0:n.key)||r))}return t}),[w,B,F]);return e.jsx(U,{N:A,V:T,Y:a,Z:S,j,ee:g,G:E})};
|
|
3
3
|
//# sourceMappingURL=index.js.map
|