@schukai/monster 3.95.2 → 3.96.1
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 +26 -0
- package/package.json +1 -1
- package/source/components/content/copy.mjs +1 -1
- package/source/components/datatable/dataset.mjs +29 -25
- package/source/components/datatable/datasource/dom.mjs +4 -6
- package/source/components/datatable/datasource/rest.mjs +472 -474
- package/source/components/datatable/datasource.mjs +0 -8
- package/source/components/datatable/pagination.mjs +434 -440
- package/source/components/datatable/status.mjs +1 -3
- package/source/components/datatable/stylesheet/pagination.mjs +13 -6
- package/source/components/datatable/util.mjs +1 -1
- package/source/components/form/api-bar.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 +2 -2
- package/source/components/form/confirm-button.mjs +1 -1
- package/source/components/form/form.mjs +7 -5
- package/source/components/form/select.mjs +2014 -2006
- package/source/components/form/style/field-set.pcss +9 -0
- package/source/components/form/style/toggle-switch.pcss +3 -0
- package/source/components/form/stylesheet/field-set.mjs +7 -14
- package/source/components/form/stylesheet/toggle-switch.mjs +7 -14
- package/source/components/form/toggle-switch.mjs +386 -334
- package/source/components/layout/tabs.mjs +900 -898
- package/source/components/layout/width-toggle.mjs +1 -1
- package/source/components/navigation/table-of-content.mjs +1 -1
- package/source/components/notify/message.mjs +11 -15
- package/source/components/notify/notify.mjs +11 -15
- package/source/components/notify/stylesheet/notify.mjs +13 -6
- package/source/components/state/log.mjs +185 -185
- package/source/components/state/state.mjs +1 -1
- package/source/components/state/stylesheet/log.mjs +13 -6
- package/source/components/style/theme.css +4 -4
- package/source/data/datasource/server/restapi.mjs +2 -3
- package/source/data/transformer.mjs +803 -806
- package/source/dom/constants.mjs +8 -5
- package/source/dom/customelement.mjs +0 -34
- package/source/dom/updater.mjs +764 -767
- package/source/i18n/time-ago.mjs +1352 -636
- package/source/monster.mjs +2 -0
- package/source/types/has.mjs +3 -6
- package/source/types/version.mjs +1 -1
- package/test/cases/components/form/form.mjs +166 -125
- package/test/cases/components/form/toggle-switch.mjs +80 -65
- package/test/cases/monster.mjs +1 -1
- package/test/web/import.js +1 -0
- package/test/web/test.html +2 -2
- package/test/web/tests.js +2080 -1433
@@ -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 {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";
|
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 {addAttributeToken} from "../../dom/attributes.mjs";
|
36
|
-
import {ATTRIBUTE_ERRORMESSAGE} from "../../dom/constants.mjs";
|
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 {Pagination};
|
41
|
+
export { Pagination };
|
42
42
|
|
43
43
|
/**
|
44
44
|
* @private
|
@@ -75,223 +75,221 @@ const debounceSizeSymbol = Symbol("debounceSize");
|
|
75
75
|
*
|
76
76
|
* @fragments /fragments/components/datatable/pagination
|
77
77
|
*
|
78
|
-
* @example /examples/components/datatable/pagination-simple
|
78
|
+
* @example /examples/components/datatable/pagination-simple Pagination
|
79
79
|
*
|
80
80
|
* @copyright schukai GmbH
|
81
81
|
* @summary The Pagination component is used to show the current page and the total number of pages.
|
82
82
|
*/
|
83
83
|
class Pagination extends CustomElement {
|
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
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
return [this.getControlCSSStyleSheet(), DisplayStyleSheet, ThemeStyleSheet];
|
294
|
-
}
|
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(new Observer(handleDataSourceChanges.bind(this)));
|
274
|
+
|
275
|
+
handleDataSourceChanges.call(this);
|
276
|
+
}
|
277
|
+
}
|
278
|
+
|
279
|
+
/**
|
280
|
+
* @private
|
281
|
+
* @return {CSSStyleSheet}
|
282
|
+
*/
|
283
|
+
static getControlCSSStyleSheet() {
|
284
|
+
return PaginationStyleSheet;
|
285
|
+
}
|
286
|
+
|
287
|
+
/**
|
288
|
+
* @return {CSSStyleSheet[]}
|
289
|
+
*/
|
290
|
+
static getCSSStyleSheet() {
|
291
|
+
return [this.getControlCSSStyleSheet(), DisplayStyleSheet, ThemeStyleSheet];
|
292
|
+
}
|
295
293
|
}
|
296
294
|
|
297
295
|
/**
|
@@ -300,88 +298,88 @@ class Pagination extends CustomElement {
|
|
300
298
|
* @throws {Error} no shadow-root is defined
|
301
299
|
*/
|
302
300
|
function initControlReferences() {
|
303
|
-
|
304
|
-
|
305
|
-
|
301
|
+
if (!this.shadowRoot) {
|
302
|
+
throw new Error("no shadow-root is defined");
|
303
|
+
}
|
306
304
|
|
307
|
-
|
308
|
-
|
309
|
-
|
305
|
+
this[paginationElementSymbol] = this.shadowRoot.querySelector(
|
306
|
+
"[data-monster-role=pagination]",
|
307
|
+
);
|
310
308
|
}
|
311
309
|
|
312
310
|
/**
|
313
311
|
* @private
|
314
312
|
*/
|
315
313
|
function initEventHandler() {
|
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
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
314
|
+
const self = this;
|
315
|
+
|
316
|
+
self[paginationElementSymbol].addEventListener("click", function (event) {
|
317
|
+
let element = null;
|
318
|
+
const datasource = self[datasourceLinkedElementSymbol];
|
319
|
+
if (!datasource) {
|
320
|
+
return;
|
321
|
+
}
|
322
|
+
|
323
|
+
element = findTargetElementFromEvent(
|
324
|
+
event,
|
325
|
+
ATTRIBUTE_ROLE,
|
326
|
+
"pagination-item",
|
327
|
+
);
|
328
|
+
|
329
|
+
if (!element) {
|
330
|
+
element = findTargetElementFromEvent(
|
331
|
+
event,
|
332
|
+
ATTRIBUTE_ROLE,
|
333
|
+
"pagination-next",
|
334
|
+
);
|
335
|
+
if (!element) {
|
336
|
+
element = findTargetElementFromEvent(
|
337
|
+
event,
|
338
|
+
ATTRIBUTE_ROLE,
|
339
|
+
"pagination-prev",
|
340
|
+
);
|
341
|
+
if (!element) {
|
342
|
+
return;
|
343
|
+
}
|
344
|
+
}
|
345
|
+
}
|
346
|
+
|
347
|
+
if (!(element instanceof HTMLElement)) {
|
348
|
+
return;
|
349
|
+
}
|
350
|
+
|
351
|
+
let page = null;
|
352
|
+
|
353
|
+
if (!element.hasAttribute("data-page-no")) {
|
354
|
+
return;
|
355
|
+
}
|
356
|
+
|
357
|
+
page = element.getAttribute("data-page-no");
|
358
|
+
|
359
|
+
if (
|
360
|
+
!page ||
|
361
|
+
page === "" ||
|
362
|
+
page === null ||
|
363
|
+
page === undefined ||
|
364
|
+
page === "undefined" ||
|
365
|
+
page === "null"
|
366
|
+
) {
|
367
|
+
return;
|
368
|
+
}
|
369
|
+
|
370
|
+
if (typeof datasource.setParameters !== "function") {
|
371
|
+
return;
|
372
|
+
}
|
373
|
+
|
374
|
+
event.preventDefault();
|
375
|
+
datasource.setParameters({ page });
|
376
|
+
|
377
|
+
if (typeof datasource.reload !== "function") {
|
378
|
+
return;
|
379
|
+
}
|
380
|
+
|
381
|
+
datasource.reload();
|
382
|
+
});
|
385
383
|
}
|
386
384
|
|
387
385
|
/**
|
@@ -397,58 +395,55 @@ function initEventHandler() {
|
|
397
395
|
* @throws {Error} the datasource could not be initialized
|
398
396
|
*/
|
399
397
|
function initOptionsFromArguments() {
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
398
|
+
const options = {};
|
399
|
+
const selector = this.getAttribute(ATTRIBUTE_DATASOURCE_SELECTOR);
|
400
|
+
if (selector) {
|
401
|
+
options.datasource = { selector: selector };
|
402
|
+
}
|
405
403
|
|
406
|
-
|
404
|
+
return options;
|
407
405
|
}
|
408
406
|
|
409
407
|
/**
|
410
408
|
* @private
|
411
409
|
*/
|
412
410
|
function handleDataSourceChanges() {
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
getWindow().requestAnimationFrame(() => {
|
450
|
-
this.setOption("pagination", pagination);
|
451
|
-
});
|
411
|
+
let pagination;
|
412
|
+
|
413
|
+
if (!this[datasourceLinkedElementSymbol]) {
|
414
|
+
return;
|
415
|
+
}
|
416
|
+
|
417
|
+
const mapping = this.getOption("mapping");
|
418
|
+
const pf = new Pathfinder(this[datasourceLinkedElementSymbol].data);
|
419
|
+
|
420
|
+
for (const key in mapping) {
|
421
|
+
const path = mapping[key];
|
422
|
+
|
423
|
+
if (pf.exists(path)) {
|
424
|
+
const value = pf.getVia(path);
|
425
|
+
this.setOption(key, value);
|
426
|
+
}
|
427
|
+
|
428
|
+
const o = this[datasourceLinkedElementSymbol].getOption(path);
|
429
|
+
if (o !== undefined && o !== null) {
|
430
|
+
this.setOption(key, o);
|
431
|
+
}
|
432
|
+
}
|
433
|
+
|
434
|
+
pagination = buildPagination.call(
|
435
|
+
this,
|
436
|
+
this.getOption("currentPage"),
|
437
|
+
this.getOption("pages"),
|
438
|
+
);
|
439
|
+
|
440
|
+
if (this?.[sizeDataSymbol]?.showNumbers !== true) {
|
441
|
+
pagination.items = [];
|
442
|
+
}
|
443
|
+
|
444
|
+
getWindow().requestAnimationFrame(() => {
|
445
|
+
this.setOption("pagination", pagination);
|
446
|
+
});
|
452
447
|
}
|
453
448
|
|
454
449
|
/**
|
@@ -458,92 +453,91 @@ function handleDataSourceChanges() {
|
|
458
453
|
* @return {object}
|
459
454
|
*/
|
460
455
|
function buildPagination(current, max) {
|
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
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
};
|
456
|
+
current = parseInt(current, 10);
|
457
|
+
max = parseInt(max, 10);
|
458
|
+
|
459
|
+
let prev = current === 1 ? null : current - 1;
|
460
|
+
let next = current === max ? null : current + 1;
|
461
|
+
const itemList = [1];
|
462
|
+
|
463
|
+
if (current > 4) itemList.push("…");
|
464
|
+
|
465
|
+
const r = 2;
|
466
|
+
const r1 = current - r;
|
467
|
+
const r2 = current + r;
|
468
|
+
|
469
|
+
for (let i = r1 > 2 ? r1 : 2; i <= Math.min(max, r2); i++) itemList.push(i);
|
470
|
+
|
471
|
+
if (r2 + 1 < max) itemList.push("…");
|
472
|
+
if (r2 < max) itemList.push(max);
|
473
|
+
|
474
|
+
let prevClass = "";
|
475
|
+
|
476
|
+
if (prev === null) {
|
477
|
+
prevClass = " disabled";
|
478
|
+
}
|
479
|
+
|
480
|
+
let nextClass = "";
|
481
|
+
if (next === null) {
|
482
|
+
nextClass = " disabled";
|
483
|
+
}
|
484
|
+
|
485
|
+
const items = itemList.map((item) => {
|
486
|
+
const p = `${item}`;
|
487
|
+
const c = `${current}`;
|
488
|
+
|
489
|
+
const obj = {
|
490
|
+
pageNo: item, // as integer
|
491
|
+
page: p, // as string
|
492
|
+
current: p === c,
|
493
|
+
class: (p === c ? "current" : "").trim(),
|
494
|
+
};
|
495
|
+
|
496
|
+
if (p === "…") {
|
497
|
+
obj.class += " disabled".trim();
|
498
|
+
}
|
499
|
+
|
500
|
+
const formatter = new Formatter(obj);
|
501
|
+
|
502
|
+
obj.description = formatter.format(this.getOption("labels.description"));
|
503
|
+
obj.label = formatter.format(this.getOption("labels.page"));
|
504
|
+
obj.href =
|
505
|
+
p === "…"
|
506
|
+
? "#"
|
507
|
+
: p === c
|
508
|
+
? "#"
|
509
|
+
: p === "1"
|
510
|
+
? "#"
|
511
|
+
: `#${formatter.format(this.getOption("href"))}`;
|
512
|
+
return obj;
|
513
|
+
});
|
514
|
+
|
515
|
+
const nextNo = next;
|
516
|
+
next = `${next}`;
|
517
|
+
|
518
|
+
const nextHref =
|
519
|
+
next === "null"
|
520
|
+
? "#"
|
521
|
+
: `#${new Formatter({ page: next }).format(this.getOption("href"))}`;
|
522
|
+
const prevNo = prev;
|
523
|
+
prev = `${prev}`;
|
524
|
+
const prevHref =
|
525
|
+
prev === "null"
|
526
|
+
? "#"
|
527
|
+
: `#${new Formatter({ page: prev }).format(this.getOption("href"))}`;
|
528
|
+
|
529
|
+
return {
|
530
|
+
current,
|
531
|
+
nextNo,
|
532
|
+
next,
|
533
|
+
nextClass,
|
534
|
+
nextHref,
|
535
|
+
prevNo,
|
536
|
+
prev,
|
537
|
+
prevClass,
|
538
|
+
prevHref,
|
539
|
+
items,
|
540
|
+
};
|
547
541
|
}
|
548
542
|
|
549
543
|
/**
|
@@ -551,8 +545,8 @@ function buildPagination(current, max) {
|
|
551
545
|
* @return {string}
|
552
546
|
*/
|
553
547
|
function getTemplate() {
|
554
|
-
|
555
|
-
|
548
|
+
// language=HTML
|
549
|
+
return `
|
556
550
|
<template id="items">
|
557
551
|
<li><a data-monster-attributes="class path:items.class,
|
558
552
|
href path:items.href,
|