@schukai/monster 4.136.10 → 4.136.11

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/package.json CHANGED
@@ -1 +1 @@
1
- {"author":"Volker Schukai","dependencies":{"@floating-ui/dom":"^1.7.6"},"description":"Monster is a simple library for creating fast, robust and lightweight websites.","homepage":"https://monsterjs.org/","keywords":["framework","web","dom","css","sass","mobile-first","app","front-end","templates","schukai","core","shopcloud","alvine","monster","buildmap","stack","observer","observable","uuid","node","nodelist","css-in-js","logger","log","theme"],"license":"AGPL 3.0","main":"source/monster.mjs","module":"source/monster.mjs","name":"@schukai/monster","repository":{"type":"git","url":"https://gitlab.schukai.com/oss/libraries/javascript/monster.git"},"type":"module","version":"4.136.10"}
1
+ {"author":"Volker Schukai","dependencies":{"@floating-ui/dom":"^1.7.6"},"description":"Monster is a simple library for creating fast, robust and lightweight websites.","homepage":"https://monsterjs.org/","keywords":["framework","web","dom","css","sass","mobile-first","app","front-end","templates","schukai","core","shopcloud","alvine","monster","buildmap","stack","observer","observable","uuid","node","nodelist","css-in-js","logger","log","theme"],"license":"AGPL 3.0","main":"source/monster.mjs","module":"source/monster.mjs","name":"@schukai/monster","repository":{"type":"git","url":"https://gitlab.schukai.com/oss/libraries/javascript/monster.git"},"type":"module","version":"4.136.11"}
@@ -1014,7 +1014,7 @@ function processAndApplyPaginationData(data) {
1014
1014
  const mappingCurrentPage = this.getOption("mapping.currentPage");
1015
1015
  const mappingObjectsPerPage = this.getOption("mapping.objectsPerPage");
1016
1016
 
1017
- if (!mappingTotal || !mappingCurrentPage || !mappingObjectsPerPage) {
1017
+ if (!mappingTotal) {
1018
1018
  this.setOption("total", null);
1019
1019
  resetPaginationState.call(this);
1020
1020
  return;
@@ -1023,8 +1023,6 @@ function processAndApplyPaginationData(data) {
1023
1023
  try {
1024
1024
  const pathfinder = new Pathfinder(data);
1025
1025
  const total = pathfinder.getVia(mappingTotal);
1026
- const currentPage = pathfinder.getVia(mappingCurrentPage);
1027
- const objectsPerPage = pathfinder.getVia(mappingObjectsPerPage);
1028
1026
 
1029
1027
  if (!isInteger(total)) {
1030
1028
  addErrorAttribute(this, "total is not an integer");
@@ -1035,8 +1033,16 @@ function processAndApplyPaginationData(data) {
1035
1033
 
1036
1034
  this.setOption("total", total);
1037
1035
 
1036
+ if (!mappingCurrentPage || !mappingObjectsPerPage) {
1037
+ resetPaginationState.call(this, false);
1038
+ return;
1039
+ }
1040
+
1041
+ const currentPage = pathfinder.getVia(mappingCurrentPage);
1042
+ const objectsPerPage = pathfinder.getVia(mappingObjectsPerPage);
1043
+
1038
1044
  if (total === 0) {
1039
- resetPaginationState.call(this);
1045
+ resetPaginationState.call(this, false);
1040
1046
  return;
1041
1047
  }
1042
1048
 
@@ -1907,6 +1913,14 @@ function fetchIt(url, controlOptions) {
1907
1913
  this[fetchRequestVersionSymbol] += 1;
1908
1914
  const requestVersion = this[fetchRequestVersionSymbol];
1909
1915
 
1916
+ if (getFilterMode.call(this) === FILTER_MODE_REMOTE) {
1917
+ let classes = new TokenList(this.getOption("classes.noOptions"));
1918
+ classes.add("d-none");
1919
+ this.setOption("classes.noOptions", classes.toString());
1920
+ this.setOption("messages.emptyOptions", "");
1921
+ this.setOption("messages.total", "");
1922
+ }
1923
+
1910
1924
  new Processing(10, () => {
1911
1925
  fetchData
1912
1926
  .call(this, url)
@@ -2712,7 +2726,17 @@ function setTotalText() {
2712
2726
  return;
2713
2727
  }
2714
2728
 
2729
+ if (this[isLoadingSymbol] === true) {
2730
+ this.setOption("messages.total", "");
2731
+ return;
2732
+ }
2733
+
2715
2734
  const count = this.getOption("options").length;
2735
+ if (count === 0) {
2736
+ this.setOption("messages.total", "");
2737
+ return;
2738
+ }
2739
+
2716
2740
  const total = Number.parseInt(this.getOption("total"));
2717
2741
  if (Number.isNaN(total)) {
2718
2742
  this.setOption("messages.total", "");
@@ -3907,8 +3931,12 @@ function areOptionsAvailableAndInitInternal() {
3907
3931
  setStatusOrRemoveBadges.call(this, "empty");
3908
3932
  if (getFilterMode.call(this) === FILTER_MODE_REMOTE) {
3909
3933
  if (this[isLoadingSymbol] !== true) {
3910
- this.setOption("total", null);
3911
- resetPaginationState.call(this);
3934
+ if (isInteger(this.getOption("total"))) {
3935
+ resetPaginationState.call(this, false);
3936
+ } else {
3937
+ this.setOption("total", null);
3938
+ resetPaginationState.call(this);
3939
+ }
3912
3940
  }
3913
3941
  }
3914
3942
 
@@ -4547,6 +4575,7 @@ function initTotal() {
4547
4575
  }
4548
4576
 
4549
4577
  const fetchOptions = this.getOption("fetch", {});
4578
+ this.setOption("messages.total", "");
4550
4579
 
4551
4580
  const remoteInfoRequest = getGlobal()
4552
4581
  .fetch(url, fetchOptions)
@@ -4592,7 +4621,7 @@ function updatePagination(total, currentPage, objectsPerPage) {
4592
4621
  });
4593
4622
  }
4594
4623
 
4595
- function resetPaginationState() {
4624
+ function resetPaginationState(clearTotalMessage = true) {
4596
4625
  const paginationElement = this[paginationElementSymbol];
4597
4626
  if (!paginationElement) {
4598
4627
  return;
@@ -4602,7 +4631,9 @@ function resetPaginationState() {
4602
4631
  paginationElement.setOption("pages", null);
4603
4632
  paginationElement.setOption("currentPage", null);
4604
4633
  paginationElement.setOption("objectsPerPage", null);
4605
- this.setOption("messages.total", "");
4634
+ if (clearTotalMessage === true) {
4635
+ this.setOption("messages.total", "");
4636
+ }
4606
4637
  }
4607
4638
 
4608
4639
  function clearOptionsOnError() {
@@ -900,6 +900,84 @@ describe('Select', function () {
900
900
  expect(requests.filter((url) => url === remoteInfoUrl)).to.have.length(1);
901
901
  });
902
902
 
903
+ it('should keep total-only remote totals for loaded options', async function () {
904
+ this.timeout(3000);
905
+
906
+ let mocks = document.getElementById('mocks');
907
+
908
+ global['fetch'] = function () {
909
+ return createJsonResponse({
910
+ items: [
911
+ {id: 'alpha', name: 'Alpha'}
912
+ ],
913
+ pagination: {
914
+ total: 1
915
+ }
916
+ });
917
+ };
918
+
919
+ const select = document.createElement('monster-select');
920
+ select.setOption('url', 'https://example.com/items?filter={filter}&page={page}');
921
+ select.setOption('filter.mode', 'remote');
922
+ select.setOption('mapping.selector', 'items.*');
923
+ select.setOption('mapping.labelTemplate', '${name}');
924
+ select.setOption('mapping.valueTemplate', '${id}');
925
+ select.setOption('mapping.total', 'pagination.total');
926
+ mocks.appendChild(select);
927
+
928
+ await waitForCondition(() => {
929
+ return select.shadowRoot.querySelector('[data-monster-role=container]') instanceof HTMLElement;
930
+ });
931
+
932
+ await select.fetch('https://example.com/items?filter=alpha&page=1');
933
+
934
+ expect(select.getOption('total')).to.equal(1);
935
+ expect(select.getOption('messages.total')).to.contain('No additional entries are available');
936
+ });
937
+
938
+ it('should avoid duplicate remote-info badges for empty remote filter results', async function () {
939
+ this.timeout(4000);
940
+
941
+ let mocks = document.getElementById('mocks');
942
+
943
+ global['fetch'] = function () {
944
+ return createJsonResponse({
945
+ items: [],
946
+ pagination: {
947
+ total: 0
948
+ }
949
+ });
950
+ };
951
+
952
+ const select = document.createElement('monster-select');
953
+ select.setOption('url', 'https://example.com/items?filter={filter}&page={page}');
954
+ select.setOption('filter.mode', 'remote');
955
+ select.setOption('filter.position', 'popper');
956
+ select.setOption('mapping.selector', 'items.*');
957
+ select.setOption('mapping.labelTemplate', '${name}');
958
+ select.setOption('mapping.valueTemplate', '${id}');
959
+ select.setOption('mapping.total', 'pagination.total');
960
+ mocks.appendChild(select);
961
+
962
+ await waitForCondition(() => {
963
+ return select.shadowRoot.querySelector('[data-monster-role=filter][name=\"popper-filter\"]') instanceof HTMLInputElement;
964
+ });
965
+
966
+ const container = select.shadowRoot.querySelector('[data-monster-role=container]');
967
+ const filterInput = select.shadowRoot.querySelector('[data-monster-role=filter][name="popper-filter"]');
968
+ filterInput.value = 'alpha';
969
+
970
+ container.click();
971
+
972
+ await waitForCondition(() => {
973
+ return select.getOption('total') === 0;
974
+ });
975
+
976
+ expect(select.getOption('total')).to.equal(0);
977
+ expect(select.getOption('messages.total')).to.equal('');
978
+ expect(select.getOption('messages.emptyOptions')).to.contain('Please consider modifying the filter');
979
+ });
980
+
903
981
  it('should keep empty equivalent matching type-safe for numeric zero', function (done) {
904
982
  this.timeout(2000);
905
983