@tanstack/react-virtual 3.0.0-beta.23 → 3.0.0-beta.28
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/build/lib/index.d.ts +4 -0
- package/build/lib/index.esm.js +56 -0
- package/build/lib/index.esm.js.map +1 -0
- package/build/{cjs/react-virtual/src → lib}/index.js +18 -22
- package/build/lib/index.js.map +1 -0
- package/build/lib/index.mjs +56 -0
- package/build/lib/index.mjs.map +1 -0
- package/build/umd/index.development.js +75 -164
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +11 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +23 -10
- package/src/index.tsx +8 -2
- package/build/cjs/react-virtual/src/index.js.map +0 -1
- package/build/cjs/virtual-core/build/esm/index.js +0 -681
- package/build/cjs/virtual-core/build/esm/index.js.map +0 -1
- package/build/esm/index.js +0 -708
- package/build/esm/index.js.map +0 -1
- package/build/stats.html +0 -2689
- package/build/stats.json +0 -90
- package/build/types/index.d.ts +0 -17
|
@@ -52,53 +52,59 @@
|
|
|
52
52
|
if (opts.key && opts.debug != null && opts.debug()) depTime = Date.now();
|
|
53
53
|
const newDeps = getDeps();
|
|
54
54
|
const depsChanged = newDeps.length !== deps.length || newDeps.some((dep, index) => deps[index] !== dep);
|
|
55
|
-
|
|
56
55
|
if (!depsChanged) {
|
|
57
56
|
return result;
|
|
58
57
|
}
|
|
59
|
-
|
|
60
58
|
deps = newDeps;
|
|
61
59
|
let resultTime;
|
|
62
60
|
if (opts.key && opts.debug != null && opts.debug()) resultTime = Date.now();
|
|
63
61
|
result = fn(...newDeps);
|
|
64
62
|
opts == null ? void 0 : opts.onChange == null ? void 0 : opts.onChange(result);
|
|
65
|
-
|
|
66
63
|
if (opts.key && opts.debug != null && opts.debug()) {
|
|
67
64
|
const depEndTime = Math.round((Date.now() - depTime) * 100) / 100;
|
|
68
65
|
const resultEndTime = Math.round((Date.now() - resultTime) * 100) / 100;
|
|
69
66
|
const resultFpsPercentage = resultEndTime / 16;
|
|
70
|
-
|
|
71
67
|
const pad = (str, num) => {
|
|
72
68
|
str = String(str);
|
|
73
|
-
|
|
74
69
|
while (str.length < num) {
|
|
75
70
|
str = ' ' + str;
|
|
76
71
|
}
|
|
77
|
-
|
|
78
72
|
return str;
|
|
79
73
|
};
|
|
80
|
-
|
|
81
|
-
|
|
74
|
+
console.info(`%c⏱ ${pad(resultEndTime, 5)} /${pad(depEndTime, 5)} ms`, `
|
|
75
|
+
font-size: .6rem;
|
|
76
|
+
font-weight: bold;
|
|
77
|
+
color: hsl(${Math.max(0, Math.min(120 - 120 * resultFpsPercentage, 120))}deg 100% 31%);`, opts == null ? void 0 : opts.key);
|
|
82
78
|
}
|
|
83
|
-
|
|
84
79
|
return result;
|
|
85
80
|
};
|
|
86
81
|
}
|
|
87
82
|
|
|
83
|
+
/**
|
|
84
|
+
* virtual-core
|
|
85
|
+
*
|
|
86
|
+
* Copyright (c) TanStack
|
|
87
|
+
*
|
|
88
|
+
* This source code is licensed under the MIT license found in the
|
|
89
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
90
|
+
*
|
|
91
|
+
* @license MIT
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
//
|
|
95
|
+
|
|
88
96
|
//
|
|
97
|
+
|
|
89
98
|
const defaultKeyExtractor = index => index;
|
|
90
99
|
const defaultRangeExtractor = range => {
|
|
91
100
|
const start = Math.max(range.startIndex - range.overscan, 0);
|
|
92
101
|
const end = Math.min(range.endIndex + range.overscan, range.count - 1);
|
|
93
102
|
const arr = [];
|
|
94
|
-
|
|
95
103
|
for (let i = start; i <= end; i++) {
|
|
96
104
|
arr.push(i);
|
|
97
105
|
}
|
|
98
|
-
|
|
99
106
|
return arr;
|
|
100
107
|
};
|
|
101
|
-
|
|
102
108
|
const memoRectCallback = (instance, cb) => {
|
|
103
109
|
let prev = {
|
|
104
110
|
height: -1,
|
|
@@ -108,25 +114,20 @@
|
|
|
108
114
|
if (instance.options.horizontal ? rect.width !== prev.width : rect.height !== prev.height) {
|
|
109
115
|
cb(rect);
|
|
110
116
|
}
|
|
111
|
-
|
|
112
117
|
prev = rect;
|
|
113
118
|
};
|
|
114
119
|
};
|
|
115
|
-
|
|
116
120
|
const observeElementRect = (instance, cb) => {
|
|
117
121
|
const observer = new ResizeObserver(entries => {
|
|
118
122
|
var _entries$, _entries$2;
|
|
119
|
-
|
|
120
123
|
cb({
|
|
121
124
|
width: (_entries$ = entries[0]) == null ? void 0 : _entries$.contentRect.width,
|
|
122
125
|
height: (_entries$2 = entries[0]) == null ? void 0 : _entries$2.contentRect.height
|
|
123
126
|
});
|
|
124
127
|
});
|
|
125
|
-
|
|
126
128
|
if (!instance.scrollElement) {
|
|
127
129
|
return;
|
|
128
130
|
}
|
|
129
|
-
|
|
130
131
|
cb(instance.scrollElement.getBoundingClientRect());
|
|
131
132
|
observer.observe(instance.scrollElement);
|
|
132
133
|
return () => {
|
|
@@ -135,16 +136,13 @@
|
|
|
135
136
|
};
|
|
136
137
|
const observeWindowRect = (instance, cb) => {
|
|
137
138
|
const memoizedCallback = memoRectCallback(instance, cb);
|
|
138
|
-
|
|
139
139
|
const onResize = () => memoizedCallback({
|
|
140
140
|
width: instance.scrollElement.innerWidth,
|
|
141
141
|
height: instance.scrollElement.innerHeight
|
|
142
142
|
});
|
|
143
|
-
|
|
144
143
|
if (!instance.scrollElement) {
|
|
145
144
|
return;
|
|
146
145
|
}
|
|
147
|
-
|
|
148
146
|
onResize();
|
|
149
147
|
instance.scrollElement.addEventListener('resize', onResize, {
|
|
150
148
|
capture: false,
|
|
@@ -158,38 +156,30 @@
|
|
|
158
156
|
element: ['scrollLeft', 'scrollTop'],
|
|
159
157
|
window: ['scrollX', 'scrollY']
|
|
160
158
|
};
|
|
161
|
-
|
|
162
159
|
const createOffsetObserver = mode => {
|
|
163
160
|
return (instance, cb) => {
|
|
164
161
|
if (!instance.scrollElement) {
|
|
165
162
|
return;
|
|
166
163
|
}
|
|
167
|
-
|
|
168
164
|
const propX = scrollProps[mode][0];
|
|
169
165
|
const propY = scrollProps[mode][1];
|
|
170
166
|
let prevX = instance.scrollElement[propX];
|
|
171
167
|
let prevY = instance.scrollElement[propY];
|
|
172
|
-
|
|
173
168
|
const scroll = () => {
|
|
174
169
|
const offset = instance.scrollElement[instance.options.horizontal ? propX : propY];
|
|
175
170
|
cb(Math.max(0, offset - instance.options.scrollMargin));
|
|
176
171
|
};
|
|
177
|
-
|
|
178
172
|
scroll();
|
|
179
|
-
|
|
180
173
|
const onScroll = e => {
|
|
181
174
|
const target = e.currentTarget;
|
|
182
175
|
const scrollX = target[propX];
|
|
183
176
|
const scrollY = target[propY];
|
|
184
|
-
|
|
185
177
|
if (instance.options.horizontal ? prevX - scrollX : prevY - scrollY) {
|
|
186
178
|
scroll();
|
|
187
179
|
}
|
|
188
|
-
|
|
189
180
|
prevX = scrollX;
|
|
190
181
|
prevY = scrollY;
|
|
191
182
|
};
|
|
192
|
-
|
|
193
183
|
instance.scrollElement.addEventListener('scroll', onScroll, {
|
|
194
184
|
capture: false,
|
|
195
185
|
passive: true
|
|
@@ -199,7 +189,6 @@
|
|
|
199
189
|
};
|
|
200
190
|
};
|
|
201
191
|
};
|
|
202
|
-
|
|
203
192
|
const observeElementOffset = createOffsetObserver('element');
|
|
204
193
|
const observeWindowOffset = createOffsetObserver('window');
|
|
205
194
|
const measureElement = (element, instance) => {
|
|
@@ -207,34 +196,33 @@
|
|
|
207
196
|
};
|
|
208
197
|
const windowScroll = (offset, _ref, instance) => {
|
|
209
198
|
var _instance$scrollEleme;
|
|
210
|
-
|
|
211
199
|
let {
|
|
212
|
-
|
|
200
|
+
adjustments,
|
|
201
|
+
behavior,
|
|
213
202
|
sync
|
|
214
203
|
} = _ref;
|
|
215
|
-
const toOffset = sync ? offset : offset + instance.options.scrollMargin;
|
|
204
|
+
const toOffset = (sync ? offset : offset + instance.options.scrollMargin) + (adjustments ?? 0);
|
|
216
205
|
(_instance$scrollEleme = instance.scrollElement) == null ? void 0 : _instance$scrollEleme.scrollTo == null ? void 0 : _instance$scrollEleme.scrollTo({
|
|
217
206
|
[instance.options.horizontal ? 'left' : 'top']: toOffset,
|
|
218
|
-
behavior
|
|
207
|
+
behavior
|
|
219
208
|
});
|
|
220
209
|
};
|
|
221
210
|
const elementScroll = (offset, _ref2, instance) => {
|
|
222
211
|
var _instance$scrollEleme2;
|
|
223
|
-
|
|
224
212
|
let {
|
|
225
|
-
|
|
213
|
+
adjustments,
|
|
214
|
+
behavior,
|
|
226
215
|
sync
|
|
227
216
|
} = _ref2;
|
|
228
|
-
const toOffset = sync ? offset : offset + instance.options.scrollMargin;
|
|
217
|
+
const toOffset = (sync ? offset : offset + instance.options.scrollMargin) + (adjustments ?? 0);
|
|
229
218
|
(_instance$scrollEleme2 = instance.scrollElement) == null ? void 0 : _instance$scrollEleme2.scrollTo == null ? void 0 : _instance$scrollEleme2.scrollTo({
|
|
230
219
|
[instance.options.horizontal ? 'left' : 'top']: toOffset,
|
|
231
|
-
behavior
|
|
220
|
+
behavior
|
|
232
221
|
});
|
|
233
222
|
};
|
|
234
223
|
class Virtualizer {
|
|
235
224
|
constructor(_opts) {
|
|
236
225
|
var _this = this;
|
|
237
|
-
|
|
238
226
|
this.unsubs = [];
|
|
239
227
|
this.scrollElement = null;
|
|
240
228
|
this.isScrolling = false;
|
|
@@ -242,9 +230,9 @@
|
|
|
242
230
|
this.measurementsCache = [];
|
|
243
231
|
this.itemMeasurementsCache = {};
|
|
244
232
|
this.pendingMeasuredCacheIndexes = [];
|
|
245
|
-
this.
|
|
233
|
+
this.scrollAdjustments = 0;
|
|
246
234
|
this.measureElementCache = {};
|
|
247
|
-
|
|
235
|
+
this.pendingScrollToIndexCallback = null;
|
|
248
236
|
this.getResizeObserver = (() => {
|
|
249
237
|
let _ro = null;
|
|
250
238
|
return () => {
|
|
@@ -261,12 +249,10 @@
|
|
|
261
249
|
}
|
|
262
250
|
};
|
|
263
251
|
})();
|
|
264
|
-
|
|
265
252
|
this.range = {
|
|
266
253
|
startIndex: 0,
|
|
267
254
|
endIndex: 0
|
|
268
255
|
};
|
|
269
|
-
|
|
270
256
|
this.setOptions = opts => {
|
|
271
257
|
Object.entries(opts).forEach(_ref3 => {
|
|
272
258
|
let [key, value] = _ref3;
|
|
@@ -283,7 +269,6 @@
|
|
|
283
269
|
horizontal: false,
|
|
284
270
|
getItemKey: defaultKeyExtractor,
|
|
285
271
|
rangeExtractor: defaultRangeExtractor,
|
|
286
|
-
enableSmoothScroll: true,
|
|
287
272
|
onChange: () => {},
|
|
288
273
|
measureElement,
|
|
289
274
|
initialRect: {
|
|
@@ -296,42 +281,35 @@
|
|
|
296
281
|
...opts
|
|
297
282
|
};
|
|
298
283
|
};
|
|
299
|
-
|
|
300
284
|
this.notify = () => {
|
|
301
285
|
var _this$options$onChang, _this$options;
|
|
302
|
-
|
|
303
286
|
(_this$options$onChang = (_this$options = this.options).onChange) == null ? void 0 : _this$options$onChang.call(_this$options, this);
|
|
304
287
|
};
|
|
305
|
-
|
|
306
288
|
this.cleanup = () => {
|
|
307
289
|
this.unsubs.filter(Boolean).forEach(d => d());
|
|
308
290
|
this.unsubs = [];
|
|
309
291
|
this.scrollElement = null;
|
|
310
292
|
};
|
|
311
|
-
|
|
312
293
|
this._didMount = () => {
|
|
313
294
|
return () => {
|
|
314
295
|
var _this$getResizeObserv;
|
|
315
|
-
|
|
316
296
|
(_this$getResizeObserv = this.getResizeObserver()) == null ? void 0 : _this$getResizeObserv.disconnect();
|
|
317
297
|
this.measureElementCache = {};
|
|
318
298
|
this.cleanup();
|
|
319
299
|
};
|
|
320
300
|
};
|
|
321
|
-
|
|
322
301
|
this._willUpdate = () => {
|
|
302
|
+
var _this$pendingScrollTo;
|
|
303
|
+
(_this$pendingScrollTo = this.pendingScrollToIndexCallback) == null ? void 0 : _this$pendingScrollTo.call(this);
|
|
323
304
|
const scrollElement = this.options.getScrollElement();
|
|
324
|
-
|
|
325
305
|
if (this.scrollElement !== scrollElement) {
|
|
326
306
|
this.cleanup();
|
|
327
307
|
this.scrollElement = scrollElement;
|
|
328
|
-
|
|
329
308
|
this._scrollToOffset(this.scrollOffset, {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
309
|
+
adjustments: undefined,
|
|
310
|
+
behavior: undefined,
|
|
311
|
+
sync: true
|
|
333
312
|
});
|
|
334
|
-
|
|
335
313
|
this.unsubs.push(this.options.observeElementRect(this, rect => {
|
|
336
314
|
this.scrollRect = rect;
|
|
337
315
|
this.calculateRange();
|
|
@@ -341,11 +319,10 @@
|
|
|
341
319
|
clearTimeout(this.isScrollingTimeoutId);
|
|
342
320
|
this.isScrollingTimeoutId = null;
|
|
343
321
|
}
|
|
344
|
-
|
|
345
322
|
if (this.scrollOffset !== offset) {
|
|
346
323
|
this.scrollOffset = offset;
|
|
347
324
|
this.isScrolling = true;
|
|
348
|
-
this.
|
|
325
|
+
this.scrollAdjustments = 0;
|
|
349
326
|
this.isScrollingTimeoutId = setTimeout(() => {
|
|
350
327
|
this.isScrollingTimeoutId = null;
|
|
351
328
|
this.isScrolling = false;
|
|
@@ -353,25 +330,21 @@
|
|
|
353
330
|
}, this.options.scrollingDelay);
|
|
354
331
|
} else {
|
|
355
332
|
this.isScrolling = false;
|
|
356
|
-
this.
|
|
333
|
+
this.scrollAdjustments = 0;
|
|
357
334
|
}
|
|
358
|
-
|
|
359
335
|
this.calculateRange();
|
|
360
336
|
}));
|
|
361
337
|
} else if (!this.isScrolling) {
|
|
362
338
|
this.calculateRange();
|
|
363
339
|
}
|
|
364
340
|
};
|
|
365
|
-
|
|
366
341
|
this.getSize = () => {
|
|
367
342
|
return this.scrollRect[this.options.horizontal ? 'width' : 'height'];
|
|
368
343
|
};
|
|
369
|
-
|
|
370
344
|
this.getMeasurements = memo(() => [this.options.count, this.options.paddingStart, this.options.getItemKey, this.itemMeasurementsCache], (count, paddingStart, getItemKey, measurementsCache) => {
|
|
371
345
|
const min = this.pendingMeasuredCacheIndexes.length > 0 ? Math.min(...this.pendingMeasuredCacheIndexes) : 0;
|
|
372
346
|
this.pendingMeasuredCacheIndexes = [];
|
|
373
347
|
const measurements = this.measurementsCache.slice(0, min);
|
|
374
|
-
|
|
375
348
|
for (let i = min; i < count; i++) {
|
|
376
349
|
const key = getItemKey(i);
|
|
377
350
|
const measuredSize = measurementsCache[key];
|
|
@@ -386,7 +359,6 @@
|
|
|
386
359
|
key
|
|
387
360
|
};
|
|
388
361
|
}
|
|
389
|
-
|
|
390
362
|
this.measurementsCache = measurements;
|
|
391
363
|
return measurements;
|
|
392
364
|
}, {
|
|
@@ -399,19 +371,18 @@
|
|
|
399
371
|
outerSize,
|
|
400
372
|
scrollOffset
|
|
401
373
|
});
|
|
402
|
-
|
|
403
374
|
if (range.startIndex !== this.range.startIndex || range.endIndex !== this.range.endIndex) {
|
|
404
375
|
this.range = range;
|
|
405
376
|
this.notify();
|
|
406
377
|
}
|
|
407
|
-
|
|
408
378
|
return this.range;
|
|
409
379
|
}, {
|
|
410
380
|
key: 'calculateRange',
|
|
411
381
|
debug: () => this.options.debug
|
|
412
382
|
});
|
|
413
383
|
this.getIndexes = memo(() => [this.options.rangeExtractor, this.range, this.options.overscan, this.options.count], (rangeExtractor, range, overscan, count) => {
|
|
414
|
-
return rangeExtractor({
|
|
384
|
+
return rangeExtractor({
|
|
385
|
+
...range,
|
|
415
386
|
overscan,
|
|
416
387
|
count: count
|
|
417
388
|
});
|
|
@@ -419,109 +390,84 @@
|
|
|
419
390
|
key: 'getIndexes',
|
|
420
391
|
debug: () => this.options.debug
|
|
421
392
|
});
|
|
422
|
-
|
|
423
393
|
this.indexFromElement = node => {
|
|
424
394
|
const attributeName = this.options.indexAttribute;
|
|
425
395
|
const indexStr = node.getAttribute(attributeName);
|
|
426
|
-
|
|
427
396
|
if (!indexStr) {
|
|
428
|
-
console.warn(
|
|
397
|
+
console.warn(`Missing attribute name '${attributeName}={index}' on measured element.`);
|
|
429
398
|
return -1;
|
|
430
399
|
}
|
|
431
|
-
|
|
432
400
|
return parseInt(indexStr, 10);
|
|
433
401
|
};
|
|
434
|
-
|
|
435
402
|
this._measureElement = (node, _sync) => {
|
|
436
|
-
var _this$itemMeasurement;
|
|
437
|
-
|
|
438
403
|
const index = this.indexFromElement(node);
|
|
439
404
|
const item = this.measurementsCache[index];
|
|
440
|
-
|
|
441
405
|
if (!item) {
|
|
442
406
|
return;
|
|
443
407
|
}
|
|
444
|
-
|
|
445
408
|
const prevNode = this.measureElementCache[item.key];
|
|
446
409
|
const ro = this.getResizeObserver();
|
|
447
|
-
|
|
448
410
|
if (!node.isConnected) {
|
|
449
411
|
if (prevNode) {
|
|
450
412
|
ro == null ? void 0 : ro.unobserve(prevNode);
|
|
451
413
|
delete this.measureElementCache[item.key];
|
|
452
414
|
}
|
|
453
|
-
|
|
454
415
|
return;
|
|
455
416
|
}
|
|
456
|
-
|
|
457
417
|
if (!prevNode || prevNode !== node) {
|
|
458
418
|
if (prevNode) {
|
|
459
419
|
ro == null ? void 0 : ro.unobserve(prevNode);
|
|
460
420
|
}
|
|
461
|
-
|
|
462
421
|
this.measureElementCache[item.key] = node;
|
|
463
422
|
ro == null ? void 0 : ro.observe(node);
|
|
464
423
|
}
|
|
465
|
-
|
|
466
424
|
const measuredItemSize = this.options.measureElement(node, this);
|
|
467
|
-
const itemSize =
|
|
425
|
+
const itemSize = this.itemMeasurementsCache[item.key] ?? item.size;
|
|
468
426
|
const delta = measuredItemSize - itemSize;
|
|
469
|
-
|
|
470
427
|
if (delta !== 0) {
|
|
471
|
-
if (item.start < this.scrollOffset && this.isScrolling
|
|
428
|
+
if (item.start < this.scrollOffset && this.isScrolling) {
|
|
472
429
|
if (this.options.debug) {
|
|
473
430
|
console.info('correction', delta);
|
|
474
431
|
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
canSmooth: false,
|
|
480
|
-
sync: false,
|
|
481
|
-
requested: false
|
|
432
|
+
this._scrollToOffset(this.scrollOffset, {
|
|
433
|
+
adjustments: this.scrollAdjustments += delta,
|
|
434
|
+
behavior: undefined,
|
|
435
|
+
sync: false
|
|
482
436
|
});
|
|
483
437
|
}
|
|
484
|
-
|
|
485
438
|
this.pendingMeasuredCacheIndexes.push(index);
|
|
486
|
-
this.itemMeasurementsCache = {
|
|
439
|
+
this.itemMeasurementsCache = {
|
|
440
|
+
...this.itemMeasurementsCache,
|
|
487
441
|
[item.key]: measuredItemSize
|
|
488
442
|
};
|
|
489
443
|
this.notify();
|
|
490
444
|
}
|
|
491
445
|
};
|
|
492
|
-
|
|
493
446
|
this.measureElement = node => {
|
|
494
447
|
if (!node) {
|
|
495
448
|
return;
|
|
496
449
|
}
|
|
497
|
-
|
|
498
450
|
this._measureElement(node, true);
|
|
499
451
|
};
|
|
500
|
-
|
|
501
452
|
this.getVirtualItems = memo(() => [this.getIndexes(), this.getMeasurements()], (indexes, measurements) => {
|
|
502
453
|
const virtualItems = [];
|
|
503
|
-
|
|
504
454
|
for (let k = 0, len = indexes.length; k < len; k++) {
|
|
505
455
|
const i = indexes[k];
|
|
506
456
|
const measurement = measurements[i];
|
|
507
457
|
virtualItems.push(measurement);
|
|
508
458
|
}
|
|
509
|
-
|
|
510
459
|
return virtualItems;
|
|
511
460
|
}, {
|
|
512
461
|
key: 'getIndexes',
|
|
513
462
|
debug: () => this.options.debug
|
|
514
463
|
});
|
|
515
|
-
|
|
516
464
|
this.scrollToOffset = function (toOffset, _temp) {
|
|
517
465
|
let {
|
|
518
466
|
align = 'start',
|
|
519
|
-
|
|
467
|
+
behavior
|
|
520
468
|
} = _temp === void 0 ? {} : _temp;
|
|
521
469
|
const offset = _this.scrollOffset;
|
|
522
|
-
|
|
523
470
|
const size = _this.getSize();
|
|
524
|
-
|
|
525
471
|
if (align === 'auto') {
|
|
526
472
|
if (toOffset <= offset) {
|
|
527
473
|
align = 'start';
|
|
@@ -531,13 +477,11 @@
|
|
|
531
477
|
align = 'start';
|
|
532
478
|
}
|
|
533
479
|
}
|
|
534
|
-
|
|
535
480
|
const options = {
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
481
|
+
adjustments: undefined,
|
|
482
|
+
behavior,
|
|
483
|
+
sync: false
|
|
539
484
|
};
|
|
540
|
-
|
|
541
485
|
if (align === 'start') {
|
|
542
486
|
_this._scrollToOffset(toOffset, options);
|
|
543
487
|
} else if (align === 'end') {
|
|
@@ -546,29 +490,22 @@
|
|
|
546
490
|
_this._scrollToOffset(toOffset - size / 2, options);
|
|
547
491
|
}
|
|
548
492
|
};
|
|
549
|
-
|
|
550
493
|
this.scrollToIndex = function (index, _temp2) {
|
|
551
494
|
let {
|
|
552
495
|
align = 'auto',
|
|
553
|
-
smoothScroll = _this.options.enableSmoothScroll,
|
|
554
496
|
...rest
|
|
555
497
|
} = _temp2 === void 0 ? {} : _temp2;
|
|
556
|
-
|
|
498
|
+
_this.pendingScrollToIndexCallback = null;
|
|
557
499
|
const measurements = _this.getMeasurements();
|
|
558
|
-
|
|
559
500
|
const offset = _this.scrollOffset;
|
|
560
|
-
|
|
561
501
|
const size = _this.getSize();
|
|
562
|
-
|
|
563
502
|
const {
|
|
564
503
|
count
|
|
565
504
|
} = _this.options;
|
|
566
505
|
const measurement = measurements[Math.max(0, Math.min(index, count - 1))];
|
|
567
|
-
|
|
568
506
|
if (!measurement) {
|
|
569
507
|
return;
|
|
570
508
|
}
|
|
571
|
-
|
|
572
509
|
if (align === 'auto') {
|
|
573
510
|
if (measurement.end >= offset + size - _this.options.scrollPaddingEnd) {
|
|
574
511
|
align = 'end';
|
|
@@ -578,78 +515,57 @@
|
|
|
578
515
|
return;
|
|
579
516
|
}
|
|
580
517
|
}
|
|
581
|
-
|
|
582
518
|
const toOffset = align === 'end' ? measurement.end + _this.options.scrollPaddingEnd : measurement.start - _this.options.scrollPaddingStart;
|
|
583
|
-
|
|
584
519
|
_this.scrollToOffset(toOffset, {
|
|
585
520
|
align,
|
|
586
|
-
smoothScroll,
|
|
587
521
|
...rest
|
|
588
522
|
});
|
|
523
|
+
const isDynamic = Object.keys(_this.measureElementCache).length > 0;
|
|
524
|
+
if (isDynamic) {
|
|
525
|
+
const didSeen = () => typeof _this.itemMeasurementsCache[_this.options.getItemKey(index)] === 'number';
|
|
526
|
+
if (!didSeen()) {
|
|
527
|
+
_this.pendingScrollToIndexCallback = () => {
|
|
528
|
+
if (didSeen()) {
|
|
529
|
+
_this.pendingScrollToIndexCallback = null;
|
|
530
|
+
_this.scrollToIndex(index, {
|
|
531
|
+
align,
|
|
532
|
+
...rest
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
}
|
|
589
538
|
};
|
|
590
|
-
|
|
591
539
|
this.getTotalSize = () => {
|
|
592
540
|
var _this$getMeasurements;
|
|
593
|
-
|
|
594
541
|
return (((_this$getMeasurements = this.getMeasurements()[this.options.count - 1]) == null ? void 0 : _this$getMeasurements.end) || this.options.paddingStart) + this.options.paddingEnd;
|
|
595
542
|
};
|
|
596
|
-
|
|
597
543
|
this._scrollToOffset = (offset, _ref4) => {
|
|
598
544
|
let {
|
|
599
|
-
|
|
600
|
-
|
|
545
|
+
adjustments,
|
|
546
|
+
behavior,
|
|
601
547
|
sync
|
|
602
548
|
} = _ref4;
|
|
603
|
-
clearTimeout(this.scrollCheckFrame);
|
|
604
|
-
|
|
605
|
-
if (requested) {
|
|
606
|
-
this.destinationOffset = offset;
|
|
607
|
-
}
|
|
608
|
-
|
|
609
549
|
this.options.scrollToFn(offset, {
|
|
610
|
-
|
|
611
|
-
sync
|
|
550
|
+
behavior,
|
|
551
|
+
sync,
|
|
552
|
+
adjustments
|
|
612
553
|
}, this);
|
|
613
|
-
let scrollCheckFrame;
|
|
614
|
-
|
|
615
|
-
const check = () => {
|
|
616
|
-
let lastOffset = this.scrollOffset;
|
|
617
|
-
this.scrollCheckFrame = scrollCheckFrame = setTimeout(() => {
|
|
618
|
-
if (this.scrollCheckFrame !== scrollCheckFrame) {
|
|
619
|
-
return;
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
if (this.scrollOffset === lastOffset) {
|
|
623
|
-
this.destinationOffset = undefined;
|
|
624
|
-
return;
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
lastOffset = this.scrollOffset;
|
|
628
|
-
check();
|
|
629
|
-
}, 100);
|
|
630
|
-
};
|
|
631
|
-
|
|
632
|
-
check();
|
|
633
554
|
};
|
|
634
|
-
|
|
635
555
|
this.measure = () => {
|
|
636
556
|
this.itemMeasurementsCache = {};
|
|
637
557
|
this.notify();
|
|
638
558
|
};
|
|
639
|
-
|
|
640
559
|
this.setOptions(_opts);
|
|
641
560
|
this.scrollRect = this.options.initialRect;
|
|
642
561
|
this.scrollOffset = this.options.initialOffset;
|
|
643
562
|
this.calculateRange();
|
|
644
563
|
}
|
|
645
|
-
|
|
646
564
|
}
|
|
647
|
-
|
|
648
565
|
const findNearestBinarySearch = (low, high, getCurrentValue, value) => {
|
|
649
566
|
while (low <= high) {
|
|
650
567
|
const middle = (low + high) / 2 | 0;
|
|
651
568
|
const currentValue = getCurrentValue(middle);
|
|
652
|
-
|
|
653
569
|
if (currentValue < value) {
|
|
654
570
|
low = middle + 1;
|
|
655
571
|
} else if (currentValue > value) {
|
|
@@ -658,14 +574,12 @@
|
|
|
658
574
|
return middle;
|
|
659
575
|
}
|
|
660
576
|
}
|
|
661
|
-
|
|
662
577
|
if (low > 0) {
|
|
663
578
|
return low - 1;
|
|
664
579
|
} else {
|
|
665
580
|
return 0;
|
|
666
581
|
}
|
|
667
582
|
};
|
|
668
|
-
|
|
669
583
|
function calculateRange(_ref5) {
|
|
670
584
|
let {
|
|
671
585
|
measurements,
|
|
@@ -673,27 +587,25 @@
|
|
|
673
587
|
scrollOffset
|
|
674
588
|
} = _ref5;
|
|
675
589
|
const count = measurements.length - 1;
|
|
676
|
-
|
|
677
590
|
const getOffset = index => measurements[index].start;
|
|
678
|
-
|
|
679
591
|
const startIndex = findNearestBinarySearch(0, count, getOffset, scrollOffset);
|
|
680
592
|
let endIndex = startIndex;
|
|
681
|
-
|
|
682
593
|
while (endIndex < count && measurements[endIndex].end < scrollOffset + outerSize) {
|
|
683
594
|
endIndex++;
|
|
684
595
|
}
|
|
685
|
-
|
|
686
596
|
return {
|
|
687
597
|
startIndex,
|
|
688
598
|
endIndex
|
|
689
599
|
};
|
|
690
600
|
}
|
|
691
601
|
|
|
692
|
-
|
|
602
|
+
//
|
|
693
603
|
|
|
604
|
+
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
694
605
|
function useVirtualizerBase(options) {
|
|
695
606
|
const rerender = React__namespace.useReducer(() => ({}), {})[1];
|
|
696
|
-
const resolvedOptions = {
|
|
607
|
+
const resolvedOptions = {
|
|
608
|
+
...options,
|
|
697
609
|
onChange: instance => {
|
|
698
610
|
rerender();
|
|
699
611
|
options.onChange == null ? void 0 : options.onChange(instance);
|
|
@@ -709,7 +621,6 @@
|
|
|
709
621
|
});
|
|
710
622
|
return instance;
|
|
711
623
|
}
|
|
712
|
-
|
|
713
624
|
function useVirtualizer(options) {
|
|
714
625
|
return useVirtualizerBase({
|
|
715
626
|
observeElementRect: observeElementRect,
|