1 | import { ISessionContext } from '@jupyterlab/apputils';
|
2 | import { IChangedArgs } from '@jupyterlab/coreutils';
|
3 | import { CodeEditor, CodeEditorWrapper } from '@jupyterlab/codeeditor';
|
4 | import { IObservableJSON, IObservableMap } from '@jupyterlab/observables';
|
5 | import { IOutputPrompt, IStdin, OutputArea, Stdin } from '@jupyterlab/outputarea';
|
6 | import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
|
7 | import { KernelMessage } from '@jupyterlab/services';
|
8 | import { JSONObject, JSONValue, PartialJSONValue } from '@lumino/coreutils';
|
9 | import { Message } from '@lumino/messaging';
|
10 | import { ISignal, Signal } from '@lumino/signaling';
|
11 | import { Widget } from '@lumino/widgets';
|
12 | import { ICellFooter, ICellHeader } from './headerfooter';
|
13 | import { IInputPrompt, InputArea } from './inputarea';
|
14 | import { IAttachmentsCellModel, ICellModel, ICodeCellModel, IMarkdownCellModel, IRawCellModel } from './model';
|
15 | export declare const MARKDOWN_HEADING_COLLAPSED = "jp-MarkdownHeadingCollapsed";
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | export declare class Cell<T extends ICellModel = ICellModel> extends Widget {
|
23 | |
24 |
|
25 |
|
26 | constructor(options: Cell.IOptions<T>);
|
27 | /**
|
28 | * Initialize view state from model.
|
29 | *
|
30 | * #### Notes
|
31 | * Should be called after construction. For convenience, returns this, so it
|
32 | * can be chained in the construction, like `new Foo().initializeState();`
|
33 | */
|
34 | initializeState(): this;
|
35 | /**
|
36 | * The content factory used by the widget.
|
37 | */
|
38 | readonly contentFactory: Cell.IContentFactory;
|
39 | /**
|
40 | * Signal to indicate that widget has changed visibly (in size, in type, etc)
|
41 | */
|
42 | get displayChanged(): ISignal<this, void>;
|
43 | /**
|
44 | * Get the prompt node used by the cell.
|
45 | */
|
46 | get promptNode(): HTMLElement;
|
47 | /**
|
48 | * Get the CodeEditorWrapper used by the cell.
|
49 | */
|
50 | get editorWidget(): CodeEditorWrapper;
|
51 | /**
|
52 | * Get the CodeEditor used by the cell.
|
53 | */
|
54 | get editor(): CodeEditor.IEditor;
|
55 | /**
|
56 | * Get the model used by the cell.
|
57 | */
|
58 | get model(): T;
|
59 | /**
|
60 | * Get the input area for the cell.
|
61 | */
|
62 | get inputArea(): InputArea;
|
63 | /**
|
64 | * The read only state of the cell.
|
65 | */
|
66 | get readOnly(): boolean;
|
67 | set readOnly(value: boolean);
|
68 | /**
|
69 | * Save view editable state to model
|
70 | */
|
71 | saveEditableState(): void;
|
72 | /**
|
73 | * Load view editable state from model.
|
74 | */
|
75 | loadEditableState(): void;
|
76 | /**
|
77 | * A promise that resolves when the widget renders for the first time.
|
78 | */
|
79 | get ready(): Promise<void>;
|
80 | /**
|
81 | * Set the prompt for the widget.
|
82 | */
|
83 | setPrompt(value: string): void;
|
84 | /**
|
85 | * The view state of input being hidden.
|
86 | */
|
87 | get inputHidden(): boolean;
|
88 | set inputHidden(value: boolean);
|
89 | /**
|
90 | * Save view collapse state to model
|
91 | */
|
92 | saveCollapseState(): void;
|
93 | /**
|
94 | * Revert view collapse state from model.
|
95 | */
|
96 | loadCollapseState(): void;
|
97 | /**
|
98 | * Handle the input being hidden.
|
99 | *
|
100 | * #### Notes
|
101 | * This is called by the `inputHidden` setter so that subclasses
|
102 | * can perform actions upon the input being hidden without accessing
|
103 | * private state.
|
104 | */
|
105 | protected handleInputHidden(value: boolean): void;
|
106 | /**
|
107 | * Whether to sync the collapse state to the cell model.
|
108 | */
|
109 | get syncCollapse(): boolean;
|
110 | set syncCollapse(value: boolean);
|
111 | /**
|
112 | * Whether to sync the editable state to the cell model.
|
113 | */
|
114 | get syncEditable(): boolean;
|
115 | set syncEditable(value: boolean);
|
116 | /**
|
117 | * Clone the cell, using the same model.
|
118 | */
|
119 | clone(): Cell<T>;
|
120 | /**
|
121 | * Dispose of the resources held by the widget.
|
122 | */
|
123 | dispose(): void;
|
124 | /**
|
125 | * Handle `after-attach` messages.
|
126 | */
|
127 | protected onAfterAttach(msg: Message): void;
|
128 | /**
|
129 | * Handle `'activate-request'` messages.
|
130 | */
|
131 | protected onActivateRequest(msg: Message): void;
|
132 | /**
|
133 | * Handle `fit-request` messages.
|
134 | */
|
135 | protected onFitRequest(msg: Message): void;
|
136 | /**
|
137 | * Handle `resize` messages.
|
138 | */
|
139 | protected onResize(msg: Widget.ResizeMessage): void;
|
140 | /**
|
141 | * Handle `update-request` messages.
|
142 | */
|
143 | protected onUpdateRequest(msg: Message): void;
|
144 | /**
|
145 | * Handle changes in the metadata.
|
146 | */
|
147 | protected onMetadataChanged(model: IObservableJSON, args: IObservableMap.IChangedArgs<PartialJSONValue | undefined>): void;
|
148 | protected _displayChanged: Signal<this, void>;
|
149 | private _readOnly;
|
150 | private _model;
|
151 | private _inputHidden;
|
152 | private _input;
|
153 | private _inputWrapper;
|
154 | private _inputPlaceholder;
|
155 | private _syncCollapse;
|
156 | private _syncEditable;
|
157 | private _resizeDebouncer;
|
158 | }
|
159 | /**
|
160 | * The namespace for the `Cell` class statics.
|
161 | */
|
162 | export declare namespace Cell {
|
163 | |
164 |
|
165 |
|
166 | interface IOptions<T extends ICellModel> {
|
167 | |
168 |
|
169 |
|
170 | model: T;
|
171 | |
172 |
|
173 |
|
174 | contentFactory?: IContentFactory;
|
175 | |
176 |
|
177 |
|
178 | editorConfig?: Partial<CodeEditor.IConfig>;
|
179 | |
180 |
|
181 |
|
182 | updateEditorOnShow?: boolean;
|
183 | |
184 |
|
185 |
|
186 | maxNumberOutputs?: number;
|
187 | |
188 |
|
189 |
|
190 | placeholder?: boolean;
|
191 | }
|
192 | |
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 | interface IContentFactory extends OutputArea.IContentFactory, InputArea.IContentFactory {
|
202 | |
203 |
|
204 |
|
205 | createCellHeader(): ICellHeader;
|
206 | |
207 |
|
208 |
|
209 | createCellFooter(): ICellFooter;
|
210 | }
|
211 | |
212 |
|
213 |
|
214 |
|
215 |
|
216 | class ContentFactory implements IContentFactory {
|
217 | |
218 |
|
219 |
|
220 | constructor(options?: ContentFactory.IOptions);
|
221 | /**
|
222 | * The readonly editor factory that create code editors
|
223 | */
|
224 | get editorFactory(): CodeEditor.Factory;
|
225 | /**
|
226 | * Create a new cell header for the parent widget.
|
227 | */
|
228 | createCellHeader(): ICellHeader;
|
229 | /**
|
230 | * Create a new cell header for the parent widget.
|
231 | */
|
232 | createCellFooter(): ICellFooter;
|
233 | /**
|
234 | * Create an input prompt.
|
235 | */
|
236 | createInputPrompt(): IInputPrompt;
|
237 | /**
|
238 | * Create the output prompt for the widget.
|
239 | */
|
240 | createOutputPrompt(): IOutputPrompt;
|
241 | /**
|
242 | * Create an stdin widget.
|
243 | */
|
244 | createStdin(options: Stdin.IOptions): IStdin;
|
245 | private _editorFactory;
|
246 | }
|
247 | /**
|
248 | * A namespace for cell content factory.
|
249 | */
|
250 | namespace ContentFactory {
|
251 | |
252 |
|
253 |
|
254 | interface IOptions {
|
255 | |
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 | editorFactory?: CodeEditor.Factory;
|
262 | }
|
263 | }
|
264 | |
265 |
|
266 |
|
267 | const defaultContentFactory: ContentFactory;
|
268 | }
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 | export declare class CodeCell extends Cell<ICodeCellModel> {
|
276 | |
277 |
|
278 |
|
279 | constructor(options: CodeCell.IOptions);
|
280 | /**
|
281 | * Initialize view state from model.
|
282 | *
|
283 | * #### Notes
|
284 | * Should be called after construction. For convenience, returns this, so it
|
285 | * can be chained in the construction, like `new Foo().initializeState();`
|
286 | */
|
287 | initializeState(): this;
|
288 | /**
|
289 | * Get the output area for the cell.
|
290 | */
|
291 | get outputArea(): OutputArea;
|
292 | /**
|
293 | * The view state of output being collapsed.
|
294 | */
|
295 | get outputHidden(): boolean;
|
296 | set outputHidden(value: boolean);
|
297 | /**
|
298 | * Save view collapse state to model
|
299 | */
|
300 | saveCollapseState(): void;
|
301 | /**
|
302 | * Revert view collapse state from model.
|
303 | *
|
304 | * We consider the `collapsed` metadata key as the source of truth for outputs
|
305 | * being hidden.
|
306 | */
|
307 | loadCollapseState(): void;
|
308 | /**
|
309 | * Whether the output is in a scrolled state?
|
310 | */
|
311 | get outputsScrolled(): boolean;
|
312 | set outputsScrolled(value: boolean);
|
313 | /**
|
314 | * Save view collapse state to model
|
315 | */
|
316 | saveScrolledState(): void;
|
317 | /**
|
318 | * Revert view collapse state from model.
|
319 | */
|
320 | loadScrolledState(): void;
|
321 | /**
|
322 | * Whether to sync the scrolled state to the cell model.
|
323 | */
|
324 | get syncScrolled(): boolean;
|
325 | set syncScrolled(value: boolean);
|
326 | /**
|
327 | * Handle the input being hidden.
|
328 | *
|
329 | * #### Notes
|
330 | * This method is called by the case cell implementation and is
|
331 | * subclasses here so the code cell can watch to see when input
|
332 | * is hidden without accessing private state.
|
333 | */
|
334 | protected handleInputHidden(value: boolean): void;
|
335 | /**
|
336 | * Clone the cell, using the same model.
|
337 | */
|
338 | clone(): CodeCell;
|
339 | /**
|
340 | * Clone the OutputArea alone, returning a simplified output area, using the same model.
|
341 | */
|
342 | cloneOutputArea(): OutputArea;
|
343 | /**
|
344 | * Dispose of the resources used by the widget.
|
345 | */
|
346 | dispose(): void;
|
347 | /**
|
348 | * Handle changes in the model.
|
349 | */
|
350 | protected onStateChanged(model: ICellModel, args: IChangedArgs<any>): void;
|
351 | /**
|
352 | * Handle changes in the metadata.
|
353 | */
|
354 | protected onMetadataChanged(model: IObservableJSON, args: IObservableMap.IChangedArgs<JSONValue>): void;
|
355 | /**
|
356 | * Handle changes in the number of outputs in the output area.
|
357 | */
|
358 | private _outputLengthHandler;
|
359 | private _rendermime;
|
360 | private _outputHidden;
|
361 | private _outputsScrolled;
|
362 | private _outputWrapper;
|
363 | private _outputPlaceholder;
|
364 | private _output;
|
365 | private _syncScrolled;
|
366 | private _savingMetadata;
|
367 | }
|
368 | /**
|
369 | * The namespace for the `CodeCell` class statics.
|
370 | */
|
371 | export declare namespace CodeCell {
|
372 | |
373 |
|
374 |
|
375 | interface IOptions extends Cell.IOptions<ICodeCellModel> {
|
376 | |
377 |
|
378 |
|
379 | rendermime: IRenderMimeRegistry;
|
380 | }
|
381 | |
382 |
|
383 |
|
384 | function execute(cell: CodeCell, sessionContext: ISessionContext, metadata?: JSONObject): Promise<KernelMessage.IExecuteReplyMsg | void>;
|
385 | }
|
386 |
|
387 |
|
388 |
|
389 |
|
390 | export declare abstract class AttachmentsCell<T extends IAttachmentsCellModel> extends Cell<T> {
|
391 | |
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 | handleEvent(event: Event): void;
|
402 | |
403 |
|
404 |
|
405 | protected abstract updateCellSourceWithAttachment(attachmentName: string, URI?: string): void;
|
406 | |
407 |
|
408 |
|
409 | protected onAfterAttach(msg: Message): void;
|
410 | |
411 |
|
412 |
|
413 |
|
414 | protected onBeforeDetach(msg: Message): void;
|
415 | private _evtDragOver;
|
416 | |
417 |
|
418 |
|
419 | private _evtPaste;
|
420 | |
421 |
|
422 |
|
423 | private _evtNativeDrop;
|
424 | |
425 |
|
426 |
|
427 | private _evtDrop;
|
428 | |
429 |
|
430 |
|
431 |
|
432 | private _attachFiles;
|
433 | |
434 |
|
435 |
|
436 |
|
437 | private _attachFile;
|
438 | |
439 |
|
440 |
|
441 |
|
442 | private _generateURI;
|
443 | }
|
444 |
|
445 |
|
446 |
|
447 |
|
448 |
|
449 |
|
450 |
|
451 |
|
452 |
|
453 |
|
454 |
|
455 |
|
456 | export declare class MarkdownCell extends AttachmentsCell<IMarkdownCellModel> {
|
457 | |
458 |
|
459 |
|
460 | constructor(options: MarkdownCell.IOptions);
|
461 | /**
|
462 | * A promise that resolves when the widget renders for the first time.
|
463 | */
|
464 | get ready(): Promise<void>;
|
465 | /**
|
466 | * Text that represents the heading if cell is a heading.
|
467 | * Returns empty string if not a heading.
|
468 | */
|
469 | get headingInfo(): {
|
470 | text: string;
|
471 | level: number;
|
472 | };
|
473 | get headingCollapsed(): boolean;
|
474 | set headingCollapsed(value: boolean);
|
475 | get numberChildNodes(): number;
|
476 | set numberChildNodes(value: number);
|
477 | get toggleCollapsedSignal(): Signal<this, boolean>;
|
478 | |
479 |
|
480 |
|
481 | get rendered(): boolean;
|
482 | set rendered(value: boolean);
|
483 | get showEditorForReadOnly(): boolean;
|
484 | set showEditorForReadOnly(value: boolean);
|
485 | dispose(): void;
|
486 | protected maybeCreateCollapseButton(): void;
|
487 | protected maybeCreateOrUpdateExpandButton(): void;
|
488 | |
489 |
|
490 |
|
491 |
|
492 |
|
493 | protected renderCollapseButtons(widget: Widget): void;
|
494 | |
495 |
|
496 |
|
497 | protected renderInput(widget: Widget): void;
|
498 | |
499 |
|
500 |
|
501 | protected showEditor(): void;
|
502 | protected onUpdateRequest(msg: Message): void;
|
503 | |
504 |
|
505 |
|
506 | protected updateCellSourceWithAttachment(attachmentName: string, URI?: string): void;
|
507 | |
508 |
|
509 |
|
510 | private _handleRendered;
|
511 | |
512 |
|
513 |
|
514 | private _updateRenderedInput;
|
515 | |
516 |
|
517 |
|
518 | clone(): MarkdownCell;
|
519 | private _monitor;
|
520 | private _numberChildNodes;
|
521 | private _headingCollapsed;
|
522 | private _toggleCollapsedSignal;
|
523 | private _renderer;
|
524 | private _rendermime;
|
525 | private _rendered;
|
526 | private _prevText;
|
527 | private _ready;
|
528 | private _showEditorForReadOnlyMarkdown;
|
529 | }
|
530 |
|
531 |
|
532 |
|
533 | export declare namespace MarkdownCell {
|
534 | |
535 |
|
536 |
|
537 | interface IOptions extends Cell.IOptions<IMarkdownCellModel> {
|
538 | |
539 |
|
540 |
|
541 | rendermime: IRenderMimeRegistry;
|
542 | |
543 |
|
544 |
|
545 | showEditorForReadOnlyMarkdown?: boolean;
|
546 | }
|
547 | |
548 |
|
549 |
|
550 | const defaultShowEditorForReadOnlyMarkdown = true;
|
551 | }
|
552 |
|
553 |
|
554 |
|
555 |
|
556 |
|
557 |
|
558 | export declare class RawCell extends Cell<IRawCellModel> {
|
559 | |
560 |
|
561 |
|
562 | constructor(options: RawCell.IOptions);
|
563 | /**
|
564 | * Clone the cell, using the same model.
|
565 | */
|
566 | clone(): RawCell;
|
567 | }
|
568 | /**
|
569 | * The namespace for the `RawCell` class statics.
|
570 | */
|
571 | export declare namespace RawCell {
|
572 | |
573 |
|
574 |
|
575 | interface IOptions extends Cell.IOptions<IRawCellModel> {
|
576 | }
|
577 | }
|