feat(canvas-core): container node use meta.isContainer tag instead of SUB_CANVAS type

This commit is contained in:
liuyangxing 2025-03-17 17:14:02 +08:00
parent 5f1f2a6a03
commit dba6190e1a
3 changed files with 14 additions and 8 deletions

View File

@ -18,6 +18,7 @@ export interface WorkflowNodeMeta extends FlowNodeMeta {
defaultPorts?: WorkflowPorts; // 默认点位
useDynamicPort?: boolean; // 使用动态点位,会计算 data-port-key
subCanvas?: (node: WorkflowNodeEntity) => WorkflowSubCanvas | undefined;
isContainer?: boolean; // 是否容器节点
}
/**

View File

@ -367,11 +367,11 @@ export class WorkflowDocument extends FlowDocument {
const endNodeId = allNode.find((node) => node.isNodeEnd)!.id;
// 子画布内节点无需开始/结束
const nodeInSubCanvas = allNode
.filter((node) => node.parent?.flowNodeType === FlowNodeBaseType.SUB_CANVAS)
const nodeInContainer = allNode
.filter((node) => node.parent?.getNodeMeta<WorkflowNodeMeta>().isContainer)
.map((node) => node.id);
const associatedCache = new Set([endNodeId, ...nodeInSubCanvas]);
const associatedCache = new Set([endNodeId, ...nodeInContainer]);
const bfs = (nodeId: string) => {
if (associatedCache.has(nodeId)) {
return;

View File

@ -8,12 +8,12 @@ import {
WorkflowPortEntity,
WorkflowNodePortsData,
WorkflowNodeEntity,
WorkflowNodeMeta,
} from '@flowgram.ai/free-layout-core';
import { WorkflowSelectService } from '@flowgram.ai/free-layout-core';
import { WorkflowNodeJSON } from '@flowgram.ai/free-layout-core';
import { FreeOperationType, HistoryService } from '@flowgram.ai/free-history-plugin';
import { FlowNodeTransformData } from '@flowgram.ai/document';
import { FlowNodeBaseType } from '@flowgram.ai/document';
import { PlaygroundConfigEntity } from '@flowgram.ai/core';
import { TransformData } from '@flowgram.ai/core';
@ -293,7 +293,7 @@ export class WorkflowNodePanelService {
}
const fromNode = fromPort?.node;
const fromContainer = fromNode?.parent;
if (fromNode?.flowNodeType === FlowNodeBaseType.SUB_CANVAS) {
if (this.isContainer(fromNode)) {
// 子画布内部输入连线
return fromNode;
}
@ -303,7 +303,7 @@ export class WorkflowNodePanelService {
/** 获取端口矩形 */
private getPortBox(port: WorkflowPortEntity, offset: IPoint = { x: 0, y: 0 }): Rectangle {
const node = port.node;
if (node.flowNodeType === FlowNodeBaseType.SUB_CANVAS) {
if (this.isContainer(node)) {
// 子画布内部端口需要虚拟节点
const { point } = port;
if (port.portType === 'input') {
@ -424,7 +424,7 @@ export class WorkflowNodePanelService {
/** 获取后续节点 */
private getSubsequentNodes(node: WorkflowNodeEntity): WorkflowNodeEntity[] {
if (node.flowNodeType === FlowNodeBaseType.SUB_CANVAS) {
if (this.isContainer(node)) {
return [];
}
const brothers = node.parent?.collapsedChildren ?? [];
@ -436,7 +436,7 @@ export class WorkflowNodePanelService {
}
if (
!line.to?.id ||
line.to.flowNodeType === FlowNodeBaseType.SUB_CANVAS // 子画布内部成环
this.isContainer(line.to) // 子画布内部成环
) {
return;
}
@ -519,4 +519,9 @@ export class WorkflowNodePanelService {
},
});
}
/** 是否容器节点 */
private isContainer(node?: WorkflowNodeEntity): boolean {
return node?.getNodeMeta<WorkflowNodeMeta>().isContainer ?? false;
}
}