@@ -215,7 +215,11 @@ const DynamicJsonForm = ({
215
215
return ;
216
216
}
217
217
218
- const updateArray = ( array : JsonValue [ ] , path : string [ ] , value : JsonValue ) : JsonValue [ ] => {
218
+ const updateArray = (
219
+ array : JsonValue [ ] ,
220
+ path : string [ ] ,
221
+ value : JsonValue ,
222
+ ) : JsonValue [ ] => {
219
223
const [ index , ...restPath ] = path ;
220
224
const arrayIndex = Number ( index ) ;
221
225
@@ -232,7 +236,7 @@ const DynamicJsonForm = ({
232
236
}
233
237
234
238
const newArray = [ ...array ] ;
235
-
239
+
236
240
if ( restPath . length === 0 ) {
237
241
newArray [ arrayIndex ] = value ;
238
242
} else {
@@ -242,22 +246,30 @@ const DynamicJsonForm = ({
242
246
newArray . length = arrayIndex + 1 ;
243
247
newArray . fill ( null , array . length , arrayIndex ) ;
244
248
}
245
- newArray [ arrayIndex ] = updateValue ( newArray [ arrayIndex ] , restPath , value ) ;
249
+ newArray [ arrayIndex ] = updateValue (
250
+ newArray [ arrayIndex ] ,
251
+ restPath ,
252
+ value ,
253
+ ) ;
246
254
}
247
255
return newArray ;
248
256
} ;
249
257
250
- const updateObject = ( obj : JsonObject , path : string [ ] , value : JsonValue ) : JsonObject => {
258
+ const updateObject = (
259
+ obj : JsonObject ,
260
+ path : string [ ] ,
261
+ value : JsonValue ,
262
+ ) : JsonObject => {
251
263
const [ key , ...restPath ] = path ;
252
-
264
+
253
265
// Validate object key
254
- if ( typeof key !== ' string' ) {
266
+ if ( typeof key !== " string" ) {
255
267
console . error ( `Invalid object key: ${ key } ` ) ;
256
268
return obj ;
257
269
}
258
270
259
271
const newObj = { ...obj } ;
260
-
272
+
261
273
if ( restPath . length === 0 ) {
262
274
newObj [ key ] = value ;
263
275
} else {
@@ -271,7 +283,11 @@ const DynamicJsonForm = ({
271
283
return newObj ;
272
284
} ;
273
285
274
- const updateValue = ( current : JsonValue , path : string [ ] , value : JsonValue ) : JsonValue => {
286
+ const updateValue = (
287
+ current : JsonValue ,
288
+ path : string [ ] ,
289
+ value : JsonValue ,
290
+ ) : JsonValue => {
275
291
if ( path . length === 0 ) return value ;
276
292
277
293
try {
@@ -282,14 +298,17 @@ const DynamicJsonForm = ({
282
298
// Type checking
283
299
if ( Array . isArray ( current ) ) {
284
300
return updateArray ( current , path , value ) ;
285
- } else if ( typeof current === ' object' && current !== null ) {
301
+ } else if ( typeof current === " object" && current !== null ) {
286
302
return updateObject ( current , path , value ) ;
287
303
} else {
288
- console . error ( `Cannot update path ${ path . join ( '.' ) } in non-object/array value:` , current ) ;
304
+ console . error (
305
+ `Cannot update path ${ path . join ( "." ) } in non-object/array value:` ,
306
+ current ,
307
+ ) ;
289
308
return current ;
290
309
}
291
310
} catch ( error ) {
292
- console . error ( `Error updating value at path ${ path . join ( '.' ) } :` , error ) ;
311
+ console . error ( `Error updating value at path ${ path . join ( "." ) } :` , error ) ;
293
312
return current ;
294
313
}
295
314
} ;
@@ -298,7 +317,7 @@ const DynamicJsonForm = ({
298
317
const newValue = updateValue ( value , path , fieldValue ) ;
299
318
onChange ( newValue ) ;
300
319
} catch ( error ) {
301
- console . error ( ' Failed to update form value:' , error ) ;
320
+ console . error ( " Failed to update form value:" , error ) ;
302
321
// Keep the original value unchanged
303
322
onChange ( value ) ;
304
323
}
0 commit comments