@pdanpdan/virtual-scroll 0.4.0 → 0.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 +246 -297
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +873 -257
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2209 -1109
- package/dist/index.mjs.map +1 -1
- package/dist/virtual-scroll.css +1 -2
- package/package.json +5 -1
- package/src/components/VirtualScroll.test.ts +1886 -326
- package/src/components/VirtualScroll.vue +813 -340
- package/src/components/VirtualScrollbar.test.ts +174 -0
- package/src/components/VirtualScrollbar.vue +102 -0
- package/src/composables/useVirtualScroll.test.ts +1506 -228
- package/src/composables/useVirtualScroll.ts +789 -373
- package/src/composables/useVirtualScrollbar.test.ts +526 -0
- package/src/composables/useVirtualScrollbar.ts +239 -0
- package/src/index.ts +2 -0
- package/src/types.ts +333 -52
- package/src/utils/fenwick-tree.test.ts +39 -39
- package/src/utils/scroll.test.ts +133 -107
- package/src/utils/scroll.ts +12 -5
- package/src/utils/virtual-scroll-logic.test.ts +653 -320
- package/src/utils/virtual-scroll-logic.ts +685 -389
package/src/types.ts
CHANGED
|
@@ -54,64 +54,94 @@ export interface RenderedItem<T = unknown> {
|
|
|
54
54
|
item: T;
|
|
55
55
|
/** The 0-based index of the item in the original array. */
|
|
56
56
|
index: number;
|
|
57
|
-
/** The calculated pixel offset relative to the items wrapper. */
|
|
57
|
+
/** The calculated pixel offset relative to the items wrapper in display pixels (DU). */
|
|
58
58
|
offset: {
|
|
59
|
-
/** Horizontal offset (left). */
|
|
59
|
+
/** Horizontal offset (left) in DU. */
|
|
60
60
|
x: number;
|
|
61
|
-
/** Vertical offset (top). */
|
|
61
|
+
/** Vertical offset (top) in DU. */
|
|
62
62
|
y: number;
|
|
63
63
|
};
|
|
64
|
-
/** The current measured or estimated size of the item. */
|
|
64
|
+
/** The current measured or estimated size of the item in virtual units (VU). */
|
|
65
65
|
size: {
|
|
66
|
-
/** Pixel width. */
|
|
66
|
+
/** Pixel width in VU. */
|
|
67
67
|
width: number;
|
|
68
|
-
/** Pixel height. */
|
|
68
|
+
/** Pixel height in VU. */
|
|
69
69
|
height: number;
|
|
70
70
|
};
|
|
71
|
-
/** The original horizontal pixel offset before any sticky adjustments. */
|
|
71
|
+
/** The original horizontal pixel offset before any sticky adjustments in VU. */
|
|
72
72
|
originalX: number;
|
|
73
|
-
/** The original vertical pixel offset before any sticky adjustments. */
|
|
73
|
+
/** The original vertical pixel offset before any sticky adjustments in VU. */
|
|
74
74
|
originalY: number;
|
|
75
75
|
/** Whether this item is configured to be sticky via the `stickyIndices` property. */
|
|
76
76
|
isSticky?: boolean;
|
|
77
77
|
/** Whether this item is currently in a stuck state at the viewport edge. */
|
|
78
78
|
isStickyActive?: boolean;
|
|
79
|
-
/** The relative translation applied to the item for the sticky pushing effect. */
|
|
79
|
+
/** The relative translation applied to the item for the sticky pushing effect in DU. */
|
|
80
80
|
stickyOffset: {
|
|
81
|
-
/** Horizontal translation. */
|
|
81
|
+
/** Horizontal translation in DU. */
|
|
82
82
|
x: number;
|
|
83
|
-
/** Vertical translation. */
|
|
83
|
+
/** Vertical translation in DU. */
|
|
84
84
|
y: number;
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
/** Information about the currently visible range of columns and their paddings. */
|
|
89
|
+
export interface ColumnRange {
|
|
90
|
+
/** Inclusive start index. */
|
|
91
|
+
start: number;
|
|
92
|
+
/** Exclusive end index. */
|
|
93
|
+
end: number;
|
|
94
|
+
/** Pixel padding to maintain at the start of the row in VU. */
|
|
95
|
+
padStart: number;
|
|
96
|
+
/** Pixel padding to maintain at the end of the row in VU. */
|
|
97
|
+
padEnd: number;
|
|
98
|
+
}
|
|
99
|
+
|
|
88
100
|
/** Comprehensive state of the virtual scroll system. */
|
|
89
101
|
export interface ScrollDetails<T = unknown> {
|
|
90
102
|
/** List of items currently rendered in the DOM buffer. */
|
|
91
103
|
items: RenderedItem<T>[];
|
|
92
|
-
/** Index of the first item
|
|
104
|
+
/** Index of the first item visible below any sticky header in the viewport. */
|
|
93
105
|
currentIndex: number;
|
|
94
|
-
/** Index of the first column
|
|
106
|
+
/** Index of the first column visible after any sticky column in the viewport (grid mode). */
|
|
95
107
|
currentColIndex: number;
|
|
96
|
-
/**
|
|
108
|
+
/** Index of the last item visible above any sticky footer in the viewport. */
|
|
109
|
+
currentEndIndex: number;
|
|
110
|
+
/** Index of the last column visible before any sticky end column in the viewport (grid mode). */
|
|
111
|
+
currentEndColIndex: number;
|
|
112
|
+
/** Current relative pixel scroll position from the content start in VU. */
|
|
97
113
|
scrollOffset: {
|
|
98
|
-
/** Horizontal position (X). */
|
|
114
|
+
/** Horizontal position (X) in VU. */
|
|
115
|
+
x: number;
|
|
116
|
+
/** Vertical position (Y) in VU. */
|
|
117
|
+
y: number;
|
|
118
|
+
};
|
|
119
|
+
/** Current display pixel scroll position (before scaling) in DU. */
|
|
120
|
+
displayScrollOffset: {
|
|
121
|
+
/** Horizontal position (X) in DU. */
|
|
99
122
|
x: number;
|
|
100
|
-
/** Vertical position (Y). */
|
|
123
|
+
/** Vertical position (Y) in DU. */
|
|
101
124
|
y: number;
|
|
102
125
|
};
|
|
103
|
-
/** Current dimensions of the visible viewport area. */
|
|
126
|
+
/** Current dimensions of the visible viewport area in VU. */
|
|
104
127
|
viewportSize: {
|
|
105
|
-
/** Pixel width. */
|
|
128
|
+
/** Pixel width in VU. */
|
|
106
129
|
width: number;
|
|
107
|
-
/** Pixel height. */
|
|
130
|
+
/** Pixel height in VU. */
|
|
108
131
|
height: number;
|
|
109
132
|
};
|
|
110
|
-
/**
|
|
133
|
+
/** Current dimensions of the visible viewport area in display pixels (DU). */
|
|
134
|
+
displayViewportSize: {
|
|
135
|
+
/** Pixel width in DU. */
|
|
136
|
+
width: number;
|
|
137
|
+
/** Pixel height in DU. */
|
|
138
|
+
height: number;
|
|
139
|
+
};
|
|
140
|
+
/** Total calculated or estimated size of all items and gaps in VU. */
|
|
111
141
|
totalSize: {
|
|
112
|
-
/** Total pixel width. */
|
|
142
|
+
/** Total pixel width in VU. */
|
|
113
143
|
width: number;
|
|
114
|
-
/** Total pixel height. */
|
|
144
|
+
/** Total pixel height in VU. */
|
|
115
145
|
height: number;
|
|
116
146
|
};
|
|
117
147
|
/** Whether the container is currently being scrolled by the user or an animation. */
|
|
@@ -126,16 +156,7 @@ export interface ScrollDetails<T = unknown> {
|
|
|
126
156
|
end: number;
|
|
127
157
|
};
|
|
128
158
|
/** The range of column indices and associated paddings currently being rendered. */
|
|
129
|
-
columnRange:
|
|
130
|
-
/** Inclusive start index. */
|
|
131
|
-
start: number;
|
|
132
|
-
/** Exclusive end index. */
|
|
133
|
-
end: number;
|
|
134
|
-
/** Pixel padding to maintain at the start of the row. */
|
|
135
|
-
padStart: number;
|
|
136
|
-
/** Pixel padding to maintain at the end of the row. */
|
|
137
|
-
padEnd: number;
|
|
138
|
-
};
|
|
159
|
+
columnRange: ColumnRange;
|
|
139
160
|
}
|
|
140
161
|
|
|
141
162
|
/** Configuration properties for the `useVirtualScroll` composable. */
|
|
@@ -146,7 +167,7 @@ export interface VirtualScrollProps<T = unknown> {
|
|
|
146
167
|
items: T[];
|
|
147
168
|
|
|
148
169
|
/**
|
|
149
|
-
* Fixed size of each item
|
|
170
|
+
* Fixed size of each item in virtual units (VU) or a function that returns the size of an item.
|
|
150
171
|
* Pass `0`, `null` or `undefined` for automatic dynamic size detection via `ResizeObserver`.
|
|
151
172
|
*/
|
|
152
173
|
itemSize?: number | ((item: T, index: number) => number) | undefined;
|
|
@@ -171,16 +192,22 @@ export interface VirtualScrollProps<T = unknown> {
|
|
|
171
192
|
|
|
172
193
|
/**
|
|
173
194
|
* The scrollable element or window object.
|
|
174
|
-
* If not provided, virtualization usually happens relative to the `
|
|
195
|
+
* If not provided, virtualization usually happens relative to the `hostRef`.
|
|
175
196
|
*/
|
|
176
197
|
container?: HTMLElement | Window | null | undefined;
|
|
177
198
|
|
|
178
199
|
/**
|
|
179
200
|
* The host element that directly wraps the absolute-positioned items.
|
|
180
|
-
* Used for calculating relative offsets.
|
|
201
|
+
* Used for calculating relative offsets in display pixels (DU).
|
|
181
202
|
*/
|
|
182
203
|
hostElement?: HTMLElement | null | undefined;
|
|
183
204
|
|
|
205
|
+
/**
|
|
206
|
+
* The root element of the VirtualScroll component.
|
|
207
|
+
* Used for calculating relative offsets in display pixels (DU).
|
|
208
|
+
*/
|
|
209
|
+
hostRef?: HTMLElement | null | undefined;
|
|
210
|
+
|
|
184
211
|
/**
|
|
185
212
|
* Configuration for Server-Side Rendering.
|
|
186
213
|
* Defines which items are rendered statically on the server.
|
|
@@ -202,29 +229,41 @@ export interface VirtualScrollProps<T = unknown> {
|
|
|
202
229
|
columnCount?: number | undefined;
|
|
203
230
|
|
|
204
231
|
/**
|
|
205
|
-
* Fixed width of columns
|
|
232
|
+
* Fixed width of columns in VU, an array of widths, or a function returning widths.
|
|
206
233
|
* Pass `0`, `null` or `undefined` for dynamic column detection.
|
|
207
234
|
*/
|
|
208
235
|
columnWidth?: number | number[] | ((index: number) => number) | undefined;
|
|
209
236
|
|
|
210
237
|
/**
|
|
211
|
-
* Pixel padding at the start of the scroll container.
|
|
238
|
+
* Pixel padding at the start of the scroll container in display pixels (DU).
|
|
212
239
|
*/
|
|
213
240
|
scrollPaddingStart?: number | { x?: number; y?: number; } | undefined;
|
|
214
241
|
|
|
215
242
|
/**
|
|
216
|
-
* Pixel padding at the end of the scroll container.
|
|
243
|
+
* Pixel padding at the end of the scroll container in DU.
|
|
217
244
|
*/
|
|
218
245
|
scrollPaddingEnd?: number | { x?: number; y?: number; } | undefined;
|
|
219
246
|
|
|
220
247
|
/**
|
|
221
|
-
*
|
|
248
|
+
* Size of sticky elements at the start of the viewport (top or left) in DU.
|
|
249
|
+
* Used to adjust the visible range and item positioning without increasing content size.
|
|
250
|
+
*/
|
|
251
|
+
stickyStart?: number | { x?: number; y?: number; } | undefined;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Size of sticky elements at the end of the viewport (bottom or right) in DU.
|
|
255
|
+
* Used to adjust the visible range without increasing content size.
|
|
256
|
+
*/
|
|
257
|
+
stickyEnd?: number | { x?: number; y?: number; } | undefined;
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Gap between items in virtual units (VU).
|
|
222
261
|
* Applied vertically in list/grid mode, horizontally in horizontal list mode.
|
|
223
262
|
*/
|
|
224
263
|
gap?: number | undefined;
|
|
225
264
|
|
|
226
265
|
/**
|
|
227
|
-
* Gap between columns in
|
|
266
|
+
* Gap between columns in VU.
|
|
228
267
|
* Applied in horizontal and bidirectional grid modes.
|
|
229
268
|
*/
|
|
230
269
|
columnGap?: number | undefined;
|
|
@@ -235,7 +274,17 @@ export interface VirtualScrollProps<T = unknown> {
|
|
|
235
274
|
stickyIndices?: number[] | undefined;
|
|
236
275
|
|
|
237
276
|
/**
|
|
238
|
-
*
|
|
277
|
+
* Extra padding (display pixels - DU) at the start of the flow (e.g. non-sticky header).
|
|
278
|
+
*/
|
|
279
|
+
flowPaddingStart?: number | { x?: number; y?: number; } | undefined;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Extra padding (DU) at the end of the flow (e.g. non-sticky footer).
|
|
283
|
+
*/
|
|
284
|
+
flowPaddingEnd?: number | { x?: number; y?: number; } | undefined;
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Threshold distance from the end in display pixels (DU) to emit the 'load' event.
|
|
239
288
|
* @default 200
|
|
240
289
|
*/
|
|
241
290
|
loadDistance?: number | undefined;
|
|
@@ -246,7 +295,7 @@ export interface VirtualScrollProps<T = unknown> {
|
|
|
246
295
|
loading?: boolean | undefined;
|
|
247
296
|
|
|
248
297
|
/**
|
|
249
|
-
* Whether to automatically restore and
|
|
298
|
+
* Whether to automatically restore and maintain scroll position when items are prepended to the array.
|
|
250
299
|
*/
|
|
251
300
|
restoreScrollOnPrepend?: boolean | undefined;
|
|
252
301
|
|
|
@@ -262,12 +311,12 @@ export interface VirtualScrollProps<T = unknown> {
|
|
|
262
311
|
initialScrollAlign?: ScrollAlignment | ScrollAlignmentOptions | undefined;
|
|
263
312
|
|
|
264
313
|
/**
|
|
265
|
-
* Default fallback size for items before they are measured.
|
|
314
|
+
* Default fallback size for items before they are measured in VU.
|
|
266
315
|
*/
|
|
267
316
|
defaultItemSize?: number | undefined;
|
|
268
317
|
|
|
269
318
|
/**
|
|
270
|
-
* Default fallback width for columns before they are measured.
|
|
319
|
+
* Default fallback width for columns before they are measured in VU.
|
|
271
320
|
*/
|
|
272
321
|
defaultColumnWidth?: number | undefined;
|
|
273
322
|
|
|
@@ -277,6 +326,85 @@ export interface VirtualScrollProps<T = unknown> {
|
|
|
277
326
|
debug?: boolean | undefined;
|
|
278
327
|
}
|
|
279
328
|
|
|
329
|
+
/** Help provide axis specific information to the scrollbar. */
|
|
330
|
+
export type ScrollAxis = 'vertical' | 'horizontal';
|
|
331
|
+
|
|
332
|
+
/** Properties for the `VirtualScrollbar` component. */
|
|
333
|
+
export interface VirtualScrollbarProps {
|
|
334
|
+
/**
|
|
335
|
+
* The axis for this scrollbar.
|
|
336
|
+
* - 'vertical': Vertical scrollbar.
|
|
337
|
+
* - 'horizontal': Horizontal scrollbar.
|
|
338
|
+
* @default 'vertical'
|
|
339
|
+
*/
|
|
340
|
+
axis?: ScrollAxis;
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Total size of the scrollable content in pixels.
|
|
344
|
+
*/
|
|
345
|
+
totalSize: number;
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Current scroll position in pixels.
|
|
349
|
+
*/
|
|
350
|
+
position: number;
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Viewport size in pixels.
|
|
354
|
+
*/
|
|
355
|
+
viewportSize: number;
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Function to scroll to a specific pixel offset on this axis.
|
|
359
|
+
* @param offset - The pixel offset to scroll to.
|
|
360
|
+
*/
|
|
361
|
+
scrollToOffset?: (offset: number) => void;
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* The ID of the container element this scrollbar controls.
|
|
365
|
+
*/
|
|
366
|
+
containerId?: string;
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Whether the scrollbar is in Right-to-Left (RTL) mode.
|
|
370
|
+
* @default false
|
|
371
|
+
*/
|
|
372
|
+
isRtl?: boolean;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** Properties passed to the 'scrollbar' scoped slot. */
|
|
376
|
+
export interface ScrollbarSlotProps {
|
|
377
|
+
/** Current scroll position as a percentage (0 to 1). */
|
|
378
|
+
positionPercent: number;
|
|
379
|
+
/** Viewport size as a percentage of total size (0 to 1). */
|
|
380
|
+
viewportPercent: number;
|
|
381
|
+
/** Calculated thumb size as a percentage of the track size (0 to 100). */
|
|
382
|
+
thumbSizePercent: number;
|
|
383
|
+
/** Calculated thumb position as a percentage of the track size (0 to 100). */
|
|
384
|
+
thumbPositionPercent: number;
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Attributes and event listeners to be bound to the scrollbar track element.
|
|
388
|
+
* Use `v-bind="trackProps"` on your track element.
|
|
389
|
+
*/
|
|
390
|
+
trackProps: Record<string, unknown>;
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Attributes and event listeners to be bound to the scrollbar thumb element.
|
|
394
|
+
* Use `v-bind="thumbProps"` on your thumb element.
|
|
395
|
+
*/
|
|
396
|
+
thumbProps: Record<string, unknown>;
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Grouped props for the `VirtualScrollbar` component.
|
|
400
|
+
* Useful for passing directly to `<VirtualScrollbar v-bind="scrollbarProps" />`.
|
|
401
|
+
*/
|
|
402
|
+
scrollbarProps: VirtualScrollbarProps;
|
|
403
|
+
|
|
404
|
+
/** Whether the thumb is currently being dragged. */
|
|
405
|
+
isDragging: boolean;
|
|
406
|
+
}
|
|
407
|
+
|
|
280
408
|
/** Properties passed to the 'item' scoped slot. */
|
|
281
409
|
export interface ItemSlotProps<T = unknown> {
|
|
282
410
|
/** The original data item being rendered. */
|
|
@@ -296,12 +424,133 @@ export interface ItemSlotProps<T = unknown> {
|
|
|
296
424
|
};
|
|
297
425
|
/** Helper to get the current calculated width of any column index. */
|
|
298
426
|
getColumnWidth: (index: number) => number;
|
|
427
|
+
/** Vertical gap between items. */
|
|
428
|
+
gap: number;
|
|
429
|
+
/** Horizontal gap between columns. */
|
|
430
|
+
columnGap: number;
|
|
299
431
|
/** Whether this item index is configured as sticky. */
|
|
300
432
|
isSticky?: boolean | undefined;
|
|
301
433
|
/** Whether this item is currently in a sticky state at the edge. */
|
|
302
434
|
isStickyActive?: boolean | undefined;
|
|
303
435
|
}
|
|
304
436
|
|
|
437
|
+
/** Configuration properties for the `VirtualScroll` component. */
|
|
438
|
+
export interface VirtualScrollComponentProps<T = unknown> {
|
|
439
|
+
/** Array of items to be virtualized. */
|
|
440
|
+
items: T[];
|
|
441
|
+
/** Fixed size of each item (in pixels) or a function that returns the size of an item. */
|
|
442
|
+
itemSize?: number | ((item: T, index: number) => number) | null;
|
|
443
|
+
/** Direction of the scroll. */
|
|
444
|
+
direction?: ScrollDirection;
|
|
445
|
+
/** Number of items to render before the visible viewport. */
|
|
446
|
+
bufferBefore?: number;
|
|
447
|
+
/** Number of items to render after the visible viewport. */
|
|
448
|
+
bufferAfter?: number;
|
|
449
|
+
/** The scrollable container element or window. */
|
|
450
|
+
container?: HTMLElement | Window | null;
|
|
451
|
+
/** Range of items to render during Server-Side Rendering. */
|
|
452
|
+
ssrRange?: {
|
|
453
|
+
/** First row index to render. */
|
|
454
|
+
start: number;
|
|
455
|
+
/** Last row index to render (exclusive). */
|
|
456
|
+
end: number;
|
|
457
|
+
/** First column index to render (for grid mode). */
|
|
458
|
+
colStart?: number;
|
|
459
|
+
/** Last column index to render (exclusive, for grid mode). */
|
|
460
|
+
colEnd?: number;
|
|
461
|
+
};
|
|
462
|
+
/** Number of columns for bidirectional (grid) scroll. */
|
|
463
|
+
columnCount?: number;
|
|
464
|
+
/** Fixed width of columns (in pixels), an array of widths, or a function for column widths. */
|
|
465
|
+
columnWidth?: number | number[] | ((index: number) => number) | null;
|
|
466
|
+
/** The HTML tag to use for the root container. */
|
|
467
|
+
containerTag?: string;
|
|
468
|
+
/** The HTML tag to use for the items wrapper. */
|
|
469
|
+
wrapperTag?: string;
|
|
470
|
+
/** The HTML tag to use for each item. */
|
|
471
|
+
itemTag?: string;
|
|
472
|
+
/** Additional padding at the start of the scroll container (top or left). */
|
|
473
|
+
scrollPaddingStart?: number | { x?: number; y?: number; };
|
|
474
|
+
/** Additional padding at the end of the scroll container (bottom or right). */
|
|
475
|
+
scrollPaddingEnd?: number | { x?: number; y?: number; };
|
|
476
|
+
/** Whether the content in the 'header' slot is sticky. */
|
|
477
|
+
stickyHeader?: boolean;
|
|
478
|
+
/** Whether the content in the 'footer' slot is sticky. */
|
|
479
|
+
stickyFooter?: boolean;
|
|
480
|
+
/** Gap between items in pixels. */
|
|
481
|
+
gap?: number;
|
|
482
|
+
/** Gap between columns in pixels. */
|
|
483
|
+
columnGap?: number;
|
|
484
|
+
/** Indices of items that should stick to the top/start of the viewport. */
|
|
485
|
+
stickyIndices?: number[];
|
|
486
|
+
/** Distance from the end of the scrollable area (in pixels) to trigger the 'load' event. */
|
|
487
|
+
loadDistance?: number;
|
|
488
|
+
/** Whether items are currently being loaded. */
|
|
489
|
+
loading?: boolean;
|
|
490
|
+
/** Whether to automatically restore and maintain scroll position when items are prepended to the list. */
|
|
491
|
+
restoreScrollOnPrepend?: boolean;
|
|
492
|
+
/** Initial scroll index to jump to immediately after mount. */
|
|
493
|
+
initialScrollIndex?: number;
|
|
494
|
+
/** Alignment for the initial scroll index. */
|
|
495
|
+
initialScrollAlign?: ScrollAlignment | ScrollAlignmentOptions;
|
|
496
|
+
/** Default size for items before they are measured by ResizeObserver. */
|
|
497
|
+
defaultItemSize?: number;
|
|
498
|
+
/** Default width for columns before they are measured by ResizeObserver. */
|
|
499
|
+
defaultColumnWidth?: number;
|
|
500
|
+
/** Whether to show debug information (visible offsets and indices) over items. */
|
|
501
|
+
debug?: boolean;
|
|
502
|
+
/** Whether to use virtual scrollbars for styling purposes. */
|
|
503
|
+
virtualScrollbar?: boolean;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/** Exposed methods and properties of the `VirtualScroll` component instance. */
|
|
507
|
+
export interface VirtualScrollInstance<T = unknown> extends VirtualScrollComponentProps<T> {
|
|
508
|
+
/** Detailed information about the current scroll state. */
|
|
509
|
+
scrollDetails: ScrollDetails<T>;
|
|
510
|
+
/** Information about the current visible range of columns. */
|
|
511
|
+
columnRange: ScrollDetails<T>[ 'columnRange' ];
|
|
512
|
+
/** Helper to get the width of a specific column. */
|
|
513
|
+
getColumnWidth: (index: number) => number;
|
|
514
|
+
/** Helper to get the height of a specific row. */
|
|
515
|
+
getRowHeight: (index: number) => number;
|
|
516
|
+
/** Helper to get the virtual offset of a specific row. */
|
|
517
|
+
getRowOffset: (index: number) => number;
|
|
518
|
+
/** Helper to get the virtual offset of a specific column. */
|
|
519
|
+
getColumnOffset: (index: number) => number;
|
|
520
|
+
/** Helper to get the virtual offset of a specific item. */
|
|
521
|
+
getItemOffset: (index: number) => number;
|
|
522
|
+
/** Helper to get the size of a specific item along the scroll axis. */
|
|
523
|
+
getItemSize: (index: number) => number;
|
|
524
|
+
/** Programmatically scroll to a specific row and/or column. */
|
|
525
|
+
scrollToIndex: (rowIndex: number | null | undefined, colIndex: number | null | undefined, options?: ScrollAlignment | ScrollAlignmentOptions | ScrollToIndexOptions) => void;
|
|
526
|
+
/** Programmatically scroll to a specific pixel offset. */
|
|
527
|
+
scrollToOffset: (x?: number | null, y?: number | null, options?: { behavior?: 'auto' | 'smooth'; }) => void;
|
|
528
|
+
/** Resets all dynamic measurements and re-initializes from props. */
|
|
529
|
+
refresh: () => void;
|
|
530
|
+
/** Immediately stops any currently active smooth scroll animation and clears pending corrections. */
|
|
531
|
+
stopProgrammaticScroll: () => void;
|
|
532
|
+
/** Detects the current direction (LTR/RTL) of the scroll container. */
|
|
533
|
+
updateDirection: () => void;
|
|
534
|
+
/** Whether the scroll container is in Right-to-Left (RTL) mode. */
|
|
535
|
+
isRtl: boolean;
|
|
536
|
+
/** Whether the component has finished its first client - side mount and hydration. */
|
|
537
|
+
isHydrated: boolean;
|
|
538
|
+
/** Coordinate scaling factor for X axis. */
|
|
539
|
+
scaleX: number;
|
|
540
|
+
/** Coordinate scaling factor for Y axis. */
|
|
541
|
+
scaleY: number;
|
|
542
|
+
/** Physical width of the content in the DOM (clamped to browser limits). */
|
|
543
|
+
renderedWidth: number;
|
|
544
|
+
/** Physical height of the content in the DOM (clamped to browser limits). */
|
|
545
|
+
renderedHeight: number;
|
|
546
|
+
/** Absolute offset of the component within its container. */
|
|
547
|
+
componentOffset: { x: number; y: number; };
|
|
548
|
+
/** Properties for the vertical scrollbar. */
|
|
549
|
+
scrollbarPropsVertical: ScrollbarSlotProps | null;
|
|
550
|
+
/** Properties for the horizontal scrollbar. */
|
|
551
|
+
scrollbarPropsHorizontal: ScrollbarSlotProps | null;
|
|
552
|
+
}
|
|
553
|
+
|
|
305
554
|
/** Parameters for calculating the scroll target position. */
|
|
306
555
|
export interface ScrollTargetParams {
|
|
307
556
|
/** Row index to target. */
|
|
@@ -310,16 +559,12 @@ export interface ScrollTargetParams {
|
|
|
310
559
|
colIndex: number | null | undefined;
|
|
311
560
|
/** Scroll options. */
|
|
312
561
|
options?: ScrollAlignment | ScrollAlignmentOptions | ScrollToIndexOptions | undefined;
|
|
313
|
-
/** Total items count. */
|
|
314
|
-
itemsLength: number;
|
|
315
|
-
/** Total columns count. */
|
|
316
|
-
columnCount: number;
|
|
317
562
|
/** Current scroll direction. */
|
|
318
563
|
direction: ScrollDirection;
|
|
319
|
-
/**
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
|
|
564
|
+
/** Current viewport width. */
|
|
565
|
+
viewportWidth: number;
|
|
566
|
+
/** Current viewport height. */
|
|
567
|
+
viewportHeight: number;
|
|
323
568
|
/** Current total estimated width. */
|
|
324
569
|
totalWidth: number;
|
|
325
570
|
/** Current total estimated height. */
|
|
@@ -348,8 +593,40 @@ export interface ScrollTargetParams {
|
|
|
348
593
|
getColumnSize: (index: number) => number;
|
|
349
594
|
/** Prefix sum resolver for column width. */
|
|
350
595
|
getColumnQuery: (index: number) => number;
|
|
596
|
+
/** Coordinate scaling factor for X axis. */
|
|
597
|
+
scaleX: number;
|
|
598
|
+
/** Coordinate scaling factor for Y axis. */
|
|
599
|
+
scaleY: number;
|
|
600
|
+
/** Host offset on X axis in display pixels. */
|
|
601
|
+
hostOffsetX: number;
|
|
602
|
+
/** Host offset on Y axis in display pixels. */
|
|
603
|
+
hostOffsetY: number;
|
|
351
604
|
/** List of sticky indices. */
|
|
352
605
|
stickyIndices?: number[] | undefined;
|
|
606
|
+
/** Sticky start offset on X axis. */
|
|
607
|
+
stickyStartX?: number | undefined;
|
|
608
|
+
/** Sticky start offset on Y axis. */
|
|
609
|
+
stickyStartY?: number | undefined;
|
|
610
|
+
/** Sticky end offset on X axis. */
|
|
611
|
+
stickyEndX?: number | undefined;
|
|
612
|
+
/** Sticky end offset on Y axis. */
|
|
613
|
+
stickyEndY?: number | undefined;
|
|
614
|
+
/** Flow padding start on X axis. */
|
|
615
|
+
flowPaddingStartX?: number | undefined;
|
|
616
|
+
/** Flow padding start on Y axis. */
|
|
617
|
+
flowPaddingStartY?: number | undefined;
|
|
618
|
+
/** Flow padding end on X axis. */
|
|
619
|
+
flowPaddingEndX?: number | undefined;
|
|
620
|
+
/** Flow padding end on Y axis. */
|
|
621
|
+
flowPaddingEndY?: number | undefined;
|
|
622
|
+
/** Scroll padding start on X axis. */
|
|
623
|
+
paddingStartX?: number | undefined;
|
|
624
|
+
/** Scroll padding start on Y axis. */
|
|
625
|
+
paddingStartY?: number | undefined;
|
|
626
|
+
/** Scroll padding end on X axis. */
|
|
627
|
+
paddingEndX?: number | undefined;
|
|
628
|
+
/** Scroll padding end on Y axis. */
|
|
629
|
+
paddingEndY?: number | undefined;
|
|
353
630
|
}
|
|
354
631
|
|
|
355
632
|
/** Calculated scroll target result. */
|
|
@@ -486,6 +763,8 @@ export interface ItemPositionParams {
|
|
|
486
763
|
getSizeY: (idx: number) => number;
|
|
487
764
|
/** Width resolver. */
|
|
488
765
|
getSizeX: (idx: number) => number;
|
|
766
|
+
/** Current column range (for grid mode). */
|
|
767
|
+
columnRange?: ColumnRange | undefined;
|
|
489
768
|
}
|
|
490
769
|
|
|
491
770
|
/** Parameters for calculating an item's style object. */
|
|
@@ -504,6 +783,8 @@ export interface ItemStyleParams<T = unknown> {
|
|
|
504
783
|
paddingStartY: number;
|
|
505
784
|
/** Hydration state. */
|
|
506
785
|
isHydrated: boolean;
|
|
786
|
+
/** Whether the container is in Right-to-Left (RTL) mode. */
|
|
787
|
+
isRtl: boolean;
|
|
507
788
|
}
|
|
508
789
|
|
|
509
790
|
/** Parameters for calculating the total size of the scrollable area. */
|