@schukai/monster 4.136.13 → 4.136.15

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.13"}
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.15"}
@@ -115,6 +115,8 @@ const dismissRecordSymbol = Symbol("dismissRecord");
115
115
  * @type {symbol}
116
116
  */
117
117
  const usesHostDismissSymbol = Symbol("usesHostDismiss");
118
+ const contentUpdateHandlerSymbol = Symbol("contentUpdateHandler");
119
+ const scheduledUpdateFrameSymbol = Symbol("scheduledUpdateFrame");
118
120
 
119
121
  /**
120
122
  * Popper component for displaying floating UI elements
@@ -248,6 +250,7 @@ class Popper extends CustomElement {
248
250
  }
249
251
 
250
252
  updatePopper.call(this);
253
+ attachContentUpdateListeners.call(this);
251
254
  attachResizeObserver.call(this);
252
255
  }
253
256
 
@@ -267,6 +270,8 @@ class Popper extends CustomElement {
267
270
 
268
271
  unregisterFromHost.call(this);
269
272
 
273
+ detachContentUpdateListeners.call(this);
274
+ cancelScheduledPopperUpdate.call(this);
270
275
  disconnectResizeObserver.call(this);
271
276
  }
272
277
 
@@ -520,6 +525,55 @@ function attachResizeObserver() {
520
525
  });
521
526
  }
522
527
 
528
+ function attachContentUpdateListeners() {
529
+ const popperElement = this[popperElementSymbol];
530
+ if (!(popperElement instanceof HTMLElement)) {
531
+ return;
532
+ }
533
+
534
+ if (typeof this[contentUpdateHandlerSymbol] !== "function") {
535
+ this[contentUpdateHandlerSymbol] = () => {
536
+ schedulePopperUpdate.call(this);
537
+ };
538
+ }
539
+
540
+ for (const type of ["input", "change", "transitionend", "animationend"]) {
541
+ popperElement.addEventListener(type, this[contentUpdateHandlerSymbol]);
542
+ }
543
+ }
544
+
545
+ function detachContentUpdateListeners() {
546
+ const popperElement = this[popperElementSymbol];
547
+ const handler = this[contentUpdateHandlerSymbol];
548
+ if (!(popperElement instanceof HTMLElement) || typeof handler !== "function") {
549
+ return;
550
+ }
551
+
552
+ for (const type of ["input", "change", "transitionend", "animationend"]) {
553
+ popperElement.removeEventListener(type, handler);
554
+ }
555
+ }
556
+
557
+ function schedulePopperUpdate() {
558
+ if (this[scheduledUpdateFrameSymbol] !== undefined) {
559
+ return;
560
+ }
561
+
562
+ this[scheduledUpdateFrameSymbol] = requestAnimationFrame(() => {
563
+ this[scheduledUpdateFrameSymbol] = undefined;
564
+ updatePopper.call(this);
565
+ });
566
+ }
567
+
568
+ function cancelScheduledPopperUpdate() {
569
+ if (this[scheduledUpdateFrameSymbol] === undefined) {
570
+ return;
571
+ }
572
+
573
+ cancelAnimationFrame(this[scheduledUpdateFrameSymbol]);
574
+ this[scheduledUpdateFrameSymbol] = undefined;
575
+ }
576
+
523
577
  /**
524
578
  * Disconnects resize observer
525
579
  * @private
@@ -284,16 +284,24 @@ function calcAndSetNavigationTopScrollableParentContext() {
284
284
  return;
285
285
  }
286
286
 
287
- const scrollTop = this[scrollableParentSymbol].scrollTop;
288
- const thisTop = scrollTop;
287
+ const parentRect = this[scrollableParentSymbol].getBoundingClientRect();
288
+ const rect = this.getBoundingClientRect();
289
+ const thisTop = rect.top - parentRect.top;
290
+ const thisBottom = rect.bottom - parentRect.top;
289
291
  let top = 0;
290
- top += scrollTop;
292
+ if (thisTop < 0) {
293
+ top = -1 * thisTop;
294
+ }
291
295
 
292
296
  const offset = this.getOption("offset");
293
297
  if (offset > 0) {
294
298
  top += offset;
295
299
  }
296
300
 
301
+ if (thisBottom < 0) {
302
+ return;
303
+ }
304
+
297
305
  fireCustomEvent(this, "new-top", { top: top });
298
306
 
299
307
  this[navigationElementSymbol].style.top = top + "px";
@@ -388,10 +396,15 @@ function createListFromHeadings(nodeList, currentLevel = 1) {
388
396
  li.addEventListener("click", (e) => {
389
397
  e.stopPropagation();
390
398
  getWindow().requestAnimationFrame(() => {
391
- window.scrollTo(0, 0);
392
- // https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
393
- // mostly supported
394
- node?.scrollIntoView({ behavior: "smooth" });
399
+ if (!node) {
400
+ return;
401
+ }
402
+
403
+ node.scrollIntoView({
404
+ behavior: "smooth",
405
+ block: "start",
406
+ inline: "nearest",
407
+ });
395
408
  });
396
409
  });
397
410
 
@@ -579,7 +592,7 @@ function getTemplate() {
579
592
  return `
580
593
  <div data-monster-role="control" part="control">
581
594
  <div class="navigation" data-monster-role="navigation">
582
- <monster-popper data-monster-option-mode="enter">
595
+ <monster-popper data-monster-option-mode="enter" data-monster-option-popper-content-overflow="visible">
583
596
  <div slot="button" data-monster-role="navigation-control">
584
597
  </div>
585
598
  <div data-monster-role="navigation-list">
@@ -263,6 +263,64 @@ describe("MessageStateButton", function () {
263
263
  }, 0);
264
264
  });
265
265
 
266
+ it("should refresh the open popper after checkbox-driven form growth", function (done) {
267
+ let mocks = document.getElementById("mocks");
268
+ const button = document.createElement("monster-message-state-button");
269
+ button.innerHTML = "Save";
270
+ mocks.appendChild(button);
271
+
272
+ const form = document.createElement("form");
273
+ const label = document.createElement("label");
274
+ const checkbox = document.createElement("input");
275
+ checkbox.type = "checkbox";
276
+ label.appendChild(checkbox);
277
+ label.append(" show more");
278
+ form.appendChild(label);
279
+
280
+ setTimeout(() => {
281
+ try {
282
+ button.setMessage(form);
283
+ button.showMessage();
284
+
285
+ setTimeout(() => {
286
+ try {
287
+ const popper = button.shadowRoot.querySelector(
288
+ '[data-monster-role="popper"]',
289
+ );
290
+ expect(popper).to.exist;
291
+
292
+ const originalHook = popper.monsterBeforeFloatingUpdate;
293
+ let updateCount = 0;
294
+ popper.monsterBeforeFloatingUpdate = () => {
295
+ updateCount += 1;
296
+ if (typeof originalHook === "function") {
297
+ originalHook();
298
+ }
299
+ };
300
+
301
+ checkbox.checked = true;
302
+ checkbox.dispatchEvent(
303
+ new Event("change", { bubbles: true, composed: true }),
304
+ );
305
+
306
+ setTimeout(() => {
307
+ try {
308
+ expect(updateCount).to.be.at.least(1);
309
+ done();
310
+ } catch (e) {
311
+ done(e);
312
+ }
313
+ }, 20);
314
+ } catch (e) {
315
+ done(e);
316
+ }
317
+ }, 0);
318
+ } catch (e) {
319
+ done(e);
320
+ }
321
+ }, 0);
322
+ });
323
+
266
324
  it("should resolve nested select message content to horizontal clipping only", async function () {
267
325
  let mocks = document.getElementById("mocks");
268
326
  const button = document.createElement("monster-message-state-button");