@rjsf/utils 5.11.2 → 5.12.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 (303) hide show
  1. package/dist/index.js +2544 -5
  2. package/dist/index.js.map +7 -0
  3. package/dist/utils.esm.js +1228 -2113
  4. package/dist/utils.esm.js.map +7 -1
  5. package/dist/utils.umd.js +2414 -0
  6. package/lib/ErrorSchemaBuilder.d.ts +60 -0
  7. package/lib/ErrorSchemaBuilder.js +103 -0
  8. package/lib/ErrorSchemaBuilder.js.map +1 -0
  9. package/lib/allowAdditionalItems.d.ts +8 -0
  10. package/lib/allowAdditionalItems.js +14 -0
  11. package/lib/allowAdditionalItems.js.map +1 -0
  12. package/lib/asNumber.d.ts +10 -0
  13. package/lib/asNumber.js +36 -0
  14. package/lib/asNumber.js.map +1 -0
  15. package/lib/canExpand.d.ts +11 -0
  16. package/lib/canExpand.js +26 -0
  17. package/lib/canExpand.js.map +1 -0
  18. package/lib/constants.d.ts +31 -0
  19. package/lib/constants.js +32 -0
  20. package/lib/constants.js.map +1 -0
  21. package/lib/createErrorHandler.d.ts +7 -0
  22. package/lib/createErrorHandler.js +31 -0
  23. package/lib/createErrorHandler.js.map +1 -0
  24. package/lib/createSchemaUtils.d.ts +10 -0
  25. package/lib/createSchemaUtils.js +207 -0
  26. package/lib/createSchemaUtils.js.map +1 -0
  27. package/lib/dataURItoBlob.d.ts +16 -0
  28. package/lib/dataURItoBlob.js +43 -0
  29. package/lib/dataURItoBlob.js.map +1 -0
  30. package/lib/deepEquals.d.ts +8 -0
  31. package/lib/deepEquals.js +19 -0
  32. package/lib/deepEquals.js.map +1 -0
  33. package/lib/englishStringTranslator.d.ts +10 -0
  34. package/lib/englishStringTranslator.js +13 -0
  35. package/lib/englishStringTranslator.js.map +1 -0
  36. package/lib/enumOptionsDeselectValue.d.ts +14 -0
  37. package/lib/enumOptionsDeselectValue.js +22 -0
  38. package/lib/enumOptionsDeselectValue.js.map +1 -0
  39. package/lib/enumOptionsIndexForValue.d.ts +13 -0
  40. package/lib/enumOptionsIndexForValue.js +22 -0
  41. package/lib/enumOptionsIndexForValue.js.map +1 -0
  42. package/lib/enumOptionsIsSelected.d.ts +8 -0
  43. package/lib/enumOptionsIsSelected.js +14 -0
  44. package/lib/enumOptionsIsSelected.js.map +1 -0
  45. package/lib/enumOptionsSelectValue.d.ts +10 -0
  46. package/lib/enumOptionsSelectValue.js +23 -0
  47. package/lib/enumOptionsSelectValue.js.map +1 -0
  48. package/lib/enumOptionsValueForIndex.d.ts +13 -0
  49. package/lib/enumOptionsValueForIndex.js +21 -0
  50. package/lib/enumOptionsValueForIndex.js.map +1 -0
  51. package/lib/enums.d.ts +72 -0
  52. package/lib/enums.js +76 -0
  53. package/lib/enums.js.map +1 -0
  54. package/lib/findSchemaDefinition.d.ts +20 -0
  55. package/lib/findSchemaDefinition.js +49 -0
  56. package/lib/findSchemaDefinition.js.map +1 -0
  57. package/lib/getDiscriminatorFieldFromSchema.d.ts +8 -0
  58. package/lib/getDiscriminatorFieldFromSchema.js +20 -0
  59. package/lib/getDiscriminatorFieldFromSchema.js.map +1 -0
  60. package/lib/getInputProps.d.ts +10 -0
  61. package/lib/getInputProps.js +41 -0
  62. package/lib/getInputProps.js.map +1 -0
  63. package/lib/getSchemaType.d.ts +13 -0
  64. package/lib/getSchemaType.js +29 -0
  65. package/lib/getSchemaType.js.map +1 -0
  66. package/lib/getSubmitButtonOptions.d.ts +10 -0
  67. package/lib/getSubmitButtonOptions.js +25 -0
  68. package/lib/getSubmitButtonOptions.js.map +1 -0
  69. package/lib/getTemplate.d.ts +10 -0
  70. package/lib/getTemplate.js +19 -0
  71. package/lib/getTemplate.js.map +1 -0
  72. package/lib/getUiOptions.d.ts +9 -0
  73. package/lib/getUiOptions.js +25 -0
  74. package/lib/getUiOptions.js.map +1 -0
  75. package/lib/getWidget.d.ts +13 -0
  76. package/lib/getWidget.js +118 -0
  77. package/lib/getWidget.js.map +1 -0
  78. package/lib/guessType.d.ts +7 -0
  79. package/lib/guessType.js +29 -0
  80. package/lib/guessType.js.map +1 -0
  81. package/lib/hasWidget.d.ts +10 -0
  82. package/lib/hasWidget.js +23 -0
  83. package/lib/hasWidget.js.map +1 -0
  84. package/lib/hashForSchema.d.ts +8 -0
  85. package/lib/hashForSchema.js +29 -0
  86. package/lib/hashForSchema.js.map +1 -0
  87. package/lib/idGenerators.d.ts +47 -0
  88. package/lib/idGenerators.js +73 -0
  89. package/lib/idGenerators.js.map +1 -0
  90. package/lib/index.d.ts +57 -0
  91. package/lib/index.js +58 -0
  92. package/lib/index.js.map +1 -0
  93. package/lib/isConstant.d.ts +8 -0
  94. package/lib/isConstant.js +11 -0
  95. package/lib/isConstant.js.map +1 -0
  96. package/lib/isCustomWidget.d.ts +7 -0
  97. package/lib/isCustomWidget.js +13 -0
  98. package/lib/isCustomWidget.js.map +1 -0
  99. package/lib/isFixedItems.d.ts +8 -0
  100. package/lib/isFixedItems.js +11 -0
  101. package/lib/isFixedItems.js.map +1 -0
  102. package/lib/isObject.d.ts +7 -0
  103. package/lib/isObject.js +16 -0
  104. package/lib/isObject.js.map +1 -0
  105. package/lib/labelValue.d.ts +13 -0
  106. package/lib/labelValue.js +4 -0
  107. package/lib/labelValue.js.map +1 -0
  108. package/lib/localToUTC.d.ts +6 -0
  109. package/lib/localToUTC.js +9 -0
  110. package/lib/localToUTC.js.map +1 -0
  111. package/lib/mergeDefaultsWithFormData.d.ts +17 -0
  112. package/lib/mergeDefaultsWithFormData.js +43 -0
  113. package/lib/mergeDefaultsWithFormData.js.map +1 -0
  114. package/lib/mergeObjects.d.ts +11 -0
  115. package/lib/mergeObjects.js +35 -0
  116. package/lib/mergeObjects.js.map +1 -0
  117. package/lib/mergeSchemas.d.ts +10 -0
  118. package/lib/mergeSchemas.js +35 -0
  119. package/lib/mergeSchemas.js.map +1 -0
  120. package/lib/optionsList.d.ts +10 -0
  121. package/lib/optionsList.js +36 -0
  122. package/lib/optionsList.js.map +1 -0
  123. package/lib/orderProperties.d.ts +11 -0
  124. package/lib/orderProperties.js +38 -0
  125. package/lib/orderProperties.js.map +1 -0
  126. package/lib/pad.d.ts +7 -0
  127. package/lib/pad.js +14 -0
  128. package/lib/pad.js.map +1 -0
  129. package/lib/parseDateString.d.ts +9 -0
  130. package/lib/parseDateString.js +32 -0
  131. package/lib/parseDateString.js.map +1 -0
  132. package/lib/parser/ParserValidator.d.ts +70 -0
  133. package/lib/parser/ParserValidator.js +93 -0
  134. package/lib/parser/ParserValidator.js.map +1 -0
  135. package/lib/parser/index.d.ts +4 -0
  136. package/lib/parser/index.js +3 -0
  137. package/lib/parser/index.js.map +1 -0
  138. package/lib/parser/schemaParser.d.ts +9 -0
  139. package/lib/parser/schemaParser.js +48 -0
  140. package/lib/parser/schemaParser.js.map +1 -0
  141. package/lib/rangeSpec.d.ts +9 -0
  142. package/lib/rangeSpec.js +20 -0
  143. package/lib/rangeSpec.js.map +1 -0
  144. package/lib/replaceStringParameters.d.ts +9 -0
  145. package/lib/replaceStringParameters.js +23 -0
  146. package/lib/replaceStringParameters.js.map +1 -0
  147. package/lib/schema/getClosestMatchingOption.d.ts +49 -0
  148. package/lib/schema/getClosestMatchingOption.js +154 -0
  149. package/lib/schema/getClosestMatchingOption.js.map +1 -0
  150. package/lib/schema/getDefaultFormState.d.ts +66 -0
  151. package/lib/schema/getDefaultFormState.js +351 -0
  152. package/lib/schema/getDefaultFormState.js.map +1 -0
  153. package/lib/schema/getDisplayLabel.d.ts +12 -0
  154. package/lib/schema/getDisplayLabel.js +39 -0
  155. package/lib/schema/getDisplayLabel.js.map +1 -0
  156. package/lib/schema/getFirstMatchingOption.d.ts +13 -0
  157. package/lib/schema/getFirstMatchingOption.js +16 -0
  158. package/lib/schema/getFirstMatchingOption.js.map +1 -0
  159. package/lib/schema/getMatchingOption.d.ts +14 -0
  160. package/lib/schema/getMatchingOption.js +80 -0
  161. package/lib/schema/getMatchingOption.js.map +1 -0
  162. package/lib/schema/index.d.ts +14 -0
  163. package/lib/schema/index.js +15 -0
  164. package/lib/schema/index.js.map +1 -0
  165. package/lib/schema/isFilesArray.d.ts +10 -0
  166. package/lib/schema/isFilesArray.js +21 -0
  167. package/lib/schema/isFilesArray.js.map +1 -0
  168. package/lib/schema/isMultiSelect.d.ts +9 -0
  169. package/lib/schema/isMultiSelect.js +15 -0
  170. package/lib/schema/isMultiSelect.js.map +1 -0
  171. package/lib/schema/isSelect.d.ts +9 -0
  172. package/lib/schema/isSelect.js +21 -0
  173. package/lib/schema/isSelect.js.map +1 -0
  174. package/lib/schema/mergeValidationData.d.ts +14 -0
  175. package/lib/schema/mergeValidationData.js +28 -0
  176. package/lib/schema/mergeValidationData.js.map +1 -0
  177. package/lib/schema/retrieveSchema.d.ts +170 -0
  178. package/lib/schema/retrieveSchema.js +437 -0
  179. package/lib/schema/retrieveSchema.js.map +1 -0
  180. package/lib/schema/sanitizeDataForNewSchema.d.ts +49 -0
  181. package/lib/schema/sanitizeDataForNewSchema.js +173 -0
  182. package/lib/schema/sanitizeDataForNewSchema.js.map +1 -0
  183. package/lib/schema/toIdSchema.d.ts +13 -0
  184. package/lib/schema/toIdSchema.js +59 -0
  185. package/lib/schema/toIdSchema.js.map +1 -0
  186. package/lib/schema/toPathSchema.d.ts +11 -0
  187. package/lib/schema/toPathSchema.js +68 -0
  188. package/lib/schema/toPathSchema.js.map +1 -0
  189. package/lib/schemaRequiresTrueValue.d.ts +11 -0
  190. package/lib/schemaRequiresTrueValue.js +34 -0
  191. package/lib/schemaRequiresTrueValue.js.map +1 -0
  192. package/lib/shouldRender.d.ts +10 -0
  193. package/lib/shouldRender.js +14 -0
  194. package/lib/shouldRender.js.map +1 -0
  195. package/lib/toConstant.d.ts +9 -0
  196. package/lib/toConstant.js +18 -0
  197. package/lib/toConstant.js.map +1 -0
  198. package/lib/toDateString.d.ts +9 -0
  199. package/lib/toDateString.js +14 -0
  200. package/lib/toDateString.js.map +1 -0
  201. package/lib/toErrorList.d.ts +8 -0
  202. package/lib/toErrorList.js +34 -0
  203. package/lib/toErrorList.js.map +1 -0
  204. package/lib/toErrorSchema.d.ts +21 -0
  205. package/lib/toErrorSchema.js +41 -0
  206. package/lib/toErrorSchema.js.map +1 -0
  207. package/lib/types.d.ts +982 -0
  208. package/lib/types.js +2 -0
  209. package/lib/types.js.map +1 -0
  210. package/lib/unwrapErrorHandler.d.ts +7 -0
  211. package/lib/unwrapErrorHandler.js +21 -0
  212. package/lib/unwrapErrorHandler.js.map +1 -0
  213. package/lib/utcToLocal.d.ts +6 -0
  214. package/lib/utcToLocal.js +26 -0
  215. package/lib/utcToLocal.js.map +1 -0
  216. package/lib/validationDataMerge.d.ts +11 -0
  217. package/lib/validationDataMerge.js +26 -0
  218. package/lib/validationDataMerge.js.map +1 -0
  219. package/lib/withIdRefPrefix.d.ts +8 -0
  220. package/lib/withIdRefPrefix.js +47 -0
  221. package/lib/withIdRefPrefix.js.map +1 -0
  222. package/package.json +20 -13
  223. package/src/ErrorSchemaBuilder.ts +112 -0
  224. package/src/allowAdditionalItems.ts +15 -0
  225. package/src/asNumber.ts +38 -0
  226. package/src/canExpand.ts +31 -0
  227. package/src/constants.ts +31 -0
  228. package/src/createErrorHandler.ts +33 -0
  229. package/src/createSchemaUtils.ts +298 -0
  230. package/src/dataURItoBlob.ts +42 -0
  231. package/src/deepEquals.ts +19 -0
  232. package/src/englishStringTranslator.ts +14 -0
  233. package/src/enumOptionsDeselectValue.ts +28 -0
  234. package/src/enumOptionsIndexForValue.ts +27 -0
  235. package/src/enumOptionsIsSelected.ts +19 -0
  236. package/src/enumOptionsSelectValue.ts +28 -0
  237. package/src/enumOptionsValueForIndex.ts +26 -0
  238. package/src/enums.ts +74 -0
  239. package/src/findSchemaDefinition.ts +54 -0
  240. package/src/getDiscriminatorFieldFromSchema.ts +21 -0
  241. package/src/getInputProps.ts +55 -0
  242. package/src/getSchemaType.ts +37 -0
  243. package/src/getSubmitButtonOptions.ts +32 -0
  244. package/src/getTemplate.ts +26 -0
  245. package/src/getUiOptions.ts +32 -0
  246. package/src/getWidget.tsx +133 -0
  247. package/src/guessType.ts +28 -0
  248. package/src/hasWidget.ts +27 -0
  249. package/src/hashForSchema.ts +31 -0
  250. package/src/idGenerators.ts +81 -0
  251. package/src/index.ts +118 -0
  252. package/src/isConstant.ts +12 -0
  253. package/src/isCustomWidget.ts +19 -0
  254. package/src/isFixedItems.ts +12 -0
  255. package/src/isObject.ts +15 -0
  256. package/src/labelValue.ts +16 -0
  257. package/src/localToUTC.ts +8 -0
  258. package/src/mergeDefaultsWithFormData.ts +53 -0
  259. package/src/mergeObjects.ts +39 -0
  260. package/src/mergeSchemas.ts +38 -0
  261. package/src/optionsList.ts +41 -0
  262. package/src/orderProperties.ts +44 -0
  263. package/src/pad.ts +13 -0
  264. package/src/parseDateString.ts +33 -0
  265. package/src/parser/ParserValidator.ts +132 -0
  266. package/src/parser/index.ts +6 -0
  267. package/src/parser/schemaParser.ts +60 -0
  268. package/src/rangeSpec.ts +22 -0
  269. package/src/replaceStringParameters.ts +22 -0
  270. package/src/schema/getClosestMatchingOption.ts +191 -0
  271. package/src/schema/getDefaultFormState.ts +447 -0
  272. package/src/schema/getDisplayLabel.ts +59 -0
  273. package/src/schema/getFirstMatchingOption.ts +27 -0
  274. package/src/schema/getMatchingOption.ts +95 -0
  275. package/src/schema/index.ts +29 -0
  276. package/src/schema/isFilesArray.ts +27 -0
  277. package/src/schema/isMultiSelect.ts +21 -0
  278. package/src/schema/isSelect.ts +26 -0
  279. package/src/schema/mergeValidationData.ts +38 -0
  280. package/src/schema/retrieveSchema.ts +614 -0
  281. package/src/schema/sanitizeDataForNewSchema.ts +197 -0
  282. package/src/schema/toIdSchema.ts +105 -0
  283. package/src/schema/toPathSchema.ts +121 -0
  284. package/src/schemaRequiresTrueValue.ts +40 -0
  285. package/src/shouldRender.ts +16 -0
  286. package/src/toConstant.ts +19 -0
  287. package/src/toDateString.ts +15 -0
  288. package/src/toErrorList.ts +41 -0
  289. package/src/toErrorSchema.ts +43 -0
  290. package/src/types.ts +1139 -0
  291. package/src/unwrapErrorHandler.ts +25 -0
  292. package/src/utcToLocal.ts +30 -0
  293. package/src/validationDataMerge.ts +31 -0
  294. package/src/withIdRefPrefix.ts +49 -0
  295. package/dist/index.d.ts +0 -1911
  296. package/dist/utils.cjs.development.js +0 -3522
  297. package/dist/utils.cjs.development.js.map +0 -1
  298. package/dist/utils.cjs.production.min.js +0 -2
  299. package/dist/utils.cjs.production.min.js.map +0 -1
  300. package/dist/utils.umd.development.js +0 -3504
  301. package/dist/utils.umd.development.js.map +0 -1
  302. package/dist/utils.umd.production.min.js +0 -2
  303. package/dist/utils.umd.production.min.js.map +0 -1
@@ -0,0 +1,59 @@
1
+ import { UI_FIELD_KEY, UI_WIDGET_KEY } from '../constants';
2
+ import getSchemaType from '../getSchemaType';
3
+ import getUiOptions from '../getUiOptions';
4
+ import isCustomWidget from '../isCustomWidget';
5
+ import {
6
+ FormContextType,
7
+ GlobalUISchemaOptions,
8
+ RJSFSchema,
9
+ StrictRJSFSchema,
10
+ UiSchema,
11
+ ValidatorType,
12
+ } from '../types';
13
+ import isFilesArray from './isFilesArray';
14
+ import isMultiSelect from './isMultiSelect';
15
+
16
+ /** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
17
+ * should be displayed in a UI.
18
+ *
19
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
20
+ * @param schema - The schema for which the display label flag is desired
21
+ * @param [uiSchema={}] - The UI schema from which to derive potentially displayable information
22
+ * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
23
+ * @param [globalOptions={}] - The optional Global UI Schema from which to get any fallback `xxx` options
24
+ * @returns - True if the label should be displayed or false if it should not
25
+ */
26
+ export default function getDisplayLabel<
27
+ T = any,
28
+ S extends StrictRJSFSchema = RJSFSchema,
29
+ F extends FormContextType = any
30
+ >(
31
+ validator: ValidatorType<T, S, F>,
32
+ schema: S,
33
+ uiSchema: UiSchema<T, S, F> = {},
34
+ rootSchema?: S,
35
+ globalOptions?: GlobalUISchemaOptions
36
+ ): boolean {
37
+ const uiOptions = getUiOptions<T, S, F>(uiSchema, globalOptions);
38
+ const { label = true } = uiOptions;
39
+ let displayLabel = !!label;
40
+ const schemaType = getSchemaType<S>(schema);
41
+
42
+ if (schemaType === 'array') {
43
+ displayLabel =
44
+ isMultiSelect<T, S, F>(validator, schema, rootSchema) ||
45
+ isFilesArray<T, S, F>(validator, schema, uiSchema, rootSchema) ||
46
+ isCustomWidget(uiSchema);
47
+ }
48
+
49
+ if (schemaType === 'object') {
50
+ displayLabel = false;
51
+ }
52
+ if (schemaType === 'boolean' && !uiSchema[UI_WIDGET_KEY]) {
53
+ displayLabel = false;
54
+ }
55
+ if (uiSchema[UI_FIELD_KEY]) {
56
+ displayLabel = false;
57
+ }
58
+ return displayLabel;
59
+ }
@@ -0,0 +1,27 @@
1
+ import getMatchingOption from './getMatchingOption';
2
+ import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
3
+
4
+ /** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
5
+ * Always returns the first option if there is nothing that matches.
6
+ *
7
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
8
+ * @param formData - The current formData, if any, used to figure out a match
9
+ * @param options - The list of options to find a matching options from
10
+ * @param rootSchema - The root schema, used to primarily to look up `$ref`s
11
+ * @param [discriminatorField] - The optional name of the field within the options object whose value is used to
12
+ * determine which option is selected
13
+ * @returns - The index of the first matched option or 0 if none is available
14
+ */
15
+ export default function getFirstMatchingOption<
16
+ T = any,
17
+ S extends StrictRJSFSchema = RJSFSchema,
18
+ F extends FormContextType = any
19
+ >(
20
+ validator: ValidatorType<T, S, F>,
21
+ formData: T | undefined,
22
+ options: S[],
23
+ rootSchema: S,
24
+ discriminatorField?: string
25
+ ): number {
26
+ return getMatchingOption<T, S, F>(validator, formData, options, rootSchema, discriminatorField);
27
+ }
@@ -0,0 +1,95 @@
1
+ import get from 'lodash/get';
2
+ import has from 'lodash/has';
3
+
4
+ import { PROPERTIES_KEY } from '../constants';
5
+ import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
6
+
7
+ /** Given the `formData` and list of `options`, attempts to find the index of the option that best matches the data.
8
+ * Deprecated, use `getFirstMatchingOption()` instead.
9
+ *
10
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
11
+ * @param formData - The current formData, if any, used to figure out a match
12
+ * @param options - The list of options to find a matching options from
13
+ * @param rootSchema - The root schema, used to primarily to look up `$ref`s
14
+ * @param [discriminatorField] - The optional name of the field within the options object whose value is used to
15
+ * determine which option is selected
16
+ * @returns - The index of the matched option or 0 if none is available
17
+ * @deprecated
18
+ */
19
+ export default function getMatchingOption<
20
+ T = any,
21
+ S extends StrictRJSFSchema = RJSFSchema,
22
+ F extends FormContextType = any
23
+ >(
24
+ validator: ValidatorType<T, S, F>,
25
+ formData: T | undefined,
26
+ options: S[],
27
+ rootSchema: S,
28
+ discriminatorField?: string
29
+ ): number {
30
+ // For performance, skip validating subschemas if formData is undefined. We just
31
+ // want to get the first option in that case.
32
+ if (formData === undefined) {
33
+ return 0;
34
+ }
35
+ for (let i = 0; i < options.length; i++) {
36
+ const option = options[i];
37
+
38
+ // If we have a discriminator field, then we will use this to make the determination
39
+ if (discriminatorField && has(option, [PROPERTIES_KEY, discriminatorField])) {
40
+ const value = get(formData, discriminatorField);
41
+ const discriminator = get(option, [PROPERTIES_KEY, discriminatorField], {});
42
+ if (validator.isValid(discriminator, value, rootSchema)) {
43
+ return i;
44
+ }
45
+ } else if (option[PROPERTIES_KEY]) {
46
+ // If the schema describes an object then we need to add slightly more
47
+ // strict matching to the schema, because unless the schema uses the
48
+ // "requires" keyword, an object will match the schema as long as it
49
+ // doesn't have matching keys with a conflicting type. To do this we use an
50
+ // "anyOf" with an array of requires. This augmentation expresses that the
51
+ // schema should match if any of the keys in the schema are present on the
52
+ // object and pass validation.
53
+ //
54
+ // Create an "anyOf" schema that requires at least one of the keys in the
55
+ // "properties" object
56
+ const requiresAnyOf = {
57
+ anyOf: Object.keys(option[PROPERTIES_KEY]).map((key) => ({
58
+ required: [key],
59
+ })),
60
+ };
61
+
62
+ let augmentedSchema;
63
+
64
+ // If the "anyOf" keyword already exists, wrap the augmentation in an "allOf"
65
+ if (option.anyOf) {
66
+ // Create a shallow clone of the option
67
+ const { ...shallowClone } = option;
68
+
69
+ if (!shallowClone.allOf) {
70
+ shallowClone.allOf = [];
71
+ } else {
72
+ // If "allOf" already exists, shallow clone the array
73
+ shallowClone.allOf = shallowClone.allOf.slice();
74
+ }
75
+
76
+ shallowClone.allOf.push(requiresAnyOf);
77
+
78
+ augmentedSchema = shallowClone;
79
+ } else {
80
+ augmentedSchema = Object.assign({}, option, requiresAnyOf);
81
+ }
82
+
83
+ // Remove the "required" field as it's likely that not all fields have
84
+ // been filled in yet, which will mean that the schema is not valid
85
+ delete augmentedSchema.required;
86
+
87
+ if (validator.isValid(augmentedSchema, formData, rootSchema)) {
88
+ return i;
89
+ }
90
+ } else if (validator.isValid(option, formData, rootSchema)) {
91
+ return i;
92
+ }
93
+ }
94
+ return 0;
95
+ }
@@ -0,0 +1,29 @@
1
+ import getDefaultFormState from './getDefaultFormState';
2
+ import getDisplayLabel from './getDisplayLabel';
3
+ import getClosestMatchingOption from './getClosestMatchingOption';
4
+ import getFirstMatchingOption from './getFirstMatchingOption';
5
+ import getMatchingOption from './getMatchingOption';
6
+ import isFilesArray from './isFilesArray';
7
+ import isMultiSelect from './isMultiSelect';
8
+ import isSelect from './isSelect';
9
+ import mergeValidationData from './mergeValidationData';
10
+ import retrieveSchema from './retrieveSchema';
11
+ import sanitizeDataForNewSchema from './sanitizeDataForNewSchema';
12
+ import toIdSchema from './toIdSchema';
13
+ import toPathSchema from './toPathSchema';
14
+
15
+ export {
16
+ getDefaultFormState,
17
+ getDisplayLabel,
18
+ getClosestMatchingOption,
19
+ getFirstMatchingOption,
20
+ getMatchingOption,
21
+ isFilesArray,
22
+ isMultiSelect,
23
+ isSelect,
24
+ mergeValidationData,
25
+ retrieveSchema,
26
+ sanitizeDataForNewSchema,
27
+ toIdSchema,
28
+ toPathSchema,
29
+ };
@@ -0,0 +1,27 @@
1
+ import { UI_WIDGET_KEY } from '../constants';
2
+ import { FormContextType, RJSFSchema, StrictRJSFSchema, UiSchema, ValidatorType } from '../types';
3
+ import retrieveSchema from './retrieveSchema';
4
+
5
+ /** Checks to see if the `schema` and `uiSchema` combination represents an array of files
6
+ *
7
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
8
+ * @param schema - The schema for which check for array of files flag is desired
9
+ * @param [uiSchema={}] - The UI schema from which to check the widget
10
+ * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
11
+ * @returns - True if schema/uiSchema contains an array of files, otherwise false
12
+ */
13
+ export default function isFilesArray<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
14
+ validator: ValidatorType<T, S, F>,
15
+ schema: S,
16
+ uiSchema: UiSchema<T, S, F> = {},
17
+ rootSchema?: S
18
+ ) {
19
+ if (uiSchema[UI_WIDGET_KEY] === 'files') {
20
+ return true;
21
+ }
22
+ if (schema.items) {
23
+ const itemsSchema = retrieveSchema<T, S, F>(validator, schema.items as S, rootSchema);
24
+ return itemsSchema.type === 'string' && itemsSchema.format === 'data-url';
25
+ }
26
+ return false;
27
+ }
@@ -0,0 +1,21 @@
1
+ import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
2
+
3
+ import isSelect from './isSelect';
4
+
5
+ /** Checks to see if the `schema` combination represents a multi-select
6
+ *
7
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
8
+ * @param schema - The schema for which check for a multi-select flag is desired
9
+ * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
10
+ * @returns - True if schema contains a multi-select, otherwise false
11
+ */
12
+ export default function isMultiSelect<
13
+ T = any,
14
+ S extends StrictRJSFSchema = RJSFSchema,
15
+ F extends FormContextType = any
16
+ >(validator: ValidatorType<T, S, F>, schema: S, rootSchema?: S) {
17
+ if (!schema.uniqueItems || !schema.items || typeof schema.items === 'boolean') {
18
+ return false;
19
+ }
20
+ return isSelect<T, S, F>(validator, schema.items as S, rootSchema);
21
+ }
@@ -0,0 +1,26 @@
1
+ import isConstant from '../isConstant';
2
+ import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
3
+ import retrieveSchema from './retrieveSchema';
4
+
5
+ /** Checks to see if the `schema` combination represents a select
6
+ *
7
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
8
+ * @param theSchema - The schema for which check for a select flag is desired
9
+ * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
10
+ * @returns - True if schema contains a select, otherwise false
11
+ */
12
+ export default function isSelect<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
13
+ validator: ValidatorType<T, S, F>,
14
+ theSchema: S,
15
+ rootSchema: S = {} as S
16
+ ) {
17
+ const schema = retrieveSchema<T, S, F>(validator, theSchema, rootSchema, undefined);
18
+ const altSchemas = schema.oneOf || schema.anyOf;
19
+ if (Array.isArray(schema.enum)) {
20
+ return true;
21
+ }
22
+ if (Array.isArray(altSchemas)) {
23
+ return altSchemas.every((altSchemas) => typeof altSchemas !== 'boolean' && isConstant(altSchemas));
24
+ }
25
+ return false;
26
+ }
@@ -0,0 +1,38 @@
1
+ import isEmpty from 'lodash/isEmpty';
2
+
3
+ import mergeObjects from '../mergeObjects';
4
+ import { ErrorSchema, FormContextType, RJSFSchema, StrictRJSFSchema, ValidationData, ValidatorType } from '../types';
5
+
6
+ /** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in the
7
+ * two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
8
+ * `validator.toErrorList()` onto the `errors` in the `validationData`. If no `additionalErrorSchema` is passed, then
9
+ * `validationData` is returned.
10
+ *
11
+ * @param validator - The validator used to convert an ErrorSchema to a list of errors
12
+ * @param validationData - The current `ValidationData` into which to merge the additional errors
13
+ * @param [additionalErrorSchema] - The additional set of errors in an `ErrorSchema`
14
+ * @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
15
+ * @deprecated - Use the `validationDataMerge()` function exported from `@rjsf/utils` instead. This function will be
16
+ * removed in the next major release.
17
+ */
18
+ export default function mergeValidationData<
19
+ T = any,
20
+ S extends StrictRJSFSchema = RJSFSchema,
21
+ F extends FormContextType = any
22
+ >(
23
+ validator: ValidatorType<T, S, F>,
24
+ validationData: ValidationData<T>,
25
+ additionalErrorSchema?: ErrorSchema<T>
26
+ ): ValidationData<T> {
27
+ if (!additionalErrorSchema) {
28
+ return validationData;
29
+ }
30
+ const { errors: oldErrors, errorSchema: oldErrorSchema } = validationData;
31
+ let errors = validator.toErrorList(additionalErrorSchema);
32
+ let errorSchema = additionalErrorSchema;
33
+ if (!isEmpty(oldErrorSchema)) {
34
+ errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true) as ErrorSchema<T>;
35
+ errors = [...oldErrors].concat(errors);
36
+ }
37
+ return { errorSchema, errors };
38
+ }