UNPKG

@payfit/unity-components

Version:

58 lines (57 loc) 1.34 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 })); } var t = 5; function n(n, r, i) { let a = Math.max(t, i % 2 == 0 ? i + 1 : i), o = a - 2; if (n === -1) { let t = []; t.push({ type: "page", value: 1 }); let n = o - 1, i = Math.floor(n / 2); return r <= 3 + i ? (t.push(...e(2, a - 1)), t.push({ type: "ellipsis", value: [a, Infinity] })) : (t.push({ type: "ellipsis", value: [2, r - i] }), t.push(...e(r - i + 1, r + i)), t.push({ type: "ellipsis", value: [r + i + 1, Infinity] })), t; } if (n <= a) return Array.from({ length: n }, (e, t) => ({ type: "page", value: t + 1 })); let s = []; s.push({ type: "page", value: 1 }); let c = o - 2, l = Math.floor(c / 2); return r <= 3 + l ? (s.push(...e(2, o)), s.push({ type: "ellipsis", value: [o + 1, n - 1] })) : r >= n - (2 + l) ? (s.push({ type: "ellipsis", value: [2, n - (o - 1) - 1] }), s.push(...e(n - (o - 1), n - 1))) : (s.push({ type: "ellipsis", value: [2, r - l - 1] }), s.push(...e(r - l, r + l)), s.push({ type: "ellipsis", value: [r + l + 1, n - 1] })), s.push({ type: "page", value: n }), s; } //#endregion export { n as generatePaginationWithWindow };