UNPKG

@payfit/unity-components

Version:

39 lines (38 loc) 948 B
//#region src/components/client-side-pagination/utils/pagination-window.ts function e(e, t) { return Array.from({ length: t - e + 1 }, (t, n) => n + e).map((e) => ({ type: "page", value: e })); } function t(t, n, r) { let i = Math.max(5, r % 2 == 0 ? r + 1 : r), a = i - 2; if (t <= i) return Array.from({ length: t }, (e, t) => ({ type: "page", value: t + 1 })); let o = []; o.push({ type: "page", value: 1 }); let s = a - 2, c = Math.floor(s / 2); return n <= 3 + c ? (o.push(...e(2, a)), o.push({ type: "ellipsis", value: [a + 1, t - 1] })) : n >= t - (2 + c) ? (o.push({ type: "ellipsis", value: [2, t - (a - 1) - 1] }), o.push(...e(t - (a - 1), t - 1))) : (o.push({ type: "ellipsis", value: [2, n - c - 1] }), o.push(...e(n - c, n + c)), o.push({ type: "ellipsis", value: [n + c + 1, t - 1] })), o.push({ type: "page", value: t }), o; } //#endregion export { t as generatePaginationWithWindow };