react-virtuoso 2.8.0-alpha.4 → 2.8.2

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.
Files changed (37) hide show
  1. package/dist/List.d.ts +261 -49
  2. package/dist/Table.d.ts +307 -95
  3. package/dist/alignToBottomSystem.d.ts +22 -2
  4. package/dist/{components/TableVirtuoso.d.ts → components.d.ts} +3443 -1300
  5. package/dist/followOutputSystem.d.ts +18 -2
  6. package/dist/groupedListSystem.d.ts +4 -0
  7. package/dist/hooks/useIsomorphicLayoutEffect.d.ts +2 -2
  8. package/dist/hooks/useScrollTop.d.ts +1 -1
  9. package/dist/index.d.ts +1 -1
  10. package/dist/index.js +2 -8
  11. package/dist/index.js.map +1 -0
  12. package/dist/index.m.js +2 -0
  13. package/dist/index.m.js.map +1 -0
  14. package/dist/initialItemCountSystem.d.ts +26 -2
  15. package/dist/initialScrollTopSystem.d.ts +22 -2
  16. package/dist/initialTopMostItemIndexSystem.d.ts +13 -3
  17. package/dist/interfaces.d.ts +7 -1
  18. package/dist/listStateSystem.d.ts +22 -2
  19. package/dist/listSystem.d.ts +234 -22
  20. package/dist/scrollIntoViewSystem.d.ts +30 -2
  21. package/dist/scrollToIndexSystem.d.ts +4 -0
  22. package/dist/sizeSystem.d.ts +2 -0
  23. package/dist/topItemCountSystem.d.ts +22 -2
  24. package/dist/totalListHeightSystem.d.ts +22 -2
  25. package/dist/upwardScrollFixSystem.d.ts +27 -3
  26. package/package.json +5 -16
  27. package/dist/components/CompProps.d.ts +0 -2
  28. package/dist/components/GroupedVirtuoso.d.ts +0 -27
  29. package/dist/components/Virtuoso.d.ts +0 -205
  30. package/dist/components/VirtuosoGrid.d.ts +0 -93
  31. package/dist/components/index.d.ts +0 -4
  32. package/dist/react-virtuoso.cjs.development.js +0 -3871
  33. package/dist/react-virtuoso.cjs.development.js.map +0 -1
  34. package/dist/react-virtuoso.cjs.production.min.js +0 -2
  35. package/dist/react-virtuoso.cjs.production.min.js.map +0 -1
  36. package/dist/react-virtuoso.esm.js +0 -3845
  37. package/dist/react-virtuoso.esm.js.map +0 -1
@@ -1,3845 +0,0 @@
1
- import { systemToComponent } from '@virtuoso.dev/react-urx';
2
- import * as u from '@virtuoso.dev/urx';
3
- import { getValue, tup, system, stream, streamFromEmitter, pipe, map, connect, prop, combineLatest, filter, distinctUntilChanged, statefulStream, subscribe, publish, noop, withLatestFrom, statefulStreamFromEmitter, compose } from '@virtuoso.dev/urx';
4
- import * as React from 'react';
5
- import { useLayoutEffect, useEffect, useRef, useCallback, createElement } from 'react';
6
-
7
- function _extends() {
8
- _extends = Object.assign || function (target) {
9
- for (var i = 1; i < arguments.length; i++) {
10
- var source = arguments[i];
11
-
12
- for (var key in source) {
13
- if (Object.prototype.hasOwnProperty.call(source, key)) {
14
- target[key] = source[key];
15
- }
16
- }
17
- }
18
-
19
- return target;
20
- };
21
-
22
- return _extends.apply(this, arguments);
23
- }
24
-
25
- function _objectWithoutPropertiesLoose(source, excluded) {
26
- if (source == null) return {};
27
- var target = {};
28
- var sourceKeys = Object.keys(source);
29
- var key, i;
30
-
31
- for (i = 0; i < sourceKeys.length; i++) {
32
- key = sourceKeys[i];
33
- if (excluded.indexOf(key) >= 0) continue;
34
- target[key] = source[key];
35
- }
36
-
37
- return target;
38
- }
39
-
40
- function _unsupportedIterableToArray(o, minLen) {
41
- if (!o) return;
42
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
43
- var n = Object.prototype.toString.call(o).slice(8, -1);
44
- if (n === "Object" && o.constructor) n = o.constructor.name;
45
- if (n === "Map" || n === "Set") return Array.from(o);
46
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
47
- }
48
-
49
- function _arrayLikeToArray(arr, len) {
50
- if (len == null || len > arr.length) len = arr.length;
51
-
52
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
53
-
54
- return arr2;
55
- }
56
-
57
- function _createForOfIteratorHelperLoose(o, allowArrayLike) {
58
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
59
- if (it) return (it = it.call(o)).next.bind(it);
60
-
61
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
62
- if (it) o = it;
63
- var i = 0;
64
- return function () {
65
- if (i >= o.length) return {
66
- done: true
67
- };
68
- return {
69
- done: false,
70
- value: o[i++]
71
- };
72
- };
73
- }
74
-
75
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
76
- }
77
-
78
- var useIsomorphicLayoutEffect = typeof document !== 'undefined' ? useLayoutEffect : useEffect;
79
-
80
- var _CONSOLE_METHOD_MAP;
81
- var LogLevel;
82
-
83
- (function (LogLevel) {
84
- LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
85
- LogLevel[LogLevel["INFO"] = 1] = "INFO";
86
- LogLevel[LogLevel["WARN"] = 2] = "WARN";
87
- LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
88
- })(LogLevel || (LogLevel = {}));
89
-
90
- var CONSOLE_METHOD_MAP = (_CONSOLE_METHOD_MAP = {}, _CONSOLE_METHOD_MAP[LogLevel.DEBUG] = 'debug', _CONSOLE_METHOD_MAP[LogLevel.INFO] = 'log', _CONSOLE_METHOD_MAP[LogLevel.WARN] = 'warn', _CONSOLE_METHOD_MAP[LogLevel.ERROR] = 'error', _CONSOLE_METHOD_MAP);
91
-
92
- var getGlobalThis = function getGlobalThis() {
93
- return typeof globalThis === 'undefined' ? window : globalThis;
94
- };
95
-
96
- var loggerSystem = /*#__PURE__*/u.system(function () {
97
- var logLevel = u.statefulStream(LogLevel.ERROR);
98
- var log = u.statefulStream(function (label, message, level) {
99
- var _getGlobalThis$VIRTUO;
100
-
101
- if (level === void 0) {
102
- level = LogLevel.INFO;
103
- }
104
-
105
- var currentLevel = (_getGlobalThis$VIRTUO = getGlobalThis()['VIRTUOSO_LOG_LEVEL']) != null ? _getGlobalThis$VIRTUO : u.getValue(logLevel);
106
-
107
- if (level >= currentLevel) {
108
- // eslint-disable-next-line no-console
109
- console[CONSOLE_METHOD_MAP[level]]('%creact-virtuoso: %c%s %o', 'color: #0253b3; font-weight: bold', 'color: initial', label, message);
110
- }
111
- });
112
- return {
113
- log: log,
114
- logLevel: logLevel
115
- };
116
- }, [], {
117
- singleton: true
118
- });
119
-
120
- function useSizeWithElRef(callback, enabled) {
121
- if (enabled === void 0) {
122
- enabled = true;
123
- }
124
-
125
- var ref = useRef(null);
126
-
127
- var callbackRef = function callbackRef(_el) {
128
- };
129
-
130
- if (typeof ResizeObserver !== 'undefined') {
131
- var observer = new ResizeObserver(function (entries) {
132
- var element = entries[0].target;
133
-
134
- if (element.offsetParent !== null) {
135
- callback(element);
136
- }
137
- });
138
-
139
- callbackRef = function callbackRef(elRef) {
140
- if (elRef && enabled) {
141
- observer.observe(elRef);
142
- ref.current = elRef;
143
- } else {
144
- if (ref.current) {
145
- observer.unobserve(ref.current);
146
- }
147
-
148
- ref.current = null;
149
- }
150
- };
151
- }
152
-
153
- return {
154
- ref: ref,
155
- callbackRef: callbackRef
156
- };
157
- }
158
- function useSize(callback, enabled) {
159
- if (enabled === void 0) {
160
- enabled = true;
161
- }
162
-
163
- return useSizeWithElRef(callback, enabled).callbackRef;
164
- }
165
-
166
- function useChangedListContentsSizes(callback, itemSize, enabled, scrollContainerStateCallback, log, customScrollParent) {
167
- return useSize(function (el) {
168
- var ranges = getChangedChildSizes(el.children, itemSize, 'offsetHeight', log);
169
- var scrollableElement = el.parentElement;
170
-
171
- while (!scrollableElement.dataset['virtuosoScroller']) {
172
- scrollableElement = scrollableElement.parentElement;
173
- }
174
-
175
- var scrollTop = customScrollParent ? customScrollParent.scrollTop : // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
176
- scrollableElement.firstElementChild.dataset['viewportType'] === 'window' ? window.pageYOffset || document.documentElement.scrollTop : scrollableElement.scrollTop;
177
- customScrollParent ? scrollContainerStateCallback([Math.max(scrollTop, 0), customScrollParent.scrollHeight]) : scrollContainerStateCallback([Math.max(scrollTop, 0), scrollableElement.scrollHeight]);
178
-
179
- if (ranges !== null) {
180
- callback(ranges);
181
- }
182
- }, enabled);
183
- }
184
-
185
- function getChangedChildSizes(children, itemSize, field, log) {
186
- var length = children.length;
187
-
188
- if (length === 0) {
189
- return null;
190
- }
191
-
192
- var results = [];
193
-
194
- for (var i = 0; i < length; i++) {
195
- var child = children.item(i);
196
-
197
- if (!child || child.dataset.index === undefined) {
198
- continue;
199
- }
200
-
201
- var index = parseInt(child.dataset.index);
202
- var knownSize = parseFloat(child.dataset.knownSize);
203
- var size = itemSize(child, field);
204
-
205
- if (size === 0) {
206
- log('Zero-sized element, this should not happen', {
207
- child: child
208
- }, LogLevel.ERROR);
209
- }
210
-
211
- if (size === knownSize) {
212
- continue;
213
- }
214
-
215
- var lastResult = results[results.length - 1];
216
-
217
- if (results.length === 0 || lastResult.size !== size || lastResult.endIndex !== index - 1) {
218
- results.push({
219
- startIndex: index,
220
- endIndex: index,
221
- size: size
222
- });
223
- } else {
224
- results[results.length - 1].endIndex++;
225
- }
226
- }
227
-
228
- return results;
229
- }
230
-
231
- function correctItemSize(el, dimension) {
232
- return Math.round(el.getBoundingClientRect()[dimension]);
233
- }
234
-
235
- function approximatelyEqual(num1, num2) {
236
- return Math.abs(num1 - num2) < 1.01;
237
- }
238
-
239
- function useScrollTop(scrollContainerStateCallback, smoothScrollTargetReached, scrollerElement, scrollerRefCallback, customScrollParent) {
240
- if (scrollerRefCallback === void 0) {
241
- scrollerRefCallback = u.noop;
242
- }
243
-
244
- var scrollerRef = useRef(null);
245
- var scrollTopTarget = useRef(null);
246
- var timeoutRef = useRef(null);
247
- var handler = useCallback(function (ev) {
248
- var el = ev.target;
249
- var scrollTop = el === window || el === document ? window.pageYOffset || document.documentElement.scrollTop : el.scrollTop;
250
- var scrollHeight = el === window ? document.documentElement.scrollHeight : el.scrollHeight;
251
- scrollContainerStateCallback([Math.max(scrollTop, 0), scrollHeight]);
252
-
253
- if (scrollTopTarget.current !== null) {
254
- if (scrollTop === scrollTopTarget.current || scrollTop <= 0 || scrollTop === el.scrollHeight - correctItemSize(el, 'height')) {
255
- scrollTopTarget.current = null;
256
- smoothScrollTargetReached(true);
257
-
258
- if (timeoutRef.current) {
259
- clearTimeout(timeoutRef.current);
260
- timeoutRef.current = null;
261
- }
262
- }
263
- }
264
- }, [scrollContainerStateCallback, smoothScrollTargetReached]);
265
- useEffect(function () {
266
- var localRef = customScrollParent ? customScrollParent : scrollerRef.current;
267
- scrollerRefCallback(customScrollParent ? customScrollParent : scrollerRef.current);
268
- handler({
269
- target: localRef
270
- });
271
- localRef.addEventListener('scroll', handler, {
272
- passive: true
273
- });
274
- return function () {
275
- scrollerRefCallback(null);
276
- localRef.removeEventListener('scroll', handler);
277
- };
278
- }, [scrollerRef, handler, scrollerElement, scrollerRefCallback, customScrollParent]);
279
-
280
- function scrollToCallback(location) {
281
- var scrollerElement = scrollerRef.current;
282
-
283
- if (!scrollerElement || 'offsetHeight' in scrollerElement && scrollerElement.offsetHeight === 0) {
284
- return;
285
- }
286
-
287
- var isSmooth = location.behavior === 'smooth';
288
- var offsetHeight;
289
- var scrollHeight;
290
- var scrollTop;
291
-
292
- if (scrollerElement === window) {
293
- // this is not a mistake
294
- scrollHeight = Math.max(correctItemSize(document.documentElement, 'height'), document.documentElement.scrollHeight);
295
- offsetHeight = window.innerHeight;
296
- scrollTop = document.documentElement.scrollTop;
297
- } else {
298
- scrollHeight = scrollerElement.scrollHeight;
299
- offsetHeight = correctItemSize(scrollerElement, 'height');
300
- scrollTop = scrollerElement.scrollTop;
301
- }
302
-
303
- var maxScrollTop = scrollHeight - offsetHeight;
304
- location.top = Math.ceil(Math.max(Math.min(maxScrollTop, location.top), 0)); // avoid system hanging because the DOM never called back
305
- // with the scrollTop
306
- // scroller is already at this location
307
-
308
- if (approximatelyEqual(offsetHeight, scrollHeight) || location.top === scrollTop) {
309
- scrollContainerStateCallback([scrollTop, scrollHeight]);
310
-
311
- if (isSmooth) {
312
- smoothScrollTargetReached(true);
313
- }
314
-
315
- return;
316
- }
317
-
318
- if (isSmooth) {
319
- scrollTopTarget.current = location.top;
320
-
321
- if (timeoutRef.current) {
322
- clearTimeout(timeoutRef.current);
323
- }
324
-
325
- timeoutRef.current = setTimeout(function () {
326
- timeoutRef.current = null;
327
- scrollTopTarget.current = null;
328
- smoothScrollTargetReached(true);
329
- }, 1000);
330
- } else {
331
- scrollTopTarget.current = null;
332
- }
333
-
334
- scrollerElement.scrollTo(location);
335
- }
336
-
337
- function scrollByCallback(location) {
338
- if (scrollTopTarget.current === null) {
339
- scrollerRef.current.scrollBy(location);
340
- }
341
- }
342
-
343
- return {
344
- scrollerRef: scrollerRef,
345
- scrollByCallback: scrollByCallback,
346
- scrollToCallback: scrollToCallback
347
- };
348
- }
349
-
350
- var domIOSystem = /*#__PURE__*/u.system(function () {
351
- var scrollContainerState = u.stream();
352
- var scrollTop = u.stream();
353
- var deviation = u.statefulStream(0);
354
- var smoothScrollTargetReached = u.stream();
355
- var statefulScrollTop = u.statefulStream(0);
356
- var viewportHeight = u.stream();
357
- var scrollHeight = u.stream();
358
- var headerHeight = u.statefulStream(0);
359
- var footerHeight = u.statefulStream(0);
360
- var scrollTo = u.stream();
361
- var scrollBy = u.stream();
362
- var scrollingInProgress = u.statefulStream(false);
363
- u.connect(u.pipe(scrollContainerState, u.map(function (_ref) {
364
- var scrollTop = _ref[0];
365
- return scrollTop;
366
- })), scrollTop);
367
- u.connect(u.pipe(scrollContainerState, u.map(function (_ref2) {
368
- var scrollHeight = _ref2[1];
369
- return scrollHeight;
370
- })), scrollHeight);
371
- u.connect(scrollTop, statefulScrollTop);
372
- return {
373
- // input
374
- scrollContainerState: scrollContainerState,
375
- scrollTop: scrollTop,
376
- viewportHeight: viewportHeight,
377
- headerHeight: headerHeight,
378
- footerHeight: footerHeight,
379
- scrollHeight: scrollHeight,
380
- smoothScrollTargetReached: smoothScrollTargetReached,
381
- // signals
382
- scrollTo: scrollTo,
383
- scrollBy: scrollBy,
384
- // state
385
- statefulScrollTop: statefulScrollTop,
386
- deviation: deviation,
387
- scrollingInProgress: scrollingInProgress
388
- };
389
- }, [], {
390
- singleton: true
391
- });
392
-
393
- var NIL_NODE = {
394
- lvl: 0
395
- };
396
-
397
- function newAANode(k, v, lvl, l, r) {
398
- if (l === void 0) {
399
- l = NIL_NODE;
400
- }
401
-
402
- if (r === void 0) {
403
- r = NIL_NODE;
404
- }
405
-
406
- return {
407
- k: k,
408
- v: v,
409
- lvl: lvl,
410
- l: l,
411
- r: r
412
- };
413
- }
414
-
415
- function empty(node) {
416
- return node === NIL_NODE;
417
- }
418
- function newTree() {
419
- return NIL_NODE;
420
- }
421
- function remove(node, key) {
422
- if (empty(node)) return NIL_NODE;
423
- var k = node.k,
424
- l = node.l,
425
- r = node.r;
426
-
427
- if (key === k) {
428
- if (empty(l)) {
429
- return r;
430
- } else if (empty(r)) {
431
- return l;
432
- } else {
433
- var _last = last(l),
434
- lastKey = _last[0],
435
- lastValue = _last[1];
436
-
437
- return adjust(clone(node, {
438
- k: lastKey,
439
- v: lastValue,
440
- l: deleteLast(l)
441
- }));
442
- }
443
- } else if (key < k) {
444
- return adjust(clone(node, {
445
- l: remove(l, key)
446
- }));
447
- } else {
448
- return adjust(clone(node, {
449
- r: remove(r, key)
450
- }));
451
- }
452
- }
453
- function findMaxKeyValue(node, value, field) {
454
- if (field === void 0) {
455
- field = 'k';
456
- }
457
-
458
- if (empty(node)) {
459
- return [-Infinity, undefined];
460
- }
461
-
462
- if (node[field] === value) {
463
- return [node.k, node.v];
464
- }
465
-
466
- if (node[field] < value) {
467
- var r = findMaxKeyValue(node.r, value, field);
468
-
469
- if (r[0] === -Infinity) {
470
- return [node.k, node.v];
471
- } else {
472
- return r;
473
- }
474
- }
475
-
476
- return findMaxKeyValue(node.l, value, field);
477
- }
478
- function insert(node, k, v) {
479
- if (empty(node)) {
480
- return newAANode(k, v, 1);
481
- }
482
-
483
- if (k === node.k) {
484
- return clone(node, {
485
- k: k,
486
- v: v
487
- });
488
- } else if (k < node.k) {
489
- return rebalance(clone(node, {
490
- l: insert(node.l, k, v)
491
- }));
492
- } else {
493
- return rebalance(clone(node, {
494
- r: insert(node.r, k, v)
495
- }));
496
- }
497
- }
498
- function walkWithin(node, start, end) {
499
- if (empty(node)) {
500
- return [];
501
- }
502
-
503
- var k = node.k,
504
- v = node.v,
505
- l = node.l,
506
- r = node.r;
507
- var result = [];
508
-
509
- if (k > start) {
510
- result = result.concat(walkWithin(l, start, end));
511
- }
512
-
513
- if (k >= start && k <= end) {
514
- result.push({
515
- k: k,
516
- v: v
517
- });
518
- }
519
-
520
- if (k <= end) {
521
- result = result.concat(walkWithin(r, start, end));
522
- }
523
-
524
- return result;
525
- }
526
- function walk(node) {
527
- if (empty(node)) {
528
- return [];
529
- }
530
-
531
- return [].concat(walk(node.l), [{
532
- k: node.k,
533
- v: node.v
534
- }], walk(node.r));
535
- }
536
-
537
- function last(node) {
538
- return empty(node.r) ? [node.k, node.v] : last(node.r);
539
- }
540
-
541
- function deleteLast(node) {
542
- return empty(node.r) ? node.l : adjust(clone(node, {
543
- r: deleteLast(node.r)
544
- }));
545
- }
546
-
547
- function clone(node, args) {
548
- return newAANode(args.k !== undefined ? args.k : node.k, args.v !== undefined ? args.v : node.v, args.lvl !== undefined ? args.lvl : node.lvl, args.l !== undefined ? args.l : node.l, args.r !== undefined ? args.r : node.r);
549
- }
550
-
551
- function isSingle(node) {
552
- return empty(node) || node.lvl > node.r.lvl;
553
- }
554
-
555
- function rebalance(node) {
556
- return split(skew(node));
557
- }
558
-
559
- function adjust(node) {
560
- var l = node.l,
561
- r = node.r,
562
- lvl = node.lvl;
563
-
564
- if (r.lvl >= lvl - 1 && l.lvl >= lvl - 1) {
565
- return node;
566
- } else if (lvl > r.lvl + 1) {
567
- if (isSingle(l)) {
568
- return skew(clone(node, {
569
- lvl: lvl - 1
570
- }));
571
- } else {
572
- if (!empty(l) && !empty(l.r)) {
573
- return clone(l.r, {
574
- l: clone(l, {
575
- r: l.r.l
576
- }),
577
- r: clone(node, {
578
- l: l.r.r,
579
- lvl: lvl - 1
580
- }),
581
- lvl: lvl
582
- });
583
- } else {
584
- throw new Error('Unexpected empty nodes');
585
- }
586
- }
587
- } else {
588
- if (isSingle(node)) {
589
- return split(clone(node, {
590
- lvl: lvl - 1
591
- }));
592
- } else {
593
- if (!empty(r) && !empty(r.l)) {
594
- var rl = r.l;
595
- var rlvl = isSingle(rl) ? r.lvl - 1 : r.lvl;
596
- return clone(rl, {
597
- l: clone(node, {
598
- r: rl.l,
599
- lvl: lvl - 1
600
- }),
601
- r: split(clone(r, {
602
- l: rl.r,
603
- lvl: rlvl
604
- })),
605
- lvl: rl.lvl + 1
606
- });
607
- } else {
608
- throw new Error('Unexpected empty nodes');
609
- }
610
- }
611
- }
612
- }
613
- function rangesWithin(node, startIndex, endIndex) {
614
- if (empty(node)) {
615
- return [];
616
- }
617
-
618
- var adjustedStart = findMaxKeyValue(node, startIndex)[0];
619
- return toRanges(walkWithin(node, adjustedStart, endIndex));
620
- }
621
- function arrayToRanges(items, parser) {
622
- var length = items.length;
623
-
624
- if (length === 0) {
625
- return [];
626
- }
627
-
628
- var _parser = parser(items[0]),
629
- start = _parser.index,
630
- value = _parser.value;
631
-
632
- var result = [];
633
-
634
- for (var i = 1; i < length; i++) {
635
- var _parser2 = parser(items[i]),
636
- nextIndex = _parser2.index,
637
- nextValue = _parser2.value;
638
-
639
- result.push({
640
- start: start,
641
- end: nextIndex - 1,
642
- value: value
643
- });
644
- start = nextIndex;
645
- value = nextValue;
646
- }
647
-
648
- result.push({
649
- start: start,
650
- end: Infinity,
651
- value: value
652
- });
653
- return result;
654
- }
655
-
656
- function toRanges(nodes) {
657
- return arrayToRanges(nodes, function (_ref) {
658
- var index = _ref.k,
659
- value = _ref.v;
660
- return {
661
- index: index,
662
- value: value
663
- };
664
- });
665
- }
666
-
667
- function split(node) {
668
- var r = node.r,
669
- lvl = node.lvl;
670
- return !empty(r) && !empty(r.r) && r.lvl === lvl && r.r.lvl === lvl ? clone(r, {
671
- l: clone(node, {
672
- r: r.l
673
- }),
674
- lvl: lvl + 1
675
- }) : node;
676
- }
677
-
678
- function skew(node) {
679
- var l = node.l;
680
- return !empty(l) && l.lvl === node.lvl ? clone(l, {
681
- r: clone(node, {
682
- l: l.r
683
- })
684
- }) : node;
685
- }
686
-
687
- function findIndexOfClosestSmallerOrEqual(items, value, comparator, start) {
688
- if (start === void 0) {
689
- start = 0;
690
- }
691
-
692
- var end = items.length - 1;
693
-
694
- while (start <= end) {
695
- var index = Math.floor((start + end) / 2);
696
- var item = items[index];
697
- var match = comparator(item, value);
698
-
699
- if (match === 0) {
700
- return index;
701
- }
702
-
703
- if (match === -1) {
704
- if (end - start < 2) {
705
- return index - 1;
706
- }
707
-
708
- end = index - 1;
709
- } else {
710
- if (end === start) {
711
- return index;
712
- }
713
-
714
- start = index + 1;
715
- }
716
- }
717
-
718
- throw new Error("Failed binary finding record in array - " + items.join(',') + ", searched for " + value);
719
- }
720
- function findClosestSmallerOrEqual(items, value, comparator) {
721
- return items[findIndexOfClosestSmallerOrEqual(items, value, comparator)];
722
- }
723
- function findRange(items, startValue, endValue, comparator) {
724
- var startIndex = findIndexOfClosestSmallerOrEqual(items, startValue, comparator);
725
- var endIndex = findIndexOfClosestSmallerOrEqual(items, endValue, comparator, startIndex);
726
- return items.slice(startIndex, endIndex + 1);
727
- }
728
-
729
- function rangeIncludes(refRange) {
730
- var size = refRange.size,
731
- startIndex = refRange.startIndex,
732
- endIndex = refRange.endIndex;
733
- return function (range) {
734
- return range.start === startIndex && (range.end === endIndex || range.end === Infinity) && range.value === size;
735
- };
736
- }
737
-
738
- function insertRanges(sizeTree, ranges) {
739
- var syncStart = empty(sizeTree) ? 0 : Infinity;
740
-
741
- for (var _iterator = _createForOfIteratorHelperLoose(ranges), _step; !(_step = _iterator()).done;) {
742
- var range = _step.value;
743
- var size = range.size,
744
- startIndex = range.startIndex,
745
- endIndex = range.endIndex;
746
- syncStart = Math.min(syncStart, startIndex);
747
-
748
- if (empty(sizeTree)) {
749
- sizeTree = insert(sizeTree, 0, size);
750
- continue;
751
- } // extend the range in both directions, so that we can get adjacent neighbours.
752
- // if the previous / next ones have the same value as the one we are about to insert,
753
- // we 'merge' them.
754
-
755
-
756
- var overlappingRanges = rangesWithin(sizeTree, startIndex - 1, endIndex + 1);
757
-
758
- if (overlappingRanges.some(rangeIncludes(range))) {
759
- continue;
760
- }
761
-
762
- var firstPassDone = false;
763
- var shouldInsert = false;
764
-
765
- for (var _iterator2 = _createForOfIteratorHelperLoose(overlappingRanges), _step2; !(_step2 = _iterator2()).done;) {
766
- var _step2$value = _step2.value,
767
- rangeStart = _step2$value.start,
768
- rangeEnd = _step2$value.end,
769
- rangeValue = _step2$value.value;
770
-
771
- // previous range
772
- if (!firstPassDone) {
773
- shouldInsert = rangeValue !== size;
774
- firstPassDone = true;
775
- } else {
776
- // remove the range if it starts within the new range OR if
777
- // it has the same value as it, in order to perform a merge
778
- if (endIndex >= rangeStart || size === rangeValue) {
779
- sizeTree = remove(sizeTree, rangeStart);
780
- }
781
- } // next range
782
-
783
-
784
- if (rangeEnd > endIndex && endIndex >= rangeStart) {
785
- if (rangeValue !== size) {
786
- sizeTree = insert(sizeTree, endIndex + 1, rangeValue);
787
- }
788
- }
789
- }
790
-
791
- if (shouldInsert) {
792
- sizeTree = insert(sizeTree, startIndex, size);
793
- }
794
- }
795
-
796
- return [sizeTree, syncStart];
797
- }
798
- function initialSizeState() {
799
- return {
800
- offsetTree: [],
801
- sizeTree: newTree(),
802
- groupOffsetTree: newTree(),
803
- lastIndex: 0,
804
- lastOffset: 0,
805
- lastSize: 0,
806
- groupIndices: []
807
- };
808
- }
809
- function indexComparator(_ref, index) {
810
- var itemIndex = _ref.index;
811
- return index === itemIndex ? 0 : index < itemIndex ? -1 : 1;
812
- }
813
- function offsetComparator(_ref2, offset) {
814
- var itemOffset = _ref2.offset;
815
- return offset === itemOffset ? 0 : offset < itemOffset ? -1 : 1;
816
- }
817
-
818
- function offsetPointParser(point) {
819
- return {
820
- index: point.index,
821
- value: point
822
- };
823
- }
824
-
825
- function rangesWithinOffsets(tree, startOffset, endOffset, minStartIndex) {
826
- if (minStartIndex === void 0) {
827
- minStartIndex = 0;
828
- }
829
-
830
- if (minStartIndex > 0) {
831
- startOffset = Math.max(startOffset, findClosestSmallerOrEqual(tree, minStartIndex, indexComparator).offset);
832
- }
833
-
834
- return arrayToRanges(findRange(tree, startOffset, endOffset, offsetComparator), offsetPointParser);
835
- }
836
- function sizeStateReducer(state, _ref3) {
837
- var ranges = _ref3[0],
838
- groupIndices = _ref3[1],
839
- log = _ref3[2];
840
-
841
- if (ranges.length > 0) {
842
- log('received item sizes', ranges, LogLevel.DEBUG);
843
- }
844
-
845
- var sizeTree = state.sizeTree;
846
- var offsetTree = state.offsetTree;
847
- var newSizeTree = sizeTree;
848
- var syncStart = 0; // We receive probe item results from a group probe,
849
- // which should always pass an item and a group
850
- // the results contain two ranges, which we consider to mean that groups and items have different size
851
-
852
- if (groupIndices.length > 0 && empty(sizeTree) && ranges.length === 2) {
853
- var groupSize = ranges[0].size;
854
- var itemSize = ranges[1].size;
855
- newSizeTree = groupIndices.reduce(function (tree, groupIndex) {
856
- return insert(insert(tree, groupIndex, groupSize), groupIndex + 1, itemSize);
857
- }, newSizeTree);
858
- } else {
859
-
860
- var _insertRanges = insertRanges(newSizeTree, ranges);
861
-
862
- newSizeTree = _insertRanges[0];
863
- syncStart = _insertRanges[1];
864
- }
865
-
866
- if (newSizeTree === sizeTree) {
867
- return state;
868
- }
869
-
870
- var prevIndex = 0;
871
- var prevSize = 0;
872
- var prevAOffset = 0;
873
- var startAIndex = 0;
874
-
875
- if (syncStart !== 0) {
876
- startAIndex = findIndexOfClosestSmallerOrEqual(offsetTree, syncStart - 1, indexComparator);
877
- var offsetInfo = offsetTree[startAIndex];
878
- prevAOffset = offsetInfo.offset;
879
- var kv = findMaxKeyValue(newSizeTree, syncStart - 1);
880
- prevIndex = kv[0];
881
- prevSize = kv[1];
882
-
883
- if (offsetTree.length && offsetTree[startAIndex].size === findMaxKeyValue(newSizeTree, syncStart)[1]) {
884
- startAIndex -= 1;
885
- }
886
-
887
- offsetTree = offsetTree.slice(0, startAIndex + 1);
888
- } else {
889
- offsetTree = [];
890
- }
891
-
892
- for (var _iterator3 = _createForOfIteratorHelperLoose(rangesWithin(newSizeTree, syncStart, Infinity)), _step3; !(_step3 = _iterator3()).done;) {
893
- var _step3$value = _step3.value,
894
- startIndex = _step3$value.start,
895
- value = _step3$value.value;
896
- var aOffset = (startIndex - prevIndex) * prevSize + prevAOffset;
897
- offsetTree.push({
898
- offset: aOffset,
899
- size: value,
900
- index: startIndex
901
- });
902
- prevIndex = startIndex;
903
- prevAOffset = aOffset;
904
- prevSize = value;
905
- }
906
-
907
- return {
908
- sizeTree: newSizeTree,
909
- offsetTree: offsetTree,
910
- groupOffsetTree: groupIndices.reduce(function (tree, index) {
911
- return insert(tree, index, offsetOf(index, offsetTree));
912
- }, newTree()),
913
- lastIndex: prevIndex,
914
- lastOffset: prevAOffset,
915
- lastSize: prevSize,
916
- groupIndices: groupIndices
917
- };
918
- }
919
- function offsetOf(index, tree) {
920
- if (tree.length === 0) {
921
- return 0;
922
- }
923
-
924
- var _arrayBinarySearch$fi = findClosestSmallerOrEqual(tree, index, indexComparator),
925
- offset = _arrayBinarySearch$fi.offset,
926
- startIndex = _arrayBinarySearch$fi.index,
927
- size = _arrayBinarySearch$fi.size;
928
-
929
- return size * (index - startIndex) + offset;
930
- }
931
- function originalIndexFromItemIndex(itemIndex, sizes) {
932
- if (!hasGroups(sizes)) {
933
- return itemIndex;
934
- }
935
-
936
- var groupOffset = 0;
937
-
938
- while (sizes.groupIndices[groupOffset] <= itemIndex + groupOffset) {
939
- groupOffset++;
940
- } // we find the real item index, offsetting it by the number of group items before it
941
-
942
-
943
- return itemIndex + groupOffset;
944
- }
945
- function hasGroups(sizes) {
946
- return !empty(sizes.groupOffsetTree);
947
- }
948
- var SIZE_MAP = {
949
- offsetHeight: 'height',
950
- offsetWidth: 'width'
951
- };
952
- var sizeSystem = /*#__PURE__*/u.system(function (_ref4) {
953
- var log = _ref4[0].log;
954
- var sizeRanges = u.stream();
955
- var totalCount = u.stream();
956
- var statefulTotalCount = u.statefulStreamFromEmitter(totalCount, 0);
957
- var unshiftWith = u.stream();
958
- var firstItemIndex = u.statefulStream(0);
959
- var groupIndices = u.statefulStream([]);
960
- var fixedItemSize = u.statefulStream(undefined);
961
- var defaultItemSize = u.statefulStream(undefined);
962
- var itemSize = u.statefulStream(function (el, field) {
963
- return correctItemSize(el, SIZE_MAP[field]);
964
- });
965
- var data = u.statefulStream(undefined);
966
- var initial = initialSizeState();
967
- var sizes = u.statefulStreamFromEmitter(u.pipe(sizeRanges, u.withLatestFrom(groupIndices, log), u.scan(sizeStateReducer, initial), u.distinctUntilChanged()), initial);
968
- u.connect(u.pipe(groupIndices, u.filter(function (indexes) {
969
- return indexes.length > 0;
970
- }), u.withLatestFrom(sizes), u.map(function (_ref5) {
971
- var groupIndices = _ref5[0],
972
- sizes = _ref5[1];
973
- var groupOffsetTree = groupIndices.reduce(function (tree, index, idx) {
974
- return insert(tree, index, offsetOf(index, sizes.offsetTree) || idx);
975
- }, newTree());
976
- return _extends({}, sizes, {
977
- groupIndices: groupIndices,
978
- groupOffsetTree: groupOffsetTree
979
- });
980
- })), sizes); // decreasing the total count should remove any existing entries
981
- // beyond the last index - do this by publishing the default size as a range over them.
982
-
983
- u.connect(u.pipe(totalCount, u.withLatestFrom(sizes), u.filter(function (_ref6) {
984
- var totalCount = _ref6[0],
985
- lastIndex = _ref6[1].lastIndex;
986
- return totalCount < lastIndex;
987
- }), u.map(function (_ref7) {
988
- var totalCount = _ref7[0],
989
- _ref7$ = _ref7[1],
990
- lastIndex = _ref7$.lastIndex,
991
- lastSize = _ref7$.lastSize;
992
- return [{
993
- startIndex: totalCount,
994
- endIndex: lastIndex,
995
- size: lastSize
996
- }];
997
- })), sizeRanges);
998
- u.connect(fixedItemSize, defaultItemSize);
999
- var trackItemSizes = u.statefulStreamFromEmitter(u.pipe(fixedItemSize, u.map(function (size) {
1000
- return size === undefined;
1001
- })), true);
1002
- u.connect(u.pipe(defaultItemSize, u.filter(function (value) {
1003
- return value !== undefined && empty(u.getValue(sizes).sizeTree);
1004
- }), u.map(function (size) {
1005
- return [{
1006
- startIndex: 0,
1007
- endIndex: 0,
1008
- size: size
1009
- }];
1010
- })), sizeRanges);
1011
- var listRefresh = u.streamFromEmitter(u.pipe(sizeRanges, u.withLatestFrom(sizes), u.scan(function (_ref8, _ref9) {
1012
- var oldSizes = _ref8.sizes;
1013
- var newSizes = _ref9[1];
1014
- return {
1015
- changed: newSizes !== oldSizes,
1016
- sizes: newSizes
1017
- };
1018
- }, {
1019
- changed: false,
1020
- sizes: initial
1021
- }), u.map(function (value) {
1022
- return value.changed;
1023
- })));
1024
- u.connect(u.pipe(firstItemIndex, u.scan(function (prev, next) {
1025
- return {
1026
- diff: prev.prev - next,
1027
- prev: next
1028
- };
1029
- }, {
1030
- diff: 0,
1031
- prev: 0
1032
- }), u.map(function (val) {
1033
- return val.diff;
1034
- }), u.filter(function (value) {
1035
- return value > 0;
1036
- })), unshiftWith);
1037
- u.subscribe(u.pipe(firstItemIndex, u.withLatestFrom(log)), function (_ref10) {
1038
- var index = _ref10[0],
1039
- log = _ref10[1];
1040
-
1041
- if (index < 0) {
1042
- log("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value", {
1043
- firstItemIndex: firstItemIndex
1044
- }, LogLevel.ERROR);
1045
- }
1046
- }); // Capture the current list top item before the sizes get refreshed
1047
-
1048
- var beforeUnshiftWith = u.streamFromEmitter(unshiftWith);
1049
- u.connect(u.pipe(unshiftWith, u.withLatestFrom(sizes), u.map(function (_ref11) {
1050
- var unshiftWith = _ref11[0],
1051
- sizes = _ref11[1];
1052
-
1053
- if (sizes.groupIndices.length > 0) {
1054
- throw new Error('Virtuoso: prepending items does not work with groups');
1055
- }
1056
-
1057
- return walk(sizes.sizeTree).reduce(function (acc, _ref12) {
1058
- var index = _ref12.k,
1059
- size = _ref12.v;
1060
- return {
1061
- ranges: [].concat(acc.ranges, [{
1062
- startIndex: acc.prevIndex,
1063
- endIndex: index + unshiftWith - 1,
1064
- size: acc.prevSize
1065
- }]),
1066
- prevIndex: index + unshiftWith,
1067
- prevSize: size
1068
- };
1069
- }, {
1070
- ranges: [],
1071
- prevIndex: 0,
1072
- prevSize: sizes.lastSize
1073
- }).ranges;
1074
- })), sizeRanges);
1075
- return {
1076
- // input
1077
- data: data,
1078
- totalCount: totalCount,
1079
- sizeRanges: sizeRanges,
1080
- groupIndices: groupIndices,
1081
- defaultItemSize: defaultItemSize,
1082
- fixedItemSize: fixedItemSize,
1083
- unshiftWith: unshiftWith,
1084
- beforeUnshiftWith: beforeUnshiftWith,
1085
- firstItemIndex: firstItemIndex,
1086
- // output
1087
- sizes: sizes,
1088
- listRefresh: listRefresh,
1089
- statefulTotalCount: statefulTotalCount,
1090
- trackItemSizes: trackItemSizes,
1091
- itemSize: itemSize
1092
- };
1093
- }, /*#__PURE__*/u.tup(loggerSystem), {
1094
- singleton: true
1095
- });
1096
-
1097
- /* eslint-disable @typescript-eslint/no-unsafe-call */
1098
- var SUPPORTS_SCROLL_TO_OPTIONS = typeof document !== 'undefined' && 'scrollBehavior' in document.documentElement.style;
1099
- function normalizeIndexLocation(location) {
1100
- var result = typeof location === 'number' ? {
1101
- index: location
1102
- } : location;
1103
-
1104
- if (!result.align) {
1105
- result.align = 'start';
1106
- }
1107
-
1108
- if (!result.behavior || !SUPPORTS_SCROLL_TO_OPTIONS) {
1109
- result.behavior = 'auto';
1110
- }
1111
-
1112
- if (!result.offset) {
1113
- result.offset = 0;
1114
- }
1115
-
1116
- return result;
1117
- }
1118
- var scrollToIndexSystem = /*#__PURE__*/u.system(function (_ref) {
1119
- var _ref$ = _ref[0],
1120
- sizes = _ref$.sizes,
1121
- totalCount = _ref$.totalCount,
1122
- listRefresh = _ref$.listRefresh,
1123
- _ref$2 = _ref[1],
1124
- scrollingInProgress = _ref$2.scrollingInProgress,
1125
- viewportHeight = _ref$2.viewportHeight,
1126
- scrollTo = _ref$2.scrollTo,
1127
- smoothScrollTargetReached = _ref$2.smoothScrollTargetReached,
1128
- headerHeight = _ref$2.headerHeight,
1129
- footerHeight = _ref$2.footerHeight,
1130
- log = _ref[2].log;
1131
- var scrollToIndex = u.stream();
1132
- var topListHeight = u.statefulStream(0);
1133
- var unsubscribeNextListRefresh = null;
1134
- var cleartTimeoutRef = null;
1135
- var unsubscribeListRefresh = null;
1136
-
1137
- function cleanup() {
1138
- if (unsubscribeNextListRefresh) {
1139
- unsubscribeNextListRefresh();
1140
- unsubscribeNextListRefresh = null;
1141
- }
1142
-
1143
- if (unsubscribeListRefresh) {
1144
- unsubscribeListRefresh();
1145
- unsubscribeListRefresh = null;
1146
- }
1147
-
1148
- if (cleartTimeoutRef) {
1149
- clearTimeout(cleartTimeoutRef);
1150
- cleartTimeoutRef = null;
1151
- }
1152
-
1153
- u.publish(scrollingInProgress, false);
1154
- }
1155
-
1156
- u.connect(u.pipe(scrollToIndex, u.withLatestFrom(sizes, viewportHeight, totalCount, topListHeight, headerHeight, footerHeight, log), u.map(function (_ref2) {
1157
- var location = _ref2[0],
1158
- sizes = _ref2[1],
1159
- viewportHeight = _ref2[2],
1160
- totalCount = _ref2[3],
1161
- topListHeight = _ref2[4],
1162
- headerHeight = _ref2[5],
1163
- footerHeight = _ref2[6],
1164
- log = _ref2[7];
1165
- var normalLocation = normalizeIndexLocation(location);
1166
- var align = normalLocation.align,
1167
- behavior = normalLocation.behavior,
1168
- offset = normalLocation.offset;
1169
- var lastIndex = totalCount - 1;
1170
- var index = normalLocation.index;
1171
-
1172
- if (index === 'LAST') {
1173
- index = lastIndex;
1174
- }
1175
-
1176
- index = originalIndexFromItemIndex(index, sizes);
1177
- index = Math.max(0, index, Math.min(lastIndex, index));
1178
- var top = offsetOf(index, sizes.offsetTree) + headerHeight;
1179
-
1180
- if (align === 'end') {
1181
- top = top - viewportHeight + findMaxKeyValue(sizes.sizeTree, index)[1];
1182
-
1183
- if (index === lastIndex) {
1184
- top += footerHeight;
1185
- }
1186
- } else if (align === 'center') {
1187
- top = top - viewportHeight / 2 + findMaxKeyValue(sizes.sizeTree, index)[1] / 2;
1188
- } else {
1189
- top -= topListHeight;
1190
- }
1191
-
1192
- if (offset) {
1193
- top += offset;
1194
- }
1195
-
1196
- var retry = function retry(listChanged) {
1197
- cleanup();
1198
-
1199
- if (listChanged) {
1200
- log('retrying to scroll to', {
1201
- location: location
1202
- }, LogLevel.DEBUG);
1203
- u.publish(scrollToIndex, location);
1204
- } else {
1205
- log('list did not change, scroll successful', {}, LogLevel.DEBUG);
1206
- }
1207
- };
1208
-
1209
- cleanup();
1210
-
1211
- if (behavior === 'smooth') {
1212
- var listChanged = false;
1213
- unsubscribeListRefresh = u.subscribe(listRefresh, function (changed) {
1214
- listChanged = listChanged || changed;
1215
- });
1216
- unsubscribeNextListRefresh = u.handleNext(smoothScrollTargetReached, function () {
1217
- retry(listChanged);
1218
- });
1219
- } else {
1220
- unsubscribeNextListRefresh = u.handleNext(u.pipe(listRefresh, watchChangesFor(50)), retry);
1221
- } // if the scroll jump is too small, the list won't get rerendered.
1222
- // clean this listener
1223
-
1224
-
1225
- cleartTimeoutRef = setTimeout(function () {
1226
- cleanup();
1227
- }, 1200);
1228
- u.publish(scrollingInProgress, true);
1229
- log('scrolling from index to', {
1230
- index: index,
1231
- top: top,
1232
- behavior: behavior
1233
- }, LogLevel.DEBUG);
1234
- return {
1235
- top: top,
1236
- behavior: behavior
1237
- };
1238
- })), scrollTo);
1239
- return {
1240
- scrollToIndex: scrollToIndex,
1241
- topListHeight: topListHeight
1242
- };
1243
- }, /*#__PURE__*/u.tup(sizeSystem, domIOSystem, loggerSystem), {
1244
- singleton: true
1245
- });
1246
-
1247
- function watchChangesFor(limit) {
1248
- return function (done) {
1249
- var timeoutRef = setTimeout(function () {
1250
- done(false);
1251
- }, limit);
1252
- return function (value) {
1253
- if (value) {
1254
- done(true);
1255
- clearTimeout(timeoutRef);
1256
- }
1257
- };
1258
- };
1259
- }
1260
-
1261
- var UP = 'up';
1262
- var DOWN = 'down';
1263
- var NONE$1 = 'none';
1264
- var INITIAL_BOTTOM_STATE = {
1265
- atBottom: false,
1266
- notAtBottomBecause: 'NOT_SHOWING_LAST_ITEM',
1267
- state: {
1268
- offsetBottom: 0,
1269
- scrollTop: 0,
1270
- viewportHeight: 0,
1271
- scrollHeight: 0
1272
- }
1273
- };
1274
- var stateFlagsSystem = /*#__PURE__*/u.system(function (_ref) {
1275
- var _ref$ = _ref[0],
1276
- scrollContainerState = _ref$.scrollContainerState,
1277
- scrollTop = _ref$.scrollTop,
1278
- viewportHeight = _ref$.viewportHeight,
1279
- headerHeight = _ref$.headerHeight,
1280
- footerHeight = _ref$.footerHeight,
1281
- scrollBy = _ref$.scrollBy;
1282
- var isAtBottom = u.statefulStream(false);
1283
- var isAtTop = u.statefulStream(true);
1284
- var atBottomStateChange = u.stream();
1285
- var atTopStateChange = u.stream();
1286
- var atBottomThreshold = u.statefulStream(4); // skip 1 to avoid an initial on/off flick
1287
-
1288
- var isScrolling = u.streamFromEmitter(u.pipe(u.merge(u.pipe(u.duc(scrollTop), u.skip(1), u.mapTo(true)), u.pipe(u.duc(scrollTop), u.skip(1), u.mapTo(false), u.debounceTime(100))), u.distinctUntilChanged()));
1289
- var isScrollingBy = u.statefulStreamFromEmitter(u.pipe(u.merge(u.pipe(scrollBy, u.mapTo(true)), u.pipe(scrollBy, u.mapTo(false), u.debounceTime(200))), u.distinctUntilChanged()), false); // u.subscribe(isScrollingBy, (isScrollingBy) => console.log({ isScrollingBy }))
1290
-
1291
- u.connect(u.pipe(u.duc(scrollTop), u.map(function (top) {
1292
- return top === 0;
1293
- }), u.distinctUntilChanged()), isAtTop);
1294
- u.connect(isAtTop, atTopStateChange);
1295
- var atBottomState = u.streamFromEmitter(u.pipe(u.combineLatest(scrollContainerState, u.duc(viewportHeight), u.duc(headerHeight), u.duc(footerHeight), u.duc(atBottomThreshold)), u.scan(function (current, _ref2) {
1296
- var _ref2$ = _ref2[0],
1297
- scrollTop = _ref2$[0],
1298
- scrollHeight = _ref2$[1],
1299
- viewportHeight = _ref2[1],
1300
- atBottomThreshold = _ref2[4];
1301
- var isAtBottom = scrollTop + viewportHeight - scrollHeight > -atBottomThreshold;
1302
- var state = {
1303
- viewportHeight: viewportHeight,
1304
- scrollTop: scrollTop,
1305
- scrollHeight: scrollHeight
1306
- };
1307
-
1308
- if (isAtBottom) {
1309
- var atBottomBecause;
1310
- var scrollTopDelta;
1311
-
1312
- if (scrollTop > current.state.scrollTop) {
1313
- atBottomBecause = 'SCROLLED_DOWN';
1314
- scrollTopDelta = current.state.scrollTop - scrollTop;
1315
- } else {
1316
- atBottomBecause = 'SIZE_DECREASED';
1317
- scrollTopDelta = current.state.scrollTop - scrollTop || current.scrollTopDelta;
1318
- }
1319
-
1320
- return {
1321
- atBottom: true,
1322
- state: state,
1323
- atBottomBecause: atBottomBecause,
1324
- scrollTopDelta: scrollTopDelta
1325
- };
1326
- }
1327
-
1328
- var notAtBottomBecause;
1329
-
1330
- if (state.scrollHeight > current.state.scrollHeight) {
1331
- notAtBottomBecause = 'SIZE_INCREASED';
1332
- } else if (viewportHeight < current.state.viewportHeight) {
1333
- notAtBottomBecause = 'VIEWPORT_HEIGHT_DECREASING';
1334
- } else if (scrollTop < current.state.scrollTop) {
1335
- notAtBottomBecause = 'SCROLLING_UPWARDS';
1336
- } else {
1337
- notAtBottomBecause = 'NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM';
1338
- }
1339
-
1340
- return {
1341
- atBottom: false,
1342
- notAtBottomBecause: notAtBottomBecause,
1343
- state: state
1344
- };
1345
- }, INITIAL_BOTTOM_STATE), u.distinctUntilChanged(function (prev, next) {
1346
- return prev && prev.atBottom === next.atBottom;
1347
- })));
1348
- var lastJumpDueToItemResize = u.statefulStreamFromEmitter(u.pipe(scrollContainerState, u.scan(function (current, _ref3) {
1349
- var scrollTop = _ref3[0],
1350
- scrollHeight = _ref3[1];
1351
-
1352
- if (current.scrollHeight !== scrollHeight) {
1353
- if (current.scrollTop !== scrollTop) {
1354
- return {
1355
- scrollHeight: scrollHeight,
1356
- scrollTop: scrollTop,
1357
- jump: current.scrollTop - scrollTop,
1358
- changed: true
1359
- };
1360
- } else {
1361
- return {
1362
- scrollHeight: scrollHeight,
1363
- scrollTop: scrollTop,
1364
- jump: 0,
1365
- changed: true
1366
- };
1367
- }
1368
- } else {
1369
- return {
1370
- scrollTop: scrollTop,
1371
- scrollHeight: scrollHeight,
1372
- jump: 0,
1373
- changed: false
1374
- };
1375
- }
1376
- }, {
1377
- scrollHeight: 0,
1378
- jump: 0,
1379
- scrollTop: 0,
1380
- changed: false
1381
- }), u.filter(function (value) {
1382
- return value.changed;
1383
- }), u.map(function (value) {
1384
- return value.jump;
1385
- })), 0);
1386
- u.connect(u.pipe(atBottomState, u.map(function (state) {
1387
- return state.atBottom;
1388
- })), isAtBottom);
1389
- u.subscribe(isAtBottom, function (value) {
1390
- setTimeout(function () {
1391
- return u.publish(atBottomStateChange, value);
1392
- });
1393
- });
1394
- var scrollDirection = u.statefulStream(DOWN);
1395
- u.subscribe(isAtBottom, function (value) {
1396
- setTimeout(function () {
1397
- u.publish(atBottomStateChange, value);
1398
- });
1399
- });
1400
- u.connect(u.pipe(scrollContainerState, u.map(function (_ref4) {
1401
- var scrollTop = _ref4[0];
1402
- return scrollTop;
1403
- }), u.distinctUntilChanged(), u.scan(function (acc, scrollTop) {
1404
- // if things change while compensating for items, ignore,
1405
- // but store the new scrollTop
1406
- if (u.getValue(isScrollingBy)) {
1407
- return {
1408
- direction: acc.direction,
1409
- prevScrollTop: scrollTop
1410
- };
1411
- }
1412
-
1413
- return {
1414
- direction: scrollTop < acc.prevScrollTop ? UP : DOWN,
1415
- prevScrollTop: scrollTop
1416
- };
1417
- }, {
1418
- direction: DOWN,
1419
- prevScrollTop: 0
1420
- }), u.map(function (value) {
1421
- return value.direction;
1422
- })), scrollDirection);
1423
- u.connect(u.pipe(scrollContainerState, u.throttleTime(50), u.mapTo(NONE$1)), scrollDirection);
1424
- u.connect(isAtBottom, atBottomStateChange);
1425
- var scrollVelocity = u.statefulStream(0);
1426
- u.connect(u.pipe(isScrolling, u.filter(function (value) {
1427
- return !value;
1428
- }), u.mapTo(0)), scrollVelocity);
1429
- u.connect(u.pipe(scrollTop, u.throttleTime(100), u.withLatestFrom(isScrolling), u.filter(function (_ref5) {
1430
- var isScrolling = _ref5[1];
1431
- return !!isScrolling;
1432
- }), u.scan(function (_ref6, _ref7) {
1433
- var prev = _ref6[1];
1434
- var next = _ref7[0];
1435
- return [prev, next];
1436
- }, [0, 0]), u.map(function (_ref8) {
1437
- var prev = _ref8[0],
1438
- next = _ref8[1];
1439
- return next - prev;
1440
- })), scrollVelocity);
1441
- return {
1442
- isScrolling: isScrolling,
1443
- isAtTop: isAtTop,
1444
- isAtBottom: isAtBottom,
1445
- atBottomState: atBottomState,
1446
- atTopStateChange: atTopStateChange,
1447
- atBottomStateChange: atBottomStateChange,
1448
- scrollDirection: scrollDirection,
1449
- atBottomThreshold: atBottomThreshold,
1450
- scrollVelocity: scrollVelocity,
1451
- lastJumpDueToItemResize: lastJumpDueToItemResize
1452
- };
1453
- }, /*#__PURE__*/u.tup(domIOSystem));
1454
-
1455
- var propsReadySystem = /*#__PURE__*/u.system(function (_ref) {
1456
- var log = _ref[0].log;
1457
- var propsReady = u.statefulStream(false);
1458
- var didMount = u.streamFromEmitter(u.pipe(propsReady, u.filter(function (ready) {
1459
- return ready;
1460
- }), u.distinctUntilChanged()));
1461
- u.subscribe(propsReady, function (value) {
1462
- value && getValue(log)('props updated', {}, LogLevel.DEBUG);
1463
- });
1464
- return {
1465
- propsReady: propsReady,
1466
- didMount: didMount
1467
- };
1468
- }, /*#__PURE__*/tup(loggerSystem), {
1469
- singleton: true
1470
- });
1471
-
1472
- var initialTopMostItemIndexSystem = /*#__PURE__*/u.system(function (_ref) {
1473
- var _ref$ = _ref[0],
1474
- sizes = _ref$.sizes,
1475
- listRefresh = _ref$.listRefresh,
1476
- defaultItemSize = _ref$.defaultItemSize,
1477
- scrollTop = _ref[1].scrollTop,
1478
- scrollToIndex = _ref[2].scrollToIndex,
1479
- didMount = _ref[3].didMount;
1480
- var scrolledToInitialItem = u.statefulStream(true);
1481
- var initialTopMostItemIndex = u.statefulStream(0);
1482
- u.connect(u.pipe(didMount, u.withLatestFrom(initialTopMostItemIndex), u.filter(function (_ref2) {
1483
- var index = _ref2[1];
1484
- return index !== 0;
1485
- }), u.mapTo(false)), scrolledToInitialItem);
1486
- u.subscribe(u.pipe(u.combineLatest(listRefresh, didMount), u.withLatestFrom(scrolledToInitialItem, sizes, defaultItemSize), u.filter(function (_ref3) {
1487
- var _ref3$ = _ref3[0],
1488
- didMount = _ref3$[1],
1489
- scrolledToInitialItem = _ref3[1],
1490
- sizeTree = _ref3[2].sizeTree,
1491
- defaultItemSize = _ref3[3];
1492
- return didMount && (!empty(sizeTree) || defaultItemSize !== undefined) && !scrolledToInitialItem;
1493
- }), u.withLatestFrom(initialTopMostItemIndex)), function (_ref4) {
1494
- var initialTopMostItemIndex = _ref4[1];
1495
- setTimeout(function () {
1496
- u.handleNext(scrollTop, function () {
1497
- u.publish(scrolledToInitialItem, true);
1498
- });
1499
- u.publish(scrollToIndex, initialTopMostItemIndex);
1500
- });
1501
- });
1502
- return {
1503
- scrolledToInitialItem: scrolledToInitialItem,
1504
- initialTopMostItemIndex: initialTopMostItemIndex
1505
- };
1506
- }, /*#__PURE__*/u.tup(sizeSystem, domIOSystem, scrollToIndexSystem, propsReadySystem), {
1507
- singleton: true
1508
- });
1509
-
1510
- /* eslint-disable @typescript-eslint/no-unsafe-call */
1511
-
1512
- function normalizeFollowOutput(follow) {
1513
- if (!follow) {
1514
- return false;
1515
- }
1516
-
1517
- return follow === 'smooth' ? 'smooth' : 'auto';
1518
- }
1519
-
1520
- var behaviorFromFollowOutput = function behaviorFromFollowOutput(follow, isAtBottom) {
1521
- if (typeof follow === 'function') {
1522
- return normalizeFollowOutput(follow(isAtBottom));
1523
- }
1524
-
1525
- return isAtBottom && normalizeFollowOutput(follow);
1526
- };
1527
-
1528
- var followOutputSystem = /*#__PURE__*/u.system(function (_ref) {
1529
- var _ref$ = _ref[0],
1530
- totalCount = _ref$.totalCount,
1531
- listRefresh = _ref$.listRefresh,
1532
- _ref$2 = _ref[1],
1533
- isAtBottom = _ref$2.isAtBottom,
1534
- atBottomState = _ref$2.atBottomState,
1535
- scrollToIndex = _ref[2].scrollToIndex,
1536
- scrolledToInitialItem = _ref[3].scrolledToInitialItem,
1537
- _ref$3 = _ref[4],
1538
- propsReady = _ref$3.propsReady,
1539
- didMount = _ref$3.didMount,
1540
- log = _ref[5].log,
1541
- scrollingInProgress = _ref[6].scrollingInProgress;
1542
- var followOutput = u.statefulStream(false);
1543
- var pendingScrollHandle = null;
1544
-
1545
- function scrollToBottom(followOutputBehavior) {
1546
- u.publish(scrollToIndex, {
1547
- index: 'LAST',
1548
- align: 'end',
1549
- behavior: followOutputBehavior
1550
- });
1551
- }
1552
-
1553
- u.subscribe(u.pipe(u.combineLatest(u.pipe(u.duc(totalCount), u.skip(1)), didMount), u.withLatestFrom(u.duc(followOutput), isAtBottom, scrolledToInitialItem, scrollingInProgress), u.map(function (_ref2) {
1554
- var _ref2$ = _ref2[0],
1555
- totalCount = _ref2$[0],
1556
- didMount = _ref2$[1],
1557
- followOutput = _ref2[1],
1558
- isAtBottom = _ref2[2],
1559
- scrolledToInitialItem = _ref2[3],
1560
- scrollingInProgress = _ref2[4];
1561
- var shouldFollow = didMount && scrolledToInitialItem;
1562
- var followOutputBehavior = 'auto';
1563
-
1564
- if (shouldFollow) {
1565
- // if scrolling to index is in progress,
1566
- // assume that a previous followOutput response is going
1567
- followOutputBehavior = behaviorFromFollowOutput(followOutput, isAtBottom || scrollingInProgress);
1568
- shouldFollow = shouldFollow && !!followOutputBehavior;
1569
- }
1570
-
1571
- return {
1572
- totalCount: totalCount,
1573
- shouldFollow: shouldFollow,
1574
- followOutputBehavior: followOutputBehavior
1575
- };
1576
- }), u.filter(function (_ref3) {
1577
- var shouldFollow = _ref3.shouldFollow;
1578
- return shouldFollow;
1579
- })), function (_ref4) {
1580
- var totalCount = _ref4.totalCount,
1581
- followOutputBehavior = _ref4.followOutputBehavior;
1582
-
1583
- if (pendingScrollHandle) {
1584
- pendingScrollHandle();
1585
- pendingScrollHandle = null;
1586
- }
1587
-
1588
- pendingScrollHandle = u.handleNext(listRefresh, function () {
1589
- u.getValue(log)('following output to ', {
1590
- totalCount: totalCount
1591
- }, LogLevel.DEBUG);
1592
- scrollToBottom(followOutputBehavior);
1593
- pendingScrollHandle = null;
1594
- });
1595
- });
1596
- u.subscribe(u.pipe(u.combineLatest(u.duc(followOutput), totalCount, propsReady), u.filter(function (_ref5) {
1597
- var follow = _ref5[0],
1598
- ready = _ref5[2];
1599
- return follow && ready;
1600
- }), u.scan(function (_ref6, _ref7) {
1601
- var value = _ref6.value;
1602
- var next = _ref7[1];
1603
- return {
1604
- refreshed: value === next,
1605
- value: next
1606
- };
1607
- }, {
1608
- refreshed: false,
1609
- value: 0
1610
- }), u.filter(function (_ref8) {
1611
- var refreshed = _ref8.refreshed;
1612
- return refreshed;
1613
- }), u.withLatestFrom(followOutput, totalCount)), function (_ref9) {
1614
- var followOutput = _ref9[1];
1615
- var cancel = u.handleNext(atBottomState, function (state) {
1616
- if (followOutput && !state.atBottom && state.notAtBottomBecause === 'SIZE_INCREASED' && !pendingScrollHandle) {
1617
- u.getValue(log)('scrolling to bottom due to increased size', {}, LogLevel.DEBUG);
1618
- scrollToBottom('auto');
1619
- }
1620
- });
1621
- setTimeout(cancel, 100);
1622
- });
1623
- u.subscribe(u.combineLatest(u.duc(followOutput), atBottomState), function (_ref10) {
1624
- var followOutput = _ref10[0],
1625
- state = _ref10[1];
1626
-
1627
- if (followOutput && !state.atBottom && state.notAtBottomBecause === 'VIEWPORT_HEIGHT_DECREASING') {
1628
- scrollToBottom('auto');
1629
- }
1630
- });
1631
- return {
1632
- followOutput: followOutput
1633
- };
1634
- }, /*#__PURE__*/u.tup(sizeSystem, stateFlagsSystem, scrollToIndexSystem, initialTopMostItemIndexSystem, propsReadySystem, loggerSystem, domIOSystem));
1635
-
1636
- function groupCountsToIndicesAndCount(counts) {
1637
- return counts.reduce(function (acc, groupCount) {
1638
- acc.groupIndices.push(acc.totalCount);
1639
- acc.totalCount += groupCount + 1;
1640
- return acc;
1641
- }, {
1642
- totalCount: 0,
1643
- groupIndices: []
1644
- });
1645
- }
1646
- var groupedListSystem = /*#__PURE__*/system(function (_ref) {
1647
- var _ref$ = _ref[0],
1648
- totalCount = _ref$.totalCount,
1649
- groupIndices = _ref$.groupIndices,
1650
- sizes = _ref$.sizes,
1651
- _ref$2 = _ref[1],
1652
- scrollTop = _ref$2.scrollTop,
1653
- headerHeight = _ref$2.headerHeight;
1654
- var groupCounts = stream();
1655
- var topItemsIndexes = stream();
1656
- var groupIndicesAndCount = streamFromEmitter(pipe(groupCounts, map(groupCountsToIndicesAndCount)));
1657
- connect(pipe(groupIndicesAndCount, map(prop('totalCount'))), totalCount);
1658
- connect(pipe(groupIndicesAndCount, map(prop('groupIndices'))), groupIndices);
1659
- connect(pipe(combineLatest(scrollTop, sizes, headerHeight), filter(function (_ref2) {
1660
- var sizes = _ref2[1];
1661
- return hasGroups(sizes);
1662
- }), map(function (_ref3) {
1663
- var scrollTop = _ref3[0],
1664
- state = _ref3[1],
1665
- headerHeight = _ref3[2];
1666
- return findMaxKeyValue(state.groupOffsetTree, Math.max(scrollTop - headerHeight, 0), 'v')[0];
1667
- }), distinctUntilChanged(), map(function (index) {
1668
- return [index];
1669
- })), topItemsIndexes);
1670
- return {
1671
- groupCounts: groupCounts,
1672
- topItemsIndexes: topItemsIndexes
1673
- };
1674
- }, /*#__PURE__*/tup(sizeSystem, domIOSystem));
1675
-
1676
- function tupleComparator(prev, current) {
1677
- return !!(prev && prev[0] === current[0] && prev[1] === current[1]);
1678
- }
1679
- function rangeComparator(prev, next) {
1680
- return !!(prev && prev.startIndex === next.startIndex && prev.endIndex === next.endIndex);
1681
- }
1682
-
1683
- var TOP = 'top';
1684
- var BOTTOM = 'bottom';
1685
- var NONE = 'none';
1686
- function getOverscan(overscan, end, direction) {
1687
- if (typeof overscan === 'number') {
1688
- return direction === UP && end === TOP || direction === DOWN && end === BOTTOM ? overscan : 0;
1689
- } else {
1690
- if (direction === UP) {
1691
- return end === TOP ? overscan.main : overscan.reverse;
1692
- } else {
1693
- return end === BOTTOM ? overscan.main : overscan.reverse;
1694
- }
1695
- }
1696
- }
1697
-
1698
- function getViewportIncrease(value, end) {
1699
- return typeof value === 'number' ? value : value[end] || 0;
1700
- }
1701
-
1702
- var sizeRangeSystem = /*#__PURE__*/u.system(function (_ref) {
1703
- var _ref$ = _ref[0],
1704
- scrollTop = _ref$.scrollTop,
1705
- viewportHeight = _ref$.viewportHeight,
1706
- deviation = _ref$.deviation,
1707
- headerHeight = _ref$.headerHeight;
1708
- var listBoundary = u.stream();
1709
- var topListHeight = u.statefulStream(0);
1710
- var fixedHeaderHeight = u.statefulStream(0);
1711
- var increaseViewportBy = u.statefulStream(0);
1712
- var overscan = u.statefulStream(0);
1713
- var visibleRange = u.statefulStreamFromEmitter(u.pipe(u.combineLatest(u.duc(scrollTop), u.duc(viewportHeight), u.duc(headerHeight), u.duc(listBoundary, tupleComparator), u.duc(overscan), u.duc(topListHeight), u.duc(fixedHeaderHeight), u.duc(deviation), u.duc(increaseViewportBy)), u.map(function (_ref2) {
1714
- var scrollTop = _ref2[0],
1715
- viewportHeight = _ref2[1],
1716
- headerHeight = _ref2[2],
1717
- _ref2$ = _ref2[3],
1718
- listTop = _ref2$[0],
1719
- listBottom = _ref2$[1],
1720
- overscan = _ref2[4],
1721
- topListHeight = _ref2[5],
1722
- fixedHeaderHeight = _ref2[6],
1723
- deviation = _ref2[7],
1724
- increaseViewportBy = _ref2[8];
1725
- var top = scrollTop - deviation;
1726
- var stickyHeaderHeight = topListHeight + fixedHeaderHeight;
1727
- var headerVisible = Math.max(headerHeight - top, 0);
1728
- var direction = NONE;
1729
- var topViewportAddition = getViewportIncrease(increaseViewportBy, TOP);
1730
- var bottomViewportAddition = getViewportIncrease(increaseViewportBy, BOTTOM);
1731
- listTop -= deviation;
1732
- listTop += headerHeight;
1733
- listBottom += headerHeight;
1734
- listBottom -= deviation;
1735
-
1736
- if (listTop > scrollTop + stickyHeaderHeight - topViewportAddition) {
1737
- direction = UP;
1738
- }
1739
-
1740
- if (listBottom < scrollTop - headerVisible + viewportHeight + bottomViewportAddition) {
1741
- direction = DOWN;
1742
- }
1743
-
1744
- if (direction !== NONE) {
1745
- return [Math.max(top - headerHeight - getOverscan(overscan, TOP, direction) - topViewportAddition, 0), top - headerVisible - fixedHeaderHeight + viewportHeight + getOverscan(overscan, BOTTOM, direction) + bottomViewportAddition];
1746
- }
1747
-
1748
- return null;
1749
- }), u.filter(function (value) {
1750
- return value != null;
1751
- }), u.distinctUntilChanged(tupleComparator)), [0, 0]);
1752
- return {
1753
- // input
1754
- listBoundary: listBoundary,
1755
- overscan: overscan,
1756
- topListHeight: topListHeight,
1757
- fixedHeaderHeight: fixedHeaderHeight,
1758
- increaseViewportBy: increaseViewportBy,
1759
- // output
1760
- visibleRange: visibleRange
1761
- };
1762
- }, /*#__PURE__*/u.tup(domIOSystem), {
1763
- singleton: true
1764
- });
1765
-
1766
- function probeItemSet(index, sizes, data) {
1767
- if (hasGroups(sizes)) {
1768
- var itemIndex = originalIndexFromItemIndex(index, sizes);
1769
- var groupIndex = findMaxKeyValue(sizes.groupOffsetTree, itemIndex)[0];
1770
- return [{
1771
- index: groupIndex,
1772
- size: 0,
1773
- offset: 0
1774
- }, {
1775
- index: itemIndex,
1776
- size: 0,
1777
- offset: 0,
1778
- data: data && data[0]
1779
- }];
1780
- }
1781
-
1782
- return [{
1783
- index: index,
1784
- size: 0,
1785
- offset: 0,
1786
- data: data && data[0]
1787
- }];
1788
- }
1789
-
1790
- var EMPTY_LIST_STATE = {
1791
- items: [],
1792
- topItems: [],
1793
- offsetTop: 0,
1794
- offsetBottom: 0,
1795
- top: 0,
1796
- bottom: 0,
1797
- topListHeight: 0,
1798
- totalCount: 0
1799
- };
1800
-
1801
- function transposeItems(items, sizes, firstItemIndex) {
1802
- if (items.length === 0) {
1803
- return [];
1804
- }
1805
-
1806
- if (!hasGroups(sizes)) {
1807
- return items.map(function (item) {
1808
- return _extends({}, item, {
1809
- index: item.index + firstItemIndex,
1810
- originalIndex: item.index
1811
- });
1812
- });
1813
- }
1814
-
1815
- var startIndex = items[0].index;
1816
- var endIndex = items[items.length - 1].index;
1817
- var transposedItems = [];
1818
- var groupRanges = rangesWithin(sizes.groupOffsetTree, startIndex, endIndex);
1819
- var currentRange = undefined;
1820
- var currentGroupIndex = 0;
1821
-
1822
- for (var _iterator = _createForOfIteratorHelperLoose(items), _step; !(_step = _iterator()).done;) {
1823
- var item = _step.value;
1824
-
1825
- if (!currentRange || currentRange.end < item.index) {
1826
- currentRange = groupRanges.shift();
1827
- currentGroupIndex = sizes.groupIndices.indexOf(currentRange.start);
1828
- }
1829
-
1830
- var transposedItem = void 0;
1831
-
1832
- if (item.index === currentRange.start) {
1833
- transposedItem = {
1834
- type: 'group',
1835
- index: currentGroupIndex
1836
- };
1837
- } else {
1838
- transposedItem = {
1839
- index: item.index - (currentGroupIndex + 1) + firstItemIndex,
1840
- groupIndex: currentGroupIndex
1841
- };
1842
- }
1843
-
1844
- transposedItems.push(_extends({}, transposedItem, {
1845
- size: item.size,
1846
- offset: item.offset,
1847
- originalIndex: item.index,
1848
- data: item.data
1849
- }));
1850
- }
1851
-
1852
- return transposedItems;
1853
- }
1854
-
1855
- function buildListState(items, topItems, totalCount, sizes, firstItemIndex) {
1856
- var lastSize = sizes.lastSize,
1857
- lastOffset = sizes.lastOffset,
1858
- lastIndex = sizes.lastIndex;
1859
- var offsetTop = 0;
1860
- var bottom = 0;
1861
-
1862
- if (items.length > 0) {
1863
- offsetTop = items[0].offset;
1864
- var lastItem = items[items.length - 1];
1865
- bottom = lastItem.offset + lastItem.size;
1866
- }
1867
-
1868
- var total = lastOffset + (totalCount - lastIndex) * lastSize;
1869
- var top = offsetTop;
1870
- var offsetBottom = total - bottom;
1871
- return {
1872
- items: transposeItems(items, sizes, firstItemIndex),
1873
- topItems: transposeItems(topItems, sizes, firstItemIndex),
1874
- topListHeight: topItems.reduce(function (height, item) {
1875
- return item.size + height;
1876
- }, 0),
1877
- offsetTop: offsetTop,
1878
- offsetBottom: offsetBottom,
1879
- top: top,
1880
- bottom: bottom,
1881
- totalCount: totalCount
1882
- };
1883
- }
1884
- var listStateSystem = /*#__PURE__*/u.system(function (_ref) {
1885
- var _ref$ = _ref[0],
1886
- sizes = _ref$.sizes,
1887
- totalCount = _ref$.totalCount,
1888
- data = _ref$.data,
1889
- firstItemIndex = _ref$.firstItemIndex,
1890
- groupedListSystem = _ref[1],
1891
- _ref$2 = _ref[2],
1892
- visibleRange = _ref$2.visibleRange,
1893
- listBoundary = _ref$2.listBoundary,
1894
- rangeTopListHeight = _ref$2.topListHeight,
1895
- _ref$3 = _ref[3],
1896
- scrolledToInitialItem = _ref$3.scrolledToInitialItem,
1897
- initialTopMostItemIndex = _ref$3.initialTopMostItemIndex,
1898
- topListHeight = _ref[4].topListHeight,
1899
- stateFlags = _ref[5],
1900
- didMount = _ref[6].didMount;
1901
- var topItemsIndexes = u.statefulStream([]);
1902
- var itemsRendered = u.stream();
1903
- u.connect(groupedListSystem.topItemsIndexes, topItemsIndexes);
1904
- var listState = u.statefulStreamFromEmitter(u.pipe(u.combineLatest(didMount, u.duc(visibleRange), u.duc(totalCount), u.duc(sizes), u.duc(initialTopMostItemIndex), scrolledToInitialItem, u.duc(topItemsIndexes), u.duc(firstItemIndex), data), u.filter(function (_ref2) {
1905
- var mount = _ref2[0];
1906
- return mount;
1907
- }), u.map(function (_ref3) {
1908
- var _ref3$ = _ref3[1],
1909
- startOffset = _ref3$[0],
1910
- endOffset = _ref3$[1],
1911
- totalCount = _ref3[2],
1912
- sizes = _ref3[3],
1913
- initialTopMostItemIndex = _ref3[4],
1914
- scrolledToInitialItem = _ref3[5],
1915
- topItemsIndexes = _ref3[6],
1916
- firstItemIndex = _ref3[7],
1917
- data = _ref3[8];
1918
- var sizesValue = sizes;
1919
- var sizeTree = sizesValue.sizeTree,
1920
- offsetTree = sizesValue.offsetTree;
1921
-
1922
- if (totalCount === 0 || startOffset === 0 && endOffset === 0) {
1923
- return EMPTY_LIST_STATE;
1924
- }
1925
-
1926
- if (empty(sizeTree)) {
1927
- return buildListState(probeItemSet(initialTopMostItemIndex, sizesValue, data), [], totalCount, sizesValue, firstItemIndex);
1928
- }
1929
-
1930
- var topItems = [];
1931
-
1932
- if (topItemsIndexes.length > 0) {
1933
- var startIndex = topItemsIndexes[0];
1934
- var endIndex = topItemsIndexes[topItemsIndexes.length - 1];
1935
- var offset = 0;
1936
-
1937
- for (var _iterator2 = _createForOfIteratorHelperLoose(rangesWithin(sizeTree, startIndex, endIndex)), _step2; !(_step2 = _iterator2()).done;) {
1938
- var range = _step2.value;
1939
- var size = range.value;
1940
- var rangeStartIndex = Math.max(range.start, startIndex);
1941
- var rangeEndIndex = Math.min(range.end, endIndex);
1942
-
1943
- for (var i = rangeStartIndex; i <= rangeEndIndex; i++) {
1944
- topItems.push({
1945
- index: i,
1946
- size: size,
1947
- offset: offset,
1948
- data: data && data[i]
1949
- });
1950
- offset += size;
1951
- }
1952
- }
1953
- } // If the list hasn't scrolled to the initial item because the initial item was set,
1954
- // render empty list.
1955
- //
1956
- // This is a condition to be evaluated past the probe check, do not merge
1957
- // with the totalCount check above
1958
-
1959
-
1960
- if (!scrolledToInitialItem) {
1961
- return buildListState([], topItems, totalCount, sizesValue, firstItemIndex);
1962
- }
1963
-
1964
- var minStartIndex = topItemsIndexes.length > 0 ? topItemsIndexes[topItemsIndexes.length - 1] + 1 : 0;
1965
- var offsetPointRanges = rangesWithinOffsets(offsetTree, startOffset, endOffset, minStartIndex);
1966
-
1967
- if (offsetPointRanges.length === 0) {
1968
- return null;
1969
- }
1970
-
1971
- var maxIndex = totalCount - 1;
1972
- var items = u.tap([], function (result) {
1973
- for (var _iterator3 = _createForOfIteratorHelperLoose(offsetPointRanges), _step3; !(_step3 = _iterator3()).done;) {
1974
- var _range = _step3.value;
1975
- var point = _range.value;
1976
- var _offset = point.offset;
1977
- var _rangeStartIndex = _range.start;
1978
- var _size = point.size;
1979
-
1980
- if (point.offset < startOffset) {
1981
- _rangeStartIndex += Math.floor((startOffset - point.offset) / _size);
1982
- _offset += (_rangeStartIndex - _range.start) * _size;
1983
- }
1984
-
1985
- if (_rangeStartIndex < minStartIndex) {
1986
- _offset += (minStartIndex - _rangeStartIndex) * _size;
1987
- _rangeStartIndex = minStartIndex;
1988
- }
1989
-
1990
- var _endIndex = Math.min(_range.end, maxIndex);
1991
-
1992
- for (var _i = _rangeStartIndex; _i <= _endIndex; _i++) {
1993
- if (_offset >= endOffset) {
1994
- break;
1995
- }
1996
-
1997
- result.push({
1998
- index: _i,
1999
- size: _size,
2000
- offset: _offset,
2001
- data: data && data[_i]
2002
- });
2003
- _offset += _size;
2004
- }
2005
- }
2006
- });
2007
- return buildListState(items, topItems, totalCount, sizesValue, firstItemIndex);
2008
- }), //@ts-expect-error filter needs to be fixed
2009
- u.filter(function (value) {
2010
- return value !== null;
2011
- }), u.distinctUntilChanged()), EMPTY_LIST_STATE);
2012
- u.connect(u.pipe(data, u.filter(function (data) {
2013
- return data !== undefined;
2014
- }), u.map(function (data) {
2015
- return data.length;
2016
- })), totalCount);
2017
- u.connect(u.pipe(listState, u.map(u.prop('topListHeight'))), topListHeight);
2018
- u.connect(topListHeight, rangeTopListHeight);
2019
- u.connect(u.pipe(listState, u.map(function (state) {
2020
- return [state.top, state.bottom];
2021
- })), listBoundary);
2022
- u.connect(u.pipe(listState, u.map(function (state) {
2023
- return state.items;
2024
- })), itemsRendered);
2025
- var endReached = u.streamFromEmitter(u.pipe(listState, u.filter(function (_ref4) {
2026
- var items = _ref4.items;
2027
- return items.length > 0;
2028
- }), u.withLatestFrom(totalCount, data), u.filter(function (_ref5) {
2029
- var items = _ref5[0].items,
2030
- totalCount = _ref5[1];
2031
- return items[items.length - 1].originalIndex === totalCount - 1;
2032
- }), u.map(function (_ref6) {
2033
- var totalCount = _ref6[1],
2034
- data = _ref6[2];
2035
- return [totalCount - 1, data];
2036
- }), u.distinctUntilChanged(tupleComparator), u.map(function (_ref7) {
2037
- var count = _ref7[0];
2038
- return count;
2039
- })));
2040
- var startReached = u.streamFromEmitter(u.pipe(listState, u.throttleTime(200), u.filter(function (_ref8) {
2041
- var items = _ref8.items,
2042
- topItems = _ref8.topItems;
2043
- return items.length > 0 && items[0].originalIndex === topItems.length;
2044
- }), u.map(function (_ref9) {
2045
- var items = _ref9.items;
2046
- return items[0].index;
2047
- }), u.distinctUntilChanged()));
2048
- var rangeChanged = u.streamFromEmitter(u.pipe(listState, u.filter(function (_ref10) {
2049
- var items = _ref10.items;
2050
- return items.length > 0;
2051
- }), u.map(function (_ref11) {
2052
- var items = _ref11.items;
2053
- return {
2054
- startIndex: items[0].index,
2055
- endIndex: items[items.length - 1].index
2056
- };
2057
- }), u.distinctUntilChanged(rangeComparator)));
2058
- return _extends({
2059
- listState: listState,
2060
- topItemsIndexes: topItemsIndexes,
2061
- endReached: endReached,
2062
- startReached: startReached,
2063
- rangeChanged: rangeChanged,
2064
- itemsRendered: itemsRendered
2065
- }, stateFlags);
2066
- }, /*#__PURE__*/u.tup(sizeSystem, groupedListSystem, sizeRangeSystem, initialTopMostItemIndexSystem, scrollToIndexSystem, stateFlagsSystem, propsReadySystem), {
2067
- singleton: true
2068
- });
2069
-
2070
- var initialItemCountSystem = /*#__PURE__*/u.system(function (_ref) {
2071
- var _ref$ = _ref[0],
2072
- sizes = _ref$.sizes,
2073
- firstItemIndex = _ref$.firstItemIndex,
2074
- data = _ref$.data,
2075
- listState = _ref[1].listState,
2076
- didMount = _ref[2].didMount;
2077
- var initialItemCount = u.statefulStream(0);
2078
- u.connect(u.pipe(didMount, u.withLatestFrom(initialItemCount), u.filter(function (_ref2) {
2079
- var count = _ref2[1];
2080
- return count !== 0;
2081
- }), u.withLatestFrom(sizes, firstItemIndex, data), u.map(function (_ref3) {
2082
- var _ref3$ = _ref3[0],
2083
- count = _ref3$[1],
2084
- sizes = _ref3[1],
2085
- firstItemIndex = _ref3[2],
2086
- _ref3$2 = _ref3[3],
2087
- data = _ref3$2 === void 0 ? [] : _ref3$2;
2088
- var includedGroupsCount = 0;
2089
-
2090
- if (sizes.groupIndices.length > 0) {
2091
- for (var _iterator = _createForOfIteratorHelperLoose(sizes.groupIndices), _step; !(_step = _iterator()).done;) {
2092
- var index = _step.value;
2093
-
2094
- if (index - includedGroupsCount >= count) {
2095
- break;
2096
- }
2097
-
2098
- includedGroupsCount++;
2099
- }
2100
- }
2101
-
2102
- var adjustedCount = count + includedGroupsCount;
2103
- var items = Array.from({
2104
- length: adjustedCount
2105
- }).map(function (_, index) {
2106
- return {
2107
- index: index,
2108
- size: 0,
2109
- offset: 0,
2110
- data: data[index]
2111
- };
2112
- });
2113
- return buildListState(items, [], adjustedCount, sizes, firstItemIndex);
2114
- })), listState);
2115
- return {
2116
- initialItemCount: initialItemCount
2117
- };
2118
- }, /*#__PURE__*/u.tup(sizeSystem, listStateSystem, propsReadySystem), {
2119
- singleton: true
2120
- });
2121
-
2122
- var scrollSeekSystem = /*#__PURE__*/u.system(function (_ref) {
2123
- var scrollVelocity = _ref[0].scrollVelocity;
2124
- var isSeeking = u.statefulStream(false);
2125
- var rangeChanged = u.stream();
2126
- var scrollSeekConfiguration = u.statefulStream(false);
2127
- u.connect(u.pipe(scrollVelocity, u.withLatestFrom(scrollSeekConfiguration, isSeeking, rangeChanged), u.filter(function (_ref2) {
2128
- var config = _ref2[1];
2129
- return !!config;
2130
- }), u.map(function (_ref3) {
2131
- var speed = _ref3[0],
2132
- config = _ref3[1],
2133
- isSeeking = _ref3[2],
2134
- range = _ref3[3];
2135
- var exit = config.exit,
2136
- enter = config.enter;
2137
-
2138
- if (isSeeking) {
2139
- if (exit(speed, range)) {
2140
- return false;
2141
- }
2142
- } else {
2143
- if (enter(speed, range)) {
2144
- return true;
2145
- }
2146
- }
2147
-
2148
- return isSeeking;
2149
- }), u.distinctUntilChanged()), isSeeking);
2150
- u.subscribe(u.pipe(u.combineLatest(isSeeking, scrollVelocity, rangeChanged), u.withLatestFrom(scrollSeekConfiguration)), function (_ref4) {
2151
- var _ref4$ = _ref4[0],
2152
- isSeeking = _ref4$[0],
2153
- velocity = _ref4$[1],
2154
- range = _ref4$[2],
2155
- config = _ref4[1];
2156
- return isSeeking && config && config.change && config.change(velocity, range);
2157
- });
2158
- return {
2159
- isSeeking: isSeeking,
2160
- scrollSeekConfiguration: scrollSeekConfiguration,
2161
- scrollVelocity: scrollVelocity,
2162
- scrollSeekRangeChanged: rangeChanged
2163
- };
2164
- }, /*#__PURE__*/u.tup(stateFlagsSystem), {
2165
- singleton: true
2166
- });
2167
-
2168
- var topItemCountSystem = /*#__PURE__*/system(function (_ref) {
2169
- var topItemsIndexes = _ref[0].topItemsIndexes;
2170
- var topItemCount = statefulStream(0);
2171
- connect(pipe(topItemCount, filter(function (length) {
2172
- return length > 0;
2173
- }), map(function (length) {
2174
- return Array.from({
2175
- length: length
2176
- }).map(function (_, index) {
2177
- return index;
2178
- });
2179
- })), topItemsIndexes);
2180
- return {
2181
- topItemCount: topItemCount
2182
- };
2183
- }, /*#__PURE__*/tup(listStateSystem));
2184
-
2185
- var totalListHeightSystem = /*#__PURE__*/u.system(function (_ref) {
2186
- var _ref$ = _ref[0],
2187
- footerHeight = _ref$.footerHeight,
2188
- headerHeight = _ref$.headerHeight,
2189
- listState = _ref[1].listState;
2190
- var totalListHeightChanged = u.stream();
2191
- var totalListHeight = u.statefulStreamFromEmitter(u.pipe(u.combineLatest(footerHeight, headerHeight, listState), u.map(function (_ref2) {
2192
- var footerHeight = _ref2[0],
2193
- headerHeight = _ref2[1],
2194
- listState = _ref2[2];
2195
- return footerHeight + headerHeight + listState.offsetBottom + listState.bottom;
2196
- })), 0);
2197
- u.connect(u.duc(totalListHeight), totalListHeightChanged);
2198
- return {
2199
- totalListHeight: totalListHeight,
2200
- totalListHeightChanged: totalListHeightChanged
2201
- };
2202
- }, /*#__PURE__*/u.tup(domIOSystem, listStateSystem), {
2203
- singleton: true
2204
- });
2205
-
2206
- /**
2207
- * Fixes upward scrolling by calculating and compensation from changed item heights, using scrollBy.
2208
- */
2209
-
2210
- var upwardScrollFixSystem = /*#__PURE__*/u.system(function (_ref) {
2211
- var _ref$ = _ref[0],
2212
- scrollBy = _ref$.scrollBy,
2213
- scrollTop = _ref$.scrollTop,
2214
- deviation = _ref$.deviation,
2215
- scrollingInProgress = _ref$.scrollingInProgress,
2216
- _ref$2 = _ref[1],
2217
- isScrolling = _ref$2.isScrolling,
2218
- isAtBottom = _ref$2.isAtBottom,
2219
- atBottomState = _ref$2.atBottomState,
2220
- scrollDirection = _ref$2.scrollDirection,
2221
- lastJumpDueToItemResize = _ref$2.lastJumpDueToItemResize,
2222
- listState = _ref[2].listState,
2223
- _ref$3 = _ref[3],
2224
- beforeUnshiftWith = _ref$3.beforeUnshiftWith,
2225
- sizes = _ref$3.sizes,
2226
- log = _ref[4].log;
2227
- var deviationOffset = u.streamFromEmitter(u.pipe(listState, u.withLatestFrom(lastJumpDueToItemResize), u.scan(function (_ref2, _ref3) {
2228
- var prevItems = _ref2[1],
2229
- prevTotalCount = _ref2[2];
2230
- var _ref3$ = _ref3[0],
2231
- items = _ref3$.items,
2232
- totalCount = _ref3$.totalCount,
2233
- lastJumpDueToItemResize = _ref3[1];
2234
- var newDev = 0;
2235
-
2236
- if (prevTotalCount === totalCount) {
2237
- if (prevItems.length > 0 && items.length > 0) {
2238
- var firstItemIndex = items[0].originalIndex;
2239
- var prevFirstItemIndex = prevItems[0].originalIndex;
2240
- var atStart = firstItemIndex === 0 && prevFirstItemIndex === 0;
2241
- var onlyItem = items.length === 1;
2242
-
2243
- if (!atStart) {
2244
- var _loop = function _loop(index) {
2245
- var item = items[index];
2246
- var prevItem = prevItems.find(function (pItem) {
2247
- return pItem.originalIndex === item.originalIndex;
2248
- });
2249
-
2250
- if (!prevItem) {
2251
- return "continue";
2252
- }
2253
-
2254
- if (item.offset !== prevItem.offset || onlyItem) {
2255
- newDev = item.offset - prevItem.offset + item.size - prevItem.size;
2256
- return "break";
2257
- }
2258
- };
2259
-
2260
- for (var index = items.length - 1; index >= 0; index--) {
2261
- var _ret = _loop(index);
2262
-
2263
- if (_ret === "continue") continue;
2264
- if (_ret === "break") break;
2265
- }
2266
- }
2267
- }
2268
-
2269
- if (newDev !== 0) {
2270
- newDev += lastJumpDueToItemResize;
2271
- }
2272
- }
2273
-
2274
- return [newDev, items, totalCount];
2275
- }, [0, [], 0]), u.filter(function (_ref4) {
2276
- var amount = _ref4[0];
2277
- return amount !== 0;
2278
- }), u.withLatestFrom(scrollTop, scrollDirection, scrollingInProgress, log, isAtBottom, atBottomState), u.filter(function (_ref5) {
2279
- var scrollTop = _ref5[1],
2280
- scrollDirection = _ref5[2],
2281
- scrollingInProgress = _ref5[3];
2282
- // console.log({ amount, scrollTop, scrollDirection, scrollingInProgress, isAtBottom, atBottomState })
2283
- return !scrollingInProgress && scrollTop !== 0 && scrollDirection === UP; // && (isAtBottom ? amount > 0 : true)
2284
- }), u.map(function (_ref6) {
2285
- var _ref6$ = _ref6[0],
2286
- amount = _ref6$[0],
2287
- log = _ref6[4];
2288
- log('Upward scrolling compensation', {
2289
- amount: amount
2290
- }, LogLevel.DEBUG);
2291
- return amount;
2292
- })));
2293
- u.connect(u.pipe(deviationOffset, u.withLatestFrom(deviation), u.map(function (_ref7) {
2294
- var amount = _ref7[0],
2295
- deviation = _ref7[1];
2296
- return deviation - amount;
2297
- })), deviation); // when the browser stops scrolling,
2298
- // restore the position and reset the glitching
2299
-
2300
- u.subscribe(u.pipe(u.combineLatest(u.statefulStreamFromEmitter(isScrolling, false), deviation), u.filter(function (_ref8) {
2301
- var is = _ref8[0],
2302
- deviation = _ref8[1];
2303
- return !is && deviation !== 0;
2304
- }), u.map(function (_ref9) {
2305
- var deviation = _ref9[1];
2306
- return deviation;
2307
- }), u.throttleTime(1)), function (offset) {
2308
- if (offset > 0) {
2309
- u.publish(scrollBy, {
2310
- top: -offset,
2311
- behavior: 'auto'
2312
- });
2313
- u.publish(deviation, 0);
2314
- } else {
2315
- u.publish(deviation, 0);
2316
- u.publish(scrollBy, {
2317
- top: -offset,
2318
- behavior: 'auto'
2319
- });
2320
- }
2321
- });
2322
- u.connect(u.pipe(beforeUnshiftWith, u.withLatestFrom(sizes), u.map(function (_ref10) {
2323
- var offset = _ref10[0],
2324
- lastSize = _ref10[1].lastSize;
2325
- return offset * lastSize;
2326
- })), deviationOffset);
2327
- return {
2328
- deviation: deviation
2329
- };
2330
- }, /*#__PURE__*/u.tup(domIOSystem, stateFlagsSystem, listStateSystem, sizeSystem, loggerSystem));
2331
-
2332
- var initialScrollTopSystem = /*#__PURE__*/u.system(function (_ref) {
2333
- var totalListHeight = _ref[0].totalListHeight,
2334
- didMount = _ref[1].didMount,
2335
- scrollTo = _ref[2].scrollTo;
2336
- var initialScrollTop = u.statefulStream(0);
2337
- u.subscribe(u.pipe(didMount, u.withLatestFrom(initialScrollTop), u.filter(function (_ref2) {
2338
- var offset = _ref2[1];
2339
- return offset !== 0;
2340
- }), u.map(function (_ref3) {
2341
- var offset = _ref3[1];
2342
- return {
2343
- top: offset
2344
- };
2345
- })), function (location) {
2346
- u.handleNext(u.pipe(totalListHeight, u.filter(function (val) {
2347
- return val !== 0;
2348
- })), function () {
2349
- setTimeout(function () {
2350
- u.publish(scrollTo, location);
2351
- });
2352
- });
2353
- });
2354
- return {
2355
- initialScrollTop: initialScrollTop
2356
- };
2357
- }, /*#__PURE__*/u.tup(totalListHeightSystem, propsReadySystem, domIOSystem), {
2358
- singleton: true
2359
- });
2360
-
2361
- var alignToBottomSystem = /*#__PURE__*/u.system(function (_ref) {
2362
- var viewportHeight = _ref[0].viewportHeight,
2363
- totalListHeight = _ref[1].totalListHeight;
2364
- var alignToBottom = u.statefulStream(false);
2365
- var paddingTopAddition = u.statefulStreamFromEmitter(u.pipe(u.combineLatest(alignToBottom, viewportHeight, totalListHeight), u.filter(function (_ref2) {
2366
- var enabled = _ref2[0];
2367
- return enabled;
2368
- }), u.map(function (_ref3) {
2369
- var viewportHeight = _ref3[1],
2370
- totalListHeight = _ref3[2];
2371
- return Math.max(0, viewportHeight - totalListHeight);
2372
- }), u.distinctUntilChanged()), 0);
2373
- return {
2374
- alignToBottom: alignToBottom,
2375
- paddingTopAddition: paddingTopAddition
2376
- };
2377
- }, /*#__PURE__*/u.tup(domIOSystem, totalListHeightSystem), {
2378
- singleton: true
2379
- });
2380
-
2381
- var windowScrollerSystem = /*#__PURE__*/u.system(function (_ref) {
2382
- var _ref$ = _ref[0],
2383
- scrollTo = _ref$.scrollTo,
2384
- scrollContainerState = _ref$.scrollContainerState;
2385
- var windowScrollContainerState = u.stream();
2386
- var windowViewportRect = u.stream();
2387
- var windowScrollTo = u.stream();
2388
- var useWindowScroll = u.statefulStream(false);
2389
- var customScrollParent = u.statefulStream(undefined);
2390
- u.connect(u.pipe(u.combineLatest(windowScrollContainerState, windowViewportRect), u.map(function (_ref2) {
2391
- var _ref2$ = _ref2[0],
2392
- windowScrollTop = _ref2$[0],
2393
- scrollHeight = _ref2$[1],
2394
- offsetTop = _ref2[1].offsetTop;
2395
- return [Math.max(0, windowScrollTop - offsetTop), scrollHeight];
2396
- })), scrollContainerState);
2397
- u.connect(u.pipe(scrollTo, u.withLatestFrom(windowViewportRect), u.map(function (_ref3) {
2398
- var scrollTo = _ref3[0],
2399
- offsetTop = _ref3[1].offsetTop;
2400
- return _extends({}, scrollTo, {
2401
- top: scrollTo.top + offsetTop
2402
- });
2403
- })), windowScrollTo);
2404
- return {
2405
- // config
2406
- useWindowScroll: useWindowScroll,
2407
- customScrollParent: customScrollParent,
2408
- // input
2409
- windowScrollContainerState: windowScrollContainerState,
2410
- windowViewportRect: windowViewportRect,
2411
- // signals
2412
- windowScrollTo: windowScrollTo
2413
- };
2414
- }, /*#__PURE__*/u.tup(domIOSystem));
2415
-
2416
- var scrollIntoViewSystem = /*#__PURE__*/u.system(function (_ref) {
2417
- var _ref$ = _ref[0],
2418
- sizes = _ref$.sizes,
2419
- totalCount = _ref$.totalCount,
2420
- _ref$2 = _ref[1],
2421
- scrollTop = _ref$2.scrollTop,
2422
- viewportHeight = _ref$2.viewportHeight,
2423
- headerHeight = _ref$2.headerHeight,
2424
- scrollingInProgress = _ref$2.scrollingInProgress,
2425
- scrollToIndex = _ref[2].scrollToIndex;
2426
- var scrollIntoView = u.stream();
2427
- u.connect(u.pipe(scrollIntoView, u.withLatestFrom(sizes, viewportHeight, totalCount, headerHeight, scrollTop), u.map(function (_ref2) {
2428
- var _ref2$ = _ref2[0],
2429
- index = _ref2$.index,
2430
- _ref2$$behavior = _ref2$.behavior,
2431
- behavior = _ref2$$behavior === void 0 ? 'auto' : _ref2$$behavior,
2432
- done = _ref2$.done,
2433
- sizes = _ref2[1],
2434
- viewportHeight = _ref2[2],
2435
- totalCount = _ref2[3],
2436
- headerHeight = _ref2[4],
2437
- scrollTop = _ref2[5];
2438
- var lastIndex = totalCount - 1;
2439
- var location = null;
2440
- index = originalIndexFromItemIndex(index, sizes);
2441
- index = Math.max(0, index, Math.min(lastIndex, index));
2442
- var itemTop = offsetOf(index, sizes.offsetTree) + headerHeight;
2443
-
2444
- if (itemTop < scrollTop) {
2445
- location = {
2446
- index: index,
2447
- behavior: behavior,
2448
- align: 'start'
2449
- };
2450
- } else {
2451
- var itemBottom = itemTop + findMaxKeyValue(sizes.sizeTree, index)[1];
2452
-
2453
- if (itemBottom > scrollTop + viewportHeight) {
2454
- location = {
2455
- index: index,
2456
- behavior: behavior,
2457
- align: 'end'
2458
- };
2459
- }
2460
- }
2461
-
2462
- if (location) {
2463
- done && u.handleNext(u.pipe(scrollingInProgress, u.skip(1), u.filter(function (value) {
2464
- return value === false;
2465
- })), done);
2466
- } else {
2467
- done && done();
2468
- }
2469
-
2470
- return location;
2471
- }), u.filter(function (value) {
2472
- return value !== null;
2473
- })), scrollToIndex);
2474
- return {
2475
- scrollIntoView: scrollIntoView
2476
- };
2477
- }, /*#__PURE__*/u.tup(sizeSystem, domIOSystem, scrollToIndexSystem, listStateSystem, loggerSystem), {
2478
- singleton: true
2479
- });
2480
-
2481
- // fix this with 4.1 recursive conditional types
2482
-
2483
- var featureGroup1System = /*#__PURE__*/u.system(function (_ref) {
2484
- var sizeRange = _ref[0],
2485
- initialItemCount = _ref[1],
2486
- propsReady = _ref[2],
2487
- scrollSeek = _ref[3],
2488
- totalListHeight = _ref[4],
2489
- initialScrollTopSystem = _ref[5],
2490
- alignToBottom = _ref[6],
2491
- windowScroller = _ref[7],
2492
- scrollIntoView = _ref[8];
2493
- return _extends({}, sizeRange, initialItemCount, propsReady, scrollSeek, totalListHeight, initialScrollTopSystem, alignToBottom, windowScroller, scrollIntoView);
2494
- }, /*#__PURE__*/u.tup(sizeRangeSystem, initialItemCountSystem, propsReadySystem, scrollSeekSystem, totalListHeightSystem, initialScrollTopSystem, alignToBottomSystem, windowScrollerSystem, scrollIntoViewSystem));
2495
- var listSystem = /*#__PURE__*/u.system(function (_ref2) {
2496
- var _ref2$ = _ref2[0],
2497
- totalCount = _ref2$.totalCount,
2498
- sizeRanges = _ref2$.sizeRanges,
2499
- fixedItemSize = _ref2$.fixedItemSize,
2500
- defaultItemSize = _ref2$.defaultItemSize,
2501
- trackItemSizes = _ref2$.trackItemSizes,
2502
- itemSize = _ref2$.itemSize,
2503
- data = _ref2$.data,
2504
- firstItemIndex = _ref2$.firstItemIndex,
2505
- groupIndices = _ref2$.groupIndices,
2506
- statefulTotalCount = _ref2$.statefulTotalCount,
2507
- _ref2$2 = _ref2[1],
2508
- initialTopMostItemIndex = _ref2$2.initialTopMostItemIndex,
2509
- scrolledToInitialItem = _ref2$2.scrolledToInitialItem,
2510
- domIO = _ref2[2],
2511
- followOutput = _ref2[3],
2512
- _ref2$3 = _ref2[4],
2513
- listState = _ref2$3.listState,
2514
- topItemsIndexes = _ref2$3.topItemsIndexes,
2515
- flags = _objectWithoutPropertiesLoose(_ref2$3, ["listState", "topItemsIndexes"]),
2516
- scrollToIndex = _ref2[5].scrollToIndex,
2517
- topItemCount = _ref2[7].topItemCount,
2518
- groupCounts = _ref2[8].groupCounts,
2519
- featureGroup1 = _ref2[9],
2520
- log = _ref2[10];
2521
-
2522
- u.connect(flags.rangeChanged, featureGroup1.scrollSeekRangeChanged);
2523
- u.connect(u.pipe(featureGroup1.windowViewportRect, u.map(u.prop('visibleHeight'))), domIO.viewportHeight);
2524
- return _extends({
2525
- // input
2526
- totalCount: totalCount,
2527
- data: data,
2528
- firstItemIndex: firstItemIndex,
2529
- sizeRanges: sizeRanges,
2530
- initialTopMostItemIndex: initialTopMostItemIndex,
2531
- scrolledToInitialItem: scrolledToInitialItem,
2532
- topItemsIndexes: topItemsIndexes,
2533
- topItemCount: topItemCount,
2534
- groupCounts: groupCounts,
2535
- fixedItemHeight: fixedItemSize,
2536
- defaultItemHeight: defaultItemSize
2537
- }, followOutput, {
2538
- // output
2539
- statefulTotalCount: statefulTotalCount,
2540
- listState: listState,
2541
- scrollToIndex: scrollToIndex,
2542
- trackItemSizes: trackItemSizes,
2543
- itemSize: itemSize,
2544
- groupIndices: groupIndices
2545
- }, flags, featureGroup1, domIO, log);
2546
- }, /*#__PURE__*/u.tup(sizeSystem, initialTopMostItemIndexSystem, domIOSystem, followOutputSystem, listStateSystem, scrollToIndexSystem, upwardScrollFixSystem, topItemCountSystem, groupedListSystem, featureGroup1System, loggerSystem));
2547
-
2548
- function simpleMemoize(func) {
2549
- var called = false;
2550
- var result;
2551
- return function () {
2552
- if (!called) {
2553
- called = true;
2554
- result = func();
2555
- }
2556
-
2557
- return result;
2558
- };
2559
- }
2560
-
2561
- var WEBKIT_STICKY = '-webkit-sticky';
2562
- var STICKY = 'sticky';
2563
- var positionStickyCssValue = /*#__PURE__*/simpleMemoize(function () {
2564
- if (typeof document === 'undefined') {
2565
- return STICKY;
2566
- }
2567
-
2568
- var node = document.createElement('div');
2569
- node.style.position = WEBKIT_STICKY;
2570
- return node.style.position === WEBKIT_STICKY ? WEBKIT_STICKY : STICKY;
2571
- });
2572
-
2573
- function useWindowViewportRectRef(callback, customScrollParent) {
2574
- var viewportInfo = useRef(null);
2575
- var calculateInfo = useCallback(function (element) {
2576
- if (element === null) {
2577
- return;
2578
- }
2579
-
2580
- var rect = element.getBoundingClientRect();
2581
- var visibleWidth = rect.width;
2582
- var visibleHeight, offsetTop;
2583
-
2584
- if (customScrollParent) {
2585
- var customScrollParentRect = customScrollParent.getBoundingClientRect();
2586
- var deltaTop = rect.top - customScrollParentRect.top;
2587
- visibleHeight = customScrollParentRect.height - Math.max(0, deltaTop);
2588
- offsetTop = deltaTop + customScrollParent.scrollTop;
2589
- } else {
2590
- visibleHeight = window.innerHeight - Math.max(0, rect.top);
2591
- offsetTop = rect.top + window.pageYOffset;
2592
- }
2593
-
2594
- viewportInfo.current = {
2595
- offsetTop: offsetTop,
2596
- visibleHeight: visibleHeight,
2597
- visibleWidth: visibleWidth
2598
- };
2599
- callback(viewportInfo.current);
2600
- }, [callback, customScrollParent]);
2601
-
2602
- var _useSizeWithElRef = useSizeWithElRef(calculateInfo),
2603
- callbackRef = _useSizeWithElRef.callbackRef,
2604
- ref = _useSizeWithElRef.ref;
2605
-
2606
- var scrollAndResizeEventHandler = useCallback(function () {
2607
- calculateInfo(ref.current);
2608
- }, [calculateInfo, ref]);
2609
- useEffect(function () {
2610
- if (customScrollParent) {
2611
- customScrollParent.addEventListener('scroll', scrollAndResizeEventHandler);
2612
- var observer = new ResizeObserver(scrollAndResizeEventHandler);
2613
- observer.observe(customScrollParent);
2614
- return function () {
2615
- customScrollParent.removeEventListener('scroll', scrollAndResizeEventHandler);
2616
- observer.unobserve(customScrollParent);
2617
- };
2618
- } else {
2619
- window.addEventListener('scroll', scrollAndResizeEventHandler);
2620
- window.addEventListener('resize', scrollAndResizeEventHandler);
2621
- return function () {
2622
- window.removeEventListener('scroll', scrollAndResizeEventHandler);
2623
- window.removeEventListener('resize', scrollAndResizeEventHandler);
2624
- };
2625
- }
2626
- }, [scrollAndResizeEventHandler, customScrollParent]);
2627
- return callbackRef;
2628
- }
2629
-
2630
- function identity(value) {
2631
- return value;
2632
- }
2633
- var listComponentPropsSystem = /*#__PURE__*/system(function () {
2634
- var itemContent = statefulStream(function (index) {
2635
- return "Item " + index;
2636
- });
2637
- var context = statefulStream(null);
2638
- var groupContent = statefulStream(function (index) {
2639
- return "Group " + index;
2640
- });
2641
- var components = statefulStream({});
2642
- var computeItemKey = statefulStream(identity);
2643
- var headerFooterTag = statefulStream('div');
2644
- var scrollerRef = statefulStream(noop);
2645
-
2646
- var distinctProp = function distinctProp(propName, defaultValue) {
2647
- if (defaultValue === void 0) {
2648
- defaultValue = null;
2649
- }
2650
-
2651
- return statefulStreamFromEmitter(pipe(components, map(function (components) {
2652
- return components[propName];
2653
- }), distinctUntilChanged()), defaultValue);
2654
- };
2655
-
2656
- return {
2657
- context: context,
2658
- itemContent: itemContent,
2659
- groupContent: groupContent,
2660
- components: components,
2661
- computeItemKey: computeItemKey,
2662
- headerFooterTag: headerFooterTag,
2663
- scrollerRef: scrollerRef,
2664
- FooterComponent: distinctProp('Footer'),
2665
- HeaderComponent: distinctProp('Header'),
2666
- TopItemListComponent: distinctProp('TopItemList'),
2667
- ListComponent: distinctProp('List', 'div'),
2668
- ItemComponent: distinctProp('Item', 'div'),
2669
- GroupComponent: distinctProp('Group', 'div'),
2670
- ScrollerComponent: distinctProp('Scroller', 'div'),
2671
- EmptyPlaceholder: distinctProp('EmptyPlaceholder'),
2672
- ScrollSeekPlaceholder: distinctProp('ScrollSeekPlaceholder')
2673
- };
2674
- });
2675
- function addDeprecatedAlias(prop, message) {
2676
- var alias = stream();
2677
- subscribe(alias, function () {
2678
- return console.warn("react-virtuoso: You are using a deprecated property. " + message, 'color: red;', 'color: inherit;', 'color: blue;');
2679
- });
2680
- connect(alias, prop);
2681
- return alias;
2682
- }
2683
- var combinedSystem$2 = /*#__PURE__*/system(function (_ref) {
2684
- var listSystem = _ref[0],
2685
- propsSystem = _ref[1];
2686
- var deprecatedProps = {
2687
- item: addDeprecatedAlias(propsSystem.itemContent, 'Rename the %citem%c prop to %citemContent.'),
2688
- group: addDeprecatedAlias(propsSystem.groupContent, 'Rename the %cgroup%c prop to %cgroupContent.'),
2689
- topItems: addDeprecatedAlias(listSystem.topItemCount, 'Rename the %ctopItems%c prop to %ctopItemCount.'),
2690
- itemHeight: addDeprecatedAlias(listSystem.fixedItemHeight, 'Rename the %citemHeight%c prop to %cfixedItemHeight.'),
2691
- scrollingStateChange: addDeprecatedAlias(listSystem.isScrolling, 'Rename the %cscrollingStateChange%c prop to %cisScrolling.'),
2692
- adjustForPrependedItems: stream(),
2693
- maxHeightCacheSize: stream(),
2694
- footer: stream(),
2695
- header: stream(),
2696
- HeaderContainer: stream(),
2697
- FooterContainer: stream(),
2698
- ItemContainer: stream(),
2699
- ScrollContainer: stream(),
2700
- GroupContainer: stream(),
2701
- ListContainer: stream(),
2702
- emptyComponent: stream(),
2703
- scrollSeek: stream()
2704
- };
2705
- subscribe(deprecatedProps.adjustForPrependedItems, function () {
2706
- console.warn("react-virtuoso: adjustForPrependedItems is no longer supported. Use the firstItemIndex property instead - https://virtuoso.dev/prepend-items.", 'color: red;', 'color: inherit;', 'color: blue;');
2707
- });
2708
- subscribe(deprecatedProps.maxHeightCacheSize, function () {
2709
- console.warn("react-virtuoso: maxHeightCacheSize is no longer necessary. Setting it has no effect - remove it from your code.");
2710
- });
2711
- subscribe(deprecatedProps.HeaderContainer, function () {
2712
- console.warn("react-virtuoso: HeaderContainer is deprecated. Use headerFooterTag if you want to change the wrapper of the header component and pass components.Header to change its contents.");
2713
- });
2714
- subscribe(deprecatedProps.FooterContainer, function () {
2715
- console.warn("react-virtuoso: FooterContainer is deprecated. Use headerFooterTag if you want to change the wrapper of the footer component and pass components.Footer to change its contents.");
2716
- });
2717
-
2718
- function deprecateComponentProp(stream, componentName, propName) {
2719
- connect(pipe(stream, withLatestFrom(propsSystem.components), map(function (_ref2) {
2720
- var _extends2;
2721
-
2722
- var comp = _ref2[0],
2723
- components = _ref2[1];
2724
- console.warn("react-virtuoso: " + propName + " property is deprecated. Pass components." + componentName + " instead."); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
2725
-
2726
- return _extends({}, components, (_extends2 = {}, _extends2[componentName] = comp, _extends2));
2727
- })), propsSystem.components);
2728
- }
2729
-
2730
- subscribe(deprecatedProps.scrollSeek, function (_ref3) {
2731
- var placeholder = _ref3.placeholder,
2732
- config = _objectWithoutPropertiesLoose(_ref3, ["placeholder"]);
2733
-
2734
- console.warn("react-virtuoso: scrollSeek property is deprecated. Pass scrollSeekConfiguration and specify the placeholder in components.ScrollSeekPlaceholder instead."); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
2735
-
2736
- publish(propsSystem.components, _extends({}, getValue(propsSystem.components), {
2737
- ScrollSeekPlaceholder: placeholder
2738
- }));
2739
- publish(listSystem.scrollSeekConfiguration, config);
2740
- });
2741
- deprecateComponentProp(deprecatedProps.footer, 'Footer', 'footer');
2742
- deprecateComponentProp(deprecatedProps.header, 'Header', 'header');
2743
- deprecateComponentProp(deprecatedProps.ItemContainer, 'Item', 'ItemContainer');
2744
- deprecateComponentProp(deprecatedProps.ListContainer, 'List', 'ListContainer');
2745
- deprecateComponentProp(deprecatedProps.ScrollContainer, 'Scroller', 'ScrollContainer');
2746
- deprecateComponentProp(deprecatedProps.emptyComponent, 'EmptyPlaceholder', 'emptyComponent');
2747
- deprecateComponentProp(deprecatedProps.GroupContainer, 'Group', 'GroupContainer');
2748
- return _extends({}, listSystem, propsSystem, deprecatedProps);
2749
- }, /*#__PURE__*/tup(listSystem, listComponentPropsSystem));
2750
-
2751
- var DefaultScrollSeekPlaceholder$1 = function DefaultScrollSeekPlaceholder(_ref4) {
2752
- var height = _ref4.height;
2753
- return React.createElement("div", {
2754
- style: {
2755
- height: height
2756
- }
2757
- });
2758
- };
2759
-
2760
- var GROUP_STYLE = {
2761
- position: /*#__PURE__*/positionStickyCssValue(),
2762
- zIndex: 1,
2763
- overflowAnchor: 'none'
2764
- };
2765
- var Items$1 = /*#__PURE__*/React.memo(function VirtuosoItems(_ref5) {
2766
- var _ref5$showTopList = _ref5.showTopList,
2767
- showTopList = _ref5$showTopList === void 0 ? false : _ref5$showTopList;
2768
- var listState = useEmitterValue$2('listState');
2769
- var deviation = useEmitterValue$2('deviation');
2770
- var sizeRanges = usePublisher$2('sizeRanges');
2771
- var useWindowScroll = useEmitterValue$2('useWindowScroll');
2772
- var customScrollParent = useEmitterValue$2('customScrollParent');
2773
- var windowScrollContainerStateCallback = usePublisher$2('windowScrollContainerState');
2774
-
2775
- var _scrollContainerStateCallback = usePublisher$2('scrollContainerState');
2776
-
2777
- var scrollContainerStateCallback = customScrollParent || useWindowScroll ? windowScrollContainerStateCallback : _scrollContainerStateCallback;
2778
- var itemContent = useEmitterValue$2('itemContent');
2779
- var context = useEmitterValue$2('context');
2780
- var groupContent = useEmitterValue$2('groupContent');
2781
- var trackItemSizes = useEmitterValue$2('trackItemSizes');
2782
- var itemSize = useEmitterValue$2('itemSize');
2783
- var log = useEmitterValue$2('log');
2784
- var ref = useChangedListContentsSizes(sizeRanges, itemSize, trackItemSizes, showTopList ? noop : scrollContainerStateCallback, log, customScrollParent);
2785
- var EmptyPlaceholder = useEmitterValue$2('EmptyPlaceholder');
2786
- var ScrollSeekPlaceholder = useEmitterValue$2('ScrollSeekPlaceholder') || DefaultScrollSeekPlaceholder$1;
2787
- var ListComponent = useEmitterValue$2('ListComponent');
2788
- var ItemComponent = useEmitterValue$2('ItemComponent');
2789
- var GroupComponent = useEmitterValue$2('GroupComponent');
2790
- var computeItemKey = useEmitterValue$2('computeItemKey');
2791
- var isSeeking = useEmitterValue$2('isSeeking');
2792
- var hasGroups = useEmitterValue$2('groupIndices').length > 0;
2793
- var paddingTopAddition = useEmitterValue$2('paddingTopAddition');
2794
- var firstItemIndex = useEmitterValue$2('firstItemIndex');
2795
- var statefulTotalCount = useEmitterValue$2('statefulTotalCount');
2796
- var containerStyle = showTopList ? {} : {
2797
- boxSizing: 'border-box',
2798
- paddingTop: listState.offsetTop + paddingTopAddition,
2799
- paddingBottom: listState.offsetBottom,
2800
- marginTop: deviation
2801
- };
2802
-
2803
- if (!showTopList && statefulTotalCount === 0 && EmptyPlaceholder) {
2804
- return createElement(EmptyPlaceholder, contextPropIfNotDomElement(EmptyPlaceholder, context));
2805
- }
2806
-
2807
- return createElement(ListComponent, _extends({}, contextPropIfNotDomElement(ListComponent, context), {
2808
- ref: ref,
2809
- style: containerStyle,
2810
- 'data-test-id': showTopList ? 'virtuoso-top-item-list' : 'virtuoso-item-list'
2811
- }), (showTopList ? listState.topItems : listState.items).map(function (item) {
2812
- var index = item.originalIndex;
2813
- var key = computeItemKey(index + firstItemIndex, item.data, context);
2814
-
2815
- if (isSeeking) {
2816
- return createElement(ScrollSeekPlaceholder, _extends({}, contextPropIfNotDomElement(ScrollSeekPlaceholder, context), {
2817
- key: key,
2818
- index: item.index,
2819
- height: item.size,
2820
- type: item.type || 'item'
2821
- }, item.type === 'group' ? {} : {
2822
- groupIndex: item.groupIndex
2823
- }));
2824
- }
2825
-
2826
- if (item.type === 'group') {
2827
- return createElement(GroupComponent, _extends({}, contextPropIfNotDomElement(GroupComponent, context), {
2828
- key: key,
2829
- 'data-index': index,
2830
- 'data-known-size': item.size,
2831
- 'data-item-index': item.index,
2832
- style: GROUP_STYLE
2833
- }), groupContent(item.index));
2834
- } else {
2835
- return createElement(ItemComponent, _extends({}, contextPropIfNotDomElement(ItemComponent, context), {
2836
- key: key,
2837
- 'data-index': index,
2838
- 'data-known-size': item.size,
2839
- 'data-item-index': item.index,
2840
- 'data-item-group-index': item.groupIndex,
2841
- style: {
2842
- overflowAnchor: 'none'
2843
- }
2844
- }), hasGroups ? itemContent(item.index, item.groupIndex, item.data, context) : itemContent(item.index, item.data, context));
2845
- }
2846
- }));
2847
- });
2848
- var scrollerStyle = {
2849
- height: '100%',
2850
- outline: 'none',
2851
- overflowY: 'auto',
2852
- position: 'relative',
2853
- WebkitOverflowScrolling: 'touch'
2854
- };
2855
- var viewportStyle = {
2856
- width: '100%',
2857
- height: '100%',
2858
- position: 'absolute',
2859
- top: 0
2860
- };
2861
- var topItemListStyle = {
2862
- width: '100%',
2863
- position: /*#__PURE__*/positionStickyCssValue(),
2864
- top: 0
2865
- };
2866
- function contextPropIfNotDomElement(element, context) {
2867
- if (typeof element === 'string') {
2868
- return undefined;
2869
- }
2870
-
2871
- return {
2872
- context: context
2873
- };
2874
- }
2875
- var Header = /*#__PURE__*/React.memo(function VirtuosoHeader() {
2876
- var Header = useEmitterValue$2('HeaderComponent');
2877
- var headerHeight = usePublisher$2('headerHeight');
2878
- var headerFooterTag = useEmitterValue$2('headerFooterTag');
2879
- var ref = useSize(function (el) {
2880
- return headerHeight(correctItemSize(el, 'height'));
2881
- });
2882
- var context = useEmitterValue$2('context');
2883
- return Header ? createElement(headerFooterTag, {
2884
- ref: ref
2885
- }, createElement(Header, contextPropIfNotDomElement(Header, context))) : null;
2886
- });
2887
- var Footer = /*#__PURE__*/React.memo(function VirtuosoFooter() {
2888
- var Footer = useEmitterValue$2('FooterComponent');
2889
- var footerHeight = usePublisher$2('footerHeight');
2890
- var headerFooterTag = useEmitterValue$2('headerFooterTag');
2891
- var ref = useSize(function (el) {
2892
- return footerHeight(correctItemSize(el, 'height'));
2893
- });
2894
- var context = useEmitterValue$2('context');
2895
- return Footer ? createElement(headerFooterTag, {
2896
- ref: ref
2897
- }, createElement(Footer, contextPropIfNotDomElement(Footer, context))) : null;
2898
- });
2899
- function buildScroller(_ref6) {
2900
- var usePublisher = _ref6.usePublisher,
2901
- useEmitter = _ref6.useEmitter,
2902
- useEmitterValue = _ref6.useEmitterValue;
2903
- var Scroller = React.memo(function VirtuosoScroller(_ref7) {
2904
- var style = _ref7.style,
2905
- children = _ref7.children,
2906
- props = _objectWithoutPropertiesLoose(_ref7, ["style", "children"]);
2907
-
2908
- var scrollContainerStateCallback = usePublisher('scrollContainerState');
2909
- var ScrollerComponent = useEmitterValue('ScrollerComponent');
2910
- var smoothScrollTargetReached = usePublisher('smoothScrollTargetReached');
2911
- var scrollerRefCallback = useEmitterValue('scrollerRef');
2912
- var context = useEmitterValue('context');
2913
-
2914
- var _useScrollTop = useScrollTop(scrollContainerStateCallback, smoothScrollTargetReached, ScrollerComponent, scrollerRefCallback),
2915
- scrollerRef = _useScrollTop.scrollerRef,
2916
- scrollByCallback = _useScrollTop.scrollByCallback,
2917
- scrollToCallback = _useScrollTop.scrollToCallback;
2918
-
2919
- useEmitter('scrollTo', scrollToCallback);
2920
- useEmitter('scrollBy', scrollByCallback);
2921
- return createElement(ScrollerComponent, _extends({
2922
- ref: scrollerRef,
2923
- style: _extends({}, scrollerStyle, style),
2924
- 'data-test-id': 'virtuoso-scroller',
2925
- 'data-virtuoso-scroller': true,
2926
- tabIndex: 0
2927
- }, props, contextPropIfNotDomElement(ScrollerComponent, context)), children);
2928
- });
2929
- return Scroller;
2930
- }
2931
- function buildWindowScroller(_ref8) {
2932
- var usePublisher = _ref8.usePublisher,
2933
- useEmitter = _ref8.useEmitter,
2934
- useEmitterValue = _ref8.useEmitterValue;
2935
- var Scroller = React.memo(function VirtuosoWindowScroller(_ref9) {
2936
- var style = _ref9.style,
2937
- children = _ref9.children,
2938
- props = _objectWithoutPropertiesLoose(_ref9, ["style", "children"]);
2939
-
2940
- var scrollContainerStateCallback = usePublisher('windowScrollContainerState');
2941
- var ScrollerComponent = useEmitterValue('ScrollerComponent');
2942
- var smoothScrollTargetReached = usePublisher('smoothScrollTargetReached');
2943
- var totalListHeight = useEmitterValue('totalListHeight');
2944
- var deviation = useEmitterValue('deviation');
2945
- var customScrollParent = useEmitterValue('customScrollParent');
2946
- var context = useEmitterValue('context');
2947
-
2948
- var _useScrollTop2 = useScrollTop(scrollContainerStateCallback, smoothScrollTargetReached, ScrollerComponent, noop, customScrollParent),
2949
- scrollerRef = _useScrollTop2.scrollerRef,
2950
- scrollByCallback = _useScrollTop2.scrollByCallback,
2951
- scrollToCallback = _useScrollTop2.scrollToCallback;
2952
-
2953
- useIsomorphicLayoutEffect(function () {
2954
- scrollerRef.current = customScrollParent ? customScrollParent : window;
2955
- return function () {
2956
- scrollerRef.current = null;
2957
- };
2958
- }, [scrollerRef, customScrollParent]);
2959
- useEmitter('windowScrollTo', scrollToCallback);
2960
- useEmitter('scrollBy', scrollByCallback);
2961
- return createElement(ScrollerComponent, _extends({
2962
- style: _extends({
2963
- position: 'relative'
2964
- }, style, totalListHeight !== 0 ? {
2965
- height: totalListHeight + deviation
2966
- } : {}),
2967
- 'data-virtuoso-scroller': true
2968
- }, props, contextPropIfNotDomElement(ScrollerComponent, context)), children);
2969
- });
2970
- return Scroller;
2971
- }
2972
-
2973
- var Viewport$2 = function Viewport(_ref10) {
2974
- var children = _ref10.children;
2975
- var viewportHeight = usePublisher$2('viewportHeight');
2976
- var viewportRef = useSize(compose(viewportHeight, function (el) {
2977
- return correctItemSize(el, 'height');
2978
- }));
2979
- return React.createElement("div", {
2980
- style: viewportStyle,
2981
- ref: viewportRef,
2982
- "data-viewport-type": "element"
2983
- }, children);
2984
- };
2985
-
2986
- var WindowViewport$2 = function WindowViewport(_ref11) {
2987
- var children = _ref11.children;
2988
- var windowViewportRect = usePublisher$2('windowViewportRect');
2989
- var customScrollParent = useEmitterValue$2('customScrollParent');
2990
- var viewportRef = useWindowViewportRectRef(windowViewportRect, customScrollParent);
2991
- return React.createElement("div", {
2992
- ref: viewportRef,
2993
- style: viewportStyle,
2994
- "data-viewport-type": "window"
2995
- }, children);
2996
- };
2997
-
2998
- var TopItemListContainer = function TopItemListContainer(_ref12) {
2999
- var children = _ref12.children;
3000
- var TopItemList = useEmitterValue$2('TopItemListComponent');
3001
- var headerHeight = useEmitterValue$2('headerHeight');
3002
-
3003
- var style = _extends({}, topItemListStyle, {
3004
- marginTop: headerHeight + "px"
3005
- });
3006
-
3007
- var context = useEmitterValue$2('context');
3008
- return createElement(TopItemList || 'div', {
3009
- style: style,
3010
- context: context
3011
- }, children);
3012
- };
3013
-
3014
- var ListRoot = /*#__PURE__*/React.memo(function VirtuosoRoot(props) {
3015
- var useWindowScroll = useEmitterValue$2('useWindowScroll');
3016
- var showTopList = useEmitterValue$2('topItemsIndexes').length > 0;
3017
- var customScrollParent = useEmitterValue$2('customScrollParent');
3018
- var TheScroller = customScrollParent || useWindowScroll ? WindowScroller$2 : Scroller$2;
3019
- var TheViewport = customScrollParent || useWindowScroll ? WindowViewport$2 : Viewport$2;
3020
- return React.createElement(TheScroller, _extends({}, props), React.createElement(TheViewport, null, React.createElement(Header, null), React.createElement(Items$1, null), React.createElement(Footer, null)), showTopList && React.createElement(TopItemListContainer, null, React.createElement(Items$1, {
3021
- showTopList: true
3022
- })));
3023
- });
3024
-
3025
- var _systemToComponent$2 = /*#__PURE__*/systemToComponent(combinedSystem$2, {
3026
- required: {},
3027
- optional: {
3028
- context: 'context',
3029
- followOutput: 'followOutput',
3030
- firstItemIndex: 'firstItemIndex',
3031
- itemContent: 'itemContent',
3032
- groupContent: 'groupContent',
3033
- overscan: 'overscan',
3034
- increaseViewportBy: 'increaseViewportBy',
3035
- totalCount: 'totalCount',
3036
- topItemCount: 'topItemCount',
3037
- initialTopMostItemIndex: 'initialTopMostItemIndex',
3038
- components: 'components',
3039
- groupCounts: 'groupCounts',
3040
- atBottomThreshold: 'atBottomThreshold',
3041
- computeItemKey: 'computeItemKey',
3042
- defaultItemHeight: 'defaultItemHeight',
3043
- fixedItemHeight: 'fixedItemHeight',
3044
- itemSize: 'itemSize',
3045
- scrollSeekConfiguration: 'scrollSeekConfiguration',
3046
- headerFooterTag: 'headerFooterTag',
3047
- data: 'data',
3048
- initialItemCount: 'initialItemCount',
3049
- initialScrollTop: 'initialScrollTop',
3050
- alignToBottom: 'alignToBottom',
3051
- useWindowScroll: 'useWindowScroll',
3052
- customScrollParent: 'customScrollParent',
3053
- scrollerRef: 'scrollerRef',
3054
- logLevel: 'logLevel',
3055
- // deprecated
3056
- item: 'item',
3057
- group: 'group',
3058
- topItems: 'topItems',
3059
- itemHeight: 'itemHeight',
3060
- scrollingStateChange: 'scrollingStateChange',
3061
- maxHeightCacheSize: 'maxHeightCacheSize',
3062
- footer: 'footer',
3063
- header: 'header',
3064
- ItemContainer: 'ItemContainer',
3065
- ScrollContainer: 'ScrollContainer',
3066
- ListContainer: 'ListContainer',
3067
- GroupContainer: 'GroupContainer',
3068
- emptyComponent: 'emptyComponent',
3069
- HeaderContainer: 'HeaderContainer',
3070
- FooterContainer: 'FooterContainer',
3071
- scrollSeek: 'scrollSeek'
3072
- },
3073
- methods: {
3074
- scrollToIndex: 'scrollToIndex',
3075
- scrollIntoView: 'scrollIntoView',
3076
- scrollTo: 'scrollTo',
3077
- scrollBy: 'scrollBy',
3078
- adjustForPrependedItems: 'adjustForPrependedItems'
3079
- },
3080
- events: {
3081
- isScrolling: 'isScrolling',
3082
- endReached: 'endReached',
3083
- startReached: 'startReached',
3084
- rangeChanged: 'rangeChanged',
3085
- atBottomStateChange: 'atBottomStateChange',
3086
- atTopStateChange: 'atTopStateChange',
3087
- totalListHeightChanged: 'totalListHeightChanged',
3088
- itemsRendered: 'itemsRendered',
3089
- groupIndices: 'groupIndices'
3090
- }
3091
- }, ListRoot),
3092
- List = _systemToComponent$2.Component,
3093
- usePublisher$2 = _systemToComponent$2.usePublisher,
3094
- useEmitterValue$2 = _systemToComponent$2.useEmitterValue,
3095
- useEmitter$2 = _systemToComponent$2.useEmitter;
3096
- var Scroller$2 = /*#__PURE__*/buildScroller({
3097
- usePublisher: usePublisher$2,
3098
- useEmitterValue: useEmitterValue$2,
3099
- useEmitter: useEmitter$2
3100
- });
3101
- var WindowScroller$2 = /*#__PURE__*/buildWindowScroller({
3102
- usePublisher: usePublisher$2,
3103
- useEmitterValue: useEmitterValue$2,
3104
- useEmitter: useEmitter$2
3105
- });
3106
-
3107
- var Virtuoso = List;
3108
-
3109
- var GroupedVirtuoso = List;
3110
-
3111
- var tableComponentPropsSystem = /*#__PURE__*/system(function () {
3112
- var itemContent = statefulStream(function (index) {
3113
- return React.createElement("td", null, "Item $", index);
3114
- });
3115
- var context = statefulStream(null);
3116
- var fixedHeaderContent = statefulStream(null);
3117
- var components = statefulStream({});
3118
- var computeItemKey = statefulStream(identity);
3119
- var scrollerRef = statefulStream(noop);
3120
-
3121
- var distinctProp = function distinctProp(propName, defaultValue) {
3122
- if (defaultValue === void 0) {
3123
- defaultValue = null;
3124
- }
3125
-
3126
- return statefulStreamFromEmitter(pipe(components, map(function (components) {
3127
- return components[propName];
3128
- }), distinctUntilChanged()), defaultValue);
3129
- };
3130
-
3131
- return {
3132
- context: context,
3133
- itemContent: itemContent,
3134
- fixedHeaderContent: fixedHeaderContent,
3135
- components: components,
3136
- computeItemKey: computeItemKey,
3137
- scrollerRef: scrollerRef,
3138
- TableComponent: distinctProp('Table', 'table'),
3139
- TableHeadComponent: distinctProp('TableHead', 'thead'),
3140
- TableBodyComponent: distinctProp('TableBody', 'tbody'),
3141
- TableRowComponent: distinctProp('TableRow', 'tr'),
3142
- ScrollerComponent: distinctProp('Scroller', 'div'),
3143
- EmptyPlaceholder: distinctProp('EmptyPlaceholder'),
3144
- ScrollSeekPlaceholder: distinctProp('ScrollSeekPlaceholder')
3145
- };
3146
- });
3147
- var combinedSystem$1 = /*#__PURE__*/system(function (_ref) {
3148
- var listSystem = _ref[0],
3149
- propsSystem = _ref[1];
3150
- return _extends({}, listSystem, propsSystem);
3151
- }, /*#__PURE__*/tup(listSystem, tableComponentPropsSystem));
3152
-
3153
- var DefaultScrollSeekPlaceholder = function DefaultScrollSeekPlaceholder(_ref2) {
3154
- var height = _ref2.height;
3155
- return React.createElement("tr", null, React.createElement("td", {
3156
- style: {
3157
- height: height
3158
- }
3159
- }));
3160
- };
3161
-
3162
- var FillerRow = function FillerRow(_ref3) {
3163
- var height = _ref3.height;
3164
- return React.createElement("tr", null, React.createElement("td", {
3165
- style: {
3166
- height: height,
3167
- padding: 0,
3168
- border: 0
3169
- }
3170
- }));
3171
- };
3172
-
3173
- var Items = /*#__PURE__*/React.memo(function VirtuosoItems() {
3174
- var listState = useEmitterValue$1('listState');
3175
- var deviation = useEmitterValue$1('deviation');
3176
- var sizeRanges = usePublisher$1('sizeRanges');
3177
- var useWindowScroll = useEmitterValue$1('useWindowScroll');
3178
- var customScrollParent = useEmitterValue$1('customScrollParent');
3179
- var windowScrollContainerStateCallback = usePublisher$1('windowScrollContainerState');
3180
-
3181
- var _scrollContainerStateCallback = usePublisher$1('scrollContainerState');
3182
-
3183
- var scrollContainerStateCallback = customScrollParent || useWindowScroll ? windowScrollContainerStateCallback : _scrollContainerStateCallback;
3184
- var itemContent = useEmitterValue$1('itemContent');
3185
- var trackItemSizes = useEmitterValue$1('trackItemSizes');
3186
- var itemSize = useEmitterValue$1('itemSize');
3187
- var log = useEmitterValue$1('log');
3188
- var ref = useChangedListContentsSizes(sizeRanges, itemSize, trackItemSizes, scrollContainerStateCallback, log, customScrollParent);
3189
- var EmptyPlaceholder = useEmitterValue$1('EmptyPlaceholder');
3190
- var ScrollSeekPlaceholder = useEmitterValue$1('ScrollSeekPlaceholder') || DefaultScrollSeekPlaceholder;
3191
- var TableBodyComponent = useEmitterValue$1('TableBodyComponent');
3192
- var TableRowComponent = useEmitterValue$1('TableRowComponent');
3193
- var computeItemKey = useEmitterValue$1('computeItemKey');
3194
- var isSeeking = useEmitterValue$1('isSeeking');
3195
- var paddingTopAddition = useEmitterValue$1('paddingTopAddition');
3196
- var firstItemIndex = useEmitterValue$1('firstItemIndex');
3197
- var statefulTotalCount = useEmitterValue$1('statefulTotalCount');
3198
- var context = useEmitterValue$1('context');
3199
-
3200
- if (statefulTotalCount === 0 && EmptyPlaceholder) {
3201
- return createElement(EmptyPlaceholder, contextPropIfNotDomElement(EmptyPlaceholder, context));
3202
- }
3203
-
3204
- var paddingTop = listState.offsetTop + paddingTopAddition + deviation;
3205
- var paddingBottom = listState.offsetBottom;
3206
- var paddingTopEl = paddingTop > 0 ? React.createElement(FillerRow, {
3207
- height: paddingTop,
3208
- key: "padding-top"
3209
- }) : null;
3210
- var paddingBottomEl = paddingBottom > 0 ? React.createElement(FillerRow, {
3211
- height: paddingBottom,
3212
- key: "padding-bottom"
3213
- }) : null;
3214
- var items = listState.items.map(function (item) {
3215
- var index = item.originalIndex;
3216
- var key = computeItemKey(index + firstItemIndex, item.data, context);
3217
-
3218
- if (isSeeking) {
3219
- return createElement(ScrollSeekPlaceholder, _extends({}, contextPropIfNotDomElement(ScrollSeekPlaceholder, context), {
3220
- key: key,
3221
- index: item.index,
3222
- height: item.size,
3223
- type: item.type || 'item'
3224
- }));
3225
- }
3226
-
3227
- return createElement(TableRowComponent, _extends({}, contextPropIfNotDomElement(TableRowComponent, context), {
3228
- key: key,
3229
- 'data-index': index,
3230
- 'data-known-size': item.size,
3231
- 'data-item-index': item.index,
3232
- style: {
3233
- overflowAnchor: 'none'
3234
- }
3235
- }), itemContent(item.index, item.data, context));
3236
- });
3237
- return createElement(TableBodyComponent, _extends({
3238
- ref: ref,
3239
- 'data-test-id': 'virtuoso-item-list'
3240
- }, contextPropIfNotDomElement(TableBodyComponent, context)), [paddingTopEl].concat(items, [paddingBottomEl]));
3241
- });
3242
-
3243
- var Viewport$1 = function Viewport(_ref4) {
3244
- var children = _ref4.children;
3245
- var viewportHeight = usePublisher$1('viewportHeight');
3246
- var viewportRef = useSize(compose(viewportHeight, function (el) {
3247
- return correctItemSize(el, 'height');
3248
- }));
3249
- return React.createElement("div", {
3250
- style: viewportStyle,
3251
- ref: viewportRef,
3252
- "data-viewport-type": "element"
3253
- }, children);
3254
- };
3255
-
3256
- var WindowViewport$1 = function WindowViewport(_ref5) {
3257
- var children = _ref5.children;
3258
- var windowViewportRect = usePublisher$1('windowViewportRect');
3259
- var customScrollParent = useEmitterValue$1('customScrollParent');
3260
- var viewportRef = useWindowViewportRectRef(windowViewportRect, customScrollParent);
3261
- return React.createElement("div", {
3262
- ref: viewportRef,
3263
- style: viewportStyle,
3264
- "data-viewport-type": "window"
3265
- }, children);
3266
- };
3267
-
3268
- var TableRoot = /*#__PURE__*/React.memo(function TableVirtuosoRoot(props) {
3269
- var useWindowScroll = useEmitterValue$1('useWindowScroll');
3270
- var customScrollParent = useEmitterValue$1('customScrollParent');
3271
- var fixedHeaderHeight = usePublisher$1('fixedHeaderHeight');
3272
- var fixedHeaderContent = useEmitterValue$1('fixedHeaderContent');
3273
- var context = useEmitterValue$1('context');
3274
- var theadRef = useSize(compose(fixedHeaderHeight, function (el) {
3275
- return correctItemSize(el, 'height');
3276
- }));
3277
- var TheScroller = customScrollParent || useWindowScroll ? WindowScroller$1 : Scroller$1;
3278
- var TheViewport = customScrollParent || useWindowScroll ? WindowViewport$1 : Viewport$1;
3279
- var TheTable = useEmitterValue$1('TableComponent');
3280
- var TheTHead = useEmitterValue$1('TableHeadComponent');
3281
- var theHead = fixedHeaderContent ? React.createElement(TheTHead, _extends({
3282
- key: 'TableHead',
3283
- style: {
3284
- zIndex: 1,
3285
- position: 'sticky',
3286
- top: 0
3287
- },
3288
- ref: theadRef
3289
- }, contextPropIfNotDomElement(TheTHead, context)), fixedHeaderContent()) : null;
3290
- return React.createElement(TheScroller, _extends({}, props), React.createElement(TheViewport, null, React.createElement(TheTable, _extends({
3291
- style: {
3292
- borderSpacing: 0
3293
- }
3294
- }, contextPropIfNotDomElement(TheTable, context)), [theHead, React.createElement(Items, {
3295
- key: "TableBody"
3296
- })])));
3297
- });
3298
-
3299
- var _systemToComponent$1 = /*#__PURE__*/systemToComponent(combinedSystem$1, {
3300
- required: {},
3301
- optional: {
3302
- context: 'context',
3303
- followOutput: 'followOutput',
3304
- firstItemIndex: 'firstItemIndex',
3305
- itemContent: 'itemContent',
3306
- fixedHeaderContent: 'fixedHeaderContent',
3307
- overscan: 'overscan',
3308
- increaseViewportBy: 'increaseViewportBy',
3309
- totalCount: 'totalCount',
3310
- topItemCount: 'topItemCount',
3311
- initialTopMostItemIndex: 'initialTopMostItemIndex',
3312
- components: 'components',
3313
- groupCounts: 'groupCounts',
3314
- atBottomThreshold: 'atBottomThreshold',
3315
- computeItemKey: 'computeItemKey',
3316
- defaultItemHeight: 'defaultItemHeight',
3317
- fixedItemHeight: 'fixedItemHeight',
3318
- itemSize: 'itemSize',
3319
- scrollSeekConfiguration: 'scrollSeekConfiguration',
3320
- data: 'data',
3321
- initialItemCount: 'initialItemCount',
3322
- initialScrollTop: 'initialScrollTop',
3323
- alignToBottom: 'alignToBottom',
3324
- useWindowScroll: 'useWindowScroll',
3325
- customScrollParent: 'customScrollParent',
3326
- scrollerRef: 'scrollerRef',
3327
- logLevel: 'logLevel'
3328
- },
3329
- methods: {
3330
- scrollToIndex: 'scrollToIndex',
3331
- scrollIntoView: 'scrollIntoView',
3332
- scrollTo: 'scrollTo',
3333
- scrollBy: 'scrollBy'
3334
- },
3335
- events: {
3336
- isScrolling: 'isScrolling',
3337
- endReached: 'endReached',
3338
- startReached: 'startReached',
3339
- rangeChanged: 'rangeChanged',
3340
- atBottomStateChange: 'atBottomStateChange',
3341
- atTopStateChange: 'atTopStateChange',
3342
- totalListHeightChanged: 'totalListHeightChanged',
3343
- itemsRendered: 'itemsRendered',
3344
- groupIndices: 'groupIndices'
3345
- }
3346
- }, TableRoot),
3347
- Table = _systemToComponent$1.Component,
3348
- usePublisher$1 = _systemToComponent$1.usePublisher,
3349
- useEmitterValue$1 = _systemToComponent$1.useEmitterValue,
3350
- useEmitter$1 = _systemToComponent$1.useEmitter;
3351
- var Scroller$1 = /*#__PURE__*/buildScroller({
3352
- usePublisher: usePublisher$1,
3353
- useEmitterValue: useEmitterValue$1,
3354
- useEmitter: useEmitter$1
3355
- });
3356
- var WindowScroller$1 = /*#__PURE__*/buildWindowScroller({
3357
- usePublisher: usePublisher$1,
3358
- useEmitterValue: useEmitterValue$1,
3359
- useEmitter: useEmitter$1
3360
- });
3361
-
3362
- var TableVirtuoso = Table;
3363
-
3364
- var INITIAL_GRID_STATE = {
3365
- items: [],
3366
- offsetBottom: 0,
3367
- offsetTop: 0,
3368
- top: 0,
3369
- bottom: 0,
3370
- itemHeight: 0,
3371
- itemWidth: 0
3372
- };
3373
- var PROBE_GRID_STATE = {
3374
- items: [{
3375
- index: 0
3376
- }],
3377
- offsetBottom: 0,
3378
- offsetTop: 0,
3379
- top: 0,
3380
- bottom: 0,
3381
- itemHeight: 0,
3382
- itemWidth: 0
3383
- };
3384
- var ceil = Math.ceil,
3385
- floor = Math.floor,
3386
- min = Math.min,
3387
- max = Math.max;
3388
-
3389
- function buildItems(startIndex, endIndex) {
3390
- return Array.from({
3391
- length: endIndex - startIndex + 1
3392
- }).map(function (_, i) {
3393
- return {
3394
- index: i + startIndex
3395
- };
3396
- });
3397
- }
3398
-
3399
- var gridSystem = /*#__PURE__*/u.system(function (_ref) {
3400
- var _ref$ = _ref[0],
3401
- overscan = _ref$.overscan,
3402
- visibleRange = _ref$.visibleRange,
3403
- listBoundary = _ref$.listBoundary,
3404
- _ref$2 = _ref[1],
3405
- scrollTop = _ref$2.scrollTop,
3406
- viewportHeight = _ref$2.viewportHeight,
3407
- scrollBy = _ref$2.scrollBy,
3408
- scrollTo = _ref$2.scrollTo,
3409
- smoothScrollTargetReached = _ref$2.smoothScrollTargetReached,
3410
- scrollContainerState = _ref$2.scrollContainerState,
3411
- stateFlags = _ref[2],
3412
- scrollSeek = _ref[3],
3413
- _ref$3 = _ref[4],
3414
- propsReady = _ref$3.propsReady,
3415
- didMount = _ref$3.didMount,
3416
- _ref$4 = _ref[5],
3417
- windowViewportRect = _ref$4.windowViewportRect,
3418
- windowScrollTo = _ref$4.windowScrollTo,
3419
- useWindowScroll = _ref$4.useWindowScroll,
3420
- customScrollParent = _ref$4.customScrollParent,
3421
- windowScrollContainerState = _ref$4.windowScrollContainerState;
3422
- var totalCount = u.statefulStream(0);
3423
- var initialItemCount = u.statefulStream(0);
3424
- var gridState = u.statefulStream(INITIAL_GRID_STATE);
3425
- var viewportDimensions = u.statefulStream({
3426
- height: 0,
3427
- width: 0
3428
- });
3429
- var itemDimensions = u.statefulStream({
3430
- height: 0,
3431
- width: 0
3432
- });
3433
- var scrollToIndex = u.stream();
3434
- var scrollHeight = u.stream();
3435
- var deviation = u.statefulStream(0);
3436
- u.connect(u.pipe(didMount, u.withLatestFrom(initialItemCount), u.filter(function (_ref2) {
3437
- var count = _ref2[1];
3438
- return count !== 0;
3439
- }), u.map(function (_ref3) {
3440
- var count = _ref3[1];
3441
- return {
3442
- items: buildItems(0, count - 1),
3443
- top: 0,
3444
- bottom: 0,
3445
- offsetBottom: 0,
3446
- offsetTop: 0,
3447
- itemHeight: 0,
3448
- itemWidth: 0
3449
- };
3450
- })), gridState);
3451
- u.connect(u.pipe(u.combineLatest(u.duc(totalCount), visibleRange, u.duc(itemDimensions, function (prev, next) {
3452
- return prev && prev.width === next.width && prev.height === next.height;
3453
- })), u.withLatestFrom(viewportDimensions), u.map(function (_ref4) {
3454
- var _ref4$ = _ref4[0],
3455
- totalCount = _ref4$[0],
3456
- _ref4$$ = _ref4$[1],
3457
- startOffset = _ref4$$[0],
3458
- endOffset = _ref4$$[1],
3459
- item = _ref4$[2],
3460
- viewport = _ref4[1];
3461
- var itemHeight = item.height,
3462
- itemWidth = item.width;
3463
- var viewportWidth = viewport.width;
3464
-
3465
- if (totalCount === 0 || viewportWidth === 0) {
3466
- return INITIAL_GRID_STATE;
3467
- }
3468
-
3469
- if (itemWidth === 0) {
3470
- return PROBE_GRID_STATE;
3471
- }
3472
-
3473
- var perRow = Math.floor(viewportWidth / itemWidth);
3474
- var startIndex = perRow * floor(startOffset / itemHeight);
3475
- var endIndex = perRow * ceil(endOffset / itemHeight) - 1;
3476
- endIndex = min(totalCount - 1, endIndex);
3477
- startIndex = min(endIndex, max(0, startIndex));
3478
- var items = buildItems(startIndex, endIndex);
3479
-
3480
- var _gridLayout = gridLayout(viewport, item, items),
3481
- top = _gridLayout.top,
3482
- bottom = _gridLayout.bottom;
3483
-
3484
- var totalHeight = ceil(totalCount / perRow) * itemHeight;
3485
- var offsetBottom = totalHeight - bottom;
3486
- return {
3487
- items: items,
3488
- offsetTop: top,
3489
- offsetBottom: offsetBottom,
3490
- top: top,
3491
- bottom: bottom,
3492
- itemHeight: itemHeight,
3493
- itemWidth: itemWidth
3494
- };
3495
- })), gridState);
3496
- u.connect(u.pipe(viewportDimensions, u.map(function (_ref5) {
3497
- var height = _ref5.height;
3498
- return height;
3499
- })), viewportHeight);
3500
- u.connect(u.pipe(u.combineLatest(viewportDimensions, itemDimensions, gridState), u.map(function (_ref6) {
3501
- var viewportDimensions = _ref6[0],
3502
- item = _ref6[1],
3503
- items = _ref6[2].items;
3504
-
3505
- var _gridLayout2 = gridLayout(viewportDimensions, item, items),
3506
- top = _gridLayout2.top,
3507
- bottom = _gridLayout2.bottom;
3508
-
3509
- return [top, bottom];
3510
- }), u.distinctUntilChanged(tupleComparator)), listBoundary);
3511
- var endReached = u.streamFromEmitter(u.pipe(u.duc(gridState), u.filter(function (_ref7) {
3512
- var items = _ref7.items;
3513
- return items.length > 0;
3514
- }), u.withLatestFrom(totalCount), u.filter(function (_ref8) {
3515
- var items = _ref8[0].items,
3516
- totalCount = _ref8[1];
3517
- return items[items.length - 1].index === totalCount - 1;
3518
- }), u.map(function (_ref9) {
3519
- var totalCount = _ref9[1];
3520
- return totalCount - 1;
3521
- }), u.distinctUntilChanged()));
3522
- var startReached = u.streamFromEmitter(u.pipe(u.duc(gridState), u.filter(function (_ref10) {
3523
- var items = _ref10.items;
3524
- return items.length > 0 && items[0].index === 0;
3525
- }), u.mapTo(0), u.distinctUntilChanged()));
3526
- var rangeChanged = u.streamFromEmitter(u.pipe(u.duc(gridState), u.filter(function (_ref11) {
3527
- var items = _ref11.items;
3528
- return items.length > 0;
3529
- }), u.map(function (_ref12) {
3530
- var items = _ref12.items;
3531
- return {
3532
- startIndex: items[0].index,
3533
- endIndex: items[items.length - 1].index
3534
- };
3535
- }), u.distinctUntilChanged(rangeComparator)));
3536
- u.connect(rangeChanged, scrollSeek.scrollSeekRangeChanged);
3537
- u.connect(u.pipe(scrollToIndex, u.withLatestFrom(viewportDimensions, itemDimensions, totalCount), u.map(function (_ref13) {
3538
- var location = _ref13[0],
3539
- viewport = _ref13[1],
3540
- item = _ref13[2],
3541
- totalCount = _ref13[3];
3542
- var normalLocation = normalizeIndexLocation(location);
3543
- var align = normalLocation.align,
3544
- behavior = normalLocation.behavior,
3545
- offset = normalLocation.offset;
3546
- var index = normalLocation.index;
3547
-
3548
- if (index === 'LAST') {
3549
- index = totalCount - 1;
3550
- }
3551
-
3552
- index = Math.max(0, index, Math.min(totalCount - 1, index));
3553
- var top = itemTop(viewport, item, index);
3554
-
3555
- if (align === 'end') {
3556
- top = Math.round(top - viewport.height + item.height);
3557
- } else if (align === 'center') {
3558
- top = Math.round(top - viewport.height / 2 + item.height / 2);
3559
- }
3560
-
3561
- if (offset) {
3562
- top += offset;
3563
- }
3564
-
3565
- return {
3566
- top: top,
3567
- behavior: behavior
3568
- };
3569
- })), scrollTo);
3570
- var totalListHeight = u.statefulStreamFromEmitter(u.pipe(gridState, u.map(function (gridState) {
3571
- return gridState.offsetBottom + gridState.bottom;
3572
- })), 0);
3573
- u.connect(u.pipe(windowViewportRect, u.map(function (viewportInfo) {
3574
- return {
3575
- width: viewportInfo.visibleWidth,
3576
- height: viewportInfo.visibleHeight
3577
- };
3578
- })), viewportDimensions);
3579
- return _extends({
3580
- // input
3581
- totalCount: totalCount,
3582
- viewportDimensions: viewportDimensions,
3583
- itemDimensions: itemDimensions,
3584
- scrollTop: scrollTop,
3585
- scrollHeight: scrollHeight,
3586
- overscan: overscan,
3587
- scrollBy: scrollBy,
3588
- scrollTo: scrollTo,
3589
- scrollToIndex: scrollToIndex,
3590
- smoothScrollTargetReached: smoothScrollTargetReached,
3591
- windowViewportRect: windowViewportRect,
3592
- windowScrollTo: windowScrollTo,
3593
- useWindowScroll: useWindowScroll,
3594
- customScrollParent: customScrollParent,
3595
- windowScrollContainerState: windowScrollContainerState,
3596
- deviation: deviation,
3597
- scrollContainerState: scrollContainerState,
3598
- initialItemCount: initialItemCount
3599
- }, scrollSeek, {
3600
- // output
3601
- gridState: gridState,
3602
- totalListHeight: totalListHeight
3603
- }, stateFlags, {
3604
- startReached: startReached,
3605
- endReached: endReached,
3606
- rangeChanged: rangeChanged,
3607
- propsReady: propsReady
3608
- });
3609
- }, /*#__PURE__*/u.tup(sizeRangeSystem, domIOSystem, stateFlagsSystem, scrollSeekSystem, propsReadySystem, windowScrollerSystem));
3610
-
3611
- function gridLayout(viewport, item, items) {
3612
- var itemHeight = item.height;
3613
-
3614
- if (itemHeight === undefined || items.length === 0) {
3615
- return {
3616
- top: 0,
3617
- bottom: 0
3618
- };
3619
- }
3620
-
3621
- var top = itemTop(viewport, item, items[0].index);
3622
- var bottom = itemTop(viewport, item, items[items.length - 1].index) + itemHeight;
3623
- return {
3624
- top: top,
3625
- bottom: bottom
3626
- };
3627
- }
3628
-
3629
- function itemTop(viewport, item, index) {
3630
- var perRow = itemsPerRow(viewport.width, item.width);
3631
- return floor(index / perRow) * item.height;
3632
- }
3633
-
3634
- function itemsPerRow(viewportWidth, itemWidth) {
3635
- return Math.floor(viewportWidth / itemWidth);
3636
- }
3637
-
3638
- var gridComponentPropsSystem = /*#__PURE__*/u.system(function () {
3639
- var itemContent = u.statefulStream(function (index) {
3640
- return "Item " + index;
3641
- });
3642
- var components = u.statefulStream({});
3643
- var context = u.statefulStream(null);
3644
- var itemClassName = u.statefulStream('virtuoso-grid-item');
3645
- var listClassName = u.statefulStream('virtuoso-grid-list');
3646
- var computeItemKey = u.statefulStream(identity);
3647
- var scrollerRef = u.statefulStream(u.noop);
3648
-
3649
- var distinctProp = function distinctProp(propName, defaultValue) {
3650
- if (defaultValue === void 0) {
3651
- defaultValue = null;
3652
- }
3653
-
3654
- return u.statefulStreamFromEmitter(u.pipe(components, u.map(function (components) {
3655
- return components[propName];
3656
- }), u.distinctUntilChanged()), defaultValue);
3657
- };
3658
-
3659
- return {
3660
- context: context,
3661
- itemContent: itemContent,
3662
- components: components,
3663
- computeItemKey: computeItemKey,
3664
- itemClassName: itemClassName,
3665
- listClassName: listClassName,
3666
- scrollerRef: scrollerRef,
3667
- ListComponent: distinctProp('List', 'div'),
3668
- ItemComponent: distinctProp('Item', 'div'),
3669
- ScrollerComponent: distinctProp('Scroller', 'div'),
3670
- ScrollSeekPlaceholder: distinctProp('ScrollSeekPlaceholder', 'div')
3671
- };
3672
- });
3673
- var combinedSystem = /*#__PURE__*/u.system(function (_ref) {
3674
- var gridSystem = _ref[0],
3675
- gridComponentPropsSystem = _ref[1];
3676
- var deprecatedProps = {
3677
- item: addDeprecatedAlias(gridComponentPropsSystem.itemContent, 'Rename the %citem%c prop to %citemContent.'),
3678
- ItemContainer: u.stream(),
3679
- ScrollContainer: u.stream(),
3680
- ListContainer: u.stream(),
3681
- emptyComponent: u.stream(),
3682
- scrollSeek: u.stream()
3683
- };
3684
-
3685
- function deprecateComponentProp(stream, componentName, propName) {
3686
- u.connect(u.pipe(stream, u.withLatestFrom(gridComponentPropsSystem.components), u.map(function (_ref2) {
3687
- var _extends2;
3688
-
3689
- var comp = _ref2[0],
3690
- components = _ref2[1];
3691
- console.warn("react-virtuoso: " + propName + " property is deprecated. Pass components." + componentName + " instead."); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
3692
-
3693
- return _extends({}, components, (_extends2 = {}, _extends2[componentName] = comp, _extends2));
3694
- })), gridComponentPropsSystem.components);
3695
- }
3696
-
3697
- u.subscribe(deprecatedProps.scrollSeek, function (_ref3) {
3698
- var placeholder = _ref3.placeholder,
3699
- config = _objectWithoutPropertiesLoose(_ref3, ["placeholder"]);
3700
-
3701
- console.warn("react-virtuoso: scrollSeek property is deprecated. Pass scrollSeekConfiguration and specify the placeholder in components.ScrollSeekPlaceholder instead.");
3702
- u.publish(gridComponentPropsSystem.components, _extends({}, u.getValue(gridComponentPropsSystem.components), {
3703
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
3704
- ScrollSeekPlaceholder: placeholder
3705
- }));
3706
- u.publish(gridSystem.scrollSeekConfiguration, config);
3707
- });
3708
- deprecateComponentProp(deprecatedProps.ItemContainer, 'Item', 'ItemContainer');
3709
- deprecateComponentProp(deprecatedProps.ListContainer, 'List', 'ListContainer');
3710
- deprecateComponentProp(deprecatedProps.ScrollContainer, 'Scroller', 'ScrollContainer');
3711
- return _extends({}, gridSystem, gridComponentPropsSystem, deprecatedProps);
3712
- }, /*#__PURE__*/u.tup(gridSystem, gridComponentPropsSystem));
3713
- var GridItems = /*#__PURE__*/React.memo(function GridItems() {
3714
- var gridState = useEmitterValue('gridState');
3715
- var listClassName = useEmitterValue('listClassName');
3716
- var itemClassName = useEmitterValue('itemClassName');
3717
- var itemContent = useEmitterValue('itemContent');
3718
- var computeItemKey = useEmitterValue('computeItemKey');
3719
- var isSeeking = useEmitterValue('isSeeking');
3720
- var scrollHeightCallback = usePublisher('scrollHeight');
3721
- var ItemComponent = useEmitterValue('ItemComponent');
3722
- var ListComponent = useEmitterValue('ListComponent');
3723
- var ScrollSeekPlaceholder = useEmitterValue('ScrollSeekPlaceholder');
3724
- var context = useEmitterValue('context');
3725
- var itemDimensions = usePublisher('itemDimensions');
3726
- var listRef = useSize(function (el) {
3727
- var scrollHeight = el.parentElement.parentElement.scrollHeight;
3728
- scrollHeightCallback(scrollHeight);
3729
- var firstItem = el.firstChild;
3730
-
3731
- if (firstItem) {
3732
- itemDimensions(firstItem.getBoundingClientRect());
3733
- }
3734
- });
3735
- return createElement(ListComponent, _extends({
3736
- ref: listRef,
3737
- className: listClassName
3738
- }, contextPropIfNotDomElement(ListComponent, context), {
3739
- style: {
3740
- paddingTop: gridState.offsetTop,
3741
- paddingBottom: gridState.offsetBottom
3742
- }
3743
- }), gridState.items.map(function (item) {
3744
- var key = computeItemKey(item.index);
3745
- return isSeeking ? createElement(ScrollSeekPlaceholder, _extends({
3746
- key: key
3747
- }, contextPropIfNotDomElement(ScrollSeekPlaceholder, context), {
3748
- index: item.index,
3749
- height: gridState.itemHeight,
3750
- width: gridState.itemWidth
3751
- })) : createElement(ItemComponent, _extends({}, contextPropIfNotDomElement(ItemComponent, context), {
3752
- className: itemClassName,
3753
- 'data-index': item.index,
3754
- key: key
3755
- }), itemContent(item.index, context));
3756
- }));
3757
- });
3758
-
3759
- var Viewport = function Viewport(_ref4) {
3760
- var children = _ref4.children;
3761
- var viewportDimensions = usePublisher('viewportDimensions');
3762
- var viewportRef = useSize(function (el) {
3763
- viewportDimensions(el.getBoundingClientRect());
3764
- });
3765
- return React.createElement("div", {
3766
- style: viewportStyle,
3767
- ref: viewportRef
3768
- }, children);
3769
- };
3770
-
3771
- var WindowViewport = function WindowViewport(_ref5) {
3772
- var children = _ref5.children;
3773
- var windowViewportRect = usePublisher('windowViewportRect');
3774
- var customScrollParent = useEmitterValue('customScrollParent');
3775
- var viewportRef = useWindowViewportRectRef(windowViewportRect, customScrollParent);
3776
- return React.createElement("div", {
3777
- ref: viewportRef,
3778
- style: viewportStyle
3779
- }, children);
3780
- };
3781
-
3782
- var GridRoot = /*#__PURE__*/React.memo(function GridRoot(_ref6) {
3783
- var props = _extends({}, _ref6);
3784
-
3785
- var useWindowScroll = useEmitterValue('useWindowScroll');
3786
- var customScrollParent = useEmitterValue('customScrollParent');
3787
- var TheScroller = customScrollParent || useWindowScroll ? WindowScroller : Scroller;
3788
- var TheViewport = customScrollParent || useWindowScroll ? WindowViewport : Viewport;
3789
- return React.createElement(TheScroller, _extends({}, props), React.createElement(TheViewport, null, React.createElement(GridItems, null)));
3790
- });
3791
-
3792
- var _systemToComponent = /*#__PURE__*/systemToComponent(combinedSystem, {
3793
- optional: {
3794
- totalCount: 'totalCount',
3795
- overscan: 'overscan',
3796
- itemContent: 'itemContent',
3797
- components: 'components',
3798
- computeItemKey: 'computeItemKey',
3799
- initialItemCount: 'initialItemCount',
3800
- scrollSeekConfiguration: 'scrollSeekConfiguration',
3801
- listClassName: 'listClassName',
3802
- itemClassName: 'itemClassName',
3803
- useWindowScroll: 'useWindowScroll',
3804
- customScrollParent: 'customScrollParent',
3805
- scrollerRef: 'scrollerRef',
3806
- // deprecated
3807
- item: 'item',
3808
- ItemContainer: 'ItemContainer',
3809
- ScrollContainer: 'ScrollContainer',
3810
- ListContainer: 'ListContainer',
3811
- scrollSeek: 'scrollSeek'
3812
- },
3813
- methods: {
3814
- scrollTo: 'scrollTo',
3815
- scrollBy: 'scrollBy',
3816
- scrollToIndex: 'scrollToIndex'
3817
- },
3818
- events: {
3819
- isScrolling: 'isScrolling',
3820
- endReached: 'endReached',
3821
- startReached: 'startReached',
3822
- rangeChanged: 'rangeChanged',
3823
- atBottomStateChange: 'atBottomStateChange',
3824
- atTopStateChange: 'atTopStateChange'
3825
- }
3826
- }, GridRoot),
3827
- Grid = _systemToComponent.Component,
3828
- usePublisher = _systemToComponent.usePublisher,
3829
- useEmitterValue = _systemToComponent.useEmitterValue,
3830
- useEmitter = _systemToComponent.useEmitter;
3831
- var Scroller = /*#__PURE__*/buildScroller({
3832
- usePublisher: usePublisher,
3833
- useEmitterValue: useEmitterValue,
3834
- useEmitter: useEmitter
3835
- });
3836
- var WindowScroller = /*#__PURE__*/buildWindowScroller({
3837
- usePublisher: usePublisher,
3838
- useEmitterValue: useEmitterValue,
3839
- useEmitter: useEmitter
3840
- });
3841
-
3842
- var VirtuosoGrid = Grid;
3843
-
3844
- export { GroupedVirtuoso, LogLevel, TableVirtuoso, Virtuoso, VirtuosoGrid };
3845
- //# sourceMappingURL=react-virtuoso.esm.js.map