|
30 | 30 | import { nodeRegistry } from '$lib/nodes'; |
31 | 31 | import { NODE_TYPES } from '$lib/constants/nodeTypes'; |
32 | 32 | import { SNAP_GRID, BACKGROUND_GAP } from '$lib/constants/grid'; |
| 33 | + import { calculateNodeDimensions } from '$lib/constants/dimensions'; |
33 | 34 | import type { NodeInstance, Connection, Annotation } from '$lib/nodes/types'; |
34 | 35 | import type { EventInstance } from '$lib/events/types'; |
35 | 36 |
|
|
381 | 382 | // Interface blocks are not deletable |
382 | 383 | const isInterface = graphNode.type === NODE_TYPES.INTERFACE; |
383 | 384 |
|
| 385 | + // Calculate node dimensions for SvelteFlow bounds |
| 386 | + const typeDef = nodeRegistry.get(graphNode.type); |
| 387 | + const pinnedParamCount = typeDef && graphNode.pinnedParams |
| 388 | + ? graphNode.pinnedParams.filter(name => typeDef.params.some(p => p.name === name)).length |
| 389 | + : 0; |
| 390 | + const rotation = (graphNode.params?.['_rotation'] as number) || 0; |
| 391 | + const { width, height } = calculateNodeDimensions( |
| 392 | + graphNode.name, |
| 393 | + graphNode.inputs.length, |
| 394 | + graphNode.outputs.length, |
| 395 | + pinnedParamCount, |
| 396 | + rotation |
| 397 | + ); |
| 398 | +
|
384 | 399 | // If node exists, update data but don't preserve selection here |
385 | 400 | // Selection is managed by SvelteFlow, trigger subscriptions, and merge effect |
386 | 401 | if (existingNode) { |
|
389 | 404 | type: existingNode.type, |
390 | 405 | position, |
391 | 406 | data: graphNode, |
| 407 | + width, |
| 408 | + height, |
| 409 | + // Explicit center origin for correct bounds calculation |
| 410 | + origin: [0.5, 0.5] as [number, number], |
392 | 411 | selectable: existingNode.selectable, |
393 | 412 | draggable: existingNode.draggable, |
394 | 413 | deletable: !isInterface |
|
402 | 421 | type: 'pathview', |
403 | 422 | position, |
404 | 423 | data: graphNode, |
| 424 | + width, |
| 425 | + height, |
| 426 | + // Explicit center origin for correct bounds calculation |
| 427 | + origin: [0.5, 0.5] as [number, number], |
405 | 428 | selectable: true, |
406 | 429 | draggable: true, |
407 | 430 | deletable: !isInterface |
|
0 commit comments