@jupyterlite/application-extension 0.1.0-alpha.10
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 +3 -0
- package/lib/index.js +266 -0
- package/package.json +72 -0
- package/style/base.css +4 -0
- package/style/index.css +8 -0
- package/style/index.js +8 -0
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
import { ILabShell } from '@jupyterlab/application';
|
|
4
|
+
import { ICommandPalette, Dialog, showDialog } from '@jupyterlab/apputils';
|
|
5
|
+
import { PageConfig } from '@jupyterlab/coreutils';
|
|
6
|
+
import { IDocumentManager } from '@jupyterlab/docmanager';
|
|
7
|
+
import { IDocumentProviderFactory, ProviderMock, getAnonymousUserName, getRandomColor } from '@jupyterlab/docprovider';
|
|
8
|
+
import { IFileBrowserFactory } from '@jupyterlab/filebrowser';
|
|
9
|
+
import { IMainMenu } from '@jupyterlab/mainmenu';
|
|
10
|
+
import { ITranslator } from '@jupyterlab/translation';
|
|
11
|
+
import { downloadIcon } from '@jupyterlab/ui-components';
|
|
12
|
+
import { liteIcon, liteWordmark } from '@jupyterlite/ui-components';
|
|
13
|
+
import { toArray } from '@lumino/algorithm';
|
|
14
|
+
import { UUID, PromiseDelegate } from '@lumino/coreutils';
|
|
15
|
+
import { Widget } from '@lumino/widgets';
|
|
16
|
+
import { getParam } from 'lib0/environment';
|
|
17
|
+
import { WebrtcProvider } from 'y-webrtc';
|
|
18
|
+
import React from 'react';
|
|
19
|
+
class WebRtcProvider extends WebrtcProvider {
|
|
20
|
+
constructor(options) {
|
|
21
|
+
super(`${options.room}${options.path}`, options.ymodel.ydoc);
|
|
22
|
+
this._initialRequest = null;
|
|
23
|
+
this.awareness = options.ymodel.awareness;
|
|
24
|
+
const color = `#${getParam('--usercolor', getRandomColor().slice(1))}`;
|
|
25
|
+
const name = getParam('--username', getAnonymousUserName());
|
|
26
|
+
const currState = this.awareness.getLocalState();
|
|
27
|
+
// only set if this was not already set by another plugin
|
|
28
|
+
if (currState && !currState.name) {
|
|
29
|
+
this.awareness.setLocalStateField('user', {
|
|
30
|
+
name,
|
|
31
|
+
color
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
setPath() {
|
|
36
|
+
// TODO: this seems super useful
|
|
37
|
+
}
|
|
38
|
+
requestInitialContent() {
|
|
39
|
+
if (this._initialRequest) {
|
|
40
|
+
return this._initialRequest.promise;
|
|
41
|
+
}
|
|
42
|
+
let resolved = false;
|
|
43
|
+
this._initialRequest = new PromiseDelegate();
|
|
44
|
+
this.on('synced', (event) => {
|
|
45
|
+
if (this._initialRequest) {
|
|
46
|
+
this._initialRequest.resolve(event.synced);
|
|
47
|
+
resolved = true;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
// similar logic as in the upstream plugin
|
|
51
|
+
setTimeout(() => {
|
|
52
|
+
if (!resolved && this._initialRequest) {
|
|
53
|
+
this._initialRequest.resolve(false);
|
|
54
|
+
}
|
|
55
|
+
}, 1000);
|
|
56
|
+
return this._initialRequest.promise;
|
|
57
|
+
}
|
|
58
|
+
putInitializedState() {
|
|
59
|
+
// no-op
|
|
60
|
+
}
|
|
61
|
+
acquireLock() {
|
|
62
|
+
return Promise.resolve(0);
|
|
63
|
+
}
|
|
64
|
+
releaseLock(lock) {
|
|
65
|
+
// no-op
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The command IDs used by the application extension.
|
|
70
|
+
*/
|
|
71
|
+
var CommandIDs;
|
|
72
|
+
(function (CommandIDs) {
|
|
73
|
+
CommandIDs.about = 'application:about';
|
|
74
|
+
CommandIDs.docmanagerDownload = 'docmanager:download';
|
|
75
|
+
CommandIDs.filebrowserDownload = 'filebrowser:download';
|
|
76
|
+
})(CommandIDs || (CommandIDs = {}));
|
|
77
|
+
/**
|
|
78
|
+
* Add a command to show an About dialog.
|
|
79
|
+
*/
|
|
80
|
+
const about = {
|
|
81
|
+
id: '@jupyterlite/application-extension:about',
|
|
82
|
+
autoStart: true,
|
|
83
|
+
requires: [ITranslator],
|
|
84
|
+
optional: [ICommandPalette, IMainMenu],
|
|
85
|
+
activate: (app, translator, palette, menu) => {
|
|
86
|
+
const { commands } = app;
|
|
87
|
+
const trans = translator.load('jupyterlab');
|
|
88
|
+
const category = trans.__('Help');
|
|
89
|
+
commands.addCommand(CommandIDs.about, {
|
|
90
|
+
label: trans.__('About %1', app.name),
|
|
91
|
+
execute: () => {
|
|
92
|
+
const versionNumber = trans.__('Version %1', app.version);
|
|
93
|
+
const versionInfo = (React.createElement("span", { className: "jp-About-version-info" },
|
|
94
|
+
React.createElement("span", { className: "jp-About-version" }, versionNumber)));
|
|
95
|
+
const title = (React.createElement("span", { className: "jp-About-header" },
|
|
96
|
+
React.createElement("div", { className: "jp-About-header-info" },
|
|
97
|
+
React.createElement(liteWordmark.react, { height: "auto", width: "196px" }),
|
|
98
|
+
versionInfo)));
|
|
99
|
+
// Create the body of the about dialog
|
|
100
|
+
const jupyterliteURL = 'https://github.com/jupyterlite/jupyterlite';
|
|
101
|
+
const contributorsURL = 'https://github.com/jupyterlite/jupyterlite/graphs/contributors';
|
|
102
|
+
const externalLinks = (React.createElement("span", { className: "jp-About-externalLinks" },
|
|
103
|
+
React.createElement("a", { href: contributorsURL, target: "_blank", rel: "noopener noreferrer", className: "jp-Button-flat" }, trans.__('CONTRIBUTOR LIST')),
|
|
104
|
+
React.createElement("a", { href: jupyterliteURL, target: "_blank", rel: "noopener noreferrer", className: "jp-Button-flat" }, trans.__('JUPYTERLITE ON GITHUB'))));
|
|
105
|
+
const copyright = (React.createElement("span", { className: "jp-About-copyright" }, trans.__('© 2021 JupyterLite Contributors')));
|
|
106
|
+
const body = (React.createElement("div", { className: "jp-About-body" },
|
|
107
|
+
externalLinks,
|
|
108
|
+
copyright));
|
|
109
|
+
return showDialog({
|
|
110
|
+
title,
|
|
111
|
+
body,
|
|
112
|
+
buttons: [
|
|
113
|
+
Dialog.createButton({
|
|
114
|
+
label: trans.__('Dismiss'),
|
|
115
|
+
className: 'jp-About-button jp-mod-reject jp-mod-styled'
|
|
116
|
+
})
|
|
117
|
+
]
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
if (palette) {
|
|
122
|
+
palette.addItem({ command: CommandIDs.about, category });
|
|
123
|
+
}
|
|
124
|
+
if (menu) {
|
|
125
|
+
menu.helpMenu.addGroup([{ command: CommandIDs.about }], 0);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* An alternative document provider plugin
|
|
131
|
+
*/
|
|
132
|
+
const docProviderPlugin = {
|
|
133
|
+
id: '@jupyterlite/application-extension:docprovider',
|
|
134
|
+
provides: IDocumentProviderFactory,
|
|
135
|
+
activate: (app) => {
|
|
136
|
+
const roomName = getParam('--room', '').trim();
|
|
137
|
+
const host = window.location.host;
|
|
138
|
+
// enable if both the page config option (deployment wide) and the room name (user) are defined
|
|
139
|
+
const collaborative = PageConfig.getOption('collaborative') === 'true' && roomName;
|
|
140
|
+
// default to a random id to not collaborate with others by default
|
|
141
|
+
const room = `${host}-${roomName || UUID.uuid4()}`;
|
|
142
|
+
const factory = (options) => {
|
|
143
|
+
return collaborative
|
|
144
|
+
? new WebRtcProvider({
|
|
145
|
+
room,
|
|
146
|
+
...options
|
|
147
|
+
})
|
|
148
|
+
: new ProviderMock();
|
|
149
|
+
};
|
|
150
|
+
return factory;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* A plugin providing download commands in the file menu and command palette.
|
|
155
|
+
*/
|
|
156
|
+
const downloadPlugin = {
|
|
157
|
+
id: '@jupyterlite/application-extension:download',
|
|
158
|
+
autoStart: true,
|
|
159
|
+
requires: [ITranslator, IDocumentManager],
|
|
160
|
+
optional: [ICommandPalette, IFileBrowserFactory, IMainMenu],
|
|
161
|
+
activate: (app, translator, docManager, palette, factory, mainMenu) => {
|
|
162
|
+
const trans = translator.load('jupyterlab');
|
|
163
|
+
const { commands, contextMenu, serviceManager, shell } = app;
|
|
164
|
+
const isEnabled = () => {
|
|
165
|
+
const { currentWidget } = shell;
|
|
166
|
+
return !!(currentWidget && docManager.contextForWidget(currentWidget));
|
|
167
|
+
};
|
|
168
|
+
const downloadContent = (content, path) => {
|
|
169
|
+
const element = document.createElement('a');
|
|
170
|
+
element.href = `data:text/json;charset=utf-8,${encodeURIComponent(content)}`;
|
|
171
|
+
element.download = path;
|
|
172
|
+
document.body.appendChild(element);
|
|
173
|
+
element.click();
|
|
174
|
+
document.body.removeChild(element);
|
|
175
|
+
};
|
|
176
|
+
commands.addCommand(CommandIDs.docmanagerDownload, {
|
|
177
|
+
label: trans.__('Download'),
|
|
178
|
+
caption: trans.__('Download the file to your computer'),
|
|
179
|
+
isEnabled,
|
|
180
|
+
execute: () => {
|
|
181
|
+
// Checks that shell.currentWidget is valid:
|
|
182
|
+
const current = shell.currentWidget;
|
|
183
|
+
if (!isEnabled() || !current) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
const context = docManager.contextForWidget(current);
|
|
187
|
+
if (!context) {
|
|
188
|
+
return showDialog({
|
|
189
|
+
title: trans.__('Cannot Download'),
|
|
190
|
+
body: trans.__('No context found for current widget!'),
|
|
191
|
+
buttons: [Dialog.okButton({ label: trans.__('OK') })]
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
downloadContent(context.model.toString(), context.path);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
const category = trans.__('File Operations');
|
|
198
|
+
if (palette) {
|
|
199
|
+
palette.addItem({ command: CommandIDs.docmanagerDownload, category });
|
|
200
|
+
}
|
|
201
|
+
if (mainMenu) {
|
|
202
|
+
mainMenu.fileMenu.addGroup([{ command: CommandIDs.docmanagerDownload }], 6);
|
|
203
|
+
}
|
|
204
|
+
if (factory) {
|
|
205
|
+
const { tracker } = factory;
|
|
206
|
+
const { contents } = serviceManager;
|
|
207
|
+
commands.addCommand(CommandIDs.filebrowserDownload, {
|
|
208
|
+
execute: async () => {
|
|
209
|
+
const widget = tracker.currentWidget;
|
|
210
|
+
if (!widget) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const selected = toArray(widget.selectedItems());
|
|
214
|
+
selected.forEach(async (item) => {
|
|
215
|
+
if (item.type === 'directory') {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const file = await contents.get(item.path, { content: true });
|
|
219
|
+
const formatted = file.type === 'notebook' || file.mimetype.indexOf('json') !== -1
|
|
220
|
+
? JSON.stringify(file.content, null, 2)
|
|
221
|
+
: file.content;
|
|
222
|
+
downloadContent(formatted, item.name);
|
|
223
|
+
});
|
|
224
|
+
},
|
|
225
|
+
icon: downloadIcon.bindprops({ stylesheet: 'menuItem' }),
|
|
226
|
+
label: trans.__('Download')
|
|
227
|
+
});
|
|
228
|
+
contextMenu.addItem({
|
|
229
|
+
command: CommandIDs.filebrowserDownload,
|
|
230
|
+
selector: '.jp-DirListing-item[data-isdir="false"]',
|
|
231
|
+
rank: 9
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* The main application icon.
|
|
238
|
+
*/
|
|
239
|
+
const liteLogo = {
|
|
240
|
+
id: '@jupyterlite/application-extension:logo',
|
|
241
|
+
// marking as optional to not throw errors in retro
|
|
242
|
+
optional: [ILabShell],
|
|
243
|
+
autoStart: true,
|
|
244
|
+
activate: (app, labShell) => {
|
|
245
|
+
if (!labShell) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
const logo = new Widget();
|
|
249
|
+
liteIcon.element({
|
|
250
|
+
container: logo.node,
|
|
251
|
+
elementPosition: 'center',
|
|
252
|
+
margin: '2px 2px 2px 8px',
|
|
253
|
+
height: 'auto',
|
|
254
|
+
width: '16px'
|
|
255
|
+
});
|
|
256
|
+
logo.id = 'jp-MainLogo';
|
|
257
|
+
labShell.add(logo, 'top', { rank: 0 });
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
const plugins = [
|
|
261
|
+
about,
|
|
262
|
+
docProviderPlugin,
|
|
263
|
+
downloadPlugin,
|
|
264
|
+
liteLogo
|
|
265
|
+
];
|
|
266
|
+
export default plugins;
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jupyterlite/application-extension",
|
|
3
|
+
"version": "0.1.0-alpha.10",
|
|
4
|
+
"description": "JupyterLite - 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
|
+
"@jupyterlab/application": "~3.1.12",
|
|
41
|
+
"@jupyterlab/apputils": "~3.1.12",
|
|
42
|
+
"@jupyterlab/docmanager": "~3.1.12",
|
|
43
|
+
"@jupyterlab/docprovider": "~3.1.12",
|
|
44
|
+
"@jupyterlab/filebrowser": "~3.1.12",
|
|
45
|
+
"@jupyterlab/help-extension": "~3.1.12",
|
|
46
|
+
"@jupyterlab/mainmenu": "~3.1.12",
|
|
47
|
+
"@jupyterlab/services": "~6.1.12",
|
|
48
|
+
"@jupyterlab/translation": "~3.1.12",
|
|
49
|
+
"@jupyterlab/ui-components": "~3.1.12",
|
|
50
|
+
"@jupyterlite/ui-components": "^0.1.0-alpha.10",
|
|
51
|
+
"@lumino/algorithm": "^1.6.0",
|
|
52
|
+
"@lumino/coreutils": "^1.8.0",
|
|
53
|
+
"@lumino/widgets": "^1.23.0",
|
|
54
|
+
"y-webrtc": "^10.2.0"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@babel/core": "^7.11.6",
|
|
58
|
+
"@babel/preset-env": "^7.12.1",
|
|
59
|
+
"@types/jest": "^26.0.10",
|
|
60
|
+
"jest": "^26.4.2",
|
|
61
|
+
"rimraf": "~3.0.0",
|
|
62
|
+
"ts-jest": "^26.3.0",
|
|
63
|
+
"typescript": "~4.2.3"
|
|
64
|
+
},
|
|
65
|
+
"publishConfig": {
|
|
66
|
+
"access": "public"
|
|
67
|
+
},
|
|
68
|
+
"jupyterlab": {
|
|
69
|
+
"extension": true
|
|
70
|
+
},
|
|
71
|
+
"styleModule": "style/index.js"
|
|
72
|
+
}
|
package/style/base.css
ADDED
package/style/index.css
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 url('~@jupyterlab/help-extension/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 '@jupyterlab/help-extension/style/index.js';
|
|
7
|
+
|
|
8
|
+
import './base.css';
|