ember-attacher 4.2.1 → 4.4.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.
Files changed (37) hide show
  1. package/dist/_app_/components/attacher.js +1 -0
  2. package/dist/_app_/modifiers/tooltip.js +1 -0
  3. package/dist/attacher-core-m7x5g04q.js +2653 -0
  4. package/dist/attacher-core-m7x5g04q.js.map +1 -0
  5. package/dist/components/attach-popover.d.ts +14 -0
  6. package/dist/components/attach-popover.js +9 -9
  7. package/dist/components/attach-popover.js.map +1 -1
  8. package/dist/components/attach-tooltip.d.ts +15 -0
  9. package/dist/components/attach-tooltip.js +12 -34
  10. package/dist/components/attach-tooltip.js.map +1 -1
  11. package/dist/components/attacher.d.ts +17 -0
  12. package/dist/components/attacher.js +33 -0
  13. package/dist/components/attacher.js.map +1 -0
  14. package/dist/components/basic-attacher.d.ts +151 -0
  15. package/dist/components/basic-attacher.js +22 -973
  16. package/dist/components/basic-attacher.js.map +1 -1
  17. package/dist/defaults.d.ts +32 -0
  18. package/dist/defaults.js +1 -0
  19. package/dist/defaults.js.map +1 -1
  20. package/dist/index.d.ts +72 -0
  21. package/dist/index.js +7 -1
  22. package/dist/index.js.map +1 -1
  23. package/dist/is-visible-DQGdmVDv.js +42 -0
  24. package/dist/is-visible-DQGdmVDv.js.map +1 -0
  25. package/dist/modifiers/tooltip.d.ts +17 -0
  26. package/dist/modifiers/tooltip.js +254 -0
  27. package/dist/modifiers/tooltip.js.map +1 -0
  28. package/dist/styles/ember-attacher.css +1 -206
  29. package/dist/template-registry.d.ts +17 -0
  30. package/dist/test-support/index.d.ts +2 -0
  31. package/dist/test-support/index.js +1 -1
  32. package/dist/test-support/is-visible.d.ts +3 -0
  33. package/package.json +50 -15
  34. package/dist/is-visible-CzMFp_fy.js +0 -23
  35. package/dist/is-visible-CzMFp_fy.js.map +0 -1
  36. package/dist/target-resolution-Bz738VeA.js +0 -164
  37. package/dist/target-resolution-Bz738VeA.js.map +0 -1
@@ -1,994 +1,43 @@
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
- import { action } from '@ember/object';
3
1
  import Component from '@glimmer/component';
4
- import { schedule, cancel, later, next, debounce, run } from '@ember/runloop';
5
- import { getOwner } from '@ember/application';
6
- import { guidFor } from '@ember/object/internals';
7
- import { htmlSafe, isHTMLSafe } from '@ember/template';
8
- import { warn, assert, runInDebug } from '@ember/debug';
9
- import { isEmpty, typeOf } from '@ember/utils';
10
- import { flip, shift, limitShift, arrow, autoUpdate, computePosition } from '@floating-ui/dom';
11
- import { buildWaiter } from '@ember/test-waiters';
12
- import { tracked } from '@glimmer/tracking';
13
- import { modifier } from 'ember-modifier';
14
- import DEFAULTS from '../defaults.js';
2
+ import { A as AttacherCore } from '../attacher-core-m7x5g04q.js';
15
3
  import { precompileTemplate } from '@ember/template-compilation';
16
4
  import { setComponentTemplate } from '@ember/component';
17
5
  import templateOnly from '@ember/component/template-only';
18
6
 
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
- }
44
-
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
- }
90
-
91
- function consume(positional) {
92
- for (let i = 0; i < positional.length; i++) {
93
- void positional[i];
94
- }
95
- }
96
-
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
- */
103
- function onInsert(fn) {
104
- const seen = new WeakSet();
105
- return modifier(element => {
106
- if (seen.has(element)) {
107
- return;
108
- }
109
- seen.add(element);
110
- const timer = schedule('actions', fn, element);
111
- return () => cancel(timer);
112
- });
113
- }
114
-
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
- */
122
- function onUpdate(fn) {
123
- const seen = new WeakSet();
124
- return modifier((element, positional) => {
125
- consume(positional);
126
- if (!seen.has(element)) {
127
- seen.add(element);
128
- return;
129
- }
130
- fn();
131
- });
132
- }
133
-
134
7
  var MaybeInElement = setComponentTemplate(precompileTemplate("{{~#if @renderInPlace~}}{{yield}}{{~else~}}{{#in-element @destinationElement insertBefore=null}}{{yield}}{{/in-element}}{{~/if~}}", {
135
8
  strictMode: true
136
9
  }), templateOnly());
137
10
 
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");
11
+ var TEMPLATE = precompileTemplate("{{~#if (has-block \"target\")~}}{{yield this.core.api.target this.core.api to=\"target\"}}{{~/if~}}{{~#unless this.core.renderFloatingElement~}}<meta hidden {{this.core.parentFinder (has-block \"target\")}} {{this.core.targetDidUpdate this.core.hideOn this.core.showOn @target @explicitTarget @id}} {{this.core.isShownDidUpdate this.core.controlledIsShown}}/>{{~/unless~}}{{~#if this.core.renderFloatingElement~}}<this.MaybeInElement @destinationElement={{this.core._floatingElementContainer}} @renderInPlace={{this.core._renderInPlace}}><div\n class=\"ember-attacher\"\n id={{this.core.id}}\n popover={{this.core._popoverAttr}}\n role={{this.core.ariaRole}}\n {{this.core.setupFloatingElement (has-block \"target\")}}\n {{this.core.targetDidUpdate this.core.hideOn this.core.showOn @target @explicitTarget @id}}\n {{this.core.isShownDidUpdate this.core.controlledIsShown}}\n {{this.core.optionsDidUpdate this.core.autoUpdate this.core.animation this.core.arrow this.core.useCapture this.core.placement this.core.strategy this.core._renderInPlace this.core._middleware this.core.id this.core.ariaRole}}\n ...attributes\n >\n {{#if this.core.shouldRenderFloatingElement}}\n <div class={{this.core._class}} style={{this.core._style}}>\n {{~#if (has-block \"content\")~}}{{yield this.core.api to=\"content\"}}{{~else if (has-block)~}}{{yield this.core.api}}{{~/if~}}\n {{#if this.core.arrow}}\n <div class=\"ember-attacher-arrow\" x-arrow {{this.core.insertArrow}}></div>\n {{/if}}\n {{#if this.core.isFillAnimation}}\n <div class=\"ember-attacher-fill-backdrop\" aria-hidden=\"true\">\n <div x-circle></div>\n </div>\n {{/if}}\n </div>\n {{/if}}\n </div></this.MaybeInElement>{{~/if~}}");
139
12
 
140
- var _class, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8;
141
- const animationTestWaiter = buildWaiter('basic-attacher');
142
- let BasicAttacher = (_class = class BasicAttacher extends Component {
143
- /**
144
- * ================== PUBLIC CONFIG OPTIONS ==================
145
- */
146
- get arrow() {
147
- return this.args.arrow ?? this._config.arrow ?? DEFAULTS.arrow;
148
- }
149
- get autoUpdate() {
150
- return this.args.autoUpdate ?? this._config.autoUpdate ?? DEFAULTS.autoUpdate;
151
- }
152
- get animation() {
153
- return this.args.animation || this._config.animation || DEFAULTS.animation;
154
- }
155
- get flip() {
156
- return this.args.flip ?? this._config.flip ?? DEFAULTS.flip;
157
- }
158
- get hideDelay() {
159
- return this.args.hideDelay ?? this._config.hideDelay ?? DEFAULTS.hideDelay;
160
- }
161
- get hideDuration() {
162
- return this.args.hideDuration ?? this._config.hideDuration ?? DEFAULTS.hideDuration;
163
- }
164
- get hideOn() {
165
- if (this.args.hideOn === null) {
166
- return null;
167
- }
168
- return this.args.hideOn ?? this._config.hideOn ?? DEFAULTS.hideOn;
169
- }
170
- get interactive() {
171
- return this.args.interactive ?? this._config.interactive ?? DEFAULTS.interactive;
172
- }
173
- get isOffset() {
174
- return this.args.isOffset ?? this._config.isOffset ?? DEFAULTS.isOffset;
175
- }
176
- get isShown() {
177
- return this.args.isShown ?? this._config.isShown ?? DEFAULTS.isShown;
178
- }
179
- get lazyRender() {
180
- return this.args.lazyRender ?? this._config.lazyRender ?? DEFAULTS.lazyRender;
181
- }
182
- get placement() {
183
- return this.args.placement ?? this._config.placement ?? DEFAULTS.placement;
184
- }
185
- get floatingElementContainer() {
186
- return this.args.floatingElementContainer || this._config.floatingElementContainer || DEFAULTS.floatingElementContainer;
187
- }
188
- get class() {
189
- return this.args.class || this._config.class;
190
- }
191
- get floatingUiOptions() {
192
- return this.args.floatingUiOptions || this._config.floatingUiOptions || DEFAULTS.floatingUiOptions;
193
- }
194
- get renderInPlace() {
195
- return this.args.renderInPlace ?? this._config.renderInPlace ?? DEFAULTS.renderInPlace;
196
- }
197
- get showDelay() {
198
- return this.args.showDelay ?? this._config.showDelay ?? DEFAULTS.showDelay;
199
- }
200
- get showDuration() {
201
- return this.args.showDuration ?? this._config.showDuration ?? DEFAULTS.showDuration;
202
- }
203
- get showOn() {
204
- if (this.args.showOn === null) {
205
- return null;
206
- }
207
- return this.args.showOn ?? this._config.showOn ?? DEFAULTS.showOn;
208
- }
209
- get style() {
210
- return this.args.style ?? this._config.style ?? DEFAULTS.style;
211
- }
212
- get useCapture() {
213
- return this.args.useCapture ?? this._config.useCapture ?? DEFAULTS.useCapture;
214
- }
215
- get configKey() {
216
- return this.args.configKey || 'popover';
217
- }
218
- get isFillAnimation() {
219
- return this.animation === 'fill';
220
- }
221
- get renderFloatingElement() {
222
- return (this.renderInPlace || this._currentTarget) && (!this.lazyRender || this._mustRender);
223
- }
224
- get shouldRenderFloatingElement() {
225
- // Always render the floating element unless lazyRender is true and we haven't been triggered yet
226
- return !this.lazyRender || this._mustRender;
227
- }
228
- get id() {
229
- return this.args.id || `${guidFor(this)}-floating`;
230
- }
231
- get overflowPadding() {
232
- return this.args.overflowPadding ?? this._config.overflowPadding ?? DEFAULTS.overflowPadding;
233
- }
234
-
235
- // The circle element needs a special duration that is slightly faster than the floating element's
236
- // transition, this prevents text from appearing outside the circle as it fills the background
237
- get _circleTransitionDuration() {
238
- return htmlSafe(`transition-duration: ${Math.round(this._transitionDuration / 1.25)}ms`);
239
- }
240
- get _class() {
241
- const showOrHideClass = `ember-attacher-${this._isStartingAnimation ? 'show' : 'hide'}`;
242
- const arrowClass = `ember-attacher-${this.arrow ? 'with' : 'without'}-arrow`;
243
- const baseClass = this.class || '';
244
- const additionalClass = this.args.additionalClass || '';
245
- return [`ember-attacher-${this.animation}`, baseClass, additionalClass, showOrHideClass, arrowClass].filter(Boolean).join(' ');
246
- }
247
- get _style() {
248
- const style = this.style;
249
- const transitionDuration = this._transitionDuration;
250
- warn('@ember/string/htmlSafe must be used for any `style` passed to ember-attacher', isEmpty(style) || isHTMLSafe(style), {
251
- id: 'ember-attacher-require-html-safe-style'
13
+ class BasicAttacher extends Component {
14
+ constructor(owner, args) {
15
+ super(owner, args);
16
+ this.MaybeInElement = MaybeInElement;
17
+ this.core = new AttacherCore(this, () => this.args, {
18
+ defaultConfigKey: this._defaultConfigKey,
19
+ defaultAriaRole: this._defaultAriaRole,
20
+ getAdditionalClass: () => this.additionalClass,
21
+ allowParentFallback: true,
22
+ isComponentHost: true
252
23
  });
253
- return htmlSafe(`transition-duration: ${transitionDuration}ms; ${style}`);
254
24
  }
255
-
256
- // This is memoized so it can be used by both attach-popover and attach-tooltip
257
- get _envConfig() {
258
- return getOwner(this).resolveRegistration('config:environment').emberAttacher || {};
259
- }
260
- get _config() {
261
- return {
262
- ...this._envConfig,
263
- ...this._envConfig[this.configKey]
264
- };
265
- }
266
- get _hideOn() {
267
- let hideOn = this.hideOn;
268
- if (hideOn === undefined) {
269
- hideOn = DEFAULTS.hideOn;
270
- }
271
- return hideOn === null ? [] : hideOn.split(' ');
272
- }
273
- get _middleware() {
274
- // Copy the middleware since we might write to the provided array
275
- const middleware = this.args.middleware ? [...this.args.middleware] : [];
276
- const flipString = this.flip;
277
- if (flipString) {
278
- const flipOptions = {
279
- fallbackPlacements: flipString.split(' ')
280
- };
281
- const flipMiddleware = middleware.find(name => name === 'flip');
282
- if (!flipMiddleware) {
283
- middleware.push(flip(flipOptions));
284
- } else if (!flipMiddleware.fallbackPlacements) {
285
- Object.assign({}, flipMiddleware, flipOptions);
286
- }
287
- } else if (this.overflowPadding !== false) {
288
- middleware.push(flip());
289
- }
290
- if (this.overflowPadding !== false && !middleware.find(name => name === 'shift')) {
291
- middleware.push(shift({
292
- limiter: limitShift(),
293
- padding: this.overflowPadding
294
- }));
295
- }
296
- if (this.arrow && this._arrowElement && !middleware.find(name => name === 'arrow')) {
297
- middleware.push(arrow({
298
- element: this._arrowElement
299
- }));
300
- }
301
- return middleware;
302
- }
303
- get _floatingElementContainer() {
304
- const maybeContainer = this.floatingElementContainer;
305
- const renderInPlace = this._renderInPlace;
306
- let floatingElementContainer;
307
- if (renderInPlace) {
308
- floatingElementContainer = this.parentElement;
309
- } else if (maybeContainer instanceof Element) {
310
- floatingElementContainer = maybeContainer;
311
- } else if (typeof maybeContainer === 'string') {
312
- const selector = maybeContainer;
313
- const possibleContainers = document.querySelectorAll(selector);
314
- assert(`floatingElementContainer selector "${selector}" found ` + `${possibleContainers.length} possible containers when there should be exactly 1`, possibleContainers.length === 1);
315
- floatingElementContainer = possibleContainers[0];
316
- }
317
- return floatingElementContainer;
318
- }
319
- get _renderInPlace() {
320
- // document is undefined in Fastboot, so we have to render in
321
- // place for the floating element to show up at all.
322
- return typeof document !== 'undefined' ? !!this.renderInPlace : true;
323
- }
324
- _setIsVisibleAfterDelay(isVisible, delay) {
325
- if (!this._floatingElement) {
326
- this._animationTimeout = requestAnimationFrame(() => {
327
- this._setIsVisibleAfterDelay(isVisible, delay);
328
- });
329
- return;
330
- }
331
- const onChange = this.args.onChange;
332
- if (delay) {
333
- this._delayedVisibilityToggle = later(this, () => {
334
- this._animationTimeout = requestAnimationFrame(() => {
335
- animationTestWaiter.endAsync(this._animationTimeout);
336
- if (!this.isDestroyed && !this.isDestroying) {
337
- if (!isVisible) {
338
- this._cleanup?.();
339
- this._cleanup = null;
340
- }
341
- this._floatingElement.style.display = isVisible ? 'block' : 'none';
342
-
343
- // Prevent jank by making the attachment invisible until positioned.
344
- // The visibility style will be toggled by this._startShowAnimation()
345
- this._floatingElement.style.visibility = isVisible ? 'hidden' : '';
346
- if (onChange) {
347
- onChange(isVisible);
348
- }
349
- }
350
- });
351
- animationTestWaiter.beginAsync(this._animationTimeout);
352
- }, delay);
353
- } else {
354
- if (!isVisible) {
355
- this._cleanup?.();
356
- this._cleanup = null;
357
- }
358
- this._floatingElement.style.display = isVisible ? 'block' : 'none';
359
- // Prevent jank by making the attachment invisible until positioned.
360
- // The visibility style will be toggled by this._startShowAnimation()
361
- this._floatingElement.style.visibility = isVisible ? 'hidden' : '';
362
- if (onChange) {
363
- onChange(isVisible);
364
- }
365
- }
366
- }
367
- get _showOn() {
368
- let showOn = this.showOn;
369
- if (showOn === undefined) {
370
- showOn = DEFAULTS.showOn;
371
- }
372
- return showOn === null ? [] : showOn.split(' ');
373
- }
374
-
375
- // Exposed via the named yield to enable custom hide events
376
- hide() {
377
- this._hide();
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
-
412
- _ensureArgumentsAreValid() {
413
- runInDebug(() => {
414
- if (this.arrow && this.isFillAnimation) {
415
- warn('Animation: \'fill\' is not compatible with arrow: true', {
416
- id: 70015
417
- });
418
- }
419
- if (this.useCapture !== this._lastUseCaptureArgumentValue) {
420
- warn('The value of the useCapture argument was mutated', {
421
- id: 'ember-attacher.use-capture-mutated'
422
- });
423
- }
424
- });
425
- }
426
- constructor() {
427
- super(...arguments);
428
-
429
- // The debounced _hide() and _show() are stored here so they can be cancelled when necessary
430
- _defineProperty(this, "MaybeInElement", MaybeInElement);
431
- _initializerDefineProperty(this, "parentNotFound", _descriptor, this);
432
- _initializerDefineProperty(this, "parentElement", _descriptor2, this);
433
- _initializerDefineProperty(this, "_isStartingAnimation", _descriptor3, this);
434
- _initializerDefineProperty(this, "_arrowElement", _descriptor4, this);
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);
440
- // Untracked copy of the node listeners are on. `_removeEventListeners` must
441
- // not read `_currentTarget` in the same computation that writes it
442
- // (`targetDidUpdate` → `_initializeAttacher` when `@explicitTarget` changes).
443
- _defineProperty(this, "_listenerTarget", null);
444
- // This is set to true when the popover is shown in order to override lazyRender=false
445
- _initializerDefineProperty(this, "_mustRender", _descriptor7, this);
446
- _initializerDefineProperty(this, "_transitionDuration", _descriptor8, this);
447
- _defineProperty(this, "_floatingElement", null);
448
- _defineProperty(this, "parentFinder", onInsert(element => {
449
- if (this.isDestroyed || this.isDestroying) {
450
- return;
451
- }
452
- this.parentElement = element.parentElement;
453
- this._initializeAttacher();
454
- }));
455
- // Insert + autoUpdate teardown. Must not read tracked state in the modifier
456
- // callback (the scheduled fn is fine); a tracked read would re-run this and
457
- // fire the destructor before updates.
458
- _defineProperty(this, "setupFloatingElement", modifier(element => {
459
- const timer = schedule('actions', () => {
460
- if (this.isDestroyed || this.isDestroying) {
461
- return;
462
- }
463
- this._floatingElement = element;
464
- if (this.renderInPlace) {
465
- this.parentElement = element.parentElement;
466
- this._initializeAttacher();
467
- }
468
- });
469
- return () => {
470
- cancel(timer);
471
- this._cleanup?.();
472
- };
473
- }));
474
- _defineProperty(this, "insertArrow", onInsert(element => {
475
- if (this.isDestroyed || this.isDestroying) {
476
- return;
477
- }
478
- this._arrowElement = element;
479
- }));
480
- _defineProperty(this, "isShownDidUpdate", onUpdate(() => this._syncIsShown()));
481
- _defineProperty(this, "targetDidUpdate", onUpdate(() => this._initializeAttacher()));
482
- _defineProperty(this, "optionsDidUpdate", onUpdate(() => {
483
- this._ensureArgumentsAreValid();
484
- this._update();
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
- }));
497
- this._delayedVisibilityToggle = null;
498
-
499
- // The final source of truth on whether or not all _hide() or _show() actions have completed
500
- this._isHidden = true;
501
-
502
- // Blocks _update from (re)starting autoUpdate after hide until the next show.
503
- this._positioningSuspended = false;
504
-
505
- // Holds a delayed function to toggle the visibility of the attachment.
506
- // Used to make sure animations can complete before the attachment is hidden.
507
- this._animationTimeout = null;
508
-
509
- // Used to store event listeners so they can be removed when necessary.
510
- this._hideListenersOnDocumentByEvent = {};
511
- this._hideListenersOnTargetByEvent = {};
512
- this._showListenersOnTargetByEvent = {};
513
-
514
- // Hacks to make sure event listeners have the right context and are still removable
515
- this._debouncedHideIfMouseOutsideTargetOrAttachment = this._debouncedHideIfMouseOutsideTargetOrAttachment.bind(this);
516
- this._hide = this._hide.bind(this);
517
- this._hideAfterDelay = this._hideAfterDelay.bind(this);
518
- this._hideIfMouseOutsideTargetOrAttachment = this._hideIfMouseOutsideTargetOrAttachment.bind(this);
519
- this._hideOnClickOut = this._hideOnClickOut.bind(this);
520
- this._hideOnEscapeKey = this._hideOnEscapeKey.bind(this);
521
- this._hideOnLostFocus = this._hideOnLostFocus.bind(this);
522
- this._hideOnMouseLeaveTarget = this._hideOnMouseLeaveTarget.bind(this);
523
- this._show = this._show.bind(this);
524
- this._showAfterDelay = this._showAfterDelay.bind(this);
525
- this._lastUseCaptureArgumentValue = this.useCapture;
526
- }
527
- _initializeAttacher() {
528
- this._removeEventListeners();
529
- const target = resolveAttachmentTarget({
530
- explicitTarget: this.args.explicitTarget,
531
- registeredTarget: this._registeredTarget,
532
- parentElement: this.parentElement
533
- });
534
- this._listenerTarget = getListenerTarget(target);
535
- this._currentTarget = target;
536
- this._addListenersForShowEvents();
537
- if (!this._isHidden || this.isShown) {
538
- this._addListenersForHideEvents();
539
-
540
- // Even if the attachment is already shown, we still want to
541
- // call this._show() to make sure its position is updated for a potentially new target.
542
- this._show();
543
- }
544
-
545
- // Call hook for subclasses to add their own initialization logic
546
- this.args.onInitializeAttacher?.(this._currentTarget, this.id);
547
- }
548
- _addListenersForShowEvents() {
549
- const target = this._listenerTarget;
550
- if (!target) {
551
- return;
552
- }
553
- this._showOn.forEach(event => {
554
- this._showListenersOnTargetByEvent[event] = this._showAfterDelay;
555
- target.addEventListener(event, this._showAfterDelay, this.useCapture);
556
- });
557
- }
558
- willDestroy() {
559
- super.willDestroy(...arguments);
560
- this._cleanup?.();
561
- this._cleanup = null;
562
- cancel(this._setReferenceTimer);
563
- this._cancelAnimation();
564
- cancel(this._delayedVisibilityToggle);
565
- this._removeEventListeners();
566
-
567
- // Call hook for cleanup
568
- this.args.onWillDestroy?.(this._currentTarget, this.id);
569
- }
570
- _removeEventListeners() {
571
- Object.keys(this._hideListenersOnDocumentByEvent).forEach(eventType => {
572
- document.removeEventListener(eventType, this._hideListenersOnDocumentByEvent[eventType], this.useCapture);
573
- delete this._hideListenersOnDocumentByEvent[eventType];
574
- });
575
- const target = this._listenerTarget;
576
- if (!target) {
577
- return;
578
- }
579
- [this._hideListenersOnTargetByEvent, this._showListenersOnTargetByEvent].forEach(eventToListener => {
580
- Object.keys(eventToListener).forEach(event => {
581
- target.removeEventListener(event, eventToListener[event], this.useCapture);
582
- });
583
- });
584
- }
585
- _syncIsShown() {
586
- const isShown = this.isShown;
587
- if (isShown === true && this._isHidden) {
588
- this._show();
589
-
590
- // Add the hide listeners in the next run loop to avoid conflicts
591
- // where clicking triggers both an isShown toggle and a clickout.
592
- next(this, () => this._addListenersForHideEvents());
593
- } else if (isShown === false && !this._isHidden) {
594
- this._hide();
595
- }
596
- }
597
-
598
- /**
599
- * ================== SHOW ATTACHMENT LOGIC ==================
600
- */
601
-
602
- _showAfterDelay() {
603
- cancel(this._delayedVisibilityToggle);
604
- this._mustRender = true;
605
- this._addListenersForHideEvents();
606
- const showDelay = parseInt(this.showDelay);
607
- this._delayedVisibilityToggle = debounce(this, this._show, showDelay, !showDelay);
608
- }
609
- _show() {
610
- this._cancelAnimation();
611
- if (!this._currentTarget) {
612
- return;
613
- }
614
- this._positioningSuspended = false;
615
- this._mustRender = true;
616
-
617
- // Make the attachment visible immediately so transition animations can take place
618
- this._setIsVisibleAfterDelay(true, 0);
619
- this._startShowAnimation();
620
- }
621
- _startShowAnimation() {
622
- // Start the show animation on the next cycle so CSS transitions can have an effect.
623
- // If we start the animation immediately, the transition won't work because
624
- // `display: none` => `display: ''` is not transition-able.
625
- // All included animations set opaque: 0, so the attachment is still effectively hidden until
626
- // the final RAF occurs.
627
- this._animationTimeout = requestAnimationFrame(() => {
628
- animationTestWaiter.endAsync(this._animationTimeout);
629
- if (this.isDestroyed || this.isDestroying || !this._currentTarget) {
630
- return;
631
- }
632
- const floatingElement = this._floatingElement;
633
-
634
- // Wait until the element is visible before continuing
635
- if (!floatingElement || floatingElement.style.display === 'none') {
636
- this._startShowAnimation();
637
- return;
638
- }
639
- this._update();
640
-
641
- // Wait for the above positioning to take effect before starting the show animation,
642
- // else the positioning itself will be animated, causing animation glitches.
643
- this._animationTimeout = requestAnimationFrame(() => {
644
- animationTestWaiter.endAsync(this._animationTimeout);
645
- if (this.isDestroyed || this.isDestroying || !this._currentTarget) {
646
- return;
647
- }
648
- run(() => {
649
- if (this.isDestroyed || this.isDestroying || !this._currentTarget) {
650
- return;
651
- }
652
- // Make the floating element visible now that it has been positioned
653
- floatingElement.style.visibility = '';
654
- this._transitionDuration = parseInt(this.showDuration);
655
- this._isStartingAnimation = true;
656
- floatingElement.setAttribute('aria-hidden', 'false');
657
- });
658
- this._isHidden = false;
659
- });
660
- animationTestWaiter.beginAsync(this._animationTimeout);
661
- });
662
- animationTestWaiter.beginAsync(this._animationTimeout);
663
- }
664
-
665
- /**
666
- * ================== HIDE ATTACHMENT LOGIC ==================
667
- */
668
-
669
- _hideAfterDelay() {
670
- cancel(this._delayedVisibilityToggle);
671
- const hideDelay = parseInt(this.hideDelay);
672
- this._delayedVisibilityToggle = debounce(this, this._hide, hideDelay, !hideDelay);
673
- }
674
- _hide() {
675
- this._positioningSuspended = true;
676
- this._cleanup?.();
677
- this._cleanup = null;
678
- if (!this._floatingElement) {
679
- this._animationTimeout = requestAnimationFrame(() => {
680
- animationTestWaiter.endAsync(this._animationTimeout);
681
- this._hide();
682
- });
683
- animationTestWaiter.beginAsync(this._animationTimeout);
684
- return;
685
- }
686
- this._cancelAnimation();
687
- this._removeListenersForHideEvents();
688
- this._animationTimeout = requestAnimationFrame(() => {
689
- animationTestWaiter.endAsync(this._animationTimeout);
690
- // Avoid a race condition where we attempt to hide after the component is being destroyed.
691
- if (this.isDestroyed || this.isDestroying) {
692
- return;
693
- }
694
- const hideDuration = parseInt(this.hideDuration);
695
- run(() => {
696
- if (this.isDestroyed || this.isDestroying) {
697
- return;
698
- }
699
- this._transitionDuration = hideDuration;
700
- this._isStartingAnimation = false;
701
- this._floatingElement.setAttribute('aria-hidden', 'true');
702
- // Wait for any animations to complete before hiding the attachment
703
- this._setIsVisibleAfterDelay(false, hideDuration);
704
- });
705
- this._isHidden = true;
706
- });
707
- animationTestWaiter.beginAsync(this._animationTimeout);
708
- }
709
-
710
- /**
711
- * ================== HIDE LISTENERS ==================
712
- */
713
-
714
- _addListenersForHideEvents() {
715
- const hideOn = this._hideOn;
716
- const target = this._listenerTarget;
717
-
718
- // Target or component was destroyed (virtual refs without contextElement skip listeners)
719
- if (!target || this.isDestroyed || this.isDestroying) {
720
- return;
721
- }
722
- if (hideOn.includes('click')) {
723
- const showOnClickListener = this._showListenersOnTargetByEvent.click;
724
- if (showOnClickListener) {
725
- target.removeEventListener('click', showOnClickListener, this.useCapture);
726
- delete this._showListenersOnTargetByEvent.click;
727
- }
728
- this._hideListenersOnTargetByEvent.click = this._hideAfterDelay;
729
- target.addEventListener('click', this._hideAfterDelay, this.useCapture);
730
- }
731
- if (hideOn.includes('clickout')) {
732
- const clickoutEvent = 'ontouchstart' in window ? 'touchend' : 'click';
733
- this._hideListenersOnDocumentByEvent[clickoutEvent] = this._hideOnClickOut;
734
- document.addEventListener(clickoutEvent, this._hideOnClickOut, this.useCapture);
735
- }
736
- if (hideOn.includes('escapekey')) {
737
- this._hideListenersOnDocumentByEvent.keydown = this._hideOnEscapeKey;
738
- document.addEventListener('keydown', this._hideOnEscapeKey, this.useCapture);
739
- }
740
-
741
- // Hides the attachment when the mouse leaves the target
742
- // (or leaves both target and attachment for interactive attachments)
743
- if (hideOn.includes('mouseleave')) {
744
- this._hideListenersOnTargetByEvent.mouseleave = this._hideOnMouseLeaveTarget;
745
- target.addEventListener('mouseleave', this._hideOnMouseLeaveTarget, this.useCapture);
746
- }
747
-
748
- // Hides the attachment when focus is lost on the target
749
- ['blur', 'focusout'].forEach(eventType => {
750
- if (hideOn.includes(eventType)) {
751
- this._hideListenersOnTargetByEvent[eventType] = this._hideOnLostFocus;
752
- target.addEventListener(eventType, this._hideOnLostFocus, this.useCapture);
753
- }
754
- });
755
- }
756
- _hideOnMouseLeaveTarget() {
757
- if (this.interactive) {
758
- // TODO(kjb) Should debounce this, but hiding appears sluggish if you debounce.
759
- // - If you debounce with immediate fire, you get a bug where you can move out of the
760
- // attachment and not trigger the hide because the hide check was debounced
761
- // - Ideally we would debounce with an immediate run, then instead of debouncing, we would
762
- // queue another fire at the end of the debounce period
763
- if (!this._hideListenersOnDocumentByEvent.mousemove) {
764
- this._hideListenersOnDocumentByEvent.mousemove = this._hideIfMouseOutsideTargetOrAttachment;
765
- document.addEventListener('mousemove', this._hideIfMouseOutsideTargetOrAttachment, this.useCapture);
766
- }
767
- } else {
768
- this._hideAfterDelay();
769
- }
770
- }
771
- _debouncedHideIfMouseOutsideTargetOrAttachment(event) {
772
- debounce(this, this._hideIfMouseOutsideTargetOrAttachment, event, 10);
773
- }
774
- _hideIfMouseOutsideTargetOrAttachment(event) {
775
- const target = this._listenerTarget;
776
- if (!target) {
777
- return;
778
- }
779
-
780
- // If cursor is not on the attachment or target, hide the floating element
781
- if (!target.contains(event.target) && !(this.isOffset && isCursorBetween(event, this._currentTarget, this._floatingElement)) && this._floatingElement && !this._floatingElement.contains(event.target)) {
782
- // Remove this listener before hiding the attachment
783
- delete this._hideListenersOnDocumentByEvent.mousemove;
784
- document.removeEventListener('mousemove', this._hideIfMouseOutsideTargetOrAttachment, this.useCapture);
785
- this._hideAfterDelay();
786
- }
787
- }
788
- _hideOnClickOut(event) {
789
- const target = this._listenerTarget;
790
- const targetReceivedClick = elementContainsEvent(target, event);
791
- if (this.interactive) {
792
- if (!targetReceivedClick && !elementContainsEvent(this._floatingElement, event)) {
793
- this._hideAfterDelay();
794
- }
795
- } else if (!targetReceivedClick) {
796
- this._hideAfterDelay();
797
- }
798
- }
799
- _hideOnEscapeKey(event) {
800
- if (event.keyCode === 27) {
801
- return this._hideAfterDelay();
802
- }
803
- }
804
- _hideOnLostFocus(event) {
805
- if (event.relatedTarget === null) {
806
- this._hideAfterDelay();
807
- }
808
- const target = this._listenerTarget;
809
- if (!target) {
810
- return;
811
- }
812
- const targetContainsFocus = target.contains(event.relatedTarget);
813
- if (this.interactive) {
814
- if (!targetContainsFocus && !this._floatingElement.contains(event.relatedTarget)) {
815
- this._hideAfterDelay();
816
- }
817
- } else if (!targetContainsFocus) {
818
- this._hideAfterDelay();
819
- }
820
- }
821
- _removeListenersForHideEvents() {
822
- Object.keys(this._hideListenersOnDocumentByEvent).forEach(eventType => {
823
- document.removeEventListener(eventType, this._hideListenersOnDocumentByEvent[eventType], this.useCapture);
824
- delete this._hideListenersOnDocumentByEvent[eventType];
825
- });
826
- const showOn = this._showOn;
827
- const target = this._listenerTarget;
828
-
829
- // The target was destroyed, nothing to remove listeners from
830
- if (!target) {
831
- return;
832
- }
833
-
834
- // Switch clicking back to a show event
835
- if (showOn.includes('click')) {
836
- const hideOnClickListener = this._hideListenersOnTargetByEvent.click;
837
- if (hideOnClickListener) {
838
- target.removeEventListener('click', hideOnClickListener, this.useCapture);
839
- delete this._hideListenersOnTargetByEvent.click;
840
- }
841
- this._showListenersOnTargetByEvent.click = this._showAfterDelay;
842
- target.addEventListener('click', this._showAfterDelay, this.useCapture);
843
- }
844
- ['blur', 'focusout', 'mouseleave'].forEach(eventType => {
845
- const listener = this._hideListenersOnTargetByEvent[eventType];
846
- if (listener) {
847
- target.removeEventListener(eventType, listener, this.useCapture);
848
- delete this._hideListenersOnTargetByEvent[eventType];
849
- }
850
- });
851
- }
852
- _update() {
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
- }
868
- if (this.autoUpdate) {
869
- this._cleanup = autoUpdate(this._currentTarget, this._floatingElement, this._updatePosition, typeOf(this.autoUpdate) === 'object' ? this.autoUpdate : undefined);
870
- } else {
871
- this._updatePosition();
872
- }
873
- }
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
- }
885
- const computePositionToken = animationTestWaiter.beginAsync();
886
- computePosition(this._currentTarget, this._floatingElement, {
887
- ...this.floatingUiOptions,
888
- middleware: this._middleware,
889
- placement: this.placement
890
- }).then(({
891
- x,
892
- y,
893
- placement,
894
- middlewareData
895
- }) => {
896
- animationTestWaiter.endAsync(computePositionToken);
897
- if (this.isDestroyed || this.isDestroying || !this._floatingElement || !this._floatingElement.isConnected) {
898
- return;
899
- }
900
- Object.assign(this._floatingElement.style, {
901
- left: `${x}px`,
902
- top: `${y}px`
903
- });
904
- if (middlewareData.arrow && this._arrowElement) {
905
- const {
906
- x: arrowX,
907
- y: arrowY
908
- } = middlewareData.arrow;
909
- Object.assign(this._arrowElement.style, {
910
- left: arrowX != null ? `${arrowX}px` : '',
911
- top: arrowY != null ? `${arrowY}px` : ''
912
- });
913
- }
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
- }
922
- });
923
- }
924
- _cancelAnimation() {
925
- if (typeof cancelAnimationFrame !== 'function') {
926
- return;
927
- }
928
- cancelAnimationFrame(this._animationTimeout);
929
- runInDebug(() => {
930
- if (animationTestWaiter.items?.get(this._animationTimeout)) {
931
- animationTestWaiter.endAsync(this._animationTimeout);
932
- }
933
- });
934
- }
935
- }, _descriptor = _applyDecoratedDescriptor(_class.prototype, "parentNotFound", [tracked], {
936
- configurable: true,
937
- enumerable: true,
938
- writable: true,
939
- initializer: function () {
940
- return true;
941
- }
942
- }), _descriptor2 = _applyDecoratedDescriptor(_class.prototype, "parentElement", [tracked], {
943
- configurable: true,
944
- enumerable: true,
945
- writable: true,
946
- initializer: function () {
947
- return null;
948
- }
949
- }), _descriptor3 = _applyDecoratedDescriptor(_class.prototype, "_isStartingAnimation", [tracked], {
950
- configurable: true,
951
- enumerable: true,
952
- writable: true,
953
- initializer: function () {
954
- return false;
955
- }
956
- }), _descriptor4 = _applyDecoratedDescriptor(_class.prototype, "_arrowElement", [tracked], {
957
- configurable: true,
958
- enumerable: true,
959
- writable: true,
960
- initializer: function () {
25
+ get _defaultConfigKey() {
961
26
  return null;
962
27
  }
963
- }), _descriptor5 = _applyDecoratedDescriptor(_class.prototype, "_currentTarget", [tracked], {
964
- configurable: true,
965
- enumerable: true,
966
- writable: true,
967
- initializer: function () {
968
- return null;
28
+ get _defaultAriaRole() {
29
+ return undefined;
969
30
  }
970
- }), _descriptor6 = _applyDecoratedDescriptor(_class.prototype, "_registeredTarget", [tracked], {
971
- configurable: true,
972
- enumerable: true,
973
- writable: true,
974
- initializer: function () {
975
- return null;
31
+ get ariaRole() {
32
+ return this.core.ariaRole;
976
33
  }
977
- }), _descriptor7 = _applyDecoratedDescriptor(_class.prototype, "_mustRender", [tracked], {
978
- configurable: true,
979
- enumerable: true,
980
- writable: true,
981
- initializer: function () {
982
- return false;
34
+ get additionalClass() {
35
+ return this.args.additionalClass || '';
983
36
  }
984
- }), _descriptor8 = _applyDecoratedDescriptor(_class.prototype, "_transitionDuration", [tracked], {
985
- configurable: true,
986
- enumerable: true,
987
- writable: true,
988
- initializer: function () {
989
- return 0;
37
+ get id() {
38
+ return this.core.id;
990
39
  }
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);
40
+ }
992
41
  setComponentTemplate(TEMPLATE, BasicAttacher);
993
42
 
994
43
  export { BasicAttacher as default };