v-page 3.0.0-beta.4 → 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
@@ -1,11 +1,18 @@
1
1
  # [v-page](https://terryz.github.io/vue/#/page) · [![CircleCI](https://dl.circleci.com/status-badge/img/gh/TerryZ/v-page/tree/master.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/TerryZ/v-page/tree/master) [![code coverage](https://codecov.io/gh/TerryZ/v-page/branch/master/graph/badge.svg)](https://codecov.io/gh/TerryZ/v-page) [![npm version](https://img.shields.io/npm/v/v-page.svg)](https://www.npmjs.com/package/v-page) [![license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://mit-license.org/) [![npm download](https://img.shields.io/npm/dy/v-page.svg)](https://www.npmjs.com/package/v-page) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
2
2
 
3
- A simple pagination bar for vue3, including size Menu, i18n support
3
+ A simple pagination bar for vue3, including size Menu, i18n support features
4
4
 
5
5
  <img src="https://terryz.github.io/image/v-page/v-page.png" alt="v-page" height="54px">
6
6
 
7
7
  If you are using vue `2.x` version, please use [v-page 2.x](https://github.com/TerryZ/v-page/tree/dev-vue-2) version instead
8
8
 
9
+ <!-- ## Features
10
+
11
+ - Simple interface style
12
+ - I18n supported
13
+ - Modularization of Pagination bar features
14
+ - -->
15
+
9
16
  ## Examples and Documentation
10
17
 
11
18
  Documentation and examples and please visit below sites
@@ -28,27 +35,27 @@ pnpm add v-page
28
35
  Include and install plugin in your `main.js` file
29
36
 
30
37
  ```js
31
- // add component in global scope as plugin
32
38
  import { createApp } from 'vue'
33
39
  import App from './app.vue'
34
- import Page from 'v-page'
40
+ import { PaginationBar } from 'v-page'
35
41
 
36
42
  const app = createApp(App)
37
- app.use(Page, {
43
+ // install component globally
44
+ app.use(PaginationBar, {
38
45
  // globally config options
39
46
  })
40
47
  app.mount('#app')
41
48
  ```
42
49
 
43
- You also can use `v-page` in local component
50
+ Use `v-page` as a locally component
44
51
 
45
52
  ```vue
46
53
  <template>
47
- <Page />
54
+ <PaginationBar />
48
55
  </template>
49
56
 
50
57
  <script setup>
51
- import { Page } from 'v-page'
58
+ import { PaginationBar } from 'v-page'
52
59
  </script>
53
60
  ```
54
61
 
@@ -56,21 +63,23 @@ import { Page } from 'v-page'
56
63
 
57
64
  ```vue
58
65
  <template>
59
- <v-page
66
+ <PaginationBar
60
67
  v-model="pageNumber"
61
68
  :total-row="totalRow"
62
- @change="pageChange"
69
+ @change="paginationChange"
63
70
  />
64
71
  </template>
65
72
 
66
- <script setup>
73
+ <script setup lang='ts'>
67
74
  import { ref } from 'vue'
68
-
69
- const pageNumber = ref(3)
70
- const totalRow = ref(100)
75
+ import { PaginationBar } from 'v-page'
76
+ import type { PageInfo } from 'v-page/types'
77
+ // set default page to 3
78
+ const pageNumber = ref<number>(3)
79
+ const totalRow = ref<number>(100)
71
80
  // respond for pagination change
72
- function pageChange (data) {
73
- console.log(pInfo) // { pageNumber: 1, pageSize: 10 }
81
+ function paginationChange (data: PageInfo): void {
82
+ console.log(data) // { pageNumber: 1, pageSize: 10, totalPage: 10 }
74
83
  }
75
84
  </script>
76
85
  ```
package/dist/v-page.js CHANGED
@@ -1,13 +1,13 @@
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 ul{margin:0;padding:0;display:flex}.v-pagination ul li{list-style:none;display:flex}.v-pagination ul li a{padding:.3rem .6rem;text-decoration:none;pointer-events:none;line-height:1.3;font-size:14px;margin:0;outline:0;color:#333;border-radius:.25rem}.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;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:2px}.v-pagination ul li select:hover[disabled]{color:#999}.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(o){console.error("vite-plugin-css-injected-by-js",o)}})();
2
- import { defineComponent as F, toRefs as j, ref as P, computed as c, watch as k, onMounted as O, h as u } from "vue";
3
- const [
4
- z,
5
- T,
6
- D,
7
- G,
8
- Z
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 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
9
  ] = ["cn", "en", "de", "jp", "pt"], I = {
10
- [z]: {
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
- [T]: {
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
- [D]: {
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, B = 10, q = [B, 20, 50, 100], x = 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({
67
- name: "VPage",
69
+ const A = U({
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,139 +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 } = j(e), l = P(0), f = P(
100
- n.value === !1 ? B : n.value[0]
101
- ), N = P(J), g = P(I[e.language] || I[z]), b = P(-1), p = c(() => f.value === x ? r : Math.ceil(o.value / f.value)), C = c(() => 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
- N.value
105
- )), M = c(() => g.value.pageInfo.replace("#pageNumber#", l.value).replace("#totalPage#", p.value).replace("#totalRow#", o.value)), V = c(() => ({
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 = c(() => l.value === r), L = c(() => l.value === p.value);
112
- k(
113
- () => e.modelValue,
114
- (a) => {
115
- typeof a == "number" && a > 0 && m(a, !1);
116
- }
117
- );
118
- function m(a = r, y = !0) {
119
- if (e.disabled || typeof a != "number")
120
- return;
121
- let d = a < r ? r : a;
122
- a > p.value && p.value > 0 && (d = p.value), !(d === l.value && f.value === b.value) && (l.value = d, y && s("update:modelValue", l.value), b.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);
129
130
  }
130
- function h(a, y, d) {
131
- return u("li", { class: a }, [u("a", {
131
+ function M(a) {
132
+ a < 0 || a !== p.value && (p.value = a, y());
133
+ }
134
+ function _(a, d, z) {
135
+ return o("li", { class: a }, [o("a", {
132
136
  href: "javascript:void(0)",
133
- onClick: () => m(y)
134
- }, d)]);
137
+ onClick: () => y(d)
138
+ }, z)]);
135
139
  }
136
- return O(() => {
137
- m(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: m,
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), m();
151
- }
152
- }, _ = 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 && _.push(
156
- u("option", { value: x }, 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", [
160
- u("span", g.value.pageLength),
161
- u("select", i, _)
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" }, [u("a", M.value)])
170
+ o("li", { class: "v-pagination__info" }, [
171
+ o("a", { href: "javascript:void(0)" }, O.value)
172
+ ])
168
173
  ), "default" in t) {
169
- const i = u("li", { class: "v-pagination__slot" }, [
170
- u(
171
- "a",
172
- t.default({
173
- pageNumber: l.value,
174
- pageSize: f.value,
175
- totalPage: p.value,
176
- totalRow: o.value,
177
- isFirst: A.value,
178
- isLast: L.value
179
- })
180
- )
174
+ const i = {
175
+ pageNumber: l.value,
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))
181
183
  ]);
182
- a.push(i);
184
+ a.push(h);
183
185
  }
184
186
  if (e.first) {
185
- const i = ["v-pagination__first", { disabled: A.value }];
186
- a.push(h(i, r, g.value.first));
187
+ const i = ["v-pagination__first", { disabled: E.value }];
188
+ a.push(_(i, g, f.first));
187
189
  }
188
- const y = ["v-pagination__previous", { disabled: A.value }];
190
+ const d = ["v-pagination__previous", { disabled: E.value }];
189
191
  a.push(
190
- h(y, l.value - 1, g.value.previous)
192
+ _(d, l.value - 1, f.previous)
191
193
  ), e.pageNumber && a.push(
192
- ...C.value.map((i) => {
193
- const _ = { active: i === l.value };
194
- return h(_, i, i);
194
+ ...B.value.map((i) => {
195
+ const h = { active: i === l.value };
196
+ return _(h, i, i);
195
197
  })
196
198
  );
197
- const d = ["v-pagination__next", { disabled: L.value }];
199
+ const z = ["v-pagination__next", { disabled: R.value }];
198
200
  if (a.push(
199
- h(d, l.value + 1, g.value.next)
201
+ _(z, l.value + 1, f.next)
200
202
  ), e.last) {
201
- const i = ["v-pagination__last", { disabled: L.value }];
203
+ const i = ["v-pagination__last", { disabled: R.value }];
202
204
  a.push(
203
- h(i, p.value, g.value.last)
205
+ _(i, r.value, f.last)
204
206
  );
205
207
  }
206
- return u("div", { class: V.value }, [u("ul", a)]);
208
+ return o("div", { class: D.value }, [o("ul", a)]);
207
209
  };
208
210
  }
209
211
  });
210
- R.install = (e, s = {}) => {
211
- if (Object.keys(s).length) {
212
- const { props: t } = R, {
213
- language: v,
214
- align: n,
215
- info: o,
216
- border: l,
217
- pageNumber: f,
218
- first: N,
219
- last: g,
220
- pageSizeMenu: b
221
- } = s;
222
- 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 N == "boolean" && (t.first.default = N), typeof g == "boolean" && (t.last.default = g), typeof b < "u" && (t.pageSizeMenu.default = b);
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);
223
225
  }
224
- e.component(R.name, R);
226
+ e.component(A.name, A);
225
227
  };
226
228
  export {
227
- R as Page,
228
- R as default
229
+ A as PaginationBar,
230
+ A as default
229
231
  };
@@ -1,2 +1,2 @@
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 ul{margin:0;padding:0;display:flex}.v-pagination ul li{list-style:none;display:flex}.v-pagination ul li a{padding:.3rem .6rem;text-decoration:none;pointer-events:none;line-height:1.3;font-size:14px;margin:0;outline:0;color:#333;border-radius:.25rem}.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;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:2px}.v-pagination ul li select:hover[disabled]{color:#999}.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(o){console.error("vite-plugin-css-injected-by-js",o)}})();
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="",[R,x,B,V,T]=["cn","en","de","jp","pt"],z={[R]:{pageLength:"每页记录数 ",pageInfo:"当前显示第 #pageNumber# / #totalPage# 页(共#totalRow#条记录)",first:"首页",previous:"«",next:"»",last:"尾页",all:"全部"},[x]:{pageLength:"Page length ",pageInfo:"Current #pageNumber# / #totalPage# (total #totalRow# records)",first:"First",previous:"«",next:"»",last:"Last",all:"All"},[B]:{pageLength:"Seitenlänge ",pageInfo:"Aktuell #pageNumber# / #totalPage# (gesamt #totalRow# Aufzeichnungen)",first:"Zuerst",previous:"«",next:"»",last:"Letzte",all:"Alle"},[V]:{pageLength:"ページごとの記録数",pageInfo:"現在の第 #pageNumber# / #totalPage# ページ(全部で #totalRow# 条の記録)",first:"トップページ",previous:"«",next:"»",last:"尾のページ",all:"すべて"},[T]:{pageLength:"Resultados por página ",pageInfo:"#pageNumber# / #totalPage# (total de #totalRow#)",first:"Início",previous:"<",next:">",last:"Fim",all:"Todos"}},s=1,j=5,C=10,E=[C,20,50,100],w=0;function F(a,r,l){if(r<=l)return s;const c=Math.floor(l/2),o=r-l+1,i=a-c;return i<s?s:i>o?o:i}function O(a,r,l){const c=F(a,r,l);return Array.from({length:l}).map((o,i)=>c+i).filter(o=>o>=s&&o<=r)}const h=e.defineComponent({name:"VPage",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:i}=e.toRefs(a),n=e.ref(0),f=e.ref(o.value===!1?C:o.value[0]),_=e.ref(j),g=e.ref(z[a.language]||z[R]),b=e.ref(-1),d=e.computed(()=>f.value===w?s:Math.ceil(i.value/f.value)),I=e.computed(()=>O(n.value,d.value,_.value)),k=e.computed(()=>g.value.pageInfo.replace("#pageNumber#",n.value).replace("#totalPage#",d.value).replace("#totalRow#",i.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&&m(t,!1)});function m(t=s,P=!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===b.value)&&(n.value=v,P&&r("update:modelValue",n.value),b.value=f.value,M())}function M(){r("change",{pageNumber:n.value,pageSize:Number(f.value)})}function y(t,P,v){const u={href:"javascript:void(0)",onClick:()=>m(P)};return e.h("li",{class:t},[e.h("a",u,v)])}return e.onMounted(()=>{m(a.modelValue||s)}),c({current:n,totalPage:d,pageNumbers:I,goPage:m,reload:M}),()=>{const t=[];if(Array.isArray(o.value)&&o.value.length){const u={disabled:a.disabled,onChange:S=>{f.value=Number(S.target.value),m()}},N=o.value.map(S=>e.h("option",{value:S},S));a.displayAll&&N.push(e.h("option",{value:w},g.value.all));const G=e.h("li",{class:"v-pagination__list"},[e.h("a",[e.h("span",g.value.pageLength),e.h("select",u,N)])]);t.push(G)}if(a.info&&t.push(e.h("li",{class:"v-pagination__info"},[e.h("a",k.value)])),"default"in l){const u=e.h("li",{class:"v-pagination__slot"},[e.h("a",l.default({pageNumber:n.value,pageSize:f.value,totalPage:d.value,totalRow:i.value,isFirst:A.value,isLast:L.value}))]);t.push(u)}if(a.first){const u=["v-pagination__first",{disabled:A.value}];t.push(y(u,s,g.value.first))}const P=["v-pagination__previous",{disabled:A.value}];t.push(y(P,n.value-1,g.value.previous)),a.pageNumber&&t.push(...I.value.map(u=>{const N={active:u===n.value};return y(N,u,u)}));const v=["v-pagination__next",{disabled:L.value}];if(t.push(y(v,n.value+1,g.value.next)),a.last){const u=["v-pagination__last",{disabled:L.value}];t.push(y(u,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:i,border:n,pageNumber:f,first:_,last:g,pageSizeMenu:b}=r;c&&(l.language.default=c),o&&(l.align.default=o),typeof i=="boolean"&&(l.info.default=i),typeof n=="boolean"&&(l.border.default=n),typeof f=="boolean"&&(l.pageNumber.default=f),typeof _=="boolean"&&(l.first.default=_),typeof g=="boolean"&&(l.last.default=g),typeof b<"u"&&(l.pageSizeMenu.default=b)}a.component(h.name,h)},p.Page=h,p.default=h,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
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 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-beta.4",
4
+ "version": "3.1.0",
5
5
  "author": "TerryZ <terry5@foxmail.com>",
6
6
  "type": "module",
7
7
  "files": [
@@ -17,6 +17,11 @@
17
17
  "default": "./dist/v-page.js"
18
18
  },
19
19
  "require": "./dist/v-page.umd.cjs"
20
+ },
21
+ "./types": {
22
+ "import": {
23
+ "types": "./types/index.d.ts"
24
+ }
20
25
  }
21
26
  },
22
27
  "typings": "./types/index.d.ts",
@@ -42,27 +47,27 @@
42
47
  "pagination"
43
48
  ],
44
49
  "peerDependencies": {
45
- "vue": "^3.2.0"
50
+ "vue": "^3.4.0"
46
51
  },
47
52
  "dependencies": {
48
- "vue": "^3.3.4"
53
+ "vue": "^3.4.29"
49
54
  },
50
55
  "devDependencies": {
51
56
  "@rushstack/eslint-patch": "^1.3.3",
52
- "@vitejs/plugin-vue": "^4.3.4",
53
- "@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",
54
60
  "@vue/eslint-config-standard": "^8.0.1",
55
- "@vue/test-utils": "^2.4.1",
56
- "bootstrap": "^5.3.1",
57
- "c8": "^8.0.1",
61
+ "@vue/test-utils": "^2.4.6",
62
+ "bootstrap": "^5.3.3",
58
63
  "eslint": "^8.49.0",
59
64
  "eslint-plugin-vue": "^9.17.0",
60
- "jsdom": "^22.1.0",
65
+ "jsdom": "^24.1.0",
61
66
  "sass": "^1.66.1",
62
67
  "sass-loader": "^13.3.2",
63
- "typescript": "^5.2.2",
64
- "vite": "^4.4.9",
65
- "vite-plugin-css-injected-by-js": "^3.3.0",
66
- "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"
67
72
  }
68
73
  }
package/types/index.d.ts CHANGED
@@ -1,33 +1,23 @@
1
1
  import {
2
- DefineComponent,
3
- ComputedOptions,
4
- MethodOptions,
5
- ComponentOptionsMixin,
6
- ObjectEmitsOptions,
7
- SlotsType
2
+ AllowedComponentProps,
3
+ ComponentCustomProps,
4
+ VNodeProps,
5
+ VNode
8
6
  } from 'vue'
9
7
 
10
8
  export declare interface PageInfo {
11
9
  pageNumber: number
12
10
  pageSize: number
11
+ totalPage: number
13
12
  }
14
13
 
15
- declare interface EmitEvents extends ObjectEmitsOptions {
16
- /** Update pageNumber value */
17
- 'update:modelValue': (pageNumber: number) => void
18
- /** The event respond pageNumber or pageSize change */
19
- change: (data: PageInfo) => void
20
- }
21
-
22
- declare interface Slots extends SlotsType {
23
- default: {
24
- pageNumber: number
25
- pageSize: number
26
- totalPage: number
27
- totalRow: number
28
- isFirst: boolean
29
- isLast: boolean
30
- }
14
+ export declare interface PageSlotData {
15
+ pageNumber: number
16
+ pageSize: number
17
+ totalPage: number
18
+ totalRow: number
19
+ isFirst: boolean
20
+ isLast: boolean
31
21
  }
32
22
 
33
23
  /**
@@ -42,16 +32,26 @@ declare interface Props {
42
32
  * The number of total record
43
33
  */
44
34
  totalRow: number
35
+ /**
36
+ * The number of page size
37
+ * @default 10
38
+ */
39
+ pageSize?: number
45
40
  /**
46
41
  * v-page language
47
- * @default `cn`
42
+ * @default `en`
48
43
  */
49
44
  language?: string
50
45
  /**
51
46
  * Page size list
52
47
  * @default [10, 20, 50, 100]
53
48
  */
54
- pageSizeMenu?: boolean|number[]
49
+ pageSizeMenu?: number[]
50
+ /**
51
+ * Whether to display page size list panel
52
+ * @default true
53
+ */
54
+ pageSizeOptions?: boolean
55
55
  /**
56
56
  * Alignment direction
57
57
  * @default `right`
@@ -92,31 +92,44 @@ declare interface Props {
92
92
  * @default false
93
93
  */
94
94
  displayAll?: boolean
95
+ /**
96
+ * Hide pagination when only have one page
97
+ * @default false
98
+ */
99
+ hideOnSinglePage?: boolean
95
100
  }
96
101
 
97
- declare interface Methods extends MethodOptions {
98
- /** Go to the specified page */
99
- goPage: (pageNumber: number) => void
100
- /** Re-emit `change` event and output pagination states data */
101
- reload: () => void
102
- }
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
+ // }
103
108
 
104
- declare const Page: DefineComponent<
105
- Props,
106
- {},
107
- {},
108
- ComputedOptions,
109
- Methods,
110
- ComponentOptionsMixin,
111
- ComponentOptionsMixin,
112
- EmitEvents,
113
- '',
114
- {},
115
- {},
116
- {},
117
- Slots
118
- >
109
+ // declare interface Methods extends MethodOptions {
110
+ // /** Go to the specified page */
111
+ // goPage: (pageNumber: number) => void
112
+ // /** Re-emit `change` event and output pagination states data */
113
+ // reload: () => void
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
121
+
122
+ declare interface PaginationBar {
123
+ new (): {
124
+ $props: AllowedComponentProps & ComponentCustomProps & VNodeProps & Props
125
+ $emit: EmitUpdateModelValue & EmitChange
126
+ $slots: {
127
+ default?: (defaultSlotData: PageSlotData) => VNode[]
128
+ }
129
+ }
130
+ }
131
+ declare const PaginationBar: PaginationBar
119
132
 
120
- export { Page }
133
+ export { PaginationBar }
121
134
 
122
- export default Page
135
+ export default PaginationBar