1 |
|
2 |
|
3 |
|
4 | import type { ISharedNotebook } from '@jupyter/ydoc';
|
5 | import { DocumentRegistry } from '@jupyterlab/docregistry';
|
6 | import { Contents } from '@jupyterlab/services';
|
7 | import { INotebookModel, NotebookModel } from './model';
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | export class NotebookModelFactory
|
13 | implements DocumentRegistry.IModelFactory<INotebookModel>
|
14 | {
|
15 | |
16 |
|
17 |
|
18 | constructor(options: NotebookModelFactory.IOptions = {}) {
|
19 | this._disableDocumentWideUndoRedo =
|
20 | options.disableDocumentWideUndoRedo ?? true;
|
21 | this._collaborative = options.collaborative ?? true;
|
22 | }
|
23 |
|
24 | |
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | get disableDocumentWideUndoRedo(): boolean {
|
31 | return this._disableDocumentWideUndoRedo;
|
32 | }
|
33 | set disableDocumentWideUndoRedo(disableDocumentWideUndoRedo: boolean) {
|
34 | this._disableDocumentWideUndoRedo = disableDocumentWideUndoRedo;
|
35 | }
|
36 |
|
37 | |
38 |
|
39 |
|
40 | get name(): string {
|
41 | return 'notebook';
|
42 | }
|
43 |
|
44 | |
45 |
|
46 |
|
47 | get contentType(): Contents.ContentType {
|
48 | return 'notebook';
|
49 | }
|
50 |
|
51 | |
52 |
|
53 |
|
54 | get fileFormat(): Contents.FileFormat {
|
55 | return 'json';
|
56 | }
|
57 |
|
58 | |
59 |
|
60 |
|
61 | get collaborative(): boolean {
|
62 | return this._collaborative;
|
63 | }
|
64 |
|
65 | |
66 |
|
67 |
|
68 | get isDisposed(): boolean {
|
69 | return this._disposed;
|
70 | }
|
71 |
|
72 | |
73 |
|
74 |
|
75 | dispose(): void {
|
76 | this._disposed = true;
|
77 | }
|
78 |
|
79 | |
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | createNew(
|
87 | options: DocumentRegistry.IModelOptions<ISharedNotebook> = {}
|
88 | ): INotebookModel {
|
89 | return new NotebookModel({
|
90 | languagePreference: options.languagePreference,
|
91 | sharedModel: options.sharedModel,
|
92 | collaborationEnabled: options.collaborationEnabled && this.collaborative,
|
93 | disableDocumentWideUndoRedo: this._disableDocumentWideUndoRedo
|
94 | });
|
95 | }
|
96 |
|
97 | |
98 |
|
99 |
|
100 | preferredLanguage(path: string): string {
|
101 | return '';
|
102 | }
|
103 |
|
104 | |
105 |
|
106 |
|
107 | private _disableDocumentWideUndoRedo: boolean;
|
108 | private _disposed = false;
|
109 | private _collaborative: boolean;
|
110 | }
|
111 |
|
112 |
|
113 |
|
114 |
|
115 | export namespace NotebookModelFactory {
|
116 | |
117 |
|
118 |
|
119 | export interface IOptions {
|
120 | |
121 |
|
122 |
|
123 | collaborative?: boolean;
|
124 |
|
125 | |
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 | disableDocumentWideUndoRedo?: boolean;
|
134 | }
|
135 | }
|