fix: branch end check, all branches are not allowed to be end (#146)

This commit is contained in:
xiamidaxia 2025-04-16 17:13:39 +08:00 committed by GitHub
parent f43d70ee88
commit 4bb3270f2d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 2 deletions

View File

@ -1,4 +1,5 @@
import { nanoid } from 'nanoid';
import { FlowNodeBaseType } from '@flowgram.ai/fixed-layout-editor';
import { FlowNodeRegistry } from '../../typings';
import iconEnd from '../../assets/icon-end.jpg';
@ -23,7 +24,34 @@ export const EndNodeRegistry: FlowNodeRegistry = {
formMeta,
canAdd(ctx, from) {
// You can only add to the last node of the branch
return from.isLast;
if (!from.isLast) return false;
/**
* condition
* blockIcon
* inlineBlocks
* block1
* blockOrderIcon
* <---- [add end]
* block2
* blockOrderIcon
* end
*/
// originParent can determine whether it is condition , and then determine whether it is the last one
// https://github.com/bytedance/flowgram.ai/pull/146
if (
from.parent &&
from.parent.parent?.flowNodeType === FlowNodeBaseType.INLINE_BLOCKS &&
from.parent.originParent &&
!from.parent.originParent.isLast
) {
const allBranches = from.parent.parent!.blocks;
// Determine whether the last node of all branch is end, All branches are not allowed to be end
const branchEndCount = allBranches.filter(
(block) => block.blocks[block.blocks.length - 1]?.getNodeMeta().isNodeEnd
).length;
return branchEndCount < allBranches.length - 1;
}
return true;
},
canDelete(ctx, node) {
return node.parent === ctx.document.root;

View File

@ -8,7 +8,7 @@ export type FlowNodeType = string | number;
*/
export interface FlowNodeJSON {
id: string;
type?: FlowNodeType; // 如果缺省 则 为 block
type?: FlowNodeBaseType | FlowNodeSplitType | FlowNodeType; // 如果缺省 则 为 block
data?: Record<string, any>; // 节点额外扩展的内容
meta?: FlowNodeMeta;
blocks?: FlowNodeJSON[]; // 子节点