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