UNPKG

2.34 kBJavaScriptView Raw
1/*
2 * Copyright (c) Jupyter Development Team.
3 * Distributed under the terms of the Modified BSD License.
4 */
5import { Widget } from '@lumino/widgets';
6import { NotebookActions } from './actions';
7const NOTEBOOK_FOOTER_CLASS = 'jp-Notebook-footer';
8/**
9 * A footer widget added after the last cell of the notebook.
10 */
11export class NotebookFooter extends Widget {
12 /**
13 * Construct a footer widget.
14 */
15 constructor(notebook) {
16 super({ node: document.createElement('button') });
17 this.notebook = notebook;
18 const trans = notebook.translator.load('jupyterlab');
19 this.addClass(NOTEBOOK_FOOTER_CLASS);
20 this.node.setAttribute('tabindex', '-1');
21 this.node.innerText = trans.__('Click to add a cell.');
22 }
23 /**
24 * Handle incoming events.
25 */
26 handleEvent(event) {
27 switch (event.type) {
28 case 'click':
29 this.onClick();
30 break;
31 case 'keydown':
32 if (event.key === 'ArrowUp') {
33 this.onArrowUp();
34 break;
35 }
36 }
37 }
38 /**
39 * On single click (mouse event), insert a cell below (at the end of the notebook as default behavior).
40 */
41 onClick() {
42 if (this.notebook.widgets.length > 0) {
43 this.notebook.activeCellIndex = this.notebook.widgets.length - 1;
44 }
45 NotebookActions.insertBelow(this.notebook);
46 // Focus on the created cell.
47 void NotebookActions.focusActiveCell(this.notebook);
48 }
49 /**
50 * On arrow up key pressed (keydown keyboard event).
51 * @deprecated To be removed in v5, this is a no-op
52 */
53 onArrowUp() {
54 // The specific behavior has been removed in https://github.com/jupyterlab/jupyterlab/pull/14796
55 }
56 /*
57 * Handle `after-detach` messages for the widget.
58 */
59 onAfterAttach(msg) {
60 super.onAfterAttach(msg);
61 this.node.addEventListener('click', this);
62 this.node.addEventListener('keydown', this);
63 }
64 /**
65 * Handle `before-detach` messages for the widget.
66 */
67 onBeforeDetach(msg) {
68 this.node.removeEventListener('click', this);
69 this.node.removeEventListener('keydown', this);
70 super.onBeforeDetach(msg);
71 }
72}
73//# sourceMappingURL=notebookfooter.js.map
\No newline at end of file