UNPKG

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