@ringcentral/juno 2.40.0 → 2.41.0

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 (183) hide show
  1. package/components/Downshift/SuggestionList/SuggestionList.d.ts +3 -3
  2. package/components/Downshift/utils/useDownshift.d.ts +1 -1
  3. package/components/Tooltip/Tooltip.js +20 -2
  4. package/components/Virtuoso/index.d.ts +1 -1
  5. package/components/Virtuoso/index.js +1 -1
  6. package/components/Virtuoso/react-virtuoso/AATree.d.ts +1 -1
  7. package/components/Virtuoso/react-virtuoso/AATree.js +60 -48
  8. package/components/Virtuoso/react-virtuoso/TableVirtuoso.d.ts +5 -0
  9. package/components/Virtuoso/react-virtuoso/TableVirtuoso.js +217 -0
  10. package/components/Virtuoso/react-virtuoso/Virtuoso.d.ts +7696 -0
  11. package/components/Virtuoso/react-virtuoso/Virtuoso.js +317 -0
  12. package/components/Virtuoso/react-virtuoso/{Grid.d.ts → VirtuosoGrid.d.ts} +170 -72
  13. package/components/Virtuoso/react-virtuoso/VirtuosoGrid.js +199 -0
  14. package/components/Virtuoso/react-virtuoso/alignToBottomSystem.d.ts +119 -65
  15. package/components/Virtuoso/react-virtuoso/alignToBottomSystem.js +3 -3
  16. package/components/Virtuoso/react-virtuoso/comparators.d.ts +1 -1
  17. package/components/Virtuoso/react-virtuoso/comparators.js +1 -3
  18. package/components/Virtuoso/react-virtuoso/component-interfaces/TableVirtuoso.d.ts +194 -0
  19. package/components/Virtuoso/react-virtuoso/component-interfaces/TableVirtuoso.js +2 -0
  20. package/components/Virtuoso/react-virtuoso/component-interfaces/Virtuoso.d.ts +274 -0
  21. package/components/Virtuoso/react-virtuoso/component-interfaces/Virtuoso.js +2 -0
  22. package/components/Virtuoso/react-virtuoso/component-interfaces/VirtuosoGrid.d.ts +125 -0
  23. package/components/Virtuoso/react-virtuoso/component-interfaces/VirtuosoGrid.js +2 -0
  24. package/components/Virtuoso/react-virtuoso/domIOSystem.d.ts +3 -2
  25. package/components/Virtuoso/react-virtuoso/domIOSystem.js +5 -3
  26. package/components/Virtuoso/react-virtuoso/followOutputSystem.d.ts +80 -43
  27. package/components/Virtuoso/react-virtuoso/followOutputSystem.js +21 -19
  28. package/components/Virtuoso/react-virtuoso/gridSystem.d.ts +57 -31
  29. package/components/Virtuoso/react-virtuoso/gridSystem.js +173 -86
  30. package/components/Virtuoso/react-virtuoso/groupedListSystem.d.ts +76 -67
  31. package/components/Virtuoso/react-virtuoso/groupedListSystem.js +12 -12
  32. package/components/Virtuoso/react-virtuoso/hooks/useChangedChildSizes.d.ts +6 -3
  33. package/components/Virtuoso/react-virtuoso/hooks/useChangedChildSizes.js +36 -17
  34. package/components/Virtuoso/react-virtuoso/hooks/useIsomorphicLayoutEffect.d.ts +2 -2
  35. package/components/Virtuoso/react-virtuoso/hooks/useIsomorphicLayoutEffect.js +3 -2
  36. package/components/Virtuoso/react-virtuoso/hooks/useRcPortalWindowContext.d.ts +2 -0
  37. package/components/Virtuoso/react-virtuoso/hooks/useRcPortalWindowContext.js +5 -0
  38. package/components/Virtuoso/react-virtuoso/hooks/useScrollTop.d.ts +2 -3
  39. package/components/Virtuoso/react-virtuoso/hooks/useScrollTop.js +36 -51
  40. package/components/Virtuoso/react-virtuoso/hooks/useSize.d.ts +2 -3
  41. package/components/Virtuoso/react-virtuoso/hooks/useSize.js +13 -13
  42. package/components/Virtuoso/react-virtuoso/hooks/useWindowViewportRect.js +17 -15
  43. package/components/Virtuoso/react-virtuoso/index.d.ts +7 -1
  44. package/components/Virtuoso/react-virtuoso/index.js +8 -1
  45. package/components/Virtuoso/react-virtuoso/initialItemCountSystem.d.ts +304 -68
  46. package/components/Virtuoso/react-virtuoso/initialItemCountSystem.js +9 -31
  47. package/components/Virtuoso/react-virtuoso/initialScrollTopSystem.d.ts +127 -109
  48. package/components/Virtuoso/react-virtuoso/initialScrollTopSystem.js +7 -7
  49. package/components/Virtuoso/react-virtuoso/initialTopMostItemIndexSystem.d.ts +38 -22
  50. package/components/Virtuoso/react-virtuoso/initialTopMostItemIndexSystem.js +13 -20
  51. package/components/Virtuoso/react-virtuoso/interfaces.d.ts +150 -51
  52. package/components/Virtuoso/react-virtuoso/listStateSystem.d.ts +109 -59
  53. package/components/Virtuoso/react-virtuoso/listStateSystem.js +100 -52
  54. package/components/Virtuoso/react-virtuoso/listSystem.d.ts +1691 -693
  55. package/components/Virtuoso/react-virtuoso/listSystem.js +15 -16
  56. package/components/Virtuoso/react-virtuoso/loggerSystem.d.ts +1 -1
  57. package/components/Virtuoso/react-virtuoso/loggerSystem.js +2 -4
  58. package/components/Virtuoso/react-virtuoso/propsReadySystem.d.ts +1 -1
  59. package/components/Virtuoso/react-virtuoso/propsReadySystem.js +3 -4
  60. package/components/Virtuoso/react-virtuoso/react-urx/index.d.ts +110 -0
  61. package/components/Virtuoso/react-virtuoso/react-urx/index.js +200 -0
  62. package/components/Virtuoso/react-virtuoso/react-urx/package.json +5 -0
  63. package/components/Virtuoso/react-virtuoso/recalcSystem.d.ts +4 -0
  64. package/components/Virtuoso/react-virtuoso/recalcSystem.js +8 -0
  65. package/components/Virtuoso/react-virtuoso/scrollIntoViewSystem.d.ts +144 -78
  66. package/components/Virtuoso/react-virtuoso/scrollIntoViewSystem.js +33 -21
  67. package/components/Virtuoso/react-virtuoso/scrollSeekSystem.d.ts +12 -7
  68. package/components/Virtuoso/react-virtuoso/scrollSeekSystem.js +7 -10
  69. package/components/Virtuoso/react-virtuoso/scrollToIndexSystem.d.ts +19 -11
  70. package/components/Virtuoso/react-virtuoso/scrollToIndexSystem.js +11 -23
  71. package/components/Virtuoso/react-virtuoso/sizeRangeSystem.d.ts +7 -6
  72. package/components/Virtuoso/react-virtuoso/sizeRangeSystem.js +15 -27
  73. package/components/Virtuoso/react-virtuoso/sizeSystem.d.ts +20 -11
  74. package/components/Virtuoso/react-virtuoso/sizeSystem.js +182 -52
  75. package/components/Virtuoso/react-virtuoso/stateFlagsSystem.d.ts +8 -5
  76. package/components/Virtuoso/react-virtuoso/stateFlagsSystem.js +32 -23
  77. package/components/Virtuoso/react-virtuoso/stateLoadSystem.d.ts +318 -0
  78. package/components/Virtuoso/react-virtuoso/stateLoadSystem.js +41 -0
  79. package/components/Virtuoso/react-virtuoso/topItemCountSystem.d.ts +518 -467
  80. package/components/Virtuoso/react-virtuoso/topItemCountSystem.js +5 -5
  81. package/components/Virtuoso/react-virtuoso/totalListHeightSystem.d.ts +115 -63
  82. package/components/Virtuoso/react-virtuoso/totalListHeightSystem.js +6 -13
  83. package/components/Virtuoso/react-virtuoso/upwardScrollFixSystem.d.ts +139 -73
  84. package/components/Virtuoso/react-virtuoso/upwardScrollFixSystem.js +74 -31
  85. package/components/Virtuoso/react-virtuoso/urx/actions.d.ts +127 -0
  86. package/components/Virtuoso/react-virtuoso/urx/actions.js +98 -0
  87. package/components/Virtuoso/react-virtuoso/urx/constants.d.ts +8 -0
  88. package/components/Virtuoso/react-virtuoso/urx/constants.js +6 -0
  89. package/components/Virtuoso/react-virtuoso/urx/index.d.ts +6 -0
  90. package/components/Virtuoso/react-virtuoso/urx/index.js +9 -0
  91. package/components/Virtuoso/react-virtuoso/urx/package.json +5 -0
  92. package/components/Virtuoso/react-virtuoso/urx/pipe.d.ts +220 -0
  93. package/components/Virtuoso/react-virtuoso/urx/pipe.js +279 -0
  94. package/components/Virtuoso/react-virtuoso/urx/streams.d.ts +143 -0
  95. package/components/Virtuoso/react-virtuoso/urx/streams.js +227 -0
  96. package/components/Virtuoso/react-virtuoso/urx/system.d.ts +148 -0
  97. package/components/Virtuoso/react-virtuoso/urx/system.js +106 -0
  98. package/components/Virtuoso/react-virtuoso/urx/transformers.d.ts +71 -0
  99. package/components/Virtuoso/react-virtuoso/urx/transformers.js +106 -0
  100. package/components/Virtuoso/react-virtuoso/urx/utils.d.ts +57 -0
  101. package/components/Virtuoso/react-virtuoso/urx/utils.js +102 -0
  102. package/components/Virtuoso/react-virtuoso/utils/approximatelyEqual.d.ts +1 -0
  103. package/components/Virtuoso/react-virtuoso/utils/approximatelyEqual.js +6 -0
  104. package/components/Virtuoso/react-virtuoso/utils/context.d.ts +13 -0
  105. package/components/Virtuoso/react-virtuoso/utils/context.js +6 -0
  106. package/components/Virtuoso/react-virtuoso/utils/skipFrames.d.ts +1 -0
  107. package/components/Virtuoso/react-virtuoso/utils/skipFrames.js +11 -0
  108. package/components/Virtuoso/react-virtuoso/windowScrollerSystem.d.ts +6 -4
  109. package/components/Virtuoso/react-virtuoso/windowScrollerSystem.js +1 -1
  110. package/components/Virtuoso/utils/isOutOfRange.d.ts +1 -1
  111. package/components/Virtuoso/utils/useHighlightScroll.d.ts +2 -2
  112. package/es6/components/Tooltip/Tooltip.js +21 -3
  113. package/es6/components/Virtuoso/index.js +1 -1
  114. package/es6/components/Virtuoso/react-virtuoso/AATree.js +60 -48
  115. package/es6/components/Virtuoso/react-virtuoso/{Table.js → TableVirtuoso.js} +73 -52
  116. package/es6/components/Virtuoso/react-virtuoso/{List.js → Virtuoso.js} +85 -161
  117. package/es6/components/Virtuoso/react-virtuoso/VirtuosoGrid.js +198 -0
  118. package/es6/components/Virtuoso/react-virtuoso/alignToBottomSystem.js +3 -3
  119. package/es6/components/Virtuoso/react-virtuoso/comparators.js +1 -3
  120. package/es6/components/Virtuoso/react-virtuoso/component-interfaces/TableVirtuoso.js +0 -0
  121. package/es6/components/Virtuoso/react-virtuoso/component-interfaces/Virtuoso.js +0 -0
  122. package/es6/components/Virtuoso/react-virtuoso/component-interfaces/VirtuosoGrid.js +0 -0
  123. package/es6/components/Virtuoso/react-virtuoso/domIOSystem.js +5 -3
  124. package/es6/components/Virtuoso/react-virtuoso/followOutputSystem.js +21 -19
  125. package/es6/components/Virtuoso/react-virtuoso/gridSystem.js +173 -87
  126. package/es6/components/Virtuoso/react-virtuoso/groupedListSystem.js +13 -13
  127. package/es6/components/Virtuoso/react-virtuoso/hooks/useChangedChildSizes.js +35 -16
  128. package/es6/components/Virtuoso/react-virtuoso/hooks/useIsomorphicLayoutEffect.js +2 -2
  129. package/es6/components/Virtuoso/react-virtuoso/hooks/useRcPortalWindowContext.js +2 -0
  130. package/es6/components/Virtuoso/react-virtuoso/hooks/useScrollTop.js +35 -50
  131. package/es6/components/Virtuoso/react-virtuoso/hooks/useSize.js +11 -12
  132. package/es6/components/Virtuoso/react-virtuoso/hooks/useWindowViewportRect.js +15 -14
  133. package/es6/components/Virtuoso/react-virtuoso/index.js +4 -1
  134. package/es6/components/Virtuoso/react-virtuoso/initialItemCountSystem.js +11 -33
  135. package/es6/components/Virtuoso/react-virtuoso/initialScrollTopSystem.js +7 -7
  136. package/es6/components/Virtuoso/react-virtuoso/initialTopMostItemIndexSystem.js +13 -20
  137. package/es6/components/Virtuoso/react-virtuoso/listStateSystem.js +101 -54
  138. package/es6/components/Virtuoso/react-virtuoso/listSystem.js +15 -16
  139. package/es6/components/Virtuoso/react-virtuoso/loggerSystem.js +2 -4
  140. package/es6/components/Virtuoso/react-virtuoso/propsReadySystem.js +3 -4
  141. package/es6/components/Virtuoso/react-virtuoso/react-urx/index.js +197 -0
  142. package/es6/components/Virtuoso/react-virtuoso/recalcSystem.js +5 -0
  143. package/es6/components/Virtuoso/react-virtuoso/scrollIntoViewSystem.js +34 -22
  144. package/es6/components/Virtuoso/react-virtuoso/scrollSeekSystem.js +7 -10
  145. package/es6/components/Virtuoso/react-virtuoso/scrollToIndexSystem.js +11 -23
  146. package/es6/components/Virtuoso/react-virtuoso/sizeRangeSystem.js +16 -28
  147. package/es6/components/Virtuoso/react-virtuoso/sizeSystem.js +180 -53
  148. package/es6/components/Virtuoso/react-virtuoso/stateFlagsSystem.js +32 -23
  149. package/es6/components/Virtuoso/react-virtuoso/stateLoadSystem.js +39 -0
  150. package/es6/components/Virtuoso/react-virtuoso/topItemCountSystem.js +5 -5
  151. package/es6/components/Virtuoso/react-virtuoso/totalListHeightSystem.js +6 -13
  152. package/es6/components/Virtuoso/react-virtuoso/upwardScrollFixSystem.js +75 -32
  153. package/es6/components/Virtuoso/react-virtuoso/urx/actions.js +90 -0
  154. package/es6/components/Virtuoso/react-virtuoso/urx/constants.js +4 -0
  155. package/es6/components/Virtuoso/react-virtuoso/urx/index.js +6 -0
  156. package/es6/components/Virtuoso/react-virtuoso/urx/pipe.js +266 -0
  157. package/es6/components/Virtuoso/react-virtuoso/urx/streams.js +220 -0
  158. package/es6/components/Virtuoso/react-virtuoso/urx/system.js +102 -0
  159. package/es6/components/Virtuoso/react-virtuoso/urx/transformers.js +101 -0
  160. package/es6/components/Virtuoso/react-virtuoso/urx/utils.js +88 -0
  161. package/es6/components/Virtuoso/react-virtuoso/utils/approximatelyEqual.js +3 -0
  162. package/es6/components/Virtuoso/react-virtuoso/utils/context.js +3 -0
  163. package/es6/components/Virtuoso/react-virtuoso/utils/skipFrames.js +8 -0
  164. package/es6/components/Virtuoso/react-virtuoso/windowScrollerSystem.js +1 -1
  165. package/es6/foundation/hooks/useForkRef/useForkRef.js +2 -1
  166. package/foundation/hooks/useForkRef/useForkRef.d.ts +2 -1
  167. package/foundation/hooks/useForkRef/useForkRef.js +1 -0
  168. package/package.json +2 -2
  169. package/components/Virtuoso/Virtuoso.d.ts +0 -1
  170. package/components/Virtuoso/Virtuoso.js +0 -4
  171. package/components/Virtuoso/react-virtuoso/Grid.js +0 -168
  172. package/components/Virtuoso/react-virtuoso/List.d.ts +0 -6749
  173. package/components/Virtuoso/react-virtuoso/List.js +0 -393
  174. package/components/Virtuoso/react-virtuoso/Table.d.ts +0 -6515
  175. package/components/Virtuoso/react-virtuoso/Table.js +0 -196
  176. package/components/Virtuoso/react-virtuoso/components.d.ts +0 -505
  177. package/components/Virtuoso/react-virtuoso/components.js +0 -9
  178. package/components/Virtuoso/react-virtuoso/utils/conditionalFlushSync.d.ts +0 -1
  179. package/components/Virtuoso/react-virtuoso/utils/conditionalFlushSync.js +0 -11
  180. package/es6/components/Virtuoso/Virtuoso.js +0 -1
  181. package/es6/components/Virtuoso/react-virtuoso/Grid.js +0 -166
  182. package/es6/components/Virtuoso/react-virtuoso/components.js +0 -7
  183. package/es6/components/Virtuoso/react-virtuoso/utils/conditionalFlushSync.js +0 -8
@@ -1,38 +1,37 @@
1
- import { useCallback, useEffect, useRef } from 'react';
2
- import * as u from '@virtuoso.dev/urx';
3
- import { useRcPortalWindowContext } from '../../../../foundation';
1
+ import React from 'react';
2
+ import * as u from '../urx';
4
3
  import { correctItemSize } from '../utils/correctItemSize';
5
- function approximatelyEqual(num1, num2) {
6
- return Math.abs(num1 - num2) < 1.01;
7
- }
4
+ import ReactDOM from 'react-dom';
5
+ import { approximatelyEqual } from '../utils/approximatelyEqual';
6
+ import { useRcPortalWindowContext } from './useRcPortalWindowContext';
8
7
  export default function useScrollTop(scrollContainerStateCallback, smoothScrollTargetReached, scrollerElement, scrollerRefCallback, customScrollParent) {
9
8
  if (scrollerRefCallback === void 0) { scrollerRefCallback = u.noop; }
10
- var scrollerRef = useRef(null);
11
- var scrollTopTarget = useRef(null);
12
- var timeoutRef = useRef(null);
9
+ var scrollerRef = React.useRef(null);
10
+ var scrollTopTarget = React.useRef(null);
11
+ var timeoutRef = React.useRef(null);
13
12
  var _a = useRcPortalWindowContext().externalWindow, externalWindow = _a === void 0 ? window : _a;
14
- var handler = useCallback(function (ev) {
13
+ var handler = React.useCallback(function (ev) {
15
14
  var el = ev.target;
16
- var scrollTop = el === externalWindow ||
17
- el === externalWindow.document
18
- ? externalWindow.pageYOffset ||
19
- externalWindow.document.documentElement.scrollTop
20
- : el.scrollTop;
21
- var scrollHeight = el === externalWindow
22
- ? externalWindow.document.documentElement.scrollHeight
23
- : el.scrollHeight;
24
- var viewportHeight = el === externalWindow
25
- ? externalWindow.innerHeight
26
- : el.offsetHeight;
27
- scrollContainerStateCallback({
28
- scrollTop: Math.max(scrollTop, 0),
29
- scrollHeight: scrollHeight,
30
- viewportHeight: viewportHeight,
31
- });
15
+ var windowScroll = el === externalWindow || el === externalWindow.document;
16
+ var scrollTop = windowScroll ? externalWindow.pageYOffset || externalWindow.document.documentElement.scrollTop : el.scrollTop;
17
+ var scrollHeight = windowScroll ? externalWindow.document.documentElement.scrollHeight : el.scrollHeight;
18
+ var viewportHeight = windowScroll ? externalWindow.innerHeight : el.offsetHeight;
19
+ var call = function () {
20
+ scrollContainerStateCallback({
21
+ scrollTop: Math.max(scrollTop, 0),
22
+ scrollHeight: scrollHeight,
23
+ viewportHeight: viewportHeight,
24
+ });
25
+ };
26
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
27
+ if (ev.suppressFlushSync) {
28
+ call();
29
+ }
30
+ else {
31
+ ReactDOM.flushSync(call);
32
+ }
32
33
  if (scrollTopTarget.current !== null) {
33
- if (scrollTop === scrollTopTarget.current ||
34
- scrollTop <= 0 ||
35
- scrollTop === el.scrollHeight - correctItemSize(el, 'height')) {
34
+ if (scrollTop === scrollTopTarget.current || scrollTop <= 0 || scrollTop === scrollHeight - viewportHeight) {
36
35
  scrollTopTarget.current = null;
37
36
  smoothScrollTargetReached(true);
38
37
  if (timeoutRef.current) {
@@ -42,28 +41,19 @@ export default function useScrollTop(scrollContainerStateCallback, smoothScrollT
42
41
  }
43
42
  }
44
43
  }, [externalWindow, scrollContainerStateCallback, smoothScrollTargetReached]);
45
- useEffect(function () {
46
- var localRef = customScrollParent
47
- ? customScrollParent
48
- : scrollerRef.current;
44
+ React.useEffect(function () {
45
+ var localRef = customScrollParent ? customScrollParent : scrollerRef.current;
49
46
  scrollerRefCallback(customScrollParent ? customScrollParent : scrollerRef.current);
50
- handler({ target: localRef });
47
+ handler({ target: localRef, suppressFlushSync: true });
51
48
  localRef.addEventListener('scroll', handler, { passive: true });
52
49
  return function () {
53
50
  scrollerRefCallback(null);
54
51
  localRef.removeEventListener('scroll', handler);
55
52
  };
56
- }, [
57
- scrollerRef,
58
- handler,
59
- scrollerElement,
60
- scrollerRefCallback,
61
- customScrollParent,
62
- ]);
53
+ }, [scrollerRef, handler, scrollerElement, scrollerRefCallback, customScrollParent]);
63
54
  function scrollToCallback(location) {
64
55
  var scrollerElement = scrollerRef.current;
65
- if (!scrollerElement ||
66
- ('offsetHeight' in scrollerElement && scrollerElement.offsetHeight === 0)) {
56
+ if (!scrollerElement || ('offsetHeight' in scrollerElement && scrollerElement.offsetHeight === 0)) {
67
57
  return;
68
58
  }
69
59
  var isSmooth = location.behavior === 'smooth';
@@ -86,13 +76,8 @@ export default function useScrollTop(scrollContainerStateCallback, smoothScrollT
86
76
  // avoid system hanging because the DOM never called back
87
77
  // with the scrollTop
88
78
  // scroller is already at this location
89
- if (approximatelyEqual(offsetHeight, scrollHeight) ||
90
- location.top === scrollTop) {
91
- scrollContainerStateCallback({
92
- scrollTop: scrollTop,
93
- scrollHeight: scrollHeight,
94
- viewportHeight: offsetHeight,
95
- });
79
+ if (approximatelyEqual(offsetHeight, scrollHeight) || location.top === scrollTop) {
80
+ scrollContainerStateCallback({ scrollTop: scrollTop, scrollHeight: scrollHeight, viewportHeight: offsetHeight });
96
81
  if (isSmooth) {
97
82
  smoothScrollTargetReached(true);
98
83
  }
@@ -1,22 +1,21 @@
1
- import { useRef } from 'react';
2
- import { useRcPortalWindowContext } from '../../../../foundation';
1
+ import React from 'react';
2
+ import { useRcPortalWindowContext } from './useRcPortalWindowContext';
3
3
  export function useSizeWithElRef(callback, enabled) {
4
4
  if (enabled === void 0) { enabled = true; }
5
- var ref = useRef(null);
5
+ var ref = React.useRef(null);
6
6
  var _a = useRcPortalWindowContext().externalWindow, externalWindow = _a === void 0 ? window : _a;
7
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
8
7
  var callbackRef = function (_el) {
9
- // eslint-disable-next-line no-void
10
8
  void 0;
11
9
  };
12
- // TODO: fix after upgrade ts
13
10
  if (typeof externalWindow['ResizeObserver'] !== 'undefined') {
14
- var observer_1 = new externalWindow['ResizeObserver'](function (entries) {
15
- var element = entries[0].target;
16
- if (element.offsetParent !== null) {
17
- callback(element);
18
- }
19
- });
11
+ var observer_1 = React.useMemo(function () {
12
+ return new externalWindow['ResizeObserver'](function (entries) {
13
+ var element = entries[0].target;
14
+ if (element.offsetParent !== null) {
15
+ callback(element);
16
+ }
17
+ });
18
+ }, [callback]);
20
19
  callbackRef = function (elRef) {
21
20
  if (elRef && enabled) {
22
21
  observer_1.observe(elRef);
@@ -1,16 +1,15 @@
1
- import { useCallback, useEffect, useRef } from 'react';
2
- import { useRcPortalWindowContext } from '../../../../foundation';
1
+ import React from 'react';
3
2
  import { useSizeWithElRef } from './useSize';
3
+ import { useRcPortalWindowContext } from './useRcPortalWindowContext';
4
4
  export default function useWindowViewportRectRef(callback, customScrollParent) {
5
- var viewportInfo = useRef(null);
5
+ var viewportInfo = React.useRef(null);
6
6
  var _a = useRcPortalWindowContext().externalWindow, externalWindow = _a === void 0 ? window : _a;
7
- var calculateInfo = useCallback(function (element) {
8
- if (element === null) {
7
+ var calculateInfo = React.useCallback(function (element) {
8
+ if (element === null || !element.offsetParent) {
9
9
  return;
10
10
  }
11
11
  var rect = element.getBoundingClientRect();
12
12
  var visibleWidth = rect.width;
13
- // eslint-disable-next-line one-var
14
13
  var visibleHeight, offsetTop;
15
14
  if (customScrollParent) {
16
15
  var customScrollParentRect = customScrollParent.getBoundingClientRect();
@@ -30,10 +29,10 @@ export default function useWindowViewportRectRef(callback, customScrollParent) {
30
29
  callback(viewportInfo.current);
31
30
  }, [callback, customScrollParent, externalWindow]);
32
31
  var _b = useSizeWithElRef(calculateInfo), callbackRef = _b.callbackRef, ref = _b.ref;
33
- var scrollAndResizeEventHandler = useCallback(function () {
32
+ var scrollAndResizeEventHandler = React.useCallback(function () {
34
33
  calculateInfo(ref.current);
35
34
  }, [calculateInfo, ref]);
36
- useEffect(function () {
35
+ React.useEffect(function () {
37
36
  if (customScrollParent) {
38
37
  customScrollParent.addEventListener('scroll', scrollAndResizeEventHandler);
39
38
  var observer_1 = new externalWindow['ResizeObserver'](scrollAndResizeEventHandler);
@@ -43,12 +42,14 @@ export default function useWindowViewportRectRef(callback, customScrollParent) {
43
42
  observer_1.unobserve(customScrollParent);
44
43
  };
45
44
  }
46
- externalWindow.addEventListener('scroll', scrollAndResizeEventHandler);
47
- externalWindow.addEventListener('resize', scrollAndResizeEventHandler);
48
- return function () {
49
- externalWindow.removeEventListener('scroll', scrollAndResizeEventHandler);
50
- externalWindow.removeEventListener('resize', scrollAndResizeEventHandler);
51
- };
45
+ else {
46
+ externalWindow.addEventListener('scroll', scrollAndResizeEventHandler);
47
+ externalWindow.addEventListener('resize', scrollAndResizeEventHandler);
48
+ return function () {
49
+ externalWindow.removeEventListener('scroll', scrollAndResizeEventHandler);
50
+ externalWindow.removeEventListener('resize', scrollAndResizeEventHandler);
51
+ };
52
+ }
52
53
  }, [scrollAndResizeEventHandler, customScrollParent, externalWindow]);
53
54
  return callbackRef;
54
55
  }
@@ -1,2 +1,5 @@
1
- export * from './components';
1
+ export { GroupedVirtuoso, Virtuoso } from './Virtuoso';
2
+ export { VirtuosoGrid } from './VirtuosoGrid';
3
+ export { TableVirtuoso } from './TableVirtuoso';
2
4
  export { LogLevel } from './loggerSystem';
5
+ export * from './utils/context';
@@ -1,39 +1,17 @@
1
- import { __read, __values } from "tslib";
2
- import * as u from '@virtuoso.dev/urx';
3
- import { buildListState, listStateSystem } from './listStateSystem';
4
- import { propsReadySystem } from './propsReadySystem';
1
+ import { __read } from "tslib";
2
+ import * as u from './urx';
3
+ import { listStateSystem, buildListStateFromItemCount } from './listStateSystem';
5
4
  import { sizeSystem } from './sizeSystem';
5
+ import { propsReadySystem } from './propsReadySystem';
6
+ import { initialTopMostItemIndexSystem } from './initialTopMostItemIndexSystem';
6
7
  export var initialItemCountSystem = u.system(function (_a) {
7
- var _b = __read(_a, 3), _c = _b[0], sizes = _c.sizes, firstItemIndex = _c.firstItemIndex, data = _c.data, listState = _b[1].listState, didMount = _b[2].didMount;
8
- var initialItemCount = u.statefulStream(0);
8
+ var _b = __read(_a, 4), _c = _b[0], sizes = _c.sizes, firstItemIndex = _c.firstItemIndex, data = _c.data, gap = _c.gap, initialTopMostItemIndex = _b[1].initialTopMostItemIndex, _d = _b[2], initialItemCount = _d.initialItemCount, listState = _d.listState, didMount = _b[3].didMount;
9
9
  u.connect(u.pipe(didMount, u.withLatestFrom(initialItemCount), u.filter(function (_a) {
10
10
  var _b = __read(_a, 2), count = _b[1];
11
11
  return count !== 0;
12
- }), u.withLatestFrom(sizes, firstItemIndex, data), u.map(function (_a) {
13
- var e_1, _b;
14
- var _c = __read(_a, 4), _d = __read(_c[0], 2), count = _d[1], sizes = _c[1], firstItemIndex = _c[2], _e = _c[3], data = _e === void 0 ? [] : _e;
15
- var includedGroupsCount = 0;
16
- if (sizes.groupIndices.length > 0) {
17
- try {
18
- for (var _f = __values(sizes.groupIndices), _g = _f.next(); !_g.done; _g = _f.next()) {
19
- var index = _g.value;
20
- if (index - includedGroupsCount >= count) {
21
- break;
22
- }
23
- includedGroupsCount++;
24
- }
25
- }
26
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
27
- finally {
28
- try {
29
- if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
30
- }
31
- finally { if (e_1) throw e_1.error; }
32
- }
33
- }
34
- var adjustedCount = count + includedGroupsCount;
35
- var items = Array.from({ length: adjustedCount }).map(function (_, index) { return ({ index: index, size: 0, offset: 0, data: data[index] }); });
36
- return buildListState(items, [], adjustedCount, sizes, firstItemIndex);
12
+ }), u.withLatestFrom(initialTopMostItemIndex, sizes, firstItemIndex, gap, data), u.map(function (_a) {
13
+ var _b = __read(_a, 6), _c = __read(_b[0], 2), count = _c[1], initialTopMostItemIndexValue = _b[1], sizes = _b[2], firstItemIndex = _b[3], gap = _b[4], _d = _b[5], data = _d === void 0 ? [] : _d;
14
+ return buildListStateFromItemCount(count, initialTopMostItemIndexValue, sizes, firstItemIndex, gap, data);
37
15
  })), listState);
38
- return { initialItemCount: initialItemCount };
39
- }, u.tup(sizeSystem, listStateSystem, propsReadySystem), { singleton: true });
16
+ return {};
17
+ }, u.tup(sizeSystem, initialTopMostItemIndexSystem, listStateSystem, propsReadySystem), { singleton: true });
@@ -1,10 +1,10 @@
1
1
  import { __read } from "tslib";
2
- import * as u from '@virtuoso.dev/urx';
3
- import { domIOSystem } from './domIOSystem';
2
+ import * as u from './urx';
4
3
  import { propsReadySystem } from './propsReadySystem';
5
- import { totalListHeightSystem } from './totalListHeightSystem';
4
+ import { domIOSystem } from './domIOSystem';
5
+ import { listStateSystem } from './listStateSystem';
6
6
  export var initialScrollTopSystem = u.system(function (_a) {
7
- var _b = __read(_a, 3), totalListHeight = _b[0].totalListHeight, didMount = _b[1].didMount, scrollTo = _b[2].scrollTo;
7
+ var _b = __read(_a, 3), didMount = _b[0].didMount, scrollTo = _b[1].scrollTo, listState = _b[2].listState;
8
8
  var initialScrollTop = u.statefulStream(0);
9
9
  u.subscribe(u.pipe(didMount, u.withLatestFrom(initialScrollTop), u.filter(function (_a) {
10
10
  var _b = __read(_a, 2), offset = _b[1];
@@ -13,8 +13,8 @@ export var initialScrollTopSystem = u.system(function (_a) {
13
13
  var _b = __read(_a, 2), offset = _b[1];
14
14
  return ({ top: offset });
15
15
  })), function (location) {
16
- u.handleNext(u.pipe(totalListHeight, u.filter(function (val) { return val !== 0; })), function () {
17
- setTimeout(function () {
16
+ u.handleNext(u.pipe(listState, u.skip(1), u.filter(function (state) { return state.items.length > 1; })), function () {
17
+ requestAnimationFrame(function () {
18
18
  u.publish(scrollTo, location);
19
19
  });
20
20
  });
@@ -22,4 +22,4 @@ export var initialScrollTopSystem = u.system(function (_a) {
22
22
  return {
23
23
  initialScrollTop: initialScrollTop,
24
24
  };
25
- }, u.tup(totalListHeightSystem, propsReadySystem, domIOSystem), { singleton: true });
25
+ }, u.tup(propsReadySystem, domIOSystem, listStateSystem), { singleton: true });
@@ -1,40 +1,33 @@
1
1
  import { __read } from "tslib";
2
- import * as u from '@virtuoso.dev/urx';
2
+ import * as u from './urx';
3
3
  import { empty } from './AATree';
4
+ import { sizeSystem } from './sizeSystem';
4
5
  import { domIOSystem } from './domIOSystem';
5
- import { propsReadySystem } from './propsReadySystem';
6
6
  import { scrollToIndexSystem } from './scrollToIndexSystem';
7
- import { sizeSystem } from './sizeSystem';
7
+ import { propsReadySystem } from './propsReadySystem';
8
+ import { skipFrames } from './utils/skipFrames';
8
9
  export function getInitialTopMostItemIndexNumber(location, totalCount) {
9
10
  var lastIndex = totalCount - 1;
10
- var index = typeof location === 'number'
11
- ? location
12
- : location.index === 'LAST'
13
- ? lastIndex
14
- : location.index;
11
+ var index = typeof location === 'number' ? location : location.index === 'LAST' ? lastIndex : location.index;
15
12
  return index;
16
13
  }
17
14
  export var initialTopMostItemIndexSystem = u.system(function (_a) {
18
15
  var _b = __read(_a, 4), _c = _b[0], sizes = _c.sizes, listRefresh = _c.listRefresh, defaultItemSize = _c.defaultItemSize, scrollTop = _b[1].scrollTop, scrollToIndex = _b[2].scrollToIndex, didMount = _b[3].didMount;
19
16
  var scrolledToInitialItem = u.statefulStream(true);
20
17
  var initialTopMostItemIndex = u.statefulStream(0);
21
- u.connect(u.pipe(didMount, u.withLatestFrom(initialTopMostItemIndex),
22
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
23
- u.filter(function (_a) {
18
+ var scrollScheduled = u.statefulStream(false);
19
+ u.connect(u.pipe(didMount, u.withLatestFrom(initialTopMostItemIndex), u.filter(function (_a) {
24
20
  var _b = __read(_a, 2), _ = _b[0], location = _b[1];
25
21
  return !!location;
26
22
  }), u.mapTo(false)), scrolledToInitialItem);
27
- u.subscribe(u.pipe(u.combineLatest(listRefresh, didMount), u.withLatestFrom(scrolledToInitialItem, sizes, defaultItemSize), u.filter(function (_a) {
28
- var _b = __read(_a, 4), _c = __read(_b[0], 2), didMount = _c[1], scrolledToInitialItem = _b[1], sizeTree = _b[2].sizeTree, defaultItemSize = _b[3];
29
- return (didMount &&
30
- (!empty(sizeTree) || defaultItemSize !== undefined) &&
31
- !scrolledToInitialItem);
23
+ u.subscribe(u.pipe(u.combineLatest(listRefresh, didMount), u.withLatestFrom(scrolledToInitialItem, sizes, defaultItemSize, scrollScheduled), u.filter(function (_a) {
24
+ var _b = __read(_a, 5), _c = __read(_b[0], 2), didMount = _c[1], scrolledToInitialItem = _b[1], sizeTree = _b[2].sizeTree, defaultItemSize = _b[3], scrollScheduled = _b[4];
25
+ return didMount && (!empty(sizeTree) || u.isDefined(defaultItemSize)) && !scrolledToInitialItem && !scrollScheduled;
32
26
  }), u.withLatestFrom(initialTopMostItemIndex)), function (_a) {
33
27
  var _b = __read(_a, 2), initialTopMostItemIndex = _b[1];
34
- setTimeout(function () {
35
- u.handleNext(scrollTop, function () {
36
- u.publish(scrolledToInitialItem, true);
37
- });
28
+ u.publish(scrollScheduled, true);
29
+ skipFrames(3, function () {
30
+ u.handleNext(scrollTop, function () { return u.publish(scrolledToInitialItem, true); });
38
31
  u.publish(scrollToIndex, initialTopMostItemIndex);
39
32
  });
40
33
  });
@@ -1,14 +1,15 @@
1
1
  import { __assign, __read, __values } from "tslib";
2
- import * as u from '@virtuoso.dev/urx';
2
+ import * as u from './urx';
3
3
  import { empty, findMaxKeyValue, rangesWithin } from './AATree';
4
- import { rangeComparator, tupleComparator } from './comparators';
5
4
  import { groupedListSystem } from './groupedListSystem';
6
- import { getInitialTopMostItemIndexNumber, initialTopMostItemIndexSystem, } from './initialTopMostItemIndexSystem';
5
+ import { getInitialTopMostItemIndexNumber, initialTopMostItemIndexSystem } from './initialTopMostItemIndexSystem';
7
6
  import { propsReadySystem } from './propsReadySystem';
8
7
  import { scrollToIndexSystem } from './scrollToIndexSystem';
9
8
  import { sizeRangeSystem } from './sizeRangeSystem';
10
- import { hasGroups, originalIndexFromItemIndex, rangesWithinOffsets, sizeSystem, } from './sizeSystem';
9
+ import { originalIndexFromItemIndex, sizeSystem, hasGroups, rangesWithinOffsets } from './sizeSystem';
11
10
  import { stateFlagsSystem } from './stateFlagsSystem';
11
+ import { rangeComparator, tupleComparator } from './comparators';
12
+ import { recalcSystem } from './recalcSystem';
12
13
  function probeItemSet(index, sizes, data) {
13
14
  if (hasGroups(sizes)) {
14
15
  var itemIndex = originalIndexFromItemIndex(index, sizes);
@@ -29,6 +30,7 @@ var EMPTY_LIST_STATE = {
29
30
  bottom: 0,
30
31
  topListHeight: 0,
31
32
  totalCount: 0,
33
+ firstItemIndex: 0,
32
34
  };
33
35
  function transposeItems(items, sizes, firstItemIndex) {
34
36
  var e_1, _a;
@@ -42,7 +44,7 @@ function transposeItems(items, sizes, firstItemIndex) {
42
44
  var endIndex = items[items.length - 1].index;
43
45
  var transposedItems = [];
44
46
  var groupRanges = rangesWithin(sizes.groupOffsetTree, startIndex, endIndex);
45
- var currentRange;
47
+ var currentRange = undefined;
46
48
  var currentGroupIndex = 0;
47
49
  try {
48
50
  for (var items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
@@ -76,7 +78,7 @@ function transposeItems(items, sizes, firstItemIndex) {
76
78
  }
77
79
  return transposedItems;
78
80
  }
79
- export function buildListState(items, topItems, totalCount, sizes, firstItemIndex) {
81
+ export function buildListState(items, topItems, totalCount, gap, sizes, firstItemIndex) {
80
82
  var lastSize = sizes.lastSize, lastOffset = sizes.lastOffset, lastIndex = sizes.lastIndex;
81
83
  var offsetTop = 0;
82
84
  var bottom = 0;
@@ -85,7 +87,8 @@ export function buildListState(items, topItems, totalCount, sizes, firstItemInde
85
87
  var lastItem = items[items.length - 1];
86
88
  bottom = lastItem.offset + lastItem.size;
87
89
  }
88
- var total = lastOffset + (totalCount - lastIndex) * lastSize;
90
+ var itemCount = totalCount - lastIndex;
91
+ var total = lastOffset + itemCount * lastSize + (itemCount - 1) * gap;
89
92
  var top = offsetTop;
90
93
  var offsetBottom = total - bottom;
91
94
  return {
@@ -97,26 +100,76 @@ export function buildListState(items, topItems, totalCount, sizes, firstItemInde
97
100
  top: top,
98
101
  bottom: bottom,
99
102
  totalCount: totalCount,
103
+ firstItemIndex: firstItemIndex,
100
104
  };
101
105
  }
106
+ export function buildListStateFromItemCount(itemCount, initialTopMostItemIndex, sizes, firstItemIndex, gap, data) {
107
+ var e_2, _a;
108
+ var includedGroupsCount = 0;
109
+ if (sizes.groupIndices.length > 0) {
110
+ try {
111
+ for (var _b = __values(sizes.groupIndices), _c = _b.next(); !_c.done; _c = _b.next()) {
112
+ var index = _c.value;
113
+ if (index - includedGroupsCount >= itemCount) {
114
+ break;
115
+ }
116
+ includedGroupsCount++;
117
+ }
118
+ }
119
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
120
+ finally {
121
+ try {
122
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
123
+ }
124
+ finally { if (e_2) throw e_2.error; }
125
+ }
126
+ }
127
+ var adjustedCount = itemCount + includedGroupsCount;
128
+ var initialTopMostItemIndexNumber = getInitialTopMostItemIndexNumber(initialTopMostItemIndex, adjustedCount);
129
+ var items = Array.from({ length: adjustedCount }).map(function (_, index) { return ({
130
+ index: index + initialTopMostItemIndexNumber,
131
+ size: 0,
132
+ offset: 0,
133
+ data: data[index + initialTopMostItemIndexNumber],
134
+ }); });
135
+ return buildListState(items, [], adjustedCount, gap, sizes, firstItemIndex);
136
+ }
102
137
  export var listStateSystem = u.system(function (_a) {
103
- var _b = __read(_a, 7), _c = _b[0], sizes = _c.sizes, totalCount = _c.totalCount, data = _c.data, firstItemIndex = _c.firstItemIndex, groupedListSystem = _b[1], _d = _b[2], visibleRange = _d.visibleRange, listBoundary = _d.listBoundary, rangeTopListHeight = _d.topListHeight, _e = _b[3], scrolledToInitialItem = _e.scrolledToInitialItem, initialTopMostItemIndex = _e.initialTopMostItemIndex, topListHeight = _b[4].topListHeight, stateFlags = _b[5], didMount = _b[6].didMount;
138
+ var _b = __read(_a, 8), _c = _b[0], sizes = _c.sizes, totalCount = _c.totalCount, data = _c.data, firstItemIndex = _c.firstItemIndex, gap = _c.gap, groupedListSystem = _b[1], _d = _b[2], visibleRange = _d.visibleRange, listBoundary = _d.listBoundary, rangeTopListHeight = _d.topListHeight, _e = _b[3], scrolledToInitialItem = _e.scrolledToInitialItem, initialTopMostItemIndex = _e.initialTopMostItemIndex, topListHeight = _b[4].topListHeight, stateFlags = _b[5], didMount = _b[6].didMount, recalcInProgress = _b[7].recalcInProgress;
104
139
  var topItemsIndexes = u.statefulStream([]);
140
+ var initialItemCount = u.statefulStream(0);
105
141
  var itemsRendered = u.stream();
106
142
  u.connect(groupedListSystem.topItemsIndexes, topItemsIndexes);
107
- 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 (_a) {
108
- var _b = __read(_a, 1), mount = _b[0];
109
- return mount;
143
+ var listState = u.statefulStreamFromEmitter(u.pipe(u.combineLatest(didMount, recalcInProgress, u.duc(visibleRange, tupleComparator), u.duc(totalCount), u.duc(sizes), u.duc(initialTopMostItemIndex), scrolledToInitialItem, u.duc(topItemsIndexes), u.duc(firstItemIndex), u.duc(gap), data), u.filter(function (_a) {
144
+ var _b = __read(_a, 11), mount = _b[0], recalcInProgress = _b[1], totalCount = _b[3], data = _b[10];
145
+ // When data length changes, it is synced to totalCount, both of which trigger a recalc separately.
146
+ // Recalc should be skipped then, as the calculation expects both data and totalCount to be in sync.
147
+ var dataChangeInProgress = data && data.length !== totalCount;
148
+ return mount && !recalcInProgress && !dataChangeInProgress;
110
149
  }), u.map(function (_a) {
111
- var e_2, _b;
112
- var _c = __read(_a, 9), _d = __read(_c[1], 2), startOffset = _d[0], endOffset = _d[1], totalCount = _c[2], sizes = _c[3], initialTopMostItemIndex = _c[4], scrolledToInitialItem = _c[5], topItemsIndexes = _c[6], firstItemIndex = _c[7], data = _c[8];
150
+ var e_3, _b;
151
+ var _c = __read(_a, 11), _d = __read(_c[2], 2), startOffset = _d[0], endOffset = _d[1], totalCount = _c[3], sizes = _c[4], initialTopMostItemIndex = _c[5], scrolledToInitialItem = _c[6], topItemsIndexes = _c[7], firstItemIndex = _c[8], gap = _c[9], data = _c[10];
113
152
  var sizesValue = sizes;
114
153
  var sizeTree = sizesValue.sizeTree, offsetTree = sizesValue.offsetTree;
115
- if (totalCount === 0 || (startOffset === 0 && endOffset === 0)) {
116
- return EMPTY_LIST_STATE;
154
+ var initialItemCountValue = u.getValue(initialItemCount);
155
+ if (totalCount === 0) {
156
+ return __assign(__assign({}, EMPTY_LIST_STATE), { totalCount: totalCount });
157
+ }
158
+ // no container measruements yet
159
+ if (startOffset === 0 && endOffset === 0) {
160
+ if (initialItemCountValue === 0) {
161
+ return __assign(__assign({}, EMPTY_LIST_STATE), { totalCount: totalCount });
162
+ }
163
+ else {
164
+ return buildListStateFromItemCount(initialItemCountValue, initialTopMostItemIndex, sizes, firstItemIndex, gap, data || []);
165
+ }
117
166
  }
118
167
  if (empty(sizeTree)) {
119
- return buildListState(probeItemSet(getInitialTopMostItemIndexNumber(initialTopMostItemIndex, totalCount), sizesValue, data), [], totalCount, sizesValue, firstItemIndex);
168
+ if (initialItemCountValue > 0) {
169
+ return null;
170
+ }
171
+ var state = buildListState(probeItemSet(getInitialTopMostItemIndexNumber(initialTopMostItemIndex, totalCount), sizesValue, data), [], totalCount, gap, sizesValue, firstItemIndex);
172
+ return state;
120
173
  }
121
174
  var topItems = [];
122
175
  if (topItemsIndexes.length > 0) {
@@ -130,42 +183,35 @@ export var listStateSystem = u.system(function (_a) {
130
183
  var rangeStartIndex = Math.max(range.start, startIndex);
131
184
  var rangeEndIndex = Math.min(range.end, endIndex);
132
185
  for (var i = rangeStartIndex; i <= rangeEndIndex; i++) {
133
- topItems.push({
134
- index: i,
135
- size: size,
136
- offset: offset,
137
- data: data && data[i],
138
- });
186
+ topItems.push({ index: i, size: size, offset: offset, data: data && data[i] });
139
187
  offset += size;
140
188
  }
141
189
  }
142
190
  }
143
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
191
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
144
192
  finally {
145
193
  try {
146
194
  if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
147
195
  }
148
- finally { if (e_2) throw e_2.error; }
196
+ finally { if (e_3) throw e_3.error; }
149
197
  }
150
198
  }
151
199
  // If the list hasn't scrolled to the initial item because the initial item was set,
152
200
  // render empty list.
153
201
  //
154
- // This is a condition to be evaluated past the probe check, do not merge
202
+ // This is a condition to be evaluated after the probe check cycle, do not merge
155
203
  // with the totalCount check above
156
204
  if (!scrolledToInitialItem) {
157
- return buildListState([], topItems, totalCount, sizesValue, firstItemIndex);
205
+ return buildListState([], topItems, totalCount, gap, sizesValue, firstItemIndex);
158
206
  }
159
- var minStartIndex = topItemsIndexes.length > 0
160
- ? topItemsIndexes[topItemsIndexes.length - 1] + 1
161
- : 0;
207
+ var minStartIndex = topItemsIndexes.length > 0 ? topItemsIndexes[topItemsIndexes.length - 1] + 1 : 0;
162
208
  var offsetPointRanges = rangesWithinOffsets(offsetTree, startOffset, endOffset, minStartIndex);
163
209
  if (offsetPointRanges.length === 0) {
164
210
  return null;
165
211
  }
166
212
  var maxIndex = totalCount - 1;
167
213
  var items = u.tap([], function (result) {
168
- var e_3, _a;
214
+ var e_4, _a;
169
215
  try {
170
216
  for (var offsetPointRanges_1 = __values(offsetPointRanges), offsetPointRanges_1_1 = offsetPointRanges_1.next(); !offsetPointRanges_1_1.done; offsetPointRanges_1_1 = offsetPointRanges_1.next()) {
171
217
  var range = offsetPointRanges_1_1.value;
@@ -174,8 +220,9 @@ export var listStateSystem = u.system(function (_a) {
174
220
  var rangeStartIndex = range.start;
175
221
  var size = point.size;
176
222
  if (point.offset < startOffset) {
177
- rangeStartIndex += Math.floor((startOffset - point.offset) / size);
178
- offset += (rangeStartIndex - range.start) * size;
223
+ rangeStartIndex += Math.floor((startOffset - point.offset + gap) / (size + gap));
224
+ var itemCount = rangeStartIndex - range.start;
225
+ offset += itemCount * size + itemCount * gap;
179
226
  }
180
227
  if (rangeStartIndex < minStartIndex) {
181
228
  offset += (minStartIndex - rangeStartIndex) * size;
@@ -186,28 +233,25 @@ export var listStateSystem = u.system(function (_a) {
186
233
  if (offset >= endOffset) {
187
234
  break;
188
235
  }
189
- result.push({
190
- index: i,
191
- size: size,
192
- offset: offset,
193
- data: data && data[i],
194
- });
195
- offset += size;
236
+ result.push({ index: i, size: size, offset: offset, data: data && data[i] });
237
+ offset += size + gap;
196
238
  }
197
239
  }
198
240
  }
199
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
241
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
200
242
  finally {
201
243
  try {
202
244
  if (offsetPointRanges_1_1 && !offsetPointRanges_1_1.done && (_a = offsetPointRanges_1.return)) _a.call(offsetPointRanges_1);
203
245
  }
204
- finally { if (e_3) throw e_3.error; }
246
+ finally { if (e_4) throw e_4.error; }
205
247
  }
206
248
  });
207
- return buildListState(items, topItems, totalCount, sizesValue, firstItemIndex);
208
- }), u.filter(function (value) { return value !== null; }), u.distinctUntilChanged()), EMPTY_LIST_STATE);
209
- u.connect(u.pipe(data, u.filter(function (data) { return data !== undefined; }), u.map(function (data) { return data.length; })), totalCount);
210
- u.connect(u.pipe(listState, u.map(u.prop('topListHeight'))), topListHeight);
249
+ return buildListState(items, topItems, totalCount, gap, sizesValue, firstItemIndex);
250
+ }),
251
+ //@ts-expect-error filter needs to be fixed
252
+ u.filter(function (value) { return value !== null; }), u.distinctUntilChanged()), EMPTY_LIST_STATE);
253
+ u.connect(u.pipe(data, u.filter(u.isDefined), u.map(function (data) { return data === null || data === void 0 ? void 0 : data.length; })), totalCount);
254
+ u.connect(u.pipe(listState, u.map(function (value) { return value.topListHeight; })), topListHeight);
211
255
  u.connect(topListHeight, rangeTopListHeight);
212
256
  u.connect(u.pipe(listState, u.map(function (state) { return [state.top, state.bottom]; })), listBoundary);
213
257
  u.connect(u.pipe(listState, u.map(function (state) { return state.items; })), itemsRendered);
@@ -236,15 +280,18 @@ export var listStateSystem = u.system(function (_a) {
236
280
  return items.length > 0;
237
281
  }), u.map(function (_a) {
238
282
  var items = _a.items;
283
+ var startIndex = 0;
284
+ var endIndex = items.length - 1;
285
+ while (items[startIndex].type === 'group' && startIndex < endIndex) {
286
+ startIndex++;
287
+ }
288
+ while (items[endIndex].type === 'group' && endIndex > startIndex) {
289
+ endIndex--;
290
+ }
239
291
  return {
240
- startIndex: items[0].index,
241
- endIndex: items[items.length - 1].index,
292
+ startIndex: items[startIndex].index,
293
+ endIndex: items[endIndex].index,
242
294
  };
243
295
  }), u.distinctUntilChanged(rangeComparator)));
244
- return __assign({ listState: listState,
245
- topItemsIndexes: topItemsIndexes,
246
- endReached: endReached,
247
- startReached: startReached,
248
- rangeChanged: rangeChanged,
249
- itemsRendered: itemsRendered }, stateFlags);
250
- }, u.tup(sizeSystem, groupedListSystem, sizeRangeSystem, initialTopMostItemIndexSystem, scrollToIndexSystem, stateFlagsSystem, propsReadySystem), { singleton: true });
296
+ return __assign({ listState: listState, topItemsIndexes: topItemsIndexes, endReached: endReached, startReached: startReached, rangeChanged: rangeChanged, itemsRendered: itemsRendered, initialItemCount: initialItemCount }, stateFlags);
297
+ }, u.tup(sizeSystem, groupedListSystem, sizeRangeSystem, initialTopMostItemIndexSystem, scrollToIndexSystem, stateFlagsSystem, propsReadySystem, recalcSystem), { singleton: true });