mirror of
https://gitee.com/ByteDance/flowgram.ai.git
synced 2025-07-07 17:43:29 +08:00
fix(demo): freeLayout delete shortcuts fixed (#251)
This commit is contained in:
parent
92b3adc5d0
commit
1de20674c5
@ -1,8 +1,10 @@
|
|||||||
import { Field, FieldRenderProps } from '@flowgram.ai/free-layout-editor';
|
import { Field, FieldRenderProps } from '@flowgram.ai/free-layout-editor';
|
||||||
|
import { useClientContext, CommandService } from '@flowgram.ai/free-layout-editor';
|
||||||
import { Typography, Button } from '@douyinfe/semi-ui';
|
import { Typography, Button } from '@douyinfe/semi-ui';
|
||||||
import { IconSmallTriangleDown, IconSmallTriangleLeft } from '@douyinfe/semi-icons';
|
import { IconSmallTriangleDown, IconSmallTriangleLeft } from '@douyinfe/semi-icons';
|
||||||
|
|
||||||
import { Feedback } from '../feedback';
|
import { Feedback } from '../feedback';
|
||||||
|
import { FlowCommandId } from '../../shortcuts';
|
||||||
import { useIsSidebar, useNodeRenderContext } from '../../hooks';
|
import { useIsSidebar, useNodeRenderContext } from '../../hooks';
|
||||||
import { NodeMenu } from '../../components/node-menu';
|
import { NodeMenu } from '../../components/node-menu';
|
||||||
import { getIcon } from './utils';
|
import { getIcon } from './utils';
|
||||||
@ -11,12 +13,16 @@ import { Header, Operators, Title } from './styles';
|
|||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
|
|
||||||
export function FormHeader() {
|
export function FormHeader() {
|
||||||
const { node, expanded, toggleExpand, readonly, deleteNode } = useNodeRenderContext();
|
const { node, expanded, toggleExpand, readonly } = useNodeRenderContext();
|
||||||
|
const ctx = useClientContext();
|
||||||
const isSidebar = useIsSidebar();
|
const isSidebar = useIsSidebar();
|
||||||
const handleExpand = (e: React.MouseEvent) => {
|
const handleExpand = (e: React.MouseEvent) => {
|
||||||
toggleExpand();
|
toggleExpand();
|
||||||
e.stopPropagation(); // Disable clicking prevents the sidebar from opening
|
e.stopPropagation(); // Disable clicking prevents the sidebar from opening
|
||||||
};
|
};
|
||||||
|
const handleDelete = () => {
|
||||||
|
ctx.get<CommandService>(CommandService).executeCommand(FlowCommandId.DELETE, [node]);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Header>
|
<Header>
|
||||||
@ -42,7 +48,7 @@ export function FormHeader() {
|
|||||||
)}
|
)}
|
||||||
{readonly ? undefined : (
|
{readonly ? undefined : (
|
||||||
<Operators>
|
<Operators>
|
||||||
<NodeMenu node={node} deleteNode={deleteNode} />
|
<NodeMenu node={node} deleteNode={handleDelete} />
|
||||||
</Operators>
|
</Operators>
|
||||||
)}
|
)}
|
||||||
</Header>
|
</Header>
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import {
|
|||||||
WorkflowNodeEntity,
|
WorkflowNodeEntity,
|
||||||
WorkflowNodeMeta,
|
WorkflowNodeMeta,
|
||||||
WorkflowSelectService,
|
WorkflowSelectService,
|
||||||
|
HistoryService,
|
||||||
} from '@flowgram.ai/free-layout-editor';
|
} from '@flowgram.ai/free-layout-editor';
|
||||||
import { Toast } from '@douyinfe/semi-ui';
|
import { Toast } from '@douyinfe/semi-ui';
|
||||||
|
|
||||||
@ -21,24 +22,34 @@ export class DeleteShortcut implements ShortcutsHandler {
|
|||||||
|
|
||||||
private selectService: WorkflowSelectService;
|
private selectService: WorkflowSelectService;
|
||||||
|
|
||||||
|
private historyService: HistoryService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* initialize delete shortcut - 初始化删除快捷键
|
* initialize delete shortcut - 初始化删除快捷键
|
||||||
*/
|
*/
|
||||||
constructor(context: FreeLayoutPluginContext) {
|
constructor(context: FreeLayoutPluginContext) {
|
||||||
this.document = context.get(WorkflowDocument);
|
this.document = context.get(WorkflowDocument);
|
||||||
this.selectService = context.get(WorkflowSelectService);
|
this.selectService = context.get(WorkflowSelectService);
|
||||||
|
this.historyService = context.get(HistoryService);
|
||||||
this.execute = this.execute.bind(this);
|
this.execute = this.execute.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* execute delete operation - 执行删除操作
|
* execute delete operation - 执行删除操作
|
||||||
*/
|
*/
|
||||||
public async execute(): Promise<void> {
|
public async execute(nodes?: WorkflowNodeEntity[]): Promise<void> {
|
||||||
if (!this.isValid(this.selectService.selectedNodes)) {
|
const selection = Array.isArray(nodes) ? nodes : this.selectService.selection;
|
||||||
|
if (
|
||||||
|
!this.isValid(
|
||||||
|
selection.filter((n) => n instanceof WorkflowNodeEntity) as WorkflowNodeEntity[]
|
||||||
|
)
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Merge actions to redo/undo
|
||||||
|
this.historyService.startTransaction();
|
||||||
// delete selected entities - 删除选中实体
|
// delete selected entities - 删除选中实体
|
||||||
this.selectService.selection.forEach((entity) => {
|
selection.forEach((entity) => {
|
||||||
if (entity instanceof WorkflowNodeEntity) {
|
if (entity instanceof WorkflowNodeEntity) {
|
||||||
this.removeNode(entity);
|
this.removeNode(entity);
|
||||||
} else if (entity instanceof WorkflowLineEntity) {
|
} else if (entity instanceof WorkflowLineEntity) {
|
||||||
@ -49,6 +60,7 @@ export class DeleteShortcut implements ShortcutsHandler {
|
|||||||
});
|
});
|
||||||
// filter out disposed entities - 过滤掉已删除的实体
|
// filter out disposed entities - 过滤掉已删除的实体
|
||||||
this.selectService.selection = this.selectService.selection.filter((s) => !s.disposed);
|
this.selectService.selection = this.selectService.selection.filter((s) => !s.disposed);
|
||||||
|
this.historyService.endTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user