2024-06-21 21:46:38 +03:00
|
|
|
|
import { Handle, Position } from '@reactflow/core';
|
|
|
|
|
import { type CSSProperties, type FC, memo } from 'react';
|
|
|
|
|
import { CiSquareRemove } from 'react-icons/ci';
|
2024-06-21 18:47:46 +03:00
|
|
|
|
import { IoGitNetworkSharp } from 'react-icons/io5';
|
2024-06-21 21:46:38 +03:00
|
|
|
|
import { VscDebugStart } from 'react-icons/vsc';
|
|
|
|
|
|
|
|
|
|
import MiniButton from '@/components/ui/MiniButton.tsx';
|
2024-06-21 18:47:46 +03:00
|
|
|
|
import { useSynthesis } from '@/pages/OssPage/SynthesisContext.tsx';
|
2024-06-05 21:34:04 +03:00
|
|
|
|
|
2024-06-21 18:47:46 +03:00
|
|
|
|
const sourceHandleStyleA: CSSProperties = { left: 50 };
|
2024-06-05 21:34:04 +03:00
|
|
|
|
const sourceHandleStyleB: CSSProperties = {
|
2024-06-21 18:47:46 +03:00
|
|
|
|
right: 50,
|
|
|
|
|
left: 'auto'
|
2024-06-05 21:34:04 +03:00
|
|
|
|
};
|
|
|
|
|
|
2024-06-21 18:47:46 +03:00
|
|
|
|
interface OperationNodeProps {
|
|
|
|
|
id: string;
|
|
|
|
|
data: {
|
|
|
|
|
label: string;
|
|
|
|
|
onDelete: (nodeId: string) => void;
|
|
|
|
|
};
|
2024-06-21 21:46:38 +03:00
|
|
|
|
xPos: number;
|
|
|
|
|
yPos: number;
|
2024-06-21 18:47:46 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const OperationNode: FC<OperationNodeProps> = ({ id, data, xPos, yPos }) => {
|
|
|
|
|
const controller = useSynthesis();
|
|
|
|
|
const { label, onDelete } = data;
|
|
|
|
|
|
|
|
|
|
const handleDelete = () => {
|
|
|
|
|
onDelete(id);
|
|
|
|
|
};
|
|
|
|
|
|
2024-06-21 21:46:38 +03:00
|
|
|
|
const handleSubstitution = () => {
|
2024-06-21 18:47:46 +03:00
|
|
|
|
controller.selectNode(id);
|
|
|
|
|
controller.showSynthesis();
|
2024-06-21 21:46:38 +03:00
|
|
|
|
};
|
2024-06-21 18:47:46 +03:00
|
|
|
|
|
|
|
|
|
const handleSynthesis = () => {
|
2024-06-21 21:46:38 +03:00
|
|
|
|
controller.singleSynthesis(id);
|
|
|
|
|
};
|
2024-06-21 18:47:46 +03:00
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2024-06-21 21:46:38 +03:00
|
|
|
|
<Handle type='target' position={Position.Bottom} />
|
2024-06-21 18:47:46 +03:00
|
|
|
|
<div>
|
2024-06-21 21:46:38 +03:00
|
|
|
|
<MiniButton
|
|
|
|
|
className='float-right'
|
|
|
|
|
icon={<CiSquareRemove className='icon-red' />}
|
|
|
|
|
title='Удалить'
|
|
|
|
|
onClick={handleDelete}
|
|
|
|
|
color={'red'}
|
2024-06-21 18:47:46 +03:00
|
|
|
|
/>
|
|
|
|
|
<div>
|
|
|
|
|
Тип: <strong>Отождествление</strong>
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
2024-06-21 21:46:38 +03:00
|
|
|
|
Схема: <strong></strong>
|
2024-06-21 18:47:46 +03:00
|
|
|
|
<MiniButton
|
2024-06-21 21:46:38 +03:00
|
|
|
|
className='float-right'
|
|
|
|
|
icon={<VscDebugStart className='icon-green' />}
|
|
|
|
|
title='Синтез'
|
2024-06-21 18:47:46 +03:00
|
|
|
|
onClick={() => handleSynthesis()}
|
|
|
|
|
/>
|
|
|
|
|
<MiniButton
|
2024-06-21 21:46:38 +03:00
|
|
|
|
className='float-right'
|
|
|
|
|
icon={<IoGitNetworkSharp className='icon-green' />}
|
|
|
|
|
title='Отождествления'
|
2024-06-21 18:47:46 +03:00
|
|
|
|
onClick={() => handleSubstitution()}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2024-06-21 21:46:38 +03:00
|
|
|
|
<Handle type='source' position={Position.Top} id='a' style={sourceHandleStyleA} />
|
|
|
|
|
<Handle type='source' position={Position.Top} id='b' style={sourceHandleStyleB} />
|
2024-06-21 18:47:46 +03:00
|
|
|
|
</>
|
|
|
|
|
);
|
2024-06-05 21:34:04 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default memo(OperationNode);
|