/** * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates * SPDX-License-Identifier: MIT */ import '@flowgram.ai/fixed-layout-editor/index.css'; import { FC } from 'react'; import { FlowNodeEntity, FlowNodeJSON, FlowOperationService, usePlayground, useService, } from '@flowgram.ai/fixed-layout-editor'; const useAddNode = () => { const playground = usePlayground(); const flowOperationService = useService(FlowOperationService) as FlowOperationService; const handleAdd = (addProps: FlowNodeJSON, dropNode: FlowNodeEntity) => { const blocks = addProps.blocks ? addProps.blocks : undefined; const entity = flowOperationService.addFromNode(dropNode, { ...addProps, blocks, }); setTimeout(() => { playground.scrollToView({ bounds: entity.bounds, scrollToCenter: true, }); }, 10); return entity; }; const handleAddBranch = (addProps: FlowNodeJSON, dropNode: FlowNodeEntity) => { const index = dropNode.index + 1; const entity = flowOperationService.addBlock(dropNode.originParent!, addProps, { index, }); return entity; }; return { handleAdd, handleAddBranch, }; }; export const Adder: FC<{ from: FlowNodeEntity; to?: FlowNodeEntity; hoverActivated: boolean; }> = ({ from, hoverActivated }) => { const playground = usePlayground(); const { handleAdd } = useAddNode(); if (playground.config.readonlyOrDisabled) return null; return (
{ handleAdd({ type: 'custom', id: `custom_${Date.now()}` }, from); }} > {hoverActivated ? ( + ) : null}
); };