@@ -3,7 +3,7 @@ const CLASS_CONTEXT_MENU_ACTIVE = 'contextMenuActive';
33interface ContextMenuAction {
44 readonly title : string ;
55 readonly visible : boolean ;
6- readonly onClick : ( ) => void ;
6+ readonly onClick : ( e ?: MouseEvent ) => void ;
77 readonly checked ?: boolean ; // Required in checked context menus
88}
99
@@ -46,15 +46,15 @@ class ContextMenu {
4646 * @param className An optional class name to add to the context menu.
4747 */
4848 public show ( actions : ContextMenuActions , checked : boolean , target : ContextMenuTarget | null , event : MouseEvent , frameElem : HTMLElement , onClose : ( ( ) => void ) | null = null , className : string | null = null ) {
49- let html = '' , handlers : ( ( ) => void ) [ ] = [ ] , handlerId = 0 ;
49+ let html = '' , handlers : ( ( e ?: MouseEvent ) => void ) [ ] = [ ] , handlerId = 0 ;
5050 this . close ( ) ;
5151
5252 for ( let i = 0 ; i < actions . length ; i ++ ) {
5353 let groupHtml = '' ;
5454 for ( let j = 0 ; j < actions [ i ] . length ; j ++ ) {
5555 if ( actions [ i ] [ j ] . visible ) {
5656 groupHtml += '<li class="contextMenuItem" data-index="' + handlerId ++ + '">' + ( checked ? '<span class="contextMenuItemCheck">' + ( actions [ i ] [ j ] . checked ? SVG_ICONS . check : '' ) + '</span>' : '' ) + actions [ i ] [ j ] . title + '</li>' ;
57- handlers . push ( actions [ i ] [ j ] . onClick ) ;
57+ handlers . push ( ( e ?: MouseEvent ) => actions [ i ] [ j ] . onClick ( e ) ) ;
5858 }
5959 }
6060
@@ -92,7 +92,9 @@ class ContextMenu {
9292 // The user clicked on a context menu item => call the corresponding handler
9393 e . stopPropagation ( ) ;
9494 this . close ( ) ;
95- handlers [ parseInt ( ( < HTMLElement > ( < Element > e . target ) . closest ( '.contextMenuItem' ) ! ) . dataset . index ! ) ] ( ) ;
95+ const handlerIndex = parseInt ( ( < HTMLElement > ( < Element > e . target ) . closest ( '.contextMenuItem' ) ! ) . dataset . index ! ) ;
96+ const handler = handlers [ handlerIndex ] ;
97+ handler ?.( e instanceof MouseEvent ? e : undefined ) ;
9698 } ) ;
9799
98100 menu . addEventListener ( 'click' , ( e ) => {
0 commit comments