Skip to content

Commit

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

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

selectParentNode: () => void;
removeSelectedNode: () => void;
cloneSelectedNode: () => void;
copySelectedNode: () => void;
Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/models/select-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,20 @@ export class SelectSource {
this._start = null;
}

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

setStart(data: StartDataType) {
this._start = data;
}
Expand Down
14 changes: 0 additions & 14 deletions packages/core/src/models/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,20 +865,6 @@ 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
2 changes: 1 addition & 1 deletion packages/designer/src/dnd/use-dnd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function useDnd({
workspace.pasteSelectedNode();
},
'command+arrowup,ctrl+arrowup': () => {
workspace.selectParentNode();
workspace.selectSource.selectParent();
},
'command+z,ctrl+z': () => {
workspace.history.back();
Expand Down
2 changes: 1 addition & 1 deletion packages/designer/src/selection-menu/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './copy-node';
export * from './delete-node';
export * from './parent-node';
export * from './select-parent-node';
export * from './view-source';
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { useWorkspace, observer } from '@music163/tango-context';
import { SelectAction } from '@music163/tango-ui';
import { EnterOutlined } from '@ant-design/icons';

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

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

export const SelectionTools = observer(
({
actions: actionsProp = ['viewSource', 'copyNode', 'deleteNode', 'parentNode'],
actions: actionsProp = ['viewSource', 'copyNode', 'deleteNode', 'selectParentNode'],
}: SelectionToolsProps) => {
const workspace = useWorkspace();
const selectSource = workspace.selectSource;
Expand Down
4 changes: 2 additions & 2 deletions packages/designer/src/widgets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
CopyNodeAction,
DeleteNodeAction,
ViewSourceAction,
ParentNodeAction,
SelectParentNodeAction,
} from './selection-menu';

const widgets = {};
Expand Down Expand Up @@ -53,5 +53,5 @@ registerWidget('sidebar.dataSource', DataSourcePanel);

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

0 comments on commit 625eaee

Please sign in to comment.