Skip to content

Commit

Permalink
feat: add select parent node of selected node
Browse files Browse the repository at this point in the history
  • Loading branch information
ccloli committed May 20, 2024
1 parent f17ccbb commit e7e2c7b
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/core/src/models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export interface IWorkspace {

// ----------------- 节点操作 -----------------

selectParentNode: () => void;
removeSelectedNode: () => void;
cloneSelectedNode: () => void;
copySelectedNode: () => void;
Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/models/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,20 @@ export class Workspace extends EventTarget implements IWorkspace {
});
}

/**
* 选中当前选中节点的父节点
*/
selectParentNode() {
const parents = this.selectSource?.first?.parents || [];
if (parents.length) {
const [parent, ...rest] = parents;
this.selectSource.select({
...parent,
parents: rest,
});
}
}

/**
* 删除选中节点
*/
Expand Down
3 changes: 3 additions & 0 deletions packages/designer/src/dnd/use-dnd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ export function useDnd({
'command+v,ctrl+v': () => {
workspace.pasteSelectedNode();
},
'command+arrowup,ctrl+arrowup': () => {
workspace.selectParentNode();
},
'command+z,ctrl+z': () => {
workspace.history.back();
},
Expand Down
1 change: 1 addition & 0 deletions packages/designer/src/selection-menu/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './copy-node';
export * from './delete-node';
export * from './parent-node';
export * from './view-source';
19 changes: 19 additions & 0 deletions packages/designer/src/selection-menu/parent-node.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import { useWorkspace, observer } from '@music163/tango-context';
import { SelectAction } from '@music163/tango-ui';
import { EnterOutlined } from '@ant-design/icons';

export const ParentNodeAction = observer(() => {
const workspace = useWorkspace();

return (
<SelectAction
tooltip="选中父节点"
onClick={() => {
workspace.selectParentNode();
}}
>
<EnterOutlined rotate={90} />
</SelectAction>
);
});
4 changes: 3 additions & 1 deletion packages/designer/src/simulator/selection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export interface SelectionToolsProps {
}

export const SelectionTools = observer(
({ actions: actionsProp = ['viewSource', 'copyNode', 'deleteNode'] }: SelectionToolsProps) => {
({
actions: actionsProp = ['viewSource', 'copyNode', 'deleteNode', 'parentNode'],
}: SelectionToolsProps) => {
const workspace = useWorkspace();
const selectSource = workspace.selectSource;
const actions = actionsProp.map((item) => {
Expand Down
8 changes: 7 additions & 1 deletion packages/designer/src/widgets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import {
OutlinePanel,
VariablePanel,
} from './sidebar';
import { CopyNodeAction, DeleteNodeAction, ViewSourceAction } from './selection-menu';
import {
CopyNodeAction,
DeleteNodeAction,
ViewSourceAction,
ParentNodeAction,
} from './selection-menu';

const widgets = {};

Expand Down Expand Up @@ -48,4 +53,5 @@ registerWidget('sidebar.dataSource', DataSourcePanel);

registerWidget('selectionMenu.copyNode', CopyNodeAction);
registerWidget('selectionMenu.deleteNode', DeleteNodeAction);
registerWidget('selectionMenu.parentNode', ParentNodeAction);
registerWidget('selectionMenu.viewSource', ViewSourceAction);

0 comments on commit e7e2c7b

Please sign in to comment.