diff --git a/packages/designer/src/context-menu-actions.ts b/packages/designer/src/context-menu-actions.ts index 053e4f031..55a83ef2f 100644 --- a/packages/designer/src/context-menu-actions.ts +++ b/packages/designer/src/context-menu-actions.ts @@ -17,6 +17,8 @@ export interface IContextMenuActions { adjustMenuLayout: IPublicApiMaterial['adjustContextMenuLayout']; } +let destroyFn: Function | undefined; + export class ContextMenuActions implements IContextMenuActions { actions: IPublicTypeContextMenuAction[] = []; @@ -55,7 +57,7 @@ export class ContextMenuActions implements IContextMenuActions { const { bounds } = designer.project.simulator?.viewport || { bounds: { left: 0, top: 0 } }; const { left: simulatorLeft, top: simulatorTop } = bounds; - let destroyFn: Function | undefined; + destroyFn?.(); const destroy = () => { destroyFn?.(); diff --git a/packages/engine/src/inner-plugins/default-context-menu.ts b/packages/engine/src/inner-plugins/default-context-menu.ts index 86feb17d9..50a86fcec 100644 --- a/packages/engine/src/inner-plugins/default-context-menu.ts +++ b/packages/engine/src/inner-plugins/default-context-menu.ts @@ -87,6 +87,9 @@ export const defaultContextMenu = (ctx: IPublicModelPluginContext) => { material.addContextMenuOption({ name: 'copy', title: intl('Copy.1'), + condition(nodes) { + return nodes.length > 0; + }, action(nodes) { if (!nodes || nodes.length < 1) { return; @@ -159,6 +162,9 @@ export const defaultContextMenu = (ctx: IPublicModelPluginContext) => { material.addContextMenuOption({ name: 'delete', title: intl('Delete'), + condition(nodes) { + return nodes.length > 0; + }, action(nodes) { nodes.forEach((node) => { node.remove(); diff --git a/packages/utils/src/context-menu.scss b/packages/utils/src/context-menu.scss index 744eede87..0bcf39d15 100644 --- a/packages/utils/src/context-menu.scss +++ b/packages/utils/src/context-menu.scss @@ -1,6 +1,6 @@ .context-menu-tree-wrap { position: relative; - padding: 4px 10px 4px 24px; + padding: 4px 10px 4px 32px; } .context-menu-tree-children { diff --git a/packages/utils/src/context-menu.tsx b/packages/utils/src/context-menu.tsx index 3c7bb5d13..f65bc312f 100644 --- a/packages/utils/src/context-menu.tsx +++ b/packages/utils/src/context-menu.tsx @@ -22,16 +22,8 @@ const Tree = (props: { const { node } = props; if (!node) { - return null; - } - - if (!node.parent) { return ( -