@tanstack/react-virtual 3.0.0-beta.23 → 3.0.0-beta.26
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 +56 -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,8 @@
|
|
|
242
230
|
this.measurementsCache = [];
|
|
243
231
|
this.itemMeasurementsCache = {};
|
|
244
232
|
this.pendingMeasuredCacheIndexes = [];
|
|
245
|
-
this.
|
|
233
|
+
this.scrollAdjustments = 0;
|
|
246
234
|
this.measureElementCache = {};
|
|
247
|
-
|
|
248
235
|
this.getResizeObserver = (() => {
|
|
249
236
|
let _ro = null;
|
|
250
237
|
return () => {
|
|
@@ -261,12 +248,10 @@
|
|
|
261
248
|
}
|
|
262
249
|
};
|
|
263
250
|
})();
|
|
264
|
-
|
|
265
251
|
this.range = {
|
|
266
252
|
startIndex: 0,
|
|
267
253
|
endIndex: 0
|
|
268
254
|
};
|
|
269
|
-
|
|
270
255
|
this.setOptions = opts => {
|
|
271
256
|
Object.entries(opts).forEach(_ref3 => {
|
|
272
257
|
let [key, value] = _ref3;
|
|
@@ -283,7 +268,6 @@
|
|
|
283
268
|
horizontal: false,
|
|
284
269
|
getItemKey: defaultKeyExtractor,
|
|
285
270
|
rangeExtractor: defaultRangeExtractor,
|
|
286
|
-
enableSmoothScroll: true,
|
|
287
271
|
onChange: () => {},
|
|
288
272
|
measureElement,
|
|
289
273
|
initialRect: {
|
|
@@ -296,42 +280,33 @@
|
|
|
296
280
|
...opts
|
|
297
281
|
};
|
|
298
282
|
};
|
|
299
|
-
|
|
300
283
|
this.notify = () => {
|
|
301
284
|
var _this$options$onChang, _this$options;
|
|
302
|
-
|
|
303
285
|
(_this$options$onChang = (_this$options = this.options).onChange) == null ? void 0 : _this$options$onChang.call(_this$options, this);
|
|
304
286
|
};
|
|
305
|
-
|
|
306
287
|
this.cleanup = () => {
|
|
307
288
|
this.unsubs.filter(Boolean).forEach(d => d());
|
|
308
289
|
this.unsubs = [];
|
|
309
290
|
this.scrollElement = null;
|
|
310
291
|
};
|
|
311
|
-
|
|
312
292
|
this._didMount = () => {
|
|
313
293
|
return () => {
|
|
314
294
|
var _this$getResizeObserv;
|
|
315
|
-
|
|
316
295
|
(_this$getResizeObserv = this.getResizeObserver()) == null ? void 0 : _this$getResizeObserv.disconnect();
|
|
317
296
|
this.measureElementCache = {};
|
|
318
297
|
this.cleanup();
|
|
319
298
|
};
|
|
320
299
|
};
|
|
321
|
-
|
|
322
300
|
this._willUpdate = () => {
|
|
323
301
|
const scrollElement = this.options.getScrollElement();
|
|
324
|
-
|
|
325
302
|
if (this.scrollElement !== scrollElement) {
|
|
326
303
|
this.cleanup();
|
|
327
304
|
this.scrollElement = scrollElement;
|
|
328
|
-
|
|
329
305
|
this._scrollToOffset(this.scrollOffset, {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
306
|
+
adjustments: undefined,
|
|
307
|
+
behavior: undefined,
|
|
308
|
+
sync: true
|
|
333
309
|
});
|
|
334
|
-
|
|
335
310
|
this.unsubs.push(this.options.observeElementRect(this, rect => {
|
|
336
311
|
this.scrollRect = rect;
|
|
337
312
|
this.calculateRange();
|
|
@@ -341,11 +316,10 @@
|
|
|
341
316
|
clearTimeout(this.isScrollingTimeoutId);
|
|
342
317
|
this.isScrollingTimeoutId = null;
|
|
343
318
|
}
|
|
344
|
-
|
|
345
319
|
if (this.scrollOffset !== offset) {
|
|
346
320
|
this.scrollOffset = offset;
|
|
347
321
|
this.isScrolling = true;
|
|
348
|
-
this.
|
|
322
|
+
this.scrollAdjustments = 0;
|
|
349
323
|
this.isScrollingTimeoutId = setTimeout(() => {
|
|
350
324
|
this.isScrollingTimeoutId = null;
|
|
351
325
|
this.isScrolling = false;
|
|
@@ -353,25 +327,21 @@
|
|
|
353
327
|
}, this.options.scrollingDelay);
|
|
354
328
|
} else {
|
|
355
329
|
this.isScrolling = false;
|
|
356
|
-
this.
|
|
330
|
+
this.scrollAdjustments = 0;
|
|
357
331
|
}
|
|
358
|
-
|
|
359
332
|
this.calculateRange();
|
|
360
333
|
}));
|
|
361
334
|
} else if (!this.isScrolling) {
|
|
362
335
|
this.calculateRange();
|
|
363
336
|
}
|
|
364
337
|
};
|
|
365
|
-
|
|
366
338
|
this.getSize = () => {
|
|
367
339
|
return this.scrollRect[this.options.horizontal ? 'width' : 'height'];
|
|
368
340
|
};
|
|
369
|
-
|
|
370
341
|
this.getMeasurements = memo(() => [this.options.count, this.options.paddingStart, this.options.getItemKey, this.itemMeasurementsCache], (count, paddingStart, getItemKey, measurementsCache) => {
|
|
371
342
|
const min = this.pendingMeasuredCacheIndexes.length > 0 ? Math.min(...this.pendingMeasuredCacheIndexes) : 0;
|
|
372
343
|
this.pendingMeasuredCacheIndexes = [];
|
|
373
344
|
const measurements = this.measurementsCache.slice(0, min);
|
|
374
|
-
|
|
375
345
|
for (let i = min; i < count; i++) {
|
|
376
346
|
const key = getItemKey(i);
|
|
377
347
|
const measuredSize = measurementsCache[key];
|
|
@@ -386,7 +356,6 @@
|
|
|
386
356
|
key
|
|
387
357
|
};
|
|
388
358
|
}
|
|
389
|
-
|
|
390
359
|
this.measurementsCache = measurements;
|
|
391
360
|
return measurements;
|
|
392
361
|
}, {
|
|
@@ -399,19 +368,18 @@
|
|
|
399
368
|
outerSize,
|
|
400
369
|
scrollOffset
|
|
401
370
|
});
|
|
402
|
-
|
|
403
371
|
if (range.startIndex !== this.range.startIndex || range.endIndex !== this.range.endIndex) {
|
|
404
372
|
this.range = range;
|
|
405
373
|
this.notify();
|
|
406
374
|
}
|
|
407
|
-
|
|
408
375
|
return this.range;
|
|
409
376
|
}, {
|
|
410
377
|
key: 'calculateRange',
|
|
411
378
|
debug: () => this.options.debug
|
|
412
379
|
});
|
|
413
380
|
this.getIndexes = memo(() => [this.options.rangeExtractor, this.range, this.options.overscan, this.options.count], (rangeExtractor, range, overscan, count) => {
|
|
414
|
-
return rangeExtractor({
|
|
381
|
+
return rangeExtractor({
|
|
382
|
+
...range,
|
|
415
383
|
overscan,
|
|
416
384
|
count: count
|
|
417
385
|
});
|
|
@@ -419,109 +387,84 @@
|
|
|
419
387
|
key: 'getIndexes',
|
|
420
388
|
debug: () => this.options.debug
|
|
421
389
|
});
|
|
422
|
-
|
|
423
390
|
this.indexFromElement = node => {
|
|
424
391
|
const attributeName = this.options.indexAttribute;
|
|
425
392
|
const indexStr = node.getAttribute(attributeName);
|
|
426
|
-
|
|
427
393
|
if (!indexStr) {
|
|
428
|
-
console.warn(
|
|
394
|
+
console.warn(`Missing attribute name '${attributeName}={index}' on measured element.`);
|
|
429
395
|
return -1;
|
|
430
396
|
}
|
|
431
|
-
|
|
432
397
|
return parseInt(indexStr, 10);
|
|
433
398
|
};
|
|
434
|
-
|
|
435
399
|
this._measureElement = (node, _sync) => {
|
|
436
|
-
var _this$itemMeasurement;
|
|
437
|
-
|
|
438
400
|
const index = this.indexFromElement(node);
|
|
439
401
|
const item = this.measurementsCache[index];
|
|
440
|
-
|
|
441
402
|
if (!item) {
|
|
442
403
|
return;
|
|
443
404
|
}
|
|
444
|
-
|
|
445
405
|
const prevNode = this.measureElementCache[item.key];
|
|
446
406
|
const ro = this.getResizeObserver();
|
|
447
|
-
|
|
448
407
|
if (!node.isConnected) {
|
|
449
408
|
if (prevNode) {
|
|
450
409
|
ro == null ? void 0 : ro.unobserve(prevNode);
|
|
451
410
|
delete this.measureElementCache[item.key];
|
|
452
411
|
}
|
|
453
|
-
|
|
454
412
|
return;
|
|
455
413
|
}
|
|
456
|
-
|
|
457
414
|
if (!prevNode || prevNode !== node) {
|
|
458
415
|
if (prevNode) {
|
|
459
416
|
ro == null ? void 0 : ro.unobserve(prevNode);
|
|
460
417
|
}
|
|
461
|
-
|
|
462
418
|
this.measureElementCache[item.key] = node;
|
|
463
419
|
ro == null ? void 0 : ro.observe(node);
|
|
464
420
|
}
|
|
465
|
-
|
|
466
421
|
const measuredItemSize = this.options.measureElement(node, this);
|
|
467
|
-
const itemSize =
|
|
422
|
+
const itemSize = this.itemMeasurementsCache[item.key] ?? item.size;
|
|
468
423
|
const delta = measuredItemSize - itemSize;
|
|
469
|
-
|
|
470
424
|
if (delta !== 0) {
|
|
471
|
-
if (item.start < this.scrollOffset && this.isScrolling
|
|
425
|
+
if (item.start < this.scrollOffset && this.isScrolling) {
|
|
472
426
|
if (this.options.debug) {
|
|
473
427
|
console.info('correction', delta);
|
|
474
428
|
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
canSmooth: false,
|
|
480
|
-
sync: false,
|
|
481
|
-
requested: false
|
|
429
|
+
this._scrollToOffset(this.scrollOffset, {
|
|
430
|
+
adjustments: this.scrollAdjustments += delta,
|
|
431
|
+
behavior: undefined,
|
|
432
|
+
sync: false
|
|
482
433
|
});
|
|
483
434
|
}
|
|
484
|
-
|
|
485
435
|
this.pendingMeasuredCacheIndexes.push(index);
|
|
486
|
-
this.itemMeasurementsCache = {
|
|
436
|
+
this.itemMeasurementsCache = {
|
|
437
|
+
...this.itemMeasurementsCache,
|
|
487
438
|
[item.key]: measuredItemSize
|
|
488
439
|
};
|
|
489
440
|
this.notify();
|
|
490
441
|
}
|
|
491
442
|
};
|
|
492
|
-
|
|
493
443
|
this.measureElement = node => {
|
|
494
444
|
if (!node) {
|
|
495
445
|
return;
|
|
496
446
|
}
|
|
497
|
-
|
|
498
447
|
this._measureElement(node, true);
|
|
499
448
|
};
|
|
500
|
-
|
|
501
449
|
this.getVirtualItems = memo(() => [this.getIndexes(), this.getMeasurements()], (indexes, measurements) => {
|
|
502
450
|
const virtualItems = [];
|
|
503
|
-
|
|
504
451
|
for (let k = 0, len = indexes.length; k < len; k++) {
|
|
505
452
|
const i = indexes[k];
|
|
506
453
|
const measurement = measurements[i];
|
|
507
454
|
virtualItems.push(measurement);
|
|
508
455
|
}
|
|
509
|
-
|
|
510
456
|
return virtualItems;
|
|
511
457
|
}, {
|
|
512
458
|
key: 'getIndexes',
|
|
513
459
|
debug: () => this.options.debug
|
|
514
460
|
});
|
|
515
|
-
|
|
516
461
|
this.scrollToOffset = function (toOffset, _temp) {
|
|
517
462
|
let {
|
|
518
463
|
align = 'start',
|
|
519
|
-
|
|
464
|
+
behavior
|
|
520
465
|
} = _temp === void 0 ? {} : _temp;
|
|
521
466
|
const offset = _this.scrollOffset;
|
|
522
|
-
|
|
523
467
|
const size = _this.getSize();
|
|
524
|
-
|
|
525
468
|
if (align === 'auto') {
|
|
526
469
|
if (toOffset <= offset) {
|
|
527
470
|
align = 'start';
|
|
@@ -531,13 +474,11 @@
|
|
|
531
474
|
align = 'start';
|
|
532
475
|
}
|
|
533
476
|
}
|
|
534
|
-
|
|
535
477
|
const options = {
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
478
|
+
adjustments: undefined,
|
|
479
|
+
behavior,
|
|
480
|
+
sync: false
|
|
539
481
|
};
|
|
540
|
-
|
|
541
482
|
if (align === 'start') {
|
|
542
483
|
_this._scrollToOffset(toOffset, options);
|
|
543
484
|
} else if (align === 'end') {
|
|
@@ -546,29 +487,21 @@
|
|
|
546
487
|
_this._scrollToOffset(toOffset - size / 2, options);
|
|
547
488
|
}
|
|
548
489
|
};
|
|
549
|
-
|
|
550
490
|
this.scrollToIndex = function (index, _temp2) {
|
|
551
491
|
let {
|
|
552
492
|
align = 'auto',
|
|
553
|
-
smoothScroll = _this.options.enableSmoothScroll,
|
|
554
493
|
...rest
|
|
555
494
|
} = _temp2 === void 0 ? {} : _temp2;
|
|
556
|
-
|
|
557
495
|
const measurements = _this.getMeasurements();
|
|
558
|
-
|
|
559
496
|
const offset = _this.scrollOffset;
|
|
560
|
-
|
|
561
497
|
const size = _this.getSize();
|
|
562
|
-
|
|
563
498
|
const {
|
|
564
499
|
count
|
|
565
500
|
} = _this.options;
|
|
566
501
|
const measurement = measurements[Math.max(0, Math.min(index, count - 1))];
|
|
567
|
-
|
|
568
502
|
if (!measurement) {
|
|
569
503
|
return;
|
|
570
504
|
}
|
|
571
|
-
|
|
572
505
|
if (align === 'auto') {
|
|
573
506
|
if (measurement.end >= offset + size - _this.options.scrollPaddingEnd) {
|
|
574
507
|
align = 'end';
|
|
@@ -578,78 +511,42 @@
|
|
|
578
511
|
return;
|
|
579
512
|
}
|
|
580
513
|
}
|
|
581
|
-
|
|
582
514
|
const toOffset = align === 'end' ? measurement.end + _this.options.scrollPaddingEnd : measurement.start - _this.options.scrollPaddingStart;
|
|
583
|
-
|
|
584
515
|
_this.scrollToOffset(toOffset, {
|
|
585
516
|
align,
|
|
586
|
-
smoothScroll,
|
|
587
517
|
...rest
|
|
588
518
|
});
|
|
589
519
|
};
|
|
590
|
-
|
|
591
520
|
this.getTotalSize = () => {
|
|
592
521
|
var _this$getMeasurements;
|
|
593
|
-
|
|
594
522
|
return (((_this$getMeasurements = this.getMeasurements()[this.options.count - 1]) == null ? void 0 : _this$getMeasurements.end) || this.options.paddingStart) + this.options.paddingEnd;
|
|
595
523
|
};
|
|
596
|
-
|
|
597
524
|
this._scrollToOffset = (offset, _ref4) => {
|
|
598
525
|
let {
|
|
599
|
-
|
|
600
|
-
|
|
526
|
+
adjustments,
|
|
527
|
+
behavior,
|
|
601
528
|
sync
|
|
602
529
|
} = _ref4;
|
|
603
|
-
clearTimeout(this.scrollCheckFrame);
|
|
604
|
-
|
|
605
|
-
if (requested) {
|
|
606
|
-
this.destinationOffset = offset;
|
|
607
|
-
}
|
|
608
|
-
|
|
609
530
|
this.options.scrollToFn(offset, {
|
|
610
|
-
|
|
611
|
-
sync
|
|
531
|
+
behavior,
|
|
532
|
+
sync,
|
|
533
|
+
adjustments
|
|
612
534
|
}, 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
535
|
};
|
|
634
|
-
|
|
635
536
|
this.measure = () => {
|
|
636
537
|
this.itemMeasurementsCache = {};
|
|
637
538
|
this.notify();
|
|
638
539
|
};
|
|
639
|
-
|
|
640
540
|
this.setOptions(_opts);
|
|
641
541
|
this.scrollRect = this.options.initialRect;
|
|
642
542
|
this.scrollOffset = this.options.initialOffset;
|
|
643
543
|
this.calculateRange();
|
|
644
544
|
}
|
|
645
|
-
|
|
646
545
|
}
|
|
647
|
-
|
|
648
546
|
const findNearestBinarySearch = (low, high, getCurrentValue, value) => {
|
|
649
547
|
while (low <= high) {
|
|
650
548
|
const middle = (low + high) / 2 | 0;
|
|
651
549
|
const currentValue = getCurrentValue(middle);
|
|
652
|
-
|
|
653
550
|
if (currentValue < value) {
|
|
654
551
|
low = middle + 1;
|
|
655
552
|
} else if (currentValue > value) {
|
|
@@ -658,14 +555,12 @@
|
|
|
658
555
|
return middle;
|
|
659
556
|
}
|
|
660
557
|
}
|
|
661
|
-
|
|
662
558
|
if (low > 0) {
|
|
663
559
|
return low - 1;
|
|
664
560
|
} else {
|
|
665
561
|
return 0;
|
|
666
562
|
}
|
|
667
563
|
};
|
|
668
|
-
|
|
669
564
|
function calculateRange(_ref5) {
|
|
670
565
|
let {
|
|
671
566
|
measurements,
|
|
@@ -673,27 +568,25 @@
|
|
|
673
568
|
scrollOffset
|
|
674
569
|
} = _ref5;
|
|
675
570
|
const count = measurements.length - 1;
|
|
676
|
-
|
|
677
571
|
const getOffset = index => measurements[index].start;
|
|
678
|
-
|
|
679
572
|
const startIndex = findNearestBinarySearch(0, count, getOffset, scrollOffset);
|
|
680
573
|
let endIndex = startIndex;
|
|
681
|
-
|
|
682
574
|
while (endIndex < count && measurements[endIndex].end < scrollOffset + outerSize) {
|
|
683
575
|
endIndex++;
|
|
684
576
|
}
|
|
685
|
-
|
|
686
577
|
return {
|
|
687
578
|
startIndex,
|
|
688
579
|
endIndex
|
|
689
580
|
};
|
|
690
581
|
}
|
|
691
582
|
|
|
692
|
-
|
|
583
|
+
//
|
|
693
584
|
|
|
585
|
+
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
694
586
|
function useVirtualizerBase(options) {
|
|
695
587
|
const rerender = React__namespace.useReducer(() => ({}), {})[1];
|
|
696
|
-
const resolvedOptions = {
|
|
588
|
+
const resolvedOptions = {
|
|
589
|
+
...options,
|
|
697
590
|
onChange: instance => {
|
|
698
591
|
rerender();
|
|
699
592
|
options.onChange == null ? void 0 : options.onChange(instance);
|
|
@@ -709,7 +602,6 @@
|
|
|
709
602
|
});
|
|
710
603
|
return instance;
|
|
711
604
|
}
|
|
712
|
-
|
|
713
605
|
function useVirtualizer(options) {
|
|
714
606
|
return useVirtualizerBase({
|
|
715
607
|
observeElementRect: observeElementRect,
|