@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.
Files changed (48) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/package.json +1 -1
  3. package/source/components/content/copy.mjs +1 -1
  4. package/source/components/datatable/dataset.mjs +29 -25
  5. package/source/components/datatable/datasource/dom.mjs +4 -6
  6. package/source/components/datatable/datasource/rest.mjs +472 -474
  7. package/source/components/datatable/datasource.mjs +0 -8
  8. package/source/components/datatable/pagination.mjs +434 -440
  9. package/source/components/datatable/status.mjs +1 -3
  10. package/source/components/datatable/stylesheet/pagination.mjs +13 -6
  11. package/source/components/datatable/util.mjs +1 -1
  12. package/source/components/form/api-bar.mjs +1 -1
  13. package/source/components/form/api-button.mjs +1 -1
  14. package/source/components/form/button-bar.mjs +1 -1
  15. package/source/components/form/button.mjs +2 -2
  16. package/source/components/form/confirm-button.mjs +1 -1
  17. package/source/components/form/form.mjs +7 -5
  18. package/source/components/form/select.mjs +2014 -2006
  19. package/source/components/form/style/field-set.pcss +9 -0
  20. package/source/components/form/style/toggle-switch.pcss +3 -0
  21. package/source/components/form/stylesheet/field-set.mjs +7 -14
  22. package/source/components/form/stylesheet/toggle-switch.mjs +7 -14
  23. package/source/components/form/toggle-switch.mjs +386 -334
  24. package/source/components/layout/tabs.mjs +900 -898
  25. package/source/components/layout/width-toggle.mjs +1 -1
  26. package/source/components/navigation/table-of-content.mjs +1 -1
  27. package/source/components/notify/message.mjs +11 -15
  28. package/source/components/notify/notify.mjs +11 -15
  29. package/source/components/notify/stylesheet/notify.mjs +13 -6
  30. package/source/components/state/log.mjs +185 -185
  31. package/source/components/state/state.mjs +1 -1
  32. package/source/components/state/stylesheet/log.mjs +13 -6
  33. package/source/components/style/theme.css +4 -4
  34. package/source/data/datasource/server/restapi.mjs +2 -3
  35. package/source/data/transformer.mjs +803 -806
  36. package/source/dom/constants.mjs +8 -5
  37. package/source/dom/customelement.mjs +0 -34
  38. package/source/dom/updater.mjs +764 -767
  39. package/source/i18n/time-ago.mjs +1352 -636
  40. package/source/monster.mjs +2 -0
  41. package/source/types/has.mjs +3 -6
  42. package/source/types/version.mjs +1 -1
  43. package/test/cases/components/form/form.mjs +166 -125
  44. package/test/cases/components/form/toggle-switch.mjs +80 -65
  45. package/test/cases/monster.mjs +1 -1
  46. package/test/web/import.js +1 -0
  47. package/test/web/test.html +2 -2
  48. package/test/web/tests.js +2080 -1433
@@ -13,32 +13,32 @@
13
13
  */
14
14
 
15
15
  import {
16
- assembleMethodSymbol,
17
- CustomElement,
18
- registerCustomElement,
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
- 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
- }
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
- if (!this.shadowRoot) {
304
- throw new Error("no shadow-root is defined");
305
- }
301
+ if (!this.shadowRoot) {
302
+ throw new Error("no shadow-root is defined");
303
+ }
306
304
 
307
- this[paginationElementSymbol] = this.shadowRoot.querySelector(
308
- "[data-monster-role=pagination]",
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
- 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
- });
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
- const options = {};
401
- const selector = this.getAttribute(ATTRIBUTE_DATASOURCE_SELECTOR);
402
- if (selector) {
403
- options.datasource = {selector: selector};
404
- }
398
+ const options = {};
399
+ const selector = this.getAttribute(ATTRIBUTE_DATASOURCE_SELECTOR);
400
+ if (selector) {
401
+ options.datasource = { selector: selector };
402
+ }
405
403
 
406
- return options;
404
+ return options;
407
405
  }
408
406
 
409
407
  /**
410
408
  * @private
411
409
  */
412
410
  function handleDataSourceChanges() {
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
- });
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
- 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
- };
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
- // language=HTML
555
- return `
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,