@rjsf/utils 6.5.2 → 6.6.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.
- package/dist/index.cjs +628 -441
- package/dist/index.cjs.map +4 -4
- package/dist/utils.esm.js +624 -437
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +632 -445
- package/lib/ErrorSchemaBuilder.js.map +1 -1
- package/lib/canExpand.js.map +1 -1
- package/lib/constIsAjvDataReference.js +1 -1
- package/lib/constIsAjvDataReference.js.map +1 -1
- package/lib/createSchemaUtils.js +3 -3
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/enumOptionSelectedValue.js.map +1 -1
- package/lib/enumOptionValueDecoder.js.map +1 -1
- package/lib/enumOptionsDeselectValue.js +1 -1
- package/lib/enumOptionsDeselectValue.js.map +1 -1
- package/lib/enumOptionsIndexForValue.js.map +1 -1
- package/lib/enumOptionsIsSelected.js.map +1 -1
- package/lib/enumOptionsSelectValue.js +1 -1
- package/lib/enumOptionsSelectValue.js.map +1 -1
- package/lib/enumOptionsValueForIndex.js +2 -2
- package/lib/enumOptionsValueForIndex.js.map +1 -1
- package/lib/enums.d.ts +2 -0
- package/lib/enums.js +2 -0
- package/lib/enums.js.map +1 -1
- package/lib/findSchemaDefinition.js +4 -4
- package/lib/findSchemaDefinition.js.map +1 -1
- package/lib/getChangedFields.js +3 -3
- package/lib/getChangedFields.js.map +1 -1
- package/lib/getDiscriminatorFieldFromSchema.js.map +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -1
- package/lib/getTestIds.d.ts +1 -1
- package/lib/getTestIds.js +4 -3
- package/lib/getTestIds.js.map +1 -1
- package/lib/getWidget.js +1 -1
- package/lib/getWidget.js.map +1 -1
- package/lib/idGenerators.js.map +1 -1
- package/lib/index.d.ts +6 -6
- package/lib/index.js +6 -6
- package/lib/index.js.map +1 -1
- package/lib/isFormDataAvailable.js +1 -1
- package/lib/isFormDataAvailable.js.map +1 -1
- package/lib/isRootSchema.js +1 -1
- package/lib/isRootSchema.js.map +1 -1
- package/lib/jsonSchemaAugmentation.d.ts +19 -0
- package/lib/jsonSchemaAugmentation.js +2 -0
- package/lib/jsonSchemaAugmentation.js.map +1 -0
- package/lib/mergeDefaultsWithFormData.js +2 -2
- package/lib/mergeDefaultsWithFormData.js.map +1 -1
- package/lib/parser/ParserValidator.js +1 -1
- package/lib/parser/ParserValidator.js.map +1 -1
- package/lib/parser/index.d.ts +1 -1
- package/lib/parser/index.js.map +1 -1
- package/lib/parser/schemaParser.js +2 -2
- package/lib/parser/schemaParser.js.map +1 -1
- package/lib/removeOptionalEmptyObjects.d.ts +2 -0
- package/lib/removeOptionalEmptyObjects.js +8 -29
- package/lib/removeOptionalEmptyObjects.js.map +1 -1
- package/lib/schema/findFieldInSchema.d.ts +2 -2
- package/lib/schema/findFieldInSchema.js +7 -6
- package/lib/schema/findFieldInSchema.js.map +1 -1
- package/lib/schema/findSelectedOptionInXxxOf.js +1 -1
- package/lib/schema/findSelectedOptionInXxxOf.js.map +1 -1
- package/lib/schema/getClosestMatchingOption.js +3 -3
- package/lib/schema/getClosestMatchingOption.js.map +1 -1
- package/lib/schema/getDefaultFormState.d.ts +4 -4
- package/lib/schema/getDefaultFormState.js +17 -22
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getFromSchema.d.ts +3 -3
- package/lib/schema/getFromSchema.js +3 -3
- package/lib/schema/getFromSchema.js.map +1 -1
- package/lib/schema/index.d.ts +4 -4
- package/lib/schema/index.js +4 -4
- package/lib/schema/index.js.map +1 -1
- package/lib/schema/isMultiSelect.js.map +1 -1
- package/lib/schema/omitExtraData.d.ts +18 -8
- package/lib/schema/omitExtraData.js +352 -16
- package/lib/schema/omitExtraData.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +15 -0
- package/lib/schema/retrieveSchema.js +36 -13
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/schema/sanitizeDataForNewSchema.js.map +1 -1
- package/lib/schema/shallowAllOfMerge.d.ts +11 -0
- package/lib/schema/shallowAllOfMerge.js +18 -0
- package/lib/schema/shallowAllOfMerge.js.map +1 -0
- package/lib/schema/toPathSchema.d.ts +1 -0
- package/lib/schema/toPathSchema.js +2 -1
- package/lib/schema/toPathSchema.js.map +1 -1
- package/lib/shouldRenderOptionalField.js +1 -1
- package/lib/shouldRenderOptionalField.js.map +1 -1
- package/lib/toErrorSchema.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +17 -5
- package/lib/types.js +1 -1
- package/lib/types.js.map +1 -1
- package/lib/useFileWidgetProps.d.ts +1 -1
- package/lib/useFileWidgetProps.js +9 -10
- package/lib/useFileWidgetProps.js.map +1 -1
- package/lib/withIdRefPrefix.js +1 -1
- package/lib/withIdRefPrefix.js.map +1 -1
- package/package.json +11 -11
- package/src/ErrorSchemaBuilder.ts +1 -1
- package/src/canExpand.ts +1 -1
- package/src/constIsAjvDataReference.ts +3 -2
- package/src/createSchemaUtils.ts +22 -20
- package/src/enumOptionSelectedValue.ts +1 -1
- package/src/enumOptionValueDecoder.ts +1 -1
- package/src/enumOptionsDeselectValue.ts +2 -2
- package/src/enumOptionsIndexForValue.ts +1 -1
- package/src/enumOptionsIsSelected.ts +1 -1
- package/src/enumOptionsSelectValue.ts +3 -2
- package/src/enumOptionsValueForIndex.ts +2 -2
- package/src/enums.ts +2 -0
- package/src/findSchemaDefinition.ts +4 -4
- package/src/getChangedFields.ts +4 -3
- package/src/getDiscriminatorFieldFromSchema.ts +1 -1
- package/src/getOptionMatchingSimpleDiscriminator.ts +1 -0
- package/src/getTestIds.ts +4 -3
- package/src/getWidget.tsx +2 -2
- package/src/idGenerators.ts +1 -1
- package/src/index.ts +6 -6
- package/src/isFormDataAvailable.ts +1 -1
- package/src/isRootSchema.ts +1 -1
- package/src/jsonSchemaAugmentation.ts +21 -0
- package/src/mergeDefaultsWithFormData.ts +4 -3
- package/src/parser/ParserValidator.ts +1 -1
- package/src/parser/index.ts +1 -1
- package/src/parser/schemaParser.ts +3 -3
- package/src/removeOptionalEmptyObjects.ts +8 -30
- package/src/schema/findFieldInSchema.ts +10 -8
- package/src/schema/findSelectedOptionInXxxOf.ts +1 -1
- package/src/schema/getClosestMatchingOption.ts +4 -4
- package/src/schema/getDefaultFormState.ts +18 -24
- package/src/schema/getFromSchema.ts +15 -8
- package/src/schema/index.ts +5 -3
- package/src/schema/isMultiSelect.ts +0 -1
- package/src/schema/omitExtraData.ts +398 -19
- package/src/schema/retrieveSchema.ts +41 -15
- package/src/schema/sanitizeDataForNewSchema.ts +1 -1
- package/src/schema/shallowAllOfMerge.ts +19 -0
- package/src/schema/toPathSchema.ts +2 -1
- package/src/shouldRenderOptionalField.ts +2 -2
- package/src/toErrorSchema.ts +1 -1
- package/src/tsconfig.json +0 -1
- package/src/types.ts +18 -5
- package/src/useFileWidgetProps.ts +9 -10
- package/src/withIdRefPrefix.ts +2 -1
|
@@ -1,31 +1,6 @@
|
|
|
1
|
-
import isNil from 'lodash/isNil';
|
|
2
|
-
|
|
3
1
|
import isObject from './isObject';
|
|
2
|
+
import { isValueEmpty, retrieveSchema } from './schema';
|
|
4
3
|
import { FormContextType, GenericObjectType, RJSFSchema, StrictRJSFSchema, ValidatorType } from './types';
|
|
5
|
-
import retrieveSchema from './schema/retrieveSchema';
|
|
6
|
-
|
|
7
|
-
/** Determines whether a value is considered "empty" for the purposes of optional object pruning.
|
|
8
|
-
* A value is empty if it is `undefined`, `null`, an empty string, or an object where all own
|
|
9
|
-
* properties are themselves empty.
|
|
10
|
-
*
|
|
11
|
-
* @param value - The value to check
|
|
12
|
-
* @returns True if the value is considered empty
|
|
13
|
-
*/
|
|
14
|
-
function isValueEmpty(value: unknown): boolean {
|
|
15
|
-
if (isNil(value) || value === '') {
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
if (Array.isArray(value)) {
|
|
19
|
-
// An empty array is considered empty; a non-empty array is not
|
|
20
|
-
return value.length === 0;
|
|
21
|
-
}
|
|
22
|
-
if (isObject(value)) {
|
|
23
|
-
const obj = value as GenericObjectType;
|
|
24
|
-
const keys = Object.keys(obj);
|
|
25
|
-
return keys.every((key) => isValueEmpty(obj[key]));
|
|
26
|
-
}
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
4
|
|
|
30
5
|
/** Recursively removes optional objects from the `formData` that are empty (i.e., all their fields
|
|
31
6
|
* are undefined, null, empty strings, or themselves empty optional objects). This solves the problem
|
|
@@ -41,7 +16,10 @@ function isValueEmpty(value: unknown): boolean {
|
|
|
41
16
|
* @param [formData] - The current form data to prune
|
|
42
17
|
* @returns - A new copy of `formData` with empty optional objects removed, or `undefined` if the
|
|
43
18
|
* entire formData was pruned
|
|
19
|
+
* @deprecated - This function will be removed in a future release. The equivalent pruning behavior
|
|
20
|
+
* is now built into `omitExtraData` — use that instead.
|
|
44
21
|
*/
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
45
23
|
export default function removeOptionalEmptyObjects<
|
|
46
24
|
T = any,
|
|
47
25
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
@@ -65,6 +43,7 @@ export default function removeOptionalEmptyObjects<
|
|
|
65
43
|
if (Array.isArray(itemsSchema)) {
|
|
66
44
|
itemSchema = itemsSchema[index] || (resolvedSchema.additionalItems as S) || ({} as S);
|
|
67
45
|
}
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
68
47
|
const cleaned = removeOptionalEmptyObjects<T, S, F>(validator, itemSchema, rootSchema, item);
|
|
69
48
|
if (cleaned !== item) {
|
|
70
49
|
hasChanges = true;
|
|
@@ -97,6 +76,7 @@ export default function removeOptionalEmptyObjects<
|
|
|
97
76
|
|
|
98
77
|
if ((isObj || isArr) && properties[key]) {
|
|
99
78
|
// Recursively process nested objects and arrays
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
100
80
|
const cleaned = removeOptionalEmptyObjects<T, S, F>(validator, propertySchema, rootSchema, value as T);
|
|
101
81
|
|
|
102
82
|
if (!isRequired && isValueEmpty(cleaned)) {
|
|
@@ -106,10 +86,8 @@ export default function removeOptionalEmptyObjects<
|
|
|
106
86
|
|
|
107
87
|
result[key] = cleaned;
|
|
108
88
|
hasAnyValue = true;
|
|
109
|
-
} else if (
|
|
110
|
-
//
|
|
111
|
-
continue;
|
|
112
|
-
} else {
|
|
89
|
+
} else if (isRequired || !isValueEmpty(value) || !properties[key]) {
|
|
90
|
+
// Keep: required, non-empty, or not schema-defined; skip optional empty scalars silently
|
|
113
91
|
result[key] = value;
|
|
114
92
|
if (!isValueEmpty(value)) {
|
|
115
93
|
hasAnyValue = true;
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
2
|
import has from 'lodash/has';
|
|
3
3
|
|
|
4
|
-
import findSelectedOptionInXxxOf from './findSelectedOptionInXxxOf';
|
|
5
|
-
import getFromSchema from './getFromSchema';
|
|
6
4
|
import { ANY_OF_KEY, ONE_OF_KEY, PROPERTIES_KEY, REQUIRED_KEY } from '../constants';
|
|
7
5
|
import {
|
|
8
6
|
Experimental_CustomMergeAllOf,
|
|
9
7
|
FormContextType,
|
|
10
8
|
FoundFieldType,
|
|
11
9
|
RJSFSchema,
|
|
10
|
+
SchemaFieldPath,
|
|
12
11
|
StrictRJSFSchema,
|
|
13
12
|
ValidatorType,
|
|
14
13
|
} from '../types';
|
|
14
|
+
import findSelectedOptionInXxxOf from './findSelectedOptionInXxxOf';
|
|
15
|
+
import getFromSchema from './getFromSchema';
|
|
15
16
|
|
|
16
17
|
/** Unique schema that represents no schema was found, exported for testing purposes */
|
|
17
18
|
export const NOT_FOUND_SCHEMA = { title: '!@#$_UNKNOWN_$#@!' };
|
|
@@ -37,7 +38,7 @@ export default function findFieldInSchema<
|
|
|
37
38
|
validator: ValidatorType<T, S, F>,
|
|
38
39
|
rootSchema: S,
|
|
39
40
|
schema: S,
|
|
40
|
-
path:
|
|
41
|
+
path: SchemaFieldPath,
|
|
41
42
|
formData: T = {} as T,
|
|
42
43
|
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
|
|
43
44
|
): FoundFieldType<S> {
|
|
@@ -46,6 +47,7 @@ export default function findFieldInSchema<
|
|
|
46
47
|
|
|
47
48
|
// store the desired field into a variable and removing it from the `pathList`
|
|
48
49
|
const fieldName = pathList.pop()!;
|
|
50
|
+
const fieldNameKey = String(fieldName);
|
|
49
51
|
|
|
50
52
|
if (pathList.length) {
|
|
51
53
|
// drilling into the schema for each sub-path and taking into account of the any/oneOfs
|
|
@@ -64,7 +66,7 @@ export default function findFieldInSchema<
|
|
|
64
66
|
validator,
|
|
65
67
|
rootSchema,
|
|
66
68
|
parentField,
|
|
67
|
-
|
|
69
|
+
fieldNameKey,
|
|
68
70
|
ONE_OF_KEY,
|
|
69
71
|
get(formData, subPath),
|
|
70
72
|
experimental_customMergeAllOf,
|
|
@@ -75,7 +77,7 @@ export default function findFieldInSchema<
|
|
|
75
77
|
validator,
|
|
76
78
|
rootSchema,
|
|
77
79
|
parentField,
|
|
78
|
-
|
|
80
|
+
fieldNameKey,
|
|
79
81
|
ANY_OF_KEY,
|
|
80
82
|
get(formData, subPath),
|
|
81
83
|
experimental_customMergeAllOf,
|
|
@@ -90,7 +92,7 @@ export default function findFieldInSchema<
|
|
|
90
92
|
validator,
|
|
91
93
|
rootSchema,
|
|
92
94
|
parentField,
|
|
93
|
-
|
|
95
|
+
fieldNameKey,
|
|
94
96
|
ONE_OF_KEY,
|
|
95
97
|
formData,
|
|
96
98
|
experimental_customMergeAllOf,
|
|
@@ -101,7 +103,7 @@ export default function findFieldInSchema<
|
|
|
101
103
|
validator,
|
|
102
104
|
rootSchema,
|
|
103
105
|
parentField,
|
|
104
|
-
|
|
106
|
+
fieldNameKey,
|
|
105
107
|
ANY_OF_KEY,
|
|
106
108
|
formData,
|
|
107
109
|
experimental_customMergeAllOf,
|
|
@@ -131,7 +133,7 @@ export default function findFieldInSchema<
|
|
|
131
133
|
);
|
|
132
134
|
let isRequired: boolean | undefined;
|
|
133
135
|
if (field && Array.isArray(requiredArray)) {
|
|
134
|
-
isRequired = requiredArray.includes(
|
|
136
|
+
isRequired = requiredArray.includes(fieldNameKey);
|
|
135
137
|
}
|
|
136
138
|
|
|
137
139
|
return { field, isRequired };
|
|
@@ -2,9 +2,9 @@ import get from 'lodash/get';
|
|
|
2
2
|
|
|
3
3
|
import { CONST_KEY, DEFAULT_KEY, PROPERTIES_KEY } from '../constants';
|
|
4
4
|
import deepEquals from '../deepEquals';
|
|
5
|
+
import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema';
|
|
5
6
|
import { Experimental_CustomMergeAllOf, FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
|
|
6
7
|
import retrieveSchema from './retrieveSchema';
|
|
7
|
-
import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema';
|
|
8
8
|
|
|
9
9
|
/** Finds the option inside the `schema['any/oneOf']` list which has the `properties[selectorField].default` or
|
|
10
10
|
* `properties[selectorField].const` that matches the `formData[selectorField]` value. For the purposes of this
|
|
@@ -6,13 +6,13 @@ import isString from 'lodash/isString';
|
|
|
6
6
|
import reduce from 'lodash/reduce';
|
|
7
7
|
import times from 'lodash/times';
|
|
8
8
|
|
|
9
|
-
import getFirstMatchingOption from './getFirstMatchingOption';
|
|
10
|
-
import retrieveSchema, { resolveAllReferences } from './retrieveSchema';
|
|
11
9
|
import { ONE_OF_KEY, REF_KEY, JUNK_OPTION_ID, ANY_OF_KEY } from '../constants';
|
|
12
|
-
import guessType from '../guessType';
|
|
13
|
-
import { Experimental_CustomMergeAllOf, FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
|
|
14
10
|
import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema';
|
|
15
11
|
import getOptionMatchingSimpleDiscriminator from '../getOptionMatchingSimpleDiscriminator';
|
|
12
|
+
import guessType from '../guessType';
|
|
13
|
+
import { Experimental_CustomMergeAllOf, FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
|
|
14
|
+
import getFirstMatchingOption from './getFirstMatchingOption';
|
|
15
|
+
import retrieveSchema, { resolveAllReferences } from './retrieveSchema';
|
|
16
16
|
|
|
17
17
|
/** A junk option used to determine when the getFirstMatchingOption call really matches an option rather than returning
|
|
18
18
|
* the first item
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { JSONSchema7Object } from 'json-schema';
|
|
1
2
|
import get from 'lodash/get';
|
|
2
3
|
import isEmpty from 'lodash/isEmpty';
|
|
3
|
-
import { JSONSchema7Object } from 'json-schema';
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
ALL_OF_KEY,
|
|
@@ -13,15 +13,18 @@ import {
|
|
|
13
13
|
PROPERTIES_KEY,
|
|
14
14
|
REF_KEY,
|
|
15
15
|
} from '../constants';
|
|
16
|
+
import constIsAjvDataReference from '../constIsAjvDataReference';
|
|
17
|
+
import deepEquals from '../deepEquals';
|
|
16
18
|
import findSchemaDefinition from '../findSchemaDefinition';
|
|
17
|
-
import getClosestMatchingOption from './getClosestMatchingOption';
|
|
18
19
|
import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema';
|
|
19
20
|
import getSchemaType from '../getSchemaType';
|
|
20
|
-
import
|
|
21
|
+
import isConstant from '../isConstant';
|
|
21
22
|
import isFixedItems from '../isFixedItems';
|
|
23
|
+
import isObject from '../isObject';
|
|
22
24
|
import mergeDefaultsWithFormData from '../mergeDefaultsWithFormData';
|
|
23
25
|
import mergeObjects from '../mergeObjects';
|
|
24
26
|
import mergeSchemas from '../mergeSchemas';
|
|
27
|
+
import optionsList from '../optionsList';
|
|
25
28
|
import {
|
|
26
29
|
Experimental_CustomMergeAllOf,
|
|
27
30
|
Experimental_DefaultFormStateBehavior,
|
|
@@ -31,13 +34,10 @@ import {
|
|
|
31
34
|
StrictRJSFSchema,
|
|
32
35
|
ValidatorType,
|
|
33
36
|
} from '../types';
|
|
37
|
+
import getClosestMatchingOption from './getClosestMatchingOption';
|
|
34
38
|
import isMultiSelect from './isMultiSelect';
|
|
35
39
|
import isSelect from './isSelect';
|
|
36
40
|
import retrieveSchema, { resolveDependencies } from './retrieveSchema';
|
|
37
|
-
import isConstant from '../isConstant';
|
|
38
|
-
import constIsAjvDataReference from '../constIsAjvDataReference';
|
|
39
|
-
import optionsList from '../optionsList';
|
|
40
|
-
import deepEquals from '../deepEquals';
|
|
41
41
|
|
|
42
42
|
const PRIMITIVE_TYPES = ['string', 'number', 'integer', 'boolean', 'null'];
|
|
43
43
|
|
|
@@ -218,7 +218,7 @@ interface ComputeDefaultsProps<T = any, S extends StrictRJSFSchema = RJSFSchema>
|
|
|
218
218
|
*
|
|
219
219
|
* @param validator - an implementation of the `ValidatorType` interface that will be used when necessary
|
|
220
220
|
* @param rawSchema - The schema for which the default state is desired
|
|
221
|
-
* @param
|
|
221
|
+
* @param computeDefaultsProps - Optional props for this function
|
|
222
222
|
* @returns - The resulting `formData` with all the defaults provided
|
|
223
223
|
*/
|
|
224
224
|
export function computeDefaults<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
@@ -465,7 +465,7 @@ export function ensureFormDataMatchingSchema<
|
|
|
465
465
|
*
|
|
466
466
|
* @param validator - an implementation of the `ValidatorType` interface that will be used when necessary
|
|
467
467
|
* @param rawSchema - The schema for which the default state is desired
|
|
468
|
-
* @param
|
|
468
|
+
* @param computeDefaultsProps - Optional props for this function
|
|
469
469
|
* @param defaults - Optional props for this function
|
|
470
470
|
* @returns - The default value based on the schema type if they are defined for object or array schemas.
|
|
471
471
|
*/
|
|
@@ -594,7 +594,7 @@ export function getObjectDefaults<T = any, S extends StrictRJSFSchema = RJSFSche
|
|
|
594
594
|
*
|
|
595
595
|
* @param validator - an implementation of the `ValidatorType` interface that will be used when necessary
|
|
596
596
|
* @param rawSchema - The schema for which the default state is desired
|
|
597
|
-
* @param
|
|
597
|
+
* @param computeDefaultsProps - Optional props for this function
|
|
598
598
|
* @param defaults - Optional props for this function
|
|
599
599
|
* @returns - The default value based on the schema type if they are defined for object or array schemas.
|
|
600
600
|
*/
|
|
@@ -673,19 +673,13 @@ export function getArrayDefaults<T = any, S extends StrictRJSFSchema = RJSFSchem
|
|
|
673
673
|
}
|
|
674
674
|
}
|
|
675
675
|
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
}
|
|
684
|
-
if (ignoreMinItemsFlagSet && !required) {
|
|
685
|
-
// If no form data exists or defaults are set leave the field empty/non-existent, otherwise
|
|
686
|
-
// return form data/defaults
|
|
687
|
-
return defaults ? defaults : undefined;
|
|
688
|
-
}
|
|
676
|
+
if (neverPopulate) {
|
|
677
|
+
return defaults ?? emptyDefault;
|
|
678
|
+
}
|
|
679
|
+
if (ignoreMinItemsFlagSet && !required) {
|
|
680
|
+
// If no form data exists or defaults are set leave the field empty/non-existent, otherwise
|
|
681
|
+
// return form data/defaults
|
|
682
|
+
return defaults ? defaults : undefined;
|
|
689
683
|
}
|
|
690
684
|
|
|
691
685
|
let arrayDefault: T[] | undefined;
|
|
@@ -726,7 +720,7 @@ export function getArrayDefaults<T = any, S extends StrictRJSFSchema = RJSFSchem
|
|
|
726
720
|
*
|
|
727
721
|
* @param validator - an implementation of the `ValidatorType` interface that will be used when necessary
|
|
728
722
|
* @param rawSchema - The schema for which the default state is desired
|
|
729
|
-
* @param
|
|
723
|
+
* @param computeDefaultsProps - Optional props for this function
|
|
730
724
|
* @param defaults - Optional props for this function
|
|
731
725
|
* @returns - The default value based on the schema type if they are defined for object or array schemas.
|
|
732
726
|
*/
|
|
@@ -2,9 +2,16 @@ import get from 'lodash/get';
|
|
|
2
2
|
import has from 'lodash/has';
|
|
3
3
|
import isEmpty from 'lodash/isEmpty';
|
|
4
4
|
|
|
5
|
-
import retrieveSchema from './retrieveSchema';
|
|
6
|
-
import { Experimental_CustomMergeAllOf, FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
|
|
7
5
|
import { REF_KEY } from '../constants';
|
|
6
|
+
import {
|
|
7
|
+
Experimental_CustomMergeAllOf,
|
|
8
|
+
FormContextType,
|
|
9
|
+
RJSFSchema,
|
|
10
|
+
SchemaFieldPath,
|
|
11
|
+
StrictRJSFSchema,
|
|
12
|
+
ValidatorType,
|
|
13
|
+
} from '../types';
|
|
14
|
+
import retrieveSchema from './retrieveSchema';
|
|
8
15
|
|
|
9
16
|
/** Internal helper function that acts like lodash's `get` but additionally retrieves `$ref`s as needed to get the path
|
|
10
17
|
* for schemas containing potentially nested `$ref`s.
|
|
@@ -20,7 +27,7 @@ function getFromSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
20
27
|
validator: ValidatorType<T, S, F>,
|
|
21
28
|
rootSchema: S,
|
|
22
29
|
schema: S,
|
|
23
|
-
path:
|
|
30
|
+
path: SchemaFieldPath,
|
|
24
31
|
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
|
|
25
32
|
): T | S | undefined {
|
|
26
33
|
let fieldSchema = schema;
|
|
@@ -30,9 +37,9 @@ function getFromSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
30
37
|
if (isEmpty(path)) {
|
|
31
38
|
return fieldSchema;
|
|
32
39
|
}
|
|
33
|
-
const pathList = Array.isArray(path) ? path : path.split('.');
|
|
40
|
+
const pathList = Array.isArray(path) ? [...path] : path.split('.');
|
|
34
41
|
const [part, ...nestedPath] = pathList;
|
|
35
|
-
if (part && has(fieldSchema, part)) {
|
|
42
|
+
if (part !== undefined && part !== '' && has(fieldSchema, part)) {
|
|
36
43
|
fieldSchema = get(fieldSchema, part) as S;
|
|
37
44
|
return getFromSchemaInternal<T, S, F>(
|
|
38
45
|
validator,
|
|
@@ -64,7 +71,7 @@ export default function getFromSchema<
|
|
|
64
71
|
validator: ValidatorType<T, S, F>,
|
|
65
72
|
rootSchema: S,
|
|
66
73
|
schema: S,
|
|
67
|
-
path:
|
|
74
|
+
path: SchemaFieldPath,
|
|
68
75
|
defaultValue: T,
|
|
69
76
|
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
|
|
70
77
|
): T;
|
|
@@ -76,7 +83,7 @@ export default function getFromSchema<
|
|
|
76
83
|
validator: ValidatorType<T, S, F>,
|
|
77
84
|
rootSchema: S,
|
|
78
85
|
schema: S,
|
|
79
|
-
path:
|
|
86
|
+
path: SchemaFieldPath,
|
|
80
87
|
defaultValue: S,
|
|
81
88
|
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
|
|
82
89
|
): S;
|
|
@@ -88,7 +95,7 @@ export default function getFromSchema<
|
|
|
88
95
|
validator: ValidatorType<T, S, F>,
|
|
89
96
|
rootSchema: S,
|
|
90
97
|
schema: S,
|
|
91
|
-
path:
|
|
98
|
+
path: SchemaFieldPath,
|
|
92
99
|
defaultValue: T | S,
|
|
93
100
|
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
|
|
94
101
|
): T | S {
|
package/src/schema/index.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import findFieldInSchema from './findFieldInSchema';
|
|
2
2
|
import findSelectedOptionInXxxOf from './findSelectedOptionInXxxOf';
|
|
3
|
+
import getClosestMatchingOption from './getClosestMatchingOption';
|
|
3
4
|
import getDefaultFormState from './getDefaultFormState';
|
|
4
5
|
import getDisplayLabel from './getDisplayLabel';
|
|
5
|
-
import getClosestMatchingOption from './getClosestMatchingOption';
|
|
6
6
|
import getFirstMatchingOption from './getFirstMatchingOption';
|
|
7
7
|
import getFromSchema from './getFromSchema';
|
|
8
8
|
import isFilesArray from './isFilesArray';
|
|
9
9
|
import isMultiSelect from './isMultiSelect';
|
|
10
10
|
import isSelect from './isSelect';
|
|
11
|
-
import omitExtraData, { getUsedFormData, getFieldNames } from './omitExtraData';
|
|
12
|
-
import retrieveSchema from './retrieveSchema';
|
|
11
|
+
import omitExtraData, { getUsedFormData, getFieldNames, isValueEmpty } from './omitExtraData';
|
|
12
|
+
import retrieveSchema, { relaxOptionsForScoring } from './retrieveSchema';
|
|
13
13
|
import sanitizeDataForNewSchema from './sanitizeDataForNewSchema';
|
|
14
14
|
import toPathSchema from './toPathSchema';
|
|
15
15
|
|
|
@@ -26,7 +26,9 @@ export {
|
|
|
26
26
|
isFilesArray,
|
|
27
27
|
isMultiSelect,
|
|
28
28
|
isSelect,
|
|
29
|
+
isValueEmpty,
|
|
29
30
|
omitExtraData,
|
|
31
|
+
relaxOptionsForScoring,
|
|
30
32
|
retrieveSchema,
|
|
31
33
|
sanitizeDataForNewSchema,
|
|
32
34
|
toPathSchema,
|