@etsoo/notificationbase 1.0.90 → 1.0.94
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.
|
@@ -21,7 +21,7 @@ class NotificationContainerTest extends NotificationContainer<
|
|
|
21
21
|
NotificationCallProps
|
|
22
22
|
> {
|
|
23
23
|
protected addRaw(
|
|
24
|
-
data: INotificaseBase<NotificationCallProps>
|
|
24
|
+
data: INotificaseBase<any, NotificationCallProps>
|
|
25
25
|
): INotification<any, NotificationCallProps> {
|
|
26
26
|
throw new Error('Method not implemented.');
|
|
27
27
|
}
|
package/lib/Notification.d.ts
CHANGED
|
@@ -100,7 +100,7 @@ export interface NotificationParameters {
|
|
|
100
100
|
/**
|
|
101
101
|
* Notification props supported for calls
|
|
102
102
|
*/
|
|
103
|
-
export interface NotificationCallProps {
|
|
103
|
+
export interface NotificationCallProps extends Record<string, unknown> {
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
106
|
* Notification render props
|
|
@@ -110,7 +110,7 @@ export interface NotificationRenderProps {
|
|
|
110
110
|
/**
|
|
111
111
|
* Notification base interface
|
|
112
112
|
*/
|
|
113
|
-
export interface INotificaseBase<C extends NotificationCallProps> {
|
|
113
|
+
export interface INotificaseBase<UI, C extends NotificationCallProps> {
|
|
114
114
|
/**
|
|
115
115
|
* Display align
|
|
116
116
|
*/
|
|
@@ -118,7 +118,7 @@ export interface INotificaseBase<C extends NotificationCallProps> {
|
|
|
118
118
|
/**
|
|
119
119
|
* Content
|
|
120
120
|
*/
|
|
121
|
-
readonly content: NotificationContent<
|
|
121
|
+
readonly content: NotificationContent<UI>;
|
|
122
122
|
/**
|
|
123
123
|
* Input or control properties
|
|
124
124
|
*/
|
|
@@ -147,7 +147,7 @@ export interface INotificaseBase<C extends NotificationCallProps> {
|
|
|
147
147
|
/**
|
|
148
148
|
* Title
|
|
149
149
|
*/
|
|
150
|
-
readonly title?: NotificationContent<
|
|
150
|
+
readonly title?: NotificationContent<UI>;
|
|
151
151
|
/**
|
|
152
152
|
* Type
|
|
153
153
|
*/
|
|
@@ -156,7 +156,7 @@ export interface INotificaseBase<C extends NotificationCallProps> {
|
|
|
156
156
|
/**
|
|
157
157
|
* Notification interface
|
|
158
158
|
*/
|
|
159
|
-
export interface INotification<UI, C extends NotificationCallProps> extends INotificaseBase<C> {
|
|
159
|
+
export interface INotification<UI, C extends NotificationCallProps> extends INotificaseBase<UI, C> {
|
|
160
160
|
/**
|
|
161
161
|
* Display align
|
|
162
162
|
*/
|
|
@@ -33,9 +33,10 @@ export interface INotifier<UI, C extends NotificationCallProps> {
|
|
|
33
33
|
* Report error
|
|
34
34
|
* @param error Error message
|
|
35
35
|
* @param callback Callback
|
|
36
|
+
* @param type Type, default is Error
|
|
36
37
|
* @param props Props
|
|
37
38
|
*/
|
|
38
|
-
alert(error: NotificationContent<UI>, callback?: NotificationReturn<void>, props?: C): INotification<UI, C>;
|
|
39
|
+
alert(error: NotificationContent<UI>, callback?: NotificationReturn<void>, type?: NotificationMessageType, props?: C): INotification<UI, C>;
|
|
39
40
|
/**
|
|
40
41
|
* Align all notification count
|
|
41
42
|
* @param align Align
|
|
@@ -115,6 +116,7 @@ export interface INotifier<UI, C extends NotificationCallProps> {
|
|
|
115
116
|
export declare abstract class NotificationContainer<UI, C extends NotificationCallProps> implements INotifier<UI, C> {
|
|
116
117
|
private update;
|
|
117
118
|
private lastLoading?;
|
|
119
|
+
private loadingCount;
|
|
118
120
|
/**
|
|
119
121
|
* Notification collection to display
|
|
120
122
|
*/
|
|
@@ -136,7 +138,7 @@ export declare abstract class NotificationContainer<UI, C extends NotificationCa
|
|
|
136
138
|
* @param data Notification data definition
|
|
137
139
|
* @param modal Show as modal
|
|
138
140
|
*/
|
|
139
|
-
protected abstract addRaw(data: INotificaseBase<C>, modal?: boolean): INotification<UI, C>;
|
|
141
|
+
protected abstract addRaw(data: INotificaseBase<UI, C>, modal?: boolean): INotification<UI, C>;
|
|
140
142
|
/**
|
|
141
143
|
* Add notification
|
|
142
144
|
* @param notification Notification
|
|
@@ -182,9 +184,10 @@ export declare abstract class NotificationContainer<UI, C extends NotificationCa
|
|
|
182
184
|
* Report error
|
|
183
185
|
* @param error Error message
|
|
184
186
|
* @param callback Callback
|
|
187
|
+
* @param type Type, default is Error
|
|
185
188
|
* @param props Props
|
|
186
189
|
*/
|
|
187
|
-
alert(error: string, callback?: NotificationReturn<void>, props?: C): INotification<UI, C>;
|
|
190
|
+
alert(error: string, callback?: NotificationReturn<void>, type?: NotificationMessageType, props?: C): INotification<UI, C>;
|
|
188
191
|
/**
|
|
189
192
|
* Confirm action
|
|
190
193
|
* @param message Message
|
|
@@ -7,6 +7,7 @@ export class NotificationContainer {
|
|
|
7
7
|
* Constructor
|
|
8
8
|
*/
|
|
9
9
|
constructor(update) {
|
|
10
|
+
this.loadingCount = 0;
|
|
10
11
|
// Update callback
|
|
11
12
|
this.update = update;
|
|
12
13
|
// Init notification collection
|
|
@@ -37,7 +38,7 @@ export class NotificationContainer {
|
|
|
37
38
|
// Align collection
|
|
38
39
|
const alignItems = this.notifications[notification.align];
|
|
39
40
|
// Support dismiss action
|
|
40
|
-
const {
|
|
41
|
+
const { timespan, onDismiss } = notification;
|
|
41
42
|
notification.onDismiss = () => {
|
|
42
43
|
// Remove from the collection
|
|
43
44
|
const index = alignItems.findIndex((item) => item.id === notification.id);
|
|
@@ -139,18 +140,19 @@ export class NotificationContainer {
|
|
|
139
140
|
* Report error
|
|
140
141
|
* @param error Error message
|
|
141
142
|
* @param callback Callback
|
|
143
|
+
* @param type Type, default is Error
|
|
142
144
|
* @param props Props
|
|
143
145
|
*/
|
|
144
|
-
alert(error, callback, props) {
|
|
146
|
+
alert(error, callback, type, props) {
|
|
145
147
|
// Setup
|
|
146
148
|
const n = {
|
|
147
149
|
inputProps: props,
|
|
148
|
-
type: NotificationType.Error,
|
|
150
|
+
type: type !== null && type !== void 0 ? type : NotificationType.Error,
|
|
149
151
|
content: error,
|
|
150
152
|
onReturn: callback
|
|
151
153
|
};
|
|
152
154
|
// Add to the collection
|
|
153
|
-
return this.addRaw(n);
|
|
155
|
+
return this.addRaw(n, true);
|
|
154
156
|
}
|
|
155
157
|
/**
|
|
156
158
|
* Confirm action
|
|
@@ -176,7 +178,12 @@ export class NotificationContainer {
|
|
|
176
178
|
*/
|
|
177
179
|
hideLoading() {
|
|
178
180
|
var _a;
|
|
179
|
-
|
|
181
|
+
// Deduct to count
|
|
182
|
+
this.loadingCount--;
|
|
183
|
+
if (this.loadingCount === 0) {
|
|
184
|
+
(_a = this.lastLoading) === null || _a === void 0 ? void 0 : _a.dismiss();
|
|
185
|
+
this.lastLoading = undefined;
|
|
186
|
+
}
|
|
180
187
|
}
|
|
181
188
|
/**
|
|
182
189
|
* Show a message
|
|
@@ -226,14 +233,18 @@ export class NotificationContainer {
|
|
|
226
233
|
* @param title Title
|
|
227
234
|
*/
|
|
228
235
|
showLoading(title) {
|
|
229
|
-
//
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
236
|
+
// Add to count
|
|
237
|
+
this.loadingCount++;
|
|
238
|
+
if (this.lastLoading == null) {
|
|
239
|
+
// Setup
|
|
240
|
+
const n = {
|
|
241
|
+
type: NotificationType.Loading,
|
|
242
|
+
content: title !== null && title !== void 0 ? title : ''
|
|
243
|
+
};
|
|
244
|
+
// Add to the collection
|
|
245
|
+
// Keep the reference
|
|
246
|
+
this.lastLoading = this.addRaw(n);
|
|
247
|
+
}
|
|
237
248
|
}
|
|
238
249
|
/**
|
|
239
250
|
* Show a success message
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/notificationbase",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.94",
|
|
4
4
|
"description": "TypeScript notification component for extending with all features described and partially implemented",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -45,22 +45,22 @@
|
|
|
45
45
|
},
|
|
46
46
|
"homepage": "https://github.com/ETSOO/NotificationBase#readme",
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@etsoo/shared": "^1.0.
|
|
48
|
+
"@etsoo/shared": "^1.0.75"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@babel/core": "^7.
|
|
52
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
53
|
-
"@babel/preset-env": "^7.
|
|
54
|
-
"@babel/runtime-corejs3": "^7.
|
|
55
|
-
"@types/jest": "^27.0.
|
|
56
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
57
|
-
"@typescript-eslint/parser": "^5.
|
|
58
|
-
"babel-jest": "^27.
|
|
59
|
-
"eslint": "^8.
|
|
60
|
-
"eslint-config-airbnb-base": "^
|
|
61
|
-
"eslint-plugin-import": "^2.25.
|
|
62
|
-
"jest": "^27.
|
|
51
|
+
"@babel/core": "^7.16.0",
|
|
52
|
+
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
53
|
+
"@babel/preset-env": "^7.16.4",
|
|
54
|
+
"@babel/runtime-corejs3": "^7.16.3",
|
|
55
|
+
"@types/jest": "^27.0.3",
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "^5.5.0",
|
|
57
|
+
"@typescript-eslint/parser": "^5.5.0",
|
|
58
|
+
"babel-jest": "^27.4.2",
|
|
59
|
+
"eslint": "^8.3.0",
|
|
60
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
61
|
+
"eslint-plugin-import": "^2.25.3",
|
|
62
|
+
"jest": "^27.4.2",
|
|
63
63
|
"ts-jest": "^27.0.7",
|
|
64
|
-
"typescript": "^4.
|
|
64
|
+
"typescript": "^4.5.2"
|
|
65
65
|
}
|
|
66
66
|
}
|
package/src/Notification.ts
CHANGED
|
@@ -110,7 +110,7 @@ export interface NotificationParameters {
|
|
|
110
110
|
/**
|
|
111
111
|
* Notification props supported for calls
|
|
112
112
|
*/
|
|
113
|
-
export interface NotificationCallProps {}
|
|
113
|
+
export interface NotificationCallProps extends Record<string, unknown> {}
|
|
114
114
|
|
|
115
115
|
/**
|
|
116
116
|
* Notification render props
|
|
@@ -120,7 +120,7 @@ export interface NotificationRenderProps {}
|
|
|
120
120
|
/**
|
|
121
121
|
* Notification base interface
|
|
122
122
|
*/
|
|
123
|
-
export interface INotificaseBase<C extends NotificationCallProps> {
|
|
123
|
+
export interface INotificaseBase<UI, C extends NotificationCallProps> {
|
|
124
124
|
/**
|
|
125
125
|
* Display align
|
|
126
126
|
*/
|
|
@@ -129,7 +129,7 @@ export interface INotificaseBase<C extends NotificationCallProps> {
|
|
|
129
129
|
/**
|
|
130
130
|
* Content
|
|
131
131
|
*/
|
|
132
|
-
readonly content: NotificationContent<
|
|
132
|
+
readonly content: NotificationContent<UI>;
|
|
133
133
|
|
|
134
134
|
/**
|
|
135
135
|
* Input or control properties
|
|
@@ -165,7 +165,7 @@ export interface INotificaseBase<C extends NotificationCallProps> {
|
|
|
165
165
|
/**
|
|
166
166
|
* Title
|
|
167
167
|
*/
|
|
168
|
-
readonly title?: NotificationContent<
|
|
168
|
+
readonly title?: NotificationContent<UI>;
|
|
169
169
|
|
|
170
170
|
/**
|
|
171
171
|
* Type
|
|
@@ -177,7 +177,7 @@ export interface INotificaseBase<C extends NotificationCallProps> {
|
|
|
177
177
|
* Notification interface
|
|
178
178
|
*/
|
|
179
179
|
export interface INotification<UI, C extends NotificationCallProps>
|
|
180
|
-
extends INotificaseBase<C> {
|
|
180
|
+
extends INotificaseBase<UI, C> {
|
|
181
181
|
/**
|
|
182
182
|
* Display align
|
|
183
183
|
*/
|
|
@@ -50,11 +50,13 @@ export interface INotifier<UI, C extends NotificationCallProps> {
|
|
|
50
50
|
* Report error
|
|
51
51
|
* @param error Error message
|
|
52
52
|
* @param callback Callback
|
|
53
|
+
* @param type Type, default is Error
|
|
53
54
|
* @param props Props
|
|
54
55
|
*/
|
|
55
56
|
alert(
|
|
56
57
|
error: NotificationContent<UI>,
|
|
57
58
|
callback?: NotificationReturn<void>,
|
|
59
|
+
type?: NotificationMessageType,
|
|
58
60
|
props?: C
|
|
59
61
|
): INotification<UI, C>;
|
|
60
62
|
|
|
@@ -176,6 +178,7 @@ export abstract class NotificationContainer<UI, C extends NotificationCallProps>
|
|
|
176
178
|
|
|
177
179
|
// Last loading
|
|
178
180
|
private lastLoading?: INotification<UI, C>;
|
|
181
|
+
private loadingCount = 0;
|
|
179
182
|
|
|
180
183
|
/**
|
|
181
184
|
* Notification collection to display
|
|
@@ -218,7 +221,7 @@ export abstract class NotificationContainer<UI, C extends NotificationCallProps>
|
|
|
218
221
|
* @param modal Show as modal
|
|
219
222
|
*/
|
|
220
223
|
protected abstract addRaw(
|
|
221
|
-
data: INotificaseBase<C>,
|
|
224
|
+
data: INotificaseBase<UI, C>,
|
|
222
225
|
modal?: boolean
|
|
223
226
|
): INotification<UI, C>;
|
|
224
227
|
|
|
@@ -232,7 +235,7 @@ export abstract class NotificationContainer<UI, C extends NotificationCallProps>
|
|
|
232
235
|
const alignItems = this.notifications[notification.align];
|
|
233
236
|
|
|
234
237
|
// Support dismiss action
|
|
235
|
-
const {
|
|
238
|
+
const { timespan, onDismiss } = notification;
|
|
236
239
|
notification.onDismiss = () => {
|
|
237
240
|
// Remove from the collection
|
|
238
241
|
const index = alignItems.findIndex(
|
|
@@ -348,19 +351,25 @@ export abstract class NotificationContainer<UI, C extends NotificationCallProps>
|
|
|
348
351
|
* Report error
|
|
349
352
|
* @param error Error message
|
|
350
353
|
* @param callback Callback
|
|
354
|
+
* @param type Type, default is Error
|
|
351
355
|
* @param props Props
|
|
352
356
|
*/
|
|
353
|
-
alert(
|
|
357
|
+
alert(
|
|
358
|
+
error: string,
|
|
359
|
+
callback?: NotificationReturn<void>,
|
|
360
|
+
type?: NotificationMessageType,
|
|
361
|
+
props?: C
|
|
362
|
+
) {
|
|
354
363
|
// Setup
|
|
355
|
-
const n: INotificaseBase<C> = {
|
|
364
|
+
const n: INotificaseBase<UI, C> = {
|
|
356
365
|
inputProps: props,
|
|
357
|
-
type: NotificationType.Error,
|
|
366
|
+
type: type ?? NotificationType.Error,
|
|
358
367
|
content: error,
|
|
359
368
|
onReturn: callback
|
|
360
369
|
};
|
|
361
370
|
|
|
362
371
|
// Add to the collection
|
|
363
|
-
return this.addRaw(n);
|
|
372
|
+
return this.addRaw(n, true);
|
|
364
373
|
}
|
|
365
374
|
|
|
366
375
|
/**
|
|
@@ -377,7 +386,7 @@ export abstract class NotificationContainer<UI, C extends NotificationCallProps>
|
|
|
377
386
|
props?: C
|
|
378
387
|
) {
|
|
379
388
|
// Setup
|
|
380
|
-
const n: INotificaseBase<C> = {
|
|
389
|
+
const n: INotificaseBase<UI, C> = {
|
|
381
390
|
type: NotificationType.Confirm,
|
|
382
391
|
content: message,
|
|
383
392
|
title,
|
|
@@ -393,7 +402,13 @@ export abstract class NotificationContainer<UI, C extends NotificationCallProps>
|
|
|
393
402
|
* Hide loading
|
|
394
403
|
*/
|
|
395
404
|
hideLoading() {
|
|
396
|
-
|
|
405
|
+
// Deduct to count
|
|
406
|
+
this.loadingCount--;
|
|
407
|
+
|
|
408
|
+
if (this.loadingCount === 0) {
|
|
409
|
+
this.lastLoading?.dismiss();
|
|
410
|
+
this.lastLoading = undefined;
|
|
411
|
+
}
|
|
397
412
|
}
|
|
398
413
|
|
|
399
414
|
/**
|
|
@@ -415,7 +430,7 @@ export abstract class NotificationContainer<UI, C extends NotificationCallProps>
|
|
|
415
430
|
const { align, timespan, callback, modal } = parameters ?? {};
|
|
416
431
|
|
|
417
432
|
// Setup
|
|
418
|
-
const n: INotificaseBase<C> = {
|
|
433
|
+
const n: INotificaseBase<UI, C> = {
|
|
419
434
|
type,
|
|
420
435
|
content: message,
|
|
421
436
|
title,
|
|
@@ -443,7 +458,7 @@ export abstract class NotificationContainer<UI, C extends NotificationCallProps>
|
|
|
443
458
|
props?: C
|
|
444
459
|
) {
|
|
445
460
|
// Setup
|
|
446
|
-
const n: INotificaseBase<C> = {
|
|
461
|
+
const n: INotificaseBase<UI, C> = {
|
|
447
462
|
type: NotificationType.Prompt,
|
|
448
463
|
content: message,
|
|
449
464
|
title,
|
|
@@ -460,15 +475,20 @@ export abstract class NotificationContainer<UI, C extends NotificationCallProps>
|
|
|
460
475
|
* @param title Title
|
|
461
476
|
*/
|
|
462
477
|
showLoading(title?: NotificationContent<UI>) {
|
|
463
|
-
//
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
478
|
+
// Add to count
|
|
479
|
+
this.loadingCount++;
|
|
480
|
+
|
|
481
|
+
if (this.lastLoading == null) {
|
|
482
|
+
// Setup
|
|
483
|
+
const n: INotificaseBase<UI, C> = {
|
|
484
|
+
type: NotificationType.Loading,
|
|
485
|
+
content: title ?? ''
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
// Add to the collection
|
|
489
|
+
// Keep the reference
|
|
490
|
+
this.lastLoading = this.addRaw(n);
|
|
491
|
+
}
|
|
472
492
|
}
|
|
473
493
|
|
|
474
494
|
/**
|