react-infinite-table
Version:
React table with infinite rows and much more!
88 lines (74 loc) • 3.56 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
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; } }
import InfiniteComputer from './infiniteComputer.js';
import bs from '../utils/binaryIndexSearch.js';
var ArrayInfiniteComputer = /*#__PURE__*/function (_InfiniteComputer) {
_inherits(ArrayInfiniteComputer, _InfiniteComputer);
var _super = _createSuper(ArrayInfiniteComputer);
function ArrayInfiniteComputer(heightData, numberOfChildren) {
var _this;
_classCallCheck(this, ArrayInfiniteComputer);
_this = _super.call(this, heightData, numberOfChildren);
_defineProperty(_assertThisInitialized(_this), "prefixHeightData", void 0);
_this.prefixHeightData = _this.heightData.reduce(function (acc, next) {
if (acc.length === 0) {
return [next];
} else {
acc.push(acc[acc.length - 1] + next);
return acc;
}
}, []);
return _this;
}
_createClass(ArrayInfiniteComputer, [{
key: "maybeIndexToIndex",
value: function maybeIndexToIndex(index) {
if (typeof index === 'undefined' || index === null) {
return this.prefixHeightData.length - 1;
} else {
return index;
}
}
}, {
key: "getTotalScrollableHeight",
value: function getTotalScrollableHeight() {
var length = this.prefixHeightData.length;
return length === 0 ? 0 : this.prefixHeightData[length - 1];
}
}, {
key: "getDisplayIndexStart",
value: function getDisplayIndexStart(windowTop) {
var foundIndex = bs.binaryIndexSearch(this.prefixHeightData, windowTop, bs.opts.CLOSEST_HIGHER);
return this.maybeIndexToIndex(foundIndex);
}
}, {
key: "getDisplayIndexEnd",
value: function getDisplayIndexEnd(windowBottom) {
var foundIndex = bs.binaryIndexSearch(this.prefixHeightData, windowBottom, bs.opts.CLOSEST_HIGHER);
return this.maybeIndexToIndex(foundIndex);
}
}, {
key: "getTopSpacerHeight",
value: function getTopSpacerHeight(displayIndexStart) {
var previous = displayIndexStart - 1;
return previous < 0 ? 0 : this.prefixHeightData[previous];
}
}, {
key: "getBottomSpacerHeight",
value: function getBottomSpacerHeight(displayIndexEnd) {
if (displayIndexEnd === -1) {
return 0;
}
return this.getTotalScrollableHeight() - this.prefixHeightData[displayIndexEnd];
}
}]);
return ArrayInfiniteComputer;
}(InfiniteComputer);
export default ArrayInfiniteComputer;