Skip to content

Commit

Permalink
feat: update comtext menu component
Browse files Browse the repository at this point in the history
  • Loading branch information
liujuping committed Jan 16, 2024
1 parent f9fe38e commit eb93654
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions packages/shell/src/components/context-menu.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import { createContextMenu, parseContextMenuAsReactNode, parseContextMenuProperties } from '@alilc/lowcode-utils';
import { engineConfig } from '@alilc/lowcode-editor-core';
import { IPublicModelPluginContext, IPublicTypeContextMenuAction } from '@alilc/lowcode-types';
import React from 'react';
import React, { useCallback } from 'react';

export function ContextMenu({ children, menus, pluginContext }: {
menus: IPublicTypeContextMenuAction[];
children: React.ReactElement[] | React.ReactElement;
pluginContext: IPublicModelPluginContext;
}): React.ReactElement<any, string | React.JSXElementConstructor<any>> {
if (!engineConfig.get('enableContextMenu')) {
return (
<>{ children }</>
);
}

const handleContextMenu = (event: React.MouseEvent) => {
const handleContextMenu = useCallback((event: React.MouseEvent) => {
event.preventDefault();
event.stopPropagation();

Expand All @@ -32,7 +26,19 @@ export function ContextMenu({ children, menus, pluginContext }: {
}

destroyFn = createContextMenu(children, { event });
};
}, [menus]);

if (!engineConfig.get('enableContextMenu')) {
return (
<>{ children }</>
);
}

if (!menus || !menus.length) {
return (
<>{ children }</>
);
}

// 克隆 children 并添加 onContextMenu 事件处理器
const childrenWithContextMenu = React.Children.map(children, (child) =>
Expand Down

0 comments on commit eb93654

Please sign in to comment.