@jupyterlite/notebook-application-extension 0.2.2 → 0.2.3
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/package.json +8 -7
- package/src/index.ts +88 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyterlite/notebook-application-extension",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "JupyterLite - Notebook Application Extension",
|
|
5
5
|
"homepage": "https://github.com/jupyterlite/jupyterlite",
|
|
6
6
|
"bugs": {
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
"lib/*.js.map",
|
|
28
28
|
"lib/*.js",
|
|
29
29
|
"style/*.css",
|
|
30
|
-
"style/index.js"
|
|
30
|
+
"style/index.js",
|
|
31
|
+
"src/**/*.{ts,tsx}"
|
|
31
32
|
],
|
|
32
33
|
"scripts": {
|
|
33
34
|
"build": "tsc -b",
|
|
@@ -37,11 +38,11 @@
|
|
|
37
38
|
"watch": "tsc -b --watch"
|
|
38
39
|
},
|
|
39
40
|
"dependencies": {
|
|
40
|
-
"@jupyter-notebook/application": "~7.0.
|
|
41
|
-
"@jupyterlab/application": "~4.0.
|
|
42
|
-
"@jupyterlab/coreutils": "~6.0.
|
|
43
|
-
"@jupyterlab/services": "~7.0.
|
|
44
|
-
"@jupyterlite/ui-components": "^0.2.
|
|
41
|
+
"@jupyter-notebook/application": "~7.0.7",
|
|
42
|
+
"@jupyterlab/application": "~4.0.11",
|
|
43
|
+
"@jupyterlab/coreutils": "~6.0.11",
|
|
44
|
+
"@jupyterlab/services": "~7.0.11",
|
|
45
|
+
"@jupyterlite/ui-components": "^0.2.3"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"@babel/core": "^7.11.6",
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
|
|
4
|
+
import { JupyterFrontEndPlugin, JupyterFrontEnd } from '@jupyterlab/application';
|
|
5
|
+
|
|
6
|
+
import { PageConfig } from '@jupyterlab/coreutils';
|
|
7
|
+
|
|
8
|
+
import { liteWordmark } from '@jupyterlite/ui-components';
|
|
9
|
+
|
|
10
|
+
import { Widget } from '@lumino/widgets';
|
|
11
|
+
|
|
12
|
+
import { INotebookPathOpener, INotebookShell } from '@jupyter-notebook/application';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The logo plugin.
|
|
16
|
+
*/
|
|
17
|
+
const logo: JupyterFrontEndPlugin<void> = {
|
|
18
|
+
id: '@jupyterlite/notebook-application-extension:logo',
|
|
19
|
+
autoStart: true,
|
|
20
|
+
activate: (app: JupyterFrontEnd) => {
|
|
21
|
+
const baseUrl = PageConfig.getBaseUrl();
|
|
22
|
+
const node = document.createElement('a');
|
|
23
|
+
node.href = `${baseUrl}tree`;
|
|
24
|
+
node.target = '_blank';
|
|
25
|
+
node.rel = 'noopener noreferrer';
|
|
26
|
+
const logo = new Widget({ node });
|
|
27
|
+
|
|
28
|
+
liteWordmark.element({
|
|
29
|
+
container: node,
|
|
30
|
+
elementPosition: 'center',
|
|
31
|
+
padding: '2px 2px 2px 8px',
|
|
32
|
+
height: '28px',
|
|
33
|
+
width: 'auto',
|
|
34
|
+
});
|
|
35
|
+
logo.id = 'jp-NotebookLogo';
|
|
36
|
+
app.shell.add(logo, 'top', { rank: 0 });
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A plugin to trigger a refresh of the commands when the shell layout changes.
|
|
42
|
+
*/
|
|
43
|
+
const notifyCommands: JupyterFrontEndPlugin<void> = {
|
|
44
|
+
id: '@jupyterlite/notebook-application-extension:notify-commands',
|
|
45
|
+
autoStart: true,
|
|
46
|
+
optional: [INotebookShell],
|
|
47
|
+
activate: (app: JupyterFrontEnd, notebookShell: INotebookShell | null) => {
|
|
48
|
+
if (notebookShell) {
|
|
49
|
+
notebookShell.currentChanged.connect(() => {
|
|
50
|
+
requestAnimationFrame(() => {
|
|
51
|
+
app.commands.notifyCommandChanged();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A plugin to open paths in new browser tabs, using `?path=` to specify the path to open.
|
|
60
|
+
*/
|
|
61
|
+
const pathOpener: JupyterFrontEndPlugin<INotebookPathOpener> = {
|
|
62
|
+
id: '@jupyterlite/notebook-application-extension:path-opener',
|
|
63
|
+
autoStart: true,
|
|
64
|
+
provides: INotebookPathOpener,
|
|
65
|
+
activate: (app: JupyterFrontEnd): INotebookPathOpener => {
|
|
66
|
+
return {
|
|
67
|
+
open(options: INotebookPathOpener.IOpenOptions): Window | null {
|
|
68
|
+
const { prefix, path, searchParams, target, features } = options;
|
|
69
|
+
const url = new URL(prefix, window.location.origin);
|
|
70
|
+
// initialize the new search params
|
|
71
|
+
const search = new URLSearchParams(searchParams?.toString() ?? '');
|
|
72
|
+
// open paths by setting the `?path=` search parameter
|
|
73
|
+
if (path) {
|
|
74
|
+
search.set('path', path);
|
|
75
|
+
}
|
|
76
|
+
const searchString = search.toString();
|
|
77
|
+
if (searchString) {
|
|
78
|
+
url.search = searchString;
|
|
79
|
+
}
|
|
80
|
+
return window.open(url, target, features);
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const plugins: JupyterFrontEndPlugin<any>[] = [logo, notifyCommands, pathOpener];
|
|
87
|
+
|
|
88
|
+
export default plugins;
|