@rjsf/utils 6.5.2 → 6.6.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 (146) hide show
  1. package/dist/index.cjs +628 -441
  2. package/dist/index.cjs.map +4 -4
  3. package/dist/utils.esm.js +624 -437
  4. package/dist/utils.esm.js.map +4 -4
  5. package/dist/utils.umd.js +632 -445
  6. package/lib/ErrorSchemaBuilder.js.map +1 -1
  7. package/lib/canExpand.js.map +1 -1
  8. package/lib/constIsAjvDataReference.js +1 -1
  9. package/lib/constIsAjvDataReference.js.map +1 -1
  10. package/lib/createSchemaUtils.js +3 -3
  11. package/lib/createSchemaUtils.js.map +1 -1
  12. package/lib/enumOptionSelectedValue.js.map +1 -1
  13. package/lib/enumOptionValueDecoder.js.map +1 -1
  14. package/lib/enumOptionsDeselectValue.js +1 -1
  15. package/lib/enumOptionsDeselectValue.js.map +1 -1
  16. package/lib/enumOptionsIndexForValue.js.map +1 -1
  17. package/lib/enumOptionsIsSelected.js.map +1 -1
  18. package/lib/enumOptionsSelectValue.js +1 -1
  19. package/lib/enumOptionsSelectValue.js.map +1 -1
  20. package/lib/enumOptionsValueForIndex.js +2 -2
  21. package/lib/enumOptionsValueForIndex.js.map +1 -1
  22. package/lib/enums.d.ts +2 -0
  23. package/lib/enums.js +2 -0
  24. package/lib/enums.js.map +1 -1
  25. package/lib/findSchemaDefinition.js +4 -4
  26. package/lib/findSchemaDefinition.js.map +1 -1
  27. package/lib/getChangedFields.js +3 -3
  28. package/lib/getChangedFields.js.map +1 -1
  29. package/lib/getDiscriminatorFieldFromSchema.js.map +1 -1
  30. package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -1
  31. package/lib/getTestIds.d.ts +1 -1
  32. package/lib/getTestIds.js +4 -3
  33. package/lib/getTestIds.js.map +1 -1
  34. package/lib/getWidget.js +1 -1
  35. package/lib/getWidget.js.map +1 -1
  36. package/lib/idGenerators.js.map +1 -1
  37. package/lib/index.d.ts +6 -6
  38. package/lib/index.js +6 -6
  39. package/lib/index.js.map +1 -1
  40. package/lib/isFormDataAvailable.js +1 -1
  41. package/lib/isFormDataAvailable.js.map +1 -1
  42. package/lib/isRootSchema.js +1 -1
  43. package/lib/isRootSchema.js.map +1 -1
  44. package/lib/jsonSchemaAugmentation.d.ts +19 -0
  45. package/lib/jsonSchemaAugmentation.js +2 -0
  46. package/lib/jsonSchemaAugmentation.js.map +1 -0
  47. package/lib/mergeDefaultsWithFormData.js +2 -2
  48. package/lib/mergeDefaultsWithFormData.js.map +1 -1
  49. package/lib/parser/ParserValidator.js +1 -1
  50. package/lib/parser/ParserValidator.js.map +1 -1
  51. package/lib/parser/index.d.ts +1 -1
  52. package/lib/parser/index.js.map +1 -1
  53. package/lib/parser/schemaParser.js +2 -2
  54. package/lib/parser/schemaParser.js.map +1 -1
  55. package/lib/removeOptionalEmptyObjects.d.ts +2 -0
  56. package/lib/removeOptionalEmptyObjects.js +8 -29
  57. package/lib/removeOptionalEmptyObjects.js.map +1 -1
  58. package/lib/schema/findFieldInSchema.d.ts +2 -2
  59. package/lib/schema/findFieldInSchema.js +7 -6
  60. package/lib/schema/findFieldInSchema.js.map +1 -1
  61. package/lib/schema/findSelectedOptionInXxxOf.js +1 -1
  62. package/lib/schema/findSelectedOptionInXxxOf.js.map +1 -1
  63. package/lib/schema/getClosestMatchingOption.js +3 -3
  64. package/lib/schema/getClosestMatchingOption.js.map +1 -1
  65. package/lib/schema/getDefaultFormState.d.ts +4 -4
  66. package/lib/schema/getDefaultFormState.js +17 -22
  67. package/lib/schema/getDefaultFormState.js.map +1 -1
  68. package/lib/schema/getFromSchema.d.ts +3 -3
  69. package/lib/schema/getFromSchema.js +3 -3
  70. package/lib/schema/getFromSchema.js.map +1 -1
  71. package/lib/schema/index.d.ts +4 -4
  72. package/lib/schema/index.js +4 -4
  73. package/lib/schema/index.js.map +1 -1
  74. package/lib/schema/isMultiSelect.js.map +1 -1
  75. package/lib/schema/omitExtraData.d.ts +18 -8
  76. package/lib/schema/omitExtraData.js +352 -16
  77. package/lib/schema/omitExtraData.js.map +1 -1
  78. package/lib/schema/retrieveSchema.d.ts +15 -0
  79. package/lib/schema/retrieveSchema.js +36 -13
  80. package/lib/schema/retrieveSchema.js.map +1 -1
  81. package/lib/schema/sanitizeDataForNewSchema.js.map +1 -1
  82. package/lib/schema/shallowAllOfMerge.d.ts +11 -0
  83. package/lib/schema/shallowAllOfMerge.js +18 -0
  84. package/lib/schema/shallowAllOfMerge.js.map +1 -0
  85. package/lib/schema/toPathSchema.d.ts +1 -0
  86. package/lib/schema/toPathSchema.js +2 -1
  87. package/lib/schema/toPathSchema.js.map +1 -1
  88. package/lib/shouldRenderOptionalField.js +1 -1
  89. package/lib/shouldRenderOptionalField.js.map +1 -1
  90. package/lib/toErrorSchema.js.map +1 -1
  91. package/lib/tsconfig.tsbuildinfo +1 -1
  92. package/lib/types.d.ts +17 -5
  93. package/lib/types.js +1 -1
  94. package/lib/types.js.map +1 -1
  95. package/lib/useFileWidgetProps.d.ts +1 -1
  96. package/lib/useFileWidgetProps.js +9 -10
  97. package/lib/useFileWidgetProps.js.map +1 -1
  98. package/lib/withIdRefPrefix.js +1 -1
  99. package/lib/withIdRefPrefix.js.map +1 -1
  100. package/package.json +11 -11
  101. package/src/ErrorSchemaBuilder.ts +1 -1
  102. package/src/canExpand.ts +1 -1
  103. package/src/constIsAjvDataReference.ts +3 -2
  104. package/src/createSchemaUtils.ts +22 -20
  105. package/src/enumOptionSelectedValue.ts +1 -1
  106. package/src/enumOptionValueDecoder.ts +1 -1
  107. package/src/enumOptionsDeselectValue.ts +2 -2
  108. package/src/enumOptionsIndexForValue.ts +1 -1
  109. package/src/enumOptionsIsSelected.ts +1 -1
  110. package/src/enumOptionsSelectValue.ts +3 -2
  111. package/src/enumOptionsValueForIndex.ts +2 -2
  112. package/src/enums.ts +2 -0
  113. package/src/findSchemaDefinition.ts +4 -4
  114. package/src/getChangedFields.ts +4 -3
  115. package/src/getDiscriminatorFieldFromSchema.ts +1 -1
  116. package/src/getOptionMatchingSimpleDiscriminator.ts +1 -0
  117. package/src/getTestIds.ts +4 -3
  118. package/src/getWidget.tsx +2 -2
  119. package/src/idGenerators.ts +1 -1
  120. package/src/index.ts +6 -6
  121. package/src/isFormDataAvailable.ts +1 -1
  122. package/src/isRootSchema.ts +1 -1
  123. package/src/jsonSchemaAugmentation.ts +21 -0
  124. package/src/mergeDefaultsWithFormData.ts +4 -3
  125. package/src/parser/ParserValidator.ts +1 -1
  126. package/src/parser/index.ts +1 -1
  127. package/src/parser/schemaParser.ts +3 -3
  128. package/src/removeOptionalEmptyObjects.ts +8 -30
  129. package/src/schema/findFieldInSchema.ts +10 -8
  130. package/src/schema/findSelectedOptionInXxxOf.ts +1 -1
  131. package/src/schema/getClosestMatchingOption.ts +4 -4
  132. package/src/schema/getDefaultFormState.ts +18 -24
  133. package/src/schema/getFromSchema.ts +15 -8
  134. package/src/schema/index.ts +5 -3
  135. package/src/schema/isMultiSelect.ts +0 -1
  136. package/src/schema/omitExtraData.ts +398 -19
  137. package/src/schema/retrieveSchema.ts +41 -15
  138. package/src/schema/sanitizeDataForNewSchema.ts +1 -1
  139. package/src/schema/shallowAllOfMerge.ts +19 -0
  140. package/src/schema/toPathSchema.ts +2 -1
  141. package/src/shouldRenderOptionalField.ts +2 -2
  142. package/src/toErrorSchema.ts +1 -1
  143. package/src/tsconfig.json +0 -1
  144. package/src/types.ts +18 -5
  145. package/src/useFileWidgetProps.ts +9 -10
  146. package/src/withIdRefPrefix.ts +2 -1
package/src/types.ts CHANGED
@@ -11,6 +11,7 @@ import type {
11
11
  import { JSONSchema7 } from 'json-schema';
12
12
 
13
13
  import { TranslatableString } from './enums';
14
+ import './jsonSchemaAugmentation';
14
15
 
15
16
  /** The representation of any generic object type, usually used as an intersection on other types to make them more
16
17
  * flexible in the properties they support (i.e. anything else)
@@ -185,6 +186,9 @@ export type InputPropsType = {
185
186
  */
186
187
  export type FieldPathList = (string | number)[];
187
188
 
189
+ /** Dot string or segment list for `getFromSchema` / `findFieldInSchema` (same segment rules as {@link FieldPathList}). */
190
+ export type SchemaFieldPath = string | FieldPathList;
191
+
188
192
  /** Type describing an id and path used for a field */
189
193
  export type FieldPathId = {
190
194
  /** The id for a field */
@@ -201,7 +205,9 @@ export type FieldPath = {
201
205
  $name: string;
202
206
  };
203
207
 
204
- /** Type describing a recursive structure of `FieldPath`s for an object with a non-empty set of keys */
208
+ /** Type describing a recursive structure of `FieldPath`s for an object with a non-empty set of keys
209
+ * @deprecated - To be removed as an exported `@rjsf/utils` type in a future release
210
+ */
205
211
  export type PathSchema<T = any> =
206
212
  T extends Array<infer U>
207
213
  ? FieldPath & {
@@ -447,6 +453,12 @@ export type GlobalUISchemaOptions = GenericObjectType & {
447
453
  * only affects the DOM-level encoding.
448
454
  */
449
455
  optionValueFormat?: OptionValueFormat;
456
+ /** Controls how a deprecated property is rendered.
457
+ * - `hide`: The field is completely hidden (via the `hidden` prop passed to FieldTemplate).
458
+ * - `disable`: The field is rendered but disabled.
459
+ * - `label` (default): The field is rendered with "(deprecated)" appended to its label.
460
+ */
461
+ deprecatedHandling?: 'hide' | 'disable' | 'label';
450
462
  };
451
463
 
452
464
  /** The set of options from the `Form` that will be available on the `Registry` for use in everywhere the `registry` is
@@ -1328,7 +1340,7 @@ export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchem
1328
1340
  * @returns - An object that contains the field and its required state. If no field can be found then
1329
1341
  * `{ field: undefined, isRequired: undefined }` is returned.
1330
1342
  */
1331
- findFieldInSchema(schema: S, path: string | string[], formData?: T): FoundFieldType<S>;
1343
+ findFieldInSchema(schema: S, path: SchemaFieldPath, formData?: T): FoundFieldType<S>;
1332
1344
  /** Finds the oneOf option inside the `schema['any/oneOf']` list which has the `properties[selectorField].default` that
1333
1345
  * matches the `formData[selectorField]` value. For the purposes of this function, `selectorField` is either
1334
1346
  * `schema.discriminator.propertyName` or `fallbackField`.
@@ -1403,9 +1415,9 @@ export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchem
1403
1415
  * @param defaultValue - The value to return if a value is not found for the `pathList` path
1404
1416
  * @returns - The internal schema from the `schema` for the given `path` or the `defaultValue` if not found
1405
1417
  */
1406
- getFromSchema(schema: S, path: string | string[], defaultValue: T): T;
1407
- getFromSchema(schema: S, path: string | string[], defaultValue: S): S;
1408
- getFromSchema(schema: S, path: string | string[], defaultValue: T | S): S | T;
1418
+ getFromSchema(schema: S, path: SchemaFieldPath, defaultValue: T): T;
1419
+ getFromSchema(schema: S, path: SchemaFieldPath, defaultValue: S): S;
1420
+ getFromSchema(schema: S, path: SchemaFieldPath, defaultValue: T | S): S | T;
1409
1421
  /** Checks to see if the `schema` and `uiSchema` combination represents an array of files
1410
1422
  *
1411
1423
  * @param schema - The schema for which check for array of files flag is desired
@@ -1463,6 +1475,7 @@ export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchem
1463
1475
  * @param [name] - The base name for the schema
1464
1476
  * @param [formData] - The current formData, if any, onto which to provide any missing defaults
1465
1477
  * @returns - The `PathSchema` object for the `schema`
1478
+ * @deprecated - To be removed as an exported `@rjsf/utils` function in a future release
1466
1479
  */
1467
1480
  toPathSchema(schema: S, name?: string, formData?: T): PathSchema<T>;
1468
1481
  }
@@ -20,7 +20,7 @@ export interface UseFileWidgetPropsResult {
20
20
  /** The list of FileInfoType contained within the FileWidget */
21
21
  filesInfo: FileInfoType[];
22
22
  /** The callback handler to pass to the onChange of the input */
23
- handleChange: (files: FileList) => void;
23
+ handleChange: (files: FileList) => void | Promise<void>;
24
24
  /** The callback handler to pass in order to delete a file */
25
25
  handleRemove: (index: number) => void;
26
26
  }
@@ -129,15 +129,14 @@ export default function useFileWidgetProps(
129
129
  );
130
130
 
131
131
  const handleChange = useCallback(
132
- (files: FileList) => {
133
- processFiles(files).then((filesInfoEvent) => {
134
- const newValue = filesInfoEvent.map((fileInfo) => fileInfo.dataURL || null);
135
- if (multiple) {
136
- onChange(values.concat(...newValue));
137
- } else {
138
- onChange(newValue[0]);
139
- }
140
- });
132
+ async (files: FileList) => {
133
+ const filesInfoEvent = await processFiles(files);
134
+ const newValue = filesInfoEvent.map((fileInfo) => fileInfo.dataURL || null);
135
+ if (multiple) {
136
+ onChange(values.concat(...newValue));
137
+ } else {
138
+ onChange(newValue[0]);
139
+ }
141
140
  },
142
141
  [values, multiple, onChange],
143
142
  );
@@ -1,6 +1,7 @@
1
+ import isObject from 'lodash/isObject';
2
+
1
3
  import { REF_KEY, ROOT_SCHEMA_PREFIX } from './constants';
2
4
  import { RJSFSchema, StrictRJSFSchema } from './types';
3
- import isObject from 'lodash/isObject';
4
5
 
5
6
  /** Takes a `node` object and transforms any contained `$ref` node variables with a prefix, recursively calling
6
7
  * `withIdRefPrefix` for any other elements.