@rjsf/utils 5.11.2 → 5.12.1

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