@jupyterlite/repl-extension 0.1.0-alpha.23

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,184 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+ import { ILabStatus, IRouter, JupyterFrontEnd, Router, } from '@jupyterlab/application';
4
+ import { CommandToolbarButton, IThemeManager, Toolbar } from '@jupyterlab/apputils';
5
+ import { IConsoleTracker } from '@jupyterlab/console';
6
+ import { ITranslator } from '@jupyterlab/translation';
7
+ import { clearIcon, refreshIcon, runIcon } from '@jupyterlab/ui-components';
8
+ import { SingleWidgetApp } from '@jupyterlite/application';
9
+ import { liteIcon } from '@jupyterlite/ui-components';
10
+ import { Widget } from '@lumino/widgets';
11
+ /**
12
+ * A plugin to add buttons to the console toolbar.
13
+ */
14
+ const buttons = {
15
+ id: '@jupyterlite/console-application:buttons',
16
+ autoStart: true,
17
+ requires: [ITranslator],
18
+ optional: [IConsoleTracker],
19
+ activate: (app, translator, tracker) => {
20
+ if (!tracker) {
21
+ return;
22
+ }
23
+ const { commands } = app;
24
+ const trans = translator.load('jupyterlab');
25
+ // wrapper commands to be able to override the icon
26
+ const runCommand = 'repl:run';
27
+ commands.addCommand(runCommand, {
28
+ caption: trans.__('Run'),
29
+ icon: runIcon,
30
+ execute: () => {
31
+ return commands.execute('console:run-forced');
32
+ },
33
+ });
34
+ const runButton = new CommandToolbarButton({
35
+ commands,
36
+ id: runCommand,
37
+ });
38
+ const restartCommand = 'repl:restart';
39
+ commands.addCommand(restartCommand, {
40
+ caption: trans.__('Restart'),
41
+ icon: refreshIcon,
42
+ execute: () => {
43
+ return commands.execute('console:restart-kernel');
44
+ },
45
+ });
46
+ const restartButton = new CommandToolbarButton({
47
+ commands,
48
+ id: restartCommand,
49
+ });
50
+ const clearCommand = 'repl:clear';
51
+ commands.addCommand(clearCommand, {
52
+ caption: trans.__('Clear'),
53
+ icon: clearIcon,
54
+ execute: () => {
55
+ return commands.execute('console:clear');
56
+ },
57
+ });
58
+ const clearButton = new CommandToolbarButton({
59
+ commands,
60
+ id: clearCommand,
61
+ });
62
+ tracker.widgetAdded.connect((_, console) => {
63
+ const { toolbar } = console;
64
+ console.toolbar.addItem('run', runButton);
65
+ console.toolbar.addItem('restart', restartButton);
66
+ console.toolbar.addItem('clear', clearButton);
67
+ toolbar.addItem('spacer', Toolbar.createSpacerItem());
68
+ const node = document.createElement('a');
69
+ node.title = trans.__('Powered by JupyterLite');
70
+ node.href = 'https://github.com/jupyterlite/jupyterlite';
71
+ node.target = '_blank';
72
+ node.rel = 'noopener noreferrer';
73
+ const poweredBy = new Widget({ node });
74
+ liteIcon.element({
75
+ container: node,
76
+ elementPosition: 'center',
77
+ margin: '2px 2px 2px 8px',
78
+ height: 'auto',
79
+ width: '16px',
80
+ });
81
+ poweredBy.addClass('jp-PoweredBy');
82
+ toolbar.insertAfter('spacer', 'powered-by', poweredBy);
83
+ });
84
+ },
85
+ };
86
+ /**
87
+ * A plugin to open a code console and
88
+ * parse custom parameters from the query string arguments.
89
+ */
90
+ const consolePlugin = {
91
+ id: '@jupyterlite/repl-extension:console',
92
+ autoStart: true,
93
+ optional: [IConsoleTracker, IThemeManager],
94
+ activate: (app, tracker, themeManager) => {
95
+ var _a;
96
+ if (!tracker) {
97
+ return;
98
+ }
99
+ const { commands } = app;
100
+ const search = window.location.search;
101
+ const urlParams = new URLSearchParams(search);
102
+ const code = urlParams.getAll('code');
103
+ const kernel = urlParams.get('kernel') || undefined;
104
+ const theme = (_a = urlParams.get('theme')) === null || _a === void 0 ? void 0 : _a.trim();
105
+ const toolbar = urlParams.get('toolbar');
106
+ app.started.then(() => {
107
+ commands.execute('console:create', { kernelPreference: { name: kernel } });
108
+ });
109
+ if (theme && themeManager) {
110
+ const themeName = decodeURIComponent(theme);
111
+ themeManager.setTheme(themeName);
112
+ }
113
+ tracker.widgetAdded.connect(async (_, widget) => {
114
+ const { console } = widget;
115
+ if (!toolbar) {
116
+ // hide the toolbar by default if not specified
117
+ widget.toolbar.dispose();
118
+ }
119
+ if (code) {
120
+ await console.sessionContext.ready;
121
+ code.forEach((line) => console.inject(line));
122
+ }
123
+ });
124
+ },
125
+ };
126
+ /**
127
+ * The default JupyterLab application status provider.
128
+ */
129
+ const status = {
130
+ id: '@jupyterlite/repl-extension:status',
131
+ autoStart: true,
132
+ provides: ILabStatus,
133
+ activate: (app) => {
134
+ if (!(app instanceof SingleWidgetApp)) {
135
+ throw new Error(`${status.id} must be activated in SingleWidgetApp.`);
136
+ }
137
+ return app.status;
138
+ },
139
+ };
140
+ /**
141
+ * The default paths for a single widget app.
142
+ */
143
+ const paths = {
144
+ id: '@jupyterlite/repl-extension:paths',
145
+ autoStart: true,
146
+ provides: JupyterFrontEnd.IPaths,
147
+ activate: (app) => {
148
+ if (!(app instanceof SingleWidgetApp)) {
149
+ throw new Error(`${paths.id} must be activated in SingleWidgetApp.`);
150
+ }
151
+ return app.paths;
152
+ },
153
+ };
154
+ /**
155
+ * The default URL router provider.
156
+ */
157
+ const router = {
158
+ id: '@jupyterlite/repl-extension:router',
159
+ autoStart: true,
160
+ provides: IRouter,
161
+ requires: [JupyterFrontEnd.IPaths],
162
+ activate: (app, paths) => {
163
+ const { commands } = app;
164
+ const base = paths.urls.base;
165
+ const router = new Router({ base, commands });
166
+ void app.started.then(() => {
167
+ // Route the very first request on load.
168
+ void router.route();
169
+ // Route all pop state events.
170
+ window.addEventListener('popstate', () => {
171
+ void router.route();
172
+ });
173
+ });
174
+ return router;
175
+ },
176
+ };
177
+ const plugins = [
178
+ buttons,
179
+ consolePlugin,
180
+ paths,
181
+ router,
182
+ status,
183
+ ];
184
+ export default plugins;
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@jupyterlite/repl-extension",
3
+ "version": "0.1.0-alpha.23",
4
+ "description": "JupyterLite - Console 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
+ "@jupyterlab/application": "~3.2.9",
41
+ "@jupyterlab/apputils": "~3.2.9",
42
+ "@jupyterlab/console": "~3.2.9",
43
+ "@jupyterlab/translation": "~3.2.9",
44
+ "@jupyterlab/ui-components": "~3.2.9",
45
+ "@jupyterlite/application": "^0.1.0-alpha.23",
46
+ "@jupyterlite/ui-components": "^0.1.0-alpha.23",
47
+ "@lumino/widgets": "^1.30.1"
48
+ },
49
+ "devDependencies": {
50
+ "@babel/core": "^7.11.6",
51
+ "@babel/preset-env": "^7.12.1",
52
+ "@types/jest": "^26.0.10",
53
+ "jest": "^26.4.2",
54
+ "rimraf": "~3.0.0",
55
+ "ts-jest": "^26.3.0",
56
+ "typescript": "~4.2.3"
57
+ },
58
+ "publishConfig": {
59
+ "access": "public"
60
+ },
61
+ "jupyterlab": {
62
+ "extension": true
63
+ },
64
+ "styleModule": "style/index.js"
65
+ }
package/style/base.css ADDED
@@ -0,0 +1,25 @@
1
+ /*-----------------------------------------------------------------------------
2
+ | Copyright (c) Jupyter Development Team.
3
+ | Distributed under the terms of the Modified BSD License.
4
+ |----------------------------------------------------------------------------*/
5
+
6
+ .jp-CodeConsole-promptCell .jp-InputPrompt {
7
+ margin-right: 10px;
8
+ }
9
+
10
+ .jp-CodeConsole-input .jp-InputCollapser {
11
+ display: none;
12
+ }
13
+
14
+ .jp-InputArea {
15
+ flex-direction: row;
16
+ }
17
+
18
+ .jp-InputArea-editor,
19
+ .jp-OutputArea-child .jp-OutputArea-output {
20
+ margin-left: unset;
21
+ }
22
+
23
+ .jp-OutputArea-child {
24
+ flex-direction: row;
25
+ }
@@ -0,0 +1,8 @@
1
+ /*-----------------------------------------------------------------------------
2
+ | Copyright (c) Jupyter Development Team.
3
+ | Distributed under the terms of the Modified BSD License.
4
+ |----------------------------------------------------------------------------*/
5
+
6
+ @import url('~@jupyterlite/application/style/index.css');
7
+
8
+ @import url('./base.css');
package/style/index.js ADDED
@@ -0,0 +1,8 @@
1
+ /*-----------------------------------------------------------------------------
2
+ | Copyright (c) Jupyter Development Team.
3
+ | Distributed under the terms of the Modified BSD License.
4
+ |----------------------------------------------------------------------------*/
5
+
6
+ import '@jupyterlite/application/style/index.js';
7
+
8
+ import './base.css';