1 | import { IChangedArgs } from '@jupyterlab/coreutils';
|
2 | import { DocumentRegistry } from '@jupyterlab/docregistry';
|
3 | import * as nbformat from '@jupyterlab/nbformat';
|
4 | import { IMapChange, ISharedNotebook } from '@jupyter/ydoc';
|
5 | import { ITranslator } from '@jupyterlab/translation';
|
6 | import { ISignal } from '@lumino/signaling';
|
7 | import { CellList } from './celllist';
|
8 |
|
9 |
|
10 |
|
11 | export interface INotebookModel extends DocumentRegistry.IModel {
|
12 | |
13 |
|
14 |
|
15 | readonly cells: CellList;
|
16 | |
17 |
|
18 |
|
19 | readonly nbformat: number;
|
20 | |
21 |
|
22 |
|
23 | readonly nbformatMinor: number;
|
24 | |
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | readonly metadata: nbformat.INotebookMetadata;
|
34 | |
35 |
|
36 |
|
37 | readonly metadataChanged: ISignal<INotebookModel, IMapChange>;
|
38 | |
39 |
|
40 |
|
41 | readonly deletedCells: string[];
|
42 | |
43 |
|
44 |
|
45 | readonly sharedModel: ISharedNotebook;
|
46 | |
47 |
|
48 |
|
49 |
|
50 |
|
51 | deleteMetadata(key: string): void;
|
52 | |
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | getMetadata(key: string): any;
|
61 | |
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | setMetadata(key: string, value: any): void;
|
68 | }
|
69 |
|
70 |
|
71 |
|
72 | export declare class NotebookModel implements INotebookModel {
|
73 | |
74 |
|
75 |
|
76 | constructor(options?: NotebookModel.IOptions);
|
77 | /**
|
78 | * A signal emitted when the document content changes.
|
79 | */
|
80 | get contentChanged(): ISignal<this, void>;
|
81 | /**
|
82 | * Signal emitted when notebook metadata changes.
|
83 | */
|
84 | get metadataChanged(): ISignal<INotebookModel, IMapChange<any>>;
|
85 | /**
|
86 | * A signal emitted when the document state changes.
|
87 | */
|
88 | get stateChanged(): ISignal<this, IChangedArgs<any>>;
|
89 | /**
|
90 | * Get the observable list of notebook cells.
|
91 | */
|
92 | get cells(): CellList;
|
93 | /**
|
94 | * The dirty state of the document.
|
95 | */
|
96 | get dirty(): boolean;
|
97 | set dirty(newValue: boolean);
|
98 | /**
|
99 | * The read only state of the document.
|
100 | */
|
101 | get readOnly(): boolean;
|
102 | set readOnly(newValue: boolean);
|
103 | /**
|
104 | * The metadata associated with the notebook.
|
105 | *
|
106 | * ### Notes
|
107 | * This is a copy of the metadata. Changing a part of it
|
108 | * won't affect the model.
|
109 | * As this returns a copy of all metadata, it is advised to
|
110 | * use `getMetadata` to speed up the process of getting a single key.
|
111 | */
|
112 | get metadata(): nbformat.INotebookMetadata;
|
113 | /**
|
114 | * The major version number of the nbformat.
|
115 | */
|
116 | get nbformat(): number;
|
117 | /**
|
118 | * The minor version number of the nbformat.
|
119 | */
|
120 | get nbformatMinor(): number;
|
121 | /**
|
122 | * The default kernel name of the document.
|
123 | */
|
124 | get defaultKernelName(): string;
|
125 | /**
|
126 | * A list of deleted cells for the notebook..
|
127 | */
|
128 | get deletedCells(): string[];
|
129 | /**
|
130 | * The default kernel language of the document.
|
131 | */
|
132 | get defaultKernelLanguage(): string;
|
133 | /**
|
134 | * Whether the model is collaborative or not.
|
135 | */
|
136 | get collaborative(): boolean;
|
137 | /**
|
138 | * Dispose of the resources held by the model.
|
139 | */
|
140 | dispose(): void;
|
141 | /**
|
142 | * Delete a metadata
|
143 | *
|
144 | * @param key Metadata key
|
145 | */
|
146 | deleteMetadata(key: string): void;
|
147 | /**
|
148 | * Get a metadata
|
149 | *
|
150 | * ### Notes
|
151 | * This returns a copy of the key value.
|
152 | *
|
153 | * @param key Metadata key
|
154 | */
|
155 | getMetadata(key: string): any;
|
156 | /**
|
157 | * Set a metadata
|
158 | *
|
159 | * @param key Metadata key
|
160 | * @param value Metadata value
|
161 | */
|
162 | setMetadata(key: string, value: any): void;
|
163 | /**
|
164 | * Serialize the model to a string.
|
165 | */
|
166 | toString(): string;
|
167 | /**
|
168 | * Deserialize the model from a string.
|
169 | *
|
170 | * #### Notes
|
171 | * Should emit a [contentChanged] signal.
|
172 | */
|
173 | fromString(value: string): void;
|
174 | /**
|
175 | * Serialize the model to JSON.
|
176 | */
|
177 | toJSON(): nbformat.INotebookContent;
|
178 | /**
|
179 | * Deserialize the model from JSON.
|
180 | *
|
181 | * #### Notes
|
182 | * Should emit a [contentChanged] signal.
|
183 | */
|
184 | fromJSON(value: nbformat.INotebookContent): void;
|
185 | /**
|
186 | * Handle a change in the cells list.
|
187 | */
|
188 | private _onCellsChanged;
|
189 | private _onMetadataChanged;
|
190 | private _onStateChanged;
|
191 | /**
|
192 | * Make sure we have the required metadata fields.
|
193 | */
|
194 | private _ensureMetadata;
|
195 | /**
|
196 | * Trigger a state change signal.
|
197 | */
|
198 | protected triggerStateChange(args: IChangedArgs<any>): void;
|
199 | /**
|
200 | * Trigger a content changed signal.
|
201 | */
|
202 | protected triggerContentChange(): void;
|
203 | /**
|
204 | * Whether the model is disposed.
|
205 | */
|
206 | get isDisposed(): boolean;
|
207 | /**
|
208 | * The shared notebook model.
|
209 | */
|
210 | readonly sharedModel: ISharedNotebook;
|
211 | /**
|
212 | * Whether the model should disposed the shared model on disposal or not.
|
213 | */
|
214 | protected standaloneModel: boolean;
|
215 | private _dirty;
|
216 | private _readOnly;
|
217 | private _contentChanged;
|
218 | private _stateChanged;
|
219 | private _trans;
|
220 | private _cells;
|
221 | private _deletedCells;
|
222 | private _isDisposed;
|
223 | private _metadataChanged;
|
224 | private _collaborationEnabled;
|
225 | }
|
226 | /**
|
227 | * The namespace for the `NotebookModel` class statics.
|
228 | */
|
229 | export declare namespace NotebookModel {
|
230 | |
231 |
|
232 |
|
233 | interface IOptions extends DocumentRegistry.IModelOptions<ISharedNotebook> {
|
234 | |
235 |
|
236 |
|
237 | defaultCell?: 'code' | 'markdown' | 'raw';
|
238 | |
239 |
|
240 |
|
241 | translator?: ITranslator;
|
242 | |
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 | disableDocumentWideUndoRedo?: boolean;
|
251 | }
|
252 | }
|