(node: Protocol, frames: FigmaFrameInfo[], thumbnailUrl?: string)
| 416 | * @param thumbnailUrl - Design thumbnail URL for AI visual context |
| 417 | */ |
| 418 | export async function populateComponentProps(node: Protocol, frames: FigmaFrameInfo[], thumbnailUrl?: string): Promise<void> { |
| 419 | if (!node || !node.children || node.children.length === 0) return; |
| 420 | |
| 421 | const componentGroups = extractComponentGroups(node); |
| 422 | |
| 423 | // Process each component group to extract props and data |
| 424 | for (const [compName, group] of componentGroups) { |
| 425 | if (group.length === 0) continue; |
| 426 | |
| 427 | const isList = group.length > 1; |
| 428 | const allElements = group.flatMap(g => g.data.elements || []); |
| 429 | const simplifiedNodes = allElements |
| 430 | .filter((n): n is FigmaFrameInfo => typeof n === 'object' && n !== null) |
| 431 | .map(n => simplifyFigmaNodeForContent(n)); |
| 432 | const figmaDataJson = JSON.stringify(simplifiedNodes); |
| 433 | const containerName = node.data.name || 'Container'; |
| 434 | |
| 435 | try { |
| 436 | const { extractDataListPrompt } = await import('./prompt'); |
| 437 | const prompt = extractDataListPrompt({ |
| 438 | containerName, |
| 439 | childComponentName: compName, |
| 440 | figmaData: figmaDataJson, |
| 441 | }); |
| 442 | |
| 443 | const result = await callModel({ |
| 444 | question: prompt, |
| 445 | imageUrls: thumbnailUrl, |
| 446 | responseFormat: { type: 'json_object' }, |
| 447 | }); |
| 448 | |
| 449 | const json = extractJSON(result); |
| 450 | const parsed = JSON.parse(json) as ParsedDataListResponse; |
| 451 | applyPropsAndStateToProtocol(parsed, node, compName, group, isList); |
| 452 | } catch (e) { |
| 453 | logger.printErrorLog( |
| 454 | `Failed to extract data list for ${compName} in ${containerName}: ${e instanceof Error ? e.message : String(e)}` |
| 455 | ); |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | // Recursively process children |
| 460 | for (const child of node.children) { |
| 461 | await populateComponentProps(child, frames, thumbnailUrl); |
| 462 | } |
| 463 | } |
no test coverage detected