@schukai/monster 4.143.0 → 4.143.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/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.143.0"}
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.143.1"}
@@ -145,6 +145,8 @@ class Pagination extends CustomElement {
145
145
  * @property {number} currentPage Current page
146
146
  * @property {number} pages Pages
147
147
  * @property {number} objectsPerPage Objects per page
148
+ * @property {Object} layout Layout configuration
149
+ * @property {"auto"|"compact"} layout.mode Layout mode. Use `"compact"` to always show the small arrow pagination.
148
150
  * @property {Object} mapping Mapping
149
151
  * @property {string} mapping.pages Pages mapping
150
152
  * @property {string} mapping.objectsPerPage Objects per page mapping
@@ -175,6 +177,10 @@ class Pagination extends CustomElement {
175
177
  objectsPerPage: 20,
176
178
  currentPage: null,
177
179
 
180
+ layout: {
181
+ mode: "auto",
182
+ },
183
+
178
184
  mapping: {
179
185
  pages: "sys.pagination.pages",
180
186
  objectsPerPage: "sys.pagination.objectsPerPage",
@@ -250,6 +256,11 @@ class Pagination extends CustomElement {
250
256
  }
251
257
 
252
258
  refreshLayout({ schedule = false } = {}) {
259
+ if (isForcedCompactPagination.call(this)) {
260
+ applyForcedCompactPaginationLayout.call(this);
261
+ return this;
262
+ }
263
+
253
264
  if (schedule === true) {
254
265
  if (isAdaptivePagination.call(this)) {
255
266
  schedulePaginationLayoutUpdate.call(this);
@@ -363,7 +374,15 @@ class Pagination extends CustomElement {
363
374
  });
364
375
  });
365
376
 
366
- if (isAdaptivePagination.call(this)) {
377
+ if (isForcedCompactPagination.call(this)) {
378
+ this[sizeDataSymbol] = {
379
+ last: {
380
+ parentWidth: 0,
381
+ },
382
+ showNumbers: false,
383
+ };
384
+ applyForcedCompactPaginationLayout.call(this);
385
+ } else if (isAdaptivePagination.call(this)) {
367
386
  this[sizeDataSymbol] = {
368
387
  last: {
369
388
  parentWidth: 0,
@@ -877,6 +896,11 @@ function syncPaginationStateToDom(pagination) {
877
896
  * @private
878
897
  */
879
898
  function schedulePaginationLayoutUpdate() {
899
+ if (isForcedCompactPagination.call(this)) {
900
+ applyForcedCompactPaginationLayout.call(this);
901
+ return;
902
+ }
903
+
880
904
  if (!isAdaptivePagination.call(this)) {
881
905
  return;
882
906
  }
@@ -895,6 +919,11 @@ function schedulePaginationLayoutUpdate() {
895
919
  * @private
896
920
  */
897
921
  function applyPaginationLayout() {
922
+ if (isForcedCompactPagination.call(this)) {
923
+ applyForcedCompactPaginationLayout.call(this);
924
+ return;
925
+ }
926
+
898
927
  if (!this.isConnected || !this.shadowRoot) {
899
928
  return;
900
929
  }
@@ -974,6 +1003,51 @@ function applyPaginationLayout() {
974
1003
  }
975
1004
  }
976
1005
 
1006
+ /**
1007
+ * @private
1008
+ */
1009
+ function applyForcedCompactPaginationLayout() {
1010
+ if (!this.isConnected || !this.shadowRoot) {
1011
+ return;
1012
+ }
1013
+
1014
+ if (this[layoutApplySymbol]) {
1015
+ return;
1016
+ }
1017
+
1018
+ this[layoutApplySymbol] = true;
1019
+ try {
1020
+ ensureLabelState.call(this);
1021
+
1022
+ const list = this.shadowRoot.querySelector(".pagination-list");
1023
+ if (!list) {
1024
+ return;
1025
+ }
1026
+
1027
+ const prevLink = this.shadowRoot.querySelector(
1028
+ "a[data-monster-role=pagination-prev]",
1029
+ );
1030
+ const nextLink = this.shadowRoot.querySelector(
1031
+ "a[data-monster-role=pagination-next]",
1032
+ );
1033
+
1034
+ setClassEnabled(list, "pagination-no-wrap", true);
1035
+ applyPaginationMode.call(this, list, prevLink, nextLink, "compact");
1036
+ setAttributeValue(list, "data-monster-adaptive-ready", "true");
1037
+ this[layoutModeSymbol] = "compact";
1038
+ } finally {
1039
+ this[layoutApplySymbol] = false;
1040
+ }
1041
+ }
1042
+
1043
+ /**
1044
+ * @private
1045
+ * @return {boolean}
1046
+ */
1047
+ function isForcedCompactPagination() {
1048
+ return this.getOption("layout.mode") === "compact";
1049
+ }
1050
+
977
1051
  /**
978
1052
  * @private
979
1053
  * @param {number} parentWidth
@@ -5769,7 +5769,8 @@ function getTemplate() {
5769
5769
  <div part="options" data-monster-role="options" data-monster-insert="options path:options"
5770
5770
  tabindex="-1"></div>
5771
5771
  </div>
5772
- <monster-pagination data-monster-role="pagination" part="pagination"></monster-pagination>
5772
+ <monster-pagination data-monster-role="pagination" part="pagination"
5773
+ data-monster-option-layout-mode="compact"></monster-pagination>
5773
5774
  <div part="remote-info"
5774
5775
  data-monster-role="remote-info"
5775
5776
  data-monster-attributes="class path:classes.remoteInfo"
@@ -156,6 +156,38 @@ describe('Select', function () {
156
156
  expect(cssText.replace(/\s+/g, '')).to.contain('z-index:var(--monster-z-index-popover)');
157
157
  });
158
158
 
159
+ it('should render select pagination in the compact arrow mode immediately', async function () {
160
+ const mocks = document.getElementById('mocks');
161
+ const select = document.createElement('monster-select');
162
+
163
+ mocks.appendChild(select);
164
+
165
+ await waitForCondition(() => {
166
+ return select.shadowRoot?.querySelector('[data-monster-role="pagination"]');
167
+ });
168
+
169
+ const pagination = select.shadowRoot.querySelector('[data-monster-role="pagination"]');
170
+ expect(pagination.getOption('layout.mode')).to.equal('compact');
171
+
172
+ pagination.style.display = 'block';
173
+ pagination.setPaginationState({currentPage: 2, totalPages: 5});
174
+
175
+ await waitForCondition(() => {
176
+ const list = pagination.shadowRoot?.querySelector('.pagination-list');
177
+ const previous = pagination.shadowRoot?.querySelector(
178
+ 'a[data-monster-role="pagination-prev"]'
179
+ );
180
+ const next = pagination.shadowRoot?.querySelector(
181
+ 'a[data-monster-role="pagination-next"]'
182
+ );
183
+
184
+ return list?.classList.contains('pagination-compact') &&
185
+ list.getAttribute('data-monster-adaptive-ready') === 'true' &&
186
+ previous?.querySelector('svg') &&
187
+ next?.querySelector('svg');
188
+ });
189
+ });
190
+
159
191
  it('should deduplicate floating layout queue jobs by popper element', async function () {
160
192
  const popper = document.createElement('div');
161
193
  const reasons = [];