xiamidaxia 92b3adc5d0
fix(fixed-layout): multi-outputs/multi-inputs collapsed and move branches (#249)
* 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
2025-05-21 10:06:41 +00:00

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>
);
}