forked from alibaba/GGEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
89 lines (82 loc) · 2.53 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
import React from 'react';
import ReactDOM from 'react-dom';
import upperFirst from 'lodash/upperFirst';
import { Divider, Tooltip } from 'antd';
import { EditorCommand } from '@/common/constants/index.js';
import GGEditor, { Flow, Mind, Command, ContextMenu, EditableLabel } from '@/index';
import flowData from '../mock/flow.json';
import mindData from '../mock/mind.json';
import IconFont from './IconFont';
import styles from './index.less';
const FLOW_COMMAND_LIST = [
EditorCommand.Undo,
EditorCommand.Redo,
'|',
EditorCommand.Copy,
EditorCommand.Paste,
EditorCommand.Remove,
'|',
EditorCommand.ZoomIn,
EditorCommand.ZoomOut,
];
const MIND_COMMAND_LIST = [
EditorCommand.Undo,
EditorCommand.Redo,
'|',
EditorCommand.Copy,
EditorCommand.Paste,
EditorCommand.Remove,
'|',
EditorCommand.Topic,
EditorCommand.Subtopic,
'|',
EditorCommand.Fold,
EditorCommand.Unfold,
'|',
EditorCommand.ZoomIn,
EditorCommand.ZoomOut,
];
class Index extends React.Component {
renderContent = (item: G6.Item, position: { x: number; y: number }, hide: () => void) => {
const { x: left, y: top } = position;
return (
<div className={styles.contextMenu} style={{ position: 'absolute', top, left }}>
{[EditorCommand.Undo, EditorCommand.Redo, EditorCommand.PasteHere].map(name => {
return (
<Command key={name} name={name} className={styles.command} disabledClassName={styles.commandDisabled}>
<div onClick={hide}>
<IconFont type={`icon-${name}`} />
<span>{upperFirst(name)}</span>
</div>
</Command>
);
})}
</div>
);
};
render() {
return (
<GGEditor className={styles.editor}>
<div className={styles.editorHd}>
{FLOW_COMMAND_LIST.map(name => {
if (name === '|') {
return <Divider type="vertical" />;
}
return (
<Command key={name} name={name} className={styles.command} disabledClassName={styles.commandDisabled}>
<Tooltip title={upperFirst(name)}>
<IconFont type={`icon-${name}`} />
</Tooltip>
</Command>
);
})}
</div>
<Flow className={styles.editorBd} data={flowData} />
{/* <Mind className={styles.editorBd} data={mindData} /> */}
<EditableLabel />
<ContextMenu renderContent={this.renderContent} />
</GGEditor>
);
}
}
ReactDOM.render(<Index />, document.getElementById('root'));