@jupyterlite/notebook-application-extension 0.2.0-alpha.0 → 0.2.0-alpha.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/index.js +32 -93
- package/lib/index.js.map +1 -1
- package/package.json +6 -8
package/lib/index.js
CHANGED
|
@@ -1,99 +1,9 @@
|
|
|
1
1
|
// Copyright (c) Jupyter Development Team.
|
|
2
2
|
// Distributed under the terms of the Modified BSD License.
|
|
3
|
-
import {
|
|
4
|
-
import { PageConfig, PathExt } from '@jupyterlab/coreutils';
|
|
5
|
-
import { IDocumentWidgetOpener } from '@jupyterlab/docmanager';
|
|
3
|
+
import { PageConfig } from '@jupyterlab/coreutils';
|
|
6
4
|
import { liteWordmark } from '@jupyterlite/ui-components';
|
|
7
|
-
import { Signal } from '@lumino/signaling';
|
|
8
5
|
import { Widget } from '@lumino/widgets';
|
|
9
|
-
import { INotebookShell } from '@jupyter-notebook/application';
|
|
10
|
-
/**
|
|
11
|
-
* Open consoles in a new tab.
|
|
12
|
-
*/
|
|
13
|
-
const consoles = {
|
|
14
|
-
id: '@jupyterlite/notebook-application-extension:consoles',
|
|
15
|
-
requires: [IConsoleTracker],
|
|
16
|
-
autoStart: true,
|
|
17
|
-
activate: (app, tracker) => {
|
|
18
|
-
const baseUrl = PageConfig.getBaseUrl();
|
|
19
|
-
tracker.widgetAdded.connect(async (send, console) => {
|
|
20
|
-
const { sessionContext } = console;
|
|
21
|
-
const page = PageConfig.getOption('notebookPage');
|
|
22
|
-
if (page === 'consoles') {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
const path = sessionContext.path;
|
|
26
|
-
window.open(`${baseUrl}consoles?path=${path}`, '_blank');
|
|
27
|
-
// the widget is not needed anymore
|
|
28
|
-
console.dispose();
|
|
29
|
-
});
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* A plugin to open documents in a new browser tab.
|
|
34
|
-
* This plugin is different than the Notebook plugin because JupyterLite creates
|
|
35
|
-
* links with `?path=...` to open documents.
|
|
36
|
-
* TODO: investigate how to use the same plugin but make the query parameter configurable
|
|
37
|
-
*
|
|
38
|
-
*/
|
|
39
|
-
const opener = {
|
|
40
|
-
id: '@jupyterlite/notebook-application-extension:opener',
|
|
41
|
-
autoStart: true,
|
|
42
|
-
optional: [INotebookShell],
|
|
43
|
-
provides: IDocumentWidgetOpener,
|
|
44
|
-
activate: (app, notebookShell) => {
|
|
45
|
-
const baseUrl = PageConfig.getBaseUrl();
|
|
46
|
-
const docRegistry = app.docRegistry;
|
|
47
|
-
let id = 0;
|
|
48
|
-
return new (class {
|
|
49
|
-
constructor() {
|
|
50
|
-
this._opened = new Signal(this);
|
|
51
|
-
}
|
|
52
|
-
open(widget, options) {
|
|
53
|
-
var _a, _b, _c;
|
|
54
|
-
const widgetName = (_a = options === null || options === void 0 ? void 0 : options.type) !== null && _a !== void 0 ? _a : '';
|
|
55
|
-
const ref = options === null || options === void 0 ? void 0 : options.ref;
|
|
56
|
-
// check if there is an setting override and if it would add the widget in the main area
|
|
57
|
-
const userLayoutArea = (_c = (_b = notebookShell === null || notebookShell === void 0 ? void 0 : notebookShell.userLayout) === null || _b === void 0 ? void 0 : _b[widgetName]) === null || _c === void 0 ? void 0 : _c.area;
|
|
58
|
-
if (ref !== '_noref' && userLayoutArea === undefined) {
|
|
59
|
-
const path = widget.context.path;
|
|
60
|
-
const ext = PathExt.extname(path);
|
|
61
|
-
let route = 'edit';
|
|
62
|
-
if ((widgetName === 'default' && ext === '.ipynb') ||
|
|
63
|
-
widgetName.includes('Notebook')) {
|
|
64
|
-
route = 'notebooks';
|
|
65
|
-
}
|
|
66
|
-
let url = `${baseUrl}${route}?path=${path}`;
|
|
67
|
-
// append ?factory only if it's not the default
|
|
68
|
-
const defaultFactory = docRegistry.defaultWidgetFactory(path);
|
|
69
|
-
if (widgetName !== defaultFactory.name) {
|
|
70
|
-
url = `${url}?factory=${widgetName}`;
|
|
71
|
-
}
|
|
72
|
-
window.open(url);
|
|
73
|
-
// dispose the widget since it is not used on this page
|
|
74
|
-
widget.dispose();
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
// otherwise open the document on the current page
|
|
78
|
-
if (!widget.id) {
|
|
79
|
-
widget.id = `document-manager-${++id}`;
|
|
80
|
-
}
|
|
81
|
-
widget.title.dataset = {
|
|
82
|
-
type: 'document-title',
|
|
83
|
-
...widget.title.dataset,
|
|
84
|
-
};
|
|
85
|
-
if (!widget.isAttached) {
|
|
86
|
-
app.shell.add(widget, 'main', options || {});
|
|
87
|
-
}
|
|
88
|
-
app.shell.activateById(widget.id);
|
|
89
|
-
this._opened.emit(widget);
|
|
90
|
-
}
|
|
91
|
-
get opened() {
|
|
92
|
-
return this._opened;
|
|
93
|
-
}
|
|
94
|
-
})();
|
|
95
|
-
},
|
|
96
|
-
};
|
|
6
|
+
import { INotebookPathOpener, INotebookShell } from '@jupyter-notebook/application';
|
|
97
7
|
/**
|
|
98
8
|
* The logo plugin.
|
|
99
9
|
*/
|
|
@@ -135,6 +45,35 @@ const notifyCommands = {
|
|
|
135
45
|
}
|
|
136
46
|
},
|
|
137
47
|
};
|
|
138
|
-
|
|
48
|
+
/**
|
|
49
|
+
* A plugin to open paths in new browser tabs, using `?path=` to specify the path to open.
|
|
50
|
+
*/
|
|
51
|
+
const pathOpener = {
|
|
52
|
+
id: '@jupyterlite/notebook-application-extension:path-opener',
|
|
53
|
+
autoStart: true,
|
|
54
|
+
provides: INotebookPathOpener,
|
|
55
|
+
activate: (app) => {
|
|
56
|
+
console.log('using the JupyterLite path opener');
|
|
57
|
+
return {
|
|
58
|
+
open(options) {
|
|
59
|
+
var _a;
|
|
60
|
+
const { prefix, path, searchParams, target, features } = options;
|
|
61
|
+
const url = new URL(prefix, window.location.origin);
|
|
62
|
+
// initialize the new search params
|
|
63
|
+
const search = new URLSearchParams((_a = searchParams === null || searchParams === void 0 ? void 0 : searchParams.toString()) !== null && _a !== void 0 ? _a : '');
|
|
64
|
+
// open paths by setting the `?path=` search parameter
|
|
65
|
+
if (path) {
|
|
66
|
+
search.set('path', path);
|
|
67
|
+
}
|
|
68
|
+
const searchString = search.toString();
|
|
69
|
+
if (searchString) {
|
|
70
|
+
url.search = searchString;
|
|
71
|
+
}
|
|
72
|
+
return window.open(url, target, features);
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
const plugins = [logo, notifyCommands, pathOpener];
|
|
139
78
|
export default plugins;
|
|
140
79
|
//# sourceMappingURL=index.js.map
|
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;AAI3D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAI3D,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAEpF;;GAEG;AACH,MAAM,IAAI,GAAgC;IACxC,EAAE,EAAE,kDAAkD;IACtD,SAAS,EAAE,IAAI;IACf,QAAQ,EAAE,CAAC,GAAoB,EAAE,EAAE;QACjC,MAAM,OAAO,GAAG,UAAU,CAAC,UAAU,EAAE,CAAC;QACxC,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;QACzC,IAAI,CAAC,IAAI,GAAG,GAAG,OAAO,MAAM,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC;QACvB,IAAI,CAAC,GAAG,GAAG,qBA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AI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;gBACpD,mCAAmC;gBACnC,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,MAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,QAAQ,EAAE,mCAAI,EAAE,CAAC,CAAC;gBACnE,sDAAsD;gBACtD,IAAI,IAAI,EAAE;oBACR,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;iBAC1B;gBACD,MAAM,YAAY,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;gBACvC,IAAI,YAAY,EAAE;oBAChB,GAAG,CAAC,MAAM,GAAG,YAAY,CAAC;iBAC3B;gBACD,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;YAC5C,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,MAAM,OAAO,GAAiC,CAAC,IAAI,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC;AAEjF,eAAe,OAAO,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyterlite/notebook-application-extension",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.1",
|
|
4
4
|
"description": "JupyterLite - Notebook Application Extension",
|
|
5
5
|
"homepage": "https://github.com/jupyterlite/jupyterlite",
|
|
6
6
|
"bugs": {
|
|
@@ -37,13 +37,11 @@
|
|
|
37
37
|
"watch": "tsc -b --watch"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@jupyter-notebook/application": "
|
|
41
|
-
"@jupyterlab/application": "~4.0.
|
|
42
|
-
"@jupyterlab/
|
|
43
|
-
"@jupyterlab/
|
|
44
|
-
"@
|
|
45
|
-
"@jupyterlab/services": "~7.0.5",
|
|
46
|
-
"@jupyterlite/ui-components": "^0.2.0-alpha.0"
|
|
40
|
+
"@jupyter-notebook/application": "~7.0.4",
|
|
41
|
+
"@jupyterlab/application": "~4.0.6",
|
|
42
|
+
"@jupyterlab/coreutils": "~6.0.6",
|
|
43
|
+
"@jupyterlab/services": "~7.0.6",
|
|
44
|
+
"@jupyterlite/ui-components": "^0.2.0-alpha.1"
|
|
47
45
|
},
|
|
48
46
|
"devDependencies": {
|
|
49
47
|
"@babel/core": "^7.11.6",
|