@0xchain/pagination 1.1.0-beta.18 → 1.1.0-beta.19

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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ ## 1.1.0-beta.19 (2026-03-17)
2
+
3
+ ### 🩹 Fixes
4
+
5
+ - monorepo 最佳实践审查修复
6
+
7
+ ### 🧱 Updated Dependencies
8
+
9
+ - Updated @0xchain/ui to 1.1.0-beta.19
10
+
11
+ ### ❤️ Thank You
12
+
13
+ - jee.song
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present 0xchain
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.js CHANGED
@@ -1,136 +1,158 @@
1
1
  'use client';
2
- import { jsx as e, jsxs as p } from "react/jsx-runtime";
3
- import * as z from "react";
4
- import { Pagination as j, PaginationContent as V, PaginationItem as r, PaginationLink as a, PaginationEllipsis as v } from "@0xchain/ui/pagination";
5
- import { Select as S, SelectTrigger as L, SelectValue as I, SelectContent as R, SelectItem as E } from "@0xchain/ui/select";
6
- import { twMerge as n } from "tailwind-merge";
7
- import { useTranslations as F } from "next-intl";
8
- import { ChevronRight as G, ChevronLeft as T } from "lucide-react";
9
- const N = 1e4;
10
- function K({
11
- className: k,
12
- total: u,
13
- pageSize: x,
14
- pageSizeOptions: b = [10, 30, 50],
15
- currentPage: s,
16
- layout: f = ["prev", "page", "next", "ellipsis", "sizes", "total"],
17
- onPageChange: t,
18
- onPageSizeChange: h,
19
- totalLabel: y
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { Pagination, PaginationContent, PaginationItem, PaginationLink, PaginationEllipsis } from "@0xchain/ui/pagination";
5
+ import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from "@0xchain/ui/select";
6
+ import { twMerge } from "tailwind-merge";
7
+ import { useTranslations } from "next-intl";
8
+ import { ChevronRight, ChevronLeft } from "lucide-react";
9
+ const limit = 1e4;
10
+ function CustomPagination({
11
+ className,
12
+ total: initialTotal,
13
+ pageSize,
14
+ pageSizeOptions = [10, 30, 50],
15
+ currentPage,
16
+ layout = ["prev", "page", "next", "ellipsis", "sizes", "total"],
17
+ onPageChange,
18
+ onPageSizeChange,
19
+ totalLabel
20
20
  }) {
21
- const d = F(), w = Math.min(u, N), l = Math.ceil(w / x), M = () => {
22
- const i = [];
23
- let o = Math.max(1, s - Math.floor(1.5));
24
- const m = Math.min(l, o + 3 - 1);
25
- m - o + 1 < 3 && (o = Math.max(1, m - 3 + 1)), o > 1 && (i.push(
26
- /* @__PURE__ */ e(r, { children: /* @__PURE__ */ e(
27
- a,
28
- {
29
- size: "sm",
30
- className: n(
31
- "h-6 min-w-6 w-fit rounded-md cursor-pointer",
32
- s === 1 ? "bg-[#000]! text-primary-foreground!" : ""
33
- ),
34
- onClick: () => t == null ? void 0 : t(1),
35
- children: "1"
36
- }
37
- ) }, "first")
38
- ), o > 2 && i.push(
39
- /* @__PURE__ */ e(r, { children: /* @__PURE__ */ e(v, {}) }, "ellipsis-start")
40
- ));
41
- for (let c = o; c <= m; c++)
42
- i.push(
43
- /* @__PURE__ */ e(r, { children: /* @__PURE__ */ e(
44
- a,
21
+ const t = useTranslations();
22
+ const total = Math.min(initialTotal, limit);
23
+ const totalPages = Math.ceil(total / pageSize);
24
+ const renderPageNumbers = () => {
25
+ const pages = [];
26
+ const maxVisiblePages = 3;
27
+ let startPage = Math.max(1, currentPage - Math.floor(maxVisiblePages / 2));
28
+ const endPage = Math.min(totalPages, startPage + maxVisiblePages - 1);
29
+ if (endPage - startPage + 1 < maxVisiblePages) {
30
+ startPage = Math.max(1, endPage - maxVisiblePages + 1);
31
+ }
32
+ if (startPage > 1) {
33
+ pages.push(
34
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(
35
+ PaginationLink,
45
36
  {
46
37
  size: "sm",
47
- className: n(
38
+ className: twMerge(
48
39
  "h-6 min-w-6 w-fit rounded-md cursor-pointer",
49
- s === c ? "bg-[#000]! text-primary-foreground!" : ""
40
+ currentPage === 1 ? "bg-[#000]! text-primary-foreground!" : ""
50
41
  ),
51
- onClick: () => t == null ? void 0 : t(c),
52
- children: c
42
+ onClick: () => onPageChange?.(1),
43
+ children: "1"
53
44
  }
54
- ) }, c)
45
+ ) }, "first")
55
46
  );
56
- return m < l && (m < l - 1 && i.push(
57
- /* @__PURE__ */ e(r, { className: "cursor-pointer", children: /* @__PURE__ */ e(v, {}) }, "ellipsis-end")
58
- ), i.push(
59
- /* @__PURE__ */ e(r, { children: /* @__PURE__ */ e(
60
- a,
61
- {
62
- size: "sm",
63
- className: n(
64
- "h-6 min-w-6 w-fit rounded-md cursor-pointer",
65
- s === l ? "bg-[#000]! text-primary-foreground!" : ""
66
- ),
67
- onClick: () => t == null ? void 0 : t(l),
68
- children: l
69
- }
70
- ) }, "last")
71
- )), i;
47
+ if (startPage > 2) {
48
+ pages.push(
49
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationEllipsis, {}) }, "ellipsis-start")
50
+ );
51
+ }
52
+ }
53
+ for (let i = startPage; i <= endPage; i++) {
54
+ pages.push(
55
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(
56
+ PaginationLink,
57
+ {
58
+ size: "sm",
59
+ className: twMerge(
60
+ "h-6 min-w-6 w-fit rounded-md cursor-pointer",
61
+ currentPage === i ? "bg-[#000]! text-primary-foreground!" : ""
62
+ ),
63
+ onClick: () => onPageChange?.(i),
64
+ children: i
65
+ }
66
+ ) }, i)
67
+ );
68
+ }
69
+ if (endPage < totalPages) {
70
+ if (endPage < totalPages - 1) {
71
+ pages.push(
72
+ /* @__PURE__ */ jsx(PaginationItem, { className: "cursor-pointer", children: /* @__PURE__ */ jsx(PaginationEllipsis, {}) }, "ellipsis-end")
73
+ );
74
+ }
75
+ pages.push(
76
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(
77
+ PaginationLink,
78
+ {
79
+ size: "sm",
80
+ className: twMerge(
81
+ "h-6 min-w-6 w-fit rounded-md cursor-pointer",
82
+ currentPage === totalPages ? "bg-[#000]! text-primary-foreground!" : ""
83
+ ),
84
+ onClick: () => onPageChange?.(totalPages),
85
+ children: totalPages
86
+ }
87
+ ) }, "last")
88
+ );
89
+ }
90
+ return pages;
72
91
  };
73
- return w <= b[0] ? null : /* @__PURE__ */ e(j, { className: n("w-full max-w-screen mt-3", k), children: /* @__PURE__ */ p(V, { className: "w-full flex flex-row items-center justify-between flex-wrap", children: [
74
- f.includes("total") && /* @__PURE__ */ e(r, { className: "mr-auto order-1 flex-1 overflow-hidden md:overflow-visible md:order-0 ", children: y || /* @__PURE__ */ p("span", { className: "text-sm block text-muted-foreground w-full truncate", children: [
75
- d("common.pagination.total"),
92
+ if (total <= pageSizeOptions[0]) {
93
+ return null;
94
+ }
95
+ return /* @__PURE__ */ jsx(Pagination, { className: twMerge("w-full max-w-screen mt-3", className), children: /* @__PURE__ */ jsxs(PaginationContent, { className: "w-full flex flex-row items-center justify-between flex-wrap", children: [
96
+ layout.includes("total") && /* @__PURE__ */ jsx(PaginationItem, { className: "mr-auto order-1 flex-1 overflow-hidden md:overflow-visible md:order-0 ", children: totalLabel || /* @__PURE__ */ jsxs("span", { className: "text-sm block text-muted-foreground w-full truncate", children: [
97
+ t("common.pagination.total"),
76
98
  " ",
77
- u,
99
+ initialTotal,
78
100
  " ",
79
- d("common.pagination.item"),
80
- u > N ? `${d("common.pagination.totalTip")}` : ""
101
+ t("common.pagination.item"),
102
+ initialTotal > limit ? `${t("common.pagination.totalTip")}` : ""
81
103
  ] }) }, "total"),
82
- /* @__PURE__ */ e("div", { className: "w-full md:w-auto md:flex-2 flex items-center justify-center", children: f.filter((i) => i !== "total" && i !== "sizes").map((i) => {
83
- switch (i) {
104
+ /* @__PURE__ */ jsx("div", { className: "w-full md:w-auto md:flex-2 flex items-center justify-center", children: layout.filter((item) => item !== "total" && item !== "sizes").map((item) => {
105
+ switch (item) {
84
106
  case "prev":
85
- return /* @__PURE__ */ e(r, { children: /* @__PURE__ */ e(
86
- a,
107
+ return /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(
108
+ PaginationLink,
87
109
  {
88
110
  "aria-label": "Go to previous page",
89
111
  size: "sm",
90
- className: n(
112
+ className: twMerge(
91
113
  "flex items-center justify-center pointer gap-1 shrink-0 cursor-pointer px-2",
92
- s === 1 ? "pointer-events-none opacity-50" : ""
114
+ currentPage === 1 ? "pointer-events-none opacity-50" : ""
93
115
  ),
94
- onClick: () => t == null ? void 0 : t(Math.max(1, s - 1)),
95
- children: /* @__PURE__ */ e(T, { size: 16 })
116
+ onClick: () => onPageChange?.(Math.max(1, currentPage - 1)),
117
+ children: /* @__PURE__ */ jsx(ChevronLeft, { size: 16 })
96
118
  }
97
119
  ) }, "prev");
98
120
  case "page":
99
- return /* @__PURE__ */ e(z.Fragment, { children: M() }, "page");
121
+ return /* @__PURE__ */ jsx(React.Fragment, { children: renderPageNumbers() }, "page");
100
122
  case "next":
101
- return /* @__PURE__ */ e(r, { children: /* @__PURE__ */ e(
102
- a,
123
+ return /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(
124
+ PaginationLink,
103
125
  {
104
126
  size: "sm",
105
- className: n(
127
+ className: twMerge(
106
128
  "flex items-center justify-center pointer gap-1 shrink-0 cursor-pointer px-2",
107
- s === l ? "pointer-events-none opacity-50" : ""
129
+ currentPage === totalPages ? "pointer-events-none opacity-50" : ""
108
130
  ),
109
- onClick: () => t == null ? void 0 : t(Math.min(l, s + 1)),
110
- children: /* @__PURE__ */ e(G, { size: 16 })
131
+ onClick: () => onPageChange?.(Math.min(totalPages, currentPage + 1)),
132
+ children: /* @__PURE__ */ jsx(ChevronRight, { size: 16 })
111
133
  }
112
134
  ) }, "next");
113
135
  default:
114
136
  return null;
115
137
  }
116
138
  }) }),
117
- f.includes("sizes") && h && /* @__PURE__ */ p(r, { className: "gap-2 flex shrink-0 order-1 lg:order-0 items-center py-0.5 flex-1 justify-end", children: [
118
- /* @__PURE__ */ e("span", { className: "text-sm text-muted-foreground", children: d("common.pagination.sizeLabel") }),
119
- /* @__PURE__ */ p(
120
- S,
139
+ layout.includes("sizes") && onPageSizeChange && /* @__PURE__ */ jsxs(PaginationItem, { className: "gap-2 flex shrink-0 order-1 lg:order-0 items-center py-0.5 flex-1 justify-end", children: [
140
+ /* @__PURE__ */ jsx("span", { className: "text-sm text-muted-foreground", children: t("common.pagination.sizeLabel") }),
141
+ /* @__PURE__ */ jsxs(
142
+ Select,
121
143
  {
122
- value: x.toString(),
123
- onValueChange: (i) => h(Number(i)),
144
+ value: pageSize.toString(),
145
+ onValueChange: (value) => onPageSizeChange(Number(value)),
124
146
  children: [
125
- /* @__PURE__ */ e(
126
- L,
147
+ /* @__PURE__ */ jsx(
148
+ SelectTrigger,
127
149
  {
128
150
  size: "sm",
129
151
  className: "border border-input w-[70px] focus:ring-0 text-foreground bg-background focus-visible:outline-0 focus-ring-0 focus-visible:ring-0 focus-visible:ring-offset-0 focus-visible:border-input py-1",
130
- children: /* @__PURE__ */ e(I, {})
152
+ children: /* @__PURE__ */ jsx(SelectValue, {})
131
153
  }
132
154
  ),
133
- /* @__PURE__ */ e(R, { className: "w-20 bg-card", children: b.map((i) => /* @__PURE__ */ e(E, { value: i.toString(), className: "text-sm px-2 py-1 cursor-pointer hover:bg-background", children: i }, i)) })
155
+ /* @__PURE__ */ jsx(SelectContent, { className: "w-20 bg-card", children: pageSizeOptions.map((size) => /* @__PURE__ */ jsx(SelectItem, { value: size.toString(), className: "text-sm px-2 py-1 cursor-pointer hover:bg-background", children: size }, size)) })
134
156
  ]
135
157
  }
136
158
  )
@@ -138,5 +160,5 @@ function K({
138
160
  ] }) });
139
161
  }
140
162
  export {
141
- K as default
163
+ CustomPagination as default
142
164
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xchain/pagination",
3
- "version": "1.1.0-beta.18",
3
+ "version": "1.1.0-beta.19",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -13,16 +13,28 @@
13
13
  "default": "./dist/index.js"
14
14
  }
15
15
  },
16
- "dependencies": {
16
+ "peerDependencies": {
17
+ "lucide-react": "0.539.0",
18
+ "next-intl": "4.8.2",
17
19
  "react": "19.1.1",
18
20
  "react-dom": "19.1.1",
19
- "next-intl": "4.8.2",
20
- "tailwind-merge": "3.3.1",
21
- "lucide-react": "0.539.0",
22
- "@0xchain/ui": "1.1.0-beta.18"
21
+ "tailwind-merge": "3.3.1"
22
+ },
23
+ "dependencies": {
24
+ "@0xchain/ui": "1.1.0-beta.19"
23
25
  },
24
26
  "devDependencies": {
25
- "rollup-plugin-preserve-use-client": "3.0.1"
27
+ "lucide-react": "0.539.0",
28
+ "next-intl": "4.8.2",
29
+ "react": "19.1.1",
30
+ "react-dom": "19.1.1",
31
+ "rollup-plugin-preserve-use-client": "3.0.1",
32
+ "tailwind-merge": "3.3.1"
33
+ },
34
+ "nx": {
35
+ "tags": [
36
+ "type:ui"
37
+ ]
26
38
  },
27
39
  "publishConfig": {
28
40
  "access": "public"
package/tsconfig.json CHANGED
@@ -2,9 +2,6 @@
2
2
  "files": [],
3
3
  "include": [],
4
4
  "references": [
5
- {
6
- "path": "../ui"
7
- },
8
5
  {
9
6
  "path": "./tsconfig.lib.json"
10
7
  },
package/vite.config.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types='vitest' />
2
1
  import { defineConfig } from 'vite';
3
2
  import react from '@vitejs/plugin-react';
4
3
  import dts from 'vite-plugin-dts';
@@ -16,31 +15,21 @@ export default defineConfig(() => ({
16
15
  tsconfigPath: path.join(__dirname, 'tsconfig.lib.json')
17
16
  }),
18
17
  ],
19
- // Uncomment this if you are using workers.
20
- // worker: {
21
- // plugins: [ nxViteTsPaths() ],
22
- // },
23
- // Configuration for building your library.
24
- // See: https://vitejs.dev/guide/build.html#library-mode
25
18
  build: {
26
19
  outDir: './dist',
27
20
  emptyOutDir: true,
28
- minify: true,
21
+ minify: false,
29
22
  reportCompressedSize: true,
30
23
  commonjsOptions: {
31
24
  transformMixedEsModules: true,
32
25
  },
33
26
  lib: {
34
- // Could also be a dictionary or array of multiple entry points.
35
27
  entry: 'src/index.tsx',
36
28
  name: '@0xchain/pagination',
37
29
  fileName: 'index',
38
- // Change this to the formats you want to support.
39
- // Don't forget to update your package.json as well.
40
30
  formats: ['es' as const],
41
31
  },
42
32
  rollupOptions: {
43
- // External packages that should not be bundled into your library.
44
33
  external: [
45
34
  'react', 'react-dom', 'react/jsx-runtime', 'tailwind-merge', 'lucide-react', 'next-intl',
46
35
  /^@0xchain\/.+/,