react-infinite-table
Version:
React table with infinite rows and much more!
66 lines (53 loc) • 2.6 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
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';
var ConstantInfiniteComputer = /*#__PURE__*/function (_InfiniteComputer) {
_inherits(ConstantInfiniteComputer, _InfiniteComputer);
var _super = _createSuper(ConstantInfiniteComputer);
function ConstantInfiniteComputer(rowCount, rowHeight) {
var _this;
_classCallCheck(this, ConstantInfiniteComputer);
_this = _super.call(this);
_this.rowCount = rowCount;
_this.rowHeight = rowHeight;
return _this;
}
_createClass(ConstantInfiniteComputer, [{
key: "getTotalScrollableHeight",
value: function getTotalScrollableHeight() {
return this.rowHeight * this.rowCount;
}
}, {
key: "getDisplayIndexStart",
value: function getDisplayIndexStart(windowTop) {
return Math.floor(windowTop / this.rowHeight);
}
}, {
key: "getDisplayIndexEnd",
value: function getDisplayIndexEnd(windowBottom) {
var nonZeroIndex = Math.ceil(windowBottom / this.rowHeight);
if (nonZeroIndex > 0) {
return nonZeroIndex - 1;
}
return nonZeroIndex;
}
}, {
key: "getTopSpacerHeight",
value: function getTopSpacerHeight(displayIndexStart) {
return displayIndexStart * this.rowHeight;
}
}, {
key: "getBottomSpacerHeight",
value: function getBottomSpacerHeight(displayIndexEnd) {
var nonZeroIndex = displayIndexEnd + 1;
return Math.max(0, (this.rowCount - nonZeroIndex) * this.rowHeight);
}
}]);
return ConstantInfiniteComputer;
}(InfiniteComputer);
export default ConstantInfiniteComputer;