Skip to content

Commit 449827e

Browse files
committed
when dragging node from taskbar to canvas.. immediately show it centered around the pointer position
1 parent f5f15d9 commit 449827e

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

libs/app-canvas/src/app/components/node-sidebar-menu.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ export class NodeSidebarMenuComponent extends Component<
298298
nodeInfo
299299
);
300300
if (node && node.nodeInfo) {
301+
// TODO : IMPROVE THIS (should be handled by the internals behind createVisualNode )
302+
(node.nodeInfo as any).taskType = nodeType;
303+
301304
const elementRect = (
302305
node.domElement as unknown as HTMLElement | SVGElement
303306
).getBoundingClientRect();
@@ -306,17 +309,23 @@ export class NodeSidebarMenuComponent extends Component<
306309
elementRect.x - rootX,
307310
elementRect.y - rootY
308311
);
309-
// TODO : IMPROVE THIS
310-
(node.nodeInfo as any).taskType = nodeType;
311-
(node.domElement as HTMLElement).setPointerCapture(event.pointerId);
312312

313+
(node.domElement as HTMLElement).setPointerCapture(event.pointerId);
313314
pointerDown(
314315
x - rect.x + (node.width ?? 0) / 2,
315316
y - rect.y + (node.height ?? 0) / 2,
316317
node,
317318
canvasApp.canvas,
318319
canvasApp.interactionStateMachine
319320
);
321+
322+
// sets the initial position of the node to the pointer position so that it centers around the pointer position
323+
node.update?.(
324+
node,
325+
node.x - (node.width ?? 0) / 2,
326+
node.y - (node.height ?? 0) / 2,
327+
node
328+
);
320329
}
321330
}
322331
};

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ export const createRectNode = <T extends BaseNodeInfo>(
340340
thumbs,
341341
componentWrapper,
342342
{
343-
classNames: ``,
343+
classNames: '',
344344
},
345345
settings?.adjustToFormContent
346346
? false
@@ -367,7 +367,7 @@ export const createRectNode = <T extends BaseNodeInfo>(
367367
thumbs,
368368
componentWrapper,
369369
{
370-
classNames: ``,
370+
classNames: '',
371371
},
372372
settings?.adjustToFormContent
373373
? false
@@ -609,7 +609,8 @@ export const visualNodeFactory = <T extends BaseNodeInfo>(
609609
childNode,
610610
isAsyncCompute,
611611
nodeInfo as unknown as T,
612-
getNodeTaskFactory
612+
getNodeTaskFactory,
613+
undefined
613614
) as CreateNodeInfo<T>;
614615
// if (!nodeInstance) {
615616
// return;

0 commit comments

Comments
 (0)