@etsoo/notificationbase 1.0.92 → 1.0.96
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 +9 -1
- package/lib/NotificationContainer.d.ts +11 -7
- package/lib/NotificationContainer.js +9 -5
- package/package.json +16 -16
- package/src/Notification.ts +14 -1
- package/src/NotificationContainer.ts +21 -8
package/README.md
CHANGED
package/lib/Notification.d.ts
CHANGED
|
@@ -72,6 +72,14 @@ export interface NotifictionRenderSetup {
|
|
|
72
72
|
export interface NotificationReturn<T> {
|
|
73
73
|
(value: T): boolean | void | PromiseLike<boolean | void>;
|
|
74
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* On prompt return callback
|
|
77
|
+
* return false will prevent default action
|
|
78
|
+
* return tuple second parameter is the error message to show
|
|
79
|
+
*/
|
|
80
|
+
export interface NotificationPromptReturn<T> extends NotificationReturn<T> {
|
|
81
|
+
(value: T): boolean | [boolean, string?] | void | PromiseLike<boolean | [boolean, string?] | void>;
|
|
82
|
+
}
|
|
75
83
|
/**
|
|
76
84
|
* Notification message parameters
|
|
77
85
|
*/
|
|
@@ -100,7 +108,7 @@ export interface NotificationParameters {
|
|
|
100
108
|
/**
|
|
101
109
|
* Notification props supported for calls
|
|
102
110
|
*/
|
|
103
|
-
export interface NotificationCallProps {
|
|
111
|
+
export interface NotificationCallProps extends Record<string, unknown> {
|
|
104
112
|
}
|
|
105
113
|
/**
|
|
106
114
|
* Notification render props
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { INotificaseBase, INotification, NotificationAlign, NotificationCallProps, NotificationContent, NotificationMessageType, NotificationParameters, NotificationReturn } from './Notification';
|
|
1
|
+
import { INotificaseBase, INotification, NotificationAlign, NotificationCallProps, NotificationContent, NotificationMessageType, NotificationParameters, NotificationPromptReturn, NotificationReturn } from './Notification';
|
|
2
2
|
/**
|
|
3
3
|
* Notification action
|
|
4
4
|
*/
|
|
@@ -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
|
|
@@ -93,7 +95,7 @@ export interface INotifier<UI, C extends NotificationCallProps> {
|
|
|
93
95
|
* @param title Title
|
|
94
96
|
* @param props More properties
|
|
95
97
|
*/
|
|
96
|
-
prompt<T = string>(message: NotificationContent<UI>, callback:
|
|
98
|
+
prompt<T = string>(message: NotificationContent<UI>, callback: NotificationPromptReturn<T>, title?: NotificationContent<UI>, props?: C): INotification<UI, C>;
|
|
97
99
|
/**
|
|
98
100
|
* Show loading
|
|
99
101
|
* @param title Title
|
|
@@ -183,9 +185,10 @@ export declare abstract class NotificationContainer<UI, C extends NotificationCa
|
|
|
183
185
|
* Report error
|
|
184
186
|
* @param error Error message
|
|
185
187
|
* @param callback Callback
|
|
188
|
+
* @param type Type, default is Error
|
|
186
189
|
* @param props Props
|
|
187
190
|
*/
|
|
188
|
-
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>;
|
|
189
192
|
/**
|
|
190
193
|
* Confirm action
|
|
191
194
|
* @param message Message
|
|
@@ -196,8 +199,9 @@ export declare abstract class NotificationContainer<UI, C extends NotificationCa
|
|
|
196
199
|
confirm(message: NotificationContent<UI>, title?: NotificationContent<UI>, callback?: NotificationReturn<boolean>, props?: C): INotification<UI, C>;
|
|
197
200
|
/**
|
|
198
201
|
* Hide loading
|
|
202
|
+
* @param force Force to hide, otherwise, only the last one
|
|
199
203
|
*/
|
|
200
|
-
hideLoading(): void;
|
|
204
|
+
hideLoading(force?: boolean): void;
|
|
201
205
|
/**
|
|
202
206
|
* Show a message
|
|
203
207
|
* @param type Message type
|
|
@@ -214,7 +218,7 @@ export declare abstract class NotificationContainer<UI, C extends NotificationCa
|
|
|
214
218
|
* @param title Title
|
|
215
219
|
* @param props More properties
|
|
216
220
|
*/
|
|
217
|
-
prompt<T>(message: NotificationContent<UI>, callback:
|
|
221
|
+
prompt<T>(message: NotificationContent<UI>, callback: NotificationPromptReturn<T>, title?: string, props?: C): INotification<UI, C>;
|
|
218
222
|
/**
|
|
219
223
|
* Show loading
|
|
220
224
|
* @param title Title
|
|
@@ -38,7 +38,7 @@ export class NotificationContainer {
|
|
|
38
38
|
// Align collection
|
|
39
39
|
const alignItems = this.notifications[notification.align];
|
|
40
40
|
// Support dismiss action
|
|
41
|
-
const {
|
|
41
|
+
const { timespan, onDismiss } = notification;
|
|
42
42
|
notification.onDismiss = () => {
|
|
43
43
|
// Remove from the collection
|
|
44
44
|
const index = alignItems.findIndex((item) => item.id === notification.id);
|
|
@@ -140,18 +140,19 @@ export class NotificationContainer {
|
|
|
140
140
|
* Report error
|
|
141
141
|
* @param error Error message
|
|
142
142
|
* @param callback Callback
|
|
143
|
+
* @param type Type, default is Error
|
|
143
144
|
* @param props Props
|
|
144
145
|
*/
|
|
145
|
-
alert(error, callback, props) {
|
|
146
|
+
alert(error, callback, type, props) {
|
|
146
147
|
// Setup
|
|
147
148
|
const n = {
|
|
148
149
|
inputProps: props,
|
|
149
|
-
type: NotificationType.Error,
|
|
150
|
+
type: type !== null && type !== void 0 ? type : NotificationType.Error,
|
|
150
151
|
content: error,
|
|
151
152
|
onReturn: callback
|
|
152
153
|
};
|
|
153
154
|
// Add to the collection
|
|
154
|
-
return this.addRaw(n);
|
|
155
|
+
return this.addRaw(n, true);
|
|
155
156
|
}
|
|
156
157
|
/**
|
|
157
158
|
* Confirm action
|
|
@@ -174,11 +175,14 @@ export class NotificationContainer {
|
|
|
174
175
|
}
|
|
175
176
|
/**
|
|
176
177
|
* Hide loading
|
|
178
|
+
* @param force Force to hide, otherwise, only the last one
|
|
177
179
|
*/
|
|
178
|
-
hideLoading() {
|
|
180
|
+
hideLoading(force) {
|
|
179
181
|
var _a;
|
|
180
182
|
// Deduct to count
|
|
181
183
|
this.loadingCount--;
|
|
184
|
+
if (force)
|
|
185
|
+
this.loadingCount = 0;
|
|
182
186
|
if (this.loadingCount === 0) {
|
|
183
187
|
(_a = this.lastLoading) === null || _a === void 0 ? void 0 : _a.dismiss();
|
|
184
188
|
this.lastLoading = undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/notificationbase",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.96",
|
|
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.97"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@babel/core": "^7.16.
|
|
52
|
-
"@babel/plugin-transform-runtime": "^7.16.
|
|
53
|
-
"@babel/preset-env": "^7.16.
|
|
54
|
-
"@babel/runtime-corejs3": "^7.16.
|
|
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.7",
|
|
52
|
+
"@babel/plugin-transform-runtime": "^7.16.7",
|
|
53
|
+
"@babel/preset-env": "^7.16.7",
|
|
54
|
+
"@babel/runtime-corejs3": "^7.16.7",
|
|
55
|
+
"@types/jest": "^27.4.0",
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "^5.8.1",
|
|
57
|
+
"@typescript-eslint/parser": "^5.8.1",
|
|
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
|
@@ -77,6 +77,19 @@ export interface NotificationReturn<T> {
|
|
|
77
77
|
(value: T): boolean | void | PromiseLike<boolean | void>;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
/**
|
|
81
|
+
* On prompt return callback
|
|
82
|
+
* return false will prevent default action
|
|
83
|
+
* return tuple second parameter is the error message to show
|
|
84
|
+
*/
|
|
85
|
+
export interface NotificationPromptReturn<T> extends NotificationReturn<T> {
|
|
86
|
+
(value: T):
|
|
87
|
+
| boolean
|
|
88
|
+
| [boolean, string?]
|
|
89
|
+
| void
|
|
90
|
+
| PromiseLike<boolean | [boolean, string?] | void>;
|
|
91
|
+
}
|
|
92
|
+
|
|
80
93
|
/**
|
|
81
94
|
* Notification message parameters
|
|
82
95
|
*/
|
|
@@ -110,7 +123,7 @@ export interface NotificationParameters {
|
|
|
110
123
|
/**
|
|
111
124
|
* Notification props supported for calls
|
|
112
125
|
*/
|
|
113
|
-
export interface NotificationCallProps {}
|
|
126
|
+
export interface NotificationCallProps extends Record<string, unknown> {}
|
|
114
127
|
|
|
115
128
|
/**
|
|
116
129
|
* Notification render props
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
NotificationMessageType,
|
|
8
8
|
NotificationModalType,
|
|
9
9
|
NotificationParameters,
|
|
10
|
+
NotificationPromptReturn,
|
|
10
11
|
NotificationReturn,
|
|
11
12
|
NotificationType
|
|
12
13
|
} from './Notification';
|
|
@@ -50,11 +51,13 @@ export interface INotifier<UI, C extends NotificationCallProps> {
|
|
|
50
51
|
* Report error
|
|
51
52
|
* @param error Error message
|
|
52
53
|
* @param callback Callback
|
|
54
|
+
* @param type Type, default is Error
|
|
53
55
|
* @param props Props
|
|
54
56
|
*/
|
|
55
57
|
alert(
|
|
56
58
|
error: NotificationContent<UI>,
|
|
57
59
|
callback?: NotificationReturn<void>,
|
|
60
|
+
type?: NotificationMessageType,
|
|
58
61
|
props?: C
|
|
59
62
|
): INotification<UI, C>;
|
|
60
63
|
|
|
@@ -109,8 +112,9 @@ export interface INotifier<UI, C extends NotificationCallProps> {
|
|
|
109
112
|
|
|
110
113
|
/**
|
|
111
114
|
* Hide loading
|
|
115
|
+
* @param force Force to hide, otherwise, only the last one
|
|
112
116
|
*/
|
|
113
|
-
hideLoading(): void;
|
|
117
|
+
hideLoading(force?: boolean): void;
|
|
114
118
|
|
|
115
119
|
/**
|
|
116
120
|
* Show a message
|
|
@@ -137,7 +141,7 @@ export interface INotifier<UI, C extends NotificationCallProps> {
|
|
|
137
141
|
*/
|
|
138
142
|
prompt<T = string>(
|
|
139
143
|
message: NotificationContent<UI>,
|
|
140
|
-
callback:
|
|
144
|
+
callback: NotificationPromptReturn<T>,
|
|
141
145
|
title?: NotificationContent<UI>,
|
|
142
146
|
props?: C
|
|
143
147
|
): INotification<UI, C>;
|
|
@@ -233,7 +237,7 @@ export abstract class NotificationContainer<UI, C extends NotificationCallProps>
|
|
|
233
237
|
const alignItems = this.notifications[notification.align];
|
|
234
238
|
|
|
235
239
|
// Support dismiss action
|
|
236
|
-
const {
|
|
240
|
+
const { timespan, onDismiss } = notification;
|
|
237
241
|
notification.onDismiss = () => {
|
|
238
242
|
// Remove from the collection
|
|
239
243
|
const index = alignItems.findIndex(
|
|
@@ -349,19 +353,25 @@ export abstract class NotificationContainer<UI, C extends NotificationCallProps>
|
|
|
349
353
|
* Report error
|
|
350
354
|
* @param error Error message
|
|
351
355
|
* @param callback Callback
|
|
356
|
+
* @param type Type, default is Error
|
|
352
357
|
* @param props Props
|
|
353
358
|
*/
|
|
354
|
-
alert(
|
|
359
|
+
alert(
|
|
360
|
+
error: string,
|
|
361
|
+
callback?: NotificationReturn<void>,
|
|
362
|
+
type?: NotificationMessageType,
|
|
363
|
+
props?: C
|
|
364
|
+
) {
|
|
355
365
|
// Setup
|
|
356
366
|
const n: INotificaseBase<UI, C> = {
|
|
357
367
|
inputProps: props,
|
|
358
|
-
type: NotificationType.Error,
|
|
368
|
+
type: type ?? NotificationType.Error,
|
|
359
369
|
content: error,
|
|
360
370
|
onReturn: callback
|
|
361
371
|
};
|
|
362
372
|
|
|
363
373
|
// Add to the collection
|
|
364
|
-
return this.addRaw(n);
|
|
374
|
+
return this.addRaw(n, true);
|
|
365
375
|
}
|
|
366
376
|
|
|
367
377
|
/**
|
|
@@ -392,11 +402,14 @@ export abstract class NotificationContainer<UI, C extends NotificationCallProps>
|
|
|
392
402
|
|
|
393
403
|
/**
|
|
394
404
|
* Hide loading
|
|
405
|
+
* @param force Force to hide, otherwise, only the last one
|
|
395
406
|
*/
|
|
396
|
-
hideLoading() {
|
|
407
|
+
hideLoading(force?: boolean) {
|
|
397
408
|
// Deduct to count
|
|
398
409
|
this.loadingCount--;
|
|
399
410
|
|
|
411
|
+
if (force) this.loadingCount = 0;
|
|
412
|
+
|
|
400
413
|
if (this.loadingCount === 0) {
|
|
401
414
|
this.lastLoading?.dismiss();
|
|
402
415
|
this.lastLoading = undefined;
|
|
@@ -445,7 +458,7 @@ export abstract class NotificationContainer<UI, C extends NotificationCallProps>
|
|
|
445
458
|
*/
|
|
446
459
|
prompt<T>(
|
|
447
460
|
message: NotificationContent<UI>,
|
|
448
|
-
callback:
|
|
461
|
+
callback: NotificationPromptReturn<T>,
|
|
449
462
|
title?: string,
|
|
450
463
|
props?: C
|
|
451
464
|
) {
|