@@ -37,12 +37,18 @@ export const SortableItem = forwardRef<HTMLDivElement, SortableItemProps>((props
37
37
} = props
38
38
39
39
const isControlAction = [ 'newPage' , 'newFolder' , 'newSeparator' ] . includes ( item . type )
40
-
41
40
const active =
42
41
! isDragging && ! isControlAction && ! isGhost && [ route , `${ route } /` ] . includes ( item . route + '/' )
43
42
// const isLink = 'withIndexPage' in item && item.withIndexPage
44
43
45
44
const isShowMenu = showMenuId === item . id
45
+ const isSeparator = item . type === 'separator'
46
+
47
+ const actionMap : Record < string , ActionType > = {
48
+ newPage : 'page' ,
49
+ newFolder : 'folder' ,
50
+ newSeparator : 'separator' ,
51
+ }
46
52
47
53
useEffect ( ( ) => {
48
54
if ( isGhost ) return
@@ -67,7 +73,14 @@ export const SortableItem = forwardRef<HTMLDivElement, SortableItemProps>((props
67
73
setShowMenuId ( null )
68
74
}
69
75
70
- const isSeparator = item . type === 'separator'
76
+ const onDelete = ( ) => {
77
+ console . log ( 'delete' )
78
+ }
79
+
80
+ const onEdit = ( ) => {
81
+ onCloseMenu ( )
82
+ setIsEdit ( ! isEdit )
83
+ }
71
84
72
85
const wrapperStyle : CSSProperties = {
73
86
listStyle : 'none' ,
@@ -80,12 +93,6 @@ export const SortableItem = forwardRef<HTMLDivElement, SortableItemProps>((props
80
93
Object . assign ( wrapperStyle , style )
81
94
}
82
95
83
- const addActionMap : Record < string , ActionType > = {
84
- newPage : 'page' ,
85
- newFolder : 'folder' ,
86
- newSeparator : 'separator' ,
87
- }
88
-
89
96
const { ref : menuRef } = useOutsideClick < HTMLDivElement > ( onCloseMenu )
90
97
91
98
return (
@@ -97,7 +104,13 @@ export const SortableItem = forwardRef<HTMLDivElement, SortableItemProps>((props
97
104
onContextMenu = { onOpenMenu }
98
105
>
99
106
{ createPortal (
100
- < ControlMenu ref = { menuRef } isOpen = { showMenuId === item . id } position = { mousePosition } /> ,
107
+ < ControlMenu
108
+ ref = { menuRef }
109
+ isOpen = { showMenuId === item . id }
110
+ position = { mousePosition }
111
+ onEdit = { onEdit }
112
+ onDelete = { onDelete }
113
+ /> ,
101
114
document . getElementById ( 'menu-root' ) ! ,
102
115
) }
103
116
< div
@@ -107,7 +120,8 @@ export const SortableItem = forwardRef<HTMLDivElement, SortableItemProps>((props
107
120
'nx-flex nx-w-full nx-items-center nx-justify-between nx-gap-2 nx-text-left' ,
108
121
isSeparator && 'nx-cursor-default' ,
109
122
isSeparator ? classes . separator : classes . link ,
110
- active ? classes . active : classes . inactive ,
123
+ ! isControlAction && active && classes . active ,
124
+ ! isControlAction && ! active && classes . inactive ,
111
125
! isControlAction && ! isDragging && ! active && classes . inactiveBgColor ,
112
126
isGhost && classes . ghost ,
113
127
clone && classes . clone ,
@@ -130,8 +144,8 @@ export const SortableItem = forwardRef<HTMLDivElement, SortableItemProps>((props
130
144
router . push ( item . route , item . route , { shallow : true } )
131
145
} }
132
146
>
133
- { isControlAction ? (
134
- < ControlInput type = { addActionMap [ item . type ] } />
147
+ { isControlAction || isEdit ? (
148
+ < ControlInput type = { actionMap [ item . type ] } />
135
149
) : (
136
150
< >
137
151
< div className = { cn ( 'nx-w-full nx-px-2 nx-py-1.5 [word-break:keep-all]' ) } >
0 commit comments