@rjsf/utils 6.0.0-alpha.0 → 6.0.0-beta.10

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 (279) hide show
  1. package/dist/index.js +1347 -642
  2. package/dist/index.js.map +4 -4
  3. package/dist/utils.esm.js +1324 -619
  4. package/dist/utils.esm.js.map +4 -4
  5. package/dist/utils.umd.js +1266 -590
  6. package/lib/ErrorSchemaBuilder.d.ts +8 -4
  7. package/lib/ErrorSchemaBuilder.js +10 -8
  8. package/lib/ErrorSchemaBuilder.js.map +1 -1
  9. package/lib/allowAdditionalItems.d.ts +1 -1
  10. package/lib/allowAdditionalItems.js +1 -1
  11. package/lib/allowAdditionalItems.js.map +1 -1
  12. package/lib/asNumber.js.map +1 -1
  13. package/lib/canExpand.d.ts +2 -2
  14. package/lib/canExpand.js +2 -2
  15. package/lib/canExpand.js.map +1 -1
  16. package/lib/constIsAjvDataReference.d.ts +9 -0
  17. package/lib/constIsAjvDataReference.js +15 -0
  18. package/lib/constIsAjvDataReference.js.map +1 -0
  19. package/lib/constants.d.ts +15 -3
  20. package/lib/constants.js +15 -3
  21. package/lib/constants.js.map +1 -1
  22. package/lib/createErrorHandler.d.ts +1 -1
  23. package/lib/createErrorHandler.js +2 -2
  24. package/lib/createErrorHandler.js.map +1 -1
  25. package/lib/createSchemaUtils.d.ts +3 -2
  26. package/lib/createSchemaUtils.js +56 -46
  27. package/lib/createSchemaUtils.js.map +1 -1
  28. package/lib/dataURItoBlob.js.map +1 -1
  29. package/lib/dateRangeOptions.d.ts +1 -1
  30. package/lib/dateRangeOptions.js +1 -1
  31. package/lib/dateRangeOptions.js.map +1 -1
  32. package/lib/deepEquals.js +1 -1
  33. package/lib/deepEquals.js.map +1 -1
  34. package/lib/englishStringTranslator.d.ts +1 -1
  35. package/lib/englishStringTranslator.js +1 -1
  36. package/lib/enumOptionsDeselectValue.d.ts +1 -1
  37. package/lib/enumOptionsDeselectValue.js +4 -4
  38. package/lib/enumOptionsDeselectValue.js.map +1 -1
  39. package/lib/enumOptionsIndexForValue.d.ts +1 -1
  40. package/lib/enumOptionsIndexForValue.js +1 -1
  41. package/lib/enumOptionsIndexForValue.js.map +1 -1
  42. package/lib/enumOptionsIsSelected.d.ts +1 -1
  43. package/lib/enumOptionsIsSelected.js +3 -3
  44. package/lib/enumOptionsIsSelected.js.map +1 -1
  45. package/lib/enumOptionsSelectValue.d.ts +1 -1
  46. package/lib/enumOptionsSelectValue.js +2 -2
  47. package/lib/enumOptionsSelectValue.js.map +1 -1
  48. package/lib/enumOptionsValueForIndex.d.ts +1 -1
  49. package/lib/enumOptionsValueForIndex.js.map +1 -1
  50. package/lib/enums.d.ts +2 -0
  51. package/lib/enums.js +2 -0
  52. package/lib/enums.js.map +1 -1
  53. package/lib/findSchemaDefinition.d.ts +5 -3
  54. package/lib/findSchemaDefinition.js +54 -11
  55. package/lib/findSchemaDefinition.js.map +1 -1
  56. package/lib/getChangedFields.d.ts +17 -0
  57. package/lib/getChangedFields.js +42 -0
  58. package/lib/getChangedFields.js.map +1 -0
  59. package/lib/getDateElementProps.d.ts +1 -1
  60. package/lib/getDateElementProps.js.map +1 -1
  61. package/lib/getDiscriminatorFieldFromSchema.d.ts +1 -1
  62. package/lib/getDiscriminatorFieldFromSchema.js +4 -3
  63. package/lib/getDiscriminatorFieldFromSchema.js.map +1 -1
  64. package/lib/getInputProps.d.ts +1 -1
  65. package/lib/getInputProps.js +4 -1
  66. package/lib/getInputProps.js.map +1 -1
  67. package/lib/getOptionMatchingSimpleDiscriminator.d.ts +1 -1
  68. package/lib/getOptionMatchingSimpleDiscriminator.js +2 -2
  69. package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -1
  70. package/lib/getSchemaType.d.ts +2 -1
  71. package/lib/getSchemaType.js +3 -2
  72. package/lib/getSchemaType.js.map +1 -1
  73. package/lib/getSubmitButtonOptions.d.ts +1 -1
  74. package/lib/getSubmitButtonOptions.js +2 -2
  75. package/lib/getSubmitButtonOptions.js.map +1 -1
  76. package/lib/getTemplate.d.ts +1 -1
  77. package/lib/getTemplate.js +9 -0
  78. package/lib/getTemplate.js.map +1 -1
  79. package/lib/getTestIds.d.ts +17 -0
  80. package/lib/getTestIds.js +34 -0
  81. package/lib/getTestIds.js.map +1 -0
  82. package/lib/getUiOptions.d.ts +1 -1
  83. package/lib/getUiOptions.js +2 -2
  84. package/lib/getUiOptions.js.map +1 -1
  85. package/lib/getWidget.d.ts +1 -1
  86. package/lib/getWidget.js +3 -3
  87. package/lib/getWidget.js.map +1 -1
  88. package/lib/guessType.d.ts +1 -1
  89. package/lib/guessType.js.map +1 -1
  90. package/lib/hasWidget.d.ts +1 -1
  91. package/lib/hasWidget.js +1 -1
  92. package/lib/hasWidget.js.map +1 -1
  93. package/lib/hashForSchema.d.ts +23 -1
  94. package/lib/hashForSchema.js +24 -6
  95. package/lib/hashForSchema.js.map +1 -1
  96. package/lib/idGenerators.d.ts +8 -1
  97. package/lib/idGenerators.js +11 -2
  98. package/lib/idGenerators.js.map +1 -1
  99. package/lib/index.d.ts +63 -60
  100. package/lib/index.js +63 -60
  101. package/lib/index.js.map +1 -1
  102. package/lib/isConstant.d.ts +1 -1
  103. package/lib/isConstant.js +1 -1
  104. package/lib/isCustomWidget.d.ts +1 -1
  105. package/lib/isCustomWidget.js +1 -1
  106. package/lib/isFixedItems.d.ts +1 -1
  107. package/lib/isFixedItems.js +1 -1
  108. package/lib/isObject.d.ts +2 -2
  109. package/lib/isObject.js +11 -4
  110. package/lib/isObject.js.map +1 -1
  111. package/lib/lookupFromFormContext.d.ts +11 -0
  112. package/lib/lookupFromFormContext.js +20 -0
  113. package/lib/lookupFromFormContext.js.map +1 -0
  114. package/lib/mergeDefaultsWithFormData.d.ts +8 -2
  115. package/lib/mergeDefaultsWithFormData.js +39 -10
  116. package/lib/mergeDefaultsWithFormData.js.map +1 -1
  117. package/lib/mergeObjects.d.ts +1 -1
  118. package/lib/mergeObjects.js +1 -1
  119. package/lib/mergeObjects.js.map +1 -1
  120. package/lib/mergeSchemas.d.ts +1 -1
  121. package/lib/mergeSchemas.js +4 -4
  122. package/lib/mergeSchemas.js.map +1 -1
  123. package/lib/optionsList.d.ts +9 -7
  124. package/lib/optionsList.js +30 -19
  125. package/lib/optionsList.js.map +1 -1
  126. package/lib/orderProperties.js.map +1 -1
  127. package/lib/pad.js.map +1 -1
  128. package/lib/parseDateString.d.ts +1 -1
  129. package/lib/parseDateString.js +1 -1
  130. package/lib/parseDateString.js.map +1 -1
  131. package/lib/parser/ParserValidator.d.ts +1 -1
  132. package/lib/parser/ParserValidator.js +6 -6
  133. package/lib/parser/ParserValidator.js.map +1 -1
  134. package/lib/parser/index.d.ts +2 -2
  135. package/lib/parser/index.js +1 -1
  136. package/lib/parser/schemaParser.d.ts +2 -2
  137. package/lib/parser/schemaParser.js +6 -6
  138. package/lib/parser/schemaParser.js.map +1 -1
  139. package/lib/rangeSpec.d.ts +2 -2
  140. package/lib/rangeSpec.js.map +1 -1
  141. package/lib/replaceStringParameters.js.map +1 -1
  142. package/lib/schema/findFieldInSchema.d.ts +19 -0
  143. package/lib/schema/findFieldInSchema.js +61 -0
  144. package/lib/schema/findFieldInSchema.js.map +1 -0
  145. package/lib/schema/findSelectedOptionInXxxOf.d.ts +16 -0
  146. package/lib/schema/findSelectedOptionInXxxOf.js +34 -0
  147. package/lib/schema/findSelectedOptionInXxxOf.js.map +1 -0
  148. package/lib/schema/getClosestMatchingOption.d.ts +5 -3
  149. package/lib/schema/getClosestMatchingOption.js +28 -20
  150. package/lib/schema/getClosestMatchingOption.js.map +1 -1
  151. package/lib/schema/getDefaultFormState.d.ts +60 -13
  152. package/lib/schema/getDefaultFormState.js +316 -167
  153. package/lib/schema/getDefaultFormState.js.map +1 -1
  154. package/lib/schema/getDisplayLabel.d.ts +3 -2
  155. package/lib/schema/getDisplayLabel.js +10 -9
  156. package/lib/schema/getDisplayLabel.js.map +1 -1
  157. package/lib/schema/getFirstMatchingOption.d.ts +1 -1
  158. package/lib/schema/getFirstMatchingOption.js +70 -2
  159. package/lib/schema/getFirstMatchingOption.js.map +1 -1
  160. package/lib/schema/getFromSchema.d.ts +14 -0
  161. package/lib/schema/getFromSchema.js +39 -0
  162. package/lib/schema/getFromSchema.js.map +1 -0
  163. package/lib/schema/index.d.ts +15 -14
  164. package/lib/schema/index.js +15 -14
  165. package/lib/schema/index.js.map +1 -1
  166. package/lib/schema/isFilesArray.d.ts +3 -2
  167. package/lib/schema/isFilesArray.js +5 -4
  168. package/lib/schema/isFilesArray.js.map +1 -1
  169. package/lib/schema/isMultiSelect.d.ts +3 -2
  170. package/lib/schema/isMultiSelect.js +4 -3
  171. package/lib/schema/isMultiSelect.js.map +1 -1
  172. package/lib/schema/isSelect.d.ts +3 -2
  173. package/lib/schema/isSelect.js +5 -4
  174. package/lib/schema/isSelect.js.map +1 -1
  175. package/lib/schema/retrieveSchema.d.ts +30 -12
  176. package/lib/schema/retrieveSchema.js +153 -70
  177. package/lib/schema/retrieveSchema.js.map +1 -1
  178. package/lib/schema/sanitizeDataForNewSchema.d.ts +3 -2
  179. package/lib/schema/sanitizeDataForNewSchema.js +12 -11
  180. package/lib/schema/sanitizeDataForNewSchema.js.map +1 -1
  181. package/lib/schema/toIdSchema.d.ts +3 -2
  182. package/lib/schema/toIdSchema.js +30 -27
  183. package/lib/schema/toIdSchema.js.map +1 -1
  184. package/lib/schema/toPathSchema.d.ts +3 -2
  185. package/lib/schema/toPathSchema.js +22 -20
  186. package/lib/schema/toPathSchema.js.map +1 -1
  187. package/lib/schemaRequiresTrueValue.d.ts +1 -1
  188. package/lib/schemaRequiresTrueValue.js.map +1 -1
  189. package/lib/shouldRender.js +1 -1
  190. package/lib/toConstant.d.ts +1 -1
  191. package/lib/toConstant.js +1 -1
  192. package/lib/toConstant.js.map +1 -1
  193. package/lib/toDateString.d.ts +1 -1
  194. package/lib/toErrorList.d.ts +1 -1
  195. package/lib/toErrorList.js +2 -2
  196. package/lib/toErrorList.js.map +1 -1
  197. package/lib/toErrorSchema.d.ts +1 -1
  198. package/lib/toErrorSchema.js +2 -2
  199. package/lib/toErrorSchema.js.map +1 -1
  200. package/lib/tsconfig.tsbuildinfo +1 -1
  201. package/lib/types.d.ts +172 -142
  202. package/lib/unwrapErrorHandler.d.ts +1 -1
  203. package/lib/unwrapErrorHandler.js +1 -1
  204. package/lib/unwrapErrorHandler.js.map +1 -1
  205. package/lib/utcToLocal.js +1 -1
  206. package/lib/utcToLocal.js.map +1 -1
  207. package/lib/validationDataMerge.d.ts +1 -1
  208. package/lib/validationDataMerge.js +3 -3
  209. package/lib/validationDataMerge.js.map +1 -1
  210. package/lib/withIdRefPrefix.d.ts +1 -1
  211. package/lib/withIdRefPrefix.js +2 -2
  212. package/lib/withIdRefPrefix.js.map +1 -1
  213. package/package.json +37 -26
  214. package/src/ErrorSchemaBuilder.ts +15 -8
  215. package/src/canExpand.ts +2 -2
  216. package/src/constIsAjvDataReference.ts +17 -0
  217. package/src/constants.ts +17 -3
  218. package/src/createSchemaUtils.ts +140 -50
  219. package/src/dataURItoBlob.ts +1 -1
  220. package/src/dateRangeOptions.ts +1 -1
  221. package/src/enumOptionsDeselectValue.ts +4 -5
  222. package/src/enumOptionsIndexForValue.ts +1 -1
  223. package/src/enumOptionsIsSelected.ts +4 -5
  224. package/src/enumOptionsSelectValue.ts +1 -1
  225. package/src/enumOptionsValueForIndex.ts +1 -1
  226. package/src/enums.ts +2 -0
  227. package/src/findSchemaDefinition.ts +55 -10
  228. package/src/getChangedFields.ts +40 -0
  229. package/src/getDateElementProps.ts +2 -2
  230. package/src/getDiscriminatorFieldFromSchema.ts +2 -1
  231. package/src/getInputProps.ts +6 -2
  232. package/src/getOptionMatchingSimpleDiscriminator.ts +2 -2
  233. package/src/getSchemaType.ts +3 -2
  234. package/src/getSubmitButtonOptions.ts +1 -1
  235. package/src/getTemplate.ts +12 -1
  236. package/src/getTestIds.ts +40 -0
  237. package/src/getUiOptions.ts +2 -2
  238. package/src/getWidget.tsx +2 -2
  239. package/src/hasWidget.ts +1 -1
  240. package/src/hashForSchema.ts +26 -6
  241. package/src/idGenerators.ts +10 -0
  242. package/src/index.ts +21 -2
  243. package/src/isCustomWidget.ts +1 -1
  244. package/src/isObject.ts +12 -5
  245. package/src/labelValue.ts +2 -2
  246. package/src/lookupFromFormContext.ts +26 -0
  247. package/src/mergeDefaultsWithFormData.ts +54 -9
  248. package/src/mergeObjects.ts +24 -21
  249. package/src/optionsList.ts +31 -22
  250. package/src/parser/ParserValidator.ts +5 -5
  251. package/src/parser/schemaParser.ts +6 -6
  252. package/src/schema/findFieldInSchema.ts +138 -0
  253. package/src/schema/findSelectedOptionInXxxOf.ts +53 -0
  254. package/src/schema/getClosestMatchingOption.ts +38 -11
  255. package/src/schema/getDefaultFormState.ts +461 -193
  256. package/src/schema/getDisplayLabel.ts +7 -4
  257. package/src/schema/getFirstMatchingOption.ts +79 -4
  258. package/src/schema/getFromSchema.ts +100 -0
  259. package/src/schema/index.ts +6 -4
  260. package/src/schema/isFilesArray.ts +18 -3
  261. package/src/schema/isMultiSelect.ts +10 -4
  262. package/src/schema/isSelect.ts +5 -3
  263. package/src/schema/retrieveSchema.ts +268 -78
  264. package/src/schema/sanitizeDataForNewSchema.ts +52 -11
  265. package/src/schema/toIdSchema.ts +69 -43
  266. package/src/schema/toPathSchema.ts +49 -16
  267. package/src/toErrorList.ts +2 -2
  268. package/src/types.ts +278 -184
  269. package/src/validationDataMerge.ts +1 -1
  270. package/src/withIdRefPrefix.ts +1 -1
  271. package/LICENSE.md +0 -201
  272. package/lib/schema/getMatchingOption.d.ts +0 -14
  273. package/lib/schema/getMatchingOption.js +0 -85
  274. package/lib/schema/getMatchingOption.js.map +0 -1
  275. package/lib/schema/mergeValidationData.d.ts +0 -14
  276. package/lib/schema/mergeValidationData.js +0 -28
  277. package/lib/schema/mergeValidationData.js.map +0 -1
  278. package/src/schema/getMatchingOption.ts +0 -103
  279. package/src/schema/mergeValidationData.ts +0 -38
@@ -9,6 +9,7 @@ import {
9
9
  StrictRJSFSchema,
10
10
  UiSchema,
11
11
  ValidatorType,
12
+ Experimental_CustomMergeAllOf,
12
13
  } from '../types';
13
14
  import isFilesArray from './isFilesArray';
14
15
  import isMultiSelect from './isMultiSelect';
@@ -21,18 +22,20 @@ import isMultiSelect from './isMultiSelect';
21
22
  * @param [uiSchema={}] - The UI schema from which to derive potentially displayable information
22
23
  * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
23
24
  * @param [globalOptions={}] - The optional Global UI Schema from which to get any fallback `xxx` options
25
+ * @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
24
26
  * @returns - True if the label should be displayed or false if it should not
25
27
  */
26
28
  export default function getDisplayLabel<
27
29
  T = any,
28
30
  S extends StrictRJSFSchema = RJSFSchema,
29
- F extends FormContextType = any
31
+ F extends FormContextType = any,
30
32
  >(
31
33
  validator: ValidatorType<T, S, F>,
32
34
  schema: S,
33
35
  uiSchema: UiSchema<T, S, F> = {},
34
36
  rootSchema?: S,
35
- globalOptions?: GlobalUISchemaOptions
37
+ globalOptions?: GlobalUISchemaOptions,
38
+ experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
36
39
  ): boolean {
37
40
  const uiOptions = getUiOptions<T, S, F>(uiSchema, globalOptions);
38
41
  const { label = true } = uiOptions;
@@ -41,8 +44,8 @@ export default function getDisplayLabel<
41
44
 
42
45
  if (schemaType === 'array') {
43
46
  displayLabel =
44
- isMultiSelect<T, S, F>(validator, schema, rootSchema) ||
45
- isFilesArray<T, S, F>(validator, schema, uiSchema, rootSchema) ||
47
+ isMultiSelect<T, S, F>(validator, schema, rootSchema, experimental_customMergeAllOf) ||
48
+ isFilesArray<T, S, F>(validator, schema, uiSchema, rootSchema, experimental_customMergeAllOf) ||
46
49
  isCustomWidget(uiSchema);
47
50
  }
48
51
 
@@ -1,4 +1,9 @@
1
- import getMatchingOption from './getMatchingOption';
1
+ import get from 'lodash/get';
2
+ import has from 'lodash/has';
3
+ import isNumber from 'lodash/isNumber';
4
+
5
+ import { PROPERTIES_KEY } from '../constants';
6
+ import getOptionMatchingSimpleDiscriminator from '../getOptionMatchingSimpleDiscriminator';
2
7
  import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
3
8
 
4
9
  /** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
@@ -15,13 +20,83 @@ import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '..
15
20
  export default function getFirstMatchingOption<
16
21
  T = any,
17
22
  S extends StrictRJSFSchema = RJSFSchema,
18
- F extends FormContextType = any
23
+ F extends FormContextType = any,
19
24
  >(
20
25
  validator: ValidatorType<T, S, F>,
21
26
  formData: T | undefined,
22
27
  options: S[],
23
28
  rootSchema: S,
24
- discriminatorField?: string
29
+ discriminatorField?: string,
25
30
  ): number {
26
- return getMatchingOption<T, S, F>(validator, formData, options, rootSchema, discriminatorField);
31
+ // For performance, skip validating subschemas if formData is undefined. We just
32
+ // want to get the first option in that case.
33
+ if (formData === undefined) {
34
+ return 0;
35
+ }
36
+
37
+ const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField);
38
+ if (isNumber(simpleDiscriminatorMatch)) {
39
+ return simpleDiscriminatorMatch;
40
+ }
41
+
42
+ for (let i = 0; i < options.length; i++) {
43
+ const option = options[i];
44
+
45
+ // If we have a discriminator field, then we will use this to make the determination
46
+ if (discriminatorField && has(option, [PROPERTIES_KEY, discriminatorField])) {
47
+ const value = get(formData, discriminatorField);
48
+ const discriminator: S = get(option, [PROPERTIES_KEY, discriminatorField], {}) as S;
49
+ if (validator.isValid(discriminator, value, rootSchema)) {
50
+ return i;
51
+ }
52
+ } else if (option[PROPERTIES_KEY]) {
53
+ // If the schema describes an object then we need to add slightly more
54
+ // strict matching to the schema, because unless the schema uses the
55
+ // "requires" keyword, an object will match the schema as long as it
56
+ // doesn't have matching keys with a conflicting type. To do this we use an
57
+ // "anyOf" with an array of requires. This augmentation expresses that the
58
+ // schema should match if any of the keys in the schema are present on the
59
+ // object and pass validation.
60
+ //
61
+ // Create an "anyOf" schema that requires at least one of the keys in the
62
+ // "properties" object
63
+ const requiresAnyOf = {
64
+ anyOf: Object.keys(option[PROPERTIES_KEY]).map((key) => ({
65
+ required: [key],
66
+ })),
67
+ };
68
+
69
+ let augmentedSchema;
70
+
71
+ // If the "anyOf" keyword already exists, wrap the augmentation in an "allOf"
72
+ if (option.anyOf) {
73
+ // Create a shallow clone of the option
74
+ const { ...shallowClone } = option;
75
+
76
+ if (!shallowClone.allOf) {
77
+ shallowClone.allOf = [];
78
+ } else {
79
+ // If "allOf" already exists, shallow clone the array
80
+ shallowClone.allOf = shallowClone.allOf.slice();
81
+ }
82
+
83
+ shallowClone.allOf.push(requiresAnyOf);
84
+
85
+ augmentedSchema = shallowClone;
86
+ } else {
87
+ augmentedSchema = Object.assign({}, option, requiresAnyOf);
88
+ }
89
+
90
+ // Remove the "required" field as it's likely that not all fields have
91
+ // been filled in yet, which will mean that the schema is not valid
92
+ delete augmentedSchema.required;
93
+
94
+ if (validator.isValid(augmentedSchema, formData, rootSchema)) {
95
+ return i;
96
+ }
97
+ } else if (validator.isValid(option, formData, rootSchema)) {
98
+ return i;
99
+ }
100
+ }
101
+ return 0;
27
102
  }
@@ -0,0 +1,100 @@
1
+ import get from 'lodash/get';
2
+ import has from 'lodash/has';
3
+ import isEmpty from 'lodash/isEmpty';
4
+
5
+ import retrieveSchema from './retrieveSchema';
6
+ import { Experimental_CustomMergeAllOf, FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
7
+ import { REF_KEY } from '../constants';
8
+
9
+ /** Internal helper function that acts like lodash's `get` but additionally retrieves `$ref`s as needed to get the path
10
+ * for schemas containing potentially nested `$ref`s.
11
+ *
12
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
13
+ * @param rootSchema - The root schema that will be forwarded to all the APIs
14
+ * @param schema - The current node within the JSON schema recursion
15
+ * @param path - The remaining keys in the path to the desired property
16
+ * @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
17
+ * @returns - The internal schema from the `schema` for the given `path` or undefined if not found
18
+ */
19
+ function getFromSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
20
+ validator: ValidatorType<T, S, F>,
21
+ rootSchema: S,
22
+ schema: S,
23
+ path: string | string[],
24
+ experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
25
+ ): T | S | undefined {
26
+ let fieldSchema = schema;
27
+ if (has(schema, REF_KEY)) {
28
+ fieldSchema = retrieveSchema<T, S, F>(validator, schema, rootSchema, undefined, experimental_customMergeAllOf);
29
+ }
30
+ if (isEmpty(path)) {
31
+ return fieldSchema;
32
+ }
33
+ const pathList = Array.isArray(path) ? path : path.split('.');
34
+ const [part, ...nestedPath] = pathList;
35
+ if (part && has(fieldSchema, part)) {
36
+ fieldSchema = get(fieldSchema, part) as S;
37
+ return getFromSchemaInternal<T, S, F>(
38
+ validator,
39
+ rootSchema,
40
+ fieldSchema,
41
+ nestedPath,
42
+ experimental_customMergeAllOf,
43
+ );
44
+ }
45
+ return undefined;
46
+ }
47
+
48
+ /** Helper that acts like lodash's `get` but additionally retrieves `$ref`s as needed to get the path for schemas
49
+ * containing potentially nested `$ref`s.
50
+ *
51
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
52
+ * @param rootSchema - The root schema that will be forwarded to all the APIs
53
+ * @param schema - The current node within the JSON schema recursion
54
+ * @param path - The keys in the path to the desired field
55
+ * @param defaultValue - The value to return if a value is not found for the `pathList` path
56
+ * @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
57
+ * @returns - The inner schema from the `schema` for the given `path` or the `defaultValue` if not found
58
+ */
59
+ export default function getFromSchema<
60
+ T = any,
61
+ S extends StrictRJSFSchema = RJSFSchema,
62
+ F extends FormContextType = any,
63
+ >(
64
+ validator: ValidatorType<T, S, F>,
65
+ rootSchema: S,
66
+ schema: S,
67
+ path: string | string[],
68
+ defaultValue: T,
69
+ experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
70
+ ): T;
71
+ export default function getFromSchema<
72
+ T = any,
73
+ S extends StrictRJSFSchema = RJSFSchema,
74
+ F extends FormContextType = any,
75
+ >(
76
+ validator: ValidatorType<T, S, F>,
77
+ rootSchema: S,
78
+ schema: S,
79
+ path: string | string[],
80
+ defaultValue: S,
81
+ experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
82
+ ): S;
83
+ export default function getFromSchema<
84
+ T = any,
85
+ S extends StrictRJSFSchema = RJSFSchema,
86
+ F extends FormContextType = any,
87
+ >(
88
+ validator: ValidatorType<T, S, F>,
89
+ rootSchema: S,
90
+ schema: S,
91
+ path: string | string[],
92
+ defaultValue: T | S,
93
+ experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
94
+ ): T | S {
95
+ const result = getFromSchemaInternal(validator, rootSchema, schema, path, experimental_customMergeAllOf);
96
+ if (result === undefined) {
97
+ return defaultValue;
98
+ }
99
+ return result;
100
+ }
@@ -1,27 +1,29 @@
1
+ import findFieldInSchema from './findFieldInSchema';
2
+ import findSelectedOptionInXxxOf from './findSelectedOptionInXxxOf';
1
3
  import getDefaultFormState from './getDefaultFormState';
2
4
  import getDisplayLabel from './getDisplayLabel';
3
5
  import getClosestMatchingOption from './getClosestMatchingOption';
4
6
  import getFirstMatchingOption from './getFirstMatchingOption';
5
- import getMatchingOption from './getMatchingOption';
7
+ import getFromSchema from './getFromSchema';
6
8
  import isFilesArray from './isFilesArray';
7
9
  import isMultiSelect from './isMultiSelect';
8
10
  import isSelect from './isSelect';
9
- import mergeValidationData from './mergeValidationData';
10
11
  import retrieveSchema from './retrieveSchema';
11
12
  import sanitizeDataForNewSchema from './sanitizeDataForNewSchema';
12
13
  import toIdSchema from './toIdSchema';
13
14
  import toPathSchema from './toPathSchema';
14
15
 
15
16
  export {
17
+ findFieldInSchema,
18
+ findSelectedOptionInXxxOf,
16
19
  getDefaultFormState,
17
20
  getDisplayLabel,
18
21
  getClosestMatchingOption,
19
22
  getFirstMatchingOption,
20
- getMatchingOption,
23
+ getFromSchema,
21
24
  isFilesArray,
22
25
  isMultiSelect,
23
26
  isSelect,
24
- mergeValidationData,
25
27
  retrieveSchema,
26
28
  sanitizeDataForNewSchema,
27
29
  toIdSchema,
@@ -1,5 +1,12 @@
1
1
  import { UI_WIDGET_KEY } from '../constants';
2
- import { FormContextType, RJSFSchema, StrictRJSFSchema, UiSchema, ValidatorType } from '../types';
2
+ import {
3
+ Experimental_CustomMergeAllOf,
4
+ FormContextType,
5
+ RJSFSchema,
6
+ StrictRJSFSchema,
7
+ UiSchema,
8
+ ValidatorType,
9
+ } from '../types';
3
10
  import retrieveSchema from './retrieveSchema';
4
11
 
5
12
  /** Checks to see if the `schema` and `uiSchema` combination represents an array of files
@@ -8,19 +15,27 @@ import retrieveSchema from './retrieveSchema';
8
15
  * @param schema - The schema for which check for array of files flag is desired
9
16
  * @param [uiSchema={}] - The UI schema from which to check the widget
10
17
  * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
18
+ * @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
11
19
  * @returns - True if schema/uiSchema contains an array of files, otherwise false
12
20
  */
13
21
  export default function isFilesArray<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
14
22
  validator: ValidatorType<T, S, F>,
15
23
  schema: S,
16
24
  uiSchema: UiSchema<T, S, F> = {},
17
- rootSchema?: S
25
+ rootSchema?: S,
26
+ experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
18
27
  ) {
19
28
  if (uiSchema[UI_WIDGET_KEY] === 'files') {
20
29
  return true;
21
30
  }
22
31
  if (schema.items) {
23
- const itemsSchema = retrieveSchema<T, S, F>(validator, schema.items as S, rootSchema);
32
+ const itemsSchema = retrieveSchema<T, S, F>(
33
+ validator,
34
+ schema.items as S,
35
+ rootSchema,
36
+ undefined,
37
+ experimental_customMergeAllOf,
38
+ );
24
39
  return itemsSchema.type === 'string' && itemsSchema.format === 'data-url';
25
40
  }
26
41
  return false;
@@ -1,4 +1,4 @@
1
- import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
1
+ import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType, Experimental_CustomMergeAllOf } from '../types';
2
2
 
3
3
  import isSelect from './isSelect';
4
4
 
@@ -7,15 +7,21 @@ import isSelect from './isSelect';
7
7
  * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
8
8
  * @param schema - The schema for which check for a multi-select flag is desired
9
9
  * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
10
+ * @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
10
11
  * @returns - True if schema contains a multi-select, otherwise false
11
12
  */
12
13
  export default function isMultiSelect<
13
14
  T = any,
14
15
  S extends StrictRJSFSchema = RJSFSchema,
15
- F extends FormContextType = any
16
- >(validator: ValidatorType<T, S, F>, schema: S, rootSchema?: S) {
16
+ F extends FormContextType = any,
17
+ >(
18
+ validator: ValidatorType<T, S, F>,
19
+ schema: S,
20
+ rootSchema?: S,
21
+ experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
22
+ ) {
17
23
  if (!schema.uniqueItems || !schema.items || typeof schema.items === 'boolean') {
18
24
  return false;
19
25
  }
20
- return isSelect<T, S, F>(validator, schema.items as S, rootSchema);
26
+ return isSelect<T, S, F>(validator, schema.items as S, rootSchema, experimental_customMergeAllOf);
21
27
  }
@@ -1,5 +1,5 @@
1
1
  import isConstant from '../isConstant';
2
- import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
2
+ import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType, Experimental_CustomMergeAllOf } from '../types';
3
3
  import retrieveSchema from './retrieveSchema';
4
4
 
5
5
  /** Checks to see if the `schema` combination represents a select
@@ -7,14 +7,16 @@ import retrieveSchema from './retrieveSchema';
7
7
  * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
8
8
  * @param theSchema - The schema for which check for a select flag is desired
9
9
  * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
10
+ * @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
10
11
  * @returns - True if schema contains a select, otherwise false
11
12
  */
12
13
  export default function isSelect<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
13
14
  validator: ValidatorType<T, S, F>,
14
15
  theSchema: S,
15
- rootSchema: S = {} as S
16
+ rootSchema: S = {} as S,
17
+ experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
16
18
  ) {
17
- const schema = retrieveSchema<T, S, F>(validator, theSchema, rootSchema, undefined);
19
+ const schema = retrieveSchema<T, S, F>(validator, theSchema, rootSchema, undefined, experimental_customMergeAllOf);
18
20
  const altSchemas = schema.oneOf || schema.anyOf;
19
21
  if (Array.isArray(schema.enum)) {
20
22
  return true;