UNPKG

2.14 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.innerText = trans.__('Click to add a cell.');
21 }
22 /**
23 * Handle incoming events.
24 */
25 handleEvent(event) {
26 switch (event.type) {
27 case 'click':
28 this.onClick();
29 break;
30 case 'keydown':
31 if (event.key === 'ArrowUp') {
32 this.onArrowUp();
33 break;
34 }
35 }
36 }
37 /**
38 * On single click (mouse event), insert a cell below (at the end of the notebook as default behavior).
39 */
40 onClick() {
41 if (this.notebook.widgets.length > 0) {
42 this.notebook.activeCellIndex = this.notebook.widgets.length - 1;
43 }
44 NotebookActions.insertBelow(this.notebook);
45 }
46 /**
47 * On arrow up key pressed (keydown keyboard event), blur the footer and switch to command mode.
48 */
49 onArrowUp() {
50 this.node.blur();
51 this.notebook.mode = 'command';
52 }
53 /*
54 * Handle `after-detach` messages for the widget.
55 */
56 onAfterAttach(msg) {
57 super.onAfterAttach(msg);
58 this.node.addEventListener('click', this);
59 this.node.addEventListener('keydown', this);
60 }
61 /**
62 * Handle `before-detach` messages for the widget.
63 */
64 onBeforeDetach(msg) {
65 this.node.removeEventListener('click', this);
66 this.node.removeEventListener('keydown', this);
67 super.onBeforeDetach(msg);
68 }
69}
70//# sourceMappingURL=notebookfooter.js.map
\No newline at end of file