forked from jupyterlab/jupyterlab
/
widget.ts
470 lines (411 loc) · 13.3 KB
/
widget.ts
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import {
Message
} from '@phosphor/messaging';
import {
h, VirtualNode
} from '@phosphor/virtualdom';
import {
VDomModel, VDomWidget
} from '@jupyterlab/apputils';
/**
* The class name added to each page in the About plugin.
*/
const SECTION_CLASS = 'jp-About-section';
/**
* The class name added to center content.
*/
const SECTION_CENTER_CLASS = 'jp-About-sectioncenter';
/**
* The class name added to group elements on the initial page.
*/
const CONTAINER_CLASS = 'jp-About-container';
/**
* The class name added to elements in a row.
*/
const ROW_CLASS = 'jp-About-row';
/**
* The class name added to elements in a column.
*/
const COLUMN_CLASS = 'jp-About-column';
/**
* The class name used specify postion of elements.
*/
const HALF_CLASS = 'jp-About-one-half';
/**
* The class name added to the About plugin description on the intial page.
*/
const DESC_ONE_CLASS = 'jp-About-desc-one';
/**
* The class name added to other plugin descriptions on the intial page.
*/
const DESC_TWO_CLASS = 'jp-About-desc-two';
/**
* The class name added to headers of other plugins on the intial page.
*/
const DESC_TWO_HEADER_CLASS = 'jp-About-desc-two-header';
/**
* The class name added to headers.
*/
const HEADER_CLASS = 'jp-About-header';
/**
* The class name added to plugin pages.
*/
const CONTENT_CLASS = 'jp-About-content';
/**
* The class name added to descriptions on plugin pages.
*/
const CONTENT_DESC_CLASS = 'jp-About-content-desc';
/**
* The class name added to the navigation down button.
*/
const NAV_CLASS = 'jp-About-nav-button';
/**
* The class name added to all images and icons.
*/
const IMAGE_CLASS = 'jp-img';
/**
* The class name added to the JupyterLab logo.
*/
const LOGO_CLASS = 'jp-About-logo';
/**
* The class name added to the main area icon.
*/
const MAIN_AREA_ICON_CLASS = 'jp-About-hero-mainarea';
/**
* The class name added the command palette icon.
*/
const COMMAND_ICON_CLASS = 'jp-About-hero-command';
/**
* The class name added to the filebrowser icon.
*/
const FILEBROWSER_ICON_CLASS = 'jp-About-hero-filebrowser';
/**
* The class name added for the notebook icon.
*/
const NOTEBOOK_ICON_CLASS = 'jp-About-hero-notebook';
/**
* The class name added to the main area image.
*/
const MAIN_AREA_IMAGE_CLASS = 'jp-About-mainarea';
/**
* The class name added to the command palette image.
*/
const COMMAND_IMAGE_CLASS = 'jp-About-command';
/**
* The class name added to the filebrowser image.
*/
const FILEBROWSER_IMAGE_CLASS = 'jp-About-fb';
/**
* The class name added to the notebook image.
*/
const NOTEBOOK_IMAGE_CLASS = 'jp-About-nb';
/**
* Title of About page.
*/
const TITLE = 'Welcome to the JupyterLab alpha preview';
/**
* Text on the first page that gives a high level overview of JupyterLab.
*/
const HEADER_TEXT = [
'Click on the Launcher tab for the initial JupyterLab screen.',
'This demo gives an alpha developer preview of the JupyterLab environment.',
'It is not ready for general usage yet.',
'We are developing JupyterLab at ',
'https://github.com/jupyterlab/jupyterlab',
'. Pull requests and feedback are welcome!',
`Here is a brief description of some of the things you'll find in this demo.`
];
/**
* Contains the plugin names.
*/
const PLUGIN_HEADERS = [
'Main Area',
'Command Palette',
'File Browser',
'Notebook'
];
/**
* Description of the main area and its functionality.
*/
const MAIN_AREA_DESC = [
'Open tabs and drag and drop them to rearrange them.',
`The main area is divided into panels of tabs. Drag a tab around the area
to split the main area in different ways. Drag a tab to the center of a
panel to move a tab without splitting the panel (in this case, the whole
panel will highlight instead of just a portion).`,
`Resize panels by dragging their borders (be aware that panels and sidebars
also have a minimum width). A file that contains changes to be saved has
a circle for a close icon.`
];
/**
* Description of the file browser and its functionality.
*/
const FILE_BROWSER_DESC = [
'Navigate and organize your files.',
`Clicking the "Files" tab, located on the left, will toggle the file browser.
Navigate into directories by double-clicking, and use the breadcrumbs at the
top to navigate out. Create a new file/directory by clicking the plus icon at
the top. Click the middle icon to upload files, and click the last icon to
reload the file listing. Drag and drop files to move them to subdirectories.
Click on a selected file to rename it. Sort the list by clicking on a column
header.
Open a file by double-clicking it or dragging it into the main area.
Opening an image displays the image. Opening a code file opens a code editor.
Opening a notebook opens a very preliminary notebook component.`
];
/**
* Description of the command palette and its functionality.
*/
const COMMAND_PALETTE_DESC = [
'View list of commands and keyboard shortcuts.',
`Clicking the "Commands" tab, located on the left, will toggle the command
palette. Execute a command by clicking, or navigating with your arrow keys
and pressing Enter. Filter commands by typing in the text box at the top of
the palette. The palette is organized into categories, and you can filter on
a single category by clicking on the category header or by typing the header
surrounded by colons in the search input (e.g., :file:).`,
'You can try these things from the command palette:',
'Open a new terminal (requires macOS or Linux)',
'Open an IPython console',
'Open a new file',
'Save a file',
'Open a help panel on the right'
];
/**
* Description of the notebook and its functionality.
*/
const NOTEBOOK_DESC = [
'Dedicate a tab to running a class notebook.',
`Opening a notebook will open a minimally-featured notebook.
Code execution, Markdown rendering, and basic cell toolbar actions are
supported.
Future versions will add more features from the existing Jupyter notebook.`
];
/**
* AboutModel holds data which the AboutWidgetwill render.
*/
export
class AboutModel extends VDomModel {
/**
* Create an about model.
*/
constructor(options: AboutModel.IOptions) {
super();
this.version = options.version;
}
/**
* Title of About page.
*/
readonly title = TITLE;
/**
* The current JupyterLab version.
*/
readonly version: string;
/**
* Text on the first page that gives a high level overview of JupyterLab.
*/
readonly headerText = HEADER_TEXT;
/**
* Contains the plugin names.
*/
readonly pluginHeaders = PLUGIN_HEADERS;
/**
* Description of the main area and its functionality.
*/
readonly mainAreaDesc = MAIN_AREA_DESC;
/**
* Description of the file browser and its functionality.
*/
readonly filebrowserDesc = FILE_BROWSER_DESC;
/**
* Description of the command palette and its functionality.
*/
readonly commandPaletteDesc = COMMAND_PALETTE_DESC;
/**
* Description of the notebook and its functionality.
*/
readonly notebookDesc = NOTEBOOK_DESC;
}
/**
* A namespace for `AboutModel` statics.
*/
export
namespace AboutModel {
/**
* Instantiation options for an about model.
*/
export
interface IOptions {
/**
* The lab application version.
*/
version: string;
}
}
/**
* A virtual-DOM-based widget for the About plugin.
*/
export
class AboutWidget extends VDomWidget<AboutModel> {
/**
* Handle `'activate-request'` messages.
*/
protected onActivateRequest(msg: Message): void {
this.node.tabIndex = -1;
this.node.focus();
}
/**
* Handle `'close-request'` messages.
*/
protected onCloseRequest(msg: Message): void {
super.onCloseRequest(msg);
this.dispose();
}
/**
* Render the about plugin to virtual DOM nodes.
*/
protected render(): VirtualNode {
let title = this.model.title;
let version = `v${this.model.version}`;
let headerText = this.model.headerText;
let pluginHeaders = this.model.pluginHeaders;
let mainAreaDesc = this.model.mainAreaDesc;
let filebrowserDesc = this.model.filebrowserDesc;
let commandPaletteDesc = this.model.commandPaletteDesc;
let notebookDesc = this.model.notebookDesc;
let headerRow = h.div({ className: ROW_CLASS },
h.div({ className: COLUMN_CLASS },
h.span({ className: IMAGE_CLASS + ' ' + LOGO_CLASS }),
h.p({ className: HEADER_CLASS },
title,
h.span(' (', h.code(version), ')')
),
h.div({ className: DESC_ONE_CLASS },
h.p(headerText[0]),
h.p(headerText[1], ' ', h.strong(headerText[2])),
h.p(headerText[3],
h.a({ href: headerText[4], target: '_blank' }, headerText[4]),
headerText[5]
),
h.p(headerText[6])
)
)
);
let mainAreaCommandPaletteRow = h.div({ className: ROW_CLASS },
h.div({ className: HALF_CLASS + ' ' + COLUMN_CLASS },
h.p({ className: DESC_TWO_HEADER_CLASS },
h.a({ href: '#about-main-area' },
h.span({ className: IMAGE_CLASS + ' ' + MAIN_AREA_ICON_CLASS }),
pluginHeaders[0]
)
),
h.p({ className: DESC_TWO_CLASS }, mainAreaDesc[0])
),
h.div({ className: HALF_CLASS + ' ' + COLUMN_CLASS },
h.p({ className: DESC_TWO_HEADER_CLASS },
h.a({ href: '#about-command' },
h.span({ className: IMAGE_CLASS + ' ' + COMMAND_ICON_CLASS }),
pluginHeaders[1]
)
),
h.p({ className: DESC_TWO_CLASS }, commandPaletteDesc[0])
)
);
let filebrowserNotebookRow = h.div({ className: ROW_CLASS },
h.div({ className: HALF_CLASS + ' ' + COLUMN_CLASS },
h.p({ className: DESC_TWO_HEADER_CLASS },
h.a({ href: '#about-filebrowser' },
h.span({ className: IMAGE_CLASS + ' ' + FILEBROWSER_ICON_CLASS }),
pluginHeaders[2]
)
),
h.p({ className: DESC_TWO_CLASS }, filebrowserDesc[0]),
),
h.div({ className: HALF_CLASS + ' ' + COLUMN_CLASS },
h.p({ className: DESC_TWO_HEADER_CLASS },
h.a({ href: '#about-notebook' },
h.span({ className: IMAGE_CLASS + ' ' + NOTEBOOK_ICON_CLASS }),
pluginHeaders[3]
)
),
h.p({ className: DESC_TWO_CLASS }, notebookDesc[0])
)
);
let mainAreaPage = h.div({ className: SECTION_CLASS },
h.a({ id: 'about-main-area' }),
h.div({ className: SECTION_CENTER_CLASS },
h.p({ className: HEADER_CLASS + ' ' + CONTENT_CLASS },
h.span({ className: IMAGE_CLASS + ' ' + MAIN_AREA_ICON_CLASS }),
pluginHeaders[0]
),
h.span({ className: IMAGE_CLASS + ' ' + MAIN_AREA_IMAGE_CLASS }),
h.p({ className: CONTENT_DESC_CLASS }, mainAreaDesc[1]),
h.p({ className: CONTENT_DESC_CLASS }, mainAreaDesc[2]),
h.a({ href: '#about-command' }, h.span({ className: NAV_CLASS }))
)
);
let commandPalettePage = h.div({ className: SECTION_CLASS },
h.a({ id: 'about-command' }),
h.div({ className: SECTION_CENTER_CLASS },
h.p({ className: HEADER_CLASS + ' ' + CONTENT_CLASS },
h.span({ className: IMAGE_CLASS + ' ' + COMMAND_ICON_CLASS }),
pluginHeaders[1]
),
h.span({ className: IMAGE_CLASS + ' ' + COMMAND_IMAGE_CLASS }),
h.p({ className: CONTENT_DESC_CLASS }, commandPaletteDesc[1]),
h.div({ className: CONTENT_DESC_CLASS },
h.p(commandPaletteDesc[2]),
h.ul(
h.li(commandPaletteDesc[3]),
h.li(commandPaletteDesc[4]),
h.li(commandPaletteDesc[5]),
h.li(commandPaletteDesc[6]),
h.li(commandPaletteDesc[7])
)
),
h.a({ href: '#about-filebrowser' }, h.span({ className: NAV_CLASS }))
)
);
let filebrowserPage = h.div({ className: SECTION_CLASS },
h.a({ id: 'about-filebrowser' }),
h.div({ className: SECTION_CENTER_CLASS },
h.p({ className: HEADER_CLASS + ' ' + CONTENT_CLASS },
h.span({ className: IMAGE_CLASS + ' ' + FILEBROWSER_ICON_CLASS }),
pluginHeaders[2]
),
h.span({ className: IMAGE_CLASS + ' ' + FILEBROWSER_IMAGE_CLASS }),
h.p({ className: CONTENT_DESC_CLASS }, filebrowserDesc[1]),
h.a({ href: '#about-notebook' }, h.span({ className: NAV_CLASS }))
)
);
let notebookPage = h.div({ className: SECTION_CLASS },
h.a({ id: 'about-notebook' }),
h.div({ className: SECTION_CENTER_CLASS },
h.p({ className: HEADER_CLASS + ' ' + CONTENT_CLASS },
h.span({ className: IMAGE_CLASS + ' ' + NOTEBOOK_ICON_CLASS }),
pluginHeaders[3]
),
h.span({ className: IMAGE_CLASS + ' ' + NOTEBOOK_IMAGE_CLASS }),
h.p({ className: CONTENT_DESC_CLASS }, notebookDesc[1])
)
);
return h.div({id: 'about' },
h.div({ className: SECTION_CLASS },
h.div({ className: SECTION_CENTER_CLASS },
h.div({ className: CONTAINER_CLASS },
headerRow,
mainAreaCommandPaletteRow,
filebrowserNotebookRow
),
h.a({ href: '#about-main-area' }, h.span({ className: NAV_CLASS }))
)
),
mainAreaPage,
commandPalettePage,
filebrowserPage,
notebookPage
);
}
}