UNPKG

8.88 kBTypeScriptView Raw
1import { IChangedArgs } from '@jupyterlab/coreutils';
2import { IDocumentManager } from '@jupyterlab/docmanager';
3import { Contents, KernelSpec, Session } from '@jupyterlab/services';
4import { IStateDB } from '@jupyterlab/statedb';
5import { ITranslator } from '@jupyterlab/translation';
6import { IIterator, IterableOrArrayLike } from '@lumino/algorithm';
7import { IDisposable } from '@lumino/disposable';
8import { ISignal } from '@lumino/signaling';
9/**
10 * The maximum upload size (in bytes) for notebook version < 5.1.0
11 */
12export declare const LARGE_FILE_SIZE: number;
13/**
14 * The size (in bytes) of the biggest chunk we should upload at once.
15 */
16export declare const CHUNK_SIZE: number;
17/**
18 * An upload progress event for a file at `path`.
19 */
20export interface IUploadModel {
21 path: string;
22 /**
23 * % uploaded [0, 1)
24 */
25 progress: number;
26}
27/**
28 * An implementation of a file browser model.
29 *
30 * #### Notes
31 * All paths parameters without a leading `'/'` are interpreted as relative to
32 * the current directory. Supports `'../'` syntax.
33 */
34export declare class FileBrowserModel implements IDisposable {
35 /**
36 * Construct a new file browser model.
37 */
38 constructor(options: FileBrowserModel.IOptions);
39 /**
40 * The document manager instance used by the file browser model.
41 */
42 readonly manager: IDocumentManager;
43 /**
44 * A signal emitted when the file browser model loses connection.
45 */
46 get connectionFailure(): ISignal<this, Error>;
47 /**
48 * The drive name that gets prepended to the path.
49 */
50 get driveName(): string;
51 /**
52 * A promise that resolves when the model is first restored.
53 */
54 get restored(): Promise<void>;
55 /**
56 * Get the file path changed signal.
57 */
58 get fileChanged(): ISignal<this, Contents.IChangedArgs>;
59 /**
60 * Get the current path.
61 */
62 get path(): string;
63 /**
64 * Get the root path
65 */
66 get rootPath(): string;
67 /**
68 * A signal emitted when the path changes.
69 */
70 get pathChanged(): ISignal<this, IChangedArgs<string>>;
71 /**
72 * A signal emitted when the directory listing is refreshed.
73 */
74 get refreshed(): ISignal<this, void>;
75 /**
76 * Get the kernel spec models.
77 */
78 get specs(): KernelSpec.ISpecModels | null;
79 /**
80 * Get whether the model is disposed.
81 */
82 get isDisposed(): boolean;
83 /**
84 * A signal emitted when an upload progresses.
85 */
86 get uploadChanged(): ISignal<this, IChangedArgs<IUploadModel | null>>;
87 /**
88 * Create an iterator over the status of all in progress uploads.
89 */
90 uploads(): IIterator<IUploadModel>;
91 /**
92 * Dispose of the resources held by the model.
93 */
94 dispose(): void;
95 /**
96 * Create an iterator over the model's items.
97 *
98 * @returns A new iterator over the model's items.
99 */
100 items(): IIterator<Contents.IModel>;
101 /**
102 * Create an iterator over the active sessions in the directory.
103 *
104 * @returns A new iterator over the model's active sessions.
105 */
106 sessions(): IIterator<Session.IModel>;
107 /**
108 * Force a refresh of the directory contents.
109 */
110 refresh(): Promise<void>;
111 /**
112 * Change directory.
113 *
114 * @param path - The path to the file or directory.
115 *
116 * @returns A promise with the contents of the directory.
117 */
118 cd(newValue?: string): Promise<void>;
119 /**
120 * Download a file.
121 *
122 * @param path - The path of the file to be downloaded.
123 *
124 * @returns A promise which resolves when the file has begun
125 * downloading.
126 */
127 download(path: string): Promise<void>;
128 /**
129 * Restore the state of the file browser.
130 *
131 * @param id - The unique ID that is used to construct a state database key.
132 *
133 * @param populate - If `false`, the restoration ID will be set but the file
134 * browser state will not be fetched from the state database.
135 *
136 * @returns A promise when restoration is complete.
137 *
138 * #### Notes
139 * This function will only restore the model *once*. If it is called multiple
140 * times, all subsequent invocations are no-ops.
141 */
142 restore(id: string, populate?: boolean): Promise<void>;
143 /**
144 * Upload a `File` object.
145 *
146 * @param file - The `File` object to upload.
147 *
148 * @returns A promise containing the new file contents model.
149 *
150 * #### Notes
151 * On Notebook version < 5.1.0, this will fail to upload files that are too
152 * big to be sent in one request to the server. On newer versions, or on
153 * Jupyter Server, it will ask for confirmation then upload the file in 1 MB
154 * chunks.
155 */
156 upload(file: File): Promise<Contents.IModel>;
157 private _shouldUploadLarge;
158 /**
159 * Perform the actual upload.
160 */
161 private _upload;
162 private _uploadCheckDisposed;
163 /**
164 * Handle an updated contents model.
165 */
166 protected handleContents(contents: Contents.IModel): void;
167 /**
168 * Handle a change to the running sessions.
169 */
170 protected onRunningChanged(sender: Session.IManager, models: IterableOrArrayLike<Session.IModel>): void;
171 /**
172 * Handle a change on the contents manager.
173 */
174 protected onFileChanged(sender: Contents.IManager, change: Contents.IChangedArgs): void;
175 /**
176 * Populate the model's sessions collection.
177 */
178 private _populateSessions;
179 protected translator: ITranslator;
180 private _trans;
181 private _connectionFailure;
182 private _fileChanged;
183 private _items;
184 private _key;
185 private _model;
186 private _pathChanged;
187 private _paths;
188 private _pending;
189 private _pendingPath;
190 private _refreshed;
191 private _sessions;
192 private _state;
193 private _driveName;
194 private _isDisposed;
195 private _restored;
196 private _uploads;
197 private _uploadChanged;
198 private _unloadEventListener;
199 private _poll;
200}
201/**
202 * The namespace for the `FileBrowserModel` class statics.
203 */
204export declare namespace FileBrowserModel {
205 /**
206 * An options object for initializing a file browser.
207 */
208 interface IOptions {
209 /**
210 * Whether a file browser automatically loads its initial path.
211 * The default is `true`.
212 */
213 auto?: boolean;
214 /**
215 * An optional `Contents.IDrive` name for the model.
216 * If given, the model will prepend `driveName:` to
217 * all paths used in file operations.
218 */
219 driveName?: string;
220 /**
221 * A document manager instance.
222 */
223 manager: IDocumentManager;
224 /**
225 * The time interval for browser refreshing, in ms.
226 */
227 refreshInterval?: number;
228 /**
229 * An optional state database. If provided, the model will restore which
230 * folder was last opened when it is restored.
231 */
232 state?: IStateDB;
233 /**
234 * The application language translator.
235 */
236 translator?: ITranslator;
237 }
238}
239/**
240 * File browser model where hidden files inclusion can be toggled on/off.
241 */
242export declare class TogglableHiddenFileBrowserModel extends FileBrowserModel {
243 constructor(options: TogglableHiddenFileBrowserModel.IOptions);
244 /**
245 * Create an iterator over the model's items filtering hidden files out if necessary.
246 *
247 * @returns A new iterator over the model's items.
248 */
249 items(): IIterator<Contents.IModel>;
250 /**
251 * Set the inclusion of hidden files. Triggers a model refresh.
252 */
253 showHiddenFiles(value: boolean): void;
254 private _includeHiddenFiles;
255}
256/**
257 * Namespace for the togglable hidden file browser model
258 */
259export declare namespace TogglableHiddenFileBrowserModel {
260 /**
261 * Constructor options
262 */
263 interface IOptions extends FileBrowserModel.IOptions {
264 /**
265 * Whether hidden files should be included in the items.
266 */
267 includeHiddenFiles?: boolean;
268 }
269}
270/**
271 * File browser model with optional filter on element.
272 */
273export declare class FilterFileBrowserModel extends TogglableHiddenFileBrowserModel {
274 constructor(options: FilterFileBrowserModel.IOptions);
275 /**
276 * Create an iterator over the filtered model's items.
277 *
278 * @returns A new iterator over the model's items.
279 */
280 items(): IIterator<Contents.IModel>;
281 setFilter(filter: (value: Contents.IModel) => boolean): void;
282 private _filter;
283}
284/**
285 * Namespace for the filtered file browser model
286 */
287export declare namespace FilterFileBrowserModel {
288 /**
289 * Constructor options
290 */
291 interface IOptions extends TogglableHiddenFileBrowserModel.IOptions {
292 /**
293 * Filter function on file browser item model
294 */
295 filter?: (value: Contents.IModel) => boolean;
296 }
297}