UNPKG

react-measured-grid

Version:

A smoother scrolling virtualized React grid with dynamically measured rows and columns.

1,431 lines (1,200 loc) 180 kB
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function (obj) { return typeof obj; }; } else { _typeof = function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function isFiniteNumber(value) { return typeof value === 'number' && isFinite(value); } function isBetween(value, low) { var high = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Infinity; return typeof value === 'number' && value >= low && value <= high; } function isFiniteNumberBetween(value, low) { var high = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Infinity; return typeof value === 'number' && isFinite(value) && value >= low && value <= high; } function show(value) { var maxDepth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; var result = maxDepth <= 0 ? '' : qdmShow(value, 0, maxDepth); return result; } function qdmShow(value, depth, maxDepth) { var result = ''; if (typeof value == 'string') { return '"' + value + '"'; } if (typeof value == 'number') { return '' + value; } if (typeof value == 'boolean') { return value ? 'true' : 'false'; } if (typeof value == 'undefined') { return '<undefined>'; } if (value === null) { return '<null>'; } if (typeof value == 'function') { return '<function>'; } if (Array.isArray(value)) { if (maxDepth && depth === maxDepth) { return '<object>'; } var items = []; var value2 = value; var prevIndex = -1; for (var index in value2) { index = Number(index); var increment = index - prevIndex; if (increment > 1) { items.push('<skip ' + (increment - 1) + '>'); } items.push(qdmShow(value2[index], depth + 1, maxDepth)); prevIndex = index; } var _result = '[' + items.join(', ') + ']'; return _result; } if (_typeof(value) == 'object') { if (maxDepth && depth === maxDepth) { return '<object>'; } var _result2 = '{'; var _items = []; for (var key in value) { var item = qdmShow(key, depth + 1, maxDepth) + ': ' + qdmShow(value[key], depth + 1, maxDepth); _items.push(item); } _result2 = '{' + _items.join(', ') + '}'; return _result2; } result = '<unknown ' + _typeof(value) + '>'; return result; } var _Node = /*#__PURE__*/function () { function _Node(unmeasuredCount, maxChildren) { _classCallCheck(this, _Node); _defineProperty(this, "measuredSize", 0); _defineProperty(this, "unmeasuredCount", 0); _defineProperty(this, "lastAccumulatedIndex", 0); _defineProperty(this, "sumMeasuredSize", void 0); _defineProperty(this, "sumUnmeasuredCount", void 0); _defineProperty(this, "children", void 0); this.unmeasuredCount = unmeasuredCount; this.sumMeasuredSize = Array(maxChildren).fill(0); this.sumUnmeasuredCount = Array(maxChildren).fill(0); this.children = Array(maxChildren).fill(null); } _createClass(_Node, [{ key: "getTotalSize", value: function getTotalSize(unmeasuredSize) { var totalSize = this.measuredSize + this.unmeasuredCount * unmeasuredSize; return totalSize; } }, { key: "updateBranchSums", value: function updateBranchSums(sizeDelta, branchIndex) { if (branchIndex < 0 || branchIndex >= this.children.length || this.lastAccumulatedIndex < branchIndex || sizeDelta.measuredSize === 0 && sizeDelta.unmeasuredCount === 0) { return; } this.sumMeasuredSize[branchIndex] += sizeDelta.measuredSize; this.sumUnmeasuredCount[branchIndex] += sizeDelta.unmeasuredCount; this.lastAccumulatedIndex = branchIndex; } }]); return _Node; }(); // Default values var DEFAULT_LOW_SIZE = 12; var DEFAULT_UNMEASURED_SIZE = 18; var DEFAULT_MAX_BRANCHES = 32; var DEFAULT_MAX_LEAF_ITEMS = 32; //Limits var MIN_LOW_SIZE = 5; var MIN_UNMEASURED_SIZE = 5; var MAX_MAX_BRANCHES = 1024; var MIN_MAX_BRANCHES = 2; var MAX_MAX_LEAF_ITEMS = 1024; var MIN_MAX_LEAF_ITEMS = 2; var MAX_ITEM_COUNT = 134217727; // = (2 ** 27) - 1; about 134 million; var MAX_SIZE = 16777215; // = (2 ** 24) - 1; about 16 million; var PositionTracker = /*#__PURE__*/function () { function PositionTracker() { var itemCount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; var unmeasuredSize = arguments.length > 1 ? arguments[1] : undefined; var lowSize = arguments.length > 2 ? arguments[2] : undefined; var maxBranches = arguments.length > 3 ? arguments[3] : undefined; var maxLeafItems = arguments.length > 4 ? arguments[4] : undefined; _classCallCheck(this, PositionTracker); _defineProperty(this, "_rootNode", void 0); _defineProperty(this, "_itemCount", void 0); _defineProperty(this, "_maxIndex", void 0); _defineProperty(this, "_lowSize", void 0); _defineProperty(this, "_unmeasuredSize", void 0); _defineProperty(this, "_maxBranches", void 0); _defineProperty(this, "_maxLeafItems", void 0); _defineProperty(this, "_branchCapacities", void 0); _defineProperty(this, "_rootLevel", void 0); //super(); if (isFiniteNumberBetween(itemCount, 0, MAX_ITEM_COUNT)) { this._itemCount = Math.trunc(itemCount); } else { this._itemCount = 0; } this._maxIndex = this._itemCount ? this._itemCount - 1 : 0; this.setUnmeasuredSize(unmeasuredSize); this.setLowSize(lowSize); if (isFiniteNumberBetween(maxBranches, MIN_MAX_BRANCHES, MAX_MAX_BRANCHES)) { this._maxBranches = Math.trunc(maxBranches); } else { this._maxBranches = DEFAULT_MAX_BRANCHES; } if (isFiniteNumberBetween(maxLeafItems, MIN_MAX_LEAF_ITEMS, MAX_MAX_LEAF_ITEMS)) { this._maxLeafItems = Math.trunc(maxLeafItems); } else { this._maxLeafItems = DEFAULT_MAX_LEAF_ITEMS; } this.clearAllItems(); } _createClass(PositionTracker, [{ key: "clearAllItems", value: function clearAllItems() { this._rootNode = new _Node(this._itemCount, this._maxBranches); var capacitiesResult = this._calculateBranchCapacities(this._itemCount, this._maxBranches, this._maxLeafItems); this._branchCapacities = capacitiesResult[0]; this._rootLevel = capacitiesResult[1]; } }, { key: "clearItemSize", value: function clearItemSize(index) { var sizeDelta; if (isFiniteNumberBetween(index, 0, this._itemCount - 1) && Math.trunc(index) === index) { sizeDelta = this._setItemSize(this._rootNode, index, this._rootLevel, null, this._itemCount); } else { sizeDelta = { oldSize: 0, size: null, measuredSize: 0, unmeasuredCount: 0 }; } return sizeDelta.oldSize; } }, { key: "getContainingIndex", value: function getContainingIndex(offset) { var index = 0; if (isFiniteNumber(offset) && this._itemCount > 0) { var totalSize = this.getTotalSize(); if (isBetween(offset, 0, totalSize)) { index = this._getContainingIndex(this._rootNode, offset, this._itemCount - 1, this._rootLevel); } else if (offset > totalSize) { index = this._maxIndex; } } index = Math.max(0, Math.min(this._maxIndex, index)); return index; } }, { key: "getItemCount", value: function getItemCount() { return this._itemCount; } }, { key: "getItemLowSize", value: function getItemLowSize(index) { var size = this.getItemMeasuredSize(index); if (size === null) { if (typeof this._lowSize === 'number') { size = this._lowSize; } else { size = this._lowSize(index); } } return size; } }, { key: "getItemMeasuredSize", value: function getItemMeasuredSize(index) { var measuredSize = 0; if (isFiniteNumberBetween(index, 0, this._itemCount - 1) && Math.trunc(index) === index) { measuredSize = this._getItemMeasuredSize(this._rootNode, index, this._rootLevel); } return measuredSize; } }, { key: "getItemSize", value: function getItemSize(index) { var size = this.getItemMeasuredSize(index); if (size === null) { size = this.getUnmeasuredSize(); } return size; } }, { key: "getItemStats", value: function getItemStats(index) { var itemStats; if (isFiniteNumber(index)) { index = Math.trunc(index); if (isBetween(index, 0, this._itemCount - 1)) { itemStats = this._getItemStats(this._rootNode, index, this._rootLevel); itemStats.end = itemStats.start + itemStats.size; } else if (index < 0) { itemStats = { start: 0, size: 0, end: 0, isMeasured: true }; } else { var totalSize = this.getTotalSize(); itemStats = { start: totalSize, size: 0, end: totalSize, isMeasured: true }; } } else { itemStats = { start: 0, size: 0, end: 0, isMeasured: true }; } return itemStats; } }, { key: "getLowSize", value: function getLowSize() { return this._lowSize; } }, { key: "getMaxBranches", value: function getMaxBranches() { return this._maxBranches; } }, { key: "getMaxLeafItems", value: function getMaxLeafItems() { return this._maxLeafItems; } }, { key: "getTotalSize", value: function getTotalSize() { var result = this._rootNode.getTotalSize(this.getUnmeasuredSize()); return result; } }, { key: "getUnmeasuredSize", value: function getUnmeasuredSize() { var result = this._unmeasuredSize; return result; } }, { key: "setItemCount", value: function setItemCount(itemCount) { itemCount = Math.trunc(itemCount); if (!isFiniteNumberBetween(itemCount, 0, MAX_ITEM_COUNT) || itemCount === this._itemCount) { return; } if (itemCount === 0) { this._itemCount = 0; this._maxIndex = 0; this.clearAllItems(); return; } var _this$_calculateBranc = this._calculateBranchCapacities(itemCount, this._maxBranches, this._maxLeafItems), _this$_calculateBranc2 = _slicedToArray(_this$_calculateBranc, 2), newBranchCapacities = _this$_calculateBranc2[0], newRootLevel = _this$_calculateBranc2[1]; if (itemCount < this._itemCount) { this._reduceNodes(this._rootNode, itemCount - 1, this._itemCount - 1, this._rootLevel); this._releaseUnusedLevels(itemCount, newRootLevel); } else { this._expandNodes(this._rootNode, itemCount - 1, this._itemCount - 1, this._rootLevel); this._addNewLevels(itemCount, newRootLevel, newBranchCapacities); } this._itemCount = itemCount; this._maxIndex = this._itemCount - 1; this._branchCapacities = newBranchCapacities; this._rootLevel = newRootLevel; } }, { key: "setItemSize", value: function setItemSize(index, size) { var sizeDelta; if (isFiniteNumberBetween(index, 0, this._itemCount - 1) && Math.trunc(index) === index && (isFiniteNumberBetween(size, 0, MAX_SIZE) || size === null)) { sizeDelta = this._setItemSize(this._rootNode, index, this._rootLevel, size, this._itemCount); } else { sizeDelta = { oldSize: 0, size: size, measuredSize: 0, unmeasuredCount: 0 }; } return sizeDelta.oldSize; } }, { key: "setLowSize", value: function setLowSize(lowSize) { if (isFiniteNumberBetween(lowSize, MIN_LOW_SIZE, this._unmeasuredSize) || typeof lowSize === 'function') { this._lowSize = lowSize; } else { this._lowSize = DEFAULT_LOW_SIZE; } } }, { key: "setUnmeasuredSize", value: function setUnmeasuredSize(unmeasuredSize) { if (isFiniteNumberBetween(unmeasuredSize, MIN_UNMEASURED_SIZE, MAX_SIZE)) { this._unmeasuredSize = unmeasuredSize; } else { this._unmeasuredSize = DEFAULT_UNMEASURED_SIZE; } } // Start of private methods }, { key: "_addNewLevels", value: function _addNewLevels(newItemCount, newRootLevel, branchCapacities) { var lowerNode = this._rootNode; for (var lix = this._rootLevel; lix < newRootLevel; lix++) { var nbrMeasuredInLower = branchCapacities[lix + 1] - lowerNode.unmeasuredCount; var newUnmeasuredCount = Math.min(newItemCount, branchCapacities[lix + 2]) - nbrMeasuredInLower; this._rootNode = new _Node(newUnmeasuredCount, this._maxBranches); this._rootNode.measuredSize = lowerNode.measuredSize; this._rootNode.children[0] = lowerNode; lowerNode = this._rootNode; } } }, { key: "_calculateBranchCapacities", value: function _calculateBranchCapacities(itemCount, maxBranches, maxLeafItems) { var branchCapacities = []; branchCapacities[0] = 1; branchCapacities[1] = maxLeafItems; branchCapacities[2] = maxLeafItems * maxBranches; var level = 2; var capacity = branchCapacities[2]; while (capacity < itemCount) { capacity *= maxBranches; branchCapacities[++level] = capacity; } return [branchCapacities, level - 1]; } }, { key: "_expandNodes", value: function _expandNodes(node, newIndex, oldIndex, level) { var nodeCapacity = this._branchCapacities[level + 1]; if (newIndex >= nodeCapacity) { newIndex = nodeCapacity - 1; } var branchCapacity = this._branchCapacities[level]; var oldBranchIndex = Math.trunc(oldIndex / branchCapacity); var oldNextIndex = oldIndex - oldBranchIndex * branchCapacity; var newBranchIndex = Math.trunc(newIndex / branchCapacity); var newNextIndex = newIndex - newBranchIndex * branchCapacity; var sizeDelta = { measuredSize: 0, unmeasuredCount: 0, size: null, oldSize: null }; var branchesPerNode = level === 0 ? this._maxLeafItems : this._maxBranches; if (newBranchIndex >= branchesPerNode) { newBranchIndex = branchesPerNode - 1; newNextIndex = branchCapacity - 1; } var unmeasuredCountDelta = newNextIndex - oldNextIndex + (newBranchIndex - oldBranchIndex) * branchCapacity; var newExtendedNextIndex = unmeasuredCountDelta + oldNextIndex; sizeDelta.unmeasuredCount += unmeasuredCountDelta; node.unmeasuredCount += sizeDelta.unmeasuredCount; if (level > 0) { var nextNode = node.children[oldBranchIndex]; if (nextNode instanceof _Node) { var subtreeDelta = this._expandNodes(nextNode, newExtendedNextIndex, oldNextIndex, level - 1); } } return sizeDelta; } }, { key: "_getBranchSize", value: function _getBranchSize(branchStats) { var size = branchStats.measuredSize + branchStats.unmeasuredCount * this._unmeasuredSize; return size; } }, { key: "_getBranchStats", value: function _getBranchStats(branch, branchCapacity, nextIndex) { var stats = { measuredSize: 0, unmeasuredCount: 0 }; if (branch === null) { stats.unmeasuredCount = Math.min(nextIndex, branchCapacity); } else if (typeof branch === 'number') { stats.measuredSize = branch; } else { stats.measuredSize = branch.measuredSize; stats.unmeasuredCount = branch.unmeasuredCount; } return stats; } }, { key: "_getContainingIndex", value: function _getContainingIndex(node, offset, maxRemainderIndex, level) { var containingBranchIndex = 0; var containingBranchStart = 0; var branchCapacity = this._branchCapacities[level]; var highIndex = node.lastAccumulatedIndex; var highStart = (node.sumMeasuredSize[highIndex] || 0) + (node.sumUnmeasuredCount[highIndex] || 0) * this._unmeasuredSize; var lowIndex = 0; var lowStart = 0; if (offset < highStart) { while (lowIndex + 1 < highIndex) { var middleIndex = Math.trunc((lowIndex + highIndex) / 2); var middleStart = (node.sumMeasuredSize[middleIndex] || 0) + (node.sumUnmeasuredCount[middleIndex] || 0) * this._unmeasuredSize; if (offset < middleStart) { highIndex = middleIndex; highStart = middleStart; } else { lowIndex = middleIndex; lowStart = middleStart; } } containingBranchIndex = lowIndex; containingBranchStart = lowStart; } else { var branchIndex = highIndex; var branchStart = highStart; var sumMeasuredSize = node.sumMeasuredSize[branchIndex]; var sumUnmeasuredCount = node.sumUnmeasuredCount[branchIndex]; var nextMaxRemainderIndex = maxRemainderIndex - branchIndex * branchCapacity; while (offset >= branchStart && nextMaxRemainderIndex >= 0) { var branchStats = this._getBranchStats(node.children[branchIndex], branchCapacity, nextMaxRemainderIndex); var branchSize = this._getBranchSize(branchStats); var branchEnd = branchStart + branchSize; if (branchIndex > node.lastAccumulatedIndex) { node.sumMeasuredSize[branchIndex] = sumMeasuredSize; node.sumUnmeasuredCount[branchIndex] = sumUnmeasuredCount; node.lastAccumulatedIndex = branchIndex; } sumMeasuredSize += branchStats.measuredSize; sumUnmeasuredCount += branchStats.unmeasuredCount; if (offset < branchEnd || nextMaxRemainderIndex < branchCapacity || branchIndex + 1 === node.children.length) { break; } branchIndex++; branchStart = branchEnd; nextMaxRemainderIndex -= branchCapacity; } containingBranchIndex = branchIndex; containingBranchStart = branchStart; } var resultIndex = containingBranchIndex * branchCapacity; var branchTreeIndex; if (level === 0) { branchTreeIndex = 0; } else { var nextNode = node.children[containingBranchIndex]; if (nextNode instanceof _Node) { var _nextMaxRemainderIndex = maxRemainderIndex - resultIndex; branchTreeIndex = this._getContainingIndex(nextNode, offset - containingBranchStart, _nextMaxRemainderIndex, level - 1); } else { branchTreeIndex = Math.trunc((offset - containingBranchStart) / this._unmeasuredSize); } } resultIndex += branchTreeIndex; return resultIndex; } }, { key: "_getItemMeasuredSize", value: function _getItemMeasuredSize(node, index, level) { var measuredSize; if (level === 0) { var notANode = node.children[index]; measuredSize = notANode instanceof _Node ? null : notANode; } else { var branchCapacity = this._branchCapacities[level]; var branchIndex = Math.trunc(index / branchCapacity); var priorCapacity = branchIndex * branchCapacity; var nextIndex = index - priorCapacity; var nextNode = node.children[branchIndex]; if (typeof nextNode === 'number' || nextNode === null) { measuredSize = null; } else { measuredSize = this._getItemMeasuredSize(nextNode, nextIndex, level - 1); } } return measuredSize; } }, { key: "_getItemStats", value: function _getItemStats(node, index, level) { var itemStats; var unmeasuredSize = this._unmeasuredSize; var lastIndex = node.lastAccumulatedIndex; if (level === 0) { if (index > lastIndex) { var sumMeasuredSize = node.sumMeasuredSize[lastIndex] || 0; var sumUnmeasuredCount = node.sumUnmeasuredCount[lastIndex] || 0; for (var bix = lastIndex; bix <= index; bix++) { if (bix > node.lastAccumulatedIndex) { node.sumMeasuredSize[bix] = sumMeasuredSize; node.sumUnmeasuredCount[bix] = sumUnmeasuredCount; node.lastAccumulatedIndex = bix; } var measuredSize = node.children[bix]; if (measuredSize === null) { sumUnmeasuredCount++; } else if (typeof measuredSize === 'number') { sumMeasuredSize += measuredSize; } } } var start = (node.sumMeasuredSize[index] || 0) + (node.sumUnmeasuredCount[index] || 0) * unmeasuredSize; var rawSize = node.children[index]; var isMeasured = isFiniteNumber(rawSize); var size = isMeasured && typeof rawSize === 'number' ? rawSize : unmeasuredSize; itemStats = { start: start, size: size, end: 0, isMeasured: isMeasured }; } else { var branchCapacity = this._branchCapacities[level]; var branchIndex = Math.trunc(index / branchCapacity); var priorCapacity = branchIndex * branchCapacity; var nextIndex = index - priorCapacity; if (branchIndex > lastIndex) { var _sumMeasuredSize = node.sumMeasuredSize[lastIndex] || 0; var _sumUnmeasuredCount = node.sumUnmeasuredCount[lastIndex] || 0; var nextIndex2 = index - lastIndex * branchCapacity; for (var _bix = lastIndex + 1; _bix <= branchIndex; _bix++) { var _nextNode = node.children[_bix - 1]; var branchStats = this._getBranchStats(_nextNode, branchCapacity, nextIndex2); _sumMeasuredSize += branchStats.measuredSize; _sumUnmeasuredCount += branchStats.unmeasuredCount; node.sumMeasuredSize[_bix] = _sumMeasuredSize; node.sumUnmeasuredCount[_bix] = _sumUnmeasuredCount; nextIndex2 -= branchCapacity; } node.lastAccumulatedIndex = branchIndex; } var nextNode = node.children[branchIndex]; var branchStart = (node.sumMeasuredSize[branchIndex] || 0) + (node.sumUnmeasuredCount[branchIndex] || 0) * unmeasuredSize; if (typeof nextNode === 'number' || nextNode === null) { var _start = unmeasuredSize * nextIndex; itemStats = { start: _start, size: unmeasuredSize, end: 0, isMeasured: false }; } else { itemStats = this._getItemStats(nextNode, nextIndex, level - 1); } itemStats.start += branchStart; } return itemStats; } }, { key: "_reduceNodes", value: function _reduceNodes(node, newIndex, oldIndex, level) { var branchCapacity = this._branchCapacities[level]; var newBranchIndex = Math.trunc(newIndex / branchCapacity); var newNextIndex = newIndex - newBranchIndex * branchCapacity; var oldBranchIndex = Math.trunc(oldIndex / branchCapacity); var oldNextIndex = oldIndex - oldBranchIndex * branchCapacity; var sizeDelta = { measuredSize: 0, unmeasuredCount: 0, size: null, oldSize: null }; if (level === 0) { for (var bix = newBranchIndex + 1; bix <= oldBranchIndex; bix++) { var measuredSize = node.children[bix]; if (typeof measuredSize === 'number') { sizeDelta.measuredSize -= measuredSize; node.children[bix] = null; } else { sizeDelta.unmeasuredCount--; } } } else { for (var _bix2 = newBranchIndex + 1; _bix2 <= oldBranchIndex; _bix2++) { var branchNode = node.children[_bix2]; if (branchNode instanceof _Node) { sizeDelta.measuredSize -= branchNode.measuredSize; sizeDelta.unmeasuredCount -= branchNode.unmeasuredCount; node.children[_bix2] = null; } else { var unmeasuredCount = _bix2 === oldBranchIndex ? oldNextIndex + 1 : branchCapacity; sizeDelta.unmeasuredCount -= unmeasuredCount; } } var nodeOldNextIndex = newBranchIndex === oldBranchIndex ? oldNextIndex : branchCapacity - 1; var nextNode = node.children[newBranchIndex]; if (nextNode instanceof _Node) { var subtreeDelta = this._reduceNodes(nextNode, newNextIndex, nodeOldNextIndex, level - 1); //node.sumMeasuredSize[newBranchIndex] += subtreeDelta.measuredSize; //node.sumUnmeasuredCount[newBranchIndex] += subtreeDelta.unmeasuredCount; sizeDelta.measuredSize += subtreeDelta.measuredSize; sizeDelta.unmeasuredCount += subtreeDelta.unmeasuredCount; } else { var unmeasuredCountDelta = nodeOldNextIndex - newNextIndex; sizeDelta.unmeasuredCount -= unmeasuredCountDelta; } } node.measuredSize += sizeDelta.measuredSize; node.unmeasuredCount += sizeDelta.unmeasuredCount; if (newBranchIndex < node.lastAccumulatedIndex) { node.lastAccumulatedIndex = newBranchIndex; } return sizeDelta; } }, { key: "_releaseUnusedLevels", value: function _releaseUnusedLevels(newItemCount, newRootLevel) { for (var lix = this._rootLevel; lix > newRootLevel; lix--) { if (!(this._rootNode instanceof _Node)) { this._rootNode = this._rootNode.children[0]; } else { this._rootNode = new _Node(newItemCount, this._maxBranches); break; } } } }, { key: "_setItemSize", value: function _setItemSize(node, index, level, size, capacityCap) { var sizeDelta; if (level === 0) { var child = node.children[index]; var oldSize = child instanceof _Node ? null : child; node.children[index] = size; sizeDelta = { size: size, oldSize: oldSize, measuredSize: 0, unmeasuredCount: 0 }; if (isFiniteNumber(oldSize) && typeof oldSize === 'number') { sizeDelta.measuredSize -= oldSize; } else { sizeDelta.unmeasuredCount--; sizeDelta.oldSize = null; } if (isFiniteNumber(size) && typeof size === 'number') { sizeDelta.measuredSize += size; } else { sizeDelta.unmeasuredCount++; } if (oldSize !== size && node.lastAccumulatedIndex >= index) { node.lastAccumulatedIndex = index - Number(index > 0); } } else { var branchCapacity = this._branchCapacities[level]; var branchIndex = Math.trunc(index / branchCapacity); var priorCapacity = branchIndex * branchCapacity; var nextIndex = index - priorCapacity; var nextCapacityCap = capacityCap - priorCapacity; var nextNode = node.children[branchIndex]; if (!(nextNode instanceof _Node) && size === null) { sizeDelta = { size: size, oldSize: null, measuredSize: 0, unmeasuredCount: 0 }; } else { if (!(nextNode instanceof _Node)) { if (level === 1) { nextNode = new _Node(Math.min(this._branchCapacities[level], nextCapacityCap), this._maxLeafItems); } else { nextNode = new _Node(Math.min(this._branchCapacities[level], nextCapacityCap), this._maxBranches); } node.children[branchIndex] = nextNode; } sizeDelta = this._setItemSize(nextNode, nextIndex, level - 1, size, nextCapacityCap); } if ((sizeDelta.measuredSize !== 0 || sizeDelta.unmeasuredCount !== 0) && node.lastAccumulatedIndex >= branchIndex) { node.lastAccumulatedIndex = branchIndex - Number(branchIndex > 0); } } node.measuredSize += sizeDelta.measuredSize; node.unmeasuredCount += sizeDelta.unmeasuredCount; return sizeDelta; } }]); return PositionTracker; }(); var ScrollPosition = /*#__PURE__*/function () { function ScrollPosition() { var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; var alignment = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'start'; var offset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; _classCallCheck(this, ScrollPosition); _defineProperty(this, "_index", void 0); _defineProperty(this, "_alignment", void 0); _defineProperty(this, "_offset", void 0); if (index < 0) { index = 0; } this._index = index; if (['start', 'center', 'end'].indexOf(alignment) === -1) { alignment = 'start'; } this._alignment = alignment; this._offset = offset; } _createClass(ScrollPosition, [{ key: "copy", value: function copy() { var result = new ScrollPosition(this._index, this._alignment, this._offset); return result; } /** * Keeps the same item index, * but changes alignment, then adjusts offset * in order to produce an equivalent total offset */ }, { key: "changeAlignment", value: function changeAlignment(alignment, positionTracker, viewSize) { var totalOffset = this.getTotalOffset(positionTracker, viewSize); var newPosition = new ScrollPosition(this._index, alignment, this._offset); var newTotalOffset = newPosition.getTotalOffset(positionTracker, viewSize); var originalAlignment = this.getAlignment(); var viewDelta = 0; if (alignment === 'end' && originalAlignment === 'start') { viewDelta = viewSize; } else if (alignment === 'center' && originalAlignment === 'start' || alignment === 'end' && originalAlignment === 'center') { viewDelta = viewSize / 2; } else if (alignment === 'start' && originalAlignment === 'center' || alignment === 'center' && originalAlignment === 'end') { viewDelta = -viewSize / 2; } else if (alignment === 'start' && originalAlignment === 'end') { viewDelta = -viewSize; } var offsetDelta = totalOffset + viewDelta - newTotalOffset; newPosition._offset += offsetDelta; return newPosition; } }, { key: "getAlignment", value: function getAlignment() { return this._alignment; } }, { key: "getAlignedOffset", value: function getAlignedOffset() { return this._offset; } }, { key: "getIndex", value: function getIndex() { return this._index; } /** * returns the corresponding offset in the context of the arguments */ }, { key: "getTotalOffset", value: function getTotalOffset(positionTracker, viewSize) { var itemStats = positionTracker.getItemStats(this._index); var offsetDelta = 0; if (this._alignment === 'center') { offsetDelta = Math.min(itemStats.size, viewSize) / 2; } else if (this._alignment === 'end') { offsetDelta = itemStats.size; } var totalSize = positionTracker.getTotalSize(); var rawTotalOffset = itemStats.start + offsetDelta + this._offset; var totalOffset = Math.max(0, Math.min(rawTotalOffset, totalSize)); return totalOffset; } }, { key: "getViewStartOffset", value: function getViewStartOffset(positionTracker, viewSize) { var offsetDelta = 0; var totalOffset = this.getTotalOffset(positionTracker, viewSize); if (this._alignment === 'center') { offsetDelta = Math.min(0, -viewSize / 2); } else if (this._alignment === 'end') { offsetDelta = -viewSize; } var totalSize = positionTracker.getTotalSize(); var viewStartOffset = Math.max(0, Math.min(totalOffset + offsetDelta, totalSize)); return viewStartOffset; } }, { key: "incrementOffset", value: function incrementOffset(offsetDelta) { if (isNaN(offsetDelta) || !isFinite(offsetDelta)) { offsetDelta = 0; } var result = new ScrollPosition(this._index, this._alignment, this._offset + offsetDelta); return result; } }, { key: "update", value: function update() { var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; var alignment = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'start'; var offset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; this._index = index; this._alignment = alignment; this._offset = offset; } }, { key: "updateFrom", value: function updateFrom(scrollPosition) { this._index = scrollPosition.getIndex(); this._alignment = scrollPosition.getAlignment(); this._offset = scrollPosition.getAlignedOffset(); } /** * Produces a new ScrollPosition that has the same alignment, but * changes the item index and alignment offset so that the total * offset is the same and is within the item of the new index. * * If the original total offset was outside the extent of the * positionTracker, the new ScrollPosition points to the start of the * first item or the end of the last item, which ever is nearest. * * If the total offset is on the boundary of two items one of the items * is chosen so that with a preserved alignment of 'start' or 'end', * the offset is zero. If the alignment is 'middle', the sign of the offset * is preserved. */ }, { key: "withContainingIndex", value: function withContainingIndex(positionTracker, viewSize) { var newPosition; var totalOffset = this.getTotalOffset(positionTracker, viewSize); if (totalOffset < 0) { totalOffset = 0; } var totalSize = positionTracker.getTotalSize(); if (totalOffset > totalSize) { totalOffset = totalSize; } if (totalOffset === 0) { newPosition = new ScrollPosition(0, 'start', 0); } else if (totalOffset === totalSize) { newPosition = new ScrollPosition(positionTracker.getItemCount() - 1, 'end', 0); } else { var containingIndex = positionTracker.getContainingIndex(totalOffset); newPosition = new ScrollPosition(containingIndex, 'start', 0); var newTotalOffset = newPosition.getTotalOffset(positionTracker, viewSize); newPosition._alignment = this._alignment; var offsetDelta = totalOffset - newTotalOffset; if (offsetDelta === 0) { if (this._alignment === 'end' && containingIndex > 0) { newPosition._index--; newPosition._alignment = 'end'; } else if (this._alignment === 'center') { newPosition._alignment = 'center'; if (this._offset > 0 && containingIndex > 0) { newPosition._index--; } } } var revisedTotalOffset = newPosition.getTotalOffset(positionTracker, viewSize); offsetDelta = totalOffset - revisedTotalOffset; newPosition._offset = offsetDelta; } return newPosition; } }]); return ScrollPosition; }(); function createCommonjsModule(fn, module) { return module = { exports: {} }, fn(module, module.exports), module.exports; } /* object-assign (c) Sindre Sorhus @license MIT */ /* eslint-disable no-unused-vars */ var getOwnPropertySymbols = Object.getOwnPropertySymbols; var hasOwnProperty = Object.prototype.hasOwnProperty; var propIsEnumerable = Object.prototype.propertyIsEnumerable; function toObject(val) { if (val === null || val === undefined) { throw new TypeError('Object.assign cannot be called with null or undefined'); } return Object(val); } function shouldUseNative() { try { if (!Object.assign) { return false; } // Detect buggy property enumeration order in older V8 versions. // https://bugs.chromium.org/p/v8/issues/detail?id=4118 var test1 = new String('abc'); // eslint-disable-line no-new-wrappers test1[5] = 'de'; if (Object.getOwnPropertyNames(test1)[0] === '5') { return false; } // https://bugs.chromium.org/p/v8/issues/detail?id=3056 var test2 = {}; for (var i = 0; i < 10; i++) { test2['_' + String.fromCharCode(i)] = i; } var order2 = Object.getOwnPropertyNames(test2).map(function (n) { return test2[n]; }); if (order2.join('') !== '0123456789') { return false; } // https://bugs.chromium.org/p/v8/issues/detail?id=3056 var test3 = {}; 'abcdefghijklmnopqrst'.split('').forEach(function (letter) { test3[letter] = letter; }); if (Object.keys(Object.assign({}, test3)).join('') !== 'abcdefghijklmnopqrst') { return false; } return true; } catch (err) { // We don't expect any of the above to throw, but better to be safe. return false; } } var objectAssign = shouldUseNative() ? Object.assign : function (target, source) { var from; var to = toObject(target); var symbols; for (var s = 1; s < arguments.length; s++) { from = Object(arguments[s]); for (var key in from) { if (hasOwnProperty.call(from, key)) { to[key] = from[key]; } } if (getOwnPropertySymbols) { symbols = getOwnPropertySymbols(from); for (var i = 0; i < symbols.length; i++) { if (propIsEnumerable.call(from, symbols[i])) { to[symbols[i]] = from[symbols[i]]; } } } } return to; }; var n="function"===typeof Symbol&&Symbol.for,p=n?Symbol.for("react.element"):60103,q=n?Symbol.for("react.portal"):60106,r=n?Symbol.for("react.fragment"):60107,t=n?Symbol.for("react.strict_mode"):60108,u=n?Symbol.for("react.profiler"):60114,v=n?Symbol.for("react.provider"):60109,w=n?Symbol.for("react.context"):60110,x=n?Symbol.for("react.forward_ref"):60112,y=n?Symbol.for("react.suspense"):60113,z=n?Symbol.for("react.memo"):60115,A=n?Symbol.for("react.lazy"): 60116,B="function"===typeof Symbol&&Symbol.iterator;function C(a){for(var b="https://reactjs.org/docs/error-decoder.html?invariant="+a,c=1;c<arguments.length;c++)b+="&args[]="+encodeURIComponent(arguments[c]);return "Minified React error #"+a+"; visit "+b+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."} var D={isMounted:function(){return !1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},E={};function F(a,b,c){this.props=a;this.context=b;this.refs=E;this.updater=c||D;}F.prototype.isReactComponent={};F.prototype.setState=function(a,b){if("object"!==typeof a&&"function"!==typeof a&&null!=a)throw Error(C(85));this.updater.enqueueSetState(this,a,b,"setState");};F.prototype.forceUpdate=function(a){this.updater.enqueueForceUpdate(this,a,"forceUpdate");}; function G(){}G.prototype=F.prototype;function H(a,b,c){this.props=a;this.context=b;this.refs=E;this.updater=c||D;}var I=H.prototype=new G;I.constructor=H;objectAssign(I,F.prototype);I.isPureReactComponent=!0;var J={current:null},K=Object.prototype.hasOwnProperty,L={key:!0,ref:!0,__self:!0,__source:!0}; function M(a,b,c){var e,d={},g=null,k=null;if(null!=b)for(e in void 0!==b.ref&&(k=b.ref),void 0!==b.key&&(g=""+b.key),b)K.call(b,e)&&!L.hasOwnProperty(e)&&(d[e]=b[e]);var f=arguments.length-2;if(1===f)d.children=c;else if(1<f){for(var h=Array(f),m=0;m<f;m++)h[m]=arguments[m+2];d.children=h;}if(a&&a.defaultProps)for(e in f=a.defaultProps,f)void 0===d[e]&&(d[e]=f[e]);return {$$typeof:p,type:a,key:g,ref:k,props:d,_owner:J.current}} function N(a,b){return {$$typeof:p,type:a.type,key:b,ref:a.ref,props:a.props,_owner:a._owner}}function O(a){return "object"===typeof a&&null!==a&&a.$$typeof===p}function escape(a){var b={"=":"=0",":":"=2"};return "$"+(""+a).replace(/[=:]/g,function(a){return b[a]})}var P=/\/+/g,Q=[];function R(a,b,c,e){if(Q.length){var d=Q.pop();d.result=a;d.keyPrefix=b;d.func=c;d.context=e;d.count=0;return d}return {result:a,keyPrefix:b,func:c,context:e,count:0}} function S(a){a.result=null;a.keyPrefix=null;a.func=null;a.context=null;a.count=0;10>Q.length&&Q.push(a);} function T(a,b,c,e){var d=typeof a;if("undefined"===d||"boolean"===d)a=null;var g=!1;if(null===a)g=!0;else switch(d){case "string":case "number":g=!0;break;case "object":switch(a.$$typeof){case p:case q:g=!0;}}if(g)return c(e,a,""===b?"."+U(a,0):b),1;g=0;b=""===b?".":b+":";if(Array.isArray(a))for(var k=0;k<a.length;k++){d=a[k];var f=b+U(d,k);g+=T(d,f,c,e);}else if(null===a||"object"!==typeof a?f=null:(f=B&&a[B]||a["@@iterator"],f="function"===typeof f?f:null),"function"===typeof f)for(a=f.call(a),k= 0;!(d=a.next()).done;)d=d.value,f=b+U(d,k++),g+=T(d,f,c,e);else if("object"===d)throw c=""+a,Error(C(31,"[object Object]"===c?"object with keys {"+Object.keys(a).join(", ")+"}":c,""));return g}function V(a,b,c){return null==a?0:T(a,"",b,c)}function U(a,b){return "object"===typeof a&&null!==a&&null!=a.key?escape(a.key):b.toString(36)}function W(a,b){a.func.call(a.context,b,a.count++);} function aa(a,b,c){var e=a.result,d=a.keyPrefix;a=a.func.call(a.context,b,a.count++);Array.isArray(a)?X(a,e,c,function(a){return a}):null!=a&&(O(a)&&(a=N(a,d+(!a.key||b&&b.key===a.key?"":(""+a.key).replace(P,"$&/")+"/")+c)),e.push(a));}function X(a,b,c,e,d){var g="";null!=c&&(g=(""+c).replace(P,"$&/")+"/");b=R(b,g,e,d);V(a,aa,b);S(b);}var Y={current:null};function Z(){var a=Y.current;if(null===a)throw Error(C(321));return a} var ba={ReactCurrentDispatcher:Y,ReactCurrentBatchConfig:{suspense:null},ReactCurrentOwner:J,IsSomeRendererActing:{current:!1},assign:objectAssign};var Children={map:function(a,b,c){if(null==a)return a;var e=[];X(a,e,null,b,c);return e},forEach:function(a,b,c){if(null==a)return a;b=R(null,null,b,c);V(a,W,b);S(b);},count:function(a){return V(a,function(){return null},null)},toArray:function(a){var b=[];X(a,b,null,function(a){return a});return b},only:function(a){if(!O(a))throw Error(C(143));return a}}; var Component=F;var Fragment=r;var Profiler=u;var PureComponent=H;var StrictMode=t;var Suspense=y;var __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=ba; var cloneElement=function(a,b,c){if(null===a||void 0===a)throw Error(C(267,a));var e=objectAssign({},a.props),d=a.key,g=a.ref,k=a._owner;if(null!=b){void 0!==b.ref&&(g=b.ref,k=J.current);void 0!==b.key&&(d=""+b.key);if(a.type&&a.type.defaultProps)var f=a.type.defaultProps;for(h in b)K.call(b,h)&&!L.hasOwnProperty(h)&&(e[h]=void 0===b[h]&&void 0!==f?f[h]:b[h]);}var h=arguments.length-2;if(1===h)e.children=c;else if(1<h){f=Array(h);for(var m=0;m<h;m++)f[m]=arguments[m+2];e.children=f;}return {$$typeof:p,type:a.type, key:d,ref:g,props:e,_owner:k}};var createContext=function(a,b){void 0===b&&(b=null);a={$$typeof:w,_calculateChangedBits:b,_currentValue:a,_currentValue2:a,_threadCount:0,Provider:null,Consumer:null};a.Provider={$$typeof:v,_context:a};return a.Consumer=a};var createElement=M;var createFactory=function(a){var b=M.bind(null,a);b.type=a;return b};var createRef=function(){return {current:null}};var forwardRef=function(a){return {$$typeof:x,render:a}};var isValidElement=O; var lazy=function(a){return {$$typeof:A,_ctor:a,_status:-1,_result:null}};var memo=function(a,b){return {$$typeof:z,type:a,compare:void 0===b?null:b}};var useCallback=function(a,b){return Z().useCallback(a,b)};var useContext=function(a,b){return Z().useContext(a,b)};var useDebugValue=function(){};var useEffect=function(a,b){return Z().useEffect(a,b)};var useImperativeHandle=function(a,b,c){return Z().useImperativeHandle(a,b,c)}; var useLayoutEffect=function(a,b){return Z().useLayoutEffect(a,b)};var useMemo=function(a,b){return Z().useMemo(a,b)};var useReducer=function(a,b,c){return Z().useReducer(a,b,c)};var useRef=function(a){return Z().useRef(a)};var useState=function(a){return Z().useState(a)};var version="16.13.1"; var react_production_min = { Children: Children, Component: Component, Fragment: Fragment, Profiler: Profiler, PureComponent: PureComponent, StrictMode: StrictMode, Suspense: Suspense, __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, cloneElement: cloneElement, createContext: createContext, createElement: createElement, createFactory: createFactory, createRef: createRef, forwardRef: forwardRef, isValidElement: isValidElement, lazy: lazy, memo: memo, useCallback: useCallback, useContext: useContext, useDebugValue: useDebugValue, useEffect: useEffect, useImperativeHandle: useImperativeHandle, useLayoutEffect: useLayoutEffect, useMemo: useMemo, useReducer: useReducer, useRef: useRef, useState: useState, version: version }; /** * Copyright (c) 2013-present, Facebook, Inc. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED'; var ReactPropTypesSecret_1 = ReactPropTypesSecret; var printWarning = function() {}; if (process.env.NODE_ENV !== 'production') { var ReactPropTypesSecret$1 = ReactPropTypesSecret_1; var loggedTypeFailu