@schukai/monster 3.95.0 → 3.95.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/CHANGELOG.md +16 -0
- package/package.json +1 -1
- package/source/components/datatable/dataset.mjs +327 -305
- package/source/components/datatable/datasource/dom.mjs +37 -1
- package/source/components/datatable/datasource/rest.mjs +481 -449
- package/source/components/datatable/datasource.mjs +23 -15
- package/source/components/datatable/embedded-pagination.mjs +11 -0
- package/source/components/datatable/pagination.mjs +444 -422
- package/source/components/datatable/status.mjs +1 -1
- package/source/components/datatable/style/pagination.pcss +2 -2
- package/source/components/datatable/stylesheet/pagination.mjs +7 -14
- package/source/components/datatable/util.mjs +1 -0
- package/source/components/host/config-manager.mjs +1 -3
- package/source/components/layout/tabs.mjs +35 -23
- package/source/data/datasource/server/restapi.mjs +23 -16
- package/source/data/datasource/server.mjs +1 -0
- package/source/dom/customelement.mjs +34 -0
- package/source/types/has.mjs +29 -0
@@ -13,32 +13,32 @@
|
|
13
13
|
*/
|
14
14
|
|
15
15
|
import {
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
assembleMethodSymbol,
|
17
|
+
CustomElement,
|
18
|
+
registerCustomElement,
|
19
19
|
} from "../../dom/customelement.mjs";
|
20
|
-
import {
|
21
|
-
import {
|
22
|
-
import {
|
23
|
-
import {
|
24
|
-
import {
|
25
|
-
import {
|
26
|
-
import {
|
27
|
-
import {
|
28
|
-
import {
|
29
|
-
import {
|
30
|
-
import {
|
31
|
-
import {
|
32
|
-
import {
|
33
|
-
import {
|
20
|
+
import {findElementWithSelectorUpwards, getWindow} from "../../dom/util.mjs";
|
21
|
+
import {DeadMansSwitch} from "../../util/deadmansswitch.mjs";
|
22
|
+
import {ThemeStyleSheet} from "../stylesheet/theme.mjs";
|
23
|
+
import {ATTRIBUTE_DATASOURCE_SELECTOR} from "./constants.mjs";
|
24
|
+
import {Datasource} from "./datasource.mjs";
|
25
|
+
import {Observer} from "../../types/observer.mjs";
|
26
|
+
import {ATTRIBUTE_ROLE} from "../../dom/constants.mjs";
|
27
|
+
import {findTargetElementFromEvent} from "../../dom/events.mjs";
|
28
|
+
import {PaginationStyleSheet} from "./stylesheet/pagination.mjs";
|
29
|
+
import {DisplayStyleSheet} from "../stylesheet/display.mjs";
|
30
|
+
import {isString} from "../../types/is.mjs";
|
31
|
+
import {Pathfinder} from "../../data/pathfinder.mjs";
|
32
|
+
import {instanceSymbol} from "../../constants.mjs";
|
33
|
+
import {Formatter} from "../../text/formatter.mjs";
|
34
34
|
import "../form/select.mjs";
|
35
|
-
import {
|
36
|
-
import {
|
35
|
+
import {addAttributeToken} from "../../dom/attributes.mjs";
|
36
|
+
import {ATTRIBUTE_ERRORMESSAGE} from "../../dom/constants.mjs";
|
37
37
|
|
38
38
|
import "./datasource/dom.mjs";
|
39
39
|
import "./datasource/rest.mjs";
|
40
40
|
|
41
|
-
export {
|
41
|
+
export {Pagination};
|
42
42
|
|
43
43
|
/**
|
44
44
|
* @private
|
@@ -71,215 +71,227 @@ const sizeDataSymbol = Symbol("sizeData");
|
|
71
71
|
const debounceSizeSymbol = Symbol("debounceSize");
|
72
72
|
|
73
73
|
/**
|
74
|
-
*
|
74
|
+
* A Pagination component
|
75
|
+
*
|
76
|
+
* @fragments /fragments/components/datatable/pagination
|
77
|
+
*
|
78
|
+
* @example /examples/components/datatable/pagination-simple
|
75
79
|
*
|
76
80
|
* @copyright schukai GmbH
|
77
81
|
* @summary The Pagination component is used to show the current page and the total number of pages.
|
78
82
|
*/
|
79
83
|
class Pagination extends CustomElement {
|
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
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
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
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
84
|
+
/**
|
85
|
+
*/
|
86
|
+
constructor() {
|
87
|
+
super();
|
88
|
+
this[datasourceLinkedElementSymbol] = null;
|
89
|
+
}
|
90
|
+
|
91
|
+
/**
|
92
|
+
* This method is called by the `instanceof` operator.
|
93
|
+
* @return {symbol}
|
94
|
+
*/
|
95
|
+
static get [instanceSymbol]() {
|
96
|
+
return Symbol.for("@schukai/monster/components/pagination");
|
97
|
+
}
|
98
|
+
|
99
|
+
/**
|
100
|
+
* To set the options via the HTML tag, the attribute `data-monster-options` must be used.
|
101
|
+
* @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
|
102
|
+
*
|
103
|
+
* The individual configuration values can be found in the table.
|
104
|
+
*
|
105
|
+
* @property {Object} templates Template definitions
|
106
|
+
* @property {string} templates.main Main template
|
107
|
+
* @property {Object} datasource Datasource configuration
|
108
|
+
* @property {string} datasource.selector Datasource selector
|
109
|
+
* @property {Object} labels Label definitions
|
110
|
+
* @property {string} labels.page Page label
|
111
|
+
* @property {string} labels.description Description label
|
112
|
+
* @property {string} labels.previous Previous label
|
113
|
+
* @property {string} labels.next Next label
|
114
|
+
* @property {string} labels.of Of label
|
115
|
+
* @property {string} href Href
|
116
|
+
* @property {number} currentPage Current page
|
117
|
+
* @property {number} pages Pages
|
118
|
+
* @property {number} objectsPerPage Objects per page
|
119
|
+
* @property {Object} mapping Mapping
|
120
|
+
* @property {string} mapping.pages Pages mapping
|
121
|
+
* @property {string} mapping.objectsPerPage Objects per page mapping
|
122
|
+
* @property {string} mapping.currentPage Current page mapping
|
123
|
+
*/
|
124
|
+
get defaults() {
|
125
|
+
return Object.assign(
|
126
|
+
{},
|
127
|
+
super.defaults,
|
128
|
+
{
|
129
|
+
templates: {
|
130
|
+
main: getTemplate(),
|
131
|
+
},
|
132
|
+
|
133
|
+
datasource: {
|
134
|
+
selector: null,
|
135
|
+
},
|
136
|
+
|
137
|
+
labels: {
|
138
|
+
page: "${page}",
|
139
|
+
description: "Page ${page}",
|
140
|
+
previous: "Previous",
|
141
|
+
next: "Next",
|
142
|
+
of: "of",
|
143
|
+
},
|
144
|
+
|
145
|
+
href: "page-${page}",
|
146
|
+
|
147
|
+
pages: null,
|
148
|
+
objectsPerPage: 20,
|
149
|
+
currentPage: null,
|
150
|
+
|
151
|
+
mapping: {
|
152
|
+
pages: "sys.pagination.pages",
|
153
|
+
objectsPerPage: "sys.pagination.objectsPerPage",
|
154
|
+
currentPage: "sys.pagination.currentPage",
|
155
|
+
},
|
156
|
+
|
157
|
+
/* @private */
|
158
|
+
pagination: {
|
159
|
+
items: [],
|
160
|
+
},
|
161
|
+
},
|
162
|
+
initOptionsFromArguments.call(this),
|
163
|
+
);
|
164
|
+
}
|
165
|
+
|
166
|
+
/**
|
167
|
+
*
|
168
|
+
* @return {string}
|
169
|
+
*/
|
170
|
+
static getTag() {
|
171
|
+
return "monster-pagination";
|
172
|
+
}
|
173
|
+
|
174
|
+
/**
|
175
|
+
* @return {void}
|
176
|
+
*/
|
177
|
+
disconnectedCallback() {
|
178
|
+
super.disconnectedCallback();
|
179
|
+
if (this?.[resizeObserverSymbol] instanceof ResizeObserver) {
|
180
|
+
this[resizeObserverSymbol].disconnect();
|
181
|
+
}
|
182
|
+
}
|
183
|
+
|
184
|
+
/**
|
185
|
+
* @return {void}
|
186
|
+
*/
|
187
|
+
connectedCallback() {
|
188
|
+
super.connectedCallback();
|
189
|
+
|
190
|
+
const parentNode = this.parentNode;
|
191
|
+
if (!parentNode) {
|
192
|
+
return;
|
193
|
+
}
|
194
|
+
|
195
|
+
try {
|
196
|
+
handleDataSourceChanges.call(this);
|
197
|
+
} catch (e) {
|
198
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e?.message || `${e}`);
|
199
|
+
}
|
200
|
+
|
201
|
+
requestAnimationFrame(() => {
|
202
|
+
const parentParentNode = parentNode?.parentNode || parentNode;
|
203
|
+
|
204
|
+
const parentWidth = parentParentNode.offsetWidth;
|
205
|
+
const ownWidth = this.offsetWidth;
|
206
|
+
|
207
|
+
this[sizeDataSymbol] = {
|
208
|
+
last: {
|
209
|
+
parentWidth: 0,
|
210
|
+
},
|
211
|
+
showNumbers: ownWidth < parentWidth,
|
212
|
+
};
|
213
|
+
|
214
|
+
this[resizeObserverSymbol] = new ResizeObserver((entries) => {
|
215
|
+
if (this[debounceSizeSymbol] instanceof DeadMansSwitch) {
|
216
|
+
try {
|
217
|
+
this[debounceSizeSymbol].touch();
|
218
|
+
return;
|
219
|
+
} catch (e) {
|
220
|
+
delete this[debounceSizeSymbol];
|
221
|
+
}
|
222
|
+
}
|
223
|
+
|
224
|
+
this[debounceSizeSymbol] = new DeadMansSwitch(250, () => {
|
225
|
+
queueMicrotask(() => {
|
226
|
+
const parentWidth = parentParentNode.offsetWidth;
|
227
|
+
const ownWidth = this.clientWidth;
|
228
|
+
|
229
|
+
if (this[sizeDataSymbol]?.last?.parentWidth === parentWidth) {
|
230
|
+
return;
|
231
|
+
}
|
232
|
+
|
233
|
+
this[sizeDataSymbol].last = {
|
234
|
+
parentWidth: parentWidth,
|
235
|
+
};
|
236
|
+
|
237
|
+
this[sizeDataSymbol].showNumbers = ownWidth <= parentWidth;
|
238
|
+
handleDataSourceChanges.call(this);
|
239
|
+
});
|
240
|
+
});
|
241
|
+
});
|
242
|
+
|
243
|
+
this[resizeObserverSymbol].observe(this?.parentNode?.parentNode);
|
244
|
+
});
|
245
|
+
}
|
246
|
+
|
247
|
+
/**
|
248
|
+
* @return {void}
|
249
|
+
*/
|
250
|
+
[assembleMethodSymbol]() {
|
251
|
+
super[assembleMethodSymbol]();
|
252
|
+
|
253
|
+
initControlReferences.call(this);
|
254
|
+
initEventHandler.call(this);
|
255
|
+
|
256
|
+
const selector = this.getOption("datasource.selector", "");
|
257
|
+
|
258
|
+
if (isString(selector)) {
|
259
|
+
const element = findElementWithSelectorUpwards(this, selector);
|
260
|
+
if (element === null) {
|
261
|
+
throw new Error("the selector must match exactly one element");
|
262
|
+
}
|
263
|
+
|
264
|
+
if (!(element instanceof Datasource)) {
|
265
|
+
throw new TypeError("the element must be a datasource");
|
266
|
+
}
|
267
|
+
|
268
|
+
this[datasourceLinkedElementSymbol] = element;
|
269
|
+
element.datasource.attachObserver(
|
270
|
+
new Observer(handleDataSourceChanges.bind(this)),
|
271
|
+
);
|
272
|
+
|
273
|
+
element.attachObserver(
|
274
|
+
new Observer(handleDataSourceChanges.bind(this)),
|
275
|
+
);
|
276
|
+
|
277
|
+
handleDataSourceChanges.call(this);
|
278
|
+
}
|
279
|
+
}
|
280
|
+
|
281
|
+
/**
|
282
|
+
* @private
|
283
|
+
* @return {CSSStyleSheet}
|
284
|
+
*/
|
285
|
+
static getControlCSSStyleSheet() {
|
286
|
+
return PaginationStyleSheet;
|
287
|
+
}
|
288
|
+
|
289
|
+
/**
|
290
|
+
* @return {CSSStyleSheet[]}
|
291
|
+
*/
|
292
|
+
static getCSSStyleSheet() {
|
293
|
+
return [this.getControlCSSStyleSheet(), DisplayStyleSheet, ThemeStyleSheet];
|
294
|
+
}
|
283
295
|
}
|
284
296
|
|
285
297
|
/**
|
@@ -288,87 +300,88 @@ class Pagination extends CustomElement {
|
|
288
300
|
* @throws {Error} no shadow-root is defined
|
289
301
|
*/
|
290
302
|
function initControlReferences() {
|
291
|
-
|
292
|
-
|
293
|
-
|
303
|
+
if (!this.shadowRoot) {
|
304
|
+
throw new Error("no shadow-root is defined");
|
305
|
+
}
|
294
306
|
|
295
|
-
|
296
|
-
|
297
|
-
|
307
|
+
this[paginationElementSymbol] = this.shadowRoot.querySelector(
|
308
|
+
"[data-monster-role=pagination]",
|
309
|
+
);
|
298
310
|
}
|
299
311
|
|
300
312
|
/**
|
301
313
|
* @private
|
302
314
|
*/
|
303
315
|
function initEventHandler() {
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
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
|
-
|
316
|
+
const self = this;
|
317
|
+
|
318
|
+
self[paginationElementSymbol].addEventListener("click", function (event) {
|
319
|
+
let element = null;
|
320
|
+
const datasource = self[datasourceLinkedElementSymbol];
|
321
|
+
if (!datasource) {
|
322
|
+
return;
|
323
|
+
}
|
324
|
+
|
325
|
+
element = findTargetElementFromEvent(
|
326
|
+
event,
|
327
|
+
ATTRIBUTE_ROLE,
|
328
|
+
"pagination-item",
|
329
|
+
);
|
330
|
+
|
331
|
+
if (!element) {
|
332
|
+
element = findTargetElementFromEvent(
|
333
|
+
event,
|
334
|
+
ATTRIBUTE_ROLE,
|
335
|
+
"pagination-next",
|
336
|
+
);
|
337
|
+
if (!element) {
|
338
|
+
element = findTargetElementFromEvent(
|
339
|
+
event,
|
340
|
+
ATTRIBUTE_ROLE,
|
341
|
+
"pagination-prev",
|
342
|
+
);
|
343
|
+
if (!element) {
|
344
|
+
return;
|
345
|
+
}
|
346
|
+
}
|
347
|
+
}
|
348
|
+
|
349
|
+
if (!(element instanceof HTMLElement)) {
|
350
|
+
return;
|
351
|
+
}
|
352
|
+
|
353
|
+
let page = null;
|
354
|
+
|
355
|
+
if (!element.hasAttribute("data-page-no")) {
|
356
|
+
return;
|
357
|
+
}
|
358
|
+
|
359
|
+
page = element.getAttribute("data-page-no");
|
360
|
+
|
361
|
+
if (
|
362
|
+
!page ||
|
363
|
+
page === "" ||
|
364
|
+
page === null ||
|
365
|
+
page === undefined ||
|
366
|
+
page === "undefined" ||
|
367
|
+
page === "null"
|
368
|
+
) {
|
369
|
+
return;
|
370
|
+
}
|
371
|
+
|
372
|
+
if (typeof datasource.setParameters !== "function") {
|
373
|
+
return;
|
374
|
+
}
|
375
|
+
|
376
|
+
event.preventDefault();
|
377
|
+
datasource.setParameters({page});
|
378
|
+
|
379
|
+
if (typeof datasource.reload !== "function") {
|
380
|
+
return;
|
381
|
+
}
|
382
|
+
|
383
|
+
datasource.reload();
|
384
|
+
});
|
372
385
|
}
|
373
386
|
|
374
387
|
/**
|
@@ -384,53 +397,58 @@ function initEventHandler() {
|
|
384
397
|
* @throws {Error} the datasource could not be initialized
|
385
398
|
*/
|
386
399
|
function initOptionsFromArguments() {
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
400
|
+
const options = {};
|
401
|
+
const selector = this.getAttribute(ATTRIBUTE_DATASOURCE_SELECTOR);
|
402
|
+
if (selector) {
|
403
|
+
options.datasource = {selector: selector};
|
404
|
+
}
|
392
405
|
|
393
|
-
|
406
|
+
return options;
|
394
407
|
}
|
395
408
|
|
396
409
|
/**
|
397
410
|
* @private
|
398
411
|
*/
|
399
412
|
function handleDataSourceChanges() {
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
413
|
+
let pagination;
|
414
|
+
|
415
|
+
if (!this[datasourceLinkedElementSymbol]) {
|
416
|
+
return;
|
417
|
+
}
|
418
|
+
|
419
|
+
const mapping = this.getOption("mapping");
|
420
|
+
const pf = new Pathfinder(this[datasourceLinkedElementSymbol].data);
|
421
|
+
|
422
|
+
for (const key in mapping) {
|
423
|
+
const path = mapping[key];
|
424
|
+
|
425
|
+
if (pf.exists(path)) {
|
426
|
+
const value = pf.getVia(
|
427
|
+
path,
|
428
|
+
);
|
429
|
+
this.setOption(key, value);
|
430
|
+
}
|
431
|
+
|
432
|
+
const o = this[datasourceLinkedElementSymbol].getOption(path);
|
433
|
+
if (o !== undefined && o !== null) {
|
434
|
+
this.setOption(key, o);
|
435
|
+
}
|
436
|
+
|
437
|
+
}
|
438
|
+
|
439
|
+
pagination = buildPagination.call(
|
440
|
+
this,
|
441
|
+
this.getOption("currentPage"),
|
442
|
+
this.getOption("pages"),
|
443
|
+
);
|
444
|
+
|
445
|
+
if (this?.[sizeDataSymbol]?.showNumbers !== true) {
|
446
|
+
pagination.items = [];
|
447
|
+
}
|
448
|
+
|
449
|
+
getWindow().requestAnimationFrame(() => {
|
450
|
+
this.setOption("pagination", pagination);
|
451
|
+
});
|
434
452
|
}
|
435
453
|
|
436
454
|
/**
|
@@ -440,88 +458,92 @@ function handleDataSourceChanges() {
|
|
440
458
|
* @return {object}
|
441
459
|
*/
|
442
460
|
function buildPagination(current, max) {
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
461
|
+
|
462
|
+
current = parseInt(current, 10);
|
463
|
+
max = parseInt(max, 10);
|
464
|
+
|
465
|
+
let prev = current === 1 ? null : current - 1;
|
466
|
+
let next = current === max ? null : current + 1;
|
467
|
+
const itemList = [1];
|
468
|
+
|
469
|
+
if (current > 4) itemList.push("…");
|
470
|
+
|
471
|
+
const r = 2;
|
472
|
+
const r1 = current - r;
|
473
|
+
const r2 = current + r;
|
474
|
+
|
475
|
+
for (let i = r1 > 2 ? r1 : 2; i <= Math.min(max, r2); i++) itemList.push(i);
|
476
|
+
|
477
|
+
if (r2 + 1 < max) itemList.push("…");
|
478
|
+
if (r2 < max) itemList.push(max);
|
479
|
+
|
480
|
+
let prevClass = "";
|
481
|
+
|
482
|
+
if (prev === null) {
|
483
|
+
prevClass = " disabled";
|
484
|
+
}
|
485
|
+
|
486
|
+
let nextClass = "";
|
487
|
+
if (next === null) {
|
488
|
+
nextClass = " disabled";
|
489
|
+
}
|
490
|
+
|
491
|
+
const items = itemList.map((item) => {
|
492
|
+
const p = `${item}`;
|
493
|
+
const c = `${current}`;
|
494
|
+
|
495
|
+
const obj = {
|
496
|
+
pageNo: item, // as integer
|
497
|
+
page: p, // as string
|
498
|
+
current: p === c,
|
499
|
+
class: (p === c ? "current" : "").trim(),
|
500
|
+
};
|
501
|
+
|
502
|
+
if (p === "…") {
|
503
|
+
obj.class += " disabled".trim();
|
504
|
+
}
|
505
|
+
|
506
|
+
const formatter = new Formatter(obj);
|
507
|
+
|
508
|
+
obj.description = formatter.format(this.getOption("labels.description"));
|
509
|
+
obj.label = formatter.format(this.getOption("labels.page"));
|
510
|
+
obj.href =
|
511
|
+
p === "…"
|
512
|
+
? "#"
|
513
|
+
: p === c
|
514
|
+
? "#"
|
515
|
+
: p === "1"
|
516
|
+
? "#"
|
517
|
+
: `#${formatter.format(this.getOption("href"))}`;
|
518
|
+
return obj;
|
519
|
+
});
|
520
|
+
|
521
|
+
const nextNo = next;
|
522
|
+
next = `${next}`;
|
523
|
+
|
524
|
+
const nextHref =
|
525
|
+
next === "null"
|
526
|
+
? "#"
|
527
|
+
: `#${new Formatter({page: next}).format(this.getOption("href"))}`;
|
528
|
+
const prevNo = prev;
|
529
|
+
prev = `${prev}`;
|
530
|
+
const prevHref =
|
531
|
+
prev === "null"
|
532
|
+
? "#"
|
533
|
+
: `#${new Formatter({page: prev}).format(this.getOption("href"))}`;
|
534
|
+
|
535
|
+
return {
|
536
|
+
current,
|
537
|
+
nextNo,
|
538
|
+
next,
|
539
|
+
nextClass,
|
540
|
+
nextHref,
|
541
|
+
prevNo,
|
542
|
+
prev,
|
543
|
+
prevClass,
|
544
|
+
prevHref,
|
545
|
+
items,
|
546
|
+
};
|
525
547
|
}
|
526
548
|
|
527
549
|
/**
|
@@ -529,8 +551,8 @@ function buildPagination(current, max) {
|
|
529
551
|
* @return {string}
|
530
552
|
*/
|
531
553
|
function getTemplate() {
|
532
|
-
|
533
|
-
|
554
|
+
// language=HTML
|
555
|
+
return `
|
534
556
|
<template id="items">
|
535
557
|
<li><a data-monster-attributes="class path:items.class,
|
536
558
|
href path:items.href,
|