@@ -6,16 +6,14 @@ import {Controller, FieldValue, ObjectIndependentInput, ValidateError} from '../
66
77const OBJECT_VALUE_PROPERTY_NAME = 'value' ;
88
9- export const ObjectValueInput : ObjectIndependentInput = ( { spec, input, name} ) => {
9+ export const ObjectValueInput : ObjectIndependentInput = ( props ) => {
10+ const { spec, input, name, Layout} = props ;
11+
1012 const parentOnChange = React . useCallback (
1113 ( childName : string , childValue : FieldValue , childErrors ?: Record < string , ValidateError > ) =>
1214 input . onChange (
1315 ( currentValue ) =>
14- _ . set (
15- { ...( currentValue || { } ) } ,
16- childName . split ( `${ name } .` ) . join ( '' ) ,
17- childValue ,
18- ) ,
16+ _ . set ( { ...currentValue } , childName . split ( `${ name } .` ) . join ( '' ) , childValue ) ,
1917 childErrors ,
2018 ) ,
2119 [ input . onChange , input . name ] ,
@@ -26,20 +24,36 @@ export const ObjectValueInput: ObjectIndependentInput = ({spec, input, name}) =>
2624 [ input . onChange ] ,
2725 ) ;
2826
29- const specProperties = { ...spec . properties } ;
27+ const childSpec = React . useMemo ( ( ) => {
28+ if ( spec . properties ?. [ OBJECT_VALUE_PROPERTY_NAME ] ) {
29+ const childSpec = _ . cloneDeep ( spec . properties [ OBJECT_VALUE_PROPERTY_NAME ] ) ;
30+
31+ childSpec . viewSpec . layout = '' ;
32+
33+ return childSpec ;
34+ }
35+
36+ return undefined ;
37+ } , [ spec . properties ] ) ;
3038
31- if ( ! specProperties [ OBJECT_VALUE_PROPERTY_NAME ] ) {
39+ if ( ! childSpec ) {
3240 return null ;
3341 }
3442
35- return (
43+ const content = (
3644 < Controller
3745 initialValue = { input . value ?. [ OBJECT_VALUE_PROPERTY_NAME ] }
38- spec = { specProperties [ OBJECT_VALUE_PROPERTY_NAME ] }
46+ spec = { childSpec }
3947 name = { `${ name } .${ OBJECT_VALUE_PROPERTY_NAME } ` }
4048 key = { `${ name } .${ OBJECT_VALUE_PROPERTY_NAME } ` }
4149 parentOnChange = { parentOnChange }
4250 parentOnUnmount = { parentOnUnmount }
4351 />
4452 ) ;
53+
54+ if ( Layout ) {
55+ return < Layout { ...props } > { content } </ Layout > ;
56+ }
57+
58+ return < React . Fragment > { content } </ React . Fragment > ;
4559} ;
0 commit comments