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