UNPKG

24.7 kBTypeScriptView Raw
1import { Cell, CodeCell, ICellModel, MarkdownCell, RawCell } from '@jupyterlab/cells';
2import { IEditorMimeTypeService } from '@jupyterlab/codeeditor';
3import { IChangedArgs } from '@jupyterlab/coreutils';
4import * as nbformat from '@jupyterlab/nbformat';
5import { IObservableList } from '@jupyterlab/observables';
6import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
7import type { IMapChange } from '@jupyter/ydoc';
8import { ITranslator } from '@jupyterlab/translation';
9import { WindowedList } from '@jupyterlab/ui-components';
10import { Message } from '@lumino/messaging';
11import { AttachedProperty } from '@lumino/properties';
12import { ISignal } from '@lumino/signaling';
13import { PanelLayout, Widget } from '@lumino/widgets';
14import { CellList } from './celllist';
15import { INotebookModel } from './model';
16type RenderingLayout = 'default' | 'side-by-side';
17/**
18 * The interactivity modes for the notebook.
19 */
20export type NotebookMode = 'command' | 'edit';
21/**
22 * A widget which renders static non-interactive notebooks.
23 *
24 * #### Notes
25 * The widget model must be set separately and can be changed
26 * at any time. Consumers of the widget must account for a
27 * `null` model, and may want to listen to the `modelChanged`
28 * signal.
29 */
30export declare class StaticNotebook extends WindowedList {
31 /**
32 * Construct a notebook widget.
33 */
34 constructor(options: StaticNotebook.IOptions);
35 get cellCollapsed(): ISignal<this, Cell>;
36 get cellInViewportChanged(): ISignal<this, Cell>;
37 /**
38 * A signal emitted when the model of the notebook changes.
39 */
40 get modelChanged(): ISignal<this, void>;
41 /**
42 * A signal emitted when the model content changes.
43 *
44 * #### Notes
45 * This is a convenience signal that follows the current model.
46 */
47 get modelContentChanged(): ISignal<this, void>;
48 /**
49 * A signal emitted when the rendering layout of the notebook changes.
50 */
51 get renderingLayoutChanged(): ISignal<this, RenderingLayout>;
52 /**
53 * The cell factory used by the widget.
54 */
55 readonly contentFactory: StaticNotebook.IContentFactory;
56 /**
57 * The Rendermime instance used by the widget.
58 */
59 readonly rendermime: IRenderMimeRegistry;
60 /**
61 * Translator to be used by cell renderers
62 */
63 readonly translator: ITranslator;
64 /**
65 * The model for the widget.
66 */
67 get model(): INotebookModel | null;
68 set model(newValue: INotebookModel | null);
69 /**
70 * Get the mimetype for code cells.
71 */
72 get codeMimetype(): string;
73 /**
74 * A read-only sequence of the widgets in the notebook.
75 */
76 get widgets(): ReadonlyArray<Cell>;
77 /**
78 * A configuration object for cell editor settings.
79 */
80 get editorConfig(): StaticNotebook.IEditorConfig;
81 set editorConfig(value: StaticNotebook.IEditorConfig);
82 /**
83 * A configuration object for notebook settings.
84 */
85 get notebookConfig(): StaticNotebook.INotebookConfig;
86 set notebookConfig(value: StaticNotebook.INotebookConfig);
87 get renderingLayout(): RenderingLayout | undefined;
88 set renderingLayout(value: RenderingLayout | undefined);
89 /**
90 * Dispose of the resources held by the widget.
91 */
92 dispose(): void;
93 /**
94 * Move cells preserving widget view state.
95 *
96 * #### Notes
97 * This is required because at the model level a move is a deletion
98 * followed by an insertion. Hence the view state is not preserved.
99 *
100 * @param from The index of the cell to move
101 * @param to The new index of the cell
102 * @param n Number of cells to move
103 */
104 moveCell(from: number, to: number, n?: number): void;
105 /**
106 * Force rendering the cell outputs of a given cell if it is still a placeholder.
107 *
108 * #### Notes
109 * The goal of this method is to allow search on cell outputs (that is based
110 * on DOM tree introspection).
111 *
112 * @param index The cell index
113 */
114 renderCellOutputs(index: number): void;
115 /**
116 * Adds a message to the notebook as a header.
117 */
118 protected addHeader(): void;
119 /**
120 * Removes the header.
121 */
122 protected removeHeader(): void;
123 /**
124 * Handle a new model.
125 *
126 * #### Notes
127 * This method is called after the model change has been handled
128 * internally and before the `modelChanged` signal is emitted.
129 * The default implementation is a no-op.
130 */
131 protected onModelChanged(oldValue: INotebookModel | null, newValue: INotebookModel | null): void;
132 /**
133 * Handle changes to the notebook model content.
134 *
135 * #### Notes
136 * The default implementation emits the `modelContentChanged` signal.
137 */
138 protected onModelContentChanged(model: INotebookModel, args: void): void;
139 /**
140 * Handle changes to the notebook model metadata.
141 *
142 * #### Notes
143 * The default implementation updates the mimetypes of the code cells
144 * when the `language_info` metadata changes.
145 */
146 protected onMetadataChanged(sender: INotebookModel, args: IMapChange): void;
147 /**
148 * Handle a cell being inserted.
149 *
150 * The default implementation is a no-op
151 */
152 protected onCellInserted(index: number, cell: Cell): void;
153 /**
154 * Handle a cell being removed.
155 *
156 * The default implementation is a no-op
157 */
158 protected onCellRemoved(index: number, cell: Cell): void;
159 /**
160 * A message handler invoked on an `'update-request'` message.
161 *
162 * #### Notes
163 * The default implementation of this handler is a no-op.
164 */
165 protected onUpdateRequest(msg: Message): void;
166 /**
167 * Handle a new model on the widget.
168 */
169 private _onModelChanged;
170 /**
171 * Handle a change cells event.
172 */
173 protected _onCellsChanged(sender: CellList, args: IObservableList.IChangedArgs<ICellModel>): void;
174 /**
175 * Create a cell widget and insert into the notebook.
176 */
177 private _insertCell;
178 /**
179 * Create a code cell widget from a code cell model.
180 */
181 private _createCodeCell;
182 /**
183 * Create a markdown cell widget from a markdown cell model.
184 */
185 private _createMarkdownCell;
186 /**
187 * Create a raw cell widget from a raw cell model.
188 */
189 private _createRawCell;
190 /**
191 * Remove a cell widget.
192 */
193 private _removeCell;
194 /**
195 * Update the mimetype of the notebook.
196 */
197 private _updateMimetype;
198 /**
199 * Callback when a cell collapsed status changes.
200 *
201 * @param cell Cell changed
202 * @param collapsed New collapsed status
203 */
204 private _onCellCollapsed;
205 /**
206 * Callback when a cell viewport status changes.
207 *
208 * @param cell Cell changed
209 */
210 private _onCellInViewportChanged;
211 /**
212 * Ensure to load in the DOM a cell requesting an user input
213 *
214 * @param cell Cell requesting an input
215 */
216 private _onInputRequested;
217 private _scheduleCellRenderOnIdle;
218 private _updateDataWindowedListIndex;
219 /**
220 * Update editor settings for notebook cells.
221 */
222 private _updateEditorConfig;
223 private _runOnIdleTime;
224 private _updateForDeferMode;
225 private _renderCSSAndJSOutputs;
226 /**
227 * Apply updated notebook settings.
228 */
229 private _updateNotebookConfig;
230 protected cellsArray: Array<Cell>;
231 private _cellCollapsed;
232 private _cellInViewportChanged;
233 private _editorConfig;
234 private _idleCallBack;
235 private _mimetype;
236 private _mimetypeService;
237 private _modelChanged;
238 private _modelContentChanged;
239 private _notebookConfig;
240 private _notebookModel;
241 private _renderingLayout;
242 private _renderingLayoutChanged;
243}
244/**
245 * The namespace for the `StaticNotebook` class statics.
246 */
247export declare namespace StaticNotebook {
248 /**
249 * An options object for initializing a static notebook.
250 */
251 interface IOptions {
252 /**
253 * The rendermime instance used by the widget.
254 */
255 rendermime: IRenderMimeRegistry;
256 /**
257 * The language preference for the model.
258 */
259 languagePreference?: string;
260 /**
261 * A factory for creating content.
262 */
263 contentFactory: IContentFactory;
264 /**
265 * A configuration object for the cell editor settings.
266 */
267 editorConfig?: IEditorConfig;
268 /**
269 * A configuration object for notebook settings.
270 */
271 notebookConfig?: INotebookConfig;
272 /**
273 * The service used to look up mime types.
274 */
275 mimeTypeService: IEditorMimeTypeService;
276 /**
277 * The application language translator.
278 */
279 translator?: ITranslator;
280 }
281 /**
282 * A factory for creating notebook content.
283 *
284 * #### Notes
285 * This extends the content factory of the cell itself, which extends the content
286 * factory of the output area and input area. The result is that there is a single
287 * factory for creating all child content of a notebook.
288 */
289 interface IContentFactory extends Cell.IContentFactory {
290 /**
291 * Create a new code cell widget.
292 */
293 createCodeCell(options: CodeCell.IOptions): CodeCell;
294 /**
295 * Create a new markdown cell widget.
296 */
297 createMarkdownCell(options: MarkdownCell.IOptions): MarkdownCell;
298 /**
299 * Create a new raw cell widget.
300 */
301 createRawCell(options: RawCell.IOptions): RawCell;
302 }
303 /**
304 * A config object for the cell editors.
305 */
306 interface IEditorConfig {
307 /**
308 * Config options for code cells.
309 */
310 readonly code: Record<string, any>;
311 /**
312 * Config options for markdown cells.
313 */
314 readonly markdown: Record<string, any>;
315 /**
316 * Config options for raw cells.
317 */
318 readonly raw: Record<string, any>;
319 }
320 /**
321 * Default configuration options for cell editors.
322 */
323 const defaultEditorConfig: IEditorConfig;
324 /**
325 * A config object for the notebook widget
326 */
327 interface INotebookConfig {
328 /**
329 * The default type for new notebook cells.
330 */
331 defaultCell: nbformat.CellType;
332 /**
333 * Defines if the document can be undo/redo.
334 */
335 disableDocumentWideUndoRedo: boolean;
336 /**
337 * Defines the maximum number of outputs per cell.
338 */
339 maxNumberOutputs: number;
340 /**
341 * Whether to split stdin line history by kernel session or keep globally accessible.
342 */
343 inputHistoryScope: 'global' | 'session';
344 /**
345 * Number of cells to render in addition to those
346 * visible in the viewport.
347 *
348 * ### Notes
349 * In 'full' windowing mode, this is the number of cells above and below the
350 * viewport.
351 * In 'defer' windowing mode, this is the number of cells to render initially
352 * in addition to the one of the viewport.
353 */
354 overscanCount: number;
355 /**
356 * Should timing be recorded in metadata
357 */
358 recordTiming: boolean;
359 /**
360 * Defines the rendering layout to use.
361 */
362 renderingLayout: RenderingLayout;
363 /**
364 * Enable scrolling past the last cell
365 */
366 scrollPastEnd: boolean;
367 /**
368 * Show hidden cells button if collapsed
369 */
370 showHiddenCellsButton: boolean;
371 /**
372 * Should an editor be shown for read-only markdown
373 */
374 showEditorForReadOnlyMarkdown?: boolean;
375 /**
376 * Override the side-by-side left margin.
377 */
378 sideBySideLeftMarginOverride: string;
379 /**
380 * Override the side-by-side right margin.
381 */
382 sideBySideRightMarginOverride: string;
383 /**
384 * Side-by-side output ratio.
385 */
386 sideBySideOutputRatio: number;
387 /**
388 * Windowing mode
389 *
390 * - 'defer': Wait for idle CPU cycles to attach out of viewport cells
391 * - 'full': Attach to the DOM only cells in viewport
392 * - 'none': Attach all cells to the viewport
393 */
394 windowingMode: 'defer' | 'full' | 'none';
395 }
396 /**
397 * Default configuration options for notebooks.
398 */
399 const defaultNotebookConfig: INotebookConfig;
400 /**
401 * The default implementation of an `IContentFactory`.
402 */
403 class ContentFactory extends Cell.ContentFactory implements IContentFactory {
404 /**
405 * Create a new code cell widget.
406 *
407 * #### Notes
408 * If no cell content factory is passed in with the options, the one on the
409 * notebook content factory is used.
410 */
411 createCodeCell(options: CodeCell.IOptions): CodeCell;
412 /**
413 * Create a new markdown cell widget.
414 *
415 * #### Notes
416 * If no cell content factory is passed in with the options, the one on the
417 * notebook content factory is used.
418 */
419 createMarkdownCell(options: MarkdownCell.IOptions): MarkdownCell;
420 /**
421 * Create a new raw cell widget.
422 *
423 * #### Notes
424 * If no cell content factory is passed in with the options, the one on the
425 * notebook content factory is used.
426 */
427 createRawCell(options: RawCell.IOptions): RawCell;
428 }
429 /**
430 * A namespace for the static notebook content factory.
431 */
432 namespace ContentFactory {
433 /**
434 * Options for the content factory.
435 */
436 interface IOptions extends Cell.ContentFactory.IOptions {
437 }
438 }
439}
440/**
441 * A notebook widget that supports interactivity.
442 */
443export declare class Notebook extends StaticNotebook {
444 /**
445 * Construct a notebook widget.
446 */
447 constructor(options: Notebook.IOptions);
448 /**
449 * List of selected and active cells
450 */
451 get selectedCells(): Cell[];
452 /**
453 * Adds a footer to the notebook.
454 */
455 protected addFooter(): void;
456 /**
457 * Handle a change cells event.
458 */
459 protected _onCellsChanged(sender: CellList, args: IObservableList.IChangedArgs<ICellModel>): void;
460 /**
461 * A signal emitted when the active cell changes.
462 *
463 * #### Notes
464 * This can be due to the active index changing or the
465 * cell at the active index changing.
466 */
467 get activeCellChanged(): ISignal<this, Cell | null>;
468 /**
469 * A signal emitted when the state of the notebook changes.
470 */
471 get stateChanged(): ISignal<this, IChangedArgs<any>>;
472 /**
473 * A signal emitted when the selection state of the notebook changes.
474 */
475 get selectionChanged(): ISignal<this, void>;
476 /**
477 * The interactivity mode of the notebook.
478 */
479 get mode(): NotebookMode;
480 set mode(newValue: NotebookMode);
481 /**
482 * The active cell index of the notebook.
483 *
484 * #### Notes
485 * The index will be clamped to the bounds of the notebook cells.
486 */
487 get activeCellIndex(): number;
488 set activeCellIndex(newValue: number);
489 /**
490 * Get the active cell widget.
491 *
492 * #### Notes
493 * This is a cell or `null` if there is no active cell.
494 */
495 get activeCell(): Cell | null;
496 get lastClipboardInteraction(): 'copy' | 'cut' | 'paste' | null;
497 set lastClipboardInteraction(newValue: 'copy' | 'cut' | 'paste' | null);
498 /**
499 * Dispose of the resources held by the widget.
500 */
501 dispose(): void;
502 /**
503 * Move cells preserving widget view state.
504 *
505 * #### Notes
506 * This is required because at the model level a move is a deletion
507 * followed by an insertion. Hence the view state is not preserved.
508 *
509 * @param from The index of the cell to move
510 * @param to The new index of the cell
511 * @param n Number of cells to move
512 */
513 moveCell(from: number, to: number, n?: number): void;
514 /**
515 * Select a cell widget.
516 *
517 * #### Notes
518 * It is a no-op if the value does not change.
519 * It will emit the `selectionChanged` signal.
520 */
521 select(widget: Cell): void;
522 /**
523 * Deselect a cell widget.
524 *
525 * #### Notes
526 * It is a no-op if the value does not change.
527 * It will emit the `selectionChanged` signal.
528 */
529 deselect(widget: Cell): void;
530 /**
531 * Whether a cell is selected.
532 */
533 isSelected(widget: Cell): boolean;
534 /**
535 * Whether a cell is selected or is the active cell.
536 */
537 isSelectedOrActive(widget: Cell): boolean;
538 /**
539 * Deselect all of the cells.
540 */
541 deselectAll(): void;
542 /**
543 * Move the head of an existing contiguous selection to extend the selection.
544 *
545 * @param index - The new head of the existing selection.
546 *
547 * #### Notes
548 * If there is no existing selection, the active cell is considered an
549 * existing one-cell selection.
550 *
551 * If the new selection is a single cell, that cell becomes the active cell
552 * and all cells are deselected.
553 *
554 * There is no change if there are no cells (i.e., activeCellIndex is -1).
555 */
556 extendContiguousSelectionTo(index: number): void;
557 /**
558 * Get the head and anchor of a contiguous cell selection.
559 *
560 * The head of a contiguous selection is always the active cell.
561 *
562 * If there are no cells selected, `{head: null, anchor: null}` is returned.
563 *
564 * Throws an error if the currently selected cells do not form a contiguous
565 * selection.
566 */
567 getContiguousSelection(): {
568 head: number;
569 anchor: number;
570 } | {
571 head: null;
572 anchor: null;
573 };
574 /**
575 * Scroll so that the given cell is in view. Selects and activates cell.
576 *
577 * @param cell - A cell in the notebook widget.
578 * @param align - Type of alignment.
579 *
580 */
581 scrollToCell(cell: Cell, align?: WindowedList.ScrollToAlign): Promise<void>;
582 private _parseFragment;
583 /**
584 * Set URI fragment identifier.
585 */
586 setFragment(fragment: string): Promise<void>;
587 /**
588 * Handle the DOM events for the widget.
589 *
590 * @param event - The DOM event sent to the widget.
591 *
592 * #### Notes
593 * This method implements the DOM `EventListener` interface and is
594 * called in response to events on the notebook panel's node. It should
595 * not be called directly by user code.
596 */
597 handleEvent(event: Event): void;
598 /**
599 * Handle `after-attach` messages for the widget.
600 */
601 protected onAfterAttach(msg: Message): void;
602 /**
603 * Handle `before-detach` messages for the widget.
604 */
605 protected onBeforeDetach(msg: Message): void;
606 /**
607 * A message handler invoked on an `'after-show'` message.
608 */
609 protected onAfterShow(msg: Message): void;
610 /**
611 * A message handler invoked on a `'resize'` message.
612 */
613 protected onResize(msg: Widget.ResizeMessage): void;
614 /**
615 * A message handler invoked on an `'before-hide'` message.
616 */
617 protected onBeforeHide(msg: Message): void;
618 /**
619 * Handle `'activate-request'` messages.
620 */
621 protected onActivateRequest(msg: Message): void;
622 /**
623 * Handle `update-request` messages sent to the widget.
624 */
625 protected onUpdateRequest(msg: Message): void;
626 /**
627 * Handle a cell being inserted.
628 */
629 protected onCellInserted(index: number, cell: Cell): void;
630 /**
631 * Handle a cell being removed.
632 */
633 protected onCellRemoved(index: number, cell: Cell): void;
634 /**
635 * Handle a new model.
636 */
637 protected onModelChanged(oldValue: INotebookModel, newValue: INotebookModel): void;
638 /**
639 * Handle edge request signals from cells.
640 */
641 private _onEdgeRequest;
642 /**
643 * Ensure that the notebook has proper focus.
644 */
645 private _ensureFocus;
646 /**
647 * Find the cell index containing the target html element.
648 *
649 * #### Notes
650 * Returns -1 if the cell is not found.
651 */
652 private _findCell;
653 /**
654 * Find the target of html mouse event and cell index containing this target.
655 *
656 * #### Notes
657 * Returned index is -1 if the cell is not found.
658 */
659 private _findEventTargetAndCell;
660 /**
661 * Find heading with given ID in any of the cells.
662 */
663 _findHeading(queryId: string): Promise<Private.IScrollTarget | null>;
664 /**
665 * Find cell by its unique ID.
666 */
667 _findCellById(queryId: string): Private.IScrollTarget | null;
668 /**
669 * Handle `contextmenu` event.
670 */
671 private _evtContextMenuCapture;
672 /**
673 * Handle `mousedown` event in the capture phase for the widget.
674 */
675 private _evtMouseDownCapture;
676 /**
677 * Handle `mousedown` events for the widget.
678 */
679 private _evtMouseDown;
680 /**
681 * Handle the `'mouseup'` event on the document.
682 */
683 private _evtDocumentMouseup;
684 /**
685 * Handle the `'mousemove'` event for the widget.
686 */
687 private _evtDocumentMousemove;
688 /**
689 * Handle the `'lm-dragenter'` event for the widget.
690 */
691 private _evtDragEnter;
692 /**
693 * Handle the `'lm-dragleave'` event for the widget.
694 */
695 private _evtDragLeave;
696 /**
697 * Handle the `'lm-dragover'` event for the widget.
698 */
699 private _evtDragOver;
700 /**
701 * Handle the `'lm-drop'` event for the widget.
702 */
703 private _evtDrop;
704 /**
705 * Start a drag event.
706 */
707 private _startDrag;
708 /**
709 * Handle `focus` events for the widget.
710 */
711 private _evtFocusIn;
712 /**
713 * Handle `focusout` events for the notebook.
714 */
715 private _evtFocusOut;
716 /**
717 * Handle `dblclick` events for the widget.
718 */
719 private _evtDblClick;
720 /**
721 * Remove selections from inactive cells to avoid
722 * spurious cursors.
723 */
724 private _trimSelections;
725 private _activeCellIndex;
726 private _activeCell;
727 private _mode;
728 private _drag;
729 private _dragData;
730 private _mouseMode;
731 private _activeCellChanged;
732 private _stateChanged;
733 private _selectionChanged;
734 private _cellLayoutStateCache?;
735 private _checkCacheOnNextResize;
736 private _lastClipboardInteraction;
737 private _updateSelectedCells;
738 private _selectedCells;
739}
740/**
741 * The namespace for the `Notebook` class statics.
742 */
743export declare namespace Notebook {
744 /**
745 * An options object for initializing a notebook widget.
746 */
747 interface IOptions extends StaticNotebook.IOptions {
748 }
749 /**
750 * The content factory for the notebook widget.
751 */
752 interface IContentFactory extends StaticNotebook.IContentFactory {
753 }
754 /**
755 * The default implementation of a notebook content factory..
756 *
757 * #### Notes
758 * Override methods on this class to customize the default notebook factory
759 * methods that create notebook content.
760 */
761 class ContentFactory extends StaticNotebook.ContentFactory {
762 }
763 /**
764 * A namespace for the notebook content factory.
765 */
766 namespace ContentFactory {
767 /**
768 * An options object for initializing a notebook content factory.
769 */
770 interface IOptions extends StaticNotebook.ContentFactory.IOptions {
771 }
772 }
773}
774/**
775 * A namespace for private data.
776 */
777declare namespace Private {
778 /**
779 * An attached property for the selected state of a cell.
780 */
781 const selectedProperty: AttachedProperty<Cell<ICellModel>, boolean>;
782 /**
783 * A custom panel layout for the notebook.
784 */
785 class NotebookPanelLayout extends PanelLayout {
786 /**
787 * A message handler invoked on an `'update-request'` message.
788 *
789 * #### Notes
790 * This is a reimplementation of the base class method,
791 * and is a no-op.
792 */
793 protected onUpdateRequest(msg: Message): void;
794 }
795 /**
796 * Create a cell drag image.
797 */
798 function createDragImage(count: number, promptNumber: string, cellContent: string): HTMLElement;
799 /**
800 * Information about resolved scroll target defined by URL fragment.
801 */
802 interface IScrollTarget {
803 /**
804 * Target cell.
805 */
806 cell: Cell;
807 /**
808 * Element to scroll to within the cell.
809 */
810 element?: HTMLElement;
811 }
812 /**
813 * Parsed fragment identifier data.
814 */
815 interface IFragmentData {
816 /**
817 * The kind of notebook element targetted by the fragment identifier.
818 */
819 kind: 'heading' | 'cell-id';
820 value: string;
821 }
822}
823export {};
824
\No newline at end of file