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