@rjsf/utils
Advanced tools
Comparing version
@@ -49,6 +49,18 @@ import get from 'lodash-es/get.js'; | ||
return Object.keys(formData).reduce((acc, key) => { | ||
var _a, _b; | ||
const keyValue = get(formData, key); | ||
const keyExistsInDefaults = isObject(defaults) && key in defaults; | ||
const keyExistsInFormData = key in formData; | ||
acc[key] = mergeDefaultsWithFormData(defaults ? get(defaults, key) : {}, keyValue, mergeExtraArrayDefaults, defaultSupercedesUndefined, | ||
const keyDefault = (_a = get(defaults, key)) !== null && _a !== void 0 ? _a : {}; | ||
const defaultValueIsNestedObject = keyExistsInDefaults && Object.entries(keyDefault).some(([, v]) => isObject(v)); | ||
const keyDefaultIsObject = keyExistsInDefaults && isObject(get(defaults, key)); | ||
const keyHasFormDataObject = keyExistsInFormData && isObject(keyValue); | ||
if (keyDefaultIsObject && keyHasFormDataObject && !defaultValueIsNestedObject) { | ||
acc[key] = { | ||
...get(defaults, key), | ||
...keyValue, | ||
}; | ||
return acc; | ||
} | ||
acc[key] = mergeDefaultsWithFormData((_b = get(defaults, key)) !== null && _b !== void 0 ? _b : {}, keyValue, mergeExtraArrayDefaults, defaultSupercedesUndefined, | ||
// overrideFormDataWithDefaults can be true only when the key value exists in defaults | ||
@@ -55,0 +67,0 @@ // Or if the key value doesn't exist in formData |
@@ -137,3 +137,3 @@ import get from 'lodash-es/get.js'; | ||
let updatedRecurseList = _recurseList; | ||
if (schema[CONST_KEY] && | ||
if (schema[CONST_KEY] !== undefined && | ||
(experimental_defaultFormStateBehavior === null || experimental_defaultFormStateBehavior === void 0 ? void 0 : experimental_defaultFormStateBehavior.constAsDefaults) !== 'never' && | ||
@@ -230,3 +230,3 @@ !constIsAjvDataReference(schema)) { | ||
parentDefaults: defaults, | ||
rawFormData: formData, | ||
rawFormData: (rawFormData !== null && rawFormData !== void 0 ? rawFormData : formData), | ||
required, | ||
@@ -506,2 +506,8 @@ shouldMergeDefaultsIntoFormData, | ||
}); | ||
if (schema.type !== 'object' && isObject(schema.default)) { | ||
return { | ||
...defaults, | ||
...formData, | ||
}; | ||
} | ||
// If the formData is an object or an array, add additional properties from formData and override formData with | ||
@@ -508,0 +514,0 @@ // defaults since the defaults are already merged with formData. |
@@ -279,2 +279,4 @@ import type { ButtonHTMLAttributes, ChangeEvent, ComponentType, HTMLAttributes, ReactElement, ReactNode, StyleHTMLAttributes } from 'react'; | ||
GridTemplate: ComponentType<GridTemplateProps>; | ||
/** The template to use while rendering a multi-schema field (i.e. anyOf, oneOf) */ | ||
MultiSchemaFieldTemplate: ComponentType<MultiSchemaFieldTemplateProps<T, S, F>>; | ||
/** The template to use while rendering an object */ | ||
@@ -631,2 +633,9 @@ ObjectFieldTemplate: ComponentType<ObjectFieldTemplateProps<T, S, F>>; | ||
} & Pick<FieldTemplateProps<T, S, F>, 'id' | 'classNames' | 'hideError' | 'rawErrors' | 'style' | 'label' | 'required' | 'readonly' | 'disabled' | 'schema' | 'uiSchema' | 'onKeyChange' | 'onDropPropertyClick' | 'registry'>; | ||
/** The properties that are passed to a MultiSchemaFieldTemplate implementation */ | ||
export interface MultiSchemaFieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> extends RJSFBaseProps<T, S, F> { | ||
/** The rendered widget used to select a schema option */ | ||
selector: ReactNode; | ||
/** The rendered SchemaField for the selected schema option */ | ||
optionSchemaField: ReactNode; | ||
} | ||
/** The properties that are passed to a Widget implementation */ | ||
@@ -633,0 +642,0 @@ export interface WidgetProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> extends GenericObjectType, RJSFBaseProps<T, S, F>, Pick<HTMLAttributes<HTMLElement>, Exclude<keyof HTMLAttributes<HTMLElement>, 'onBlur' | 'onFocus'>> { |
{ | ||
"name": "@rjsf/utils", | ||
"version": "6.0.0-beta.10", | ||
"version": "6.0.0-beta.11", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "module": "lib/index.js", |
@@ -70,4 +70,18 @@ import get from 'lodash/get'; | ||
const keyExistsInFormData = key in (formData as GenericObjectType); | ||
const keyDefault = get(defaults, key) ?? {}; | ||
const defaultValueIsNestedObject = keyExistsInDefaults && Object.entries(keyDefault).some(([, v]) => isObject(v)); | ||
const keyDefaultIsObject = keyExistsInDefaults && isObject(get(defaults, key)); | ||
const keyHasFormDataObject = keyExistsInFormData && isObject(keyValue); | ||
if (keyDefaultIsObject && keyHasFormDataObject && !defaultValueIsNestedObject) { | ||
acc[key as keyof T] = { | ||
...get(defaults, key), | ||
...keyValue, | ||
}; | ||
return acc; | ||
} | ||
acc[key as keyof T] = mergeDefaultsWithFormData<T>( | ||
defaults ? get(defaults, key) : {}, | ||
get(defaults, key) ?? {}, | ||
keyValue, | ||
@@ -74,0 +88,0 @@ mergeExtraArrayDefaults, |
@@ -216,3 +216,3 @@ import get from 'lodash/get'; | ||
if ( | ||
schema[CONST_KEY] && | ||
schema[CONST_KEY] !== undefined && | ||
experimental_defaultFormStateBehavior?.constAsDefaults !== 'never' && | ||
@@ -338,3 +338,3 @@ !constIsAjvDataReference(schema) | ||
parentDefaults: defaults as T | undefined, | ||
rawFormData: formData as T, | ||
rawFormData: (rawFormData ?? formData) as T, | ||
required, | ||
@@ -733,2 +733,9 @@ shouldMergeDefaultsIntoFormData, | ||
if (schema.type !== 'object' && isObject(schema.default)) { | ||
return { | ||
...defaults, | ||
...formData, | ||
} as T; | ||
} | ||
// If the formData is an object or an array, add additional properties from formData and override formData with | ||
@@ -735,0 +742,0 @@ // defaults since the defaults are already merged with formData. |
@@ -344,2 +344,4 @@ import type { | ||
GridTemplate: ComponentType<GridTemplateProps>; | ||
/** The template to use while rendering a multi-schema field (i.e. anyOf, oneOf) */ | ||
MultiSchemaFieldTemplate: ComponentType<MultiSchemaFieldTemplateProps<T, S, F>>; | ||
/** The template to use while rendering an object */ | ||
@@ -781,2 +783,14 @@ ObjectFieldTemplate: ComponentType<ObjectFieldTemplateProps<T, S, F>>; | ||
/** The properties that are passed to a MultiSchemaFieldTemplate implementation */ | ||
export interface MultiSchemaFieldTemplateProps< | ||
T = any, | ||
S extends StrictRJSFSchema = RJSFSchema, | ||
F extends FormContextType = any, | ||
> extends RJSFBaseProps<T, S, F> { | ||
/** The rendered widget used to select a schema option */ | ||
selector: ReactNode; | ||
/** The rendered SchemaField for the selected schema option */ | ||
optionSchemaField: ReactNode; | ||
} | ||
/** The properties that are passed to a Widget implementation */ | ||
@@ -783,0 +797,0 @@ export interface WidgetProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
2000219
0.41%24136
0.45%