@rjsf/utils 6.0.0-beta.9 → 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/dist/{index.js → index.cjs} +563 -200
  2. package/dist/index.cjs.map +7 -0
  3. package/dist/utils.esm.js +562 -199
  4. package/dist/utils.esm.js.map +4 -4
  5. package/dist/utils.umd.js +533 -193
  6. package/lib/ErrorSchemaBuilder.d.ts +2 -2
  7. package/lib/constants.d.ts +3 -0
  8. package/lib/constants.js +3 -0
  9. package/lib/constants.js.map +1 -1
  10. package/lib/createSchemaUtils.js +25 -18
  11. package/lib/createSchemaUtils.js.map +1 -1
  12. package/lib/enums.d.ts +13 -3
  13. package/lib/enums.js +13 -3
  14. package/lib/enums.js.map +1 -1
  15. package/lib/findSchemaDefinition.d.ts +6 -0
  16. package/lib/findSchemaDefinition.js +44 -3
  17. package/lib/findSchemaDefinition.js.map +1 -1
  18. package/lib/getDateElementProps.d.ts +1 -2
  19. package/lib/getTestIds.js +2 -2
  20. package/lib/getTestIds.js.map +1 -1
  21. package/lib/getUiOptions.js +4 -0
  22. package/lib/getUiOptions.js.map +1 -1
  23. package/lib/getWidget.js +3 -3
  24. package/lib/getWidget.js.map +1 -1
  25. package/lib/guessType.d.ts +1 -1
  26. package/lib/idGenerators.d.ts +22 -15
  27. package/lib/idGenerators.js +17 -8
  28. package/lib/idGenerators.js.map +1 -1
  29. package/lib/index.d.ts +16 -6
  30. package/lib/index.js +13 -4
  31. package/lib/index.js.map +1 -1
  32. package/lib/isFormDataAvailable.d.ts +7 -0
  33. package/lib/isFormDataAvailable.js +13 -0
  34. package/lib/isFormDataAvailable.js.map +1 -0
  35. package/lib/isRootSchema.d.ts +13 -0
  36. package/lib/isRootSchema.js +25 -0
  37. package/lib/isRootSchema.js.map +1 -0
  38. package/lib/mergeDefaultsWithFormData.js +14 -2
  39. package/lib/mergeDefaultsWithFormData.js.map +1 -1
  40. package/lib/nameGenerators.d.ts +13 -0
  41. package/lib/nameGenerators.js +30 -0
  42. package/lib/nameGenerators.js.map +1 -0
  43. package/lib/schema/getDefaultFormState.d.ts +17 -3
  44. package/lib/schema/getDefaultFormState.js +66 -26
  45. package/lib/schema/getDefaultFormState.js.map +1 -1
  46. package/lib/schema/getDisplayLabel.js +2 -2
  47. package/lib/schema/getDisplayLabel.js.map +1 -1
  48. package/lib/schema/index.d.ts +1 -2
  49. package/lib/schema/index.js +1 -2
  50. package/lib/schema/index.js.map +1 -1
  51. package/lib/schema/retrieveSchema.d.ts +10 -5
  52. package/lib/schema/retrieveSchema.js +40 -17
  53. package/lib/schema/retrieveSchema.js.map +1 -1
  54. package/lib/shallowEquals.d.ts +8 -0
  55. package/lib/shallowEquals.js +36 -0
  56. package/lib/shallowEquals.js.map +1 -0
  57. package/lib/shouldRender.d.ts +8 -2
  58. package/lib/shouldRender.js +17 -2
  59. package/lib/shouldRender.js.map +1 -1
  60. package/lib/shouldRenderOptionalField.d.ts +18 -0
  61. package/lib/shouldRenderOptionalField.js +47 -0
  62. package/lib/shouldRenderOptionalField.js.map +1 -0
  63. package/lib/toFieldPathId.d.ts +14 -0
  64. package/lib/toFieldPathId.js +26 -0
  65. package/lib/toFieldPathId.js.map +1 -0
  66. package/lib/tsconfig.tsbuildinfo +1 -1
  67. package/lib/types.d.ts +196 -105
  68. package/lib/useAltDateWidgetProps.d.ts +39 -0
  69. package/lib/useAltDateWidgetProps.js +71 -0
  70. package/lib/useAltDateWidgetProps.js.map +1 -0
  71. package/lib/useDeepCompareMemo.d.ts +8 -0
  72. package/lib/useDeepCompareMemo.js +17 -0
  73. package/lib/useDeepCompareMemo.js.map +1 -0
  74. package/lib/useFileWidgetProps.d.ts +29 -0
  75. package/lib/useFileWidgetProps.js +119 -0
  76. package/lib/useFileWidgetProps.js.map +1 -0
  77. package/lib/validationDataMerge.d.ts +2 -1
  78. package/lib/validationDataMerge.js +3 -2
  79. package/lib/validationDataMerge.js.map +1 -1
  80. package/package.json +13 -14
  81. package/src/ErrorSchemaBuilder.ts +2 -2
  82. package/src/constants.ts +3 -0
  83. package/src/createSchemaUtils.ts +25 -26
  84. package/src/enums.ts +13 -3
  85. package/src/findSchemaDefinition.ts +51 -3
  86. package/src/getDateElementProps.ts +1 -1
  87. package/src/getTestIds.ts +2 -2
  88. package/src/getUiOptions.ts +4 -0
  89. package/src/getWidget.tsx +3 -3
  90. package/src/idGenerators.ts +35 -25
  91. package/src/index.ts +36 -5
  92. package/src/isFormDataAvailable.ts +13 -0
  93. package/src/isRootSchema.ts +30 -0
  94. package/src/mergeDefaultsWithFormData.ts +16 -2
  95. package/src/nameGenerators.ts +43 -0
  96. package/src/schema/getDefaultFormState.ts +87 -31
  97. package/src/schema/getDisplayLabel.ts +2 -2
  98. package/src/schema/index.ts +0 -2
  99. package/src/schema/retrieveSchema.ts +43 -7
  100. package/src/shallowEquals.ts +41 -0
  101. package/src/shouldRender.ts +27 -2
  102. package/src/shouldRenderOptionalField.ts +56 -0
  103. package/src/toFieldPathId.ts +34 -0
  104. package/src/types.ts +229 -113
  105. package/src/useAltDateWidgetProps.tsx +163 -0
  106. package/src/useDeepCompareMemo.ts +17 -0
  107. package/src/useFileWidgetProps.ts +155 -0
  108. package/src/validationDataMerge.ts +7 -1
  109. package/dist/index.js.map +0 -7
  110. package/lib/schema/toIdSchema.d.ts +0 -14
  111. package/lib/schema/toIdSchema.js +0 -62
  112. package/lib/schema/toIdSchema.js.map +0 -1
  113. package/src/schema/toIdSchema.ts +0 -131
package/src/types.ts CHANGED
@@ -2,6 +2,7 @@ import type {
2
2
  ButtonHTMLAttributes,
3
3
  ChangeEvent,
4
4
  ComponentType,
5
+ FocusEvent,
5
6
  HTMLAttributes,
6
7
  ReactElement,
7
8
  ReactNode,
@@ -35,6 +36,9 @@ export type FormContextType = GenericObjectType;
35
36
  */
36
37
  export type TestIdShape = Record<string, string>;
37
38
 
39
+ /** Function to generate HTML name attributes from path segments */
40
+ export type NameGeneratorFunction = (path: FieldPathList, idPrefix: string, isMultiValue?: boolean) => string;
41
+
38
42
  /** Experimental feature that specifies the Array `minItems` default form state behavior
39
43
  */
40
44
  export type Experimental_ArrayMinItems = {
@@ -158,20 +162,27 @@ export type InputPropsType = Omit<RangeSpecType, 'step'> & {
158
162
  accept?: HTMLInputElement['accept'];
159
163
  };
160
164
 
161
- /** Type describing an id used for a field in the `IdSchema` */
162
- export type FieldId = {
165
+ /** The list of path elements that represents where in the schema a field is located. When the item in the field list is
166
+ * a string, then it represents the name of the property within an object. When it is a number, then it represents the
167
+ * index within an array.
168
+ *
169
+ * For example:
170
+ * `[]` represents the root object of the schema
171
+ * `['foo', 'bar']` represents the `bar` element contained within the `foo` element of the schema
172
+ * `['baz', 1]` represents the second element in the list `baz` of the schema
173
+ */
174
+ export type FieldPathList = (string | number)[];
175
+
176
+ /** Type describing an id and path used for a field */
177
+ export type FieldPathId = {
163
178
  /** The id for a field */
164
179
  $id: string;
180
+ /** The path for a field */
181
+ path: FieldPathList;
182
+ /** The optional HTML name attribute for a field, generated by nameGenerator if provided */
183
+ name?: string;
165
184
  };
166
185
 
167
- /** Type describing a recursive structure of `FieldId`s for an object with a non-empty set of keys */
168
- export type IdSchema<T = any> = T extends GenericObjectType
169
- ? FieldId & {
170
- /** The set of ids for fields in the recursive object structure */
171
- [key in keyof T]?: IdSchema<T[key]>;
172
- }
173
- : FieldId;
174
-
175
186
  /** Type describing a name used for a field in the `PathSchema` */
176
187
  export type FieldPath = {
177
188
  /** The name of a field */
@@ -212,6 +223,8 @@ export type RJSFValidationError = {
212
223
  schemaPath?: string;
213
224
  /** Full error name, for example ".name is a required property" */
214
225
  stack: string;
226
+ /** The title property for the failing field*/
227
+ title?: string;
215
228
  };
216
229
 
217
230
  /** The type that describes an error in a field */
@@ -261,8 +274,6 @@ export type ErrorListProps<
261
274
  errorSchema: ErrorSchema<T>;
262
275
  /** An array of the errors */
263
276
  errors: RJSFValidationError[];
264
- /** The `formContext` object that was passed to `Form` */
265
- formContext?: F;
266
277
  };
267
278
 
268
279
  /** The properties that are passed to an `FieldErrorTemplate` implementation */
@@ -275,8 +286,8 @@ export type FieldErrorProps<
275
286
  errorSchema?: ErrorSchema<T>;
276
287
  /** An array of the errors */
277
288
  errors?: Array<string | ReactElement>;
278
- /** The tree of unique ids for every child field */
279
- idSchema: IdSchema<T>;
289
+ /** The FieldPathId of the field in the hierarchy */
290
+ fieldPathId: FieldPathId;
280
291
  };
281
292
 
282
293
  /** The properties that are passed to an `FieldHelpTemplate` implementation */
@@ -287,8 +298,8 @@ export type FieldHelpProps<
287
298
  > = RJSFBaseProps<T, S, F> & {
288
299
  /** The help information to be rendered */
289
300
  help?: string | ReactElement;
290
- /** The tree of unique ids for every child field */
291
- idSchema: IdSchema<T>;
301
+ /** The FieldPathId of the field in the hierarchy */
302
+ fieldPathId: FieldPathId;
292
303
  /** Flag indicating whether there are errors associated with this field */
293
304
  hasErrors?: boolean;
294
305
  };
@@ -322,9 +333,9 @@ export type TemplatesType<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
322
333
  /** The template to use while rendering the description for an array field */
323
334
  ArrayFieldDescriptionTemplate: ComponentType<ArrayFieldDescriptionProps<T, S, F>>;
324
335
  /** The template to use while rendering the buttons for an item in an array field */
325
- ArrayFieldItemButtonsTemplate: ComponentType<ArrayFieldItemButtonsTemplateType<T, S, F>>;
336
+ ArrayFieldItemButtonsTemplate: ComponentType<ArrayFieldItemButtonsTemplateProps<T, S, F>>;
326
337
  /** The template to use while rendering an item in an array field */
327
- ArrayFieldItemTemplate: ComponentType<ArrayFieldItemTemplateType<T, S, F>>;
338
+ ArrayFieldItemTemplate: ComponentType<ArrayFieldItemTemplateProps<T, S, F>>;
328
339
  /** The template to use while rendering the title for an array field */
329
340
  ArrayFieldTitleTemplate: ComponentType<ArrayFieldTitleProps<T, S, F>>;
330
341
  /** The template to use while rendering the standard html input */
@@ -333,6 +344,8 @@ export type TemplatesType<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
333
344
  DescriptionFieldTemplate: ComponentType<DescriptionFieldProps<T, S, F>>;
334
345
  /** The template to use while rendering the errors for the whole form */
335
346
  ErrorListTemplate: ComponentType<ErrorListProps<T, S, F>>;
347
+ /** The template to use while rendering a fallback field for schemas that have an empty or unknown 'type' */
348
+ FallbackFieldTemplate: ComponentType<FallbackFieldTemplateProps<T, S, F>>;
336
349
  /** The template to use while rendering the errors for a single field */
337
350
  FieldErrorTemplate: ComponentType<FieldErrorProps<T, S, F>>;
338
351
  /** The template to use while rendering the errors for a single field */
@@ -341,8 +354,12 @@ export type TemplatesType<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
341
354
  FieldTemplate: ComponentType<FieldTemplateProps<T, S, F>>;
342
355
  /** The template to use to render a Grid element */
343
356
  GridTemplate: ComponentType<GridTemplateProps>;
357
+ /** The template to use while rendering a multi-schema field (i.e. anyOf, oneOf) */
358
+ MultiSchemaFieldTemplate: ComponentType<MultiSchemaFieldTemplateProps<T, S, F>>;
344
359
  /** The template to use while rendering an object */
345
360
  ObjectFieldTemplate: ComponentType<ObjectFieldTemplateProps<T, S, F>>;
361
+ /** The template to use while rendering the Optional Data field controls */
362
+ OptionalDataControlsTemplate: ComponentType<OptionalDataControlsTemplateProps<T, S, F>>;
346
363
  /** The template to use for rendering the title of a field */
347
364
  TitleFieldTemplate: ComponentType<TitleFieldProps<T, S, F>>;
348
365
  /** The template to use for rendering information about an unsupported field type in the schema */
@@ -391,6 +408,36 @@ export type GlobalUISchemaOptions = GenericObjectType & {
391
408
  /** Enables the displaying of description text that contains markdown
392
409
  */
393
410
  enableMarkdownInDescription?: boolean;
411
+ /** Enables the rendering of the Optional Data Field UI for specific types of schemas, either `object`, `array` or
412
+ * both. To disable the Optional Data Field UI for a specific field, provide an empty array within the UI schema.
413
+ */
414
+ enableOptionalDataFieldForType?: ('object' | 'array')[];
415
+ };
416
+
417
+ /** The set of options from the `Form` that will be available on the `Registry` for use in everywhere the `registry` is
418
+ * available.
419
+ */
420
+ export type GlobalFormOptions = {
421
+ /** To avoid collisions with existing ids in the DOM, it is possible to change the prefix used for ids;
422
+ * Default is `root`. This prop is passed to the `toFilePathId()` function within the RJSF field implementations.
423
+ */
424
+ readonly idPrefix: string;
425
+ /** To avoid using a path separator that is present in field names, it is possible to change the separator used for
426
+ * ids; Default is `_`. This prop is passed to the `toFilePathId()` function within the RJSF field implementations.
427
+ */
428
+ readonly idSeparator: string;
429
+ /** The component update strategy used by the Form and its fields for performance optimization */
430
+ readonly experimental_componentUpdateStrategy?: 'customDeep' | 'shallow' | 'always';
431
+ /** Optional function to generate custom HTML name attributes for form elements. Receives the field path segments
432
+ * and element type (object or array), and returns a custom name string. This allows backends like PHP/Rails
433
+ * (`root[tasks][0][title]`) or Django (`root__tasks-0__title`) to receive form data in their expected format.
434
+ */
435
+ readonly nameGenerator?: NameGeneratorFunction;
436
+ /**
437
+ * Boolean flag that, when set to true, will cause the form to use a fallback UI when encountering a schema type that
438
+ * is not supported by RJSF or a custom field. When false, the UnsupportedField error component will be shown instead.
439
+ */
440
+ readonly useFallbackUiForUnsupportedType?: boolean;
394
441
  };
395
442
 
396
443
  /** The object containing the registered core, theme and custom fields and widgets as well as the root schema, form
@@ -401,7 +448,7 @@ export interface Registry<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
401
448
  * registered fields
402
449
  */
403
450
  fields: RegistryFieldsType<T, S, F>;
404
- /** The set of templates used by the `Form`. Includes templates from `core`, theme-specific fields and any custom
451
+ /** The set of templates used by the `Form`. Includes templates from `core`, theme-specific templates and any custom
405
452
  * registered templates
406
453
  */
407
454
  templates: TemplatesType<T, S, F>;
@@ -419,29 +466,31 @@ export interface Registry<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
419
466
  schemaUtils: SchemaUtilsType<T, S>;
420
467
  /** The string translation function to use when displaying any of the RJSF strings in templates, fields or widgets */
421
468
  translateString: (stringKey: TranslatableString, params?: string[]) => string;
469
+ /** The global Form Options that are available for all templates, fields and widgets to access */
470
+ readonly globalFormOptions: GlobalFormOptions;
422
471
  /** The optional global UI Options that are available for all templates, fields and widgets to access */
423
472
  globalUiOptions?: GlobalUISchemaOptions;
424
473
  }
425
474
 
426
- /** The properties that are passed to a Field implementation */
475
+ /** The properties that are passed to a `Field` implementation */
427
476
  export interface FieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>
428
477
  extends GenericObjectType,
429
478
  RJSFBaseProps<T, S, F>,
430
479
  Pick<HTMLAttributes<HTMLElement>, Exclude<keyof HTMLAttributes<HTMLElement>, 'onBlur' | 'onFocus' | 'onChange'>> {
431
- /** The tree of unique ids for every child field */
432
- idSchema: IdSchema<T>;
480
+ /** The FieldPathId of the field in the hierarchy */
481
+ fieldPathId: FieldPathId;
433
482
  /** The data for this field */
434
483
  formData?: T;
435
484
  /** The tree of errors for this field and its children */
436
485
  errorSchema?: ErrorSchema<T>;
437
- /** The field change event handler; called with the updated form data and an optional `ErrorSchema` */
438
- onChange: (newFormData: T | undefined, es?: ErrorSchema<T>, id?: string) => any;
486
+ /** The field change event handler; called with the updated field value, the change path for the value
487
+ * (defaults to an empty array), an optional ErrorSchema and the optional id of the field being changed
488
+ */
489
+ onChange: (newValue: T | undefined, path: FieldPathList, es?: ErrorSchema<T>, id?: string) => void;
439
490
  /** The input blur event handler; call it with the field id and value */
440
491
  onBlur: (id: string, value: any) => void;
441
492
  /** The input focus event handler; call it with the field id and value */
442
493
  onFocus: (id: string, value: any) => void;
443
- /** The `formContext` object that you passed to `Form` */
444
- formContext?: F;
445
494
  /** A boolean value stating if the field should autofocus */
446
495
  autofocus?: boolean;
447
496
  /** A boolean value stating if the field is disabled */
@@ -454,14 +503,6 @@ export interface FieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F
454
503
  required?: boolean;
455
504
  /** The unique name of the field, usually derived from the name of the property in the JSONSchema */
456
505
  name: string;
457
- /** To avoid collisions with existing ids in the DOM, it is possible to change the prefix used for ids;
458
- * Default is `root`
459
- */
460
- idPrefix?: string;
461
- /** To avoid using a path separator that is present in field names, it is possible to change the separator used for
462
- * ids (Default is `_`)
463
- */
464
- idSeparator?: string;
465
506
  /** An array of strings listing all generated error messages from encountered errors for this field */
466
507
  rawErrors?: string[];
467
508
  }
@@ -474,7 +515,7 @@ export type Field<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
474
515
  TEST_IDS?: TestIdShape;
475
516
  };
476
517
 
477
- /** The properties that are passed to a FieldTemplate implementation */
518
+ /** The properties that are passed to a `FieldTemplate` implementation */
478
519
  export type FieldTemplateProps<
479
520
  T = any,
480
521
  S extends StrictRJSFSchema = RJSFSchema,
@@ -520,16 +561,42 @@ export type FieldTemplateProps<
520
561
  * you don't want to clutter the UI
521
562
  */
522
563
  displayLabel?: boolean;
523
- /** The `formContext` object that was passed to `Form` */
524
- formContext?: F;
525
564
  /** The formData for this field */
526
565
  formData?: T;
527
566
  /** The value change event handler; Can be called with a new value to change the value for this field */
528
567
  onChange: FieldProps<T, S, F>['onChange'];
529
- /** The key change event handler; Called when the key associated with a field is changed for an additionalProperty */
530
- onKeyChange: (value: string) => () => void;
531
- /** The property drop/removal event handler; Called when a field is removed in an additionalProperty context */
532
- onDropPropertyClick: (value: string) => () => void;
568
+ /** Callback used to handle the changing of an additional property key's name with the new value
569
+ */
570
+ onKeyRename: (newKey: string) => void;
571
+ /** Callback used to handle the changing of an additional property key's name when the input is blurred. The event's
572
+ * target's value will be used as the new value. Its a wrapper callback around `onKeyRename`
573
+ */
574
+ onKeyRenameBlur: (event: FocusEvent<HTMLInputElement>) => void;
575
+ /** Callback used to handle the removal of the additionalProperty */
576
+ onRemoveProperty: () => void;
577
+ };
578
+
579
+ /**
580
+ * The properties that are passed to a `FallbackField` implementation
581
+ */
582
+ export type FallbackFieldProps<
583
+ T = any,
584
+ S extends StrictRJSFSchema = RJSFSchema,
585
+ F extends FormContextType = any,
586
+ > = FieldProps<T, S, F>;
587
+
588
+ /**
589
+ * The properties that are passed to a `FallbackFieldTemplate` implementation
590
+ */
591
+ export type FallbackFieldTemplateProps<
592
+ T = any,
593
+ S extends StrictRJSFSchema = RJSFSchema,
594
+ F extends FormContextType = any,
595
+ > = RJSFBaseProps<T, S, F> & {
596
+ /** A ReactNode that allows the selecting a different type for the field */
597
+ typeSelector: ReactNode;
598
+ /** A ReactNode that renders the field with the present formData and matches the selected type */
599
+ schemaField: ReactNode;
533
600
  };
534
601
 
535
602
  /** The properties that are passed to the `UnsupportedFieldTemplate` implementation */
@@ -538,8 +605,8 @@ export type UnsupportedFieldProps<
538
605
  S extends StrictRJSFSchema = RJSFSchema,
539
606
  F extends FormContextType = any,
540
607
  > = RJSFBaseProps<T, S, F> & {
541
- /** The tree of unique ids for every child field */
542
- idSchema?: IdSchema<T>;
608
+ /** The FieldPathId of the field in the hierarchy */
609
+ fieldPathId: FieldPathId;
543
610
  /** The reason why the schema field has an unsupported type */
544
611
  reason: string;
545
612
  };
@@ -556,6 +623,8 @@ export type TitleFieldProps<
556
623
  title: string;
557
624
  /** A boolean value stating if the field is required */
558
625
  required?: boolean;
626
+ /** Add optional data control */
627
+ optionalDataControl?: ReactNode;
559
628
  };
560
629
 
561
630
  /** The properties that are passed to a `DescriptionFieldTemplate` implementation */
@@ -578,8 +647,10 @@ export type ArrayFieldTitleProps<
578
647
  > = Omit<TitleFieldProps<T, S, F>, 'id' | 'title'> & {
579
648
  /** The title for the field being rendered */
580
649
  title?: string;
581
- /** The idSchema of the field in the hierarchy */
582
- idSchema: IdSchema<T>;
650
+ /** The FieldPathId of the field in the hierarchy */
651
+ fieldPathId: FieldPathId;
652
+ /** Add optional data control */
653
+ optionalDataControl?: ReactNode;
583
654
  };
584
655
 
585
656
  /** The properties that are passed to a `ArrayFieldDescriptionTemplate` implementation */
@@ -590,18 +661,18 @@ export type ArrayFieldDescriptionProps<
590
661
  > = Omit<DescriptionFieldProps<T, S, F>, 'id' | 'description'> & {
591
662
  /** The description of the field being rendered */
592
663
  description?: string | ReactElement;
593
- /** The idSchema of the field in the hierarchy */
594
- idSchema: IdSchema<T>;
664
+ /** An object containing the id and path for this field */
665
+ fieldPathId: FieldPathId;
595
666
  };
596
667
 
597
668
  /** The properties of the buttons to render for each element in the ArrayFieldTemplateProps.items array */
598
- export type ArrayFieldItemButtonsTemplateType<
669
+ export type ArrayFieldItemButtonsTemplateProps<
599
670
  T = any,
600
671
  S extends StrictRJSFSchema = RJSFSchema,
601
672
  F extends FormContextType = any,
602
673
  > = RJSFBaseProps<T, S, F> & {
603
- /** The idSchema of the item for which buttons are being rendered */
604
- idSchema: IdSchema<T>;
674
+ /** The FieldPathId of the item for which buttons are being rendered */
675
+ fieldPathId: FieldPathId;
605
676
  /** The className string */
606
677
  className?: string;
607
678
  /** Any optional style attributes */
@@ -622,20 +693,22 @@ export type ArrayFieldItemButtonsTemplateType<
622
693
  index: number;
623
694
  /** A number stating the total number `items` in the array */
624
695
  totalItems: number;
625
- /** Returns a function that adds a new item at `index` */
626
- onAddIndexClick: (index: number) => (event?: any) => void;
627
- /** Returns a function that copies the item at `index` into the position at `index + 1` */
628
- onCopyIndexClick: (index: number) => (event?: any) => void;
629
- /** Returns a function that removes the item at `index` */
630
- onDropIndexClick: (index: number) => (event?: any) => void;
631
- /** Returns a function that swaps the items at `index` with `newIndex` */
632
- onReorderClick: (index: number, newIndex: number) => (event?: any) => void;
696
+ /** Callback function that adds a new item below this item */
697
+ onAddItem: (event?: any) => void;
698
+ /** Callback function that copies this item below itself */
699
+ onCopyItem: (event?: any) => void;
700
+ /** Callback function that moves the item up one spot in the list */
701
+ onMoveUpItem: (event?: any) => void;
702
+ /** Callback function that moves the item down one spot in the list */
703
+ onMoveDownItem: (event?: any) => void;
704
+ /** Callback function that removes the item from the list */
705
+ onRemoveItem: (event?: any) => void;
633
706
  /** A boolean value stating if the array item is read-only */
634
707
  readonly?: boolean;
635
708
  };
636
709
 
637
- /** The properties of each element in the ArrayFieldTemplateProps.items array */
638
- export type ArrayFieldItemTemplateType<
710
+ /** The properties used to render the ArrayFieldItemTemplate */
711
+ export type ArrayFieldItemTemplateProps<
639
712
  T = any,
640
713
  S extends StrictRJSFSchema = RJSFSchema,
641
714
  F extends FormContextType = any,
@@ -643,7 +716,7 @@ export type ArrayFieldItemTemplateType<
643
716
  /** The html for the item's content */
644
717
  children: ReactNode;
645
718
  /** The props to pass to the `ArrayFieldItemButtonTemplate` */
646
- buttonsProps: ArrayFieldItemButtonsTemplateType<T, S, F>;
719
+ buttonsProps: ArrayFieldItemButtonsTemplateProps<T, S, F>;
647
720
  /** The className string */
648
721
  className: string;
649
722
  /** A boolean value stating if the array item is disabled */
@@ -657,36 +730,25 @@ export type ArrayFieldItemTemplateType<
657
730
  /** A boolean value stating if the array item is read-only */
658
731
  readonly?: boolean;
659
732
  /** A stable, unique key for the array item */
660
- key: string;
733
+ itemKey: string;
734
+ /** The UI schema of the array item's parent array field used for
735
+ * customization in some themes
736
+ */
737
+ parentUiSchema?: UiSchema<T, S, F>;
661
738
  };
662
739
 
663
- /**
664
- * @deprecated - Use `ArrayFieldItemTemplateType` instead
665
- */
666
- export type ArrayFieldTemplateItemType<
667
- T = any,
668
- S extends StrictRJSFSchema = RJSFSchema,
669
- F extends FormContextType = any,
670
- > = ArrayFieldItemTemplateType<T, S, F>;
671
-
672
- /** The properties that are passed to an ArrayFieldTemplate implementation */
673
- export type ArrayFieldTemplateProps<
740
+ /** The common properties of the two container templates: `ArrayFieldTemplateProps` and `ObjectFieldTemplateProps` */
741
+ export type ContainerFieldTemplateProps<
674
742
  T = any,
675
743
  S extends StrictRJSFSchema = RJSFSchema,
676
744
  F extends FormContextType = any,
677
745
  > = RJSFBaseProps<T, S, F> & {
678
- /** A boolean value stating whether new elements can be added to the array */
679
- canAdd?: boolean;
680
746
  /** The className string */
681
747
  className?: string;
682
748
  /** A boolean value stating if the array is disabled */
683
749
  disabled?: boolean;
684
- /** An object containing the id for this object & ids for its properties */
685
- idSchema: IdSchema<T>;
686
- /** An array of objects representing the items in the array */
687
- items: ArrayFieldItemTemplateType<T, S, F>[];
688
- /** A function that adds a new item to the array */
689
- onAddClick: (event?: any) => void;
750
+ /** The FieldPathId of the field in the hierarchy */
751
+ fieldPathId: FieldPathId;
690
752
  /** A boolean value stating if the array is read-only */
691
753
  readonly?: boolean;
692
754
  /** A boolean value stating if the array is required */
@@ -695,12 +757,26 @@ export type ArrayFieldTemplateProps<
695
757
  hideError?: boolean;
696
758
  /** A string value containing the title for the array */
697
759
  title: string;
698
- /** The `formContext` object that was passed to Form */
699
- formContext?: F;
700
760
  /** The formData for this array */
701
761
  formData?: T;
702
- /** The tree of errors for this field and its children */
762
+ /** The optional validation errors in the form of an `ErrorSchema` */
703
763
  errorSchema?: ErrorSchema<T>;
764
+ /** The optional data control node to render within the ObjectFieldTemplate that controls */
765
+ optionalDataControl?: ReactNode;
766
+ };
767
+
768
+ /** The properties that are passed to an `ArrayFieldTemplate` implementation */
769
+ export type ArrayFieldTemplateProps<
770
+ T = any,
771
+ S extends StrictRJSFSchema = RJSFSchema,
772
+ F extends FormContextType = any,
773
+ > = ContainerFieldTemplateProps<T, S, F> & {
774
+ /** A boolean value stating whether new elements can be added to the array */
775
+ canAdd?: boolean;
776
+ /** An array of React elements representing the items in the array */
777
+ items: ReactElement[];
778
+ /** A function that adds a new item to the end of the array */
779
+ onAddClick: (event?: any) => void;
704
780
  /** An array of strings listing all generated error messages from encountered errors for this widget */
705
781
  rawErrors?: string[];
706
782
  };
@@ -724,31 +800,43 @@ export type ObjectFieldTemplateProps<
724
800
  T = any,
725
801
  S extends StrictRJSFSchema = RJSFSchema,
726
802
  F extends FormContextType = any,
727
- > = RJSFBaseProps<T, S, F> & {
728
- /** A string value containing the title for the object */
729
- title: string;
803
+ > = ContainerFieldTemplateProps<T, S, F> & {
730
804
  /** A string value containing the description for the object */
731
805
  description?: string | ReactElement;
732
- /** A boolean value stating if the object is disabled */
733
- disabled?: boolean;
734
806
  /** An array of objects representing the properties in the object */
735
807
  properties: ObjectFieldTemplatePropertyType[];
736
- /** Returns a function that adds a new property to the object (to be used with additionalProperties) */
737
- onAddClick: (schema: S) => () => void;
808
+ /** Callback to use in order to add an new additionalProperty to the object field (to be used with
809
+ * additionalProperties and patternProperties)
810
+ */
811
+ onAddProperty: () => void;
738
812
  /** A boolean value stating if the object is read-only */
739
813
  readonly?: boolean;
740
814
  /** A boolean value stating if the object is required */
741
815
  required?: boolean;
742
816
  /** A boolean value stating if the field is hiding its errors */
743
817
  hideError?: boolean;
744
- /** An object containing the id for this object & ids for its properties */
745
- idSchema: IdSchema<T>;
818
+ /** The FieldPathId of the field in the hierarchy */
819
+ fieldPathId: FieldPathId;
746
820
  /** The optional validation errors in the form of an `ErrorSchema` */
747
821
  errorSchema?: ErrorSchema<T>;
748
822
  /** The form data for the object */
749
823
  formData?: T;
750
- /** The `formContext` object that was passed to Form */
751
- formContext?: F;
824
+ };
825
+
826
+ /** The properties that are passed to a OptionalDataControlsTemplate implementation */
827
+ export type OptionalDataControlsTemplateProps<
828
+ T = any,
829
+ S extends StrictRJSFSchema = RJSFSchema,
830
+ F extends FormContextType = any,
831
+ > = RJSFBaseProps<T, S, F> & {
832
+ /** The generated id for this Optional Data Control instance */
833
+ id: string;
834
+ /** The label to use for the Optional Data Control */
835
+ label: string;
836
+ /** Optional callback to call when clicking on the Optional Data Control to add data */
837
+ onRemoveClick?: () => void;
838
+ /** Optional callback to call when clicking on the Optional Data Control to remove data */
839
+ onAddClick?: () => void;
752
840
  };
753
841
 
754
842
  /** The properties that are passed to a WrapIfAdditionalTemplate implementation */
@@ -772,16 +860,29 @@ export type WrapIfAdditionalTemplateProps<
772
860
  | 'disabled'
773
861
  | 'schema'
774
862
  | 'uiSchema'
775
- | 'onKeyChange'
776
- | 'onDropPropertyClick'
863
+ | 'onKeyRename'
864
+ | 'onKeyRenameBlur'
865
+ | 'onRemoveProperty'
777
866
  | 'registry'
778
867
  >;
779
868
 
780
- /** The properties that are passed to a Widget implementation */
869
+ /** The properties that are passed to a MultiSchemaFieldTemplate implementation */
870
+ export interface MultiSchemaFieldTemplateProps<
871
+ T = any,
872
+ S extends StrictRJSFSchema = RJSFSchema,
873
+ F extends FormContextType = any,
874
+ > extends RJSFBaseProps<T, S, F> {
875
+ /** The rendered widget used to select a schema option */
876
+ selector: ReactNode;
877
+ /** The rendered SchemaField for the selected schema option */
878
+ optionSchemaField: ReactNode;
879
+ }
880
+
881
+ /** The properties that are passed to a `Widget` implementation */
781
882
  export interface WidgetProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>
782
883
  extends GenericObjectType,
783
884
  RJSFBaseProps<T, S, F>,
784
- Pick<HTMLAttributes<HTMLElement>, Exclude<keyof HTMLAttributes<HTMLElement>, 'onBlur' | 'onFocus'>> {
885
+ Pick<HTMLAttributes<HTMLElement>, Exclude<keyof HTMLAttributes<HTMLElement>, 'onBlur' | 'onFocus' | 'onChange'>> {
785
886
  /** The generated id for this widget, used to provide unique `name`s and `id`s for the HTML field elements rendered by
786
887
  * widgets
787
888
  */
@@ -811,8 +912,6 @@ export interface WidgetProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F
811
912
  /** The enum options list for a type that supports them */
812
913
  enumOptions?: EnumOptionsType<S>[];
813
914
  };
814
- /** The `formContext` object that you passed to `Form` */
815
- formContext?: F;
816
915
  /** The input blur event handler; call it with the widget id and value */
817
916
  onBlur: (id: string, value: any) => void;
818
917
  /** The value change event handler; call it with the new value every time it changes */
@@ -829,6 +928,8 @@ export interface WidgetProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F
829
928
  multiple?: boolean;
830
929
  /** An array of strings listing all generated error messages from encountered errors for this widget */
831
930
  rawErrors?: string[];
931
+ /** The optional custom HTML name attribute generated by the nameGenerator function, if provided */
932
+ htmlName?: string;
832
933
  }
833
934
 
834
935
  /** The definition of a React-based Widget component */
@@ -989,6 +1090,13 @@ export type UIOptionsType<
989
1090
  [key: string]: boolean | number | string | object | any[] | null | undefined;
990
1091
  };
991
1092
 
1093
+ /**
1094
+ * A utility type that extracts the element type from an array type.
1095
+ * If the type is not an array, it returns the type itself as a safe fallback.
1096
+ * Handles both standard arrays and readonly arrays.
1097
+ */
1098
+ export type ArrayElement<A> = A extends readonly (infer E)[] ? E : A;
1099
+
992
1100
  /** Type describing the well-known properties of the `UiSchema` while also supporting all user defined properties,
993
1101
  * starting with `ui:`.
994
1102
  */
@@ -1002,7 +1110,10 @@ export type UiSchema<
1002
1110
  * Registry for use everywhere.
1003
1111
  */
1004
1112
  'ui:globalOptions'?: GlobalUISchemaOptions;
1005
- /** Allows the form to generate a unique prefix for the `Form`'s root prefix */
1113
+ /** Allows the form to generate a unique prefix for the `Form`'s root prefix
1114
+ *
1115
+ * @deprecated - use `Form.idPrefix` instead, will be removed in a future major version
1116
+ */
1006
1117
  'ui:rootFieldId'?: string;
1007
1118
  /** By default, any field that is rendered for an `anyOf`/`oneOf` schema will be wrapped inside the `AnyOfField` or
1008
1119
  * `OneOfField` component. This default behavior may be undesirable if your custom field already handles behavior
@@ -1014,6 +1125,13 @@ export type UiSchema<
1014
1125
  'ui:fieldReplacesAnyOrOneOf'?: boolean;
1015
1126
  /** An object that contains all the potential UI options in a single object */
1016
1127
  'ui:options'?: UIOptionsType<T, S, F>;
1128
+ /** The uiSchema for items in an array. Can be an object for a uniform uiSchema across all items (current behavior),
1129
+ * or a function that returns a dynamic uiSchema based on the item's data and index.
1130
+ * When using a function, it receives the item data, index, and optionally the form context as parameters.
1131
+ */
1132
+ items?:
1133
+ | UiSchema<ArrayElement<T>, S, F>
1134
+ | ((itemData: ArrayElement<T>, index: number, formContext?: F) => UiSchema<ArrayElement<T>, S, F>);
1017
1135
  };
1018
1136
 
1019
1137
  /** A `CustomValidator` function takes in a `formData`, `errors` and `uiSchema` objects and returns the given `errors`
@@ -1100,6 +1218,11 @@ export interface FoundFieldType<S extends StrictRJSFSchema = RJSFSchema> {
1100
1218
  * set of APIs to the `@rjsf/core` components and the various themes as well.
1101
1219
  */
1102
1220
  export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> {
1221
+ /** Returns the `rootSchema` in the `SchemaUtilsType`
1222
+ *
1223
+ * @returns - The rootSchema
1224
+ */
1225
+ getRootSchema(): S;
1103
1226
  /** Returns the `ValidatorType` in the `SchemaUtilsType`
1104
1227
  *
1105
1228
  * @returns - The `ValidatorType`
@@ -1151,12 +1274,14 @@ export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchem
1151
1274
  * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
1152
1275
  * If "excludeObjectChildren", cause undefined values for this object and pass `includeUndefinedValues` as
1153
1276
  * false when computing defaults for any nested object properties.
1277
+ * @param initialDefaultsGenerated - Indicates whether or not initial defaults have been generated
1154
1278
  * @returns - The resulting `formData` with all the defaults provided
1155
1279
  */
1156
1280
  getDefaultFormState(
1157
1281
  schema: S,
1158
1282
  formData?: T,
1159
1283
  includeUndefinedValues?: boolean | 'excludeObjectChildren',
1284
+ initialDefaultsGenerated?: boolean,
1160
1285
  ): T | T[] | undefined;
1161
1286
  /** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
1162
1287
  * should be displayed in a UI.
@@ -1232,9 +1357,10 @@ export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchem
1232
1357
  *
1233
1358
  * @param schema - The schema for which retrieving a schema is desired
1234
1359
  * @param [formData] - The current formData, if any, to assist retrieving a schema
1360
+ * @param [resolveAnyOfOrOneOfRefs] - Optional flag indicating whether to resolved refs in anyOf/oneOf lists
1235
1361
  * @returns - The schema having its conditions, additional properties, references and dependencies resolved
1236
1362
  */
1237
- retrieveSchema(schema: S, formData?: T): S;
1363
+ retrieveSchema(schema: S, formData?: T, resolveAnyOfOrOneOfRefs?: boolean): S;
1238
1364
  /** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the
1239
1365
  * new schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the
1240
1366
  * nature of schemas, this sanitization happens recursively for nested objects of data. Also, any properties in the
@@ -1247,16 +1373,6 @@ export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchem
1247
1373
  * to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
1248
1374
  */
1249
1375
  sanitizeDataForNewSchema(newSchema?: S, oldSchema?: S, data?: any): T;
1250
- /** Generates an `IdSchema` object for the `schema`, recursively
1251
- *
1252
- * @param schema - The schema for which the display label flag is desired
1253
- * @param [id] - The base id for the schema
1254
- * @param [formData] - The current formData, if any, onto which to provide any missing defaults
1255
- * @param [idPrefix='root'] - The prefix to use for the id
1256
- * @param [idSeparator='_'] - The separator to use for the path segments in the id
1257
- * @returns - The `IdSchema` object for the `schema`
1258
- */
1259
- toIdSchema(schema: S, id?: string, formData?: T, idPrefix?: string, idSeparator?: string): IdSchema<T>;
1260
1376
  /** Generates an `PathSchema` object for the `schema`, recursively
1261
1377
  *
1262
1378
  * @param schema - The schema for which the display label flag is desired