react-virtual-renderer 1.0.7 → 1.0.9
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/dist/components/VirtualGrid.d.ts.map +1 -1
- package/dist/components/VirtualGrid.js +137 -107
- package/dist/components/VirtualGrid.js.map +1 -1
- package/dist/components/VirtualList.d.ts +57 -5
- package/dist/components/VirtualList.d.ts.map +1 -1
- package/dist/components/VirtualList.js +366 -97
- package/dist/components/VirtualList.js.map +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/types.d.ts +7 -5
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,124 +1,393 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import React, {
|
|
2
|
+
// import React, {
|
|
3
|
+
// forwardRef,
|
|
4
|
+
// useEffect,
|
|
5
|
+
// useImperativeHandle,
|
|
6
|
+
// useRef,
|
|
7
|
+
// } from 'react';
|
|
8
|
+
// import { useVirtualList } from '../hooks/useVirtualList';
|
|
9
|
+
// import {
|
|
10
|
+
// VirtualListProps,
|
|
11
|
+
// RenderItemProps,
|
|
12
|
+
// } from '../types';
|
|
13
|
+
// /**
|
|
14
|
+
// * VirtualList Component
|
|
15
|
+
// * Drop-in replacement for long lists with virtualization support
|
|
16
|
+
// */
|
|
17
|
+
// export const VirtualList = forwardRef<
|
|
18
|
+
// HTMLDivElement,
|
|
19
|
+
// VirtualListProps<any>
|
|
20
|
+
// >(
|
|
21
|
+
// (
|
|
22
|
+
// {
|
|
23
|
+
// items,
|
|
24
|
+
// renderItem,
|
|
25
|
+
// itemWrapper,
|
|
26
|
+
// itemKey,
|
|
27
|
+
// height = 400,
|
|
28
|
+
// width = 500,
|
|
29
|
+
// itemSize,
|
|
30
|
+
// overscan = 5,
|
|
31
|
+
// scrollDirection = 'forward',
|
|
32
|
+
// onScroll,
|
|
33
|
+
// className = '',
|
|
34
|
+
// itemClassName = '',
|
|
35
|
+
// style = {},
|
|
36
|
+
// estimatedItemSize = 35,
|
|
37
|
+
// getItemSize,
|
|
38
|
+
// stickyIndices = [],
|
|
39
|
+
// onScrollEnd,
|
|
40
|
+
// innerRef,
|
|
41
|
+
// scrollOffsetRef,
|
|
42
|
+
// },
|
|
43
|
+
// containerRef
|
|
44
|
+
// ) => {
|
|
45
|
+
// const {
|
|
46
|
+
// virtualItems,
|
|
47
|
+
// isScrolling,
|
|
48
|
+
// scrollOffset,
|
|
49
|
+
// totalSize,
|
|
50
|
+
// containerRef: internalContainerRef,
|
|
51
|
+
// innerRef: internalInnerRef,
|
|
52
|
+
// getItemStyle,
|
|
53
|
+
// } = useVirtualList({
|
|
54
|
+
// items,
|
|
55
|
+
// getItemKey: itemKey,
|
|
56
|
+
// containerHeight:
|
|
57
|
+
// typeof height === 'number'
|
|
58
|
+
// ? height
|
|
59
|
+
// : 400,
|
|
60
|
+
// containerWidth:
|
|
61
|
+
// typeof width === 'number'
|
|
62
|
+
// ? width
|
|
63
|
+
// : 500,
|
|
64
|
+
// itemSize: getItemSize || itemSize,
|
|
65
|
+
// overscan,
|
|
66
|
+
// scrollDirection,
|
|
67
|
+
// estimatedItemSize,
|
|
68
|
+
// onScroll,
|
|
69
|
+
// onScrollEnd,
|
|
70
|
+
// stickyIndices,
|
|
71
|
+
// });
|
|
72
|
+
// /**
|
|
73
|
+
// * Local refs
|
|
74
|
+
// */
|
|
75
|
+
// const mergedContainerRef =
|
|
76
|
+
// useRef<HTMLDivElement | null>(null);
|
|
77
|
+
// const mergedInnerRef =
|
|
78
|
+
// useRef<HTMLDivElement | null>(null);
|
|
79
|
+
// /**
|
|
80
|
+
// * Expose container ref
|
|
81
|
+
// */
|
|
82
|
+
// useImperativeHandle(
|
|
83
|
+
// containerRef,
|
|
84
|
+
// () => mergedContainerRef.current as HTMLDivElement
|
|
85
|
+
// );
|
|
86
|
+
// /**
|
|
87
|
+
// * Expose inner ref
|
|
88
|
+
// */
|
|
89
|
+
// useImperativeHandle(
|
|
90
|
+
// innerRef,
|
|
91
|
+
// () => mergedInnerRef.current as HTMLDivElement
|
|
92
|
+
// );
|
|
93
|
+
// /**
|
|
94
|
+
// * Expose current scroll offset
|
|
95
|
+
// */
|
|
96
|
+
// useEffect(() => {
|
|
97
|
+
// if (scrollOffsetRef) {
|
|
98
|
+
// scrollOffsetRef.current =
|
|
99
|
+
// scrollOffset;
|
|
100
|
+
// }
|
|
101
|
+
// }, [scrollOffset, scrollOffsetRef]);
|
|
102
|
+
// /**
|
|
103
|
+
// * Container styles
|
|
104
|
+
// */
|
|
105
|
+
// const containerStyle: React.CSSProperties =
|
|
106
|
+
// {
|
|
107
|
+
// height,
|
|
108
|
+
// width,
|
|
109
|
+
// overflow: 'auto',
|
|
110
|
+
// position: 'relative',
|
|
111
|
+
// ...style,
|
|
112
|
+
// };
|
|
113
|
+
// /**
|
|
114
|
+
// * Inner wrapper styles
|
|
115
|
+
// */
|
|
116
|
+
// const innerStyle: React.CSSProperties = {
|
|
117
|
+
// position: 'relative',
|
|
118
|
+
// height: totalSize,
|
|
119
|
+
// width: '100%',
|
|
120
|
+
// };
|
|
121
|
+
// return (
|
|
122
|
+
// <div
|
|
123
|
+
// ref={(el) => {
|
|
124
|
+
// mergedContainerRef.current =
|
|
125
|
+
// el;
|
|
126
|
+
// internalContainerRef.current =
|
|
127
|
+
// el;
|
|
128
|
+
// }}
|
|
129
|
+
// className={`virtualize-container ${className}`}
|
|
130
|
+
// style={containerStyle}
|
|
131
|
+
// onScroll={(e) => {
|
|
132
|
+
// const target =
|
|
133
|
+
// e.target as HTMLElement;
|
|
134
|
+
// const handler = (
|
|
135
|
+
// renderItem as any
|
|
136
|
+
// )?.__scrollHandler;
|
|
137
|
+
// if (handler) {
|
|
138
|
+
// handler(e);
|
|
139
|
+
// }
|
|
140
|
+
// if (onScroll) {
|
|
141
|
+
// onScroll(
|
|
142
|
+
// target.scrollTop,
|
|
143
|
+
// 'auto'
|
|
144
|
+
// );
|
|
145
|
+
// }
|
|
146
|
+
// }}
|
|
147
|
+
// >
|
|
148
|
+
// <div
|
|
149
|
+
// ref={(el) => {
|
|
150
|
+
// mergedInnerRef.current =
|
|
151
|
+
// el;
|
|
152
|
+
// internalInnerRef.current =
|
|
153
|
+
// el;
|
|
154
|
+
// }}
|
|
155
|
+
// style={innerStyle}
|
|
156
|
+
// className="virtualize-inner"
|
|
157
|
+
// >
|
|
158
|
+
// {virtualItems.map(
|
|
159
|
+
// (virtualItem) => {
|
|
160
|
+
// const item =
|
|
161
|
+
// items[
|
|
162
|
+
// virtualItem.index
|
|
163
|
+
// ];
|
|
164
|
+
// const key = itemKey
|
|
165
|
+
// ? itemKey(
|
|
166
|
+
// virtualItem.index,
|
|
167
|
+
// item
|
|
168
|
+
// )
|
|
169
|
+
// : virtualItem.index;
|
|
170
|
+
// const virtualStyle =
|
|
171
|
+
// getItemStyle(
|
|
172
|
+
// virtualItem.index,
|
|
173
|
+
// virtualItem.size
|
|
174
|
+
// );
|
|
175
|
+
// const renderProps: RenderItemProps<any> =
|
|
176
|
+
// {
|
|
177
|
+
// item,
|
|
178
|
+
// index:
|
|
179
|
+
// virtualItem.index,
|
|
180
|
+
// /**
|
|
181
|
+
// * @deprecated
|
|
182
|
+
// * Kept only for backwards compatibility.
|
|
183
|
+
// * Avoid spreading this style in renderItem.
|
|
184
|
+
// */
|
|
185
|
+
// style:
|
|
186
|
+
// virtualStyle,
|
|
187
|
+
// isScrolling,
|
|
188
|
+
// };
|
|
189
|
+
// const content =
|
|
190
|
+
// renderItem(
|
|
191
|
+
// renderProps
|
|
192
|
+
// );
|
|
193
|
+
// /**
|
|
194
|
+
// * Advanced wrapper API
|
|
195
|
+
// */
|
|
196
|
+
// if (itemWrapper) {
|
|
197
|
+
// return (
|
|
198
|
+
// <React.Fragment
|
|
199
|
+
// key={key}
|
|
200
|
+
// >
|
|
201
|
+
// {itemWrapper({
|
|
202
|
+
// item,
|
|
203
|
+
// index:
|
|
204
|
+
// virtualItem.index,
|
|
205
|
+
// style:
|
|
206
|
+
// virtualStyle,
|
|
207
|
+
// children:
|
|
208
|
+
// content,
|
|
209
|
+
// })}
|
|
210
|
+
// </React.Fragment>
|
|
211
|
+
// );
|
|
212
|
+
// }
|
|
213
|
+
// /**
|
|
214
|
+
// * Default wrapper
|
|
215
|
+
// */
|
|
216
|
+
// return (
|
|
217
|
+
// <div
|
|
218
|
+
// key={key}
|
|
219
|
+
// data-virtualize-index={
|
|
220
|
+
// virtualItem.index
|
|
221
|
+
// }
|
|
222
|
+
// className={
|
|
223
|
+
// itemClassName
|
|
224
|
+
// }
|
|
225
|
+
// style={{
|
|
226
|
+
// ...virtualStyle,
|
|
227
|
+
// boxSizing:
|
|
228
|
+
// 'border-box',
|
|
229
|
+
// }}
|
|
230
|
+
// >
|
|
231
|
+
// {content}
|
|
232
|
+
// </div>
|
|
233
|
+
// );
|
|
234
|
+
// }
|
|
235
|
+
// )}
|
|
236
|
+
// </div>
|
|
237
|
+
// </div>
|
|
238
|
+
// );
|
|
239
|
+
// }
|
|
240
|
+
// );
|
|
241
|
+
// VirtualList.displayName = 'VirtualList';
|
|
242
|
+
// src/components/VirtualList.generic.tsx
|
|
243
|
+
// Fully Generic VirtualList - Production Ready with All Fixes
|
|
244
|
+
import React, { forwardRef, useEffect, useImperativeHandle, useRef, useCallback, useMemo, } from 'react';
|
|
3
245
|
import { useVirtualList } from '../hooks/useVirtualList';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
246
|
+
// ============================================
|
|
247
|
+
// VIRTUALGRID COMPONENT - FULLY GENERIC
|
|
248
|
+
// ============================================
|
|
249
|
+
export const VirtualList = forwardRef(({ items, renderItem, itemWrapper, itemKey, height = 400, width = 500, itemSize, overscan = 5, scrollDirection = 'forward', onScroll, className = '', itemClassName = '', style = {}, estimatedItemSize = 35, getItemSize, stickyIndices = [], innerRef, scrollOffsetRef, }, containerRef) => {
|
|
250
|
+
// ✅ FIX 1: Proper ref initialization
|
|
251
|
+
const mergedContainerRef = useRef(null);
|
|
252
|
+
const mergedInnerRef = useRef(null);
|
|
253
|
+
// ✅ FIX 2: Use virtual list hook with proper typing
|
|
9
254
|
const { virtualItems, isScrolling, scrollOffset, totalSize, containerRef: internalContainerRef, innerRef: internalInnerRef, getItemStyle, } = useVirtualList({
|
|
10
255
|
items,
|
|
11
256
|
getItemKey: itemKey,
|
|
12
|
-
containerHeight: typeof height === 'number'
|
|
13
|
-
|
|
14
|
-
: 400,
|
|
15
|
-
containerWidth: typeof width === 'number'
|
|
16
|
-
? width
|
|
17
|
-
: 500,
|
|
257
|
+
containerHeight: typeof height === 'number' ? height : 400,
|
|
258
|
+
containerWidth: typeof width === 'number' ? width : 500,
|
|
18
259
|
itemSize: getItemSize || itemSize,
|
|
19
260
|
overscan,
|
|
20
|
-
scrollDirection,
|
|
261
|
+
scrollDirection: 'forward',
|
|
21
262
|
estimatedItemSize,
|
|
22
263
|
onScroll,
|
|
23
|
-
onScrollEnd,
|
|
264
|
+
onScrollEnd: () => { },
|
|
24
265
|
stickyIndices,
|
|
25
266
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
267
|
+
// ✅ FIX 3: Proper container ref forwarding
|
|
268
|
+
useImperativeHandle(containerRef, () => {
|
|
269
|
+
const handle = mergedContainerRef.current;
|
|
270
|
+
if (!handle)
|
|
271
|
+
return {};
|
|
272
|
+
// Add imperative methods
|
|
273
|
+
return {
|
|
274
|
+
...handle,
|
|
275
|
+
scrollToItem: (index) => {
|
|
276
|
+
if (mergedContainerRef.current) {
|
|
277
|
+
const item = virtualItems.find(v => v.index === index);
|
|
278
|
+
if (item) {
|
|
279
|
+
const offset = getItemStyle(index, item.size).top;
|
|
280
|
+
if (typeof offset === 'number') {
|
|
281
|
+
mergedContainerRef.current.scrollTop = offset;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
scrollToOffset: (offset) => {
|
|
287
|
+
if (mergedContainerRef.current) {
|
|
288
|
+
mergedContainerRef.current.scrollTop = offset;
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
resetAfterIndex: () => {
|
|
292
|
+
// Reset logic here if needed
|
|
293
|
+
},
|
|
294
|
+
getScrollOffset: () => scrollOffset,
|
|
295
|
+
};
|
|
296
|
+
}, [virtualItems, getItemStyle, scrollOffset]);
|
|
297
|
+
// ✅ FIX 4: Expose inner ref
|
|
38
298
|
useImperativeHandle(innerRef, () => mergedInnerRef.current);
|
|
39
|
-
|
|
40
|
-
* Expose current scroll offset
|
|
41
|
-
*/
|
|
299
|
+
// ✅ FIX 5: Update scroll offset ref
|
|
42
300
|
useEffect(() => {
|
|
43
301
|
if (scrollOffsetRef) {
|
|
44
|
-
scrollOffsetRef.current =
|
|
45
|
-
scrollOffset;
|
|
302
|
+
scrollOffsetRef.current = scrollOffset;
|
|
46
303
|
}
|
|
47
304
|
}, [scrollOffset, scrollOffsetRef]);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
width
|
|
305
|
+
// ✅ FIX 6: Proper height/width conversion
|
|
306
|
+
const heightCss = useMemo(() => {
|
|
307
|
+
return typeof height === 'string' ? height : `${height}px`;
|
|
308
|
+
}, [height]);
|
|
309
|
+
const widthCss = useMemo(() => {
|
|
310
|
+
return typeof width === 'string' ? width : `${width}px`;
|
|
311
|
+
}, [width]);
|
|
312
|
+
// ✅ FIX 7: Memoized container style
|
|
313
|
+
const containerStyle = useMemo(() => ({
|
|
314
|
+
height: heightCss,
|
|
315
|
+
width: widthCss,
|
|
54
316
|
overflow: 'auto',
|
|
55
317
|
position: 'relative',
|
|
56
318
|
...style,
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
*/
|
|
61
|
-
const innerStyle = {
|
|
319
|
+
}), [heightCss, widthCss, style]);
|
|
320
|
+
// ✅ FIX 8: Memoized inner style
|
|
321
|
+
const innerStyle = useMemo(() => ({
|
|
62
322
|
position: 'relative',
|
|
63
|
-
height: totalSize,
|
|
323
|
+
height: Math.max(totalSize, 1), // Ensure at least 1px
|
|
64
324
|
width: '100%',
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
el;
|
|
71
|
-
}, className: `virtualize-container ${className}`, style: containerStyle, onScroll: (e) => {
|
|
72
|
-
const target = e.target;
|
|
73
|
-
const handler = renderItem?.__scrollHandler;
|
|
74
|
-
if (handler) {
|
|
75
|
-
handler(e);
|
|
76
|
-
}
|
|
325
|
+
}), [totalSize]);
|
|
326
|
+
// ✅ FIX 9: Proper scroll handler with error handling
|
|
327
|
+
const handleScroll = useCallback((e) => {
|
|
328
|
+
try {
|
|
329
|
+
const target = e.currentTarget;
|
|
77
330
|
if (onScroll) {
|
|
78
|
-
onScroll(target.scrollTop,
|
|
331
|
+
onScroll(target.scrollTop, scrollDirection);
|
|
79
332
|
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
333
|
+
}
|
|
334
|
+
catch (error) {
|
|
335
|
+
console.error('Error in VirtualList scroll handler:', error);
|
|
336
|
+
}
|
|
337
|
+
}, [onScroll, scrollDirection]);
|
|
338
|
+
// ✅ FIX 10: Refs assignment with null safety
|
|
339
|
+
const assignContainerRef = useCallback((el) => {
|
|
340
|
+
mergedContainerRef.current = el;
|
|
341
|
+
if (internalContainerRef) {
|
|
342
|
+
internalContainerRef.current = el;
|
|
343
|
+
}
|
|
344
|
+
}, [internalContainerRef]);
|
|
345
|
+
const assignInnerRef = useCallback((el) => {
|
|
346
|
+
mergedInnerRef.current = el;
|
|
347
|
+
if (internalInnerRef) {
|
|
348
|
+
internalInnerRef.current = el;
|
|
349
|
+
}
|
|
350
|
+
}, [internalInnerRef]);
|
|
351
|
+
// ✅ FIX 11: Render with proper error handling and null checks
|
|
352
|
+
return (_jsx("div", { ref: assignContainerRef, className: `virtualize-container ${className}`, style: containerStyle, onScroll: handleScroll, role: "presentation", children: _jsx("div", { ref: assignInnerRef, style: innerStyle, className: "virtualize-inner", role: "presentation", children: virtualItems.length === 0 && items.length === 0 ? (
|
|
353
|
+
// ✅ FIX 12: Empty state handling
|
|
354
|
+
_jsx("div", { style: { padding: '20px', textAlign: 'center', color: '#999' }, children: "No items to display" })) : (virtualItems.map((virtualItem) => {
|
|
355
|
+
try {
|
|
356
|
+
const item = items[virtualItem.index];
|
|
357
|
+
// ✅ FIX 13: Null item handling
|
|
358
|
+
if (!item) {
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
const key = itemKey?.(virtualItem.index, item) ??
|
|
362
|
+
virtualItem.index;
|
|
363
|
+
const virtualStyle = getItemStyle(virtualItem.index, virtualItem.size);
|
|
364
|
+
const renderProps = {
|
|
365
|
+
item,
|
|
366
|
+
index: virtualItem.index,
|
|
367
|
+
isScrolling,
|
|
368
|
+
};
|
|
369
|
+
const content = renderItem(renderProps);
|
|
370
|
+
// ✅ FIX 14: Support custom wrapper
|
|
371
|
+
if (itemWrapper) {
|
|
372
|
+
return (_jsx(React.Fragment, { children: itemWrapper({
|
|
373
|
+
item,
|
|
374
|
+
index: virtualItem.index,
|
|
375
|
+
style: virtualStyle,
|
|
376
|
+
children: content,
|
|
377
|
+
}) }, key));
|
|
378
|
+
}
|
|
379
|
+
// ✅ FIX 15: Default wrapper with proper styling
|
|
380
|
+
return (_jsx("div", { "data-virtualize-index": virtualItem.index, className: itemClassName, style: {
|
|
381
|
+
...virtualStyle,
|
|
382
|
+
boxSizing: 'border-box',
|
|
383
|
+
}, role: "presentation", children: content }, key));
|
|
384
|
+
}
|
|
385
|
+
catch (error) {
|
|
386
|
+
console.error(`Error rendering item at index ${virtualItem.index}:`, error);
|
|
387
|
+
return null;
|
|
113
388
|
}
|
|
114
|
-
|
|
115
|
-
* Default wrapper
|
|
116
|
-
*/
|
|
117
|
-
return (_jsx("div", { "data-virtualize-index": virtualItem.index, className: itemClassName, style: {
|
|
118
|
-
...virtualStyle,
|
|
119
|
-
boxSizing: 'border-box',
|
|
120
|
-
}, children: content }, key));
|
|
121
|
-
}) }) }));
|
|
389
|
+
})) }) }));
|
|
122
390
|
});
|
|
123
391
|
VirtualList.displayName = 'VirtualList';
|
|
392
|
+
export default VirtualList;
|
|
124
393
|
//# sourceMappingURL=VirtualList.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VirtualList.js","sourceRoot":"","sources":["../../src/components/VirtualList.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,EACV,UAAU,EACV,SAAS,EACT,mBAAmB,EACnB,MAAM,
|
|
1
|
+
{"version":3,"file":"VirtualList.js","sourceRoot":"","sources":["../../src/components/VirtualList.tsx"],"names":[],"mappings":";AAAA,kBAAkB;AAClB,kBAAkB;AAClB,iBAAiB;AACjB,2BAA2B;AAC3B,cAAc;AACd,kBAAkB;AAElB,4DAA4D;AAC5D,WAAW;AACX,wBAAwB;AACxB,uBAAuB;AACvB,qBAAqB;AAErB,MAAM;AACN,2BAA2B;AAC3B,oEAAoE;AACpE,MAAM;AACN,yCAAyC;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AM,YAAY,GAAG,YAAY,CAC7B,WAAW,CAAC,KAAK,EACjB,WAAW,CAAC,IAAI,CACnB,CAAC;oBAEF,MAAM,WAAW,GAAyB;wBACtC,IAAI;wBACJ,KAAK,EAAE,WAAW,CAAC,KAAK;wBACxB,WAAW;qBACd,CAAC;oBAEF,MAAM,OAAO,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;oBAExC,mCAAmC;oBACnC,IAAI,WAAW,EAAE,CAAC;wBACd,OAAO,CACH,KAAC,KAAK,CAAC,QAAQ,cACV,WAAW,CAAC;gCACT,IAAI;gCACJ,KAAK,EAAE,WAAW,CAAC,KAAK;gCACxB,KAAK,EAAE,YAAY;gCACnB,QAAQ,EAAE,OAAO;6BACpB,CAAC,IANe,GAAG,CAOP,CACpB,CAAC;oBACN,CAAC;oBAED,gDAAgD;oBAChD,OAAO,CACH,uCAE2B,WAAW,CAAC,KAAK,EACxC,SAAS,EAAE,aAAa,EACxB,KAAK,EAAE;4BACH,GAAG,YAAY;4BACf,SAAS,EAAE,YAAY;yBAC1B,EACD,IAAI,EAAC,cAAc,YAElB,OAAO,IATH,GAAG,CAUN,CACT,CAAC;gBACN,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACb,OAAO,CAAC,KAAK,CACT,iCAAiC,WAAW,CAAC,KAAK,GAAG,EACrD,KAAK,CACR,CAAC;oBACF,OAAO,IAAI,CAAC;gBAChB,CAAC;YACL,CAAC,CAAC,CACL,GACC,GACJ,CACT,CAAC;AACN,CAAC,CACJ,CAAC;AAEF,WAAW,CAAC,WAAW,GAAG,aAAa,CAAC;AAExC,eAAe,WAAW,CAAC"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("react/jsx-runtime"),t=require("react");class r{constructor(e=35){Object.defineProperty(this,"itemSizeMap",{enumerable:!0,configurable:!0,writable:!0,value:{}}),Object.defineProperty(this,"estimatedItemSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"itemCount",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"prefix",{enumerable:!0,configurable:!0,writable:!0,value:[0]}),Object.defineProperty(this,"dirty",{enumerable:!0,configurable:!0,writable:!0,value:!0}),this.estimatedItemSize=e}setItemCount(e){this.itemCount=e,this.dirty=!0}recordItemSize(e,t){this.itemSizeMap[e]!==t&&(this.itemSizeMap[e]=t,this.dirty=!0)}rebuildPrefix(){let e=0;this.prefix=[0];for(let t=0;t<this.itemCount;t++)e+=this.itemSizeMap[t]??this.estimatedItemSize,this.prefix[t+1]=e;this.dirty=!1}getItemSize(e){return this.itemSizeMap[e]??this.estimatedItemSize}getItemOffset(e){return this.dirty&&this.rebuildPrefix(),this.prefix[e]??0}getTotalSize(){return this.dirty&&this.rebuildPrefix(),this.prefix[this.itemCount]||0}binarySearch(e){this.dirty&&this.rebuildPrefix();let t=0,r=this.itemCount-1;for(;t<=r;){const n=t+r>>1,i=this.prefix[n];if(i===e)return n;i<e?t=n+1:r=n-1}return Math.max(0,t-1)}getVisibleRange(e,t,r,n=5){this.setItemCount(r);const i=this.binarySearch(e),s=this.binarySearch(e+t);return{startIndex:Math.max(0,i-n),endIndex:Math.min(r-1,s+n),overscanStartIndex:i,overscanEndIndex:s}}getVisibleItems(e,t,r,n){const i=this.getVisibleRange(e,t,r,n),s=[];for(let e=i.startIndex;e<=i.endIndex;e++)s.push({index:e,size:this.getItemSize(e),offset:this.getItemOffset(e)});return s}getScrollOffsetForIndex(e,t,r="start"){const n=this.getItemOffset(e),i=this.getItemSize(e);return"center"===r?Math.max(0,n-(t-i)/2):"end"===r?Math.max(0,n-t+i):Math.max(0,n)}}class n{constructor(){Object.defineProperty(this,"resizeObserver",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"measurements",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"observedElements",{enumerable:!0,configurable:!0,writable:!0,value:new WeakMap}),Object.defineProperty(this,"pendingUpdates",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"rafId",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"onMeasure",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"handleResize",{enumerable:!0,configurable:!0,writable:!0,value:e=>{for(const t of e){const e=t.target,r=this.observedElements.get(e);if(void 0===r)continue;const n=Math.round(t.contentRect.height);this.measurements.get(r)!==n&&(this.measurements.set(r,n),this.pendingUpdates.set(r,n))}this.flushPendingUpdates()}}),"undefined"!=typeof window&&"ResizeObserver"in window&&(this.resizeObserver=new ResizeObserver(this.handleResize))}startMeasuring(e,t){this.onMeasure=t;e.querySelectorAll("[data-virtualize-index]").forEach(e=>{const t=e.dataset.virtualizeIndex;if(void 0===t)return;const r=Number(t);this.observeItem(r,e)})}observeItem(e,t){t.dataset.virtualizeIndex=String(e),this.observedElements.set(t,e),this.resizeObserver?.observe(t),this.syncMeasure(e,t)}unobserveItem(e){this.resizeObserver?.unobserve(e),this.observedElements.delete(e)}flushPendingUpdates(){null===this.rafId&&(this.rafId=requestAnimationFrame(()=>{this.pendingUpdates.forEach((e,t)=>{this.onMeasure?.(t,e)}),this.pendingUpdates.clear(),this.rafId=null}))}syncMeasure(e,t){const r=t.getBoundingClientRect().height;if(r<=0)return;const n=Math.round(r);this.measurements.get(e)!==n&&(this.measurements.set(e,n),this.onMeasure?.(e,n))}stopMeasuring(){this.resizeObserver?.disconnect(),this.pendingUpdates.clear(),null!==this.rafId&&cancelAnimationFrame(this.rafId)}getMeasurement(e){return this.measurements.get(e)}getAllMeasurements(){return new Map(this.measurements)}clearPending(){this.pendingUpdates.clear()}clearMeasurements(){this.measurements.clear()}destroy(){this.stopMeasuring(),this.measurements.clear(),this.pendingUpdates.clear(),this.observedElements=new WeakMap,this.onMeasure=null}}function i(e){const{items:i,containerHeight:s,overscan:o=5,scrollDirection:u="forward",estimatedItemSize:l=35,onScroll:a,onScrollEnd:c,stickyIndices:f=[]}=e,d=t.useRef(new r(l)),h=t.useRef(new n),m=t.useRef(null),g=t.useRef(null),[p,b]=t.useState(0),[y,v]=t.useState(!1),x=t.useRef(null),S=t.useRef(0),I=t.useRef(u),[w,M]=t.useState([]);t.useEffect(()=>{const e=d.current.getVisibleItems(p,s,i.length,o).map(e=>({index:e.index,offset:e.offset,size:e.size,isSticky:f.includes(e.index)}));M(t=>{if(t.length===e.length){let r=!1;for(let n=0;n<t.length;n++){const i=t[n],s=e[n];if(i.index!==s.index||i.offset!==s.offset||i.size!==s.size||i.isSticky!==s.isSticky){r=!0;break}}if(!r)return t}return e})},[p,s,i.length,o,f]);const z=t.useCallback(e=>{const t=e.currentTarget.scrollTop;if(t===S.current)return;const r=t>S.current?"forward":"reverse";I.current=r,S.current=t,b(t),v(!0),a&&a(t,r),x.current&&clearTimeout(x.current),x.current=setTimeout(()=>{v(!1),c&&c()},150)},[a,c]);t.useEffect(()=>{const e=m.current;if(!e)return;const t=e=>{z(e)};return e.addEventListener("scroll",t),()=>{e.removeEventListener("scroll",t)}},[z]);const R=t.useCallback((e,t)=>{d.current.recordItemSize(e,t)},[]);t.useEffect(()=>{const e=m.current;return e&&h.current.startMeasuring(e,R),()=>{h.current.stopMeasuring()}},[R]);const E=t.useCallback((e,t="start")=>{const r=d.current.getScrollOffsetForIndex(e,s,t);m.current&&(m.current.scrollTop=r)},[s]),O=t.useCallback(e=>{m.current&&(m.current.scrollTop=e)},[]),k=t.useCallback((e,t)=>{const r=d.current.getItemOffset(e),n=f.includes(e);return{position:n?"sticky":"absolute",top:n?0:r,left:0,width:"100%",height:t,zIndex:n?10:0}},[f]);t.useEffect(()=>()=>{x.current&&clearTimeout(x.current),h.current.destroy()},[]);const C=d.current.getTotalSize();return{virtualItems:w,isScrolling:y,scrollOffset:p,totalSize:C,scrollToItem:E,scrollToOffset:O,setScrollOffset:b,containerRef:m,innerRef:g,getItemStyle:k}}const s=t.forwardRef(({items:r,renderItem:n,itemWrapper:s,itemKey:o,height:u=400,width:l=500,itemSize:a,overscan:c=5,scrollDirection:f="forward",onScroll:d,className:h="",itemClassName:m="",style:g={},estimatedItemSize:p=35,getItemSize:b,stickyIndices:y=[],onScrollEnd:v,innerRef:x,scrollOffsetRef:S},I)=>{const{virtualItems:w,isScrolling:M,scrollOffset:z,totalSize:R,containerRef:E,innerRef:O,getItemStyle:k}=i({items:r,containerHeight:"number"==typeof u?u:400,overscan:c,scrollDirection:f,estimatedItemSize:p,onScroll:d,onScrollEnd:v,stickyIndices:y}),C=t.useRef(null),j=t.useRef(null);t.useImperativeHandle(I,()=>C.current),t.useImperativeHandle(x,()=>j.current),t.useEffect(()=>{S&&(S.current=z)},[z,S]);const P={height:u,width:l,overflow:"auto",position:"relative",...g},T={position:"relative",height:R,width:"100%"};return e.jsx("div",{ref:e=>{C.current=e,E.current=e},className:`virtualize-container ${h}`,style:P,onScroll:e=>{const t=e.target,r=n?.__scrollHandler;r&&r(e),d&&d(t.scrollTop,"auto")},children:e.jsx("div",{ref:e=>{j.current=e,O.current=e},style:T,className:"virtualize-inner",children:w.map(i=>{const u=r[i.index],l=o?o(i.index,u):i.index,a=k(i.index,i.size),c={item:u,index:i.index,style:a,isScrolling:M},f=n(c);return s?e.jsx(t.Fragment,{children:s({item:u,index:i.index,style:a,children:f})},l):e.jsx("div",{"data-virtualize-index":i.index,className:m,style:{...a,boxSizing:"border-box"},children:f},l)})})})});s.displayName="VirtualList";const o=t.forwardRef(({items:r,renderItem:n,itemKey:i,height:s=600,width:o="100%",columnCount:u=3,rowHeight:l=200,columnWidth:a,layout:c="grid",overscan:f=5,gap:d=16,onScroll:h,innerClassName:m,innerStyle:g},p)=>{const b=t.useRef(null);t.useImperativeHandle(p,()=>b.current);const[y,v]=t.useState(0),[x,S]=t.useState(!1),I=t.useRef(null),w=t.useMemo(()=>{if("number"==typeof o)return o;if("string"==typeof o){if(o.endsWith("%")){const e=b.current?.offsetWidth||window.innerWidth;return parseFloat(o)/100*e}const e=Number(o);return Number.isFinite(e)?e:800}return 800},[o]),M=t.useMemo(()=>{if("auto"===u){const e="number"==typeof o?o:b.current?.offsetWidth||800,t=250;return Math.max(1,Math.floor(e/t))}return Math.max(1,u)},[u,o]),z=t.useMemo(()=>{if("number"==typeof a)return a;return((Number.isFinite(w)?w:800)-d*(M-1))/M},[a,w,M,d]),R=t.useMemo(()=>{const e=[];if(!Number.isFinite(z))return e;if("masonry"===c){const t=Array(M).fill(0);for(let n=0;n<r.length;n++){const r=t.indexOf(Math.min(...t)),i="function"==typeof l?l(n):l;e.push({x:r*(z+d),y:t[r],width:z,height:i}),t[r]+=i+d}}else for(let t=0;t<r.length;t++){const r=Math.floor(t/M),n=t%M,i="function"==typeof l?l(t):l;e.push({x:n*(z+d),y:r*(i+d),width:z,height:i})}return e},[r,M,z,d,c,l]),E=t.useMemo(()=>{const e=R.findIndex(e=>e.y+e.height>=y),t=R.findIndex(e=>e.y>y+("number"==typeof s?s:600));return{start:Math.max(0,e-f),end:-1===t?r.length-1:Math.min(r.length-1,t+f)}},[R,y,s,f,r.length]),O=t.useMemo(()=>{if(!R.length)return 0;if("masonry"===c)return Math.max(...R.map(e=>e.y+e.height));return Math.ceil(r.length/M)*(("function"==typeof l?200:l)+d)},[R,c,r.length,M,l,d]);t.useEffect(()=>()=>{I.current&&clearTimeout(I.current)},[]);const k={height:s,width:o,overflowY:"auto",overflowX:"hidden",position:"relative",...g},C=Number.isFinite(z)?z:200,j={position:"relative",height:O,width:M*C+d*(M-1)};return e.jsx("div",{ref:b,className:m,style:k,onScroll:e=>{const t=e.currentTarget.scrollTop;v(t),S(!0),h?.(t,e.currentTarget.scrollLeft),I.current&&clearTimeout(I.current),I.current=setTimeout(()=>{S(!1)},120)},children:e.jsx("div",{style:j,children:Array.from({length:E.end-E.start+1},(t,s)=>{const o=E.start+s,u=r[o],l=R[o];if(!u||!l)return null;if(!Number.isFinite(l.width))return null;const a={position:"absolute",top:l.y,left:l.x,width:l.width,height:l.height};return e.jsx("div",{style:a,children:n({item:u,index:o,isScrolling:x,style:a})},i?.(o,u)??o)})})})});function u(e,t){return t?e:e.toLowerCase()}o.displayName="VirtualGrid";const l=new Map;exports.MeasurementSystem=n,exports.VirtualGrid=o,exports.VirtualList=s,exports.VirtualizationEngine=r,exports.useInfiniteScroll=function({onLoadMore:e,threshold:r=500,isLoading:n=!1,enabled:i=!0}){const s=t.useRef(null),[o,u]=t.useState(!1),l=t.useRef(!1),a=t.useRef(e);t.useEffect(()=>{a.current=e},[e]);const c=t.useCallback(()=>{if(!i||n)return;const e=s.current;if(!e)return;const{scrollTop:t,scrollHeight:o,clientHeight:c}=e,f=o-t-c<=r;u(f),!f||l.current||n||(l.current=!0,Promise.resolve(a.current()).finally(()=>{l.current=!1}))},[r,n,i]);return t.useEffect(()=>{if(!i)return;const e=s.current;if(!e)return;const t=()=>{c()};return e.addEventListener("scroll",t,{passive:!0}),c(),()=>{e.removeEventListener("scroll",t)}},[c,i]),{containerRef:s,isAtBottom:o,isLoading:n,checkIfAtBottom:c}},exports.useLazyLoad=function({threshold:e=.1,onVisible:r,root:n=null,rootMargin:i="0px",enabled:s=!0,once:o=!0}={}){const[u,l]=t.useState(!1),[a,c]=t.useState(null),f=t.useRef(null),d=t.useRef(r);return t.useEffect(()=>{d.current=r},[r]),t.useEffect(()=>{if(!s)return;const t=f.current;if(!t)return;if("undefined"==typeof window||!("IntersectionObserver"in window))return l(!0),void d.current?.();const r=new IntersectionObserver(([e])=>{c(e),e.isIntersecting?(l(!0),d.current?.(),o&&r.unobserve(e.target)):o||l(!1)},{threshold:e,root:n,rootMargin:i});return r.observe(t),()=>{r.disconnect()}},[e,n,i,s,o]),{ref:f,isVisible:u,entry:a}},exports.useScrollRestoration=function(e,r,{persist:n=!0,storageKey:i="virtualize-scroll-positions",storage:s,autoSave:o=!1,maxEntries:u=100,useRAF:a=!0,enabled:c=!0,onError:f}={}){const d=t.useRef(s??("undefined"!=typeof window&&"undefined"!=typeof document?window.localStorage:null));t.useEffect(()=>{if(c&&n&&d.current&&!(l.size>0))try{const e=d.current.getItem(i);if(!e)return;JSON.parse(e).forEach(e=>{l.set(e.key,e)})}catch(e){f?.(e)}},[c,n,i,f]);const h=t.useCallback(()=>{if(n&&d.current)try{const e=Array.from(l.values()).sort((e,t)=>t.timestamp-e.timestamp).slice(0,u);d.current.setItem(i,JSON.stringify(e))}catch(e){f?.(e)}},[n,i,u,f]),m=t.useCallback(()=>{if(!c)return;const t=r.current;if(!t)return;const n={key:e,top:t.scrollTop,left:t.scrollLeft,timestamp:Date.now()};l.set(e,n),h()},[e,r,c,h]),g=t.useCallback(()=>{if(!c)return;if(!r.current)return;const t=l.get(e);if(!t)return;const n=()=>{r.current&&(r.current.scrollTop=t.top,r.current.scrollLeft=t.left)};a?requestAnimationFrame(n):n()},[e,r,c,a]);return t.useEffect(()=>{c&&g()},[c,g]),t.useEffect(()=>{if(c)return()=>{m()}},[c,m]),t.useEffect(()=>{if(!c||!o||!r.current)return;const e=r.current,t=()=>{m()};return e.addEventListener("scroll",t,{passive:!0}),()=>{e.removeEventListener("scroll",t)}},[c,o,m,r]),{savePosition:m,restorePosition:g}},exports.useVirtualList=i,exports.useVirtualizedSearch=function({items:r,searchValue:n,searchFields:i,caseSensitive:s=!1,deferSearch:o=!0,matcher:l}){const a=t.useMemo(()=>u(n.trim(),s),[n,s]),c=t.useDeferredValue(a),f=o?c:a,d=o&&c!==a,h=t.useCallback(e=>!f||(l?l(e,f):function(e,t,r,n){return r.some(r=>{const i=e[r];return null!=i&&u(String(i).trim(),n).includes(t)})}(e,f,i,s)),[f,l,i,s]),m=t.useMemo(()=>f?r.filter(h):[...r],[r,f,h]),g=t.useCallback(e=>h(e),[h]),p=t.useMemo(()=>{if(!a)return null;const e=a.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`(${e})`,s?"g":"gi")},[a,s]),b=t.useCallback(r=>{if(!r||!p)return r;return r.split(p).map((r,n)=>n%2==1?e.jsx("mark",{children:r},n):e.jsx(t.Fragment,{children:r},n))},[p]);return{filteredItems:m,resultCount:m.length,query:f,hasMatch:g,isSearching:d,highlightMatch:b}};
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),t=require("react");class r{constructor(e=35){Object.defineProperty(this,"itemSizeMap",{enumerable:!0,configurable:!0,writable:!0,value:{}}),Object.defineProperty(this,"estimatedItemSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"itemCount",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"prefix",{enumerable:!0,configurable:!0,writable:!0,value:[0]}),Object.defineProperty(this,"dirty",{enumerable:!0,configurable:!0,writable:!0,value:!0}),this.estimatedItemSize=e}setItemCount(e){this.itemCount=e,this.dirty=!0}recordItemSize(e,t){this.itemSizeMap[e]!==t&&(this.itemSizeMap[e]=t,this.dirty=!0)}rebuildPrefix(){let e=0;this.prefix=[0];for(let t=0;t<this.itemCount;t++)e+=this.itemSizeMap[t]??this.estimatedItemSize,this.prefix[t+1]=e;this.dirty=!1}getItemSize(e){return this.itemSizeMap[e]??this.estimatedItemSize}getItemOffset(e){return this.dirty&&this.rebuildPrefix(),this.prefix[e]??0}getTotalSize(){return this.dirty&&this.rebuildPrefix(),this.prefix[this.itemCount]||0}binarySearch(e){this.dirty&&this.rebuildPrefix();let t=0,r=this.itemCount-1;for(;t<=r;){const n=t+r>>1,s=this.prefix[n];if(s===e)return n;s<e?t=n+1:r=n-1}return Math.max(0,t-1)}getVisibleRange(e,t,r,n=5){this.setItemCount(r);const s=this.binarySearch(e),i=this.binarySearch(e+t);return{startIndex:Math.max(0,s-n),endIndex:Math.min(r-1,i+n),overscanStartIndex:s,overscanEndIndex:i}}getVisibleItems(e,t,r,n){const s=this.getVisibleRange(e,t,r,n),i=[];for(let e=s.startIndex;e<=s.endIndex;e++)i.push({index:e,size:this.getItemSize(e),offset:this.getItemOffset(e)});return i}getScrollOffsetForIndex(e,t,r="start"){const n=this.getItemOffset(e),s=this.getItemSize(e);return"center"===r?Math.max(0,n-(t-s)/2):"end"===r?Math.max(0,n-t+s):Math.max(0,n)}}class n{constructor(){Object.defineProperty(this,"resizeObserver",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"measurements",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"observedElements",{enumerable:!0,configurable:!0,writable:!0,value:new WeakMap}),Object.defineProperty(this,"pendingUpdates",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"rafId",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"onMeasure",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"handleResize",{enumerable:!0,configurable:!0,writable:!0,value:e=>{for(const t of e){const e=t.target,r=this.observedElements.get(e);if(void 0===r)continue;const n=Math.round(t.contentRect.height);this.measurements.get(r)!==n&&(this.measurements.set(r,n),this.pendingUpdates.set(r,n))}this.flushPendingUpdates()}}),"undefined"!=typeof window&&"ResizeObserver"in window&&(this.resizeObserver=new ResizeObserver(this.handleResize))}startMeasuring(e,t){this.onMeasure=t;e.querySelectorAll("[data-virtualize-index]").forEach(e=>{const t=e.dataset.virtualizeIndex;if(void 0===t)return;const r=Number(t);this.observeItem(r,e)})}observeItem(e,t){t.dataset.virtualizeIndex=String(e),this.observedElements.set(t,e),this.resizeObserver?.observe(t),this.syncMeasure(e,t)}unobserveItem(e){this.resizeObserver?.unobserve(e),this.observedElements.delete(e)}flushPendingUpdates(){null===this.rafId&&(this.rafId=requestAnimationFrame(()=>{this.pendingUpdates.forEach((e,t)=>{this.onMeasure?.(t,e)}),this.pendingUpdates.clear(),this.rafId=null}))}syncMeasure(e,t){const r=t.getBoundingClientRect().height;if(r<=0)return;const n=Math.round(r);this.measurements.get(e)!==n&&(this.measurements.set(e,n),this.onMeasure?.(e,n))}stopMeasuring(){this.resizeObserver?.disconnect(),this.pendingUpdates.clear(),null!==this.rafId&&cancelAnimationFrame(this.rafId)}getMeasurement(e){return this.measurements.get(e)}getAllMeasurements(){return new Map(this.measurements)}clearPending(){this.pendingUpdates.clear()}clearMeasurements(){this.measurements.clear()}destroy(){this.stopMeasuring(),this.measurements.clear(),this.pendingUpdates.clear(),this.observedElements=new WeakMap,this.onMeasure=null}}function s(e){const{items:s,containerHeight:i,overscan:o=5,scrollDirection:l="forward",estimatedItemSize:a=35,onScroll:u,onScrollEnd:c,stickyIndices:f=[]}=e,d=t.useRef(new r(a)),h=t.useRef(new n),m=t.useRef(null),g=t.useRef(null),[p,b]=t.useState(0),[x,y]=t.useState(!1),v=t.useRef(null),S=t.useRef(0),I=t.useRef(l),[M,w]=t.useState([]);t.useEffect(()=>{const e=d.current.getVisibleItems(p,i,s.length,o).map(e=>({index:e.index,offset:e.offset,size:e.size,isSticky:f.includes(e.index)}));w(t=>{if(t.length===e.length){let r=!1;for(let n=0;n<t.length;n++){const s=t[n],i=e[n];if(s.index!==i.index||s.offset!==i.offset||s.size!==i.size||s.isSticky!==i.isSticky){r=!0;break}}if(!r)return t}return e})},[p,i,s.length,o,f]);const z=t.useCallback(e=>{const t=e.currentTarget.scrollTop;if(t===S.current)return;const r=t>S.current?"forward":"reverse";I.current=r,S.current=t,b(t),y(!0),u&&u(t,r),v.current&&clearTimeout(v.current),v.current=setTimeout(()=>{y(!1),c&&c()},150)},[u,c]);t.useEffect(()=>{const e=m.current;if(!e)return;const t=e=>{z(e)};return e.addEventListener("scroll",t),()=>{e.removeEventListener("scroll",t)}},[z]);const R=t.useCallback((e,t)=>{d.current.recordItemSize(e,t)},[]);t.useEffect(()=>{const e=m.current;return e&&h.current.startMeasuring(e,R),()=>{h.current.stopMeasuring()}},[R]);const E=t.useCallback((e,t="start")=>{const r=d.current.getScrollOffsetForIndex(e,i,t);m.current&&(m.current.scrollTop=r)},[i]),O=t.useCallback(e=>{m.current&&(m.current.scrollTop=e)},[]),k=t.useCallback((e,t)=>{const r=d.current.getItemOffset(e),n=f.includes(e);return{position:n?"sticky":"absolute",top:n?0:r,left:0,width:"100%",height:t,zIndex:n?10:0}},[f]);t.useEffect(()=>()=>{v.current&&clearTimeout(v.current),h.current.destroy()},[]);const C=d.current.getTotalSize();return{virtualItems:M,isScrolling:x,scrollOffset:p,totalSize:C,scrollToItem:E,scrollToOffset:O,setScrollOffset:b,containerRef:m,innerRef:g,getItemStyle:k}}const i=t.forwardRef(({items:r,renderItem:n,itemWrapper:i,itemKey:o,height:l=400,width:a=500,itemSize:u,overscan:c=5,scrollDirection:f="forward",onScroll:d,className:h="",itemClassName:m="",style:g={},estimatedItemSize:p=35,getItemSize:b,stickyIndices:x=[],innerRef:y,scrollOffsetRef:v},S)=>{const I=t.useRef(null),M=t.useRef(null),{virtualItems:w,isScrolling:z,scrollOffset:R,totalSize:E,containerRef:O,innerRef:k,getItemStyle:C}=s({items:r,containerHeight:"number"==typeof l?l:400,overscan:c,scrollDirection:"forward",estimatedItemSize:p,onScroll:d,onScrollEnd:()=>{},stickyIndices:x});t.useImperativeHandle(S,()=>{const e=I.current;return e?{...e,scrollToItem:e=>{if(I.current){const t=w.find(t=>t.index===e);if(t){const r=C(e,t.size).top;"number"==typeof r&&(I.current.scrollTop=r)}}},scrollToOffset:e=>{I.current&&(I.current.scrollTop=e)},resetAfterIndex:()=>{},getScrollOffset:()=>R}:{}},[w,C,R]),t.useImperativeHandle(y,()=>M.current),t.useEffect(()=>{v&&(v.current=R)},[R,v]);const j=t.useMemo(()=>"string"==typeof l?l:`${l}px`,[l]),T=t.useMemo(()=>"string"==typeof a?a:`${a}px`,[a]),P=t.useMemo(()=>({height:j,width:T,overflow:"auto",position:"relative",...g}),[j,T,g]),N=t.useMemo(()=>({position:"relative",height:Math.max(E,1),width:"100%"}),[E]),L=t.useCallback(e=>{try{const t=e.currentTarget;d&&d(t.scrollTop,f)}catch(e){console.error("Error in VirtualList scroll handler:",e)}},[d,f]),V=t.useCallback(e=>{I.current=e,O&&(O.current=e)},[O]),$=t.useCallback(e=>{M.current=e,k&&(k.current=e)},[k]);return e.jsx("div",{ref:V,className:`virtualize-container ${h}`,style:P,onScroll:L,role:"presentation",children:e.jsx("div",{ref:$,style:N,className:"virtualize-inner",role:"presentation",children:0===w.length&&0===r.length?e.jsx("div",{style:{padding:"20px",textAlign:"center",color:"#999"},children:"No items to display"}):w.map(s=>{try{const l=r[s.index];if(!l)return null;const a=o?.(s.index,l)??s.index,u=C(s.index,s.size),c={item:l,index:s.index,isScrolling:z},f=n(c);return i?e.jsx(t.Fragment,{children:i({item:l,index:s.index,style:u,children:f})},a):e.jsx("div",{"data-virtualize-index":s.index,className:m,style:{...u,boxSizing:"border-box"},role:"presentation",children:f},a)}catch(e){return console.error(`Error rendering item at index ${s.index}:`,e),null}})})})});i.displayName="VirtualList";const o=t.forwardRef(({items:r,renderItem:n,itemKey:s,height:i=600,width:o="100%",columnCount:l=3,rowHeight:a=200,columnWidth:u,layout:c="grid",overscan:f=5,gap:d=16,onScroll:h,onVisibleRangeChange:m,innerClassName:g,innerStyle:p,containerClassName:b,containerStyle:x},y)=>{const v=t.useRef(null);t.useImperativeHandle(y,()=>v.current);const[S,I]=t.useState(0),[M,w]=t.useState(!1),[z,R]=t.useState(0),E=t.useRef(null);t.useEffect(()=>{if(!v.current)return;const e=v.current,t=new ResizeObserver(e=>{for(const t of e){const e=t.contentRect.width;e>0&&R(e)}});return t.observe(e),()=>t.disconnect()},[]),t.useEffect(()=>()=>{E.current&&clearTimeout(E.current)},[]);const O=z>0&&r.length>0,k=t.useMemo(()=>{if("auto"===l){const e=200;return Math.max(1,Math.floor(z/(e+d)))}return Math.max(1,Number(l))},[l,z,d]),C=t.useMemo(()=>{if("number"==typeof u)return u;if(u&&"function"==typeof u)return u(0);const e=d*Math.max(0,k-1);return Math.max(50,(z-e)/k)},[u,z,k,d]),j=t.useMemo(()=>{if(!O)return[];const e=[];if("masonry"===c){const t=Array(k).fill(0);for(let n=0;n<r.length;n++){const r="function"==typeof a?a(n):Number(a),s=t.indexOf(Math.min(...t)),i=s*(C+d),o=t[s];e.push({x:i,y:o,width:C,height:r}),t[s]+=r+d}}else for(let t=0;t<r.length;t++){const r=Math.floor(t/k),n=t%k,s="function"==typeof a?a(t):Number(a);e.push({x:n*(C+d),y:r*(s+d),width:C,height:s})}return e},[r,k,C,d,c,a,O]),T=t.useMemo(()=>{if(!j.length||!O)return{start:0,end:0};const e="string"==typeof i?parseInt(i):Number(i);let t=0;for(let e=0;e<j.length;e++)if(j[e].y+j[e].height>=S){t=e;break}let n=j.length-1;for(let t=j.length-1;t>=0;t--)if(j[t].y<=S+e){n=t;break}return{start:Math.max(0,t-f),end:Math.min(r.length-1,n+f)}},[j,S,i,f,r.length,O]),P=t.useMemo(()=>{if(!j.length)return 0;return Math.max(...j.map(e=>e.y+e.height))||0},[j]),N=t.useCallback(e=>{const t=e.currentTarget,r=t.scrollTop,n=t.scrollLeft;I(r),w(!0),h?.(r,n),E.current&&clearTimeout(E.current),E.current=setTimeout(()=>{w(!1)},120)},[h]);t.useEffect(()=>{m?.(T.start,T.end)},[T,m]);const L={height:"string"==typeof i?i:`${i}px`,width:"string"==typeof o?o:`${o}px`,overflowY:"auto",overflowX:"hidden",position:"relative",...x},V={position:"relative",height:P||1,width:Math.max(0,k*C+(k-1)*d),...p};if(!O)return e.jsx("div",{ref:v,className:b,style:L,onScroll:N,children:e.jsx("div",{className:g,style:V})});const $=[];for(let e=T.start;e<=T.end;e++)e>=0&&e<r.length&&$.push({index:e,key:s?.(e,r[e])??e});return e.jsx("div",{ref:v,className:b,style:L,onScroll:N,children:e.jsx("div",{className:g,style:V,children:$.map(t=>{const s=r[t.index],i=j[t.index];if(!s||!i)return null;const o={position:"absolute",top:`${i.y}px`,left:`${i.x}px`,width:`${i.width}px`,height:`${i.height}px`,boxSizing:"border-box"};return e.jsx("div",{style:o,children:n({item:s,index:t.index,isScrolling:M})},t.key)})})})});function l(e,t){return t?e:e.toLowerCase()}o.displayName="VirtualGrid";const a=new Map;exports.MeasurementSystem=n,exports.VirtualGrid=o,exports.VirtualList=i,exports.VirtualizationEngine=r,exports.useInfiniteScroll=function({onLoadMore:e,threshold:r=500,isLoading:n=!1,enabled:s=!0}){const i=t.useRef(null),[o,l]=t.useState(!1),a=t.useRef(!1),u=t.useRef(e);t.useEffect(()=>{u.current=e},[e]);const c=t.useCallback(()=>{if(!s||n)return;const e=i.current;if(!e)return;const{scrollTop:t,scrollHeight:o,clientHeight:c}=e,f=o-t-c<=r;l(f),!f||a.current||n||(a.current=!0,Promise.resolve(u.current()).finally(()=>{a.current=!1}))},[r,n,s]);return t.useEffect(()=>{if(!s)return;const e=i.current;if(!e)return;const t=()=>{c()};return e.addEventListener("scroll",t,{passive:!0}),c(),()=>{e.removeEventListener("scroll",t)}},[c,s]),{containerRef:i,isAtBottom:o,isLoading:n,checkIfAtBottom:c}},exports.useLazyLoad=function({threshold:e=.1,onVisible:r,root:n=null,rootMargin:s="0px",enabled:i=!0,once:o=!0}={}){const[l,a]=t.useState(!1),[u,c]=t.useState(null),f=t.useRef(null),d=t.useRef(r);return t.useEffect(()=>{d.current=r},[r]),t.useEffect(()=>{if(!i)return;const t=f.current;if(!t)return;if("undefined"==typeof window||!("IntersectionObserver"in window))return a(!0),void d.current?.();const r=new IntersectionObserver(([e])=>{c(e),e.isIntersecting?(a(!0),d.current?.(),o&&r.unobserve(e.target)):o||a(!1)},{threshold:e,root:n,rootMargin:s});return r.observe(t),()=>{r.disconnect()}},[e,n,s,i,o]),{ref:f,isVisible:l,entry:u}},exports.useScrollRestoration=function(e,r,{persist:n=!0,storageKey:s="virtualize-scroll-positions",storage:i,autoSave:o=!1,maxEntries:l=100,useRAF:u=!0,enabled:c=!0,onError:f}={}){const d=t.useRef(i??("undefined"!=typeof window&&"undefined"!=typeof document?window.localStorage:null));t.useEffect(()=>{if(c&&n&&d.current&&!(a.size>0))try{const e=d.current.getItem(s);if(!e)return;JSON.parse(e).forEach(e=>{a.set(e.key,e)})}catch(e){f?.(e)}},[c,n,s,f]);const h=t.useCallback(()=>{if(n&&d.current)try{const e=Array.from(a.values()).sort((e,t)=>t.timestamp-e.timestamp).slice(0,l);d.current.setItem(s,JSON.stringify(e))}catch(e){f?.(e)}},[n,s,l,f]),m=t.useCallback(()=>{if(!c)return;const t=r.current;if(!t)return;const n={key:e,top:t.scrollTop,left:t.scrollLeft,timestamp:Date.now()};a.set(e,n),h()},[e,r,c,h]),g=t.useCallback(()=>{if(!c)return;if(!r.current)return;const t=a.get(e);if(!t)return;const n=()=>{r.current&&(r.current.scrollTop=t.top,r.current.scrollLeft=t.left)};u?requestAnimationFrame(n):n()},[e,r,c,u]);return t.useEffect(()=>{c&&g()},[c,g]),t.useEffect(()=>{if(c)return()=>{m()}},[c,m]),t.useEffect(()=>{if(!c||!o||!r.current)return;const e=r.current,t=()=>{m()};return e.addEventListener("scroll",t,{passive:!0}),()=>{e.removeEventListener("scroll",t)}},[c,o,m,r]),{savePosition:m,restorePosition:g}},exports.useVirtualList=s,exports.useVirtualizedSearch=function({items:r,searchValue:n,searchFields:s,caseSensitive:i=!1,deferSearch:o=!0,matcher:a}){const u=t.useMemo(()=>l(n.trim(),i),[n,i]),c=t.useDeferredValue(u),f=o?c:u,d=o&&c!==u,h=t.useCallback(e=>!f||(a?a(e,f):function(e,t,r,n){return r.some(r=>{const s=e[r];return null!=s&&l(String(s).trim(),n).includes(t)})}(e,f,s,i)),[f,a,s,i]),m=t.useMemo(()=>f?r.filter(h):[...r],[r,f,h]),g=t.useCallback(e=>h(e),[h]),p=t.useMemo(()=>{if(!u)return null;const e=u.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`(${e})`,i?"g":"gi")},[u,i]),b=t.useCallback(r=>{if(!r||!p)return r;return r.split(p).map((r,n)=>n%2==1?e.jsx("mark",{children:r},n):e.jsx(t.Fragment,{children:r},n))},[p]);return{filteredItems:m,resultCount:m.length,query:f,hasMatch:g,isSearching:d,highlightMatch:b}};
|
|
2
2
|
//# sourceMappingURL=index.cjs.js.map
|