wj-elements 0.1.219 → 0.1.220
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/dist/light.css +1 -1
- package/dist/packages/wje-popup/popup.element.d.ts +52 -4
- package/dist/packages/wje-select/select.element.d.ts +1 -0
- package/dist/{popup.element-ZX3dWrG0.js → popup.element-B0Lm42bh.js} +217 -44
- package/dist/{popup.element-ZX3dWrG0.js.map → popup.element-B0Lm42bh.js.map} +1 -1
- package/dist/wje-dropdown.js +2 -1
- package/dist/wje-dropdown.js.map +1 -1
- package/dist/wje-icon-picker.js +1 -1
- package/dist/wje-infinite-scroll.js +1 -1
- package/dist/wje-input.js +0 -1
- package/dist/wje-input.js.map +1 -1
- package/dist/wje-master.js +1 -1
- package/dist/wje-option.js +16 -1
- package/dist/wje-option.js.map +1 -1
- package/dist/wje-options.js +2 -1
- package/dist/wje-options.js.map +1 -1
- package/dist/wje-popup.js +1 -1
- package/dist/wje-select.js +15 -3
- package/dist/wje-select.js.map +1 -1
- package/dist/wje-tooltip.js +1 -1
- package/package.json +1 -1
package/dist/light.css
CHANGED
|
@@ -542,7 +542,7 @@
|
|
|
542
542
|
--wje-select-background: var(--wje-color-contrast-0);
|
|
543
543
|
--wje-select-line-height: 20px;
|
|
544
544
|
--wje-select-color: var(--wje-color);
|
|
545
|
-
|
|
545
|
+
--wje-select-label-margin: 0 0 var(--wje-spacing-x-small) 0;
|
|
546
546
|
--wje-select-margin-bottom: var(--wje-spacing-x-small);
|
|
547
547
|
--wje-select-find-margin-inline: var(--wje-spacing-x-small);
|
|
548
548
|
--wje-select-find-margin-block: var(--wje-spacing-x-small);
|
|
@@ -40,6 +40,18 @@ export default class Popup extends WJElement {
|
|
|
40
40
|
* @returns {boolean} The value of the manual property.
|
|
41
41
|
*/
|
|
42
42
|
get manual(): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Sets or removes the 'portal' attribute on the element based on the provided value.
|
|
45
|
+
* If the value is truthy, the 'portal' attribute will be added.
|
|
46
|
+
* If the value is falsy, the 'portal' attribute will be removed.
|
|
47
|
+
* @param {boolean} value Determines whether the 'portal' attribute should be added or removed.
|
|
48
|
+
*/
|
|
49
|
+
set portal(value: boolean);
|
|
50
|
+
/**
|
|
51
|
+
* Returns whether the 'portal' attribute is present on the element.
|
|
52
|
+
* @returns {boolean} True if the 'portal' attribute exists, otherwise false.
|
|
53
|
+
*/
|
|
54
|
+
get portal(): boolean;
|
|
43
55
|
beforeDraw(context: any, store: any, params: any): void;
|
|
44
56
|
/**
|
|
45
57
|
* Draws the component for the popup.
|
|
@@ -62,6 +74,7 @@ export default class Popup extends WJElement {
|
|
|
62
74
|
anchorEl: any;
|
|
63
75
|
manualCallback: (e: any) => void;
|
|
64
76
|
clickHandler: (e: any) => void;
|
|
77
|
+
get floatingEl(): HTMLDivElement;
|
|
65
78
|
/**
|
|
66
79
|
* Toggles the active attribute of the popup.
|
|
67
80
|
*/
|
|
@@ -74,15 +87,50 @@ export default class Popup extends WJElement {
|
|
|
74
87
|
offsetCalc: number;
|
|
75
88
|
arrow: Element;
|
|
76
89
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
90
|
+
* Mounts content to a portal container by creating or ensuring a portal root and mirroring
|
|
91
|
+
* the host's classes, attributes, and slot contents onto the portal. This method manages the
|
|
92
|
+
* movement of default and arrow slot content into the portal shadow DOM, while also setting
|
|
93
|
+
* up necessary mutation observers to keep attributes in sync.
|
|
94
|
+
* @returns {void} Does not return a value.
|
|
95
|
+
*/
|
|
96
|
+
_mountContentToPortal(): void;
|
|
97
|
+
_portalNative: HTMLDivElement;
|
|
98
|
+
_portalAttrObserver: MutationObserver;
|
|
99
|
+
_defPlaceholders: any[];
|
|
100
|
+
_arrowPlaceholders: any[];
|
|
101
|
+
_floatingEl: HTMLDivElement;
|
|
102
|
+
_portaled: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Restores the content previously moved to a portal back to its original location.
|
|
105
|
+
* This method handles restoring default slot content, arrow placeholders, disconnecting
|
|
106
|
+
* attribute mirroring observers, and cleaning up elements and containers related to the portal.
|
|
107
|
+
* Ensures all placeholders and native portal elements are properly removed from the DOM.
|
|
108
|
+
* @returns {void} Does not return a value.
|
|
109
|
+
*/
|
|
110
|
+
_restoreContentFromPortal(): void;
|
|
111
|
+
_portalContainer: HTMLDivElement;
|
|
112
|
+
_portalShadow: ShadowRoot;
|
|
113
|
+
/**
|
|
114
|
+
* Ensures that a portal root is created and initialized properly with a shadow DOM and attached styles.
|
|
115
|
+
* If the portal root already exists, the method exits early.
|
|
116
|
+
* The method creates a `div` element in the document body and attaches a shadow DOM to it.
|
|
117
|
+
* It also applies the required styles to the shadow DOM, either using constructable stylesheets
|
|
118
|
+
* or by appending a `<style>` element. Additionally, it copies CSS custom properties from the
|
|
119
|
+
* component's computed styles to the portal host to ensure proper style resolution.
|
|
120
|
+
* @returns {void} This method does not return a value.
|
|
121
|
+
*/
|
|
122
|
+
_ensurePortalRoot(): void;
|
|
123
|
+
/**
|
|
124
|
+
* Displays the popup by portaling the content, managing the loader state, and attaching event handlers.
|
|
125
|
+
* Optionally dispatches a custom event when the popup is shown.
|
|
126
|
+
* @param {boolean} [dispatchEvent] Indicates whether to dispatch a custom event ('wje-popup:show') when the popup is shown.
|
|
127
|
+
* @returns {void} Does not return any value.
|
|
80
128
|
*/
|
|
81
129
|
show(dispatchEvent?: boolean): void;
|
|
82
130
|
cleanup: any;
|
|
83
131
|
/**
|
|
84
132
|
* Hides the popup.
|
|
85
|
-
* Removes the popup-active class from the
|
|
133
|
+
* Removes the popup-active class from the floating element.
|
|
86
134
|
* Cleans up the auto update for repositioning.
|
|
87
135
|
*/
|
|
88
136
|
hide(dispatchEvent?: boolean): void;
|
|
@@ -233,6 +233,7 @@ export class Select extends FormAssociatedElement {
|
|
|
233
233
|
draw(): DocumentFragment;
|
|
234
234
|
findEl: HTMLElement;
|
|
235
235
|
displayInput: HTMLInputElement;
|
|
236
|
+
slotFooter: HTMLSlotElement;
|
|
236
237
|
/**
|
|
237
238
|
* Executes post-render logic for the custom element.
|
|
238
239
|
* This includes validation, event listener registration, managing custom attributes, and
|
|
@@ -683,7 +683,7 @@ function isOverflowElement(element) {
|
|
|
683
683
|
overflowX,
|
|
684
684
|
overflowY,
|
|
685
685
|
display
|
|
686
|
-
} = getComputedStyle(element);
|
|
686
|
+
} = getComputedStyle$1(element);
|
|
687
687
|
return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && !["inline", "contents"].includes(display);
|
|
688
688
|
}
|
|
689
689
|
function isTableElement(element) {
|
|
@@ -700,7 +700,7 @@ function isTopLayer(element) {
|
|
|
700
700
|
}
|
|
701
701
|
function isContainingBlock(elementOrCss) {
|
|
702
702
|
const webkit = isWebKit();
|
|
703
|
-
const css = isElement(elementOrCss) ? getComputedStyle(elementOrCss) : elementOrCss;
|
|
703
|
+
const css = isElement(elementOrCss) ? getComputedStyle$1(elementOrCss) : elementOrCss;
|
|
704
704
|
return ["transform", "translate", "scale", "rotate", "perspective"].some((value) => css[value] ? css[value] !== "none" : false) || (css.containerType ? css.containerType !== "normal" : false) || !webkit && (css.backdropFilter ? css.backdropFilter !== "none" : false) || !webkit && (css.filter ? css.filter !== "none" : false) || ["transform", "translate", "scale", "rotate", "perspective", "filter"].some((value) => (css.willChange || "").includes(value)) || ["paint", "layout", "strict", "content"].some((value) => (css.contain || "").includes(value));
|
|
705
705
|
}
|
|
706
706
|
function getContainingBlock(element) {
|
|
@@ -722,7 +722,7 @@ function isWebKit() {
|
|
|
722
722
|
function isLastTraversableNode(node) {
|
|
723
723
|
return ["html", "body", "#document"].includes(getNodeName(node));
|
|
724
724
|
}
|
|
725
|
-
function getComputedStyle(element) {
|
|
725
|
+
function getComputedStyle$1(element) {
|
|
726
726
|
return getWindow(element).getComputedStyle(element);
|
|
727
727
|
}
|
|
728
728
|
function getNodeScroll(element) {
|
|
@@ -781,7 +781,7 @@ function getFrameElement(win) {
|
|
|
781
781
|
return win.parent && Object.getPrototypeOf(win.parent) ? win.frameElement : null;
|
|
782
782
|
}
|
|
783
783
|
function getCssDimensions(element) {
|
|
784
|
-
const css = getComputedStyle(element);
|
|
784
|
+
const css = getComputedStyle$1(element);
|
|
785
785
|
let width = parseFloat(css.width) || 0;
|
|
786
786
|
let height = parseFloat(css.height) || 0;
|
|
787
787
|
const hasOffset = isHTMLElement(element);
|
|
@@ -877,7 +877,7 @@ function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetPar
|
|
|
877
877
|
while (currentIFrame && offsetParent && offsetWin !== currentWin) {
|
|
878
878
|
const iframeScale = getScale(currentIFrame);
|
|
879
879
|
const iframeRect = currentIFrame.getBoundingClientRect();
|
|
880
|
-
const css = getComputedStyle(currentIFrame);
|
|
880
|
+
const css = getComputedStyle$1(currentIFrame);
|
|
881
881
|
const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
|
|
882
882
|
const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
|
|
883
883
|
x *= iframeScale.x;
|
|
@@ -969,7 +969,7 @@ function getDocumentRect(element) {
|
|
|
969
969
|
const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
|
|
970
970
|
let x = -scroll.scrollLeft + getWindowScrollBarX(element);
|
|
971
971
|
const y = -scroll.scrollTop;
|
|
972
|
-
if (getComputedStyle(body).direction === "rtl") {
|
|
972
|
+
if (getComputedStyle$1(body).direction === "rtl") {
|
|
973
973
|
x += max(html.clientWidth, body.clientWidth) - width;
|
|
974
974
|
}
|
|
975
975
|
return {
|
|
@@ -1043,7 +1043,7 @@ function hasFixedPositionAncestor(element, stopNode) {
|
|
|
1043
1043
|
if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
|
|
1044
1044
|
return false;
|
|
1045
1045
|
}
|
|
1046
|
-
return getComputedStyle(parentNode).position === "fixed" || hasFixedPositionAncestor(parentNode, stopNode);
|
|
1046
|
+
return getComputedStyle$1(parentNode).position === "fixed" || hasFixedPositionAncestor(parentNode, stopNode);
|
|
1047
1047
|
}
|
|
1048
1048
|
function getClippingElementAncestors(element, cache) {
|
|
1049
1049
|
const cachedResult = cache.get(element);
|
|
@@ -1052,10 +1052,10 @@ function getClippingElementAncestors(element, cache) {
|
|
|
1052
1052
|
}
|
|
1053
1053
|
let result = getOverflowAncestors(element, [], false).filter((el) => isElement(el) && getNodeName(el) !== "body");
|
|
1054
1054
|
let currentContainingBlockComputedStyle = null;
|
|
1055
|
-
const elementIsFixed = getComputedStyle(element).position === "fixed";
|
|
1055
|
+
const elementIsFixed = getComputedStyle$1(element).position === "fixed";
|
|
1056
1056
|
let currentNode = elementIsFixed ? getParentNode(element) : element;
|
|
1057
1057
|
while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
|
|
1058
|
-
const computedStyle = getComputedStyle(currentNode);
|
|
1058
|
+
const computedStyle = getComputedStyle$1(currentNode);
|
|
1059
1059
|
const currentNodeIsContaining = isContainingBlock(currentNode);
|
|
1060
1060
|
if (!currentNodeIsContaining && computedStyle.position === "fixed") {
|
|
1061
1061
|
currentContainingBlockComputedStyle = null;
|
|
@@ -1139,10 +1139,10 @@ function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
|
|
|
1139
1139
|
};
|
|
1140
1140
|
}
|
|
1141
1141
|
function isStaticPositioned(element) {
|
|
1142
|
-
return getComputedStyle(element).position === "static";
|
|
1142
|
+
return getComputedStyle$1(element).position === "static";
|
|
1143
1143
|
}
|
|
1144
1144
|
function getTrueOffsetParent(element, polyfill) {
|
|
1145
|
-
if (!isHTMLElement(element) || getComputedStyle(element).position === "fixed") {
|
|
1145
|
+
if (!isHTMLElement(element) || getComputedStyle$1(element).position === "fixed") {
|
|
1146
1146
|
return null;
|
|
1147
1147
|
}
|
|
1148
1148
|
if (polyfill) {
|
|
@@ -1193,7 +1193,7 @@ const getElementRects = async function(data) {
|
|
|
1193
1193
|
};
|
|
1194
1194
|
};
|
|
1195
1195
|
function isRTL(element) {
|
|
1196
|
-
return getComputedStyle(element).direction === "rtl";
|
|
1196
|
+
return getComputedStyle$1(element).direction === "rtl";
|
|
1197
1197
|
}
|
|
1198
1198
|
const platform = {
|
|
1199
1199
|
convertOffsetParentRelativeRectToViewportRelativeRect,
|
|
@@ -1385,10 +1385,9 @@ class Popup extends WJElement {
|
|
|
1385
1385
|
this.showHide();
|
|
1386
1386
|
});
|
|
1387
1387
|
__publicField(this, "clickHandler", (e) => {
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
}
|
|
1388
|
+
const path = e.composedPath();
|
|
1389
|
+
const inside = path.includes(this) || this.floatingEl && path.includes(this.floatingEl);
|
|
1390
|
+
if (!inside && this.hasAttribute("active")) this.hide(true);
|
|
1392
1391
|
});
|
|
1393
1392
|
/**
|
|
1394
1393
|
* Removes the active attribute when the popup is hidden.
|
|
@@ -1426,6 +1425,23 @@ class Popup extends WJElement {
|
|
|
1426
1425
|
get manual() {
|
|
1427
1426
|
return this.hasAttribute("manual");
|
|
1428
1427
|
}
|
|
1428
|
+
/**
|
|
1429
|
+
* Sets or removes the 'portal' attribute on the element based on the provided value.
|
|
1430
|
+
* If the value is truthy, the 'portal' attribute will be added.
|
|
1431
|
+
* If the value is falsy, the 'portal' attribute will be removed.
|
|
1432
|
+
* @param {boolean} value Determines whether the 'portal' attribute should be added or removed.
|
|
1433
|
+
*/
|
|
1434
|
+
set portal(value) {
|
|
1435
|
+
if (value) this.setAttribute("portal", "");
|
|
1436
|
+
else this.removeAttribute("portal");
|
|
1437
|
+
}
|
|
1438
|
+
/**
|
|
1439
|
+
* Returns whether the 'portal' attribute is present on the element.
|
|
1440
|
+
* @returns {boolean} True if the 'portal' attribute exists, otherwise false.
|
|
1441
|
+
*/
|
|
1442
|
+
get portal() {
|
|
1443
|
+
return this.hasAttribute("portal");
|
|
1444
|
+
}
|
|
1429
1445
|
/**
|
|
1430
1446
|
* Returns the CSS styles for the component.
|
|
1431
1447
|
* @static
|
|
@@ -1452,6 +1468,7 @@ class Popup extends WJElement {
|
|
|
1452
1468
|
var _a;
|
|
1453
1469
|
event.removeListener(this.anchorEl, "click", this.manualCallback);
|
|
1454
1470
|
document.removeEventListener("click", this.clickHandler, { capture: true });
|
|
1471
|
+
this._restoreContentFromPortal();
|
|
1455
1472
|
(_a = this.cleanup) == null ? void 0 : _a.call(this);
|
|
1456
1473
|
}
|
|
1457
1474
|
beforeDraw(context, store, params) {
|
|
@@ -1493,6 +1510,7 @@ class Popup extends WJElement {
|
|
|
1493
1510
|
afterDraw() {
|
|
1494
1511
|
this.setAnchor();
|
|
1495
1512
|
this.addEventListener("wje-popup:content-ready", () => {
|
|
1513
|
+
debugger;
|
|
1496
1514
|
this.markContentReady();
|
|
1497
1515
|
}, { once: true });
|
|
1498
1516
|
if (this.hasAttribute("active")) this.show(false);
|
|
@@ -1513,6 +1531,9 @@ class Popup extends WJElement {
|
|
|
1513
1531
|
event.addListener(this.anchorEl, "click", null, this.manualCallback, { stopPropagation: true });
|
|
1514
1532
|
}
|
|
1515
1533
|
}
|
|
1534
|
+
get floatingEl() {
|
|
1535
|
+
return this._floatingEl || this.native;
|
|
1536
|
+
}
|
|
1516
1537
|
/**
|
|
1517
1538
|
* Toggles the active attribute of the popup.
|
|
1518
1539
|
*/
|
|
@@ -1520,8 +1541,9 @@ class Popup extends WJElement {
|
|
|
1520
1541
|
if (this.hasAttribute("active")) {
|
|
1521
1542
|
this.hide();
|
|
1522
1543
|
} else {
|
|
1523
|
-
event.dispatchCustomEvent(this, "wje-popup:
|
|
1544
|
+
event.dispatchCustomEvent(this, "wje-popup:beforeshow");
|
|
1524
1545
|
this.show();
|
|
1546
|
+
event.dispatchCustomEvent(this, "wje-popup:aftershow");
|
|
1525
1547
|
}
|
|
1526
1548
|
}
|
|
1527
1549
|
/**
|
|
@@ -1531,16 +1553,18 @@ class Popup extends WJElement {
|
|
|
1531
1553
|
reposition() {
|
|
1532
1554
|
const middleware = [];
|
|
1533
1555
|
this.offsetCalc = +this.offset || 0;
|
|
1534
|
-
if (this.
|
|
1556
|
+
if (this.portal && this._portaled && this.floatingEl) {
|
|
1557
|
+
this.arrow = this.floatingEl.querySelector('[slot="arrow"]');
|
|
1558
|
+
} else if (this.slotArrow instanceof HTMLSlotElement) {
|
|
1535
1559
|
this.arrow = this.slotArrow.assignedElements({ flatten: true })[0];
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
)
|
|
1542
|
-
|
|
1543
|
-
|
|
1560
|
+
}
|
|
1561
|
+
if (this.arrow) {
|
|
1562
|
+
middleware.push(
|
|
1563
|
+
arrow({
|
|
1564
|
+
element: this.arrow
|
|
1565
|
+
})
|
|
1566
|
+
);
|
|
1567
|
+
this.offsetCalc = Math.sqrt(2 * this.arrow.offsetWidth ** 2) / 2 + +this.offset;
|
|
1544
1568
|
}
|
|
1545
1569
|
middleware.push(offset(this.offsetCalc));
|
|
1546
1570
|
middleware.push(flip());
|
|
@@ -1555,14 +1579,14 @@ class Popup extends WJElement {
|
|
|
1555
1579
|
})
|
|
1556
1580
|
);
|
|
1557
1581
|
}
|
|
1558
|
-
computePosition(this.anchorEl, this.
|
|
1582
|
+
computePosition(this.anchorEl, this.floatingEl, {
|
|
1559
1583
|
placement: this.placement || "bottom",
|
|
1560
1584
|
strategy: "fixed",
|
|
1561
1585
|
middleware
|
|
1562
1586
|
}).then(({ x, y, middlewareData, placement, strategy }) => {
|
|
1563
|
-
this.
|
|
1564
|
-
this.
|
|
1565
|
-
this.
|
|
1587
|
+
this.floatingEl.style.setProperty("--wje-popup-left", x + "px");
|
|
1588
|
+
this.floatingEl.style.setProperty("--wje-popup-top", y + "px");
|
|
1589
|
+
this.floatingEl.style.position = strategy;
|
|
1566
1590
|
if (this.arrow) {
|
|
1567
1591
|
const staticSide = {
|
|
1568
1592
|
top: "bottom",
|
|
@@ -1571,7 +1595,7 @@ class Popup extends WJElement {
|
|
|
1571
1595
|
left: "right"
|
|
1572
1596
|
}[placement];
|
|
1573
1597
|
if (middlewareData.arrow) {
|
|
1574
|
-
const { width, height } = this.
|
|
1598
|
+
const { width, height } = this.floatingEl.getBoundingClientRect();
|
|
1575
1599
|
let osX = middlewareData.arrow.x;
|
|
1576
1600
|
let osY = middlewareData.arrow.y;
|
|
1577
1601
|
Object.assign(this.arrow.style, {
|
|
@@ -1589,24 +1613,172 @@ class Popup extends WJElement {
|
|
|
1589
1613
|
});
|
|
1590
1614
|
}
|
|
1591
1615
|
/**
|
|
1592
|
-
*
|
|
1593
|
-
*
|
|
1594
|
-
*
|
|
1616
|
+
* Mounts content to a portal container by creating or ensuring a portal root and mirroring
|
|
1617
|
+
* the host's classes, attributes, and slot contents onto the portal. This method manages the
|
|
1618
|
+
* movement of default and arrow slot content into the portal shadow DOM, while also setting
|
|
1619
|
+
* up necessary mutation observers to keep attributes in sync.
|
|
1620
|
+
* @returns {void} Does not return a value.
|
|
1621
|
+
*/
|
|
1622
|
+
_mountContentToPortal() {
|
|
1623
|
+
if (this._portaled) return;
|
|
1624
|
+
this._ensurePortalRoot();
|
|
1625
|
+
if (!this._portalNative) {
|
|
1626
|
+
this._portalNative = document.createElement("div");
|
|
1627
|
+
this._portalNative.setAttribute("part", "native");
|
|
1628
|
+
this._portalNative.classList.add("native-popup");
|
|
1629
|
+
}
|
|
1630
|
+
this._portalShadow.append(this._portalNative);
|
|
1631
|
+
const mirrorAll = () => {
|
|
1632
|
+
for (const { name } of Array.from(this._portalContainer.attributes)) {
|
|
1633
|
+
this._portalContainer.removeAttribute(name);
|
|
1634
|
+
}
|
|
1635
|
+
for (const attr of Array.from(this.attributes)) {
|
|
1636
|
+
this._portalContainer.setAttribute(attr.name, attr.value ?? "");
|
|
1637
|
+
}
|
|
1638
|
+
this._portalContainer.setAttribute("class", this.getAttribute("class") || "");
|
|
1639
|
+
};
|
|
1640
|
+
mirrorAll();
|
|
1641
|
+
this._portalAttrObserver = new MutationObserver((records) => {
|
|
1642
|
+
for (const r of records) {
|
|
1643
|
+
if (r.type === "attributes") {
|
|
1644
|
+
const name = r.attributeName;
|
|
1645
|
+
const val = this.getAttribute(name);
|
|
1646
|
+
if (val === null) this._portalContainer.removeAttribute(name);
|
|
1647
|
+
else this._portalContainer.setAttribute(name, val);
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
});
|
|
1651
|
+
this._portalAttrObserver.observe(this, { attributes: true });
|
|
1652
|
+
const defaultSlot = this.shadowRoot.querySelector("slot:not([name])");
|
|
1653
|
+
const defNodes = (defaultSlot ? defaultSlot.assignedNodes({ flatten: true }) : []).filter((n) => n && n.nodeType === Node.ELEMENT_NODE || n && n.nodeType === Node.TEXT_NODE);
|
|
1654
|
+
this._defPlaceholders = [];
|
|
1655
|
+
for (const n of defNodes) {
|
|
1656
|
+
const ph = document.createComment("wje-portal-default");
|
|
1657
|
+
this._defPlaceholders.push({ node: n, ph });
|
|
1658
|
+
n.parentNode && n.parentNode.insertBefore(ph, n.nextSibling);
|
|
1659
|
+
this._portalNative.append(n);
|
|
1660
|
+
}
|
|
1661
|
+
const arrowNodes = (this.slotArrow instanceof HTMLSlotElement ? this.slotArrow.assignedNodes({ flatten: true }) : []).filter((n) => n && n.nodeType === Node.ELEMENT_NODE || n && n.nodeType === Node.TEXT_NODE);
|
|
1662
|
+
this._arrowPlaceholders = [];
|
|
1663
|
+
for (const n of arrowNodes) {
|
|
1664
|
+
const ph = document.createComment("wje-portal-arrow");
|
|
1665
|
+
this._arrowPlaceholders.push({ node: n, ph });
|
|
1666
|
+
n.parentNode && n.parentNode.insertBefore(ph, n.nextSibling);
|
|
1667
|
+
this._portalNative.append(n);
|
|
1668
|
+
}
|
|
1669
|
+
this._floatingEl = this._portalNative;
|
|
1670
|
+
this._portaled = true;
|
|
1671
|
+
}
|
|
1672
|
+
/**
|
|
1673
|
+
* Restores the content previously moved to a portal back to its original location.
|
|
1674
|
+
* This method handles restoring default slot content, arrow placeholders, disconnecting
|
|
1675
|
+
* attribute mirroring observers, and cleaning up elements and containers related to the portal.
|
|
1676
|
+
* Ensures all placeholders and native portal elements are properly removed from the DOM.
|
|
1677
|
+
* @returns {void} Does not return a value.
|
|
1678
|
+
*/
|
|
1679
|
+
_restoreContentFromPortal() {
|
|
1680
|
+
if (!this._portaled) return;
|
|
1681
|
+
if (Array.isArray(this._defPlaceholders)) {
|
|
1682
|
+
for (const { node, ph } of this._defPlaceholders) {
|
|
1683
|
+
if (ph && ph.parentNode) {
|
|
1684
|
+
ph.parentNode.insertBefore(node, ph);
|
|
1685
|
+
ph.remove();
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
this._defPlaceholders = void 0;
|
|
1690
|
+
if (Array.isArray(this._arrowPlaceholders)) {
|
|
1691
|
+
for (const { node, ph } of this._arrowPlaceholders) {
|
|
1692
|
+
if (ph && ph.parentNode) {
|
|
1693
|
+
ph.parentNode.insertBefore(node, ph);
|
|
1694
|
+
ph.remove();
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
this._arrowPlaceholders = void 0;
|
|
1699
|
+
if (this._portalAttrObserver) {
|
|
1700
|
+
this._portalAttrObserver.disconnect();
|
|
1701
|
+
this._portalAttrObserver = null;
|
|
1702
|
+
}
|
|
1703
|
+
if (this._portalNative && this._portalNative.parentNode) {
|
|
1704
|
+
this._portalNative.remove();
|
|
1705
|
+
}
|
|
1706
|
+
this._floatingEl = void 0;
|
|
1707
|
+
this._portaled = false;
|
|
1708
|
+
if (this._portalContainer) {
|
|
1709
|
+
this._portalContainer.remove();
|
|
1710
|
+
this._portalContainer = null;
|
|
1711
|
+
this._portalShadow = null;
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
/**
|
|
1715
|
+
* Ensures that a portal root is created and initialized properly with a shadow DOM and attached styles.
|
|
1716
|
+
* If the portal root already exists, the method exits early.
|
|
1717
|
+
* The method creates a `div` element in the document body and attaches a shadow DOM to it.
|
|
1718
|
+
* It also applies the required styles to the shadow DOM, either using constructable stylesheets
|
|
1719
|
+
* or by appending a `<style>` element. Additionally, it copies CSS custom properties from the
|
|
1720
|
+
* component's computed styles to the portal host to ensure proper style resolution.
|
|
1721
|
+
* @returns {void} This method does not return a value.
|
|
1722
|
+
*/
|
|
1723
|
+
_ensurePortalRoot() {
|
|
1724
|
+
var _a, _b;
|
|
1725
|
+
if (this._portalContainer && this._portalShadow) return;
|
|
1726
|
+
const host = document.createElement("div");
|
|
1727
|
+
host.setAttribute("data-wje-popup-portal", "");
|
|
1728
|
+
const shadow = host.attachShadow({ mode: "open" });
|
|
1729
|
+
const sheetCandidate = this.constructor.cssStyleSheet;
|
|
1730
|
+
try {
|
|
1731
|
+
if (sheetCandidate instanceof CSSStyleSheet) {
|
|
1732
|
+
shadow.adoptedStyleSheets = [sheetCandidate];
|
|
1733
|
+
} else if (typeof sheetCandidate === "string" && "adoptedStyleSheets" in Document.prototype) {
|
|
1734
|
+
const sheet = new CSSStyleSheet();
|
|
1735
|
+
sheet.replaceSync(sheetCandidate);
|
|
1736
|
+
shadow.adoptedStyleSheets = [sheet];
|
|
1737
|
+
} else {
|
|
1738
|
+
const style = document.createElement("style");
|
|
1739
|
+
style.textContent = typeof sheetCandidate === "string" ? sheetCandidate : ((_a = sheetCandidate == null ? void 0 : sheetCandidate.toString) == null ? void 0 : _a.call(sheetCandidate)) || "";
|
|
1740
|
+
shadow.append(style);
|
|
1741
|
+
}
|
|
1742
|
+
} catch (e) {
|
|
1743
|
+
const style = document.createElement("style");
|
|
1744
|
+
style.textContent = typeof sheetCandidate === "string" ? sheetCandidate : ((_b = sheetCandidate == null ? void 0 : sheetCandidate.toString) == null ? void 0 : _b.call(sheetCandidate)) || "";
|
|
1745
|
+
shadow.append(style);
|
|
1746
|
+
}
|
|
1747
|
+
const comp = getComputedStyle(this);
|
|
1748
|
+
for (let i = 0; i < comp.length; i++) {
|
|
1749
|
+
const prop = comp[i];
|
|
1750
|
+
if (prop.startsWith("--")) {
|
|
1751
|
+
host.style.setProperty(prop, comp.getPropertyValue(prop));
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
document.body.appendChild(host);
|
|
1755
|
+
this._portalContainer = host;
|
|
1756
|
+
this._portalShadow = shadow;
|
|
1757
|
+
}
|
|
1758
|
+
/**
|
|
1759
|
+
* Displays the popup by portaling the content, managing the loader state, and attaching event handlers.
|
|
1760
|
+
* Optionally dispatches a custom event when the popup is shown.
|
|
1761
|
+
* @param {boolean} [dispatchEvent] Indicates whether to dispatch a custom event ('wje-popup:show') when the popup is shown.
|
|
1762
|
+
* @returns {void} Does not return any value.
|
|
1595
1763
|
*/
|
|
1596
1764
|
show(dispatchEvent = true) {
|
|
1597
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
1765
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1766
|
+
debugger;
|
|
1767
|
+
if (this.portal) {
|
|
1768
|
+
this._mountContentToPortal();
|
|
1769
|
+
}
|
|
1598
1770
|
if (this.loader) {
|
|
1599
|
-
(_b = (_a = this.
|
|
1771
|
+
(_b = (_a = this.floatingEl) == null ? void 0 : _a.classList) == null ? void 0 : _b.add("loading");
|
|
1600
1772
|
(_d = (_c = this.loaderEl) == null ? void 0 : _c.classList) == null ? void 0 : _d.remove("fade-out");
|
|
1601
|
-
this.
|
|
1773
|
+
(_e = this.floatingEl) == null ? void 0 : _e.prepend(this.loaderEl);
|
|
1602
1774
|
}
|
|
1603
1775
|
if (dispatchEvent) {
|
|
1604
1776
|
event.dispatchCustomEvent(this, "wje-popup:show");
|
|
1605
1777
|
}
|
|
1606
|
-
if (this.anchorEl && this.
|
|
1607
|
-
(
|
|
1608
|
-
(
|
|
1609
|
-
this.cleanup = autoUpdate(this.anchorEl, this.
|
|
1778
|
+
if (this.anchorEl && this.floatingEl) {
|
|
1779
|
+
(_g = (_f = this.floatingEl) == null ? void 0 : _f.classList) == null ? void 0 : _g.add("popup-active");
|
|
1780
|
+
(_h = this.cleanup) == null ? void 0 : _h.call(this);
|
|
1781
|
+
this.cleanup = autoUpdate(this.anchorEl, this.floatingEl, () => {
|
|
1610
1782
|
this.reposition();
|
|
1611
1783
|
});
|
|
1612
1784
|
document.addEventListener("click", this.clickHandler, { capture: true });
|
|
@@ -1617,7 +1789,7 @@ class Popup extends WJElement {
|
|
|
1617
1789
|
}
|
|
1618
1790
|
/**
|
|
1619
1791
|
* Hides the popup.
|
|
1620
|
-
* Removes the popup-active class from the
|
|
1792
|
+
* Removes the popup-active class from the floating element.
|
|
1621
1793
|
* Cleans up the auto update for repositioning.
|
|
1622
1794
|
*/
|
|
1623
1795
|
hide(dispatchEvent = true) {
|
|
@@ -1625,10 +1797,11 @@ class Popup extends WJElement {
|
|
|
1625
1797
|
if (dispatchEvent) {
|
|
1626
1798
|
event.dispatchCustomEvent(this, "wje-popup:hide");
|
|
1627
1799
|
}
|
|
1628
|
-
(_b = (_a = this.
|
|
1800
|
+
(_b = (_a = this.floatingEl) == null ? void 0 : _a.classList) == null ? void 0 : _b.remove("popup-active");
|
|
1629
1801
|
(_c = this.cleanup) == null ? void 0 : _c.call(this);
|
|
1630
1802
|
this.cleanup = void 0;
|
|
1631
1803
|
document.removeEventListener("click", this.clickHandler, { capture: true });
|
|
1804
|
+
this._restoreContentFromPortal();
|
|
1632
1805
|
if (this.hasAttribute("active")) {
|
|
1633
1806
|
this.removeAttribute("active");
|
|
1634
1807
|
}
|
|
@@ -1648,4 +1821,4 @@ class Popup extends WJElement {
|
|
|
1648
1821
|
export {
|
|
1649
1822
|
Popup as P
|
|
1650
1823
|
};
|
|
1651
|
-
//# sourceMappingURL=popup.element-
|
|
1824
|
+
//# sourceMappingURL=popup.element-B0Lm42bh.js.map
|