@ditojs/ui 2.11.3 → 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.3",
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",
43
+ "sass": "1.66.1",
44
44
  "vite": "^4.4.9"
45
45
  },
46
- "gitHead": "9a5406b3ce9575128e9432dfbe6a6d3177d96c3d",
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",
@@ -7,21 +7,18 @@
7
7
  template(
8
8
  v-if="total > 0"
9
9
  ) {{ first }} – {{ last }} / {{ total }}
10
- template(
11
- v-else
12
- ) 0
13
10
  .dito-buttons.dito-buttons-round(
14
11
  v-if="numPages > 1"
15
12
  )
16
13
  button.dito-button(
17
- v-for="page in pageRange"
18
- :class="getPageClass(page)"
19
- :disabled="page.disabled"
20
- @click="onClickPage(page)"
14
+ v-for="button in buttons"
15
+ :class="getButtonClasses(button)"
16
+ :disabled="button.disabled"
17
+ @click="onClickButton(button)"
21
18
  )
22
19
  span(
23
- v-if="page.text"
24
- ) {{ page.text }}
20
+ v-if="button.text"
21
+ ) {{ button.text }}
25
22
  </template>
26
23
 
27
24
  <script>
@@ -37,7 +34,6 @@ export default {
37
34
 
38
35
  data() {
39
36
  return {
40
- pageRange: [],
41
37
  showPrev: true,
42
38
  showNext: true,
43
39
  currentPage: this.page
@@ -59,10 +55,6 @@ export default {
59
55
  },
60
56
 
61
57
  watch: {
62
- total: 'updatePageRange',
63
- showPrev: 'updatePageRange',
64
- showNext: 'updatePageRange',
65
-
66
58
  page(page) {
67
59
  this.currentPage = page
68
60
  },
@@ -71,43 +63,15 @@ export default {
71
63
  if (this.currentPage > this.numPages) {
72
64
  this.currentPage = this.numPages
73
65
  }
74
- this.updatePageRange()
75
66
  },
76
67
 
77
68
  currentPage(to, from) {
78
69
  if (to !== from) {
79
- this.updatePageRange()
80
70
  this.$emit('update:page', to)
81
71
  }
82
- }
83
- },
84
-
85
- created() {
86
- this.currentPage = this.page
87
- },
88
-
89
- mounted() {
90
- this.updatePageRange()
91
- },
92
-
93
- methods: {
94
- onClickPage(page) {
95
- if (page.index && !page.disabled && page.index !== this.currentPage) {
96
- this.currentPage = page.index
97
- }
98
- },
99
-
100
- getPageClass(page) {
101
- const classes = {
102
- 'dito-selected': page.active
103
- }
104
- if (page.type) {
105
- classes[`dito-button-${page.type}`] = true
106
- }
107
- return classes
108
72
  },
109
73
 
110
- updatePageRange() {
74
+ buttons() {
111
75
  const { showPrev, showNext, currentPage, numPages } = this
112
76
  const showLength = showPrev + showNext + 1
113
77
 
@@ -125,44 +89,70 @@ export default {
125
89
  end = currentPage + showNext
126
90
  }
127
91
 
128
- const pageRange = []
129
- pageRange.push({
92
+ const buttons = []
93
+ buttons.push({
130
94
  index: currentPage - 1,
131
95
  type: 'prev',
132
96
  disabled: currentPage <= 1
133
97
  })
134
98
  if (start >= 2) {
135
- pageRange.push({ index: 1, text: 1 })
99
+ buttons.push({ index: 1, text: 1 })
136
100
  }
137
101
  if (start > 2) {
138
- pageRange.push({
102
+ buttons.push({
139
103
  index: Math.max(1, currentPage - 10),
140
104
  type: 'ellipsis-prev'
141
105
  })
142
106
  }
143
107
  for (let i = start; i <= end; i++) {
144
- pageRange.push({
108
+ buttons.push({
145
109
  index: i,
146
110
  text: i,
147
111
  active: i === currentPage
148
112
  })
149
113
  }
150
114
  if (end < numPages - 1) {
151
- pageRange.push({
115
+ buttons.push({
152
116
  index: Math.min(numPages, currentPage + 10),
153
117
  type: 'ellipsis-next'
154
118
  })
155
119
  }
156
120
  if (end <= numPages - 1) {
157
- pageRange.push({ index: numPages, text: numPages })
121
+ buttons.push({ index: numPages, text: numPages })
158
122
  }
159
- pageRange.push({
123
+ buttons.push({
160
124
  index: currentPage + 1,
161
125
  type: 'next',
162
126
  disabled: currentPage >= numPages
163
127
  })
164
128
 
165
- 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
+ }
166
156
  }
167
157
  }
168
158
  }