11import { FC } from 'react'
22
3- import type { AnyEvent , DisplayMode , Display , JsonData } from '../models'
3+ import type { AnyEvent , DisplayMode , Display , JsonData , FastProps } from '../models'
44
55import { useCustomRender } from '../hooks/config'
66import { unreachable , asTitle } from '../tools'
77
8+ import { AnyComp } from '.'
9+
810import { JsonComp } from './Json'
911import { LinkRender } from './link'
1012
@@ -26,6 +28,28 @@ export const DisplayComp: FC<Display> = (props) => {
2628 }
2729}
2830
31+ // todo: this list should probably be defined in the models file
32+ const nestableSubcomponents = [
33+ 'Text' ,
34+ 'Paragraph' ,
35+ 'Div' ,
36+ 'Heading' ,
37+ 'Markdown' ,
38+ 'Code' ,
39+ 'Json' ,
40+ 'Button' ,
41+ 'Link' ,
42+ 'LinkList' ,
43+ 'ServerLoad' ,
44+ 'Image' ,
45+ 'Iframe' ,
46+ 'Video' ,
47+ 'Spinner' ,
48+ 'Custom' ,
49+ 'Table' ,
50+ 'Details' ,
51+ ]
52+
2953const DisplayRender : FC < Display > = ( props ) => {
3054 const mode = props . mode ?? 'auto'
3155 const value = props . value ?? null
@@ -34,7 +58,11 @@ const DisplayRender: FC<Display> = (props) => {
3458 } else if ( Array . isArray ( value ) ) {
3559 return < DisplayArray mode = { mode } value = { value } />
3660 } else if ( typeof value === 'object' && value !== null ) {
37- return < DisplayObject mode = { mode } value = { value } />
61+ if ( value . type !== null && typeof value . type === 'string' && nestableSubcomponents . includes ( value . type ) ) {
62+ return < AnyComp { ...( value as unknown as FastProps ) } />
63+ } else {
64+ return < DisplayObject mode = { mode } value = { value } />
65+ }
3866 } else {
3967 return < DisplayPrimitive mode = { mode } value = { value } />
4068 }
0 commit comments