@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.
- package/LICENSE.md +201 -0
- package/dist/index.cjs +534 -376
- package/dist/index.cjs.map +4 -4
- package/dist/utils.esm.js +534 -376
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +561 -400
- package/lib/ErrorSchemaBuilder.d.ts +1 -1
- package/lib/SelectedOptionDescription.d.ts +4 -0
- package/lib/SelectedOptionDescription.js +24 -0
- package/lib/SelectedOptionDescription.js.map +1 -0
- package/lib/allowAdditionalItems.d.ts +1 -1
- package/lib/allowAdditionalItems.js +1 -0
- package/lib/allowAdditionalItems.js.map +1 -1
- package/lib/asNumber.js +2 -0
- package/lib/asNumber.js.map +1 -1
- package/lib/canExpand.d.ts +1 -1
- package/lib/constIsAjvDataReference.d.ts +1 -1
- package/lib/constants.d.ts +8 -5
- package/lib/constants.js +10 -7
- package/lib/constants.js.map +1 -1
- package/lib/createErrorHandler.d.ts +1 -1
- package/lib/createErrorHandler.js +2 -6
- package/lib/createErrorHandler.js.map +1 -1
- package/lib/createSchemaUtils.d.ts +1 -1
- package/lib/createSchemaUtils.js +3 -1
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/dataURItoBlob.js +3 -3
- package/lib/dataURItoBlob.js.map +1 -1
- package/lib/dateRangeOptions.d.ts +1 -1
- package/lib/dateRangeOptions.js +8 -7
- package/lib/dateRangeOptions.js.map +1 -1
- package/lib/englishStringTranslator.d.ts +1 -1
- package/lib/enumOptionSelectedValue.d.ts +1 -1
- package/lib/enumOptionValueDecoder.d.ts +1 -1
- package/lib/enumOptionValueDecoder.js +1 -1
- package/lib/enumOptionValueDecoder.js.map +1 -1
- package/lib/enumOptionValueEncoder.d.ts +1 -1
- package/lib/enumOptionsDeselectValue.d.ts +1 -1
- package/lib/enumOptionsIndexForValue.d.ts +1 -1
- package/lib/enumOptionsIndexForValue.js.map +1 -1
- package/lib/enumOptionsIsSelected.d.ts +1 -1
- package/lib/enumOptionsSelectValue.d.ts +1 -1
- package/lib/enumOptionsValueForIndex.d.ts +2 -2
- package/lib/enumOptionsValueForIndex.js.map +1 -1
- package/lib/enums.d.ts +4 -0
- package/lib/enums.js +4 -0
- package/lib/enums.js.map +1 -1
- package/lib/findSchemaDefinition.d.ts +1 -1
- package/lib/findSchemaDefinition.js +15 -15
- package/lib/findSchemaDefinition.js.map +1 -1
- package/lib/getChangedFields.js +4 -6
- package/lib/getChangedFields.js.map +1 -1
- package/lib/getDateElementProps.d.ts +3 -3
- package/lib/getDiscriminatorFieldFromSchema.d.ts +1 -1
- package/lib/getDiscriminatorFieldFromSchema.js +1 -0
- package/lib/getDiscriminatorFieldFromSchema.js.map +1 -1
- package/lib/getInputProps.d.ts +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.d.ts +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.js +10 -11
- package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -1
- package/lib/getOptionValueFormat.d.ts +1 -1
- package/lib/getSchemaType.d.ts +1 -1
- package/lib/getSchemaType.js +2 -1
- package/lib/getSchemaType.js.map +1 -1
- package/lib/getSubmitButtonOptions.d.ts +1 -1
- package/lib/getSubmitButtonOptions.js +1 -1
- package/lib/getSubmitButtonOptions.js.map +1 -1
- package/lib/getTemplate.d.ts +1 -1
- package/lib/getTestIds.d.ts +1 -1
- package/lib/getUiOptions.d.ts +1 -1
- package/lib/getUiOptions.js +2 -1
- package/lib/getUiOptions.js.map +1 -1
- package/lib/getWidget.d.ts +1 -1
- package/lib/getWidget.js +4 -4
- package/lib/getWidget.js.map +1 -1
- package/lib/guessType.js +1 -1
- package/lib/guessType.js.map +1 -1
- package/lib/hasWidget.d.ts +1 -1
- package/lib/hashForSchema.d.ts +3 -1
- package/lib/hashForSchema.js +11 -4
- package/lib/hashForSchema.js.map +1 -1
- package/lib/idGenerators.d.ts +1 -1
- package/lib/index.d.ts +14 -7
- package/lib/index.js +5 -2
- package/lib/index.js.map +1 -1
- package/lib/isConstant.d.ts +1 -1
- package/lib/isCustomWidget.d.ts +1 -1
- package/lib/isCustomWidget.js +1 -1
- package/lib/isCustomWidget.js.map +1 -1
- package/lib/isFixedItems.d.ts +3 -3
- package/lib/isFixedItems.js +3 -3
- package/lib/isFixedItems.js.map +1 -1
- package/lib/isRootSchema.d.ts +1 -1
- package/lib/isRootSchema.js +2 -3
- package/lib/isRootSchema.js.map +1 -1
- package/lib/labelValue.d.ts +1 -1
- package/lib/logUnsupportedDefaultForEnum.d.ts +9 -0
- package/lib/logUnsupportedDefaultForEnum.js +18 -0
- package/lib/logUnsupportedDefaultForEnum.js.map +1 -0
- package/lib/lookupFromFormContext.d.ts +1 -1
- package/lib/mergeDefaultsWithFormData.js +6 -5
- package/lib/mergeDefaultsWithFormData.js.map +1 -1
- package/lib/mergeObjects.d.ts +4 -2
- package/lib/mergeObjects.js +1 -1
- package/lib/mergeObjects.js.map +1 -1
- package/lib/mergeSchemas.d.ts +4 -2
- package/lib/mergeSchemas.js +13 -6
- package/lib/mergeSchemas.js.map +1 -1
- package/lib/nameGenerators.d.ts +1 -1
- package/lib/optionsList.d.ts +1 -1
- package/lib/optionsList.js +22 -21
- package/lib/optionsList.js.map +1 -1
- package/lib/orderProperties.js +3 -3
- package/lib/orderProperties.js.map +1 -1
- package/lib/pad.js +1 -1
- package/lib/pad.js.map +1 -1
- package/lib/parseDateString.d.ts +1 -1
- package/lib/parseDateString.js +1 -1
- package/lib/parseDateString.js.map +1 -1
- package/lib/parser/ParserValidator.d.ts +2 -4
- package/lib/parser/ParserValidator.js +2 -0
- package/lib/parser/ParserValidator.js.map +1 -1
- package/lib/parser/index.d.ts +1 -1
- package/lib/parser/schemaParser.d.ts +2 -2
- package/lib/parser/schemaParser.js +7 -7
- package/lib/parser/schemaParser.js.map +1 -1
- package/lib/rangeSpec.d.ts +1 -2
- package/lib/rangeSpec.js.map +1 -1
- package/lib/removeOptionalEmptyObjects.d.ts +1 -1
- package/lib/removeOptionalEmptyObjects.js +6 -8
- package/lib/removeOptionalEmptyObjects.js.map +1 -1
- package/lib/resolveUiSchema.d.ts +1 -1
- package/lib/resolveUiSchema.js +16 -16
- package/lib/resolveUiSchema.js.map +1 -1
- package/lib/schema/findFieldInSchema.d.ts +1 -1
- package/lib/schema/findSelectedOptionInXxxOf.d.ts +1 -1
- package/lib/schema/findSelectedOptionInXxxOf.js +1 -3
- package/lib/schema/findSelectedOptionInXxxOf.js.map +1 -1
- package/lib/schema/getClosestMatchingOption.d.ts +1 -1
- package/lib/schema/getClosestMatchingOption.js +6 -9
- package/lib/schema/getClosestMatchingOption.js.map +1 -1
- package/lib/schema/getDefaultFormState.d.ts +4 -4
- package/lib/schema/getDefaultFormState.js +81 -43
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getDisplayLabel.d.ts +1 -1
- package/lib/schema/getDisplayLabel.js +2 -3
- package/lib/schema/getDisplayLabel.js.map +1 -1
- package/lib/schema/getFirstMatchingOption.d.ts +1 -1
- package/lib/schema/getFirstMatchingOption.js +2 -2
- package/lib/schema/getFirstMatchingOption.js.map +1 -1
- package/lib/schema/getFromSchema.d.ts +1 -1
- package/lib/schema/index.js +9 -3
- package/lib/schema/index.js.map +1 -1
- package/lib/schema/isFilesArray.d.ts +1 -1
- package/lib/schema/isMultiSelect.d.ts +1 -1
- package/lib/schema/isMultiSelect.js.map +1 -1
- package/lib/schema/isSelect.d.ts +1 -1
- package/lib/schema/isSelect.js +1 -1
- package/lib/schema/isSelect.js.map +1 -1
- package/lib/schema/omitExtraData.d.ts +1 -1
- package/lib/schema/omitExtraData.js +66 -52
- package/lib/schema/omitExtraData.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +7 -3
- package/lib/schema/retrieveSchema.js +83 -56
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/schema/sanitizeDataForNewSchema.d.ts +1 -1
- package/lib/schema/sanitizeDataForNewSchema.js +48 -7
- package/lib/schema/sanitizeDataForNewSchema.js.map +1 -1
- package/lib/schema/toPathSchema.d.ts +1 -1
- package/lib/schema/toPathSchema.js +9 -5
- package/lib/schema/toPathSchema.js.map +1 -1
- package/lib/schemaRequiresTrueValue.d.ts +1 -1
- package/lib/schemaRequiresTrueValue.js +4 -3
- package/lib/schemaRequiresTrueValue.js.map +1 -1
- package/lib/shallowEquals.js +2 -2
- package/lib/shallowEquals.js.map +1 -1
- package/lib/shouldRenderOptionalField.d.ts +1 -1
- package/lib/toConstant.d.ts +1 -1
- package/lib/toDateString.d.ts +1 -1
- package/lib/toErrorList.d.ts +1 -1
- package/lib/toErrorList.js +3 -3
- package/lib/toErrorList.js.map +1 -1
- package/lib/toErrorSchema.d.ts +1 -1
- package/lib/toFieldPathId.d.ts +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +63 -57
- package/lib/unwrapErrorHandler.d.ts +1 -1
- package/lib/unwrapErrorHandler.js +7 -9
- package/lib/unwrapErrorHandler.js.map +1 -1
- package/lib/useAltDateWidgetProps.d.ts +6 -6
- package/lib/useAltDateWidgetProps.js +3 -3
- package/lib/useAltDateWidgetProps.js.map +1 -1
- package/lib/useFileWidgetProps.d.ts +2 -2
- package/lib/useFileWidgetProps.js +3 -3
- package/lib/useFileWidgetProps.js.map +1 -1
- package/lib/validationDataMerge.d.ts +1 -1
- package/lib/withIdRefPrefix.d.ts +1 -1
- package/lib/withIdRefPrefix.js +12 -12
- package/lib/withIdRefPrefix.js.map +1 -1
- package/package.json +19 -19
- package/src/ErrorSchemaBuilder.ts +1 -1
- package/src/SelectedOptionDescription.tsx +48 -0
- package/src/allowAdditionalItems.ts +2 -1
- package/src/asNumber.ts +2 -0
- package/src/canExpand.ts +1 -1
- package/src/constIsAjvDataReference.ts +2 -2
- package/src/constants.ts +10 -7
- package/src/createErrorHandler.ts +6 -7
- package/src/createSchemaUtils.ts +4 -2
- package/src/dataURItoBlob.ts +3 -3
- package/src/dateRangeOptions.ts +9 -7
- package/src/englishStringTranslator.ts +1 -1
- package/src/enumOptionSelectedValue.ts +1 -1
- package/src/enumOptionValueDecoder.ts +2 -2
- package/src/enumOptionValueEncoder.ts +1 -1
- package/src/enumOptionsDeselectValue.ts +1 -1
- package/src/enumOptionsIndexForValue.ts +2 -2
- package/src/enumOptionsIsSelected.ts +1 -1
- package/src/enumOptionsSelectValue.ts +1 -1
- package/src/enumOptionsValueForIndex.ts +2 -2
- package/src/enums.ts +4 -0
- package/src/findSchemaDefinition.ts +18 -17
- package/src/getChangedFields.ts +5 -5
- package/src/getDateElementProps.ts +3 -3
- package/src/getDiscriminatorFieldFromSchema.ts +2 -1
- package/src/getInputProps.ts +1 -1
- package/src/getOptionMatchingSimpleDiscriminator.ts +11 -15
- package/src/getOptionValueFormat.ts +1 -1
- package/src/getSchemaType.ts +3 -2
- package/src/getSubmitButtonOptions.ts +3 -3
- package/src/getTemplate.ts +1 -1
- package/src/getTestIds.ts +1 -1
- package/src/getUiOptions.ts +10 -2
- package/src/getWidget.tsx +5 -6
- package/src/guessType.ts +1 -1
- package/src/hasWidget.ts +1 -1
- package/src/hashForSchema.ts +12 -5
- package/src/idGenerators.ts +1 -1
- package/src/index.ts +16 -5
- package/src/isConstant.ts +1 -1
- package/src/isCustomWidget.ts +2 -2
- package/src/isFixedItems.ts +4 -4
- package/src/isRootSchema.ts +3 -5
- package/src/labelValue.ts +1 -1
- package/src/logUnsupportedDefaultForEnum.ts +28 -0
- package/src/lookupFromFormContext.ts +1 -1
- package/src/mergeDefaultsWithFormData.ts +8 -7
- package/src/mergeObjects.ts +2 -2
- package/src/mergeSchemas.ts +14 -7
- package/src/nameGenerators.ts +1 -1
- package/src/optionsList.ts +21 -23
- package/src/orderProperties.ts +4 -4
- package/src/pad.ts +1 -1
- package/src/parseDateString.ts +2 -2
- package/src/parser/ParserValidator.ts +4 -4
- package/src/parser/index.ts +1 -1
- package/src/parser/schemaParser.ts +10 -9
- package/src/rangeSpec.ts +1 -2
- package/src/removeOptionalEmptyObjects.ts +8 -11
- package/src/resolveUiSchema.ts +32 -25
- package/src/schema/findFieldInSchema.ts +1 -1
- package/src/schema/findSelectedOptionInXxxOf.ts +17 -7
- package/src/schema/getClosestMatchingOption.ts +17 -11
- package/src/schema/getDefaultFormState.ts +104 -43
- package/src/schema/getDisplayLabel.ts +4 -5
- package/src/schema/getFirstMatchingOption.ts +3 -3
- package/src/schema/getFromSchema.ts +1 -1
- package/src/schema/index.ts +3 -0
- package/src/schema/isFilesArray.ts +1 -1
- package/src/schema/isMultiSelect.ts +7 -1
- package/src/schema/isSelect.ts +8 -2
- package/src/schema/omitExtraData.ts +73 -60
- package/src/schema/retrieveSchema.ts +131 -83
- package/src/schema/sanitizeDataForNewSchema.ts +57 -8
- package/src/schema/toPathSchema.ts +11 -7
- package/src/schemaRequiresTrueValue.ts +4 -4
- package/src/shallowEquals.ts +2 -2
- package/src/shouldRenderOptionalField.ts +1 -1
- package/src/toConstant.ts +1 -1
- package/src/toDateString.ts +1 -1
- package/src/toErrorList.ts +4 -4
- package/src/toErrorSchema.ts +1 -1
- package/src/toFieldPathId.ts +1 -1
- package/src/types.ts +92 -63
- package/src/unwrapErrorHandler.ts +11 -12
- package/src/useAltDateWidgetProps.tsx +10 -8
- package/src/useFileWidgetProps.ts +7 -7
- package/src/validationDataMerge.ts +1 -1
- package/src/withIdRefPrefix.ts +12 -12
package/src/parseDateString.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DateObject } from './types';
|
|
1
|
+
import type { DateObject } from './types';
|
|
2
2
|
|
|
3
3
|
/** Parses the `dateString` into a `DateObject`, including the time information when `includeTime` is true
|
|
4
4
|
*
|
|
@@ -20,7 +20,7 @@ export default function parseDateString(dateString?: string, includeTime = true)
|
|
|
20
20
|
}
|
|
21
21
|
const date = new Date(dateString);
|
|
22
22
|
if (Number.isNaN(date.getTime())) {
|
|
23
|
-
throw new Error(
|
|
23
|
+
throw new Error(`Unable to parse date ${dateString}`);
|
|
24
24
|
}
|
|
25
25
|
return {
|
|
26
26
|
year: date.getUTCFullYear(),
|
|
@@ -3,7 +3,7 @@ import get from 'lodash/get';
|
|
|
3
3
|
import { ID_KEY } from '../constants';
|
|
4
4
|
import deepEquals from '../deepEquals';
|
|
5
5
|
import hashForSchema from '../hashForSchema';
|
|
6
|
-
import {
|
|
6
|
+
import type {
|
|
7
7
|
CustomValidator,
|
|
8
8
|
ErrorSchema,
|
|
9
9
|
ErrorTransformer,
|
|
@@ -18,9 +18,7 @@ import {
|
|
|
18
18
|
|
|
19
19
|
/** The type of the map of schema hash to schema
|
|
20
20
|
*/
|
|
21
|
-
export type SchemaMap<S extends StrictRJSFSchema = RJSFSchema> =
|
|
22
|
-
[hash: string]: S;
|
|
23
|
-
};
|
|
21
|
+
export type SchemaMap<S extends StrictRJSFSchema = RJSFSchema> = Record<string, S>;
|
|
24
22
|
|
|
25
23
|
/** An implementation of the `ValidatorType` interface that is designed for use in capturing schemas used by the
|
|
26
24
|
* `isValid()` function. The rest of the implementation of the interface throws errors when it is attempted to be used.
|
|
@@ -70,7 +68,9 @@ export default class ParserValidator<
|
|
|
70
68
|
if (!existing) {
|
|
71
69
|
this.schemaMap[key] = identifiedSchema;
|
|
72
70
|
} else if (!deepEquals(existing, identifiedSchema)) {
|
|
71
|
+
// oxlint-disable-next-line no-console
|
|
73
72
|
console.error('existing schema:', JSON.stringify(existing, null, 2));
|
|
73
|
+
// oxlint-disable-next-line no-console
|
|
74
74
|
console.error('new schema:', JSON.stringify(identifiedSchema, null, 2));
|
|
75
75
|
throw new Error(
|
|
76
76
|
`Two different schemas exist with the same key ${key}! What a bad coincidence. If possible, try adding an $id to one of the schemas`,
|
package/src/parser/index.ts
CHANGED
|
@@ -3,8 +3,9 @@ import forEach from 'lodash/forEach';
|
|
|
3
3
|
import { ITEMS_KEY, PROPERTIES_KEY } from '../constants';
|
|
4
4
|
import deepEquals from '../deepEquals';
|
|
5
5
|
import { resolveAnyOrOneOfSchemas, retrieveSchemaInternal } from '../schema/retrieveSchema';
|
|
6
|
-
import { FormContextType, RJSFSchema, StrictRJSFSchema } from '../types';
|
|
7
|
-
import
|
|
6
|
+
import type { FormContextType, RJSFSchema, StrictRJSFSchema } from '../types';
|
|
7
|
+
import type { SchemaMap } from './ParserValidator';
|
|
8
|
+
import ParserValidator from './ParserValidator';
|
|
8
9
|
|
|
9
10
|
/** Recursive function used to parse the given `schema` belonging to the `rootSchema`. The `validator` is used to
|
|
10
11
|
* capture the sub-schemas that the `isValid()` function is called with. For each schema returned by the
|
|
@@ -23,20 +24,20 @@ function parseSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
|
|
|
23
24
|
schema: S,
|
|
24
25
|
) {
|
|
25
26
|
const schemas = retrieveSchemaInternal<T, S, F>(validator, schema, rootSchema, undefined, true);
|
|
26
|
-
schemas.forEach((
|
|
27
|
-
const sameSchemaIndex = recurseList.findIndex((item) => deepEquals(item,
|
|
27
|
+
schemas.forEach((localSchema) => {
|
|
28
|
+
const sameSchemaIndex = recurseList.findIndex((item) => deepEquals(item, localSchema));
|
|
28
29
|
if (sameSchemaIndex === -1) {
|
|
29
|
-
recurseList.push(
|
|
30
|
-
const allOptions = resolveAnyOrOneOfSchemas<T, S, F>(validator,
|
|
30
|
+
recurseList.push(localSchema);
|
|
31
|
+
const allOptions = resolveAnyOrOneOfSchemas<T, S, F>(validator, localSchema, rootSchema, true);
|
|
31
32
|
allOptions.forEach((s) => {
|
|
32
33
|
if (PROPERTIES_KEY in s && s[PROPERTIES_KEY]) {
|
|
33
|
-
forEach(
|
|
34
|
+
forEach(localSchema[PROPERTIES_KEY], (value) => {
|
|
34
35
|
parseSchema<T, S, F>(validator, recurseList, rootSchema, value as S);
|
|
35
36
|
});
|
|
36
37
|
}
|
|
37
38
|
});
|
|
38
|
-
if (ITEMS_KEY in
|
|
39
|
-
parseSchema<T, S, F>(validator, recurseList, rootSchema,
|
|
39
|
+
if (ITEMS_KEY in localSchema && !Array.isArray(localSchema.items) && typeof localSchema.items !== 'boolean') {
|
|
40
|
+
parseSchema<T, S, F>(validator, recurseList, rootSchema, localSchema.items as S);
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
});
|
package/src/rangeSpec.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { RangeSpecType, StrictRJSFSchema } from './types';
|
|
2
|
-
import { RJSFSchema } from './types';
|
|
1
|
+
import type { RangeSpecType, RJSFSchema, StrictRJSFSchema } from './types';
|
|
3
2
|
|
|
4
3
|
/** Extracts the range spec information `{ step?: number, min?: number, max?: number }` that can be spread onto an HTML
|
|
5
4
|
* input from the range analog in the schema `{ multipleOf?: number, minimum?: number, maximum?: number }`.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import isObject from './isObject';
|
|
2
2
|
import { isValueEmpty, retrieveSchema } from './schema';
|
|
3
|
-
import { FormContextType, GenericObjectType, RJSFSchema, StrictRJSFSchema, ValidatorType } from './types';
|
|
3
|
+
import type { FormContextType, GenericObjectType, RJSFSchema, StrictRJSFSchema, ValidatorType } from './types';
|
|
4
4
|
|
|
5
5
|
/** Recursively removes optional objects from the `formData` that are empty (i.e., all their fields
|
|
6
6
|
* are undefined, null, empty strings, or themselves empty optional objects). This solves the problem
|
|
@@ -19,7 +19,7 @@ import { FormContextType, GenericObjectType, RJSFSchema, StrictRJSFSchema, Valid
|
|
|
19
19
|
* @deprecated - This function will be removed in a future release. The equivalent pruning behavior
|
|
20
20
|
* is now built into `omitExtraData` — use that instead.
|
|
21
21
|
*/
|
|
22
|
-
//
|
|
22
|
+
// oxlint-disable-next-line @typescript-eslint/no-deprecated
|
|
23
23
|
export default function removeOptionalEmptyObjects<
|
|
24
24
|
T = any,
|
|
25
25
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
@@ -43,7 +43,7 @@ export default function removeOptionalEmptyObjects<
|
|
|
43
43
|
if (Array.isArray(itemsSchema)) {
|
|
44
44
|
itemSchema = itemsSchema[index] || (resolvedSchema.additionalItems as S) || ({} as S);
|
|
45
45
|
}
|
|
46
|
-
//
|
|
46
|
+
// oxlint-disable-next-line @typescript-eslint/no-deprecated
|
|
47
47
|
const cleaned = removeOptionalEmptyObjects<T, S, F>(validator, itemSchema, rootSchema, item);
|
|
48
48
|
if (cleaned !== item) {
|
|
49
49
|
hasChanges = true;
|
|
@@ -69,23 +69,20 @@ export default function removeOptionalEmptyObjects<
|
|
|
69
69
|
for (const key of Object.keys(data)) {
|
|
70
70
|
const value = data[key];
|
|
71
71
|
const propertySchema = (properties[key] || {}) as S;
|
|
72
|
-
const isRequired =
|
|
72
|
+
const isRequired = requiredFields.includes(key);
|
|
73
73
|
|
|
74
74
|
const isObj = isObject(value);
|
|
75
75
|
const isArr = Array.isArray(value);
|
|
76
76
|
|
|
77
77
|
if ((isObj || isArr) && properties[key]) {
|
|
78
78
|
// Recursively process nested objects and arrays
|
|
79
|
-
//
|
|
79
|
+
// oxlint-disable-next-line @typescript-eslint/no-deprecated
|
|
80
80
|
const cleaned = removeOptionalEmptyObjects<T, S, F>(validator, propertySchema, rootSchema, value as T);
|
|
81
81
|
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
if (isRequired || !isValueEmpty(cleaned)) {
|
|
83
|
+
result[key] = cleaned;
|
|
84
|
+
hasAnyValue = true;
|
|
85
85
|
}
|
|
86
|
-
|
|
87
|
-
result[key] = cleaned;
|
|
88
|
-
hasAnyValue = true;
|
|
89
86
|
} else if (isRequired || !isValueEmpty(value) || !properties[key]) {
|
|
90
87
|
// Keep: required, non-empty, or not schema-defined; skip optional empty scalars silently
|
|
91
88
|
result[key] = value;
|
package/src/resolveUiSchema.ts
CHANGED
|
@@ -3,7 +3,15 @@ import isEmpty from 'lodash/isEmpty';
|
|
|
3
3
|
import { ANY_OF_KEY, ONE_OF_KEY, REF_KEY, RJSF_REF_KEY } from './constants';
|
|
4
4
|
import findSchemaDefinition from './findSchemaDefinition';
|
|
5
5
|
import mergeObjects from './mergeObjects';
|
|
6
|
-
import {
|
|
6
|
+
import type {
|
|
7
|
+
FormContextType,
|
|
8
|
+
GenericObjectType,
|
|
9
|
+
Registry,
|
|
10
|
+
RJSFMarkedSchema,
|
|
11
|
+
RJSFSchema,
|
|
12
|
+
StrictRJSFSchema,
|
|
13
|
+
UiSchema,
|
|
14
|
+
} from './types';
|
|
7
15
|
|
|
8
16
|
/** Resolves the uiSchema for a given schema, considering `ui:definitions` stored in the registry.
|
|
9
17
|
*
|
|
@@ -26,7 +34,7 @@ export default function resolveUiSchema<
|
|
|
26
34
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
27
35
|
F extends FormContextType = any,
|
|
28
36
|
>(schema: S, localUiSchema: UiSchema<T, S, F> | undefined, registry: Registry<T, S, F>): UiSchema<T, S, F> {
|
|
29
|
-
const ref = ((schema as
|
|
37
|
+
const ref = ((schema as RJSFMarkedSchema)[RJSF_REF_KEY] ?? schema[REF_KEY]) as string | undefined;
|
|
30
38
|
const definitions = registry.uiSchemaDefinitions;
|
|
31
39
|
const definitionUiSchema = ref && definitions ? definitions[ref] : undefined;
|
|
32
40
|
|
|
@@ -47,10 +55,11 @@ export default function resolveUiSchema<
|
|
|
47
55
|
// can read dropdown option titles at the parent level.
|
|
48
56
|
if (definitions) {
|
|
49
57
|
let resolvedSchema: S = schema;
|
|
50
|
-
if (ref && schema[REF_KEY] && !(schema as
|
|
58
|
+
if (ref && schema[REF_KEY] && !(schema as RJSFMarkedSchema)[RJSF_REF_KEY]) {
|
|
51
59
|
try {
|
|
52
|
-
resolvedSchema = findSchemaDefinition<S>(ref, registry.rootSchema
|
|
60
|
+
resolvedSchema = findSchemaDefinition<S>(ref, registry.rootSchema);
|
|
53
61
|
} catch (e) {
|
|
62
|
+
// oxlint-disable-next-line no-console
|
|
54
63
|
console.warn('could not resolve $ref in resolveUiSchema:\n', e);
|
|
55
64
|
return result;
|
|
56
65
|
}
|
|
@@ -58,30 +67,28 @@ export default function resolveUiSchema<
|
|
|
58
67
|
|
|
59
68
|
for (const keyword of [ONE_OF_KEY, ANY_OF_KEY] as const) {
|
|
60
69
|
const schemaOptions = resolvedSchema[keyword];
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const currentUiSchemaArray = (result as GenericObjectType)[keyword];
|
|
66
|
-
const uiSchemaArray: UiSchema<T, S, F>[] = Array.isArray(currentUiSchemaArray) ? [...currentUiSchemaArray] : [];
|
|
70
|
+
if (Array.isArray(schemaOptions) && schemaOptions.length > 0) {
|
|
71
|
+
const currentUiSchemaArray = (result as GenericObjectType)[keyword];
|
|
72
|
+
const uiSchemaArray: UiSchema<T, S, F>[] = Array.isArray(currentUiSchemaArray) ? [...currentUiSchemaArray] : [];
|
|
67
73
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
let hasExpanded = false;
|
|
75
|
+
for (let i = 0; i < schemaOptions.length; i++) {
|
|
76
|
+
const option = schemaOptions[i] as GenericObjectType | undefined;
|
|
77
|
+
const optionRef = ((option as RJSFMarkedSchema)?.[RJSF_REF_KEY] ?? option?.[REF_KEY]) as string | undefined;
|
|
78
|
+
if (optionRef && optionRef in definitions) {
|
|
79
|
+
const optionUiSchema = (uiSchemaArray[i] || {}) as GenericObjectType;
|
|
80
|
+
uiSchemaArray[i] = mergeObjects(definitions[optionRef] as GenericObjectType, optionUiSchema) as UiSchema<
|
|
81
|
+
T,
|
|
82
|
+
S,
|
|
83
|
+
F
|
|
84
|
+
>;
|
|
85
|
+
hasExpanded = true;
|
|
86
|
+
}
|
|
80
87
|
}
|
|
81
|
-
}
|
|
82
88
|
|
|
83
|
-
|
|
84
|
-
|
|
89
|
+
if (hasExpanded) {
|
|
90
|
+
(result as GenericObjectType)[keyword] = uiSchemaArray;
|
|
91
|
+
}
|
|
85
92
|
}
|
|
86
93
|
}
|
|
87
94
|
}
|
|
@@ -3,7 +3,13 @@ import get from 'lodash/get';
|
|
|
3
3
|
import { CONST_KEY, DEFAULT_KEY, PROPERTIES_KEY } from '../constants';
|
|
4
4
|
import deepEquals from '../deepEquals';
|
|
5
5
|
import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema';
|
|
6
|
-
import {
|
|
6
|
+
import type {
|
|
7
|
+
Experimental_CustomMergeAllOf,
|
|
8
|
+
FormContextType,
|
|
9
|
+
RJSFSchema,
|
|
10
|
+
StrictRJSFSchema,
|
|
11
|
+
ValidatorType,
|
|
12
|
+
} from '../types';
|
|
7
13
|
import retrieveSchema from './retrieveSchema';
|
|
8
14
|
|
|
9
15
|
/** Finds the option inside the `schema['any/oneOf']` list which has the `properties[selectorField].default` or
|
|
@@ -36,17 +42,21 @@ export default function findSelectedOptionInXxxOf<
|
|
|
36
42
|
if (Array.isArray(schema[xxx])) {
|
|
37
43
|
const discriminator = getDiscriminatorFieldFromSchema<S>(schema);
|
|
38
44
|
const selectorField = discriminator || fallbackField;
|
|
39
|
-
const xxxOfs = schema[xxx]
|
|
45
|
+
const xxxOfs = schema[xxx].map((xxxOf) =>
|
|
40
46
|
retrieveSchema<T, S, F>(validator, xxxOf as S, rootSchema, formData, experimental_customMergeAllOf),
|
|
41
47
|
);
|
|
42
48
|
const data = get(formData, selectorField);
|
|
43
49
|
if (data !== undefined) {
|
|
44
|
-
return xxxOfs.find((
|
|
45
|
-
|
|
46
|
-
get(
|
|
50
|
+
return xxxOfs.find((xxxOfOption) =>
|
|
51
|
+
deepEquals(
|
|
52
|
+
get(
|
|
53
|
+
xxxOfOption,
|
|
54
|
+
[PROPERTIES_KEY, selectorField, DEFAULT_KEY],
|
|
55
|
+
get(xxxOfOption, [PROPERTIES_KEY, selectorField, CONST_KEY]),
|
|
56
|
+
),
|
|
47
57
|
data,
|
|
48
|
-
)
|
|
49
|
-
|
|
58
|
+
),
|
|
59
|
+
);
|
|
50
60
|
}
|
|
51
61
|
}
|
|
52
62
|
return undefined;
|
|
@@ -10,7 +10,13 @@ import { ONE_OF_KEY, REF_KEY, JUNK_OPTION_ID, ANY_OF_KEY } from '../constants';
|
|
|
10
10
|
import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema';
|
|
11
11
|
import getOptionMatchingSimpleDiscriminator from '../getOptionMatchingSimpleDiscriminator';
|
|
12
12
|
import guessType from '../guessType';
|
|
13
|
-
import {
|
|
13
|
+
import type {
|
|
14
|
+
Experimental_CustomMergeAllOf,
|
|
15
|
+
FormContextType,
|
|
16
|
+
RJSFSchema,
|
|
17
|
+
StrictRJSFSchema,
|
|
18
|
+
ValidatorType,
|
|
19
|
+
} from '../types';
|
|
14
20
|
import getFirstMatchingOption from './getFirstMatchingOption';
|
|
15
21
|
import retrieveSchema, { resolveAllReferences } from './retrieveSchema';
|
|
16
22
|
|
|
@@ -85,7 +91,7 @@ export function calculateIndexScore<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
85
91
|
);
|
|
86
92
|
}
|
|
87
93
|
if ((has(value, ONE_OF_KEY) || has(value, ANY_OF_KEY)) && formValue) {
|
|
88
|
-
const
|
|
94
|
+
const xxxOfKey = has(value, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
|
|
89
95
|
const discriminator = getDiscriminatorFieldFromSchema<S>(value as S);
|
|
90
96
|
return (
|
|
91
97
|
score +
|
|
@@ -93,7 +99,7 @@ export function calculateIndexScore<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
93
99
|
validator,
|
|
94
100
|
rootSchema,
|
|
95
101
|
formValue,
|
|
96
|
-
get(value,
|
|
102
|
+
get(value, xxxOfKey) as S[],
|
|
97
103
|
-1,
|
|
98
104
|
discriminator,
|
|
99
105
|
experimental_customMergeAllOf,
|
|
@@ -101,12 +107,11 @@ export function calculateIndexScore<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
101
107
|
);
|
|
102
108
|
}
|
|
103
109
|
if (value.type === 'object') {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
score += 1;
|
|
107
|
-
}
|
|
110
|
+
// If the structure is matching then give it a little boost in score
|
|
111
|
+
const structureBoost = isObject(formValue) ? 1 : 0;
|
|
108
112
|
return (
|
|
109
113
|
score +
|
|
114
|
+
structureBoost +
|
|
110
115
|
calculateIndexScore<T, S, F>(validator, rootSchema, value as S, formValue, experimental_customMergeAllOf)
|
|
111
116
|
);
|
|
112
117
|
}
|
|
@@ -173,9 +178,7 @@ export default function getClosestMatchingOption<
|
|
|
173
178
|
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
|
|
174
179
|
): number {
|
|
175
180
|
// First resolve any refs in the options
|
|
176
|
-
const resolvedOptions = options.map((option) =>
|
|
177
|
-
return resolveAllReferences<S>(option, rootSchema, []);
|
|
178
|
-
});
|
|
181
|
+
const resolvedOptions = options.map((option) => resolveAllReferences<S>(option, rootSchema, []));
|
|
179
182
|
|
|
180
183
|
const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField);
|
|
181
184
|
if (isNumber(simpleDiscriminatorMatch)) {
|
|
@@ -201,7 +204,10 @@ export default function getClosestMatchingOption<
|
|
|
201
204
|
// No indexes were valid, so we'll score all the options, add all the indexes
|
|
202
205
|
times(resolvedOptions.length, (i) => allValidIndexes.push(i));
|
|
203
206
|
}
|
|
204
|
-
|
|
207
|
+
interface BestType {
|
|
208
|
+
bestIndex: number;
|
|
209
|
+
bestScore: number;
|
|
210
|
+
}
|
|
205
211
|
const scoreCount = new Set<number>();
|
|
206
212
|
// Score all the options in the list of valid indexes and return the index with the best score
|
|
207
213
|
const { bestIndex }: BestType = allValidIndexes.reduce(
|