UNPKG

@payfit/unity-components

Version:

57 lines (56 loc) 1.33 kB
//#region src/components/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 === -1) { let t = []; t.push({ type: "page", value: 1 }); let r = a - 1, o = Math.floor(r / 2); return n <= 3 + o ? (t.push(...e(2, i - 1)), t.push({ type: "ellipsis", value: [i, Infinity] })) : (t.push({ type: "ellipsis", value: [2, n - o] }), t.push(...e(n - o + 1, n + o)), t.push({ type: "ellipsis", value: [n + o + 1, Infinity] })), t; } 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 };