UNPKG

21.9 kBTypeScriptView Raw
1import { Cell, CodeCell, MarkdownCell, RawCell } from '@jupyterlab/cells';
2import { CodeEditor, IEditorMimeTypeService } from '@jupyterlab/codeeditor';
3import { IChangedArgs } from '@jupyterlab/coreutils';
4import * as nbformat from '@jupyterlab/nbformat';
5import { IObservableMap } from '@jupyterlab/observables';
6import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
7import { ITranslator } from '@jupyterlab/translation';
8import { ReadonlyPartialJSONValue } from '@lumino/coreutils';
9import { Message } from '@lumino/messaging';
10import { ISignal } from '@lumino/signaling';
11import { Widget } from '@lumino/widgets';
12import { INotebookModel } from './model';
13declare type RenderingLayout = 'default' | 'side-by-side';
14/**
15 * The interactivity modes for the notebook.
16 */
17export declare type NotebookMode = 'command' | 'edit';
18/**
19 * A widget which renders static non-interactive notebooks.
20 *
21 * #### Notes
22 * The widget model must be set separately and can be changed
23 * at any time. Consumers of the widget must account for a
24 * `null` model, and may want to listen to the `modelChanged`
25 * signal.
26 */
27export declare class StaticNotebook extends Widget {
28 /**
29 * Construct a notebook widget.
30 */
31 constructor(options: StaticNotebook.IOptions);
32 /**
33 * A signal emitted when the notebook is fully rendered.
34 */
35 get fullyRendered(): ISignal<this, boolean>;
36 /**
37 * A signal emitted when the a placeholder cell is rendered.
38 */
39 get placeholderCellRendered(): ISignal<this, Cell>;
40 /**
41 * A signal emitted when the model of the notebook changes.
42 */
43 get modelChanged(): ISignal<this, void>;
44 /**
45 * A signal emitted when the model content changes.
46 *
47 * #### Notes
48 * This is a convenience signal that follows the current model.
49 */
50 get modelContentChanged(): ISignal<this, void>;
51 /**
52 * A signal emitted when the rendering layout of the notebook changes.
53 */
54 get renderingLayoutChanged(): ISignal<this, RenderingLayout>;
55 /**
56 * The cell factory used by the widget.
57 */
58 readonly contentFactory: StaticNotebook.IContentFactory;
59 /**
60 * The Rendermime instance used by the widget.
61 */
62 readonly rendermime: IRenderMimeRegistry;
63 /**
64 * Translator to be used by cell renderers
65 */
66 readonly translator: ITranslator;
67 /**
68 * The model for the widget.
69 */
70 get model(): INotebookModel | null;
71 set model(newValue: INotebookModel | null);
72 /**
73 * Get the mimetype for code cells.
74 */
75 get codeMimetype(): string;
76 /**
77 * A read-only sequence of the widgets in the notebook.
78 */
79 get widgets(): ReadonlyArray<Cell>;
80 /**
81 * A configuration object for cell editor settings.
82 */
83 get editorConfig(): StaticNotebook.IEditorConfig;
84 set editorConfig(value: StaticNotebook.IEditorConfig);
85 /**
86 * A configuration object for notebook settings.
87 */
88 get notebookConfig(): StaticNotebook.INotebookConfig;
89 set notebookConfig(value: StaticNotebook.INotebookConfig);
90 get renderingLayout(): RenderingLayout | undefined;
91 set renderingLayout(value: RenderingLayout | undefined);
92 /**
93 * Dispose of the resources held by the widget.
94 */
95 dispose(): void;
96 /**
97 * Handle a new model.
98 *
99 * #### Notes
100 * This method is called after the model change has been handled
101 * internally and before the `modelChanged` signal is emitted.
102 * The default implementation is a no-op.
103 */
104 protected onModelChanged(oldValue: INotebookModel | null, newValue: INotebookModel | null): void;
105 /**
106 * Handle changes to the notebook model content.
107 *
108 * #### Notes
109 * The default implementation emits the `modelContentChanged` signal.
110 */
111 protected onModelContentChanged(model: INotebookModel, args: void): void;
112 /**
113 * Handle changes to the notebook model metadata.
114 *
115 * #### Notes
116 * The default implementation updates the mimetypes of the code cells
117 * when the `language_info` metadata changes.
118 */
119 protected onMetadataChanged(sender: IObservableMap<ReadonlyPartialJSONValue | undefined>, args: IObservableMap.IChangedArgs<ReadonlyPartialJSONValue>): void;
120 /**
121 * Handle a cell being inserted.
122 *
123 * The default implementation is a no-op
124 */
125 protected onCellInserted(index: number, cell: Cell): void;
126 /**
127 * Handle a cell being moved.
128 *
129 * The default implementation is a no-op
130 */
131 protected onCellMoved(fromIndex: number, toIndex: number): void;
132 /**
133 * Handle a cell being removed.
134 *
135 * The default implementation is a no-op
136 */
137 protected onCellRemoved(index: number, cell: Cell): void;
138 /**
139 * Handle a new model on the widget.
140 */
141 private _onModelChanged;
142 /**
143 * Handle a change cells event.
144 */
145 private _onCellsChanged;
146 /**
147 * Create a cell widget and insert into the notebook.
148 */
149 private _insertCell;
150 private _scheduleCellRenderOnIdle;
151 private _renderPlaceholderCells;
152 private _renderPlaceholderCell;
153 /**
154 * Create a code cell widget from a code cell model.
155 */
156 private _createCodeCell;
157 /**
158 * Create a markdown cell widget from a markdown cell model.
159 */
160 private _createMarkdownCell;
161 /**
162 * Create a placeholder cell widget from a raw cell model.
163 */
164 private _createPlaceholderCell;
165 /**
166 * Create a raw cell widget from a raw cell model.
167 */
168 private _createRawCell;
169 /**
170 * Move a cell widget.
171 */
172 private _moveCell;
173 /**
174 * Remove a cell widget.
175 */
176 private _removeCell;
177 /**
178 * Update the mimetype of the notebook.
179 */
180 private _updateMimetype;
181 /**
182 * Handle an update to the collaborators.
183 */
184 private _onCollaboratorsChanged;
185 /**
186 * Update editor settings for notebook cells.
187 */
188 private _updateEditorConfig;
189 /**
190 * Apply updated notebook settings.
191 */
192 private _updateNotebookConfig;
193 private _incrementRenderedCount;
194 get remainingCellToRenderCount(): number;
195 private _editorConfig;
196 private _notebookConfig;
197 private _mimetype;
198 private _model;
199 private _mimetypeService;
200 private _modelChanged;
201 private _modelContentChanged;
202 private _fullyRendered;
203 private _placeholderCellRendered;
204 private _observer;
205 private _renderedCellsCount;
206 private _toRenderMap;
207 private _idleCallBack;
208 private _renderingLayout;
209 private _renderingLayoutChanged;
210}
211/**
212 * The namespace for the `StaticNotebook` class statics.
213 */
214export declare namespace StaticNotebook {
215 /**
216 * An options object for initializing a static notebook.
217 */
218 interface IOptions {
219 /**
220 * The rendermime instance used by the widget.
221 */
222 rendermime: IRenderMimeRegistry;
223 /**
224 * The language preference for the model.
225 */
226 languagePreference?: string;
227 /**
228 * A factory for creating content.
229 */
230 contentFactory?: IContentFactory;
231 /**
232 * A configuration object for the cell editor settings.
233 */
234 editorConfig?: IEditorConfig;
235 /**
236 * A configuration object for notebook settings.
237 */
238 notebookConfig?: INotebookConfig;
239 /**
240 * The service used to look up mime types.
241 */
242 mimeTypeService: IEditorMimeTypeService;
243 /**
244 * The application language translator.
245 */
246 translator?: ITranslator;
247 }
248 /**
249 * A factory for creating notebook content.
250 *
251 * #### Notes
252 * This extends the content factory of the cell itself, which extends the content
253 * factory of the output area and input area. The result is that there is a single
254 * factory for creating all child content of a notebook.
255 */
256 interface IContentFactory extends Cell.IContentFactory {
257 /**
258 * Create a new code cell widget.
259 */
260 createCodeCell(options: CodeCell.IOptions, parent: StaticNotebook): CodeCell;
261 /**
262 * Create a new markdown cell widget.
263 */
264 createMarkdownCell(options: MarkdownCell.IOptions, parent: StaticNotebook): MarkdownCell;
265 /**
266 * Create a new raw cell widget.
267 */
268 createRawCell(options: RawCell.IOptions, parent: StaticNotebook): RawCell;
269 }
270 /**
271 * A config object for the cell editors.
272 */
273 interface IEditorConfig {
274 /**
275 * Config options for code cells.
276 */
277 readonly code: Partial<CodeEditor.IConfig>;
278 /**
279 * Config options for markdown cells.
280 */
281 readonly markdown: Partial<CodeEditor.IConfig>;
282 /**
283 * Config options for raw cells.
284 */
285 readonly raw: Partial<CodeEditor.IConfig>;
286 }
287 /**
288 * Default configuration options for cell editors.
289 */
290 const defaultEditorConfig: IEditorConfig;
291 /**
292 * A config object for the notebook widget
293 */
294 interface INotebookConfig {
295 /**
296 * Enable scrolling past the last cell
297 */
298 scrollPastEnd: boolean;
299 /**
300 * The default type for new notebook cells.
301 */
302 defaultCell: nbformat.CellType;
303 /**
304 * Should timing be recorded in metadata
305 */
306 recordTiming: boolean;
307 numberCellsToRenderDirectly: number;
308 remainingTimeBeforeRescheduling: number;
309 /**
310 * Defines if the placeholder cells should be rendered
311 * when the browser is idle.
312 */
313 renderCellOnIdle: boolean;
314 /**
315 * Defines the observed top margin for the
316 * virtual notebook, set a positive number of pixels
317 * to render cells below the visible view.
318 */
319 observedTopMargin: string;
320 /**
321 * Defines the observed bottom margin for the
322 * virtual notebook, set a positive number of pixels
323 * to render cells below the visible view.
324 */
325 observedBottomMargin: string;
326 /**
327 * Defines the maximum number of outputs per cell.
328 */
329 maxNumberOutputs: number;
330 /**
331 * Should an editor be shown for read-only markdown
332 */
333 showEditorForReadOnlyMarkdown?: boolean;
334 /**
335 * Defines if the document can be undo/redo.
336 */
337 disableDocumentWideUndoRedo: boolean;
338 /**
339 * Defines the rendering layout to use.
340 */
341 renderingLayout: RenderingLayout;
342 /**
343 * Override the side-by-side left margin.
344 */
345 sideBySideLeftMarginOverride: string;
346 /**
347 * Override the side-by-side right margin.
348 */
349 sideBySideRightMarginOverride: string;
350 /**
351 * Side-by-side output ratio.
352 */
353 sideBySideOutputRatio: number;
354 }
355 /**
356 * Default configuration options for notebooks.
357 */
358 const defaultNotebookConfig: INotebookConfig;
359 /**
360 * The default implementation of an `IContentFactory`.
361 */
362 class ContentFactory extends Cell.ContentFactory implements IContentFactory {
363 /**
364 * Create a new code cell widget.
365 *
366 * #### Notes
367 * If no cell content factory is passed in with the options, the one on the
368 * notebook content factory is used.
369 */
370 createCodeCell(options: CodeCell.IOptions, parent: StaticNotebook): CodeCell;
371 /**
372 * Create a new markdown cell widget.
373 *
374 * #### Notes
375 * If no cell content factory is passed in with the options, the one on the
376 * notebook content factory is used.
377 */
378 createMarkdownCell(options: MarkdownCell.IOptions, parent: StaticNotebook): MarkdownCell;
379 /**
380 * Create a new raw cell widget.
381 *
382 * #### Notes
383 * If no cell content factory is passed in with the options, the one on the
384 * notebook content factory is used.
385 */
386 createRawCell(options: RawCell.IOptions, parent: StaticNotebook): RawCell;
387 }
388 /**
389 * A namespace for the static notebook content factory.
390 */
391 namespace ContentFactory {
392 /**
393 * Options for the content factory.
394 */
395 interface IOptions extends Cell.ContentFactory.IOptions {
396 }
397 }
398 /**
399 * Default content factory for the static notebook widget.
400 */
401 const defaultContentFactory: IContentFactory;
402}
403/**
404 * A notebook widget that supports interactivity.
405 */
406export declare class Notebook extends StaticNotebook {
407 /**
408 * Construct a notebook widget.
409 */
410 constructor(options: Notebook.IOptions);
411 /**
412 * A signal emitted when the active cell changes.
413 *
414 * #### Notes
415 * This can be due to the active index changing or the
416 * cell at the active index changing.
417 */
418 get activeCellChanged(): ISignal<this, Cell>;
419 /**
420 * A signal emitted when the state of the notebook changes.
421 */
422 get stateChanged(): ISignal<this, IChangedArgs<any>>;
423 /**
424 * A signal emitted when the selection state of the notebook changes.
425 */
426 get selectionChanged(): ISignal<this, void>;
427 /**
428 * The interactivity mode of the notebook.
429 */
430 get mode(): NotebookMode;
431 set mode(newValue: NotebookMode);
432 /**
433 * The active cell index of the notebook.
434 *
435 * #### Notes
436 * The index will be clamped to the bounds of the notebook cells.
437 */
438 get activeCellIndex(): number;
439 set activeCellIndex(newValue: number);
440 /**
441 * Get the active cell widget.
442 *
443 * #### Notes
444 * This is a cell or `null` if there is no active cell.
445 */
446 get activeCell(): Cell | null;
447 get lastClipboardInteraction(): 'copy' | 'cut' | 'paste' | null;
448 set lastClipboardInteraction(newValue: 'copy' | 'cut' | 'paste' | null);
449 /**
450 * Dispose of the resources held by the widget.
451 */
452 dispose(): void;
453 /**
454 * Select a cell widget.
455 *
456 * #### Notes
457 * It is a no-op if the value does not change.
458 * It will emit the `selectionChanged` signal.
459 */
460 select(widget: Cell): void;
461 /**
462 * Deselect a cell widget.
463 *
464 * #### Notes
465 * It is a no-op if the value does not change.
466 * It will emit the `selectionChanged` signal.
467 */
468 deselect(widget: Cell): void;
469 /**
470 * Whether a cell is selected.
471 */
472 isSelected(widget: Cell): boolean;
473 /**
474 * Whether a cell is selected or is the active cell.
475 */
476 isSelectedOrActive(widget: Cell): boolean;
477 /**
478 * Deselect all of the cells.
479 */
480 deselectAll(): void;
481 /**
482 * Move the head of an existing contiguous selection to extend the selection.
483 *
484 * @param index - The new head of the existing selection.
485 *
486 * #### Notes
487 * If there is no existing selection, the active cell is considered an
488 * existing one-cell selection.
489 *
490 * If the new selection is a single cell, that cell becomes the active cell
491 * and all cells are deselected.
492 *
493 * There is no change if there are no cells (i.e., activeCellIndex is -1).
494 */
495 extendContiguousSelectionTo(index: number): void;
496 /**
497 * Get the head and anchor of a contiguous cell selection.
498 *
499 * The head of a contiguous selection is always the active cell.
500 *
501 * If there are no cells selected, `{head: null, anchor: null}` is returned.
502 *
503 * Throws an error if the currently selected cells do not form a contiguous
504 * selection.
505 */
506 getContiguousSelection(): {
507 head: number;
508 anchor: number;
509 } | {
510 head: null;
511 anchor: null;
512 };
513 /**
514 * Scroll so that the given position is centered.
515 *
516 * @param position - The vertical position in the notebook widget.
517 *
518 * @param threshold - An optional threshold for the scroll (0-50, defaults to
519 * 25).
520 *
521 * #### Notes
522 * If the position is within the threshold percentage of the widget height,
523 * measured from the center of the widget, the scroll position will not be
524 * changed. A threshold of 0 means we will always scroll so the position is
525 * centered, and a threshold of 50 means scrolling only happens if position is
526 * outside the current window.
527 */
528 scrollToPosition(position: number, threshold?: number): void;
529 /**
530 * Scroll so that the given cell is in view. Selects and activates cell.
531 *
532 * @param cell - A cell in the notebook widget.
533 *
534 */
535 scrollToCell(cell: Cell): void;
536 /**
537 * Set URI fragment identifier.
538 */
539 setFragment(fragment: string): void;
540 /**
541 * Handle the DOM events for the widget.
542 *
543 * @param event - The DOM event sent to the widget.
544 *
545 * #### Notes
546 * This method implements the DOM `EventListener` interface and is
547 * called in response to events on the notebook panel's node. It should
548 * not be called directly by user code.
549 */
550 handleEvent(event: Event): void;
551 /**
552 * Handle `after-attach` messages for the widget.
553 */
554 protected onAfterAttach(msg: Message): void;
555 /**
556 * Handle `before-detach` messages for the widget.
557 */
558 protected onBeforeDetach(msg: Message): void;
559 /**
560 * A message handler invoked on an `'after-show'` message.
561 */
562 protected onAfterShow(msg: Message): void;
563 /**
564 * A message handler invoked on a `'resize'` message.
565 */
566 protected onResize(msg: Widget.ResizeMessage): void;
567 /**
568 * A message handler invoked on an `'before-hide'` message.
569 */
570 protected onBeforeHide(msg: Message): void;
571 /**
572 * Handle `'activate-request'` messages.
573 */
574 protected onActivateRequest(msg: Message): void;
575 /**
576 * Handle `update-request` messages sent to the widget.
577 */
578 protected onUpdateRequest(msg: Message): void;
579 /**
580 * Handle a cell being inserted.
581 */
582 protected onCellInserted(index: number, cell: Cell): void;
583 /**
584 * Handle a cell being moved.
585 */
586 protected onCellMoved(fromIndex: number, toIndex: number): void;
587 /**
588 * Handle a cell being removed.
589 */
590 protected onCellRemoved(index: number, cell: Cell): void;
591 /**
592 * Handle a new model.
593 */
594 protected onModelChanged(oldValue: INotebookModel, newValue: INotebookModel): void;
595 /**
596 * Handle edge request signals from cells.
597 */
598 private _onEdgeRequest;
599 /**
600 * Ensure that the notebook has proper focus.
601 */
602 private _ensureFocus;
603 /**
604 * Find the cell index containing the target html element.
605 *
606 * #### Notes
607 * Returns -1 if the cell is not found.
608 */
609 private _findCell;
610 /**
611 * Find the target of html mouse event and cell index containing this target.
612 *
613 * #### Notes
614 * Returned index is -1 if the cell is not found.
615 */
616 private _findEventTargetAndCell;
617 /**
618 * Handle `contextmenu` event.
619 */
620 private _evtContextMenuCapture;
621 /**
622 * Handle `mousedown` event in the capture phase for the widget.
623 */
624 private _evtMouseDownCapture;
625 /**
626 * Handle `mousedown` events for the widget.
627 */
628 private _evtMouseDown;
629 /**
630 * Handle the `'mouseup'` event on the document.
631 */
632 private _evtDocumentMouseup;
633 /**
634 * Handle the `'mousemove'` event for the widget.
635 */
636 private _evtDocumentMousemove;
637 /**
638 * Handle the `'lm-dragenter'` event for the widget.
639 */
640 private _evtDragEnter;
641 /**
642 * Handle the `'lm-dragleave'` event for the widget.
643 */
644 private _evtDragLeave;
645 /**
646 * Handle the `'lm-dragover'` event for the widget.
647 */
648 private _evtDragOver;
649 /**
650 * Handle the `'lm-drop'` event for the widget.
651 */
652 private _evtDrop;
653 /**
654 * Start a drag event.
655 */
656 private _startDrag;
657 /**
658 * Handle `focus` events for the widget.
659 */
660 private _evtFocusIn;
661 /**
662 * Handle `focusout` events for the notebook.
663 */
664 private _evtFocusOut;
665 /**
666 * Handle `dblclick` events for the widget.
667 */
668 private _evtDblClick;
669 /**
670 * Remove selections from inactive cells to avoid
671 * spurious cursors.
672 */
673 private _trimSelections;
674 private _activeCellIndex;
675 private _activeCell;
676 private _mode;
677 private _drag;
678 private _fragment;
679 private _dragData;
680 private _mouseMode;
681 private _activeCellChanged;
682 private _stateChanged;
683 private _selectionChanged;
684 private _cellLayoutStateCache?;
685 private _checkCacheOnNextResize;
686 private _lastClipboardInteraction;
687}
688/**
689 * The namespace for the `Notebook` class statics.
690 */
691export declare namespace Notebook {
692 /**
693 * An options object for initializing a notebook widget.
694 */
695 interface IOptions extends StaticNotebook.IOptions {
696 }
697 /**
698 * The content factory for the notebook widget.
699 */
700 interface IContentFactory extends StaticNotebook.IContentFactory {
701 }
702 /**
703 * The default implementation of a notebook content factory..
704 *
705 * #### Notes
706 * Override methods on this class to customize the default notebook factory
707 * methods that create notebook content.
708 */
709 class ContentFactory extends StaticNotebook.ContentFactory {
710 }
711 /**
712 * A namespace for the notebook content factory.
713 */
714 namespace ContentFactory {
715 /**
716 * An options object for initializing a notebook content factory.
717 */
718 interface IOptions extends StaticNotebook.ContentFactory.IOptions {
719 }
720 }
721 const defaultContentFactory: IContentFactory;
722}
723export {};
724
\No newline at end of file