@etsoo/notificationbase 1.0.97 → 1.1.1
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 +5 -3
- package/lib/Notification.d.ts +4 -3
- package/lib/NotificationContainer.d.ts +8 -8
- package/lib/NotificationContainer.js +13 -3
- package/package.json +14 -14
- package/src/Notification.ts +4 -7
- package/src/NotificationContainer.ts +23 -8
package/README.md
CHANGED
|
@@ -102,14 +102,16 @@ Methods:
|
|
|
102
102
|
add(notification: INotification<UI, C>, top?: boolean): void;
|
|
103
103
|
|
|
104
104
|
/**
|
|
105
|
-
* Report error
|
|
106
|
-
* @param
|
|
105
|
+
* Report error or message
|
|
106
|
+
* @param errorOrTitle Error message or title
|
|
107
107
|
* @param callback Callback
|
|
108
|
+
* @param type Type, default is Error
|
|
108
109
|
* @param props Props
|
|
109
110
|
*/
|
|
110
111
|
alert(
|
|
111
|
-
error: NotificationContent<UI>,
|
|
112
|
+
error: NotificationContent<UI> | [NotificationContent<UI>, NotificationContent<UI>],
|
|
112
113
|
callback?: NotificationReturn<void>,
|
|
114
|
+
type?: NotificationMessageType,
|
|
113
115
|
props?: C
|
|
114
116
|
): INotification<UI, C>;
|
|
115
117
|
|
package/lib/Notification.d.ts
CHANGED
|
@@ -67,11 +67,12 @@ export interface NotifictionRenderSetup {
|
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
69
|
* On return callback
|
|
70
|
+
* T = string | undefined, Undefined value means cancel
|
|
70
71
|
* return false will prevent default action
|
|
71
|
-
* return
|
|
72
|
+
* return string is the error message to show
|
|
72
73
|
*/
|
|
73
74
|
export interface NotificationReturn<T> {
|
|
74
|
-
(value: T): boolean |
|
|
75
|
+
(value: T): boolean | string | void | PromiseLike<boolean | string | void>;
|
|
75
76
|
}
|
|
76
77
|
/**
|
|
77
78
|
* Notification message parameters
|
|
@@ -244,7 +245,7 @@ export declare abstract class Notification<UI, C extends NotificationCallProps>
|
|
|
244
245
|
/**
|
|
245
246
|
* On return value
|
|
246
247
|
*/
|
|
247
|
-
onReturn?: NotificationReturn<
|
|
248
|
+
onReturn?: NotificationReturn<unknown>;
|
|
248
249
|
private _open;
|
|
249
250
|
/**
|
|
250
251
|
* Is open or not
|
|
@@ -30,13 +30,13 @@ export interface INotifier<UI, C extends NotificationCallProps> {
|
|
|
30
30
|
*/
|
|
31
31
|
add(notification: INotification<UI, C>, top?: boolean): void;
|
|
32
32
|
/**
|
|
33
|
-
* Report error
|
|
34
|
-
* @param
|
|
33
|
+
* Report error or message
|
|
34
|
+
* @param errorOrTitle Error message or title
|
|
35
35
|
* @param callback Callback
|
|
36
36
|
* @param type Type, default is Error
|
|
37
37
|
* @param props Props
|
|
38
38
|
*/
|
|
39
|
-
alert(
|
|
39
|
+
alert(errorOrTitle: NotificationContent<UI> | [NotificationContent<UI>, NotificationContent<UI>], callback?: NotificationReturn<void>, type?: NotificationMessageType, props?: C): INotification<UI, C>;
|
|
40
40
|
/**
|
|
41
41
|
* Align all notification count
|
|
42
42
|
* @param align Align
|
|
@@ -95,7 +95,7 @@ export interface INotifier<UI, C extends NotificationCallProps> {
|
|
|
95
95
|
* @param title Title
|
|
96
96
|
* @param props More properties
|
|
97
97
|
*/
|
|
98
|
-
prompt<T = string>(message: NotificationContent<UI>, callback: NotificationReturn<T>, title?: NotificationContent<UI>, props?: C): INotification<UI, C>;
|
|
98
|
+
prompt<T = string | undefined>(message: NotificationContent<UI>, callback: NotificationReturn<T>, title?: NotificationContent<UI>, props?: C): INotification<UI, C>;
|
|
99
99
|
/**
|
|
100
100
|
* Show loading
|
|
101
101
|
* @param title Title
|
|
@@ -182,13 +182,13 @@ export declare abstract class NotificationContainer<UI, C extends NotificationCa
|
|
|
182
182
|
*/
|
|
183
183
|
getById(id: string): INotification<UI, C> | undefined;
|
|
184
184
|
/**
|
|
185
|
-
* Report error
|
|
186
|
-
* @param
|
|
185
|
+
* Report error or message
|
|
186
|
+
* @param errorOrTitle Error message or title
|
|
187
187
|
* @param callback Callback
|
|
188
188
|
* @param type Type, default is Error
|
|
189
189
|
* @param props Props
|
|
190
190
|
*/
|
|
191
|
-
alert(
|
|
191
|
+
alert(errorOrTitle: NotificationContent<UI> | [NotificationContent<UI>, NotificationContent<UI>], callback?: NotificationReturn<void>, type?: NotificationMessageType, props?: C): INotification<UI, C>;
|
|
192
192
|
/**
|
|
193
193
|
* Confirm action
|
|
194
194
|
* @param message Message
|
|
@@ -218,7 +218,7 @@ export declare abstract class NotificationContainer<UI, C extends NotificationCa
|
|
|
218
218
|
* @param title Title
|
|
219
219
|
* @param props More properties
|
|
220
220
|
*/
|
|
221
|
-
prompt<T>(message: NotificationContent<UI>, callback: NotificationReturn<T>, title?: string, props?: C): INotification<UI, C>;
|
|
221
|
+
prompt<T = string | undefined>(message: NotificationContent<UI>, callback: NotificationReturn<T>, title?: string, props?: C): INotification<UI, C>;
|
|
222
222
|
/**
|
|
223
223
|
* Show loading
|
|
224
224
|
* @param title Title
|
|
@@ -137,17 +137,27 @@ export class NotificationContainer {
|
|
|
137
137
|
return undefined;
|
|
138
138
|
}
|
|
139
139
|
/**
|
|
140
|
-
* Report error
|
|
141
|
-
* @param
|
|
140
|
+
* Report error or message
|
|
141
|
+
* @param errorOrTitle Error message or title
|
|
142
142
|
* @param callback Callback
|
|
143
143
|
* @param type Type, default is Error
|
|
144
144
|
* @param props Props
|
|
145
145
|
*/
|
|
146
|
-
alert(
|
|
146
|
+
alert(errorOrTitle, callback, type, props) {
|
|
147
|
+
// Parse messange and title
|
|
148
|
+
let error, title;
|
|
149
|
+
if (Array.isArray(errorOrTitle)) {
|
|
150
|
+
error = errorOrTitle[0];
|
|
151
|
+
title = errorOrTitle[1];
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
error = errorOrTitle;
|
|
155
|
+
}
|
|
147
156
|
// Setup
|
|
148
157
|
const n = {
|
|
149
158
|
inputProps: props,
|
|
150
159
|
type: type !== null && type !== void 0 ? type : NotificationType.Error,
|
|
160
|
+
title,
|
|
151
161
|
content: error,
|
|
152
162
|
onReturn: callback
|
|
153
163
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/notificationbase",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
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.
|
|
48
|
+
"@etsoo/shared": "^1.1.9"
|
|
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.
|
|
51
|
+
"@babel/core": "^7.16.12",
|
|
52
|
+
"@babel/plugin-transform-runtime": "^7.16.10",
|
|
53
|
+
"@babel/preset-env": "^7.16.11",
|
|
54
|
+
"@babel/runtime-corejs3": "^7.16.8",
|
|
55
55
|
"@types/jest": "^27.4.0",
|
|
56
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
57
|
-
"@typescript-eslint/parser": "^5.
|
|
58
|
-
"babel-jest": "^27.4.
|
|
59
|
-
"eslint": "^8.
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "^5.10.2",
|
|
57
|
+
"@typescript-eslint/parser": "^5.10.2",
|
|
58
|
+
"babel-jest": "^27.4.6",
|
|
59
|
+
"eslint": "^8.8.0",
|
|
60
60
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
61
|
-
"eslint-plugin-import": "^2.25.
|
|
62
|
-
"jest": "^27.4.
|
|
63
|
-
"ts-jest": "^27.1.
|
|
64
|
-
"typescript": "^4.5.
|
|
61
|
+
"eslint-plugin-import": "^2.25.4",
|
|
62
|
+
"jest": "^27.4.7",
|
|
63
|
+
"ts-jest": "^27.1.3",
|
|
64
|
+
"typescript": "^4.5.5"
|
|
65
65
|
}
|
|
66
66
|
}
|
package/src/Notification.ts
CHANGED
|
@@ -71,15 +71,12 @@ export interface NotifictionRenderSetup {
|
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
73
|
* On return callback
|
|
74
|
+
* T = string | undefined, Undefined value means cancel
|
|
74
75
|
* return false will prevent default action
|
|
75
|
-
* return
|
|
76
|
+
* return string is the error message to show
|
|
76
77
|
*/
|
|
77
78
|
export interface NotificationReturn<T> {
|
|
78
|
-
(value: T):
|
|
79
|
-
| boolean
|
|
80
|
-
| [boolean, string | undefined]
|
|
81
|
-
| void
|
|
82
|
-
| PromiseLike<boolean | [boolean, string | undefined] | void>;
|
|
79
|
+
(value: T): boolean | string | void | PromiseLike<boolean | string | void>;
|
|
83
80
|
}
|
|
84
81
|
|
|
85
82
|
/**
|
|
@@ -289,7 +286,7 @@ export abstract class Notification<UI, C extends NotificationCallProps>
|
|
|
289
286
|
/**
|
|
290
287
|
* On return value
|
|
291
288
|
*/
|
|
292
|
-
onReturn?: NotificationReturn<
|
|
289
|
+
onReturn?: NotificationReturn<unknown>;
|
|
293
290
|
|
|
294
291
|
private _open: boolean = true;
|
|
295
292
|
/**
|
|
@@ -47,14 +47,16 @@ export interface INotifier<UI, C extends NotificationCallProps> {
|
|
|
47
47
|
add(notification: INotification<UI, C>, top?: boolean): void;
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
|
-
* Report error
|
|
51
|
-
* @param
|
|
50
|
+
* Report error or message
|
|
51
|
+
* @param errorOrTitle Error message or title
|
|
52
52
|
* @param callback Callback
|
|
53
53
|
* @param type Type, default is Error
|
|
54
54
|
* @param props Props
|
|
55
55
|
*/
|
|
56
56
|
alert(
|
|
57
|
-
|
|
57
|
+
errorOrTitle:
|
|
58
|
+
| NotificationContent<UI>
|
|
59
|
+
| [NotificationContent<UI>, NotificationContent<UI>],
|
|
58
60
|
callback?: NotificationReturn<void>,
|
|
59
61
|
type?: NotificationMessageType,
|
|
60
62
|
props?: C
|
|
@@ -138,7 +140,7 @@ export interface INotifier<UI, C extends NotificationCallProps> {
|
|
|
138
140
|
* @param title Title
|
|
139
141
|
* @param props More properties
|
|
140
142
|
*/
|
|
141
|
-
prompt<T = string>(
|
|
143
|
+
prompt<T = string | undefined>(
|
|
142
144
|
message: NotificationContent<UI>,
|
|
143
145
|
callback: NotificationReturn<T>,
|
|
144
146
|
title?: NotificationContent<UI>,
|
|
@@ -349,22 +351,35 @@ export abstract class NotificationContainer<UI, C extends NotificationCallProps>
|
|
|
349
351
|
}
|
|
350
352
|
|
|
351
353
|
/**
|
|
352
|
-
* Report error
|
|
353
|
-
* @param
|
|
354
|
+
* Report error or message
|
|
355
|
+
* @param errorOrTitle Error message or title
|
|
354
356
|
* @param callback Callback
|
|
355
357
|
* @param type Type, default is Error
|
|
356
358
|
* @param props Props
|
|
357
359
|
*/
|
|
358
360
|
alert(
|
|
359
|
-
|
|
361
|
+
errorOrTitle:
|
|
362
|
+
| NotificationContent<UI>
|
|
363
|
+
| [NotificationContent<UI>, NotificationContent<UI>],
|
|
360
364
|
callback?: NotificationReturn<void>,
|
|
361
365
|
type?: NotificationMessageType,
|
|
362
366
|
props?: C
|
|
363
367
|
) {
|
|
368
|
+
// Parse messange and title
|
|
369
|
+
let error: NotificationContent<UI>,
|
|
370
|
+
title: NotificationContent<UI> | undefined;
|
|
371
|
+
if (Array.isArray(errorOrTitle)) {
|
|
372
|
+
error = errorOrTitle[0];
|
|
373
|
+
title = errorOrTitle[1];
|
|
374
|
+
} else {
|
|
375
|
+
error = errorOrTitle;
|
|
376
|
+
}
|
|
377
|
+
|
|
364
378
|
// Setup
|
|
365
379
|
const n: INotificaseBase<UI, C> = {
|
|
366
380
|
inputProps: props,
|
|
367
381
|
type: type ?? NotificationType.Error,
|
|
382
|
+
title,
|
|
368
383
|
content: error,
|
|
369
384
|
onReturn: callback
|
|
370
385
|
};
|
|
@@ -455,7 +470,7 @@ export abstract class NotificationContainer<UI, C extends NotificationCallProps>
|
|
|
455
470
|
* @param title Title
|
|
456
471
|
* @param props More properties
|
|
457
472
|
*/
|
|
458
|
-
prompt<T>(
|
|
473
|
+
prompt<T = string | undefined>(
|
|
459
474
|
message: NotificationContent<UI>,
|
|
460
475
|
callback: NotificationReturn<T>,
|
|
461
476
|
title?: string,
|