@tanstack/react-virtual 3.0.0-beta.6 → 3.0.0-beta.60
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.d.ts +4 -0
- package/build/lib/index.esm.js +61 -0
- package/build/lib/index.esm.js.map +1 -0
- package/build/lib/index.js +91 -0
- package/build/lib/index.js.map +1 -0
- package/build/lib/index.mjs +61 -0
- package/build/lib/index.mjs.map +1 -0
- package/build/umd/index.development.js +663 -470
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +22 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +23 -10
- package/src/index.tsx +11 -5
- package/build/cjs/react-virtual/src/index.js +0 -90
- package/build/cjs/react-virtual/src/index.js.map +0 -1
- package/build/cjs/virtual-core/build/esm/index.js +0 -583
- package/build/cjs/virtual-core/build/esm/index.js.map +0 -1
- package/build/esm/index.js +0 -610
- package/build/esm/index.js.map +0 -1
- package/build/stats-html.html +0 -2689
- package/build/stats.json +0 -90
- package/build/types/react-virtual/src/index.d.ts +0 -4
- package/build/types/virtual-core/src/utils.d.ts +0 -7
|
@@ -34,6 +34,21 @@
|
|
|
34
34
|
|
|
35
35
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
36
36
|
|
|
37
|
+
function _extends$1() {
|
|
38
|
+
_extends$1 = Object.assign ? Object.assign.bind() : function (target) {
|
|
39
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
40
|
+
var source = arguments[i];
|
|
41
|
+
for (var key in source) {
|
|
42
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
43
|
+
target[key] = source[key];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return target;
|
|
48
|
+
};
|
|
49
|
+
return _extends$1.apply(this, arguments);
|
|
50
|
+
}
|
|
51
|
+
|
|
37
52
|
/**
|
|
38
53
|
* virtual-core
|
|
39
54
|
*
|
|
@@ -44,514 +59,691 @@
|
|
|
44
59
|
*
|
|
45
60
|
* @license MIT
|
|
46
61
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
b = {};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return props.some(function (prop) {
|
|
59
|
-
return a[prop] !== b[prop];
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
var observedNodes = /*#__PURE__*/new Map();
|
|
64
|
-
var rafId;
|
|
65
|
-
|
|
66
|
-
var run = function run() {
|
|
67
|
-
var changedStates = [];
|
|
68
|
-
observedNodes.forEach(function (state, node) {
|
|
69
|
-
var newRect = node.getBoundingClientRect();
|
|
70
|
-
|
|
71
|
-
if (rectChanged(newRect, state.rect)) {
|
|
72
|
-
state.rect = newRect;
|
|
73
|
-
changedStates.push(state);
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
changedStates.forEach(function (state) {
|
|
77
|
-
state.callbacks.forEach(function (cb) {
|
|
78
|
-
return cb(state.rect);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
rafId = window.requestAnimationFrame(run);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
function observeRect(node, cb) {
|
|
85
|
-
return {
|
|
86
|
-
observe: function observe() {
|
|
87
|
-
var wasEmpty = observedNodes.size === 0;
|
|
88
|
-
|
|
89
|
-
if (observedNodes.has(node)) {
|
|
90
|
-
observedNodes.get(node).callbacks.push(cb);
|
|
91
|
-
} else {
|
|
92
|
-
observedNodes.set(node, {
|
|
93
|
-
rect: undefined,
|
|
94
|
-
hasRectChanged: false,
|
|
95
|
-
callbacks: [cb]
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (wasEmpty) run();
|
|
100
|
-
},
|
|
101
|
-
unobserve: function unobserve() {
|
|
102
|
-
var state = observedNodes.get(node);
|
|
103
|
-
|
|
104
|
-
if (state) {
|
|
105
|
-
// Remove the callback
|
|
106
|
-
var index = state.callbacks.indexOf(cb);
|
|
107
|
-
if (index >= 0) state.callbacks.splice(index, 1); // Remove the node reference
|
|
108
|
-
|
|
109
|
-
if (!state.callbacks.length) observedNodes["delete"](node); // Stop the loop
|
|
110
|
-
|
|
111
|
-
if (!observedNodes.size) cancelAnimationFrame(rafId);
|
|
62
|
+
function _extends() {
|
|
63
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
64
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
65
|
+
var source = arguments[i];
|
|
66
|
+
for (var key in source) {
|
|
67
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
68
|
+
target[key] = source[key];
|
|
69
|
+
}
|
|
112
70
|
}
|
|
113
71
|
}
|
|
72
|
+
return target;
|
|
114
73
|
};
|
|
74
|
+
return _extends.apply(this, arguments);
|
|
115
75
|
}
|
|
116
76
|
|
|
77
|
+
/**
|
|
78
|
+
* virtual-core
|
|
79
|
+
*
|
|
80
|
+
* Copyright (c) TanStack
|
|
81
|
+
*
|
|
82
|
+
* This source code is licensed under the MIT license found in the
|
|
83
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
84
|
+
*
|
|
85
|
+
* @license MIT
|
|
86
|
+
*/
|
|
117
87
|
function memo(getDeps, fn, opts) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
88
|
+
var _opts$initialDeps;
|
|
89
|
+
var deps = (_opts$initialDeps = opts.initialDeps) != null ? _opts$initialDeps : [];
|
|
90
|
+
var result;
|
|
91
|
+
return function () {
|
|
92
|
+
var depTime;
|
|
122
93
|
if (opts.key && opts.debug != null && opts.debug()) depTime = Date.now();
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
94
|
+
var newDeps = getDeps();
|
|
95
|
+
var depsChanged = newDeps.length !== deps.length || newDeps.some(function (dep, index) {
|
|
96
|
+
return deps[index] !== dep;
|
|
97
|
+
});
|
|
126
98
|
if (!depsChanged) {
|
|
127
99
|
return result;
|
|
128
100
|
}
|
|
129
|
-
|
|
130
101
|
deps = newDeps;
|
|
131
|
-
|
|
102
|
+
var resultTime;
|
|
132
103
|
if (opts.key && opts.debug != null && opts.debug()) resultTime = Date.now();
|
|
133
|
-
result = fn(
|
|
134
|
-
opts == null ? void 0 : opts.onChange == null ? void 0 : opts.onChange(result);
|
|
135
|
-
|
|
104
|
+
result = fn.apply(void 0, newDeps);
|
|
136
105
|
if (opts.key && opts.debug != null && opts.debug()) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const pad = (str, num) => {
|
|
106
|
+
var depEndTime = Math.round((Date.now() - depTime) * 100) / 100;
|
|
107
|
+
var resultEndTime = Math.round((Date.now() - resultTime) * 100) / 100;
|
|
108
|
+
var resultFpsPercentage = resultEndTime / 16;
|
|
109
|
+
var pad = function pad(str, num) {
|
|
142
110
|
str = String(str);
|
|
143
|
-
|
|
144
111
|
while (str.length < num) {
|
|
145
112
|
str = ' ' + str;
|
|
146
113
|
}
|
|
147
|
-
|
|
148
114
|
return str;
|
|
149
115
|
};
|
|
150
|
-
|
|
151
116
|
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);
|
|
152
117
|
}
|
|
153
|
-
|
|
118
|
+
opts == null ? void 0 : opts.onChange == null ? void 0 : opts.onChange(result);
|
|
154
119
|
return result;
|
|
155
120
|
};
|
|
156
121
|
}
|
|
122
|
+
function notUndefined(value, msg) {
|
|
123
|
+
if (value === undefined) {
|
|
124
|
+
throw new Error("Unexpected undefined" + (msg ? ": " + msg : ''));
|
|
125
|
+
} else {
|
|
126
|
+
return value;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
var approxEqual = function approxEqual(a, b) {
|
|
130
|
+
return Math.abs(a - b) < 1;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* virtual-core
|
|
135
|
+
*
|
|
136
|
+
* Copyright (c) TanStack
|
|
137
|
+
*
|
|
138
|
+
* This source code is licensed under the MIT license found in the
|
|
139
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
140
|
+
*
|
|
141
|
+
* @license MIT
|
|
142
|
+
*/
|
|
157
143
|
|
|
158
144
|
//
|
|
159
|
-
const defaultKeyExtractor = index => index;
|
|
160
|
-
const defaultRangeExtractor = range => {
|
|
161
|
-
const start = Math.max(range.startIndex - range.overscan, 0);
|
|
162
|
-
const end = Math.min(range.endIndex + range.overscan, range.count - 1);
|
|
163
|
-
const arr = [];
|
|
164
145
|
|
|
165
|
-
|
|
166
|
-
arr.push(i);
|
|
167
|
-
}
|
|
146
|
+
//
|
|
168
147
|
|
|
148
|
+
var defaultKeyExtractor = function defaultKeyExtractor(index) {
|
|
149
|
+
return index;
|
|
150
|
+
};
|
|
151
|
+
var defaultRangeExtractor = function defaultRangeExtractor(range) {
|
|
152
|
+
var start = Math.max(range.startIndex - range.overscan, 0);
|
|
153
|
+
var end = Math.min(range.endIndex + range.overscan, range.count - 1);
|
|
154
|
+
var arr = [];
|
|
155
|
+
for (var _i = start; _i <= end; _i++) {
|
|
156
|
+
arr.push(_i);
|
|
157
|
+
}
|
|
169
158
|
return arr;
|
|
170
159
|
};
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
if (!instance.scrollElement) {
|
|
160
|
+
var observeElementRect = function observeElementRect(instance, cb) {
|
|
161
|
+
var element = instance.scrollElement;
|
|
162
|
+
if (!element) {
|
|
177
163
|
return;
|
|
178
164
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
return () => {
|
|
183
|
-
observer.unobserve();
|
|
184
|
-
};
|
|
185
|
-
};
|
|
186
|
-
const observeWindowRect = (instance, cb) => {
|
|
187
|
-
const onResize = () => {
|
|
165
|
+
var handler = function handler(rect) {
|
|
166
|
+
var width = rect.width,
|
|
167
|
+
height = rect.height;
|
|
188
168
|
cb({
|
|
189
|
-
width:
|
|
190
|
-
height:
|
|
169
|
+
width: Math.round(width),
|
|
170
|
+
height: Math.round(height)
|
|
191
171
|
});
|
|
192
172
|
};
|
|
193
|
-
|
|
194
|
-
|
|
173
|
+
handler(element.getBoundingClientRect());
|
|
174
|
+
var observer = new ResizeObserver(function (entries) {
|
|
175
|
+
var entry = entries[0];
|
|
176
|
+
if (entry != null && entry.borderBoxSize) {
|
|
177
|
+
var box = entry.borderBoxSize[0];
|
|
178
|
+
if (box) {
|
|
179
|
+
handler({
|
|
180
|
+
width: box.inlineSize,
|
|
181
|
+
height: box.blockSize
|
|
182
|
+
});
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
handler(element.getBoundingClientRect());
|
|
187
|
+
});
|
|
188
|
+
observer.observe(element, {
|
|
189
|
+
box: 'border-box'
|
|
190
|
+
});
|
|
191
|
+
return function () {
|
|
192
|
+
observer.unobserve(element);
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
var observeWindowRect = function observeWindowRect(instance, cb) {
|
|
196
|
+
var element = instance.scrollElement;
|
|
197
|
+
if (!element) {
|
|
195
198
|
return;
|
|
196
199
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
200
|
+
var handler = function handler() {
|
|
201
|
+
cb({
|
|
202
|
+
width: element.innerWidth,
|
|
203
|
+
height: element.innerHeight
|
|
204
|
+
});
|
|
205
|
+
};
|
|
206
|
+
handler();
|
|
207
|
+
element.addEventListener('resize', handler, {
|
|
201
208
|
passive: true
|
|
202
209
|
});
|
|
203
|
-
return ()
|
|
204
|
-
|
|
210
|
+
return function () {
|
|
211
|
+
element.removeEventListener('resize', handler);
|
|
205
212
|
};
|
|
206
213
|
};
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
if (!instance.scrollElement) {
|
|
214
|
+
var observeElementOffset = function observeElementOffset(instance, cb) {
|
|
215
|
+
var element = instance.scrollElement;
|
|
216
|
+
if (!element) {
|
|
211
217
|
return;
|
|
212
218
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
219
|
+
var handler = function handler() {
|
|
220
|
+
cb(element[instance.options.horizontal ? 'scrollLeft' : 'scrollTop']);
|
|
221
|
+
};
|
|
222
|
+
handler();
|
|
223
|
+
element.addEventListener('scroll', handler, {
|
|
217
224
|
passive: true
|
|
218
225
|
});
|
|
219
|
-
return ()
|
|
220
|
-
|
|
226
|
+
return function () {
|
|
227
|
+
element.removeEventListener('scroll', handler);
|
|
221
228
|
};
|
|
222
229
|
};
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
if (!instance.scrollElement) {
|
|
230
|
+
var observeWindowOffset = function observeWindowOffset(instance, cb) {
|
|
231
|
+
var element = instance.scrollElement;
|
|
232
|
+
if (!element) {
|
|
227
233
|
return;
|
|
228
234
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
235
|
+
var handler = function handler() {
|
|
236
|
+
cb(element[instance.options.horizontal ? 'scrollX' : 'scrollY']);
|
|
237
|
+
};
|
|
238
|
+
handler();
|
|
239
|
+
element.addEventListener('scroll', handler, {
|
|
233
240
|
passive: true
|
|
234
241
|
});
|
|
235
|
-
return ()
|
|
236
|
-
|
|
242
|
+
return function () {
|
|
243
|
+
element.removeEventListener('scroll', handler);
|
|
237
244
|
};
|
|
238
245
|
};
|
|
239
|
-
|
|
240
|
-
|
|
246
|
+
var measureElement = function measureElement(element, entry, instance) {
|
|
247
|
+
if (entry != null && entry.borderBoxSize) {
|
|
248
|
+
var box = entry.borderBoxSize[0];
|
|
249
|
+
if (box) {
|
|
250
|
+
var size = Math.round(box[instance.options.horizontal ? 'inlineSize' : 'blockSize']);
|
|
251
|
+
return size;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return Math.round(element.getBoundingClientRect()[instance.options.horizontal ? 'width' : 'height']);
|
|
241
255
|
};
|
|
242
|
-
|
|
243
|
-
var _instance$scrollEleme;
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
behavior
|
|
247
|
-
|
|
256
|
+
var windowScroll = function windowScroll(offset, _ref, instance) {
|
|
257
|
+
var _instance$scrollEleme, _instance$scrollEleme2;
|
|
258
|
+
var _ref$adjustments = _ref.adjustments,
|
|
259
|
+
adjustments = _ref$adjustments === void 0 ? window.scrollY : _ref$adjustments,
|
|
260
|
+
behavior = _ref.behavior;
|
|
261
|
+
var toOffset = offset + adjustments;
|
|
262
|
+
(_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));
|
|
248
263
|
};
|
|
249
|
-
|
|
250
|
-
var _instance$
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
behavior
|
|
254
|
-
|
|
264
|
+
var elementScroll = function elementScroll(offset, _ref2, instance) {
|
|
265
|
+
var _instance$scrollEleme3, _instance$scrollEleme4;
|
|
266
|
+
var _ref2$adjustments = _ref2.adjustments,
|
|
267
|
+
adjustments = _ref2$adjustments === void 0 ? 0 : _ref2$adjustments,
|
|
268
|
+
behavior = _ref2.behavior;
|
|
269
|
+
var toOffset = offset + adjustments;
|
|
270
|
+
(_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));
|
|
255
271
|
};
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
rangeExtractor: defaultRangeExtractor,
|
|
283
|
-
enableSmoothScroll: true,
|
|
284
|
-
onChange: () => {},
|
|
285
|
-
measureElement,
|
|
286
|
-
initialRect: {
|
|
287
|
-
width: 0,
|
|
288
|
-
height: 0
|
|
289
|
-
},
|
|
290
|
-
...opts
|
|
291
|
-
};
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
this.notify = () => {
|
|
295
|
-
var _this$options$onChang, _this$options;
|
|
296
|
-
|
|
297
|
-
(_this$options$onChang = (_this$options = this.options).onChange) == null ? void 0 : _this$options$onChang.call(_this$options, this);
|
|
298
|
-
};
|
|
299
|
-
|
|
300
|
-
this.cleanup = () => {
|
|
301
|
-
this.unsubs.filter(Boolean).forEach(d => d());
|
|
302
|
-
this.unsubs = [];
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
this._didMount = () => {
|
|
306
|
-
return () => {
|
|
307
|
-
this.cleanup();
|
|
308
|
-
};
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
this._willUpdate = () => {
|
|
312
|
-
const scrollElement = this.options.getScrollElement();
|
|
313
|
-
|
|
314
|
-
if (this.scrollElement !== scrollElement) {
|
|
315
|
-
this.cleanup();
|
|
316
|
-
this.scrollElement = scrollElement;
|
|
317
|
-
this.unsubs.push(this.options.observeElementRect(this, rect => {
|
|
318
|
-
this.scrollRect = rect;
|
|
319
|
-
this.notify();
|
|
320
|
-
}));
|
|
321
|
-
this.unsubs.push(this.options.observeElementOffset(this, offset => {
|
|
322
|
-
this.scrollOffset = offset;
|
|
323
|
-
this.notify();
|
|
324
|
-
}));
|
|
272
|
+
var Virtualizer = function Virtualizer(_opts) {
|
|
273
|
+
var _this = this;
|
|
274
|
+
this.unsubs = [];
|
|
275
|
+
this.scrollElement = null;
|
|
276
|
+
this.isScrolling = false;
|
|
277
|
+
this.isScrollingTimeoutId = null;
|
|
278
|
+
this.scrollToIndexTimeoutId = null;
|
|
279
|
+
this.measurementsCache = [];
|
|
280
|
+
this.itemSizeCache = new Map();
|
|
281
|
+
this.pendingMeasuredCacheIndexes = [];
|
|
282
|
+
this.scrollDirection = null;
|
|
283
|
+
this.scrollAdjustments = 0;
|
|
284
|
+
this.measureElementCache = new Map();
|
|
285
|
+
this.observer = function () {
|
|
286
|
+
var _ro = null;
|
|
287
|
+
var get = function get() {
|
|
288
|
+
if (_ro) {
|
|
289
|
+
return _ro;
|
|
290
|
+
} else if (typeof ResizeObserver !== 'undefined') {
|
|
291
|
+
return _ro = new ResizeObserver(function (entries) {
|
|
292
|
+
entries.forEach(function (entry) {
|
|
293
|
+
_this._measureElement(entry.target, entry);
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
} else {
|
|
297
|
+
return null;
|
|
325
298
|
}
|
|
326
299
|
};
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
const size = typeof measuredSize === 'number' ? measuredSize : this.options.estimateSize(i);
|
|
342
|
-
const end = start + size;
|
|
343
|
-
measurements[i] = {
|
|
344
|
-
index: i,
|
|
345
|
-
start,
|
|
346
|
-
size,
|
|
347
|
-
end,
|
|
348
|
-
key
|
|
349
|
-
};
|
|
300
|
+
return {
|
|
301
|
+
disconnect: function disconnect() {
|
|
302
|
+
var _get;
|
|
303
|
+
return (_get = get()) == null ? void 0 : _get.disconnect();
|
|
304
|
+
},
|
|
305
|
+
observe: function observe(target) {
|
|
306
|
+
var _get2;
|
|
307
|
+
return (_get2 = get()) == null ? void 0 : _get2.observe(target, {
|
|
308
|
+
box: 'border-box'
|
|
309
|
+
});
|
|
310
|
+
},
|
|
311
|
+
unobserve: function unobserve(target) {
|
|
312
|
+
var _get3;
|
|
313
|
+
return (_get3 = get()) == null ? void 0 : _get3.unobserve(target);
|
|
350
314
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
315
|
+
};
|
|
316
|
+
}();
|
|
317
|
+
this.range = {
|
|
318
|
+
startIndex: 0,
|
|
319
|
+
endIndex: 0
|
|
320
|
+
};
|
|
321
|
+
this.setOptions = function (opts) {
|
|
322
|
+
Object.entries(opts).forEach(function (_ref3) {
|
|
323
|
+
var key = _ref3[0],
|
|
324
|
+
value = _ref3[1];
|
|
325
|
+
if (typeof value === 'undefined') delete opts[key];
|
|
357
326
|
});
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
327
|
+
_this.options = _extends({
|
|
328
|
+
debug: false,
|
|
329
|
+
initialOffset: 0,
|
|
330
|
+
overscan: 1,
|
|
331
|
+
paddingStart: 0,
|
|
332
|
+
paddingEnd: 0,
|
|
333
|
+
scrollPaddingStart: 0,
|
|
334
|
+
scrollPaddingEnd: 0,
|
|
335
|
+
horizontal: false,
|
|
336
|
+
getItemKey: defaultKeyExtractor,
|
|
337
|
+
rangeExtractor: defaultRangeExtractor,
|
|
338
|
+
onChange: function onChange() {},
|
|
339
|
+
measureElement: measureElement,
|
|
340
|
+
initialRect: {
|
|
341
|
+
width: 0,
|
|
342
|
+
height: 0
|
|
343
|
+
},
|
|
344
|
+
scrollMargin: 0,
|
|
345
|
+
scrollingDelay: 150,
|
|
346
|
+
indexAttribute: 'data-index',
|
|
347
|
+
initialMeasurementsCache: [],
|
|
348
|
+
lanes: 1
|
|
349
|
+
}, opts);
|
|
350
|
+
};
|
|
351
|
+
this.notify = function () {
|
|
352
|
+
_this.options.onChange == null ? void 0 : _this.options.onChange(_this);
|
|
353
|
+
};
|
|
354
|
+
this.cleanup = function () {
|
|
355
|
+
_this.unsubs.filter(Boolean).forEach(function (d) {
|
|
356
|
+
return d();
|
|
367
357
|
});
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
358
|
+
_this.unsubs = [];
|
|
359
|
+
_this.scrollElement = null;
|
|
360
|
+
};
|
|
361
|
+
this._didMount = function () {
|
|
362
|
+
_this.measureElementCache.forEach(_this.observer.observe);
|
|
363
|
+
return function () {
|
|
364
|
+
_this.observer.disconnect();
|
|
365
|
+
_this.cleanup();
|
|
366
|
+
};
|
|
367
|
+
};
|
|
368
|
+
this._willUpdate = function () {
|
|
369
|
+
var scrollElement = _this.options.getScrollElement();
|
|
370
|
+
if (_this.scrollElement !== scrollElement) {
|
|
371
|
+
_this.cleanup();
|
|
372
|
+
_this.scrollElement = scrollElement;
|
|
373
|
+
_this._scrollToOffset(_this.scrollOffset, {
|
|
374
|
+
adjustments: undefined,
|
|
375
|
+
behavior: undefined
|
|
372
376
|
});
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
if (
|
|
377
|
+
_this.unsubs.push(_this.options.observeElementRect(_this, function (rect) {
|
|
378
|
+
var prev = _this.scrollRect;
|
|
379
|
+
_this.scrollRect = rect;
|
|
380
|
+
if (_this.options.horizontal ? rect.width !== prev.width : rect.height !== prev.height) {
|
|
381
|
+
_this.maybeNotify();
|
|
382
|
+
}
|
|
383
|
+
}));
|
|
384
|
+
_this.unsubs.push(_this.options.observeElementOffset(_this, function (offset) {
|
|
385
|
+
_this.scrollAdjustments = 0;
|
|
386
|
+
if (_this.scrollOffset === offset) {
|
|
383
387
|
return;
|
|
384
388
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
if (measuredItemSize !== itemSize) {
|
|
390
|
-
if (item.start < this.scrollOffset) {
|
|
391
|
-
if (this.options.debug) {
|
|
392
|
-
console.info('correction', measuredItemSize - itemSize);
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
if (!this.destinationOffset) {
|
|
396
|
-
this._scrollToOffset(this.scrollOffset + (measuredItemSize - itemSize), false);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
this.pendingMeasuredCacheIndexes.push(index);
|
|
401
|
-
this.itemMeasurementsCache = { ...this.itemMeasurementsCache,
|
|
402
|
-
[item.key]: measuredItemSize
|
|
403
|
-
};
|
|
404
|
-
this.notify();
|
|
389
|
+
if (_this.isScrollingTimeoutId !== null) {
|
|
390
|
+
clearTimeout(_this.isScrollingTimeoutId);
|
|
391
|
+
_this.isScrollingTimeoutId = null;
|
|
405
392
|
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
393
|
+
_this.isScrolling = true;
|
|
394
|
+
_this.scrollDirection = _this.scrollOffset < offset ? 'forward' : 'backward';
|
|
395
|
+
_this.scrollOffset = offset;
|
|
396
|
+
_this.maybeNotify();
|
|
397
|
+
_this.isScrollingTimeoutId = setTimeout(function () {
|
|
398
|
+
_this.isScrollingTimeoutId = null;
|
|
399
|
+
_this.isScrolling = false;
|
|
400
|
+
_this.scrollDirection = null;
|
|
401
|
+
_this.maybeNotify();
|
|
402
|
+
}, _this.options.scrollingDelay);
|
|
403
|
+
}));
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
this.getSize = function () {
|
|
407
|
+
return _this.scrollRect[_this.options.horizontal ? 'width' : 'height'];
|
|
408
|
+
};
|
|
409
|
+
this.memoOptions = memo(function () {
|
|
410
|
+
return [_this.options.count, _this.options.paddingStart, _this.options.scrollMargin, _this.options.getItemKey];
|
|
411
|
+
}, function (count, paddingStart, scrollMargin, getItemKey) {
|
|
412
|
+
_this.pendingMeasuredCacheIndexes = [];
|
|
413
|
+
return {
|
|
414
|
+
count: count,
|
|
415
|
+
paddingStart: paddingStart,
|
|
416
|
+
scrollMargin: scrollMargin,
|
|
417
|
+
getItemKey: getItemKey
|
|
418
|
+
};
|
|
419
|
+
}, {
|
|
420
|
+
key: false
|
|
421
|
+
});
|
|
422
|
+
this.getFurthestMeasurement = function (measurements, index) {
|
|
423
|
+
var furthestMeasurementsFound = new Map();
|
|
424
|
+
var furthestMeasurements = new Map();
|
|
425
|
+
for (var m = index - 1; m >= 0; m--) {
|
|
426
|
+
var measurement = measurements[m];
|
|
427
|
+
if (furthestMeasurementsFound.has(measurement.lane)) {
|
|
428
|
+
continue;
|
|
420
429
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
430
|
+
var previousFurthestMeasurement = furthestMeasurements.get(measurement.lane);
|
|
431
|
+
if (previousFurthestMeasurement == null || measurement.end > previousFurthestMeasurement.end) {
|
|
432
|
+
furthestMeasurements.set(measurement.lane, measurement);
|
|
433
|
+
} else if (measurement.end < previousFurthestMeasurement.end) {
|
|
434
|
+
furthestMeasurementsFound.set(measurement.lane, true);
|
|
435
|
+
}
|
|
436
|
+
if (furthestMeasurementsFound.size === _this.options.lanes) {
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
return furthestMeasurements.size === _this.options.lanes ? Array.from(furthestMeasurements.values()).sort(function (a, b) {
|
|
441
|
+
return a.end - b.end;
|
|
442
|
+
})[0] : undefined;
|
|
443
|
+
};
|
|
444
|
+
this.getMeasurements = memo(function () {
|
|
445
|
+
return [_this.memoOptions(), _this.itemSizeCache];
|
|
446
|
+
}, function (_ref4, itemSizeCache) {
|
|
447
|
+
var count = _ref4.count,
|
|
448
|
+
paddingStart = _ref4.paddingStart,
|
|
449
|
+
scrollMargin = _ref4.scrollMargin,
|
|
450
|
+
getItemKey = _ref4.getItemKey;
|
|
451
|
+
var min = _this.pendingMeasuredCacheIndexes.length > 0 ? Math.min.apply(Math, _this.pendingMeasuredCacheIndexes) : 0;
|
|
452
|
+
_this.pendingMeasuredCacheIndexes = [];
|
|
453
|
+
var measurements = _this.measurementsCache.slice(0, min);
|
|
454
|
+
for (var _i2 = min; _i2 < count; _i2++) {
|
|
455
|
+
var key = getItemKey(_i2);
|
|
456
|
+
var furthestMeasurement = _this.options.lanes === 1 ? measurements[_i2 - 1] : _this.getFurthestMeasurement(measurements, _i2);
|
|
457
|
+
var start = furthestMeasurement ? furthestMeasurement.end : paddingStart + scrollMargin;
|
|
458
|
+
var measuredSize = itemSizeCache.get(key);
|
|
459
|
+
var size = typeof measuredSize === 'number' ? measuredSize : _this.options.estimateSize(_i2);
|
|
460
|
+
var end = start + size;
|
|
461
|
+
var lane = furthestMeasurement ? furthestMeasurement.lane : _i2 % _this.options.lanes;
|
|
462
|
+
measurements[_i2] = {
|
|
463
|
+
index: _i2,
|
|
464
|
+
start: start,
|
|
465
|
+
size: size,
|
|
466
|
+
end: end,
|
|
467
|
+
key: key,
|
|
468
|
+
lane: lane
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
_this.measurementsCache = measurements;
|
|
472
|
+
return measurements;
|
|
473
|
+
}, {
|
|
474
|
+
key: 'getMeasurements',
|
|
475
|
+
debug: function debug() {
|
|
476
|
+
return _this.options.debug;
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
this.calculateRange = memo(function () {
|
|
480
|
+
return [_this.getMeasurements(), _this.getSize(), _this.scrollOffset];
|
|
481
|
+
}, function (measurements, outerSize, scrollOffset) {
|
|
482
|
+
return _this.range = calculateRange({
|
|
483
|
+
measurements: measurements,
|
|
484
|
+
outerSize: outerSize,
|
|
485
|
+
scrollOffset: scrollOffset
|
|
426
486
|
});
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
487
|
+
}, {
|
|
488
|
+
key: 'calculateRange',
|
|
489
|
+
debug: function debug() {
|
|
490
|
+
return _this.options.debug;
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
this.maybeNotify = memo(function () {
|
|
494
|
+
var range = _this.calculateRange();
|
|
495
|
+
return [range.startIndex, range.endIndex, _this.isScrolling];
|
|
496
|
+
}, function () {
|
|
497
|
+
_this.notify();
|
|
498
|
+
}, {
|
|
499
|
+
key: 'maybeNotify',
|
|
500
|
+
debug: function debug() {
|
|
501
|
+
return _this.options.debug;
|
|
502
|
+
},
|
|
503
|
+
initialDeps: [this.range.startIndex, this.range.endIndex, this.isScrolling]
|
|
504
|
+
});
|
|
505
|
+
this.getIndexes = memo(function () {
|
|
506
|
+
return [_this.options.rangeExtractor, _this.calculateRange(), _this.options.overscan, _this.options.count];
|
|
507
|
+
}, function (rangeExtractor, range, overscan, count) {
|
|
508
|
+
return rangeExtractor(_extends({}, range, {
|
|
509
|
+
overscan: overscan,
|
|
510
|
+
count: count
|
|
511
|
+
}));
|
|
512
|
+
}, {
|
|
513
|
+
key: 'getIndexes',
|
|
514
|
+
debug: function debug() {
|
|
515
|
+
return _this.options.debug;
|
|
516
|
+
}
|
|
517
|
+
});
|
|
518
|
+
this.indexFromElement = function (node) {
|
|
519
|
+
var attributeName = _this.options.indexAttribute;
|
|
520
|
+
var indexStr = node.getAttribute(attributeName);
|
|
521
|
+
if (!indexStr) {
|
|
522
|
+
console.warn("Missing attribute name '" + attributeName + "={index}' on measured element.");
|
|
523
|
+
return -1;
|
|
524
|
+
}
|
|
525
|
+
return parseInt(indexStr, 10);
|
|
526
|
+
};
|
|
527
|
+
this._measureElement = function (node, entry) {
|
|
528
|
+
var item = _this.measurementsCache[_this.indexFromElement(node)];
|
|
529
|
+
if (!item) {
|
|
530
|
+
_this.measureElementCache.forEach(function (cached, key) {
|
|
531
|
+
if (cached === node) {
|
|
532
|
+
_this.observer.unobserve(node);
|
|
533
|
+
_this.measureElementCache["delete"](key);
|
|
456
534
|
}
|
|
457
|
-
};
|
|
458
|
-
|
|
459
|
-
attempt();
|
|
460
|
-
requestAnimationFrame(() => {
|
|
461
|
-
attempt();
|
|
462
535
|
});
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
align: 'auto'
|
|
471
|
-
} : _temp2;
|
|
472
|
-
|
|
473
|
-
const measurements = _this.getMeasurements();
|
|
474
|
-
|
|
475
|
-
const offset = _this.scrollOffset;
|
|
476
|
-
|
|
477
|
-
const size = _this.getSize();
|
|
478
|
-
|
|
479
|
-
const {
|
|
480
|
-
count
|
|
481
|
-
} = _this.options;
|
|
482
|
-
const measurement = measurements[Math.max(0, Math.min(index, count - 1))];
|
|
483
|
-
|
|
484
|
-
if (!measurement) {
|
|
485
|
-
return;
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
var prevNode = _this.measureElementCache.get(item.key);
|
|
539
|
+
if (!node.isConnected) {
|
|
540
|
+
if (prevNode) {
|
|
541
|
+
_this.observer.unobserve(prevNode);
|
|
542
|
+
_this.measureElementCache["delete"](item.key);
|
|
486
543
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
if (prevNode !== node) {
|
|
547
|
+
if (prevNode) {
|
|
548
|
+
_this.observer.unobserve(prevNode);
|
|
549
|
+
}
|
|
550
|
+
_this.observer.observe(node);
|
|
551
|
+
_this.measureElementCache.set(item.key, node);
|
|
552
|
+
}
|
|
553
|
+
var measuredItemSize = _this.options.measureElement(node, entry, _this);
|
|
554
|
+
_this.resizeItem(item, measuredItemSize);
|
|
555
|
+
};
|
|
556
|
+
this.resizeItem = function (item, size) {
|
|
557
|
+
var _this$itemSizeCache$g;
|
|
558
|
+
var itemSize = (_this$itemSizeCache$g = _this.itemSizeCache.get(item.key)) != null ? _this$itemSizeCache$g : item.size;
|
|
559
|
+
var delta = size - itemSize;
|
|
560
|
+
if (delta !== 0) {
|
|
561
|
+
if (item.start < _this.scrollOffset) {
|
|
562
|
+
if (_this.options.debug) {
|
|
563
|
+
console.info('correction', delta);
|
|
495
564
|
}
|
|
565
|
+
_this._scrollToOffset(_this.scrollOffset, {
|
|
566
|
+
adjustments: _this.scrollAdjustments += delta,
|
|
567
|
+
behavior: undefined
|
|
568
|
+
});
|
|
496
569
|
}
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
570
|
+
_this.pendingMeasuredCacheIndexes.push(item.index);
|
|
571
|
+
_this.itemSizeCache = new Map(_this.itemSizeCache.set(item.key, size));
|
|
572
|
+
_this.notify();
|
|
573
|
+
}
|
|
574
|
+
};
|
|
575
|
+
this.measureElement = function (node) {
|
|
576
|
+
if (!node) {
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
_this._measureElement(node, undefined);
|
|
580
|
+
};
|
|
581
|
+
this.getVirtualItems = memo(function () {
|
|
582
|
+
return [_this.getIndexes(), _this.getMeasurements()];
|
|
583
|
+
}, function (indexes, measurements) {
|
|
584
|
+
var virtualItems = [];
|
|
585
|
+
for (var k = 0, len = indexes.length; k < len; k++) {
|
|
586
|
+
var _i3 = indexes[k];
|
|
587
|
+
var measurement = measurements[_i3];
|
|
588
|
+
virtualItems.push(measurement);
|
|
589
|
+
}
|
|
590
|
+
return virtualItems;
|
|
591
|
+
}, {
|
|
592
|
+
key: 'getIndexes',
|
|
593
|
+
debug: function debug() {
|
|
594
|
+
return _this.options.debug;
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
this.getVirtualItemForOffset = function (offset) {
|
|
598
|
+
var measurements = _this.getMeasurements();
|
|
599
|
+
return notUndefined(measurements[findNearestBinarySearch(0, measurements.length - 1, function (index) {
|
|
600
|
+
return notUndefined(measurements[index]).start;
|
|
601
|
+
}, offset)]);
|
|
602
|
+
};
|
|
603
|
+
this.getOffsetForAlignment = function (toOffset, align) {
|
|
604
|
+
var size = _this.getSize();
|
|
605
|
+
if (align === 'auto') {
|
|
606
|
+
if (toOffset <= _this.scrollOffset) {
|
|
607
|
+
align = 'start';
|
|
608
|
+
} else if (toOffset >= _this.scrollOffset + size) {
|
|
609
|
+
align = 'end';
|
|
610
|
+
} else {
|
|
611
|
+
align = 'start';
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
if (align === 'start') {
|
|
615
|
+
toOffset = toOffset;
|
|
616
|
+
} else if (align === 'end') {
|
|
617
|
+
toOffset = toOffset - size;
|
|
618
|
+
} else if (align === 'center') {
|
|
619
|
+
toOffset = toOffset - size / 2;
|
|
620
|
+
}
|
|
621
|
+
var scrollSizeProp = _this.options.horizontal ? 'scrollWidth' : 'scrollHeight';
|
|
622
|
+
var scrollSize = _this.scrollElement ? 'document' in _this.scrollElement ? _this.scrollElement.document.documentElement[scrollSizeProp] : _this.scrollElement[scrollSizeProp] : 0;
|
|
623
|
+
var maxOffset = scrollSize - _this.getSize();
|
|
624
|
+
return Math.max(Math.min(maxOffset, toOffset), 0);
|
|
625
|
+
};
|
|
626
|
+
this.getOffsetForIndex = function (index, align) {
|
|
627
|
+
if (align === void 0) {
|
|
628
|
+
align = 'auto';
|
|
629
|
+
}
|
|
630
|
+
index = Math.max(0, Math.min(index, _this.options.count - 1));
|
|
631
|
+
var measurement = notUndefined(_this.getMeasurements()[index]);
|
|
632
|
+
if (align === 'auto') {
|
|
633
|
+
if (measurement.end >= _this.scrollOffset + _this.getSize() - _this.options.scrollPaddingEnd) {
|
|
634
|
+
align = 'end';
|
|
635
|
+
} else if (measurement.start <= _this.scrollOffset + _this.options.scrollPaddingStart) {
|
|
636
|
+
align = 'start';
|
|
637
|
+
} else {
|
|
638
|
+
return [_this.scrollOffset, align];
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
var toOffset = align === 'end' ? measurement.end + _this.options.scrollPaddingEnd : measurement.start - _this.options.scrollPaddingStart;
|
|
642
|
+
return [_this.getOffsetForAlignment(toOffset, align), align];
|
|
643
|
+
};
|
|
644
|
+
this.isDynamicMode = function () {
|
|
645
|
+
return _this.measureElementCache.size > 0;
|
|
646
|
+
};
|
|
647
|
+
this.cancelScrollToIndex = function () {
|
|
648
|
+
if (_this.scrollToIndexTimeoutId !== null) {
|
|
649
|
+
clearTimeout(_this.scrollToIndexTimeoutId);
|
|
650
|
+
_this.scrollToIndexTimeoutId = null;
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
this.scrollToOffset = function (toOffset, _temp) {
|
|
654
|
+
var _ref5 = _temp === void 0 ? {} : _temp,
|
|
655
|
+
_ref5$align = _ref5.align,
|
|
656
|
+
align = _ref5$align === void 0 ? 'start' : _ref5$align,
|
|
657
|
+
behavior = _ref5.behavior;
|
|
658
|
+
_this.cancelScrollToIndex();
|
|
659
|
+
if (behavior === 'smooth' && _this.isDynamicMode()) {
|
|
660
|
+
console.warn('The `smooth` scroll behavior is not fully supported with dynamic size.');
|
|
661
|
+
}
|
|
662
|
+
_this._scrollToOffset(_this.getOffsetForAlignment(toOffset, align), {
|
|
663
|
+
adjustments: undefined,
|
|
664
|
+
behavior: behavior
|
|
665
|
+
});
|
|
666
|
+
};
|
|
667
|
+
this.scrollToIndex = function (index, _temp2) {
|
|
668
|
+
var _ref6 = _temp2 === void 0 ? {} : _temp2,
|
|
669
|
+
_ref6$align = _ref6.align,
|
|
670
|
+
initialAlign = _ref6$align === void 0 ? 'auto' : _ref6$align,
|
|
671
|
+
behavior = _ref6.behavior;
|
|
672
|
+
index = Math.max(0, Math.min(index, _this.options.count - 1));
|
|
673
|
+
_this.cancelScrollToIndex();
|
|
674
|
+
if (behavior === 'smooth' && _this.isDynamicMode()) {
|
|
675
|
+
console.warn('The `smooth` scroll behavior is not fully supported with dynamic size.');
|
|
676
|
+
}
|
|
677
|
+
var _this$getOffsetForInd = _this.getOffsetForIndex(index, initialAlign),
|
|
678
|
+
toOffset = _this$getOffsetForInd[0],
|
|
679
|
+
align = _this$getOffsetForInd[1];
|
|
680
|
+
_this._scrollToOffset(toOffset, {
|
|
681
|
+
adjustments: undefined,
|
|
682
|
+
behavior: behavior
|
|
683
|
+
});
|
|
684
|
+
if (behavior !== 'smooth' && _this.isDynamicMode()) {
|
|
685
|
+
_this.scrollToIndexTimeoutId = setTimeout(function () {
|
|
686
|
+
_this.scrollToIndexTimeoutId = null;
|
|
687
|
+
var elementInDOM = _this.measureElementCache.has(_this.options.getItemKey(index));
|
|
688
|
+
if (elementInDOM) {
|
|
689
|
+
var _this$getOffsetForInd2 = _this.getOffsetForIndex(index, align),
|
|
690
|
+
_toOffset = _this$getOffsetForInd2[0];
|
|
691
|
+
if (!approxEqual(_toOffset, _this.scrollOffset)) {
|
|
692
|
+
_this.scrollToIndex(index, {
|
|
693
|
+
align: align,
|
|
694
|
+
behavior: behavior
|
|
695
|
+
});
|
|
528
696
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
697
|
+
} else {
|
|
698
|
+
_this.scrollToIndex(index, {
|
|
699
|
+
align: align,
|
|
700
|
+
behavior: behavior
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
this.scrollBy = function (delta, _temp3) {
|
|
707
|
+
var _ref7 = _temp3 === void 0 ? {} : _temp3,
|
|
708
|
+
behavior = _ref7.behavior;
|
|
709
|
+
_this.cancelScrollToIndex();
|
|
710
|
+
if (behavior === 'smooth' && _this.isDynamicMode()) {
|
|
711
|
+
console.warn('The `smooth` scroll behavior is not fully supported with dynamic size.');
|
|
712
|
+
}
|
|
713
|
+
_this._scrollToOffset(_this.scrollOffset + delta, {
|
|
714
|
+
adjustments: undefined,
|
|
715
|
+
behavior: behavior
|
|
716
|
+
});
|
|
717
|
+
};
|
|
718
|
+
this.getTotalSize = function () {
|
|
719
|
+
var _this$getMeasurements;
|
|
720
|
+
return (((_this$getMeasurements = _this.getMeasurements()[_this.options.count - 1]) == null ? void 0 : _this$getMeasurements.end) || _this.options.paddingStart) - _this.options.scrollMargin + _this.options.paddingEnd;
|
|
721
|
+
};
|
|
722
|
+
this._scrollToOffset = function (offset, _ref8) {
|
|
723
|
+
var adjustments = _ref8.adjustments,
|
|
724
|
+
behavior = _ref8.behavior;
|
|
725
|
+
_this.options.scrollToFn(offset, {
|
|
726
|
+
behavior: behavior,
|
|
727
|
+
adjustments: adjustments
|
|
728
|
+
}, _this);
|
|
729
|
+
};
|
|
730
|
+
this.measure = function () {
|
|
731
|
+
_this.itemSizeCache = new Map();
|
|
732
|
+
_this.notify();
|
|
733
|
+
};
|
|
734
|
+
this.setOptions(_opts);
|
|
735
|
+
this.scrollRect = this.options.initialRect;
|
|
736
|
+
this.scrollOffset = this.options.initialOffset;
|
|
737
|
+
this.measurementsCache = this.options.initialMeasurementsCache;
|
|
738
|
+
this.measurementsCache.forEach(function (item) {
|
|
739
|
+
_this.itemSizeCache.set(item.key, item.size);
|
|
740
|
+
});
|
|
741
|
+
this.maybeNotify();
|
|
742
|
+
};
|
|
743
|
+
var findNearestBinarySearch = function findNearestBinarySearch(low, high, getCurrentValue, value) {
|
|
551
744
|
while (low <= high) {
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
745
|
+
var middle = (low + high) / 2 | 0;
|
|
746
|
+
var currentValue = getCurrentValue(middle);
|
|
555
747
|
if (currentValue < value) {
|
|
556
748
|
low = middle + 1;
|
|
557
749
|
} else if (currentValue > value) {
|
|
@@ -560,82 +752,83 @@
|
|
|
560
752
|
return middle;
|
|
561
753
|
}
|
|
562
754
|
}
|
|
563
|
-
|
|
564
755
|
if (low > 0) {
|
|
565
756
|
return low - 1;
|
|
566
757
|
} else {
|
|
567
758
|
return 0;
|
|
568
759
|
}
|
|
569
760
|
};
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
const startIndex = findNearestBinarySearch(0, count, getOffset, scrollOffset);
|
|
582
|
-
let endIndex = startIndex;
|
|
583
|
-
|
|
761
|
+
function calculateRange(_ref9) {
|
|
762
|
+
var measurements = _ref9.measurements,
|
|
763
|
+
outerSize = _ref9.outerSize,
|
|
764
|
+
scrollOffset = _ref9.scrollOffset;
|
|
765
|
+
var count = measurements.length - 1;
|
|
766
|
+
var getOffset = function getOffset(index) {
|
|
767
|
+
return measurements[index].start;
|
|
768
|
+
};
|
|
769
|
+
var startIndex = findNearestBinarySearch(0, count, getOffset, scrollOffset);
|
|
770
|
+
var endIndex = startIndex;
|
|
584
771
|
while (endIndex < count && measurements[endIndex].end < scrollOffset + outerSize) {
|
|
585
772
|
endIndex++;
|
|
586
773
|
}
|
|
587
|
-
|
|
588
774
|
return {
|
|
589
|
-
startIndex,
|
|
590
|
-
endIndex
|
|
775
|
+
startIndex: startIndex,
|
|
776
|
+
endIndex: endIndex
|
|
591
777
|
};
|
|
592
778
|
}
|
|
593
779
|
|
|
594
|
-
|
|
780
|
+
//
|
|
595
781
|
|
|
782
|
+
var useIsomorphicLayoutEffect = typeof document !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
596
783
|
function useVirtualizerBase(options) {
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
784
|
+
var rerender = React__namespace.useReducer(function () {
|
|
785
|
+
return {};
|
|
786
|
+
}, {})[1];
|
|
787
|
+
var resolvedOptions = _extends$1({}, options, {
|
|
788
|
+
onChange: function onChange(instance) {
|
|
600
789
|
rerender();
|
|
601
790
|
options.onChange == null ? void 0 : options.onChange(instance);
|
|
602
791
|
}
|
|
603
|
-
};
|
|
604
|
-
|
|
792
|
+
});
|
|
793
|
+
var _React$useState = React__namespace.useState(function () {
|
|
794
|
+
return new Virtualizer(resolvedOptions);
|
|
795
|
+
}),
|
|
796
|
+
instance = _React$useState[0];
|
|
605
797
|
instance.setOptions(resolvedOptions);
|
|
606
|
-
React__namespace.useEffect(()
|
|
798
|
+
React__namespace.useEffect(function () {
|
|
607
799
|
return instance._didMount();
|
|
608
800
|
}, []);
|
|
609
|
-
useIsomorphicLayoutEffect(()
|
|
801
|
+
useIsomorphicLayoutEffect(function () {
|
|
610
802
|
return instance._willUpdate();
|
|
611
803
|
});
|
|
612
804
|
return instance;
|
|
613
805
|
}
|
|
614
|
-
|
|
615
806
|
function useVirtualizer(options) {
|
|
616
|
-
return useVirtualizerBase({
|
|
807
|
+
return useVirtualizerBase(_extends$1({
|
|
617
808
|
observeElementRect: observeElementRect,
|
|
618
809
|
observeElementOffset: observeElementOffset,
|
|
619
|
-
scrollToFn: elementScroll
|
|
620
|
-
|
|
621
|
-
});
|
|
810
|
+
scrollToFn: elementScroll
|
|
811
|
+
}, options));
|
|
622
812
|
}
|
|
623
813
|
function useWindowVirtualizer(options) {
|
|
624
|
-
return useVirtualizerBase({
|
|
625
|
-
getScrollElement: ()
|
|
814
|
+
return useVirtualizerBase(_extends$1({
|
|
815
|
+
getScrollElement: function getScrollElement() {
|
|
816
|
+
return typeof document !== 'undefined' ? window : null;
|
|
817
|
+
},
|
|
626
818
|
observeElementRect: observeWindowRect,
|
|
627
819
|
observeElementOffset: observeWindowOffset,
|
|
628
|
-
scrollToFn: windowScroll
|
|
629
|
-
|
|
630
|
-
});
|
|
820
|
+
scrollToFn: windowScroll
|
|
821
|
+
}, options));
|
|
631
822
|
}
|
|
632
823
|
|
|
633
824
|
exports.Virtualizer = Virtualizer;
|
|
825
|
+
exports.approxEqual = approxEqual;
|
|
634
826
|
exports.defaultKeyExtractor = defaultKeyExtractor;
|
|
635
827
|
exports.defaultRangeExtractor = defaultRangeExtractor;
|
|
636
828
|
exports.elementScroll = elementScroll;
|
|
637
829
|
exports.measureElement = measureElement;
|
|
638
830
|
exports.memo = memo;
|
|
831
|
+
exports.notUndefined = notUndefined;
|
|
639
832
|
exports.observeElementOffset = observeElementOffset;
|
|
640
833
|
exports.observeElementRect = observeElementRect;
|
|
641
834
|
exports.observeWindowOffset = observeWindowOffset;
|