forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
165 lines (142 loc) · 3.54 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import {
Application, IPlugin
} from '@phosphor/application';
import {
ModuleLoader
} from './loader';
import {
ApplicationShell
} from './shell';
export { ModuleLoader } from './loader';
export { ApplicationShell } from './shell';
/**
* The type for all JupyterLab plugins.
*/
export
type JupyterLabPlugin<T> = IPlugin<JupyterLab, T>;
/**
* JupyterLab is the main application class. It is instantiated once and shared.
*/
export
class JupyterLab extends Application<ApplicationShell> {
/**
* Construct a new JupyterLab object.
*/
constructor(options: JupyterLab.IOptions = {}) {
super({ shell: new ApplicationShell() });
this._info = {
gitDescription: options.gitDescription || 'unknown',
namespace: options.namespace || 'jupyterlab',
version: options.version || 'unknown'
};
this._loader = options.loader || null;
}
/**
* The information about the application.
*/
get info(): JupyterLab.IInfo {
return this._info;
}
/**
* The module loader used by the application.
*/
get loader(): ModuleLoader | null {
return this._loader;
}
/**
* Promise that resolves when state is restored, returning layout description.
*
* #### Notes
* This is just a reference to `shell.restored`.
*/
get restored(): Promise<ApplicationShell.ILayout> {
return this.shell.restored;
}
/**
* Register plugins from a plugin module.
*
* @param mod - The plugin module to register.
*/
registerPluginModule(mod: JupyterLab.IPluginModule): void {
let data = mod.default;
if (!Array.isArray(data)) {
data = [data];
}
data.forEach(item => { this.registerPlugin(item); });
}
/**
* Register the plugins from multiple plugin modules.
*
* @param mods - The plugin modules to register.
*/
registerPluginModules(mods: JupyterLab.IPluginModule[]): void {
mods.forEach(mod => { this.registerPluginModule(mod); });
}
private _info: JupyterLab.IInfo;
private _loader: ModuleLoader | null;
}
/**
* The namespace for `JupyterLab` class statics.
*/
export
namespace JupyterLab {
/**
* The options used to initialize a JupyterLab object.
*/
export
interface IOptions {
/**
* The git description of the JupyterLab application.
*/
gitDescription?: string;
/**
* The module loader used by the application.
*/
loader?: ModuleLoader;
/**
* The namespace/prefix plugins may use to denote their origin.
*
* #### Notes
* This field may be used by persistent storage mechanisms such as state
* databases, cookies, session storage, etc.
*
* If unspecified, the default value is `'jupyterlab'`.
*/
namespace?: string;
/**
* The version of the JupyterLab application.
*/
version?: string;
}
/**
* The information about a JupyterLab application.
*/
export
interface IInfo {
/**
* The git description of the JupyterLab application.
*/
readonly gitDescription: string;
/**
* The namespace/prefix plugins may use to denote their origin.
*/
readonly namespace: string;
/**
* The version of the JupyterLab application.
*/
readonly version: string;
}
/**
* The interface for a module that exports a plugin or plugins as
* the default value.
*/
export
interface IPluginModule {
/**
* The default export.
*/
default: JupyterLabPlugin<any> | JupyterLabPlugin<any>[];
}
}