mn-angular-lib 2.0.33 → 2.0.35
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/mn-angular-lib-alert.mjs +515 -527
- package/fesm2022/mn-angular-lib-alert.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-bottom-sheet.mjs +264 -357
- package/fesm2022/mn-angular-lib-bottom-sheet.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-button.mjs +819 -382
- package/fesm2022/mn-angular-lib-button.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-calendar-core.mjs +240 -365
- package/fesm2022/mn-angular-lib-calendar-core.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-calendar.mjs +1691 -1545
- package/fesm2022/mn-angular-lib-calendar.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-collection.mjs +2367 -2796
- package/fesm2022/mn-angular-lib-collection.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-core.mjs +693 -1241
- package/fesm2022/mn-angular-lib-core.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-display.mjs +679 -712
- package/fesm2022/mn-angular-lib-display.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-forms.mjs +3671 -4647
- package/fesm2022/mn-angular-lib-forms.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-keyboard.mjs +221 -190
- package/fesm2022/mn-angular-lib-keyboard.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-modal-core.mjs +711 -896
- package/fesm2022/mn-angular-lib-modal-core.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-modal-ui.mjs +2089 -2035
- package/fesm2022/mn-angular-lib-modal-ui.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-modal.mjs +76 -121
- package/fesm2022/mn-angular-lib-modal.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-rich-text-editor.mjs +289 -277
- package/fesm2022/mn-angular-lib-rich-text-editor.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-segmented.mjs +189 -241
- package/fesm2022/mn-angular-lib-segmented.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-tab.mjs +409 -642
- package/fesm2022/mn-angular-lib-tab.mjs.map +1 -1
- package/fesm2022/mn-angular-lib.mjs +16 -29
- package/package.json +1 -1
- package/types/mn-angular-lib-alert.d.ts +239 -241
- package/types/mn-angular-lib-bottom-sheet.d.ts +190 -150
- package/types/mn-angular-lib-button.d.ts +319 -317
- package/types/mn-angular-lib-calendar-core.d.ts +199 -209
- package/types/mn-angular-lib-calendar.d.ts +656 -511
- package/types/mn-angular-lib-collection.d.ts +1649 -1585
- package/types/mn-angular-lib-core.d.ts +524 -535
- package/types/mn-angular-lib-display.d.ts +946 -886
- package/types/mn-angular-lib-forms.d.ts +3012 -3013
- package/types/mn-angular-lib-keyboard.d.ts +125 -85
- package/types/mn-angular-lib-modal-core.d.ts +978 -994
- package/types/mn-angular-lib-modal-ui.d.ts +541 -493
- package/types/mn-angular-lib-modal.d.ts +24 -27
- package/types/mn-angular-lib-rich-text-editor.d.ts +131 -98
- package/types/mn-angular-lib-segmented.d.ts +354 -341
- package/types/mn-angular-lib-tab.d.ts +345 -336
- package/types/mn-angular-lib.d.ts +16 -16
- package/fesm2022/mn-angular-lib.mjs.map +0 -1
|
@@ -1,536 +1,524 @@
|
|
|
1
|
-
import * as i0 from
|
|
2
|
-
import {
|
|
3
|
-
import { BehaviorSubject } from
|
|
4
|
-
import { takeUntilDestroyed } from
|
|
5
|
-
import * as i1 from
|
|
6
|
-
import { CommonModule } from
|
|
7
|
-
import { tv } from
|
|
8
|
-
import { MnButton } from
|
|
9
|
-
import { MnLanguageService } from
|
|
10
|
-
|
|
11
|
-
// projects/mn-angular-lib/src/lib/mn-mn-alert/mn-mn-alert.tokens.ts
|
|
12
|
-
const MN_ALERT_CONFIG = new InjectionToken('MN_ALERT_CONFIG');
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { ChangeDetectionStrategy, Component, DestroyRef, Injectable, InjectionToken, Input, inject, signal } from "@angular/core";
|
|
3
|
+
import { BehaviorSubject } from "rxjs";
|
|
4
|
+
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
|
|
5
|
+
import * as i1 from "@angular/common";
|
|
6
|
+
import { CommonModule } from "@angular/common";
|
|
7
|
+
import { tv } from "tailwind-variants";
|
|
8
|
+
import { MnButton } from "mn-angular-lib/button";
|
|
9
|
+
import { MnLanguageService } from "mn-angular-lib/core";
|
|
10
|
+
const MN_ALERT_CONFIG = new InjectionToken("MN_ALERT_CONFIG");
|
|
13
11
|
const DEFAULT_MN_ALERT_CONFIG = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
12
|
+
durations: {
|
|
13
|
+
success: 3e3,
|
|
14
|
+
info: 4e3,
|
|
15
|
+
warning: 5e3,
|
|
16
|
+
error: 7e3,
|
|
17
|
+
default: 4e3
|
|
18
|
+
},
|
|
19
|
+
cssClasses: {
|
|
20
|
+
success: "mn-alert-success",
|
|
21
|
+
info: "mn-alert-info",
|
|
22
|
+
warning: "mn-alert-warning",
|
|
23
|
+
error: "mn-alert-error",
|
|
24
|
+
default: "alert"
|
|
25
|
+
},
|
|
26
|
+
icons: {},
|
|
27
|
+
fallbackDuration: 4e3,
|
|
28
|
+
maxVisible: 3,
|
|
29
|
+
finalize: (a) => a
|
|
26
30
|
};
|
|
27
|
-
|
|
28
31
|
function provideMnAlerts(config = {}) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
const merged = {
|
|
33
|
+
...DEFAULT_MN_ALERT_CONFIG,
|
|
34
|
+
...config,
|
|
35
|
+
durations: {
|
|
36
|
+
...DEFAULT_MN_ALERT_CONFIG.durations,
|
|
37
|
+
...config.durations ?? {}
|
|
38
|
+
},
|
|
39
|
+
cssClasses: {
|
|
40
|
+
...DEFAULT_MN_ALERT_CONFIG.cssClasses,
|
|
41
|
+
...config.cssClasses ?? {}
|
|
42
|
+
},
|
|
43
|
+
icons: {
|
|
44
|
+
...DEFAULT_MN_ALERT_CONFIG.icons,
|
|
45
|
+
...config.icons ?? {}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
provide: MN_ALERT_CONFIG,
|
|
50
|
+
useValue: merged
|
|
51
|
+
};
|
|
37
52
|
}
|
|
38
|
-
|
|
39
53
|
let COUNTER = 0;
|
|
40
54
|
const uid = () => `mn_${++COUNTER}`;
|
|
41
|
-
class MnAlertStore {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
55
|
+
var MnAlertStore = class MnAlertStore {
|
|
56
|
+
_alerts$ = new BehaviorSubject([]);
|
|
57
|
+
alerts$ = this._alerts$.asObservable();
|
|
58
|
+
cfg = inject(MN_ALERT_CONFIG, { optional: true });
|
|
59
|
+
timers = /* @__PURE__ */ new Map();
|
|
60
|
+
get maxVisible() {
|
|
61
|
+
const configured = this.cfg?.maxVisible;
|
|
62
|
+
return typeof configured === "number" && configured > 0 ? configured : DEFAULT_MN_ALERT_CONFIG.maxVisible;
|
|
63
|
+
}
|
|
64
|
+
show(partial) {
|
|
65
|
+
const computedDuration = partial.duration ?? DEFAULT_MN_ALERT_CONFIG.durations[partial.kind ?? ""] ?? DEFAULT_MN_ALERT_CONFIG.fallbackDuration;
|
|
66
|
+
const a = {
|
|
67
|
+
id: uid(),
|
|
68
|
+
...partial,
|
|
69
|
+
duration: computedDuration
|
|
70
|
+
};
|
|
71
|
+
const queued = [...this._alerts$.value, a];
|
|
72
|
+
const overflow = queued.length - this.maxVisible;
|
|
73
|
+
if (overflow > 0) queued.splice(0, overflow).forEach((dropped) => this.clearTimer(dropped.id));
|
|
74
|
+
this._alerts$.next(queued);
|
|
75
|
+
if (typeof a.duration === "number" && a.duration > 0) this.timers.set(a.id, setTimeout(() => this.dismiss(a.id), a.duration));
|
|
76
|
+
return a.id;
|
|
77
|
+
}
|
|
78
|
+
dismiss(id) {
|
|
79
|
+
const list = this._alerts$.value;
|
|
80
|
+
if (list.some((x) => x.id === id)) {
|
|
81
|
+
this.clearTimer(id);
|
|
82
|
+
this._alerts$.next(list.filter((x) => x.id !== id));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
clear() {
|
|
86
|
+
this.timers.forEach((t) => clearTimeout(t));
|
|
87
|
+
this.timers.clear();
|
|
88
|
+
this._alerts$.next([]);
|
|
89
|
+
}
|
|
90
|
+
clearTimer(id) {
|
|
91
|
+
const timer = this.timers.get(id);
|
|
92
|
+
if (timer !== void 0) {
|
|
93
|
+
clearTimeout(timer);
|
|
94
|
+
this.timers.delete(id);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
98
|
+
minVersion: "12.0.0",
|
|
99
|
+
version: "22.2.2",
|
|
100
|
+
ngImport: i0,
|
|
101
|
+
type: MnAlertStore,
|
|
102
|
+
deps: [],
|
|
103
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
104
|
+
});
|
|
105
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
106
|
+
minVersion: "12.0.0",
|
|
107
|
+
version: "22.2.2",
|
|
108
|
+
ngImport: i0,
|
|
109
|
+
type: MnAlertStore,
|
|
110
|
+
providedIn: "root"
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
114
|
+
minVersion: "12.0.0",
|
|
115
|
+
version: "22.2.2",
|
|
116
|
+
ngImport: i0,
|
|
117
|
+
type: MnAlertStore,
|
|
118
|
+
decorators: [{
|
|
119
|
+
type: Injectable,
|
|
120
|
+
args: [{ providedIn: "root" }]
|
|
121
|
+
}]
|
|
122
|
+
});
|
|
123
|
+
var MnAlertService = class MnAlertService {
|
|
124
|
+
store = inject(MnAlertStore);
|
|
125
|
+
cfg;
|
|
126
|
+
userDurations;
|
|
127
|
+
hasUserDurations;
|
|
128
|
+
constructor() {
|
|
129
|
+
const cfg = inject(MN_ALERT_CONFIG, { optional: true });
|
|
130
|
+
this.userDurations = cfg?.durations;
|
|
131
|
+
this.hasUserDurations = !!cfg?.durations;
|
|
132
|
+
this.cfg = {
|
|
133
|
+
...DEFAULT_MN_ALERT_CONFIG,
|
|
134
|
+
...cfg ?? {},
|
|
135
|
+
durations: DEFAULT_MN_ALERT_CONFIG.durations,
|
|
136
|
+
cssClasses: {
|
|
137
|
+
...DEFAULT_MN_ALERT_CONFIG.cssClasses,
|
|
138
|
+
...cfg?.cssClasses ?? {}
|
|
139
|
+
},
|
|
140
|
+
icons: {
|
|
141
|
+
...DEFAULT_MN_ALERT_CONFIG.icons,
|
|
142
|
+
...cfg?.icons ?? {}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
show(input) {
|
|
147
|
+
let duration = input.duration;
|
|
148
|
+
if (duration == null) {
|
|
149
|
+
const userDefault = this.cfg.fallbackDuration;
|
|
150
|
+
if (typeof userDefault === "number") duration = userDefault;
|
|
151
|
+
else duration = DEFAULT_MN_ALERT_CONFIG.durations[input.kind];
|
|
152
|
+
}
|
|
153
|
+
const a = {
|
|
154
|
+
title: input.title,
|
|
155
|
+
subTitle: input.subTitle,
|
|
156
|
+
duration,
|
|
157
|
+
icon: input.icon,
|
|
158
|
+
cssClass: input.cssClass,
|
|
159
|
+
meta: input.meta,
|
|
160
|
+
kind: input.kind,
|
|
161
|
+
variant: input.variant
|
|
162
|
+
};
|
|
163
|
+
return this.store.show(this.cfg.finalize(a));
|
|
164
|
+
}
|
|
165
|
+
success(title, subTitle, extra) {
|
|
166
|
+
return this.kind("success", title, subTitle, extra);
|
|
167
|
+
}
|
|
168
|
+
info(title, subTitle, extra) {
|
|
169
|
+
return this.kind("info", title, subTitle, extra);
|
|
170
|
+
}
|
|
171
|
+
warning(title, subTitle, extra) {
|
|
172
|
+
return this.kind("warning", title, subTitle, extra);
|
|
173
|
+
}
|
|
174
|
+
error(title, subTitle, extra) {
|
|
175
|
+
return this.kind("error", title, subTitle, extra);
|
|
176
|
+
}
|
|
177
|
+
dismiss(id) {
|
|
178
|
+
this.store.dismiss(id);
|
|
179
|
+
}
|
|
180
|
+
clear() {
|
|
181
|
+
this.store.clear();
|
|
182
|
+
}
|
|
183
|
+
kind(kind, title, subTitle, extra) {
|
|
184
|
+
let duration = extra?.duration;
|
|
185
|
+
if (duration == null) {
|
|
186
|
+
if (this.hasUserDurations) {
|
|
187
|
+
const userDur = this.userDurations?.[kind];
|
|
188
|
+
if (typeof userDur === "number") duration = userDur;
|
|
189
|
+
else if (typeof this.cfg.fallbackDuration === "number") duration = this.cfg.fallbackDuration;
|
|
190
|
+
else duration = this.cfg.durations[kind];
|
|
191
|
+
} else duration = this.cfg.durations[kind];
|
|
192
|
+
}
|
|
193
|
+
const cssClass = extra?.cssClass ?? this.cfg.cssClasses[kind];
|
|
194
|
+
const icon = extra?.icon ?? this.cfg.icons[kind];
|
|
195
|
+
const variant = extra?.variant;
|
|
196
|
+
return this.show({
|
|
197
|
+
title,
|
|
198
|
+
subTitle,
|
|
199
|
+
duration,
|
|
200
|
+
cssClass,
|
|
201
|
+
icon,
|
|
202
|
+
meta: extra?.meta,
|
|
203
|
+
kind,
|
|
204
|
+
variant
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
208
|
+
minVersion: "12.0.0",
|
|
209
|
+
version: "22.2.2",
|
|
210
|
+
ngImport: i0,
|
|
211
|
+
type: MnAlertService,
|
|
212
|
+
deps: [],
|
|
213
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
214
|
+
});
|
|
215
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
216
|
+
minVersion: "12.0.0",
|
|
217
|
+
version: "22.2.2",
|
|
218
|
+
ngImport: i0,
|
|
219
|
+
type: MnAlertService,
|
|
220
|
+
providedIn: "root"
|
|
221
|
+
});
|
|
222
|
+
};
|
|
223
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
224
|
+
minVersion: "12.0.0",
|
|
225
|
+
version: "22.2.2",
|
|
226
|
+
ngImport: i0,
|
|
227
|
+
type: MnAlertService,
|
|
228
|
+
decorators: [{
|
|
229
|
+
type: Injectable,
|
|
230
|
+
args: [{ providedIn: "root" }]
|
|
231
|
+
}],
|
|
232
|
+
ctorParameters: () => []
|
|
233
|
+
});
|
|
195
234
|
const mnAlertVariants = tv({
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
235
|
+
base: "flex items-start gap-3 p-4 border rounded-xl shadow-sm w-full ",
|
|
236
|
+
variants: {
|
|
237
|
+
kind: {
|
|
238
|
+
success: "bg-success/10 border-success/30 text-success",
|
|
239
|
+
info: "bg-info/10 border-info/30 text-info",
|
|
240
|
+
warning: "bg-warning/10 border-warning/30 text-warning",
|
|
241
|
+
error: "bg-error/10 border-error/30 text-error",
|
|
242
|
+
default: "bg-base-100 border-base-300 text-base-content",
|
|
243
|
+
accent: "bg-accent/10 border-accent/30 text-accent"
|
|
244
|
+
},
|
|
245
|
+
variant: {
|
|
246
|
+
fill: "",
|
|
247
|
+
outline: "bg-base-200 border-2",
|
|
248
|
+
soft: "border-none shadow-none"
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
compoundVariants: [
|
|
252
|
+
{
|
|
253
|
+
kind: "success",
|
|
254
|
+
variant: "fill",
|
|
255
|
+
class: "bg-success border-success text-success-content"
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
kind: "info",
|
|
259
|
+
variant: "fill",
|
|
260
|
+
class: "bg-info border-info text-info-content"
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
kind: "warning",
|
|
264
|
+
variant: "fill",
|
|
265
|
+
class: "bg-warning border-warning text-warning-content"
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
kind: "error",
|
|
269
|
+
variant: "fill",
|
|
270
|
+
class: "bg-error border-error text-error-content"
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
kind: "accent",
|
|
274
|
+
variant: "fill",
|
|
275
|
+
class: "bg-accent border-accent text-accent-content"
|
|
276
|
+
}
|
|
277
|
+
],
|
|
278
|
+
defaultVariants: {
|
|
279
|
+
kind: "info",
|
|
280
|
+
variant: "soft"
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
var MnAlertOutletComponent = class MnAlertOutletComponent {
|
|
284
|
+
lang = inject(MnLanguageService);
|
|
285
|
+
store = inject(MnAlertStore);
|
|
286
|
+
destroyRef = inject(DestroyRef);
|
|
287
|
+
static SWIPE_DISMISS_THRESHOLD = 96;
|
|
288
|
+
static FLICK_VELOCITY = .4;
|
|
289
|
+
static FLICK_MIN_DISTANCE = 24;
|
|
290
|
+
static EXIT_MS = 320;
|
|
291
|
+
static DRAG_OPACITY_FLOOR = .35;
|
|
292
|
+
swipeAxis = "auto";
|
|
293
|
+
isApple = this.detectApple();
|
|
294
|
+
get vertical() {
|
|
295
|
+
if (this.swipeAxis === "vertical") return true;
|
|
296
|
+
if (this.swipeAxis === "horizontal") return false;
|
|
297
|
+
return this.isApple;
|
|
298
|
+
}
|
|
299
|
+
get closeLabel() {
|
|
300
|
+
return this.lang.translateIfPresent("mnAlert.close") ?? "Close";
|
|
301
|
+
}
|
|
302
|
+
template;
|
|
303
|
+
views = signal([], ...ngDevMode ? [{ debugName: "views" }] : /* istanbul ignore next */ []);
|
|
304
|
+
get touchAction() {
|
|
305
|
+
return this.vertical ? "pan-x" : "pan-y";
|
|
306
|
+
}
|
|
307
|
+
exitTimers = /* @__PURE__ */ new Map();
|
|
308
|
+
activeDrag = null;
|
|
309
|
+
constructor() {
|
|
310
|
+
this.store.alerts$.pipe(takeUntilDestroyed()).subscribe((alerts) => this.sync(alerts));
|
|
311
|
+
this.destroyRef.onDestroy(() => {
|
|
312
|
+
this.exitTimers.forEach((t) => clearTimeout(t));
|
|
313
|
+
this.exitTimers.clear();
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
trackById = (_, v) => v.alert.id;
|
|
317
|
+
getAlertClasses(a) {
|
|
318
|
+
return mnAlertVariants({
|
|
319
|
+
kind: a.kind,
|
|
320
|
+
variant: a.variant
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
countdownDuration(v) {
|
|
324
|
+
if (v.leaving) return null;
|
|
325
|
+
const duration = v.alert.duration;
|
|
326
|
+
return typeof duration === "number" && duration > 0 ? duration : null;
|
|
327
|
+
}
|
|
328
|
+
contextFor(a) {
|
|
329
|
+
return {
|
|
330
|
+
$implicit: a,
|
|
331
|
+
alert: a,
|
|
332
|
+
dismiss: () => this.dismissAlert(a.id)
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
dismissAlert(id) {
|
|
336
|
+
this.store.dismiss(id);
|
|
337
|
+
}
|
|
338
|
+
sync(alerts) {
|
|
339
|
+
const current = this.views();
|
|
340
|
+
const existing = new Set(current.map((v) => v.alert.id));
|
|
341
|
+
const storeById = new Map(alerts.map((a) => [a.id, a]));
|
|
342
|
+
const next = [];
|
|
343
|
+
for (const v of current) {
|
|
344
|
+
const fresh = storeById.get(v.alert.id);
|
|
345
|
+
if (fresh) v.alert = fresh;
|
|
346
|
+
else if (!v.leaving) this.beginLeave(v);
|
|
347
|
+
next.push(v);
|
|
348
|
+
}
|
|
349
|
+
for (const a of alerts) if (!existing.has(a.id)) next.push({
|
|
350
|
+
alert: a,
|
|
351
|
+
leaving: false,
|
|
352
|
+
dragging: false,
|
|
353
|
+
drag: 0,
|
|
354
|
+
fling: 0
|
|
355
|
+
});
|
|
356
|
+
this.views.set(next);
|
|
357
|
+
}
|
|
358
|
+
beginLeave(v, fling) {
|
|
359
|
+
if (v.leaving) return;
|
|
360
|
+
v.leaving = true;
|
|
361
|
+
v.dragging = false;
|
|
362
|
+
if (fling !== void 0) v.fling = fling;
|
|
363
|
+
const delay = this.prefersReducedMotion() ? 0 : MnAlertOutletComponent.EXIT_MS;
|
|
364
|
+
const timer = setTimeout(() => this.removeView(v.alert.id), delay);
|
|
365
|
+
this.exitTimers.set(v.alert.id, timer);
|
|
366
|
+
}
|
|
367
|
+
removeView(id) {
|
|
368
|
+
const timer = this.exitTimers.get(id);
|
|
369
|
+
if (timer) {
|
|
370
|
+
clearTimeout(timer);
|
|
371
|
+
this.exitTimers.delete(id);
|
|
372
|
+
}
|
|
373
|
+
this.views.update((list) => list.filter((v) => v.alert.id !== id));
|
|
374
|
+
}
|
|
375
|
+
onPointerDown(event, v) {
|
|
376
|
+
if (v.leaving) return;
|
|
377
|
+
if (event.target.closest("button, a, input, textarea, select")) return;
|
|
378
|
+
if (event.button !== void 0 && event.button !== 0) return;
|
|
379
|
+
const coord = this.axisCoord(event);
|
|
380
|
+
this.activeDrag = {
|
|
381
|
+
view: v,
|
|
382
|
+
startCoord: coord,
|
|
383
|
+
lastSample: {
|
|
384
|
+
c: coord,
|
|
385
|
+
t: event.timeStamp
|
|
386
|
+
},
|
|
387
|
+
prevSample: {
|
|
388
|
+
c: coord,
|
|
389
|
+
t: event.timeStamp
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
v.dragging = true;
|
|
393
|
+
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
394
|
+
}
|
|
395
|
+
onPointerMove(event, v) {
|
|
396
|
+
const drag = this.activeDrag;
|
|
397
|
+
if (!drag || drag.view !== v) return;
|
|
398
|
+
const delta = this.axisCoord(event) - drag.startCoord;
|
|
399
|
+
v.drag = this.vertical ? Math.min(0, delta) : Math.max(0, delta);
|
|
400
|
+
drag.prevSample = drag.lastSample;
|
|
401
|
+
drag.lastSample = {
|
|
402
|
+
c: this.axisCoord(event),
|
|
403
|
+
t: event.timeStamp
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
onPointerUp(event, v) {
|
|
407
|
+
const drag = this.activeDrag;
|
|
408
|
+
if (!drag || drag.view !== v) return;
|
|
409
|
+
this.activeDrag = null;
|
|
410
|
+
v.dragging = false;
|
|
411
|
+
if (this.shouldDismiss(drag, v)) {
|
|
412
|
+
const extent = this.viewportExtent() + Math.abs(v.drag);
|
|
413
|
+
const fling = this.vertical ? -extent : extent;
|
|
414
|
+
this.beginLeave(v, fling);
|
|
415
|
+
this.store.dismiss(v.alert.id);
|
|
416
|
+
} else v.drag = 0;
|
|
417
|
+
this.views.update((list) => [...list]);
|
|
418
|
+
}
|
|
419
|
+
shouldDismiss(drag, v) {
|
|
420
|
+
if (Math.abs(v.drag) > MnAlertOutletComponent.SWIPE_DISMISS_THRESHOLD) return true;
|
|
421
|
+
const dt = drag.lastSample.t - drag.prevSample.t;
|
|
422
|
+
return (dt > 0 ? Math.abs(drag.lastSample.c - drag.prevSample.c) / dt : 0) > MnAlertOutletComponent.FLICK_VELOCITY && Math.abs(v.drag) > MnAlertOutletComponent.FLICK_MIN_DISTANCE;
|
|
423
|
+
}
|
|
424
|
+
itemTransform(v) {
|
|
425
|
+
if (v.leaving) return v.fling !== 0 ? this.translate(v.fling) : null;
|
|
426
|
+
return v.drag !== 0 ? this.translate(v.drag) : null;
|
|
427
|
+
}
|
|
428
|
+
itemOpacity(v) {
|
|
429
|
+
if (v.leaving || !v.dragging || v.drag === 0) return null;
|
|
430
|
+
return 1 - Math.min(Math.abs(v.drag) / MnAlertOutletComponent.SWIPE_DISMISS_THRESHOLD, 1) * (1 - MnAlertOutletComponent.DRAG_OPACITY_FLOOR);
|
|
431
|
+
}
|
|
432
|
+
translate(px) {
|
|
433
|
+
return this.vertical ? `translateY(${px}px)` : `translateX(${px}px)`;
|
|
434
|
+
}
|
|
435
|
+
axisCoord(event) {
|
|
436
|
+
return this.vertical ? event.clientY : event.clientX;
|
|
437
|
+
}
|
|
438
|
+
viewportExtent() {
|
|
439
|
+
if (typeof window === "undefined") return 400;
|
|
440
|
+
return this.vertical ? window.innerHeight : window.innerWidth;
|
|
441
|
+
}
|
|
442
|
+
detectApple() {
|
|
443
|
+
if (typeof navigator === "undefined") return false;
|
|
444
|
+
const ua = navigator.userAgent ?? "";
|
|
445
|
+
const platform = navigator.platform ?? "";
|
|
446
|
+
const isIOS = /iP(hone|ad|od)/.test(platform) || /iPad|iPhone|iPod/.test(ua);
|
|
447
|
+
const isTouchMac = /Mac/.test(platform + " " + ua) && typeof document !== "undefined" && "ontouchend" in document;
|
|
448
|
+
const isMac = /Mac/.test(ua);
|
|
449
|
+
return isIOS || isTouchMac || isMac;
|
|
450
|
+
}
|
|
451
|
+
prefersReducedMotion() {
|
|
452
|
+
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
453
|
+
}
|
|
454
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
455
|
+
minVersion: "12.0.0",
|
|
456
|
+
version: "22.2.2",
|
|
457
|
+
ngImport: i0,
|
|
458
|
+
type: MnAlertOutletComponent,
|
|
459
|
+
deps: [],
|
|
460
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
461
|
+
});
|
|
462
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
463
|
+
minVersion: "17.0.0",
|
|
464
|
+
version: "22.2.2",
|
|
465
|
+
type: MnAlertOutletComponent,
|
|
466
|
+
isStandalone: true,
|
|
467
|
+
selector: "mn-alert-outlet",
|
|
468
|
+
inputs: {
|
|
469
|
+
swipeAxis: "swipeAxis",
|
|
470
|
+
template: "template"
|
|
471
|
+
},
|
|
472
|
+
ngImport: i0,
|
|
473
|
+
template: "<!-- The stack is a polite live region so every toast is announced; an error toast upgrades itself to an alert. -->\n<div aria-live=\"polite\" role=\"status\" class=\"fixed top-4 left-0 right-0 z-[9999] flex flex-col w-full px-2 sm:px-0 sm:left-auto sm:right-4 sm:max-w-sm\">\n @for (v of views(); track trackById($index, v)) {\n <div\n class=\"mn-alert-item\"\n [attr.role]=\"v.alert.kind === 'error' ? 'alert' : null\"\n [class.dragging]=\"v.dragging\"\n [class.leaving]=\"v.leaving\"\n [style.touch-action]=\"touchAction\"\n [style.transform]=\"itemTransform(v)\"\n [style.opacity]=\"itemOpacity(v)\"\n (pointerdown)=\"onPointerDown($event, v)\"\n (pointermove)=\"onPointerMove($event, v)\"\n (pointerup)=\"onPointerUp($event, v)\"\n (pointercancel)=\"onPointerUp($event, v)\"\n >\n <div class=\"mn-alert-inner\">\n @if (template) {\n <ng-container\n [ngTemplateOutlet]=\"template\"\n [ngTemplateOutletContext]=\"contextFor(v.alert)\">\n </ng-container>\n } @else {\n <div [class.extra]=\"v.alert.cssClass\" [class]=\"getAlertClasses(v.alert)\" class=\"relative overflow-hidden\">\n <div class=\"flex-1 min-w-0 pr-8\">\n <h4 class=\"font-semibold text-sm\">{{ v.alert.title }}</h4>\n @if (v.alert.subTitle) {\n <p class=\"text-sm mt-1 opacity-90 leading-tight\">{{ v.alert.subTitle }}</p>\n }\n </div>\n <button\n [attr.aria-label]=\"closeLabel\"\n mnButton\n [data]=\"{ size: 'md', variant: 'text' }\"\n (click)=\"dismissAlert(v.alert.id)\"\n class=\"absolute top-2 right-2 shrink-0 !text-current hover:!bg-current/10\"\n type=\"button\"\n >\n ×\n </button>\n @if (countdownDuration(v); as ms) {\n <span aria-hidden=\"true\" class=\"mn-alert-progress\">\n <span [style.animation-duration.ms]=\"ms\" class=\"mn-alert-progress-bar\"></span>\n </span>\n }\n </div>\n }\n </div>\n </div>\n }\n</div>\n",
|
|
474
|
+
styles: [":host{--mn-alert-exit: .32s}.mn-alert-item{display:grid;grid-template-rows:1fr;margin-bottom:.75rem;touch-action:pan-y;cursor:grab;transition:transform .28s cubic-bezier(.22,1,.36,1),opacity var(--mn-alert-exit) ease,grid-template-rows var(--mn-alert-exit) cubic-bezier(.4,0,.2,1),margin-bottom var(--mn-alert-exit) cubic-bezier(.4,0,.2,1)}.mn-alert-item:last-child{margin-bottom:0}.mn-alert-item.dragging{transition:none;cursor:grabbing;-webkit-user-select:none;user-select:none}.mn-alert-inner{min-height:0}.mn-alert-item.leaving{grid-template-rows:0fr;opacity:0;margin-bottom:0;pointer-events:none}.mn-alert-item.leaving .mn-alert-inner{overflow:hidden}.mn-alert-progress{position:absolute;left:0;right:0;bottom:0;height:3px;overflow:hidden;background-color:color-mix(in srgb,currentColor 18%,transparent);pointer-events:none}.mn-alert-progress-bar{display:block;height:100%;background-color:currentColor;opacity:.55;transform-origin:left center;animation-name:mn-alert-countdown;animation-timing-function:linear;animation-fill-mode:forwards}@keyframes mn-alert-countdown{0%{transform:scaleX(1)}to{transform:scaleX(0)}}@media(prefers-reduced-motion:reduce){.mn-alert-item{transition:none}}\n"],
|
|
475
|
+
dependencies: [
|
|
476
|
+
{
|
|
477
|
+
kind: "ngmodule",
|
|
478
|
+
type: CommonModule
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
kind: "directive",
|
|
482
|
+
type: i1.NgTemplateOutlet,
|
|
483
|
+
selector: "[ngTemplateOutlet]",
|
|
484
|
+
inputs: [
|
|
485
|
+
"ngTemplateOutletContext",
|
|
486
|
+
"ngTemplateOutlet",
|
|
487
|
+
"ngTemplateOutletInjector"
|
|
488
|
+
]
|
|
489
|
+
},
|
|
490
|
+
{
|
|
491
|
+
kind: "component",
|
|
492
|
+
type: MnButton,
|
|
493
|
+
selector: "button[mnButton], a[mnButton]",
|
|
494
|
+
inputs: ["data"]
|
|
495
|
+
}
|
|
496
|
+
],
|
|
497
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush
|
|
498
|
+
});
|
|
499
|
+
};
|
|
500
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
501
|
+
minVersion: "12.0.0",
|
|
502
|
+
version: "22.2.2",
|
|
503
|
+
ngImport: i0,
|
|
504
|
+
type: MnAlertOutletComponent,
|
|
505
|
+
decorators: [{
|
|
506
|
+
type: Component,
|
|
507
|
+
args: [{
|
|
508
|
+
selector: "mn-alert-outlet",
|
|
509
|
+
standalone: true,
|
|
510
|
+
imports: [CommonModule, MnButton],
|
|
511
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
512
|
+
template: "<!-- The stack is a polite live region so every toast is announced; an error toast upgrades itself to an alert. -->\n<div aria-live=\"polite\" role=\"status\" class=\"fixed top-4 left-0 right-0 z-[9999] flex flex-col w-full px-2 sm:px-0 sm:left-auto sm:right-4 sm:max-w-sm\">\n @for (v of views(); track trackById($index, v)) {\n <div\n class=\"mn-alert-item\"\n [attr.role]=\"v.alert.kind === 'error' ? 'alert' : null\"\n [class.dragging]=\"v.dragging\"\n [class.leaving]=\"v.leaving\"\n [style.touch-action]=\"touchAction\"\n [style.transform]=\"itemTransform(v)\"\n [style.opacity]=\"itemOpacity(v)\"\n (pointerdown)=\"onPointerDown($event, v)\"\n (pointermove)=\"onPointerMove($event, v)\"\n (pointerup)=\"onPointerUp($event, v)\"\n (pointercancel)=\"onPointerUp($event, v)\"\n >\n <div class=\"mn-alert-inner\">\n @if (template) {\n <ng-container\n [ngTemplateOutlet]=\"template\"\n [ngTemplateOutletContext]=\"contextFor(v.alert)\">\n </ng-container>\n } @else {\n <div [class.extra]=\"v.alert.cssClass\" [class]=\"getAlertClasses(v.alert)\" class=\"relative overflow-hidden\">\n <div class=\"flex-1 min-w-0 pr-8\">\n <h4 class=\"font-semibold text-sm\">{{ v.alert.title }}</h4>\n @if (v.alert.subTitle) {\n <p class=\"text-sm mt-1 opacity-90 leading-tight\">{{ v.alert.subTitle }}</p>\n }\n </div>\n <button\n [attr.aria-label]=\"closeLabel\"\n mnButton\n [data]=\"{ size: 'md', variant: 'text' }\"\n (click)=\"dismissAlert(v.alert.id)\"\n class=\"absolute top-2 right-2 shrink-0 !text-current hover:!bg-current/10\"\n type=\"button\"\n >\n ×\n </button>\n @if (countdownDuration(v); as ms) {\n <span aria-hidden=\"true\" class=\"mn-alert-progress\">\n <span [style.animation-duration.ms]=\"ms\" class=\"mn-alert-progress-bar\"></span>\n </span>\n }\n </div>\n }\n </div>\n </div>\n }\n</div>\n",
|
|
513
|
+
styles: [":host{--mn-alert-exit: .32s}.mn-alert-item{display:grid;grid-template-rows:1fr;margin-bottom:.75rem;touch-action:pan-y;cursor:grab;transition:transform .28s cubic-bezier(.22,1,.36,1),opacity var(--mn-alert-exit) ease,grid-template-rows var(--mn-alert-exit) cubic-bezier(.4,0,.2,1),margin-bottom var(--mn-alert-exit) cubic-bezier(.4,0,.2,1)}.mn-alert-item:last-child{margin-bottom:0}.mn-alert-item.dragging{transition:none;cursor:grabbing;-webkit-user-select:none;user-select:none}.mn-alert-inner{min-height:0}.mn-alert-item.leaving{grid-template-rows:0fr;opacity:0;margin-bottom:0;pointer-events:none}.mn-alert-item.leaving .mn-alert-inner{overflow:hidden}.mn-alert-progress{position:absolute;left:0;right:0;bottom:0;height:3px;overflow:hidden;background-color:color-mix(in srgb,currentColor 18%,transparent);pointer-events:none}.mn-alert-progress-bar{display:block;height:100%;background-color:currentColor;opacity:.55;transform-origin:left center;animation-name:mn-alert-countdown;animation-timing-function:linear;animation-fill-mode:forwards}@keyframes mn-alert-countdown{0%{transform:scaleX(1)}to{transform:scaleX(0)}}@media(prefers-reduced-motion:reduce){.mn-alert-item{transition:none}}\n"]
|
|
514
|
+
}]
|
|
515
|
+
}],
|
|
516
|
+
ctorParameters: () => [],
|
|
517
|
+
propDecorators: {
|
|
518
|
+
swipeAxis: [{ type: Input }],
|
|
519
|
+
template: [{ type: Input }]
|
|
520
|
+
}
|
|
243
521
|
});
|
|
244
|
-
|
|
245
|
-
class MnAlertOutletComponent {
|
|
246
|
-
lang = inject(MnLanguageService);
|
|
247
|
-
store = inject(MnAlertStore);
|
|
248
|
-
destroyRef = inject(DestroyRef);
|
|
249
|
-
/** Drag distance (px) past which a release dismisses regardless of speed. */
|
|
250
|
-
static SWIPE_DISMISS_THRESHOLD = 96;
|
|
251
|
-
/** Release speed (px/ms) above which a short drag still dismisses — a "flick". */
|
|
252
|
-
static FLICK_VELOCITY = 0.4;
|
|
253
|
-
/** Minimum drag distance (px) a flick must cover, so an incidental fast tap never dismisses. */
|
|
254
|
-
static FLICK_MIN_DISTANCE = 24;
|
|
255
|
-
/** Upper bound for the leave wait; kept a touch longer than the CSS exit so removal never
|
|
256
|
-
* preempts the animation. Mirrored by the `--mn-alert-exit` duration in the stylesheet. */
|
|
257
|
-
static EXIT_MS = 320;
|
|
258
|
-
/** Opacity floor a card fades to at the dismiss threshold, for drag feedback. */
|
|
259
|
-
static DRAG_OPACITY_FLOOR = 0.35;
|
|
260
|
-
/**
|
|
261
|
-
* How the dismiss swipe is oriented:
|
|
262
|
-
* - `'auto'` (default) matches the host platform's convention — Apple platforms
|
|
263
|
-
* (iOS/iPadOS/macOS) flick a top banner *upward*, so we swipe vertically; Android (and
|
|
264
|
-
* every other platform) dismisses toasts *to the right*, so we swipe horizontally.
|
|
265
|
-
*
|
|
266
|
-
* Either axis is one-directional: only an upward (vertical) or rightward (horizontal)
|
|
267
|
-
* drag dismisses; dragging the opposite way springs the card back.
|
|
268
|
-
* - `'vertical'` / `'horizontal'` force the axis regardless of platform. Useful when the
|
|
269
|
-
* host can't be sniffed reliably (e.g. Chrome DevTools *Responsive* mode does not spoof
|
|
270
|
-
* the user agent, so `'auto'` there resolves to the desktop/Android horizontal axis).
|
|
271
|
-
*/
|
|
272
|
-
swipeAxis = 'auto';
|
|
273
|
-
/** Whether the running device is an Apple platform. Sniffed once from `navigator` at
|
|
274
|
-
* construction (the UA is read at page load and does not change mid-session). */
|
|
275
|
-
isApple = this.detectApple();
|
|
276
|
-
/** The resolved swipe axis: the explicit {@link swipeAxis} override, or the platform
|
|
277
|
-
* default when left on `'auto'`. */
|
|
278
|
-
get vertical() {
|
|
279
|
-
if (this.swipeAxis === 'vertical')
|
|
280
|
-
return true;
|
|
281
|
-
if (this.swipeAxis === 'horizontal')
|
|
282
|
-
return false;
|
|
283
|
-
return this.isApple;
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* Accessible name for this control. Resolved through the conventional
|
|
287
|
-
* `mnAlert.close` key so an app can translate it, falling back to English when the
|
|
288
|
-
* key is not defined rather than leaking the raw key into the UI.
|
|
289
|
-
*/
|
|
290
|
-
get closeLabel() {
|
|
291
|
-
return this.lang.translateIfPresent('mnAlert.close') ?? 'Close';
|
|
292
|
-
}
|
|
293
|
-
template;
|
|
294
|
-
/** The view-layer mirror of the store's alerts, retaining alerts mid-leave. A signal so
|
|
295
|
-
* writes from the (external) store subscription and leave timers schedule change
|
|
296
|
-
* detection in a zoneless app. */
|
|
297
|
-
views = signal([], /* @ts-ignore */
|
|
298
|
-
...(ngDevMode ? [{ debugName: "views" }] : /* istanbul ignore next */ []));
|
|
299
|
-
/**
|
|
300
|
-
* `touch-action` for the swipe wrapper: reserve the swipe axis for our gesture while
|
|
301
|
-
* leaving the cross-axis to the browser. Vertical swipe (Apple) claims the Y axis
|
|
302
|
-
* (`pan-x`); horizontal swipe (Android/other) claims the X axis (`pan-y`).
|
|
303
|
-
*/
|
|
304
|
-
get touchAction() {
|
|
305
|
-
return this.vertical ? 'pan-x' : 'pan-y';
|
|
306
|
-
}
|
|
307
|
-
/** In-flight leave-removal timers, keyed by alert id, cleared on destroy so a fired
|
|
308
|
-
* timer never touches a torn-down view. */
|
|
309
|
-
exitTimers = new Map();
|
|
310
|
-
/** The single active swipe, or null. Only one card is dragged at a time. `startCoord`
|
|
311
|
-
* and the samples are taken along the active axis (Y when vertical, else X). */
|
|
312
|
-
activeDrag = null;
|
|
313
|
-
constructor() {
|
|
314
|
-
this.store.alerts$
|
|
315
|
-
.pipe(takeUntilDestroyed())
|
|
316
|
-
.subscribe(alerts => this.sync(alerts));
|
|
317
|
-
this.destroyRef.onDestroy(() => {
|
|
318
|
-
this.exitTimers.forEach(t => clearTimeout(t));
|
|
319
|
-
this.exitTimers.clear();
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
trackById = (_, v) => v.alert.id;
|
|
323
|
-
getAlertClasses(a) {
|
|
324
|
-
return mnAlertVariants({ kind: a.kind, variant: a.variant });
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* The lifetime (ms) to run the countdown bar over, or null when no bar should show: an alert
|
|
328
|
-
* that never auto-dismisses has nothing to count down, and one already leaving would only
|
|
329
|
-
* restart the animation mid-exit.
|
|
330
|
-
*/
|
|
331
|
-
countdownDuration(v) {
|
|
332
|
-
if (v.leaving)
|
|
333
|
-
return null;
|
|
334
|
-
const duration = v.alert.duration;
|
|
335
|
-
return typeof duration === 'number' && duration > 0 ? duration : null;
|
|
336
|
-
}
|
|
337
|
-
contextFor(a) {
|
|
338
|
-
return {
|
|
339
|
-
$implicit: a,
|
|
340
|
-
alert: a,
|
|
341
|
-
dismiss: () => this.dismissAlert(a.id)
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
/** Dismisses via the store; the store's removal is turned into a leave animation by
|
|
345
|
-
* {@link sync}. Used by the close button and the custom-template `dismiss` context. */
|
|
346
|
-
dismissAlert(id) {
|
|
347
|
-
this.store.dismiss(id);
|
|
348
|
-
}
|
|
349
|
-
// =========================
|
|
350
|
-
// Store → view reconciliation
|
|
351
|
-
// =========================
|
|
352
|
-
/** Reconciles the view list against the store: appends new alerts, updates the alert
|
|
353
|
-
* reference for still-present ones, and marks vanished ones as leaving (they stay in the
|
|
354
|
-
* list, animating out, until their removal timer fires). */
|
|
355
|
-
sync(alerts) {
|
|
356
|
-
const current = this.views();
|
|
357
|
-
const existing = new Set(current.map(v => v.alert.id));
|
|
358
|
-
const storeById = new Map(alerts.map(a => [a.id, a]));
|
|
359
|
-
const next = [];
|
|
360
|
-
for (const v of current) {
|
|
361
|
-
const fresh = storeById.get(v.alert.id);
|
|
362
|
-
if (fresh) {
|
|
363
|
-
v.alert = fresh;
|
|
364
|
-
}
|
|
365
|
-
else if (!v.leaving) {
|
|
366
|
-
this.beginLeave(v);
|
|
367
|
-
}
|
|
368
|
-
next.push(v);
|
|
369
|
-
}
|
|
370
|
-
for (const a of alerts) {
|
|
371
|
-
if (!existing.has(a.id)) {
|
|
372
|
-
next.push({ alert: a, leaving: false, dragging: false, drag: 0, fling: 0 });
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
this.views.set(next);
|
|
376
|
-
}
|
|
377
|
-
/** Flags a view as leaving and schedules its removal once the exit animation has run.
|
|
378
|
-
* Idempotent: a card already leaving (e.g. flung by a swipe) is left untouched, so a
|
|
379
|
-
* synchronous store re-emit cannot overwrite the swipe direction with the default fade. */
|
|
380
|
-
beginLeave(v, fling) {
|
|
381
|
-
if (v.leaving)
|
|
382
|
-
return;
|
|
383
|
-
v.leaving = true;
|
|
384
|
-
v.dragging = false;
|
|
385
|
-
if (fling !== undefined)
|
|
386
|
-
v.fling = fling;
|
|
387
|
-
const delay = this.prefersReducedMotion() ? 0 : MnAlertOutletComponent.EXIT_MS;
|
|
388
|
-
const timer = setTimeout(() => this.removeView(v.alert.id), delay);
|
|
389
|
-
this.exitTimers.set(v.alert.id, timer);
|
|
390
|
-
}
|
|
391
|
-
removeView(id) {
|
|
392
|
-
const timer = this.exitTimers.get(id);
|
|
393
|
-
if (timer) {
|
|
394
|
-
clearTimeout(timer);
|
|
395
|
-
this.exitTimers.delete(id);
|
|
396
|
-
}
|
|
397
|
-
this.views.update(list => list.filter(v => v.alert.id !== id));
|
|
398
|
-
}
|
|
399
|
-
// =========================
|
|
400
|
-
// Swipe-to-dismiss
|
|
401
|
-
// =========================
|
|
402
|
-
onPointerDown(event, v) {
|
|
403
|
-
if (v.leaving)
|
|
404
|
-
return;
|
|
405
|
-
// Don't hijack a press that begins on an interactive control inside the alert.
|
|
406
|
-
if (event.target.closest('button, a, input, textarea, select'))
|
|
407
|
-
return;
|
|
408
|
-
if (event.button !== undefined && event.button !== 0)
|
|
409
|
-
return;
|
|
410
|
-
const coord = this.axisCoord(event);
|
|
411
|
-
this.activeDrag = {
|
|
412
|
-
view: v,
|
|
413
|
-
startCoord: coord,
|
|
414
|
-
lastSample: { c: coord, t: event.timeStamp },
|
|
415
|
-
prevSample: { c: coord, t: event.timeStamp },
|
|
416
|
-
};
|
|
417
|
-
v.dragging = true;
|
|
418
|
-
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
419
|
-
}
|
|
420
|
-
onPointerMove(event, v) {
|
|
421
|
-
const drag = this.activeDrag;
|
|
422
|
-
if (!drag || drag.view !== v)
|
|
423
|
-
return;
|
|
424
|
-
const delta = this.axisCoord(event) - drag.startCoord;
|
|
425
|
-
// Dismissal is one-directional: vertical (Apple) tracks upward only (clamp ≤ 0),
|
|
426
|
-
// horizontal (Android/other) tracks rightward only (clamp ≥ 0). A drag the other way
|
|
427
|
-
// rests at 0 and springs back.
|
|
428
|
-
v.drag = this.vertical ? Math.min(0, delta) : Math.max(0, delta);
|
|
429
|
-
drag.prevSample = drag.lastSample;
|
|
430
|
-
drag.lastSample = { c: this.axisCoord(event), t: event.timeStamp };
|
|
431
|
-
}
|
|
432
|
-
onPointerUp(event, v) {
|
|
433
|
-
const drag = this.activeDrag;
|
|
434
|
-
if (!drag || drag.view !== v)
|
|
435
|
-
return;
|
|
436
|
-
this.activeDrag = null;
|
|
437
|
-
v.dragging = false;
|
|
438
|
-
if (this.shouldDismiss(drag, v)) {
|
|
439
|
-
// Fling the card the rest of the way off its edge, then dismiss through the store.
|
|
440
|
-
// Vertical flings upward (off the top); horizontal flings rightward (off the right).
|
|
441
|
-
const extent = this.viewportExtent() + Math.abs(v.drag);
|
|
442
|
-
const fling = this.vertical ? -extent : extent;
|
|
443
|
-
this.beginLeave(v, fling);
|
|
444
|
-
this.store.dismiss(v.alert.id);
|
|
445
|
-
}
|
|
446
|
-
else {
|
|
447
|
-
// Snap back to rest; the wrapper's transition eases the offset → 0.
|
|
448
|
-
v.drag = 0;
|
|
449
|
-
}
|
|
450
|
-
// Notify: pointerup is template-bound (schedules CD), but the leave/snap mutations live
|
|
451
|
-
// on the view object — re-set the signal so the new transform is reflected reliably.
|
|
452
|
-
this.views.update(list => [...list]);
|
|
453
|
-
}
|
|
454
|
-
shouldDismiss(drag, v) {
|
|
455
|
-
if (Math.abs(v.drag) > MnAlertOutletComponent.SWIPE_DISMISS_THRESHOLD)
|
|
456
|
-
return true;
|
|
457
|
-
const dt = drag.lastSample.t - drag.prevSample.t;
|
|
458
|
-
const velocity = dt > 0 ? Math.abs(drag.lastSample.c - drag.prevSample.c) / dt : 0;
|
|
459
|
-
return velocity > MnAlertOutletComponent.FLICK_VELOCITY
|
|
460
|
-
&& Math.abs(v.drag) > MnAlertOutletComponent.FLICK_MIN_DISTANCE;
|
|
461
|
-
}
|
|
462
|
-
// =========================
|
|
463
|
-
// Template style helpers
|
|
464
|
-
// =========================
|
|
465
|
-
/** Offset transform for a card: the fling target while leaving via swipe, otherwise the
|
|
466
|
-
* live drag offset, translated along the active axis. Returns null when neither applies,
|
|
467
|
-
* letting the stylesheet own the default (fade-in-place) leave. */
|
|
468
|
-
itemTransform(v) {
|
|
469
|
-
if (v.leaving) {
|
|
470
|
-
return v.fling !== 0 ? this.translate(v.fling) : null;
|
|
471
|
-
}
|
|
472
|
-
return v.drag !== 0 ? this.translate(v.drag) : null;
|
|
473
|
-
}
|
|
474
|
-
/** Fades a card toward a floor as it is dragged toward the dismiss threshold. Null (CSS
|
|
475
|
-
* owns opacity) when at rest or leaving. */
|
|
476
|
-
itemOpacity(v) {
|
|
477
|
-
if (v.leaving || !v.dragging || v.drag === 0)
|
|
478
|
-
return null;
|
|
479
|
-
const progress = Math.min(Math.abs(v.drag) / MnAlertOutletComponent.SWIPE_DISMISS_THRESHOLD, 1);
|
|
480
|
-
return 1 - progress * (1 - MnAlertOutletComponent.DRAG_OPACITY_FLOOR);
|
|
481
|
-
}
|
|
482
|
-
translate(px) {
|
|
483
|
-
return this.vertical ? `translateY(${px}px)` : `translateX(${px}px)`;
|
|
484
|
-
}
|
|
485
|
-
axisCoord(event) {
|
|
486
|
-
return this.vertical ? event.clientY : event.clientX;
|
|
487
|
-
}
|
|
488
|
-
viewportExtent() {
|
|
489
|
-
if (typeof window === 'undefined')
|
|
490
|
-
return 400;
|
|
491
|
-
return this.vertical ? window.innerHeight : window.innerWidth;
|
|
492
|
-
}
|
|
493
|
-
/** Whether the current device runs an Apple OS (iOS/iPadOS/macOS). iPadOS 13+ masquerades
|
|
494
|
-
* as a Mac, so it is caught by the touch-capable-Mac branch. */
|
|
495
|
-
detectApple() {
|
|
496
|
-
if (typeof navigator === 'undefined')
|
|
497
|
-
return false;
|
|
498
|
-
const ua = navigator.userAgent ?? '';
|
|
499
|
-
const platform = navigator.platform ?? '';
|
|
500
|
-
const isIOS = /iP(hone|ad|od)/.test(platform) || /iPad|iPhone|iPod/.test(ua);
|
|
501
|
-
const isTouchMac = /Mac/.test(platform + ' ' + ua)
|
|
502
|
-
&& typeof document !== 'undefined' && 'ontouchend' in document;
|
|
503
|
-
const isMac = /Mac/.test(ua);
|
|
504
|
-
return isIOS || isTouchMac || isMac;
|
|
505
|
-
}
|
|
506
|
-
prefersReducedMotion() {
|
|
507
|
-
return typeof window !== 'undefined'
|
|
508
|
-
&& typeof window.matchMedia === 'function'
|
|
509
|
-
&& window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
510
|
-
}
|
|
511
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: MnAlertOutletComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
512
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.7", type: MnAlertOutletComponent, isStandalone: true, selector: "mn-alert-outlet", inputs: { swipeAxis: "swipeAxis", template: "template" }, ngImport: i0, template: "<!-- The stack is a polite live region so every toast is announced; an error toast upgrades itself to an alert. -->\n<div aria-live=\"polite\" role=\"status\" class=\"fixed top-4 left-0 right-0 z-[9999] flex flex-col w-full px-2 sm:px-0 sm:left-auto sm:right-4 sm:max-w-sm\">\n @for (v of views(); track trackById($index, v)) {\n <div\n class=\"mn-alert-item\"\n [attr.role]=\"v.alert.kind === 'error' ? 'alert' : null\"\n [class.dragging]=\"v.dragging\"\n [class.leaving]=\"v.leaving\"\n [style.touch-action]=\"touchAction\"\n [style.transform]=\"itemTransform(v)\"\n [style.opacity]=\"itemOpacity(v)\"\n (pointerdown)=\"onPointerDown($event, v)\"\n (pointermove)=\"onPointerMove($event, v)\"\n (pointerup)=\"onPointerUp($event, v)\"\n (pointercancel)=\"onPointerUp($event, v)\"\n >\n <div class=\"mn-alert-inner\">\n @if (template) {\n <ng-container\n [ngTemplateOutlet]=\"template\"\n [ngTemplateOutletContext]=\"contextFor(v.alert)\">\n </ng-container>\n } @else {\n <div [class.extra]=\"v.alert.cssClass\" [class]=\"getAlertClasses(v.alert)\" class=\"relative overflow-hidden\">\n <div class=\"flex-1 min-w-0 pr-8\">\n <h4 class=\"font-semibold text-sm\">{{ v.alert.title }}</h4>\n @if (v.alert.subTitle) {\n <p class=\"text-sm mt-1 opacity-90 leading-tight\">{{ v.alert.subTitle }}</p>\n }\n </div>\n <button\n [attr.aria-label]=\"closeLabel\"\n mnButton\n [data]=\"{ size: 'md', variant: 'text' }\"\n (click)=\"dismissAlert(v.alert.id)\"\n class=\"absolute top-2 right-2 shrink-0 !text-current hover:!bg-current/10\"\n type=\"button\"\n >\n ×\n </button>\n @if (countdownDuration(v); as ms) {\n <span aria-hidden=\"true\" class=\"mn-alert-progress\">\n <span [style.animation-duration.ms]=\"ms\" class=\"mn-alert-progress-bar\"></span>\n </span>\n }\n </div>\n }\n </div>\n </div>\n }\n</div>\n", styles: [":host{--mn-alert-exit: .32s}.mn-alert-item{display:grid;grid-template-rows:1fr;margin-bottom:.75rem;touch-action:pan-y;cursor:grab;transition:transform .28s cubic-bezier(.22,1,.36,1),opacity var(--mn-alert-exit) ease,grid-template-rows var(--mn-alert-exit) cubic-bezier(.4,0,.2,1),margin-bottom var(--mn-alert-exit) cubic-bezier(.4,0,.2,1)}.mn-alert-item:last-child{margin-bottom:0}.mn-alert-item.dragging{transition:none;cursor:grabbing;-webkit-user-select:none;user-select:none}.mn-alert-inner{min-height:0}.mn-alert-item.leaving{grid-template-rows:0fr;opacity:0;margin-bottom:0;pointer-events:none}.mn-alert-item.leaving .mn-alert-inner{overflow:hidden}.mn-alert-progress{position:absolute;left:0;right:0;bottom:0;height:3px;overflow:hidden;background-color:color-mix(in srgb,currentColor 18%,transparent);pointer-events:none}.mn-alert-progress-bar{display:block;height:100%;background-color:currentColor;opacity:.55;transform-origin:left center;animation-name:mn-alert-countdown;animation-timing-function:linear;animation-fill-mode:forwards}@keyframes mn-alert-countdown{0%{transform:scaleX(1)}to{transform:scaleX(0)}}@media(prefers-reduced-motion:reduce){.mn-alert-item{transition:none}}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "component", type: MnButton, selector: "button[mnButton], a[mnButton]", inputs: ["data"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
513
|
-
}
|
|
514
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: MnAlertOutletComponent, decorators: [{
|
|
515
|
-
type: Component,
|
|
516
|
-
args: [{ selector: 'mn-alert-outlet', standalone: true, imports: [CommonModule, MnButton], changeDetection: ChangeDetectionStrategy.OnPush, template: "<!-- The stack is a polite live region so every toast is announced; an error toast upgrades itself to an alert. -->\n<div aria-live=\"polite\" role=\"status\" class=\"fixed top-4 left-0 right-0 z-[9999] flex flex-col w-full px-2 sm:px-0 sm:left-auto sm:right-4 sm:max-w-sm\">\n @for (v of views(); track trackById($index, v)) {\n <div\n class=\"mn-alert-item\"\n [attr.role]=\"v.alert.kind === 'error' ? 'alert' : null\"\n [class.dragging]=\"v.dragging\"\n [class.leaving]=\"v.leaving\"\n [style.touch-action]=\"touchAction\"\n [style.transform]=\"itemTransform(v)\"\n [style.opacity]=\"itemOpacity(v)\"\n (pointerdown)=\"onPointerDown($event, v)\"\n (pointermove)=\"onPointerMove($event, v)\"\n (pointerup)=\"onPointerUp($event, v)\"\n (pointercancel)=\"onPointerUp($event, v)\"\n >\n <div class=\"mn-alert-inner\">\n @if (template) {\n <ng-container\n [ngTemplateOutlet]=\"template\"\n [ngTemplateOutletContext]=\"contextFor(v.alert)\">\n </ng-container>\n } @else {\n <div [class.extra]=\"v.alert.cssClass\" [class]=\"getAlertClasses(v.alert)\" class=\"relative overflow-hidden\">\n <div class=\"flex-1 min-w-0 pr-8\">\n <h4 class=\"font-semibold text-sm\">{{ v.alert.title }}</h4>\n @if (v.alert.subTitle) {\n <p class=\"text-sm mt-1 opacity-90 leading-tight\">{{ v.alert.subTitle }}</p>\n }\n </div>\n <button\n [attr.aria-label]=\"closeLabel\"\n mnButton\n [data]=\"{ size: 'md', variant: 'text' }\"\n (click)=\"dismissAlert(v.alert.id)\"\n class=\"absolute top-2 right-2 shrink-0 !text-current hover:!bg-current/10\"\n type=\"button\"\n >\n ×\n </button>\n @if (countdownDuration(v); as ms) {\n <span aria-hidden=\"true\" class=\"mn-alert-progress\">\n <span [style.animation-duration.ms]=\"ms\" class=\"mn-alert-progress-bar\"></span>\n </span>\n }\n </div>\n }\n </div>\n </div>\n }\n</div>\n", styles: [":host{--mn-alert-exit: .32s}.mn-alert-item{display:grid;grid-template-rows:1fr;margin-bottom:.75rem;touch-action:pan-y;cursor:grab;transition:transform .28s cubic-bezier(.22,1,.36,1),opacity var(--mn-alert-exit) ease,grid-template-rows var(--mn-alert-exit) cubic-bezier(.4,0,.2,1),margin-bottom var(--mn-alert-exit) cubic-bezier(.4,0,.2,1)}.mn-alert-item:last-child{margin-bottom:0}.mn-alert-item.dragging{transition:none;cursor:grabbing;-webkit-user-select:none;user-select:none}.mn-alert-inner{min-height:0}.mn-alert-item.leaving{grid-template-rows:0fr;opacity:0;margin-bottom:0;pointer-events:none}.mn-alert-item.leaving .mn-alert-inner{overflow:hidden}.mn-alert-progress{position:absolute;left:0;right:0;bottom:0;height:3px;overflow:hidden;background-color:color-mix(in srgb,currentColor 18%,transparent);pointer-events:none}.mn-alert-progress-bar{display:block;height:100%;background-color:currentColor;opacity:.55;transform-origin:left center;animation-name:mn-alert-countdown;animation-timing-function:linear;animation-fill-mode:forwards}@keyframes mn-alert-countdown{0%{transform:scaleX(1)}to{transform:scaleX(0)}}@media(prefers-reduced-motion:reduce){.mn-alert-item{transition:none}}\n"] }]
|
|
517
|
-
}], ctorParameters: () => [], propDecorators: { swipeAxis: [{
|
|
518
|
-
type: Input
|
|
519
|
-
}], template: [{
|
|
520
|
-
type: Input
|
|
521
|
-
}] } });
|
|
522
|
-
|
|
523
|
-
/**
|
|
524
|
-
* Public API of the `mn-angular-lib/alert` entry point: toast alerts.
|
|
525
|
-
*
|
|
526
|
-
* Each entry point is its own module in the published package, so a consumer's bundler
|
|
527
|
-
* splits it into the chunk that uses it instead of loading the whole library at startup.
|
|
528
|
-
* The root `mn-angular-lib` entry re-exports every entry point.
|
|
529
|
-
*/
|
|
530
|
-
|
|
531
|
-
/**
|
|
532
|
-
* Generated bundle index. Do not edit.
|
|
533
|
-
*/
|
|
534
|
-
|
|
535
522
|
export { DEFAULT_MN_ALERT_CONFIG, MN_ALERT_CONFIG, MnAlertOutletComponent, MnAlertService, MnAlertStore, mnAlertVariants, provideMnAlerts };
|
|
536
|
-
|
|
523
|
+
|
|
524
|
+
//# sourceMappingURL=mn-angular-lib-alert.mjs.map
|