-
Notifications
You must be signed in to change notification settings - Fork 5k
/
index.tsx
176 lines (155 loc) · 4.37 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';
import { showDialog, Dialog } from '@jupyterlab/apputils';
import { IMainMenu } from '@jupyterlab/mainmenu';
import { ITranslator } from '@jupyterlab/translation';
import { jupyterIcon } from '@jupyter-notebook/ui-components';
import * as React from 'react';
/**
* A list of resources to show in the help menu.
*/
const RESOURCES = [
{
text: 'About Jupyter',
url: 'https://jupyter.org'
},
{
text: 'Markdown Reference',
url: 'https://commonmark.org/help/'
}
];
/**
* The command IDs used by the help plugin.
*/
namespace CommandIDs {
export const open = 'help:open';
export const shortcuts = 'help:shortcuts';
export const about = 'help:about';
}
/**
* The help plugin.
*/
const plugin: JupyterFrontEndPlugin<void> = {
id: '@jupyter-notebook/help-extension:plugin',
autoStart: true,
requires: [ITranslator],
optional: [IMainMenu],
activate: (
app: JupyterFrontEnd,
translator: ITranslator,
menu: IMainMenu | null
): void => {
const { commands } = app;
const trans = translator.load('notebook');
commands.addCommand(CommandIDs.open, {
label: args => args['text'] as string,
execute: args => {
const url = args['url'] as string;
window.open(url);
}
});
commands.addCommand(CommandIDs.shortcuts, {
label: trans.__('Keyboard Shortcuts'),
execute: () => {
const title = (
<span className="jp-AboutNotebook-about-header">
<div className="jp-AboutNotebook-about-header-info">
{trans.__('Keyboard Shortcuts')}
</div>
</span>
);
const body = (
<table className="jp-AboutNotebook-shortcuts">
<thead>
<tr>
<th>{trans.__('Name')}</th>
<th>{trans.__('Shortcut')}</th>
</tr>
</thead>
<tbody>
{commands.keyBindings
.filter(binding => commands.isEnabled(binding.command))
.map((binding, i) => (
<tr key={i}>
<td>{commands.label(binding.command)}</td>
<td>
<pre>{binding.keys.join(', ')}</pre>
</td>
</tr>
))}
</tbody>
</table>
);
return showDialog({
title,
body,
buttons: [
Dialog.createButton({
label: trans.__('Dismiss'),
className:
'jp-AboutNotebook-about-button jp-mod-reject jp-mod-styled'
})
]
});
}
});
commands.addCommand(CommandIDs.about, {
label: trans.__('About %1', app.name),
execute: () => {
const title = (
<>
<span className="jp-AboutNotebook-header">
<jupyterIcon.react width="196px" height="auto" />
</span>
</>
);
const notebookURL = 'https://github.com/jupyter/notebook';
const linkLabel = trans.__('JUPYTER NOTEBOOK ON GITHUB');
const externalLinks = (
<span>
<a
href={notebookURL}
target="_blank"
rel="noopener noreferrer"
className="jp-Button-flat jp-AboutNotebook-about-externalLinks"
>
{linkLabel}
</a>
</span>
);
const version = trans.__('Version: %1', app.version);
const body = (
<>
<span className="jp-AboutNotebook-body">{version}</span>
<div>{externalLinks}</div>
</>
);
const dialog = new Dialog({
title,
body,
buttons: [
Dialog.createButton({
label: trans.__('Dismiss'),
className:
'jp-AboutNotebook-about-button jp-mod-reject jp-mod-styled'
})
]
});
dialog.addClass('jp-AboutNotebook');
void dialog.launch();
}
});
const resourcesGroup = RESOURCES.map(args => ({
args,
command: CommandIDs.open
}));
if (menu) {
menu.helpMenu.addGroup(resourcesGroup, 30);
}
}
};
export default plugin;