mirror of
https://gitee.com/ByteDance/flowgram.ai.git
synced 2025-07-07 17:43:29 +08:00
fix: branch end check, all branches are not allowed to be end (#146)
This commit is contained in:
parent
f43d70ee88
commit
4bb3270f2d
@ -1,4 +1,5 @@
|
|||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
|
import { FlowNodeBaseType } from '@flowgram.ai/fixed-layout-editor';
|
||||||
|
|
||||||
import { FlowNodeRegistry } from '../../typings';
|
import { FlowNodeRegistry } from '../../typings';
|
||||||
import iconEnd from '../../assets/icon-end.jpg';
|
import iconEnd from '../../assets/icon-end.jpg';
|
||||||
@ -23,7 +24,34 @@ export const EndNodeRegistry: FlowNodeRegistry = {
|
|||||||
formMeta,
|
formMeta,
|
||||||
canAdd(ctx, from) {
|
canAdd(ctx, from) {
|
||||||
// You can only add to the last node of the branch
|
// 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) {
|
canDelete(ctx, node) {
|
||||||
return node.parent === ctx.document.root;
|
return node.parent === ctx.document.root;
|
||||||
|
|||||||
@ -8,7 +8,7 @@ export type FlowNodeType = string | number;
|
|||||||
*/
|
*/
|
||||||
export interface FlowNodeJSON {
|
export interface FlowNodeJSON {
|
||||||
id: string;
|
id: string;
|
||||||
type?: FlowNodeType; // 如果缺省 则 为 block
|
type?: FlowNodeBaseType | FlowNodeSplitType | FlowNodeType; // 如果缺省 则 为 block
|
||||||
data?: Record<string, any>; // 节点额外扩展的内容
|
data?: Record<string, any>; // 节点额外扩展的内容
|
||||||
meta?: FlowNodeMeta;
|
meta?: FlowNodeMeta;
|
||||||
blocks?: FlowNodeJSON[]; // 子节点
|
blocks?: FlowNodeJSON[]; // 子节点
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user