@rjsf/utils 5.11.2 → 5.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (303) hide show
  1. package/dist/index.js +2545 -5
  2. package/dist/index.js.map +7 -0
  3. package/dist/utils.esm.js +1230 -2114
  4. package/dist/utils.esm.js.map +7 -1
  5. package/dist/utils.umd.js +2415 -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 +438 -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 +615 -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
package/dist/utils.esm.js CHANGED
@@ -1,185 +1,107 @@
1
- import isPlainObject from 'lodash-es/isPlainObject';
2
- import isEqualWith from 'lodash-es/isEqualWith';
3
- import get from 'lodash-es/get';
4
- import isEmpty from 'lodash-es/isEmpty';
5
- import jsonpointer from 'jsonpointer';
6
- import omit from 'lodash-es/omit';
7
- import has from 'lodash-es/has';
8
- import isObject$1 from 'lodash-es/isObject';
9
- import isString from 'lodash-es/isString';
10
- import reduce from 'lodash-es/reduce';
11
- import times from 'lodash-es/times';
12
- import set from 'lodash-es/set';
13
- import transform from 'lodash-es/transform';
14
- import mergeAllOf from 'json-schema-merge-allof';
15
- import union from 'lodash-es/union';
16
- import isEqual from 'lodash-es/isEqual';
17
- import { isNil } from 'lodash-es';
18
- import cloneDeep from 'lodash-es/cloneDeep';
19
- import { jsx } from 'react/jsx-runtime';
20
- import { createElement } from 'react';
21
- import ReactIs from 'react-is';
22
- import toPath from 'lodash-es/toPath';
23
- import forEach from 'lodash-es/forEach';
24
-
25
- /** Determines whether a `thing` is an object for the purposes of RSJF. In this case, `thing` is an object if it has
26
- * the type `object` but is NOT null, an array or a File.
27
- *
28
- * @param thing - The thing to check to see whether it is an object
29
- * @returns - True if it is a non-null, non-array, non-File object
30
- */
1
+ // src/isObject.ts
31
2
  function isObject(thing) {
32
- if (typeof File !== 'undefined' && thing instanceof File) {
3
+ if (typeof File !== "undefined" && thing instanceof File) {
33
4
  return false;
34
5
  }
35
- if (typeof Date !== 'undefined' && thing instanceof Date) {
6
+ if (typeof Date !== "undefined" && thing instanceof Date) {
36
7
  return false;
37
8
  }
38
- return typeof thing === 'object' && thing !== null && !Array.isArray(thing);
9
+ return typeof thing === "object" && thing !== null && !Array.isArray(thing);
39
10
  }
40
11
 
41
- /** Checks the schema to see if it is allowing additional items, by verifying that `schema.additionalItems` is an
42
- * object. The user is warned in the console if `schema.additionalItems` has the value `true`.
43
- *
44
- * @param schema - The schema object to check
45
- * @returns - True if additional items is allowed, otherwise false
46
- */
12
+ // src/allowAdditionalItems.ts
47
13
  function allowAdditionalItems(schema) {
48
14
  if (schema.additionalItems === true) {
49
- console.warn('additionalItems=true is currently not supported');
15
+ console.warn("additionalItems=true is currently not supported");
50
16
  }
51
17
  return isObject(schema.additionalItems);
52
18
  }
53
19
 
54
- /** Attempts to convert the string into a number. If an empty string is provided, then `undefined` is returned. If a
55
- * `null` is provided, it is returned. If the string ends in a `.` then the string is returned because the user may be
56
- * in the middle of typing a float number. If a number ends in a pattern like `.0`, `.20`, `.030`, string is returned
57
- * because the user may be typing number that will end in a non-zero digit. Otherwise, the string is wrapped by
58
- * `Number()` and if that result is not `NaN`, that number will be returned, otherwise the string `value` will be.
59
- *
60
- * @param value - The string or null value to convert to a number
61
- * @returns - The `value` converted to a number when appropriate, otherwise the `value`
62
- */
20
+ // src/asNumber.ts
63
21
  function asNumber(value) {
64
- if (value === '') {
65
- return undefined;
22
+ if (value === "") {
23
+ return void 0;
66
24
  }
67
25
  if (value === null) {
68
26
  return null;
69
27
  }
70
28
  if (/\.$/.test(value)) {
71
- // '3.' can't really be considered a number even if it parses in js. The
72
- // user is most likely entering a float.
73
29
  return value;
74
30
  }
75
31
  if (/\.0$/.test(value)) {
76
- // we need to return this as a string here, to allow for input like 3.07
77
32
  return value;
78
33
  }
79
34
  if (/\.\d*0$/.test(value)) {
80
- // It's a number, that's cool - but we need it as a string so it doesn't screw
81
- // with the user when entering dollar amounts or other values (such as those with
82
- // specific precision or number of significant digits)
83
35
  return value;
84
36
  }
85
37
  const n = Number(value);
86
- const valid = typeof n === 'number' && !Number.isNaN(n);
38
+ const valid = typeof n === "number" && !Number.isNaN(n);
87
39
  return valid ? n : value;
88
40
  }
89
41
 
90
- /** Below are the list of all the keys into various elements of a RJSFSchema or UiSchema that are used by the various
91
- * utility functions. In addition to those keys, there are the special `ADDITIONAL_PROPERTY_FLAG` and
92
- * `RJSF_ADDITONAL_PROPERTIES_FLAG` flags that is added to a schema under certain conditions by the `retrieveSchema()`
93
- * utility.
94
- */
95
- const ADDITIONAL_PROPERTY_FLAG = '__additional_property';
96
- const ADDITIONAL_PROPERTIES_KEY = 'additionalProperties';
97
- const ALL_OF_KEY = 'allOf';
98
- const ANY_OF_KEY = 'anyOf';
99
- const CONST_KEY = 'const';
100
- const DEFAULT_KEY = 'default';
101
- const DEFINITIONS_KEY = 'definitions';
102
- const DEPENDENCIES_KEY = 'dependencies';
103
- const ENUM_KEY = 'enum';
104
- const ERRORS_KEY = '__errors';
105
- const ID_KEY = '$id';
106
- const IF_KEY = 'if';
107
- const ITEMS_KEY = 'items';
108
- const JUNK_OPTION_ID = '_$junk_option_schema_id$_';
109
- const NAME_KEY = '$name';
110
- const ONE_OF_KEY = 'oneOf';
111
- const PROPERTIES_KEY = 'properties';
112
- const REQUIRED_KEY = 'required';
113
- const SUBMIT_BTN_OPTIONS_KEY = 'submitButtonOptions';
114
- const REF_KEY = '$ref';
115
- const RJSF_ADDITONAL_PROPERTIES_FLAG = '__rjsf_additionalProperties';
116
- const ROOT_SCHEMA_PREFIX = '__rjsf_rootSchema';
117
- const UI_FIELD_KEY = 'ui:field';
118
- const UI_WIDGET_KEY = 'ui:widget';
119
- const UI_OPTIONS_KEY = 'ui:options';
120
- const UI_GLOBAL_OPTIONS_KEY = 'ui:globalOptions';
121
-
122
- /** Get all passed options from ui:options, and ui:<optionName>, returning them in an object with the `ui:`
123
- * stripped off. Any `globalOptions` will always be returned, unless they are overridden by options in the `uiSchema`.
124
- *
125
- * @param [uiSchema={}] - The UI Schema from which to get any `ui:xxx` options
126
- * @param [globalOptions={}] - The optional Global UI Schema from which to get any fallback `xxx` options
127
- * @returns - An object containing all the `ui:xxx` options with the `ui:` stripped off along with all `globalOptions`
128
- */
42
+ // src/constants.ts
43
+ var ADDITIONAL_PROPERTY_FLAG = "__additional_property";
44
+ var ADDITIONAL_PROPERTIES_KEY = "additionalProperties";
45
+ var ALL_OF_KEY = "allOf";
46
+ var ANY_OF_KEY = "anyOf";
47
+ var CONST_KEY = "const";
48
+ var DEFAULT_KEY = "default";
49
+ var DEFINITIONS_KEY = "definitions";
50
+ var DEPENDENCIES_KEY = "dependencies";
51
+ var ENUM_KEY = "enum";
52
+ var ERRORS_KEY = "__errors";
53
+ var ID_KEY = "$id";
54
+ var IF_KEY = "if";
55
+ var ITEMS_KEY = "items";
56
+ var JUNK_OPTION_ID = "_$junk_option_schema_id$_";
57
+ var NAME_KEY = "$name";
58
+ var ONE_OF_KEY = "oneOf";
59
+ var PROPERTIES_KEY = "properties";
60
+ var REQUIRED_KEY = "required";
61
+ var SUBMIT_BTN_OPTIONS_KEY = "submitButtonOptions";
62
+ var REF_KEY = "$ref";
63
+ var RJSF_ADDITONAL_PROPERTIES_FLAG = "__rjsf_additionalProperties";
64
+ var ROOT_SCHEMA_PREFIX = "__rjsf_rootSchema";
65
+ var UI_FIELD_KEY = "ui:field";
66
+ var UI_WIDGET_KEY = "ui:widget";
67
+ var UI_OPTIONS_KEY = "ui:options";
68
+ var UI_GLOBAL_OPTIONS_KEY = "ui:globalOptions";
69
+
70
+ // src/getUiOptions.ts
129
71
  function getUiOptions(uiSchema = {}, globalOptions = {}) {
130
- return Object.keys(uiSchema).filter(key => key.indexOf('ui:') === 0).reduce((options, key) => {
131
- const value = uiSchema[key];
132
- if (key === UI_WIDGET_KEY && isObject(value)) {
133
- console.error('Setting options via ui:widget object is no longer supported, use ui:options instead');
134
- return options;
135
- }
136
- if (key === UI_OPTIONS_KEY && isObject(value)) {
137
- return {
138
- ...options,
139
- ...value
140
- };
141
- }
142
- return {
143
- ...options,
144
- [key.substring(3)]: value
145
- };
146
- }, {
147
- ...globalOptions
148
- });
72
+ return Object.keys(uiSchema).filter((key) => key.indexOf("ui:") === 0).reduce(
73
+ (options, key) => {
74
+ const value = uiSchema[key];
75
+ if (key === UI_WIDGET_KEY && isObject(value)) {
76
+ console.error("Setting options via ui:widget object is no longer supported, use ui:options instead");
77
+ return options;
78
+ }
79
+ if (key === UI_OPTIONS_KEY && isObject(value)) {
80
+ return { ...options, ...value };
81
+ }
82
+ return { ...options, [key.substring(3)]: value };
83
+ },
84
+ { ...globalOptions }
85
+ );
149
86
  }
150
87
 
151
- /** Checks whether the field described by `schema`, having the `uiSchema` and `formData` supports expanding. The UI for
152
- * the field can expand if it has additional properties, is not forced as non-expandable by the `uiSchema` and the
153
- * `formData` object doesn't already have `schema.maxProperties` elements.
154
- *
155
- * @param schema - The schema for the field that is being checked
156
- * @param [uiSchema={}] - The uiSchema for the field
157
- * @param [formData] - The formData for the field
158
- * @returns - True if the schema element has additionalProperties, is expandable, and not at the maxProperties limit
159
- */
88
+ // src/canExpand.ts
160
89
  function canExpand(schema, uiSchema = {}, formData) {
161
90
  if (!schema.additionalProperties) {
162
91
  return false;
163
92
  }
164
- const {
165
- expandable = true
166
- } = getUiOptions(uiSchema);
93
+ const { expandable = true } = getUiOptions(uiSchema);
167
94
  if (expandable === false) {
168
95
  return expandable;
169
96
  }
170
- // if ui:options.expandable was not explicitly set to false, we can add
171
- // another property if we have not exceeded maxProperties yet
172
- if (schema.maxProperties !== undefined && formData) {
97
+ if (schema.maxProperties !== void 0 && formData) {
173
98
  return Object.keys(formData).length < schema.maxProperties;
174
99
  }
175
100
  return true;
176
101
  }
177
102
 
178
- /** Given a `formData` object, recursively creates a `FormValidation` error handling structure around it
179
- *
180
- * @param formData - The form data around which the error handler is created
181
- * @returns - A `FormValidation` object based on the `formData` structure
182
- */
103
+ // src/createErrorHandler.ts
104
+ import isPlainObject from "lodash/isPlainObject";
183
105
  function createErrorHandler(formData) {
184
106
  const handler = {
185
107
  // We store the list of errors for this node in a property named __errors
@@ -192,111 +114,80 @@ function createErrorHandler(formData) {
192
114
  };
193
115
  if (Array.isArray(formData)) {
194
116
  return formData.reduce((acc, value, key) => {
195
- return {
196
- ...acc,
197
- [key]: createErrorHandler(value)
198
- };
117
+ return { ...acc, [key]: createErrorHandler(value) };
199
118
  }, handler);
200
119
  }
201
120
  if (isPlainObject(formData)) {
202
121
  const formObject = formData;
203
122
  return Object.keys(formObject).reduce((acc, key) => {
204
- return {
205
- ...acc,
206
- [key]: createErrorHandler(formObject[key])
207
- };
123
+ return { ...acc, [key]: createErrorHandler(formObject[key]) };
208
124
  }, handler);
209
125
  }
210
126
  return handler;
211
127
  }
212
128
 
213
- /** Implements a deep equals using the `lodash.isEqualWith` function, that provides a customized comparator that
214
- * assumes all functions are equivalent.
215
- *
216
- * @param a - The first element to compare
217
- * @param b - The second element to compare
218
- * @returns - True if the `a` and `b` are deeply equal, false otherwise
219
- */
129
+ // src/deepEquals.ts
130
+ import isEqualWith from "lodash/isEqualWith";
220
131
  function deepEquals(a, b) {
221
132
  return isEqualWith(a, b, (obj, other) => {
222
- if (typeof obj === 'function' && typeof other === 'function') {
223
- // Assume all functions are equivalent
224
- // see https://github.com/rjsf-team/react-jsonschema-form/issues/255
133
+ if (typeof obj === "function" && typeof other === "function") {
225
134
  return true;
226
135
  }
227
- return undefined; // fallback to default isEquals behavior
136
+ return void 0;
228
137
  });
229
138
  }
230
139
 
231
- /** Splits out the value at the `key` in `object` from the `object`, returning an array that contains in the first
232
- * location, the `object` minus the `key: value` and in the second location the `value`.
233
- *
234
- * @param key - The key from the object to extract
235
- * @param object - The object from which to extract the element
236
- * @returns - An array with the first value being the object minus the `key` element and the second element being the
237
- * value from `object[key]`
238
- */
140
+ // src/schema/getDefaultFormState.ts
141
+ import get6 from "lodash/get";
142
+ import isEmpty from "lodash/isEmpty";
143
+
144
+ // src/findSchemaDefinition.ts
145
+ import jsonpointer from "jsonpointer";
146
+ import omit from "lodash/omit";
239
147
  function splitKeyElementFromObject(key, object) {
240
148
  const value = object[key];
241
149
  const remaining = omit(object, [key]);
242
150
  return [remaining, value];
243
151
  }
244
- /** Given the name of a `$ref` from within a schema, using the `rootSchema`, look up and return the sub-schema using the
245
- * path provided by that reference. If `#` is not the first character of the reference, or the path does not exist in
246
- * the schema, then throw an Error. Otherwise return the sub-schema. Also deals with nested `$ref`s in the sub-schema.
247
- *
248
- * @param $ref - The ref string for which the schema definition is desired
249
- * @param [rootSchema={}] - The root schema in which to search for the definition
250
- * @returns - The sub-schema within the `rootSchema` which matches the `$ref` if it exists
251
- * @throws - Error indicating that no schema for that reference exists
252
- */
253
152
  function findSchemaDefinition($ref, rootSchema = {}) {
254
- let ref = $ref || '';
255
- if (ref.startsWith('#')) {
256
- // Decode URI fragment representation.
153
+ let ref = $ref || "";
154
+ if (ref.startsWith("#")) {
257
155
  ref = decodeURIComponent(ref.substring(1));
258
156
  } else {
259
157
  throw new Error(`Could not find a definition for ${$ref}.`);
260
158
  }
261
159
  const current = jsonpointer.get(rootSchema, ref);
262
- if (current === undefined) {
160
+ if (current === void 0) {
263
161
  throw new Error(`Could not find a definition for ${$ref}.`);
264
162
  }
265
163
  if (current[REF_KEY]) {
266
164
  const [remaining, theRef] = splitKeyElementFromObject(REF_KEY, current);
267
165
  const subSchema = findSchemaDefinition(theRef, rootSchema);
268
166
  if (Object.keys(remaining).length > 0) {
269
- return {
270
- ...remaining,
271
- ...subSchema
272
- };
167
+ return { ...remaining, ...subSchema };
273
168
  }
274
169
  return subSchema;
275
170
  }
276
171
  return current;
277
172
  }
278
173
 
279
- /** Given the `formData` and list of `options`, attempts to find the index of the option that best matches the data.
280
- * Deprecated, use `getFirstMatchingOption()` instead.
281
- *
282
- * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
283
- * @param formData - The current formData, if any, used to figure out a match
284
- * @param options - The list of options to find a matching options from
285
- * @param rootSchema - The root schema, used to primarily to look up `$ref`s
286
- * @param [discriminatorField] - The optional name of the field within the options object whose value is used to
287
- * determine which option is selected
288
- * @returns - The index of the matched option or 0 if none is available
289
- * @deprecated
290
- */
174
+ // src/schema/getClosestMatchingOption.ts
175
+ import get4 from "lodash/get";
176
+ import has2 from "lodash/has";
177
+ import isObject2 from "lodash/isObject";
178
+ import isString2 from "lodash/isString";
179
+ import reduce from "lodash/reduce";
180
+ import times2 from "lodash/times";
181
+
182
+ // src/schema/getMatchingOption.ts
183
+ import get from "lodash/get";
184
+ import has from "lodash/has";
291
185
  function getMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
292
- // For performance, skip validating subschemas if formData is undefined. We just
293
- // want to get the first option in that case.
294
- if (formData === undefined) {
186
+ if (formData === void 0) {
295
187
  return 0;
296
188
  }
297
189
  for (let i = 0; i < options.length; i++) {
298
190
  const option = options[i];
299
- // If we have a discriminator field, then we will use this to make the determination
300
191
  if (discriminatorField && has(option, [PROPERTIES_KEY, discriminatorField])) {
301
192
  const value = get(formData, discriminatorField);
302
193
  const discriminator = get(option, [PROPERTIES_KEY, discriminatorField], {});
@@ -304,32 +195,17 @@ function getMatchingOption(validator, formData, options, rootSchema, discriminat
304
195
  return i;
305
196
  }
306
197
  } else if (option[PROPERTIES_KEY]) {
307
- // If the schema describes an object then we need to add slightly more
308
- // strict matching to the schema, because unless the schema uses the
309
- // "requires" keyword, an object will match the schema as long as it
310
- // doesn't have matching keys with a conflicting type. To do this we use an
311
- // "anyOf" with an array of requires. This augmentation expresses that the
312
- // schema should match if any of the keys in the schema are present on the
313
- // object and pass validation.
314
- //
315
- // Create an "anyOf" schema that requires at least one of the keys in the
316
- // "properties" object
317
198
  const requiresAnyOf = {
318
- anyOf: Object.keys(option[PROPERTIES_KEY]).map(key => ({
199
+ anyOf: Object.keys(option[PROPERTIES_KEY]).map((key) => ({
319
200
  required: [key]
320
201
  }))
321
202
  };
322
203
  let augmentedSchema;
323
- // If the "anyOf" keyword already exists, wrap the augmentation in an "allOf"
324
204
  if (option.anyOf) {
325
- // Create a shallow clone of the option
326
- const {
327
- ...shallowClone
328
- } = option;
205
+ const { ...shallowClone } = option;
329
206
  if (!shallowClone.allOf) {
330
207
  shallowClone.allOf = [];
331
208
  } else {
332
- // If "allOf" already exists, shallow clone the array
333
209
  shallowClone.allOf = shallowClone.allOf.slice();
334
210
  }
335
211
  shallowClone.allOf.push(requiresAnyOf);
@@ -337,8 +213,6 @@ function getMatchingOption(validator, formData, options, rootSchema, discriminat
337
213
  } else {
338
214
  augmentedSchema = Object.assign({}, option, requiresAnyOf);
339
215
  }
340
- // Remove the "required" field as it's likely that not all fields have
341
- // been filled in yet, which will mean that the schema is not valid
342
216
  delete augmentedSchema.required;
343
217
  if (validator.isValid(augmentedSchema, formData, rootSchema)) {
344
218
  return i;
@@ -350,393 +224,252 @@ function getMatchingOption(validator, formData, options, rootSchema, discriminat
350
224
  return 0;
351
225
  }
352
226
 
353
- /** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
354
- * Always returns the first option if there is nothing that matches.
355
- *
356
- * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
357
- * @param formData - The current formData, if any, used to figure out a match
358
- * @param options - The list of options to find a matching options from
359
- * @param rootSchema - The root schema, used to primarily to look up `$ref`s
360
- * @param [discriminatorField] - The optional name of the field within the options object whose value is used to
361
- * determine which option is selected
362
- * @returns - The index of the first matched option or 0 if none is available
363
- */
227
+ // src/schema/getFirstMatchingOption.ts
364
228
  function getFirstMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
365
229
  return getMatchingOption(validator, formData, options, rootSchema, discriminatorField);
366
230
  }
367
231
 
368
- /** Returns the `discriminator.propertyName` when defined in the `schema` if it is a string. A warning is generated when
369
- * it is not a string. Returns `undefined` when a valid discriminator is not present.
370
- *
371
- * @param schema - The schema from which the discriminator is potentially obtained
372
- * @returns - The `discriminator.propertyName` if it exists in the schema, otherwise `undefined`
373
- */
232
+ // src/schema/retrieveSchema.ts
233
+ import get3 from "lodash/get";
234
+ import set from "lodash/set";
235
+ import times from "lodash/times";
236
+ import transform from "lodash/transform";
237
+ import mergeAllOf from "json-schema-merge-allof";
238
+
239
+ // src/getDiscriminatorFieldFromSchema.ts
240
+ import get2 from "lodash/get";
241
+ import isString from "lodash/isString";
374
242
  function getDiscriminatorFieldFromSchema(schema) {
375
243
  let discriminator;
376
- const maybeString = get(schema, 'discriminator.propertyName', undefined);
244
+ const maybeString = get2(schema, "discriminator.propertyName", void 0);
377
245
  if (isString(maybeString)) {
378
246
  discriminator = maybeString;
379
- } else if (maybeString !== undefined) {
247
+ } else if (maybeString !== void 0) {
380
248
  console.warn(`Expecting discriminator to be a string, got "${typeof maybeString}" instead`);
381
249
  }
382
250
  return discriminator;
383
251
  }
384
252
 
385
- /** Given a specific `value` attempts to guess the type of a schema element. In the case where we have to implicitly
386
- * create a schema, it is useful to know what type to use based on the data we are defining.
387
- *
388
- * @param value - The value from which to guess the type
389
- * @returns - The best guess for the object type
390
- */
253
+ // src/guessType.ts
391
254
  function guessType(value) {
392
255
  if (Array.isArray(value)) {
393
- return 'array';
256
+ return "array";
394
257
  }
395
- if (typeof value === 'string') {
396
- return 'string';
258
+ if (typeof value === "string") {
259
+ return "string";
397
260
  }
398
261
  if (value == null) {
399
- return 'null';
262
+ return "null";
400
263
  }
401
- if (typeof value === 'boolean') {
402
- return 'boolean';
264
+ if (typeof value === "boolean") {
265
+ return "boolean";
403
266
  }
404
267
  if (!isNaN(value)) {
405
- return 'number';
406
- }
407
- if (typeof value === 'object') {
408
- return 'object';
409
- }
410
- // Default to string if we can't figure it out
411
- return 'string';
412
- }
413
-
414
- /** Gets the type of a given `schema`. If the type is not explicitly defined, then an attempt is made to infer it from
415
- * other elements of the schema as follows:
416
- * - schema.const: Returns the `guessType()` of that value
417
- * - schema.enum: Returns `string`
418
- * - schema.properties: Returns `object`
419
- * - schema.additionalProperties: Returns `object`
420
- * - type is an array with a length of 2 and one type is 'null': Returns the other type
421
- *
422
- * @param schema - The schema for which to get the type
423
- * @returns - The type of the schema
424
- */
268
+ return "number";
269
+ }
270
+ if (typeof value === "object") {
271
+ return "object";
272
+ }
273
+ return "string";
274
+ }
275
+
276
+ // src/mergeSchemas.ts
277
+ import union from "lodash/union";
278
+
279
+ // src/getSchemaType.ts
425
280
  function getSchemaType(schema) {
426
- let {
427
- type
428
- } = schema;
281
+ let { type } = schema;
429
282
  if (!type && schema.const) {
430
283
  return guessType(schema.const);
431
284
  }
432
285
  if (!type && schema.enum) {
433
- return 'string';
286
+ return "string";
434
287
  }
435
288
  if (!type && (schema.properties || schema.additionalProperties)) {
436
- return 'object';
289
+ return "object";
437
290
  }
438
- if (Array.isArray(type) && type.length === 2 && type.includes('null')) {
439
- type = type.find(type => type !== 'null');
291
+ if (Array.isArray(type) && type.length === 2 && type.includes("null")) {
292
+ type = type.find((type2) => type2 !== "null");
440
293
  }
441
294
  return type;
442
295
  }
443
296
 
444
- /** Recursively merge deeply nested schemas. The difference between `mergeSchemas` and `mergeObjects` is that
445
- * `mergeSchemas` only concats arrays for values under the 'required' keyword, and when it does, it doesn't include
446
- * duplicate values.
447
- *
448
- * @param obj1 - The first schema object to merge
449
- * @param obj2 - The second schema object to merge
450
- * @returns - The merged schema object
451
- */
297
+ // src/mergeSchemas.ts
452
298
  function mergeSchemas(obj1, obj2) {
453
- const acc = Object.assign({}, obj1); // Prevent mutation of source object.
454
- return Object.keys(obj2).reduce((acc, key) => {
455
- const left = obj1 ? obj1[key] : {},
456
- right = obj2[key];
299
+ const acc = Object.assign({}, obj1);
300
+ return Object.keys(obj2).reduce((acc2, key) => {
301
+ const left = obj1 ? obj1[key] : {}, right = obj2[key];
457
302
  if (obj1 && key in obj1 && isObject(right)) {
458
- acc[key] = mergeSchemas(left, right);
459
- } else if (obj1 && obj2 && (getSchemaType(obj1) === 'object' || getSchemaType(obj2) === 'object') && key === REQUIRED_KEY && Array.isArray(left) && Array.isArray(right)) {
460
- // Don't include duplicate values when merging 'required' fields.
461
- acc[key] = union(left, right);
303
+ acc2[key] = mergeSchemas(left, right);
304
+ } else if (obj1 && obj2 && (getSchemaType(obj1) === "object" || getSchemaType(obj2) === "object") && key === REQUIRED_KEY && Array.isArray(left) && Array.isArray(right)) {
305
+ acc2[key] = union(left, right);
462
306
  } else {
463
- acc[key] = right;
307
+ acc2[key] = right;
464
308
  }
465
- return acc;
309
+ return acc2;
466
310
  }, acc);
467
311
  }
468
312
 
469
- /** Retrieves an expanded schema that has had all of its conditions, additional properties, references and dependencies
470
- * resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData` that is used to do the
471
- * potentially recursive resolution.
472
- *
473
- * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
474
- * @param schema - The schema for which retrieving a schema is desired
475
- * @param [rootSchema={}] - The root schema that will be forwarded to all the APIs
476
- * @param [rawFormData] - The current formData, if any, to assist retrieving a schema
477
- * @returns - The schema having its conditions, additional properties, references and dependencies resolved
478
- */
313
+ // src/schema/retrieveSchema.ts
479
314
  function retrieveSchema(validator, schema, rootSchema = {}, rawFormData) {
480
315
  return retrieveSchemaInternal(validator, schema, rootSchema, rawFormData)[0];
481
316
  }
482
- /** Resolves a conditional block (if/else/then) by removing the condition and merging the appropriate conditional branch
483
- * with the rest of the schema. If `expandAllBranches` is true, then the `retrieveSchemaInteral()` results for both
484
- * conditions will be returned.
485
- *
486
- * @param validator - An implementation of the `ValidatorType` interface that is used to detect valid schema conditions
487
- * @param schema - The schema for which resolving a condition is desired
488
- * @param rootSchema - The root schema that will be forwarded to all the APIs
489
- * @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and
490
- * dependencies as a list of schemas
491
- * @param [formData] - The current formData to assist retrieving a schema
492
- * @returns - A list of schemas with the appropriate conditions resolved, possibly with all branches expanded
493
- */
494
317
  function resolveCondition(validator, schema, rootSchema, expandAllBranches, formData) {
495
- const {
496
- if: expression,
497
- then,
498
- else: otherwise,
499
- ...resolvedSchemaLessConditional
500
- } = schema;
318
+ const { if: expression, then, else: otherwise, ...resolvedSchemaLessConditional } = schema;
501
319
  const conditionValue = validator.isValid(expression, formData || {}, rootSchema);
502
320
  let resolvedSchemas = [resolvedSchemaLessConditional];
503
321
  let schemas = [];
504
322
  if (expandAllBranches) {
505
- if (then && typeof then !== 'boolean') {
506
- schemas = schemas.concat(retrieveSchemaInternal(validator, then, rootSchema, formData, expandAllBranches));
323
+ if (then && typeof then !== "boolean") {
324
+ schemas = schemas.concat(
325
+ retrieveSchemaInternal(validator, then, rootSchema, formData, expandAllBranches)
326
+ );
507
327
  }
508
- if (otherwise && typeof otherwise !== 'boolean') {
509
- schemas = schemas.concat(retrieveSchemaInternal(validator, otherwise, rootSchema, formData, expandAllBranches));
328
+ if (otherwise && typeof otherwise !== "boolean") {
329
+ schemas = schemas.concat(
330
+ retrieveSchemaInternal(validator, otherwise, rootSchema, formData, expandAllBranches)
331
+ );
510
332
  }
511
333
  } else {
512
334
  const conditionalSchema = conditionValue ? then : otherwise;
513
- if (conditionalSchema && typeof conditionalSchema !== 'boolean') {
514
- schemas = schemas.concat(retrieveSchemaInternal(validator, conditionalSchema, rootSchema, formData, expandAllBranches));
335
+ if (conditionalSchema && typeof conditionalSchema !== "boolean") {
336
+ schemas = schemas.concat(
337
+ retrieveSchemaInternal(validator, conditionalSchema, rootSchema, formData, expandAllBranches)
338
+ );
515
339
  }
516
340
  }
517
341
  if (schemas.length) {
518
- resolvedSchemas = schemas.map(s => mergeSchemas(resolvedSchemaLessConditional, s));
519
- }
520
- return resolvedSchemas.flatMap(s => retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches));
521
- }
522
- /** Given a list of lists of allOf, anyOf or oneOf values, create a list of lists of all permutations of the values. The
523
- * `listOfLists` is expected to be all resolved values of the 1st...nth schemas within an `allOf`, `anyOf` or `oneOf`.
524
- * From those lists, build a matrix for each `xxxOf` where there is more than one schema for a row in the list of lists.
525
- *
526
- * For example:
527
- * - If there are three xxxOf rows (A, B, C) and they have been resolved such that there is only one A, two B and three
528
- * C schemas then:
529
- * - The permutation for the first row is `[[A]]`
530
- * - The permutations for the second row are `[[A,B1], [A,B2]]`
531
- * - The permutations for the third row are `[[A,B1,C1], [A,B1,C2], [A,B1,C3], [A,B2,C1], [A,B2,C2], [A,B2,C3]]`
532
- *
533
- * @param listOfLists - The list of lists of elements that represent the allOf, anyOf or oneOf resolved values in order
534
- * @returns - The list of all permutations of schemas for a set of `xxxOf`s
535
- */
342
+ resolvedSchemas = schemas.map((s) => mergeSchemas(resolvedSchemaLessConditional, s));
343
+ }
344
+ return resolvedSchemas.flatMap(
345
+ (s) => retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches)
346
+ );
347
+ }
536
348
  function getAllPermutationsOfXxxOf(listOfLists) {
537
- const allPermutations = listOfLists.reduce((permutations, list) => {
538
- // When there are more than one set of schemas for a row, duplicate the set of permutations and add in the values
539
- if (list.length > 1) {
540
- return list.flatMap(element => times(permutations.length, i => [...permutations[i]].concat(element)));
541
- }
542
- // Otherwise just push in the single value into the current set of permutations
543
- permutations.forEach(permutation => permutation.push(list[0]));
544
- return permutations;
545
- }, [[]] // Start with an empty list
349
+ const allPermutations = listOfLists.reduce(
350
+ (permutations, list) => {
351
+ if (list.length > 1) {
352
+ return list.flatMap((element) => times(permutations.length, (i) => [...permutations[i]].concat(element)));
353
+ }
354
+ permutations.forEach((permutation) => permutation.push(list[0]));
355
+ return permutations;
356
+ },
357
+ [[]]
358
+ // Start with an empty list
546
359
  );
547
-
548
360
  return allPermutations;
549
361
  }
550
- /** Resolves references and dependencies within a schema and its 'allOf' children. Passes the `expandAllBranches` flag
551
- * down to the `retrieveSchemaInternal()`, `resolveReference()` and `resolveDependencies()` helper calls. If
552
- * `expandAllBranches` is true, then all possible dependencies and/or allOf branches are returned.
553
- *
554
- * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
555
- * @param schema - The schema for which resolving a schema is desired
556
- * @param rootSchema - The root schema that will be forwarded to all the APIs
557
- * @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
558
- * as a list of schemas
559
- * @param [formData] - The current formData, if any, to assist retrieving a schema
560
- * @returns - The list of schemas having its references, dependencies and allOf schemas resolved
561
- */
562
362
  function resolveSchema(validator, schema, rootSchema, expandAllBranches, formData) {
563
363
  if (REF_KEY in schema) {
564
364
  return resolveReference(validator, schema, rootSchema, expandAllBranches, formData);
565
365
  }
566
366
  if (DEPENDENCIES_KEY in schema) {
567
367
  const resolvedSchemas = resolveDependencies(validator, schema, rootSchema, expandAllBranches, formData);
568
- return resolvedSchemas.flatMap(s => {
368
+ return resolvedSchemas.flatMap((s) => {
569
369
  return retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches);
570
370
  });
571
371
  }
572
372
  if (ALL_OF_KEY in schema && Array.isArray(schema.allOf)) {
573
- const allOfSchemaElements = schema.allOf.map(allOfSubschema => retrieveSchemaInternal(validator, allOfSubschema, rootSchema, formData, expandAllBranches));
373
+ const allOfSchemaElements = schema.allOf.map(
374
+ (allOfSubschema) => retrieveSchemaInternal(validator, allOfSubschema, rootSchema, formData, expandAllBranches)
375
+ );
574
376
  const allPermutations = getAllPermutationsOfXxxOf(allOfSchemaElements);
575
- return allPermutations.map(permutation => ({
576
- ...schema,
577
- allOf: permutation
578
- }));
377
+ return allPermutations.map((permutation) => ({ ...schema, allOf: permutation }));
579
378
  }
580
- // No $ref or dependencies or allOf attribute was found, returning the original schema.
581
379
  return [schema];
582
380
  }
583
- /** Resolves references within a schema and then returns the `retrieveSchemaInternal()` of the resolved schema. Passes
584
- * the `expandAllBranches` flag down to the `retrieveSchemaInternal()` helper call.
585
- *
586
- * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
587
- * @param schema - The schema for which resolving a reference is desired
588
- * @param rootSchema - The root schema that will be forwarded to all the APIs
589
- * @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
590
- * as a list of schemas
591
- * @param [formData] - The current formData, if any, to assist retrieving a schema
592
- * @returns - The list schemas retrieved after having all references resolved
593
- */
594
381
  function resolveReference(validator, schema, rootSchema, expandAllBranches, formData) {
595
- // Drop the $ref property of the source schema.
596
- const {
597
- $ref,
598
- ...localSchema
599
- } = schema;
600
- // Retrieve the referenced schema definition.
382
+ const { $ref, ...localSchema } = schema;
601
383
  const refSchema = findSchemaDefinition($ref, rootSchema);
602
- // Update referenced schema definition with local schema properties.
603
- return retrieveSchemaInternal(validator, {
604
- ...refSchema,
605
- ...localSchema
606
- }, rootSchema, formData, expandAllBranches);
607
- }
608
- /** Resolves all references within a schema's properties and array items.
609
- *
610
- * @param schema - The schema for which resolving all references is desired
611
- * @param rootSchema - The root schema that will be forwarded to all the APIs
612
- * @returns - given schema will all references resolved
613
- */
384
+ return retrieveSchemaInternal(
385
+ validator,
386
+ { ...refSchema, ...localSchema },
387
+ rootSchema,
388
+ formData,
389
+ expandAllBranches
390
+ );
391
+ }
614
392
  function resolveAllReferences(schema, rootSchema) {
615
393
  let resolvedSchema = schema;
616
- // resolve top level ref
617
394
  if (REF_KEY in resolvedSchema) {
618
- const {
619
- $ref,
620
- ...localSchema
621
- } = resolvedSchema;
622
- // Retrieve the referenced schema definition.
395
+ const { $ref, ...localSchema } = resolvedSchema;
623
396
  const refSchema = findSchemaDefinition($ref, rootSchema);
624
- resolvedSchema = {
625
- ...refSchema,
626
- ...localSchema
627
- };
397
+ resolvedSchema = { ...refSchema, ...localSchema };
628
398
  }
629
399
  if (PROPERTIES_KEY in resolvedSchema) {
630
- const updatedProps = transform(resolvedSchema[PROPERTIES_KEY], (result, value, key) => {
631
- result[key] = resolveAllReferences(value, rootSchema);
632
- }, {});
633
- resolvedSchema = {
634
- ...resolvedSchema,
635
- [PROPERTIES_KEY]: updatedProps
636
- };
400
+ const updatedProps = transform(
401
+ resolvedSchema[PROPERTIES_KEY],
402
+ (result, value, key) => {
403
+ result[key] = resolveAllReferences(value, rootSchema);
404
+ },
405
+ {}
406
+ );
407
+ resolvedSchema = { ...resolvedSchema, [PROPERTIES_KEY]: updatedProps };
637
408
  }
638
- if (ITEMS_KEY in resolvedSchema && !Array.isArray(resolvedSchema.items) && typeof resolvedSchema.items !== 'boolean') {
639
- resolvedSchema = {
640
- ...resolvedSchema,
641
- items: resolveAllReferences(resolvedSchema.items, rootSchema)
642
- };
409
+ if (ITEMS_KEY in resolvedSchema && !Array.isArray(resolvedSchema.items) && typeof resolvedSchema.items !== "boolean") {
410
+ resolvedSchema = { ...resolvedSchema, items: resolveAllReferences(resolvedSchema.items, rootSchema) };
643
411
  }
644
412
  return resolvedSchema;
645
413
  }
646
- /** Creates new 'properties' items for each key in the `formData`
647
- *
648
- * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
649
- * @param theSchema - The schema for which the existing additional properties is desired
650
- * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s * @param validator
651
- * @param [aFormData] - The current formData, if any, to assist retrieving a schema
652
- * @returns - The updated schema with additional properties stubbed
653
- */
654
414
  function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData) {
655
- // Clone the schema so that we don't ruin the consumer's original
656
415
  const schema = {
657
416
  ...theSchema,
658
- properties: {
659
- ...theSchema.properties
660
- }
417
+ properties: { ...theSchema.properties }
661
418
  };
662
- // make sure formData is an object
663
419
  const formData = aFormData && isObject(aFormData) ? aFormData : {};
664
- Object.keys(formData).forEach(key => {
420
+ Object.keys(formData).forEach((key) => {
665
421
  if (key in schema.properties) {
666
- // No need to stub, our schema already has the property
667
422
  return;
668
423
  }
669
424
  let additionalProperties = {};
670
- if (typeof schema.additionalProperties !== 'boolean') {
425
+ if (typeof schema.additionalProperties !== "boolean") {
671
426
  if (REF_KEY in schema.additionalProperties) {
672
- additionalProperties = retrieveSchema(validator, {
673
- $ref: get(schema.additionalProperties, [REF_KEY])
674
- }, rootSchema, formData);
675
- } else if ('type' in schema.additionalProperties) {
676
- additionalProperties = {
677
- ...schema.additionalProperties
678
- };
427
+ additionalProperties = retrieveSchema(
428
+ validator,
429
+ { $ref: get3(schema.additionalProperties, [REF_KEY]) },
430
+ rootSchema,
431
+ formData
432
+ );
433
+ } else if ("type" in schema.additionalProperties) {
434
+ additionalProperties = { ...schema.additionalProperties };
679
435
  } else if (ANY_OF_KEY in schema.additionalProperties || ONE_OF_KEY in schema.additionalProperties) {
680
436
  additionalProperties = {
681
- type: 'object',
437
+ type: "object",
682
438
  ...schema.additionalProperties
683
439
  };
684
440
  } else {
685
- additionalProperties = {
686
- type: guessType(get(formData, [key]))
687
- };
441
+ additionalProperties = { type: guessType(get3(formData, [key])) };
688
442
  }
689
443
  } else {
690
- additionalProperties = {
691
- type: guessType(get(formData, [key]))
692
- };
444
+ additionalProperties = { type: guessType(get3(formData, [key])) };
693
445
  }
694
- // The type of our new key should match the additionalProperties value;
695
446
  schema.properties[key] = additionalProperties;
696
- // Set our additional property flag so we know it was dynamically added
697
447
  set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
698
448
  });
699
449
  return schema;
700
450
  }
701
- /** Internal handler that retrieves an expanded schema that has had all of its conditions, additional properties,
702
- * references and dependencies resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData`
703
- * that is used to do the potentially recursive resolution. If `expandAllBranches` is true, then all possible branches
704
- * of the schema and its references, conditions and dependencies are returned.
705
- *
706
- * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
707
- * @param schema - The schema for which retrieving a schema is desired
708
- * @param rootSchema - The root schema that will be forwarded to all the APIs
709
- * @param [rawFormData] - The current formData, if any, to assist retrieving a schema
710
- * @param [expandAllBranches=false] - Flag, if true, will return all possible branches of conditions, any/oneOf and
711
- * dependencies as a list of schemas
712
- * @returns - The schema(s) resulting from having its conditions, additional properties, references and dependencies
713
- * resolved. Multiple schemas may be returned if `expandAllBranches` is true.
714
- */
715
451
  function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false) {
716
452
  if (!isObject(schema)) {
717
453
  return [{}];
718
454
  }
719
455
  const resolvedSchemas = resolveSchema(validator, schema, rootSchema, expandAllBranches, rawFormData);
720
- return resolvedSchemas.flatMap(s => {
456
+ return resolvedSchemas.flatMap((s) => {
721
457
  let resolvedSchema = s;
722
458
  if (IF_KEY in resolvedSchema) {
723
459
  return resolveCondition(validator, resolvedSchema, rootSchema, expandAllBranches, rawFormData);
724
460
  }
725
461
  if (ALL_OF_KEY in resolvedSchema) {
726
- // resolve allOf schemas
727
462
  if (expandAllBranches) {
728
- return [...resolvedSchema.allOf];
463
+ const { allOf, ...restOfSchema } = resolvedSchema;
464
+ return [...allOf, restOfSchema];
729
465
  }
730
466
  try {
731
467
  resolvedSchema = mergeAllOf(resolvedSchema, {
732
468
  deep: false
733
469
  });
734
470
  } catch (e) {
735
- console.warn('could not merge subschemas in allOf:\n', e);
736
- const {
737
- allOf,
738
- ...resolvedSchemaWithoutAllOf
739
- } = resolvedSchema;
471
+ console.warn("could not merge subschemas in allOf:\n", e);
472
+ const { allOf, ...resolvedSchemaWithoutAllOf } = resolvedSchema;
740
473
  return resolvedSchemaWithoutAllOf;
741
474
  }
742
475
  }
@@ -747,177 +480,123 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
747
480
  return resolvedSchema;
748
481
  });
749
482
  }
750
- /** Resolves an `anyOf` or `oneOf` within a schema (if present) to the list of schemas returned from
751
- * `retrieveSchemaInternal()` for the best matching option. If `expandAllBranches` is true, then a list of schemas for ALL
752
- * options are retrieved and returned.
753
- *
754
- * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
755
- * @param schema - The schema for which retrieving a schema is desired
756
- * @param rootSchema - The root schema that will be forwarded to all the APIs
757
- * @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
758
- * as a list of schemas
759
- * @param [rawFormData] - The current formData, if any, to assist retrieving a schema, defaults to an empty object
760
- * @returns - Either an array containing the best matching option or all options if `expandAllBranches` is true
761
- */
762
483
  function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranches, rawFormData) {
763
484
  let anyOrOneOf;
764
- const {
765
- oneOf,
766
- anyOf,
767
- ...remaining
768
- } = schema;
485
+ const { oneOf, anyOf, ...remaining } = schema;
769
486
  if (Array.isArray(oneOf)) {
770
487
  anyOrOneOf = oneOf;
771
488
  } else if (Array.isArray(anyOf)) {
772
489
  anyOrOneOf = anyOf;
773
490
  }
774
491
  if (anyOrOneOf) {
775
- // Ensure that during expand all branches we pass an object rather than undefined so that all options are interrogated
776
- const formData = rawFormData === undefined && expandAllBranches ? {} : rawFormData;
492
+ const formData = rawFormData === void 0 && expandAllBranches ? {} : rawFormData;
777
493
  const discriminator = getDiscriminatorFieldFromSchema(schema);
778
- anyOrOneOf = anyOrOneOf.map(s => {
494
+ anyOrOneOf = anyOrOneOf.map((s) => {
779
495
  return resolveAllReferences(s, rootSchema);
780
496
  });
781
- // Call this to trigger the set of isValid() calls that the schema parser will need
782
497
  const option = getFirstMatchingOption(validator, formData, anyOrOneOf, rootSchema, discriminator);
783
498
  if (expandAllBranches) {
784
- return anyOrOneOf.map(item => mergeSchemas(remaining, item));
499
+ return anyOrOneOf.map((item) => mergeSchemas(remaining, item));
785
500
  }
786
501
  schema = mergeSchemas(remaining, anyOrOneOf[option]);
787
502
  }
788
503
  return [schema];
789
504
  }
790
- /** Resolves dependencies within a schema and its 'anyOf/oneOf' children. Passes the `expandAllBranches` flag down to
791
- * the `resolveAnyOrOneOfSchema()` and `processDependencies()` helper calls.
792
- *
793
- * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
794
- * @param schema - The schema for which resolving a dependency is desired
795
- * @param rootSchema - The root schema that will be forwarded to all the APIs
796
- * @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
797
- * as a list of schemas
798
- * @param [formData] - The current formData, if any, to assist retrieving a schema
799
- * @returns - The list of schemas with their dependencies resolved
800
- */
801
505
  function resolveDependencies(validator, schema, rootSchema, expandAllBranches, formData) {
802
- // Drop the dependencies from the source schema.
803
- const {
804
- dependencies,
805
- ...remainingSchema
806
- } = schema;
807
- const resolvedSchemas = resolveAnyOrOneOfSchemas(validator, remainingSchema, rootSchema, expandAllBranches, formData);
808
- return resolvedSchemas.flatMap(resolvedSchema => processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, formData));
809
- }
810
- /** Processes all the `dependencies` recursively into the list of `resolvedSchema`s as needed. Passes the
811
- * `expandAllBranches` flag down to the `withDependentSchema()` and the recursive `processDependencies()` helper calls.
812
- *
813
- * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
814
- * @param dependencies - The set of dependencies that needs to be processed
815
- * @param resolvedSchema - The schema for which processing dependencies is desired
816
- * @param rootSchema - The root schema that will be forwarded to all the APIs
817
- * @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
818
- * as a list of schemas
819
- * @param [formData] - The current formData, if any, to assist retrieving a schema
820
- * @returns - The schema with the `dependencies` resolved into it
821
- */
506
+ const { dependencies, ...remainingSchema } = schema;
507
+ const resolvedSchemas = resolveAnyOrOneOfSchemas(
508
+ validator,
509
+ remainingSchema,
510
+ rootSchema,
511
+ expandAllBranches,
512
+ formData
513
+ );
514
+ return resolvedSchemas.flatMap(
515
+ (resolvedSchema) => processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, formData)
516
+ );
517
+ }
822
518
  function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, formData) {
823
519
  let schemas = [resolvedSchema];
824
- // Process dependencies updating the local schema properties as appropriate.
825
520
  for (const dependencyKey in dependencies) {
826
- // Skip this dependency if its trigger property is not present.
827
- if (!expandAllBranches && get(formData, [dependencyKey]) === undefined) {
521
+ if (!expandAllBranches && get3(formData, [dependencyKey]) === void 0) {
828
522
  continue;
829
523
  }
830
- // Skip this dependency if it is not included in the schema (such as when dependencyKey is itself a hidden dependency.)
831
524
  if (resolvedSchema.properties && !(dependencyKey in resolvedSchema.properties)) {
832
525
  continue;
833
526
  }
834
- const [remainingDependencies, dependencyValue] = splitKeyElementFromObject(dependencyKey, dependencies);
527
+ const [remainingDependencies, dependencyValue] = splitKeyElementFromObject(
528
+ dependencyKey,
529
+ dependencies
530
+ );
835
531
  if (Array.isArray(dependencyValue)) {
836
532
  schemas[0] = withDependentProperties(resolvedSchema, dependencyValue);
837
533
  } else if (isObject(dependencyValue)) {
838
- schemas = withDependentSchema(validator, resolvedSchema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, formData);
534
+ schemas = withDependentSchema(
535
+ validator,
536
+ resolvedSchema,
537
+ rootSchema,
538
+ dependencyKey,
539
+ dependencyValue,
540
+ expandAllBranches,
541
+ formData
542
+ );
839
543
  }
840
- return schemas.flatMap(schema => processDependencies(validator, remainingDependencies, schema, rootSchema, expandAllBranches, formData));
544
+ return schemas.flatMap(
545
+ (schema) => processDependencies(validator, remainingDependencies, schema, rootSchema, expandAllBranches, formData)
546
+ );
841
547
  }
842
548
  return schemas;
843
549
  }
844
- /** Updates a schema with additionally required properties added
845
- *
846
- * @param schema - The schema for which resolving a dependent properties is desired
847
- * @param [additionallyRequired] - An optional array of additionally required names
848
- * @returns - The schema with the additional required values merged in
849
- */
850
550
  function withDependentProperties(schema, additionallyRequired) {
851
551
  if (!additionallyRequired) {
852
552
  return schema;
853
553
  }
854
- const required = Array.isArray(schema.required) ? Array.from(new Set([...schema.required, ...additionallyRequired])) : additionallyRequired;
855
- return {
856
- ...schema,
857
- required: required
858
- };
554
+ const required = Array.isArray(schema.required) ? Array.from(/* @__PURE__ */ new Set([...schema.required, ...additionallyRequired])) : additionallyRequired;
555
+ return { ...schema, required };
859
556
  }
860
- /** Merges a dependent schema into the `schema` dealing with oneOfs and references. Passes the `expandAllBranches` flag
861
- * down to the `retrieveSchemaInternal()`, `resolveReference()` and `withExactlyOneSubschema()` helper calls.
862
- *
863
- * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
864
- * @param schema - The schema for which resolving a dependent schema is desired
865
- * @param rootSchema - The root schema that will be forwarded to all the APIs
866
- * @param dependencyKey - The key name of the dependency
867
- * @param dependencyValue - The potentially dependent schema
868
- * @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
869
- * as a list of schemas
870
- * @param [formData]- The current formData to assist retrieving a schema
871
- * @returns - The list of schemas with the dependent schema resolved into them
872
- */
873
557
  function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, formData) {
874
- const dependentSchemas = retrieveSchemaInternal(validator, dependencyValue, rootSchema, formData, expandAllBranches);
875
- return dependentSchemas.flatMap(dependent => {
876
- const {
877
- oneOf,
878
- ...dependentSchema
879
- } = dependent;
558
+ const dependentSchemas = retrieveSchemaInternal(
559
+ validator,
560
+ dependencyValue,
561
+ rootSchema,
562
+ formData,
563
+ expandAllBranches
564
+ );
565
+ return dependentSchemas.flatMap((dependent) => {
566
+ const { oneOf, ...dependentSchema } = dependent;
880
567
  schema = mergeSchemas(schema, dependentSchema);
881
- // Since it does not contain oneOf, we return the original schema.
882
- if (oneOf === undefined) {
568
+ if (oneOf === void 0) {
883
569
  return schema;
884
570
  }
885
- // Resolve $refs inside oneOf.
886
- const resolvedOneOfs = oneOf.map(subschema => {
887
- if (typeof subschema === 'boolean' || !(REF_KEY in subschema)) {
571
+ const resolvedOneOfs = oneOf.map((subschema) => {
572
+ if (typeof subschema === "boolean" || !(REF_KEY in subschema)) {
888
573
  return [subschema];
889
574
  }
890
575
  return resolveReference(validator, subschema, rootSchema, expandAllBranches, formData);
891
576
  });
892
577
  const allPermutations = getAllPermutationsOfXxxOf(resolvedOneOfs);
893
- return allPermutations.flatMap(resolvedOneOf => withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, resolvedOneOf, expandAllBranches, formData));
578
+ return allPermutations.flatMap(
579
+ (resolvedOneOf) => withExactlyOneSubschema(
580
+ validator,
581
+ schema,
582
+ rootSchema,
583
+ dependencyKey,
584
+ resolvedOneOf,
585
+ expandAllBranches,
586
+ formData
587
+ )
588
+ );
894
589
  });
895
590
  }
896
- /** Returns a list of `schema`s with the best choice from the `oneOf` options merged into it. If `expandAllBranches` is
897
- * true, then a list of schemas for ALL options are retrieved and returned. Passes the `expandAllBranches` flag down to
898
- * the `retrieveSchemaInternal()` helper call.
899
- *
900
- * @param validator - An implementation of the `ValidatorType` interface that will be used to validate oneOf options
901
- * @param schema - The schema for which resolving a oneOf subschema is desired
902
- * @param rootSchema - The root schema that will be forwarded to all the APIs
903
- * @param dependencyKey - The key name of the oneOf dependency
904
- * @param oneOf - The list of schemas representing the oneOf options
905
- * @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
906
- * as a list of schemas
907
- * @param [formData] - The current formData to assist retrieving a schema
908
- * @returns - Either an array containing the best matching option or all options if `expandAllBranches` is true
909
- */
910
591
  function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, formData) {
911
- const validSubschemas = oneOf.filter(subschema => {
912
- if (typeof subschema === 'boolean' || !subschema || !subschema.properties) {
592
+ const validSubschemas = oneOf.filter((subschema) => {
593
+ if (typeof subschema === "boolean" || !subschema || !subschema.properties) {
913
594
  return false;
914
595
  }
915
- const {
916
- [dependencyKey]: conditionPropertySchema
917
- } = subschema.properties;
596
+ const { [dependencyKey]: conditionPropertySchema } = subschema.properties;
918
597
  if (conditionPropertySchema) {
919
598
  const conditionSchema = {
920
- type: 'object',
599
+ type: "object",
921
600
  properties: {
922
601
  [dependencyKey]: conditionPropertySchema
923
602
  }
@@ -930,194 +609,125 @@ function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, o
930
609
  console.warn("ignoring oneOf in dependencies because there isn't exactly one subschema that is valid");
931
610
  return [schema];
932
611
  }
933
- return validSubschemas.flatMap(s => {
612
+ return validSubschemas.flatMap((s) => {
934
613
  const subschema = s;
935
614
  const [dependentSubschema] = splitKeyElementFromObject(dependencyKey, subschema.properties);
936
- const dependentSchema = {
937
- ...subschema,
938
- properties: dependentSubschema
939
- };
940
- const schemas = retrieveSchemaInternal(validator, dependentSchema, rootSchema, formData, expandAllBranches);
941
- return schemas.map(s => mergeSchemas(schema, s));
615
+ const dependentSchema = { ...subschema, properties: dependentSubschema };
616
+ const schemas = retrieveSchemaInternal(
617
+ validator,
618
+ dependentSchema,
619
+ rootSchema,
620
+ formData,
621
+ expandAllBranches
622
+ );
623
+ return schemas.map((s2) => mergeSchemas(schema, s2));
942
624
  });
943
625
  }
944
626
 
945
- /** A junk option used to determine when the getFirstMatchingOption call really matches an option rather than returning
946
- * the first item
947
- */
948
- const JUNK_OPTION = {
949
- type: 'object',
627
+ // src/schema/getClosestMatchingOption.ts
628
+ var JUNK_OPTION = {
629
+ type: "object",
950
630
  $id: JUNK_OPTION_ID,
951
631
  properties: {
952
632
  __not_really_there__: {
953
- type: 'number'
633
+ type: "number"
954
634
  }
955
635
  }
956
636
  };
957
- /** Recursive function that calculates the score of a `formData` against the given `schema`. The computation is fairly
958
- * simple. Initially the total score is 0. When `schema.properties` object exists, then all the `key/value` pairs within
959
- * the object are processed as follows after obtaining the formValue from `formData` using the `key`:
960
- * - If the `value` contains a `$ref`, `calculateIndexScore()` is called recursively with the formValue and the new
961
- * schema that is the result of the ref in the schema being resolved and that sub-schema's resulting score is added to
962
- * the total.
963
- * - If the `value` contains a `oneOf` and there is a formValue, then score based on the index returned from calling
964
- * `getClosestMatchingOption()` of that oneOf.
965
- * - If the type of the `value` is 'object', `calculateIndexScore()` is called recursively with the formValue and the
966
- * `value` itself as the sub-schema, and the score is added to the total.
967
- * - If the type of the `value` matches the guessed-type of the `formValue`, the score is incremented by 1, UNLESS the
968
- * value has a `default` or `const`. In those case, if the `default` or `const` and the `formValue` match, the score
969
- * is incremented by another 1 otherwise it is decremented by 1.
970
- *
971
- * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
972
- * @param rootSchema - The root JSON schema of the entire form
973
- * @param schema - The schema for which the score is being calculated
974
- * @param formData - The form data associated with the schema, used to calculate the score
975
- * @returns - The score a schema against the formData
976
- */
977
637
  function calculateIndexScore(validator, rootSchema, schema, formData = {}) {
978
638
  let totalScore = 0;
979
639
  if (schema) {
980
- if (isObject$1(schema.properties)) {
981
- totalScore += reduce(schema.properties, (score, value, key) => {
982
- const formValue = get(formData, key);
983
- if (typeof value === 'boolean') {
984
- return score;
985
- }
986
- if (has(value, REF_KEY)) {
987
- const newSchema = retrieveSchema(validator, value, rootSchema, formValue);
988
- return score + calculateIndexScore(validator, rootSchema, newSchema, formValue || {});
989
- }
990
- if ((has(value, ONE_OF_KEY) || has(value, ANY_OF_KEY)) && formValue) {
991
- const key = has(value, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
992
- const discriminator = getDiscriminatorFieldFromSchema(value);
993
- return score + getClosestMatchingOption(validator, rootSchema, formValue, get(value, key), -1, discriminator);
994
- }
995
- if (value.type === 'object') {
996
- return score + calculateIndexScore(validator, rootSchema, value, formValue || {});
997
- }
998
- if (value.type === guessType(formValue)) {
999
- // If the types match, then we bump the score by one
1000
- let newScore = score + 1;
1001
- if (value.default) {
1002
- // If the schema contains a readonly default value score the value that matches the default higher and
1003
- // any non-matching value lower
1004
- newScore += formValue === value.default ? 1 : -1;
1005
- } else if (value.const) {
1006
- // If the schema contains a const value score the value that matches the default higher and
1007
- // any non-matching value lower
1008
- newScore += formValue === value.const ? 1 : -1;
640
+ if (isObject2(schema.properties)) {
641
+ totalScore += reduce(
642
+ schema.properties,
643
+ (score, value, key) => {
644
+ const formValue = get4(formData, key);
645
+ if (typeof value === "boolean") {
646
+ return score;
1009
647
  }
1010
- // TODO eventually, deal with enums/arrays
1011
- return newScore;
1012
- }
1013
- return score;
1014
- }, 0);
1015
- } else if (isString(schema.type) && schema.type === guessType(formData)) {
648
+ if (has2(value, REF_KEY)) {
649
+ const newSchema = retrieveSchema(validator, value, rootSchema, formValue);
650
+ return score + calculateIndexScore(validator, rootSchema, newSchema, formValue || {});
651
+ }
652
+ if ((has2(value, ONE_OF_KEY) || has2(value, ANY_OF_KEY)) && formValue) {
653
+ const key2 = has2(value, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
654
+ const discriminator = getDiscriminatorFieldFromSchema(value);
655
+ return score + getClosestMatchingOption(
656
+ validator,
657
+ rootSchema,
658
+ formValue,
659
+ get4(value, key2),
660
+ -1,
661
+ discriminator
662
+ );
663
+ }
664
+ if (value.type === "object") {
665
+ return score + calculateIndexScore(validator, rootSchema, value, formValue || {});
666
+ }
667
+ if (value.type === guessType(formValue)) {
668
+ let newScore = score + 1;
669
+ if (value.default) {
670
+ newScore += formValue === value.default ? 1 : -1;
671
+ } else if (value.const) {
672
+ newScore += formValue === value.const ? 1 : -1;
673
+ }
674
+ return newScore;
675
+ }
676
+ return score;
677
+ },
678
+ 0
679
+ );
680
+ } else if (isString2(schema.type) && schema.type === guessType(formData)) {
1016
681
  totalScore += 1;
1017
682
  }
1018
683
  }
1019
684
  return totalScore;
1020
685
  }
1021
- /** Determines which of the given `options` provided most closely matches the `formData`. Using
1022
- * `getFirstMatchingOption()` to match two schemas that differ only by the readOnly, default or const value of a field
1023
- * based on the `formData` and returns 0 when there is no match. Rather than passing in all the `options` at once to
1024
- * this utility, instead an array of valid option indexes is created by iterating over the list of options, call
1025
- * `getFirstMatchingOptions` with a list of one junk option and one good option, seeing if the good option is considered
1026
- * matched.
1027
- *
1028
- * Once the list of valid indexes is created, if there is only one valid index, just return it. Otherwise, if there are
1029
- * no valid indexes, then fill the valid indexes array with the indexes of all the options. Next, the index of the
1030
- * option with the highest score is determined by iterating over the list of valid options, calling
1031
- * `calculateIndexScore()` on each, comparing it against the current best score, and returning the index of the one that
1032
- * eventually has the best score.
1033
- *
1034
- * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
1035
- * @param rootSchema - The root JSON schema of the entire form
1036
- * @param formData - The form data associated with the schema
1037
- * @param options - The list of options that can be selected from
1038
- * @param [selectedOption=-1] - The index of the currently selected option, defaulted to -1 if not specified
1039
- * @param [discriminatorField] - The optional name of the field within the options object whose value is used to
1040
- * determine which option is selected
1041
- * @returns - The index of the option that is the closest match to the `formData` or the `selectedOption` if no match
1042
- */
1043
686
  function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption = -1, discriminatorField) {
1044
- // First resolve any refs in the options
1045
- const resolvedOptions = options.map(option => {
687
+ const resolvedOptions = options.map((option) => {
1046
688
  return resolveAllReferences(option, rootSchema);
1047
689
  });
1048
- // Reduce the array of options down to a list of the indexes that are considered matching options
1049
690
  const allValidIndexes = resolvedOptions.reduce((validList, option, index) => {
1050
691
  const testOptions = [JUNK_OPTION, option];
1051
692
  const match = getFirstMatchingOption(validator, formData, testOptions, rootSchema, discriminatorField);
1052
- // The match is the real option, so add its index to list of valid indexes
1053
693
  if (match === 1) {
1054
694
  validList.push(index);
1055
695
  }
1056
696
  return validList;
1057
697
  }, []);
1058
- // There is only one valid index, so return it!
1059
698
  if (allValidIndexes.length === 1) {
1060
699
  return allValidIndexes[0];
1061
700
  }
1062
701
  if (!allValidIndexes.length) {
1063
- // No indexes were valid, so we'll score all the options, add all the indexes
1064
- times(resolvedOptions.length, i => allValidIndexes.push(i));
1065
- }
1066
- const scoreCount = new Set();
1067
- // Score all the options in the list of valid indexes and return the index with the best score
1068
- const {
1069
- bestIndex
1070
- } = allValidIndexes.reduce((scoreData, index) => {
1071
- const {
1072
- bestScore
1073
- } = scoreData;
1074
- const option = resolvedOptions[index];
1075
- const score = calculateIndexScore(validator, rootSchema, option, formData);
1076
- scoreCount.add(score);
1077
- if (score > bestScore) {
1078
- return {
1079
- bestIndex: index,
1080
- bestScore: score
1081
- };
1082
- }
1083
- return scoreData;
1084
- }, {
1085
- bestIndex: selectedOption,
1086
- bestScore: 0
1087
- });
1088
- // if all scores are the same go with selectedOption
702
+ times2(resolvedOptions.length, (i) => allValidIndexes.push(i));
703
+ }
704
+ const scoreCount = /* @__PURE__ */ new Set();
705
+ const { bestIndex } = allValidIndexes.reduce(
706
+ (scoreData, index) => {
707
+ const { bestScore } = scoreData;
708
+ const option = resolvedOptions[index];
709
+ const score = calculateIndexScore(validator, rootSchema, option, formData);
710
+ scoreCount.add(score);
711
+ if (score > bestScore) {
712
+ return { bestIndex: index, bestScore: score };
713
+ }
714
+ return scoreData;
715
+ },
716
+ { bestIndex: selectedOption, bestScore: 0 }
717
+ );
1089
718
  if (scoreCount.size === 1 && selectedOption >= 0) {
1090
719
  return selectedOption;
1091
720
  }
1092
721
  return bestIndex;
1093
722
  }
1094
723
 
1095
- /** Detects whether the given `schema` contains fixed items. This is the case when `schema.items` is a non-empty array
1096
- * that only contains objects.
1097
- *
1098
- * @param schema - The schema in which to check for fixed items
1099
- * @returns - True if there are fixed items in the schema, false otherwise
1100
- */
724
+ // src/isFixedItems.ts
1101
725
  function isFixedItems(schema) {
1102
- return Array.isArray(schema.items) && schema.items.length > 0 && schema.items.every(item => isObject(item));
1103
- }
1104
-
1105
- /** Merges the `defaults` object of type `T` into the `formData` of type `T`
1106
- *
1107
- * When merging defaults and form data, we want to merge in this specific way:
1108
- * - objects are deeply merged
1109
- * - arrays are merged in such a way that:
1110
- * - when the array is set in form data, only array entries set in form data
1111
- * are deeply merged; additional entries from the defaults are ignored unless `mergeExtraArrayDefaults` is true, in
1112
- * which case the extras are appended onto the end of the form data
1113
- * - when the array is not set in form data, the default is copied over
1114
- * - scalars are overwritten/set by form data
1115
- *
1116
- * @param [defaults] - The defaults to merge
1117
- * @param [formData] - The form data into which the defaults will be merged
1118
- * @param [mergeExtraArrayDefaults=false] - If true, any additional default array entries are appended onto the formData
1119
- * @returns - The resulting merged form data with defaults
1120
- */
726
+ return Array.isArray(schema.items) && schema.items.length > 0 && schema.items.every((item) => isObject(item));
727
+ }
728
+
729
+ // src/mergeDefaultsWithFormData.ts
730
+ import get5 from "lodash/get";
1121
731
  function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults = false) {
1122
732
  if (Array.isArray(formData)) {
1123
733
  const defaultsArray = Array.isArray(defaults) ? defaults : [];
@@ -1127,40 +737,34 @@ function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults =
1127
737
  }
1128
738
  return value;
1129
739
  });
1130
- // Merge any extra defaults when mergeExtraArrayDefaults is true
1131
740
  if (mergeExtraArrayDefaults && mapped.length < defaultsArray.length) {
1132
741
  mapped.push(...defaultsArray.slice(mapped.length));
1133
742
  }
1134
743
  return mapped;
1135
744
  }
1136
745
  if (isObject(formData)) {
1137
- const acc = Object.assign({}, defaults); // Prevent mutation of source object.
1138
- return Object.keys(formData).reduce((acc, key) => {
1139
- acc[key] = mergeDefaultsWithFormData(defaults ? get(defaults, key) : {}, get(formData, key), mergeExtraArrayDefaults);
1140
- return acc;
746
+ const acc = Object.assign({}, defaults);
747
+ return Object.keys(formData).reduce((acc2, key) => {
748
+ acc2[key] = mergeDefaultsWithFormData(
749
+ defaults ? get5(defaults, key) : {},
750
+ get5(formData, key),
751
+ mergeExtraArrayDefaults
752
+ );
753
+ return acc2;
1141
754
  }, acc);
1142
755
  }
1143
756
  return formData;
1144
757
  }
1145
758
 
1146
- /** Recursively merge deeply nested objects.
1147
- *
1148
- * @param obj1 - The first object to merge
1149
- * @param obj2 - The second object to merge
1150
- * @param [concatArrays=false] - Optional flag that, when true, will cause arrays to be concatenated. Use
1151
- * "preventDuplicates" to merge arrays in a manner that prevents any duplicate entries from being merged.
1152
- * NOTE: Uses shallow comparison for the duplicate checking.
1153
- * @returns - A new object that is the merge of the two given objects
1154
- */
759
+ // src/mergeObjects.ts
1155
760
  function mergeObjects(obj1, obj2, concatArrays = false) {
1156
761
  return Object.keys(obj2).reduce((acc, key) => {
1157
- const left = obj1 ? obj1[key] : {},
1158
- right = obj2[key];
762
+ const left = obj1 ? obj1[key] : {}, right = obj2[key];
1159
763
  if (obj1 && key in obj1 && isObject(right)) {
1160
764
  acc[key] = mergeObjects(left, right, concatArrays);
1161
765
  } else if (concatArrays && Array.isArray(left) && Array.isArray(right)) {
1162
766
  let toMerge = right;
1163
- if (concatArrays === 'preventDuplicates') {
767
+ if (concatArrays === "preventDuplicates") {
1164
768
  toMerge = right.reduce((result, value) => {
1165
769
  if (!left.includes(value)) {
1166
770
  result.push(value);
@@ -1173,216 +777,140 @@ function mergeObjects(obj1, obj2, concatArrays = false) {
1173
777
  acc[key] = right;
1174
778
  }
1175
779
  return acc;
1176
- }, Object.assign({}, obj1)); // Prevent mutation of source object.
780
+ }, Object.assign({}, obj1));
1177
781
  }
1178
782
 
1179
- /** This function checks if the given `schema` matches a single constant value. This happens when either the schema has
1180
- * an `enum` array with a single value or there is a `const` defined.
1181
- *
1182
- * @param schema - The schema for a field
1183
- * @returns - True if the `schema` has a single constant value, false otherwise
1184
- */
783
+ // src/isConstant.ts
1185
784
  function isConstant(schema) {
1186
785
  return Array.isArray(schema.enum) && schema.enum.length === 1 || CONST_KEY in schema;
1187
786
  }
1188
787
 
1189
- /** Checks to see if the `schema` combination represents a select
1190
- *
1191
- * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
1192
- * @param theSchema - The schema for which check for a select flag is desired
1193
- * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
1194
- * @returns - True if schema contains a select, otherwise false
1195
- */
788
+ // src/schema/isSelect.ts
1196
789
  function isSelect(validator, theSchema, rootSchema = {}) {
1197
- const schema = retrieveSchema(validator, theSchema, rootSchema, undefined);
790
+ const schema = retrieveSchema(validator, theSchema, rootSchema, void 0);
1198
791
  const altSchemas = schema.oneOf || schema.anyOf;
1199
792
  if (Array.isArray(schema.enum)) {
1200
793
  return true;
1201
794
  }
1202
795
  if (Array.isArray(altSchemas)) {
1203
- return altSchemas.every(altSchemas => typeof altSchemas !== 'boolean' && isConstant(altSchemas));
796
+ return altSchemas.every((altSchemas2) => typeof altSchemas2 !== "boolean" && isConstant(altSchemas2));
1204
797
  }
1205
798
  return false;
1206
799
  }
1207
800
 
1208
- /** Checks to see if the `schema` combination represents a multi-select
1209
- *
1210
- * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
1211
- * @param schema - The schema for which check for a multi-select flag is desired
1212
- * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
1213
- * @returns - True if schema contains a multi-select, otherwise false
1214
- */
801
+ // src/schema/isMultiSelect.ts
1215
802
  function isMultiSelect(validator, schema, rootSchema) {
1216
- if (!schema.uniqueItems || !schema.items || typeof schema.items === 'boolean') {
803
+ if (!schema.uniqueItems || !schema.items || typeof schema.items === "boolean") {
1217
804
  return false;
1218
805
  }
1219
806
  return isSelect(validator, schema.items, rootSchema);
1220
807
  }
1221
808
 
1222
- /** Enum that indicates how `schema.additionalItems` should be handled by the `getInnerSchemaForArrayItem()` function.
1223
- */
1224
- var AdditionalItemsHandling;
1225
- (function (AdditionalItemsHandling) {
1226
- AdditionalItemsHandling[AdditionalItemsHandling["Ignore"] = 0] = "Ignore";
1227
- AdditionalItemsHandling[AdditionalItemsHandling["Invert"] = 1] = "Invert";
1228
- AdditionalItemsHandling[AdditionalItemsHandling["Fallback"] = 2] = "Fallback";
1229
- })(AdditionalItemsHandling || (AdditionalItemsHandling = {}));
1230
- /** Given a `schema` will return an inner schema that for an array item. This is computed differently based on the
1231
- * `additionalItems` enum and the value of `idx`. There are four possible returns:
1232
- * 1. If `idx` is >= 0, then if `schema.items` is an array the `idx`th element of the array is returned if it is a valid
1233
- * index and not a boolean, otherwise it falls through to 3.
1234
- * 2. If `schema.items` is not an array AND truthy and not a boolean, then `schema.items` is returned since it actually
1235
- * is a schema, otherwise it falls through to 3.
1236
- * 3. If `additionalItems` is not `AdditionalItemsHandling.Ignore` and `schema.additionalItems` is an object, then
1237
- * `schema.additionalItems` is returned since it actually is a schema, otherwise it falls through to 4.
1238
- * 4. {} is returned representing an empty schema
1239
- *
1240
- * @param schema - The schema from which to get the particular item
1241
- * @param [additionalItems=AdditionalItemsHandling.Ignore] - How do we want to handle additional items?
1242
- * @param [idx=-1] - Index, if non-negative, will be used to return the idx-th element in a `schema.items` array
1243
- * @returns - The best fit schema object from the `schema` given the `additionalItems` and `idx` modifiers
1244
- */
1245
- function getInnerSchemaForArrayItem(schema, additionalItems = AdditionalItemsHandling.Ignore, idx = -1) {
809
+ // src/schema/getDefaultFormState.ts
810
+ function getInnerSchemaForArrayItem(schema, additionalItems = 0 /* Ignore */, idx = -1) {
1246
811
  if (idx >= 0) {
1247
812
  if (Array.isArray(schema.items) && idx < schema.items.length) {
1248
813
  const item = schema.items[idx];
1249
- if (typeof item !== 'boolean') {
814
+ if (typeof item !== "boolean") {
1250
815
  return item;
1251
816
  }
1252
817
  }
1253
- } else if (schema.items && !Array.isArray(schema.items) && typeof schema.items !== 'boolean') {
818
+ } else if (schema.items && !Array.isArray(schema.items) && typeof schema.items !== "boolean") {
1254
819
  return schema.items;
1255
820
  }
1256
- if (additionalItems !== AdditionalItemsHandling.Ignore && isObject(schema.additionalItems)) {
821
+ if (additionalItems !== 0 /* Ignore */ && isObject(schema.additionalItems)) {
1257
822
  return schema.additionalItems;
1258
823
  }
1259
824
  return {};
1260
825
  }
1261
- /** Either add `computedDefault` at `key` into `obj` or not add it based on its value, the value of
1262
- * `includeUndefinedValues`, the value of `emptyObjectFields` and if its parent field is required. Generally undefined
1263
- * `computedDefault` values are added only when `includeUndefinedValues` is either true/"excludeObjectChildren". If `
1264
- * includeUndefinedValues` is false and `emptyObjectFields` is not "skipDefaults", then non-undefined and non-empty-object
1265
- * values will be added based on certain conditions.
1266
- *
1267
- * @param obj - The object into which the computed default may be added
1268
- * @param key - The key into the object at which the computed default may be added
1269
- * @param computedDefault - The computed default value that maybe should be added to the obj
1270
- * @param includeUndefinedValues - Optional flag, if true, cause undefined values to be added as defaults.
1271
- * If "excludeObjectChildren", cause undefined values for this object and pass `includeUndefinedValues` as
1272
- * false when computing defaults for any nested object properties. If "allowEmptyObject", prevents undefined
1273
- * values in this object while allow the object itself to be empty and passing `includeUndefinedValues` as
1274
- * false when computing defaults for any nested object properties.
1275
- * @param isParentRequired - The optional boolean that indicates whether the parent field is required
1276
- * @param requiredFields - The list of fields that are required
1277
- * @param experimental_defaultFormStateBehavior - Optional configuration object, if provided, allows users to override
1278
- * default form state behavior
1279
- */
1280
826
  function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields = [], experimental_defaultFormStateBehavior = {}) {
1281
- const {
1282
- emptyObjectFields = 'populateAllDefaults'
1283
- } = experimental_defaultFormStateBehavior;
827
+ const { emptyObjectFields = "populateAllDefaults" } = experimental_defaultFormStateBehavior;
1284
828
  if (includeUndefinedValues) {
1285
829
  obj[key] = computedDefault;
1286
- } else if (emptyObjectFields !== 'skipDefaults') {
830
+ } else if (emptyObjectFields !== "skipDefaults") {
1287
831
  if (isObject(computedDefault)) {
1288
- // If isParentRequired is undefined, then we are at the root level of the schema so defer to the requiredness of
1289
- // the field key itself in the `requiredField` list
1290
- const isSelfOrParentRequired = isParentRequired === undefined ? requiredFields.includes(key) : isParentRequired;
1291
- // Store computedDefault if it's a non-empty object(e.g. not {}) and satisfies certain conditions
1292
- // Condition 1: If computedDefault is not empty or if the key is a required field
1293
- // Condition 2: If the parent object is required or emptyObjectFields is not 'populateRequiredDefaults'
1294
- if ((!isEmpty(computedDefault) || requiredFields.includes(key)) && (isSelfOrParentRequired || emptyObjectFields !== 'populateRequiredDefaults')) {
832
+ const isSelfOrParentRequired = isParentRequired === void 0 ? requiredFields.includes(key) : isParentRequired;
833
+ if ((!isEmpty(computedDefault) || requiredFields.includes(key)) && (isSelfOrParentRequired || emptyObjectFields !== "populateRequiredDefaults")) {
1295
834
  obj[key] = computedDefault;
1296
835
  }
1297
836
  } else if (
1298
- // Store computedDefault if it's a defined primitive (e.g., true) and satisfies certain conditions
1299
- // Condition 1: computedDefault is not undefined
1300
- // Condition 2: If emptyObjectFields is 'populateAllDefaults' or if the key is a required field
1301
- computedDefault !== undefined && (emptyObjectFields === 'populateAllDefaults' || requiredFields.includes(key))) {
837
+ // Store computedDefault if it's a defined primitive (e.g., true) and satisfies certain conditions
838
+ // Condition 1: computedDefault is not undefined
839
+ // Condition 2: If emptyObjectFields is 'populateAllDefaults' or if the key is a required field
840
+ computedDefault !== void 0 && (emptyObjectFields === "populateAllDefaults" || requiredFields.includes(key))
841
+ ) {
1302
842
  obj[key] = computedDefault;
1303
843
  }
1304
844
  }
1305
845
  }
1306
- /** Computes the defaults for the current `schema` given the `rawFormData` and `parentDefaults` if any. This drills into
1307
- * each level of the schema, recursively, to fill out every level of defaults provided by the schema.
1308
- *
1309
- * @param validator - an implementation of the `ValidatorType` interface that will be used when necessary
1310
- * @param rawSchema - The schema for which the default state is desired
1311
- * @param [props] - Optional props for this function
1312
- * @param [props.parentDefaults] - Any defaults provided by the parent field in the schema
1313
- * @param [props.rootSchema] - The options root schema, used to primarily to look up `$ref`s
1314
- * @param [props.rawFormData] - The current formData, if any, onto which to provide any missing defaults
1315
- * @param [props.includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
1316
- * If "excludeObjectChildren", cause undefined values for this object and pass `includeUndefinedValues` as
1317
- * false when computing defaults for any nested object properties.
1318
- * @param [props._recurseList=[]] - The list of ref names currently being recursed, used to prevent infinite recursion
1319
- * @param [props.experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
1320
- * @param [props.required] - Optional flag, if true, indicates this schema was required in the parent schema.
1321
- * @returns - The resulting `formData` with all the defaults provided
1322
- */
1323
846
  function computeDefaults(validator, rawSchema, {
1324
847
  parentDefaults,
1325
848
  rawFormData,
1326
849
  rootSchema = {},
1327
850
  includeUndefinedValues = false,
1328
851
  _recurseList = [],
1329
- experimental_defaultFormStateBehavior = undefined,
852
+ experimental_defaultFormStateBehavior = void 0,
1330
853
  required
1331
854
  } = {}) {
1332
855
  const formData = isObject(rawFormData) ? rawFormData : {};
1333
856
  const schema = isObject(rawSchema) ? rawSchema : {};
1334
- // Compute the defaults recursively: give highest priority to deepest nodes.
1335
857
  let defaults = parentDefaults;
1336
- // If we get a new schema, then we need to recompute defaults again for the new schema found.
1337
858
  let schemaToCompute = null;
1338
859
  let updatedRecurseList = _recurseList;
1339
860
  if (isObject(defaults) && isObject(schema.default)) {
1340
- // For object defaults, only override parent defaults that are defined in
1341
- // schema.default.
1342
861
  defaults = mergeObjects(defaults, schema.default);
1343
862
  } else if (DEFAULT_KEY in schema) {
1344
863
  defaults = schema.default;
1345
864
  } else if (REF_KEY in schema) {
1346
865
  const refName = schema[REF_KEY];
1347
- // Use referenced schema defaults for this node.
1348
866
  if (!_recurseList.includes(refName)) {
1349
867
  updatedRecurseList = _recurseList.concat(refName);
1350
868
  schemaToCompute = findSchemaDefinition(refName, rootSchema);
1351
869
  }
1352
870
  } else if (DEPENDENCIES_KEY in schema) {
1353
871
  const resolvedSchema = resolveDependencies(validator, schema, rootSchema, false, formData);
1354
- schemaToCompute = resolvedSchema[0]; // pick the first element from resolve dependencies
872
+ schemaToCompute = resolvedSchema[0];
1355
873
  } else if (isFixedItems(schema)) {
1356
- defaults = schema.items.map((itemSchema, idx) => computeDefaults(validator, itemSchema, {
1357
- rootSchema,
1358
- includeUndefinedValues,
1359
- _recurseList,
1360
- experimental_defaultFormStateBehavior,
1361
- parentDefaults: Array.isArray(parentDefaults) ? parentDefaults[idx] : undefined,
1362
- rawFormData: formData,
1363
- required
1364
- }));
874
+ defaults = schema.items.map(
875
+ (itemSchema, idx) => computeDefaults(validator, itemSchema, {
876
+ rootSchema,
877
+ includeUndefinedValues,
878
+ _recurseList,
879
+ experimental_defaultFormStateBehavior,
880
+ parentDefaults: Array.isArray(parentDefaults) ? parentDefaults[idx] : void 0,
881
+ rawFormData: formData,
882
+ required
883
+ })
884
+ );
1365
885
  } else if (ONE_OF_KEY in schema) {
1366
- const {
1367
- oneOf,
1368
- ...remaining
1369
- } = schema;
886
+ const { oneOf, ...remaining } = schema;
1370
887
  if (oneOf.length === 0) {
1371
- return undefined;
888
+ return void 0;
1372
889
  }
1373
890
  const discriminator = getDiscriminatorFieldFromSchema(schema);
1374
- schemaToCompute = oneOf[getClosestMatchingOption(validator, rootSchema, isEmpty(formData) ? undefined : formData, oneOf, 0, discriminator)];
891
+ schemaToCompute = oneOf[getClosestMatchingOption(
892
+ validator,
893
+ rootSchema,
894
+ isEmpty(formData) ? void 0 : formData,
895
+ oneOf,
896
+ 0,
897
+ discriminator
898
+ )];
1375
899
  schemaToCompute = mergeSchemas(remaining, schemaToCompute);
1376
900
  } else if (ANY_OF_KEY in schema) {
1377
- const {
1378
- anyOf,
1379
- ...remaining
1380
- } = schema;
901
+ const { anyOf, ...remaining } = schema;
1381
902
  if (anyOf.length === 0) {
1382
- return undefined;
903
+ return void 0;
1383
904
  }
1384
905
  const discriminator = getDiscriminatorFieldFromSchema(schema);
1385
- schemaToCompute = anyOf[getClosestMatchingOption(validator, rootSchema, isEmpty(formData) ? undefined : formData, anyOf, 0, discriminator)];
906
+ schemaToCompute = anyOf[getClosestMatchingOption(
907
+ validator,
908
+ rootSchema,
909
+ isEmpty(formData) ? void 0 : formData,
910
+ anyOf,
911
+ 0,
912
+ discriminator
913
+ )];
1386
914
  schemaToCompute = mergeSchemas(remaining, schemaToCompute);
1387
915
  }
1388
916
  if (schemaToCompute) {
@@ -1396,135 +924,130 @@ function computeDefaults(validator, rawSchema, {
1396
924
  required
1397
925
  });
1398
926
  }
1399
- // No defaults defined for this node, fallback to generic typed ones.
1400
- if (defaults === undefined) {
927
+ if (defaults === void 0) {
1401
928
  defaults = schema.default;
1402
929
  }
1403
930
  switch (getSchemaType(schema)) {
1404
- // We need to recurse for object schema inner default values.
1405
- case 'object':
1406
- {
1407
- const objectDefaults = Object.keys(schema.properties || {}).reduce((acc, key) => {
1408
- var _schema$required;
1409
- // Compute the defaults for this node, with the parent defaults we might
1410
- // have from a previous run: defaults[key].
1411
- const computedDefault = computeDefaults(validator, get(schema, [PROPERTIES_KEY, key]), {
931
+ case "object": {
932
+ const objectDefaults = Object.keys(schema.properties || {}).reduce((acc, key) => {
933
+ const computedDefault = computeDefaults(validator, get6(schema, [PROPERTIES_KEY, key]), {
934
+ rootSchema,
935
+ _recurseList,
936
+ experimental_defaultFormStateBehavior,
937
+ includeUndefinedValues: includeUndefinedValues === true,
938
+ parentDefaults: get6(defaults, [key]),
939
+ rawFormData: get6(formData, [key]),
940
+ required: schema.required?.includes(key)
941
+ });
942
+ maybeAddDefaultToObject(
943
+ acc,
944
+ key,
945
+ computedDefault,
946
+ includeUndefinedValues,
947
+ required,
948
+ schema.required,
949
+ experimental_defaultFormStateBehavior
950
+ );
951
+ return acc;
952
+ }, {});
953
+ if (schema.additionalProperties) {
954
+ const additionalPropertiesSchema = isObject(schema.additionalProperties) ? schema.additionalProperties : {};
955
+ const keys = /* @__PURE__ */ new Set();
956
+ if (isObject(defaults)) {
957
+ Object.keys(defaults).filter((key) => !schema.properties || !schema.properties[key]).forEach((key) => keys.add(key));
958
+ }
959
+ let formDataRequired;
960
+ if (isObject(formData)) {
961
+ formDataRequired = [];
962
+ Object.keys(formData).filter((key) => !schema.properties || !schema.properties[key]).forEach((key) => {
963
+ keys.add(key);
964
+ formDataRequired.push(key);
965
+ });
966
+ }
967
+ keys.forEach((key) => {
968
+ const computedDefault = computeDefaults(validator, additionalPropertiesSchema, {
1412
969
  rootSchema,
1413
970
  _recurseList,
1414
971
  experimental_defaultFormStateBehavior,
1415
972
  includeUndefinedValues: includeUndefinedValues === true,
1416
- parentDefaults: get(defaults, [key]),
1417
- rawFormData: get(formData, [key]),
1418
- required: (_schema$required = schema.required) === null || _schema$required === void 0 ? void 0 : _schema$required.includes(key)
1419
- });
1420
- maybeAddDefaultToObject(acc, key, computedDefault, includeUndefinedValues, required, schema.required, experimental_defaultFormStateBehavior);
1421
- return acc;
1422
- }, {});
1423
- if (schema.additionalProperties) {
1424
- // as per spec additionalProperties may be either schema or boolean
1425
- const additionalPropertiesSchema = isObject(schema.additionalProperties) ? schema.additionalProperties : {};
1426
- const keys = new Set();
1427
- if (isObject(defaults)) {
1428
- Object.keys(defaults).filter(key => !schema.properties || !schema.properties[key]).forEach(key => keys.add(key));
1429
- }
1430
- let formDataRequired;
1431
- if (isObject(formData)) {
1432
- formDataRequired = [];
1433
- Object.keys(formData).filter(key => !schema.properties || !schema.properties[key]).forEach(key => {
1434
- keys.add(key);
1435
- formDataRequired.push(key);
1436
- });
1437
- }
1438
- keys.forEach(key => {
1439
- var _schema$required2;
1440
- const computedDefault = computeDefaults(validator, additionalPropertiesSchema, {
1441
- rootSchema,
1442
- _recurseList,
1443
- experimental_defaultFormStateBehavior,
1444
- includeUndefinedValues: includeUndefinedValues === true,
1445
- parentDefaults: get(defaults, [key]),
1446
- rawFormData: get(formData, [key]),
1447
- required: (_schema$required2 = schema.required) === null || _schema$required2 === void 0 ? void 0 : _schema$required2.includes(key)
1448
- });
1449
- // Since these are additional properties we don’t need to add the `experimental_defaultFormStateBehavior` prop
1450
- maybeAddDefaultToObject(objectDefaults, key, computedDefault, includeUndefinedValues, required, formDataRequired);
973
+ parentDefaults: get6(defaults, [key]),
974
+ rawFormData: get6(formData, [key]),
975
+ required: schema.required?.includes(key)
1451
976
  });
1452
- }
1453
- return objectDefaults;
977
+ maybeAddDefaultToObject(
978
+ objectDefaults,
979
+ key,
980
+ computedDefault,
981
+ includeUndefinedValues,
982
+ required,
983
+ formDataRequired
984
+ );
985
+ });
1454
986
  }
1455
- case 'array':
1456
- {
1457
- var _experimental_default;
1458
- // Inject defaults into existing array defaults
1459
- if (Array.isArray(defaults)) {
1460
- defaults = defaults.map((item, idx) => {
1461
- const schemaItem = getInnerSchemaForArrayItem(schema, AdditionalItemsHandling.Fallback, idx);
1462
- return computeDefaults(validator, schemaItem, {
1463
- rootSchema,
1464
- _recurseList,
1465
- experimental_defaultFormStateBehavior,
1466
- parentDefaults: item,
1467
- required
1468
- });
987
+ return objectDefaults;
988
+ }
989
+ case "array": {
990
+ const neverPopulate = experimental_defaultFormStateBehavior?.arrayMinItems?.populate === "never";
991
+ const ignoreMinItemsFlagSet = experimental_defaultFormStateBehavior?.arrayMinItems?.populate === "requiredOnly";
992
+ if (Array.isArray(defaults)) {
993
+ defaults = defaults.map((item, idx) => {
994
+ const schemaItem = getInnerSchemaForArrayItem(schema, 2 /* Fallback */, idx);
995
+ return computeDefaults(validator, schemaItem, {
996
+ rootSchema,
997
+ _recurseList,
998
+ experimental_defaultFormStateBehavior,
999
+ parentDefaults: item,
1000
+ required
1469
1001
  });
1470
- }
1471
- // Deeply inject defaults into already existing form data
1472
- if (Array.isArray(rawFormData)) {
1473
- const schemaItem = getInnerSchemaForArrayItem(schema);
1002
+ });
1003
+ }
1004
+ if (Array.isArray(rawFormData)) {
1005
+ const schemaItem = getInnerSchemaForArrayItem(schema);
1006
+ if (neverPopulate) {
1007
+ defaults = rawFormData;
1008
+ } else {
1474
1009
  defaults = rawFormData.map((item, idx) => {
1475
1010
  return computeDefaults(validator, schemaItem, {
1476
1011
  rootSchema,
1477
1012
  _recurseList,
1478
1013
  experimental_defaultFormStateBehavior,
1479
1014
  rawFormData: item,
1480
- parentDefaults: get(defaults, [idx]),
1015
+ parentDefaults: get6(defaults, [idx]),
1481
1016
  required
1482
1017
  });
1483
1018
  });
1484
1019
  }
1485
- const ignoreMinItemsFlagSet = (experimental_defaultFormStateBehavior === null || experimental_defaultFormStateBehavior === void 0 ? void 0 : (_experimental_default = experimental_defaultFormStateBehavior.arrayMinItems) === null || _experimental_default === void 0 ? void 0 : _experimental_default.populate) === 'requiredOnly';
1486
- if (ignoreMinItemsFlagSet && !required) {
1487
- // If no form data exists or defaults are set leave the field empty/non-existent, otherwise
1488
- // return form data/defaults
1489
- return defaults ? defaults : undefined;
1490
- }
1491
- const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
1492
- if (!schema.minItems || isMultiSelect(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
1493
- return defaults ? defaults : [];
1494
- }
1495
- const defaultEntries = defaults || [];
1496
- const fillerSchema = getInnerSchemaForArrayItem(schema, AdditionalItemsHandling.Invert);
1497
- const fillerDefault = fillerSchema.default;
1498
- // Calculate filler entries for remaining items (minItems - existing raw data/defaults)
1499
- const fillerEntries = new Array(schema.minItems - defaultsLength).fill(computeDefaults(validator, fillerSchema, {
1020
+ }
1021
+ if (neverPopulate) {
1022
+ return defaults ?? [];
1023
+ }
1024
+ if (ignoreMinItemsFlagSet && !required) {
1025
+ return defaults ? defaults : void 0;
1026
+ }
1027
+ const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
1028
+ if (!schema.minItems || isMultiSelect(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
1029
+ return defaults ? defaults : [];
1030
+ }
1031
+ const defaultEntries = defaults || [];
1032
+ const fillerSchema = getInnerSchemaForArrayItem(schema, 1 /* Invert */);
1033
+ const fillerDefault = fillerSchema.default;
1034
+ const fillerEntries = new Array(schema.minItems - defaultsLength).fill(
1035
+ computeDefaults(validator, fillerSchema, {
1500
1036
  parentDefaults: fillerDefault,
1501
1037
  rootSchema,
1502
1038
  _recurseList,
1503
1039
  experimental_defaultFormStateBehavior,
1504
1040
  required
1505
- }));
1506
- // then fill up the rest with either the item default or empty, up to minItems
1507
- return defaultEntries.concat(fillerEntries);
1508
- }
1041
+ })
1042
+ );
1043
+ return defaultEntries.concat(fillerEntries);
1044
+ }
1509
1045
  }
1510
1046
  return defaults;
1511
1047
  }
1512
- /** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
1513
- * computed to have defaults provided in the `schema`.
1514
- *
1515
- * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
1516
- * @param theSchema - The schema for which the default state is desired
1517
- * @param [formData] - The current formData, if any, onto which to provide any missing defaults
1518
- * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
1519
- * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
1520
- * If "excludeObjectChildren", cause undefined values for this object and pass `includeUndefinedValues` as
1521
- * false when computing defaults for any nested object properties.
1522
- * @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
1523
- * @returns - The resulting `formData` with all the defaults provided
1524
- */
1525
1048
  function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues = false, experimental_defaultFormStateBehavior) {
1526
1049
  if (!isObject(theSchema)) {
1527
- throw new Error('Invalid schema: ' + theSchema);
1050
+ throw new Error("Invalid schema: " + theSchema);
1528
1051
  }
1529
1052
  const schema = retrieveSchema(validator, theSchema, rootSchema, formData);
1530
1053
  const defaults = computeDefaults(validator, schema, {
@@ -1533,13 +1056,10 @@ function getDefaultFormState(validator, theSchema, formData, rootSchema, include
1533
1056
  experimental_defaultFormStateBehavior,
1534
1057
  rawFormData: formData
1535
1058
  });
1536
- if (formData === undefined || formData === null || typeof formData === 'number' && isNaN(formData)) {
1537
- // No form data? Use schema defaults.
1059
+ if (formData === void 0 || formData === null || typeof formData === "number" && isNaN(formData)) {
1538
1060
  return defaults;
1539
1061
  }
1540
- const {
1541
- mergeExtraDefaults
1542
- } = (experimental_defaultFormStateBehavior === null || experimental_defaultFormStateBehavior === void 0 ? void 0 : experimental_defaultFormStateBehavior.arrayMinItems) || {};
1062
+ const { mergeExtraDefaults } = experimental_defaultFormStateBehavior?.arrayMinItems || {};
1543
1063
  if (isObject(formData)) {
1544
1064
  return mergeDefaultsWithFormData(defaults, formData, mergeExtraDefaults);
1545
1065
  }
@@ -1549,62 +1069,40 @@ function getDefaultFormState(validator, theSchema, formData, rootSchema, include
1549
1069
  return formData;
1550
1070
  }
1551
1071
 
1552
- /** Checks to see if the `uiSchema` contains the `widget` field and that the widget is not `hidden`
1553
- *
1554
- * @param uiSchema - The UI Schema from which to detect if it is customized
1555
- * @returns - True if the `uiSchema` describes a custom widget, false otherwise
1556
- */
1072
+ // src/isCustomWidget.ts
1557
1073
  function isCustomWidget(uiSchema = {}) {
1558
1074
  return (
1559
1075
  // TODO: Remove the `&& uiSchema['ui:widget'] !== 'hidden'` once we support hidden widgets for arrays.
1560
1076
  // https://rjsf-team.github.io/react-jsonschema-form/docs/usage/widgets/#hidden-widgets
1561
- 'widget' in getUiOptions(uiSchema) && getUiOptions(uiSchema)['widget'] !== 'hidden'
1077
+ "widget" in getUiOptions(uiSchema) && getUiOptions(uiSchema)["widget"] !== "hidden"
1562
1078
  );
1563
1079
  }
1564
1080
 
1565
- /** Checks to see if the `schema` and `uiSchema` combination represents an array of files
1566
- *
1567
- * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
1568
- * @param schema - The schema for which check for array of files flag is desired
1569
- * @param [uiSchema={}] - The UI schema from which to check the widget
1570
- * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
1571
- * @returns - True if schema/uiSchema contains an array of files, otherwise false
1572
- */
1081
+ // src/schema/isFilesArray.ts
1573
1082
  function isFilesArray(validator, schema, uiSchema = {}, rootSchema) {
1574
- if (uiSchema[UI_WIDGET_KEY] === 'files') {
1083
+ if (uiSchema[UI_WIDGET_KEY] === "files") {
1575
1084
  return true;
1576
1085
  }
1577
1086
  if (schema.items) {
1578
1087
  const itemsSchema = retrieveSchema(validator, schema.items, rootSchema);
1579
- return itemsSchema.type === 'string' && itemsSchema.format === 'data-url';
1088
+ return itemsSchema.type === "string" && itemsSchema.format === "data-url";
1580
1089
  }
1581
1090
  return false;
1582
1091
  }
1583
1092
 
1584
- /** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
1585
- * should be displayed in a UI.
1586
- *
1587
- * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
1588
- * @param schema - The schema for which the display label flag is desired
1589
- * @param [uiSchema={}] - The UI schema from which to derive potentially displayable information
1590
- * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
1591
- * @param [globalOptions={}] - The optional Global UI Schema from which to get any fallback `xxx` options
1592
- * @returns - True if the label should be displayed or false if it should not
1593
- */
1093
+ // src/schema/getDisplayLabel.ts
1594
1094
  function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOptions) {
1595
1095
  const uiOptions = getUiOptions(uiSchema, globalOptions);
1596
- const {
1597
- label = true
1598
- } = uiOptions;
1096
+ const { label = true } = uiOptions;
1599
1097
  let displayLabel = !!label;
1600
1098
  const schemaType = getSchemaType(schema);
1601
- if (schemaType === 'array') {
1099
+ if (schemaType === "array") {
1602
1100
  displayLabel = isMultiSelect(validator, schema, rootSchema) || isFilesArray(validator, schema, uiSchema, rootSchema) || isCustomWidget(uiSchema);
1603
1101
  }
1604
- if (schemaType === 'object') {
1102
+ if (schemaType === "object") {
1605
1103
  displayLabel = false;
1606
1104
  }
1607
- if (schemaType === 'boolean' && !uiSchema[UI_WIDGET_KEY]) {
1105
+ if (schemaType === "boolean" && !uiSchema[UI_WIDGET_KEY]) {
1608
1106
  displayLabel = false;
1609
1107
  }
1610
1108
  if (uiSchema[UI_FIELD_KEY]) {
@@ -1613,152 +1111,81 @@ function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOpt
1613
1111
  return displayLabel;
1614
1112
  }
1615
1113
 
1616
- /** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in the
1617
- * two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
1618
- * `validator.toErrorList()` onto the `errors` in the `validationData`. If no `additionalErrorSchema` is passed, then
1619
- * `validationData` is returned.
1620
- *
1621
- * @param validator - The validator used to convert an ErrorSchema to a list of errors
1622
- * @param validationData - The current `ValidationData` into which to merge the additional errors
1623
- * @param [additionalErrorSchema] - The additional set of errors in an `ErrorSchema`
1624
- * @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
1625
- * @deprecated - Use the `validationDataMerge()` function exported from `@rjsf/utils` instead. This function will be
1626
- * removed in the next major release.
1627
- */
1114
+ // src/schema/mergeValidationData.ts
1115
+ import isEmpty2 from "lodash/isEmpty";
1628
1116
  function mergeValidationData(validator, validationData, additionalErrorSchema) {
1629
1117
  if (!additionalErrorSchema) {
1630
1118
  return validationData;
1631
1119
  }
1632
- const {
1633
- errors: oldErrors,
1634
- errorSchema: oldErrorSchema
1635
- } = validationData;
1120
+ const { errors: oldErrors, errorSchema: oldErrorSchema } = validationData;
1636
1121
  let errors = validator.toErrorList(additionalErrorSchema);
1637
1122
  let errorSchema = additionalErrorSchema;
1638
- if (!isEmpty(oldErrorSchema)) {
1123
+ if (!isEmpty2(oldErrorSchema)) {
1639
1124
  errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
1640
1125
  errors = [...oldErrors].concat(errors);
1641
1126
  }
1642
- return {
1643
- errorSchema,
1644
- errors
1645
- };
1127
+ return { errorSchema, errors };
1646
1128
  }
1647
1129
 
1648
- const NO_VALUE = /*#__PURE__*/Symbol('no Value');
1649
- /** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the new
1650
- * schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the nature
1651
- * of schemas, this sanitization happens recursively for nested objects of data. Also, any properties in the old schema
1652
- * that are non-existent in the new schema are set to `undefined`. The data sanitization process has the following flow:
1653
- *
1654
- * - If the new schema is an object that contains a `properties` object then:
1655
- * - Create a `removeOldSchemaData` object, setting each key in the `oldSchema.properties` having `data` to undefined
1656
- * - Create an empty `nestedData` object for use in the key filtering below:
1657
- * - Iterate over each key in the `newSchema.properties` as follows:
1658
- * - Get the `formValue` of the key from the `data`
1659
- * - Get the `oldKeySchema` and `newKeyedSchema` for the key, defaulting to `{}` when it doesn't exist
1660
- * - Retrieve the schema for any refs within each `oldKeySchema` and/or `newKeySchema`
1661
- * - Get the types of the old and new keyed schemas and if the old doesn't exist or the old & new are the same then:
1662
- * - If `removeOldSchemaData` has an entry for the key, delete it since the new schema has the same property
1663
- * - If type of the key in the new schema is `object`:
1664
- * - Store the value from the recursive `sanitizeDataForNewSchema` call in `nestedData[key]`
1665
- * - Otherwise, check for default or const values:
1666
- * - Get the old and new `default` values from the schema and check:
1667
- * - If the new `default` value does not match the form value:
1668
- * - If the old `default` value DOES match the form value, then:
1669
- * - Replace `removeOldSchemaData[key]` with the new `default`
1670
- * - Otherwise, if the new schema is `readOnly` then replace `removeOldSchemaData[key]` with undefined
1671
- * - Get the old and new `const` values from the schema and check:
1672
- * - If the new `const` value does not match the form value:
1673
- * - If the old `const` value DOES match the form value, then:
1674
- * - Replace `removeOldSchemaData[key]` with the new `const`
1675
- * - Otherwise, replace `removeOldSchemaData[key]` with undefined
1676
- * - Once all keys have been processed, return an object built as follows:
1677
- * - `{ ...removeOldSchemaData, ...nestedData, ...pick(data, keysToKeep) }`
1678
- * - If the new and old schema types are array and the `data` is an array then:
1679
- * - If the type of the old and new schema `items` are a non-array objects:
1680
- * - Retrieve the schema for any refs within each `oldKeySchema.items` and/or `newKeySchema.items`
1681
- * - If the `type`s of both items are the same (or the old does not have a type):
1682
- * - If the type is "object", then:
1683
- * - For each element in the `data` recursively sanitize the data, stopping at `maxItems` if specified
1684
- * - Otherwise, just return the `data` removing any values after `maxItems` if it is set
1685
- * - If the type of the old and new schema `items` are booleans of the same value, return `data` as is
1686
- * - Otherwise return `undefined`
1687
- *
1688
- * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
1689
- * @param rootSchema - The root JSON schema of the entire form
1690
- * @param [newSchema] - The new schema for which the data is being sanitized
1691
- * @param [oldSchema] - The old schema from which the data originated
1692
- * @param [data={}] - The form data associated with the schema, defaulting to an empty object when undefined
1693
- * @returns - The new form data, with all the fields uniquely associated with the old schema set
1694
- * to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
1695
- */
1130
+ // src/schema/sanitizeDataForNewSchema.ts
1131
+ import get7 from "lodash/get";
1132
+ import has3 from "lodash/has";
1133
+ var NO_VALUE = Symbol("no Value");
1696
1134
  function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}) {
1697
- // By default, we will clear the form data
1698
1135
  let newFormData;
1699
- // If the new schema is of type object and that object contains a list of properties
1700
- if (has(newSchema, PROPERTIES_KEY)) {
1701
- // Create an object containing root-level keys in the old schema, setting each key to undefined to remove the data
1136
+ if (has3(newSchema, PROPERTIES_KEY)) {
1702
1137
  const removeOldSchemaData = {};
1703
- if (has(oldSchema, PROPERTIES_KEY)) {
1704
- const properties = get(oldSchema, PROPERTIES_KEY, {});
1705
- Object.keys(properties).forEach(key => {
1706
- if (has(data, key)) {
1707
- removeOldSchemaData[key] = undefined;
1138
+ if (has3(oldSchema, PROPERTIES_KEY)) {
1139
+ const properties = get7(oldSchema, PROPERTIES_KEY, {});
1140
+ Object.keys(properties).forEach((key) => {
1141
+ if (has3(data, key)) {
1142
+ removeOldSchemaData[key] = void 0;
1708
1143
  }
1709
1144
  });
1710
1145
  }
1711
- const keys = Object.keys(get(newSchema, PROPERTIES_KEY, {}));
1712
- // Create a place to store nested data that will be a side-effect of the filter
1146
+ const keys = Object.keys(get7(newSchema, PROPERTIES_KEY, {}));
1713
1147
  const nestedData = {};
1714
- keys.forEach(key => {
1715
- const formValue = get(data, key);
1716
- let oldKeyedSchema = get(oldSchema, [PROPERTIES_KEY, key], {});
1717
- let newKeyedSchema = get(newSchema, [PROPERTIES_KEY, key], {});
1718
- // Resolve the refs if they exist
1719
- if (has(oldKeyedSchema, REF_KEY)) {
1148
+ keys.forEach((key) => {
1149
+ const formValue = get7(data, key);
1150
+ let oldKeyedSchema = get7(oldSchema, [PROPERTIES_KEY, key], {});
1151
+ let newKeyedSchema = get7(newSchema, [PROPERTIES_KEY, key], {});
1152
+ if (has3(oldKeyedSchema, REF_KEY)) {
1720
1153
  oldKeyedSchema = retrieveSchema(validator, oldKeyedSchema, rootSchema, formValue);
1721
1154
  }
1722
- if (has(newKeyedSchema, REF_KEY)) {
1155
+ if (has3(newKeyedSchema, REF_KEY)) {
1723
1156
  newKeyedSchema = retrieveSchema(validator, newKeyedSchema, rootSchema, formValue);
1724
1157
  }
1725
- // Now get types and see if they are the same
1726
- const oldSchemaTypeForKey = get(oldKeyedSchema, 'type');
1727
- const newSchemaTypeForKey = get(newKeyedSchema, 'type');
1728
- // Check if the old option has the same key with the same type
1158
+ const oldSchemaTypeForKey = get7(oldKeyedSchema, "type");
1159
+ const newSchemaTypeForKey = get7(newKeyedSchema, "type");
1729
1160
  if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
1730
- if (has(removeOldSchemaData, key)) {
1731
- // SIDE-EFFECT: remove the undefined value for a key that has the same type between the old and new schemas
1161
+ if (has3(removeOldSchemaData, key)) {
1732
1162
  delete removeOldSchemaData[key];
1733
1163
  }
1734
- // If it is an object, we'll recurse and store the resulting sanitized data for the key
1735
- if (newSchemaTypeForKey === 'object' || newSchemaTypeForKey === 'array' && Array.isArray(formValue)) {
1736
- // SIDE-EFFECT: process the new schema type of object recursively to save iterations
1737
- const itemData = sanitizeDataForNewSchema(validator, rootSchema, newKeyedSchema, oldKeyedSchema, formValue);
1738
- if (itemData !== undefined || newSchemaTypeForKey === 'array') {
1739
- // only put undefined values for the array type and not the object type
1164
+ if (newSchemaTypeForKey === "object" || newSchemaTypeForKey === "array" && Array.isArray(formValue)) {
1165
+ const itemData = sanitizeDataForNewSchema(
1166
+ validator,
1167
+ rootSchema,
1168
+ newKeyedSchema,
1169
+ oldKeyedSchema,
1170
+ formValue
1171
+ );
1172
+ if (itemData !== void 0 || newSchemaTypeForKey === "array") {
1740
1173
  nestedData[key] = itemData;
1741
1174
  }
1742
1175
  } else {
1743
- // Ok, the non-object types match, let's make sure that a default or a const of a different value is replaced
1744
- // with the new default or const. This allows the case where two schemas differ that only by the default/const
1745
- // value to be properly selected
1746
- const newOptionDefault = get(newKeyedSchema, 'default', NO_VALUE);
1747
- const oldOptionDefault = get(oldKeyedSchema, 'default', NO_VALUE);
1176
+ const newOptionDefault = get7(newKeyedSchema, "default", NO_VALUE);
1177
+ const oldOptionDefault = get7(oldKeyedSchema, "default", NO_VALUE);
1748
1178
  if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
1749
1179
  if (oldOptionDefault === formValue) {
1750
- // If the old default matches the formValue, we'll update the new value to match the new default
1751
1180
  removeOldSchemaData[key] = newOptionDefault;
1752
- } else if (get(newKeyedSchema, 'readOnly') === true) {
1753
- // If the new schema has the default set to read-only, treat it like a const and remove the value
1754
- removeOldSchemaData[key] = undefined;
1181
+ } else if (get7(newKeyedSchema, "readOnly") === true) {
1182
+ removeOldSchemaData[key] = void 0;
1755
1183
  }
1756
1184
  }
1757
- const newOptionConst = get(newKeyedSchema, 'const', NO_VALUE);
1758
- const oldOptionConst = get(oldKeyedSchema, 'const', NO_VALUE);
1185
+ const newOptionConst = get7(newKeyedSchema, "const", NO_VALUE);
1186
+ const oldOptionConst = get7(oldKeyedSchema, "const", NO_VALUE);
1759
1187
  if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
1760
- // Since this is a const, if the old value matches, replace the value with the new const otherwise clear it
1761
- removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : undefined;
1188
+ removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : void 0;
1762
1189
  }
1763
1190
  }
1764
1191
  }
@@ -1768,29 +1195,30 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
1768
1195
  ...removeOldSchemaData,
1769
1196
  ...nestedData
1770
1197
  };
1771
- // First apply removing the old schema data, then apply the nested data, then apply the old data keys to keep
1772
- } else if (get(oldSchema, 'type') === 'array' && get(newSchema, 'type') === 'array' && Array.isArray(data)) {
1773
- let oldSchemaItems = get(oldSchema, 'items');
1774
- let newSchemaItems = get(newSchema, 'items');
1775
- // If any of the array types `items` are arrays (remember arrays are objects) then we'll just drop the data
1776
- // Eventually, we may want to deal with when either of the `items` are arrays since those tuple validations
1777
- if (typeof oldSchemaItems === 'object' && typeof newSchemaItems === 'object' && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
1778
- if (has(oldSchemaItems, REF_KEY)) {
1198
+ } else if (get7(oldSchema, "type") === "array" && get7(newSchema, "type") === "array" && Array.isArray(data)) {
1199
+ let oldSchemaItems = get7(oldSchema, "items");
1200
+ let newSchemaItems = get7(newSchema, "items");
1201
+ if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
1202
+ if (has3(oldSchemaItems, REF_KEY)) {
1779
1203
  oldSchemaItems = retrieveSchema(validator, oldSchemaItems, rootSchema, data);
1780
1204
  }
1781
- if (has(newSchemaItems, REF_KEY)) {
1205
+ if (has3(newSchemaItems, REF_KEY)) {
1782
1206
  newSchemaItems = retrieveSchema(validator, newSchemaItems, rootSchema, data);
1783
1207
  }
1784
- // Now get types and see if they are the same
1785
- const oldSchemaType = get(oldSchemaItems, 'type');
1786
- const newSchemaType = get(newSchemaItems, 'type');
1787
- // Check if the old option has the same key with the same type
1208
+ const oldSchemaType = get7(oldSchemaItems, "type");
1209
+ const newSchemaType = get7(newSchemaItems, "type");
1788
1210
  if (!oldSchemaType || oldSchemaType === newSchemaType) {
1789
- const maxItems = get(newSchema, 'maxItems', -1);
1790
- if (newSchemaType === 'object') {
1211
+ const maxItems = get7(newSchema, "maxItems", -1);
1212
+ if (newSchemaType === "object") {
1791
1213
  newFormData = data.reduce((newValue, aValue) => {
1792
- const itemValue = sanitizeDataForNewSchema(validator, rootSchema, newSchemaItems, oldSchemaItems, aValue);
1793
- if (itemValue !== undefined && (maxItems < 0 || newValue.length < maxItems)) {
1214
+ const itemValue = sanitizeDataForNewSchema(
1215
+ validator,
1216
+ rootSchema,
1217
+ newSchemaItems,
1218
+ oldSchemaItems,
1219
+ aValue
1220
+ );
1221
+ if (itemValue !== void 0 && (maxItems < 0 || newValue.length < maxItems)) {
1794
1222
  newValue.push(itemValue);
1795
1223
  }
1796
1224
  return newValue;
@@ -1799,92 +1227,92 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
1799
1227
  newFormData = maxItems > 0 && data.length > maxItems ? data.slice(0, maxItems) : data;
1800
1228
  }
1801
1229
  }
1802
- } else if (typeof oldSchemaItems === 'boolean' && typeof newSchemaItems === 'boolean' && oldSchemaItems === newSchemaItems) {
1803
- // If they are both booleans and have the same value just return the data as is otherwise fall-thru to undefined
1230
+ } else if (typeof oldSchemaItems === "boolean" && typeof newSchemaItems === "boolean" && oldSchemaItems === newSchemaItems) {
1804
1231
  newFormData = data;
1805
1232
  }
1806
- // Also probably want to deal with `prefixItems` as tuples with the latest 2020 draft
1807
1233
  }
1808
-
1809
1234
  return newFormData;
1810
1235
  }
1811
1236
 
1812
- /** An internal helper that generates an `IdSchema` object for the `schema`, recursively with protection against
1813
- * infinite recursion
1814
- *
1815
- * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
1816
- * @param schema - The schema for which the `IdSchema` is desired
1817
- * @param idPrefix - The prefix to use for the id
1818
- * @param idSeparator - The separator to use for the path segments in the id
1819
- * @param [id] - The base id for the schema
1820
- * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
1821
- * @param [formData] - The current formData, if any, to assist retrieving a schema
1822
- * @param [_recurseList=[]] - The list of retrieved schemas currently being recursed, used to prevent infinite recursion
1823
- * @returns - The `IdSchema` object for the `schema`
1824
- */
1237
+ // src/schema/toIdSchema.ts
1238
+ import get8 from "lodash/get";
1239
+ import isEqual from "lodash/isEqual";
1825
1240
  function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = []) {
1826
1241
  if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
1827
1242
  const _schema = retrieveSchema(validator, schema, rootSchema, formData);
1828
- const sameSchemaIndex = _recurseList.findIndex(item => isEqual(item, _schema));
1243
+ const sameSchemaIndex = _recurseList.findIndex((item) => isEqual(item, _schema));
1829
1244
  if (sameSchemaIndex === -1) {
1830
- return toIdSchemaInternal(validator, _schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList.concat(_schema));
1245
+ return toIdSchemaInternal(
1246
+ validator,
1247
+ _schema,
1248
+ idPrefix,
1249
+ idSeparator,
1250
+ id,
1251
+ rootSchema,
1252
+ formData,
1253
+ _recurseList.concat(_schema)
1254
+ );
1831
1255
  }
1832
1256
  }
1833
- if (ITEMS_KEY in schema && !get(schema, [ITEMS_KEY, REF_KEY])) {
1834
- return toIdSchemaInternal(validator, get(schema, ITEMS_KEY), idPrefix, idSeparator, id, rootSchema, formData, _recurseList);
1257
+ if (ITEMS_KEY in schema && !get8(schema, [ITEMS_KEY, REF_KEY])) {
1258
+ return toIdSchemaInternal(
1259
+ validator,
1260
+ get8(schema, ITEMS_KEY),
1261
+ idPrefix,
1262
+ idSeparator,
1263
+ id,
1264
+ rootSchema,
1265
+ formData,
1266
+ _recurseList
1267
+ );
1835
1268
  }
1836
1269
  const $id = id || idPrefix;
1837
- const idSchema = {
1838
- $id
1839
- };
1840
- if (getSchemaType(schema) === 'object' && PROPERTIES_KEY in schema) {
1270
+ const idSchema = { $id };
1271
+ if (getSchemaType(schema) === "object" && PROPERTIES_KEY in schema) {
1841
1272
  for (const name in schema.properties) {
1842
- const field = get(schema, [PROPERTIES_KEY, name]);
1273
+ const field = get8(schema, [PROPERTIES_KEY, name]);
1843
1274
  const fieldId = idSchema[ID_KEY] + idSeparator + name;
1844
- idSchema[name] = toIdSchemaInternal(validator, isObject(field) ? field : {}, idPrefix, idSeparator, fieldId, rootSchema,
1845
- // It's possible that formData is not an object -- this can happen if an
1846
- // array item has just been added, but not populated with data yet
1847
- get(formData, [name]), _recurseList);
1275
+ idSchema[name] = toIdSchemaInternal(
1276
+ validator,
1277
+ isObject(field) ? field : {},
1278
+ idPrefix,
1279
+ idSeparator,
1280
+ fieldId,
1281
+ rootSchema,
1282
+ // It's possible that formData is not an object -- this can happen if an
1283
+ // array item has just been added, but not populated with data yet
1284
+ get8(formData, [name]),
1285
+ _recurseList
1286
+ );
1848
1287
  }
1849
1288
  }
1850
1289
  return idSchema;
1851
1290
  }
1852
- /** Generates an `IdSchema` object for the `schema`, recursively
1853
- *
1854
- * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
1855
- * @param schema - The schema for which the `IdSchema` is desired
1856
- * @param [id] - The base id for the schema
1857
- * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
1858
- * @param [formData] - The current formData, if any, to assist retrieving a schema
1859
- * @param [idPrefix='root'] - The prefix to use for the id
1860
- * @param [idSeparator='_'] - The separator to use for the path segments in the id
1861
- * @returns - The `IdSchema` object for the `schema`
1862
- */
1863
- function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = 'root', idSeparator = '_') {
1291
+ function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "root", idSeparator = "_") {
1864
1292
  return toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData);
1865
1293
  }
1866
1294
 
1867
- /** An internal helper that generates an `PathSchema` object for the `schema`, recursively with protection against
1868
- * infinite recursion
1869
- *
1870
- * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
1871
- * @param schema - The schema for which the `PathSchema` is desired
1872
- * @param [name=''] - The base name for the schema
1873
- * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
1874
- * @param [formData] - The current formData, if any, to assist retrieving a schema
1875
- * @param [_recurseList=[]] - The list of retrieved schemas currently being recursed, used to prevent infinite recursion
1876
- * @returns - The `PathSchema` object for the `schema`
1877
- */
1295
+ // src/schema/toPathSchema.ts
1296
+ import get9 from "lodash/get";
1297
+ import isEqual2 from "lodash/isEqual";
1298
+ import set2 from "lodash/set";
1878
1299
  function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = []) {
1879
1300
  if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
1880
1301
  const _schema = retrieveSchema(validator, schema, rootSchema, formData);
1881
- const sameSchemaIndex = _recurseList.findIndex(item => isEqual(item, _schema));
1302
+ const sameSchemaIndex = _recurseList.findIndex((item) => isEqual2(item, _schema));
1882
1303
  if (sameSchemaIndex === -1) {
1883
- return toPathSchemaInternal(validator, _schema, name, rootSchema, formData, _recurseList.concat(_schema));
1304
+ return toPathSchemaInternal(
1305
+ validator,
1306
+ _schema,
1307
+ name,
1308
+ rootSchema,
1309
+ formData,
1310
+ _recurseList.concat(_schema)
1311
+ );
1884
1312
  }
1885
1313
  }
1886
1314
  let pathSchema = {
1887
- [NAME_KEY]: name.replace(/^\./, '')
1315
+ [NAME_KEY]: name.replace(/^\./, "")
1888
1316
  };
1889
1317
  if (ONE_OF_KEY in schema || ANY_OF_KEY in schema) {
1890
1318
  const xxxOf = ONE_OF_KEY in schema ? schema.oneOf : schema.anyOf;
@@ -1897,71 +1325,68 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
1897
1325
  };
1898
1326
  }
1899
1327
  if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
1900
- set(pathSchema, RJSF_ADDITONAL_PROPERTIES_FLAG, true);
1328
+ set2(pathSchema, RJSF_ADDITONAL_PROPERTIES_FLAG, true);
1901
1329
  }
1902
1330
  if (ITEMS_KEY in schema && Array.isArray(formData)) {
1903
1331
  formData.forEach((element, i) => {
1904
- pathSchema[i] = toPathSchemaInternal(validator, schema.items, `${name}.${i}`, rootSchema, element, _recurseList);
1332
+ pathSchema[i] = toPathSchemaInternal(
1333
+ validator,
1334
+ schema.items,
1335
+ `${name}.${i}`,
1336
+ rootSchema,
1337
+ element,
1338
+ _recurseList
1339
+ );
1905
1340
  });
1906
1341
  } else if (PROPERTIES_KEY in schema) {
1907
1342
  for (const property in schema.properties) {
1908
- const field = get(schema, [PROPERTIES_KEY, property]);
1909
- pathSchema[property] = toPathSchemaInternal(validator, field, `${name}.${property}`, rootSchema,
1910
- // It's possible that formData is not an object -- this can happen if an
1911
- // array item has just been added, but not populated with data yet
1912
- get(formData, [property]), _recurseList);
1343
+ const field = get9(schema, [PROPERTIES_KEY, property]);
1344
+ pathSchema[property] = toPathSchemaInternal(
1345
+ validator,
1346
+ field,
1347
+ `${name}.${property}`,
1348
+ rootSchema,
1349
+ // It's possible that formData is not an object -- this can happen if an
1350
+ // array item has just been added, but not populated with data yet
1351
+ get9(formData, [property]),
1352
+ _recurseList
1353
+ );
1913
1354
  }
1914
1355
  }
1915
1356
  return pathSchema;
1916
1357
  }
1917
- /** Generates an `PathSchema` object for the `schema`, recursively
1918
- *
1919
- * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
1920
- * @param schema - The schema for which the `PathSchema` is desired
1921
- * @param [name=''] - The base name for the schema
1922
- * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
1923
- * @param [formData] - The current formData, if any, to assist retrieving a schema
1924
- * @returns - The `PathSchema` object for the `schema`
1925
- */
1926
- function toPathSchema(validator, schema, name = '', rootSchema, formData) {
1358
+ function toPathSchema(validator, schema, name = "", rootSchema, formData) {
1927
1359
  return toPathSchemaInternal(validator, schema, name, rootSchema, formData);
1928
1360
  }
1929
1361
 
1930
- /** The `SchemaUtils` class provides a wrapper around the publicly exported APIs in the `utils/schema` directory such
1931
- * that one does not have to explicitly pass the `validator`, `rootSchema`, or `experimental_defaultFormStateBehavior` to each method.
1932
- * Since these generally do not change across a `Form`, this allows for providing a simplified set of APIs to the
1933
- * `@rjsf/core` components and the various themes as well. This class implements the `SchemaUtilsType` interface.
1934
- */
1935
- class SchemaUtils {
1936
- /** Constructs the `SchemaUtils` instance with the given `validator` and `rootSchema` stored as instance variables
1937
- *
1938
- * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
1939
- * @param rootSchema - The root schema that will be forwarded to all the APIs
1940
- * @param experimental_defaultFormStateBehavior - Configuration flags to allow users to override default form state behavior
1362
+ // src/createSchemaUtils.ts
1363
+ var SchemaUtils = class {
1364
+ /** Constructs the `SchemaUtils` instance with the given `validator` and `rootSchema` stored as instance variables
1365
+ *
1366
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
1367
+ * @param rootSchema - The root schema that will be forwarded to all the APIs
1368
+ * @param experimental_defaultFormStateBehavior - Configuration flags to allow users to override default form state behavior
1941
1369
  */
1942
1370
  constructor(validator, rootSchema, experimental_defaultFormStateBehavior) {
1943
- this.rootSchema = void 0;
1944
- this.validator = void 0;
1945
- this.experimental_defaultFormStateBehavior = void 0;
1946
1371
  this.rootSchema = rootSchema;
1947
1372
  this.validator = validator;
1948
1373
  this.experimental_defaultFormStateBehavior = experimental_defaultFormStateBehavior;
1949
1374
  }
1950
- /** Returns the `ValidatorType` in the `SchemaUtilsType`
1951
- *
1952
- * @returns - The `ValidatorType`
1375
+ /** Returns the `ValidatorType` in the `SchemaUtilsType`
1376
+ *
1377
+ * @returns - The `ValidatorType`
1953
1378
  */
1954
1379
  getValidator() {
1955
1380
  return this.validator;
1956
1381
  }
1957
- /** Determines whether either the `validator` and `rootSchema` differ from the ones associated with this instance of
1958
- * the `SchemaUtilsType`. If either `validator` or `rootSchema` are falsy, then return false to prevent the creation
1959
- * of a new `SchemaUtilsType` with incomplete properties.
1960
- *
1961
- * @param validator - An implementation of the `ValidatorType` interface that will be compared against the current one
1962
- * @param rootSchema - The root schema that will be compared against the current one
1963
- * @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
1964
- * @returns - True if the `SchemaUtilsType` differs from the given `validator` or `rootSchema`
1382
+ /** Determines whether either the `validator` and `rootSchema` differ from the ones associated with this instance of
1383
+ * the `SchemaUtilsType`. If either `validator` or `rootSchema` are falsy, then return false to prevent the creation
1384
+ * of a new `SchemaUtilsType` with incomplete properties.
1385
+ *
1386
+ * @param validator - An implementation of the `ValidatorType` interface that will be compared against the current one
1387
+ * @param rootSchema - The root schema that will be compared against the current one
1388
+ * @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
1389
+ * @returns - True if the `SchemaUtilsType` differs from the given `validator` or `rootSchema`
1965
1390
  */
1966
1391
  doesSchemaUtilsDiffer(validator, rootSchema, experimental_defaultFormStateBehavior = {}) {
1967
1392
  if (!validator || !rootSchema) {
@@ -1969,411 +1394,334 @@ class SchemaUtils {
1969
1394
  }
1970
1395
  return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema) || !deepEquals(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior);
1971
1396
  }
1972
- /** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
1973
- * computed to have defaults provided in the `schema`.
1974
- *
1975
- * @param schema - The schema for which the default state is desired
1976
- * @param [formData] - The current formData, if any, onto which to provide any missing defaults
1977
- * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
1978
- * If "excludeObjectChildren", pass `includeUndefinedValues` as false when computing defaults for any nested
1979
- * object properties.
1980
- * @returns - The resulting `formData` with all the defaults provided
1397
+ /** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
1398
+ * computed to have defaults provided in the `schema`.
1399
+ *
1400
+ * @param schema - The schema for which the default state is desired
1401
+ * @param [formData] - The current formData, if any, onto which to provide any missing defaults
1402
+ * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
1403
+ * If "excludeObjectChildren", pass `includeUndefinedValues` as false when computing defaults for any nested
1404
+ * object properties.
1405
+ * @returns - The resulting `formData` with all the defaults provided
1981
1406
  */
1982
1407
  getDefaultFormState(schema, formData, includeUndefinedValues = false) {
1983
- return getDefaultFormState(this.validator, schema, formData, this.rootSchema, includeUndefinedValues, this.experimental_defaultFormStateBehavior);
1984
- }
1985
- /** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
1986
- * should be displayed in a UI.
1987
- *
1988
- * @param schema - The schema for which the display label flag is desired
1989
- * @param [uiSchema] - The UI schema from which to derive potentially displayable information
1990
- * @param [globalOptions={}] - The optional Global UI Schema from which to get any fallback `xxx` options
1991
- * @returns - True if the label should be displayed or false if it should not
1408
+ return getDefaultFormState(
1409
+ this.validator,
1410
+ schema,
1411
+ formData,
1412
+ this.rootSchema,
1413
+ includeUndefinedValues,
1414
+ this.experimental_defaultFormStateBehavior
1415
+ );
1416
+ }
1417
+ /** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
1418
+ * should be displayed in a UI.
1419
+ *
1420
+ * @param schema - The schema for which the display label flag is desired
1421
+ * @param [uiSchema] - The UI schema from which to derive potentially displayable information
1422
+ * @param [globalOptions={}] - The optional Global UI Schema from which to get any fallback `xxx` options
1423
+ * @returns - True if the label should be displayed or false if it should not
1992
1424
  */
1993
1425
  getDisplayLabel(schema, uiSchema, globalOptions) {
1994
1426
  return getDisplayLabel(this.validator, schema, uiSchema, this.rootSchema, globalOptions);
1995
1427
  }
1996
- /** Determines which of the given `options` provided most closely matches the `formData`.
1997
- * Returns the index of the option that is valid and is the closest match, or 0 if there is no match.
1998
- *
1999
- * The closest match is determined using the number of matching properties, and more heavily favors options with
2000
- * matching readOnly, default, or const values.
2001
- *
2002
- * @param formData - The form data associated with the schema
2003
- * @param options - The list of options that can be selected from
2004
- * @param [selectedOption] - The index of the currently selected option, defaulted to -1 if not specified
2005
- * @param [discriminatorField] - The optional name of the field within the options object whose value is used to
2006
- * determine which option is selected
2007
- * @returns - The index of the option that is the closest match to the `formData` or the `selectedOption` if no match
1428
+ /** Determines which of the given `options` provided most closely matches the `formData`.
1429
+ * Returns the index of the option that is valid and is the closest match, or 0 if there is no match.
1430
+ *
1431
+ * The closest match is determined using the number of matching properties, and more heavily favors options with
1432
+ * matching readOnly, default, or const values.
1433
+ *
1434
+ * @param formData - The form data associated with the schema
1435
+ * @param options - The list of options that can be selected from
1436
+ * @param [selectedOption] - The index of the currently selected option, defaulted to -1 if not specified
1437
+ * @param [discriminatorField] - The optional name of the field within the options object whose value is used to
1438
+ * determine which option is selected
1439
+ * @returns - The index of the option that is the closest match to the `formData` or the `selectedOption` if no match
2008
1440
  */
2009
1441
  getClosestMatchingOption(formData, options, selectedOption, discriminatorField) {
2010
- return getClosestMatchingOption(this.validator, this.rootSchema, formData, options, selectedOption, discriminatorField);
2011
- }
2012
- /** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
2013
- * Always returns the first option if there is nothing that matches.
2014
- *
2015
- * @param formData - The current formData, if any, used to figure out a match
2016
- * @param options - The list of options to find a matching options from
2017
- * @param [discriminatorField] - The optional name of the field within the options object whose value is used to
2018
- * determine which option is selected
2019
- * @returns - The firstindex of the matched option or 0 if none is available
1442
+ return getClosestMatchingOption(
1443
+ this.validator,
1444
+ this.rootSchema,
1445
+ formData,
1446
+ options,
1447
+ selectedOption,
1448
+ discriminatorField
1449
+ );
1450
+ }
1451
+ /** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
1452
+ * Always returns the first option if there is nothing that matches.
1453
+ *
1454
+ * @param formData - The current formData, if any, used to figure out a match
1455
+ * @param options - The list of options to find a matching options from
1456
+ * @param [discriminatorField] - The optional name of the field within the options object whose value is used to
1457
+ * determine which option is selected
1458
+ * @returns - The firstindex of the matched option or 0 if none is available
2020
1459
  */
2021
1460
  getFirstMatchingOption(formData, options, discriminatorField) {
2022
1461
  return getFirstMatchingOption(this.validator, formData, options, this.rootSchema, discriminatorField);
2023
1462
  }
2024
- /** Given the `formData` and list of `options`, attempts to find the index of the option that best matches the data.
2025
- * Deprecated, use `getFirstMatchingOption()` instead.
2026
- *
2027
- * @param formData - The current formData, if any, onto which to provide any missing defaults
2028
- * @param options - The list of options to find a matching options from
2029
- * @param [discriminatorField] - The optional name of the field within the options object whose value is used to
2030
- * determine which option is selected
2031
- * @returns - The index of the matched option or 0 if none is available
2032
- * @deprecated
1463
+ /** Given the `formData` and list of `options`, attempts to find the index of the option that best matches the data.
1464
+ * Deprecated, use `getFirstMatchingOption()` instead.
1465
+ *
1466
+ * @param formData - The current formData, if any, onto which to provide any missing defaults
1467
+ * @param options - The list of options to find a matching options from
1468
+ * @param [discriminatorField] - The optional name of the field within the options object whose value is used to
1469
+ * determine which option is selected
1470
+ * @returns - The index of the matched option or 0 if none is available
1471
+ * @deprecated
2033
1472
  */
2034
1473
  getMatchingOption(formData, options, discriminatorField) {
2035
1474
  return getMatchingOption(this.validator, formData, options, this.rootSchema, discriminatorField);
2036
1475
  }
2037
- /** Checks to see if the `schema` and `uiSchema` combination represents an array of files
2038
- *
2039
- * @param schema - The schema for which check for array of files flag is desired
2040
- * @param [uiSchema] - The UI schema from which to check the widget
2041
- * @returns - True if schema/uiSchema contains an array of files, otherwise false
1476
+ /** Checks to see if the `schema` and `uiSchema` combination represents an array of files
1477
+ *
1478
+ * @param schema - The schema for which check for array of files flag is desired
1479
+ * @param [uiSchema] - The UI schema from which to check the widget
1480
+ * @returns - True if schema/uiSchema contains an array of files, otherwise false
2042
1481
  */
2043
1482
  isFilesArray(schema, uiSchema) {
2044
1483
  return isFilesArray(this.validator, schema, uiSchema, this.rootSchema);
2045
1484
  }
2046
- /** Checks to see if the `schema` combination represents a multi-select
2047
- *
2048
- * @param schema - The schema for which check for a multi-select flag is desired
2049
- * @returns - True if schema contains a multi-select, otherwise false
1485
+ /** Checks to see if the `schema` combination represents a multi-select
1486
+ *
1487
+ * @param schema - The schema for which check for a multi-select flag is desired
1488
+ * @returns - True if schema contains a multi-select, otherwise false
2050
1489
  */
2051
1490
  isMultiSelect(schema) {
2052
1491
  return isMultiSelect(this.validator, schema, this.rootSchema);
2053
1492
  }
2054
- /** Checks to see if the `schema` combination represents a select
2055
- *
2056
- * @param schema - The schema for which check for a select flag is desired
2057
- * @returns - True if schema contains a select, otherwise false
1493
+ /** Checks to see if the `schema` combination represents a select
1494
+ *
1495
+ * @param schema - The schema for which check for a select flag is desired
1496
+ * @returns - True if schema contains a select, otherwise false
2058
1497
  */
2059
1498
  isSelect(schema) {
2060
1499
  return isSelect(this.validator, schema, this.rootSchema);
2061
1500
  }
2062
- /** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in
2063
- * the two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
2064
- * `getValidator().toErrorList()` onto the `errors` in the `validationData`. If no `additionalErrorSchema` is passed,
2065
- * then `validationData` is returned.
2066
- *
2067
- * @param validationData - The current `ValidationData` into which to merge the additional errors
2068
- * @param [additionalErrorSchema] - The additional set of errors
2069
- * @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
2070
- * @deprecated - Use the `validationDataMerge()` function exported from `@rjsf/utils` instead. This function will be
2071
- * removed in the next major release.
1501
+ /** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in
1502
+ * the two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
1503
+ * `getValidator().toErrorList()` onto the `errors` in the `validationData`. If no `additionalErrorSchema` is passed,
1504
+ * then `validationData` is returned.
1505
+ *
1506
+ * @param validationData - The current `ValidationData` into which to merge the additional errors
1507
+ * @param [additionalErrorSchema] - The additional set of errors
1508
+ * @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
1509
+ * @deprecated - Use the `validationDataMerge()` function exported from `@rjsf/utils` instead. This function will be
1510
+ * removed in the next major release.
2072
1511
  */
2073
1512
  mergeValidationData(validationData, additionalErrorSchema) {
2074
1513
  return mergeValidationData(this.validator, validationData, additionalErrorSchema);
2075
1514
  }
2076
- /** Retrieves an expanded schema that has had all of its conditions, additional properties, references and
2077
- * dependencies resolved and merged into the `schema` given a `rawFormData` that is used to do the potentially
2078
- * recursive resolution.
2079
- *
2080
- * @param schema - The schema for which retrieving a schema is desired
2081
- * @param [rawFormData] - The current formData, if any, to assist retrieving a schema
2082
- * @returns - The schema having its conditions, additional properties, references and dependencies resolved
1515
+ /** Retrieves an expanded schema that has had all of its conditions, additional properties, references and
1516
+ * dependencies resolved and merged into the `schema` given a `rawFormData` that is used to do the potentially
1517
+ * recursive resolution.
1518
+ *
1519
+ * @param schema - The schema for which retrieving a schema is desired
1520
+ * @param [rawFormData] - The current formData, if any, to assist retrieving a schema
1521
+ * @returns - The schema having its conditions, additional properties, references and dependencies resolved
2083
1522
  */
2084
1523
  retrieveSchema(schema, rawFormData) {
2085
1524
  return retrieveSchema(this.validator, schema, this.rootSchema, rawFormData);
2086
1525
  }
2087
- /** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the
2088
- * new schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the
2089
- * nature of schemas, this sanitization happens recursively for nested objects of data. Also, any properties in the
2090
- * old schemas that are non-existent in the new schema are set to `undefined`.
2091
- *
2092
- * @param [newSchema] - The new schema for which the data is being sanitized
2093
- * @param [oldSchema] - The old schema from which the data originated
2094
- * @param [data={}] - The form data associated with the schema, defaulting to an empty object when undefined
2095
- * @returns - The new form data, with all the fields uniquely associated with the old schema set
2096
- * to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
1526
+ /** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the
1527
+ * new schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the
1528
+ * nature of schemas, this sanitization happens recursively for nested objects of data. Also, any properties in the
1529
+ * old schemas that are non-existent in the new schema are set to `undefined`.
1530
+ *
1531
+ * @param [newSchema] - The new schema for which the data is being sanitized
1532
+ * @param [oldSchema] - The old schema from which the data originated
1533
+ * @param [data={}] - The form data associated with the schema, defaulting to an empty object when undefined
1534
+ * @returns - The new form data, with all the fields uniquely associated with the old schema set
1535
+ * to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
2097
1536
  */
2098
1537
  sanitizeDataForNewSchema(newSchema, oldSchema, data) {
2099
1538
  return sanitizeDataForNewSchema(this.validator, this.rootSchema, newSchema, oldSchema, data);
2100
1539
  }
2101
- /** Generates an `IdSchema` object for the `schema`, recursively
2102
- *
2103
- * @param schema - The schema for which the display label flag is desired
2104
- * @param [id] - The base id for the schema
2105
- * @param [formData] - The current formData, if any, onto which to provide any missing defaults
2106
- * @param [idPrefix='root'] - The prefix to use for the id
2107
- * @param [idSeparator='_'] - The separator to use for the path segments in the id
2108
- * @returns - The `IdSchema` object for the `schema`
1540
+ /** Generates an `IdSchema` object for the `schema`, recursively
1541
+ *
1542
+ * @param schema - The schema for which the display label flag is desired
1543
+ * @param [id] - The base id for the schema
1544
+ * @param [formData] - The current formData, if any, onto which to provide any missing defaults
1545
+ * @param [idPrefix='root'] - The prefix to use for the id
1546
+ * @param [idSeparator='_'] - The separator to use for the path segments in the id
1547
+ * @returns - The `IdSchema` object for the `schema`
2109
1548
  */
2110
- toIdSchema(schema, id, formData, idPrefix = 'root', idSeparator = '_') {
1549
+ toIdSchema(schema, id, formData, idPrefix = "root", idSeparator = "_") {
2111
1550
  return toIdSchema(this.validator, schema, id, this.rootSchema, formData, idPrefix, idSeparator);
2112
1551
  }
2113
- /** Generates an `PathSchema` object for the `schema`, recursively
2114
- *
2115
- * @param schema - The schema for which the display label flag is desired
2116
- * @param [name] - The base name for the schema
2117
- * @param [formData] - The current formData, if any, onto which to provide any missing defaults
2118
- * @returns - The `PathSchema` object for the `schema`
1552
+ /** Generates an `PathSchema` object for the `schema`, recursively
1553
+ *
1554
+ * @param schema - The schema for which the display label flag is desired
1555
+ * @param [name] - The base name for the schema
1556
+ * @param [formData] - The current formData, if any, onto which to provide any missing defaults
1557
+ * @returns - The `PathSchema` object for the `schema`
2119
1558
  */
2120
1559
  toPathSchema(schema, name, formData) {
2121
1560
  return toPathSchema(this.validator, schema, name, this.rootSchema, formData);
2122
1561
  }
2123
- }
2124
- /** Creates a `SchemaUtilsType` interface that is based around the given `validator` and `rootSchema` parameters. The
2125
- * resulting interface implementation will forward the `validator` and `rootSchema` to all the wrapped APIs.
2126
- *
2127
- * @param validator - an implementation of the `ValidatorType` interface that will be forwarded to all the APIs
2128
- * @param rootSchema - The root schema that will be forwarded to all the APIs
2129
- * @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
2130
- * @returns - An implementation of a `SchemaUtilsType` interface
2131
- */
1562
+ };
2132
1563
  function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior = {}) {
2133
1564
  return new SchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior);
2134
1565
  }
2135
1566
 
2136
- /** Given the `FileReader.readAsDataURL()` based `dataURI` extracts that data into an actual Blob along with the name
2137
- * of that Blob if provided in the URL. If no name is provided, then the name falls back to `unknown`.
2138
- *
2139
- * @param dataURI - The `DataUrl` potentially containing name and raw data to be converted to a Blob
2140
- * @returns - an object containing a Blob and its name, extracted from the URI
2141
- */
1567
+ // src/dataURItoBlob.ts
2142
1568
  function dataURItoBlob(dataURI) {
2143
- // Split metadata from data
2144
- const splitted = dataURI.split(',');
2145
- // Split params
2146
- const params = splitted[0].split(';');
2147
- // Get mime-type from params
2148
- const type = params[0].replace('data:', '');
2149
- // Filter the name property from params
2150
- const properties = params.filter(param => {
2151
- return param.split('=')[0] === 'name';
1569
+ const splitted = dataURI.split(",");
1570
+ const params = splitted[0].split(";");
1571
+ const type = params[0].replace("data:", "");
1572
+ const properties = params.filter((param) => {
1573
+ return param.split("=")[0] === "name";
2152
1574
  });
2153
- // Look for the name and use unknown if no name property.
2154
1575
  let name;
2155
1576
  if (properties.length !== 1) {
2156
- name = 'unknown';
1577
+ name = "unknown";
2157
1578
  } else {
2158
- // Because we filtered out the other property,
2159
- // we only have the name case here, which we decode to make it human-readable
2160
- name = decodeURI(properties[0].split('=')[1]);
1579
+ name = decodeURI(properties[0].split("=")[1]);
2161
1580
  }
2162
- // Built the Uint8Array Blob parameter from the base64 string.
2163
1581
  try {
2164
1582
  const binary = atob(splitted[1]);
2165
1583
  const array = [];
2166
1584
  for (let i = 0; i < binary.length; i++) {
2167
1585
  array.push(binary.charCodeAt(i));
2168
1586
  }
2169
- // Create the blob object
2170
- const blob = new window.Blob([new Uint8Array(array)], {
2171
- type
2172
- });
2173
- return {
2174
- blob,
2175
- name
2176
- };
1587
+ const blob = new window.Blob([new Uint8Array(array)], { type });
1588
+ return { blob, name };
2177
1589
  } catch (error) {
2178
- return {
2179
- blob: {
2180
- size: 0,
2181
- type: error.message
2182
- },
2183
- name: dataURI
2184
- };
1590
+ return { blob: { size: 0, type: error.message }, name: dataURI };
2185
1591
  }
2186
1592
  }
2187
1593
 
2188
- /** Potentially substitutes all replaceable parameters with the associated value(s) from the `params` if available. When
2189
- * a `params` array is provided, each value in the array is used to replace any of the replaceable parameters in the
2190
- * `inputString` using the `%1`, `%2`, etc. replacement specifiers.
2191
- *
2192
- * @param inputString - The string which will be potentially updated with replacement parameters
2193
- * @param params - The optional list of replaceable parameter values to substitute into the english string
2194
- * @returns - The updated string with any replacement specifiers replaced
2195
- */
1594
+ // src/replaceStringParameters.ts
2196
1595
  function replaceStringParameters(inputString, params) {
2197
1596
  let output = inputString;
2198
1597
  if (Array.isArray(params)) {
2199
1598
  const parts = output.split(/(%\d)/);
2200
1599
  params.forEach((param, index) => {
2201
- const partIndex = parts.findIndex(part => part === `%${index + 1}`);
1600
+ const partIndex = parts.findIndex((part) => part === `%${index + 1}`);
2202
1601
  if (partIndex >= 0) {
2203
1602
  parts[partIndex] = param;
2204
1603
  }
2205
1604
  });
2206
- output = parts.join('');
1605
+ output = parts.join("");
2207
1606
  }
2208
1607
  return output;
2209
1608
  }
2210
1609
 
2211
- /** Translates a `TranslatableString` value `stringToTranslate` into english. When a `params` array is provided, each
2212
- * value in the array is used to replace any of the replaceable parameters in the `stringToTranslate` using the `%1`,
2213
- * `%2`, etc. replacement specifiers.
2214
- *
2215
- * @param stringToTranslate - The `TranslatableString` value to convert to english
2216
- * @param params - The optional list of replaceable parameter values to substitute into the english string
2217
- * @returns - The `stringToTranslate` itself with any replaceable parameter values substituted
2218
- */
1610
+ // src/englishStringTranslator.ts
2219
1611
  function englishStringTranslator(stringToTranslate, params) {
2220
1612
  return replaceStringParameters(stringToTranslate, params);
2221
1613
  }
2222
1614
 
2223
- /** Returns the value(s) from `allEnumOptions` at the index(es) provided by `valueIndex`. If `valueIndex` is not an
2224
- * array AND the index is not valid for `allEnumOptions`, `emptyValue` is returned. If `valueIndex` is an array, AND it
2225
- * contains an invalid index, the returned array will have the resulting undefined values filtered out, leaving only
2226
- * valid values or in the worst case, an empty array.
2227
- *
2228
- * @param valueIndex - The index(es) of the value(s) that should be returned
2229
- * @param [allEnumOptions=[]] - The list of all the known enumOptions
2230
- * @param [emptyValue] - The value to return when the non-array `valueIndex` does not refer to a real option
2231
- * @returns - The single or list of values specified by the single or list of indexes if they are valid. Otherwise,
2232
- * `emptyValue` or an empty list.
2233
- */
1615
+ // src/enumOptionsDeselectValue.ts
1616
+ import isEqual3 from "lodash/isEqual";
1617
+
1618
+ // src/enumOptionsValueForIndex.ts
2234
1619
  function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
2235
1620
  if (Array.isArray(valueIndex)) {
2236
- return valueIndex.map(index => enumOptionsValueForIndex(index, allEnumOptions)).filter(val => val);
1621
+ return valueIndex.map((index2) => enumOptionsValueForIndex(index2, allEnumOptions)).filter((val) => val);
2237
1622
  }
2238
- // So Number(null) and Number('') both return 0, so use emptyValue for those two values
2239
- const index = valueIndex === '' || valueIndex === null ? -1 : Number(valueIndex);
1623
+ const index = valueIndex === "" || valueIndex === null ? -1 : Number(valueIndex);
2240
1624
  const option = allEnumOptions[index];
2241
1625
  return option ? option.value : emptyValue;
2242
1626
  }
2243
1627
 
2244
- /** Removes the enum option value at the `valueIndex` from the currently `selected` (list of) value(s). If `selected` is
2245
- * a list, then that list is updated to remove the enum option value with the `valueIndex` in `allEnumOptions`. If it is
2246
- * a single value, then if the enum option value with the `valueIndex` in `allEnumOptions` matches `selected`, undefined
2247
- * is returned, otherwise the `selected` value is returned.
2248
- *
2249
- * @param valueIndex - The index of the value to be removed from the selected list or single value
2250
- * @param selected - The current (list of) selected value(s)
2251
- * @param [allEnumOptions=[]] - The list of all the known enumOptions
2252
- * @returns - The updated `selected` with the enum option value at `valueIndex` in `allEnumOptions` removed from it,
2253
- * unless `selected` is a single value. In that case, if the `valueIndex` value matches `selected`, returns
2254
- * undefined, otherwise `selected`.
2255
- */
1628
+ // src/enumOptionsDeselectValue.ts
2256
1629
  function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions = []) {
2257
1630
  const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
2258
1631
  if (Array.isArray(selected)) {
2259
- return selected.filter(v => !isEqual(v, value));
1632
+ return selected.filter((v) => !isEqual3(v, value));
2260
1633
  }
2261
- return isEqual(value, selected) ? undefined : selected;
1634
+ return isEqual3(value, selected) ? void 0 : selected;
2262
1635
  }
2263
1636
 
2264
- /** Determines whether the given `value` is (one of) the `selected` value(s).
2265
- *
2266
- * @param value - The value being checked to see if it is selected
2267
- * @param selected - The current selected value or list of values
2268
- * @returns - true if the `value` is one of the `selected` ones, false otherwise
2269
- */
1637
+ // src/enumOptionsIsSelected.ts
1638
+ import isEqual4 from "lodash/isEqual";
2270
1639
  function enumOptionsIsSelected(value, selected) {
2271
1640
  if (Array.isArray(selected)) {
2272
- return selected.some(sel => isEqual(sel, value));
2273
- }
2274
- return isEqual(selected, value);
2275
- }
2276
-
2277
- /** Returns the index(es) of the options in `allEnumOptions` whose value(s) match the ones in `value`. All the
2278
- * `enumOptions` are filtered based on whether they are a "selected" `value` and the index of each selected one is then
2279
- * stored in an array. If `multiple` is true, that array is returned, otherwise the first element in the array is
2280
- * returned.
2281
- *
2282
- * @param value - The single value or list of values for which indexes are desired
2283
- * @param [allEnumOptions=[]] - The list of all the known enumOptions
2284
- * @param [multiple=false] - Optional flag, if true will return a list of index, otherwise a single one
2285
- * @returns - A single string index for the first `value` in `allEnumOptions`, if not `multiple`. Otherwise, the list
2286
- * of indexes for (each of) the value(s) in `value`.
2287
- */
1641
+ return selected.some((sel) => isEqual4(sel, value));
1642
+ }
1643
+ return isEqual4(selected, value);
1644
+ }
1645
+
1646
+ // src/enumOptionsIndexForValue.ts
2288
1647
  function enumOptionsIndexForValue(value, allEnumOptions = [], multiple = false) {
2289
- const selectedIndexes = allEnumOptions.map((opt, index) => enumOptionsIsSelected(opt.value, value) ? String(index) : undefined).filter(opt => typeof opt !== 'undefined');
1648
+ const selectedIndexes = allEnumOptions.map((opt, index) => enumOptionsIsSelected(opt.value, value) ? String(index) : void 0).filter((opt) => typeof opt !== "undefined");
2290
1649
  if (!multiple) {
2291
1650
  return selectedIndexes[0];
2292
1651
  }
2293
1652
  return selectedIndexes;
2294
1653
  }
2295
1654
 
2296
- /** Add the enum option value at the `valueIndex` to the list of `selected` values in the proper order as defined by
2297
- * `allEnumOptions`
2298
- *
2299
- * @param valueIndex - The index of the value that should be selected
2300
- * @param selected - The current list of selected values
2301
- * @param [allEnumOptions=[]] - The list of all the known enumOptions
2302
- * @returns - The updated list of selected enum values with enum value at the `valueIndex` added to it
2303
- */
1655
+ // src/enumOptionsSelectValue.ts
1656
+ import { isNil } from "lodash";
2304
1657
  function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
2305
1658
  const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
2306
1659
  if (!isNil(value)) {
2307
- const index = allEnumOptions.findIndex(opt => value === opt.value);
2308
- const all = allEnumOptions.map(({
2309
- value: val
2310
- }) => val);
1660
+ const index = allEnumOptions.findIndex((opt) => value === opt.value);
1661
+ const all = allEnumOptions.map(({ value: val }) => val);
2311
1662
  const updated = selected.slice(0, index).concat(value, selected.slice(index));
2312
- // As inserting values at predefined index positions doesn't work with empty
2313
- // arrays, we need to reorder the updated selection to match the initial order
2314
1663
  return updated.sort((a, b) => Number(all.indexOf(a) > all.indexOf(b)));
2315
1664
  }
2316
1665
  return selected;
2317
1666
  }
2318
1667
 
2319
- /** The `ErrorSchemaBuilder<T>` is used to build an `ErrorSchema<T>` since the definition of the `ErrorSchema` type is
2320
- * designed for reading information rather than writing it. Use this class to add, replace or clear errors in an error
2321
- * schema by using either dotted path or an array of path names. Once you are done building the `ErrorSchema`, you can
2322
- * get the result and/or reset all the errors back to an initial set and start again.
2323
- */
2324
- class ErrorSchemaBuilder {
2325
- /** Construct an `ErrorSchemaBuilder` with an optional initial set of errors in an `ErrorSchema`.
2326
- *
2327
- * @param [initialSchema] - The optional set of initial errors, that will be cloned into the class
1668
+ // src/ErrorSchemaBuilder.ts
1669
+ import cloneDeep from "lodash/cloneDeep";
1670
+ import get10 from "lodash/get";
1671
+ import set3 from "lodash/set";
1672
+ var ErrorSchemaBuilder = class {
1673
+ /** Construct an `ErrorSchemaBuilder` with an optional initial set of errors in an `ErrorSchema`.
1674
+ *
1675
+ * @param [initialSchema] - The optional set of initial errors, that will be cloned into the class
2328
1676
  */
2329
1677
  constructor(initialSchema) {
2330
- /** The error schema being built
2331
- *
2332
- * @private
1678
+ /** The error schema being built
1679
+ *
1680
+ * @private
2333
1681
  */
2334
1682
  this.errorSchema = {};
2335
1683
  this.resetAllErrors(initialSchema);
2336
1684
  }
2337
- /** Returns the `ErrorSchema` that has been updated by the methods of the `ErrorSchemaBuilder`
1685
+ /** Returns the `ErrorSchema` that has been updated by the methods of the `ErrorSchemaBuilder`
2338
1686
  */
2339
1687
  get ErrorSchema() {
2340
1688
  return this.errorSchema;
2341
1689
  }
2342
- /** Will get an existing `ErrorSchema` at the specified `pathOfError` or create and return one.
2343
- *
2344
- * @param [pathOfError] - The optional path into the `ErrorSchema` at which to add the error(s)
2345
- * @returns - The error block for the given `pathOfError` or the root if not provided
2346
- * @private
1690
+ /** Will get an existing `ErrorSchema` at the specified `pathOfError` or create and return one.
1691
+ *
1692
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to add the error(s)
1693
+ * @returns - The error block for the given `pathOfError` or the root if not provided
1694
+ * @private
2347
1695
  */
2348
1696
  getOrCreateErrorBlock(pathOfError) {
2349
- const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === 'string';
2350
- let errorBlock = hasPath ? get(this.errorSchema, pathOfError) : this.errorSchema;
1697
+ const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
1698
+ let errorBlock = hasPath ? get10(this.errorSchema, pathOfError) : this.errorSchema;
2351
1699
  if (!errorBlock && pathOfError) {
2352
1700
  errorBlock = {};
2353
- set(this.errorSchema, pathOfError, errorBlock);
1701
+ set3(this.errorSchema, pathOfError, errorBlock);
2354
1702
  }
2355
1703
  return errorBlock;
2356
1704
  }
2357
- /** Resets all errors in the `ErrorSchemaBuilder` back to the `initialSchema` if provided, otherwise an empty set.
2358
- *
2359
- * @param [initialSchema] - The optional set of initial errors, that will be cloned into the class
2360
- * @returns - The `ErrorSchemaBuilder` object for chaining purposes
1705
+ /** Resets all errors in the `ErrorSchemaBuilder` back to the `initialSchema` if provided, otherwise an empty set.
1706
+ *
1707
+ * @param [initialSchema] - The optional set of initial errors, that will be cloned into the class
1708
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
2361
1709
  */
2362
1710
  resetAllErrors(initialSchema) {
2363
1711
  this.errorSchema = initialSchema ? cloneDeep(initialSchema) : {};
2364
1712
  return this;
2365
1713
  }
2366
- /** Adds the `errorOrList` to the list of errors in the `ErrorSchema` at either the root level or the location within
2367
- * the schema described by the `pathOfError`. For more information about how to specify the path see the
2368
- * [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
2369
- *
2370
- * @param errorOrList - The error or list of errors to add into the `ErrorSchema`
2371
- * @param [pathOfError] - The optional path into the `ErrorSchema` at which to add the error(s)
2372
- * @returns - The `ErrorSchemaBuilder` object for chaining purposes
1714
+ /** Adds the `errorOrList` to the list of errors in the `ErrorSchema` at either the root level or the location within
1715
+ * the schema described by the `pathOfError`. For more information about how to specify the path see the
1716
+ * [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
1717
+ *
1718
+ * @param errorOrList - The error or list of errors to add into the `ErrorSchema`
1719
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to add the error(s)
1720
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
2373
1721
  */
2374
1722
  addErrors(errorOrList, pathOfError) {
2375
1723
  const errorBlock = this.getOrCreateErrorBlock(pathOfError);
2376
- let errorsList = get(errorBlock, ERRORS_KEY);
1724
+ let errorsList = get10(errorBlock, ERRORS_KEY);
2377
1725
  if (!Array.isArray(errorsList)) {
2378
1726
  errorsList = [];
2379
1727
  errorBlock[ERRORS_KEY] = errorsList;
@@ -2385,41 +1733,35 @@ class ErrorSchemaBuilder {
2385
1733
  }
2386
1734
  return this;
2387
1735
  }
2388
- /** Sets/replaces the `errorOrList` as the error(s) in the `ErrorSchema` at either the root level or the location
2389
- * within the schema described by the `pathOfError`. For more information about how to specify the path see the
2390
- * [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
2391
- *
2392
- * @param errorOrList - The error or list of errors to set into the `ErrorSchema`
2393
- * @param [pathOfError] - The optional path into the `ErrorSchema` at which to set the error(s)
2394
- * @returns - The `ErrorSchemaBuilder` object for chaining purposes
1736
+ /** Sets/replaces the `errorOrList` as the error(s) in the `ErrorSchema` at either the root level or the location
1737
+ * within the schema described by the `pathOfError`. For more information about how to specify the path see the
1738
+ * [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
1739
+ *
1740
+ * @param errorOrList - The error or list of errors to set into the `ErrorSchema`
1741
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to set the error(s)
1742
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
2395
1743
  */
2396
1744
  setErrors(errorOrList, pathOfError) {
2397
1745
  const errorBlock = this.getOrCreateErrorBlock(pathOfError);
2398
- // Effectively clone the array being given to prevent accidental outside manipulation of the given list
2399
1746
  const listToAdd = Array.isArray(errorOrList) ? [...errorOrList] : [errorOrList];
2400
- set(errorBlock, ERRORS_KEY, listToAdd);
1747
+ set3(errorBlock, ERRORS_KEY, listToAdd);
2401
1748
  return this;
2402
1749
  }
2403
- /** Clears the error(s) in the `ErrorSchema` at either the root level or the location within the schema described by
2404
- * the `pathOfError`. For more information about how to specify the path see the
2405
- * [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
2406
- *
2407
- * @param [pathOfError] - The optional path into the `ErrorSchema` at which to clear the error(s)
2408
- * @returns - The `ErrorSchemaBuilder` object for chaining purposes
1750
+ /** Clears the error(s) in the `ErrorSchema` at either the root level or the location within the schema described by
1751
+ * the `pathOfError`. For more information about how to specify the path see the
1752
+ * [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
1753
+ *
1754
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to clear the error(s)
1755
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
2409
1756
  */
2410
1757
  clearErrors(pathOfError) {
2411
1758
  const errorBlock = this.getOrCreateErrorBlock(pathOfError);
2412
- set(errorBlock, ERRORS_KEY, []);
1759
+ set3(errorBlock, ERRORS_KEY, []);
2413
1760
  return this;
2414
1761
  }
2415
- }
1762
+ };
2416
1763
 
2417
- /** Extracts the range spec information `{ step?: number, min?: number, max?: number }` that can be spread onto an HTML
2418
- * input from the range analog in the schema `{ multipleOf?: number, minimum?: number, maximum?: number }`.
2419
- *
2420
- * @param schema - The schema from which to extract the range spec
2421
- * @returns - A range specification from the schema
2422
- */
1764
+ // src/rangeSpec.ts
2423
1765
  function rangeSpec(schema) {
2424
1766
  const spec = {};
2425
1767
  if (schema.multipleOf) {
@@ -2434,37 +1776,23 @@ function rangeSpec(schema) {
2434
1776
  return spec;
2435
1777
  }
2436
1778
 
2437
- /** Using the `schema`, `defaultType` and `options`, extract out the props for the <input> element that make sense.
2438
- *
2439
- * @param schema - The schema for the field provided by the widget
2440
- * @param [defaultType] - The default type, if any, for the field provided by the widget
2441
- * @param [options={}] - The UI Options for the field provided by the widget
2442
- * @param [autoDefaultStepAny=true] - Determines whether to auto-default step=any when the type is number and no step
2443
- * @returns - The extracted `InputPropsType` object
2444
- */
1779
+ // src/getInputProps.ts
2445
1780
  function getInputProps(schema, defaultType, options = {}, autoDefaultStepAny = true) {
2446
1781
  const inputProps = {
2447
- type: defaultType || 'text',
1782
+ type: defaultType || "text",
2448
1783
  ...rangeSpec(schema)
2449
1784
  };
2450
- // If options.inputType is set use that as the input type
2451
1785
  if (options.inputType) {
2452
1786
  inputProps.type = options.inputType;
2453
1787
  } else if (!defaultType) {
2454
- // If the schema is of type number or integer, set the input type to number
2455
- if (schema.type === 'number') {
2456
- inputProps.type = 'number';
2457
- // Only add step if one isn't already defined and we are auto-defaulting the "any" step
2458
- if (autoDefaultStepAny && inputProps.step === undefined) {
2459
- // Setting step to 'any' fixes a bug in Safari where decimals are not
2460
- // allowed in number inputs
2461
- inputProps.step = 'any';
1788
+ if (schema.type === "number") {
1789
+ inputProps.type = "number";
1790
+ if (autoDefaultStepAny && inputProps.step === void 0) {
1791
+ inputProps.step = "any";
2462
1792
  }
2463
- } else if (schema.type === 'integer') {
2464
- inputProps.type = 'number';
2465
- // Only add step if one isn't already defined
2466
- if (inputProps.step === undefined) {
2467
- // Since this is integer, you always want to step up or down in multiples of 1
1793
+ } else if (schema.type === "integer") {
1794
+ inputProps.type = "number";
1795
+ if (inputProps.step === void 0) {
2468
1796
  inputProps.step = 1;
2469
1797
  }
2470
1798
  }
@@ -2475,45 +1803,27 @@ function getInputProps(schema, defaultType, options = {}, autoDefaultStepAny = t
2475
1803
  return inputProps;
2476
1804
  }
2477
1805
 
2478
- /** The default submit button options, exported for testing purposes
2479
- */
2480
- const DEFAULT_OPTIONS = {
1806
+ // src/getSubmitButtonOptions.ts
1807
+ var DEFAULT_OPTIONS = {
2481
1808
  props: {
2482
1809
  disabled: false
2483
1810
  },
2484
- submitText: 'Submit',
1811
+ submitText: "Submit",
2485
1812
  norender: false
2486
1813
  };
2487
- /** Extracts any `ui:submitButtonOptions` from the `uiSchema` and merges them onto the `DEFAULT_OPTIONS`
2488
- *
2489
- * @param [uiSchema={}] - the UI Schema from which to extract submit button props
2490
- * @returns - The merging of the `DEFAULT_OPTIONS` with any custom ones
2491
- */
2492
1814
  function getSubmitButtonOptions(uiSchema = {}) {
2493
1815
  const uiOptions = getUiOptions(uiSchema);
2494
1816
  if (uiOptions && uiOptions[SUBMIT_BTN_OPTIONS_KEY]) {
2495
1817
  const options = uiOptions[SUBMIT_BTN_OPTIONS_KEY];
2496
- return {
2497
- ...DEFAULT_OPTIONS,
2498
- ...options
2499
- };
1818
+ return { ...DEFAULT_OPTIONS, ...options };
2500
1819
  }
2501
1820
  return DEFAULT_OPTIONS;
2502
1821
  }
2503
1822
 
2504
- /** Returns the template with the given `name` from either the `uiSchema` if it is defined or from the `registry`
2505
- * otherwise. NOTE, since `ButtonTemplates` are not overridden in `uiSchema` only those in the `registry` are returned.
2506
- *
2507
- * @param name - The name of the template to fetch, restricted to the keys of `TemplatesType`
2508
- * @param registry - The `Registry` from which to read the template
2509
- * @param [uiOptions={}] - The `UIOptionsType` from which to read an alternate template
2510
- * @returns - The template from either the `uiSchema` or `registry` for the `name`
2511
- */
1823
+ // src/getTemplate.ts
2512
1824
  function getTemplate(name, registry, uiOptions = {}) {
2513
- const {
2514
- templates
2515
- } = registry;
2516
- if (name === 'ButtonTemplates') {
1825
+ const { templates } = registry;
1826
+ if (name === "ButtonTemplates") {
2517
1827
  return templates[name];
2518
1828
  }
2519
1829
  return (
@@ -2523,112 +1833,88 @@ function getTemplate(name, registry, uiOptions = {}) {
2523
1833
  );
2524
1834
  }
2525
1835
 
2526
- /** The map of schema types to widget type to widget name
2527
- */
2528
- const widgetMap = {
1836
+ // src/getWidget.tsx
1837
+ import { createElement } from "react";
1838
+ import ReactIs from "react-is";
1839
+ import get11 from "lodash/get";
1840
+ import set4 from "lodash/set";
1841
+ import { jsx } from "react/jsx-runtime";
1842
+ var widgetMap = {
2529
1843
  boolean: {
2530
- checkbox: 'CheckboxWidget',
2531
- radio: 'RadioWidget',
2532
- select: 'SelectWidget',
2533
- hidden: 'HiddenWidget'
1844
+ checkbox: "CheckboxWidget",
1845
+ radio: "RadioWidget",
1846
+ select: "SelectWidget",
1847
+ hidden: "HiddenWidget"
2534
1848
  },
2535
1849
  string: {
2536
- text: 'TextWidget',
2537
- password: 'PasswordWidget',
2538
- email: 'EmailWidget',
2539
- hostname: 'TextWidget',
2540
- ipv4: 'TextWidget',
2541
- ipv6: 'TextWidget',
2542
- uri: 'URLWidget',
2543
- 'data-url': 'FileWidget',
2544
- radio: 'RadioWidget',
2545
- select: 'SelectWidget',
2546
- textarea: 'TextareaWidget',
2547
- hidden: 'HiddenWidget',
2548
- date: 'DateWidget',
2549
- datetime: 'DateTimeWidget',
2550
- 'date-time': 'DateTimeWidget',
2551
- 'alt-date': 'AltDateWidget',
2552
- 'alt-datetime': 'AltDateTimeWidget',
2553
- time: 'TimeWidget',
2554
- color: 'ColorWidget',
2555
- file: 'FileWidget'
1850
+ text: "TextWidget",
1851
+ password: "PasswordWidget",
1852
+ email: "EmailWidget",
1853
+ hostname: "TextWidget",
1854
+ ipv4: "TextWidget",
1855
+ ipv6: "TextWidget",
1856
+ uri: "URLWidget",
1857
+ "data-url": "FileWidget",
1858
+ radio: "RadioWidget",
1859
+ select: "SelectWidget",
1860
+ textarea: "TextareaWidget",
1861
+ hidden: "HiddenWidget",
1862
+ date: "DateWidget",
1863
+ datetime: "DateTimeWidget",
1864
+ "date-time": "DateTimeWidget",
1865
+ "alt-date": "AltDateWidget",
1866
+ "alt-datetime": "AltDateTimeWidget",
1867
+ time: "TimeWidget",
1868
+ color: "ColorWidget",
1869
+ file: "FileWidget"
2556
1870
  },
2557
1871
  number: {
2558
- text: 'TextWidget',
2559
- select: 'SelectWidget',
2560
- updown: 'UpDownWidget',
2561
- range: 'RangeWidget',
2562
- radio: 'RadioWidget',
2563
- hidden: 'HiddenWidget'
1872
+ text: "TextWidget",
1873
+ select: "SelectWidget",
1874
+ updown: "UpDownWidget",
1875
+ range: "RangeWidget",
1876
+ radio: "RadioWidget",
1877
+ hidden: "HiddenWidget"
2564
1878
  },
2565
1879
  integer: {
2566
- text: 'TextWidget',
2567
- select: 'SelectWidget',
2568
- updown: 'UpDownWidget',
2569
- range: 'RangeWidget',
2570
- radio: 'RadioWidget',
2571
- hidden: 'HiddenWidget'
1880
+ text: "TextWidget",
1881
+ select: "SelectWidget",
1882
+ updown: "UpDownWidget",
1883
+ range: "RangeWidget",
1884
+ radio: "RadioWidget",
1885
+ hidden: "HiddenWidget"
2572
1886
  },
2573
1887
  array: {
2574
- select: 'SelectWidget',
2575
- checkboxes: 'CheckboxesWidget',
2576
- files: 'FileWidget',
2577
- hidden: 'HiddenWidget'
1888
+ select: "SelectWidget",
1889
+ checkboxes: "CheckboxesWidget",
1890
+ files: "FileWidget",
1891
+ hidden: "HiddenWidget"
2578
1892
  }
2579
1893
  };
2580
- /** Wraps the given widget with stateless functional component that will merge any `defaultProps.options` with the
2581
- * `options` that are provided in the props. It will add the wrapper component as a `MergedWidget` property onto the
2582
- * `Widget` so that future attempts to wrap `AWidget` will return the already existing wrapper.
2583
- *
2584
- * @param AWidget - A widget that will be wrapped or one that is already wrapped
2585
- * @returns - The wrapper widget
2586
- */
2587
1894
  function mergeWidgetOptions(AWidget) {
2588
- let MergedWidget = get(AWidget, 'MergedWidget');
2589
- // cache return value as property of widget for proper react reconciliation
1895
+ let MergedWidget = get11(AWidget, "MergedWidget");
2590
1896
  if (!MergedWidget) {
2591
1897
  const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
2592
- MergedWidget = ({
2593
- options,
2594
- ...props
2595
- }) => {
2596
- return jsx(AWidget, {
2597
- options: {
2598
- ...defaultOptions,
2599
- ...options
2600
- },
2601
- ...props
2602
- });
1898
+ MergedWidget = ({ options, ...props }) => {
1899
+ return /* @__PURE__ */ jsx(AWidget, { options: { ...defaultOptions, ...options }, ...props });
2603
1900
  };
2604
- set(AWidget, 'MergedWidget', MergedWidget);
1901
+ set4(AWidget, "MergedWidget", MergedWidget);
2605
1902
  }
2606
1903
  return MergedWidget;
2607
1904
  }
2608
- /** Given a schema representing a field to render and either the name or actual `Widget` implementation, returns the
2609
- * React component that is used to render the widget. If the `widget` is already a React component, then it is wrapped
2610
- * with a `MergedWidget`. Otherwise an attempt is made to look up the widget inside of the `registeredWidgets` map based
2611
- * on the schema type and `widget` name. If no widget component can be found an `Error` is thrown.
2612
- *
2613
- * @param schema - The schema for the field
2614
- * @param [widget] - Either the name of the widget OR a `Widget` implementation to use
2615
- * @param [registeredWidgets={}] - A registry of widget name to `Widget` implementation
2616
- * @returns - The `Widget` component to use
2617
- * @throws - An error if there is no `Widget` component that can be returned
2618
- */
2619
1905
  function getWidget(schema, widget, registeredWidgets = {}) {
2620
1906
  const type = getSchemaType(schema);
2621
- if (typeof widget === 'function' || widget && ReactIs.isForwardRef( /*#__PURE__*/createElement(widget)) || ReactIs.isMemo(widget)) {
1907
+ if (typeof widget === "function" || widget && ReactIs.isForwardRef(createElement(widget)) || ReactIs.isMemo(widget)) {
2622
1908
  return mergeWidgetOptions(widget);
2623
1909
  }
2624
- if (typeof widget !== 'string') {
1910
+ if (typeof widget !== "string") {
2625
1911
  throw new Error(`Unsupported widget definition: ${typeof widget}`);
2626
1912
  }
2627
1913
  if (widget in registeredWidgets) {
2628
1914
  const registeredWidget = registeredWidgets[widget];
2629
1915
  return getWidget(schema, registeredWidget, registeredWidgets);
2630
1916
  }
2631
- if (typeof type === 'string') {
1917
+ if (typeof type === "string") {
2632
1918
  if (!(type in widgetMap)) {
2633
1919
  throw new Error(`No widget for type '${type}'`);
2634
1920
  }
@@ -2640,148 +1926,76 @@ function getWidget(schema, widget, registeredWidgets = {}) {
2640
1926
  throw new Error(`No widget '${widget}' for type '${type}'`);
2641
1927
  }
2642
1928
 
2643
- /** JS has no built-in hashing function, so rolling our own
2644
- * based on Java's hashing fn:
2645
- * http://www.java2s.com/example/nodejs-utility-method/string-hash/hashcode-4dc2b.html
2646
- *
2647
- * @param string - The string for which to get the hash
2648
- * @returns - The resulting hash of the string in hex format
2649
- */
1929
+ // src/hashForSchema.ts
2650
1930
  function hashString(string) {
2651
1931
  let hash = 0;
2652
1932
  for (let i = 0; i < string.length; i += 1) {
2653
1933
  const chr = string.charCodeAt(i);
2654
1934
  hash = (hash << 5) - hash + chr;
2655
- hash = hash & hash; // Convert to 32bit integer
1935
+ hash = hash & hash;
2656
1936
  }
2657
-
2658
1937
  return hash.toString(16);
2659
1938
  }
2660
- /** Stringifies the schema and returns the hash of the resulting string. Sorts schema fields
2661
- * in consistent order before stringify to prevent different hash ids for the same schema.
2662
- *
2663
- * @param schema - The schema for which the hash is desired
2664
- * @returns - The string obtained from the hash of the stringified schema
2665
- */
2666
1939
  function hashForSchema(schema) {
2667
- const allKeys = new Set();
2668
- // solution source: https://stackoverflow.com/questions/16167581/sort-object-properties-and-json-stringify/53593328#53593328
1940
+ const allKeys = /* @__PURE__ */ new Set();
2669
1941
  JSON.stringify(schema, (key, value) => (allKeys.add(key), value));
2670
1942
  return hashString(JSON.stringify(schema, Array.from(allKeys).sort()));
2671
1943
  }
2672
1944
 
2673
- /** Detects whether the `widget` exists for the `schema` with the associated `registryWidgets` and returns true if it
2674
- * does, or false if it doesn't.
2675
- *
2676
- * @param schema - The schema for the field
2677
- * @param widget - Either the name of the widget OR a `Widget` implementation to use
2678
- * @param [registeredWidgets={}] - A registry of widget name to `Widget` implementation
2679
- * @returns - True if the widget exists, false otherwise
2680
- */
1945
+ // src/hasWidget.ts
2681
1946
  function hasWidget(schema, widget, registeredWidgets = {}) {
2682
1947
  try {
2683
1948
  getWidget(schema, widget, registeredWidgets);
2684
1949
  return true;
2685
1950
  } catch (e) {
2686
1951
  const err = e;
2687
- if (err.message && (err.message.startsWith('No widget') || err.message.startsWith('Unsupported widget'))) {
1952
+ if (err.message && (err.message.startsWith("No widget") || err.message.startsWith("Unsupported widget"))) {
2688
1953
  return false;
2689
1954
  }
2690
1955
  throw e;
2691
1956
  }
2692
1957
  }
2693
1958
 
2694
- /** Generates a consistent `id` pattern for a given `id` and a `suffix`
2695
- *
2696
- * @param id - Either simple string id or an IdSchema from which to extract it
2697
- * @param suffix - The suffix to append to the id
2698
- */
1959
+ // src/idGenerators.ts
1960
+ import isString3 from "lodash/isString";
2699
1961
  function idGenerator(id, suffix) {
2700
- const theId = isString(id) ? id : id[ID_KEY];
1962
+ const theId = isString3(id) ? id : id[ID_KEY];
2701
1963
  return `${theId}__${suffix}`;
2702
1964
  }
2703
- /** Return a consistent `id` for the field description element
2704
- *
2705
- * @param id - Either simple string id or an IdSchema from which to extract it
2706
- * @returns - The consistent id for the field description element from the given `id`
2707
- */
2708
1965
  function descriptionId(id) {
2709
- return idGenerator(id, 'description');
1966
+ return idGenerator(id, "description");
2710
1967
  }
2711
- /** Return a consistent `id` for the field error element
2712
- *
2713
- * @param id - Either simple string id or an IdSchema from which to extract it
2714
- * @returns - The consistent id for the field error element from the given `id`
2715
- */
2716
1968
  function errorId(id) {
2717
- return idGenerator(id, 'error');
1969
+ return idGenerator(id, "error");
2718
1970
  }
2719
- /** Return a consistent `id` for the field examples element
2720
- *
2721
- * @param id - Either simple string id or an IdSchema from which to extract it
2722
- * @returns - The consistent id for the field examples element from the given `id`
2723
- */
2724
1971
  function examplesId(id) {
2725
- return idGenerator(id, 'examples');
1972
+ return idGenerator(id, "examples");
2726
1973
  }
2727
- /** Return a consistent `id` for the field help element
2728
- *
2729
- * @param id - Either simple string id or an IdSchema from which to extract it
2730
- * @returns - The consistent id for the field help element from the given `id`
2731
- */
2732
1974
  function helpId(id) {
2733
- return idGenerator(id, 'help');
1975
+ return idGenerator(id, "help");
2734
1976
  }
2735
- /** Return a consistent `id` for the field title element
2736
- *
2737
- * @param id - Either simple string id or an IdSchema from which to extract it
2738
- * @returns - The consistent id for the field title element from the given `id`
2739
- */
2740
1977
  function titleId(id) {
2741
- return idGenerator(id, 'title');
2742
- }
2743
- /** Return a list of element ids that contain additional information about the field that can be used to as the aria
2744
- * description of the field. This is correctly omitting `titleId` which would be "labeling" rather than "describing" the
2745
- * element.
2746
- *
2747
- * @param id - Either simple string id or an IdSchema from which to extract it
2748
- * @param [includeExamples=false] - Optional flag, if true, will add the `examplesId` into the list
2749
- * @returns - The string containing the list of ids for use in an `aria-describedBy` attribute
2750
- */
1978
+ return idGenerator(id, "title");
1979
+ }
2751
1980
  function ariaDescribedByIds(id, includeExamples = false) {
2752
- const examples = includeExamples ? ` ${examplesId(id)}` : '';
1981
+ const examples = includeExamples ? ` ${examplesId(id)}` : "";
2753
1982
  return `${errorId(id)} ${descriptionId(id)} ${helpId(id)}${examples}`;
2754
1983
  }
2755
- /** Return a consistent `id` for the `optionIndex`s of a `Radio` or `Checkboxes` widget
2756
- *
2757
- * @param id - The id of the parent component for the option
2758
- * @param optionIndex - The index of the option for which the id is desired
2759
- * @returns - An id for the option index based on the parent `id`
2760
- */
2761
1984
  function optionId(id, optionIndex) {
2762
1985
  return `${id}-${optionIndex}`;
2763
1986
  }
2764
1987
 
1988
+ // src/labelValue.ts
2765
1989
  function labelValue(label, hideLabel, fallback) {
2766
1990
  return hideLabel ? fallback : label;
2767
1991
  }
2768
1992
 
2769
- /** Converts a local Date string into a UTC date string
2770
- *
2771
- * @param dateString - The string representation of a date as accepted by the `Date()` constructor
2772
- * @returns - A UTC date string if `dateString` is truthy, otherwise undefined
2773
- */
1993
+ // src/localToUTC.ts
2774
1994
  function localToUTC(dateString) {
2775
- return dateString ? new Date(dateString).toJSON() : undefined;
1995
+ return dateString ? new Date(dateString).toJSON() : void 0;
2776
1996
  }
2777
1997
 
2778
- /** Returns the constant value from the schema when it is either a single value enum or has a const key. Otherwise
2779
- * throws an error.
2780
- *
2781
- * @param schema - The schema from which to obtain the constant value
2782
- * @returns - The constant value for the schema
2783
- * @throws - Error when the schema does not have a constant value
2784
- */
1998
+ // src/toConstant.ts
2785
1999
  function toConstant(schema) {
2786
2000
  if (ENUM_KEY in schema && Array.isArray(schema.enum) && schema.enum.length === 1) {
2787
2001
  return schema.enum[0];
@@ -2789,35 +2003,23 @@ function toConstant(schema) {
2789
2003
  if (CONST_KEY in schema) {
2790
2004
  return schema.const;
2791
2005
  }
2792
- throw new Error('schema cannot be inferred as a constant');
2006
+ throw new Error("schema cannot be inferred as a constant");
2793
2007
  }
2794
2008
 
2795
- /** Gets the list of options from the schema. If the schema has an enum list, then those enum values are returned. The
2796
- * labels for the options will be extracted from the non-standard, RJSF-deprecated `enumNames` if it exists, otherwise
2797
- * the label will be the same as the `value`. If the schema has a `oneOf` or `anyOf`, then the value is the list of
2798
- * `const` values from the schema and the label is either the `schema.title` or the value.
2799
- *
2800
- * @param schema - The schema from which to extract the options list
2801
- * @returns - The list of options from the schema
2802
- */
2009
+ // src/optionsList.ts
2803
2010
  function optionsList(schema) {
2804
- // enumNames was deprecated in v5 and is intentionally omitted from the RJSFSchema type.
2805
- // Cast the type to include enumNames so the feature still works.
2806
2011
  const schemaWithEnumNames = schema;
2807
- if (schemaWithEnumNames.enumNames && process.env.NODE_ENV !== 'production') {
2808
- console.warn('The enumNames property is deprecated and may be removed in a future major release.');
2012
+ if (schemaWithEnumNames.enumNames && true) {
2013
+ console.warn("The enumNames property is deprecated and may be removed in a future major release.");
2809
2014
  }
2810
2015
  if (schema.enum) {
2811
2016
  return schema.enum.map((value, i) => {
2812
2017
  const label = schemaWithEnumNames.enumNames && schemaWithEnumNames.enumNames[i] || String(value);
2813
- return {
2814
- label,
2815
- value
2816
- };
2018
+ return { label, value };
2817
2019
  });
2818
2020
  }
2819
2021
  const altSchemas = schema.oneOf || schema.anyOf;
2820
- return altSchemas && altSchemas.map(aSchemaDef => {
2022
+ return altSchemas && altSchemas.map((aSchemaDef) => {
2821
2023
  const aSchema = aSchemaDef;
2822
2024
  const value = toConstant(aSchema);
2823
2025
  const label = aSchema.title || String(value);
@@ -2829,65 +2031,45 @@ function optionsList(schema) {
2829
2031
  });
2830
2032
  }
2831
2033
 
2832
- /** Given a list of `properties` and an `order` list, returns a list that contains the `properties` ordered correctly.
2833
- * If `order` is not an array, then the untouched `properties` list is returned. Otherwise `properties` is ordered per
2834
- * the `order` list. If `order` contains a '*' then any `properties` that are not mentioned explicity in `order` will be
2835
- * places in the location of the `*`.
2836
- *
2837
- * @param properties - The list of property keys to be ordered
2838
- * @param order - An array of property keys to be ordered first, with an optional '*' property
2839
- * @returns - A list with the `properties` ordered
2840
- * @throws - Error when the properties cannot be ordered correctly
2841
- */
2034
+ // src/orderProperties.ts
2842
2035
  function orderProperties(properties, order) {
2843
2036
  if (!Array.isArray(order)) {
2844
2037
  return properties;
2845
2038
  }
2846
- const arrayToHash = arr => arr.reduce((prev, curr) => {
2039
+ const arrayToHash = (arr) => arr.reduce((prev, curr) => {
2847
2040
  prev[curr] = true;
2848
2041
  return prev;
2849
2042
  }, {});
2850
- const errorPropList = arr => arr.length > 1 ? `properties '${arr.join("', '")}'` : `property '${arr[0]}'`;
2043
+ const errorPropList = (arr) => arr.length > 1 ? `properties '${arr.join("', '")}'` : `property '${arr[0]}'`;
2851
2044
  const propertyHash = arrayToHash(properties);
2852
- const orderFiltered = order.filter(prop => prop === '*' || propertyHash[prop]);
2045
+ const orderFiltered = order.filter((prop) => prop === "*" || propertyHash[prop]);
2853
2046
  const orderHash = arrayToHash(orderFiltered);
2854
- const rest = properties.filter(prop => !orderHash[prop]);
2855
- const restIndex = orderFiltered.indexOf('*');
2047
+ const rest = properties.filter((prop) => !orderHash[prop]);
2048
+ const restIndex = orderFiltered.indexOf("*");
2856
2049
  if (restIndex === -1) {
2857
2050
  if (rest.length) {
2858
2051
  throw new Error(`uiSchema order list does not contain ${errorPropList(rest)}`);
2859
2052
  }
2860
2053
  return orderFiltered;
2861
2054
  }
2862
- if (restIndex !== orderFiltered.lastIndexOf('*')) {
2863
- throw new Error('uiSchema order list contains more than one wildcard item');
2055
+ if (restIndex !== orderFiltered.lastIndexOf("*")) {
2056
+ throw new Error("uiSchema order list contains more than one wildcard item");
2864
2057
  }
2865
2058
  const complete = [...orderFiltered];
2866
2059
  complete.splice(restIndex, 1, ...rest);
2867
2060
  return complete;
2868
2061
  }
2869
2062
 
2870
- /** Returns a string representation of the `num` that is padded with leading "0"s if necessary
2871
- *
2872
- * @param num - The number to pad
2873
- * @param width - The width of the string at which no lead padding is necessary
2874
- * @returns - The number converted to a string with leading zero padding if the number of digits is less than `width`
2875
- */
2063
+ // src/pad.ts
2876
2064
  function pad(num, width) {
2877
2065
  let s = String(num);
2878
2066
  while (s.length < width) {
2879
- s = '0' + s;
2067
+ s = "0" + s;
2880
2068
  }
2881
2069
  return s;
2882
2070
  }
2883
2071
 
2884
- /** Parses the `dateString` into a `DateObject`, including the time information when `includeTime` is true
2885
- *
2886
- * @param dateString - The date string to parse into a DateObject
2887
- * @param [includeTime=true] - Optional flag, if false, will not include the time data into the object
2888
- * @returns - The date string converted to a `DateObject`
2889
- * @throws - Error when the date cannot be parsed from the string
2890
- */
2072
+ // src/parseDateString.ts
2891
2073
  function parseDateString(dateString, includeTime = true) {
2892
2074
  if (!dateString) {
2893
2075
  return {
@@ -2901,11 +2083,12 @@ function parseDateString(dateString, includeTime = true) {
2901
2083
  }
2902
2084
  const date = new Date(dateString);
2903
2085
  if (Number.isNaN(date.getTime())) {
2904
- throw new Error('Unable to parse date ' + dateString);
2086
+ throw new Error("Unable to parse date " + dateString);
2905
2087
  }
2906
2088
  return {
2907
2089
  year: date.getUTCFullYear(),
2908
2090
  month: date.getUTCMonth() + 1,
2091
+ // oh you, javascript.
2909
2092
  day: date.getUTCDate(),
2910
2093
  hour: includeTime ? date.getUTCHours() : 0,
2911
2094
  minute: includeTime ? date.getUTCMinutes() : 0,
@@ -2913,102 +2096,64 @@ function parseDateString(dateString, includeTime = true) {
2913
2096
  };
2914
2097
  }
2915
2098
 
2916
- /** Check to see if a `schema` specifies that a value must be true. This happens when:
2917
- * - `schema.const` is truthy
2918
- * - `schema.enum` == `[true]`
2919
- * - `schema.anyOf` or `schema.oneOf` has a single value which recursively returns true
2920
- * - `schema.allOf` has at least one value which recursively returns true
2921
- *
2922
- * @param schema - The schema to check
2923
- * @returns - True if the schema specifies a value that must be true, false otherwise
2924
- */
2099
+ // src/schemaRequiresTrueValue.ts
2925
2100
  function schemaRequiresTrueValue(schema) {
2926
- // Check if const is a truthy value
2927
2101
  if (schema.const) {
2928
2102
  return true;
2929
2103
  }
2930
- // Check if an enum has a single value of true
2931
2104
  if (schema.enum && schema.enum.length === 1 && schema.enum[0] === true) {
2932
2105
  return true;
2933
2106
  }
2934
- // If anyOf has a single value, evaluate the subschema
2935
2107
  if (schema.anyOf && schema.anyOf.length === 1) {
2936
2108
  return schemaRequiresTrueValue(schema.anyOf[0]);
2937
2109
  }
2938
- // If oneOf has a single value, evaluate the subschema
2939
2110
  if (schema.oneOf && schema.oneOf.length === 1) {
2940
2111
  return schemaRequiresTrueValue(schema.oneOf[0]);
2941
2112
  }
2942
- // Evaluate each subschema in allOf, to see if one of them requires a true value
2943
2113
  if (schema.allOf) {
2944
- const schemaSome = subSchema => schemaRequiresTrueValue(subSchema);
2114
+ const schemaSome = (subSchema) => schemaRequiresTrueValue(subSchema);
2945
2115
  return schema.allOf.some(schemaSome);
2946
2116
  }
2947
2117
  return false;
2948
2118
  }
2949
2119
 
2950
- /** Determines whether the given `component` should be rerendered by comparing its current set of props and state
2951
- * against the next set. If either of those two sets are not the same, then the component should be rerendered.
2952
- *
2953
- * @param component - A React component being checked
2954
- * @param nextProps - The next set of props against which to check
2955
- * @param nextState - The next set of state against which to check
2956
- * @returns - True if the component should be re-rendered, false otherwise
2957
- */
2120
+ // src/shouldRender.ts
2958
2121
  function shouldRender(component, nextProps, nextState) {
2959
- const {
2960
- props,
2961
- state
2962
- } = component;
2122
+ const { props, state } = component;
2963
2123
  return !deepEquals(props, nextProps) || !deepEquals(state, nextState);
2964
2124
  }
2965
2125
 
2966
- /** Returns a UTC date string for the given `dateObject`. If `time` is false, then the time portion of the string is
2967
- * removed.
2968
- *
2969
- * @param dateObject - The `DateObject` to convert to a date string
2970
- * @param [time=true] - Optional flag used to remove the time portion of the date string if false
2971
- * @returns - The UTC date string
2972
- */
2126
+ // src/toDateString.ts
2973
2127
  function toDateString(dateObject, time = true) {
2974
- const {
2975
- year,
2976
- month,
2977
- day,
2978
- hour = 0,
2979
- minute = 0,
2980
- second = 0
2981
- } = dateObject;
2128
+ const { year, month, day, hour = 0, minute = 0, second = 0 } = dateObject;
2982
2129
  const utcTime = Date.UTC(year, month - 1, day, hour, minute, second);
2983
2130
  const datetime = new Date(utcTime).toJSON();
2984
2131
  return time ? datetime : datetime.slice(0, 10);
2985
2132
  }
2986
2133
 
2987
- /** Converts an `errorSchema` into a list of `RJSFValidationErrors`
2988
- *
2989
- * @param errorSchema - The `ErrorSchema` instance to convert
2990
- * @param [fieldPath=[]] - The current field path, defaults to [] if not specified
2991
- * @returns - The list of `RJSFValidationErrors` extracted from the `errorSchema`
2992
- */
2134
+ // src/toErrorList.ts
2135
+ import isPlainObject2 from "lodash/isPlainObject";
2993
2136
  function toErrorList(errorSchema, fieldPath = []) {
2994
2137
  if (!errorSchema) {
2995
2138
  return [];
2996
2139
  }
2997
2140
  let errorList = [];
2998
2141
  if (ERRORS_KEY in errorSchema) {
2999
- errorList = errorList.concat(errorSchema[ERRORS_KEY].map(message => {
3000
- const property = `.${fieldPath.join('.')}`;
3001
- return {
3002
- property,
3003
- message,
3004
- stack: `${property} ${message}`
3005
- };
3006
- }));
2142
+ errorList = errorList.concat(
2143
+ errorSchema[ERRORS_KEY].map((message) => {
2144
+ const property = `.${fieldPath.join(".")}`;
2145
+ return {
2146
+ property,
2147
+ message,
2148
+ stack: `${property} ${message}`
2149
+ };
2150
+ })
2151
+ );
3007
2152
  }
3008
2153
  return Object.keys(errorSchema).reduce((acc, key) => {
3009
2154
  if (key !== ERRORS_KEY) {
3010
2155
  const childSchema = errorSchema[key];
3011
- if (isPlainObject(childSchema)) {
2156
+ if (isPlainObject2(childSchema)) {
3012
2157
  acc = acc.concat(toErrorList(childSchema, [...fieldPath, key]));
3013
2158
  }
3014
2159
  }
@@ -3016,38 +2161,15 @@ function toErrorList(errorSchema, fieldPath = []) {
3016
2161
  }, errorList);
3017
2162
  }
3018
2163
 
3019
- /** Transforms a rjsf validation errors list:
3020
- * [
3021
- * {property: '.level1.level2[2].level3', message: 'err a'},
3022
- * {property: '.level1.level2[2].level3', message: 'err b'},
3023
- * {property: '.level1.level2[4].level3', message: 'err b'},
3024
- * ]
3025
- * Into an error tree:
3026
- * {
3027
- * level1: {
3028
- * level2: {
3029
- * 2: {level3: {errors: ['err a', 'err b']}},
3030
- * 4: {level3: {errors: ['err b']}},
3031
- * }
3032
- * }
3033
- * };
3034
- *
3035
- * @param errors - The list of RJSFValidationError objects
3036
- * @returns - The `ErrorSchema` built from the list of `RJSFValidationErrors`
3037
- */
2164
+ // src/toErrorSchema.ts
2165
+ import toPath from "lodash/toPath";
3038
2166
  function toErrorSchema(errors) {
3039
2167
  const builder = new ErrorSchemaBuilder();
3040
2168
  if (errors.length) {
3041
- errors.forEach(error => {
3042
- const {
3043
- property,
3044
- message
3045
- } = error;
3046
- // When the property is the root element, just use an empty array for the path
3047
- const path = property === '.' ? [] : toPath(property);
3048
- // If the property is at the root (.level1) then toPath creates
3049
- // an empty array element at the first index. Remove it.
3050
- if (path.length > 0 && path[0] === '') {
2169
+ errors.forEach((error) => {
2170
+ const { property, message } = error;
2171
+ const path = property === "." ? [] : toPath(property);
2172
+ if (path.length > 0 && path[0] === "") {
3051
2173
  path.splice(0, 1);
3052
2174
  }
3053
2175
  if (message) {
@@ -3058,45 +2180,30 @@ function toErrorSchema(errors) {
3058
2180
  return builder.ErrorSchema;
3059
2181
  }
3060
2182
 
3061
- /** Unwraps the `errorHandler` structure into the associated `ErrorSchema`, stripping the `addError()` functions from it
3062
- *
3063
- * @param errorHandler - The `FormValidation` error handling structure
3064
- * @returns - The `ErrorSchema` resulting from the stripping of the `addError()` function
3065
- */
2183
+ // src/unwrapErrorHandler.ts
2184
+ import isPlainObject3 from "lodash/isPlainObject";
3066
2185
  function unwrapErrorHandler(errorHandler) {
3067
2186
  return Object.keys(errorHandler).reduce((acc, key) => {
3068
- if (key === 'addError') {
2187
+ if (key === "addError") {
3069
2188
  return acc;
3070
2189
  } else {
3071
2190
  const childSchema = errorHandler[key];
3072
- if (isPlainObject(childSchema)) {
2191
+ if (isPlainObject3(childSchema)) {
3073
2192
  return {
3074
2193
  ...acc,
3075
2194
  [key]: unwrapErrorHandler(childSchema)
3076
2195
  };
3077
2196
  }
3078
- return {
3079
- ...acc,
3080
- [key]: childSchema
3081
- };
2197
+ return { ...acc, [key]: childSchema };
3082
2198
  }
3083
2199
  }, {});
3084
2200
  }
3085
2201
 
3086
- /** Converts a UTC date string into a local Date format
3087
- *
3088
- * @param jsonDate - A UTC date string
3089
- * @returns - An empty string when `jsonDate` is falsey, otherwise a date string in local format
3090
- */
2202
+ // src/utcToLocal.ts
3091
2203
  function utcToLocal(jsonDate) {
3092
2204
  if (!jsonDate) {
3093
- return '';
2205
+ return "";
3094
2206
  }
3095
- // required format of `'yyyy-MM-ddThh:mm' followed by optional ':ss' or ':ss.SSS'
3096
- // https://html.spec.whatwg.org/multipage/input.html#local-date-and-time-state-(type%3Ddatetime-local)
3097
- // > should be a _valid local date and time string_ (not GMT)
3098
- // Note - date constructor passed local ISO-8601 does not correctly
3099
- // change time to UTC in node pre-8
3100
2207
  const date = new Date(jsonDate);
3101
2208
  const yyyy = pad(date.getFullYear(), 4);
3102
2209
  const MM = pad(date.getMonth() + 1, 2);
@@ -3108,45 +2215,29 @@ function utcToLocal(jsonDate) {
3108
2215
  return `${yyyy}-${MM}-${dd}T${hh}:${mm}:${ss}.${SSS}`;
3109
2216
  }
3110
2217
 
3111
- /** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in the
3112
- * two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
3113
- * `toErrorList()` on the `errors` in the `validationData`. If no `additionalErrorSchema` is passed, then
3114
- * `validationData` is returned.
3115
- *
3116
- * @param validationData - The current `ValidationData` into which to merge the additional errors
3117
- * @param [additionalErrorSchema] - The optional additional set of errors in an `ErrorSchema`
3118
- * @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
3119
- */
2218
+ // src/validationDataMerge.ts
2219
+ import isEmpty3 from "lodash/isEmpty";
3120
2220
  function validationDataMerge(validationData, additionalErrorSchema) {
3121
2221
  if (!additionalErrorSchema) {
3122
2222
  return validationData;
3123
2223
  }
3124
- const {
3125
- errors: oldErrors,
3126
- errorSchema: oldErrorSchema
3127
- } = validationData;
2224
+ const { errors: oldErrors, errorSchema: oldErrorSchema } = validationData;
3128
2225
  let errors = toErrorList(additionalErrorSchema);
3129
2226
  let errorSchema = additionalErrorSchema;
3130
- if (!isEmpty(oldErrorSchema)) {
2227
+ if (!isEmpty3(oldErrorSchema)) {
3131
2228
  errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
3132
2229
  errors = [...oldErrors].concat(errors);
3133
2230
  }
3134
- return {
3135
- errorSchema,
3136
- errors
3137
- };
2231
+ return { errorSchema, errors };
3138
2232
  }
3139
2233
 
3140
- /** Takes a `node` object and transforms any contained `$ref` node variables with a prefix, recursively calling
3141
- * `withIdRefPrefix` for any other elements.
3142
- *
3143
- * @param node - The object node to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it
3144
- */
2234
+ // src/withIdRefPrefix.ts
2235
+ import isObject3 from "lodash/isObject";
3145
2236
  function withIdRefPrefixObject(node) {
3146
2237
  for (const key in node) {
3147
2238
  const realObj = node;
3148
2239
  const value = realObj[key];
3149
- if (key === REF_KEY && typeof value === 'string' && value.startsWith('#')) {
2240
+ if (key === REF_KEY && typeof value === "string" && value.startsWith("#")) {
3150
2241
  realObj[key] = ROOT_SCHEMA_PREFIX + value;
3151
2242
  } else {
3152
2243
  realObj[key] = withIdRefPrefix(value);
@@ -3154,246 +2245,271 @@ function withIdRefPrefixObject(node) {
3154
2245
  }
3155
2246
  return node;
3156
2247
  }
3157
- /** Takes a `node` object list and transforms any contained `$ref` node variables with a prefix, recursively calling
3158
- * `withIdRefPrefix` for any other elements.
3159
- *
3160
- * @param node - The list of object nodes to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it
3161
- */
3162
2248
  function withIdRefPrefixArray(node) {
3163
2249
  for (let i = 0; i < node.length; i++) {
3164
2250
  node[i] = withIdRefPrefix(node[i]);
3165
2251
  }
3166
2252
  return node;
3167
2253
  }
3168
- /** Recursively prefixes all `$ref`s in a schema with the value of the `ROOT_SCHEMA_PREFIX` constant.
3169
- * This is used in isValid to make references to the rootSchema
3170
- *
3171
- * @param schemaNode - The object node to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it
3172
- * @returns - A copy of the `schemaNode` with updated `$ref`s
3173
- */
3174
2254
  function withIdRefPrefix(schemaNode) {
3175
2255
  if (Array.isArray(schemaNode)) {
3176
2256
  return withIdRefPrefixArray([...schemaNode]);
3177
2257
  }
3178
- if (isObject$1(schemaNode)) {
3179
- return withIdRefPrefixObject({
3180
- ...schemaNode
3181
- });
2258
+ if (isObject3(schemaNode)) {
2259
+ return withIdRefPrefixObject({ ...schemaNode });
3182
2260
  }
3183
2261
  return schemaNode;
3184
2262
  }
3185
2263
 
3186
- /** An enumeration of all the translatable strings used by `@rjsf/core` and its themes. The value of each of the
3187
- * enumeration keys is expected to be the actual english string. Some strings contain replaceable parameter values
3188
- * as indicated by `%1`, `%2`, etc. The number after the `%` indicates the order of the parameter. The ordering of
3189
- * parameters is important because some languages may choose to put the second parameter before the first in its
3190
- * translation. Also, some strings are rendered using `markdown-to-jsx` and thus support markdown and inline html.
3191
- */
3192
- var TranslatableString;
3193
- (function (TranslatableString) {
3194
- /** Fallback title of an array item, used by ArrayField */
3195
- TranslatableString["ArrayItemTitle"] = "Item";
3196
- /** Missing items reason, used by ArrayField */
3197
- TranslatableString["MissingItems"] = "Missing items definition";
3198
- /** Yes label, used by BooleanField */
3199
- TranslatableString["YesLabel"] = "Yes";
3200
- /** No label, used by BooleanField */
3201
- TranslatableString["NoLabel"] = "No";
3202
- /** Close label, used by ErrorList */
3203
- TranslatableString["CloseLabel"] = "Close";
3204
- /** Errors label, used by ErrorList */
3205
- TranslatableString["ErrorsLabel"] = "Errors";
3206
- /** New additionalProperties string default value, used by ObjectField */
3207
- TranslatableString["NewStringDefault"] = "New Value";
3208
- /** Add button title, used by AddButton */
3209
- TranslatableString["AddButton"] = "Add";
3210
- /** Add button title, used by AddButton */
3211
- TranslatableString["AddItemButton"] = "Add Item";
3212
- /** Copy button title, used by IconButton */
3213
- TranslatableString["CopyButton"] = "Copy";
3214
- /** Move down button title, used by IconButton */
3215
- TranslatableString["MoveDownButton"] = "Move down";
3216
- /** Move up button title, used by IconButton */
3217
- TranslatableString["MoveUpButton"] = "Move up";
3218
- /** Remove button title, used by IconButton */
3219
- TranslatableString["RemoveButton"] = "Remove";
3220
- /** Now label, used by AltDateWidget */
3221
- TranslatableString["NowLabel"] = "Now";
3222
- /** Clear label, used by AltDateWidget */
3223
- TranslatableString["ClearLabel"] = "Clear";
3224
- /** Aria date label, used by DateWidget */
3225
- TranslatableString["AriaDateLabel"] = "Select a date";
3226
- /** File preview label, used by FileWidget */
3227
- TranslatableString["PreviewLabel"] = "Preview";
3228
- /** Decrement button aria label, used by UpDownWidget */
3229
- TranslatableString["DecrementAriaLabel"] = "Decrease value by 1";
3230
- /** Increment button aria label, used by UpDownWidget */
3231
- TranslatableString["IncrementAriaLabel"] = "Increase value by 1";
3232
- // Strings with replaceable parameters
3233
- /** Unknown field type reason, where %1 will be replaced with the type as provided by SchemaField */
3234
- TranslatableString["UnknownFieldType"] = "Unknown field type %1";
3235
- /** Option prefix, where %1 will be replaced with the option index as provided by MultiSchemaField */
3236
- TranslatableString["OptionPrefix"] = "Option %1";
3237
- /** Option prefix, where %1 and %2 will be replaced by the schema title and option index, respectively as provided by
3238
- * MultiSchemaField
3239
- */
3240
- TranslatableString["TitleOptionPrefix"] = "%1 option %2";
3241
- /** Key label, where %1 will be replaced by the label as provided by WrapIfAdditionalTemplate */
3242
- TranslatableString["KeyLabel"] = "%1 Key";
3243
- // Strings with replaceable parameters AND/OR that support markdown and html
3244
- /** Invalid object field configuration as provided by the ObjectField */
3245
- TranslatableString["InvalidObjectField"] = "Invalid \"%1\" object field configuration: <em>%2</em>.";
3246
- /** Unsupported field schema, used by UnsupportedField */
3247
- TranslatableString["UnsupportedField"] = "Unsupported field schema.";
3248
- /** Unsupported field schema, where %1 will be replaced by the idSchema.$id as provided by UnsupportedField */
3249
- TranslatableString["UnsupportedFieldWithId"] = "Unsupported field schema for field <code>%1</code>.";
3250
- /** Unsupported field schema, where %1 will be replaced by the reason string as provided by UnsupportedField */
3251
- TranslatableString["UnsupportedFieldWithReason"] = "Unsupported field schema: <em>%1</em>.";
3252
- /** Unsupported field schema, where %1 and %2 will be replaced by the idSchema.$id and reason strings, respectively,
3253
- * as provided by UnsupportedField
3254
- */
3255
- TranslatableString["UnsupportedFieldWithIdAndReason"] = "Unsupported field schema for field <code>%1</code>: <em>%2</em>.";
3256
- /** File name, type and size info, where %1, %2 and %3 will be replaced by the file name, file type and file size as
3257
- * provided by FileWidget
3258
- */
3259
- TranslatableString["FilesInfo"] = "<strong>%1</strong> (%2, %3 bytes)";
3260
- })(TranslatableString || (TranslatableString = {}));
3261
-
3262
- /** An implementation of the `ValidatorType` interface that is designed for use in capturing schemas used by the
3263
- * `isValid()` function. The rest of the implementation of the interface throws errors when it is attempted to be used.
3264
- * An instance of the object allows the caller to capture the schemas used in calls to the `isValid()` function. These
3265
- * captured schema, along with the root schema used to construct the object are stored in the map of schemas keyed by
3266
- * the hashed value of the schema. NOTE: After hashing the schema, an $id with the hash value is added to the
3267
- * schema IF that schema doesn't already have an $id, prior to putting the schema into the map.
3268
- */
3269
- class ParserValidator {
3270
- /** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
3271
- * first.
3272
- *
3273
- * @param rootSchema - The root schema against which this validator will be executed
2264
+ // src/enums.ts
2265
+ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
2266
+ TranslatableString2["ArrayItemTitle"] = "Item";
2267
+ TranslatableString2["MissingItems"] = "Missing items definition";
2268
+ TranslatableString2["YesLabel"] = "Yes";
2269
+ TranslatableString2["NoLabel"] = "No";
2270
+ TranslatableString2["CloseLabel"] = "Close";
2271
+ TranslatableString2["ErrorsLabel"] = "Errors";
2272
+ TranslatableString2["NewStringDefault"] = "New Value";
2273
+ TranslatableString2["AddButton"] = "Add";
2274
+ TranslatableString2["AddItemButton"] = "Add Item";
2275
+ TranslatableString2["CopyButton"] = "Copy";
2276
+ TranslatableString2["MoveDownButton"] = "Move down";
2277
+ TranslatableString2["MoveUpButton"] = "Move up";
2278
+ TranslatableString2["RemoveButton"] = "Remove";
2279
+ TranslatableString2["NowLabel"] = "Now";
2280
+ TranslatableString2["ClearLabel"] = "Clear";
2281
+ TranslatableString2["AriaDateLabel"] = "Select a date";
2282
+ TranslatableString2["PreviewLabel"] = "Preview";
2283
+ TranslatableString2["DecrementAriaLabel"] = "Decrease value by 1";
2284
+ TranslatableString2["IncrementAriaLabel"] = "Increase value by 1";
2285
+ TranslatableString2["UnknownFieldType"] = "Unknown field type %1";
2286
+ TranslatableString2["OptionPrefix"] = "Option %1";
2287
+ TranslatableString2["TitleOptionPrefix"] = "%1 option %2";
2288
+ TranslatableString2["KeyLabel"] = "%1 Key";
2289
+ TranslatableString2["InvalidObjectField"] = 'Invalid "%1" object field configuration: <em>%2</em>.';
2290
+ TranslatableString2["UnsupportedField"] = "Unsupported field schema.";
2291
+ TranslatableString2["UnsupportedFieldWithId"] = "Unsupported field schema for field <code>%1</code>.";
2292
+ TranslatableString2["UnsupportedFieldWithReason"] = "Unsupported field schema: <em>%1</em>.";
2293
+ TranslatableString2["UnsupportedFieldWithIdAndReason"] = "Unsupported field schema for field <code>%1</code>: <em>%2</em>.";
2294
+ TranslatableString2["FilesInfo"] = "<strong>%1</strong> (%2, %3 bytes)";
2295
+ return TranslatableString2;
2296
+ })(TranslatableString || {});
2297
+
2298
+ // src/parser/schemaParser.ts
2299
+ import forEach from "lodash/forEach";
2300
+ import isEqual6 from "lodash/isEqual";
2301
+
2302
+ // src/parser/ParserValidator.ts
2303
+ import get12 from "lodash/get";
2304
+ import isEqual5 from "lodash/isEqual";
2305
+ var ParserValidator = class {
2306
+ /** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
2307
+ * first.
2308
+ *
2309
+ * @param rootSchema - The root schema against which this validator will be executed
3274
2310
  */
3275
2311
  constructor(rootSchema) {
3276
- /** The rootSchema provided during construction of the class */
3277
- this.rootSchema = void 0;
3278
2312
  /** The map of schemas encountered by the ParserValidator */
3279
2313
  this.schemaMap = {};
3280
2314
  this.rootSchema = rootSchema;
3281
2315
  this.addSchema(rootSchema, hashForSchema(rootSchema));
3282
2316
  }
3283
- /** Adds the given `schema` to the `schemaMap` keyed by the `hash` or `ID_KEY` if present on the `schema`. If the
3284
- * schema does not have an `ID_KEY`, then the `hash` will be added as the `ID_KEY` to allow the schema to be
3285
- * associated with it's `hash` for future use (by a schema compiler).
3286
- *
3287
- * @param schema - The schema which is to be added to the map
3288
- * @param hash - The hash value at which to map the schema
2317
+ /** Adds the given `schema` to the `schemaMap` keyed by the `hash` or `ID_KEY` if present on the `schema`. If the
2318
+ * schema does not have an `ID_KEY`, then the `hash` will be added as the `ID_KEY` to allow the schema to be
2319
+ * associated with it's `hash` for future use (by a schema compiler).
2320
+ *
2321
+ * @param schema - The schema which is to be added to the map
2322
+ * @param hash - The hash value at which to map the schema
3289
2323
  */
3290
2324
  addSchema(schema, hash) {
3291
- const key = get(schema, ID_KEY, hash);
3292
- const identifiedSchema = {
3293
- ...schema,
3294
- [ID_KEY]: key
3295
- };
2325
+ const key = get12(schema, ID_KEY, hash);
2326
+ const identifiedSchema = { ...schema, [ID_KEY]: key };
3296
2327
  const existing = this.schemaMap[key];
3297
2328
  if (!existing) {
3298
2329
  this.schemaMap[key] = identifiedSchema;
3299
- } else if (!isEqual(existing, identifiedSchema)) {
3300
- console.error('existing schema:', JSON.stringify(existing, null, 2));
3301
- console.error('new schema:', JSON.stringify(identifiedSchema, null, 2));
3302
- throw new Error(`Two different schemas exist with the same key ${key}! What a bad coincidence. If possible, try adding an $id to one of the schemas`);
2330
+ } else if (!isEqual5(existing, identifiedSchema)) {
2331
+ console.error("existing schema:", JSON.stringify(existing, null, 2));
2332
+ console.error("new schema:", JSON.stringify(identifiedSchema, null, 2));
2333
+ throw new Error(
2334
+ `Two different schemas exist with the same key ${key}! What a bad coincidence. If possible, try adding an $id to one of the schemas`
2335
+ );
3303
2336
  }
3304
2337
  }
3305
- /** Returns the current `schemaMap` to the caller
2338
+ /** Returns the current `schemaMap` to the caller
3306
2339
  */
3307
2340
  getSchemaMap() {
3308
2341
  return this.schemaMap;
3309
2342
  }
3310
- /** Implements the `ValidatorType` `isValid()` method to capture the `schema` in the `schemaMap`. Throws an error when
3311
- * the `rootSchema` is not the same as the root schema provided during construction.
3312
- *
3313
- * @param schema - The schema to record in the `schemaMap`
3314
- * @param _formData - The formData parameter that is ignored
3315
- * @param rootSchema - The root schema associated with the schema
3316
- * @throws - Error when the given `rootSchema` differs from the root schema provided during construction
2343
+ /** Implements the `ValidatorType` `isValid()` method to capture the `schema` in the `schemaMap`. Throws an error when
2344
+ * the `rootSchema` is not the same as the root schema provided during construction.
2345
+ *
2346
+ * @param schema - The schema to record in the `schemaMap`
2347
+ * @param _formData - The formData parameter that is ignored
2348
+ * @param rootSchema - The root schema associated with the schema
2349
+ * @throws - Error when the given `rootSchema` differs from the root schema provided during construction
3317
2350
  */
3318
2351
  isValid(schema, _formData, rootSchema) {
3319
- if (!isEqual(rootSchema, this.rootSchema)) {
3320
- throw new Error('Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema');
2352
+ if (!isEqual5(rootSchema, this.rootSchema)) {
2353
+ throw new Error("Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema");
3321
2354
  }
3322
2355
  this.addSchema(schema, hashForSchema(schema));
3323
2356
  return false;
3324
2357
  }
3325
- /** Implements the `ValidatorType` `rawValidation()` method to throw an error since it is never supposed to be called
3326
- *
3327
- * @param _schema - The schema parameter that is ignored
3328
- * @param _formData - The formData parameter that is ignored
2358
+ /** Implements the `ValidatorType` `rawValidation()` method to throw an error since it is never supposed to be called
2359
+ *
2360
+ * @param _schema - The schema parameter that is ignored
2361
+ * @param _formData - The formData parameter that is ignored
3329
2362
  */
3330
2363
  rawValidation(_schema, _formData) {
3331
- throw new Error('Unexpectedly calling the `rawValidation()` method during schema parsing');
2364
+ throw new Error("Unexpectedly calling the `rawValidation()` method during schema parsing");
3332
2365
  }
3333
- /** Implements the `ValidatorType` `toErrorList()` method to throw an error since it is never supposed to be called
3334
- *
3335
- * @param _errorSchema - The error schema parameter that is ignored
3336
- * @param _fieldPath - The field path parameter that is ignored
2366
+ /** Implements the `ValidatorType` `toErrorList()` method to throw an error since it is never supposed to be called
2367
+ *
2368
+ * @param _errorSchema - The error schema parameter that is ignored
2369
+ * @param _fieldPath - The field path parameter that is ignored
3337
2370
  */
3338
2371
  toErrorList(_errorSchema, _fieldPath) {
3339
- throw new Error('Unexpectedly calling the `toErrorList()` method during schema parsing');
3340
- }
3341
- /** Implements the `ValidatorType` `validateFormData()` method to throw an error since it is never supposed to be
3342
- * called
3343
- *
3344
- * @param _formData - The formData parameter that is ignored
3345
- * @param _schema - The schema parameter that is ignored
3346
- * @param _customValidate - The customValidate parameter that is ignored
3347
- * @param _transformErrors - The transformErrors parameter that is ignored
3348
- * @param _uiSchema - The uiSchema parameter that is ignored
2372
+ throw new Error("Unexpectedly calling the `toErrorList()` method during schema parsing");
2373
+ }
2374
+ /** Implements the `ValidatorType` `validateFormData()` method to throw an error since it is never supposed to be
2375
+ * called
2376
+ *
2377
+ * @param _formData - The formData parameter that is ignored
2378
+ * @param _schema - The schema parameter that is ignored
2379
+ * @param _customValidate - The customValidate parameter that is ignored
2380
+ * @param _transformErrors - The transformErrors parameter that is ignored
2381
+ * @param _uiSchema - The uiSchema parameter that is ignored
3349
2382
  */
3350
2383
  validateFormData(_formData, _schema, _customValidate, _transformErrors, _uiSchema) {
3351
- throw new Error('Unexpectedly calling the `validateFormData()` method during schema parsing');
2384
+ throw new Error("Unexpectedly calling the `validateFormData()` method during schema parsing");
3352
2385
  }
3353
- }
2386
+ };
3354
2387
 
3355
- /** Recursive function used to parse the given `schema` belonging to the `rootSchema`. The `validator` is used to
3356
- * capture the sub-schemas that the `isValid()` function is called with. For each schema returned by the
3357
- * `retrieveSchemaInternal()`, the `resolveAnyOrOneOfSchemas()` function is called. For each of the schemas returned
3358
- * from THAT call have `properties`, then each of the sub-schema property objects are then recursively parsed.
3359
- *
3360
- * @param validator - The `ParserValidator` implementation used to capture `isValid()` calls during parsing
3361
- * @param recurseList - The list of schemas returned from the `retrieveSchemaInternal`, preventing infinite recursion
3362
- * @param rootSchema - The root schema from which the schema parsing began
3363
- * @param schema - The current schema element being parsed
3364
- */
2388
+ // src/parser/schemaParser.ts
3365
2389
  function parseSchema(validator, recurseList, rootSchema, schema) {
3366
- const schemas = retrieveSchemaInternal(validator, schema, rootSchema, undefined, true);
3367
- schemas.forEach(schema => {
3368
- const sameSchemaIndex = recurseList.findIndex(item => isEqual(item, schema));
2390
+ const schemas = retrieveSchemaInternal(validator, schema, rootSchema, void 0, true);
2391
+ schemas.forEach((schema2) => {
2392
+ const sameSchemaIndex = recurseList.findIndex((item) => isEqual6(item, schema2));
3369
2393
  if (sameSchemaIndex === -1) {
3370
- recurseList.push(schema);
3371
- const allOptions = resolveAnyOrOneOfSchemas(validator, schema, rootSchema, true);
3372
- allOptions.forEach(s => {
2394
+ recurseList.push(schema2);
2395
+ const allOptions = resolveAnyOrOneOfSchemas(validator, schema2, rootSchema, true);
2396
+ allOptions.forEach((s) => {
3373
2397
  if (PROPERTIES_KEY in s && s[PROPERTIES_KEY]) {
3374
- forEach(schema[PROPERTIES_KEY], value => {
2398
+ forEach(schema2[PROPERTIES_KEY], (value) => {
3375
2399
  parseSchema(validator, recurseList, rootSchema, value);
3376
2400
  });
3377
2401
  }
3378
2402
  });
3379
- if (ITEMS_KEY in schema && !Array.isArray(schema.items) && typeof schema.items !== 'boolean') {
3380
- parseSchema(validator, recurseList, rootSchema, schema.items);
2403
+ if (ITEMS_KEY in schema2 && !Array.isArray(schema2.items) && typeof schema2.items !== "boolean") {
2404
+ parseSchema(validator, recurseList, rootSchema, schema2.items);
3381
2405
  }
3382
2406
  }
3383
2407
  });
3384
2408
  }
3385
- /** Parses the given `rootSchema` to extract out all the sub-schemas that maybe contained within it. Returns a map of
3386
- * the hash of the schema to schema/sub-schema.
3387
- *
3388
- * @param rootSchema - The root schema to parse for sub-schemas used by `isValid()` calls
3389
- * @returns - The `SchemaMap` of all schemas that were parsed
3390
- */
3391
2409
  function schemaParser(rootSchema) {
3392
2410
  const validator = new ParserValidator(rootSchema);
3393
2411
  const recurseList = [];
3394
2412
  parseSchema(validator, recurseList, rootSchema, rootSchema);
3395
2413
  return validator.getSchemaMap();
3396
2414
  }
3397
-
3398
- export { ADDITIONAL_PROPERTIES_KEY, ADDITIONAL_PROPERTY_FLAG, ALL_OF_KEY, ANY_OF_KEY, CONST_KEY, DEFAULT_KEY, DEFINITIONS_KEY, DEPENDENCIES_KEY, ENUM_KEY, ERRORS_KEY, ErrorSchemaBuilder, ID_KEY, IF_KEY, ITEMS_KEY, JUNK_OPTION_ID, NAME_KEY, ONE_OF_KEY, PROPERTIES_KEY, REF_KEY, REQUIRED_KEY, RJSF_ADDITONAL_PROPERTIES_FLAG, ROOT_SCHEMA_PREFIX, SUBMIT_BTN_OPTIONS_KEY, TranslatableString, UI_FIELD_KEY, UI_GLOBAL_OPTIONS_KEY, UI_OPTIONS_KEY, UI_WIDGET_KEY, allowAdditionalItems, ariaDescribedByIds, asNumber, canExpand, createErrorHandler, createSchemaUtils, dataURItoBlob, deepEquals, descriptionId, englishStringTranslator, enumOptionsDeselectValue, enumOptionsIndexForValue, enumOptionsIsSelected, enumOptionsSelectValue, enumOptionsValueForIndex, errorId, examplesId, findSchemaDefinition, getClosestMatchingOption, getDefaultFormState, getDiscriminatorFieldFromSchema, getDisplayLabel, getFirstMatchingOption, getInputProps, getMatchingOption, getSchemaType, getSubmitButtonOptions, getTemplate, getUiOptions, getWidget, guessType, hasWidget, hashForSchema, helpId, isConstant, isCustomWidget, isFilesArray, isFixedItems, isMultiSelect, isObject, isSelect, labelValue, localToUTC, mergeDefaultsWithFormData, mergeObjects, mergeSchemas, mergeValidationData, optionId, optionsList, orderProperties, pad, parseDateString, rangeSpec, replaceStringParameters, retrieveSchema, sanitizeDataForNewSchema, schemaParser, schemaRequiresTrueValue, shouldRender, titleId, toConstant, toDateString, toErrorList, toErrorSchema, toIdSchema, toPathSchema, unwrapErrorHandler, utcToLocal, validationDataMerge, withIdRefPrefix };
2415
+ export {
2416
+ ADDITIONAL_PROPERTIES_KEY,
2417
+ ADDITIONAL_PROPERTY_FLAG,
2418
+ ALL_OF_KEY,
2419
+ ANY_OF_KEY,
2420
+ CONST_KEY,
2421
+ DEFAULT_KEY,
2422
+ DEFINITIONS_KEY,
2423
+ DEPENDENCIES_KEY,
2424
+ ENUM_KEY,
2425
+ ERRORS_KEY,
2426
+ ErrorSchemaBuilder,
2427
+ ID_KEY,
2428
+ IF_KEY,
2429
+ ITEMS_KEY,
2430
+ JUNK_OPTION_ID,
2431
+ NAME_KEY,
2432
+ ONE_OF_KEY,
2433
+ PROPERTIES_KEY,
2434
+ REF_KEY,
2435
+ REQUIRED_KEY,
2436
+ RJSF_ADDITONAL_PROPERTIES_FLAG,
2437
+ ROOT_SCHEMA_PREFIX,
2438
+ SUBMIT_BTN_OPTIONS_KEY,
2439
+ TranslatableString,
2440
+ UI_FIELD_KEY,
2441
+ UI_GLOBAL_OPTIONS_KEY,
2442
+ UI_OPTIONS_KEY,
2443
+ UI_WIDGET_KEY,
2444
+ allowAdditionalItems,
2445
+ ariaDescribedByIds,
2446
+ asNumber,
2447
+ canExpand,
2448
+ createErrorHandler,
2449
+ createSchemaUtils,
2450
+ dataURItoBlob,
2451
+ deepEquals,
2452
+ descriptionId,
2453
+ englishStringTranslator,
2454
+ enumOptionsDeselectValue,
2455
+ enumOptionsIndexForValue,
2456
+ enumOptionsIsSelected,
2457
+ enumOptionsSelectValue,
2458
+ enumOptionsValueForIndex,
2459
+ errorId,
2460
+ examplesId,
2461
+ findSchemaDefinition,
2462
+ getClosestMatchingOption,
2463
+ getDefaultFormState,
2464
+ getDiscriminatorFieldFromSchema,
2465
+ getDisplayLabel,
2466
+ getFirstMatchingOption,
2467
+ getInputProps,
2468
+ getMatchingOption,
2469
+ getSchemaType,
2470
+ getSubmitButtonOptions,
2471
+ getTemplate,
2472
+ getUiOptions,
2473
+ getWidget,
2474
+ guessType,
2475
+ hasWidget,
2476
+ hashForSchema,
2477
+ helpId,
2478
+ isConstant,
2479
+ isCustomWidget,
2480
+ isFilesArray,
2481
+ isFixedItems,
2482
+ isMultiSelect,
2483
+ isObject,
2484
+ isSelect,
2485
+ labelValue,
2486
+ localToUTC,
2487
+ mergeDefaultsWithFormData,
2488
+ mergeObjects,
2489
+ mergeSchemas,
2490
+ mergeValidationData,
2491
+ optionId,
2492
+ optionsList,
2493
+ orderProperties,
2494
+ pad,
2495
+ parseDateString,
2496
+ rangeSpec,
2497
+ replaceStringParameters,
2498
+ retrieveSchema,
2499
+ sanitizeDataForNewSchema,
2500
+ schemaParser,
2501
+ schemaRequiresTrueValue,
2502
+ shouldRender,
2503
+ titleId,
2504
+ toConstant,
2505
+ toDateString,
2506
+ toErrorList,
2507
+ toErrorSchema,
2508
+ toIdSchema,
2509
+ toPathSchema,
2510
+ unwrapErrorHandler,
2511
+ utcToLocal,
2512
+ validationDataMerge,
2513
+ withIdRefPrefix
2514
+ };
3399
2515
  //# sourceMappingURL=utils.esm.js.map