index.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { type FlowNodeEntity, useClientContext } from '@flowgram.ai/fixed-layout-editor';
  2. import { IconPlus } from '@douyinfe/semi-icons';
  3. import { BlockNodeRegistry } from '../../nodes/block';
  4. import { Container } from './styles';
  5. interface PropsType {
  6. activated?: boolean;
  7. node: FlowNodeEntity;
  8. }
  9. export default function BranchAdder(props: PropsType) {
  10. const { activated, node } = props;
  11. const nodeData = node.firstChild!.renderData;
  12. const ctx = useClientContext();
  13. const { operation, playground } = ctx;
  14. const { isVertical } = node;
  15. function addBranch() {
  16. const block = operation.addBlock(node, BlockNodeRegistry.onAdd!(ctx, node));
  17. setTimeout(() => {
  18. playground.scrollToView({
  19. bounds: block.bounds,
  20. scrollToCenter: true,
  21. });
  22. }, 10);
  23. }
  24. if (playground.config.readonlyOrDisabled) return null;
  25. return (
  26. <Container
  27. isVertical={isVertical}
  28. activated={activated}
  29. onMouseEnter={() => nodeData?.toggleMouseEnter()}
  30. onMouseLeave={() => nodeData?.toggleMouseLeave()}
  31. >
  32. <div
  33. onClick={() => {
  34. addBranch();
  35. }}
  36. aria-hidden="true"
  37. style={{ flexGrow: 1, textAlign: 'center' }}
  38. >
  39. <IconPlus />
  40. </div>
  41. </Container>
  42. );
  43. }