@rjsf/utils 6.0.0-beta.10 → 6.0.0-beta.11

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.
@@ -213,7 +213,7 @@ export function computeDefaults<T = any, S extends StrictRJSFSchema = RJSFSchema
213
213
  let experimental_dfsb_to_compute = experimental_defaultFormStateBehavior;
214
214
  let updatedRecurseList = _recurseList;
215
215
  if (
216
- schema[CONST_KEY] &&
216
+ schema[CONST_KEY] !== undefined &&
217
217
  experimental_defaultFormStateBehavior?.constAsDefaults !== 'never' &&
218
218
  !constIsAjvDataReference(schema)
219
219
  ) {
@@ -334,7 +334,7 @@ export function computeDefaults<T = any, S extends StrictRJSFSchema = RJSFSchema
334
334
  experimental_defaultFormStateBehavior: experimental_dfsb_to_compute,
335
335
  experimental_customMergeAllOf,
336
336
  parentDefaults: defaults as T | undefined,
337
- rawFormData: formData as T,
337
+ rawFormData: (rawFormData ?? formData) as T,
338
338
  required,
339
339
  shouldMergeDefaultsIntoFormData,
340
340
  });
@@ -728,6 +728,13 @@ export default function getDefaultFormState<
728
728
  shouldMergeDefaultsIntoFormData: true,
729
729
  });
730
730
 
731
+ if (schema.type !== 'object' && isObject(schema.default)) {
732
+ return {
733
+ ...defaults,
734
+ ...formData,
735
+ } as T;
736
+ }
737
+
731
738
  // If the formData is an object or an array, add additional properties from formData and override formData with
732
739
  // defaults since the defaults are already merged with formData.
733
740
  if (isObject(formData) || Array.isArray(formData)) {
package/src/types.ts CHANGED
@@ -341,6 +341,8 @@ export type TemplatesType<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
341
341
  FieldTemplate: ComponentType<FieldTemplateProps<T, S, F>>;
342
342
  /** The template to use to render a Grid element */
343
343
  GridTemplate: ComponentType<GridTemplateProps>;
344
+ /** The template to use while rendering a multi-schema field (i.e. anyOf, oneOf) */
345
+ MultiSchemaFieldTemplate: ComponentType<MultiSchemaFieldTemplateProps<T, S, F>>;
344
346
  /** The template to use while rendering an object */
345
347
  ObjectFieldTemplate: ComponentType<ObjectFieldTemplateProps<T, S, F>>;
346
348
  /** The template to use for rendering the title of a field */
@@ -777,6 +779,18 @@ export type WrapIfAdditionalTemplateProps<
777
779
  | 'registry'
778
780
  >;
779
781
 
782
+ /** The properties that are passed to a MultiSchemaFieldTemplate implementation */
783
+ export interface MultiSchemaFieldTemplateProps<
784
+ T = any,
785
+ S extends StrictRJSFSchema = RJSFSchema,
786
+ F extends FormContextType = any,
787
+ > extends RJSFBaseProps<T, S, F> {
788
+ /** The rendered widget used to select a schema option */
789
+ selector: ReactNode;
790
+ /** The rendered SchemaField for the selected schema option */
791
+ optionSchemaField: ReactNode;
792
+ }
793
+
780
794
  /** The properties that are passed to a Widget implementation */
781
795
  export interface WidgetProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>
782
796
  extends GenericObjectType,