1 | import { Extension } from '@codemirror/state';
|
2 | import { ISessionContext } from '@jupyterlab/apputils';
|
3 | import { IChangedArgs } from '@jupyterlab/coreutils';
|
4 | import { CodeEditor, CodeEditorWrapper } from '@jupyterlab/codeeditor';
|
5 | import { IOutputPrompt, IStdin, OutputArea, Stdin } from '@jupyterlab/outputarea';
|
6 | import { IRenderMime, IRenderMimeRegistry } from '@jupyterlab/rendermime';
|
7 | import { KernelMessage } from '@jupyterlab/services';
|
8 | import { IMapChange } from '@jupyter/ydoc';
|
9 | import { ITranslator } from '@jupyterlab/translation';
|
10 | import { JSONObject } from '@lumino/coreutils';
|
11 | import { Message } from '@lumino/messaging';
|
12 | import { ISignal, Signal } from '@lumino/signaling';
|
13 | import { PanelLayout, Widget } from '@lumino/widgets';
|
14 | import { ICellFooter, ICellHeader } from './headerfooter';
|
15 | import { IInputPrompt, InputArea } from './inputarea';
|
16 | import { CellModel, IAttachmentsCellModel, ICellModel, ICodeCellModel, IMarkdownCellModel, IRawCellModel } from './model';
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | export declare class Cell<T extends ICellModel = ICellModel> extends Widget {
|
24 | |
25 |
|
26 |
|
27 | constructor(options: Cell.IOptions<T>);
|
28 | /**
|
29 | * Initialize view state from model.
|
30 | *
|
31 | * #### Notes
|
32 | * Should be called after construction. For convenience, returns this, so it
|
33 | * can be chained in the construction, like `new Foo().initializeState();`
|
34 | */
|
35 | initializeState(): this;
|
36 | /**
|
37 | * The content factory used by the widget.
|
38 | */
|
39 | readonly contentFactory: Cell.IContentFactory;
|
40 | /**
|
41 | * Signal to indicate that widget has changed visibly (in size, in type, etc)
|
42 | */
|
43 | get displayChanged(): ISignal<this, void>;
|
44 | /**
|
45 | * Whether the cell is in viewport or not.
|
46 | */
|
47 | get inViewport(): boolean;
|
48 | set inViewport(v: boolean);
|
49 | /**
|
50 | * Will emit true just after the node is attached to the DOM
|
51 | * Will emit false just before the node is detached of the DOM
|
52 | */
|
53 | get inViewportChanged(): ISignal<Cell, boolean>;
|
54 | /**
|
55 | * Whether the cell is a placeholder not yet fully rendered or not.
|
56 | */
|
57 | protected get placeholder(): boolean;
|
58 | protected set placeholder(v: boolean);
|
59 | /**
|
60 | * Get the prompt node used by the cell.
|
61 | */
|
62 | get promptNode(): HTMLElement | null;
|
63 | /**
|
64 | * Get the CodeEditorWrapper used by the cell.
|
65 | */
|
66 | get editorWidget(): CodeEditorWrapper | null;
|
67 | /**
|
68 | * Get the CodeEditor used by the cell.
|
69 | */
|
70 | get editor(): CodeEditor.IEditor | null;
|
71 | /**
|
72 | * Editor configuration
|
73 | */
|
74 | get editorConfig(): Record<string, any>;
|
75 | /**
|
76 | * Cell headings
|
77 | */
|
78 | get headings(): Cell.IHeading[];
|
79 | /**
|
80 | * Get the model used by the cell.
|
81 | */
|
82 | get model(): T;
|
83 | /**
|
84 | * Get the input area for the cell.
|
85 | */
|
86 | get inputArea(): InputArea | null;
|
87 | /**
|
88 | * The read only state of the cell.
|
89 | */
|
90 | get readOnly(): boolean;
|
91 | set readOnly(value: boolean);
|
92 | /**
|
93 | * Whether the cell is a placeholder that defer rendering
|
94 | *
|
95 | * #### Notes
|
96 | * You can wait for the promise `Cell.ready` to wait for the
|
97 | * cell to be rendered.
|
98 | */
|
99 | isPlaceholder(): boolean;
|
100 | /**
|
101 | * Save view editable state to model
|
102 | */
|
103 | saveEditableState(): void;
|
104 | /**
|
105 | * Load view editable state from model.
|
106 | */
|
107 | loadEditableState(): void;
|
108 | /**
|
109 | * A promise that resolves when the widget renders for the first time.
|
110 | */
|
111 | get ready(): Promise<void>;
|
112 | /**
|
113 | * Set the prompt for the widget.
|
114 | */
|
115 | setPrompt(value: string): void;
|
116 | /**
|
117 | * The view state of input being hidden.
|
118 | */
|
119 | get inputHidden(): boolean;
|
120 | set inputHidden(value: boolean);
|
121 | /**
|
122 | * Save view collapse state to model
|
123 | */
|
124 | saveCollapseState(): void;
|
125 | /**
|
126 | * Revert view collapse state from model.
|
127 | */
|
128 | loadCollapseState(): void;
|
129 | /**
|
130 | * Handle the input being hidden.
|
131 | *
|
132 | * #### Notes
|
133 | * This is called by the `inputHidden` setter so that subclasses
|
134 | * can perform actions upon the input being hidden without accessing
|
135 | * private state.
|
136 | */
|
137 | protected handleInputHidden(value: boolean): void;
|
138 | /**
|
139 | * Whether to sync the collapse state to the cell model.
|
140 | */
|
141 | get syncCollapse(): boolean;
|
142 | set syncCollapse(value: boolean);
|
143 | /**
|
144 | * Whether to sync the editable state to the cell model.
|
145 | */
|
146 | get syncEditable(): boolean;
|
147 | set syncEditable(value: boolean);
|
148 | /**
|
149 | * Clone the cell, using the same model.
|
150 | */
|
151 | clone(): Cell<T>;
|
152 | /**
|
153 | * Dispose of the resources held by the widget.
|
154 | */
|
155 | dispose(): void;
|
156 | /**
|
157 | * Update the editor configuration with the partial provided dictionary.
|
158 | *
|
159 | * @param v Partial editor configuration
|
160 | */
|
161 | updateEditorConfig(v: Record<string, any>): void;
|
162 | /**
|
163 | * Create children widgets.
|
164 | */
|
165 | protected initializeDOM(): void;
|
166 | /**
|
167 | * Get the editor options at initialization.
|
168 | *
|
169 | * @returns Editor options
|
170 | */
|
171 | protected getEditorOptions(): InputArea.IOptions['editorOptions'];
|
172 | /**
|
173 | * Handle `before-attach` messages.
|
174 | */
|
175 | protected onBeforeAttach(msg: Message): void;
|
176 | /**
|
177 | * Handle `after-attach` messages.
|
178 | */
|
179 | protected onAfterAttach(msg: Message): void;
|
180 | /**
|
181 | * Handle `'activate-request'` messages.
|
182 | */
|
183 | protected onActivateRequest(msg: Message): void;
|
184 | /**
|
185 | * Handle `resize` messages.
|
186 | */
|
187 | protected onResize(msg: Widget.ResizeMessage): void;
|
188 | /**
|
189 | * Handle `update-request` messages.
|
190 | */
|
191 | protected onUpdateRequest(msg: Message): void;
|
192 | protected onContentChanged(): void;
|
193 | /**
|
194 | * Handle changes in the metadata.
|
195 | */
|
196 | protected onMetadataChanged(model: CellModel, args: IMapChange): void;
|
197 | protected prompt: string;
|
198 | protected translator: ITranslator;
|
199 | protected _displayChanged: Signal<this, void>;
|
200 | private _editorConfig;
|
201 | private _input;
|
202 | private _inputHidden;
|
203 | private _inputWrapper;
|
204 | private _inputPlaceholder;
|
205 | private _inViewport;
|
206 | private _inViewportChanged;
|
207 | private _model;
|
208 | private _placeholder;
|
209 | private _readOnly;
|
210 | private _ready;
|
211 | private _resizeDebouncer;
|
212 | private _syncCollapse;
|
213 | private _syncEditable;
|
214 | }
|
215 | /**
|
216 | * The namespace for the `Cell` class statics.
|
217 | */
|
218 | export declare namespace Cell {
|
219 | |
220 |
|
221 |
|
222 | interface IOptions<T extends ICellModel> {
|
223 | |
224 |
|
225 |
|
226 | model: T;
|
227 | |
228 |
|
229 |
|
230 | contentFactory: IContentFactory;
|
231 | |
232 |
|
233 |
|
234 | editorConfig?: Record<string, any>;
|
235 | |
236 |
|
237 |
|
238 | editorExtensions?: Extension[];
|
239 | |
240 |
|
241 |
|
242 | layout?: PanelLayout;
|
243 | |
244 |
|
245 |
|
246 | maxNumberOutputs?: number;
|
247 | |
248 |
|
249 |
|
250 | inputHistoryScope?: 'global' | 'session';
|
251 | |
252 |
|
253 |
|
254 | placeholder?: boolean;
|
255 | |
256 |
|
257 |
|
258 | translator?: ITranslator;
|
259 | }
|
260 | |
261 |
|
262 |
|
263 | interface IHeading {
|
264 | |
265 |
|
266 |
|
267 | text: string;
|
268 | |
269 |
|
270 |
|
271 | level: number;
|
272 | |
273 |
|
274 |
|
275 | outputIndex?: number;
|
276 | |
277 |
|
278 |
|
279 | type: HeadingType;
|
280 | }
|
281 | |
282 |
|
283 |
|
284 | enum HeadingType {
|
285 | |
286 |
|
287 |
|
288 | HTML = 0,
|
289 | |
290 |
|
291 |
|
292 | Markdown = 1
|
293 | }
|
294 | |
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 | interface IContentFactory extends OutputArea.IContentFactory, InputArea.IContentFactory {
|
304 | |
305 |
|
306 |
|
307 | createCellHeader(): ICellHeader;
|
308 | |
309 |
|
310 |
|
311 | createCellFooter(): ICellFooter;
|
312 | }
|
313 | |
314 |
|
315 |
|
316 |
|
317 |
|
318 | class ContentFactory implements IContentFactory {
|
319 | |
320 |
|
321 |
|
322 | constructor(options: ContentFactory.IOptions);
|
323 | /**
|
324 | * The readonly editor factory that create code editors
|
325 | */
|
326 | get editorFactory(): CodeEditor.Factory;
|
327 | /**
|
328 | * Create a new cell header for the parent widget.
|
329 | */
|
330 | createCellHeader(): ICellHeader;
|
331 | /**
|
332 | * Create a new cell footer for the parent widget.
|
333 | */
|
334 | createCellFooter(): ICellFooter;
|
335 | /**
|
336 | * Create an input prompt.
|
337 | */
|
338 | createInputPrompt(): IInputPrompt;
|
339 | /**
|
340 | * Create the output prompt for the widget.
|
341 | */
|
342 | createOutputPrompt(): IOutputPrompt;
|
343 | /**
|
344 | * Create an stdin widget.
|
345 | */
|
346 | createStdin(options: Stdin.IOptions): IStdin;
|
347 | private _editorFactory;
|
348 | }
|
349 | /**
|
350 | * A namespace for cell content factory.
|
351 | */
|
352 | namespace ContentFactory {
|
353 | |
354 |
|
355 |
|
356 | interface IOptions {
|
357 | |
358 |
|
359 |
|
360 | editorFactory: CodeEditor.Factory;
|
361 | }
|
362 | }
|
363 | }
|
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 | export declare class CodeCellLayout extends PanelLayout {
|
373 | |
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 | protected onBeforeAttach(msg: Message): void;
|
384 | |
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 | protected onAfterDetach(msg: Message): void;
|
395 | }
|
396 |
|
397 |
|
398 |
|
399 | export declare class CodeCell extends Cell<ICodeCellModel> {
|
400 | |
401 |
|
402 |
|
403 | constructor(options: CodeCell.IOptions);
|
404 | /**
|
405 | * Maximum number of outputs to display.
|
406 | */
|
407 | protected maxNumberOutputs: number | undefined;
|
408 | /**
|
409 | * Create children widgets.
|
410 | */
|
411 | protected initializeDOM(): void;
|
412 | protected getOutputPlaceholderText(): string | undefined;
|
413 | /**
|
414 | * Initialize view state from model.
|
415 | *
|
416 | * #### Notes
|
417 | * Should be called after construction. For convenience, returns this, so it
|
418 | * can be chained in the construction, like `new Foo().initializeState();`
|
419 | */
|
420 | initializeState(): this;
|
421 | get headings(): Cell.IHeading[];
|
422 | /**
|
423 | * Get the output area for the cell.
|
424 | */
|
425 | get outputArea(): OutputArea;
|
426 | /**
|
427 | * The view state of output being collapsed.
|
428 | */
|
429 | get outputHidden(): boolean;
|
430 | set outputHidden(value: boolean);
|
431 | /**
|
432 | * Save view collapse state to model
|
433 | */
|
434 | saveCollapseState(): void;
|
435 | /**
|
436 | * Revert view collapse state from model.
|
437 | *
|
438 | * We consider the `collapsed` metadata key as the source of truth for outputs
|
439 | * being hidden.
|
440 | */
|
441 | loadCollapseState(): void;
|
442 | /**
|
443 | * Whether the output is in a scrolled state?
|
444 | */
|
445 | get outputsScrolled(): boolean;
|
446 | set outputsScrolled(value: boolean);
|
447 | /**
|
448 | * Save view collapse state to model
|
449 | */
|
450 | saveScrolledState(): void;
|
451 | /**
|
452 | * Revert view collapse state from model.
|
453 | */
|
454 | loadScrolledState(): void;
|
455 | /**
|
456 | * Whether to sync the scrolled state to the cell model.
|
457 | */
|
458 | get syncScrolled(): boolean;
|
459 | set syncScrolled(value: boolean);
|
460 | /**
|
461 | * Handle the input being hidden.
|
462 | *
|
463 | * #### Notes
|
464 | * This method is called by the case cell implementation and is
|
465 | * subclasses here so the code cell can watch to see when input
|
466 | * is hidden without accessing private state.
|
467 | */
|
468 | protected handleInputHidden(value: boolean): void;
|
469 | /**
|
470 | * Clone the cell, using the same model.
|
471 | */
|
472 | clone(): CodeCell;
|
473 | /**
|
474 | * Clone the OutputArea alone, returning a simplified output area, using the same model.
|
475 | */
|
476 | cloneOutputArea(): OutputArea;
|
477 | /**
|
478 | * Dispose of the resources used by the widget.
|
479 | */
|
480 | dispose(): void;
|
481 | /**
|
482 | * Handle changes in the model.
|
483 | */
|
484 | protected onStateChanged(model: ICellModel, args: IChangedArgs<any>): void;
|
485 | /**
|
486 | * Callback on output changes
|
487 | */
|
488 | protected onOutputChanged(): void;
|
489 | /**
|
490 | * Handle changes in the metadata.
|
491 | */
|
492 | protected onMetadataChanged(model: CellModel, args: IMapChange): void;
|
493 | /**
|
494 | * Handle changes in the number of outputs in the output area.
|
495 | */
|
496 | private _outputLengthHandler;
|
497 | private _headingsCache;
|
498 | private _rendermime;
|
499 | private _outputHidden;
|
500 | private _outputsScrolled;
|
501 | private _outputWrapper;
|
502 | private _outputPlaceholder;
|
503 | private _output;
|
504 | private _syncScrolled;
|
505 | }
|
506 | /**
|
507 | * The namespace for the `CodeCell` class statics.
|
508 | */
|
509 | export declare namespace CodeCell {
|
510 | |
511 |
|
512 |
|
513 | interface IOptions extends Cell.IOptions<ICodeCellModel> {
|
514 | |
515 |
|
516 |
|
517 | layout?: CodeCellLayout;
|
518 | |
519 |
|
520 |
|
521 | rendermime: IRenderMimeRegistry;
|
522 | }
|
523 | |
524 |
|
525 |
|
526 | function execute(cell: CodeCell, sessionContext: ISessionContext, metadata?: JSONObject): Promise<KernelMessage.IExecuteReplyMsg | void>;
|
527 | }
|
528 |
|
529 |
|
530 |
|
531 |
|
532 | export declare abstract class AttachmentsCell<T extends IAttachmentsCellModel> extends Cell<T> {
|
533 | |
534 |
|
535 |
|
536 |
|
537 |
|
538 |
|
539 |
|
540 |
|
541 |
|
542 |
|
543 | handleEvent(event: Event): void;
|
544 | |
545 |
|
546 |
|
547 |
|
548 |
|
549 | protected getEditorOptions(): InputArea.IOptions['editorOptions'];
|
550 | |
551 |
|
552 |
|
553 | protected abstract updateCellSourceWithAttachment(attachmentName: string, URI?: string): void;
|
554 | |
555 |
|
556 |
|
557 | protected onAfterAttach(msg: Message): void;
|
558 | |
559 |
|
560 |
|
561 |
|
562 | protected onBeforeDetach(msg: Message): void;
|
563 | private _evtDragOver;
|
564 | |
565 |
|
566 |
|
567 | private _evtPaste;
|
568 | |
569 |
|
570 |
|
571 | private _evtNativeDrop;
|
572 | |
573 |
|
574 |
|
575 | private _evtDrop;
|
576 | |
577 |
|
578 |
|
579 |
|
580 | private _attachFiles;
|
581 | |
582 |
|
583 |
|
584 |
|
585 | private _attachFile;
|
586 | |
587 |
|
588 |
|
589 |
|
590 | private _generateURI;
|
591 | }
|
592 |
|
593 |
|
594 |
|
595 |
|
596 |
|
597 |
|
598 |
|
599 |
|
600 |
|
601 |
|
602 |
|
603 |
|
604 | export declare class MarkdownCell extends AttachmentsCell<IMarkdownCellModel> {
|
605 | |
606 |
|
607 |
|
608 | constructor(options: MarkdownCell.IOptions);
|
609 | /**
|
610 | * Text that represents the highest heading (i.e. lowest level) if cell is a heading.
|
611 | * Returns empty string if not a heading.
|
612 | */
|
613 | get headingInfo(): {
|
614 | text: string;
|
615 | level: number;
|
616 | };
|
617 | get headings(): Cell.IHeading[];
|
618 | |
619 |
|
620 |
|
621 | get headingCollapsed(): boolean;
|
622 | set headingCollapsed(value: boolean);
|
623 | |
624 |
|
625 |
|
626 | get numberChildNodes(): number;
|
627 | set numberChildNodes(value: number);
|
628 | |
629 |
|
630 |
|
631 | get headingCollapsedChanged(): ISignal<MarkdownCell, boolean>;
|
632 | |
633 |
|
634 |
|
635 | get rendered(): boolean;
|
636 | set rendered(value: boolean);
|
637 | |
638 |
|
639 |
|
640 | get renderedChanged(): ISignal<MarkdownCell, boolean>;
|
641 | get showEditorForReadOnly(): boolean;
|
642 | set showEditorForReadOnly(value: boolean);
|
643 | |
644 |
|
645 |
|
646 | get renderer(): IRenderMime.IRenderer;
|
647 | |
648 |
|
649 |
|
650 | dispose(): void;
|
651 | |
652 |
|
653 |
|
654 | protected initializeDOM(): void;
|
655 | protected maybeCreateCollapseButton(): void;
|
656 | |
657 |
|
658 |
|
659 |
|
660 | protected maybeCreateOrUpdateExpandButton(): void;
|
661 | |
662 |
|
663 |
|
664 | protected onContentChanged(): void;
|
665 | |
666 |
|
667 |
|
668 |
|
669 |
|
670 | protected renderCollapseButtons(widget: Widget): void;
|
671 | |
672 |
|
673 |
|
674 | protected renderInput(widget: Widget): void;
|
675 | |
676 |
|
677 |
|
678 | protected showEditor(): void;
|
679 | protected onUpdateRequest(msg: Message): void;
|
680 | |
681 |
|
682 |
|
683 | protected updateCellSourceWithAttachment(attachmentName: string, URI?: string): void;
|
684 | |
685 |
|
686 |
|
687 | private _handleRendered;
|
688 | |
689 |
|
690 |
|
691 | private _updateRenderedInput;
|
692 | |
693 |
|
694 |
|
695 | clone(): MarkdownCell;
|
696 | private _headingsCache;
|
697 | private _headingCollapsed;
|
698 | private _headingCollapsedChanged;
|
699 | private _monitor;
|
700 | private _numberChildNodes;
|
701 | private _prevText;
|
702 | private _renderer;
|
703 | private _rendermime;
|
704 | private _rendered;
|
705 | private _renderedChanged;
|
706 | private _showEditorForReadOnlyMarkdown;
|
707 | }
|
708 |
|
709 |
|
710 |
|
711 | export declare namespace MarkdownCell {
|
712 | |
713 |
|
714 |
|
715 | interface IOptions extends Cell.IOptions<IMarkdownCellModel> {
|
716 | |
717 |
|
718 |
|
719 | rendermime: IRenderMimeRegistry;
|
720 | |
721 |
|
722 |
|
723 | showEditorForReadOnlyMarkdown?: boolean;
|
724 | }
|
725 | |
726 |
|
727 |
|
728 | const defaultShowEditorForReadOnlyMarkdown = true;
|
729 | }
|
730 |
|
731 |
|
732 |
|
733 |
|
734 |
|
735 |
|
736 | export declare class RawCell extends Cell<IRawCellModel> {
|
737 | |
738 |
|
739 |
|
740 | constructor(options: RawCell.IOptions);
|
741 | /**
|
742 | * Clone the cell, using the same model.
|
743 | */
|
744 | clone(): RawCell;
|
745 | }
|
746 | /**
|
747 | * The namespace for the `RawCell` class statics.
|
748 | */
|
749 | export declare namespace RawCell {
|
750 | |
751 |
|
752 |
|
753 | interface IOptions extends Cell.IOptions<IRawCellModel> {
|
754 | }
|
755 | }
|