@ditojs/ui 2.11.3 → 2.12.2

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.2",
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.67.0",
44
44
  "vite": "^4.4.9"
45
45
  },
46
- "gitHead": "9a5406b3ce9575128e9432dfbe6a6d3177d96c3d",
46
+ "gitHead": "db38e59b09cb0f98360b98e4efe51d94c57d3194",
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
@@ -55,59 +51,9 @@ export default {
55
51
 
56
52
  numPages() {
57
53
  return Math.ceil(this.total / this.pageSize)
58
- }
59
- },
60
-
61
- watch: {
62
- total: 'updatePageRange',
63
- showPrev: 'updatePageRange',
64
- showNext: 'updatePageRange',
65
-
66
- page(page) {
67
- this.currentPage = page
68
- },
69
-
70
- pageSize() {
71
- if (this.currentPage > this.numPages) {
72
- this.currentPage = this.numPages
73
- }
74
- this.updatePageRange()
75
- },
76
-
77
- currentPage(to, from) {
78
- if (to !== from) {
79
- this.updatePageRange()
80
- this.$emit('update:page', to)
81
- }
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
54
  },
109
55
 
110
- updatePageRange() {
56
+ buttons() {
111
57
  const { showPrev, showNext, currentPage, numPages } = this
112
58
  const showLength = showPrev + showNext + 1
113
59
 
@@ -125,44 +71,88 @@ export default {
125
71
  end = currentPage + showNext
126
72
  }
127
73
 
128
- const pageRange = []
129
- pageRange.push({
74
+ const buttons = []
75
+ buttons.push({
130
76
  index: currentPage - 1,
131
77
  type: 'prev',
132
78
  disabled: currentPage <= 1
133
79
  })
134
80
  if (start >= 2) {
135
- pageRange.push({ index: 1, text: 1 })
81
+ buttons.push({ index: 1, text: 1 })
136
82
  }
137
83
  if (start > 2) {
138
- pageRange.push({
84
+ buttons.push({
139
85
  index: Math.max(1, currentPage - 10),
140
86
  type: 'ellipsis-prev'
141
87
  })
142
88
  }
143
89
  for (let i = start; i <= end; i++) {
144
- pageRange.push({
90
+ buttons.push({
145
91
  index: i,
146
92
  text: i,
147
93
  active: i === currentPage
148
94
  })
149
95
  }
150
96
  if (end < numPages - 1) {
151
- pageRange.push({
97
+ buttons.push({
152
98
  index: Math.min(numPages, currentPage + 10),
153
99
  type: 'ellipsis-next'
154
100
  })
155
101
  }
156
102
  if (end <= numPages - 1) {
157
- pageRange.push({ index: numPages, text: numPages })
103
+ buttons.push({ index: numPages, text: numPages })
158
104
  }
159
- pageRange.push({
105
+ buttons.push({
160
106
  index: currentPage + 1,
161
107
  type: 'next',
162
108
  disabled: currentPage >= numPages
163
109
  })
164
110
 
165
- this.pageRange = pageRange
111
+ return buttons
112
+ }
113
+ },
114
+
115
+ watch: {
116
+ page(page) {
117
+ this.currentPage = page
118
+ },
119
+
120
+ pageSize() {
121
+ if (this.currentPage > this.numPages) {
122
+ this.currentPage = this.numPages
123
+ }
124
+ },
125
+
126
+ currentPage(to, from) {
127
+ if (to !== from) {
128
+ this.$emit('update:page', to)
129
+ }
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
  }