@rjsf/utils 5.11.2 → 5.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (303) hide show
  1. package/dist/index.js +2544 -5
  2. package/dist/index.js.map +7 -0
  3. package/dist/utils.esm.js +1228 -2113
  4. package/dist/utils.esm.js.map +7 -1
  5. package/dist/utils.umd.js +2414 -0
  6. package/lib/ErrorSchemaBuilder.d.ts +60 -0
  7. package/lib/ErrorSchemaBuilder.js +103 -0
  8. package/lib/ErrorSchemaBuilder.js.map +1 -0
  9. package/lib/allowAdditionalItems.d.ts +8 -0
  10. package/lib/allowAdditionalItems.js +14 -0
  11. package/lib/allowAdditionalItems.js.map +1 -0
  12. package/lib/asNumber.d.ts +10 -0
  13. package/lib/asNumber.js +36 -0
  14. package/lib/asNumber.js.map +1 -0
  15. package/lib/canExpand.d.ts +11 -0
  16. package/lib/canExpand.js +26 -0
  17. package/lib/canExpand.js.map +1 -0
  18. package/lib/constants.d.ts +31 -0
  19. package/lib/constants.js +32 -0
  20. package/lib/constants.js.map +1 -0
  21. package/lib/createErrorHandler.d.ts +7 -0
  22. package/lib/createErrorHandler.js +31 -0
  23. package/lib/createErrorHandler.js.map +1 -0
  24. package/lib/createSchemaUtils.d.ts +10 -0
  25. package/lib/createSchemaUtils.js +207 -0
  26. package/lib/createSchemaUtils.js.map +1 -0
  27. package/lib/dataURItoBlob.d.ts +16 -0
  28. package/lib/dataURItoBlob.js +43 -0
  29. package/lib/dataURItoBlob.js.map +1 -0
  30. package/lib/deepEquals.d.ts +8 -0
  31. package/lib/deepEquals.js +19 -0
  32. package/lib/deepEquals.js.map +1 -0
  33. package/lib/englishStringTranslator.d.ts +10 -0
  34. package/lib/englishStringTranslator.js +13 -0
  35. package/lib/englishStringTranslator.js.map +1 -0
  36. package/lib/enumOptionsDeselectValue.d.ts +14 -0
  37. package/lib/enumOptionsDeselectValue.js +22 -0
  38. package/lib/enumOptionsDeselectValue.js.map +1 -0
  39. package/lib/enumOptionsIndexForValue.d.ts +13 -0
  40. package/lib/enumOptionsIndexForValue.js +22 -0
  41. package/lib/enumOptionsIndexForValue.js.map +1 -0
  42. package/lib/enumOptionsIsSelected.d.ts +8 -0
  43. package/lib/enumOptionsIsSelected.js +14 -0
  44. package/lib/enumOptionsIsSelected.js.map +1 -0
  45. package/lib/enumOptionsSelectValue.d.ts +10 -0
  46. package/lib/enumOptionsSelectValue.js +23 -0
  47. package/lib/enumOptionsSelectValue.js.map +1 -0
  48. package/lib/enumOptionsValueForIndex.d.ts +13 -0
  49. package/lib/enumOptionsValueForIndex.js +21 -0
  50. package/lib/enumOptionsValueForIndex.js.map +1 -0
  51. package/lib/enums.d.ts +72 -0
  52. package/lib/enums.js +76 -0
  53. package/lib/enums.js.map +1 -0
  54. package/lib/findSchemaDefinition.d.ts +20 -0
  55. package/lib/findSchemaDefinition.js +49 -0
  56. package/lib/findSchemaDefinition.js.map +1 -0
  57. package/lib/getDiscriminatorFieldFromSchema.d.ts +8 -0
  58. package/lib/getDiscriminatorFieldFromSchema.js +20 -0
  59. package/lib/getDiscriminatorFieldFromSchema.js.map +1 -0
  60. package/lib/getInputProps.d.ts +10 -0
  61. package/lib/getInputProps.js +41 -0
  62. package/lib/getInputProps.js.map +1 -0
  63. package/lib/getSchemaType.d.ts +13 -0
  64. package/lib/getSchemaType.js +29 -0
  65. package/lib/getSchemaType.js.map +1 -0
  66. package/lib/getSubmitButtonOptions.d.ts +10 -0
  67. package/lib/getSubmitButtonOptions.js +25 -0
  68. package/lib/getSubmitButtonOptions.js.map +1 -0
  69. package/lib/getTemplate.d.ts +10 -0
  70. package/lib/getTemplate.js +19 -0
  71. package/lib/getTemplate.js.map +1 -0
  72. package/lib/getUiOptions.d.ts +9 -0
  73. package/lib/getUiOptions.js +25 -0
  74. package/lib/getUiOptions.js.map +1 -0
  75. package/lib/getWidget.d.ts +13 -0
  76. package/lib/getWidget.js +118 -0
  77. package/lib/getWidget.js.map +1 -0
  78. package/lib/guessType.d.ts +7 -0
  79. package/lib/guessType.js +29 -0
  80. package/lib/guessType.js.map +1 -0
  81. package/lib/hasWidget.d.ts +10 -0
  82. package/lib/hasWidget.js +23 -0
  83. package/lib/hasWidget.js.map +1 -0
  84. package/lib/hashForSchema.d.ts +8 -0
  85. package/lib/hashForSchema.js +29 -0
  86. package/lib/hashForSchema.js.map +1 -0
  87. package/lib/idGenerators.d.ts +47 -0
  88. package/lib/idGenerators.js +73 -0
  89. package/lib/idGenerators.js.map +1 -0
  90. package/lib/index.d.ts +57 -0
  91. package/lib/index.js +58 -0
  92. package/lib/index.js.map +1 -0
  93. package/lib/isConstant.d.ts +8 -0
  94. package/lib/isConstant.js +11 -0
  95. package/lib/isConstant.js.map +1 -0
  96. package/lib/isCustomWidget.d.ts +7 -0
  97. package/lib/isCustomWidget.js +13 -0
  98. package/lib/isCustomWidget.js.map +1 -0
  99. package/lib/isFixedItems.d.ts +8 -0
  100. package/lib/isFixedItems.js +11 -0
  101. package/lib/isFixedItems.js.map +1 -0
  102. package/lib/isObject.d.ts +7 -0
  103. package/lib/isObject.js +16 -0
  104. package/lib/isObject.js.map +1 -0
  105. package/lib/labelValue.d.ts +13 -0
  106. package/lib/labelValue.js +4 -0
  107. package/lib/labelValue.js.map +1 -0
  108. package/lib/localToUTC.d.ts +6 -0
  109. package/lib/localToUTC.js +9 -0
  110. package/lib/localToUTC.js.map +1 -0
  111. package/lib/mergeDefaultsWithFormData.d.ts +17 -0
  112. package/lib/mergeDefaultsWithFormData.js +43 -0
  113. package/lib/mergeDefaultsWithFormData.js.map +1 -0
  114. package/lib/mergeObjects.d.ts +11 -0
  115. package/lib/mergeObjects.js +35 -0
  116. package/lib/mergeObjects.js.map +1 -0
  117. package/lib/mergeSchemas.d.ts +10 -0
  118. package/lib/mergeSchemas.js +35 -0
  119. package/lib/mergeSchemas.js.map +1 -0
  120. package/lib/optionsList.d.ts +10 -0
  121. package/lib/optionsList.js +36 -0
  122. package/lib/optionsList.js.map +1 -0
  123. package/lib/orderProperties.d.ts +11 -0
  124. package/lib/orderProperties.js +38 -0
  125. package/lib/orderProperties.js.map +1 -0
  126. package/lib/pad.d.ts +7 -0
  127. package/lib/pad.js +14 -0
  128. package/lib/pad.js.map +1 -0
  129. package/lib/parseDateString.d.ts +9 -0
  130. package/lib/parseDateString.js +32 -0
  131. package/lib/parseDateString.js.map +1 -0
  132. package/lib/parser/ParserValidator.d.ts +70 -0
  133. package/lib/parser/ParserValidator.js +93 -0
  134. package/lib/parser/ParserValidator.js.map +1 -0
  135. package/lib/parser/index.d.ts +4 -0
  136. package/lib/parser/index.js +3 -0
  137. package/lib/parser/index.js.map +1 -0
  138. package/lib/parser/schemaParser.d.ts +9 -0
  139. package/lib/parser/schemaParser.js +48 -0
  140. package/lib/parser/schemaParser.js.map +1 -0
  141. package/lib/rangeSpec.d.ts +9 -0
  142. package/lib/rangeSpec.js +20 -0
  143. package/lib/rangeSpec.js.map +1 -0
  144. package/lib/replaceStringParameters.d.ts +9 -0
  145. package/lib/replaceStringParameters.js +23 -0
  146. package/lib/replaceStringParameters.js.map +1 -0
  147. package/lib/schema/getClosestMatchingOption.d.ts +49 -0
  148. package/lib/schema/getClosestMatchingOption.js +154 -0
  149. package/lib/schema/getClosestMatchingOption.js.map +1 -0
  150. package/lib/schema/getDefaultFormState.d.ts +66 -0
  151. package/lib/schema/getDefaultFormState.js +351 -0
  152. package/lib/schema/getDefaultFormState.js.map +1 -0
  153. package/lib/schema/getDisplayLabel.d.ts +12 -0
  154. package/lib/schema/getDisplayLabel.js +39 -0
  155. package/lib/schema/getDisplayLabel.js.map +1 -0
  156. package/lib/schema/getFirstMatchingOption.d.ts +13 -0
  157. package/lib/schema/getFirstMatchingOption.js +16 -0
  158. package/lib/schema/getFirstMatchingOption.js.map +1 -0
  159. package/lib/schema/getMatchingOption.d.ts +14 -0
  160. package/lib/schema/getMatchingOption.js +80 -0
  161. package/lib/schema/getMatchingOption.js.map +1 -0
  162. package/lib/schema/index.d.ts +14 -0
  163. package/lib/schema/index.js +15 -0
  164. package/lib/schema/index.js.map +1 -0
  165. package/lib/schema/isFilesArray.d.ts +10 -0
  166. package/lib/schema/isFilesArray.js +21 -0
  167. package/lib/schema/isFilesArray.js.map +1 -0
  168. package/lib/schema/isMultiSelect.d.ts +9 -0
  169. package/lib/schema/isMultiSelect.js +15 -0
  170. package/lib/schema/isMultiSelect.js.map +1 -0
  171. package/lib/schema/isSelect.d.ts +9 -0
  172. package/lib/schema/isSelect.js +21 -0
  173. package/lib/schema/isSelect.js.map +1 -0
  174. package/lib/schema/mergeValidationData.d.ts +14 -0
  175. package/lib/schema/mergeValidationData.js +28 -0
  176. package/lib/schema/mergeValidationData.js.map +1 -0
  177. package/lib/schema/retrieveSchema.d.ts +170 -0
  178. package/lib/schema/retrieveSchema.js +437 -0
  179. package/lib/schema/retrieveSchema.js.map +1 -0
  180. package/lib/schema/sanitizeDataForNewSchema.d.ts +49 -0
  181. package/lib/schema/sanitizeDataForNewSchema.js +173 -0
  182. package/lib/schema/sanitizeDataForNewSchema.js.map +1 -0
  183. package/lib/schema/toIdSchema.d.ts +13 -0
  184. package/lib/schema/toIdSchema.js +59 -0
  185. package/lib/schema/toIdSchema.js.map +1 -0
  186. package/lib/schema/toPathSchema.d.ts +11 -0
  187. package/lib/schema/toPathSchema.js +68 -0
  188. package/lib/schema/toPathSchema.js.map +1 -0
  189. package/lib/schemaRequiresTrueValue.d.ts +11 -0
  190. package/lib/schemaRequiresTrueValue.js +34 -0
  191. package/lib/schemaRequiresTrueValue.js.map +1 -0
  192. package/lib/shouldRender.d.ts +10 -0
  193. package/lib/shouldRender.js +14 -0
  194. package/lib/shouldRender.js.map +1 -0
  195. package/lib/toConstant.d.ts +9 -0
  196. package/lib/toConstant.js +18 -0
  197. package/lib/toConstant.js.map +1 -0
  198. package/lib/toDateString.d.ts +9 -0
  199. package/lib/toDateString.js +14 -0
  200. package/lib/toDateString.js.map +1 -0
  201. package/lib/toErrorList.d.ts +8 -0
  202. package/lib/toErrorList.js +34 -0
  203. package/lib/toErrorList.js.map +1 -0
  204. package/lib/toErrorSchema.d.ts +21 -0
  205. package/lib/toErrorSchema.js +41 -0
  206. package/lib/toErrorSchema.js.map +1 -0
  207. package/lib/types.d.ts +982 -0
  208. package/lib/types.js +2 -0
  209. package/lib/types.js.map +1 -0
  210. package/lib/unwrapErrorHandler.d.ts +7 -0
  211. package/lib/unwrapErrorHandler.js +21 -0
  212. package/lib/unwrapErrorHandler.js.map +1 -0
  213. package/lib/utcToLocal.d.ts +6 -0
  214. package/lib/utcToLocal.js +26 -0
  215. package/lib/utcToLocal.js.map +1 -0
  216. package/lib/validationDataMerge.d.ts +11 -0
  217. package/lib/validationDataMerge.js +26 -0
  218. package/lib/validationDataMerge.js.map +1 -0
  219. package/lib/withIdRefPrefix.d.ts +8 -0
  220. package/lib/withIdRefPrefix.js +47 -0
  221. package/lib/withIdRefPrefix.js.map +1 -0
  222. package/package.json +20 -13
  223. package/src/ErrorSchemaBuilder.ts +112 -0
  224. package/src/allowAdditionalItems.ts +15 -0
  225. package/src/asNumber.ts +38 -0
  226. package/src/canExpand.ts +31 -0
  227. package/src/constants.ts +31 -0
  228. package/src/createErrorHandler.ts +33 -0
  229. package/src/createSchemaUtils.ts +298 -0
  230. package/src/dataURItoBlob.ts +42 -0
  231. package/src/deepEquals.ts +19 -0
  232. package/src/englishStringTranslator.ts +14 -0
  233. package/src/enumOptionsDeselectValue.ts +28 -0
  234. package/src/enumOptionsIndexForValue.ts +27 -0
  235. package/src/enumOptionsIsSelected.ts +19 -0
  236. package/src/enumOptionsSelectValue.ts +28 -0
  237. package/src/enumOptionsValueForIndex.ts +26 -0
  238. package/src/enums.ts +74 -0
  239. package/src/findSchemaDefinition.ts +54 -0
  240. package/src/getDiscriminatorFieldFromSchema.ts +21 -0
  241. package/src/getInputProps.ts +55 -0
  242. package/src/getSchemaType.ts +37 -0
  243. package/src/getSubmitButtonOptions.ts +32 -0
  244. package/src/getTemplate.ts +26 -0
  245. package/src/getUiOptions.ts +32 -0
  246. package/src/getWidget.tsx +133 -0
  247. package/src/guessType.ts +28 -0
  248. package/src/hasWidget.ts +27 -0
  249. package/src/hashForSchema.ts +31 -0
  250. package/src/idGenerators.ts +81 -0
  251. package/src/index.ts +118 -0
  252. package/src/isConstant.ts +12 -0
  253. package/src/isCustomWidget.ts +19 -0
  254. package/src/isFixedItems.ts +12 -0
  255. package/src/isObject.ts +15 -0
  256. package/src/labelValue.ts +16 -0
  257. package/src/localToUTC.ts +8 -0
  258. package/src/mergeDefaultsWithFormData.ts +53 -0
  259. package/src/mergeObjects.ts +39 -0
  260. package/src/mergeSchemas.ts +38 -0
  261. package/src/optionsList.ts +41 -0
  262. package/src/orderProperties.ts +44 -0
  263. package/src/pad.ts +13 -0
  264. package/src/parseDateString.ts +33 -0
  265. package/src/parser/ParserValidator.ts +132 -0
  266. package/src/parser/index.ts +6 -0
  267. package/src/parser/schemaParser.ts +60 -0
  268. package/src/rangeSpec.ts +22 -0
  269. package/src/replaceStringParameters.ts +22 -0
  270. package/src/schema/getClosestMatchingOption.ts +191 -0
  271. package/src/schema/getDefaultFormState.ts +447 -0
  272. package/src/schema/getDisplayLabel.ts +59 -0
  273. package/src/schema/getFirstMatchingOption.ts +27 -0
  274. package/src/schema/getMatchingOption.ts +95 -0
  275. package/src/schema/index.ts +29 -0
  276. package/src/schema/isFilesArray.ts +27 -0
  277. package/src/schema/isMultiSelect.ts +21 -0
  278. package/src/schema/isSelect.ts +26 -0
  279. package/src/schema/mergeValidationData.ts +38 -0
  280. package/src/schema/retrieveSchema.ts +614 -0
  281. package/src/schema/sanitizeDataForNewSchema.ts +197 -0
  282. package/src/schema/toIdSchema.ts +105 -0
  283. package/src/schema/toPathSchema.ts +121 -0
  284. package/src/schemaRequiresTrueValue.ts +40 -0
  285. package/src/shouldRender.ts +16 -0
  286. package/src/toConstant.ts +19 -0
  287. package/src/toDateString.ts +15 -0
  288. package/src/toErrorList.ts +41 -0
  289. package/src/toErrorSchema.ts +43 -0
  290. package/src/types.ts +1139 -0
  291. package/src/unwrapErrorHandler.ts +25 -0
  292. package/src/utcToLocal.ts +30 -0
  293. package/src/validationDataMerge.ts +31 -0
  294. package/src/withIdRefPrefix.ts +49 -0
  295. package/dist/index.d.ts +0 -1911
  296. package/dist/utils.cjs.development.js +0 -3522
  297. package/dist/utils.cjs.development.js.map +0 -1
  298. package/dist/utils.cjs.production.min.js +0 -2
  299. package/dist/utils.cjs.production.min.js.map +0 -1
  300. package/dist/utils.umd.development.js +0 -3504
  301. package/dist/utils.umd.development.js.map +0 -1
  302. package/dist/utils.umd.production.min.js +0 -2
  303. package/dist/utils.umd.production.min.js.map +0 -1
@@ -0,0 +1,60 @@
1
+ import { ErrorSchema } from './types';
2
+ /** The `ErrorSchemaBuilder<T>` is used to build an `ErrorSchema<T>` since the definition of the `ErrorSchema` type is
3
+ * designed for reading information rather than writing it. Use this class to add, replace or clear errors in an error
4
+ * schema by using either dotted path or an array of path names. Once you are done building the `ErrorSchema`, you can
5
+ * get the result and/or reset all the errors back to an initial set and start again.
6
+ */
7
+ export default class ErrorSchemaBuilder<T = any> {
8
+ /** The error schema being built
9
+ *
10
+ * @private
11
+ */
12
+ private errorSchema;
13
+ /** Construct an `ErrorSchemaBuilder` with an optional initial set of errors in an `ErrorSchema`.
14
+ *
15
+ * @param [initialSchema] - The optional set of initial errors, that will be cloned into the class
16
+ */
17
+ constructor(initialSchema?: ErrorSchema<T>);
18
+ /** Returns the `ErrorSchema` that has been updated by the methods of the `ErrorSchemaBuilder`
19
+ */
20
+ get ErrorSchema(): ErrorSchema<T>;
21
+ /** Will get an existing `ErrorSchema` at the specified `pathOfError` or create and return one.
22
+ *
23
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to add the error(s)
24
+ * @returns - The error block for the given `pathOfError` or the root if not provided
25
+ * @private
26
+ */
27
+ private getOrCreateErrorBlock;
28
+ /** Resets all errors in the `ErrorSchemaBuilder` back to the `initialSchema` if provided, otherwise an empty set.
29
+ *
30
+ * @param [initialSchema] - The optional set of initial errors, that will be cloned into the class
31
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
32
+ */
33
+ resetAllErrors(initialSchema?: ErrorSchema<T>): this;
34
+ /** Adds the `errorOrList` to the list of errors in the `ErrorSchema` at either the root level or the location within
35
+ * the schema described by the `pathOfError`. For more information about how to specify the path see the
36
+ * [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
37
+ *
38
+ * @param errorOrList - The error or list of errors to add into the `ErrorSchema`
39
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to add the error(s)
40
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
41
+ */
42
+ addErrors(errorOrList: string | string[], pathOfError?: string | string[]): this;
43
+ /** Sets/replaces the `errorOrList` as the error(s) in the `ErrorSchema` at either the root level or the location
44
+ * within the schema described by the `pathOfError`. For more information about how to specify the path see the
45
+ * [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
46
+ *
47
+ * @param errorOrList - The error or list of errors to set into the `ErrorSchema`
48
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to set the error(s)
49
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
50
+ */
51
+ setErrors(errorOrList: string | string[], pathOfError?: string | string[]): this;
52
+ /** Clears the error(s) in the `ErrorSchema` at either the root level or the location within the schema described by
53
+ * the `pathOfError`. For more information about how to specify the path see the
54
+ * [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
55
+ *
56
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to clear the error(s)
57
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
58
+ */
59
+ clearErrors(pathOfError?: string | string[]): this;
60
+ }
@@ -0,0 +1,103 @@
1
+ import cloneDeep from 'lodash/cloneDeep';
2
+ import get from 'lodash/get';
3
+ import set from 'lodash/set';
4
+ import { ERRORS_KEY } from './constants';
5
+ /** The `ErrorSchemaBuilder<T>` is used to build an `ErrorSchema<T>` since the definition of the `ErrorSchema` type is
6
+ * designed for reading information rather than writing it. Use this class to add, replace or clear errors in an error
7
+ * schema by using either dotted path or an array of path names. Once you are done building the `ErrorSchema`, you can
8
+ * get the result and/or reset all the errors back to an initial set and start again.
9
+ */
10
+ export default class ErrorSchemaBuilder {
11
+ /** Construct an `ErrorSchemaBuilder` with an optional initial set of errors in an `ErrorSchema`.
12
+ *
13
+ * @param [initialSchema] - The optional set of initial errors, that will be cloned into the class
14
+ */
15
+ constructor(initialSchema) {
16
+ /** The error schema being built
17
+ *
18
+ * @private
19
+ */
20
+ this.errorSchema = {};
21
+ this.resetAllErrors(initialSchema);
22
+ }
23
+ /** Returns the `ErrorSchema` that has been updated by the methods of the `ErrorSchemaBuilder`
24
+ */
25
+ get ErrorSchema() {
26
+ return this.errorSchema;
27
+ }
28
+ /** Will get an existing `ErrorSchema` at the specified `pathOfError` or create and return one.
29
+ *
30
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to add the error(s)
31
+ * @returns - The error block for the given `pathOfError` or the root if not provided
32
+ * @private
33
+ */
34
+ getOrCreateErrorBlock(pathOfError) {
35
+ const hasPath = (Array.isArray(pathOfError) && pathOfError.length > 0) || typeof pathOfError === 'string';
36
+ let errorBlock = hasPath ? get(this.errorSchema, pathOfError) : this.errorSchema;
37
+ if (!errorBlock && pathOfError) {
38
+ errorBlock = {};
39
+ set(this.errorSchema, pathOfError, errorBlock);
40
+ }
41
+ return errorBlock;
42
+ }
43
+ /** Resets all errors in the `ErrorSchemaBuilder` back to the `initialSchema` if provided, otherwise an empty set.
44
+ *
45
+ * @param [initialSchema] - The optional set of initial errors, that will be cloned into the class
46
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
47
+ */
48
+ resetAllErrors(initialSchema) {
49
+ this.errorSchema = initialSchema ? cloneDeep(initialSchema) : {};
50
+ return this;
51
+ }
52
+ /** Adds the `errorOrList` to the list of errors in the `ErrorSchema` at either the root level or the location within
53
+ * the schema described by the `pathOfError`. For more information about how to specify the path see the
54
+ * [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
55
+ *
56
+ * @param errorOrList - The error or list of errors to add into the `ErrorSchema`
57
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to add the error(s)
58
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
59
+ */
60
+ addErrors(errorOrList, pathOfError) {
61
+ const errorBlock = this.getOrCreateErrorBlock(pathOfError);
62
+ let errorsList = get(errorBlock, ERRORS_KEY);
63
+ if (!Array.isArray(errorsList)) {
64
+ errorsList = [];
65
+ errorBlock[ERRORS_KEY] = errorsList;
66
+ }
67
+ if (Array.isArray(errorOrList)) {
68
+ errorsList.push(...errorOrList);
69
+ }
70
+ else {
71
+ errorsList.push(errorOrList);
72
+ }
73
+ return this;
74
+ }
75
+ /** Sets/replaces the `errorOrList` as the error(s) in the `ErrorSchema` at either the root level or the location
76
+ * within the schema described by the `pathOfError`. For more information about how to specify the path see the
77
+ * [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
78
+ *
79
+ * @param errorOrList - The error or list of errors to set into the `ErrorSchema`
80
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to set the error(s)
81
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
82
+ */
83
+ setErrors(errorOrList, pathOfError) {
84
+ const errorBlock = this.getOrCreateErrorBlock(pathOfError);
85
+ // Effectively clone the array being given to prevent accidental outside manipulation of the given list
86
+ const listToAdd = Array.isArray(errorOrList) ? [...errorOrList] : [errorOrList];
87
+ set(errorBlock, ERRORS_KEY, listToAdd);
88
+ return this;
89
+ }
90
+ /** Clears the error(s) in the `ErrorSchema` at either the root level or the location within the schema described by
91
+ * the `pathOfError`. For more information about how to specify the path see the
92
+ * [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
93
+ *
94
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to clear the error(s)
95
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
96
+ */
97
+ clearErrors(pathOfError) {
98
+ const errorBlock = this.getOrCreateErrorBlock(pathOfError);
99
+ set(errorBlock, ERRORS_KEY, []);
100
+ return this;
101
+ }
102
+ }
103
+ //# sourceMappingURL=ErrorSchemaBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorSchemaBuilder.js","sourceRoot":"","sources":["../src/ErrorSchemaBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,GAAG,MAAM,YAAY,CAAC;AAC7B,OAAO,GAAG,MAAM,YAAY,CAAC;AAG7B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAkB;IAOrC;;;OAGG;IACH,YAAY,aAA8B;QAV1C;;;WAGG;QACK,gBAAW,GAAmB,EAAE,CAAC;QAOvC,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;IACrC,CAAC;IAED;OACG;IACH,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED;;;;;OAKG;IACK,qBAAqB,CAAC,WAA+B;QAC3D,MAAM,OAAO,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,OAAO,WAAW,KAAK,QAAQ,CAAC;QAC1G,IAAI,UAAU,GAAgB,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC;QAC9F,IAAI,CAAC,UAAU,IAAI,WAAW,EAAE;YAC9B,UAAU,GAAG,EAAE,CAAC;YAChB,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;SAChD;QACD,OAAO,UAAU,CAAC;IACpB,CAAC;IAED;;;;OAIG;IACH,cAAc,CAAC,aAA8B;QAC3C,IAAI,CAAC,WAAW,GAAG,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACjE,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;OAOG;IACH,SAAS,CAAC,WAA8B,EAAE,WAA+B;QACvE,MAAM,UAAU,GAAgB,IAAI,CAAC,qBAAqB,CAAC,WAAW,CAAC,CAAC;QACxE,IAAI,UAAU,GAAG,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;QAC7C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;YAC9B,UAAU,GAAG,EAAE,CAAC;YAChB,UAAU,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC;SACrC;QAED,IAAI,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;YAC9B,UAAU,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC;SACjC;aAAM;YACL,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;SAC9B;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;OAOG;IACH,SAAS,CAAC,WAA8B,EAAE,WAA+B;QACvE,MAAM,UAAU,GAAgB,IAAI,CAAC,qBAAqB,CAAC,WAAW,CAAC,CAAC;QACxE,uGAAuG;QACvG,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;QAChF,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;QACvC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;OAMG;IACH,WAAW,CAAC,WAA+B;QACzC,MAAM,UAAU,GAAgB,IAAI,CAAC,qBAAqB,CAAC,WAAW,CAAC,CAAC;QACxE,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ import { RJSFSchema, StrictRJSFSchema } from './types';
2
+ /** Checks the schema to see if it is allowing additional items, by verifying that `schema.additionalItems` is an
3
+ * object. The user is warned in the console if `schema.additionalItems` has the value `true`.
4
+ *
5
+ * @param schema - The schema object to check
6
+ * @returns - True if additional items is allowed, otherwise false
7
+ */
8
+ export default function allowAdditionalItems<S extends StrictRJSFSchema = RJSFSchema>(schema: S): boolean;
@@ -0,0 +1,14 @@
1
+ import isObject from './isObject';
2
+ /** Checks the schema to see if it is allowing additional items, by verifying that `schema.additionalItems` is an
3
+ * object. The user is warned in the console if `schema.additionalItems` has the value `true`.
4
+ *
5
+ * @param schema - The schema object to check
6
+ * @returns - True if additional items is allowed, otherwise false
7
+ */
8
+ export default function allowAdditionalItems(schema) {
9
+ if (schema.additionalItems === true) {
10
+ console.warn('additionalItems=true is currently not supported');
11
+ }
12
+ return isObject(schema.additionalItems);
13
+ }
14
+ //# sourceMappingURL=allowAdditionalItems.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"allowAdditionalItems.js","sourceRoot":"","sources":["../src/allowAdditionalItems.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,YAAY,CAAC;AAGlC;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAA0C,MAAS;IAC7F,IAAI,MAAM,CAAC,eAAe,KAAK,IAAI,EAAE;QACnC,OAAO,CAAC,IAAI,CAAC,iDAAiD,CAAC,CAAC;KACjE;IACD,OAAO,QAAQ,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,10 @@
1
+ /** Attempts to convert the string into a number. If an empty string is provided, then `undefined` is returned. If a
2
+ * `null` is provided, it is returned. If the string ends in a `.` then the string is returned because the user may be
3
+ * in the middle of typing a float number. If a number ends in a pattern like `.0`, `.20`, `.030`, string is returned
4
+ * because the user may be typing number that will end in a non-zero digit. Otherwise, the string is wrapped by
5
+ * `Number()` and if that result is not `NaN`, that number will be returned, otherwise the string `value` will be.
6
+ *
7
+ * @param value - The string or null value to convert to a number
8
+ * @returns - The `value` converted to a number when appropriate, otherwise the `value`
9
+ */
10
+ export default function asNumber(value: string | null): string | number | null | undefined;
@@ -0,0 +1,36 @@
1
+ /** Attempts to convert the string into a number. If an empty string is provided, then `undefined` is returned. If a
2
+ * `null` is provided, it is returned. If the string ends in a `.` then the string is returned because the user may be
3
+ * in the middle of typing a float number. If a number ends in a pattern like `.0`, `.20`, `.030`, string is returned
4
+ * because the user may be typing number that will end in a non-zero digit. Otherwise, the string is wrapped by
5
+ * `Number()` and if that result is not `NaN`, that number will be returned, otherwise the string `value` will be.
6
+ *
7
+ * @param value - The string or null value to convert to a number
8
+ * @returns - The `value` converted to a number when appropriate, otherwise the `value`
9
+ */
10
+ export default function asNumber(value) {
11
+ if (value === '') {
12
+ return undefined;
13
+ }
14
+ if (value === null) {
15
+ return null;
16
+ }
17
+ if (/\.$/.test(value)) {
18
+ // '3.' can't really be considered a number even if it parses in js. The
19
+ // user is most likely entering a float.
20
+ return value;
21
+ }
22
+ if (/\.0$/.test(value)) {
23
+ // we need to return this as a string here, to allow for input like 3.07
24
+ return value;
25
+ }
26
+ if (/\.\d*0$/.test(value)) {
27
+ // It's a number, that's cool - but we need it as a string so it doesn't screw
28
+ // with the user when entering dollar amounts or other values (such as those with
29
+ // specific precision or number of significant digits)
30
+ return value;
31
+ }
32
+ const n = Number(value);
33
+ const valid = typeof n === 'number' && !Number.isNaN(n);
34
+ return valid ? n : value;
35
+ }
36
+ //# sourceMappingURL=asNumber.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asNumber.js","sourceRoot":"","sources":["../src/asNumber.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,KAAoB;IACnD,IAAI,KAAK,KAAK,EAAE,EAAE;QAChB,OAAO,SAAS,CAAC;KAClB;IACD,IAAI,KAAK,KAAK,IAAI,EAAE;QAClB,OAAO,IAAI,CAAC;KACb;IACD,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;QACrB,wEAAwE;QACxE,wCAAwC;QACxC,OAAO,KAAK,CAAC;KACd;IACD,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;QACtB,wEAAwE;QACxE,OAAO,KAAK,CAAC;KACd;IAED,IAAI,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;QACzB,8EAA8E;QAC9E,iFAAiF;QACjF,sDAAsD;QACtD,OAAO,KAAK,CAAC;KACd;IAED,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACxB,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAExD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { FormContextType, RJSFSchema, StrictRJSFSchema, UiSchema } from './types';
2
+ /** Checks whether the field described by `schema`, having the `uiSchema` and `formData` supports expanding. The UI for
3
+ * the field can expand if it has additional properties, is not forced as non-expandable by the `uiSchema` and the
4
+ * `formData` object doesn't already have `schema.maxProperties` elements.
5
+ *
6
+ * @param schema - The schema for the field that is being checked
7
+ * @param [uiSchema={}] - The uiSchema for the field
8
+ * @param [formData] - The formData for the field
9
+ * @returns - True if the schema element has additionalProperties, is expandable, and not at the maxProperties limit
10
+ */
11
+ export default function canExpand<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(schema: RJSFSchema, uiSchema?: UiSchema<T, S, F>, formData?: T): boolean;
@@ -0,0 +1,26 @@
1
+ import getUiOptions from './getUiOptions';
2
+ /** Checks whether the field described by `schema`, having the `uiSchema` and `formData` supports expanding. The UI for
3
+ * the field can expand if it has additional properties, is not forced as non-expandable by the `uiSchema` and the
4
+ * `formData` object doesn't already have `schema.maxProperties` elements.
5
+ *
6
+ * @param schema - The schema for the field that is being checked
7
+ * @param [uiSchema={}] - The uiSchema for the field
8
+ * @param [formData] - The formData for the field
9
+ * @returns - True if the schema element has additionalProperties, is expandable, and not at the maxProperties limit
10
+ */
11
+ export default function canExpand(schema, uiSchema = {}, formData) {
12
+ if (!schema.additionalProperties) {
13
+ return false;
14
+ }
15
+ const { expandable = true } = getUiOptions(uiSchema);
16
+ if (expandable === false) {
17
+ return expandable;
18
+ }
19
+ // if ui:options.expandable was not explicitly set to false, we can add
20
+ // another property if we have not exceeded maxProperties yet
21
+ if (schema.maxProperties !== undefined && formData) {
22
+ return Object.keys(formData).length < schema.maxProperties;
23
+ }
24
+ return true;
25
+ }
26
+ //# sourceMappingURL=canExpand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canExpand.js","sourceRoot":"","sources":["../src/canExpand.ts"],"names":[],"mappings":"AACA,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAE1C;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,MAAkB,EAClB,WAA8B,EAAE,EAChC,QAAY;IAEZ,IAAI,CAAC,MAAM,CAAC,oBAAoB,EAAE;QAChC,OAAO,KAAK,CAAC;KACd;IACD,MAAM,EAAE,UAAU,GAAG,IAAI,EAAE,GAAG,YAAY,CAAU,QAAQ,CAAC,CAAC;IAC9D,IAAI,UAAU,KAAK,KAAK,EAAE;QACxB,OAAO,UAAU,CAAC;KACnB;IACD,uEAAuE;IACvE,6DAA6D;IAC7D,IAAI,MAAM,CAAC,aAAa,KAAK,SAAS,IAAI,QAAQ,EAAE;QAClD,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC,aAAa,CAAC;KAC5D;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,31 @@
1
+ /** Below are the list of all the keys into various elements of a RJSFSchema or UiSchema that are used by the various
2
+ * utility functions. In addition to those keys, there are the special `ADDITIONAL_PROPERTY_FLAG` and
3
+ * `RJSF_ADDITONAL_PROPERTIES_FLAG` flags that is added to a schema under certain conditions by the `retrieveSchema()`
4
+ * utility.
5
+ */
6
+ export declare const ADDITIONAL_PROPERTY_FLAG = "__additional_property";
7
+ export declare const ADDITIONAL_PROPERTIES_KEY = "additionalProperties";
8
+ export declare const ALL_OF_KEY = "allOf";
9
+ export declare const ANY_OF_KEY = "anyOf";
10
+ export declare const CONST_KEY = "const";
11
+ export declare const DEFAULT_KEY = "default";
12
+ export declare const DEFINITIONS_KEY = "definitions";
13
+ export declare const DEPENDENCIES_KEY = "dependencies";
14
+ export declare const ENUM_KEY = "enum";
15
+ export declare const ERRORS_KEY = "__errors";
16
+ export declare const ID_KEY = "$id";
17
+ export declare const IF_KEY = "if";
18
+ export declare const ITEMS_KEY = "items";
19
+ export declare const JUNK_OPTION_ID = "_$junk_option_schema_id$_";
20
+ export declare const NAME_KEY = "$name";
21
+ export declare const ONE_OF_KEY = "oneOf";
22
+ export declare const PROPERTIES_KEY = "properties";
23
+ export declare const REQUIRED_KEY = "required";
24
+ export declare const SUBMIT_BTN_OPTIONS_KEY = "submitButtonOptions";
25
+ export declare const REF_KEY = "$ref";
26
+ export declare const RJSF_ADDITONAL_PROPERTIES_FLAG = "__rjsf_additionalProperties";
27
+ export declare const ROOT_SCHEMA_PREFIX = "__rjsf_rootSchema";
28
+ export declare const UI_FIELD_KEY = "ui:field";
29
+ export declare const UI_WIDGET_KEY = "ui:widget";
30
+ export declare const UI_OPTIONS_KEY = "ui:options";
31
+ export declare const UI_GLOBAL_OPTIONS_KEY = "ui:globalOptions";
@@ -0,0 +1,32 @@
1
+ /** Below are the list of all the keys into various elements of a RJSFSchema or UiSchema that are used by the various
2
+ * utility functions. In addition to those keys, there are the special `ADDITIONAL_PROPERTY_FLAG` and
3
+ * `RJSF_ADDITONAL_PROPERTIES_FLAG` flags that is added to a schema under certain conditions by the `retrieveSchema()`
4
+ * utility.
5
+ */
6
+ export const ADDITIONAL_PROPERTY_FLAG = '__additional_property';
7
+ export const ADDITIONAL_PROPERTIES_KEY = 'additionalProperties';
8
+ export const ALL_OF_KEY = 'allOf';
9
+ export const ANY_OF_KEY = 'anyOf';
10
+ export const CONST_KEY = 'const';
11
+ export const DEFAULT_KEY = 'default';
12
+ export const DEFINITIONS_KEY = 'definitions';
13
+ export const DEPENDENCIES_KEY = 'dependencies';
14
+ export const ENUM_KEY = 'enum';
15
+ export const ERRORS_KEY = '__errors';
16
+ export const ID_KEY = '$id';
17
+ export const IF_KEY = 'if';
18
+ export const ITEMS_KEY = 'items';
19
+ export const JUNK_OPTION_ID = '_$junk_option_schema_id$_';
20
+ export const NAME_KEY = '$name';
21
+ export const ONE_OF_KEY = 'oneOf';
22
+ export const PROPERTIES_KEY = 'properties';
23
+ export const REQUIRED_KEY = 'required';
24
+ export const SUBMIT_BTN_OPTIONS_KEY = 'submitButtonOptions';
25
+ export const REF_KEY = '$ref';
26
+ export const RJSF_ADDITONAL_PROPERTIES_FLAG = '__rjsf_additionalProperties';
27
+ export const ROOT_SCHEMA_PREFIX = '__rjsf_rootSchema';
28
+ export const UI_FIELD_KEY = 'ui:field';
29
+ export const UI_WIDGET_KEY = 'ui:widget';
30
+ export const UI_OPTIONS_KEY = 'ui:options';
31
+ export const UI_GLOBAL_OPTIONS_KEY = 'ui:globalOptions';
32
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,uBAAuB,CAAC;AAChE,MAAM,CAAC,MAAM,yBAAyB,GAAG,sBAAsB,CAAC;AAChE,MAAM,CAAC,MAAM,UAAU,GAAG,OAAO,CAAC;AAClC,MAAM,CAAC,MAAM,UAAU,GAAG,OAAO,CAAC;AAClC,MAAM,CAAC,MAAM,SAAS,GAAG,OAAO,CAAC;AACjC,MAAM,CAAC,MAAM,WAAW,GAAG,SAAS,CAAC;AACrC,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAAC;AAC7C,MAAM,CAAC,MAAM,gBAAgB,GAAG,cAAc,CAAC;AAC/C,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC;AAC/B,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAC;AACrC,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,CAAC;AAC5B,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,CAAC;AAC3B,MAAM,CAAC,MAAM,SAAS,GAAG,OAAO,CAAC;AACjC,MAAM,CAAC,MAAM,cAAc,GAAG,2BAA2B,CAAC;AAC1D,MAAM,CAAC,MAAM,QAAQ,GAAG,OAAO,CAAC;AAChC,MAAM,CAAC,MAAM,UAAU,GAAG,OAAO,CAAC;AAClC,MAAM,CAAC,MAAM,cAAc,GAAG,YAAY,CAAC;AAC3C,MAAM,CAAC,MAAM,YAAY,GAAG,UAAU,CAAC;AACvC,MAAM,CAAC,MAAM,sBAAsB,GAAG,qBAAqB,CAAC;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC;AAC9B,MAAM,CAAC,MAAM,8BAA8B,GAAG,6BAA6B,CAAC;AAC5E,MAAM,CAAC,MAAM,kBAAkB,GAAG,mBAAmB,CAAC;AACtD,MAAM,CAAC,MAAM,YAAY,GAAG,UAAU,CAAC;AACvC,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,CAAC;AACzC,MAAM,CAAC,MAAM,cAAc,GAAG,YAAY,CAAC;AAC3C,MAAM,CAAC,MAAM,qBAAqB,GAAG,kBAAkB,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { FormValidation } from './types';
2
+ /** Given a `formData` object, recursively creates a `FormValidation` error handling structure around it
3
+ *
4
+ * @param formData - The form data around which the error handler is created
5
+ * @returns - A `FormValidation` object based on the `formData` structure
6
+ */
7
+ export default function createErrorHandler<T = any>(formData: T): FormValidation<T>;
@@ -0,0 +1,31 @@
1
+ import isPlainObject from 'lodash/isPlainObject';
2
+ import { ERRORS_KEY } from './constants';
3
+ /** Given a `formData` object, recursively creates a `FormValidation` error handling structure around it
4
+ *
5
+ * @param formData - The form data around which the error handler is created
6
+ * @returns - A `FormValidation` object based on the `formData` structure
7
+ */
8
+ export default function createErrorHandler(formData) {
9
+ const handler = {
10
+ // We store the list of errors for this node in a property named __errors
11
+ // to avoid name collision with a possible sub schema field named
12
+ // 'errors' (see `utils.toErrorSchema`).
13
+ [ERRORS_KEY]: [],
14
+ addError(message) {
15
+ this[ERRORS_KEY].push(message);
16
+ },
17
+ };
18
+ if (Array.isArray(formData)) {
19
+ return formData.reduce((acc, value, key) => {
20
+ return Object.assign(Object.assign({}, acc), { [key]: createErrorHandler(value) });
21
+ }, handler);
22
+ }
23
+ if (isPlainObject(formData)) {
24
+ const formObject = formData;
25
+ return Object.keys(formObject).reduce((acc, key) => {
26
+ return Object.assign(Object.assign({}, acc), { [key]: createErrorHandler(formObject[key]) });
27
+ }, handler);
28
+ }
29
+ return handler;
30
+ }
31
+ //# sourceMappingURL=createErrorHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createErrorHandler.js","sourceRoot":"","sources":["../src/createErrorHandler.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAU,QAAW;IAC7D,MAAM,OAAO,GAAoB;QAC/B,yEAAyE;QACzE,iEAAiE;QACjE,wCAAwC;QACxC,CAAC,UAAU,CAAC,EAAE,EAAE;QAChB,QAAQ,CAAC,OAAe;YACtB,IAAI,CAAC,UAAU,CAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;KACF,CAAC;IACF,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QAC3B,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;YACzC,uCAAY,GAAG,KAAE,CAAC,GAAG,CAAC,EAAE,kBAAkB,CAAC,KAAK,CAAC,IAAG;QACtD,CAAC,EAAE,OAAO,CAAC,CAAC;KACb;IACD,IAAI,aAAa,CAAC,QAAQ,CAAC,EAAE;QAC3B,MAAM,UAAU,GAAsB,QAA6B,CAAC;QACpE,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACjD,uCAAY,GAAG,KAAE,CAAC,GAAG,CAAC,EAAE,kBAAkB,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,IAAG;QAChE,CAAC,EAAE,OAA4B,CAAC,CAAC;KAClC;IACD,OAAO,OAA4B,CAAC;AACtC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { FormContextType, RJSFSchema, SchemaUtilsType, StrictRJSFSchema, ValidatorType } from './types';
2
+ /** Creates a `SchemaUtilsType` interface that is based around the given `validator` and `rootSchema` parameters. The
3
+ * resulting interface implementation will forward the `validator` and `rootSchema` to all the wrapped APIs.
4
+ *
5
+ * @param validator - an implementation of the `ValidatorType` interface that will be forwarded to all the APIs
6
+ * @param rootSchema - The root schema that will be forwarded to all the APIs
7
+ * @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
8
+ * @returns - An implementation of a `SchemaUtilsType` interface
9
+ */
10
+ export default function createSchemaUtils<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, rootSchema: S, experimental_defaultFormStateBehavior?: {}): SchemaUtilsType<T, S, F>;
@@ -0,0 +1,207 @@
1
+ import deepEquals from './deepEquals';
2
+ import { getDefaultFormState, getDisplayLabel, getClosestMatchingOption, getFirstMatchingOption, getMatchingOption, isFilesArray, isMultiSelect, isSelect, mergeValidationData, retrieveSchema, sanitizeDataForNewSchema, toIdSchema, toPathSchema, } from './schema';
3
+ /** The `SchemaUtils` class provides a wrapper around the publicly exported APIs in the `utils/schema` directory such
4
+ * that one does not have to explicitly pass the `validator`, `rootSchema`, or `experimental_defaultFormStateBehavior` to each method.
5
+ * Since these generally do not change across a `Form`, this allows for providing a simplified set of APIs to the
6
+ * `@rjsf/core` components and the various themes as well. This class implements the `SchemaUtilsType` interface.
7
+ */
8
+ class SchemaUtils {
9
+ /** Constructs the `SchemaUtils` instance with the given `validator` and `rootSchema` stored as instance variables
10
+ *
11
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
12
+ * @param rootSchema - The root schema that will be forwarded to all the APIs
13
+ * @param experimental_defaultFormStateBehavior - Configuration flags to allow users to override default form state behavior
14
+ */
15
+ constructor(validator, rootSchema, experimental_defaultFormStateBehavior) {
16
+ this.rootSchema = rootSchema;
17
+ this.validator = validator;
18
+ this.experimental_defaultFormStateBehavior = experimental_defaultFormStateBehavior;
19
+ }
20
+ /** Returns the `ValidatorType` in the `SchemaUtilsType`
21
+ *
22
+ * @returns - The `ValidatorType`
23
+ */
24
+ getValidator() {
25
+ return this.validator;
26
+ }
27
+ /** Determines whether either the `validator` and `rootSchema` differ from the ones associated with this instance of
28
+ * the `SchemaUtilsType`. If either `validator` or `rootSchema` are falsy, then return false to prevent the creation
29
+ * of a new `SchemaUtilsType` with incomplete properties.
30
+ *
31
+ * @param validator - An implementation of the `ValidatorType` interface that will be compared against the current one
32
+ * @param rootSchema - The root schema that will be compared against the current one
33
+ * @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
34
+ * @returns - True if the `SchemaUtilsType` differs from the given `validator` or `rootSchema`
35
+ */
36
+ doesSchemaUtilsDiffer(validator, rootSchema, experimental_defaultFormStateBehavior = {}) {
37
+ if (!validator || !rootSchema) {
38
+ return false;
39
+ }
40
+ return (this.validator !== validator ||
41
+ !deepEquals(this.rootSchema, rootSchema) ||
42
+ !deepEquals(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior));
43
+ }
44
+ /** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
45
+ * computed to have defaults provided in the `schema`.
46
+ *
47
+ * @param schema - The schema for which the default state is desired
48
+ * @param [formData] - The current formData, if any, onto which to provide any missing defaults
49
+ * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
50
+ * If "excludeObjectChildren", pass `includeUndefinedValues` as false when computing defaults for any nested
51
+ * object properties.
52
+ * @returns - The resulting `formData` with all the defaults provided
53
+ */
54
+ getDefaultFormState(schema, formData, includeUndefinedValues = false) {
55
+ return getDefaultFormState(this.validator, schema, formData, this.rootSchema, includeUndefinedValues, this.experimental_defaultFormStateBehavior);
56
+ }
57
+ /** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
58
+ * should be displayed in a UI.
59
+ *
60
+ * @param schema - The schema for which the display label flag is desired
61
+ * @param [uiSchema] - The UI schema from which to derive potentially displayable information
62
+ * @param [globalOptions={}] - The optional Global UI Schema from which to get any fallback `xxx` options
63
+ * @returns - True if the label should be displayed or false if it should not
64
+ */
65
+ getDisplayLabel(schema, uiSchema, globalOptions) {
66
+ return getDisplayLabel(this.validator, schema, uiSchema, this.rootSchema, globalOptions);
67
+ }
68
+ /** Determines which of the given `options` provided most closely matches the `formData`.
69
+ * Returns the index of the option that is valid and is the closest match, or 0 if there is no match.
70
+ *
71
+ * The closest match is determined using the number of matching properties, and more heavily favors options with
72
+ * matching readOnly, default, or const values.
73
+ *
74
+ * @param formData - The form data associated with the schema
75
+ * @param options - The list of options that can be selected from
76
+ * @param [selectedOption] - The index of the currently selected option, defaulted to -1 if not specified
77
+ * @param [discriminatorField] - The optional name of the field within the options object whose value is used to
78
+ * determine which option is selected
79
+ * @returns - The index of the option that is the closest match to the `formData` or the `selectedOption` if no match
80
+ */
81
+ getClosestMatchingOption(formData, options, selectedOption, discriminatorField) {
82
+ return getClosestMatchingOption(this.validator, this.rootSchema, formData, options, selectedOption, discriminatorField);
83
+ }
84
+ /** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
85
+ * Always returns the first option if there is nothing that matches.
86
+ *
87
+ * @param formData - The current formData, if any, used to figure out a match
88
+ * @param options - The list of options to find a matching options from
89
+ * @param [discriminatorField] - The optional name of the field within the options object whose value is used to
90
+ * determine which option is selected
91
+ * @returns - The firstindex of the matched option or 0 if none is available
92
+ */
93
+ getFirstMatchingOption(formData, options, discriminatorField) {
94
+ return getFirstMatchingOption(this.validator, formData, options, this.rootSchema, discriminatorField);
95
+ }
96
+ /** Given the `formData` and list of `options`, attempts to find the index of the option that best matches the data.
97
+ * Deprecated, use `getFirstMatchingOption()` instead.
98
+ *
99
+ * @param formData - The current formData, if any, onto which to provide any missing defaults
100
+ * @param options - The list of options to find a matching options from
101
+ * @param [discriminatorField] - The optional name of the field within the options object whose value is used to
102
+ * determine which option is selected
103
+ * @returns - The index of the matched option or 0 if none is available
104
+ * @deprecated
105
+ */
106
+ getMatchingOption(formData, options, discriminatorField) {
107
+ return getMatchingOption(this.validator, formData, options, this.rootSchema, discriminatorField);
108
+ }
109
+ /** Checks to see if the `schema` and `uiSchema` combination represents an array of files
110
+ *
111
+ * @param schema - The schema for which check for array of files flag is desired
112
+ * @param [uiSchema] - The UI schema from which to check the widget
113
+ * @returns - True if schema/uiSchema contains an array of files, otherwise false
114
+ */
115
+ isFilesArray(schema, uiSchema) {
116
+ return isFilesArray(this.validator, schema, uiSchema, this.rootSchema);
117
+ }
118
+ /** Checks to see if the `schema` combination represents a multi-select
119
+ *
120
+ * @param schema - The schema for which check for a multi-select flag is desired
121
+ * @returns - True if schema contains a multi-select, otherwise false
122
+ */
123
+ isMultiSelect(schema) {
124
+ return isMultiSelect(this.validator, schema, this.rootSchema);
125
+ }
126
+ /** Checks to see if the `schema` combination represents a select
127
+ *
128
+ * @param schema - The schema for which check for a select flag is desired
129
+ * @returns - True if schema contains a select, otherwise false
130
+ */
131
+ isSelect(schema) {
132
+ return isSelect(this.validator, schema, this.rootSchema);
133
+ }
134
+ /** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in
135
+ * the two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
136
+ * `getValidator().toErrorList()` onto the `errors` in the `validationData`. If no `additionalErrorSchema` is passed,
137
+ * then `validationData` is returned.
138
+ *
139
+ * @param validationData - The current `ValidationData` into which to merge the additional errors
140
+ * @param [additionalErrorSchema] - The additional set of errors
141
+ * @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
142
+ * @deprecated - Use the `validationDataMerge()` function exported from `@rjsf/utils` instead. This function will be
143
+ * removed in the next major release.
144
+ */
145
+ mergeValidationData(validationData, additionalErrorSchema) {
146
+ return mergeValidationData(this.validator, validationData, additionalErrorSchema);
147
+ }
148
+ /** Retrieves an expanded schema that has had all of its conditions, additional properties, references and
149
+ * dependencies resolved and merged into the `schema` given a `rawFormData` that is used to do the potentially
150
+ * recursive resolution.
151
+ *
152
+ * @param schema - The schema for which retrieving a schema is desired
153
+ * @param [rawFormData] - The current formData, if any, to assist retrieving a schema
154
+ * @returns - The schema having its conditions, additional properties, references and dependencies resolved
155
+ */
156
+ retrieveSchema(schema, rawFormData) {
157
+ return retrieveSchema(this.validator, schema, this.rootSchema, rawFormData);
158
+ }
159
+ /** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the
160
+ * new schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the
161
+ * nature of schemas, this sanitization happens recursively for nested objects of data. Also, any properties in the
162
+ * old schemas that are non-existent in the new schema are set to `undefined`.
163
+ *
164
+ * @param [newSchema] - The new schema for which the data is being sanitized
165
+ * @param [oldSchema] - The old schema from which the data originated
166
+ * @param [data={}] - The form data associated with the schema, defaulting to an empty object when undefined
167
+ * @returns - The new form data, with all the fields uniquely associated with the old schema set
168
+ * to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
169
+ */
170
+ sanitizeDataForNewSchema(newSchema, oldSchema, data) {
171
+ return sanitizeDataForNewSchema(this.validator, this.rootSchema, newSchema, oldSchema, data);
172
+ }
173
+ /** Generates an `IdSchema` object for the `schema`, recursively
174
+ *
175
+ * @param schema - The schema for which the display label flag is desired
176
+ * @param [id] - The base id for the schema
177
+ * @param [formData] - The current formData, if any, onto which to provide any missing defaults
178
+ * @param [idPrefix='root'] - The prefix to use for the id
179
+ * @param [idSeparator='_'] - The separator to use for the path segments in the id
180
+ * @returns - The `IdSchema` object for the `schema`
181
+ */
182
+ toIdSchema(schema, id, formData, idPrefix = 'root', idSeparator = '_') {
183
+ return toIdSchema(this.validator, schema, id, this.rootSchema, formData, idPrefix, idSeparator);
184
+ }
185
+ /** Generates an `PathSchema` object for the `schema`, recursively
186
+ *
187
+ * @param schema - The schema for which the display label flag is desired
188
+ * @param [name] - The base name for the schema
189
+ * @param [formData] - The current formData, if any, onto which to provide any missing defaults
190
+ * @returns - The `PathSchema` object for the `schema`
191
+ */
192
+ toPathSchema(schema, name, formData) {
193
+ return toPathSchema(this.validator, schema, name, this.rootSchema, formData);
194
+ }
195
+ }
196
+ /** Creates a `SchemaUtilsType` interface that is based around the given `validator` and `rootSchema` parameters. The
197
+ * resulting interface implementation will forward the `validator` and `rootSchema` to all the wrapped APIs.
198
+ *
199
+ * @param validator - an implementation of the `ValidatorType` interface that will be forwarded to all the APIs
200
+ * @param rootSchema - The root schema that will be forwarded to all the APIs
201
+ * @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
202
+ * @returns - An implementation of a `SchemaUtilsType` interface
203
+ */
204
+ export default function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior = {}) {
205
+ return new SchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior);
206
+ }
207
+ //# sourceMappingURL=createSchemaUtils.js.map