@rjsf/core 6.5.1 → 6.5.3
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/core.umd.js +41 -13
- package/dist/index.cjs +37 -9
- package/dist/index.cjs.map +2 -2
- package/dist/index.esm.js +63 -32
- package/dist/index.esm.js.map +3 -3
- package/lib/components/Form.d.ts.map +1 -1
- package/lib/components/Form.js +40 -8
- package/lib/components/fields/ArrayField.d.ts.map +1 -1
- package/lib/components/fields/ArrayField.js +3 -1
- package/lib/components/fields/SchemaField.d.ts.map +1 -1
- package/lib/components/fields/SchemaField.js +8 -3
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/components/Form.tsx +41 -7
- package/src/components/fields/ArrayField.tsx +3 -1
- package/src/components/fields/SchemaField.tsx +11 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rjsf/core",
|
|
3
|
-
"version": "6.5.
|
|
3
|
+
"version": "6.5.3",
|
|
4
4
|
"description": "A simple React component capable of building HTML forms out of a JSON schema.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"compileReplacer": "tsc -p tsconfig.replacer.json && move-file lodashReplacer.js lodashReplacer.cjs",
|
|
@@ -76,9 +76,9 @@
|
|
|
76
76
|
"prop-types": "^15.8.1"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
|
-
"@rjsf/snapshot-tests": "6.5.
|
|
80
|
-
"@rjsf/utils": "6.5.
|
|
81
|
-
"@rjsf/validator-ajv8": "6.5.
|
|
79
|
+
"@rjsf/snapshot-tests": "6.5.3",
|
|
80
|
+
"@rjsf/utils": "6.5.3",
|
|
81
|
+
"@rjsf/validator-ajv8": "6.5.3",
|
|
82
82
|
"@testing-library/jest-dom": "^6.9.1",
|
|
83
83
|
"@testing-library/react": "^16.3.2",
|
|
84
84
|
"@testing-library/user-event": "^14.6.1",
|
package/src/components/Form.tsx
CHANGED
|
@@ -45,6 +45,8 @@ import {
|
|
|
45
45
|
NameGeneratorFunction,
|
|
46
46
|
getUsedFormData,
|
|
47
47
|
getFieldNames,
|
|
48
|
+
ANY_OF_KEY,
|
|
49
|
+
ONE_OF_KEY,
|
|
48
50
|
} from '@rjsf/utils';
|
|
49
51
|
import _cloneDeep from 'lodash/cloneDeep';
|
|
50
52
|
import _get from 'lodash/get';
|
|
@@ -896,7 +898,11 @@ export default class Form<
|
|
|
896
898
|
const { extraErrors, omitExtraData, liveOmit, noValidate, liveValidate, onChange, removeEmptyOptionalObjects } =
|
|
897
899
|
this.props;
|
|
898
900
|
const { formData: oldFormData, schemaUtils, schema, fieldPathId, schemaValidationErrorSchema, errors } = this.state;
|
|
899
|
-
let { customErrors
|
|
901
|
+
let { customErrors } = this.state;
|
|
902
|
+
// Use the un-merged AJV-only schema as the base for re-merging extraErrors. Mirrors the
|
|
903
|
+
// pattern in getStateFromProps/getDerivedStateFromProps and avoids the duplication that
|
|
904
|
+
// happened when state.errorSchema (already containing merged extraErrors) was passed in.
|
|
905
|
+
let mergeBaseErrorSchema: ErrorSchema<T> = schemaValidationErrorSchema as ErrorSchema<T>;
|
|
900
906
|
const rootPathId = fieldPathId.path[0] || '';
|
|
901
907
|
|
|
902
908
|
const isRootPath = !path || path.length === 0 || (path.length === 1 && path[0] === rootPathId);
|
|
@@ -920,7 +926,33 @@ export default class Form<
|
|
|
920
926
|
_unset(formData, path);
|
|
921
927
|
} else if (!isRootPath) {
|
|
922
928
|
// If the newValue is not on the root path, then set it into the form data
|
|
923
|
-
|
|
929
|
+
let unsetPath = false;
|
|
930
|
+
let valueForPath: T | null | undefined = newValue;
|
|
931
|
+
|
|
932
|
+
if (newValue === undefined) {
|
|
933
|
+
const lastSegment = path[path.length - 1];
|
|
934
|
+
if (typeof lastSegment === 'number') {
|
|
935
|
+
// Array items: match ArrayField `handleChange` — AJV needs `null`, not undefined.
|
|
936
|
+
valueForPath = null as unknown as T;
|
|
937
|
+
} else {
|
|
938
|
+
const { field } = schemaUtils.findFieldInSchema(schema, path, oldFormData);
|
|
939
|
+
const leaf = field as RJSFSchema | undefined;
|
|
940
|
+
const isOneOfOrAnyOfLeaf = leaf && (ONE_OF_KEY in leaf || ANY_OF_KEY in leaf);
|
|
941
|
+
// Plain leaves: omit the key instead of `{ key: undefined }`, which breaks `type: "string"` validation in
|
|
942
|
+
// AJV after clearing a text input (https://github.com/rjsf-team/react-jsonschema-form/issues/4518).
|
|
943
|
+
// oneOf/anyOf leaves and unresolved leaves: keep `valueForPath === newValue` (already `undefined`) so
|
|
944
|
+
// mergeDefaults does not immediately re-apply a branch default when clearing those widgets.
|
|
945
|
+
if (!isOneOfOrAnyOfLeaf && leaf !== undefined) {
|
|
946
|
+
unsetPath = true;
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
if (unsetPath) {
|
|
952
|
+
_unset(formData, path);
|
|
953
|
+
} else {
|
|
954
|
+
_set(formData, path, valueForPath);
|
|
955
|
+
}
|
|
924
956
|
}
|
|
925
957
|
// Pass true to skip live validation in `getStateFromProps()` since we will do it a bit later
|
|
926
958
|
const newState = this.getStateFromProps(this.props, inputForDefaults, undefined, undefined, undefined, true);
|
|
@@ -958,11 +990,13 @@ export default class Form<
|
|
|
958
990
|
const oldValidationError = !isRootPath ? _get(schemaValidationErrorSchema, path) : schemaValidationErrorSchema;
|
|
959
991
|
// If there is an old validation error for this path, assume we are updating it directly
|
|
960
992
|
if (!_isEmpty(oldValidationError)) {
|
|
961
|
-
//
|
|
993
|
+
// Apply the user-supplied newErrorSchema onto a clone of the AJV-only base, so that
|
|
994
|
+
// mergeErrors below sees the user's error at this path without mutating shared state.
|
|
962
995
|
if (!isRootPath) {
|
|
963
|
-
|
|
996
|
+
mergeBaseErrorSchema = _cloneDeep(schemaValidationErrorSchema) as ErrorSchema<T>;
|
|
997
|
+
_set(mergeBaseErrorSchema, path, newErrorSchema);
|
|
964
998
|
} else {
|
|
965
|
-
|
|
999
|
+
mergeBaseErrorSchema = newErrorSchema as ErrorSchema<T>;
|
|
966
1000
|
}
|
|
967
1001
|
} else {
|
|
968
1002
|
if (!customErrors) {
|
|
@@ -987,7 +1021,7 @@ export default class Form<
|
|
|
987
1021
|
const liveValidation = this.liveValidate(
|
|
988
1022
|
schema,
|
|
989
1023
|
schemaUtils,
|
|
990
|
-
|
|
1024
|
+
mergeBaseErrorSchema,
|
|
991
1025
|
newFormData,
|
|
992
1026
|
extraErrors,
|
|
993
1027
|
customErrors,
|
|
@@ -996,7 +1030,7 @@ export default class Form<
|
|
|
996
1030
|
state = { formData: newFormData, ...liveValidation, customErrors };
|
|
997
1031
|
} else if (!noValidate && newErrorSchema) {
|
|
998
1032
|
// Merging 'newErrorSchema' into 'errorSchema' to display the custom raised errors.
|
|
999
|
-
const mergedErrors = this.mergeErrors({ errorSchema:
|
|
1033
|
+
const mergedErrors = this.mergeErrors({ errorSchema: mergeBaseErrorSchema, errors }, extraErrors, customErrors);
|
|
1000
1034
|
state = {
|
|
1001
1035
|
formData: newFormData,
|
|
1002
1036
|
...mergedErrors,
|
|
@@ -1028,10 +1028,12 @@ export default function ArrayField<T = any, S extends StrictRJSFSchema = RJSFSch
|
|
|
1028
1028
|
*/
|
|
1029
1029
|
const handleChange = useCallback(
|
|
1030
1030
|
(value: any, path: FieldPathList, newErrorSchema?: ErrorSchema<T>, id?: string) => {
|
|
1031
|
+
const lastPathIsItemIndex = typeof path.at(-1) === 'number';
|
|
1031
1032
|
onChange(
|
|
1032
1033
|
// We need to treat undefined items as nulls to have validation.
|
|
1033
1034
|
// See https://github.com/tdegrunt/jsonschema/issues/206
|
|
1034
|
-
|
|
1035
|
+
// Only set to null for array items, and not for object properties within array items
|
|
1036
|
+
lastPathIsItemIndex && value === undefined ? null : value,
|
|
1035
1037
|
path,
|
|
1036
1038
|
newErrorSchema as ErrorSchema<T[]>,
|
|
1037
1039
|
id,
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
shouldRenderOptionalField,
|
|
24
24
|
StrictRJSFSchema,
|
|
25
25
|
toFieldPathId,
|
|
26
|
+
TranslatableString,
|
|
26
27
|
UI_OPTIONS_KEY,
|
|
27
28
|
UIOptionsType,
|
|
28
29
|
} from '@rjsf/utils';
|
|
@@ -133,7 +134,11 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
133
134
|
);
|
|
134
135
|
|
|
135
136
|
const FieldComponent = getFieldComponent<T, S, F>(schema, uiOptions, registry);
|
|
136
|
-
|
|
137
|
+
|
|
138
|
+
const isDeprecated = Boolean(schema.deprecated);
|
|
139
|
+
const deprecatedHandling = isDeprecated ? (uiOptions.deprecatedHandling ?? 'label') : undefined;
|
|
140
|
+
|
|
141
|
+
const disabled = Boolean(uiOptions.disabled ?? props.disabled) || deprecatedHandling === 'disable';
|
|
137
142
|
const readonly = Boolean(uiOptions.readonly ?? (props.readonly || props.schema.readOnly || schema.readOnly));
|
|
138
143
|
const uiSchemaHideError = uiOptions.hideError;
|
|
139
144
|
// Set hideError to the value provided in the uiSchema, otherwise stick with the prop to propagate to children
|
|
@@ -214,9 +219,13 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
214
219
|
: uiOptions.title || props.schema.title || schema.title || props.title || name;
|
|
215
220
|
}
|
|
216
221
|
|
|
222
|
+
if (deprecatedHandling === 'label') {
|
|
223
|
+
label = registry.translateString(TranslatableString.DeprecatedLabel, [label]);
|
|
224
|
+
}
|
|
225
|
+
|
|
217
226
|
const description = uiOptions.description || props.schema.description || schema.description || '';
|
|
218
227
|
const help = uiOptions.help;
|
|
219
|
-
const hidden = uiOptions.widget === 'hidden';
|
|
228
|
+
const hidden = uiOptions.widget === 'hidden' || deprecatedHandling === 'hide';
|
|
220
229
|
|
|
221
230
|
const classNames = ['rjsf-field', `rjsf-field-${getSchemaType(schema)}`];
|
|
222
231
|
if (!hideError && __errors && __errors.length > 0) {
|