44 * @license MIT
55 */
66
7- import React , { CSSProperties , useCallback , useContext , useEffect , useRef } from 'react' ;
8- import { Nullable } from 'tsdef' ;
7+ import React , { CSSProperties , useCallback , useContext , useEffect , useRef } from 'react' ;
8+ import { Nullable } from 'tsdef' ;
99
1010import {
1111 addGenericListener ,
@@ -19,8 +19,8 @@ import {
1919 removeLocalMenuHandler ,
2020 saveHandlerData ,
2121} from './globalState' ;
22- import { ContextMenuEvent , DataAttributes , LocalHandlers } from './handlers' ;
23- import { determineMenuPlacement , warn } from './util' ;
22+ import { ContextMenuEvent , DataAttributes , LocalHandlers } from './handlers' ;
23+ import { determineMenuPlacement , warn } from './util' ;
2424
2525const UNINITIALIZED_SENTINEL = { } ;
2626export const useLazyValue = < T > ( factory : ( ) => T ) : T => {
@@ -34,10 +34,12 @@ export const useContextMenuEvent = <DataType = any>(): Nullable<ContextMenuEvent
3434 return useContext ( ContextMenuEventContext ) ;
3535} ;
3636
37- export const useContextMenuTrigger = < RefType extends HTMLElement > (
38- parameters : { menuId ?: string ; data ?: any , ref ?: React . RefObject < RefType > } ,
39- ) : React . RefObject < RefType > => {
40- const { menuId, data} = parameters ;
37+ export const useContextMenuTrigger = < RefType extends HTMLElement > ( parameters : {
38+ menuId ?: string ;
39+ data ?: any ;
40+ ref ?: React . RefObject < RefType > ;
41+ } ) : React . RefObject < RefType > => {
42+ const { menuId, data } = parameters ;
4143
4244 // If user did not provide a ref, we simply generate a new one.
4345 const ref = parameters . ref ? parameters . ref : useRef < RefType > ( null ) ;
@@ -51,7 +53,7 @@ export const useContextMenuTrigger = <RefType extends HTMLElement>(
5153 } , [ data ] ) ;
5254
5355 useEffect ( ( ) => {
54- const { current} = ref ;
56+ const { current } = ref ;
5557 if ( ! current ) return ;
5658
5759 if ( menuId ) current . setAttribute ( DataAttributes . MenuId , menuId ) ;
@@ -80,14 +82,14 @@ export const useMenuToggleMethods = (
8082 lastShowMenuEvent : Nullable < ContextMenuEvent > ,
8183 setShowMenuEvent : ( event : Nullable < ContextMenuEvent > ) => void ,
8284 onShow ?: ( event : ContextMenuEvent ) => void ,
83- onHide ?: ( ) => void ,
85+ onHide ?: ( ) => void
8486) : [ ( event : ContextMenuEvent ) => void , ( ) => void ] => {
8587 const showMenu = useCallback (
8688 ( event : ContextMenuEvent ) => {
8789 setShowMenuEvent ( event ) ;
8890 if ( onShow ) onShow ( event ) ;
8991 } ,
90- [ setShowMenuEvent , onShow ] ,
92+ [ setShowMenuEvent , onShow ]
9193 ) ;
9294 const hideMenu = useCallback ( ( ) => {
9395 if ( lastShowMenuEvent === null ) return ;
@@ -100,11 +102,11 @@ export const useMenuToggleMethods = (
100102export const useMenuPlacementStyle = (
101103 wrapperRef : React . RefObject < HTMLElement > ,
102104 lastShowMenuEvent : Nullable < ContextMenuEvent > ,
103- setMenuPlacementStyle : ( style : Nullable < CSSProperties > ) => void ,
105+ setMenuPlacementStyle : ( style : Nullable < CSSProperties > ) => void
104106) => {
105107 useEffect ( ( ) => {
106108 if ( lastShowMenuEvent ) {
107- const { clientX, clientY} = lastShowMenuEvent ;
109+ const { clientX, clientY } = lastShowMenuEvent ;
108110
109111 let menuWidth = 200 ;
110112 let menuHeight = 200 ;
@@ -131,7 +133,7 @@ export const useInternalHandlers = (
131133 hideOnOutsideClick ?: boolean ,
132134 hideOnEscape ?: boolean ,
133135 hideOnScroll ?: boolean ,
134- hideOnWindowResize ?: boolean ,
136+ hideOnWindowResize ?: boolean
135137) => {
136138 const isVisible = ! ! lastShowMenuEvent ;
137139 const handleClick = useCallback (
@@ -147,15 +149,15 @@ export const useInternalHandlers = (
147149 else hideMenu ( ) ;
148150 }
149151 } ,
150- [ hideMenu , isVisible , wrapperRef . current , hideOnSelfClick , hideOnOutsideClick ] ,
152+ [ hideMenu , isVisible , wrapperRef . current , hideOnSelfClick , hideOnOutsideClick ]
151153 ) ;
152154 const handleKeydown = useCallback (
153155 ( event : KeyboardEvent ) => {
154156 if ( ! isVisible ) return ;
155157 // Hide on escape
156158 if ( event . key === 'Escape' || event . code === 'Escape' ) hideMenu ( ) ;
157159 } ,
158- [ hideMenu , isVisible ] ,
160+ [ hideMenu , isVisible ]
159161 ) ;
160162
161163 useEffect ( ( ) => {
0 commit comments