@jupyterlab/apputils 1.0.0-alpha.8 → 1.0.0

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.
Files changed (59) hide show
  1. package/lib/clientsession.js +4 -3
  2. package/lib/clientsession.js.map +1 -0
  3. package/lib/clipboard.js +1 -0
  4. package/lib/clipboard.js.map +1 -0
  5. package/lib/collapse.js +1 -0
  6. package/lib/collapse.js.map +1 -0
  7. package/lib/commandlinker.js +1 -0
  8. package/lib/commandlinker.js.map +1 -0
  9. package/lib/commandpalette.js +1 -0
  10. package/lib/commandpalette.js.map +1 -0
  11. package/lib/dialog.d.ts +4 -15
  12. package/lib/dialog.js +31 -75
  13. package/lib/dialog.js.map +1 -0
  14. package/lib/domutils.js +1 -0
  15. package/lib/domutils.js.map +1 -0
  16. package/lib/hoverbox.js +1 -0
  17. package/lib/hoverbox.js.map +1 -0
  18. package/lib/iframe.js +1 -0
  19. package/lib/iframe.js.map +1 -0
  20. package/lib/index.d.ts +1 -2
  21. package/lib/index.js +2 -2
  22. package/lib/index.js.map +1 -0
  23. package/lib/inputdialog.d.ts +80 -27
  24. package/lib/inputdialog.js +96 -39
  25. package/lib/inputdialog.js.map +1 -0
  26. package/lib/mainareawidget.d.ts +4 -0
  27. package/lib/mainareawidget.js +8 -0
  28. package/lib/mainareawidget.js.map +1 -0
  29. package/lib/printing.js +1 -0
  30. package/lib/printing.js.map +1 -0
  31. package/lib/sanitizer.js +1 -0
  32. package/lib/sanitizer.js.map +1 -0
  33. package/lib/spinner.js +1 -0
  34. package/lib/spinner.js.map +1 -0
  35. package/lib/splash.js +1 -0
  36. package/lib/splash.js.map +1 -0
  37. package/lib/styling.js +1 -0
  38. package/lib/styling.js.map +1 -0
  39. package/lib/thememanager.js +1 -0
  40. package/lib/thememanager.js.map +1 -0
  41. package/lib/tokens.js +1 -0
  42. package/lib/tokens.js.map +1 -0
  43. package/lib/toolbar.js +6 -2
  44. package/lib/toolbar.js.map +1 -0
  45. package/lib/vdom.js +1 -0
  46. package/lib/vdom.js.map +1 -0
  47. package/lib/widgettracker.d.ts +249 -0
  48. package/lib/widgettracker.js +218 -0
  49. package/lib/widgettracker.js.map +1 -0
  50. package/lib/windowresolver.js +1 -0
  51. package/lib/windowresolver.js.map +1 -0
  52. package/package.json +20 -16
  53. package/style/base.css +16 -0
  54. package/style/commandpalette.css +11 -3
  55. package/style/dialog.css +14 -0
  56. package/style/index.css +6 -12
  57. package/style/styling.css +0 -1
  58. package/lib/instancetracker.d.ts +0 -302
  59. package/lib/instancetracker.js +0 -340
@@ -1,302 +0,0 @@
1
- import { IStateDB } from '@jupyterlab/coreutils';
2
- import { CommandRegistry } from '@phosphor/commands';
3
- import { ReadonlyJSONObject } from '@phosphor/coreutils';
4
- import { IDisposable } from '@phosphor/disposable';
5
- import { ISignal } from '@phosphor/signaling';
6
- import { Widget } from '@phosphor/widgets';
7
- /**
8
- * An object that tracks widget instances.
9
- */
10
- export interface IInstanceTracker<T extends Widget> extends IDisposable {
11
- /**
12
- * A signal emitted when the current widget changes.
13
- *
14
- * #### Notes
15
- * If the last widget being tracked is disposed, `null` will be emitted.
16
- */
17
- readonly currentChanged: ISignal<this, T | null>;
18
- /**
19
- * A signal emitted when a widget is added.
20
- *
21
- * #### Notes
22
- * This signal will only fire when a widget is added to the tracker. It will
23
- * not fire if a widget is injected into the tracker.
24
- */
25
- readonly widgetAdded: ISignal<this, T>;
26
- /**
27
- * The current widget is the most recently focused or added widget.
28
- *
29
- * #### Notes
30
- * It is the most recently focused widget, or the most recently added
31
- * widget if no widget has taken focus.
32
- */
33
- readonly currentWidget: T | null;
34
- /**
35
- * The number of widgets held by the tracker.
36
- */
37
- readonly size: number;
38
- /**
39
- * A promise that is resolved when the instance tracker has been
40
- * restored from a serialized state.
41
- *
42
- * #### Notes
43
- * Most client code will not need to use this, since they can wait
44
- * for the whole application to restore. However, if an extension
45
- * wants to perform actions during the application restoration, but
46
- * after the restoration of another instance tracker, they can use
47
- * this promise.
48
- */
49
- readonly restored: Promise<void>;
50
- /**
51
- * Find the first widget in the tracker that satisfies a filter function.
52
- *
53
- * @param - fn The filter function to call on each widget.
54
- *
55
- * #### Notes
56
- * If no widget is found, the value returned is `undefined`.
57
- */
58
- find(fn: (widget: T) => boolean): T | undefined;
59
- /**
60
- * Iterate through each widget in the tracker.
61
- *
62
- * @param fn - The function to call on each widget.
63
- */
64
- forEach(fn: (widget: T) => void): void;
65
- /**
66
- * Filter the widgets in the tracker based on a predicate.
67
- *
68
- * @param fn - The function by which to filter.
69
- */
70
- filter(fn: (widget: T) => boolean): T[];
71
- /**
72
- * Check if this tracker has the specified widget.
73
- *
74
- * @param widget - The widget whose existence is being checked.
75
- */
76
- has(widget: Widget): boolean;
77
- /**
78
- * Inject a foreign widget into the instance tracker.
79
- *
80
- * @param widget - The widget to inject into the tracker.
81
- *
82
- * #### Notes
83
- * Any widgets injected into an instance tracker will not have their state
84
- * saved by the tracker. The primary use case for widget injection is for a
85
- * plugin that offers a sub-class of an extant plugin to have its instances
86
- * share the same commands as the parent plugin (since most relevant commands
87
- * will use the `currentWidget` of the parent plugin's instance tracker). In
88
- * this situation, the sub-class plugin may well have its own instance tracker
89
- * for layout and state restoration in addition to injecting its widgets into
90
- * the parent plugin's instance tracker.
91
- */
92
- inject(widget: T): void;
93
- }
94
- /**
95
- * A class that keeps track of widget instances on an Application shell.
96
- *
97
- * #### Notes
98
- * The API surface area of this concrete implementation is substantially larger
99
- * than the instance tracker interface it implements. The interface is intended
100
- * for export by JupyterLab plugins that create widgets and have clients who may
101
- * wish to keep track of newly created widgets. This class, however, can be used
102
- * internally by plugins to restore state as well.
103
- */
104
- export declare class InstanceTracker<T extends Widget> implements IInstanceTracker<T>, IDisposable {
105
- /**
106
- * Create a new instance tracker.
107
- *
108
- * @param options - The instantiation options for an instance tracker.
109
- */
110
- constructor(options: InstanceTracker.IOptions);
111
- /**
112
- * A signal emitted when the current widget changes.
113
- */
114
- readonly currentChanged: ISignal<this, T | null>;
115
- /**
116
- * A signal emitted when a widget is added.
117
- *
118
- * #### Notes
119
- * This signal will only fire when a widget is added to the tracker. It will
120
- * not fire if a widget is injected into the tracker.
121
- */
122
- readonly widgetAdded: ISignal<this, T>;
123
- /**
124
- * A signal emitted when a widget is updated.
125
- */
126
- readonly widgetUpdated: ISignal<this, T>;
127
- /**
128
- * A namespace for all tracked widgets, (e.g., `notebook`).
129
- */
130
- readonly namespace: string;
131
- /**
132
- * The current widget is the most recently focused or added widget.
133
- *
134
- * #### Notes
135
- * It is the most recently focused widget, or the most recently added
136
- * widget if no widget has taken focus.
137
- */
138
- readonly currentWidget: T | null;
139
- /**
140
- * A promise resolved when the instance tracker has been restored.
141
- */
142
- readonly restored: Promise<void>;
143
- /**
144
- * The number of widgets held by the tracker.
145
- */
146
- readonly size: number;
147
- /**
148
- * Add a new widget to the tracker.
149
- *
150
- * @param widget - The widget being added.
151
- *
152
- * #### Notes
153
- * When a widget is added its state is saved to the state database.
154
- * This function returns a promise that is resolved when that saving
155
- * is completed. However, the widget is added to the in-memory tracker
156
- * synchronously, and is available to use before the promise is resolved.
157
- */
158
- add(widget: T): Promise<void>;
159
- /**
160
- * Test whether the tracker is disposed.
161
- */
162
- readonly isDisposed: boolean;
163
- /**
164
- * Dispose of the resources held by the tracker.
165
- */
166
- dispose(): void;
167
- /**
168
- * Find the first widget in the tracker that satisfies a filter function.
169
- *
170
- * @param - fn The filter function to call on each widget.
171
- *
172
- * #### Notes
173
- * If no widget is found, the value returned is `undefined`.
174
- */
175
- find(fn: (widget: T) => boolean): T | undefined;
176
- /**
177
- * Iterate through each widget in the tracker.
178
- *
179
- * @param fn - The function to call on each widget.
180
- */
181
- forEach(fn: (widget: T) => void): void;
182
- /**
183
- * Filter the widgets in the tracker based on a predicate.
184
- *
185
- * @param fn - The function by which to filter.
186
- */
187
- filter(fn: (widget: T) => boolean): T[];
188
- /**
189
- * Inject a foreign widget into the instance tracker.
190
- *
191
- * @param widget - The widget to inject into the tracker.
192
- *
193
- * #### Notes
194
- * Any widgets injected into an instance tracker will not have their state
195
- * saved by the tracker. The primary use case for widget injection is for a
196
- * plugin that offers a sub-class of an extant plugin to have its instances
197
- * share the same commands as the parent plugin (since most relevant commands
198
- * will use the `currentWidget` of the parent plugin's instance tracker). In
199
- * this situation, the sub-class plugin may well have its own instance tracker
200
- * for layout and state restoration in addition to injecting its widgets into
201
- * the parent plugin's instance tracker.
202
- */
203
- inject(widget: T): void;
204
- /**
205
- * Check if this tracker has the specified widget.
206
- *
207
- * @param widget - The widget whose existence is being checked.
208
- */
209
- has(widget: Widget): boolean;
210
- /**
211
- * Restore the widgets in this tracker's namespace.
212
- *
213
- * @param options - The configuration options that describe restoration.
214
- *
215
- * @returns A promise that resolves when restoration has completed.
216
- *
217
- * #### Notes
218
- * This function should almost never be invoked by client code. Its primary
219
- * use case is to be invoked by a layout restorer plugin that handles
220
- * multiple instance trackers and, when ready, asks them each to restore their
221
- * respective widgets.
222
- */
223
- restore(options: InstanceTracker.IRestoreOptions<T>): Promise<any>;
224
- /**
225
- * Save the restore data for a given widget.
226
- *
227
- * @param widget - The widget being saved.
228
- */
229
- save(widget: T): Promise<void>;
230
- /**
231
- * Handle the current change event.
232
- *
233
- * #### Notes
234
- * The default implementation is a no-op.
235
- */
236
- protected onCurrentChanged(value: T | null): void;
237
- /**
238
- * Handle the current change signal from the internal focus tracker.
239
- */
240
- private _onCurrentChanged;
241
- /**
242
- * Clean up after disposed widgets.
243
- */
244
- private _onWidgetDisposed;
245
- private _hasRestored;
246
- private _restore;
247
- private _restored;
248
- private _tracker;
249
- private _currentChanged;
250
- private _widgetAdded;
251
- private _widgetUpdated;
252
- private _widgets;
253
- private _currentWidget;
254
- private _isDisposed;
255
- }
256
- /**
257
- * A namespace for `InstanceTracker` statics.
258
- */
259
- export declare namespace InstanceTracker {
260
- /**
261
- * The instantiation options for an instance tracker.
262
- */
263
- interface IOptions {
264
- /**
265
- * A namespace for all tracked widgets, (e.g., `notebook`).
266
- */
267
- namespace: string;
268
- }
269
- /**
270
- * The state restoration configuration options.
271
- */
272
- interface IRestoreOptions<T extends Widget> {
273
- /**
274
- * The command to execute when restoring instances.
275
- */
276
- command: string;
277
- /**
278
- * A function that returns the args needed to restore an instance.
279
- */
280
- args: (widget: T) => ReadonlyJSONObject;
281
- /**
282
- * A function that returns a unique persistent name for this instance.
283
- */
284
- name: (widget: T) => string;
285
- /**
286
- * The command registry which holds the restore command.
287
- */
288
- registry: CommandRegistry;
289
- /**
290
- * The state database instance.
291
- */
292
- state: IStateDB;
293
- /**
294
- * The point after which it is safe to restore state.
295
- *
296
- * #### Notes
297
- * By definition, this promise or promises will happen after the application
298
- * has `started`.
299
- */
300
- when?: Promise<any> | Array<Promise<any>>;
301
- }
302
- }
@@ -1,340 +0,0 @@
1
- // Copyright (c) Jupyter Development Team.
2
- // Distributed under the terms of the Modified BSD License.
3
- import { ArrayExt, each, find } from '@phosphor/algorithm';
4
- import { PromiseDelegate } from '@phosphor/coreutils';
5
- import { AttachedProperty } from '@phosphor/properties';
6
- import { Signal } from '@phosphor/signaling';
7
- import { FocusTracker } from '@phosphor/widgets';
8
- /**
9
- * A class that keeps track of widget instances on an Application shell.
10
- *
11
- * #### Notes
12
- * The API surface area of this concrete implementation is substantially larger
13
- * than the instance tracker interface it implements. The interface is intended
14
- * for export by JupyterLab plugins that create widgets and have clients who may
15
- * wish to keep track of newly created widgets. This class, however, can be used
16
- * internally by plugins to restore state as well.
17
- */
18
- export class InstanceTracker {
19
- /**
20
- * Create a new instance tracker.
21
- *
22
- * @param options - The instantiation options for an instance tracker.
23
- */
24
- constructor(options) {
25
- this._hasRestored = false;
26
- this._restore = null;
27
- this._restored = new PromiseDelegate();
28
- this._tracker = new FocusTracker();
29
- this._currentChanged = new Signal(this);
30
- this._widgetAdded = new Signal(this);
31
- this._widgetUpdated = new Signal(this);
32
- this._widgets = [];
33
- this._currentWidget = null;
34
- this._isDisposed = false;
35
- this.namespace = options.namespace;
36
- this._tracker.currentChanged.connect(this._onCurrentChanged, this);
37
- }
38
- /**
39
- * A signal emitted when the current widget changes.
40
- */
41
- get currentChanged() {
42
- return this._currentChanged;
43
- }
44
- /**
45
- * A signal emitted when a widget is added.
46
- *
47
- * #### Notes
48
- * This signal will only fire when a widget is added to the tracker. It will
49
- * not fire if a widget is injected into the tracker.
50
- */
51
- get widgetAdded() {
52
- return this._widgetAdded;
53
- }
54
- /**
55
- * A signal emitted when a widget is updated.
56
- */
57
- get widgetUpdated() {
58
- return this._widgetUpdated;
59
- }
60
- /**
61
- * The current widget is the most recently focused or added widget.
62
- *
63
- * #### Notes
64
- * It is the most recently focused widget, or the most recently added
65
- * widget if no widget has taken focus.
66
- */
67
- get currentWidget() {
68
- return this._currentWidget;
69
- }
70
- /**
71
- * A promise resolved when the instance tracker has been restored.
72
- */
73
- get restored() {
74
- return this._restored.promise;
75
- }
76
- /**
77
- * The number of widgets held by the tracker.
78
- */
79
- get size() {
80
- return this._tracker.widgets.length;
81
- }
82
- /**
83
- * Add a new widget to the tracker.
84
- *
85
- * @param widget - The widget being added.
86
- *
87
- * #### Notes
88
- * When a widget is added its state is saved to the state database.
89
- * This function returns a promise that is resolved when that saving
90
- * is completed. However, the widget is added to the in-memory tracker
91
- * synchronously, and is available to use before the promise is resolved.
92
- */
93
- add(widget) {
94
- if (widget.isDisposed) {
95
- const warning = `${widget.id} is disposed and cannot be tracked.`;
96
- console.warn(warning);
97
- return Promise.reject(warning);
98
- }
99
- if (this._tracker.has(widget)) {
100
- const warning = `${widget.id} already exists in the tracker.`;
101
- console.warn(warning);
102
- return Promise.reject(warning);
103
- }
104
- this._tracker.add(widget);
105
- this._widgets.push(widget);
106
- let injected = Private.injectedProperty.get(widget);
107
- let promise = Promise.resolve(void 0);
108
- if (injected) {
109
- return promise;
110
- }
111
- widget.disposed.connect(this._onWidgetDisposed, this);
112
- // Handle widget state restoration.
113
- if (this._restore) {
114
- let { state } = this._restore;
115
- let widgetName = this._restore.name(widget);
116
- if (widgetName) {
117
- let name = `${this.namespace}:${widgetName}`;
118
- let data = this._restore.args(widget);
119
- Private.nameProperty.set(widget, name);
120
- promise = state.save(name, { data });
121
- }
122
- }
123
- // If there is no focused widget, set this as the current widget.
124
- if (!this._tracker.currentWidget) {
125
- this._currentWidget = widget;
126
- this.onCurrentChanged(widget);
127
- this._currentChanged.emit(widget);
128
- }
129
- // Emit the widget added signal.
130
- this._widgetAdded.emit(widget);
131
- return promise;
132
- }
133
- /**
134
- * Test whether the tracker is disposed.
135
- */
136
- get isDisposed() {
137
- return this._isDisposed;
138
- }
139
- /**
140
- * Dispose of the resources held by the tracker.
141
- */
142
- dispose() {
143
- if (this.isDisposed) {
144
- return;
145
- }
146
- this._isDisposed = true;
147
- Signal.clearData(this);
148
- this._tracker.dispose();
149
- }
150
- /**
151
- * Find the first widget in the tracker that satisfies a filter function.
152
- *
153
- * @param - fn The filter function to call on each widget.
154
- *
155
- * #### Notes
156
- * If no widget is found, the value returned is `undefined`.
157
- */
158
- find(fn) {
159
- return find(this._tracker.widgets, fn);
160
- }
161
- /**
162
- * Iterate through each widget in the tracker.
163
- *
164
- * @param fn - The function to call on each widget.
165
- */
166
- forEach(fn) {
167
- each(this._tracker.widgets, widget => {
168
- fn(widget);
169
- });
170
- }
171
- /**
172
- * Filter the widgets in the tracker based on a predicate.
173
- *
174
- * @param fn - The function by which to filter.
175
- */
176
- filter(fn) {
177
- return this._tracker.widgets.filter(fn);
178
- }
179
- /**
180
- * Inject a foreign widget into the instance tracker.
181
- *
182
- * @param widget - The widget to inject into the tracker.
183
- *
184
- * #### Notes
185
- * Any widgets injected into an instance tracker will not have their state
186
- * saved by the tracker. The primary use case for widget injection is for a
187
- * plugin that offers a sub-class of an extant plugin to have its instances
188
- * share the same commands as the parent plugin (since most relevant commands
189
- * will use the `currentWidget` of the parent plugin's instance tracker). In
190
- * this situation, the sub-class plugin may well have its own instance tracker
191
- * for layout and state restoration in addition to injecting its widgets into
192
- * the parent plugin's instance tracker.
193
- */
194
- inject(widget) {
195
- Private.injectedProperty.set(widget, true);
196
- void this.add(widget);
197
- }
198
- /**
199
- * Check if this tracker has the specified widget.
200
- *
201
- * @param widget - The widget whose existence is being checked.
202
- */
203
- has(widget) {
204
- return this._tracker.has(widget);
205
- }
206
- /**
207
- * Restore the widgets in this tracker's namespace.
208
- *
209
- * @param options - The configuration options that describe restoration.
210
- *
211
- * @returns A promise that resolves when restoration has completed.
212
- *
213
- * #### Notes
214
- * This function should almost never be invoked by client code. Its primary
215
- * use case is to be invoked by a layout restorer plugin that handles
216
- * multiple instance trackers and, when ready, asks them each to restore their
217
- * respective widgets.
218
- */
219
- async restore(options) {
220
- if (this._hasRestored) {
221
- throw new Error('Instance tracker has already restored');
222
- }
223
- this._hasRestored = true;
224
- const { command, registry, state, when } = options;
225
- const namespace = this.namespace;
226
- const promises = when
227
- ? [state.list(namespace)].concat(when)
228
- : [state.list(namespace)];
229
- this._restore = options;
230
- const [saved] = await Promise.all(promises);
231
- const values = await Promise.all(saved.ids.map((id, index) => {
232
- const value = saved.values[index];
233
- const args = value && value.data;
234
- if (args === undefined) {
235
- return state.remove(id);
236
- }
237
- // Execute the command and if it fails, delete the state restore data.
238
- return registry.execute(command, args).catch(() => state.remove(id));
239
- }));
240
- this._restored.resolve(undefined);
241
- return values;
242
- }
243
- /**
244
- * Save the restore data for a given widget.
245
- *
246
- * @param widget - The widget being saved.
247
- */
248
- async save(widget) {
249
- const injected = Private.injectedProperty.get(widget);
250
- if (!this._restore || !this.has(widget) || injected) {
251
- return;
252
- }
253
- const { state } = this._restore;
254
- const widgetName = this._restore.name(widget);
255
- const oldName = Private.nameProperty.get(widget);
256
- const newName = widgetName ? `${this.namespace}:${widgetName}` : '';
257
- if (oldName && oldName !== newName) {
258
- await state.remove(oldName);
259
- }
260
- // Set the name property irrespective of whether the new name is null.
261
- Private.nameProperty.set(widget, newName);
262
- if (newName) {
263
- const data = this._restore.args(widget);
264
- await state.save(newName, { data });
265
- }
266
- if (oldName !== newName) {
267
- this._widgetUpdated.emit(widget);
268
- }
269
- }
270
- /**
271
- * Handle the current change event.
272
- *
273
- * #### Notes
274
- * The default implementation is a no-op.
275
- */
276
- onCurrentChanged(value) {
277
- /* no-op */
278
- }
279
- /**
280
- * Handle the current change signal from the internal focus tracker.
281
- */
282
- _onCurrentChanged(sender, args) {
283
- // Bail if the active widget did not change.
284
- if (args.newValue === this._currentWidget) {
285
- return;
286
- }
287
- this._currentWidget = args.newValue;
288
- this.onCurrentChanged(args.newValue);
289
- this._currentChanged.emit(args.newValue);
290
- }
291
- /**
292
- * Clean up after disposed widgets.
293
- */
294
- _onWidgetDisposed(widget) {
295
- const injected = Private.injectedProperty.get(widget);
296
- if (injected) {
297
- return;
298
- }
299
- // Handle widget removal.
300
- ArrayExt.removeFirstOf(this._widgets, widget);
301
- // Handle the current widget being disposed.
302
- if (widget === this._currentWidget) {
303
- this._currentWidget =
304
- this._tracker.currentWidget ||
305
- this._widgets[this._widgets.length - 1] ||
306
- null;
307
- this.onCurrentChanged(this._currentWidget);
308
- this._currentChanged.emit(this._currentWidget);
309
- }
310
- // If there is no restore data, return.
311
- if (!this._restore) {
312
- return;
313
- }
314
- const { state } = this._restore;
315
- const name = Private.nameProperty.get(widget);
316
- if (name) {
317
- void state.remove(name);
318
- }
319
- }
320
- }
321
- /*
322
- * A namespace for private data.
323
- */
324
- var Private;
325
- (function (Private) {
326
- /**
327
- * An attached property to indicate whether a widget has been injected.
328
- */
329
- Private.injectedProperty = new AttachedProperty({
330
- name: 'injected',
331
- create: () => false
332
- });
333
- /**
334
- * An attached property for a widget's ID in the state database.
335
- */
336
- Private.nameProperty = new AttachedProperty({
337
- name: 'name',
338
- create: () => ''
339
- });
340
- })(Private || (Private = {}));