diff --git a/README.md b/README.md index 239d2f4..a5b5ef6 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,9 @@ yarn add git+https://git.d.aiengines.ir/bi/uikit.git yarn upgrade uikit ``` -or +اگر نیاز به پاک‌سازی cache و نصب مجدد `uikit` بود: + +**Bash** ```bash rm -rf .next @@ -29,6 +31,17 @@ rm -rf node_modules/uikit yarn upgrade uikit ``` +**PowerShell** + +```powershell +Remove-Item -Recurse -Force .next -ErrorAction SilentlyContinue +Remove-Item -Recurse -Force node_modules/.vite -ErrorAction SilentlyContinue +Remove-Item -Recurse -Force node_modules/.cache -ErrorAction SilentlyContinue +Remove-Item -Recurse -Force node_modules/uikit -ErrorAction SilentlyContinue + +yarn upgrade uikit +``` + --- # imports diff --git a/dist/remote/Pagination.js b/dist/remote/Pagination.js index 8d17c40..55a6ad0 100644 --- a/dist/remote/Pagination.js +++ b/dist/remote/Pagination.js @@ -6,11 +6,11 @@ const Z = { inputWidth: "100px", justifyContent: "space-around", pageButtonPx: void 0, - getPageNumbers: ({ currentPage: t, totalPages: e }) => [ + getPageNumbers: ({ currentPage: e, totalPages: t }) => [ 1, - t, - t + 1, - e + e, + e + 1, + t ] }, compact: { @@ -20,10 +20,10 @@ const Z = { inputWidth: "56px", justifyContent: "space-around", pageButtonPx: 2, - getPageNumbers: ({ currentPage: t, totalPages: e }) => [ + getPageNumbers: ({ currentPage: e, totalPages: t }) => [ 1, - t, - e + e, + t ] }, simple: { @@ -44,34 +44,45 @@ const Z = { 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) +}, ee = ["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"], me = /[۰-۹]/g, fe = /[٠-٩]/g; +function v() { + const e = window.__UIKIT_REMOTE_DEPS__, t = []; + if (e?.React || t.push("React"), e?.createRoot || t.push("createRoot"), e?.ChakraProvider || t.push("ChakraProvider"), e?.Button || t.push("Button"), e?.HStack || t.push("HStack"), e?.IconButton || t.push("IconButton"), e?.Input || t.push("Input"), e?.Text || t.push("Text"), t.length) throw new Error( - `[uikit-pagination] Missing remote dependencies: ${e.join(", ")}. Set window.__UIKIT_REMOTE_DEPS__ before loading the remote component.` + `[uikit-pagination] Missing remote dependencies: ${t.join(", ")}. Set window.__UIKIT_REMOTE_DEPS__ before loading the remote component.` ); - return t; + return e; } -function c(t) { - return t == null ? "" : String(t).replace(/\d/g, (e) => ee[Number(e)]); +function c(e) { + return e == null ? "" : String(e).replace(/\d/g, (t) => ee[Number(t)]); } -function J(t) { - return t == null ? "" : String(t).replace( +function J(e) { + return e == null ? "" : String(e).replace( me, - (e) => String(ee.indexOf(e)) - ).replace(pe, (e) => String(e.charCodeAt(0) - 1632)); + (t) => String(ee.indexOf(t)) + ).replace(fe, (t) => String(t.charCodeAt(0) - 1632)); } -function fe(t) { - return Z[t] ? t : "full"; +function pe(e) { + return Z[e] ? e : "full"; } -function U(t, e) { - const E = Number(t), m = Number(e); +function ge(e) { + if (!e || typeof e != "object") return e; + const t = e.styles; + return !t || typeof t != "object" ? e : { + ...e, + styles: { + ...t, + global: {} + } + }; +} +function U(e, t) { + const E = Number(e), m = Number(t); 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( +function Q(e) { + const { React: t } = v(); + return t.createElement( "svg", { width: "20", @@ -80,9 +91,9 @@ function Q(t) { fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true", - ...t + ...e }, - e.createElement("path", { + t.createElement("path", { d: "M9 18L15 12L9 6", stroke: "currentColor", strokeWidth: "2", @@ -91,9 +102,9 @@ function Q(t) { }) ); } -function Y(t) { - const { React: e } = I(); - return e.createElement( +function Y(e) { + const { React: t } = v(); + return t.createElement( "svg", { width: "20", @@ -102,9 +113,9 @@ function Y(t) { fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true", - ...t + ...e }, - e.createElement("path", { + t.createElement("path", { d: "M15 18L9 12L15 6", stroke: "currentColor", strokeWidth: "2", @@ -113,136 +124,137 @@ function Y(t) { }) ); } -function he({ size: t = 14, color: e = "#667085", label: E = "در حال بارگذاری" } = {}) { - const { React: m } = I(); +function he({ size: e = 14, color: t = "#667085", label: E = "در حال بارگذاری" } = {}) { + const { React: m } = v(); return m.createElement( "svg", { - width: String(t), - height: String(t), + width: String(e), + height: String(e), 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 } + style: { + display: "block", + flexShrink: 0, + color: t, + transformOrigin: "50% 50%", + animation: "uikit-pagination-spinner 0.7s linear infinite", + willChange: "transform" + } }, 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" - }) - ) + "style", + null, + "@keyframes uikit-pagination-spinner{from{transform:rotate(0deg)}to{transform:rotate(360deg)}}" + ), + m.createElement("circle", { + cx: "12", + cy: "12", + r: "9", + stroke: "currentColor", + strokeWidth: "2.25", + strokeLinecap: "round", + strokeDasharray: "42 18" + }) ); } -function ge({ - currentPage: t = 1, - totalCount: e = 0, +function de({ + currentPage: e = 1, + totalCount: t = 0, totalPages: E, pageSize: m = 10, onPageChange: C, - level: F = "full", - loading: j = !1, + level: A = "full", + loading: F = !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( + const { React: n, Button: X, HStack: x, IconButton: D, Input: te, Text: p } = v(), { useCallback: I, useEffect: z, useMemo: ne, useRef: re, useState: M } = n, H = pe(A), g = Z[H], s = H === "simple", h = H === "minimal", u = F === !0, G = Number(m), oe = Number.isFinite(G) && G > 0 ? G : 10, O = Number(t), 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, a = l ? 1 : U(e, i), [k, d] = M( + s ? "" : c(a) + ), [P, y] = M(!1), [w, b] = M(null), _ = re(null), f = w ?? a, $ = B > 0, ie = ne(() => s ? [] : l ? [1] : i <= 0 ? [] : Array.from( new Set( - h.getPageNumbers({ - currentPage: s, + g.getPageNumbers({ + currentPage: a, 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( + ).filter((r) => r >= 1 && r <= i).sort((r, o) => r - o), [g, l, s, a, i]), R = I(() => { + d(s ? "" : c(a)), y(!1), b(null); + }, [s, a]), T = I( (r) => { if (u) return; const o = U(r, i); - S(!1), d(a ? "" : c(s)), b(null), o !== s && C?.(o); + y(!1), d(s ? "" : c(a)), b(null), o !== a && C?.(o); }, - [u, a, C, s, i] - ), W = T(() => { - if (!P) { - R(), y.current?.blur(); + [u, s, C, a, i] + ), W = I(() => { + if (!k) { + R(), _.current?.blur(); return; } - const r = parseInt(J(P), 10); + const r = parseInt(J(k), 10); if (Number.isNaN(r)) { - R(), y.current?.blur(); + R(), _.current?.blur(); return; } const o = U(r, i); - if (a) { - S(!1), d(""), o !== s ? (b(o), C?.(o)) : b(null), y.current?.blur(); + if (s) { + y(!1), d(""), o !== a ? (b(o), C?.(o)) : b(null), _.current?.blur(); return; } - o !== s ? (b(o), d(c(o)), C?.(o)) : (d(c(s)), S(!1), b(null)), y.current?.blur(); + o !== a ? (b(o), d(c(o)), C?.(o)) : (d(c(a)), y(!1), b(null)), _.current?.blur(); }, [ - P, - a, + k, + s, C, R, - s, + a, i - ]), ae = T(() => { - u || (b(null), d(""), S(!0)); - }, [u]), se = T((r) => { + ]), se = I(() => { + u || (b(null), d(""), y(!0)); + }, [u]), ae = I((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); + if (s) { + w !== null && a === w && b(null); return; } if (w !== null) { - s === w && (b(null), S(!1), d(c(s))); + a === w && (b(null), y(!1), d(c(a))); 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; + P || d(c(a)); + }, [P, s, w, a]), z(() => { + s && P && _.current?.focus(); + }, [P, s]), z(() => { + if (!P || !k || !s && 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 = () => { + }, [W, k, P, s, w]), i <= 0 && !l) return null; + const S = (r = 14, o) => n.createElement(he, { size: r, color: o }), K = () => { const r = n.createElement(te, { - ref: y, + ref: _, type: "text", inputMode: "numeric", - placeholder: g && N ? "" : "صفحه", - w: g && N ? "100%" : h.inputWidth, - value: g && N ? "" : P, + placeholder: h && N ? "" : "صفحه", + w: h && N ? "100%" : g.inputWidth, + value: h && N ? "" : k, readOnly: u, onFocus: () => { - u || a || (S(!0), b(null), d("")); + u || s || (y(!0), b(null), d("")); }, - onChange: se, + onChange: ae, onBlur: () => { if (!u) { - if (P) { - a && W(); + if (k) { + s && W(); return; } R(); @@ -253,21 +265,21 @@ function ge({ }, 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, + fontSize: h ? "sm" : void 0, + fontWeight: h ? "700" : void 0, + _placeholder: h ? { fontWeight: "400" } : void 0, + h: h ? "28px" : void 0, + minH: h ? "28px" : void 0, px: 1, minW: 0, dir: "ltr" }); - return !g || !N ? r : n.createElement( + return !h || !N ? r : n.createElement( "div", { style: { position: "relative", - width: h.inputWidth, + width: g.inputWidth, height: "28px", flexShrink: 0 } @@ -285,37 +297,37 @@ function ge({ pointerEvents: "none" } }, - _(13) + S(13) ) ); - }, A = (r, o = !1) => n.createElement( + }, j = (r, o = !1) => n.createElement( X, { key: r, size: "md", - px: h.pageButtonPx, + px: g.pageButtonPx, bg: o ? "#4B49AC" : "#e6e6f1", color: o ? "#e6e6f1" : "#4B49AC", _hover: { bg: o ? "#4B49AC" : "#cbcbe8" }, - onClick: a && o ? ae : () => v(r), + onClick: s && o ? se : () => T(r), variant: "soft" }, - o && N ? _(14, "#FFFFFF") : c(r) + o && N ? S(14, "#FFFFFF") : c(r) ), q = () => n.createElement( X, { key: "loading-total-page", size: "md", - px: h.pageButtonPx, + px: g.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( + S(14) + ), le = s && i > 1 && f !== 1, ue = s && i > 1 && f !== i; + return h ? n.createElement( x, { justifyContent: "space-between", @@ -342,19 +354,19 @@ function ge({ bg: "#e6e6f1", color: "#4B49AC", _hover: { bg: "#cbcbe8" }, - onClick: () => v(p - 1), - isDisabled: l || p === 1, + onClick: () => T(f - 1), + isDisabled: l || f === 1, icon: n.createElement(Q, { width: "16", height: "16" }), "aria-label": "صفحه قبلی" }), K(), n.createElement( - f, + p, { color: "#475467", fontSize: "sm", whiteSpace: "nowrap" }, "از" ), n.createElement( - f, + p, { color: "#1D2939", fontSize: "sm", @@ -362,10 +374,10 @@ function ge({ cursor: i > 0 ? "pointer" : "default", whiteSpace: "nowrap", onClick: () => { - i > 0 && v(i); + i > 0 && T(i); } }, - l ? _(13) : c(i) + l ? S(13) : c(i) ), n.createElement(D, { size: "sm", @@ -376,8 +388,8 @@ function ge({ bg: "#e6e6f1", color: "#4B49AC", _hover: { bg: "#cbcbe8" }, - onClick: () => v(p + 1), - isDisabled: l || p === i, + onClick: () => T(f + 1), + isDisabled: l || f === i, icon: n.createElement(Y, { width: "16", height: "16" }), "aria-label": "صفحه بعدی" }) @@ -391,12 +403,12 @@ function ge({ "aria-label": "تعداد کل" }, n.createElement( - f, + p, { color: "#1D2939", fontSize: "sm", fontWeight: "700" }, - l ? _(13) : c(B) + l ? S(13) : c(B) ), n.createElement( - f, + p, { color: "#475467", fontSize: "sm" }, "مورد" ) @@ -404,7 +416,7 @@ function ge({ ) : n.createElement( x, { - justifyContent: h.justifyContent, + justifyContent: g.justifyContent, backgroundColor: "white", py: "10px", px: "16px", @@ -415,16 +427,16 @@ function ge({ "aria-busy": u, ...L }, - h.showPageSummary && n.createElement( + g.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(p, { fontWeight: "bold" }, "صفحه"), + n.createElement(p, null, c(a)), + n.createElement(p, { fontWeight: "bold" }, "از"), n.createElement( - f, + p, null, - l ? _(13) : c(i) + l ? S(13) : c(i) ) ), n.createElement( @@ -435,26 +447,26 @@ function ge({ bg: "#e6e6f1", color: "#4B49AC", _hover: { bg: "#cbcbe8" }, - onClick: () => v(p - 1), - isDisabled: l || p === 1, + onClick: () => T(f - 1), + isDisabled: l || f === 1, icon: n.createElement(Q), "aria-label": "صفحه قبلی" }), - a ? [ - le ? A(1) : null, - k ? n.createElement( + s ? [ + le ? j(1) : null, + P ? n.createElement( n.Fragment, { key: "input" }, K() - ) : A(p, !0), + ) : j(f, !0), l ? q() : null, - ue ? A(i) : null + ue ? j(i) : null ] : [ ...ie.map( - (r) => A(r, s === r) + (r) => j(r, a === r) ), l ? q() : null, - h.showInput ? n.createElement( + g.showInput ? n.createElement( n.Fragment, { key: "input" }, K() @@ -465,44 +477,44 @@ function ge({ bg: "#e6e6f1", color: "#4B49AC", _hover: { bg: "#cbcbe8" }, - onClick: () => v(p + 1), - isDisabled: l || p === i, + onClick: () => T(f + 1), + isDisabled: l || f === i, icon: n.createElement(Y), "aria-label": "صفحه بعدی" }) ), - h.showTotalCount && ($ || l) && n.createElement( + g.showTotalCount && ($ || l) && n.createElement( x, { spacing: 2, whiteSpace: "nowrap" }, n.createElement( - f, + p, { w: "auto", fontWeight: "bold" }, "تعداد کل:" ), n.createElement( - f, + p, null, - l ? _(13) : c(B) + l ? S(13) : c(B) ) ) ); } -class de extends HTMLElement { +class be 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(); + const { createRoot: t } = v(); + this._root || (this._root = t(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(); + set componentProps(t) { + this._props = t ?? {}, this.isConnected && this.renderComponent(); } get componentProps() { return this._props; @@ -510,24 +522,25 @@ class de extends HTMLElement { renderComponent() { if (!this._root) return; const { - React: e, + React: t, ChakraProvider: E, theme: m, chakraProviderProps: C - } = I(), { theme: F, chakraProviderProps: j, ...L } = this._props || {}; + } = v(), { theme: A, chakraProviderProps: F, ...L } = this._props || {}, n = ge(A || m); this._root.render( - e.createElement( + t.createElement( E, { - theme: F || m, + ...C || {}, + ...F || {}, + theme: n, resetCSS: !1, disableGlobalStyle: !0, - ...C || {}, - ...j || {} + cssVarsRoot: "uikit-pagination" }, - e.createElement(ge, L) + t.createElement(de, L) ) ); } } -customElements.get("uikit-pagination") || customElements.define("uikit-pagination", de); +customElements.get("uikit-pagination") || customElements.define("uikit-pagination", be); diff --git a/src/remote/ui/Pagination/Pagination.remote.jsx b/src/remote/ui/Pagination/Pagination.remote.jsx index db7708a..e4a8b4a 100644 --- a/src/remote/ui/Pagination/Pagination.remote.jsx +++ b/src/remote/ui/Pagination/Pagination.remote.jsx @@ -101,6 +101,21 @@ function normalizeLevel(level) { return "full"; } +function getScopedChakraTheme(theme) { + if (!theme || typeof theme !== "object") return theme; + + const styles = theme.styles; + if (!styles || typeof styles !== "object") return theme; + + return { + ...theme, + styles: { + ...styles, + global: {}, + }, + }; +} + function getSafePage(page, totalPages) { const numericPage = Number(page); const numericTotalPages = Number(totalPages); @@ -173,28 +188,29 @@ function LoadingSpinner({ size = 14, color = "#667085", label = "در حال ب xmlns: "http://www.w3.org/2000/svg", role: "status", "aria-label": label, - style: { display: "block", flexShrink: 0, color }, + style: { + display: "block", + flexShrink: 0, + color, + transformOrigin: "50% 50%", + animation: "uikit-pagination-spinner 0.7s linear infinite", + willChange: "transform", + }, }, React.createElement( - "circle", - { - cx: "12", - cy: "12", - r: "9", - stroke: "currentColor", - strokeWidth: "2.25", - strokeLinecap: "round", - strokeDasharray: "42 18", - }, - React.createElement("animateTransform", { - attributeName: "transform", - type: "rotate", - from: "0 12 12", - to: "360 12 12", - dur: "0.8s", - repeatCount: "indefinite", - }), + "style", + null, + "@keyframes uikit-pagination-spinner{from{transform:rotate(0deg)}to{transform:rotate(360deg)}}", ), + React.createElement("circle", { + cx: "12", + cy: "12", + r: "9", + stroke: "currentColor", + strokeWidth: "2.25", + strokeLinecap: "round", + strokeDasharray: "42 18", + }), ); } @@ -786,15 +802,18 @@ class PaginationElement extends HTMLElement { const { theme, chakraProviderProps, ...paginationProps } = this._props || {}; + const scopedTheme = getScopedChakraTheme(theme || defaultTheme); + this._root.render( React.createElement( ChakraProvider, { - theme: theme || defaultTheme, - resetCSS: false, - disableGlobalStyle: true, ...(defaultProviderProps || {}), ...(chakraProviderProps || {}), + theme: scopedTheme, + resetCSS: false, + disableGlobalStyle: true, + cssVarsRoot: "uikit-pagination", }, React.createElement(RemotePagination, paginationProps), ),