mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-11 18:42:56 +00:00
feat: update comtext menu component
This commit is contained in:
parent
7f2b2870aa
commit
4dd6f7a352
@ -1,20 +1,14 @@
|
|||||||
import { createContextMenu, parseContextMenuAsReactNode, parseContextMenuProperties } from '@alilc/lowcode-utils';
|
import { createContextMenu, parseContextMenuAsReactNode, parseContextMenuProperties } from '@alilc/lowcode-utils';
|
||||||
import { engineConfig } from '@alilc/lowcode-editor-core';
|
import { engineConfig } from '@alilc/lowcode-editor-core';
|
||||||
import { IPublicModelPluginContext, IPublicTypeContextMenuAction } from '@alilc/lowcode-types';
|
import { IPublicModelPluginContext, IPublicTypeContextMenuAction } from '@alilc/lowcode-types';
|
||||||
import React from 'react';
|
import React, { useCallback } from 'react';
|
||||||
|
|
||||||
export function ContextMenu({ children, menus, pluginContext }: {
|
export function ContextMenu({ children, menus, pluginContext }: {
|
||||||
menus: IPublicTypeContextMenuAction[];
|
menus: IPublicTypeContextMenuAction[];
|
||||||
children: React.ReactElement[] | React.ReactElement;
|
children: React.ReactElement[] | React.ReactElement;
|
||||||
pluginContext: IPublicModelPluginContext;
|
pluginContext: IPublicModelPluginContext;
|
||||||
}): React.ReactElement<any, string | React.JSXElementConstructor<any>> {
|
}): React.ReactElement<any, string | React.JSXElementConstructor<any>> {
|
||||||
if (!engineConfig.get('enableContextMenu')) {
|
const handleContextMenu = useCallback((event: React.MouseEvent) => {
|
||||||
return (
|
|
||||||
<>{ children }</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleContextMenu = (event: React.MouseEvent) => {
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
@ -32,7 +26,19 @@ export function ContextMenu({ children, menus, pluginContext }: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
destroyFn = createContextMenu(children, { event });
|
destroyFn = createContextMenu(children, { event });
|
||||||
};
|
}, [menus]);
|
||||||
|
|
||||||
|
if (!engineConfig.get('enableContextMenu')) {
|
||||||
|
return (
|
||||||
|
<>{ children }</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!menus || !menus.length) {
|
||||||
|
return (
|
||||||
|
<>{ children }</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// 克隆 children 并添加 onContextMenu 事件处理器
|
// 克隆 children 并添加 onContextMenu 事件处理器
|
||||||
const childrenWithContextMenu = React.Children.map(children, (child) =>
|
const childrenWithContextMenu = React.Children.map(children, (child) =>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user