UNPKG

6.65 kBTypeScriptView Raw
1import { IChangedArgs } from '@jupyterlab/coreutils';
2import { DocumentRegistry } from '@jupyterlab/docregistry';
3import * as nbformat from '@jupyterlab/nbformat';
4import { IMapChange, ISharedNotebook } from '@jupyter/ydoc';
5import { ITranslator } from '@jupyterlab/translation';
6import { ISignal } from '@lumino/signaling';
7import { CellList } from './celllist';
8/**
9 * The definition of a model object for a notebook widget.
10 */
11export interface INotebookModel extends DocumentRegistry.IModel {
12 /**
13 * The list of cells in the notebook.
14 */
15 readonly cells: CellList;
16 /**
17 * The major version number of the nbformat.
18 */
19 readonly nbformat: number;
20 /**
21 * The minor version number of the nbformat.
22 */
23 readonly nbformatMinor: number;
24 /**
25 * The metadata associated with the notebook.
26 *
27 * ### Notes
28 * This is a copy of the metadata. Changing a part of it
29 * won't affect the model.
30 * As this returns a copy of all metadata, it is advised to
31 * use `getMetadata` to speed up the process of getting a single key.
32 */
33 readonly metadata: nbformat.INotebookMetadata;
34 /**
35 * Signal emitted when notebook metadata changes.
36 */
37 readonly metadataChanged: ISignal<INotebookModel, IMapChange>;
38 /**
39 * The array of deleted cells since the notebook was last run.
40 */
41 readonly deletedCells: string[];
42 /**
43 * Shared model
44 */
45 readonly sharedModel: ISharedNotebook;
46 /**
47 * Delete a metadata
48 *
49 * @param key Metadata key
50 */
51 deleteMetadata(key: string): void;
52 /**
53 * Get a metadata
54 *
55 * ### Notes
56 * This returns a copy of the key value.
57 *
58 * @param key Metadata key
59 */
60 getMetadata(key: string): any;
61 /**
62 * Set a metadata
63 *
64 * @param key Metadata key
65 * @param value Metadata value
66 */
67 setMetadata(key: string, value: any): void;
68}
69/**
70 * An implementation of a notebook Model.
71 */
72export declare class NotebookModel implements INotebookModel {
73 /**
74 * Construct a new notebook model.
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 */
229export declare namespace NotebookModel {
230 /**
231 * An options object for initializing a notebook model.
232 */
233 interface IOptions extends DocumentRegistry.IModelOptions<ISharedNotebook> {
234 /**
235 * Default cell type.
236 */
237 defaultCell?: 'code' | 'markdown' | 'raw';
238 /**
239 * Language translator.
240 */
241 translator?: ITranslator;
242 /**
243 * Defines if the document can be undo/redo.
244 *
245 * Default: true
246 *
247 * @experimental
248 * @alpha
249 */
250 disableDocumentWideUndoRedo?: boolean;
251 }
252}