UNPKG

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