@depup/react-virtualized 9.22.6-depup.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 (254) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +34 -0
  3. package/changes.json +22 -0
  4. package/dist/commonjs/ArrowKeyStepper/ArrowKeyStepper.example.js +184 -0
  5. package/dist/commonjs/ArrowKeyStepper/ArrowKeyStepper.jest.js +338 -0
  6. package/dist/commonjs/ArrowKeyStepper/ArrowKeyStepper.js +204 -0
  7. package/dist/commonjs/ArrowKeyStepper/index.js +19 -0
  8. package/dist/commonjs/ArrowKeyStepper/types.js +5 -0
  9. package/dist/commonjs/AutoSizer/AutoSizer.example.js +104 -0
  10. package/dist/commonjs/AutoSizer/AutoSizer.jest.js +341 -0
  11. package/dist/commonjs/AutoSizer/AutoSizer.js +199 -0
  12. package/dist/commonjs/AutoSizer/AutoSizer.ssr.js +25 -0
  13. package/dist/commonjs/AutoSizer/index.js +19 -0
  14. package/dist/commonjs/CellMeasurer/CellMeasurer.DynamicHeightGrid.example.js +100 -0
  15. package/dist/commonjs/CellMeasurer/CellMeasurer.DynamicHeightList.example.js +99 -0
  16. package/dist/commonjs/CellMeasurer/CellMeasurer.DynamicHeightTableColumn.example.js +107 -0
  17. package/dist/commonjs/CellMeasurer/CellMeasurer.DynamicWidthGrid.example.js +102 -0
  18. package/dist/commonjs/CellMeasurer/CellMeasurer.DynamicWidthMultiGrid.example.js +107 -0
  19. package/dist/commonjs/CellMeasurer/CellMeasurer.example.js +129 -0
  20. package/dist/commonjs/CellMeasurer/CellMeasurer.jest.js +345 -0
  21. package/dist/commonjs/CellMeasurer/CellMeasurer.js +195 -0
  22. package/dist/commonjs/CellMeasurer/CellMeasurerCache.jest.js +298 -0
  23. package/dist/commonjs/CellMeasurer/CellMeasurerCache.js +202 -0
  24. package/dist/commonjs/CellMeasurer/index.js +22 -0
  25. package/dist/commonjs/CellMeasurer/types.js +14 -0
  26. package/dist/commonjs/Collection/Collection.example.js +231 -0
  27. package/dist/commonjs/Collection/Collection.jest.js +829 -0
  28. package/dist/commonjs/Collection/Collection.js +266 -0
  29. package/dist/commonjs/Collection/CollectionView.js +553 -0
  30. package/dist/commonjs/Collection/Section.jest.js +63 -0
  31. package/dist/commonjs/Collection/Section.js +57 -0
  32. package/dist/commonjs/Collection/SectionManager.jest.js +121 -0
  33. package/dist/commonjs/Collection/SectionManager.js +134 -0
  34. package/dist/commonjs/Collection/TestData.js +77 -0
  35. package/dist/commonjs/Collection/index.js +15 -0
  36. package/dist/commonjs/Collection/types.js +22 -0
  37. package/dist/commonjs/Collection/utils/calculateSizeAndPositionData.jest.js +34 -0
  38. package/dist/commonjs/Collection/utils/calculateSizeAndPositionData.js +38 -0
  39. package/dist/commonjs/ColumnSizer/ColumnSizer.example.js +159 -0
  40. package/dist/commonjs/ColumnSizer/ColumnSizer.jest.js +129 -0
  41. package/dist/commonjs/ColumnSizer/ColumnSizer.js +103 -0
  42. package/dist/commonjs/ColumnSizer/index.js +15 -0
  43. package/dist/commonjs/Grid/Grid.example.js +330 -0
  44. package/dist/commonjs/Grid/Grid.jest.js +2561 -0
  45. package/dist/commonjs/Grid/Grid.js +1432 -0
  46. package/dist/commonjs/Grid/Grid.ssr.js +62 -0
  47. package/dist/commonjs/Grid/accessibilityOverscanIndicesGetter.jest.js +92 -0
  48. package/dist/commonjs/Grid/accessibilityOverscanIndicesGetter.js +40 -0
  49. package/dist/commonjs/Grid/defaultCellRangeRenderer.js +139 -0
  50. package/dist/commonjs/Grid/defaultOverscanIndicesGetter.jest.js +92 -0
  51. package/dist/commonjs/Grid/defaultOverscanIndicesGetter.js +36 -0
  52. package/dist/commonjs/Grid/index.js +40 -0
  53. package/dist/commonjs/Grid/types.js +8 -0
  54. package/dist/commonjs/Grid/utils/CellSizeAndPositionManager.jest.js +375 -0
  55. package/dist/commonjs/Grid/utils/CellSizeAndPositionManager.js +296 -0
  56. package/dist/commonjs/Grid/utils/ScalingCellSizeAndPositionManager.jest.js +201 -0
  57. package/dist/commonjs/Grid/utils/ScalingCellSizeAndPositionManager.js +204 -0
  58. package/dist/commonjs/Grid/utils/calculateSizeAndPositionDataAndUpdateScrollOffset.jest.js +84 -0
  59. package/dist/commonjs/Grid/utils/calculateSizeAndPositionDataAndUpdateScrollOffset.js +59 -0
  60. package/dist/commonjs/Grid/utils/maxElementSize.js +22 -0
  61. package/dist/commonjs/Grid/utils/updateScrollIndexHelper.jest.js +180 -0
  62. package/dist/commonjs/Grid/utils/updateScrollIndexHelper.js +85 -0
  63. package/dist/commonjs/InfiniteLoader/InfiniteLoader.example.js +179 -0
  64. package/dist/commonjs/InfiniteLoader/InfiniteLoader.jest.js +571 -0
  65. package/dist/commonjs/InfiniteLoader/InfiniteLoader.js +274 -0
  66. package/dist/commonjs/InfiniteLoader/index.js +15 -0
  67. package/dist/commonjs/List/List.example.js +236 -0
  68. package/dist/commonjs/List/List.jest.js +517 -0
  69. package/dist/commonjs/List/List.js +318 -0
  70. package/dist/commonjs/List/index.js +19 -0
  71. package/dist/commonjs/List/types.js +6 -0
  72. package/dist/commonjs/Masonry/Masonry.example.js +287 -0
  73. package/dist/commonjs/Masonry/Masonry.jest.js +450 -0
  74. package/dist/commonjs/Masonry/Masonry.js +431 -0
  75. package/dist/commonjs/Masonry/PositionCache.js +88 -0
  76. package/dist/commonjs/Masonry/createCellPositioner.js +59 -0
  77. package/dist/commonjs/Masonry/index.js +22 -0
  78. package/dist/commonjs/MultiGrid/CellMeasurerCacheDecorator.js +106 -0
  79. package/dist/commonjs/MultiGrid/MultiGrid.example.js +131 -0
  80. package/dist/commonjs/MultiGrid/MultiGrid.jest.js +584 -0
  81. package/dist/commonjs/MultiGrid/MultiGrid.js +743 -0
  82. package/dist/commonjs/MultiGrid/index.js +15 -0
  83. package/dist/commonjs/ScrollSync/ScrollSync.example.js +257 -0
  84. package/dist/commonjs/ScrollSync/ScrollSync.jest.js +66 -0
  85. package/dist/commonjs/ScrollSync/ScrollSync.js +88 -0
  86. package/dist/commonjs/ScrollSync/index.js +15 -0
  87. package/dist/commonjs/Table/Column.jest.js +90 -0
  88. package/dist/commonjs/Table/Column.js +93 -0
  89. package/dist/commonjs/Table/SortDirection.js +19 -0
  90. package/dist/commonjs/Table/SortIndicator.js +40 -0
  91. package/dist/commonjs/Table/Table.example.js +325 -0
  92. package/dist/commonjs/Table/Table.jest.js +1257 -0
  93. package/dist/commonjs/Table/Table.js +742 -0
  94. package/dist/commonjs/Table/createMultiSort.jest.js +165 -0
  95. package/dist/commonjs/Table/createMultiSort.js +99 -0
  96. package/dist/commonjs/Table/defaultCellDataGetter.js +21 -0
  97. package/dist/commonjs/Table/defaultCellRenderer.js +19 -0
  98. package/dist/commonjs/Table/defaultHeaderRenderer.js +35 -0
  99. package/dist/commonjs/Table/defaultHeaderRowRenderer.js +21 -0
  100. package/dist/commonjs/Table/defaultRowRenderer.js +87 -0
  101. package/dist/commonjs/Table/index.js +78 -0
  102. package/dist/commonjs/Table/types.js +39 -0
  103. package/dist/commonjs/WindowScroller/WindowScroller.e2e.js +298 -0
  104. package/dist/commonjs/WindowScroller/WindowScroller.example.js +167 -0
  105. package/dist/commonjs/WindowScroller/WindowScroller.header-resize.e2e.js +359 -0
  106. package/dist/commonjs/WindowScroller/WindowScroller.jest.js +536 -0
  107. package/dist/commonjs/WindowScroller/WindowScroller.js +268 -0
  108. package/dist/commonjs/WindowScroller/WindowScroller.ssr.js +25 -0
  109. package/dist/commonjs/WindowScroller/index.js +23 -0
  110. package/dist/commonjs/WindowScroller/utils/dimensions.js +89 -0
  111. package/dist/commonjs/WindowScroller/utils/onScroll.js +70 -0
  112. package/dist/commonjs/index.js +180 -0
  113. package/dist/commonjs/jest-setup.js +7 -0
  114. package/dist/commonjs/utils/TestHelper.js +36 -0
  115. package/dist/commonjs/utils/animationFrame.js +29 -0
  116. package/dist/commonjs/utils/createCallbackMemoizer.jest.js +219 -0
  117. package/dist/commonjs/utils/createCallbackMemoizer.js +31 -0
  118. package/dist/commonjs/utils/getUpdatedOffsetForIndex.jest.js +68 -0
  119. package/dist/commonjs/utils/getUpdatedOffsetForIndex.js +38 -0
  120. package/dist/commonjs/utils/initCellMetadata.js +37 -0
  121. package/dist/commonjs/utils/requestAnimationTimeout.js +38 -0
  122. package/dist/commonjs/vendor/binarySearchBounds.js +200 -0
  123. package/dist/commonjs/vendor/detectElementResize.js +192 -0
  124. package/dist/commonjs/vendor/intervalTree.js +361 -0
  125. package/dist/es/ArrowKeyStepper/ArrowKeyStepper.example.js +176 -0
  126. package/dist/es/ArrowKeyStepper/ArrowKeyStepper.jest.js +332 -0
  127. package/dist/es/ArrowKeyStepper/ArrowKeyStepper.js +197 -0
  128. package/dist/es/ArrowKeyStepper/index.js +3 -0
  129. package/dist/es/ArrowKeyStepper/types.js +4 -0
  130. package/dist/es/AutoSizer/AutoSizer.example.js +96 -0
  131. package/dist/es/AutoSizer/AutoSizer.jest.js +335 -0
  132. package/dist/es/AutoSizer/AutoSizer.js +190 -0
  133. package/dist/es/AutoSizer/AutoSizer.js.flow +200 -0
  134. package/dist/es/AutoSizer/AutoSizer.ssr.js +19 -0
  135. package/dist/es/AutoSizer/index.js +2 -0
  136. package/dist/es/AutoSizer/index.js.flow +4 -0
  137. package/dist/es/CellMeasurer/CellMeasurer.DynamicHeightGrid.example.js +91 -0
  138. package/dist/es/CellMeasurer/CellMeasurer.DynamicHeightList.example.js +90 -0
  139. package/dist/es/CellMeasurer/CellMeasurer.DynamicHeightTableColumn.example.js +98 -0
  140. package/dist/es/CellMeasurer/CellMeasurer.DynamicWidthGrid.example.js +93 -0
  141. package/dist/es/CellMeasurer/CellMeasurer.DynamicWidthMultiGrid.example.js +98 -0
  142. package/dist/es/CellMeasurer/CellMeasurer.example.js +120 -0
  143. package/dist/es/CellMeasurer/CellMeasurer.jest.js +340 -0
  144. package/dist/es/CellMeasurer/CellMeasurer.js +187 -0
  145. package/dist/es/CellMeasurer/CellMeasurerCache.jest.js +293 -0
  146. package/dist/es/CellMeasurer/CellMeasurerCache.js +196 -0
  147. package/dist/es/CellMeasurer/index.js +4 -0
  148. package/dist/es/CellMeasurer/types.js +13 -0
  149. package/dist/es/Collection/Collection.example.js +223 -0
  150. package/dist/es/Collection/Collection.jest.js +824 -0
  151. package/dist/es/Collection/Collection.js +257 -0
  152. package/dist/es/Collection/CollectionView.js +544 -0
  153. package/dist/es/Collection/Section.jest.js +60 -0
  154. package/dist/es/Collection/Section.js +51 -0
  155. package/dist/es/Collection/SectionManager.jest.js +118 -0
  156. package/dist/es/Collection/SectionManager.js +128 -0
  157. package/dist/es/Collection/TestData.js +71 -0
  158. package/dist/es/Collection/index.js +3 -0
  159. package/dist/es/Collection/types.js +21 -0
  160. package/dist/es/Collection/utils/calculateSizeAndPositionData.jest.js +31 -0
  161. package/dist/es/Collection/utils/calculateSizeAndPositionData.js +31 -0
  162. package/dist/es/ColumnSizer/ColumnSizer.example.js +150 -0
  163. package/dist/es/ColumnSizer/ColumnSizer.jest.js +123 -0
  164. package/dist/es/ColumnSizer/ColumnSizer.js +95 -0
  165. package/dist/es/ColumnSizer/index.js +3 -0
  166. package/dist/es/Grid/Grid.example.js +321 -0
  167. package/dist/es/Grid/Grid.jest.js +2555 -0
  168. package/dist/es/Grid/Grid.js +1425 -0
  169. package/dist/es/Grid/Grid.ssr.js +57 -0
  170. package/dist/es/Grid/accessibilityOverscanIndicesGetter.jest.js +87 -0
  171. package/dist/es/Grid/accessibilityOverscanIndicesGetter.js +33 -0
  172. package/dist/es/Grid/defaultCellRangeRenderer.js +134 -0
  173. package/dist/es/Grid/defaultOverscanIndicesGetter.jest.js +87 -0
  174. package/dist/es/Grid/defaultOverscanIndicesGetter.js +29 -0
  175. package/dist/es/Grid/index.js +15 -0
  176. package/dist/es/Grid/types.js +96 -0
  177. package/dist/es/Grid/utils/CellSizeAndPositionManager.jest.js +372 -0
  178. package/dist/es/Grid/utils/CellSizeAndPositionManager.js +290 -0
  179. package/dist/es/Grid/utils/ScalingCellSizeAndPositionManager.jest.js +198 -0
  180. package/dist/es/Grid/utils/ScalingCellSizeAndPositionManager.js +198 -0
  181. package/dist/es/Grid/utils/calculateSizeAndPositionDataAndUpdateScrollOffset.jest.js +81 -0
  182. package/dist/es/Grid/utils/calculateSizeAndPositionDataAndUpdateScrollOffset.js +53 -0
  183. package/dist/es/Grid/utils/maxElementSize.js +16 -0
  184. package/dist/es/Grid/utils/updateScrollIndexHelper.jest.js +174 -0
  185. package/dist/es/Grid/utils/updateScrollIndexHelper.js +79 -0
  186. package/dist/es/InfiniteLoader/InfiniteLoader.example.js +170 -0
  187. package/dist/es/InfiniteLoader/InfiniteLoader.jest.js +565 -0
  188. package/dist/es/InfiniteLoader/InfiniteLoader.js +263 -0
  189. package/dist/es/InfiniteLoader/index.js +3 -0
  190. package/dist/es/List/List.example.js +227 -0
  191. package/dist/es/List/List.jest.js +511 -0
  192. package/dist/es/List/List.js +312 -0
  193. package/dist/es/List/index.js +3 -0
  194. package/dist/es/List/types.js +21 -0
  195. package/dist/es/Masonry/Masonry.example.js +278 -0
  196. package/dist/es/Masonry/Masonry.jest.js +444 -0
  197. package/dist/es/Masonry/Masonry.js +421 -0
  198. package/dist/es/Masonry/PositionCache.js +82 -0
  199. package/dist/es/Masonry/createCellPositioner.js +53 -0
  200. package/dist/es/Masonry/index.js +4 -0
  201. package/dist/es/MultiGrid/CellMeasurerCacheDecorator.js +100 -0
  202. package/dist/es/MultiGrid/MultiGrid.example.js +122 -0
  203. package/dist/es/MultiGrid/MultiGrid.jest.js +579 -0
  204. package/dist/es/MultiGrid/MultiGrid.js +733 -0
  205. package/dist/es/MultiGrid/index.js +3 -0
  206. package/dist/es/ScrollSync/ScrollSync.example.js +248 -0
  207. package/dist/es/ScrollSync/ScrollSync.jest.js +60 -0
  208. package/dist/es/ScrollSync/ScrollSync.js +80 -0
  209. package/dist/es/ScrollSync/index.js +3 -0
  210. package/dist/es/Table/Column.jest.js +84 -0
  211. package/dist/es/Table/Column.js +85 -0
  212. package/dist/es/Table/SortDirection.js +13 -0
  213. package/dist/es/Table/SortIndicator.js +31 -0
  214. package/dist/es/Table/Table.example.js +316 -0
  215. package/dist/es/Table/Table.jest.js +1251 -0
  216. package/dist/es/Table/Table.js +735 -0
  217. package/dist/es/Table/createMultiSort.jest.js +162 -0
  218. package/dist/es/Table/createMultiSort.js +93 -0
  219. package/dist/es/Table/defaultCellDataGetter.js +15 -0
  220. package/dist/es/Table/defaultCellRenderer.js +13 -0
  221. package/dist/es/Table/defaultHeaderRenderer.js +25 -0
  222. package/dist/es/Table/defaultHeaderRowRenderer.js +12 -0
  223. package/dist/es/Table/defaultRowRenderer.js +77 -0
  224. package/dist/es/Table/index.js +12 -0
  225. package/dist/es/Table/types.js +38 -0
  226. package/dist/es/WindowScroller/WindowScroller.e2e.js +295 -0
  227. package/dist/es/WindowScroller/WindowScroller.example.js +158 -0
  228. package/dist/es/WindowScroller/WindowScroller.header-resize.e2e.js +356 -0
  229. package/dist/es/WindowScroller/WindowScroller.jest.js +530 -0
  230. package/dist/es/WindowScroller/WindowScroller.js +259 -0
  231. package/dist/es/WindowScroller/WindowScroller.js.flow +277 -0
  232. package/dist/es/WindowScroller/WindowScroller.ssr.js +19 -0
  233. package/dist/es/WindowScroller/index.js +3 -0
  234. package/dist/es/WindowScroller/index.js.flow +6 -0
  235. package/dist/es/WindowScroller/utils/dimensions.js +81 -0
  236. package/dist/es/WindowScroller/utils/dimensions.js.flow +91 -0
  237. package/dist/es/WindowScroller/utils/onScroll.js +64 -0
  238. package/dist/es/WindowScroller/utils/onScroll.js.flow +94 -0
  239. package/dist/es/index.js +13 -0
  240. package/dist/es/jest-setup.js +5 -0
  241. package/dist/es/utils/TestHelper.js +30 -0
  242. package/dist/es/utils/animationFrame.js +23 -0
  243. package/dist/es/utils/createCallbackMemoizer.jest.js +216 -0
  244. package/dist/es/utils/createCallbackMemoizer.js +25 -0
  245. package/dist/es/utils/getUpdatedOffsetForIndex.jest.js +65 -0
  246. package/dist/es/utils/getUpdatedOffsetForIndex.js +32 -0
  247. package/dist/es/utils/initCellMetadata.js +31 -0
  248. package/dist/es/utils/requestAnimationTimeout.js +32 -0
  249. package/dist/es/vendor/binarySearchBounds.js +194 -0
  250. package/dist/es/vendor/detectElementResize.js +186 -0
  251. package/dist/es/vendor/intervalTree.js +354 -0
  252. package/dist/umd/react-virtualized.js +4638 -0
  253. package/package.json +188 -0
  254. package/styles.css +80 -0
@@ -0,0 +1,544 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
4
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
5
+ import _inherits from "@babel/runtime/helpers/inherits";
6
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
7
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
8
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
9
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
10
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
11
+ import clsx from 'clsx';
12
+ import PropTypes from 'prop-types';
13
+ import * as React from 'react';
14
+ import { polyfill } from 'react-lifecycles-compat';
15
+ import createCallbackMemoizer from '../utils/createCallbackMemoizer';
16
+ import getScrollbarSize from 'dom-helpers/scrollbarSize';
17
+
18
+ // @TODO Merge Collection and CollectionView
19
+
20
+ /**
21
+ * Specifies the number of milliseconds during which to disable pointer events while a scroll is in progress.
22
+ * This improves performance and makes scrolling smoother.
23
+ */
24
+ var IS_SCROLLING_TIMEOUT = 150;
25
+
26
+ /**
27
+ * Controls whether the Grid updates the DOM element's scrollLeft/scrollTop based on the current state or just observes it.
28
+ * This prevents Grid from interrupting mouse-wheel animations (see issue #2).
29
+ */
30
+ var SCROLL_POSITION_CHANGE_REASONS = {
31
+ OBSERVED: 'observed',
32
+ REQUESTED: 'requested'
33
+ };
34
+
35
+ /**
36
+ * Monitors changes in properties (eg. cellCount) and state (eg. scroll offsets) to determine when rendering needs to occur.
37
+ * This component does not render any visible content itself; it defers to the specified :cellLayoutManager.
38
+ */
39
+ var CollectionView = /*#__PURE__*/function (_React$PureComponent) {
40
+ function CollectionView() {
41
+ var _this;
42
+ _classCallCheck(this, CollectionView);
43
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
44
+ args[_key] = arguments[_key];
45
+ }
46
+ _this = _callSuper(this, CollectionView, [].concat(args));
47
+
48
+ // If this component is being rendered server-side, getScrollbarSize() will return undefined.
49
+ // We handle this case in componentDidMount()
50
+ _defineProperty(_this, "state", {
51
+ isScrolling: false,
52
+ scrollLeft: 0,
53
+ scrollTop: 0
54
+ });
55
+ _defineProperty(_this, "_calculateSizeAndPositionDataOnNextUpdate", false);
56
+ // Invokes callbacks only when their values have changed.
57
+ _defineProperty(_this, "_onSectionRenderedMemoizer", createCallbackMemoizer());
58
+ _defineProperty(_this, "_onScrollMemoizer", createCallbackMemoizer(false));
59
+ _defineProperty(_this, "_invokeOnSectionRenderedHelper", function () {
60
+ var _this$props = _this.props,
61
+ cellLayoutManager = _this$props.cellLayoutManager,
62
+ onSectionRendered = _this$props.onSectionRendered;
63
+ _this._onSectionRenderedMemoizer({
64
+ callback: onSectionRendered,
65
+ indices: {
66
+ indices: cellLayoutManager.getLastRenderedIndices()
67
+ }
68
+ });
69
+ });
70
+ _defineProperty(_this, "_setScrollingContainerRef", function (ref) {
71
+ _this._scrollingContainer = ref;
72
+ });
73
+ _defineProperty(_this, "_updateScrollPositionForScrollToCell", function () {
74
+ var _this$props2 = _this.props,
75
+ cellLayoutManager = _this$props2.cellLayoutManager,
76
+ height = _this$props2.height,
77
+ scrollToAlignment = _this$props2.scrollToAlignment,
78
+ scrollToCell = _this$props2.scrollToCell,
79
+ width = _this$props2.width;
80
+ var _this$state = _this.state,
81
+ scrollLeft = _this$state.scrollLeft,
82
+ scrollTop = _this$state.scrollTop;
83
+ if (scrollToCell >= 0) {
84
+ var scrollPosition = cellLayoutManager.getScrollPositionForCell({
85
+ align: scrollToAlignment,
86
+ cellIndex: scrollToCell,
87
+ height: height,
88
+ scrollLeft: scrollLeft,
89
+ scrollTop: scrollTop,
90
+ width: width
91
+ });
92
+ if (scrollPosition.scrollLeft !== scrollLeft || scrollPosition.scrollTop !== scrollTop) {
93
+ _this._setScrollPosition(scrollPosition);
94
+ }
95
+ }
96
+ });
97
+ _defineProperty(_this, "_onScroll", function (event) {
98
+ // In certain edge-cases React dispatches an onScroll event with an invalid target.scrollLeft / target.scrollTop.
99
+ // This invalid event can be detected by comparing event.target to this component's scrollable DOM element.
100
+ // See issue #404 for more information.
101
+ if (event.target !== _this._scrollingContainer) {
102
+ return;
103
+ }
104
+
105
+ // Prevent pointer events from interrupting a smooth scroll
106
+ _this._enablePointerEventsAfterDelay();
107
+
108
+ // When this component is shrunk drastically, React dispatches a series of back-to-back scroll events,
109
+ // Gradually converging on a scrollTop that is within the bounds of the new, smaller height.
110
+ // This causes a series of rapid renders that is slow for long lists.
111
+ // We can avoid that by doing some simple bounds checking to ensure that scrollTop never exceeds the total height.
112
+ var _this$props3 = _this.props,
113
+ cellLayoutManager = _this$props3.cellLayoutManager,
114
+ height = _this$props3.height,
115
+ isScrollingChange = _this$props3.isScrollingChange,
116
+ width = _this$props3.width;
117
+ var scrollbarSize = _this._scrollbarSize;
118
+ var _cellLayoutManager$ge = cellLayoutManager.getTotalSize(),
119
+ totalHeight = _cellLayoutManager$ge.height,
120
+ totalWidth = _cellLayoutManager$ge.width;
121
+ var scrollLeft = Math.max(0, Math.min(totalWidth - width + scrollbarSize, event.target.scrollLeft));
122
+ var scrollTop = Math.max(0, Math.min(totalHeight - height + scrollbarSize, event.target.scrollTop));
123
+
124
+ // Certain devices (like Apple touchpad) rapid-fire duplicate events.
125
+ // Don't force a re-render if this is the case.
126
+ // The mouse may move faster then the animation frame does.
127
+ // Use requestAnimationFrame to avoid over-updating.
128
+ if (_this.state.scrollLeft !== scrollLeft || _this.state.scrollTop !== scrollTop) {
129
+ // Browsers with cancelable scroll events (eg. Firefox) interrupt scrolling animations if scrollTop/scrollLeft is set.
130
+ // Other browsers (eg. Safari) don't scroll as well without the help under certain conditions (DOM or style changes during scrolling).
131
+ // All things considered, this seems to be the best current work around that I'm aware of.
132
+ // For more information see https://github.com/bvaughn/react-virtualized/pull/124
133
+ var scrollPositionChangeReason = event.cancelable ? SCROLL_POSITION_CHANGE_REASONS.OBSERVED : SCROLL_POSITION_CHANGE_REASONS.REQUESTED;
134
+
135
+ // Synchronously set :isScrolling the first time (since _setNextState will reschedule its animation frame each time it's called)
136
+ if (!_this.state.isScrolling) {
137
+ isScrollingChange(true);
138
+ }
139
+ _this.setState({
140
+ isScrolling: true,
141
+ scrollLeft: scrollLeft,
142
+ scrollPositionChangeReason: scrollPositionChangeReason,
143
+ scrollTop: scrollTop
144
+ });
145
+ }
146
+ _this._invokeOnScrollMemoizer({
147
+ scrollLeft: scrollLeft,
148
+ scrollTop: scrollTop,
149
+ totalWidth: totalWidth,
150
+ totalHeight: totalHeight
151
+ });
152
+ });
153
+ _this._scrollbarSize = getScrollbarSize();
154
+ if (_this._scrollbarSize === undefined) {
155
+ _this._scrollbarSizeMeasured = false;
156
+ _this._scrollbarSize = 0;
157
+ } else {
158
+ _this._scrollbarSizeMeasured = true;
159
+ }
160
+ return _this;
161
+ }
162
+
163
+ /**
164
+ * Forced recompute of cell sizes and positions.
165
+ * This function should be called if cell sizes have changed but nothing else has.
166
+ * Since cell positions are calculated by callbacks, the collection view has no way of detecting when the underlying data has changed.
167
+ */
168
+ _inherits(CollectionView, _React$PureComponent);
169
+ return _createClass(CollectionView, [{
170
+ key: "recomputeCellSizesAndPositions",
171
+ value: function recomputeCellSizesAndPositions() {
172
+ this._calculateSizeAndPositionDataOnNextUpdate = true;
173
+ this.forceUpdate();
174
+ }
175
+
176
+ /* ---------------------------- Component lifecycle methods ---------------------------- */
177
+
178
+ /**
179
+ * @private
180
+ * This method updates scrollLeft/scrollTop in state for the following conditions:
181
+ * 1) Empty content (0 rows or columns)
182
+ * 2) New scroll props overriding the current state
183
+ * 3) Cells-count or cells-size has changed, making previous scroll offsets invalid
184
+ */
185
+ }, {
186
+ key: "componentDidMount",
187
+ value: function componentDidMount() {
188
+ var _this$props4 = this.props,
189
+ cellLayoutManager = _this$props4.cellLayoutManager,
190
+ scrollLeft = _this$props4.scrollLeft,
191
+ scrollToCell = _this$props4.scrollToCell,
192
+ scrollTop = _this$props4.scrollTop;
193
+
194
+ // If this component was first rendered server-side, scrollbar size will be undefined.
195
+ // In that event we need to remeasure.
196
+ if (!this._scrollbarSizeMeasured) {
197
+ this._scrollbarSize = getScrollbarSize();
198
+ this._scrollbarSizeMeasured = true;
199
+ this.setState({});
200
+ }
201
+ if (scrollToCell >= 0) {
202
+ this._updateScrollPositionForScrollToCell();
203
+ } else if (scrollLeft >= 0 || scrollTop >= 0) {
204
+ this._setScrollPosition({
205
+ scrollLeft: scrollLeft,
206
+ scrollTop: scrollTop
207
+ });
208
+ }
209
+
210
+ // Update onSectionRendered callback.
211
+ this._invokeOnSectionRenderedHelper();
212
+ var _cellLayoutManager$ge2 = cellLayoutManager.getTotalSize(),
213
+ totalHeight = _cellLayoutManager$ge2.height,
214
+ totalWidth = _cellLayoutManager$ge2.width;
215
+
216
+ // Initialize onScroll callback.
217
+ this._invokeOnScrollMemoizer({
218
+ scrollLeft: scrollLeft || 0,
219
+ scrollTop: scrollTop || 0,
220
+ totalHeight: totalHeight,
221
+ totalWidth: totalWidth
222
+ });
223
+ }
224
+ }, {
225
+ key: "componentDidUpdate",
226
+ value: function componentDidUpdate(prevProps, prevState) {
227
+ var _this$props5 = this.props,
228
+ height = _this$props5.height,
229
+ scrollToAlignment = _this$props5.scrollToAlignment,
230
+ scrollToCell = _this$props5.scrollToCell,
231
+ width = _this$props5.width;
232
+ var _this$state2 = this.state,
233
+ scrollLeft = _this$state2.scrollLeft,
234
+ scrollPositionChangeReason = _this$state2.scrollPositionChangeReason,
235
+ scrollTop = _this$state2.scrollTop;
236
+
237
+ // Make sure requested changes to :scrollLeft or :scrollTop get applied.
238
+ // Assigning to scrollLeft/scrollTop tells the browser to interrupt any running scroll animations,
239
+ // And to discard any pending async changes to the scroll position that may have happened in the meantime (e.g. on a separate scrolling thread).
240
+ // So we only set these when we require an adjustment of the scroll position.
241
+ // See issue #2 for more information.
242
+ if (scrollPositionChangeReason === SCROLL_POSITION_CHANGE_REASONS.REQUESTED) {
243
+ if (scrollLeft >= 0 && scrollLeft !== prevState.scrollLeft && scrollLeft !== this._scrollingContainer.scrollLeft) {
244
+ this._scrollingContainer.scrollLeft = scrollLeft;
245
+ }
246
+ if (scrollTop >= 0 && scrollTop !== prevState.scrollTop && scrollTop !== this._scrollingContainer.scrollTop) {
247
+ this._scrollingContainer.scrollTop = scrollTop;
248
+ }
249
+ }
250
+
251
+ // Update scroll offsets if the current :scrollToCell values requires it
252
+ if (height !== prevProps.height || scrollToAlignment !== prevProps.scrollToAlignment || scrollToCell !== prevProps.scrollToCell || width !== prevProps.width) {
253
+ this._updateScrollPositionForScrollToCell();
254
+ }
255
+
256
+ // Update onRowsRendered callback if start/stop indices have changed
257
+ this._invokeOnSectionRenderedHelper();
258
+ }
259
+ }, {
260
+ key: "componentWillUnmount",
261
+ value: function componentWillUnmount() {
262
+ if (this._disablePointerEventsTimeoutId) {
263
+ clearTimeout(this._disablePointerEventsTimeoutId);
264
+ }
265
+ }
266
+ }, {
267
+ key: "render",
268
+ value: function render() {
269
+ var _this$props6 = this.props,
270
+ autoHeight = _this$props6.autoHeight,
271
+ cellCount = _this$props6.cellCount,
272
+ cellLayoutManager = _this$props6.cellLayoutManager,
273
+ className = _this$props6.className,
274
+ height = _this$props6.height,
275
+ horizontalOverscanSize = _this$props6.horizontalOverscanSize,
276
+ id = _this$props6.id,
277
+ noContentRenderer = _this$props6.noContentRenderer,
278
+ style = _this$props6.style,
279
+ verticalOverscanSize = _this$props6.verticalOverscanSize,
280
+ width = _this$props6.width;
281
+ var _this$state3 = this.state,
282
+ isScrolling = _this$state3.isScrolling,
283
+ scrollLeft = _this$state3.scrollLeft,
284
+ scrollTop = _this$state3.scrollTop;
285
+
286
+ // Memoization reset
287
+ if (this._lastRenderedCellCount !== cellCount || this._lastRenderedCellLayoutManager !== cellLayoutManager || this._calculateSizeAndPositionDataOnNextUpdate) {
288
+ this._lastRenderedCellCount = cellCount;
289
+ this._lastRenderedCellLayoutManager = cellLayoutManager;
290
+ this._calculateSizeAndPositionDataOnNextUpdate = false;
291
+ cellLayoutManager.calculateSizeAndPositionData();
292
+ }
293
+ var _cellLayoutManager$ge3 = cellLayoutManager.getTotalSize(),
294
+ totalHeight = _cellLayoutManager$ge3.height,
295
+ totalWidth = _cellLayoutManager$ge3.width;
296
+
297
+ // Safely expand the rendered area by the specified overscan amount
298
+ var left = Math.max(0, scrollLeft - horizontalOverscanSize);
299
+ var top = Math.max(0, scrollTop - verticalOverscanSize);
300
+ var right = Math.min(totalWidth, scrollLeft + width + horizontalOverscanSize);
301
+ var bottom = Math.min(totalHeight, scrollTop + height + verticalOverscanSize);
302
+ var childrenToDisplay = height > 0 && width > 0 ? cellLayoutManager.cellRenderers({
303
+ height: bottom - top,
304
+ isScrolling: isScrolling,
305
+ width: right - left,
306
+ x: left,
307
+ y: top
308
+ }) : [];
309
+ var collectionStyle = {
310
+ boxSizing: 'border-box',
311
+ direction: 'ltr',
312
+ height: autoHeight ? 'auto' : height,
313
+ position: 'relative',
314
+ WebkitOverflowScrolling: 'touch',
315
+ width: width,
316
+ willChange: 'transform'
317
+ };
318
+
319
+ // Force browser to hide scrollbars when we know they aren't necessary.
320
+ // Otherwise once scrollbars appear they may not disappear again.
321
+ // For more info see issue #116
322
+ var verticalScrollBarSize = totalHeight > height ? this._scrollbarSize : 0;
323
+ var horizontalScrollBarSize = totalWidth > width ? this._scrollbarSize : 0;
324
+
325
+ // Also explicitly init styles to 'auto' if scrollbars are required.
326
+ // This works around an obscure edge case where external CSS styles have not yet been loaded,
327
+ // But an initial scroll index of offset is set as an external prop.
328
+ // Without this style, Grid would render the correct range of cells but would NOT update its internal offset.
329
+ // This was originally reported via clauderic/react-infinite-calendar/issues/23
330
+ collectionStyle.overflowX = totalWidth + verticalScrollBarSize <= width ? 'hidden' : 'auto';
331
+ collectionStyle.overflowY = totalHeight + horizontalScrollBarSize <= height ? 'hidden' : 'auto';
332
+ return /*#__PURE__*/React.createElement("div", {
333
+ ref: this._setScrollingContainerRef,
334
+ "aria-label": this.props['aria-label'],
335
+ className: clsx('ReactVirtualized__Collection', className),
336
+ id: id,
337
+ onScroll: this._onScroll,
338
+ role: "grid",
339
+ style: _objectSpread(_objectSpread({}, collectionStyle), style),
340
+ tabIndex: 0
341
+ }, cellCount > 0 && /*#__PURE__*/React.createElement("div", {
342
+ className: "ReactVirtualized__Collection__innerScrollContainer",
343
+ style: {
344
+ height: totalHeight,
345
+ maxHeight: totalHeight,
346
+ maxWidth: totalWidth,
347
+ overflow: 'hidden',
348
+ pointerEvents: isScrolling ? 'none' : '',
349
+ width: totalWidth
350
+ }
351
+ }, childrenToDisplay), cellCount === 0 && noContentRenderer());
352
+ }
353
+
354
+ /* ---------------------------- Helper methods ---------------------------- */
355
+
356
+ /**
357
+ * Sets an :isScrolling flag for a small window of time.
358
+ * This flag is used to disable pointer events on the scrollable portion of the Collection.
359
+ * This prevents jerky/stuttery mouse-wheel scrolling.
360
+ */
361
+ }, {
362
+ key: "_enablePointerEventsAfterDelay",
363
+ value: function _enablePointerEventsAfterDelay() {
364
+ var _this2 = this;
365
+ if (this._disablePointerEventsTimeoutId) {
366
+ clearTimeout(this._disablePointerEventsTimeoutId);
367
+ }
368
+ this._disablePointerEventsTimeoutId = setTimeout(function () {
369
+ var isScrollingChange = _this2.props.isScrollingChange;
370
+ isScrollingChange(false);
371
+ _this2._disablePointerEventsTimeoutId = null;
372
+ _this2.setState({
373
+ isScrolling: false
374
+ });
375
+ }, IS_SCROLLING_TIMEOUT);
376
+ }
377
+ }, {
378
+ key: "_invokeOnScrollMemoizer",
379
+ value: function _invokeOnScrollMemoizer(_ref) {
380
+ var _this3 = this;
381
+ var scrollLeft = _ref.scrollLeft,
382
+ scrollTop = _ref.scrollTop,
383
+ totalHeight = _ref.totalHeight,
384
+ totalWidth = _ref.totalWidth;
385
+ this._onScrollMemoizer({
386
+ callback: function callback(_ref2) {
387
+ var scrollLeft = _ref2.scrollLeft,
388
+ scrollTop = _ref2.scrollTop;
389
+ var _this3$props = _this3.props,
390
+ height = _this3$props.height,
391
+ onScroll = _this3$props.onScroll,
392
+ width = _this3$props.width;
393
+ onScroll({
394
+ clientHeight: height,
395
+ clientWidth: width,
396
+ scrollHeight: totalHeight,
397
+ scrollLeft: scrollLeft,
398
+ scrollTop: scrollTop,
399
+ scrollWidth: totalWidth
400
+ });
401
+ },
402
+ indices: {
403
+ scrollLeft: scrollLeft,
404
+ scrollTop: scrollTop
405
+ }
406
+ });
407
+ }
408
+ }, {
409
+ key: "_setScrollPosition",
410
+ value: function _setScrollPosition(_ref3) {
411
+ var scrollLeft = _ref3.scrollLeft,
412
+ scrollTop = _ref3.scrollTop;
413
+ var newState = {
414
+ scrollPositionChangeReason: SCROLL_POSITION_CHANGE_REASONS.REQUESTED
415
+ };
416
+ if (scrollLeft >= 0) {
417
+ newState.scrollLeft = scrollLeft;
418
+ }
419
+ if (scrollTop >= 0) {
420
+ newState.scrollTop = scrollTop;
421
+ }
422
+ if (scrollLeft >= 0 && scrollLeft !== this.state.scrollLeft || scrollTop >= 0 && scrollTop !== this.state.scrollTop) {
423
+ this.setState(newState);
424
+ }
425
+ }
426
+ }], [{
427
+ key: "getDerivedStateFromProps",
428
+ value: function getDerivedStateFromProps(nextProps, prevState) {
429
+ if (nextProps.cellCount === 0 && (prevState.scrollLeft !== 0 || prevState.scrollTop !== 0)) {
430
+ return {
431
+ scrollLeft: 0,
432
+ scrollTop: 0,
433
+ scrollPositionChangeReason: SCROLL_POSITION_CHANGE_REASONS.REQUESTED
434
+ };
435
+ } else if (nextProps.scrollLeft !== prevState.scrollLeft || nextProps.scrollTop !== prevState.scrollTop) {
436
+ return {
437
+ scrollLeft: nextProps.scrollLeft != null ? nextProps.scrollLeft : prevState.scrollLeft,
438
+ scrollTop: nextProps.scrollTop != null ? nextProps.scrollTop : prevState.scrollTop,
439
+ scrollPositionChangeReason: SCROLL_POSITION_CHANGE_REASONS.REQUESTED
440
+ };
441
+ }
442
+ return null;
443
+ }
444
+ }]);
445
+ }(React.PureComponent);
446
+ _defineProperty(CollectionView, "defaultProps", {
447
+ 'aria-label': 'grid',
448
+ horizontalOverscanSize: 0,
449
+ noContentRenderer: function noContentRenderer() {
450
+ return null;
451
+ },
452
+ onScroll: function onScroll() {
453
+ return null;
454
+ },
455
+ onSectionRendered: function onSectionRendered() {
456
+ return null;
457
+ },
458
+ scrollToAlignment: 'auto',
459
+ scrollToCell: -1,
460
+ style: {},
461
+ verticalOverscanSize: 0
462
+ });
463
+ CollectionView.propTypes = process.env.NODE_ENV !== "production" ? {
464
+ 'aria-label': PropTypes.string,
465
+ /**
466
+ * Removes fixed height from the scrollingContainer so that the total height
467
+ * of rows can stretch the window. Intended for use with WindowScroller
468
+ */
469
+ autoHeight: PropTypes.bool,
470
+ /**
471
+ * Number of cells in collection.
472
+ */
473
+ cellCount: PropTypes.number.isRequired,
474
+ /**
475
+ * Calculates cell sizes and positions and manages rendering the appropriate cells given a specified window.
476
+ */
477
+ cellLayoutManager: PropTypes.object.isRequired,
478
+ /**
479
+ * Optional custom CSS class name to attach to root Collection element.
480
+ */
481
+ className: PropTypes.string,
482
+ /**
483
+ * Height of Collection; this property determines the number of visible (vs virtualized) rows.
484
+ */
485
+ height: PropTypes.number.isRequired,
486
+ /**
487
+ * Optional custom id to attach to root Collection element.
488
+ */
489
+ id: PropTypes.string,
490
+ /**
491
+ * Enables the `Collection` to horiontally "overscan" its content similar to how `Grid` does.
492
+ * This can reduce flicker around the edges when a user scrolls quickly.
493
+ */
494
+ horizontalOverscanSize: PropTypes.number.isRequired,
495
+ isScrollingChange: PropTypes.func,
496
+ /**
497
+ * Optional renderer to be used in place of rows when either :rowCount or :cellCount is 0.
498
+ */
499
+ noContentRenderer: PropTypes.func.isRequired,
500
+ /**
501
+ * Callback invoked whenever the scroll offset changes within the inner scrollable region.
502
+ * This callback can be used to sync scrolling between lists, tables, or grids.
503
+ * ({ clientHeight, clientWidth, scrollHeight, scrollLeft, scrollTop, scrollWidth }): void
504
+ */
505
+ onScroll: PropTypes.func.isRequired,
506
+ /**
507
+ * Callback invoked with information about the section of the Collection that was just rendered.
508
+ * This callback is passed a named :indices parameter which is an Array of the most recently rendered section indices.
509
+ */
510
+ onSectionRendered: PropTypes.func.isRequired,
511
+ /**
512
+ * Horizontal offset.
513
+ */
514
+ scrollLeft: PropTypes.number,
515
+ /**
516
+ * Controls scroll-to-cell behavior of the Grid.
517
+ * The default ("auto") scrolls the least amount possible to ensure that the specified cell is fully visible.
518
+ * Use "start" to align cells to the top/left of the Grid and "end" to align bottom/right.
519
+ */
520
+ scrollToAlignment: PropTypes.oneOf(['auto', 'end', 'start', 'center']).isRequired,
521
+ /**
522
+ * Cell index to ensure visible (by forcefully scrolling if necessary).
523
+ */
524
+ scrollToCell: PropTypes.number.isRequired,
525
+ /**
526
+ * Vertical offset.
527
+ */
528
+ scrollTop: PropTypes.number,
529
+ /**
530
+ * Optional custom inline style to attach to root Collection element.
531
+ */
532
+ style: PropTypes.object,
533
+ /**
534
+ * Enables the `Collection` to vertically "overscan" its content similar to how `Grid` does.
535
+ * This can reduce flicker around the edges when a user scrolls quickly.
536
+ */
537
+ verticalOverscanSize: PropTypes.number.isRequired,
538
+ /**
539
+ * Width of Collection; this property determines the number of visible (vs virtualized) columns.
540
+ */
541
+ width: PropTypes.number.isRequired
542
+ } : {};
543
+ polyfill(CollectionView);
544
+ export default CollectionView;
@@ -0,0 +1,60 @@
1
+ import Section from './Section';
2
+ describe('Section', function () {
3
+ function helper() {
4
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
5
+ _ref$height = _ref.height,
6
+ height = _ref$height === void 0 ? 100 : _ref$height,
7
+ _ref$width = _ref.width,
8
+ width = _ref$width === void 0 ? 200 : _ref$width,
9
+ _ref$x = _ref.x,
10
+ x = _ref$x === void 0 ? 0 : _ref$x,
11
+ _ref$y = _ref.y,
12
+ y = _ref$y === void 0 ? 0 : _ref$y;
13
+ return new Section({
14
+ height: height,
15
+ width: width,
16
+ x: x,
17
+ y: y
18
+ });
19
+ }
20
+ it('should add a new cell index', function () {
21
+ var section = helper();
22
+ expect(section.getCellIndices()).toEqual([]);
23
+ section.addCellIndex({
24
+ index: 0
25
+ });
26
+ expect(section.getCellIndices()).toEqual([0]);
27
+ section.addCellIndex({
28
+ index: 1
29
+ });
30
+ expect(section.getCellIndices()).toEqual([0, 1]);
31
+ });
32
+ it('should not add a duplicate cell index', function () {
33
+ var section = helper();
34
+ section.addCellIndex({
35
+ index: 0
36
+ });
37
+ section.addCellIndex({
38
+ index: 1
39
+ });
40
+ section.addCellIndex({
41
+ index: 0
42
+ });
43
+ section.addCellIndex({
44
+ index: 1
45
+ });
46
+ section.addCellIndex({
47
+ index: 2
48
+ });
49
+ expect(section.getCellIndices()).toEqual([0, 1, 2]);
50
+ });
51
+ it('should define a working toString() method for debugging', function () {
52
+ var section = helper({
53
+ height: 100,
54
+ width: 200,
55
+ x: 25,
56
+ y: 50
57
+ });
58
+ expect(section.toString()).toEqual('25,50 200x100');
59
+ });
60
+ });
@@ -0,0 +1,51 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ /*:: import type {Index, SizeAndPositionInfo} from './types';*/
4
+ /**
5
+ * A section of the Window.
6
+ * Window Sections are used to group nearby cells.
7
+ * This enables us to more quickly determine which cells to display in a given region of the Window.
8
+ * Sections have a fixed size and contain 0 to many cells (tracked by their indices).
9
+ */
10
+ var Section = /*#__PURE__*/function () {
11
+ function Section(_ref /*:: */) {
12
+ var height = _ref /*:: */.height,
13
+ width = _ref /*:: */.width,
14
+ x = _ref /*:: */.x,
15
+ y = _ref /*:: */.y;
16
+ _classCallCheck(this, Section);
17
+ this.height = height;
18
+ this.width = width;
19
+ this.x = x;
20
+ this.y = y;
21
+ this._indexMap = {};
22
+ this._indices = [];
23
+ }
24
+
25
+ /** Add a cell to this section. */
26
+ return _createClass(Section, [{
27
+ key: "addCellIndex",
28
+ value: function addCellIndex(_ref2 /*:: */) {
29
+ var index = _ref2 /*:: */.index;
30
+ if (!this._indexMap[index]) {
31
+ this._indexMap[index] = true;
32
+ this._indices.push(index);
33
+ }
34
+ }
35
+
36
+ /** Get all cell indices that have been added to this section. */
37
+ }, {
38
+ key: "getCellIndices",
39
+ value: function getCellIndices() /*: Array<number>*/{
40
+ return this._indices;
41
+ }
42
+
43
+ /** Intended for debugger/test purposes only */
44
+ }, {
45
+ key: "toString",
46
+ value: function toString() {
47
+ return "".concat(this.x, ",").concat(this.y, " ").concat(this.width, "x").concat(this.height);
48
+ }
49
+ }]);
50
+ }();
51
+ export { Section as default };