@memobit/libs 4.2.0 → 4.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
.pagination{align-items:center;gap:var(--spacing-12);flex-wrap:wrap;justify-content:space-around;width:100%;display:flex}.pagination__pages{justify-content:center;align-items:center;gap:var(--spacing-8);flex:1;display:flex}.pagination--left .pagination__pages{justify-content:flex-start}.pagination--center .pagination__pages{flex:none;justify-content:center}.pagination--right{flex-direction:row-reverse}.pagination--right .pagination__pages,.pagination--single{justify-content:flex-end}.pagination .page-info{color:var(--body-color);font-size:var(--font-size-sm)}.pagination__page-size{align-items:center;gap:var(--spacing-8);font-size:var(--font-size-sm);color:var(--body-color);display:flex}.pagination__page-size .dropdown-container{min-width:120px}@media (width>=769px) and (width<=1024px){.pagination__pages{flex-wrap:wrap}.pagination .page-info{text-align:center;width:100%;margin-top:var(--spacing-8)}}@media (width<=768px){.pagination{flex-direction:column;align-items:stretch}.pagination__pages{flex-wrap:wrap
|
|
1
|
+
.pagination{align-items:center;gap:var(--spacing-12);flex-wrap:wrap;justify-content:space-around;width:100%;display:flex}.pagination__pages{justify-content:center;align-items:center;gap:var(--spacing-8);flex:1;display:flex;position:relative}.pagination__pages .button{font-variant-numeric:tabular-nums}.pagination__probe{visibility:hidden;pointer-events:none;display:flex;position:absolute;top:0;left:0}.pagination--left .pagination__pages{justify-content:flex-start}.pagination--center .pagination__pages{flex:none;justify-content:center}.pagination--right{flex-direction:row-reverse}.pagination--right .pagination__pages,.pagination--single{justify-content:flex-end}.pagination .page-info{color:var(--body-color);font-size:var(--font-size-sm)}.pagination__page-size{align-items:center;gap:var(--spacing-8);font-size:var(--font-size-sm);color:var(--body-color);display:flex}.pagination__page-size .dropdown-container{min-width:120px}@media (width>=769px) and (width<=1024px){.pagination__pages{flex-wrap:wrap}.pagination .page-info{text-align:center;width:100%;margin-top:var(--spacing-8)}}@media (width<=768px){.pagination{flex-direction:column;align-items:stretch}.pagination__pages{justify-content:center;gap:var(--spacing-4);flex-wrap:wrap}.pagination__pages .button{padding-inline:var(--spacing-8)}.pagination__page-size{justify-content:center}.pagination--single .pagination__page-size{justify-content:flex-end}}
|
|
@@ -1,90 +1,124 @@
|
|
|
1
1
|
import './Pagination.css';
|
|
2
|
-
import { libMessages as
|
|
3
|
-
import { useMessages as
|
|
4
|
-
import { Button as
|
|
5
|
-
import { Dropdown as
|
|
6
|
-
import { useBreakpoint as
|
|
2
|
+
import { libMessages as O } from "../../contexts/LanguageContext/libMessages.js";
|
|
3
|
+
import { useMessages as K } from "../../hooks/useLanguage.js";
|
|
4
|
+
import { Button as d } from "../Button/Button2.js";
|
|
5
|
+
import { Dropdown as U } from "../Dropdown/Dropdown2.js";
|
|
6
|
+
import { useBreakpoint as X } from "../../hooks/useBreakpoint.js";
|
|
7
|
+
import { getPageItems as q } from "./pageItems.js";
|
|
7
8
|
/* empty css */
|
|
8
|
-
import { useCallback as
|
|
9
|
-
import { jsx as
|
|
10
|
-
var
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
9
|
+
import { useCallback as z, useLayoutEffect as H, useRef as h, useState as J } from "react";
|
|
10
|
+
import { jsx as o, jsxs as m } from "react/jsx-runtime";
|
|
11
|
+
var Q = 5, W = "...", T = 1, g = (r) => r.getBoundingClientRect().width, V = (r, t) => r.room === t.room && r.gap === t.gap && r.ellipsis === t.ellipsis && r.byDigits.length === t.byDigits.length && r.byDigits.every((n, i) => n === t.byDigits[i]), Y = (r, t) => {
|
|
12
|
+
const n = getComputedStyle(r), i = r.clientWidth - parseFloat(n.paddingLeft) - parseFloat(n.paddingRight);
|
|
13
|
+
if (n.flexDirection.startsWith("column")) return i;
|
|
14
|
+
const b = parseFloat(n.columnGap) || 0;
|
|
15
|
+
let l = 0;
|
|
16
|
+
for (const p of r.children) {
|
|
17
|
+
if (p === t) continue;
|
|
18
|
+
const u = g(p);
|
|
19
|
+
u >= i || (l += u + b);
|
|
20
|
+
}
|
|
21
|
+
return i - l;
|
|
22
|
+
}, ae = ({ currentPage: r, totalPages: t, totalItems: n, onPageChange: i, showPagesNumbers: b = !1, pageSizeOptions: l, pageSize: p, onPageSizeChange: u, pageSizeLabel: F, horizontalAlign: G = "left" }) => {
|
|
23
|
+
const f = K(O), { isAtLeast: R } = X(), v = h(null), y = h(null), w = h(null), _ = h(null), [c, I] = J(null), k = n !== void 0 && !!l?.length && n <= Math.min(...l), A = t > 1 && !k, E = String(t).length, D = z(() => {
|
|
24
|
+
const e = v.current, s = e?.parentElement, a = y.current, B = w.current, C = _.current;
|
|
25
|
+
if (!e || !s || !a || !B || !C) return;
|
|
26
|
+
const [$ = 0, ...j] = Array.from(C.children, g), S = {
|
|
27
|
+
room: Y(s, e) - g(a) - g(B) - T,
|
|
28
|
+
gap: parseFloat(getComputedStyle(e).columnGap) || 0,
|
|
29
|
+
ellipsis: $,
|
|
30
|
+
byDigits: j
|
|
31
|
+
};
|
|
32
|
+
I((N) => N && V(N, S) ? N : S);
|
|
33
|
+
}, []), M = (e) => c ? e.reduce((s, a) => s + c.gap + (typeof a == "number" ? c.byDigits[String(a).length - 1] ?? 0 : c.ellipsis), c.gap) <= c.room : !0;
|
|
34
|
+
H(() => {
|
|
35
|
+
const e = v.current?.parentElement;
|
|
36
|
+
if (!A || !e) return;
|
|
37
|
+
const s = new ResizeObserver(D);
|
|
38
|
+
for (const a of [
|
|
39
|
+
e,
|
|
40
|
+
...e.children,
|
|
41
|
+
y.current,
|
|
42
|
+
w.current,
|
|
43
|
+
_.current
|
|
44
|
+
]) a && s.observe(a);
|
|
45
|
+
return D(), () => s.disconnect();
|
|
46
|
+
}, [A, D]);
|
|
47
|
+
const L = l && p !== void 0 && u, x = l?.map((e) => ({
|
|
48
|
+
label: `${e}`,
|
|
49
|
+
value: e
|
|
50
|
+
}));
|
|
51
|
+
return k || t <= 1 && !L ? null : /* @__PURE__ */ m("div", {
|
|
52
|
+
className: `pagination pagination--${G}${t <= 1 ? " pagination--single" : ""}`,
|
|
37
53
|
children: [
|
|
38
|
-
|
|
54
|
+
A && /* @__PURE__ */ m("div", {
|
|
39
55
|
className: "pagination__pages",
|
|
40
|
-
ref:
|
|
56
|
+
ref: v,
|
|
41
57
|
children: [
|
|
42
|
-
/* @__PURE__ */
|
|
58
|
+
/* @__PURE__ */ o(d, {
|
|
59
|
+
ref: y,
|
|
43
60
|
variant: "default",
|
|
44
61
|
borders: "sharp",
|
|
45
|
-
disabled:
|
|
46
|
-
icon: "
|
|
47
|
-
onClick: () =>
|
|
48
|
-
children:
|
|
62
|
+
disabled: r === 1,
|
|
63
|
+
icon: "caret-left",
|
|
64
|
+
onClick: () => i(r - 1),
|
|
65
|
+
children: R("desktop") ? f.previous : ""
|
|
49
66
|
}),
|
|
50
|
-
|
|
67
|
+
q(r, t, M, Q).map((e) => typeof e == "number" ? /* @__PURE__ */ o(d, {
|
|
51
68
|
borders: "sharp",
|
|
52
|
-
variant:
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
69
|
+
variant: e === r ? "warning" : "default",
|
|
70
|
+
onClick: () => i(e),
|
|
71
|
+
children: e
|
|
72
|
+
}, e) : /* @__PURE__ */ o(d, {
|
|
73
|
+
borders: "sharp",
|
|
74
|
+
variant: "default",
|
|
75
|
+
disabled: !0,
|
|
76
|
+
children: W
|
|
56
77
|
}, e)),
|
|
57
|
-
/* @__PURE__ */
|
|
78
|
+
/* @__PURE__ */ o(d, {
|
|
79
|
+
ref: w,
|
|
58
80
|
variant: "default",
|
|
59
81
|
borders: "sharp",
|
|
60
|
-
disabled:
|
|
61
|
-
sufixIcon: "
|
|
62
|
-
onClick: () =>
|
|
63
|
-
children:
|
|
82
|
+
disabled: r === t,
|
|
83
|
+
sufixIcon: "caret-right",
|
|
84
|
+
onClick: () => i(r + 1),
|
|
85
|
+
children: R("desktop") ? f.next : ""
|
|
86
|
+
}),
|
|
87
|
+
/* @__PURE__ */ m("span", {
|
|
88
|
+
className: "pagination__probe",
|
|
89
|
+
ref: _,
|
|
90
|
+
children: [/* @__PURE__ */ o(d, {
|
|
91
|
+
borders: "sharp",
|
|
92
|
+
disabled: !0,
|
|
93
|
+
children: W
|
|
94
|
+
}), Array.from({ length: E }, (e, s) => /* @__PURE__ */ o(d, {
|
|
95
|
+
borders: "sharp",
|
|
96
|
+
children: "8".repeat(s + 1)
|
|
97
|
+
}, s))]
|
|
64
98
|
})
|
|
65
99
|
]
|
|
66
100
|
}),
|
|
67
|
-
|
|
101
|
+
L && x && /* @__PURE__ */ m("div", {
|
|
68
102
|
className: "pagination__page-size",
|
|
69
|
-
children: [/* @__PURE__ */
|
|
103
|
+
children: [/* @__PURE__ */ o("span", { children: F ?? f.rows }), /* @__PURE__ */ o(U, {
|
|
70
104
|
name: "pageSize",
|
|
71
|
-
options:
|
|
72
|
-
value:
|
|
105
|
+
options: x,
|
|
106
|
+
value: p,
|
|
73
107
|
clearable: !1,
|
|
74
108
|
searchable: !1,
|
|
75
109
|
usePortal: !1,
|
|
76
|
-
onChange: (
|
|
77
|
-
|
|
110
|
+
onChange: (e) => {
|
|
111
|
+
e && !Array.isArray(e) && u(Number(e.value));
|
|
78
112
|
}
|
|
79
113
|
})]
|
|
80
114
|
}),
|
|
81
|
-
|
|
115
|
+
b && /* @__PURE__ */ o("span", {
|
|
82
116
|
className: "page-info",
|
|
83
|
-
children:
|
|
117
|
+
children: f.pageOf(r, t)
|
|
84
118
|
})
|
|
85
119
|
]
|
|
86
120
|
});
|
|
87
121
|
};
|
|
88
122
|
export {
|
|
89
|
-
|
|
123
|
+
ae as Pagination
|
|
90
124
|
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var o = (e, n) => Array.from({ length: Math.max(0, n - e + 1) }, (a, r) => e + r), i = (e, n, a, r) => {
|
|
2
|
+
if (n <= 1) return [1];
|
|
3
|
+
const s = Math.max(2, e - a), t = Math.min(n - 1, e + r), f = s > 3 ? ["start-gap"] : o(2, s - 1), g = t < n - 2 ? ["end-gap"] : o(t + 1, n - 1);
|
|
4
|
+
return [
|
|
5
|
+
1,
|
|
6
|
+
...f,
|
|
7
|
+
...o(s, t),
|
|
8
|
+
...g,
|
|
9
|
+
n
|
|
10
|
+
];
|
|
11
|
+
}, m = (e, n, a) => {
|
|
12
|
+
let r = e, s = e;
|
|
13
|
+
for (; ; ) {
|
|
14
|
+
const t = s < n && a(o(r, s + 1)), f = r > 1 && a(o(r - 1, s));
|
|
15
|
+
if (t && (s - e <= e - r || !f)) s += 1;
|
|
16
|
+
else if (f) r -= 1;
|
|
17
|
+
else return o(r, s);
|
|
18
|
+
}
|
|
19
|
+
}, d = (e, n, a, r) => {
|
|
20
|
+
const s = (l) => l !== null && a(l);
|
|
21
|
+
let t = 0, f = 0, g = i(e, n, t, f);
|
|
22
|
+
if (!a(g)) return m(e, n, a);
|
|
23
|
+
for (; ; ) {
|
|
24
|
+
const l = t < r && e - t > 3 ? i(e, n, t + 1, f) : null, h = f < r && e + f < n - 2 ? i(e, n, t, f + 1) : null;
|
|
25
|
+
if (s(h) && (f <= t || !s(l)))
|
|
26
|
+
f += 1, g = h;
|
|
27
|
+
else if (s(l))
|
|
28
|
+
t += 1, g = l;
|
|
29
|
+
else return g;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
export {
|
|
33
|
+
d as getPageItems
|
|
34
|
+
};
|
package/dist/version.js
CHANGED
package/dist/version.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memobit/libs",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "React component library powering the Memobit apps — 100+ components, helpers and hooks. Icons ship as @memobit/icons and themes as @memobit/themes. TypeScript-first, ESM-only, React 19.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|