@rjsf/utils 5.22.4 → 5.23.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.js +166 -55
- package/dist/index.js.map +2 -2
- package/dist/utils.esm.js +166 -55
- package/dist/utils.esm.js.map +2 -2
- package/dist/utils.umd.js +178 -59
- package/lib/ErrorSchemaBuilder.js +3 -3
- package/lib/ErrorSchemaBuilder.js.map +1 -1
- package/lib/createSchemaUtils.js +7 -7
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/schema/getClosestMatchingOption.d.ts +5 -3
- package/lib/schema/getClosestMatchingOption.js +11 -7
- package/lib/schema/getClosestMatchingOption.js.map +1 -1
- package/lib/schema/getDefaultFormState.d.ts +1 -1
- package/lib/schema/getDefaultFormState.js +28 -11
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getDisplayLabel.d.ts +3 -2
- package/lib/schema/getDisplayLabel.js +4 -3
- package/lib/schema/getDisplayLabel.js.map +1 -1
- package/lib/schema/isFilesArray.d.ts +3 -2
- package/lib/schema/isFilesArray.js +3 -2
- package/lib/schema/isFilesArray.js.map +1 -1
- package/lib/schema/isMultiSelect.d.ts +3 -2
- package/lib/schema/isMultiSelect.js +3 -2
- package/lib/schema/isMultiSelect.js.map +1 -1
- package/lib/schema/isSelect.d.ts +3 -2
- package/lib/schema/isSelect.js +3 -2
- package/lib/schema/isSelect.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +2 -1
- package/lib/schema/retrieveSchema.js +5 -4
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/schema/sanitizeDataForNewSchema.d.ts +3 -2
- package/lib/schema/sanitizeDataForNewSchema.js +8 -7
- package/lib/schema/sanitizeDataForNewSchema.js.map +1 -1
- package/lib/schema/toIdSchema.js +1 -1
- package/lib/schema/toIdSchema.js.map +1 -1
- package/lib/schema/toPathSchema.d.ts +3 -2
- package/lib/schema/toPathSchema.js +13 -11
- package/lib/schema/toPathSchema.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +12 -0
- package/package.json +2 -2
- package/src/ErrorSchemaBuilder.ts +3 -3
- package/src/createSchemaUtils.ts +29 -7
- package/src/schema/getClosestMatchingOption.ts +31 -8
- package/src/schema/getDefaultFormState.ts +35 -10
- package/src/schema/getDisplayLabel.ts +6 -3
- package/src/schema/isFilesArray.ts +18 -3
- package/src/schema/isMultiSelect.ts +9 -3
- package/src/schema/isSelect.ts +5 -3
- package/src/schema/retrieveSchema.ts +19 -4
- package/src/schema/sanitizeDataForNewSchema.ts +49 -8
- package/src/schema/toIdSchema.ts +1 -1
- package/src/schema/toPathSchema.ts +45 -12
- package/src/types.ts +12 -0
|
@@ -15,7 +15,15 @@ import {
|
|
|
15
15
|
RJSF_ADDITIONAL_PROPERTIES_FLAG,
|
|
16
16
|
} from '../constants';
|
|
17
17
|
import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema';
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
Experimental_CustomMergeAllOf,
|
|
20
|
+
FormContextType,
|
|
21
|
+
GenericObjectType,
|
|
22
|
+
PathSchema,
|
|
23
|
+
RJSFSchema,
|
|
24
|
+
StrictRJSFSchema,
|
|
25
|
+
ValidatorType,
|
|
26
|
+
} from '../types';
|
|
19
27
|
import getClosestMatchingOption from './getClosestMatchingOption';
|
|
20
28
|
import retrieveSchema from './retrieveSchema';
|
|
21
29
|
|
|
@@ -28,6 +36,7 @@ import retrieveSchema from './retrieveSchema';
|
|
|
28
36
|
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
29
37
|
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
30
38
|
* @param [_recurseList=[]] - The list of retrieved schemas currently being recursed, used to prevent infinite recursion
|
|
39
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
31
40
|
* @returns - The `PathSchema` object for the `schema`
|
|
32
41
|
*/
|
|
33
42
|
function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
@@ -36,10 +45,11 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
36
45
|
name: string,
|
|
37
46
|
rootSchema?: S,
|
|
38
47
|
formData?: T,
|
|
39
|
-
_recurseList: S[] = []
|
|
48
|
+
_recurseList: S[] = [],
|
|
49
|
+
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>
|
|
40
50
|
): PathSchema<T> {
|
|
41
51
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
42
|
-
const _schema = retrieveSchema<T, S, F>(validator, schema, rootSchema, formData);
|
|
52
|
+
const _schema = retrieveSchema<T, S, F>(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
43
53
|
const sameSchemaIndex = _recurseList.findIndex((item) => isEqual(item, _schema));
|
|
44
54
|
if (sameSchemaIndex === -1) {
|
|
45
55
|
return toPathSchemaInternal<T, S, F>(
|
|
@@ -48,7 +58,8 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
48
58
|
name,
|
|
49
59
|
rootSchema,
|
|
50
60
|
formData,
|
|
51
|
-
_recurseList.concat(_schema)
|
|
61
|
+
_recurseList.concat(_schema),
|
|
62
|
+
experimental_customMergeAllOf
|
|
52
63
|
);
|
|
53
64
|
}
|
|
54
65
|
}
|
|
@@ -60,11 +71,27 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
60
71
|
if (ONE_OF_KEY in schema || ANY_OF_KEY in schema) {
|
|
61
72
|
const xxxOf: S[] = ONE_OF_KEY in schema ? (schema.oneOf as S[]) : (schema.anyOf as S[]);
|
|
62
73
|
const discriminator = getDiscriminatorFieldFromSchema<S>(schema);
|
|
63
|
-
const index = getClosestMatchingOption<T, S, F>(
|
|
74
|
+
const index = getClosestMatchingOption<T, S, F>(
|
|
75
|
+
validator,
|
|
76
|
+
rootSchema!,
|
|
77
|
+
formData,
|
|
78
|
+
xxxOf,
|
|
79
|
+
0,
|
|
80
|
+
discriminator,
|
|
81
|
+
experimental_customMergeAllOf
|
|
82
|
+
);
|
|
64
83
|
const _schema: S = xxxOf![index] as S;
|
|
65
84
|
pathSchema = {
|
|
66
85
|
...pathSchema,
|
|
67
|
-
...toPathSchemaInternal<T, S, F>(
|
|
86
|
+
...toPathSchemaInternal<T, S, F>(
|
|
87
|
+
validator,
|
|
88
|
+
_schema,
|
|
89
|
+
name,
|
|
90
|
+
rootSchema,
|
|
91
|
+
formData,
|
|
92
|
+
_recurseList,
|
|
93
|
+
experimental_customMergeAllOf
|
|
94
|
+
),
|
|
68
95
|
};
|
|
69
96
|
}
|
|
70
97
|
|
|
@@ -84,7 +111,8 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
84
111
|
`${name}.${i}`,
|
|
85
112
|
rootSchema,
|
|
86
113
|
element,
|
|
87
|
-
_recurseList
|
|
114
|
+
_recurseList,
|
|
115
|
+
experimental_customMergeAllOf
|
|
88
116
|
);
|
|
89
117
|
} else if (schemaAdditionalItems) {
|
|
90
118
|
(pathSchema as PathSchema<T[]>)[i] = toPathSchemaInternal<T, S, F>(
|
|
@@ -93,7 +121,8 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
93
121
|
`${name}.${i}`,
|
|
94
122
|
rootSchema,
|
|
95
123
|
element,
|
|
96
|
-
_recurseList
|
|
124
|
+
_recurseList,
|
|
125
|
+
experimental_customMergeAllOf
|
|
97
126
|
);
|
|
98
127
|
} else {
|
|
99
128
|
console.warn(`Unable to generate path schema for "${name}.${i}". No schema defined for it`);
|
|
@@ -107,7 +136,8 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
107
136
|
`${name}.${i}`,
|
|
108
137
|
rootSchema,
|
|
109
138
|
element,
|
|
110
|
-
_recurseList
|
|
139
|
+
_recurseList,
|
|
140
|
+
experimental_customMergeAllOf
|
|
111
141
|
);
|
|
112
142
|
});
|
|
113
143
|
}
|
|
@@ -122,7 +152,8 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
122
152
|
// It's possible that formData is not an object -- this can happen if an
|
|
123
153
|
// array item has just been added, but not populated with data yet
|
|
124
154
|
get(formData, [property]),
|
|
125
|
-
_recurseList
|
|
155
|
+
_recurseList,
|
|
156
|
+
experimental_customMergeAllOf
|
|
126
157
|
);
|
|
127
158
|
}
|
|
128
159
|
}
|
|
@@ -136,6 +167,7 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
136
167
|
* @param [name=''] - The base name for the schema
|
|
137
168
|
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
138
169
|
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
170
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
139
171
|
* @returns - The `PathSchema` object for the `schema`
|
|
140
172
|
*/
|
|
141
173
|
export default function toPathSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
@@ -143,7 +175,8 @@ export default function toPathSchema<T = any, S extends StrictRJSFSchema = RJSFS
|
|
|
143
175
|
schema: S,
|
|
144
176
|
name = '',
|
|
145
177
|
rootSchema?: S,
|
|
146
|
-
formData?: T
|
|
178
|
+
formData?: T,
|
|
179
|
+
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>
|
|
147
180
|
): PathSchema<T> {
|
|
148
|
-
return toPathSchemaInternal(validator, schema, name, rootSchema, formData);
|
|
181
|
+
return toPathSchemaInternal(validator, schema, name, rootSchema, formData, undefined, experimental_customMergeAllOf);
|
|
149
182
|
}
|
package/src/types.ts
CHANGED
|
@@ -96,6 +96,18 @@ export type Experimental_DefaultFormStateBehavior = {
|
|
|
96
96
|
* default value instead
|
|
97
97
|
*/
|
|
98
98
|
mergeDefaultsIntoFormData?: 'useFormDataIfPresent' | 'useDefaultIfFormDataUndefined';
|
|
99
|
+
/** Optional enumerated flag controlling how const values are merged into the form data as defaults when dealing with
|
|
100
|
+
* undefined values, defaulting to `always`. The defaulting behavior for this flag will always be controlled by the
|
|
101
|
+
* `emptyObjectField` flag value. For instance, if `populateRequiredDefaults` is set and the const value is not
|
|
102
|
+
* required, it will not be set.
|
|
103
|
+
* - `always`: A const value will always be merged into the form as a default. If there is are const values in a
|
|
104
|
+
* `oneOf` (for instance to create an enumeration with title different from the values), the first const value
|
|
105
|
+
* will be defaulted
|
|
106
|
+
* - `skipOneOf`: If const is in a `oneOf` it will NOT pick the first value as a default
|
|
107
|
+
* - `never`: A const value will never be used as a default
|
|
108
|
+
*
|
|
109
|
+
*/
|
|
110
|
+
constAsDefaults?: 'always' | 'skipOneOf' | 'never';
|
|
99
111
|
};
|
|
100
112
|
|
|
101
113
|
/** Optional function that allows for custom merging of `allOf` schemas
|