@ditojs/ui 2.11.2 → 2.12.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ditojs/ui",
3
- "version": "2.11.2",
3
+ "version": "2.12.0",
4
4
  "type": "module",
5
5
  "description": "Dito.js UI is a simple UI library, built with Vue.js for use in Dito.js Admin and elsewhere",
6
6
  "repository": "https://github.com/ditojs/dito/tree/master/packages/ui",
@@ -32,18 +32,18 @@
32
32
  "ie_mob >= 11"
33
33
  ],
34
34
  "dependencies": {
35
- "@ditojs/utils": "^2.11.1",
35
+ "@ditojs/utils": "^2.12.0",
36
36
  "@soda/get-current-script": "^1.0.2"
37
37
  },
38
38
  "devDependencies": {
39
- "@ditojs/build": "^2.11.0",
40
- "@vitejs/plugin-vue": "^4.2.3",
39
+ "@ditojs/build": "^2.12.0",
40
+ "@vitejs/plugin-vue": "^4.3.4",
41
41
  "@vue/compiler-sfc": "^3.3.4",
42
42
  "pug": "^3.0.2",
43
- "sass": "1.64.2",
44
- "vite": "^4.4.8"
43
+ "sass": "1.66.1",
44
+ "vite": "^4.4.9"
45
45
  },
46
- "gitHead": "681f441e6d90931bbfa7dfb301fb480d7b6fc4cf",
46
+ "gitHead": "186a1020c58e17182a19895e5f5df2955a22c301",
47
47
  "scripts": {
48
48
  "build:icons": "yarn inline-assets src/icons/*.svg --template src/icons/template.js > src/styles/mixins/_icons.scss",
49
49
  "build:vue": "vite build",
@@ -6,21 +6,19 @@
6
6
  )
7
7
  template(
8
8
  v-if="total > 0"
9
- ) {{ first }} – {{ last }}
10
- template(
11
- v-else
12
- ) 0
13
- | / {{ total }}
14
- .dito-buttons.dito-buttons-round
9
+ ) {{ first }} – {{ last }} / {{ total }}
10
+ .dito-buttons.dito-buttons-round(
11
+ v-if="numPages > 1"
12
+ )
15
13
  button.dito-button(
16
- v-for="page in pageRange"
17
- :class="getPageClass(page)"
18
- :disabled="page.disabled"
19
- @click="onClickPage(page)"
14
+ v-for="button in buttons"
15
+ :class="getButtonClasses(button)"
16
+ :disabled="button.disabled"
17
+ @click="onClickButton(button)"
20
18
  )
21
19
  span(
22
- v-if="page.text"
23
- ) {{ page.text }}
20
+ v-if="button.text"
21
+ ) {{ button.text }}
24
22
  </template>
25
23
 
26
24
  <script>
@@ -36,84 +34,46 @@ export default {
36
34
 
37
35
  data() {
38
36
  return {
39
- pageRange: [],
40
37
  showPrev: true,
41
38
  showNext: true,
42
- numPages: 0,
43
- currentPageSize: this.pageSize,
44
39
  currentPage: this.page
45
40
  }
46
41
  },
47
42
 
48
43
  computed: {
49
44
  first() {
50
- return (this.currentPage - 1) * this.currentPageSize + 1
45
+ return (this.currentPage - 1) * this.pageSize + 1
51
46
  },
52
47
 
53
48
  last() {
54
- return Math.min(this.first + this.currentPageSize - 1, this.total)
49
+ return Math.min(this.first + this.pageSize - 1, this.total)
50
+ },
51
+
52
+ numPages() {
53
+ return Math.ceil(this.total / this.pageSize)
55
54
  }
56
55
  },
57
56
 
58
57
  watch: {
59
- total: 'updatePageRange',
60
- showPrev: 'updatePageRange',
61
- showNext: 'updatePageRange',
62
-
63
58
  page(page) {
64
59
  this.currentPage = page
65
60
  },
66
61
 
67
- pageSize(pageSize) {
68
- this.currentPageSize = pageSize
69
- },
70
-
71
- currentPageSize(currentPageSize) {
72
- this.numPages = Math.ceil(this.total / currentPageSize)
62
+ pageSize() {
73
63
  if (this.currentPage > this.numPages) {
74
64
  this.currentPage = this.numPages
75
65
  }
76
- this.updatePageRange()
77
66
  },
78
67
 
79
68
  currentPage(to, from) {
80
69
  if (to !== from) {
81
- this.updatePageRange()
82
70
  this.$emit('update:page', to)
83
71
  }
84
- }
85
- },
86
-
87
- created() {
88
- this.currentPage = this.page
89
- this.currentPageSize = this.pageSize
90
- },
91
-
92
- mounted() {
93
- this.updatePageRange()
94
- },
95
-
96
- methods: {
97
- onClickPage(page) {
98
- if (page.index && !page.disabled && page.index !== this.currentPage) {
99
- this.currentPage = page.index
100
- }
101
72
  },
102
73
 
103
- getPageClass(page) {
104
- const classes = {
105
- 'dito-selected': page.active
106
- }
107
- if (page.type) {
108
- classes[`dito-button-${page.type}`] = true
109
- }
110
- return classes
111
- },
112
-
113
- updatePageRange() {
114
- const { showPrev, showNext, total, currentPageSize, currentPage } = this
74
+ buttons() {
75
+ const { showPrev, showNext, currentPage, numPages } = this
115
76
  const showLength = showPrev + showNext + 1
116
- const numPages = (this.numPages = Math.ceil(total / currentPageSize))
117
77
 
118
78
  let start = 1
119
79
  let end = 1
@@ -129,44 +89,70 @@ export default {
129
89
  end = currentPage + showNext
130
90
  }
131
91
 
132
- const pageRange = []
133
- pageRange.push({
92
+ const buttons = []
93
+ buttons.push({
134
94
  index: currentPage - 1,
135
95
  type: 'prev',
136
96
  disabled: currentPage <= 1
137
97
  })
138
98
  if (start >= 2) {
139
- pageRange.push({ index: 1, text: 1 })
99
+ buttons.push({ index: 1, text: 1 })
140
100
  }
141
101
  if (start > 2) {
142
- pageRange.push({
102
+ buttons.push({
143
103
  index: Math.max(1, currentPage - 10),
144
104
  type: 'ellipsis-prev'
145
105
  })
146
106
  }
147
107
  for (let i = start; i <= end; i++) {
148
- pageRange.push({
108
+ buttons.push({
149
109
  index: i,
150
110
  text: i,
151
111
  active: i === currentPage
152
112
  })
153
113
  }
154
114
  if (end < numPages - 1) {
155
- pageRange.push({
115
+ buttons.push({
156
116
  index: Math.min(numPages, currentPage + 10),
157
117
  type: 'ellipsis-next'
158
118
  })
159
119
  }
160
120
  if (end <= numPages - 1) {
161
- pageRange.push({ index: numPages, text: numPages })
121
+ buttons.push({ index: numPages, text: numPages })
162
122
  }
163
- pageRange.push({
123
+ buttons.push({
164
124
  index: currentPage + 1,
165
125
  type: 'next',
166
126
  disabled: currentPage >= numPages
167
127
  })
168
128
 
169
- this.pageRange = pageRange
129
+ return buttons
130
+ }
131
+ },
132
+
133
+ created() {
134
+ this.currentPage = this.page
135
+ },
136
+
137
+ methods: {
138
+ getButtonClasses(button) {
139
+ const classes = {
140
+ 'dito-selected': button.active
141
+ }
142
+ if (button.type) {
143
+ classes[`dito-button-${button.type}`] = true
144
+ }
145
+ return classes
146
+ },
147
+
148
+ onClickButton(button) {
149
+ if (
150
+ button.index &&
151
+ !button.disabled &&
152
+ button.index !== this.currentPage
153
+ ) {
154
+ this.currentPage = button.index
155
+ }
170
156
  }
171
157
  }
172
158
  }