@rjsf/core 6.0.0-beta.21 → 6.0.0-beta.23
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 +1580 -1771
- package/dist/index.cjs +2019 -2206
- package/dist/index.cjs.map +4 -4
- package/dist/index.esm.js +2011 -2182
- package/dist/index.esm.js.map +4 -4
- package/lib/components/Form.d.ts +50 -12
- package/lib/components/Form.d.ts.map +1 -1
- package/lib/components/Form.js +114 -31
- package/lib/components/fields/ArrayField.d.ts +2 -197
- package/lib/components/fields/ArrayField.d.ts.map +1 -1
- package/lib/components/fields/ArrayField.js +518 -536
- package/lib/components/fields/BooleanField.js +2 -2
- package/lib/components/fields/FallbackField.d.ts +7 -0
- package/lib/components/fields/FallbackField.d.ts.map +1 -0
- package/lib/components/fields/FallbackField.js +72 -0
- package/lib/components/fields/LayoutGridField.d.ts +109 -191
- package/lib/components/fields/LayoutGridField.d.ts.map +1 -1
- package/lib/components/fields/LayoutGridField.js +417 -444
- package/lib/components/fields/LayoutMultiSchemaField.d.ts.map +1 -1
- package/lib/components/fields/LayoutMultiSchemaField.js +2 -3
- package/lib/components/fields/MultiSchemaField.d.ts.map +1 -1
- package/lib/components/fields/MultiSchemaField.js +5 -3
- package/lib/components/fields/ObjectField.d.ts +2 -68
- package/lib/components/fields/ObjectField.d.ts.map +1 -1
- package/lib/components/fields/ObjectField.js +166 -168
- package/lib/components/fields/SchemaField.d.ts.map +1 -1
- package/lib/components/fields/SchemaField.js +35 -22
- package/lib/components/fields/StringField.js +2 -2
- package/lib/components/fields/index.d.ts.map +1 -1
- package/lib/components/fields/index.js +2 -0
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts +3 -3
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.js +3 -8
- package/lib/components/templates/ArrayFieldItemTemplate.d.ts +3 -3
- package/lib/components/templates/ArrayFieldItemTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldItemTemplate.js +1 -1
- package/lib/components/templates/ArrayFieldTemplate.d.ts +1 -1
- package/lib/components/templates/ArrayFieldTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldTemplate.js +2 -4
- package/lib/components/templates/BaseInputTemplate.js +2 -2
- package/lib/components/templates/FallbackFieldTemplate.d.ts +7 -0
- package/lib/components/templates/FallbackFieldTemplate.d.ts.map +1 -0
- package/lib/components/templates/FallbackFieldTemplate.js +12 -0
- package/lib/components/templates/ObjectFieldTemplate.js +2 -2
- package/lib/components/templates/WrapIfAdditionalTemplate.js +2 -2
- package/lib/components/templates/index.d.ts.map +1 -1
- package/lib/components/templates/index.js +2 -0
- package/lib/components/widgets/AltDateWidget.d.ts +1 -1
- package/lib/components/widgets/AltDateWidget.d.ts.map +1 -1
- package/lib/components/widgets/AltDateWidget.js +5 -43
- package/lib/components/widgets/CheckboxWidget.d.ts +1 -1
- package/lib/components/widgets/CheckboxWidget.d.ts.map +1 -1
- package/lib/components/widgets/CheckboxWidget.js +2 -2
- package/lib/components/widgets/CheckboxesWidget.d.ts +1 -1
- package/lib/components/widgets/CheckboxesWidget.d.ts.map +1 -1
- package/lib/components/widgets/CheckboxesWidget.js +2 -2
- package/lib/components/widgets/FileWidget.d.ts.map +1 -1
- package/lib/components/widgets/FileWidget.js +7 -87
- package/lib/components/widgets/HiddenWidget.d.ts +1 -1
- package/lib/components/widgets/HiddenWidget.d.ts.map +1 -1
- package/lib/components/widgets/HiddenWidget.js +2 -2
- package/lib/components/widgets/RadioWidget.d.ts +1 -1
- package/lib/components/widgets/RadioWidget.d.ts.map +1 -1
- package/lib/components/widgets/RadioWidget.js +2 -2
- package/lib/components/widgets/RatingWidget.d.ts +1 -1
- package/lib/components/widgets/RatingWidget.d.ts.map +1 -1
- package/lib/components/widgets/RatingWidget.js +2 -2
- package/lib/components/widgets/SelectWidget.d.ts +1 -1
- package/lib/components/widgets/SelectWidget.d.ts.map +1 -1
- package/lib/components/widgets/SelectWidget.js +2 -2
- package/lib/components/widgets/TextareaWidget.d.ts +1 -1
- package/lib/components/widgets/TextareaWidget.d.ts.map +1 -1
- package/lib/components/widgets/TextareaWidget.js +2 -2
- package/lib/getDefaultRegistry.d.ts.map +1 -1
- package/lib/getDefaultRegistry.js +5 -1
- package/lib/getTestRegistry.d.ts.map +1 -1
- package/lib/getTestRegistry.js +5 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -5
- package/src/components/Form.tsx +176 -43
- package/src/components/fields/ArrayField.tsx +849 -758
- package/src/components/fields/BooleanField.tsx +2 -2
- package/src/components/fields/FallbackField.tsx +157 -0
- package/src/components/fields/LayoutGridField.tsx +613 -600
- package/src/components/fields/LayoutMultiSchemaField.tsx +4 -5
- package/src/components/fields/MultiSchemaField.tsx +30 -25
- package/src/components/fields/ObjectField.tsx +315 -242
- package/src/components/fields/OptionalDataControlsField.tsx +1 -1
- package/src/components/fields/SchemaField.tsx +46 -70
- package/src/components/fields/StringField.tsx +2 -2
- package/src/components/fields/index.ts +2 -0
- package/src/components/templates/ArrayFieldItemButtonsTemplate.tsx +11 -16
- package/src/components/templates/ArrayFieldItemTemplate.tsx +3 -3
- package/src/components/templates/ArrayFieldTemplate.tsx +2 -13
- package/src/components/templates/BaseInputTemplate.tsx +2 -2
- package/src/components/templates/FallbackFieldTemplate.tsx +28 -0
- package/src/components/templates/ObjectFieldTemplate.tsx +2 -2
- package/src/components/templates/WrapIfAdditionalTemplate.tsx +4 -4
- package/src/components/templates/index.ts +2 -0
- package/src/components/widgets/AltDateWidget.tsx +8 -124
- package/src/components/widgets/CheckboxWidget.tsx +2 -1
- package/src/components/widgets/CheckboxesWidget.tsx +2 -1
- package/src/components/widgets/FileWidget.tsx +11 -102
- package/src/components/widgets/HiddenWidget.tsx +2 -1
- package/src/components/widgets/RadioWidget.tsx +2 -1
- package/src/components/widgets/RatingWidget.tsx +2 -1
- package/src/components/widgets/SelectWidget.tsx +2 -1
- package/src/components/widgets/TextareaWidget.tsx +2 -1
- package/src/getDefaultRegistry.ts +5 -1
- package/src/getTestRegistry.tsx +5 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LayoutMultiSchemaField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/LayoutMultiSchemaField.tsx"],"names":[],"mappings":"AACA,OAAO,EAIL,eAAe,EAEf,UAAU,EACV,eAAe,EAOf,UAAU,EAIV,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACT,MAAM,aAAa,CAAC;AAQrB;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,gBAAgB,GAAG,UAAU,EACvE,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,EAC7B,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,OAAO,GACb,CAAC,GAAG,SAAS,CAQf;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,gBAAgB,GAAG,UAAU,EAAE,CAAC,SAAS,eAAe,GAAG,GAAG,EAClH,MAAM,EAAE,CAAC,EACT,OAAO,EAAE,CAAC,EAAE,EACZ,WAAW,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EACrC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC5B,QAAQ,CAAC,EAAE,CAAC,GACX,eAAe,CAAC,CAAC,CAAC,EAAE,CAatB;AAED;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,CAAC,GAAG,GAAG,EACP,CAAC,SAAS,gBAAgB,GAAG,UAAU,EACvC,CAAC,SAAS,eAAe,GAAG,GAAG,EAC/B,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"LayoutMultiSchemaField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/LayoutMultiSchemaField.tsx"],"names":[],"mappings":"AACA,OAAO,EAIL,eAAe,EAEf,UAAU,EACV,eAAe,EAOf,UAAU,EAIV,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACT,MAAM,aAAa,CAAC;AAQrB;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,gBAAgB,GAAG,UAAU,EACvE,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,EAC7B,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,OAAO,GACb,CAAC,GAAG,SAAS,CAQf;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,gBAAgB,GAAG,UAAU,EAAE,CAAC,SAAS,eAAe,GAAG,GAAG,EAClH,MAAM,EAAE,CAAC,EACT,OAAO,EAAE,CAAC,EAAE,EACZ,WAAW,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EACrC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC5B,QAAQ,CAAC,EAAE,CAAC,GACX,eAAe,CAAC,CAAC,CAAC,EAAE,CAatB;AAED;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,CAAC,GAAG,GAAG,EACP,CAAC,SAAS,gBAAgB,GAAG,UAAU,EACvC,CAAC,SAAS,eAAe,GAAG,GAAG,EAC/B,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,2CAsI3B"}
|
|
@@ -55,7 +55,7 @@ export function computeEnumOptions(schema, options, schemaUtils, uiSchema, formD
|
|
|
55
55
|
* is active. If no `selectorField` is specified, then an error is thrown.
|
|
56
56
|
*/
|
|
57
57
|
export default function LayoutMultiSchemaField(props) {
|
|
58
|
-
const { name, baseType, disabled = false, formData, fieldPathId, onBlur, onChange, options, onFocus, registry, uiSchema, schema,
|
|
58
|
+
const { name, baseType, disabled = false, formData, fieldPathId, onBlur, onChange, options, onFocus, registry, uiSchema, schema, autofocus, readonly, required, errorSchema, hideError = false, } = props;
|
|
59
59
|
const { widgets, schemaUtils, globalUiOptions } = registry;
|
|
60
60
|
const [enumOptions, setEnumOptions] = useState(computeEnumOptions(schema, options, schemaUtils, uiSchema, formData));
|
|
61
61
|
const id = get(fieldPathId, ID_KEY);
|
|
@@ -110,6 +110,5 @@ export default function LayoutMultiSchemaField(props) {
|
|
|
110
110
|
// filtering the options based on the type of widget because `selectField` does not recognize the `convertOther` prop
|
|
111
111
|
const widgetOptions = { enumOptions, ...uiOptions };
|
|
112
112
|
const errors = !hideFieldError && rawErrors.length > 0 ? (_jsx(FieldErrorTemplate, { fieldPathId: fieldPathId, schema: schema, errors: rawErrors, registry: registry })) : undefined;
|
|
113
|
-
|
|
114
|
-
return (_jsx(FieldTemplate, { id: id, schema: schema, label: (title || schema.title) ?? '', disabled: disabled || (Array.isArray(enumOptions) && isEmpty(enumOptions)), uiSchema: uiSchema, required: required, readonly: !!readonly, registry: registry, displayLabel: displayLabel, errors: errors, onChange: onChange, onDropPropertyClick: ignored, onKeyChange: ignored, children: _jsx(Widget, { id: id, name: name, schema: schema, label: (title || schema.title) ?? '', disabled: disabled || (Array.isArray(enumOptions) && isEmpty(enumOptions)), uiSchema: uiSchema, formContext: formContext, autofocus: autofocus, readonly: readonly, required: required, registry: registry, multiple: false, rawErrors: rawErrors, hideError: hideFieldError, hideLabel: !displayLabel, errorSchema: fieldErrorSchema, placeholder: placeholder, onChange: onOptionChange, onBlur: onBlur, onFocus: onFocus, value: selectedOption, options: widgetOptions }) }));
|
|
113
|
+
return (_jsx(FieldTemplate, { id: id, schema: schema, label: (title || schema.title) ?? '', disabled: disabled || (Array.isArray(enumOptions) && isEmpty(enumOptions)), uiSchema: uiSchema, required: required, readonly: !!readonly, registry: registry, displayLabel: displayLabel, errors: errors, onChange: onChange, onKeyRename: noop, onKeyRenameBlur: noop, onRemoveProperty: noop, children: _jsx(Widget, { id: id, name: name, schema: schema, label: (title || schema.title) ?? '', disabled: disabled || (Array.isArray(enumOptions) && isEmpty(enumOptions)), uiSchema: uiSchema, autofocus: autofocus, readonly: readonly, required: required, registry: registry, multiple: false, rawErrors: rawErrors, hideError: hideFieldError, hideLabel: !displayLabel, errorSchema: fieldErrorSchema, placeholder: placeholder, onChange: onOptionChange, onBlur: onBlur, onFocus: onFocus, value: selectedOption, options: widgetOptions, htmlName: fieldPathId.name }) }));
|
|
115
114
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiSchemaField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/MultiSchemaField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIlC,OAAO,EAIL,UAAU,EACV,eAAe,
|
|
1
|
+
{"version":3,"file":"MultiSchemaField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/MultiSchemaField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIlC,OAAO,EAIL,UAAU,EACV,eAAe,EAQf,UAAU,EAEV,gBAAgB,EAGjB,MAAM,aAAa,CAAC;AAErB,4DAA4D;AAC5D,KAAK,eAAe,CAAC,CAAC,SAAS,gBAAgB,GAAG,UAAU,IAAI;IAC9D,oCAAoC;IACpC,cAAc,EAAE,MAAM,CAAC;IACvB,oDAAoD;IACpD,gBAAgB,EAAE,CAAC,EAAE,CAAC;CACvB,CAAC;AAEF;;;;GAIG;AACH,cAAM,UAAU,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,gBAAgB,GAAG,UAAU,EAAE,CAAC,SAAS,eAAe,GAAG,GAAG,CAAE,SAAQ,SAAS,CACnH,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EACnB,eAAe,CAAC,CAAC,CAAC,CACnB;IACC;;;OAGG;gBACS,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAiBtC;;;;;OAKG;IACH,kBAAkB,CAAC,SAAS,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,QAAQ,CAAC,eAAe,CAAC;IAyBjG;;;;;OAKG;IACH,iBAAiB,CAAC,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE;IAW/E;;;;;OAKG;IACH,cAAc,GAAI,SAAS,MAAM,UAqB/B;IAEF,UAAU;IAKV;OACG;IACH,MAAM;CA4HP;AAED,eAAe,UAAU,CAAC"}
|
|
@@ -3,7 +3,7 @@ import { Component } from 'react';
|
|
|
3
3
|
import get from 'lodash-es/get.js';
|
|
4
4
|
import isEmpty from 'lodash-es/isEmpty.js';
|
|
5
5
|
import omit from 'lodash-es/omit.js';
|
|
6
|
-
import { ANY_OF_KEY, deepEquals, ERRORS_KEY, getDiscriminatorFieldFromSchema, getTemplate, getUiOptions, getWidget, mergeSchemas, ONE_OF_KEY, TranslatableString, } from '@rjsf/utils';
|
|
6
|
+
import { ANY_OF_KEY, deepEquals, ERRORS_KEY, getDiscriminatorFieldFromSchema, getTemplate, getUiOptions, getWidget, isFormDataAvailable, mergeSchemas, ONE_OF_KEY, shouldRenderOptionalField, TranslatableString, } from '@rjsf/utils';
|
|
7
7
|
/** The `AnyOfField` component is used to render a field in the schema that is an `anyOf`, `allOf` or `oneOf`. It tracks
|
|
8
8
|
* the currently selected option and cleans up any irrelevant data in `formData`.
|
|
9
9
|
*
|
|
@@ -96,10 +96,12 @@ class AnyOfField extends Component {
|
|
|
96
96
|
/** Renders the `AnyOfField` selector along with a `SchemaField` for the value of the `formData`
|
|
97
97
|
*/
|
|
98
98
|
render() {
|
|
99
|
-
const { name, disabled = false, errorSchema = {},
|
|
99
|
+
const { name, disabled = false, errorSchema = {}, formData, onBlur, onFocus, readonly, required = false, registry, schema, uiSchema, } = this.props;
|
|
100
100
|
const { widgets, fields, translateString, globalUiOptions, schemaUtils } = registry;
|
|
101
101
|
const { SchemaField: _SchemaField } = fields;
|
|
102
102
|
const MultiSchemaFieldTemplate = getTemplate('MultiSchemaFieldTemplate', registry, globalUiOptions);
|
|
103
|
+
const isOptionalRender = shouldRenderOptionalField(registry, schema, required, uiSchema);
|
|
104
|
+
const hasFormData = isFormDataAvailable(formData);
|
|
103
105
|
const { selectedOption, retrievedOptions } = this.state;
|
|
104
106
|
const { widget = 'select', placeholder, autofocus, autocomplete, title = schema.title, ...uiOptions } = getUiOptions(uiSchema, globalUiOptions);
|
|
105
107
|
const Widget = getWidget({ type: 'number' }, widget, widgets);
|
|
@@ -149,7 +151,7 @@ class AnyOfField extends Component {
|
|
|
149
151
|
value: index,
|
|
150
152
|
};
|
|
151
153
|
});
|
|
152
|
-
const selector = (_jsx(Widget, { id: this.getFieldId(), name: `${name}${schema.oneOf ? '__oneof_select' : '__anyof_select'}`, schema: { type: 'number', default: 0 }, onChange: this.onOptionChange, onBlur: onBlur, onFocus: onFocus, disabled: disabled || isEmpty(enumOptions), multiple: false, rawErrors: rawErrors, errorSchema: fieldErrorSchema, value: selectedOption >= 0 ? selectedOption : undefined, options: { enumOptions, ...uiOptions }, registry: registry,
|
|
154
|
+
const selector = !isOptionalRender || hasFormData ? (_jsx(Widget, { id: this.getFieldId(), name: `${name}${schema.oneOf ? '__oneof_select' : '__anyof_select'}`, schema: { type: 'number', default: 0 }, onChange: this.onOptionChange, onBlur: onBlur, onFocus: onFocus, disabled: disabled || isEmpty(enumOptions), multiple: false, rawErrors: rawErrors, errorSchema: fieldErrorSchema, value: selectedOption >= 0 ? selectedOption : undefined, options: { enumOptions, ...uiOptions }, registry: registry, placeholder: placeholder, autocomplete: autocomplete, autofocus: autofocus, label: title ?? name, hideLabel: !displayLabel, readonly: readonly })) : undefined;
|
|
153
155
|
const optionsSchemaField = (optionSchema && optionSchema.type !== 'null' && (_jsx(_SchemaField, { ...this.props, schema: optionSchema, uiSchema: optionUiSchema }))) ||
|
|
154
156
|
null;
|
|
155
157
|
return (_jsx(MultiSchemaFieldTemplate, { schema: schema, registry: registry, uiSchema: uiSchema, selector: selector, optionSchemaField: optionsSchemaField }));
|
|
@@ -1,74 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ErrorSchema, FieldPathList, FieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
3
|
-
/** Type used for the state of the `ObjectField` component */
|
|
4
|
-
type ObjectFieldState = {
|
|
5
|
-
/** Flag indicating whether an additional property key was modified */
|
|
6
|
-
wasPropertyKeyModified: boolean;
|
|
7
|
-
/** The set of additional properties */
|
|
8
|
-
additionalProperties: object;
|
|
9
|
-
};
|
|
1
|
+
import { FieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
10
2
|
/** The `ObjectField` component is used to render a field in the schema that is of type `object`. It tracks whether an
|
|
11
3
|
* additional property key was modified and what it was modified to
|
|
12
4
|
*
|
|
13
5
|
* @param props - The `FieldProps` for this template
|
|
14
6
|
*/
|
|
15
|
-
|
|
16
|
-
/** Set up the initial state */
|
|
17
|
-
state: {
|
|
18
|
-
wasPropertyKeyModified: boolean;
|
|
19
|
-
additionalProperties: {};
|
|
20
|
-
};
|
|
21
|
-
/** Returns a flag indicating whether the `name` field is required in the object schema
|
|
22
|
-
*
|
|
23
|
-
* @param name - The name of the field to check for required-ness
|
|
24
|
-
* @returns - True if the field `name` is required, false otherwise
|
|
25
|
-
*/
|
|
26
|
-
isRequired(name: string): boolean;
|
|
27
|
-
/** Returns the `onPropertyChange` handler for the `name` field. Handles the special case where a user is attempting
|
|
28
|
-
* to clear the data for a field added as an additional property. Calls the `onChange()` handler with the updated
|
|
29
|
-
* formData.
|
|
30
|
-
*
|
|
31
|
-
* @param name - The name of the property
|
|
32
|
-
* @param addedByAdditionalProperties - Flag indicating whether this property is an additional property
|
|
33
|
-
* @returns - The onPropertyChange callback for the `name` property
|
|
34
|
-
*/
|
|
35
|
-
onPropertyChange: (name: string, addedByAdditionalProperties?: boolean) => (value: T | undefined, path: FieldPathList, newErrorSchema?: ErrorSchema<T>, id?: string) => void;
|
|
36
|
-
/** Returns a callback to handle the onDropPropertyClick event for the given `key` which removes the old `key` data
|
|
37
|
-
* and calls the `onChange` callback with it
|
|
38
|
-
*
|
|
39
|
-
* @param key - The key for which the drop callback is desired
|
|
40
|
-
* @returns - The drop property click callback
|
|
41
|
-
*/
|
|
42
|
-
onDropPropertyClick: (key: string) => (event: DragEvent) => void;
|
|
43
|
-
/** Computes the next available key name from the `preferredKey`, indexing through the already existing keys until one
|
|
44
|
-
* that is already not assigned is found.
|
|
45
|
-
*
|
|
46
|
-
* @param preferredKey - The preferred name of a new key
|
|
47
|
-
* @param [formData] - The form data in which to check if the desired key already exists
|
|
48
|
-
* @returns - The name of the next available key from `preferredKey`
|
|
49
|
-
*/
|
|
50
|
-
getAvailableKey: (preferredKey: string, formData?: T) => string;
|
|
51
|
-
/** Returns a callback function that deals with the rename of a key for an additional property for a schema. That
|
|
52
|
-
* callback will attempt to rename the key and move the existing data to that key, calling `onChange` when it does.
|
|
53
|
-
*
|
|
54
|
-
* @param oldValue - The old value of a field
|
|
55
|
-
* @returns - The key change callback function
|
|
56
|
-
*/
|
|
57
|
-
onKeyChange: (oldValue: any) => (value: any) => void;
|
|
58
|
-
/** Returns a default value to be used for a new additional schema property of the given `type`
|
|
59
|
-
*
|
|
60
|
-
* @param type - The type of the new additional schema property
|
|
61
|
-
*/
|
|
62
|
-
getDefaultValue(type?: RJSFSchema['type']): {} | null;
|
|
63
|
-
/** Handles the adding of a new additional property on the given `schema`. Calls the `onChange` callback once the new
|
|
64
|
-
* default data for that field has been added to the formData.
|
|
65
|
-
*
|
|
66
|
-
* @param schema - The schema element to which the new property is being added
|
|
67
|
-
*/
|
|
68
|
-
handleAddClick: (schema: S) => () => void;
|
|
69
|
-
/** Renders the `ObjectField` from the given props
|
|
70
|
-
*/
|
|
71
|
-
render(): import("react/jsx-runtime").JSX.Element;
|
|
72
|
-
}
|
|
73
|
-
export default ObjectField;
|
|
7
|
+
export default function ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(props: FieldProps<T, S, F>): import("react/jsx-runtime").JSX.Element;
|
|
74
8
|
//# sourceMappingURL=ObjectField.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/ObjectField.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ObjectField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/ObjectField.tsx"],"names":[],"mappings":"AACA,OAAO,EAcL,UAAU,EACV,eAAe,EAMf,UAAU,EACV,gBAAgB,EAEjB,MAAM,aAAa,CAAC;AAuKrB;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,gBAAgB,GAAG,UAAU,EAAE,CAAC,SAAS,eAAe,GAAG,GAAG,EACnH,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,2CAmN3B"}
|
|
@@ -1,32 +1,52 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import { getTemplate, getUiOptions, orderProperties, shouldRenderOptionalField, toFieldPathId,
|
|
2
|
+
import { useCallback, useState } from 'react';
|
|
3
|
+
import { ADDITIONAL_PROPERTY_FLAG, ANY_OF_KEY, getTemplate, getUiOptions, hashObject, isFormDataAvailable, orderProperties, shouldRenderOptionalField, toFieldPathId, useDeepCompareMemo, ONE_OF_KEY, PROPERTIES_KEY, REF_KEY, TranslatableString, } from '@rjsf/utils';
|
|
4
4
|
import Markdown from 'markdown-to-jsx';
|
|
5
5
|
import get from 'lodash-es/get.js';
|
|
6
6
|
import has from 'lodash-es/has.js';
|
|
7
7
|
import isObject from 'lodash-es/isObject.js';
|
|
8
8
|
import set from 'lodash-es/set.js';
|
|
9
9
|
import unset from 'lodash-es/unset.js';
|
|
10
|
-
/**
|
|
11
|
-
* additional property key was modified and what it was modified to
|
|
10
|
+
/** Returns a flag indicating whether the `name` field is required in the object schema
|
|
12
11
|
*
|
|
13
|
-
* @param
|
|
12
|
+
* @param schema - The schema to check
|
|
13
|
+
* @param name - The name of the field to check for required-ness
|
|
14
|
+
* @returns - True if the field `name` is required, false otherwise
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
16
|
+
function isRequired(schema, name) {
|
|
17
|
+
return Array.isArray(schema.required) && schema.required.indexOf(name) !== -1;
|
|
18
|
+
}
|
|
19
|
+
/** Returns a default value to be used for a new additional schema property of the given `type`
|
|
20
|
+
*
|
|
21
|
+
* @param translateString - The string translation function from the registry
|
|
22
|
+
* @param type - The type of the new additional schema property
|
|
23
|
+
*/
|
|
24
|
+
function getDefaultValue(translateString, type) {
|
|
25
|
+
switch (type) {
|
|
26
|
+
case 'array':
|
|
27
|
+
return [];
|
|
28
|
+
case 'boolean':
|
|
29
|
+
return false;
|
|
30
|
+
case 'null':
|
|
31
|
+
return null;
|
|
32
|
+
case 'number':
|
|
33
|
+
return 0;
|
|
34
|
+
case 'object':
|
|
35
|
+
return {};
|
|
36
|
+
case 'string':
|
|
37
|
+
default:
|
|
38
|
+
// We don't have a datatype for some reason (perhaps additionalProperties was true)
|
|
39
|
+
return translateString(TranslatableString.NewStringDefault);
|
|
29
40
|
}
|
|
41
|
+
}
|
|
42
|
+
/** The `ObjectFieldProperty` component is used to render the `SchemaField` for a child property of an object
|
|
43
|
+
*/
|
|
44
|
+
function ObjectFieldProperty(props) {
|
|
45
|
+
const { fieldPathId, schema, registry, uiSchema, errorSchema, formData, onChange, onBlur, onFocus, disabled, readonly, required, hideError, propertyName, handleKeyRename, handleRemoveProperty, addedByAdditionalProperties, } = props;
|
|
46
|
+
const [wasPropertyKeyModified, setWasPropertyKeyModified] = useState(false);
|
|
47
|
+
const { globalFormOptions, fields } = registry;
|
|
48
|
+
const { SchemaField } = fields;
|
|
49
|
+
const innerFieldIdPathId = useDeepCompareMemo(toFieldPathId(propertyName, globalFormOptions, fieldPathId.path));
|
|
30
50
|
/** Returns the `onPropertyChange` handler for the `name` field. Handles the special case where a user is attempting
|
|
31
51
|
* to clear the data for a field added as an additional property. Calls the `onChange()` handler with the updated
|
|
32
52
|
* formData.
|
|
@@ -35,38 +55,57 @@ class ObjectField extends Component {
|
|
|
35
55
|
* @param addedByAdditionalProperties - Flag indicating whether this property is an additional property
|
|
36
56
|
* @returns - The onPropertyChange callback for the `name` property
|
|
37
57
|
*/
|
|
38
|
-
onPropertyChange = (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
onChange(value, path, newErrorSchema, id);
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
/** Returns a callback to handle the onDropPropertyClick event for the given `key` which removes the old `key` data
|
|
55
|
-
* and calls the `onChange` callback with it
|
|
56
|
-
*
|
|
57
|
-
* @param key - The key for which the drop callback is desired
|
|
58
|
-
* @returns - The drop property click callback
|
|
58
|
+
const onPropertyChange = useCallback((value, path, newErrorSchema, id) => {
|
|
59
|
+
if (value === undefined && addedByAdditionalProperties) {
|
|
60
|
+
// Don't set value = undefined for fields added by additionalProperties. Doing so removes them from the
|
|
61
|
+
// formData, which causes them to completely disappear (including the input field for the property name). Unlike
|
|
62
|
+
// fields which are "mandated" by the schema, these fields can be set to undefined by clicking a "delete field"
|
|
63
|
+
// button, so set empty values to the empty string.
|
|
64
|
+
value = '';
|
|
65
|
+
}
|
|
66
|
+
onChange(value, path, newErrorSchema, id);
|
|
67
|
+
}, [onChange, addedByAdditionalProperties]);
|
|
68
|
+
/** The key change event handler; Called when the key associated with a field is changed for an additionalProperty.
|
|
69
|
+
* simply returns a function that call the `handleKeyChange()` event with the value
|
|
59
70
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
const onKeyRename = useCallback((value) => {
|
|
72
|
+
if (propertyName !== value) {
|
|
73
|
+
setWasPropertyKeyModified(true);
|
|
74
|
+
}
|
|
75
|
+
handleKeyRename(propertyName, value);
|
|
76
|
+
}, [propertyName, handleKeyRename]);
|
|
77
|
+
/** Returns a callback the handle the blur event, getting the value from the target and passing that along to the
|
|
78
|
+
* `handleKeyChange` function
|
|
79
|
+
*/
|
|
80
|
+
const onKeyRenameBlur = useCallback((event) => {
|
|
81
|
+
const { target: { value }, } = event;
|
|
82
|
+
onKeyRename(value);
|
|
83
|
+
}, [onKeyRename]);
|
|
84
|
+
/** The property drop/removal event handler; Called when a field is removed in an additionalProperty context
|
|
85
|
+
*/
|
|
86
|
+
const onRemoveProperty = useCallback(() => {
|
|
87
|
+
handleRemoveProperty(propertyName);
|
|
88
|
+
}, [propertyName, handleRemoveProperty]);
|
|
89
|
+
return (_jsx(SchemaField, { name: propertyName, required: required, schema: schema, uiSchema: uiSchema, errorSchema: errorSchema, fieldPathId: innerFieldIdPathId, formData: formData, wasPropertyKeyModified: wasPropertyKeyModified, onKeyRename: onKeyRename, onKeyRenameBlur: onKeyRenameBlur, onRemoveProperty: onRemoveProperty, onChange: onPropertyChange, onBlur: onBlur, onFocus: onFocus, registry: registry, disabled: disabled, readonly: readonly, hideError: hideError }));
|
|
90
|
+
}
|
|
91
|
+
/** The `ObjectField` component is used to render a field in the schema that is of type `object`. It tracks whether an
|
|
92
|
+
* additional property key was modified and what it was modified to
|
|
93
|
+
*
|
|
94
|
+
* @param props - The `FieldProps` for this template
|
|
95
|
+
*/
|
|
96
|
+
export default function ObjectField(props) {
|
|
97
|
+
const { schema: rawSchema, uiSchema = {}, formData, errorSchema, fieldPathId, name, required = false, disabled, readonly, hideError, onBlur, onFocus, onChange, registry, title, } = props;
|
|
98
|
+
const { fields, schemaUtils, translateString, globalUiOptions } = registry;
|
|
99
|
+
const { OptionalDataControlsField } = fields;
|
|
100
|
+
const schema = schemaUtils.retrieveSchema(rawSchema, formData, true);
|
|
101
|
+
const uiOptions = getUiOptions(uiSchema, globalUiOptions);
|
|
102
|
+
const { properties: schemaProperties = {} } = schema;
|
|
103
|
+
const formDataHash = hashObject(formData || {});
|
|
104
|
+
const templateTitle = uiOptions.title ?? schema.title ?? title ?? name;
|
|
105
|
+
const description = uiOptions.description ?? schema.description;
|
|
106
|
+
const renderOptionalField = shouldRenderOptionalField(registry, schema, required, uiSchema);
|
|
107
|
+
const hasFormData = isFormDataAvailable(formData);
|
|
108
|
+
let orderedProperties = [];
|
|
70
109
|
/** Computes the next available key name from the `preferredKey`, indexing through the already existing keys until one
|
|
71
110
|
* that is already not assigned is found.
|
|
72
111
|
*
|
|
@@ -74,77 +113,25 @@ class ObjectField extends Component {
|
|
|
74
113
|
* @param [formData] - The form data in which to check if the desired key already exists
|
|
75
114
|
* @returns - The name of the next available key from `preferredKey`
|
|
76
115
|
*/
|
|
77
|
-
getAvailableKey = (preferredKey, formData) => {
|
|
78
|
-
const {
|
|
79
|
-
const { duplicateKeySuffixSeparator = '-' } = getUiOptions(uiSchema, registry.globalUiOptions);
|
|
116
|
+
const getAvailableKey = useCallback((preferredKey, formData) => {
|
|
117
|
+
const { duplicateKeySuffixSeparator = '-' } = getUiOptions(uiSchema, globalUiOptions);
|
|
80
118
|
let index = 0;
|
|
81
119
|
let newKey = preferredKey;
|
|
82
120
|
while (has(formData, newKey)) {
|
|
83
121
|
newKey = `${preferredKey}${duplicateKeySuffixSeparator}${++index}`;
|
|
84
122
|
}
|
|
85
123
|
return newKey;
|
|
86
|
-
};
|
|
87
|
-
/** Returns a callback function that deals with the rename of a key for an additional property for a schema. That
|
|
88
|
-
* callback will attempt to rename the key and move the existing data to that key, calling `onChange` when it does.
|
|
89
|
-
*
|
|
90
|
-
* @param oldValue - The old value of a field
|
|
91
|
-
* @returns - The key change callback function
|
|
92
|
-
*/
|
|
93
|
-
onKeyChange = (oldValue) => {
|
|
94
|
-
return (value) => {
|
|
95
|
-
if (oldValue === value) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
const { formData, onChange, fieldPathId } = this.props;
|
|
99
|
-
value = this.getAvailableKey(value, formData);
|
|
100
|
-
const newFormData = {
|
|
101
|
-
...formData,
|
|
102
|
-
};
|
|
103
|
-
const newKeys = { [oldValue]: value };
|
|
104
|
-
const keyValues = Object.keys(newFormData).map((key) => {
|
|
105
|
-
const newKey = newKeys[key] || key;
|
|
106
|
-
return { [newKey]: newFormData[key] };
|
|
107
|
-
});
|
|
108
|
-
const renamedObj = Object.assign({}, ...keyValues);
|
|
109
|
-
this.setState({ wasPropertyKeyModified: true });
|
|
110
|
-
onChange(renamedObj, fieldPathId.path);
|
|
111
|
-
};
|
|
112
|
-
};
|
|
113
|
-
/** Returns a default value to be used for a new additional schema property of the given `type`
|
|
114
|
-
*
|
|
115
|
-
* @param type - The type of the new additional schema property
|
|
116
|
-
*/
|
|
117
|
-
getDefaultValue(type) {
|
|
118
|
-
const { registry: { translateString }, } = this.props;
|
|
119
|
-
switch (type) {
|
|
120
|
-
case 'array':
|
|
121
|
-
return [];
|
|
122
|
-
case 'boolean':
|
|
123
|
-
return false;
|
|
124
|
-
case 'null':
|
|
125
|
-
return null;
|
|
126
|
-
case 'number':
|
|
127
|
-
return 0;
|
|
128
|
-
case 'object':
|
|
129
|
-
return {};
|
|
130
|
-
case 'string':
|
|
131
|
-
default:
|
|
132
|
-
// We don't have a datatype for some reason (perhaps additionalProperties was true)
|
|
133
|
-
return translateString(TranslatableString.NewStringDefault);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
124
|
+
}, [uiSchema, globalUiOptions]);
|
|
136
125
|
/** Handles the adding of a new additional property on the given `schema`. Calls the `onChange` callback once the new
|
|
137
126
|
* default data for that field has been added to the formData.
|
|
138
|
-
*
|
|
139
|
-
* @param schema - The schema element to which the new property is being added
|
|
140
127
|
*/
|
|
141
|
-
|
|
128
|
+
const onAddProperty = useCallback(() => {
|
|
142
129
|
if (!(schema.additionalProperties || schema.patternProperties)) {
|
|
143
130
|
return;
|
|
144
131
|
}
|
|
145
|
-
const {
|
|
132
|
+
const { translateString } = registry;
|
|
146
133
|
const newFormData = { ...formData };
|
|
147
|
-
const newKey =
|
|
134
|
+
const newKey = getAvailableKey('newKey', newFormData);
|
|
148
135
|
if (schema.patternProperties) {
|
|
149
136
|
// Cast this to make the `set` work properly
|
|
150
137
|
set(newFormData, newKey, null);
|
|
@@ -160,7 +147,7 @@ class ObjectField extends Component {
|
|
|
160
147
|
let apSchema = schema.additionalProperties;
|
|
161
148
|
if (REF_KEY in apSchema) {
|
|
162
149
|
const { schemaUtils } = registry;
|
|
163
|
-
apSchema = schemaUtils.retrieveSchema({
|
|
150
|
+
apSchema = schemaUtils.retrieveSchema({ [REF_KEY]: apSchema[REF_KEY] }, formData);
|
|
164
151
|
type = apSchema.type;
|
|
165
152
|
constValue = apSchema.const;
|
|
166
153
|
defaultValue = apSchema.default;
|
|
@@ -169,70 +156,81 @@ class ObjectField extends Component {
|
|
|
169
156
|
type = 'object';
|
|
170
157
|
}
|
|
171
158
|
}
|
|
172
|
-
const newValue = constValue ?? defaultValue ??
|
|
159
|
+
const newValue = constValue ?? defaultValue ?? getDefaultValue(translateString, type);
|
|
173
160
|
// Cast this to make the `set` work properly
|
|
174
161
|
set(newFormData, newKey, newValue);
|
|
175
162
|
}
|
|
176
|
-
// add will pass the name in `path` array
|
|
177
163
|
onChange(newFormData, fieldPathId.path);
|
|
178
|
-
};
|
|
179
|
-
/**
|
|
164
|
+
}, [formData, onChange, registry, fieldPathId, getAvailableKey, schema]);
|
|
165
|
+
/** Returns a callback function that deals with the rename of a key for an additional property for a schema. That
|
|
166
|
+
* callback will attempt to rename the key and move the existing data to that key, calling `onChange` when it does.
|
|
167
|
+
*
|
|
168
|
+
* @param oldKey - The old key for the field
|
|
169
|
+
* @param newKey - The new key for the field
|
|
170
|
+
* @returns - The key change callback function
|
|
180
171
|
*/
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
172
|
+
const handleKeyRename = useCallback((oldKey, newKey) => {
|
|
173
|
+
if (oldKey !== newKey) {
|
|
174
|
+
const actualNewKey = getAvailableKey(newKey, formData);
|
|
175
|
+
const newFormData = {
|
|
176
|
+
...formData,
|
|
177
|
+
};
|
|
178
|
+
const newKeys = { [oldKey]: actualNewKey };
|
|
179
|
+
const keyValues = Object.keys(newFormData).map((key) => {
|
|
180
|
+
const newKey = newKeys[key] || key;
|
|
181
|
+
return { [newKey]: newFormData[key] };
|
|
182
|
+
});
|
|
183
|
+
const renamedObj = Object.assign({}, ...keyValues);
|
|
184
|
+
onChange(renamedObj, fieldPathId.path);
|
|
185
|
+
}
|
|
186
|
+
}, [formData, onChange, fieldPathId, getAvailableKey]);
|
|
187
|
+
/** Handles the remove click which removes the old `key` data and calls the `onChange` callback with it
|
|
188
|
+
*/
|
|
189
|
+
const handleRemoveProperty = useCallback((key) => {
|
|
190
|
+
const copiedFormData = { ...formData };
|
|
191
|
+
unset(copiedFormData, key);
|
|
192
|
+
onChange(copiedFormData, fieldPathId.path);
|
|
193
|
+
}, [onChange, fieldPathId, formData]);
|
|
194
|
+
if (!renderOptionalField || hasFormData) {
|
|
195
|
+
try {
|
|
196
|
+
const properties = Object.keys(schemaProperties);
|
|
197
|
+
orderedProperties = orderProperties(properties, uiOptions.order);
|
|
198
|
+
}
|
|
199
|
+
catch (err) {
|
|
200
|
+
return (_jsxs("div", { children: [_jsx("p", { className: 'rjsf-config-error', style: { color: 'red' }, children: _jsx(Markdown, { options: { disableParsingRawHTML: true }, children: translateString(TranslatableString.InvalidObjectField, [name || 'root', err.message]) }) }), _jsx("pre", { children: JSON.stringify(schema) })] }));
|
|
201
201
|
}
|
|
202
|
-
const Template = getTemplate('ObjectFieldTemplate', registry, uiOptions);
|
|
203
|
-
const optionalDataControl = renderOptionalField ? (_jsx(OptionalDataControlsField, { ...this.props, schema: schema })) : undefined;
|
|
204
|
-
const templateProps = {
|
|
205
|
-
// getDisplayLabel() always returns false for object types, so just check the `uiOptions.label`
|
|
206
|
-
title: uiOptions.label === false ? '' : templateTitle,
|
|
207
|
-
description: uiOptions.label === false ? undefined : description,
|
|
208
|
-
properties: orderedProperties.map((name) => {
|
|
209
|
-
const addedByAdditionalProperties = has(schema, [PROPERTIES_KEY, name, ADDITIONAL_PROPERTY_FLAG]);
|
|
210
|
-
const fieldUiSchema = addedByAdditionalProperties ? uiSchema.additionalProperties : uiSchema[name];
|
|
211
|
-
const hidden = getUiOptions(fieldUiSchema).widget === 'hidden';
|
|
212
|
-
const innerFieldIdPathId = toFieldPathId(name, globalFormOptions, fieldPathId);
|
|
213
|
-
return {
|
|
214
|
-
content: (_jsx(SchemaField, { name: name, required: this.isRequired(name), schema: get(schema, [PROPERTIES_KEY, name], {}), uiSchema: fieldUiSchema, errorSchema: get(errorSchema, name), fieldPathId: innerFieldIdPathId, formData: get(formData, name), formContext: formContext, wasPropertyKeyModified: this.state.wasPropertyKeyModified, onKeyChange: this.onKeyChange(name), onChange: this.onPropertyChange(name, addedByAdditionalProperties), onBlur: onBlur, onFocus: onFocus, registry: registry, disabled: disabled, readonly: readonly, hideError: hideError, onDropPropertyClick: this.onDropPropertyClick }, name)),
|
|
215
|
-
name,
|
|
216
|
-
readonly,
|
|
217
|
-
disabled,
|
|
218
|
-
required,
|
|
219
|
-
hidden,
|
|
220
|
-
};
|
|
221
|
-
}),
|
|
222
|
-
readonly,
|
|
223
|
-
disabled,
|
|
224
|
-
required,
|
|
225
|
-
fieldPathId,
|
|
226
|
-
uiSchema,
|
|
227
|
-
errorSchema,
|
|
228
|
-
schema,
|
|
229
|
-
formData,
|
|
230
|
-
formContext,
|
|
231
|
-
registry,
|
|
232
|
-
optionalDataControl,
|
|
233
|
-
className: renderOptionalField ? 'rjsf-optional-object-field' : undefined,
|
|
234
|
-
};
|
|
235
|
-
return _jsx(Template, { ...templateProps, onAddClick: this.handleAddClick });
|
|
236
202
|
}
|
|
203
|
+
const Template = getTemplate('ObjectFieldTemplate', registry, uiOptions);
|
|
204
|
+
const optionalDataControl = renderOptionalField ? (_jsx(OptionalDataControlsField, { ...props, schema: schema })) : undefined;
|
|
205
|
+
const templateProps = {
|
|
206
|
+
// getDisplayLabel() always returns false for object types, so just check the `uiOptions.label`
|
|
207
|
+
title: uiOptions.label === false ? '' : templateTitle,
|
|
208
|
+
description: uiOptions.label === false ? undefined : description,
|
|
209
|
+
properties: orderedProperties.map((name) => {
|
|
210
|
+
const addedByAdditionalProperties = has(schema, [PROPERTIES_KEY, name, ADDITIONAL_PROPERTY_FLAG]);
|
|
211
|
+
const fieldUiSchema = addedByAdditionalProperties ? uiSchema.additionalProperties : uiSchema[name];
|
|
212
|
+
const hidden = getUiOptions(fieldUiSchema).widget === 'hidden';
|
|
213
|
+
const content = (_jsx(ObjectFieldProperty, { propertyName: name, required: isRequired(schema, name), schema: get(schema, [PROPERTIES_KEY, name], {}), uiSchema: fieldUiSchema, errorSchema: get(errorSchema, name), fieldPathId: fieldPathId, formData: get(formData, name), handleKeyRename: handleKeyRename, handleRemoveProperty: handleRemoveProperty, addedByAdditionalProperties: addedByAdditionalProperties, onChange: onChange, onBlur: onBlur, onFocus: onFocus, registry: registry, disabled: disabled, readonly: readonly, hideError: hideError }, addedByAdditionalProperties ? `${name}-${formDataHash}` : name));
|
|
214
|
+
return {
|
|
215
|
+
content,
|
|
216
|
+
name,
|
|
217
|
+
readonly,
|
|
218
|
+
disabled,
|
|
219
|
+
required,
|
|
220
|
+
hidden,
|
|
221
|
+
};
|
|
222
|
+
}),
|
|
223
|
+
readonly,
|
|
224
|
+
disabled,
|
|
225
|
+
required,
|
|
226
|
+
fieldPathId,
|
|
227
|
+
uiSchema,
|
|
228
|
+
errorSchema,
|
|
229
|
+
schema,
|
|
230
|
+
formData,
|
|
231
|
+
registry,
|
|
232
|
+
optionalDataControl,
|
|
233
|
+
className: renderOptionalField ? 'rjsf-optional-object-field' : undefined,
|
|
234
|
+
};
|
|
235
|
+
return _jsx(Template, { ...templateProps, onAddProperty: onAddProperty });
|
|
237
236
|
}
|
|
238
|
-
export default ObjectField;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/SchemaField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAe,SAAS,EAAiB,MAAM,OAAO,CAAC;AAC9D,OAAO,
|
|
1
|
+
{"version":3,"file":"SchemaField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/SchemaField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAe,SAAS,EAAiB,MAAM,OAAO,CAAC;AAC9D,OAAO,EAOL,UAAU,EAEV,eAAe,EAQf,UAAU,EAGV,gBAAgB,EAGjB,MAAM,aAAa,CAAC;AAuRrB;;GAEG;AACH,cAAM,WAAW,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,gBAAgB,GAAG,UAAU,EAAE,CAAC,SAAS,eAAe,GAAG,GAAG,CAAE,SAAQ,SAAS,CACpH,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CACpB;IACC,qBAAqB,CAAC,SAAS,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAS9D,MAAM;CAGP;AAED,eAAe,WAAW,CAAC"}
|