UNPKG

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