@rjsf/utils 6.0.0-beta.8 → 6.0.0

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/lib/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ButtonHTMLAttributes, ChangeEvent, ComponentType, HTMLAttributes, ReactElement, ReactNode, StyleHTMLAttributes } from 'react';
1
+ import type { ButtonHTMLAttributes, ChangeEvent, ComponentType, FocusEvent, HTMLAttributes, ReactElement, ReactNode, StyleHTMLAttributes } from 'react';
2
2
  import { JSONSchema7 } from 'json-schema';
3
3
  import { TranslatableString } from './enums.js';
4
4
  /** The representation of any generic object type, usually used as an intersection on other types to make them more
@@ -20,6 +20,8 @@ export type FormContextType = GenericObjectType;
20
20
  /** The interface for the test ID proxy objects that are returned by the `getTestId` utility function.
21
21
  */
22
22
  export type TestIdShape = Record<string, string>;
23
+ /** Function to generate HTML name attributes from path segments */
24
+ export type NameGeneratorFunction = (path: FieldPathList, idPrefix: string, isMultiValue?: boolean) => string;
23
25
  /** Experimental feature that specifies the Array `minItems` default form state behavior
24
26
  */
25
27
  export type Experimental_ArrayMinItems = {
@@ -133,15 +135,25 @@ export type InputPropsType = Omit<RangeSpecType, 'step'> & {
133
135
  /** Specifies a filter for what file types the user can upload. */
134
136
  accept?: HTMLInputElement['accept'];
135
137
  };
136
- /** Type describing an id used for a field in the `IdSchema` */
137
- export type FieldId = {
138
+ /** The list of path elements that represents where in the schema a field is located. When the item in the field list is
139
+ * a string, then it represents the name of the property within an object. When it is a number, then it represents the
140
+ * index within an array.
141
+ *
142
+ * For example:
143
+ * `[]` represents the root object of the schema
144
+ * `['foo', 'bar']` represents the `bar` element contained within the `foo` element of the schema
145
+ * `['baz', 1]` represents the second element in the list `baz` of the schema
146
+ */
147
+ export type FieldPathList = (string | number)[];
148
+ /** Type describing an id and path used for a field */
149
+ export type FieldPathId = {
138
150
  /** The id for a field */
139
151
  $id: string;
152
+ /** The path for a field */
153
+ path: FieldPathList;
154
+ /** The optional HTML name attribute for a field, generated by nameGenerator if provided */
155
+ name?: string;
140
156
  };
141
- /** Type describing a recursive structure of `FieldId`s for an object with a non-empty set of keys */
142
- export type IdSchema<T = any> = T extends GenericObjectType ? FieldId & {
143
- [key in keyof T]?: IdSchema<T[key]>;
144
- } : FieldId;
145
157
  /** Type describing a name used for a field in the `PathSchema` */
146
158
  export type FieldPath = {
147
159
  /** The name of a field */
@@ -174,6 +186,8 @@ export type RJSFValidationError = {
174
186
  schemaPath?: string;
175
187
  /** Full error name, for example ".name is a required property" */
176
188
  stack: string;
189
+ /** The title property for the failing field*/
190
+ title?: string;
177
191
  };
178
192
  /** The type that describes an error in a field */
179
193
  export type FieldError = string;
@@ -210,8 +224,6 @@ export type ErrorListProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
210
224
  errorSchema: ErrorSchema<T>;
211
225
  /** An array of the errors */
212
226
  errors: RJSFValidationError[];
213
- /** The `formContext` object that was passed to `Form` */
214
- formContext?: F;
215
227
  };
216
228
  /** The properties that are passed to an `FieldErrorTemplate` implementation */
217
229
  export type FieldErrorProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = RJSFBaseProps<T, S, F> & {
@@ -219,15 +231,15 @@ export type FieldErrorProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F
219
231
  errorSchema?: ErrorSchema<T>;
220
232
  /** An array of the errors */
221
233
  errors?: Array<string | ReactElement>;
222
- /** The tree of unique ids for every child field */
223
- idSchema: IdSchema<T>;
234
+ /** The FieldPathId of the field in the hierarchy */
235
+ fieldPathId: FieldPathId;
224
236
  };
225
237
  /** The properties that are passed to an `FieldHelpTemplate` implementation */
226
238
  export type FieldHelpProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = RJSFBaseProps<T, S, F> & {
227
239
  /** The help information to be rendered */
228
240
  help?: string | ReactElement;
229
- /** The tree of unique ids for every child field */
230
- idSchema: IdSchema<T>;
241
+ /** The FieldPathId of the field in the hierarchy */
242
+ fieldPathId: FieldPathId;
231
243
  /** Flag indicating whether there are errors associated with this field */
232
244
  hasErrors?: boolean;
233
245
  };
@@ -257,9 +269,9 @@ export type TemplatesType<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
257
269
  /** The template to use while rendering the description for an array field */
258
270
  ArrayFieldDescriptionTemplate: ComponentType<ArrayFieldDescriptionProps<T, S, F>>;
259
271
  /** The template to use while rendering the buttons for an item in an array field */
260
- ArrayFieldItemButtonsTemplate: ComponentType<ArrayFieldItemButtonsTemplateType<T, S, F>>;
272
+ ArrayFieldItemButtonsTemplate: ComponentType<ArrayFieldItemButtonsTemplateProps<T, S, F>>;
261
273
  /** The template to use while rendering an item in an array field */
262
- ArrayFieldItemTemplate: ComponentType<ArrayFieldItemTemplateType<T, S, F>>;
274
+ ArrayFieldItemTemplate: ComponentType<ArrayFieldItemTemplateProps<T, S, F>>;
263
275
  /** The template to use while rendering the title for an array field */
264
276
  ArrayFieldTitleTemplate: ComponentType<ArrayFieldTitleProps<T, S, F>>;
265
277
  /** The template to use while rendering the standard html input */
@@ -268,6 +280,8 @@ export type TemplatesType<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
268
280
  DescriptionFieldTemplate: ComponentType<DescriptionFieldProps<T, S, F>>;
269
281
  /** The template to use while rendering the errors for the whole form */
270
282
  ErrorListTemplate: ComponentType<ErrorListProps<T, S, F>>;
283
+ /** The template to use while rendering a fallback field for schemas that have an empty or unknown 'type' */
284
+ FallbackFieldTemplate: ComponentType<FallbackFieldTemplateProps<T, S, F>>;
271
285
  /** The template to use while rendering the errors for a single field */
272
286
  FieldErrorTemplate: ComponentType<FieldErrorProps<T, S, F>>;
273
287
  /** The template to use while rendering the errors for a single field */
@@ -276,8 +290,12 @@ export type TemplatesType<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
276
290
  FieldTemplate: ComponentType<FieldTemplateProps<T, S, F>>;
277
291
  /** The template to use to render a Grid element */
278
292
  GridTemplate: ComponentType<GridTemplateProps>;
293
+ /** The template to use while rendering a multi-schema field (i.e. anyOf, oneOf) */
294
+ MultiSchemaFieldTemplate: ComponentType<MultiSchemaFieldTemplateProps<T, S, F>>;
279
295
  /** The template to use while rendering an object */
280
296
  ObjectFieldTemplate: ComponentType<ObjectFieldTemplateProps<T, S, F>>;
297
+ /** The template to use while rendering the Optional Data field controls */
298
+ OptionalDataControlsTemplate: ComponentType<OptionalDataControlsTemplateProps<T, S, F>>;
281
299
  /** The template to use for rendering the title of a field */
282
300
  TitleFieldTemplate: ComponentType<TitleFieldProps<T, S, F>>;
283
301
  /** The template to use for rendering information about an unsupported field type in the schema */
@@ -327,6 +345,35 @@ export type GlobalUISchemaOptions = GenericObjectType & {
327
345
  /** Enables the displaying of description text that contains markdown
328
346
  */
329
347
  enableMarkdownInDescription?: boolean;
348
+ /** Enables the rendering of the Optional Data Field UI for specific types of schemas, either `object`, `array` or
349
+ * both. To disable the Optional Data Field UI for a specific field, provide an empty array within the UI schema.
350
+ */
351
+ enableOptionalDataFieldForType?: ('object' | 'array')[];
352
+ };
353
+ /** The set of options from the `Form` that will be available on the `Registry` for use in everywhere the `registry` is
354
+ * available.
355
+ */
356
+ export type GlobalFormOptions = {
357
+ /** To avoid collisions with existing ids in the DOM, it is possible to change the prefix used for ids;
358
+ * Default is `root`. This prop is passed to the `toFilePathId()` function within the RJSF field implementations.
359
+ */
360
+ readonly idPrefix: string;
361
+ /** To avoid using a path separator that is present in field names, it is possible to change the separator used for
362
+ * ids; Default is `_`. This prop is passed to the `toFilePathId()` function within the RJSF field implementations.
363
+ */
364
+ readonly idSeparator: string;
365
+ /** The component update strategy used by the Form and its fields for performance optimization */
366
+ readonly experimental_componentUpdateStrategy?: 'customDeep' | 'shallow' | 'always';
367
+ /** Optional function to generate custom HTML name attributes for form elements. Receives the field path segments
368
+ * and element type (object or array), and returns a custom name string. This allows backends like PHP/Rails
369
+ * (`root[tasks][0][title]`) or Django (`root__tasks-0__title`) to receive form data in their expected format.
370
+ */
371
+ readonly nameGenerator?: NameGeneratorFunction;
372
+ /**
373
+ * Boolean flag that, when set to true, will cause the form to use a fallback UI when encountering a schema type that
374
+ * is not supported by RJSF or a custom field. When false, the UnsupportedField error component will be shown instead.
375
+ */
376
+ readonly useFallbackUiForUnsupportedType?: boolean;
330
377
  };
331
378
  /** The object containing the registered core, theme and custom fields and widgets as well as the root schema, form
332
379
  * context, schema utils and templates.
@@ -336,7 +383,7 @@ export interface Registry<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
336
383
  * registered fields
337
384
  */
338
385
  fields: RegistryFieldsType<T, S, F>;
339
- /** The set of templates used by the `Form`. Includes templates from `core`, theme-specific fields and any custom
386
+ /** The set of templates used by the `Form`. Includes templates from `core`, theme-specific templates and any custom
340
387
  * registered templates
341
388
  */
342
389
  templates: TemplatesType<T, S, F>;
@@ -354,25 +401,27 @@ export interface Registry<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
354
401
  schemaUtils: SchemaUtilsType<T, S>;
355
402
  /** The string translation function to use when displaying any of the RJSF strings in templates, fields or widgets */
356
403
  translateString: (stringKey: TranslatableString, params?: string[]) => string;
404
+ /** The global Form Options that are available for all templates, fields and widgets to access */
405
+ readonly globalFormOptions: GlobalFormOptions;
357
406
  /** The optional global UI Options that are available for all templates, fields and widgets to access */
358
407
  globalUiOptions?: GlobalUISchemaOptions;
359
408
  }
360
- /** The properties that are passed to a Field implementation */
409
+ /** The properties that are passed to a `Field` implementation */
361
410
  export interface FieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> extends GenericObjectType, RJSFBaseProps<T, S, F>, Pick<HTMLAttributes<HTMLElement>, Exclude<keyof HTMLAttributes<HTMLElement>, 'onBlur' | 'onFocus' | 'onChange'>> {
362
- /** The tree of unique ids for every child field */
363
- idSchema: IdSchema<T>;
411
+ /** The FieldPathId of the field in the hierarchy */
412
+ fieldPathId: FieldPathId;
364
413
  /** The data for this field */
365
414
  formData?: T;
366
415
  /** The tree of errors for this field and its children */
367
416
  errorSchema?: ErrorSchema<T>;
368
- /** The field change event handler; called with the updated form data and an optional `ErrorSchema` */
369
- onChange: (newFormData: T | undefined, es?: ErrorSchema<T>, id?: string) => any;
417
+ /** The field change event handler; called with the updated field value, the change path for the value
418
+ * (defaults to an empty array), an optional ErrorSchema and the optional id of the field being changed
419
+ */
420
+ onChange: (newValue: T | undefined, path: FieldPathList, es?: ErrorSchema<T>, id?: string) => void;
370
421
  /** The input blur event handler; call it with the field id and value */
371
422
  onBlur: (id: string, value: any) => void;
372
423
  /** The input focus event handler; call it with the field id and value */
373
424
  onFocus: (id: string, value: any) => void;
374
- /** The `formContext` object that you passed to `Form` */
375
- formContext?: F;
376
425
  /** A boolean value stating if the field should autofocus */
377
426
  autofocus?: boolean;
378
427
  /** A boolean value stating if the field is disabled */
@@ -385,14 +434,6 @@ export interface FieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F
385
434
  required?: boolean;
386
435
  /** The unique name of the field, usually derived from the name of the property in the JSONSchema */
387
436
  name: string;
388
- /** To avoid collisions with existing ids in the DOM, it is possible to change the prefix used for ids;
389
- * Default is `root`
390
- */
391
- idPrefix?: string;
392
- /** To avoid using a path separator that is present in field names, it is possible to change the separator used for
393
- * ids (Default is `_`)
394
- */
395
- idSeparator?: string;
396
437
  /** An array of strings listing all generated error messages from encountered errors for this field */
397
438
  rawErrors?: string[];
398
439
  }
@@ -401,7 +442,7 @@ export type Field<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
401
442
  /** The optional TEST_IDS block that some fields contain, exported for testing purposes */
402
443
  TEST_IDS?: TestIdShape;
403
444
  };
404
- /** The properties that are passed to a FieldTemplate implementation */
445
+ /** The properties that are passed to a `FieldTemplate` implementation */
405
446
  export type FieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = RJSFBaseProps<T, S, F> & {
406
447
  /** The id of the field in the hierarchy. You can use it to render a label targeting the wrapped widget */
407
448
  id: string;
@@ -443,21 +484,37 @@ export type FieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema,
443
484
  * you don't want to clutter the UI
444
485
  */
445
486
  displayLabel?: boolean;
446
- /** The `formContext` object that was passed to `Form` */
447
- formContext?: F;
448
487
  /** The formData for this field */
449
488
  formData?: T;
450
489
  /** The value change event handler; Can be called with a new value to change the value for this field */
451
490
  onChange: FieldProps<T, S, F>['onChange'];
452
- /** The key change event handler; Called when the key associated with a field is changed for an additionalProperty */
453
- onKeyChange: (value: string) => () => void;
454
- /** The property drop/removal event handler; Called when a field is removed in an additionalProperty context */
455
- onDropPropertyClick: (value: string) => () => void;
491
+ /** Callback used to handle the changing of an additional property key's name with the new value
492
+ */
493
+ onKeyRename: (newKey: string) => void;
494
+ /** Callback used to handle the changing of an additional property key's name when the input is blurred. The event's
495
+ * target's value will be used as the new value. Its a wrapper callback around `onKeyRename`
496
+ */
497
+ onKeyRenameBlur: (event: FocusEvent<HTMLInputElement>) => void;
498
+ /** Callback used to handle the removal of the additionalProperty */
499
+ onRemoveProperty: () => void;
500
+ };
501
+ /**
502
+ * The properties that are passed to a `FallbackField` implementation
503
+ */
504
+ export type FallbackFieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = FieldProps<T, S, F>;
505
+ /**
506
+ * The properties that are passed to a `FallbackFieldTemplate` implementation
507
+ */
508
+ export type FallbackFieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = RJSFBaseProps<T, S, F> & {
509
+ /** A ReactNode that allows the selecting a different type for the field */
510
+ typeSelector: ReactNode;
511
+ /** A ReactNode that renders the field with the present formData and matches the selected type */
512
+ schemaField: ReactNode;
456
513
  };
457
514
  /** The properties that are passed to the `UnsupportedFieldTemplate` implementation */
458
515
  export type UnsupportedFieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = RJSFBaseProps<T, S, F> & {
459
- /** The tree of unique ids for every child field */
460
- idSchema?: IdSchema<T>;
516
+ /** The FieldPathId of the field in the hierarchy */
517
+ fieldPathId: FieldPathId;
461
518
  /** The reason why the schema field has an unsupported type */
462
519
  reason: string;
463
520
  };
@@ -469,6 +526,8 @@ export type TitleFieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F
469
526
  title: string;
470
527
  /** A boolean value stating if the field is required */
471
528
  required?: boolean;
529
+ /** Add optional data control */
530
+ optionalDataControl?: ReactNode;
472
531
  };
473
532
  /** The properties that are passed to a `DescriptionFieldTemplate` implementation */
474
533
  export type DescriptionFieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = RJSFBaseProps<T, S, F> & {
@@ -481,20 +540,22 @@ export type DescriptionFieldProps<T = any, S extends StrictRJSFSchema = RJSFSche
481
540
  export type ArrayFieldTitleProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = Omit<TitleFieldProps<T, S, F>, 'id' | 'title'> & {
482
541
  /** The title for the field being rendered */
483
542
  title?: string;
484
- /** The idSchema of the field in the hierarchy */
485
- idSchema: IdSchema<T>;
543
+ /** The FieldPathId of the field in the hierarchy */
544
+ fieldPathId: FieldPathId;
545
+ /** Add optional data control */
546
+ optionalDataControl?: ReactNode;
486
547
  };
487
548
  /** The properties that are passed to a `ArrayFieldDescriptionTemplate` implementation */
488
549
  export type ArrayFieldDescriptionProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = Omit<DescriptionFieldProps<T, S, F>, 'id' | 'description'> & {
489
550
  /** The description of the field being rendered */
490
551
  description?: string | ReactElement;
491
- /** The idSchema of the field in the hierarchy */
492
- idSchema: IdSchema<T>;
552
+ /** An object containing the id and path for this field */
553
+ fieldPathId: FieldPathId;
493
554
  };
494
555
  /** The properties of the buttons to render for each element in the ArrayFieldTemplateProps.items array */
495
- export type ArrayFieldItemButtonsTemplateType<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = RJSFBaseProps<T, S, F> & {
496
- /** The idSchema of the item for which buttons are being rendered */
497
- idSchema: IdSchema<T>;
556
+ export type ArrayFieldItemButtonsTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = RJSFBaseProps<T, S, F> & {
557
+ /** The FieldPathId of the item for which buttons are being rendered */
558
+ fieldPathId: FieldPathId;
498
559
  /** The className string */
499
560
  className?: string;
500
561
  /** Any optional style attributes */
@@ -515,23 +576,25 @@ export type ArrayFieldItemButtonsTemplateType<T = any, S extends StrictRJSFSchem
515
576
  index: number;
516
577
  /** A number stating the total number `items` in the array */
517
578
  totalItems: number;
518
- /** Returns a function that adds a new item at `index` */
519
- onAddIndexClick: (index: number) => (event?: any) => void;
520
- /** Returns a function that copies the item at `index` into the position at `index + 1` */
521
- onCopyIndexClick: (index: number) => (event?: any) => void;
522
- /** Returns a function that removes the item at `index` */
523
- onDropIndexClick: (index: number) => (event?: any) => void;
524
- /** Returns a function that swaps the items at `index` with `newIndex` */
525
- onReorderClick: (index: number, newIndex: number) => (event?: any) => void;
579
+ /** Callback function that adds a new item below this item */
580
+ onAddItem: (event?: any) => void;
581
+ /** Callback function that copies this item below itself */
582
+ onCopyItem: (event?: any) => void;
583
+ /** Callback function that moves the item up one spot in the list */
584
+ onMoveUpItem: (event?: any) => void;
585
+ /** Callback function that moves the item down one spot in the list */
586
+ onMoveDownItem: (event?: any) => void;
587
+ /** Callback function that removes the item from the list */
588
+ onRemoveItem: (event?: any) => void;
526
589
  /** A boolean value stating if the array item is read-only */
527
590
  readonly?: boolean;
528
591
  };
529
- /** The properties of each element in the ArrayFieldTemplateProps.items array */
530
- export type ArrayFieldItemTemplateType<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = RJSFBaseProps<T, S, F> & {
592
+ /** The properties used to render the ArrayFieldItemTemplate */
593
+ export type ArrayFieldItemTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = RJSFBaseProps<T, S, F> & {
531
594
  /** The html for the item's content */
532
595
  children: ReactNode;
533
596
  /** The props to pass to the `ArrayFieldItemButtonTemplate` */
534
- buttonsProps: ArrayFieldItemButtonsTemplateType<T, S, F>;
597
+ buttonsProps: ArrayFieldItemButtonsTemplateProps<T, S, F>;
535
598
  /** The className string */
536
599
  className: string;
537
600
  /** A boolean value stating if the array item is disabled */
@@ -545,26 +608,20 @@ export type ArrayFieldItemTemplateType<T = any, S extends StrictRJSFSchema = RJS
545
608
  /** A boolean value stating if the array item is read-only */
546
609
  readonly?: boolean;
547
610
  /** A stable, unique key for the array item */
548
- key: string;
611
+ itemKey: string;
612
+ /** The UI schema of the array item's parent array field used for
613
+ * customization in some themes
614
+ */
615
+ parentUiSchema?: UiSchema<T, S, F>;
549
616
  };
550
- /**
551
- * @deprecated - Use `ArrayFieldItemTemplateType` instead
552
- */
553
- export type ArrayFieldTemplateItemType<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = ArrayFieldItemTemplateType<T, S, F>;
554
- /** The properties that are passed to an ArrayFieldTemplate implementation */
555
- export type ArrayFieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = RJSFBaseProps<T, S, F> & {
556
- /** A boolean value stating whether new elements can be added to the array */
557
- canAdd?: boolean;
617
+ /** The common properties of the two container templates: `ArrayFieldTemplateProps` and `ObjectFieldTemplateProps` */
618
+ export type ContainerFieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = RJSFBaseProps<T, S, F> & {
558
619
  /** The className string */
559
620
  className?: string;
560
621
  /** A boolean value stating if the array is disabled */
561
622
  disabled?: boolean;
562
- /** An object containing the id for this object & ids for its properties */
563
- idSchema: IdSchema<T>;
564
- /** An array of objects representing the items in the array */
565
- items: ArrayFieldItemTemplateType<T, S, F>[];
566
- /** A function that adds a new item to the array */
567
- onAddClick: (event?: any) => void;
623
+ /** The FieldPathId of the field in the hierarchy */
624
+ fieldPathId: FieldPathId;
568
625
  /** A boolean value stating if the array is read-only */
569
626
  readonly?: boolean;
570
627
  /** A boolean value stating if the array is required */
@@ -573,12 +630,21 @@ export type ArrayFieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSc
573
630
  hideError?: boolean;
574
631
  /** A string value containing the title for the array */
575
632
  title: string;
576
- /** The `formContext` object that was passed to Form */
577
- formContext?: F;
578
633
  /** The formData for this array */
579
634
  formData?: T;
580
- /** The tree of errors for this field and its children */
635
+ /** The optional validation errors in the form of an `ErrorSchema` */
581
636
  errorSchema?: ErrorSchema<T>;
637
+ /** The optional data control node to render within the ObjectFieldTemplate that controls */
638
+ optionalDataControl?: ReactNode;
639
+ };
640
+ /** The properties that are passed to an `ArrayFieldTemplate` implementation */
641
+ export type ArrayFieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = ContainerFieldTemplateProps<T, S, F> & {
642
+ /** A boolean value stating whether new elements can be added to the array */
643
+ canAdd?: boolean;
644
+ /** An array of React elements representing the items in the array */
645
+ items: ReactElement[];
646
+ /** A function that adds a new item to the end of the array */
647
+ onAddClick: (event?: any) => void;
582
648
  /** An array of strings listing all generated error messages from encountered errors for this widget */
583
649
  rawErrors?: string[];
584
650
  };
@@ -596,39 +662,53 @@ export type ObjectFieldTemplatePropertyType = {
596
662
  hidden: boolean;
597
663
  };
598
664
  /** The properties that are passed to an ObjectFieldTemplate implementation */
599
- export type ObjectFieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = RJSFBaseProps<T, S, F> & {
600
- /** A string value containing the title for the object */
601
- title: string;
665
+ export type ObjectFieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = ContainerFieldTemplateProps<T, S, F> & {
602
666
  /** A string value containing the description for the object */
603
667
  description?: string | ReactElement;
604
- /** A boolean value stating if the object is disabled */
605
- disabled?: boolean;
606
668
  /** An array of objects representing the properties in the object */
607
669
  properties: ObjectFieldTemplatePropertyType[];
608
- /** Returns a function that adds a new property to the object (to be used with additionalProperties) */
609
- onAddClick: (schema: S) => () => void;
670
+ /** Callback to use in order to add an new additionalProperty to the object field (to be used with
671
+ * additionalProperties and patternProperties)
672
+ */
673
+ onAddProperty: () => void;
610
674
  /** A boolean value stating if the object is read-only */
611
675
  readonly?: boolean;
612
676
  /** A boolean value stating if the object is required */
613
677
  required?: boolean;
614
678
  /** A boolean value stating if the field is hiding its errors */
615
679
  hideError?: boolean;
616
- /** An object containing the id for this object & ids for its properties */
617
- idSchema: IdSchema<T>;
680
+ /** The FieldPathId of the field in the hierarchy */
681
+ fieldPathId: FieldPathId;
618
682
  /** The optional validation errors in the form of an `ErrorSchema` */
619
683
  errorSchema?: ErrorSchema<T>;
620
684
  /** The form data for the object */
621
685
  formData?: T;
622
- /** The `formContext` object that was passed to Form */
623
- formContext?: F;
686
+ };
687
+ /** The properties that are passed to a OptionalDataControlsTemplate implementation */
688
+ export type OptionalDataControlsTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = RJSFBaseProps<T, S, F> & {
689
+ /** The generated id for this Optional Data Control instance */
690
+ id: string;
691
+ /** The label to use for the Optional Data Control */
692
+ label: string;
693
+ /** Optional callback to call when clicking on the Optional Data Control to add data */
694
+ onRemoveClick?: () => void;
695
+ /** Optional callback to call when clicking on the Optional Data Control to remove data */
696
+ onAddClick?: () => void;
624
697
  };
625
698
  /** The properties that are passed to a WrapIfAdditionalTemplate implementation */
626
699
  export type WrapIfAdditionalTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = RJSFBaseProps<T, S, F> & {
627
700
  /** The field or widget component instance for this field row */
628
701
  children: ReactNode;
629
- } & Pick<FieldTemplateProps<T, S, F>, 'id' | 'classNames' | 'hideError' | 'rawErrors' | 'style' | 'label' | 'required' | 'readonly' | 'disabled' | 'schema' | 'uiSchema' | 'onKeyChange' | 'onDropPropertyClick' | 'registry'>;
630
- /** The properties that are passed to a Widget implementation */
631
- export interface WidgetProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> extends GenericObjectType, RJSFBaseProps<T, S, F>, Pick<HTMLAttributes<HTMLElement>, Exclude<keyof HTMLAttributes<HTMLElement>, 'onBlur' | 'onFocus'>> {
702
+ } & Pick<FieldTemplateProps<T, S, F>, 'id' | 'classNames' | 'hideError' | 'rawErrors' | 'style' | 'label' | 'required' | 'readonly' | 'disabled' | 'schema' | 'uiSchema' | 'onKeyRename' | 'onKeyRenameBlur' | 'onRemoveProperty' | 'registry'>;
703
+ /** The properties that are passed to a MultiSchemaFieldTemplate implementation */
704
+ export interface MultiSchemaFieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> extends RJSFBaseProps<T, S, F> {
705
+ /** The rendered widget used to select a schema option */
706
+ selector: ReactNode;
707
+ /** The rendered SchemaField for the selected schema option */
708
+ optionSchemaField: ReactNode;
709
+ }
710
+ /** The properties that are passed to a `Widget` implementation */
711
+ export interface WidgetProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> extends GenericObjectType, RJSFBaseProps<T, S, F>, Pick<HTMLAttributes<HTMLElement>, Exclude<keyof HTMLAttributes<HTMLElement>, 'onBlur' | 'onFocus' | 'onChange'>> {
632
712
  /** The generated id for this widget, used to provide unique `name`s and `id`s for the HTML field elements rendered by
633
713
  * widgets
634
714
  */
@@ -658,8 +738,6 @@ export interface WidgetProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F
658
738
  /** The enum options list for a type that supports them */
659
739
  enumOptions?: EnumOptionsType<S>[];
660
740
  };
661
- /** The `formContext` object that you passed to `Form` */
662
- formContext?: F;
663
741
  /** The input blur event handler; call it with the widget id and value */
664
742
  onBlur: (id: string, value: any) => void;
665
743
  /** The value change event handler; call it with the new value every time it changes */
@@ -676,6 +754,8 @@ export interface WidgetProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F
676
754
  multiple?: boolean;
677
755
  /** An array of strings listing all generated error messages from encountered errors for this widget */
678
756
  rawErrors?: string[];
757
+ /** The optional custom HTML name attribute generated by the nameGenerator function, if provided */
758
+ htmlName?: string;
679
759
  }
680
760
  /** The definition of a React-based Widget component */
681
761
  export type Widget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = ComponentType<WidgetProps<T, S, F>>;
@@ -792,6 +872,12 @@ export type UIOptionsType<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
792
872
  /** Anything else will be one of these types */
793
873
  [key: string]: boolean | number | string | object | any[] | null | undefined;
794
874
  };
875
+ /**
876
+ * A utility type that extracts the element type from an array type.
877
+ * If the type is not an array, it returns the type itself as a safe fallback.
878
+ * Handles both standard arrays and readonly arrays.
879
+ */
880
+ export type ArrayElement<A> = A extends readonly (infer E)[] ? E : A;
795
881
  /** Type describing the well-known properties of the `UiSchema` while also supporting all user defined properties,
796
882
  * starting with `ui:`.
797
883
  */
@@ -800,7 +886,10 @@ export type UiSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
800
886
  * Registry for use everywhere.
801
887
  */
802
888
  'ui:globalOptions'?: GlobalUISchemaOptions;
803
- /** Allows the form to generate a unique prefix for the `Form`'s root prefix */
889
+ /** Allows the form to generate a unique prefix for the `Form`'s root prefix
890
+ *
891
+ * @deprecated - use `Form.idPrefix` instead, will be removed in a future major version
892
+ */
804
893
  'ui:rootFieldId'?: string;
805
894
  /** By default, any field that is rendered for an `anyOf`/`oneOf` schema will be wrapped inside the `AnyOfField` or
806
895
  * `OneOfField` component. This default behavior may be undesirable if your custom field already handles behavior
@@ -812,6 +901,11 @@ export type UiSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
812
901
  'ui:fieldReplacesAnyOrOneOf'?: boolean;
813
902
  /** An object that contains all the potential UI options in a single object */
814
903
  'ui:options'?: UIOptionsType<T, S, F>;
904
+ /** The uiSchema for items in an array. Can be an object for a uniform uiSchema across all items (current behavior),
905
+ * or a function that returns a dynamic uiSchema based on the item's data and index.
906
+ * When using a function, it receives the item data, index, and optionally the form context as parameters.
907
+ */
908
+ items?: UiSchema<ArrayElement<T>, S, F> | ((itemData: ArrayElement<T>, index: number, formContext?: F) => UiSchema<ArrayElement<T>, S, F>);
815
909
  };
816
910
  /** A `CustomValidator` function takes in a `formData`, `errors` and `uiSchema` objects and returns the given `errors`
817
911
  * object back, while potentially adding additional messages to the `errors`
@@ -882,6 +976,11 @@ export interface FoundFieldType<S extends StrictRJSFSchema = RJSFSchema> {
882
976
  * set of APIs to the `@rjsf/core` components and the various themes as well.
883
977
  */
884
978
  export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> {
979
+ /** Returns the `rootSchema` in the `SchemaUtilsType`
980
+ *
981
+ * @returns - The rootSchema
982
+ */
983
+ getRootSchema(): S;
885
984
  /** Returns the `ValidatorType` in the `SchemaUtilsType`
886
985
  *
887
986
  * @returns - The `ValidatorType`
@@ -928,9 +1027,10 @@ export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchem
928
1027
  * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
929
1028
  * If "excludeObjectChildren", cause undefined values for this object and pass `includeUndefinedValues` as
930
1029
  * false when computing defaults for any nested object properties.
1030
+ * @param initialDefaultsGenerated - Indicates whether or not initial defaults have been generated
931
1031
  * @returns - The resulting `formData` with all the defaults provided
932
1032
  */
933
- getDefaultFormState(schema: S, formData?: T, includeUndefinedValues?: boolean | 'excludeObjectChildren'): T | T[] | undefined;
1033
+ getDefaultFormState(schema: S, formData?: T, includeUndefinedValues?: boolean | 'excludeObjectChildren', initialDefaultsGenerated?: boolean): T | T[] | undefined;
934
1034
  /** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
935
1035
  * should be displayed in a UI.
936
1036
  *
@@ -1000,9 +1100,10 @@ export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchem
1000
1100
  *
1001
1101
  * @param schema - The schema for which retrieving a schema is desired
1002
1102
  * @param [formData] - The current formData, if any, to assist retrieving a schema
1103
+ * @param [resolveAnyOfOrOneOfRefs] - Optional flag indicating whether to resolved refs in anyOf/oneOf lists
1003
1104
  * @returns - The schema having its conditions, additional properties, references and dependencies resolved
1004
1105
  */
1005
- retrieveSchema(schema: S, formData?: T): S;
1106
+ retrieveSchema(schema: S, formData?: T, resolveAnyOfOrOneOfRefs?: boolean): S;
1006
1107
  /** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the
1007
1108
  * new schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the
1008
1109
  * nature of schemas, this sanitization happens recursively for nested objects of data. Also, any properties in the
@@ -1015,16 +1116,6 @@ export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchem
1015
1116
  * to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
1016
1117
  */
1017
1118
  sanitizeDataForNewSchema(newSchema?: S, oldSchema?: S, data?: any): T;
1018
- /** Generates an `IdSchema` object for the `schema`, recursively
1019
- *
1020
- * @param schema - The schema for which the display label flag is desired
1021
- * @param [id] - The base id for the schema
1022
- * @param [formData] - The current formData, if any, onto which to provide any missing defaults
1023
- * @param [idPrefix='root'] - The prefix to use for the id
1024
- * @param [idSeparator='_'] - The separator to use for the path segments in the id
1025
- * @returns - The `IdSchema` object for the `schema`
1026
- */
1027
- toIdSchema(schema: S, id?: string, formData?: T, idPrefix?: string, idSeparator?: string): IdSchema<T>;
1028
1119
  /** Generates an `PathSchema` object for the `schema`, recursively
1029
1120
  *
1030
1121
  * @param schema - The schema for which the display label flag is desired
@@ -0,0 +1,39 @@
1
+ import { MouseEvent } from 'react';
2
+ import { DateElementProp } from './getDateElementProps.js';
3
+ import { DateObject, FormContextType, RJSFSchema, StrictRJSFSchema, WidgetProps } from './types.js';
4
+ /** The Props for the `DateElement` component */
5
+ export type DateElementProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = Pick<WidgetProps<T, S, F>, 'value' | 'name' | 'disabled' | 'readonly' | 'autofocus' | 'registry' | 'onBlur' | 'onFocus' | 'className'> & {
6
+ /** The root id of the field */
7
+ rootId: string;
8
+ /** The selector function for a specific prop within the `DateObject`, for a value */
9
+ select: (property: keyof DateObject, value: any) => void;
10
+ /** The type of the date element */
11
+ type: DateElementProp['type'];
12
+ /** The range for the date element */
13
+ range: DateElementProp['range'];
14
+ };
15
+ /** The `DateElement` component renders one of the 6 date element selectors for an `AltDateWidget`, using the `select`
16
+ * widget from the registry.
17
+ *
18
+ * @param props - The `DateElementProps` for the date element
19
+ */
20
+ export declare function DateElement<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(props: DateElementProps<T, S, F>): import("react/jsx-runtime").JSX.Element;
21
+ /** The result of a call to the `useAltDateWidgetProps()` hook */
22
+ export type UseAltDateWidgetResult = {
23
+ /** The list of `DateElementProp` data to render for the `AltDateWidget` */
24
+ elements: DateElementProp[];
25
+ /** The callback that handles the changing of DateElement components */
26
+ handleChange: (property: keyof DateObject, value?: string) => void;
27
+ /** The callback that will clear the `AltDateWidget` when a button is clicked */
28
+ handleClear: (event: MouseEvent) => void;
29
+ /** The callback that will set the `AltDateWidget` to NOW when a button is clicked */
30
+ handleSetNow: (event: MouseEvent) => void;
31
+ };
32
+ /** Hook which encapsulates the logic needed to render an `AltDateWidget` with optional `time` elements. It contains
33
+ * the `state` of the current date(/time) selections in the widget. It returns a `UseAltDateWidgetResult` object
34
+ * that contains the `elements: DateElementProp[]` and three callbacks needed to change one of the rendered `elements`,
35
+ * and to handle the clicking of the `clear` and `setNow` buttons.
36
+ *
37
+ * @param props - The `WidgetProps` for the `AltDateWidget`
38
+ */
39
+ export default function useAltDateWidgetProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(props: WidgetProps<T, S, F>): UseAltDateWidgetResult;