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 '@jupyterlab/shared-models';
|
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 | * Dispose of the resources held by the model.
|
103 | */
|
104 | dispose(): void;
|
105 | /**
|
106 | * Serialize the model to a string.
|
107 | */
|
108 | toString(): string;
|
109 | /**
|
110 | * Deserialize the model from a string.
|
111 | *
|
112 | * #### Notes
|
113 | * Should emit a [contentChanged] signal.
|
114 | */
|
115 | fromString(value: string): void;
|
116 | /**
|
117 | * Serialize the model to JSON.
|
118 | */
|
119 | toJSON(): nbformat.INotebookContent;
|
120 | /**
|
121 | * Deserialize the model from JSON.
|
122 | *
|
123 | * #### Notes
|
124 | * Should emit a [contentChanged] signal.
|
125 | */
|
126 | fromJSON(value: nbformat.INotebookContent): void;
|
127 | /**
|
128 | * Initialize the model with its current state.
|
129 | *
|
130 | * # Notes
|
131 | * Adds an empty code cell if the model is empty
|
132 | * and clears undo state.
|
133 | */
|
134 | initialize(): void;
|
135 | /**
|
136 | * Handle a change in the cells list.
|
137 | */
|
138 | private _onCellsChanged;
|
139 | private _onStateChanged;
|
140 | private _onMetadataChanged;
|
141 | /**
|
142 | * Make sure we have the required metadata fields.
|
143 | */
|
144 | private _ensureMetadata;
|
145 | /**
|
146 | * Trigger a state change signal.
|
147 | */
|
148 | protected triggerStateChange(args: IChangedArgs<any>): void;
|
149 | /**
|
150 | * Trigger a content changed signal.
|
151 | */
|
152 | protected triggerContentChange(): void;
|
153 | /**
|
154 | * Whether the model is disposed.
|
155 | */
|
156 | get isDisposed(): boolean;
|
157 | /**
|
158 | * The cell model factory for the notebook.
|
159 | */
|
160 | readonly contentFactory: NotebookModel.IContentFactory;
|
161 | /**
|
162 | * The shared notebook model.
|
163 | */
|
164 | readonly sharedModel: models.ISharedNotebook;
|
165 | /**
|
166 | * A mutex to update the shared model.
|
167 | */
|
168 | protected readonly _modelDBMutex: (f: () => void) => void;
|
169 | /**
|
170 | * The underlying `IModelDB` instance in which model
|
171 | * data is stored.
|
172 | */
|
173 | readonly modelDB: IModelDB;
|
174 | private _readOnly;
|
175 | private _contentChanged;
|
176 | private _stateChanged;
|
177 | private _trans;
|
178 | private _cells;
|
179 | private _nbformat;
|
180 | private _nbformatMinor;
|
181 | private _deletedCells;
|
182 | private _isInitialized;
|
183 | private _isDisposed;
|
184 | }
|
185 | /**
|
186 | * The namespace for the `NotebookModel` class statics.
|
187 | */
|
188 | export declare namespace NotebookModel {
|
189 | |
190 |
|
191 |
|
192 | interface IOptions {
|
193 | |
194 |
|
195 |
|
196 | languagePreference?: string;
|
197 | |
198 |
|
199 |
|
200 |
|
201 |
|
202 | contentFactory?: IContentFactory;
|
203 | |
204 |
|
205 |
|
206 | modelDB?: IModelDB;
|
207 | |
208 |
|
209 |
|
210 | translator?: ITranslator;
|
211 | |
212 |
|
213 |
|
214 | isInitialized?: boolean;
|
215 | |
216 |
|
217 |
|
218 | disableDocumentWideUndoRedo?: boolean;
|
219 | }
|
220 | |
221 |
|
222 |
|
223 | interface IContentFactory {
|
224 | |
225 |
|
226 |
|
227 | readonly codeCellContentFactory: CodeCellModel.IContentFactory;
|
228 | |
229 |
|
230 |
|
231 | modelDB: IModelDB | undefined;
|
232 | |
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 | createCell(type: nbformat.CellType, options: CellModel.IOptions): ICellModel;
|
244 | |
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 | createCodeCell(options: CodeCellModel.IOptions): ICodeCellModel;
|
253 | |
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 | createMarkdownCell(options: CellModel.IOptions): IMarkdownCellModel;
|
262 | |
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 | createRawCell(options: CellModel.IOptions): IRawCellModel;
|
271 | |
272 |
|
273 |
|
274 | clone(modelDB: IModelDB): IContentFactory;
|
275 | }
|
276 | |
277 |
|
278 |
|
279 | class ContentFactory {
|
280 | |
281 |
|
282 |
|
283 | constructor(options: ContentFactory.IOptions);
|
284 | /**
|
285 | * The factory for code cell content.
|
286 | */
|
287 | readonly codeCellContentFactory: CodeCellModel.IContentFactory;
|
288 | /**
|
289 | * The IModelDB in which to put the notebook data.
|
290 | */
|
291 | readonly modelDB: IModelDB | undefined;
|
292 | /**
|
293 | * Create a new cell by cell type.
|
294 | *
|
295 | * @param type: the type of the cell to create.
|
296 | *
|
297 | * @param options: the cell creation options.
|
298 | *
|
299 | * #### Notes
|
300 | * This method is intended to be a convenience method to programmatically
|
301 | * call the other cell creation methods in the factory.
|
302 | */
|
303 | createCell(type: nbformat.CellType, options: CellModel.IOptions): ICellModel;
|
304 | /**
|
305 | * Create a new code cell.
|
306 | *
|
307 | * @param source - The data to use for the original source data.
|
308 | *
|
309 | * @returns A new code cell. If a source cell is provided, the
|
310 | * new cell will be initialized with the data from the source.
|
311 | * If the contentFactory is not provided, the instance
|
312 | * `codeCellContentFactory` will be used.
|
313 | */
|
314 | createCodeCell(options: CodeCellModel.IOptions): ICodeCellModel;
|
315 | /**
|
316 | * Create a new markdown cell.
|
317 | *
|
318 | * @param source - The data to use for the original source data.
|
319 | *
|
320 | * @returns A new markdown cell. If a source cell is provided, the
|
321 | * new cell will be initialized with the data from the source.
|
322 | */
|
323 | createMarkdownCell(options: CellModel.IOptions): IMarkdownCellModel;
|
324 | /**
|
325 | * Create a new raw cell.
|
326 | *
|
327 | * @param source - The data to use for the original source data.
|
328 | *
|
329 | * @returns A new raw cell. If a source cell is provided, the
|
330 | * new cell will be initialized with the data from the source.
|
331 | */
|
332 | createRawCell(options: CellModel.IOptions): IRawCellModel;
|
333 | /**
|
334 | * Clone the content factory with a new IModelDB.
|
335 | */
|
336 | clone(modelDB: IModelDB): ContentFactory;
|
337 | }
|
338 | /**
|
339 | * A namespace for the notebook model content factory.
|
340 | */
|
341 | namespace ContentFactory {
|
342 | |
343 |
|
344 |
|
345 | interface IOptions {
|
346 | |
347 |
|
348 |
|
349 | codeCellContentFactory?: CodeCellModel.IContentFactory;
|
350 | |
351 |
|
352 |
|
353 | modelDB?: IModelDB;
|
354 | }
|
355 | }
|
356 | |
357 |
|
358 |
|
359 | const defaultContentFactory: ContentFactory;
|
360 | }
|