@coral-viz/viz 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +4 -0
- package/README.md +11 -0
- package/dist/compatibility/CompatibilityEdge.d.ts +106 -0
- package/dist/compatibility/CompatibilityEdge.d.ts.map +1 -0
- package/dist/compatibility/CompatibilityEdge.js +233 -0
- package/dist/compatibility/CompatibilityEdge.js.map +1 -0
- package/dist/compatibility/IncompatibilityTooltip.d.ts +44 -0
- package/dist/compatibility/IncompatibilityTooltip.d.ts.map +1 -0
- package/dist/compatibility/IncompatibilityTooltip.js +145 -0
- package/dist/compatibility/IncompatibilityTooltip.js.map +1 -0
- package/dist/compatibility/index.d.ts +10 -0
- package/dist/compatibility/index.d.ts.map +1 -0
- package/dist/compatibility/index.js +10 -0
- package/dist/compatibility/index.js.map +1 -0
- package/dist/compatibility/useEdgeCompatibility.d.ts +82 -0
- package/dist/compatibility/useEdgeCompatibility.d.ts.map +1 -0
- package/dist/compatibility/useEdgeCompatibility.js +170 -0
- package/dist/compatibility/useEdgeCompatibility.js.map +1 -0
- package/dist/compatibility/validateConnection.d.ts +56 -0
- package/dist/compatibility/validateConnection.d.ts.map +1 -0
- package/dist/compatibility/validateConnection.js +382 -0
- package/dist/compatibility/validateConnection.js.map +1 -0
- package/dist/components/EditContext.d.ts +45 -0
- package/dist/components/EditContext.d.ts.map +1 -0
- package/dist/components/EditContext.js +41 -0
- package/dist/components/EditContext.js.map +1 -0
- package/dist/components/ShapeRenderer.d.ts +35 -0
- package/dist/components/ShapeRenderer.d.ts.map +1 -0
- package/dist/components/ShapeRenderer.js +77 -0
- package/dist/components/ShapeRenderer.js.map +1 -0
- package/dist/components/SymbolNode.d.ts +53 -0
- package/dist/components/SymbolNode.d.ts.map +1 -0
- package/dist/components/SymbolNode.js +333 -0
- package/dist/components/SymbolNode.js.map +1 -0
- package/dist/components/index.d.ts +8 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +10 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/nodes.d.ts +43 -0
- package/dist/components/nodes.d.ts.map +1 -0
- package/dist/components/nodes.js +111 -0
- package/dist/components/nodes.js.map +1 -0
- package/dist/editor/CoralEditor.d.ts +29 -0
- package/dist/editor/CoralEditor.d.ts.map +1 -0
- package/dist/editor/CoralEditor.js +112 -0
- package/dist/editor/CoralEditor.js.map +1 -0
- package/dist/editor/FileControls.d.ts +34 -0
- package/dist/editor/FileControls.d.ts.map +1 -0
- package/dist/editor/FileControls.js +139 -0
- package/dist/editor/FileControls.js.map +1 -0
- package/dist/editor/LayoutControls.d.ts +41 -0
- package/dist/editor/LayoutControls.d.ts.map +1 -0
- package/dist/editor/LayoutControls.js +124 -0
- package/dist/editor/LayoutControls.js.map +1 -0
- package/dist/editor/converter.d.ts +37 -0
- package/dist/editor/converter.d.ts.map +1 -0
- package/dist/editor/converter.js +256 -0
- package/dist/editor/converter.js.map +1 -0
- package/dist/editor/index.d.ts +8 -0
- package/dist/editor/index.d.ts.map +1 -0
- package/dist/editor/index.js +8 -0
- package/dist/editor/index.js.map +1 -0
- package/dist/file/deserialize.d.ts +15 -0
- package/dist/file/deserialize.d.ts.map +1 -0
- package/dist/file/deserialize.js +145 -0
- package/dist/file/deserialize.js.map +1 -0
- package/dist/file/index.d.ts +15 -0
- package/dist/file/index.d.ts.map +1 -0
- package/dist/file/index.js +20 -0
- package/dist/file/index.js.map +1 -0
- package/dist/file/migrate.d.ts +29 -0
- package/dist/file/migrate.d.ts.map +1 -0
- package/dist/file/migrate.js +103 -0
- package/dist/file/migrate.js.map +1 -0
- package/dist/file/schema.d.ts +385 -0
- package/dist/file/schema.d.ts.map +1 -0
- package/dist/file/schema.js +180 -0
- package/dist/file/schema.js.map +1 -0
- package/dist/file/serialize.d.ts +30 -0
- package/dist/file/serialize.d.ts.map +1 -0
- package/dist/file/serialize.js +218 -0
- package/dist/file/serialize.js.map +1 -0
- package/dist/file/validate.d.ts +21 -0
- package/dist/file/validate.d.ts.map +1 -0
- package/dist/file/validate.js +165 -0
- package/dist/file/validate.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/layout/elk.d.ts +77 -0
- package/dist/layout/elk.d.ts.map +1 -0
- package/dist/layout/elk.js +379 -0
- package/dist/layout/elk.js.map +1 -0
- package/dist/layout/index.d.ts +12 -0
- package/dist/layout/index.d.ts.map +1 -0
- package/dist/layout/index.js +12 -0
- package/dist/layout/index.js.map +1 -0
- package/dist/layout/nodeSizing.d.ts +65 -0
- package/dist/layout/nodeSizing.d.ts.map +1 -0
- package/dist/layout/nodeSizing.js +319 -0
- package/dist/layout/nodeSizing.js.map +1 -0
- package/dist/layout/positionStability.d.ts +73 -0
- package/dist/layout/positionStability.d.ts.map +1 -0
- package/dist/layout/positionStability.js +199 -0
- package/dist/layout/positionStability.js.map +1 -0
- package/dist/layout/useAxisConstrain.d.ts +20 -0
- package/dist/layout/useAxisConstrain.d.ts.map +1 -0
- package/dist/layout/useAxisConstrain.js +106 -0
- package/dist/layout/useAxisConstrain.js.map +1 -0
- package/dist/layout/useDiagramState.d.ts +92 -0
- package/dist/layout/useDiagramState.d.ts.map +1 -0
- package/dist/layout/useDiagramState.js +256 -0
- package/dist/layout/useDiagramState.js.map +1 -0
- package/dist/layout/useLayoutHistory.d.ts +53 -0
- package/dist/layout/useLayoutHistory.d.ts.map +1 -0
- package/dist/layout/useLayoutHistory.js +124 -0
- package/dist/layout/useLayoutHistory.js.map +1 -0
- package/dist/properties/NodePropertiesPanel.d.ts +47 -0
- package/dist/properties/NodePropertiesPanel.d.ts.map +1 -0
- package/dist/properties/NodePropertiesPanel.js +199 -0
- package/dist/properties/NodePropertiesPanel.js.map +1 -0
- package/dist/properties/index.d.ts +10 -0
- package/dist/properties/index.d.ts.map +1 -0
- package/dist/properties/index.js +10 -0
- package/dist/properties/index.js.map +1 -0
- package/dist/properties/propertyUtils.d.ts +60 -0
- package/dist/properties/propertyUtils.d.ts.map +1 -0
- package/dist/properties/propertyUtils.js +89 -0
- package/dist/properties/propertyUtils.js.map +1 -0
- package/dist/settings/FontSettingsForm.d.ts +28 -0
- package/dist/settings/FontSettingsForm.d.ts.map +1 -0
- package/dist/settings/FontSettingsForm.js +129 -0
- package/dist/settings/FontSettingsForm.js.map +1 -0
- package/dist/settings/LayoutSettingsForm.d.ts +37 -0
- package/dist/settings/LayoutSettingsForm.d.ts.map +1 -0
- package/dist/settings/LayoutSettingsForm.js +165 -0
- package/dist/settings/LayoutSettingsForm.js.map +1 -0
- package/dist/settings/SettingsPanel.d.ts +55 -0
- package/dist/settings/SettingsPanel.d.ts.map +1 -0
- package/dist/settings/SettingsPanel.js +84 -0
- package/dist/settings/SettingsPanel.js.map +1 -0
- package/dist/settings/index.d.ts +13 -0
- package/dist/settings/index.d.ts.map +1 -0
- package/dist/settings/index.js +13 -0
- package/dist/settings/index.js.map +1 -0
- package/dist/settings/useSettings.d.ts +51 -0
- package/dist/settings/useSettings.d.ts.map +1 -0
- package/dist/settings/useSettings.js +154 -0
- package/dist/settings/useSettings.js.map +1 -0
- package/dist/text-editor/SplitEditor.d.ts +72 -0
- package/dist/text-editor/SplitEditor.d.ts.map +1 -0
- package/dist/text-editor/SplitEditor.js +172 -0
- package/dist/text-editor/SplitEditor.js.map +1 -0
- package/dist/text-editor/TextEditor.d.ts +53 -0
- package/dist/text-editor/TextEditor.d.ts.map +1 -0
- package/dist/text-editor/TextEditor.js +181 -0
- package/dist/text-editor/TextEditor.js.map +1 -0
- package/dist/text-editor/hooks/useBidirectionalSync.d.ts +106 -0
- package/dist/text-editor/hooks/useBidirectionalSync.d.ts.map +1 -0
- package/dist/text-editor/hooks/useBidirectionalSync.js +151 -0
- package/dist/text-editor/hooks/useBidirectionalSync.js.map +1 -0
- package/dist/text-editor/index.d.ts +9 -0
- package/dist/text-editor/index.d.ts.map +1 -0
- package/dist/text-editor/index.js +11 -0
- package/dist/text-editor/index.js.map +1 -0
- package/dist/types.d.ts +242 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/waypoints/index.d.ts +8 -0
- package/dist/waypoints/index.d.ts.map +1 -0
- package/dist/waypoints/index.js +7 -0
- package/dist/waypoints/index.js.map +1 -0
- package/dist/waypoints/operations.d.ts +29 -0
- package/dist/waypoints/operations.d.ts.map +1 -0
- package/dist/waypoints/operations.js +85 -0
- package/dist/waypoints/operations.js.map +1 -0
- package/dist/waypoints/router.d.ts +23 -0
- package/dist/waypoints/router.d.ts.map +1 -0
- package/dist/waypoints/router.js +109 -0
- package/dist/waypoints/router.js.map +1 -0
- package/dist/waypoints/types.d.ts +15 -0
- package/dist/waypoints/types.d.ts.map +1 -0
- package/dist/waypoints/types.js +5 -0
- package/dist/waypoints/types.js.map +1 -0
- package/dist/waypoints/useWaypointManager.d.ts +38 -0
- package/dist/waypoints/useWaypointManager.d.ts.map +1 -0
- package/dist/waypoints/useWaypointManager.js +106 -0
- package/dist/waypoints/useWaypointManager.js.map +1 -0
- package/package.json +76 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useEdgeCompatibility Hook (CORAL-REQ-010)
|
|
3
|
+
*
|
|
4
|
+
* React hook for managing edge compatibility state and providing
|
|
5
|
+
* validation functions for the visual editor.
|
|
6
|
+
*/
|
|
7
|
+
import type { CoralNode, CoralEdge, EdgeCompatibility, EdgeCompatibilityStatus, ConnectionValidation, NodeConnectionInfo } from '../types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Options for the useEdgeCompatibility hook (CoralNode/CoralEdge mode)
|
|
10
|
+
*/
|
|
11
|
+
export interface UseEdgeCompatibilityOptionsNodes {
|
|
12
|
+
/** Current nodes in the diagram */
|
|
13
|
+
nodes: CoralNode[];
|
|
14
|
+
/** Current edges in the diagram */
|
|
15
|
+
edges: CoralEdge[];
|
|
16
|
+
/** Notation ID for validation rules */
|
|
17
|
+
notationId: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Options for the useEdgeCompatibility hook (context mode)
|
|
21
|
+
* Use this when you have pre-built node info and edge arrays
|
|
22
|
+
*/
|
|
23
|
+
export interface UseEdgeCompatibilityOptionsContext {
|
|
24
|
+
/** Notation ID for validation rules */
|
|
25
|
+
notationId: string;
|
|
26
|
+
/** Pre-built node connection info map */
|
|
27
|
+
nodeInfo: Map<string, NodeConnectionInfo>;
|
|
28
|
+
/** Pre-built existing edges array (with IDs for lookup) */
|
|
29
|
+
existingEdges: Array<{
|
|
30
|
+
id: string;
|
|
31
|
+
source: string;
|
|
32
|
+
target: string;
|
|
33
|
+
sourcePort?: string;
|
|
34
|
+
targetPort?: string;
|
|
35
|
+
}>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Options for the useEdgeCompatibility hook
|
|
39
|
+
*/
|
|
40
|
+
export type UseEdgeCompatibilityOptions = UseEdgeCompatibilityOptionsNodes | UseEdgeCompatibilityOptionsContext;
|
|
41
|
+
/**
|
|
42
|
+
* Result from the useEdgeCompatibility hook
|
|
43
|
+
*/
|
|
44
|
+
export interface UseEdgeCompatibilityResult {
|
|
45
|
+
/** Compatibility info for all edges */
|
|
46
|
+
edgeCompatibility: EdgeCompatibility[];
|
|
47
|
+
/** Check if a proposed connection is valid */
|
|
48
|
+
checkConnection: (sourceId: string, targetId: string, sourcePort?: string, targetPort?: string) => ConnectionValidation;
|
|
49
|
+
/** Get list of incompatible edge IDs */
|
|
50
|
+
getIncompatibleEdgeIds: () => string[];
|
|
51
|
+
/** Get list of edges with warnings */
|
|
52
|
+
getWarningEdgeIds: () => string[];
|
|
53
|
+
/** Get status for a specific edge */
|
|
54
|
+
getEdgeStatus: (edgeId: string) => EdgeCompatibilityStatus | undefined;
|
|
55
|
+
/** Get validation result for a specific edge */
|
|
56
|
+
getEdgeValidation: (edgeId: string) => ConnectionValidation | undefined;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Hook for managing edge compatibility in the visual editor
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```tsx
|
|
63
|
+
* const { edgeCompatibility, checkConnection, getIncompatibleEdgeIds } = useEdgeCompatibility({
|
|
64
|
+
* nodes,
|
|
65
|
+
* edges,
|
|
66
|
+
* notationId: 'flowchart',
|
|
67
|
+
* });
|
|
68
|
+
*
|
|
69
|
+
* // Style incompatible edges
|
|
70
|
+
* const styledEdges = edges.map(edge => ({
|
|
71
|
+
* ...edge,
|
|
72
|
+
* style: getIncompatibleEdgeIds().includes(edge.id)
|
|
73
|
+
* ? { stroke: '#f59e0b' } // warning color
|
|
74
|
+
* : undefined,
|
|
75
|
+
* }));
|
|
76
|
+
*
|
|
77
|
+
* // Validate during drag
|
|
78
|
+
* const isValid = checkConnection(sourceId, targetId);
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare function useEdgeCompatibility(options: UseEdgeCompatibilityOptions): UseEdgeCompatibilityResult;
|
|
82
|
+
//# sourceMappingURL=useEdgeCompatibility.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEdgeCompatibility.d.ts","sourceRoot":"","sources":["../../src/compatibility/useEdgeCompatibility.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EACV,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,uBAAuB,EACvB,oBAAoB,EACpB,kBAAkB,EAEnB,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,MAAM,WAAW,gCAAgC;IAC/C,mCAAmC;IACnC,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,mCAAmC;IACnC,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,uCAAuC;IACvC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,MAAM,WAAW,kCAAkC;IACjD,uCAAuC;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,yCAAyC;IACzC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC1C,2DAA2D;IAC3D,aAAa,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChH;AAED;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG,gCAAgC,GAAG,kCAAkC,CAAC;AAShH;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,uCAAuC;IACvC,iBAAiB,EAAE,iBAAiB,EAAE,CAAC;IACvC,8CAA8C;IAC9C,eAAe,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,KAAK,oBAAoB,CAAC;IACxH,wCAAwC;IACxC,sBAAsB,EAAE,MAAM,MAAM,EAAE,CAAC;IACvC,sCAAsC;IACtC,iBAAiB,EAAE,MAAM,MAAM,EAAE,CAAC;IAClC,qCAAqC;IACrC,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,uBAAuB,GAAG,SAAS,CAAC;IACvE,gDAAgD;IAChD,iBAAiB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,oBAAoB,GAAG,SAAS,CAAC;CACzE;AAyCD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,2BAA2B,GACnC,0BAA0B,CAgI5B"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useEdgeCompatibility Hook (CORAL-REQ-010)
|
|
3
|
+
*
|
|
4
|
+
* React hook for managing edge compatibility state and providing
|
|
5
|
+
* validation functions for the visual editor.
|
|
6
|
+
*/
|
|
7
|
+
import { useMemo, useCallback } from 'react';
|
|
8
|
+
import { getEdgeCompatibility, validateConnection } from './validateConnection.js';
|
|
9
|
+
/**
|
|
10
|
+
* Check if options are in context mode
|
|
11
|
+
*/
|
|
12
|
+
function isContextMode(options) {
|
|
13
|
+
return 'nodeInfo' in options && 'existingEdges' in options;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Extract symbol ID and variant from CoralNode
|
|
17
|
+
*/
|
|
18
|
+
function extractNodeInfo(node) {
|
|
19
|
+
const data = node.data;
|
|
20
|
+
return {
|
|
21
|
+
id: node.id,
|
|
22
|
+
symbolId: data.symbolId || data.nodeType || 'unknown',
|
|
23
|
+
variant: data.properties?.variant,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Build validation context from nodes and edges
|
|
28
|
+
*/
|
|
29
|
+
function buildContext(nodes, edges, notationId) {
|
|
30
|
+
const nodeInfo = new Map();
|
|
31
|
+
nodes.forEach((node) => {
|
|
32
|
+
nodeInfo.set(node.id, extractNodeInfo(node));
|
|
33
|
+
});
|
|
34
|
+
const existingEdges = edges.map((edge) => ({
|
|
35
|
+
source: edge.source,
|
|
36
|
+
target: edge.target,
|
|
37
|
+
sourcePort: edge.sourceHandle || undefined,
|
|
38
|
+
targetPort: edge.targetHandle || undefined,
|
|
39
|
+
}));
|
|
40
|
+
return {
|
|
41
|
+
notationId,
|
|
42
|
+
nodeInfo,
|
|
43
|
+
existingEdges,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Hook for managing edge compatibility in the visual editor
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```tsx
|
|
51
|
+
* const { edgeCompatibility, checkConnection, getIncompatibleEdgeIds } = useEdgeCompatibility({
|
|
52
|
+
* nodes,
|
|
53
|
+
* edges,
|
|
54
|
+
* notationId: 'flowchart',
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* // Style incompatible edges
|
|
58
|
+
* const styledEdges = edges.map(edge => ({
|
|
59
|
+
* ...edge,
|
|
60
|
+
* style: getIncompatibleEdgeIds().includes(edge.id)
|
|
61
|
+
* ? { stroke: '#f59e0b' } // warning color
|
|
62
|
+
* : undefined,
|
|
63
|
+
* }));
|
|
64
|
+
*
|
|
65
|
+
* // Validate during drag
|
|
66
|
+
* const isValid = checkConnection(sourceId, targetId);
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export function useEdgeCompatibility(options) {
|
|
70
|
+
// Build context for validation - supports both modes
|
|
71
|
+
const context = useMemo(() => {
|
|
72
|
+
if (isContextMode(options)) {
|
|
73
|
+
// Context mode: use pre-built nodeInfo and existingEdges
|
|
74
|
+
// Strip IDs from existingEdges since the validation context doesn't use them
|
|
75
|
+
return {
|
|
76
|
+
notationId: options.notationId,
|
|
77
|
+
nodeInfo: options.nodeInfo,
|
|
78
|
+
existingEdges: options.existingEdges.map((e) => ({
|
|
79
|
+
source: e.source,
|
|
80
|
+
target: e.target,
|
|
81
|
+
sourcePort: e.sourcePort,
|
|
82
|
+
targetPort: e.targetPort,
|
|
83
|
+
})),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
// Nodes mode: build context from CoralNode/CoralEdge arrays
|
|
88
|
+
return buildContext(options.nodes, options.edges, options.notationId);
|
|
89
|
+
}
|
|
90
|
+
}, [options]);
|
|
91
|
+
// Get edges for validation - differs based on mode
|
|
92
|
+
const edgesForValidation = useMemo(() => {
|
|
93
|
+
if (isContextMode(options)) {
|
|
94
|
+
// In context mode, use the provided edges with IDs
|
|
95
|
+
return options.existingEdges.map((e) => ({
|
|
96
|
+
id: e.id,
|
|
97
|
+
source: e.source,
|
|
98
|
+
target: e.target,
|
|
99
|
+
sourcePort: e.sourcePort,
|
|
100
|
+
targetPort: e.targetPort,
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
return options.edges.map((edge) => ({
|
|
105
|
+
id: edge.id,
|
|
106
|
+
source: edge.source,
|
|
107
|
+
target: edge.target,
|
|
108
|
+
sourcePort: edge.sourceHandle || undefined,
|
|
109
|
+
targetPort: edge.targetHandle || undefined,
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
}, [options]);
|
|
113
|
+
// Compute compatibility for all edges
|
|
114
|
+
const edgeCompatibility = useMemo(() => {
|
|
115
|
+
return getEdgeCompatibility(edgesForValidation, context);
|
|
116
|
+
}, [edgesForValidation, context]);
|
|
117
|
+
// Build a map for quick lookup
|
|
118
|
+
const compatibilityMap = useMemo(() => {
|
|
119
|
+
const map = new Map();
|
|
120
|
+
edgeCompatibility.forEach((ec) => map.set(ec.edgeId, ec));
|
|
121
|
+
return map;
|
|
122
|
+
}, [edgeCompatibility]);
|
|
123
|
+
// Check a proposed connection (for drag validation).
|
|
124
|
+
const checkConnection = useCallback((sourceId, targetId, sourcePort, targetPort) => {
|
|
125
|
+
const exists = context.existingEdges.some((e) => e.source === sourceId && e.target === targetId);
|
|
126
|
+
if (exists) {
|
|
127
|
+
return {
|
|
128
|
+
valid: false,
|
|
129
|
+
hasWarning: false,
|
|
130
|
+
reason: 'constraint-violation',
|
|
131
|
+
message: 'This connection already exists',
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
return validateConnection({
|
|
135
|
+
sourceNodeId: sourceId,
|
|
136
|
+
targetNodeId: targetId,
|
|
137
|
+
sourcePortId: sourcePort,
|
|
138
|
+
targetPortId: targetPort,
|
|
139
|
+
}, context);
|
|
140
|
+
}, [context]);
|
|
141
|
+
// Get list of incompatible edge IDs
|
|
142
|
+
const getIncompatibleEdgeIds = useCallback(() => {
|
|
143
|
+
return edgeCompatibility
|
|
144
|
+
.filter((ec) => ec.status === 'incompatible')
|
|
145
|
+
.map((ec) => ec.edgeId);
|
|
146
|
+
}, [edgeCompatibility]);
|
|
147
|
+
// Get list of edges with warnings
|
|
148
|
+
const getWarningEdgeIds = useCallback(() => {
|
|
149
|
+
return edgeCompatibility
|
|
150
|
+
.filter((ec) => ec.status === 'warning')
|
|
151
|
+
.map((ec) => ec.edgeId);
|
|
152
|
+
}, [edgeCompatibility]);
|
|
153
|
+
// Get status for a specific edge
|
|
154
|
+
const getEdgeStatus = useCallback((edgeId) => {
|
|
155
|
+
return compatibilityMap.get(edgeId)?.status;
|
|
156
|
+
}, [compatibilityMap]);
|
|
157
|
+
// Get validation result for a specific edge
|
|
158
|
+
const getEdgeValidation = useCallback((edgeId) => {
|
|
159
|
+
return compatibilityMap.get(edgeId)?.validation;
|
|
160
|
+
}, [compatibilityMap]);
|
|
161
|
+
return {
|
|
162
|
+
edgeCompatibility,
|
|
163
|
+
checkConnection,
|
|
164
|
+
getIncompatibleEdgeIds,
|
|
165
|
+
getWarningEdgeIds,
|
|
166
|
+
getEdgeStatus,
|
|
167
|
+
getEdgeValidation,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=useEdgeCompatibility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEdgeCompatibility.js","sourceRoot":"","sources":["../../src/compatibility/useEdgeCompatibility.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAyCnF;;GAEG;AACH,SAAS,aAAa,CAAC,OAAoC;IACzD,OAAO,UAAU,IAAI,OAAO,IAAI,eAAe,IAAI,OAAO,CAAC;AAC7D,CAAC;AAoBD;;GAEG;AACH,SAAS,eAAe,CAAC,IAAe;IACtC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;IACvB,OAAO;QACL,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,QAAQ,EAAG,IAAI,CAAC,QAA+B,IAAI,IAAI,CAAC,QAAQ,IAAI,SAAS;QAC7E,OAAO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CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC,EAAE,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAExB,kCAAkC;IAClC,MAAM,iBAAiB,GAAG,WAAW,CAAC,GAAa,EAAE;QACnD,OAAO,iBAAiB;aACrB,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,MAAM,KAAK,SAAS,CAAC;aACvC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC,EAAE,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAExB,iCAAiC;IACjC,MAAM,aAAa,GAAG,WAAW,CAC/B,CAAC,MAAc,EAAuC,EAAE;QACtD,OAAO,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAC9C,CAAC,EACD,CAAC,gBAAgB,CAAC,CACnB,CAAC;IAEF,4CAA4C;IAC5C,MAAM,iBAAiB,GAAG,WAAW,CACnC,CAAC,MAAc,EAAoC,EAAE;QACnD,OAAO,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC;IAClD,CAAC,EACD,CAAC,gBAAgB,CAAC,CACnB,CAAC;IAEF,OAAO;QACL,iBAAiB;QACjB,eAAe;QACf,sBAAsB;QACtB,iBAAiB;QACjB,aAAa;QACb,iBAAiB;KAClB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connection Validation Utilities (CORAL-REQ-010)
|
|
3
|
+
*
|
|
4
|
+
* Validates connections against notation rules and provides
|
|
5
|
+
* compatibility information for visual feedback.
|
|
6
|
+
*/
|
|
7
|
+
import type { ConnectionInfo, ConnectionValidation, ConnectionValidationContext, EdgeCompatibility } from '../types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Check if port directions are compatible
|
|
10
|
+
*
|
|
11
|
+
* @param sourceDirection - Direction of source port (in/out/inout)
|
|
12
|
+
* @param targetDirection - Direction of target port (in/out/inout)
|
|
13
|
+
*/
|
|
14
|
+
export declare function checkPortDirection(sourceDirection: 'in' | 'out' | 'inout', targetDirection: 'in' | 'out' | 'inout'): ConnectionValidation;
|
|
15
|
+
/**
|
|
16
|
+
* Check if adding a connection would exceed max connections
|
|
17
|
+
*
|
|
18
|
+
* @param nodeId - Node ID to check
|
|
19
|
+
* @param portId - Port ID (optional)
|
|
20
|
+
* @param maxConnections - Maximum allowed connections (undefined = unlimited)
|
|
21
|
+
* @param existingEdges - Current edges in the diagram
|
|
22
|
+
* @param checkAs - Check as 'source' (outgoing) or 'target' (incoming)
|
|
23
|
+
*/
|
|
24
|
+
export declare function checkMaxConnections(nodeId: string, portId: string | undefined, maxConnections: number | undefined, existingEdges: Array<{
|
|
25
|
+
source: string;
|
|
26
|
+
target: string;
|
|
27
|
+
sourcePort?: string;
|
|
28
|
+
targetPort?: string;
|
|
29
|
+
}>, checkAs: 'source' | 'target'): ConnectionValidation;
|
|
30
|
+
/**
|
|
31
|
+
* Validate a connection against notation rules
|
|
32
|
+
*
|
|
33
|
+
* @param connection - The connection to validate
|
|
34
|
+
* @param context - Validation context with notation and node info
|
|
35
|
+
* @returns Validation result with compatibility status and message
|
|
36
|
+
*/
|
|
37
|
+
export declare function validateConnection(connection: ConnectionInfo, context: ConnectionValidationContext): ConnectionValidation;
|
|
38
|
+
/**
|
|
39
|
+
* Get compatibility status for multiple edges
|
|
40
|
+
*
|
|
41
|
+
* When validating existing edges, we exclude the edge being validated from
|
|
42
|
+
* the existingEdges count. This prevents false positives where an edge at
|
|
43
|
+
* the maxConnections limit would fail validation because it counts itself.
|
|
44
|
+
*
|
|
45
|
+
* @param edges - Edges to check
|
|
46
|
+
* @param context - Validation context
|
|
47
|
+
* @returns Array of edge compatibility info
|
|
48
|
+
*/
|
|
49
|
+
export declare function getEdgeCompatibility(edges: Array<{
|
|
50
|
+
id: string;
|
|
51
|
+
source: string;
|
|
52
|
+
target: string;
|
|
53
|
+
sourcePort?: string;
|
|
54
|
+
targetPort?: string;
|
|
55
|
+
}>, context: ConnectionValidationContext): EdgeCompatibility[];
|
|
56
|
+
//# sourceMappingURL=validateConnection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateConnection.d.ts","sourceRoot":"","sources":["../../src/compatibility/validateConnection.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,2BAA2B,EAC3B,iBAAiB,EAGlB,MAAM,aAAa,CAAC;AASrB;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,eAAe,EAAE,IAAI,GAAG,KAAK,GAAG,OAAO,EACvC,eAAe,EAAE,IAAI,GAAG,KAAK,GAAG,OAAO,GACtC,oBAAoB,CAsBtB;AAMD;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,aAAa,EAAE,KAAK,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,EAClG,OAAO,EAAE,QAAQ,GAAG,QAAQ,GAC3B,oBAAoB,CAgCtB;AA0PD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,cAAc,EAC1B,OAAO,EAAE,2BAA2B,GACnC,oBAAoB,CA2EtB;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,EACtG,OAAO,EAAE,2BAA2B,GACnC,iBAAiB,EAAE,CAsCrB"}
|