@refinitiv-ui/elements 5.9.1 → 5.10.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/CHANGELOG.md +23 -0
- package/lib/button/themes/solar/charcoal/index.js +1 -1
- package/lib/button/themes/solar/pearl/index.js +1 -1
- package/lib/combo-box/themes/halo/dark/index.js +1 -1
- package/lib/combo-box/themes/halo/light/index.js +1 -1
- package/lib/combo-box/themes/solar/charcoal/index.js +1 -1
- package/lib/combo-box/themes/solar/pearl/index.js +1 -1
- package/lib/counter/themes/halo/dark/index.js +1 -1
- package/lib/counter/themes/halo/light/index.js +1 -1
- package/lib/label/index.js +2 -1
- package/lib/number-field/themes/solar/charcoal/index.js +1 -1
- package/lib/pagination/custom-elements.json +16 -33
- package/lib/pagination/custom-elements.md +8 -9
- package/lib/pagination/index.d.ts +142 -74
- package/lib/pagination/index.js +358 -202
- package/lib/pagination/themes/halo/dark/index.js +1 -1
- package/lib/pagination/themes/halo/light/index.js +1 -1
- package/lib/pagination/themes/solar/charcoal/index.js +1 -1
- package/lib/pagination/themes/solar/pearl/index.js +1 -1
- package/lib/toggle/themes/halo/dark/index.js +1 -1
- package/lib/toggle/themes/halo/light/index.js +1 -1
- package/lib/toggle/themes/solar/charcoal/index.js +1 -1
- package/lib/toggle/themes/solar/pearl/index.js +1 -1
- package/lib/tree/themes/halo/dark/index.js +1 -1
- package/lib/tree/themes/halo/light/index.js +1 -1
- package/lib/tree/themes/solar/charcoal/index.js +1 -1
- package/lib/tree/themes/solar/pearl/index.js +1 -1
- package/lib/tree-select/themes/halo/dark/index.js +1 -1
- package/lib/tree-select/themes/halo/light/index.js +1 -1
- package/lib/tree-select/themes/solar/charcoal/index.js +1 -1
- package/lib/tree-select/themes/solar/pearl/index.js +1 -1
- package/lib/version.js +1 -1
- package/package.json +8 -8
- package/lib/pagination/helpers/types.d.ts +0 -9
- package/lib/pagination/helpers/types.js +0 -1
package/lib/pagination/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
|
-
import { BasicElement, html, css } from '@refinitiv-ui/core';
|
|
2
|
+
import { BasicElement, html, css, WarningNotice, DeprecationNotice } from '@refinitiv-ui/core';
|
|
3
3
|
import { customElement } from '@refinitiv-ui/core/lib/decorators/custom-element.js';
|
|
4
4
|
import { property } from '@refinitiv-ui/core/lib/decorators/property.js';
|
|
5
|
+
import { state } from '@refinitiv-ui/core/lib/decorators/state.js';
|
|
5
6
|
import { query } from '@refinitiv-ui/core/lib/decorators/query.js';
|
|
6
7
|
import { VERSION } from '../version.js';
|
|
7
8
|
import '../button/index.js';
|
|
@@ -10,29 +11,42 @@ import '../layout/index.js';
|
|
|
10
11
|
import '../text-field/index.js';
|
|
11
12
|
import '@refinitiv-ui/phrasebook/lib/locale/en/pagination.js';
|
|
12
13
|
import { translate } from '@refinitiv-ui/translate';
|
|
14
|
+
const pageDeprecation = new DeprecationNotice('Property `page` is deprecated, use `value` instead.');
|
|
15
|
+
const pageSizeDeprecation = new DeprecationNotice('Property `pageSize ` is deprecated, use `max` instead.');
|
|
16
|
+
const totalItemsDeprecation = new DeprecationNotice('Property `totalItems ` is deprecated, use `max` instead.');
|
|
13
17
|
/**
|
|
14
18
|
* Used to control and navigate through multiple pages
|
|
15
|
-
* @fires
|
|
19
|
+
* @fires value-changed - Fired when the `value` property is changed
|
|
16
20
|
*/
|
|
17
21
|
let Pagination = class Pagination extends BasicElement {
|
|
18
22
|
constructor() {
|
|
19
23
|
super(...arguments);
|
|
20
24
|
/**
|
|
21
|
-
*
|
|
25
|
+
* Current page internal current page value
|
|
22
26
|
*/
|
|
23
|
-
this.
|
|
27
|
+
this._value = '';
|
|
24
28
|
/**
|
|
25
|
-
*
|
|
29
|
+
* Max page
|
|
26
30
|
*/
|
|
27
|
-
this.
|
|
31
|
+
this._max = '';
|
|
28
32
|
/**
|
|
29
|
-
*
|
|
33
|
+
* Number of item per page internal value
|
|
34
|
+
* @deprecated
|
|
30
35
|
*/
|
|
31
|
-
this.
|
|
36
|
+
this._pageSize = '';
|
|
37
|
+
/**
|
|
38
|
+
* Total items internal value
|
|
39
|
+
* @deprecated
|
|
40
|
+
*/
|
|
41
|
+
this._totalItems = '';
|
|
32
42
|
/**
|
|
33
43
|
* Set state to disable
|
|
34
44
|
*/
|
|
35
45
|
this.disabled = false;
|
|
46
|
+
/**
|
|
47
|
+
* State for check the input focus
|
|
48
|
+
*/
|
|
49
|
+
this.inputFocused = false;
|
|
36
50
|
}
|
|
37
51
|
/**
|
|
38
52
|
* Element version number
|
|
@@ -42,209 +56,335 @@ let Pagination = class Pagination extends BasicElement {
|
|
|
42
56
|
return VERSION;
|
|
43
57
|
}
|
|
44
58
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* and the internal template of the element.
|
|
48
|
-
* @return CSS template
|
|
59
|
+
* Internal current page
|
|
60
|
+
* @returns current page
|
|
49
61
|
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
`;
|
|
62
|
+
get internalValue() {
|
|
63
|
+
let value = parseInt(this._value, 10) || 0;
|
|
64
|
+
if (value <= 0) {
|
|
65
|
+
value = 1;
|
|
66
|
+
}
|
|
67
|
+
return value;
|
|
57
68
|
}
|
|
58
69
|
/**
|
|
59
|
-
*
|
|
60
|
-
* @param changedProperties Map of changed properties with old values
|
|
61
|
-
* @returns {void}
|
|
70
|
+
* Current page
|
|
62
71
|
*/
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
72
|
+
get value() {
|
|
73
|
+
return this._value;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Set current page
|
|
77
|
+
* @param value current page
|
|
78
|
+
*/
|
|
79
|
+
set value(value) {
|
|
80
|
+
let newValue = value;
|
|
81
|
+
if (!newValue || !this.validatePage(newValue, true, 'value')) {
|
|
82
|
+
newValue = '';
|
|
67
83
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this.
|
|
71
|
-
this.updateButtons();
|
|
84
|
+
const oldValue = this._value;
|
|
85
|
+
if (oldValue !== newValue) {
|
|
86
|
+
this._value = newValue.toString();
|
|
72
87
|
}
|
|
73
|
-
|
|
74
|
-
|
|
88
|
+
this.requestUpdate('value', oldValue);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Internal max page
|
|
92
|
+
* @returns max page
|
|
93
|
+
*/
|
|
94
|
+
get internalMax() {
|
|
95
|
+
const max = parseInt(this._max, 10) || 0;
|
|
96
|
+
const pageSize = this.internalPageSize;
|
|
97
|
+
const totalItems = this.internalTotalitems;
|
|
98
|
+
if (!max && !totalItems) {
|
|
99
|
+
return Infinity;
|
|
75
100
|
}
|
|
76
|
-
if (
|
|
77
|
-
|
|
101
|
+
else if (max >= 1) {
|
|
102
|
+
return max;
|
|
78
103
|
}
|
|
104
|
+
if (pageSize > 0) {
|
|
105
|
+
const totalPage = Math.ceil(totalItems / pageSize);
|
|
106
|
+
return totalPage >= 1 ? totalPage : 1;
|
|
107
|
+
}
|
|
108
|
+
return 1;
|
|
79
109
|
}
|
|
80
110
|
/**
|
|
81
|
-
*
|
|
82
|
-
* @returns
|
|
111
|
+
* Max page
|
|
112
|
+
* @returns max page
|
|
113
|
+
*/
|
|
114
|
+
get max() {
|
|
115
|
+
return this._max;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Set max page
|
|
119
|
+
* @param value max page
|
|
83
120
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (pageSize < 1) {
|
|
89
|
-
this.pageSize = '1';
|
|
121
|
+
set max(value) {
|
|
122
|
+
let newValue = value;
|
|
123
|
+
if (!newValue || !this.validatePage(value, true, 'max')) {
|
|
124
|
+
newValue = '';
|
|
90
125
|
}
|
|
91
|
-
|
|
92
|
-
|
|
126
|
+
const oldValue = this._max;
|
|
127
|
+
if (oldValue !== newValue) {
|
|
128
|
+
this._max = newValue.toString();
|
|
93
129
|
}
|
|
94
|
-
this.
|
|
130
|
+
this.requestUpdate('max', oldValue);
|
|
95
131
|
}
|
|
96
132
|
/**
|
|
97
|
-
*
|
|
98
|
-
* @returns
|
|
133
|
+
* Current page
|
|
134
|
+
* @returns current page
|
|
135
|
+
* @deprecated
|
|
136
|
+
* @ignore
|
|
137
|
+
*/
|
|
138
|
+
get page() {
|
|
139
|
+
pageDeprecation.once();
|
|
140
|
+
return this._value;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Set current page
|
|
144
|
+
* @param value - Set current page
|
|
145
|
+
* @deprecated
|
|
146
|
+
* @ignore
|
|
99
147
|
*/
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
this.totalItems = '0';
|
|
106
|
-
this.page = '1';
|
|
148
|
+
set page(value) {
|
|
149
|
+
pageDeprecation.show();
|
|
150
|
+
let newValue = value;
|
|
151
|
+
if (!newValue || !this.validatePage(value, true, 'page')) {
|
|
152
|
+
newValue = '';
|
|
107
153
|
}
|
|
108
|
-
|
|
109
|
-
|
|
154
|
+
const oldValue = this._value;
|
|
155
|
+
if (oldValue !== newValue) {
|
|
156
|
+
this._value = newValue.toString();
|
|
110
157
|
}
|
|
111
|
-
this.
|
|
158
|
+
this.requestUpdate('page', oldValue);
|
|
112
159
|
}
|
|
113
160
|
/**
|
|
114
|
-
*
|
|
115
|
-
* @returns
|
|
161
|
+
* Number of item per page
|
|
162
|
+
* @returns number of items per page
|
|
163
|
+
* @deprecated
|
|
164
|
+
* @ignore
|
|
165
|
+
*/
|
|
166
|
+
get pageSize() {
|
|
167
|
+
pageSizeDeprecation.once();
|
|
168
|
+
return this._pageSize;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Set number of item per page
|
|
172
|
+
* @param value - number of item per page
|
|
173
|
+
* @deprecated
|
|
174
|
+
* @ignore
|
|
116
175
|
*/
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
176
|
+
set pageSize(value) {
|
|
177
|
+
pageSizeDeprecation.show();
|
|
178
|
+
let newValue = value;
|
|
179
|
+
if (!newValue || !this.validatePage(value, true, 'page-size')) {
|
|
180
|
+
newValue = '';
|
|
120
181
|
}
|
|
121
|
-
|
|
122
|
-
|
|
182
|
+
// Validate to show warning only, need to keep developer value.
|
|
183
|
+
// Check page still is in supported range if page-size changed
|
|
184
|
+
const newTotalPage = Math.ceil(this.internalTotalitems / (parseInt(newValue, 10) || 1)) || 1;
|
|
185
|
+
if (this.internalValue > newTotalPage) {
|
|
186
|
+
new WarningNotice(`${this.localName} : The specified value "${newValue}" of page-size caused the value of page property is out of supported range.`).show();
|
|
187
|
+
}
|
|
188
|
+
const oldValue = this._pageSize;
|
|
189
|
+
if (oldValue !== newValue) {
|
|
190
|
+
this._pageSize = newValue;
|
|
123
191
|
}
|
|
124
|
-
this.
|
|
125
|
-
// recalculate button state
|
|
126
|
-
this.updateButtons();
|
|
192
|
+
this.requestUpdate('pageSize', oldValue);
|
|
127
193
|
}
|
|
128
194
|
/**
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* @returns {void}
|
|
195
|
+
* Internal page size
|
|
196
|
+
* @deprecated
|
|
197
|
+
* @returns page size
|
|
133
198
|
*/
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const firstPage = this.disabled || page <= 1;
|
|
137
|
-
const lastPage = this.disabled || page >= this.totalPage;
|
|
138
|
-
this.previousPageButton.disabled = firstPage;
|
|
139
|
-
this.firstPageButton.disabled = firstPage;
|
|
140
|
-
this.nextPageButton.disabled = lastPage;
|
|
141
|
-
this.lastPageButton.disabled = lastPage;
|
|
199
|
+
get internalPageSize() {
|
|
200
|
+
return parseInt(this._pageSize, 10);
|
|
142
201
|
}
|
|
143
202
|
/**
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
* @
|
|
203
|
+
* Internal total items
|
|
204
|
+
* @returns total items
|
|
205
|
+
* @deprecated
|
|
147
206
|
*/
|
|
148
|
-
get
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
if (pageSize > 0) {
|
|
152
|
-
const totalPage = Math.ceil(totalItems / pageSize);
|
|
153
|
-
return totalPage > 0 ? totalPage : 1;
|
|
154
|
-
}
|
|
155
|
-
return 1;
|
|
207
|
+
get internalTotalitems() {
|
|
208
|
+
const totalItems = parseInt(this._totalItems, 10) || 0;
|
|
209
|
+
return totalItems >= 1 ? totalItems : 0;
|
|
156
210
|
}
|
|
157
211
|
/**
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
* @
|
|
162
|
-
* @param newPage a new page value
|
|
163
|
-
* @return return a new page value
|
|
212
|
+
* Total items
|
|
213
|
+
* @returns total items
|
|
214
|
+
* @deprecated
|
|
215
|
+
* @ignore
|
|
164
216
|
*/
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
217
|
+
get totalItems() {
|
|
218
|
+
totalItemsDeprecation.once();
|
|
219
|
+
return this._totalItems;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Set total items
|
|
223
|
+
* @param value total items
|
|
224
|
+
* @deprecated
|
|
225
|
+
* @ignore
|
|
226
|
+
*/
|
|
227
|
+
set totalItems(value) {
|
|
228
|
+
totalItemsDeprecation.show();
|
|
229
|
+
let newValue = value;
|
|
230
|
+
if (!newValue || !this.validatePage(value, true, 'total-items')) {
|
|
231
|
+
newValue = '';
|
|
169
232
|
}
|
|
170
|
-
|
|
171
|
-
|
|
233
|
+
// Validate to show warning only, need to keep developer value.
|
|
234
|
+
// Check page still is in supported range if total-item changed
|
|
235
|
+
const newTotalPage = Math.ceil((parseInt(newValue, 10) || 1) / this.internalPageSize) || 1;
|
|
236
|
+
if (this.internalValue > newTotalPage) {
|
|
237
|
+
new WarningNotice(`${this.localName} : The specified value "${newValue}" of total-items caused the value of page property is out of supported range.`).show();
|
|
172
238
|
}
|
|
173
|
-
|
|
174
|
-
|
|
239
|
+
const oldValue = this._totalItems;
|
|
240
|
+
if (oldValue !== newValue) {
|
|
241
|
+
this._totalItems = newValue;
|
|
175
242
|
}
|
|
176
|
-
|
|
243
|
+
this.requestUpdate('totalItems', oldValue);
|
|
177
244
|
}
|
|
178
245
|
/**
|
|
179
|
-
* Get
|
|
180
|
-
* @returns
|
|
246
|
+
* Get infinite pagination state
|
|
247
|
+
* @returns infinite pagination state
|
|
181
248
|
*/
|
|
182
|
-
get
|
|
183
|
-
|
|
184
|
-
const pageSize = Number.parseInt(this.pageSize, 10);
|
|
185
|
-
const totalCount = Number.parseInt(this.totalItems, 10);
|
|
186
|
-
const from = ((page - 1) * pageSize) + 1;
|
|
187
|
-
const to = page * pageSize > totalCount ? totalCount : page * pageSize;
|
|
188
|
-
return {
|
|
189
|
-
from,
|
|
190
|
-
to,
|
|
191
|
-
totalCount,
|
|
192
|
-
pageSize
|
|
193
|
-
};
|
|
249
|
+
get infinitePaginate() {
|
|
250
|
+
return this.internalMax === Infinity; // internalMax always returns 1-Infinity
|
|
194
251
|
}
|
|
195
252
|
/**
|
|
196
|
-
*
|
|
197
|
-
* @returns
|
|
253
|
+
* Getter for display text in the input
|
|
254
|
+
* @returns input text
|
|
198
255
|
*/
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
256
|
+
get inputText() {
|
|
257
|
+
if (this.inputFocused) {
|
|
258
|
+
return this.internalValue.toString();
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
return (this.infinitePaginate ? this.t('PAGE', { page: this.internalValue }) : this.t('PAGE_OF', { page: this.internalValue, pageTotal: this.internalMax }));
|
|
262
|
+
}
|
|
202
263
|
}
|
|
203
264
|
/**
|
|
204
|
-
*
|
|
205
|
-
* @returns {void}
|
|
265
|
+
* State for checking the first page button is available
|
|
206
266
|
*/
|
|
207
|
-
|
|
208
|
-
this.
|
|
209
|
-
setTimeout(() => {
|
|
210
|
-
this.input.select();
|
|
211
|
-
});
|
|
267
|
+
get useFirstButton() {
|
|
268
|
+
return !this.disabled && this.internalValue >= 2;
|
|
212
269
|
}
|
|
213
270
|
/**
|
|
214
|
-
*
|
|
215
|
-
|
|
216
|
-
|
|
271
|
+
* State for checking the previous page button is available
|
|
272
|
+
*/
|
|
273
|
+
get usePreviousButton() {
|
|
274
|
+
return this.useFirstButton;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* State for checking the next page button is available
|
|
278
|
+
*/
|
|
279
|
+
get useNextButton() {
|
|
280
|
+
return !this.disabled && this.internalValue < this.internalMax;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* State for checking the last page button is available
|
|
217
284
|
*/
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
285
|
+
get useLastButton() {
|
|
286
|
+
return this.useNextButton && !this.infinitePaginate;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* @override
|
|
290
|
+
*/
|
|
291
|
+
updated(changedProperties) {
|
|
292
|
+
super.updated(changedProperties);
|
|
293
|
+
if (this.inputFocused && changedProperties.has('inputFocused')) {
|
|
294
|
+
void this.selectInput();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Validate integer value
|
|
299
|
+
* @param value value
|
|
300
|
+
* @param warning show warning message when value is invalid
|
|
301
|
+
* @param propName property name to show in warning message
|
|
302
|
+
* @returns result of validation
|
|
303
|
+
*/
|
|
304
|
+
validatePage(value, warning = false, propName = '') {
|
|
305
|
+
if ((/^[1-9]([0-9]+)?$/).test(value)) {
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
if (value !== null && warning && propName) {
|
|
310
|
+
new WarningNotice(`${this.localName} : The specified value "${value}" of ${propName} property is not valid, The value must be integer and greater than 0.`).show();
|
|
311
|
+
}
|
|
312
|
+
return false;
|
|
225
313
|
}
|
|
226
314
|
}
|
|
227
315
|
/**
|
|
228
|
-
* Handles action when Enter key is press onto the input
|
|
316
|
+
* Handles action when Enter and Tab key is press onto the input
|
|
229
317
|
* @param event Keyboard event
|
|
230
318
|
* @returns {void}
|
|
231
319
|
*/
|
|
232
320
|
onInputKeyDown(event) {
|
|
233
321
|
var _a, _b;
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
322
|
+
const isEnter = event.key === 'Enter' || event.keyCode === 13;
|
|
323
|
+
const isTab = event.key === 'Tab' || event.keyCode === 9;
|
|
324
|
+
if (isEnter || isTab) {
|
|
325
|
+
this.updatePageInput();
|
|
326
|
+
if (isEnter) {
|
|
327
|
+
this.input.blur();
|
|
328
|
+
event.preventDefault();
|
|
329
|
+
/**
|
|
330
|
+
* Issue only in firefox
|
|
331
|
+
* cannot blur() or focus() to this.input so create a temp to this.input loses focus
|
|
332
|
+
*/
|
|
333
|
+
const temp = document.createElement('input');
|
|
334
|
+
(_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.appendChild(temp);
|
|
335
|
+
temp.focus();
|
|
336
|
+
this.input.blur();
|
|
337
|
+
(_b = this.shadowRoot) === null || _b === void 0 ? void 0 : _b.removeChild(temp);
|
|
338
|
+
}
|
|
246
339
|
}
|
|
247
340
|
}
|
|
341
|
+
/**
|
|
342
|
+
* Handles action when input focused change
|
|
343
|
+
* @param event focus change event
|
|
344
|
+
* @returns {void}
|
|
345
|
+
*/
|
|
346
|
+
onInputFocusedChanged(event) {
|
|
347
|
+
this.inputFocused = event.detail.value;
|
|
348
|
+
if (!this.inputFocused) {
|
|
349
|
+
this.updatePageInput();
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Update page by using value from the input
|
|
354
|
+
* @returns {void}
|
|
355
|
+
*/
|
|
356
|
+
updatePageInput() {
|
|
357
|
+
// Prevent update page to the same value
|
|
358
|
+
if (this.value === this.input.value) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
const oldValue = this.value;
|
|
362
|
+
let newValue = parseInt(this.input.value, 10);
|
|
363
|
+
// Reset input and boundary value into supported range.
|
|
364
|
+
if (this.validatePage(this.input.value)) {
|
|
365
|
+
if (newValue <= 0) {
|
|
366
|
+
newValue = 1;
|
|
367
|
+
}
|
|
368
|
+
else if (newValue > this.internalMax) {
|
|
369
|
+
newValue = this.internalMax;
|
|
370
|
+
}
|
|
371
|
+
this.value = newValue.toString();
|
|
372
|
+
}
|
|
373
|
+
else if (!isNaN(newValue)) {
|
|
374
|
+
this.value = '1';
|
|
375
|
+
}
|
|
376
|
+
if (this.value !== oldValue) {
|
|
377
|
+
this.notifyValueChange();
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Select text in input when update element complete
|
|
382
|
+
* @returns returns a promise void
|
|
383
|
+
*/
|
|
384
|
+
async selectInput() {
|
|
385
|
+
await this.updateComplete;
|
|
386
|
+
this.input.select();
|
|
387
|
+
}
|
|
248
388
|
/**
|
|
249
389
|
* Updates page value depending on direction
|
|
250
390
|
* @param direction page value direction
|
|
@@ -252,21 +392,35 @@ let Pagination = class Pagination extends BasicElement {
|
|
|
252
392
|
* @returns {void}
|
|
253
393
|
*/
|
|
254
394
|
updatePage(direction, event = false) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
395
|
+
/**
|
|
396
|
+
* Handle in case the value of max property is greater than value of value/page property,
|
|
397
|
+
* which it might happen by using developer API.
|
|
398
|
+
*/
|
|
399
|
+
let page = this.internalValue;
|
|
400
|
+
if (page > this.internalMax) {
|
|
401
|
+
page = this.internalMax + 1;
|
|
402
|
+
}
|
|
403
|
+
const limit = direction === 'increment' ? page >= this.internalMax : page <= 1;
|
|
404
|
+
if (!limit) {
|
|
405
|
+
this.value = direction === 'increment' ? (page + 1).toString() : (page - 1).toString();
|
|
259
406
|
if (event) {
|
|
260
|
-
this.
|
|
407
|
+
this.notifyValueChange();
|
|
261
408
|
}
|
|
262
409
|
}
|
|
263
410
|
}
|
|
411
|
+
/**
|
|
412
|
+
* Fires event when value change
|
|
413
|
+
* @returns {void}
|
|
414
|
+
*/
|
|
415
|
+
notifyValueChange() {
|
|
416
|
+
this.notifyPropertyChange('value', this.value);
|
|
417
|
+
this.notifyPropertyChange('page', this.value); // deprecated. support backwards compatibility.
|
|
418
|
+
}
|
|
264
419
|
/**
|
|
265
420
|
* Go to the next page
|
|
266
421
|
* @returns {void}
|
|
267
422
|
*/
|
|
268
423
|
next() {
|
|
269
|
-
this.input.blur();
|
|
270
424
|
this.updatePage('increment');
|
|
271
425
|
}
|
|
272
426
|
/**
|
|
@@ -274,7 +428,6 @@ let Pagination = class Pagination extends BasicElement {
|
|
|
274
428
|
* @returns {void}
|
|
275
429
|
*/
|
|
276
430
|
onNextTap() {
|
|
277
|
-
this.input.blur();
|
|
278
431
|
this.updatePage('increment', true);
|
|
279
432
|
}
|
|
280
433
|
/**
|
|
@@ -282,15 +435,13 @@ let Pagination = class Pagination extends BasicElement {
|
|
|
282
435
|
* @returns {void}
|
|
283
436
|
*/
|
|
284
437
|
previous() {
|
|
285
|
-
this.input.blur();
|
|
286
438
|
this.updatePage('decrement');
|
|
287
439
|
}
|
|
288
440
|
/**
|
|
289
|
-
* Go to the previous page and fires
|
|
441
|
+
* Go to the previous page and fires event
|
|
290
442
|
* @returns {void}
|
|
291
443
|
*/
|
|
292
444
|
onPreviousTap() {
|
|
293
|
-
this.input.blur();
|
|
294
445
|
this.updatePage('decrement', true);
|
|
295
446
|
}
|
|
296
447
|
/**
|
|
@@ -298,8 +449,7 @@ let Pagination = class Pagination extends BasicElement {
|
|
|
298
449
|
* @returns {void}
|
|
299
450
|
*/
|
|
300
451
|
first() {
|
|
301
|
-
this.
|
|
302
|
-
this.page = '1';
|
|
452
|
+
this.value = '1';
|
|
303
453
|
}
|
|
304
454
|
/**
|
|
305
455
|
* Go to the first page and fires event
|
|
@@ -307,15 +457,18 @@ let Pagination = class Pagination extends BasicElement {
|
|
|
307
457
|
*/
|
|
308
458
|
onFirstTap() {
|
|
309
459
|
this.first();
|
|
310
|
-
this.
|
|
460
|
+
this.notifyValueChange();
|
|
311
461
|
}
|
|
312
462
|
/**
|
|
313
463
|
* Go to the last page
|
|
314
464
|
* @returns {void}
|
|
315
465
|
*/
|
|
316
466
|
last() {
|
|
317
|
-
this.
|
|
318
|
-
|
|
467
|
+
if (this.infinitePaginate) {
|
|
468
|
+
new WarningNotice(`${this.localName}: Cannot call "last()" when "max" attribute/property is unset.`).show();
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
this.value = this.internalMax.toString();
|
|
319
472
|
}
|
|
320
473
|
/**
|
|
321
474
|
* Go to the last page and fires event
|
|
@@ -323,35 +476,44 @@ let Pagination = class Pagination extends BasicElement {
|
|
|
323
476
|
*/
|
|
324
477
|
onLastTap() {
|
|
325
478
|
this.last();
|
|
326
|
-
this.
|
|
479
|
+
this.notifyValueChange();
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* A `CSSResultGroup` that will be used
|
|
483
|
+
* to style the host, slotted children
|
|
484
|
+
* and the internal template of the element.
|
|
485
|
+
* @return CSS template
|
|
486
|
+
*/
|
|
487
|
+
static get styles() {
|
|
488
|
+
return css `
|
|
489
|
+
:host {
|
|
490
|
+
display: inline-block;
|
|
491
|
+
}
|
|
492
|
+
`;
|
|
327
493
|
}
|
|
328
494
|
/**
|
|
329
495
|
* A `TemplateResult` that will be used
|
|
330
496
|
* to render the updated internal template.
|
|
331
|
-
* @return
|
|
497
|
+
* @return Render template
|
|
332
498
|
*/
|
|
333
499
|
render() {
|
|
334
500
|
return html `
|
|
335
|
-
<ef-layout part="container" flex nowrap
|
|
336
|
-
<div id="info" part="info">${this.t('ITEM_INFO', this.pageInfo)}</div>
|
|
501
|
+
<ef-layout part="container" flex nowrap>
|
|
337
502
|
<ef-button-bar part="buttons">
|
|
338
|
-
<ef-button id="first" icon="skip-to-start" @tap="${this.onFirstTap}"></ef-button>
|
|
339
|
-
<ef-button id="previous" icon="left" @tap="${this.onPreviousTap}"></ef-button>
|
|
503
|
+
<ef-button id="first" icon="skip-to-start" @tap="${this.onFirstTap}" .disabled=${!this.useFirstButton}></ef-button>
|
|
504
|
+
<ef-button id="previous" icon="left" @tap="${this.onPreviousTap}" .disabled=${!this.usePreviousButton}></ef-button>
|
|
340
505
|
</ef-button-bar>
|
|
341
506
|
<ef-text-field
|
|
342
507
|
id="input"
|
|
343
508
|
part="input"
|
|
344
|
-
@
|
|
345
|
-
@
|
|
346
|
-
|
|
347
|
-
.
|
|
348
|
-
page: this.page,
|
|
349
|
-
pageTotal: this.totalPage
|
|
350
|
-
})}"
|
|
509
|
+
@focused-changed=${this.onInputFocusedChanged}
|
|
510
|
+
@keydown=${this.onInputKeyDown}
|
|
511
|
+
.value=${this.inputText}
|
|
512
|
+
.disabled=${this.disabled}
|
|
351
513
|
no-spinner></ef-text-field>
|
|
352
514
|
<ef-button-bar part="buttons">
|
|
353
|
-
<ef-button id="next" icon="right" @tap="${this.onNextTap}"></ef-button>
|
|
354
|
-
<ef-button id="last" icon="skip-to-end" @tap="${this.onLastTap}"></ef-button>
|
|
515
|
+
<ef-button id="next" icon="right" @tap="${this.onNextTap}" .disabled=${!this.useNextButton}></ef-button>
|
|
516
|
+
<ef-button id="last" icon="skip-to-end" @tap="${this.onLastTap}" .disabled=${!this.useLastButton}></ef-button>
|
|
355
517
|
</ef-button-bar>
|
|
356
518
|
</ef-layout>
|
|
357
519
|
`;
|
|
@@ -359,37 +521,31 @@ let Pagination = class Pagination extends BasicElement {
|
|
|
359
521
|
};
|
|
360
522
|
__decorate([
|
|
361
523
|
property({ type: String })
|
|
362
|
-
], Pagination.prototype, "
|
|
524
|
+
], Pagination.prototype, "value", null);
|
|
525
|
+
__decorate([
|
|
526
|
+
property({ type: String })
|
|
527
|
+
], Pagination.prototype, "max", null);
|
|
528
|
+
__decorate([
|
|
529
|
+
property({ type: String })
|
|
530
|
+
], Pagination.prototype, "page", null);
|
|
363
531
|
__decorate([
|
|
364
532
|
property({ type: String, attribute: 'page-size' })
|
|
365
|
-
], Pagination.prototype, "pageSize",
|
|
533
|
+
], Pagination.prototype, "pageSize", null);
|
|
366
534
|
__decorate([
|
|
367
535
|
property({ type: String, attribute: 'total-items' })
|
|
368
|
-
], Pagination.prototype, "totalItems",
|
|
536
|
+
], Pagination.prototype, "totalItems", null);
|
|
369
537
|
__decorate([
|
|
370
538
|
property({ type: Boolean, reflect: true })
|
|
371
539
|
], Pagination.prototype, "disabled", void 0);
|
|
372
|
-
__decorate([
|
|
373
|
-
query('#info')
|
|
374
|
-
], Pagination.prototype, "infoElement", void 0);
|
|
375
540
|
__decorate([
|
|
376
541
|
query('#input')
|
|
377
542
|
], Pagination.prototype, "input", void 0);
|
|
378
|
-
__decorate([
|
|
379
|
-
query('#first')
|
|
380
|
-
], Pagination.prototype, "firstPageButton", void 0);
|
|
381
|
-
__decorate([
|
|
382
|
-
query('#previous')
|
|
383
|
-
], Pagination.prototype, "previousPageButton", void 0);
|
|
384
|
-
__decorate([
|
|
385
|
-
query('#next')
|
|
386
|
-
], Pagination.prototype, "nextPageButton", void 0);
|
|
387
|
-
__decorate([
|
|
388
|
-
query('#last')
|
|
389
|
-
], Pagination.prototype, "lastPageButton", void 0);
|
|
390
543
|
__decorate([
|
|
391
544
|
translate()
|
|
392
545
|
], Pagination.prototype, "t", void 0);
|
|
546
|
+
__decorate([
|
|
547
|
+
state()
|
|
548
|
+
], Pagination.prototype, "inputFocused", void 0);
|
|
393
549
|
Pagination = __decorate([
|
|
394
550
|
customElement('ef-pagination', {
|
|
395
551
|
alias: 'emerald-pagination'
|