@@ -10,51 +10,40 @@ import { IFolderTreeController } from 'mo/controller/explorer/folderTree';
10
10
import { useContextView } from 'mo/components/contextView' ;
11
11
import { useContextMenu } from 'mo/components/contextMenu' ;
12
12
import { explorerService } from 'mo/services' ;
13
- import { TreeNodeModel } from 'mo/model' ;
13
+ import { TreeNodeModel , IFolderInputEvent } from 'mo/model' ;
14
14
15
15
const FolderTree : React . FunctionComponent < IFolderTree > = (
16
16
props : IFolderTree & IFolderTreeController
17
17
) => {
18
18
const {
19
19
data = [ ] ,
20
20
contextMenu = [ ] ,
21
+ folderPanelContextMenu = [ ] ,
21
22
onSelectFile,
22
23
onDropTree,
23
24
filterContextMenu,
24
25
onClickContextMenu,
26
+ getInputEvent,
25
27
...restProps
26
28
} = props ;
27
29
const inputRef = useRef < any > ( null ) ;
28
30
29
31
const contextView = useContextView ( ) ;
30
32
31
33
let contextViewMenu ;
32
- const folderContextMenu = [
33
- {
34
- id : 'addFolder' ,
35
- name : 'Add Folder to Workspace' ,
36
- onClick : ( ) => {
37
- explorerService . addRootFolder ?.(
38
- new TreeNodeModel ( {
39
- name : `molecule_temp${ Math . random ( ) } ` ,
40
- fileType : 'rootFolder' ,
41
- } )
42
- ) ;
43
- } ,
44
- } ,
45
- ] ;
46
34
const onClickMenuItem = useCallback (
47
35
( e , item ) => {
36
+ onClickContextMenu ?.( e , item )
48
37
contextViewMenu ?. dispose ( ) ;
49
38
} ,
50
- [ folderContextMenu ]
39
+ [ folderPanelContextMenu ]
51
40
) ;
52
41
const renderContextMenu = ( ) => (
53
- < Menu onClick = { onClickMenuItem } data = { folderContextMenu } />
42
+ < Menu onClick = { onClickMenuItem } data = { folderPanelContextMenu } />
54
43
) ;
55
44
56
45
useEffect ( ( ) => {
57
- if ( folderContextMenu . length > 0 ) {
46
+ if ( folderPanelContextMenu . length > 0 ) {
58
47
contextViewMenu = useContextMenu ( {
59
48
anchor : select ( '.samplefolder' ) ,
60
49
render : renderContextMenu ,
@@ -73,23 +62,23 @@ const FolderTree: React.FunctionComponent<IFolderTree> = (
73
62
} ) ;
74
63
} ;
75
64
76
- const setInputVal = ( val ) => {
65
+ const setInputValue = ( val ) => {
77
66
setTimeout ( ( ) => {
78
67
if ( inputRef . current ) {
79
68
inputRef . current . value = val ;
80
69
}
81
70
} ) ;
82
71
} ;
83
72
84
- const inputEvents = {
73
+ const inputEvents : IFolderInputEvent = {
85
74
onFocus,
86
- setValue : ( val ) => setInputVal ( val ) ,
75
+ setValue : ( val ) => setInputValue ( val ) ,
87
76
} ;
88
77
89
78
const handleRightClick = ( { event, node } ) => {
90
79
const menuItems = filterContextMenu ?.( contextMenu , node . data ) ;
91
80
const handleOnMenuClick = ( e : React . MouseEvent , item ) => {
92
- onClickContextMenu ?.( e , item , node . data , inputEvents ) ;
81
+ onClickContextMenu ?.( e , item , node . data , getInputEvent ?. ( inputEvents ) ) ;
93
82
contextView . hide ( ) ;
94
83
} ;
95
84
contextView ?. show ( getEventPosition ( event ) , ( ) => (
@@ -141,8 +130,8 @@ const FolderTree: React.FunctionComponent<IFolderTree> = (
141
130
onBlur = { handleInputBlur }
142
131
/>
143
132
) : (
144
- name
145
- ) ;
133
+ name
134
+ ) ;
146
135
} ;
147
136
148
137
const renderByData = (
0 commit comments