@tanstack/virtual-core 3.14.0 → 3.16.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.
@@ -1,13 +1,18 @@
1
- export * from './utils.js';
1
+ export declare const _resetIOSDetectionForTests: () => void;
2
+ export { approxEqual, debounce, memo, notUndefined } from './utils.js';
3
+ export type { NoInfer, PartialKeys } from './utils.js';
2
4
  type ScrollDirection = 'forward' | 'backward';
3
5
  type ScrollAlignment = 'start' | 'center' | 'end' | 'auto';
4
6
  type ScrollBehavior = 'auto' | 'smooth' | 'instant';
7
+ type ScrollAnchor = 'start' | 'end';
8
+ type FollowOnAppend = boolean | ScrollBehavior;
5
9
  export interface ScrollToOptions {
6
10
  align?: ScrollAlignment;
7
11
  behavior?: ScrollBehavior;
8
12
  }
9
13
  type ScrollToOffsetOptions = ScrollToOptions;
10
14
  type ScrollToIndexOptions = ScrollToOptions;
15
+ type ScrollToEndOptions = Pick<ScrollToOptions, 'behavior'>;
11
16
  export interface Range {
12
17
  startIndex: number;
13
18
  endIndex: number;
@@ -35,11 +40,11 @@ type ObserveOffsetCallBack = (offset: number, isScrolling: boolean) => void;
35
40
  export declare const observeElementOffset: <T extends Element>(instance: Virtualizer<T, any>, cb: ObserveOffsetCallBack) => (() => void) | undefined;
36
41
  export declare const observeWindowOffset: (instance: Virtualizer<Window, any>, cb: ObserveOffsetCallBack) => (() => void) | undefined;
37
42
  export declare const measureElement: <TItemElement extends Element>(element: TItemElement, entry: ResizeObserverEntry | undefined, instance: Virtualizer<any, TItemElement>) => number;
38
- export declare const windowScroll: <T extends Window>(offset: number, { adjustments, behavior, }: {
43
+ export declare const windowScroll: <T extends Window>(offset: number, options: {
39
44
  adjustments?: number;
40
45
  behavior?: ScrollBehavior;
41
46
  }, instance: Virtualizer<T, any>) => void;
42
- export declare const elementScroll: <T extends Element>(offset: number, { adjustments, behavior, }: {
47
+ export declare const elementScroll: <T extends Element>(offset: number, options: {
43
48
  adjustments?: number;
44
49
  behavior?: ScrollBehavior;
45
50
  }, instance: Virtualizer<T, any>) => void;
@@ -72,6 +77,9 @@ export interface VirtualizerOptions<TScrollElement extends Element | Window, TIt
72
77
  indexAttribute?: string;
73
78
  initialMeasurementsCache?: Array<VirtualItem>;
74
79
  lanes?: number;
80
+ anchorTo?: ScrollAnchor;
81
+ followOnAppend?: FollowOnAppend;
82
+ scrollEndThreshold?: number;
75
83
  isScrollingResetDelay?: number;
76
84
  useScrollendEvent?: boolean;
77
85
  enabled?: boolean;
@@ -87,16 +95,24 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
87
95
  isScrolling: boolean;
88
96
  private scrollState;
89
97
  measurementsCache: Array<VirtualItem>;
98
+ private _flatMeasurements;
90
99
  private itemSizeCache;
100
+ private itemSizeCacheVersion;
91
101
  private laneAssignments;
92
- private pendingMeasuredCacheIndexes;
102
+ private pendingMin;
93
103
  private prevLanes;
94
104
  private lanesChangedFlag;
95
105
  private lanesSettling;
106
+ private pendingScrollAnchor;
96
107
  scrollRect: Rect | null;
97
108
  scrollOffset: number | null;
98
109
  scrollDirection: ScrollDirection | null;
99
110
  private scrollAdjustments;
111
+ private _iosDeferredAdjustment;
112
+ private _iosTouching;
113
+ private _iosJustTouchEnded;
114
+ private _iosTouchEndTimerId;
115
+ private _intendedScrollOffset;
100
116
  shouldAdjustScrollPositionOnItemSizeChange: undefined | ((item: VirtualItem, delta: number, instance: Virtualizer<TScrollElement, TItemElement>) => boolean);
101
117
  elementsCache: Map<Key, TItemElement>;
102
118
  private now;
@@ -108,10 +124,12 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
108
124
  constructor(opts: VirtualizerOptions<TScrollElement, TItemElement>);
109
125
  setOptions: (opts: VirtualizerOptions<TScrollElement, TItemElement>) => void;
110
126
  private notify;
127
+ private applyScrollAdjustment;
111
128
  private maybeNotify;
112
129
  private cleanup;
113
130
  _didMount: () => () => void;
114
131
  _willUpdate: () => void;
132
+ private _flushIosDeferredIfReady;
115
133
  private rafId;
116
134
  private scheduleScrollReconcile;
117
135
  private reconcileScroll;
@@ -129,7 +147,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
129
147
  };
130
148
  getVirtualIndexes: {
131
149
  (): number[];
132
- updateDeps(newDeps: [(range: Range) => number[], number, number, number | null, number | null]): void;
150
+ updateDeps(newDeps: [(range: Range) => Array<number>, number, number, number | null, number | null]): void;
133
151
  };
134
152
  indexFromElement: (node: TItemElement) => number;
135
153
  /**
@@ -146,12 +164,27 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
146
164
  };
147
165
  getVirtualItemForOffset: (offset: number) => VirtualItem | undefined;
148
166
  private getMaxScrollOffset;
167
+ private getVirtualDistanceFromEnd;
168
+ getDistanceFromEnd: () => number;
169
+ isAtEnd: (threshold?: number) => boolean;
149
170
  getOffsetForAlignment: (toOffset: number, align: ScrollAlignment, itemSize?: number) => number;
150
171
  getOffsetForIndex: (index: number, align?: ScrollAlignment) => readonly [number, "auto"] | readonly [number, "start" | "center" | "end"] | undefined;
151
172
  scrollToOffset: (toOffset: number, { align, behavior }?: ScrollToOffsetOptions) => void;
152
173
  scrollToIndex: (index: number, { align: initialAlign, behavior, }?: ScrollToIndexOptions) => void;
153
174
  scrollBy: (delta: number, { behavior }?: ScrollToOffsetOptions) => void;
175
+ scrollToEnd: ({ behavior }?: ScrollToEndOptions) => void;
154
176
  getTotalSize: () => number;
177
+ /**
178
+ * Returns a snapshot of currently-measured items suitable for round-
179
+ * tripping through state storage (sessionStorage, history, etc.) and
180
+ * passing back as `initialMeasurementsCache` on remount. Pair with the
181
+ * current `scrollOffset` to restore exact scroll position after navigation.
182
+ *
183
+ * Only items the consumer has actually rendered (and thus measured) appear
184
+ * in the snapshot; unmeasured items will fall back to `estimateSize` on
185
+ * restore. Returns an empty array if no items have been measured.
186
+ */
187
+ takeSnapshot: () => Array<VirtualItem>;
155
188
  private _scrollToOffset;
156
189
  measure: () => void;
157
190
  }