@nanahoshi/mona-ui 0.24.7 → 0.24.9

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 (97) hide show
  1. package/fesm2022/nanahoshi-mona-ui-auto-complete.mjs +1 -1
  2. package/fesm2022/nanahoshi-mona-ui-button-group.mjs +37 -9
  3. package/fesm2022/nanahoshi-mona-ui-button.mjs +8 -2
  4. package/fesm2022/nanahoshi-mona-ui-color-gradient.mjs +4 -3
  5. package/fesm2022/nanahoshi-mona-ui-combo-box.mjs +1 -1
  6. package/fesm2022/nanahoshi-mona-ui-contextmenu.mjs +101 -47
  7. package/fesm2022/nanahoshi-mona-ui-dialog.mjs +339 -101
  8. package/fesm2022/nanahoshi-mona-ui-dropdown-button.mjs +119 -69
  9. package/fesm2022/nanahoshi-mona-ui-dropdown-list.mjs +1 -1
  10. package/fesm2022/nanahoshi-mona-ui-editor.mjs +2 -2
  11. package/fesm2022/{nanahoshi-mona-ui-grid-grid-footer-row.component-vXXNWmEN.mjs → nanahoshi-mona-ui-grid-grid-footer-row.component-DhKLnW06.mjs} +2 -2
  12. package/fesm2022/{nanahoshi-mona-ui-grid-grid-list.component-DDgNmgE0.mjs → nanahoshi-mona-ui-grid-grid-list.component-voGbKOiB.mjs} +4 -4
  13. package/fesm2022/{nanahoshi-mona-ui-grid-grid-row.component-Dzf6Vbs_.mjs → nanahoshi-mona-ui-grid-grid-row.component-HQ1Kv6R9.mjs} +2 -3
  14. package/fesm2022/{nanahoshi-mona-ui-grid-grid-virtual-list.component-DAPNqnWV.mjs → nanahoshi-mona-ui-grid-grid-virtual-list.component-PNLJFcuH.mjs} +4 -4
  15. package/fesm2022/{nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-B9rmDLq8.mjs → nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-BO19AVwC.mjs} +10 -10
  16. package/fesm2022/nanahoshi-mona-ui-grid.mjs +1 -1
  17. package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +44 -3
  18. package/fesm2022/nanahoshi-mona-ui-internal-filter-input.mjs +20 -4
  19. package/fesm2022/nanahoshi-mona-ui-internal-list.mjs +335 -45
  20. package/fesm2022/nanahoshi-mona-ui-internal-tree.mjs +565 -197
  21. package/fesm2022/nanahoshi-mona-ui-internal.mjs +465 -23
  22. package/fesm2022/nanahoshi-mona-ui-list-box.mjs +598 -208
  23. package/fesm2022/nanahoshi-mona-ui-list-view.mjs +193 -71
  24. package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +29 -3
  25. package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +33 -3
  26. package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +33 -3
  27. package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +40 -3
  28. package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +29 -3
  29. package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +33 -3
  30. package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +29 -3
  31. package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +29 -3
  32. package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +33 -3
  33. package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +49 -3
  34. package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +29 -3
  35. package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +29 -3
  36. package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +29 -3
  37. package/fesm2022/nanahoshi-mona-ui-menubar.mjs +127 -133
  38. package/fesm2022/nanahoshi-mona-ui-multi-select.mjs +1 -1
  39. package/fesm2022/nanahoshi-mona-ui-notification.mjs +473 -240
  40. package/fesm2022/nanahoshi-mona-ui-popover.mjs +202 -90
  41. package/fesm2022/nanahoshi-mona-ui-popup-menu.mjs +609 -256
  42. package/fesm2022/nanahoshi-mona-ui-popup.mjs +2 -0
  43. package/fesm2022/nanahoshi-mona-ui-sheet.mjs +45 -10
  44. package/fesm2022/nanahoshi-mona-ui-split-button.mjs +102 -58
  45. package/fesm2022/nanahoshi-mona-ui-tooltip.mjs +286 -443
  46. package/fesm2022/nanahoshi-mona-ui-tree-view.mjs +205 -140
  47. package/fesm2022/nanahoshi-mona-ui-window.mjs +591 -310
  48. package/i18n/catalogs/en-US.messages.json +32 -6
  49. package/locales/ar-sa/ar-sa.messages.json +29 -3
  50. package/locales/de-de/de-de.messages.json +29 -3
  51. package/locales/es-es/es-es.messages.json +29 -3
  52. package/locales/fr-fr/fr-fr.messages.json +29 -3
  53. package/locales/id-id/id-id.messages.json +29 -3
  54. package/locales/it-it/it-it.messages.json +29 -3
  55. package/locales/ja-jp/ja-jp.messages.json +29 -3
  56. package/locales/ko-kr/ko-kr.messages.json +29 -3
  57. package/locales/pt-br/pt-br.messages.json +29 -3
  58. package/locales/ru-ru/ru-ru.messages.json +29 -3
  59. package/locales/tr-tr/tr-tr.messages.json +29 -3
  60. package/locales/zh-cn/zh-cn.messages.json +29 -3
  61. package/locales/zh-tw/zh-tw.messages.json +29 -3
  62. package/package.json +1 -1
  63. package/types/nanahoshi-mona-ui-button-group.d.ts +13 -3
  64. package/types/nanahoshi-mona-ui-button.d.ts +20 -3
  65. package/types/nanahoshi-mona-ui-contextmenu.d.ts +5 -6
  66. package/types/nanahoshi-mona-ui-dialog.d.ts +131 -20
  67. package/types/nanahoshi-mona-ui-dropdown-button.d.ts +75 -56
  68. package/types/nanahoshi-mona-ui-i18n.d.ts +69 -0
  69. package/types/nanahoshi-mona-ui-internal-filter-input.d.ts +14 -2
  70. package/types/nanahoshi-mona-ui-internal-list.d.ts +89 -10
  71. package/types/nanahoshi-mona-ui-internal-tree.d.ts +155 -40
  72. package/types/nanahoshi-mona-ui-internal.d.ts +128 -16
  73. package/types/nanahoshi-mona-ui-list-box.d.ts +148 -47
  74. package/types/nanahoshi-mona-ui-list-view.d.ts +112 -21
  75. package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +26 -0
  76. package/types/nanahoshi-mona-ui-locales-de-de.d.ts +26 -0
  77. package/types/nanahoshi-mona-ui-locales-es-es.d.ts +26 -0
  78. package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +26 -0
  79. package/types/nanahoshi-mona-ui-locales-id-id.d.ts +26 -0
  80. package/types/nanahoshi-mona-ui-locales-it-it.d.ts +26 -0
  81. package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +26 -0
  82. package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +26 -0
  83. package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +26 -0
  84. package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +26 -0
  85. package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +26 -0
  86. package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +26 -0
  87. package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +26 -0
  88. package/types/nanahoshi-mona-ui-menubar.d.ts +65 -62
  89. package/types/nanahoshi-mona-ui-notification.d.ts +76 -16
  90. package/types/nanahoshi-mona-ui-popover.d.ts +44 -17
  91. package/types/nanahoshi-mona-ui-popup-menu.d.ts +110 -32
  92. package/types/nanahoshi-mona-ui-popup.d.ts +2 -0
  93. package/types/nanahoshi-mona-ui-sheet.d.ts +16 -5
  94. package/types/nanahoshi-mona-ui-split-button.d.ts +29 -7
  95. package/types/nanahoshi-mona-ui-tooltip.d.ts +43 -20
  96. package/types/nanahoshi-mona-ui-tree-view.d.ts +84 -40
  97. package/types/nanahoshi-mona-ui-window.d.ts +103 -14
@@ -1,15 +1,26 @@
1
+ import { Directionality } from '@angular/cdk/bidi';
1
2
  import * as i0 from '@angular/core';
2
- import { inject, DestroyRef, computed, signal, TemplateRef, viewChild, ViewContainerRef, input, afterNextRender, Component, ApplicationRef, DOCUMENT as DOCUMENT$1, createComponent, Injectable } from '@angular/core';
3
- import { interval, takeWhile, asyncScheduler, Subject, take } from 'rxjs';
4
- import { v4 } from 'uuid';
3
+ import { InjectionToken, inject, DestroyRef, signal, ElementRef, Injector, computed, TemplateRef, viewChild, ViewContainerRef, untracked, input, effect, afterRenderEffect, afterNextRender, Component, ApplicationRef, DOCUMENT as DOCUMENT$1, createComponent, Injectable, makeEnvironmentProviders } from '@angular/core';
4
+ import { MonaI18nService } from '@nanahoshi/mona-ui/i18n';
5
+ import { themeOverlaySurfaceClasses, createElementControlId } from '@nanahoshi/mona-ui/internal';
5
6
  import { cva } from 'class-variance-authority';
6
- import { themeOverlaySurfaceClasses } from '@nanahoshi/mona-ui/internal';
7
+ import { LiveAnnouncer } from '@angular/cdk/a11y';
7
8
  import { DOCUMENT, NgTemplateOutlet } from '@angular/common';
8
- import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
9
9
  import { LucideOctagonX, LucideBadgeInfo, LucideCircleCheckBig, LucideOctagonAlert, LucideX } from '@lucide/angular';
10
10
  import { ButtonDirective } from '@nanahoshi/mona-ui/button';
11
- import { MonaI18nService } from '@nanahoshi/mona-ui/i18n';
12
11
  import { ProgressBarComponent } from '@nanahoshi/mona-ui/progress-bar';
12
+ import { Subject } from 'rxjs';
13
+
14
+ // Generated from i18n/catalogs/en-US.messages.json by scripts/generate-locale-catalogs.ts. Do not edit.
15
+ // Edit the JSON file and run `npm run generate:locale-catalogs`.
16
+ const NOTIFICATION_DEFAULT_MESSAGES = {
17
+ close: "Close",
18
+ error: "Error",
19
+ info: "Info",
20
+ region: "Notifications",
21
+ success: "Success",
22
+ warning: "Warning"
23
+ };
13
24
 
14
25
  //---------------------------------
15
26
  // Notification Container Component
@@ -73,37 +84,93 @@ const notificationTextThemeVariants = cva(`
73
84
  text-sm text-foreground
74
85
  `);
75
86
 
76
- // Generated from i18n/catalogs/en-US.messages.json by scripts/generate-locale-catalogs.ts. Do not edit.
77
- // Edit the JSON file and run `npm run generate:locale-catalogs`.
78
- const NOTIFICATION_DEFAULT_MESSAGES = {
79
- close: "Close",
80
- error: "Error",
81
- info: "Info",
82
- success: "Success",
83
- warning: "Warning"
87
+ /** The defaults used when nothing is provided with `provideNotificationDefaults()`. */
88
+ const DEFAULT_NOTIFICATION_DEFAULTS = {
89
+ autoHide: true,
90
+ durationScale: 1,
91
+ pauseOnWindowBlur: true
84
92
  };
93
+ /**
94
+ * @description Application-wide notification settings. Provide them with `provideNotificationDefaults()`.
95
+ */
96
+ const NOTIFICATION_DEFAULTS = new InjectionToken("Mona UI notification defaults", {
97
+ providedIn: "root",
98
+ factory: () => DEFAULT_NOTIFICATION_DEFAULTS
99
+ });
100
+ /**
101
+ * @description The `data` given in the notification's options, for a content component or template to inject.
102
+ */
103
+ const NOTIFICATION_DATA = new InjectionToken("Mona UI notification data");
104
+ /**
105
+ * @description The reference of the notification a content component or template is shown in.
106
+ */
107
+ const NOTIFICATION_REF = new InjectionToken("Mona UI notification reference");
85
108
 
109
+ /** Elements that can take focus with Tab, for moving focus to another notification. */
110
+ const TABBABLE = [
111
+ "a[href]",
112
+ "button:not([disabled])",
113
+ "input:not([disabled]):not([type='hidden'])",
114
+ "select:not([disabled])",
115
+ "textarea:not([disabled])",
116
+ "[tabindex]:not([tabindex='-1'])"
117
+ ].join(", ");
118
+ /** How long closing waits for the leave animation before removing the notification anyway. */
119
+ const LEAVE_FALLBACK = 1000;
120
+ /**
121
+ * Where focus goes back to once a notification closes, by notification element. Focus handed from one notification
122
+ * to the next keeps the place it first came from.
123
+ */
124
+ const RETURN_FOCUS = new WeakMap();
86
125
  class NotificationComponent {
126
+ #announcer;
127
+ #defaults;
87
128
  #destroyRef;
88
129
  #document;
130
+ #focused;
131
+ #host;
132
+ #hovered;
89
133
  #i18n;
134
+ #injector;
90
135
  #isUrgent;
91
- #paused;
136
+ /** Whether the countdown runs: there is one, and nothing pauses it. */
137
+ #running;
138
+ #windowBlurred;
139
+ #closeTimer;
140
+ #progressTimer;
141
+ #remaining;
142
+ #startedAt;
92
143
  constructor() {
144
+ this.#announcer = inject(LiveAnnouncer);
145
+ this.#defaults = inject(NOTIFICATION_DEFAULTS);
93
146
  this.#destroyRef = inject(DestroyRef);
94
147
  this.#document = inject(DOCUMENT);
148
+ this.#focused = signal(false, /* @ts-ignore */
149
+ ...(ngDevMode ? [{ debugName: "#focused" }] : /* istanbul ignore next */ []));
150
+ this.#host = inject(ElementRef);
151
+ this.#hovered = signal(false, /* @ts-ignore */
152
+ ...(ngDevMode ? [{ debugName: "#hovered" }] : /* istanbul ignore next */ []));
95
153
  this.#i18n = inject(MonaI18nService);
154
+ this.#injector = inject(Injector);
96
155
  this.#isUrgent = computed(() => this.type() === "error" || this.type() === "warning", /* @ts-ignore */
97
156
  ...(ngDevMode ? [{ debugName: "#isUrgent" }] : /* istanbul ignore next */ []));
98
- this.#paused = signal(false, /* @ts-ignore */
99
- ...(ngDevMode ? [{ debugName: "#paused" }] : /* istanbul ignore next */ []));
100
- this.messages = this.#i18n.componentMessages("notification", NOTIFICATION_DEFAULT_MESSAGES);
157
+ /** Whether the countdown runs: there is one, and nothing pauses it. */
158
+ this.#running = computed(() => this.options().duration != null &&
159
+ !this.data().closing() &&
160
+ !this.#hovered() &&
161
+ !this.#focused() &&
162
+ !this.#windowBlurred(), /* @ts-ignore */
163
+ ...(ngDevMode ? [{ debugName: "#running" }] : /* istanbul ignore next */ []));
164
+ this.#windowBlurred = signal(false, /* @ts-ignore */
165
+ ...(ngDevMode ? [{ debugName: "#windowBlurred" }] : /* istanbul ignore next */ []));
166
+ this.#closeTimer = null;
167
+ this.#progressTimer = null;
168
+ this.#remaining = null;
169
+ this.#startedAt = 0;
101
170
  this.actionClass = computed(() => {
102
171
  return notificationActionThemeVariants();
103
172
  }, /* @ts-ignore */
104
173
  ...(ngDevMode ? [{ debugName: "actionClass" }] : /* istanbul ignore next */ []));
105
- this.ariaLive = computed(() => (this.#isUrgent() ? "assertive" : "polite"), /* @ts-ignore */
106
- ...(ngDevMode ? [{ debugName: "ariaLive" }] : /* istanbul ignore next */ []));
107
174
  this.baseClass = computed(() => {
108
175
  return notificationBaseThemeVariants();
109
176
  }, /* @ts-ignore */
@@ -113,7 +180,7 @@ class NotificationComponent {
113
180
  }, /* @ts-ignore */
114
181
  ...(ngDevMode ? [{ debugName: "bodyClass" }] : /* istanbul ignore next */ []));
115
182
  this.closeTitle = computed(() => {
116
- return this.data().options.closeTitle ?? this.messages().close;
183
+ return this.options().closeTitle ?? this.messages().close;
117
184
  }, /* @ts-ignore */
118
185
  ...(ngDevMode ? [{ debugName: "closeTitle" }] : /* istanbul ignore next */ []));
119
186
  this.contentClass = computed(() => {
@@ -121,16 +188,28 @@ class NotificationComponent {
121
188
  }, /* @ts-ignore */
122
189
  ...(ngDevMode ? [{ debugName: "contentClass" }] : /* istanbul ignore next */ []));
123
190
  this.contentComponent = computed(() => {
124
- const content = this.data().options.content;
191
+ const content = this.options().content;
125
192
  return typeof content !== "string" && !(content instanceof TemplateRef) ? content : null;
126
193
  }, /* @ts-ignore */
127
194
  ...(ngDevMode ? [{ debugName: "contentComponent" }] : /* istanbul ignore next */ []));
195
+ this.contentHost = viewChild("contentHost", { ...(ngDevMode ? { debugName: "contentHost" } : /* istanbul ignore next */ {}), read: ViewContainerRef });
196
+ /** Gives a content component or template the notification's reference and data. */
197
+ this.contentInjector = computed(() => {
198
+ const data = this.data();
199
+ return Injector.create({
200
+ parent: this.#injector,
201
+ providers: [
202
+ { provide: NOTIFICATION_REF, useValue: data.ref },
203
+ { provide: NOTIFICATION_DATA, useValue: untracked(() => data.options().data) }
204
+ ]
205
+ });
206
+ }, /* @ts-ignore */
207
+ ...(ngDevMode ? [{ debugName: "contentInjector" }] : /* istanbul ignore next */ []));
128
208
  this.contentTemplate = computed(() => {
129
- const content = this.data().options.content;
209
+ const content = this.options().content;
130
210
  return content instanceof TemplateRef ? content : null;
131
211
  }, /* @ts-ignore */
132
212
  ...(ngDevMode ? [{ debugName: "contentTemplate" }] : /* istanbul ignore next */ []));
133
- this.contentHost = viewChild("contentHost", { ...(ngDevMode ? { debugName: "contentHost" } : /* istanbul ignore next */ {}), read: ViewContainerRef });
134
213
  this.headerClass = computed(() => {
135
214
  return notificationHeaderThemeVariants();
136
215
  }, /* @ts-ignore */
@@ -140,76 +219,228 @@ class NotificationComponent {
140
219
  return notificationIconThemeVariants({ type });
141
220
  }, /* @ts-ignore */
142
221
  ...(ngDevMode ? [{ debugName: "iconClass" }] : /* istanbul ignore next */ []));
143
- this.isStringContent = computed(() => typeof this.data().options.content === "string", /* @ts-ignore */
144
- ...(ngDevMode ? [{ debugName: "isStringContent" }] : /* istanbul ignore next */ []));
145
- this.progressColor = computed(() => {
146
- const type = this.type();
147
- const propertyName = `--color-${type}`;
148
- return getComputedStyle(this.#document.documentElement).getPropertyValue(propertyName);
149
- }, /* @ts-ignore */
222
+ this.messageElement = viewChild("message", /* @ts-ignore */
223
+ ...(ngDevMode ? [{ debugName: "messageElement" }] : /* istanbul ignore next */ []));
224
+ this.messages = this.#i18n.componentMessages("notification", NOTIFICATION_DEFAULT_MESSAGES);
225
+ this.options = computed(() => this.data().options(), /* @ts-ignore */
226
+ ...(ngDevMode ? [{ debugName: "options" }] : /* istanbul ignore next */ []));
227
+ /** A theme color through its variable, so it follows a theme switch. */
228
+ this.progressColor = computed(() => `var(--color-${this.type()})`, /* @ts-ignore */
150
229
  ...(ngDevMode ? [{ debugName: "progressColor" }] : /* istanbul ignore next */ []));
151
230
  this.progressValue = signal(100, /* @ts-ignore */
152
231
  ...(ngDevMode ? [{ debugName: "progressValue" }] : /* istanbul ignore next */ []));
153
- this.role = computed(() => (this.#isUrgent() ? "alert" : "status"), /* @ts-ignore */
154
- ...(ngDevMode ? [{ debugName: "role" }] : /* istanbul ignore next */ []));
232
+ this.stringContent = computed(() => {
233
+ const content = this.options().content;
234
+ return typeof content === "string" ? content : null;
235
+ }, /* @ts-ignore */
236
+ ...(ngDevMode ? [{ debugName: "stringContent" }] : /* istanbul ignore next */ []));
237
+ this.templateContext = computed(() => ({
238
+ $implicit: this.data().ref,
239
+ data: this.options().data
240
+ }), /* @ts-ignore */
241
+ ...(ngDevMode ? [{ debugName: "templateContext" }] : /* istanbul ignore next */ []));
155
242
  this.textClass = computed(() => {
156
243
  return notificationTextThemeVariants();
157
244
  }, /* @ts-ignore */
158
245
  ...(ngDevMode ? [{ debugName: "textClass" }] : /* istanbul ignore next */ []));
159
- this.type = computed(() => this.data().options.type ?? "info", /* @ts-ignore */
160
- ...(ngDevMode ? [{ debugName: "type" }] : /* istanbul ignore next */ []));
161
- this.title = computed(() => this.data().options.title ?? this.messages()[this.type()], /* @ts-ignore */
246
+ this.title = computed(() => this.options().title ?? this.messages()[this.type()], /* @ts-ignore */
162
247
  ...(ngDevMode ? [{ debugName: "title" }] : /* istanbul ignore next */ []));
248
+ this.type = computed(() => this.options().type ?? "info", /* @ts-ignore */
249
+ ...(ngDevMode ? [{ debugName: "type" }] : /* istanbul ignore next */ []));
163
250
  /**
164
251
  * @description The notification's internal state, created and managed by `NotificationService`. Not intended to be provided directly by consumers.
165
252
  */
166
253
  this.data = input.required(/* @ts-ignore */
167
254
  ...(ngDevMode ? [{ debugName: "data" }] : /* istanbul ignore next */ []));
168
- afterNextRender({
255
+ /**
256
+ * @description The edge the notification's container is on, which its leave animation moves towards.
257
+ */
258
+ this.side = input("top", /* @ts-ignore */
259
+ ...(ngDevMode ? [{ debugName: "side" }] : /* istanbul ignore next */ []));
260
+ effect(() => {
261
+ this.data().rendered = true;
262
+ });
263
+ effect(() => {
264
+ const running = this.#running();
265
+ untracked(() => (running ? this.#resume() : this.#pause()));
266
+ });
267
+ effect(() => {
268
+ if (this.data().closing()) {
269
+ untracked(() => this.#leave());
270
+ }
271
+ });
272
+ afterRenderEffect({
169
273
  write: () => {
170
- this.#setupProgressBar();
171
274
  const type = this.contentComponent();
172
- const vcr = this.contentHost();
173
- if (type && vcr) {
174
- this.data().contentComponentRef.set(vcr.createComponent(type));
175
- }
275
+ const host = this.contentHost();
276
+ const injector = this.contentInjector();
277
+ untracked(() => {
278
+ host?.clear();
279
+ const componentRef = type && host ? host.createComponent(type, { injector }) : null;
280
+ componentRef?.changeDetectorRef.detectChanges();
281
+ this.data().contentComponentRef.set(componentRef);
282
+ });
283
+ }
284
+ });
285
+ // Announced once rendered, and again when update() changes it. The notification itself isn't a live
286
+ // region: one inserted with its text already in it is often skipped by screen readers.
287
+ afterRenderEffect({
288
+ read: () => {
289
+ this.options();
290
+ untracked(() => this.#announce());
176
291
  }
177
292
  });
178
- this.#destroyRef.onDestroy(() => this.data().componentDestroy$.next(this.data().options.id));
293
+ this.#listenForWindowFocus();
294
+ this.#destroyRef.onDestroy(() => {
295
+ this.#stopTimers();
296
+ this.data().finish();
297
+ });
179
298
  }
180
299
  close() {
181
- this.data().componentDestroy$.next(this.data().options.id);
182
- }
183
- onInteractionEnd() {
184
- this.#paused.set(false);
300
+ this.data().close();
185
301
  }
186
- onInteractionStart() {
187
- this.#paused.set(true);
302
+ onFocusIn(event) {
303
+ const host = this.#host.nativeElement;
304
+ const from = event.relatedTarget;
305
+ if (!this.#focused() && from instanceof HTMLElement && !host.contains(from)) {
306
+ const fromNotification = from.closest(host.tagName);
307
+ const target = fromNotification ? RETURN_FOCUS.get(fromNotification) : from;
308
+ if (target) {
309
+ RETURN_FOCUS.set(host, target);
310
+ }
311
+ }
312
+ this.#focused.set(true);
188
313
  }
189
- #setupProgressBar() {
190
- const duration = this.data().options.duration;
191
- if (duration == null) {
314
+ onFocusOut(event) {
315
+ const to = event.relatedTarget;
316
+ if (to instanceof Node && this.#host.nativeElement.contains(to)) {
192
317
  return;
193
318
  }
194
- const progressInterval = Math.max(duration, 100) / 100;
195
- interval(progressInterval)
196
- .pipe(takeWhile(() => this.progressValue() > 0), takeUntilDestroyed(this.#destroyRef))
197
- .subscribe({
198
- next: () => {
199
- if (this.#paused()) {
319
+ this.#focused.set(false);
320
+ }
321
+ onPointerChange(inside) {
322
+ this.#hovered.set(inside);
323
+ }
324
+ #announce() {
325
+ const content = this.stringContent();
326
+ const element = this.messageElement()?.nativeElement;
327
+ const text = content != null
328
+ ? `${this.title()} ${content}`
329
+ : (element?.innerText ?? element?.textContent);
330
+ const message = text?.replace(/\s+/g, " ").trim();
331
+ if (message) {
332
+ void this.#announcer.announce(message, this.#isUrgent() ? "assertive" : "polite");
333
+ }
334
+ }
335
+ /** Plays the leave animation, then removes the notification. */
336
+ #leave() {
337
+ this.#stopTimers();
338
+ this.#moveFocusAway();
339
+ afterNextRender({
340
+ read: () => {
341
+ const host = this.#host.nativeElement;
342
+ const animation = this.#document.defaultView?.getComputedStyle(host).animationName;
343
+ if (!animation || animation === "none") {
344
+ this.data().finish();
200
345
  return;
201
346
  }
202
- this.progressValue.set(this.progressValue() - 1);
203
- if (this.progressValue() === 0) {
204
- asyncScheduler.schedule(() => {
205
- this.close();
206
- }, 300);
207
- }
347
+ const done = () => {
348
+ clearTimeout(fallback);
349
+ host.removeEventListener("animationend", onEnd);
350
+ this.data().finish();
351
+ };
352
+ const onEnd = (event) => {
353
+ if (event.target === host) {
354
+ done();
355
+ }
356
+ };
357
+ const fallback = setTimeout(done, LEAVE_FALLBACK);
358
+ host.addEventListener("animationend", onEnd);
208
359
  }
360
+ }, { injector: this.#injector });
361
+ }
362
+ #listenForWindowFocus() {
363
+ const view = this.#document.defaultView;
364
+ if (!this.#defaults.pauseOnWindowBlur || !view) {
365
+ return;
366
+ }
367
+ const blur = () => this.#windowBlurred.set(true);
368
+ const focus = () => this.#windowBlurred.set(false);
369
+ view.addEventListener("blur", blur);
370
+ view.addEventListener("focus", focus);
371
+ this.#destroyRef.onDestroy(() => {
372
+ view.removeEventListener("blur", blur);
373
+ view.removeEventListener("focus", focus);
209
374
  });
210
375
  }
376
+ /** A closing notification that has focus hands it to the next notification, else back to where it came from. */
377
+ #moveFocusAway() {
378
+ const host = this.#host.nativeElement;
379
+ const active = this.#document.activeElement;
380
+ if (!(active instanceof HTMLElement) || !host.contains(active)) {
381
+ return;
382
+ }
383
+ const siblings = Array.from(host.parentElement?.children ?? []).filter(element => element !== host && element.tagName === host.tagName && !element.hasAttribute("data-closing"));
384
+ const isAfter = (element) => !!(host.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_FOLLOWING);
385
+ const ordered = [...siblings.filter(isAfter), ...siblings.filter(element => !isAfter(element)).reverse()];
386
+ for (const sibling of ordered) {
387
+ const target = sibling.querySelector(TABBABLE);
388
+ if (target) {
389
+ target.focus();
390
+ return;
391
+ }
392
+ }
393
+ const returnFocus = RETURN_FOCUS.get(host);
394
+ if (returnFocus?.isConnected) {
395
+ returnFocus.focus();
396
+ return;
397
+ }
398
+ active.blur();
399
+ }
400
+ #pause() {
401
+ if (this.#closeTimer == null) {
402
+ return;
403
+ }
404
+ const duration = this.options().duration ?? 0;
405
+ this.#remaining = Math.max(0, (this.#remaining ?? duration) - (performance.now() - this.#startedAt));
406
+ this.#stopTimers();
407
+ this.progressValue.set(duration > 0 ? (this.#remaining / duration) * 100 : 0);
408
+ }
409
+ /** Runs the countdown from the time left, measured with the clock rather than by counting ticks. */
410
+ #resume() {
411
+ const duration = this.options().duration;
412
+ if (duration == null || this.#closeTimer != null) {
413
+ return;
414
+ }
415
+ const remaining = (this.#remaining ??= duration);
416
+ this.#startedAt = performance.now();
417
+ this.#closeTimer = setTimeout(() => {
418
+ this.#closeTimer = null;
419
+ this.#remaining = 0;
420
+ this.#stopTimers();
421
+ this.progressValue.set(0);
422
+ this.data().close();
423
+ }, remaining);
424
+ if (this.options().progressBar && duration > 0) {
425
+ const step = Math.min(100, Math.max(16, duration / 100));
426
+ this.#progressTimer = setInterval(() => {
427
+ const left = remaining - (performance.now() - this.#startedAt);
428
+ this.progressValue.set(Math.max(0, (left / duration) * 100));
429
+ }, step);
430
+ }
431
+ }
432
+ #stopTimers() {
433
+ if (this.#closeTimer != null) {
434
+ clearTimeout(this.#closeTimer);
435
+ this.#closeTimer = null;
436
+ }
437
+ if (this.#progressTimer != null) {
438
+ clearInterval(this.#progressTimer);
439
+ this.#progressTimer = null;
440
+ }
441
+ }
211
442
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: NotificationComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
212
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: NotificationComponent, isStandalone: true, selector: "mona-notification", inputs: { data: { classPropertyName: "data", publicName: "data", isSignal: true, isRequired: true, transformFunction: null } }, host: { listeners: { "pointerenter": "onInteractionStart()", "pointerleave": "onInteractionEnd()", "focusin": "onInteractionStart()", "focusout": "onInteractionEnd()" } }, viewQueries: [{ propertyName: "contentHost", first: true, predicate: ["contentHost"], descendants: true, read: ViewContainerRef, isSignal: true }], ngImport: i0, template: "@let width = typeof data().options.width === \"string\" ? data().options.width : `${data().options.width}px`;\n@let height = typeof data().options.height === \"string\" ? data().options.height : `${data().options.height}px`;\n\n<div\n [class]=\"baseClass()\"\n [style.width]=\"width\"\n [style.height]=\"height\"\n [attr.role]=\"role()\"\n [attr.aria-live]=\"ariaLive()\">\n @if (contentTemplate() || contentComponent()) {\n @if (contentTemplate()) {\n <ng-container [ngTemplateOutlet]=\"contentTemplate()\"></ng-container>\n } @else if (contentComponent()) {\n <ng-container #contentHost></ng-container>\n }\n } @else {\n <div [class]=\"bodyClass()\">\n <div [class]=\"iconClass()\" aria-hidden=\"true\">\n @switch (type()) {\n @case (\"error\") {\n <svg lucideOctagonX aria-hidden=\"true\"></svg>\n }\n @case (\"info\") {\n <svg lucideBadgeInfo aria-hidden=\"true\"></svg>\n }\n @case (\"success\") {\n <svg lucideCircleCheckBig aria-hidden=\"true\"></svg>\n }\n @case (\"warning\") {\n <svg lucideOctagonAlert aria-hidden=\"true\"></svg>\n }\n }\n </div>\n <div class=\"flex flex-col flex-1\">\n <div [class]=\"headerClass()\">{{ title() }}</div>\n <div [class]=\"contentClass()\">\n @if (isStringContent()) {\n <span [class]=\"textClass()\" title=\"{{ data().options.content }}\">{{\n data().options.content\n }}</span>\n }\n </div>\n </div>\n </div>\n @if (data().options.progressBar) {\n <div class=\"w-full h-1\">\n <mona-progress-bar\n [value]=\"progressValue()\"\n [color]=\"progressColor()\"\n [labelVisible]=\"false\"\n [animate]=\"false\"\n rounded=\"none\"\n class=\"h-full\"></mona-progress-bar>\n </div>\n }\n }\n @if (data().options.closable) {\n <div [class]=\"actionClass()\">\n <button\n monaButton\n size=\"small\"\n look=\"link\"\n rounded=\"none\"\n [iconOnly]=\"true\"\n [title]=\"closeTitle()\"\n [attr.aria-label]=\"closeTitle()\"\n (click)=\"close()\">\n <svg lucideX [size]=\"14\" aria-hidden=\"true\"></svg>\n </button>\n </div>\n }\n</div>\n", styles: [":host{display:block}@keyframes notification-slide-in-top{0%{clip-path:inset(0 -20px 100% -20px);transform:translateY(-12px);opacity:0}to{clip-path:inset(-20px);transform:translateY(0);opacity:1}}@keyframes notification-slide-out-top{0%{clip-path:inset(-20px);transform:translateY(0);opacity:1}to{clip-path:inset(0 -20px 100% -20px);transform:translateY(-12px);opacity:0}}@keyframes notification-slide-in-bottom{0%{clip-path:inset(100% -20px 0 -20px);transform:translateY(12px);opacity:0}to{clip-path:inset(-20px);transform:translateY(0);opacity:1}}@keyframes notification-slide-out-bottom{0%{clip-path:inset(-20px);transform:translateY(0);opacity:1}to{clip-path:inset(100% -20px 0 -20px);transform:translateY(12px);opacity:0}}:host.notification-enter-top{animation:notification-slide-in-top .3s cubic-bezier(.4,0,.2,1) forwards}:host.notification-enter-bottom{animation:notification-slide-in-bottom .3s cubic-bezier(.4,0,.2,1) forwards}:host.notification-leave-top{animation:notification-slide-out-top .3s cubic-bezier(.4,0,.2,1) forwards}:host.notification-leave-bottom{animation:notification-slide-out-bottom .3s cubic-bezier(.4,0,.2,1) forwards}\n"], dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "component", type: ProgressBarComponent, selector: "mona-progress-bar", inputs: ["animate", "aria-label", "aria-valuetext", "color", "disabled", "indeterminate", "labelPosition", "labelStyles", "labelVisible", "max", "min", "rounded", "class", "value"] }, { kind: "directive", type: ButtonDirective, selector: "button[monaButton]", inputs: ["aria-haspopup", "disabled", "iconOnly", "loading", "look", "rounded", "selected", "size", "tabindex", "toggleable", "type", "class"], outputs: ["lookChange", "selectedChange"] }, { kind: "component", type: LucideOctagonX, selector: "svg[lucideOctagonX], svg[lucideXOctagon]" }, { kind: "component", type: LucideBadgeInfo, selector: "svg[lucideBadgeInfo]" }, { kind: "component", type: LucideCircleCheckBig, selector: "svg[lucideCircleCheckBig], svg[lucideCheckCircle]" }, { kind: "component", type: LucideOctagonAlert, selector: "svg[lucideOctagonAlert], svg[lucideAlertOctagon]" }, { kind: "component", type: LucideX, selector: "svg[lucideX]" }] }); }
443
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: NotificationComponent, isStandalone: true, selector: "mona-notification", inputs: { data: { classPropertyName: "data", publicName: "data", isSignal: true, isRequired: true, transformFunction: null }, side: { classPropertyName: "side", publicName: "side", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "focusin": "onFocusIn($event)", "focusout": "onFocusOut($event)", "pointerenter": "onPointerChange(true)", "pointerleave": "onPointerChange(false)" }, properties: { "attr.data-closing": "data().closing() ? '' : null", "class.notification-leave-bottom": "data().closing() && side() === 'bottom'", "class.notification-leave-top": "data().closing() && side() !== 'bottom'" } }, viewQueries: [{ propertyName: "contentHost", first: true, predicate: ["contentHost"], descendants: true, read: ViewContainerRef, isSignal: true }, { propertyName: "messageElement", first: true, predicate: ["message"], descendants: true, isSignal: true }], ngImport: i0, template: "@let opts = options();\n@let width = typeof opts.width === \"string\" ? opts.width : `${opts.width}px`;\n@let height = typeof opts.height === \"string\" ? opts.height : `${opts.height}px`;\n\n<div [class]=\"baseClass()\" [style.width]=\"width\" [style.height]=\"height\">\n @if (contentTemplate(); as template) {\n <div #message class=\"contents\">\n <ng-container\n [ngTemplateOutlet]=\"template\"\n [ngTemplateOutletContext]=\"templateContext()\"\n [ngTemplateOutletInjector]=\"contentInjector()\"></ng-container>\n </div>\n } @else if (contentComponent()) {\n <div #message class=\"contents\">\n <ng-container #contentHost></ng-container>\n </div>\n } @else {\n <div #message [class]=\"bodyClass()\">\n <div [class]=\"iconClass()\" aria-hidden=\"true\">\n @switch (type()) {\n @case (\"error\") {\n <svg lucideOctagonX aria-hidden=\"true\"></svg>\n }\n @case (\"info\") {\n <svg lucideBadgeInfo aria-hidden=\"true\"></svg>\n }\n @case (\"success\") {\n <svg lucideCircleCheckBig aria-hidden=\"true\"></svg>\n }\n @case (\"warning\") {\n <svg lucideOctagonAlert aria-hidden=\"true\"></svg>\n }\n }\n </div>\n <div class=\"flex flex-col flex-1\">\n <div [class]=\"headerClass()\">{{ title() }}</div>\n <div [class]=\"contentClass()\">\n <span [class]=\"textClass()\">{{ stringContent() }}</span>\n </div>\n </div>\n </div>\n @if (opts.progressBar && opts.duration !== undefined) {\n <!-- Decorative: the time left isn't worth announcing. -->\n <div class=\"w-full h-1\" aria-hidden=\"true\">\n <mona-progress-bar\n [value]=\"progressValue()\"\n [color]=\"progressColor()\"\n [labelVisible]=\"false\"\n [animate]=\"false\"\n rounded=\"none\"\n class=\"h-full\"></mona-progress-bar>\n </div>\n }\n }\n @if (opts.closable) {\n <div [class]=\"actionClass()\">\n <button\n monaButton\n size=\"small\"\n look=\"link\"\n rounded=\"none\"\n [iconOnly]=\"true\"\n [title]=\"closeTitle()\"\n [attr.aria-label]=\"closeTitle()\"\n (click)=\"close()\">\n <svg lucideX [size]=\"14\" aria-hidden=\"true\"></svg>\n </button>\n </div>\n }\n</div>\n", styles: [":host{display:block}@keyframes notification-slide-in-top{0%{clip-path:inset(0 -20px 100% -20px);transform:translateY(-12px);opacity:0}to{clip-path:inset(-20px);transform:translateY(0);opacity:1}}@keyframes notification-slide-out-top{0%{clip-path:inset(-20px);transform:translateY(0);opacity:1}to{clip-path:inset(0 -20px 100% -20px);transform:translateY(-12px);opacity:0}}@keyframes notification-slide-in-bottom{0%{clip-path:inset(100% -20px 0 -20px);transform:translateY(12px);opacity:0}to{clip-path:inset(-20px);transform:translateY(0);opacity:1}}@keyframes notification-slide-out-bottom{0%{clip-path:inset(-20px);transform:translateY(0);opacity:1}to{clip-path:inset(100% -20px 0 -20px);transform:translateY(12px);opacity:0}}:host.notification-enter-top{animation:notification-slide-in-top .3s cubic-bezier(.4,0,.2,1) forwards}:host.notification-enter-bottom{animation:notification-slide-in-bottom .3s cubic-bezier(.4,0,.2,1) forwards}:host.notification-leave-top{animation:notification-slide-out-top .3s cubic-bezier(.4,0,.2,1) forwards}:host.notification-leave-bottom{animation:notification-slide-out-bottom .3s cubic-bezier(.4,0,.2,1) forwards}@media(prefers-reduced-motion:reduce){:host.notification-enter-top,:host.notification-enter-bottom,:host.notification-leave-top,:host.notification-leave-bottom{animation:none}}\n"], dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "component", type: ProgressBarComponent, selector: "mona-progress-bar", inputs: ["animate", "aria-label", "aria-valuetext", "color", "disabled", "indeterminate", "labelPosition", "labelStyles", "labelVisible", "max", "min", "rounded", "class", "value"] }, { kind: "directive", type: ButtonDirective, selector: "button[monaButton]", inputs: ["aria-haspopup", "disabled", "iconOnly", "loading", "look", "rounded", "selected", "size", "tabindex", "toggleable", "type", "class"], outputs: ["lookChange", "selectedChange"] }, { kind: "component", type: LucideOctagonX, selector: "svg[lucideOctagonX], svg[lucideXOctagon]" }, { kind: "component", type: LucideBadgeInfo, selector: "svg[lucideBadgeInfo]" }, { kind: "component", type: LucideCircleCheckBig, selector: "svg[lucideCircleCheckBig], svg[lucideCheckCircle]" }, { kind: "component", type: LucideOctagonAlert, selector: "svg[lucideOctagonAlert], svg[lucideAlertOctagon]" }, { kind: "component", type: LucideX, selector: "svg[lucideX]" }] }); }
213
444
  }
214
445
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: NotificationComponent, decorators: [{
215
446
  type: Component,
@@ -223,25 +454,30 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImpor
223
454
  LucideOctagonAlert,
224
455
  LucideX
225
456
  ], host: {
226
- "(pointerenter)": "onInteractionStart()",
227
- "(pointerleave)": "onInteractionEnd()",
228
- "(focusin)": "onInteractionStart()",
229
- "(focusout)": "onInteractionEnd()"
230
- }, template: "@let width = typeof data().options.width === \"string\" ? data().options.width : `${data().options.width}px`;\n@let height = typeof data().options.height === \"string\" ? data().options.height : `${data().options.height}px`;\n\n<div\n [class]=\"baseClass()\"\n [style.width]=\"width\"\n [style.height]=\"height\"\n [attr.role]=\"role()\"\n [attr.aria-live]=\"ariaLive()\">\n @if (contentTemplate() || contentComponent()) {\n @if (contentTemplate()) {\n <ng-container [ngTemplateOutlet]=\"contentTemplate()\"></ng-container>\n } @else if (contentComponent()) {\n <ng-container #contentHost></ng-container>\n }\n } @else {\n <div [class]=\"bodyClass()\">\n <div [class]=\"iconClass()\" aria-hidden=\"true\">\n @switch (type()) {\n @case (\"error\") {\n <svg lucideOctagonX aria-hidden=\"true\"></svg>\n }\n @case (\"info\") {\n <svg lucideBadgeInfo aria-hidden=\"true\"></svg>\n }\n @case (\"success\") {\n <svg lucideCircleCheckBig aria-hidden=\"true\"></svg>\n }\n @case (\"warning\") {\n <svg lucideOctagonAlert aria-hidden=\"true\"></svg>\n }\n }\n </div>\n <div class=\"flex flex-col flex-1\">\n <div [class]=\"headerClass()\">{{ title() }}</div>\n <div [class]=\"contentClass()\">\n @if (isStringContent()) {\n <span [class]=\"textClass()\" title=\"{{ data().options.content }}\">{{\n data().options.content\n }}</span>\n }\n </div>\n </div>\n </div>\n @if (data().options.progressBar) {\n <div class=\"w-full h-1\">\n <mona-progress-bar\n [value]=\"progressValue()\"\n [color]=\"progressColor()\"\n [labelVisible]=\"false\"\n [animate]=\"false\"\n rounded=\"none\"\n class=\"h-full\"></mona-progress-bar>\n </div>\n }\n }\n @if (data().options.closable) {\n <div [class]=\"actionClass()\">\n <button\n monaButton\n size=\"small\"\n look=\"link\"\n rounded=\"none\"\n [iconOnly]=\"true\"\n [title]=\"closeTitle()\"\n [attr.aria-label]=\"closeTitle()\"\n (click)=\"close()\">\n <svg lucideX [size]=\"14\" aria-hidden=\"true\"></svg>\n </button>\n </div>\n }\n</div>\n", styles: [":host{display:block}@keyframes notification-slide-in-top{0%{clip-path:inset(0 -20px 100% -20px);transform:translateY(-12px);opacity:0}to{clip-path:inset(-20px);transform:translateY(0);opacity:1}}@keyframes notification-slide-out-top{0%{clip-path:inset(-20px);transform:translateY(0);opacity:1}to{clip-path:inset(0 -20px 100% -20px);transform:translateY(-12px);opacity:0}}@keyframes notification-slide-in-bottom{0%{clip-path:inset(100% -20px 0 -20px);transform:translateY(12px);opacity:0}to{clip-path:inset(-20px);transform:translateY(0);opacity:1}}@keyframes notification-slide-out-bottom{0%{clip-path:inset(-20px);transform:translateY(0);opacity:1}to{clip-path:inset(100% -20px 0 -20px);transform:translateY(12px);opacity:0}}:host.notification-enter-top{animation:notification-slide-in-top .3s cubic-bezier(.4,0,.2,1) forwards}:host.notification-enter-bottom{animation:notification-slide-in-bottom .3s cubic-bezier(.4,0,.2,1) forwards}:host.notification-leave-top{animation:notification-slide-out-top .3s cubic-bezier(.4,0,.2,1) forwards}:host.notification-leave-bottom{animation:notification-slide-out-bottom .3s cubic-bezier(.4,0,.2,1) forwards}\n"] }]
231
- }], ctorParameters: () => [], propDecorators: { contentHost: [{ type: i0.ViewChild, args: ["contentHost", { ...{ read: ViewContainerRef }, isSignal: true }] }], data: [{ type: i0.Input, args: [{ isSignal: true, alias: "data", required: true }] }] } });
457
+ "[attr.data-closing]": "data().closing() ? '' : null",
458
+ "[class.notification-leave-bottom]": "data().closing() && side() === 'bottom'",
459
+ "[class.notification-leave-top]": "data().closing() && side() !== 'bottom'",
460
+ "(focusin)": "onFocusIn($event)",
461
+ "(focusout)": "onFocusOut($event)",
462
+ "(pointerenter)": "onPointerChange(true)",
463
+ "(pointerleave)": "onPointerChange(false)"
464
+ }, template: "@let opts = options();\n@let width = typeof opts.width === \"string\" ? opts.width : `${opts.width}px`;\n@let height = typeof opts.height === \"string\" ? opts.height : `${opts.height}px`;\n\n<div [class]=\"baseClass()\" [style.width]=\"width\" [style.height]=\"height\">\n @if (contentTemplate(); as template) {\n <div #message class=\"contents\">\n <ng-container\n [ngTemplateOutlet]=\"template\"\n [ngTemplateOutletContext]=\"templateContext()\"\n [ngTemplateOutletInjector]=\"contentInjector()\"></ng-container>\n </div>\n } @else if (contentComponent()) {\n <div #message class=\"contents\">\n <ng-container #contentHost></ng-container>\n </div>\n } @else {\n <div #message [class]=\"bodyClass()\">\n <div [class]=\"iconClass()\" aria-hidden=\"true\">\n @switch (type()) {\n @case (\"error\") {\n <svg lucideOctagonX aria-hidden=\"true\"></svg>\n }\n @case (\"info\") {\n <svg lucideBadgeInfo aria-hidden=\"true\"></svg>\n }\n @case (\"success\") {\n <svg lucideCircleCheckBig aria-hidden=\"true\"></svg>\n }\n @case (\"warning\") {\n <svg lucideOctagonAlert aria-hidden=\"true\"></svg>\n }\n }\n </div>\n <div class=\"flex flex-col flex-1\">\n <div [class]=\"headerClass()\">{{ title() }}</div>\n <div [class]=\"contentClass()\">\n <span [class]=\"textClass()\">{{ stringContent() }}</span>\n </div>\n </div>\n </div>\n @if (opts.progressBar && opts.duration !== undefined) {\n <!-- Decorative: the time left isn't worth announcing. -->\n <div class=\"w-full h-1\" aria-hidden=\"true\">\n <mona-progress-bar\n [value]=\"progressValue()\"\n [color]=\"progressColor()\"\n [labelVisible]=\"false\"\n [animate]=\"false\"\n rounded=\"none\"\n class=\"h-full\"></mona-progress-bar>\n </div>\n }\n }\n @if (opts.closable) {\n <div [class]=\"actionClass()\">\n <button\n monaButton\n size=\"small\"\n look=\"link\"\n rounded=\"none\"\n [iconOnly]=\"true\"\n [title]=\"closeTitle()\"\n [attr.aria-label]=\"closeTitle()\"\n (click)=\"close()\">\n <svg lucideX [size]=\"14\" aria-hidden=\"true\"></svg>\n </button>\n </div>\n }\n</div>\n", styles: [":host{display:block}@keyframes notification-slide-in-top{0%{clip-path:inset(0 -20px 100% -20px);transform:translateY(-12px);opacity:0}to{clip-path:inset(-20px);transform:translateY(0);opacity:1}}@keyframes notification-slide-out-top{0%{clip-path:inset(-20px);transform:translateY(0);opacity:1}to{clip-path:inset(0 -20px 100% -20px);transform:translateY(-12px);opacity:0}}@keyframes notification-slide-in-bottom{0%{clip-path:inset(100% -20px 0 -20px);transform:translateY(12px);opacity:0}to{clip-path:inset(-20px);transform:translateY(0);opacity:1}}@keyframes notification-slide-out-bottom{0%{clip-path:inset(-20px);transform:translateY(0);opacity:1}to{clip-path:inset(100% -20px 0 -20px);transform:translateY(12px);opacity:0}}:host.notification-enter-top{animation:notification-slide-in-top .3s cubic-bezier(.4,0,.2,1) forwards}:host.notification-enter-bottom{animation:notification-slide-in-bottom .3s cubic-bezier(.4,0,.2,1) forwards}:host.notification-leave-top{animation:notification-slide-out-top .3s cubic-bezier(.4,0,.2,1) forwards}:host.notification-leave-bottom{animation:notification-slide-out-bottom .3s cubic-bezier(.4,0,.2,1) forwards}@media(prefers-reduced-motion:reduce){:host.notification-enter-top,:host.notification-enter-bottom,:host.notification-leave-top,:host.notification-leave-bottom{animation:none}}\n"] }]
465
+ }], ctorParameters: () => [], propDecorators: { contentHost: [{ type: i0.ViewChild, args: ["contentHost", { ...{ read: ViewContainerRef }, isSignal: true }] }], messageElement: [{ type: i0.ViewChild, args: ["message", { isSignal: true }] }], data: [{ type: i0.Input, args: [{ isSignal: true, alias: "data", required: true }] }], side: [{ type: i0.Input, args: [{ isSignal: true, alias: "side", required: false }] }] } });
232
466
 
233
467
  class NotificationContainerComponent {
234
468
  constructor() {
469
+ this.#i18n = inject(MonaI18nService);
235
470
  this.baseClass = computed(() => {
236
471
  const position = this.position();
237
472
  const positionType = this.positionType();
238
473
  return notificationContainerBaseThemeVariants({ position, positionType });
239
474
  }, /* @ts-ignore */
240
475
  ...(ngDevMode ? [{ debugName: "baseClass" }] : /* istanbul ignore next */ []));
241
- this.enterAnimClass = computed(() => this.position().startsWith("bottom") ? "notification-enter-bottom" : "notification-enter-top", /* @ts-ignore */
476
+ this.enterAnimClass = computed(() => this.side() === "bottom" ? "notification-enter-bottom" : "notification-enter-top", /* @ts-ignore */
242
477
  ...(ngDevMode ? [{ debugName: "enterAnimClass" }] : /* istanbul ignore next */ []));
243
- this.leaveAnimClass = computed(() => this.position().startsWith("bottom") ? "notification-leave-bottom" : "notification-leave-top", /* @ts-ignore */
244
- ...(ngDevMode ? [{ debugName: "leaveAnimClass" }] : /* istanbul ignore next */ []));
478
+ this.messages = this.#i18n.componentMessages("notification", NOTIFICATION_DEFAULT_MESSAGES);
479
+ this.side = computed(() => (this.position().startsWith("bottom") ? "bottom" : "top"), /* @ts-ignore */
480
+ ...(ngDevMode ? [{ debugName: "side" }] : /* istanbul ignore next */ []));
245
481
  this.notificationDataList = signal([], /* @ts-ignore */
246
482
  ...(ngDevMode ? [{ debugName: "notificationDataList" }] : /* istanbul ignore next */ []));
247
483
  this.position = signal("topright", /* @ts-ignore */
@@ -249,208 +485,195 @@ class NotificationContainerComponent {
249
485
  this.positionType = signal("fixed", /* @ts-ignore */
250
486
  ...(ngDevMode ? [{ debugName: "positionType" }] : /* istanbul ignore next */ []));
251
487
  }
488
+ #i18n;
252
489
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: NotificationContainerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
253
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: NotificationContainerComponent, isStandalone: true, selector: "mona-notification-container", host: { properties: { "class": "baseClass()" } }, ngImport: i0, template: "@for (notificationData of notificationDataList(); track notificationData.options.id) {\n <mona-notification [data]=\"notificationData\" [animate.enter]=\"enterAnimClass()\" [animate.leave]=\"leaveAnimClass()\">\n </mona-notification>\n}\n", dependencies: [{ kind: "component", type: NotificationComponent, selector: "mona-notification", inputs: ["data"] }] }); }
490
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: NotificationContainerComponent, isStandalone: true, selector: "mona-notification-container", host: { attributes: { "role": "region" }, properties: { "attr.aria-label": "messages().region", "class": "baseClass()" } }, ngImport: i0, template: "@for (notificationData of notificationDataList(); track notificationData) {\n <mona-notification [data]=\"notificationData\" [side]=\"side()\" [animate.enter]=\"enterAnimClass()\"></mona-notification>\n}\n", dependencies: [{ kind: "component", type: NotificationComponent, selector: "mona-notification", inputs: ["data", "side"] }] }); }
254
491
  }
255
492
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: NotificationContainerComponent, decorators: [{
256
493
  type: Component,
257
494
  args: [{ selector: "mona-notification-container", imports: [NotificationComponent], host: {
258
- "[class]": "baseClass()"
259
- }, template: "@for (notificationData of notificationDataList(); track notificationData.options.id) {\n <mona-notification [data]=\"notificationData\" [animate.enter]=\"enterAnimClass()\" [animate.leave]=\"leaveAnimClass()\">\n </mona-notification>\n}\n" }]
495
+ "[attr.aria-label]": "messages().region",
496
+ "[class]": "baseClass()",
497
+ role: "region"
498
+ }, template: "@for (notificationData of notificationDataList(); track notificationData) {\n <mona-notification [data]=\"notificationData\" [side]=\"side()\" [animate.enter]=\"enterAnimClass()\"></mona-notification>\n}\n" }]
260
499
  }] });
261
500
 
501
+ /**
502
+ * The internal state of one shown notification, shared by the service and the notification component.
503
+ * Closing has two steps: `close()` starts it and the component plays its leave animation, then `finish()` removes it.
504
+ */
505
+ class NotificationData {
506
+ #afterHide$;
507
+ #onFinish;
508
+ #finished;
509
+ constructor(options, onFinish = () => undefined) {
510
+ this.#afterHide$ = new Subject();
511
+ this.#finished = false;
512
+ this.closing = signal(false, /* @ts-ignore */
513
+ ...(ngDevMode ? [{ debugName: "closing" }] : /* istanbul ignore next */ []));
514
+ this.contentComponentRef = signal(null, /* @ts-ignore */
515
+ ...(ngDevMode ? [{ debugName: "contentComponentRef" }] : /* istanbul ignore next */ []));
516
+ /** Set once the notification component exists, so closing waits for its leave animation. */
517
+ this.rendered = false;
518
+ this.#onFinish = onFinish;
519
+ this.options = signal(options, /* @ts-ignore */
520
+ ...(ngDevMode ? [{ debugName: "options" }] : /* istanbul ignore next */ []));
521
+ const contentComponentRef = this.contentComponentRef;
522
+ this.ref = {
523
+ afterHide: this.#afterHide$.asObservable(),
524
+ get content() {
525
+ return contentComponentRef();
526
+ },
527
+ hide: () => this.close(),
528
+ id: options.id,
529
+ update: changes => {
530
+ if (!this.#finished) {
531
+ this.options.update(current => ({ ...current, ...changes }));
532
+ }
533
+ }
534
+ };
535
+ }
536
+ get finished() {
537
+ return this.#finished;
538
+ }
539
+ get id() {
540
+ return this.options().id;
541
+ }
542
+ /** Starts closing. A notification that hasn't rendered yet is removed at once. */
543
+ close() {
544
+ if (this.#finished || this.closing()) {
545
+ return;
546
+ }
547
+ if (!this.rendered) {
548
+ this.finish();
549
+ return;
550
+ }
551
+ this.closing.set(true);
552
+ }
553
+ /** Removes the notification, and emits and completes `afterHide`. */
554
+ finish() {
555
+ if (this.#finished) {
556
+ return;
557
+ }
558
+ this.#finished = true;
559
+ this.closing.set(true);
560
+ this.#onFinish(this);
561
+ this.#afterHide$.next();
562
+ this.#afterHide$.complete();
563
+ }
564
+ }
565
+
262
566
  class NotificationService {
263
- #appRef;
264
- #document;
265
- #pendingTimeouts;
567
+ #appRef = inject(ApplicationRef);
568
+ #containers = new Map();
569
+ #defaults = inject(NOTIFICATION_DEFAULTS);
570
+ #directionality = inject(Directionality, { optional: true });
571
+ #document = inject(DOCUMENT$1);
572
+ #i18n = inject(MonaI18nService, { optional: true });
573
+ #destroyed = false;
266
574
  constructor() {
267
- this.#appRef = inject(ApplicationRef);
268
- this.#document = inject(DOCUMENT$1);
269
- this.#pendingTimeouts = new Set();
270
- this.notificationContainerMap = new Map();
271
- this.notificationContainerSubscriptions = {
272
- bottom: null,
273
- bottomleft: null,
274
- bottomright: null,
275
- top: null,
276
- topleft: null,
277
- topright: null
278
- };
279
- this.initialize();
280
- // The ApplicationRef is destroyed with the same injector, so a timeout firing afterwards would detach
281
- // views from a destroyed ApplicationRef.
282
575
  inject(DestroyRef).onDestroy(() => {
283
- this.#pendingTimeouts.forEach(handle => window.clearTimeout(handle));
284
- this.#pendingTimeouts.clear();
576
+ this.#destroyed = true;
577
+ for (const container of this.#containers.values()) {
578
+ this.#destroyContainer(container);
579
+ }
580
+ this.#containers.clear();
285
581
  });
286
582
  }
287
583
  hide(id) {
288
- const notificationData = this.getNotificationDataById(id);
289
- if (notificationData) {
290
- notificationData.componentDestroy$.next(id);
584
+ for (const container of this.#containers.values()) {
585
+ container.notifications.get(id)?.close();
291
586
  }
292
587
  }
293
588
  hideAll() {
294
- this.notificationContainerMap.forEach(container => {
295
- container.notifications.forEach(notification => {
296
- this.hide(notification.options.id);
297
- });
298
- });
589
+ for (const container of [...this.#containers.values()]) {
590
+ for (const notification of [...container.notifications.values()]) {
591
+ notification.close();
592
+ }
593
+ }
299
594
  }
300
595
  show(options) {
301
596
  const position = options.position ?? "topright";
302
- const type = options.type ?? "info";
303
- const resolvedOptions = {
597
+ const id = options.id ?? createElementControlId();
598
+ const existing = this.#containers.get(position)?.notifications.get(id);
599
+ if (existing && !existing.finished) {
600
+ return existing.ref;
601
+ }
602
+ const duration = options.duration != null && this.#defaults.autoHide
603
+ ? options.duration * this.#defaults.durationScale
604
+ : undefined;
605
+ const resolved = {
304
606
  ...options,
305
- id: options.id ?? `Notification_${v4()}`,
607
+ closable: options.closable ?? true,
608
+ duration,
609
+ id,
306
610
  position,
307
- type,
308
- title: options.title,
309
- closable: options.closable ?? (options.duration == null ? true : undefined)
611
+ type: options.type ?? "info"
310
612
  };
311
- const containerData = this.notificationContainerMap.get(position);
312
- if (containerData?.notifications.has(resolvedOptions.id)) {
313
- const existing = containerData.notifications.get(resolvedOptions.id);
314
- return {
315
- afterHide: existing.afterHide$.asObservable(),
316
- get content() {
317
- return existing.contentComponentRef();
318
- },
319
- hide: () => this.hide(resolvedOptions.id)
320
- };
321
- }
322
- if (this.notificationContainerSubscriptions[position]) {
323
- return this.createNotification(resolvedOptions);
324
- }
325
- else {
326
- return this.createNotificationContainer(resolvedOptions);
327
- }
613
+ const container = this.#containers.get(position) ?? this.#createContainer(position, options.appendTo);
614
+ const data = new NotificationData(resolved, finished => this.#remove(position, finished));
615
+ container.notifications.set(id, data);
616
+ this.#limit(container);
617
+ this.#sync(container);
618
+ return data.ref;
328
619
  }
329
- createContainerComponent(appendTo) {
330
- const containerSubject = new Subject();
331
- const notificationContainerComponent = createComponent(NotificationContainerComponent, {
620
+ #createContainer(position, appendTo) {
621
+ // Created and attached at once, so a notification hidden in the same tick never leaves a container behind.
622
+ const componentRef = createComponent(NotificationContainerComponent, {
332
623
  environmentInjector: this.#appRef.injector
333
624
  });
625
+ const element = componentRef.location.nativeElement;
334
626
  const host = appendTo ? appendTo.element.nativeElement : this.#document.body;
335
- notificationContainerComponent.instance.positionType.set(appendTo ? "absolute" : "fixed");
336
- host.appendChild(notificationContainerComponent.location.nativeElement);
337
- this.#appRef.attachView(notificationContainerComponent.hostView);
338
- notificationContainerComponent.changeDetectorRef.detectChanges();
339
- this.scheduleTimeout(() => {
340
- containerSubject.next(notificationContainerComponent);
341
- });
342
- return containerSubject;
343
- }
344
- createNotification(options) {
345
- const position = options.position;
346
- const notificationContainerData = this.notificationContainerMap.get(position);
347
- if (!notificationContainerData) {
348
- throw new Error(`Notification container for position ${position} was not found.`);
349
- }
350
- const componentDestroy$ = new Subject();
351
- const afterHide$ = new Subject();
352
- const notificationData = {
353
- options,
354
- componentDestroy$,
355
- afterHide$,
356
- contentComponentRef: signal(null)
357
- };
358
- if (!notificationContainerData.notifications.has(options.id)) {
359
- notificationContainerData.notifications.set(options.id, notificationData);
360
- if (notificationContainerData.componentRef) {
361
- notificationContainerData.componentRef.instance.notificationDataList.set(Array.from(notificationContainerData.notifications.values()));
627
+ componentRef.instance.position.set(position);
628
+ componentRef.instance.positionType.set(appendTo ? "absolute" : "fixed");
629
+ if (!appendTo) {
630
+ // The container sits outside the app root, so it takes the app's direction and language explicitly.
631
+ element.setAttribute("dir", this.#directionality?.value ?? "ltr");
632
+ const lang = this.#i18n?.localeId();
633
+ if (lang) {
634
+ element.setAttribute("lang", lang);
362
635
  }
363
636
  }
364
- componentDestroy$.pipe(take(1)).subscribe(id => {
365
- afterHide$.next();
366
- afterHide$.complete();
367
- this.removeNotificationData(id, position);
368
- });
369
- return {
370
- afterHide: afterHide$.asObservable(),
371
- get content() {
372
- return notificationData.contentComponentRef();
373
- },
374
- hide: () => this.hide(options.id)
375
- };
376
- }
377
- createNotificationContainer(options) {
378
- const position = options.position;
379
- const ref = this.createNotification(options);
380
- this.notificationContainerSubscriptions[position] = this.createContainerComponent(options.appendTo).subscribe(ncr => {
381
- ncr.instance.position.set(options.position);
382
- const notificationContainerData = this.notificationContainerMap.get(position);
383
- notificationContainerData.componentRef = ncr;
384
- notificationContainerData.appendTo = options.appendTo;
385
- notificationContainerData.subscription = this.notificationContainerSubscriptions[position];
386
- ncr.instance.notificationDataList.set(Array.from(notificationContainerData.notifications.values()));
387
- });
388
- return ref;
637
+ host.appendChild(element);
638
+ this.#appRef.attachView(componentRef.hostView);
639
+ componentRef.changeDetectorRef.detectChanges();
640
+ const container = { componentRef, notifications: new Map() };
641
+ this.#containers.set(position, container);
642
+ return container;
389
643
  }
390
- getNotificationDataById(id) {
391
- for (const notificationContainerData of this.notificationContainerMap.values()) {
392
- const notificationData = notificationContainerData.notifications.get(id);
393
- if (notificationData) {
394
- return notificationData;
395
- }
644
+ #destroyContainer(container) {
645
+ const { componentRef } = container;
646
+ if (!componentRef.hostView.destroyed) {
647
+ componentRef.destroy();
396
648
  }
397
- return null;
649
+ componentRef.location.nativeElement.remove();
398
650
  }
399
- initialize() {
400
- this.notificationContainerMap.set("bottom", {
401
- componentRef: null,
402
- notifications: new Map()
403
- });
404
- this.notificationContainerMap.set("bottomleft", {
405
- componentRef: null,
406
- notifications: new Map()
407
- });
408
- this.notificationContainerMap.set("bottomright", {
409
- componentRef: null,
410
- notifications: new Map()
411
- });
412
- this.notificationContainerMap.set("top", {
413
- componentRef: null,
414
- notifications: new Map()
415
- });
416
- this.notificationContainerMap.set("topleft", {
417
- componentRef: null,
418
- notifications: new Map()
419
- });
420
- this.notificationContainerMap.set("topright", {
421
- componentRef: null,
422
- notifications: new Map()
423
- });
424
- }
425
- removeNotificationData(id, position) {
426
- const container = this.notificationContainerMap.get(position);
427
- if (!container) {
651
+ /** Closes the oldest notifications beyond `maxVisible`. */
652
+ #limit(container) {
653
+ const max = this.#defaults.maxVisible;
654
+ if (max == null || max < 1) {
428
655
  return;
429
656
  }
430
- container.notifications.delete(id);
431
- if (container.componentRef) {
432
- container.componentRef.instance.notificationDataList.set(Array.from(container.notifications.values()));
657
+ const open = [...container.notifications.values()].filter(notification => !notification.closing());
658
+ for (const notification of open.slice(0, Math.max(0, open.length - max))) {
659
+ notification.close();
433
660
  }
661
+ }
662
+ #remove(position, data) {
663
+ const container = this.#containers.get(position);
664
+ if (this.#destroyed || !container || container.notifications.get(data.id) !== data) {
665
+ return;
666
+ }
667
+ container.notifications.delete(data.id);
434
668
  if (container.notifications.size === 0) {
435
- container.subscription?.unsubscribe();
436
- const componentRefToDestroy = container.componentRef;
437
- container.componentRef = null;
438
- container.subscription = undefined;
439
- this.notificationContainerSubscriptions[position] = null;
440
- this.scheduleTimeout(() => {
441
- if (componentRefToDestroy) {
442
- this.#appRef.detachView(componentRefToDestroy.hostView);
443
- componentRefToDestroy.destroy();
444
- }
445
- }, 300);
669
+ this.#containers.delete(position);
670
+ this.#destroyContainer(container);
671
+ return;
446
672
  }
673
+ this.#sync(container);
447
674
  }
448
- scheduleTimeout(callback, delay) {
449
- const handle = window.setTimeout(() => {
450
- this.#pendingTimeouts.delete(handle);
451
- callback();
452
- }, delay);
453
- this.#pendingTimeouts.add(handle);
675
+ #sync(container) {
676
+ container.componentRef.instance.notificationDataList.set([...container.notifications.values()]);
454
677
  }
455
678
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: NotificationService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
456
679
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: NotificationService, providedIn: "root" }); }
@@ -462,6 +685,16 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImpor
462
685
  }]
463
686
  }], ctorParameters: () => [] });
464
687
 
688
+ /**
689
+ * Sets application-wide notification behavior: whether timed notifications close on their own, how much longer they
690
+ * stay, how many show at once, and whether the countdown pauses while the window is in the background.
691
+ */
692
+ function provideNotificationDefaults(defaults) {
693
+ return makeEnvironmentProviders([
694
+ { provide: NOTIFICATION_DEFAULTS, useValue: { ...DEFAULT_NOTIFICATION_DEFAULTS, ...defaults } }
695
+ ]);
696
+ }
697
+
465
698
  /*
466
699
  * Public API Surface of @nanahoshi/mona-ui/notification
467
700
  */
@@ -470,5 +703,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImpor
470
703
  * Generated bundle index. Do not edit.
471
704
  */
472
705
 
473
- export { NOTIFICATION_DEFAULT_MESSAGES, NotificationService };
706
+ export { NOTIFICATION_DATA, NOTIFICATION_DEFAULTS, NOTIFICATION_DEFAULT_MESSAGES, NOTIFICATION_REF, NotificationService, provideNotificationDefaults };
474
707
  //# sourceMappingURL=nanahoshi-mona-ui-notification.mjs.map