v-page 3.0.0 → 3.1.0

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/README.md CHANGED
@@ -47,7 +47,7 @@ app.use(PaginationBar, {
47
47
  app.mount('#app')
48
48
  ```
49
49
 
50
- You can also use `v-page` as a locally component
50
+ Use `v-page` as a locally component
51
51
 
52
52
  ```vue
53
53
  <template>
@@ -70,15 +70,16 @@ import { PaginationBar } from 'v-page'
70
70
  />
71
71
  </template>
72
72
 
73
- <script setup>
73
+ <script setup lang='ts'>
74
74
  import { ref } from 'vue'
75
75
  import { PaginationBar } from 'v-page'
76
+ import type { PageInfo } from 'v-page/types'
76
77
  // set default page to 3
77
- const pageNumber = ref(3)
78
- const totalRow = ref(100)
78
+ const pageNumber = ref<number>(3)
79
+ const totalRow = ref<number>(100)
79
80
  // respond for pagination change
80
- function paginationChange (data) {
81
- console.log(data) // { pageNumber: 1, pageSize: 10 }
81
+ function paginationChange (data: PageInfo): void {
82
+ console.log(data) // { pageNumber: 1, pageSize: 10, totalPage: 10 }
82
83
  }
83
84
  </script>
84
85
  ```
package/dist/v-page.js CHANGED
@@ -1,13 +1,13 @@
1
1
  (function(){"use strict";try{if(typeof document<"u"){var i=document.createElement("style");i.appendChild(document.createTextNode(".v-pagination{display:flex;justify-content:flex-start;box-sizing:border-box}.v-pagination--right{justify-content:flex-end}.v-pagination--center{justify-content:center}.v-pagination.v-pagination--disabled a,.v-pagination.v-pagination--disabled select{color:#999!important}.v-pagination.v-pagination--disabled.v-pagination--border a,.v-pagination.v-pagination--disabled.v-pagination--border a:hover{background-color:#fafafa}.v-pagination ul{margin:0;padding:0;display:flex}.v-pagination ul li{list-style:none;display:flex}.v-pagination ul li.v-pagination__info a,.v-pagination ul li.v-pagination__list a{cursor:default;color:#333}.v-pagination ul li a{padding:.3rem .6rem;text-decoration:none;line-height:1.3;font-size:14px;margin:0;outline:0;color:#333;border-radius:.25rem;display:inline-flex;align-items:center}.v-pagination ul li:not(.active):not(.disabled):not(.v-pagination__list):not(.v-pagination__info):not(.v-pagination__slot) a:hover{background-color:#fafafa}.v-pagination ul li.active a{background-color:#eee;color:#aaa}.v-pagination ul li.disabled a{color:#999!important;cursor:default}.v-pagination ul li select{width:auto!important;font-size:12px;padding:0;outline:0;margin:0 0 0 5px;border:1px solid #ccc;color:#333;border-radius:.3rem}.v-pagination.v-pagination--border ul{box-shadow:0 1px 2px #0000000d;border-radius:.25rem}.v-pagination.v-pagination--border ul li:not(:first-child) a{margin-left:-1px}.v-pagination.v-pagination--border ul li a{border:1px solid #DEE2E6;border-radius:0}.v-pagination.v-pagination--border ul li:first-child>a{border-bottom-left-radius:.25rem;border-top-left-radius:.25rem}.v-pagination.v-pagination--border ul li:last-child>a{border-top-right-radius:.25rem;border-bottom-right-radius:.25rem}.v-pagination.v-pagination--border ul li.active a{color:#999;background-color:#eee}")),document.head.appendChild(i)}}catch(a){console.error("vite-plugin-css-injected-by-js",a)}})();
2
- import { defineComponent as F, toRefs as V, ref as N, computed as b, watch as k, onMounted as D, h as u } from "vue";
3
- const [
4
- O,
5
- z,
6
- T,
7
- G,
8
- Z
9
- ] = ["cn", "en", "de", "jp", "pt"], B = {
10
- [O]: {
2
+ import { defineComponent as U, toRefs as V, ref as P, computed as v, watch as x, onMounted as Z, h as o } from "vue";
3
+ const g = 1, k = 5, C = 10, F = [C, 20, 50, 100], G = 0, [ee, ae, H] = ["left", "center", "right"], [
4
+ J,
5
+ L,
6
+ q,
7
+ K,
8
+ Q
9
+ ] = ["cn", "en", "de", "jp", "pt"], I = {
10
+ [J]: {
11
11
  pageLength: "每页记录数 ",
12
12
  pageInfo: "当前显示第 #pageNumber# / #totalPage# 页(共#totalRow#条记录)",
13
13
  first: "首页",
@@ -16,7 +16,7 @@ const [
16
16
  last: "尾页",
17
17
  all: "全部"
18
18
  },
19
- [z]: {
19
+ [L]: {
20
20
  pageLength: "Page length ",
21
21
  pageInfo: "Current #pageNumber# / #totalPage# (total #totalRow# records)",
22
22
  first: "First",
@@ -25,7 +25,7 @@ const [
25
25
  last: "Last",
26
26
  all: "All"
27
27
  },
28
- [T]: {
28
+ [q]: {
29
29
  pageLength: "Seitenlänge ",
30
30
  pageInfo: "Aktuell #pageNumber# / #totalPage# (gesamt #totalRow# Aufzeichnungen)",
31
31
  first: "Zuerst",
@@ -34,7 +34,7 @@ const [
34
34
  last: "Letzte",
35
35
  all: "Alle"
36
36
  },
37
- [G]: {
37
+ [K]: {
38
38
  pageLength: "ページごとの記録数",
39
39
  pageInfo: "現在の第 #pageNumber# / #totalPage# ページ(全部で #totalRow# 条の記録)",
40
40
  first: "トップページ",
@@ -43,7 +43,7 @@ const [
43
43
  last: "尾のページ",
44
44
  all: "すべて"
45
45
  },
46
- [Z]: {
46
+ [Q]: {
47
47
  pageLength: "Resultados por página ",
48
48
  pageInfo: "#pageNumber# / #totalPage# (total de #totalRow#)",
49
49
  first: "Início",
@@ -52,37 +52,36 @@ const [
52
52
  last: "Fim",
53
53
  all: "Todos"
54
54
  }
55
- }, r = 1, J = 5, x = 10, q = [x, 20, 50, 100], I = 0;
56
- function H(e, s, t) {
57
- if (s <= t)
58
- return r;
59
- const v = Math.floor(t / 2), n = s - t + 1, o = e - v;
60
- return o < r ? r : o > n ? n : o;
55
+ };
56
+ function W(e, n, t) {
57
+ if (n <= t) return g;
58
+ const c = Math.floor(t / 2), s = n - t + 1, u = e - c;
59
+ return u < g ? g : u > s ? s : u;
60
+ }
61
+ function X(e, n, t) {
62
+ const c = W(e, n, t);
63
+ return Array.from({ length: t }).map((s, u) => c + u).filter((s) => s >= g && s <= n);
61
64
  }
62
- function K(e, s, t) {
63
- const v = H(e, s, t);
64
- return Array.from({ length: t }).map((n, o) => v + o).filter((n) => n >= r && n <= s);
65
+ function Y(e = L) {
66
+ const n = String(e).toLowerCase();
67
+ return n in I ? I[n] : I[L];
65
68
  }
66
- const R = F({
69
+ const A = U({
67
70
  name: "PaginationBar",
68
71
  props: {
69
72
  modelValue: { type: Number, default: 0 },
70
73
  totalRow: { type: Number, default: 0 },
71
- language: { type: String, default: z },
72
- /**
73
- * Page size list
74
- * false: close page size list
75
- * array: custom page sizes list
76
- */
77
- pageSizeMenu: {
78
- type: [Boolean, Array],
79
- default: () => q
80
- },
74
+ pageSize: { type: Number, default: C },
75
+ language: { type: String, default: L },
81
76
  /**
82
77
  * Pagination alignment direction
83
78
  * `left`, `center` and `right`(default)
84
79
  */
85
- align: { type: String, default: "right" },
80
+ align: { type: String, default: H },
81
+ /** Page size list */
82
+ pageSizeMenu: { type: [Array], default: () => F },
83
+ /** Display page size menu panel */
84
+ pageSizeOptions: { type: Boolean, default: !0 },
86
85
  disabled: { type: Boolean, default: !1 },
87
86
  border: { type: Boolean, default: !1 },
88
87
  info: { type: Boolean, default: !0 },
@@ -91,138 +90,142 @@ const R = F({
91
90
  first: { type: Boolean, default: !0 },
92
91
  /** last page button */
93
92
  last: { type: Boolean, default: !0 },
94
- /** display all records */
95
- displayAll: { type: Boolean, default: !1 }
93
+ /**
94
+ * Display all records
95
+ *
96
+ * will add `all` option in page size list
97
+ * and the page size will be 0
98
+ */
99
+ displayAll: { type: Boolean, default: !1 },
100
+ /** Hide pagination when only have one page */
101
+ hideOnSinglePage: { type: Boolean, default: !1 }
96
102
  },
97
- emits: ["update:modelValue", "change"],
98
- setup(e, { emit: s, slots: t, expose: v }) {
99
- const { pageSizeMenu: n, totalRow: o } = V(e), l = N(0), f = N(
100
- n.value === !1 ? x : n.value[0]
101
- ), _ = N(J), g = N(B[e.language] || B[z]), m = N(-1), p = b(() => f.value === I ? r : Math.ceil(o.value / f.value)), C = b(() => K(
103
+ emits: ["update:modelValue", "update:pageSize", "change"],
104
+ setup(e, { emit: n, slots: t, expose: c }) {
105
+ const { pageSizeOptions: s, pageSizeMenu: u, totalRow: b } = V(e), l = P(0), m = P(-1), S = P(k), f = Y(e.language), T = v(() => Array.isArray(u.value) && u.value.length > 0 ? u.value : F), p = P(e.pageSize || C), r = v(() => p.value === G ? g : Math.ceil(b.value / p.value)), B = v(() => X(
102
106
  l.value,
103
- p.value,
104
- _.value
105
- )), M = b(() => g.value.pageInfo.replace("#pageNumber#", l.value).replace("#totalPage#", p.value).replace("#totalRow#", o.value)), j = b(() => ({
107
+ r.value,
108
+ S.value
109
+ )), O = v(
110
+ () => f.pageInfo.replace("#pageNumber#", l.value).replace("#totalPage#", r.value).replace("#totalRow#", b.value)
111
+ ), D = v(() => ({
106
112
  "v-pagination": !0,
107
113
  "v-pagination--border": e.border,
108
114
  "v-pagination--right": e.align === "right",
109
115
  "v-pagination--center": e.align === "center",
110
116
  "v-pagination--disabled": e.disabled
111
- })), A = b(() => l.value === r), L = b(() => l.value === p.value);
112
- k(
113
- () => e.modelValue,
114
- (a) => {
115
- typeof a == "number" && a > 0 && h(a, !1);
116
- }
117
- );
118
- function h(a = r, P = !0) {
119
- if (e.disabled || typeof a != "number")
120
- return;
121
- let c = a < r ? r : a;
122
- a > p.value && p.value > 0 && (c = p.value), !(c === l.value && f.value === m.value) && (l.value = c, P && s("update:modelValue", l.value), m.value = f.value, w());
117
+ })), E = v(() => l.value === g), R = v(() => l.value === r.value);
118
+ x(() => e.modelValue, (a) => y(a)), x(() => e.pageSize, M);
119
+ function y(a = g) {
120
+ if (e.disabled || typeof a != "number") return;
121
+ let d = a < g ? g : a;
122
+ a > r.value && r.value > 0 && (d = r.value), !(d === l.value && p.value === m.value) && (l.value = d, m.value = p.value, w());
123
123
  }
124
124
  function w() {
125
- s("change", {
125
+ n("change", {
126
126
  pageNumber: l.value,
127
- pageSize: Number(f.value)
128
- });
127
+ pageSize: Number(p.value),
128
+ totalPage: r.value
129
+ }), n("update:modelValue", l.value), n("update:pageSize", p.value);
130
+ }
131
+ function M(a) {
132
+ a < 0 || a !== p.value && (p.value = a, y());
129
133
  }
130
- function y(a, P, c) {
131
- return u("li", { class: a }, [u("a", {
134
+ function _(a, d, z) {
135
+ return o("li", { class: a }, [o("a", {
132
136
  href: "javascript:void(0)",
133
- onClick: () => h(P)
134
- }, c)]);
137
+ onClick: () => y(d)
138
+ }, z)]);
135
139
  }
136
- return D(() => {
137
- h(e.modelValue || r);
138
- }), v({
140
+ return Z(() => {
141
+ y(e.modelValue || g);
142
+ }), c({
143
+ goPage: y,
139
144
  current: l,
140
- totalPage: p,
141
- pageNumbers: C,
142
- goPage: h,
145
+ totalPage: r,
146
+ pageNumbers: B,
143
147
  reload: w
144
148
  }), () => {
149
+ if (e.hideOnSinglePage && r.value <= 1) return;
145
150
  const a = [];
146
- if (Array.isArray(n.value) && n.value.length) {
151
+ if (s.value) {
147
152
  const i = {
148
153
  disabled: e.disabled,
149
- onChange: (S) => {
150
- f.value = Number(S.target.value), h();
151
- }
152
- }, d = n.value.map(
153
- (S) => u("option", { value: S }, S)
154
+ onChange: (N) => M(Number(N.target.value))
155
+ }, h = T.value.map(
156
+ (N) => o("option", { value: N }, N)
154
157
  );
155
- e.displayAll && d.push(
156
- u("option", { value: I }, g.value.all)
158
+ e.displayAll && h.push(
159
+ o("option", { value: G }, f.all)
157
160
  );
158
- const E = u("li", { class: "v-pagination__list" }, [
159
- u("a", { href: "javascript:void(0)" }, [
160
- u("span", g.value.pageLength),
161
- u("select", i, d)
161
+ const j = o("li", { class: "v-pagination__list" }, [
162
+ o("a", { href: "javascript:void(0)" }, [
163
+ o("span", f.pageLength),
164
+ o("select", i, h)
162
165
  ])
163
166
  ]);
164
- a.push(E);
167
+ a.push(j);
165
168
  }
166
169
  if (e.info && a.push(
167
- u("li", { class: "v-pagination__info" }, [
168
- u("a", { href: "javascript:void(0)" }, M.value)
170
+ o("li", { class: "v-pagination__info" }, [
171
+ o("a", { href: "javascript:void(0)" }, O.value)
169
172
  ])
170
173
  ), "default" in t) {
171
174
  const i = {
172
175
  pageNumber: l.value,
173
- pageSize: f.value,
174
- totalPage: p.value,
175
- totalRow: o.value,
176
- isFirst: A.value,
177
- isLast: L.value
178
- }, d = u("li", { class: "v-pagination__slot" }, [
179
- u("a", t.default(i))
176
+ pageSize: p.value,
177
+ totalPage: r.value,
178
+ totalRow: b.value,
179
+ isFirst: E.value,
180
+ isLast: R.value
181
+ }, h = o("li", { class: "v-pagination__slot" }, [
182
+ o("a", t.default(i))
180
183
  ]);
181
- a.push(d);
184
+ a.push(h);
182
185
  }
183
186
  if (e.first) {
184
- const i = ["v-pagination__first", { disabled: A.value }];
185
- a.push(y(i, r, g.value.first));
187
+ const i = ["v-pagination__first", { disabled: E.value }];
188
+ a.push(_(i, g, f.first));
186
189
  }
187
- const P = ["v-pagination__previous", { disabled: A.value }];
190
+ const d = ["v-pagination__previous", { disabled: E.value }];
188
191
  a.push(
189
- y(P, l.value - 1, g.value.previous)
192
+ _(d, l.value - 1, f.previous)
190
193
  ), e.pageNumber && a.push(
191
- ...C.value.map((i) => {
192
- const d = { active: i === l.value };
193
- return y(d, i, i);
194
+ ...B.value.map((i) => {
195
+ const h = { active: i === l.value };
196
+ return _(h, i, i);
194
197
  })
195
198
  );
196
- const c = ["v-pagination__next", { disabled: L.value }];
199
+ const z = ["v-pagination__next", { disabled: R.value }];
197
200
  if (a.push(
198
- y(c, l.value + 1, g.value.next)
201
+ _(z, l.value + 1, f.next)
199
202
  ), e.last) {
200
- const i = ["v-pagination__last", { disabled: L.value }];
203
+ const i = ["v-pagination__last", { disabled: R.value }];
201
204
  a.push(
202
- y(i, p.value, g.value.last)
205
+ _(i, r.value, f.last)
203
206
  );
204
207
  }
205
- return u("div", { class: j.value }, [u("ul", a)]);
208
+ return o("div", { class: D.value }, [o("ul", a)]);
206
209
  };
207
210
  }
208
211
  });
209
- R.install = (e, s = {}) => {
210
- if (Object.keys(s).length) {
211
- const { props: t } = R, {
212
- language: v,
213
- align: n,
214
- info: o,
215
- border: l,
216
- pageNumber: f,
217
- first: _,
218
- last: g,
219
- pageSizeMenu: m
220
- } = s;
221
- v && (t.language.default = v), n && (t.align.default = n), typeof o == "boolean" && (t.info.default = o), typeof l == "boolean" && (t.border.default = l), typeof f == "boolean" && (t.pageNumber.default = f), typeof _ == "boolean" && (t.first.default = _), typeof g == "boolean" && (t.last.default = g), typeof m < "u" && (t.pageSizeMenu.default = m);
212
+ A.install = (e, n = {}) => {
213
+ if (Object.keys(n).length) {
214
+ const { props: t } = A, {
215
+ language: c,
216
+ align: s,
217
+ info: u,
218
+ border: b,
219
+ pageNumber: l,
220
+ first: m,
221
+ last: S,
222
+ pageSizeMenu: f
223
+ } = n;
224
+ c && (t.language.default = c), s && (t.align.default = s), typeof u == "boolean" && (t.info.default = u), typeof b == "boolean" && (t.border.default = b), typeof l == "boolean" && (t.pageNumber.default = l), typeof m == "boolean" && (t.first.default = m), typeof S == "boolean" && (t.last.default = S), typeof f < "u" && (t.pageSizeMenu.default = f);
222
225
  }
223
- e.component(R.name, R);
226
+ e.component(A.name, A);
224
227
  };
225
228
  export {
226
- R as PaginationBar,
227
- R as default
229
+ A as PaginationBar,
230
+ A as default
228
231
  };
@@ -1,2 +1,2 @@
1
1
  (function(){"use strict";try{if(typeof document<"u"){var i=document.createElement("style");i.appendChild(document.createTextNode(".v-pagination{display:flex;justify-content:flex-start;box-sizing:border-box}.v-pagination--right{justify-content:flex-end}.v-pagination--center{justify-content:center}.v-pagination.v-pagination--disabled a,.v-pagination.v-pagination--disabled select{color:#999!important}.v-pagination.v-pagination--disabled.v-pagination--border a,.v-pagination.v-pagination--disabled.v-pagination--border a:hover{background-color:#fafafa}.v-pagination ul{margin:0;padding:0;display:flex}.v-pagination ul li{list-style:none;display:flex}.v-pagination ul li.v-pagination__info a,.v-pagination ul li.v-pagination__list a{cursor:default;color:#333}.v-pagination ul li a{padding:.3rem .6rem;text-decoration:none;line-height:1.3;font-size:14px;margin:0;outline:0;color:#333;border-radius:.25rem;display:inline-flex;align-items:center}.v-pagination ul li:not(.active):not(.disabled):not(.v-pagination__list):not(.v-pagination__info):not(.v-pagination__slot) a:hover{background-color:#fafafa}.v-pagination ul li.active a{background-color:#eee;color:#aaa}.v-pagination ul li.disabled a{color:#999!important;cursor:default}.v-pagination ul li select{width:auto!important;font-size:12px;padding:0;outline:0;margin:0 0 0 5px;border:1px solid #ccc;color:#333;border-radius:.3rem}.v-pagination.v-pagination--border ul{box-shadow:0 1px 2px #0000000d;border-radius:.25rem}.v-pagination.v-pagination--border ul li:not(:first-child) a{margin-left:-1px}.v-pagination.v-pagination--border ul li a{border:1px solid #DEE2E6;border-radius:0}.v-pagination.v-pagination--border ul li:first-child>a{border-bottom-left-radius:.25rem;border-top-left-radius:.25rem}.v-pagination.v-pagination--border ul li:last-child>a{border-top-right-radius:.25rem;border-bottom-right-radius:.25rem}.v-pagination.v-pagination--border ul li.active a{color:#999;background-color:#eee}")),document.head.appendChild(i)}}catch(a){console.error("vite-plugin-css-injected-by-js",a)}})();
2
- (function(p,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(p=typeof globalThis<"u"?globalThis:p||self,e(p.VPage={},p.Vue))})(this,function(p,e){"use strict";const Z="",[M,R,x,j,V]=["cn","en","de","jp","pt"],z={[M]:{pageLength:"每页记录数 ",pageInfo:"当前显示第 #pageNumber# / #totalPage# 页(共#totalRow#条记录)",first:"首页",previous:"«",next:"»",last:"尾页",all:"全部"},[R]:{pageLength:"Page length ",pageInfo:"Current #pageNumber# / #totalPage# (total #totalRow# records)",first:"First",previous:"«",next:"»",last:"Last",all:"All"},[x]:{pageLength:"Seitenlänge ",pageInfo:"Aktuell #pageNumber# / #totalPage# (gesamt #totalRow# Aufzeichnungen)",first:"Zuerst",previous:"«",next:"»",last:"Letzte",all:"Alle"},[j]:{pageLength:"ページごとの記録数",pageInfo:"現在の第 #pageNumber# / #totalPage# ページ(全部で #totalRow# 条の記録)",first:"トップページ",previous:"«",next:"»",last:"尾のページ",all:"すべて"},[V]:{pageLength:"Resultados por página ",pageInfo:"#pageNumber# / #totalPage# (total de #totalRow#)",first:"Início",previous:"<",next:">",last:"Fim",all:"Todos"}},s=1,T=5,B=10,E=[B,20,50,100],C=0;function F(a,r,l){if(r<=l)return s;const c=Math.floor(l/2),o=r-l+1,u=a-c;return u<s?s:u>o?o:u}function O(a,r,l){const c=F(a,r,l);return Array.from({length:l}).map((o,u)=>c+u).filter(o=>o>=s&&o<=r)}const h=e.defineComponent({name:"PaginationBar",props:{modelValue:{type:Number,default:0},totalRow:{type:Number,default:0},language:{type:String,default:R},pageSizeMenu:{type:[Boolean,Array],default:()=>E},align:{type:String,default:"right"},disabled:{type:Boolean,default:!1},border:{type:Boolean,default:!1},info:{type:Boolean,default:!0},pageNumber:{type:Boolean,default:!0},first:{type:Boolean,default:!0},last:{type:Boolean,default:!0},displayAll:{type:Boolean,default:!1}},emits:["update:modelValue","change"],setup(a,{emit:r,slots:l,expose:c}){const{pageSizeMenu:o,totalRow:u}=e.toRefs(a),n=e.ref(0),f=e.ref(o.value===!1?B:o.value[0]),N=e.ref(T),g=e.ref(z[a.language]||z[R]),m=e.ref(-1),d=e.computed(()=>f.value===C?s:Math.ceil(u.value/f.value)),w=e.computed(()=>O(n.value,d.value,N.value)),k=e.computed(()=>g.value.pageInfo.replace("#pageNumber#",n.value).replace("#totalPage#",d.value).replace("#totalRow#",u.value)),D=e.computed(()=>({"v-pagination":!0,"v-pagination--border":a.border,"v-pagination--right":a.align==="right","v-pagination--center":a.align==="center","v-pagination--disabled":a.disabled})),A=e.computed(()=>n.value===s),L=e.computed(()=>n.value===d.value);e.watch(()=>a.modelValue,t=>{typeof t=="number"&&t>0&&y(t,!1)});function y(t=s,_=!0){if(a.disabled||typeof t!="number")return;let v=t<s?s:t;t>d.value&&d.value>0&&(v=d.value),!(v===n.value&&f.value===m.value)&&(n.value=v,_&&r("update:modelValue",n.value),m.value=f.value,I())}function I(){r("change",{pageNumber:n.value,pageSize:Number(f.value)})}function P(t,_,v){const i={href:"javascript:void(0)",onClick:()=>y(_)};return e.h("li",{class:t},[e.h("a",i,v)])}return e.onMounted(()=>{y(a.modelValue||s)}),c({current:n,totalPage:d,pageNumbers:w,goPage:y,reload:I}),()=>{const t=[];if(Array.isArray(o.value)&&o.value.length){const i={disabled:a.disabled,onChange:S=>{f.value=Number(S.target.value),y()}},b=o.value.map(S=>e.h("option",{value:S},S));a.displayAll&&b.push(e.h("option",{value:C},g.value.all));const G=e.h("li",{class:"v-pagination__list"},[e.h("a",{href:"javascript:void(0)"},[e.h("span",g.value.pageLength),e.h("select",i,b)])]);t.push(G)}if(a.info&&t.push(e.h("li",{class:"v-pagination__info"},[e.h("a",{href:"javascript:void(0)"},k.value)])),"default"in l){const i={pageNumber:n.value,pageSize:f.value,totalPage:d.value,totalRow:u.value,isFirst:A.value,isLast:L.value},b=e.h("li",{class:"v-pagination__slot"},[e.h("a",l.default(i))]);t.push(b)}if(a.first){const i=["v-pagination__first",{disabled:A.value}];t.push(P(i,s,g.value.first))}const _=["v-pagination__previous",{disabled:A.value}];t.push(P(_,n.value-1,g.value.previous)),a.pageNumber&&t.push(...w.value.map(i=>{const b={active:i===n.value};return P(b,i,i)}));const v=["v-pagination__next",{disabled:L.value}];if(t.push(P(v,n.value+1,g.value.next)),a.last){const i=["v-pagination__last",{disabled:L.value}];t.push(P(i,d.value,g.value.last))}return e.h("div",{class:D.value},[e.h("ul",t)])}}});h.install=(a,r={})=>{if(Object.keys(r).length){const{props:l}=h,{language:c,align:o,info:u,border:n,pageNumber:f,first:N,last:g,pageSizeMenu:m}=r;c&&(l.language.default=c),o&&(l.align.default=o),typeof u=="boolean"&&(l.info.default=u),typeof n=="boolean"&&(l.border.default=n),typeof f=="boolean"&&(l.pageNumber.default=f),typeof N=="boolean"&&(l.first.default=N),typeof g=="boolean"&&(l.last.default=g),typeof m<"u"&&(l.pageSizeMenu.default=m)}a.component(h.name,h)},p.PaginationBar=h,p.default=h,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
2
+ (function(p,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(p=typeof globalThis<"u"?globalThis:p||self,e(p.VPage={},p.Vue))})(this,function(p,e){"use strict";const L=[10,20,50,100],N=0,[K,Q,C]=["left","center","right"],[G,y,M,w,D]=["cn","en","de","jp","pt"],P={[G]:{pageLength:"每页记录数 ",pageInfo:"当前显示第 #pageNumber# / #totalPage# 页(共#totalRow#条记录)",first:"首页",previous:"«",next:"»",last:"尾页",all:"全部"},[y]:{pageLength:"Page length ",pageInfo:"Current #pageNumber# / #totalPage# (total #totalRow# records)",first:"First",previous:"«",next:"»",last:"Last",all:"All"},[M]:{pageLength:"Seitenlänge ",pageInfo:"Aktuell #pageNumber# / #totalPage# (gesamt #totalRow# Aufzeichnungen)",first:"Zuerst",previous:"«",next:"»",last:"Letzte",all:"Alle"},[w]:{pageLength:"ページごとの記録数",pageInfo:"現在の第 #pageNumber# / #totalPage# ページ(全部で #totalRow# 条の記録)",first:"トップページ",previous:"«",next:"»",last:"尾のページ",all:"すべて"},[D]:{pageLength:"Resultados por página ",pageInfo:"#pageNumber# / #totalPage# (total de #totalRow#)",first:"Início",previous:"<",next:">",last:"Fim",all:"Todos"}};function U(a,o,n){if(o<=n)return 1;const d=Math.floor(n/2),s=o-n+1,u=a-d;return u<1?1:u>s?s:u}function x(a,o,n){const d=U(a,o,n);return Array.from({length:n}).map((s,u)=>d+u).filter(s=>s>=1&&s<=o)}function Z(a=y){const o=String(a).toLowerCase();return o in P?P[o]:P[y]}const h=e.defineComponent({name:"PaginationBar",props:{modelValue:{type:Number,default:0},totalRow:{type:Number,default:0},pageSize:{type:Number,default:10},language:{type:String,default:y},align:{type:String,default:C},pageSizeMenu:{type:[Array],default:()=>L},pageSizeOptions:{type:Boolean,default:!0},disabled:{type:Boolean,default:!1},border:{type:Boolean,default:!1},info:{type:Boolean,default:!0},pageNumber:{type:Boolean,default:!0},first:{type:Boolean,default:!0},last:{type:Boolean,default:!0},displayAll:{type:Boolean,default:!1},hideOnSinglePage:{type:Boolean,default:!1}},emits:["update:modelValue","update:pageSize","change"],setup(a,{emit:o,slots:n,expose:d}){const{pageSizeOptions:s,pageSizeMenu:u,totalRow:v}=e.toRefs(a),l=e.ref(0),S=e.ref(-1),E=e.ref(5),f=Z(a.language),O=e.computed(()=>Array.isArray(u.value)&&u.value.length>0?u.value:L),g=e.ref(a.pageSize||10),r=e.computed(()=>g.value===N?1:Math.ceil(v.value/g.value)),F=e.computed(()=>x(l.value,r.value,E.value)),j=e.computed(()=>f.pageInfo.replace("#pageNumber#",l.value).replace("#totalPage#",r.value).replace("#totalRow#",v.value)),V=e.computed(()=>({"v-pagination":!0,"v-pagination--border":a.border,"v-pagination--right":a.align==="right","v-pagination--center":a.align==="center","v-pagination--disabled":a.disabled})),R=e.computed(()=>l.value===1),A=e.computed(()=>l.value===r.value);e.watch(()=>a.modelValue,t=>b(t)),e.watch(()=>a.pageSize,B);function b(t=1){if(a.disabled||typeof t!="number")return;let c=t<1?1:t;t>r.value&&r.value>0&&(c=r.value),!(c===l.value&&g.value===S.value)&&(l.value=c,S.value=g.value,z())}function z(){o("change",{pageNumber:l.value,pageSize:Number(g.value),totalPage:r.value}),o("update:modelValue",l.value),o("update:pageSize",g.value)}function B(t){t<0||t!==g.value&&(g.value=t,b())}function _(t,c,T){const i={href:"javascript:void(0)",onClick:()=>b(c)};return e.h("li",{class:t},[e.h("a",i,T)])}return e.onMounted(()=>{b(a.modelValue||1)}),d({goPage:b,current:l,totalPage:r,pageNumbers:F,reload:z}),()=>{if(a.hideOnSinglePage&&r.value<=1)return;const t=[];if(s.value){const i={disabled:a.disabled,onChange:I=>B(Number(I.target.value))},m=O.value.map(I=>e.h("option",{value:I},I));a.displayAll&&m.push(e.h("option",{value:N},f.all));const k=e.h("li",{class:"v-pagination__list"},[e.h("a",{href:"javascript:void(0)"},[e.h("span",f.pageLength),e.h("select",i,m)])]);t.push(k)}if(a.info&&t.push(e.h("li",{class:"v-pagination__info"},[e.h("a",{href:"javascript:void(0)"},j.value)])),"default"in n){const i={pageNumber:l.value,pageSize:g.value,totalPage:r.value,totalRow:v.value,isFirst:R.value,isLast:A.value},m=e.h("li",{class:"v-pagination__slot"},[e.h("a",n.default(i))]);t.push(m)}if(a.first){const i=["v-pagination__first",{disabled:R.value}];t.push(_(i,1,f.first))}const c=["v-pagination__previous",{disabled:R.value}];t.push(_(c,l.value-1,f.previous)),a.pageNumber&&t.push(...F.value.map(i=>{const m={active:i===l.value};return _(m,i,i)}));const T=["v-pagination__next",{disabled:A.value}];if(t.push(_(T,l.value+1,f.next)),a.last){const i=["v-pagination__last",{disabled:A.value}];t.push(_(i,r.value,f.last))}return e.h("div",{class:V.value},[e.h("ul",t)])}}});h.install=(a,o={})=>{if(Object.keys(o).length){const{props:n}=h,{language:d,align:s,info:u,border:v,pageNumber:l,first:S,last:E,pageSizeMenu:f}=o;d&&(n.language.default=d),s&&(n.align.default=s),typeof u=="boolean"&&(n.info.default=u),typeof v=="boolean"&&(n.border.default=v),typeof l=="boolean"&&(n.pageNumber.default=l),typeof S=="boolean"&&(n.first.default=S),typeof E=="boolean"&&(n.last.default=E),typeof f<"u"&&(n.pageSizeMenu.default=f)}a.component(h.name,h)},p.PaginationBar=h,p.default=h,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "v-page",
3
3
  "description": "A simple pagination bar",
4
- "version": "3.0.0",
4
+ "version": "3.1.0",
5
5
  "author": "TerryZ <terry5@foxmail.com>",
6
6
  "type": "module",
7
7
  "files": [
@@ -47,27 +47,27 @@
47
47
  "pagination"
48
48
  ],
49
49
  "peerDependencies": {
50
- "vue": "^3.2.0"
50
+ "vue": "^3.4.0"
51
51
  },
52
52
  "dependencies": {
53
- "vue": "^3.3.4"
53
+ "vue": "^3.4.29"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@rushstack/eslint-patch": "^1.3.3",
57
- "@vitejs/plugin-vue": "^4.3.4",
58
- "@vitejs/plugin-vue-jsx": "^3.0.2",
57
+ "@vitejs/plugin-vue": "^5.0.5",
58
+ "@vitejs/plugin-vue-jsx": "^4.0.0",
59
+ "@vitest/coverage-v8": "^1.6.0",
59
60
  "@vue/eslint-config-standard": "^8.0.1",
60
- "@vue/test-utils": "^2.4.1",
61
- "bootstrap": "^5.3.1",
62
- "c8": "^8.0.1",
61
+ "@vue/test-utils": "^2.4.6",
62
+ "bootstrap": "^5.3.3",
63
63
  "eslint": "^8.49.0",
64
64
  "eslint-plugin-vue": "^9.17.0",
65
- "jsdom": "^22.1.0",
65
+ "jsdom": "^24.1.0",
66
66
  "sass": "^1.66.1",
67
67
  "sass-loader": "^13.3.2",
68
- "typescript": "^5.2.2",
69
- "vite": "^4.4.9",
70
- "vite-plugin-css-injected-by-js": "^3.3.0",
71
- "vitest": "^0.34.4"
68
+ "typescript": "^5.5.2",
69
+ "vite": "^5.3.1",
70
+ "vite-plugin-css-injected-by-js": "^3.5.1",
71
+ "vitest": "^1.6.0"
72
72
  }
73
73
  }
package/types/index.d.ts CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  export declare interface PageInfo {
9
9
  pageNumber: number
10
10
  pageSize: number
11
+ totalPage: number
11
12
  }
12
13
 
13
14
  export declare interface PageSlotData {
@@ -31,6 +32,11 @@ declare interface Props {
31
32
  * The number of total record
32
33
  */
33
34
  totalRow: number
35
+ /**
36
+ * The number of page size
37
+ * @default 10
38
+ */
39
+ pageSize?: number
34
40
  /**
35
41
  * v-page language
36
42
  * @default `en`
@@ -40,7 +46,12 @@ declare interface Props {
40
46
  * Page size list
41
47
  * @default [10, 20, 50, 100]
42
48
  */
43
- pageSizeMenu?: boolean|number[]
49
+ pageSizeMenu?: number[]
50
+ /**
51
+ * Whether to display page size list panel
52
+ * @default true
53
+ */
54
+ pageSizeOptions?: boolean
44
55
  /**
45
56
  * Alignment direction
46
57
  * @default `right`
@@ -81,14 +92,19 @@ declare interface Props {
81
92
  * @default false
82
93
  */
83
94
  displayAll?: boolean
95
+ /**
96
+ * Hide pagination when only have one page
97
+ * @default false
98
+ */
99
+ hideOnSinglePage?: boolean
84
100
  }
85
101
 
86
- declare interface Emits {
87
- /** Update pageNumber value */
88
- 'onUpdate:modelValue'?: (pageNumber: number) => void
89
- /** The event respond pageNumber or pageSize change */
90
- onChange?: (data: PageInfo) => void
91
- }
102
+ // declare interface Emits {
103
+ // /** Update pageNumber value */
104
+ // 'onUpdate:modelValue'?: (pageNumber: number) => void
105
+ // /** The event respond pageNumber or pageSize change */
106
+ // onChange?: (data: PageInfo) => void
107
+ // }
92
108
 
93
109
  // declare interface Methods extends MethodOptions {
94
110
  // /** Go to the specified page */
@@ -96,10 +112,17 @@ declare interface Emits {
96
112
  // /** Re-emit `change` event and output pagination states data */
97
113
  // reload: () => void
98
114
  // }
115
+ // $emit: ((event: "update:modelValue", value: boolean) => void) & ((event: "click:close", e: MouseEvent) => void)
116
+
117
+ /** Update pageNumber value */
118
+ type EmitUpdateModelValue = (event: "update:modelValue", value: number) => void
119
+ /** The event respond pageNumber or pageSize change */
120
+ type EmitChange = (event: "change", value: PageInfo) => void
99
121
 
100
122
  declare interface PaginationBar {
101
123
  new (): {
102
- $props: AllowedComponentProps & ComponentCustomProps & VNodeProps & Props & Emits
124
+ $props: AllowedComponentProps & ComponentCustomProps & VNodeProps & Props
125
+ $emit: EmitUpdateModelValue & EmitChange
103
126
  $slots: {
104
127
  default?: (defaultSlotData: PageSlotData) => VNode[]
105
128
  }