1 |
|
2 |
|
3 | import { PageConfig } from '@jupyterlab/coreutils';
|
4 | import { Base64ModelFactory } from '@jupyterlab/docregistry';
|
5 | import { Token } from '@lumino/coreutils';
|
6 | import { JupyterFrontEnd } from './frontend';
|
7 | import { createRendermimePlugins } from './mimerenderers';
|
8 | import { LabShell } from './shell';
|
9 | import { LabStatus } from './status';
|
10 |
|
11 |
|
12 |
|
13 | export class JupyterLab extends JupyterFrontEnd {
|
14 | |
15 |
|
16 |
|
17 | constructor(options = { shell: new LabShell() }) {
|
18 | super(Object.assign(Object.assign({}, options), { shell: options.shell || new LabShell() }));
|
19 | |
20 |
|
21 |
|
22 | this.name = PageConfig.getOption('appName') || 'JupyterLab';
|
23 | |
24 |
|
25 |
|
26 | this.namespace = PageConfig.getOption('appNamespace') || this.name;
|
27 | |
28 |
|
29 |
|
30 | this.registerPluginErrors = [];
|
31 | |
32 |
|
33 |
|
34 | this.status = new LabStatus(this);
|
35 | |
36 |
|
37 |
|
38 | this.version = PageConfig.getOption('appVersion') || 'unknown';
|
39 | this.restored = this.shell.restored
|
40 | .then(() => undefined)
|
41 | .catch(() => undefined);
|
42 |
|
43 | const info = Object.keys(JupyterLab.defaultInfo).reduce((acc, val) => {
|
44 | if (val in options) {
|
45 | acc[val] = JSON.parse(JSON.stringify(options[val]));
|
46 | }
|
47 | return acc;
|
48 | }, {});
|
49 |
|
50 | this._info = Object.assign(Object.assign({}, JupyterLab.defaultInfo), info);
|
51 |
|
52 | const defaultURLs = JupyterLab.defaultPaths.urls;
|
53 | const defaultDirs = JupyterLab.defaultPaths.directories;
|
54 | const optionURLs = (options.paths && options.paths.urls) || {};
|
55 | const optionDirs = (options.paths && options.paths.directories) || {};
|
56 | this._paths = {
|
57 | urls: Object.keys(defaultURLs).reduce((acc, key) => {
|
58 | if (key in optionURLs) {
|
59 | const value = optionURLs[key];
|
60 | acc[key] = value;
|
61 | }
|
62 | else {
|
63 | acc[key] = defaultURLs[key];
|
64 | }
|
65 | return acc;
|
66 | }, {}),
|
67 | directories: Object.keys(JupyterLab.defaultPaths.directories).reduce((acc, key) => {
|
68 | if (key in optionDirs) {
|
69 | const value = optionDirs[key];
|
70 | acc[key] = value;
|
71 | }
|
72 | else {
|
73 | acc[key] = defaultDirs[key];
|
74 | }
|
75 | return acc;
|
76 | }, {})
|
77 | };
|
78 | if (this._info.devMode) {
|
79 | this.shell.addClass('jp-mod-devMode');
|
80 | }
|
81 |
|
82 | this.docRegistry.addModelFactory(new Base64ModelFactory());
|
83 | if (options.mimeExtensions) {
|
84 | for (const plugin of createRendermimePlugins(options.mimeExtensions)) {
|
85 | this.registerPlugin(plugin);
|
86 | }
|
87 | }
|
88 | }
|
89 | |
90 |
|
91 |
|
92 | get info() {
|
93 | return this._info;
|
94 | }
|
95 | |
96 |
|
97 |
|
98 | get paths() {
|
99 | return this._paths;
|
100 | }
|
101 | |
102 |
|
103 |
|
104 |
|
105 |
|
106 | registerPluginModule(mod) {
|
107 | let data = mod.default;
|
108 |
|
109 | if (!mod.hasOwnProperty('__esModule')) {
|
110 | data = mod;
|
111 | }
|
112 | if (!Array.isArray(data)) {
|
113 | data = [data];
|
114 | }
|
115 | data.forEach(item => {
|
116 | try {
|
117 | this.registerPlugin(item);
|
118 | }
|
119 | catch (error) {
|
120 | this.registerPluginErrors.push(error);
|
121 | }
|
122 | });
|
123 | }
|
124 | |
125 |
|
126 |
|
127 |
|
128 |
|
129 | registerPluginModules(mods) {
|
130 | mods.forEach(mod => {
|
131 | this.registerPluginModule(mod);
|
132 | });
|
133 | }
|
134 | }
|
135 |
|
136 |
|
137 |
|
138 | (function (JupyterLab) {
|
139 | |
140 |
|
141 |
|
142 | JupyterLab.IInfo = new Token('@jupyterlab/application:IInfo');
|
143 | |
144 |
|
145 |
|
146 | JupyterLab.defaultInfo = {
|
147 | devMode: PageConfig.getOption('devMode').toLowerCase() === 'true',
|
148 | deferred: { patterns: [], matches: [] },
|
149 | disabled: { patterns: [], matches: [] },
|
150 | mimeExtensions: [],
|
151 | filesCached: PageConfig.getOption('cacheFiles').toLowerCase() === 'true'
|
152 | };
|
153 | |
154 |
|
155 |
|
156 | JupyterLab.defaultPaths = {
|
157 | urls: {
|
158 | base: PageConfig.getOption('baseUrl'),
|
159 | notFound: PageConfig.getOption('notFoundUrl'),
|
160 | app: PageConfig.getOption('appUrl'),
|
161 | doc: PageConfig.getOption('docUrl'),
|
162 | static: PageConfig.getOption('staticUrl'),
|
163 | settings: PageConfig.getOption('settingsUrl'),
|
164 | themes: PageConfig.getOption('themesUrl'),
|
165 | translations: PageConfig.getOption('translationsApiUrl'),
|
166 | hubHost: PageConfig.getOption('hubHost') || undefined,
|
167 | hubPrefix: PageConfig.getOption('hubPrefix') || undefined,
|
168 | hubUser: PageConfig.getOption('hubUser') || undefined,
|
169 | hubServerName: PageConfig.getOption('hubServerName') || undefined
|
170 | },
|
171 | directories: {
|
172 | appSettings: PageConfig.getOption('appSettingsDir'),
|
173 | schemas: PageConfig.getOption('schemasDir'),
|
174 | static: PageConfig.getOption('staticDir'),
|
175 | templates: PageConfig.getOption('templatesDir'),
|
176 | themes: PageConfig.getOption('themesDir'),
|
177 | userSettings: PageConfig.getOption('userSettingsDir'),
|
178 | serverRoot: PageConfig.getOption('serverRoot'),
|
179 | workspaces: PageConfig.getOption('workspacesDir')
|
180 | }
|
181 | };
|
182 | })(JupyterLab || (JupyterLab = {}));
|
183 |
|
\ | No newline at end of file |