forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modelfactory.ts
110 lines (93 loc) · 2.51 KB
/
modelfactory.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import { CodeCellModel } from '@jupyterlab/cells';
import { DocumentRegistry } from '@jupyterlab/docregistry';
import { IModelDB } from '@jupyterlab/observables';
import { Contents } from '@jupyterlab/services';
import { INotebookModel, NotebookModel } from './model';
/**
* A model factory for notebooks.
*/
export class NotebookModelFactory
implements DocumentRegistry.IModelFactory<INotebookModel> {
/**
* Construct a new notebook model factory.
*/
constructor(options: NotebookModelFactory.IOptions) {
const codeCellContentFactory = options.codeCellContentFactory;
this.contentFactory =
options.contentFactory ||
new NotebookModel.ContentFactory({ codeCellContentFactory });
}
/**
* The content model factory used by the NotebookModelFactory.
*/
readonly contentFactory: NotebookModel.IContentFactory;
/**
* The name of the model.
*/
get name(): string {
return 'notebook';
}
/**
* The content type of the file.
*/
get contentType(): Contents.ContentType {
return 'notebook';
}
/**
* The format of the file.
*/
get fileFormat(): Contents.FileFormat {
return 'json';
}
/**
* Get whether the model factory has been disposed.
*/
get isDisposed(): boolean {
return this._disposed;
}
/**
* Dispose of the model factory.
*/
dispose(): void {
this._disposed = true;
}
/**
* Create a new model for a given path.
*
* @param languagePreference - An optional kernel language preference.
*
* @returns A new document model.
*/
createNew(languagePreference?: string, modelDB?: IModelDB): INotebookModel {
const contentFactory = this.contentFactory;
return new NotebookModel({ languagePreference, contentFactory, modelDB });
}
/**
* Get the preferred kernel language given a path.
*/
preferredLanguage(path: string): string {
return '';
}
private _disposed = false;
}
/**
* The namespace for notebook model factory statics.
*/
export namespace NotebookModelFactory {
/**
* The options used to initialize a NotebookModelFactory.
*/
export interface IOptions {
/**
* The factory for code cell content.
*/
codeCellContentFactory?: CodeCellModel.IContentFactory;
/**
* The content factory used by the NotebookModelFactory. If
* given, it will supersede the `codeCellContentFactory`.
*/
contentFactory?: NotebookModel.IContentFactory;
}
}