import { memo, useEffect } from 'react'; import { useUpdateNodeInternals } from '@xyflow/react'; import NodeShell from '../components/NodeShell.jsx'; import { NodeDraftInput } from '../components/NodeDraftField.jsx'; import { useWorkflow } from '../context/WorkflowContext.jsx'; import { createBrowserId } from '../lib/ids.js'; import { getNodeAccent } from '../lib/nodeRegistry.js'; function IfElseFlowNode({ id, data, selected, type }) { const { getNodeHandles, replaceNodeData, removeHandleConnections } = useWorkflow(); const updateNodeInternals = useUpdateNodeInternals(); const handles = getNodeHandles(type, data); const runtime = data.runtime || {}; useEffect(() => { updateNodeInternals(id); }, [id, data.conditions.length, updateNodeInternals]); const addCondition = () => { replaceNodeData(id, (current) => ({ ...current, conditions: [...current.conditions, { id: createBrowserId('condition'), keyword: '' }], })); }; const updateCondition = (conditionId, keyword) => { replaceNodeData(id, (current) => ({ ...current, conditions: current.conditions.map((condition) => condition.id === conditionId ? { ...condition, keyword } : condition, ), })); }; const removeCondition = (conditionId) => { if (data.conditions.length <= 1) { return; } removeHandleConnections(id, conditionId, 'source'); replaceNodeData(id, (current) => ({ ...current, conditions: current.conditions.filter((condition) => condition.id !== conditionId), })); }; return (
{data.conditions.map((condition, index) => (
updateCondition(condition.id, value)} />
))}
{runtime.matchId ? `Matched condition: ${data.conditions.findIndex((condition) => condition.id === runtime.matchId)}` : 'Точное совпадение строки активирует один из выходов.'}
{runtime.error ?
{runtime.error}
: null}
); } export default memo(IfElseFlowNode);