-
-
Notifications
You must be signed in to change notification settings - Fork 135
/
Copy pathindex.ts
157 lines (138 loc) · 3.55 KB
/
index.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
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import { CommandRegistry } from '@lumino/commands';
import { Menu, MenuBar, PanelLayout, Widget } from '@lumino/widgets';
import '../style/index.css';
/**
* Wrapper widget containing the example application.
*/
class Application extends Widget {
constructor() {
super({ tag: 'main' });
}
}
/**
* Skip link to jump to the main content.
*/
class SkipLink extends Widget {
/**
* Create a HTMLElement that statically links to "#content".
*/
static createNode(): HTMLElement {
const node = document.createElement('a');
node.setAttribute('href', '#content');
node.innerHTML = 'Skip to the main content';
node.classList.add('lm-example-skip-link');
return node;
}
constructor() {
super({ node: SkipLink.createNode() });
}
}
/**
* A Widget containing some content to provide context example.
*/
class Article extends Widget {
/**
* Create the content structure.
*/
static createNode(): HTMLElement {
const node = document.createElement('div');
node.setAttribute('id', 'content');
node.setAttribute('tabindex', '-1');
const h1 = document.createElement('h1');
h1.innerHTML = 'MenuBar Example';
node.appendChild(h1);
const button = document.createElement('button');
button.innerHTML = 'A button you can tab to out of the menubar';
node.appendChild(button);
return node;
}
constructor() {
super({ node: Article.createNode() });
}
}
/**
* Helper Function to add menu items.
*/
function addMenuItem(
commands: CommandRegistry,
menu: Menu,
command: string,
label: string,
log: string
): void {
commands.addCommand(command, {
label: label,
execute: () => {
console.log(log);
}
});
menu.addItem({
type: 'command',
command: command
});
}
/**
* Create the MenuBar example application.
*/
function main(): void {
const app = new Application();
const appLayout = new PanelLayout();
app.layout = appLayout;
const skipLink = new SkipLink();
const menubar = new MenuBar();
const commands = new CommandRegistry();
const fileMenu = new Menu({ commands: commands });
fileMenu.title.label = 'File';
addMenuItem(commands, fileMenu, 'new', 'New', 'File > New');
addMenuItem(commands, fileMenu, 'open', 'Open', 'File > Open');
addMenuItem(commands, fileMenu, 'save', 'Save', 'File > Save');
const recentMenu = new Menu({ commands: commands });
recentMenu.title.label = 'Open Recent';
addMenuItem(
commands,
recentMenu,
'file1',
'File1.txt',
'File > Open Recent > File1.txt'
);
addMenuItem(
commands,
recentMenu,
'file2',
'File2.md',
'File > Open Recent > File2.md'
);
addMenuItem(
commands,
recentMenu,
'file3',
'File3.xml',
'File > Open Recent > File3.xml'
);
addMenuItem(
commands,
recentMenu,
'file4',
'File4.txt',
'File > Open Recent > File4.txt'
);
fileMenu.addItem({
type: 'submenu',
submenu: recentMenu
});
menubar.addMenu(fileMenu);
const editMenu = new Menu({ commands: commands });
editMenu.title.label = 'Edit';
addMenuItem(commands, editMenu, 'cut', 'Cut', 'Edit > Cut');
addMenuItem(commands, editMenu, 'copy', 'Copy', 'Edit > Copy');
addMenuItem(commands, editMenu, 'paste', 'Paste', 'Edit > Paste');
menubar.addMenu(editMenu);
const article = new Article();
appLayout.addWidget(skipLink);
appLayout.addWidget(menubar);
appLayout.addWidget(article);
Widget.attach(app, document.body);
}
window.onload = main;