@pdanpdan/virtual-scroll 0.2.0 → 0.3.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 +182 -88
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +100 -35
- package/dist/index.js +1 -823
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +902 -0
- package/dist/index.mjs.map +1 -0
- package/dist/virtual-scroll.css +2 -0
- package/package.json +9 -6
- package/src/components/VirtualScroll.test.ts +397 -329
- package/src/components/VirtualScroll.vue +107 -25
- package/src/composables/useVirtualScroll.test.ts +1029 -255
- package/src/composables/useVirtualScroll.ts +176 -88
- package/src/utils/fenwick-tree.test.ts +80 -65
- package/dist/index.css +0 -2
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { PublicProps } from 'vue';
|
|
|
5
5
|
import { Ref } from 'vue';
|
|
6
6
|
import { ShallowUnwrapRef } from 'vue';
|
|
7
7
|
import { VNode } from 'vue';
|
|
8
|
+
import { VNodeChild } from 'vue';
|
|
8
9
|
import { VNodeProps } from 'vue';
|
|
9
10
|
|
|
10
11
|
declare type __VLS_PrettifyLocal<T> = {
|
|
@@ -13,9 +14,9 @@ declare type __VLS_PrettifyLocal<T> = {
|
|
|
13
14
|
|
|
14
15
|
export declare const DEFAULT_BUFFER = 5;
|
|
15
16
|
|
|
16
|
-
export declare const DEFAULT_COLUMN_WIDTH =
|
|
17
|
+
export declare const DEFAULT_COLUMN_WIDTH = 100;
|
|
17
18
|
|
|
18
|
-
export declare const DEFAULT_ITEM_SIZE =
|
|
19
|
+
export declare const DEFAULT_ITEM_SIZE = 40;
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* Fenwick Tree (Binary Indexed Tree) implementation for efficient
|
|
@@ -195,21 +196,31 @@ declare interface Props<T = unknown> {
|
|
|
195
196
|
debug?: boolean;
|
|
196
197
|
}
|
|
197
198
|
|
|
199
|
+
/** Represents an item currently rendered in the virtual scroll area. */
|
|
198
200
|
export declare interface RenderedItem<T = unknown> {
|
|
201
|
+
/** The original data item. */
|
|
199
202
|
item: T;
|
|
203
|
+
/** The index of the item in the original array. */
|
|
200
204
|
index: number;
|
|
205
|
+
/** The calculated offset relative to the host element. */
|
|
201
206
|
offset: {
|
|
202
207
|
x: number;
|
|
203
208
|
y: number;
|
|
204
209
|
};
|
|
210
|
+
/** The current measured or estimated size. */
|
|
205
211
|
size: {
|
|
206
212
|
width: number;
|
|
207
213
|
height: number;
|
|
208
214
|
};
|
|
215
|
+
/** The original X offset before sticky adjustments. */
|
|
209
216
|
originalX: number;
|
|
217
|
+
/** The original Y offset before sticky adjustments. */
|
|
210
218
|
originalY: number;
|
|
219
|
+
/** Whether this item is configured to be sticky. */
|
|
211
220
|
isSticky?: boolean;
|
|
221
|
+
/** Whether this item is currently stuck at the threshold. */
|
|
212
222
|
isStickyActive?: boolean;
|
|
223
|
+
/** The offset applied for the sticky pushing effect. */
|
|
213
224
|
stickyOffset: {
|
|
214
225
|
x: number;
|
|
215
226
|
y: number;
|
|
@@ -218,35 +229,47 @@ export declare interface RenderedItem<T = unknown> {
|
|
|
218
229
|
|
|
219
230
|
export declare type ScrollAlignment = 'start' | 'center' | 'end' | 'auto';
|
|
220
231
|
|
|
232
|
+
/** Options for scroll alignment in a single axis or both axes. */
|
|
221
233
|
export declare interface ScrollAlignmentOptions {
|
|
234
|
+
/** Alignment on the X axis. */
|
|
222
235
|
x?: ScrollAlignment;
|
|
236
|
+
/** Alignment on the Y axis. */
|
|
223
237
|
y?: ScrollAlignment;
|
|
224
238
|
}
|
|
225
239
|
|
|
240
|
+
/** Comprehensive state of the virtual scroll system. */
|
|
226
241
|
export declare interface ScrollDetails<T = unknown> {
|
|
242
|
+
/** List of items currently rendered. */
|
|
227
243
|
items: RenderedItem<T>[];
|
|
244
|
+
/** Index of the first item partially or fully visible in the viewport. */
|
|
228
245
|
currentIndex: number;
|
|
246
|
+
/** Index of the first column partially or fully visible. */
|
|
229
247
|
currentColIndex: number;
|
|
248
|
+
/** Current scroll position relative to content start. */
|
|
230
249
|
scrollOffset: {
|
|
231
250
|
x: number;
|
|
232
251
|
y: number;
|
|
233
252
|
};
|
|
253
|
+
/** Dimensions of the visible viewport. */
|
|
234
254
|
viewportSize: {
|
|
235
255
|
width: number;
|
|
236
256
|
height: number;
|
|
237
257
|
};
|
|
258
|
+
/** Total calculated size of all items and gaps. */
|
|
238
259
|
totalSize: {
|
|
239
260
|
width: number;
|
|
240
261
|
height: number;
|
|
241
262
|
};
|
|
263
|
+
/** Whether the container is currently being scrolled. */
|
|
242
264
|
isScrolling: boolean;
|
|
265
|
+
/** Whether the current scroll was initiated by a method call. */
|
|
243
266
|
isProgrammaticScroll: boolean;
|
|
244
|
-
/** Range of items currently being rendered */
|
|
267
|
+
/** Range of items currently being rendered. */
|
|
245
268
|
range: {
|
|
246
269
|
start: number;
|
|
247
270
|
end: number;
|
|
248
271
|
};
|
|
249
|
-
/** Range of columns currently being rendered (for grid mode) */
|
|
272
|
+
/** Range of columns currently being rendered (for grid mode). */
|
|
250
273
|
columnRange: {
|
|
251
274
|
start: number;
|
|
252
275
|
end: number;
|
|
@@ -257,9 +280,13 @@ export declare interface ScrollDetails<T = unknown> {
|
|
|
257
280
|
|
|
258
281
|
export declare type ScrollDirection = 'vertical' | 'horizontal' | 'both';
|
|
259
282
|
|
|
283
|
+
/** Options for the scrollToIndex method. */
|
|
260
284
|
export declare interface ScrollToIndexOptions {
|
|
285
|
+
/** Where to align the item in the viewport. */
|
|
261
286
|
align?: ScrollAlignment | ScrollAlignmentOptions;
|
|
287
|
+
/** Scroll behavior. */
|
|
262
288
|
behavior?: 'auto' | 'smooth';
|
|
289
|
+
/** Internal flag for recursive correction calls. */
|
|
263
290
|
isCorrection?: boolean;
|
|
264
291
|
}
|
|
265
292
|
|
|
@@ -381,23 +408,60 @@ export declare const VirtualScroll: <T>(__VLS_props: NonNullable<Awaited<typeof
|
|
|
381
408
|
stopProgrammaticScroll: () => void;
|
|
382
409
|
}>): void;
|
|
383
410
|
attrs: any;
|
|
384
|
-
slots: {
|
|
385
|
-
|
|
386
|
-
|
|
411
|
+
slots: Readonly<{
|
|
412
|
+
/** Content rendered at the top of the scrollable area. Can be made sticky. */
|
|
413
|
+
header?: (props: Record<string, never>) => VNodeChild;
|
|
414
|
+
/** Slot for rendering each individual item. */
|
|
415
|
+
item?: (props: {
|
|
416
|
+
/** The data item being rendered. */
|
|
387
417
|
item: T;
|
|
418
|
+
/** The index of the item in the items array. */
|
|
388
419
|
index: number;
|
|
420
|
+
/** The current visible range of columns (for grid mode). */
|
|
389
421
|
columnRange: {
|
|
390
422
|
start: number;
|
|
391
423
|
end: number;
|
|
392
424
|
padStart: number;
|
|
393
425
|
padEnd: number;
|
|
394
426
|
};
|
|
427
|
+
/** Function to get the width of a specific column. */
|
|
395
428
|
getColumnWidth: (index: number) => number;
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
429
|
+
/** Whether this item is configured to be sticky. */
|
|
430
|
+
isSticky?: boolean | undefined;
|
|
431
|
+
/** Whether this item is currently in a sticky state. */
|
|
432
|
+
isStickyActive?: boolean | undefined;
|
|
433
|
+
}) => VNodeChild;
|
|
434
|
+
/** Content shown when `loading` prop is true. */
|
|
435
|
+
loading?: (props: Record<string, never>) => VNodeChild;
|
|
436
|
+
/** Content rendered at the bottom of the scrollable area. Can be made sticky. */
|
|
437
|
+
footer?: (props: Record<string, never>) => VNodeChild;
|
|
438
|
+
}> & {
|
|
439
|
+
/** Content rendered at the top of the scrollable area. Can be made sticky. */
|
|
440
|
+
header?: (props: Record<string, never>) => VNodeChild;
|
|
441
|
+
/** Slot for rendering each individual item. */
|
|
442
|
+
item?: (props: {
|
|
443
|
+
/** The data item being rendered. */
|
|
444
|
+
item: T;
|
|
445
|
+
/** The index of the item in the items array. */
|
|
446
|
+
index: number;
|
|
447
|
+
/** The current visible range of columns (for grid mode). */
|
|
448
|
+
columnRange: {
|
|
449
|
+
start: number;
|
|
450
|
+
end: number;
|
|
451
|
+
padStart: number;
|
|
452
|
+
padEnd: number;
|
|
453
|
+
};
|
|
454
|
+
/** Function to get the width of a specific column. */
|
|
455
|
+
getColumnWidth: (index: number) => number;
|
|
456
|
+
/** Whether this item is configured to be sticky. */
|
|
457
|
+
isSticky?: boolean | undefined;
|
|
458
|
+
/** Whether this item is currently in a sticky state. */
|
|
459
|
+
isStickyActive?: boolean | undefined;
|
|
460
|
+
}) => VNodeChild;
|
|
461
|
+
/** Content shown when `loading` prop is true. */
|
|
462
|
+
loading?: (props: Record<string, never>) => VNodeChild;
|
|
463
|
+
/** Content rendered at the bottom of the scrollable area. Can be made sticky. */
|
|
464
|
+
footer?: (props: Record<string, never>) => VNodeChild;
|
|
401
465
|
};
|
|
402
466
|
emit: {
|
|
403
467
|
(e: "scroll", details: ScrollDetails<T>): void;
|
|
@@ -413,63 +477,64 @@ export declare const VirtualScroll: <T>(__VLS_props: NonNullable<Awaited<typeof
|
|
|
413
477
|
__ctx?: Awaited<typeof __VLS_setup>;
|
|
414
478
|
};
|
|
415
479
|
|
|
480
|
+
/** Configuration properties for the useVirtualScroll composable. */
|
|
416
481
|
export declare interface VirtualScrollProps<T = unknown> {
|
|
417
|
-
/** Array of items to be virtualized */
|
|
482
|
+
/** Array of items to be virtualized. */
|
|
418
483
|
items: T[];
|
|
419
|
-
/** Fixed size of each item or a function that returns the size of an item */
|
|
484
|
+
/** Fixed size of each item or a function that returns the size of an item. */
|
|
420
485
|
itemSize?: number | ((item: T, index: number) => number) | undefined;
|
|
421
|
-
/** Direction of the scroll: 'vertical', 'horizontal', or 'both' */
|
|
486
|
+
/** Direction of the scroll: 'vertical', 'horizontal', or 'both'. */
|
|
422
487
|
direction?: ScrollDirection | undefined;
|
|
423
|
-
/** Number of items to render before the visible viewport */
|
|
488
|
+
/** Number of items to render before the visible viewport. */
|
|
424
489
|
bufferBefore?: number | undefined;
|
|
425
|
-
/** Number of items to render after the visible viewport */
|
|
490
|
+
/** Number of items to render after the visible viewport. */
|
|
426
491
|
bufferAfter?: number | undefined;
|
|
427
|
-
/** The scrollable container element or window */
|
|
492
|
+
/** The scrollable container element or window. */
|
|
428
493
|
container?: HTMLElement | Window | null | undefined;
|
|
429
|
-
/** The host element that contains the items */
|
|
494
|
+
/** The host element that contains the items. */
|
|
430
495
|
hostElement?: HTMLElement | null | undefined;
|
|
431
|
-
/** Range of items to render for SSR */
|
|
496
|
+
/** Range of items to render for SSR. */
|
|
432
497
|
ssrRange?: {
|
|
433
498
|
start: number;
|
|
434
499
|
end: number;
|
|
435
500
|
colStart?: number;
|
|
436
501
|
colEnd?: number;
|
|
437
502
|
} | undefined;
|
|
438
|
-
/** Number of columns for bidirectional scroll */
|
|
503
|
+
/** Number of columns for bidirectional scroll. */
|
|
439
504
|
columnCount?: number | undefined;
|
|
440
|
-
/** Fixed width of columns or an array
|
|
505
|
+
/** Fixed width of columns or an array/function for column widths. */
|
|
441
506
|
columnWidth?: number | number[] | ((index: number) => number) | undefined;
|
|
442
|
-
/** Padding at the start of the scroll container
|
|
507
|
+
/** Padding at the start of the scroll container. */
|
|
443
508
|
scrollPaddingStart?: number | {
|
|
444
509
|
x?: number;
|
|
445
510
|
y?: number;
|
|
446
511
|
} | undefined;
|
|
447
|
-
/** Padding at the end of the scroll container */
|
|
512
|
+
/** Padding at the end of the scroll container. */
|
|
448
513
|
scrollPaddingEnd?: number | {
|
|
449
514
|
x?: number;
|
|
450
515
|
y?: number;
|
|
451
516
|
} | undefined;
|
|
452
|
-
/** Gap between items in pixels (vertical) */
|
|
517
|
+
/** Gap between items in pixels (vertical). */
|
|
453
518
|
gap?: number | undefined;
|
|
454
|
-
/** Gap between columns in pixels (horizontal/grid) */
|
|
519
|
+
/** Gap between columns in pixels (horizontal/grid). */
|
|
455
520
|
columnGap?: number | undefined;
|
|
456
|
-
/** Indices of items that should stick to the top/start */
|
|
521
|
+
/** Indices of items that should stick to the top/start. */
|
|
457
522
|
stickyIndices?: number[] | undefined;
|
|
458
|
-
/** Distance from the end of the scrollable area to trigger 'load' event */
|
|
523
|
+
/** Distance from the end of the scrollable area to trigger 'load' event. */
|
|
459
524
|
loadDistance?: number | undefined;
|
|
460
|
-
/** Whether items are currently being loaded */
|
|
525
|
+
/** Whether items are currently being loaded. */
|
|
461
526
|
loading?: boolean | undefined;
|
|
462
|
-
/** Whether to restore scroll position when items are prepended */
|
|
527
|
+
/** Whether to restore scroll position when items are prepended. */
|
|
463
528
|
restoreScrollOnPrepend?: boolean | undefined;
|
|
464
|
-
/** Initial scroll index to jump to on mount */
|
|
529
|
+
/** Initial scroll index to jump to on mount. */
|
|
465
530
|
initialScrollIndex?: number | undefined;
|
|
466
|
-
/** Alignment for the initial scroll index */
|
|
531
|
+
/** Alignment for the initial scroll index. */
|
|
467
532
|
initialScrollAlign?: ScrollAlignment | ScrollAlignmentOptions | undefined;
|
|
468
|
-
/** Default size for items before they are measured */
|
|
533
|
+
/** Default size for items before they are measured. */
|
|
469
534
|
defaultItemSize?: number | undefined;
|
|
470
|
-
/** Default width for columns before they are measured */
|
|
535
|
+
/** Default width for columns before they are measured. */
|
|
471
536
|
defaultColumnWidth?: number | undefined;
|
|
472
|
-
/** Whether to enable debug mode
|
|
537
|
+
/** Whether to enable debug mode. */
|
|
473
538
|
debug?: boolean | undefined;
|
|
474
539
|
}
|
|
475
540
|
|