react-window 1.8.6 → 1.8.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -5,8 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
6
 
7
7
  var _extends = _interopDefault(require('@babel/runtime/helpers/extends'));
8
- var _inheritsLoose = _interopDefault(require('@babel/runtime/helpers/inheritsLoose'));
9
8
  var _assertThisInitialized = _interopDefault(require('@babel/runtime/helpers/assertThisInitialized'));
9
+ var _inheritsLoose = _interopDefault(require('@babel/runtime/helpers/inheritsLoose'));
10
10
  var memoizeOne = _interopDefault(require('memoize-one'));
11
11
  var react = require('react');
12
12
  var _objectWithoutPropertiesLoose = _interopDefault(require('@babel/runtime/helpers/objectWithoutPropertiesLoose'));
@@ -121,20 +121,14 @@ var devWarningsTagName = null;
121
121
 
122
122
  if (process.env.NODE_ENV !== 'production') {
123
123
  if (typeof window !== 'undefined' && typeof window.WeakSet !== 'undefined') {
124
- devWarningsOverscanCount =
125
- /*#__PURE__*/
126
- new WeakSet();
127
- devWarningsOverscanRowsColumnsCount =
128
- /*#__PURE__*/
129
- new WeakSet();
130
- devWarningsTagName =
131
- /*#__PURE__*/
132
- new WeakSet();
124
+ devWarningsOverscanCount = /*#__PURE__*/new WeakSet();
125
+ devWarningsOverscanRowsColumnsCount = /*#__PURE__*/new WeakSet();
126
+ devWarningsTagName = /*#__PURE__*/new WeakSet();
133
127
  }
134
128
  }
135
129
 
136
130
  function createGridComponent(_ref2) {
137
- var _class, _temp;
131
+ var _class;
138
132
 
139
133
  var getColumnOffset = _ref2.getColumnOffset,
140
134
  getColumnStartIndexForOffset = _ref2.getColumnStartIndexForOffset,
@@ -151,9 +145,7 @@ function createGridComponent(_ref2) {
151
145
  initInstanceProps = _ref2.initInstanceProps,
152
146
  shouldResetStyleCacheOnItemSizeChange = _ref2.shouldResetStyleCacheOnItemSizeChange,
153
147
  validateProps = _ref2.validateProps;
154
- return _temp = _class =
155
- /*#__PURE__*/
156
- function (_PureComponent) {
148
+ return _class = /*#__PURE__*/function (_PureComponent) {
157
149
  _inheritsLoose(Grid, _PureComponent);
158
150
 
159
151
  // Always use explicit constructor for React components.
@@ -163,11 +155,11 @@ function createGridComponent(_ref2) {
163
155
  var _this;
164
156
 
165
157
  _this = _PureComponent.call(this, props) || this;
166
- _this._instanceProps = initInstanceProps(_this.props, _assertThisInitialized(_assertThisInitialized(_this)));
158
+ _this._instanceProps = initInstanceProps(_this.props, _assertThisInitialized(_this));
167
159
  _this._resetIsScrollingTimeoutId = null;
168
160
  _this._outerRef = void 0;
169
161
  _this.state = {
170
- instance: _assertThisInitialized(_assertThisInitialized(_this)),
162
+ instance: _assertThisInitialized(_this),
171
163
  isScrolling: false,
172
164
  horizontalScrollDirection: 'forward',
173
165
  scrollLeft: typeof _this.props.initialScrollLeft === 'number' ? _this.props.initialScrollLeft : 0,
@@ -576,11 +568,11 @@ function createGridComponent(_ref2) {
576
568
 
577
569
  this._callOnScroll(_scrollLeft, _scrollTop, _horizontalScrollDirection, _verticalScrollDirection, _scrollUpdateWasRequested);
578
570
  }
579
- }; // Lazily create and cache item styles while scrolling,
571
+ } // Lazily create and cache item styles while scrolling,
580
572
  // So that pure component sCU will prevent re-renders.
581
573
  // We maintain this cache, and pass a style prop rather than index,
582
574
  // So that List can clear cached styles and force item re-render if necessary.
583
-
575
+ ;
584
576
 
585
577
  _proto._getHorizontalRangeToRender = function _getHorizontalRangeToRender() {
586
578
  var _this$props6 = this.props,
@@ -639,7 +631,7 @@ function createGridComponent(_ref2) {
639
631
  direction: 'ltr',
640
632
  itemData: undefined,
641
633
  useIsScrolling: false
642
- }, _temp;
634
+ }, _class;
643
635
  }
644
636
 
645
637
  var validateSharedProps = function validateSharedProps(_ref5, _ref6) {
@@ -887,9 +879,7 @@ var getOffsetForIndexAndAlignment = function getOffsetForIndexAndAlignment(itemT
887
879
  }
888
880
  };
889
881
 
890
- var VariableSizeGrid =
891
- /*#__PURE__*/
892
- createGridComponent({
882
+ var VariableSizeGrid = /*#__PURE__*/createGridComponent({
893
883
  getColumnOffset: function getColumnOffset(props, index, instanceProps) {
894
884
  return getItemMetadata('column', props, index, instanceProps).offset;
895
885
  },
@@ -1036,17 +1026,13 @@ var devWarningsTagName$1 = null;
1036
1026
 
1037
1027
  if (process.env.NODE_ENV !== 'production') {
1038
1028
  if (typeof window !== 'undefined' && typeof window.WeakSet !== 'undefined') {
1039
- devWarningsDirection =
1040
- /*#__PURE__*/
1041
- new WeakSet();
1042
- devWarningsTagName$1 =
1043
- /*#__PURE__*/
1044
- new WeakSet();
1029
+ devWarningsDirection = /*#__PURE__*/new WeakSet();
1030
+ devWarningsTagName$1 = /*#__PURE__*/new WeakSet();
1045
1031
  }
1046
1032
  }
1047
1033
 
1048
1034
  function createListComponent(_ref) {
1049
- var _class, _temp;
1035
+ var _class;
1050
1036
 
1051
1037
  var getItemOffset = _ref.getItemOffset,
1052
1038
  getEstimatedTotalSize = _ref.getEstimatedTotalSize,
@@ -1057,9 +1043,7 @@ function createListComponent(_ref) {
1057
1043
  initInstanceProps = _ref.initInstanceProps,
1058
1044
  shouldResetStyleCacheOnItemSizeChange = _ref.shouldResetStyleCacheOnItemSizeChange,
1059
1045
  validateProps = _ref.validateProps;
1060
- return _temp = _class =
1061
- /*#__PURE__*/
1062
- function (_PureComponent) {
1046
+ return _class = /*#__PURE__*/function (_PureComponent) {
1063
1047
  _inheritsLoose(List, _PureComponent);
1064
1048
 
1065
1049
  // Always use explicit constructor for React components.
@@ -1069,11 +1053,11 @@ function createListComponent(_ref) {
1069
1053
  var _this;
1070
1054
 
1071
1055
  _this = _PureComponent.call(this, props) || this;
1072
- _this._instanceProps = initInstanceProps(_this.props, _assertThisInitialized(_assertThisInitialized(_this)));
1056
+ _this._instanceProps = initInstanceProps(_this.props, _assertThisInitialized(_this));
1073
1057
  _this._outerRef = void 0;
1074
1058
  _this._resetIsScrollingTimeoutId = null;
1075
1059
  _this.state = {
1076
- instance: _assertThisInitialized(_assertThisInitialized(_this)),
1060
+ instance: _assertThisInitialized(_this),
1077
1061
  isScrolling: false,
1078
1062
  scrollDirection: 'forward',
1079
1063
  scrollOffset: typeof _this.props.initialScrollOffset === 'number' ? _this.props.initialScrollOffset : 0,
@@ -1267,17 +1251,34 @@ function createListComponent(_ref) {
1267
1251
  align = 'auto';
1268
1252
  }
1269
1253
 
1270
- var itemCount = this.props.itemCount;
1254
+ var _this$props2 = this.props,
1255
+ itemCount = _this$props2.itemCount,
1256
+ layout = _this$props2.layout;
1271
1257
  var scrollOffset = this.state.scrollOffset;
1272
- index = Math.max(0, Math.min(index, itemCount - 1));
1273
- this.scrollTo(getOffsetForIndexAndAlignment(this.props, index, align, scrollOffset, this._instanceProps));
1258
+ index = Math.max(0, Math.min(index, itemCount - 1)); // The scrollbar size should be considered when scrolling an item into view, to ensure it's fully visible.
1259
+ // But we only need to account for its size when it's actually visible.
1260
+ // This is an edge case for lists; normally they only scroll in the dominant direction.
1261
+
1262
+ var scrollbarSize = 0;
1263
+
1264
+ if (this._outerRef) {
1265
+ var outerRef = this._outerRef;
1266
+
1267
+ if (layout === 'vertical') {
1268
+ scrollbarSize = outerRef.scrollWidth > outerRef.clientWidth ? getScrollbarSize() : 0;
1269
+ } else {
1270
+ scrollbarSize = outerRef.scrollHeight > outerRef.clientHeight ? getScrollbarSize() : 0;
1271
+ }
1272
+ }
1273
+
1274
+ this.scrollTo(getOffsetForIndexAndAlignment(this.props, index, align, scrollOffset, this._instanceProps, scrollbarSize));
1274
1275
  };
1275
1276
 
1276
1277
  _proto.componentDidMount = function componentDidMount() {
1277
- var _this$props2 = this.props,
1278
- direction = _this$props2.direction,
1279
- initialScrollOffset = _this$props2.initialScrollOffset,
1280
- layout = _this$props2.layout;
1278
+ var _this$props3 = this.props,
1279
+ direction = _this$props3.direction,
1280
+ initialScrollOffset = _this$props3.initialScrollOffset,
1281
+ layout = _this$props3.layout;
1281
1282
 
1282
1283
  if (typeof initialScrollOffset === 'number' && this._outerRef != null) {
1283
1284
  var outerRef = this._outerRef; // TODO Deprecate direction "horizontal"
@@ -1293,9 +1294,9 @@ function createListComponent(_ref) {
1293
1294
  };
1294
1295
 
1295
1296
  _proto.componentDidUpdate = function componentDidUpdate() {
1296
- var _this$props3 = this.props,
1297
- direction = _this$props3.direction,
1298
- layout = _this$props3.layout;
1297
+ var _this$props4 = this.props,
1298
+ direction = _this$props4.direction,
1299
+ layout = _this$props4.layout;
1299
1300
  var _this$state = this.state,
1300
1301
  scrollOffset = _this$state.scrollOffset,
1301
1302
  scrollUpdateWasRequested = _this$state.scrollUpdateWasRequested;
@@ -1341,24 +1342,24 @@ function createListComponent(_ref) {
1341
1342
  };
1342
1343
 
1343
1344
  _proto.render = function render() {
1344
- var _this$props4 = this.props,
1345
- children = _this$props4.children,
1346
- className = _this$props4.className,
1347
- direction = _this$props4.direction,
1348
- height = _this$props4.height,
1349
- innerRef = _this$props4.innerRef,
1350
- innerElementType = _this$props4.innerElementType,
1351
- innerTagName = _this$props4.innerTagName,
1352
- itemCount = _this$props4.itemCount,
1353
- itemData = _this$props4.itemData,
1354
- _this$props4$itemKey = _this$props4.itemKey,
1355
- itemKey = _this$props4$itemKey === void 0 ? defaultItemKey$1 : _this$props4$itemKey,
1356
- layout = _this$props4.layout,
1357
- outerElementType = _this$props4.outerElementType,
1358
- outerTagName = _this$props4.outerTagName,
1359
- style = _this$props4.style,
1360
- useIsScrolling = _this$props4.useIsScrolling,
1361
- width = _this$props4.width;
1345
+ var _this$props5 = this.props,
1346
+ children = _this$props5.children,
1347
+ className = _this$props5.className,
1348
+ direction = _this$props5.direction,
1349
+ height = _this$props5.height,
1350
+ innerRef = _this$props5.innerRef,
1351
+ innerElementType = _this$props5.innerElementType,
1352
+ innerTagName = _this$props5.innerTagName,
1353
+ itemCount = _this$props5.itemCount,
1354
+ itemData = _this$props5.itemData,
1355
+ _this$props5$itemKey = _this$props5.itemKey,
1356
+ itemKey = _this$props5$itemKey === void 0 ? defaultItemKey$1 : _this$props5$itemKey,
1357
+ layout = _this$props5.layout,
1358
+ outerElementType = _this$props5.outerElementType,
1359
+ outerTagName = _this$props5.outerTagName,
1360
+ style = _this$props5.style,
1361
+ useIsScrolling = _this$props5.useIsScrolling,
1362
+ width = _this$props5.width;
1362
1363
  var isScrolling = this.state.isScrolling; // TODO Deprecate direction "horizontal"
1363
1364
 
1364
1365
  var isHorizontal = direction === 'horizontal' || layout === 'horizontal';
@@ -1432,16 +1433,16 @@ function createListComponent(_ref) {
1432
1433
 
1433
1434
  this._callOnScroll(_scrollDirection, _scrollOffset, _scrollUpdateWasRequested);
1434
1435
  }
1435
- }; // Lazily create and cache item styles while scrolling,
1436
+ } // Lazily create and cache item styles while scrolling,
1436
1437
  // So that pure component sCU will prevent re-renders.
1437
1438
  // We maintain this cache, and pass a style prop rather than index,
1438
1439
  // So that List can clear cached styles and force item re-render if necessary.
1439
-
1440
+ ;
1440
1441
 
1441
1442
  _proto._getRangeToRender = function _getRangeToRender() {
1442
- var _this$props5 = this.props,
1443
- itemCount = _this$props5.itemCount,
1444
- overscanCount = _this$props5.overscanCount;
1443
+ var _this$props6 = this.props,
1444
+ itemCount = _this$props6.itemCount,
1445
+ overscanCount = _this$props6.overscanCount;
1445
1446
  var _this$state3 = this.state,
1446
1447
  isScrolling = _this$state3.isScrolling,
1447
1448
  scrollDirection = _this$state3.scrollDirection,
@@ -1467,7 +1468,7 @@ function createListComponent(_ref) {
1467
1468
  layout: 'vertical',
1468
1469
  overscanCount: 2,
1469
1470
  useIsScrolling: false
1470
- }, _temp;
1471
+ }, _class;
1471
1472
  } // NOTE: I considered further wrapping individual items with a pure ListItem component.
1472
1473
  // This would avoid ever calling the render function for the same index more than once,
1473
1474
  // But it would also add the overhead of a lot of components/fibers.
@@ -1638,9 +1639,7 @@ var getEstimatedTotalSize = function getEstimatedTotalSize(_ref2, _ref3) {
1638
1639
  return totalSizeOfMeasuredItems + totalSizeOfUnmeasuredItems;
1639
1640
  };
1640
1641
 
1641
- var VariableSizeList =
1642
- /*#__PURE__*/
1643
- createListComponent({
1642
+ var VariableSizeList = /*#__PURE__*/createListComponent({
1644
1643
  getItemOffset: function getItemOffset(props, index, instanceProps) {
1645
1644
  return getItemMetadata$1(props, index, instanceProps).offset;
1646
1645
  },
@@ -1648,7 +1647,7 @@ createListComponent({
1648
1647
  return instanceProps.itemMetadataMap[index].size;
1649
1648
  },
1650
1649
  getEstimatedTotalSize: getEstimatedTotalSize,
1651
- getOffsetForIndexAndAlignment: function getOffsetForIndexAndAlignment(props, index, align, scrollOffset, instanceProps) {
1650
+ getOffsetForIndexAndAlignment: function getOffsetForIndexAndAlignment(props, index, align, scrollOffset, instanceProps, scrollbarSize) {
1652
1651
  var direction = props.direction,
1653
1652
  height = props.height,
1654
1653
  layout = props.layout,
@@ -1661,7 +1660,7 @@ createListComponent({
1661
1660
 
1662
1661
  var estimatedTotalSize = getEstimatedTotalSize(props, instanceProps);
1663
1662
  var maxOffset = Math.max(0, Math.min(estimatedTotalSize - size, itemMetadata.offset));
1664
- var minOffset = Math.max(0, itemMetadata.offset - size + itemMetadata.size);
1663
+ var minOffset = Math.max(0, itemMetadata.offset - size + itemMetadata.size + scrollbarSize);
1665
1664
 
1666
1665
  if (align === 'smart') {
1667
1666
  if (scrollOffset >= minOffset - size && scrollOffset <= maxOffset + size) {
@@ -1757,9 +1756,7 @@ createListComponent({
1757
1756
  }
1758
1757
  });
1759
1758
 
1760
- var FixedSizeGrid =
1761
- /*#__PURE__*/
1762
- createGridComponent({
1759
+ var FixedSizeGrid = /*#__PURE__*/createGridComponent({
1763
1760
  getColumnOffset: function getColumnOffset(_ref, index) {
1764
1761
  var columnWidth = _ref.columnWidth;
1765
1762
  return index * columnWidth;
@@ -1937,9 +1934,7 @@ createGridComponent({
1937
1934
  }
1938
1935
  });
1939
1936
 
1940
- var FixedSizeList =
1941
- /*#__PURE__*/
1942
- createListComponent({
1937
+ var FixedSizeList = /*#__PURE__*/createListComponent({
1943
1938
  getItemOffset: function getItemOffset(_ref, index) {
1944
1939
  var itemSize = _ref.itemSize;
1945
1940
  return index * itemSize;
@@ -1953,7 +1948,7 @@ createListComponent({
1953
1948
  itemSize = _ref3.itemSize;
1954
1949
  return itemSize * itemCount;
1955
1950
  },
1956
- getOffsetForIndexAndAlignment: function getOffsetForIndexAndAlignment(_ref4, index, align, scrollOffset) {
1951
+ getOffsetForIndexAndAlignment: function getOffsetForIndexAndAlignment(_ref4, index, align, scrollOffset, instanceProps, scrollbarSize) {
1957
1952
  var direction = _ref4.direction,
1958
1953
  height = _ref4.height,
1959
1954
  itemCount = _ref4.itemCount,
@@ -1965,7 +1960,7 @@ createListComponent({
1965
1960
  var size = isHorizontal ? width : height;
1966
1961
  var lastItemOffset = Math.max(0, itemCount * itemSize - size);
1967
1962
  var maxOffset = Math.min(lastItemOffset, index * itemSize);
1968
- var minOffset = Math.max(0, index * itemSize - size + itemSize);
1963
+ var minOffset = Math.max(0, index * itemSize - size + itemSize + scrollbarSize);
1969
1964
 
1970
1965
  if (align === 'smart') {
1971
1966
  if (scrollOffset >= minOffset - size && scrollOffset <= maxOffset + size) {
@@ -2061,15 +2056,17 @@ function shallowDiffers(prev, next) {
2061
2056
  return false;
2062
2057
  }
2063
2058
 
2059
+ var _excluded = ["style"],
2060
+ _excluded2 = ["style"];
2064
2061
  // It knows to compare individual style props and ignore the wrapper object.
2065
2062
  // See https://reactjs.org/docs/react-api.html#reactmemo
2066
2063
 
2067
2064
  function areEqual(prevProps, nextProps) {
2068
2065
  var prevStyle = prevProps.style,
2069
- prevRest = _objectWithoutPropertiesLoose(prevProps, ["style"]);
2066
+ prevRest = _objectWithoutPropertiesLoose(prevProps, _excluded);
2070
2067
 
2071
2068
  var nextStyle = nextProps.style,
2072
- nextRest = _objectWithoutPropertiesLoose(nextProps, ["style"]);
2069
+ nextRest = _objectWithoutPropertiesLoose(nextProps, _excluded2);
2073
2070
 
2074
2071
  return !shallowDiffers(prevStyle, nextStyle) && !shallowDiffers(prevRest, nextRest);
2075
2072
  }
@@ -2081,10 +2078,10 @@ function shouldComponentUpdate(nextProps, nextState) {
2081
2078
  return !areEqual(this.props, nextProps) || shallowDiffers(this.state, nextState);
2082
2079
  }
2083
2080
 
2084
- exports.VariableSizeGrid = VariableSizeGrid;
2085
- exports.VariableSizeList = VariableSizeList;
2086
2081
  exports.FixedSizeGrid = FixedSizeGrid;
2087
2082
  exports.FixedSizeList = FixedSizeList;
2083
+ exports.VariableSizeGrid = VariableSizeGrid;
2084
+ exports.VariableSizeList = VariableSizeList;
2088
2085
  exports.areEqual = areEqual;
2089
2086
  exports.shouldComponentUpdate = shouldComponentUpdate;
2090
2087
  //# sourceMappingURL=index.cjs.js.map