@jupyter-notebook/application-extension 7.0.0-beta.3 → 7.0.0-rc.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.
- package/lib/index.js +146 -11
- package/package.json +14 -13
- package/schema/shell.json +34 -0
package/lib/index.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
// Copyright (c) Jupyter Development Team.
|
|
2
2
|
// Distributed under the terms of the Modified BSD License.
|
|
3
3
|
import { ILabStatus, IRouter, ITreePathUpdater, JupyterFrontEnd, } from '@jupyterlab/application';
|
|
4
|
-
import { DOMUtils, ICommandPalette, IToolbarWidgetRegistry, } from '@jupyterlab/apputils';
|
|
4
|
+
import { DOMUtils, ICommandPalette, ISanitizer, ISplashScreen, IToolbarWidgetRegistry, } from '@jupyterlab/apputils';
|
|
5
5
|
import { ConsolePanel } from '@jupyterlab/console';
|
|
6
6
|
import { PageConfig, PathExt, URLExt } from '@jupyterlab/coreutils';
|
|
7
7
|
import { IDocumentManager, renameDialog } from '@jupyterlab/docmanager';
|
|
8
8
|
import { DocumentWidget } from '@jupyterlab/docregistry';
|
|
9
9
|
import { IMainMenu } from '@jupyterlab/mainmenu';
|
|
10
|
+
import { ILatexTypesetter, IMarkdownParser, IRenderMimeRegistry, RenderMimeRegistry, standardRendererFactories, } from '@jupyterlab/rendermime';
|
|
10
11
|
import { ISettingRegistry } from '@jupyterlab/settingregistry';
|
|
11
|
-
import { ITranslator } from '@jupyterlab/translation';
|
|
12
|
+
import { ITranslator, nullTranslator } from '@jupyterlab/translation';
|
|
12
13
|
import { NotebookApp, NotebookShell, INotebookShell, SidePanelPalette, } from '@jupyter-notebook/application';
|
|
13
14
|
import { jupyterIcon } from '@jupyter-notebook/ui-components';
|
|
14
15
|
import { PromiseDelegate } from '@lumino/coreutils';
|
|
@@ -22,11 +23,19 @@ const TREE_PATTERN = new RegExp('/(notebooks|edit)/(.*)');
|
|
|
22
23
|
* A regular expression to suppress the file extension from display for .ipynb files.
|
|
23
24
|
*/
|
|
24
25
|
const STRIP_IPYNB = /\.ipynb$/;
|
|
26
|
+
/**
|
|
27
|
+
* The JupyterLab document manager plugin id.
|
|
28
|
+
*/
|
|
29
|
+
const JUPYTERLAB_DOCMANAGER_PLUGIN_ID = '@jupyterlab/docmanager-extension:plugin';
|
|
25
30
|
/**
|
|
26
31
|
* The command IDs used by the application plugin.
|
|
27
32
|
*/
|
|
28
33
|
var CommandIDs;
|
|
29
34
|
(function (CommandIDs) {
|
|
35
|
+
/**
|
|
36
|
+
* Handle local links
|
|
37
|
+
*/
|
|
38
|
+
CommandIDs.handleLink = 'application:handle-local-link';
|
|
30
39
|
/**
|
|
31
40
|
* Toggle Top Bar visibility
|
|
32
41
|
*/
|
|
@@ -108,22 +117,43 @@ const opener = {
|
|
|
108
117
|
id: '@jupyter-notebook/application-extension:opener',
|
|
109
118
|
autoStart: true,
|
|
110
119
|
requires: [IRouter, IDocumentManager],
|
|
111
|
-
|
|
112
|
-
|
|
120
|
+
optional: [ISettingRegistry],
|
|
121
|
+
activate: (app, router, docManager, settingRegistry) => {
|
|
122
|
+
const { commands, docRegistry } = app;
|
|
113
123
|
const command = 'router:tree';
|
|
114
124
|
commands.addCommand(command, {
|
|
115
125
|
execute: (args) => {
|
|
116
|
-
var _a
|
|
126
|
+
var _a;
|
|
117
127
|
const parsed = args;
|
|
118
128
|
const matches = (_a = parsed.path.match(TREE_PATTERN)) !== null && _a !== void 0 ? _a : [];
|
|
119
129
|
const [, , path] = matches;
|
|
120
130
|
if (!path) {
|
|
121
131
|
return;
|
|
122
132
|
}
|
|
123
|
-
const file = decodeURIComponent(path);
|
|
124
|
-
const urlParams = new URLSearchParams(parsed.search);
|
|
125
|
-
const factory = (_b = urlParams.get('factory')) !== null && _b !== void 0 ? _b : 'default';
|
|
126
133
|
app.started.then(async () => {
|
|
134
|
+
var _a;
|
|
135
|
+
const file = decodeURIComponent(path);
|
|
136
|
+
const urlParams = new URLSearchParams(parsed.search);
|
|
137
|
+
let defaultFactory = docRegistry.defaultWidgetFactory(path).name;
|
|
138
|
+
// Explicitely get the default viewers from the settings because
|
|
139
|
+
// JupyterLab might not have had the time to load the settings yet (race condition)
|
|
140
|
+
// Relevant code: https://github.com/jupyterlab/jupyterlab/blob/d56ff811f39b3c10c6d8b6eb27a94624b753eb53/packages/docmanager-extension/src/index.tsx#L265-L293
|
|
141
|
+
if (settingRegistry) {
|
|
142
|
+
const settings = await settingRegistry.load(JUPYTERLAB_DOCMANAGER_PLUGIN_ID);
|
|
143
|
+
const defaultViewers = settings.get('defaultViewers').composite;
|
|
144
|
+
// get the file types for the path
|
|
145
|
+
const types = docRegistry.getFileTypesForPath(path);
|
|
146
|
+
// for each file type, check if there is a default viewer and if it
|
|
147
|
+
// is available in the docRegistry. If it is the case, use it as the
|
|
148
|
+
// default factory
|
|
149
|
+
types.forEach((ft) => {
|
|
150
|
+
if (defaultViewers[ft.name] !== undefined &&
|
|
151
|
+
docRegistry.getWidgetFactory(defaultViewers[ft.name])) {
|
|
152
|
+
defaultFactory = defaultViewers[ft.name];
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
const factory = (_a = urlParams.get('factory')) !== null && _a !== void 0 ? _a : defaultFactory;
|
|
127
157
|
docManager.open(file, factory, undefined, {
|
|
128
158
|
ref: '_noref',
|
|
129
159
|
});
|
|
@@ -223,19 +253,122 @@ const paths = {
|
|
|
223
253
|
return app.paths;
|
|
224
254
|
},
|
|
225
255
|
};
|
|
256
|
+
/**
|
|
257
|
+
* A plugin providing a rendermime registry.
|
|
258
|
+
*/
|
|
259
|
+
const rendermime = {
|
|
260
|
+
id: '@jupyter-notebook/application-extension:rendermime',
|
|
261
|
+
autoStart: true,
|
|
262
|
+
provides: IRenderMimeRegistry,
|
|
263
|
+
description: 'Provides the render mime registry.',
|
|
264
|
+
optional: [
|
|
265
|
+
IDocumentManager,
|
|
266
|
+
ILatexTypesetter,
|
|
267
|
+
ISanitizer,
|
|
268
|
+
IMarkdownParser,
|
|
269
|
+
ITranslator,
|
|
270
|
+
],
|
|
271
|
+
activate: (app, docManager, latexTypesetter, sanitizer, markdownParser, translator) => {
|
|
272
|
+
const trans = (translator !== null && translator !== void 0 ? translator : nullTranslator).load('jupyterlab');
|
|
273
|
+
if (docManager) {
|
|
274
|
+
app.commands.addCommand(CommandIDs.handleLink, {
|
|
275
|
+
label: trans.__('Handle Local Link'),
|
|
276
|
+
execute: (args) => {
|
|
277
|
+
const path = args['path'];
|
|
278
|
+
if (path === undefined || path === null) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
return docManager.services.contents
|
|
282
|
+
.get(path, { content: false })
|
|
283
|
+
.then((model) => {
|
|
284
|
+
// Open in a new browser tab
|
|
285
|
+
const url = PageConfig.getBaseUrl();
|
|
286
|
+
const treeUrl = URLExt.join(url, 'tree', model.path);
|
|
287
|
+
window.open(treeUrl, '_blank');
|
|
288
|
+
});
|
|
289
|
+
},
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
return new RenderMimeRegistry({
|
|
293
|
+
initialFactories: standardRendererFactories,
|
|
294
|
+
linkHandler: !docManager
|
|
295
|
+
? undefined
|
|
296
|
+
: {
|
|
297
|
+
handleLink: (node, path, id) => {
|
|
298
|
+
// If node has the download attribute explicitly set, use the
|
|
299
|
+
// default browser downloading behavior.
|
|
300
|
+
if (node.tagName === 'A' && node.hasAttribute('download')) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
app.commandLinker.connectNode(node, CommandIDs.handleLink, {
|
|
304
|
+
path,
|
|
305
|
+
id,
|
|
306
|
+
});
|
|
307
|
+
},
|
|
308
|
+
},
|
|
309
|
+
latexTypesetter: latexTypesetter !== null && latexTypesetter !== void 0 ? latexTypesetter : undefined,
|
|
310
|
+
markdownParser: markdownParser !== null && markdownParser !== void 0 ? markdownParser : undefined,
|
|
311
|
+
translator: translator !== null && translator !== void 0 ? translator : undefined,
|
|
312
|
+
sanitizer: sanitizer !== null && sanitizer !== void 0 ? sanitizer : undefined,
|
|
313
|
+
});
|
|
314
|
+
},
|
|
315
|
+
};
|
|
226
316
|
/**
|
|
227
317
|
* The default Jupyter Notebook application shell.
|
|
228
318
|
*/
|
|
229
319
|
const shell = {
|
|
230
320
|
id: '@jupyter-notebook/application-extension:shell',
|
|
231
|
-
|
|
321
|
+
autoStart: true,
|
|
322
|
+
provides: INotebookShell,
|
|
323
|
+
optional: [ISettingRegistry],
|
|
324
|
+
activate: (app, settingRegistry) => {
|
|
232
325
|
if (!(app.shell instanceof NotebookShell)) {
|
|
233
326
|
throw new Error(`${shell.id} did not find a NotebookShell instance.`);
|
|
234
327
|
}
|
|
235
|
-
|
|
328
|
+
const notebookShell = app.shell;
|
|
329
|
+
if (settingRegistry) {
|
|
330
|
+
settingRegistry
|
|
331
|
+
.load(shell.id)
|
|
332
|
+
.then((settings) => {
|
|
333
|
+
// Add a layer of customization to support app shell mode
|
|
334
|
+
const customLayout = settings.composite['layout'];
|
|
335
|
+
// Restore the layout.
|
|
336
|
+
void notebookShell.restoreLayout(customLayout);
|
|
337
|
+
})
|
|
338
|
+
.catch((reason) => {
|
|
339
|
+
console.error('Fail to load settings for the layout restorer.');
|
|
340
|
+
console.error(reason);
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
return notebookShell;
|
|
236
344
|
},
|
|
345
|
+
};
|
|
346
|
+
/**
|
|
347
|
+
* The default splash screen provider.
|
|
348
|
+
*/
|
|
349
|
+
const splash = {
|
|
350
|
+
id: '@jupyter-notebook/application-extension:splash',
|
|
351
|
+
description: 'Provides an empty splash screen.',
|
|
237
352
|
autoStart: true,
|
|
238
|
-
provides:
|
|
353
|
+
provides: ISplashScreen,
|
|
354
|
+
activate: (app) => {
|
|
355
|
+
const { restored } = app;
|
|
356
|
+
const splash = document.createElement('div');
|
|
357
|
+
splash.style.position = 'absolute';
|
|
358
|
+
splash.style.width = '100%';
|
|
359
|
+
splash.style.height = '100%';
|
|
360
|
+
splash.style.zIndex = '10';
|
|
361
|
+
return {
|
|
362
|
+
show: (light = true) => {
|
|
363
|
+
splash.style.backgroundColor = light ? 'white' : '#111111';
|
|
364
|
+
document.body.appendChild(splash);
|
|
365
|
+
return new DisposableDelegate(async () => {
|
|
366
|
+
await restored;
|
|
367
|
+
document.body.removeChild(splash);
|
|
368
|
+
});
|
|
369
|
+
},
|
|
370
|
+
};
|
|
371
|
+
},
|
|
239
372
|
};
|
|
240
373
|
/**
|
|
241
374
|
* The default JupyterLab application status provider.
|
|
@@ -739,8 +872,10 @@ const plugins = [
|
|
|
739
872
|
opener,
|
|
740
873
|
pages,
|
|
741
874
|
paths,
|
|
875
|
+
rendermime,
|
|
742
876
|
shell,
|
|
743
877
|
sidePanelVisibility,
|
|
878
|
+
splash,
|
|
744
879
|
status,
|
|
745
880
|
tabTitle,
|
|
746
881
|
title,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyter-notebook/application-extension",
|
|
3
|
-
"version": "7.0.0-
|
|
3
|
+
"version": "7.0.0-rc.0",
|
|
4
4
|
"description": "Jupyter Notebook - Application Extension",
|
|
5
5
|
"homepage": "https://github.com/jupyter/notebook",
|
|
6
6
|
"bugs": {
|
|
@@ -38,18 +38,19 @@
|
|
|
38
38
|
"watch": "tsc -b --watch"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@jupyter-notebook/application": "^7.0.0-
|
|
42
|
-
"@jupyter-notebook/ui-components": "^7.0.0-
|
|
43
|
-
"@jupyterlab/application": "^4.0.
|
|
44
|
-
"@jupyterlab/apputils": "^4.
|
|
45
|
-
"@jupyterlab/codeeditor": "^4.0.
|
|
46
|
-
"@jupyterlab/console": "^4.0.
|
|
47
|
-
"@jupyterlab/coreutils": "^6.0.
|
|
48
|
-
"@jupyterlab/docmanager": "^4.0.
|
|
49
|
-
"@jupyterlab/docregistry": "^4.0.
|
|
50
|
-
"@jupyterlab/mainmenu": "^4.0.
|
|
51
|
-
"@jupyterlab/
|
|
52
|
-
"@jupyterlab/
|
|
41
|
+
"@jupyter-notebook/application": "^7.0.0-rc.0",
|
|
42
|
+
"@jupyter-notebook/ui-components": "^7.0.0-rc.0",
|
|
43
|
+
"@jupyterlab/application": "^4.0.2",
|
|
44
|
+
"@jupyterlab/apputils": "^4.1.2",
|
|
45
|
+
"@jupyterlab/codeeditor": "^4.0.2",
|
|
46
|
+
"@jupyterlab/console": "^4.0.2",
|
|
47
|
+
"@jupyterlab/coreutils": "^6.0.2",
|
|
48
|
+
"@jupyterlab/docmanager": "^4.0.2",
|
|
49
|
+
"@jupyterlab/docregistry": "^4.0.2",
|
|
50
|
+
"@jupyterlab/mainmenu": "^4.0.2",
|
|
51
|
+
"@jupyterlab/rendermime": "^4.0.2",
|
|
52
|
+
"@jupyterlab/settingregistry": "^4.0.2",
|
|
53
|
+
"@jupyterlab/translation": "^4.0.2",
|
|
53
54
|
"@lumino/coreutils": "^2.1.1",
|
|
54
55
|
"@lumino/disposable": "^2.1.1",
|
|
55
56
|
"@lumino/widgets": "^2.1.1"
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema",
|
|
3
|
+
"title": "Notebook Shell",
|
|
4
|
+
"description": "Notebook Shell layout settings.",
|
|
5
|
+
"properties": {
|
|
6
|
+
"layout": {
|
|
7
|
+
"$ref": "#/definitions/layout",
|
|
8
|
+
"type": "object",
|
|
9
|
+
"title": "Customize shell widget positioning",
|
|
10
|
+
"description": "Overrides default widget position in the application layout",
|
|
11
|
+
"default": {
|
|
12
|
+
"Markdown Preview": { "area": "right" }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"additionalProperties": false,
|
|
17
|
+
"type": "object",
|
|
18
|
+
"definitions": {
|
|
19
|
+
"layout": {
|
|
20
|
+
"type": "object",
|
|
21
|
+
"properties": {
|
|
22
|
+
"[\\w-]+": {
|
|
23
|
+
"type": "object",
|
|
24
|
+
"properties": {
|
|
25
|
+
"area": {
|
|
26
|
+
"enum": ["left", "right"]
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"additionalProperties": false
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|