@nanahoshi/mona-ui 0.24.8 → 0.24.10

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 (83) hide show
  1. package/fesm2022/nanahoshi-mona-ui-button-group.mjs +37 -9
  2. package/fesm2022/nanahoshi-mona-ui-button.mjs +8 -2
  3. package/fesm2022/nanahoshi-mona-ui-color-gradient.mjs +4 -3
  4. package/fesm2022/nanahoshi-mona-ui-color-picker.mjs +2 -2
  5. package/fesm2022/nanahoshi-mona-ui-contextmenu.mjs +101 -47
  6. package/fesm2022/nanahoshi-mona-ui-dialog.mjs +342 -102
  7. package/fesm2022/nanahoshi-mona-ui-dropdown-button.mjs +119 -69
  8. package/fesm2022/nanahoshi-mona-ui-editor.mjs +1054 -452
  9. package/fesm2022/{nanahoshi-mona-ui-grid-grid-footer-row.component-DdyHnUIr.mjs → nanahoshi-mona-ui-grid-grid-footer-row.component-DhKLnW06.mjs} +2 -2
  10. package/fesm2022/{nanahoshi-mona-ui-grid-grid-list.component-B6gq7Hu3.mjs → nanahoshi-mona-ui-grid-grid-list.component-voGbKOiB.mjs} +4 -4
  11. package/fesm2022/{nanahoshi-mona-ui-grid-grid-row.component-DdUY3I7P.mjs → nanahoshi-mona-ui-grid-grid-row.component-HQ1Kv6R9.mjs} +2 -3
  12. package/fesm2022/{nanahoshi-mona-ui-grid-grid-virtual-list.component-DG8Bu4Dy.mjs → nanahoshi-mona-ui-grid-grid-virtual-list.component-PNLJFcuH.mjs} +4 -4
  13. package/fesm2022/{nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-CVqpbMcb.mjs → nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-BO19AVwC.mjs} +9 -9
  14. package/fesm2022/nanahoshi-mona-ui-grid.mjs +1 -1
  15. package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +23 -0
  16. package/fesm2022/nanahoshi-mona-ui-internal.mjs +567 -33
  17. package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +20 -0
  18. package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +20 -0
  19. package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +20 -0
  20. package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +20 -0
  21. package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +20 -0
  22. package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +20 -0
  23. package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +20 -0
  24. package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +20 -0
  25. package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +20 -0
  26. package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +20 -0
  27. package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +20 -0
  28. package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +20 -0
  29. package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +20 -0
  30. package/fesm2022/nanahoshi-mona-ui-menubar.mjs +127 -133
  31. package/fesm2022/nanahoshi-mona-ui-notification.mjs +473 -240
  32. package/fesm2022/nanahoshi-mona-ui-popover.mjs +202 -90
  33. package/fesm2022/nanahoshi-mona-ui-popup-menu.mjs +609 -256
  34. package/fesm2022/nanahoshi-mona-ui-popup.mjs +2 -0
  35. package/fesm2022/nanahoshi-mona-ui-sheet.mjs +45 -10
  36. package/fesm2022/nanahoshi-mona-ui-split-button.mjs +102 -58
  37. package/fesm2022/nanahoshi-mona-ui-tooltip.mjs +286 -443
  38. package/fesm2022/nanahoshi-mona-ui-window.mjs +594 -311
  39. package/i18n/catalogs/en-US.messages.json +24 -4
  40. package/locales/ar-sa/ar-sa.messages.json +20 -0
  41. package/locales/de-de/de-de.messages.json +20 -0
  42. package/locales/es-es/es-es.messages.json +20 -0
  43. package/locales/fr-fr/fr-fr.messages.json +20 -0
  44. package/locales/id-id/id-id.messages.json +20 -0
  45. package/locales/it-it/it-it.messages.json +20 -0
  46. package/locales/ja-jp/ja-jp.messages.json +20 -0
  47. package/locales/ko-kr/ko-kr.messages.json +20 -0
  48. package/locales/pt-br/pt-br.messages.json +20 -0
  49. package/locales/ru-ru/ru-ru.messages.json +20 -0
  50. package/locales/tr-tr/tr-tr.messages.json +20 -0
  51. package/locales/zh-cn/zh-cn.messages.json +20 -0
  52. package/locales/zh-tw/zh-tw.messages.json +20 -0
  53. package/package.json +1 -1
  54. package/types/nanahoshi-mona-ui-button-group.d.ts +13 -3
  55. package/types/nanahoshi-mona-ui-button.d.ts +20 -3
  56. package/types/nanahoshi-mona-ui-contextmenu.d.ts +5 -6
  57. package/types/nanahoshi-mona-ui-dialog.d.ts +131 -20
  58. package/types/nanahoshi-mona-ui-dropdown-button.d.ts +75 -56
  59. package/types/nanahoshi-mona-ui-editor.d.ts +118 -21
  60. package/types/nanahoshi-mona-ui-i18n.d.ts +37 -0
  61. package/types/nanahoshi-mona-ui-internal.d.ts +142 -16
  62. package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +20 -0
  63. package/types/nanahoshi-mona-ui-locales-de-de.d.ts +20 -0
  64. package/types/nanahoshi-mona-ui-locales-es-es.d.ts +20 -0
  65. package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +20 -0
  66. package/types/nanahoshi-mona-ui-locales-id-id.d.ts +20 -0
  67. package/types/nanahoshi-mona-ui-locales-it-it.d.ts +20 -0
  68. package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +20 -0
  69. package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +20 -0
  70. package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +20 -0
  71. package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +20 -0
  72. package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +20 -0
  73. package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +20 -0
  74. package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +20 -0
  75. package/types/nanahoshi-mona-ui-menubar.d.ts +65 -62
  76. package/types/nanahoshi-mona-ui-notification.d.ts +76 -16
  77. package/types/nanahoshi-mona-ui-popover.d.ts +44 -17
  78. package/types/nanahoshi-mona-ui-popup-menu.d.ts +110 -32
  79. package/types/nanahoshi-mona-ui-popup.d.ts +2 -0
  80. package/types/nanahoshi-mona-ui-sheet.d.ts +16 -5
  81. package/types/nanahoshi-mona-ui-split-button.d.ts +29 -7
  82. package/types/nanahoshi-mona-ui-tooltip.d.ts +43 -20
  83. package/types/nanahoshi-mona-ui-window.d.ts +103 -14
@@ -1,15 +1,14 @@
1
+ import { Directionality } from '@angular/cdk/bidi';
1
2
  import { NgTemplateOutlet } from '@angular/common';
2
3
  import * as i0 from '@angular/core';
3
- import { Directive, inject, DestroyRef, Renderer2, computed, contentChild, TemplateRef, viewChild, input, output, effect, ElementRef, Component } from '@angular/core';
4
- import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
5
- import { PopupService, fadePopupAnimation } from '@nanahoshi/mona-ui/popup';
6
- import { getPositionConnectionPoints, getOffsetForPosition } from '@nanahoshi/mona-ui/tooltip';
7
- import { takeUntil, take, fromEvent, filter, tap } from 'rxjs';
4
+ import { Directive, inject, DestroyRef, Injector, computed, signal, contentChild, TemplateRef, viewChild, input, output, afterRenderEffect, untracked, effect, afterNextRender, isDevMode, ElementRef, Component } from '@angular/core';
5
+ import { resolveComponentDirection } from '@nanahoshi/mona-ui/i18n';
6
+ import { themeOverlaySurfaceClasses, HoverIntent, createElementControlId, resolveOverlaySide, overlaySidePositions, sideOfPosition, listenForHover } from '@nanahoshi/mona-ui/internal';
7
+ import { PopupService, fadePopupAnimation, PopupCloseSource } from '@nanahoshi/mona-ui/popup';
8
+ import { takeUntil, take } from 'rxjs';
8
9
  import { twMerge } from 'tailwind-merge';
9
- import { v4 } from 'uuid';
10
10
  import { PreventableEvent } from '@nanahoshi/mona-ui/common';
11
11
  import { cva } from 'class-variance-authority';
12
- import { themeOverlaySurfaceClasses } from '@nanahoshi/mona-ui/internal';
13
12
 
14
13
  class PopoverFooterTemplateDirective {
15
14
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: PopoverFooterTemplateDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
@@ -100,16 +99,43 @@ const popoverArrowThemeVariants = cva(`
100
99
  data-[position="right"]:[clip-path:inset(1px_1px_0_0)]
101
100
  `);
102
101
 
102
+ /** Elements that can take focus with Tab, for moving focus into the popover when it opens. */
103
+ const TABBABLE = [
104
+ "a[href]",
105
+ "area[href]",
106
+ "button:not([disabled])",
107
+ "input:not([disabled]):not([type='hidden'])",
108
+ "select:not([disabled])",
109
+ "textarea:not([disabled])",
110
+ "iframe",
111
+ "[contenteditable]:not([contenteditable='false'])",
112
+ "[tabindex]:not([tabindex='-1'])"
113
+ ].join(", ");
103
114
  class PopoverComponent {
104
115
  #destroyRef;
116
+ #directionality;
117
+ #injector;
118
+ #intent;
105
119
  #popupService;
106
- #renderer;
107
- #subscription;
120
+ /** The element that carries the popover's `aria-*` attributes. */
121
+ #ariaTarget;
122
+ #destroyed;
123
+ #popupRef;
108
124
  constructor() {
109
125
  this.#destroyRef = inject(DestroyRef);
126
+ this.#directionality = inject(Directionality, { optional: true });
127
+ this.#injector = inject(Injector);
128
+ this.#intent = new HoverIntent({
129
+ hide: () => this.close(),
130
+ hideDelay: () => 0,
131
+ show: () => this.#openViaTrigger(),
132
+ showDelay: () => 0
133
+ });
110
134
  this.#popupService = inject(PopupService);
111
- this.#renderer = inject(Renderer2);
112
- this.#subscription = null;
135
+ /** The element that carries the popover's `aria-*` attributes. */
136
+ this.#ariaTarget = null;
137
+ this.#destroyed = false;
138
+ this.#popupRef = null;
113
139
  this.arrowClasses = computed(() => {
114
140
  return popoverArrowThemeVariants();
115
141
  }, /* @ts-ignore */
@@ -123,9 +149,11 @@ class PopoverComponent {
123
149
  return popoverContentThemeVariants();
124
150
  }, /* @ts-ignore */
125
151
  ...(ngDevMode ? [{ debugName: "contentClasses" }] : /* istanbul ignore next */ []));
126
- this.currentArrowPosition = computed(() => this.position(), /* @ts-ignore */
152
+ this.currentArrowPosition = signal("top", /* @ts-ignore */
127
153
  ...(ngDevMode ? [{ debugName: "currentArrowPosition" }] : /* istanbul ignore next */ []));
128
154
  this.footerTemplateRef = contentChild(PopoverFooterTemplateDirective, { ...(ngDevMode ? { debugName: "footerTemplateRef" } : /* istanbul ignore next */ {}), read: TemplateRef });
155
+ this.hasTitle = computed(() => !!this.title() || !!this.titleTemplateRef(), /* @ts-ignore */
156
+ ...(ngDevMode ? [{ debugName: "hasTitle" }] : /* istanbul ignore next */ []));
129
157
  this.headerClasses = computed(() => {
130
158
  const rounded = this.rounded();
131
159
  const hasTemplate = !!this.titleTemplateRef();
@@ -134,29 +162,52 @@ class PopoverComponent {
134
162
  return twMerge(variants, padding);
135
163
  }, /* @ts-ignore */
136
164
  ...(ngDevMode ? [{ debugName: "headerClasses" }] : /* istanbul ignore next */ []));
137
- this.headerId = computed(() => this.title() || this.titleTemplateRef() ? `${this.uid}-title` : null, /* @ts-ignore */
165
+ this.headerId = computed(() => (this.hasTitle() ? `${this.uid}-title` : null), /* @ts-ignore */
138
166
  ...(ngDevMode ? [{ debugName: "headerId" }] : /* istanbul ignore next */ []));
139
- this.titleTemplateRef = contentChild(PopoverTitleTemplateDirective, { ...(ngDevMode ? { debugName: "titleTemplateRef" } : /* istanbul ignore next */ {}), read: TemplateRef });
140
167
  this.templateRef = viewChild.required(TemplateRef, /* @ts-ignore */
141
168
  ...(ngDevMode ? [{ debugName: "templateRef" }] : /* istanbul ignore next */ []));
142
- this.uid = v4();
143
- this.popupRef = null;
169
+ this.titleTemplateRef = contentChild(PopoverTitleTemplateDirective, { ...(ngDevMode ? { debugName: "titleTemplateRef" } : /* istanbul ignore next */ {}), read: TemplateRef });
170
+ this.uid = createElementControlId();
171
+ /**
172
+ * @description Accessible name for the popover when it has no `title` or title template.
173
+ */
174
+ this.ariaLabel = input(/* @ts-ignore */
175
+ ...(ngDevMode ? [undefined, { debugName: "ariaLabel" }] : /* istanbul ignore next */ []));
176
+ /**
177
+ * @description Whether focus moves into the popover when it opens: to its first focusable element, or to the
178
+ * popover itself. Defaults to `true`, except for the `hover` trigger.
179
+ */
180
+ this.autoFocus = input(undefined, /* @ts-ignore */
181
+ ...(ngDevMode ? [{ debugName: "autoFocus" }] : /* istanbul ignore next */ []));
182
+ /**
183
+ * @description Whether pressing Escape closes the popover.
184
+ * @default true
185
+ */
186
+ this.closeOnEscape = input(true, /* @ts-ignore */
187
+ ...(ngDevMode ? [{ debugName: "closeOnEscape" }] : /* istanbul ignore next */ []));
188
+ /**
189
+ * @description Whether a click outside the popover and its target closes it.
190
+ * @default true
191
+ */
192
+ this.closeOnOutsideClick = input(true, /* @ts-ignore */
193
+ ...(ngDevMode ? [{ debugName: "closeOnOutsideClick" }] : /* istanbul ignore next */ []));
144
194
  /**
145
195
  * @description Display the arrow of the popover.
146
196
  */
147
197
  this.displayArrow = input(false, /* @ts-ignore */
148
198
  ...(ngDevMode ? [{ debugName: "displayArrow" }] : /* istanbul ignore next */ []));
199
+ /**
200
+ * @description Emits when the popover is hidden.
201
+ */
202
+ this.hidden = output();
149
203
  /**
150
204
  * @description Emits when the popover is about to be closed.
151
205
  * This event is preventable.
152
206
  */
153
207
  this.hide = output();
154
208
  /**
155
- * @description Emits when the popover is hidden.
156
- */
157
- this.hidden = output();
158
- /**
159
- * @description The position of the popover relative to the target element.
209
+ * @description The side of the target the popover opens on. `left` and `right` are physical; `start` and `end`
210
+ * follow the text direction. It flips to the opposite side when there isn't room.
160
211
  */
161
212
  this.position = input("top", /* @ts-ignore */
162
213
  ...(ngDevMode ? [{ debugName: "position" }] : /* istanbul ignore next */ []));
@@ -171,7 +222,7 @@ class PopoverComponent {
171
222
  */
172
223
  this.show = output();
173
224
  /**
174
- * @description Emits when the popover is shown.
225
+ * @description Emits once the popover has opened.
175
226
  */
176
227
  this.shown = output();
177
228
  /**
@@ -186,111 +237,172 @@ class PopoverComponent {
186
237
  ...(ngDevMode ? [{ debugName: "title" }] : /* istanbul ignore next */ []));
187
238
  /**
188
239
  * @description The trigger that opens/closes the popover.
189
- * "click" toggles on click, "hover" opens on pointer enter and closes on
190
- * pointer leave, "none" disables automatic triggering (use `open()`/`close()`
191
- * instead). Any other DOM event name is also accepted and used as-is.
240
+ * "click" toggles on click, "hover" opens while the pointer is on the target or the popover, or focus is on the
241
+ * target, "none" disables automatic triggering (use `open()`/`close()` instead). Any other DOM event name is
242
+ * also accepted and used as-is.
192
243
  */
193
244
  this.trigger = input("click", /* @ts-ignore */
194
245
  ...(ngDevMode ? [{ debugName: "trigger" }] : /* istanbul ignore next */ []));
195
- effect(() => {
196
- if (this.#subscription) {
197
- this.#subscription.unsubscribe();
198
- this.#subscription = null;
199
- }
200
- this.#setSubscriptions();
246
+ // The target says it opens a dialog from the start, and forgets it when it changes or the popover goes.
247
+ // After render, so the target's own host bindings (a monaButton's aria-haspopup) have run and don't undo it.
248
+ afterRenderEffect(onCleanup => {
249
+ const element = this.#elementOf(this.target());
250
+ untracked(() => {
251
+ this.#ariaTarget = element;
252
+ element.setAttribute("aria-haspopup", "dialog");
253
+ element.setAttribute("aria-expanded", this.#popupRef ? "true" : "false");
254
+ });
255
+ onCleanup(() => {
256
+ this.close();
257
+ if (this.#ariaTarget === element) {
258
+ this.#ariaTarget = null;
259
+ }
260
+ element.removeAttribute("aria-haspopup");
261
+ element.removeAttribute("aria-expanded");
262
+ element.removeAttribute("aria-controls");
263
+ });
264
+ });
265
+ effect(onCleanup => {
266
+ const element = this.#elementOf(this.target());
267
+ const trigger = this.trigger();
268
+ const stop = untracked(() => this.#listen(element, trigger));
269
+ onCleanup(() => {
270
+ stop();
271
+ this.#intent.dispose();
272
+ });
273
+ });
274
+ this.#destroyRef.onDestroy(() => {
275
+ // Outputs can't emit once the component is destroyed, so this close is silent and can't be prevented.
276
+ this.#destroyed = true;
277
+ this.close();
201
278
  });
202
279
  }
203
280
  close() {
204
- if (this.popupRef) {
205
- this.popupRef.close();
206
- }
281
+ this.#popupRef?.close();
207
282
  }
208
283
  open() {
209
- if (this.popupRef) {
284
+ if (this.#popupRef) {
210
285
  return;
211
286
  }
212
287
  this.#createPopover();
213
288
  }
214
289
  #createPopover() {
215
- const position = this.position();
216
- const connectionPoints = getPositionConnectionPoints(position);
217
- const offset = getOffsetForPosition(position, this.displayArrow());
218
- const anchor = this.target();
219
- const content = this.templateRef();
220
- const targetElement = this.#popoverTargetElement;
221
- this.popupRef = this.#popupService.create({
222
- anchor,
223
- anchorConnectionPoint: connectionPoints.anchor,
290
+ const targetElement = this.#elementOf(this.target());
291
+ const direction = resolveComponentDirection(targetElement, this.#directionality);
292
+ const side = resolveOverlaySide(this.position(), direction);
293
+ const gap = this.displayArrow() ? 12 : 4;
294
+ this.currentArrowPosition.set(side);
295
+ const popupRef = this.#popupService.create({
296
+ anchor: targetElement,
224
297
  animation: fadePopupAnimation,
225
- closeOnMouseLeave: this.trigger() === "hover",
226
- closeOnOutsideClick: true,
227
- content,
298
+ closeOnEscape: this.closeOnEscape(),
299
+ closeOnMouseLeave: false,
300
+ closeOnOutsideClick: this.closeOnOutsideClick(),
301
+ content: this.templateRef(),
228
302
  hasBackdrop: false,
229
- offset,
230
- popupConnectionPoint: connectionPoints.popup,
303
+ positions: overlaySidePositions(side, gap, direction),
231
304
  withPush: true
232
305
  });
233
- this.#renderer.setAttribute(targetElement, "aria-haspopup", "dialog");
234
- this.#renderer.setAttribute(targetElement, "aria-controls", this.uid);
235
- this.#renderer.setAttribute(targetElement, "aria-expanded", "true");
236
- this.popupRef.beforeClose.pipe(takeUntil(this.popupRef.closed)).subscribe(event => {
237
- const hideEvent = new PopoverHideEvent(this.#popoverTargetElement, this.popupRef);
306
+ this.#popupRef = popupRef;
307
+ targetElement.setAttribute("aria-controls", this.uid);
308
+ targetElement.setAttribute("aria-expanded", "true");
309
+ if (this.trigger() === "hover") {
310
+ this.#intent.opened(targetElement, popupRef.overlayRef.overlayElement);
311
+ }
312
+ popupRef.positionChanges.pipe(takeUntil(popupRef.closeStart)).subscribe(position => {
313
+ this.currentArrowPosition.set(sideOfPosition(position, direction));
314
+ });
315
+ popupRef.beforeClose.pipe(takeUntil(popupRef.closed)).subscribe(event => {
316
+ if (this.#destroyed) {
317
+ return;
318
+ }
319
+ const hideEvent = new PopoverHideEvent(targetElement, popupRef);
238
320
  this.hide.emit(hideEvent);
239
321
  if (hideEvent.isDefaultPrevented()) {
240
322
  event.preventDefault();
241
- return;
242
323
  }
243
324
  });
244
- this.popupRef.closed.pipe(take(1)).subscribe(() => {
245
- this.popupRef = null;
246
- this.#renderer.setAttribute(targetElement, "aria-expanded", "false");
247
- this.hidden.emit();
325
+ popupRef.opened.pipe(take(1)).subscribe(() => {
326
+ if (!this.#destroyed) {
327
+ this.shown.emit(new PopoverShownEvent(targetElement, popupRef));
328
+ }
329
+ });
330
+ popupRef.closeStart.pipe(take(1)).subscribe(event => {
331
+ this.#intent.closed(targetElement, event.via === PopupCloseSource.Escape);
332
+ });
333
+ popupRef.closed.pipe(take(1)).subscribe(() => {
334
+ if (this.#popupRef === popupRef) {
335
+ this.#popupRef = null;
336
+ }
337
+ targetElement.removeAttribute("aria-controls");
338
+ if (this.#ariaTarget === targetElement) {
339
+ targetElement.setAttribute("aria-expanded", "false");
340
+ }
341
+ if (!this.#destroyed) {
342
+ this.hidden.emit();
343
+ }
248
344
  });
345
+ afterNextRender({
346
+ write: () => {
347
+ const panel = popupRef.overlayRef.overlayElement.querySelector('[role="dialog"]');
348
+ if (!panel || this.#popupRef !== popupRef) {
349
+ return;
350
+ }
351
+ if (isDevMode() && !this.hasTitle() && !this.ariaLabel()) {
352
+ console.warn("[Mona Popover] A popover needs an accessible name. Set title, a title template or ariaLabel.", panel);
353
+ }
354
+ if (this.autoFocus() ?? this.trigger() !== "hover") {
355
+ const first = panel.querySelector(TABBABLE);
356
+ (first ?? panel).focus({ preventScroll: true });
357
+ }
358
+ }
359
+ }, { injector: this.#injector });
249
360
  }
250
- #openViaTrigger() {
251
- const showEvent = new PopoverShowEvent(this.#popoverTargetElement);
252
- this.show.emit(showEvent);
253
- if (showEvent.isDefaultPrevented()) {
254
- return;
255
- }
256
- this.#createPopover();
257
- if (this.popupRef) {
258
- const shownEvent = new PopoverShownEvent(this.#popoverTargetElement, this.popupRef);
259
- this.shown.emit(shownEvent);
260
- }
361
+ #elementOf(target) {
362
+ return target instanceof ElementRef ? target.nativeElement : target;
261
363
  }
262
- #setSubscriptions() {
263
- const trigger = this.trigger();
364
+ #listen(element, trigger) {
264
365
  if (trigger === "none") {
265
- return;
366
+ return () => undefined;
266
367
  }
267
368
  if (trigger === "hover") {
268
- this.#subscription = fromEvent(this.#popoverTargetElement, "pointerenter")
269
- .pipe(filter(() => !this.popupRef), tap(() => this.#openViaTrigger()), takeUntilDestroyed(this.#destroyRef))
270
- .subscribe();
271
- return;
369
+ return element instanceof HTMLElement
370
+ ? listenForHover(element, node => (element.contains(node) ? element : null), this.#intent)
371
+ : () => undefined;
272
372
  }
273
- this.#subscription = fromEvent(this.#popoverTargetElement, trigger)
274
- .pipe(tap(event => event.preventDefault()), filter(() => {
275
- if (this.popupRef) {
373
+ const handler = (event) => {
374
+ // The browser's own menu would cover a popover opened from it; other events keep their default action.
375
+ if (trigger === "contextmenu") {
376
+ event.preventDefault();
377
+ }
378
+ if (this.#popupRef) {
276
379
  this.close();
277
- return false;
278
380
  }
279
- return true;
280
- }), tap(() => this.#openViaTrigger()), takeUntilDestroyed(this.#destroyRef))
281
- .subscribe();
381
+ else {
382
+ this.#openViaTrigger();
383
+ }
384
+ };
385
+ element.addEventListener(trigger, handler);
386
+ return () => element.removeEventListener(trigger, handler);
282
387
  }
283
- get #popoverTargetElement() {
284
- const target = this.target();
285
- return target instanceof ElementRef ? target.nativeElement : target;
388
+ #openViaTrigger() {
389
+ if (this.#popupRef || this.#destroyed) {
390
+ return;
391
+ }
392
+ const showEvent = new PopoverShowEvent(this.#elementOf(this.target()));
393
+ this.show.emit(showEvent);
394
+ if (showEvent.isDefaultPrevented()) {
395
+ return;
396
+ }
397
+ this.#createPopover();
286
398
  }
287
399
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: PopoverComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
288
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: PopoverComponent, isStandalone: true, selector: "mona-popover", inputs: { displayArrow: { classPropertyName: "displayArrow", publicName: "displayArrow", isSignal: true, isRequired: false, transformFunction: null }, position: { classPropertyName: "position", publicName: "position", isSignal: true, isRequired: false, transformFunction: null }, rounded: { classPropertyName: "rounded", publicName: "rounded", isSignal: true, isRequired: false, transformFunction: null }, target: { classPropertyName: "target", publicName: "target", isSignal: true, isRequired: true, transformFunction: null }, title: { classPropertyName: "title", publicName: "title", isSignal: true, isRequired: false, transformFunction: null }, trigger: { classPropertyName: "trigger", publicName: "trigger", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { hide: "hide", hidden: "hidden", show: "show", shown: "shown" }, queries: [{ propertyName: "footerTemplateRef", first: true, predicate: PopoverFooterTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "titleTemplateRef", first: true, predicate: PopoverTitleTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }], viewQueries: [{ propertyName: "templateRef", first: true, predicate: TemplateRef, descendants: true, isSignal: true }], exportAs: ["monaPopover"], ngImport: i0, template: "<ng-template>\n <div [class]=\"baseClasses()\" [id]=\"uid\" role=\"dialog\" [attr.aria-labelledby]=\"headerId()\" [attr.data-uid]=\"uid\">\n <div>\n @if (title() || titleTemplateRef()) {\n <div [class]=\"headerClasses()\" [id]=\"headerId()\">\n @if (titleTemplateRef()) {\n <ng-container [ngTemplateOutlet]=\"titleTemplateRef()\"></ng-container>\n } @else {\n <span>{{ title() }}</span>\n }\n </div>\n }\n <div [class]=\"contentClasses()\">\n <ng-content></ng-content>\n </div>\n @if (footerTemplateRef()) {\n <div class=\"mona-popover-footer\">\n <ng-container [ngTemplateOutlet]=\"footerTemplateRef()\"></ng-container>\n </div>\n }\n </div>\n @if (displayArrow()) {\n <div [class]=\"arrowClasses()\" [attr.data-position]=\"currentArrowPosition()\"></div>\n }\n </div>\n</ng-template>\n", dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }] }); }
400
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: PopoverComponent, isStandalone: true, selector: "mona-popover", inputs: { ariaLabel: { classPropertyName: "ariaLabel", publicName: "ariaLabel", isSignal: true, isRequired: false, transformFunction: null }, autoFocus: { classPropertyName: "autoFocus", publicName: "autoFocus", isSignal: true, isRequired: false, transformFunction: null }, closeOnEscape: { classPropertyName: "closeOnEscape", publicName: "closeOnEscape", isSignal: true, isRequired: false, transformFunction: null }, closeOnOutsideClick: { classPropertyName: "closeOnOutsideClick", publicName: "closeOnOutsideClick", isSignal: true, isRequired: false, transformFunction: null }, displayArrow: { classPropertyName: "displayArrow", publicName: "displayArrow", isSignal: true, isRequired: false, transformFunction: null }, position: { classPropertyName: "position", publicName: "position", isSignal: true, isRequired: false, transformFunction: null }, rounded: { classPropertyName: "rounded", publicName: "rounded", isSignal: true, isRequired: false, transformFunction: null }, target: { classPropertyName: "target", publicName: "target", isSignal: true, isRequired: true, transformFunction: null }, title: { classPropertyName: "title", publicName: "title", isSignal: true, isRequired: false, transformFunction: null }, trigger: { classPropertyName: "trigger", publicName: "trigger", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { hidden: "hidden", hide: "hide", show: "show", shown: "shown" }, queries: [{ propertyName: "footerTemplateRef", first: true, predicate: PopoverFooterTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "titleTemplateRef", first: true, predicate: PopoverTitleTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }], viewQueries: [{ propertyName: "templateRef", first: true, predicate: TemplateRef, descendants: true, isSignal: true }], exportAs: ["monaPopover"], ngImport: i0, template: "<ng-template>\n <div\n [class]=\"baseClasses()\"\n [id]=\"uid\"\n role=\"dialog\"\n tabindex=\"-1\"\n [attr.aria-labelledby]=\"headerId()\"\n [attr.aria-label]=\"hasTitle() ? null : ariaLabel() || null\"\n [attr.data-uid]=\"uid\">\n <div>\n @if (hasTitle()) {\n <div [class]=\"headerClasses()\" [id]=\"headerId()\">\n @if (titleTemplateRef()) {\n <ng-container [ngTemplateOutlet]=\"titleTemplateRef()\"></ng-container>\n } @else {\n <span>{{ title() }}</span>\n }\n </div>\n }\n <div [class]=\"contentClasses()\">\n <ng-content></ng-content>\n </div>\n @if (footerTemplateRef()) {\n <div class=\"mona-popover-footer\">\n <ng-container [ngTemplateOutlet]=\"footerTemplateRef()\"></ng-container>\n </div>\n }\n </div>\n @if (displayArrow()) {\n <div [class]=\"arrowClasses()\" [attr.data-position]=\"currentArrowPosition()\"></div>\n }\n </div>\n</ng-template>\n", dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }] }); }
289
401
  }
290
402
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: PopoverComponent, decorators: [{
291
403
  type: Component,
292
- args: [{ selector: "mona-popover", exportAs: "monaPopover", imports: [NgTemplateOutlet], template: "<ng-template>\n <div [class]=\"baseClasses()\" [id]=\"uid\" role=\"dialog\" [attr.aria-labelledby]=\"headerId()\" [attr.data-uid]=\"uid\">\n <div>\n @if (title() || titleTemplateRef()) {\n <div [class]=\"headerClasses()\" [id]=\"headerId()\">\n @if (titleTemplateRef()) {\n <ng-container [ngTemplateOutlet]=\"titleTemplateRef()\"></ng-container>\n } @else {\n <span>{{ title() }}</span>\n }\n </div>\n }\n <div [class]=\"contentClasses()\">\n <ng-content></ng-content>\n </div>\n @if (footerTemplateRef()) {\n <div class=\"mona-popover-footer\">\n <ng-container [ngTemplateOutlet]=\"footerTemplateRef()\"></ng-container>\n </div>\n }\n </div>\n @if (displayArrow()) {\n <div [class]=\"arrowClasses()\" [attr.data-position]=\"currentArrowPosition()\"></div>\n }\n </div>\n</ng-template>\n" }]
293
- }], ctorParameters: () => [], propDecorators: { footerTemplateRef: [{ type: i0.ContentChild, args: [i0.forwardRef(() => PopoverFooterTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], titleTemplateRef: [{ type: i0.ContentChild, args: [i0.forwardRef(() => PopoverTitleTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], templateRef: [{ type: i0.ViewChild, args: [i0.forwardRef(() => TemplateRef), { isSignal: true }] }], displayArrow: [{ type: i0.Input, args: [{ isSignal: true, alias: "displayArrow", required: false }] }], hide: [{ type: i0.Output, args: ["hide"] }], hidden: [{ type: i0.Output, args: ["hidden"] }], position: [{ type: i0.Input, args: [{ isSignal: true, alias: "position", required: false }] }], rounded: [{ type: i0.Input, args: [{ isSignal: true, alias: "rounded", required: false }] }], show: [{ type: i0.Output, args: ["show"] }], shown: [{ type: i0.Output, args: ["shown"] }], target: [{ type: i0.Input, args: [{ isSignal: true, alias: "target", required: true }] }], title: [{ type: i0.Input, args: [{ isSignal: true, alias: "title", required: false }] }], trigger: [{ type: i0.Input, args: [{ isSignal: true, alias: "trigger", required: false }] }] } });
404
+ args: [{ selector: "mona-popover", exportAs: "monaPopover", imports: [NgTemplateOutlet], template: "<ng-template>\n <div\n [class]=\"baseClasses()\"\n [id]=\"uid\"\n role=\"dialog\"\n tabindex=\"-1\"\n [attr.aria-labelledby]=\"headerId()\"\n [attr.aria-label]=\"hasTitle() ? null : ariaLabel() || null\"\n [attr.data-uid]=\"uid\">\n <div>\n @if (hasTitle()) {\n <div [class]=\"headerClasses()\" [id]=\"headerId()\">\n @if (titleTemplateRef()) {\n <ng-container [ngTemplateOutlet]=\"titleTemplateRef()\"></ng-container>\n } @else {\n <span>{{ title() }}</span>\n }\n </div>\n }\n <div [class]=\"contentClasses()\">\n <ng-content></ng-content>\n </div>\n @if (footerTemplateRef()) {\n <div class=\"mona-popover-footer\">\n <ng-container [ngTemplateOutlet]=\"footerTemplateRef()\"></ng-container>\n </div>\n }\n </div>\n @if (displayArrow()) {\n <div [class]=\"arrowClasses()\" [attr.data-position]=\"currentArrowPosition()\"></div>\n }\n </div>\n</ng-template>\n" }]
405
+ }], ctorParameters: () => [], propDecorators: { footerTemplateRef: [{ type: i0.ContentChild, args: [i0.forwardRef(() => PopoverFooterTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], templateRef: [{ type: i0.ViewChild, args: [i0.forwardRef(() => TemplateRef), { isSignal: true }] }], titleTemplateRef: [{ type: i0.ContentChild, args: [i0.forwardRef(() => PopoverTitleTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaLabel", required: false }] }], autoFocus: [{ type: i0.Input, args: [{ isSignal: true, alias: "autoFocus", required: false }] }], closeOnEscape: [{ type: i0.Input, args: [{ isSignal: true, alias: "closeOnEscape", required: false }] }], closeOnOutsideClick: [{ type: i0.Input, args: [{ isSignal: true, alias: "closeOnOutsideClick", required: false }] }], displayArrow: [{ type: i0.Input, args: [{ isSignal: true, alias: "displayArrow", required: false }] }], hidden: [{ type: i0.Output, args: ["hidden"] }], hide: [{ type: i0.Output, args: ["hide"] }], position: [{ type: i0.Input, args: [{ isSignal: true, alias: "position", required: false }] }], rounded: [{ type: i0.Input, args: [{ isSignal: true, alias: "rounded", required: false }] }], show: [{ type: i0.Output, args: ["show"] }], shown: [{ type: i0.Output, args: ["shown"] }], target: [{ type: i0.Input, args: [{ isSignal: true, alias: "target", required: true }] }], title: [{ type: i0.Input, args: [{ isSignal: true, alias: "title", required: false }] }], trigger: [{ type: i0.Input, args: [{ isSignal: true, alias: "trigger", required: false }] }] } });
294
406
 
295
407
  /*
296
408
  * Public API Surface of @nanahoshi/mona-ui/popover