@canmingir/link 1.2.39 → 1.2.41
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/package.json
CHANGED
|
@@ -26,10 +26,12 @@ const FlowViewport = ({
|
|
|
26
26
|
const [zoom, setZoom] = useState(1);
|
|
27
27
|
const [isDragging, setIsDragging] = useState(false);
|
|
28
28
|
const [selectionBox, setSelectionBox] = useState(null);
|
|
29
|
+
const [shouldCenter, setShouldCenter] = useState(true);
|
|
29
30
|
|
|
30
31
|
const containerRef = useRef(null);
|
|
31
32
|
const selectionBoxRef = useRef(null);
|
|
32
33
|
const mousePositionRef = useRef({ x: 0, y: 0 });
|
|
34
|
+
const innerRef = useRef(null);
|
|
33
35
|
|
|
34
36
|
const {
|
|
35
37
|
clearSelection,
|
|
@@ -40,6 +42,28 @@ const FlowViewport = ({
|
|
|
40
42
|
selectedIds,
|
|
41
43
|
} = useSelection();
|
|
42
44
|
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
const container = containerRef.current;
|
|
47
|
+
const inner = innerRef.current;
|
|
48
|
+
if (!container || !inner) return;
|
|
49
|
+
|
|
50
|
+
const observer = new ResizeObserver(() => {
|
|
51
|
+
const contentWidth = inner.scrollWidth;
|
|
52
|
+
const contentHeight = inner.scrollHeight;
|
|
53
|
+
const containerWidth = container.clientWidth;
|
|
54
|
+
const containerHeight = container.clientHeight;
|
|
55
|
+
|
|
56
|
+
const exceeds =
|
|
57
|
+
contentWidth > containerWidth || contentHeight > containerHeight;
|
|
58
|
+
setShouldCenter(!exceeds);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
observer.observe(inner);
|
|
62
|
+
observer.observe(container);
|
|
63
|
+
|
|
64
|
+
return () => observer.disconnect();
|
|
65
|
+
}, []);
|
|
66
|
+
|
|
43
67
|
useEffect(() => {
|
|
44
68
|
const handleMouseMove = (e) => {
|
|
45
69
|
mousePositionRef.current = { x: e.clientX, y: e.clientY };
|
|
@@ -252,6 +276,7 @@ const FlowViewport = ({
|
|
|
252
276
|
>
|
|
253
277
|
<SelectionOverlay box={selectionBox} selectionColor={selectionColor} />
|
|
254
278
|
<Box
|
|
279
|
+
ref={innerRef}
|
|
255
280
|
sx={{
|
|
256
281
|
transform: `translate(${offset.x}px, ${offset.y}px) scale(${zoom})`,
|
|
257
282
|
transformOrigin: "center center",
|
|
@@ -259,7 +284,7 @@ const FlowViewport = ({
|
|
|
259
284
|
height: height,
|
|
260
285
|
display: "flex",
|
|
261
286
|
alignItems: "center",
|
|
262
|
-
justifyContent:
|
|
287
|
+
justifyContent: shouldCenter ? "center" : "flex-start",
|
|
263
288
|
transition: isDragging ? "none" : "transform 0.1s ease-out",
|
|
264
289
|
pointerEvents: "auto",
|
|
265
290
|
position: "relative",
|
|
@@ -20,6 +20,7 @@ const FlowNodeView = ({
|
|
|
20
20
|
onConnect,
|
|
21
21
|
}) => {
|
|
22
22
|
const hasChildren = Array.isArray(node.children) && node.children.length > 0;
|
|
23
|
+
const isVirtualRoot = !!node.virtual;
|
|
23
24
|
|
|
24
25
|
const {
|
|
25
26
|
baseStyle,
|
|
@@ -146,6 +147,36 @@ const FlowNodeView = ({
|
|
|
146
147
|
);
|
|
147
148
|
};
|
|
148
149
|
|
|
150
|
+
if (isVirtualRoot) {
|
|
151
|
+
return (
|
|
152
|
+
<Box
|
|
153
|
+
ref={containerRef}
|
|
154
|
+
sx={{
|
|
155
|
+
display: "flex",
|
|
156
|
+
flexDirection: isHorizontal ? "row" : "column",
|
|
157
|
+
alignItems: "flex-end",
|
|
158
|
+
gap,
|
|
159
|
+
position: "relative",
|
|
160
|
+
}}
|
|
161
|
+
>
|
|
162
|
+
{node.children.map((child) => (
|
|
163
|
+
<FlowNode
|
|
164
|
+
key={child.id}
|
|
165
|
+
node={child}
|
|
166
|
+
type={type}
|
|
167
|
+
variant={variant}
|
|
168
|
+
style={style}
|
|
169
|
+
plugin={plugin}
|
|
170
|
+
registerRef={(el) => (childRefs.current[child.id] = el)}
|
|
171
|
+
onDrag={() => setConnectorTick((t) => t + 1)}
|
|
172
|
+
isRoot={false}
|
|
173
|
+
onConnect={onConnect}
|
|
174
|
+
/>
|
|
175
|
+
))}
|
|
176
|
+
</Box>
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
149
180
|
return (
|
|
150
181
|
<Box
|
|
151
182
|
ref={containerRef}
|