@rjsf/utils 6.6.1 → 6.7.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 (289) hide show
  1. package/LICENSE.md +201 -0
  2. package/dist/index.cjs +534 -376
  3. package/dist/index.cjs.map +4 -4
  4. package/dist/utils.esm.js +534 -376
  5. package/dist/utils.esm.js.map +4 -4
  6. package/dist/utils.umd.js +561 -400
  7. package/lib/ErrorSchemaBuilder.d.ts +1 -1
  8. package/lib/SelectedOptionDescription.d.ts +4 -0
  9. package/lib/SelectedOptionDescription.js +24 -0
  10. package/lib/SelectedOptionDescription.js.map +1 -0
  11. package/lib/allowAdditionalItems.d.ts +1 -1
  12. package/lib/allowAdditionalItems.js +1 -0
  13. package/lib/allowAdditionalItems.js.map +1 -1
  14. package/lib/asNumber.js +2 -0
  15. package/lib/asNumber.js.map +1 -1
  16. package/lib/canExpand.d.ts +1 -1
  17. package/lib/constIsAjvDataReference.d.ts +1 -1
  18. package/lib/constants.d.ts +8 -5
  19. package/lib/constants.js +10 -7
  20. package/lib/constants.js.map +1 -1
  21. package/lib/createErrorHandler.d.ts +1 -1
  22. package/lib/createErrorHandler.js +2 -6
  23. package/lib/createErrorHandler.js.map +1 -1
  24. package/lib/createSchemaUtils.d.ts +1 -1
  25. package/lib/createSchemaUtils.js +3 -1
  26. package/lib/createSchemaUtils.js.map +1 -1
  27. package/lib/dataURItoBlob.js +3 -3
  28. package/lib/dataURItoBlob.js.map +1 -1
  29. package/lib/dateRangeOptions.d.ts +1 -1
  30. package/lib/dateRangeOptions.js +8 -7
  31. package/lib/dateRangeOptions.js.map +1 -1
  32. package/lib/englishStringTranslator.d.ts +1 -1
  33. package/lib/enumOptionSelectedValue.d.ts +1 -1
  34. package/lib/enumOptionValueDecoder.d.ts +1 -1
  35. package/lib/enumOptionValueDecoder.js +1 -1
  36. package/lib/enumOptionValueDecoder.js.map +1 -1
  37. package/lib/enumOptionValueEncoder.d.ts +1 -1
  38. package/lib/enumOptionsDeselectValue.d.ts +1 -1
  39. package/lib/enumOptionsIndexForValue.d.ts +1 -1
  40. package/lib/enumOptionsIndexForValue.js.map +1 -1
  41. package/lib/enumOptionsIsSelected.d.ts +1 -1
  42. package/lib/enumOptionsSelectValue.d.ts +1 -1
  43. package/lib/enumOptionsValueForIndex.d.ts +2 -2
  44. package/lib/enumOptionsValueForIndex.js.map +1 -1
  45. package/lib/enums.d.ts +4 -0
  46. package/lib/enums.js +4 -0
  47. package/lib/enums.js.map +1 -1
  48. package/lib/findSchemaDefinition.d.ts +1 -1
  49. package/lib/findSchemaDefinition.js +15 -15
  50. package/lib/findSchemaDefinition.js.map +1 -1
  51. package/lib/getChangedFields.js +4 -6
  52. package/lib/getChangedFields.js.map +1 -1
  53. package/lib/getDateElementProps.d.ts +3 -3
  54. package/lib/getDiscriminatorFieldFromSchema.d.ts +1 -1
  55. package/lib/getDiscriminatorFieldFromSchema.js +1 -0
  56. package/lib/getDiscriminatorFieldFromSchema.js.map +1 -1
  57. package/lib/getInputProps.d.ts +1 -1
  58. package/lib/getOptionMatchingSimpleDiscriminator.d.ts +1 -1
  59. package/lib/getOptionMatchingSimpleDiscriminator.js +10 -11
  60. package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -1
  61. package/lib/getOptionValueFormat.d.ts +1 -1
  62. package/lib/getSchemaType.d.ts +1 -1
  63. package/lib/getSchemaType.js +2 -1
  64. package/lib/getSchemaType.js.map +1 -1
  65. package/lib/getSubmitButtonOptions.d.ts +1 -1
  66. package/lib/getSubmitButtonOptions.js +1 -1
  67. package/lib/getSubmitButtonOptions.js.map +1 -1
  68. package/lib/getTemplate.d.ts +1 -1
  69. package/lib/getTestIds.d.ts +1 -1
  70. package/lib/getUiOptions.d.ts +1 -1
  71. package/lib/getUiOptions.js +2 -1
  72. package/lib/getUiOptions.js.map +1 -1
  73. package/lib/getWidget.d.ts +1 -1
  74. package/lib/getWidget.js +4 -4
  75. package/lib/getWidget.js.map +1 -1
  76. package/lib/guessType.js +1 -1
  77. package/lib/guessType.js.map +1 -1
  78. package/lib/hasWidget.d.ts +1 -1
  79. package/lib/hashForSchema.d.ts +3 -1
  80. package/lib/hashForSchema.js +11 -4
  81. package/lib/hashForSchema.js.map +1 -1
  82. package/lib/idGenerators.d.ts +1 -1
  83. package/lib/index.d.ts +14 -7
  84. package/lib/index.js +5 -2
  85. package/lib/index.js.map +1 -1
  86. package/lib/isConstant.d.ts +1 -1
  87. package/lib/isCustomWidget.d.ts +1 -1
  88. package/lib/isCustomWidget.js +1 -1
  89. package/lib/isCustomWidget.js.map +1 -1
  90. package/lib/isFixedItems.d.ts +3 -3
  91. package/lib/isFixedItems.js +3 -3
  92. package/lib/isFixedItems.js.map +1 -1
  93. package/lib/isRootSchema.d.ts +1 -1
  94. package/lib/isRootSchema.js +2 -3
  95. package/lib/isRootSchema.js.map +1 -1
  96. package/lib/labelValue.d.ts +1 -1
  97. package/lib/logUnsupportedDefaultForEnum.d.ts +9 -0
  98. package/lib/logUnsupportedDefaultForEnum.js +18 -0
  99. package/lib/logUnsupportedDefaultForEnum.js.map +1 -0
  100. package/lib/lookupFromFormContext.d.ts +1 -1
  101. package/lib/mergeDefaultsWithFormData.js +6 -5
  102. package/lib/mergeDefaultsWithFormData.js.map +1 -1
  103. package/lib/mergeObjects.d.ts +4 -2
  104. package/lib/mergeObjects.js +1 -1
  105. package/lib/mergeObjects.js.map +1 -1
  106. package/lib/mergeSchemas.d.ts +4 -2
  107. package/lib/mergeSchemas.js +13 -6
  108. package/lib/mergeSchemas.js.map +1 -1
  109. package/lib/nameGenerators.d.ts +1 -1
  110. package/lib/optionsList.d.ts +1 -1
  111. package/lib/optionsList.js +22 -21
  112. package/lib/optionsList.js.map +1 -1
  113. package/lib/orderProperties.js +3 -3
  114. package/lib/orderProperties.js.map +1 -1
  115. package/lib/pad.js +1 -1
  116. package/lib/pad.js.map +1 -1
  117. package/lib/parseDateString.d.ts +1 -1
  118. package/lib/parseDateString.js +1 -1
  119. package/lib/parseDateString.js.map +1 -1
  120. package/lib/parser/ParserValidator.d.ts +2 -4
  121. package/lib/parser/ParserValidator.js +2 -0
  122. package/lib/parser/ParserValidator.js.map +1 -1
  123. package/lib/parser/index.d.ts +1 -1
  124. package/lib/parser/schemaParser.d.ts +2 -2
  125. package/lib/parser/schemaParser.js +7 -7
  126. package/lib/parser/schemaParser.js.map +1 -1
  127. package/lib/rangeSpec.d.ts +1 -2
  128. package/lib/rangeSpec.js.map +1 -1
  129. package/lib/removeOptionalEmptyObjects.d.ts +1 -1
  130. package/lib/removeOptionalEmptyObjects.js +6 -8
  131. package/lib/removeOptionalEmptyObjects.js.map +1 -1
  132. package/lib/resolveUiSchema.d.ts +1 -1
  133. package/lib/resolveUiSchema.js +16 -16
  134. package/lib/resolveUiSchema.js.map +1 -1
  135. package/lib/schema/findFieldInSchema.d.ts +1 -1
  136. package/lib/schema/findSelectedOptionInXxxOf.d.ts +1 -1
  137. package/lib/schema/findSelectedOptionInXxxOf.js +1 -3
  138. package/lib/schema/findSelectedOptionInXxxOf.js.map +1 -1
  139. package/lib/schema/getClosestMatchingOption.d.ts +1 -1
  140. package/lib/schema/getClosestMatchingOption.js +6 -9
  141. package/lib/schema/getClosestMatchingOption.js.map +1 -1
  142. package/lib/schema/getDefaultFormState.d.ts +4 -4
  143. package/lib/schema/getDefaultFormState.js +81 -43
  144. package/lib/schema/getDefaultFormState.js.map +1 -1
  145. package/lib/schema/getDisplayLabel.d.ts +1 -1
  146. package/lib/schema/getDisplayLabel.js +2 -3
  147. package/lib/schema/getDisplayLabel.js.map +1 -1
  148. package/lib/schema/getFirstMatchingOption.d.ts +1 -1
  149. package/lib/schema/getFirstMatchingOption.js +2 -2
  150. package/lib/schema/getFirstMatchingOption.js.map +1 -1
  151. package/lib/schema/getFromSchema.d.ts +1 -1
  152. package/lib/schema/index.js +9 -3
  153. package/lib/schema/index.js.map +1 -1
  154. package/lib/schema/isFilesArray.d.ts +1 -1
  155. package/lib/schema/isMultiSelect.d.ts +1 -1
  156. package/lib/schema/isMultiSelect.js.map +1 -1
  157. package/lib/schema/isSelect.d.ts +1 -1
  158. package/lib/schema/isSelect.js +1 -1
  159. package/lib/schema/isSelect.js.map +1 -1
  160. package/lib/schema/omitExtraData.d.ts +1 -1
  161. package/lib/schema/omitExtraData.js +66 -52
  162. package/lib/schema/omitExtraData.js.map +1 -1
  163. package/lib/schema/retrieveSchema.d.ts +7 -3
  164. package/lib/schema/retrieveSchema.js +83 -56
  165. package/lib/schema/retrieveSchema.js.map +1 -1
  166. package/lib/schema/sanitizeDataForNewSchema.d.ts +1 -1
  167. package/lib/schema/sanitizeDataForNewSchema.js +48 -7
  168. package/lib/schema/sanitizeDataForNewSchema.js.map +1 -1
  169. package/lib/schema/toPathSchema.d.ts +1 -1
  170. package/lib/schema/toPathSchema.js +9 -5
  171. package/lib/schema/toPathSchema.js.map +1 -1
  172. package/lib/schemaRequiresTrueValue.d.ts +1 -1
  173. package/lib/schemaRequiresTrueValue.js +4 -3
  174. package/lib/schemaRequiresTrueValue.js.map +1 -1
  175. package/lib/shallowEquals.js +2 -2
  176. package/lib/shallowEquals.js.map +1 -1
  177. package/lib/shouldRenderOptionalField.d.ts +1 -1
  178. package/lib/toConstant.d.ts +1 -1
  179. package/lib/toDateString.d.ts +1 -1
  180. package/lib/toErrorList.d.ts +1 -1
  181. package/lib/toErrorList.js +3 -3
  182. package/lib/toErrorList.js.map +1 -1
  183. package/lib/toErrorSchema.d.ts +1 -1
  184. package/lib/toFieldPathId.d.ts +1 -1
  185. package/lib/tsconfig.tsbuildinfo +1 -1
  186. package/lib/types.d.ts +63 -57
  187. package/lib/unwrapErrorHandler.d.ts +1 -1
  188. package/lib/unwrapErrorHandler.js +7 -9
  189. package/lib/unwrapErrorHandler.js.map +1 -1
  190. package/lib/useAltDateWidgetProps.d.ts +6 -6
  191. package/lib/useAltDateWidgetProps.js +3 -3
  192. package/lib/useAltDateWidgetProps.js.map +1 -1
  193. package/lib/useFileWidgetProps.d.ts +2 -2
  194. package/lib/useFileWidgetProps.js +3 -3
  195. package/lib/useFileWidgetProps.js.map +1 -1
  196. package/lib/validationDataMerge.d.ts +1 -1
  197. package/lib/withIdRefPrefix.d.ts +1 -1
  198. package/lib/withIdRefPrefix.js +12 -12
  199. package/lib/withIdRefPrefix.js.map +1 -1
  200. package/package.json +19 -19
  201. package/src/ErrorSchemaBuilder.ts +1 -1
  202. package/src/SelectedOptionDescription.tsx +48 -0
  203. package/src/allowAdditionalItems.ts +2 -1
  204. package/src/asNumber.ts +2 -0
  205. package/src/canExpand.ts +1 -1
  206. package/src/constIsAjvDataReference.ts +2 -2
  207. package/src/constants.ts +10 -7
  208. package/src/createErrorHandler.ts +6 -7
  209. package/src/createSchemaUtils.ts +4 -2
  210. package/src/dataURItoBlob.ts +3 -3
  211. package/src/dateRangeOptions.ts +9 -7
  212. package/src/englishStringTranslator.ts +1 -1
  213. package/src/enumOptionSelectedValue.ts +1 -1
  214. package/src/enumOptionValueDecoder.ts +2 -2
  215. package/src/enumOptionValueEncoder.ts +1 -1
  216. package/src/enumOptionsDeselectValue.ts +1 -1
  217. package/src/enumOptionsIndexForValue.ts +2 -2
  218. package/src/enumOptionsIsSelected.ts +1 -1
  219. package/src/enumOptionsSelectValue.ts +1 -1
  220. package/src/enumOptionsValueForIndex.ts +2 -2
  221. package/src/enums.ts +4 -0
  222. package/src/findSchemaDefinition.ts +18 -17
  223. package/src/getChangedFields.ts +5 -5
  224. package/src/getDateElementProps.ts +3 -3
  225. package/src/getDiscriminatorFieldFromSchema.ts +2 -1
  226. package/src/getInputProps.ts +1 -1
  227. package/src/getOptionMatchingSimpleDiscriminator.ts +11 -15
  228. package/src/getOptionValueFormat.ts +1 -1
  229. package/src/getSchemaType.ts +3 -2
  230. package/src/getSubmitButtonOptions.ts +3 -3
  231. package/src/getTemplate.ts +1 -1
  232. package/src/getTestIds.ts +1 -1
  233. package/src/getUiOptions.ts +10 -2
  234. package/src/getWidget.tsx +5 -6
  235. package/src/guessType.ts +1 -1
  236. package/src/hasWidget.ts +1 -1
  237. package/src/hashForSchema.ts +12 -5
  238. package/src/idGenerators.ts +1 -1
  239. package/src/index.ts +16 -5
  240. package/src/isConstant.ts +1 -1
  241. package/src/isCustomWidget.ts +2 -2
  242. package/src/isFixedItems.ts +4 -4
  243. package/src/isRootSchema.ts +3 -5
  244. package/src/labelValue.ts +1 -1
  245. package/src/logUnsupportedDefaultForEnum.ts +28 -0
  246. package/src/lookupFromFormContext.ts +1 -1
  247. package/src/mergeDefaultsWithFormData.ts +8 -7
  248. package/src/mergeObjects.ts +2 -2
  249. package/src/mergeSchemas.ts +14 -7
  250. package/src/nameGenerators.ts +1 -1
  251. package/src/optionsList.ts +21 -23
  252. package/src/orderProperties.ts +4 -4
  253. package/src/pad.ts +1 -1
  254. package/src/parseDateString.ts +2 -2
  255. package/src/parser/ParserValidator.ts +4 -4
  256. package/src/parser/index.ts +1 -1
  257. package/src/parser/schemaParser.ts +10 -9
  258. package/src/rangeSpec.ts +1 -2
  259. package/src/removeOptionalEmptyObjects.ts +8 -11
  260. package/src/resolveUiSchema.ts +32 -25
  261. package/src/schema/findFieldInSchema.ts +1 -1
  262. package/src/schema/findSelectedOptionInXxxOf.ts +17 -7
  263. package/src/schema/getClosestMatchingOption.ts +17 -11
  264. package/src/schema/getDefaultFormState.ts +104 -43
  265. package/src/schema/getDisplayLabel.ts +4 -5
  266. package/src/schema/getFirstMatchingOption.ts +3 -3
  267. package/src/schema/getFromSchema.ts +1 -1
  268. package/src/schema/index.ts +3 -0
  269. package/src/schema/isFilesArray.ts +1 -1
  270. package/src/schema/isMultiSelect.ts +7 -1
  271. package/src/schema/isSelect.ts +8 -2
  272. package/src/schema/omitExtraData.ts +73 -60
  273. package/src/schema/retrieveSchema.ts +131 -83
  274. package/src/schema/sanitizeDataForNewSchema.ts +57 -8
  275. package/src/schema/toPathSchema.ts +11 -7
  276. package/src/schemaRequiresTrueValue.ts +4 -4
  277. package/src/shallowEquals.ts +2 -2
  278. package/src/shouldRenderOptionalField.ts +1 -1
  279. package/src/toConstant.ts +1 -1
  280. package/src/toDateString.ts +1 -1
  281. package/src/toErrorList.ts +4 -4
  282. package/src/toErrorSchema.ts +1 -1
  283. package/src/toFieldPathId.ts +1 -1
  284. package/src/types.ts +92 -63
  285. package/src/unwrapErrorHandler.ts +11 -12
  286. package/src/useAltDateWidgetProps.tsx +10 -8
  287. package/src/useFileWidgetProps.ts +7 -7
  288. package/src/validationDataMerge.ts +1 -1
  289. package/src/withIdRefPrefix.ts +12 -12
@@ -1,7 +1,7 @@
1
1
  import get from 'lodash/get';
2
2
 
3
3
  import { PROPERTIES_KEY } from './constants';
4
- import { RJSFSchema, StrictRJSFSchema } from './types';
4
+ import type { RJSFSchema, StrictRJSFSchema } from './types';
5
5
 
6
6
  /** Compares the value of `discriminatorField` within `formData` against the value of `discriminatorField` within schema for each `option`.
7
7
  * Returns index of first `option` whose discriminator matches formData. Returns `undefined` if there is no match.
@@ -22,26 +22,22 @@ export default function getOptionMatchingSimpleDiscriminator<T = any, S extends
22
22
  const value = get(formData, discriminatorField);
23
23
 
24
24
  if (value === undefined) {
25
- return;
25
+ return undefined;
26
26
  }
27
27
 
28
- for (let i = 0; i < options.length; i++) {
28
+ for (let i = 0; i < options.length; i += 1) {
29
29
  const option = options[i];
30
30
  const discriminator: S = get(option, [PROPERTIES_KEY, discriminatorField], {}) as S;
31
31
 
32
- if (discriminator.type === 'object' || discriminator.type === 'array') {
33
- continue;
34
- }
35
-
36
- if (discriminator.const === value) {
37
- return i;
38
- }
39
-
40
- if (discriminator.enum?.includes(value)) {
41
- return i;
32
+ if (discriminator.type !== 'object' && discriminator.type !== 'array') {
33
+ if (discriminator.const === value) {
34
+ return i;
35
+ }
36
+ if (discriminator.enum?.includes(value)) {
37
+ return i;
38
+ }
42
39
  }
43
40
  }
44
41
  }
45
-
46
- return;
42
+ return undefined;
47
43
  }
@@ -1,4 +1,4 @@
1
- import { OptionValueFormat } from './types';
1
+ import type { OptionValueFormat } from './types';
2
2
 
3
3
  /** Resolves the effective `optionValueFormat` for enum-backed widgets.
4
4
  *
@@ -1,5 +1,5 @@
1
1
  import guessType from './guessType';
2
- import { RJSFSchema, StrictRJSFSchema } from './types';
2
+ import type { RJSFSchema, StrictRJSFSchema } from './types';
3
3
 
4
4
  /** Gets the type of a given `schema`. If the type is not explicitly defined, then an attempt is made to infer it from
5
5
  * other elements of the schema as follows:
@@ -32,8 +32,9 @@ export default function getSchemaType<S extends StrictRJSFSchema = RJSFSchema>(
32
32
 
33
33
  if (Array.isArray(type)) {
34
34
  if (type.length === 2 && type.includes('null')) {
35
- type = type.find((type) => type !== 'null');
35
+ type = type.find((t) => t !== 'null');
36
36
  } else {
37
+ // oxlint-disable-next-line prefer-destructuring
37
38
  type = type[0];
38
39
  }
39
40
  }
@@ -1,6 +1,6 @@
1
1
  import { SUBMIT_BTN_OPTIONS_KEY } from './constants';
2
2
  import getUiOptions from './getUiOptions';
3
- import { FormContextType, RJSFSchema, StrictRJSFSchema, UiSchema, UISchemaSubmitButtonOptions } from './types';
3
+ import type { FormContextType, RJSFSchema, StrictRJSFSchema, UiSchema, UISchemaSubmitButtonOptions } from './types';
4
4
 
5
5
  /** The default submit button options, exported for testing purposes
6
6
  */
@@ -23,8 +23,8 @@ export default function getSubmitButtonOptions<
23
23
  F extends FormContextType = any,
24
24
  >(uiSchema: UiSchema<T, S, F> = {}): UISchemaSubmitButtonOptions {
25
25
  const uiOptions = getUiOptions<T, S, F>(uiSchema);
26
- if (uiOptions && uiOptions[SUBMIT_BTN_OPTIONS_KEY]) {
27
- const options = uiOptions[SUBMIT_BTN_OPTIONS_KEY] as UISchemaSubmitButtonOptions;
26
+ if (uiOptions?.[SUBMIT_BTN_OPTIONS_KEY]) {
27
+ const options = uiOptions[SUBMIT_BTN_OPTIONS_KEY];
28
28
  return { ...DEFAULT_OPTIONS, ...options };
29
29
  }
30
30
 
@@ -1,4 +1,4 @@
1
- import { FormContextType, TemplatesType, Registry, UIOptionsType, StrictRJSFSchema, RJSFSchema } from './types';
1
+ import type { FormContextType, TemplatesType, Registry, UIOptionsType, StrictRJSFSchema, RJSFSchema } from './types';
2
2
 
3
3
  /** Returns the template with the given `name` from either the `uiSchema` if it is defined or from the `registry`
4
4
  * otherwise. NOTE, since `ButtonTemplates` are not overridden in `uiSchema` only those in the `registry` are returned.
package/src/getTestIds.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import get from 'lodash/get';
2
2
  import uniqueId from 'lodash/uniqueId';
3
3
 
4
- import { TestIdShape } from './types';
4
+ import type { TestIdShape } from './types';
5
5
 
6
6
  /** Returns an object of test IDs that can only be used in test mode. If the function is called in a test environment
7
7
  * (`NODE_ENV === 'test'`, this is set by vitest) then a Proxy object will be returned. If a key within the returned
@@ -1,6 +1,13 @@
1
1
  import { UI_OPTIONS_KEY, UI_WIDGET_KEY } from './constants';
2
2
  import isObject from './isObject';
3
- import { FormContextType, GlobalUISchemaOptions, RJSFSchema, StrictRJSFSchema, UIOptionsType, UiSchema } from './types';
3
+ import type {
4
+ FormContextType,
5
+ GlobalUISchemaOptions,
6
+ RJSFSchema,
7
+ StrictRJSFSchema,
8
+ UIOptionsType,
9
+ UiSchema,
10
+ } from './types';
4
11
 
5
12
  /** Get all passed options from ui:options, and ui:<optionName>, returning them in an object with the `ui:`
6
13
  * stripped off. Any `globalOptions` will always be returned, unless they are overridden by options in the `uiSchema`.
@@ -18,11 +25,12 @@ export default function getUiOptions<T = any, S extends StrictRJSFSchema = RJSFS
18
25
  return { ...globalOptions };
19
26
  }
20
27
  return Object.keys(uiSchema)
21
- .filter((key) => key.indexOf('ui:') === 0)
28
+ .filter((key) => key.startsWith('ui:'))
22
29
  .reduce(
23
30
  (options, key) => {
24
31
  const value = uiSchema[key];
25
32
  if (key === UI_WIDGET_KEY && isObject(value)) {
33
+ // oxlint-disable-next-line no-console
26
34
  console.error('Setting options via ui:widget object is no longer supported, use ui:options instead');
27
35
  return options;
28
36
  }
package/src/getWidget.tsx CHANGED
@@ -4,11 +4,11 @@ import set from 'lodash/set';
4
4
  import ReactIs from 'react-is';
5
5
 
6
6
  import getSchemaType from './getSchemaType';
7
- import { FormContextType, RJSFSchema, Widget, RegistryWidgetsType, StrictRJSFSchema } from './types';
7
+ import type { FormContextType, RJSFSchema, Widget, RegistryWidgetsType, StrictRJSFSchema } from './types';
8
8
 
9
9
  /** The map of schema types to widget type to widget name
10
10
  */
11
- const widgetMap: { [k: string]: { [j: string]: string } } = {
11
+ const widgetMap: Record<string, Record<string, string>> = {
12
12
  boolean: {
13
13
  checkbox: 'CheckboxWidget',
14
14
  radio: 'RadioWidget',
@@ -74,10 +74,9 @@ function mergeWidgetOptions<T = any, S extends StrictRJSFSchema = RJSFSchema, F
74
74
  let MergedWidget: Widget<T, S, F> | undefined = get(AWidget, 'MergedWidget');
75
75
  // cache return value as property of widget for proper react reconciliation
76
76
  if (!MergedWidget) {
77
- const defaultOptions = (AWidget.defaultProps && AWidget.defaultProps.options) || {};
78
- MergedWidget = ({ options, ...props }) => {
79
- return <AWidget options={{ ...defaultOptions, ...options }} {...props} />;
80
- };
77
+ // oxlint-disable-next-line typescript/no-deprecated
78
+ const defaultOptions = AWidget.defaultProps?.options || {};
79
+ MergedWidget = ({ options, ...props }) => <AWidget options={{ ...defaultOptions, ...options }} {...props} />;
81
80
  set(AWidget, 'MergedWidget', MergedWidget);
82
81
  }
83
82
  return MergedWidget;
package/src/guessType.ts CHANGED
@@ -17,7 +17,7 @@ export default function guessType(value: any) {
17
17
  if (typeof value === 'boolean') {
18
18
  return 'boolean';
19
19
  }
20
- if (!isNaN(value)) {
20
+ if (typeof value === 'number' && !Number.isNaN(value)) {
21
21
  return 'number';
22
22
  }
23
23
  if (typeof value === 'object') {
package/src/hasWidget.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import getWidget from './getWidget';
2
- import { FormContextType, RegistryWidgetsType, RJSFSchema, StrictRJSFSchema, Widget } from './types';
2
+ import type { FormContextType, RegistryWidgetsType, RJSFSchema, StrictRJSFSchema, Widget } from './types';
3
3
 
4
4
  /** Detects whether the `widget` exists for the `schema` with the associated `registryWidgets` and returns true if it
5
5
  * does, or false if it doesn't.
@@ -1,4 +1,4 @@
1
- import { RJSFSchema, StrictRJSFSchema } from './types';
1
+ import type { RJSFSchema, StrictRJSFSchema } from './types';
2
2
 
3
3
  /** Hashes a string using the algorithm based on Java's hashing function.
4
4
  * JS has no built-in hashing function, so rolling our own
@@ -10,10 +10,12 @@ import { RJSFSchema, StrictRJSFSchema } from './types';
10
10
  */
11
11
  export function hashString(string: string): string {
12
12
  let hash = 0;
13
- for (let i = 0; i < string.length; i += 1) {
13
+ for (let i = 0; i < string.length; i++) {
14
14
  const chr = string.charCodeAt(i);
15
+ // oxlint-disable-next-line no-bitwise
15
16
  hash = (hash << 5) - hash + chr;
16
- hash = hash & hash; // Convert to 32bit integer
17
+ // oxlint-disable-next-line no-bitwise
18
+ hash &= hash; // Convert to 32bit integer
17
19
  }
18
20
  return hash.toString(16);
19
21
  }
@@ -26,7 +28,10 @@ export function hashString(string: string): string {
26
28
  export function sortedJSONStringify(object: unknown): string {
27
29
  const allKeys = new Set<string>();
28
30
  // solution source: https://stackoverflow.com/questions/16167581/sort-object-properties-and-json-stringify/53593328#53593328
29
- JSON.stringify(object, (key, value) => (allKeys.add(key), value));
31
+ JSON.stringify(object, (key, value) => {
32
+ allKeys.add(key);
33
+ return value;
34
+ });
30
35
  return JSON.stringify(object, Array.from(allKeys).sort());
31
36
  }
32
37
 
@@ -42,10 +47,12 @@ export function hashObject(object: unknown): string {
42
47
 
43
48
  /** Stringifies the schema and returns the hash of the resulting string. Sorts schema fields
44
49
  * in consistent order before stringify to prevent different hash ids for the same schema.
50
+ * Symbol-keyed properties (RJSF_REF_KEY, RJSF_REF_CYCLE_KEY, ADDITIONAL_PROPERTY_FLAG) are
51
+ * automatically excluded by JSON.stringify, so no special filtering is needed.
45
52
  *
46
53
  * @param schema - The schema for which the hash is desired
47
54
  * @returns - The string obtained from the hash of the stringified schema
48
55
  */
49
56
  export default function hashForSchema<S extends StrictRJSFSchema = RJSFSchema>(schema: S) {
50
- return hashObject(schema);
57
+ return hashString(sortedJSONStringify(schema));
51
58
  }
@@ -1,7 +1,7 @@
1
1
  import isString from 'lodash/isString';
2
2
 
3
3
  import { ID_KEY } from './constants';
4
- import { FieldPathId } from './types';
4
+ import type { FieldPathId } from './types';
5
5
 
6
6
  /** Generates a consistent `id` pattern for a given `id` and a `suffix`
7
7
  *
package/src/index.ts CHANGED
@@ -18,7 +18,8 @@ import enumOptionValueEncoder from './enumOptionValueEncoder';
18
18
  import ErrorSchemaBuilder from './ErrorSchemaBuilder';
19
19
  import findSchemaDefinition from './findSchemaDefinition';
20
20
  import getChangedFields from './getChangedFields';
21
- import getDateElementProps, { DateElementFormat, DateElementProp } from './getDateElementProps';
21
+ import type { DateElementFormat, DateElementProp } from './getDateElementProps';
22
+ import getDateElementProps from './getDateElementProps';
22
23
  import getDiscriminatorFieldFromSchema from './getDiscriminatorFieldFromSchema';
23
24
  import getInputProps from './getInputProps';
24
25
  import getOptionMatchingSimpleDiscriminator from './getOptionMatchingSimpleDiscriminator';
@@ -51,6 +52,7 @@ import isObject from './isObject';
51
52
  import isRootSchema from './isRootSchema';
52
53
  import labelValue from './labelValue';
53
54
  import localToUTC from './localToUTC';
55
+ import logUnsupportedDefaultForEnum from './logUnsupportedDefaultForEnum';
54
56
  import lookupFromFormContext from './lookupFromFormContext';
55
57
  import mergeDefaultsWithFormData from './mergeDefaultsWithFormData';
56
58
  import mergeObjects from './mergeObjects';
@@ -65,8 +67,11 @@ import removeOptionalEmptyObjects from './removeOptionalEmptyObjects';
65
67
  import replaceStringParameters from './replaceStringParameters';
66
68
  import resolveUiSchema from './resolveUiSchema';
67
69
  import schemaRequiresTrueValue from './schemaRequiresTrueValue';
70
+ import SelectedOptionDescription from './SelectedOptionDescription';
71
+ import type { SelectedOptionDescriptionProps } from './SelectedOptionDescription';
68
72
  import shallowEquals from './shallowEquals';
69
- import shouldRender, { ComponentUpdateStrategy } from './shouldRender';
73
+ import type { ComponentUpdateStrategy } from './shouldRender';
74
+ import shouldRender from './shouldRender';
70
75
  import shouldRenderOptionalField from './shouldRenderOptionalField';
71
76
  import toConstant from './toConstant';
72
77
  import toDateString from './toDateString';
@@ -74,14 +79,16 @@ import toErrorList from './toErrorList';
74
79
  import toErrorSchema from './toErrorSchema';
75
80
  import toFieldPathId from './toFieldPathId';
76
81
  import unwrapErrorHandler from './unwrapErrorHandler';
77
- import useAltDateWidgetProps, { DateElement, DateElementProps, UseAltDateWidgetResult } from './useAltDateWidgetProps';
82
+ import type { DateElementProps, UseAltDateWidgetResult } from './useAltDateWidgetProps';
83
+ import useAltDateWidgetProps, { DateElement } from './useAltDateWidgetProps';
78
84
  import useDeepCompareMemo from './useDeepCompareMemo';
79
- import useFileWidgetProps, { FileInfoType, UseFileWidgetPropsResult } from './useFileWidgetProps';
85
+ import type { FileInfoType, UseFileWidgetPropsResult } from './useFileWidgetProps';
86
+ import useFileWidgetProps from './useFileWidgetProps';
80
87
  import utcToLocal from './utcToLocal';
81
88
  import validationDataMerge from './validationDataMerge';
82
89
  import withIdRefPrefix from './withIdRefPrefix';
83
90
 
84
- export * from './types';
91
+ export type * from './types';
85
92
  export * from './enums';
86
93
 
87
94
  export * from './constants';
@@ -94,6 +101,7 @@ export type {
94
101
  DateElementProp,
95
102
  DateElementProps,
96
103
  FileInfoType,
104
+ SelectedOptionDescriptionProps,
97
105
  UseAltDateWidgetResult,
98
106
  UseFileWidgetPropsResult,
99
107
  };
@@ -150,6 +158,7 @@ export {
150
158
  isRootSchema,
151
159
  labelValue,
152
160
  localToUTC,
161
+ logUnsupportedDefaultForEnum,
153
162
  lookupFromFormContext,
154
163
  mergeDefaultsWithFormData,
155
164
  mergeObjects,
@@ -161,10 +170,12 @@ export {
161
170
  pad,
162
171
  parseDateString,
163
172
  rangeSpec,
173
+ // oxlint-disable-next-line typescript/no-deprecated
164
174
  removeOptionalEmptyObjects,
165
175
  replaceStringParameters,
166
176
  resolveUiSchema,
167
177
  schemaRequiresTrueValue,
178
+ SelectedOptionDescription,
168
179
  shallowEquals,
169
180
  shouldRender,
170
181
  shouldRenderOptionalField,
package/src/isConstant.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CONST_KEY } from './constants';
2
- import { RJSFSchema, StrictRJSFSchema } from './types';
2
+ import type { RJSFSchema, StrictRJSFSchema } from './types';
3
3
 
4
4
  /** This function checks if the given `schema` matches a single constant value. This happens when either the schema has
5
5
  * an `enum` array with a single value or there is a `const` defined.
@@ -1,5 +1,5 @@
1
1
  import getUiOptions from './getUiOptions';
2
- import { FormContextType, RJSFSchema, StrictRJSFSchema, UiSchema } from './types';
2
+ import type { FormContextType, RJSFSchema, StrictRJSFSchema, UiSchema } from './types';
3
3
 
4
4
  /** Checks to see if the `uiSchema` contains the `widget` field and that the widget is not `hidden`
5
5
  *
@@ -14,6 +14,6 @@ export default function isCustomWidget<
14
14
  return (
15
15
  // TODO: Remove the `&& uiSchema['ui:widget'] !== 'hidden'` once we support hidden widgets for arrays.
16
16
  // https://rjsf-team.github.io/react-jsonschema-form/docs/usage/widgets/#hidden-widgets
17
- 'widget' in getUiOptions<T, S, F>(uiSchema) && getUiOptions<T, S, F>(uiSchema)['widget'] !== 'hidden'
17
+ 'widget' in getUiOptions<T, S, F>(uiSchema) && getUiOptions<T, S, F>(uiSchema).widget !== 'hidden'
18
18
  );
19
19
  }
@@ -1,12 +1,12 @@
1
1
  import isObject from './isObject';
2
- import { RJSFSchema, StrictRJSFSchema } from './types';
2
+ import type { RJSFSchema, StrictRJSFSchema } from './types';
3
3
 
4
- /** Detects whether the given `schema` contains fixed items. This is the case when `schema.items` is a non-empty array
5
- * that only contains objects.
4
+ /** Detects whether the given `schema` contains fixed items. This is the case when `schema.items` is an array that only
5
+ * contains objects.
6
6
  *
7
7
  * @param schema - The schema in which to check for fixed items
8
8
  * @returns - True if there are fixed items in the schema, false otherwise
9
9
  */
10
10
  export default function isFixedItems<S extends StrictRJSFSchema = RJSFSchema>(schema: S) {
11
- return Array.isArray(schema.items) && schema.items.length > 0 && schema.items.every((item) => isObject(item));
11
+ return Array.isArray(schema.items) && schema.items.every((item) => isObject(item));
12
12
  }
@@ -1,8 +1,6 @@
1
- import omit from 'lodash/omit';
2
-
3
- import { REF_KEY, RJSF_REF_KEY } from './constants';
1
+ import { REF_KEY } from './constants';
4
2
  import deepEquals from './deepEquals';
5
- import { FormContextType, Registry, RJSFSchema, StrictRJSFSchema } from './types';
3
+ import type { FormContextType, Registry, RJSFSchema, StrictRJSFSchema } from './types';
6
4
 
7
5
  /** Helper to check whether a JSON schema object is the root schema. The schema is a root schema with root `properties`
8
6
  * key or a root `$ref` key. If the `schemaToCompare` has a root `oneOf` property, the function will
@@ -25,7 +23,7 @@ export default function isRootSchema<T = any, S extends StrictRJSFSchema = RJSFS
25
23
  }
26
24
  if (REF_KEY in rootSchema) {
27
25
  const resolvedSchema = schemaUtils.retrieveSchema(rootSchema);
28
- return deepEquals(schemaToCompare, omit(resolvedSchema, RJSF_REF_KEY));
26
+ return deepEquals(schemaToCompare, resolvedSchema);
29
27
  }
30
28
  return false;
31
29
  }
package/src/labelValue.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ReactElement } from 'react';
1
+ import type { ReactElement } from 'react';
2
2
 
3
3
  /** Helper function that will return the value to use for a widget `label` based on `hideLabel`. The `fallback` is used
4
4
  * as the return value from the function when `hideLabel` is true. Due to the implementation of theme components, it
@@ -0,0 +1,28 @@
1
+ import enumOptionsIndexForValue from './enumOptionsIndexForValue';
2
+ import type { EnumOptionsType, RJSFSchema, StrictRJSFSchema } from './types';
3
+
4
+ /** Logs a warning when a single-select enum widget has a schema default that is not one of its enum options.
5
+ *
6
+ * @param id - The field id used in the warning message
7
+ * @param schema - The schema whose default value is checked
8
+ * @param enumOptions - The enum options available to the widget
9
+ * @param multiple - Whether the widget allows multiple selections
10
+ */
11
+ export default function logUnsupportedDefaultForEnum<S extends StrictRJSFSchema = RJSFSchema>(
12
+ id: string,
13
+ schema: S,
14
+ enumOptions?: EnumOptionsType<S>[],
15
+ multiple = false,
16
+ ) {
17
+ if (
18
+ !multiple &&
19
+ Array.isArray(enumOptions) &&
20
+ schema.default !== undefined &&
21
+ enumOptionsIndexForValue<S>(schema.default, enumOptions, multiple) === undefined
22
+ ) {
23
+ // oxlint-disable-next-line no-console
24
+ console.error(
25
+ `The schema default value "${schema.default}" is not one of the values in the enum options for "${id}"`,
26
+ );
27
+ }
28
+ }
@@ -2,7 +2,7 @@ import get from 'lodash/get';
2
2
  import has from 'lodash/has';
3
3
 
4
4
  import { FORM_CONTEXT_NAME, LOOKUP_MAP_NAME } from './constants';
5
- import { FormContextType, RJSFSchema, Registry, StrictRJSFSchema } from './types';
5
+ import type { FormContextType, RJSFSchema, Registry, StrictRJSFSchema } from './types';
6
6
 
7
7
  /** Given a React JSON Schema Form registry or formContext object, return the value associated with `toLookup`. This
8
8
  * might be contained within the lookup map in the formContext. If no such value exists, return the `fallback`
@@ -1,7 +1,7 @@
1
1
  import get from 'lodash/get';
2
2
  import isNil from 'lodash/isNil';
3
3
 
4
- import { GenericObjectType } from '../src';
4
+ import type { GenericObjectType } from '../src';
5
5
  import isObject from './isObject';
6
6
 
7
7
  /** Merges the `defaults` object of type `T` into the `formData` of type `T`
@@ -43,7 +43,7 @@ export default function mergeDefaultsWithFormData<T = any>(
43
43
  const mapped = overrideArray.map((value, idx) => {
44
44
  // We want to explicitly make sure that the value is NOT undefined since null, 0 and empty space are valid values
45
45
  if (overrideOppositeArray[idx] !== undefined) {
46
- return mergeDefaultsWithFormData<any>(
46
+ return mergeDefaultsWithFormData(
47
47
  defaultsArray[idx],
48
48
  formData[idx],
49
49
  mergeExtraArrayDefaults,
@@ -62,8 +62,9 @@ export default function mergeDefaultsWithFormData<T = any>(
62
62
  return mapped as unknown as T;
63
63
  }
64
64
  if (isObject(formData)) {
65
+ // oxlint-disable-next-line prefer-object-spread -- spread loses T type, Object.assign preserves it
65
66
  const acc: { [key in keyof T]: any } = Object.assign({}, defaults); // Prevent mutation of source object.
66
- return Object.keys(formData as GenericObjectType).reduce((acc, key) => {
67
+ return Object.keys(formData as GenericObjectType).reduce((accumulator, key) => {
67
68
  const keyValue = get(formData, key);
68
69
  const keyExistsInDefaults = isObject(defaults) && key in (defaults as GenericObjectType);
69
70
  const keyExistsInFormData = key in (formData as GenericObjectType);
@@ -75,14 +76,14 @@ export default function mergeDefaultsWithFormData<T = any>(
75
76
  const keyHasFormDataObject = keyExistsInFormData && isObject(keyValue);
76
77
 
77
78
  if (keyDefaultIsObject && keyHasFormDataObject && !defaultValueIsNestedObject) {
78
- acc[key as keyof T] = {
79
+ accumulator[key as keyof T] = {
79
80
  ...get(defaults, key),
80
81
  ...keyValue,
81
82
  };
82
- return acc;
83
+ return accumulator;
83
84
  }
84
85
 
85
- acc[key as keyof T] = mergeDefaultsWithFormData<T>(
86
+ accumulator[key as keyof T] = mergeDefaultsWithFormData<T>(
86
87
  get(defaults, key),
87
88
  keyValue,
88
89
  mergeExtraArrayDefaults,
@@ -103,7 +104,7 @@ export default function mergeDefaultsWithFormData<T = any>(
103
104
  */
104
105
  if (
105
106
  (defaultSupercedesUndefined &&
106
- ((!(defaults === undefined) && isNil(formData)) || (typeof formData === 'number' && isNaN(formData)))) ||
107
+ ((!(defaults === undefined) && isNil(formData)) || (typeof formData === 'number' && Number.isNaN(formData)))) ||
107
108
  (overrideFormDataWithDefaults && !isNil(formData))
108
109
  ) {
109
110
  return defaults;
@@ -1,5 +1,5 @@
1
1
  import isObject from './isObject';
2
- import { GenericObjectType } from './types';
2
+ import type { GenericObjectType } from './types';
3
3
 
4
4
  /** Recursively merge deeply nested objects.
5
5
  *
@@ -37,6 +37,6 @@ export default function mergeObjects(
37
37
  }
38
38
  return acc;
39
39
  },
40
- Object.assign({}, obj1),
40
+ { ...obj1 },
41
41
  ); // Prevent mutation of source object.
42
42
  }
@@ -3,7 +3,7 @@ import union from 'lodash/union';
3
3
  import { REQUIRED_KEY } from './constants';
4
4
  import getSchemaType from './getSchemaType';
5
5
  import isObject from './isObject';
6
- import { GenericObjectType } from './types';
6
+ import type { GenericObjectType, GenericSymbolObjectType } from './types';
7
7
 
8
8
  /** Recursively merge deeply nested schemas. The difference between `mergeSchemas` and `mergeObjects` is that
9
9
  * `mergeSchemas` only concats arrays for values under the 'required' keyword, and when it does, it doesn't include
@@ -14,12 +14,12 @@ import { GenericObjectType } from './types';
14
14
  * @returns - The merged schema object
15
15
  */
16
16
  export default function mergeSchemas(obj1: GenericObjectType, obj2: GenericObjectType) {
17
- const acc = Object.assign({}, obj1); // Prevent mutation of source object.
18
- return Object.keys(obj2).reduce((acc, key) => {
17
+ const acc = { ...obj1 }; // Prevent mutation of source object.
18
+ const result = Object.keys(obj2).reduce((accumulator, key) => {
19
19
  const left = obj1 ? obj1[key] : {},
20
20
  right = obj2[key];
21
21
  if (obj1 && key in obj1 && isObject(right)) {
22
- acc[key] = mergeSchemas(left, right);
22
+ accumulator[key] = mergeSchemas(left, right);
23
23
  } else if (
24
24
  obj1 &&
25
25
  obj2 &&
@@ -29,10 +29,17 @@ export default function mergeSchemas(obj1: GenericObjectType, obj2: GenericObjec
29
29
  Array.isArray(right)
30
30
  ) {
31
31
  // Don't include duplicate values when merging 'required' fields.
32
- acc[key] = union(left, right);
32
+ accumulator[key] = union(left, right);
33
33
  } else {
34
- acc[key] = right;
34
+ accumulator[key] = right;
35
35
  }
36
- return acc;
36
+ return accumulator;
37
37
  }, acc);
38
+ // Copy own Symbol-keyed properties from obj2 (Object.keys skips them).
39
+ for (const sym of Object.getOwnPropertySymbols(obj2)) {
40
+ // To avoid issues with symbols, we cast them to GenericSymbolObjectType. If we make the mergeSchema function take
41
+ // in GenericSymbolObjectType rather than GenericObjectType, it causes a bunch of type errors downstream
42
+ (result as GenericSymbolObjectType)[sym] = (obj2 as GenericSymbolObjectType)[sym];
43
+ }
44
+ return result;
38
45
  }
@@ -1,4 +1,4 @@
1
- import { NameGeneratorFunction, FieldPathList } from './types';
1
+ import type { NameGeneratorFunction, FieldPathList } from './types';
2
2
 
3
3
  /**
4
4
  * Generates bracketed names
@@ -4,7 +4,7 @@ import { CONST_KEY, DEFAULT_KEY, PROPERTIES_KEY } from './constants';
4
4
  import getDiscriminatorFieldFromSchema from './getDiscriminatorFieldFromSchema';
5
5
  import getUiOptions from './getUiOptions';
6
6
  import toConstant from './toConstant';
7
- import { RJSFSchema, EnumOptionsType, EnumValue, StrictRJSFSchema, FormContextType, UiSchema } from './types';
7
+ import type { RJSFSchema, EnumOptionsType, EnumValue, StrictRJSFSchema, FormContextType, UiSchema } from './types';
8
8
 
9
9
  /** Reorders `options` according to `order`, which may contain a `'*'` wildcard representing all
10
10
  * remaining options in their original order. Options not listed in `order` (and not covered by
@@ -79,26 +79,24 @@ export default function optionsList<T = any, S extends StrictRJSFSchema = RJSFSc
79
79
  const { optionsSchemaSelector = selectorField } = getUiOptions<T, S, F>(uiSchema);
80
80
  selectorField = optionsSchemaSelector;
81
81
  }
82
- return (
83
- altSchemas &&
84
- altSchemas.map((aSchemaDef, index) => {
85
- const { title } = getUiOptions<T, S, F>(altUiSchemas?.[index]);
86
- const aSchema = aSchemaDef as S;
87
- let value: EnumOptionsType<S>['value'];
88
- let label = title;
89
- if (selectorField) {
90
- const innerSchema: S = get(aSchema, [PROPERTIES_KEY, selectorField], {}) as S;
91
- value = get(innerSchema, DEFAULT_KEY, get(innerSchema, CONST_KEY));
92
- label = label || innerSchema?.title || aSchema.title || String(value);
93
- } else {
94
- value = toConstant(aSchema);
95
- label = label || aSchema.title || String(value);
96
- }
97
- return {
98
- schema: aSchema,
99
- label,
100
- value,
101
- };
102
- })
103
- );
82
+ return altSchemas?.map((aSchemaDef, index) => {
83
+ const { title } = getUiOptions<T, S, F>(altUiSchemas?.[index]);
84
+ const aSchema = aSchemaDef as S;
85
+ let value: EnumOptionsType<S>['value'];
86
+ let label = title;
87
+ if (selectorField) {
88
+ const innerSchema: S = get(aSchema, [PROPERTIES_KEY, selectorField], {}) as S;
89
+ value = get(innerSchema, DEFAULT_KEY, get(innerSchema, CONST_KEY));
90
+ // Use nullish coalescing so that an explicitly empty string title is preserved
91
+ label = label ?? innerSchema?.title ?? aSchema.title ?? String(value);
92
+ } else {
93
+ value = toConstant(aSchema);
94
+ label = label ?? aSchema.title ?? String(value);
95
+ }
96
+ return {
97
+ schema: aSchema,
98
+ label,
99
+ value,
100
+ };
101
+ });
104
102
  }
@@ -1,4 +1,4 @@
1
- import { GenericObjectType } from './types';
1
+ import type { GenericObjectType } from './types';
2
2
 
3
3
  /** Given a list of `properties` and an `order` list, returns a list that contains the `properties` ordered correctly.
4
4
  * If `order` is not an array, then the untouched `properties` list is returned. Otherwise `properties` is ordered per
@@ -16,9 +16,9 @@ export default function orderProperties(properties: string[], order?: string[]):
16
16
  }
17
17
 
18
18
  const arrayToHash = (arr: string[]) =>
19
- arr.reduce((prev: GenericObjectType, curr) => {
20
- prev[curr] = true;
21
- return prev;
19
+ arr.reduce((acc: GenericObjectType, curr) => {
20
+ acc[curr] = true;
21
+ return acc;
22
22
  }, {});
23
23
  const errorPropList = (arr: string[]) =>
24
24
  arr.length > 1 ? `properties '${arr.join("', '")}'` : `property '${arr[0]}'`;
package/src/pad.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  export default function pad(num: number, width: number) {
8
8
  let s = String(num);
9
9
  while (s.length < width) {
10
- s = '0' + s;
10
+ s = `0${s}`;
11
11
  }
12
12
  return s;
13
13
  }