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 _original;
|
114 | private _first;
|
115 | private _primary;
|
116 | private _promise;
|
117 | private _defaultButton;
|
118 | private _host;
|
119 | private _hasClose;
|
120 | private _body;
|
121 | private _lastMouseDownInDialog;
|
122 | private _focusNodeSelector;
|
123 | }
|
124 | /**
|
125 | * The namespace for Dialog class statics.
|
126 | */
|
127 | export declare namespace Dialog {
|
128 | |
129 |
|
130 |
|
131 | type Body<T> = IBodyWidget<T> | React.ReactElement<any> | string;
|
132 | |
133 |
|
134 |
|
135 | type Header = React.ReactElement<any> | string;
|
136 | |
137 |
|
138 |
|
139 | interface IBodyWidget<T = string> extends Widget {
|
140 | |
141 |
|
142 |
|
143 | getValue?(): T;
|
144 | }
|
145 | |
146 |
|
147 |
|
148 | interface IButton {
|
149 | |
150 |
|
151 |
|
152 | label: string;
|
153 | |
154 |
|
155 |
|
156 | iconClass: string;
|
157 | |
158 |
|
159 |
|
160 | iconLabel: string;
|
161 | |
162 |
|
163 |
|
164 | caption: string;
|
165 | |
166 |
|
167 |
|
168 | className: string;
|
169 | |
170 |
|
171 |
|
172 | accept: boolean;
|
173 | |
174 |
|
175 |
|
176 | actions: Array<string>;
|
177 | |
178 |
|
179 |
|
180 | displayType: 'default' | 'warn';
|
181 | }
|
182 | |
183 |
|
184 |
|
185 | interface IOptions<T> {
|
186 | |
187 |
|
188 |
|
189 | title: Header;
|
190 | |
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 | body: Body<T>;
|
203 | |
204 |
|
205 |
|
206 | host: HTMLElement;
|
207 | |
208 |
|
209 |
|
210 | buttons: ReadonlyArray<IButton>;
|
211 | |
212 |
|
213 |
|
214 | defaultButton: number;
|
215 | |
216 |
|
217 |
|
218 |
|
219 |
|
220 | focusNodeSelector: string;
|
221 | |
222 |
|
223 |
|
224 |
|
225 | hasClose: boolean;
|
226 | |
227 |
|
228 |
|
229 |
|
230 | renderer: IRenderer;
|
231 | }
|
232 | |
233 |
|
234 |
|
235 | interface IRenderer {
|
236 | |
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 | createHeader<T>(title: Header, reject: () => void, options: Partial<Dialog.IOptions<T>>): Widget;
|
244 | /**
|
245 | * Create the body of the dialog.
|
246 | *
|
247 | * @param value - The input value for the body.
|
248 | *
|
249 | * @returns A widget for the body.
|
250 | */
|
251 | createBody(body: Body<any>): Widget;
|
252 | /**
|
253 | * Create the footer of the dialog.
|
254 | *
|
255 | * @param buttons - The button nodes to add to the footer.
|
256 | *
|
257 | * @returns A widget for the footer.
|
258 | */
|
259 | createFooter(buttons: ReadonlyArray<HTMLElement>): Widget;
|
260 | /**
|
261 | * Create a button node for the dialog.
|
262 | *
|
263 | * @param button - The button data.
|
264 | *
|
265 | * @returns A node for the button.
|
266 | */
|
267 | createButtonNode(button: IButton): HTMLElement;
|
268 | }
|
269 | /**
|
270 | * The result of a dialog.
|
271 | */
|
272 | interface IResult<T> {
|
273 | /**
|
274 | * The button that was pressed.
|
275 | */
|
276 | button: IButton;
|
277 | /**
|
278 | * The value retrieved from `.getValue()` if given on the widget.
|
279 | */
|
280 | value: T | null;
|
281 | }
|
282 | /**
|
283 | * Create a button item.
|
284 | */
|
285 | function createButton(value: Partial<IButton>): Readonly<IButton>;
|
286 | /**
|
287 | * Create a reject button.
|
288 | */
|
289 | function cancelButton(options?: Partial<IButton>): Readonly<IButton>;
|
290 | /**
|
291 | * Create an accept button.
|
292 | */
|
293 | function okButton(options?: Partial<IButton>): Readonly<IButton>;
|
294 | /**
|
295 | * Create a warn button.
|
296 | */
|
297 | function warnButton(options?: Partial<IButton>): Readonly<IButton>;
|
298 | /**
|
299 | * Disposes all dialog instances.
|
300 | *
|
301 | * #### Notes
|
302 | * This function should only be used in tests or cases where application state
|
303 | * may be discarded.
|
304 | */
|
305 | function flush(): void;
|
306 | /**
|
307 | * The default implementation of a dialog renderer.
|
308 | */
|
309 | class Renderer {
|
310 | /**
|
311 | * Create the header of the dialog.
|
312 | *
|
313 | * @param title - The title of the dialog.
|
314 | *
|
315 | * @returns A widget for the dialog header.
|
316 | */
|
317 | createHeader<T>(title: Header, reject?: () => void, options?: Partial<Dialog.IOptions<T>>): Widget;
|
318 | /**
|
319 | * Create the body of the dialog.
|
320 | *
|
321 | * @param value - The input value for the body.
|
322 | *
|
323 | * @returns A widget for the body.
|
324 | */
|
325 | createBody(value: Body<any>): Widget;
|
326 | /**
|
327 | * Create the footer of the dialog.
|
328 | *
|
329 | * @param buttonNodes - The buttons nodes to add to the footer.
|
330 | *
|
331 | * @returns A widget for the footer.
|
332 | */
|
333 | createFooter(buttons: ReadonlyArray<HTMLElement>): Widget;
|
334 | /**
|
335 | * Create a button node for the dialog.
|
336 | *
|
337 | * @param button - The button data.
|
338 | *
|
339 | * @returns A node for the button.
|
340 | */
|
341 | createButtonNode(button: IButton): HTMLElement;
|
342 | /**
|
343 | * Create the class name for the button.
|
344 | *
|
345 | * @param data - The data to use for the class name.
|
346 | *
|
347 | * @returns The full class name for the button.
|
348 | */
|
349 | createItemClass(data: IButton): string;
|
350 | /**
|
351 | * Render an icon element for a dialog item.
|
352 | *
|
353 | * @param data - The data to use for rendering the icon.
|
354 | *
|
355 | * @returns An HTML element representing the icon.
|
356 | */
|
357 | renderIcon(data: IButton): HTMLElement;
|
358 | /**
|
359 | * Create the class name for the button icon.
|
360 | *
|
361 | * @param data - The data to use for the class name.
|
362 | *
|
363 | * @returns The full class name for the item icon.
|
364 | */
|
365 | createIconClass(data: IButton): string;
|
366 | /**
|
367 | * Render the label element for a button.
|
368 | *
|
369 | * @param data - The data to use for rendering the label.
|
370 | *
|
371 | * @returns An HTML element representing the item label.
|
372 | */
|
373 | renderLabel(data: IButton): HTMLElement;
|
374 | }
|
375 | /**
|
376 | * The default renderer instance.
|
377 | */
|
378 | const defaultRenderer: Renderer;
|
379 | /**
|
380 | * The dialog widget tracker.
|
381 | */
|
382 | const tracker: WidgetTracker<Dialog<any>>;
|
383 | }
|
384 |
|
\ | No newline at end of file |