1 | import { DocumentRegistry } from '@jupyterlab/docregistry';
|
2 | import { Contents } from '@jupyterlab/services';
|
3 | import { ITranslator, TranslationBundle } from '@jupyterlab/translation';
|
4 | import { Drag } from '@lumino/dragdrop';
|
5 | import { Message } from '@lumino/messaging';
|
6 | import { ISignal } from '@lumino/signaling';
|
7 | import { Widget } from '@lumino/widgets';
|
8 | import { FilterFileBrowserModel } from './model';
|
9 |
|
10 |
|
11 |
|
12 | export declare class DirListing extends Widget {
|
13 | |
14 |
|
15 |
|
16 |
|
17 |
|
18 | constructor(options: DirListing.IOptions);
|
19 | /**
|
20 | * Dispose of the resources held by the directory listing.
|
21 | */
|
22 | dispose(): void;
|
23 | /**
|
24 | * Get the model used by the listing.
|
25 | */
|
26 | get model(): FilterFileBrowserModel;
|
27 | /**
|
28 | * Get the dir listing header node.
|
29 | *
|
30 | * #### Notes
|
31 | * This is the node which holds the header cells.
|
32 | *
|
33 | * Modifying this node directly can lead to undefined behavior.
|
34 | */
|
35 | get headerNode(): HTMLElement;
|
36 | /**
|
37 | * Get the dir listing content node.
|
38 | *
|
39 | * #### Notes
|
40 | * This is the node which holds the item nodes.
|
41 | *
|
42 | * Modifying this node directly can lead to undefined behavior.
|
43 | */
|
44 | get contentNode(): HTMLElement;
|
45 | /**
|
46 | * The renderer instance used by the directory listing.
|
47 | */
|
48 | get renderer(): DirListing.IRenderer;
|
49 | /**
|
50 | * The current sort state.
|
51 | */
|
52 | get sortState(): DirListing.ISortState;
|
53 | /**
|
54 | * A signal fired when an item is opened.
|
55 | */
|
56 | get onItemOpened(): ISignal<DirListing, Contents.IModel>;
|
57 | /**
|
58 | * Create an iterator over the listing's selected items.
|
59 | *
|
60 | * @returns A new iterator over the listing's selected items.
|
61 | */
|
62 | selectedItems(): IterableIterator<Contents.IModel>;
|
63 | /**
|
64 | * Create an iterator over the listing's sorted items.
|
65 | *
|
66 | * @returns A new iterator over the listing's sorted items.
|
67 | */
|
68 | sortedItems(): IterableIterator<Contents.IModel>;
|
69 | /**
|
70 | * Sort the items using a sort condition.
|
71 | */
|
72 | sort(state: DirListing.ISortState): void;
|
73 | /**
|
74 | * Rename the first currently selected item.
|
75 | *
|
76 | * @returns A promise that resolves with the new name of the item.
|
77 | */
|
78 | rename(): Promise<string>;
|
79 | /**
|
80 | * Cut the selected items.
|
81 | */
|
82 | cut(): void;
|
83 | /**
|
84 | * Copy the selected items.
|
85 | */
|
86 | copy(): void;
|
87 | /**
|
88 | * Paste the items from the clipboard.
|
89 | *
|
90 | * @returns A promise that resolves when the operation is complete.
|
91 | */
|
92 | paste(): Promise<void>;
|
93 | /**
|
94 | * Delete the currently selected item(s).
|
95 | *
|
96 | * @returns A promise that resolves when the operation is complete.
|
97 | */
|
98 | delete(): Promise<void>;
|
99 | /**
|
100 | * Duplicate the currently selected item(s).
|
101 | *
|
102 | * @returns A promise that resolves when the operation is complete.
|
103 | */
|
104 | duplicate(): Promise<void>;
|
105 | /**
|
106 | * Download the currently selected item(s).
|
107 | */
|
108 | download(): Promise<void>;
|
109 | /**
|
110 | * Shut down kernels on the applicable currently selected items.
|
111 | *
|
112 | * @returns A promise that resolves when the operation is complete.
|
113 | */
|
114 | shutdownKernels(): Promise<void>;
|
115 | /**
|
116 | * Select next item.
|
117 | *
|
118 | * @param keepExisting - Whether to keep the current selection and add to it.
|
119 | */
|
120 | selectNext(keepExisting?: boolean): void;
|
121 | /**
|
122 | * Select previous item.
|
123 | *
|
124 | * @param keepExisting - Whether to keep the current selection and add to it.
|
125 | */
|
126 | selectPrevious(keepExisting?: boolean): void;
|
127 | /**
|
128 | * Select the first item that starts with prefix being typed.
|
129 | */
|
130 | selectByPrefix(): void;
|
131 | /**
|
132 | * Get whether an item is selected by name.
|
133 | *
|
134 | * @param name - The name of of the item.
|
135 | *
|
136 | * @returns Whether the item is selected.
|
137 | */
|
138 | isSelected(name: string): boolean;
|
139 | /**
|
140 | * Find a model given a click.
|
141 | *
|
142 | * @param event - The mouse event.
|
143 | *
|
144 | * @returns The model for the selected file.
|
145 | */
|
146 | modelForClick(event: MouseEvent): Contents.IModel | undefined;
|
147 | /**
|
148 | * Clear the selected items.
|
149 | */
|
150 | clearSelectedItems(): void;
|
151 | /**
|
152 | * Select an item by name.
|
153 | *
|
154 | * @param name - The name of the item to select.
|
155 | * @param focus - Whether to move focus to the selected item.
|
156 | *
|
157 | * @returns A promise that resolves when the name is selected.
|
158 | */
|
159 | selectItemByName(name: string, focus?: boolean): Promise<void>;
|
160 | /**
|
161 | * Handle the DOM events for the directory listing.
|
162 | *
|
163 | * @param event - The DOM event sent to the widget.
|
164 | *
|
165 | * #### Notes
|
166 | * This method implements the DOM `EventListener` interface and is
|
167 | * called in response to events on the panel's DOM node. It should
|
168 | * not be called directly by user code.
|
169 | */
|
170 | handleEvent(event: Event): void;
|
171 | /**
|
172 | * A message handler invoked on an `'after-attach'` message.
|
173 | */
|
174 | protected onAfterAttach(msg: Message): void;
|
175 | /**
|
176 | * A message handler invoked on a `'before-detach'` message.
|
177 | */
|
178 | protected onBeforeDetach(msg: Message): void;
|
179 | /**
|
180 | * A message handler invoked on an `'after-show'` message.
|
181 | */
|
182 | protected onAfterShow(msg: Message): void;
|
183 | /**
|
184 | * A handler invoked on an `'update-request'` message.
|
185 | */
|
186 | protected onUpdateRequest(msg: Message): void;
|
187 | onResize(msg: Widget.ResizeMessage): void;
|
188 | setColumnVisibility(name: DirListing.ToggleableColumn, visible: boolean): void;
|
189 | /**
|
190 | * Update the setting to sort notebooks above files.
|
191 | * This sorts the items again if the internal value is modified.
|
192 | */
|
193 | setNotebooksFirstSorting(isEnabled: boolean): void;
|
194 | /**
|
195 | * Would this click (or other event type) hit the checkbox by default?
|
196 | */
|
197 | protected isWithinCheckboxHitArea(event: Event): boolean;
|
198 | /**
|
199 | * Handle the `'click'` event for the widget.
|
200 | */
|
201 | private _evtClick;
|
202 | /**
|
203 | * Handle the `'scroll'` event for the widget.
|
204 | */
|
205 | private _evtScroll;
|
206 | /**
|
207 | * Handle the `'mousedown'` event for the widget.
|
208 | */
|
209 | private _evtMousedown;
|
210 | /**
|
211 | * Handle the `'mouseup'` event for the widget.
|
212 | */
|
213 | private _evtMouseup;
|
214 | /**
|
215 | * Handle the `'mousemove'` event for the widget.
|
216 | */
|
217 | private _evtMousemove;
|
218 | /**
|
219 | * Handle the opening of an item.
|
220 | */
|
221 | protected handleOpen(item: Contents.IModel): void;
|
222 | /**
|
223 | * Calculate the next focus index, given the current focus index and a
|
224 | * direction, keeping within the bounds of the directory listing.
|
225 | *
|
226 | * @param index Current focus index
|
227 | * @param direction -1 (up) or 1 (down)
|
228 | * @returns The next focus index, which could be the same as the current focus
|
229 | * index if at the boundary.
|
230 | */
|
231 | private _getNextFocusIndex;
|
232 | /**
|
233 | * Handle the up or down arrow key.
|
234 | *
|
235 | * @param event The keyboard event
|
236 | * @param direction -1 (up) or 1 (down)
|
237 | */
|
238 | private _handleArrowY;
|
239 | /**
|
240 | * cd ..
|
241 | *
|
242 | * Go up one level in the directory tree.
|
243 | */
|
244 | goUp(): Promise<void>;
|
245 | /**
|
246 | * Handle the `'keydown'` event for the widget.
|
247 | */
|
248 | protected evtKeydown(event: KeyboardEvent): void;
|
249 | /**
|
250 | * Handle the `'dblclick'` event for the widget.
|
251 | */
|
252 | protected evtDblClick(event: MouseEvent): void;
|
253 | /**
|
254 | * Handle the `drop` event for the widget.
|
255 | */
|
256 | protected evtNativeDrop(event: DragEvent): void;
|
257 | /**
|
258 | * Handle the `'lm-dragenter'` event for the widget.
|
259 | */
|
260 | protected evtDragEnter(event: Drag.Event): void;
|
261 | /**
|
262 | * Handle the `'lm-dragleave'` event for the widget.
|
263 | */
|
264 | protected evtDragLeave(event: Drag.Event): void;
|
265 | /**
|
266 | * Handle the `'lm-dragover'` event for the widget.
|
267 | */
|
268 | protected evtDragOver(event: Drag.Event): void;
|
269 | /**
|
270 | * Handle the `'lm-drop'` event for the widget.
|
271 | */
|
272 | protected evtDrop(event: Drag.Event): void;
|
273 | /**
|
274 | * Start a drag event.
|
275 | */
|
276 | private _startDrag;
|
277 | /**
|
278 | * Handle selection on a file node.
|
279 | */
|
280 | protected handleFileSelect(event: MouseEvent): void;
|
281 | /**
|
282 | * (Re-)focus an item in the directory listing.
|
283 | *
|
284 | * @param index The index of the item node to focus
|
285 | */
|
286 | private _focusItem;
|
287 | /**
|
288 | * Are all of the items between two provided indices selected?
|
289 | *
|
290 | * The items at the indices are not considered.
|
291 | *
|
292 | * @param j Index of one item.
|
293 | * @param k Index of another item. Note: may be less or greater than first
|
294 | * index.
|
295 | * @returns True if and only if all items between the j and k are selected.
|
296 | * Returns undefined if j and k are the same.
|
297 | */
|
298 | private _allSelectedBetween;
|
299 | /**
|
300 | * Handle a multiple select on a file item node.
|
301 | */
|
302 | private _handleMultiSelect;
|
303 | /**
|
304 | * Copy the selected items, and optionally cut as well.
|
305 | */
|
306 | private _copy;
|
307 | /**
|
308 | * Delete the files with the given paths.
|
309 | */
|
310 | private _delete;
|
311 | /**
|
312 | * Allow the user to rename item on a given row.
|
313 | */
|
314 | private _doRename;
|
315 | /**
|
316 | * Select a given item.
|
317 | */
|
318 | private _selectItem;
|
319 | /**
|
320 | * Handle the `refreshed` signal from the model.
|
321 | */
|
322 | private _onModelRefreshed;
|
323 | /**
|
324 | * Handle a `pathChanged` signal from the model.
|
325 | */
|
326 | private _onPathChanged;
|
327 | /**
|
328 | * Handle a `fileChanged` signal from the model.
|
329 | */
|
330 | private _onFileChanged;
|
331 | /**
|
332 | * Handle an `activateRequested` signal from the manager.
|
333 | */
|
334 | private _onActivateRequested;
|
335 | protected translator: ITranslator;
|
336 | protected _model: FilterFileBrowserModel;
|
337 | private _trans;
|
338 | private _editNode;
|
339 | private _items;
|
340 | private _sortedItems;
|
341 | private _sortState;
|
342 | private _onItemOpened;
|
343 | private _drag;
|
344 | private _dragData;
|
345 | private _selectTimer;
|
346 | private _isCut;
|
347 | private _prevPath;
|
348 | private _clipboard;
|
349 | private _manager;
|
350 | private _softSelection;
|
351 | protected selection: {
|
352 | [key: string]: boolean;
|
353 | };
|
354 | private _renderer;
|
355 | private _searchPrefix;
|
356 | private _searchPrefixTimer;
|
357 | private _inRename;
|
358 | private _isDirty;
|
359 | private _hiddenColumns;
|
360 | private _sortNotebooksFirst;
|
361 | private _focusIndex;
|
362 | }
|
363 |
|
364 |
|
365 |
|
366 | export declare namespace DirListing {
|
367 | |
368 |
|
369 |
|
370 | interface IOptions {
|
371 | |
372 |
|
373 |
|
374 | model: FilterFileBrowserModel;
|
375 | |
376 |
|
377 |
|
378 |
|
379 |
|
380 | renderer?: IRenderer;
|
381 | |
382 |
|
383 |
|
384 | translator?: ITranslator;
|
385 | }
|
386 | |
387 |
|
388 |
|
389 | interface ISortState {
|
390 | |
391 |
|
392 |
|
393 | direction: 'ascending' | 'descending';
|
394 | |
395 |
|
396 |
|
397 | key: 'name' | 'last_modified' | 'file_size';
|
398 | }
|
399 | |
400 |
|
401 |
|
402 | type ToggleableColumn = 'last_modified' | 'is_selected' | 'file_size';
|
403 | |
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 | interface IContentsThunk {
|
411 | |
412 |
|
413 |
|
414 | model: Contents.IModel;
|
415 | |
416 |
|
417 |
|
418 | withContent: () => Promise<Contents.IModel>;
|
419 | }
|
420 | |
421 |
|
422 |
|
423 | interface IRenderer {
|
424 | |
425 |
|
426 |
|
427 | createNode(): HTMLElement;
|
428 | |
429 |
|
430 |
|
431 |
|
432 |
|
433 | populateHeaderNode(node: HTMLElement, translator?: ITranslator, hiddenColumns?: Set<DirListing.ToggleableColumn>): void;
|
434 | |
435 |
|
436 |
|
437 |
|
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 | handleHeaderClick(node: HTMLElement, event: MouseEvent): ISortState | null;
|
444 | |
445 |
|
446 |
|
447 |
|
448 |
|
449 | createItemNode(hiddenColumns?: Set<DirListing.ToggleableColumn>): HTMLElement;
|
450 | |
451 |
|
452 |
|
453 |
|
454 |
|
455 |
|
456 |
|
457 |
|
458 |
|
459 | updateItemNode(node: HTMLElement, model: Contents.IModel, fileType?: DocumentRegistry.IFileType, translator?: ITranslator, hiddenColumns?: Set<DirListing.ToggleableColumn>, selected?: boolean): void;
|
460 | |
461 |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 |
|
467 | getNameNode(node: HTMLElement): HTMLElement;
|
468 | |
469 |
|
470 |
|
471 |
|
472 |
|
473 |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 |
|
480 | getCheckboxNode: (node: HTMLElement) => HTMLInputElement | null;
|
481 | |
482 |
|
483 |
|
484 |
|
485 |
|
486 |
|
487 |
|
488 |
|
489 |
|
490 |
|
491 |
|
492 | createDragImage(node: HTMLElement, count: number, trans: TranslationBundle, fileType?: DocumentRegistry.IFileType): HTMLElement;
|
493 | }
|
494 | |
495 |
|
496 |
|
497 | class Renderer implements IRenderer {
|
498 | |
499 |
|
500 |
|
501 | createNode(): HTMLElement;
|
502 | |
503 |
|
504 |
|
505 |
|
506 |
|
507 | populateHeaderNode(node: HTMLElement, translator?: ITranslator, hiddenColumns?: Set<DirListing.ToggleableColumn>): void;
|
508 | |
509 |
|
510 |
|
511 |
|
512 |
|
513 |
|
514 |
|
515 |
|
516 |
|
517 | handleHeaderClick(node: HTMLElement, event: MouseEvent): ISortState | null;
|
518 | |
519 |
|
520 |
|
521 |
|
522 |
|
523 | createItemNode(hiddenColumns?: Set<DirListing.ToggleableColumn>): HTMLElement;
|
524 | |
525 |
|
526 |
|
527 |
|
528 |
|
529 |
|
530 |
|
531 |
|
532 |
|
533 |
|
534 |
|
535 |
|
536 |
|
537 |
|
538 | createCheckboxWrapperNode(options?: {
|
539 | alwaysVisible: boolean;
|
540 | }): HTMLElement;
|
541 | |
542 |
|
543 |
|
544 |
|
545 |
|
546 |
|
547 |
|
548 |
|
549 |
|
550 |
|
551 | updateItemNode(node: HTMLElement, model: Contents.IModel, fileType?: DocumentRegistry.IFileType, translator?: ITranslator, hiddenColumns?: Set<DirListing.ToggleableColumn>, selected?: boolean): void;
|
552 | |
553 |
|
554 |
|
555 |
|
556 |
|
557 |
|
558 |
|
559 | getNameNode(node: HTMLElement): HTMLElement;
|
560 | |
561 |
|
562 |
|
563 |
|
564 |
|
565 |
|
566 |
|
567 |
|
568 | getCheckboxNode(node: HTMLElement): HTMLInputElement | null;
|
569 | |
570 |
|
571 |
|
572 |
|
573 |
|
574 |
|
575 |
|
576 |
|
577 |
|
578 |
|
579 |
|
580 | createDragImage(node: HTMLElement, count: number, trans: TranslationBundle, fileType?: DocumentRegistry.IFileType): HTMLElement;
|
581 | |
582 |
|
583 |
|
584 | protected createHeaderItemNode(label: string): HTMLElement;
|
585 | }
|
586 | |
587 |
|
588 |
|
589 | const defaultRenderer: Renderer;
|
590 | }
|