@schukai/monster 3.53.0 → 3.55.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 +16 -0
- package/package.json +1 -1
- package/source/components/datatable/datasource/rest.mjs +358 -309
- package/source/components/datatable/datatable/header.mjs +8 -0
- package/source/components/datatable/datatable.mjs +606 -557
- package/source/components/datatable/embedded-pagination.mjs +50 -62
- package/source/components/datatable/filter/util.mjs +122 -0
- package/source/components/datatable/filter.mjs +893 -708
- package/source/components/datatable/pagination.mjs +335 -310
- package/source/components/datatable/status.mjs +248 -0
- package/source/components/datatable/style/datatable.pcss +1 -0
- package/source/components/datatable/style/embedded-pagination.pcss +59 -2
- package/source/components/datatable/style/filter.pcss +4 -0
- package/source/components/datatable/style/pagination.pcss +28 -4
- package/source/components/datatable/style/status.pcss +42 -0
- package/source/components/datatable/stylesheet/column-bar.mjs +1 -1
- package/source/components/datatable/stylesheet/datatable.mjs +1 -1
- package/source/components/datatable/stylesheet/filter-button.mjs +1 -1
- package/source/components/datatable/stylesheet/filter.mjs +1 -1
- package/source/components/datatable/stylesheet/pagination.mjs +1 -1
- package/source/components/datatable/stylesheet/status.mjs +27 -0
- package/source/components/form/action-button.mjs +1 -1
- package/source/components/form/api-button.mjs +1 -1
- package/source/components/form/button-bar.mjs +1 -1
- package/source/components/form/button.mjs +1 -1
- package/source/components/form/confirm-button.mjs +1 -1
- package/source/components/form/context-error.mjs +275 -0
- package/source/components/form/context-help.mjs +5 -5
- package/source/components/form/form.mjs +2 -2
- package/source/components/form/message-state-button.mjs +2 -2
- package/source/components/form/popper-button.mjs +7 -4
- package/source/components/form/popper.mjs +317 -309
- package/source/components/form/reload.mjs +1 -1
- package/source/components/form/select.mjs +9 -3
- package/source/components/form/shadow-reload.mjs +1 -1
- package/source/components/form/state-button.mjs +2 -1
- package/source/components/form/style/context-error.pcss +32 -0
- package/source/components/form/style/context-help.pcss +22 -5
- package/source/components/form/stylesheet/context-error.mjs +27 -0
- package/source/components/form/stylesheet/context-help.mjs +1 -1
- package/source/components/form/stylesheet/select.mjs +1 -1
- package/source/components/form/stylesheet/tabs.mjs +1 -1
- package/source/components/form/tabs.mjs +757 -707
- package/source/components/form/template.mjs +1 -1
- package/source/components/form/tree-select.mjs +1 -1
- package/source/components/host/collapse.mjs +22 -5
- package/source/components/host/config-manager.mjs +39 -2
- package/source/components/host/host.mjs +14 -0
- package/source/components/host/stylesheet/call-button.mjs +1 -1
- package/source/components/host/stylesheet/overlay.mjs +1 -1
- package/source/components/host/stylesheet/toggle-button.mjs +1 -1
- package/source/components/host/util.mjs +6 -1
- package/source/components/notify/stylesheet/message.mjs +1 -1
- package/source/components/stylesheet/icons.mjs +1 -1
- package/source/data/transformer.mjs +39 -42
- package/source/dom/customelement.mjs +1 -1
- package/source/dom/updater.mjs +700 -688
- package/source/dom/util.mjs +42 -0
- package/source/i18n/providers/embed.mjs +3 -3
- package/source/monster.mjs +6 -0
- package/source/text/formatter.mjs +2 -2
- package/source/types/observer.mjs +1 -1
- package/source/types/version.mjs +1 -1
- package/source/util/sleep.mjs +18 -0
- package/test/cases/components/form/button.mjs +2 -1
- package/test/cases/components/form/select.mjs +1 -1
- package/test/cases/components/form/tree-select.mjs +1 -1
- package/test/cases/data/transformer.mjs +2 -2
- package/test/cases/dom/updater.mjs +67 -46
- package/test/cases/monster.mjs +1 -1
- package/test/web/test.html +2 -2
- package/test/web/tests.js +18 -13
|
@@ -4,28 +4,32 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
assembleMethodSymbol,
|
|
8
|
+
CustomElement,
|
|
9
|
+
registerCustomElement,
|
|
10
10
|
} from "../../dom/customelement.mjs";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
11
|
+
import {ThemeStyleSheet} from "../stylesheet/theme.mjs";
|
|
12
|
+
import {ATTRIBUTE_DATASOURCE_SELECTOR} from "./constants.mjs";
|
|
13
|
+
import {Datasource} from "./datasource.mjs";
|
|
14
|
+
import {Observer} from "../../types/observer.mjs";
|
|
15
|
+
import {ATTRIBUTE_ROLE} from "../../dom/constants.mjs";
|
|
16
|
+
import {findTargetElementFromEvent} from "../../dom/events.mjs";
|
|
17
|
+
import {EmbeddedPaginationStyleSheet} from "./stylesheet/embedded-pagination.mjs";
|
|
18
|
+
import {PaginationStyleSheet} from "./stylesheet/pagination.mjs";
|
|
19
|
+
//import {SpinnerStyleSheet} from "../stylesheet/spinner.mjs";
|
|
20
|
+
import {DisplayStyleSheet} from "../stylesheet/display.mjs";
|
|
21
|
+
import {isString} from "../../types/is.mjs";
|
|
22
|
+
import {Pathfinder} from "../../data/pathfinder.mjs";
|
|
23
|
+
import {instanceSymbol} from "../../constants.mjs";
|
|
24
|
+
import {Formatter} from "../../text/formatter.mjs";
|
|
21
25
|
import "../form/select.mjs";
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
26
|
+
import {addAttributeToken} from "../../dom/attributes.mjs";
|
|
27
|
+
import {ATTRIBUTE_ERRORMESSAGE} from "../../dom/constants.mjs";
|
|
24
28
|
|
|
25
29
|
import "./datasource/dom.mjs";
|
|
26
30
|
import "./datasource/rest.mjs";
|
|
27
31
|
|
|
28
|
-
export {
|
|
32
|
+
export {Pagination};
|
|
29
33
|
|
|
30
34
|
/**
|
|
31
35
|
* @private
|
|
@@ -72,123 +76,144 @@ const datasourceLinkedElementSymbol = Symbol("datasourceLinkedElement");
|
|
|
72
76
|
* @summary A datatable
|
|
73
77
|
*/
|
|
74
78
|
class Pagination extends CustomElement {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
79
|
+
/**
|
|
80
|
+
*/
|
|
81
|
+
constructor() {
|
|
82
|
+
super();
|
|
83
|
+
this[datasourceLinkedElementSymbol] = null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* This method is called by the `instanceof` operator.
|
|
88
|
+
* @returns {symbol}
|
|
89
|
+
*/
|
|
90
|
+
static get [instanceSymbol]() {
|
|
91
|
+
return Symbol.for("@schukai/monster/components/pagination");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* To set the options via the html tag the attribute `data-monster-options` must be used.
|
|
96
|
+
* @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
|
|
97
|
+
*
|
|
98
|
+
* The individual configuration values can be found in the table.
|
|
99
|
+
*
|
|
100
|
+
* @property {Object} templates Template definitions
|
|
101
|
+
* @property {string} templates.main Main template
|
|
102
|
+
* @property {int} offset Current offset
|
|
103
|
+
* @property {int} nextOffset Next offset
|
|
104
|
+
* @property {int} prevOffset Previous offset
|
|
105
|
+
* @property {int} objectsPerPage Number of objects per page
|
|
106
|
+
* @property {int} currentPage Current page
|
|
107
|
+
* @property {int} pages Total number of pages
|
|
108
|
+
* @property {int} total Total number of objects
|
|
109
|
+
*/
|
|
110
|
+
get defaults() {
|
|
111
|
+
return Object.assign(
|
|
112
|
+
{},
|
|
113
|
+
super.defaults,
|
|
114
|
+
{
|
|
115
|
+
templates: {
|
|
116
|
+
main: getTemplate(),
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
datasource: {
|
|
120
|
+
selector: null,
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
labels: {
|
|
124
|
+
page: "${page}",
|
|
125
|
+
description: "Page ${page}",
|
|
126
|
+
previous: "Previous",
|
|
127
|
+
next: "Next",
|
|
128
|
+
of: "of",
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
href: "page-${page}",
|
|
132
|
+
|
|
133
|
+
currentPage: undefined,
|
|
134
|
+
pages: undefined,
|
|
135
|
+
objectsPerPage: 20,
|
|
136
|
+
|
|
137
|
+
mapping: {
|
|
138
|
+
pages: "sys.pagination.pages",
|
|
139
|
+
objectsPerPage: "sys.pagination.objectsPerPage",
|
|
140
|
+
currentPage: "sys.pagination.currentPage",
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
// classes: {
|
|
144
|
+
// // spinner: "monster-spinner monster-theme-primary-3",
|
|
145
|
+
// // spinnerContainer: "monster-theme-primary-1 ",
|
|
146
|
+
// // error: "monster-theme-error-2 monster-bg-color-primary-2",
|
|
147
|
+
// // errorContainer: "monster-theme-primary-1",
|
|
148
|
+
// },
|
|
149
|
+
|
|
150
|
+
// state: {
|
|
151
|
+
// // spinner: false,
|
|
152
|
+
// // error: false,
|
|
153
|
+
// },
|
|
154
|
+
|
|
155
|
+
pagination: {
|
|
156
|
+
items: [],
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
initOptionsFromArguments.call(this),
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
*
|
|
165
|
+
* @return {string}
|
|
166
|
+
*/
|
|
167
|
+
static getTag() {
|
|
168
|
+
return "monster-pagination";
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
*
|
|
173
|
+
* @return {Monster.Components.Form.Form}
|
|
174
|
+
*/
|
|
175
|
+
[assembleMethodSymbol]() {
|
|
176
|
+
super[assembleMethodSymbol]();
|
|
177
|
+
|
|
178
|
+
initControlReferences.call(this);
|
|
179
|
+
initEventHandler.call(this);
|
|
180
|
+
|
|
181
|
+
const selector = this.getOption("datasource.selector", "");
|
|
182
|
+
|
|
183
|
+
if (isString(selector)) {
|
|
184
|
+
const elements = document.querySelectorAll(selector);
|
|
185
|
+
if (elements.length !== 1) {
|
|
186
|
+
throw new Error("the selector must match exactly one element");
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const element = elements[0];
|
|
190
|
+
if (!(element instanceof Datasource)) {
|
|
191
|
+
throw new TypeError("the element must be a datasource");
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
this[datasourceLinkedElementSymbol] = element;
|
|
195
|
+
element.datasource.attachObserver(
|
|
196
|
+
new Observer(handleDataSourceChanges.bind(this)),
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* @private
|
|
204
|
+
* @returns {CSSStyleSheet}
|
|
205
|
+
*/
|
|
206
|
+
static getControlCSSStyleSheet() {
|
|
207
|
+
return PaginationStyleSheet;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
*
|
|
212
|
+
* @return [CSSStyleSheet]
|
|
213
|
+
*/
|
|
214
|
+
static getCSSStyleSheet() {
|
|
215
|
+
return [this.getControlCSSStyleSheet(), DisplayStyleSheet, ThemeStyleSheet];
|
|
216
|
+
}
|
|
192
217
|
}
|
|
193
218
|
|
|
194
219
|
/**
|
|
@@ -197,73 +222,73 @@ class Pagination extends CustomElement {
|
|
|
197
222
|
* @throws {Error} no shadow-root is defined
|
|
198
223
|
*/
|
|
199
224
|
function initControlReferences() {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
225
|
+
if (!this.shadowRoot) {
|
|
226
|
+
throw new Error("no shadow-root is defined");
|
|
227
|
+
}
|
|
203
228
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
229
|
+
this[paginationElementSymbol] = this.shadowRoot.querySelector(
|
|
230
|
+
"[data-monster-role=pagination]",
|
|
231
|
+
);
|
|
207
232
|
}
|
|
208
233
|
|
|
209
234
|
/**
|
|
210
235
|
* @private
|
|
211
236
|
*/
|
|
212
237
|
function initEventHandler() {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
238
|
+
const self = this;
|
|
239
|
+
|
|
240
|
+
self[paginationElementSymbol].addEventListener("click", function (event) {
|
|
241
|
+
let element = null;
|
|
242
|
+
const datasource = self[datasourceLinkedElementSymbol];
|
|
243
|
+
if (!datasource) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
element = findTargetElementFromEvent(
|
|
248
|
+
event,
|
|
249
|
+
ATTRIBUTE_ROLE,
|
|
250
|
+
"pagination-item",
|
|
251
|
+
);
|
|
252
|
+
if (!element) {
|
|
253
|
+
element = findTargetElementFromEvent(
|
|
254
|
+
event,
|
|
255
|
+
ATTRIBUTE_ROLE,
|
|
256
|
+
"pagination-next",
|
|
257
|
+
);
|
|
258
|
+
if (!element) {
|
|
259
|
+
element = findTargetElementFromEvent(
|
|
260
|
+
event,
|
|
261
|
+
ATTRIBUTE_ROLE,
|
|
262
|
+
"pagination-prev",
|
|
263
|
+
);
|
|
264
|
+
if (!element) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
let page = null;
|
|
271
|
+
|
|
272
|
+
if (!element.hasAttribute("data-page-no")) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
page = element.getAttribute("data-page-no");
|
|
277
|
+
event.preventDefault();
|
|
278
|
+
|
|
279
|
+
if (
|
|
280
|
+
!page ||
|
|
281
|
+
page === "" ||
|
|
282
|
+
page === null ||
|
|
283
|
+
page === undefined ||
|
|
284
|
+
page === "undefined" ||
|
|
285
|
+
page === "null"
|
|
286
|
+
) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
datasource.setParameters({page}).reload();
|
|
291
|
+
});
|
|
267
292
|
}
|
|
268
293
|
|
|
269
294
|
/**
|
|
@@ -279,46 +304,46 @@ function initEventHandler() {
|
|
|
279
304
|
* @throws {Error} the datasource could not be initialized
|
|
280
305
|
*/
|
|
281
306
|
function initOptionsFromArguments() {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
307
|
+
const options = {};
|
|
308
|
+
const selector = this.getAttribute(ATTRIBUTE_DATASOURCE_SELECTOR);
|
|
309
|
+
if (selector) {
|
|
310
|
+
options.datasource = {selector: selector};
|
|
311
|
+
}
|
|
287
312
|
|
|
288
|
-
|
|
313
|
+
return options;
|
|
289
314
|
}
|
|
290
315
|
|
|
291
316
|
/**
|
|
292
317
|
* @private
|
|
293
318
|
*/
|
|
294
319
|
function handleDataSourceChanges() {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
320
|
+
let pagination;
|
|
321
|
+
|
|
322
|
+
if (!this[datasourceLinkedElementSymbol]) {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const mapping = this.getOption("mapping");
|
|
327
|
+
for (const key in mapping) {
|
|
328
|
+
const path = mapping[key];
|
|
329
|
+
|
|
330
|
+
let value;
|
|
331
|
+
try {
|
|
332
|
+
value = new Pathfinder(this[datasourceLinkedElementSymbol].data).getVia(
|
|
333
|
+
path,
|
|
334
|
+
);
|
|
335
|
+
this.setOption(key, value);
|
|
336
|
+
} catch (e) {
|
|
337
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e.message);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
pagination = buildPagination.call(
|
|
342
|
+
this,
|
|
343
|
+
this.getOption("currentPage"),
|
|
344
|
+
this.getOption("pages"),
|
|
345
|
+
);
|
|
346
|
+
this.setOption("pagination", pagination);
|
|
322
347
|
}
|
|
323
348
|
|
|
324
349
|
/**
|
|
@@ -328,88 +353,88 @@ function handleDataSourceChanges() {
|
|
|
328
353
|
* @returns {object}
|
|
329
354
|
*/
|
|
330
355
|
function buildPagination(current, max) {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
356
|
+
let prev = current === 1 ? null : current - 1;
|
|
357
|
+
let next = current === max ? null : current + 1;
|
|
358
|
+
const itemList = [1];
|
|
359
|
+
|
|
360
|
+
if (current > 4) itemList.push("…");
|
|
361
|
+
|
|
362
|
+
const r = 2;
|
|
363
|
+
const r1 = current - r;
|
|
364
|
+
const r2 = current + r;
|
|
365
|
+
|
|
366
|
+
for (let i = r1 > 2 ? r1 : 2; i <= Math.min(max, r2); i++) itemList.push(i);
|
|
367
|
+
|
|
368
|
+
if (r2 + 1 < max) itemList.push("…");
|
|
369
|
+
if (r2 < max) itemList.push(max);
|
|
370
|
+
|
|
371
|
+
let prevClass = "";
|
|
372
|
+
|
|
373
|
+
if (prev === null) {
|
|
374
|
+
prevClass = " disabled";
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
let nextClass = "";
|
|
378
|
+
if (next === null) {
|
|
379
|
+
nextClass = " disabled";
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const items = itemList.map((item) => {
|
|
383
|
+
const p = `${item}`;
|
|
384
|
+
const c = `${current}`;
|
|
385
|
+
|
|
386
|
+
const obj = {
|
|
387
|
+
pageNo: item, // as integer
|
|
388
|
+
page: p, // as string
|
|
389
|
+
current: p === c,
|
|
390
|
+
class: (p === c ? "current" : "").trim(),
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
if (p === "…") {
|
|
394
|
+
obj.class += " disabled".trim();
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
const formatter = new Formatter(obj);
|
|
398
|
+
|
|
399
|
+
obj.description = formatter.format(this.getOption("labels.description"));
|
|
400
|
+
obj.label = formatter.format(this.getOption("labels.page"));
|
|
401
|
+
obj.href =
|
|
402
|
+
p === "…"
|
|
403
|
+
? "#"
|
|
404
|
+
: p === c
|
|
405
|
+
? "#"
|
|
406
|
+
: p === "1"
|
|
407
|
+
? "#"
|
|
408
|
+
: `#${formatter.format(this.getOption("href"))}`;
|
|
409
|
+
return obj;
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
const nextNo = next;
|
|
413
|
+
next = `${next}`;
|
|
414
|
+
|
|
415
|
+
const nextHref =
|
|
416
|
+
next === "null"
|
|
417
|
+
? "#"
|
|
418
|
+
: `#${new Formatter({page: next}).format(this.getOption("href"))}`;
|
|
419
|
+
const prevNo = prev;
|
|
420
|
+
prev = `${prev}`;
|
|
421
|
+
const prevHref =
|
|
422
|
+
prev === "null"
|
|
423
|
+
? "#"
|
|
424
|
+
: `#${new Formatter({page: prev}).format(this.getOption("href"))}`;
|
|
425
|
+
|
|
426
|
+
return {
|
|
427
|
+
current,
|
|
428
|
+
nextNo,
|
|
429
|
+
next,
|
|
430
|
+
nextClass,
|
|
431
|
+
nextHref,
|
|
432
|
+
prevNo,
|
|
433
|
+
prev,
|
|
434
|
+
prevClass,
|
|
435
|
+
prevHref,
|
|
436
|
+
items,
|
|
437
|
+
};
|
|
413
438
|
}
|
|
414
439
|
|
|
415
440
|
/**
|
|
@@ -417,8 +442,8 @@ function buildPagination(current, max) {
|
|
|
417
442
|
* @return {string}
|
|
418
443
|
*/
|
|
419
444
|
function getTemplate() {
|
|
420
|
-
|
|
421
|
-
|
|
445
|
+
// language=HTML
|
|
446
|
+
return `
|
|
422
447
|
<template id="items">
|
|
423
448
|
<li><a data-monster-attributes="class path:items.class,
|
|
424
449
|
href path:items.href,
|