MCPcopy Index your code
hub / github.com/simstudioai/sim / updateContainerDimensions

Function updateContainerDimensions

apps/sim/lib/workflows/autolayout/targeted.ts:488–544  ·  view source on GitHub ↗

* Updates container dimensions based on children

(
  parentBlock: BlockState,
  childIds: string[],
  blocks: Record<string, BlockState>
)

Source from the content-addressed store, hash-verified

486 * Updates container dimensions based on children
487 */
488function updateContainerDimensions(
489 parentBlock: BlockState,
490 childIds: string[],
491 blocks: Record<string, BlockState>
492): void {
493 if (childIds.length === 0) {
494 parentBlock.data = {
495 ...parentBlock.data,
496 width: CONTAINER_DIMENSIONS.DEFAULT_WIDTH,
497 height: CONTAINER_DIMENSIONS.DEFAULT_HEIGHT,
498 }
499 parentBlock.layout = {
500 ...parentBlock.layout,
501 measuredWidth: CONTAINER_DIMENSIONS.DEFAULT_WIDTH,
502 measuredHeight: CONTAINER_DIMENSIONS.DEFAULT_HEIGHT,
503 }
504 return
505 }
506
507 let minX = Number.POSITIVE_INFINITY
508 let minY = Number.POSITIVE_INFINITY
509 let maxX = Number.NEGATIVE_INFINITY
510 let maxY = Number.NEGATIVE_INFINITY
511
512 for (const id of childIds) {
513 const child = blocks[id]
514 if (!child) continue
515 if (shouldSkipAutoLayout(child)) {
516 continue
517 }
518 const metrics = getBlockMetrics(child)
519
520 minX = Math.min(minX, child.position.x)
521 minY = Math.min(minY, child.position.y)
522 maxX = Math.max(maxX, child.position.x + metrics.width)
523 maxY = Math.max(maxY, child.position.y + metrics.height)
524 }
525
526 if (!Number.isFinite(minX) || !Number.isFinite(minY)) {
527 return
528 }
529
530 const calculatedWidth = maxX - minX + CONTAINER_PADDING * 2
531 const calculatedHeight = maxY - minY + CONTAINER_PADDING * 2
532
533 parentBlock.data = {
534 ...parentBlock.data,
535 width: Math.max(calculatedWidth, CONTAINER_DIMENSIONS.DEFAULT_WIDTH),
536 height: Math.max(calculatedHeight, CONTAINER_DIMENSIONS.DEFAULT_HEIGHT),
537 }
538
539 parentBlock.layout = {
540 ...parentBlock.layout,
541 measuredWidth: parentBlock.data.width,
542 measuredHeight: parentBlock.data.height,
543 }
544}

Callers 1

layoutGroupFunction · 0.85

Calls 2

shouldSkipAutoLayoutFunction · 0.90
getBlockMetricsFunction · 0.90

Tested by

no test coverage detected