feat: add select parent node of selected node (#158)

* feat: add select parent node of selected node

* feat: move select parent node to SelectSource

* fix: change icon & order

---------

Co-authored-by: ccloli <8115912+ccloli@users.noreply.github.com>
This commit is contained in:
864907600cc
2024-05-20 20:15:28 +08:00
committed by GitHub
parent 9daf3872e7
commit fe31246483
9 changed files with 49 additions and 5 deletions

View File

@@ -89,7 +89,7 @@ const sandboxQuery = new DndQuery({
// 4. 图标库初始化(物料面板和组件树使用了 iconfont 里的图标)
createFromIconfontCN({
scriptUrl: '//at.alicdn.com/t/c/font_2891794_cxbtmzehxyi.js',
scriptUrl: '//at.alicdn.com/t/c/font_2891794_151xsllxqd7.js',
});
/**

View File

@@ -45,7 +45,7 @@ const sandboxQuery = new DndQuery({
// 4. 图标库初始化(物料面板和组件树使用了 iconfont 里的图标)
createFromIconfontCN({
scriptUrl: '//at.alicdn.com/t/c/font_2891794_cxbtmzehxyi.js',
scriptUrl: '//at.alicdn.com/t/c/font_2891794_151xsllxqd7.js',
});
/**

View File

@@ -14,7 +14,7 @@ const BLACK_LIST = ['codeSetter', 'eventSetter', 'modelSetter', 'routerSetter'];
BUILT_IN_SETTERS.filter((setter) => !BLACK_LIST.includes(setter.name)).forEach(register);
createFromIconfontCN({
scriptUrl: '//at.alicdn.com/t/c/font_2891794_cxbtmzehxyi.js',
scriptUrl: '//at.alicdn.com/t/c/font_2891794_151xsllxqd7.js',
});
export default {

View File

@@ -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;
}

View File

@@ -58,6 +58,9 @@ export function useDnd({
'command+v,ctrl+v': () => {
workspace.pasteSelectedNode();
},
'command+arrowup,ctrl+arrowup': () => {
workspace.selectSource.selectParent();
},
'command+z,ctrl+z': () => {
workspace.history.back();
},

View File

@@ -1,3 +1,4 @@
export * from './copy-node';
export * from './delete-node';
export * from './select-parent-node';
export * from './view-source';

View File

@@ -0,0 +1,18 @@
import React from 'react';
import { useWorkspace, observer } from '@music163/tango-context';
import { IconFont, SelectAction } from '@music163/tango-ui';
export const SelectParentNodeAction = observer(() => {
const workspace = useWorkspace();
return (
<SelectAction
tooltip="选中父节点"
onClick={() => {
workspace.selectSource.selectParent();
}}
>
<IconFont type="icon-huiche1" rotate={90} />
</SelectAction>
);
});

View File

@@ -24,7 +24,9 @@ export interface SelectionToolsProps {
}
export const SelectionTools = observer(
({ actions: actionsProp = ['viewSource', 'copyNode', 'deleteNode'] }: SelectionToolsProps) => {
({
actions: actionsProp = ['selectParentNode', 'viewSource', 'copyNode', 'deleteNode'],
}: SelectionToolsProps) => {
const workspace = useWorkspace();
const selectSource = workspace.selectSource;
const actions = actionsProp.map((item) => {

View File

@@ -13,7 +13,12 @@ import {
OutlinePanel,
VariablePanel,
} from './sidebar';
import { CopyNodeAction, DeleteNodeAction, ViewSourceAction } from './selection-menu';
import {
CopyNodeAction,
DeleteNodeAction,
ViewSourceAction,
SelectParentNodeAction,
} from './selection-menu';
const widgets = {};
@@ -48,4 +53,5 @@ registerWidget('sidebar.dataSource', DataSourcePanel);
registerWidget('selectionMenu.copyNode', CopyNodeAction);
registerWidget('selectionMenu.deleteNode', DeleteNodeAction);
registerWidget('selectionMenu.selectParentNode', SelectParentNodeAction);
registerWidget('selectionMenu.viewSource', ViewSourceAction);