@schukai/monster 4.92.0 → 4.94.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/columnbar.mjs +204 -0
- package/source/components/datatable/pagination.mjs +512 -11
- package/source/components/datatable/style/column-bar.pcss +17 -2
- package/source/components/datatable/style/embedded-pagination.pcss +65 -0
- package/source/components/datatable/style/pagination.pcss +57 -1
- package/source/components/datatable/stylesheet/column-bar.mjs +1 -1
- package/source/components/datatable/stylesheet/embedded-pagination.mjs +1 -1
- package/source/components/datatable/stylesheet/pagination.mjs +1 -1
- package/source/text/formatter.mjs +75 -6
- package/test/cases/text/formatter.mjs +26 -2
|
@@ -71,6 +71,28 @@ const sizeDataSymbol = Symbol("sizeData");
|
|
|
71
71
|
*/
|
|
72
72
|
const debounceSizeSymbol = Symbol("debounceSize");
|
|
73
73
|
|
|
74
|
+
/**
|
|
75
|
+
* @private
|
|
76
|
+
* @type {symbol}
|
|
77
|
+
*/
|
|
78
|
+
const layoutUpdateSymbol = Symbol("layoutUpdate");
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @private
|
|
82
|
+
* @type {symbol}
|
|
83
|
+
*/
|
|
84
|
+
const layoutApplySymbol = Symbol("layoutApply");
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @private
|
|
88
|
+
* @type {symbol}
|
|
89
|
+
*/
|
|
90
|
+
const labelStateSymbol = Symbol("labelState");
|
|
91
|
+
const layoutModeSymbol = Symbol("layoutMode");
|
|
92
|
+
|
|
93
|
+
const compactPrevIcon = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M8 0a8 8 0 1 0 0 16A8 8 0 0 0 8 0m3.5 7.5a.5.5 0 0 1 0 1H5.707l2.147 2.146a.5.5 0 0 1-.708.708l-3-3a.5.5 0 0 1 0-.708l3-3a.5.5 0 1 1 .708.708L5.707 7.5z"/></svg>`;
|
|
94
|
+
const compactNextIcon = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M8 0a8 8 0 1 1 0 16A8 8 0 0 1 8 0M4.5 7.5a.5.5 0 0 0 0 1h5.793l-2.147 2.146a.5.5 0 0 0 .708.708l3-3a.5.5 0 0 0 0-.708l-3-3a.5.5 0 1 0-.708.708L10.293 7.5z"/></svg>`;
|
|
95
|
+
|
|
74
96
|
/**
|
|
75
97
|
* A Pagination component
|
|
76
98
|
*
|
|
@@ -190,12 +212,23 @@ class Pagination extends CustomElement {
|
|
|
190
212
|
);
|
|
191
213
|
|
|
192
214
|
// 3. Preserve the responsive visibility of page numbers.
|
|
193
|
-
if (
|
|
215
|
+
if (
|
|
216
|
+
!isAdaptivePagination.call(this) &&
|
|
217
|
+
this?.[sizeDataSymbol]?.showNumbers !== true
|
|
218
|
+
) {
|
|
194
219
|
pagination.items = [];
|
|
195
220
|
}
|
|
196
221
|
|
|
197
222
|
// 4. Set the 'pagination' option, which will trigger the component to re-render.
|
|
198
223
|
this.setOption("pagination", pagination);
|
|
224
|
+
|
|
225
|
+
if (isAdaptivePagination.call(this)) {
|
|
226
|
+
const list = this.shadowRoot?.querySelector(".pagination-list");
|
|
227
|
+
if (list) {
|
|
228
|
+
list.setAttribute("data-monster-adaptive-ready", "false");
|
|
229
|
+
}
|
|
230
|
+
schedulePaginationLayoutUpdate.call(this);
|
|
231
|
+
}
|
|
199
232
|
}
|
|
200
233
|
/**
|
|
201
234
|
*
|
|
@@ -243,17 +276,10 @@ class Pagination extends CustomElement {
|
|
|
243
276
|
setTimeout(() => {
|
|
244
277
|
const parentParentNode = parentNode?.parentNode || parentNode;
|
|
245
278
|
|
|
246
|
-
const parentWidth = parentParentNode.offsetWidth;
|
|
247
|
-
const ownWidth = this.offsetWidth;
|
|
248
|
-
|
|
249
|
-
this[sizeDataSymbol] = {
|
|
250
|
-
last: {
|
|
251
|
-
parentWidth: 0,
|
|
252
|
-
},
|
|
253
|
-
showNumbers: ownWidth < parentWidth,
|
|
254
|
-
};
|
|
255
|
-
|
|
256
279
|
this[resizeObserverSymbol] = new ResizeObserver(() => {
|
|
280
|
+
if (this[layoutApplySymbol]) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
257
283
|
if (this[debounceSizeSymbol] instanceof DeadMansSwitch) {
|
|
258
284
|
try {
|
|
259
285
|
this[debounceSizeSymbol].touch();
|
|
@@ -265,6 +291,11 @@ class Pagination extends CustomElement {
|
|
|
265
291
|
|
|
266
292
|
this[debounceSizeSymbol] = new DeadMansSwitch(250, () => {
|
|
267
293
|
queueMicrotask(() => {
|
|
294
|
+
if (isAdaptivePagination.call(this)) {
|
|
295
|
+
schedulePaginationLayoutUpdate.call(this);
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
|
|
268
299
|
const parentWidth = parentParentNode.offsetWidth;
|
|
269
300
|
const ownWidth = this.clientWidth;
|
|
270
301
|
|
|
@@ -282,6 +313,26 @@ class Pagination extends CustomElement {
|
|
|
282
313
|
});
|
|
283
314
|
});
|
|
284
315
|
|
|
316
|
+
if (isAdaptivePagination.call(this)) {
|
|
317
|
+
this[sizeDataSymbol] = {
|
|
318
|
+
last: {
|
|
319
|
+
parentWidth: 0,
|
|
320
|
+
},
|
|
321
|
+
showNumbers: true,
|
|
322
|
+
};
|
|
323
|
+
schedulePaginationLayoutUpdate.call(this);
|
|
324
|
+
} else {
|
|
325
|
+
const parentWidth = parentParentNode.offsetWidth;
|
|
326
|
+
const ownWidth = this.offsetWidth;
|
|
327
|
+
|
|
328
|
+
this[sizeDataSymbol] = {
|
|
329
|
+
last: {
|
|
330
|
+
parentWidth: 0,
|
|
331
|
+
},
|
|
332
|
+
showNumbers: ownWidth < parentWidth,
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
|
|
285
336
|
this[resizeObserverSymbol].observe(parentParentNode);
|
|
286
337
|
}, 0);
|
|
287
338
|
}
|
|
@@ -344,6 +395,7 @@ function getTranslations() {
|
|
|
344
395
|
previous: "Vorherige",
|
|
345
396
|
next: "Nächste",
|
|
346
397
|
of: "von",
|
|
398
|
+
summary: "Seite ${current} von ${max}",
|
|
347
399
|
};
|
|
348
400
|
case "fr":
|
|
349
401
|
return {
|
|
@@ -352,6 +404,7 @@ function getTranslations() {
|
|
|
352
404
|
previous: "Précédent",
|
|
353
405
|
next: "Suivant",
|
|
354
406
|
of: "de",
|
|
407
|
+
summary: "Page ${current} sur ${max}",
|
|
355
408
|
};
|
|
356
409
|
case "sp":
|
|
357
410
|
return {
|
|
@@ -360,6 +413,7 @@ function getTranslations() {
|
|
|
360
413
|
previous: "Anterior",
|
|
361
414
|
next: "Siguiente",
|
|
362
415
|
of: "de",
|
|
416
|
+
summary: "Página ${current} de ${max}",
|
|
363
417
|
};
|
|
364
418
|
case "it":
|
|
365
419
|
return {
|
|
@@ -368,6 +422,7 @@ function getTranslations() {
|
|
|
368
422
|
previous: "Precedente",
|
|
369
423
|
next: "Successivo",
|
|
370
424
|
of: "di",
|
|
425
|
+
summary: "Pagina ${current} di ${max}",
|
|
371
426
|
};
|
|
372
427
|
case "pl":
|
|
373
428
|
return {
|
|
@@ -376,6 +431,7 @@ function getTranslations() {
|
|
|
376
431
|
previous: "Poprzednia",
|
|
377
432
|
next: "Następna",
|
|
378
433
|
of: "z",
|
|
434
|
+
summary: "Strona ${current} z ${max}",
|
|
379
435
|
};
|
|
380
436
|
case "no":
|
|
381
437
|
return {
|
|
@@ -384,6 +440,7 @@ function getTranslations() {
|
|
|
384
440
|
previous: "Forrige",
|
|
385
441
|
next: "Neste",
|
|
386
442
|
of: "av",
|
|
443
|
+
summary: "Side ${current} av ${max}",
|
|
387
444
|
};
|
|
388
445
|
case "dk":
|
|
389
446
|
return {
|
|
@@ -392,6 +449,7 @@ function getTranslations() {
|
|
|
392
449
|
previous: "Forrige",
|
|
393
450
|
next: "Næste",
|
|
394
451
|
of: "af",
|
|
452
|
+
summary: "Side ${current} af ${max}",
|
|
395
453
|
};
|
|
396
454
|
case "sw":
|
|
397
455
|
return {
|
|
@@ -400,6 +458,7 @@ function getTranslations() {
|
|
|
400
458
|
previous: "Föregående",
|
|
401
459
|
next: "Nästa",
|
|
402
460
|
of: "av",
|
|
461
|
+
summary: "Sida ${current} av ${max}",
|
|
403
462
|
};
|
|
404
463
|
default:
|
|
405
464
|
case "en":
|
|
@@ -409,6 +468,7 @@ function getTranslations() {
|
|
|
409
468
|
previous: "Previous",
|
|
410
469
|
next: "Next",
|
|
411
470
|
of: "of",
|
|
471
|
+
summary: "${current} of ${max}",
|
|
412
472
|
};
|
|
413
473
|
}
|
|
414
474
|
}
|
|
@@ -470,6 +530,44 @@ function initEventHandler() {
|
|
|
470
530
|
clickCallback(parseInt(page, 10), event);
|
|
471
531
|
}
|
|
472
532
|
});
|
|
533
|
+
|
|
534
|
+
self[paginationElementSymbol].addEventListener("dblclick", function (event) {
|
|
535
|
+
const prevTarget = findTargetElementFromEvent(
|
|
536
|
+
event,
|
|
537
|
+
ATTRIBUTE_ROLE,
|
|
538
|
+
"pagination-prev",
|
|
539
|
+
);
|
|
540
|
+
const nextTarget = findTargetElementFromEvent(
|
|
541
|
+
event,
|
|
542
|
+
ATTRIBUTE_ROLE,
|
|
543
|
+
"pagination-next",
|
|
544
|
+
);
|
|
545
|
+
|
|
546
|
+
if (!prevTarget && !nextTarget) {
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
event.preventDefault();
|
|
551
|
+
|
|
552
|
+
const maxPage = parseInt(self.getOption("pages"), 10);
|
|
553
|
+
if (!Number.isFinite(maxPage) || maxPage <= 0) {
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
const targetPage = prevTarget ? 1 : maxPage;
|
|
558
|
+
|
|
559
|
+
const datasource = self[datasourceLinkedElementSymbol];
|
|
560
|
+
const clickCallback = self.getOption("callbacks.click");
|
|
561
|
+
|
|
562
|
+
if (datasource && typeof datasource.setParameters === "function") {
|
|
563
|
+
datasource.setParameters({ page: targetPage });
|
|
564
|
+
if (typeof datasource.reload === "function") {
|
|
565
|
+
datasource.reload();
|
|
566
|
+
}
|
|
567
|
+
} else if (typeof clickCallback === "function") {
|
|
568
|
+
clickCallback(targetPage, event);
|
|
569
|
+
}
|
|
570
|
+
});
|
|
473
571
|
}
|
|
474
572
|
|
|
475
573
|
/**
|
|
@@ -531,6 +629,10 @@ function handleDataSourceChanges() {
|
|
|
531
629
|
}
|
|
532
630
|
|
|
533
631
|
this.setOption("pagination", pagination);
|
|
632
|
+
|
|
633
|
+
if (isEmbeddedPagination.call(this)) {
|
|
634
|
+
schedulePaginationLayoutUpdate.call(this);
|
|
635
|
+
}
|
|
534
636
|
}
|
|
535
637
|
|
|
536
638
|
/**
|
|
@@ -618,6 +720,16 @@ function buildPagination(current, max) {
|
|
|
618
720
|
prev === "null"
|
|
619
721
|
? "#"
|
|
620
722
|
: `#${new Formatter({ page: prev }).format(this.getOption("href"))}`;
|
|
723
|
+
const ofLabel = this.getOption("labels.of") || "of";
|
|
724
|
+
const summaryTemplate = this.getOption("labels.summary");
|
|
725
|
+
const summaryContext = {
|
|
726
|
+
current: String(current),
|
|
727
|
+
max: String(max),
|
|
728
|
+
of: String(ofLabel),
|
|
729
|
+
};
|
|
730
|
+
const summary = isString(summaryTemplate)
|
|
731
|
+
? new Formatter(summaryContext).format(summaryTemplate)
|
|
732
|
+
: `${summaryContext.current} ${summaryContext.of} ${summaryContext.max}`;
|
|
621
733
|
|
|
622
734
|
return {
|
|
623
735
|
current,
|
|
@@ -629,10 +741,395 @@ function buildPagination(current, max) {
|
|
|
629
741
|
prev,
|
|
630
742
|
prevClass,
|
|
631
743
|
prevHref,
|
|
744
|
+
summary,
|
|
632
745
|
items,
|
|
633
746
|
};
|
|
634
747
|
}
|
|
635
748
|
|
|
749
|
+
/**
|
|
750
|
+
* @private
|
|
751
|
+
*/
|
|
752
|
+
function schedulePaginationLayoutUpdate() {
|
|
753
|
+
if (!isAdaptivePagination.call(this)) {
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
if (this[layoutUpdateSymbol] || this[layoutApplySymbol]) {
|
|
757
|
+
return;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
this[layoutUpdateSymbol] = true;
|
|
761
|
+
requestAnimationFrame(() => {
|
|
762
|
+
this[layoutUpdateSymbol] = false;
|
|
763
|
+
applyPaginationLayout.call(this);
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* @private
|
|
769
|
+
*/
|
|
770
|
+
function applyPaginationLayout() {
|
|
771
|
+
if (!this.isConnected || !this.shadowRoot) {
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
if (!isAdaptivePagination.call(this)) {
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
const parentNode = this.parentNode;
|
|
780
|
+
const parentParentNode = parentNode?.parentNode || parentNode;
|
|
781
|
+
const availableWidth = isSelectPagination.call(this)
|
|
782
|
+
? getSelectAvailableWidth.call(this, parentNode)
|
|
783
|
+
: isEmbeddedPagination.call(this)
|
|
784
|
+
? getEmbeddedAvailableWidth.call(this, parentNode)
|
|
785
|
+
: this.getBoundingClientRect().width ||
|
|
786
|
+
parentParentNode?.offsetWidth ||
|
|
787
|
+
0;
|
|
788
|
+
|
|
789
|
+
if (!availableWidth) {
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
this[layoutApplySymbol] = true;
|
|
794
|
+
try {
|
|
795
|
+
ensureLabelState.call(this);
|
|
796
|
+
|
|
797
|
+
const list = this.shadowRoot.querySelector(".pagination-list");
|
|
798
|
+
if (!list) {
|
|
799
|
+
return;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
list.classList.add("pagination-no-wrap");
|
|
803
|
+
list.setAttribute("data-monster-adaptive-ready", "false");
|
|
804
|
+
|
|
805
|
+
const prevLink = this.shadowRoot.querySelector(
|
|
806
|
+
"a[data-monster-role=pagination-prev]",
|
|
807
|
+
);
|
|
808
|
+
const nextLink = this.shadowRoot.querySelector(
|
|
809
|
+
"a[data-monster-role=pagination-next]",
|
|
810
|
+
);
|
|
811
|
+
|
|
812
|
+
const widthFull = applyPaginationMode.call(
|
|
813
|
+
this,
|
|
814
|
+
list,
|
|
815
|
+
prevLink,
|
|
816
|
+
nextLink,
|
|
817
|
+
"full",
|
|
818
|
+
);
|
|
819
|
+
const widthNoNumbers = applyPaginationMode.call(
|
|
820
|
+
this,
|
|
821
|
+
list,
|
|
822
|
+
prevLink,
|
|
823
|
+
nextLink,
|
|
824
|
+
"no-numbers",
|
|
825
|
+
);
|
|
826
|
+
const widthCompactSummary = applyPaginationMode.call(
|
|
827
|
+
this,
|
|
828
|
+
list,
|
|
829
|
+
prevLink,
|
|
830
|
+
nextLink,
|
|
831
|
+
"compact-summary",
|
|
832
|
+
);
|
|
833
|
+
const widthCompact = applyPaginationMode.call(
|
|
834
|
+
this,
|
|
835
|
+
list,
|
|
836
|
+
prevLink,
|
|
837
|
+
nextLink,
|
|
838
|
+
"compact",
|
|
839
|
+
);
|
|
840
|
+
|
|
841
|
+
const nextMode = choosePaginationMode.call(this, {
|
|
842
|
+
availableWidth,
|
|
843
|
+
widthFull,
|
|
844
|
+
widthNoNumbers,
|
|
845
|
+
widthCompactSummary,
|
|
846
|
+
widthCompact,
|
|
847
|
+
});
|
|
848
|
+
|
|
849
|
+
applyPaginationMode.call(this, list, prevLink, nextLink, nextMode);
|
|
850
|
+
list.setAttribute("data-monster-adaptive-ready", "true");
|
|
851
|
+
} finally {
|
|
852
|
+
this[layoutApplySymbol] = false;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
/**
|
|
857
|
+
* @private
|
|
858
|
+
* @param {number} parentWidth
|
|
859
|
+
* @return {boolean}
|
|
860
|
+
*/
|
|
861
|
+
function paginationFits(parentWidth) {
|
|
862
|
+
const list = this.shadowRoot.querySelector(".pagination-list");
|
|
863
|
+
if (!list) {
|
|
864
|
+
return true;
|
|
865
|
+
}
|
|
866
|
+
return list.scrollWidth <= parentWidth;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* @private
|
|
871
|
+
* @param {HTMLElement} list
|
|
872
|
+
* @param {boolean} visible
|
|
873
|
+
*/
|
|
874
|
+
function setNumberItemsVisible(list, visible) {
|
|
875
|
+
const numberItems = list.querySelectorAll(
|
|
876
|
+
"[data-monster-role=pagination-item]",
|
|
877
|
+
);
|
|
878
|
+
for (const item of numberItems) {
|
|
879
|
+
const container = item.parentElement;
|
|
880
|
+
if (!container) continue;
|
|
881
|
+
container.style.display = visible ? "" : "none";
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
/**
|
|
886
|
+
* @private
|
|
887
|
+
* @param {HTMLElement} list
|
|
888
|
+
* @param {boolean} visible
|
|
889
|
+
*/
|
|
890
|
+
function setSummaryVisible(list, visible) {
|
|
891
|
+
const summaryItem = list.querySelector(
|
|
892
|
+
"[data-monster-role=pagination-summary]",
|
|
893
|
+
);
|
|
894
|
+
if (!summaryItem) {
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
summaryItem.style.display = visible ? "flex" : "none";
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
/**
|
|
901
|
+
* @private
|
|
902
|
+
*/
|
|
903
|
+
function ensureLabelState() {
|
|
904
|
+
if (this[labelStateSymbol]) {
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
const prevLink = this.shadowRoot?.querySelector(
|
|
909
|
+
"a[data-monster-role=pagination-prev]",
|
|
910
|
+
);
|
|
911
|
+
const nextLink = this.shadowRoot?.querySelector(
|
|
912
|
+
"a[data-monster-role=pagination-next]",
|
|
913
|
+
);
|
|
914
|
+
|
|
915
|
+
this[labelStateSymbol] = {
|
|
916
|
+
previous: prevLink?.innerHTML || this.getOption("labels.previous"),
|
|
917
|
+
next: nextLink?.innerHTML || this.getOption("labels.next"),
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
/**
|
|
922
|
+
* @private
|
|
923
|
+
* @param {boolean} compact
|
|
924
|
+
*/
|
|
925
|
+
function setCompactLabels(compact, prevLink, nextLink) {
|
|
926
|
+
const state = this[labelStateSymbol];
|
|
927
|
+
if (!state) return;
|
|
928
|
+
|
|
929
|
+
if (compact) {
|
|
930
|
+
if (prevLink) prevLink.innerHTML = compactPrevIcon;
|
|
931
|
+
if (nextLink) nextLink.innerHTML = compactNextIcon;
|
|
932
|
+
} else {
|
|
933
|
+
if (prevLink) prevLink.innerHTML = state.previous;
|
|
934
|
+
if (nextLink) nextLink.innerHTML = state.next;
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
/**
|
|
939
|
+
* @private
|
|
940
|
+
* @return {boolean}
|
|
941
|
+
*/
|
|
942
|
+
function isEmbeddedPagination() {
|
|
943
|
+
return this?.tagName?.toLowerCase?.() === "monster-embedded-pagination";
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
/**
|
|
947
|
+
* @private
|
|
948
|
+
* @return {boolean}
|
|
949
|
+
*/
|
|
950
|
+
function isSelectPagination() {
|
|
951
|
+
const root = this.getRootNode?.();
|
|
952
|
+
const host = root?.host;
|
|
953
|
+
return host?.tagName?.toLowerCase?.() === "monster-select";
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
/**
|
|
957
|
+
* @private
|
|
958
|
+
* @return {boolean}
|
|
959
|
+
*/
|
|
960
|
+
function isAdaptivePagination() {
|
|
961
|
+
return isEmbeddedPagination.call(this) || isSelectPagination.call(this);
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
/**
|
|
965
|
+
* @private
|
|
966
|
+
* @param {HTMLElement|null} parentNode
|
|
967
|
+
* @return {number}
|
|
968
|
+
*/
|
|
969
|
+
function getSelectAvailableWidth(parentNode) {
|
|
970
|
+
if (!parentNode) {
|
|
971
|
+
return this.getBoundingClientRect().width;
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
const rect = parentNode.getBoundingClientRect();
|
|
975
|
+
const styles = getComputedStyle(parentNode);
|
|
976
|
+
const paddingLeft = parseFloat(styles.paddingLeft || "0");
|
|
977
|
+
const paddingRight = parseFloat(styles.paddingRight || "0");
|
|
978
|
+
return Math.max(0, rect.width - paddingLeft - paddingRight);
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
/**
|
|
982
|
+
* @private
|
|
983
|
+
* @param {HTMLElement|null} parentNode
|
|
984
|
+
* @return {number}
|
|
985
|
+
*/
|
|
986
|
+
function getEmbeddedAvailableWidth(parentNode) {
|
|
987
|
+
if (!parentNode) {
|
|
988
|
+
return this.getBoundingClientRect().width;
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
const rect = parentNode.getBoundingClientRect();
|
|
992
|
+
if (!rect.width) {
|
|
993
|
+
return this.getBoundingClientRect().width;
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
const styles = getComputedStyle(parentNode);
|
|
997
|
+
const gapValue = styles.columnGap || styles.gap || "0";
|
|
998
|
+
const gap = parseFloat(gapValue) || 0;
|
|
999
|
+
|
|
1000
|
+
const siblings = Array.from(parentNode.children).filter((el) => el !== this);
|
|
1001
|
+
let siblingsWidth = 0;
|
|
1002
|
+
for (const sibling of siblings) {
|
|
1003
|
+
const siblingStyles = getComputedStyle(sibling);
|
|
1004
|
+
if (siblingStyles.display === "none") {
|
|
1005
|
+
continue;
|
|
1006
|
+
}
|
|
1007
|
+
siblingsWidth += sibling.getBoundingClientRect().width;
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
const gaps = siblings.length > 0 ? siblings.length : 0;
|
|
1011
|
+
return Math.max(0, rect.width - siblingsWidth - gap * gaps);
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
/**
|
|
1015
|
+
* @private
|
|
1016
|
+
* @param {HTMLElement} list
|
|
1017
|
+
* @param {HTMLElement|null} prevLink
|
|
1018
|
+
* @param {HTMLElement|null} nextLink
|
|
1019
|
+
* @param {"full"|"no-numbers"|"compact-summary"|"compact"} mode
|
|
1020
|
+
* @return {number}
|
|
1021
|
+
*/
|
|
1022
|
+
function applyPaginationMode(list, prevLink, nextLink, mode) {
|
|
1023
|
+
switch (mode) {
|
|
1024
|
+
case "compact":
|
|
1025
|
+
list.classList.add("pagination-numbers-hidden");
|
|
1026
|
+
list.classList.add("pagination-compact");
|
|
1027
|
+
setNumberItemsVisible(list, false);
|
|
1028
|
+
setSummaryVisible(list, true);
|
|
1029
|
+
setCompactLabels.call(this, true, prevLink, nextLink);
|
|
1030
|
+
break;
|
|
1031
|
+
case "compact-summary":
|
|
1032
|
+
list.classList.add("pagination-numbers-hidden");
|
|
1033
|
+
list.classList.add("pagination-compact");
|
|
1034
|
+
setNumberItemsVisible(list, false);
|
|
1035
|
+
setSummaryVisible(list, true);
|
|
1036
|
+
setCompactLabels.call(this, true, prevLink, nextLink);
|
|
1037
|
+
break;
|
|
1038
|
+
case "no-numbers":
|
|
1039
|
+
list.classList.add("pagination-numbers-hidden");
|
|
1040
|
+
list.classList.remove("pagination-compact");
|
|
1041
|
+
setNumberItemsVisible(list, false);
|
|
1042
|
+
setSummaryVisible(list, true);
|
|
1043
|
+
setCompactLabels.call(this, false, prevLink, nextLink);
|
|
1044
|
+
break;
|
|
1045
|
+
default:
|
|
1046
|
+
list.classList.remove("pagination-numbers-hidden");
|
|
1047
|
+
list.classList.remove("pagination-compact");
|
|
1048
|
+
setNumberItemsVisible(list, true);
|
|
1049
|
+
setSummaryVisible(list, false);
|
|
1050
|
+
setCompactLabels.call(this, false, prevLink, nextLink);
|
|
1051
|
+
break;
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
return list.scrollWidth;
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
/**
|
|
1058
|
+
* @private
|
|
1059
|
+
* @param {object} params
|
|
1060
|
+
* @return {"full"|"no-numbers"|"compact-summary"|"compact"}
|
|
1061
|
+
*/
|
|
1062
|
+
function choosePaginationMode({
|
|
1063
|
+
availableWidth,
|
|
1064
|
+
widthFull,
|
|
1065
|
+
widthNoNumbers,
|
|
1066
|
+
widthCompactSummary,
|
|
1067
|
+
widthCompact,
|
|
1068
|
+
}) {
|
|
1069
|
+
const hysteresisUp = 24;
|
|
1070
|
+
const hysteresisDown = 8;
|
|
1071
|
+
const currentMode = this[layoutModeSymbol] || "full";
|
|
1072
|
+
|
|
1073
|
+
if (currentMode === "full") {
|
|
1074
|
+
if (widthFull > availableWidth - hysteresisDown) {
|
|
1075
|
+
if (widthNoNumbers <= availableWidth - hysteresisDown) {
|
|
1076
|
+
this[layoutModeSymbol] = "no-numbers";
|
|
1077
|
+
return "no-numbers";
|
|
1078
|
+
}
|
|
1079
|
+
if (widthCompactSummary <= availableWidth - hysteresisDown) {
|
|
1080
|
+
this[layoutModeSymbol] = "compact-summary";
|
|
1081
|
+
return "compact-summary";
|
|
1082
|
+
}
|
|
1083
|
+
this[layoutModeSymbol] = "compact";
|
|
1084
|
+
return "compact";
|
|
1085
|
+
}
|
|
1086
|
+
this[layoutModeSymbol] = "full";
|
|
1087
|
+
return "full";
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
if (currentMode === "no-numbers") {
|
|
1091
|
+
if (widthNoNumbers > availableWidth - hysteresisDown) {
|
|
1092
|
+
if (widthCompactSummary <= availableWidth - hysteresisDown) {
|
|
1093
|
+
this[layoutModeSymbol] = "compact-summary";
|
|
1094
|
+
return "compact-summary";
|
|
1095
|
+
}
|
|
1096
|
+
this[layoutModeSymbol] = "compact";
|
|
1097
|
+
return "compact";
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
if (widthFull + hysteresisUp <= availableWidth) {
|
|
1101
|
+
this[layoutModeSymbol] = "full";
|
|
1102
|
+
return "full";
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
this[layoutModeSymbol] = "no-numbers";
|
|
1106
|
+
return "no-numbers";
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
if (currentMode === "compact-summary") {
|
|
1110
|
+
if (widthNoNumbers + hysteresisUp <= availableWidth) {
|
|
1111
|
+
this[layoutModeSymbol] = "no-numbers";
|
|
1112
|
+
return "no-numbers";
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
if (widthCompactSummary > availableWidth - hysteresisDown) {
|
|
1116
|
+
this[layoutModeSymbol] = "compact";
|
|
1117
|
+
return "compact";
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
this[layoutModeSymbol] = "compact-summary";
|
|
1121
|
+
return "compact-summary";
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
if (widthCompactSummary + hysteresisUp <= availableWidth) {
|
|
1125
|
+
this[layoutModeSymbol] = "compact-summary";
|
|
1126
|
+
return "compact-summary";
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
this[layoutModeSymbol] = "compact";
|
|
1130
|
+
return "compact";
|
|
1131
|
+
}
|
|
1132
|
+
|
|
636
1133
|
/**
|
|
637
1134
|
* @private
|
|
638
1135
|
* @return {string}
|
|
@@ -656,6 +1153,7 @@ function getTemplate() {
|
|
|
656
1153
|
<div data-monster-role="control" part="control">
|
|
657
1154
|
<nav data-monster-role="pagination" role="navigation" aria-label="pagination" part="nav">
|
|
658
1155
|
<ul class="pagination-list" data-monster-insert="items path:pagination.items"
|
|
1156
|
+
data-monster-adaptive-ready="false"
|
|
659
1157
|
data-monster-select-this="true" part="list">
|
|
660
1158
|
<li part="prev" data-monster-role="pagination-prev"><a
|
|
661
1159
|
data-monster-role="pagination-prev"
|
|
@@ -665,6 +1163,9 @@ function getTemplate() {
|
|
|
665
1163
|
data-page-no path:pagination.prevNo,
|
|
666
1164
|
href path:pagination.prevHref | prefix: #"
|
|
667
1165
|
data-monster-replace="path:labels.previous">Previous</a></li>
|
|
1166
|
+
<li part="summary" data-monster-role="pagination-summary">
|
|
1167
|
+
<span data-monster-replace="path:pagination.summary"></span>
|
|
1168
|
+
</li>
|
|
668
1169
|
<li part="next" data-monster-role="pagination-next"><a
|
|
669
1170
|
data-monster-role="pagination-next"
|
|
670
1171
|
part="next-link"
|
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
padding: 0;
|
|
22
22
|
margin: 0 15px 0 0;
|
|
23
23
|
|
|
24
|
+
&.dots-hidden {
|
|
25
|
+
display: none;
|
|
26
|
+
}
|
|
27
|
+
|
|
24
28
|
& li {
|
|
25
29
|
list-style: none;
|
|
26
30
|
padding: 0;
|
|
@@ -52,10 +56,21 @@
|
|
|
52
56
|
& :hover, & :focus {
|
|
53
57
|
background-clip: border-box;
|
|
54
58
|
}
|
|
59
|
+
}
|
|
55
60
|
|
|
56
|
-
|
|
61
|
+
& .dots-overflow-hidden {
|
|
62
|
+
display: none;
|
|
57
63
|
}
|
|
58
64
|
|
|
65
|
+
& .dots-overflow-indicator {
|
|
66
|
+
align-items: center;
|
|
67
|
+
color: var(--monster-color-primary-1);
|
|
68
|
+
display: flex;
|
|
69
|
+
font-size: 0.75rem;
|
|
70
|
+
line-height: 1;
|
|
71
|
+
padding: 0 2px;
|
|
72
|
+
white-space: nowrap;
|
|
73
|
+
}
|
|
59
74
|
|
|
60
75
|
}
|
|
61
76
|
|
|
@@ -134,4 +149,4 @@
|
|
|
134
149
|
}
|
|
135
150
|
|
|
136
151
|
}
|
|
137
|
-
}
|
|
152
|
+
}
|