1 | import { ITranslator } from '@jupyterlab/translation';
|
2 | import { Message } from '@lumino/messaging';
|
3 | import { Widget } from '@lumino/widgets';
|
4 | import * as React from 'react';
|
5 | import { WidgetTracker } from './widgettracker';
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | export declare function showDialog<T>(options?: Partial<Dialog.IOptions<T>>): Promise<Dialog.IResult<T>>;
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | export declare function showErrorMessage(title: string, error: string | Dialog.IError, buttons?: ReadonlyArray<Dialog.IButton>): Promise<void>;
|
23 |
|
24 |
|
25 |
|
26 | export declare class Dialog<T> extends Widget {
|
27 | |
28 |
|
29 |
|
30 |
|
31 |
|
32 | constructor(options?: Partial<Dialog.IOptions<T>>);
|
33 | /**
|
34 | * A promise that resolves when the Dialog first rendering is done.
|
35 | */
|
36 | get ready(): Promise<void>;
|
37 | /**
|
38 | * Dispose of the resources used by the dialog.
|
39 | */
|
40 | dispose(): void;
|
41 | /**
|
42 | * Launch the dialog as a modal window.
|
43 | *
|
44 | * @returns a promise that resolves with the result of the dialog.
|
45 | */
|
46 | launch(): Promise<Dialog.IResult<T>>;
|
47 | /**
|
48 | * Resolve the current dialog.
|
49 | *
|
50 | * @param index - An optional index to the button to resolve.
|
51 | *
|
52 | * #### Notes
|
53 | * Will default to the defaultIndex.
|
54 | * Will resolve the current `show()` with the button value.
|
55 | * Will be a no-op if the dialog is not shown.
|
56 | */
|
57 | resolve(index?: number): void;
|
58 | /**
|
59 | * Reject the current dialog with a default reject value.
|
60 | *
|
61 | * #### Notes
|
62 | * Will be a no-op if the dialog is not shown.
|
63 | */
|
64 | reject(): void;
|
65 | /**
|
66 | * Handle the DOM events for the directory listing.
|
67 | *
|
68 | * @param event - The DOM event sent to the widget.
|
69 | *
|
70 | * #### Notes
|
71 | * This method implements the DOM `EventListener` interface and is
|
72 | * called in response to events on the panel's DOM node. It should
|
73 | * not be called directly by user code.
|
74 | */
|
75 | handleEvent(event: Event): void;
|
76 | /**
|
77 | * A message handler invoked on an `'after-attach'` message.
|
78 | */
|
79 | protected onAfterAttach(msg: Message): void;
|
80 | /**
|
81 | * A message handler invoked on an `'after-detach'` message.
|
82 | */
|
83 | protected onAfterDetach(msg: Message): void;
|
84 | /**
|
85 | * A message handler invoked on a `'close-request'` message.
|
86 | */
|
87 | protected onCloseRequest(msg: Message): void;
|
88 | /**
|
89 | * Handle the `'input'` event for dialog's children.
|
90 | *
|
91 | * @param event - The DOM event sent to the widget
|
92 | */
|
93 | protected _evtInput(_event: InputEvent): void;
|
94 | /**
|
95 | * Handle the `'click'` event for a dialog button.
|
96 | *
|
97 | * @param event - The DOM event sent to the widget
|
98 | */
|
99 | protected _evtClick(event: MouseEvent): void;
|
100 | /**
|
101 | * Handle the `'keydown'` event for the widget.
|
102 | *
|
103 | * @param event - The DOM event sent to the widget
|
104 | */
|
105 | protected _evtKeydown(event: KeyboardEvent): void;
|
106 | /**
|
107 | * Handle the `'focus'` event for the widget.
|
108 | *
|
109 | * @param event - The DOM event sent to the widget
|
110 | */
|
111 | protected _evtFocus(event: FocusEvent): void;
|
112 | /**
|
113 | * Handle the `'mousedown'` event for the widget.
|
114 | *
|
115 | * @param event - The DOM event sent to the widget
|
116 | */
|
117 | protected _evtMouseDown(event: MouseEvent): void;
|
118 | /**
|
119 | * Resolve a button item.
|
120 | */
|
121 | private _resolve;
|
122 | private _hasValidationErrors;
|
123 | private _ready;
|
124 | private _buttonNodes;
|
125 | private _buttons;
|
126 | private _checkboxNode;
|
127 | private _original;
|
128 | private _first;
|
129 | private _primary;
|
130 | private _promise;
|
131 | private _defaultButton;
|
132 | private _host;
|
133 | private _hasClose;
|
134 | private _body;
|
135 | private _lastMouseDownInDialog;
|
136 | private _focusNodeSelector;
|
137 | private _bodyWidget;
|
138 | }
|
139 | /**
|
140 | * The namespace for Dialog class statics.
|
141 | */
|
142 | export declare namespace Dialog {
|
143 | |
144 |
|
145 |
|
146 | let translator: ITranslator;
|
147 | |
148 |
|
149 |
|
150 | type Body<T> = IBodyWidget<T> | React.ReactElement<any> | string;
|
151 | |
152 |
|
153 |
|
154 | type Header = React.ReactElement<any> | string;
|
155 | |
156 |
|
157 |
|
158 | interface IBodyWidget<T = string> extends Widget {
|
159 | |
160 |
|
161 |
|
162 | getValue?(): T;
|
163 | }
|
164 | |
165 |
|
166 |
|
167 | interface IButton {
|
168 | |
169 |
|
170 |
|
171 | ariaLabel: string;
|
172 | |
173 |
|
174 |
|
175 | label: string;
|
176 | |
177 |
|
178 |
|
179 | iconClass: string;
|
180 | |
181 |
|
182 |
|
183 | iconLabel: string;
|
184 | |
185 |
|
186 |
|
187 | caption: string;
|
188 | |
189 |
|
190 |
|
191 | className: string;
|
192 | |
193 |
|
194 |
|
195 | accept: boolean;
|
196 | |
197 |
|
198 |
|
199 | actions: Array<string>;
|
200 | |
201 |
|
202 |
|
203 | displayType: 'default' | 'warn';
|
204 | }
|
205 | |
206 |
|
207 |
|
208 | interface ICheckbox {
|
209 | |
210 |
|
211 |
|
212 | label: string;
|
213 | |
214 |
|
215 |
|
216 | caption: string;
|
217 | |
218 |
|
219 |
|
220 | checked: boolean;
|
221 | |
222 |
|
223 |
|
224 | className: string;
|
225 | }
|
226 | |
227 |
|
228 |
|
229 | interface IError {
|
230 | |
231 |
|
232 |
|
233 | message: string | React.ReactElement<any>;
|
234 | }
|
235 | |
236 |
|
237 |
|
238 | interface IOptions<T> {
|
239 | |
240 |
|
241 |
|
242 | title: Header;
|
243 | |
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 | body: Body<T>;
|
256 | |
257 |
|
258 |
|
259 | host: HTMLElement;
|
260 | |
261 |
|
262 |
|
263 | buttons: ReadonlyArray<IButton>;
|
264 | |
265 |
|
266 |
|
267 | checkbox: Partial<ICheckbox> | null;
|
268 | |
269 |
|
270 |
|
271 | defaultButton: number;
|
272 | |
273 |
|
274 |
|
275 |
|
276 |
|
277 | focusNodeSelector: string;
|
278 | |
279 |
|
280 |
|
281 |
|
282 | hasClose: boolean;
|
283 | |
284 |
|
285 |
|
286 |
|
287 | renderer: IRenderer;
|
288 | }
|
289 | |
290 |
|
291 |
|
292 | interface IRenderer {
|
293 | |
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 | createHeader<T>(title: Header, reject: () => void, options: Partial<Dialog.IOptions<T>>): Widget;
|
301 | /**
|
302 | * Create the body of the dialog.
|
303 | *
|
304 | * @param body - The input value for the body.
|
305 | *
|
306 | * @returns A widget for the body.
|
307 | */
|
308 | createBody(body: Body<any>): Widget;
|
309 | /**
|
310 | * Create the footer of the dialog.
|
311 | *
|
312 | * @param buttons - The button nodes to add to the footer.
|
313 | * @param checkbox - The checkbox node to add to the footer.
|
314 | *
|
315 | * @returns A widget for the footer.
|
316 | */
|
317 | createFooter(buttons: ReadonlyArray<HTMLElement>, checkbox: HTMLElement | null): Widget;
|
318 | /**
|
319 | * Create a button node for the dialog.
|
320 | *
|
321 | * @param button - The button data.
|
322 | *
|
323 | * @returns A node for the button.
|
324 | */
|
325 | createButtonNode(button: IButton): HTMLButtonElement;
|
326 | /**
|
327 | * Create a checkbox node for the dialog.
|
328 | *
|
329 | * @param checkbox - The checkbox data.
|
330 | *
|
331 | * @returns A node for the checkbox.
|
332 | */
|
333 | createCheckboxNode(checkbox: ICheckbox): HTMLElement;
|
334 | }
|
335 | /**
|
336 | * The result of a dialog.
|
337 | */
|
338 | interface IResult<T> {
|
339 | /**
|
340 | * The button that was pressed.
|
341 | */
|
342 | button: IButton;
|
343 | /**
|
344 | * State of the dialog checkbox.
|
345 | *
|
346 | * #### Notes
|
347 | * It will be null if no checkbox is defined for the dialog.
|
348 | */
|
349 | isChecked: boolean | null;
|
350 | /**
|
351 | * The value retrieved from `.getValue()` if given on the widget.
|
352 | */
|
353 | value: T | null;
|
354 | }
|
355 | /**
|
356 | * Create a button item.
|
357 | */
|
358 | function createButton(value: Partial<IButton>): Readonly<IButton>;
|
359 | /**
|
360 | * Create a reject button.
|
361 | */
|
362 | function cancelButton(options?: Partial<IButton>): Readonly<IButton>;
|
363 | /**
|
364 | * Create an accept button.
|
365 | */
|
366 | function okButton(options?: Partial<IButton>): Readonly<IButton>;
|
367 | /**
|
368 | * Create a warn button.
|
369 | */
|
370 | function warnButton(options?: Partial<IButton>): Readonly<IButton>;
|
371 | /**
|
372 | * Disposes all dialog instances.
|
373 | *
|
374 | * #### Notes
|
375 | * This function should only be used in tests or cases where application state
|
376 | * may be discarded.
|
377 | */
|
378 | function flush(): void;
|
379 | /**
|
380 | * The default implementation of a dialog renderer.
|
381 | */
|
382 | class Renderer {
|
383 | /**
|
384 | * Create the header of the dialog.
|
385 | *
|
386 | * @param title - The title of the dialog.
|
387 | *
|
388 | * @returns A widget for the dialog header.
|
389 | */
|
390 | createHeader<T>(title: Header, reject?: () => void, options?: Partial<Dialog.IOptions<T>>): Widget;
|
391 | /**
|
392 | * Create the body of the dialog.
|
393 | *
|
394 | * @param value - The input value for the body.
|
395 | *
|
396 | * @returns A widget for the body.
|
397 | */
|
398 | createBody(value: Body<any>): Widget;
|
399 | /**
|
400 | * Create the footer of the dialog.
|
401 | *
|
402 | * @param buttons - The buttons nodes to add to the footer.
|
403 | * @param checkbox - The checkbox node to add to the footer.
|
404 | *
|
405 | * @returns A widget for the footer.
|
406 | */
|
407 | createFooter(buttons: ReadonlyArray<HTMLElement>, checkbox: HTMLElement | null): Widget;
|
408 | /**
|
409 | * Create a button node for the dialog.
|
410 | *
|
411 | * @param button - The button data.
|
412 | *
|
413 | * @returns A node for the button.
|
414 | */
|
415 | createButtonNode(button: IButton): HTMLButtonElement;
|
416 | /**
|
417 | * Create a checkbox node for the dialog.
|
418 | *
|
419 | * @param checkbox - The checkbox data.
|
420 | *
|
421 | * @returns A node for the checkbox.
|
422 | */
|
423 | createCheckboxNode(checkbox: ICheckbox): HTMLElement;
|
424 | /**
|
425 | * Create the class name for the button.
|
426 | *
|
427 | * @param data - The data to use for the class name.
|
428 | *
|
429 | * @returns The full class name for the button.
|
430 | */
|
431 | createItemClass(data: IButton): string;
|
432 | /**
|
433 | * Render an icon element for a dialog item.
|
434 | *
|
435 | * @param data - The data to use for rendering the icon.
|
436 | *
|
437 | * @returns An HTML element representing the icon.
|
438 | */
|
439 | renderIcon(data: IButton): HTMLElement;
|
440 | /**
|
441 | * Create the class name for the button icon.
|
442 | *
|
443 | * @param data - The data to use for the class name.
|
444 | *
|
445 | * @returns The full class name for the item icon.
|
446 | */
|
447 | createIconClass(data: IButton): string;
|
448 | /**
|
449 | * Render the label element for a button.
|
450 | *
|
451 | * @param data - The data to use for rendering the label.
|
452 | *
|
453 | * @returns An HTML element representing the item label.
|
454 | */
|
455 | renderLabel(data: IButton): HTMLElement;
|
456 | }
|
457 | /**
|
458 | * The default renderer instance.
|
459 | */
|
460 | const defaultRenderer: Renderer;
|
461 | /**
|
462 | * The dialog widget tracker.
|
463 | */
|
464 | const tracker: WidgetTracker<Dialog<any>>;
|
465 | }
|
466 |
|
\ | No newline at end of file |