@tanstack/virtual-core 3.19.13 → 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 +67 -9
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +5 -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 +5 -1
- package/dist/esm/index.js +68 -10
- 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 +145 -22
- 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;
|
|
@@ -131,6 +131,8 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
131
131
|
*/
|
|
132
132
|
get scrollAdjustments(): number;
|
|
133
133
|
private _holdOffset;
|
|
134
|
+
private _wheelTimer;
|
|
135
|
+
private _edgeFlushFrame;
|
|
134
136
|
private _reportedOverscroll;
|
|
135
137
|
private _trailing;
|
|
136
138
|
private _drawnListEnd;
|
|
@@ -161,6 +163,8 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
161
163
|
private _writeAwaitingCommand;
|
|
162
164
|
private _readElementOffset;
|
|
163
165
|
private _canWriteScroll;
|
|
166
|
+
private _holdAtTop;
|
|
167
|
+
private _flushHoldAtTop;
|
|
164
168
|
private _flushHoldIfReady;
|
|
165
169
|
private rafId;
|
|
166
170
|
private scheduleScrollReconcile;
|
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":";;AAIA,IAAI;AACG,MAAM,cAAc,MAAe;AACxC,MAAI,iBAAiB,OAAW,QAAO;AACvC,MAAI,OAAO,cAAc,YAAa,QAA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WAAW,MAAM;AAC5B,cAAI,KAAK,KAAK,mBAAmB;AAC/B,iBAAK,UAAU,KAAK,OAAO,KAAK,aAAa;AAC7C;AAAA,UACF;AACA,eAAK,SAAS,KAAK,gBACf,EAAE,OAAO,aAAa,OAAO,KAAK,KAAK,IAAA,IAAQ,IAAA,IAC/C;AACJ,eAAK,KAAK,aAAA;AAAA,QACZ,GAAG,GAAG;AAAA,MAAA;AAER,WAAK,SAAS;AAAA,IAChB;AAAA,EAtIG;AAAA,EAEH,IAAI,QAAkB;AACpB,WAAO,KAAK;AAAA,EACd;AAmIF;;;;;;"}
|
|
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":";;AAIA,IAAI;AACG,MAAM,cAAc,MAAe;AACxC,MAAI,iBAAiB,OAAW,QAAO;AACvC,MAAI,OAAO,cAAc,YAAa,QAAQ,eAAe;AAC7D,MAAI,iBAAiB,KAAK,UAAU,SAAS,UAAW,eAAe;AAEvE,QAAM,MAAO,UACV;AACH,SAAQ,eACN,UAAU,aAAa,cAAc,QAAQ,UAAa,MAAM;AACpE;AAQA,IAAI;AACG,MAAM,6BAA6B,MAAe;AACvD,MAAI,sCAAsC,QAAW;AACnD,WAAO;AAAA,EACT;AACA,SAAQ,oCACN,iBACA,OAAO,QAAQ,eACf,OAAO,IAAI,aAAa,cACxB,IAAI,SAAS,uBAAuB;AACxC;AAUO,MAAM,0BAA0B,MACrC,CAAC,YAAA,KAAiB,2BAAA;AAMpB,IAAI;AACG,MAAM,WAAW,MAAe;AACrC,MAAI,oBAAoB,OAA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AK,KAAK,aAAA;AAAA,QACZ,GAAG,GAAG;AAAA,MAAA;AAER,WAAK,SAAS;AAAA,IAChB;AAAA,EAtIG;AAAA,EAEH,IAAI,QAAkB;AACpB,WAAO,KAAK;AAAA,EACd;AAmIF;;;;;;;"}
|
|
@@ -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;
|
|
@@ -131,6 +131,8 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
131
131
|
*/
|
|
132
132
|
get scrollAdjustments(): number;
|
|
133
133
|
private _holdOffset;
|
|
134
|
+
private _wheelTimer;
|
|
135
|
+
private _edgeFlushFrame;
|
|
134
136
|
private _reportedOverscroll;
|
|
135
137
|
private _trailing;
|
|
136
138
|
private _drawnListEnd;
|
|
@@ -161,6 +163,8 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
161
163
|
private _writeAwaitingCommand;
|
|
162
164
|
private _readElementOffset;
|
|
163
165
|
private _canWriteScroll;
|
|
166
|
+
private _holdAtTop;
|
|
167
|
+
private _flushHoldAtTop;
|
|
164
168
|
private _flushHoldIfReady;
|
|
165
169
|
private rafId;
|
|
166
170
|
private scheduleScrollReconcile;
|
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;
|
|
@@ -216,6 +216,8 @@ class Virtualizer {
|
|
|
216
216
|
this.scrollOffset = null;
|
|
217
217
|
this.scrollDirection = null;
|
|
218
218
|
this._holdOffset = 0;
|
|
219
|
+
this._wheelTimer = null;
|
|
220
|
+
this._edgeFlushFrame = null;
|
|
219
221
|
this._reportedOverscroll = false;
|
|
220
222
|
this._trailing = 0;
|
|
221
223
|
this._drawnListEnd = Infinity;
|
|
@@ -507,6 +509,16 @@ class Virtualizer {
|
|
|
507
509
|
this.isScrolling = false;
|
|
508
510
|
this.scrollDirection = null;
|
|
509
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;
|
|
510
522
|
this._reportedOverscroll = false;
|
|
511
523
|
this._trailing = 0;
|
|
512
524
|
this._clampedAdjustment = null;
|
|
@@ -617,6 +629,7 @@ class Virtualizer {
|
|
|
617
629
|
this.scrollState = null;
|
|
618
630
|
}
|
|
619
631
|
this._flushHoldIfReady(true);
|
|
632
|
+
this._flushHoldAtTop();
|
|
620
633
|
if (this.scrollState) {
|
|
621
634
|
this.scheduleScrollReconcile();
|
|
622
635
|
}
|
|
@@ -624,9 +637,23 @@ class Virtualizer {
|
|
|
624
637
|
})
|
|
625
638
|
);
|
|
626
639
|
if ("addEventListener" in this.scrollElement) {
|
|
627
|
-
this.
|
|
628
|
-
|
|
629
|
-
)
|
|
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
|
+
}
|
|
630
657
|
}
|
|
631
658
|
this._scrollToOffset(this.getScrollOffset());
|
|
632
659
|
this._readTrailing(this._elementMaxScrollOffset());
|
|
@@ -704,7 +731,28 @@ class Virtualizer {
|
|
|
704
731
|
}
|
|
705
732
|
return null;
|
|
706
733
|
};
|
|
707
|
-
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
|
+
};
|
|
708
756
|
this._flushHoldIfReady = (sync) => {
|
|
709
757
|
var _a;
|
|
710
758
|
if (this._holdOffset === 0) return;
|
|
@@ -734,7 +782,7 @@ class Virtualizer {
|
|
|
734
782
|
this.scrollOffset = null;
|
|
735
783
|
return 0;
|
|
736
784
|
}
|
|
737
|
-
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);
|
|
738
786
|
return this.scrollOffset;
|
|
739
787
|
};
|
|
740
788
|
this.getMeasurementOptions = memo(
|
|
@@ -1053,6 +1101,9 @@ class Virtualizer {
|
|
|
1053
1101
|
this.resizeItem = (index, size) => {
|
|
1054
1102
|
var _a, _b, _c;
|
|
1055
1103
|
if (!this.isIndexInRange(index)) return;
|
|
1104
|
+
if (this.getMeasurementOptions() !== this.builtMeasurementOptions) {
|
|
1105
|
+
this.getMeasurements();
|
|
1106
|
+
}
|
|
1056
1107
|
let startShift = 0;
|
|
1057
1108
|
if ((_a = this._resizeBatch) == null ? void 0 : _a.sync) {
|
|
1058
1109
|
if (this.canShiftFromPendingResizes()) {
|
|
@@ -1574,15 +1625,22 @@ class Virtualizer {
|
|
|
1574
1625
|
// Every scroll command starts here: it becomes the in-flight command,
|
|
1575
1626
|
// writes its first target and leaves reconcile to retarget and retire it.
|
|
1576
1627
|
//
|
|
1577
|
-
// Targets are layout offsets. A held
|
|
1578
|
-
//
|
|
1579
|
-
//
|
|
1580
|
-
//
|
|
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.
|
|
1581
1633
|
//
|
|
1582
1634
|
// An index or end target that is already at its offset starts a smooth
|
|
1583
1635
|
// scroll as landed; an offset target never does, so its first scroll
|
|
1584
1636
|
// event is read as the user's (see the scroll handler in `_willUpdate`).
|
|
1585
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
|
+
}
|
|
1586
1644
|
this.pendingScrollAnchor = null;
|
|
1587
1645
|
this._clampedAdjustment = null;
|
|
1588
1646
|
const tail = this._iosGesture.tail();
|