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 { ObservableValue } from '@jupyterlab/observables';
|
7 | import { IOutputAreaModel } from '@jupyterlab/outputarea';
|
8 | import { IMapChange, ISharedCell, ISharedCodeCell, ISharedMarkdownCell, ISharedRawCell } from '@jupyter/ydoc';
|
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<boolean, boolean, any>>;
|
29 | |
30 |
|
31 |
|
32 | trusted: boolean;
|
33 | |
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | readonly metadata: Omit<nbformat.IBaseCellMetadata, 'trusted'>;
|
43 | |
44 |
|
45 |
|
46 | readonly metadataChanged: ISignal<ICellModel, IMapChange>;
|
47 | |
48 |
|
49 |
|
50 | readonly sharedModel: ISharedCell;
|
51 | |
52 |
|
53 |
|
54 |
|
55 |
|
56 | deleteMetadata(key: string): void;
|
57 | |
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | getMetadata(key: string): any;
|
66 | |
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | setMetadata(key: string, value: any): void;
|
73 | |
74 |
|
75 |
|
76 | toJSON(): nbformat.ICell;
|
77 | }
|
78 |
|
79 |
|
80 |
|
81 | export interface IAttachmentsCellModel extends ICellModel {
|
82 | |
83 |
|
84 |
|
85 | readonly attachments: IAttachmentsModel;
|
86 | }
|
87 |
|
88 |
|
89 |
|
90 | export interface ICodeCellModel extends ICellModel {
|
91 | |
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 | readonly type: 'code';
|
98 | |
99 |
|
100 |
|
101 | readonly isDirty: boolean;
|
102 | |
103 |
|
104 |
|
105 | toJSON(): nbformat.ICodeCell;
|
106 | |
107 |
|
108 |
|
109 | executionCount: nbformat.ExecutionCount;
|
110 | |
111 |
|
112 |
|
113 | readonly outputs: IOutputAreaModel;
|
114 | |
115 |
|
116 |
|
117 | clearExecution(): void;
|
118 | |
119 |
|
120 |
|
121 | readonly sharedModel: ISharedCodeCell;
|
122 | }
|
123 |
|
124 |
|
125 |
|
126 | export interface IMarkdownCellModel extends IAttachmentsCellModel {
|
127 | |
128 |
|
129 |
|
130 | readonly type: 'markdown';
|
131 | |
132 |
|
133 |
|
134 | toJSON(): nbformat.IMarkdownCell;
|
135 | }
|
136 |
|
137 |
|
138 |
|
139 | export interface IRawCellModel extends IAttachmentsCellModel {
|
140 | |
141 |
|
142 |
|
143 | readonly type: 'raw';
|
144 | |
145 |
|
146 |
|
147 | toJSON(): nbformat.IRawCell;
|
148 | }
|
149 | export declare function isCodeCellModel(model: ICellModel): model is ICodeCellModel;
|
150 | export declare function isMarkdownCellModel(model: ICellModel): model is IMarkdownCellModel;
|
151 | export declare function isRawCellModel(model: ICellModel): model is IRawCellModel;
|
152 |
|
153 |
|
154 |
|
155 | export declare abstract class CellModel extends CodeEditor.Model implements ICellModel {
|
156 | constructor(options?: CellModel.IOptions<ISharedCell>);
|
157 | readonly sharedModel: ISharedCell;
|
158 | /**
|
159 | * The type of cell.
|
160 | */
|
161 | abstract get type(): nbformat.CellType;
|
162 | /**
|
163 | * A signal emitted when the state of the model changes.
|
164 | */
|
165 | readonly contentChanged: Signal<this, void>;
|
166 | /**
|
167 | * Signal emitted when cell metadata changes.
|
168 | */
|
169 | get metadataChanged(): ISignal<ICellModel, IMapChange>;
|
170 | /**
|
171 | * A signal emitted when a model state changes.
|
172 | */
|
173 | readonly stateChanged: Signal<this, IChangedArgs<any, any, "trusted" | "isDirty" | "executionCount">>;
|
174 | /**
|
175 | * The id for the cell.
|
176 | */
|
177 | get id(): string;
|
178 | /**
|
179 | * The metadata associated with the cell.
|
180 | */
|
181 | get metadata(): Omit<nbformat.IBaseCellMetadata, 'trusted'>;
|
182 | /**
|
183 | * The trusted state of the model.
|
184 | */
|
185 | get trusted(): boolean;
|
186 | set trusted(newValue: boolean);
|
187 | /**
|
188 | * Dispose of the resources held by the model.
|
189 | */
|
190 | dispose(): void;
|
191 | /**
|
192 | * Handle a change to the trusted state.
|
193 | *
|
194 | * The default implementation is a no-op.
|
195 | */
|
196 | onTrustedChanged(trusted: CellModel, args: ObservableValue.IChangedArgs): void;
|
197 | /**
|
198 | * Delete a metadata
|
199 | *
|
200 | * @param key Metadata key
|
201 | */
|
202 | deleteMetadata(key: string): any;
|
203 | /**
|
204 | * Get a metadata
|
205 | *
|
206 | * ### Notes
|
207 | * This returns a copy of the key value.
|
208 | *
|
209 | * @param key Metadata key
|
210 | */
|
211 | getMetadata(key: string): any;
|
212 | /**
|
213 | * Set a metadata
|
214 | *
|
215 | * @param key Metadata key
|
216 | * @param value Metadata value
|
217 | */
|
218 | setMetadata(key: string, value: any): void;
|
219 | /**
|
220 | * Serialize the model to JSON.
|
221 | */
|
222 | toJSON(): nbformat.ICell;
|
223 | /**
|
224 | * Handle a change to the observable value.
|
225 | */
|
226 | protected onGenericChange(): void;
|
227 | private _onMetadataChanged;
|
228 | private _metadataChanged;
|
229 | private _trusted;
|
230 | }
|
231 | /**
|
232 | * The namespace for `CellModel` statics.
|
233 | */
|
234 | export declare namespace CellModel {
|
235 | |
236 |
|
237 |
|
238 | interface IOptions<T extends ISharedCell> {
|
239 | |
240 |
|
241 |
|
242 | id?: string;
|
243 | |
244 |
|
245 |
|
246 | sharedModel?: T;
|
247 | |
248 |
|
249 |
|
250 | cell_type?: string;
|
251 | |
252 |
|
253 |
|
254 | trusted?: boolean;
|
255 | }
|
256 | }
|
257 |
|
258 |
|
259 |
|
260 | export declare abstract class AttachmentsCellModel extends CellModel {
|
261 | |
262 |
|
263 |
|
264 | constructor(options: AttachmentsCellModel.IOptions<ISharedCell>);
|
265 | /**
|
266 | * Get the attachments of the model.
|
267 | */
|
268 | get attachments(): IAttachmentsModel;
|
269 | /**
|
270 | * Dispose of the resources held by the model.
|
271 | */
|
272 | dispose(): void;
|
273 | /**
|
274 | * Serialize the model to JSON.
|
275 | */
|
276 | toJSON(): nbformat.IRawCell | nbformat.IMarkdownCell;
|
277 | /**
|
278 | * Handle a change to the cell outputs modelDB and reflect it in the shared model.
|
279 | */
|
280 | private _onAttachmentsChange;
|
281 | /**
|
282 | * Handle a change to the code cell value.
|
283 | */
|
284 | private _onSharedModelChanged;
|
285 | private _attachments;
|
286 | }
|
287 | /**
|
288 | * The namespace for `AttachmentsCellModel` statics.
|
289 | */
|
290 | export declare namespace AttachmentsCellModel {
|
291 | |
292 |
|
293 |
|
294 | interface IOptions<T extends ISharedCell> extends CellModel.IOptions<T> {
|
295 | |
296 |
|
297 |
|
298 | contentFactory?: IContentFactory;
|
299 | }
|
300 | |
301 |
|
302 |
|
303 | interface IContentFactory {
|
304 | |
305 |
|
306 |
|
307 | createAttachmentsModel(options: IAttachmentsModel.IOptions): IAttachmentsModel;
|
308 | }
|
309 | |
310 |
|
311 |
|
312 | class ContentFactory implements IContentFactory {
|
313 | |
314 |
|
315 |
|
316 | createAttachmentsModel(options: IAttachmentsModel.IOptions): IAttachmentsModel;
|
317 | }
|
318 | |
319 |
|
320 |
|
321 | const defaultContentFactory: ContentFactory;
|
322 | }
|
323 |
|
324 |
|
325 |
|
326 | export declare class RawCellModel extends AttachmentsCellModel {
|
327 | |
328 |
|
329 |
|
330 | constructor(options?: Omit<AttachmentsCellModel.IOptions<ISharedRawCell>, 'cell_type'>);
|
331 | /**
|
332 | * The type of the cell.
|
333 | */
|
334 | get type(): 'raw';
|
335 | /**
|
336 | * Serialize the model to JSON.
|
337 | */
|
338 | toJSON(): nbformat.IRawCell;
|
339 | }
|
340 | /**
|
341 | * An implementation of a markdown cell model.
|
342 | */
|
343 | export declare class MarkdownCellModel extends AttachmentsCellModel {
|
344 | |
345 |
|
346 |
|
347 | constructor(options?: Omit<AttachmentsCellModel.IOptions<ISharedMarkdownCell>, 'cell_type'>);
|
348 | /**
|
349 | * The type of the cell.
|
350 | */
|
351 | get type(): 'markdown';
|
352 | /**
|
353 | * Serialize the model to JSON.
|
354 | */
|
355 | toJSON(): nbformat.IMarkdownCell;
|
356 | }
|
357 | /**
|
358 | * An implementation of a code cell Model.
|
359 | */
|
360 | export declare class CodeCellModel extends CellModel implements ICodeCellModel {
|
361 | |
362 |
|
363 |
|
364 | constructor(options?: CodeCellModel.IOptions);
|
365 | /**
|
366 | * The type of the cell.
|
367 | */
|
368 | get type(): 'code';
|
369 | /**
|
370 | * The execution count of the cell.
|
371 | */
|
372 | get executionCount(): nbformat.ExecutionCount;
|
373 | set executionCount(newValue: nbformat.ExecutionCount);
|
374 | /**
|
375 | * Whether the cell is dirty or not.
|
376 | *
|
377 | * A cell is dirty if it is output is not empty and does not
|
378 | * result of the input code execution.
|
379 | */
|
380 | get isDirty(): boolean;
|
381 | /**
|
382 | * The cell outputs.
|
383 | */
|
384 | get outputs(): IOutputAreaModel;
|
385 | readonly sharedModel: ISharedCodeCell;
|
386 | clearExecution(): void;
|
387 | /**
|
388 | * Dispose of the resources held by the model.
|
389 | */
|
390 | dispose(): void;
|
391 | /**
|
392 | * Handle a change to the trusted state.
|
393 | */
|
394 | onTrustedChanged(trusted: CellModel, args: ObservableValue.IChangedArgs): void;
|
395 | /**
|
396 | * Serialize the model to JSON.
|
397 | */
|
398 | toJSON(): nbformat.ICodeCell;
|
399 | /**
|
400 | * Handle a change to the cell outputs modelDB and reflect it in the shared model.
|
401 | */
|
402 | protected onOutputsChange(sender: IOutputAreaModel, event: IOutputAreaModel.ChangedArgs): void;
|
403 | /**
|
404 | * Handle a change to the code cell value.
|
405 | */
|
406 | private _onSharedModelChanged;
|
407 | /**
|
408 | * Set whether the cell is dirty or not.
|
409 | */
|
410 | private _setDirty;
|
411 | private _executedCode;
|
412 | private _isDirty;
|
413 | private _outputs;
|
414 | }
|
415 | /**
|
416 | * The namespace for `CodeCellModel` statics.
|
417 | */
|
418 | export declare namespace CodeCellModel {
|
419 | |
420 |
|
421 |
|
422 | interface IOptions extends Omit<CellModel.IOptions<ISharedCodeCell>, 'cell_type'> {
|
423 | |
424 |
|
425 |
|
426 | contentFactory?: IContentFactory;
|
427 | }
|
428 | |
429 |
|
430 |
|
431 | interface IContentFactory {
|
432 | |
433 |
|
434 |
|
435 | createOutputArea(options: IOutputAreaModel.IOptions): IOutputAreaModel;
|
436 | }
|
437 | |
438 |
|
439 |
|
440 | class ContentFactory implements IContentFactory {
|
441 | |
442 |
|
443 |
|
444 | createOutputArea(options: IOutputAreaModel.IOptions): IOutputAreaModel;
|
445 | }
|
446 | |
447 |
|
448 |
|
449 | const defaultContentFactory: ContentFactory;
|
450 | }
|