@jupyterlab/application 4.0.0-alpha.9 → 4.0.0-beta.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/lib/frontend.d.ts +2 -3
- package/lib/frontend.js.map +1 -1
- package/lib/lab.js +7 -3
- package/lib/lab.js.map +1 -1
- package/lib/layoutrestorer.d.ts +23 -2
- package/lib/layoutrestorer.js +71 -22
- package/lib/layoutrestorer.js.map +1 -1
- package/lib/mimerenderers.js +1 -1
- package/lib/mimerenderers.js.map +1 -1
- package/lib/shell.d.ts +110 -19
- package/lib/shell.js +197 -66
- package/lib/shell.js.map +1 -1
- package/lib/tokens.d.ts +1 -1
- package/lib/utils.js +9 -3
- package/lib/utils.js.map +1 -1
- package/package.json +27 -27
- package/src/connectionlost.ts +27 -0
- package/src/frontend.ts +412 -0
- package/src/index.ts +25 -0
- package/src/lab.ts +289 -0
- package/src/layoutrestorer.ts +870 -0
- package/src/mimerenderers.ts +180 -0
- package/src/router.ts +206 -0
- package/src/shell.ts +2285 -0
- package/src/status.ts +93 -0
- package/src/tokens.ts +220 -0
- package/src/treepathupdater.ts +20 -0
- package/src/utils.ts +153 -0
- package/style/buttons.css +10 -10
- package/style/core.css +4 -0
- package/style/menus.css +23 -3
- package/style/scrollbar.css +1 -66
- package/style/sidepanel.css +61 -80
- package/style/tabs.css +19 -22
package/src/lab.ts
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
|
|
4
|
+
import { PageConfig } from '@jupyterlab/coreutils';
|
|
5
|
+
import { Base64ModelFactory } from '@jupyterlab/docregistry';
|
|
6
|
+
import { IRenderMime } from '@jupyterlab/rendermime-interfaces';
|
|
7
|
+
import { ServiceManager } from '@jupyterlab/services';
|
|
8
|
+
import { Token } from '@lumino/coreutils';
|
|
9
|
+
import { JupyterFrontEnd, JupyterFrontEndPlugin } from './frontend';
|
|
10
|
+
import { createRendermimePlugins } from './mimerenderers';
|
|
11
|
+
import { ILabShell, LabShell } from './shell';
|
|
12
|
+
import { LabStatus } from './status';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* JupyterLab is the main application class. It is instantiated once and shared.
|
|
16
|
+
*/
|
|
17
|
+
export class JupyterLab extends JupyterFrontEnd<ILabShell> {
|
|
18
|
+
/**
|
|
19
|
+
* Construct a new JupyterLab object.
|
|
20
|
+
*/
|
|
21
|
+
constructor(options: JupyterLab.IOptions = { shell: new LabShell() }) {
|
|
22
|
+
super({
|
|
23
|
+
...options,
|
|
24
|
+
shell: options.shell || new LabShell(),
|
|
25
|
+
serviceManager:
|
|
26
|
+
options.serviceManager ||
|
|
27
|
+
new ServiceManager({
|
|
28
|
+
standby: () => {
|
|
29
|
+
return !this._info.isConnected || 'when-hidden';
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
});
|
|
33
|
+
this.restored = this.shell.restored
|
|
34
|
+
.then(() => undefined)
|
|
35
|
+
.catch(() => undefined);
|
|
36
|
+
|
|
37
|
+
// Create an IInfo dictionary from the options to override the defaults.
|
|
38
|
+
const info = Object.keys(JupyterLab.defaultInfo).reduce((acc, val) => {
|
|
39
|
+
if (val in options) {
|
|
40
|
+
(acc as any)[val] = JSON.parse(JSON.stringify((options as any)[val]));
|
|
41
|
+
}
|
|
42
|
+
return acc;
|
|
43
|
+
}, {} as Partial<JupyterLab.IInfo>);
|
|
44
|
+
|
|
45
|
+
// Populate application info.
|
|
46
|
+
this._info = { ...JupyterLab.defaultInfo, ...info };
|
|
47
|
+
|
|
48
|
+
// Populate application paths override the defaults if necessary.
|
|
49
|
+
const defaultURLs = JupyterLab.defaultPaths.urls;
|
|
50
|
+
const defaultDirs = JupyterLab.defaultPaths.directories;
|
|
51
|
+
const optionURLs = (options.paths && options.paths.urls) || {};
|
|
52
|
+
const optionDirs = (options.paths && options.paths.directories) || {};
|
|
53
|
+
|
|
54
|
+
this._paths = {
|
|
55
|
+
urls: Object.keys(defaultURLs).reduce((acc, key) => {
|
|
56
|
+
if (key in optionURLs) {
|
|
57
|
+
const value = (optionURLs as any)[key];
|
|
58
|
+
(acc as any)[key] = value;
|
|
59
|
+
} else {
|
|
60
|
+
(acc as any)[key] = (defaultURLs as any)[key];
|
|
61
|
+
}
|
|
62
|
+
return acc;
|
|
63
|
+
}, {}),
|
|
64
|
+
directories: Object.keys(JupyterLab.defaultPaths.directories).reduce(
|
|
65
|
+
(acc, key) => {
|
|
66
|
+
if (key in optionDirs) {
|
|
67
|
+
const value = (optionDirs as any)[key];
|
|
68
|
+
(acc as any)[key] = value;
|
|
69
|
+
} else {
|
|
70
|
+
(acc as any)[key] = (defaultDirs as any)[key];
|
|
71
|
+
}
|
|
72
|
+
return acc;
|
|
73
|
+
},
|
|
74
|
+
{}
|
|
75
|
+
)
|
|
76
|
+
} as JupyterFrontEnd.IPaths;
|
|
77
|
+
|
|
78
|
+
if (this._info.devMode) {
|
|
79
|
+
this.shell.addClass('jp-mod-devMode');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Add initial model factory.
|
|
83
|
+
this.docRegistry.addModelFactory(new Base64ModelFactory());
|
|
84
|
+
|
|
85
|
+
if (options.mimeExtensions) {
|
|
86
|
+
for (const plugin of createRendermimePlugins(options.mimeExtensions)) {
|
|
87
|
+
this.registerPlugin(plugin);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The name of the JupyterLab application.
|
|
94
|
+
*/
|
|
95
|
+
readonly name = PageConfig.getOption('appName') || 'JupyterLab';
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* A namespace/prefix plugins may use to denote their provenance.
|
|
99
|
+
*/
|
|
100
|
+
readonly namespace = PageConfig.getOption('appNamespace') || this.name;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* A list of all errors encountered when registering plugins.
|
|
104
|
+
*/
|
|
105
|
+
readonly registerPluginErrors: Array<Error> = [];
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Promise that resolves when state is first restored, returning layout
|
|
109
|
+
* description.
|
|
110
|
+
*/
|
|
111
|
+
readonly restored: Promise<void>;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The application busy and dirty status signals and flags.
|
|
115
|
+
*/
|
|
116
|
+
readonly status = new LabStatus(this);
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The version of the JupyterLab application.
|
|
120
|
+
*/
|
|
121
|
+
readonly version = PageConfig.getOption('appVersion') || 'unknown';
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The JupyterLab application information dictionary.
|
|
125
|
+
*/
|
|
126
|
+
get info(): JupyterLab.IInfo {
|
|
127
|
+
return this._info;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* The JupyterLab application paths dictionary.
|
|
132
|
+
*/
|
|
133
|
+
get paths(): JupyterFrontEnd.IPaths {
|
|
134
|
+
return this._paths;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Register plugins from a plugin module.
|
|
139
|
+
*
|
|
140
|
+
* @param mod - The plugin module to register.
|
|
141
|
+
*/
|
|
142
|
+
registerPluginModule(mod: JupyterLab.IPluginModule): void {
|
|
143
|
+
let data = mod.default;
|
|
144
|
+
// Handle commonjs exports.
|
|
145
|
+
if (!mod.hasOwnProperty('__esModule')) {
|
|
146
|
+
data = mod as any;
|
|
147
|
+
}
|
|
148
|
+
if (!Array.isArray(data)) {
|
|
149
|
+
data = [data];
|
|
150
|
+
}
|
|
151
|
+
data.forEach(item => {
|
|
152
|
+
try {
|
|
153
|
+
this.registerPlugin(item);
|
|
154
|
+
} catch (error) {
|
|
155
|
+
this.registerPluginErrors.push(error);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Register the plugins from multiple plugin modules.
|
|
162
|
+
*
|
|
163
|
+
* @param mods - The plugin modules to register.
|
|
164
|
+
*/
|
|
165
|
+
registerPluginModules(mods: JupyterLab.IPluginModule[]): void {
|
|
166
|
+
mods.forEach(mod => {
|
|
167
|
+
this.registerPluginModule(mod);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private _info: JupyterLab.IInfo = JupyterLab.defaultInfo;
|
|
172
|
+
private _paths: JupyterFrontEnd.IPaths;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* The namespace for `JupyterLab` class statics.
|
|
177
|
+
*/
|
|
178
|
+
export namespace JupyterLab {
|
|
179
|
+
/**
|
|
180
|
+
* The options used to initialize a JupyterLab object.
|
|
181
|
+
*/
|
|
182
|
+
export interface IOptions
|
|
183
|
+
extends Partial<JupyterFrontEnd.IOptions<ILabShell>>,
|
|
184
|
+
Partial<IInfo> {
|
|
185
|
+
paths?: Partial<JupyterFrontEnd.IPaths>;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* The layout restorer token.
|
|
190
|
+
*/
|
|
191
|
+
export const IInfo = new Token<IInfo>('@jupyterlab/application:IInfo');
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* The information about a JupyterLab application.
|
|
195
|
+
*/
|
|
196
|
+
export interface IInfo {
|
|
197
|
+
/**
|
|
198
|
+
* Whether the application is in dev mode.
|
|
199
|
+
*/
|
|
200
|
+
readonly devMode: boolean;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* The collection of deferred extension patterns and matched extensions.
|
|
204
|
+
*/
|
|
205
|
+
readonly deferred: { patterns: string[]; matches: string[] };
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* The collection of disabled extension patterns and matched extensions.
|
|
209
|
+
*/
|
|
210
|
+
readonly disabled: { patterns: string[]; matches: string[] };
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* The mime renderer extensions.
|
|
214
|
+
*/
|
|
215
|
+
readonly mimeExtensions: IRenderMime.IExtensionModule[];
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Whether files are cached on the server.
|
|
219
|
+
*/
|
|
220
|
+
readonly filesCached: boolean;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Every periodic network polling should be paused while this is set
|
|
224
|
+
* to `false`. Extensions should use this value to decide whether to proceed
|
|
225
|
+
* with the polling.
|
|
226
|
+
* The extensions may also set this value to `false` if there is no need to
|
|
227
|
+
* fetch anything from the server backend basing on some conditions
|
|
228
|
+
* (e.g. when an error message dialog is displayed).
|
|
229
|
+
* At the same time, the extensions are responsible for setting this value
|
|
230
|
+
* back to `true`.
|
|
231
|
+
*/
|
|
232
|
+
isConnected: boolean;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* The default JupyterLab application info.
|
|
237
|
+
*/
|
|
238
|
+
export const defaultInfo: IInfo = {
|
|
239
|
+
devMode: PageConfig.getOption('devMode').toLowerCase() === 'true',
|
|
240
|
+
deferred: { patterns: [], matches: [] },
|
|
241
|
+
disabled: { patterns: [], matches: [] },
|
|
242
|
+
mimeExtensions: [],
|
|
243
|
+
filesCached: PageConfig.getOption('cacheFiles').toLowerCase() === 'true',
|
|
244
|
+
isConnected: true
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* The default JupyterLab application paths.
|
|
249
|
+
*/
|
|
250
|
+
export const defaultPaths: JupyterFrontEnd.IPaths = {
|
|
251
|
+
urls: {
|
|
252
|
+
base: PageConfig.getOption('baseUrl'),
|
|
253
|
+
notFound: PageConfig.getOption('notFoundUrl'),
|
|
254
|
+
app: PageConfig.getOption('appUrl'),
|
|
255
|
+
doc: PageConfig.getOption('docUrl'),
|
|
256
|
+
static: PageConfig.getOption('staticUrl'),
|
|
257
|
+
settings: PageConfig.getOption('settingsUrl'),
|
|
258
|
+
themes: PageConfig.getOption('themesUrl'),
|
|
259
|
+
translations: PageConfig.getOption('translationsApiUrl'),
|
|
260
|
+
hubHost: PageConfig.getOption('hubHost') || undefined,
|
|
261
|
+
hubPrefix: PageConfig.getOption('hubPrefix') || undefined,
|
|
262
|
+
hubUser: PageConfig.getOption('hubUser') || undefined,
|
|
263
|
+
hubServerName: PageConfig.getOption('hubServerName') || undefined
|
|
264
|
+
},
|
|
265
|
+
directories: {
|
|
266
|
+
appSettings: PageConfig.getOption('appSettingsDir'),
|
|
267
|
+
schemas: PageConfig.getOption('schemasDir'),
|
|
268
|
+
static: PageConfig.getOption('staticDir'),
|
|
269
|
+
templates: PageConfig.getOption('templatesDir'),
|
|
270
|
+
themes: PageConfig.getOption('themesDir'),
|
|
271
|
+
userSettings: PageConfig.getOption('userSettingsDir'),
|
|
272
|
+
serverRoot: PageConfig.getOption('serverRoot'),
|
|
273
|
+
workspaces: PageConfig.getOption('workspacesDir')
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* The interface for a module that exports a plugin or plugins as
|
|
279
|
+
* the default value.
|
|
280
|
+
*/
|
|
281
|
+
export interface IPluginModule {
|
|
282
|
+
/**
|
|
283
|
+
* The default export.
|
|
284
|
+
*/
|
|
285
|
+
default:
|
|
286
|
+
| JupyterFrontEndPlugin<any, any, any>
|
|
287
|
+
| JupyterFrontEndPlugin<any, any, any>[];
|
|
288
|
+
}
|
|
289
|
+
}
|