forked from KathiraveluLab/DHGWorkflow
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathHeader.jsx
More file actions
87 lines (82 loc) · 3.14 KB
/
Copy pathHeader.jsx
File metadata and controls
87 lines (82 loc) · 3.14 KB
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
/* eslint-disable react/jsx-props-no-spreading */
import React from 'react';
import hotkeys from 'hotkeys-js';
import toolbarList from '../toolbarActions/toolbarList';
import '@szhsin/react-menu/dist/index.css';
import './header.css';
import {
ActionButton, Vsep, Hsep, Space, TextBox, Switcher, DropDown, FileUploader,
} from './HeaderComps';
import 'rc-switch/assets/index.css';
import FullScreenButton from './FullScreenButton';
// import ServerActions from './serverActions/ServerActions';
const setHotKeys = (actions) => {
let keys = '';
const map = {};
actions.forEach((action, i) => {
if (action.hotkey) {
action.hotkey.split(',').forEach((key) => {
[key, key.replace('Ctrl', 'Command')].forEach((k) => {
keys += `${k},`;
map[k] = document.getElementById(`action_${i + 1}`);
});
});
}
});
keys = keys.substring(0, keys.length - 1);
hotkeys(keys, (event, handler) => {
event.preventDefault();
map[handler.shortcut].click();
});
};
const Header = ({ superState, dispatcher }) => {
const actions = toolbarList(superState, dispatcher);
React.useEffect(() => {
setHotKeys(actions, superState, dispatcher);
}, []);
return (
<header className="header">
<div style={{ display: 'flex' }}>
<section className="middle titlebar">
{
superState.curGraphInstance ? `${superState.curGraphInstance.projectName
} - concore Editor` : 'untitled'
}
</section>
<FullScreenButton />
</div>
<section className="toolbar">
{
actions.map(({
text, active, visibility, action, icon, type, hotkey,
}, i) => {
const props = {
text,
active,
visibility,
tabIndex: i + 1,
key: text,
action: (e) => action(superState, dispatcher, e),
Icon: icon,
hotkey,
};
switch (type) {
case 'vsep': return <Vsep key={`${`v${i}`}`} />;
case 'space': return <Space key={`${`s${i}`}`} />;
case 'switch': return <Switcher {...props} />;
case 'menu': return <DropDown {...props} />;
case 'file-upload': return <FileUploader {...props} superState={superState} />;
case 'action': return <ActionButton {...props} />;
// case 'serverActions': return <ServerActions superState={superState} />;
default: return <></>;
}
})
}
</section>
<Hsep />
</header>
);
};
export {
Header, ActionButton, Vsep, Hsep, Space, TextBox,
};