forked from jupyter/notebook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
163 lines (143 loc) · 4.22 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
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import {
JupyterFrontEnd,
JupyterFrontEndPlugin,
} from '@jupyterlab/application';
import { 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';
/**
* 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/',
},
{
text: 'Documentation',
url: 'https://jupyter-notebook.readthedocs.io/en/stable/',
},
];
/**
* The command IDs used by the help plugin.
*/
namespace CommandIDs {
export const open = 'help:open';
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 copyright = trans.__('© 2021-2023 Jupyter Notebook Contributors');
const body = (
<>
<span className="jp-AboutNotebook-version">{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);
}
},
};
const plugins: JupyterFrontEndPlugin<any>[] = [open, about];
export default plugins;