@jupyter-notebook/console-extension 7.6.0-alpha.1 → 7.6.0-alpha.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/lib/index.js +118 -5
- package/package.json +14 -7
- package/schema/scratchpad-console.json +38 -0
package/lib/index.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
// Copyright (c) Jupyter Development Team.
|
|
2
2
|
// Distributed under the terms of the Modified BSD License.
|
|
3
3
|
import { IRouter, } from '@jupyterlab/application';
|
|
4
|
+
import { ICommandPalette } from '@jupyterlab/apputils';
|
|
4
5
|
import { IConsoleTracker } from '@jupyterlab/console';
|
|
5
6
|
import { PageConfig, URLExt } from '@jupyterlab/coreutils';
|
|
6
|
-
import {
|
|
7
|
+
import { INotebookTracker } from '@jupyterlab/notebook';
|
|
8
|
+
import { ITranslator, nullTranslator } from '@jupyterlab/translation';
|
|
9
|
+
import { consoleIcon } from '@jupyterlab/ui-components';
|
|
10
|
+
import { INotebookPathOpener, INotebookShell, defaultNotebookPathOpener, } from '@jupyter-notebook/application';
|
|
7
11
|
import { find } from '@lumino/algorithm';
|
|
8
12
|
/**
|
|
9
13
|
* A plugin to open consoles in a new tab
|
|
@@ -36,18 +40,38 @@ const opener = {
|
|
|
36
40
|
},
|
|
37
41
|
};
|
|
38
42
|
/**
|
|
39
|
-
* Open consoles in a new tab.
|
|
43
|
+
* Open consoles in a new tab or in the side panel (scratchpad like).
|
|
40
44
|
*/
|
|
41
45
|
const redirect = {
|
|
42
46
|
id: '@jupyter-notebook/console-extension:redirect',
|
|
43
47
|
requires: [IConsoleTracker],
|
|
44
|
-
optional: [INotebookPathOpener],
|
|
48
|
+
optional: [INotebookPathOpener, INotebookShell, INotebookTracker],
|
|
45
49
|
autoStart: true,
|
|
46
50
|
description: 'Open consoles in a new tab',
|
|
47
|
-
activate: (app, tracker, notebookPathOpener) => {
|
|
51
|
+
activate: (app, tracker, notebookPathOpener, notebookShell, notebookTracker) => {
|
|
48
52
|
const baseUrl = PageConfig.getBaseUrl();
|
|
49
53
|
const opener = notebookPathOpener !== null && notebookPathOpener !== void 0 ? notebookPathOpener : defaultNotebookPathOpener;
|
|
50
54
|
tracker.widgetAdded.connect(async (send, console) => {
|
|
55
|
+
var _a, _b, _c, _d;
|
|
56
|
+
// Check if we should open the console in side panel:
|
|
57
|
+
// - this is a notebook view
|
|
58
|
+
// - the notebook and the console share the same kernel
|
|
59
|
+
// Otherwise, the console opens in a new tab.
|
|
60
|
+
if (notebookShell && notebookTracker) {
|
|
61
|
+
const notebook = notebookTracker.currentWidget;
|
|
62
|
+
// Wait for the notebook and console to be ready.
|
|
63
|
+
await Promise.all([
|
|
64
|
+
notebook === null || notebook === void 0 ? void 0 : notebook.sessionContext.ready,
|
|
65
|
+
console.sessionContext.ready,
|
|
66
|
+
]);
|
|
67
|
+
const notebookKernelId = (_b = (_a = notebook === null || notebook === void 0 ? void 0 : notebook.sessionContext.session) === null || _a === void 0 ? void 0 : _a.kernel) === null || _b === void 0 ? void 0 : _b.id;
|
|
68
|
+
const consoleKernelId = (_d = (_c = console.sessionContext.session) === null || _c === void 0 ? void 0 : _c.kernel) === null || _d === void 0 ? void 0 : _d.id;
|
|
69
|
+
if (notebookKernelId === consoleKernelId) {
|
|
70
|
+
notebookShell.add(console, 'right');
|
|
71
|
+
notebookShell.expandRight(console.id);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
51
75
|
const { sessionContext } = console;
|
|
52
76
|
await sessionContext.ready;
|
|
53
77
|
const widget = find(app.shell.widgets('main'), (w) => w.id === console.id);
|
|
@@ -65,8 +89,97 @@ const redirect = {
|
|
|
65
89
|
});
|
|
66
90
|
},
|
|
67
91
|
};
|
|
92
|
+
/**
|
|
93
|
+
* Open consoles in the side panel.
|
|
94
|
+
*/
|
|
95
|
+
const scratchpadConsole = {
|
|
96
|
+
id: '@jupyter-notebook/console-extension:scratchpad-console',
|
|
97
|
+
requires: [INotebookTracker],
|
|
98
|
+
optional: [INotebookShell, ICommandPalette, ITranslator],
|
|
99
|
+
autoStart: true,
|
|
100
|
+
description: 'Open scratchpad console in side panel',
|
|
101
|
+
activate: (app, tracker, notebookShell, palette, translator) => {
|
|
102
|
+
const { commands } = app;
|
|
103
|
+
const manager = app.serviceManager;
|
|
104
|
+
const trans = (translator !== null && translator !== void 0 ? translator : nullTranslator).load('notebook');
|
|
105
|
+
const command = 'scratchpad-console:open';
|
|
106
|
+
commands.addCommand(command, {
|
|
107
|
+
label: (args) => args['isPalette']
|
|
108
|
+
? trans.__('Open a scratchpad console')
|
|
109
|
+
: trans.__('Scratchpad console'),
|
|
110
|
+
isVisible: () => !!tracker.currentWidget,
|
|
111
|
+
icon: (args) => (args['isPalette'] ? undefined : consoleIcon),
|
|
112
|
+
execute: async (args) => {
|
|
113
|
+
var _a, _b, _c, _d;
|
|
114
|
+
if (!notebookShell) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const consoleId = scratchpadConsole.id;
|
|
118
|
+
const sidebar = notebookShell.rightHandler;
|
|
119
|
+
// Close the console if it is already opened (shortcut only).
|
|
120
|
+
if (sidebar.isVisible && ((_a = sidebar.currentWidget) === null || _a === void 0 ? void 0 : _a.id) === consoleId) {
|
|
121
|
+
if (!args.isPalette && !args.isMenu) {
|
|
122
|
+
notebookShell.collapseRight();
|
|
123
|
+
(_b = notebookShell.currentWidget) === null || _b === void 0 ? void 0 : _b.activate();
|
|
124
|
+
}
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
let panel = sidebar.widgets.find((w) => w.id === consoleId);
|
|
128
|
+
// Create the widget if it is not already in the right area.
|
|
129
|
+
if (!panel) {
|
|
130
|
+
const notebook = tracker.currentWidget;
|
|
131
|
+
if (!notebook) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const notebookSessionContext = notebook.sessionContext;
|
|
135
|
+
await Promise.all([notebookSessionContext.ready, manager.ready]);
|
|
136
|
+
const id = (_d = (_c = notebookSessionContext.session) === null || _c === void 0 ? void 0 : _c.kernel) === null || _d === void 0 ? void 0 : _d.id;
|
|
137
|
+
const kernelPref = notebookSessionContext.kernelPreference;
|
|
138
|
+
panel = await commands.execute('console:create', {
|
|
139
|
+
kernelPreference: { ...kernelPref, id },
|
|
140
|
+
});
|
|
141
|
+
if (!panel) {
|
|
142
|
+
console.error('An error occurred during scratchpad console creation');
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
panel.title.caption = trans.__('Console');
|
|
146
|
+
panel.id = consoleId;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
notebookShell.expandRight(consoleId);
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
describedBy: {
|
|
153
|
+
args: {
|
|
154
|
+
type: 'object',
|
|
155
|
+
properties: {
|
|
156
|
+
isPalette: {
|
|
157
|
+
type: 'boolean',
|
|
158
|
+
description: trans.__('Whether the command is executed from the palette'),
|
|
159
|
+
},
|
|
160
|
+
isMenu: {
|
|
161
|
+
type: 'boolean',
|
|
162
|
+
description: trans.__('Whether the command is executed from the menu'),
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
if (palette) {
|
|
169
|
+
palette.addItem({
|
|
170
|
+
category: 'Notebook Console',
|
|
171
|
+
command,
|
|
172
|
+
args: { isPalette: true },
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
};
|
|
68
177
|
/**
|
|
69
178
|
* Export the plugins as default.
|
|
70
179
|
*/
|
|
71
|
-
const plugins = [
|
|
180
|
+
const plugins = [
|
|
181
|
+
opener,
|
|
182
|
+
redirect,
|
|
183
|
+
scratchpadConsole,
|
|
184
|
+
];
|
|
72
185
|
export default plugins;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyter-notebook/console-extension",
|
|
3
|
-
"version": "7.6.0-alpha.
|
|
3
|
+
"version": "7.6.0-alpha.3",
|
|
4
4
|
"description": "Jupyter Notebook - Console Extension",
|
|
5
5
|
"homepage": "https://github.com/jupyter/notebook",
|
|
6
6
|
"bugs": {
|
|
@@ -38,11 +38,17 @@
|
|
|
38
38
|
"watch": "tsc -b --watch"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@jupyter-notebook/application": "^7.6.0-alpha.
|
|
42
|
-
"@jupyterlab/application": "~4.6.0-alpha.
|
|
43
|
-
"@jupyterlab/
|
|
44
|
-
"@jupyterlab/
|
|
45
|
-
"@
|
|
41
|
+
"@jupyter-notebook/application": "^7.6.0-alpha.3",
|
|
42
|
+
"@jupyterlab/application": "~4.6.0-alpha.3",
|
|
43
|
+
"@jupyterlab/apputils": "~4.7.0-alpha.3",
|
|
44
|
+
"@jupyterlab/console": "~4.6.0-alpha.3",
|
|
45
|
+
"@jupyterlab/coreutils": "~6.6.0-alpha.3",
|
|
46
|
+
"@jupyterlab/notebook": "~4.6.0-alpha.3",
|
|
47
|
+
"@jupyterlab/translation": "~4.6.0-alpha.3",
|
|
48
|
+
"@jupyterlab/ui-components": "~4.6.0-alpha.3",
|
|
49
|
+
"@lumino/algorithm": "^2.0.4",
|
|
50
|
+
"@lumino/coreutils": "^2.2.2",
|
|
51
|
+
"@lumino/widgets": "^2.7.2"
|
|
46
52
|
},
|
|
47
53
|
"devDependencies": {
|
|
48
54
|
"rimraf": "^3.0.2",
|
|
@@ -52,7 +58,8 @@
|
|
|
52
58
|
"access": "public"
|
|
53
59
|
},
|
|
54
60
|
"jupyterlab": {
|
|
55
|
-
"extension": true
|
|
61
|
+
"extension": true,
|
|
62
|
+
"schemaDir": "schema"
|
|
56
63
|
},
|
|
57
64
|
"styleModule": "style/index.js"
|
|
58
65
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"title": "Jupyter Notebook Scratchpad Console",
|
|
3
|
+
"description": "Jupyter Notebook Scratchpad Console",
|
|
4
|
+
"jupyter.lab.menus": {
|
|
5
|
+
"main": [
|
|
6
|
+
{
|
|
7
|
+
"id": "jp-mainmenu-file",
|
|
8
|
+
"items": [
|
|
9
|
+
{
|
|
10
|
+
"type": "submenu",
|
|
11
|
+
"submenu": {
|
|
12
|
+
"id": "jp-mainmenu-file-new",
|
|
13
|
+
"items": [
|
|
14
|
+
{
|
|
15
|
+
"command": "scratchpad-console:open",
|
|
16
|
+
"rank": 2,
|
|
17
|
+
"args": {
|
|
18
|
+
"isMenu": true
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
"jupyter.lab.shortcuts": [
|
|
29
|
+
{
|
|
30
|
+
"command": "scratchpad-console:open",
|
|
31
|
+
"keys": ["Accel B"],
|
|
32
|
+
"selector": "body"
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
"properties": {},
|
|
36
|
+
"additionalProperties": false,
|
|
37
|
+
"type": "object"
|
|
38
|
+
}
|