@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
@@ -8,7 +8,7 @@ import findSchemaDefinition from '../findSchemaDefinition';
8
8
  import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema';
9
9
  import getSchemaType from '../getSchemaType';
10
10
  import isObject from '../isObject';
11
- import {
11
+ import type {
12
12
  Experimental_CustomMergeAllOf,
13
13
  FormContextType,
14
14
  GenericObjectType,
@@ -48,6 +48,7 @@ export function getUsedFormData<T = any>(formData: T | undefined, fields: string
48
48
  * @param [formData] - The form data to use while checking for empty objects/arrays
49
49
  * @deprecated - To be removed as an exported `@rjsf/utils` function in a future release
50
50
  */
51
+ // oxlint-disable-next-line typescript/no-deprecated
51
52
  export function getFieldNames<T = any>(pathSchema: PathSchema<T>, formData?: T): string[][] {
52
53
  const formValueHasData = (value: T, isLeaf: boolean) =>
53
54
  typeof value !== 'object' || isEmpty(value) || (isLeaf && !isEmpty(value));
@@ -170,14 +171,14 @@ export default function omitExtraData<
170
171
  * are always written when defined. Always returns `target` — pruning of the object itself is
171
172
  * the caller's responsibility.
172
173
  *
173
- * @param schema - The object schema describing which properties are allowed
174
+ * @param childSchema - The object schema describing which properties are allowed
174
175
  * @param source - The source form data object to read values from
175
176
  * @param target - The accumulator object to write filtered values into
176
177
  * @returns - `target` after all schema-defined properties have been processed
177
178
  */
178
- function handleObject(schema: S, source: GenericObjectType, target: GenericObjectType): GenericObjectType {
179
- const { properties, additionalProperties, patternProperties, propertyNames } = schema;
180
- const requiredSet = new Set((schema.required ?? []) as string[]);
179
+ function handleObject(childSchema: S, source: GenericObjectType, target: GenericObjectType): GenericObjectType {
180
+ const { properties, additionalProperties, patternProperties, propertyNames } = childSchema;
181
+ const requiredSet = new Set(childSchema.required ?? []);
181
182
 
182
183
  /** Recursively omits extra data from `value` via `omit`, then conditionally writes the result to
183
184
  * `target[key]`. Optional object-valued properties are dropped when every key in the filtered
@@ -196,11 +197,11 @@ export default function omitExtraData<
196
197
  const v = omit(schemaDef, value, target[key]);
197
198
  if (!required && isObject(v)) {
198
199
  // Resolve $ref so we can inspect the effective required list for the inner schema.
199
- let sd = isSchemaObj(schemaDef as S | boolean) ? (schemaDef as S) : ({} as S);
200
+ let sd = isSchemaObj(schemaDef) ? schemaDef : ({} as S);
200
201
  if (sd.$ref !== undefined) {
201
- sd = findSchemaDefinition(sd.$ref, rootSchema) as S;
202
+ sd = findSchemaDefinition<S>(sd.$ref, rootSchema);
202
203
  }
203
- const innerRequired = new Set((sd.required ?? []) as string[]);
204
+ const innerRequired = new Set(sd.required ?? []);
204
205
  // Drop this optional object when every key in v is both optional in the inner schema
205
206
  // and has an empty value. Vacuously true for {} so empty objects are always dropped.
206
207
  const shouldDrop = Object.entries(v as GenericObjectType).every(
@@ -211,6 +212,7 @@ export default function omitExtraData<
211
212
  }
212
213
  }
213
214
  if (v !== undefined) {
215
+ // oxlint-disable-next-line no-param-reassign
214
216
  target[key] = v;
215
217
  }
216
218
  }
@@ -231,15 +233,14 @@ export default function omitExtraData<
231
233
  ]);
232
234
  const knownProperties = new Set(Object.keys(properties ?? {}));
233
235
  for (const [key, value] of Object.entries(source)) {
234
- if (knownProperties.has(key)) {
235
- continue;
236
- }
237
- const matched = patterns.find(([re]) => re.test(key));
238
- if (matched === undefined) {
239
- patternPropertiesRest.push(key);
240
- continue;
236
+ if (!knownProperties.has(key)) {
237
+ const matched = patterns.find(([re]) => re.test(key));
238
+ if (matched === undefined) {
239
+ patternPropertiesRest.push(key);
240
+ } else {
241
+ setProperty(key, matched[1], value);
242
+ }
241
243
  }
242
- setProperty(key, matched[1], value);
243
244
  }
244
245
  }
245
246
 
@@ -254,10 +255,9 @@ export default function omitExtraData<
254
255
  } else {
255
256
  const knownProperties = new Set(Object.keys(properties ?? {}));
256
257
  for (const [key, value] of Object.entries(source)) {
257
- if (knownProperties.has(key)) {
258
- continue;
258
+ if (!knownProperties.has(key)) {
259
+ setProperty(key, addlSchema, value);
259
260
  }
260
- setProperty(key, addlSchema, value);
261
261
  }
262
262
  }
263
263
  }
@@ -265,6 +265,7 @@ export default function omitExtraData<
265
265
  // When propertyNames is present, the schema only constrains key names — all source keys are valid.
266
266
  if (propertyNames !== undefined) {
267
267
  for (const [key, value] of Object.entries(source)) {
268
+ // oxlint-disable-next-line no-param-reassign
268
269
  target[key] = value;
269
270
  }
270
271
  }
@@ -277,27 +278,27 @@ export default function omitExtraData<
277
278
  * per-index schema; elements beyond the tuple length are covered by `additionalItems` when present.
278
279
  * For list schemas (`items` is a single schema) every element is filtered by that schema.
279
280
  *
280
- * @param schema - The array schema describing `items` and optionally `additionalItems`
281
+ * @param childSchema - The array schema describing `items` and optionally `additionalItems`
281
282
  * @param source - The source array to read elements from
282
283
  * @param target - The accumulator array to push filtered elements into
283
284
  * @returns - `target` after all applicable source elements have been pushed
284
285
  */
285
- function handleArray(schema: S, source: unknown[], target: unknown[]): unknown[] {
286
- const { items, additionalItems } = schema;
286
+ function handleArray(childSchema: S, source: unknown[], target: unknown[]): unknown[] {
287
+ const { items, additionalItems } = childSchema;
287
288
  if (items !== undefined) {
288
289
  if (Array.isArray(items)) {
289
- for (let i = 0; i < items.length; i++) {
290
+ for (let i = 0; i < items.length; i += 1) {
290
291
  target.push(omit(items[i] as S | boolean, source[i]));
291
292
  }
292
293
  } else {
293
- for (let i = 0; i < source.length; i++) {
294
+ for (let i = 0; i < source.length; i += 1) {
294
295
  target.push(omit(items as S | boolean, source[i]));
295
296
  }
296
297
  }
297
298
  }
298
299
  // additionalItems covers tuple items beyond the items array length.
299
300
  if (additionalItems) {
300
- for (let i = target.length; i < source.length; i++) {
301
+ for (let i = target.length; i < source.length; i += 1) {
301
302
  target.push(omit(additionalItems as S | boolean, source[i]));
302
303
  }
303
304
  }
@@ -310,13 +311,13 @@ export default function omitExtraData<
310
311
  * (`then` or `else`) is applied via `omit`. When the selected branch is absent, `target` is returned
311
312
  * unchanged.
312
313
  *
313
- * @param schema - The schema potentially containing `if`, `then`, and `else` keywords
314
+ * @param childSchema - The schema potentially containing `if`, `then`, and `else` keywords
314
315
  * @param source - The current form data value, passed to `validator.isValid` and the branch `omit`
315
316
  * @param target - The already-filtered value to merge the branch result into
316
317
  * @returns - The result of applying the matched branch, or `target` when no branch applies
317
318
  */
318
- function handleConditions(schema: S, source: unknown, target: unknown): unknown {
319
- const { if: condition, then, else: otherwise } = schema;
319
+ function handleConditions(childSchema: S, source: unknown, target: unknown): unknown {
320
+ const { if: condition, then, else: otherwise } = childSchema;
320
321
  if (condition === undefined) {
321
322
  return target;
322
323
  }
@@ -335,33 +336,33 @@ export default function omitExtraData<
335
336
  * actual `omit` call.
336
337
  *
337
338
  * @param oneOf - The `oneOf` array from the schema, or `undefined`
338
- * @param schema - The parent schema containing the `oneOf` keyword
339
+ * @param childSchema - The parent schema containing the `oneOf` keyword
339
340
  * @param source - The current form data value used to score each option
340
341
  * @param target - The already-filtered value to merge the winning option's result into
341
342
  * @returns - The result of applying the best-matching option, or `target` when no matching applies
342
343
  */
343
- function handleOneOf(oneOf: S['oneOf'], schema: S, source: unknown, target: unknown): unknown {
344
- if (!Array.isArray(oneOf) || isSelect(validator, schema, rootSchema, experimental_customMergeAllOf)) {
344
+ function handleOneOf(oneOf: S['oneOf'], childSchema: S, source: unknown, target: unknown): unknown {
345
+ if (!Array.isArray(oneOf) || isSelect(validator, childSchema, rootSchema, experimental_customMergeAllOf)) {
345
346
  return target;
346
347
  }
347
348
  // Resolve $refs and relax additionalProperties:false → true in one pass for scoring only.
348
349
  // The unrelaxed resolved schema is re-derived for the winning option so that omit() still
349
350
  // respects additionalProperties:false during filtering.
350
- const scoringOptions = relaxOptionsForScoring<S>(oneOf as Array<S | boolean>, true, rootSchema);
351
+ const scoringOptions = relaxOptionsForScoring<S>(oneOf as (S | boolean)[], true, rootSchema);
351
352
  const bestIndex = getClosestMatchingOption<T, S, F>(
352
353
  validator,
353
354
  rootSchema,
354
355
  source as T,
355
356
  scoringOptions,
356
357
  0,
357
- getDiscriminatorFieldFromSchema<S>(schema),
358
+ getDiscriminatorFieldFromSchema<S>(childSchema),
358
359
  experimental_customMergeAllOf,
359
360
  );
360
- const winning = (oneOf as Array<S | boolean>)[bestIndex];
361
+ const winning = (oneOf as (S | boolean)[])[bestIndex];
361
362
  // For object options, re-resolve without relaxation so additionalProperties:false is respected.
362
363
  // For boolean options, scoringOptions already holds the converted schema (true→{}, false→{not:{}}).
363
364
  const resolved: S = isObject(winning)
364
- ? resolveAllReferences<S>(winning as S, rootSchema, [])
365
+ ? resolveAllReferences<S>(winning, rootSchema, [])
365
366
  : scoringOptions[bestIndex];
366
367
  return omit(resolved, source, target);
367
368
  }
@@ -371,13 +372,13 @@ export default function omitExtraData<
371
372
  * defaults can flow through all branches) every branch is applied in sequence. For non-empty sources
372
373
  * the best-matching branch is selected via `handleOneOf`.
373
374
  *
374
- * @param schema - The schema potentially containing an `anyOf` keyword
375
+ * @param childSchema - The schema potentially containing an `anyOf` keyword
375
376
  * @param source - The current form data value; empty or undefined triggers all-branch application
376
377
  * @param target - The already-filtered value to merge branch results into
377
378
  * @returns - The result after applying the relevant `anyOf` branch(es), or `target` when inapplicable
378
379
  */
379
- function handleAnyOf(schema: S, source: unknown, target: unknown): unknown {
380
- const { anyOf } = schema;
380
+ function handleAnyOf(childSchema: S, source: unknown, target: unknown): unknown {
381
+ const { anyOf } = childSchema;
381
382
  if (!Array.isArray(anyOf)) {
382
383
  return target;
383
384
  }
@@ -385,14 +386,15 @@ export default function omitExtraData<
385
386
  if (
386
387
  source === undefined ||
387
388
  (Array.isArray(source) && source.length === 0) ||
388
- (isObject(source) && Object.keys(source as object).length === 0)
389
+ (isObject(source) && Object.keys(source).length === 0)
389
390
  ) {
390
- for (const branch of anyOf as Array<S | boolean>) {
391
- target = omit(branch, source, target);
391
+ let result = target;
392
+ for (const branch of anyOf as (S | boolean)[]) {
393
+ result = omit(branch, source, result);
392
394
  }
393
- return target;
395
+ return result;
394
396
  }
395
- return handleOneOf(anyOf, schema, source, target);
397
+ return handleOneOf(anyOf, childSchema, source, target);
396
398
  }
397
399
 
398
400
  /** Applies schema-based `dependencies` from `schema` to `source`, merging each active dependency's
@@ -400,24 +402,24 @@ export default function omitExtraData<
400
402
  * schema dependencies are processed. A dependency is considered active when its trigger key is
401
403
  * present on `source`.
402
404
  *
403
- * @param schema - The schema potentially containing a `dependencies` keyword
405
+ * @param childSchema - The schema potentially containing a `dependencies` keyword
404
406
  * @param source - The current form data value; must be a plain object for dependencies to apply
405
407
  * @param target - The already-filtered value to merge dependency results into
406
408
  * @returns - The result after applying all active schema dependencies, or `target` when inapplicable
407
409
  */
408
- function handleDependencies(schema: S, source: unknown, target: unknown): unknown {
409
- const { dependencies } = schema;
410
+ function handleDependencies(childSchema: S, source: unknown, target: unknown): unknown {
411
+ const { dependencies } = childSchema;
410
412
  if (dependencies === undefined || !isObjectValue(source)) {
411
413
  return target;
412
414
  }
415
+ let result = target;
413
416
  for (const [key, deps] of Object.entries(dependencies)) {
414
417
  // Skip property dependencies (string arrays); only process schema dependencies.
415
- if (!(key in source) || Array.isArray(deps)) {
416
- continue;
418
+ if (key in source && !Array.isArray(deps)) {
419
+ result = omit(deps as S | boolean, source, result);
417
420
  }
418
- target = omit(deps as S | boolean, source, target);
419
421
  }
420
- return target;
422
+ return result;
421
423
  }
422
424
 
423
425
  /** Core recursive filter. Resolves `$ref`s, merges `allOf`, then delegates to the type-specific
@@ -438,34 +440,45 @@ export default function omitExtraData<
438
440
  return source;
439
441
  }
440
442
 
441
- let schema = schemaDef as S;
442
- const { $ref: ref, allOf } = schema;
443
+ let localSchema = schemaDef;
444
+ const { $ref: ref, allOf } = localSchema;
443
445
 
444
446
  if (ref !== undefined) {
445
447
  return omit(findSchemaDefinition<S>(ref, rootSchema), source, target);
446
448
  }
447
449
  if (allOf) {
448
- schema = doMergeAllOf<S>(schema, experimental_customMergeAllOf);
450
+ localSchema = doMergeAllOf<S>(localSchema, experimental_customMergeAllOf);
451
+ // Schemas whose allOf entries contain if/then/else keywords may not fully merge: the merger
452
+ // can only hoist one if/then/else triple to the parent level, so additional entries stay in
453
+ // allOf. Process any that remain so their conditional properties are not silently dropped.
454
+ // See: https://github.com/rjsf-team/react-jsonschema-form/issues/5142
455
+ const remainingAllOf = localSchema.allOf;
456
+ if (remainingAllOf) {
457
+ for (let i = 0; i < remainingAllOf.length; i++) {
458
+ // oxlint-disable-next-line no-param-reassign
459
+ target = omit(remainingAllOf[i] as S | boolean, source, target);
460
+ }
461
+ }
449
462
  }
450
463
 
451
- target = handleAnyOf(schema, source, handleOneOf(schema.oneOf, schema, source, target));
464
+ let filtered = handleAnyOf(localSchema, source, handleOneOf(localSchema.oneOf, localSchema, source, target));
452
465
 
453
- const type = getSchemaType<S>(schema);
466
+ const type = getSchemaType<S>(localSchema);
454
467
  if (type === 'object') {
455
468
  if (!isObjectValue(source)) {
456
469
  return undefined;
457
470
  }
458
- target = handleObject(schema, source, isObjectValue(target) ? target : {});
471
+ filtered = handleObject(localSchema, source, isObjectValue(filtered) ? filtered : {});
459
472
  } else if (type === 'array') {
460
473
  if (!Array.isArray(source)) {
461
474
  return undefined;
462
475
  }
463
- target = handleArray(schema, source, Array.isArray(target) ? target : []);
464
- } else if (target === undefined) {
465
- target = source;
476
+ filtered = handleArray(localSchema, source, Array.isArray(filtered) ? filtered : []);
477
+ } else if (filtered === undefined) {
478
+ filtered = source;
466
479
  }
467
480
 
468
- return handleDependencies(schema, source, handleConditions(schema, source, target));
481
+ return handleDependencies(localSchema, source, handleConditions(localSchema, source, filtered));
469
482
  }
470
483
 
471
484
  return omit(schema, formData) as T | undefined;