1 | import { IIterator } from '@lumino/algorithm';
|
2 | import { IObservableDisposable } from '@lumino/disposable';
|
3 | import { ConflatableMessage, IMessageHandler, Message } from '@lumino/messaging';
|
4 | import { ISignal } from '@lumino/signaling';
|
5 | import { Layout } from './layout';
|
6 | import { Title } from './title';
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | export declare class Widget implements IMessageHandler, IObservableDisposable {
|
16 | |
17 |
|
18 |
|
19 |
|
20 |
|
21 | constructor(options?: Widget.IOptions);
|
22 | /**
|
23 | * Dispose of the widget and its descendant widgets.
|
24 | *
|
25 | * #### Notes
|
26 | * It is unsafe to use the widget after it has been disposed.
|
27 | *
|
28 | * All calls made to this method after the first are a no-op.
|
29 | */
|
30 | dispose(): void;
|
31 | /**
|
32 | * A signal emitted when the widget is disposed.
|
33 | */
|
34 | readonly disposed: ISignal<this, void>;
|
35 | /**
|
36 | * Get the DOM node owned by the widget.
|
37 | */
|
38 | readonly node: HTMLElement;
|
39 | /**
|
40 | * Test whether the widget has been disposed.
|
41 | */
|
42 | readonly isDisposed: boolean;
|
43 | /**
|
44 | * Test whether the widget's node is attached to the DOM.
|
45 | */
|
46 | readonly isAttached: boolean;
|
47 | /**
|
48 | * Test whether the widget is explicitly hidden.
|
49 | */
|
50 | readonly isHidden: boolean;
|
51 | /**
|
52 | * Test whether the widget is visible.
|
53 | *
|
54 | * #### Notes
|
55 | * A widget is visible when it is attached to the DOM, is not
|
56 | * explicitly hidden, and has no explicitly hidden ancestors.
|
57 | */
|
58 | readonly isVisible: boolean;
|
59 | /**
|
60 | * The title object for the widget.
|
61 | *
|
62 | * #### Notes
|
63 | * The title object is used by some container widgets when displaying
|
64 | * the widget alongside some title, such as a tab panel or side bar.
|
65 | *
|
66 | * Since not all widgets will use the title, it is created on demand.
|
67 | *
|
68 | * The `owner` property of the title is set to this widget.
|
69 | */
|
70 | readonly title: Title<Widget>;
|
71 | /**
|
72 | * Get the id of the widget's DOM node.
|
73 | */
|
74 | /**
|
75 | * Set the id of the widget's DOM node.
|
76 | */
|
77 | id: string;
|
78 | /**
|
79 | * The dataset for the widget's DOM node.
|
80 | */
|
81 | readonly dataset: DOMStringMap;
|
82 | /**
|
83 | * Get the method for hiding the widget.
|
84 | */
|
85 | /**
|
86 | * Set the method for hiding the widget.
|
87 | */
|
88 | hiddenMode: Widget.HiddenMode;
|
89 | /**
|
90 | * Get the parent of the widget.
|
91 | */
|
92 | /**
|
93 | * Set the parent of the widget.
|
94 | *
|
95 | * #### Notes
|
96 | * Children are typically added to a widget by using a layout, which
|
97 | * means user code will not normally set the parent widget directly.
|
98 | *
|
99 | * The widget will be automatically removed from its old parent.
|
100 | *
|
101 | * This is a no-op if there is no effective parent change.
|
102 | */
|
103 | parent: Widget | null;
|
104 | /**
|
105 | * Get the layout for the widget.
|
106 | */
|
107 | /**
|
108 | * Set the layout for the widget.
|
109 | *
|
110 | * #### Notes
|
111 | * The layout is single-use only. It cannot be changed after the
|
112 | * first assignment.
|
113 | *
|
114 | * The layout is disposed automatically when the widget is disposed.
|
115 | */
|
116 | layout: Layout | null;
|
117 | /**
|
118 | * Create an iterator over the widget's children.
|
119 | *
|
120 | * @returns A new iterator over the children of the widget.
|
121 | *
|
122 | * #### Notes
|
123 | * The widget must have a populated layout in order to have children.
|
124 | *
|
125 | * If a layout is not installed, the returned iterator will be empty.
|
126 | */
|
127 | children(): IIterator<Widget>;
|
128 | /**
|
129 | * Test whether a widget is a descendant of this widget.
|
130 | *
|
131 | * @param widget - The descendant widget of interest.
|
132 | *
|
133 | * @returns `true` if the widget is a descendant, `false` otherwise.
|
134 | */
|
135 | contains(widget: Widget): boolean;
|
136 | /**
|
137 | * Test whether the widget's DOM node has the given class name.
|
138 | *
|
139 | * @param name - The class name of interest.
|
140 | *
|
141 | * @returns `true` if the node has the class, `false` otherwise.
|
142 | */
|
143 | hasClass(name: string): boolean;
|
144 | /**
|
145 | * Add a class name to the widget's DOM node.
|
146 | *
|
147 | * @param name - The class name to add to the node.
|
148 | *
|
149 | * #### Notes
|
150 | * If the class name is already added to the node, this is a no-op.
|
151 | *
|
152 | * The class name must not contain whitespace.
|
153 | */
|
154 | addClass(name: string): void;
|
155 | /**
|
156 | * Remove a class name from the widget's DOM node.
|
157 | *
|
158 | * @param name - The class name to remove from the node.
|
159 | *
|
160 | * #### Notes
|
161 | * If the class name is not yet added to the node, this is a no-op.
|
162 | *
|
163 | * The class name must not contain whitespace.
|
164 | */
|
165 | removeClass(name: string): void;
|
166 | /**
|
167 | * Toggle a class name on the widget's DOM node.
|
168 | *
|
169 | * @param name - The class name to toggle on the node.
|
170 | *
|
171 | * @param force - Whether to force add the class (`true`) or force
|
172 | * remove the class (`false`). If not provided, the presence of
|
173 | * the class will be toggled from its current state.
|
174 | *
|
175 | * @returns `true` if the class is now present, `false` otherwise.
|
176 | *
|
177 | * #### Notes
|
178 | * The class name must not contain whitespace.
|
179 | */
|
180 | toggleClass(name: string, force?: boolean): boolean;
|
181 | /**
|
182 | * Post an `'update-request'` message to the widget.
|
183 | *
|
184 | * #### Notes
|
185 | * This is a simple convenience method for posting the message.
|
186 | */
|
187 | update(): void;
|
188 | /**
|
189 | * Post a `'fit-request'` message to the widget.
|
190 | *
|
191 | * #### Notes
|
192 | * This is a simple convenience method for posting the message.
|
193 | */
|
194 | fit(): void;
|
195 | /**
|
196 | * Post an `'activate-request'` message to the widget.
|
197 | *
|
198 | * #### Notes
|
199 | * This is a simple convenience method for posting the message.
|
200 | */
|
201 | activate(): void;
|
202 | /**
|
203 | * Send a `'close-request'` message to the widget.
|
204 | *
|
205 | * #### Notes
|
206 | * This is a simple convenience method for sending the message.
|
207 | */
|
208 | close(): void;
|
209 | /**
|
210 | * Show the widget and make it visible to its parent widget.
|
211 | *
|
212 | * #### Notes
|
213 | * This causes the [[isHidden]] property to be `false`.
|
214 | *
|
215 | * If the widget is not explicitly hidden, this is a no-op.
|
216 | */
|
217 | show(): void;
|
218 | /**
|
219 | * Hide the widget and make it hidden to its parent widget.
|
220 | *
|
221 | * #### Notes
|
222 | * This causes the [[isHidden]] property to be `true`.
|
223 | *
|
224 | * If the widget is explicitly hidden, this is a no-op.
|
225 | */
|
226 | hide(): void;
|
227 | /**
|
228 | * Show or hide the widget according to a boolean value.
|
229 | *
|
230 | * @param hidden - `true` to hide the widget, or `false` to show it.
|
231 | *
|
232 | * #### Notes
|
233 | * This is a convenience method for `hide()` and `show()`.
|
234 | */
|
235 | setHidden(hidden: boolean): void;
|
236 | /**
|
237 | * Test whether the given widget flag is set.
|
238 | *
|
239 | * #### Notes
|
240 | * This will not typically be called directly by user code.
|
241 | */
|
242 | testFlag(flag: Widget.Flag): boolean;
|
243 | /**
|
244 | * Set the given widget flag.
|
245 | *
|
246 | * #### Notes
|
247 | * This will not typically be called directly by user code.
|
248 | */
|
249 | setFlag(flag: Widget.Flag): void;
|
250 | /**
|
251 | * Clear the given widget flag.
|
252 | *
|
253 | * #### Notes
|
254 | * This will not typically be called directly by user code.
|
255 | */
|
256 | clearFlag(flag: Widget.Flag): void;
|
257 | /**
|
258 | * Process a message sent to the widget.
|
259 | *
|
260 | * @param msg - The message sent to the widget.
|
261 | *
|
262 | * #### Notes
|
263 | * Subclasses may reimplement this method as needed.
|
264 | */
|
265 | processMessage(msg: Message): void;
|
266 | /**
|
267 | * Invoke the message processing routine of the widget's layout.
|
268 | *
|
269 | * @param msg - The message to dispatch to the layout.
|
270 | *
|
271 | * #### Notes
|
272 | * This is a no-op if the widget does not have a layout.
|
273 | *
|
274 | * This will not typically be called directly by user code.
|
275 | */
|
276 | protected notifyLayout(msg: Message): void;
|
277 | /**
|
278 | * A message handler invoked on a `'close-request'` message.
|
279 | *
|
280 | * #### Notes
|
281 | * The default implementation unparents or detaches the widget.
|
282 | */
|
283 | protected onCloseRequest(msg: Message): void;
|
284 | /**
|
285 | * A message handler invoked on a `'resize'` message.
|
286 | *
|
287 | * #### Notes
|
288 | * The default implementation of this handler is a no-op.
|
289 | */
|
290 | protected onResize(msg: Widget.ResizeMessage): void;
|
291 | /**
|
292 | * A message handler invoked on an `'update-request'` message.
|
293 | *
|
294 | * #### Notes
|
295 | * The default implementation of this handler is a no-op.
|
296 | */
|
297 | protected onUpdateRequest(msg: Message): void;
|
298 | /**
|
299 | * A message handler invoked on a `'fit-request'` message.
|
300 | *
|
301 | * #### Notes
|
302 | * The default implementation of this handler is a no-op.
|
303 | */
|
304 | protected onFitRequest(msg: Message): void;
|
305 | /**
|
306 | * A message handler invoked on an `'activate-request'` message.
|
307 | *
|
308 | * #### Notes
|
309 | * The default implementation of this handler is a no-op.
|
310 | */
|
311 | protected onActivateRequest(msg: Message): void;
|
312 | /**
|
313 | * A message handler invoked on a `'before-show'` message.
|
314 | *
|
315 | * #### Notes
|
316 | * The default implementation of this handler is a no-op.
|
317 | */
|
318 | protected onBeforeShow(msg: Message): void;
|
319 | /**
|
320 | * A message handler invoked on an `'after-show'` message.
|
321 | *
|
322 | * #### Notes
|
323 | * The default implementation of this handler is a no-op.
|
324 | */
|
325 | protected onAfterShow(msg: Message): void;
|
326 | /**
|
327 | * A message handler invoked on a `'before-hide'` message.
|
328 | *
|
329 | * #### Notes
|
330 | * The default implementation of this handler is a no-op.
|
331 | */
|
332 | protected onBeforeHide(msg: Message): void;
|
333 | /**
|
334 | * A message handler invoked on an `'after-hide'` message.
|
335 | *
|
336 | * #### Notes
|
337 | * The default implementation of this handler is a no-op.
|
338 | */
|
339 | protected onAfterHide(msg: Message): void;
|
340 | /**
|
341 | * A message handler invoked on a `'before-attach'` message.
|
342 | *
|
343 | * #### Notes
|
344 | * The default implementation of this handler is a no-op.
|
345 | */
|
346 | protected onBeforeAttach(msg: Message): void;
|
347 | /**
|
348 | * A message handler invoked on an `'after-attach'` message.
|
349 | *
|
350 | * #### Notes
|
351 | * The default implementation of this handler is a no-op.
|
352 | */
|
353 | protected onAfterAttach(msg: Message): void;
|
354 | /**
|
355 | * A message handler invoked on a `'before-detach'` message.
|
356 | *
|
357 | * #### Notes
|
358 | * The default implementation of this handler is a no-op.
|
359 | */
|
360 | protected onBeforeDetach(msg: Message): void;
|
361 | /**
|
362 | * A message handler invoked on an `'after-detach'` message.
|
363 | *
|
364 | * #### Notes
|
365 | * The default implementation of this handler is a no-op.
|
366 | */
|
367 | protected onAfterDetach(msg: Message): void;
|
368 | /**
|
369 | * A message handler invoked on a `'child-added'` message.
|
370 | *
|
371 | * #### Notes
|
372 | * The default implementation of this handler is a no-op.
|
373 | */
|
374 | protected onChildAdded(msg: Widget.ChildMessage): void;
|
375 | /**
|
376 | * A message handler invoked on a `'child-removed'` message.
|
377 | *
|
378 | * #### Notes
|
379 | * The default implementation of this handler is a no-op.
|
380 | */
|
381 | protected onChildRemoved(msg: Widget.ChildMessage): void;
|
382 | private _toggleHidden;
|
383 | private _flags;
|
384 | private _layout;
|
385 | private _parent;
|
386 | private _disposed;
|
387 | private _hiddenMode;
|
388 | }
|
389 | /**
|
390 | * The namespace for the `Widget` class statics.
|
391 | */
|
392 | export declare namespace Widget {
|
393 | |
394 |
|
395 |
|
396 | interface IOptions {
|
397 | |
398 |
|
399 |
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 | node?: HTMLElement;
|
406 | |
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 | tag?: keyof HTMLElementTagNameMap;
|
413 | }
|
414 | |
415 |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 |
|
421 |
|
422 |
|
423 |
|
424 |
|
425 |
|
426 |
|
427 |
|
428 |
|
429 |
|
430 | enum HiddenMode {
|
431 | |
432 |
|
433 |
|
434 |
|
435 | Display = 0,
|
436 | |
437 |
|
438 |
|
439 | Scale = 1,
|
440 | |
441 |
|
442 |
|
443 | ContentVisibility = 2
|
444 | }
|
445 | |
446 |
|
447 |
|
448 | enum Flag {
|
449 | |
450 |
|
451 |
|
452 | IsDisposed = 1,
|
453 | |
454 |
|
455 |
|
456 | IsAttached = 2,
|
457 | |
458 |
|
459 |
|
460 | IsHidden = 4,
|
461 | |
462 |
|
463 |
|
464 | IsVisible = 8,
|
465 | |
466 |
|
467 |
|
468 | DisallowLayout = 16
|
469 | }
|
470 | |
471 |
|
472 |
|
473 | namespace Msg {
|
474 | |
475 |
|
476 |
|
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 | const BeforeShow: Message;
|
483 | |
484 |
|
485 |
|
486 |
|
487 |
|
488 |
|
489 |
|
490 |
|
491 | const AfterShow: Message;
|
492 | |
493 |
|
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 |
|
500 | const BeforeHide: Message;
|
501 | |
502 |
|
503 |
|
504 |
|
505 |
|
506 |
|
507 |
|
508 |
|
509 | const AfterHide: Message;
|
510 | |
511 |
|
512 |
|
513 |
|
514 |
|
515 |
|
516 | const BeforeAttach: Message;
|
517 | |
518 |
|
519 |
|
520 |
|
521 |
|
522 |
|
523 | const AfterAttach: Message;
|
524 | |
525 |
|
526 |
|
527 |
|
528 |
|
529 |
|
530 | const BeforeDetach: Message;
|
531 | |
532 |
|
533 |
|
534 |
|
535 |
|
536 |
|
537 | const AfterDetach: Message;
|
538 | |
539 |
|
540 |
|
541 |
|
542 |
|
543 |
|
544 | const ParentChanged: Message;
|
545 | |
546 |
|
547 |
|
548 |
|
549 |
|
550 |
|
551 |
|
552 |
|
553 |
|
554 |
|
555 |
|
556 | const UpdateRequest: ConflatableMessage;
|
557 | |
558 |
|
559 |
|
560 |
|
561 |
|
562 |
|
563 |
|
564 |
|
565 |
|
566 | const FitRequest: ConflatableMessage;
|
567 | |
568 |
|
569 |
|
570 |
|
571 |
|
572 |
|
573 |
|
574 |
|
575 | const ActivateRequest: ConflatableMessage;
|
576 | |
577 |
|
578 |
|
579 |
|
580 |
|
581 |
|
582 |
|
583 | const CloseRequest: ConflatableMessage;
|
584 | }
|
585 | |
586 |
|
587 |
|
588 | class ChildMessage extends Message {
|
589 | |
590 |
|
591 |
|
592 |
|
593 |
|
594 |
|
595 |
|
596 | constructor(type: string, child: Widget);
|
597 | /**
|
598 | * The child widget for the message.
|
599 | */
|
600 | readonly child: Widget;
|
601 | }
|
602 | /**
|
603 | * A message class for `'resize'` messages.
|
604 | */
|
605 | class ResizeMessage extends Message {
|
606 | |
607 |
|
608 |
|
609 |
|
610 |
|
611 |
|
612 |
|
613 |
|
614 |
|
615 | constructor(width: number, height: number);
|
616 | /**
|
617 | * The offset width of the widget.
|
618 | *
|
619 | * #### Notes
|
620 | * This will be `-1` if the width is unknown.
|
621 | */
|
622 | readonly width: number;
|
623 | /**
|
624 | * The offset height of the widget.
|
625 | *
|
626 | * #### Notes
|
627 | * This will be `-1` if the height is unknown.
|
628 | */
|
629 | readonly height: number;
|
630 | }
|
631 | /**
|
632 | * The namespace for the `ResizeMessage` class statics.
|
633 | */
|
634 | namespace ResizeMessage {
|
635 | |
636 |
|
637 |
|
638 | const UnknownSize: ResizeMessage;
|
639 | }
|
640 | |
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 |
|
648 |
|
649 |
|
650 |
|
651 |
|
652 |
|
653 |
|
654 |
|
655 |
|
656 |
|
657 | function attach(widget: Widget, host: HTMLElement, ref?: HTMLElement | null): void;
|
658 | |
659 |
|
660 |
|
661 |
|
662 |
|
663 |
|
664 |
|
665 |
|
666 |
|
667 | function detach(widget: Widget): void;
|
668 | }
|
669 |
|
\ | No newline at end of file |