Skip to content

Commit b7594a8

Browse files
committed
feat: update node components to enhance resizing functionality and improve drag interactions
1 parent 75cf670 commit b7594a8

File tree

4 files changed

+32
-23
lines changed

4 files changed

+32
-23
lines changed

frontend/package.json.md5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
26a1cb68f011440ec834ec05278dcf9a
1+
f510197448dce85168f8ff06bb3b3003

frontend/src/components/canvas-view.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
useReactFlow,
1616
getNodesBounds,
1717
getViewportForBounds,
18+
ControlButton,
1819
} from "@xyflow/react";
1920
import { toPng } from "html-to-image";
2021
import { useState, useCallback, useMemo, useRef, useEffect } from "react";
@@ -261,8 +262,6 @@ function CanvasEditor({ project, onBack }: CanvasViewProps) {
261262
const dragRef = useRef<{ id: string; position: { x: number; y: number } } | null>(null);
262263

263264

264-
265-
266265
// group 子节点跟随拖动
267266
const onNodeDrag = useCallback(
268267
(_: React.MouseEvent, node: Node) => {
@@ -278,7 +277,7 @@ function CanvasEditor({ project, onBack }: CanvasViewProps) {
278277
// Find intersecting nodes
279278
// Note: We use the group node's current dimension (which React Flow tracks)
280279
const intersectingNodes = getIntersectingNodes(node).filter(
281-
(n) => n.type !== "group" && n.parentId !== node.id
280+
(n) => n.parentId !== node.id
282281
);
283282

284283
if (intersectingNodes.length > 0) {
@@ -547,9 +546,13 @@ function CanvasEditor({ project, onBack }: CanvasViewProps) {
547546
panOnScroll
548547
onNodeDragStart={onNodeDragStart}
549548
onNodeDragStop={onNodeDragStop}
549+
onNodeDrag={onNodeDrag}
550550
onNodeClick={onNodeClick}
551+
minZoom={0.1}
552+
maxZoom={2}
553+
proOptions={{ hideAttribution: true }}
551554
>
552-
<MiniMap />
555+
<MiniMap pannable />
553556
<Background variant={BackgroundVariant.Cross} gap={12} size={1} />
554557
</ReactFlow>
555558
</div>

frontend/src/components/nodes/base-node.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Handle, Position, useReactFlow, type NodeProps, NodeResizeControl, NodeToolbar } from "@xyflow/react";
1+
import { Handle, Position, useReactFlow, type NodeProps, NodeResizeControl, NodeToolbar, EdgeText } from "@xyflow/react";
22
import { Card } from "@/components/ui/card";
33
import { Spinner } from "@/components/ui/spinner";
44
import { NodeParametersPanel } from "./node-parameters-panel";
@@ -30,8 +30,10 @@ export function BaseNode({
3030
promptPlaceholder,
3131
minWidth = 200,
3232
minHeight = 200,
33-
maxWidth = 400,
34-
maxHeight = 400,
33+
maxWidth,
34+
maxHeight,
35+
width,
36+
height,
3537
}: BaseNodeProps) {
3638
const nodeData = data as unknown as BaseNodeData;
3739
const { updateNodeData, getNodes, updateNode } = useReactFlow();
@@ -41,10 +43,12 @@ export function BaseNode({
4143
const isSelected = selected && selectedNodesCount === 1;
4244

4345
useEffect(() => {
44-
updateNode(id, {
45-
width: minWidth,
46-
height: minHeight
47-
});
46+
if (!width && !height) {
47+
updateNode(id, {
48+
width: minWidth,
49+
height: minHeight
50+
});
51+
}
4852
}, []);
4953

5054
return (

frontend/src/components/nodes/group-node.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,19 @@ export const GroupNode = memo(({ id, data, selected, }: NodeProps) => {
146146
return (
147147
<div className={cn(["h-full w-full relative group border rounded-2xl bg-muted/20", selected && "border-primary bg-primary/5 "])}>
148148

149-
<NodeResizeControl
150-
minWidth={100}
151-
minHeight={100}
152-
position="bottom-right"
153-
className="bg-transparent border-none"
154-
>
155-
<div
156-
className="absolute bottom-0 right-0 p-4 rounded-br-2xl cursor-nwse-resize bg-transparent nodrag z-50 pointer-events-auto"
157-
style={{ cursor: 'nwse-resize' }}
158-
/>
159-
</NodeResizeControl>
149+
{isSelected && (
150+
<NodeResizeControl
151+
minWidth={100}
152+
minHeight={100}
153+
position="bottom-right"
154+
className="bg-transparent border-none"
155+
>
156+
<div
157+
className="absolute bottom-0 right-0 p-4 rounded-br-2xl cursor-nwse-resize bg-transparent nodrag z-50 pointer-events-auto"
158+
style={{ cursor: 'nwse-resize' }}
159+
/>
160+
</NodeResizeControl>
161+
)}
160162

161163
<NodeToolbar
162164
isVisible={isSelected}

0 commit comments

Comments
 (0)