@jupyterlite/notebook-application-extension 0.2.0-alpha.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.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { JupyterFrontEndPlugin } from '@jupyterlab/application';
2
+ declare const plugins: JupyterFrontEndPlugin<any>[];
3
+ export default plugins;
package/lib/index.js ADDED
@@ -0,0 +1,140 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+ import { IConsoleTracker } from '@jupyterlab/console';
4
+ import { PageConfig, PathExt } from '@jupyterlab/coreutils';
5
+ import { IDocumentWidgetOpener } from '@jupyterlab/docmanager';
6
+ import { liteWordmark } from '@jupyterlite/ui-components';
7
+ import { Signal } from '@lumino/signaling';
8
+ 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
+ };
97
+ /**
98
+ * The logo plugin.
99
+ */
100
+ const logo = {
101
+ id: '@jupyterlite/notebook-application-extension:logo',
102
+ autoStart: true,
103
+ activate: (app) => {
104
+ const baseUrl = PageConfig.getBaseUrl();
105
+ const node = document.createElement('a');
106
+ node.href = `${baseUrl}tree`;
107
+ node.target = '_blank';
108
+ node.rel = 'noopener noreferrer';
109
+ const logo = new Widget({ node });
110
+ liteWordmark.element({
111
+ container: node,
112
+ elementPosition: 'center',
113
+ padding: '2px 2px 2px 8px',
114
+ height: '28px',
115
+ width: 'auto',
116
+ });
117
+ logo.id = 'jp-NotebookLogo';
118
+ app.shell.add(logo, 'top', { rank: 0 });
119
+ },
120
+ };
121
+ /**
122
+ * A plugin to trigger a refresh of the commands when the shell layout changes.
123
+ */
124
+ const notifyCommands = {
125
+ id: '@jupyterlite/notebook-application-extension:notify-commands',
126
+ autoStart: true,
127
+ optional: [INotebookShell],
128
+ activate: (app, notebookShell) => {
129
+ if (notebookShell) {
130
+ notebookShell.currentChanged.connect(() => {
131
+ requestAnimationFrame(() => {
132
+ app.commands.notifyCommandChanged();
133
+ });
134
+ });
135
+ }
136
+ },
137
+ };
138
+ const plugins = [consoles, logo, opener, notifyCommands];
139
+ export default plugins;
140
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAI3D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAI/D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D;;GAEG;AACH,MAAM,QAAQ,GAAgC;IAC5C,EAAE,EAAE,sDAAsD;I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CAAC;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,cAAc,GAAgC;IAClD,EAAE,EAAE,6DAA6D;IACjE,SAAS,EAAE,IAAI;IACf,QAAQ,EAAE,CAAC,cAAc,CAAC;IAC1B,QAAQ,EAAE,CAAC,GAAoB,EAAE,aAAoC,EAAE,EAAE;QACvE,IAAI,aAAa,EAAE;YACjB,aAAa,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,EAAE;gBACxC,qBAAqB,CAAC,GAAG,EAAE;oBACzB,GAAG,CAAC,QAAQ,CAAC,oBAAoB,EAAE,CAAC;gBACtC,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;CACF,CAAC;AAEF,MAAM,OAAO,GAAiC,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC;AAEvF,eAAe,OAAO,CAAC"}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@jupyterlite/notebook-application-extension",
3
+ "version": "0.2.0-alpha.0",
4
+ "description": "JupyterLite - Notebook Application Extension",
5
+ "homepage": "https://github.com/jupyterlite/jupyterlite",
6
+ "bugs": {
7
+ "url": "https://github.com/jupyterlite/jupyterlite/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/jupyterlite/jupyterlite.git"
12
+ },
13
+ "license": "BSD-3-Clause",
14
+ "author": "JupyterLite Contributors",
15
+ "sideEffects": [
16
+ "style/*.css",
17
+ "style/index.js"
18
+ ],
19
+ "main": "lib/index.js",
20
+ "types": "lib/index.d.ts",
21
+ "style": "style/index.css",
22
+ "directories": {
23
+ "lib": "lib/"
24
+ },
25
+ "files": [
26
+ "lib/*.d.ts",
27
+ "lib/*.js.map",
28
+ "lib/*.js",
29
+ "style/*.css",
30
+ "style/index.js"
31
+ ],
32
+ "scripts": {
33
+ "build": "tsc -b",
34
+ "clean": "rimraf lib && rimraf tsconfig.tsbuildinfo",
35
+ "docs": "typedoc src",
36
+ "prepublishOnly": "npm run build",
37
+ "watch": "tsc -b --watch"
38
+ },
39
+ "dependencies": {
40
+ "@jupyter-notebook/application": "^7.0.3",
41
+ "@jupyterlab/application": "~4.0.5",
42
+ "@jupyterlab/console": "~4.0.5",
43
+ "@jupyterlab/coreutils": "~6.0.5",
44
+ "@jupyterlab/docmanager": "~4.0.5",
45
+ "@jupyterlab/services": "~7.0.5",
46
+ "@jupyterlite/ui-components": "^0.2.0-alpha.0"
47
+ },
48
+ "devDependencies": {
49
+ "@babel/core": "^7.11.6",
50
+ "@babel/preset-env": "^7.12.1",
51
+ "@types/jest": "^29.5.3",
52
+ "jest": "^29.6.2",
53
+ "rimraf": "~5.0.1",
54
+ "ts-jest": "^29.1.1",
55
+ "typescript": "~5.0.4"
56
+ },
57
+ "publishConfig": {
58
+ "access": "public"
59
+ },
60
+ "jupyterlab": {
61
+ "extension": true
62
+ },
63
+ "styleModule": "style/index.js"
64
+ }
package/style/base.css ADDED
@@ -0,0 +1,4 @@
1
+ /*-----------------------------------------------------------------------------
2
+ | Copyright (c) Jupyter Development Team.
3
+ | Distributed under the terms of the Modified BSD License.
4
+ |----------------------------------------------------------------------------*/
@@ -0,0 +1,6 @@
1
+ /*-----------------------------------------------------------------------------
2
+ | Copyright (c) Jupyter Development Team.
3
+ | Distributed under the terms of the Modified BSD License.
4
+ |----------------------------------------------------------------------------*/
5
+
6
+ @import url('./base.css');
package/style/index.js ADDED
@@ -0,0 +1,6 @@
1
+ /*-----------------------------------------------------------------------------
2
+ | Copyright (c) Jupyter Development Team.
3
+ | Distributed under the terms of the Modified BSD License.
4
+ |----------------------------------------------------------------------------*/
5
+
6
+ import './base.css';