@nanahoshi/mona-ui 0.24.8 → 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.
- package/fesm2022/nanahoshi-mona-ui-button-group.mjs +37 -9
- package/fesm2022/nanahoshi-mona-ui-button.mjs +8 -2
- package/fesm2022/nanahoshi-mona-ui-color-gradient.mjs +4 -3
- package/fesm2022/nanahoshi-mona-ui-contextmenu.mjs +101 -47
- package/fesm2022/nanahoshi-mona-ui-dialog.mjs +339 -101
- package/fesm2022/nanahoshi-mona-ui-dropdown-button.mjs +119 -69
- package/fesm2022/nanahoshi-mona-ui-editor.mjs +2 -2
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-footer-row.component-DdyHnUIr.mjs → nanahoshi-mona-ui-grid-grid-footer-row.component-DhKLnW06.mjs} +2 -2
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-list.component-B6gq7Hu3.mjs → nanahoshi-mona-ui-grid-grid-list.component-voGbKOiB.mjs} +4 -4
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-row.component-DdUY3I7P.mjs → nanahoshi-mona-ui-grid-grid-row.component-HQ1Kv6R9.mjs} +2 -3
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-virtual-list.component-DG8Bu4Dy.mjs → nanahoshi-mona-ui-grid-grid-virtual-list.component-PNLJFcuH.mjs} +4 -4
- package/fesm2022/{nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-CVqpbMcb.mjs → nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-BO19AVwC.mjs} +9 -9
- package/fesm2022/nanahoshi-mona-ui-grid.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-internal.mjs +438 -22
- package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-menubar.mjs +127 -133
- package/fesm2022/nanahoshi-mona-ui-notification.mjs +473 -240
- package/fesm2022/nanahoshi-mona-ui-popover.mjs +202 -90
- package/fesm2022/nanahoshi-mona-ui-popup-menu.mjs +609 -256
- package/fesm2022/nanahoshi-mona-ui-popup.mjs +2 -0
- package/fesm2022/nanahoshi-mona-ui-sheet.mjs +45 -10
- package/fesm2022/nanahoshi-mona-ui-split-button.mjs +102 -58
- package/fesm2022/nanahoshi-mona-ui-tooltip.mjs +286 -443
- package/fesm2022/nanahoshi-mona-ui-window.mjs +591 -310
- package/i18n/catalogs/en-US.messages.json +4 -0
- package/locales/ar-sa/ar-sa.messages.json +4 -0
- package/locales/de-de/de-de.messages.json +4 -0
- package/locales/es-es/es-es.messages.json +4 -0
- package/locales/fr-fr/fr-fr.messages.json +4 -0
- package/locales/id-id/id-id.messages.json +4 -0
- package/locales/it-it/it-it.messages.json +4 -0
- package/locales/ja-jp/ja-jp.messages.json +4 -0
- package/locales/ko-kr/ko-kr.messages.json +4 -0
- package/locales/pt-br/pt-br.messages.json +4 -0
- package/locales/ru-ru/ru-ru.messages.json +4 -0
- package/locales/tr-tr/tr-tr.messages.json +4 -0
- package/locales/zh-cn/zh-cn.messages.json +4 -0
- package/locales/zh-tw/zh-tw.messages.json +4 -0
- package/package.json +1 -1
- package/types/nanahoshi-mona-ui-button-group.d.ts +13 -3
- package/types/nanahoshi-mona-ui-button.d.ts +20 -3
- package/types/nanahoshi-mona-ui-contextmenu.d.ts +5 -6
- package/types/nanahoshi-mona-ui-dialog.d.ts +131 -20
- package/types/nanahoshi-mona-ui-dropdown-button.d.ts +75 -56
- package/types/nanahoshi-mona-ui-i18n.d.ts +19 -0
- package/types/nanahoshi-mona-ui-internal.d.ts +119 -15
- package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +4 -0
- package/types/nanahoshi-mona-ui-locales-de-de.d.ts +4 -0
- package/types/nanahoshi-mona-ui-locales-es-es.d.ts +4 -0
- package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +4 -0
- package/types/nanahoshi-mona-ui-locales-id-id.d.ts +4 -0
- package/types/nanahoshi-mona-ui-locales-it-it.d.ts +4 -0
- package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +4 -0
- package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +4 -0
- package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +4 -0
- package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +4 -0
- package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +4 -0
- package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +4 -0
- package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +4 -0
- package/types/nanahoshi-mona-ui-menubar.d.ts +65 -62
- package/types/nanahoshi-mona-ui-notification.d.ts +76 -16
- package/types/nanahoshi-mona-ui-popover.d.ts +44 -17
- package/types/nanahoshi-mona-ui-popup-menu.d.ts +110 -32
- package/types/nanahoshi-mona-ui-popup.d.ts +2 -0
- package/types/nanahoshi-mona-ui-sheet.d.ts +16 -5
- package/types/nanahoshi-mona-ui-split-button.d.ts +29 -7
- package/types/nanahoshi-mona-ui-tooltip.d.ts +43 -20
- 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,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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 {
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
144
|
-
...(ngDevMode ? [{ debugName: "
|
|
145
|
-
this.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
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.
|
|
154
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
|
173
|
-
|
|
174
|
-
|
|
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.#
|
|
293
|
+
this.#listenForWindowFocus();
|
|
294
|
+
this.#destroyRef.onDestroy(() => {
|
|
295
|
+
this.#stopTimers();
|
|
296
|
+
this.data().finish();
|
|
297
|
+
});
|
|
179
298
|
}
|
|
180
299
|
close() {
|
|
181
|
-
this.data().
|
|
182
|
-
}
|
|
183
|
-
onInteractionEnd() {
|
|
184
|
-
this.#paused.set(false);
|
|
300
|
+
this.data().close();
|
|
185
301
|
}
|
|
186
|
-
|
|
187
|
-
this.#
|
|
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
|
-
|
|
190
|
-
const
|
|
191
|
-
if (
|
|
314
|
+
onFocusOut(event) {
|
|
315
|
+
const to = event.relatedTarget;
|
|
316
|
+
if (to instanceof Node && this.#host.nativeElement.contains(to)) {
|
|
192
317
|
return;
|
|
193
318
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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": "
|
|
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
|
-
"
|
|
227
|
-
"
|
|
228
|
-
"
|
|
229
|
-
"(
|
|
230
|
-
|
|
231
|
-
|
|
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.
|
|
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.
|
|
244
|
-
|
|
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
|
|
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
|
-
"[
|
|
259
|
-
|
|
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
|
-
#
|
|
265
|
-
#
|
|
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.#
|
|
284
|
-
this.#
|
|
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
|
|
289
|
-
|
|
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.
|
|
295
|
-
container.notifications.
|
|
296
|
-
|
|
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
|
|
303
|
-
const
|
|
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
|
-
|
|
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
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
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
|
-
|
|
330
|
-
|
|
331
|
-
const
|
|
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
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
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
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
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
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
return notificationData;
|
|
395
|
-
}
|
|
644
|
+
#destroyContainer(container) {
|
|
645
|
+
const { componentRef } = container;
|
|
646
|
+
if (!componentRef.hostView.destroyed) {
|
|
647
|
+
componentRef.destroy();
|
|
396
648
|
}
|
|
397
|
-
|
|
649
|
+
componentRef.location.nativeElement.remove();
|
|
398
650
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
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.
|
|
431
|
-
|
|
432
|
-
|
|
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
|
-
|
|
436
|
-
|
|
437
|
-
|
|
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
|
-
|
|
449
|
-
|
|
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
|