/
index.ts
50 lines (47 loc) · 1.38 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
/**
* @packageDocumentation
* @module docprovider-extension
*/
import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';
import { PageConfig, URLExt } from '@jupyterlab/coreutils';
import {
IDocumentProvider,
IDocumentProviderFactory,
ProviderMock,
WebSocketProviderWithLocks
} from '@jupyterlab/docprovider';
import { ServerConnection } from '@jupyterlab/services';
/**
* The default document provider plugin
*/
const docProviderPlugin: JupyterFrontEndPlugin<IDocumentProviderFactory> = {
id: '@jupyterlab/docprovider-extension:plugin',
provides: IDocumentProviderFactory,
activate: (app: JupyterFrontEnd): IDocumentProviderFactory => {
const server = ServerConnection.makeSettings();
const url = URLExt.join(server.wsUrl, 'api/yjs');
const collaborative =
PageConfig.getOption('collaborative') == 'true' ? true : false;
const factory = (
options: IDocumentProviderFactory.IOptions
): IDocumentProvider => {
return collaborative
? new WebSocketProviderWithLocks({
...options,
url
})
: new ProviderMock();
};
return factory;
}
};
/**
* Export the plugins as default.
*/
const plugins: JupyterFrontEndPlugin<any>[] = [docProviderPlugin];
export default plugins;