@@ -19,7 +19,7 @@ import './context-menu-actions.scss';
1919export interface IContextMenuActions {
2020 actions : IPublicTypeContextMenuAction [ ] ;
2121
22- adjustMenuLayoutFn : ( actions : IPublicTypeContextMenuItem [ ] ) => IPublicTypeContextMenuItem [ ] ;
22+ // adjustMenuLayoutFn: (actions: IPublicTypeContextMenuItem[]) => IPublicTypeContextMenuItem[];
2323
2424 addMenuAction : IPublicApiMaterial [ 'addContextMenuOption' ] ;
2525
@@ -57,7 +57,11 @@ export class GlobalContextMenuActions {
5757 event . preventDefault ( ) ;
5858
5959 const actions : IPublicTypeContextMenuAction [ ] = [ ] ;
60- let contextMenu : ContextMenuActions = this . contextMenuActionsMap . values ( ) . next ( ) . value ;
60+ let contextMenu : ContextMenuActions | undefined = this . contextMenuActionsMap
61+ . values ( )
62+ . next ( ) . value ;
63+ if ( ! contextMenu ) return ;
64+
6165 this . contextMenuActionsMap . forEach ( ( contextMenu ) => {
6266 actions . push ( ...contextMenu . actions ) ;
6367 } ) ;
@@ -90,12 +94,17 @@ export class GlobalContextMenuActions {
9094 pluginContext,
9195 } ) ;
9296
93- const target = event . target ;
97+ const target = event . target as HTMLElement ;
98+
99+ if ( ! target ) {
100+ console . warn ( 'context menu target is null' ) ;
101+ return ;
102+ }
94103
95- const { top, left } = target ? .getBoundingClientRect ( ) ;
104+ const { top, left } = target . getBoundingClientRect ( ) ;
96105
97106 const menuInstance = Menu . create ( {
98- target : event . target ,
107+ target : target ,
99108 offset : [ event . clientX - left , event . clientY - top ] ,
100109 children : menuNode ,
101110 className : 'engine-context-menu' ,
@@ -177,7 +186,7 @@ export class ContextMenuActions implements IContextMenuActions {
177186 ) as IPublicModelPluginContext ;
178187
179188 const menus : IPublicTypeContextMenuItem [ ] = parseContextMenuProperties ( actions , {
180- nodes : nodes . map ( ( d ) => designer . shellModelFactory . createNode ( d ) ! ) ,
189+ nodes : nodes . map ( ( d ) => designer . shellModelFactory ! . createNode ( d ) ! ) ,
181190 destroy,
182191 event,
183192 pluginContext,
@@ -191,7 +200,7 @@ export class ContextMenuActions implements IContextMenuActions {
191200
192201 const menuNode = parseContextMenuAsReactNode ( layoutMenu , {
193202 destroy,
194- nodes : nodes . map ( ( d ) => designer . shellModelFactory . createNode ( d ) ! ) ,
203+ nodes : nodes . map ( ( d ) => designer . shellModelFactory ! . createNode ( d ) ! ) ,
195204 pluginContext,
196205 } ) ;
197206
@@ -210,10 +219,10 @@ export class ContextMenuActions implements IContextMenuActions {
210219 originalEvent . stopPropagation ( ) ;
211220 originalEvent . preventDefault ( ) ;
212221 // 如果右键的节点不在 当前选中的节点中,选中该节点
213- if ( ! designer . currentSelection . has ( node . id ) ) {
214- designer . currentSelection . select ( node . id ) ;
222+ if ( ! designer . currentSelection ! . has ( node . id ) ) {
223+ designer . currentSelection ! . select ( node . id ) ;
215224 }
216- const nodes = designer . currentSelection . getNodes ( ) ;
225+ const nodes = designer . currentSelection ! . getNodes ( ) ;
217226 this . handleContextMenu ( nodes , originalEvent ) ;
218227 } ,
219228 ) ,
0 commit comments