mirror of
https://gitee.com/ByteDance/flowgram.ai.git
synced 2025-07-07 17:43:29 +08:00
* feat(demo): demo-fixed-layout-simple add tryCatch node * feat(demo): use-editor-props add fromNodeJSON/toNodeJSON config * fix(demo): demo-fixed-layout-simple readonly refresh * fix(fixed-layout): multi-outputs collapsed and move branches * chore: update codeowners * fix(fixed-layout): multi-inputs branch adder * test(fixed-layout-core): test snapshots update * test(fixed-layout-editor): move block to other dynamicSplit
82 lines
1.9 KiB
TypeScript
82 lines
1.9 KiB
TypeScript
import { nanoid } from 'nanoid';
|
|
import { type FlowNodeEntity, useClientContext } from '@flowgram.ai/fixed-layout-editor';
|
|
import { IconPlus } from '@douyinfe/semi-icons';
|
|
|
|
interface PropsType {
|
|
activated?: boolean;
|
|
node: FlowNodeEntity;
|
|
}
|
|
|
|
export function BranchAdder(props: PropsType) {
|
|
const { activated, node } = props;
|
|
const nodeData = node.firstChild!.renderData;
|
|
const ctx = useClientContext();
|
|
const { operation, playground } = ctx;
|
|
const { isVertical } = node;
|
|
|
|
function addBranch() {
|
|
let block: FlowNodeEntity;
|
|
if (node.flowNodeType === 'multiOutputs') {
|
|
block = operation.addBlock(node, {
|
|
id: `output_${nanoid(5)}`,
|
|
type: 'output',
|
|
data: {
|
|
title: 'New Ouput',
|
|
content: '',
|
|
},
|
|
});
|
|
} else if (node.flowNodeType === 'multiInputs') {
|
|
block = operation.addBlock(node, {
|
|
id: `input_${nanoid(5)}`,
|
|
type: 'input',
|
|
data: {
|
|
title: 'New Input',
|
|
content: '',
|
|
},
|
|
});
|
|
} else {
|
|
block = operation.addBlock(node, {
|
|
id: `branch_${nanoid(5)}`,
|
|
type: 'block',
|
|
data: {
|
|
title: 'New Branch',
|
|
content: '',
|
|
},
|
|
});
|
|
}
|
|
|
|
setTimeout(() => {
|
|
playground.scrollToView({
|
|
bounds: block.bounds,
|
|
scrollToCenter: true,
|
|
});
|
|
}, 10);
|
|
}
|
|
|
|
if (playground.config.readonlyOrDisabled) return null;
|
|
|
|
const className = [
|
|
'demo-fixed-adder',
|
|
isVertical ? '' : 'isHorizontal',
|
|
activated ? 'activated' : '',
|
|
].join(' ');
|
|
|
|
return (
|
|
<div
|
|
className={className}
|
|
onMouseEnter={() => nodeData?.toggleMouseEnter()}
|
|
onMouseLeave={() => nodeData?.toggleMouseLeave()}
|
|
>
|
|
<div
|
|
onClick={() => {
|
|
addBranch();
|
|
}}
|
|
aria-hidden="true"
|
|
style={{ flexGrow: 1, textAlign: 'center' }}
|
|
>
|
|
<IconPlus />
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|