import { memo, useEffect } from 'react'; import { useUpdateNodeInternals } from '@xyflow/react'; import NodeShell from '../components/NodeShell.jsx'; import { useWorkflow } from '../context/WorkflowContext.jsx'; import { createBrowserId } from '../lib/ids.js'; import { getNodeAccent } from '../lib/nodeRegistry.js'; function ScriptFlowNode({ 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.entries.length, data.hasScriptOutput, updateNodeInternals]); const addEntry = (kind) => { replaceNodeData(id, (current) => ({ ...current, entries: [...current.entries, { id: createBrowserId(`${kind}-slot`), kind }], })); }; const removeEntry = (entryId) => { removeHandleConnections(id, entryId, 'target'); replaceNodeData(id, (current) => ({ ...current, entries: current.entries.filter((entry) => entry.id !== entryId), })); }; const toggleOutput = () => { if (data.hasScriptOutput) { removeHandleConnections(id, 'script-text', 'source'); } replaceNodeData(id, (current) => ({ ...current, hasScriptOutput: !current.hasScriptOutput, })); }; return ( index === 0 ? null : ( ) } footer={
} >
{runtime.error ?
{runtime.error}
: null} ); } export default memo(ScriptFlowNode);