|
15 | 15 | */ |
16 | 16 |
|
17 | 17 | import React from 'react'; |
18 | | -import {type ComponentContext} from '@a2ui/web_core/v0_9'; |
| 18 | +import {type ComponentContext, type ComponentId} from '@a2ui/web_core/v0_9'; |
| 19 | + |
| 20 | +type ResolvedChildRef = |
| 21 | + | ComponentId |
| 22 | + | { |
| 23 | + id: ComponentId; |
| 24 | + basePath: string; |
| 25 | + }; |
| 26 | + |
| 27 | +type ResolvedChildList = ResolvedChildRef[]; |
19 | 28 |
|
20 | 29 | export const ChildList: React.FC<{ |
21 | | - childList: unknown; |
| 30 | + childList: ResolvedChildList; |
22 | 31 | context: ComponentContext; |
23 | | - buildChild: (id: string, basePath?: string) => React.ReactNode; |
| 32 | + buildChild: (id: ComponentId, basePath?: string) => React.ReactNode; |
24 | 33 | }> = ({childList, buildChild}) => { |
25 | | - if (Array.isArray(childList)) { |
26 | | - return ( |
27 | | - <> |
28 | | - {childList.map((item: unknown, i: number) => { |
29 | | - // The new binder outputs objects like { id: string, basePath: string } for arrays of structural nodes |
30 | | - if (item && typeof item === 'object' && 'id' in item) { |
31 | | - const node = item as {id: string; basePath?: string}; |
32 | | - return ( |
33 | | - <React.Fragment key={`${node.id}-${i}`}> |
34 | | - {buildChild(node.id, node.basePath)} |
35 | | - </React.Fragment> |
36 | | - ); |
37 | | - } |
38 | | - // Fallback for static string lists |
39 | | - if (typeof item === 'string') { |
40 | | - return <React.Fragment key={`${item}-${i}`}>{buildChild(item)}</React.Fragment>; |
41 | | - } |
42 | | - return null; |
43 | | - })} |
44 | | - </> |
45 | | - ); |
46 | | - } |
| 34 | + if (!Array.isArray(childList)) return null; |
| 35 | + |
| 36 | + return ( |
| 37 | + <> |
| 38 | + {childList.map((childRef, index) => { |
| 39 | + if (typeof childRef === 'string') { |
| 40 | + return ( |
| 41 | + <React.Fragment key={`${childRef}-${index}`}>{buildChild(childRef)}</React.Fragment> |
| 42 | + ); |
| 43 | + } |
47 | 44 |
|
48 | | - return null; |
| 45 | + return ( |
| 46 | + <React.Fragment key={`${childRef.id}-${childRef.basePath}`}> |
| 47 | + {buildChild(childRef.id, childRef.basePath)} |
| 48 | + </React.Fragment> |
| 49 | + ); |
| 50 | + })} |
| 51 | + </> |
| 52 | + ); |
49 | 53 | }; |
0 commit comments