@rjsf/utils 5.22.2 → 5.22.4
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.
- package/dist/index.js +11 -6
- package/dist/index.js.map +2 -2
- package/dist/utils.esm.js +11 -6
- package/dist/utils.esm.js.map +2 -2
- package/dist/utils.umd.js +11 -6
- package/lib/schema/getDefaultFormState.js +13 -6
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/schema/getDefaultFormState.ts +14 -6
|
@@ -219,8 +219,8 @@ export function computeDefaults<T = any, S extends StrictRJSFSchema = RJSFSchema
|
|
|
219
219
|
} else if (DEPENDENCIES_KEY in schema) {
|
|
220
220
|
// Get the default if set from properties to ensure the dependencies conditions are resolved based on it
|
|
221
221
|
const defaultFormData: T = {
|
|
222
|
-
...formData,
|
|
223
222
|
...getDefaultBasedOnSchemaType(validator, schema, computeDefaultsProps, defaults),
|
|
223
|
+
...formData,
|
|
224
224
|
};
|
|
225
225
|
const resolvedSchema = resolveDependencies<T, S, F>(
|
|
226
226
|
validator,
|
|
@@ -432,11 +432,14 @@ export function getArrayDefaults<T = any, S extends StrictRJSFSchema = RJSFSchem
|
|
|
432
432
|
): T | T[] | undefined {
|
|
433
433
|
const schema: S = rawSchema;
|
|
434
434
|
|
|
435
|
-
const
|
|
436
|
-
const
|
|
435
|
+
const arrayMinItemsStateBehavior = experimental_defaultFormStateBehavior?.arrayMinItems ?? {};
|
|
436
|
+
const { populate: arrayMinItemsPopulate, mergeExtraDefaults: arrayMergeExtraDefaults } = arrayMinItemsStateBehavior;
|
|
437
|
+
|
|
438
|
+
const neverPopulate = arrayMinItemsPopulate === 'never';
|
|
439
|
+
const ignoreMinItemsFlagSet = arrayMinItemsPopulate === 'requiredOnly';
|
|
440
|
+
const isPopulateAll = arrayMinItemsPopulate === 'all' || (!neverPopulate && !ignoreMinItemsFlagSet);
|
|
441
|
+
const computeSkipPopulate = arrayMinItemsStateBehavior?.computeSkipPopulate ?? (() => false);
|
|
437
442
|
const isSkipEmptyDefaults = experimental_defaultFormStateBehavior?.emptyObjectFields === 'skipEmptyDefaults';
|
|
438
|
-
const computeSkipPopulate =
|
|
439
|
-
experimental_defaultFormStateBehavior?.arrayMinItems?.computeSkipPopulate ?? (() => false);
|
|
440
443
|
|
|
441
444
|
const emptyDefault = isSkipEmptyDefaults ? undefined : [];
|
|
442
445
|
|
|
@@ -460,7 +463,7 @@ export function getArrayDefaults<T = any, S extends StrictRJSFSchema = RJSFSchem
|
|
|
460
463
|
if (neverPopulate) {
|
|
461
464
|
defaults = rawFormData;
|
|
462
465
|
} else {
|
|
463
|
-
|
|
466
|
+
const itemDefaults = rawFormData.map((item: T, idx: number) => {
|
|
464
467
|
return computeDefaults<T, S, F>(validator, schemaItem, {
|
|
465
468
|
rootSchema,
|
|
466
469
|
_recurseList,
|
|
@@ -470,6 +473,11 @@ export function getArrayDefaults<T = any, S extends StrictRJSFSchema = RJSFSchem
|
|
|
470
473
|
required,
|
|
471
474
|
});
|
|
472
475
|
}) as T[];
|
|
476
|
+
|
|
477
|
+
// If the populate 'requiredOnly' flag is set then we only merge and include extra defaults if they are required.
|
|
478
|
+
// Or if populate 'all' is set we merge and include extra defaults.
|
|
479
|
+
const mergeExtraDefaults = ((ignoreMinItemsFlagSet && required) || isPopulateAll) && arrayMergeExtraDefaults;
|
|
480
|
+
defaults = mergeDefaultsWithFormData(defaults, itemDefaults, mergeExtraDefaults);
|
|
473
481
|
}
|
|
474
482
|
}
|
|
475
483
|
|