@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,41 @@
1
+ import rangeSpec from './rangeSpec';
2
+ /** Using the `schema`, `defaultType` and `options`, extract out the props for the <input> element that make sense.
3
+ *
4
+ * @param schema - The schema for the field provided by the widget
5
+ * @param [defaultType] - The default type, if any, for the field provided by the widget
6
+ * @param [options={}] - The UI Options for the field provided by the widget
7
+ * @param [autoDefaultStepAny=true] - Determines whether to auto-default step=any when the type is number and no step
8
+ * @returns - The extracted `InputPropsType` object
9
+ */
10
+ export default function getInputProps(schema, defaultType, options = {}, autoDefaultStepAny = true) {
11
+ const inputProps = Object.assign({ type: defaultType || 'text' }, rangeSpec(schema));
12
+ // If options.inputType is set use that as the input type
13
+ if (options.inputType) {
14
+ inputProps.type = options.inputType;
15
+ }
16
+ else if (!defaultType) {
17
+ // If the schema is of type number or integer, set the input type to number
18
+ if (schema.type === 'number') {
19
+ inputProps.type = 'number';
20
+ // Only add step if one isn't already defined and we are auto-defaulting the "any" step
21
+ if (autoDefaultStepAny && inputProps.step === undefined) {
22
+ // Setting step to 'any' fixes a bug in Safari where decimals are not
23
+ // allowed in number inputs
24
+ inputProps.step = 'any';
25
+ }
26
+ }
27
+ else if (schema.type === 'integer') {
28
+ inputProps.type = 'number';
29
+ // Only add step if one isn't already defined
30
+ if (inputProps.step === undefined) {
31
+ // Since this is integer, you always want to step up or down in multiples of 1
32
+ inputProps.step = 1;
33
+ }
34
+ }
35
+ }
36
+ if (options.autocomplete) {
37
+ inputProps.autoComplete = options.autocomplete;
38
+ }
39
+ return inputProps;
40
+ }
41
+ //# sourceMappingURL=getInputProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getInputProps.js","sourceRoot":"","sources":["../src/getInputProps.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,aAAa,CAAC;AAGpC;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CAKnC,MAAkB,EAClB,WAAoB,EACpB,UAAkC,EAAE,EACpC,kBAAkB,GAAG,IAAI;IAEzB,MAAM,UAAU,mBACd,IAAI,EAAE,WAAW,IAAI,MAAM,IACxB,SAAS,CAAC,MAAM,CAAC,CACrB,CAAC;IAEF,yDAAyD;IACzD,IAAI,OAAO,CAAC,SAAS,EAAE;QACrB,UAAU,CAAC,IAAI,GAAG,OAAO,CAAC,SAAS,CAAC;KACrC;SAAM,IAAI,CAAC,WAAW,EAAE;QACvB,2EAA2E;QAC3E,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE;YAC5B,UAAU,CAAC,IAAI,GAAG,QAAQ,CAAC;YAC3B,uFAAuF;YACvF,IAAI,kBAAkB,IAAI,UAAU,CAAC,IAAI,KAAK,SAAS,EAAE;gBACvD,qEAAqE;gBACrE,2BAA2B;gBAC3B,UAAU,CAAC,IAAI,GAAG,KAAK,CAAC;aACzB;SACF;aAAM,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE;YACpC,UAAU,CAAC,IAAI,GAAG,QAAQ,CAAC;YAC3B,6CAA6C;YAC7C,IAAI,UAAU,CAAC,IAAI,KAAK,SAAS,EAAE;gBACjC,8EAA8E;gBAC9E,UAAU,CAAC,IAAI,GAAG,CAAC,CAAC;aACrB;SACF;KACF;IAED,IAAI,OAAO,CAAC,YAAY,EAAE;QACxB,UAAU,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;KAChD;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { RJSFSchema, StrictRJSFSchema } from './types';
2
+ /** Gets the type of a given `schema`. If the type is not explicitly defined, then an attempt is made to infer it from
3
+ * other elements of the schema as follows:
4
+ * - schema.const: Returns the `guessType()` of that value
5
+ * - schema.enum: Returns `string`
6
+ * - schema.properties: Returns `object`
7
+ * - schema.additionalProperties: Returns `object`
8
+ * - type is an array with a length of 2 and one type is 'null': Returns the other type
9
+ *
10
+ * @param schema - The schema for which to get the type
11
+ * @returns - The type of the schema
12
+ */
13
+ export default function getSchemaType<S extends StrictRJSFSchema = RJSFSchema>(schema: S): string | string[] | undefined;
@@ -0,0 +1,29 @@
1
+ import guessType from './guessType';
2
+ /** Gets the type of a given `schema`. If the type is not explicitly defined, then an attempt is made to infer it from
3
+ * other elements of the schema as follows:
4
+ * - schema.const: Returns the `guessType()` of that value
5
+ * - schema.enum: Returns `string`
6
+ * - schema.properties: Returns `object`
7
+ * - schema.additionalProperties: Returns `object`
8
+ * - type is an array with a length of 2 and one type is 'null': Returns the other type
9
+ *
10
+ * @param schema - The schema for which to get the type
11
+ * @returns - The type of the schema
12
+ */
13
+ export default function getSchemaType(schema) {
14
+ let { type } = schema;
15
+ if (!type && schema.const) {
16
+ return guessType(schema.const);
17
+ }
18
+ if (!type && schema.enum) {
19
+ return 'string';
20
+ }
21
+ if (!type && (schema.properties || schema.additionalProperties)) {
22
+ return 'object';
23
+ }
24
+ if (Array.isArray(type) && type.length === 2 && type.includes('null')) {
25
+ type = type.find((type) => type !== 'null');
26
+ }
27
+ return type;
28
+ }
29
+ //# sourceMappingURL=getSchemaType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSchemaType.js","sourceRoot":"","sources":["../src/getSchemaType.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,aAAa,CAAC;AAGpC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CACnC,MAAS;IAET,IAAI,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IAEtB,IAAI,CAAC,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE;QACzB,OAAO,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;KAChC;IAED,IAAI,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,EAAE;QACxB,OAAO,QAAQ,CAAC;KACjB;IAED,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,oBAAoB,CAAC,EAAE;QAC/D,OAAO,QAAQ,CAAC;KACjB;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QACrE,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC;KAC7C;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { FormContextType, RJSFSchema, StrictRJSFSchema, UiSchema, UISchemaSubmitButtonOptions } from './types';
2
+ /** The default submit button options, exported for testing purposes
3
+ */
4
+ export declare const DEFAULT_OPTIONS: UISchemaSubmitButtonOptions;
5
+ /** Extracts any `ui:submitButtonOptions` from the `uiSchema` and merges them onto the `DEFAULT_OPTIONS`
6
+ *
7
+ * @param [uiSchema={}] - the UI Schema from which to extract submit button props
8
+ * @returns - The merging of the `DEFAULT_OPTIONS` with any custom ones
9
+ */
10
+ export default function getSubmitButtonOptions<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(uiSchema?: UiSchema<T, S, F>): UISchemaSubmitButtonOptions;
@@ -0,0 +1,25 @@
1
+ import { SUBMIT_BTN_OPTIONS_KEY } from './constants';
2
+ import getUiOptions from './getUiOptions';
3
+ /** The default submit button options, exported for testing purposes
4
+ */
5
+ export const DEFAULT_OPTIONS = {
6
+ props: {
7
+ disabled: false,
8
+ },
9
+ submitText: 'Submit',
10
+ norender: false,
11
+ };
12
+ /** Extracts any `ui:submitButtonOptions` from the `uiSchema` and merges them onto the `DEFAULT_OPTIONS`
13
+ *
14
+ * @param [uiSchema={}] - the UI Schema from which to extract submit button props
15
+ * @returns - The merging of the `DEFAULT_OPTIONS` with any custom ones
16
+ */
17
+ export default function getSubmitButtonOptions(uiSchema = {}) {
18
+ const uiOptions = getUiOptions(uiSchema);
19
+ if (uiOptions && uiOptions[SUBMIT_BTN_OPTIONS_KEY]) {
20
+ const options = uiOptions[SUBMIT_BTN_OPTIONS_KEY];
21
+ return Object.assign(Object.assign({}, DEFAULT_OPTIONS), options);
22
+ }
23
+ return DEFAULT_OPTIONS;
24
+ }
25
+ //# sourceMappingURL=getSubmitButtonOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSubmitButtonOptions.js","sourceRoot":"","sources":["../src/getSubmitButtonOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAG1C;GACG;AACH,MAAM,CAAC,MAAM,eAAe,GAAgC;IAC1D,KAAK,EAAE;QACL,QAAQ,EAAE,KAAK;KAChB;IACD,UAAU,EAAE,QAAQ;IACpB,QAAQ,EAAE,KAAK;CAChB,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAI5C,WAA8B,EAAE;IAChC,MAAM,SAAS,GAAG,YAAY,CAAU,QAAQ,CAAC,CAAC;IAClD,IAAI,SAAS,IAAI,SAAS,CAAC,sBAAsB,CAAC,EAAE;QAClD,MAAM,OAAO,GAAG,SAAS,CAAC,sBAAsB,CAAgC,CAAC;QACjF,uCAAY,eAAe,GAAK,OAAO,EAAG;KAC3C;IAED,OAAO,eAAe,CAAC;AACzB,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { FormContextType, TemplatesType, Registry, UIOptionsType, StrictRJSFSchema, RJSFSchema } from './types';
2
+ /** Returns the template with the given `name` from either the `uiSchema` if it is defined or from the `registry`
3
+ * otherwise. NOTE, since `ButtonTemplates` are not overridden in `uiSchema` only those in the `registry` are returned.
4
+ *
5
+ * @param name - The name of the template to fetch, restricted to the keys of `TemplatesType`
6
+ * @param registry - The `Registry` from which to read the template
7
+ * @param [uiOptions={}] - The `UIOptionsType` from which to read an alternate template
8
+ * @returns - The template from either the `uiSchema` or `registry` for the `name`
9
+ */
10
+ export default function getTemplate<Name extends keyof TemplatesType<T, S, F>, T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(name: Name, registry: Registry<T, S, F>, uiOptions?: UIOptionsType<T, S, F>): TemplatesType<T, S, F>[Name];
@@ -0,0 +1,19 @@
1
+ /** Returns the template with the given `name` from either the `uiSchema` if it is defined or from the `registry`
2
+ * otherwise. NOTE, since `ButtonTemplates` are not overridden in `uiSchema` only those in the `registry` are returned.
3
+ *
4
+ * @param name - The name of the template to fetch, restricted to the keys of `TemplatesType`
5
+ * @param registry - The `Registry` from which to read the template
6
+ * @param [uiOptions={}] - The `UIOptionsType` from which to read an alternate template
7
+ * @returns - The template from either the `uiSchema` or `registry` for the `name`
8
+ */
9
+ export default function getTemplate(name, registry, uiOptions = {}) {
10
+ const { templates } = registry;
11
+ if (name === 'ButtonTemplates') {
12
+ return templates[name];
13
+ }
14
+ return (
15
+ // Evaluating uiOptions[name] results in TS2590: Expression produces a union type that is too complex to represent
16
+ // To avoid that, we cast uiOptions to `any` before accessing the name field
17
+ uiOptions[name] || templates[name]);
18
+ }
19
+ //# sourceMappingURL=getTemplate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getTemplate.js","sourceRoot":"","sources":["../src/getTemplate.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW,CAKjC,IAAU,EAAE,QAA2B,EAAE,YAAoC,EAAE;IAC/E,MAAM,EAAE,SAAS,EAAE,GAAG,QAAQ,CAAC;IAC/B,IAAI,IAAI,KAAK,iBAAiB,EAAE;QAC9B,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;KACxB;IACD,OAAO;IACL,kHAAkH;IAClH,4EAA4E;IAC1E,SAAiB,CAAC,IAAI,CAAkC,IAAI,SAAS,CAAC,IAAI,CAAC,CAC9E,CAAC;AACJ,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { FormContextType, GlobalUISchemaOptions, RJSFSchema, StrictRJSFSchema, UIOptionsType, UiSchema } from './types';
2
+ /** Get all passed options from ui:options, and ui:<optionName>, returning them in an object with the `ui:`
3
+ * stripped off. Any `globalOptions` will always be returned, unless they are overridden by options in the `uiSchema`.
4
+ *
5
+ * @param [uiSchema={}] - The UI Schema from which to get any `ui:xxx` options
6
+ * @param [globalOptions={}] - The optional Global UI Schema from which to get any fallback `xxx` options
7
+ * @returns - An object containing all the `ui:xxx` options with the `ui:` stripped off along with all `globalOptions`
8
+ */
9
+ export default function getUiOptions<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(uiSchema?: UiSchema<T, S, F>, globalOptions?: GlobalUISchemaOptions): UIOptionsType<T, S, F>;
@@ -0,0 +1,25 @@
1
+ import { UI_OPTIONS_KEY, UI_WIDGET_KEY } from './constants';
2
+ import isObject from './isObject';
3
+ /** Get all passed options from ui:options, and ui:<optionName>, returning them in an object with the `ui:`
4
+ * stripped off. Any `globalOptions` will always be returned, unless they are overridden by options in the `uiSchema`.
5
+ *
6
+ * @param [uiSchema={}] - The UI Schema from which to get any `ui:xxx` options
7
+ * @param [globalOptions={}] - The optional Global UI Schema from which to get any fallback `xxx` options
8
+ * @returns - An object containing all the `ui:xxx` options with the `ui:` stripped off along with all `globalOptions`
9
+ */
10
+ export default function getUiOptions(uiSchema = {}, globalOptions = {}) {
11
+ return Object.keys(uiSchema)
12
+ .filter((key) => key.indexOf('ui:') === 0)
13
+ .reduce((options, key) => {
14
+ const value = uiSchema[key];
15
+ if (key === UI_WIDGET_KEY && isObject(value)) {
16
+ console.error('Setting options via ui:widget object is no longer supported, use ui:options instead');
17
+ return options;
18
+ }
19
+ if (key === UI_OPTIONS_KEY && isObject(value)) {
20
+ return Object.assign(Object.assign({}, options), value);
21
+ }
22
+ return Object.assign(Object.assign({}, options), { [key.substring(3)]: value });
23
+ }, Object.assign({}, globalOptions));
24
+ }
25
+ //# sourceMappingURL=getUiOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getUiOptions.js","sourceRoot":"","sources":["../src/getUiOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,QAAQ,MAAM,YAAY,CAAC;AAGlC;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,WAA8B,EAAE,EAChC,gBAAuC,EAAE;IAEzC,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;SACzB,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;SACzC,MAAM,CACL,CAAC,OAAO,EAAE,GAAG,EAAE,EAAE;QACf,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;QAC5B,IAAI,GAAG,KAAK,aAAa,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE;YAC5C,OAAO,CAAC,KAAK,CAAC,qFAAqF,CAAC,CAAC;YACrG,OAAO,OAAO,CAAC;SAChB;QACD,IAAI,GAAG,KAAK,cAAc,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE;YAC7C,uCAAY,OAAO,GAAK,KAAK,EAAG;SACjC;QACD,uCAAY,OAAO,KAAE,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,IAAG;IACnD,CAAC,oBACI,aAAa,EACnB,CAAC;AACN,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { FormContextType, RJSFSchema, Widget, RegistryWidgetsType, StrictRJSFSchema } from './types';
2
+ /** Given a schema representing a field to render and either the name or actual `Widget` implementation, returns the
3
+ * React component that is used to render the widget. If the `widget` is already a React component, then it is wrapped
4
+ * with a `MergedWidget`. Otherwise an attempt is made to look up the widget inside of the `registeredWidgets` map based
5
+ * on the schema type and `widget` name. If no widget component can be found an `Error` is thrown.
6
+ *
7
+ * @param schema - The schema for the field
8
+ * @param [widget] - Either the name of the widget OR a `Widget` implementation to use
9
+ * @param [registeredWidgets={}] - A registry of widget name to `Widget` implementation
10
+ * @returns - The `Widget` component to use
11
+ * @throws - An error if there is no `Widget` component that can be returned
12
+ */
13
+ export default function getWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(schema: RJSFSchema, widget?: Widget<T, S, F> | string, registeredWidgets?: RegistryWidgetsType<T, S, F>): Widget<T, S, F>;
@@ -0,0 +1,118 @@
1
+ import { __rest } from "tslib";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { createElement } from 'react';
4
+ import ReactIs from 'react-is';
5
+ import get from 'lodash/get';
6
+ import set from 'lodash/set';
7
+ import getSchemaType from './getSchemaType';
8
+ /** The map of schema types to widget type to widget name
9
+ */
10
+ const widgetMap = {
11
+ boolean: {
12
+ checkbox: 'CheckboxWidget',
13
+ radio: 'RadioWidget',
14
+ select: 'SelectWidget',
15
+ hidden: 'HiddenWidget',
16
+ },
17
+ string: {
18
+ text: 'TextWidget',
19
+ password: 'PasswordWidget',
20
+ email: 'EmailWidget',
21
+ hostname: 'TextWidget',
22
+ ipv4: 'TextWidget',
23
+ ipv6: 'TextWidget',
24
+ uri: 'URLWidget',
25
+ 'data-url': 'FileWidget',
26
+ radio: 'RadioWidget',
27
+ select: 'SelectWidget',
28
+ textarea: 'TextareaWidget',
29
+ hidden: 'HiddenWidget',
30
+ date: 'DateWidget',
31
+ datetime: 'DateTimeWidget',
32
+ 'date-time': 'DateTimeWidget',
33
+ 'alt-date': 'AltDateWidget',
34
+ 'alt-datetime': 'AltDateTimeWidget',
35
+ time: 'TimeWidget',
36
+ color: 'ColorWidget',
37
+ file: 'FileWidget',
38
+ },
39
+ number: {
40
+ text: 'TextWidget',
41
+ select: 'SelectWidget',
42
+ updown: 'UpDownWidget',
43
+ range: 'RangeWidget',
44
+ radio: 'RadioWidget',
45
+ hidden: 'HiddenWidget',
46
+ },
47
+ integer: {
48
+ text: 'TextWidget',
49
+ select: 'SelectWidget',
50
+ updown: 'UpDownWidget',
51
+ range: 'RangeWidget',
52
+ radio: 'RadioWidget',
53
+ hidden: 'HiddenWidget',
54
+ },
55
+ array: {
56
+ select: 'SelectWidget',
57
+ checkboxes: 'CheckboxesWidget',
58
+ files: 'FileWidget',
59
+ hidden: 'HiddenWidget',
60
+ },
61
+ };
62
+ /** Wraps the given widget with stateless functional component that will merge any `defaultProps.options` with the
63
+ * `options` that are provided in the props. It will add the wrapper component as a `MergedWidget` property onto the
64
+ * `Widget` so that future attempts to wrap `AWidget` will return the already existing wrapper.
65
+ *
66
+ * @param AWidget - A widget that will be wrapped or one that is already wrapped
67
+ * @returns - The wrapper widget
68
+ */
69
+ function mergeWidgetOptions(AWidget) {
70
+ let MergedWidget = get(AWidget, 'MergedWidget');
71
+ // cache return value as property of widget for proper react reconciliation
72
+ if (!MergedWidget) {
73
+ const defaultOptions = (AWidget.defaultProps && AWidget.defaultProps.options) || {};
74
+ MergedWidget = (_a) => {
75
+ var { options } = _a, props = __rest(_a, ["options"]);
76
+ return _jsx(AWidget, Object.assign({ options: Object.assign(Object.assign({}, defaultOptions), options) }, props));
77
+ };
78
+ set(AWidget, 'MergedWidget', MergedWidget);
79
+ }
80
+ return MergedWidget;
81
+ }
82
+ /** Given a schema representing a field to render and either the name or actual `Widget` implementation, returns the
83
+ * React component that is used to render the widget. If the `widget` is already a React component, then it is wrapped
84
+ * with a `MergedWidget`. Otherwise an attempt is made to look up the widget inside of the `registeredWidgets` map based
85
+ * on the schema type and `widget` name. If no widget component can be found an `Error` is thrown.
86
+ *
87
+ * @param schema - The schema for the field
88
+ * @param [widget] - Either the name of the widget OR a `Widget` implementation to use
89
+ * @param [registeredWidgets={}] - A registry of widget name to `Widget` implementation
90
+ * @returns - The `Widget` component to use
91
+ * @throws - An error if there is no `Widget` component that can be returned
92
+ */
93
+ export default function getWidget(schema, widget, registeredWidgets = {}) {
94
+ const type = getSchemaType(schema);
95
+ if (typeof widget === 'function' ||
96
+ (widget && ReactIs.isForwardRef(createElement(widget))) ||
97
+ ReactIs.isMemo(widget)) {
98
+ return mergeWidgetOptions(widget);
99
+ }
100
+ if (typeof widget !== 'string') {
101
+ throw new Error(`Unsupported widget definition: ${typeof widget}`);
102
+ }
103
+ if (widget in registeredWidgets) {
104
+ const registeredWidget = registeredWidgets[widget];
105
+ return getWidget(schema, registeredWidget, registeredWidgets);
106
+ }
107
+ if (typeof type === 'string') {
108
+ if (!(type in widgetMap)) {
109
+ throw new Error(`No widget for type '${type}'`);
110
+ }
111
+ if (widget in widgetMap[type]) {
112
+ const registeredWidget = registeredWidgets[widgetMap[type][widget]];
113
+ return getWidget(schema, registeredWidget, registeredWidgets);
114
+ }
115
+ }
116
+ throw new Error(`No widget '${widget}' for type '${type}'`);
117
+ }
118
+ //# sourceMappingURL=getWidget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getWidget.js","sourceRoot":"","sources":["../src/getWidget.tsx"],"names":[],"mappings":"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"}
@@ -0,0 +1,7 @@
1
+ /** Given a specific `value` attempts to guess the type of a schema element. In the case where we have to implicitly
2
+ * create a schema, it is useful to know what type to use based on the data we are defining.
3
+ *
4
+ * @param value - The value from which to guess the type
5
+ * @returns - The best guess for the object type
6
+ */
7
+ export default function guessType(value: any): "object" | "string" | "number" | "boolean" | "array" | "null";
@@ -0,0 +1,29 @@
1
+ /** Given a specific `value` attempts to guess the type of a schema element. In the case where we have to implicitly
2
+ * create a schema, it is useful to know what type to use based on the data we are defining.
3
+ *
4
+ * @param value - The value from which to guess the type
5
+ * @returns - The best guess for the object type
6
+ */
7
+ export default function guessType(value) {
8
+ if (Array.isArray(value)) {
9
+ return 'array';
10
+ }
11
+ if (typeof value === 'string') {
12
+ return 'string';
13
+ }
14
+ if (value == null) {
15
+ return 'null';
16
+ }
17
+ if (typeof value === 'boolean') {
18
+ return 'boolean';
19
+ }
20
+ if (!isNaN(value)) {
21
+ return 'number';
22
+ }
23
+ if (typeof value === 'object') {
24
+ return 'object';
25
+ }
26
+ // Default to string if we can't figure it out
27
+ return 'string';
28
+ }
29
+ //# sourceMappingURL=guessType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guessType.js","sourceRoot":"","sources":["../src/guessType.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,KAAU;IAC1C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACxB,OAAO,OAAO,CAAC;KAChB;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,OAAO,QAAQ,CAAC;KACjB;IACD,IAAI,KAAK,IAAI,IAAI,EAAE;QACjB,OAAO,MAAM,CAAC;KACf;IACD,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE;QAC9B,OAAO,SAAS,CAAC;KAClB;IACD,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;QACjB,OAAO,QAAQ,CAAC;KACjB;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,OAAO,QAAQ,CAAC;KACjB;IACD,8CAA8C;IAC9C,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { FormContextType, RegistryWidgetsType, RJSFSchema, StrictRJSFSchema, Widget } from './types';
2
+ /** Detects whether the `widget` exists for the `schema` with the associated `registryWidgets` and returns true if it
3
+ * does, or false if it doesn't.
4
+ *
5
+ * @param schema - The schema for the field
6
+ * @param widget - Either the name of the widget OR a `Widget` implementation to use
7
+ * @param [registeredWidgets={}] - A registry of widget name to `Widget` implementation
8
+ * @returns - True if the widget exists, false otherwise
9
+ */
10
+ export default function hasWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(schema: RJSFSchema, widget: Widget<T, S, F> | string, registeredWidgets?: RegistryWidgetsType<T, S, F>): boolean;
@@ -0,0 +1,23 @@
1
+ import getWidget from './getWidget';
2
+ /** Detects whether the `widget` exists for the `schema` with the associated `registryWidgets` and returns true if it
3
+ * does, or false if it doesn't.
4
+ *
5
+ * @param schema - The schema for the field
6
+ * @param widget - Either the name of the widget OR a `Widget` implementation to use
7
+ * @param [registeredWidgets={}] - A registry of widget name to `Widget` implementation
8
+ * @returns - True if the widget exists, false otherwise
9
+ */
10
+ export default function hasWidget(schema, widget, registeredWidgets = {}) {
11
+ try {
12
+ getWidget(schema, widget, registeredWidgets);
13
+ return true;
14
+ }
15
+ catch (e) {
16
+ const err = e;
17
+ if (err.message && (err.message.startsWith('No widget') || err.message.startsWith('Unsupported widget'))) {
18
+ return false;
19
+ }
20
+ throw e;
21
+ }
22
+ }
23
+ //# sourceMappingURL=hasWidget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hasWidget.js","sourceRoot":"","sources":["../src/hasWidget.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,aAAa,CAAC;AAGpC;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,MAAkB,EAClB,MAAgC,EAChC,oBAAkD,EAAE;IAEpD,IAAI;QACF,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,iBAAiB,CAAC,CAAC;QAC7C,OAAO,IAAI,CAAC;KACb;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,GAAG,GAAU,CAAU,CAAC;QAC9B,IAAI,GAAG,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC,EAAE;YACxG,OAAO,KAAK,CAAC;SACd;QACD,MAAM,CAAC,CAAC;KACT;AACH,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { RJSFSchema, StrictRJSFSchema } from './types';
2
+ /** Stringifies the schema and returns the hash of the resulting string. Sorts schema fields
3
+ * in consistent order before stringify to prevent different hash ids for the same schema.
4
+ *
5
+ * @param schema - The schema for which the hash is desired
6
+ * @returns - The string obtained from the hash of the stringified schema
7
+ */
8
+ export default function hashForSchema<S extends StrictRJSFSchema = RJSFSchema>(schema: S): string;
@@ -0,0 +1,29 @@
1
+ /** JS has no built-in hashing function, so rolling our own
2
+ * based on Java's hashing fn:
3
+ * http://www.java2s.com/example/nodejs-utility-method/string-hash/hashcode-4dc2b.html
4
+ *
5
+ * @param string - The string for which to get the hash
6
+ * @returns - The resulting hash of the string in hex format
7
+ */
8
+ function hashString(string) {
9
+ let hash = 0;
10
+ for (let i = 0; i < string.length; i += 1) {
11
+ const chr = string.charCodeAt(i);
12
+ hash = (hash << 5) - hash + chr;
13
+ hash = hash & hash; // Convert to 32bit integer
14
+ }
15
+ return hash.toString(16);
16
+ }
17
+ /** Stringifies the schema and returns the hash of the resulting string. Sorts schema fields
18
+ * in consistent order before stringify to prevent different hash ids for the same schema.
19
+ *
20
+ * @param schema - The schema for which the hash is desired
21
+ * @returns - The string obtained from the hash of the stringified schema
22
+ */
23
+ export default function hashForSchema(schema) {
24
+ const allKeys = new Set();
25
+ // solution source: https://stackoverflow.com/questions/16167581/sort-object-properties-and-json-stringify/53593328#53593328
26
+ JSON.stringify(schema, (key, value) => (allKeys.add(key), value));
27
+ return hashString(JSON.stringify(schema, Array.from(allKeys).sort()));
28
+ }
29
+ //# sourceMappingURL=hashForSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hashForSchema.js","sourceRoot":"","sources":["../src/hashForSchema.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,SAAS,UAAU,CAAC,MAAc;IAChC,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;QACzC,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACjC,IAAI,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,GAAG,GAAG,CAAC;QAChC,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,2BAA2B;KAChD;IACD,OAAO,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AAC3B,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CAA0C,MAAS;IACtF,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,4HAA4H;IAC5H,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;IAClE,OAAO,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AACxE,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { IdSchema } from './types';
2
+ /** Return a consistent `id` for the field description element
3
+ *
4
+ * @param id - Either simple string id or an IdSchema from which to extract it
5
+ * @returns - The consistent id for the field description element from the given `id`
6
+ */
7
+ export declare function descriptionId<T = any>(id: IdSchema<T> | string): string;
8
+ /** Return a consistent `id` for the field error element
9
+ *
10
+ * @param id - Either simple string id or an IdSchema from which to extract it
11
+ * @returns - The consistent id for the field error element from the given `id`
12
+ */
13
+ export declare function errorId<T = any>(id: IdSchema<T> | string): string;
14
+ /** Return a consistent `id` for the field examples element
15
+ *
16
+ * @param id - Either simple string id or an IdSchema from which to extract it
17
+ * @returns - The consistent id for the field examples element from the given `id`
18
+ */
19
+ export declare function examplesId<T = any>(id: IdSchema<T> | string): string;
20
+ /** Return a consistent `id` for the field help element
21
+ *
22
+ * @param id - Either simple string id or an IdSchema from which to extract it
23
+ * @returns - The consistent id for the field help element from the given `id`
24
+ */
25
+ export declare function helpId<T = any>(id: IdSchema<T> | string): string;
26
+ /** Return a consistent `id` for the field title element
27
+ *
28
+ * @param id - Either simple string id or an IdSchema from which to extract it
29
+ * @returns - The consistent id for the field title element from the given `id`
30
+ */
31
+ export declare function titleId<T = any>(id: IdSchema<T> | string): string;
32
+ /** Return a list of element ids that contain additional information about the field that can be used to as the aria
33
+ * description of the field. This is correctly omitting `titleId` which would be "labeling" rather than "describing" the
34
+ * element.
35
+ *
36
+ * @param id - Either simple string id or an IdSchema from which to extract it
37
+ * @param [includeExamples=false] - Optional flag, if true, will add the `examplesId` into the list
38
+ * @returns - The string containing the list of ids for use in an `aria-describedBy` attribute
39
+ */
40
+ export declare function ariaDescribedByIds<T = any>(id: IdSchema<T> | string, includeExamples?: boolean): string;
41
+ /** Return a consistent `id` for the `optionIndex`s of a `Radio` or `Checkboxes` widget
42
+ *
43
+ * @param id - The id of the parent component for the option
44
+ * @param optionIndex - The index of the option for which the id is desired
45
+ * @returns - An id for the option index based on the parent `id`
46
+ */
47
+ export declare function optionId(id: string, optionIndex: number): string;
@@ -0,0 +1,73 @@
1
+ import isString from 'lodash/isString';
2
+ import { ID_KEY } from './constants';
3
+ /** Generates a consistent `id` pattern for a given `id` and a `suffix`
4
+ *
5
+ * @param id - Either simple string id or an IdSchema from which to extract it
6
+ * @param suffix - The suffix to append to the id
7
+ */
8
+ function idGenerator(id, suffix) {
9
+ const theId = isString(id) ? id : id[ID_KEY];
10
+ return `${theId}__${suffix}`;
11
+ }
12
+ /** Return a consistent `id` for the field description element
13
+ *
14
+ * @param id - Either simple string id or an IdSchema from which to extract it
15
+ * @returns - The consistent id for the field description element from the given `id`
16
+ */
17
+ export function descriptionId(id) {
18
+ return idGenerator(id, 'description');
19
+ }
20
+ /** Return a consistent `id` for the field error element
21
+ *
22
+ * @param id - Either simple string id or an IdSchema from which to extract it
23
+ * @returns - The consistent id for the field error element from the given `id`
24
+ */
25
+ export function errorId(id) {
26
+ return idGenerator(id, 'error');
27
+ }
28
+ /** Return a consistent `id` for the field examples element
29
+ *
30
+ * @param id - Either simple string id or an IdSchema from which to extract it
31
+ * @returns - The consistent id for the field examples element from the given `id`
32
+ */
33
+ export function examplesId(id) {
34
+ return idGenerator(id, 'examples');
35
+ }
36
+ /** Return a consistent `id` for the field help element
37
+ *
38
+ * @param id - Either simple string id or an IdSchema from which to extract it
39
+ * @returns - The consistent id for the field help element from the given `id`
40
+ */
41
+ export function helpId(id) {
42
+ return idGenerator(id, 'help');
43
+ }
44
+ /** Return a consistent `id` for the field title element
45
+ *
46
+ * @param id - Either simple string id or an IdSchema from which to extract it
47
+ * @returns - The consistent id for the field title element from the given `id`
48
+ */
49
+ export function titleId(id) {
50
+ return idGenerator(id, 'title');
51
+ }
52
+ /** Return a list of element ids that contain additional information about the field that can be used to as the aria
53
+ * description of the field. This is correctly omitting `titleId` which would be "labeling" rather than "describing" the
54
+ * element.
55
+ *
56
+ * @param id - Either simple string id or an IdSchema from which to extract it
57
+ * @param [includeExamples=false] - Optional flag, if true, will add the `examplesId` into the list
58
+ * @returns - The string containing the list of ids for use in an `aria-describedBy` attribute
59
+ */
60
+ export function ariaDescribedByIds(id, includeExamples = false) {
61
+ const examples = includeExamples ? ` ${examplesId(id)}` : '';
62
+ return `${errorId(id)} ${descriptionId(id)} ${helpId(id)}${examples}`;
63
+ }
64
+ /** Return a consistent `id` for the `optionIndex`s of a `Radio` or `Checkboxes` widget
65
+ *
66
+ * @param id - The id of the parent component for the option
67
+ * @param optionIndex - The index of the option for which the id is desired
68
+ * @returns - An id for the option index based on the parent `id`
69
+ */
70
+ export function optionId(id, optionIndex) {
71
+ return `${id}-${optionIndex}`;
72
+ }
73
+ //# sourceMappingURL=idGenerators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idGenerators.js","sourceRoot":"","sources":["../src/idGenerators.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AAGvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;;GAIG;AACH,SAAS,WAAW,CAAU,EAAwB,EAAE,MAAc;IACpE,MAAM,KAAK,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;IAC7C,OAAO,GAAG,KAAK,KAAK,MAAM,EAAE,CAAC;AAC/B,CAAC;AACD;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAU,EAAwB;IAC7D,OAAO,WAAW,CAAI,EAAE,EAAE,aAAa,CAAC,CAAC;AAC3C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAU,EAAwB;IACvD,OAAO,WAAW,CAAI,EAAE,EAAE,OAAO,CAAC,CAAC;AACrC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAU,EAAwB;IAC1D,OAAO,WAAW,CAAI,EAAE,EAAE,UAAU,CAAC,CAAC;AACxC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAU,EAAwB;IACtD,OAAO,WAAW,CAAI,EAAE,EAAE,MAAM,CAAC,CAAC;AACpC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAU,EAAwB;IACvD,OAAO,WAAW,CAAI,EAAE,EAAE,OAAO,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAU,EAAwB,EAAE,eAAe,GAAG,KAAK;IAC3F,MAAM,QAAQ,GAAG,eAAe,CAAC,CAAC,CAAC,IAAI,UAAU,CAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAChE,OAAO,GAAG,OAAO,CAAI,EAAE,CAAC,IAAI,aAAa,CAAI,EAAE,CAAC,IAAI,MAAM,CAAI,EAAE,CAAC,GAAG,QAAQ,EAAE,CAAC;AACjF,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,EAAU,EAAE,WAAmB;IACtD,OAAO,GAAG,EAAE,IAAI,WAAW,EAAE,CAAC;AAChC,CAAC"}