@uipath/apollo-react 4.16.0 → 4.17.0-pr605.1e1e7d4
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/canvas/components/AddNodePanel/AddNodeManager.cjs +35 -21
- package/dist/canvas/components/AddNodePanel/AddNodeManager.d.ts.map +1 -1
- package/dist/canvas/components/AddNodePanel/AddNodeManager.helpers.cjs +154 -0
- package/dist/canvas/components/AddNodePanel/AddNodeManager.helpers.d.ts +20 -0
- package/dist/canvas/components/AddNodePanel/AddNodeManager.helpers.d.ts.map +1 -0
- package/dist/canvas/components/AddNodePanel/AddNodeManager.helpers.js +114 -0
- package/dist/canvas/components/AddNodePanel/AddNodeManager.js +35 -21
- package/dist/canvas/components/AddNodePanel/createAddNodePreview.cjs +15 -4
- package/dist/canvas/components/AddNodePanel/createAddNodePreview.d.ts +5 -1
- package/dist/canvas/components/AddNodePanel/createAddNodePreview.d.ts.map +1 -1
- package/dist/canvas/components/AddNodePanel/createAddNodePreview.js +15 -4
- package/dist/canvas/components/AddNodePanel/index.d.ts +1 -1
- package/dist/canvas/components/AddNodePanel/index.d.ts.map +1 -1
- package/dist/canvas/components/CanvasTooltip.cjs +2 -0
- package/dist/canvas/components/CanvasTooltip.d.ts +2 -2
- package/dist/canvas/components/CanvasTooltip.d.ts.map +1 -1
- package/dist/canvas/components/CanvasTooltip.js +2 -0
- package/dist/canvas/components/HierarchicalCanvas/HierarchicalCanvas.cjs +23 -1
- package/dist/canvas/components/HierarchicalCanvas/HierarchicalCanvas.d.ts.map +1 -1
- package/dist/canvas/components/HierarchicalCanvas/HierarchicalCanvas.js +23 -1
- package/dist/canvas/components/HierarchicalCanvas/HierarchicalCanvasWithControls.cjs +0 -14
- package/dist/canvas/components/HierarchicalCanvas/HierarchicalCanvasWithControls.d.ts.map +1 -1
- package/dist/canvas/components/HierarchicalCanvas/HierarchicalCanvasWithControls.js +2 -16
- package/dist/canvas/components/LoopNode/LoopNode.cjs +25 -19
- package/dist/canvas/components/LoopNode/LoopNode.d.ts.map +1 -1
- package/dist/canvas/components/LoopNode/LoopNode.helpers.cjs +33 -42
- package/dist/canvas/components/LoopNode/LoopNode.helpers.d.ts +9 -10
- package/dist/canvas/components/LoopNode/LoopNode.helpers.d.ts.map +1 -1
- package/dist/canvas/components/LoopNode/LoopNode.helpers.js +25 -31
- package/dist/canvas/components/LoopNode/LoopNode.js +17 -11
- package/dist/canvas/components/LoopNode/LoopNodePreview.cjs +17 -4
- package/dist/canvas/components/LoopNode/LoopNodePreview.d.ts.map +1 -1
- package/dist/canvas/components/LoopNode/LoopNodePreview.js +17 -4
- package/dist/canvas/components/Toolbar/EdgeToolbar/useEdgeToolbarState.cjs +26 -14
- package/dist/canvas/components/Toolbar/EdgeToolbar/useEdgeToolbarState.d.ts.map +1 -1
- package/dist/canvas/components/Toolbar/EdgeToolbar/useEdgeToolbarState.js +26 -14
- package/dist/canvas/components/Toolbox/ListView.cjs +66 -19
- package/dist/canvas/components/Toolbox/ListView.d.ts +12 -1
- package/dist/canvas/components/Toolbox/ListView.d.ts.map +1 -1
- package/dist/canvas/components/Toolbox/ListView.js +66 -19
- package/dist/canvas/components/Toolbox/Toolbox.cjs +6 -5
- package/dist/canvas/components/Toolbox/Toolbox.d.ts.map +1 -1
- package/dist/canvas/components/Toolbox/Toolbox.js +6 -5
- package/dist/canvas/constants.cjs +0 -8
- package/dist/canvas/constants.d.ts +0 -2
- package/dist/canvas/constants.d.ts.map +1 -1
- package/dist/canvas/constants.js +1 -3
- package/dist/canvas/hooks/useAddNodeOnConnectEnd.cjs +4 -2
- package/dist/canvas/hooks/useAddNodeOnConnectEnd.d.ts.map +1 -1
- package/dist/canvas/hooks/useAddNodeOnConnectEnd.js +4 -2
- package/dist/canvas/storybook-utils/hooks/useCanvasStory.d.ts.map +1 -1
- package/dist/canvas/styles/tailwind.canvas.css +1 -1
- package/dist/canvas/utils/NodeUtils.cjs +26 -10
- package/dist/canvas/utils/NodeUtils.d.ts +7 -0
- package/dist/canvas/utils/NodeUtils.d.ts.map +1 -1
- package/dist/canvas/utils/NodeUtils.js +13 -6
- package/dist/canvas/utils/collapse.cjs +3 -3
- package/dist/canvas/utils/collapse.d.ts.map +1 -1
- package/dist/canvas/utils/collapse.js +1 -1
- package/dist/canvas/utils/container.cjs +643 -0
- package/dist/canvas/utils/container.d.ts +97 -0
- package/dist/canvas/utils/container.d.ts.map +1 -0
- package/dist/canvas/utils/container.js +567 -0
- package/dist/canvas/utils/createPreviewGraph.cjs +13 -15
- package/dist/canvas/utils/createPreviewGraph.d.ts +9 -7
- package/dist/canvas/utils/createPreviewGraph.d.ts.map +1 -1
- package/dist/canvas/utils/createPreviewGraph.js +13 -15
- package/dist/canvas/utils/createPreviewNode.cjs +16 -10
- package/dist/canvas/utils/createPreviewNode.d.ts.map +1 -1
- package/dist/canvas/utils/createPreviewNode.js +16 -10
- package/dist/canvas/utils/index.cjs +29 -22
- package/dist/canvas/utils/index.d.ts +1 -0
- package/dist/canvas/utils/index.d.ts.map +1 -1
- package/dist/canvas/utils/index.js +1 -0
- package/package.json +2 -2
- package/dist/canvas/components/LoopNode/LoopNode.constants.cjs +0 -56
- package/dist/canvas/components/LoopNode/LoopNode.constants.d.ts +0 -7
- package/dist/canvas/components/LoopNode/LoopNode.constants.d.ts.map +0 -1
- package/dist/canvas/components/LoopNode/LoopNode.constants.js +0 -7
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { Edge, Node, ReactFlowInstance } from '../xyflow/react.ts';
|
|
2
|
+
import type { NodeManifest } from '../schema/node-definition';
|
|
3
|
+
import type { PreviewEndpoint, PreviewGraphOverrides } from './createPreviewGraph';
|
|
4
|
+
export interface NodeDimensions {
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
}
|
|
8
|
+
export interface ContainerFitGeometry {
|
|
9
|
+
minWidth: number;
|
|
10
|
+
minHeight: number;
|
|
11
|
+
padding?: {
|
|
12
|
+
right?: number;
|
|
13
|
+
bottom?: number;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export interface ContainerSafeArea {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
width: number;
|
|
20
|
+
height: number;
|
|
21
|
+
padding?: {
|
|
22
|
+
left?: number;
|
|
23
|
+
right?: number;
|
|
24
|
+
top?: number;
|
|
25
|
+
bottom?: number;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export interface ContainerSizeChange {
|
|
29
|
+
containerId: string;
|
|
30
|
+
previousSize: NodeDimensions;
|
|
31
|
+
nextSize: NodeDimensions;
|
|
32
|
+
}
|
|
33
|
+
export interface EnsureContainersFitChildrenResult {
|
|
34
|
+
nodes: Node[];
|
|
35
|
+
changes: ContainerSizeChange[];
|
|
36
|
+
}
|
|
37
|
+
export interface ContainerPlacement {
|
|
38
|
+
containerId: string;
|
|
39
|
+
sourceNodeId?: string;
|
|
40
|
+
targetNodeId?: string;
|
|
41
|
+
mode: 'first-child' | 'sequence';
|
|
42
|
+
}
|
|
43
|
+
interface ContainerPreviewContext {
|
|
44
|
+
source: PreviewEndpoint;
|
|
45
|
+
sourceHandleType: 'source' | 'target';
|
|
46
|
+
reactFlowInstance: ReactFlowInstance;
|
|
47
|
+
}
|
|
48
|
+
interface ContainerPreviewOptions {
|
|
49
|
+
isContainerNode?: (node: Node) => boolean;
|
|
50
|
+
getContainerSafeArea?: (containerNode: Node) => ContainerSafeArea | undefined;
|
|
51
|
+
getContainerContinuationTarget?: (context: {
|
|
52
|
+
containerNode: Node;
|
|
53
|
+
sourceNode: Node;
|
|
54
|
+
source: PreviewEndpoint;
|
|
55
|
+
reactFlowInstance: ReactFlowInstance;
|
|
56
|
+
}) => PreviewEndpoint | null | undefined;
|
|
57
|
+
previewNodeSize?: NodeDimensions;
|
|
58
|
+
gap?: number;
|
|
59
|
+
avoidSiblings?: boolean;
|
|
60
|
+
getNodeDimensions?: (node: Node) => NodeDimensions;
|
|
61
|
+
}
|
|
62
|
+
export declare const DEFAULT_CONTAINER_WIDTH: number;
|
|
63
|
+
export declare const DEFAULT_CONTAINER_HEIGHT: number;
|
|
64
|
+
export declare const DEFAULT_CONTAINER_MIN_WIDTH: number;
|
|
65
|
+
export declare const DEFAULT_CONTAINER_MIN_HEIGHT: number;
|
|
66
|
+
export declare const CONTAINER_FRAME_INSET_PX = 10;
|
|
67
|
+
export declare const CONTAINER_SEQUENCE_GAP_PX: number;
|
|
68
|
+
export declare function getNodeDimensions(node: Pick<Node, 'width' | 'height' | 'measured' | 'style'>, fallback?: NodeDimensions): NodeDimensions;
|
|
69
|
+
export declare function getContainerSafeArea(containerNode: Pick<Node, 'width' | 'height' | 'measured' | 'style'>, fallback?: NodeDimensions): ContainerSafeArea;
|
|
70
|
+
export declare function getContainerFitGeometry(): ContainerFitGeometry;
|
|
71
|
+
export declare function isContainerNodeManifest(manifest: Pick<NodeManifest, 'display'> | undefined): boolean;
|
|
72
|
+
export declare function ensureContainersFitChildren(nodes: Node[], { containerIds, getContainerFitGeometry: resolveContainerFitGeometry, getNodeDimensions: resolveNodeDimensions, ignoredNodeTypes, includeAncestors, }?: {
|
|
73
|
+
containerIds?: Iterable<string>;
|
|
74
|
+
getContainerFitGeometry?: (containerNode: Node) => ContainerFitGeometry | null | undefined;
|
|
75
|
+
getNodeDimensions?: (node: Node) => NodeDimensions;
|
|
76
|
+
ignoredNodeTypes?: string[];
|
|
77
|
+
includeAncestors?: boolean;
|
|
78
|
+
}): EnsureContainersFitChildrenResult;
|
|
79
|
+
export declare function getContainerNodeForEdge(sourceNode: Node, targetNode: Node, nodes: Node[]): Node | null;
|
|
80
|
+
export declare function resolveContainerPreview({ source, sourceHandleType, reactFlowInstance, ...options }: ContainerPreviewContext & ContainerPreviewOptions): PreviewGraphOverrides | null;
|
|
81
|
+
export declare function getContainerPlacement({ previewNode, isContainerId, }: {
|
|
82
|
+
previewNode: Pick<Node, 'data' | 'parentId'>;
|
|
83
|
+
isContainerId?: (containerId: string) => boolean;
|
|
84
|
+
}): ContainerPlacement | null;
|
|
85
|
+
export declare function placeContainerNode({ nodes, insertedNode, placement, safeArea, getContainerFitGeometry: resolveContainerFitGeometry, getNodeDimensions: resolveNodeDimensions, gap, downstreamNodeIds, edges, }: {
|
|
86
|
+
nodes: Node[];
|
|
87
|
+
insertedNode: Node;
|
|
88
|
+
placement: ContainerPlacement;
|
|
89
|
+
safeArea?: ContainerSafeArea;
|
|
90
|
+
getContainerFitGeometry?: (containerNode: Node) => ContainerFitGeometry | null | undefined;
|
|
91
|
+
getNodeDimensions?: (node: Node) => NodeDimensions;
|
|
92
|
+
gap?: number;
|
|
93
|
+
downstreamNodeIds?: Iterable<string>;
|
|
94
|
+
edges?: Edge[];
|
|
95
|
+
}): Node[];
|
|
96
|
+
export {};
|
|
97
|
+
//# sourceMappingURL=container.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../../../src/canvas/utils/container.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,EACJ,IAAI,EACJ,iBAAiB,EAElB,MAAM,0CAA0C,CAAC;AAOlD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAanF,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAOD,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;CACH;AAMD,MAAM,WAAW,iBAAiB;IAChC,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EA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AC,EAAE,IAAI,EAAE,CAAC;CAChB,GAAG,IAAI,EAAE,CAwET"}
|
|
@@ -0,0 +1,567 @@
|
|
|
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 centerInSafeArea(safeArea, nodeSize) {
|
|
166
|
+
return {
|
|
167
|
+
x: Math.max(safeArea.x, snapToGrid(safeArea.x + (safeArea.width - nodeSize.width) / 2)),
|
|
168
|
+
y: Math.max(safeArea.y, snapToGrid(safeArea.y + (safeArea.height - nodeSize.height) / 2))
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function getLocalNodePosition(node, containerNode, nodes) {
|
|
172
|
+
if (!node || node.id === containerNode.id) return null;
|
|
173
|
+
if (node.parentId === containerNode.id) return node.position;
|
|
174
|
+
const containerPosition = getAbsolutePosition(containerNode, nodes);
|
|
175
|
+
const nodePosition = node.parentId ? getAbsolutePosition(node, nodes) : node.position;
|
|
176
|
+
return {
|
|
177
|
+
x: nodePosition.x - containerPosition.x,
|
|
178
|
+
y: nodePosition.y - containerPosition.y
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
function getPlacementDirection(sourcePosition, targetPosition) {
|
|
182
|
+
if (!sourcePosition || !targetPosition) return sourcePosition ? 'right' : 'left';
|
|
183
|
+
return targetPosition.x >= sourcePosition.x ? 'right' : 'left';
|
|
184
|
+
}
|
|
185
|
+
function getSiblingNodes(containerId, nodes, insertedNodeId) {
|
|
186
|
+
return nodes.filter((node)=>node.id !== PREVIEW_NODE_ID && node.id !== insertedNodeId && node.parentId === containerId);
|
|
187
|
+
}
|
|
188
|
+
function resolveSequenceTopLeft({ sourceNode, targetNode, containerNode, nodes, safeArea, previewNodeSize, gap, getNodeDimensions }) {
|
|
189
|
+
const sourcePosition = getLocalNodePosition(sourceNode, containerNode, nodes);
|
|
190
|
+
const targetPosition = getLocalNodePosition(targetNode, containerNode, nodes);
|
|
191
|
+
const sourceSize = sourceNode ? getNodeDimensions(sourceNode) : void 0;
|
|
192
|
+
const targetSize = targetNode ? getNodeDimensions(targetNode) : void 0;
|
|
193
|
+
if (sourcePosition && sourceSize && targetPosition) {
|
|
194
|
+
const sourceRight = sourcePosition.x + sourceSize.width;
|
|
195
|
+
const targetLeft = targetPosition.x;
|
|
196
|
+
const centerX = targetLeft - sourceRight >= previewNodeSize.width + 2 * gap ? sourceRight + (targetLeft - sourceRight) / 2 : sourceRight + gap + previewNodeSize.width / 2;
|
|
197
|
+
return {
|
|
198
|
+
x: centerX - previewNodeSize.width / 2,
|
|
199
|
+
y: sourcePosition.y + sourceSize.height / 2 - previewNodeSize.height / 2
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
if (sourcePosition && sourceSize) return {
|
|
203
|
+
x: sourcePosition.x + sourceSize.width + gap,
|
|
204
|
+
y: sourcePosition.y + sourceSize.height / 2 - previewNodeSize.height / 2
|
|
205
|
+
};
|
|
206
|
+
if (targetPosition && targetSize) return {
|
|
207
|
+
x: targetPosition.x - previewNodeSize.width - gap,
|
|
208
|
+
y: targetPosition.y + targetSize.height / 2 - previewNodeSize.height / 2
|
|
209
|
+
};
|
|
210
|
+
return {
|
|
211
|
+
x: safeArea.x + safeArea.width / 2 - previewNodeSize.width / 2,
|
|
212
|
+
y: safeArea.y + safeArea.height / 2 - previewNodeSize.height / 2
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
function getContainerNodeForEdge(sourceNode, targetNode, nodes) {
|
|
216
|
+
if (sourceNode.parentId === targetNode.id) return targetNode;
|
|
217
|
+
if (targetNode.parentId === sourceNode.id) return sourceNode;
|
|
218
|
+
if (sourceNode.parentId && sourceNode.parentId === targetNode.parentId) return nodes.find((node)=>node.id === sourceNode.parentId) ?? null;
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
function handleMatches(edgeHandleId, handleId) {
|
|
222
|
+
return (edgeHandleId ?? DEFAULT_SOURCE_HANDLE_ID) === handleId;
|
|
223
|
+
}
|
|
224
|
+
function getOutgoingEdges(sourceNodeId, sourceHandleId, edges) {
|
|
225
|
+
return edges.filter((edge)=>edge.source !== PREVIEW_NODE_ID && edge.target !== PREVIEW_NODE_ID && edge.source === sourceNodeId && handleMatches(edge.sourceHandle, sourceHandleId));
|
|
226
|
+
}
|
|
227
|
+
function getSingleOutgoingEdge(sourceNodeId, sourceHandleId, edges) {
|
|
228
|
+
const outgoingEdges = getOutgoingEdges(sourceNodeId, sourceHandleId, edges);
|
|
229
|
+
return 1 === outgoingEdges.length ? outgoingEdges[0] : null;
|
|
230
|
+
}
|
|
231
|
+
function isPreviewGraphEdge(edge) {
|
|
232
|
+
return edge.source === PREVIEW_NODE_ID || edge.target === PREVIEW_NODE_ID;
|
|
233
|
+
}
|
|
234
|
+
function getDefaultNextContainerSequenceNodeId({ nodeId, edges, nodesById, containerId, isSequenceEdge }) {
|
|
235
|
+
const localOutgoingEdges = edges.filter((edge)=>{
|
|
236
|
+
if (isPreviewGraphEdge(edge) || edge.source !== nodeId) return false;
|
|
237
|
+
if (isSequenceEdge && !isSequenceEdge(edge)) return false;
|
|
238
|
+
const targetNode = nodesById.get(edge.target);
|
|
239
|
+
return edge.target === containerId || targetNode?.parentId === containerId;
|
|
240
|
+
});
|
|
241
|
+
return 1 === localOutgoingEdges.length ? localOutgoingEdges[0].target : null;
|
|
242
|
+
}
|
|
243
|
+
function collectDownstreamNodes({ targetNodeId, containerId, nodes, edges, isSequenceEdge, getNextNodeId }) {
|
|
244
|
+
if (!targetNodeId || targetNodeId === containerId) return [];
|
|
245
|
+
const nodesById = new Map(nodes.map((node)=>[
|
|
246
|
+
node.id,
|
|
247
|
+
node
|
|
248
|
+
]));
|
|
249
|
+
const collectedIds = [];
|
|
250
|
+
const visitedIds = new Set();
|
|
251
|
+
let currentNodeId = targetNodeId;
|
|
252
|
+
while(!visitedIds.has(currentNodeId)){
|
|
253
|
+
const currentNode = nodesById.get(currentNodeId);
|
|
254
|
+
if (!currentNode || currentNode.parentId !== containerId) break;
|
|
255
|
+
collectedIds.push(currentNodeId);
|
|
256
|
+
visitedIds.add(currentNodeId);
|
|
257
|
+
const nextNodeId = getNextNodeId?.({
|
|
258
|
+
nodeId: currentNodeId,
|
|
259
|
+
edges,
|
|
260
|
+
nodesById,
|
|
261
|
+
containerId
|
|
262
|
+
}) ?? getDefaultNextContainerSequenceNodeId({
|
|
263
|
+
nodeId: currentNodeId,
|
|
264
|
+
edges,
|
|
265
|
+
nodesById,
|
|
266
|
+
containerId,
|
|
267
|
+
isSequenceEdge
|
|
268
|
+
});
|
|
269
|
+
if (!nextNodeId || nextNodeId === containerId) break;
|
|
270
|
+
currentNodeId = nextNodeId;
|
|
271
|
+
}
|
|
272
|
+
return collectedIds;
|
|
273
|
+
}
|
|
274
|
+
function resolveInsertPreview({ source, sourceHandleType, reactFlowInstance, isContainerNode, getContainerSafeArea, previewNodeSize, gap, getNodeDimensions }) {
|
|
275
|
+
if ('source' !== sourceHandleType || !source.handleId) return null;
|
|
276
|
+
const replacedEdge = getSingleOutgoingEdge(source.nodeId, source.handleId, reactFlowInstance.getEdges());
|
|
277
|
+
if (!replacedEdge) return null;
|
|
278
|
+
const sourceNode = reactFlowInstance.getNode(replacedEdge.source);
|
|
279
|
+
const targetNode = reactFlowInstance.getNode(replacedEdge.target);
|
|
280
|
+
const nodes = reactFlowInstance.getNodes();
|
|
281
|
+
const containerNode = getContainerNodeForEdge(sourceNode, targetNode, nodes);
|
|
282
|
+
if (!containerNode) return null;
|
|
283
|
+
if (isContainerNode && !isContainerNode(containerNode)) return null;
|
|
284
|
+
const containerPlacement = getPreviewPlacement({
|
|
285
|
+
sourceNode,
|
|
286
|
+
targetNode,
|
|
287
|
+
containerNode,
|
|
288
|
+
nodes,
|
|
289
|
+
safeArea: getContainerSafeArea?.(containerNode),
|
|
290
|
+
previewNodeSize,
|
|
291
|
+
gap,
|
|
292
|
+
getNodeDimensions
|
|
293
|
+
});
|
|
294
|
+
const placement = {
|
|
295
|
+
containerId: containerPlacement.containerId,
|
|
296
|
+
sourceNodeId: sourceNode.id,
|
|
297
|
+
targetNodeId: targetNode.id,
|
|
298
|
+
mode: 'sequence'
|
|
299
|
+
};
|
|
300
|
+
return {
|
|
301
|
+
position: containerPlacement.centerPosition,
|
|
302
|
+
positionMode: 'center',
|
|
303
|
+
data: {
|
|
304
|
+
originalEdge: replacedEdge,
|
|
305
|
+
[PLACEMENT_DATA_KEY]: placement
|
|
306
|
+
},
|
|
307
|
+
target: {
|
|
308
|
+
nodeId: replacedEdge.target,
|
|
309
|
+
handleId: replacedEdge.targetHandle
|
|
310
|
+
},
|
|
311
|
+
containerId: containerPlacement.containerId
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
function resolveAppendPreview({ source, sourceHandleType, reactFlowInstance, ...options }) {
|
|
315
|
+
if ('source' !== sourceHandleType || !source.handleId) return null;
|
|
316
|
+
const sourceNode = reactFlowInstance.getNode(source.nodeId);
|
|
317
|
+
if (!sourceNode?.parentId) return null;
|
|
318
|
+
const outgoingEdges = getOutgoingEdges(source.nodeId, source.handleId, reactFlowInstance.getEdges());
|
|
319
|
+
if (outgoingEdges.length > 0) return null;
|
|
320
|
+
const nodes = reactFlowInstance.getNodes();
|
|
321
|
+
const containerNode = nodes.find((node)=>node.id === sourceNode.parentId);
|
|
322
|
+
if (options.isContainerNode && !options.isContainerNode(containerNode)) return null;
|
|
323
|
+
const continuationTarget = options.getContainerContinuationTarget?.({
|
|
324
|
+
containerNode,
|
|
325
|
+
sourceNode,
|
|
326
|
+
source,
|
|
327
|
+
reactFlowInstance
|
|
328
|
+
});
|
|
329
|
+
if (!continuationTarget) return null;
|
|
330
|
+
const targetNode = continuationTarget.nodeId === containerNode.id ? containerNode : reactFlowInstance.getNode(continuationTarget.nodeId);
|
|
331
|
+
const containerPlacement = getPreviewPlacement({
|
|
332
|
+
sourceNode,
|
|
333
|
+
targetNode,
|
|
334
|
+
containerNode,
|
|
335
|
+
nodes,
|
|
336
|
+
safeArea: options.getContainerSafeArea?.(containerNode),
|
|
337
|
+
previewNodeSize: options.previewNodeSize,
|
|
338
|
+
gap: options.gap,
|
|
339
|
+
avoidSiblings: options.avoidSiblings ?? true,
|
|
340
|
+
getNodeDimensions: options.getNodeDimensions
|
|
341
|
+
});
|
|
342
|
+
const placement = {
|
|
343
|
+
containerId: containerPlacement.containerId,
|
|
344
|
+
sourceNodeId: sourceNode.id,
|
|
345
|
+
targetNodeId: continuationTarget.nodeId,
|
|
346
|
+
mode: 'sequence'
|
|
347
|
+
};
|
|
348
|
+
return {
|
|
349
|
+
position: containerPlacement.centerPosition,
|
|
350
|
+
positionMode: 'center',
|
|
351
|
+
data: {
|
|
352
|
+
[PLACEMENT_DATA_KEY]: placement
|
|
353
|
+
},
|
|
354
|
+
target: continuationTarget,
|
|
355
|
+
containerId: containerPlacement.containerId
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
function resolveContainerPreview({ source, sourceHandleType, reactFlowInstance, ...options }) {
|
|
359
|
+
return resolveInsertPreview({
|
|
360
|
+
source,
|
|
361
|
+
sourceHandleType,
|
|
362
|
+
reactFlowInstance,
|
|
363
|
+
...options
|
|
364
|
+
}) ?? resolveAppendPreview({
|
|
365
|
+
source,
|
|
366
|
+
sourceHandleType,
|
|
367
|
+
reactFlowInstance,
|
|
368
|
+
...options
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
function getPreviewPlacement({ sourceNode, targetNode, containerNode, nodes, containerAbsolutePosition = getAbsolutePosition(containerNode, nodes), safeArea, previewNodeSize = {
|
|
372
|
+
width: DEFAULT_NODE_SIZE,
|
|
373
|
+
height: DEFAULT_NODE_SIZE
|
|
374
|
+
}, gap = CONTAINER_SEQUENCE_GAP_PX, avoidSiblings = false, getNodeDimensions: resolveNodeDimensions = container_getNodeDimensions }) {
|
|
375
|
+
const resolvedSafeArea = getSafeArea(containerNode, safeArea);
|
|
376
|
+
const sourcePosition = getLocalNodePosition(sourceNode, containerNode, nodes);
|
|
377
|
+
const targetPosition = getLocalNodePosition(targetNode, containerNode, nodes);
|
|
378
|
+
const direction = getPlacementDirection(sourcePosition, targetPosition);
|
|
379
|
+
const initialPosition = resolveSequenceTopLeft({
|
|
380
|
+
sourceNode,
|
|
381
|
+
targetNode,
|
|
382
|
+
containerNode,
|
|
383
|
+
nodes,
|
|
384
|
+
safeArea: resolvedSafeArea,
|
|
385
|
+
previewNodeSize,
|
|
386
|
+
gap,
|
|
387
|
+
getNodeDimensions: resolveNodeDimensions
|
|
388
|
+
});
|
|
389
|
+
const collisionPosition = avoidSiblings ? getNonOverlappingPositionForDirection(getSiblingNodes(containerNode.id, nodes), initialPosition, previewNodeSize, direction, gap) : initialPosition;
|
|
390
|
+
const position = clampTopLeftToSafeArea(collisionPosition, resolvedSafeArea, previewNodeSize);
|
|
391
|
+
return {
|
|
392
|
+
containerId: containerNode.id,
|
|
393
|
+
centerPosition: {
|
|
394
|
+
x: containerAbsolutePosition.x + position.x + previewNodeSize.width / 2,
|
|
395
|
+
y: containerAbsolutePosition.y + position.y + previewNodeSize.height / 2
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
function getNodeCenterY(position, nodeSize) {
|
|
400
|
+
return position.y + nodeSize.height / 2;
|
|
401
|
+
}
|
|
402
|
+
function getInsertedPosition({ sourceNode, targetNode, insertedNode, containerNode, nodes, safeArea, insertedNodeSize, gap, getNodeDimensions }) {
|
|
403
|
+
const sourcePosition = getLocalNodePosition(sourceNode, containerNode, nodes);
|
|
404
|
+
const targetPosition = getLocalNodePosition(targetNode, containerNode, nodes);
|
|
405
|
+
const sourceSize = sourceNode ? getNodeDimensions(sourceNode) : void 0;
|
|
406
|
+
const targetSize = targetNode ? getNodeDimensions(targetNode) : void 0;
|
|
407
|
+
const sourceIsContainer = sourceNode?.id === containerNode.id;
|
|
408
|
+
const targetIsContainer = targetNode?.id === containerNode.id;
|
|
409
|
+
if (sourcePosition && sourceSize && !sourceIsContainer) return {
|
|
410
|
+
x: Math.max(safeArea.x, snapToGrid(sourcePosition.x + sourceSize.width + gap)),
|
|
411
|
+
y: clampTopToSafeArea(snapToGrid(getNodeCenterY(sourcePosition, sourceSize) - insertedNodeSize.height / 2), safeArea, insertedNodeSize)
|
|
412
|
+
};
|
|
413
|
+
if (targetPosition && targetSize && !targetIsContainer) return {
|
|
414
|
+
x: Math.max(safeArea.x, snapToGrid(targetPosition.x - insertedNodeSize.width - gap)),
|
|
415
|
+
y: clampTopToSafeArea(snapToGrid(getNodeCenterY(targetPosition, targetSize) - insertedNodeSize.height / 2), safeArea, insertedNodeSize)
|
|
416
|
+
};
|
|
417
|
+
return {
|
|
418
|
+
x: Math.max(safeArea.x, snapToGrid(insertedNode.position.x)),
|
|
419
|
+
y: clampTopToSafeArea(snapToGrid(insertedNode.position.y), safeArea, insertedNodeSize)
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
function getNodeDepth(node, nodesById) {
|
|
423
|
+
let depth = 0;
|
|
424
|
+
let parentId = node?.parentId;
|
|
425
|
+
while(parentId){
|
|
426
|
+
depth += 1;
|
|
427
|
+
parentId = nodesById.get(parentId)?.parentId;
|
|
428
|
+
}
|
|
429
|
+
return depth;
|
|
430
|
+
}
|
|
431
|
+
function sortContainerSizeChanges(changes, nodes) {
|
|
432
|
+
const nodesById = new Map(nodes.map((node)=>[
|
|
433
|
+
node.id,
|
|
434
|
+
node
|
|
435
|
+
]));
|
|
436
|
+
return [
|
|
437
|
+
...changes
|
|
438
|
+
].sort((left, right)=>{
|
|
439
|
+
const leftNode = nodesById.get(left.containerId);
|
|
440
|
+
const rightNode = nodesById.get(right.containerId);
|
|
441
|
+
const depthDifference = getNodeDepth(rightNode, nodesById) - getNodeDepth(leftNode, nodesById);
|
|
442
|
+
if (0 !== depthDifference) return depthDifference;
|
|
443
|
+
if (leftNode.parentId === rightNode.parentId) return leftNode.position.x - rightNode.position.x;
|
|
444
|
+
return 0;
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
function pushSiblingsAfterContainerGrowth({ nodes, changes, getNodeDimensions, gap }) {
|
|
448
|
+
let shifted = false;
|
|
449
|
+
let nextNodes = nodes;
|
|
450
|
+
for (const change of sortContainerSizeChanges(changes, nextNodes)){
|
|
451
|
+
const widthDelta = change.nextSize.width - change.previousSize.width;
|
|
452
|
+
if (widthDelta <= 0) continue;
|
|
453
|
+
const containerNode = nextNodes.find((node)=>node.id === change.containerId);
|
|
454
|
+
const oldRight = containerNode.position.x + change.previousSize.width;
|
|
455
|
+
const newRight = containerNode.position.x + change.nextSize.width;
|
|
456
|
+
const containerTop = containerNode.position.y;
|
|
457
|
+
const containerBottom = containerNode.position.y + Math.max(change.previousSize.height, change.nextSize.height);
|
|
458
|
+
nextNodes = nextNodes.map((node)=>{
|
|
459
|
+
if (node.id === containerNode.id || node.parentId !== containerNode.parentId) return node;
|
|
460
|
+
const nodeSize = getNodeDimensions(node);
|
|
461
|
+
const isRightSibling = node.position.x >= oldRight;
|
|
462
|
+
const verticallyOverlaps = rangesOverlap(node.position.y, node.position.y + nodeSize.height, containerTop, containerBottom);
|
|
463
|
+
if (!isRightSibling || !verticallyOverlaps) return node;
|
|
464
|
+
const nextX = Math.max(node.position.x + widthDelta, snapUpToGrid(newRight + gap));
|
|
465
|
+
if (nextX === node.position.x) return node;
|
|
466
|
+
shifted = true;
|
|
467
|
+
return {
|
|
468
|
+
...node,
|
|
469
|
+
position: {
|
|
470
|
+
...node.position,
|
|
471
|
+
x: nextX
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
return {
|
|
477
|
+
nodes: nextNodes,
|
|
478
|
+
shifted
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
function fitContainersAndPushSiblings({ nodes, containerIds, getContainerFitGeometry, getNodeDimensions, gap }) {
|
|
482
|
+
let nextNodes = nodes;
|
|
483
|
+
for(let iteration = 0; iteration < 10; iteration += 1){
|
|
484
|
+
const fitResult = ensureContainersFitChildren(nextNodes, {
|
|
485
|
+
containerIds,
|
|
486
|
+
getContainerFitGeometry,
|
|
487
|
+
getNodeDimensions,
|
|
488
|
+
includeAncestors: true
|
|
489
|
+
});
|
|
490
|
+
nextNodes = fitResult.nodes;
|
|
491
|
+
if (0 === fitResult.changes.length) break;
|
|
492
|
+
const pushResult = pushSiblingsAfterContainerGrowth({
|
|
493
|
+
nodes: nextNodes,
|
|
494
|
+
changes: fitResult.changes,
|
|
495
|
+
getNodeDimensions,
|
|
496
|
+
gap
|
|
497
|
+
});
|
|
498
|
+
nextNodes = pushResult.nodes;
|
|
499
|
+
if (!pushResult.shifted) break;
|
|
500
|
+
}
|
|
501
|
+
return nextNodes;
|
|
502
|
+
}
|
|
503
|
+
function getContainerPlacement({ previewNode, isContainerId }) {
|
|
504
|
+
const placement = previewNode.data?.[PLACEMENT_DATA_KEY];
|
|
505
|
+
if (!placement) return null;
|
|
506
|
+
if (previewNode.parentId && placement.containerId !== previewNode.parentId) return null;
|
|
507
|
+
return isContainerId && !isContainerId(placement.containerId) ? null : placement;
|
|
508
|
+
}
|
|
509
|
+
function placeContainerNode({ nodes, insertedNode, placement, safeArea, getContainerFitGeometry: resolveContainerFitGeometry = container_getContainerFitGeometry, getNodeDimensions: resolveNodeDimensions = container_getNodeDimensions, gap = CONTAINER_SEQUENCE_GAP_PX, downstreamNodeIds, edges }) {
|
|
510
|
+
const containerNode = nodes.find((node)=>node.id === placement.containerId);
|
|
511
|
+
const nodesById = new Map(nodes.map((node)=>[
|
|
512
|
+
node.id,
|
|
513
|
+
node
|
|
514
|
+
]));
|
|
515
|
+
const insertedSize = resolveNodeDimensions(insertedNode);
|
|
516
|
+
const resolvedSafeArea = getSafeArea(containerNode, safeArea);
|
|
517
|
+
const positionedNode = 'first-child' === placement.mode ? {
|
|
518
|
+
...insertedNode,
|
|
519
|
+
position: centerInSafeArea(resolvedSafeArea, insertedSize)
|
|
520
|
+
} : {
|
|
521
|
+
...insertedNode,
|
|
522
|
+
position: getInsertedPosition({
|
|
523
|
+
sourceNode: placement.sourceNodeId ? nodesById.get(placement.sourceNodeId) : void 0,
|
|
524
|
+
targetNode: placement.targetNodeId ? nodesById.get(placement.targetNodeId) : void 0,
|
|
525
|
+
insertedNode,
|
|
526
|
+
containerNode,
|
|
527
|
+
nodes,
|
|
528
|
+
safeArea: resolvedSafeArea,
|
|
529
|
+
insertedNodeSize: insertedSize,
|
|
530
|
+
gap,
|
|
531
|
+
getNodeDimensions: resolveNodeDimensions
|
|
532
|
+
})
|
|
533
|
+
};
|
|
534
|
+
const targetNode = placement.targetNodeId && placement.targetNodeId !== placement.containerId ? nodesById.get(placement.targetNodeId) : void 0;
|
|
535
|
+
const fallbackTargetIds = placement.targetNodeId && placement.targetNodeId !== placement.containerId ? [
|
|
536
|
+
placement.targetNodeId
|
|
537
|
+
] : [];
|
|
538
|
+
const idsToShift = new Set(downstreamNodeIds ?? (edges ? collectDownstreamNodes({
|
|
539
|
+
targetNodeId: placement.targetNodeId,
|
|
540
|
+
containerId: placement.containerId,
|
|
541
|
+
nodes,
|
|
542
|
+
edges
|
|
543
|
+
}) : fallbackTargetIds));
|
|
544
|
+
const requiredTargetLeft = positionedNode.position.x + insertedSize.width + gap;
|
|
545
|
+
const downstreamShift = targetNode && targetNode.position.x < requiredTargetLeft ? snapUpToGrid(requiredTargetLeft - targetNode.position.x) : 0;
|
|
546
|
+
const positionedNodes = nodes.map((node)=>{
|
|
547
|
+
if (node.id === insertedNode.id) return positionedNode;
|
|
548
|
+
if (downstreamShift > 0 && idsToShift.has(node.id)) return {
|
|
549
|
+
...node,
|
|
550
|
+
position: {
|
|
551
|
+
...node.position,
|
|
552
|
+
x: node.position.x + downstreamShift
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
return node;
|
|
556
|
+
});
|
|
557
|
+
return fitContainersAndPushSiblings({
|
|
558
|
+
nodes: positionedNodes,
|
|
559
|
+
containerIds: [
|
|
560
|
+
placement.containerId
|
|
561
|
+
],
|
|
562
|
+
getContainerFitGeometry: resolveContainerFitGeometry,
|
|
563
|
+
getNodeDimensions: resolveNodeDimensions,
|
|
564
|
+
gap
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
export { CONTAINER_FRAME_INSET_PX, CONTAINER_SEQUENCE_GAP_PX, DEFAULT_CONTAINER_HEIGHT, DEFAULT_CONTAINER_MIN_HEIGHT, DEFAULT_CONTAINER_MIN_WIDTH, DEFAULT_CONTAINER_WIDTH, ensureContainersFitChildren, container_getContainerFitGeometry as getContainerFitGeometry, getContainerNodeForEdge, getContainerPlacement, container_getContainerSafeArea as getContainerSafeArea, container_getNodeDimensions as getNodeDimensions, isContainerNodeManifest, placeContainerNode, resolveContainerPreview };
|