feat: error connections

This commit is contained in:
2026-03-11 23:05:09 +01:00
parent e79821bd81
commit 48dcf38e01
6 changed files with 112 additions and 5 deletions

View File

@@ -0,0 +1,48 @@
/**
* Connection status: visual state of an edge (color/class).
* Priority when multiple apply: error > paused > updating > default.
* Nodes report state via FlowContext (e.g. addConnectionPathError); edges derive status here.
*/
export type ConnectionStatus = 'default' | 'updating' | 'paused' | 'error'
export type ConnectionStatusInputs = {
source: string
target: string
pathNodeIds: Set<string>
pausedSegmentNodeIds: Set<string>
activeSegmentNodeIds: Set<string>
errorTargetNodeIds: Set<string>
}
/**
* Compute the single connection status for an edge (priority: error > paused > updating > default).
* Use in edge components; add new statuses by extending the type and adding a branch here.
*/
export function getConnectionStatus(inputs: ConnectionStatusInputs): ConnectionStatus {
const { target, pathNodeIds, pausedSegmentNodeIds, activeSegmentNodeIds, errorTargetNodeIds, source } = inputs
if (errorTargetNodeIds.has(target)) return 'error'
if (
pathNodeIds.has(source) &&
pathNodeIds.has(target) &&
pausedSegmentNodeIds.has(source) &&
pausedSegmentNodeIds.has(target)
)
return 'paused'
if (
pathNodeIds.has(source) &&
pathNodeIds.has(target) &&
activeSegmentNodeIds.has(source) &&
activeSegmentNodeIds.has(target)
)
return 'updating'
return 'default'
}
/** CSS class suffix for each status (animated-edge-path--{status}). */
export const CONNECTION_STATUS_CLASS: Record<ConnectionStatus, string> = {
default: '',
updating: 'animated-edge-path--updating',
paused: 'animated-edge-path--paused',
error: 'animated-edge-path--error',
}

View File

@@ -46,6 +46,12 @@ export type FlowContextValue = {
addConnectionPathPausedNode: (nodeId: string) => void
/** Remove this node from paused. */
removeConnectionPathPausedNode: (nodeId: string) => void
/** Node ids that have an error (e.g. Render node). Incoming edges show error status (red). */
connectionPathErrorNodeIds: string[]
/** Call when this node has an error; remove when error is cleared. */
addConnectionPathError: (nodeId: string) => void
/** Call when this node's error is cleared. */
removeConnectionPathError: (nodeId: string) => void
/** Call when a path update starts for this node. Animation runs at least CONNECTION_PATH_UPDATE_MIN_MS. */
startConnectionPathUpdate: (nodeId: string) => void
/** Call when a path update ends for this node. If min duration not reached, animation continues until then. */