@tanstack/virtual-core 3.19.12 → 3.19.14
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/cjs/index.cjs +101 -22
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +10 -1
- package/dist/cjs/ios-gesture.cjs +9 -0
- package/dist/cjs/ios-gesture.cjs.map +1 -1
- package/dist/cjs/ios-gesture.d.cts +1 -0
- package/dist/esm/index.d.ts +10 -1
- package/dist/esm/index.js +102 -23
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/ios-gesture.d.ts +1 -0
- package/dist/esm/ios-gesture.js +9 -0
- package/dist/esm/ios-gesture.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +188 -30
- package/src/ios-gesture.ts +15 -0
package/dist/cjs/index.d.cts
CHANGED
|
@@ -74,7 +74,7 @@ export interface VirtualizerOptions<TScrollElement extends Element | Window, TIt
|
|
|
74
74
|
paddingEnd?: number;
|
|
75
75
|
scrollPaddingStart?: number;
|
|
76
76
|
scrollPaddingEnd?: number;
|
|
77
|
-
initialOffset?: number | (() => number);
|
|
77
|
+
initialOffset?: number | ((instance: Virtualizer<TScrollElement, TItemElement>) => number);
|
|
78
78
|
getItemKey?: (index: number) => Key;
|
|
79
79
|
rangeExtractor?: (range: Range) => Array<number>;
|
|
80
80
|
scrollMargin?: number;
|
|
@@ -104,11 +104,15 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
104
104
|
private _singleLaneMeasurements;
|
|
105
105
|
itemSizeCache: Map<Key, number>;
|
|
106
106
|
private itemSizeCacheVersion;
|
|
107
|
+
private builtMeasurementOptions;
|
|
108
|
+
private builtItemSizeCacheVersion;
|
|
109
|
+
private pendingResizes;
|
|
107
110
|
private laneAssignments;
|
|
108
111
|
private pendingMin;
|
|
109
112
|
private prevLanes;
|
|
110
113
|
private lanesChangedFlag;
|
|
111
114
|
private lanesSettling;
|
|
115
|
+
private initialMeasurementsCacheApplied;
|
|
112
116
|
private pendingScrollAnchor;
|
|
113
117
|
scrollRect: Rect | null;
|
|
114
118
|
/**
|
|
@@ -127,6 +131,8 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
127
131
|
*/
|
|
128
132
|
get scrollAdjustments(): number;
|
|
129
133
|
private _holdOffset;
|
|
134
|
+
private _wheelTimer;
|
|
135
|
+
private _edgeFlushFrame;
|
|
130
136
|
private _reportedOverscroll;
|
|
131
137
|
private _trailing;
|
|
132
138
|
private _drawnListEnd;
|
|
@@ -157,6 +163,8 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
157
163
|
private _writeAwaitingCommand;
|
|
158
164
|
private _readElementOffset;
|
|
159
165
|
private _canWriteScroll;
|
|
166
|
+
private _holdAtTop;
|
|
167
|
+
private _flushHoldAtTop;
|
|
160
168
|
private _flushHoldIfReady;
|
|
161
169
|
private rafId;
|
|
162
170
|
private scheduleScrollReconcile;
|
|
@@ -186,6 +194,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
186
194
|
*/
|
|
187
195
|
private shouldMeasureDuringScroll;
|
|
188
196
|
measureElement: (node: TItemElement | null) => void;
|
|
197
|
+
private canShiftFromPendingResizes;
|
|
189
198
|
resizeItem: (index: number, size: number) => void;
|
|
190
199
|
getVirtualItems: {
|
|
191
200
|
(): VirtualItem[];
|
package/dist/cjs/ios-gesture.cjs
CHANGED
|
@@ -16,8 +16,16 @@ const iosMomentumOverridesWrites = () => {
|
|
|
16
16
|
return _iosMomentumOverridesWritesResult = isIOSWebKit() && typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("overflow-anchor: auto");
|
|
17
17
|
};
|
|
18
18
|
const momentumOverridesWrites = () => !isIOSWebKit() || iosMomentumOverridesWrites();
|
|
19
|
+
let _isWebKitResult;
|
|
20
|
+
const isWebKit = () => {
|
|
21
|
+
if (_isWebKitResult !== void 0) return _isWebKitResult;
|
|
22
|
+
if (typeof navigator === "undefined") return _isWebKitResult = false;
|
|
23
|
+
const ua = navigator.userAgent;
|
|
24
|
+
return _isWebKitResult = /AppleWebKit/.test(ua) && !/Chrome|Chromium|Android|jsdom|HappyDOM/.test(ua);
|
|
25
|
+
};
|
|
19
26
|
const _resetIOSDetectionForTests = () => {
|
|
20
27
|
_isIOSResult = void 0;
|
|
28
|
+
_isWebKitResult = void 0;
|
|
21
29
|
_iosMomentumOverridesWritesResult = void 0;
|
|
22
30
|
};
|
|
23
31
|
const touchListenerOptions = {
|
|
@@ -127,5 +135,6 @@ exports.IosGesture = IosGesture;
|
|
|
127
135
|
exports._resetIOSDetectionForTests = _resetIOSDetectionForTests;
|
|
128
136
|
exports.iosMomentumOverridesWrites = iosMomentumOverridesWrites;
|
|
129
137
|
exports.isIOSWebKit = isIOSWebKit;
|
|
138
|
+
exports.isWebKit = isWebKit;
|
|
130
139
|
exports.momentumOverridesWrites = momentumOverridesWrites;
|
|
131
140
|
//# sourceMappingURL=ios-gesture.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ios-gesture.cjs","sources":["../../src/ios-gesture.ts"],"sourcesContent":["// Browser-aware iOS detection. Programmatic `scrollTo`/`scrollTop` writes\n// during a momentum-scroll cancel the momentum on iOS WebKit, so we defer\n// scroll-position adjustments triggered by mid-scroll resizes until the\n// scroll settles. SSR-safe (returns false when navigator is unavailable).\nlet _isIOSResult: boolean | undefined\nexport const isIOSWebKit = (): boolean => {\n if (_isIOSResult !== undefined) return _isIOSResult\n if (typeof navigator === 'undefined') return (_isIOSResult = false)\n if (/iP(hone|od|ad)/.test(navigator.userAgent)) return (_isIOSResult = true)\n // iPadOS 13+ reports as MacIntel; touch-points distinguishes it from desktop.\n const mtp = (navigator as Navigator & { maxTouchPoints?: number })\n .maxTouchPoints\n return (_isIOSResult =\n navigator.platform === 'MacIntel' && mtp !== undefined && mtp > 0)\n}\n\n// iOS 27 changed what a scrollTop write does to a fling: it no longer stops\n// the momentum, the fling carries on along its own path and the write shows\n// for one frame (measured on the 27.0 simulator in #1307, device check still\n// open). WebKit shipped `overflow-anchor` in the same release, so that is\n// the feature check; iOS 26 and earlier report false. Cached like the iOS\n// check; SSR-safe.\nlet _iosMomentumOverridesWritesResult: boolean | undefined\nexport const iosMomentumOverridesWrites = (): boolean => {\n if (_iosMomentumOverridesWritesResult !== undefined) {\n return _iosMomentumOverridesWritesResult\n }\n return (_iosMomentumOverridesWritesResult =\n isIOSWebKit() &&\n typeof CSS !== 'undefined' &&\n typeof CSS.supports === 'function' &&\n CSS.supports('overflow-anchor: auto'))\n}\n\n// Whether a touch fling survives a scrollTop write, so a command issued\n// mid-fling has to stop the fling before it writes. Only iOS 26 and earlier\n// stop the momentum on the write itself. Chrome on Android carries the fling\n// on from the written position: on a Pixel 6 (Android 16, Chrome 156) a\n// `scrollToIndex` issued 150ms into a fling wrote its target, then went on\n// ~3,200px past it, 3 runs of 3. Other non-iOS engines are not measured; on\n// one whose write does stop the fling, stopping it first costs the two\n// frames of the stop.\nexport const momentumOverridesWrites = (): boolean =>\n !isIOSWebKit() || iosMomentumOverridesWrites()\n\n// Test hook: reset the iOS detection caches. Not exported.\nexport const _resetIOSDetectionForTests = () => {\n _isIOSResult = undefined\n _iosMomentumOverridesWritesResult = undefined\n}\n\n// Touch listeners on the scroll element run in the capture phase, so a row\n// that stops a touch event's propagation cannot hide the gesture from the\n// iOS deferral.\nconst touchListenerOptions = {\n capture: true,\n passive: true,\n}\n\n// The touch gesture in progress. iOS WebKit ignores a scrollTop write while\n// a finger drags the content (one resting on it does not stop the write)\n// and cancels momentum on one after it, so adjustments are deferred through\n// the whole gesture: `down` from touchstart to touchend/touchcancel, then\n// `tail` while momentum runs. iOS fires no touch events during momentum, so\n// every scroll event re-arms the tail and it closes ~150ms after the last\n// one. Null between gestures. The tail is tracked on every platform, but\n// only iOS defers anything through it; elsewhere it only tells a command\n// that a fling may be running (`momentumOverridesWrites`). The tail record\n// owns its timer: every replacement of the state goes through `end`, which\n// clears it, so a live timer always has its record.\n//\n// `moved`: the content moved under or after the finger other than by our\n// own write's read-back. While `down`, a scroll event that changed the\n// position sets it: the finger is dragging. The tail inherits it from the\n// drag, and any other scroll event re-arming the tail sets it: a fling can\n// be running. A tap's tail has it unset.\n//\n// `awaitingFling`: the tail follows a drag whose fling has not reported\n// yet. The first frame of a fling can come 150–250ms after touchend when\n// the main thread is busy (27.0 simulator, #1307); if the tail closes\n// first, `lateFling` waits until `until` for that frame to reopen it. It\n// defers nothing: other scroll events with no touch before them must not\n// defer corrections (#1250).\ntype IosTouch =\n | { phase: 'down'; moved: boolean }\n | { phase: 'tail'; moved: boolean; awaitingFling: boolean; timerId: number }\n | { phase: 'lateFling'; until: number }\n | null\n\ntype TimerWindow = Pick<Window, 'setTimeout' | 'clearTimeout'>\n\nexport class IosGesture {\n private _touch: IosTouch = null\n\n constructor(\n private readonly host: {\n // The scroll element's window, which runs the tail timer; null when\n // there is no element.\n getWindow: () => TimerWindow | null\n now: () => number\n // Asked when the tail's timer fires: true keeps it open another\n // 150ms (the fling still moves between scroll events).\n tailStillMoving: () => boolean\n // The tail closed on its own: a write is possible again.\n onTailClosed: () => void\n },\n ) {}\n\n get touch(): IosTouch {\n return this._touch\n }\n\n // A touch gesture owns the scroll: on iOS a write now would be ignored or\n // would cancel the momentum, so adjustments wait for the tail to close.\n // `isScrolling` is not part of it: any scroll event sets it, including\n // the read-back of our own write, and a programmatic scroll has no\n // momentum to protect (#1250).\n inMotion = () => this._touch !== null && this._touch.phase !== 'lateFling'\n\n // A finger is dragging the content, so iOS ignores our writes and no\n // read-back will come. A resting finger does not: the write lands.\n dragging = () => this._touch?.phase === 'down' && this._touch.moved\n\n // The open tail, if any: after a tap, or after a drag or fling. Except on\n // iOS 26 and earlier, a fling's momentum outlasts a write (see\n // `momentumOverridesWrites`).\n tail = (): 'tap' | 'fling' | null =>\n this._touch?.phase === 'tail' ? (this._touch.moved ? 'fling' : 'tap') : null\n\n // A scroll event reached the handler. `ownReadBack`: it is our own\n // write's read-back; `moved`: it changed the layout position; `external`:\n // the user or a fling moved it (not our write nor our smooth animation).\n // Returns whether it shows a finger dragging the content.\n onScroll = ({\n isScrolling,\n ownReadBack,\n moved,\n external,\n }: {\n isScrolling: boolean\n ownReadBack: boolean\n moved: boolean\n external: boolean\n }): boolean => {\n // Momentum after touchend fires a scroll event per frame but no touch\n // events, so each one re-arms the tail to span the fling. Only an open\n // tail is extended: a scroll event with no touch before it (our own\n // write's read-back) never opens one.\n if (isScrolling && this._touch?.phase === 'tail') {\n this._openTail(this._touch.moved || !ownReadBack, false)\n } else if (this._touch?.phase === 'lateFling') {\n // A drag's fling reporting after its tail closed reopens it.\n if (this.host.now() > this._touch.until) {\n this._touch = null\n } else if (external && isScrolling && moved) {\n this._openTail(true, false)\n }\n }\n // A finger that moved the content is dragging. Our own write landing\n // under a resting finger is not, and neither is a report at rest that\n // leaves the position where it was.\n if (!ownReadBack && isScrolling && moved && this._touch?.phase === 'down') {\n this._touch.moved = true\n return true\n }\n return false\n }\n\n touchStart = () => {\n // A finger back down inside the grace window cancels its tail.\n this.end()\n this._touch = { phase: 'down', moved: false }\n }\n\n touchEnd = () => {\n const moved = this._touch?.phase === 'down' && this._touch.moved\n this.end()\n this._openTail(moved, moved)\n }\n\n // Drop the gesture, and the tail's timer with it.\n end = () => {\n const win = this.host.getWindow()\n if (this._touch?.phase === 'tail' && win != null) {\n win.clearTimeout(this._touch.timerId)\n }\n this._touch = null\n }\n\n // Follow the touch events on `target`; the returned function stops and\n // drops the gesture. Listening is unconditional: the listeners are\n // passive and cheap, and on non-touch devices they never fire. The gating\n // by `isIOSWebKit()` lives where a write is decided.\n listen = (target: EventTarget) => {\n const onTouchStart = () => this.touchStart()\n const onTouchEnd = () => this.touchEnd()\n target.addEventListener('touchstart', onTouchStart, touchListenerOptions)\n target.addEventListener('touchend', onTouchEnd, touchListenerOptions)\n // Same handler as touchend: iOS can end a touch with touchcancel (system\n // gesture, interrupted scroll) and never fire touchend.\n target.addEventListener('touchcancel', onTouchEnd, touchListenerOptions)\n return () => {\n target.removeEventListener(\n 'touchstart',\n onTouchStart,\n touchListenerOptions,\n )\n target.removeEventListener('touchend', onTouchEnd, touchListenerOptions)\n target.removeEventListener(\n 'touchcancel',\n onTouchEnd,\n touchListenerOptions,\n )\n this.end()\n }\n }\n\n // (Re)open the tail after the finger lifts, closing ~150ms after the last\n // touchend or momentum frame.\n private _openTail = (moved: boolean, awaitingFling: boolean) => {\n const win = this.host.getWindow()\n if (win == null) return\n this.end()\n const tail = {\n phase: 'tail' as const,\n moved,\n awaitingFling,\n // Only fires while this tail is current: `end` clears it otherwise.\n timerId: win.setTimeout(() => {\n if (this.host.tailStillMoving()) {\n this._openTail(tail.moved, tail.awaitingFling)\n return\n }\n this._touch = tail.awaitingFling\n ? { phase: 'lateFling', until: this.host.now() + 1000 }\n : null\n this.host.onTailClosed()\n }, 150),\n }\n this._touch = tail\n }\n}\n"],"names":[],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"ios-gesture.cjs","sources":["../../src/ios-gesture.ts"],"sourcesContent":["// Browser-aware iOS detection. Programmatic `scrollTo`/`scrollTop` writes\n// during a momentum-scroll cancel the momentum on iOS WebKit, so we defer\n// scroll-position adjustments triggered by mid-scroll resizes until the\n// scroll settles. SSR-safe (returns false when navigator is unavailable).\nlet _isIOSResult: boolean | undefined\nexport const isIOSWebKit = (): boolean => {\n if (_isIOSResult !== undefined) return _isIOSResult\n if (typeof navigator === 'undefined') return (_isIOSResult = false)\n if (/iP(hone|od|ad)/.test(navigator.userAgent)) return (_isIOSResult = true)\n // iPadOS 13+ reports as MacIntel; touch-points distinguishes it from desktop.\n const mtp = (navigator as Navigator & { maxTouchPoints?: number })\n .maxTouchPoints\n return (_isIOSResult =\n navigator.platform === 'MacIntel' && mtp !== undefined && mtp > 0)\n}\n\n// iOS 27 changed what a scrollTop write does to a fling: it no longer stops\n// the momentum, the fling carries on along its own path and the write shows\n// for one frame (measured on the 27.0 simulator in #1307, device check still\n// open). WebKit shipped `overflow-anchor` in the same release, so that is\n// the feature check; iOS 26 and earlier report false. Cached like the iOS\n// check; SSR-safe.\nlet _iosMomentumOverridesWritesResult: boolean | undefined\nexport const iosMomentumOverridesWrites = (): boolean => {\n if (_iosMomentumOverridesWritesResult !== undefined) {\n return _iosMomentumOverridesWritesResult\n }\n return (_iosMomentumOverridesWritesResult =\n isIOSWebKit() &&\n typeof CSS !== 'undefined' &&\n typeof CSS.supports === 'function' &&\n CSS.supports('overflow-anchor: auto'))\n}\n\n// Whether a touch fling survives a scrollTop write, so a command issued\n// mid-fling has to stop the fling before it writes. Only iOS 26 and earlier\n// stop the momentum on the write itself. Chrome on Android carries the fling\n// on from the written position: on a Pixel 6 (Android 16, Chrome 156) a\n// `scrollToIndex` issued 150ms into a fling wrote its target, then went on\n// ~3,200px past it, 3 runs of 3. Other non-iOS engines are not measured; on\n// one whose write does stop the fling, stopping it first costs the two\n// frames of the stop.\nexport const momentumOverridesWrites = (): boolean =>\n !isIOSWebKit() || iosMomentumOverridesWrites()\n\n// Any WebKit: Safari, a WKWebView app, every browser on iOS. Chromium's\n// user agent names AppleWebKit too, and so do jsdom's and happy-dom's, where\n// a consumer's test must see the same writes as before. Cached like the iOS\n// check; SSR-safe.\nlet _isWebKitResult: boolean | undefined\nexport const isWebKit = (): boolean => {\n if (_isWebKitResult !== undefined) return _isWebKitResult\n if (typeof navigator === 'undefined') return (_isWebKitResult = false)\n const ua = navigator.userAgent\n return (_isWebKitResult =\n /AppleWebKit/.test(ua) &&\n !/Chrome|Chromium|Android|jsdom|HappyDOM/.test(ua))\n}\n\n// Test hook: reset the iOS detection caches. Not exported.\nexport const _resetIOSDetectionForTests = () => {\n _isIOSResult = undefined\n _isWebKitResult = undefined\n _iosMomentumOverridesWritesResult = undefined\n}\n\n// Touch listeners on the scroll element run in the capture phase, so a row\n// that stops a touch event's propagation cannot hide the gesture from the\n// iOS deferral.\nconst touchListenerOptions = {\n capture: true,\n passive: true,\n}\n\n// The touch gesture in progress. iOS WebKit ignores a scrollTop write while\n// a finger drags the content (one resting on it does not stop the write)\n// and cancels momentum on one after it, so adjustments are deferred through\n// the whole gesture: `down` from touchstart to touchend/touchcancel, then\n// `tail` while momentum runs. iOS fires no touch events during momentum, so\n// every scroll event re-arms the tail and it closes ~150ms after the last\n// one. Null between gestures. The tail is tracked on every platform, but\n// only iOS defers anything through it; elsewhere it only tells a command\n// that a fling may be running (`momentumOverridesWrites`). The tail record\n// owns its timer: every replacement of the state goes through `end`, which\n// clears it, so a live timer always has its record.\n//\n// `moved`: the content moved under or after the finger other than by our\n// own write's read-back. While `down`, a scroll event that changed the\n// position sets it: the finger is dragging. The tail inherits it from the\n// drag, and any other scroll event re-arming the tail sets it: a fling can\n// be running. A tap's tail has it unset.\n//\n// `awaitingFling`: the tail follows a drag whose fling has not reported\n// yet. The first frame of a fling can come 150–250ms after touchend when\n// the main thread is busy (27.0 simulator, #1307); if the tail closes\n// first, `lateFling` waits until `until` for that frame to reopen it. It\n// defers nothing: other scroll events with no touch before them must not\n// defer corrections (#1250).\ntype IosTouch =\n | { phase: 'down'; moved: boolean }\n | { phase: 'tail'; moved: boolean; awaitingFling: boolean; timerId: number }\n | { phase: 'lateFling'; until: number }\n | null\n\ntype TimerWindow = Pick<Window, 'setTimeout' | 'clearTimeout'>\n\nexport class IosGesture {\n private _touch: IosTouch = null\n\n constructor(\n private readonly host: {\n // The scroll element's window, which runs the tail timer; null when\n // there is no element.\n getWindow: () => TimerWindow | null\n now: () => number\n // Asked when the tail's timer fires: true keeps it open another\n // 150ms (the fling still moves between scroll events).\n tailStillMoving: () => boolean\n // The tail closed on its own: a write is possible again.\n onTailClosed: () => void\n },\n ) {}\n\n get touch(): IosTouch {\n return this._touch\n }\n\n // A touch gesture owns the scroll: on iOS a write now would be ignored or\n // would cancel the momentum, so adjustments wait for the tail to close.\n // `isScrolling` is not part of it: any scroll event sets it, including\n // the read-back of our own write, and a programmatic scroll has no\n // momentum to protect (#1250).\n inMotion = () => this._touch !== null && this._touch.phase !== 'lateFling'\n\n // A finger is dragging the content, so iOS ignores our writes and no\n // read-back will come. A resting finger does not: the write lands.\n dragging = () => this._touch?.phase === 'down' && this._touch.moved\n\n // The open tail, if any: after a tap, or after a drag or fling. Except on\n // iOS 26 and earlier, a fling's momentum outlasts a write (see\n // `momentumOverridesWrites`).\n tail = (): 'tap' | 'fling' | null =>\n this._touch?.phase === 'tail' ? (this._touch.moved ? 'fling' : 'tap') : null\n\n // A scroll event reached the handler. `ownReadBack`: it is our own\n // write's read-back; `moved`: it changed the layout position; `external`:\n // the user or a fling moved it (not our write nor our smooth animation).\n // Returns whether it shows a finger dragging the content.\n onScroll = ({\n isScrolling,\n ownReadBack,\n moved,\n external,\n }: {\n isScrolling: boolean\n ownReadBack: boolean\n moved: boolean\n external: boolean\n }): boolean => {\n // Momentum after touchend fires a scroll event per frame but no touch\n // events, so each one re-arms the tail to span the fling. Only an open\n // tail is extended: a scroll event with no touch before it (our own\n // write's read-back) never opens one.\n if (isScrolling && this._touch?.phase === 'tail') {\n this._openTail(this._touch.moved || !ownReadBack, false)\n } else if (this._touch?.phase === 'lateFling') {\n // A drag's fling reporting after its tail closed reopens it.\n if (this.host.now() > this._touch.until) {\n this._touch = null\n } else if (external && isScrolling && moved) {\n this._openTail(true, false)\n }\n }\n // A finger that moved the content is dragging. Our own write landing\n // under a resting finger is not, and neither is a report at rest that\n // leaves the position where it was.\n if (!ownReadBack && isScrolling && moved && this._touch?.phase === 'down') {\n this._touch.moved = true\n return true\n }\n return false\n }\n\n touchStart = () => {\n // A finger back down inside the grace window cancels its tail.\n this.end()\n this._touch = { phase: 'down', moved: false }\n }\n\n touchEnd = () => {\n const moved = this._touch?.phase === 'down' && this._touch.moved\n this.end()\n this._openTail(moved, moved)\n }\n\n // Drop the gesture, and the tail's timer with it.\n end = () => {\n const win = this.host.getWindow()\n if (this._touch?.phase === 'tail' && win != null) {\n win.clearTimeout(this._touch.timerId)\n }\n this._touch = null\n }\n\n // Follow the touch events on `target`; the returned function stops and\n // drops the gesture. Listening is unconditional: the listeners are\n // passive and cheap, and on non-touch devices they never fire. The gating\n // by `isIOSWebKit()` lives where a write is decided.\n listen = (target: EventTarget) => {\n const onTouchStart = () => this.touchStart()\n const onTouchEnd = () => this.touchEnd()\n target.addEventListener('touchstart', onTouchStart, touchListenerOptions)\n target.addEventListener('touchend', onTouchEnd, touchListenerOptions)\n // Same handler as touchend: iOS can end a touch with touchcancel (system\n // gesture, interrupted scroll) and never fire touchend.\n target.addEventListener('touchcancel', onTouchEnd, touchListenerOptions)\n return () => {\n target.removeEventListener(\n 'touchstart',\n onTouchStart,\n touchListenerOptions,\n )\n target.removeEventListener('touchend', onTouchEnd, touchListenerOptions)\n target.removeEventListener(\n 'touchcancel',\n onTouchEnd,\n touchListenerOptions,\n )\n this.end()\n }\n }\n\n // (Re)open the tail after the finger lifts, closing ~150ms after the last\n // touchend or momentum frame.\n private _openTail = (moved: boolean, awaitingFling: boolean) => {\n const win = this.host.getWindow()\n if (win == null) return\n this.end()\n const tail = {\n phase: 'tail' as const,\n moved,\n awaitingFling,\n // Only fires while this tail is current: `end` clears it otherwise.\n timerId: win.setTimeout(() => {\n if (this.host.tailStillMoving()) {\n this._openTail(tail.moved, tail.awaitingFling)\n return\n }\n this._touch = tail.awaitingFling\n ? { phase: 'lateFling', until: this.host.now() + 1000 }\n : null\n this.host.onTailClosed()\n }, 150),\n }\n this._touch = tail\n }\n}\n"],"names":[],"mappings":"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"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const isIOSWebKit: () => boolean;
|
|
2
2
|
export declare const iosMomentumOverridesWrites: () => boolean;
|
|
3
3
|
export declare const momentumOverridesWrites: () => boolean;
|
|
4
|
+
export declare const isWebKit: () => boolean;
|
|
4
5
|
export declare const _resetIOSDetectionForTests: () => void;
|
|
5
6
|
type IosTouch = {
|
|
6
7
|
phase: 'down';
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -74,7 +74,7 @@ export interface VirtualizerOptions<TScrollElement extends Element | Window, TIt
|
|
|
74
74
|
paddingEnd?: number;
|
|
75
75
|
scrollPaddingStart?: number;
|
|
76
76
|
scrollPaddingEnd?: number;
|
|
77
|
-
initialOffset?: number | (() => number);
|
|
77
|
+
initialOffset?: number | ((instance: Virtualizer<TScrollElement, TItemElement>) => number);
|
|
78
78
|
getItemKey?: (index: number) => Key;
|
|
79
79
|
rangeExtractor?: (range: Range) => Array<number>;
|
|
80
80
|
scrollMargin?: number;
|
|
@@ -104,11 +104,15 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
104
104
|
private _singleLaneMeasurements;
|
|
105
105
|
itemSizeCache: Map<Key, number>;
|
|
106
106
|
private itemSizeCacheVersion;
|
|
107
|
+
private builtMeasurementOptions;
|
|
108
|
+
private builtItemSizeCacheVersion;
|
|
109
|
+
private pendingResizes;
|
|
107
110
|
private laneAssignments;
|
|
108
111
|
private pendingMin;
|
|
109
112
|
private prevLanes;
|
|
110
113
|
private lanesChangedFlag;
|
|
111
114
|
private lanesSettling;
|
|
115
|
+
private initialMeasurementsCacheApplied;
|
|
112
116
|
private pendingScrollAnchor;
|
|
113
117
|
scrollRect: Rect | null;
|
|
114
118
|
/**
|
|
@@ -127,6 +131,8 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
127
131
|
*/
|
|
128
132
|
get scrollAdjustments(): number;
|
|
129
133
|
private _holdOffset;
|
|
134
|
+
private _wheelTimer;
|
|
135
|
+
private _edgeFlushFrame;
|
|
130
136
|
private _reportedOverscroll;
|
|
131
137
|
private _trailing;
|
|
132
138
|
private _drawnListEnd;
|
|
@@ -157,6 +163,8 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
157
163
|
private _writeAwaitingCommand;
|
|
158
164
|
private _readElementOffset;
|
|
159
165
|
private _canWriteScroll;
|
|
166
|
+
private _holdAtTop;
|
|
167
|
+
private _flushHoldAtTop;
|
|
160
168
|
private _flushHoldIfReady;
|
|
161
169
|
private rafId;
|
|
162
170
|
private scheduleScrollReconcile;
|
|
@@ -186,6 +194,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
186
194
|
*/
|
|
187
195
|
private shouldMeasureDuringScroll;
|
|
188
196
|
measureElement: (node: TItemElement | null) => void;
|
|
197
|
+
private canShiftFromPendingResizes;
|
|
189
198
|
resizeItem: (index: number, size: number) => void;
|
|
190
199
|
getVirtualItems: {
|
|
191
200
|
(): VirtualItem[];
|
package/dist/esm/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createLazyMeasurementsView, getMeasurementKey } from "./lazy-measurements.js";
|
|
2
2
|
import { memo, approxEqual, notUndefined, debounce } from "./utils.js";
|
|
3
3
|
import { flingCaught, externalRetiresCommand, flingSpedUp, classifyScrollEvent } from "./scroll-classifier.js";
|
|
4
|
-
import { IosGesture, isIOSWebKit, momentumOverridesWrites } from "./ios-gesture.js";
|
|
4
|
+
import { IosGesture, isWebKit, isIOSWebKit, momentumOverridesWrites } from "./ios-gesture.js";
|
|
5
5
|
import { _resetIOSDetectionForTests } from "./ios-gesture.js";
|
|
6
6
|
const getRect = (element) => {
|
|
7
7
|
const { clientWidth, clientHeight } = element;
|
|
@@ -202,16 +202,22 @@ class Virtualizer {
|
|
|
202
202
|
this._singleLaneMeasurements = null;
|
|
203
203
|
this.itemSizeCache = /* @__PURE__ */ new Map();
|
|
204
204
|
this.itemSizeCacheVersion = 0;
|
|
205
|
+
this.builtMeasurementOptions = null;
|
|
206
|
+
this.builtItemSizeCacheVersion = -1;
|
|
207
|
+
this.pendingResizes = [];
|
|
205
208
|
this.laneAssignments = /* @__PURE__ */ new Map();
|
|
206
209
|
this.pendingMin = null;
|
|
207
210
|
this.prevLanes = void 0;
|
|
208
211
|
this.lanesChangedFlag = false;
|
|
209
212
|
this.lanesSettling = false;
|
|
213
|
+
this.initialMeasurementsCacheApplied = false;
|
|
210
214
|
this.pendingScrollAnchor = null;
|
|
211
215
|
this.scrollRect = null;
|
|
212
216
|
this.scrollOffset = null;
|
|
213
217
|
this.scrollDirection = null;
|
|
214
218
|
this._holdOffset = 0;
|
|
219
|
+
this._wheelTimer = null;
|
|
220
|
+
this._edgeFlushFrame = null;
|
|
215
221
|
this._reportedOverscroll = false;
|
|
216
222
|
this._trailing = 0;
|
|
217
223
|
this._drawnListEnd = Infinity;
|
|
@@ -503,6 +509,16 @@ class Virtualizer {
|
|
|
503
509
|
this.isScrolling = false;
|
|
504
510
|
this.scrollDirection = null;
|
|
505
511
|
this._holdOffset = 0;
|
|
512
|
+
if (this.targetWindow) {
|
|
513
|
+
if (this._wheelTimer !== null) {
|
|
514
|
+
this.targetWindow.clearTimeout(this._wheelTimer);
|
|
515
|
+
}
|
|
516
|
+
if (this._edgeFlushFrame !== null) {
|
|
517
|
+
this.targetWindow.cancelAnimationFrame(this._edgeFlushFrame);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
this._wheelTimer = null;
|
|
521
|
+
this._edgeFlushFrame = null;
|
|
506
522
|
this._reportedOverscroll = false;
|
|
507
523
|
this._trailing = 0;
|
|
508
524
|
this._clampedAdjustment = null;
|
|
@@ -613,6 +629,7 @@ class Virtualizer {
|
|
|
613
629
|
this.scrollState = null;
|
|
614
630
|
}
|
|
615
631
|
this._flushHoldIfReady(true);
|
|
632
|
+
this._flushHoldAtTop();
|
|
616
633
|
if (this.scrollState) {
|
|
617
634
|
this.scheduleScrollReconcile();
|
|
618
635
|
}
|
|
@@ -620,9 +637,23 @@ class Virtualizer {
|
|
|
620
637
|
})
|
|
621
638
|
);
|
|
622
639
|
if ("addEventListener" in this.scrollElement) {
|
|
623
|
-
this.
|
|
624
|
-
|
|
625
|
-
)
|
|
640
|
+
const target = this.scrollElement;
|
|
641
|
+
this.unsubs.push(this._iosGesture.listen(target));
|
|
642
|
+
if (isWebKit()) {
|
|
643
|
+
const onWheel = () => {
|
|
644
|
+
const win = this.targetWindow;
|
|
645
|
+
if (win === null) return;
|
|
646
|
+
if (this._wheelTimer !== null) win.clearTimeout(this._wheelTimer);
|
|
647
|
+
this._wheelTimer = win.setTimeout(() => {
|
|
648
|
+
this._wheelTimer = null;
|
|
649
|
+
this._flushHoldIfReady(true);
|
|
650
|
+
this._retryClampedAdjustment();
|
|
651
|
+
}, 150);
|
|
652
|
+
this._flushHoldAtTop();
|
|
653
|
+
};
|
|
654
|
+
target.addEventListener("wheel", onWheel, addEventListenerOptions);
|
|
655
|
+
this.unsubs.push(() => target.removeEventListener("wheel", onWheel));
|
|
656
|
+
}
|
|
626
657
|
}
|
|
627
658
|
this._scrollToOffset(this.getScrollOffset());
|
|
628
659
|
this._readTrailing(this._elementMaxScrollOffset());
|
|
@@ -700,7 +731,28 @@ class Virtualizer {
|
|
|
700
731
|
}
|
|
701
732
|
return null;
|
|
702
733
|
};
|
|
703
|
-
this._canWriteScroll = () => !(isIOSWebKit() && this._iosGesture.inMotion()) && !this._reportedOverscroll;
|
|
734
|
+
this._canWriteScroll = () => !(isIOSWebKit() && this._iosGesture.inMotion()) && !this._reportedOverscroll && this._wheelTimer === null;
|
|
735
|
+
this._holdAtTop = () => {
|
|
736
|
+
if (this._holdOffset === 0) return false;
|
|
737
|
+
const offset = this._readElementOffset();
|
|
738
|
+
return offset !== null && Math.min(offset, offset + this._holdOffset) < this.options.scrollMargin + 1;
|
|
739
|
+
};
|
|
740
|
+
this._flushHoldAtTop = () => {
|
|
741
|
+
const win = this.targetWindow;
|
|
742
|
+
if (win === null || this._wheelTimer === null || this._edgeFlushFrame !== null || !this._holdAtTop()) {
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
this._edgeFlushFrame = win.requestAnimationFrame(() => {
|
|
746
|
+
this._edgeFlushFrame = win.requestAnimationFrame(() => {
|
|
747
|
+
this._edgeFlushFrame = null;
|
|
748
|
+
if (this._wheelTimer === null || !this._holdAtTop()) return;
|
|
749
|
+
win.clearTimeout(this._wheelTimer);
|
|
750
|
+
this._wheelTimer = null;
|
|
751
|
+
this._flushHoldIfReady(true);
|
|
752
|
+
this._retryClampedAdjustment();
|
|
753
|
+
});
|
|
754
|
+
});
|
|
755
|
+
};
|
|
704
756
|
this._flushHoldIfReady = (sync) => {
|
|
705
757
|
var _a;
|
|
706
758
|
if (this._holdOffset === 0) return;
|
|
@@ -730,7 +782,7 @@ class Virtualizer {
|
|
|
730
782
|
this.scrollOffset = null;
|
|
731
783
|
return 0;
|
|
732
784
|
}
|
|
733
|
-
this.scrollOffset = this.scrollOffset ?? (typeof this.options.initialOffset === "function" ? this.options.initialOffset() : this.options.initialOffset);
|
|
785
|
+
this.scrollOffset = this.scrollOffset ?? (typeof this.options.initialOffset === "function" ? this.options.initialOffset(this) : this.options.initialOffset);
|
|
734
786
|
return this.scrollOffset;
|
|
735
787
|
};
|
|
736
788
|
this.getMeasurementOptions = memo(
|
|
@@ -769,23 +821,28 @@ class Virtualizer {
|
|
|
769
821
|
this.isIndexInRange = (index) => index >= 0 && index < this.options.count;
|
|
770
822
|
this.getMeasurements = memo(
|
|
771
823
|
() => [this.getMeasurementOptions(), this.itemSizeCacheVersion],
|
|
772
|
-
({
|
|
773
|
-
count,
|
|
774
|
-
paddingStart,
|
|
775
|
-
scrollMargin,
|
|
776
|
-
getItemKey,
|
|
777
|
-
enabled,
|
|
778
|
-
lanes,
|
|
779
|
-
laneAssignmentMode,
|
|
780
|
-
gap
|
|
781
|
-
}, _itemSizeCacheVersion) => {
|
|
824
|
+
(measurementOptions, itemSizeCacheVersion) => {
|
|
782
825
|
var _a;
|
|
826
|
+
const {
|
|
827
|
+
count,
|
|
828
|
+
paddingStart,
|
|
829
|
+
scrollMargin,
|
|
830
|
+
getItemKey,
|
|
831
|
+
enabled,
|
|
832
|
+
lanes,
|
|
833
|
+
laneAssignmentMode,
|
|
834
|
+
gap
|
|
835
|
+
} = measurementOptions;
|
|
836
|
+
this.builtMeasurementOptions = measurementOptions;
|
|
837
|
+
this.builtItemSizeCacheVersion = itemSizeCacheVersion;
|
|
838
|
+
this.pendingResizes = [];
|
|
783
839
|
const itemSizeCache = this.itemSizeCache;
|
|
784
840
|
if (!enabled) {
|
|
785
841
|
this.measurementsCache = [];
|
|
786
842
|
this._singleLaneMeasurements = null;
|
|
787
843
|
this.itemSizeCache.clear();
|
|
788
844
|
this.laneAssignments.clear();
|
|
845
|
+
this.initialMeasurementsCacheApplied = false;
|
|
789
846
|
return [];
|
|
790
847
|
}
|
|
791
848
|
if (this.laneAssignments.size > count) {
|
|
@@ -804,7 +861,8 @@ class Virtualizer {
|
|
|
804
861
|
this.laneAssignments.clear();
|
|
805
862
|
this.pendingMin = null;
|
|
806
863
|
}
|
|
807
|
-
if (this.measurementsCache.length === 0 && !this.lanesSettling) {
|
|
864
|
+
if (!this.initialMeasurementsCacheApplied && this.measurementsCache.length === 0 && !this.lanesSettling) {
|
|
865
|
+
this.initialMeasurementsCacheApplied = true;
|
|
808
866
|
this.measurementsCache = this.options.initialMeasurementsCache;
|
|
809
867
|
this.measurementsCache.forEach((item) => {
|
|
810
868
|
this.itemSizeCache.set(item.key, item.size);
|
|
@@ -1039,17 +1097,30 @@ class Virtualizer {
|
|
|
1039
1097
|
this.resizeItem(index, this.options.measureElement(node, void 0, this));
|
|
1040
1098
|
}
|
|
1041
1099
|
};
|
|
1100
|
+
this.canShiftFromPendingResizes = () => this.options.lanes === 1 && this._singleLaneMeasurements !== null && this.shouldAdjustScrollPositionOnItemSizeChange === void 0 && !this.lanesChangedFlag && !this.lanesSettling && this.getMeasurementOptions() === this.builtMeasurementOptions && this.itemSizeCacheVersion === this.builtItemSizeCacheVersion + this.pendingResizes.length;
|
|
1042
1101
|
this.resizeItem = (index, size) => {
|
|
1043
1102
|
var _a, _b, _c;
|
|
1044
1103
|
if (!this.isIndexInRange(index)) return;
|
|
1045
|
-
if (
|
|
1104
|
+
if (this.getMeasurementOptions() !== this.builtMeasurementOptions) {
|
|
1105
|
+
this.getMeasurements();
|
|
1106
|
+
}
|
|
1107
|
+
let startShift = 0;
|
|
1108
|
+
if ((_a = this._resizeBatch) == null ? void 0 : _a.sync) {
|
|
1109
|
+
if (this.canShiftFromPendingResizes()) {
|
|
1110
|
+
for (const resize of this.pendingResizes) {
|
|
1111
|
+
if (resize.index < index) startShift += resize.delta;
|
|
1112
|
+
}
|
|
1113
|
+
} else {
|
|
1114
|
+
this.getMeasurements();
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1046
1117
|
let cachedSize;
|
|
1047
1118
|
let itemStart;
|
|
1048
1119
|
let key;
|
|
1049
1120
|
const flat = (_b = this._singleLaneMeasurements) == null ? void 0 : _b.flat;
|
|
1050
1121
|
if (this.options.lanes === 1 && flat != null) {
|
|
1051
1122
|
key = this.options.getItemKey(index);
|
|
1052
|
-
itemStart = flat[index * 2];
|
|
1123
|
+
itemStart = flat[index * 2] + startShift;
|
|
1053
1124
|
cachedSize = flat[index * 2 + 1];
|
|
1054
1125
|
} else {
|
|
1055
1126
|
const item = this.measurementsCache[index];
|
|
@@ -1099,6 +1170,7 @@ class Virtualizer {
|
|
|
1099
1170
|
}
|
|
1100
1171
|
this.itemSizeCache.set(key, size);
|
|
1101
1172
|
this.itemSizeCacheVersion++;
|
|
1173
|
+
this.pendingResizes.push({ index, delta });
|
|
1102
1174
|
let adjustedSync = false;
|
|
1103
1175
|
if (!this._awaitingCommandReadBack()) {
|
|
1104
1176
|
if (wasAtEnd) {
|
|
@@ -1553,15 +1625,22 @@ class Virtualizer {
|
|
|
1553
1625
|
// Every scroll command starts here: it becomes the in-flight command,
|
|
1554
1626
|
// writes its first target and leaves reconcile to retarget and retire it.
|
|
1555
1627
|
//
|
|
1556
|
-
// Targets are layout offsets. A held
|
|
1557
|
-
//
|
|
1558
|
-
//
|
|
1559
|
-
//
|
|
1628
|
+
// Targets are layout offsets. A correction held for the wheel is written
|
|
1629
|
+
// before the command (below). One held for a touch or a bounce is not
|
|
1630
|
+
// dropped by a command: the write lands the element `_holdOffset` short
|
|
1631
|
+
// of the target, under the rows exposed shifted by the same amount, and
|
|
1632
|
+
// the flush moves both together once a write is possible.
|
|
1560
1633
|
//
|
|
1561
1634
|
// An index or end target that is already at its offset starts a smooth
|
|
1562
1635
|
// scroll as landed; an offset target never does, so its first scroll
|
|
1563
1636
|
// event is read as the user's (see the scroll handler in `_willUpdate`).
|
|
1564
1637
|
_startScroll(target, offset, behavior, kind) {
|
|
1638
|
+
if (this._wheelTimer !== null && this.targetWindow) {
|
|
1639
|
+
this.targetWindow.clearTimeout(this._wheelTimer);
|
|
1640
|
+
this._wheelTimer = null;
|
|
1641
|
+
this.scrollState = null;
|
|
1642
|
+
this._flushHoldIfReady(true);
|
|
1643
|
+
}
|
|
1565
1644
|
this.pendingScrollAnchor = null;
|
|
1566
1645
|
this._clampedAdjustment = null;
|
|
1567
1646
|
const tail = this._iosGesture.tail();
|