@@ -64,8 +64,9 @@ const Tree = (props: {
6464let destroyFn : Function | undefined ;
6565
6666export function parseContextMenuAsReactNode ( menus : IPublicTypeContextMenuItem [ ] , options : IOptions ) : React . ReactNode [ ] {
67- const { common } = options . pluginContext || { } ;
67+ const { common, commonUI } = options . pluginContext || { } ;
6868 const { intl = ( title : any ) => title } = common ?. utils || { } ;
69+ const { HelpTip } = commonUI || { } ;
6970
7071 const children : React . ReactNode [ ] = [ ] ;
7172 menus . forEach ( ( menu , index ) => {
@@ -79,7 +80,7 @@ export function parseContextMenuAsReactNode(menus: IPublicTypeContextMenuItem[],
7980 children . push ( (
8081 < PopupItem
8182 className = { classNames ( 'engine-context-menu-item' , {
82- disbale : menu . disabled ,
83+ disabled : menu . disabled ,
8384 } ) }
8485 key = { menu . name }
8586 label = { < div className = "engine-context-menu-text" > { intl ( menu . title ) } </ div > }
@@ -93,14 +94,17 @@ export function parseContextMenuAsReactNode(menus: IPublicTypeContextMenuItem[],
9394 children . push ( (
9495 < Item
9596 className = { classNames ( 'engine-context-menu-item' , {
96- disbale : menu . disabled ,
97+ disabled : menu . disabled ,
9798 } ) }
9899 disabled = { menu . disabled }
99- onClick = { menu . action }
100+ onClick = { ( ) => {
101+ menu . action ?.( ) ;
102+ } }
100103 key = { menu . name }
101104 >
102105 < div className = "engine-context-menu-text" >
103- { intl ( menu . title ) }
106+ { menu . title ? intl ( menu . title ) : null }
107+ { menu . help ? < HelpTip size = "xs" help = { menu . help } direction = "right" /> : null }
104108 </ div >
105109 </ Item >
106110 ) ) ;
@@ -135,12 +139,14 @@ export function parseContextMenuProperties(menus: (IPublicTypeContextMenuAction
135139 name,
136140 title,
137141 type = IPublicEnumContextMenuType . MENU_ITEM ,
142+ help,
138143 } = menu ;
139144
140145 const result : IPublicTypeContextMenuItem = {
141146 name,
142147 title,
143148 type,
149+ help,
144150 action : ( ) => {
145151 destroy ?.( ) ;
146152 menu . action ?.( nodes || [ ] , options . event ) ;
@@ -193,26 +199,27 @@ export function createContextMenu(children: React.ReactNode[], {
193199 event : MouseEvent | React . MouseEvent ;
194200 offset ?: [ number , number ] ;
195201} ) {
202+ event . preventDefault ( ) ;
203+ event . stopPropagation ( ) ;
204+
196205 const viewportWidth = window . innerWidth ;
197206 const viewportHeight = window . innerHeight ;
198207 const dividerCount = React . Children . count ( children . filter ( child => React . isValidElement ( child ) && child . type === Divider ) ) ;
199208 const popupItemCount = React . Children . count ( children . filter ( child => React . isValidElement ( child ) && ( child . type === PopupItem || child . type === Item ) ) ) ;
200209 const menuHeight = popupItemCount * parseInt ( getMenuItemHeight ( ) , 10 ) + dividerCount * 8 + 16 ;
201210 const menuWidthLimit = 200 ;
202- const target = event . target ;
203- const { top, left } = ( target as any ) ?. getBoundingClientRect ( ) ;
204- let x = event . clientX - left + offset [ 0 ] ;
205- let y = event . clientY - top + offset [ 1 ] ;
206- if ( x + menuWidthLimit + left > viewportWidth ) {
211+ let x = event . clientX + offset [ 0 ] ;
212+ let y = event . clientY + offset [ 1 ] ;
213+ if ( x + menuWidthLimit > viewportWidth ) {
207214 x = x - menuWidthLimit ;
208215 }
209- if ( y + menuHeight + top > viewportHeight ) {
216+ if ( y + menuHeight > viewportHeight ) {
210217 y = y - menuHeight ;
211218 }
212219
213220 const menuInstance = Menu . create ( {
214- target,
215- offset : [ x , y , 0 , 0 ] ,
221+ target : document . body ,
222+ offset : [ x , y ] ,
216223 children,
217224 className : 'engine-context-menu' ,
218225 } ) ;
0 commit comments