ember-attacher 4.0.0 → 4.2.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.
@@ -2,7 +2,7 @@ import Component from '@glimmer/component';
2
2
  import { precompileTemplate } from '@ember/template-compilation';
3
3
  import { setComponentTemplate } from '@ember/component';
4
4
 
5
- var TEMPLATE = precompileTemplate("<BasicAttacher\n @id={{@id}}\n @configKey=\"popover\"\n @ariaRole={{this.ariaRole}}\n @additionalClass={{@additionalClass}}\n @animation={{@animation}}\n @arrow={{@arrow}}\n @autoUpdate={{@autoUpdate}}\n @class={{@class}}\n @explicitTarget={{@explicitTarget}}\n @flip={{@flip}}\n @floatingElementContainer={{@floatingElementContainer}}\n @floatingUiOptions={{@floatingUiOptions}}\n @hideDelay={{@hideDelay}}\n @hideDuration={{@hideDuration}}\n @hideOn={{@hideOn}}\n @interactive={{@interactive}}\n @isOffset={{@isOffset}}\n @isShown={{@isShown}}\n @lazyRender={{@lazyRender}}\n @middleware={{@middleware}}\n @onChange={{@onChange}}\n @onInitializeAttacher={{@onInitializeAttacher}}\n @onWillDestroy={{@onWillDestroy}}\n @overflowPadding={{@overflowPadding}}\n @placement={{@placement}}\n @renderInPlace={{@renderInPlace}}\n @showDelay={{@showDelay}}\n @showDuration={{@showDuration}}\n @showOn={{@showOn}}\n @style={{@style}}\n @useCapture={{@useCapture}}\n ...attributes\n as |popover|\n>\n {{yield popover}}\n</BasicAttacher>\n");
5
+ var TEMPLATE = precompileTemplate("<BasicAttacher\n @id={{@id}}\n @configKey=\"popover\"\n @ariaRole={{this.ariaRole}}\n @additionalClass={{@additionalClass}}\n @animation={{@animation}}\n @arrow={{@arrow}}\n @autoUpdate={{@autoUpdate}}\n @class={{@class}}\n @explicitTarget={{@explicitTarget}}\n @flip={{@flip}}\n @floatingElementContainer={{@floatingElementContainer}}\n @floatingUiOptions={{@floatingUiOptions}}\n @hideDelay={{@hideDelay}}\n @hideDuration={{@hideDuration}}\n @hideOn={{@hideOn}}\n @interactive={{@interactive}}\n @isOffset={{@isOffset}}\n @isShown={{@isShown}}\n @lazyRender={{@lazyRender}}\n @middleware={{@middleware}}\n @onChange={{@onChange}}\n @onInitializeAttacher={{@onInitializeAttacher}}\n @onWillDestroy={{@onWillDestroy}}\n @overflowPadding={{@overflowPadding}}\n @placement={{@placement}}\n @renderInPlace={{@renderInPlace}}\n @showDelay={{@showDelay}}\n @showDuration={{@showDuration}}\n @showOn={{@showOn}}\n @style={{@style}}\n @useCapture={{@useCapture}}\n ...attributes\n as |popover|\n>{{yield popover}}</BasicAttacher>");
6
6
 
7
7
  class AttachPopover extends Component {
8
8
  get ariaRole() {
@@ -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":["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;AACF;AAACE,oBAAA,CAAAC,QAAA,EAJoBL,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-hULyhLkN.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';
@@ -6,7 +6,7 @@ import { getOwner } from '@ember/application';
6
6
  import { precompileTemplate } from '@ember/template-compilation';
7
7
  import { setComponentTemplate } from '@ember/component';
8
8
 
9
- var TEMPLATE = precompileTemplate("<BasicAttacher\n @id={{@id}}\n @configKey=\"tooltip\"\n @ariaRole={{this.ariaRole}}\n @additionalClass={{this.additionalClass}}\n @animation={{@animation}}\n @arrow={{@arrow}}\n @autoUpdate={{@autoUpdate}}\n @class={{@class}}\n @explicitTarget={{@explicitTarget}}\n @flip={{@flip}}\n @floatingElementContainer={{@floatingElementContainer}}\n @floatingUiOptions={{@floatingUiOptions}}\n @hideDelay={{@hideDelay}}\n @hideDuration={{@hideDuration}}\n @hideOn={{@hideOn}}\n @interactive={{@interactive}}\n @isOffset={{@isOffset}}\n @isShown={{@isShown}}\n @lazyRender={{@lazyRender}}\n @middleware={{@middleware}}\n @onChange={{@onChange}}\n @onInitializeAttacher={{this.onInitializeAttacher}}\n @onWillDestroy={{this.onWillDestroy}}\n @overflowPadding={{@overflowPadding}}\n @placement={{@placement}}\n @renderInPlace={{@renderInPlace}}\n @showDelay={{@showDelay}}\n @showDuration={{@showDuration}}\n @showOn={{@showOn}}\n @style={{@style}}\n @useCapture={{@useCapture}}\n ...attributes\n as |tooltip|\n>\n {{yield tooltip}}\n</BasicAttacher>");
9
+ var TEMPLATE = precompileTemplate("<BasicAttacher\n @id={{@id}}\n @configKey=\"tooltip\"\n @ariaRole={{this.ariaRole}}\n @additionalClass={{this.additionalClass}}\n @animation={{@animation}}\n @arrow={{@arrow}}\n @autoUpdate={{@autoUpdate}}\n @class={{@class}}\n @explicitTarget={{@explicitTarget}}\n @flip={{@flip}}\n @floatingElementContainer={{@floatingElementContainer}}\n @floatingUiOptions={{@floatingUiOptions}}\n @hideDelay={{@hideDelay}}\n @hideDuration={{@hideDuration}}\n @hideOn={{@hideOn}}\n @interactive={{@interactive}}\n @isOffset={{@isOffset}}\n @isShown={{@isShown}}\n @lazyRender={{@lazyRender}}\n @middleware={{@middleware}}\n @onChange={{@onChange}}\n @onInitializeAttacher={{this.onInitializeAttacher}}\n @onWillDestroy={{this.onWillDestroy}}\n @overflowPadding={{@overflowPadding}}\n @placement={{@placement}}\n @renderInPlace={{@renderInPlace}}\n @showDelay={{@showDelay}}\n @showDuration={{@showDuration}}\n @showOn={{@showOn}}\n @style={{@style}}\n @useCapture={{@useCapture}}\n ...attributes\n as |tooltip|\n>{{yield tooltip}}</BasicAttacher>");
10
10
 
11
11
  var _class;
12
12
  let AttachTooltip = (_class = class AttachTooltip extends Component {
@@ -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.removeAttribute('aria-describedby');\n }\n }\n}\n"],"names":["AttachTooltip","_class","Component","ariaRole","args","additionalClass","tooltip","tooltipClass","getOwner","resolveRegistration","emberAttacher","DEFAULTS","onInitializeAttacher","currentTarget","id","getAttribute","oldTarget","document","querySelector","removeAttribute","setAttribute","onWillDestroy","_applyDecoratedDescriptor","prototype","action","Object","getOwnPropertyDescriptor","setComponentTemplate","TEMPLATE"],"mappings":";;;;;;;;;;;AAG8C,IAEzBA,aAAa,IAAAC,MAAA,GAAnB,MAAMD,aAAa,SAASE,SAAS,CAAC;EACnD,IAAIC,QAAQA,GAAG;AACb,IAAA,OAAO,IAAI,CAACC,IAAI,CAACD,QAAQ,IAAI,SAAS;AACxC;EAEA,IAAIE,eAAeA,GAAG;IACpB,MAAM;MAAEC,OAAO;AAAEC,MAAAA;AAAa,KAAC,GAAGC,QAAQ,CAAC,IAAI,CAAC,CAACC,mBAAmB,CAAC,oBAAoB,CAAC,CAACC,aAAa,IAAI,EAAE;IAE9G,OAAOJ,OAAO,EAAEC,YAAY,IAAIA,YAAY,IAAII,QAAQ,CAACJ,YAAY;AACvE;AAGAK,EAAAA,oBAAoBA,CAACC,aAAa,EAAEC,EAAE,EAAE;IACtC,IAAID,aAAa,EAAEE,YAAY,CAAC,kBAAkB,CAAC,IAAID,EAAE,EAAE;MACzD,MAAME,SAAS,GAAGC,QAAQ,CAACC,aAAa,CAAC,CAAA,mBAAA,EAAsBJ,EAAE,CAAA,EAAA,CAAI,CAAC;AAEtEE,MAAAA,SAAS,EAAEG,eAAe,CAAC,kBAAkB,CAAC;AAC9CN,MAAAA,aAAa,EAAEO,YAAY,CAAC,kBAAkB,EAAEN,EAAE,CAAC;AACrD;AACF;EAGAO,aAAaA,CAACR,aAAa,EAAE;AAC3B,IAAA,IAAIA,aAAa,EAAE;AACjBA,MAAAA,aAAa,CAACM,eAAe,CAAC,kBAAkB,CAAC;AACnD;AACF;AACF,CAAC,EAAAG,yBAAA,CAAArB,MAAA,CAAAsB,SAAA,2BAhBEC,MAAM,CAAA,EAAAC,MAAA,CAAAC,wBAAA,CAAAzB,MAAA,CAAAsB,SAAA,EAAA,sBAAA,CAAA,EAAAtB,MAAA,CAAAsB,SAAA,CAAA,EAAAD,yBAAA,CAAArB,MAAA,CAAAsB,SAAA,EAAA,eAAA,EAAA,CAUNC,MAAM,GAAAC,MAAA,CAAAC,wBAAA,CAAAzB,MAAA,CAAAsB,SAAA,EAAA,eAAA,CAAA,EAAAtB,MAAA,CAAAsB,SAAA,GAAAtB,MAAA;AArByB0B,oBAAA,CAAAC,QAAA,EAAb5B,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,IAAI,SAAS;AACxC,EAAA;EAEA,IAAIE,eAAeA,GAAG;IACpB,MAAM;MAAEC,OAAO;AAAEC,MAAAA;AAAa,KAAC,GAAGC,QAAQ,CAAC,IAAI,CAAC,CAACC,mBAAmB,CAAC,oBAAoB,CAAC,CAACC,aAAa,IAAI,EAAE;IAE9G,OAAOJ,OAAO,EAAEC,YAAY,IAAIA,YAAY,IAAII,QAAQ,CAACJ,YAAY;AACvE,EAAA;AAGAK,EAAAA,oBAAoBA,CAACC,aAAa,EAAEC,EAAE,EAAE;AACtC,IAAA,MAAMC,aAAa,GAAGC,iBAAiB,CAACH,aAAa,CAAC;IAEtD,IAAI,CAACE,aAAa,EAAE;AAClB,MAAA;AACF,IAAA;IAEA,IAAIA,aAAa,CAACE,YAAY,CAAC,kBAAkB,CAAC,IAAIH,EAAE,EAAE;MACxD,MAAMI,SAAS,GAAGC,QAAQ,CAACC,aAAa,CAAC,CAAA,mBAAA,EAAsBN,EAAE,CAAA,EAAA,CAAI,CAAC;AAEtEI,MAAAA,SAAS,EAAEG,eAAe,CAAC,kBAAkB,CAAC;AAC9CN,MAAAA,aAAa,CAACO,YAAY,CAAC,kBAAkB,EAAER,EAAE,CAAC;AACpD,IAAA;AACF,EAAA;EAGAS,aAAaA,CAACV,aAAa,EAAE;AAC3BG,IAAAA,iBAAiB,CAACH,aAAa,CAAC,EAAEQ,eAAe,CAAC,kBAAkB,CAAC;AACvE,EAAA;AACF,CAAC,EAAAG,yBAAA,CAAAvB,MAAA,CAAAwB,SAAA,2BApBEC,MAAM,CAAA,EAAAC,MAAA,CAAAC,wBAAA,CAAA3B,MAAA,CAAAwB,SAAA,EAAA,sBAAA,CAAA,EAAAxB,MAAA,CAAAwB,SAAA,CAAA,EAAAD,yBAAA,CAAAvB,MAAA,CAAAwB,SAAA,EAAA,eAAA,EAAA,CAgBNC,MAAM,GAAAC,MAAA,CAAAC,wBAAA,CAAA3B,MAAA,CAAAwB,SAAA,EAAA,eAAA,CAAA,EAAAxB,MAAA,CAAAwB,SAAA,GAAAxB,MAAA;AA3ByB4B,oBAAA,CAAAC,QAAA,EAAb9B,aAAa,CAAA;;"}
@@ -1,7 +1,7 @@
1
- import { _ as _applyDecoratedDescriptor, a as _initializerDefineProperty, b as _defineProperty } from '../_rollupPluginBabelHelpers-hULyhLkN.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, cancel, next, debounce, run } from '@ember/runloop';
4
+ import { later, cancel, schedule, 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';
@@ -10,14 +10,52 @@ import { isEmpty, typeOf } from '@ember/utils';
10
10
  import { flip, shift, limitShift, arrow, autoUpdate, computePosition } from '@floating-ui/dom';
11
11
  import { buildWaiter } from '@ember/test-waiters';
12
12
  import { tracked } from '@glimmer/tracking';
13
+ import { modifier } from 'ember-modifier';
13
14
  import DEFAULTS from '../defaults.js';
14
15
  import { precompileTemplate } from '@ember/template-compilation';
15
16
  import { setComponentTemplate } from '@ember/component';
17
+ import templateOnly from '@ember/component/template-only';
16
18
 
17
- var TEMPLATE = precompileTemplate("{{~#unless this.renderFloatingElement}}\n <meta hidden {{did-insert this.onParentFinderInsert}} {{did-update this.onIsShownChange this.isShown}}/>\n{{~/unless~}}\n\n{{~#if this.renderFloatingElement~}}\n <MaybeInElement @destinationElement={{this._floatingElementContainer}} @renderInPlace={{@renderInPlace}}>\n <div\n class=\"ember-attacher\"\n id={{this.id}}\n role={{@ariaRole}}\n {{did-insert this.didInsertFloatingElement}}\n {{did-update this.onIsShownChange this.isShown}}\n {{did-update this.onTargetOrTriggerChange this.hideOn this.showOn @explicitTarget}}\n {{did-update this.onOptionsChange this.autoUpdate this.animation this.arrow this.useCapture this.placement this._renderInPlace this._currentTarget this._middleware}}\n {{will-destroy this.willDestroyFloatingElement}}\n ...attributes\n >\n <div class={{this._class}} style={{this._style}}>\n {{yield (hash hide=this.hide)}}\n {{#if this.arrow}}\n <div x-arrow {{did-insert this.didInsertArrow}}></div>\n {{/if}}\n {{#if this.isFillAnimation}}\n <div x-circle style=\"{{this._circleTransitionDuration}}\"></div>\n {{/if}}\n </div>\n </div>\n </MaybeInElement>\n{{~/if~}}\n");
19
+ var MaybeInElement = setComponentTemplate(precompileTemplate("{{~#if @renderInPlace~}}{{yield}}{{~else~}}{{#in-element @destinationElement insertBefore=null}}{{yield}}{{/in-element}}{{~/if~}}", {
20
+ strictMode: true
21
+ }), templateOnly());
18
22
 
19
- var _class, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7;
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 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");
24
+
25
+ var _class, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8;
20
26
  const animationTestWaiter = buildWaiter('basic-attacher');
27
+ function consume(positional) {
28
+ for (let i = 0; i < positional.length; i++) {
29
+ void positional[i];
30
+ }
31
+ }
32
+
33
+ // Run once per element, after render, so tracked writes do not hit the modifier's tracking frame.
34
+ function onInsert(fn) {
35
+ const seen = new WeakSet();
36
+ return modifier(element => {
37
+ if (seen.has(element)) {
38
+ return;
39
+ }
40
+ seen.add(element);
41
+ const timer = schedule('actions', fn, element);
42
+ return () => cancel(timer);
43
+ });
44
+ }
45
+
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.
48
+ function onUpdate(fn) {
49
+ const seen = new WeakSet();
50
+ return modifier((element, positional) => {
51
+ consume(positional);
52
+ if (!seen.has(element)) {
53
+ seen.add(element);
54
+ return;
55
+ }
56
+ fn();
57
+ });
58
+ }
21
59
  let BasicAttacher = (_class = class BasicAttacher extends Component {
22
60
  /**
23
61
  * ================== PUBLIC CONFIG OPTIONS ==================
@@ -41,7 +79,10 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
41
79
  return this.args.hideDuration ?? this._config.hideDuration ?? DEFAULTS.hideDuration;
42
80
  }
43
81
  get hideOn() {
44
- return this.args.hideOn || this._config.hideOn || DEFAULTS.hideOn;
82
+ if (this.args.hideOn === null) {
83
+ return null;
84
+ }
85
+ return this.args.hideOn ?? this._config.hideOn ?? DEFAULTS.hideOn;
45
86
  }
46
87
  get interactive() {
47
88
  return this.args.interactive ?? this._config.interactive ?? DEFAULTS.interactive;
@@ -210,6 +251,10 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
210
251
  this._animationTimeout = requestAnimationFrame(() => {
211
252
  animationTestWaiter.endAsync(this._animationTimeout);
212
253
  if (!this.isDestroyed && !this.isDestroying) {
254
+ if (!isVisible) {
255
+ this._cleanup?.();
256
+ this._cleanup = null;
257
+ }
213
258
  this._floatingElement.style.display = isVisible ? 'block' : 'none';
214
259
 
215
260
  // Prevent jank by making the attachment invisible until positioned.
@@ -223,6 +268,10 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
223
268
  animationTestWaiter.beginAsync(this._animationTimeout);
224
269
  }, delay);
225
270
  } else {
271
+ if (!isVisible) {
272
+ this._cleanup?.();
273
+ this._cleanup = null;
274
+ }
226
275
  this._floatingElement.style.display = isVisible ? 'block' : 'none';
227
276
  // Prevent jank by making the attachment invisible until positioned.
228
277
  // The visibility style will be toggled by this._startShowAnimation()
@@ -244,10 +293,39 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
244
293
  hide() {
245
294
  this._hide();
246
295
  }
247
- onParentFinderInsert(element) {
248
- this.parentElement = element.parentElement;
249
- this._initializeAttacher();
296
+
297
+ /**
298
+ * Register an explicit attachment target (Element or Floating UI virtual ref).
299
+ * Yielded for composition into other modifiers.
300
+ * Pass `null` to clear and fall back to `@explicitTarget` / parent.
301
+ *
302
+ * Calls `_initializeAttacher` directly so registration that happens during the
303
+ * floating element's first render takes effect before the next user event.
304
+ *
305
+ * @param {Element | { getBoundingClientRect: Function } | null | undefined} target
306
+ */
307
+ setReference(target) {
308
+ cancel(this._setReferenceTimer);
309
+
310
+ // Defer: callers often invoke this from another modifier's
311
+ // `modify()` (composition). Tracked writes + re-init must not run in
312
+ // that tracking frame.
313
+ this._setReferenceTimer = schedule('actions', () => {
314
+ this._setReferenceTimer = null;
315
+ if (this.isDestroyed || this.isDestroying) {
316
+ return;
317
+ }
318
+ const next = target ?? null;
319
+ if (this._registeredTarget === next) {
320
+ return;
321
+ }
322
+ this._registeredTarget = next;
323
+ this._initializeAttacher();
324
+ });
250
325
  }
326
+
327
+ // Always defined on first render so the modifier binding is present immediately.
328
+
251
329
  _ensureArgumentsAreValid() {
252
330
  runInDebug(() => {
253
331
  if (this.arrow && this.isFillAnimation) {
@@ -266,20 +344,81 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
266
344
  super(...arguments);
267
345
 
268
346
  // The debounced _hide() and _show() are stored here so they can be cancelled when necessary
347
+ _defineProperty(this, "MaybeInElement", MaybeInElement);
269
348
  _initializerDefineProperty(this, "parentNotFound", _descriptor, this);
270
349
  _initializerDefineProperty(this, "parentElement", _descriptor2, this);
271
350
  _initializerDefineProperty(this, "_isStartingAnimation", _descriptor3, this);
272
351
  _initializerDefineProperty(this, "_arrowElement", _descriptor4, this);
273
352
  _initializerDefineProperty(this, "_currentTarget", _descriptor5, this);
353
+ // Yielded `setReference` / `reference` registration. Prefer
354
+ // `@explicitTarget` when that arg is set; otherwise this beats parent.
355
+ _initializerDefineProperty(this, "_registeredTarget", _descriptor6, this);
356
+ _defineProperty(this, "_setReferenceTimer", null);
357
+ // Untracked copy of the node listeners are on. `_removeEventListeners` must
358
+ // not read `_currentTarget` in the same computation that writes it
359
+ // (`targetDidUpdate` → `_initializeAttacher` when `@explicitTarget` changes).
360
+ _defineProperty(this, "_listenerTarget", null);
274
361
  // This is set to true when the popover is shown in order to override lazyRender=false
275
- _initializerDefineProperty(this, "_mustRender", _descriptor6, this);
276
- _initializerDefineProperty(this, "_transitionDuration", _descriptor7, this);
362
+ _initializerDefineProperty(this, "_mustRender", _descriptor7, this);
363
+ _initializerDefineProperty(this, "_transitionDuration", _descriptor8, this);
277
364
  _defineProperty(this, "_floatingElement", null);
365
+ _defineProperty(this, "parentFinder", onInsert(element => {
366
+ if (this.isDestroyed || this.isDestroying) {
367
+ return;
368
+ }
369
+ this.parentElement = element.parentElement;
370
+ this._initializeAttacher();
371
+ }));
372
+ // Insert + autoUpdate teardown. Must not read tracked state in the modifier
373
+ // callback (the scheduled fn is fine); a tracked read would re-run this and
374
+ // fire the destructor before updates.
375
+ _defineProperty(this, "setupFloatingElement", modifier(element => {
376
+ const timer = schedule('actions', () => {
377
+ if (this.isDestroyed || this.isDestroying) {
378
+ return;
379
+ }
380
+ this._floatingElement = element;
381
+ if (this.renderInPlace) {
382
+ this.parentElement = element.parentElement;
383
+ this._initializeAttacher();
384
+ }
385
+ });
386
+ return () => {
387
+ cancel(timer);
388
+ this._cleanup?.();
389
+ };
390
+ }));
391
+ _defineProperty(this, "insertArrow", onInsert(element => {
392
+ if (this.isDestroyed || this.isDestroying) {
393
+ return;
394
+ }
395
+ this._arrowElement = element;
396
+ }));
397
+ _defineProperty(this, "isShownDidUpdate", onUpdate(() => this._syncIsShown()));
398
+ _defineProperty(this, "targetDidUpdate", onUpdate(() => this._initializeAttacher()));
399
+ _defineProperty(this, "optionsDidUpdate", onUpdate(() => {
400
+ this._ensureArgumentsAreValid();
401
+ this._update();
402
+ }));
403
+ _defineProperty(this, "reference", modifier(element => {
404
+ this.setReference(element);
405
+ return () => {
406
+ if (this.isDestroyed || this.isDestroying) {
407
+ return;
408
+ }
409
+ if (this._registeredTarget === element) {
410
+ this.setReference(null);
411
+ }
412
+ };
413
+ }));
278
414
  this._delayedVisibilityToggle = null;
279
415
 
280
416
  // The final source of truth on whether or not all _hide() or _show() actions have completed
281
417
  this._isHidden = true;
282
418
 
419
+ // Blocks _update from (re)starting autoUpdate after hide until the next show.
420
+ this._positioningSuspended = false;
421
+
283
422
  // Holds a delayed function to toggle the visibility of the attachment.
284
423
  // Used to make sure animations can complete before the attachment is hidden.
285
424
  this._animationTimeout = null;
@@ -304,7 +443,13 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
304
443
  }
305
444
  _initializeAttacher() {
306
445
  this._removeEventListeners();
307
- this._currentTarget = this.args.explicitTarget || this.parentElement;
446
+ const target = resolveAttachmentTarget({
447
+ explicitTarget: this.args.explicitTarget,
448
+ registeredTarget: this._registeredTarget,
449
+ parentElement: this.parentElement
450
+ });
451
+ this._listenerTarget = getListenerTarget(target);
452
+ this._currentTarget = target;
308
453
  this._addListenersForShowEvents();
309
454
  if (!this._isHidden || this.isShown) {
310
455
  this._addListenersForHideEvents();
@@ -318,16 +463,20 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
318
463
  this.args.onInitializeAttacher?.(this._currentTarget, this.id);
319
464
  }
320
465
  _addListenersForShowEvents() {
321
- if (!this._currentTarget) {
466
+ const target = this._listenerTarget;
467
+ if (!target) {
322
468
  return;
323
469
  }
324
470
  this._showOn.forEach(event => {
325
471
  this._showListenersOnTargetByEvent[event] = this._showAfterDelay;
326
- this._currentTarget.addEventListener(event, this._showAfterDelay, this.useCapture);
472
+ target.addEventListener(event, this._showAfterDelay, this.useCapture);
327
473
  });
328
474
  }
329
475
  willDestroy() {
330
476
  super.willDestroy(...arguments);
477
+ this._cleanup?.();
478
+ this._cleanup = null;
479
+ cancel(this._setReferenceTimer);
331
480
  this._cancelAnimation();
332
481
  cancel(this._delayedVisibilityToggle);
333
482
  this._removeEventListeners();
@@ -340,19 +489,17 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
340
489
  document.removeEventListener(eventType, this._hideListenersOnDocumentByEvent[eventType], this.useCapture);
341
490
  delete this._hideListenersOnDocumentByEvent[eventType];
342
491
  });
343
- if (!this._currentTarget) {
492
+ const target = this._listenerTarget;
493
+ if (!target) {
344
494
  return;
345
495
  }
346
496
  [this._hideListenersOnTargetByEvent, this._showListenersOnTargetByEvent].forEach(eventToListener => {
347
497
  Object.keys(eventToListener).forEach(event => {
348
- this._currentTarget.removeEventListener(event, eventToListener[event], this.useCapture);
498
+ target.removeEventListener(event, eventToListener[event], this.useCapture);
349
499
  });
350
500
  });
351
501
  }
352
- onTargetOrTriggerChange() {
353
- this._initializeAttacher();
354
- }
355
- onIsShownChange() {
502
+ _syncIsShown() {
356
503
  const isShown = this.isShown;
357
504
  if (isShown === true && this._isHidden) {
358
505
  this._show();
@@ -381,6 +528,7 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
381
528
  if (!this._currentTarget) {
382
529
  return;
383
530
  }
531
+ this._positioningSuspended = false;
384
532
  this._mustRender = true;
385
533
 
386
534
  // Make the attachment visible immediately so transition animations can take place
@@ -441,6 +589,9 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
441
589
  this._delayedVisibilityToggle = debounce(this, this._hide, hideDelay, !hideDelay);
442
590
  }
443
591
  _hide() {
592
+ this._positioningSuspended = true;
593
+ this._cleanup?.();
594
+ this._cleanup = null;
444
595
  if (!this._floatingElement) {
445
596
  this._animationTimeout = requestAnimationFrame(() => {
446
597
  animationTestWaiter.endAsync(this._animationTimeout);
@@ -479,9 +630,9 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
479
630
 
480
631
  _addListenersForHideEvents() {
481
632
  const hideOn = this._hideOn;
482
- const target = this._currentTarget;
633
+ const target = this._listenerTarget;
483
634
 
484
- // Target or component was destroyed
635
+ // Target or component was destroyed (virtual refs without contextElement skip listeners)
485
636
  if (!target || this.isDestroyed || this.isDestroying) {
486
637
  return;
487
638
  }
@@ -538,7 +689,7 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
538
689
  debounce(this, this._hideIfMouseOutsideTargetOrAttachment, event, 10);
539
690
  }
540
691
  _hideIfMouseOutsideTargetOrAttachment(event) {
541
- const target = this._currentTarget;
692
+ const target = this._listenerTarget;
542
693
  if (!target) {
543
694
  return;
544
695
  }
@@ -552,8 +703,8 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
552
703
  }
553
704
  }
554
705
  _isCursorBetweenTargetAndAttachment(event) {
555
- if (!this._currentTarget) {
556
- return;
706
+ if (!this._currentTarget || !this._floatingElement) {
707
+ return false;
557
708
  }
558
709
  const {
559
710
  clientX,
@@ -586,7 +737,8 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
586
737
  return false;
587
738
  }
588
739
  _hideOnClickOut(event) {
589
- const targetReceivedClick = this._currentTarget.contains(event.target);
740
+ const target = this._listenerTarget;
741
+ const targetReceivedClick = target ? target.contains(event.target) : false;
590
742
  if (this.interactive) {
591
743
  if (!targetReceivedClick && !this._floatingElement.contains(event.target)) {
592
744
  this._hideAfterDelay();
@@ -604,10 +756,11 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
604
756
  if (event.relatedTarget === null) {
605
757
  this._hideAfterDelay();
606
758
  }
607
- if (!this._currentTarget) {
759
+ const target = this._listenerTarget;
760
+ if (!target) {
608
761
  return;
609
762
  }
610
- const targetContainsFocus = this._currentTarget.contains(event.relatedTarget);
763
+ const targetContainsFocus = target.contains(event.relatedTarget);
611
764
  if (this.interactive) {
612
765
  if (!targetContainsFocus && !this._floatingElement.contains(event.relatedTarget)) {
613
766
  this._hideAfterDelay();
@@ -622,7 +775,7 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
622
775
  delete this._hideListenersOnDocumentByEvent[eventType];
623
776
  });
624
777
  const showOn = this._showOn;
625
- const target = this._currentTarget;
778
+ const target = this._listenerTarget;
626
779
 
627
780
  // The target was destroyed, nothing to remove listeners from
628
781
  if (!target) {
@@ -647,25 +800,22 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
647
800
  }
648
801
  });
649
802
  }
650
- didInsertFloatingElement(floatingElement) {
651
- this._floatingElement = floatingElement;
652
- if (this.renderInPlace) {
653
- this.parentElement = floatingElement.parentElement;
654
- this._initializeAttacher();
655
- }
656
- }
657
- didInsertArrow(element) {
658
- this._arrowElement = element;
659
- }
660
- onOptionsChange() {
661
- this._ensureArgumentsAreValid();
662
- this._update();
663
- }
664
- willDestroyFloatingElement() {
665
- this._cleanup?.();
666
- }
667
803
  _update() {
668
804
  this._cleanup?.();
805
+ this._cleanup = null;
806
+
807
+ // Suspended after _hide until the next _show. Hide writes tracked state that
808
+ // re-renders and can re-fire optionsDidUpdate → _update; without this flag
809
+ // that path restarts autoUpdate (especially with hideDuration: 0). Do not
810
+ // use _isHidden here — it stays true until late in _startShowAnimation,
811
+ // after _update must already run.
812
+ if (this.isDestroyed || this.isDestroying || this._positioningSuspended || !this._currentTarget || !this._floatingElement) {
813
+ return;
814
+ }
815
+ const isTargetConnected = isElementTarget(this._currentTarget) ? this._currentTarget.isConnected : true;
816
+ if (!isTargetConnected || !this._floatingElement.isConnected) {
817
+ return;
818
+ }
669
819
  if (this.autoUpdate) {
670
820
  this._cleanup = autoUpdate(this._currentTarget, this._floatingElement, this._updatePosition, typeOf(this.autoUpdate) === 'object' ? this.autoUpdate : undefined);
671
821
  } else {
@@ -673,6 +823,16 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
673
823
  }
674
824
  }
675
825
  _updatePosition() {
826
+ if (this.isDestroyed || this.isDestroying || !this._currentTarget || !this._floatingElement) {
827
+ return;
828
+ }
829
+ const isTargetConnected = isElementTarget(this._currentTarget) ? this._currentTarget.isConnected : true;
830
+ if (!isTargetConnected || !this._floatingElement.isConnected) {
831
+ // Stop lingering observers if a node detached mid-update.
832
+ this._cleanup?.();
833
+ this._cleanup = null;
834
+ return;
835
+ }
676
836
  const computePositionToken = animationTestWaiter.beginAsync();
677
837
  computePosition(this._currentTarget, this._floatingElement, {
678
838
  ...this.floatingUiOptions,
@@ -685,21 +845,31 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
685
845
  middlewareData
686
846
  }) => {
687
847
  animationTestWaiter.endAsync(computePositionToken);
848
+ if (this.isDestroyed || this.isDestroying || !this._floatingElement || !this._floatingElement.isConnected) {
849
+ return;
850
+ }
688
851
  Object.assign(this._floatingElement.style, {
689
852
  left: `${x}px`,
690
853
  top: `${y}px`
691
854
  });
692
- if (middlewareData.arrow) {
855
+ if (middlewareData.arrow && this._arrowElement) {
693
856
  const {
694
- x,
695
- y
857
+ x: arrowX,
858
+ y: arrowY
696
859
  } = middlewareData.arrow;
697
860
  Object.assign(this._arrowElement.style, {
698
- left: x != null ? `${x}px` : '',
699
- top: y != null ? `${y}px` : ''
861
+ left: arrowX != null ? `${arrowX}px` : '',
862
+ top: arrowY != null ? `${arrowY}px` : ''
700
863
  });
701
864
  }
702
865
  this._floatingElement.setAttribute('x-placement', placement);
866
+ }).catch(error => {
867
+ animationTestWaiter.endAsync(computePositionToken);
868
+ if (!this.isDestroyed && !this.isDestroying) {
869
+ warn(`[ember-attacher] Positioning error: ${error?.message ?? error}`, {
870
+ id: 'ember-attacher.positioning-error'
871
+ });
872
+ }
703
873
  });
704
874
  }
705
875
  _cancelAnimation() {
@@ -748,21 +918,28 @@ let BasicAttacher = (_class = class BasicAttacher extends Component {
748
918
  initializer: function () {
749
919
  return null;
750
920
  }
751
- }), _descriptor6 = _applyDecoratedDescriptor(_class.prototype, "_mustRender", [tracked], {
921
+ }), _descriptor6 = _applyDecoratedDescriptor(_class.prototype, "_registeredTarget", [tracked], {
922
+ configurable: true,
923
+ enumerable: true,
924
+ writable: true,
925
+ initializer: function () {
926
+ return null;
927
+ }
928
+ }), _descriptor7 = _applyDecoratedDescriptor(_class.prototype, "_mustRender", [tracked], {
752
929
  configurable: true,
753
930
  enumerable: true,
754
931
  writable: true,
755
932
  initializer: function () {
756
933
  return false;
757
934
  }
758
- }), _descriptor7 = _applyDecoratedDescriptor(_class.prototype, "_transitionDuration", [tracked], {
935
+ }), _descriptor8 = _applyDecoratedDescriptor(_class.prototype, "_transitionDuration", [tracked], {
759
936
  configurable: true,
760
937
  enumerable: true,
761
938
  writable: true,
762
939
  initializer: function () {
763
940
  return 0;
764
941
  }
765
- }), _applyDecoratedDescriptor(_class.prototype, "hide", [action], Object.getOwnPropertyDescriptor(_class.prototype, "hide"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "onParentFinderInsert", [action], Object.getOwnPropertyDescriptor(_class.prototype, "onParentFinderInsert"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "_ensureArgumentsAreValid", [action], Object.getOwnPropertyDescriptor(_class.prototype, "_ensureArgumentsAreValid"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "onTargetOrTriggerChange", [action], Object.getOwnPropertyDescriptor(_class.prototype, "onTargetOrTriggerChange"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "onIsShownChange", [action], Object.getOwnPropertyDescriptor(_class.prototype, "onIsShownChange"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "didInsertFloatingElement", [action], Object.getOwnPropertyDescriptor(_class.prototype, "didInsertFloatingElement"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "didInsertArrow", [action], Object.getOwnPropertyDescriptor(_class.prototype, "didInsertArrow"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "onOptionsChange", [action], Object.getOwnPropertyDescriptor(_class.prototype, "onOptionsChange"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "willDestroyFloatingElement", [action], Object.getOwnPropertyDescriptor(_class.prototype, "willDestroyFloatingElement"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "_updatePosition", [action], Object.getOwnPropertyDescriptor(_class.prototype, "_updatePosition"), _class.prototype), _class);
942
+ }), _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);
766
943
  setComponentTemplate(TEMPLATE, BasicAttacher);
767
944
 
768
945
  export { BasicAttacher as default };