UNPKG

11.3 kBTypeScriptView Raw
1import { CellModel, CodeCellModel, ICellModel, ICodeCellModel, IMarkdownCellModel, IRawCellModel } from '@jupyterlab/cells';
2import { IChangedArgs } from '@jupyterlab/coreutils';
3import { DocumentRegistry } from '@jupyterlab/docregistry';
4import * as nbformat from '@jupyterlab/nbformat';
5import { IModelDB, IObservableJSON, IObservableUndoableList } from '@jupyterlab/observables';
6import * as models from '@jupyter/ydoc';
7import { ITranslator } from '@jupyterlab/translation';
8import { ISignal } from '@lumino/signaling';
9/**
10 * The definition of a model object for a notebook widget.
11 */
12export interface INotebookModel extends DocumentRegistry.IModel {
13 /**
14 * The list of cells in the notebook.
15 */
16 readonly cells: IObservableUndoableList<ICellModel>;
17 /**
18 * The cell model factory for the notebook.
19 */
20 readonly contentFactory: NotebookModel.IContentFactory;
21 /**
22 * The major version number of the nbformat.
23 */
24 readonly nbformat: number;
25 /**
26 * The minor version number of the nbformat.
27 */
28 readonly nbformatMinor: number;
29 /**
30 * The metadata associated with the notebook.
31 */
32 readonly metadata: IObservableJSON;
33 /**
34 * The array of deleted cells since the notebook was last run.
35 */
36 readonly deletedCells: string[];
37 /**
38 * If the model is initialized or not.
39 */
40 isInitialized: boolean;
41 readonly sharedModel: models.ISharedNotebook;
42}
43/**
44 * An implementation of a notebook Model.
45 */
46export declare class NotebookModel implements INotebookModel {
47 /**
48 * Construct a new notebook model.
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 */
194export declare namespace NotebookModel {
195 /**
196 * An options object for initializing a notebook model.
197 */
198 interface IOptions {
199 /**
200 * The language preference for the model.
201 */
202 languagePreference?: string;
203 /**
204 * A factory for creating cell models.
205 *
206 * The default is a shared factory instance.
207 */
208 contentFactory?: IContentFactory;
209 /**
210 * A modelDB for storing notebook data.
211 */
212 modelDB?: IModelDB;
213 /**
214 * Language translator.
215 */
216 translator?: ITranslator;
217 /**
218 * If the model is initialized or not.
219 */
220 isInitialized?: boolean;
221 /**
222 * Defines if the document can be undo/redo.
223 */
224 disableDocumentWideUndoRedo?: boolean;
225 /**
226 * Whether collaboration should be enabled for this document model.
227 */
228 collaborationEnabled?: boolean;
229 }
230 /**
231 * A factory for creating notebook model content.
232 */
233 interface IContentFactory {
234 /**
235 * The factory for output area models.
236 */
237 readonly codeCellContentFactory: CodeCellModel.IContentFactory;
238 /**
239 * The IModelDB in which to put data for the notebook model.
240 */
241 modelDB: IModelDB | undefined;
242 /**
243 * Create a new cell by cell type.
244 *
245 * @param type: the type of the cell to create.
246 *
247 * @param options: the cell creation options.
248 *
249 * #### Notes
250 * This method is intended to be a convenience method to programmatically
251 * call the other cell creation methods in the factory.
252 */
253 createCell(type: nbformat.CellType, options: CellModel.IOptions): ICellModel;
254 /**
255 * Create a new code cell.
256 *
257 * @param options - The options used to create the cell.
258 *
259 * @returns A new code cell. If a source cell is provided, the
260 * new cell will be initialized with the data from the source.
261 */
262 createCodeCell(options: CodeCellModel.IOptions): ICodeCellModel;
263 /**
264 * Create a new markdown cell.
265 *
266 * @param options - The options used to create the cell.
267 *
268 * @returns A new markdown cell. If a source cell is provided, the
269 * new cell will be initialized with the data from the source.
270 */
271 createMarkdownCell(options: CellModel.IOptions): IMarkdownCellModel;
272 /**
273 * Create a new raw cell.
274 *
275 * @param options - The options used to create the cell.
276 *
277 * @returns A new raw cell. If a source cell is provided, the
278 * new cell will be initialized with the data from the source.
279 */
280 createRawCell(options: CellModel.IOptions): IRawCellModel;
281 /**
282 * Clone the content factory with a new IModelDB.
283 */
284 clone(modelDB: IModelDB): IContentFactory;
285 }
286 /**
287 * The default implementation of an `IContentFactory`.
288 */
289 class ContentFactory {
290 /**
291 * Create a new cell model factory.
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 * The options used to initialize a `ContentFactory`.
354 */
355 interface IOptions {
356 /**
357 * The factory for code cell model content.
358 */
359 codeCellContentFactory?: CodeCellModel.IContentFactory;
360 /**
361 * The modelDB in which to place new content.
362 */
363 modelDB?: IModelDB;
364 }
365 }
366 /**
367 * The default `ContentFactory` instance.
368 */
369 const defaultContentFactory: ContentFactory;
370}