react-virtuoso 0.0.0-development → 0.0.0-semantic-release

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/index.d.ts CHANGED
@@ -1,5 +1,22 @@
1
1
  import { default as React_2 } from 'react';
2
2
 
3
+ export declare type CalculateViewLocation = (params: CalculateViewLocationParams) => IndexLocationWithAlign | number | null;
4
+
5
+ export declare interface CalculateViewLocationParams {
6
+ itemTop: number;
7
+ itemBottom: number;
8
+ viewportTop: number;
9
+ viewportBottom: number;
10
+ locationParams: {
11
+ align?: 'start' | 'center' | 'end';
12
+ behavior?: 'auto' | 'smooth';
13
+ } & ({
14
+ index: number;
15
+ } | {
16
+ groupIndex: number;
17
+ });
18
+ }
19
+
3
20
  /**
4
21
  * Customize the Virtuoso rendering by passing a set of custom components.
5
22
  */
@@ -68,6 +85,11 @@ export declare interface ComputeItemKey<D, C> {
68
85
  (index: number, item: D, context: C): React_2.Key;
69
86
  }
70
87
 
88
+ export declare interface ElementDimensions {
89
+ width: number;
90
+ height: number;
91
+ }
92
+
71
93
  /**
72
94
  * Passed to the Components.FillerRow custom component
73
95
  */
@@ -96,6 +118,11 @@ export declare type FollowOutputCallback = (isAtBottom: boolean) => FollowOutput
96
118
 
97
119
  export declare type FollowOutputScalarType = boolean | 'smooth' | 'auto';
98
120
 
121
+ export declare interface Gap {
122
+ row: number;
123
+ column: number;
124
+ }
125
+
99
126
  export declare interface GridComponents<Context = any> {
100
127
  /**
101
128
  * Set to customize the item wrapping element. Use only if you would like to render list from elements different than a `div`.
@@ -143,6 +170,8 @@ export declare interface GridComputeItemKey<D, C> {
143
170
  (index: number, item: D, context: C): React_2.Key;
144
171
  }
145
172
 
173
+ export declare type GridIndexLocation = FlatIndexLocationWithAlign | number;
174
+
146
175
  export declare interface GridItem<D> {
147
176
  index: number;
148
177
  data?: D;
@@ -152,17 +181,19 @@ export declare interface GridItemContent<D, C> {
152
181
  (index: number, data: D, context: C): React_2.ReactNode;
153
182
  }
154
183
 
155
- export declare interface GridItemProps {
184
+ /**
185
+ * Passed to the Components.Item custom component
186
+ */
187
+ export declare type GridItemProps = Pick<React_2.ComponentProps<'div'>, 'style' | 'children' | 'className'> & {
156
188
  'data-index': number;
157
- className?: string;
158
- }
189
+ } & React_2.RefAttributes<HTMLDivElement>;
159
190
 
160
191
  /**
161
192
  * Passed to the Components.List custom component
162
193
  */
163
- export declare type GridListProps = Pick<React_2.ComponentPropsWithRef<'div'>, 'style' | 'children' | 'ref' | 'className'> & {
164
- 'data-test-id': string;
165
- };
194
+ export declare type GridListProps = Pick<React_2.ComponentProps<'div'>, 'style' | 'children' | 'className'> & {
195
+ 'data-testid': string;
196
+ } & React_2.RefAttributes<HTMLDivElement>;
166
197
 
167
198
  export declare type GridRootProps = Omit<React_2.HTMLProps<HTMLDivElement>, 'ref' | 'data'>;
168
199
 
@@ -175,8 +206,15 @@ export declare interface GridScrollSeekPlaceholderProps {
175
206
  width: number;
176
207
  }
177
208
 
178
- export declare interface GroupContent {
179
- (index: number): React_2.ReactNode;
209
+ export declare interface GridStateSnapshot {
210
+ viewport: ElementDimensions;
211
+ item: ElementDimensions;
212
+ gap: Gap;
213
+ scrollTop: number;
214
+ }
215
+
216
+ export declare interface GroupContent<C> {
217
+ (index: number, context: C): React_2.ReactNode;
180
218
  }
181
219
 
182
220
  export declare interface GroupedScrollIntoViewLocation extends ScrollIntoViewLocationOptions {
@@ -193,6 +231,10 @@ export declare interface GroupedVirtuosoHandle {
193
231
  scrollTo(location: ScrollToOptions): void;
194
232
  scrollBy(location: ScrollToOptions): void;
195
233
  autoscrollToBottom(): void;
234
+ /**
235
+ * Obtains the internal size state of the component, so that it can be restored later. This does not include the data items.
236
+ */
237
+ getState(stateCb: StateCallback): void;
196
238
  }
197
239
 
198
240
  export declare interface GroupedVirtuosoProps<D, C> extends Omit<VirtuosoProps<D, C>, 'totalCount' | 'itemContent'> {
@@ -204,11 +246,25 @@ export declare interface GroupedVirtuosoProps<D, C> extends Omit<VirtuosoProps<D
204
246
  /**
205
247
  * Specifies how each each group header gets rendered. The callback receives the zero-based index of the group.
206
248
  */
207
- groupContent?: GroupContent;
249
+ groupContent?: GroupContent<C>;
208
250
  /**
209
251
  * Specifies how each each item gets rendered.
210
252
  */
211
253
  itemContent?: GroupItemContent<D, C>;
254
+ /**
255
+ * Use when implementing inverse infinite scrolling, decrease the value this property
256
+ * in combination with a change in `groupCounts` to prepend groups items to the top of the list.
257
+ * Both new groups and extending the top group is supported.
258
+ *
259
+ * The delta of the firstItemIndex should equal the amount of new items introduced, without the group themselves.
260
+ * As an example, if you prepend 2 groups with 20 and 30 items each, the firstItemIndex should be decreased with 50.
261
+ *
262
+ * You can also prepend more items to the first group, for example:
263
+ * `{ groupCounts: [20, 30], firstItemIndex: 1000 }` can become `{ groupCounts: [10, 30, 30], firstItemIndex: 980 }`
264
+ *
265
+ * Warning: the firstItemIndex should **be a positive number**, based on the total amount of items to be displayed.
266
+ */
267
+ firstItemIndex?: number;
212
268
  }
213
269
 
214
270
  export declare interface GroupIndexLocationWithAlign extends LocationOptions {
@@ -227,7 +283,7 @@ export declare interface GroupItemContent<D, C> {
227
283
  (index: number, groupIndex: number, data: D, context: C): React_2.ReactNode;
228
284
  }
229
285
 
230
- export declare type GroupProps = Pick<React_2.ComponentPropsWithRef<'div'>, 'style' | 'children'> & {
286
+ export declare type GroupProps = Pick<React_2.ComponentProps<'div'>, 'style' | 'children'> & {
231
287
  'data-index': number;
232
288
  'data-item-index': number;
233
289
  'data-known-size': number;
@@ -246,7 +302,7 @@ export declare interface ItemContent<D, C> {
246
302
  (index: number, data: D, context: C): React_2.ReactNode;
247
303
  }
248
304
 
249
- export declare type ItemProps<D> = Pick<React_2.ComponentPropsWithRef<'div'>, 'style' | 'children'> & {
305
+ export declare type ItemProps<D> = Pick<React_2.ComponentProps<'div'>, 'style' | 'children'> & {
250
306
  'data-index': number;
251
307
  'data-item-index': number;
252
308
  'data-item-group-index'?: number;
@@ -259,9 +315,9 @@ export declare type ListItem<D> = RecordItem<D> | GroupItem<D>;
259
315
  /**
260
316
  * Passed to the Components.List custom component
261
317
  */
262
- export declare type ListProps = Pick<React_2.ComponentPropsWithRef<'div'>, 'style' | 'children' | 'ref'> & {
263
- 'data-test-id': string;
264
- };
318
+ export declare type ListProps = Pick<React_2.ComponentProps<'div'>, 'style' | 'children'> & {
319
+ 'data-testid': string;
320
+ } & React_2.RefAttributes<HTMLDivElement>;
265
321
 
266
322
  export declare interface ListRange {
267
323
  startIndex: number;
@@ -308,17 +364,44 @@ export declare interface ScrollContainerState {
308
364
  /**
309
365
  * Passed to the Components.Scroller custom component
310
366
  */
311
- export declare type ScrollerProps = Pick<React_2.ComponentPropsWithRef<'div'>, 'style' | 'children' | 'tabIndex' | 'ref'> & {
312
- 'data-test-id'?: string;
367
+ export declare type ScrollerProps = Pick<React_2.ComponentProps<'div'>, 'style' | 'children' | 'tabIndex'> & {
368
+ 'data-testid'?: string;
313
369
  'data-virtuoso-scroller'?: boolean;
314
- };
370
+ } & React_2.RefAttributes<HTMLDivElement>;
315
371
 
316
372
  export declare type ScrollIntoViewLocation = FlatScrollIntoViewLocation | GroupedScrollIntoViewLocation;
317
373
 
318
374
  export declare interface ScrollIntoViewLocationOptions {
319
375
  align?: 'start' | 'center' | 'end';
320
376
  behavior?: 'auto' | 'smooth';
377
+ /**
378
+ * Will be called when the scroll is done, or immediately if no scroll is needed.
379
+ */
321
380
  done?: () => void;
381
+ /**
382
+ * Use this function to fine-tune the scrollIntoView behavior.
383
+ * The function receives the item's top and bottom position in the viewport, and the viewport top/bottom.
384
+ * Return an location object to scroll, or null to prevent scrolling.
385
+ * Here's the default implementation:
386
+ * ```ts
387
+ const defaultCalculateViewLocation: CalculateViewLocation = ({
388
+ itemTop,
389
+ itemBottom,
390
+ viewportTop,
391
+ viewportBottom,
392
+ locationParams: { behavior, align, ...rest },
393
+ }) => {
394
+ if (itemTop < viewportTop) {
395
+ return { ...rest, behavior, align: align ?? 'start' }
396
+ }
397
+ if (itemBottom > viewportBottom) {
398
+ return { ...rest, behavior, align: align ?? 'end' }
399
+ }
400
+ return null
401
+ }
402
+ *```
403
+ */
404
+ calculateViewLocation?: CalculateViewLocation;
322
405
  }
323
406
 
324
407
  export declare interface ScrollSeekConfiguration {
@@ -331,7 +414,7 @@ export declare interface ScrollSeekConfiguration {
331
414
  */
332
415
  change?: (velocity: number, range: ListRange) => void;
333
416
  /**
334
- * Callback to determine if the list should enter "scroll seek" mode.
417
+ * Callback to determine if the list should exit "scroll seek" mode.
335
418
  */
336
419
  exit: ScrollSeekToggle;
337
420
  }
@@ -353,12 +436,25 @@ export declare interface ScrollSeekToggle {
353
436
  /** Calculates the height of `el`, which will be the `Item` element in the DOM. */
354
437
  export declare type SizeFunction = (el: HTMLElement, field: 'offsetHeight' | 'offsetWidth') => number;
355
438
 
439
+ export declare interface SizeRange {
440
+ startIndex: number;
441
+ endIndex: number;
442
+ size: number;
443
+ }
444
+
445
+ export declare type StateCallback = (state: StateSnapshot) => void;
446
+
447
+ export declare interface StateSnapshot {
448
+ ranges: SizeRange[];
449
+ scrollTop: number;
450
+ }
451
+
356
452
  /**
357
453
  * Passed to the Components.TableBody custom component
358
454
  */
359
- export declare type TableBodyProps = Pick<React_2.ComponentPropsWithRef<'tbody'>, 'style' | 'children' | 'ref' | 'className'> & {
360
- 'data-test-id': string;
361
- };
455
+ export declare type TableBodyProps = Pick<React_2.ComponentProps<'tbody'>, 'style' | 'children' | 'className'> & {
456
+ 'data-testid': string;
457
+ } & React_2.RefAttributes<HTMLTableSectionElement>;
362
458
 
363
459
  /**
364
460
  * Customize the TableVirtuoso rendering by passing a set of custom components.
@@ -372,18 +468,18 @@ export declare interface TableComponents<Data = unknown, Context = unknown> {
372
468
  context?: Context;
373
469
  }>;
374
470
  /**
375
- * Set to render a fixed header at the top of the table (`thead`). use [[fixedHeaderHeight]] to set the contents
471
+ * Set to render a fixed header at the top of the table (`thead`). use [[fixedHeaderContent]] to set the contents
376
472
  *
377
473
  */
378
- TableHead?: React_2.ComponentType<Pick<React_2.ComponentPropsWithRef<'thead'>, 'style' | 'ref'> & {
474
+ TableHead?: React_2.ComponentType<Pick<React_2.ComponentProps<'thead'>, 'style' | 'children'> & {
379
475
  context?: Context;
380
- }>;
476
+ } & React_2.RefAttributes<HTMLTableSectionElement>>;
381
477
  /**
382
478
  * Set to render a fixed footer at the bottom of the table (`tfoot`). use [[fixedFooterContent]] to set the contents
383
479
  */
384
- TableFoot?: React_2.ComponentType<Pick<React_2.ComponentPropsWithRef<'tfoot'>, 'style' | 'ref'> & {
480
+ TableFoot?: React_2.ComponentType<Pick<React_2.ComponentProps<'tfoot'>, 'style' | 'children'> & {
385
481
  context?: Context;
386
- }>;
482
+ } & React_2.RefAttributes<HTMLTableSectionElement>>;
387
483
  /**
388
484
  * Set to customize the item wrapping element. Default is `tr`.
389
485
  */
@@ -423,7 +519,7 @@ export declare interface TableComponents<Data = unknown, Context = unknown> {
423
519
  }>;
424
520
  }
425
521
 
426
- export declare type TableProps = Pick<React_2.ComponentPropsWithRef<'table'>, 'style' | 'children'>;
522
+ export declare type TableProps = Pick<React_2.ComponentProps<'table'>, 'style' | 'children'>;
427
523
 
428
524
  export declare type TableRootProps = Omit<React_2.HTMLProps<HTMLTableElement>, 'ref' | 'data'>;
429
525
 
@@ -436,6 +532,10 @@ export declare interface TableVirtuosoHandle {
436
532
  scrollToIndex(location: number | FlatIndexLocationWithAlign): void;
437
533
  scrollTo(location: ScrollToOptions): void;
438
534
  scrollBy(location: ScrollToOptions): void;
535
+ /**
536
+ * Obtains the internal size state of the component, so that it can be restored later. This does not include the data items.
537
+ */
538
+ getState(stateCb: StateCallback): void;
439
539
  }
440
540
 
441
541
  export declare interface TableVirtuosoProps<D, C> extends Omit<VirtuosoProps<D, C>, 'components' | 'headerFooterTag' | 'topItemCount'> {
@@ -613,9 +713,15 @@ export declare interface TableVirtuosoProps<D, C> extends Omit<VirtuosoProps<D,
613
713
  * By default `4`. Redefine to change how much away from the bottom the scroller can be before the list is not considered not at bottom.
614
714
  */
615
715
  atBottomThreshold?: number;
716
+ /**
717
+ * pass a state obtained from the getState() method to restore the list state - this includes the previously measured item sizes and the scroll location.
718
+ * Notice that you should still pass the same data and totalCount properties as before, so that the list can match the data with the stored measurements.
719
+ * This is useful when you want to keep the list state when the component is unmounted and remounted, for example when navigating to a different page.
720
+ */
721
+ restoreStateFrom?: StateSnapshot;
616
722
  }
617
723
 
618
- export declare type TopItemListProps = Pick<React_2.ComponentPropsWithRef<'div'>, 'style' | 'children'>;
724
+ export declare type TopItemListProps = Pick<React_2.ComponentProps<'div'>, 'style' | 'children'>;
619
725
 
620
726
  export declare const Virtuoso: <ItemData = any, Context = any>(props: VirtuosoProps<ItemData, Context> & {
621
727
  ref?: React_2.Ref<VirtuosoHandle> | undefined;
@@ -626,7 +732,7 @@ export declare const VirtuosoGrid: <ItemData = any, Context = any>(props: Virtuo
626
732
  }) => React_2.ReactElement;
627
733
 
628
734
  export declare interface VirtuosoGridHandle {
629
- scrollToIndex(location: number | IndexLocationWithAlign): void;
735
+ scrollToIndex(location: GridIndexLocation): void;
630
736
  scrollTo(location: ScrollToOptions): void;
631
737
  scrollBy(location: ScrollToOptions): void;
632
738
  }
@@ -702,6 +808,11 @@ export declare interface VirtuosoGridProps<D, C = unknown> extends GridRootProps
702
808
  * Called with the new set of items each time the list items are rendered due to scrolling.
703
809
  */
704
810
  rangeChanged?: (range: ListRange) => void;
811
+ /**
812
+ * reports when the grid state changes. The reported value can be stored and passed back to `restoreStateFrom` to restore the grid to the same state.
813
+ */
814
+ stateChanged?: (state: GridStateSnapshot) => void;
815
+ restoreStateFrom?: GridStateSnapshot | undefined | null;
705
816
  /**
706
817
  * Called with true / false when the list has reached the bottom / gets scrolled up.
707
818
  * Can be used to load newer items, like `tail -f`.
@@ -731,6 +842,13 @@ export declare interface VirtuosoGridProps<D, C = unknown> extends GridRootProps
731
842
  * Pass a reference to a scrollable parent element, so that the grid won't wrap in its own.
732
843
  */
733
844
  customScrollParent?: HTMLElement;
845
+ /**
846
+ * set to LogLevel.DEBUG to enable various diagnostics in the console, the most useful being the item measurement reports.
847
+ *
848
+ * Ensure that you have "all levels" enabled in the browser console too see the messages.
849
+ */
850
+ logLevel?: LogLevel;
851
+ initialTopMostItemIndex?: GridIndexLocation;
734
852
  }
735
853
 
736
854
  export declare interface VirtuosoHandle {
@@ -754,6 +872,10 @@ export declare interface VirtuosoHandle {
754
872
  * Use this with combination with follow output if you have images loading in the list. Listen to the image loading and call the method.
755
873
  */
756
874
  autoscrollToBottom(): void;
875
+ /**
876
+ * Obtains the internal size state of the component, so that it can be restored later. This does not include the data items.
877
+ */
878
+ getState(stateCb: StateCallback): void;
757
879
  }
758
880
 
759
881
  export declare const VirtuosoMockContext: React_2.Context<VirtuosoMockContextValue | undefined>;
@@ -956,6 +1078,22 @@ export declare interface VirtuosoProps<D, C> extends ListRootProps {
956
1078
  * By default `4`. Redefine to change how much away from the bottom the scroller can be before the list is not considered not at bottom.
957
1079
  */
958
1080
  atBottomThreshold?: number;
1081
+ /**
1082
+ * set to LogLevel.DEBUG to enable various diagnostics in the console, the most useful being the item measurement reports.
1083
+ *
1084
+ * Ensure that you have "all levels" enabled in the browser console too see the messages.
1085
+ */
1086
+ logLevel?: LogLevel;
1087
+ /**
1088
+ * pass a state obtained from the getState() method to restore the list state - this includes the previously measured item sizes and the scroll location.
1089
+ * Notice that you should still pass the same data and totalCount properties as before, so that the list can match the data with the stored measurements.
1090
+ * This is useful when you want to keep the list state when the component is unmounted and remounted, for example when navigating to a different page.
1091
+ */
1092
+ restoreStateFrom?: StateSnapshot;
1093
+ /**
1094
+ * when set, turns the scroller into a horizontal list.
1095
+ */
1096
+ horizontalDirection?: boolean;
959
1097
  }
960
1098
 
961
1099
  export declare interface WindowViewportInfo {