UNPKG

12.6 kBTypeScriptView Raw
1import { ISignal, Signal } from '@lumino/signaling';
2import { IAttachmentsModel } from '@jupyterlab/attachments';
3import { CodeEditor } from '@jupyterlab/codeeditor';
4import { IChangedArgs } from '@jupyterlab/coreutils';
5import * as nbformat from '@jupyterlab/nbformat';
6import * as models from '@jupyter/ydoc';
7import { IModelDB, IObservableJSON, IObservableValue, ObservableValue } from '@jupyterlab/observables';
8import { IOutputAreaModel } from '@jupyterlab/outputarea';
9/**
10 * The definition of a model object for a cell.
11 */
12export interface ICellModel extends CodeEditor.IModel {
13 /**
14 * The type of the cell.
15 */
16 readonly type: nbformat.CellType;
17 /**
18 * A unique identifier for the cell.
19 */
20 readonly id: string;
21 /**
22 * A signal emitted when the content of the model changes.
23 */
24 readonly contentChanged: ISignal<ICellModel, void>;
25 /**
26 * A signal emitted when a model state changes.
27 */
28 readonly stateChanged: ISignal<ICellModel, IChangedArgs<any>>;
29 /**
30 * Whether the cell is trusted.
31 */
32 trusted: boolean;
33 /**
34 * The metadata associated with the cell.
35 */
36 readonly metadata: IObservableJSON;
37 readonly sharedModel: models.ISharedCell & models.ISharedText;
38 /**
39 * Serialize the model to JSON.
40 */
41 toJSON(): nbformat.ICell;
42}
43/**
44 * The definition of a model cell object for a cell with attachments.
45 */
46export interface IAttachmentsCellModel extends ICellModel {
47 /**
48 * The cell attachments
49 */
50 readonly attachments: IAttachmentsModel;
51}
52/**
53 * The definition of a code cell.
54 */
55export interface ICodeCellModel extends ICellModel {
56 /**
57 * The type of the cell.
58 *
59 * #### Notes
60 * This is a read-only property.
61 */
62 readonly type: 'code';
63 /**
64 * Whether the code cell has been edited since the last run.
65 */
66 readonly isDirty: boolean;
67 /**
68 * Serialize the model to JSON.
69 */
70 toJSON(): nbformat.ICodeCell;
71 /**
72 * The code cell's prompt number. Will be null if the cell has not been run.
73 */
74 executionCount: nbformat.ExecutionCount;
75 /**
76 * The cell outputs.
77 */
78 readonly outputs: IOutputAreaModel;
79 /**
80 * Clear execution, outputs, and related metadata
81 */
82 clearExecution(): void;
83}
84/**
85 * The definition of a markdown cell.
86 */
87export interface IMarkdownCellModel extends IAttachmentsCellModel {
88 /**
89 * The type of the cell.
90 */
91 readonly type: 'markdown';
92 /**
93 * Serialize the model to JSON.
94 */
95 toJSON(): nbformat.IMarkdownCell;
96}
97/**
98 * The definition of a raw cell.
99 */
100export interface IRawCellModel extends IAttachmentsCellModel {
101 /**
102 * The type of the cell.
103 */
104 readonly type: 'raw';
105 /**
106 * Serialize the model to JSON.
107 */
108 toJSON(): nbformat.IRawCell;
109}
110export declare function isCodeCellModel(model: ICellModel): model is ICodeCellModel;
111export declare function isMarkdownCellModel(model: ICellModel): model is IMarkdownCellModel;
112export declare function isRawCellModel(model: ICellModel): model is IRawCellModel;
113/**
114 * An implementation of the cell model.
115 */
116export declare class CellModel extends CodeEditor.Model implements ICellModel {
117 /**
118 * Construct a cell model from optional cell content.
119 */
120 constructor(options: CellModel.IOptions);
121 /**
122 * The type of cell.
123 */
124 get type(): nbformat.CellType;
125 /**
126 * A signal emitted when the state of the model changes.
127 */
128 readonly contentChanged: Signal<this, void>;
129 /**
130 * A signal emitted when a model state changes.
131 */
132 readonly stateChanged: Signal<this, IChangedArgs<any, any, string>>;
133 /**
134 * The id for the cell.
135 */
136 get id(): string;
137 /**
138 * The metadata associated with the cell.
139 */
140 get metadata(): IObservableJSON;
141 /**
142 * Get the trusted state of the model.
143 */
144 get trusted(): boolean;
145 /**
146 * Set the trusted state of the model.
147 */
148 set trusted(newValue: boolean);
149 /**
150 * Serialize the model to JSON.
151 */
152 toJSON(): nbformat.ICell;
153 /**
154 * Handle a change to the trusted state.
155 *
156 * The default implementation is a no-op.
157 */
158 onTrustedChanged(trusted: IObservableValue, args: ObservableValue.IChangedArgs): void;
159 /**
160 * When we initialize a cell model, we create a standalone model that cannot be shared in a YNotebook.
161 * Call this function to re-initialize the local representation based on a fresh shared model (e.g. models.YFile or models.YCodeCell).
162 *
163 * @param sharedModel
164 * @param reinitialize Whether to reinitialize the shared model.
165 */
166 switchSharedModel(sharedModel: models.ISharedCodeCell, reinitialize?: boolean): void;
167 /**
168 * Handle a change to the cell metadata modelDB and reflect it in the shared model.
169 */
170 protected onModelDBMetadataChange(sender: IObservableJSON, event: IObservableJSON.IChangedArgs): void;
171 /**
172 * Change the cell metadata for a given event.
173 *
174 * @param metadata The cell metadata.
175 * @param event The event to handle.
176 */
177 private _changeCellMetadata;
178 /**
179 * Handle a change to the cell shared model and reflect it in modelDB.
180 * We update the modeldb metadata when the shared model changes.
181 *
182 * This method overrides the CodeEditor protected _onSharedModelChanged
183 * so we first call super._onSharedModelChanged
184 *
185 * @override CodeEditor._onSharedModelChanged
186 */
187 protected _onSharedModelChanged(sender: models.ISharedCodeCell, change: models.CellChange<nbformat.IBaseCellMetadata>): void;
188 private _updateModelDBMetadata;
189 /**
190 * Handle a change to the observable value.
191 */
192 protected onGenericChange(): void;
193 sharedModel: models.ISharedCell;
194}
195/**
196 * The namespace for `CellModel` statics.
197 */
198export declare namespace CellModel {
199 /**
200 * The options used to initialize a `CellModel`.
201 */
202 interface IOptions {
203 /**
204 * The source cell data.
205 */
206 cell?: nbformat.IBaseCell;
207 /**
208 * An IModelDB in which to store cell data.
209 */
210 modelDB?: IModelDB;
211 /**
212 * A unique identifier for this cell.
213 */
214 id?: string;
215 }
216}
217/**
218 * A base implementation for cell models with attachments.
219 */
220export declare class AttachmentsCellModel extends CellModel {
221 /**
222 * Construct a new cell with optional attachments.
223 */
224 constructor(options: AttachmentsCellModel.IOptions);
225 /**
226 * Get the attachments of the model.
227 */
228 get attachments(): IAttachmentsModel;
229 /**
230 * Serialize the model to JSON.
231 */
232 toJSON(): nbformat.IRawCell | nbformat.IMarkdownCell;
233 switchSharedModel(sharedModel: models.ISharedCodeCell, reinitialize?: boolean): void;
234 /**
235 * Handle a change to the cell outputs modelDB and reflect it in the shared model.
236 */
237 protected onModelDBAttachmentsChange(sender: IAttachmentsModel, event: IAttachmentsModel.ChangedArgs): void;
238 /**
239 * Handle a change to the output shared model and reflect it in modelDB.
240 * We update the modeldb metadata when the nbcell changes.
241 *
242 * This method overrides the CellModel protected _onSharedModelChanged
243 * so we first call super._onSharedModelChanged
244 *
245 * @override CellModel._onSharedModelChanged
246 */
247 protected _onSharedModelChanged(sender: models.ISharedCodeCell, change: models.CellChange<nbformat.IBaseCellMetadata>): void;
248 private _attachments;
249}
250/**
251 * The namespace for `AttachmentsCellModel` statics.
252 */
253export declare namespace AttachmentsCellModel {
254 /**
255 * The options used to initialize a `AttachmentsCellModel`.
256 */
257 interface IOptions extends CellModel.IOptions {
258 /**
259 * The factory for attachment model creation.
260 */
261 contentFactory?: IContentFactory;
262 }
263 /**
264 * A factory for creating code cell model content.
265 */
266 interface IContentFactory {
267 /**
268 * Create an output area.
269 */
270 createAttachmentsModel(options: IAttachmentsModel.IOptions): IAttachmentsModel;
271 }
272 /**
273 * The default implementation of an `IContentFactory`.
274 */
275 class ContentFactory implements IContentFactory {
276 /**
277 * Create an attachments model.
278 */
279 createAttachmentsModel(options: IAttachmentsModel.IOptions): IAttachmentsModel;
280 }
281 /**
282 * The shared `ContentFactory` instance.
283 */
284 const defaultContentFactory: ContentFactory;
285}
286/**
287 * An implementation of a raw cell model.
288 */
289export declare class RawCellModel extends AttachmentsCellModel {
290 /**
291 * The type of the cell.
292 */
293 get type(): 'raw';
294 /**
295 * Serialize the model to JSON.
296 */
297 toJSON(): nbformat.IRawCell;
298}
299/**
300 * An implementation of a markdown cell model.
301 */
302export declare class MarkdownCellModel extends AttachmentsCellModel {
303 /**
304 * Construct a markdown cell model from optional cell content.
305 */
306 constructor(options: CellModel.IOptions);
307 /**
308 * The type of the cell.
309 */
310 get type(): 'markdown';
311 /**
312 * Serialize the model to JSON.
313 */
314 toJSON(): nbformat.IMarkdownCell;
315}
316/**
317 * An implementation of a code cell Model.
318 */
319export declare class CodeCellModel extends CellModel implements ICodeCellModel {
320 /**
321 * Construct a new code cell with optional original cell content.
322 */
323 constructor(options: CodeCellModel.IOptions);
324 switchSharedModel(sharedModel: models.ISharedCodeCell, reinitialize?: boolean): void;
325 /**
326 * The type of the cell.
327 */
328 get type(): 'code';
329 /**
330 * The execution count of the cell.
331 */
332 get executionCount(): nbformat.ExecutionCount;
333 set executionCount(newValue: nbformat.ExecutionCount);
334 /**
335 * Whether the cell is dirty or not.
336 *
337 * A cell is dirty if it is output is not empty and does not
338 * result of the input code execution.
339 */
340 get isDirty(): boolean;
341 /**
342 * Set whether the cell is dirty or not.
343 */
344 private _setDirty;
345 clearExecution(): void;
346 /**
347 * The cell outputs.
348 */
349 get outputs(): IOutputAreaModel;
350 /**
351 * Dispose of the resources held by the model.
352 */
353 dispose(): void;
354 /**
355 * Serialize the model to JSON.
356 */
357 toJSON(): nbformat.ICodeCell;
358 /**
359 * Handle a change to the trusted state.
360 */
361 onTrustedChanged(trusted: IObservableValue, args: ObservableValue.IChangedArgs): void;
362 /**
363 * Handle a change to the cell outputs modelDB and reflect it in the shared model.
364 */
365 protected onModelDBOutputsChange(sender: IOutputAreaModel, event: IOutputAreaModel.ChangedArgs): void;
366 /**
367 * Handle a change to the code cell value.
368 */
369 private _onValueChanged;
370 /**
371 * Handle a change to the output shared model and reflect it in modelDB.
372 * We update the modeldb metadata when the nbcell changes.
373 *
374 * This method overrides the CellModel protected _onSharedModelChanged
375 * so we first call super._onSharedModelChanged
376 *
377 * @override CellModel._onSharedModelChanged
378 */
379 protected _onSharedModelChanged(sender: models.ISharedCodeCell, change: models.CellChange<nbformat.IBaseCellMetadata>): void;
380 /**
381 * Handle a change to the execution count.
382 */
383 private _onExecutionCountChanged;
384 private _executedCode;
385 private _isDirty;
386 private _outputs;
387}
388/**
389 * The namespace for `CodeCellModel` statics.
390 */
391export declare namespace CodeCellModel {
392 /**
393 * The options used to initialize a `CodeCellModel`.
394 */
395 interface IOptions extends CellModel.IOptions {
396 /**
397 * The factory for output area model creation.
398 */
399 contentFactory?: IContentFactory;
400 }
401 /**
402 * A factory for creating code cell model content.
403 */
404 interface IContentFactory {
405 /**
406 * Create an output area.
407 */
408 createOutputArea(options: IOutputAreaModel.IOptions): IOutputAreaModel;
409 }
410 /**
411 * The default implementation of an `IContentFactory`.
412 */
413 class ContentFactory implements IContentFactory {
414 /**
415 * Create an output area.
416 */
417 createOutputArea(options: IOutputAreaModel.IOptions): IOutputAreaModel;
418 }
419 /**
420 * The shared `ContentFactory` instance.
421 */
422 const defaultContentFactory: ContentFactory;
423}