UNPKG

16.8 kBTypeScriptView Raw
1import { Message } from '@lumino/messaging';
2import { Layout } from './layout';
3import { TabBar } from './tabbar';
4import { Widget } from './widget';
5/**
6 * A layout which provides a flexible docking arrangement.
7 *
8 * #### Notes
9 * The consumer of this layout is responsible for handling all signals
10 * from the generated tab bars and managing the visibility of widgets
11 * and tab bars as needed.
12 */
13export declare class DockLayout extends Layout {
14 /**
15 * Construct a new dock layout.
16 *
17 * @param options - The options for initializing the layout.
18 */
19 constructor(options: DockLayout.IOptions);
20 /**
21 * Dispose of the resources held by the layout.
22 *
23 * #### Notes
24 * This will clear and dispose all widgets in the layout.
25 */
26 dispose(): void;
27 /**
28 * The renderer used by the dock layout.
29 */
30 readonly renderer: DockLayout.IRenderer;
31 /**
32 * The method for hiding child widgets.
33 *
34 * #### Notes
35 * If there is only one child widget, `Display` hiding mode will be used
36 * regardless of this setting.
37 */
38 get hiddenMode(): Widget.HiddenMode;
39 set hiddenMode(v: Widget.HiddenMode);
40 /**
41 * Get the inter-element spacing for the dock layout.
42 */
43 get spacing(): number;
44 /**
45 * Set the inter-element spacing for the dock layout.
46 */
47 set spacing(value: number);
48 /**
49 * Whether the dock layout is empty.
50 */
51 get isEmpty(): boolean;
52 /**
53 * Create an iterator over all widgets in the layout.
54 *
55 * @returns A new iterator over the widgets in the layout.
56 *
57 * #### Notes
58 * This iterator includes the generated tab bars.
59 */
60 [Symbol.iterator](): IterableIterator<Widget>;
61 /**
62 * Create an iterator over the user widgets in the layout.
63 *
64 * @returns A new iterator over the user widgets in the layout.
65 *
66 * #### Notes
67 * This iterator does not include the generated tab bars.
68 */
69 widgets(): IterableIterator<Widget>;
70 /**
71 * Create an iterator over the selected widgets in the layout.
72 *
73 * @returns A new iterator over the selected user widgets.
74 *
75 * #### Notes
76 * This iterator yields the widgets corresponding to the current tab
77 * of each tab bar in the layout.
78 */
79 selectedWidgets(): IterableIterator<Widget>;
80 /**
81 * Create an iterator over the tab bars in the layout.
82 *
83 * @returns A new iterator over the tab bars in the layout.
84 *
85 * #### Notes
86 * This iterator does not include the user widgets.
87 */
88 tabBars(): IterableIterator<TabBar<Widget>>;
89 /**
90 * Create an iterator over the handles in the layout.
91 *
92 * @returns A new iterator over the handles in the layout.
93 */
94 handles(): IterableIterator<HTMLDivElement>;
95 /**
96 * Move a handle to the given offset position.
97 *
98 * @param handle - The handle to move.
99 *
100 * @param offsetX - The desired offset X position of the handle.
101 *
102 * @param offsetY - The desired offset Y position of the handle.
103 *
104 * #### Notes
105 * If the given handle is not contained in the layout, this is no-op.
106 *
107 * The handle will be moved as close as possible to the desired
108 * position without violating any of the layout constraints.
109 *
110 * Only one of the coordinates is used depending on the orientation
111 * of the handle. This method accepts both coordinates to make it
112 * easy to invoke from a mouse move event without needing to know
113 * the handle orientation.
114 */
115 moveHandle(handle: HTMLDivElement, offsetX: number, offsetY: number): void;
116 /**
117 * Save the current configuration of the dock layout.
118 *
119 * @returns A new config object for the current layout state.
120 *
121 * #### Notes
122 * The return value can be provided to the `restoreLayout` method
123 * in order to restore the layout to its current configuration.
124 */
125 saveLayout(): DockLayout.ILayoutConfig;
126 /**
127 * Restore the layout to a previously saved configuration.
128 *
129 * @param config - The layout configuration to restore.
130 *
131 * #### Notes
132 * Widgets which currently belong to the layout but which are not
133 * contained in the config will be unparented.
134 */
135 restoreLayout(config: DockLayout.ILayoutConfig): void;
136 /**
137 * Add a widget to the dock layout.
138 *
139 * @param widget - The widget to add to the dock layout.
140 *
141 * @param options - The additional options for adding the widget.
142 *
143 * #### Notes
144 * The widget will be moved if it is already contained in the layout.
145 *
146 * An error will be thrown if the reference widget is invalid.
147 */
148 addWidget(widget: Widget, options?: DockLayout.IAddOptions): void;
149 /**
150 * Remove a widget from the layout.
151 *
152 * @param widget - The widget to remove from the layout.
153 *
154 * #### Notes
155 * A widget is automatically removed from the layout when its `parent`
156 * is set to `null`. This method should only be invoked directly when
157 * removing a widget from a layout which has yet to be installed on a
158 * parent widget.
159 *
160 * This method does *not* modify the widget's `parent`.
161 */
162 removeWidget(widget: Widget): void;
163 /**
164 * Find the tab area which contains the given client position.
165 *
166 * @param clientX - The client X position of interest.
167 *
168 * @param clientY - The client Y position of interest.
169 *
170 * @returns The geometry of the tab area at the given position, or
171 * `null` if there is no tab area at the given position.
172 */
173 hitTestTabAreas(clientX: number, clientY: number): DockLayout.ITabAreaGeometry | null;
174 /**
175 * Perform layout initialization which requires the parent widget.
176 */
177 protected init(): void;
178 /**
179 * Attach the widget to the layout parent widget.
180 *
181 * @param widget - The widget to attach to the parent.
182 *
183 * #### Notes
184 * This is a no-op if the widget is already attached.
185 */
186 protected attachWidget(widget: Widget): void;
187 /**
188 * Detach the widget from the layout parent widget.
189 *
190 * @param widget - The widget to detach from the parent.
191 *
192 * #### Notes
193 * This is a no-op if the widget is not attached.
194 */
195 protected detachWidget(widget: Widget): void;
196 /**
197 * A message handler invoked on a `'before-show'` message.
198 */
199 protected onBeforeShow(msg: Message): void;
200 /**
201 * A message handler invoked on a `'before-attach'` message.
202 */
203 protected onBeforeAttach(msg: Message): void;
204 /**
205 * A message handler invoked on a `'child-shown'` message.
206 */
207 protected onChildShown(msg: Widget.ChildMessage): void;
208 /**
209 * A message handler invoked on a `'child-hidden'` message.
210 */
211 protected onChildHidden(msg: Widget.ChildMessage): void;
212 /**
213 * A message handler invoked on a `'resize'` message.
214 */
215 protected onResize(msg: Widget.ResizeMessage): void;
216 /**
217 * A message handler invoked on an `'update-request'` message.
218 */
219 protected onUpdateRequest(msg: Message): void;
220 /**
221 * A message handler invoked on a `'fit-request'` message.
222 */
223 protected onFitRequest(msg: Message): void;
224 /**
225 * Remove the specified widget from the layout structure.
226 *
227 * #### Notes
228 * This is a no-op if the widget is not in the layout tree.
229 *
230 * This does not detach the widget from the parent node.
231 */
232 private _removeWidget;
233 /**
234 * Create the tab layout node to hold the widget.
235 */
236 private _createTabNode;
237 /**
238 * Insert a widget next to an existing tab.
239 *
240 * #### Notes
241 * This does not attach the widget to the parent widget.
242 */
243 private _insertTab;
244 /**
245 * Insert a widget as a new split area.
246 *
247 * #### Notes
248 * This does not attach the widget to the parent widget.
249 */
250 private _insertSplit;
251 /**
252 * Ensure the root is a split node with the given orientation.
253 */
254 private _splitRoot;
255 /**
256 * Fit the layout to the total size required by the widgets.
257 */
258 private _fit;
259 /**
260 * Update the layout position and size of the widgets.
261 *
262 * The parent offset dimensions should be `-1` if unknown.
263 */
264 private _update;
265 /**
266 * Create a new tab bar for use by the dock layout.
267 *
268 * #### Notes
269 * The tab bar will be attached to the parent if it exists.
270 */
271 private _createTabBar;
272 /**
273 * Create a new handle for the dock layout.
274 *
275 * #### Notes
276 * The handle will be attached to the parent if it exists.
277 */
278 private _createHandle;
279 private _spacing;
280 private _dirty;
281 private _root;
282 private _box;
283 private _document;
284 private _hiddenMode;
285 private _items;
286}
287/**
288 * The namespace for the `DockLayout` class statics.
289 */
290export declare namespace DockLayout {
291 /**
292 * An options object for creating a dock layout.
293 */
294 interface IOptions {
295 /**
296 * The document to use with the dock panel.
297 *
298 * The default is the global `document` instance.
299 */
300 document?: Document | ShadowRoot;
301 /**
302 * The method for hiding widgets.
303 *
304 * The default is `Widget.HiddenMode.Display`.
305 */
306 hiddenMode?: Widget.HiddenMode;
307 /**
308 * The renderer to use for the dock layout.
309 */
310 renderer: IRenderer;
311 /**
312 * The spacing between items in the layout.
313 *
314 * The default is `4`.
315 */
316 spacing?: number;
317 }
318 /**
319 * A renderer for use with a dock layout.
320 */
321 interface IRenderer {
322 /**
323 * Create a new tab bar for use with a dock layout.
324 *
325 * @returns A new tab bar for a dock layout.
326 */
327 createTabBar(document?: Document | ShadowRoot): TabBar<Widget>;
328 /**
329 * Create a new handle node for use with a dock layout.
330 *
331 * @returns A new handle node for a dock layout.
332 */
333 createHandle(): HTMLDivElement;
334 }
335 /**
336 * A type alias for the supported insertion modes.
337 *
338 * An insert mode is used to specify how a widget should be added
339 * to the dock layout relative to a reference widget.
340 */
341 type InsertMode = /**
342 * The area to the top of the reference widget.
343 *
344 * The widget will be inserted just above the reference widget.
345 *
346 * If the reference widget is null or invalid, the widget will be
347 * inserted at the top edge of the dock layout.
348 */ 'split-top'
349 /**
350 * The area to the left of the reference widget.
351 *
352 * The widget will be inserted just left of the reference widget.
353 *
354 * If the reference widget is null or invalid, the widget will be
355 * inserted at the left edge of the dock layout.
356 */
357 | 'split-left'
358 /**
359 * The area to the right of the reference widget.
360 *
361 * The widget will be inserted just right of the reference widget.
362 *
363 * If the reference widget is null or invalid, the widget will be
364 * inserted at the right edge of the dock layout.
365 */
366 | 'split-right'
367 /**
368 * The area to the bottom of the reference widget.
369 *
370 * The widget will be inserted just below the reference widget.
371 *
372 * If the reference widget is null or invalid, the widget will be
373 * inserted at the bottom edge of the dock layout.
374 */
375 | 'split-bottom'
376 /**
377 * Like `split-top` but if a tab layout exists above the reference widget,
378 * it behaves like `tab-after` with reference to that instead.
379 */
380 | 'merge-top'
381 /**
382 * Like `split-left` but if a tab layout exists left of the reference widget,
383 * it behaves like `tab-after` with reference to that instead.
384 */
385 | 'merge-left'
386 /**
387 * Like `split-right` but if a tab layout exists right of the reference widget,
388 * it behaves like `tab-after` with reference to that instead.
389 */
390 | 'merge-right'
391 /**
392 * Like `split-bottom` but if a tab layout exists below the reference widget,
393 * it behaves like `tab-after` with reference to that instead.
394 */
395 | 'merge-bottom'
396 /**
397 * The tab position before the reference widget.
398 *
399 * The widget will be added as a tab before the reference widget.
400 *
401 * If the reference widget is null or invalid, a sensible default
402 * will be used.
403 */
404 | 'tab-before'
405 /**
406 * The tab position after the reference widget.
407 *
408 * The widget will be added as a tab after the reference widget.
409 *
410 * If the reference widget is null or invalid, a sensible default
411 * will be used.
412 */
413 | 'tab-after';
414 /**
415 * An options object for adding a widget to the dock layout.
416 */
417 interface IAddOptions {
418 /**
419 * The insertion mode for adding the widget.
420 *
421 * The default is `'tab-after'`.
422 */
423 mode?: InsertMode;
424 /**
425 * The reference widget for the insert location.
426 *
427 * The default is `null`.
428 */
429 ref?: Widget | null;
430 }
431 /**
432 * A layout config object for a tab area.
433 */
434 interface ITabAreaConfig {
435 /**
436 * The discriminated type of the config object.
437 */
438 type: 'tab-area';
439 /**
440 * The widgets contained in the tab area.
441 */
442 widgets: Widget[];
443 /**
444 * The index of the selected tab.
445 */
446 currentIndex: number;
447 }
448 /**
449 * A layout config object for a split area.
450 */
451 interface ISplitAreaConfig {
452 /**
453 * The discriminated type of the config object.
454 */
455 type: 'split-area';
456 /**
457 * The orientation of the split area.
458 */
459 orientation: 'horizontal' | 'vertical';
460 /**
461 * The children in the split area.
462 */
463 children: AreaConfig[];
464 /**
465 * The relative sizes of the children.
466 */
467 sizes: number[];
468 }
469 /**
470 * A type alias for a general area config.
471 */
472 type AreaConfig = ITabAreaConfig | ISplitAreaConfig;
473 /**
474 * A dock layout configuration object.
475 */
476 interface ILayoutConfig {
477 /**
478 * The layout config for the main dock area.
479 */
480 main: AreaConfig | null;
481 }
482 /**
483 * An object which represents the geometry of a tab area.
484 */
485 interface ITabAreaGeometry {
486 /**
487 * The tab bar for the tab area.
488 */
489 tabBar: TabBar<Widget>;
490 /**
491 * The local X position of the hit test in the dock area.
492 *
493 * #### Notes
494 * This is the distance from the left edge of the layout parent
495 * widget, to the local X coordinate of the hit test query.
496 */
497 x: number;
498 /**
499 * The local Y position of the hit test in the dock area.
500 *
501 * #### Notes
502 * This is the distance from the top edge of the layout parent
503 * widget, to the local Y coordinate of the hit test query.
504 */
505 y: number;
506 /**
507 * The local coordinate of the top edge of the tab area.
508 *
509 * #### Notes
510 * This is the distance from the top edge of the layout parent
511 * widget, to the top edge of the tab area.
512 */
513 top: number;
514 /**
515 * The local coordinate of the left edge of the tab area.
516 *
517 * #### Notes
518 * This is the distance from the left edge of the layout parent
519 * widget, to the left edge of the tab area.
520 */
521 left: number;
522 /**
523 * The local coordinate of the right edge of the tab area.
524 *
525 * #### Notes
526 * This is the distance from the right edge of the layout parent
527 * widget, to the right edge of the tab area.
528 */
529 right: number;
530 /**
531 * The local coordinate of the bottom edge of the tab area.
532 *
533 * #### Notes
534 * This is the distance from the bottom edge of the layout parent
535 * widget, to the bottom edge of the tab area.
536 */
537 bottom: number;
538 /**
539 * The width of the tab area.
540 *
541 * #### Notes
542 * This is total width allocated for the tab area.
543 */
544 width: number;
545 /**
546 * The height of the tab area.
547 *
548 * #### Notes
549 * This is total height allocated for the tab area.
550 */
551 height: number;
552 }
553}