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