wj-elements 0.6.1 → 0.7.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.
@@ -1404,7 +1404,8 @@ const computePosition = (reference, floating, options) => {
1404
1404
  platform: platformWithCache
1405
1405
  });
1406
1406
  };
1407
- const styles = "/*\n[ WJ Popup ]\n*/\n\n:host {\n --wje-popup-top: auto;\n --wje-popup-left: auto;\n\n display: flex; /* zmenene z contents na flex kvoli breadcrumbs v a jeho trom bodkam */\n}\n\n.native-popup {\n position: absolute;\n isolation: isolate;\n z-index: 999;\n left: var(--wje-popup-left);\n top: var(--wje-popup-top);\n}\n.native-popup:not(.popup-active) {\n display: none;\n}\n\n.popup-loader.overlay {\n position: absolute;\n inset: 1px;\n background: var(--wje-popup-overlay-background);\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: 1;\n}\n.popup-loader.fade-out {\n opacity: 0;\n transition: opacity 0.3s ease;\n pointer-events: none;\n}";
1407
+ const styles = "/*\n[ WJ Popup ]\n*/\n\n:host {\n --wje-popup-top: auto;\n --wje-popup-left: auto;\n --wje-popup-mobile-transition-duration: 250ms;\n --wje-popup-mobile-transition-easing: ease;\n\n display: flex; /* zmenene z contents na flex kvoli breadcrumbs v a jeho trom bodkam */\n}\n\n.popup-backdrop {\n display: none;\n}\n\n.native-popup {\n position: absolute;\n isolation: isolate;\n z-index: 999;\n left: var(--wje-popup-left);\n top: var(--wje-popup-top);\n}\n.native-popup:not(.popup-active) {\n display: none;\n}\n\n.popup-backdrop.popup-mobile-sheet {\n display: block;\n position: fixed;\n inset: 0;\n z-index: 998;\n opacity: 0;\n pointer-events: none;\n background: var(\n --wje-popup-backdrop-background,\n var(--wje-sliding-container-backdrop-background, var(--wje-backdrop, rgba(0, 0, 0, 0.35)))\n );\n transition:\n opacity var(--wje-popup-mobile-transition-duration) var(--wje-popup-mobile-transition-easing),\n visibility 0s linear var(--wje-popup-mobile-transition-duration);\n visibility: hidden;\n}\n\n.popup-backdrop.popup-mobile-sheet.popup-active {\n opacity: var(\n --wje-popup-backdrop-opacity,\n var(--wje-sliding-container-backdrop-opacity, var(--wje-backdrop-opacity, 1))\n );\n pointer-events: auto;\n visibility: visible;\n transition-delay: 0s;\n}\n\n.native-popup.popup-mobile-sheet {\n display: flex;\n flex-direction: column;\n align-items: stretch;\n position: fixed;\n inset: auto 0 0 0;\n left: 0;\n right: 0;\n top: auto;\n width: 100vw;\n max-width: 100vw;\n max-height: var(--wje-popup-mobile-max-height, 90vh);\n overflow: auto;\n background: var(\n --wje-popup-mobile-background,\n var(--wje-select-options-background-color, var(--wje-color-contrast-0, #fff))\n );\n box-shadow: var(--wje-popup-mobile-box-shadow, 0 -8px 32px rgba(0, 0, 0, 0.16));\n border-radius: var(\n --wje-popup-mobile-border-radius,\n var(\n --wje-sliding-container-sheet-border-radius,\n var(--wje-border-radius-large, 16px) var(--wje-border-radius-large, 16px) 0 0\n )\n );\n padding-bottom: env(safe-area-inset-bottom, 0);\n transform: translateY(100%);\n transition:\n transform var(--wje-popup-mobile-transition-duration) var(--wje-popup-mobile-transition-easing),\n visibility 0s linear var(--wje-popup-mobile-transition-duration);\n visibility: hidden;\n pointer-events: none;\n}\n\n.native-popup.popup-mobile-sheet.popup-active {\n transform: translateY(0);\n visibility: visible;\n pointer-events: auto;\n transition-delay: 0s;\n}\n\n.popup-loader.overlay {\n position: absolute;\n inset: var(--wje-popup-loader-inset, 0);\n background: var(\n --wje-popup-overlay-background,\n var(--wje-select-options-background-color, var(--wje-color-contrast-0, #fff))\n );\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: 1;\n}\n.popup-loader.fade-out {\n opacity: 0;\n transition: opacity 0.3s ease;\n pointer-events: none;\n}\n";
1408
+ const POPUP_MOBILE_SHEET_TRANSITION_FALLBACK_MS = 250;
1408
1409
  class Popup extends WJElement {
1409
1410
  /**
1410
1411
  * Creates an instance of Popup.
@@ -1419,11 +1420,25 @@ class Popup extends WJElement {
1419
1420
  });
1420
1421
  __publicField(this, "clickHandler", (e) => {
1421
1422
  const path = typeof e.composedPath === "function" ? e.composedPath() : [];
1422
- const isMenuClick = path.some((n) => n && (n.tagName === "WJE-MENU-ITEM" || n.tagName === "WJE-MENU"));
1423
+ const isMenuClick = path.some(
1424
+ (n) => n && (n.tagName === "WJE-MENU-ITEM" || n.tagName === "WJE-MENU")
1425
+ // ||
1426
+ // n.tagName === 'WJE-DROPDOWNs'
1427
+ );
1423
1428
  if (isMenuClick) return;
1424
1429
  const inside = path.includes(this) || this.floatingEl && path.includes(this.floatingEl);
1425
1430
  if (!inside && this.hasAttribute("active")) this.hide(true);
1426
1431
  });
1432
+ __publicField(this, "handleBackdropClick", (e) => {
1433
+ var _a;
1434
+ if (!this.hasAttribute("active") || !((_a = this.floatingEl) == null ? void 0 : _a.classList.contains("popup-mobile-sheet"))) return;
1435
+ e.stopPropagation();
1436
+ this.hide(true);
1437
+ });
1438
+ __publicField(this, "handleViewportResize", () => {
1439
+ if (!this.mobilePresentation || !this.hasAttribute("active")) return;
1440
+ this.syncResponsivePresentation();
1441
+ });
1427
1442
  /**
1428
1443
  * Removes the active attribute when the popup is hidden.
1429
1444
  */
@@ -1431,17 +1446,28 @@ class Popup extends WJElement {
1431
1446
  this.removeAttribute("active");
1432
1447
  });
1433
1448
  this._manual = false;
1449
+ this._contentAwareSize = false;
1450
+ this._contentReadyHandler = () => this.markContentReady();
1451
+ this._bottomSheetRestoreTimeout = null;
1434
1452
  }
1435
1453
  set loader(value) {
1436
1454
  if (value) {
1437
1455
  this.setAttribute("loader", "");
1456
+ this._showLoader();
1438
1457
  } else {
1439
1458
  this.removeAttribute("loader");
1459
+ this._hideLoader();
1440
1460
  }
1441
1461
  }
1442
1462
  get loader() {
1443
1463
  return this.hasAttribute("loader");
1444
1464
  }
1465
+ set contentAwareSize(value) {
1466
+ this._contentAwareSize = Boolean(value);
1467
+ }
1468
+ get contentAwareSize() {
1469
+ return this._contentAwareSize === true;
1470
+ }
1445
1471
  /**
1446
1472
  * Sets the manual property of the popup.
1447
1473
  * @param {boolean} value The value to set.
@@ -1477,9 +1503,26 @@ class Popup extends WJElement {
1477
1503
  get portal() {
1478
1504
  return this.hasAttribute("portal");
1479
1505
  }
1506
+ set mobilePresentation(value) {
1507
+ if (value) this.setAttribute("mobile-presentation", value);
1508
+ else this.removeAttribute("mobile-presentation");
1509
+ }
1510
+ get mobilePresentation() {
1511
+ return this.getAttribute("mobile-presentation");
1512
+ }
1513
+ set mobileBreakPoint(value) {
1514
+ if (value) this.setAttribute("mobile-break-point", value);
1515
+ else this.removeAttribute("mobile-break-point");
1516
+ }
1517
+ get mobileBreakPoint() {
1518
+ return this.getAttribute("mobile-break-point") || "768";
1519
+ }
1480
1520
  get floatingEl() {
1481
1521
  return this._floatingEl || this.native;
1482
1522
  }
1523
+ get backdropEl() {
1524
+ return this._portaled ? this._portalBackdrop : this.backdrop;
1525
+ }
1483
1526
  /**
1484
1527
  * Returns the CSS styles for the component.
1485
1528
  * @static
@@ -1526,11 +1569,17 @@ class Popup extends WJElement {
1526
1569
  this._hiddenFloatingLightDomContent = null;
1527
1570
  }
1528
1571
  afterDisconnect() {
1529
- var _a;
1572
+ var _a, _b, _c;
1573
+ this.clearBottomSheetRestoreTimeout();
1574
+ window.removeEventListener("resize", this.handleViewportResize);
1530
1575
  event.removeListener(this.anchorEl, "click", this.manualCallback);
1531
1576
  document.removeEventListener("click", this.clickHandler, { capture: true });
1577
+ this.removeEventListener("wje-popup:content-ready", this._contentReadyHandler);
1578
+ this._contentReadyListenerAttached = false;
1579
+ (_a = this.backdrop) == null ? void 0 : _a.removeEventListener("click", this.handleBackdropClick);
1580
+ (_b = this._portalBackdrop) == null ? void 0 : _b.removeEventListener("click", this.handleBackdropClick);
1532
1581
  this._restoreContentFromPortal();
1533
- (_a = this.cleanup) == null ? void 0 : _a.call(this);
1582
+ (_c = this.cleanup) == null ? void 0 : _c.call(this);
1534
1583
  }
1535
1584
  beforeDraw(context, store, params) {
1536
1585
  var _a;
@@ -1546,6 +1595,10 @@ class Popup extends WJElement {
1546
1595
  slotAnchor.setAttribute("name", "anchor");
1547
1596
  let slotArrow = document.createElement("slot");
1548
1597
  slotArrow.setAttribute("name", "arrow");
1598
+ let backdrop = document.createElement("div");
1599
+ backdrop.setAttribute("part", "backdrop");
1600
+ backdrop.classList.add("popup-backdrop");
1601
+ backdrop.addEventListener("click", this.handleBackdropClick);
1549
1602
  let native = document.createElement("div");
1550
1603
  native.setAttribute("part", "native");
1551
1604
  native.classList.add("native-popup");
@@ -1558,9 +1611,12 @@ class Popup extends WJElement {
1558
1611
  native.append(slot);
1559
1612
  native.append(slotArrow);
1560
1613
  fragment.append(slotAnchor);
1614
+ fragment.append(backdrop);
1561
1615
  fragment.append(native);
1562
1616
  this.slotAnchor = slotAnchor;
1563
1617
  this.slotArrow = slotArrow;
1618
+ this.defaultSlot = slot;
1619
+ this.backdrop = backdrop;
1564
1620
  this.native = native;
1565
1621
  this.loaderEl = loader;
1566
1622
  return fragment;
@@ -1571,9 +1627,12 @@ class Popup extends WJElement {
1571
1627
  afterDraw() {
1572
1628
  this._restoreFloatingLightDomContentAfterRender();
1573
1629
  this.setAnchor();
1574
- this.addEventListener("wje-popup:content-ready", () => {
1575
- this.markContentReady();
1576
- }, { once: true });
1630
+ window.removeEventListener("resize", this.handleViewportResize);
1631
+ window.addEventListener("resize", this.handleViewportResize);
1632
+ if (!this._contentReadyListenerAttached) {
1633
+ this.addEventListener("wje-popup:content-ready", this._contentReadyHandler);
1634
+ this._contentReadyListenerAttached = true;
1635
+ }
1577
1636
  if (this.hasAttribute("active")) this.show(false);
1578
1637
  if (!this.hasAttribute("active")) this.hide(false);
1579
1638
  }
@@ -1592,6 +1651,101 @@ class Popup extends WJElement {
1592
1651
  event.addListener(this.anchorEl, "click", null, this.manualCallback, { stopPropagation: true });
1593
1652
  }
1594
1653
  }
1654
+ clearBottomSheetRestoreTimeout() {
1655
+ if (this._bottomSheetRestoreTimeout === null) return;
1656
+ window.clearTimeout(this._bottomSheetRestoreTimeout);
1657
+ this._bottomSheetRestoreTimeout = null;
1658
+ }
1659
+ isBottomSheetActive() {
1660
+ return this.mobilePresentation === "bottom-sheet" && window.innerWidth <= +this.mobileBreakPoint;
1661
+ }
1662
+ setBottomSheetState(isActive) {
1663
+ const native = this.floatingEl;
1664
+ const backdrop = this.backdropEl;
1665
+ if (!native || !backdrop) return;
1666
+ native.classList.add("popup-mobile-sheet");
1667
+ backdrop.classList.add("popup-mobile-sheet");
1668
+ native.classList.toggle("popup-active", isActive);
1669
+ backdrop.classList.toggle("popup-active", isActive);
1670
+ }
1671
+ clearBottomSheetState() {
1672
+ [this.native, this.backdrop, this._portalNative, this._portalBackdrop].forEach((el) => {
1673
+ el == null ? void 0 : el.classList.remove("popup-mobile-sheet", "popup-active");
1674
+ });
1675
+ }
1676
+ rebindPortaledRouter() {
1677
+ if (!this._portalShadow) return;
1678
+ const detail = {
1679
+ root: this._portalShadow,
1680
+ container: this._portalContainer,
1681
+ floating: this._portalNative
1682
+ };
1683
+ document.dispatchEvent(new CustomEvent("wje-router:rebind", { bubbles: true, composed: true, detail }));
1684
+ if (typeof window.bindRouterLinks === "function") {
1685
+ window.bindRouterLinks(this._portalShadow);
1686
+ }
1687
+ }
1688
+ syncResponsivePresentation() {
1689
+ var _a, _b, _c, _d, _e, _f;
1690
+ const shouldUseBottomSheet = this.isBottomSheetActive();
1691
+ const isUsingBottomSheet = (_b = (_a = this.floatingEl) == null ? void 0 : _a.classList) == null ? void 0 : _b.contains("popup-mobile-sheet");
1692
+ if (shouldUseBottomSheet) {
1693
+ (_c = this.cleanup) == null ? void 0 : _c.call(this);
1694
+ this.cleanup = void 0;
1695
+ if (!this._portaled) {
1696
+ this._mountContentToPortal();
1697
+ this.rebindPortaledRouter();
1698
+ }
1699
+ this.setBottomSheetState(false);
1700
+ (_d = this.floatingEl) == null ? void 0 : _d.getBoundingClientRect();
1701
+ (_e = this.backdropEl) == null ? void 0 : _e.getBoundingClientRect();
1702
+ requestAnimationFrame(() => {
1703
+ if (!this.hasAttribute("active") || !this.isBottomSheetActive()) return;
1704
+ this.setBottomSheetState(true);
1705
+ });
1706
+ return;
1707
+ }
1708
+ if (isUsingBottomSheet) {
1709
+ this.clearBottomSheetRestoreTimeout();
1710
+ this.clearBottomSheetState();
1711
+ if (!this.portal && this._portaled) {
1712
+ this._restoreContentFromPortal();
1713
+ }
1714
+ }
1715
+ if (this.anchorEl && this.floatingEl) {
1716
+ this.floatingEl.classList.add("popup-active");
1717
+ (_f = this.cleanup) == null ? void 0 : _f.call(this);
1718
+ this.cleanup = autoUpdate(this.anchorEl, this.floatingEl, () => {
1719
+ this.reposition();
1720
+ });
1721
+ this.reposition();
1722
+ }
1723
+ }
1724
+ getBottomSheetTransitionDurationMs() {
1725
+ const parseDuration = (value) => {
1726
+ const trimmedValue = value == null ? void 0 : value.trim();
1727
+ if (!trimmedValue) return 0;
1728
+ if (trimmedValue.endsWith("ms")) return Number.parseFloat(trimmedValue) || 0;
1729
+ if (trimmedValue.endsWith("s")) return (Number.parseFloat(trimmedValue) || 0) * 1e3;
1730
+ return Number.parseFloat(trimmedValue) || 0;
1731
+ };
1732
+ const getMaxDuration = (el) => {
1733
+ if (!el) return 0;
1734
+ const computedStyles = getComputedStyle(el);
1735
+ const durations = computedStyles.transitionDuration.split(",");
1736
+ const delays = computedStyles.transitionDelay.split(",");
1737
+ const count = Math.max(durations.length, delays.length);
1738
+ let maxDuration = 0;
1739
+ for (let i = 0; i < count; i++) {
1740
+ const duration = parseDuration(durations[i] || durations[durations.length - 1]);
1741
+ const delay = parseDuration(delays[i] || delays[delays.length - 1]);
1742
+ maxDuration = Math.max(maxDuration, duration + delay);
1743
+ }
1744
+ return maxDuration;
1745
+ };
1746
+ const transitionDuration = Math.max(getMaxDuration(this.floatingEl), getMaxDuration(this.backdropEl));
1747
+ return transitionDuration || POPUP_MOBILE_SHEET_TRANSITION_FALLBACK_MS;
1748
+ }
1595
1749
  /**
1596
1750
  * Toggles the active attribute of the popup.
1597
1751
  */
@@ -1609,6 +1763,8 @@ class Popup extends WJElement {
1609
1763
  * Uses the floating-ui library to compute the position.
1610
1764
  */
1611
1765
  reposition() {
1766
+ var _a, _b;
1767
+ if ((_b = (_a = this.floatingEl) == null ? void 0 : _a.classList) == null ? void 0 : _b.contains("popup-mobile-sheet")) return;
1612
1768
  const middleware = [];
1613
1769
  this.offsetCalc = +this.offset || 0;
1614
1770
  if (this.portal && this._portaled && this.floatingEl) {
@@ -1629,8 +1785,16 @@ class Popup extends WJElement {
1629
1785
  if (this.hasAttribute("size")) {
1630
1786
  middleware.push(
1631
1787
  size({
1632
- apply({ availableWidth, availableHeight, elements }) {
1788
+ apply: ({ elements }) => {
1789
+ if (this.contentAwareSize) {
1790
+ Object.assign(elements.floating.style, {
1791
+ minWidth: `${elements.reference.offsetWidth}px`,
1792
+ width: ""
1793
+ });
1794
+ return;
1795
+ }
1633
1796
  Object.assign(elements.floating.style, {
1797
+ minWidth: "",
1634
1798
  width: `${elements.reference.offsetWidth}px`
1635
1799
  });
1636
1800
  }
@@ -1681,6 +1845,10 @@ class Popup extends WJElement {
1681
1845
  if (this._portaled) return;
1682
1846
  this._ensurePortalRoot();
1683
1847
  if (!this._portalNative) {
1848
+ this._portalBackdrop = document.createElement("div");
1849
+ this._portalBackdrop.setAttribute("part", "backdrop");
1850
+ this._portalBackdrop.classList.add("popup-backdrop");
1851
+ this._portalBackdrop.addEventListener("click", this.handleBackdropClick);
1684
1852
  this._portalNative = document.createElement("div");
1685
1853
  this._portalNative.setAttribute("part", "native");
1686
1854
  this._portalNative.classList.add("native-popup");
@@ -1689,9 +1857,11 @@ class Popup extends WJElement {
1689
1857
  this._portalArrowSlot.setAttribute("name", "arrow");
1690
1858
  this._portalNative.append(this._portalSlot, this._portalArrowSlot);
1691
1859
  }
1860
+ this._portalShadow.append(this._portalBackdrop);
1692
1861
  this._portalShadow.append(this._portalNative);
1693
1862
  const mirrorAll = () => {
1694
1863
  for (const { name } of Array.from(this._portalContainer.attributes)) {
1864
+ if (name === "data-wje-popup-portal") continue;
1695
1865
  this._portalContainer.removeAttribute(name);
1696
1866
  }
1697
1867
  for (const attr of Array.from(this.attributes)) {
@@ -1711,8 +1881,10 @@ class Popup extends WJElement {
1711
1881
  }
1712
1882
  });
1713
1883
  this._portalAttrObserver.observe(this, { attributes: true });
1714
- const defaultSlot = this.shadowRoot.querySelector("slot:not([name])");
1715
- const defNodes = (defaultSlot ? defaultSlot.assignedNodes({ flatten: true }) : []).filter((n) => n && n.nodeType === Node.ELEMENT_NODE || n && n.nodeType === Node.TEXT_NODE);
1884
+ const defaultSlot = this.defaultSlot;
1885
+ const defNodes = (defaultSlot ? defaultSlot.assignedNodes({ flatten: true }) : []).filter(
1886
+ (n) => n && n.nodeType === Node.ELEMENT_NODE || n && n.nodeType === Node.TEXT_NODE
1887
+ );
1716
1888
  this._defPlaceholders = [];
1717
1889
  for (const n of defNodes) {
1718
1890
  const ph = document.createComment("wje-portal-default");
@@ -1732,7 +1904,11 @@ class Popup extends WJElement {
1732
1904
  this._portaled = true;
1733
1905
  this._floatingEl = this._portalNative;
1734
1906
  this._portaled = true;
1735
- event.dispatchCustomEvent(this, "wje-router:rebind", { root: this._portalShadow, container: this._portalContainer, floating: this._portalNative });
1907
+ event.dispatchCustomEvent(this, "wje-router:rebind", {
1908
+ root: this._portalShadow,
1909
+ container: this._portalContainer,
1910
+ floating: this._portalNative
1911
+ });
1736
1912
  }
1737
1913
  /**
1738
1914
  * Restores the content previously moved to a portal back to its original location.
@@ -1768,6 +1944,9 @@ class Popup extends WJElement {
1768
1944
  if (this._portalNative && this._portalNative.parentNode) {
1769
1945
  this._portalNative.remove();
1770
1946
  }
1947
+ if (this._portalBackdrop && this._portalBackdrop.parentNode) {
1948
+ this._portalBackdrop.remove();
1949
+ }
1771
1950
  this._floatingEl = void 0;
1772
1951
  this._portaled = false;
1773
1952
  if (this._portalContainer) {
@@ -1825,9 +2004,9 @@ class Popup extends WJElement {
1825
2004
  host.style.setProperty(prop, comp.getPropertyValue(prop));
1826
2005
  }
1827
2006
  }
1828
- if (this.getAttribute("portal") === "dialog") {
2007
+ if (this.getAttribute("portal") === "dialog" || this.isBottomSheetActive() && this.findDialog(this)) {
1829
2008
  const dialog = this.findDialog(this);
1830
- if (this.getAttribute("portal") === "dialog" && dialog) {
2009
+ if (dialog) {
1831
2010
  dialog.append(host);
1832
2011
  } else {
1833
2012
  document.body.append(host);
@@ -1854,29 +2033,32 @@ class Popup extends WJElement {
1854
2033
  * @returns {void} Does not return any value.
1855
2034
  */
1856
2035
  show(dispatchEvent = true) {
1857
- var _a, _b, _c, _d, _e, _f, _g, _h;
2036
+ var _a, _b, _c, _d, _e;
2037
+ this.clearBottomSheetRestoreTimeout();
1858
2038
  event.dispatchCustomEvent(document, "wje-popup:opened", { popup: this });
1859
- if (this.portal) {
2039
+ if (this.portal || this.isBottomSheetActive()) {
1860
2040
  this._mountContentToPortal();
1861
- if (this.portal && this._portalShadow) {
1862
- const detail = { root: this._portalShadow, container: this._portalContainer, floating: this._portalNative };
1863
- document.dispatchEvent(new CustomEvent("wje-router:rebind", { bubbles: true, composed: true, detail }));
1864
- if (typeof window.bindRouterLinks === "function") {
1865
- window.bindRouterLinks(this._portalShadow);
1866
- }
1867
- }
2041
+ this.rebindPortaledRouter();
1868
2042
  }
1869
2043
  if (this.loader) {
1870
- (_b = (_a = this.floatingEl) == null ? void 0 : _a.classList) == null ? void 0 : _b.add("loading");
1871
- (_d = (_c = this.loaderEl) == null ? void 0 : _c.classList) == null ? void 0 : _d.remove("fade-out");
1872
- (_e = this.floatingEl) == null ? void 0 : _e.prepend(this.loaderEl);
2044
+ this._showLoader();
1873
2045
  }
1874
2046
  if (dispatchEvent) {
1875
2047
  event.dispatchCustomEvent(this, "wje-popup:show");
1876
2048
  }
1877
- if (this.anchorEl && this.floatingEl) {
1878
- (_g = (_f = this.floatingEl) == null ? void 0 : _f.classList) == null ? void 0 : _g.add("popup-active");
1879
- (_h = this.cleanup) == null ? void 0 : _h.call(this);
2049
+ if (this.isBottomSheetActive()) {
2050
+ this.setBottomSheetState(false);
2051
+ (_a = this.floatingEl) == null ? void 0 : _a.getBoundingClientRect();
2052
+ (_b = this.backdropEl) == null ? void 0 : _b.getBoundingClientRect();
2053
+ requestAnimationFrame(() => {
2054
+ if (!this.hasAttribute("active")) return;
2055
+ this.setBottomSheetState(true);
2056
+ });
2057
+ document.addEventListener("click", this.clickHandler, { capture: true });
2058
+ } else if (this.anchorEl && this.floatingEl) {
2059
+ this.clearBottomSheetState();
2060
+ (_d = (_c = this.floatingEl) == null ? void 0 : _c.classList) == null ? void 0 : _d.add("popup-active");
2061
+ (_e = this.cleanup) == null ? void 0 : _e.call(this);
1880
2062
  this.cleanup = autoUpdate(this.anchorEl, this.floatingEl, () => {
1881
2063
  this.reposition();
1882
2064
  });
@@ -1892,34 +2074,60 @@ class Popup extends WJElement {
1892
2074
  * Cleans up the auto update for repositioning.
1893
2075
  */
1894
2076
  hide(dispatchEvent = true) {
1895
- var _a, _b, _c;
2077
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1896
2078
  if (dispatchEvent) {
1897
2079
  event.dispatchCustomEvent(this, "wje-popup:hide");
1898
2080
  }
1899
- (_b = (_a = this.floatingEl) == null ? void 0 : _a.classList) == null ? void 0 : _b.remove("popup-active");
1900
- (_c = this.cleanup) == null ? void 0 : _c.call(this);
2081
+ (_a = this.cleanup) == null ? void 0 : _a.call(this);
1901
2082
  this.cleanup = void 0;
1902
2083
  document.removeEventListener("click", this.clickHandler, { capture: true });
1903
- if (this.portal && this._portaled) {
1904
- this._restoreContentFromPortal();
2084
+ const shouldAnimateBottomSheetClose = (_c = (_b = this.floatingEl) == null ? void 0 : _b.classList) == null ? void 0 : _c.contains("popup-mobile-sheet");
2085
+ if (shouldAnimateBottomSheetClose) {
2086
+ (_e = (_d = this.backdropEl) == null ? void 0 : _d.classList) == null ? void 0 : _e.remove("popup-active");
2087
+ (_g = (_f = this.floatingEl) == null ? void 0 : _f.classList) == null ? void 0 : _g.remove("popup-active");
2088
+ this.clearBottomSheetRestoreTimeout();
2089
+ this._bottomSheetRestoreTimeout = window.setTimeout(() => {
2090
+ this.clearBottomSheetState();
2091
+ if (this._portaled) {
2092
+ this._restoreContentFromPortal();
2093
+ }
2094
+ this._bottomSheetRestoreTimeout = null;
2095
+ }, this.getBottomSheetTransitionDurationMs());
2096
+ } else {
2097
+ (_i = (_h = this.floatingEl) == null ? void 0 : _h.classList) == null ? void 0 : _i.remove("popup-active");
2098
+ this.clearBottomSheetState();
2099
+ if (this._portaled) {
2100
+ this._restoreContentFromPortal();
2101
+ }
1905
2102
  }
1906
2103
  if (this.hasAttribute("active")) {
1907
2104
  this.removeAttribute("active");
1908
2105
  }
1909
2106
  }
1910
- markContentReady() {
1911
- this.native.classList.remove("loading");
1912
- if (this.loader) {
1913
- this.loaderEl.classList.add("fade-out");
1914
- setTimeout(() => {
1915
- var _a;
1916
- (_a = this.loaderEl) == null ? void 0 : _a.remove();
1917
- this.loader = false;
1918
- }, 300);
2107
+ _showLoader() {
2108
+ const floating = this.floatingEl;
2109
+ if (!(floating instanceof HTMLElement) || !(this.loaderEl instanceof HTMLElement)) return;
2110
+ floating.classList.add("loading");
2111
+ this.loaderEl.classList.remove("fade-out");
2112
+ if (this.loaderEl.parentElement !== floating) {
2113
+ floating.prepend(this.loaderEl);
1919
2114
  }
1920
2115
  }
2116
+ _hideLoader() {
2117
+ var _a, _b, _c, _d, _e, _f;
2118
+ (_b = (_a = this.native) == null ? void 0 : _a.classList) == null ? void 0 : _b.remove("loading");
2119
+ (_d = (_c = this._portalNative) == null ? void 0 : _c.classList) == null ? void 0 : _d.remove("loading");
2120
+ (_f = (_e = this.floatingEl) == null ? void 0 : _e.classList) == null ? void 0 : _f.remove("loading");
2121
+ if (this.loaderEl instanceof HTMLElement) {
2122
+ this.loaderEl.classList.remove("fade-out");
2123
+ this.loaderEl.remove();
2124
+ }
2125
+ }
2126
+ markContentReady() {
2127
+ this.loader = false;
2128
+ }
1921
2129
  }
1922
2130
  export {
1923
2131
  Popup as P
1924
2132
  };
1925
- //# sourceMappingURL=popup.element-B1HZhDZJ.js.map
2133
+ //# sourceMappingURL=popup.element-CwXvVFK7.js.map