UNPKG

11.8 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 '@jupyterlab/shared-models';
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<models.ISharedBaseCellMetadata>): 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 private _attachments;
234}
235/**
236 * The namespace for `AttachmentsCellModel` statics.
237 */
238export declare namespace AttachmentsCellModel {
239 /**
240 * The options used to initialize a `AttachmentsCellModel`.
241 */
242 interface IOptions extends CellModel.IOptions {
243 /**
244 * The factory for attachment model creation.
245 */
246 contentFactory?: IContentFactory;
247 }
248 /**
249 * A factory for creating code cell model content.
250 */
251 interface IContentFactory {
252 /**
253 * Create an output area.
254 */
255 createAttachmentsModel(options: IAttachmentsModel.IOptions): IAttachmentsModel;
256 }
257 /**
258 * The default implementation of an `IContentFactory`.
259 */
260 class ContentFactory implements IContentFactory {
261 /**
262 * Create an attachments model.
263 */
264 createAttachmentsModel(options: IAttachmentsModel.IOptions): IAttachmentsModel;
265 }
266 /**
267 * The shared `ContentFactory` instance.
268 */
269 const defaultContentFactory: ContentFactory;
270}
271/**
272 * An implementation of a raw cell model.
273 */
274export declare class RawCellModel extends AttachmentsCellModel {
275 /**
276 * The type of the cell.
277 */
278 get type(): 'raw';
279 /**
280 * Serialize the model to JSON.
281 */
282 toJSON(): nbformat.IRawCell;
283}
284/**
285 * An implementation of a markdown cell model.
286 */
287export declare class MarkdownCellModel extends AttachmentsCellModel {
288 /**
289 * Construct a markdown cell model from optional cell content.
290 */
291 constructor(options: CellModel.IOptions);
292 /**
293 * The type of the cell.
294 */
295 get type(): 'markdown';
296 /**
297 * Serialize the model to JSON.
298 */
299 toJSON(): nbformat.IMarkdownCell;
300}
301/**
302 * An implementation of a code cell Model.
303 */
304export declare class CodeCellModel extends CellModel implements ICodeCellModel {
305 /**
306 * Construct a new code cell with optional original cell content.
307 */
308 constructor(options: CodeCellModel.IOptions);
309 switchSharedModel(sharedModel: models.ISharedCodeCell, reinitialize?: boolean): void;
310 /**
311 * The type of the cell.
312 */
313 get type(): 'code';
314 /**
315 * The execution count of the cell.
316 */
317 get executionCount(): nbformat.ExecutionCount;
318 set executionCount(newValue: nbformat.ExecutionCount);
319 /**
320 * Whether the cell is dirty or not.
321 *
322 * A cell is dirty if it is output is not empty and does not
323 * result of the input code execution.
324 */
325 get isDirty(): boolean;
326 /**
327 * Set whether the cell is dirty or not.
328 */
329 private _setDirty;
330 clearExecution(): void;
331 /**
332 * The cell outputs.
333 */
334 get outputs(): IOutputAreaModel;
335 /**
336 * Dispose of the resources held by the model.
337 */
338 dispose(): void;
339 /**
340 * Serialize the model to JSON.
341 */
342 toJSON(): nbformat.ICodeCell;
343 /**
344 * Handle a change to the trusted state.
345 */
346 onTrustedChanged(trusted: IObservableValue, args: ObservableValue.IChangedArgs): void;
347 /**
348 * Handle a change to the cell outputs modelDB and reflect it in the shared model.
349 */
350 protected onModelDBOutputsChange(sender: IOutputAreaModel, event: IOutputAreaModel.ChangedArgs): void;
351 /**
352 * Handle a change to the code cell value.
353 */
354 private _onValueChanged;
355 /**
356 * Handle a change to the output shared model and reflect it in modelDB.
357 * We update the modeldb metadata when the nbcell changes.
358 *
359 * This method overrides the CellModel protected _onSharedModelChanged
360 * so we first call super._onSharedModelChanged
361 *
362 * @override CellModel._onSharedModelChanged
363 */
364 protected _onSharedModelChanged(sender: models.ISharedCodeCell, change: models.CellChange<models.ISharedBaseCellMetadata>): void;
365 /**
366 * Handle a change to the execution count.
367 */
368 private _onExecutionCountChanged;
369 private _executedCode;
370 private _isDirty;
371 private _outputs;
372}
373/**
374 * The namespace for `CodeCellModel` statics.
375 */
376export declare namespace CodeCellModel {
377 /**
378 * The options used to initialize a `CodeCellModel`.
379 */
380 interface IOptions extends CellModel.IOptions {
381 /**
382 * The factory for output area model creation.
383 */
384 contentFactory?: IContentFactory;
385 }
386 /**
387 * A factory for creating code cell model content.
388 */
389 interface IContentFactory {
390 /**
391 * Create an output area.
392 */
393 createOutputArea(options: IOutputAreaModel.IOptions): IOutputAreaModel;
394 }
395 /**
396 * The default implementation of an `IContentFactory`.
397 */
398 class ContentFactory implements IContentFactory {
399 /**
400 * Create an output area.
401 */
402 createOutputArea(options: IOutputAreaModel.IOptions): IOutputAreaModel;
403 }
404 /**
405 * The shared `ContentFactory` instance.
406 */
407 const defaultContentFactory: ContentFactory;
408}