UNPKG

18.5 kBTypeScriptView Raw
1import { DocumentRegistry } from '@jupyterlab/docregistry';
2import { Contents } from '@jupyterlab/services';
3import { ITranslator, TranslationBundle } from '@jupyterlab/translation';
4import { Drag } from '@lumino/dragdrop';
5import { Message } from '@lumino/messaging';
6import { ISignal } from '@lumino/signaling';
7import { Widget } from '@lumino/widgets';
8import { FilterFileBrowserModel } from './model';
9/**
10 * A widget which hosts a file list area.
11 */
12export declare class DirListing extends Widget {
13 /**
14 * Construct a new file browser directory listing widget.
15 *
16 * @param model - The file browser view model.
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 * The namespace for the `DirListing` class statics.
365 */
366export declare namespace DirListing {
367 /**
368 * An options object for initializing a file browser directory listing.
369 */
370 interface IOptions {
371 /**
372 * A file browser model instance.
373 */
374 model: FilterFileBrowserModel;
375 /**
376 * A renderer for file items.
377 *
378 * The default is a shared `Renderer` instance.
379 */
380 renderer?: IRenderer;
381 /**
382 * A language translator.
383 */
384 translator?: ITranslator;
385 }
386 /**
387 * A sort state.
388 */
389 interface ISortState {
390 /**
391 * The direction of sort.
392 */
393 direction: 'ascending' | 'descending';
394 /**
395 * The sort key.
396 */
397 key: 'name' | 'last_modified' | 'file_size';
398 }
399 /**
400 * Toggleable columns.
401 */
402 type ToggleableColumn = 'last_modified' | 'is_selected' | 'file_size';
403 /**
404 * A file contents model thunk.
405 *
406 * Note: The content of the model will be empty.
407 * To get the contents, call and await the `withContent`
408 * method.
409 */
410 interface IContentsThunk {
411 /**
412 * The contents model.
413 */
414 model: Contents.IModel;
415 /**
416 * Fetches the model with contents.
417 */
418 withContent: () => Promise<Contents.IModel>;
419 }
420 /**
421 * The render interface for file browser listing options.
422 */
423 interface IRenderer {
424 /**
425 * Create the DOM node for a dir listing.
426 */
427 createNode(): HTMLElement;
428 /**
429 * Populate and empty header node for a dir listing.
430 *
431 * @param node - The header node to populate.
432 */
433 populateHeaderNode(node: HTMLElement, translator?: ITranslator, hiddenColumns?: Set<DirListing.ToggleableColumn>): void;
434 /**
435 * Handle a header click.
436 *
437 * @param node - A node populated by [[populateHeaderNode]].
438 *
439 * @param event - A click event on the node.
440 *
441 * @returns The sort state of the header after the click event.
442 */
443 handleHeaderClick(node: HTMLElement, event: MouseEvent): ISortState | null;
444 /**
445 * Create a new item node for a dir listing.
446 *
447 * @returns A new DOM node to use as a content item.
448 */
449 createItemNode(hiddenColumns?: Set<DirListing.ToggleableColumn>): HTMLElement;
450 /**
451 * Update an item node to reflect the current state of a model.
452 *
453 * @param node - A node created by [[createItemNode]].
454 *
455 * @param model - The model object to use for the item state.
456 *
457 * @param fileType - The file type of the item, if applicable.
458 */
459 updateItemNode(node: HTMLElement, model: Contents.IModel, fileType?: DocumentRegistry.IFileType, translator?: ITranslator, hiddenColumns?: Set<DirListing.ToggleableColumn>, selected?: boolean): void;
460 /**
461 * Get the node containing the file name.
462 *
463 * @param node - A node created by [[createItemNode]].
464 *
465 * @returns The node containing the file name.
466 */
467 getNameNode(node: HTMLElement): HTMLElement;
468 /**
469 * Get the checkbox input element node.
470 *
471 * Downstream interface implementations,such as jupyterlab-unfold, that
472 * don't support checkboxes should simply always return null for this
473 * function.
474 *
475 * @param node A node created by [[createItemNode]] or
476 * [[createHeaderItemNode]]
477 *
478 * @returns The checkbox node.
479 */
480 getCheckboxNode: (node: HTMLElement) => HTMLInputElement | null;
481 /**
482 * Create an appropriate drag image for an item.
483 *
484 * @param node - A node created by [[createItemNode]].
485 *
486 * @param count - The number of items being dragged.
487 *
488 * @param fileType - The file type of the item, if applicable.
489 *
490 * @returns An element to use as the drag image.
491 */
492 createDragImage(node: HTMLElement, count: number, trans: TranslationBundle, fileType?: DocumentRegistry.IFileType): HTMLElement;
493 }
494 /**
495 * The default implementation of an `IRenderer`.
496 */
497 class Renderer implements IRenderer {
498 /**
499 * Create the DOM node for a dir listing.
500 */
501 createNode(): HTMLElement;
502 /**
503 * Populate and empty header node for a dir listing.
504 *
505 * @param node - The header node to populate.
506 */
507 populateHeaderNode(node: HTMLElement, translator?: ITranslator, hiddenColumns?: Set<DirListing.ToggleableColumn>): void;
508 /**
509 * Handle a header click.
510 *
511 * @param node - A node populated by [[populateHeaderNode]].
512 *
513 * @param event - A click event on the node.
514 *
515 * @returns The sort state of the header after the click event.
516 */
517 handleHeaderClick(node: HTMLElement, event: MouseEvent): ISortState | null;
518 /**
519 * Create a new item node for a dir listing.
520 *
521 * @returns A new DOM node to use as a content item.
522 */
523 createItemNode(hiddenColumns?: Set<DirListing.ToggleableColumn>): HTMLElement;
524 /**
525 * Creates a node containing a checkbox.
526 *
527 * We wrap the checkbox in a label element in order to increase its hit
528 * area. This is because the padding of the checkbox itself cannot be
529 * increased via CSS, as the CSS/form compatibility table at the following
530 * url from MDN shows:
531 * https://developer.mozilla.org/en-US/docs/Learn/Forms/Property_compatibility_table_for_form_controls#check_boxes_and_radio_buttons
532 *
533 * @param [options]
534 * @params options.alwaysVisible Should the checkbox be visible even when
535 * not hovered?
536 * @returns A new DOM node that contains a checkbox.
537 */
538 createCheckboxWrapperNode(options?: {
539 alwaysVisible: boolean;
540 }): HTMLElement;
541 /**
542 * Update an item node to reflect the current state of a model.
543 *
544 * @param node - A node created by [[createItemNode]].
545 *
546 * @param model - The model object to use for the item state.
547 *
548 * @param fileType - The file type of the item, if applicable.
549 *
550 */
551 updateItemNode(node: HTMLElement, model: Contents.IModel, fileType?: DocumentRegistry.IFileType, translator?: ITranslator, hiddenColumns?: Set<DirListing.ToggleableColumn>, selected?: boolean): void;
552 /**
553 * Get the node containing the file name.
554 *
555 * @param node - A node created by [[createItemNode]].
556 *
557 * @returns The node containing the file name.
558 */
559 getNameNode(node: HTMLElement): HTMLElement;
560 /**
561 * Get the checkbox input element node.
562 *
563 * @param node A node created by [[createItemNode]] or
564 * [[createHeaderItemNode]]
565 *
566 * @returns The checkbox node.
567 */
568 getCheckboxNode(node: HTMLElement): HTMLInputElement | null;
569 /**
570 * Create a drag image for an item.
571 *
572 * @param node - A node created by [[createItemNode]].
573 *
574 * @param count - The number of items being dragged.
575 *
576 * @param fileType - The file type of the item, if applicable.
577 *
578 * @returns An element to use as the drag image.
579 */
580 createDragImage(node: HTMLElement, count: number, trans: TranslationBundle, fileType?: DocumentRegistry.IFileType): HTMLElement;
581 /**
582 * Create a node for a header item.
583 */
584 protected createHeaderItemNode(label: string): HTMLElement;
585 }
586 /**
587 * The default `IRenderer` instance.
588 */
589 const defaultRenderer: Renderer;
590}