Skip to content

Commit 287e907

Browse files
committed
fix dragging rect nodes on the canvas, make rect nodes connectable
1 parent ab7897a commit 287e907

File tree

6 files changed

+56
-9
lines changed

6 files changed

+56
-9
lines changed

apps/vps-web/src/app/custom-nodes/classes/rect-node-class.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ w-min h-min
6666
this.updated();
6767
}}
6868
contentEditable={true}
69+
pointerdown={(e: PointerEvent) => {
70+
if (e.shiftKey && this.rectElement) {
71+
this.rectElement.contentEditable = 'false';
72+
}
73+
}}
74+
pointerup={(e: PointerEvent) => {
75+
if (this.rectElement) {
76+
this.rectElement.contentEditable = 'true';
77+
}
78+
}}
6979
>
7080
{nodeInfo?.text ?? ''}
7181
</div>

apps/vps-web/src/app/custom-nodes/rect-node.tsx

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
Rect,
99
renderElement,
1010
Theme,
11+
ThumbConnectionType,
12+
ThumbType,
1113
visualNodeFactory,
1214
} from '@devhelpr/visual-programming-system';
1315
import { NodeInfo } from '@devhelpr/web-flow-executor';
@@ -55,14 +57,38 @@ export const getRectNode =
5557
computeAsync,
5658
initializeCompute,
5759
false,
58-
flowNode?.width ?? 10,
59-
flowNode?.height ?? 10,
60-
[],
60+
flowNode?.width ?? 200,
61+
flowNode?.height ?? 100,
62+
[
63+
{
64+
thumbType: ThumbType.Center,
65+
thumbIndex: 0,
66+
connectionType: ThumbConnectionType.startOrEnd,
67+
color: 'white',
68+
label: ' ',
69+
name: 'input-output',
70+
hidden: true,
71+
maxConnections: -1,
72+
},
73+
],
6174
(_values?: InitialValues): FormField[] => {
6275
return [];
6376
},
6477
(nodeInstance) => {
65-
if (!flowNode) {
78+
console.log('before rect-node !flowNod', flowNode);
79+
const flowNodeInstance: FlowNode<NodeInfo> = flowNode ?? {
80+
id: nodeInstance.node.id,
81+
x: 0,
82+
y: 0,
83+
width: 200,
84+
height: 100,
85+
nodeInfo: {
86+
fillColor: 'black',
87+
strokeColor: 'white',
88+
strokeWidth: 2,
89+
} as any,
90+
};
91+
if (!flowNodeInstance) {
6692
return;
6793
}
6894
rect = nodeInstance.rect;
@@ -78,7 +104,13 @@ export const getRectNode =
78104
if (childNodeInstance) {
79105
childNodeInstance.remove();
80106
}
81-
renderElement(rectNode.render(flowNode), childNodeWrapper);
107+
108+
console.log(
109+
'render rect-node',
110+
flowNodeInstance.width,
111+
flowNodeInstance.height
112+
);
113+
renderElement(rectNode.render(flowNodeInstance), childNodeWrapper);
82114
nodeRenderElement = (
83115
rect?.nodeComponent?.domElement as HTMLElement
84116
).querySelector('.child-node-wrapper > *:first-child');
@@ -124,6 +156,9 @@ export const getRectNode =
124156
childNodeWrapperClass: 'child-node-wrapper',
125157
centerToYPositionThumb: false,
126158
skipDetermineSizeOnInit: true,
159+
160+
isRectThumb: true,
161+
rectThumbWithStraightConnections: true,
127162
},
128163
<div class="child-instance"></div>,
129164
true

libs/app-canvas/src/app/components/toolbar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ export function Toolbar<T extends BaseNodeInfo>(props: {
158158
props.getCanvasAction() !== CanvasAction.newConnectionCreated
159159
) {
160160
const outputConnectionInfo = (
161-
(info.node as IConnectionNodeComponent<T>).startNode
161+
(info.node as IConnectionNodeComponent<T>)?.startNode
162162
?.nodeInfo as BaseNodeInfo
163-
).outputConnectionInfo;
163+
)?.outputConnectionInfo;
164164
if (outputConnectionInfo) {
165165
popupTriggeredFromEffect = false;
166166
// skipHide = true;

libs/visual-programming-system/src/canvas-app/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,7 @@ export class FlowCanvas<T extends BaseNodeInfo>
14281428
if (!rectInstance || !rectInstance.nodeComponent) {
14291429
throw new Error('rectInstance is undefined');
14301430
}
1431+
this.rectInstanceList[rectInstance.nodeComponent.id] = rectInstance;
14311432
rectInstance.nodeComponent.nodeInfo = nodeInfo;
14321433
if (this.onCanvasUpdated) {
14331434
this.onCanvasUpdated(undefined, undefined, FlowChangeType.AddNode);

libs/visual-programming-system/src/components/rect-thumb.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ export class RectThumb<T extends BaseNodeInfo> extends Rect<T> {
253253
this.canvasUpdated,
254254
undefined,
255255
this.containerNode,
256-
undefined,
256+
this.theme,
257257
undefined,
258258
this.rootElement
259259
)
@@ -274,7 +274,7 @@ export class RectThumb<T extends BaseNodeInfo> extends Rect<T> {
274274
this.canvasUpdated,
275275
undefined,
276276
this.containerNode,
277-
undefined,
277+
this.theme,
278278
undefined,
279279
this.rootElement
280280
);

libs/visual-programming-system/src/utils/create-rect-node.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ export const createRectNode = <T extends BaseNodeInfo>(
367367
classNames: '',
368368
hasCustomStyling: settings?.hasCustomStyling ?? false,
369369
customClassName: settings?.customClassName,
370+
centerToYPositionThumb: settings?.centerToYPositionThumb,
370371
skipDetermineSizeOnInit: settings?.skipDetermineSizeOnInit,
371372
},
372373
settings?.adjustToFormContent

0 commit comments

Comments
 (0)