@tanstack/virtual-core 3.19.13 → 3.19.15
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 +91 -15
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +7 -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 +7 -1
- package/dist/esm/index.js +92 -16
- 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 +186 -28
- 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;
|
|
@@ -142,6 +144,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
142
144
|
shouldAdjustScrollPositionOnItemSizeChange: undefined | ((item: VirtualItem, delta: number, instance: Virtualizer<TScrollElement, TItemElement>) => boolean);
|
|
143
145
|
elementsCache: Map<Key, TItemElement>;
|
|
144
146
|
private _resizeBatch;
|
|
147
|
+
private _dropQueued;
|
|
145
148
|
private now;
|
|
146
149
|
private observer;
|
|
147
150
|
range: {
|
|
@@ -161,6 +164,8 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
161
164
|
private _writeAwaitingCommand;
|
|
162
165
|
private _readElementOffset;
|
|
163
166
|
private _canWriteScroll;
|
|
167
|
+
private _holdAtTop;
|
|
168
|
+
private _flushHoldAtTop;
|
|
164
169
|
private _flushHoldIfReady;
|
|
165
170
|
private rafId;
|
|
166
171
|
private scheduleScrollReconcile;
|
|
@@ -189,6 +194,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
189
194
|
* to prevent items far from the target from pushing it away.
|
|
190
195
|
*/
|
|
191
196
|
private shouldMeasureDuringScroll;
|
|
197
|
+
private dropDisconnected;
|
|
192
198
|
measureElement: (node: TItemElement | null) => void;
|
|
193
199
|
private canShiftFromPendingResizes;
|
|
194
200
|
resizeItem: (index: number, size: number) => void;
|
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,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;AAGb,MAAM,6BAA6B,MAAM;AAC9C,iBAAe;AACf,sCAAoC;AACtC;AAKA,MAAM,uBAAuB;AAAA,EAC3B,SAAS;AAAA,EACT,SAAS;AACX;AAkCO,MAAM,WAAW;AAAA,EAGtB,YACmB,MAWjB;AAXiB,SAAA,OAAA;AAHnB,SAAQ,SAAmB;AAyB3B,SAAA,WAAW,MAAM,KAAK,WAAW,QAAQ,KAAK,OAAO,UAAU;AAI/D,SAAA,WAA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aAAa,MAAM,KAAK,SAAA;AAC9B,aAAO,iBAAiB,cAAc,cAAc,oBAAoB;AACxE,aAAO,iBAAiB,YAAY,YAAY,oBAAoB;AAGpE,aAAO,iBAAiB,eAAe,YAAY,oBAAoB;AACvE,aAAO,MAAM;AACX,eAAO;AAAA,UACL;AAAA,UACA;AAAA,UACA;AAAA,QAAA;AAEF,eAAO,oBAAoB,YAAY,YAAY,oBAAoB;AACvE,eAAO;AAAA,UACL;AAAA,UACA;AAAA,UACA;AAAA,QAAA;AAEF,aAAK,IAAA;AAAA,MACP;AAAA,IACF;AAIA,SAAQ,YAAY,CAAC,OAAgB,kBAA2B;AAC9D,YAAM,MAAM,KAAK,KAAK,UAAA;AACtB,UAAI,OAAO,KAAM;AACjB,WAAK,IAAA;AACL,YAAM,OAAO;AAAA,QACX,OAAO;AAAA,QACP;AAAA,QACA;AAAA;AAAA,QAEA,SAAS,IAAI,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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A;AAAA,QAAA;AAEF,eAAO,oBAAoB,YAAY,YAAY,oBAAoB;AACvE,eAAO;AAAA,UACL;AAAA,UACA;AAAA,UACA;AAAA,QAAA;AAEF,aAAK,IAAA;AAAA,MACP;AAAA,IACF;AAIA,SAAQ,YAAY,CAAC,OAAgB,kBAA2B;AAC9D,YAAM,MAAM,KAAK,KAAK,UAAA;AACtB,UAAI,OAAO,KAAM;AACjB,WAAK,IAAA;AACL,YAAM,OAAO;AAAA,QACX,OAAO;AAAA,QACP;AAAA,QACA;AAAA;AAAA,QAEA,SAAS,IAAI,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,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;
|
|
@@ -142,6 +144,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
142
144
|
shouldAdjustScrollPositionOnItemSizeChange: undefined | ((item: VirtualItem, delta: number, instance: Virtualizer<TScrollElement, TItemElement>) => boolean);
|
|
143
145
|
elementsCache: Map<Key, TItemElement>;
|
|
144
146
|
private _resizeBatch;
|
|
147
|
+
private _dropQueued;
|
|
145
148
|
private now;
|
|
146
149
|
private observer;
|
|
147
150
|
range: {
|
|
@@ -161,6 +164,8 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
161
164
|
private _writeAwaitingCommand;
|
|
162
165
|
private _readElementOffset;
|
|
163
166
|
private _canWriteScroll;
|
|
167
|
+
private _holdAtTop;
|
|
168
|
+
private _flushHoldAtTop;
|
|
164
169
|
private _flushHoldIfReady;
|
|
165
170
|
private rafId;
|
|
166
171
|
private scheduleScrollReconcile;
|
|
@@ -189,6 +194,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
189
194
|
* to prevent items far from the target from pushing it away.
|
|
190
195
|
*/
|
|
191
196
|
private shouldMeasureDuringScroll;
|
|
197
|
+
private dropDisconnected;
|
|
192
198
|
measureElement: (node: TItemElement | null) => void;
|
|
193
199
|
private canShiftFromPendingResizes;
|
|
194
200
|
resizeItem: (index: number, size: number) => void;
|
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;
|
|
@@ -257,6 +259,7 @@ class Virtualizer {
|
|
|
257
259
|
this._clampedAdjustment = null;
|
|
258
260
|
this.elementsCache = /* @__PURE__ */ new Map();
|
|
259
261
|
this._resizeBatch = null;
|
|
262
|
+
this._dropQueued = false;
|
|
260
263
|
this.now = () => {
|
|
261
264
|
var _a, _b, _c;
|
|
262
265
|
return ((_c = (_b = (_a = this.targetWindow) == null ? void 0 : _a.performance) == null ? void 0 : _b.now) == null ? void 0 : _c.call(_b)) ?? Date.now();
|
|
@@ -507,6 +510,16 @@ class Virtualizer {
|
|
|
507
510
|
this.isScrolling = false;
|
|
508
511
|
this.scrollDirection = null;
|
|
509
512
|
this._holdOffset = 0;
|
|
513
|
+
if (this.targetWindow) {
|
|
514
|
+
if (this._wheelTimer !== null) {
|
|
515
|
+
this.targetWindow.clearTimeout(this._wheelTimer);
|
|
516
|
+
}
|
|
517
|
+
if (this._edgeFlushFrame !== null) {
|
|
518
|
+
this.targetWindow.cancelAnimationFrame(this._edgeFlushFrame);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
this._wheelTimer = null;
|
|
522
|
+
this._edgeFlushFrame = null;
|
|
510
523
|
this._reportedOverscroll = false;
|
|
511
524
|
this._trailing = 0;
|
|
512
525
|
this._clampedAdjustment = null;
|
|
@@ -617,6 +630,7 @@ class Virtualizer {
|
|
|
617
630
|
this.scrollState = null;
|
|
618
631
|
}
|
|
619
632
|
this._flushHoldIfReady(true);
|
|
633
|
+
this._flushHoldAtTop();
|
|
620
634
|
if (this.scrollState) {
|
|
621
635
|
this.scheduleScrollReconcile();
|
|
622
636
|
}
|
|
@@ -624,9 +638,23 @@ class Virtualizer {
|
|
|
624
638
|
})
|
|
625
639
|
);
|
|
626
640
|
if ("addEventListener" in this.scrollElement) {
|
|
627
|
-
this.
|
|
628
|
-
|
|
629
|
-
)
|
|
641
|
+
const target = this.scrollElement;
|
|
642
|
+
this.unsubs.push(this._iosGesture.listen(target));
|
|
643
|
+
if (isWebKit()) {
|
|
644
|
+
const onWheel = () => {
|
|
645
|
+
const win = this.targetWindow;
|
|
646
|
+
if (win === null) return;
|
|
647
|
+
if (this._wheelTimer !== null) win.clearTimeout(this._wheelTimer);
|
|
648
|
+
this._wheelTimer = win.setTimeout(() => {
|
|
649
|
+
this._wheelTimer = null;
|
|
650
|
+
this._flushHoldIfReady(true);
|
|
651
|
+
this._retryClampedAdjustment();
|
|
652
|
+
}, 150);
|
|
653
|
+
this._flushHoldAtTop();
|
|
654
|
+
};
|
|
655
|
+
target.addEventListener("wheel", onWheel, addEventListenerOptions);
|
|
656
|
+
this.unsubs.push(() => target.removeEventListener("wheel", onWheel));
|
|
657
|
+
}
|
|
630
658
|
}
|
|
631
659
|
this._scrollToOffset(this.getScrollOffset());
|
|
632
660
|
this._readTrailing(this._elementMaxScrollOffset());
|
|
@@ -704,7 +732,28 @@ class Virtualizer {
|
|
|
704
732
|
}
|
|
705
733
|
return null;
|
|
706
734
|
};
|
|
707
|
-
this._canWriteScroll = () => !(isIOSWebKit() && this._iosGesture.inMotion()) && !this._reportedOverscroll;
|
|
735
|
+
this._canWriteScroll = () => !(isIOSWebKit() && this._iosGesture.inMotion()) && !this._reportedOverscroll && this._wheelTimer === null;
|
|
736
|
+
this._holdAtTop = () => {
|
|
737
|
+
if (this._holdOffset === 0) return false;
|
|
738
|
+
const offset = this._readElementOffset();
|
|
739
|
+
return offset !== null && Math.min(offset, offset + this._holdOffset) < this.options.scrollMargin + 1;
|
|
740
|
+
};
|
|
741
|
+
this._flushHoldAtTop = () => {
|
|
742
|
+
const win = this.targetWindow;
|
|
743
|
+
if (win === null || this._wheelTimer === null || this._edgeFlushFrame !== null || !this._holdAtTop()) {
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
this._edgeFlushFrame = win.requestAnimationFrame(() => {
|
|
747
|
+
this._edgeFlushFrame = win.requestAnimationFrame(() => {
|
|
748
|
+
this._edgeFlushFrame = null;
|
|
749
|
+
if (this._wheelTimer === null || !this._holdAtTop()) return;
|
|
750
|
+
win.clearTimeout(this._wheelTimer);
|
|
751
|
+
this._wheelTimer = null;
|
|
752
|
+
this._flushHoldIfReady(true);
|
|
753
|
+
this._retryClampedAdjustment();
|
|
754
|
+
});
|
|
755
|
+
});
|
|
756
|
+
};
|
|
708
757
|
this._flushHoldIfReady = (sync) => {
|
|
709
758
|
var _a;
|
|
710
759
|
if (this._holdOffset === 0) return;
|
|
@@ -734,7 +783,7 @@ class Virtualizer {
|
|
|
734
783
|
this.scrollOffset = null;
|
|
735
784
|
return 0;
|
|
736
785
|
}
|
|
737
|
-
this.scrollOffset = this.scrollOffset ?? (typeof this.options.initialOffset === "function" ? this.options.initialOffset() : this.options.initialOffset);
|
|
786
|
+
this.scrollOffset = this.scrollOffset ?? (typeof this.options.initialOffset === "function" ? this.options.initialOffset(this) : this.options.initialOffset);
|
|
738
787
|
return this.scrollOffset;
|
|
739
788
|
};
|
|
740
789
|
this.getMeasurementOptions = memo(
|
|
@@ -1024,14 +1073,24 @@ class Virtualizer {
|
|
|
1024
1073
|
}
|
|
1025
1074
|
return true;
|
|
1026
1075
|
};
|
|
1076
|
+
this.dropDisconnected = () => {
|
|
1077
|
+
this.elementsCache.forEach((cached, key) => {
|
|
1078
|
+
if (!cached.isConnected) {
|
|
1079
|
+
this.observer.unobserve(cached);
|
|
1080
|
+
this.elementsCache.delete(key);
|
|
1081
|
+
}
|
|
1082
|
+
});
|
|
1083
|
+
};
|
|
1027
1084
|
this.measureElement = (node) => {
|
|
1028
1085
|
if (!node) {
|
|
1029
|
-
this.
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1086
|
+
this.dropDisconnected();
|
|
1087
|
+
if (!this._dropQueued) {
|
|
1088
|
+
this._dropQueued = true;
|
|
1089
|
+
queueMicrotask(() => {
|
|
1090
|
+
this._dropQueued = false;
|
|
1091
|
+
this.dropDisconnected();
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1035
1094
|
return;
|
|
1036
1095
|
}
|
|
1037
1096
|
const index = this.indexFromElement(node);
|
|
@@ -1053,6 +1112,9 @@ class Virtualizer {
|
|
|
1053
1112
|
this.resizeItem = (index, size) => {
|
|
1054
1113
|
var _a, _b, _c;
|
|
1055
1114
|
if (!this.isIndexInRange(index)) return;
|
|
1115
|
+
if (this.getMeasurementOptions() !== this.builtMeasurementOptions) {
|
|
1116
|
+
this.getMeasurements();
|
|
1117
|
+
}
|
|
1056
1118
|
let startShift = 0;
|
|
1057
1119
|
if ((_a = this._resizeBatch) == null ? void 0 : _a.sync) {
|
|
1058
1120
|
if (this.canShiftFromPendingResizes()) {
|
|
@@ -1574,15 +1636,23 @@ class Virtualizer {
|
|
|
1574
1636
|
// Every scroll command starts here: it becomes the in-flight command,
|
|
1575
1637
|
// writes its first target and leaves reconcile to retarget and retire it.
|
|
1576
1638
|
//
|
|
1577
|
-
// Targets are layout offsets. A held
|
|
1578
|
-
//
|
|
1579
|
-
//
|
|
1580
|
-
//
|
|
1639
|
+
// Targets are layout offsets. A correction held for the wheel is written
|
|
1640
|
+
// before the command (below). One held for a touch or a bounce is not
|
|
1641
|
+
// dropped by a command: the write lands the element `_holdOffset` short
|
|
1642
|
+
// of the target, under the rows exposed shifted by the same amount, and
|
|
1643
|
+
// the flush moves both together once a write is possible. Unless the
|
|
1644
|
+
// target is less than the hold (below).
|
|
1581
1645
|
//
|
|
1582
1646
|
// An index or end target that is already at its offset starts a smooth
|
|
1583
1647
|
// scroll as landed; an offset target never does, so its first scroll
|
|
1584
1648
|
// event is read as the user's (see the scroll handler in `_willUpdate`).
|
|
1585
1649
|
_startScroll(target, offset, behavior, kind) {
|
|
1650
|
+
if (this._wheelTimer !== null && this.targetWindow) {
|
|
1651
|
+
this.targetWindow.clearTimeout(this._wheelTimer);
|
|
1652
|
+
this._wheelTimer = null;
|
|
1653
|
+
this.scrollState = null;
|
|
1654
|
+
this._flushHoldIfReady(true);
|
|
1655
|
+
}
|
|
1586
1656
|
this.pendingScrollAnchor = null;
|
|
1587
1657
|
this._clampedAdjustment = null;
|
|
1588
1658
|
const tail = this._iosGesture.tail();
|
|
@@ -1616,6 +1686,12 @@ class Virtualizer {
|
|
|
1616
1686
|
}
|
|
1617
1687
|
this._iosGesture.end();
|
|
1618
1688
|
}
|
|
1689
|
+
if (offset < this._holdOffset && this._canWriteScroll()) {
|
|
1690
|
+
this.scrollState = null;
|
|
1691
|
+
this._flushHoldIfReady(true);
|
|
1692
|
+
this._clampedAdjustment = null;
|
|
1693
|
+
offset = Math.min(offset, Math.max(this.getMaxScrollOffset(), 0));
|
|
1694
|
+
}
|
|
1619
1695
|
this.scrollState = {
|
|
1620
1696
|
...target,
|
|
1621
1697
|
startedAt: this.now(),
|