@jupyterlite/application-extension 0.1.0-beta.0 → 0.1.0-beta.11
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 +0 -19
- package/lib/index.js +45 -98
- package/package.json +15 -16
package/lib/index.d.ts
CHANGED
|
@@ -1,22 +1,3 @@
|
|
|
1
1
|
import { JupyterFrontEndPlugin } from '@jupyterlab/application';
|
|
2
|
-
import { IDocumentProviderFactory } from '@jupyterlab/docprovider';
|
|
3
|
-
import { Awareness } from 'y-protocols/awareness';
|
|
4
|
-
/**
|
|
5
|
-
* A public namespace for WebRTC options
|
|
6
|
-
*/
|
|
7
|
-
export declare namespace IWebRtcProvider {
|
|
8
|
-
interface IOptions extends IDocumentProviderFactory.IOptions {
|
|
9
|
-
room: string;
|
|
10
|
-
signalingUrls?: string[];
|
|
11
|
-
}
|
|
12
|
-
interface IYjsWebRtcOptions {
|
|
13
|
-
signaling: Array<string>;
|
|
14
|
-
password: string | null;
|
|
15
|
-
awareness: Awareness;
|
|
16
|
-
maxConns: number;
|
|
17
|
-
filterBcConns: boolean;
|
|
18
|
-
peerOpts: any;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
2
|
declare const plugins: JupyterFrontEndPlugin<any>[];
|
|
22
3
|
export default plugins;
|
package/lib/index.js
CHANGED
|
@@ -4,18 +4,15 @@ import { IRouter, ILabShell, } from '@jupyterlab/application';
|
|
|
4
4
|
import { Clipboard, ICommandPalette, Dialog, showDialog } from '@jupyterlab/apputils';
|
|
5
5
|
import { PageConfig, URLExt } from '@jupyterlab/coreutils';
|
|
6
6
|
import { IDocumentManager } from '@jupyterlab/docmanager';
|
|
7
|
-
import { IDocumentProviderFactory, ProviderMock,
|
|
7
|
+
import { IDocumentProviderFactory, ProviderMock, } from '@jupyterlab/docprovider';
|
|
8
8
|
import { IFileBrowserFactory } from '@jupyterlab/filebrowser';
|
|
9
9
|
import { IMainMenu } from '@jupyterlab/mainmenu';
|
|
10
10
|
import { ITranslator } from '@jupyterlab/translation';
|
|
11
11
|
import { downloadIcon, linkIcon } from '@jupyterlab/ui-components';
|
|
12
12
|
import { liteIcon, liteWordmark } from '@jupyterlite/ui-components';
|
|
13
13
|
import { filter, toArray } from '@lumino/algorithm';
|
|
14
|
-
import { UUID, PromiseDelegate } from '@lumino/coreutils';
|
|
15
14
|
import { Widget } from '@lumino/widgets';
|
|
16
15
|
import { getParam } from 'lib0/environment';
|
|
17
|
-
import { WebrtcProvider } from 'y-webrtc';
|
|
18
|
-
import { Awareness } from 'y-protocols/awareness';
|
|
19
16
|
import React from 'react';
|
|
20
17
|
/**
|
|
21
18
|
* The default notebook factory.
|
|
@@ -29,80 +26,6 @@ const EDITOR_FACTORY = 'Editor';
|
|
|
29
26
|
* A regular expression to match path to notebooks, documents and consoles
|
|
30
27
|
*/
|
|
31
28
|
const URL_PATTERN = new RegExp('/(lab|notebooks|edit|consoles)\\/?');
|
|
32
|
-
class WebRtcProvider extends WebrtcProvider {
|
|
33
|
-
constructor(options) {
|
|
34
|
-
super(`${options.room}${options.path}`, options.ymodel.ydoc, WebRtcProvider.yProviderOptions(options));
|
|
35
|
-
this._initialRequest = null;
|
|
36
|
-
this.awareness = options.ymodel.awareness;
|
|
37
|
-
const color = `#${getParam('--usercolor', getRandomColor().slice(1))}`;
|
|
38
|
-
const name = getParam('--username', getAnonymousUserName());
|
|
39
|
-
const currState = this.awareness.getLocalState();
|
|
40
|
-
// only set if this was not already set by another plugin
|
|
41
|
-
if (currState && !currState.name) {
|
|
42
|
-
this.awareness.setLocalStateField('user', {
|
|
43
|
-
name,
|
|
44
|
-
color,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
setPath() {
|
|
49
|
-
// TODO: this seems super useful
|
|
50
|
-
}
|
|
51
|
-
requestInitialContent() {
|
|
52
|
-
if (this._initialRequest) {
|
|
53
|
-
return this._initialRequest.promise;
|
|
54
|
-
}
|
|
55
|
-
let resolved = false;
|
|
56
|
-
this._initialRequest = new PromiseDelegate();
|
|
57
|
-
this.on('synced', (event) => {
|
|
58
|
-
if (this._initialRequest) {
|
|
59
|
-
this._initialRequest.resolve(event.synced);
|
|
60
|
-
resolved = true;
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
// similar logic as in the upstream plugin
|
|
64
|
-
setTimeout(() => {
|
|
65
|
-
if (!resolved && this._initialRequest) {
|
|
66
|
-
this._initialRequest.resolve(false);
|
|
67
|
-
}
|
|
68
|
-
}, 1000);
|
|
69
|
-
return this._initialRequest.promise;
|
|
70
|
-
}
|
|
71
|
-
putInitializedState() {
|
|
72
|
-
// no-op
|
|
73
|
-
}
|
|
74
|
-
acquireLock() {
|
|
75
|
-
return Promise.resolve(0);
|
|
76
|
-
}
|
|
77
|
-
releaseLock(lock) {
|
|
78
|
-
// no-op
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* A private (so far) namespace for Yjs/WebRTC implementation details
|
|
83
|
-
*/
|
|
84
|
-
(function (WebRtcProvider) {
|
|
85
|
-
/**
|
|
86
|
-
* Re-map Lab provider options to yjs ones.
|
|
87
|
-
*/
|
|
88
|
-
function yProviderOptions(options) {
|
|
89
|
-
return {
|
|
90
|
-
signaling: options.signalingUrls && options.signalingUrls.length
|
|
91
|
-
? options.signalingUrls
|
|
92
|
-
: [
|
|
93
|
-
'wss://signaling.yjs.dev',
|
|
94
|
-
'wss://y-webrtc-signaling-eu.herokuapp.com',
|
|
95
|
-
'wss://y-webrtc-signaling-us.herokuapp.com',
|
|
96
|
-
],
|
|
97
|
-
password: null,
|
|
98
|
-
awareness: new Awareness(options.ymodel.ydoc),
|
|
99
|
-
maxConns: 20 + Math.floor(Math.random() * 15),
|
|
100
|
-
filterBcConns: true,
|
|
101
|
-
peerOpts: {}, // simple-peer options. See https://github.com/feross/simple-peer#peer--new-peeropts
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
WebRtcProvider.yProviderOptions = yProviderOptions;
|
|
105
|
-
})(WebRtcProvider || (WebRtcProvider = {}));
|
|
106
29
|
/**
|
|
107
30
|
* The command IDs used by the application extension.
|
|
108
31
|
*/
|
|
@@ -113,6 +36,10 @@ var CommandIDs;
|
|
|
113
36
|
CommandIDs.filebrowserDownload = 'filebrowser:download';
|
|
114
37
|
CommandIDs.copyShareableLink = 'filebrowser:share-main';
|
|
115
38
|
})(CommandIDs || (CommandIDs = {}));
|
|
39
|
+
/**
|
|
40
|
+
* The name of the translation bundle for internationalized strings.
|
|
41
|
+
*/
|
|
42
|
+
const I18N_BUNDLE = 'jupyterlite';
|
|
116
43
|
/**
|
|
117
44
|
* Add a command to show an About dialog.
|
|
118
45
|
*/
|
|
@@ -123,7 +50,7 @@ const about = {
|
|
|
123
50
|
optional: [ICommandPalette, IMainMenu],
|
|
124
51
|
activate: (app, translator, palette, menu) => {
|
|
125
52
|
const { commands } = app;
|
|
126
|
-
const trans = translator.load(
|
|
53
|
+
const trans = translator.load(I18N_BUNDLE);
|
|
127
54
|
const category = trans.__('Help');
|
|
128
55
|
commands.addCommand(CommandIDs.about, {
|
|
129
56
|
label: trans.__('About %1', app.name),
|
|
@@ -141,7 +68,7 @@ const about = {
|
|
|
141
68
|
const externalLinks = (React.createElement("span", { className: "jp-About-externalLinks" },
|
|
142
69
|
React.createElement("a", { href: contributorsURL, target: "_blank", rel: "noopener noreferrer", className: "jp-Button-flat" }, trans.__('CONTRIBUTOR LIST')),
|
|
143
70
|
React.createElement("a", { href: jupyterliteURL, target: "_blank", rel: "noopener noreferrer", className: "jp-Button-flat" }, trans.__('JUPYTERLITE ON GITHUB'))));
|
|
144
|
-
const copyright = (React.createElement("span", { className: "jp-About-copyright" }, trans.__('© 2021 JupyterLite Contributors')));
|
|
71
|
+
const copyright = (React.createElement("span", { className: "jp-About-copyright" }, trans.__('© 2021-2022 JupyterLite Contributors')));
|
|
145
72
|
const body = (React.createElement("div", { className: "jp-About-body" },
|
|
146
73
|
externalLinks,
|
|
147
74
|
copyright));
|
|
@@ -171,22 +98,16 @@ const about = {
|
|
|
171
98
|
const docProviderPlugin = {
|
|
172
99
|
id: '@jupyterlite/application-extension:docprovider',
|
|
173
100
|
provides: IDocumentProviderFactory,
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const
|
|
177
|
-
// enable if both the page config option (deployment wide) and the room name (user) are defined
|
|
178
|
-
const collaborative = PageConfig.getOption('collaborative') === 'true' && roomName;
|
|
179
|
-
const signalingUrls = JSON.parse(PageConfig.getOption('fullWebRtcSignalingUrls') || 'null');
|
|
180
|
-
// default to a random id to not collaborate with others by default
|
|
181
|
-
const room = `${host}-${roomName || UUID.uuid4()}`;
|
|
101
|
+
requires: [ITranslator],
|
|
102
|
+
activate: (app, translator) => {
|
|
103
|
+
const collaborative = PageConfig.getOption('collaborative') === 'true';
|
|
182
104
|
const factory = (options) => {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
: new ProviderMock();
|
|
105
|
+
if (collaborative) {
|
|
106
|
+
const trans = translator.load(I18N_BUNDLE);
|
|
107
|
+
console.warn(trans.__('The `collaborative` feature was enabled, but no docprovider is available.'));
|
|
108
|
+
console.info(trans.__('Install `jupyterlab-webrtc-docprovider` to enable WebRTC-based collaboration.'));
|
|
109
|
+
}
|
|
110
|
+
return new ProviderMock();
|
|
190
111
|
};
|
|
191
112
|
return factory;
|
|
192
113
|
},
|
|
@@ -200,7 +121,7 @@ const downloadPlugin = {
|
|
|
200
121
|
requires: [ITranslator, IDocumentManager],
|
|
201
122
|
optional: [ICommandPalette, IFileBrowserFactory],
|
|
202
123
|
activate: (app, translator, docManager, palette, factory) => {
|
|
203
|
-
const trans = translator.load(
|
|
124
|
+
const trans = translator.load(I18N_BUNDLE);
|
|
204
125
|
const { commands, serviceManager, shell } = app;
|
|
205
126
|
const { contents } = serviceManager;
|
|
206
127
|
const isEnabled = () => {
|
|
@@ -240,6 +161,7 @@ const downloadPlugin = {
|
|
|
240
161
|
buttons: [Dialog.okButton({ label: trans.__('OK') })],
|
|
241
162
|
});
|
|
242
163
|
}
|
|
164
|
+
await context.save();
|
|
243
165
|
const content = await formatContent(context.path);
|
|
244
166
|
downloadContent(content, context.path);
|
|
245
167
|
},
|
|
@@ -295,6 +217,21 @@ const liteLogo = {
|
|
|
295
217
|
labShell.add(logo, 'top', { rank: 0 });
|
|
296
218
|
},
|
|
297
219
|
};
|
|
220
|
+
/**
|
|
221
|
+
* A plugin to trigger a refresh of the commands when the shell layout changes.
|
|
222
|
+
*/
|
|
223
|
+
const notifyCommands = {
|
|
224
|
+
id: '@jupyterlite/application-extension:notify-commands',
|
|
225
|
+
autoStart: true,
|
|
226
|
+
optional: [ILabShell],
|
|
227
|
+
activate: (app, labShell) => {
|
|
228
|
+
if (labShell) {
|
|
229
|
+
labShell.layoutModified.connect(() => {
|
|
230
|
+
app.commands.notifyCommandChanged();
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
};
|
|
298
235
|
/**
|
|
299
236
|
* A custom opener plugin to pass the path to documents as
|
|
300
237
|
* query string parameters.
|
|
@@ -303,7 +240,8 @@ const opener = {
|
|
|
303
240
|
id: '@jupyterlite/application-extension:opener',
|
|
304
241
|
autoStart: true,
|
|
305
242
|
requires: [IRouter, IDocumentManager],
|
|
306
|
-
|
|
243
|
+
optional: [ILabShell],
|
|
244
|
+
activate: (app, router, docManager, labShell) => {
|
|
307
245
|
const { commands } = app;
|
|
308
246
|
const command = 'router:tree';
|
|
309
247
|
commands.addCommand(command, {
|
|
@@ -350,6 +288,14 @@ const opener = {
|
|
|
350
288
|
url.searchParams.delete('path');
|
|
351
289
|
const { pathname, search } = url;
|
|
352
290
|
router.navigate(`${pathname}${search}`, { skipRouting: true });
|
|
291
|
+
if (labShell) {
|
|
292
|
+
// open the folder where the files are located on startup
|
|
293
|
+
const showInBrowser = () => {
|
|
294
|
+
commands.execute('docmanager:show-in-file-browser');
|
|
295
|
+
labShell.currentChanged.disconnect(showInBrowser);
|
|
296
|
+
};
|
|
297
|
+
labShell.currentChanged.connect(showInBrowser);
|
|
298
|
+
}
|
|
353
299
|
break;
|
|
354
300
|
}
|
|
355
301
|
}
|
|
@@ -371,7 +317,7 @@ const shareFile = {
|
|
|
371
317
|
requires: [IFileBrowserFactory, ITranslator],
|
|
372
318
|
autoStart: true,
|
|
373
319
|
activate: (app, factory, translator) => {
|
|
374
|
-
const trans = translator.load(
|
|
320
|
+
const trans = translator.load(I18N_BUNDLE);
|
|
375
321
|
const { commands } = app;
|
|
376
322
|
const { tracker } = factory;
|
|
377
323
|
const roomName = getParam('--room', '').trim();
|
|
@@ -404,6 +350,7 @@ const plugins = [
|
|
|
404
350
|
docProviderPlugin,
|
|
405
351
|
downloadPlugin,
|
|
406
352
|
liteLogo,
|
|
353
|
+
notifyCommands,
|
|
407
354
|
opener,
|
|
408
355
|
shareFile,
|
|
409
356
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyterlite/application-extension",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.11",
|
|
4
4
|
"description": "JupyterLite - Application Extension",
|
|
5
5
|
"homepage": "https://github.com/jupyterlite/jupyterlite",
|
|
6
6
|
"bugs": {
|
|
@@ -37,21 +37,20 @@
|
|
|
37
37
|
"watch": "tsc -b --watch"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@jupyterlab/application": "~3.
|
|
41
|
-
"@jupyterlab/apputils": "~3.
|
|
42
|
-
"@jupyterlab/docmanager": "~3.
|
|
43
|
-
"@jupyterlab/docprovider": "~3.
|
|
44
|
-
"@jupyterlab/filebrowser": "~3.
|
|
45
|
-
"@jupyterlab/help-extension": "~3.
|
|
46
|
-
"@jupyterlab/mainmenu": "~3.
|
|
47
|
-
"@jupyterlab/services": "~6.
|
|
48
|
-
"@jupyterlab/translation": "~3.
|
|
49
|
-
"@jupyterlab/ui-components": "~3.
|
|
50
|
-
"@jupyterlite/ui-components": "^0.1.0-beta.
|
|
51
|
-
"@lumino/algorithm": "^1.
|
|
52
|
-
"@lumino/coreutils": "^1.
|
|
53
|
-
"@lumino/widgets": "^1.
|
|
54
|
-
"y-webrtc": "^10.2.0"
|
|
40
|
+
"@jupyterlab/application": "~3.4.3",
|
|
41
|
+
"@jupyterlab/apputils": "~3.4.3",
|
|
42
|
+
"@jupyterlab/docmanager": "~3.4.3",
|
|
43
|
+
"@jupyterlab/docprovider": "~3.4.3",
|
|
44
|
+
"@jupyterlab/filebrowser": "~3.4.3",
|
|
45
|
+
"@jupyterlab/help-extension": "~3.4.3",
|
|
46
|
+
"@jupyterlab/mainmenu": "~3.4.3",
|
|
47
|
+
"@jupyterlab/services": "~6.4.3",
|
|
48
|
+
"@jupyterlab/translation": "~3.4.3",
|
|
49
|
+
"@jupyterlab/ui-components": "~3.4.3",
|
|
50
|
+
"@jupyterlite/ui-components": "^0.1.0-beta.11",
|
|
51
|
+
"@lumino/algorithm": "^1.9.1",
|
|
52
|
+
"@lumino/coreutils": "^1.12.0",
|
|
53
|
+
"@lumino/widgets": "^1.31.1"
|
|
55
54
|
},
|
|
56
55
|
"devDependencies": {
|
|
57
56
|
"@babel/core": "^7.11.6",
|