@etsoo/notificationbase 1.1.52 → 1.1.53
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/.github/workflows/main.yml +6 -5
- package/README.md +25 -23
- package/__tests__/Notification.ts +81 -81
- package/__tests__/tsconfig.json +15 -15
- package/babel.config.json +8 -8
- package/lib/cjs/Notification.d.ts +1 -1
- package/lib/cjs/NotificationContainer.d.ts +1 -1
- package/lib/cjs/NotificationContainer.js +1 -1
- package/lib/cjs/index.d.ts +2 -2
- package/lib/mjs/Notification.d.ts +1 -1
- package/lib/mjs/Notification.js +1 -1
- package/lib/mjs/NotificationContainer.d.ts +1 -1
- package/lib/mjs/NotificationContainer.js +2 -2
- package/lib/mjs/index.d.ts +2 -2
- package/lib/mjs/index.js +2 -2
- package/package.json +7 -7
- package/src/Notification.ts +349 -349
- package/src/NotificationContainer.ts +569 -572
- package/src/index.ts +2 -2
- package/tsconfig.cjs.json +15 -15
- package/tsconfig.json +15 -15
- package/.eslintignore +0 -3
- package/.eslintrc.json +0 -29
- package/.prettierignore +0 -5
- package/.prettierrc +0 -6
|
@@ -1,607 +1,604 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} from
|
|
2
|
+
INotificaseBase,
|
|
3
|
+
INotification,
|
|
4
|
+
NotificationAlign,
|
|
5
|
+
NotificationCallProps,
|
|
6
|
+
NotificationContent,
|
|
7
|
+
NotificationMessageType,
|
|
8
|
+
NotificationModalType,
|
|
9
|
+
NotificationParameters,
|
|
10
|
+
NotificationReturn,
|
|
11
|
+
NotificationType
|
|
12
|
+
} from "./Notification";
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Notification action
|
|
16
16
|
*/
|
|
17
17
|
export interface NotificationAction<UI, C extends NotificationCallProps> {
|
|
18
|
-
|
|
18
|
+
(notification: INotification<UI, C>, dismiss: boolean): void;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Notifications sorted with display align type
|
|
23
23
|
*/
|
|
24
24
|
export type NotificationDictionary<UI, C extends NotificationCallProps> = {
|
|
25
|
-
|
|
25
|
+
[key: number]: INotification<UI, C>[];
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Notifier interface
|
|
30
30
|
*/
|
|
31
31
|
export interface INotifier<UI, C extends NotificationCallProps> {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Is loading bar showing
|
|
34
|
+
*/
|
|
35
|
+
readonly isLoading: boolean;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Is model window showing
|
|
39
|
+
*/
|
|
40
|
+
readonly isModeling: boolean;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Loading count
|
|
44
|
+
*/
|
|
45
|
+
readonly loadingCount: number;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Is debug mode
|
|
49
|
+
*/
|
|
50
|
+
debug: boolean;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Add notification
|
|
54
|
+
* @param notification Notification
|
|
55
|
+
* @param top Is insert top
|
|
56
|
+
*/
|
|
57
|
+
add(notification: INotification<UI, C>, top?: boolean): void;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Report error or message
|
|
61
|
+
* @param errorOrTitle Error message or title
|
|
62
|
+
* @param callback Callback
|
|
63
|
+
* @param type Type, default is Error
|
|
64
|
+
* @param props Props
|
|
65
|
+
*/
|
|
66
|
+
alert(
|
|
67
|
+
errorOrTitle:
|
|
68
|
+
| NotificationContent<UI>
|
|
69
|
+
| [NotificationContent<UI>, NotificationContent<UI>],
|
|
70
|
+
callback?: NotificationReturn<void>,
|
|
71
|
+
type?: NotificationMessageType,
|
|
72
|
+
props?: C
|
|
73
|
+
): INotification<UI, C>;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Align all notification count
|
|
77
|
+
* @param align Align
|
|
78
|
+
*/
|
|
79
|
+
alignCount(align: NotificationAlign): number;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Align open notification count
|
|
83
|
+
* @param align Align
|
|
84
|
+
*/
|
|
85
|
+
alignOpenCount(align: NotificationAlign): number;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Remove all closed notification
|
|
89
|
+
*/
|
|
90
|
+
clear(): void;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Confirm action
|
|
94
|
+
* @param message Message
|
|
95
|
+
* @param title Title
|
|
96
|
+
* @param callback Callback
|
|
97
|
+
* @param props Props
|
|
98
|
+
*/
|
|
99
|
+
confirm(
|
|
100
|
+
message: NotificationContent<UI>,
|
|
101
|
+
title?: NotificationContent<UI>,
|
|
102
|
+
callback?: NotificationReturn<boolean>,
|
|
103
|
+
props?: C
|
|
104
|
+
): INotification<UI, C>;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Dispose all notifications
|
|
108
|
+
*/
|
|
109
|
+
dispose(): void;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Get notification with align and id
|
|
113
|
+
* @param align Align
|
|
114
|
+
* @param id Notification id
|
|
115
|
+
*/
|
|
116
|
+
get(align: NotificationAlign, id: string): INotification<UI, C> | undefined;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Get notification with id
|
|
120
|
+
* @param id Notification id
|
|
121
|
+
*/
|
|
122
|
+
getById(id: string): INotification<UI, C> | undefined;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Hide loading
|
|
126
|
+
* @param force Force to hide, otherwise, only the last one
|
|
127
|
+
*/
|
|
128
|
+
hideLoading(force?: boolean): void;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Show a message
|
|
132
|
+
* @param type Message type
|
|
133
|
+
* @param message Message
|
|
134
|
+
* @param title Title
|
|
135
|
+
* @param parameters Parameters
|
|
136
|
+
* @param props Props
|
|
137
|
+
*/
|
|
138
|
+
message(
|
|
139
|
+
type: NotificationMessageType,
|
|
140
|
+
message: NotificationContent<UI>,
|
|
141
|
+
title?: NotificationContent<UI>,
|
|
142
|
+
parameters?: NotificationParameters,
|
|
143
|
+
props?: C
|
|
144
|
+
): INotification<UI, C>;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Popup component as modal
|
|
148
|
+
* @param component Component to popup
|
|
149
|
+
* @param properties Popup properties
|
|
150
|
+
* @returns Result
|
|
151
|
+
*/
|
|
152
|
+
popup(
|
|
153
|
+
component: NotificationContent<UI>,
|
|
154
|
+
properties: any
|
|
155
|
+
): INotification<UI, C>;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Prompt action
|
|
159
|
+
* @param message Message
|
|
160
|
+
* @param callback Callback
|
|
161
|
+
* @param title Title
|
|
162
|
+
* @param props More properties
|
|
163
|
+
*/
|
|
164
|
+
prompt<T = string | undefined>(
|
|
165
|
+
message: NotificationContent<UI>,
|
|
166
|
+
callback: NotificationReturn<T>,
|
|
167
|
+
title?: NotificationContent<UI>,
|
|
168
|
+
props?: C
|
|
169
|
+
): INotification<UI, C>;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Show loading
|
|
173
|
+
* @param title Title
|
|
174
|
+
*/
|
|
175
|
+
showLoading(title?: NotificationContent<UI>): void;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Show a success message
|
|
179
|
+
* @param message Message
|
|
180
|
+
* @param title Title
|
|
181
|
+
* @param callback Callback
|
|
182
|
+
* @param timespan Timespan to close
|
|
183
|
+
* @param props Props
|
|
184
|
+
*/
|
|
185
|
+
succeed(
|
|
186
|
+
message: NotificationContent<UI>,
|
|
187
|
+
title?: NotificationContent<UI>,
|
|
188
|
+
callback?: NotificationReturn<void>,
|
|
189
|
+
timespan?: number,
|
|
190
|
+
props?: C
|
|
191
|
+
): INotification<UI, C>;
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
/**
|
|
195
195
|
* Notification container class
|
|
196
196
|
*/
|
|
197
197
|
export abstract class NotificationContainer<UI, C extends NotificationCallProps>
|
|
198
|
-
|
|
198
|
+
implements INotifier<UI, C>
|
|
199
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
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Add raw definition
|
|
260
|
-
* @param data Notification data definition
|
|
261
|
-
* @param modal Show as modal
|
|
262
|
-
*/
|
|
263
|
-
protected abstract addRaw(
|
|
264
|
-
data: INotificaseBase<UI, C>,
|
|
265
|
-
modal?: boolean
|
|
266
|
-
): INotification<UI, C>;
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Add notification
|
|
270
|
-
* @param notification Notification
|
|
271
|
-
* @param top Is insert top
|
|
272
|
-
*/
|
|
273
|
-
add(notification: INotification<UI, C>, top: boolean = false): void {
|
|
274
|
-
// Align collection
|
|
275
|
-
const alignItems = this.notifications[notification.align];
|
|
276
|
-
|
|
277
|
-
// Support dismiss action
|
|
278
|
-
const { timespan, onDismiss } = notification;
|
|
279
|
-
notification.onDismiss = () => {
|
|
280
|
-
// Remove from the collection
|
|
281
|
-
alignItems.remove((n) => n.id === notification.id);
|
|
282
|
-
|
|
283
|
-
// Call the registered callback
|
|
284
|
-
this.doRegister(notification, true);
|
|
285
|
-
|
|
286
|
-
// Custom onDismiss callback
|
|
287
|
-
if (onDismiss) onDismiss();
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
// Add to the collection
|
|
291
|
-
if (top) alignItems.unshift(notification);
|
|
292
|
-
else alignItems.push(notification);
|
|
293
|
-
|
|
294
|
-
// Call the registered callback
|
|
295
|
-
this.doRegister(notification, false);
|
|
296
|
-
|
|
297
|
-
// Auto dismiss in timespan seconds
|
|
298
|
-
if (timespan > 0) notification.dismiss(timespan);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Align all notification count
|
|
303
|
-
* @param align Align
|
|
304
|
-
*/
|
|
305
|
-
alignCount(align: NotificationAlign) {
|
|
306
|
-
return this.notifications[align].length;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* Align open notification count
|
|
311
|
-
* @param align Align
|
|
312
|
-
*/
|
|
313
|
-
alignOpenCount(align: NotificationAlign) {
|
|
314
|
-
const items = this.notifications[align];
|
|
315
|
-
return items.filter((item) => item.open).length;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* Remove all closed notification
|
|
320
|
-
*/
|
|
321
|
-
clear(): void {
|
|
322
|
-
for (const align in this.notifications) {
|
|
323
|
-
// Align items
|
|
324
|
-
const items = this.notifications[align];
|
|
325
|
-
|
|
326
|
-
// Remove closed items
|
|
327
|
-
items.remove((n) => {
|
|
328
|
-
if (!n.open) {
|
|
329
|
-
n.dispose();
|
|
330
|
-
return true;
|
|
331
|
-
}
|
|
332
|
-
return false;
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* Dispose all notifications
|
|
339
|
-
*/
|
|
340
|
-
dispose(): void {
|
|
341
|
-
for (const align in this.notifications) {
|
|
342
|
-
// Align items
|
|
343
|
-
const items = this.notifications[align];
|
|
344
|
-
items.forEach((item) => item.dispose());
|
|
345
|
-
|
|
346
|
-
// Reset
|
|
347
|
-
this.notifications[align] = [];
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* Call register callback
|
|
353
|
-
* @param id Notification id
|
|
354
|
-
* @param dismiss Is dismiss
|
|
355
|
-
*/
|
|
356
|
-
private doRegister(item: INotification<UI, C>, dismiss: boolean): void {
|
|
357
|
-
// Call
|
|
358
|
-
this.update(item, dismiss);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* Get notification with align and id
|
|
363
|
-
* @param align Align
|
|
364
|
-
* @param id Notification id
|
|
365
|
-
*/
|
|
366
|
-
get(
|
|
367
|
-
align: NotificationAlign,
|
|
368
|
-
id: string
|
|
369
|
-
): INotification<UI, C> | undefined {
|
|
370
|
-
const items = this.notifications[align];
|
|
371
|
-
return items.find((item) => item.id === id);
|
|
200
|
+
// Registered update action
|
|
201
|
+
private update: NotificationAction<UI, C>;
|
|
202
|
+
|
|
203
|
+
// Last loading
|
|
204
|
+
private lastLoading?: INotification<UI, C>;
|
|
205
|
+
|
|
206
|
+
private _loadingCount = 0;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Loading count
|
|
210
|
+
*/
|
|
211
|
+
get loadingCount() {
|
|
212
|
+
return this._loadingCount;
|
|
213
|
+
}
|
|
214
|
+
private set loadingCount(value: number) {
|
|
215
|
+
this._loadingCount = value;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Is debug mode
|
|
220
|
+
*/
|
|
221
|
+
debug: boolean = false;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Notification collection to display
|
|
225
|
+
*/
|
|
226
|
+
readonly notifications: NotificationDictionary<UI, C>;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Is loading bar showing
|
|
230
|
+
*/
|
|
231
|
+
get isLoading() {
|
|
232
|
+
return this.notifications[NotificationAlign.Unknown].some(
|
|
233
|
+
(n) => n.open && n.type === NotificationModalType.Loading
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Is model window showing
|
|
239
|
+
*/
|
|
240
|
+
get isModeling() {
|
|
241
|
+
return this.alignOpenCount(NotificationAlign.Unknown) > 0;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Constructor
|
|
246
|
+
*/
|
|
247
|
+
constructor(update: NotificationAction<UI, C>) {
|
|
248
|
+
// Update callback
|
|
249
|
+
this.update = update;
|
|
250
|
+
|
|
251
|
+
// Init notification collection
|
|
252
|
+
this.notifications = {};
|
|
253
|
+
for (const align in NotificationAlign) {
|
|
254
|
+
if (!isNaN(Number(align))) this.notifications[align] = [];
|
|
372
255
|
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Add raw definition
|
|
260
|
+
* @param data Notification data definition
|
|
261
|
+
* @param modal Show as modal
|
|
262
|
+
*/
|
|
263
|
+
protected abstract addRaw(
|
|
264
|
+
data: INotificaseBase<UI, C>,
|
|
265
|
+
modal?: boolean
|
|
266
|
+
): INotification<UI, C>;
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Add notification
|
|
270
|
+
* @param notification Notification
|
|
271
|
+
* @param top Is insert top
|
|
272
|
+
*/
|
|
273
|
+
add(notification: INotification<UI, C>, top: boolean = false): void {
|
|
274
|
+
// Align collection
|
|
275
|
+
const alignItems = this.notifications[notification.align];
|
|
276
|
+
|
|
277
|
+
// Support dismiss action
|
|
278
|
+
const { timespan, onDismiss } = notification;
|
|
279
|
+
notification.onDismiss = () => {
|
|
280
|
+
// Remove from the collection
|
|
281
|
+
alignItems.remove((n) => n.id === notification.id);
|
|
282
|
+
|
|
283
|
+
// Call the registered callback
|
|
284
|
+
this.doRegister(notification, true);
|
|
285
|
+
|
|
286
|
+
// Custom onDismiss callback
|
|
287
|
+
if (onDismiss) onDismiss();
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
// Add to the collection
|
|
291
|
+
if (top) alignItems.unshift(notification);
|
|
292
|
+
else alignItems.push(notification);
|
|
293
|
+
|
|
294
|
+
// Call the registered callback
|
|
295
|
+
this.doRegister(notification, false);
|
|
296
|
+
|
|
297
|
+
// Auto dismiss in timespan seconds
|
|
298
|
+
if (timespan > 0) notification.dismiss(timespan);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Align all notification count
|
|
303
|
+
* @param align Align
|
|
304
|
+
*/
|
|
305
|
+
alignCount(align: NotificationAlign) {
|
|
306
|
+
return this.notifications[align].length;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Align open notification count
|
|
311
|
+
* @param align Align
|
|
312
|
+
*/
|
|
313
|
+
alignOpenCount(align: NotificationAlign) {
|
|
314
|
+
const items = this.notifications[align];
|
|
315
|
+
return items.filter((item) => item.open).length;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Remove all closed notification
|
|
320
|
+
*/
|
|
321
|
+
clear(): void {
|
|
322
|
+
for (const align in this.notifications) {
|
|
323
|
+
// Align items
|
|
324
|
+
const items = this.notifications[align];
|
|
325
|
+
|
|
326
|
+
// Remove closed items
|
|
327
|
+
items.remove((n) => {
|
|
328
|
+
if (!n.open) {
|
|
329
|
+
n.dispose();
|
|
330
|
+
return true;
|
|
382
331
|
}
|
|
383
|
-
return
|
|
332
|
+
return false;
|
|
333
|
+
});
|
|
384
334
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
type?: NotificationMessageType,
|
|
399
|
-
props?: C
|
|
400
|
-
) {
|
|
401
|
-
// Parse messange and title
|
|
402
|
-
let error: NotificationContent<UI>,
|
|
403
|
-
title: NotificationContent<UI> | undefined;
|
|
404
|
-
if (Array.isArray(errorOrTitle)) {
|
|
405
|
-
error = errorOrTitle[0];
|
|
406
|
-
title = errorOrTitle[1];
|
|
407
|
-
} else {
|
|
408
|
-
error = errorOrTitle;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
// Setup
|
|
412
|
-
const n: INotificaseBase<UI, C> = {
|
|
413
|
-
inputProps: props,
|
|
414
|
-
type: type ?? NotificationType.Error,
|
|
415
|
-
title,
|
|
416
|
-
content: error,
|
|
417
|
-
onReturn: callback
|
|
418
|
-
};
|
|
419
|
-
|
|
420
|
-
// Add to the collection
|
|
421
|
-
return this.addRaw(n, true);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Dispose all notifications
|
|
339
|
+
*/
|
|
340
|
+
dispose(): void {
|
|
341
|
+
for (const align in this.notifications) {
|
|
342
|
+
// Align items
|
|
343
|
+
const items = this.notifications[align];
|
|
344
|
+
items.forEach((item) => item.dispose());
|
|
345
|
+
|
|
346
|
+
// Reset
|
|
347
|
+
this.notifications[align] = [];
|
|
422
348
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Call register callback
|
|
353
|
+
* @param id Notification id
|
|
354
|
+
* @param dismiss Is dismiss
|
|
355
|
+
*/
|
|
356
|
+
private doRegister(item: INotification<UI, C>, dismiss: boolean): void {
|
|
357
|
+
// Call
|
|
358
|
+
this.update(item, dismiss);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Get notification with align and id
|
|
363
|
+
* @param align Align
|
|
364
|
+
* @param id Notification id
|
|
365
|
+
*/
|
|
366
|
+
get(align: NotificationAlign, id: string): INotification<UI, C> | undefined {
|
|
367
|
+
const items = this.notifications[align];
|
|
368
|
+
return items.find((item) => item.id === id);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Get notification with id
|
|
373
|
+
* @param id Notification id
|
|
374
|
+
*/
|
|
375
|
+
getById(id: string): INotification<UI, C> | undefined {
|
|
376
|
+
for (const align in Object.keys(NotificationAlign)) {
|
|
377
|
+
var item = this.get(align as unknown as NotificationAlign, id);
|
|
378
|
+
if (item != null) return item;
|
|
448
379
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
/**
|
|
476
|
-
* Show a message
|
|
477
|
-
* @param type Message type
|
|
478
|
-
* @param message Message
|
|
479
|
-
* @param title Title
|
|
480
|
-
* @param parameters Parameters
|
|
481
|
-
* @param props Props
|
|
482
|
-
*/
|
|
483
|
-
message(
|
|
484
|
-
type: NotificationMessageType,
|
|
485
|
-
message: NotificationContent<UI>,
|
|
486
|
-
title?: NotificationContent<UI>,
|
|
487
|
-
parameters?: NotificationParameters,
|
|
488
|
-
props?: C
|
|
489
|
-
) {
|
|
490
|
-
// Destruct
|
|
491
|
-
const { align, timespan, callback, modal } = parameters ?? {};
|
|
492
|
-
|
|
493
|
-
// Setup
|
|
494
|
-
const n: INotificaseBase<UI, C> = {
|
|
495
|
-
type,
|
|
496
|
-
content: message,
|
|
497
|
-
title,
|
|
498
|
-
align,
|
|
499
|
-
timespan,
|
|
500
|
-
onReturn: callback,
|
|
501
|
-
inputProps: props
|
|
502
|
-
};
|
|
503
|
-
|
|
504
|
-
// Add to the collection
|
|
505
|
-
return this.addRaw(n, modal);
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
/**
|
|
509
|
-
* Prompt action
|
|
510
|
-
* @param message Message
|
|
511
|
-
* @param callback Callback
|
|
512
|
-
* @param title Title
|
|
513
|
-
* @param props More properties
|
|
514
|
-
*/
|
|
515
|
-
prompt<T = string | undefined>(
|
|
516
|
-
message: NotificationContent<UI>,
|
|
517
|
-
callback: NotificationReturn<T>,
|
|
518
|
-
title?: string,
|
|
519
|
-
props?: C
|
|
520
|
-
) {
|
|
521
|
-
// Setup
|
|
522
|
-
const n: INotificaseBase<UI, C> = {
|
|
523
|
-
type: NotificationType.Prompt,
|
|
524
|
-
content: message,
|
|
525
|
-
title,
|
|
526
|
-
inputProps: props,
|
|
527
|
-
onReturn: callback
|
|
528
|
-
};
|
|
529
|
-
|
|
530
|
-
// Add to the collection
|
|
531
|
-
return this.addRaw(n);
|
|
380
|
+
return undefined;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Report error or message
|
|
385
|
+
* @param errorOrTitle Error message or title
|
|
386
|
+
* @param callback Callback
|
|
387
|
+
* @param type Type, default is Error
|
|
388
|
+
* @param props Props
|
|
389
|
+
*/
|
|
390
|
+
alert(
|
|
391
|
+
errorOrTitle:
|
|
392
|
+
| NotificationContent<UI>
|
|
393
|
+
| [NotificationContent<UI>, NotificationContent<UI>],
|
|
394
|
+
callback?: NotificationReturn<void>,
|
|
395
|
+
type?: NotificationMessageType,
|
|
396
|
+
props?: C
|
|
397
|
+
) {
|
|
398
|
+
// Parse messange and title
|
|
399
|
+
let error: NotificationContent<UI>,
|
|
400
|
+
title: NotificationContent<UI> | undefined;
|
|
401
|
+
if (Array.isArray(errorOrTitle)) {
|
|
402
|
+
error = errorOrTitle[0];
|
|
403
|
+
title = errorOrTitle[1];
|
|
404
|
+
} else {
|
|
405
|
+
error = errorOrTitle;
|
|
532
406
|
}
|
|
533
407
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
408
|
+
// Setup
|
|
409
|
+
const n: INotificaseBase<UI, C> = {
|
|
410
|
+
inputProps: props,
|
|
411
|
+
type: type ?? NotificationType.Error,
|
|
412
|
+
title,
|
|
413
|
+
content: error,
|
|
414
|
+
onReturn: callback
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
// Add to the collection
|
|
418
|
+
return this.addRaw(n, true);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Confirm action
|
|
423
|
+
* @param message Message
|
|
424
|
+
* @param title Title
|
|
425
|
+
* @param callback Callback
|
|
426
|
+
* @param props Props
|
|
427
|
+
*/
|
|
428
|
+
confirm(
|
|
429
|
+
message: NotificationContent<UI>,
|
|
430
|
+
title?: NotificationContent<UI>,
|
|
431
|
+
callback?: NotificationReturn<boolean>,
|
|
432
|
+
props?: C
|
|
433
|
+
) {
|
|
434
|
+
// Setup
|
|
435
|
+
const n: INotificaseBase<UI, C> = {
|
|
436
|
+
type: NotificationType.Confirm,
|
|
437
|
+
content: message,
|
|
438
|
+
title,
|
|
439
|
+
onReturn: callback,
|
|
440
|
+
inputProps: props
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
// Add to the collection
|
|
444
|
+
return this.addRaw(n);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Hide loading
|
|
449
|
+
* @param force Force to hide, otherwise, only the last one
|
|
450
|
+
*/
|
|
451
|
+
hideLoading(force?: boolean) {
|
|
452
|
+
if (this.lastLoading == null) {
|
|
453
|
+
// Reset count when no loading
|
|
454
|
+
this.loadingCount = 0;
|
|
455
|
+
} else {
|
|
456
|
+
// Deduct to count
|
|
457
|
+
// Avoid negative result (-1)
|
|
458
|
+
if (this.loadingCount > 0) {
|
|
459
|
+
this.loadingCount--;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
if (force) this.loadingCount = 0;
|
|
463
|
+
|
|
464
|
+
// Hide the loading
|
|
465
|
+
if (this.loadingCount === 0) {
|
|
466
|
+
this.lastLoading.dismiss();
|
|
467
|
+
this.lastLoading = undefined;
|
|
468
|
+
}
|
|
553
469
|
}
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Show a message
|
|
474
|
+
* @param type Message type
|
|
475
|
+
* @param message Message
|
|
476
|
+
* @param title Title
|
|
477
|
+
* @param parameters Parameters
|
|
478
|
+
* @param props Props
|
|
479
|
+
*/
|
|
480
|
+
message(
|
|
481
|
+
type: NotificationMessageType,
|
|
482
|
+
message: NotificationContent<UI>,
|
|
483
|
+
title?: NotificationContent<UI>,
|
|
484
|
+
parameters?: NotificationParameters,
|
|
485
|
+
props?: C
|
|
486
|
+
) {
|
|
487
|
+
// Destruct
|
|
488
|
+
const { align, timespan, callback, modal } = parameters ?? {};
|
|
489
|
+
|
|
490
|
+
// Setup
|
|
491
|
+
const n: INotificaseBase<UI, C> = {
|
|
492
|
+
type,
|
|
493
|
+
content: message,
|
|
494
|
+
title,
|
|
495
|
+
align,
|
|
496
|
+
timespan,
|
|
497
|
+
onReturn: callback,
|
|
498
|
+
inputProps: props
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
// Add to the collection
|
|
502
|
+
return this.addRaw(n, modal);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Prompt action
|
|
507
|
+
* @param message Message
|
|
508
|
+
* @param callback Callback
|
|
509
|
+
* @param title Title
|
|
510
|
+
* @param props More properties
|
|
511
|
+
*/
|
|
512
|
+
prompt<T = string | undefined>(
|
|
513
|
+
message: NotificationContent<UI>,
|
|
514
|
+
callback: NotificationReturn<T>,
|
|
515
|
+
title?: string,
|
|
516
|
+
props?: C
|
|
517
|
+
) {
|
|
518
|
+
// Setup
|
|
519
|
+
const n: INotificaseBase<UI, C> = {
|
|
520
|
+
type: NotificationType.Prompt,
|
|
521
|
+
content: message,
|
|
522
|
+
title,
|
|
523
|
+
inputProps: props,
|
|
524
|
+
onReturn: callback
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
// Add to the collection
|
|
528
|
+
return this.addRaw(n);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* Show loading
|
|
533
|
+
* @param title Title
|
|
534
|
+
*/
|
|
535
|
+
showLoading(title?: NotificationContent<UI>) {
|
|
536
|
+
// Add to count
|
|
537
|
+
this.loadingCount++;
|
|
538
|
+
|
|
539
|
+
if (this.lastLoading == null) {
|
|
540
|
+
// Setup
|
|
541
|
+
const n: INotificaseBase<UI, C> = {
|
|
542
|
+
type: NotificationType.Loading,
|
|
543
|
+
content: title ?? ""
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
// Add to the collection
|
|
547
|
+
// Keep the reference
|
|
548
|
+
this.lastLoading = this.addRaw(n);
|
|
606
549
|
}
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* Popup component as modal
|
|
554
|
+
* @param component Component to popup
|
|
555
|
+
* @param properties Popup properties
|
|
556
|
+
* @returns Result
|
|
557
|
+
*/
|
|
558
|
+
popup(component: NotificationContent<UI>, properties: any) {
|
|
559
|
+
// Setup
|
|
560
|
+
const n: INotificaseBase<UI, C> = {
|
|
561
|
+
type: NotificationType.Popup,
|
|
562
|
+
content: component,
|
|
563
|
+
renderSetup: (_options) => {
|
|
564
|
+
return properties;
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
// Add to the collection
|
|
569
|
+
return this.addRaw(n);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Show a success message
|
|
574
|
+
* @param message Message
|
|
575
|
+
* @param title Title
|
|
576
|
+
* @param callback Callback
|
|
577
|
+
* @param timespan Timespan to close
|
|
578
|
+
* @param props Props
|
|
579
|
+
*/
|
|
580
|
+
succeed(
|
|
581
|
+
message: NotificationContent<UI>,
|
|
582
|
+
title?: NotificationContent<UI>,
|
|
583
|
+
callback?: NotificationReturn<void>,
|
|
584
|
+
timespan?: number,
|
|
585
|
+
props?: C
|
|
586
|
+
) {
|
|
587
|
+
// Default to zero for constant
|
|
588
|
+
timespan ??= 0;
|
|
589
|
+
|
|
590
|
+
// Create as message
|
|
591
|
+
return this.message(
|
|
592
|
+
NotificationMessageType.Success,
|
|
593
|
+
message,
|
|
594
|
+
title,
|
|
595
|
+
{
|
|
596
|
+
align: NotificationAlign.Center,
|
|
597
|
+
modal: true,
|
|
598
|
+
timespan,
|
|
599
|
+
callback
|
|
600
|
+
},
|
|
601
|
+
props
|
|
602
|
+
);
|
|
603
|
+
}
|
|
607
604
|
}
|