1 | import { ISessionContext, Toolbar, ToolbarRegistry } from '@jupyterlab/apputils';
|
2 | import { CodeEditor } from '@jupyterlab/codeeditor';
|
3 | import { IChangedArgs as IChangedArgsGeneric } from '@jupyterlab/coreutils';
|
4 | import { IModelDB, IObservableList } from '@jupyterlab/observables';
|
5 | import { IRenderMime } from '@jupyterlab/rendermime-interfaces';
|
6 | import { Contents, Kernel } from '@jupyterlab/services';
|
7 | import { ISharedDocument, ISharedFile } from '@jupyter/ydoc';
|
8 | import { ITranslator } from '@jupyterlab/translation';
|
9 | import { LabIcon } from '@jupyterlab/ui-components';
|
10 | import { IIterator } from '@lumino/algorithm';
|
11 | import { PartialJSONValue, ReadonlyPartialJSONValue } from '@lumino/coreutils';
|
12 | import { IDisposable } from '@lumino/disposable';
|
13 | import { ISignal } from '@lumino/signaling';
|
14 | import { DockLayout, Widget } from '@lumino/widgets';
|
15 |
|
16 |
|
17 |
|
18 | export declare class DocumentRegistry implements IDisposable {
|
19 | |
20 |
|
21 |
|
22 | constructor(options?: DocumentRegistry.IOptions);
|
23 | /**
|
24 | * A signal emitted when the registry has changed.
|
25 | */
|
26 | get changed(): ISignal<this, DocumentRegistry.IChangedArgs>;
|
27 | /**
|
28 | * Get whether the document registry has been disposed.
|
29 | */
|
30 | get isDisposed(): boolean;
|
31 | /**
|
32 | * Dispose of the resources held by the document registry.
|
33 | */
|
34 | dispose(): void;
|
35 | /**
|
36 | * Add a widget factory to the registry.
|
37 | *
|
38 | * @param factory - The factory instance to register.
|
39 | *
|
40 | * @returns A disposable which will unregister the factory.
|
41 | *
|
42 | * #### Notes
|
43 | * If a factory with the given `'name'` is already registered,
|
44 | * a warning will be logged, and this will be a no-op.
|
45 | * If `'*'` is given as a default extension, the factory will be registered
|
46 | * as the global default.
|
47 | * If an extension or global default is already registered, this factory
|
48 | * will override the existing default.
|
49 | * The factory cannot be named an empty string or the string `'default'`.
|
50 | */
|
51 | addWidgetFactory(factory: DocumentRegistry.WidgetFactory): IDisposable;
|
52 | /**
|
53 | * Add a model factory to the registry.
|
54 | *
|
55 | * @param factory - The factory instance.
|
56 | *
|
57 | * @returns A disposable which will unregister the factory.
|
58 | *
|
59 | * #### Notes
|
60 | * If a factory with the given `name` is already registered, or
|
61 | * the given factory is already registered, a warning will be logged
|
62 | * and this will be a no-op.
|
63 | */
|
64 | addModelFactory(factory: DocumentRegistry.ModelFactory): IDisposable;
|
65 | /**
|
66 | * Add a widget extension to the registry.
|
67 | *
|
68 | * @param widgetName - The name of the widget factory.
|
69 | *
|
70 | * @param extension - A widget extension.
|
71 | *
|
72 | * @returns A disposable which will unregister the extension.
|
73 | *
|
74 | * #### Notes
|
75 | * If the extension is already registered for the given
|
76 | * widget name, a warning will be logged and this will be a no-op.
|
77 | */
|
78 | addWidgetExtension(widgetName: string, extension: DocumentRegistry.WidgetExtension): IDisposable;
|
79 | /**
|
80 | * Add a file type to the document registry.
|
81 | *
|
82 | * @param fileType - The file type object to register.
|
83 | * @param factories - Optional factories to use for the file type.
|
84 | *
|
85 | * @returns A disposable which will unregister the command.
|
86 | *
|
87 | * #### Notes
|
88 | * These are used to populate the "Create New" dialog.
|
89 | *
|
90 | * If no default factory exists for the file type, the first factory will
|
91 | * be defined as default factory.
|
92 | */
|
93 | addFileType(fileType: Partial<DocumentRegistry.IFileType>, factories?: string[]): IDisposable;
|
94 | /**
|
95 | * Get a list of the preferred widget factories.
|
96 | *
|
97 | * @param path - The file path to filter the results.
|
98 | *
|
99 | * @returns A new array of widget factories.
|
100 | *
|
101 | * #### Notes
|
102 | * Only the widget factories whose associated model factory have
|
103 | * been registered will be returned.
|
104 | * The first item is considered the default. The returned array
|
105 | * has widget factories in the following order:
|
106 | * - path-specific default factory
|
107 | * - path-specific default rendered factory
|
108 | * - global default factory
|
109 | * - all other path-specific factories
|
110 | * - all other global factories
|
111 | */
|
112 | preferredWidgetFactories(path: string): DocumentRegistry.WidgetFactory[];
|
113 | /**
|
114 | * Get the default rendered widget factory for a path.
|
115 | *
|
116 | * @param path - The path to for which to find a widget factory.
|
117 | *
|
118 | * @returns The default rendered widget factory for the path.
|
119 | *
|
120 | * ### Notes
|
121 | * If the widget factory has registered a separate set of `defaultRendered`
|
122 | * file types and there is a match in that set, this returns that.
|
123 | * Otherwise, this returns the same widget factory as
|
124 | * [[defaultWidgetFactory]].
|
125 | *
|
126 | * The user setting `defaultViewers` took precedence on this one too.
|
127 | */
|
128 | defaultRenderedWidgetFactory(path: string): DocumentRegistry.WidgetFactory;
|
129 | /**
|
130 | * Get the default widget factory for a path.
|
131 | *
|
132 | * @param path - An optional file path to filter the results.
|
133 | *
|
134 | * @returns The default widget factory for an path.
|
135 | *
|
136 | * #### Notes
|
137 | * This is equivalent to the first value in [[preferredWidgetFactories]].
|
138 | */
|
139 | defaultWidgetFactory(path?: string): DocumentRegistry.WidgetFactory;
|
140 | /**
|
141 | * Set overrides for the default widget factory for a file type.
|
142 | *
|
143 | * Normally, a widget factory informs the document registry which file types
|
144 | * it should be the default for using the `defaultFor` option in the
|
145 | * IWidgetFactoryOptions. This function can be used to override that after
|
146 | * the fact.
|
147 | *
|
148 | * @param fileType: The name of the file type.
|
149 | *
|
150 | * @param factory: The name of the factory.
|
151 | *
|
152 | * #### Notes
|
153 | * If `factory` is undefined, then any override will be unset, and the
|
154 | * default factory will revert to the original value.
|
155 | *
|
156 | * If `factory` or `fileType` are not known to the docregistry, or
|
157 | * if `factory` cannot open files of type `fileType`, this will throw
|
158 | * an error.
|
159 | */
|
160 | setDefaultWidgetFactory(fileType: string, factory: string | undefined): void;
|
161 | /**
|
162 | * Create an iterator over the widget factories that have been registered.
|
163 | *
|
164 | * @returns A new iterator of widget factories.
|
165 | */
|
166 | widgetFactories(): IIterator<DocumentRegistry.WidgetFactory>;
|
167 | /**
|
168 | * Create an iterator over the model factories that have been registered.
|
169 | *
|
170 | * @returns A new iterator of model factories.
|
171 | */
|
172 | modelFactories(): IIterator<DocumentRegistry.ModelFactory>;
|
173 | /**
|
174 | * Create an iterator over the registered extensions for a given widget.
|
175 | *
|
176 | * @param widgetName - The name of the widget factory.
|
177 | *
|
178 | * @returns A new iterator over the widget extensions.
|
179 | */
|
180 | widgetExtensions(widgetName: string): IIterator<DocumentRegistry.WidgetExtension>;
|
181 | /**
|
182 | * Create an iterator over the file types that have been registered.
|
183 | *
|
184 | * @returns A new iterator of file types.
|
185 | */
|
186 | fileTypes(): IIterator<DocumentRegistry.IFileType>;
|
187 | /**
|
188 | * Get a widget factory by name.
|
189 | *
|
190 | * @param widgetName - The name of the widget factory.
|
191 | *
|
192 | * @returns A widget factory instance.
|
193 | */
|
194 | getWidgetFactory(widgetName: string): DocumentRegistry.WidgetFactory | undefined;
|
195 | /**
|
196 | * Get a model factory by name.
|
197 | *
|
198 | * @param name - The name of the model factory.
|
199 | *
|
200 | * @returns A model factory instance.
|
201 | */
|
202 | getModelFactory(name: string): DocumentRegistry.ModelFactory | undefined;
|
203 | /**
|
204 | * Get a file type by name.
|
205 | */
|
206 | getFileType(name: string): DocumentRegistry.IFileType | undefined;
|
207 | /**
|
208 | * Get a kernel preference.
|
209 | *
|
210 | * @param path - The file path.
|
211 | *
|
212 | * @param widgetName - The name of the widget factory.
|
213 | *
|
214 | * @param kernel - An optional existing kernel model.
|
215 | *
|
216 | * @returns A kernel preference.
|
217 | */
|
218 | getKernelPreference(path: string, widgetName: string, kernel?: Partial<Kernel.IModel>): ISessionContext.IKernelPreference | undefined;
|
219 | /**
|
220 | * Get the best file type given a contents model.
|
221 | *
|
222 | * @param model - The contents model of interest.
|
223 | *
|
224 | * @returns The best matching file type.
|
225 | */
|
226 | getFileTypeForModel(model: Partial<Contents.IModel>): DocumentRegistry.IFileType;
|
227 | /**
|
228 | * Get the file types that match a file name.
|
229 | *
|
230 | * @param path - The path of the file.
|
231 | *
|
232 | * @returns An ordered list of matching file types.
|
233 | */
|
234 | getFileTypesForPath(path: string): DocumentRegistry.IFileType[];
|
235 | protected translator: ITranslator;
|
236 | private _modelFactories;
|
237 | private _widgetFactories;
|
238 | private _defaultWidgetFactory;
|
239 | private _defaultWidgetFactoryOverrides;
|
240 | private _defaultWidgetFactories;
|
241 | private _defaultRenderedWidgetFactories;
|
242 | private _widgetFactoriesForFileType;
|
243 | private _fileTypes;
|
244 | private _extenders;
|
245 | private _changed;
|
246 | private _isDisposed;
|
247 | }
|
248 | /**
|
249 | * The namespace for the `DocumentRegistry` class statics.
|
250 | */
|
251 | export declare namespace DocumentRegistry {
|
252 | |
253 |
|
254 |
|
255 | interface IToolbarItem extends ToolbarRegistry.IToolbarItem {
|
256 | }
|
257 | |
258 |
|
259 |
|
260 | interface IOptions {
|
261 | |
262 |
|
263 |
|
264 |
|
265 | textModelFactory?: ModelFactory;
|
266 | |
267 |
|
268 |
|
269 |
|
270 | initialFileTypes?: DocumentRegistry.IFileType[];
|
271 | |
272 |
|
273 |
|
274 | translator?: ITranslator;
|
275 | }
|
276 | |
277 |
|
278 |
|
279 | interface IModel extends IDisposable {
|
280 | |
281 |
|
282 |
|
283 | contentChanged: ISignal<this, void>;
|
284 | |
285 |
|
286 |
|
287 | stateChanged: ISignal<this, IChangedArgsGeneric<any>>;
|
288 | |
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 | dirty: boolean;
|
296 | |
297 |
|
298 |
|
299 | readOnly: boolean;
|
300 | |
301 |
|
302 |
|
303 | readonly defaultKernelName: string;
|
304 | |
305 |
|
306 |
|
307 | readonly defaultKernelLanguage: string;
|
308 | |
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 | readonly modelDB: IModelDB;
|
317 | |
318 |
|
319 |
|
320 | readonly sharedModel: ISharedDocument;
|
321 | |
322 |
|
323 |
|
324 |
|
325 | readonly collaborative?: boolean;
|
326 | |
327 |
|
328 |
|
329 | toString(): string;
|
330 | |
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 | fromString(value: string): void;
|
337 | |
338 |
|
339 |
|
340 | toJSON(): PartialJSONValue;
|
341 | |
342 |
|
343 |
|
344 |
|
345 |
|
346 |
|
347 | fromJSON(value: ReadonlyPartialJSONValue): void;
|
348 | |
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 |
|
355 | initialize(): void;
|
356 | }
|
357 | |
358 |
|
359 |
|
360 | interface ICodeModel extends IModel, CodeEditor.IModel {
|
361 | sharedModel: ISharedFile;
|
362 | }
|
363 | |
364 |
|
365 |
|
366 | interface IContext<T extends IModel> extends IDisposable {
|
367 | |
368 |
|
369 |
|
370 | pathChanged: ISignal<this, string>;
|
371 | |
372 |
|
373 |
|
374 | fileChanged: ISignal<this, Contents.IModel>;
|
375 | |
376 |
|
377 |
|
378 | saveState: ISignal<this, SaveState>;
|
379 | |
380 |
|
381 |
|
382 | disposed: ISignal<this, void>;
|
383 | |
384 |
|
385 |
|
386 | lastModifiedCheckMargin: number;
|
387 | |
388 |
|
389 |
|
390 | readonly model: T;
|
391 | |
392 |
|
393 |
|
394 | readonly sessionContext: ISessionContext;
|
395 | |
396 |
|
397 |
|
398 | readonly path: string;
|
399 | |
400 |
|
401 |
|
402 |
|
403 |
|
404 | readonly localPath: string;
|
405 | |
406 |
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 | readonly contentsModel: Contents.IModel | null;
|
413 | |
414 |
|
415 |
|
416 | readonly urlResolver: IRenderMime.IResolver;
|
417 | |
418 |
|
419 |
|
420 | readonly isReady: boolean;
|
421 | |
422 |
|
423 |
|
424 | readonly ready: Promise<void>;
|
425 | |
426 |
|
427 |
|
428 | rename(newName: string): Promise<void>;
|
429 | |
430 |
|
431 |
|
432 | save(): Promise<void>;
|
433 | |
434 |
|
435 |
|
436 | saveAs(): Promise<void>;
|
437 | |
438 |
|
439 |
|
440 | download(): Promise<void>;
|
441 | |
442 |
|
443 |
|
444 | revert(): Promise<void>;
|
445 | |
446 |
|
447 |
|
448 |
|
449 |
|
450 |
|
451 | createCheckpoint(): Promise<Contents.ICheckpointModel>;
|
452 | |
453 |
|
454 |
|
455 |
|
456 |
|
457 |
|
458 |
|
459 | deleteCheckpoint(checkpointID: string): Promise<void>;
|
460 | |
461 |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 |
|
467 |
|
468 | restoreCheckpoint(checkpointID?: string): Promise<void>;
|
469 | |
470 |
|
471 |
|
472 |
|
473 |
|
474 |
|
475 | listCheckpoints(): Promise<Contents.ICheckpointModel[]>;
|
476 | |
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 |
|
483 |
|
484 |
|
485 |
|
486 |
|
487 |
|
488 |
|
489 | addSibling(widget: Widget, options?: IOpenOptions): IDisposable;
|
490 | }
|
491 | |
492 |
|
493 |
|
494 | type SaveState = 'started' | 'failed' | 'completed';
|
495 | |
496 |
|
497 |
|
498 | type Context = IContext<IModel>;
|
499 | |
500 |
|
501 |
|
502 | type CodeContext = IContext<ICodeModel>;
|
503 | |
504 |
|
505 |
|
506 | interface IWidgetFactoryOptions<T extends Widget = Widget> {
|
507 | |
508 |
|
509 |
|
510 | readonly name: string;
|
511 | |
512 |
|
513 |
|
514 | readonly fileTypes: ReadonlyArray<string>;
|
515 | |
516 |
|
517 |
|
518 | readonly defaultFor?: ReadonlyArray<string>;
|
519 | |
520 |
|
521 |
|
522 |
|
523 |
|
524 | readonly defaultRendered?: ReadonlyArray<string>;
|
525 | |
526 |
|
527 |
|
528 | readonly readOnly?: boolean;
|
529 | |
530 |
|
531 |
|
532 | readonly modelName?: string;
|
533 | |
534 |
|
535 |
|
536 | readonly preferKernel?: boolean;
|
537 | |
538 |
|
539 |
|
540 | readonly canStartKernel?: boolean;
|
541 | |
542 |
|
543 |
|
544 | readonly shutdownOnClose?: boolean;
|
545 | |
546 |
|
547 |
|
548 | readonly translator?: ITranslator;
|
549 | |
550 |
|
551 |
|
552 | readonly toolbarFactory?: (widget: T) => DocumentRegistry.IToolbarItem[] | IObservableList<DocumentRegistry.IToolbarItem>;
|
553 | }
|
554 | |
555 |
|
556 |
|
557 | interface IOpenOptions {
|
558 | |
559 |
|
560 |
|
561 |
|
562 |
|
563 | ref?: string | null;
|
564 | |
565 |
|
566 |
|
567 |
|
568 |
|
569 |
|
570 | mode?: DockLayout.InsertMode;
|
571 | |
572 |
|
573 |
|
574 | activate?: boolean;
|
575 | |
576 |
|
577 |
|
578 |
|
579 |
|
580 |
|
581 | rank?: number;
|
582 | }
|
583 | |
584 |
|
585 |
|
586 | interface IWidgetFactory<T extends IDocumentWidget, U extends IModel> extends IDisposable, IWidgetFactoryOptions {
|
587 | |
588 |
|
589 |
|
590 | widgetCreated: ISignal<IWidgetFactory<T, U>, T>;
|
591 | |
592 |
|
593 |
|
594 |
|
595 |
|
596 |
|
597 |
|
598 |
|
599 | createNew(context: IContext<U>, source?: T): T;
|
600 | }
|
601 | |
602 |
|
603 |
|
604 | type WidgetFactory = IWidgetFactory<IDocumentWidget, IModel>;
|
605 | |
606 |
|
607 |
|
608 | interface IWidgetExtension<T extends Widget, U extends IModel> {
|
609 | |
610 |
|
611 |
|
612 | createNew(widget: T, context: IContext<U>): IDisposable | void;
|
613 | }
|
614 | |
615 |
|
616 |
|
617 | type WidgetExtension = IWidgetExtension<Widget, IModel>;
|
618 | |
619 |
|
620 |
|
621 | interface IModelFactory<T extends IModel> extends IDisposable {
|
622 | |
623 |
|
624 |
|
625 | readonly name: string;
|
626 | |
627 |
|
628 |
|
629 | readonly contentType: Contents.ContentType;
|
630 | |
631 |
|
632 |
|
633 | readonly fileFormat: Contents.FileFormat;
|
634 | |
635 |
|
636 |
|
637 | readonly collaborative?: boolean;
|
638 | |
639 |
|
640 |
|
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 |
|
648 | createNew(languagePreference?: string, modelDB?: IModelDB, isInitialized?: boolean, collaborationEnabled?: boolean): T;
|
649 | |
650 |
|
651 |
|
652 | preferredLanguage(path: string): string;
|
653 | }
|
654 | |
655 |
|
656 |
|
657 | type ModelFactory = IModelFactory<IModel>;
|
658 | |
659 |
|
660 |
|
661 | type CodeModelFactory = IModelFactory<ICodeModel>;
|
662 | |
663 |
|
664 |
|
665 | interface IFileType {
|
666 | |
667 |
|
668 |
|
669 | readonly name: string;
|
670 | |
671 |
|
672 |
|
673 | readonly mimeTypes: ReadonlyArray<string>;
|
674 | |
675 |
|
676 |
|
677 |
|
678 | readonly extensions: ReadonlyArray<string>;
|
679 | |
680 |
|
681 |
|
682 | readonly displayName?: string;
|
683 | |
684 |
|
685 |
|
686 | readonly pattern?: string;
|
687 | |
688 |
|
689 |
|
690 | readonly icon?: LabIcon;
|
691 | |
692 |
|
693 |
|
694 | readonly iconClass?: string;
|
695 | |
696 |
|
697 |
|
698 | readonly iconLabel?: string;
|
699 | |
700 |
|
701 |
|
702 | readonly contentType: Contents.ContentType;
|
703 | |
704 |
|
705 |
|
706 | readonly fileFormat: Contents.FileFormat;
|
707 | }
|
708 | |
709 |
|
710 |
|
711 | interface IChangedArgs {
|
712 | |
713 |
|
714 |
|
715 | readonly type: 'widgetFactory' | 'modelFactory' | 'widgetExtension' | 'fileType';
|
716 | |
717 |
|
718 |
|
719 | readonly name?: string;
|
720 | |
721 |
|
722 |
|
723 | readonly change: 'added' | 'removed';
|
724 | }
|
725 | |
726 |
|
727 |
|
728 |
|
729 |
|
730 |
|
731 |
|
732 | function getFileTypeDefaults(translator?: ITranslator): IFileType;
|
733 | |
734 |
|
735 |
|
736 |
|
737 |
|
738 |
|
739 |
|
740 | function getDefaultTextFileType(translator?: ITranslator): IFileType;
|
741 | |
742 |
|
743 |
|
744 |
|
745 |
|
746 |
|
747 |
|
748 | function getDefaultNotebookFileType(translator?: ITranslator): IFileType;
|
749 | |
750 |
|
751 |
|
752 |
|
753 |
|
754 |
|
755 |
|
756 | function getDefaultDirectoryFileType(translator?: ITranslator): IFileType;
|
757 | |
758 |
|
759 |
|
760 |
|
761 |
|
762 |
|
763 |
|
764 | function getDefaultFileTypes(translator?: ITranslator): ReadonlyArray<Partial<IFileType>>;
|
765 | }
|
766 |
|
767 |
|
768 |
|
769 | export interface IDocumentWidget<T extends Widget = Widget, U extends DocumentRegistry.IModel = DocumentRegistry.IModel> extends Widget {
|
770 | |
771 |
|
772 |
|
773 | readonly content: T;
|
774 | |
775 |
|
776 |
|
777 | readonly context: DocumentRegistry.IContext<U>;
|
778 | |
779 |
|
780 |
|
781 |
|
782 |
|
783 |
|
784 |
|
785 | isUntitled?: boolean;
|
786 | |
787 |
|
788 |
|
789 | readonly revealed: Promise<void>;
|
790 | |
791 |
|
792 |
|
793 | readonly toolbar: Toolbar<Widget>;
|
794 | |
795 |
|
796 |
|
797 | setFragment(fragment: string): void;
|
798 | }
|