Skip to content

Commit

Permalink
feat: add select parent node of selected node (#158)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
ccloli and ccloli committed May 20, 2024
1 parent 9daf387 commit fe31246
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 5 deletions.
2 changes: 1 addition & 1 deletion apps/playground/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});

/**
Expand Down
2 changes: 1 addition & 1 deletion apps/playground/src/pages/mail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});

/**
Expand Down
2 changes: 1 addition & 1 deletion apps/storybook/src/setting-form.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
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
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.selectSource.selectParent();
},
'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 './select-parent-node';
export * from './view-source';
18 changes: 18 additions & 0 deletions packages/designer/src/selection-menu/select-parent-node.tsx
Original file line number Diff line number Diff line change
@@ -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>
);
});
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 = ['selectParentNode', 'viewSource', 'copyNode', 'deleteNode'],
}: 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,
SelectParentNodeAction,
} 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.selectParentNode', SelectParentNodeAction);
registerWidget('selectionMenu.viewSource', ViewSourceAction);

0 comments on commit fe31246

Please sign in to comment.