1 | import { CellModel, CodeCellModel, ICellModel, ICodeCellModel, IMarkdownCellModel, IRawCellModel } from '@jupyterlab/cells';
|
2 | import { IChangedArgs } from '@jupyterlab/coreutils';
|
3 | import { DocumentRegistry } from '@jupyterlab/docregistry';
|
4 | import * as nbformat from '@jupyterlab/nbformat';
|
5 | import { IModelDB, IObservableJSON, IObservableUndoableList } from '@jupyterlab/observables';
|
6 | import * as models from '@jupyter/ydoc';
|
7 | import { ITranslator } from '@jupyterlab/translation';
|
8 | import { ISignal } from '@lumino/signaling';
|
9 |
|
10 |
|
11 |
|
12 | export interface INotebookModel extends DocumentRegistry.IModel {
|
13 | |
14 |
|
15 |
|
16 | readonly cells: IObservableUndoableList<ICellModel>;
|
17 | |
18 |
|
19 |
|
20 | readonly contentFactory: NotebookModel.IContentFactory;
|
21 | |
22 |
|
23 |
|
24 | readonly nbformat: number;
|
25 | |
26 |
|
27 |
|
28 | readonly nbformatMinor: number;
|
29 | |
30 |
|
31 |
|
32 | readonly metadata: IObservableJSON;
|
33 | |
34 |
|
35 |
|
36 | readonly deletedCells: string[];
|
37 | |
38 |
|
39 |
|
40 | isInitialized: boolean;
|
41 | readonly sharedModel: models.ISharedNotebook;
|
42 | }
|
43 |
|
44 |
|
45 |
|
46 | export declare class NotebookModel implements INotebookModel {
|
47 | |
48 |
|
49 |
|
50 | constructor(options?: NotebookModel.IOptions);
|
51 | /**
|
52 | * A signal emitted when the document content changes.
|
53 | */
|
54 | get contentChanged(): ISignal<this, void>;
|
55 | /**
|
56 | * A signal emitted when the document state changes.
|
57 | */
|
58 | get stateChanged(): ISignal<this, IChangedArgs<any>>;
|
59 | /**
|
60 | * The dirty state of the document.
|
61 | */
|
62 | get dirty(): boolean;
|
63 | set dirty(newValue: boolean);
|
64 | /**
|
65 | * The read only state of the document.
|
66 | */
|
67 | get readOnly(): boolean;
|
68 | set readOnly(newValue: boolean);
|
69 | /**
|
70 | * The metadata associated with the notebook.
|
71 | */
|
72 | get metadata(): IObservableJSON;
|
73 | /**
|
74 | * Get the observable list of notebook cells.
|
75 | */
|
76 | get cells(): IObservableUndoableList<ICellModel>;
|
77 | /**
|
78 | * The major version number of the nbformat.
|
79 | */
|
80 | get nbformat(): number;
|
81 | /**
|
82 | * The minor version number of the nbformat.
|
83 | */
|
84 | get nbformatMinor(): number;
|
85 | /**
|
86 | * The default kernel name of the document.
|
87 | */
|
88 | get defaultKernelName(): string;
|
89 | /**
|
90 | * A list of deleted cells for the notebook..
|
91 | */
|
92 | get deletedCells(): string[];
|
93 | /**
|
94 | * If the model is initialized or not.
|
95 | */
|
96 | get isInitialized(): boolean;
|
97 | /**
|
98 | * The default kernel language of the document.
|
99 | */
|
100 | get defaultKernelLanguage(): string;
|
101 | /**
|
102 | * Whether the model is collaborative or not.
|
103 | */
|
104 | get collaborative(): boolean;
|
105 | /**
|
106 | * Dispose of the resources held by the model.
|
107 | */
|
108 | dispose(): void;
|
109 | /**
|
110 | * Serialize the model to a string.
|
111 | */
|
112 | toString(): string;
|
113 | /**
|
114 | * Deserialize the model from a string.
|
115 | *
|
116 | * #### Notes
|
117 | * Should emit a [contentChanged] signal.
|
118 | */
|
119 | fromString(value: string): void;
|
120 | /**
|
121 | * Serialize the model to JSON.
|
122 | */
|
123 | toJSON(): nbformat.INotebookContent;
|
124 | /**
|
125 | * Deserialize the model from JSON.
|
126 | *
|
127 | * #### Notes
|
128 | * Should emit a [contentChanged] signal.
|
129 | */
|
130 | fromJSON(value: nbformat.INotebookContent): void;
|
131 | /**
|
132 | * Initialize the model with its current state.
|
133 | *
|
134 | * # Notes
|
135 | * Adds an empty code cell if the model is empty
|
136 | * and clears undo state.
|
137 | */
|
138 | initialize(): void;
|
139 | /**
|
140 | * Handle a change in the cells list.
|
141 | */
|
142 | private _onCellsChanged;
|
143 | private _onStateChanged;
|
144 | private _onMetadataChanged;
|
145 | /**
|
146 | * Make sure we have the required metadata fields.
|
147 | */
|
148 | private _ensureMetadata;
|
149 | /**
|
150 | * Trigger a state change signal.
|
151 | */
|
152 | protected triggerStateChange(args: IChangedArgs<any>): void;
|
153 | /**
|
154 | * Trigger a content changed signal.
|
155 | */
|
156 | protected triggerContentChange(): void;
|
157 | /**
|
158 | * Whether the model is disposed.
|
159 | */
|
160 | get isDisposed(): boolean;
|
161 | /**
|
162 | * The cell model factory for the notebook.
|
163 | */
|
164 | readonly contentFactory: NotebookModel.IContentFactory;
|
165 | /**
|
166 | * The shared notebook model.
|
167 | */
|
168 | readonly sharedModel: models.ISharedNotebook;
|
169 | /**
|
170 | * A mutex to update the shared model.
|
171 | */
|
172 | protected readonly _modelDBMutex: (f: () => void) => void;
|
173 | /**
|
174 | * The underlying `IModelDB` instance in which model
|
175 | * data is stored.
|
176 | */
|
177 | readonly modelDB: IModelDB;
|
178 | private _dirty;
|
179 | private _readOnly;
|
180 | private _contentChanged;
|
181 | private _stateChanged;
|
182 | private _trans;
|
183 | private _cells;
|
184 | private _nbformat;
|
185 | private _nbformatMinor;
|
186 | private _deletedCells;
|
187 | private _isInitialized;
|
188 | private _isDisposed;
|
189 | private _collaborationEnabled;
|
190 | }
|
191 | /**
|
192 | * The namespace for the `NotebookModel` class statics.
|
193 | */
|
194 | export declare namespace NotebookModel {
|
195 | |
196 |
|
197 |
|
198 | interface IOptions {
|
199 | |
200 |
|
201 |
|
202 | languagePreference?: string;
|
203 | |
204 |
|
205 |
|
206 |
|
207 |
|
208 | contentFactory?: IContentFactory;
|
209 | |
210 |
|
211 |
|
212 | modelDB?: IModelDB;
|
213 | |
214 |
|
215 |
|
216 | translator?: ITranslator;
|
217 | |
218 |
|
219 |
|
220 | isInitialized?: boolean;
|
221 | |
222 |
|
223 |
|
224 | disableDocumentWideUndoRedo?: boolean;
|
225 | |
226 |
|
227 |
|
228 | collaborationEnabled?: boolean;
|
229 | }
|
230 | |
231 |
|
232 |
|
233 | interface IContentFactory {
|
234 | |
235 |
|
236 |
|
237 | readonly codeCellContentFactory: CodeCellModel.IContentFactory;
|
238 | |
239 |
|
240 |
|
241 | modelDB: IModelDB | undefined;
|
242 | |
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 | createCell(type: nbformat.CellType, options: CellModel.IOptions): ICellModel;
|
254 | |
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 | createCodeCell(options: CodeCellModel.IOptions): ICodeCellModel;
|
263 | |
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 | createMarkdownCell(options: CellModel.IOptions): IMarkdownCellModel;
|
272 | |
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 | createRawCell(options: CellModel.IOptions): IRawCellModel;
|
281 | |
282 |
|
283 |
|
284 | clone(modelDB: IModelDB): IContentFactory;
|
285 | }
|
286 | |
287 |
|
288 |
|
289 | class ContentFactory {
|
290 | |
291 |
|
292 |
|
293 | constructor(options: ContentFactory.IOptions);
|
294 | /**
|
295 | * The factory for code cell content.
|
296 | */
|
297 | readonly codeCellContentFactory: CodeCellModel.IContentFactory;
|
298 | /**
|
299 | * The IModelDB in which to put the notebook data.
|
300 | */
|
301 | readonly modelDB: IModelDB | undefined;
|
302 | /**
|
303 | * Create a new cell by cell type.
|
304 | *
|
305 | * @param type: the type of the cell to create.
|
306 | *
|
307 | * @param options: the cell creation options.
|
308 | *
|
309 | * #### Notes
|
310 | * This method is intended to be a convenience method to programmatically
|
311 | * call the other cell creation methods in the factory.
|
312 | */
|
313 | createCell(type: nbformat.CellType, options: CellModel.IOptions): ICellModel;
|
314 | /**
|
315 | * Create a new code cell.
|
316 | *
|
317 | * @param source - The data to use for the original source data.
|
318 | *
|
319 | * @returns A new code cell. If a source cell is provided, the
|
320 | * new cell will be initialized with the data from the source.
|
321 | * If the contentFactory is not provided, the instance
|
322 | * `codeCellContentFactory` will be used.
|
323 | */
|
324 | createCodeCell(options: CodeCellModel.IOptions): ICodeCellModel;
|
325 | /**
|
326 | * Create a new markdown cell.
|
327 | *
|
328 | * @param source - The data to use for the original source data.
|
329 | *
|
330 | * @returns A new markdown cell. If a source cell is provided, the
|
331 | * new cell will be initialized with the data from the source.
|
332 | */
|
333 | createMarkdownCell(options: CellModel.IOptions): IMarkdownCellModel;
|
334 | /**
|
335 | * Create a new raw cell.
|
336 | *
|
337 | * @param source - The data to use for the original source data.
|
338 | *
|
339 | * @returns A new raw cell. If a source cell is provided, the
|
340 | * new cell will be initialized with the data from the source.
|
341 | */
|
342 | createRawCell(options: CellModel.IOptions): IRawCellModel;
|
343 | /**
|
344 | * Clone the content factory with a new IModelDB.
|
345 | */
|
346 | clone(modelDB: IModelDB): ContentFactory;
|
347 | }
|
348 | /**
|
349 | * A namespace for the notebook model content factory.
|
350 | */
|
351 | namespace ContentFactory {
|
352 | |
353 |
|
354 |
|
355 | interface IOptions {
|
356 | |
357 |
|
358 |
|
359 | codeCellContentFactory?: CodeCellModel.IContentFactory;
|
360 | |
361 |
|
362 |
|
363 | modelDB?: IModelDB;
|
364 | }
|
365 | }
|
366 | |
367 |
|
368 |
|
369 | const defaultContentFactory: ContentFactory;
|
370 | }
|