@tanstack/solid-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 +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 +53 -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
|
+
|
|
74
|
+
//
|
|
75
|
+
|
|
68
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,109 +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 =
|
|
402
|
+
const itemSize = this.itemMeasurementsCache[item.key] ?? item.size;
|
|
448
403
|
const delta = measuredItemSize - itemSize;
|
|
449
|
-
|
|
450
404
|
if (delta !== 0) {
|
|
451
|
-
if (item.start < this.scrollOffset && this.isScrolling
|
|
405
|
+
if (item.start < this.scrollOffset && this.isScrolling) {
|
|
452
406
|
if (this.options.debug) {
|
|
453
407
|
console.info('correction', delta);
|
|
454
408
|
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
canSmooth: false,
|
|
460
|
-
sync: false,
|
|
461
|
-
requested: false
|
|
409
|
+
this._scrollToOffset(this.scrollOffset, {
|
|
410
|
+
adjustments: this.scrollAdjustments += delta,
|
|
411
|
+
behavior: undefined,
|
|
412
|
+
sync: false
|
|
462
413
|
});
|
|
463
414
|
}
|
|
464
|
-
|
|
465
415
|
this.pendingMeasuredCacheIndexes.push(index);
|
|
466
|
-
this.itemMeasurementsCache = {
|
|
416
|
+
this.itemMeasurementsCache = {
|
|
417
|
+
...this.itemMeasurementsCache,
|
|
467
418
|
[item.key]: measuredItemSize
|
|
468
419
|
};
|
|
469
420
|
this.notify();
|
|
470
421
|
}
|
|
471
422
|
};
|
|
472
|
-
|
|
473
423
|
this.measureElement = node => {
|
|
474
424
|
if (!node) {
|
|
475
425
|
return;
|
|
476
426
|
}
|
|
477
|
-
|
|
478
427
|
this._measureElement(node, true);
|
|
479
428
|
};
|
|
480
|
-
|
|
481
429
|
this.getVirtualItems = memo(() => [this.getIndexes(), this.getMeasurements()], (indexes, measurements) => {
|
|
482
430
|
const virtualItems = [];
|
|
483
|
-
|
|
484
431
|
for (let k = 0, len = indexes.length; k < len; k++) {
|
|
485
432
|
const i = indexes[k];
|
|
486
433
|
const measurement = measurements[i];
|
|
487
434
|
virtualItems.push(measurement);
|
|
488
435
|
}
|
|
489
|
-
|
|
490
436
|
return virtualItems;
|
|
491
437
|
}, {
|
|
492
438
|
key: 'getIndexes',
|
|
493
439
|
debug: () => this.options.debug
|
|
494
440
|
});
|
|
495
|
-
|
|
496
441
|
this.scrollToOffset = function (toOffset, _temp) {
|
|
497
442
|
let {
|
|
498
443
|
align = 'start',
|
|
499
|
-
|
|
444
|
+
behavior
|
|
500
445
|
} = _temp === void 0 ? {} : _temp;
|
|
501
446
|
const offset = _this.scrollOffset;
|
|
502
|
-
|
|
503
447
|
const size = _this.getSize();
|
|
504
|
-
|
|
505
448
|
if (align === 'auto') {
|
|
506
449
|
if (toOffset <= offset) {
|
|
507
450
|
align = 'start';
|
|
@@ -511,13 +454,11 @@
|
|
|
511
454
|
align = 'start';
|
|
512
455
|
}
|
|
513
456
|
}
|
|
514
|
-
|
|
515
457
|
const options = {
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
458
|
+
adjustments: undefined,
|
|
459
|
+
behavior,
|
|
460
|
+
sync: false
|
|
519
461
|
};
|
|
520
|
-
|
|
521
462
|
if (align === 'start') {
|
|
522
463
|
_this._scrollToOffset(toOffset, options);
|
|
523
464
|
} else if (align === 'end') {
|
|
@@ -526,29 +467,21 @@
|
|
|
526
467
|
_this._scrollToOffset(toOffset - size / 2, options);
|
|
527
468
|
}
|
|
528
469
|
};
|
|
529
|
-
|
|
530
470
|
this.scrollToIndex = function (index, _temp2) {
|
|
531
471
|
let {
|
|
532
472
|
align = 'auto',
|
|
533
|
-
smoothScroll = _this.options.enableSmoothScroll,
|
|
534
473
|
...rest
|
|
535
474
|
} = _temp2 === void 0 ? {} : _temp2;
|
|
536
|
-
|
|
537
475
|
const measurements = _this.getMeasurements();
|
|
538
|
-
|
|
539
476
|
const offset = _this.scrollOffset;
|
|
540
|
-
|
|
541
477
|
const size = _this.getSize();
|
|
542
|
-
|
|
543
478
|
const {
|
|
544
479
|
count
|
|
545
480
|
} = _this.options;
|
|
546
481
|
const measurement = measurements[Math.max(0, Math.min(index, count - 1))];
|
|
547
|
-
|
|
548
482
|
if (!measurement) {
|
|
549
483
|
return;
|
|
550
484
|
}
|
|
551
|
-
|
|
552
485
|
if (align === 'auto') {
|
|
553
486
|
if (measurement.end >= offset + size - _this.options.scrollPaddingEnd) {
|
|
554
487
|
align = 'end';
|
|
@@ -558,78 +491,42 @@
|
|
|
558
491
|
return;
|
|
559
492
|
}
|
|
560
493
|
}
|
|
561
|
-
|
|
562
494
|
const toOffset = align === 'end' ? measurement.end + _this.options.scrollPaddingEnd : measurement.start - _this.options.scrollPaddingStart;
|
|
563
|
-
|
|
564
495
|
_this.scrollToOffset(toOffset, {
|
|
565
496
|
align,
|
|
566
|
-
smoothScroll,
|
|
567
497
|
...rest
|
|
568
498
|
});
|
|
569
499
|
};
|
|
570
|
-
|
|
571
500
|
this.getTotalSize = () => {
|
|
572
501
|
var _this$getMeasurements;
|
|
573
|
-
|
|
574
502
|
return (((_this$getMeasurements = this.getMeasurements()[this.options.count - 1]) == null ? void 0 : _this$getMeasurements.end) || this.options.paddingStart) + this.options.paddingEnd;
|
|
575
503
|
};
|
|
576
|
-
|
|
577
504
|
this._scrollToOffset = (offset, _ref4) => {
|
|
578
505
|
let {
|
|
579
|
-
|
|
580
|
-
|
|
506
|
+
adjustments,
|
|
507
|
+
behavior,
|
|
581
508
|
sync
|
|
582
509
|
} = _ref4;
|
|
583
|
-
clearTimeout(this.scrollCheckFrame);
|
|
584
|
-
|
|
585
|
-
if (requested) {
|
|
586
|
-
this.destinationOffset = offset;
|
|
587
|
-
}
|
|
588
|
-
|
|
589
510
|
this.options.scrollToFn(offset, {
|
|
590
|
-
|
|
591
|
-
sync
|
|
511
|
+
behavior,
|
|
512
|
+
sync,
|
|
513
|
+
adjustments
|
|
592
514
|
}, 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
515
|
};
|
|
614
|
-
|
|
615
516
|
this.measure = () => {
|
|
616
517
|
this.itemMeasurementsCache = {};
|
|
617
518
|
this.notify();
|
|
618
519
|
};
|
|
619
|
-
|
|
620
520
|
this.setOptions(_opts);
|
|
621
521
|
this.scrollRect = this.options.initialRect;
|
|
622
522
|
this.scrollOffset = this.options.initialOffset;
|
|
623
523
|
this.calculateRange();
|
|
624
524
|
}
|
|
625
|
-
|
|
626
525
|
}
|
|
627
|
-
|
|
628
526
|
const findNearestBinarySearch = (low, high, getCurrentValue, value) => {
|
|
629
527
|
while (low <= high) {
|
|
630
528
|
const middle = (low + high) / 2 | 0;
|
|
631
529
|
const currentValue = getCurrentValue(middle);
|
|
632
|
-
|
|
633
530
|
if (currentValue < value) {
|
|
634
531
|
low = middle + 1;
|
|
635
532
|
} else if (currentValue > value) {
|
|
@@ -638,14 +535,12 @@
|
|
|
638
535
|
return middle;
|
|
639
536
|
}
|
|
640
537
|
}
|
|
641
|
-
|
|
642
538
|
if (low > 0) {
|
|
643
539
|
return low - 1;
|
|
644
540
|
} else {
|
|
645
541
|
return 0;
|
|
646
542
|
}
|
|
647
543
|
};
|
|
648
|
-
|
|
649
544
|
function calculateRange(_ref5) {
|
|
650
545
|
let {
|
|
651
546
|
measurements,
|
|
@@ -653,16 +548,12 @@
|
|
|
653
548
|
scrollOffset
|
|
654
549
|
} = _ref5;
|
|
655
550
|
const count = measurements.length - 1;
|
|
656
|
-
|
|
657
551
|
const getOffset = index => measurements[index].start;
|
|
658
|
-
|
|
659
552
|
const startIndex = findNearestBinarySearch(0, count, getOffset, scrollOffset);
|
|
660
553
|
let endIndex = startIndex;
|
|
661
|
-
|
|
662
554
|
while (endIndex < count && measurements[endIndex].end < scrollOffset + outerSize) {
|
|
663
555
|
endIndex++;
|
|
664
556
|
}
|
|
665
|
-
|
|
666
557
|
return {
|
|
667
558
|
startIndex,
|
|
668
559
|
endIndex
|
|
@@ -679,30 +570,24 @@
|
|
|
679
570
|
switch (prop) {
|
|
680
571
|
case 'getVirtualItems':
|
|
681
572
|
return () => virtualItems;
|
|
682
|
-
|
|
683
573
|
case 'getTotalSize':
|
|
684
574
|
return () => totalSize();
|
|
685
|
-
|
|
686
575
|
default:
|
|
687
576
|
return Reflect.get(target, prop);
|
|
688
577
|
}
|
|
689
578
|
}
|
|
690
|
-
|
|
691
579
|
};
|
|
692
580
|
const virtualizer = new Proxy(instance, handler);
|
|
693
581
|
virtualizer.setOptions(resolvedOptions);
|
|
694
582
|
solidJs.onMount(() => {
|
|
695
583
|
const cleanup = virtualizer._didMount();
|
|
696
|
-
|
|
697
584
|
virtualizer._willUpdate();
|
|
698
|
-
|
|
699
585
|
solidJs.onCleanup(cleanup);
|
|
700
586
|
});
|
|
701
587
|
solidJs.createComputed(() => {
|
|
702
588
|
virtualizer.setOptions(solidJs.mergeProps(resolvedOptions, options, {
|
|
703
589
|
onChange: instance => {
|
|
704
590
|
instance._willUpdate();
|
|
705
|
-
|
|
706
591
|
setVirtualItems(store.reconcile(instance.getVirtualItems(), {
|
|
707
592
|
key: 'index'
|
|
708
593
|
}));
|
|
@@ -714,7 +599,6 @@
|
|
|
714
599
|
});
|
|
715
600
|
return virtualizer;
|
|
716
601
|
}
|
|
717
|
-
|
|
718
602
|
function createVirtualizer(options) {
|
|
719
603
|
return createVirtualizerBase(solidJs.mergeProps({
|
|
720
604
|
observeElementRect: observeElementRect,
|