ember-attacher 5.0.0 → 5.1.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.
@@ -1,7 +1,7 @@
1
1
  import { getOwner } from '@ember/application';
2
2
  import { isDestroying, isDestroyed, registerDestructor } from '@ember/destroyable';
3
3
  import { runInDebug, warn, assert } from '@ember/debug';
4
- import { arrow, flip, shift, limitShift, autoUpdate, computePosition } from '@floating-ui/dom';
4
+ import { platform, arrow, offset, flip, shift, limitShift, autoUpdate, computePosition } from '@floating-ui/dom';
5
5
  import { tracked } from '@glimmer/tracking';
6
6
  import Modifier, { modifier } from 'ember-modifier';
7
7
  import DEFAULTS, { POPOVER_DEFAULTS } from './defaults.js';
@@ -673,12 +673,88 @@ function isVirtualReference(value) {
673
673
  return typeof value.getBoundingClientRect === 'function';
674
674
  }
675
675
 
676
+ /** Whether a `@target` string uses a relative DOM token (`:previous`, `:previous(...)`, `:parent`, `:closest(...)`). */
677
+ function isRelativeTargetToken(value) {
678
+ return typeof value === 'string' && value.startsWith(':');
679
+ }
680
+
681
+ /** Non-asserting lookup for relative target tokens used to detect stale DOM bindings. */
682
+ function peekRelativeTarget(token, floatingElement) {
683
+ if (!floatingElement) {
684
+ return null;
685
+ }
686
+ if (token === ':parent') {
687
+ return floatingElement.parentElement;
688
+ }
689
+ if (token === ':previous' || token.startsWith(':previous(') && token.endsWith(')')) {
690
+ const selector = token === ':previous' ? null : token.slice(':previous('.length, -1).trim();
691
+ if (selector !== null && selector.length === 0) {
692
+ return null;
693
+ }
694
+ let sibling = floatingElement.previousElementSibling;
695
+ while (sibling?.classList.contains('ember-attacher')) {
696
+ sibling = sibling.previousElementSibling;
697
+ }
698
+ if (!sibling) {
699
+ return null;
700
+ }
701
+ if (selector && !sibling.matches(selector)) {
702
+ return null;
703
+ }
704
+ return sibling;
705
+ }
706
+ if (token.startsWith(':closest(') && token.endsWith(')')) {
707
+ const selector = token.slice(':closest('.length, -1).trim();
708
+ if (!selector) {
709
+ return null;
710
+ }
711
+ return floatingElement.parentElement?.closest(selector) ?? null;
712
+ }
713
+ return null;
714
+ }
715
+ function resolveRelativeTarget(token, floatingElement) {
716
+ assert(`@target="${token}" requires a mounted Attachment Host element (<AttachTooltip>, <AttachPopover>, or <Attacher @lazyRender={{false}}>).`, floatingElement != null);
717
+ if (!floatingElement) {
718
+ return null;
719
+ }
720
+ if (token === ':parent') {
721
+ const parent = floatingElement.parentElement;
722
+ assert('@target=":parent" could not resolve a parentElement', parent != null);
723
+ return parent;
724
+ }
725
+ if (token === ':previous' || token.startsWith(':previous(') && token.endsWith(')')) {
726
+ const selector = token === ':previous' ? null : token.slice(':previous('.length, -1).trim();
727
+ assert('@target=":previous()" requires a non-empty selector', selector === null || selector.length > 0);
728
+ let sibling = floatingElement.previousElementSibling;
729
+ while (sibling?.classList.contains('ember-attacher')) {
730
+ sibling = sibling.previousElementSibling;
731
+ }
732
+ assert(`@target="${token}" found no preceding non-attacher sibling element`, sibling != null);
733
+ if (sibling && selector) {
734
+ assert(`@target="${token}" expected the preceding sibling <${sibling.tagName.toLowerCase()}> to match "${selector}"`, sibling.matches(selector));
735
+ return sibling.matches(selector) ? sibling : null;
736
+ }
737
+ return sibling;
738
+ }
739
+ if (token.startsWith(':closest(') && token.endsWith(')')) {
740
+ const selector = token.slice(':closest('.length, -1).trim();
741
+ assert('@target=":closest()" requires a non-empty selector', selector.length > 0);
742
+ const match = floatingElement.parentElement?.closest(selector) ?? null;
743
+ assert(`@target="${token}" found no ancestor matching "${selector}"`, match != null);
744
+ return match;
745
+ }
746
+ assert(`[ember-attacher] Unknown relative @target token "${token}". Supported: :previous, :previous(<selector>), :parent, :closest(<selector>).`, false);
747
+ return null;
748
+ }
749
+
676
750
  /**
677
- * Resolve a public `@target` value (Element | selector | virtual ref).
751
+ * Resolve a public `@target` value (Element | selector | relative token | virtual ref).
678
752
  *
679
753
  * Selector strings use `querySelectorAll` and must match exactly one node.
754
+ * Relative tokens (`:previous`, `:previous(selector)`, `:parent`, `:closest(selector)`)
755
+ * resolve from the in-place `floatingElement` Host without `<meta hidden>` markers.
680
756
  */
681
- function coerceTarget(value, root) {
757
+ function coerceTarget(value, root, floatingElement) {
682
758
  if (value == null) {
683
759
  return null;
684
760
  }
@@ -686,6 +762,9 @@ function coerceTarget(value, root) {
686
762
  return value;
687
763
  }
688
764
  if (typeof value === 'string') {
765
+ if (isRelativeTargetToken(value)) {
766
+ return resolveRelativeTarget(value, floatingElement);
767
+ }
689
768
  const doc = root ?? (typeof document !== 'undefined' ? document : null);
690
769
  assert(`@target selector "${value}" cannot be resolved without a document`, doc != null);
691
770
  const matches = doc.querySelectorAll(value);
@@ -737,10 +816,11 @@ function resolveAttachmentTarget({
737
816
  target,
738
817
  registeredTarget,
739
818
  triggerTargets,
740
- root
819
+ root,
820
+ floatingElement
741
821
  }) {
742
822
  if (target != null) {
743
- return coerceTarget(target, root);
823
+ return coerceTarget(target, root, floatingElement);
744
824
  }
745
825
  if (registeredTarget != null) {
746
826
  return registeredTarget;
@@ -828,6 +908,80 @@ function hidePopoverHost(el) {
828
908
  }
829
909
 
830
910
  const DEFAULT_SHIFT_PADDING = 5;
911
+ const OVERFLOW_CLIP_RE = /auto|scroll|overlay|hidden|clip/;
912
+ function isTopLayerElement(element) {
913
+ try {
914
+ if (element.matches(':popover-open')) {
915
+ return true;
916
+ }
917
+ } catch {
918
+ // Unsupported selector in older engines
919
+ }
920
+ try {
921
+ if (element.matches(':modal')) {
922
+ return true;
923
+ }
924
+ } catch {
925
+ // Unsupported selector in older engines
926
+ }
927
+ return false;
928
+ }
929
+ function findEnclosingTopLayerHost(element) {
930
+ let current = element.parentElement;
931
+ while (current) {
932
+ if (isTopLayerElement(current)) {
933
+ return current;
934
+ }
935
+ current = current.parentElement;
936
+ }
937
+ return null;
938
+ }
939
+ function collectOverflowAncestorsUpTo(element, topLayerHost) {
940
+ const ancestors = [];
941
+ let current = element.parentElement;
942
+ while (current) {
943
+ const isManagedTopLayerHost = current.classList.contains('ember-attacher') && current.hasAttribute('popover');
944
+ if (!isManagedTopLayerHost && typeof getComputedStyle === 'function') {
945
+ const {
946
+ overflow,
947
+ overflowX,
948
+ overflowY,
949
+ display
950
+ } = getComputedStyle(current);
951
+ if (OVERFLOW_CLIP_RE.test(overflow + overflowY + overflowX) && display !== 'inline' && display !== 'contents') {
952
+ ancestors.push(current);
953
+ }
954
+ }
955
+ if (current === topLayerHost) {
956
+ break;
957
+ }
958
+ current = current.parentElement;
959
+ }
960
+ return ancestors;
961
+ }
962
+
963
+ /**
964
+ * Floating UI platform adapter that stops `clippingAncestors` discovery at the
965
+ * nearest enclosing Top-Layer host (`:popover-open` or `:modal`), preventing
966
+ * background page overflow containers from falsely clipping references inside
967
+ * dialogs or nested popovers while preserving scroll clipping inside that host.
968
+ */
969
+ const topLayerAwarePlatform = {
970
+ ...platform,
971
+ getClippingRect(args) {
972
+ if (args.boundary === 'clippingAncestors' && isElementTarget(args.element) && !isTopLayerElement(args.element)) {
973
+ const topLayerHost = findEnclosingTopLayerHost(args.element);
974
+ if (topLayerHost) {
975
+ const scopedAncestors = collectOverflowAncestorsUpTo(args.element, topLayerHost);
976
+ return platform.getClippingRect.call(this, {
977
+ ...args,
978
+ boundary: scopedAncestors
979
+ });
980
+ }
981
+ }
982
+ return platform.getClippingRect.call(this, args);
983
+ }
984
+ };
831
985
 
832
986
  /** Check whether an attachment target (DOM Element or VirtualElement) is still connected. */
833
987
  function isTargetConnected(target) {
@@ -842,12 +996,18 @@ function isTargetConnected(target) {
842
996
  }
843
997
  return true;
844
998
  }
999
+ /** Whether a normalized middleware pipeline includes an `offset` entry. */
1000
+ function hasOffsetMiddleware(middleware) {
1001
+ return middleware.some(m => m.name === 'offset');
1002
+ }
1003
+
845
1004
  /**
846
1005
  * Normalize and deduplicate the Floating UI middleware array without mutating
847
1006
  * caller-supplied middleware objects.
848
1007
  */
849
1008
  function buildMiddleware({
850
1009
  rawMiddleware,
1010
+ offsetOptions,
851
1011
  arrowElement,
852
1012
  arrowEnabled
853
1013
  }) {
@@ -878,6 +1038,9 @@ function buildMiddleware({
878
1038
  }
879
1039
  middleware.push(m);
880
1040
  }
1041
+ if (offsetOptions !== undefined && offsetOptions !== null && !hasOffsetMiddleware(middleware)) {
1042
+ middleware.unshift(offset(offsetOptions));
1043
+ }
881
1044
  if (!middleware.some(m => m.name === 'flip')) {
882
1045
  middleware.push(flip());
883
1046
  }
@@ -1026,6 +1189,13 @@ function resolveTooltipClass(envConfig) {
1026
1189
  } = envConfig || {};
1027
1190
  return tooltip?.tooltipClass ?? tooltipClass ?? DEFAULTS.tooltipClass;
1028
1191
  }
1192
+ function resolvePopoverClass(envConfig) {
1193
+ const {
1194
+ popover,
1195
+ popoverClass
1196
+ } = envConfig || {};
1197
+ return popover?.popoverClass ?? popoverClass ?? DEFAULTS.popoverClass;
1198
+ }
1029
1199
  const TRUTHY_OPTION_KEYS = new Set(['animation', 'class']);
1030
1200
  const REMOVED_4X_ARGS = {
1031
1201
  explicitTarget: 'Use `@target` instead.',
@@ -1221,6 +1391,10 @@ let AttacherCore = (_class = class AttacherCore {
1221
1391
  this._lastUseCaptureArgumentValue = void 0;
1222
1392
  this._warnedRemovedArgs = new Set();
1223
1393
  this._cleanup = null;
1394
+ this._openingTriggerEvent = null;
1395
+ this._openingTriggerHandle = null;
1396
+ this._relativeTargetObserver = null;
1397
+ this._observedRelativeParent = null;
1224
1398
  this.api = void 0;
1225
1399
  /** Tracks template args read inside `<template>` and schedules an idle args sync. */
1226
1400
  this.syncArgs = (..._positional) => {
@@ -1238,6 +1412,7 @@ let AttacherCore = (_class = class AttacherCore {
1238
1412
  this._detachPopoverEvents(element);
1239
1413
  if (this._floatingElement === element) {
1240
1414
  this._floatingElement = null;
1415
+ this._disconnectRelativeTargetObserver();
1241
1416
  }
1242
1417
  this._cleanup?.();
1243
1418
  this._cleanup = null;
@@ -1274,6 +1449,7 @@ let AttacherCore = (_class = class AttacherCore {
1274
1449
  this._addedManagedPopover = false;
1275
1450
  if (this._floatingElement === element) {
1276
1451
  this._floatingElement = null;
1452
+ this._disconnectRelativeTargetObserver();
1277
1453
  }
1278
1454
  this._cleanup?.();
1279
1455
  this._cleanup = null;
@@ -1490,6 +1666,7 @@ let AttacherCore = (_class = class AttacherCore {
1490
1666
  isFillAnimation: this.isFillAnimation,
1491
1667
  isShown: this._isShown,
1492
1668
  isHiding: this._isHiding,
1669
+ hasOffset: this.hasOffset,
1493
1670
  container
1494
1671
  };
1495
1672
  }
@@ -1518,10 +1695,14 @@ let AttacherCore = (_class = class AttacherCore {
1518
1695
  get _middleware() {
1519
1696
  return buildMiddleware({
1520
1697
  rawMiddleware: this._opt('middleware'),
1698
+ offsetOptions: this._opt('offset'),
1521
1699
  arrowElement: this._arrowElement,
1522
1700
  arrowEnabled: this.arrow || !this._isComponentHost && Boolean(this._arrowElement)
1523
1701
  });
1524
1702
  }
1703
+ get hasOffset() {
1704
+ return hasOffsetMiddleware(this._middleware);
1705
+ }
1525
1706
  get _usePopoverHost() {
1526
1707
  return supportsPopoverHost() && !this._renderInPlace;
1527
1708
  }
@@ -1569,7 +1750,8 @@ let AttacherCore = (_class = class AttacherCore {
1569
1750
  const targetKey = `${this._opt('showOn')}|${this._opt('hideOn')}|${this.id}|${this._renderInPlace}`;
1570
1751
  const targetArg = this.targetArg;
1571
1752
  const isInitialSync = !this._prevSyncedTargetKey;
1572
- const targetChanged = isInitialSync || this._prevSyncedTargetKey !== targetKey || this._prevSyncedTarget !== targetArg;
1753
+ const relativeTargetStale = isRelativeTargetToken(targetArg) && (!isTargetConnected(this._currentTarget) || this._floatingElement != null && peekRelativeTarget(targetArg, this._floatingElement) !== this._currentTarget);
1754
+ const targetChanged = isInitialSync || this._prevSyncedTargetKey !== targetKey || this._prevSyncedTarget !== targetArg || relativeTargetStale;
1573
1755
  if (targetChanged) {
1574
1756
  this._prevSyncedTargetKey = targetKey;
1575
1757
  this._prevSyncedTarget = targetArg;
@@ -1584,8 +1766,15 @@ let AttacherCore = (_class = class AttacherCore {
1584
1766
  this._syncIsShown();
1585
1767
  }
1586
1768
  this._ensureArgumentsAreValid();
1587
- if (this._floatingElement && !this._isComponentHost) {
1588
- this._syncHeadlessAttachmentElement(this._floatingElement);
1769
+ if (this._floatingElement) {
1770
+ if (this.hasOffset) {
1771
+ this._floatingElement.setAttribute('data-offset', '');
1772
+ } else {
1773
+ this._floatingElement.removeAttribute('data-offset');
1774
+ }
1775
+ if (!this._isComponentHost) {
1776
+ this._syncHeadlessAttachmentElement(this._floatingElement);
1777
+ }
1589
1778
  }
1590
1779
  this._syncAria();
1591
1780
  if (!targetChanged) {
@@ -1716,6 +1905,11 @@ let AttacherCore = (_class = class AttacherCore {
1716
1905
  element.style.display = 'none';
1717
1906
  element.setAttribute('aria-hidden', 'true');
1718
1907
  }
1908
+ if (this.hasOffset) {
1909
+ element.setAttribute('data-offset', '');
1910
+ } else {
1911
+ element.removeAttribute('data-offset');
1912
+ }
1719
1913
  }
1720
1914
  _attachPopoverEvents(element) {
1721
1915
  if (!element || this._attachedPopoverEventsOn === element) {
@@ -1766,9 +1960,28 @@ let AttacherCore = (_class = class AttacherCore {
1766
1960
  }
1767
1961
  }
1768
1962
  }
1963
+ _isEventFromAttachment(event) {
1964
+ if (!(typeof Event !== 'undefined' && event instanceof Event) || !this._floatingElement) {
1965
+ return false;
1966
+ }
1967
+ if (descendantAttachmentContainsEvent(this, event)) {
1968
+ return true;
1969
+ }
1970
+ if (!elementContainsEvent(this._floatingElement, event)) {
1971
+ return false;
1972
+ }
1973
+
1974
+ // Allow Targets that intentionally live inside this Attachment's own content block,
1975
+ // while ignoring events bubbling out of the Attachment into an enclosing ancestor Target.
1976
+ const current = event.currentTarget;
1977
+ if (current instanceof Element && this._floatingElement.contains(current) && (current === this._listenerTarget || this._registeredEntries.has(current) || this._popoverTargetEntries.has(current))) {
1978
+ return false;
1979
+ }
1980
+ return true;
1981
+ }
1769
1982
  _onPopoverTargetClick(event) {
1770
1983
  const trigger = event.currentTarget;
1771
- if (!(trigger instanceof Element) || this._isDestroyed) {
1984
+ if (!(trigger instanceof Element) || this._isDestroyed || this._isEventFromAttachment(event)) {
1772
1985
  return;
1773
1986
  }
1774
1987
  const floatingEl = this._floatingElement;
@@ -1790,6 +2003,7 @@ let AttacherCore = (_class = class AttacherCore {
1790
2003
  if (this._currentTarget !== trigger) {
1791
2004
  this._switchTargetFromEvent(trigger, undefined, null);
1792
2005
  }
2006
+ this._markOpeningTriggerEvent(event);
1793
2007
  this._show();
1794
2008
  this._addListenersForHideEvents();
1795
2009
  } else {
@@ -1814,11 +2028,11 @@ let AttacherCore = (_class = class AttacherCore {
1814
2028
  entry.useCapture = useCapture;
1815
2029
  for (const eventName of showOn) {
1816
2030
  const listener = event => {
1817
- if (this._isDestroyed) {
2031
+ if (this._isDestroyed || this._isEventFromAttachment(event)) {
1818
2032
  return;
1819
2033
  }
1820
2034
  if (eventName === 'click' && this._currentTarget === entry.element && (!this._isHidden || this._isShown) && !this._isHiding && this._hideOn.includes('click')) {
1821
- this._hideAfterDelay();
2035
+ this._hideAfterDelay(event);
1822
2036
  return;
1823
2037
  }
1824
2038
  this._activateRegisteredEntry(entry);
@@ -1919,6 +2133,11 @@ let AttacherCore = (_class = class AttacherCore {
1919
2133
  el.setAttribute('x-placement', initialPlacement);
1920
2134
  }
1921
2135
  el.style.setProperty('--ember-attacher-transition-duration', `${showDuration}ms`);
2136
+ if (this.hasOffset) {
2137
+ el.setAttribute('data-offset', '');
2138
+ } else {
2139
+ el.removeAttribute('data-offset');
2140
+ }
1922
2141
  if (!el.classList.contains('ember-attacher')) {
1923
2142
  el.style.display = 'block';
1924
2143
  } else if (el.style.display === 'none') {
@@ -2151,7 +2370,15 @@ let AttacherCore = (_class = class AttacherCore {
2151
2370
  const target = resolveAttachmentTarget({
2152
2371
  target: this.targetArg,
2153
2372
  registeredTarget: this._registeredTarget,
2154
- triggerTargets: allTargets
2373
+ triggerTargets: allTargets,
2374
+ floatingElement: this._floatingElement
2375
+ });
2376
+ runInDebug(() => {
2377
+ if (!this._isTooltip && this._floatingElement && this._floatingElement.parentElement?.closest('button, a')) {
2378
+ warn('[ember-attacher] Interactive <AttachPopover> / <Attacher> is rendered inside a <button> or <a> element, which creates invalid nested-interactive HTML and bubbles clicks to the parent control. Render the attachment as a sibling with @target=":previous" instead.', false, {
2379
+ id: 'ember-attacher.nested-interactive-target'
2380
+ });
2381
+ }
2155
2382
  });
2156
2383
  this._listenerTarget = getListenerTarget(target);
2157
2384
  this._setTracked('_currentTarget', target);
@@ -2162,6 +2389,7 @@ let AttacherCore = (_class = class AttacherCore {
2162
2389
  }
2163
2390
  this._syncModalContainer();
2164
2391
  syncParentAttachment(this);
2392
+ this._syncRelativeTargetObserver();
2165
2393
  this._addShowListenersIfUnregistered();
2166
2394
  this._notifyRenderStateChange();
2167
2395
  const shouldBeOpen = !this._isHiding && (!this._isHidden || this._isShown) || Boolean(this._opt('isShown'));
@@ -2252,9 +2480,15 @@ let AttacherCore = (_class = class AttacherCore {
2252
2480
  }
2253
2481
  }
2254
2482
  _showAfterDelay(event) {
2483
+ if (this._isEventFromAttachment(event)) {
2484
+ return;
2485
+ }
2255
2486
  if (this._suppressFocusShow && (event?.type === 'focus' || event?.type === 'focusin')) {
2256
2487
  return;
2257
2488
  }
2489
+ if (this._isHidden || this._isHiding) {
2490
+ this._markOpeningTriggerEvent(event);
2491
+ }
2258
2492
  cancelScheduled(this._delayedVisibilityToggle);
2259
2493
  this._cancelCloseAnimation();
2260
2494
  this._isHiding = false;
@@ -2289,7 +2523,10 @@ let AttacherCore = (_class = class AttacherCore {
2289
2523
  this._syncAria();
2290
2524
  this._update();
2291
2525
  }
2292
- _hideAfterDelay() {
2526
+ _hideAfterDelay(event) {
2527
+ if (this._isEventFromAttachment(event)) {
2528
+ return;
2529
+ }
2293
2530
  cancelScheduled(this._delayedVisibilityToggle);
2294
2531
  this._isHiding = true;
2295
2532
  const hideDelay = parseInt(String(this._opt('hideDelay') ?? 0), 10) || 0;
@@ -2421,14 +2658,52 @@ let AttacherCore = (_class = class AttacherCore {
2421
2658
  this._hideAfterDelay();
2422
2659
  }
2423
2660
  }
2661
+ _markOpeningTriggerEvent(event) {
2662
+ cancelScheduled(this._openingTriggerHandle);
2663
+ this._openingTriggerEvent = event ?? null;
2664
+ if (event) {
2665
+ this._openingTriggerHandle = scheduleMicrotask(() => {
2666
+ this._openingTriggerHandle = null;
2667
+ if (this._openingTriggerEvent === event) {
2668
+ this._openingTriggerEvent = null;
2669
+ }
2670
+ });
2671
+ } else {
2672
+ this._openingTriggerHandle = null;
2673
+ }
2674
+ }
2675
+ _isTargetContainingFloating() {
2676
+ return Boolean(this._listenerTarget && this._floatingElement && this._listenerTarget.contains(this._floatingElement));
2677
+ }
2678
+ _isEventInDismissRetentionZone(event) {
2679
+ if (descendantAttachmentContainsEvent(this, event)) {
2680
+ return true;
2681
+ }
2682
+ if (Boolean(this._opt('interactive')) && elementContainsEvent(this._floatingElement, event)) {
2683
+ return true;
2684
+ }
2685
+ if (this._isTargetContainingFloating()) {
2686
+ return this._openingTriggerEvent === event;
2687
+ }
2688
+ return elementContainsEvent(this._listenerTarget, event);
2689
+ }
2690
+ _isNodeInDismissRetentionZone(node) {
2691
+ if (descendantAttachmentContainsNode(this, node)) {
2692
+ return true;
2693
+ }
2694
+ if (Boolean(this._opt('interactive')) && Boolean(this._floatingElement?.contains(node))) {
2695
+ return true;
2696
+ }
2697
+ if (this._isTargetContainingFloating()) {
2698
+ return false;
2699
+ }
2700
+ return Boolean(this._listenerTarget?.contains(node));
2701
+ }
2424
2702
  _hideOnClickOut(event) {
2425
- const target = this._listenerTarget;
2426
- if (elementContainsEvent(target, event) || descendantAttachmentContainsEvent(this, event)) {
2703
+ if (this._isEventInDismissRetentionZone(event)) {
2427
2704
  return;
2428
2705
  }
2429
- if (!this._opt('interactive') || !elementContainsEvent(this._floatingElement, event)) {
2430
- this._hideAfterDelay();
2431
- }
2706
+ this._hideAfterDelay();
2432
2707
  }
2433
2708
  _hideOnEscapeKey(rawEvent) {
2434
2709
  const event = rawEvent;
@@ -2443,17 +2718,14 @@ let AttacherCore = (_class = class AttacherCore {
2443
2718
  this._hideAfterDelay();
2444
2719
  return;
2445
2720
  }
2446
- const target = this._listenerTarget;
2447
- if (!target) {
2721
+ if (!this._listenerTarget) {
2448
2722
  return;
2449
2723
  }
2450
2724
  const relatedNode = event.relatedTarget instanceof Node ? event.relatedTarget : null;
2451
- if (target.contains(relatedNode) || descendantAttachmentContainsNode(this, relatedNode)) {
2725
+ if (this._isNodeInDismissRetentionZone(relatedNode)) {
2452
2726
  return;
2453
2727
  }
2454
- if (!this._opt('interactive') || !this._floatingElement?.contains(relatedNode)) {
2455
- this._hideAfterDelay();
2456
- }
2728
+ this._hideAfterDelay();
2457
2729
  }
2458
2730
  _update() {
2459
2731
  this._cleanup?.();
@@ -2478,11 +2750,18 @@ let AttacherCore = (_class = class AttacherCore {
2478
2750
  return;
2479
2751
  }
2480
2752
  const strategy = this._opt('strategy') || DEFAULTS.strategy;
2753
+ const middleware = this._middleware;
2754
+ if (hasOffsetMiddleware(middleware)) {
2755
+ this._floatingElement.setAttribute('data-offset', '');
2756
+ } else {
2757
+ this._floatingElement.removeAttribute('data-offset');
2758
+ }
2481
2759
  const computePositionToken = attacherWaiter.beginAsync();
2482
2760
  computePosition(this._currentTarget, this._floatingElement, {
2483
- middleware: this._middleware,
2761
+ middleware,
2484
2762
  placement: this._opt('placement'),
2485
- strategy
2763
+ strategy,
2764
+ platform: topLayerAwarePlatform
2486
2765
  }).then(({
2487
2766
  x,
2488
2767
  y,
@@ -2515,11 +2794,43 @@ let AttacherCore = (_class = class AttacherCore {
2515
2794
  }
2516
2795
  });
2517
2796
  }
2797
+ _disconnectRelativeTargetObserver() {
2798
+ this._relativeTargetObserver?.disconnect();
2799
+ this._relativeTargetObserver = null;
2800
+ this._observedRelativeParent = null;
2801
+ }
2802
+ _syncRelativeTargetObserver() {
2803
+ const targetArg = this.targetArg;
2804
+ const isPreviousToken = typeof targetArg === 'string' && (targetArg === ':previous' || targetArg.startsWith(':previous('));
2805
+ const parent = isPreviousToken ? this._floatingElement?.parentElement ?? null : null;
2806
+ if (!parent || this._isDestroyed || typeof MutationObserver !== 'function') {
2807
+ this._disconnectRelativeTargetObserver();
2808
+ return;
2809
+ }
2810
+ if (this._observedRelativeParent === parent && this._relativeTargetObserver) {
2811
+ return;
2812
+ }
2813
+ this._disconnectRelativeTargetObserver();
2814
+ this._observedRelativeParent = parent;
2815
+ this._relativeTargetObserver = new MutationObserver(() => {
2816
+ if (this._isDestroyed) {
2817
+ return;
2818
+ }
2819
+ const nextToken = this.targetArg;
2820
+ if (isRelativeTargetToken(nextToken) && (!isTargetConnected(this._currentTarget) || this._floatingElement != null && peekRelativeTarget(nextToken, this._floatingElement) !== this._currentTarget)) {
2821
+ this._initializeAttacher();
2822
+ }
2823
+ });
2824
+ this._relativeTargetObserver.observe(parent, {
2825
+ childList: true
2826
+ });
2827
+ }
2518
2828
  destroy() {
2519
2829
  if (this._isDestroyed) {
2520
2830
  return;
2521
2831
  }
2522
2832
  this._isDestroyed = true;
2833
+ this._disconnectRelativeTargetObserver();
2523
2834
  peekDelayGroup(this._delayGroupOwner)?.close(this, {
2524
2835
  markWarm: false
2525
2836
  });
@@ -2528,6 +2839,8 @@ let AttacherCore = (_class = class AttacherCore {
2528
2839
  this._cleanup = null;
2529
2840
  cancelScheduled(this._syncArgsHandle);
2530
2841
  cancelScheduled(this._setTargetHandle);
2842
+ cancelScheduled(this._openingTriggerHandle);
2843
+ this._openingTriggerEvent = null;
2531
2844
  this._cancelCloseAnimation();
2532
2845
  cancelScheduled(this._delayedVisibilityToggle);
2533
2846
  this._detachPopoverEvents(this._attachedPopoverEventsOn);
@@ -2606,5 +2919,5 @@ let AttacherCore = (_class = class AttacherCore {
2606
2919
  }
2607
2920
  }), _class);
2608
2921
 
2609
- export { AttacherCore as A, cancelScheduled as c, resolveTooltipClass as r, scheduleMicrotask as s };
2610
- //# sourceMappingURL=attacher-core-CtbFbuD_.js.map
2922
+ export { AttacherCore as A, resolveTooltipClass as a, cancelScheduled as c, resolvePopoverClass as r, scheduleMicrotask as s };
2923
+ //# sourceMappingURL=attacher-core-BuH7FXay.js.map