@etsoo/notificationbase 1.0.91 → 1.0.95
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/README.md +2 -1
- package/lib/Notification.d.ts +1 -1
- package/lib/NotificationContainer.d.ts +9 -4
- package/lib/NotificationContainer.js +28 -14
- package/package.json +16 -16
- package/src/Notification.ts +1 -1
- package/src/NotificationContainer.ts +40 -16
package/README.md
CHANGED
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
|
|
@@ -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
|
|
@@ -75,8 +76,9 @@ export interface INotifier<UI, C extends NotificationCallProps> {
|
|
|
75
76
|
getById(id: string): INotification<UI, C> | undefined;
|
|
76
77
|
/**
|
|
77
78
|
* Hide loading
|
|
79
|
+
* @param force Force to hide, otherwise, only the last one
|
|
78
80
|
*/
|
|
79
|
-
hideLoading(): void;
|
|
81
|
+
hideLoading(force?: boolean): void;
|
|
80
82
|
/**
|
|
81
83
|
* Show a message
|
|
82
84
|
* @param type Message type
|
|
@@ -115,6 +117,7 @@ export interface INotifier<UI, C extends NotificationCallProps> {
|
|
|
115
117
|
export declare abstract class NotificationContainer<UI, C extends NotificationCallProps> implements INotifier<UI, C> {
|
|
116
118
|
private update;
|
|
117
119
|
private lastLoading?;
|
|
120
|
+
private loadingCount;
|
|
118
121
|
/**
|
|
119
122
|
* Notification collection to display
|
|
120
123
|
*/
|
|
@@ -182,9 +185,10 @@ export declare abstract class NotificationContainer<UI, C extends NotificationCa
|
|
|
182
185
|
* Report error
|
|
183
186
|
* @param error Error message
|
|
184
187
|
* @param callback Callback
|
|
188
|
+
* @param type Type, default is Error
|
|
185
189
|
* @param props Props
|
|
186
190
|
*/
|
|
187
|
-
alert(error: string, callback?: NotificationReturn<void>, props?: C): INotification<UI, C>;
|
|
191
|
+
alert(error: string, callback?: NotificationReturn<void>, type?: NotificationMessageType, props?: C): INotification<UI, C>;
|
|
188
192
|
/**
|
|
189
193
|
* Confirm action
|
|
190
194
|
* @param message Message
|
|
@@ -195,8 +199,9 @@ export declare abstract class NotificationContainer<UI, C extends NotificationCa
|
|
|
195
199
|
confirm(message: NotificationContent<UI>, title?: NotificationContent<UI>, callback?: NotificationReturn<boolean>, props?: C): INotification<UI, C>;
|
|
196
200
|
/**
|
|
197
201
|
* Hide loading
|
|
202
|
+
* @param force Force to hide, otherwise, only the last one
|
|
198
203
|
*/
|
|
199
|
-
hideLoading(): void;
|
|
204
|
+
hideLoading(force?: boolean): void;
|
|
200
205
|
/**
|
|
201
206
|
* Show a message
|
|
202
207
|
* @param type Message type
|
|
@@ -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
|
|
@@ -173,10 +175,18 @@ export class NotificationContainer {
|
|
|
173
175
|
}
|
|
174
176
|
/**
|
|
175
177
|
* Hide loading
|
|
178
|
+
* @param force Force to hide, otherwise, only the last one
|
|
176
179
|
*/
|
|
177
|
-
hideLoading() {
|
|
180
|
+
hideLoading(force) {
|
|
178
181
|
var _a;
|
|
179
|
-
|
|
182
|
+
// Deduct to count
|
|
183
|
+
this.loadingCount--;
|
|
184
|
+
if (force)
|
|
185
|
+
this.loadingCount = 0;
|
|
186
|
+
if (this.loadingCount === 0) {
|
|
187
|
+
(_a = this.lastLoading) === null || _a === void 0 ? void 0 : _a.dismiss();
|
|
188
|
+
this.lastLoading = undefined;
|
|
189
|
+
}
|
|
180
190
|
}
|
|
181
191
|
/**
|
|
182
192
|
* Show a message
|
|
@@ -226,14 +236,18 @@ export class NotificationContainer {
|
|
|
226
236
|
* @param title Title
|
|
227
237
|
*/
|
|
228
238
|
showLoading(title) {
|
|
229
|
-
//
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
239
|
+
// Add to count
|
|
240
|
+
this.loadingCount++;
|
|
241
|
+
if (this.lastLoading == null) {
|
|
242
|
+
// Setup
|
|
243
|
+
const n = {
|
|
244
|
+
type: NotificationType.Loading,
|
|
245
|
+
content: title !== null && title !== void 0 ? title : ''
|
|
246
|
+
};
|
|
247
|
+
// Add to the collection
|
|
248
|
+
// Keep the reference
|
|
249
|
+
this.lastLoading = this.addRaw(n);
|
|
250
|
+
}
|
|
237
251
|
}
|
|
238
252
|
/**
|
|
239
253
|
* 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.95",
|
|
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.79"
|
|
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.
|
|
63
|
-
"ts-jest": "^27.
|
|
64
|
-
"typescript": "^4.
|
|
51
|
+
"@babel/core": "^7.16.5",
|
|
52
|
+
"@babel/plugin-transform-runtime": "^7.16.5",
|
|
53
|
+
"@babel/preset-env": "^7.16.5",
|
|
54
|
+
"@babel/runtime-corejs3": "^7.16.5",
|
|
55
|
+
"@types/jest": "^27.0.3",
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "^5.8.0",
|
|
57
|
+
"@typescript-eslint/parser": "^5.8.0",
|
|
58
|
+
"babel-jest": "^27.4.5",
|
|
59
|
+
"eslint": "^8.5.0",
|
|
60
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
61
|
+
"eslint-plugin-import": "^2.25.3",
|
|
62
|
+
"jest": "^27.4.5",
|
|
63
|
+
"ts-jest": "^27.1.2",
|
|
64
|
+
"typescript": "^4.5.4"
|
|
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
|
|
@@ -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
|
|
|
@@ -109,8 +111,9 @@ export interface INotifier<UI, C extends NotificationCallProps> {
|
|
|
109
111
|
|
|
110
112
|
/**
|
|
111
113
|
* Hide loading
|
|
114
|
+
* @param force Force to hide, otherwise, only the last one
|
|
112
115
|
*/
|
|
113
|
-
hideLoading(): void;
|
|
116
|
+
hideLoading(force?: boolean): void;
|
|
114
117
|
|
|
115
118
|
/**
|
|
116
119
|
* Show a message
|
|
@@ -176,6 +179,7 @@ export abstract class NotificationContainer<UI, C extends NotificationCallProps>
|
|
|
176
179
|
|
|
177
180
|
// Last loading
|
|
178
181
|
private lastLoading?: INotification<UI, C>;
|
|
182
|
+
private loadingCount = 0;
|
|
179
183
|
|
|
180
184
|
/**
|
|
181
185
|
* Notification collection to display
|
|
@@ -232,7 +236,7 @@ export abstract class NotificationContainer<UI, C extends NotificationCallProps>
|
|
|
232
236
|
const alignItems = this.notifications[notification.align];
|
|
233
237
|
|
|
234
238
|
// Support dismiss action
|
|
235
|
-
const {
|
|
239
|
+
const { timespan, onDismiss } = notification;
|
|
236
240
|
notification.onDismiss = () => {
|
|
237
241
|
// Remove from the collection
|
|
238
242
|
const index = alignItems.findIndex(
|
|
@@ -348,19 +352,25 @@ export abstract class NotificationContainer<UI, C extends NotificationCallProps>
|
|
|
348
352
|
* Report error
|
|
349
353
|
* @param error Error message
|
|
350
354
|
* @param callback Callback
|
|
355
|
+
* @param type Type, default is Error
|
|
351
356
|
* @param props Props
|
|
352
357
|
*/
|
|
353
|
-
alert(
|
|
358
|
+
alert(
|
|
359
|
+
error: string,
|
|
360
|
+
callback?: NotificationReturn<void>,
|
|
361
|
+
type?: NotificationMessageType,
|
|
362
|
+
props?: C
|
|
363
|
+
) {
|
|
354
364
|
// Setup
|
|
355
365
|
const n: INotificaseBase<UI, C> = {
|
|
356
366
|
inputProps: props,
|
|
357
|
-
type: NotificationType.Error,
|
|
367
|
+
type: type ?? NotificationType.Error,
|
|
358
368
|
content: error,
|
|
359
369
|
onReturn: callback
|
|
360
370
|
};
|
|
361
371
|
|
|
362
372
|
// Add to the collection
|
|
363
|
-
return this.addRaw(n);
|
|
373
|
+
return this.addRaw(n, true);
|
|
364
374
|
}
|
|
365
375
|
|
|
366
376
|
/**
|
|
@@ -391,9 +401,18 @@ export abstract class NotificationContainer<UI, C extends NotificationCallProps>
|
|
|
391
401
|
|
|
392
402
|
/**
|
|
393
403
|
* Hide loading
|
|
404
|
+
* @param force Force to hide, otherwise, only the last one
|
|
394
405
|
*/
|
|
395
|
-
hideLoading() {
|
|
396
|
-
|
|
406
|
+
hideLoading(force?: boolean) {
|
|
407
|
+
// Deduct to count
|
|
408
|
+
this.loadingCount--;
|
|
409
|
+
|
|
410
|
+
if (force) this.loadingCount = 0;
|
|
411
|
+
|
|
412
|
+
if (this.loadingCount === 0) {
|
|
413
|
+
this.lastLoading?.dismiss();
|
|
414
|
+
this.lastLoading = undefined;
|
|
415
|
+
}
|
|
397
416
|
}
|
|
398
417
|
|
|
399
418
|
/**
|
|
@@ -460,15 +479,20 @@ export abstract class NotificationContainer<UI, C extends NotificationCallProps>
|
|
|
460
479
|
* @param title Title
|
|
461
480
|
*/
|
|
462
481
|
showLoading(title?: NotificationContent<UI>) {
|
|
463
|
-
//
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
482
|
+
// Add to count
|
|
483
|
+
this.loadingCount++;
|
|
484
|
+
|
|
485
|
+
if (this.lastLoading == null) {
|
|
486
|
+
// Setup
|
|
487
|
+
const n: INotificaseBase<UI, C> = {
|
|
488
|
+
type: NotificationType.Loading,
|
|
489
|
+
content: title ?? ''
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
// Add to the collection
|
|
493
|
+
// Keep the reference
|
|
494
|
+
this.lastLoading = this.addRaw(n);
|
|
495
|
+
}
|
|
472
496
|
}
|
|
473
497
|
|
|
474
498
|
/**
|