@schukai/monster 4.136.14 → 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.14"}
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
@@ -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");