@jupyterlite/application-extension 0.1.0-beta.3 → 0.1.0-beta.6
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 +27 -97
- package/package.json +3 -4
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),
|
|
@@ -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 = () => {
|
|
@@ -318,7 +239,8 @@ const opener = {
|
|
|
318
239
|
id: '@jupyterlite/application-extension:opener',
|
|
319
240
|
autoStart: true,
|
|
320
241
|
requires: [IRouter, IDocumentManager],
|
|
321
|
-
|
|
242
|
+
optional: [ILabShell],
|
|
243
|
+
activate: (app, router, docManager, labShell) => {
|
|
322
244
|
const { commands } = app;
|
|
323
245
|
const command = 'router:tree';
|
|
324
246
|
commands.addCommand(command, {
|
|
@@ -365,6 +287,14 @@ const opener = {
|
|
|
365
287
|
url.searchParams.delete('path');
|
|
366
288
|
const { pathname, search } = url;
|
|
367
289
|
router.navigate(`${pathname}${search}`, { skipRouting: true });
|
|
290
|
+
if (labShell) {
|
|
291
|
+
// open the folder where the files are located on startup
|
|
292
|
+
const showInBrowser = () => {
|
|
293
|
+
commands.execute('docmanager:show-in-file-browser');
|
|
294
|
+
labShell.currentChanged.disconnect(showInBrowser);
|
|
295
|
+
};
|
|
296
|
+
labShell.currentChanged.connect(showInBrowser);
|
|
297
|
+
}
|
|
368
298
|
break;
|
|
369
299
|
}
|
|
370
300
|
}
|
|
@@ -386,7 +316,7 @@ const shareFile = {
|
|
|
386
316
|
requires: [IFileBrowserFactory, ITranslator],
|
|
387
317
|
autoStart: true,
|
|
388
318
|
activate: (app, factory, translator) => {
|
|
389
|
-
const trans = translator.load(
|
|
319
|
+
const trans = translator.load(I18N_BUNDLE);
|
|
390
320
|
const { commands } = app;
|
|
391
321
|
const { tracker } = factory;
|
|
392
322
|
const roomName = getParam('--room', '').trim();
|
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.6",
|
|
4
4
|
"description": "JupyterLite - Application Extension",
|
|
5
5
|
"homepage": "https://github.com/jupyterlite/jupyterlite",
|
|
6
6
|
"bugs": {
|
|
@@ -47,11 +47,10 @@
|
|
|
47
47
|
"@jupyterlab/services": "~6.3.2",
|
|
48
48
|
"@jupyterlab/translation": "~3.3.2",
|
|
49
49
|
"@jupyterlab/ui-components": "~3.3.2",
|
|
50
|
-
"@jupyterlite/ui-components": "^0.1.0-beta.
|
|
50
|
+
"@jupyterlite/ui-components": "^0.1.0-beta.6",
|
|
51
51
|
"@lumino/algorithm": "^1.9.1",
|
|
52
52
|
"@lumino/coreutils": "^1.12.0",
|
|
53
|
-
"@lumino/widgets": "^1.31.1"
|
|
54
|
-
"y-webrtc": "^10.2.0"
|
|
53
|
+
"@lumino/widgets": "^1.31.1"
|
|
55
54
|
},
|
|
56
55
|
"devDependencies": {
|
|
57
56
|
"@babel/core": "^7.11.6",
|