UNPKG

16.3 kBTypeScriptView Raw
1import { DocumentRegistry } from '@jupyterlab/docregistry';
2import { ITranslator } from '@jupyterlab/translation';
3import { Token } from '@lumino/coreutils';
4import { Message } from '@lumino/messaging';
5import { ISignal } from '@lumino/signaling';
6import { DockLayout, DockPanel, FocusTracker, TabBar, Widget } from '@lumino/widgets';
7import { JupyterFrontEnd } from './frontend';
8import { LayoutRestorer } from './layoutrestorer';
9/**
10 * The JupyterLab application shell token.
11 */
12export declare const ILabShell: Token<ILabShell>;
13/**
14 * The JupyterLab application shell interface.
15 */
16export interface ILabShell extends LabShell {
17}
18/**
19 * The namespace for `ILabShell` type information.
20 */
21export declare namespace ILabShell {
22 /**
23 * The areas of the application shell where widgets can reside.
24 */
25 type Area = 'main' | 'header' | 'top' | 'menu' | 'left' | 'right' | 'bottom' | 'down';
26 /**
27 * The restorable description of an area within the main dock panel.
28 */
29 type AreaConfig = DockLayout.AreaConfig;
30 /**
31 * An options object for creating a lab shell object.
32 */
33 type IOptions = {
34 /**
35 * Whether the layout should wait to be restored before adding widgets or not.
36 *
37 * #### Notes
38 * It defaults to true
39 */
40 waitForRestore?: boolean;
41 };
42 /**
43 * An arguments object for the changed signals.
44 */
45 type IChangedArgs = FocusTracker.IChangedArgs<Widget>;
46 interface IConfig {
47 /**
48 * The method for hiding widgets in the dock panel.
49 *
50 * The default is `display`.
51 *
52 * Using `scale` will often increase performance as most browsers will not trigger style computation
53 * for the transform action.
54 *
55 * `contentVisibility` is only available in Chromium-based browsers.
56 */
57 hiddenMode: 'display' | 'scale' | 'contentVisibility';
58 }
59 /**
60 * Widget position
61 */
62 interface IWidgetPosition {
63 /**
64 * Widget area
65 */
66 area?: Area;
67 /**
68 * Widget opening options
69 */
70 options?: DocumentRegistry.IOpenOptions;
71 }
72 /**
73 * To-be-added widget and associated position
74 */
75 interface IDelayedWidget extends IWidgetPosition {
76 widget: Widget;
77 }
78 /**
79 * Mapping of widget type identifier and their user customized position
80 */
81 interface IUserLayout {
82 /**
83 * Widget customized position
84 */
85 [k: string]: IWidgetPosition;
86 }
87 /**
88 * The args for the current path change signal.
89 */
90 interface ICurrentPathChangedArgs {
91 /**
92 * The new value of the tree path, not including '/tree'.
93 */
94 oldValue: string;
95 /**
96 * The old value of the tree path, not including '/tree'.
97 */
98 newValue: string;
99 }
100 /**
101 * A description of the application's user interface layout.
102 */
103 interface ILayout {
104 /**
105 * Indicates whether fetched session restore data was actually retrieved
106 * from the state database or whether it is a fresh blank slate.
107 *
108 * #### Notes
109 * This attribute is only relevant when the layout data is retrieved via a
110 * `fetch` call. If it is set when being passed into `save`, it will be
111 * ignored.
112 */
113 readonly fresh?: boolean;
114 /**
115 * The main area of the user interface.
116 */
117 readonly mainArea: IMainArea | null;
118 /**
119 * The down area of the user interface.
120 */
121 readonly downArea: IDownArea | null;
122 /**
123 * The left area of the user interface.
124 */
125 readonly leftArea: ISideArea | null;
126 /**
127 * The right area of the user interface.
128 */
129 readonly rightArea: ISideArea | null;
130 /**
131 * The top area of the user interface.
132 */
133 readonly topArea: ITopArea | null;
134 /**
135 * The relatives sizes of the areas of the user interface.
136 */
137 readonly relativeSizes: number[] | null;
138 }
139 /**
140 * The restorable description of the main application area.
141 */
142 interface IMainArea {
143 /**
144 * The current widget that has application focus.
145 */
146 readonly currentWidget: Widget | null;
147 /**
148 * The contents of the main application dock panel.
149 */
150 readonly dock: DockLayout.ILayoutConfig | null;
151 }
152 interface IDownArea {
153 /**
154 * The current widget that has down area focus.
155 */
156 readonly currentWidget: Widget | null;
157 /**
158 * The collection of widgets held by the panel.
159 */
160 readonly widgets: Array<Widget> | null;
161 /**
162 * Vertical relative size of the down area
163 *
164 * The main area will take the rest of the height
165 */
166 readonly size: number | null;
167 }
168 /**
169 * The restorable description of a sidebar in the user interface.
170 */
171 interface ISideArea {
172 /**
173 * A flag denoting whether the sidebar has been collapsed.
174 */
175 readonly collapsed: boolean;
176 /**
177 * The current widget that has side area focus.
178 */
179 readonly currentWidget: Widget | null;
180 /**
181 * A flag denoting whether the side tab bar is visible.
182 */
183 readonly visible: boolean;
184 /**
185 * The collection of widgets held by the sidebar.
186 */
187 readonly widgets: Array<Widget> | null;
188 /**
189 * The collection of widgets states held by the sidebar.
190 */
191 readonly widgetStates: {
192 [id: string]: {
193 /**
194 * Vertical sizes of the widgets.
195 */
196 readonly sizes: Array<number> | null;
197 /**
198 * Expansion states of the widgets.
199 */
200 readonly expansionStates: Array<boolean> | null;
201 };
202 };
203 }
204}
205/**
206 * The restorable description of the top area in the user interface.
207 */
208export interface ITopArea {
209 /**
210 * Top area visibility in simple mode.
211 */
212 readonly simpleVisibility: boolean;
213}
214/**
215 * The application shell for JupyterLab.
216 */
217export declare class LabShell extends Widget implements JupyterFrontEnd.IShell {
218 /**
219 * Construct a new application shell.
220 */
221 constructor(options?: ILabShell.IOptions);
222 /**
223 * A signal emitted when main area's active focus changes.
224 */
225 get activeChanged(): ISignal<this, ILabShell.IChangedArgs>;
226 /**
227 * The active widget in the shell's main area.
228 */
229 get activeWidget(): Widget | null;
230 /**
231 * Whether the add buttons for each main area tab bar are enabled.
232 */
233 get addButtonEnabled(): boolean;
234 set addButtonEnabled(value: boolean);
235 /**
236 * A signal emitted when the add button on a main area tab bar is clicked.
237 */
238 get addRequested(): ISignal<DockPanel, TabBar<Widget>>;
239 /**
240 * A signal emitted when main area's current focus changes.
241 */
242 get currentChanged(): ISignal<this, ILabShell.IChangedArgs>;
243 /**
244 * Current document path.
245 */
246 get currentPath(): string | null | undefined;
247 /**
248 * A signal emitted when the path of the current document changes.
249 *
250 * This also fires when the current document itself changes.
251 */
252 get currentPathChanged(): ISignal<this, ILabShell.ICurrentPathChangedArgs>;
253 /**
254 * The current widget in the shell's main area.
255 */
256 get currentWidget(): Widget | null;
257 /**
258 * A signal emitted when the main area's layout is modified.
259 */
260 get layoutModified(): ISignal<this, void>;
261 /**
262 * Whether the left area is collapsed.
263 */
264 get leftCollapsed(): boolean;
265 /**
266 * Whether the left area is collapsed.
267 */
268 get rightCollapsed(): boolean;
269 /**
270 * Whether JupyterLab is in presentation mode with the
271 * `jp-mod-presentationMode` CSS class.
272 */
273 get presentationMode(): boolean;
274 set presentationMode(value: boolean);
275 /**
276 * The main dock area's user interface mode.
277 */
278 get mode(): DockPanel.Mode;
279 set mode(mode: DockPanel.Mode);
280 /**
281 * A signal emitted when the shell/dock panel change modes (single/multiple document).
282 */
283 get modeChanged(): ISignal<this, DockPanel.Mode>;
284 /**
285 * Promise that resolves when state is first restored, returning layout
286 * description.
287 */
288 get restored(): Promise<ILabShell.ILayout>;
289 get translator(): ITranslator;
290 set translator(value: ITranslator);
291 /**
292 * User customized shell layout.
293 */
294 get userLayout(): {
295 'single-document': ILabShell.IUserLayout;
296 'multiple-document': ILabShell.IUserLayout;
297 };
298 /**
299 * Activate a widget in its area.
300 */
301 activateById(id: string): void;
302 /**
303 * Activate widget in specified area.
304 *
305 * ### Notes
306 * The alpha version of this method only supports activating the "main" area.
307 *
308 * @alpha
309 * @param area Name of area to activate
310 */
311 activateArea(area?: ILabShell.Area): void;
312 /**
313 * Activate the next Tab in the active TabBar.
314 */
315 activateNextTab(): void;
316 /**
317 * Activate the previous Tab in the active TabBar.
318 */
319 activatePreviousTab(): void;
320 /**
321 * Activate the next TabBar.
322 */
323 activateNextTabBar(): void;
324 /**
325 * Activate the next TabBar.
326 */
327 activatePreviousTabBar(): void;
328 /**
329 * Add a widget to the JupyterLab shell
330 *
331 * @param widget Widget
332 * @param area Area
333 * @param options Options
334 */
335 add(widget: Widget, area?: ILabShell.Area, options?: DocumentRegistry.IOpenOptions): void;
336 /**
337 * Move a widget type to a new area.
338 *
339 * The type is determined from the `widget.id` and fallback to `widget.id`.
340 *
341 * #### Notes
342 * If `mode` is undefined, both mode are updated.
343 * The new layout is now persisted.
344 *
345 * @param widget Widget to move
346 * @param area New area
347 * @param mode Mode to change
348 * @returns The new user layout
349 */
350 move(widget: Widget, area: ILabShell.Area, mode?: DockPanel.Mode): {
351 'single-document': ILabShell.IUserLayout;
352 'multiple-document': ILabShell.IUserLayout;
353 };
354 /**
355 * Collapse the left area.
356 */
357 collapseLeft(): void;
358 /**
359 * Collapse the right area.
360 */
361 collapseRight(): void;
362 /**
363 * Dispose the shell.
364 */
365 dispose(): void;
366 /**
367 * Expand the left area.
368 *
369 * #### Notes
370 * This will open the most recently used tab,
371 * or the first tab if there is no most recently used.
372 */
373 expandLeft(): void;
374 /**
375 * Expand the right area.
376 *
377 * #### Notes
378 * This will open the most recently used tab,
379 * or the first tab if there is no most recently used.
380 */
381 expandRight(): void;
382 /**
383 * Close all widgets in the main and down area.
384 */
385 closeAll(): void;
386 /**
387 * Whether an side tab bar is visible or not.
388 *
389 * @param side Sidebar of interest
390 * @returns Side tab bar visibility
391 */
392 isSideTabBarVisible(side: 'left' | 'right'): boolean;
393 /**
394 * Whether the top bar in simple mode is visible or not.
395 *
396 * @returns Top bar visibility
397 */
398 isTopInSimpleModeVisible(): boolean;
399 /**
400 * True if the given area is empty.
401 */
402 isEmpty(area: ILabShell.Area): boolean;
403 /**
404 * Restore the layout state and configuration for the application shell.
405 *
406 * #### Notes
407 * This should only be called once.
408 */
409 restoreLayout(mode: DockPanel.Mode, layoutRestorer: LayoutRestorer, configuration?: {
410 [m: string]: ILabShell.IUserLayout;
411 }): Promise<void>;
412 /**
413 * Save the dehydrated state of the application shell.
414 */
415 saveLayout(): ILabShell.ILayout;
416 /**
417 * Toggle top header visibility in simple mode
418 *
419 * Note: Does nothing in multi-document mode
420 */
421 toggleTopInSimpleModeVisibility(): void;
422 /**
423 * Toggle side tab bar visibility
424 *
425 * @param side Sidebar of interest
426 */
427 toggleSideTabBarVisibility(side: 'right' | 'left'): void;
428 /**
429 * Update the shell configuration.
430 *
431 * @param config Shell configuration
432 */
433 updateConfig(config: Partial<ILabShell.IConfig>): void;
434 /**
435 * Returns the widgets for an application area.
436 */
437 widgets(area?: ILabShell.Area): IterableIterator<Widget>;
438 /**
439 * Handle `after-attach` messages for the application shell.
440 */
441 protected onAfterAttach(msg: Message): void;
442 /**
443 * Update the title panel title based on the title of the current widget.
444 */
445 private _updateTitlePanelTitle;
446 /**
447 * The path of the current widget changed, fire the _currentPathChanged signal.
448 */
449 private _updateCurrentPath;
450 /**
451 * Add a widget to the left content area.
452 *
453 * #### Notes
454 * Widgets must have a unique `id` property, which will be used as the DOM id.
455 */
456 private _addToLeftArea;
457 /**
458 * Add a widget to the main content area.
459 *
460 * #### Notes
461 * Widgets must have a unique `id` property, which will be used as the DOM id.
462 * All widgets added to the main area should be disposed after removal
463 * (disposal before removal will remove the widget automatically).
464 *
465 * In the options, `ref` defaults to `null`, `mode` defaults to `'tab-after'`,
466 * and `activate` defaults to `true`.
467 */
468 private _addToMainArea;
469 /**
470 * Add a widget to the right content area.
471 *
472 * #### Notes
473 * Widgets must have a unique `id` property, which will be used as the DOM id.
474 */
475 private _addToRightArea;
476 /**
477 * Add a widget to the top content area.
478 *
479 * #### Notes
480 * Widgets must have a unique `id` property, which will be used as the DOM id.
481 */
482 private _addToTopArea;
483 /**
484 * Add a widget to the title content area.
485 *
486 * #### Notes
487 * Widgets must have a unique `id` property, which will be used as the DOM id.
488 */
489 private _addToMenuArea;
490 /**
491 * Add a widget to the header content area.
492 *
493 * #### Notes
494 * Widgets must have a unique `id` property, which will be used as the DOM id.
495 */
496 private _addToHeaderArea;
497 /**
498 * Add a widget to the bottom content area.
499 *
500 * #### Notes
501 * Widgets must have a unique `id` property, which will be used as the DOM id.
502 */
503 private _addToBottomArea;
504 private _addToDownArea;
505 private _adjacentBar;
506 private _currentTabBar;
507 /**
508 * Handle a change to the dock area active widget.
509 */
510 private _onActiveChanged;
511 /**
512 * Handle a change to the dock area current widget.
513 */
514 private _onCurrentChanged;
515 /**
516 * Handle a change on the down panel widgets
517 */
518 private _onTabPanelChanged;
519 /**
520 * Handle a change to the layout.
521 */
522 private _onLayoutModified;
523 /**
524 * A message hook for child add/remove messages on the main area dock panel.
525 */
526 private _dockChildHook;
527 private _activeChanged;
528 private _cachedLayout;
529 private _currentChanged;
530 private _currentPath;
531 private _currentPathChanged;
532 private _modeChanged;
533 private _dockPanel;
534 private _downPanel;
535 private _isRestored;
536 private _layoutModified;
537 private _layoutDebouncer;
538 private _leftHandler;
539 private _restored;
540 private _rightHandler;
541 private _tracker;
542 private _headerPanel;
543 private _hsplitPanel;
544 private _vsplitPanel;
545 private _topHandler;
546 private _topHandlerHiddenByUser;
547 private _menuHandler;
548 private _skipLinkWidget;
549 private _titleHandler;
550 private _bottomPanel;
551 private _idTypeMap;
552 private _mainOptionsCache;
553 private _sideOptionsCache;
554 private _userLayout;
555 private _delayedWidget;
556 private _translator;
557 private _layoutRestorer;
558}