MCPcopy Index your code
hub / github.com/alibaba/lowcode-engine / ContextMenu

Function ContextMenu

packages/shell/src/components/context-menu.tsx:6–53  ·  view source on GitHub ↗
({ children, menus, pluginContext }: {
  menus: IPublicTypeContextMenuAction[];
  children: React.ReactElement[] | React.ReactElement;
  pluginContext: IPublicModelPluginContext;
})

Source from the content-addressed store, hash-verified

4import React, { useCallback } from 'react';
5
6export function ContextMenu({ children, menus, pluginContext }: {
7 menus: IPublicTypeContextMenuAction[];
8 children: React.ReactElement[] | React.ReactElement;
9 pluginContext: IPublicModelPluginContext;
10}): React.ReactElement<any, string | React.JSXElementConstructor<any>> {
11 const handleContextMenu = useCallback((event: React.MouseEvent) => {
12 event.preventDefault();
13 event.stopPropagation();
14
15 let destroyFn: Function | undefined;
16 const destroy = () => {
17 destroyFn?.();
18 };
19 const children: React.ReactNode[] = parseContextMenuAsReactNode(parseContextMenuProperties(menus, {
20 destroy,
21 pluginContext,
22 }), { pluginContext });
23
24 if (!children?.length) {
25 return;
26 }
27
28 destroyFn = createContextMenu(children, { event });
29 }, [menus]);
30
31 if (!engineConfig.get('enableContextMenu')) {
32 return (
33 <>{ children }</>
34 );
35 }
36
37 if (!menus) {
38 return (
39 <>{ children }</>
40 );
41 }
42
43 // 克隆 children 并添加 onContextMenu 事件处理器
44 const childrenWithContextMenu = React.Children.map(children, (child) =>
45 React.cloneElement(
46 child,
47 { onContextMenu: handleContextMenu },
48 ));
49
50 return (
51 <>{childrenWithContextMenu}</>
52 );
53}
54
55ContextMenu.create = (pluginContext: IPublicModelPluginContext, menus: IPublicTypeContextMenuAction[], event: MouseEvent) => {
56 event.preventDefault();

Callers

nothing calls this directly

Calls 5

createContextMenuFunction · 0.85
getMethod · 0.65
mapMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…