1 | import { CommandRegistry } from '@phosphor/commands';
|
2 | import { Token } from '@phosphor/coreutils';
|
3 | import { ContextMenu, Menu, Widget } from '@phosphor/widgets';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | export interface IPlugin<T, U> {
|
19 | |
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | id: string;
|
26 | |
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | autoStart?: boolean;
|
33 | |
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | requires?: Token<any>[];
|
45 | |
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | optional?: Token<any>[];
|
57 | |
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | provides?: Token<U>;
|
67 | |
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | activate: (app: T, ...args: any[]) => U | Promise<U>;
|
85 | }
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | export declare class Application<T extends Widget> {
|
95 | |
96 |
|
97 |
|
98 |
|
99 |
|
100 | constructor(options: Application.IOptions<T>);
|
101 | /**
|
102 | * The application command registry.
|
103 | */
|
104 | readonly commands: CommandRegistry;
|
105 | /**
|
106 | * The application context menu.
|
107 | */
|
108 | readonly contextMenu: ContextMenu;
|
109 | /**
|
110 | * The application shell widget.
|
111 | *
|
112 | * #### Notes
|
113 | * The shell widget is the root "container" widget for the entire
|
114 | * application. It will typically expose an API which allows the
|
115 | * application plugins to insert content in a variety of places.
|
116 | */
|
117 | readonly shell: T;
|
118 | /**
|
119 | * A promise which resolves after the application has started.
|
120 | *
|
121 | * #### Notes
|
122 | * This promise will resolve after the `start()` method is called,
|
123 | * when all the bootstrapping and shell mounting work is complete.
|
124 | */
|
125 | readonly started: Promise<void>;
|
126 | /**
|
127 | * Test whether a plugin is registered with the application.
|
128 | *
|
129 | * @param id - The id of the plugin of interest.
|
130 | *
|
131 | * @returns `true` if the plugin is registered, `false` otherwise.
|
132 | */
|
133 | hasPlugin(id: string): boolean;
|
134 | /**
|
135 | * List the IDs of the plugins registered with the application.
|
136 | *
|
137 | * @returns A new array of the registered plugin IDs.
|
138 | */
|
139 | listPlugins(): string[];
|
140 | /**
|
141 | * Register a plugin with the application.
|
142 | *
|
143 | * @param plugin - The plugin to register.
|
144 | *
|
145 | * #### Notes
|
146 | * An error will be thrown if a plugin with the same id is already
|
147 | * registered, or if the plugin has a circular dependency.
|
148 | *
|
149 | * If the plugin provides a service which has already been provided
|
150 | * by another plugin, the new service will override the old service.
|
151 | */
|
152 | registerPlugin(plugin: IPlugin<this, any>): void;
|
153 | /**
|
154 | * Register multiple plugins with the application.
|
155 | *
|
156 | * @param plugins - The plugins to register.
|
157 | *
|
158 | * #### Notes
|
159 | * This calls `registerPlugin()` for each of the given plugins.
|
160 | */
|
161 | registerPlugins(plugins: IPlugin<this, any>[]): void;
|
162 | /**
|
163 | * Activate the plugin with the given id.
|
164 | *
|
165 | * @param id - The ID of the plugin of interest.
|
166 | *
|
167 | * @returns A promise which resolves when the plugin is activated
|
168 | * or rejects with an error if it cannot be activated.
|
169 | */
|
170 | activatePlugin(id: string): Promise<void>;
|
171 | /**
|
172 | * Resolve a required service of a given type.
|
173 | *
|
174 | * @param token - The token for the service type of interest.
|
175 | *
|
176 | * @returns A promise which resolves to an instance of the requested
|
177 | * service, or rejects with an error if it cannot be resolved.
|
178 | *
|
179 | * #### Notes
|
180 | * Services are singletons. The same instance will be returned each
|
181 | * time a given service token is resolved.
|
182 | *
|
183 | * If the plugin which provides the service has not been activated,
|
184 | * resolving the service will automatically activate the plugin.
|
185 | *
|
186 | * User code will not typically call this method directly. Instead,
|
187 | * the required services for the user's plugins will be resolved
|
188 | * automatically when the plugin is activated.
|
189 | */
|
190 | resolveRequiredService<U>(token: Token<U>): Promise<U>;
|
191 | /**
|
192 | * Resolve an optional service of a given type.
|
193 | *
|
194 | * @param token - The token for the service type of interest.
|
195 | *
|
196 | * @returns A promise which resolves to an instance of the requested
|
197 | * service, or `null` if it cannot be resolved.
|
198 | *
|
199 | * #### Notes
|
200 | * Services are singletons. The same instance will be returned each
|
201 | * time a given service token is resolved.
|
202 | *
|
203 | * If the plugin which provides the service has not been activated,
|
204 | * resolving the service will automatically activate the plugin.
|
205 | *
|
206 | * User code will not typically call this method directly. Instead,
|
207 | * the optional services for the user's plugins will be resolved
|
208 | * automatically when the plugin is activated.
|
209 | */
|
210 | resolveOptionalService<U>(token: Token<U>): Promise<U | null>;
|
211 | /**
|
212 | * Start the application.
|
213 | *
|
214 | * @param options - The options for starting the application.
|
215 | *
|
216 | * @returns A promise which resolves when all bootstrapping work
|
217 | * is complete and the shell is mounted to the DOM.
|
218 | *
|
219 | * #### Notes
|
220 | * This should be called once by the application creator after all
|
221 | * initial plugins have been registered.
|
222 | *
|
223 | * If a plugin fails to the load, the error will be logged and the
|
224 | * other valid plugins will continue to be loaded.
|
225 | *
|
226 | * Bootstrapping the application consists of the following steps:
|
227 | * 1. Activate the startup plugins
|
228 | * 2. Wait for those plugins to activate
|
229 | * 3. Attach the shell widget to the DOM
|
230 | * 4. Add the application event listeners
|
231 | */
|
232 | start(options?: Application.IStartOptions): Promise<void>;
|
233 | /**
|
234 | * Handle the DOM events for the application.
|
235 | *
|
236 | * @param event - The DOM event sent to the application.
|
237 | *
|
238 | * #### Notes
|
239 | * This method implements the DOM `EventListener` interface and is
|
240 | * called in response to events registered for the application. It
|
241 | * should not be called directly by user code.
|
242 | */
|
243 | handleEvent(event: Event): void;
|
244 | /**
|
245 | * Attach the application shell to the DOM.
|
246 | *
|
247 | * @param id - The id of the host node for the shell, or `''`.
|
248 | *
|
249 | * #### Notes
|
250 | * If the id is not provided, the document body will be the host.
|
251 | *
|
252 | * A subclass may reimplement this method as needed.
|
253 | */
|
254 | protected attachShell(id: string): void;
|
255 | /**
|
256 | * Add the application event listeners.
|
257 | *
|
258 | * #### Notes
|
259 | * The default implementation of this method adds listeners for
|
260 | * `'keydown'` and `'resize'` events.
|
261 | *
|
262 | * A subclass may reimplement this method as needed.
|
263 | */
|
264 | protected addEventListeners(): void;
|
265 | /**
|
266 | * A method invoked on a document `'keydown'` event.
|
267 | *
|
268 | * #### Notes
|
269 | * The default implementation of this method invokes the key down
|
270 | * processing method of the application command registry.
|
271 | *
|
272 | * A subclass may reimplement this method as needed.
|
273 | */
|
274 | protected evtKeydown(event: KeyboardEvent): void;
|
275 | /**
|
276 | * A method invoked on a document `'contextmenu'` event.
|
277 | *
|
278 | * #### Notes
|
279 | * The default implementation of this method opens the application
|
280 | * `contextMenu` at the current mouse position.
|
281 | *
|
282 | * If the application context menu has no matching content *or* if
|
283 | * the shift key is pressed, the default browser context menu will
|
284 | * be opened instead.
|
285 | *
|
286 | * A subclass may reimplement this method as needed.
|
287 | */
|
288 | protected evtContextMenu(event: MouseEvent): void;
|
289 | /**
|
290 | * A method invoked on a window `'resize'` event.
|
291 | *
|
292 | * #### Notes
|
293 | * The default implementation of this method updates the shell.
|
294 | *
|
295 | * A subclass may reimplement this method as needed.
|
296 | */
|
297 | protected evtResize(event: Event): void;
|
298 | private _started;
|
299 | private _pluginMap;
|
300 | private _serviceMap;
|
301 | private _delegate;
|
302 | }
|
303 | /**
|
304 | * The namespace for the `Application` class statics.
|
305 | */
|
306 | export declare namespace Application {
|
307 | |
308 |
|
309 |
|
310 | interface IOptions<T extends Widget> {
|
311 | |
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 | shell: T;
|
319 | |
320 |
|
321 |
|
322 | contextMenuRenderer?: Menu.IRenderer;
|
323 | }
|
324 | |
325 |
|
326 |
|
327 | interface IStartOptions {
|
328 | |
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 | hostID?: string;
|
335 | |
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 | startPlugins?: string[];
|
342 | |
343 |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 | ignorePlugins?: string[];
|
349 | }
|
350 | }
|