UNPKG

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