MCPcopy
hub / github.com/react-grid-layout/react-grid-layout / applyPositionConstraints

Function applyPositionConstraints

src/core/constraints.ts:371–402  ·  view source on GitHub ↗
(
  constraints: LayoutConstraint[],
  item: LayoutItem,
  x: number,
  y: number,
  context: ConstraintContext
)

Source from the content-addressed store, hash-verified

369 * @returns Constrained position
370 */
371export function applyPositionConstraints(
372 constraints: LayoutConstraint[],
373 item: LayoutItem,
374 x: number,
375 y: number,
376 context: ConstraintContext
377): { x: number; y: number } {
378 let result = { x, y };
379
380 // Apply grid-level constraints
381 for (const constraint of constraints) {
382 if (constraint.constrainPosition) {
383 result = constraint.constrainPosition(item, result.x, result.y, context);
384 }
385 }
386
387 // Apply per-item constraints
388 if (item.constraints) {
389 for (const constraint of item.constraints) {
390 if (constraint.constrainPosition) {
391 result = constraint.constrainPosition(
392 item,
393 result.x,
394 result.y,
395 context
396 );
397 }
398 }
399 }
400
401 return result;
402}
403
404/**
405 * Apply size constraints to a proposed size.

Callers 2

GridItemFunction · 0.85

Calls 1

constrainPositionMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…