-
Notifications
You must be signed in to change notification settings - Fork 5.2k
/
Copy pathindex.tsx
236 lines (209 loc) · 6.34 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';
import { showDialog, Dialog, ICommandPalette } 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';
from platform import python_version /* to print Python version it is running on */
/**
* 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';
}
/**
* A plugin to open the about section with resources.
*/
const open: JupyterFrontEndPlugin<void> = {
id: '@jupyter-notebook/help-extension:open',
autoStart: true,
activate: (app: JupyterFrontEnd): void => {
const { commands } = app;
commands.addCommand(CommandIDs.open, {
label: args => args['text'] as string,
execute: args => {
const url = args['url'] as string;
window.open(url);
}
});
}
};
/**
* Plugin to add a command to show an About Jupyter Notebook and Markdown Reference.
*/
const about: JupyterFrontEndPlugin<void> = {
id: '@jupyter-notebook/help-extension:about',
autoStart: true,
requires: [ITranslator],
optional: [IMainMenu, ICommandPalette],
activate: (
app: JupyterFrontEnd,
translator: ITranslator,
menu: IMainMenu | null,
palette: ICommandPalette | null
): void => {
const { commands } = app;
const trans = translator.load('notebook');
const category = trans.__('Help');
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 contributorURL = 'https://github.com/jupyter/notebook/pulse';
const aboutJupyter = trans.__('JUPYTER NOTEBOOK ON GITHUB');
const contributorList = trans.__('CONTRIBUTOR LIST');
const externalLinks = (
<span>
<a
href={notebookURL}
target="_blank"
rel="noopener noreferrer"
className="jp-Button-flat jp-AboutNotebook-about-externalLinks"
>
{aboutJupyter}
</a>
<a
href={contributorURL}
target="_blank"
rel="noopener noreferrer"
className="jp-Button-flat jp-AboutNotebook-about-externalLinks"
>
{contributorList}
</a>
</span>
);
const version = trans.__('Version: %1', app.version);
const py_version = trans.__('Python version: %1', app.python_version());
const copyright = trans.__('© 2021-2023 Jupyter Notebook Contributors');
const body = (
<>
<span className="jp-AboutNotebook-version">{version}</span>
<span className="jp-AboutNotebook-python-version">{py_version}</span>
<div>{externalLinks}</div>
<span className="jp-AboutNotebook-about-copyright">
{copyright}
</span>
</>
);
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();
}
});
if (palette) {
palette.addItem({ command: CommandIDs.about, category });
}
const resourcesGroup = RESOURCES.map(args => ({
args,
command: CommandIDs.open
}));
if (menu) {
menu.helpMenu.addGroup(resourcesGroup, 30);
}
}
};
/**
* A plugin to add a command to display Keyboard Shortcuts.
*/
const shortcuts: JupyterFrontEndPlugin<void> = {
id: '@jupyter-notebook/help-extension:shortcuts',
autoStart: true,
requires: [ITranslator],
optional: [ICommandPalette],
activate: (
app: JupyterFrontEnd,
translator: ITranslator,
palette: ICommandPalette | null
): void => {
const { commands } = app;
const trans = translator.load('notebook');
const category = trans.__('Help');
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'
})
]
});
}
});
if (palette) {
palette.addItem({ command: CommandIDs.shortcuts, category });
}
}
};
const plugins: JupyterFrontEndPlugin<any>[] = [open, shortcuts, about];
export default plugins;