@rjsf/utils 5.11.2 → 5.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (303) hide show
  1. package/dist/index.js +2544 -5
  2. package/dist/index.js.map +7 -0
  3. package/dist/utils.esm.js +1228 -2113
  4. package/dist/utils.esm.js.map +7 -1
  5. package/dist/utils.umd.js +2414 -0
  6. package/lib/ErrorSchemaBuilder.d.ts +60 -0
  7. package/lib/ErrorSchemaBuilder.js +103 -0
  8. package/lib/ErrorSchemaBuilder.js.map +1 -0
  9. package/lib/allowAdditionalItems.d.ts +8 -0
  10. package/lib/allowAdditionalItems.js +14 -0
  11. package/lib/allowAdditionalItems.js.map +1 -0
  12. package/lib/asNumber.d.ts +10 -0
  13. package/lib/asNumber.js +36 -0
  14. package/lib/asNumber.js.map +1 -0
  15. package/lib/canExpand.d.ts +11 -0
  16. package/lib/canExpand.js +26 -0
  17. package/lib/canExpand.js.map +1 -0
  18. package/lib/constants.d.ts +31 -0
  19. package/lib/constants.js +32 -0
  20. package/lib/constants.js.map +1 -0
  21. package/lib/createErrorHandler.d.ts +7 -0
  22. package/lib/createErrorHandler.js +31 -0
  23. package/lib/createErrorHandler.js.map +1 -0
  24. package/lib/createSchemaUtils.d.ts +10 -0
  25. package/lib/createSchemaUtils.js +207 -0
  26. package/lib/createSchemaUtils.js.map +1 -0
  27. package/lib/dataURItoBlob.d.ts +16 -0
  28. package/lib/dataURItoBlob.js +43 -0
  29. package/lib/dataURItoBlob.js.map +1 -0
  30. package/lib/deepEquals.d.ts +8 -0
  31. package/lib/deepEquals.js +19 -0
  32. package/lib/deepEquals.js.map +1 -0
  33. package/lib/englishStringTranslator.d.ts +10 -0
  34. package/lib/englishStringTranslator.js +13 -0
  35. package/lib/englishStringTranslator.js.map +1 -0
  36. package/lib/enumOptionsDeselectValue.d.ts +14 -0
  37. package/lib/enumOptionsDeselectValue.js +22 -0
  38. package/lib/enumOptionsDeselectValue.js.map +1 -0
  39. package/lib/enumOptionsIndexForValue.d.ts +13 -0
  40. package/lib/enumOptionsIndexForValue.js +22 -0
  41. package/lib/enumOptionsIndexForValue.js.map +1 -0
  42. package/lib/enumOptionsIsSelected.d.ts +8 -0
  43. package/lib/enumOptionsIsSelected.js +14 -0
  44. package/lib/enumOptionsIsSelected.js.map +1 -0
  45. package/lib/enumOptionsSelectValue.d.ts +10 -0
  46. package/lib/enumOptionsSelectValue.js +23 -0
  47. package/lib/enumOptionsSelectValue.js.map +1 -0
  48. package/lib/enumOptionsValueForIndex.d.ts +13 -0
  49. package/lib/enumOptionsValueForIndex.js +21 -0
  50. package/lib/enumOptionsValueForIndex.js.map +1 -0
  51. package/lib/enums.d.ts +72 -0
  52. package/lib/enums.js +76 -0
  53. package/lib/enums.js.map +1 -0
  54. package/lib/findSchemaDefinition.d.ts +20 -0
  55. package/lib/findSchemaDefinition.js +49 -0
  56. package/lib/findSchemaDefinition.js.map +1 -0
  57. package/lib/getDiscriminatorFieldFromSchema.d.ts +8 -0
  58. package/lib/getDiscriminatorFieldFromSchema.js +20 -0
  59. package/lib/getDiscriminatorFieldFromSchema.js.map +1 -0
  60. package/lib/getInputProps.d.ts +10 -0
  61. package/lib/getInputProps.js +41 -0
  62. package/lib/getInputProps.js.map +1 -0
  63. package/lib/getSchemaType.d.ts +13 -0
  64. package/lib/getSchemaType.js +29 -0
  65. package/lib/getSchemaType.js.map +1 -0
  66. package/lib/getSubmitButtonOptions.d.ts +10 -0
  67. package/lib/getSubmitButtonOptions.js +25 -0
  68. package/lib/getSubmitButtonOptions.js.map +1 -0
  69. package/lib/getTemplate.d.ts +10 -0
  70. package/lib/getTemplate.js +19 -0
  71. package/lib/getTemplate.js.map +1 -0
  72. package/lib/getUiOptions.d.ts +9 -0
  73. package/lib/getUiOptions.js +25 -0
  74. package/lib/getUiOptions.js.map +1 -0
  75. package/lib/getWidget.d.ts +13 -0
  76. package/lib/getWidget.js +118 -0
  77. package/lib/getWidget.js.map +1 -0
  78. package/lib/guessType.d.ts +7 -0
  79. package/lib/guessType.js +29 -0
  80. package/lib/guessType.js.map +1 -0
  81. package/lib/hasWidget.d.ts +10 -0
  82. package/lib/hasWidget.js +23 -0
  83. package/lib/hasWidget.js.map +1 -0
  84. package/lib/hashForSchema.d.ts +8 -0
  85. package/lib/hashForSchema.js +29 -0
  86. package/lib/hashForSchema.js.map +1 -0
  87. package/lib/idGenerators.d.ts +47 -0
  88. package/lib/idGenerators.js +73 -0
  89. package/lib/idGenerators.js.map +1 -0
  90. package/lib/index.d.ts +57 -0
  91. package/lib/index.js +58 -0
  92. package/lib/index.js.map +1 -0
  93. package/lib/isConstant.d.ts +8 -0
  94. package/lib/isConstant.js +11 -0
  95. package/lib/isConstant.js.map +1 -0
  96. package/lib/isCustomWidget.d.ts +7 -0
  97. package/lib/isCustomWidget.js +13 -0
  98. package/lib/isCustomWidget.js.map +1 -0
  99. package/lib/isFixedItems.d.ts +8 -0
  100. package/lib/isFixedItems.js +11 -0
  101. package/lib/isFixedItems.js.map +1 -0
  102. package/lib/isObject.d.ts +7 -0
  103. package/lib/isObject.js +16 -0
  104. package/lib/isObject.js.map +1 -0
  105. package/lib/labelValue.d.ts +13 -0
  106. package/lib/labelValue.js +4 -0
  107. package/lib/labelValue.js.map +1 -0
  108. package/lib/localToUTC.d.ts +6 -0
  109. package/lib/localToUTC.js +9 -0
  110. package/lib/localToUTC.js.map +1 -0
  111. package/lib/mergeDefaultsWithFormData.d.ts +17 -0
  112. package/lib/mergeDefaultsWithFormData.js +43 -0
  113. package/lib/mergeDefaultsWithFormData.js.map +1 -0
  114. package/lib/mergeObjects.d.ts +11 -0
  115. package/lib/mergeObjects.js +35 -0
  116. package/lib/mergeObjects.js.map +1 -0
  117. package/lib/mergeSchemas.d.ts +10 -0
  118. package/lib/mergeSchemas.js +35 -0
  119. package/lib/mergeSchemas.js.map +1 -0
  120. package/lib/optionsList.d.ts +10 -0
  121. package/lib/optionsList.js +36 -0
  122. package/lib/optionsList.js.map +1 -0
  123. package/lib/orderProperties.d.ts +11 -0
  124. package/lib/orderProperties.js +38 -0
  125. package/lib/orderProperties.js.map +1 -0
  126. package/lib/pad.d.ts +7 -0
  127. package/lib/pad.js +14 -0
  128. package/lib/pad.js.map +1 -0
  129. package/lib/parseDateString.d.ts +9 -0
  130. package/lib/parseDateString.js +32 -0
  131. package/lib/parseDateString.js.map +1 -0
  132. package/lib/parser/ParserValidator.d.ts +70 -0
  133. package/lib/parser/ParserValidator.js +93 -0
  134. package/lib/parser/ParserValidator.js.map +1 -0
  135. package/lib/parser/index.d.ts +4 -0
  136. package/lib/parser/index.js +3 -0
  137. package/lib/parser/index.js.map +1 -0
  138. package/lib/parser/schemaParser.d.ts +9 -0
  139. package/lib/parser/schemaParser.js +48 -0
  140. package/lib/parser/schemaParser.js.map +1 -0
  141. package/lib/rangeSpec.d.ts +9 -0
  142. package/lib/rangeSpec.js +20 -0
  143. package/lib/rangeSpec.js.map +1 -0
  144. package/lib/replaceStringParameters.d.ts +9 -0
  145. package/lib/replaceStringParameters.js +23 -0
  146. package/lib/replaceStringParameters.js.map +1 -0
  147. package/lib/schema/getClosestMatchingOption.d.ts +49 -0
  148. package/lib/schema/getClosestMatchingOption.js +154 -0
  149. package/lib/schema/getClosestMatchingOption.js.map +1 -0
  150. package/lib/schema/getDefaultFormState.d.ts +66 -0
  151. package/lib/schema/getDefaultFormState.js +351 -0
  152. package/lib/schema/getDefaultFormState.js.map +1 -0
  153. package/lib/schema/getDisplayLabel.d.ts +12 -0
  154. package/lib/schema/getDisplayLabel.js +39 -0
  155. package/lib/schema/getDisplayLabel.js.map +1 -0
  156. package/lib/schema/getFirstMatchingOption.d.ts +13 -0
  157. package/lib/schema/getFirstMatchingOption.js +16 -0
  158. package/lib/schema/getFirstMatchingOption.js.map +1 -0
  159. package/lib/schema/getMatchingOption.d.ts +14 -0
  160. package/lib/schema/getMatchingOption.js +80 -0
  161. package/lib/schema/getMatchingOption.js.map +1 -0
  162. package/lib/schema/index.d.ts +14 -0
  163. package/lib/schema/index.js +15 -0
  164. package/lib/schema/index.js.map +1 -0
  165. package/lib/schema/isFilesArray.d.ts +10 -0
  166. package/lib/schema/isFilesArray.js +21 -0
  167. package/lib/schema/isFilesArray.js.map +1 -0
  168. package/lib/schema/isMultiSelect.d.ts +9 -0
  169. package/lib/schema/isMultiSelect.js +15 -0
  170. package/lib/schema/isMultiSelect.js.map +1 -0
  171. package/lib/schema/isSelect.d.ts +9 -0
  172. package/lib/schema/isSelect.js +21 -0
  173. package/lib/schema/isSelect.js.map +1 -0
  174. package/lib/schema/mergeValidationData.d.ts +14 -0
  175. package/lib/schema/mergeValidationData.js +28 -0
  176. package/lib/schema/mergeValidationData.js.map +1 -0
  177. package/lib/schema/retrieveSchema.d.ts +170 -0
  178. package/lib/schema/retrieveSchema.js +437 -0
  179. package/lib/schema/retrieveSchema.js.map +1 -0
  180. package/lib/schema/sanitizeDataForNewSchema.d.ts +49 -0
  181. package/lib/schema/sanitizeDataForNewSchema.js +173 -0
  182. package/lib/schema/sanitizeDataForNewSchema.js.map +1 -0
  183. package/lib/schema/toIdSchema.d.ts +13 -0
  184. package/lib/schema/toIdSchema.js +59 -0
  185. package/lib/schema/toIdSchema.js.map +1 -0
  186. package/lib/schema/toPathSchema.d.ts +11 -0
  187. package/lib/schema/toPathSchema.js +68 -0
  188. package/lib/schema/toPathSchema.js.map +1 -0
  189. package/lib/schemaRequiresTrueValue.d.ts +11 -0
  190. package/lib/schemaRequiresTrueValue.js +34 -0
  191. package/lib/schemaRequiresTrueValue.js.map +1 -0
  192. package/lib/shouldRender.d.ts +10 -0
  193. package/lib/shouldRender.js +14 -0
  194. package/lib/shouldRender.js.map +1 -0
  195. package/lib/toConstant.d.ts +9 -0
  196. package/lib/toConstant.js +18 -0
  197. package/lib/toConstant.js.map +1 -0
  198. package/lib/toDateString.d.ts +9 -0
  199. package/lib/toDateString.js +14 -0
  200. package/lib/toDateString.js.map +1 -0
  201. package/lib/toErrorList.d.ts +8 -0
  202. package/lib/toErrorList.js +34 -0
  203. package/lib/toErrorList.js.map +1 -0
  204. package/lib/toErrorSchema.d.ts +21 -0
  205. package/lib/toErrorSchema.js +41 -0
  206. package/lib/toErrorSchema.js.map +1 -0
  207. package/lib/types.d.ts +982 -0
  208. package/lib/types.js +2 -0
  209. package/lib/types.js.map +1 -0
  210. package/lib/unwrapErrorHandler.d.ts +7 -0
  211. package/lib/unwrapErrorHandler.js +21 -0
  212. package/lib/unwrapErrorHandler.js.map +1 -0
  213. package/lib/utcToLocal.d.ts +6 -0
  214. package/lib/utcToLocal.js +26 -0
  215. package/lib/utcToLocal.js.map +1 -0
  216. package/lib/validationDataMerge.d.ts +11 -0
  217. package/lib/validationDataMerge.js +26 -0
  218. package/lib/validationDataMerge.js.map +1 -0
  219. package/lib/withIdRefPrefix.d.ts +8 -0
  220. package/lib/withIdRefPrefix.js +47 -0
  221. package/lib/withIdRefPrefix.js.map +1 -0
  222. package/package.json +20 -13
  223. package/src/ErrorSchemaBuilder.ts +112 -0
  224. package/src/allowAdditionalItems.ts +15 -0
  225. package/src/asNumber.ts +38 -0
  226. package/src/canExpand.ts +31 -0
  227. package/src/constants.ts +31 -0
  228. package/src/createErrorHandler.ts +33 -0
  229. package/src/createSchemaUtils.ts +298 -0
  230. package/src/dataURItoBlob.ts +42 -0
  231. package/src/deepEquals.ts +19 -0
  232. package/src/englishStringTranslator.ts +14 -0
  233. package/src/enumOptionsDeselectValue.ts +28 -0
  234. package/src/enumOptionsIndexForValue.ts +27 -0
  235. package/src/enumOptionsIsSelected.ts +19 -0
  236. package/src/enumOptionsSelectValue.ts +28 -0
  237. package/src/enumOptionsValueForIndex.ts +26 -0
  238. package/src/enums.ts +74 -0
  239. package/src/findSchemaDefinition.ts +54 -0
  240. package/src/getDiscriminatorFieldFromSchema.ts +21 -0
  241. package/src/getInputProps.ts +55 -0
  242. package/src/getSchemaType.ts +37 -0
  243. package/src/getSubmitButtonOptions.ts +32 -0
  244. package/src/getTemplate.ts +26 -0
  245. package/src/getUiOptions.ts +32 -0
  246. package/src/getWidget.tsx +133 -0
  247. package/src/guessType.ts +28 -0
  248. package/src/hasWidget.ts +27 -0
  249. package/src/hashForSchema.ts +31 -0
  250. package/src/idGenerators.ts +81 -0
  251. package/src/index.ts +118 -0
  252. package/src/isConstant.ts +12 -0
  253. package/src/isCustomWidget.ts +19 -0
  254. package/src/isFixedItems.ts +12 -0
  255. package/src/isObject.ts +15 -0
  256. package/src/labelValue.ts +16 -0
  257. package/src/localToUTC.ts +8 -0
  258. package/src/mergeDefaultsWithFormData.ts +53 -0
  259. package/src/mergeObjects.ts +39 -0
  260. package/src/mergeSchemas.ts +38 -0
  261. package/src/optionsList.ts +41 -0
  262. package/src/orderProperties.ts +44 -0
  263. package/src/pad.ts +13 -0
  264. package/src/parseDateString.ts +33 -0
  265. package/src/parser/ParserValidator.ts +132 -0
  266. package/src/parser/index.ts +6 -0
  267. package/src/parser/schemaParser.ts +60 -0
  268. package/src/rangeSpec.ts +22 -0
  269. package/src/replaceStringParameters.ts +22 -0
  270. package/src/schema/getClosestMatchingOption.ts +191 -0
  271. package/src/schema/getDefaultFormState.ts +447 -0
  272. package/src/schema/getDisplayLabel.ts +59 -0
  273. package/src/schema/getFirstMatchingOption.ts +27 -0
  274. package/src/schema/getMatchingOption.ts +95 -0
  275. package/src/schema/index.ts +29 -0
  276. package/src/schema/isFilesArray.ts +27 -0
  277. package/src/schema/isMultiSelect.ts +21 -0
  278. package/src/schema/isSelect.ts +26 -0
  279. package/src/schema/mergeValidationData.ts +38 -0
  280. package/src/schema/retrieveSchema.ts +614 -0
  281. package/src/schema/sanitizeDataForNewSchema.ts +197 -0
  282. package/src/schema/toIdSchema.ts +105 -0
  283. package/src/schema/toPathSchema.ts +121 -0
  284. package/src/schemaRequiresTrueValue.ts +40 -0
  285. package/src/shouldRender.ts +16 -0
  286. package/src/toConstant.ts +19 -0
  287. package/src/toDateString.ts +15 -0
  288. package/src/toErrorList.ts +41 -0
  289. package/src/toErrorSchema.ts +43 -0
  290. package/src/types.ts +1139 -0
  291. package/src/unwrapErrorHandler.ts +25 -0
  292. package/src/utcToLocal.ts +30 -0
  293. package/src/validationDataMerge.ts +31 -0
  294. package/src/withIdRefPrefix.ts +49 -0
  295. package/dist/index.d.ts +0 -1911
  296. package/dist/utils.cjs.development.js +0 -3522
  297. package/dist/utils.cjs.development.js.map +0 -1
  298. package/dist/utils.cjs.production.min.js +0 -2
  299. package/dist/utils.cjs.production.min.js.map +0 -1
  300. package/dist/utils.umd.development.js +0 -3504
  301. package/dist/utils.umd.development.js.map +0 -1
  302. package/dist/utils.umd.production.min.js +0 -2
  303. package/dist/utils.umd.production.min.js.map +0 -1
@@ -0,0 +1,2414 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash/isPlainObject'), require('lodash/isEqualWith'), require('lodash/get'), require('lodash/isEmpty'), require('jsonpointer'), require('lodash/omit'), require('lodash/has'), require('lodash/isObject'), require('lodash/isString'), require('lodash/reduce'), require('lodash/times'), require('lodash/set'), require('lodash/transform'), require('json-schema-merge-allof'), require('lodash/union'), require('lodash/isEqual'), require('lodash'), require('lodash/cloneDeep'), require('react'), require('react-is'), require('react/jsx-runtime'), require('lodash/toPath'), require('lodash/forEach')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'lodash/isPlainObject', 'lodash/isEqualWith', 'lodash/get', 'lodash/isEmpty', 'jsonpointer', 'lodash/omit', 'lodash/has', 'lodash/isObject', 'lodash/isString', 'lodash/reduce', 'lodash/times', 'lodash/set', 'lodash/transform', 'json-schema-merge-allof', 'lodash/union', 'lodash/isEqual', 'lodash', 'lodash/cloneDeep', 'react', 'react-is', 'react/jsx-runtime', 'lodash/toPath', 'lodash/forEach'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@rjsf/utils"] = {}, global.isPlainObject, global.isEqualWith, global.get7, global.isEmpty, global.jsonpointer, global.omit, global.has3, global.isObject2, global.isString, global.reduce, global.times, global.set3, global.transform, global.mergeAllOf, global.union, global.isEqual3, global.lodash, global.cloneDeep, global.react, global.ReactIs, global.jsxRuntime, global.toPath, global.forEach));
5
+ })(this, (function (exports, isPlainObject, isEqualWith, get7, isEmpty, jsonpointer, omit, has3, isObject2, isString, reduce, times, set3, transform, mergeAllOf, union, isEqual3, lodash, cloneDeep, react, ReactIs, jsxRuntime, toPath, forEach) { 'use strict';
6
+
7
+ // src/isObject.ts
8
+ function isObject(thing) {
9
+ if (typeof File !== "undefined" && thing instanceof File) {
10
+ return false;
11
+ }
12
+ if (typeof Date !== "undefined" && thing instanceof Date) {
13
+ return false;
14
+ }
15
+ return typeof thing === "object" && thing !== null && !Array.isArray(thing);
16
+ }
17
+
18
+ // src/allowAdditionalItems.ts
19
+ function allowAdditionalItems(schema) {
20
+ if (schema.additionalItems === true) {
21
+ console.warn("additionalItems=true is currently not supported");
22
+ }
23
+ return isObject(schema.additionalItems);
24
+ }
25
+
26
+ // src/asNumber.ts
27
+ function asNumber(value) {
28
+ if (value === "") {
29
+ return void 0;
30
+ }
31
+ if (value === null) {
32
+ return null;
33
+ }
34
+ if (/\.$/.test(value)) {
35
+ return value;
36
+ }
37
+ if (/\.0$/.test(value)) {
38
+ return value;
39
+ }
40
+ if (/\.\d*0$/.test(value)) {
41
+ return value;
42
+ }
43
+ const n = Number(value);
44
+ const valid = typeof n === "number" && !Number.isNaN(n);
45
+ return valid ? n : value;
46
+ }
47
+
48
+ // src/constants.ts
49
+ var ADDITIONAL_PROPERTY_FLAG = "__additional_property";
50
+ var ADDITIONAL_PROPERTIES_KEY = "additionalProperties";
51
+ var ALL_OF_KEY = "allOf";
52
+ var ANY_OF_KEY = "anyOf";
53
+ var CONST_KEY = "const";
54
+ var DEFAULT_KEY = "default";
55
+ var DEFINITIONS_KEY = "definitions";
56
+ var DEPENDENCIES_KEY = "dependencies";
57
+ var ENUM_KEY = "enum";
58
+ var ERRORS_KEY = "__errors";
59
+ var ID_KEY = "$id";
60
+ var IF_KEY = "if";
61
+ var ITEMS_KEY = "items";
62
+ var JUNK_OPTION_ID = "_$junk_option_schema_id$_";
63
+ var NAME_KEY = "$name";
64
+ var ONE_OF_KEY = "oneOf";
65
+ var PROPERTIES_KEY = "properties";
66
+ var REQUIRED_KEY = "required";
67
+ var SUBMIT_BTN_OPTIONS_KEY = "submitButtonOptions";
68
+ var REF_KEY = "$ref";
69
+ var RJSF_ADDITONAL_PROPERTIES_FLAG = "__rjsf_additionalProperties";
70
+ var ROOT_SCHEMA_PREFIX = "__rjsf_rootSchema";
71
+ var UI_FIELD_KEY = "ui:field";
72
+ var UI_WIDGET_KEY = "ui:widget";
73
+ var UI_OPTIONS_KEY = "ui:options";
74
+ var UI_GLOBAL_OPTIONS_KEY = "ui:globalOptions";
75
+
76
+ // src/getUiOptions.ts
77
+ function getUiOptions(uiSchema = {}, globalOptions = {}) {
78
+ return Object.keys(uiSchema).filter((key) => key.indexOf("ui:") === 0).reduce(
79
+ (options, key) => {
80
+ const value = uiSchema[key];
81
+ if (key === UI_WIDGET_KEY && isObject(value)) {
82
+ console.error("Setting options via ui:widget object is no longer supported, use ui:options instead");
83
+ return options;
84
+ }
85
+ if (key === UI_OPTIONS_KEY && isObject(value)) {
86
+ return { ...options, ...value };
87
+ }
88
+ return { ...options, [key.substring(3)]: value };
89
+ },
90
+ { ...globalOptions }
91
+ );
92
+ }
93
+
94
+ // src/canExpand.ts
95
+ function canExpand(schema, uiSchema = {}, formData) {
96
+ if (!schema.additionalProperties) {
97
+ return false;
98
+ }
99
+ const { expandable = true } = getUiOptions(uiSchema);
100
+ if (expandable === false) {
101
+ return expandable;
102
+ }
103
+ if (schema.maxProperties !== void 0 && formData) {
104
+ return Object.keys(formData).length < schema.maxProperties;
105
+ }
106
+ return true;
107
+ }
108
+ function createErrorHandler(formData) {
109
+ const handler = {
110
+ // We store the list of errors for this node in a property named __errors
111
+ // to avoid name collision with a possible sub schema field named
112
+ // 'errors' (see `utils.toErrorSchema`).
113
+ [ERRORS_KEY]: [],
114
+ addError(message) {
115
+ this[ERRORS_KEY].push(message);
116
+ }
117
+ };
118
+ if (Array.isArray(formData)) {
119
+ return formData.reduce((acc, value, key) => {
120
+ return { ...acc, [key]: createErrorHandler(value) };
121
+ }, handler);
122
+ }
123
+ if (isPlainObject(formData)) {
124
+ const formObject = formData;
125
+ return Object.keys(formObject).reduce((acc, key) => {
126
+ return { ...acc, [key]: createErrorHandler(formObject[key]) };
127
+ }, handler);
128
+ }
129
+ return handler;
130
+ }
131
+ function deepEquals(a, b) {
132
+ return isEqualWith(a, b, (obj, other) => {
133
+ if (typeof obj === "function" && typeof other === "function") {
134
+ return true;
135
+ }
136
+ return void 0;
137
+ });
138
+ }
139
+ function splitKeyElementFromObject(key, object) {
140
+ const value = object[key];
141
+ const remaining = omit(object, [key]);
142
+ return [remaining, value];
143
+ }
144
+ function findSchemaDefinition($ref, rootSchema = {}) {
145
+ let ref = $ref || "";
146
+ if (ref.startsWith("#")) {
147
+ ref = decodeURIComponent(ref.substring(1));
148
+ } else {
149
+ throw new Error(`Could not find a definition for ${$ref}.`);
150
+ }
151
+ const current = jsonpointer.get(rootSchema, ref);
152
+ if (current === void 0) {
153
+ throw new Error(`Could not find a definition for ${$ref}.`);
154
+ }
155
+ if (current[REF_KEY]) {
156
+ const [remaining, theRef] = splitKeyElementFromObject(REF_KEY, current);
157
+ const subSchema = findSchemaDefinition(theRef, rootSchema);
158
+ if (Object.keys(remaining).length > 0) {
159
+ return { ...remaining, ...subSchema };
160
+ }
161
+ return subSchema;
162
+ }
163
+ return current;
164
+ }
165
+ function getMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
166
+ if (formData === void 0) {
167
+ return 0;
168
+ }
169
+ for (let i = 0; i < options.length; i++) {
170
+ const option = options[i];
171
+ if (discriminatorField && has3(option, [PROPERTIES_KEY, discriminatorField])) {
172
+ const value = get7(formData, discriminatorField);
173
+ const discriminator = get7(option, [PROPERTIES_KEY, discriminatorField], {});
174
+ if (validator.isValid(discriminator, value, rootSchema)) {
175
+ return i;
176
+ }
177
+ } else if (option[PROPERTIES_KEY]) {
178
+ const requiresAnyOf = {
179
+ anyOf: Object.keys(option[PROPERTIES_KEY]).map((key) => ({
180
+ required: [key]
181
+ }))
182
+ };
183
+ let augmentedSchema;
184
+ if (option.anyOf) {
185
+ const { ...shallowClone } = option;
186
+ if (!shallowClone.allOf) {
187
+ shallowClone.allOf = [];
188
+ } else {
189
+ shallowClone.allOf = shallowClone.allOf.slice();
190
+ }
191
+ shallowClone.allOf.push(requiresAnyOf);
192
+ augmentedSchema = shallowClone;
193
+ } else {
194
+ augmentedSchema = Object.assign({}, option, requiresAnyOf);
195
+ }
196
+ delete augmentedSchema.required;
197
+ if (validator.isValid(augmentedSchema, formData, rootSchema)) {
198
+ return i;
199
+ }
200
+ } else if (validator.isValid(option, formData, rootSchema)) {
201
+ return i;
202
+ }
203
+ }
204
+ return 0;
205
+ }
206
+
207
+ // src/schema/getFirstMatchingOption.ts
208
+ function getFirstMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
209
+ return getMatchingOption(validator, formData, options, rootSchema, discriminatorField);
210
+ }
211
+ function getDiscriminatorFieldFromSchema(schema) {
212
+ let discriminator;
213
+ const maybeString = get7(schema, "discriminator.propertyName", void 0);
214
+ if (isString(maybeString)) {
215
+ discriminator = maybeString;
216
+ } else if (maybeString !== void 0) {
217
+ console.warn(`Expecting discriminator to be a string, got "${typeof maybeString}" instead`);
218
+ }
219
+ return discriminator;
220
+ }
221
+
222
+ // src/guessType.ts
223
+ function guessType(value) {
224
+ if (Array.isArray(value)) {
225
+ return "array";
226
+ }
227
+ if (typeof value === "string") {
228
+ return "string";
229
+ }
230
+ if (value == null) {
231
+ return "null";
232
+ }
233
+ if (typeof value === "boolean") {
234
+ return "boolean";
235
+ }
236
+ if (!isNaN(value)) {
237
+ return "number";
238
+ }
239
+ if (typeof value === "object") {
240
+ return "object";
241
+ }
242
+ return "string";
243
+ }
244
+
245
+ // src/getSchemaType.ts
246
+ function getSchemaType(schema) {
247
+ let { type } = schema;
248
+ if (!type && schema.const) {
249
+ return guessType(schema.const);
250
+ }
251
+ if (!type && schema.enum) {
252
+ return "string";
253
+ }
254
+ if (!type && (schema.properties || schema.additionalProperties)) {
255
+ return "object";
256
+ }
257
+ if (Array.isArray(type) && type.length === 2 && type.includes("null")) {
258
+ type = type.find((type2) => type2 !== "null");
259
+ }
260
+ return type;
261
+ }
262
+
263
+ // src/mergeSchemas.ts
264
+ function mergeSchemas(obj1, obj2) {
265
+ const acc = Object.assign({}, obj1);
266
+ return Object.keys(obj2).reduce((acc2, key) => {
267
+ const left = obj1 ? obj1[key] : {}, right = obj2[key];
268
+ if (obj1 && key in obj1 && isObject(right)) {
269
+ acc2[key] = mergeSchemas(left, right);
270
+ } else if (obj1 && obj2 && (getSchemaType(obj1) === "object" || getSchemaType(obj2) === "object") && key === REQUIRED_KEY && Array.isArray(left) && Array.isArray(right)) {
271
+ acc2[key] = union(left, right);
272
+ } else {
273
+ acc2[key] = right;
274
+ }
275
+ return acc2;
276
+ }, acc);
277
+ }
278
+
279
+ // src/schema/retrieveSchema.ts
280
+ function retrieveSchema(validator, schema, rootSchema = {}, rawFormData) {
281
+ return retrieveSchemaInternal(validator, schema, rootSchema, rawFormData)[0];
282
+ }
283
+ function resolveCondition(validator, schema, rootSchema, expandAllBranches, formData) {
284
+ const { if: expression, then, else: otherwise, ...resolvedSchemaLessConditional } = schema;
285
+ const conditionValue = validator.isValid(expression, formData || {}, rootSchema);
286
+ let resolvedSchemas = [resolvedSchemaLessConditional];
287
+ let schemas = [];
288
+ if (expandAllBranches) {
289
+ if (then && typeof then !== "boolean") {
290
+ schemas = schemas.concat(
291
+ retrieveSchemaInternal(validator, then, rootSchema, formData, expandAllBranches)
292
+ );
293
+ }
294
+ if (otherwise && typeof otherwise !== "boolean") {
295
+ schemas = schemas.concat(
296
+ retrieveSchemaInternal(validator, otherwise, rootSchema, formData, expandAllBranches)
297
+ );
298
+ }
299
+ } else {
300
+ const conditionalSchema = conditionValue ? then : otherwise;
301
+ if (conditionalSchema && typeof conditionalSchema !== "boolean") {
302
+ schemas = schemas.concat(
303
+ retrieveSchemaInternal(validator, conditionalSchema, rootSchema, formData, expandAllBranches)
304
+ );
305
+ }
306
+ }
307
+ if (schemas.length) {
308
+ resolvedSchemas = schemas.map((s) => mergeSchemas(resolvedSchemaLessConditional, s));
309
+ }
310
+ return resolvedSchemas.flatMap(
311
+ (s) => retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches)
312
+ );
313
+ }
314
+ function getAllPermutationsOfXxxOf(listOfLists) {
315
+ const allPermutations = listOfLists.reduce(
316
+ (permutations, list) => {
317
+ if (list.length > 1) {
318
+ return list.flatMap((element) => times(permutations.length, (i) => [...permutations[i]].concat(element)));
319
+ }
320
+ permutations.forEach((permutation) => permutation.push(list[0]));
321
+ return permutations;
322
+ },
323
+ [[]]
324
+ // Start with an empty list
325
+ );
326
+ return allPermutations;
327
+ }
328
+ function resolveSchema(validator, schema, rootSchema, expandAllBranches, formData) {
329
+ if (REF_KEY in schema) {
330
+ return resolveReference(validator, schema, rootSchema, expandAllBranches, formData);
331
+ }
332
+ if (DEPENDENCIES_KEY in schema) {
333
+ const resolvedSchemas = resolveDependencies(validator, schema, rootSchema, expandAllBranches, formData);
334
+ return resolvedSchemas.flatMap((s) => {
335
+ return retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches);
336
+ });
337
+ }
338
+ if (ALL_OF_KEY in schema && Array.isArray(schema.allOf)) {
339
+ const allOfSchemaElements = schema.allOf.map(
340
+ (allOfSubschema) => retrieveSchemaInternal(validator, allOfSubschema, rootSchema, formData, expandAllBranches)
341
+ );
342
+ const allPermutations = getAllPermutationsOfXxxOf(allOfSchemaElements);
343
+ return allPermutations.map((permutation) => ({ ...schema, allOf: permutation }));
344
+ }
345
+ return [schema];
346
+ }
347
+ function resolveReference(validator, schema, rootSchema, expandAllBranches, formData) {
348
+ const { $ref, ...localSchema } = schema;
349
+ const refSchema = findSchemaDefinition($ref, rootSchema);
350
+ return retrieveSchemaInternal(
351
+ validator,
352
+ { ...refSchema, ...localSchema },
353
+ rootSchema,
354
+ formData,
355
+ expandAllBranches
356
+ );
357
+ }
358
+ function resolveAllReferences(schema, rootSchema) {
359
+ let resolvedSchema = schema;
360
+ if (REF_KEY in resolvedSchema) {
361
+ const { $ref, ...localSchema } = resolvedSchema;
362
+ const refSchema = findSchemaDefinition($ref, rootSchema);
363
+ resolvedSchema = { ...refSchema, ...localSchema };
364
+ }
365
+ if (PROPERTIES_KEY in resolvedSchema) {
366
+ const updatedProps = transform(
367
+ resolvedSchema[PROPERTIES_KEY],
368
+ (result, value, key) => {
369
+ result[key] = resolveAllReferences(value, rootSchema);
370
+ },
371
+ {}
372
+ );
373
+ resolvedSchema = { ...resolvedSchema, [PROPERTIES_KEY]: updatedProps };
374
+ }
375
+ if (ITEMS_KEY in resolvedSchema && !Array.isArray(resolvedSchema.items) && typeof resolvedSchema.items !== "boolean") {
376
+ resolvedSchema = { ...resolvedSchema, items: resolveAllReferences(resolvedSchema.items, rootSchema) };
377
+ }
378
+ return resolvedSchema;
379
+ }
380
+ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData) {
381
+ const schema = {
382
+ ...theSchema,
383
+ properties: { ...theSchema.properties }
384
+ };
385
+ const formData = aFormData && isObject(aFormData) ? aFormData : {};
386
+ Object.keys(formData).forEach((key) => {
387
+ if (key in schema.properties) {
388
+ return;
389
+ }
390
+ let additionalProperties = {};
391
+ if (typeof schema.additionalProperties !== "boolean") {
392
+ if (REF_KEY in schema.additionalProperties) {
393
+ additionalProperties = retrieveSchema(
394
+ validator,
395
+ { $ref: get7(schema.additionalProperties, [REF_KEY]) },
396
+ rootSchema,
397
+ formData
398
+ );
399
+ } else if ("type" in schema.additionalProperties) {
400
+ additionalProperties = { ...schema.additionalProperties };
401
+ } else if (ANY_OF_KEY in schema.additionalProperties || ONE_OF_KEY in schema.additionalProperties) {
402
+ additionalProperties = {
403
+ type: "object",
404
+ ...schema.additionalProperties
405
+ };
406
+ } else {
407
+ additionalProperties = { type: guessType(get7(formData, [key])) };
408
+ }
409
+ } else {
410
+ additionalProperties = { type: guessType(get7(formData, [key])) };
411
+ }
412
+ schema.properties[key] = additionalProperties;
413
+ set3(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
414
+ });
415
+ return schema;
416
+ }
417
+ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false) {
418
+ if (!isObject(schema)) {
419
+ return [{}];
420
+ }
421
+ const resolvedSchemas = resolveSchema(validator, schema, rootSchema, expandAllBranches, rawFormData);
422
+ return resolvedSchemas.flatMap((s) => {
423
+ let resolvedSchema = s;
424
+ if (IF_KEY in resolvedSchema) {
425
+ return resolveCondition(validator, resolvedSchema, rootSchema, expandAllBranches, rawFormData);
426
+ }
427
+ if (ALL_OF_KEY in resolvedSchema) {
428
+ if (expandAllBranches) {
429
+ return [...resolvedSchema.allOf];
430
+ }
431
+ try {
432
+ resolvedSchema = mergeAllOf(resolvedSchema, {
433
+ deep: false
434
+ });
435
+ } catch (e) {
436
+ console.warn("could not merge subschemas in allOf:\n", e);
437
+ const { allOf, ...resolvedSchemaWithoutAllOf } = resolvedSchema;
438
+ return resolvedSchemaWithoutAllOf;
439
+ }
440
+ }
441
+ const hasAdditionalProperties = ADDITIONAL_PROPERTIES_KEY in resolvedSchema && resolvedSchema.additionalProperties !== false;
442
+ if (hasAdditionalProperties) {
443
+ return stubExistingAdditionalProperties(validator, resolvedSchema, rootSchema, rawFormData);
444
+ }
445
+ return resolvedSchema;
446
+ });
447
+ }
448
+ function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranches, rawFormData) {
449
+ let anyOrOneOf;
450
+ const { oneOf, anyOf, ...remaining } = schema;
451
+ if (Array.isArray(oneOf)) {
452
+ anyOrOneOf = oneOf;
453
+ } else if (Array.isArray(anyOf)) {
454
+ anyOrOneOf = anyOf;
455
+ }
456
+ if (anyOrOneOf) {
457
+ const formData = rawFormData === void 0 && expandAllBranches ? {} : rawFormData;
458
+ const discriminator = getDiscriminatorFieldFromSchema(schema);
459
+ anyOrOneOf = anyOrOneOf.map((s) => {
460
+ return resolveAllReferences(s, rootSchema);
461
+ });
462
+ const option = getFirstMatchingOption(validator, formData, anyOrOneOf, rootSchema, discriminator);
463
+ if (expandAllBranches) {
464
+ return anyOrOneOf.map((item) => mergeSchemas(remaining, item));
465
+ }
466
+ schema = mergeSchemas(remaining, anyOrOneOf[option]);
467
+ }
468
+ return [schema];
469
+ }
470
+ function resolveDependencies(validator, schema, rootSchema, expandAllBranches, formData) {
471
+ const { dependencies, ...remainingSchema } = schema;
472
+ const resolvedSchemas = resolveAnyOrOneOfSchemas(
473
+ validator,
474
+ remainingSchema,
475
+ rootSchema,
476
+ expandAllBranches,
477
+ formData
478
+ );
479
+ return resolvedSchemas.flatMap(
480
+ (resolvedSchema) => processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, formData)
481
+ );
482
+ }
483
+ function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, formData) {
484
+ let schemas = [resolvedSchema];
485
+ for (const dependencyKey in dependencies) {
486
+ if (!expandAllBranches && get7(formData, [dependencyKey]) === void 0) {
487
+ continue;
488
+ }
489
+ if (resolvedSchema.properties && !(dependencyKey in resolvedSchema.properties)) {
490
+ continue;
491
+ }
492
+ const [remainingDependencies, dependencyValue] = splitKeyElementFromObject(
493
+ dependencyKey,
494
+ dependencies
495
+ );
496
+ if (Array.isArray(dependencyValue)) {
497
+ schemas[0] = withDependentProperties(resolvedSchema, dependencyValue);
498
+ } else if (isObject(dependencyValue)) {
499
+ schemas = withDependentSchema(
500
+ validator,
501
+ resolvedSchema,
502
+ rootSchema,
503
+ dependencyKey,
504
+ dependencyValue,
505
+ expandAllBranches,
506
+ formData
507
+ );
508
+ }
509
+ return schemas.flatMap(
510
+ (schema) => processDependencies(validator, remainingDependencies, schema, rootSchema, expandAllBranches, formData)
511
+ );
512
+ }
513
+ return schemas;
514
+ }
515
+ function withDependentProperties(schema, additionallyRequired) {
516
+ if (!additionallyRequired) {
517
+ return schema;
518
+ }
519
+ const required = Array.isArray(schema.required) ? Array.from(/* @__PURE__ */ new Set([...schema.required, ...additionallyRequired])) : additionallyRequired;
520
+ return { ...schema, required };
521
+ }
522
+ function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, formData) {
523
+ const dependentSchemas = retrieveSchemaInternal(
524
+ validator,
525
+ dependencyValue,
526
+ rootSchema,
527
+ formData,
528
+ expandAllBranches
529
+ );
530
+ return dependentSchemas.flatMap((dependent) => {
531
+ const { oneOf, ...dependentSchema } = dependent;
532
+ schema = mergeSchemas(schema, dependentSchema);
533
+ if (oneOf === void 0) {
534
+ return schema;
535
+ }
536
+ const resolvedOneOfs = oneOf.map((subschema) => {
537
+ if (typeof subschema === "boolean" || !(REF_KEY in subschema)) {
538
+ return [subschema];
539
+ }
540
+ return resolveReference(validator, subschema, rootSchema, expandAllBranches, formData);
541
+ });
542
+ const allPermutations = getAllPermutationsOfXxxOf(resolvedOneOfs);
543
+ return allPermutations.flatMap(
544
+ (resolvedOneOf) => withExactlyOneSubschema(
545
+ validator,
546
+ schema,
547
+ rootSchema,
548
+ dependencyKey,
549
+ resolvedOneOf,
550
+ expandAllBranches,
551
+ formData
552
+ )
553
+ );
554
+ });
555
+ }
556
+ function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, formData) {
557
+ const validSubschemas = oneOf.filter((subschema) => {
558
+ if (typeof subschema === "boolean" || !subschema || !subschema.properties) {
559
+ return false;
560
+ }
561
+ const { [dependencyKey]: conditionPropertySchema } = subschema.properties;
562
+ if (conditionPropertySchema) {
563
+ const conditionSchema = {
564
+ type: "object",
565
+ properties: {
566
+ [dependencyKey]: conditionPropertySchema
567
+ }
568
+ };
569
+ return validator.isValid(conditionSchema, formData, rootSchema) || expandAllBranches;
570
+ }
571
+ return false;
572
+ });
573
+ if (!expandAllBranches && validSubschemas.length !== 1) {
574
+ console.warn("ignoring oneOf in dependencies because there isn't exactly one subschema that is valid");
575
+ return [schema];
576
+ }
577
+ return validSubschemas.flatMap((s) => {
578
+ const subschema = s;
579
+ const [dependentSubschema] = splitKeyElementFromObject(dependencyKey, subschema.properties);
580
+ const dependentSchema = { ...subschema, properties: dependentSubschema };
581
+ const schemas = retrieveSchemaInternal(
582
+ validator,
583
+ dependentSchema,
584
+ rootSchema,
585
+ formData,
586
+ expandAllBranches
587
+ );
588
+ return schemas.map((s2) => mergeSchemas(schema, s2));
589
+ });
590
+ }
591
+
592
+ // src/schema/getClosestMatchingOption.ts
593
+ var JUNK_OPTION = {
594
+ type: "object",
595
+ $id: JUNK_OPTION_ID,
596
+ properties: {
597
+ __not_really_there__: {
598
+ type: "number"
599
+ }
600
+ }
601
+ };
602
+ function calculateIndexScore(validator, rootSchema, schema, formData = {}) {
603
+ let totalScore = 0;
604
+ if (schema) {
605
+ if (isObject2(schema.properties)) {
606
+ totalScore += reduce(
607
+ schema.properties,
608
+ (score, value, key) => {
609
+ const formValue = get7(formData, key);
610
+ if (typeof value === "boolean") {
611
+ return score;
612
+ }
613
+ if (has3(value, REF_KEY)) {
614
+ const newSchema = retrieveSchema(validator, value, rootSchema, formValue);
615
+ return score + calculateIndexScore(validator, rootSchema, newSchema, formValue || {});
616
+ }
617
+ if ((has3(value, ONE_OF_KEY) || has3(value, ANY_OF_KEY)) && formValue) {
618
+ const key2 = has3(value, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
619
+ const discriminator = getDiscriminatorFieldFromSchema(value);
620
+ return score + getClosestMatchingOption(
621
+ validator,
622
+ rootSchema,
623
+ formValue,
624
+ get7(value, key2),
625
+ -1,
626
+ discriminator
627
+ );
628
+ }
629
+ if (value.type === "object") {
630
+ return score + calculateIndexScore(validator, rootSchema, value, formValue || {});
631
+ }
632
+ if (value.type === guessType(formValue)) {
633
+ let newScore = score + 1;
634
+ if (value.default) {
635
+ newScore += formValue === value.default ? 1 : -1;
636
+ } else if (value.const) {
637
+ newScore += formValue === value.const ? 1 : -1;
638
+ }
639
+ return newScore;
640
+ }
641
+ return score;
642
+ },
643
+ 0
644
+ );
645
+ } else if (isString(schema.type) && schema.type === guessType(formData)) {
646
+ totalScore += 1;
647
+ }
648
+ }
649
+ return totalScore;
650
+ }
651
+ function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption = -1, discriminatorField) {
652
+ const resolvedOptions = options.map((option) => {
653
+ return resolveAllReferences(option, rootSchema);
654
+ });
655
+ const allValidIndexes = resolvedOptions.reduce((validList, option, index) => {
656
+ const testOptions = [JUNK_OPTION, option];
657
+ const match = getFirstMatchingOption(validator, formData, testOptions, rootSchema, discriminatorField);
658
+ if (match === 1) {
659
+ validList.push(index);
660
+ }
661
+ return validList;
662
+ }, []);
663
+ if (allValidIndexes.length === 1) {
664
+ return allValidIndexes[0];
665
+ }
666
+ if (!allValidIndexes.length) {
667
+ times(resolvedOptions.length, (i) => allValidIndexes.push(i));
668
+ }
669
+ const scoreCount = /* @__PURE__ */ new Set();
670
+ const { bestIndex } = allValidIndexes.reduce(
671
+ (scoreData, index) => {
672
+ const { bestScore } = scoreData;
673
+ const option = resolvedOptions[index];
674
+ const score = calculateIndexScore(validator, rootSchema, option, formData);
675
+ scoreCount.add(score);
676
+ if (score > bestScore) {
677
+ return { bestIndex: index, bestScore: score };
678
+ }
679
+ return scoreData;
680
+ },
681
+ { bestIndex: selectedOption, bestScore: 0 }
682
+ );
683
+ if (scoreCount.size === 1 && selectedOption >= 0) {
684
+ return selectedOption;
685
+ }
686
+ return bestIndex;
687
+ }
688
+
689
+ // src/isFixedItems.ts
690
+ function isFixedItems(schema) {
691
+ return Array.isArray(schema.items) && schema.items.length > 0 && schema.items.every((item) => isObject(item));
692
+ }
693
+ function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults = false) {
694
+ if (Array.isArray(formData)) {
695
+ const defaultsArray = Array.isArray(defaults) ? defaults : [];
696
+ const mapped = formData.map((value, idx) => {
697
+ if (defaultsArray[idx]) {
698
+ return mergeDefaultsWithFormData(defaultsArray[idx], value, mergeExtraArrayDefaults);
699
+ }
700
+ return value;
701
+ });
702
+ if (mergeExtraArrayDefaults && mapped.length < defaultsArray.length) {
703
+ mapped.push(...defaultsArray.slice(mapped.length));
704
+ }
705
+ return mapped;
706
+ }
707
+ if (isObject(formData)) {
708
+ const acc = Object.assign({}, defaults);
709
+ return Object.keys(formData).reduce((acc2, key) => {
710
+ acc2[key] = mergeDefaultsWithFormData(
711
+ defaults ? get7(defaults, key) : {},
712
+ get7(formData, key),
713
+ mergeExtraArrayDefaults
714
+ );
715
+ return acc2;
716
+ }, acc);
717
+ }
718
+ return formData;
719
+ }
720
+
721
+ // src/mergeObjects.ts
722
+ function mergeObjects(obj1, obj2, concatArrays = false) {
723
+ return Object.keys(obj2).reduce((acc, key) => {
724
+ const left = obj1 ? obj1[key] : {}, right = obj2[key];
725
+ if (obj1 && key in obj1 && isObject(right)) {
726
+ acc[key] = mergeObjects(left, right, concatArrays);
727
+ } else if (concatArrays && Array.isArray(left) && Array.isArray(right)) {
728
+ let toMerge = right;
729
+ if (concatArrays === "preventDuplicates") {
730
+ toMerge = right.reduce((result, value) => {
731
+ if (!left.includes(value)) {
732
+ result.push(value);
733
+ }
734
+ return result;
735
+ }, []);
736
+ }
737
+ acc[key] = left.concat(toMerge);
738
+ } else {
739
+ acc[key] = right;
740
+ }
741
+ return acc;
742
+ }, Object.assign({}, obj1));
743
+ }
744
+
745
+ // src/isConstant.ts
746
+ function isConstant(schema) {
747
+ return Array.isArray(schema.enum) && schema.enum.length === 1 || CONST_KEY in schema;
748
+ }
749
+
750
+ // src/schema/isSelect.ts
751
+ function isSelect(validator, theSchema, rootSchema = {}) {
752
+ const schema = retrieveSchema(validator, theSchema, rootSchema, void 0);
753
+ const altSchemas = schema.oneOf || schema.anyOf;
754
+ if (Array.isArray(schema.enum)) {
755
+ return true;
756
+ }
757
+ if (Array.isArray(altSchemas)) {
758
+ return altSchemas.every((altSchemas2) => typeof altSchemas2 !== "boolean" && isConstant(altSchemas2));
759
+ }
760
+ return false;
761
+ }
762
+
763
+ // src/schema/isMultiSelect.ts
764
+ function isMultiSelect(validator, schema, rootSchema) {
765
+ if (!schema.uniqueItems || !schema.items || typeof schema.items === "boolean") {
766
+ return false;
767
+ }
768
+ return isSelect(validator, schema.items, rootSchema);
769
+ }
770
+
771
+ // src/schema/getDefaultFormState.ts
772
+ function getInnerSchemaForArrayItem(schema, additionalItems = 0 /* Ignore */, idx = -1) {
773
+ if (idx >= 0) {
774
+ if (Array.isArray(schema.items) && idx < schema.items.length) {
775
+ const item = schema.items[idx];
776
+ if (typeof item !== "boolean") {
777
+ return item;
778
+ }
779
+ }
780
+ } else if (schema.items && !Array.isArray(schema.items) && typeof schema.items !== "boolean") {
781
+ return schema.items;
782
+ }
783
+ if (additionalItems !== 0 /* Ignore */ && isObject(schema.additionalItems)) {
784
+ return schema.additionalItems;
785
+ }
786
+ return {};
787
+ }
788
+ function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields = [], experimental_defaultFormStateBehavior = {}) {
789
+ const { emptyObjectFields = "populateAllDefaults" } = experimental_defaultFormStateBehavior;
790
+ if (includeUndefinedValues) {
791
+ obj[key] = computedDefault;
792
+ } else if (emptyObjectFields !== "skipDefaults") {
793
+ if (isObject(computedDefault)) {
794
+ const isSelfOrParentRequired = isParentRequired === void 0 ? requiredFields.includes(key) : isParentRequired;
795
+ if ((!isEmpty(computedDefault) || requiredFields.includes(key)) && (isSelfOrParentRequired || emptyObjectFields !== "populateRequiredDefaults")) {
796
+ obj[key] = computedDefault;
797
+ }
798
+ } else if (
799
+ // Store computedDefault if it's a defined primitive (e.g., true) and satisfies certain conditions
800
+ // Condition 1: computedDefault is not undefined
801
+ // Condition 2: If emptyObjectFields is 'populateAllDefaults' or if the key is a required field
802
+ computedDefault !== void 0 && (emptyObjectFields === "populateAllDefaults" || requiredFields.includes(key))
803
+ ) {
804
+ obj[key] = computedDefault;
805
+ }
806
+ }
807
+ }
808
+ function computeDefaults(validator, rawSchema, {
809
+ parentDefaults,
810
+ rawFormData,
811
+ rootSchema = {},
812
+ includeUndefinedValues = false,
813
+ _recurseList = [],
814
+ experimental_defaultFormStateBehavior = void 0,
815
+ required
816
+ } = {}) {
817
+ const formData = isObject(rawFormData) ? rawFormData : {};
818
+ const schema = isObject(rawSchema) ? rawSchema : {};
819
+ let defaults = parentDefaults;
820
+ let schemaToCompute = null;
821
+ let updatedRecurseList = _recurseList;
822
+ if (isObject(defaults) && isObject(schema.default)) {
823
+ defaults = mergeObjects(defaults, schema.default);
824
+ } else if (DEFAULT_KEY in schema) {
825
+ defaults = schema.default;
826
+ } else if (REF_KEY in schema) {
827
+ const refName = schema[REF_KEY];
828
+ if (!_recurseList.includes(refName)) {
829
+ updatedRecurseList = _recurseList.concat(refName);
830
+ schemaToCompute = findSchemaDefinition(refName, rootSchema);
831
+ }
832
+ } else if (DEPENDENCIES_KEY in schema) {
833
+ const resolvedSchema = resolveDependencies(validator, schema, rootSchema, false, formData);
834
+ schemaToCompute = resolvedSchema[0];
835
+ } else if (isFixedItems(schema)) {
836
+ defaults = schema.items.map(
837
+ (itemSchema, idx) => computeDefaults(validator, itemSchema, {
838
+ rootSchema,
839
+ includeUndefinedValues,
840
+ _recurseList,
841
+ experimental_defaultFormStateBehavior,
842
+ parentDefaults: Array.isArray(parentDefaults) ? parentDefaults[idx] : void 0,
843
+ rawFormData: formData,
844
+ required
845
+ })
846
+ );
847
+ } else if (ONE_OF_KEY in schema) {
848
+ const { oneOf, ...remaining } = schema;
849
+ if (oneOf.length === 0) {
850
+ return void 0;
851
+ }
852
+ const discriminator = getDiscriminatorFieldFromSchema(schema);
853
+ schemaToCompute = oneOf[getClosestMatchingOption(
854
+ validator,
855
+ rootSchema,
856
+ isEmpty(formData) ? void 0 : formData,
857
+ oneOf,
858
+ 0,
859
+ discriminator
860
+ )];
861
+ schemaToCompute = mergeSchemas(remaining, schemaToCompute);
862
+ } else if (ANY_OF_KEY in schema) {
863
+ const { anyOf, ...remaining } = schema;
864
+ if (anyOf.length === 0) {
865
+ return void 0;
866
+ }
867
+ const discriminator = getDiscriminatorFieldFromSchema(schema);
868
+ schemaToCompute = anyOf[getClosestMatchingOption(
869
+ validator,
870
+ rootSchema,
871
+ isEmpty(formData) ? void 0 : formData,
872
+ anyOf,
873
+ 0,
874
+ discriminator
875
+ )];
876
+ schemaToCompute = mergeSchemas(remaining, schemaToCompute);
877
+ }
878
+ if (schemaToCompute) {
879
+ return computeDefaults(validator, schemaToCompute, {
880
+ rootSchema,
881
+ includeUndefinedValues,
882
+ _recurseList: updatedRecurseList,
883
+ experimental_defaultFormStateBehavior,
884
+ parentDefaults: defaults,
885
+ rawFormData: formData,
886
+ required
887
+ });
888
+ }
889
+ if (defaults === void 0) {
890
+ defaults = schema.default;
891
+ }
892
+ switch (getSchemaType(schema)) {
893
+ case "object": {
894
+ const objectDefaults = Object.keys(schema.properties || {}).reduce((acc, key) => {
895
+ const computedDefault = computeDefaults(validator, get7(schema, [PROPERTIES_KEY, key]), {
896
+ rootSchema,
897
+ _recurseList,
898
+ experimental_defaultFormStateBehavior,
899
+ includeUndefinedValues: includeUndefinedValues === true,
900
+ parentDefaults: get7(defaults, [key]),
901
+ rawFormData: get7(formData, [key]),
902
+ required: schema.required?.includes(key)
903
+ });
904
+ maybeAddDefaultToObject(
905
+ acc,
906
+ key,
907
+ computedDefault,
908
+ includeUndefinedValues,
909
+ required,
910
+ schema.required,
911
+ experimental_defaultFormStateBehavior
912
+ );
913
+ return acc;
914
+ }, {});
915
+ if (schema.additionalProperties) {
916
+ const additionalPropertiesSchema = isObject(schema.additionalProperties) ? schema.additionalProperties : {};
917
+ const keys = /* @__PURE__ */ new Set();
918
+ if (isObject(defaults)) {
919
+ Object.keys(defaults).filter((key) => !schema.properties || !schema.properties[key]).forEach((key) => keys.add(key));
920
+ }
921
+ let formDataRequired;
922
+ if (isObject(formData)) {
923
+ formDataRequired = [];
924
+ Object.keys(formData).filter((key) => !schema.properties || !schema.properties[key]).forEach((key) => {
925
+ keys.add(key);
926
+ formDataRequired.push(key);
927
+ });
928
+ }
929
+ keys.forEach((key) => {
930
+ const computedDefault = computeDefaults(validator, additionalPropertiesSchema, {
931
+ rootSchema,
932
+ _recurseList,
933
+ experimental_defaultFormStateBehavior,
934
+ includeUndefinedValues: includeUndefinedValues === true,
935
+ parentDefaults: get7(defaults, [key]),
936
+ rawFormData: get7(formData, [key]),
937
+ required: schema.required?.includes(key)
938
+ });
939
+ maybeAddDefaultToObject(
940
+ objectDefaults,
941
+ key,
942
+ computedDefault,
943
+ includeUndefinedValues,
944
+ required,
945
+ formDataRequired
946
+ );
947
+ });
948
+ }
949
+ return objectDefaults;
950
+ }
951
+ case "array": {
952
+ const neverPopulate = experimental_defaultFormStateBehavior?.arrayMinItems?.populate === "never";
953
+ const ignoreMinItemsFlagSet = experimental_defaultFormStateBehavior?.arrayMinItems?.populate === "requiredOnly";
954
+ if (Array.isArray(defaults)) {
955
+ defaults = defaults.map((item, idx) => {
956
+ const schemaItem = getInnerSchemaForArrayItem(schema, 2 /* Fallback */, idx);
957
+ return computeDefaults(validator, schemaItem, {
958
+ rootSchema,
959
+ _recurseList,
960
+ experimental_defaultFormStateBehavior,
961
+ parentDefaults: item,
962
+ required
963
+ });
964
+ });
965
+ }
966
+ if (Array.isArray(rawFormData)) {
967
+ const schemaItem = getInnerSchemaForArrayItem(schema);
968
+ if (neverPopulate) {
969
+ defaults = rawFormData;
970
+ } else {
971
+ defaults = rawFormData.map((item, idx) => {
972
+ return computeDefaults(validator, schemaItem, {
973
+ rootSchema,
974
+ _recurseList,
975
+ experimental_defaultFormStateBehavior,
976
+ rawFormData: item,
977
+ parentDefaults: get7(defaults, [idx]),
978
+ required
979
+ });
980
+ });
981
+ }
982
+ }
983
+ if (neverPopulate) {
984
+ return defaults ?? [];
985
+ }
986
+ if (ignoreMinItemsFlagSet && !required) {
987
+ return defaults ? defaults : void 0;
988
+ }
989
+ const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
990
+ if (!schema.minItems || isMultiSelect(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
991
+ return defaults ? defaults : [];
992
+ }
993
+ const defaultEntries = defaults || [];
994
+ const fillerSchema = getInnerSchemaForArrayItem(schema, 1 /* Invert */);
995
+ const fillerDefault = fillerSchema.default;
996
+ const fillerEntries = new Array(schema.minItems - defaultsLength).fill(
997
+ computeDefaults(validator, fillerSchema, {
998
+ parentDefaults: fillerDefault,
999
+ rootSchema,
1000
+ _recurseList,
1001
+ experimental_defaultFormStateBehavior,
1002
+ required
1003
+ })
1004
+ );
1005
+ return defaultEntries.concat(fillerEntries);
1006
+ }
1007
+ }
1008
+ return defaults;
1009
+ }
1010
+ function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues = false, experimental_defaultFormStateBehavior) {
1011
+ if (!isObject(theSchema)) {
1012
+ throw new Error("Invalid schema: " + theSchema);
1013
+ }
1014
+ const schema = retrieveSchema(validator, theSchema, rootSchema, formData);
1015
+ const defaults = computeDefaults(validator, schema, {
1016
+ rootSchema,
1017
+ includeUndefinedValues,
1018
+ experimental_defaultFormStateBehavior,
1019
+ rawFormData: formData
1020
+ });
1021
+ if (formData === void 0 || formData === null || typeof formData === "number" && isNaN(formData)) {
1022
+ return defaults;
1023
+ }
1024
+ const { mergeExtraDefaults } = experimental_defaultFormStateBehavior?.arrayMinItems || {};
1025
+ if (isObject(formData)) {
1026
+ return mergeDefaultsWithFormData(defaults, formData, mergeExtraDefaults);
1027
+ }
1028
+ if (Array.isArray(formData)) {
1029
+ return mergeDefaultsWithFormData(defaults, formData, mergeExtraDefaults);
1030
+ }
1031
+ return formData;
1032
+ }
1033
+
1034
+ // src/isCustomWidget.ts
1035
+ function isCustomWidget(uiSchema = {}) {
1036
+ return (
1037
+ // TODO: Remove the `&& uiSchema['ui:widget'] !== 'hidden'` once we support hidden widgets for arrays.
1038
+ // https://rjsf-team.github.io/react-jsonschema-form/docs/usage/widgets/#hidden-widgets
1039
+ "widget" in getUiOptions(uiSchema) && getUiOptions(uiSchema)["widget"] !== "hidden"
1040
+ );
1041
+ }
1042
+
1043
+ // src/schema/isFilesArray.ts
1044
+ function isFilesArray(validator, schema, uiSchema = {}, rootSchema) {
1045
+ if (uiSchema[UI_WIDGET_KEY] === "files") {
1046
+ return true;
1047
+ }
1048
+ if (schema.items) {
1049
+ const itemsSchema = retrieveSchema(validator, schema.items, rootSchema);
1050
+ return itemsSchema.type === "string" && itemsSchema.format === "data-url";
1051
+ }
1052
+ return false;
1053
+ }
1054
+
1055
+ // src/schema/getDisplayLabel.ts
1056
+ function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOptions) {
1057
+ const uiOptions = getUiOptions(uiSchema, globalOptions);
1058
+ const { label = true } = uiOptions;
1059
+ let displayLabel = !!label;
1060
+ const schemaType = getSchemaType(schema);
1061
+ if (schemaType === "array") {
1062
+ displayLabel = isMultiSelect(validator, schema, rootSchema) || isFilesArray(validator, schema, uiSchema, rootSchema) || isCustomWidget(uiSchema);
1063
+ }
1064
+ if (schemaType === "object") {
1065
+ displayLabel = false;
1066
+ }
1067
+ if (schemaType === "boolean" && !uiSchema[UI_WIDGET_KEY]) {
1068
+ displayLabel = false;
1069
+ }
1070
+ if (uiSchema[UI_FIELD_KEY]) {
1071
+ displayLabel = false;
1072
+ }
1073
+ return displayLabel;
1074
+ }
1075
+ function mergeValidationData(validator, validationData, additionalErrorSchema) {
1076
+ if (!additionalErrorSchema) {
1077
+ return validationData;
1078
+ }
1079
+ const { errors: oldErrors, errorSchema: oldErrorSchema } = validationData;
1080
+ let errors = validator.toErrorList(additionalErrorSchema);
1081
+ let errorSchema = additionalErrorSchema;
1082
+ if (!isEmpty(oldErrorSchema)) {
1083
+ errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
1084
+ errors = [...oldErrors].concat(errors);
1085
+ }
1086
+ return { errorSchema, errors };
1087
+ }
1088
+ var NO_VALUE = Symbol("no Value");
1089
+ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}) {
1090
+ let newFormData;
1091
+ if (has3(newSchema, PROPERTIES_KEY)) {
1092
+ const removeOldSchemaData = {};
1093
+ if (has3(oldSchema, PROPERTIES_KEY)) {
1094
+ const properties = get7(oldSchema, PROPERTIES_KEY, {});
1095
+ Object.keys(properties).forEach((key) => {
1096
+ if (has3(data, key)) {
1097
+ removeOldSchemaData[key] = void 0;
1098
+ }
1099
+ });
1100
+ }
1101
+ const keys = Object.keys(get7(newSchema, PROPERTIES_KEY, {}));
1102
+ const nestedData = {};
1103
+ keys.forEach((key) => {
1104
+ const formValue = get7(data, key);
1105
+ let oldKeyedSchema = get7(oldSchema, [PROPERTIES_KEY, key], {});
1106
+ let newKeyedSchema = get7(newSchema, [PROPERTIES_KEY, key], {});
1107
+ if (has3(oldKeyedSchema, REF_KEY)) {
1108
+ oldKeyedSchema = retrieveSchema(validator, oldKeyedSchema, rootSchema, formValue);
1109
+ }
1110
+ if (has3(newKeyedSchema, REF_KEY)) {
1111
+ newKeyedSchema = retrieveSchema(validator, newKeyedSchema, rootSchema, formValue);
1112
+ }
1113
+ const oldSchemaTypeForKey = get7(oldKeyedSchema, "type");
1114
+ const newSchemaTypeForKey = get7(newKeyedSchema, "type");
1115
+ if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
1116
+ if (has3(removeOldSchemaData, key)) {
1117
+ delete removeOldSchemaData[key];
1118
+ }
1119
+ if (newSchemaTypeForKey === "object" || newSchemaTypeForKey === "array" && Array.isArray(formValue)) {
1120
+ const itemData = sanitizeDataForNewSchema(
1121
+ validator,
1122
+ rootSchema,
1123
+ newKeyedSchema,
1124
+ oldKeyedSchema,
1125
+ formValue
1126
+ );
1127
+ if (itemData !== void 0 || newSchemaTypeForKey === "array") {
1128
+ nestedData[key] = itemData;
1129
+ }
1130
+ } else {
1131
+ const newOptionDefault = get7(newKeyedSchema, "default", NO_VALUE);
1132
+ const oldOptionDefault = get7(oldKeyedSchema, "default", NO_VALUE);
1133
+ if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
1134
+ if (oldOptionDefault === formValue) {
1135
+ removeOldSchemaData[key] = newOptionDefault;
1136
+ } else if (get7(newKeyedSchema, "readOnly") === true) {
1137
+ removeOldSchemaData[key] = void 0;
1138
+ }
1139
+ }
1140
+ const newOptionConst = get7(newKeyedSchema, "const", NO_VALUE);
1141
+ const oldOptionConst = get7(oldKeyedSchema, "const", NO_VALUE);
1142
+ if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
1143
+ removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : void 0;
1144
+ }
1145
+ }
1146
+ }
1147
+ });
1148
+ newFormData = {
1149
+ ...data,
1150
+ ...removeOldSchemaData,
1151
+ ...nestedData
1152
+ };
1153
+ } else if (get7(oldSchema, "type") === "array" && get7(newSchema, "type") === "array" && Array.isArray(data)) {
1154
+ let oldSchemaItems = get7(oldSchema, "items");
1155
+ let newSchemaItems = get7(newSchema, "items");
1156
+ if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
1157
+ if (has3(oldSchemaItems, REF_KEY)) {
1158
+ oldSchemaItems = retrieveSchema(validator, oldSchemaItems, rootSchema, data);
1159
+ }
1160
+ if (has3(newSchemaItems, REF_KEY)) {
1161
+ newSchemaItems = retrieveSchema(validator, newSchemaItems, rootSchema, data);
1162
+ }
1163
+ const oldSchemaType = get7(oldSchemaItems, "type");
1164
+ const newSchemaType = get7(newSchemaItems, "type");
1165
+ if (!oldSchemaType || oldSchemaType === newSchemaType) {
1166
+ const maxItems = get7(newSchema, "maxItems", -1);
1167
+ if (newSchemaType === "object") {
1168
+ newFormData = data.reduce((newValue, aValue) => {
1169
+ const itemValue = sanitizeDataForNewSchema(
1170
+ validator,
1171
+ rootSchema,
1172
+ newSchemaItems,
1173
+ oldSchemaItems,
1174
+ aValue
1175
+ );
1176
+ if (itemValue !== void 0 && (maxItems < 0 || newValue.length < maxItems)) {
1177
+ newValue.push(itemValue);
1178
+ }
1179
+ return newValue;
1180
+ }, []);
1181
+ } else {
1182
+ newFormData = maxItems > 0 && data.length > maxItems ? data.slice(0, maxItems) : data;
1183
+ }
1184
+ }
1185
+ } else if (typeof oldSchemaItems === "boolean" && typeof newSchemaItems === "boolean" && oldSchemaItems === newSchemaItems) {
1186
+ newFormData = data;
1187
+ }
1188
+ }
1189
+ return newFormData;
1190
+ }
1191
+ function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = []) {
1192
+ if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
1193
+ const _schema = retrieveSchema(validator, schema, rootSchema, formData);
1194
+ const sameSchemaIndex = _recurseList.findIndex((item) => isEqual3(item, _schema));
1195
+ if (sameSchemaIndex === -1) {
1196
+ return toIdSchemaInternal(
1197
+ validator,
1198
+ _schema,
1199
+ idPrefix,
1200
+ idSeparator,
1201
+ id,
1202
+ rootSchema,
1203
+ formData,
1204
+ _recurseList.concat(_schema)
1205
+ );
1206
+ }
1207
+ }
1208
+ if (ITEMS_KEY in schema && !get7(schema, [ITEMS_KEY, REF_KEY])) {
1209
+ return toIdSchemaInternal(
1210
+ validator,
1211
+ get7(schema, ITEMS_KEY),
1212
+ idPrefix,
1213
+ idSeparator,
1214
+ id,
1215
+ rootSchema,
1216
+ formData,
1217
+ _recurseList
1218
+ );
1219
+ }
1220
+ const $id = id || idPrefix;
1221
+ const idSchema = { $id };
1222
+ if (getSchemaType(schema) === "object" && PROPERTIES_KEY in schema) {
1223
+ for (const name in schema.properties) {
1224
+ const field = get7(schema, [PROPERTIES_KEY, name]);
1225
+ const fieldId = idSchema[ID_KEY] + idSeparator + name;
1226
+ idSchema[name] = toIdSchemaInternal(
1227
+ validator,
1228
+ isObject(field) ? field : {},
1229
+ idPrefix,
1230
+ idSeparator,
1231
+ fieldId,
1232
+ rootSchema,
1233
+ // It's possible that formData is not an object -- this can happen if an
1234
+ // array item has just been added, but not populated with data yet
1235
+ get7(formData, [name]),
1236
+ _recurseList
1237
+ );
1238
+ }
1239
+ }
1240
+ return idSchema;
1241
+ }
1242
+ function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "root", idSeparator = "_") {
1243
+ return toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData);
1244
+ }
1245
+ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = []) {
1246
+ if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
1247
+ const _schema = retrieveSchema(validator, schema, rootSchema, formData);
1248
+ const sameSchemaIndex = _recurseList.findIndex((item) => isEqual3(item, _schema));
1249
+ if (sameSchemaIndex === -1) {
1250
+ return toPathSchemaInternal(
1251
+ validator,
1252
+ _schema,
1253
+ name,
1254
+ rootSchema,
1255
+ formData,
1256
+ _recurseList.concat(_schema)
1257
+ );
1258
+ }
1259
+ }
1260
+ let pathSchema = {
1261
+ [NAME_KEY]: name.replace(/^\./, "")
1262
+ };
1263
+ if (ONE_OF_KEY in schema || ANY_OF_KEY in schema) {
1264
+ const xxxOf = ONE_OF_KEY in schema ? schema.oneOf : schema.anyOf;
1265
+ const discriminator = getDiscriminatorFieldFromSchema(schema);
1266
+ const index = getClosestMatchingOption(validator, rootSchema, formData, xxxOf, 0, discriminator);
1267
+ const _schema = xxxOf[index];
1268
+ pathSchema = {
1269
+ ...pathSchema,
1270
+ ...toPathSchemaInternal(validator, _schema, name, rootSchema, formData, _recurseList)
1271
+ };
1272
+ }
1273
+ if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
1274
+ set3(pathSchema, RJSF_ADDITONAL_PROPERTIES_FLAG, true);
1275
+ }
1276
+ if (ITEMS_KEY in schema && Array.isArray(formData)) {
1277
+ formData.forEach((element, i) => {
1278
+ pathSchema[i] = toPathSchemaInternal(
1279
+ validator,
1280
+ schema.items,
1281
+ `${name}.${i}`,
1282
+ rootSchema,
1283
+ element,
1284
+ _recurseList
1285
+ );
1286
+ });
1287
+ } else if (PROPERTIES_KEY in schema) {
1288
+ for (const property in schema.properties) {
1289
+ const field = get7(schema, [PROPERTIES_KEY, property]);
1290
+ pathSchema[property] = toPathSchemaInternal(
1291
+ validator,
1292
+ field,
1293
+ `${name}.${property}`,
1294
+ rootSchema,
1295
+ // It's possible that formData is not an object -- this can happen if an
1296
+ // array item has just been added, but not populated with data yet
1297
+ get7(formData, [property]),
1298
+ _recurseList
1299
+ );
1300
+ }
1301
+ }
1302
+ return pathSchema;
1303
+ }
1304
+ function toPathSchema(validator, schema, name = "", rootSchema, formData) {
1305
+ return toPathSchemaInternal(validator, schema, name, rootSchema, formData);
1306
+ }
1307
+
1308
+ // src/createSchemaUtils.ts
1309
+ var SchemaUtils = class {
1310
+ /** Constructs the `SchemaUtils` instance with the given `validator` and `rootSchema` stored as instance variables
1311
+ *
1312
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
1313
+ * @param rootSchema - The root schema that will be forwarded to all the APIs
1314
+ * @param experimental_defaultFormStateBehavior - Configuration flags to allow users to override default form state behavior
1315
+ */
1316
+ constructor(validator, rootSchema, experimental_defaultFormStateBehavior) {
1317
+ this.rootSchema = rootSchema;
1318
+ this.validator = validator;
1319
+ this.experimental_defaultFormStateBehavior = experimental_defaultFormStateBehavior;
1320
+ }
1321
+ /** Returns the `ValidatorType` in the `SchemaUtilsType`
1322
+ *
1323
+ * @returns - The `ValidatorType`
1324
+ */
1325
+ getValidator() {
1326
+ return this.validator;
1327
+ }
1328
+ /** Determines whether either the `validator` and `rootSchema` differ from the ones associated with this instance of
1329
+ * the `SchemaUtilsType`. If either `validator` or `rootSchema` are falsy, then return false to prevent the creation
1330
+ * of a new `SchemaUtilsType` with incomplete properties.
1331
+ *
1332
+ * @param validator - An implementation of the `ValidatorType` interface that will be compared against the current one
1333
+ * @param rootSchema - The root schema that will be compared against the current one
1334
+ * @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
1335
+ * @returns - True if the `SchemaUtilsType` differs from the given `validator` or `rootSchema`
1336
+ */
1337
+ doesSchemaUtilsDiffer(validator, rootSchema, experimental_defaultFormStateBehavior = {}) {
1338
+ if (!validator || !rootSchema) {
1339
+ return false;
1340
+ }
1341
+ return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema) || !deepEquals(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior);
1342
+ }
1343
+ /** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
1344
+ * computed to have defaults provided in the `schema`.
1345
+ *
1346
+ * @param schema - The schema for which the default state is desired
1347
+ * @param [formData] - The current formData, if any, onto which to provide any missing defaults
1348
+ * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
1349
+ * If "excludeObjectChildren", pass `includeUndefinedValues` as false when computing defaults for any nested
1350
+ * object properties.
1351
+ * @returns - The resulting `formData` with all the defaults provided
1352
+ */
1353
+ getDefaultFormState(schema, formData, includeUndefinedValues = false) {
1354
+ return getDefaultFormState(
1355
+ this.validator,
1356
+ schema,
1357
+ formData,
1358
+ this.rootSchema,
1359
+ includeUndefinedValues,
1360
+ this.experimental_defaultFormStateBehavior
1361
+ );
1362
+ }
1363
+ /** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
1364
+ * should be displayed in a UI.
1365
+ *
1366
+ * @param schema - The schema for which the display label flag is desired
1367
+ * @param [uiSchema] - The UI schema from which to derive potentially displayable information
1368
+ * @param [globalOptions={}] - The optional Global UI Schema from which to get any fallback `xxx` options
1369
+ * @returns - True if the label should be displayed or false if it should not
1370
+ */
1371
+ getDisplayLabel(schema, uiSchema, globalOptions) {
1372
+ return getDisplayLabel(this.validator, schema, uiSchema, this.rootSchema, globalOptions);
1373
+ }
1374
+ /** Determines which of the given `options` provided most closely matches the `formData`.
1375
+ * Returns the index of the option that is valid and is the closest match, or 0 if there is no match.
1376
+ *
1377
+ * The closest match is determined using the number of matching properties, and more heavily favors options with
1378
+ * matching readOnly, default, or const values.
1379
+ *
1380
+ * @param formData - The form data associated with the schema
1381
+ * @param options - The list of options that can be selected from
1382
+ * @param [selectedOption] - The index of the currently selected option, defaulted to -1 if not specified
1383
+ * @param [discriminatorField] - The optional name of the field within the options object whose value is used to
1384
+ * determine which option is selected
1385
+ * @returns - The index of the option that is the closest match to the `formData` or the `selectedOption` if no match
1386
+ */
1387
+ getClosestMatchingOption(formData, options, selectedOption, discriminatorField) {
1388
+ return getClosestMatchingOption(
1389
+ this.validator,
1390
+ this.rootSchema,
1391
+ formData,
1392
+ options,
1393
+ selectedOption,
1394
+ discriminatorField
1395
+ );
1396
+ }
1397
+ /** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
1398
+ * Always returns the first option if there is nothing that matches.
1399
+ *
1400
+ * @param formData - The current formData, if any, used to figure out a match
1401
+ * @param options - The list of options to find a matching options from
1402
+ * @param [discriminatorField] - The optional name of the field within the options object whose value is used to
1403
+ * determine which option is selected
1404
+ * @returns - The firstindex of the matched option or 0 if none is available
1405
+ */
1406
+ getFirstMatchingOption(formData, options, discriminatorField) {
1407
+ return getFirstMatchingOption(this.validator, formData, options, this.rootSchema, discriminatorField);
1408
+ }
1409
+ /** Given the `formData` and list of `options`, attempts to find the index of the option that best matches the data.
1410
+ * Deprecated, use `getFirstMatchingOption()` instead.
1411
+ *
1412
+ * @param formData - The current formData, if any, onto which to provide any missing defaults
1413
+ * @param options - The list of options to find a matching options from
1414
+ * @param [discriminatorField] - The optional name of the field within the options object whose value is used to
1415
+ * determine which option is selected
1416
+ * @returns - The index of the matched option or 0 if none is available
1417
+ * @deprecated
1418
+ */
1419
+ getMatchingOption(formData, options, discriminatorField) {
1420
+ return getMatchingOption(this.validator, formData, options, this.rootSchema, discriminatorField);
1421
+ }
1422
+ /** Checks to see if the `schema` and `uiSchema` combination represents an array of files
1423
+ *
1424
+ * @param schema - The schema for which check for array of files flag is desired
1425
+ * @param [uiSchema] - The UI schema from which to check the widget
1426
+ * @returns - True if schema/uiSchema contains an array of files, otherwise false
1427
+ */
1428
+ isFilesArray(schema, uiSchema) {
1429
+ return isFilesArray(this.validator, schema, uiSchema, this.rootSchema);
1430
+ }
1431
+ /** Checks to see if the `schema` combination represents a multi-select
1432
+ *
1433
+ * @param schema - The schema for which check for a multi-select flag is desired
1434
+ * @returns - True if schema contains a multi-select, otherwise false
1435
+ */
1436
+ isMultiSelect(schema) {
1437
+ return isMultiSelect(this.validator, schema, this.rootSchema);
1438
+ }
1439
+ /** Checks to see if the `schema` combination represents a select
1440
+ *
1441
+ * @param schema - The schema for which check for a select flag is desired
1442
+ * @returns - True if schema contains a select, otherwise false
1443
+ */
1444
+ isSelect(schema) {
1445
+ return isSelect(this.validator, schema, this.rootSchema);
1446
+ }
1447
+ /** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in
1448
+ * the two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
1449
+ * `getValidator().toErrorList()` onto the `errors` in the `validationData`. If no `additionalErrorSchema` is passed,
1450
+ * then `validationData` is returned.
1451
+ *
1452
+ * @param validationData - The current `ValidationData` into which to merge the additional errors
1453
+ * @param [additionalErrorSchema] - The additional set of errors
1454
+ * @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
1455
+ * @deprecated - Use the `validationDataMerge()` function exported from `@rjsf/utils` instead. This function will be
1456
+ * removed in the next major release.
1457
+ */
1458
+ mergeValidationData(validationData, additionalErrorSchema) {
1459
+ return mergeValidationData(this.validator, validationData, additionalErrorSchema);
1460
+ }
1461
+ /** Retrieves an expanded schema that has had all of its conditions, additional properties, references and
1462
+ * dependencies resolved and merged into the `schema` given a `rawFormData` that is used to do the potentially
1463
+ * recursive resolution.
1464
+ *
1465
+ * @param schema - The schema for which retrieving a schema is desired
1466
+ * @param [rawFormData] - The current formData, if any, to assist retrieving a schema
1467
+ * @returns - The schema having its conditions, additional properties, references and dependencies resolved
1468
+ */
1469
+ retrieveSchema(schema, rawFormData) {
1470
+ return retrieveSchema(this.validator, schema, this.rootSchema, rawFormData);
1471
+ }
1472
+ /** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the
1473
+ * new schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the
1474
+ * nature of schemas, this sanitization happens recursively for nested objects of data. Also, any properties in the
1475
+ * old schemas that are non-existent in the new schema are set to `undefined`.
1476
+ *
1477
+ * @param [newSchema] - The new schema for which the data is being sanitized
1478
+ * @param [oldSchema] - The old schema from which the data originated
1479
+ * @param [data={}] - The form data associated with the schema, defaulting to an empty object when undefined
1480
+ * @returns - The new form data, with all the fields uniquely associated with the old schema set
1481
+ * to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
1482
+ */
1483
+ sanitizeDataForNewSchema(newSchema, oldSchema, data) {
1484
+ return sanitizeDataForNewSchema(this.validator, this.rootSchema, newSchema, oldSchema, data);
1485
+ }
1486
+ /** Generates an `IdSchema` object for the `schema`, recursively
1487
+ *
1488
+ * @param schema - The schema for which the display label flag is desired
1489
+ * @param [id] - The base id for the schema
1490
+ * @param [formData] - The current formData, if any, onto which to provide any missing defaults
1491
+ * @param [idPrefix='root'] - The prefix to use for the id
1492
+ * @param [idSeparator='_'] - The separator to use for the path segments in the id
1493
+ * @returns - The `IdSchema` object for the `schema`
1494
+ */
1495
+ toIdSchema(schema, id, formData, idPrefix = "root", idSeparator = "_") {
1496
+ return toIdSchema(this.validator, schema, id, this.rootSchema, formData, idPrefix, idSeparator);
1497
+ }
1498
+ /** Generates an `PathSchema` object for the `schema`, recursively
1499
+ *
1500
+ * @param schema - The schema for which the display label flag is desired
1501
+ * @param [name] - The base name for the schema
1502
+ * @param [formData] - The current formData, if any, onto which to provide any missing defaults
1503
+ * @returns - The `PathSchema` object for the `schema`
1504
+ */
1505
+ toPathSchema(schema, name, formData) {
1506
+ return toPathSchema(this.validator, schema, name, this.rootSchema, formData);
1507
+ }
1508
+ };
1509
+ function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior = {}) {
1510
+ return new SchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior);
1511
+ }
1512
+
1513
+ // src/dataURItoBlob.ts
1514
+ function dataURItoBlob(dataURI) {
1515
+ const splitted = dataURI.split(",");
1516
+ const params = splitted[0].split(";");
1517
+ const type = params[0].replace("data:", "");
1518
+ const properties = params.filter((param) => {
1519
+ return param.split("=")[0] === "name";
1520
+ });
1521
+ let name;
1522
+ if (properties.length !== 1) {
1523
+ name = "unknown";
1524
+ } else {
1525
+ name = decodeURI(properties[0].split("=")[1]);
1526
+ }
1527
+ try {
1528
+ const binary = atob(splitted[1]);
1529
+ const array = [];
1530
+ for (let i = 0; i < binary.length; i++) {
1531
+ array.push(binary.charCodeAt(i));
1532
+ }
1533
+ const blob = new window.Blob([new Uint8Array(array)], { type });
1534
+ return { blob, name };
1535
+ } catch (error) {
1536
+ return { blob: { size: 0, type: error.message }, name: dataURI };
1537
+ }
1538
+ }
1539
+
1540
+ // src/replaceStringParameters.ts
1541
+ function replaceStringParameters(inputString, params) {
1542
+ let output = inputString;
1543
+ if (Array.isArray(params)) {
1544
+ const parts = output.split(/(%\d)/);
1545
+ params.forEach((param, index) => {
1546
+ const partIndex = parts.findIndex((part) => part === `%${index + 1}`);
1547
+ if (partIndex >= 0) {
1548
+ parts[partIndex] = param;
1549
+ }
1550
+ });
1551
+ output = parts.join("");
1552
+ }
1553
+ return output;
1554
+ }
1555
+
1556
+ // src/englishStringTranslator.ts
1557
+ function englishStringTranslator(stringToTranslate, params) {
1558
+ return replaceStringParameters(stringToTranslate, params);
1559
+ }
1560
+
1561
+ // src/enumOptionsValueForIndex.ts
1562
+ function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
1563
+ if (Array.isArray(valueIndex)) {
1564
+ return valueIndex.map((index2) => enumOptionsValueForIndex(index2, allEnumOptions)).filter((val) => val);
1565
+ }
1566
+ const index = valueIndex === "" || valueIndex === null ? -1 : Number(valueIndex);
1567
+ const option = allEnumOptions[index];
1568
+ return option ? option.value : emptyValue;
1569
+ }
1570
+
1571
+ // src/enumOptionsDeselectValue.ts
1572
+ function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions = []) {
1573
+ const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
1574
+ if (Array.isArray(selected)) {
1575
+ return selected.filter((v) => !isEqual3(v, value));
1576
+ }
1577
+ return isEqual3(value, selected) ? void 0 : selected;
1578
+ }
1579
+ function enumOptionsIsSelected(value, selected) {
1580
+ if (Array.isArray(selected)) {
1581
+ return selected.some((sel) => isEqual3(sel, value));
1582
+ }
1583
+ return isEqual3(selected, value);
1584
+ }
1585
+
1586
+ // src/enumOptionsIndexForValue.ts
1587
+ function enumOptionsIndexForValue(value, allEnumOptions = [], multiple = false) {
1588
+ const selectedIndexes = allEnumOptions.map((opt, index) => enumOptionsIsSelected(opt.value, value) ? String(index) : void 0).filter((opt) => typeof opt !== "undefined");
1589
+ if (!multiple) {
1590
+ return selectedIndexes[0];
1591
+ }
1592
+ return selectedIndexes;
1593
+ }
1594
+ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
1595
+ const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
1596
+ if (!lodash.isNil(value)) {
1597
+ const index = allEnumOptions.findIndex((opt) => value === opt.value);
1598
+ const all = allEnumOptions.map(({ value: val }) => val);
1599
+ const updated = selected.slice(0, index).concat(value, selected.slice(index));
1600
+ return updated.sort((a, b) => Number(all.indexOf(a) > all.indexOf(b)));
1601
+ }
1602
+ return selected;
1603
+ }
1604
+ var ErrorSchemaBuilder = class {
1605
+ /** Construct an `ErrorSchemaBuilder` with an optional initial set of errors in an `ErrorSchema`.
1606
+ *
1607
+ * @param [initialSchema] - The optional set of initial errors, that will be cloned into the class
1608
+ */
1609
+ constructor(initialSchema) {
1610
+ /** The error schema being built
1611
+ *
1612
+ * @private
1613
+ */
1614
+ this.errorSchema = {};
1615
+ this.resetAllErrors(initialSchema);
1616
+ }
1617
+ /** Returns the `ErrorSchema` that has been updated by the methods of the `ErrorSchemaBuilder`
1618
+ */
1619
+ get ErrorSchema() {
1620
+ return this.errorSchema;
1621
+ }
1622
+ /** Will get an existing `ErrorSchema` at the specified `pathOfError` or create and return one.
1623
+ *
1624
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to add the error(s)
1625
+ * @returns - The error block for the given `pathOfError` or the root if not provided
1626
+ * @private
1627
+ */
1628
+ getOrCreateErrorBlock(pathOfError) {
1629
+ const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
1630
+ let errorBlock = hasPath ? get7(this.errorSchema, pathOfError) : this.errorSchema;
1631
+ if (!errorBlock && pathOfError) {
1632
+ errorBlock = {};
1633
+ set3(this.errorSchema, pathOfError, errorBlock);
1634
+ }
1635
+ return errorBlock;
1636
+ }
1637
+ /** Resets all errors in the `ErrorSchemaBuilder` back to the `initialSchema` if provided, otherwise an empty set.
1638
+ *
1639
+ * @param [initialSchema] - The optional set of initial errors, that will be cloned into the class
1640
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
1641
+ */
1642
+ resetAllErrors(initialSchema) {
1643
+ this.errorSchema = initialSchema ? cloneDeep(initialSchema) : {};
1644
+ return this;
1645
+ }
1646
+ /** Adds the `errorOrList` to the list of errors in the `ErrorSchema` at either the root level or the location within
1647
+ * the schema described by the `pathOfError`. For more information about how to specify the path see the
1648
+ * [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
1649
+ *
1650
+ * @param errorOrList - The error or list of errors to add into the `ErrorSchema`
1651
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to add the error(s)
1652
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
1653
+ */
1654
+ addErrors(errorOrList, pathOfError) {
1655
+ const errorBlock = this.getOrCreateErrorBlock(pathOfError);
1656
+ let errorsList = get7(errorBlock, ERRORS_KEY);
1657
+ if (!Array.isArray(errorsList)) {
1658
+ errorsList = [];
1659
+ errorBlock[ERRORS_KEY] = errorsList;
1660
+ }
1661
+ if (Array.isArray(errorOrList)) {
1662
+ errorsList.push(...errorOrList);
1663
+ } else {
1664
+ errorsList.push(errorOrList);
1665
+ }
1666
+ return this;
1667
+ }
1668
+ /** Sets/replaces the `errorOrList` as the error(s) in the `ErrorSchema` at either the root level or the location
1669
+ * within the schema described by the `pathOfError`. For more information about how to specify the path see the
1670
+ * [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
1671
+ *
1672
+ * @param errorOrList - The error or list of errors to set into the `ErrorSchema`
1673
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to set the error(s)
1674
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
1675
+ */
1676
+ setErrors(errorOrList, pathOfError) {
1677
+ const errorBlock = this.getOrCreateErrorBlock(pathOfError);
1678
+ const listToAdd = Array.isArray(errorOrList) ? [...errorOrList] : [errorOrList];
1679
+ set3(errorBlock, ERRORS_KEY, listToAdd);
1680
+ return this;
1681
+ }
1682
+ /** Clears the error(s) in the `ErrorSchema` at either the root level or the location within the schema described by
1683
+ * the `pathOfError`. For more information about how to specify the path see the
1684
+ * [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
1685
+ *
1686
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to clear the error(s)
1687
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
1688
+ */
1689
+ clearErrors(pathOfError) {
1690
+ const errorBlock = this.getOrCreateErrorBlock(pathOfError);
1691
+ set3(errorBlock, ERRORS_KEY, []);
1692
+ return this;
1693
+ }
1694
+ };
1695
+
1696
+ // src/rangeSpec.ts
1697
+ function rangeSpec(schema) {
1698
+ const spec = {};
1699
+ if (schema.multipleOf) {
1700
+ spec.step = schema.multipleOf;
1701
+ }
1702
+ if (schema.minimum || schema.minimum === 0) {
1703
+ spec.min = schema.minimum;
1704
+ }
1705
+ if (schema.maximum || schema.maximum === 0) {
1706
+ spec.max = schema.maximum;
1707
+ }
1708
+ return spec;
1709
+ }
1710
+
1711
+ // src/getInputProps.ts
1712
+ function getInputProps(schema, defaultType, options = {}, autoDefaultStepAny = true) {
1713
+ const inputProps = {
1714
+ type: defaultType || "text",
1715
+ ...rangeSpec(schema)
1716
+ };
1717
+ if (options.inputType) {
1718
+ inputProps.type = options.inputType;
1719
+ } else if (!defaultType) {
1720
+ if (schema.type === "number") {
1721
+ inputProps.type = "number";
1722
+ if (autoDefaultStepAny && inputProps.step === void 0) {
1723
+ inputProps.step = "any";
1724
+ }
1725
+ } else if (schema.type === "integer") {
1726
+ inputProps.type = "number";
1727
+ if (inputProps.step === void 0) {
1728
+ inputProps.step = 1;
1729
+ }
1730
+ }
1731
+ }
1732
+ if (options.autocomplete) {
1733
+ inputProps.autoComplete = options.autocomplete;
1734
+ }
1735
+ return inputProps;
1736
+ }
1737
+
1738
+ // src/getSubmitButtonOptions.ts
1739
+ var DEFAULT_OPTIONS = {
1740
+ props: {
1741
+ disabled: false
1742
+ },
1743
+ submitText: "Submit",
1744
+ norender: false
1745
+ };
1746
+ function getSubmitButtonOptions(uiSchema = {}) {
1747
+ const uiOptions = getUiOptions(uiSchema);
1748
+ if (uiOptions && uiOptions[SUBMIT_BTN_OPTIONS_KEY]) {
1749
+ const options = uiOptions[SUBMIT_BTN_OPTIONS_KEY];
1750
+ return { ...DEFAULT_OPTIONS, ...options };
1751
+ }
1752
+ return DEFAULT_OPTIONS;
1753
+ }
1754
+
1755
+ // src/getTemplate.ts
1756
+ function getTemplate(name, registry, uiOptions = {}) {
1757
+ const { templates } = registry;
1758
+ if (name === "ButtonTemplates") {
1759
+ return templates[name];
1760
+ }
1761
+ return (
1762
+ // Evaluating uiOptions[name] results in TS2590: Expression produces a union type that is too complex to represent
1763
+ // To avoid that, we cast uiOptions to `any` before accessing the name field
1764
+ uiOptions[name] || templates[name]
1765
+ );
1766
+ }
1767
+ var widgetMap = {
1768
+ boolean: {
1769
+ checkbox: "CheckboxWidget",
1770
+ radio: "RadioWidget",
1771
+ select: "SelectWidget",
1772
+ hidden: "HiddenWidget"
1773
+ },
1774
+ string: {
1775
+ text: "TextWidget",
1776
+ password: "PasswordWidget",
1777
+ email: "EmailWidget",
1778
+ hostname: "TextWidget",
1779
+ ipv4: "TextWidget",
1780
+ ipv6: "TextWidget",
1781
+ uri: "URLWidget",
1782
+ "data-url": "FileWidget",
1783
+ radio: "RadioWidget",
1784
+ select: "SelectWidget",
1785
+ textarea: "TextareaWidget",
1786
+ hidden: "HiddenWidget",
1787
+ date: "DateWidget",
1788
+ datetime: "DateTimeWidget",
1789
+ "date-time": "DateTimeWidget",
1790
+ "alt-date": "AltDateWidget",
1791
+ "alt-datetime": "AltDateTimeWidget",
1792
+ time: "TimeWidget",
1793
+ color: "ColorWidget",
1794
+ file: "FileWidget"
1795
+ },
1796
+ number: {
1797
+ text: "TextWidget",
1798
+ select: "SelectWidget",
1799
+ updown: "UpDownWidget",
1800
+ range: "RangeWidget",
1801
+ radio: "RadioWidget",
1802
+ hidden: "HiddenWidget"
1803
+ },
1804
+ integer: {
1805
+ text: "TextWidget",
1806
+ select: "SelectWidget",
1807
+ updown: "UpDownWidget",
1808
+ range: "RangeWidget",
1809
+ radio: "RadioWidget",
1810
+ hidden: "HiddenWidget"
1811
+ },
1812
+ array: {
1813
+ select: "SelectWidget",
1814
+ checkboxes: "CheckboxesWidget",
1815
+ files: "FileWidget",
1816
+ hidden: "HiddenWidget"
1817
+ }
1818
+ };
1819
+ function mergeWidgetOptions(AWidget) {
1820
+ let MergedWidget = get7(AWidget, "MergedWidget");
1821
+ if (!MergedWidget) {
1822
+ const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
1823
+ MergedWidget = ({ options, ...props }) => {
1824
+ return /* @__PURE__ */ jsxRuntime.jsx(AWidget, { options: { ...defaultOptions, ...options }, ...props });
1825
+ };
1826
+ set3(AWidget, "MergedWidget", MergedWidget);
1827
+ }
1828
+ return MergedWidget;
1829
+ }
1830
+ function getWidget(schema, widget, registeredWidgets = {}) {
1831
+ const type = getSchemaType(schema);
1832
+ if (typeof widget === "function" || widget && ReactIs.isForwardRef(react.createElement(widget)) || ReactIs.isMemo(widget)) {
1833
+ return mergeWidgetOptions(widget);
1834
+ }
1835
+ if (typeof widget !== "string") {
1836
+ throw new Error(`Unsupported widget definition: ${typeof widget}`);
1837
+ }
1838
+ if (widget in registeredWidgets) {
1839
+ const registeredWidget = registeredWidgets[widget];
1840
+ return getWidget(schema, registeredWidget, registeredWidgets);
1841
+ }
1842
+ if (typeof type === "string") {
1843
+ if (!(type in widgetMap)) {
1844
+ throw new Error(`No widget for type '${type}'`);
1845
+ }
1846
+ if (widget in widgetMap[type]) {
1847
+ const registeredWidget = registeredWidgets[widgetMap[type][widget]];
1848
+ return getWidget(schema, registeredWidget, registeredWidgets);
1849
+ }
1850
+ }
1851
+ throw new Error(`No widget '${widget}' for type '${type}'`);
1852
+ }
1853
+
1854
+ // src/hashForSchema.ts
1855
+ function hashString(string) {
1856
+ let hash = 0;
1857
+ for (let i = 0; i < string.length; i += 1) {
1858
+ const chr = string.charCodeAt(i);
1859
+ hash = (hash << 5) - hash + chr;
1860
+ hash = hash & hash;
1861
+ }
1862
+ return hash.toString(16);
1863
+ }
1864
+ function hashForSchema(schema) {
1865
+ const allKeys = /* @__PURE__ */ new Set();
1866
+ JSON.stringify(schema, (key, value) => (allKeys.add(key), value));
1867
+ return hashString(JSON.stringify(schema, Array.from(allKeys).sort()));
1868
+ }
1869
+
1870
+ // src/hasWidget.ts
1871
+ function hasWidget(schema, widget, registeredWidgets = {}) {
1872
+ try {
1873
+ getWidget(schema, widget, registeredWidgets);
1874
+ return true;
1875
+ } catch (e) {
1876
+ const err = e;
1877
+ if (err.message && (err.message.startsWith("No widget") || err.message.startsWith("Unsupported widget"))) {
1878
+ return false;
1879
+ }
1880
+ throw e;
1881
+ }
1882
+ }
1883
+ function idGenerator(id, suffix) {
1884
+ const theId = isString(id) ? id : id[ID_KEY];
1885
+ return `${theId}__${suffix}`;
1886
+ }
1887
+ function descriptionId(id) {
1888
+ return idGenerator(id, "description");
1889
+ }
1890
+ function errorId(id) {
1891
+ return idGenerator(id, "error");
1892
+ }
1893
+ function examplesId(id) {
1894
+ return idGenerator(id, "examples");
1895
+ }
1896
+ function helpId(id) {
1897
+ return idGenerator(id, "help");
1898
+ }
1899
+ function titleId(id) {
1900
+ return idGenerator(id, "title");
1901
+ }
1902
+ function ariaDescribedByIds(id, includeExamples = false) {
1903
+ const examples = includeExamples ? ` ${examplesId(id)}` : "";
1904
+ return `${errorId(id)} ${descriptionId(id)} ${helpId(id)}${examples}`;
1905
+ }
1906
+ function optionId(id, optionIndex) {
1907
+ return `${id}-${optionIndex}`;
1908
+ }
1909
+
1910
+ // src/labelValue.ts
1911
+ function labelValue(label, hideLabel, fallback) {
1912
+ return hideLabel ? fallback : label;
1913
+ }
1914
+
1915
+ // src/localToUTC.ts
1916
+ function localToUTC(dateString) {
1917
+ return dateString ? new Date(dateString).toJSON() : void 0;
1918
+ }
1919
+
1920
+ // src/toConstant.ts
1921
+ function toConstant(schema) {
1922
+ if (ENUM_KEY in schema && Array.isArray(schema.enum) && schema.enum.length === 1) {
1923
+ return schema.enum[0];
1924
+ }
1925
+ if (CONST_KEY in schema) {
1926
+ return schema.const;
1927
+ }
1928
+ throw new Error("schema cannot be inferred as a constant");
1929
+ }
1930
+
1931
+ // src/optionsList.ts
1932
+ function optionsList(schema) {
1933
+ const schemaWithEnumNames = schema;
1934
+ if (schemaWithEnumNames.enumNames && true) {
1935
+ console.warn("The enumNames property is deprecated and may be removed in a future major release.");
1936
+ }
1937
+ if (schema.enum) {
1938
+ return schema.enum.map((value, i) => {
1939
+ const label = schemaWithEnumNames.enumNames && schemaWithEnumNames.enumNames[i] || String(value);
1940
+ return { label, value };
1941
+ });
1942
+ }
1943
+ const altSchemas = schema.oneOf || schema.anyOf;
1944
+ return altSchemas && altSchemas.map((aSchemaDef) => {
1945
+ const aSchema = aSchemaDef;
1946
+ const value = toConstant(aSchema);
1947
+ const label = aSchema.title || String(value);
1948
+ return {
1949
+ schema: aSchema,
1950
+ label,
1951
+ value
1952
+ };
1953
+ });
1954
+ }
1955
+
1956
+ // src/orderProperties.ts
1957
+ function orderProperties(properties, order) {
1958
+ if (!Array.isArray(order)) {
1959
+ return properties;
1960
+ }
1961
+ const arrayToHash = (arr) => arr.reduce((prev, curr) => {
1962
+ prev[curr] = true;
1963
+ return prev;
1964
+ }, {});
1965
+ const errorPropList = (arr) => arr.length > 1 ? `properties '${arr.join("', '")}'` : `property '${arr[0]}'`;
1966
+ const propertyHash = arrayToHash(properties);
1967
+ const orderFiltered = order.filter((prop) => prop === "*" || propertyHash[prop]);
1968
+ const orderHash = arrayToHash(orderFiltered);
1969
+ const rest = properties.filter((prop) => !orderHash[prop]);
1970
+ const restIndex = orderFiltered.indexOf("*");
1971
+ if (restIndex === -1) {
1972
+ if (rest.length) {
1973
+ throw new Error(`uiSchema order list does not contain ${errorPropList(rest)}`);
1974
+ }
1975
+ return orderFiltered;
1976
+ }
1977
+ if (restIndex !== orderFiltered.lastIndexOf("*")) {
1978
+ throw new Error("uiSchema order list contains more than one wildcard item");
1979
+ }
1980
+ const complete = [...orderFiltered];
1981
+ complete.splice(restIndex, 1, ...rest);
1982
+ return complete;
1983
+ }
1984
+
1985
+ // src/pad.ts
1986
+ function pad(num, width) {
1987
+ let s = String(num);
1988
+ while (s.length < width) {
1989
+ s = "0" + s;
1990
+ }
1991
+ return s;
1992
+ }
1993
+
1994
+ // src/parseDateString.ts
1995
+ function parseDateString(dateString, includeTime = true) {
1996
+ if (!dateString) {
1997
+ return {
1998
+ year: -1,
1999
+ month: -1,
2000
+ day: -1,
2001
+ hour: includeTime ? -1 : 0,
2002
+ minute: includeTime ? -1 : 0,
2003
+ second: includeTime ? -1 : 0
2004
+ };
2005
+ }
2006
+ const date = new Date(dateString);
2007
+ if (Number.isNaN(date.getTime())) {
2008
+ throw new Error("Unable to parse date " + dateString);
2009
+ }
2010
+ return {
2011
+ year: date.getUTCFullYear(),
2012
+ month: date.getUTCMonth() + 1,
2013
+ // oh you, javascript.
2014
+ day: date.getUTCDate(),
2015
+ hour: includeTime ? date.getUTCHours() : 0,
2016
+ minute: includeTime ? date.getUTCMinutes() : 0,
2017
+ second: includeTime ? date.getUTCSeconds() : 0
2018
+ };
2019
+ }
2020
+
2021
+ // src/schemaRequiresTrueValue.ts
2022
+ function schemaRequiresTrueValue(schema) {
2023
+ if (schema.const) {
2024
+ return true;
2025
+ }
2026
+ if (schema.enum && schema.enum.length === 1 && schema.enum[0] === true) {
2027
+ return true;
2028
+ }
2029
+ if (schema.anyOf && schema.anyOf.length === 1) {
2030
+ return schemaRequiresTrueValue(schema.anyOf[0]);
2031
+ }
2032
+ if (schema.oneOf && schema.oneOf.length === 1) {
2033
+ return schemaRequiresTrueValue(schema.oneOf[0]);
2034
+ }
2035
+ if (schema.allOf) {
2036
+ const schemaSome = (subSchema) => schemaRequiresTrueValue(subSchema);
2037
+ return schema.allOf.some(schemaSome);
2038
+ }
2039
+ return false;
2040
+ }
2041
+
2042
+ // src/shouldRender.ts
2043
+ function shouldRender(component, nextProps, nextState) {
2044
+ const { props, state } = component;
2045
+ return !deepEquals(props, nextProps) || !deepEquals(state, nextState);
2046
+ }
2047
+
2048
+ // src/toDateString.ts
2049
+ function toDateString(dateObject, time = true) {
2050
+ const { year, month, day, hour = 0, minute = 0, second = 0 } = dateObject;
2051
+ const utcTime = Date.UTC(year, month - 1, day, hour, minute, second);
2052
+ const datetime = new Date(utcTime).toJSON();
2053
+ return time ? datetime : datetime.slice(0, 10);
2054
+ }
2055
+ function toErrorList(errorSchema, fieldPath = []) {
2056
+ if (!errorSchema) {
2057
+ return [];
2058
+ }
2059
+ let errorList = [];
2060
+ if (ERRORS_KEY in errorSchema) {
2061
+ errorList = errorList.concat(
2062
+ errorSchema[ERRORS_KEY].map((message) => {
2063
+ const property = `.${fieldPath.join(".")}`;
2064
+ return {
2065
+ property,
2066
+ message,
2067
+ stack: `${property} ${message}`
2068
+ };
2069
+ })
2070
+ );
2071
+ }
2072
+ return Object.keys(errorSchema).reduce((acc, key) => {
2073
+ if (key !== ERRORS_KEY) {
2074
+ const childSchema = errorSchema[key];
2075
+ if (isPlainObject(childSchema)) {
2076
+ acc = acc.concat(toErrorList(childSchema, [...fieldPath, key]));
2077
+ }
2078
+ }
2079
+ return acc;
2080
+ }, errorList);
2081
+ }
2082
+ function toErrorSchema(errors) {
2083
+ const builder = new ErrorSchemaBuilder();
2084
+ if (errors.length) {
2085
+ errors.forEach((error) => {
2086
+ const { property, message } = error;
2087
+ const path = property === "." ? [] : toPath(property);
2088
+ if (path.length > 0 && path[0] === "") {
2089
+ path.splice(0, 1);
2090
+ }
2091
+ if (message) {
2092
+ builder.addErrors(message, path);
2093
+ }
2094
+ });
2095
+ }
2096
+ return builder.ErrorSchema;
2097
+ }
2098
+ function unwrapErrorHandler(errorHandler) {
2099
+ return Object.keys(errorHandler).reduce((acc, key) => {
2100
+ if (key === "addError") {
2101
+ return acc;
2102
+ } else {
2103
+ const childSchema = errorHandler[key];
2104
+ if (isPlainObject(childSchema)) {
2105
+ return {
2106
+ ...acc,
2107
+ [key]: unwrapErrorHandler(childSchema)
2108
+ };
2109
+ }
2110
+ return { ...acc, [key]: childSchema };
2111
+ }
2112
+ }, {});
2113
+ }
2114
+
2115
+ // src/utcToLocal.ts
2116
+ function utcToLocal(jsonDate) {
2117
+ if (!jsonDate) {
2118
+ return "";
2119
+ }
2120
+ const date = new Date(jsonDate);
2121
+ const yyyy = pad(date.getFullYear(), 4);
2122
+ const MM = pad(date.getMonth() + 1, 2);
2123
+ const dd = pad(date.getDate(), 2);
2124
+ const hh = pad(date.getHours(), 2);
2125
+ const mm = pad(date.getMinutes(), 2);
2126
+ const ss = pad(date.getSeconds(), 2);
2127
+ const SSS = pad(date.getMilliseconds(), 3);
2128
+ return `${yyyy}-${MM}-${dd}T${hh}:${mm}:${ss}.${SSS}`;
2129
+ }
2130
+ function validationDataMerge(validationData, additionalErrorSchema) {
2131
+ if (!additionalErrorSchema) {
2132
+ return validationData;
2133
+ }
2134
+ const { errors: oldErrors, errorSchema: oldErrorSchema } = validationData;
2135
+ let errors = toErrorList(additionalErrorSchema);
2136
+ let errorSchema = additionalErrorSchema;
2137
+ if (!isEmpty(oldErrorSchema)) {
2138
+ errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
2139
+ errors = [...oldErrors].concat(errors);
2140
+ }
2141
+ return { errorSchema, errors };
2142
+ }
2143
+ function withIdRefPrefixObject(node) {
2144
+ for (const key in node) {
2145
+ const realObj = node;
2146
+ const value = realObj[key];
2147
+ if (key === REF_KEY && typeof value === "string" && value.startsWith("#")) {
2148
+ realObj[key] = ROOT_SCHEMA_PREFIX + value;
2149
+ } else {
2150
+ realObj[key] = withIdRefPrefix(value);
2151
+ }
2152
+ }
2153
+ return node;
2154
+ }
2155
+ function withIdRefPrefixArray(node) {
2156
+ for (let i = 0; i < node.length; i++) {
2157
+ node[i] = withIdRefPrefix(node[i]);
2158
+ }
2159
+ return node;
2160
+ }
2161
+ function withIdRefPrefix(schemaNode) {
2162
+ if (Array.isArray(schemaNode)) {
2163
+ return withIdRefPrefixArray([...schemaNode]);
2164
+ }
2165
+ if (isObject2(schemaNode)) {
2166
+ return withIdRefPrefixObject({ ...schemaNode });
2167
+ }
2168
+ return schemaNode;
2169
+ }
2170
+
2171
+ // src/enums.ts
2172
+ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
2173
+ TranslatableString2["ArrayItemTitle"] = "Item";
2174
+ TranslatableString2["MissingItems"] = "Missing items definition";
2175
+ TranslatableString2["YesLabel"] = "Yes";
2176
+ TranslatableString2["NoLabel"] = "No";
2177
+ TranslatableString2["CloseLabel"] = "Close";
2178
+ TranslatableString2["ErrorsLabel"] = "Errors";
2179
+ TranslatableString2["NewStringDefault"] = "New Value";
2180
+ TranslatableString2["AddButton"] = "Add";
2181
+ TranslatableString2["AddItemButton"] = "Add Item";
2182
+ TranslatableString2["CopyButton"] = "Copy";
2183
+ TranslatableString2["MoveDownButton"] = "Move down";
2184
+ TranslatableString2["MoveUpButton"] = "Move up";
2185
+ TranslatableString2["RemoveButton"] = "Remove";
2186
+ TranslatableString2["NowLabel"] = "Now";
2187
+ TranslatableString2["ClearLabel"] = "Clear";
2188
+ TranslatableString2["AriaDateLabel"] = "Select a date";
2189
+ TranslatableString2["PreviewLabel"] = "Preview";
2190
+ TranslatableString2["DecrementAriaLabel"] = "Decrease value by 1";
2191
+ TranslatableString2["IncrementAriaLabel"] = "Increase value by 1";
2192
+ TranslatableString2["UnknownFieldType"] = "Unknown field type %1";
2193
+ TranslatableString2["OptionPrefix"] = "Option %1";
2194
+ TranslatableString2["TitleOptionPrefix"] = "%1 option %2";
2195
+ TranslatableString2["KeyLabel"] = "%1 Key";
2196
+ TranslatableString2["InvalidObjectField"] = 'Invalid "%1" object field configuration: <em>%2</em>.';
2197
+ TranslatableString2["UnsupportedField"] = "Unsupported field schema.";
2198
+ TranslatableString2["UnsupportedFieldWithId"] = "Unsupported field schema for field <code>%1</code>.";
2199
+ TranslatableString2["UnsupportedFieldWithReason"] = "Unsupported field schema: <em>%1</em>.";
2200
+ TranslatableString2["UnsupportedFieldWithIdAndReason"] = "Unsupported field schema for field <code>%1</code>: <em>%2</em>.";
2201
+ TranslatableString2["FilesInfo"] = "<strong>%1</strong> (%2, %3 bytes)";
2202
+ return TranslatableString2;
2203
+ })(TranslatableString || {});
2204
+ var ParserValidator = class {
2205
+ /** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
2206
+ * first.
2207
+ *
2208
+ * @param rootSchema - The root schema against which this validator will be executed
2209
+ */
2210
+ constructor(rootSchema) {
2211
+ /** The map of schemas encountered by the ParserValidator */
2212
+ this.schemaMap = {};
2213
+ this.rootSchema = rootSchema;
2214
+ this.addSchema(rootSchema, hashForSchema(rootSchema));
2215
+ }
2216
+ /** Adds the given `schema` to the `schemaMap` keyed by the `hash` or `ID_KEY` if present on the `schema`. If the
2217
+ * schema does not have an `ID_KEY`, then the `hash` will be added as the `ID_KEY` to allow the schema to be
2218
+ * associated with it's `hash` for future use (by a schema compiler).
2219
+ *
2220
+ * @param schema - The schema which is to be added to the map
2221
+ * @param hash - The hash value at which to map the schema
2222
+ */
2223
+ addSchema(schema, hash) {
2224
+ const key = get7(schema, ID_KEY, hash);
2225
+ const identifiedSchema = { ...schema, [ID_KEY]: key };
2226
+ const existing = this.schemaMap[key];
2227
+ if (!existing) {
2228
+ this.schemaMap[key] = identifiedSchema;
2229
+ } else if (!isEqual3(existing, identifiedSchema)) {
2230
+ console.error("existing schema:", JSON.stringify(existing, null, 2));
2231
+ console.error("new schema:", JSON.stringify(identifiedSchema, null, 2));
2232
+ throw new Error(
2233
+ `Two different schemas exist with the same key ${key}! What a bad coincidence. If possible, try adding an $id to one of the schemas`
2234
+ );
2235
+ }
2236
+ }
2237
+ /** Returns the current `schemaMap` to the caller
2238
+ */
2239
+ getSchemaMap() {
2240
+ return this.schemaMap;
2241
+ }
2242
+ /** Implements the `ValidatorType` `isValid()` method to capture the `schema` in the `schemaMap`. Throws an error when
2243
+ * the `rootSchema` is not the same as the root schema provided during construction.
2244
+ *
2245
+ * @param schema - The schema to record in the `schemaMap`
2246
+ * @param _formData - The formData parameter that is ignored
2247
+ * @param rootSchema - The root schema associated with the schema
2248
+ * @throws - Error when the given `rootSchema` differs from the root schema provided during construction
2249
+ */
2250
+ isValid(schema, _formData, rootSchema) {
2251
+ if (!isEqual3(rootSchema, this.rootSchema)) {
2252
+ throw new Error("Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema");
2253
+ }
2254
+ this.addSchema(schema, hashForSchema(schema));
2255
+ return false;
2256
+ }
2257
+ /** Implements the `ValidatorType` `rawValidation()` method to throw an error since it is never supposed to be called
2258
+ *
2259
+ * @param _schema - The schema parameter that is ignored
2260
+ * @param _formData - The formData parameter that is ignored
2261
+ */
2262
+ rawValidation(_schema, _formData) {
2263
+ throw new Error("Unexpectedly calling the `rawValidation()` method during schema parsing");
2264
+ }
2265
+ /** Implements the `ValidatorType` `toErrorList()` method to throw an error since it is never supposed to be called
2266
+ *
2267
+ * @param _errorSchema - The error schema parameter that is ignored
2268
+ * @param _fieldPath - The field path parameter that is ignored
2269
+ */
2270
+ toErrorList(_errorSchema, _fieldPath) {
2271
+ throw new Error("Unexpectedly calling the `toErrorList()` method during schema parsing");
2272
+ }
2273
+ /** Implements the `ValidatorType` `validateFormData()` method to throw an error since it is never supposed to be
2274
+ * called
2275
+ *
2276
+ * @param _formData - The formData parameter that is ignored
2277
+ * @param _schema - The schema parameter that is ignored
2278
+ * @param _customValidate - The customValidate parameter that is ignored
2279
+ * @param _transformErrors - The transformErrors parameter that is ignored
2280
+ * @param _uiSchema - The uiSchema parameter that is ignored
2281
+ */
2282
+ validateFormData(_formData, _schema, _customValidate, _transformErrors, _uiSchema) {
2283
+ throw new Error("Unexpectedly calling the `validateFormData()` method during schema parsing");
2284
+ }
2285
+ };
2286
+
2287
+ // src/parser/schemaParser.ts
2288
+ function parseSchema(validator, recurseList, rootSchema, schema) {
2289
+ const schemas = retrieveSchemaInternal(validator, schema, rootSchema, void 0, true);
2290
+ schemas.forEach((schema2) => {
2291
+ const sameSchemaIndex = recurseList.findIndex((item) => isEqual3(item, schema2));
2292
+ if (sameSchemaIndex === -1) {
2293
+ recurseList.push(schema2);
2294
+ const allOptions = resolveAnyOrOneOfSchemas(validator, schema2, rootSchema, true);
2295
+ allOptions.forEach((s) => {
2296
+ if (PROPERTIES_KEY in s && s[PROPERTIES_KEY]) {
2297
+ forEach(schema2[PROPERTIES_KEY], (value) => {
2298
+ parseSchema(validator, recurseList, rootSchema, value);
2299
+ });
2300
+ }
2301
+ });
2302
+ if (ITEMS_KEY in schema2 && !Array.isArray(schema2.items) && typeof schema2.items !== "boolean") {
2303
+ parseSchema(validator, recurseList, rootSchema, schema2.items);
2304
+ }
2305
+ }
2306
+ });
2307
+ }
2308
+ function schemaParser(rootSchema) {
2309
+ const validator = new ParserValidator(rootSchema);
2310
+ const recurseList = [];
2311
+ parseSchema(validator, recurseList, rootSchema, rootSchema);
2312
+ return validator.getSchemaMap();
2313
+ }
2314
+
2315
+ exports.ADDITIONAL_PROPERTIES_KEY = ADDITIONAL_PROPERTIES_KEY;
2316
+ exports.ADDITIONAL_PROPERTY_FLAG = ADDITIONAL_PROPERTY_FLAG;
2317
+ exports.ALL_OF_KEY = ALL_OF_KEY;
2318
+ exports.ANY_OF_KEY = ANY_OF_KEY;
2319
+ exports.CONST_KEY = CONST_KEY;
2320
+ exports.DEFAULT_KEY = DEFAULT_KEY;
2321
+ exports.DEFINITIONS_KEY = DEFINITIONS_KEY;
2322
+ exports.DEPENDENCIES_KEY = DEPENDENCIES_KEY;
2323
+ exports.ENUM_KEY = ENUM_KEY;
2324
+ exports.ERRORS_KEY = ERRORS_KEY;
2325
+ exports.ErrorSchemaBuilder = ErrorSchemaBuilder;
2326
+ exports.ID_KEY = ID_KEY;
2327
+ exports.IF_KEY = IF_KEY;
2328
+ exports.ITEMS_KEY = ITEMS_KEY;
2329
+ exports.JUNK_OPTION_ID = JUNK_OPTION_ID;
2330
+ exports.NAME_KEY = NAME_KEY;
2331
+ exports.ONE_OF_KEY = ONE_OF_KEY;
2332
+ exports.PROPERTIES_KEY = PROPERTIES_KEY;
2333
+ exports.REF_KEY = REF_KEY;
2334
+ exports.REQUIRED_KEY = REQUIRED_KEY;
2335
+ exports.RJSF_ADDITONAL_PROPERTIES_FLAG = RJSF_ADDITONAL_PROPERTIES_FLAG;
2336
+ exports.ROOT_SCHEMA_PREFIX = ROOT_SCHEMA_PREFIX;
2337
+ exports.SUBMIT_BTN_OPTIONS_KEY = SUBMIT_BTN_OPTIONS_KEY;
2338
+ exports.TranslatableString = TranslatableString;
2339
+ exports.UI_FIELD_KEY = UI_FIELD_KEY;
2340
+ exports.UI_GLOBAL_OPTIONS_KEY = UI_GLOBAL_OPTIONS_KEY;
2341
+ exports.UI_OPTIONS_KEY = UI_OPTIONS_KEY;
2342
+ exports.UI_WIDGET_KEY = UI_WIDGET_KEY;
2343
+ exports.allowAdditionalItems = allowAdditionalItems;
2344
+ exports.ariaDescribedByIds = ariaDescribedByIds;
2345
+ exports.asNumber = asNumber;
2346
+ exports.canExpand = canExpand;
2347
+ exports.createErrorHandler = createErrorHandler;
2348
+ exports.createSchemaUtils = createSchemaUtils;
2349
+ exports.dataURItoBlob = dataURItoBlob;
2350
+ exports.deepEquals = deepEquals;
2351
+ exports.descriptionId = descriptionId;
2352
+ exports.englishStringTranslator = englishStringTranslator;
2353
+ exports.enumOptionsDeselectValue = enumOptionsDeselectValue;
2354
+ exports.enumOptionsIndexForValue = enumOptionsIndexForValue;
2355
+ exports.enumOptionsIsSelected = enumOptionsIsSelected;
2356
+ exports.enumOptionsSelectValue = enumOptionsSelectValue;
2357
+ exports.enumOptionsValueForIndex = enumOptionsValueForIndex;
2358
+ exports.errorId = errorId;
2359
+ exports.examplesId = examplesId;
2360
+ exports.findSchemaDefinition = findSchemaDefinition;
2361
+ exports.getClosestMatchingOption = getClosestMatchingOption;
2362
+ exports.getDefaultFormState = getDefaultFormState;
2363
+ exports.getDiscriminatorFieldFromSchema = getDiscriminatorFieldFromSchema;
2364
+ exports.getDisplayLabel = getDisplayLabel;
2365
+ exports.getFirstMatchingOption = getFirstMatchingOption;
2366
+ exports.getInputProps = getInputProps;
2367
+ exports.getMatchingOption = getMatchingOption;
2368
+ exports.getSchemaType = getSchemaType;
2369
+ exports.getSubmitButtonOptions = getSubmitButtonOptions;
2370
+ exports.getTemplate = getTemplate;
2371
+ exports.getUiOptions = getUiOptions;
2372
+ exports.getWidget = getWidget;
2373
+ exports.guessType = guessType;
2374
+ exports.hasWidget = hasWidget;
2375
+ exports.hashForSchema = hashForSchema;
2376
+ exports.helpId = helpId;
2377
+ exports.isConstant = isConstant;
2378
+ exports.isCustomWidget = isCustomWidget;
2379
+ exports.isFilesArray = isFilesArray;
2380
+ exports.isFixedItems = isFixedItems;
2381
+ exports.isMultiSelect = isMultiSelect;
2382
+ exports.isObject = isObject;
2383
+ exports.isSelect = isSelect;
2384
+ exports.labelValue = labelValue;
2385
+ exports.localToUTC = localToUTC;
2386
+ exports.mergeDefaultsWithFormData = mergeDefaultsWithFormData;
2387
+ exports.mergeObjects = mergeObjects;
2388
+ exports.mergeSchemas = mergeSchemas;
2389
+ exports.mergeValidationData = mergeValidationData;
2390
+ exports.optionId = optionId;
2391
+ exports.optionsList = optionsList;
2392
+ exports.orderProperties = orderProperties;
2393
+ exports.pad = pad;
2394
+ exports.parseDateString = parseDateString;
2395
+ exports.rangeSpec = rangeSpec;
2396
+ exports.replaceStringParameters = replaceStringParameters;
2397
+ exports.retrieveSchema = retrieveSchema;
2398
+ exports.sanitizeDataForNewSchema = sanitizeDataForNewSchema;
2399
+ exports.schemaParser = schemaParser;
2400
+ exports.schemaRequiresTrueValue = schemaRequiresTrueValue;
2401
+ exports.shouldRender = shouldRender;
2402
+ exports.titleId = titleId;
2403
+ exports.toConstant = toConstant;
2404
+ exports.toDateString = toDateString;
2405
+ exports.toErrorList = toErrorList;
2406
+ exports.toErrorSchema = toErrorSchema;
2407
+ exports.toIdSchema = toIdSchema;
2408
+ exports.toPathSchema = toPathSchema;
2409
+ exports.unwrapErrorHandler = unwrapErrorHandler;
2410
+ exports.utcToLocal = utcToLocal;
2411
+ exports.validationDataMerge = validationDataMerge;
2412
+ exports.withIdRefPrefix = withIdRefPrefix;
2413
+
2414
+ }));