@rjsf/utils 5.11.2 → 5.12.1

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