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 `'click'` event for a dialog button.
|
90 | *
|
91 | * @param event - The DOM event sent to the widget
|
92 | */
|
93 | protected _evtClick(event: MouseEvent): void;
|
94 | /**
|
95 | * Handle the `'keydown'` event for the widget.
|
96 | *
|
97 | * @param event - The DOM event sent to the widget
|
98 | */
|
99 | protected _evtKeydown(event: KeyboardEvent): void;
|
100 | /**
|
101 | * Handle the `'focus'` event for the widget.
|
102 | *
|
103 | * @param event - The DOM event sent to the widget
|
104 | */
|
105 | protected _evtFocus(event: FocusEvent): void;
|
106 | /**
|
107 | * Handle the `'mousedown'` event for the widget.
|
108 | *
|
109 | * @param event - The DOM event sent to the widget
|
110 | */
|
111 | protected _evtMouseDown(event: MouseEvent): void;
|
112 | /**
|
113 | * Resolve a button item.
|
114 | */
|
115 | private _resolve;
|
116 | private _ready;
|
117 | private _buttonNodes;
|
118 | private _buttons;
|
119 | private _checkboxNode;
|
120 | private _original;
|
121 | private _first;
|
122 | private _primary;
|
123 | private _promise;
|
124 | private _defaultButton;
|
125 | private _host;
|
126 | private _hasClose;
|
127 | private _body;
|
128 | private _lastMouseDownInDialog;
|
129 | private _focusNodeSelector;
|
130 | private _bodyWidget;
|
131 | }
|
132 | /**
|
133 | * The namespace for Dialog class statics.
|
134 | */
|
135 | export declare namespace Dialog {
|
136 | |
137 |
|
138 |
|
139 | let translator: ITranslator;
|
140 | |
141 |
|
142 |
|
143 | type Body<T> = IBodyWidget<T> | React.ReactElement<any> | string;
|
144 | |
145 |
|
146 |
|
147 | type Header = React.ReactElement<any> | string;
|
148 | |
149 |
|
150 |
|
151 | interface IBodyWidget<T = string> extends Widget {
|
152 | |
153 |
|
154 |
|
155 | getValue?(): T;
|
156 | }
|
157 | |
158 |
|
159 |
|
160 | interface IButton {
|
161 | |
162 |
|
163 |
|
164 | ariaLabel: string;
|
165 | |
166 |
|
167 |
|
168 | label: string;
|
169 | |
170 |
|
171 |
|
172 | iconClass: string;
|
173 | |
174 |
|
175 |
|
176 | iconLabel: string;
|
177 | |
178 |
|
179 |
|
180 | caption: string;
|
181 | |
182 |
|
183 |
|
184 | className: string;
|
185 | |
186 |
|
187 |
|
188 | accept: boolean;
|
189 | |
190 |
|
191 |
|
192 | actions: Array<string>;
|
193 | |
194 |
|
195 |
|
196 | displayType: 'default' | 'warn';
|
197 | }
|
198 | |
199 |
|
200 |
|
201 | interface ICheckbox {
|
202 | |
203 |
|
204 |
|
205 | label: string;
|
206 | |
207 |
|
208 |
|
209 | caption: string;
|
210 | |
211 |
|
212 |
|
213 | checked: boolean;
|
214 | |
215 |
|
216 |
|
217 | className: string;
|
218 | }
|
219 | |
220 |
|
221 |
|
222 | interface IError {
|
223 | |
224 |
|
225 |
|
226 | message: string | React.ReactElement<any>;
|
227 | }
|
228 | |
229 |
|
230 |
|
231 | interface IOptions<T> {
|
232 | |
233 |
|
234 |
|
235 | title: Header;
|
236 | |
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 | body: Body<T>;
|
249 | |
250 |
|
251 |
|
252 | host: HTMLElement;
|
253 | |
254 |
|
255 |
|
256 | buttons: ReadonlyArray<IButton>;
|
257 | |
258 |
|
259 |
|
260 | checkbox: Partial<ICheckbox> | null;
|
261 | |
262 |
|
263 |
|
264 | defaultButton: number;
|
265 | |
266 |
|
267 |
|
268 |
|
269 |
|
270 | focusNodeSelector: string;
|
271 | |
272 |
|
273 |
|
274 |
|
275 | hasClose: boolean;
|
276 | |
277 |
|
278 |
|
279 |
|
280 | renderer: IRenderer;
|
281 | }
|
282 | |
283 |
|
284 |
|
285 | interface IRenderer {
|
286 | |
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 | createHeader<T>(title: Header, reject: () => void, options: Partial<Dialog.IOptions<T>>): Widget;
|
294 | /**
|
295 | * Create the body of the dialog.
|
296 | *
|
297 | * @param body - The input value for the body.
|
298 | *
|
299 | * @returns A widget for the body.
|
300 | */
|
301 | createBody(body: Body<any>): Widget;
|
302 | /**
|
303 | * Create the footer of the dialog.
|
304 | *
|
305 | * @param buttons - The button nodes to add to the footer.
|
306 | * @param checkbox - The checkbox node to add to the footer.
|
307 | *
|
308 | * @returns A widget for the footer.
|
309 | */
|
310 | createFooter(buttons: ReadonlyArray<HTMLElement>, checkbox: HTMLElement | null): Widget;
|
311 | /**
|
312 | * Create a button node for the dialog.
|
313 | *
|
314 | * @param button - The button data.
|
315 | *
|
316 | * @returns A node for the button.
|
317 | */
|
318 | createButtonNode(button: IButton): HTMLElement;
|
319 | /**
|
320 | * Create a checkbox node for the dialog.
|
321 | *
|
322 | * @param checkbox - The checkbox data.
|
323 | *
|
324 | * @returns A node for the checkbox.
|
325 | */
|
326 | createCheckboxNode(checkbox: ICheckbox): HTMLElement;
|
327 | }
|
328 | /**
|
329 | * The result of a dialog.
|
330 | */
|
331 | interface IResult<T> {
|
332 | /**
|
333 | * The button that was pressed.
|
334 | */
|
335 | button: IButton;
|
336 | /**
|
337 | * State of the dialog checkbox.
|
338 | *
|
339 | * #### Notes
|
340 | * It will be null if no checkbox is defined for the dialog.
|
341 | */
|
342 | isChecked: boolean | null;
|
343 | /**
|
344 | * The value retrieved from `.getValue()` if given on the widget.
|
345 | */
|
346 | value: T | null;
|
347 | }
|
348 | /**
|
349 | * Create a button item.
|
350 | */
|
351 | function createButton(value: Partial<IButton>): Readonly<IButton>;
|
352 | /**
|
353 | * Create a reject button.
|
354 | */
|
355 | function cancelButton(options?: Partial<IButton>): Readonly<IButton>;
|
356 | /**
|
357 | * Create an accept button.
|
358 | */
|
359 | function okButton(options?: Partial<IButton>): Readonly<IButton>;
|
360 | /**
|
361 | * Create a warn button.
|
362 | */
|
363 | function warnButton(options?: Partial<IButton>): Readonly<IButton>;
|
364 | /**
|
365 | * Disposes all dialog instances.
|
366 | *
|
367 | * #### Notes
|
368 | * This function should only be used in tests or cases where application state
|
369 | * may be discarded.
|
370 | */
|
371 | function flush(): void;
|
372 | /**
|
373 | * The default implementation of a dialog renderer.
|
374 | */
|
375 | class Renderer {
|
376 | /**
|
377 | * Create the header of the dialog.
|
378 | *
|
379 | * @param title - The title of the dialog.
|
380 | *
|
381 | * @returns A widget for the dialog header.
|
382 | */
|
383 | createHeader<T>(title: Header, reject?: () => void, options?: Partial<Dialog.IOptions<T>>): Widget;
|
384 | /**
|
385 | * Create the body of the dialog.
|
386 | *
|
387 | * @param value - The input value for the body.
|
388 | *
|
389 | * @returns A widget for the body.
|
390 | */
|
391 | createBody(value: Body<any>): Widget;
|
392 | /**
|
393 | * Create the footer of the dialog.
|
394 | *
|
395 | * @param buttons - The buttons nodes to add to the footer.
|
396 | * @param checkbox - The checkbox node to add to the footer.
|
397 | *
|
398 | * @returns A widget for the footer.
|
399 | */
|
400 | createFooter(buttons: ReadonlyArray<HTMLElement>, checkbox: HTMLElement | null): Widget;
|
401 | /**
|
402 | * Create a button node for the dialog.
|
403 | *
|
404 | * @param button - The button data.
|
405 | *
|
406 | * @returns A node for the button.
|
407 | */
|
408 | createButtonNode(button: IButton): HTMLElement;
|
409 | /**
|
410 | * Create a checkbox node for the dialog.
|
411 | *
|
412 | * @param checkbox - The checkbox data.
|
413 | *
|
414 | * @returns A node for the checkbox.
|
415 | */
|
416 | createCheckboxNode(checkbox: ICheckbox): HTMLElement;
|
417 | /**
|
418 | * Create the class name for the button.
|
419 | *
|
420 | * @param data - The data to use for the class name.
|
421 | *
|
422 | * @returns The full class name for the button.
|
423 | */
|
424 | createItemClass(data: IButton): string;
|
425 | /**
|
426 | * Render an icon element for a dialog item.
|
427 | *
|
428 | * @param data - The data to use for rendering the icon.
|
429 | *
|
430 | * @returns An HTML element representing the icon.
|
431 | */
|
432 | renderIcon(data: IButton): HTMLElement;
|
433 | /**
|
434 | * Create the class name for the button icon.
|
435 | *
|
436 | * @param data - The data to use for the class name.
|
437 | *
|
438 | * @returns The full class name for the item icon.
|
439 | */
|
440 | createIconClass(data: IButton): string;
|
441 | /**
|
442 | * Render the label element for a button.
|
443 | *
|
444 | * @param data - The data to use for rendering the label.
|
445 | *
|
446 | * @returns An HTML element representing the item label.
|
447 | */
|
448 | renderLabel(data: IButton): HTMLElement;
|
449 | }
|
450 | /**
|
451 | * The default renderer instance.
|
452 | */
|
453 | const defaultRenderer: Renderer;
|
454 | /**
|
455 | * The dialog widget tracker.
|
456 | */
|
457 | const tracker: WidgetTracker<Dialog<any>>;
|
458 | }
|
459 |
|
\ | No newline at end of file |