@canmingir/link 1.2.19 → 1.2.21
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
|
@@ -11,6 +11,7 @@ export const Flow = ({
|
|
|
11
11
|
plugin,
|
|
12
12
|
editable = false,
|
|
13
13
|
onChange,
|
|
14
|
+
height,
|
|
14
15
|
}) => {
|
|
15
16
|
const [floatingNodes, setFloatingNodes] = useState([]);
|
|
16
17
|
|
|
@@ -72,6 +73,7 @@ export const Flow = ({
|
|
|
72
73
|
onCut={editable ? handleCut : undefined}
|
|
73
74
|
onConnect={editable ? handleConnect : undefined}
|
|
74
75
|
floatingNodes={floatingNodes}
|
|
76
|
+
height={height}
|
|
75
77
|
/>
|
|
76
78
|
);
|
|
77
79
|
};
|
|
@@ -16,6 +16,7 @@ const FlowNode = ({
|
|
|
16
16
|
style,
|
|
17
17
|
plugin,
|
|
18
18
|
node,
|
|
19
|
+
height,
|
|
19
20
|
...props
|
|
20
21
|
}) => {
|
|
21
22
|
if (!isRoot) {
|
|
@@ -48,6 +49,7 @@ const FlowNode = ({
|
|
|
48
49
|
variant={variant}
|
|
49
50
|
style={style}
|
|
50
51
|
plugin={plugin}
|
|
52
|
+
height={height}
|
|
51
53
|
>
|
|
52
54
|
{node && (
|
|
53
55
|
<FlowNodeView
|
|
@@ -16,6 +16,9 @@ const FlowViewport = ({
|
|
|
16
16
|
variant,
|
|
17
17
|
style,
|
|
18
18
|
plugin,
|
|
19
|
+
height = "100vh",
|
|
20
|
+
sx = {},
|
|
21
|
+
...rest
|
|
19
22
|
}) => {
|
|
20
23
|
const clampZoom = (zoom) => Math.min(2.5, Math.max(0.25, zoom));
|
|
21
24
|
|
|
@@ -50,16 +53,34 @@ const FlowViewport = ({
|
|
|
50
53
|
}, []);
|
|
51
54
|
|
|
52
55
|
useEffect(() => {
|
|
56
|
+
const container = containerRef.current;
|
|
57
|
+
if (!container) return;
|
|
58
|
+
|
|
53
59
|
const onWheel = (e) => {
|
|
54
60
|
const wantsZoom = e.ctrlKey || e.metaKey;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
|
|
62
|
+
if (wantsZoom) {
|
|
63
|
+
e.preventDefault();
|
|
64
|
+
const direction = e.deltaY > 0 ? -1 : 1;
|
|
65
|
+
const factor = direction > 0 ? 1.1 : 1 / 1.1;
|
|
66
|
+
setZoom((z) => clampZoom(z * factor));
|
|
67
|
+
} else if (e.shiftKey) {
|
|
68
|
+
e.preventDefault();
|
|
69
|
+
const delta = e.deltaX !== 0 ? e.deltaX : e.deltaY;
|
|
70
|
+
setOffset((prev) => ({
|
|
71
|
+
x: prev.x - delta,
|
|
72
|
+
y: prev.y,
|
|
73
|
+
}));
|
|
74
|
+
} else {
|
|
75
|
+
e.preventDefault();
|
|
76
|
+
setOffset((prev) => ({
|
|
77
|
+
x: prev.x - e.deltaX,
|
|
78
|
+
y: prev.y - e.deltaY,
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
60
81
|
};
|
|
61
|
-
|
|
62
|
-
return () =>
|
|
82
|
+
container.addEventListener("wheel", onWheel, { passive: false });
|
|
83
|
+
return () => container.removeEventListener("wheel", onWheel);
|
|
63
84
|
}, []);
|
|
64
85
|
|
|
65
86
|
useEffect(() => {
|
|
@@ -225,13 +246,14 @@ const FlowViewport = ({
|
|
|
225
246
|
transform: `translate(${offset.x}px, ${offset.y}px) scale(${zoom})`,
|
|
226
247
|
transformOrigin: "center center",
|
|
227
248
|
width: "100%",
|
|
228
|
-
height:
|
|
249
|
+
height: height,
|
|
229
250
|
display: "flex",
|
|
230
251
|
alignItems: "center",
|
|
231
|
-
justifyContent: "center",
|
|
252
|
+
justifyContent: variant === "horizontal" ? "flex-start" : "center",
|
|
232
253
|
transition: isDragging ? "none" : "transform 0.1s ease-out",
|
|
233
254
|
pointerEvents: "auto",
|
|
234
255
|
position: "relative",
|
|
256
|
+
pl: variant === "horizontal" ? 4 : 0,
|
|
235
257
|
}}
|
|
236
258
|
>
|
|
237
259
|
{children}
|