@etsoo/notificationbase 1.0.75 → 1.0.79

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.
@@ -3,20 +3,26 @@ import {
3
3
  INotification,
4
4
  Notification,
5
5
  NotificationAlign,
6
+ NotificationCallProps,
6
7
  NotificationRenderProps,
7
8
  NotificationType
8
9
  } from '../src/Notification';
9
10
  import { NotificationContainer } from '../src/NotificationContainer';
10
11
 
11
12
  // Class implementation for tests
12
- class NotificationTest extends Notification<any> {
13
+ class NotificationTest extends Notification<any, NotificationCallProps> {
13
14
  render(props: NotificationRenderProps, className?: string, options?: any) {
14
15
  throw new Error('Method not implemented.');
15
16
  }
16
17
  }
17
18
 
18
- class NotificationContainerTest extends NotificationContainer<any> {
19
- protected addRaw(data: INotificaseBase): INotification<any> {
19
+ class NotificationContainerTest extends NotificationContainer<
20
+ any,
21
+ NotificationCallProps
22
+ > {
23
+ protected addRaw(
24
+ data: INotificaseBase<NotificationCallProps>
25
+ ): INotification<any, NotificationCallProps> {
20
26
  throw new Error('Method not implemented.');
21
27
  }
22
28
  }
@@ -44,10 +50,6 @@ test('Tests for notification dismiss', () => {
44
50
  // Act
45
51
  n.dismiss(2);
46
52
 
47
- // Assert
48
- // setTimeout should be called 1 time
49
- expect(setTimeout).toBeCalled();
50
-
51
53
  // Fast forward
52
54
  jest.runOnlyPendingTimers();
53
55
 
@@ -72,7 +72,7 @@ export interface NotifictionRenderSetup {
72
72
  * return false will prevent default action
73
73
  */
74
74
  export interface NotificationReturn<T> {
75
- (value: T): boolean | void;
75
+ (value: T): boolean | void | PromiseLike<boolean | void>;
76
76
  }
77
77
  /**
78
78
  * Notification message parameters
@@ -99,6 +99,11 @@ export interface NotificationParameters {
99
99
  */
100
100
  top?: boolean;
101
101
  }
102
+ /**
103
+ * Notification props supported for calls
104
+ */
105
+ export interface NotificationCallProps {
106
+ }
102
107
  /**
103
108
  * Notification render props
104
109
  */
@@ -107,7 +112,7 @@ export interface NotificationRenderProps {
107
112
  /**
108
113
  * Notification base interface
109
114
  */
110
- export interface INotificaseBase {
115
+ export interface INotificaseBase<C extends NotificationCallProps> {
111
116
  /**
112
117
  * Display align
113
118
  */
@@ -119,7 +124,7 @@ export interface INotificaseBase {
119
124
  /**
120
125
  * Input or control properties
121
126
  */
122
- inputProps?: any;
127
+ inputProps?: C;
123
128
  /**
124
129
  * On dismiss handling
125
130
  */
@@ -138,6 +143,7 @@ export interface INotificaseBase {
138
143
  timespan?: number;
139
144
  /**
140
145
  * Render setup / callback
146
+ * Add more properties
141
147
  */
142
148
  renderSetup?: NotifictionRenderSetup;
143
149
  /**
@@ -152,7 +158,7 @@ export interface INotificaseBase {
152
158
  /**
153
159
  * Notification interface
154
160
  */
155
- export interface INotification<UI> extends INotificaseBase {
161
+ export interface INotification<UI, C extends NotificationCallProps> extends INotificaseBase<C> {
156
162
  /**
157
163
  * Display align
158
164
  */
@@ -201,13 +207,13 @@ export interface INotification<UI> extends INotificaseBase {
201
207
  * @param className Style class name
202
208
  * @param options Other options
203
209
  */
204
- render(props: NotificationRenderProps, className?: string, options?: any): UI | undefined;
210
+ render(props: NotificationRenderProps, className?: string): UI | undefined;
205
211
  }
206
212
  /**
207
213
  * Notification class
208
214
  * Generic parameter UI presents UI element type
209
215
  */
210
- export declare abstract class Notification<UI> implements INotification<UI> {
216
+ export declare abstract class Notification<UI, C extends NotificationCallProps> implements INotification<UI, C> {
211
217
  /**
212
218
  * Display align
213
219
  */
@@ -227,7 +233,7 @@ export declare abstract class Notification<UI> implements INotification<UI> {
227
233
  /**
228
234
  * Input or control properties
229
235
  */
230
- inputProps?: any;
236
+ inputProps?: C;
231
237
  /**
232
238
  * Display as modal
233
239
  */
@@ -291,9 +297,8 @@ export declare abstract class Notification<UI> implements INotification<UI> {
291
297
  dispose(): void;
292
298
  /**
293
299
  * Render method
294
- * @param props Props
300
+ * @param props Props, provider's UI props
295
301
  * @param className Style class name
296
- * @param options Other options
297
302
  */
298
- abstract render(props: NotificationRenderProps, className?: string, options?: any): UI | undefined;
303
+ abstract render(props: NotificationRenderProps, className?: string): UI | undefined;
299
304
  }
@@ -96,7 +96,7 @@ export class Notification {
96
96
  return false;
97
97
  if (delaySeconds > 0) {
98
98
  this.removeTimeout();
99
- this.dismissSeed = setTimeout(this.dismiss.bind(this), delaySeconds * 1000, 0 // force to dismiss
99
+ this.dismissSeed = window.setTimeout(this.dismiss.bind(this), delaySeconds * 1000, 0 // force to dismiss
100
100
  );
101
101
  return true;
102
102
  }
@@ -1,20 +1,20 @@
1
- import { INotificaseBase, INotification, NotificationAlign, NotificationMessageType, NotificationParameters, NotificationReturn } from './Notification';
1
+ import { INotificaseBase, INotification, NotificationAlign, NotificationCallProps, NotificationMessageType, NotificationParameters, NotificationReturn } from './Notification';
2
2
  /**
3
3
  * Notification action
4
4
  */
5
- export interface NotificationAction<UI> {
6
- (notification: INotification<UI>, dismiss: boolean): void;
5
+ export interface NotificationAction<UI, C extends NotificationCallProps> {
6
+ (notification: INotification<UI, C>, dismiss: boolean): void;
7
7
  }
8
8
  /**
9
9
  * Notifications sorted with display align type
10
10
  */
11
- export declare type NotificationDictionary<UI> = {
12
- [key: number]: INotification<UI>[];
11
+ export declare type NotificationDictionary<UI, C extends NotificationCallProps> = {
12
+ [key: number]: INotification<UI, C>[];
13
13
  };
14
14
  /**
15
15
  * Notifier interface
16
16
  */
17
- export interface INotifier<UI> {
17
+ export interface INotifier<UI, C extends NotificationCallProps> {
18
18
  /**
19
19
  * Is loading bar showing
20
20
  */
@@ -28,13 +28,14 @@ export interface INotifier<UI> {
28
28
  * @param notification Notification
29
29
  * @param top Is insert top
30
30
  */
31
- add(notification: INotification<UI>, top?: boolean): void;
31
+ add(notification: INotification<UI, C>, top?: boolean): void;
32
32
  /**
33
33
  * Report error
34
34
  * @param error Error message
35
35
  * @param callback Callback
36
+ * @param props Props
36
37
  */
37
- alert(error: string, callback?: NotificationReturn<void>): void;
38
+ alert(error: string, callback?: NotificationReturn<void>, props?: C): void;
38
39
  /**
39
40
  * Align all notification count
40
41
  * @param align Align
@@ -54,8 +55,9 @@ export interface INotifier<UI> {
54
55
  * @param message Message
55
56
  * @param title Title
56
57
  * @param callback Callback
58
+ * @param props Props
57
59
  */
58
- confirm(message: string, title?: string, callback?: NotificationReturn<boolean>): void;
60
+ confirm(message: string, title?: string, callback?: NotificationReturn<boolean>, props?: C): void;
59
61
  /**
60
62
  * Dispose all notifications
61
63
  */
@@ -65,12 +67,12 @@ export interface INotifier<UI> {
65
67
  * @param align Align
66
68
  * @param id Notification id
67
69
  */
68
- get(align: NotificationAlign, id: string): INotification<UI> | undefined;
70
+ get(align: NotificationAlign, id: string): INotification<UI, C> | undefined;
69
71
  /**
70
72
  * Get notification with id
71
73
  * @param id Notification id
72
74
  */
73
- getById(id: string): INotification<UI> | undefined;
75
+ getById(id: string): INotification<UI, C> | undefined;
74
76
  /**
75
77
  * Hide loading
76
78
  */
@@ -81,8 +83,9 @@ export interface INotifier<UI> {
81
83
  * @param message Message
82
84
  * @param title Title
83
85
  * @param parameters Parameters
86
+ * @param props Props
84
87
  */
85
- message(type: NotificationMessageType, message: string, title?: string, parameters?: NotificationParameters): INotification<UI>;
88
+ message(type: NotificationMessageType, message: string, title?: string, parameters?: NotificationParameters, props?: C): INotification<UI, C>;
86
89
  /**
87
90
  * Prompt action
88
91
  * @param message Message
@@ -90,7 +93,7 @@ export interface INotifier<UI> {
90
93
  * @param title Title
91
94
  * @param props More properties
92
95
  */
93
- prompt(message: string, callback: NotificationReturn<string>, title?: string, props?: any): void;
96
+ prompt<T = string>(message: string, callback: NotificationReturn<T>, title?: string, props?: C): void;
94
97
  /**
95
98
  * Show loading
96
99
  * @param title Title
@@ -102,19 +105,20 @@ export interface INotifier<UI> {
102
105
  * @param title Title
103
106
  * @param callback Callback
104
107
  * @param timespan Timespan to close
108
+ * @param props Props
105
109
  */
106
- succeed(message: string, title?: string, callback?: NotificationReturn<void>, timespan?: number): void;
110
+ succeed(message: string, title?: string, callback?: NotificationReturn<void>, timespan?: number, props?: C): void;
107
111
  }
108
112
  /**
109
113
  * Notification container class
110
114
  */
111
- export declare abstract class NotificationContainer<UI> implements INotifier<UI> {
115
+ export declare abstract class NotificationContainer<UI, C extends NotificationCallProps> implements INotifier<UI, C> {
112
116
  private update;
113
117
  private lastLoading?;
114
118
  /**
115
119
  * Notification collection to display
116
120
  */
117
- readonly notifications: NotificationDictionary<UI>;
121
+ readonly notifications: NotificationDictionary<UI, C>;
118
122
  /**
119
123
  * Is loading bar showing
120
124
  */
@@ -126,19 +130,19 @@ export declare abstract class NotificationContainer<UI> implements INotifier<UI>
126
130
  /**
127
131
  * Constructor
128
132
  */
129
- constructor(update: NotificationAction<UI>);
133
+ constructor(update: NotificationAction<UI, C>);
130
134
  /**
131
135
  * Add raw definition
132
136
  * @param data Notification data definition
133
137
  * @param modal Show as modal
134
138
  */
135
- protected abstract addRaw(data: INotificaseBase, modal?: boolean): INotification<UI>;
139
+ protected abstract addRaw(data: INotificaseBase<C>, modal?: boolean): INotification<UI, C>;
136
140
  /**
137
141
  * Add notification
138
142
  * @param notification Notification
139
143
  * @param top Is insert top
140
144
  */
141
- add(notification: INotification<UI>, top?: boolean): void;
145
+ add(notification: INotification<UI, C>, top?: boolean): void;
142
146
  /**
143
147
  * Align all notification count
144
148
  * @param align Align
@@ -168,25 +172,27 @@ export declare abstract class NotificationContainer<UI> implements INotifier<UI>
168
172
  * @param align Align
169
173
  * @param id Notification id
170
174
  */
171
- get(align: NotificationAlign, id: string): INotification<UI> | undefined;
175
+ get(align: NotificationAlign, id: string): INotification<UI, C> | undefined;
172
176
  /**
173
177
  * Get notification with id
174
178
  * @param id Notification id
175
179
  */
176
- getById(id: string): INotification<UI> | undefined;
180
+ getById(id: string): INotification<UI, C> | undefined;
177
181
  /**
178
182
  * Report error
179
183
  * @param error Error message
180
184
  * @param callback Callback
185
+ * @param props Props
181
186
  */
182
- alert(error: string, callback?: NotificationReturn<void>): void;
187
+ alert(error: string, callback?: NotificationReturn<void>, props?: C): void;
183
188
  /**
184
189
  * Confirm action
185
190
  * @param message Message
186
191
  * @param title Title
187
192
  * @param callback Callback
193
+ * @param props Props
188
194
  */
189
- confirm(message: string, title?: string, callback?: NotificationReturn<boolean>): void;
195
+ confirm(message: string, title?: string, callback?: NotificationReturn<boolean>, props?: C): void;
190
196
  /**
191
197
  * Hide loading
192
198
  */
@@ -197,8 +203,9 @@ export declare abstract class NotificationContainer<UI> implements INotifier<UI>
197
203
  * @param message Message
198
204
  * @param title Title
199
205
  * @param parameters Parameters
206
+ * @param props Props
200
207
  */
201
- message(type: NotificationMessageType, message: string, title?: string, parameters?: NotificationParameters): INotification<UI>;
208
+ message(type: NotificationMessageType, message: string, title?: string, parameters?: NotificationParameters, props?: C): INotification<UI, C>;
202
209
  /**
203
210
  * Prompt action
204
211
  * @param message Message
@@ -206,7 +213,7 @@ export declare abstract class NotificationContainer<UI> implements INotifier<UI>
206
213
  * @param title Title
207
214
  * @param props More properties
208
215
  */
209
- prompt(message: string, callback: NotificationReturn<string>, title?: string, props?: any): void;
216
+ prompt<T>(message: string, callback: NotificationReturn<T>, title?: string, props?: C): void;
210
217
  /**
211
218
  * Show loading
212
219
  * @param title Title
@@ -218,6 +225,7 @@ export declare abstract class NotificationContainer<UI> implements INotifier<UI>
218
225
  * @param title Title
219
226
  * @param callback Callback
220
227
  * @param timespan Timespan to close
228
+ * @param props Props
221
229
  */
222
- succeed(message: string, title?: string, callback?: NotificationReturn<void>, timespan?: number): void;
230
+ succeed(message: string, title?: string, callback?: NotificationReturn<void>, timespan?: number, props?: C): void;
223
231
  }
@@ -149,15 +149,16 @@ export class NotificationContainer {
149
149
  * Report error
150
150
  * @param error Error message
151
151
  * @param callback Callback
152
+ * @param props Props
152
153
  */
153
- alert(error, callback) {
154
+ alert(error, callback, props) {
154
155
  // Setup
155
156
  const n = {
157
+ inputProps: props,
156
158
  type: NotificationType.Error,
157
- content: error
159
+ content: error,
160
+ onReturn: callback
158
161
  };
159
- // Callback
160
- n.onReturn = callback;
161
162
  // Add to the collection
162
163
  this.addRaw(n);
163
164
  }
@@ -166,16 +167,17 @@ export class NotificationContainer {
166
167
  * @param message Message
167
168
  * @param title Title
168
169
  * @param callback Callback
170
+ * @param props Props
169
171
  */
170
- confirm(message, title, callback) {
172
+ confirm(message, title, callback, props) {
171
173
  // Setup
172
174
  const n = {
173
175
  type: NotificationType.Confirm,
174
176
  content: message,
175
- title
177
+ title,
178
+ onReturn: callback,
179
+ inputProps: props
176
180
  };
177
- // Callback
178
- n.onReturn = callback;
179
181
  // Add to the collection
180
182
  this.addRaw(n);
181
183
  }
@@ -192,8 +194,9 @@ export class NotificationContainer {
192
194
  * @param message Message
193
195
  * @param title Title
194
196
  * @param parameters Parameters
197
+ * @param props Props
195
198
  */
196
- message(type, message, title, parameters) {
199
+ message(type, message, title, parameters, props) {
197
200
  // Destruct
198
201
  const { align, timespan, callback, modal } = parameters !== null && parameters !== void 0 ? parameters : {};
199
202
  // Setup
@@ -202,10 +205,10 @@ export class NotificationContainer {
202
205
  content: message,
203
206
  title,
204
207
  align,
205
- timespan
208
+ timespan,
209
+ onReturn: callback,
210
+ inputProps: props
206
211
  };
207
- // Additional parameters
208
- n.onReturn = callback;
209
212
  // Add to the collection
210
213
  return this.addRaw(n, modal);
211
214
  }
@@ -221,12 +224,10 @@ export class NotificationContainer {
221
224
  const n = {
222
225
  type: NotificationType.Prompt,
223
226
  content: message,
224
- title
227
+ title,
228
+ inputProps: props,
229
+ onReturn: callback
225
230
  };
226
- // Additional parameters
227
- n.inputProps = props;
228
- // Callback
229
- n.onReturn = callback;
230
231
  // Add to the collection
231
232
  this.addRaw(n);
232
233
  }
@@ -250,8 +251,9 @@ export class NotificationContainer {
250
251
  * @param title Title
251
252
  * @param callback Callback
252
253
  * @param timespan Timespan to close
254
+ * @param props Props
253
255
  */
254
- succeed(message, title, callback, timespan) {
256
+ succeed(message, title, callback, timespan, props) {
255
257
  // Default to zero for constant
256
258
  timespan !== null && timespan !== void 0 ? timespan : (timespan = 0);
257
259
  // Create as message
@@ -260,6 +262,6 @@ export class NotificationContainer {
260
262
  modal: true,
261
263
  timespan,
262
264
  callback
263
- });
265
+ }, props);
264
266
  }
265
267
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/notificationbase",
3
- "version": "1.0.75",
3
+ "version": "1.0.79",
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",
@@ -40,24 +40,24 @@
40
40
  },
41
41
  "homepage": "https://github.com/ETSOO/NotificationBase#readme",
42
42
  "dependencies": {
43
- "@etsoo/shared": "^1.0.39"
43
+ "@etsoo/shared": "^1.0.46"
44
44
  },
45
45
  "devDependencies": {
46
- "@babel/core": "^7.13.10",
47
- "@babel/plugin-transform-runtime": "^7.13.15",
48
- "@babel/preset-env": "^7.13.10",
49
- "@babel/runtime-corejs3": "^7.13.10",
50
- "@types/jest": "^26.0.21",
51
- "@typescript-eslint/eslint-plugin": "^4.18.0",
52
- "@typescript-eslint/parser": "^4.18.0",
46
+ "@babel/core": "^7.15.8",
47
+ "@babel/plugin-transform-runtime": "^7.15.8",
48
+ "@babel/preset-env": "^7.15.8",
49
+ "@babel/runtime-corejs3": "^7.15.4",
50
+ "@types/jest": "^27.0.2",
51
+ "@typescript-eslint/eslint-plugin": "^4.33.0",
52
+ "@typescript-eslint/parser": "^4.33.0",
53
53
  "babel-core": "^7.0.0-bridge.0",
54
- "babel-jest": "^26.6.3",
55
- "eslint": "^7.22.0",
54
+ "babel-jest": "^27.2.4",
55
+ "eslint": "^7.32.0",
56
56
  "eslint-config-airbnb-base": "^14.2.1",
57
- "eslint-plugin-import": "^2.22.1",
58
- "jest": "^26.6.3",
59
- "regenerator-runtime": "^0.13.7",
60
- "ts-jest": "^26.5.4",
61
- "typescript": "^4.2.3"
57
+ "eslint-plugin-import": "^2.24.2",
58
+ "jest": "^27.2.4",
59
+ "regenerator-runtime": "^0.13.9",
60
+ "ts-jest": "^27.0.5",
61
+ "typescript": "^4.4.3"
62
62
  }
63
63
  }
@@ -76,7 +76,7 @@ export interface NotifictionRenderSetup {
76
76
  * return false will prevent default action
77
77
  */
78
78
  export interface NotificationReturn<T> {
79
- (value: T): boolean | void;
79
+ (value: T): boolean | void | PromiseLike<boolean | void>;
80
80
  }
81
81
 
82
82
  /**
@@ -109,6 +109,11 @@ export interface NotificationParameters {
109
109
  top?: boolean;
110
110
  }
111
111
 
112
+ /**
113
+ * Notification props supported for calls
114
+ */
115
+ export interface NotificationCallProps {}
116
+
112
117
  /**
113
118
  * Notification render props
114
119
  */
@@ -117,7 +122,7 @@ export interface NotificationRenderProps {}
117
122
  /**
118
123
  * Notification base interface
119
124
  */
120
- export interface INotificaseBase {
125
+ export interface INotificaseBase<C extends NotificationCallProps> {
121
126
  /**
122
127
  * Display align
123
128
  */
@@ -131,7 +136,7 @@ export interface INotificaseBase {
131
136
  /**
132
137
  * Input or control properties
133
138
  */
134
- inputProps?: any;
139
+ inputProps?: C;
135
140
 
136
141
  /**
137
142
  * On dismiss handling
@@ -155,6 +160,7 @@ export interface INotificaseBase {
155
160
 
156
161
  /**
157
162
  * Render setup / callback
163
+ * Add more properties
158
164
  */
159
165
  renderSetup?: NotifictionRenderSetup;
160
166
 
@@ -172,7 +178,8 @@ export interface INotificaseBase {
172
178
  /**
173
179
  * Notification interface
174
180
  */
175
- export interface INotification<UI> extends INotificaseBase {
181
+ export interface INotification<UI, C extends NotificationCallProps>
182
+ extends INotificaseBase<C> {
176
183
  /**
177
184
  * Display align
178
185
  */
@@ -231,18 +238,16 @@ export interface INotification<UI> extends INotificaseBase {
231
238
  * @param className Style class name
232
239
  * @param options Other options
233
240
  */
234
- render(
235
- props: NotificationRenderProps,
236
- className?: string,
237
- options?: any
238
- ): UI | undefined;
241
+ render(props: NotificationRenderProps, className?: string): UI | undefined;
239
242
  }
240
243
 
241
244
  /**
242
245
  * Notification class
243
246
  * Generic parameter UI presents UI element type
244
247
  */
245
- export abstract class Notification<UI> implements INotification<UI> {
248
+ export abstract class Notification<UI, C extends NotificationCallProps>
249
+ implements INotification<UI, C>
250
+ {
246
251
  /**
247
252
  * Display align
248
253
  */
@@ -266,7 +271,7 @@ export abstract class Notification<UI> implements INotification<UI> {
266
271
  /**
267
272
  * Input or control properties
268
273
  */
269
- inputProps?: any;
274
+ inputProps?: C;
270
275
 
271
276
  /**
272
277
  * Display as modal
@@ -368,7 +373,7 @@ export abstract class Notification<UI> implements INotification<UI> {
368
373
 
369
374
  if (delaySeconds > 0) {
370
375
  this.removeTimeout();
371
- this.dismissSeed = setTimeout(
376
+ this.dismissSeed = window.setTimeout(
372
377
  this.dismiss.bind(this),
373
378
  delaySeconds * 1000,
374
379
  0 // force to dismiss
@@ -408,13 +413,11 @@ export abstract class Notification<UI> implements INotification<UI> {
408
413
 
409
414
  /**
410
415
  * Render method
411
- * @param props Props
416
+ * @param props Props, provider's UI props
412
417
  * @param className Style class name
413
- * @param options Other options
414
418
  */
415
419
  abstract render(
416
420
  props: NotificationRenderProps,
417
- className?: string,
418
- options?: any
421
+ className?: string
419
422
  ): UI | undefined;
420
423
  }
@@ -2,6 +2,7 @@ import {
2
2
  INotificaseBase,
3
3
  INotification,
4
4
  NotificationAlign,
5
+ NotificationCallProps,
5
6
  NotificationMessageType,
6
7
  NotificationModalType,
7
8
  NotificationParameters,
@@ -12,21 +13,21 @@ import {
12
13
  /**
13
14
  * Notification action
14
15
  */
15
- export interface NotificationAction<UI> {
16
- (notification: INotification<UI>, dismiss: boolean): void;
16
+ export interface NotificationAction<UI, C extends NotificationCallProps> {
17
+ (notification: INotification<UI, C>, dismiss: boolean): void;
17
18
  }
18
19
 
19
20
  /**
20
21
  * Notifications sorted with display align type
21
22
  */
22
- export type NotificationDictionary<UI> = {
23
- [key: number]: INotification<UI>[];
23
+ export type NotificationDictionary<UI, C extends NotificationCallProps> = {
24
+ [key: number]: INotification<UI, C>[];
24
25
  };
25
26
 
26
27
  /**
27
28
  * Notifier interface
28
29
  */
29
- export interface INotifier<UI> {
30
+ export interface INotifier<UI, C extends NotificationCallProps> {
30
31
  /**
31
32
  * Is loading bar showing
32
33
  */
@@ -42,14 +43,15 @@ export interface INotifier<UI> {
42
43
  * @param notification Notification
43
44
  * @param top Is insert top
44
45
  */
45
- add(notification: INotification<UI>, top?: boolean): void;
46
+ add(notification: INotification<UI, C>, top?: boolean): void;
46
47
 
47
48
  /**
48
49
  * Report error
49
50
  * @param error Error message
50
51
  * @param callback Callback
52
+ * @param props Props
51
53
  */
52
- alert(error: string, callback?: NotificationReturn<void>): void;
54
+ alert(error: string, callback?: NotificationReturn<void>, props?: C): void;
53
55
 
54
56
  /**
55
57
  * Align all notification count
@@ -73,11 +75,13 @@ export interface INotifier<UI> {
73
75
  * @param message Message
74
76
  * @param title Title
75
77
  * @param callback Callback
78
+ * @param props Props
76
79
  */
77
80
  confirm(
78
81
  message: string,
79
82
  title?: string,
80
- callback?: NotificationReturn<boolean>
83
+ callback?: NotificationReturn<boolean>,
84
+ props?: C
81
85
  ): void;
82
86
 
83
87
  /**
@@ -90,13 +94,13 @@ export interface INotifier<UI> {
90
94
  * @param align Align
91
95
  * @param id Notification id
92
96
  */
93
- get(align: NotificationAlign, id: string): INotification<UI> | undefined;
97
+ get(align: NotificationAlign, id: string): INotification<UI, C> | undefined;
94
98
 
95
99
  /**
96
100
  * Get notification with id
97
101
  * @param id Notification id
98
102
  */
99
- getById(id: string): INotification<UI> | undefined;
103
+ getById(id: string): INotification<UI, C> | undefined;
100
104
 
101
105
  /**
102
106
  * Hide loading
@@ -109,13 +113,15 @@ export interface INotifier<UI> {
109
113
  * @param message Message
110
114
  * @param title Title
111
115
  * @param parameters Parameters
116
+ * @param props Props
112
117
  */
113
118
  message(
114
119
  type: NotificationMessageType,
115
120
  message: string,
116
121
  title?: string,
117
- parameters?: NotificationParameters
118
- ): INotification<UI>;
122
+ parameters?: NotificationParameters,
123
+ props?: C
124
+ ): INotification<UI, C>;
119
125
 
120
126
  /**
121
127
  * Prompt action
@@ -124,11 +130,11 @@ export interface INotifier<UI> {
124
130
  * @param title Title
125
131
  * @param props More properties
126
132
  */
127
- prompt(
133
+ prompt<T = string>(
128
134
  message: string,
129
- callback: NotificationReturn<string>,
135
+ callback: NotificationReturn<T>,
130
136
  title?: string,
131
- props?: any
137
+ props?: C
132
138
  ): void;
133
139
 
134
140
  /**
@@ -143,29 +149,33 @@ export interface INotifier<UI> {
143
149
  * @param title Title
144
150
  * @param callback Callback
145
151
  * @param timespan Timespan to close
152
+ * @param props Props
146
153
  */
147
154
  succeed(
148
155
  message: string,
149
156
  title?: string,
150
157
  callback?: NotificationReturn<void>,
151
- timespan?: number
158
+ timespan?: number,
159
+ props?: C
152
160
  ): void;
153
161
  }
154
162
 
155
163
  /**
156
164
  * Notification container class
157
165
  */
158
- export abstract class NotificationContainer<UI> implements INotifier<UI> {
166
+ export abstract class NotificationContainer<UI, C extends NotificationCallProps>
167
+ implements INotifier<UI, C>
168
+ {
159
169
  // Registered update action
160
- private update: NotificationAction<UI>;
170
+ private update: NotificationAction<UI, C>;
161
171
 
162
172
  // Last loading
163
- private lastLoading?: INotification<UI>;
173
+ private lastLoading?: INotification<UI, C>;
164
174
 
165
175
  /**
166
176
  * Notification collection to display
167
177
  */
168
- readonly notifications: NotificationDictionary<UI>;
178
+ readonly notifications: NotificationDictionary<UI, C>;
169
179
 
170
180
  /**
171
181
  * Is loading bar showing
@@ -186,7 +196,7 @@ export abstract class NotificationContainer<UI> implements INotifier<UI> {
186
196
  /**
187
197
  * Constructor
188
198
  */
189
- constructor(update: NotificationAction<UI>) {
199
+ constructor(update: NotificationAction<UI, C>) {
190
200
  // Update callback
191
201
  this.update = update;
192
202
 
@@ -203,16 +213,16 @@ export abstract class NotificationContainer<UI> implements INotifier<UI> {
203
213
  * @param modal Show as modal
204
214
  */
205
215
  protected abstract addRaw(
206
- data: INotificaseBase,
216
+ data: INotificaseBase<C>,
207
217
  modal?: boolean
208
- ): INotification<UI>;
218
+ ): INotification<UI, C>;
209
219
 
210
220
  /**
211
221
  * Add notification
212
222
  * @param notification Notification
213
223
  * @param top Is insert top
214
224
  */
215
- add(notification: INotification<UI>, top: boolean = false): void {
225
+ add(notification: INotification<UI, C>, top: boolean = false): void {
216
226
  // Align collection
217
227
  const alignItems = this.notifications[notification.align];
218
228
 
@@ -308,7 +318,7 @@ export abstract class NotificationContainer<UI> implements INotifier<UI> {
308
318
  * @param id Notification id
309
319
  * @param dismiss Is dismiss
310
320
  */
311
- private doRegister(item: INotification<UI>, dismiss: boolean): void {
321
+ private doRegister(item: INotification<UI, C>, dismiss: boolean): void {
312
322
  // Call
313
323
  this.update(item, dismiss);
314
324
  }
@@ -318,7 +328,10 @@ export abstract class NotificationContainer<UI> implements INotifier<UI> {
318
328
  * @param align Align
319
329
  * @param id Notification id
320
330
  */
321
- get(align: NotificationAlign, id: string): INotification<UI> | undefined {
331
+ get(
332
+ align: NotificationAlign,
333
+ id: string
334
+ ): INotification<UI, C> | undefined {
322
335
  const items = this.notifications[align];
323
336
  return items.find((item) => item.id === id);
324
337
  }
@@ -327,7 +340,7 @@ export abstract class NotificationContainer<UI> implements INotifier<UI> {
327
340
  * Get notification with id
328
341
  * @param id Notification id
329
342
  */
330
- getById(id: string): INotification<UI> | undefined {
343
+ getById(id: string): INotification<UI, C> | undefined {
331
344
  for (const align in Object.keys(NotificationAlign)) {
332
345
  var item = this.get(align as unknown as NotificationAlign, id);
333
346
  if (item != null) return item;
@@ -339,17 +352,17 @@ export abstract class NotificationContainer<UI> implements INotifier<UI> {
339
352
  * Report error
340
353
  * @param error Error message
341
354
  * @param callback Callback
355
+ * @param props Props
342
356
  */
343
- alert(error: string, callback?: NotificationReturn<void>) {
357
+ alert(error: string, callback?: NotificationReturn<void>, props?: C) {
344
358
  // Setup
345
- const n: INotificaseBase = {
359
+ const n: INotificaseBase<C> = {
360
+ inputProps: props,
346
361
  type: NotificationType.Error,
347
- content: error
362
+ content: error,
363
+ onReturn: callback
348
364
  };
349
365
 
350
- // Callback
351
- n.onReturn = callback;
352
-
353
366
  // Add to the collection
354
367
  this.addRaw(n);
355
368
  }
@@ -359,22 +372,23 @@ export abstract class NotificationContainer<UI> implements INotifier<UI> {
359
372
  * @param message Message
360
373
  * @param title Title
361
374
  * @param callback Callback
375
+ * @param props Props
362
376
  */
363
377
  confirm(
364
378
  message: string,
365
379
  title?: string,
366
- callback?: NotificationReturn<boolean>
380
+ callback?: NotificationReturn<boolean>,
381
+ props?: C
367
382
  ) {
368
383
  // Setup
369
- const n: INotificaseBase = {
384
+ const n: INotificaseBase<C> = {
370
385
  type: NotificationType.Confirm,
371
386
  content: message,
372
- title
387
+ title,
388
+ onReturn: callback,
389
+ inputProps: props
373
390
  };
374
391
 
375
- // Callback
376
- n.onReturn = callback;
377
-
378
392
  // Add to the collection
379
393
  this.addRaw(n);
380
394
  }
@@ -392,28 +406,29 @@ export abstract class NotificationContainer<UI> implements INotifier<UI> {
392
406
  * @param message Message
393
407
  * @param title Title
394
408
  * @param parameters Parameters
409
+ * @param props Props
395
410
  */
396
411
  message(
397
412
  type: NotificationMessageType,
398
413
  message: string,
399
414
  title?: string,
400
- parameters?: NotificationParameters
415
+ parameters?: NotificationParameters,
416
+ props?: C
401
417
  ) {
402
418
  // Destruct
403
419
  const { align, timespan, callback, modal } = parameters ?? {};
404
420
 
405
421
  // Setup
406
- const n: INotificaseBase = {
422
+ const n: INotificaseBase<C> = {
407
423
  type,
408
424
  content: message,
409
425
  title,
410
426
  align,
411
- timespan
427
+ timespan,
428
+ onReturn: callback,
429
+ inputProps: props
412
430
  };
413
431
 
414
- // Additional parameters
415
- n.onReturn = callback;
416
-
417
432
  // Add to the collection
418
433
  return this.addRaw(n, modal);
419
434
  }
@@ -425,25 +440,21 @@ export abstract class NotificationContainer<UI> implements INotifier<UI> {
425
440
  * @param title Title
426
441
  * @param props More properties
427
442
  */
428
- prompt(
443
+ prompt<T>(
429
444
  message: string,
430
- callback: NotificationReturn<string>,
445
+ callback: NotificationReturn<T>,
431
446
  title?: string,
432
- props?: any
447
+ props?: C
433
448
  ) {
434
449
  // Setup
435
- const n: INotificaseBase = {
450
+ const n: INotificaseBase<C> = {
436
451
  type: NotificationType.Prompt,
437
452
  content: message,
438
- title
453
+ title,
454
+ inputProps: props,
455
+ onReturn: callback
439
456
  };
440
457
 
441
- // Additional parameters
442
- n.inputProps = props;
443
-
444
- // Callback
445
- n.onReturn = callback;
446
-
447
458
  // Add to the collection
448
459
  this.addRaw(n);
449
460
  }
@@ -454,7 +465,7 @@ export abstract class NotificationContainer<UI> implements INotifier<UI> {
454
465
  */
455
466
  showLoading(title?: string) {
456
467
  // Setup
457
- const n: INotificaseBase = {
468
+ const n: INotificaseBase<C> = {
458
469
  type: NotificationType.Loading,
459
470
  content: title ?? ''
460
471
  };
@@ -470,22 +481,30 @@ export abstract class NotificationContainer<UI> implements INotifier<UI> {
470
481
  * @param title Title
471
482
  * @param callback Callback
472
483
  * @param timespan Timespan to close
484
+ * @param props Props
473
485
  */
474
486
  succeed(
475
487
  message: string,
476
488
  title?: string,
477
489
  callback?: NotificationReturn<void>,
478
- timespan?: number
490
+ timespan?: number,
491
+ props?: C
479
492
  ) {
480
493
  // Default to zero for constant
481
494
  timespan ??= 0;
482
495
 
483
496
  // Create as message
484
- this.message(NotificationMessageType.Success, message, title, {
485
- align: NotificationAlign.Center,
486
- modal: true,
487
- timespan,
488
- callback
489
- });
497
+ this.message(
498
+ NotificationMessageType.Success,
499
+ message,
500
+ title,
501
+ {
502
+ align: NotificationAlign.Center,
503
+ modal: true,
504
+ timespan,
505
+ callback
506
+ },
507
+ props
508
+ );
490
509
  }
491
510
  }