@principal-ai/principal-view-react 0.13.10 → 0.13.12
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/dist/components/GraphRenderer.d.ts +14 -0
- package/dist/components/GraphRenderer.d.ts.map +1 -1
- package/dist/components/GraphRenderer.js +31 -12
- package/dist/components/GraphRenderer.js.map +1 -1
- package/dist/components/MultiCanvasRenderer.d.ts +75 -0
- package/dist/components/MultiCanvasRenderer.d.ts.map +1 -0
- package/dist/components/MultiCanvasRenderer.js +207 -0
- package/dist/components/MultiCanvasRenderer.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/canvasBounds.d.ts +29 -0
- package/dist/utils/canvasBounds.d.ts.map +1 -0
- package/dist/utils/canvasBounds.js +56 -0
- package/dist/utils/canvasBounds.js.map +1 -0
- package/package.json +1 -1
- package/src/components/GraphRenderer.tsx +54 -10
- package/src/components/MultiCanvasRenderer.tsx +299 -0
- package/src/index.ts +9 -0
- package/src/stories/MultiCanvasRenderer.stories.tsx +370 -0
- package/src/utils/canvasBounds.ts +91 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, useCallback, useRef, forwardRef } from 'react';
|
|
3
|
+
import { GraphRenderer } from './GraphRenderer';
|
|
4
|
+
// ============================================================================
|
|
5
|
+
// Canvas Merging Utilities
|
|
6
|
+
// ============================================================================
|
|
7
|
+
const DEFAULT_NODE_WIDTH = 200;
|
|
8
|
+
const DEFAULT_NODE_HEIGHT = 100;
|
|
9
|
+
const GROUP_PADDING = 40;
|
|
10
|
+
/**
|
|
11
|
+
* Create a prefixed node ID to avoid collisions between canvases
|
|
12
|
+
*/
|
|
13
|
+
function prefixNodeId(canvasId, nodeId) {
|
|
14
|
+
return `${canvasId}:${nodeId}`;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Calculate the bounding box of nodes in a canvas (relative to canvas origin)
|
|
18
|
+
*/
|
|
19
|
+
function calculateCanvasBounds(canvas) {
|
|
20
|
+
if (!canvas.nodes || canvas.nodes.length === 0) {
|
|
21
|
+
return { minX: 0, minY: 0, maxX: DEFAULT_NODE_WIDTH, maxY: DEFAULT_NODE_HEIGHT };
|
|
22
|
+
}
|
|
23
|
+
let minX = Infinity;
|
|
24
|
+
let minY = Infinity;
|
|
25
|
+
let maxX = -Infinity;
|
|
26
|
+
let maxY = -Infinity;
|
|
27
|
+
for (const node of canvas.nodes) {
|
|
28
|
+
const x = node.x ?? 0;
|
|
29
|
+
const y = node.y ?? 0;
|
|
30
|
+
const width = node.width ?? DEFAULT_NODE_WIDTH;
|
|
31
|
+
const height = node.height ?? DEFAULT_NODE_HEIGHT;
|
|
32
|
+
minX = Math.min(minX, x);
|
|
33
|
+
minY = Math.min(minY, y);
|
|
34
|
+
maxX = Math.max(maxX, x + width);
|
|
35
|
+
maxY = Math.max(maxY, y + height);
|
|
36
|
+
}
|
|
37
|
+
return { minX, minY, maxX, maxY };
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Merge multiple canvases into a single canvas with position offsets applied.
|
|
41
|
+
* Each canvas gets a group node border with its name as a label.
|
|
42
|
+
* Node IDs are prefixed with canvasId to avoid collisions (format: "canvasId:nodeId").
|
|
43
|
+
* Original IDs can be recovered using parseNodeId().
|
|
44
|
+
*/
|
|
45
|
+
export function mergeCanvases(placements, options = {}) {
|
|
46
|
+
const { showGroups = true } = options;
|
|
47
|
+
const groupNodes = [];
|
|
48
|
+
const mergedNodes = [];
|
|
49
|
+
const mergedEdges = [];
|
|
50
|
+
for (const placement of placements) {
|
|
51
|
+
const { canvasId, canvas, position, label } = placement;
|
|
52
|
+
// Calculate bounds for this canvas to create a group node
|
|
53
|
+
if (showGroups && canvas.nodes && canvas.nodes.length > 0) {
|
|
54
|
+
const bounds = calculateCanvasBounds(canvas);
|
|
55
|
+
const groupNode = {
|
|
56
|
+
id: `${canvasId}:__group__`,
|
|
57
|
+
type: 'group',
|
|
58
|
+
label: label ?? canvas.pv?.name ?? canvasId,
|
|
59
|
+
x: position.x + bounds.minX - GROUP_PADDING,
|
|
60
|
+
y: position.y + bounds.minY - GROUP_PADDING,
|
|
61
|
+
width: bounds.maxX - bounds.minX + GROUP_PADDING * 2,
|
|
62
|
+
height: bounds.maxY - bounds.minY + GROUP_PADDING * 2,
|
|
63
|
+
};
|
|
64
|
+
groupNodes.push(groupNode);
|
|
65
|
+
}
|
|
66
|
+
// Process nodes - apply position offset and prefix IDs
|
|
67
|
+
if (canvas.nodes) {
|
|
68
|
+
for (const node of canvas.nodes) {
|
|
69
|
+
const mergedNode = {
|
|
70
|
+
...node,
|
|
71
|
+
id: prefixNodeId(canvasId, node.id),
|
|
72
|
+
x: (node.x ?? 0) + position.x,
|
|
73
|
+
y: (node.y ?? 0) + position.y,
|
|
74
|
+
};
|
|
75
|
+
mergedNodes.push(mergedNode);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Process edges - update node references with prefixed IDs
|
|
79
|
+
if (canvas.edges) {
|
|
80
|
+
for (const edge of canvas.edges) {
|
|
81
|
+
const mergedEdge = {
|
|
82
|
+
...edge,
|
|
83
|
+
id: prefixNodeId(canvasId, edge.id),
|
|
84
|
+
fromNode: prefixNodeId(canvasId, edge.fromNode),
|
|
85
|
+
toNode: prefixNodeId(canvasId, edge.toNode),
|
|
86
|
+
};
|
|
87
|
+
mergedEdges.push(mergedEdge);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Create merged canvas - group nodes first so they render behind
|
|
92
|
+
const mergedCanvas = {
|
|
93
|
+
nodes: [...groupNodes, ...mergedNodes],
|
|
94
|
+
edges: mergedEdges,
|
|
95
|
+
pv: {
|
|
96
|
+
version: '1.0.0',
|
|
97
|
+
name: 'Multi-Canvas View',
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
return mergedCanvas;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Extract the original canvas ID and node ID from a merged node ID
|
|
104
|
+
*/
|
|
105
|
+
export function parseNodeId(mergedNodeId) {
|
|
106
|
+
const colonIndex = mergedNodeId.indexOf(':');
|
|
107
|
+
if (colonIndex === -1)
|
|
108
|
+
return null;
|
|
109
|
+
return {
|
|
110
|
+
canvasId: mergedNodeId.substring(0, colonIndex),
|
|
111
|
+
nodeId: mergedNodeId.substring(colonIndex + 1),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
// ============================================================================
|
|
115
|
+
// MultiCanvasRenderer Component
|
|
116
|
+
// ============================================================================
|
|
117
|
+
/**
|
|
118
|
+
* Renders multiple canvases merged into a single graph view.
|
|
119
|
+
*
|
|
120
|
+
* Each canvas is positioned at its specified offset, and all nodes/edges
|
|
121
|
+
* are combined into a unified viewport. Node IDs are prefixed with their
|
|
122
|
+
* source canvas ID to avoid collisions (format: "canvasId:nodeId").
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```tsx
|
|
126
|
+
* <MultiCanvasRenderer
|
|
127
|
+
* layout={{
|
|
128
|
+
* placements: [
|
|
129
|
+
* { canvasId: 'auth', canvas: authCanvas, position: { x: 0, y: 0 } },
|
|
130
|
+
* { canvasId: 'data', canvas: dataCanvas, position: { x: 600, y: 0 } },
|
|
131
|
+
* ],
|
|
132
|
+
* }}
|
|
133
|
+
* showControls
|
|
134
|
+
* />
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export const MultiCanvasRenderer = forwardRef(function MultiCanvasRenderer({ layout, onLayoutChange, showGroups = true, ...graphRendererProps }, ref) {
|
|
138
|
+
// Track group positions at the start of drag to calculate deltas
|
|
139
|
+
const groupPositionsRef = useRef(new Map());
|
|
140
|
+
// Merge all canvases into a single canvas
|
|
141
|
+
const mergedCanvas = useMemo(() => mergeCanvases(layout.placements, { showGroups }), [layout.placements, showGroups]);
|
|
142
|
+
// Calculate group node IDs for dragging
|
|
143
|
+
const draggableNodeIds = useMemo(() => {
|
|
144
|
+
if (!showGroups)
|
|
145
|
+
return undefined;
|
|
146
|
+
const ids = new Set();
|
|
147
|
+
for (const placement of layout.placements) {
|
|
148
|
+
if (placement.canvas.nodes && placement.canvas.nodes.length > 0) {
|
|
149
|
+
ids.add(`${placement.canvasId}:__group__`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
console.log('[MultiCanvasRenderer] draggableNodeIds:', [...ids]);
|
|
153
|
+
return ids.size > 0 ? ids : undefined;
|
|
154
|
+
}, [layout.placements, showGroups]);
|
|
155
|
+
// Store initial group positions whenever layout changes
|
|
156
|
+
useMemo(() => {
|
|
157
|
+
groupPositionsRef.current.clear();
|
|
158
|
+
for (const placement of layout.placements) {
|
|
159
|
+
if (placement.canvas.nodes && placement.canvas.nodes.length > 0) {
|
|
160
|
+
const bounds = calculateCanvasBounds(placement.canvas);
|
|
161
|
+
// Group position = placement position + bounds offset - padding
|
|
162
|
+
groupPositionsRef.current.set(`${placement.canvasId}:__group__`, {
|
|
163
|
+
x: placement.position.x + bounds.minX - GROUP_PADDING,
|
|
164
|
+
y: placement.position.y + bounds.minY - GROUP_PADDING,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}, [layout.placements]);
|
|
169
|
+
// Handle group drag to update layout positions
|
|
170
|
+
const handleNodeDragStop = useCallback((nodeId, newPosition) => {
|
|
171
|
+
// Only handle group nodes
|
|
172
|
+
if (!nodeId.endsWith(':__group__'))
|
|
173
|
+
return;
|
|
174
|
+
if (!onLayoutChange)
|
|
175
|
+
return;
|
|
176
|
+
const parsed = parseNodeId(nodeId);
|
|
177
|
+
if (!parsed)
|
|
178
|
+
return;
|
|
179
|
+
const { canvasId } = parsed;
|
|
180
|
+
// Get the original group position
|
|
181
|
+
const originalGroupPos = groupPositionsRef.current.get(nodeId);
|
|
182
|
+
if (!originalGroupPos)
|
|
183
|
+
return;
|
|
184
|
+
// Calculate delta
|
|
185
|
+
const deltaX = newPosition.x - originalGroupPos.x;
|
|
186
|
+
const deltaY = newPosition.y - originalGroupPos.y;
|
|
187
|
+
// Skip if no significant movement
|
|
188
|
+
if (Math.abs(deltaX) < 1 && Math.abs(deltaY) < 1)
|
|
189
|
+
return;
|
|
190
|
+
// Create updated layout with new position for this canvas
|
|
191
|
+
const updatedPlacements = layout.placements.map((placement) => {
|
|
192
|
+
if (placement.canvasId === canvasId) {
|
|
193
|
+
return {
|
|
194
|
+
...placement,
|
|
195
|
+
position: {
|
|
196
|
+
x: placement.position.x + deltaX,
|
|
197
|
+
y: placement.position.y + deltaY,
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
return placement;
|
|
202
|
+
});
|
|
203
|
+
onLayoutChange({ placements: updatedPlacements });
|
|
204
|
+
}, [layout.placements, onLayoutChange]);
|
|
205
|
+
return (_jsx(GraphRenderer, { ref: ref, canvas: mergedCanvas, editable: false, draggableNodeIds: draggableNodeIds, onNodeDragStop: handleNodeDragStop, ...graphRendererProps }));
|
|
206
|
+
});
|
|
207
|
+
//# sourceMappingURL=MultiCanvasRenderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultiCanvasRenderer.js","sourceRoot":"","sources":["../../src/components/MultiCanvasRenderer.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEjE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AA0ChD,+EAA+E;AAC/E,2BAA2B;AAC3B,+EAA+E;AAE/E,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAC/B,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAChC,MAAM,aAAa,GAAG,EAAE,CAAC;AAEzB;;GAEG;AACH,SAAS,YAAY,CAAC,QAAgB,EAAE,MAAc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BAAkB;QAClB,MAAM,MAAM,GAAG,WAAW,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC;QAClD,MAAM,MAAM,GAAG,WAAW,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC;QAElD,kCAAkC;QAClC,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC;YAAE,OAAO;QAEzD,0DAA0D;QAC1D,MAAM,iBAAiB,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE;YAC5D,IAAI,SAAS,CAAC,QAAQ,KAAK,QAAQ,EAAE;gBACnC,OAAO;oBACL,GAAG,SAAS;oBACZ,QAAQ,EAAE;wBACR,CAAC,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,GAAG,MAAM;wBAChC,CAAC,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,GAAG,MAAM;qBACjC;iBACF,CAAC;aACH;YACD,OAAO,SAAS,CAAC;QACnB,CAAC,CAAC,CAAC;QAEH,cAAc,CAAC,EAAE,UAAU,EAAE,iBAAiB,EAAE,CAAC,CAAC;IACpD,CAAC,EACD,CAAC,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,CACpC,CAAC;IAEF,OAAO,CACL,KAAC,aAAa,IACZ,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,YAAY,EACpB,QAAQ,EAAE,KAAK,EACf,gBAAgB,EAAE,gBAAgB,EAClC,cAAc,EAAE,kBAAkB,KAC9B,kBAAkB,GACtB,CACH,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
export type { GraphConfiguration, GraphEvent, GraphMetrics, Violation, Warning, ValidationResult, EventStream, NodeTypeDefinition, EdgeTypeDefinition, ConnectionRule, NodeState, EdgeState, ConfigurationFile, ConfigurationLoadResult, ComponentLibrary, LibraryNodeComponent, LibraryEdgeComponent, } from '@principal-ai/principal-view-core';
|
|
9
9
|
export { GraphRenderer } from './components/GraphRenderer';
|
|
10
10
|
export type { GraphRendererProps, GraphRendererHandle, NodePositionChange, PendingChanges, } from './components/GraphRenderer';
|
|
11
|
+
export { MultiCanvasRenderer, mergeCanvases, parseNodeId } from './components/MultiCanvasRenderer';
|
|
12
|
+
export type { MultiCanvasRendererProps, MultiCanvasLayout, CanvasPlacement, } from './components/MultiCanvasRenderer';
|
|
11
13
|
export { ConfigurationSelector } from './components/ConfigurationSelector';
|
|
12
14
|
export type { ConfigurationSelectorProps } from './components/ConfigurationSelector';
|
|
13
15
|
export { GenericNode } from './nodes/GenericNode';
|
|
@@ -25,4 +27,6 @@ export type { EdgeStateWithHandles } from './utils/graphConverter';
|
|
|
25
27
|
export { Icon, resolveIcon } from './utils/iconResolver';
|
|
26
28
|
export type { IconProps } from './utils/iconResolver';
|
|
27
29
|
export { swapGraphOrientation, swapNodePositions, swapEdgeSides, } from './utils/orientationUtils';
|
|
30
|
+
export { getCanvasBounds, getCanvasDisplaySize } from './utils/canvasBounds';
|
|
31
|
+
export type { CanvasBounds } from './utils/canvasBounds';
|
|
28
32
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,YAAY,EACV,kBAAkB,EAClB,UAAU,EACV,YAAY,EACZ,SAAS,EACT,OAAO,EACP,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAClB,cAAc,EACd,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,uBAAuB,EAEvB,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,mCAAmC,CAAC;AAG3C,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC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O,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACzD,YAAY,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,aAAa,GACd,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC7E,YAAY,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
// Export components
|
|
9
9
|
export { GraphRenderer } from './components/GraphRenderer';
|
|
10
|
+
export { MultiCanvasRenderer, mergeCanvases, parseNodeId } from './components/MultiCanvasRenderer';
|
|
10
11
|
export { ConfigurationSelector } from './components/ConfigurationSelector';
|
|
11
12
|
// Export node/edge renderers
|
|
12
13
|
export { GenericNode } from './nodes/GenericNode';
|
|
@@ -19,4 +20,5 @@ export { NodeTooltip } from './components/NodeTooltip';
|
|
|
19
20
|
export { convertToXYFlowNodes, convertToXYFlowEdges, } from './utils/graphConverter';
|
|
20
21
|
export { Icon, resolveIcon } from './utils/iconResolver';
|
|
21
22
|
export { swapGraphOrientation, swapNodePositions, swapEdgeSides, } from './utils/orientationUtils';
|
|
23
|
+
export { getCanvasBounds, getCanvasDisplaySize } from './utils/canvasBounds';
|
|
22
24
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAwBH,oBAAoB;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAQ3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAG3E,6BAA6B;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlD,OAAO,EA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;AAClC,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ExtendedCanvas } from '@principal-ai/principal-view-core';
|
|
2
|
+
export interface CanvasBounds {
|
|
3
|
+
minX: number;
|
|
4
|
+
minY: number;
|
|
5
|
+
maxX: number;
|
|
6
|
+
maxY: number;
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Calculate the bounding box of all nodes in a canvas.
|
|
12
|
+
* Returns the min/max coordinates and total dimensions.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getCanvasBounds(canvas: ExtendedCanvas): CanvasBounds;
|
|
15
|
+
/**
|
|
16
|
+
* Calculate a recommended display size for a canvas cell.
|
|
17
|
+
* Adds padding and enforces minimum dimensions.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getCanvasDisplaySize(canvas: ExtendedCanvas, options?: {
|
|
20
|
+
padding?: number;
|
|
21
|
+
minWidth?: number;
|
|
22
|
+
minHeight?: number;
|
|
23
|
+
maxWidth?: number;
|
|
24
|
+
maxHeight?: number;
|
|
25
|
+
}): {
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=canvasBounds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canvasBounds.d.ts","sourceRoot":"","sources":["../../src/utils/canvasBounds.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAExE,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAKD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,cAAc,GAAG,YAAY,CAqCpE;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,cAAc,EACtB,OAAO,GAAE;IACP,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACf,GACL;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAoBnC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const DEFAULT_NODE_WIDTH = 200;
|
|
2
|
+
const DEFAULT_NODE_HEIGHT = 100;
|
|
3
|
+
/**
|
|
4
|
+
* Calculate the bounding box of all nodes in a canvas.
|
|
5
|
+
* Returns the min/max coordinates and total dimensions.
|
|
6
|
+
*/
|
|
7
|
+
export function getCanvasBounds(canvas) {
|
|
8
|
+
if (!canvas.nodes || canvas.nodes.length === 0) {
|
|
9
|
+
return {
|
|
10
|
+
minX: 0,
|
|
11
|
+
minY: 0,
|
|
12
|
+
maxX: DEFAULT_NODE_WIDTH,
|
|
13
|
+
maxY: DEFAULT_NODE_HEIGHT,
|
|
14
|
+
width: DEFAULT_NODE_WIDTH,
|
|
15
|
+
height: DEFAULT_NODE_HEIGHT,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
let minX = Infinity;
|
|
19
|
+
let minY = Infinity;
|
|
20
|
+
let maxX = -Infinity;
|
|
21
|
+
let maxY = -Infinity;
|
|
22
|
+
for (const node of canvas.nodes) {
|
|
23
|
+
const x = node.x ?? 0;
|
|
24
|
+
const y = node.y ?? 0;
|
|
25
|
+
const width = node.width ?? DEFAULT_NODE_WIDTH;
|
|
26
|
+
const height = node.height ?? DEFAULT_NODE_HEIGHT;
|
|
27
|
+
minX = Math.min(minX, x);
|
|
28
|
+
minY = Math.min(minY, y);
|
|
29
|
+
maxX = Math.max(maxX, x + width);
|
|
30
|
+
maxY = Math.max(maxY, y + height);
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
minX,
|
|
34
|
+
minY,
|
|
35
|
+
maxX,
|
|
36
|
+
maxY,
|
|
37
|
+
width: maxX - minX,
|
|
38
|
+
height: maxY - minY,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Calculate a recommended display size for a canvas cell.
|
|
43
|
+
* Adds padding and enforces minimum dimensions.
|
|
44
|
+
*/
|
|
45
|
+
export function getCanvasDisplaySize(canvas, options = {}) {
|
|
46
|
+
const { padding = 100, minWidth = 300, minHeight = 200, maxWidth = 1200, maxHeight = 800, } = options;
|
|
47
|
+
const bounds = getCanvasBounds(canvas);
|
|
48
|
+
// Add padding to content dimensions
|
|
49
|
+
const contentWidth = bounds.width + padding * 2;
|
|
50
|
+
const contentHeight = bounds.height + padding * 2;
|
|
51
|
+
// Clamp to min/max
|
|
52
|
+
const width = Math.min(maxWidth, Math.max(minWidth, contentWidth));
|
|
53
|
+
const height = Math.min(maxHeight, Math.max(minHeight, contentHeight));
|
|
54
|
+
return { width, height };
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=canvasBounds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canvasBounds.js","sourceRoot":"","sources":["../../src/utils/canvasBounds.ts"],"names":[],"mappings":"AAWA,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAC/B,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEhC;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,MAAsB;IACpD,IAAI,CAAC,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;QAC9C,OAAO;YACL,IAAI,EAAE,CAAC;YACP,IAAI,EAAE,CAAC;YACP,IAAI,EAAE,kBAA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AG,GAChB,GAAG,OAAO,CAAC;IAEZ,MAAM,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;IAEvC,oCAAoC;IACpC,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK,GAAG,OAAO,GAAG,CAAC,CAAC;IAChD,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,GAAG,OAAO,GAAG,CAAC,CAAC;IAElD,mBAAmB;IACnB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC;IACnE,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC;IAEvE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAC3B,CAAC"}
|
package/package.json
CHANGED
|
@@ -213,6 +213,19 @@ interface GraphRendererBaseProps {
|
|
|
213
213
|
*/
|
|
214
214
|
fitViewPadding?: number;
|
|
215
215
|
|
|
216
|
+
/**
|
|
217
|
+
* Set of node IDs that should be draggable even when editable=false.
|
|
218
|
+
* Useful for allowing specific nodes (like group containers) to be moved
|
|
219
|
+
* while keeping other nodes locked in place.
|
|
220
|
+
*/
|
|
221
|
+
draggableNodeIds?: Set<string>;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Callback fired when a node drag operation completes.
|
|
225
|
+
* Receives the node ID and its new position.
|
|
226
|
+
*/
|
|
227
|
+
onNodeDragStop?: (nodeId: string, position: { x: number; y: number }) => void;
|
|
228
|
+
|
|
216
229
|
}
|
|
217
230
|
|
|
218
231
|
/** GraphRenderer props - canvas format only */
|
|
@@ -440,6 +453,8 @@ interface GraphRendererInnerProps {
|
|
|
440
453
|
onNodeClick?: (nodeId: string, event: React.MouseEvent) => void;
|
|
441
454
|
fitViewToNodeIds?: string[] | null;
|
|
442
455
|
fitViewPadding?: number;
|
|
456
|
+
draggableNodeIds?: Set<string>;
|
|
457
|
+
onNodeDragStop?: (nodeId: string, position: { x: number; y: number }) => void;
|
|
443
458
|
}
|
|
444
459
|
|
|
445
460
|
/**
|
|
@@ -470,6 +485,8 @@ const GraphRendererInner: React.FC<GraphRendererInnerProps> = ({
|
|
|
470
485
|
onNodeClick: onNodeClickProp,
|
|
471
486
|
fitViewToNodeIds,
|
|
472
487
|
fitViewPadding = 0.2,
|
|
488
|
+
draggableNodeIds,
|
|
489
|
+
onNodeDragStop: onNodeDragStopProp,
|
|
473
490
|
}) => {
|
|
474
491
|
const { fitView, fitBounds, getNodes } = useReactFlow();
|
|
475
492
|
const updateNodeInternals = useUpdateNodeInternals();
|
|
@@ -1319,10 +1336,20 @@ const GraphRendererInner: React.FC<GraphRendererInnerProps> = ({
|
|
|
1319
1336
|
const animation = animationState.nodeAnimations[node.id];
|
|
1320
1337
|
// Apply any pending position changes
|
|
1321
1338
|
const pendingPosition = editStateRef.current.positionChanges.get(node.id);
|
|
1339
|
+
// Allow specific nodes to be draggable even when not in edit mode
|
|
1340
|
+
const isDraggable = editable || draggableNodeIds?.has(node.id);
|
|
1341
|
+
if (isDraggable && !editable) {
|
|
1342
|
+
console.log('[GraphRenderer] Setting draggable=true for node:', node.id);
|
|
1343
|
+
}
|
|
1344
|
+
// When draggableNodeIds is provided, we need to explicitly control each node's draggability
|
|
1345
|
+
// because nodesDraggable will be true to allow the specific nodes to drag
|
|
1346
|
+
const hasDraggableNodeIds = draggableNodeIds && draggableNodeIds.size > 0;
|
|
1322
1347
|
return {
|
|
1323
1348
|
...node,
|
|
1324
1349
|
...(pendingPosition ? { position: pendingPosition } : {}),
|
|
1325
1350
|
selected: selectedNodeIds.has(node.id),
|
|
1351
|
+
// Explicitly set draggable for each node when using draggableNodeIds
|
|
1352
|
+
draggable: hasDraggableNodeIds ? isDraggable : (editable || false),
|
|
1326
1353
|
data: {
|
|
1327
1354
|
...node.data,
|
|
1328
1355
|
editable,
|
|
@@ -1340,7 +1367,7 @@ const GraphRendererInner: React.FC<GraphRendererInnerProps> = ({
|
|
|
1340
1367
|
} as CustomNodeData,
|
|
1341
1368
|
};
|
|
1342
1369
|
});
|
|
1343
|
-
}, [localNodes, configuration, violations, animationState.nodeAnimations, editable, showTooltips, highlightedNodeId, activeNodeIds, editStateRef, shiftKeyPressed, selectedNodeIds, hiddenNodeIds]);
|
|
1370
|
+
}, [localNodes, configuration, violations, animationState.nodeAnimations, editable, showTooltips, highlightedNodeId, activeNodeIds, editStateRef, shiftKeyPressed, selectedNodeIds, hiddenNodeIds, draggableNodeIds]);
|
|
1344
1371
|
|
|
1345
1372
|
const baseNodesKey = useMemo(() => {
|
|
1346
1373
|
return nodes
|
|
@@ -1407,18 +1434,31 @@ const GraphRendererInner: React.FC<GraphRendererInnerProps> = ({
|
|
|
1407
1434
|
// Handle node drag to show alignment guides
|
|
1408
1435
|
const handleNodeDrag = useCallback(
|
|
1409
1436
|
(_event: React.MouseEvent, node: Node) => {
|
|
1410
|
-
if
|
|
1437
|
+
// Allow dragging if editable OR if this node is in draggableNodeIds
|
|
1438
|
+
const canDrag = editable || draggableNodeIds?.has(node.id);
|
|
1439
|
+
if (!canDrag) return;
|
|
1411
1440
|
|
|
1412
|
-
|
|
1413
|
-
|
|
1441
|
+
// Only show alignment guides in full edit mode
|
|
1442
|
+
if (editable) {
|
|
1443
|
+
const guides = detectAlignmentGuides(node.id, xyflowNodes);
|
|
1444
|
+
setAlignmentGuides(guides);
|
|
1445
|
+
}
|
|
1414
1446
|
},
|
|
1415
|
-
[editable, xyflowNodes, detectAlignmentGuides]
|
|
1447
|
+
[editable, draggableNodeIds, xyflowNodes, detectAlignmentGuides]
|
|
1416
1448
|
);
|
|
1417
1449
|
|
|
1418
|
-
// Clear guides when drag ends
|
|
1419
|
-
const handleNodeDragStop = useCallback(
|
|
1420
|
-
|
|
1421
|
-
|
|
1450
|
+
// Clear guides when drag ends and notify parent
|
|
1451
|
+
const handleNodeDragStop = useCallback(
|
|
1452
|
+
(_event: React.MouseEvent, node: Node) => {
|
|
1453
|
+
setAlignmentGuides([]);
|
|
1454
|
+
|
|
1455
|
+
// Call the callback if provided (for draggable nodes outside edit mode)
|
|
1456
|
+
if (onNodeDragStopProp && node.position) {
|
|
1457
|
+
onNodeDragStopProp(node.id, node.position);
|
|
1458
|
+
}
|
|
1459
|
+
},
|
|
1460
|
+
[onNodeDragStopProp]
|
|
1461
|
+
);
|
|
1422
1462
|
|
|
1423
1463
|
// Handle node changes (drag and resize events)
|
|
1424
1464
|
const handleNodesChange = useCallback(
|
|
@@ -1674,7 +1714,7 @@ const GraphRendererInner: React.FC<GraphRendererInnerProps> = ({
|
|
|
1674
1714
|
onNodeDrag={handleNodeDrag}
|
|
1675
1715
|
onNodeDragStop={handleNodeDragStop}
|
|
1676
1716
|
proOptions={{ hideAttribution: true }}
|
|
1677
|
-
nodesDraggable={editable}
|
|
1717
|
+
nodesDraggable={editable || (draggableNodeIds && draggableNodeIds.size > 0)}
|
|
1678
1718
|
elementsSelectable={editable}
|
|
1679
1719
|
selectNodesOnDrag={false}
|
|
1680
1720
|
nodesConnectable={editable}
|
|
@@ -2108,6 +2148,8 @@ export const GraphRenderer = forwardRef<GraphRendererHandle, GraphRendererProps>
|
|
|
2108
2148
|
onNodeClick,
|
|
2109
2149
|
fitViewToNodeIds,
|
|
2110
2150
|
fitViewPadding,
|
|
2151
|
+
draggableNodeIds,
|
|
2152
|
+
onNodeDragStop,
|
|
2111
2153
|
} = props;
|
|
2112
2154
|
|
|
2113
2155
|
return (
|
|
@@ -2137,6 +2179,8 @@ export const GraphRenderer = forwardRef<GraphRendererHandle, GraphRendererProps>
|
|
|
2137
2179
|
onNodeClick={onNodeClick}
|
|
2138
2180
|
fitViewToNodeIds={fitViewToNodeIds}
|
|
2139
2181
|
fitViewPadding={fitViewPadding}
|
|
2182
|
+
draggableNodeIds={draggableNodeIds}
|
|
2183
|
+
onNodeDragStop={onNodeDragStop}
|
|
2140
2184
|
/>
|
|
2141
2185
|
</ReactFlowProvider>
|
|
2142
2186
|
</div>
|