@jupyterlab/apputils 3.6.0-alpha.1 → 3.6.0-alpha.2
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/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/notification.d.ts +288 -0
- package/lib/notification.js +279 -0
- package/lib/notification.js.map +1 -0
- package/package.json +9 -9
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAC3D;;;GAGG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAC3D;;;GAGG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { ReadonlyJSONValue } from '@lumino/coreutils';
|
|
2
|
+
import { IDisposable } from '@lumino/disposable';
|
|
3
|
+
import { ISignal } from '@lumino/signaling';
|
|
4
|
+
/**
|
|
5
|
+
* Notification manager
|
|
6
|
+
*/
|
|
7
|
+
export declare class NotificationManager implements IDisposable {
|
|
8
|
+
constructor();
|
|
9
|
+
/**
|
|
10
|
+
* Signal emitted whenever a notification changes.
|
|
11
|
+
*/
|
|
12
|
+
get changed(): ISignal<NotificationManager, Notification.IChange>;
|
|
13
|
+
/**
|
|
14
|
+
* Total number of notifications.
|
|
15
|
+
*/
|
|
16
|
+
get count(): number;
|
|
17
|
+
/**
|
|
18
|
+
* Whether the manager is disposed or not.
|
|
19
|
+
*/
|
|
20
|
+
get isDisposed(): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The list of notifications.
|
|
23
|
+
*/
|
|
24
|
+
get notifications(): Notification.INotification[];
|
|
25
|
+
/**
|
|
26
|
+
* Dismiss one notification (specified by its id) or all if no id provided.
|
|
27
|
+
*
|
|
28
|
+
* @param id Notification id
|
|
29
|
+
*/
|
|
30
|
+
dismiss(id?: string): void;
|
|
31
|
+
/**
|
|
32
|
+
* Dispose the manager.
|
|
33
|
+
*/
|
|
34
|
+
dispose(): void;
|
|
35
|
+
/**
|
|
36
|
+
* Test whether a notification exists or not.
|
|
37
|
+
*
|
|
38
|
+
* @param id Notification id
|
|
39
|
+
* @returns Notification status
|
|
40
|
+
*/
|
|
41
|
+
has(id: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Add a new notification.
|
|
44
|
+
*
|
|
45
|
+
* This will trigger the `changed` signal with an `added` event.
|
|
46
|
+
*
|
|
47
|
+
* @param message Notification message
|
|
48
|
+
* @param type Notification type
|
|
49
|
+
* @param options Notification option
|
|
50
|
+
* @returns Notification unique id
|
|
51
|
+
*/
|
|
52
|
+
notify<T extends ReadonlyJSONValue = ReadonlyJSONValue>(message: string, type: Notification.TypeOptions, options: Notification.IOptions<T>): string;
|
|
53
|
+
/**
|
|
54
|
+
* Update an existing notification.
|
|
55
|
+
*
|
|
56
|
+
* If the notification does not exists this won't do anything.
|
|
57
|
+
*
|
|
58
|
+
* Once updated the notification will be moved at the begin
|
|
59
|
+
* of the notification stack.
|
|
60
|
+
*
|
|
61
|
+
* @param args Update options
|
|
62
|
+
* @returns Whether the update was successful or not.
|
|
63
|
+
*/
|
|
64
|
+
update<T extends ReadonlyJSONValue = ReadonlyJSONValue>(args: Notification.IUpdate<T>): boolean;
|
|
65
|
+
private _isDisposed;
|
|
66
|
+
private _changed;
|
|
67
|
+
private _queue;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Notification namespace
|
|
71
|
+
*/
|
|
72
|
+
export declare namespace Notification {
|
|
73
|
+
/**
|
|
74
|
+
* Interface describing an action linked to a notification.
|
|
75
|
+
*/
|
|
76
|
+
interface IAction {
|
|
77
|
+
/**
|
|
78
|
+
* The action label.
|
|
79
|
+
*
|
|
80
|
+
* This should be a short description.
|
|
81
|
+
*/
|
|
82
|
+
label: string;
|
|
83
|
+
/**
|
|
84
|
+
* Callback function to trigger
|
|
85
|
+
*/
|
|
86
|
+
callback: () => void;
|
|
87
|
+
/**
|
|
88
|
+
* The action caption.
|
|
89
|
+
*
|
|
90
|
+
* This can be a longer description of the action.
|
|
91
|
+
*/
|
|
92
|
+
caption?: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Notification interface
|
|
96
|
+
*/
|
|
97
|
+
interface INotification<T extends ReadonlyJSONValue = ReadonlyJSONValue> {
|
|
98
|
+
/**
|
|
99
|
+
* Notification unique identifier
|
|
100
|
+
*/
|
|
101
|
+
id: string;
|
|
102
|
+
/**
|
|
103
|
+
* Notification message
|
|
104
|
+
*/
|
|
105
|
+
message: string;
|
|
106
|
+
/**
|
|
107
|
+
* Notification creation date
|
|
108
|
+
*/
|
|
109
|
+
createdAt: number;
|
|
110
|
+
/**
|
|
111
|
+
* Notification modification date
|
|
112
|
+
*/
|
|
113
|
+
modifiedAt: number;
|
|
114
|
+
/**
|
|
115
|
+
* Notification type
|
|
116
|
+
*/
|
|
117
|
+
type: TypeOptions;
|
|
118
|
+
/**
|
|
119
|
+
* Notification options
|
|
120
|
+
*/
|
|
121
|
+
options: IOptions<T>;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Notification change interface
|
|
125
|
+
*/
|
|
126
|
+
interface IChange {
|
|
127
|
+
/**
|
|
128
|
+
* Change type
|
|
129
|
+
*/
|
|
130
|
+
type: 'added' | 'removed' | 'updated';
|
|
131
|
+
/**
|
|
132
|
+
* Notification that changed
|
|
133
|
+
*/
|
|
134
|
+
notification: INotification;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Notification options
|
|
138
|
+
*/
|
|
139
|
+
interface IOptions<T extends ReadonlyJSONValue> {
|
|
140
|
+
/**
|
|
141
|
+
* Autoclosing behavior - false (not closing automatically)
|
|
142
|
+
* or number (time in milliseconds before hiding the notification)
|
|
143
|
+
*
|
|
144
|
+
* Set to zero if you want the notification to be retained in the notification
|
|
145
|
+
* center but not displayed as toast. This is the default behavior.
|
|
146
|
+
*/
|
|
147
|
+
autoClose?: number | false;
|
|
148
|
+
/**
|
|
149
|
+
* List of associated actions
|
|
150
|
+
*/
|
|
151
|
+
actions?: Array<IAction>;
|
|
152
|
+
/**
|
|
153
|
+
* Data associated with a notification
|
|
154
|
+
*/
|
|
155
|
+
data?: T;
|
|
156
|
+
/**
|
|
157
|
+
* Task progression
|
|
158
|
+
*
|
|
159
|
+
* ### Notes
|
|
160
|
+
* This should be a number between 0 (not started) and 1 (completed).
|
|
161
|
+
*/
|
|
162
|
+
progress?: number;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Parameters for notification depending on a promise.
|
|
166
|
+
*/
|
|
167
|
+
interface IPromiseOptions<Pending extends ReadonlyJSONValue, Success extends ReadonlyJSONValue = Pending, Error extends ReadonlyJSONValue = Pending> {
|
|
168
|
+
/**
|
|
169
|
+
* Promise pending message and options
|
|
170
|
+
*/
|
|
171
|
+
pending: {
|
|
172
|
+
message: string;
|
|
173
|
+
options?: IOptions<Pending>;
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* Message when promise resolves and options
|
|
177
|
+
*
|
|
178
|
+
* The message factory receives as first argument the result
|
|
179
|
+
* of the promise and as second the success `options.data`.
|
|
180
|
+
*/
|
|
181
|
+
success: {
|
|
182
|
+
message: (result: unknown, data?: Success) => string;
|
|
183
|
+
options?: IOptions<Success>;
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* Message when promise rejects and options
|
|
187
|
+
*
|
|
188
|
+
* The message factory receives as first argument the error
|
|
189
|
+
* of the promise and as second the error `options.data`.
|
|
190
|
+
*/
|
|
191
|
+
error: {
|
|
192
|
+
message: (reason: unknown, data?: Error) => string;
|
|
193
|
+
options?: IOptions<Error>;
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Type of notifications
|
|
198
|
+
*/
|
|
199
|
+
type TypeOptions = 'info' | 'in-progress' | 'success' | 'warning' | 'error' | 'default';
|
|
200
|
+
/**
|
|
201
|
+
* Options for updating a notification
|
|
202
|
+
*/
|
|
203
|
+
interface IUpdate<T extends ReadonlyJSONValue> extends IOptions<T> {
|
|
204
|
+
/**
|
|
205
|
+
* Notification unique id
|
|
206
|
+
*/
|
|
207
|
+
id: string;
|
|
208
|
+
/**
|
|
209
|
+
* New notification message
|
|
210
|
+
*/
|
|
211
|
+
message?: string;
|
|
212
|
+
/**
|
|
213
|
+
* New notification type
|
|
214
|
+
*/
|
|
215
|
+
type?: TypeOptions;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* The global notification manager.
|
|
219
|
+
*/
|
|
220
|
+
const manager: NotificationManager;
|
|
221
|
+
/**
|
|
222
|
+
* Dismiss one notification (specified by its id) or all if no id provided
|
|
223
|
+
*
|
|
224
|
+
* @param id notification id
|
|
225
|
+
*/
|
|
226
|
+
function dismiss(id?: string): void;
|
|
227
|
+
/**
|
|
228
|
+
* Helper function to emit a notification.
|
|
229
|
+
*
|
|
230
|
+
* @param message Notification message
|
|
231
|
+
* @param type Notification type
|
|
232
|
+
* @param options Options for the error notification
|
|
233
|
+
* @returns Notification unique id
|
|
234
|
+
*/
|
|
235
|
+
function emit<T extends ReadonlyJSONValue = ReadonlyJSONValue>(message: string, type?: TypeOptions, options?: IOptions<T>): string;
|
|
236
|
+
/**
|
|
237
|
+
* Helper function to emit an error notification.
|
|
238
|
+
*
|
|
239
|
+
* @param message Notification message
|
|
240
|
+
* @param options Options for the error notification
|
|
241
|
+
* @returns Notification unique id
|
|
242
|
+
*/
|
|
243
|
+
function error<T extends ReadonlyJSONValue = ReadonlyJSONValue>(message: string, options?: IOptions<T>): string;
|
|
244
|
+
/**
|
|
245
|
+
* Helper function to emit an info notification.
|
|
246
|
+
*
|
|
247
|
+
* @param message Notification message
|
|
248
|
+
* @param options Options for the info notification
|
|
249
|
+
* @returns Notification unique id
|
|
250
|
+
*/
|
|
251
|
+
function info<T extends ReadonlyJSONValue = ReadonlyJSONValue>(message: string, options?: IOptions<T>): string;
|
|
252
|
+
/**
|
|
253
|
+
* Helper function to show an in-progress notification.
|
|
254
|
+
*
|
|
255
|
+
* @param promise Promise to wait for
|
|
256
|
+
* @param options Options for the in-progress notification
|
|
257
|
+
* @returns Notification unique id
|
|
258
|
+
*/
|
|
259
|
+
function promise<Pending extends ReadonlyJSONValue = ReadonlyJSONValue, Success extends ReadonlyJSONValue = Pending, Error extends ReadonlyJSONValue = Pending>(promise: Promise<Success>, options: IPromiseOptions<Pending, Success, Error>): string;
|
|
260
|
+
/**
|
|
261
|
+
* Helper function to emit a success notification.
|
|
262
|
+
*
|
|
263
|
+
* @param message Notification message
|
|
264
|
+
* @param options Options for the success notification
|
|
265
|
+
* @returns Notification unique id
|
|
266
|
+
*/
|
|
267
|
+
function success<T extends ReadonlyJSONValue = ReadonlyJSONValue>(message: string, options?: IOptions<T>): string;
|
|
268
|
+
/**
|
|
269
|
+
* Helper function to update a notification.
|
|
270
|
+
*
|
|
271
|
+
* If the notification does not exists, nothing will happen.
|
|
272
|
+
*
|
|
273
|
+
* Once updated the notification will be moved at the begin
|
|
274
|
+
* of the notification stack.
|
|
275
|
+
*
|
|
276
|
+
* @param args Update options
|
|
277
|
+
* @returns Whether the update was successful or not.
|
|
278
|
+
*/
|
|
279
|
+
function update<T extends ReadonlyJSONValue = ReadonlyJSONValue>(args: IUpdate<T>): boolean;
|
|
280
|
+
/**
|
|
281
|
+
* Helper function to emit a warning notification.
|
|
282
|
+
*
|
|
283
|
+
* @param message Notification message
|
|
284
|
+
* @param options Options for the warning notification
|
|
285
|
+
* @returns Notification unique id
|
|
286
|
+
*/
|
|
287
|
+
function warning<T extends ReadonlyJSONValue = ReadonlyJSONValue>(message: string, options?: IOptions<T>): string;
|
|
288
|
+
}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Jupyter Development Team.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
6
|
+
var t = {};
|
|
7
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
8
|
+
t[p] = s[p];
|
|
9
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
10
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
11
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
12
|
+
t[p[i]] = s[p[i]];
|
|
13
|
+
}
|
|
14
|
+
return t;
|
|
15
|
+
};
|
|
16
|
+
import { UUID } from '@lumino/coreutils';
|
|
17
|
+
import { Signal } from '@lumino/signaling';
|
|
18
|
+
/**
|
|
19
|
+
* Notification manager
|
|
20
|
+
*/
|
|
21
|
+
export class NotificationManager {
|
|
22
|
+
constructor() {
|
|
23
|
+
this._isDisposed = false;
|
|
24
|
+
this._queue = [];
|
|
25
|
+
this._changed = new Signal(this);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Signal emitted whenever a notification changes.
|
|
29
|
+
*/
|
|
30
|
+
get changed() {
|
|
31
|
+
return this._changed;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Total number of notifications.
|
|
35
|
+
*/
|
|
36
|
+
get count() {
|
|
37
|
+
return this._queue.length;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Whether the manager is disposed or not.
|
|
41
|
+
*/
|
|
42
|
+
get isDisposed() {
|
|
43
|
+
return this._isDisposed;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The list of notifications.
|
|
47
|
+
*/
|
|
48
|
+
get notifications() {
|
|
49
|
+
return this._queue.slice();
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Dismiss one notification (specified by its id) or all if no id provided.
|
|
53
|
+
*
|
|
54
|
+
* @param id Notification id
|
|
55
|
+
*/
|
|
56
|
+
dismiss(id) {
|
|
57
|
+
if (typeof id === 'undefined') {
|
|
58
|
+
const q = this._queue.slice();
|
|
59
|
+
this._queue.length = 0;
|
|
60
|
+
for (const notification of q) {
|
|
61
|
+
this._changed.emit({
|
|
62
|
+
type: 'removed',
|
|
63
|
+
notification
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const notificationIndex = this._queue.findIndex(n => n.id === id);
|
|
69
|
+
if (notificationIndex > -1) {
|
|
70
|
+
const notification = this._queue.splice(notificationIndex, 1)[0];
|
|
71
|
+
this._changed.emit({
|
|
72
|
+
type: 'removed',
|
|
73
|
+
notification
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Dispose the manager.
|
|
80
|
+
*/
|
|
81
|
+
dispose() {
|
|
82
|
+
if (this._isDisposed) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
this._isDisposed = true;
|
|
86
|
+
Signal.clearData(this);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Test whether a notification exists or not.
|
|
90
|
+
*
|
|
91
|
+
* @param id Notification id
|
|
92
|
+
* @returns Notification status
|
|
93
|
+
*/
|
|
94
|
+
has(id) {
|
|
95
|
+
return this._queue.findIndex(n => n.id === id) > -1;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Add a new notification.
|
|
99
|
+
*
|
|
100
|
+
* This will trigger the `changed` signal with an `added` event.
|
|
101
|
+
*
|
|
102
|
+
* @param message Notification message
|
|
103
|
+
* @param type Notification type
|
|
104
|
+
* @param options Notification option
|
|
105
|
+
* @returns Notification unique id
|
|
106
|
+
*/
|
|
107
|
+
notify(message, type, options) {
|
|
108
|
+
const now = Date.now();
|
|
109
|
+
const { progress } = options, othersOptions = __rest(options, ["progress"]);
|
|
110
|
+
const notification = Object.freeze({
|
|
111
|
+
id: UUID.uuid4(),
|
|
112
|
+
createdAt: now,
|
|
113
|
+
modifiedAt: now,
|
|
114
|
+
message,
|
|
115
|
+
type,
|
|
116
|
+
options: Object.assign({
|
|
117
|
+
// By default notification will be silent
|
|
118
|
+
autoClose: 0, progress: typeof progress === 'number'
|
|
119
|
+
? Math.min(Math.max(0, progress), 1)
|
|
120
|
+
: progress }, othersOptions)
|
|
121
|
+
});
|
|
122
|
+
this._queue.unshift(notification);
|
|
123
|
+
this._changed.emit({
|
|
124
|
+
type: 'added',
|
|
125
|
+
notification
|
|
126
|
+
});
|
|
127
|
+
return notification.id;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Update an existing notification.
|
|
131
|
+
*
|
|
132
|
+
* If the notification does not exists this won't do anything.
|
|
133
|
+
*
|
|
134
|
+
* Once updated the notification will be moved at the begin
|
|
135
|
+
* of the notification stack.
|
|
136
|
+
*
|
|
137
|
+
* @param args Update options
|
|
138
|
+
* @returns Whether the update was successful or not.
|
|
139
|
+
*/
|
|
140
|
+
update(args) {
|
|
141
|
+
const { id, message, actions, autoClose, data, progress, type } = args;
|
|
142
|
+
const newProgress = typeof progress === 'number'
|
|
143
|
+
? Math.min(Math.max(0, progress), 1)
|
|
144
|
+
: progress;
|
|
145
|
+
const notificationIndex = this._queue.findIndex(n => n.id === id);
|
|
146
|
+
if (notificationIndex > -1) {
|
|
147
|
+
const oldNotification = this._queue[notificationIndex];
|
|
148
|
+
// We need to create a new object as notification are frozen; i.e. cannot be edited
|
|
149
|
+
const notification = Object.freeze(Object.assign(Object.assign({}, oldNotification), { message: message !== null && message !== void 0 ? message : oldNotification.message, type: type !== null && type !== void 0 ? type : oldNotification.type, options: {
|
|
150
|
+
actions: actions !== null && actions !== void 0 ? actions : oldNotification.options.actions,
|
|
151
|
+
autoClose: autoClose !== null && autoClose !== void 0 ? autoClose : oldNotification.options.autoClose,
|
|
152
|
+
data: data !== null && data !== void 0 ? data : oldNotification.options.data,
|
|
153
|
+
progress: newProgress !== null && newProgress !== void 0 ? newProgress : oldNotification.options.progress
|
|
154
|
+
}, modifiedAt: Date.now() }));
|
|
155
|
+
this._queue.splice(notificationIndex, 1);
|
|
156
|
+
this._queue.unshift(notification);
|
|
157
|
+
this._changed.emit({
|
|
158
|
+
type: 'updated',
|
|
159
|
+
notification
|
|
160
|
+
});
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Notification namespace
|
|
168
|
+
*/
|
|
169
|
+
export var Notification;
|
|
170
|
+
(function (Notification) {
|
|
171
|
+
/**
|
|
172
|
+
* The global notification manager.
|
|
173
|
+
*/
|
|
174
|
+
Notification.manager = new NotificationManager();
|
|
175
|
+
/**
|
|
176
|
+
* Dismiss one notification (specified by its id) or all if no id provided
|
|
177
|
+
*
|
|
178
|
+
* @param id notification id
|
|
179
|
+
*/
|
|
180
|
+
function dismiss(id) {
|
|
181
|
+
Notification.manager.dismiss(id);
|
|
182
|
+
}
|
|
183
|
+
Notification.dismiss = dismiss;
|
|
184
|
+
/**
|
|
185
|
+
* Helper function to emit a notification.
|
|
186
|
+
*
|
|
187
|
+
* @param message Notification message
|
|
188
|
+
* @param type Notification type
|
|
189
|
+
* @param options Options for the error notification
|
|
190
|
+
* @returns Notification unique id
|
|
191
|
+
*/
|
|
192
|
+
function emit(message, type = 'default', options = {}) {
|
|
193
|
+
return Notification.manager.notify(message, type, options);
|
|
194
|
+
}
|
|
195
|
+
Notification.emit = emit;
|
|
196
|
+
/**
|
|
197
|
+
* Helper function to emit an error notification.
|
|
198
|
+
*
|
|
199
|
+
* @param message Notification message
|
|
200
|
+
* @param options Options for the error notification
|
|
201
|
+
* @returns Notification unique id
|
|
202
|
+
*/
|
|
203
|
+
function error(message, options = {}) {
|
|
204
|
+
return Notification.manager.notify(message, 'error', options);
|
|
205
|
+
}
|
|
206
|
+
Notification.error = error;
|
|
207
|
+
/**
|
|
208
|
+
* Helper function to emit an info notification.
|
|
209
|
+
*
|
|
210
|
+
* @param message Notification message
|
|
211
|
+
* @param options Options for the info notification
|
|
212
|
+
* @returns Notification unique id
|
|
213
|
+
*/
|
|
214
|
+
function info(message, options = {}) {
|
|
215
|
+
return Notification.manager.notify(message, 'info', options);
|
|
216
|
+
}
|
|
217
|
+
Notification.info = info;
|
|
218
|
+
/**
|
|
219
|
+
* Helper function to show an in-progress notification.
|
|
220
|
+
*
|
|
221
|
+
* @param promise Promise to wait for
|
|
222
|
+
* @param options Options for the in-progress notification
|
|
223
|
+
* @returns Notification unique id
|
|
224
|
+
*/
|
|
225
|
+
function promise(promise, options) {
|
|
226
|
+
var _a;
|
|
227
|
+
const { pending, error, success } = options;
|
|
228
|
+
const id = Notification.manager.notify(pending.message, 'in-progress', (_a = pending.options) !== null && _a !== void 0 ? _a : {});
|
|
229
|
+
promise
|
|
230
|
+
.then(result => {
|
|
231
|
+
var _a, _b, _c;
|
|
232
|
+
Notification.manager.update(Object.assign(Object.assign({ id, message: success.message(result, (_a = success.options) === null || _a === void 0 ? void 0 : _a.data), type: 'success' }, success.options), { data: (_c = (_b = success.options) === null || _b === void 0 ? void 0 : _b.data) !== null && _c !== void 0 ? _c : result }));
|
|
233
|
+
})
|
|
234
|
+
.catch(reason => {
|
|
235
|
+
var _a, _b, _c;
|
|
236
|
+
Notification.manager.update(Object.assign(Object.assign({ id, message: error.message(reason, (_a = error.options) === null || _a === void 0 ? void 0 : _a.data), type: 'error' }, error.options), { data: (_c = (_b = error.options) === null || _b === void 0 ? void 0 : _b.data) !== null && _c !== void 0 ? _c : reason }));
|
|
237
|
+
});
|
|
238
|
+
return id;
|
|
239
|
+
}
|
|
240
|
+
Notification.promise = promise;
|
|
241
|
+
/**
|
|
242
|
+
* Helper function to emit a success notification.
|
|
243
|
+
*
|
|
244
|
+
* @param message Notification message
|
|
245
|
+
* @param options Options for the success notification
|
|
246
|
+
* @returns Notification unique id
|
|
247
|
+
*/
|
|
248
|
+
function success(message, options = {}) {
|
|
249
|
+
return Notification.manager.notify(message, 'success', options);
|
|
250
|
+
}
|
|
251
|
+
Notification.success = success;
|
|
252
|
+
/**
|
|
253
|
+
* Helper function to update a notification.
|
|
254
|
+
*
|
|
255
|
+
* If the notification does not exists, nothing will happen.
|
|
256
|
+
*
|
|
257
|
+
* Once updated the notification will be moved at the begin
|
|
258
|
+
* of the notification stack.
|
|
259
|
+
*
|
|
260
|
+
* @param args Update options
|
|
261
|
+
* @returns Whether the update was successful or not.
|
|
262
|
+
*/
|
|
263
|
+
function update(args) {
|
|
264
|
+
return Notification.manager.update(args);
|
|
265
|
+
}
|
|
266
|
+
Notification.update = update;
|
|
267
|
+
/**
|
|
268
|
+
* Helper function to emit a warning notification.
|
|
269
|
+
*
|
|
270
|
+
* @param message Notification message
|
|
271
|
+
* @param options Options for the warning notification
|
|
272
|
+
* @returns Notification unique id
|
|
273
|
+
*/
|
|
274
|
+
function warning(message, options = {}) {
|
|
275
|
+
return Notification.manager.notify(message, 'warning', options);
|
|
276
|
+
}
|
|
277
|
+
Notification.warning = warning;
|
|
278
|
+
})(Notification || (Notification = {}));
|
|
279
|
+
//# sourceMappingURL=notification.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification.js","sourceRoot":"","sources":["../src/notification.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;;;AAEH,OAAO,EAAqB,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,EAAW,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;GAEG;AACH,MAAM,OAAO,mBAAmB;IAC9B;QACE,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;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AE;QAEzB,OAAO,aAAA,OAAO,CAAC,MAAM,CAAI,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IACxD,CAAC;IALe,oBAAO,UAKtB,CAAA;AACH,CAAC,EAvTgB,YAAY,KAAZ,YAAY,QAuT5B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyterlab/apputils",
|
|
3
|
-
"version": "3.6.0-alpha.
|
|
3
|
+
"version": "3.6.0-alpha.2",
|
|
4
4
|
"description": "JupyterLab - Application Utilities",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jupyter",
|
|
@@ -44,13 +44,13 @@
|
|
|
44
44
|
"watch": "tsc -b --watch"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@jupyterlab/coreutils": "^5.6.0-alpha.
|
|
48
|
-
"@jupyterlab/observables": "^4.6.0-alpha.
|
|
49
|
-
"@jupyterlab/services": "^6.6.0-alpha.
|
|
50
|
-
"@jupyterlab/settingregistry": "^3.6.0-alpha.
|
|
51
|
-
"@jupyterlab/statedb": "^3.6.0-alpha.
|
|
52
|
-
"@jupyterlab/translation": "^3.6.0-alpha.
|
|
53
|
-
"@jupyterlab/ui-components": "^3.6.0-alpha.
|
|
47
|
+
"@jupyterlab/coreutils": "^5.6.0-alpha.2",
|
|
48
|
+
"@jupyterlab/observables": "^4.6.0-alpha.2",
|
|
49
|
+
"@jupyterlab/services": "^6.6.0-alpha.2",
|
|
50
|
+
"@jupyterlab/settingregistry": "^3.6.0-alpha.2",
|
|
51
|
+
"@jupyterlab/statedb": "^3.6.0-alpha.2",
|
|
52
|
+
"@jupyterlab/translation": "^3.6.0-alpha.2",
|
|
53
|
+
"@jupyterlab/ui-components": "^3.6.0-alpha.2",
|
|
54
54
|
"@lumino/algorithm": "^1.9.0",
|
|
55
55
|
"@lumino/commands": "^1.19.0",
|
|
56
56
|
"@lumino/coreutils": "^1.11.0",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"url": "^0.11.0"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"@jupyterlab/testutils": "^3.6.0-alpha.
|
|
72
|
+
"@jupyterlab/testutils": "^3.6.0-alpha.2",
|
|
73
73
|
"@types/jest": "^26.0.10",
|
|
74
74
|
"@types/react-dom": "^17.0.0",
|
|
75
75
|
"@types/sanitize-html": "^2.3.1",
|