UNPKG

13.3 kBTypeScriptView Raw
1import { IIterator } from '@phosphor/algorithm';
2import { Message } from '@phosphor/messaging';
3import { ISignal } from '@phosphor/signaling';
4import { DockLayout } from './docklayout';
5import { TabBar } from './tabbar';
6import { Widget } from './widget';
7/**
8 * A widget which provides a flexible docking area for widgets.
9 */
10export declare class DockPanel extends Widget {
11 /**
12 * Construct a new dock panel.
13 *
14 * @param options - The options for initializing the panel.
15 */
16 constructor(options?: DockPanel.IOptions);
17 /**
18 * Dispose of the resources held by the panel.
19 */
20 dispose(): void;
21 /**
22 * A signal emitted when the layout configuration is modified.
23 *
24 * #### Notes
25 * This signal is emitted whenever the current layout configuration
26 * may have changed.
27 *
28 * This signal is emitted asynchronously in a collapsed fashion, so
29 * that multiple synchronous modifications results in only a single
30 * emit of the signal.
31 */
32 readonly layoutModified: ISignal<this, void>;
33 /**
34 * The overlay used by the dock panel.
35 */
36 readonly overlay: DockPanel.IOverlay;
37 /**
38 * The renderer used by the dock panel.
39 */
40 readonly renderer: DockPanel.IRenderer;
41 /**
42 * Get the spacing between the widgets.
43 */
44 /**
45 * Set the spacing between the widgets.
46 */
47 spacing: number;
48 /**
49 * Get the mode for the dock panel.
50 */
51 /**
52 * Set the mode for the dock panel.
53 *
54 * #### Notes
55 * Changing the mode is a destructive operation with respect to the
56 * panel's layout configuration. If layout state must be preserved,
57 * save the current layout config before changing the mode.
58 */
59 mode: DockPanel.Mode;
60 /**
61 * Whether the dock panel is empty.
62 */
63 readonly isEmpty: boolean;
64 /**
65 * Create an iterator over the user widgets in the panel.
66 *
67 * @returns A new iterator over the user widgets in the panel.
68 *
69 * #### Notes
70 * This iterator does not include the generated tab bars.
71 */
72 widgets(): IIterator<Widget>;
73 /**
74 * Create an iterator over the selected widgets in the panel.
75 *
76 * @returns A new iterator over the selected user widgets.
77 *
78 * #### Notes
79 * This iterator yields the widgets corresponding to the current tab
80 * of each tab bar in the panel.
81 */
82 selectedWidgets(): IIterator<Widget>;
83 /**
84 * Create an iterator over the tab bars in the panel.
85 *
86 * @returns A new iterator over the tab bars in the panel.
87 *
88 * #### Notes
89 * This iterator does not include the user widgets.
90 */
91 tabBars(): IIterator<TabBar<Widget>>;
92 /**
93 * Create an iterator over the handles in the panel.
94 *
95 * @returns A new iterator over the handles in the panel.
96 */
97 handles(): IIterator<HTMLDivElement>;
98 /**
99 * Select a specific widget in the dock panel.
100 *
101 * @param widget - The widget of interest.
102 *
103 * #### Notes
104 * This will make the widget the current widget in its tab area.
105 */
106 selectWidget(widget: Widget): void;
107 /**
108 * Activate a specified widget in the dock panel.
109 *
110 * @param widget - The widget of interest.
111 *
112 * #### Notes
113 * This will select and activate the given widget.
114 */
115 activateWidget(widget: Widget): void;
116 /**
117 * Save the current layout configuration of the dock panel.
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(): DockPanel.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 * The dock panel automatically reverts to `'multiple-document'`
136 * mode when a layout config is restored.
137 */
138 restoreLayout(config: DockPanel.ILayoutConfig): void;
139 /**
140 * Add a widget to the dock panel.
141 *
142 * @param widget - The widget to add to the dock panel.
143 *
144 * @param options - The additional options for adding the widget.
145 *
146 * #### Notes
147 * If the panel is in single document mode, the options are ignored
148 * and the widget is always added as tab in the hidden tab bar.
149 */
150 addWidget(widget: Widget, options?: DockPanel.IAddOptions): void;
151 /**
152 * Process a message sent to the widget.
153 *
154 * @param msg - The message sent to the widget.
155 */
156 processMessage(msg: Message): void;
157 /**
158 * Handle the DOM events for the dock panel.
159 *
160 * @param event - The DOM event sent to the panel.
161 *
162 * #### Notes
163 * This method implements the DOM `EventListener` interface and is
164 * called in response to events on the panel's DOM node. It should
165 * not be called directly by user code.
166 */
167 handleEvent(event: Event): void;
168 /**
169 * A message handler invoked on a `'before-attach'` message.
170 */
171 protected onBeforeAttach(msg: Message): void;
172 /**
173 * A message handler invoked on an `'after-detach'` message.
174 */
175 protected onAfterDetach(msg: Message): void;
176 /**
177 * A message handler invoked on a `'child-added'` message.
178 */
179 protected onChildAdded(msg: Widget.ChildMessage): void;
180 /**
181 * A message handler invoked on a `'child-removed'` message.
182 */
183 protected onChildRemoved(msg: Widget.ChildMessage): void;
184 /**
185 * Handle the `'p-dragenter'` event for the dock panel.
186 */
187 private _evtDragEnter;
188 /**
189 * Handle the `'p-dragleave'` event for the dock panel.
190 */
191 private _evtDragLeave;
192 /**
193 * Handle the `'p-dragover'` event for the dock panel.
194 */
195 private _evtDragOver;
196 /**
197 * Handle the `'p-drop'` event for the dock panel.
198 */
199 private _evtDrop;
200 /**
201 * Handle the `'keydown'` event for the dock panel.
202 */
203 private _evtKeyDown;
204 /**
205 * Handle the `'mousedown'` event for the dock panel.
206 */
207 private _evtMouseDown;
208 /**
209 * Handle the `'mousemove'` event for the dock panel.
210 */
211 private _evtMouseMove;
212 /**
213 * Handle the `'mouseup'` event for the dock panel.
214 */
215 private _evtMouseUp;
216 /**
217 * Release the mouse grab for the dock panel.
218 */
219 private _releaseMouse;
220 /**
221 * Show the overlay indicator at the given client position.
222 *
223 * Returns the drop zone at the specified client position.
224 *
225 * #### Notes
226 * If the position is not over a valid zone, the overlay is hidden.
227 */
228 private _showOverlay;
229 /**
230 * Create a new tab bar for use by the panel.
231 */
232 private _createTabBar;
233 /**
234 * Create a new handle for use by the panel.
235 */
236 private _createHandle;
237 /**
238 * Handle the `tabMoved` signal from a tab bar.
239 */
240 private _onTabMoved;
241 /**
242 * Handle the `currentChanged` signal from a tab bar.
243 */
244 private _onCurrentChanged;
245 /**
246 * Handle the `tabActivateRequested` signal from a tab bar.
247 */
248 private _onTabActivateRequested;
249 /**
250 * Handle the `tabCloseRequested` signal from a tab bar.
251 */
252 private _onTabCloseRequested;
253 /**
254 * Handle the `tabDetachRequested` signal from a tab bar.
255 */
256 private _onTabDetachRequested;
257 private _edges;
258 private _mode;
259 private _drag;
260 private _renderer;
261 private _pressData;
262 private _layoutModified;
263}
264/**
265 * The namespace for the `DockPanel` class statics.
266 */
267export declare namespace DockPanel {
268 /**
269 * An options object for creating a dock panel.
270 */
271 interface IOptions {
272 /**
273 * The overlay to use with the dock panel.
274 *
275 * The default is a new `Overlay` instance.
276 */
277 overlay?: IOverlay;
278 /**
279 * The renderer to use for the dock panel.
280 *
281 * The default is a shared renderer instance.
282 */
283 renderer?: IRenderer;
284 /**
285 * The spacing between the items in the panel.
286 *
287 * The default is `4`.
288 */
289 spacing?: number;
290 /**
291 * The mode for the dock panel.
292 *
293 * The deafult is `'multiple-document'`.
294 */
295 mode?: DockPanel.Mode;
296 /**
297 * The sizes of the edge drop zones, in pixels.
298 * If not given, default values will be used.
299 */
300 edges?: IEdges;
301 }
302 /**
303 * The sizes of the edge drop zones, in pixels.
304 */
305 interface IEdges {
306 /**
307 * The size of the top edge drop zone.
308 */
309 top: number;
310 /**
311 * The size of the right edge drop zone.
312 */
313 right: number;
314 /**
315 * The size of the bottom edge drop zone.
316 */
317 bottom: number;
318 /**
319 * The size of the left edge drop zone.
320 */
321 left: number;
322 }
323 /**
324 * A type alias for the supported dock panel modes.
325 */
326 type Mode = (
327 /**
328 * The single document mode.
329 *
330 * In this mode, only a single widget is visible at a time, and that
331 * widget fills the available layout space. No tab bars are visible.
332 */
333 'single-document' |
334 /**
335 * The multiple document mode.
336 *
337 * In this mode, multiple documents are displayed in separate tab
338 * areas, and those areas can be individually resized by the user.
339 */
340 'multiple-document');
341 /**
342 * A type alias for a layout configuration object.
343 */
344 type ILayoutConfig = DockLayout.ILayoutConfig;
345 /**
346 * A type alias for the supported insertion modes.
347 */
348 type InsertMode = DockLayout.InsertMode;
349 /**
350 * A type alias for the add widget options.
351 */
352 type IAddOptions = DockLayout.IAddOptions;
353 /**
354 * An object which holds the geometry for overlay positioning.
355 */
356 interface IOverlayGeometry {
357 /**
358 * The distance between the overlay and parent top edges.
359 */
360 top: number;
361 /**
362 * The distance between the overlay and parent left edges.
363 */
364 left: number;
365 /**
366 * The distance between the overlay and parent right edges.
367 */
368 right: number;
369 /**
370 * The distance between the overlay and parent bottom edges.
371 */
372 bottom: number;
373 }
374 /**
375 * An object which manages the overlay node for a dock panel.
376 */
377 interface IOverlay {
378 /**
379 * The DOM node for the overlay.
380 */
381 readonly node: HTMLDivElement;
382 /**
383 * Show the overlay using the given overlay geometry.
384 *
385 * @param geo - The desired geometry for the overlay.
386 *
387 * #### Notes
388 * The given geometry values assume the node will use absolute
389 * positioning.
390 *
391 * This is called on every mouse move event during a drag in order
392 * to update the position of the overlay. It should be efficient.
393 */
394 show(geo: IOverlayGeometry): void;
395 /**
396 * Hide the overlay node.
397 *
398 * @param delay - The delay (in ms) before hiding the overlay.
399 * A delay value <= 0 should hide the overlay immediately.
400 *
401 * #### Notes
402 * This is called whenever the overlay node should been hidden.
403 */
404 hide(delay: number): void;
405 }
406 /**
407 * A concrete implementation of `IOverlay`.
408 *
409 * This is the default overlay implementation for a dock panel.
410 */
411 class Overlay implements IOverlay {
412 /**
413 * Construct a new overlay.
414 */
415 constructor();
416 /**
417 * The DOM node for the overlay.
418 */
419 readonly node: HTMLDivElement;
420 /**
421 * Show the overlay using the given overlay geometry.
422 *
423 * @param geo - The desired geometry for the overlay.
424 */
425 show(geo: IOverlayGeometry): void;
426 /**
427 * Hide the overlay node.
428 *
429 * @param delay - The delay (in ms) before hiding the overlay.
430 * A delay value <= 0 will hide the overlay immediately.
431 */
432 hide(delay: number): void;
433 private _timer;
434 private _hidden;
435 }
436 /**
437 * A type alias for a dock panel renderer;
438 */
439 type IRenderer = DockLayout.IRenderer;
440 /**
441 * The default implementation of `IRenderer`.
442 */
443 class Renderer implements IRenderer {
444 /**
445 * Create a new tab bar for use with a dock panel.
446 *
447 * @returns A new tab bar for a dock panel.
448 */
449 createTabBar(): TabBar<Widget>;
450 /**
451 * Create a new handle node for use with a dock panel.
452 *
453 * @returns A new handle node for a dock panel.
454 */
455 createHandle(): HTMLDivElement;
456 }
457 /**
458 * The default `Renderer` instance.
459 */
460 const defaultRenderer: Renderer;
461}