1 | import { ISignal, Signal } from '@lumino/signaling';
|
2 | import { IAttachmentsModel } from '@jupyterlab/attachments';
|
3 | import { CodeEditor } from '@jupyterlab/codeeditor';
|
4 | import { IChangedArgs } from '@jupyterlab/coreutils';
|
5 | import * as nbformat from '@jupyterlab/nbformat';
|
6 | import * as models from '@jupyterlab/shared-models';
|
7 | import { IModelDB, IObservableJSON, IObservableValue, ObservableValue } from '@jupyterlab/observables';
|
8 | import { IOutputAreaModel } from '@jupyterlab/outputarea';
|
9 |
|
10 |
|
11 |
|
12 | export interface ICellModel extends CodeEditor.IModel {
|
13 | |
14 |
|
15 |
|
16 | readonly type: nbformat.CellType;
|
17 | |
18 |
|
19 |
|
20 | readonly id: string;
|
21 | |
22 |
|
23 |
|
24 | readonly contentChanged: ISignal<ICellModel, void>;
|
25 | |
26 |
|
27 |
|
28 | readonly stateChanged: ISignal<ICellModel, IChangedArgs<any>>;
|
29 | |
30 |
|
31 |
|
32 | trusted: boolean;
|
33 | |
34 |
|
35 |
|
36 | readonly metadata: IObservableJSON;
|
37 | readonly sharedModel: models.ISharedCell & models.ISharedText;
|
38 | |
39 |
|
40 |
|
41 | toJSON(): nbformat.ICell;
|
42 | }
|
43 |
|
44 |
|
45 |
|
46 | export interface IAttachmentsCellModel extends ICellModel {
|
47 | |
48 |
|
49 |
|
50 | readonly attachments: IAttachmentsModel;
|
51 | }
|
52 |
|
53 |
|
54 |
|
55 | export interface ICodeCellModel extends ICellModel {
|
56 | |
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | readonly type: 'code';
|
63 | |
64 |
|
65 |
|
66 | readonly isDirty: boolean;
|
67 | |
68 |
|
69 |
|
70 | toJSON(): nbformat.ICodeCell;
|
71 | |
72 |
|
73 |
|
74 | executionCount: nbformat.ExecutionCount;
|
75 | |
76 |
|
77 |
|
78 | readonly outputs: IOutputAreaModel;
|
79 | |
80 |
|
81 |
|
82 | clearExecution(): void;
|
83 | }
|
84 |
|
85 |
|
86 |
|
87 | export interface IMarkdownCellModel extends IAttachmentsCellModel {
|
88 | |
89 |
|
90 |
|
91 | readonly type: 'markdown';
|
92 | |
93 |
|
94 |
|
95 | toJSON(): nbformat.IMarkdownCell;
|
96 | }
|
97 |
|
98 |
|
99 |
|
100 | export interface IRawCellModel extends IAttachmentsCellModel {
|
101 | |
102 |
|
103 |
|
104 | readonly type: 'raw';
|
105 | |
106 |
|
107 |
|
108 | toJSON(): nbformat.IRawCell;
|
109 | }
|
110 | export declare function isCodeCellModel(model: ICellModel): model is ICodeCellModel;
|
111 | export declare function isMarkdownCellModel(model: ICellModel): model is IMarkdownCellModel;
|
112 | export declare function isRawCellModel(model: ICellModel): model is IRawCellModel;
|
113 |
|
114 |
|
115 |
|
116 | export declare class CellModel extends CodeEditor.Model implements ICellModel {
|
117 | |
118 |
|
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 | */
|
198 | export declare namespace CellModel {
|
199 | |
200 |
|
201 |
|
202 | interface IOptions {
|
203 | |
204 |
|
205 |
|
206 | cell?: nbformat.IBaseCell;
|
207 | |
208 |
|
209 |
|
210 | modelDB?: IModelDB;
|
211 | |
212 |
|
213 |
|
214 | id?: string;
|
215 | }
|
216 | }
|
217 |
|
218 |
|
219 |
|
220 | export declare class AttachmentsCellModel extends CellModel {
|
221 | |
222 |
|
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 | */
|
238 | export declare namespace AttachmentsCellModel {
|
239 | |
240 |
|
241 |
|
242 | interface IOptions extends CellModel.IOptions {
|
243 | |
244 |
|
245 |
|
246 | contentFactory?: IContentFactory;
|
247 | }
|
248 | |
249 |
|
250 |
|
251 | interface IContentFactory {
|
252 | |
253 |
|
254 |
|
255 | createAttachmentsModel(options: IAttachmentsModel.IOptions): IAttachmentsModel;
|
256 | }
|
257 | |
258 |
|
259 |
|
260 | class ContentFactory implements IContentFactory {
|
261 | |
262 |
|
263 |
|
264 | createAttachmentsModel(options: IAttachmentsModel.IOptions): IAttachmentsModel;
|
265 | }
|
266 | |
267 |
|
268 |
|
269 | const defaultContentFactory: ContentFactory;
|
270 | }
|
271 |
|
272 |
|
273 |
|
274 | export declare class RawCellModel extends AttachmentsCellModel {
|
275 | |
276 |
|
277 |
|
278 | get type(): 'raw';
|
279 | |
280 |
|
281 |
|
282 | toJSON(): nbformat.IRawCell;
|
283 | }
|
284 |
|
285 |
|
286 |
|
287 | export declare class MarkdownCellModel extends AttachmentsCellModel {
|
288 | |
289 |
|
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 | */
|
304 | export declare class CodeCellModel extends CellModel implements ICodeCellModel {
|
305 | |
306 |
|
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 | */
|
376 | export declare namespace CodeCellModel {
|
377 | |
378 |
|
379 |
|
380 | interface IOptions extends CellModel.IOptions {
|
381 | |
382 |
|
383 |
|
384 | contentFactory?: IContentFactory;
|
385 | }
|
386 | |
387 |
|
388 |
|
389 | interface IContentFactory {
|
390 | |
391 |
|
392 |
|
393 | createOutputArea(options: IOutputAreaModel.IOptions): IOutputAreaModel;
|
394 | }
|
395 | |
396 |
|
397 |
|
398 | class ContentFactory implements IContentFactory {
|
399 | |
400 |
|
401 |
|
402 | createOutputArea(options: IOutputAreaModel.IOptions): IOutputAreaModel;
|
403 | }
|
404 | |
405 |
|
406 |
|
407 | const defaultContentFactory: ContentFactory;
|
408 | }
|