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

Function createContextMenu

packages/utils/src/context-menu.tsx:195–230  ·  view source on GitHub ↗
(children: React.ReactNode[], {
  event,
  offset = [0, 0],
}: {
  event: MouseEvent | React.MouseEvent;
  offset?: [number, number];
})

Source from the content-addressed store, hash-verified

193}
194
195export function createContextMenu(children: React.ReactNode[], {
196 event,
197 offset = [0, 0],
198}: {
199 event: MouseEvent | React.MouseEvent;
200 offset?: [number, number];
201}) {
202 event.preventDefault();
203 event.stopPropagation();
204
205 const viewportWidth = window.innerWidth;
206 const viewportHeight = window.innerHeight;
207 const dividerCount = React.Children.count(children.filter(child => React.isValidElement(child) && child.type === Divider));
208 const popupItemCount = React.Children.count(children.filter(child => React.isValidElement(child) && (child.type === PopupItem || child.type === Item)));
209 const menuHeight = popupItemCount * parseInt(getMenuItemHeight(), 10) + dividerCount * 8 + 16;
210 const menuWidthLimit = 200;
211 let x = event.clientX + offset[0];
212 let y = event.clientY + offset[1];
213 if (x + menuWidthLimit > viewportWidth) {
214 x = x - menuWidthLimit;
215 }
216 if (y + menuHeight > viewportHeight) {
217 y = y - menuHeight;
218 }
219
220 const menuInstance = Menu.create({
221 target: document.body,
222 offset: [x, y],
223 children,
224 className: 'engine-context-menu',
225 });
226
227 destroyFn = (menuInstance as any).destroy;
228
229 return destroyFn;
230}

Callers 3

ContextMenuFunction · 0.85
context-menu.tsxFile · 0.85
ContextMenuActionsClass · 0.85

Calls 3

getMenuItemHeightFunction · 0.85
filterMethod · 0.65
createMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…