UNPKG

handsontable

Version:

Handsontable is a JavaScript Data Grid available for React, Angular and Vue.

88 lines (84 loc) 2.76 kB
"use strict"; exports.__esModule = true; require("core-js/modules/es.error.cause.js"); function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /** * @typedef PageInfo * @property {number} startIndex The visual index of the first item in the page. * @property {number} endIndex The visual index of the last item in the page. * @property {number} pageSize The number of items in the page. */ /** * The module computes the state of pagination based on a fixed page size. * * @class FixedPageSizeStrategy * @private */ class FixedPageSizeStrategy { constructor() { /** * The fixed page size. * * @type {number} */ _defineProperty(this, "pageSize", 1); /** * Total number of items in the dataset. * * @type {number} */ _defineProperty(this, "totalItems", 0); /** * Total number of pages. * * @type {number} */ _defineProperty(this, "totalPages", 0); } /** * Calculates the state of pagination. * * @param {object} options Options for pagination calculation. * @param {number} options.pageSize The fixed number of items per page. * @param {number} options.totalItems The total number of items in the dataset. */ calculate(_ref) { let { pageSize, totalItems } = _ref; this.pageSize = Math.max(pageSize, 1); this.totalItems = totalItems; this.totalPages = Math.max(1, Math.ceil(this.totalItems / this.pageSize)); } /** * Gets the total number of pages. * * @returns {number} The total number of pages. */ getTotalPages() { return this.totalPages; } /** * Gets the state of a specific page. * * @param {number} currentPage The current page number (1-based index). * @returns {PageInfo | undefined} */ getState(currentPage) { currentPage -= 1; if (currentPage < 0 || currentPage >= this.getTotalPages()) { return; } const startIndex = currentPage * this.pageSize; const endIndex = Math.max(0, Math.min(startIndex + this.pageSize - 1, this.totalItems - 1)); return { startIndex, endIndex, pageSize: this.pageSize }; } } exports.FixedPageSizeStrategy = FixedPageSizeStrategy;