@uipath/apollo-react 4.17.0 → 4.18.1

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.
Files changed (71) hide show
  1. package/dist/canvas/components/AddNodePanel/AddNodeManager.cjs +35 -21
  2. package/dist/canvas/components/AddNodePanel/AddNodeManager.d.ts.map +1 -1
  3. package/dist/canvas/components/AddNodePanel/AddNodeManager.helpers.cjs +208 -0
  4. package/dist/canvas/components/AddNodePanel/AddNodeManager.helpers.d.ts +20 -0
  5. package/dist/canvas/components/AddNodePanel/AddNodeManager.helpers.d.ts.map +1 -0
  6. package/dist/canvas/components/AddNodePanel/AddNodeManager.helpers.js +168 -0
  7. package/dist/canvas/components/AddNodePanel/AddNodeManager.js +35 -21
  8. package/dist/canvas/components/AddNodePanel/createAddNodePreview.cjs +34 -4
  9. package/dist/canvas/components/AddNodePanel/createAddNodePreview.d.ts +5 -1
  10. package/dist/canvas/components/AddNodePanel/createAddNodePreview.d.ts.map +1 -1
  11. package/dist/canvas/components/AddNodePanel/createAddNodePreview.js +34 -4
  12. package/dist/canvas/components/AddNodePanel/index.d.ts +1 -1
  13. package/dist/canvas/components/AddNodePanel/index.d.ts.map +1 -1
  14. package/dist/canvas/components/HierarchicalCanvas/HierarchicalCanvas.cjs +23 -1
  15. package/dist/canvas/components/HierarchicalCanvas/HierarchicalCanvas.d.ts.map +1 -1
  16. package/dist/canvas/components/HierarchicalCanvas/HierarchicalCanvas.js +23 -1
  17. package/dist/canvas/components/HierarchicalCanvas/HierarchicalCanvasWithControls.cjs +0 -14
  18. package/dist/canvas/components/HierarchicalCanvas/HierarchicalCanvasWithControls.d.ts.map +1 -1
  19. package/dist/canvas/components/HierarchicalCanvas/HierarchicalCanvasWithControls.js +2 -16
  20. package/dist/canvas/components/LoopNode/LoopNode.cjs +38 -32
  21. package/dist/canvas/components/LoopNode/LoopNode.d.ts.map +1 -1
  22. package/dist/canvas/components/LoopNode/LoopNode.helpers.cjs +33 -42
  23. package/dist/canvas/components/LoopNode/LoopNode.helpers.d.ts +9 -10
  24. package/dist/canvas/components/LoopNode/LoopNode.helpers.d.ts.map +1 -1
  25. package/dist/canvas/components/LoopNode/LoopNode.helpers.js +25 -31
  26. package/dist/canvas/components/LoopNode/LoopNode.js +30 -24
  27. package/dist/canvas/components/LoopNode/LoopNodePreview.cjs +20 -5
  28. package/dist/canvas/components/LoopNode/LoopNodePreview.d.ts.map +1 -1
  29. package/dist/canvas/components/LoopNode/LoopNodePreview.js +20 -5
  30. package/dist/canvas/components/Toolbar/EdgeToolbar/useEdgeToolbarState.cjs +26 -14
  31. package/dist/canvas/components/Toolbar/EdgeToolbar/useEdgeToolbarState.d.ts.map +1 -1
  32. package/dist/canvas/components/Toolbar/EdgeToolbar/useEdgeToolbarState.js +26 -14
  33. package/dist/canvas/constants.cjs +0 -8
  34. package/dist/canvas/constants.d.ts +0 -2
  35. package/dist/canvas/constants.d.ts.map +1 -1
  36. package/dist/canvas/constants.js +1 -3
  37. package/dist/canvas/hooks/useAddNodeOnConnectEnd.cjs +4 -2
  38. package/dist/canvas/hooks/useAddNodeOnConnectEnd.d.ts.map +1 -1
  39. package/dist/canvas/hooks/useAddNodeOnConnectEnd.js +4 -2
  40. package/dist/canvas/storybook-utils/hooks/useCanvasStory.d.ts.map +1 -1
  41. package/dist/canvas/storybook-utils/manifests/node-definitions.d.ts.map +1 -1
  42. package/dist/canvas/storybook-utils/mocks/nodes.d.ts +6 -6
  43. package/dist/canvas/storybook-utils/mocks/nodes.d.ts.map +1 -1
  44. package/dist/canvas/utils/NodeUtils.cjs +41 -13
  45. package/dist/canvas/utils/NodeUtils.d.ts +12 -1
  46. package/dist/canvas/utils/NodeUtils.d.ts.map +1 -1
  47. package/dist/canvas/utils/NodeUtils.js +28 -9
  48. package/dist/canvas/utils/collapse.cjs +3 -3
  49. package/dist/canvas/utils/collapse.d.ts.map +1 -1
  50. package/dist/canvas/utils/collapse.js +1 -1
  51. package/dist/canvas/utils/container.cjs +670 -0
  52. package/dist/canvas/utils/container.d.ts +110 -0
  53. package/dist/canvas/utils/container.d.ts.map +1 -0
  54. package/dist/canvas/utils/container.js +591 -0
  55. package/dist/canvas/utils/createPreviewGraph.cjs +25 -15
  56. package/dist/canvas/utils/createPreviewGraph.d.ts +11 -7
  57. package/dist/canvas/utils/createPreviewGraph.d.ts.map +1 -1
  58. package/dist/canvas/utils/createPreviewGraph.js +25 -15
  59. package/dist/canvas/utils/createPreviewNode.cjs +24 -15
  60. package/dist/canvas/utils/createPreviewNode.d.ts +21 -7
  61. package/dist/canvas/utils/createPreviewNode.d.ts.map +1 -1
  62. package/dist/canvas/utils/createPreviewNode.js +24 -15
  63. package/dist/canvas/utils/index.cjs +29 -22
  64. package/dist/canvas/utils/index.d.ts +1 -0
  65. package/dist/canvas/utils/index.d.ts.map +1 -1
  66. package/dist/canvas/utils/index.js +1 -0
  67. package/package.json +3 -3
  68. package/dist/canvas/components/LoopNode/LoopNode.constants.cjs +0 -56
  69. package/dist/canvas/components/LoopNode/LoopNode.constants.d.ts +0 -7
  70. package/dist/canvas/components/LoopNode/LoopNode.constants.d.ts.map +0 -1
  71. package/dist/canvas/components/LoopNode/LoopNode.constants.js +0 -7
@@ -0,0 +1,591 @@
1
+ import { DEFAULT_NODE_SIZE, DEFAULT_SOURCE_HANDLE_ID, GRID_SPACING, PREVIEW_NODE_ID } from "../constants.js";
2
+ import { clamp, getAbsolutePosition, getNonOverlappingPositionForDirection, snapToGrid, snapUpToGrid } from "./NodeUtils.js";
3
+ const DEFAULT_CONTAINER_WIDTH = 35 * GRID_SPACING;
4
+ const DEFAULT_CONTAINER_HEIGHT = 20 * GRID_SPACING;
5
+ const DEFAULT_CONTAINER_MIN_WIDTH = 25 * GRID_SPACING;
6
+ const DEFAULT_CONTAINER_MIN_HEIGHT = 14 * GRID_SPACING;
7
+ const CONTAINER_FRAME_INSET_PX = 10;
8
+ const CONTAINER_BODY_PADDING_PX = 2 * GRID_SPACING;
9
+ const CONTAINER_INNER_HANDLE_RAIL_WIDTH_PX = 5 * GRID_SPACING;
10
+ const CONTAINER_CHILD_SAFE_GAP_PX = GRID_SPACING;
11
+ const DEFAULT_CONTAINER_HEADER_HEIGHT_PX = 40;
12
+ const CONTAINER_SEQUENCE_GAP_PX = 3 * GRID_SPACING;
13
+ const PLACEMENT_DATA_KEY = 'placement';
14
+ function readNumericDimension(...values) {
15
+ for (const value of values){
16
+ if ('number' == typeof value && Number.isFinite(value)) return value;
17
+ if ('string' == typeof value) {
18
+ const parsedValue = Number.parseFloat(value);
19
+ if (Number.isFinite(parsedValue)) return parsedValue;
20
+ }
21
+ }
22
+ }
23
+ function container_getNodeDimensions(node, fallback = {
24
+ width: DEFAULT_NODE_SIZE,
25
+ height: DEFAULT_NODE_SIZE
26
+ }) {
27
+ return {
28
+ width: readNumericDimension(node.width, node.measured?.width, node.style?.width) ?? fallback.width,
29
+ height: readNumericDimension(node.height, node.measured?.height, node.style?.height) ?? fallback.height
30
+ };
31
+ }
32
+ function container_getContainerSafeArea(containerNode, fallback = {
33
+ width: DEFAULT_CONTAINER_WIDTH,
34
+ height: DEFAULT_CONTAINER_HEIGHT
35
+ }) {
36
+ const size = container_getNodeDimensions(containerNode, fallback);
37
+ const horizontalPadding = snapUpToGrid(CONTAINER_FRAME_INSET_PX + CONTAINER_BODY_PADDING_PX + CONTAINER_INNER_HANDLE_RAIL_WIDTH_PX + CONTAINER_CHILD_SAFE_GAP_PX);
38
+ const verticalPadding = snapUpToGrid(CONTAINER_FRAME_INSET_PX + CONTAINER_BODY_PADDING_PX);
39
+ const padding = {
40
+ left: horizontalPadding,
41
+ right: horizontalPadding,
42
+ top: snapUpToGrid(DEFAULT_CONTAINER_HEADER_HEIGHT_PX + verticalPadding),
43
+ bottom: verticalPadding
44
+ };
45
+ return {
46
+ x: padding.left,
47
+ y: padding.top,
48
+ width: Math.max(0, size.width - padding.left - padding.right),
49
+ height: Math.max(0, size.height - padding.top - padding.bottom),
50
+ padding
51
+ };
52
+ }
53
+ function container_getContainerFitGeometry() {
54
+ const padding = container_getContainerSafeArea({
55
+ width: DEFAULT_CONTAINER_WIDTH,
56
+ height: DEFAULT_CONTAINER_HEIGHT
57
+ }).padding;
58
+ return {
59
+ minWidth: DEFAULT_CONTAINER_MIN_WIDTH,
60
+ minHeight: DEFAULT_CONTAINER_MIN_HEIGHT,
61
+ padding: {
62
+ right: padding.right,
63
+ bottom: padding.bottom
64
+ }
65
+ };
66
+ }
67
+ function isContainerNodeManifest(manifest) {
68
+ return manifest?.display.shape === 'container';
69
+ }
70
+ function getAncestorContainerIds(containerId, nodesById) {
71
+ const ancestors = [];
72
+ let parentId = nodesById.get(containerId)?.parentId;
73
+ while(parentId){
74
+ ancestors.push(parentId);
75
+ parentId = nodesById.get(parentId)?.parentId;
76
+ }
77
+ return ancestors;
78
+ }
79
+ function getContainerDepth(containerId, nodesById) {
80
+ let depth = 0;
81
+ let parentId = nodesById.get(containerId)?.parentId;
82
+ while(parentId){
83
+ depth += 1;
84
+ parentId = nodesById.get(parentId)?.parentId;
85
+ }
86
+ return depth;
87
+ }
88
+ function withNodeDimensions(node, size) {
89
+ return {
90
+ ...node,
91
+ width: size.width,
92
+ height: size.height,
93
+ style: {
94
+ ...node.style,
95
+ width: size.width,
96
+ height: size.height
97
+ }
98
+ };
99
+ }
100
+ function ensureContainersFitChildren(nodes, { containerIds, getContainerFitGeometry: resolveContainerFitGeometry, getNodeDimensions: resolveNodeDimensions = container_getNodeDimensions, ignoredNodeTypes = [], includeAncestors = true } = {}) {
101
+ let nextNodes = nodes;
102
+ const changes = [];
103
+ const ignoredTypes = new Set(ignoredNodeTypes);
104
+ const nodesById = new Map(nextNodes.map((node)=>[
105
+ node.id,
106
+ node
107
+ ]));
108
+ const idsToFit = new Set();
109
+ if (containerIds) for (const id of containerIds)idsToFit.add(id);
110
+ else for (const node of nextNodes)if (node.parentId) idsToFit.add(node.parentId);
111
+ if (includeAncestors) for (const id of Array.from(idsToFit))for (const ancestorId of getAncestorContainerIds(id, nodesById))idsToFit.add(ancestorId);
112
+ const orderedContainerIds = Array.from(idsToFit).sort((left, right)=>getContainerDepth(right, nodesById) - getContainerDepth(left, nodesById));
113
+ for (const containerId of orderedContainerIds){
114
+ const containerNode = nextNodes.find((node)=>node.id === containerId);
115
+ if (!containerNode) continue;
116
+ const geometry = resolveContainerFitGeometry?.(containerNode);
117
+ if (!geometry) continue;
118
+ const currentSize = resolveNodeDimensions(containerNode);
119
+ const padding = geometry.padding ?? {};
120
+ let requiredWidth = geometry.minWidth;
121
+ let requiredHeight = geometry.minHeight;
122
+ for (const childNode of nextNodes){
123
+ if (childNode.id === PREVIEW_NODE_ID || childNode.hidden || childNode.parentId !== containerId || ignoredTypes.has(childNode.type ?? '')) continue;
124
+ const childSize = resolveNodeDimensions(childNode);
125
+ requiredWidth = Math.max(requiredWidth, childNode.position.x + childSize.width + (padding.right ?? 0));
126
+ requiredHeight = Math.max(requiredHeight, childNode.position.y + childSize.height + (padding.bottom ?? 0));
127
+ }
128
+ const nextSize = {
129
+ width: Math.max(currentSize.width, snapUpToGrid(requiredWidth)),
130
+ height: Math.max(currentSize.height, snapUpToGrid(requiredHeight))
131
+ };
132
+ if (nextSize.width !== currentSize.width || nextSize.height !== currentSize.height) {
133
+ nextNodes = nextNodes.map((node)=>node.id === containerId ? withNodeDimensions(node, nextSize) : node);
134
+ nodesById.set(containerId, nextNodes.find((node)=>node.id === containerId));
135
+ changes.push({
136
+ containerId,
137
+ previousSize: currentSize,
138
+ nextSize
139
+ });
140
+ }
141
+ }
142
+ return {
143
+ nodes: nextNodes,
144
+ changes
145
+ };
146
+ }
147
+ function getSafeArea(containerNode, safeArea) {
148
+ return safeArea ?? container_getContainerSafeArea(containerNode);
149
+ }
150
+ function clampTopLeftToSafeArea(position, safeArea, nodeSize) {
151
+ const maxX = safeArea.x + Math.max(0, safeArea.width - nodeSize.width);
152
+ const maxY = safeArea.y + Math.max(0, safeArea.height - nodeSize.height);
153
+ return {
154
+ x: clamp(position.x, safeArea.x, maxX),
155
+ y: clamp(position.y, safeArea.y, maxY)
156
+ };
157
+ }
158
+ function clampTopToSafeArea(top, safeArea, nodeSize) {
159
+ const maxY = safeArea.y + Math.max(0, safeArea.height - nodeSize.height);
160
+ return clamp(top, safeArea.y, maxY);
161
+ }
162
+ function rangesOverlap(startA, endA, startB, endB) {
163
+ return startA < endB && endA > startB;
164
+ }
165
+ function centerOnContainerRail(containerSize, safeArea, nodeSize) {
166
+ const railY = snapToGrid(containerSize.height / 2 - nodeSize.height / 2);
167
+ const maxY = safeArea.y + Math.max(0, safeArea.height - nodeSize.height);
168
+ return {
169
+ x: Math.max(safeArea.x, snapToGrid(safeArea.x + (safeArea.width - nodeSize.width) / 2)),
170
+ y: clamp(railY, safeArea.y, maxY)
171
+ };
172
+ }
173
+ function getLocalNodePosition(node, containerNode, nodes) {
174
+ if (!node || node.id === containerNode.id) return null;
175
+ if (node.parentId === containerNode.id) return node.position;
176
+ const containerPosition = getAbsolutePosition(containerNode, nodes);
177
+ const nodePosition = node.parentId ? getAbsolutePosition(node, nodes) : node.position;
178
+ return {
179
+ x: nodePosition.x - containerPosition.x,
180
+ y: nodePosition.y - containerPosition.y
181
+ };
182
+ }
183
+ function getPlacementDirection(sourcePosition, targetPosition) {
184
+ if (!sourcePosition || !targetPosition) return sourcePosition ? 'right' : 'left';
185
+ return targetPosition.x >= sourcePosition.x ? 'right' : 'left';
186
+ }
187
+ function getSiblingNodes(containerId, nodes, insertedNodeId) {
188
+ return nodes.filter((node)=>node.id !== PREVIEW_NODE_ID && node.id !== insertedNodeId && node.parentId === containerId);
189
+ }
190
+ function resolveSequenceTopLeft({ sourceNode, targetNode, containerNode, nodes, safeArea, previewNodeSize, gap, getNodeDimensions }) {
191
+ const sourcePosition = getLocalNodePosition(sourceNode, containerNode, nodes);
192
+ const targetPosition = getLocalNodePosition(targetNode, containerNode, nodes);
193
+ const sourceSize = sourceNode ? getNodeDimensions(sourceNode) : void 0;
194
+ const targetSize = targetNode ? getNodeDimensions(targetNode) : void 0;
195
+ if (sourcePosition && sourceSize && targetPosition) {
196
+ const sourceRight = sourcePosition.x + sourceSize.width;
197
+ const targetLeft = targetPosition.x;
198
+ const centerX = targetLeft - sourceRight >= previewNodeSize.width + 2 * gap ? sourceRight + (targetLeft - sourceRight) / 2 : sourceRight + gap + previewNodeSize.width / 2;
199
+ return {
200
+ x: centerX - previewNodeSize.width / 2,
201
+ y: sourcePosition.y + sourceSize.height / 2 - previewNodeSize.height / 2
202
+ };
203
+ }
204
+ if (sourcePosition && sourceSize) return {
205
+ x: sourcePosition.x + sourceSize.width + gap,
206
+ y: sourcePosition.y + sourceSize.height / 2 - previewNodeSize.height / 2
207
+ };
208
+ if (targetPosition && targetSize) return {
209
+ x: targetPosition.x - previewNodeSize.width - gap,
210
+ y: targetPosition.y + targetSize.height / 2 - previewNodeSize.height / 2
211
+ };
212
+ return {
213
+ x: safeArea.x + safeArea.width / 2 - previewNodeSize.width / 2,
214
+ y: safeArea.y + safeArea.height / 2 - previewNodeSize.height / 2
215
+ };
216
+ }
217
+ function getContainerNodeForEdge(sourceNode, targetNode, nodes) {
218
+ if (sourceNode.parentId === targetNode.id) return targetNode;
219
+ if (targetNode.parentId === sourceNode.id) return sourceNode;
220
+ if (sourceNode.parentId && sourceNode.parentId === targetNode.parentId) return nodes.find((node)=>node.id === sourceNode.parentId) ?? null;
221
+ return null;
222
+ }
223
+ function handleMatches(edgeHandleId, handleId) {
224
+ return (edgeHandleId ?? DEFAULT_SOURCE_HANDLE_ID) === handleId;
225
+ }
226
+ function getOutgoingEdges(sourceNodeId, sourceHandleId, edges) {
227
+ return edges.filter((edge)=>edge.source !== PREVIEW_NODE_ID && edge.target !== PREVIEW_NODE_ID && edge.source === sourceNodeId && handleMatches(edge.sourceHandle, sourceHandleId));
228
+ }
229
+ function getSingleOutgoingEdge(sourceNodeId, sourceHandleId, edges) {
230
+ const outgoingEdges = getOutgoingEdges(sourceNodeId, sourceHandleId, edges);
231
+ return 1 === outgoingEdges.length ? outgoingEdges[0] : null;
232
+ }
233
+ function isPreviewGraphEdge(edge) {
234
+ return edge.source === PREVIEW_NODE_ID || edge.target === PREVIEW_NODE_ID;
235
+ }
236
+ function bucketInScopeEdgesBySource({ edges, nodesById, parentId, isSequenceEdge }) {
237
+ const bySource = new Map();
238
+ for (const edge of edges){
239
+ if (isPreviewGraphEdge(edge)) continue;
240
+ if (isSequenceEdge && !isSequenceEdge(edge)) continue;
241
+ const targetIsParent = void 0 !== parentId && edge.target === parentId;
242
+ const targetIsSibling = nodesById.get(edge.target)?.parentId === parentId;
243
+ if (!targetIsParent && !targetIsSibling) continue;
244
+ const bucket = bySource.get(edge.source);
245
+ if (bucket) bucket.push(edge);
246
+ else bySource.set(edge.source, [
247
+ edge
248
+ ]);
249
+ }
250
+ return bySource;
251
+ }
252
+ function collectLinearDownstreamSiblings({ startNodeId, parentId, nodes, edges, isSequenceEdge, getNextNodeId }) {
253
+ if (!startNodeId || startNodeId === parentId) return [];
254
+ const nodesById = new Map(nodes.map((node)=>[
255
+ node.id,
256
+ node
257
+ ]));
258
+ const inScopeEdgesBySource = bucketInScopeEdgesBySource({
259
+ edges,
260
+ nodesById,
261
+ parentId,
262
+ isSequenceEdge
263
+ });
264
+ const collectedIds = [];
265
+ const visitedIds = new Set();
266
+ let currentNodeId = startNodeId;
267
+ while(!visitedIds.has(currentNodeId)){
268
+ const currentNode = nodesById.get(currentNodeId);
269
+ if (!currentNode || currentNode.parentId !== parentId) break;
270
+ collectedIds.push(currentNodeId);
271
+ visitedIds.add(currentNodeId);
272
+ let next = getNextNodeId ? getNextNodeId({
273
+ nodeId: currentNodeId,
274
+ edges,
275
+ nodesById,
276
+ parentId
277
+ }) : void 0;
278
+ if (void 0 === next) {
279
+ const outgoing = inScopeEdgesBySource.get(currentNodeId) ?? [];
280
+ next = 1 === outgoing.length ? outgoing[0].target : null;
281
+ }
282
+ if (!next || next === parentId) break;
283
+ currentNodeId = next;
284
+ }
285
+ return collectedIds;
286
+ }
287
+ function resolveInsertPreview({ source, sourceHandleType, reactFlowInstance, isContainerNode, getContainerSafeArea, previewNodeSize, gap, getNodeDimensions }) {
288
+ if ('source' !== sourceHandleType || !source.handleId) return null;
289
+ const replacedEdge = getSingleOutgoingEdge(source.nodeId, source.handleId, reactFlowInstance.getEdges());
290
+ if (!replacedEdge) return null;
291
+ const sourceNode = reactFlowInstance.getNode(replacedEdge.source);
292
+ const targetNode = reactFlowInstance.getNode(replacedEdge.target);
293
+ const nodes = reactFlowInstance.getNodes();
294
+ const containerNode = getContainerNodeForEdge(sourceNode, targetNode, nodes);
295
+ if (!containerNode) return null;
296
+ if (isContainerNode && !isContainerNode(containerNode)) return null;
297
+ const containerPlacement = getPreviewPlacement({
298
+ sourceNode,
299
+ targetNode,
300
+ containerNode,
301
+ nodes,
302
+ safeArea: getContainerSafeArea?.(containerNode),
303
+ previewNodeSize,
304
+ gap,
305
+ getNodeDimensions
306
+ });
307
+ const placement = {
308
+ containerId: containerPlacement.containerId,
309
+ sourceNodeId: sourceNode.id,
310
+ targetNodeId: targetNode.id,
311
+ mode: 'sequence'
312
+ };
313
+ return {
314
+ position: containerPlacement.centerPosition,
315
+ positionMode: 'center',
316
+ data: {
317
+ originalEdge: replacedEdge,
318
+ [PLACEMENT_DATA_KEY]: placement
319
+ },
320
+ target: {
321
+ nodeId: replacedEdge.target,
322
+ handleId: replacedEdge.targetHandle
323
+ },
324
+ containerId: containerPlacement.containerId
325
+ };
326
+ }
327
+ function resolveAppendPreview({ source, sourceHandleType, reactFlowInstance, ...options }) {
328
+ if ('source' !== sourceHandleType || !source.handleId) return null;
329
+ const sourceNode = reactFlowInstance.getNode(source.nodeId);
330
+ if (!sourceNode?.parentId) return null;
331
+ const outgoingEdges = getOutgoingEdges(source.nodeId, source.handleId, reactFlowInstance.getEdges());
332
+ if (outgoingEdges.length > 0) return null;
333
+ const nodes = reactFlowInstance.getNodes();
334
+ const containerNode = nodes.find((node)=>node.id === sourceNode.parentId);
335
+ if (options.isContainerNode && !options.isContainerNode(containerNode)) return null;
336
+ const continuationTarget = options.getContainerContinuationTarget?.({
337
+ containerNode,
338
+ sourceNode,
339
+ source,
340
+ reactFlowInstance
341
+ });
342
+ if (!continuationTarget) return null;
343
+ const targetNode = continuationTarget.nodeId === containerNode.id ? containerNode : reactFlowInstance.getNode(continuationTarget.nodeId);
344
+ const containerPlacement = getPreviewPlacement({
345
+ sourceNode,
346
+ targetNode,
347
+ containerNode,
348
+ nodes,
349
+ safeArea: options.getContainerSafeArea?.(containerNode),
350
+ previewNodeSize: options.previewNodeSize,
351
+ gap: options.gap,
352
+ avoidSiblings: options.avoidSiblings ?? true,
353
+ getNodeDimensions: options.getNodeDimensions
354
+ });
355
+ const placement = {
356
+ containerId: containerPlacement.containerId,
357
+ sourceNodeId: sourceNode.id,
358
+ targetNodeId: continuationTarget.nodeId,
359
+ mode: 'sequence'
360
+ };
361
+ return {
362
+ position: containerPlacement.centerPosition,
363
+ positionMode: 'center',
364
+ data: {
365
+ [PLACEMENT_DATA_KEY]: placement
366
+ },
367
+ target: continuationTarget,
368
+ containerId: containerPlacement.containerId
369
+ };
370
+ }
371
+ function resolveContainerPreview({ source, sourceHandleType, reactFlowInstance, ...options }) {
372
+ return resolveInsertPreview({
373
+ source,
374
+ sourceHandleType,
375
+ reactFlowInstance,
376
+ ...options
377
+ }) ?? resolveAppendPreview({
378
+ source,
379
+ sourceHandleType,
380
+ reactFlowInstance,
381
+ ...options
382
+ });
383
+ }
384
+ function getPreviewPlacement({ sourceNode, targetNode, containerNode, nodes, containerAbsolutePosition = getAbsolutePosition(containerNode, nodes), safeArea, previewNodeSize = {
385
+ width: DEFAULT_NODE_SIZE,
386
+ height: DEFAULT_NODE_SIZE
387
+ }, gap = CONTAINER_SEQUENCE_GAP_PX, avoidSiblings = false, getNodeDimensions: resolveNodeDimensions = container_getNodeDimensions }) {
388
+ const resolvedSafeArea = getSafeArea(containerNode, safeArea);
389
+ const sourcePosition = getLocalNodePosition(sourceNode, containerNode, nodes);
390
+ const targetPosition = getLocalNodePosition(targetNode, containerNode, nodes);
391
+ const direction = getPlacementDirection(sourcePosition, targetPosition);
392
+ const initialPosition = resolveSequenceTopLeft({
393
+ sourceNode,
394
+ targetNode,
395
+ containerNode,
396
+ nodes,
397
+ safeArea: resolvedSafeArea,
398
+ previewNodeSize,
399
+ gap,
400
+ getNodeDimensions: resolveNodeDimensions
401
+ });
402
+ const collisionPosition = avoidSiblings ? getNonOverlappingPositionForDirection(getSiblingNodes(containerNode.id, nodes), initialPosition, previewNodeSize, direction, gap) : initialPosition;
403
+ const position = clampTopLeftToSafeArea(collisionPosition, resolvedSafeArea, previewNodeSize);
404
+ return {
405
+ containerId: containerNode.id,
406
+ centerPosition: {
407
+ x: containerAbsolutePosition.x + position.x + previewNodeSize.width / 2,
408
+ y: containerAbsolutePosition.y + position.y + previewNodeSize.height / 2
409
+ }
410
+ };
411
+ }
412
+ function getNodeCenterY(position, nodeSize) {
413
+ return position.y + nodeSize.height / 2;
414
+ }
415
+ function getInsertedPosition({ sourceNode, targetNode, insertedNode, containerNode, nodes, safeArea, insertedNodeSize, gap, getNodeDimensions }) {
416
+ const sourcePosition = getLocalNodePosition(sourceNode, containerNode, nodes);
417
+ const targetPosition = getLocalNodePosition(targetNode, containerNode, nodes);
418
+ const sourceSize = sourceNode ? getNodeDimensions(sourceNode) : void 0;
419
+ const targetSize = targetNode ? getNodeDimensions(targetNode) : void 0;
420
+ const sourceIsContainer = sourceNode?.id === containerNode.id;
421
+ const targetIsContainer = targetNode?.id === containerNode.id;
422
+ if (sourcePosition && sourceSize && !sourceIsContainer) return {
423
+ x: Math.max(safeArea.x, snapToGrid(sourcePosition.x + sourceSize.width + gap)),
424
+ y: clampTopToSafeArea(snapToGrid(getNodeCenterY(sourcePosition, sourceSize) - insertedNodeSize.height / 2), safeArea, insertedNodeSize)
425
+ };
426
+ if (targetPosition && targetSize && !targetIsContainer) return {
427
+ x: Math.max(safeArea.x, snapToGrid(targetPosition.x - insertedNodeSize.width - gap)),
428
+ y: clampTopToSafeArea(snapToGrid(getNodeCenterY(targetPosition, targetSize) - insertedNodeSize.height / 2), safeArea, insertedNodeSize)
429
+ };
430
+ return {
431
+ x: Math.max(safeArea.x, snapToGrid(insertedNode.position.x)),
432
+ y: clampTopToSafeArea(snapToGrid(insertedNode.position.y), safeArea, insertedNodeSize)
433
+ };
434
+ }
435
+ function getNodeDepth(node, nodesById) {
436
+ let depth = 0;
437
+ let parentId = node?.parentId;
438
+ while(parentId){
439
+ depth += 1;
440
+ parentId = nodesById.get(parentId)?.parentId;
441
+ }
442
+ return depth;
443
+ }
444
+ function sortContainerSizeChanges(changes, nodes) {
445
+ const nodesById = new Map(nodes.map((node)=>[
446
+ node.id,
447
+ node
448
+ ]));
449
+ return [
450
+ ...changes
451
+ ].sort((left, right)=>{
452
+ const leftNode = nodesById.get(left.containerId);
453
+ const rightNode = nodesById.get(right.containerId);
454
+ const depthDifference = getNodeDepth(rightNode, nodesById) - getNodeDepth(leftNode, nodesById);
455
+ if (0 !== depthDifference) return depthDifference;
456
+ if (leftNode.parentId === rightNode.parentId) return leftNode.position.x - rightNode.position.x;
457
+ return 0;
458
+ });
459
+ }
460
+ function pushSiblingsAfterContainerGrowth({ nodes, changes, getNodeDimensions, gap }) {
461
+ let shifted = false;
462
+ let nextNodes = nodes;
463
+ for (const change of sortContainerSizeChanges(changes, nextNodes)){
464
+ const widthDelta = change.nextSize.width - change.previousSize.width;
465
+ const heightDelta = change.nextSize.height - change.previousSize.height;
466
+ if (widthDelta <= 0 && heightDelta <= 0) continue;
467
+ const containerNode = nextNodes.find((node)=>node.id === change.containerId);
468
+ const oldRight = containerNode.position.x + change.previousSize.width;
469
+ const newRight = containerNode.position.x + change.nextSize.width;
470
+ const oldBottom = containerNode.position.y + change.previousSize.height;
471
+ const newBottom = containerNode.position.y + change.nextSize.height;
472
+ const containerLeft = containerNode.position.x;
473
+ const containerRight = containerNode.position.x + Math.max(change.previousSize.width, change.nextSize.width);
474
+ const containerTop = containerNode.position.y;
475
+ const containerBottom = containerNode.position.y + Math.max(change.previousSize.height, change.nextSize.height);
476
+ nextNodes = nextNodes.map((node)=>{
477
+ if (node.id === containerNode.id || node.parentId !== containerNode.parentId) return node;
478
+ const nodeSize = getNodeDimensions(node);
479
+ let nextX = node.position.x;
480
+ let nextY = node.position.y;
481
+ if (widthDelta > 0 && node.position.x >= oldRight) {
482
+ const verticallyOverlaps = rangesOverlap(node.position.y, node.position.y + nodeSize.height, containerTop, containerBottom);
483
+ if (verticallyOverlaps) nextX = Math.max(node.position.x + widthDelta, snapUpToGrid(newRight + gap));
484
+ }
485
+ if (heightDelta > 0 && node.position.y >= oldBottom) {
486
+ const horizontallyOverlaps = rangesOverlap(node.position.x, node.position.x + nodeSize.width, containerLeft, containerRight);
487
+ if (horizontallyOverlaps) nextY = Math.max(node.position.y + heightDelta, snapUpToGrid(newBottom + gap));
488
+ }
489
+ if (nextX === node.position.x && nextY === node.position.y) return node;
490
+ shifted = true;
491
+ return {
492
+ ...node,
493
+ position: {
494
+ x: nextX,
495
+ y: nextY
496
+ }
497
+ };
498
+ });
499
+ }
500
+ return {
501
+ nodes: nextNodes,
502
+ shifted
503
+ };
504
+ }
505
+ function fitContainersAndPushSiblings({ nodes, containerIds, getContainerFitGeometry, getNodeDimensions, gap }) {
506
+ let nextNodes = nodes;
507
+ for(let iteration = 0; iteration < 10; iteration += 1){
508
+ const fitResult = ensureContainersFitChildren(nextNodes, {
509
+ containerIds,
510
+ getContainerFitGeometry,
511
+ getNodeDimensions,
512
+ includeAncestors: true
513
+ });
514
+ nextNodes = fitResult.nodes;
515
+ if (0 === fitResult.changes.length) break;
516
+ const pushResult = pushSiblingsAfterContainerGrowth({
517
+ nodes: nextNodes,
518
+ changes: fitResult.changes,
519
+ getNodeDimensions,
520
+ gap
521
+ });
522
+ nextNodes = pushResult.nodes;
523
+ if (!pushResult.shifted) break;
524
+ }
525
+ return nextNodes;
526
+ }
527
+ function getContainerPlacement(previewNode) {
528
+ const placement = previewNode.data?.[PLACEMENT_DATA_KEY];
529
+ if (!placement) return null;
530
+ if (previewNode.parentId && placement.containerId !== previewNode.parentId) return null;
531
+ return placement;
532
+ }
533
+ function placeContainerNode({ nodes, insertedNode, placement, safeArea, getContainerFitGeometry: resolveContainerFitGeometry = container_getContainerFitGeometry, getNodeDimensions: resolveNodeDimensions = container_getNodeDimensions, gap = CONTAINER_SEQUENCE_GAP_PX, downstreamNodeIds, edges }) {
534
+ const containerNode = nodes.find((node)=>node.id === placement.containerId);
535
+ const nodesById = new Map(nodes.map((node)=>[
536
+ node.id,
537
+ node
538
+ ]));
539
+ const insertedSize = resolveNodeDimensions(insertedNode);
540
+ const resolvedSafeArea = getSafeArea(containerNode, safeArea);
541
+ const positionedNode = 'first-child' === placement.mode ? {
542
+ ...insertedNode,
543
+ position: centerOnContainerRail(resolveNodeDimensions(containerNode), resolvedSafeArea, insertedSize)
544
+ } : {
545
+ ...insertedNode,
546
+ position: getInsertedPosition({
547
+ sourceNode: placement.sourceNodeId ? nodesById.get(placement.sourceNodeId) : void 0,
548
+ targetNode: placement.targetNodeId ? nodesById.get(placement.targetNodeId) : void 0,
549
+ insertedNode,
550
+ containerNode,
551
+ nodes,
552
+ safeArea: resolvedSafeArea,
553
+ insertedNodeSize: insertedSize,
554
+ gap,
555
+ getNodeDimensions: resolveNodeDimensions
556
+ })
557
+ };
558
+ const targetNode = placement.targetNodeId && placement.targetNodeId !== placement.containerId ? nodesById.get(placement.targetNodeId) : void 0;
559
+ const fallbackTargetIds = placement.targetNodeId && placement.targetNodeId !== placement.containerId ? [
560
+ placement.targetNodeId
561
+ ] : [];
562
+ const idsToShift = new Set(downstreamNodeIds ?? (edges ? collectLinearDownstreamSiblings({
563
+ startNodeId: placement.targetNodeId,
564
+ parentId: placement.containerId,
565
+ nodes,
566
+ edges
567
+ }) : fallbackTargetIds));
568
+ const requiredTargetLeft = positionedNode.position.x + insertedSize.width + gap;
569
+ const downstreamShift = targetNode && targetNode.position.x < requiredTargetLeft ? snapUpToGrid(requiredTargetLeft - targetNode.position.x) : 0;
570
+ const positionedNodes = nodes.map((node)=>{
571
+ if (node.id === insertedNode.id) return positionedNode;
572
+ if (downstreamShift > 0 && idsToShift.has(node.id)) return {
573
+ ...node,
574
+ position: {
575
+ ...node.position,
576
+ x: node.position.x + downstreamShift
577
+ }
578
+ };
579
+ return node;
580
+ });
581
+ return fitContainersAndPushSiblings({
582
+ nodes: positionedNodes,
583
+ containerIds: [
584
+ placement.containerId
585
+ ],
586
+ getContainerFitGeometry: resolveContainerFitGeometry,
587
+ getNodeDimensions: resolveNodeDimensions,
588
+ gap
589
+ });
590
+ }
591
+ export { CONTAINER_FRAME_INSET_PX, CONTAINER_SEQUENCE_GAP_PX, DEFAULT_CONTAINER_HEIGHT, DEFAULT_CONTAINER_MIN_HEIGHT, DEFAULT_CONTAINER_MIN_WIDTH, DEFAULT_CONTAINER_WIDTH, collectLinearDownstreamSiblings, ensureContainersFitChildren, container_getContainerFitGeometry as getContainerFitGeometry, getContainerNodeForEdge, getContainerPlacement, container_getContainerSafeArea as getContainerSafeArea, container_getNodeDimensions as getNodeDimensions, isContainerNodeManifest, placeContainerNode, resolveContainerPreview };
@@ -52,28 +52,39 @@ function reparentPreviewNodeToContainer(previewNode, containerId, reactFlowInsta
52
52
  extent: 'parent'
53
53
  };
54
54
  }
55
- function createPreviewNodeForGraph({ sourceNodeId, sourceHandleId, reactFlowInstance, position, data, sourceHandleType, previewNodeSize, handlePosition, ignoredNodeTypes, positionMode }) {
56
- return (0, external_createPreviewNode_cjs_namespaceObject.createPreviewNode)(sourceNodeId, sourceHandleId, reactFlowInstance, position, data, sourceHandleType, previewNodeSize, handlePosition, ignoredNodeTypes, positionMode);
55
+ function createPreviewNodeForGraph({ source, reactFlowInstance, position, data, sourceHandleType, previewNodeSize, handlePosition, ignoredNodeTypes, positionMode, sourceBoundaryOf }) {
56
+ return (0, external_createPreviewNode_cjs_namespaceObject.createPreviewNode)({
57
+ sourceNodeId: source.nodeId,
58
+ sourceHandleId: source.handleId ?? external_constants_cjs_namespaceObject.DEFAULT_SOURCE_HANDLE_ID,
59
+ reactFlowInstance,
60
+ position,
61
+ data,
62
+ sourceHandleType,
63
+ previewNodeSize,
64
+ handlePosition,
65
+ ignoredNodeTypes,
66
+ positionMode,
67
+ sourceBoundaryOf
68
+ });
57
69
  }
58
- function createTrailingPreviewEdge({ targetNodeId, targetHandleId, trailingEdgeId, trailingEdgeStyle = external_createPreviewNode_cjs_namespaceObject.PREVIEW_EDGE_STYLE }) {
59
- if (!targetNodeId) return null;
70
+ function createTrailingPreviewEdge({ target, trailingEdgeId, trailingEdgeStyle = external_createPreviewNode_cjs_namespaceObject.PREVIEW_EDGE_STYLE }) {
71
+ if (!target) return null;
60
72
  return {
61
- id: trailingEdgeId ?? `${external_constants_cjs_namespaceObject.PREVIEW_NODE_ID}-${targetNodeId}`,
73
+ id: trailingEdgeId ?? `${external_constants_cjs_namespaceObject.PREVIEW_NODE_ID}-${target.nodeId}`,
62
74
  source: external_constants_cjs_namespaceObject.PREVIEW_NODE_ID,
63
75
  sourceHandle: external_constants_cjs_namespaceObject.DEFAULT_SOURCE_HANDLE_ID,
64
- target: targetNodeId,
65
- targetHandle: targetHandleId,
76
+ target: target.nodeId,
77
+ targetHandle: target.handleId,
66
78
  type: 'default',
67
79
  style: trailingEdgeStyle
68
80
  };
69
81
  }
70
82
  function createPreviewGraph(options) {
71
- const { reactFlowInstance, targetNodeId, containerId, removedEdgeIds, sourceNodeId } = options;
83
+ const { reactFlowInstance, target, containerId, source } = options;
72
84
  const preview = createPreviewNodeForGraph(options);
73
85
  if (!preview) return null;
74
- const sourceNode = reactFlowInstance.getNode(sourceNodeId);
75
- if (!sourceNode) return null;
76
- const targetNode = targetNodeId ? reactFlowInstance.getNode(targetNodeId) : void 0;
86
+ const sourceNode = reactFlowInstance.getNode(source.nodeId);
87
+ const targetNode = target ? reactFlowInstance.getNode(target.nodeId) : void 0;
77
88
  const resolvedContainerId = containerId ?? inferPreviewContainerId(sourceNode, targetNode);
78
89
  const finalPreviewNode = resolvedContainerId ? reparentPreviewNodeToContainer(preview.node, resolvedContainerId, reactFlowInstance) : preview.node;
79
90
  if (!finalPreviewNode) return null;
@@ -86,8 +97,7 @@ function createPreviewGraph(options) {
86
97
  ];
87
98
  return {
88
99
  node: finalPreviewNode,
89
- edges,
90
- removedEdgeIds
100
+ edges
91
101
  };
92
102
  }
93
103
  function showPreviewGraph(options) {
@@ -96,7 +106,7 @@ function showPreviewGraph(options) {
96
106
  return preview;
97
107
  }
98
108
  function applyPreviewGraphToReactFlow(preview, reactFlowInstance) {
99
- const removedEdgeIds = new Set(preview.removedEdgeIds ?? []);
109
+ const originalEdge = preview.node.data?.originalEdge;
100
110
  setTimeout(()=>{
101
111
  reactFlowInstance.setNodes((nodes)=>[
102
112
  ...nodes.filter((node)=>node.id !== external_constants_cjs_namespaceObject.PREVIEW_NODE_ID).map((node)=>({
@@ -106,7 +116,7 @@ function applyPreviewGraphToReactFlow(preview, reactFlowInstance) {
106
116
  preview.node
107
117
  ]);
108
118
  reactFlowInstance.setEdges((edges)=>[
109
- ...edges.filter((edge)=>!(0, external_createPreviewNode_cjs_namespaceObject.isPreviewEdge)(edge) && !removedEdgeIds.has(edge.id)),
119
+ ...edges.filter((edge)=>!(0, external_createPreviewNode_cjs_namespaceObject.isPreviewEdge)(edge) && edge.id !== originalEdge?.id),
110
120
  ...preview.edges
111
121
  ]);
112
122
  }, 0);