@tanstack/virtual-core 3.19.2 → 3.19.3
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 +114 -122
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +7 -5
- package/dist/esm/index.d.ts +7 -5
- package/dist/esm/index.js +114 -122
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +185 -199
package/dist/cjs/index.d.cts
CHANGED
|
@@ -113,12 +113,10 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
113
113
|
scrollRect: Rect | null;
|
|
114
114
|
scrollOffset: number | null;
|
|
115
115
|
scrollDirection: ScrollDirection | null;
|
|
116
|
-
scrollAdjustments: number;
|
|
116
|
+
get scrollAdjustments(): number;
|
|
117
117
|
private _iosDeferredAdjustment;
|
|
118
|
-
private
|
|
119
|
-
private
|
|
120
|
-
private _iosTouchEndTimerId;
|
|
121
|
-
private _intendedScrollOffset;
|
|
118
|
+
private _iosTouch;
|
|
119
|
+
private pendingWrite;
|
|
122
120
|
private _clampedAdjustment;
|
|
123
121
|
shouldAdjustScrollPositionOnItemSizeChange: undefined | ((item: VirtualItem, delta: number, instance: Virtualizer<TScrollElement, TItemElement>) => boolean);
|
|
124
122
|
elementsCache: Map<Key, TItemElement>;
|
|
@@ -138,6 +136,8 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
138
136
|
_didMount: () => () => void;
|
|
139
137
|
_willUpdate: () => void;
|
|
140
138
|
private _retryClampedAdjustment;
|
|
139
|
+
private _iosInMotion;
|
|
140
|
+
private _endIosTouch;
|
|
141
141
|
private _flushIosDeferredIfReady;
|
|
142
142
|
private rafId;
|
|
143
143
|
private scheduleScrollReconcile;
|
|
@@ -183,6 +183,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
183
183
|
scrollToIndex: (index: number, { align: initialAlign, behavior, }?: ScrollToIndexOptions) => void;
|
|
184
184
|
scrollBy: (delta: number, { behavior }?: ScrollToOffsetOptions) => void;
|
|
185
185
|
scrollToEnd: ({ behavior }?: ScrollToEndOptions) => void;
|
|
186
|
+
private _startScroll;
|
|
186
187
|
cancelScroll: () => void;
|
|
187
188
|
getTotalSize: () => number;
|
|
188
189
|
/**
|
|
@@ -197,5 +198,6 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
197
198
|
*/
|
|
198
199
|
takeSnapshot: () => Array<VirtualItem>;
|
|
199
200
|
private _scrollToOffset;
|
|
201
|
+
private getCommandWrittenOffset;
|
|
200
202
|
measure: () => void;
|
|
201
203
|
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -113,12 +113,10 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
113
113
|
scrollRect: Rect | null;
|
|
114
114
|
scrollOffset: number | null;
|
|
115
115
|
scrollDirection: ScrollDirection | null;
|
|
116
|
-
scrollAdjustments: number;
|
|
116
|
+
get scrollAdjustments(): number;
|
|
117
117
|
private _iosDeferredAdjustment;
|
|
118
|
-
private
|
|
119
|
-
private
|
|
120
|
-
private _iosTouchEndTimerId;
|
|
121
|
-
private _intendedScrollOffset;
|
|
118
|
+
private _iosTouch;
|
|
119
|
+
private pendingWrite;
|
|
122
120
|
private _clampedAdjustment;
|
|
123
121
|
shouldAdjustScrollPositionOnItemSizeChange: undefined | ((item: VirtualItem, delta: number, instance: Virtualizer<TScrollElement, TItemElement>) => boolean);
|
|
124
122
|
elementsCache: Map<Key, TItemElement>;
|
|
@@ -138,6 +136,8 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
138
136
|
_didMount: () => () => void;
|
|
139
137
|
_willUpdate: () => void;
|
|
140
138
|
private _retryClampedAdjustment;
|
|
139
|
+
private _iosInMotion;
|
|
140
|
+
private _endIosTouch;
|
|
141
141
|
private _flushIosDeferredIfReady;
|
|
142
142
|
private rafId;
|
|
143
143
|
private scheduleScrollReconcile;
|
|
@@ -183,6 +183,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
183
183
|
scrollToIndex: (index: number, { align: initialAlign, behavior, }?: ScrollToIndexOptions) => void;
|
|
184
184
|
scrollBy: (delta: number, { behavior }?: ScrollToOffsetOptions) => void;
|
|
185
185
|
scrollToEnd: ({ behavior }?: ScrollToEndOptions) => void;
|
|
186
|
+
private _startScroll;
|
|
186
187
|
cancelScroll: () => void;
|
|
187
188
|
getTotalSize: () => number;
|
|
188
189
|
/**
|
|
@@ -197,5 +198,6 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
197
198
|
*/
|
|
198
199
|
takeSnapshot: () => Array<VirtualItem>;
|
|
199
200
|
private _scrollToOffset;
|
|
201
|
+
private getCommandWrittenOffset;
|
|
200
202
|
measure: () => void;
|
|
201
203
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -207,12 +207,9 @@ class Virtualizer {
|
|
|
207
207
|
this.scrollRect = null;
|
|
208
208
|
this.scrollOffset = null;
|
|
209
209
|
this.scrollDirection = null;
|
|
210
|
-
this.scrollAdjustments = 0;
|
|
211
210
|
this._iosDeferredAdjustment = 0;
|
|
212
|
-
this.
|
|
213
|
-
this.
|
|
214
|
-
this._iosTouchEndTimerId = null;
|
|
215
|
-
this._intendedScrollOffset = null;
|
|
211
|
+
this._iosTouch = null;
|
|
212
|
+
this.pendingWrite = null;
|
|
216
213
|
this._clampedAdjustment = null;
|
|
217
214
|
this.elementsCache = /* @__PURE__ */ new Map();
|
|
218
215
|
this._resizeBatch = null;
|
|
@@ -356,8 +353,7 @@ class Virtualizer {
|
|
|
356
353
|
this.pendingMin = 0;
|
|
357
354
|
this.itemSizeCacheVersion++;
|
|
358
355
|
}
|
|
359
|
-
let
|
|
360
|
-
let anchorDelta = 0;
|
|
356
|
+
let anchorDelta = null;
|
|
361
357
|
if (anchor && this.scrollOffset !== null) {
|
|
362
358
|
const [anchorKey, anchorOffset] = anchor;
|
|
363
359
|
const newMeasurements = this.getMeasurements();
|
|
@@ -373,18 +369,14 @@ class Virtualizer {
|
|
|
373
369
|
if (!followOnAppend && newOffset !== this.scrollOffset) {
|
|
374
370
|
anchorDelta = newOffset - this.scrollOffset;
|
|
375
371
|
this.scrollOffset = newOffset;
|
|
376
|
-
anchorResolved = true;
|
|
377
372
|
}
|
|
378
373
|
}
|
|
379
374
|
}
|
|
380
375
|
}
|
|
381
|
-
if (
|
|
382
|
-
this.pendingScrollAnchor =
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
followOnAppend,
|
|
386
|
-
anchorDelta
|
|
387
|
-
];
|
|
376
|
+
if (followOnAppend) {
|
|
377
|
+
this.pendingScrollAnchor = { kind: "follow", behavior: followOnAppend };
|
|
378
|
+
} else if (anchorDelta !== null) {
|
|
379
|
+
this.pendingScrollAnchor = { kind: "anchor", delta: anchorDelta };
|
|
388
380
|
}
|
|
389
381
|
};
|
|
390
382
|
this.notify = (sync) => {
|
|
@@ -425,9 +417,9 @@ class Virtualizer {
|
|
|
425
417
|
this.isScrolling = false;
|
|
426
418
|
this.scrollDirection = null;
|
|
427
419
|
this._iosDeferredAdjustment = 0;
|
|
428
|
-
this.
|
|
429
|
-
this._iosJustTouchEnded = false;
|
|
420
|
+
this._endIosTouch();
|
|
430
421
|
this._clampedAdjustment = null;
|
|
422
|
+
this.pendingWrite = null;
|
|
431
423
|
this.scrollElement = null;
|
|
432
424
|
this.targetWindow = null;
|
|
433
425
|
};
|
|
@@ -463,11 +455,12 @@ class Virtualizer {
|
|
|
463
455
|
this.unsubs.push(
|
|
464
456
|
this.options.observeElementOffset(this, (offset, isScrolling) => {
|
|
465
457
|
var _a2;
|
|
466
|
-
if (isScrolling && this.
|
|
458
|
+
if (isScrolling && this.pendingWrite === null && offset === this.scrollOffset) {
|
|
467
459
|
return;
|
|
468
460
|
}
|
|
469
|
-
|
|
470
|
-
|
|
461
|
+
const pending = this.pendingWrite;
|
|
462
|
+
if (pending !== null && Math.abs(offset - pending.target) < 1.5) {
|
|
463
|
+
offset = pending.target;
|
|
471
464
|
} else if (((_a2 = this.scrollState) == null ? void 0 : _a2.index) != null && // A non-smooth write lands at once, so any other scroll event is
|
|
472
465
|
// the user's, even before reconcile saw the target reached (the
|
|
473
466
|
// target may keep moving, or iOS ignored the write under a
|
|
@@ -484,12 +477,10 @@ class Virtualizer {
|
|
|
484
477
|
!isAnimating(this.scrollState) && !approxEqual(offset, this.scrollState.lastTargetOffset) && !approxEqual(offset, this.getScrollStateTarget(this.scrollState)) && (this._clampedAdjustment === null || Math.abs(offset - this._clampedAdjustment.maxAtWrite) >= 1.5)) {
|
|
485
478
|
this.scrollState = null;
|
|
486
479
|
}
|
|
487
|
-
this.
|
|
488
|
-
if (this.scrollState) this.scrollState.writtenOffset = null;
|
|
480
|
+
this.pendingWrite = null;
|
|
489
481
|
if (this._clampedAdjustment !== null && Math.abs(offset - this._clampedAdjustment.maxAtWrite) >= 1.5) {
|
|
490
482
|
this._clampedAdjustment = null;
|
|
491
483
|
}
|
|
492
|
-
this.scrollAdjustments = 0;
|
|
493
484
|
const prevOffset = this.getScrollOffset();
|
|
494
485
|
this.scrollDirection = isScrolling ? prevOffset === offset ? this.scrollDirection : prevOffset < offset ? "forward" : "backward" : null;
|
|
495
486
|
this.scrollOffset = offset;
|
|
@@ -504,24 +495,22 @@ class Virtualizer {
|
|
|
504
495
|
if ("addEventListener" in this.scrollElement) {
|
|
505
496
|
const scrollEl = this.scrollElement;
|
|
506
497
|
const onTouchStart = () => {
|
|
507
|
-
this.
|
|
508
|
-
this.
|
|
509
|
-
if (this._iosTouchEndTimerId !== null && this.targetWindow != null) {
|
|
510
|
-
this.targetWindow.clearTimeout(this._iosTouchEndTimerId);
|
|
511
|
-
this._iosTouchEndTimerId = null;
|
|
512
|
-
}
|
|
498
|
+
this._endIosTouch();
|
|
499
|
+
this._iosTouch = { phase: "down" };
|
|
513
500
|
};
|
|
514
501
|
const onTouchEnd = () => {
|
|
515
|
-
this.
|
|
502
|
+
this._endIosTouch();
|
|
516
503
|
if (!isIOSWebKit() || this.targetWindow == null) {
|
|
517
504
|
return;
|
|
518
505
|
}
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
this.
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
506
|
+
const tail = {
|
|
507
|
+
phase: "tail",
|
|
508
|
+
timerId: this.targetWindow.setTimeout(() => {
|
|
509
|
+
if (this._iosTouch === tail) this._iosTouch = null;
|
|
510
|
+
this._flushIosDeferredIfReady();
|
|
511
|
+
}, 150)
|
|
512
|
+
};
|
|
513
|
+
this._iosTouch = tail;
|
|
525
514
|
};
|
|
526
515
|
scrollEl.addEventListener(
|
|
527
516
|
"touchstart",
|
|
@@ -542,10 +531,7 @@ class Virtualizer {
|
|
|
542
531
|
scrollEl.removeEventListener("touchstart", onTouchStart);
|
|
543
532
|
scrollEl.removeEventListener("touchend", onTouchEnd);
|
|
544
533
|
scrollEl.removeEventListener("touchcancel", onTouchEnd);
|
|
545
|
-
|
|
546
|
-
this.targetWindow.clearTimeout(this._iosTouchEndTimerId);
|
|
547
|
-
this._iosTouchEndTimerId = null;
|
|
548
|
-
}
|
|
534
|
+
this._endIosTouch();
|
|
549
535
|
});
|
|
550
536
|
}
|
|
551
537
|
this._scrollToOffset(this.getScrollOffset(), {
|
|
@@ -556,14 +542,11 @@ class Virtualizer {
|
|
|
556
542
|
const anchor = this.pendingScrollAnchor;
|
|
557
543
|
this.pendingScrollAnchor = null;
|
|
558
544
|
if (anchor && this.scrollElement && this.options.enabled) {
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
if (anchorDelta !== 0) {
|
|
563
|
-
this._iosDeferredAdjustment += anchorDelta;
|
|
564
|
-
}
|
|
545
|
+
if (anchor.kind === "anchor") {
|
|
546
|
+
if (isIOSWebKit() && this._iosInMotion()) {
|
|
547
|
+
this._iosDeferredAdjustment += anchor.delta;
|
|
565
548
|
} else if (isSmoothScroll(this.scrollState) && !approxEqual(
|
|
566
|
-
this.getScrollOffset() -
|
|
549
|
+
this.getScrollOffset() - anchor.delta,
|
|
567
550
|
this.scrollState.lastTargetOffset
|
|
568
551
|
)) ;
|
|
569
552
|
else {
|
|
@@ -572,9 +555,8 @@ class Virtualizer {
|
|
|
572
555
|
behavior: void 0
|
|
573
556
|
});
|
|
574
557
|
}
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
this.scrollToEnd({ behavior: followOnAppend });
|
|
558
|
+
} else {
|
|
559
|
+
this.scrollToEnd({ behavior: anchor.behavior });
|
|
578
560
|
}
|
|
579
561
|
}
|
|
580
562
|
this._retryClampedAdjustment();
|
|
@@ -593,11 +575,17 @@ class Virtualizer {
|
|
|
593
575
|
});
|
|
594
576
|
}
|
|
595
577
|
};
|
|
578
|
+
this._iosInMotion = () => this.isScrolling || this._iosTouch !== null;
|
|
579
|
+
this._endIosTouch = () => {
|
|
580
|
+
var _a;
|
|
581
|
+
if (((_a = this._iosTouch) == null ? void 0 : _a.phase) === "tail" && this.targetWindow != null) {
|
|
582
|
+
this.targetWindow.clearTimeout(this._iosTouch.timerId);
|
|
583
|
+
}
|
|
584
|
+
this._iosTouch = null;
|
|
585
|
+
};
|
|
596
586
|
this._flushIosDeferredIfReady = () => {
|
|
597
587
|
if (this._iosDeferredAdjustment === 0) return;
|
|
598
|
-
if (this.
|
|
599
|
-
if (this._iosTouching) return;
|
|
600
|
-
if (this._iosJustTouchEnded) return;
|
|
588
|
+
if (this._iosInMotion()) return;
|
|
601
589
|
const cur = this.getScrollOffset();
|
|
602
590
|
const max = this.getMaxScrollOffset();
|
|
603
591
|
if (cur < 0 || cur > max) return;
|
|
@@ -608,7 +596,7 @@ class Virtualizer {
|
|
|
608
596
|
const delta = this._iosDeferredAdjustment;
|
|
609
597
|
this._iosDeferredAdjustment = 0;
|
|
610
598
|
this._scrollToOffset(cur, {
|
|
611
|
-
adjustments: this.scrollAdjustments
|
|
599
|
+
adjustments: this.scrollAdjustments + delta,
|
|
612
600
|
behavior: void 0
|
|
613
601
|
});
|
|
614
602
|
};
|
|
@@ -931,7 +919,7 @@ class Virtualizer {
|
|
|
931
919
|
}
|
|
932
920
|
};
|
|
933
921
|
this.resizeItem = (index, size) => {
|
|
934
|
-
var _a, _b, _c
|
|
922
|
+
var _a, _b, _c;
|
|
935
923
|
if (!this.isIndexInRange(index)) return;
|
|
936
924
|
if ((_a = this._resizeBatch) == null ? void 0 : _a.sync) this.getMeasurements();
|
|
937
925
|
let cachedSize;
|
|
@@ -990,8 +978,9 @@ class Virtualizer {
|
|
|
990
978
|
}
|
|
991
979
|
this.itemSizeCache.set(key, size);
|
|
992
980
|
this.itemSizeCacheVersion++;
|
|
993
|
-
const
|
|
994
|
-
|
|
981
|
+
const writtenOffset = this.getCommandWrittenOffset();
|
|
982
|
+
const awaitingCommandReadBack = writtenOffset !== null && !approxEqual(
|
|
983
|
+
writtenOffset,
|
|
995
984
|
this.getScrollOffset() + this.scrollAdjustments
|
|
996
985
|
);
|
|
997
986
|
let adjustedSync = false;
|
|
@@ -1006,7 +995,7 @@ class Virtualizer {
|
|
|
1006
995
|
}
|
|
1007
996
|
if (this._resizeBatch) {
|
|
1008
997
|
this._resizeBatch.notify = true;
|
|
1009
|
-
(
|
|
998
|
+
(_c = this._resizeBatch).sync || (_c.sync = adjustedSync);
|
|
1010
999
|
return;
|
|
1011
1000
|
}
|
|
1012
1001
|
this.notify(adjustedSync);
|
|
@@ -1108,82 +1097,46 @@ class Virtualizer {
|
|
|
1108
1097
|
];
|
|
1109
1098
|
};
|
|
1110
1099
|
this.scrollToOffset = (toOffset, { align = "start", behavior = "auto" } = {}) => {
|
|
1111
|
-
this.
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
startedAt: now,
|
|
1118
|
-
lastTargetOffset: offset,
|
|
1119
|
-
stableFrames: 0,
|
|
1120
|
-
phase: initialScrollPhase(behavior, false)
|
|
1121
|
-
};
|
|
1122
|
-
this._scrollToOffset(offset, { adjustments: void 0, behavior });
|
|
1123
|
-
this.scheduleScrollReconcile();
|
|
1100
|
+
this._startScroll(
|
|
1101
|
+
{ index: null, align },
|
|
1102
|
+
this.getOffsetForAlignment(toOffset, align),
|
|
1103
|
+
behavior,
|
|
1104
|
+
"absolute"
|
|
1105
|
+
);
|
|
1124
1106
|
};
|
|
1125
1107
|
this.scrollToIndex = (index, {
|
|
1126
1108
|
align: initialAlign = "auto",
|
|
1127
1109
|
behavior = "auto"
|
|
1128
1110
|
} = {}) => {
|
|
1129
|
-
this._iosDeferredAdjustment = 0;
|
|
1130
1111
|
index = Math.max(0, Math.min(index, this.options.count - 1));
|
|
1131
1112
|
const offsetInfo = this.getOffsetForIndex(index, initialAlign);
|
|
1132
1113
|
if (!offsetInfo) {
|
|
1114
|
+
this._iosDeferredAdjustment = 0;
|
|
1133
1115
|
return;
|
|
1134
1116
|
}
|
|
1135
1117
|
const [offset, align] = offsetInfo;
|
|
1136
|
-
|
|
1137
|
-
this.scrollState = {
|
|
1138
|
-
index,
|
|
1139
|
-
align,
|
|
1140
|
-
startedAt: now,
|
|
1141
|
-
lastTargetOffset: offset,
|
|
1142
|
-
stableFrames: 0,
|
|
1143
|
-
phase: initialScrollPhase(
|
|
1144
|
-
behavior,
|
|
1145
|
-
approxEqual(offset, this.getScrollOffset())
|
|
1146
|
-
)
|
|
1147
|
-
};
|
|
1148
|
-
this._scrollToOffset(offset, { adjustments: void 0, behavior });
|
|
1149
|
-
this.scheduleScrollReconcile();
|
|
1118
|
+
this._startScroll({ index, align }, offset, behavior, "absolute");
|
|
1150
1119
|
};
|
|
1151
1120
|
this.scrollBy = (delta, { behavior = "auto" } = {}) => {
|
|
1152
|
-
var _a;
|
|
1153
1121
|
const offset = this.getOffsetForAlignment(
|
|
1154
|
-
(
|
|
1122
|
+
(this.getCommandWrittenOffset() ?? this.getScrollOffset()) + delta,
|
|
1155
1123
|
"start"
|
|
1156
1124
|
);
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
stableFrames: 0,
|
|
1164
|
-
phase: initialScrollPhase(behavior, false)
|
|
1165
|
-
};
|
|
1166
|
-
this._scrollToOffset(offset, { adjustments: void 0, behavior });
|
|
1167
|
-
this.scheduleScrollReconcile();
|
|
1125
|
+
this._startScroll(
|
|
1126
|
+
{ index: null, align: "start" },
|
|
1127
|
+
offset,
|
|
1128
|
+
behavior,
|
|
1129
|
+
"relative"
|
|
1130
|
+
);
|
|
1168
1131
|
};
|
|
1169
1132
|
this.scrollToEnd = ({ behavior = "auto" } = {}) => {
|
|
1170
1133
|
if (this.options.count > 0) {
|
|
1171
|
-
this.
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
startedAt: this.now(),
|
|
1178
|
-
lastTargetOffset: offset,
|
|
1179
|
-
stableFrames: 0,
|
|
1180
|
-
phase: initialScrollPhase(
|
|
1181
|
-
behavior,
|
|
1182
|
-
approxEqual(offset, this.getScrollOffset())
|
|
1183
|
-
)
|
|
1184
|
-
};
|
|
1185
|
-
this._scrollToOffset(offset, { adjustments: void 0, behavior });
|
|
1186
|
-
this.scheduleScrollReconcile();
|
|
1134
|
+
this._startScroll(
|
|
1135
|
+
{ index: this.options.count - 1, align: "end", toEnd: true },
|
|
1136
|
+
Math.max(this.getMaxScrollOffset(), 0),
|
|
1137
|
+
behavior,
|
|
1138
|
+
"absolute"
|
|
1139
|
+
);
|
|
1187
1140
|
return;
|
|
1188
1141
|
}
|
|
1189
1142
|
this.scrollToOffset(Math.max(this.getTotalSize() - this.getSize(), 0), {
|
|
@@ -1250,12 +1203,14 @@ class Virtualizer {
|
|
|
1250
1203
|
adjustments,
|
|
1251
1204
|
behavior
|
|
1252
1205
|
}) => {
|
|
1253
|
-
this.
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1206
|
+
this.pendingWrite = {
|
|
1207
|
+
target: offset + (adjustments ?? 0),
|
|
1208
|
+
smooth: behavior === "smooth",
|
|
1209
|
+
adjustments: adjustments ?? this.scrollAdjustments
|
|
1210
|
+
};
|
|
1257
1211
|
this.options.scrollToFn(offset, { behavior, adjustments }, this);
|
|
1258
1212
|
};
|
|
1213
|
+
this.getCommandWrittenOffset = () => this.scrollState !== null && this.pendingWrite !== null && !this.pendingWrite.smooth ? this.pendingWrite.target : null;
|
|
1259
1214
|
this.measure = () => {
|
|
1260
1215
|
this.pendingMin = null;
|
|
1261
1216
|
this.itemSizeCache.clear();
|
|
@@ -1265,6 +1220,13 @@ class Virtualizer {
|
|
|
1265
1220
|
};
|
|
1266
1221
|
this.setOptions(opts);
|
|
1267
1222
|
}
|
|
1223
|
+
// Size compensation written to the element but not yet reflected in
|
|
1224
|
+
// `scrollOffset`: the element is expected at `scrollOffset +
|
|
1225
|
+
// scrollAdjustments` until the next scroll event reports it.
|
|
1226
|
+
get scrollAdjustments() {
|
|
1227
|
+
var _a;
|
|
1228
|
+
return ((_a = this.pendingWrite) == null ? void 0 : _a.adjustments) ?? 0;
|
|
1229
|
+
}
|
|
1268
1230
|
// Returns `true` when it performed a synchronous `scrollTop` write this
|
|
1269
1231
|
// tick, `false` when the delta was zero or the write was deferred (iOS).
|
|
1270
1232
|
// `resizeItem` uses that to decide whether the follow-up `notify` must be
|
|
@@ -1275,7 +1237,7 @@ class Virtualizer {
|
|
|
1275
1237
|
if (process.env.NODE_ENV !== "production" && this.options.debug) {
|
|
1276
1238
|
console.info("correction", delta);
|
|
1277
1239
|
}
|
|
1278
|
-
if (isIOSWebKit() &&
|
|
1240
|
+
if (isIOSWebKit() && this._iosInMotion()) {
|
|
1279
1241
|
if (((_a = this.scrollState) == null ? void 0 : _a.index) == null) {
|
|
1280
1242
|
this._iosDeferredAdjustment += delta;
|
|
1281
1243
|
}
|
|
@@ -1286,13 +1248,13 @@ class Virtualizer {
|
|
|
1286
1248
|
const maxAtWrite = el !== null && ("scrollHeight" in el || "document" in el) ? this.getMaxScrollOffset() : null;
|
|
1287
1249
|
this._clampedAdjustment = maxAtWrite !== null && target > maxAtWrite + 0.5 ? { target, maxAtWrite } : null;
|
|
1288
1250
|
this._scrollToOffset(this.getScrollOffset(), {
|
|
1289
|
-
adjustments: this.scrollAdjustments
|
|
1251
|
+
adjustments: this.scrollAdjustments + delta,
|
|
1290
1252
|
behavior
|
|
1291
1253
|
});
|
|
1292
1254
|
if (this.scrollOffset !== null) {
|
|
1293
1255
|
this.scrollOffset += this.scrollAdjustments;
|
|
1294
1256
|
if (this.scrollOffset < 0) this.scrollOffset = 0;
|
|
1295
|
-
this.
|
|
1257
|
+
if (this.pendingWrite) this.pendingWrite.adjustments = 0;
|
|
1296
1258
|
}
|
|
1297
1259
|
return true;
|
|
1298
1260
|
}
|
|
@@ -1364,6 +1326,36 @@ class Virtualizer {
|
|
|
1364
1326
|
}
|
|
1365
1327
|
this.scheduleScrollReconcile();
|
|
1366
1328
|
}
|
|
1329
|
+
// Every scroll command starts here: it becomes the in-flight command,
|
|
1330
|
+
// writes its first target and leaves reconcile to retarget and retire it.
|
|
1331
|
+
//
|
|
1332
|
+
// An absolute command derives its target from current measurements, so
|
|
1333
|
+
// any iOS-deferred compensation still pending is stale by definition —
|
|
1334
|
+
// the command already accounts for the measurements the delta was
|
|
1335
|
+
// compensating for. Drop it so _flushIosDeferredIfReady doesn't replay it
|
|
1336
|
+
// onto the just-established position. A relative command (scrollBy)
|
|
1337
|
+
// builds on the current offset, so it keeps the deferral.
|
|
1338
|
+
//
|
|
1339
|
+
// An index or end target that is already at its offset starts a smooth
|
|
1340
|
+
// scroll as landed; an offset target never does, so its first scroll
|
|
1341
|
+
// event is read as the user's (see the scroll handler in `_willUpdate`).
|
|
1342
|
+
_startScroll(target, offset, behavior, kind) {
|
|
1343
|
+
if (kind === "absolute") {
|
|
1344
|
+
this._iosDeferredAdjustment = 0;
|
|
1345
|
+
}
|
|
1346
|
+
this.scrollState = {
|
|
1347
|
+
...target,
|
|
1348
|
+
startedAt: this.now(),
|
|
1349
|
+
lastTargetOffset: offset,
|
|
1350
|
+
stableFrames: 0,
|
|
1351
|
+
phase: initialScrollPhase(
|
|
1352
|
+
behavior,
|
|
1353
|
+
target.index != null && approxEqual(offset, this.getScrollOffset())
|
|
1354
|
+
)
|
|
1355
|
+
};
|
|
1356
|
+
this._scrollToOffset(offset, { adjustments: void 0, behavior });
|
|
1357
|
+
this.scheduleScrollReconcile();
|
|
1358
|
+
}
|
|
1367
1359
|
}
|
|
1368
1360
|
const findNearestBinarySearch = (low, high, getCurrentValue, value) => {
|
|
1369
1361
|
while (low <= high) {
|