uikit/dist/remote/Pagination.js
Mohamadzadeh e9d96339e2
All checks were successful
Build and Deploy Next.js + Nginx Docker Image / build-and-deploy (push) Successful in 52s
Build and Deploy Next.js + Nginx Docker Image / deploy (push) Successful in 7s
fix bug
2026-10-04 12:56:25 +03:30

534 lines
13 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const Z = {
full: {
showPageSummary: !0,
showTotalCount: !0,
showInput: !0,
inputWidth: "100px",
justifyContent: "space-around",
pageButtonPx: void 0,
getPageNumbers: ({ currentPage: t, totalPages: e }) => [
1,
t,
t + 1,
e
]
},
compact: {
showPageSummary: !1,
showTotalCount: !0,
showInput: !0,
inputWidth: "56px",
justifyContent: "space-around",
pageButtonPx: 2,
getPageNumbers: ({ currentPage: t, totalPages: e }) => [
1,
t,
e
]
},
simple: {
showPageSummary: !1,
showTotalCount: !1,
showInput: !1,
inputWidth: "48px",
justifyContent: "center",
pageButtonPx: void 0,
getPageNumbers: () => []
},
minimal: {
showPageSummary: !1,
showTotalCount: !1,
showInput: !0,
inputWidth: "56px",
justifyContent: "center",
pageButtonPx: void 0,
getPageNumbers: () => []
}
}, ee = ["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"], me = /[۰-۹]/g, pe = /[٠-٩]/g;
function I() {
const t = window.__UIKIT_REMOTE_DEPS__, e = [];
if (t?.React || e.push("React"), t?.createRoot || e.push("createRoot"), t?.ChakraProvider || e.push("ChakraProvider"), t?.Button || e.push("Button"), t?.HStack || e.push("HStack"), t?.IconButton || e.push("IconButton"), t?.Input || e.push("Input"), t?.Text || e.push("Text"), e.length)
throw new Error(
`[uikit-pagination] Missing remote dependencies: ${e.join(", ")}. Set window.__UIKIT_REMOTE_DEPS__ before loading the remote component.`
);
return t;
}
function c(t) {
return t == null ? "" : String(t).replace(/\d/g, (e) => ee[Number(e)]);
}
function J(t) {
return t == null ? "" : String(t).replace(
me,
(e) => String(ee.indexOf(e))
).replace(pe, (e) => String(e.charCodeAt(0) - 1632));
}
function fe(t) {
return Z[t] ? t : "full";
}
function U(t, e) {
const E = Number(t), m = Number(e);
return !m || m <= 0 || !E || Number.isNaN(E) ? 1 : Math.min(Math.max(E, 1), m);
}
function Q(t) {
const { React: e } = I();
return e.createElement(
"svg",
{
width: "20",
height: "20",
viewBox: "0 0 24 24",
fill: "none",
xmlns: "http://www.w3.org/2000/svg",
"aria-hidden": "true",
...t
},
e.createElement("path", {
d: "M9 18L15 12L9 6",
stroke: "currentColor",
strokeWidth: "2",
strokeLinecap: "round",
strokeLinejoin: "round"
})
);
}
function Y(t) {
const { React: e } = I();
return e.createElement(
"svg",
{
width: "20",
height: "20",
viewBox: "0 0 24 24",
fill: "none",
xmlns: "http://www.w3.org/2000/svg",
"aria-hidden": "true",
...t
},
e.createElement("path", {
d: "M15 18L9 12L15 6",
stroke: "currentColor",
strokeWidth: "2",
strokeLinecap: "round",
strokeLinejoin: "round"
})
);
}
function he({ size: t = 14, color: e = "#667085", label: E = "در حال بارگذاری" } = {}) {
const { React: m } = I();
return m.createElement(
"svg",
{
width: String(t),
height: String(t),
viewBox: "0 0 24 24",
fill: "none",
xmlns: "http://www.w3.org/2000/svg",
role: "status",
"aria-label": E,
style: { display: "block", flexShrink: 0, color: e }
},
m.createElement(
"circle",
{
cx: "12",
cy: "12",
r: "9",
stroke: "currentColor",
strokeWidth: "2.25",
strokeLinecap: "round",
strokeDasharray: "42 18"
},
m.createElement("animateTransform", {
attributeName: "transform",
type: "rotate",
from: "0 12 12",
to: "360 12 12",
dur: "0.8s",
repeatCount: "indefinite"
})
)
);
}
function ge({
currentPage: t = 1,
totalCount: e = 0,
totalPages: E,
pageSize: m = 10,
onPageChange: C,
level: F = "full",
loading: j = !1,
...L
}) {
const { React: n, Button: X, HStack: x, IconButton: D, Input: te, Text: f } = I(), { useCallback: T, useEffect: z, useMemo: ne, useRef: re, useState: M } = n, H = fe(F), h = Z[H], a = H === "simple", g = H === "minimal", u = j === !0, G = Number(m), oe = Number.isFinite(G) && G > 0 ? G : 10, O = Number(e), B = Number.isFinite(O) && O > 0 ? O : 0, V = Number(E), i = Number.isFinite(V) && V > 0 ? Math.ceil(V) : Math.ceil(B / oe), l = u && i <= 0 && B <= 0, N = u && !l, s = l ? 1 : U(t, i), [P, d] = M(
a ? "" : c(s)
), [k, S] = M(!1), [w, b] = M(null), y = re(null), p = w ?? s, $ = B > 0, ie = ne(() => a ? [] : l ? [1] : i <= 0 ? [] : Array.from(
new Set(
h.getPageNumbers({
currentPage: s,
totalPages: i
})
)
).filter((r) => r >= 1 && r <= i).sort((r, o) => r - o), [h, l, a, s, i]), R = T(() => {
d(a ? "" : c(s)), S(!1), b(null);
}, [a, s]), v = T(
(r) => {
if (u) return;
const o = U(r, i);
S(!1), d(a ? "" : c(s)), b(null), o !== s && C?.(o);
},
[u, a, C, s, i]
), W = T(() => {
if (!P) {
R(), y.current?.blur();
return;
}
const r = parseInt(J(P), 10);
if (Number.isNaN(r)) {
R(), y.current?.blur();
return;
}
const o = U(r, i);
if (a) {
S(!1), d(""), o !== s ? (b(o), C?.(o)) : b(null), y.current?.blur();
return;
}
o !== s ? (b(o), d(c(o)), C?.(o)) : (d(c(s)), S(!1), b(null)), y.current?.blur();
}, [
P,
a,
C,
R,
s,
i
]), ae = T(() => {
u || (b(null), d(""), S(!0));
}, [u]), se = T((r) => {
if (u) return;
const o = r.target.value, ce = J(o).replace(/\D/g, "");
d(c(ce));
}, [u]);
if (z(() => {
if (a) {
w !== null && s === w && b(null);
return;
}
if (w !== null) {
s === w && (b(null), S(!1), d(c(s)));
return;
}
k || d(c(s));
}, [k, a, w, s]), z(() => {
a && k && y.current?.focus();
}, [k, a]), z(() => {
if (!k || !P || !a && w !== null) return;
const r = setTimeout(() => {
W();
}, 1e3);
return () => clearTimeout(r);
}, [W, P, k, a, w]), i <= 0 && !l) return null;
const _ = (r = 14, o) => n.createElement(he, { size: r, color: o }), K = () => {
const r = n.createElement(te, {
ref: y,
type: "text",
inputMode: "numeric",
placeholder: g && N ? "" : "صفحه",
w: g && N ? "100%" : h.inputWidth,
value: g && N ? "" : P,
readOnly: u,
onFocus: () => {
u || a || (S(!0), b(null), d(""));
},
onChange: se,
onBlur: () => {
if (!u) {
if (P) {
a && W();
return;
}
R();
}
},
onKeyDown: (o) => {
u || (o.key === "Enter" && W(), o.key === "Escape" && R());
},
textAlign: "center",
color: "#1D2939",
fontSize: g ? "sm" : void 0,
fontWeight: g ? "700" : void 0,
_placeholder: g ? { fontWeight: "400" } : void 0,
h: g ? "28px" : void 0,
minH: g ? "28px" : void 0,
px: 1,
minW: 0,
dir: "ltr"
});
return !g || !N ? r : n.createElement(
"div",
{
style: {
position: "relative",
width: h.inputWidth,
height: "28px",
flexShrink: 0
}
},
r,
n.createElement(
"span",
{
style: {
position: "absolute",
inset: 0,
display: "flex",
alignItems: "center",
justifyContent: "center",
pointerEvents: "none"
}
},
_(13)
)
);
}, A = (r, o = !1) => n.createElement(
X,
{
key: r,
size: "md",
px: h.pageButtonPx,
bg: o ? "#4B49AC" : "#e6e6f1",
color: o ? "#e6e6f1" : "#4B49AC",
_hover: { bg: o ? "#4B49AC" : "#cbcbe8" },
onClick: a && o ? ae : () => v(r),
variant: "soft"
},
o && N ? _(14, "#FFFFFF") : c(r)
), q = () => n.createElement(
X,
{
key: "loading-total-page",
size: "md",
px: h.pageButtonPx,
bg: "#e6e6f1",
color: "#4B49AC",
variant: "soft",
cursor: "default",
"aria-label": "در حال دریافت تعداد صفحات"
},
_(14)
), le = a && i > 1 && p !== 1, ue = a && i > 1 && p !== i;
return g ? n.createElement(
x,
{
justifyContent: "space-between",
backgroundColor: "white",
py: "8px",
px: "12px",
rounded: "lg",
border: "1px",
borderColor: "blue.200",
w: "100%",
"aria-busy": u,
dir: "rtl",
...L
},
n.createElement(
x,
{ spacing: 2, alignItems: "center", justifyContent: "center" },
n.createElement(D, {
size: "sm",
w: "24px",
h: "24px",
minW: "24px",
minH: "24px",
bg: "#e6e6f1",
color: "#4B49AC",
_hover: { bg: "#cbcbe8" },
onClick: () => v(p - 1),
isDisabled: l || p === 1,
icon: n.createElement(Q, { width: "16", height: "16" }),
"aria-label": "صفحه قبلی"
}),
K(),
n.createElement(
f,
{ color: "#475467", fontSize: "sm", whiteSpace: "nowrap" },
"از"
),
n.createElement(
f,
{
color: "#1D2939",
fontSize: "sm",
fontWeight: "700",
cursor: i > 0 ? "pointer" : "default",
whiteSpace: "nowrap",
onClick: () => {
i > 0 && v(i);
}
},
l ? _(13) : c(i)
),
n.createElement(D, {
size: "sm",
w: "24px",
h: "24px",
minW: "24px",
minH: "24px",
bg: "#e6e6f1",
color: "#4B49AC",
_hover: { bg: "#cbcbe8" },
onClick: () => v(p + 1),
isDisabled: l || p === i,
icon: n.createElement(Y, { width: "16", height: "16" }),
"aria-label": "صفحه بعدی"
})
),
($ || l) && n.createElement(
x,
{
spacing: 1,
whiteSpace: "nowrap",
title: "تعداد کل",
"aria-label": "تعداد کل"
},
n.createElement(
f,
{ color: "#1D2939", fontSize: "sm", fontWeight: "700" },
l ? _(13) : c(B)
),
n.createElement(
f,
{ color: "#475467", fontSize: "sm" },
"مورد"
)
)
) : n.createElement(
x,
{
justifyContent: h.justifyContent,
backgroundColor: "white",
py: "10px",
px: "16px",
rounded: "lg",
border: "1px",
borderColor: "blue.200",
w: "100%",
"aria-busy": u,
...L
},
h.showPageSummary && n.createElement(
x,
{ spacing: 2, whiteSpace: "nowrap" },
n.createElement(f, { fontWeight: "bold" }, "صفحه"),
n.createElement(f, null, c(s)),
n.createElement(f, { fontWeight: "bold" }, "از"),
n.createElement(
f,
null,
l ? _(13) : c(i)
)
),
n.createElement(
x,
{ spacing: 2, alignItems: "center", justifyContent: "center" },
n.createElement(D, {
size: "md",
bg: "#e6e6f1",
color: "#4B49AC",
_hover: { bg: "#cbcbe8" },
onClick: () => v(p - 1),
isDisabled: l || p === 1,
icon: n.createElement(Q),
"aria-label": "صفحه قبلی"
}),
a ? [
le ? A(1) : null,
k ? n.createElement(
n.Fragment,
{ key: "input" },
K()
) : A(p, !0),
l ? q() : null,
ue ? A(i) : null
] : [
...ie.map(
(r) => A(r, s === r)
),
l ? q() : null,
h.showInput ? n.createElement(
n.Fragment,
{ key: "input" },
K()
) : null
],
n.createElement(D, {
size: "md",
bg: "#e6e6f1",
color: "#4B49AC",
_hover: { bg: "#cbcbe8" },
onClick: () => v(p + 1),
isDisabled: l || p === i,
icon: n.createElement(Y),
"aria-label": "صفحه بعدی"
})
),
h.showTotalCount && ($ || l) && n.createElement(
x,
{ spacing: 2, whiteSpace: "nowrap" },
n.createElement(
f,
{ w: "auto", fontWeight: "bold" },
"تعداد کل:"
),
n.createElement(
f,
null,
l ? _(13) : c(B)
)
)
);
}
class de extends HTMLElement {
constructor() {
super(), this._props = {}, this._root = null, this._unmountTimer = null;
}
connectedCallback() {
this._unmountTimer && (clearTimeout(this._unmountTimer), this._unmountTimer = null);
const { createRoot: e } = I();
this._root || (this._root = e(this)), this.renderComponent();
}
disconnectedCallback() {
!this._root || this._unmountTimer || (this._unmountTimer = setTimeout(() => {
this._unmountTimer = null, this._root && (this._root.unmount(), this._root = null);
}, 0));
}
set componentProps(e) {
this._props = e ?? {}, this.isConnected && this.renderComponent();
}
get componentProps() {
return this._props;
}
renderComponent() {
if (!this._root) return;
const {
React: e,
ChakraProvider: E,
theme: m,
chakraProviderProps: C
} = I(), { theme: F, chakraProviderProps: j, ...L } = this._props || {};
this._root.render(
e.createElement(
E,
{
theme: F || m,
resetCSS: !1,
disableGlobalStyle: !0,
...C || {},
...j || {}
},
e.createElement(ge, L)
)
);
}
}
customElements.get("uikit-pagination") || customElements.define("uikit-pagination", de);