Skip to content

Commit

Permalink
fix(context-menu): fix context menu bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
liujuping authored and JackLian committed Jan 9, 2024
1 parent 6ded1a6 commit 8f0291f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
4 changes: 3 additions & 1 deletion packages/designer/src/context-menu-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export interface IContextMenuActions {
adjustMenuLayout: IPublicApiMaterial['adjustContextMenuLayout'];
}

let destroyFn: Function | undefined;

export class ContextMenuActions implements IContextMenuActions {
actions: IPublicTypeContextMenuAction[] = [];

Expand Down Expand Up @@ -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?.();
Expand Down
6 changes: 6 additions & 0 deletions packages/engine/src/inner-plugins/default-context-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/context-menu.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.context-menu-tree-wrap {
position: relative;
padding: 4px 10px 4px 24px;
padding: 4px 10px 4px 32px;
}

.context-menu-tree-children {
Expand Down
10 changes: 1 addition & 9 deletions packages/utils/src/context-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,8 @@ const Tree = (props: {
const { node } = props;

if (!node) {
return null;
}

if (!node.parent) {
return (
<div className="context-menu-tree-wrap">
<div className="context-menu-tree-children">
{props.children}
</div>
</div>
<div className="context-menu-tree-wrap">{ props.children }</div>
);
}

Expand Down

0 comments on commit 8f0291f

Please sign in to comment.