UNPKG

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