@rjsf/utils 5.24.8 → 5.24.10

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/package.json CHANGED
@@ -1,37 +1,10 @@
1
1
  {
2
2
  "name": "@rjsf/utils",
3
- "version": "5.24.8",
3
+ "version": "5.24.10",
4
4
  "main": "dist/index.js",
5
5
  "module": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "description": "Utility functions for @rjsf/core",
8
- "exports": {
9
- ".": {
10
- "require": "./dist/index.js",
11
- "import": "./lib/index.js",
12
- "types": "./lib/index.d.ts"
13
- },
14
- "./lib": {
15
- "require": "./dist/index.js",
16
- "import": "./lib/index.js",
17
- "types": "./lib/index.d.ts"
18
- },
19
- "./lib/*.js": {
20
- "require": "./dist/*.js",
21
- "import": "./lib/*.js",
22
- "types": "./lib/*.d.ts"
23
- },
24
- "./dist": {
25
- "require": "./dist/index.js",
26
- "import": "./lib/index.js",
27
- "types": "./lib/index.d.ts"
28
- },
29
- "./dist/*.js": {
30
- "require": "./dist/*.js",
31
- "import": "./lib/*.js",
32
- "types": "./lib/*.d.ts"
33
- }
34
- },
35
8
  "files": [
36
9
  "dist",
37
10
  "lib",
@@ -113,5 +86,5 @@
113
86
  "url": "git+https://github.com/rjsf-team/react-jsonschema-form.git"
114
87
  },
115
88
  "license": "Apache-2.0",
116
- "gitHead": "840f8fa9882fa178cc772951638e1bf505e2af50"
89
+ "gitHead": "ad33d7c324cb040d0f34da30a17caea0251f1e3a"
117
90
  }
@@ -223,7 +223,9 @@ export function computeDefaults<T = any, S extends StrictRJSFSchema = RJSFSchema
223
223
  // For object defaults, only override parent defaults that are defined in
224
224
  // schema.default.
225
225
  defaults = mergeObjects(defaults!, schema.default as GenericObjectType) as T;
226
- } else if (DEFAULT_KEY in schema) {
226
+ } else if (DEFAULT_KEY in schema && !schema[ANY_OF_KEY] && !schema[ONE_OF_KEY]) {
227
+ // If the schema has a default value, then we should use it as the default.
228
+ // And if the schema does not have anyOf or oneOf, this is done because we need to merge the defaults with the formData.
227
229
  defaults = schema.default as unknown as T;
228
230
  } else if (REF_KEY in schema) {
229
231
  const refName = schema[REF_KEY];
@@ -284,7 +286,7 @@ export function computeDefaults<T = any, S extends StrictRJSFSchema = RJSFSchema
284
286
  getClosestMatchingOption<T, S, F>(
285
287
  validator,
286
288
  rootSchema,
287
- rawFormData,
289
+ rawFormData ?? (schema.default as T),
288
290
  oneOf as S[],
289
291
  0,
290
292
  discriminator,
@@ -302,7 +304,7 @@ export function computeDefaults<T = any, S extends StrictRJSFSchema = RJSFSchema
302
304
  getClosestMatchingOption<T, S, F>(
303
305
  validator,
304
306
  rootSchema,
305
- rawFormData,
307
+ rawFormData ?? (schema.default as T),
306
308
  anyOf as S[],
307
309
  0,
308
310
  discriminator,
@@ -347,7 +349,9 @@ export function computeDefaults<T = any, S extends StrictRJSFSchema = RJSFSchema
347
349
  experimental_defaultFormStateBehavior,
348
350
  experimental_customMergeAllOf
349
351
  );
350
- if (!isObject(rawFormData)) {
352
+ if (!isObject(rawFormData) || ALL_OF_KEY in schema) {
353
+ // If the formData is not an object which means it's a primitive field, then we need to merge the defaults into the formData.
354
+ // Or if the schema has allOf, we need to merge the defaults into the formData because we don't compute the defaults for allOf.
351
355
  defaultsWithFormData = mergeDefaultsWithFormData<T>(
352
356
  defaultsWithFormData as T,
353
357
  matchingFormData as T,