diff --git a/mcp-server/data/prompts.yml b/mcp-server/data/prompts.yml index 10a915e..4f829e6 100644 --- a/mcp-server/data/prompts.yml +++ b/mcp-server/data/prompts.yml @@ -137,7 +137,7 @@ initial_instructions: | Returns true if child is fully within parent's visual bounds * setParentXY(shape: Shape, parentX: number, parentY: number): void Sets shape position relative to its parent (since parentX/parentY are read-only) - * analyzeDescendants(root: Shape, evaluator: (descendant: Shape) => T | null | undefined, maxDepth?: number): Array<{ shape: Shape, result: T }> + * analyzeDescendants(root: Shape, evaluator: (root: Shape, descendant: Shape) => T | null | undefined, maxDepth?: number): Array<{ shape: Shape, result: T }> General-purpose utility for analyzing/validating descendants Calls evaluator on each descendant; collects non-null/undefined results Powerful pattern: evaluator can return corrector functions or diagnostic data @@ -163,7 +163,7 @@ initial_instructions: | * Find shapes in current selection/board: const shapes = penpotUtils.findShapes(predicate, penpot.selection[0] || penpot.root); * Validate/analyze descendants (returns corrector functions): - const fixes = penpotUtils.analyzeDescendants(board, (shape) => { + const fixes = penpotUtils.analyzeDescendants(board, (root, shape) => { const xMod = shape.parentX % 4; if (xMod !== 0) { return () => penpotUtils.setParentXY(shape, Math.round(shape.parentX / 4) * 4, shape.parentY); @@ -171,8 +171,8 @@ initial_instructions: | }); fixes.forEach(f => f.result()); // Apply all fixes * Find containment violations: - const violations = penpotUtils.analyzeDescendants(board, (shape) => { - return !penpotUtils.isContainedIn(shape, board) ? 'outside-bounds' : null; + const violations = penpotUtils.analyzeDescendants(board, (root, shape) => { + return !penpotUtils.isContainedIn(shape, root) ? 'outside-bounds' : null; }); # Asset Libraries diff --git a/penpot-plugin/src/PenpotUtils.ts b/penpot-plugin/src/PenpotUtils.ts index 2ae115d..83e89c6 100644 --- a/penpot-plugin/src/PenpotUtils.ts +++ b/penpot-plugin/src/PenpotUtils.ts @@ -204,19 +204,19 @@ export class PenpotUtils { * This is a general-purpose utility for validation, analysis, or collecting corrector functions. * * @param root - The root shape whose descendants to analyze - * @param evaluator - Function called for each descendant; return null/undefined to skip + * @param evaluator - Function called for each descendant with (root, descendant); return null/undefined to skip * @param maxDepth - Optional maximum depth to traverse (undefined for unlimited) * @returns Array of objects containing the shape and the evaluator's result */ public static analyzeDescendants( root: Shape, - evaluator: (descendant: Shape) => T | null | undefined, + evaluator: (root: Shape, descendant: Shape) => T | null | undefined, maxDepth: number | undefined = undefined ): Array<{ shape: Shape; result: NonNullable }> { const results: Array<{ shape: Shape; result: NonNullable }> = []; const traverse = (shape: Shape, currentDepth: number): void => { - const result = evaluator(shape); + const result = evaluator(root, shape); if (result !== null && result !== undefined) { results.push({ shape, result: result as NonNullable }); }