ember-attacher 4.1.0 → 4.2.1

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 +1 @@
1
- {"version":3,"file":"attach-popover.js","sources":["../../src/components/attach-popover.js"],"sourcesContent":["import Component from '@glimmer/component';\n\nexport default class AttachPopover extends Component {\n get ariaRole() {\n return this.args.ariaRole || 'dialog';\n }\n} "],"names":[],"mappings":";;;;;;AAEe,MAAM,aAAa,SAAS,SAAS,CAAC;AACnD,EAAA,IAAI,QAAQ,GAAG;AACb,IAAA,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,QAAQ;AACvC,EAAA;AACF;AAAC,oBAAA,CAAA,QAAA,EAJoB,aAAa,CAAA;;"}
1
+ {"version":3,"file":"attach-popover.js","sources":["../../src/components/attach-popover.js"],"sourcesContent":["import Component from '@glimmer/component';\n\nexport default class AttachPopover extends Component {\n get ariaRole() {\n return this.args.ariaRole || 'dialog';\n }\n} "],"names":["AttachPopover","Component","ariaRole","args","setComponentTemplate","TEMPLATE"],"mappings":";;;;;;AAEe,MAAMA,aAAa,SAASC,SAAS,CAAC;EACnD,IAAIC,QAAQA,GAAG;AACb,IAAA,OAAO,IAAI,CAACC,IAAI,CAACD,QAAQ,IAAI,QAAQ;AACvC,EAAA;AACF;AAACE,oBAAA,CAAAC,QAAA,EAJoBL,aAAa,CAAA;;"}
@@ -1,4 +1,4 @@
1
- import { _ as _applyDecoratedDescriptor } from '../_rollupPluginBabelHelpers-D7BmOdxG.js';
1
+ import { _ as _applyDecoratedDescriptor, g as getListenerTarget } from '../target-resolution-Bz738VeA.js';
2
2
  import Component from '@glimmer/component';
3
3
  import { action } from '@ember/object';
4
4
  import DEFAULTS from '../defaults.js';
@@ -21,16 +21,18 @@ let AttachTooltip = (_class = class AttachTooltip extends Component {
21
21
  return tooltip?.tooltipClass ?? tooltipClass ?? DEFAULTS.tooltipClass;
22
22
  }
23
23
  onInitializeAttacher(currentTarget, id) {
24
- if (currentTarget?.getAttribute('aria-describedby') != id) {
24
+ const elementTarget = getListenerTarget(currentTarget);
25
+ if (!elementTarget) {
26
+ return;
27
+ }
28
+ if (elementTarget.getAttribute('aria-describedby') != id) {
25
29
  const oldTarget = document.querySelector(`[aria-describedby="${id}"]`);
26
30
  oldTarget?.removeAttribute('aria-describedby');
27
- currentTarget?.setAttribute('aria-describedby', id);
31
+ elementTarget.setAttribute('aria-describedby', id);
28
32
  }
29
33
  }
30
34
  onWillDestroy(currentTarget) {
31
- if (currentTarget) {
32
- currentTarget.removeAttribute('aria-describedby');
33
- }
35
+ getListenerTarget(currentTarget)?.removeAttribute('aria-describedby');
34
36
  }
35
37
  }, _applyDecoratedDescriptor(_class.prototype, "onInitializeAttacher", [action], Object.getOwnPropertyDescriptor(_class.prototype, "onInitializeAttacher"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "onWillDestroy", [action], Object.getOwnPropertyDescriptor(_class.prototype, "onWillDestroy"), _class.prototype), _class);
36
38
  setComponentTemplate(TEMPLATE, AttachTooltip);
@@ -1 +1 @@
1
- {"version":3,"file":"attach-tooltip.js","sources":["../../src/components/attach-tooltip.js"],"sourcesContent":["import Component from '@glimmer/component';\nimport { action } from '@ember/object';\nimport DEFAULTS from '../defaults';\nimport { getOwner } from '@ember/application';\n\nexport default class AttachTooltip extends Component {\n get ariaRole() {\n return this.args.ariaRole || 'tooltip';\n }\n\n get additionalClass() {\n const { tooltip, tooltipClass } = getOwner(this).resolveRegistration('config:environment').emberAttacher || {}\n\n return tooltip?.tooltipClass ?? tooltipClass ?? DEFAULTS.tooltipClass;\n }\n\n @action\n onInitializeAttacher(currentTarget, id) {\n if (currentTarget?.getAttribute('aria-describedby') != id) {\n const oldTarget = document.querySelector(`[aria-describedby=\"${id}\"]`);\n\n oldTarget?.removeAttribute('aria-describedby')\n currentTarget?.setAttribute('aria-describedby', id);\n }\n }\n\n @action\n onWillDestroy(currentTarget) {\n if (currentTarget) {\n currentTarget.remov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AA,MAAA,CAAA,wBAAA,CAAA,MAAA,CAAA,SAAA,EAAA,eAAA,CAAA,EAAA,MAAA,CAAA,SAAA,CAAA,EAAA,MAAA;AArByB,oBAAA,CAAA,QAAA,EAAb,aAAa,CAAA;;"}
1
+ {"version":3,"file":"attach-tooltip.js","sources":["../../src/components/attach-tooltip.js"],"sourcesContent":["import Component from '@glimmer/component';\nimport { action } from '@ember/object';\nimport DEFAULTS from '../defaults';\nimport { getOwner } from '@ember/application';\nimport { getListenerTarget } from '../lib/target-resolution.js';\n\nexport default class AttachTooltip extends Component {\n get ariaRole() {\n return this.args.ariaRole || 'tooltip';\n }\n\n get additionalClass() {\n const { tooltip, tooltipClass } = getOwner(this).resolveRegistration('config:environment').emberAttacher || {}\n\n return tooltip?.tooltipClass ?? tooltipClass ?? DEFAULTS.tooltipClass;\n }\n\n @action\n onInitializeAttacher(currentTarget, id) {\n const elementTarget = getListenerTarget(currentTarget);\n\n if (!elementTarget) {\n return;\n }\n\n if (elementTarget.getAttribute('aria-describedby') != id) {\n const oldTarget = document.querySelector(`[aria-describedby=\"${id}\"]`);\n\n oldTarget?.removeAttribute('aria-describedby');\n elementTarget.setAttribute('aria-describedby', id);\n }\n }\n\n @action\n onWillDestroy(currentTarget) {\n getListenerTarget(currentTarget)?.removeAttribute('aria-describedby');\n }\n}\n"],"names":["AttachTooltip","_class","Component","ariaRole","args","additionalClass","tooltip","tooltipClass","getOwner","resolveRegistration","emberAttacher","DEFAULTS","onInitializeAttacher","currentTarget","id","elementTarget","getListenerTarget","getAttribute","oldTarget","document","querySelector","removeAttribute","setAttribute","onWillDestroy","_applyDecoratedDescriptor","prototype","action","Object","getOwnPropertyDescriptor","setComponentTemplate","TEMPLATE"],"mappings":";;;;;;;;;;;AAIgE,IAE3CA,aAAa,IAAAC,MAAA,GAAnB,MAAMD,aAAa,SAASE,SAAS,CAAC;EACnD,IAAIC,QAAQA,GAAG;AACb,IAAA,OAAO,IAAI,CAACC,IAAI,CAACD,QAAQ,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,MAAA,CAAAwB,SAAA,GAAAxB,MAAA;AA3ByB4B,oBAAA,CAAAC,QAAA,EAAb9B,aAAa,CAAA;;"}
@@ -1,7 +1,7 @@
1
- import { _ as _applyDecoratedDescriptor, a as _defineProperty, b as _initializerDefineProperty } from '../_rollupPluginBabelHelpers-D7BmOdxG.js';
1
+ import { _ as _applyDecoratedDescriptor, a as _defineProperty, b as _initializerDefineProperty, r as resolveAttachmentTarget, g as getListenerTarget, i as isElementTarget } from '../target-resolution-Bz738VeA.js';
2
2
  import { action } from '@ember/object';
3
3
  import Component from '@glimmer/component';
4
- import { later, schedule, cancel, next, debounce, run } from '@ember/runloop';
4
+ import { schedule, cancel, later, next, debounce, run } from '@ember/runloop';
5
5
  import { getOwner } from '@ember/application';
6
6
  import { guidFor } from '@ember/object/internals';
7
7
  import { htmlSafe, isHTMLSafe } from '@ember/template';
@@ -16,21 +16,90 @@ import { precompileTemplate } from '@ember/template-compilation';
16
16
  import { setComponentTemplate } from '@ember/component';
17
17
  import templateOnly from '@ember/component/template-only';
18
18
 
19
- var MaybeInElement = setComponentTemplate(precompileTemplate("{{~#if @renderInPlace~}}{{yield}}{{~else~}}{{#in-element @destinationElement insertBefore=null}}{{yield}}{{/in-element}}{{~/if~}}", {
20
- strictMode: true
21
- }), templateOnly());
19
+ /**
20
+ * DOM and event helpers for attachment boundary and cursor detection.
21
+ */
22
+
23
+ /**
24
+ * Determine whether an event originated from or traversed through a given DOM element.
25
+ *
26
+ * Uses `event.composedPath()` to safely detect clicks on elements that were subsequently
27
+ * removed from the DOM during event handling (e.g. self-disappearing buttons).
28
+ * Falls back to `element.contains(event.target)` when `composedPath` is unavailable.
29
+ *
30
+ * @param {Element | null | undefined} element
31
+ * @param {Event | null | undefined} event
32
+ * @returns {boolean}
33
+ */
34
+ function elementContainsEvent(element, event) {
35
+ if (!element) {
36
+ return false;
37
+ }
38
+ const path = typeof event?.composedPath === 'function' ? event.composedPath() : null;
39
+ if (path && path.length > 0) {
40
+ return path.includes(element);
41
+ }
42
+ return Boolean(event?.target && element.contains(event.target));
43
+ }
22
44
 
23
- var TEMPLATE = precompileTemplate("{{~#unless this.renderFloatingElement~}}<meta hidden {{this.parentFinder}} {{this.isShownDidUpdate this.isShown}}/>{{~/unless~}}{{~#if this.renderFloatingElement~}}<this.MaybeInElement @destinationElement={{this._floatingElementContainer}} @renderInPlace={{this._renderInPlace}}><div\n class=\"ember-attacher\"\n id={{this.id}}\n role={{@ariaRole}}\n {{this.setupFloatingElement}}\n {{this.isShownDidUpdate this.isShown}}\n {{this.targetDidUpdate this.hideOn this.showOn @explicitTarget}}\n {{this.optionsDidUpdate this.autoUpdate this.animation this.arrow this.useCapture this.placement this._renderInPlace this._middleware}}\n ...attributes\n >\n <div class={{this._class}} style={{this._style}}>\n {{yield (hash hide=this.hide)}}\n {{#if this.arrow}}\n <div class=\"ember-attacher-arrow\" x-arrow {{this.insertArrow}}></div>\n {{/if}}\n {{#if this.isFillAnimation}}\n <div x-circle style=\"{{this._circleTransitionDuration}}\"></div>\n {{/if}}\n </div>\n </div></this.MaybeInElement>{{~/if~}}\n");
45
+ /**
46
+ * Check if cursor coordinates lie in the geometric gap between the target and floating element.
47
+ *
48
+ * Used for interactive attachments with `isOffset=true` to prevent premature hide
49
+ * while the cursor transitions across the gap between target and attachment.
50
+ *
51
+ * @param {MouseEvent} event
52
+ * @param {Element | { getBoundingClientRect: Function } | null | undefined} target
53
+ * @param {Element | null | undefined} floatingElement
54
+ * @returns {boolean}
55
+ */
56
+ function isCursorBetween(event, target, floatingElement) {
57
+ if (!target || !floatingElement) {
58
+ return false;
59
+ }
60
+ const {
61
+ clientX,
62
+ clientY
63
+ } = event;
64
+ const attachmentPosition = floatingElement.getBoundingClientRect();
65
+ const targetPosition = target.getBoundingClientRect();
66
+ const isBetweenLeftAndRight = clientX > Math.min(attachmentPosition.left, targetPosition.left) && clientX < Math.max(attachmentPosition.right, targetPosition.right);
67
+ const isBetweenTopAndBottom = clientY > Math.min(attachmentPosition.top, targetPosition.top) && clientY < Math.max(attachmentPosition.bottom, targetPosition.bottom);
68
+
69
+ // Check if cursor is between a left-flipped attachment
70
+ if (attachmentPosition.right < targetPosition.left && clientX >= attachmentPosition.right && clientX <= targetPosition.left && isBetweenTopAndBottom) {
71
+ return true;
72
+ }
73
+
74
+ // Check if cursor is between a right-flipped attachment
75
+ if (attachmentPosition.left > targetPosition.right && clientX <= attachmentPosition.left && clientX >= targetPosition.right && isBetweenTopAndBottom) {
76
+ return true;
77
+ }
78
+
79
+ // Check if cursor is between a bottom-flipped attachment
80
+ if (attachmentPosition.top > targetPosition.bottom && clientY <= attachmentPosition.top && clientY >= targetPosition.bottom && isBetweenLeftAndRight) {
81
+ return true;
82
+ }
83
+
84
+ // Check if cursor is between a top-flipped attachment
85
+ if (attachmentPosition.bottom < targetPosition.top && clientY >= attachmentPosition.bottom && clientY <= targetPosition.top && isBetweenLeftAndRight) {
86
+ return true;
87
+ }
88
+ return false;
89
+ }
24
90
 
25
- var _class, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7;
26
- const animationTestWaiter = buildWaiter('basic-attacher');
27
91
  function consume(positional) {
28
92
  for (let i = 0; i < positional.length; i++) {
29
93
  void positional[i];
30
94
  }
31
95
  }
32
96
 
33
- // Run once per element, after render, so tracked writes do not hit the modifier's tracking frame.
97
+ /**
98
+ * Run once per element, after render, so tracked writes do not hit the modifier's tracking frame.
99
+ *
100
+ * @param {Function} fn
101
+ * @returns {import('ember-modifier').ModifierFunction}
102
+ */
34
103
  function onInsert(fn) {
35
104
  const seen = new WeakSet();
36
105
  return modifier(element => {
@@ -43,8 +112,13 @@ function onInsert(fn) {
43
112
  });
44
113
  }
45
114
 
46
- // Skip install ({{did-update}} semantics). Each factory has its own WeakSet so two
47
- // onUpdate modifiers on the same node do not steal each other's first run.
115
+ /**
116
+ * Skip install ({{did-update}} semantics). Each factory has its own WeakSet so two
117
+ * onUpdate modifiers on the same node do not steal each other's first run.
118
+ *
119
+ * @param {Function} fn
120
+ * @returns {import('ember-modifier').ModifierFunction}
121
+ */
48
122
  function onUpdate(fn) {
49
123
  const seen = new WeakSet();
50
124
  return modifier((element, positional) => {
@@ -56,6 +130,15 @@ function onUpdate(fn) {
56
130
  fn();
57
131
  });
58
132
  }
133
+
134
+ var MaybeInElement = setComponentTemplate(precompileTemplate("{{~#if @renderInPlace~}}{{yield}}{{~else~}}{{#in-element @destinationElement insertBefore=null}}{{yield}}{{/in-element}}{{~/if~}}", {
135
+ strictMode: true
136
+ }), templateOnly());
137
+
138
+ var TEMPLATE = precompileTemplate("{{~#unless this.renderFloatingElement~}}<meta hidden {{this.parentFinder}} {{this.isShownDidUpdate this.isShown}}/>{{~/unless~}}{{~#if this.renderFloatingElement~}}<this.MaybeInElement @destinationElement={{this._floatingElementContainer}} @renderInPlace={{this._renderInPlace}}><div\n class=\"ember-attacher\"\n id={{this.id}}\n role={{@ariaRole}}\n {{this.setupFloatingElement}}\n {{this.isShownDidUpdate this.isShown}}\n {{this.targetDidUpdate this.hideOn this.showOn @explicitTarget}}\n {{this.optionsDidUpdate this.autoUpdate this.animation this.arrow this.useCapture this.placement this._renderInPlace this._middleware}}\n ...attributes\n >\n <div class={{this._class}} style={{this._style}}>\n {{yield (hash hide=this.hide setReference=this.setReference reference=this.reference)}}\n {{#if this.arrow}}\n <div class=\"ember-attacher-arrow\" x-arrow {{this.insertArrow}}></div>\n {{/if}}\n {{#if this.isFillAnimation}}\n <div x-circle style=\"{{this._circleTransitionDuration}}\"></div>\n {{/if}}\n </div>\n </div></this.MaybeInElement>{{~/if~}}\n");
139
+
140
+ var _class, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8;
141
+ const animationTestWaiter = buildWaiter('basic-attacher');
59
142
  let BasicAttacher = (_class = class BasicAttacher extends Component {
60
143
  /**
61
144
  * ================== PUBLIC CONFIG OPTIONS ==================
@@ -251,6 +334,10 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
251
334
  this._animationTimeout = requestAnimationFrame(() => {
252
335
  animationTestWaiter.endAsync(this._animationTimeout);
253
336
  if (!this.isDestroyed && !this.isDestroying) {
337
+ if (!isVisible) {
338
+ this._cleanup?.();
339
+ this._cleanup = null;
340
+ }
254
341
  this._floatingElement.style.display = isVisible ? 'block' : 'none';
255
342
 
256
343
  // Prevent jank by making the attachment invisible until positioned.
@@ -264,6 +351,10 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
264
351
  animationTestWaiter.beginAsync(this._animationTimeout);
265
352
  }, delay);
266
353
  } else {
354
+ if (!isVisible) {
355
+ this._cleanup?.();
356
+ this._cleanup = null;
357
+ }
267
358
  this._floatingElement.style.display = isVisible ? 'block' : 'none';
268
359
  // Prevent jank by making the attachment invisible until positioned.
269
360
  // The visibility style will be toggled by this._startShowAnimation()
@@ -285,6 +376,39 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
285
376
  hide() {
286
377
  this._hide();
287
378
  }
379
+
380
+ /**
381
+ * Register an explicit attachment target (Element or Floating UI virtual ref).
382
+ * Yielded for composition into other modifiers.
383
+ * Pass `null` to clear and fall back to `@explicitTarget` / parent.
384
+ *
385
+ * Calls `_initializeAttacher` directly so registration that happens during the
386
+ * floating element's first render takes effect before the next user event.
387
+ *
388
+ * @param {Element | { getBoundingClientRect: Function } | null | undefined} target
389
+ */
390
+ setReference(target) {
391
+ cancel(this._setReferenceTimer);
392
+
393
+ // Defer: callers often invoke this from another modifier's
394
+ // `modify()` (composition). Tracked writes + re-init must not run in
395
+ // that tracking frame.
396
+ this._setReferenceTimer = schedule('actions', () => {
397
+ this._setReferenceTimer = null;
398
+ if (this.isDestroyed || this.isDestroying) {
399
+ return;
400
+ }
401
+ const next = target ?? null;
402
+ if (this._registeredTarget === next) {
403
+ return;
404
+ }
405
+ this._registeredTarget = next;
406
+ this._initializeAttacher();
407
+ });
408
+ }
409
+
410
+ // Always defined on first render so the modifier binding is present immediately.
411
+
288
412
  _ensureArgumentsAreValid() {
289
413
  runInDebug(() => {
290
414
  if (this.arrow && this.isFillAnimation) {
@@ -309,13 +433,17 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
309
433
  _initializerDefineProperty(this, "_isStartingAnimation", _descriptor3, this);
310
434
  _initializerDefineProperty(this, "_arrowElement", _descriptor4, this);
311
435
  _initializerDefineProperty(this, "_currentTarget", _descriptor5, this);
436
+ // Yielded `setReference` / `reference` registration. Prefer
437
+ // `@explicitTarget` when that arg is set; otherwise this beats parent.
438
+ _initializerDefineProperty(this, "_registeredTarget", _descriptor6, this);
439
+ _defineProperty(this, "_setReferenceTimer", null);
312
440
  // Untracked copy of the node listeners are on. `_removeEventListeners` must
313
441
  // not read `_currentTarget` in the same computation that writes it
314
442
  // (`targetDidUpdate` → `_initializeAttacher` when `@explicitTarget` changes).
315
443
  _defineProperty(this, "_listenerTarget", null);
316
444
  // This is set to true when the popover is shown in order to override lazyRender=false
317
- _initializerDefineProperty(this, "_mustRender", _descriptor6, this);
318
- _initializerDefineProperty(this, "_transitionDuration", _descriptor7, this);
445
+ _initializerDefineProperty(this, "_mustRender", _descriptor7, this);
446
+ _initializerDefineProperty(this, "_transitionDuration", _descriptor8, this);
319
447
  _defineProperty(this, "_floatingElement", null);
320
448
  _defineProperty(this, "parentFinder", onInsert(element => {
321
449
  if (this.isDestroyed || this.isDestroying) {
@@ -355,11 +483,25 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
355
483
  this._ensureArgumentsAreValid();
356
484
  this._update();
357
485
  }));
486
+ _defineProperty(this, "reference", modifier(element => {
487
+ this.setReference(element);
488
+ return () => {
489
+ if (this.isDestroyed || this.isDestroying) {
490
+ return;
491
+ }
492
+ if (this._registeredTarget === element) {
493
+ this.setReference(null);
494
+ }
495
+ };
496
+ }));
358
497
  this._delayedVisibilityToggle = null;
359
498
 
360
499
  // The final source of truth on whether or not all _hide() or _show() actions have completed
361
500
  this._isHidden = true;
362
501
 
502
+ // Blocks _update from (re)starting autoUpdate after hide until the next show.
503
+ this._positioningSuspended = false;
504
+
363
505
  // Holds a delayed function to toggle the visibility of the attachment.
364
506
  // Used to make sure animations can complete before the attachment is hidden.
365
507
  this._animationTimeout = null;
@@ -384,8 +526,12 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
384
526
  }
385
527
  _initializeAttacher() {
386
528
  this._removeEventListeners();
387
- const target = this.args.explicitTarget || this.parentElement;
388
- this._listenerTarget = target;
529
+ const target = resolveAttachmentTarget({
530
+ explicitTarget: this.args.explicitTarget,
531
+ registeredTarget: this._registeredTarget,
532
+ parentElement: this.parentElement
533
+ });
534
+ this._listenerTarget = getListenerTarget(target);
389
535
  this._currentTarget = target;
390
536
  this._addListenersForShowEvents();
391
537
  if (!this._isHidden || this.isShown) {
@@ -400,16 +546,20 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
400
546
  this.args.onInitializeAttacher?.(this._currentTarget, this.id);
401
547
  }
402
548
  _addListenersForShowEvents() {
403
- if (!this._currentTarget) {
549
+ const target = this._listenerTarget;
550
+ if (!target) {
404
551
  return;
405
552
  }
406
553
  this._showOn.forEach(event => {
407
554
  this._showListenersOnTargetByEvent[event] = this._showAfterDelay;
408
- this._currentTarget.addEventListener(event, this._showAfterDelay, this.useCapture);
555
+ target.addEventListener(event, this._showAfterDelay, this.useCapture);
409
556
  });
410
557
  }
411
558
  willDestroy() {
412
559
  super.willDestroy(...arguments);
560
+ this._cleanup?.();
561
+ this._cleanup = null;
562
+ cancel(this._setReferenceTimer);
413
563
  this._cancelAnimation();
414
564
  cancel(this._delayedVisibilityToggle);
415
565
  this._removeEventListeners();
@@ -461,6 +611,7 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
461
611
  if (!this._currentTarget) {
462
612
  return;
463
613
  }
614
+ this._positioningSuspended = false;
464
615
  this._mustRender = true;
465
616
 
466
617
  // Make the attachment visible immediately so transition animations can take place
@@ -521,6 +672,9 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
521
672
  this._delayedVisibilityToggle = debounce(this, this._hide, hideDelay, !hideDelay);
522
673
  }
523
674
  _hide() {
675
+ this._positioningSuspended = true;
676
+ this._cleanup?.();
677
+ this._cleanup = null;
524
678
  if (!this._floatingElement) {
525
679
  this._animationTimeout = requestAnimationFrame(() => {
526
680
  animationTestWaiter.endAsync(this._animationTimeout);
@@ -559,9 +713,9 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
559
713
 
560
714
  _addListenersForHideEvents() {
561
715
  const hideOn = this._hideOn;
562
- const target = this._currentTarget;
716
+ const target = this._listenerTarget;
563
717
 
564
- // Target or component was destroyed
718
+ // Target or component was destroyed (virtual refs without contextElement skip listeners)
565
719
  if (!target || this.isDestroyed || this.isDestroying) {
566
720
  return;
567
721
  }
@@ -618,57 +772,24 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
618
772
  debounce(this, this._hideIfMouseOutsideTargetOrAttachment, event, 10);
619
773
  }
620
774
  _hideIfMouseOutsideTargetOrAttachment(event) {
621
- const target = this._currentTarget;
775
+ const target = this._listenerTarget;
622
776
  if (!target) {
623
777
  return;
624
778
  }
625
779
 
626
780
  // If cursor is not on the attachment or target, hide the floating element
627
- if (!target.contains(event.target) && !(this.isOffset && this._isCursorBetweenTargetAndAttachment(event)) && this._floatingElement && !this._floatingElement.contains(event.target)) {
781
+ if (!target.contains(event.target) && !(this.isOffset && isCursorBetween(event, this._currentTarget, this._floatingElement)) && this._floatingElement && !this._floatingElement.contains(event.target)) {
628
782
  // Remove this listener before hiding the attachment
629
783
  delete this._hideListenersOnDocumentByEvent.mousemove;
630
784
  document.removeEventListener('mousemove', this._hideIfMouseOutsideTargetOrAttachment, this.useCapture);
631
785
  this._hideAfterDelay();
632
786
  }
633
787
  }
634
- _isCursorBetweenTargetAndAttachment(event) {
635
- if (!this._currentTarget) {
636
- return;
637
- }
638
- const {
639
- clientX,
640
- clientY
641
- } = event;
642
- const attachmentPosition = this._floatingElement.getBoundingClientRect();
643
- const targetPosition = this._currentTarget.getBoundingClientRect();
644
- const isBetweenLeftAndRight = clientX > Math.min(attachmentPosition.left, targetPosition.left) && clientX < Math.max(attachmentPosition.right, targetPosition.right);
645
- const isBetweenTopAndBottom = clientY > Math.min(attachmentPosition.top, targetPosition.top) && clientY < Math.max(attachmentPosition.bottom, targetPosition.bottom);
646
-
647
- // Check if cursor is between a left-flipped attachment
648
- if (attachmentPosition.right < targetPosition.left && clientX >= attachmentPosition.right && clientX <= targetPosition.left && isBetweenTopAndBottom) {
649
- return true;
650
- }
651
-
652
- // Check if cursor is between a right-flipped attachment
653
- if (attachmentPosition.left > targetPosition.right && clientX <= attachmentPosition.left && clientX >= targetPosition.right && isBetweenTopAndBottom) {
654
- return true;
655
- }
656
-
657
- // Check if cursor is between a bottom-flipped attachment
658
- if (attachmentPosition.top > targetPosition.bottom && clientY <= attachmentPosition.top && clientY >= targetPosition.bottom && isBetweenLeftAndRight) {
659
- return true;
660
- }
661
-
662
- // Check if cursor is between a top-flipped attachment
663
- if (attachmentPosition.bottom < targetPosition.top && clientY >= attachmentPosition.bottom && clientY <= targetPosition.top && isBetweenLeftAndRight) {
664
- return true;
665
- }
666
- return false;
667
- }
668
788
  _hideOnClickOut(event) {
669
- const targetReceivedClick = this._currentTarget.contains(event.target);
789
+ const target = this._listenerTarget;
790
+ const targetReceivedClick = elementContainsEvent(target, event);
670
791
  if (this.interactive) {
671
- if (!targetReceivedClick && !this._floatingElement.contains(event.target)) {
792
+ if (!targetReceivedClick && !elementContainsEvent(this._floatingElement, event)) {
672
793
  this._hideAfterDelay();
673
794
  }
674
795
  } else if (!targetReceivedClick) {
@@ -684,10 +805,11 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
684
805
  if (event.relatedTarget === null) {
685
806
  this._hideAfterDelay();
686
807
  }
687
- if (!this._currentTarget) {
808
+ const target = this._listenerTarget;
809
+ if (!target) {
688
810
  return;
689
811
  }
690
- const targetContainsFocus = this._currentTarget.contains(event.relatedTarget);
812
+ const targetContainsFocus = target.contains(event.relatedTarget);
691
813
  if (this.interactive) {
692
814
  if (!targetContainsFocus && !this._floatingElement.contains(event.relatedTarget)) {
693
815
  this._hideAfterDelay();
@@ -702,7 +824,7 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
702
824
  delete this._hideListenersOnDocumentByEvent[eventType];
703
825
  });
704
826
  const showOn = this._showOn;
705
- const target = this._currentTarget;
827
+ const target = this._listenerTarget;
706
828
 
707
829
  // The target was destroyed, nothing to remove listeners from
708
830
  if (!target) {
@@ -729,6 +851,20 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
729
851
  }
730
852
  _update() {
731
853
  this._cleanup?.();
854
+ this._cleanup = null;
855
+
856
+ // Suspended after _hide until the next _show. Hide writes tracked state that
857
+ // re-renders and can re-fire optionsDidUpdate → _update; without this flag
858
+ // that path restarts autoUpdate (especially with hideDuration: 0). Do not
859
+ // use _isHidden here — it stays true until late in _startShowAnimation,
860
+ // after _update must already run.
861
+ if (this.isDestroyed || this.isDestroying || this._positioningSuspended || !this._currentTarget || !this._floatingElement) {
862
+ return;
863
+ }
864
+ const isTargetConnected = isElementTarget(this._currentTarget) ? this._currentTarget.isConnected : this._currentTarget?.contextElement instanceof Element ? this._currentTarget.contextElement.isConnected : true;
865
+ if (!isTargetConnected || !this._floatingElement.isConnected) {
866
+ return;
867
+ }
732
868
  if (this.autoUpdate) {
733
869
  this._cleanup = autoUpdate(this._currentTarget, this._floatingElement, this._updatePosition, typeOf(this.autoUpdate) === 'object' ? this.autoUpdate : undefined);
734
870
  } else {
@@ -736,6 +872,16 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
736
872
  }
737
873
  }
738
874
  _updatePosition() {
875
+ if (this.isDestroyed || this.isDestroying || !this._currentTarget || !this._floatingElement) {
876
+ return;
877
+ }
878
+ const isTargetConnected = isElementTarget(this._currentTarget) ? this._currentTarget.isConnected : this._currentTarget?.contextElement instanceof Element ? this._currentTarget.contextElement.isConnected : true;
879
+ if (!isTargetConnected || !this._floatingElement.isConnected) {
880
+ // Stop lingering observers if a node detached mid-update.
881
+ this._cleanup?.();
882
+ this._cleanup = null;
883
+ return;
884
+ }
739
885
  const computePositionToken = animationTestWaiter.beginAsync();
740
886
  computePosition(this._currentTarget, this._floatingElement, {
741
887
  ...this.floatingUiOptions,
@@ -748,21 +894,31 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
748
894
  middlewareData
749
895
  }) => {
750
896
  animationTestWaiter.endAsync(computePositionToken);
897
+ if (this.isDestroyed || this.isDestroying || !this._floatingElement || !this._floatingElement.isConnected) {
898
+ return;
899
+ }
751
900
  Object.assign(this._floatingElement.style, {
752
901
  left: `${x}px`,
753
902
  top: `${y}px`
754
903
  });
755
- if (middlewareData.arrow) {
904
+ if (middlewareData.arrow && this._arrowElement) {
756
905
  const {
757
- x,
758
- y
906
+ x: arrowX,
907
+ y: arrowY
759
908
  } = middlewareData.arrow;
760
909
  Object.assign(this._arrowElement.style, {
761
- left: x != null ? `${x}px` : '',
762
- top: y != null ? `${y}px` : ''
910
+ left: arrowX != null ? `${arrowX}px` : '',
911
+ top: arrowY != null ? `${arrowY}px` : ''
763
912
  });
764
913
  }
765
914
  this._floatingElement.setAttribute('x-placement', placement);
915
+ }).catch(error => {
916
+ animationTestWaiter.endAsync(computePositionToken);
917
+ if (!this.isDestroyed && !this.isDestroying) {
918
+ warn(`[ember-attacher] Positioning error: ${error?.message ?? error}`, {
919
+ id: 'ember-attacher.positioning-error'
920
+ });
921
+ }
766
922
  });
767
923
  }
768
924
  _cancelAnimation() {
@@ -811,21 +967,28 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
811
967
  initializer: function () {
812
968
  return null;
813
969
  }
814
- }), _descriptor6 = _applyDecoratedDescriptor(_class.prototype, "_mustRender", [tracked], {
970
+ }), _descriptor6 = _applyDecoratedDescriptor(_class.prototype, "_registeredTarget", [tracked], {
971
+ configurable: true,
972
+ enumerable: true,
973
+ writable: true,
974
+ initializer: function () {
975
+ return null;
976
+ }
977
+ }), _descriptor7 = _applyDecoratedDescriptor(_class.prototype, "_mustRender", [tracked], {
815
978
  configurable: true,
816
979
  enumerable: true,
817
980
  writable: true,
818
981
  initializer: function () {
819
982
  return false;
820
983
  }
821
- }), _descriptor7 = _applyDecoratedDescriptor(_class.prototype, "_transitionDuration", [tracked], {
984
+ }), _descriptor8 = _applyDecoratedDescriptor(_class.prototype, "_transitionDuration", [tracked], {
822
985
  configurable: true,
823
986
  enumerable: true,
824
987
  writable: true,
825
988
  initializer: function () {
826
989
  return 0;
827
990
  }
828
- }), _applyDecoratedDescriptor(_class.prototype, "hide", [action], Object.getOwnPropertyDescriptor(_class.prototype, "hide"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "_updatePosition", [action], Object.getOwnPropertyDescriptor(_class.prototype, "_updatePosition"), _class.prototype), _class);
991
+ }), _applyDecoratedDescriptor(_class.prototype, "hide", [action], Object.getOwnPropertyDescriptor(_class.prototype, "hide"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "setReference", [action], Object.getOwnPropertyDescriptor(_class.prototype, "setReference"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "_updatePosition", [action], Object.getOwnPropertyDescriptor(_class.prototype, "_updatePosition"), _class.prototype), _class);
829
992
  setComponentTemplate(TEMPLATE, BasicAttacher);
830
993
 
831
994
  export { BasicAttacher as default };