@schukai/monster 4.99.0 → 4.100.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
CHANGED
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"author":"Volker Schukai","dependencies":{"@floating-ui/dom":"^1.7.4","@popperjs/core":"^2.11.8"},"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.
|
|
1
|
+
{"author":"Volker Schukai","dependencies":{"@floating-ui/dom":"^1.7.4","@popperjs/core":"^2.11.8"},"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.100.0"}
|
|
@@ -36,6 +36,9 @@ export { MessageStateButton };
|
|
|
36
36
|
*/
|
|
37
37
|
const buttonElementSymbol = Symbol("buttonElement");
|
|
38
38
|
const innerDisabledObserverSymbol = Symbol("innerDisabledObserver");
|
|
39
|
+
const popperElementSymbol = Symbol("popperElement");
|
|
40
|
+
const messageElementSymbol = Symbol("messageElement");
|
|
41
|
+
const measurementPopperSymbol = Symbol("measurementPopper");
|
|
39
42
|
|
|
40
43
|
/**
|
|
41
44
|
* A specialized button component that combines state management with message display capabilities.
|
|
@@ -239,6 +242,7 @@ class MessageStateButton extends Popper {
|
|
|
239
242
|
* @return {MessageStateButton} Returns the button instance for chaining
|
|
240
243
|
*/
|
|
241
244
|
showMessage(timeout) {
|
|
245
|
+
applyMeasuredMessageWidth.call(this);
|
|
242
246
|
this.showDialog.call(this);
|
|
243
247
|
|
|
244
248
|
if (timeout !== undefined) {
|
|
@@ -398,6 +402,12 @@ function initControlReferences() {
|
|
|
398
402
|
this[buttonElementSymbol] = this.shadowRoot.querySelector(
|
|
399
403
|
`[${ATTRIBUTE_ROLE}=button]`,
|
|
400
404
|
);
|
|
405
|
+
this[popperElementSymbol] = this.shadowRoot.querySelector(
|
|
406
|
+
`[${ATTRIBUTE_ROLE}=popper]`,
|
|
407
|
+
);
|
|
408
|
+
this[messageElementSymbol] = this.shadowRoot.querySelector(
|
|
409
|
+
`[${ATTRIBUTE_ROLE}=message]`,
|
|
410
|
+
);
|
|
401
411
|
}
|
|
402
412
|
|
|
403
413
|
/**
|
|
@@ -499,4 +509,106 @@ function getTemplate() {
|
|
|
499
509
|
`;
|
|
500
510
|
}
|
|
501
511
|
|
|
512
|
+
/**
|
|
513
|
+
* @private
|
|
514
|
+
* @param {string|HTMLElement} content
|
|
515
|
+
* @return {HTMLElement|string|null}
|
|
516
|
+
*/
|
|
517
|
+
function getMeasurementContent(content) {
|
|
518
|
+
if (isString(content)) {
|
|
519
|
+
return content;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
if (content instanceof HTMLElement) {
|
|
523
|
+
return content.cloneNode(true);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
return null;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* @private
|
|
531
|
+
* @return {{popper: HTMLElement, message: HTMLElement}|null}
|
|
532
|
+
*/
|
|
533
|
+
function ensureMeasurementPopper() {
|
|
534
|
+
if (this[measurementPopperSymbol]) {
|
|
535
|
+
return this[measurementPopperSymbol];
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
if (!this.shadowRoot) {
|
|
539
|
+
return null;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
const popper = document.createElement("div");
|
|
543
|
+
popper.setAttribute(ATTRIBUTE_ROLE, "popper");
|
|
544
|
+
popper.setAttribute("data-measurement", "true");
|
|
545
|
+
popper.setAttribute("aria-hidden", "true");
|
|
546
|
+
popper.style.position = "absolute";
|
|
547
|
+
popper.style.left = "-10000px";
|
|
548
|
+
popper.style.top = "-10000px";
|
|
549
|
+
popper.style.visibility = "hidden";
|
|
550
|
+
popper.style.display = "block";
|
|
551
|
+
popper.style.pointerEvents = "none";
|
|
552
|
+
popper.style.maxWidth = "none";
|
|
553
|
+
popper.style.width = "max-content";
|
|
554
|
+
|
|
555
|
+
const message = document.createElement("div");
|
|
556
|
+
message.setAttribute(ATTRIBUTE_ROLE, "message");
|
|
557
|
+
message.className = "flex";
|
|
558
|
+
|
|
559
|
+
popper.appendChild(message);
|
|
560
|
+
this.shadowRoot.appendChild(popper);
|
|
561
|
+
|
|
562
|
+
this[measurementPopperSymbol] = { popper, message };
|
|
563
|
+
return this[measurementPopperSymbol];
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* @private
|
|
568
|
+
*/
|
|
569
|
+
function applyMeasuredMessageWidth() {
|
|
570
|
+
const popper = this[popperElementSymbol];
|
|
571
|
+
if (!popper) {
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
const content = this.getOption("message.content");
|
|
576
|
+
const measureContent = getMeasurementContent(content);
|
|
577
|
+
if (!measureContent) {
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
const measurement = ensureMeasurementPopper.call(this);
|
|
582
|
+
if (!measurement?.message) {
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
measurement.message.innerHTML = "";
|
|
587
|
+
if (isString(measureContent)) {
|
|
588
|
+
measurement.message.innerHTML = measureContent;
|
|
589
|
+
} else {
|
|
590
|
+
measurement.message.appendChild(measureContent);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
const measuredWidth = Math.ceil(
|
|
594
|
+
measurement.popper.getBoundingClientRect().width,
|
|
595
|
+
);
|
|
596
|
+
const fontSize = parseFloat(getComputedStyle(popper).fontSize) || 16;
|
|
597
|
+
const minWidth = Math.round(fontSize * 12);
|
|
598
|
+
const maxWidth = Math.max(
|
|
599
|
+
minWidth,
|
|
600
|
+
Math.min(window.innerWidth * 0.7, fontSize * 32),
|
|
601
|
+
);
|
|
602
|
+
const targetWidth = Math.max(
|
|
603
|
+
minWidth,
|
|
604
|
+
Math.min(measuredWidth || minWidth, maxWidth),
|
|
605
|
+
);
|
|
606
|
+
|
|
607
|
+
popper.style.width = `${targetWidth}px`;
|
|
608
|
+
popper.style.minWidth = `${minWidth}px`;
|
|
609
|
+
popper.style.maxWidth = `${maxWidth}px`;
|
|
610
|
+
popper.style.whiteSpace = "normal";
|
|
611
|
+
popper.style.overflowWrap = "anywhere";
|
|
612
|
+
}
|
|
613
|
+
|
|
502
614
|
registerCustomElement(MessageStateButton);
|