@rjsf/core 6.6.1 → 6.7.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/LICENSE.md +201 -0
- package/dist/core.umd.js +694 -584
- package/dist/index.cjs +1191 -1071
- package/dist/index.cjs.map +4 -4
- package/dist/index.esm.js +1030 -984
- package/dist/index.esm.js.map +4 -4
- package/lib/components/Form.d.ts +16 -13
- package/lib/components/Form.d.ts.map +1 -1
- package/lib/components/Form.js +126 -76
- package/lib/components/RichDescription.d.ts +3 -3
- package/lib/components/RichDescription.d.ts.map +1 -1
- package/lib/components/RichDescription.js +1 -1
- package/lib/components/RichHelp.d.ts +3 -3
- package/lib/components/RichHelp.d.ts.map +1 -1
- package/lib/components/RichHelp.js +1 -1
- package/lib/components/SchemaExamples.d.ts +2 -2
- package/lib/components/SchemaExamples.d.ts.map +1 -1
- package/lib/components/SchemaExamples.js +1 -3
- package/lib/components/fields/ArrayField.d.ts +2 -2
- package/lib/components/fields/ArrayField.d.ts.map +1 -1
- package/lib/components/fields/ArrayField.js +87 -88
- package/lib/components/fields/BooleanField.d.ts +2 -2
- package/lib/components/fields/BooleanField.d.ts.map +1 -1
- package/lib/components/fields/BooleanField.js +2 -5
- package/lib/components/fields/CyclicSchemaField.d.ts +8 -0
- package/lib/components/fields/CyclicSchemaField.d.ts.map +1 -0
- package/lib/components/fields/CyclicSchemaField.js +21 -0
- package/lib/components/fields/FallbackField.d.ts +2 -2
- package/lib/components/fields/FallbackField.d.ts.map +1 -1
- package/lib/components/fields/FallbackField.js +2 -2
- package/lib/components/fields/LayoutGridField.d.ts +8 -10
- package/lib/components/fields/LayoutGridField.d.ts.map +1 -1
- package/lib/components/fields/LayoutGridField.js +5 -4
- package/lib/components/fields/LayoutHeaderField.d.ts +2 -2
- package/lib/components/fields/LayoutHeaderField.d.ts.map +1 -1
- package/lib/components/fields/LayoutHeaderField.js +1 -1
- package/lib/components/fields/LayoutMultiSchemaField.d.ts +2 -2
- package/lib/components/fields/LayoutMultiSchemaField.d.ts.map +1 -1
- package/lib/components/fields/LayoutMultiSchemaField.js +4 -1
- package/lib/components/fields/MultiSchemaField.d.ts +2 -41
- package/lib/components/fields/MultiSchemaField.d.ts.map +1 -1
- package/lib/components/fields/MultiSchemaField.js +116 -122
- package/lib/components/fields/NullField.d.ts +1 -1
- package/lib/components/fields/NullField.d.ts.map +1 -1
- package/lib/components/fields/NumberField.d.ts +2 -2
- package/lib/components/fields/NumberField.d.ts.map +1 -1
- package/lib/components/fields/NumberField.js +7 -9
- package/lib/components/fields/ObjectField.d.ts +2 -2
- package/lib/components/fields/ObjectField.d.ts.map +1 -1
- package/lib/components/fields/ObjectField.js +28 -26
- package/lib/components/fields/OptionalDataControlsField.d.ts +2 -2
- package/lib/components/fields/OptionalDataControlsField.d.ts.map +1 -1
- package/lib/components/fields/SchemaField.d.ts +14 -8
- package/lib/components/fields/SchemaField.d.ts.map +1 -1
- package/lib/components/fields/SchemaField.js +43 -30
- package/lib/components/fields/StringField.d.ts +2 -2
- package/lib/components/fields/StringField.d.ts.map +1 -1
- package/lib/components/fields/StringField.js +2 -5
- package/lib/components/fields/index.d.ts +1 -1
- package/lib/components/fields/index.d.ts.map +1 -1
- package/lib/components/fields/index.js +2 -0
- package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts +2 -2
- package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldDescriptionTemplate.js +1 -1
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts +2 -2
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.js +1 -1
- package/lib/components/templates/ArrayFieldItemTemplate.d.ts +2 -2
- 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 +2 -2
- package/lib/components/templates/ArrayFieldTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldTemplate.js +1 -1
- package/lib/components/templates/ArrayFieldTitleTemplate.d.ts +2 -2
- package/lib/components/templates/ArrayFieldTitleTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldTitleTemplate.js +1 -1
- package/lib/components/templates/BaseInputTemplate.d.ts +2 -2
- package/lib/components/templates/BaseInputTemplate.d.ts.map +1 -1
- package/lib/components/templates/BaseInputTemplate.js +7 -6
- package/lib/components/templates/ButtonTemplates/AddButton.d.ts +2 -2
- package/lib/components/templates/ButtonTemplates/AddButton.d.ts.map +1 -1
- package/lib/components/templates/ButtonTemplates/IconButton.d.ts +14 -7
- package/lib/components/templates/ButtonTemplates/IconButton.d.ts.map +1 -1
- package/lib/components/templates/ButtonTemplates/IconButton.js +14 -6
- package/lib/components/templates/ButtonTemplates/SubmitButton.d.ts +2 -2
- package/lib/components/templates/ButtonTemplates/SubmitButton.d.ts.map +1 -1
- package/lib/components/templates/ButtonTemplates/index.d.ts +1 -1
- package/lib/components/templates/ButtonTemplates/index.d.ts.map +1 -1
- package/lib/components/templates/CyclicSchemaExpandTemplate.d.ts +7 -0
- package/lib/components/templates/CyclicSchemaExpandTemplate.d.ts.map +1 -0
- package/lib/components/templates/CyclicSchemaExpandTemplate.js +12 -0
- package/lib/components/templates/DescriptionField.d.ts +2 -2
- package/lib/components/templates/DescriptionField.d.ts.map +1 -1
- package/lib/components/templates/ErrorList.d.ts +2 -2
- package/lib/components/templates/ErrorList.d.ts.map +1 -1
- package/lib/components/templates/ErrorList.js +2 -4
- package/lib/components/templates/FallbackFieldTemplate.d.ts +2 -2
- package/lib/components/templates/FallbackFieldTemplate.d.ts.map +1 -1
- package/lib/components/templates/FieldErrorTemplate.d.ts +2 -2
- package/lib/components/templates/FieldErrorTemplate.d.ts.map +1 -1
- package/lib/components/templates/FieldErrorTemplate.js +1 -3
- package/lib/components/templates/FieldHelpTemplate.d.ts +2 -2
- package/lib/components/templates/FieldHelpTemplate.d.ts.map +1 -1
- package/lib/components/templates/FieldTemplate/FieldTemplate.d.ts +2 -2
- package/lib/components/templates/FieldTemplate/FieldTemplate.d.ts.map +1 -1
- package/lib/components/templates/FieldTemplate/FieldTemplate.js +1 -1
- package/lib/components/templates/FieldTemplate/Label.d.ts +3 -3
- package/lib/components/templates/FieldTemplate/Label.d.ts.map +1 -1
- package/lib/components/templates/GridTemplate.d.ts +2 -2
- package/lib/components/templates/GridTemplate.d.ts.map +1 -1
- package/lib/components/templates/MultiSchemaFieldTemplate.d.ts +2 -2
- package/lib/components/templates/MultiSchemaFieldTemplate.d.ts.map +1 -1
- package/lib/components/templates/ObjectFieldTemplate.d.ts +2 -2
- package/lib/components/templates/ObjectFieldTemplate.d.ts.map +1 -1
- package/lib/components/templates/ObjectFieldTemplate.js +1 -1
- package/lib/components/templates/OptionalDataControlsTemplate.d.ts +2 -2
- package/lib/components/templates/OptionalDataControlsTemplate.d.ts.map +1 -1
- package/lib/components/templates/OptionalDataControlsTemplate.js +1 -1
- package/lib/components/templates/TitleField.d.ts +2 -2
- package/lib/components/templates/TitleField.d.ts.map +1 -1
- package/lib/components/templates/UnsupportedField.d.ts +2 -2
- package/lib/components/templates/UnsupportedField.d.ts.map +1 -1
- package/lib/components/templates/UnsupportedField.js +2 -2
- package/lib/components/templates/WrapIfAdditionalTemplate.d.ts +2 -2
- package/lib/components/templates/WrapIfAdditionalTemplate.d.ts.map +1 -1
- package/lib/components/templates/WrapIfAdditionalTemplate.js +1 -1
- package/lib/components/templates/index.d.ts +1 -1
- package/lib/components/templates/index.d.ts.map +1 -1
- package/lib/components/templates/index.js +2 -0
- package/lib/components/widgets/AltDateTimeWidget.d.ts +2 -2
- package/lib/components/widgets/AltDateTimeWidget.d.ts.map +1 -1
- package/lib/components/widgets/AltDateWidget.d.ts +2 -2
- package/lib/components/widgets/AltDateWidget.d.ts.map +1 -1
- package/lib/components/widgets/AltDateWidget.js +2 -2
- package/lib/components/widgets/CheckboxWidget.d.ts +2 -2
- package/lib/components/widgets/CheckboxWidget.d.ts.map +1 -1
- package/lib/components/widgets/CheckboxesWidget.d.ts +2 -2
- package/lib/components/widgets/CheckboxesWidget.d.ts.map +1 -1
- package/lib/components/widgets/CheckboxesWidget.js +4 -4
- package/lib/components/widgets/ColorWidget.d.ts +2 -2
- package/lib/components/widgets/ColorWidget.d.ts.map +1 -1
- package/lib/components/widgets/DateTimeWidget.d.ts +2 -2
- package/lib/components/widgets/DateTimeWidget.d.ts.map +1 -1
- package/lib/components/widgets/DateTimeWidget.js +2 -2
- package/lib/components/widgets/DateWidget.d.ts +2 -2
- package/lib/components/widgets/DateWidget.d.ts.map +1 -1
- package/lib/components/widgets/EmailWidget.d.ts +2 -2
- package/lib/components/widgets/EmailWidget.d.ts.map +1 -1
- package/lib/components/widgets/FileWidget.d.ts +2 -2
- package/lib/components/widgets/FileWidget.d.ts.map +1 -1
- package/lib/components/widgets/FileWidget.js +6 -4
- package/lib/components/widgets/HiddenWidget.d.ts +2 -2
- package/lib/components/widgets/HiddenWidget.d.ts.map +1 -1
- package/lib/components/widgets/PasswordWidget.d.ts +2 -2
- package/lib/components/widgets/PasswordWidget.d.ts.map +1 -1
- package/lib/components/widgets/RadioWidget.d.ts +2 -2
- package/lib/components/widgets/RadioWidget.d.ts.map +1 -1
- package/lib/components/widgets/RadioWidget.js +4 -4
- package/lib/components/widgets/RangeWidget.d.ts +2 -2
- package/lib/components/widgets/RangeWidget.d.ts.map +1 -1
- package/lib/components/widgets/RatingWidget.d.ts +2 -2
- package/lib/components/widgets/RatingWidget.d.ts.map +1 -1
- package/lib/components/widgets/RatingWidget.js +15 -15
- package/lib/components/widgets/SelectWidget.d.ts +2 -2
- package/lib/components/widgets/SelectWidget.d.ts.map +1 -1
- package/lib/components/widgets/SelectWidget.js +9 -8
- package/lib/components/widgets/TextWidget.d.ts +2 -2
- package/lib/components/widgets/TextWidget.d.ts.map +1 -1
- package/lib/components/widgets/TextareaWidget.d.ts +2 -2
- package/lib/components/widgets/TextareaWidget.d.ts.map +1 -1
- package/lib/components/widgets/TextareaWidget.js +5 -5
- package/lib/components/widgets/TimeWidget.d.ts +2 -2
- package/lib/components/widgets/TimeWidget.d.ts.map +1 -1
- package/lib/components/widgets/URLWidget.d.ts +2 -2
- package/lib/components/widgets/URLWidget.d.ts.map +1 -1
- package/lib/components/widgets/UpDownWidget.d.ts +2 -2
- package/lib/components/widgets/UpDownWidget.d.ts.map +1 -1
- package/lib/components/widgets/index.d.ts +1 -1
- package/lib/components/widgets/index.d.ts.map +1 -1
- package/lib/getDefaultRegistry.d.ts +1 -1
- package/lib/getDefaultRegistry.d.ts.map +1 -1
- package/lib/getDefaultRegistry.js +1 -1
- package/lib/getTestRegistry.d.ts +1 -1
- package/lib/getTestRegistry.d.ts.map +1 -1
- package/lib/getTestRegistry.js +1 -1
- package/lib/index.d.ts +10 -5
- package/lib/index.d.ts.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/withTheme.d.ts +3 -3
- package/lib/withTheme.d.ts.map +1 -1
- package/lib/withTheme.js +6 -6
- package/package.json +28 -28
- package/src/components/Form.tsx +197 -111
- package/src/components/RichDescription.tsx +3 -10
- package/src/components/RichHelp.tsx +3 -10
- package/src/components/SchemaExamples.tsx +6 -4
- package/src/components/fields/ArrayField.tsx +122 -108
- package/src/components/fields/BooleanField.tsx +4 -9
- package/src/components/fields/CyclicSchemaField.tsx +40 -0
- package/src/components/fields/FallbackField.tsx +4 -8
- package/src/components/fields/LayoutGridField.tsx +21 -19
- package/src/components/fields/LayoutHeaderField.tsx +2 -10
- package/src/components/fields/LayoutMultiSchemaField.tsx +15 -10
- package/src/components/fields/MultiSchemaField.tsx +202 -218
- package/src/components/fields/NullField.tsx +1 -1
- package/src/components/fields/NumberField.tsx +8 -10
- package/src/components/fields/ObjectField.tsx +52 -40
- package/src/components/fields/OptionalDataControlsField.tsx +6 -4
- package/src/components/fields/SchemaField.tsx +66 -51
- package/src/components/fields/StringField.tsx +4 -15
- package/src/components/fields/index.ts +3 -1
- package/src/components/templates/ArrayFieldDescriptionTemplate.tsx +2 -9
- package/src/components/templates/ArrayFieldItemButtonsTemplate.tsx +2 -7
- package/src/components/templates/ArrayFieldItemTemplate.tsx +3 -9
- package/src/components/templates/ArrayFieldTemplate.tsx +2 -9
- package/src/components/templates/ArrayFieldTitleTemplate.tsx +2 -10
- package/src/components/templates/BaseInputTemplate.tsx +16 -23
- package/src/components/templates/ButtonTemplates/AddButton.tsx +2 -1
- package/src/components/templates/ButtonTemplates/IconButton.tsx +16 -7
- package/src/components/templates/ButtonTemplates/SubmitButton.tsx +2 -1
- package/src/components/templates/ButtonTemplates/index.ts +1 -1
- package/src/components/templates/CyclicSchemaExpandTemplate.tsx +31 -0
- package/src/components/templates/DescriptionField.tsx +1 -1
- package/src/components/templates/ErrorList.tsx +8 -15
- package/src/components/templates/FallbackFieldTemplate.tsx +2 -1
- package/src/components/templates/FieldErrorTemplate.tsx +8 -8
- package/src/components/templates/FieldHelpTemplate.tsx +2 -1
- package/src/components/templates/FieldTemplate/FieldTemplate.tsx +2 -8
- package/src/components/templates/FieldTemplate/Label.tsx +2 -2
- package/src/components/templates/GridTemplate.tsx +1 -1
- package/src/components/templates/MultiSchemaFieldTemplate.tsx +1 -1
- package/src/components/templates/ObjectFieldTemplate.tsx +2 -7
- package/src/components/templates/OptionalDataControlsTemplate.tsx +3 -2
- package/src/components/templates/TitleField.tsx +1 -1
- package/src/components/templates/UnsupportedField.tsx +4 -3
- package/src/components/templates/WrapIfAdditionalTemplate.tsx +2 -9
- package/src/components/templates/index.ts +3 -1
- package/src/components/widgets/AltDateTimeWidget.tsx +1 -1
- package/src/components/widgets/AltDateWidget.tsx +7 -13
- package/src/components/widgets/CheckboxWidget.tsx +3 -5
- package/src/components/widgets/CheckboxesWidget.tsx +8 -10
- package/src/components/widgets/ColorWidget.tsx +2 -1
- package/src/components/widgets/DateTimeWidget.tsx +3 -10
- package/src/components/widgets/DateWidget.tsx +2 -1
- package/src/components/widgets/EmailWidget.tsx +2 -1
- package/src/components/widgets/FileWidget.tsx +9 -8
- package/src/components/widgets/HiddenWidget.tsx +1 -1
- package/src/components/widgets/PasswordWidget.tsx +2 -1
- package/src/components/widgets/RadioWidget.tsx +8 -10
- package/src/components/widgets/RangeWidget.tsx +1 -1
- package/src/components/widgets/RatingWidget.tsx +48 -47
- package/src/components/widgets/SelectWidget.tsx +48 -31
- package/src/components/widgets/TextWidget.tsx +2 -1
- package/src/components/widgets/TextareaWidget.tsx +10 -7
- package/src/components/widgets/TimeWidget.tsx +2 -1
- package/src/components/widgets/URLWidget.tsx +2 -1
- package/src/components/widgets/UpDownWidget.tsx +2 -1
- package/src/components/widgets/index.ts +1 -1
- package/src/getDefaultRegistry.ts +2 -9
- package/src/getTestRegistry.tsx +2 -7
- package/src/index.ts +10 -5
- package/src/withTheme.tsx +14 -9
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EnumOptionsType, FieldProps, FormContextType, RJSFSchema, SchemaUtilsType, StrictRJSFSchema, UiSchema } from '@rjsf/utils';
|
|
1
|
+
import type { EnumOptionsType, FieldProps, FormContextType, RJSFSchema, SchemaUtilsType, StrictRJSFSchema, UiSchema } from '@rjsf/utils';
|
|
2
2
|
/** Gets the selected option from the list of `options`, using the `selectorField` to search inside each `option` for
|
|
3
3
|
* the `properties[selectorField].default(or const)` that matches the given `value`.
|
|
4
4
|
*
|
|
@@ -24,5 +24,5 @@ export declare function computeEnumOptions<T = any, S extends StrictRJSFSchema =
|
|
|
24
24
|
* field or indirectly via `ui:optionsSchemaSelector` in the `uiSchema`) to help determine which `anyOf`/`oneOf` schema
|
|
25
25
|
* is active. If no `selectorField` is specified, then an error is thrown.
|
|
26
26
|
*/
|
|
27
|
-
export default function LayoutMultiSchemaField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(props: FieldProps<T, S, F>): import("react
|
|
27
|
+
export default function LayoutMultiSchemaField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(props: FieldProps<T, S, F>): import("react").JSX.Element;
|
|
28
28
|
//# sourceMappingURL=LayoutMultiSchemaField.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LayoutMultiSchemaField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/LayoutMultiSchemaField.tsx"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"LayoutMultiSchemaField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/LayoutMultiSchemaField.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,UAAU,EACV,eAAe,EACf,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACT,MAAM,aAAa,CAAC;AAuBrB;;;;;;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,+BA0I3B"}
|
|
@@ -69,7 +69,7 @@ export default function LayoutMultiSchemaField(props) {
|
|
|
69
69
|
useEffect(() => {
|
|
70
70
|
setEnumOptions(computeEnumOptions(schema, options, schemaUtils, uiSchema, formData));
|
|
71
71
|
// We are using hashes in place of the dependencies
|
|
72
|
-
//
|
|
72
|
+
// oxlint-disable-next-line react-hooks/exhaustive-deps
|
|
73
73
|
}, [schemaHash, optionsHash, schemaUtils, uiSchemaHash, formDataHash]);
|
|
74
74
|
const { widget = discriminator ? 'radio' : 'select', title = '', placeholder = '', optionsSchemaSelector: selectorField = discriminator, hideError: uiSchemaHideError, ...uiOptions } = getUiOptions(uiSchema);
|
|
75
75
|
if (!selectorField) {
|
|
@@ -94,6 +94,9 @@ export default function LayoutMultiSchemaField(props) {
|
|
|
94
94
|
* will use it as the index of the new option to select
|
|
95
95
|
*/
|
|
96
96
|
const onOptionChange = (opt) => {
|
|
97
|
+
if (disabled || readonly) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
97
100
|
const newOption = getSelectedOption(enumOptions, selectorField, opt);
|
|
98
101
|
const oldOption = getSelectedOption(enumOptions, selectorField, selectedOption);
|
|
99
102
|
let newFormData = schemaUtils.sanitizeDataForNewSchema(newOption, oldOption, formData);
|
|
@@ -1,48 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { FieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
3
|
-
/** Type used for the state of the `AnyOfField` component */
|
|
4
|
-
type AnyOfFieldState<S extends StrictRJSFSchema = RJSFSchema> = {
|
|
5
|
-
/** The currently selected option */
|
|
6
|
-
selectedOption: number;
|
|
7
|
-
/** The option schemas after retrieving all $refs */
|
|
8
|
-
retrievedOptions: S[];
|
|
9
|
-
};
|
|
1
|
+
import type { FieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
10
2
|
/** The `AnyOfField` component is used to render a field in the schema that is an `anyOf`, `allOf` or `oneOf`. It tracks
|
|
11
3
|
* the currently selected option and cleans up any irrelevant data in `formData`.
|
|
12
4
|
*
|
|
13
5
|
* @param props - The `FieldProps` for this template
|
|
14
6
|
*/
|
|
15
|
-
declare
|
|
16
|
-
/** Constructs an `AnyOfField` with the given `props` to initialize the initially selected option in state
|
|
17
|
-
*
|
|
18
|
-
* @param props - The `FieldProps` for this template
|
|
19
|
-
*/
|
|
20
|
-
constructor(props: FieldProps<T, S, F>);
|
|
21
|
-
/** React lifecycle method that is called when the props and/or state for this component is updated. It recomputes the
|
|
22
|
-
* currently selected option based on the overall `formData`
|
|
23
|
-
*
|
|
24
|
-
* @param prevProps - The previous `FieldProps` for this template
|
|
25
|
-
* @param prevState - The previous `AnyOfFieldState` for this template
|
|
26
|
-
*/
|
|
27
|
-
componentDidUpdate(prevProps: Readonly<FieldProps<T, S, F>>, prevState: Readonly<AnyOfFieldState>): void;
|
|
28
|
-
/** Determines the best matching option for the given `formData` and `options`.
|
|
29
|
-
*
|
|
30
|
-
* @param formData - The new formData
|
|
31
|
-
* @param options - The list of options to choose from
|
|
32
|
-
* @return - The index of the `option` that best matches the `formData`
|
|
33
|
-
*/
|
|
34
|
-
getMatchingOption(selectedOption: number, formData: T | undefined, options: S[]): number;
|
|
35
|
-
/** Callback handler to remember what the currently selected option is. In addition to that the `formData` is updated
|
|
36
|
-
* to remove properties that are not part of the newly selected option schema, and then the updated data is passed to
|
|
37
|
-
* the `onChange` handler.
|
|
38
|
-
*
|
|
39
|
-
* @param option - The new option value being selected
|
|
40
|
-
*/
|
|
41
|
-
onOptionChange: (option?: string) => void;
|
|
42
|
-
getFieldId(): string;
|
|
43
|
-
/** Renders the `AnyOfField` selector along with a `SchemaField` for the value of the `formData`
|
|
44
|
-
*/
|
|
45
|
-
render(): import("react/jsx-runtime").JSX.Element;
|
|
46
|
-
}
|
|
7
|
+
declare function AnyOfField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(props: FieldProps<T, S, F>): import("react").JSX.Element;
|
|
47
8
|
export default AnyOfField;
|
|
48
9
|
//# sourceMappingURL=MultiSchemaField.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiSchemaField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/MultiSchemaField.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MultiSchemaField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/MultiSchemaField.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,gBAAgB,EAAY,MAAM,aAAa,CAAC;AAoBvG;;;;GAIG;AACH,iBAAS,UAAU,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,gBAAgB,GAAG,UAAU,EAAE,CAAC,SAAS,eAAe,GAAG,GAAG,EACnG,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,+BAmO3B;AAED,eAAe,UAAU,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import { ANY_OF_KEY, deepEquals, ERRORS_KEY, getDiscriminatorFieldFromSchema, getTemplate, getUiOptions, getWidget, isFormDataAvailable, mergeSchemas, ONE_OF_KEY, shouldRenderOptionalField, TranslatableString, } from '@rjsf/utils';
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { ANY_OF_KEY, deepEquals, ERRORS_KEY, getDiscriminatorFieldFromSchema, getTemplate, getUiOptions, getWidget, hashObject, isFormDataAvailable, mergeSchemas, ONE_OF_KEY, shouldRenderOptionalField, TranslatableString, } from '@rjsf/utils';
|
|
4
4
|
import get from 'lodash-es/get.js';
|
|
5
5
|
import isEmpty from 'lodash-es/isEmpty.js';
|
|
6
6
|
import omit from 'lodash-es/omit.js';
|
|
@@ -9,70 +9,60 @@ import omit from 'lodash-es/omit.js';
|
|
|
9
9
|
*
|
|
10
10
|
* @param props - The `FieldProps` for this template
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* @param prevState - The previous `AnyOfFieldState` for this template
|
|
12
|
+
function AnyOfField(props) {
|
|
13
|
+
const { name, disabled = false, errorSchema = {}, formData, fieldPathId, onBlur, onChange, onFocus, options, readonly, registry, required = false, schema, uiSchema, } = props;
|
|
14
|
+
const { schemaUtils } = registry;
|
|
15
|
+
// Hash formData by value so the memo only invalidates when data actually changes, not on every
|
|
16
|
+
// new object reference. hashObject(undefined) throws, so null is used as the fallback.
|
|
17
|
+
const formDataHash = hashObject(formData ?? null);
|
|
18
|
+
// retrievedOptions is purely derived from options — useMemo handles re-derivation automatically
|
|
19
|
+
// when options, schemaUtils, or formData's value changes, with no render-phase dispatch needed.
|
|
20
|
+
const retrievedOptions = useMemo(() => options.map((opt) => schemaUtils.retrieveSchema(opt, formData)),
|
|
21
|
+
// oxlint-disable-next-line react-hooks/exhaustive-deps -- formDataHash is the value-stable proxy for formData
|
|
22
|
+
[options, schemaUtils, formDataHash]);
|
|
23
|
+
const [selectedOption, setSelectedOption] = useState(() => {
|
|
24
|
+
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
25
|
+
return schemaUtils.getClosestMatchingOption(formData, retrievedOptions, 0, discriminator);
|
|
26
|
+
});
|
|
27
|
+
/** Flag to skip the formData-change-driven option recalculation when the user just selected an option.
|
|
28
|
+
* Set to true in onOptionChange (before onChange is called), consumed and reset in the update effect.
|
|
29
|
+
* This prevents the matching-option recalculation from overriding a user's explicit choice when
|
|
30
|
+
* getDefaultFormState populates undefined properties that make deepEquals see a false formData change.
|
|
32
31
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
32
|
+
const skipNextOptionRecalculation = useRef(false);
|
|
33
|
+
const prevFormDataRef = useRef(formData);
|
|
34
|
+
const prevFieldIdRef = useRef(fieldPathId.$id);
|
|
35
|
+
// Mirrors componentDidUpdate: re-match selectedOption when formData changes on the same field.
|
|
36
|
+
// Runs after every render (no deps array) to compare against prev values stored in refs.
|
|
37
|
+
// oxlint-disable-next-line react-hooks/exhaustive-deps
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
const prevFormData = prevFormDataRef.current;
|
|
40
|
+
const prevFieldId = prevFieldIdRef.current;
|
|
41
|
+
prevFormDataRef.current = formData;
|
|
42
|
+
prevFieldIdRef.current = fieldPathId.$id;
|
|
43
|
+
if (!deepEquals(formData, prevFormData) && fieldPathId.$id === prevFieldId) {
|
|
44
|
+
if (skipNextOptionRecalculation.current) {
|
|
45
|
+
skipNextOptionRecalculation.current = false;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
49
|
+
const matchingOption = schemaUtils.getClosestMatchingOption(formData, retrievedOptions, selectedOption, discriminator);
|
|
50
|
+
if (matchingOption !== selectedOption) {
|
|
51
|
+
setSelectedOption(matchingOption);
|
|
48
52
|
}
|
|
49
53
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
/** Determines the best matching option for the given `formData` and `options`.
|
|
55
|
-
*
|
|
56
|
-
* @param formData - The new formData
|
|
57
|
-
* @param options - The list of options to choose from
|
|
58
|
-
* @return - The index of the `option` that best matches the `formData`
|
|
59
|
-
*/
|
|
60
|
-
getMatchingOption(selectedOption, formData, options) {
|
|
61
|
-
const { schema, registry: { schemaUtils }, } = this.props;
|
|
62
|
-
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
63
|
-
const option = schemaUtils.getClosestMatchingOption(formData, options, selectedOption, discriminator);
|
|
64
|
-
return option;
|
|
65
|
-
}
|
|
54
|
+
});
|
|
55
|
+
const fieldId = `${fieldPathId.$id}${schema.oneOf ? '__oneof_select' : '__anyof_select'}`;
|
|
66
56
|
/** Callback handler to remember what the currently selected option is. In addition to that the `formData` is updated
|
|
67
57
|
* to remove properties that are not part of the newly selected option schema, and then the updated data is passed to
|
|
68
58
|
* the `onChange` handler.
|
|
69
59
|
*
|
|
70
60
|
* @param option - The new option value being selected
|
|
71
61
|
*/
|
|
72
|
-
onOptionChange = (option) => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
62
|
+
const onOptionChange = useCallback((option) => {
|
|
63
|
+
if (disabled || readonly) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
76
66
|
const intOption = option !== undefined ? parseInt(option, 10) : -1;
|
|
77
67
|
if (intOption === selectedOption) {
|
|
78
68
|
return;
|
|
@@ -85,76 +75,80 @@ class AnyOfField extends Component {
|
|
|
85
75
|
// so that only the root objects themselves are created without adding undefined children properties
|
|
86
76
|
newFormData = schemaUtils.getDefaultFormState(newOption, newFormData, 'excludeObjectChildren');
|
|
87
77
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
78
|
+
setSelectedOption(intOption);
|
|
79
|
+
skipNextOptionRecalculation.current = true;
|
|
80
|
+
onChange(newFormData, fieldPathId.path, undefined, fieldId);
|
|
81
|
+
},
|
|
82
|
+
// setSelectedOption is stable (guaranteed by useState); skipNextOptionRecalculation is a ref
|
|
83
|
+
[selectedOption, retrievedOptions, disabled, readonly, schemaUtils, formData, fieldPathId, onChange, fieldId]);
|
|
84
|
+
const { widgets, fields, translateString, globalUiOptions } = registry;
|
|
85
|
+
const { SchemaField: SchemaFieldComponent } = fields;
|
|
86
|
+
const MultiSchemaFieldTemplate = getTemplate('MultiSchemaFieldTemplate', registry, globalUiOptions);
|
|
87
|
+
const isOptionalRender = shouldRenderOptionalField(registry, schema, required, uiSchema);
|
|
88
|
+
const hasFormData = isFormDataAvailable(formData);
|
|
89
|
+
const { widget = 'select', placeholder, autofocus, autocomplete, title = schema.title, ...uiOptions } = getUiOptions(uiSchema, globalUiOptions);
|
|
90
|
+
const Widget = getWidget({ type: 'number' }, widget, widgets);
|
|
91
|
+
const rawErrors = get(errorSchema, ERRORS_KEY, []);
|
|
92
|
+
const fieldErrorSchema = omit(errorSchema, [ERRORS_KEY]);
|
|
93
|
+
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
94
|
+
const option = selectedOption >= 0 ? retrievedOptions[selectedOption] || null : null;
|
|
95
|
+
let optionSchema;
|
|
96
|
+
if (option) {
|
|
97
|
+
const { required: schemaRequired, type: schemaType } = schema;
|
|
98
|
+
const parentProps = {};
|
|
99
|
+
if (schemaRequired) {
|
|
100
|
+
parentProps.required = schemaRequired;
|
|
101
|
+
}
|
|
102
|
+
// Propagate the parent schema type to options that don't define their own.
|
|
103
|
+
// This is necessary when the parent constrains the type (e.g. { type: 'string',
|
|
104
|
+
// oneOf: [{ pattern: '...' }, { pattern: '...' }] }) but the option sub-schemas
|
|
105
|
+
// omit the type — without it, getSchemaType returns undefined and the option
|
|
106
|
+
// renders as FallbackField instead of the correct widget (e.g. StringField).
|
|
107
|
+
if (schemaType !== undefined && !('type' in option)) {
|
|
108
|
+
parentProps.type = schemaType;
|
|
109
|
+
}
|
|
110
|
+
// Merge in all the non-oneOf/anyOf properties and also skip the special ADDITIONAL_PROPERTY_FLAG property
|
|
111
|
+
optionSchema = Object.keys(parentProps).length > 0 ? mergeSchemas(parentProps, option) : option;
|
|
95
112
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const { SchemaField: _SchemaField } = fields;
|
|
102
|
-
const MultiSchemaFieldTemplate = getTemplate('MultiSchemaFieldTemplate', registry, globalUiOptions);
|
|
103
|
-
const isOptionalRender = shouldRenderOptionalField(registry, schema, required, uiSchema);
|
|
104
|
-
const hasFormData = isFormDataAvailable(formData);
|
|
105
|
-
const { selectedOption, retrievedOptions } = this.state;
|
|
106
|
-
const { widget = 'select', placeholder, autofocus, autocomplete, title = schema.title, ...uiOptions } = getUiOptions(uiSchema, globalUiOptions);
|
|
107
|
-
const Widget = getWidget({ type: 'number' }, widget, widgets);
|
|
108
|
-
const rawErrors = get(errorSchema, ERRORS_KEY, []);
|
|
109
|
-
const fieldErrorSchema = omit(errorSchema, [ERRORS_KEY]);
|
|
110
|
-
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
111
|
-
const option = selectedOption >= 0 ? retrievedOptions[selectedOption] || null : null;
|
|
112
|
-
let optionSchema;
|
|
113
|
-
if (option) {
|
|
114
|
-
// merge top level required field
|
|
115
|
-
const { required } = schema;
|
|
116
|
-
// Merge in all the non-oneOf/anyOf properties and also skip the special ADDITIONAL_PROPERTY_FLAG property
|
|
117
|
-
optionSchema = required ? mergeSchemas({ required }, option) : option;
|
|
113
|
+
// First we will check to see if there is an anyOf/oneOf override for the UI schema
|
|
114
|
+
let optionsUiSchema = [];
|
|
115
|
+
if (ONE_OF_KEY in schema && uiSchema && ONE_OF_KEY in uiSchema) {
|
|
116
|
+
if (Array.isArray(uiSchema[ONE_OF_KEY])) {
|
|
117
|
+
optionsUiSchema = uiSchema[ONE_OF_KEY];
|
|
118
118
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (Array.isArray(uiSchema[ONE_OF_KEY])) {
|
|
123
|
-
optionsUiSchema = uiSchema[ONE_OF_KEY];
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
console.warn(`uiSchema.oneOf is not an array for "${title || name}"`);
|
|
127
|
-
}
|
|
119
|
+
else {
|
|
120
|
+
// oxlint-disable-next-line no-console
|
|
121
|
+
console.warn(`uiSchema.oneOf is not an array for "${title || name}"`);
|
|
128
122
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
else {
|
|
134
|
-
console.warn(`uiSchema.anyOf is not an array for "${title || name}"`);
|
|
135
|
-
}
|
|
123
|
+
}
|
|
124
|
+
else if (ANY_OF_KEY in schema && uiSchema && ANY_OF_KEY in uiSchema) {
|
|
125
|
+
if (Array.isArray(uiSchema[ANY_OF_KEY])) {
|
|
126
|
+
optionsUiSchema = uiSchema[ANY_OF_KEY];
|
|
136
127
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
optionUiSchema = optionsUiSchema[selectedOption];
|
|
128
|
+
else {
|
|
129
|
+
// oxlint-disable-next-line no-console
|
|
130
|
+
console.warn(`uiSchema.anyOf is not an array for "${title || name}"`);
|
|
141
131
|
}
|
|
142
|
-
const translateEnum = title
|
|
143
|
-
? TranslatableString.TitleOptionPrefix
|
|
144
|
-
: TranslatableString.OptionPrefix;
|
|
145
|
-
const translateParams = title ? [title] : [];
|
|
146
|
-
const enumOptions = retrievedOptions.map((opt, index) => {
|
|
147
|
-
// Also see if there is an override title in the uiSchema for each option, otherwise use the title from the option
|
|
148
|
-
const { title: uiTitle = opt.title } = getUiOptions(optionsUiSchema[index]);
|
|
149
|
-
return {
|
|
150
|
-
label: uiTitle || translateString(translateEnum, translateParams.concat(String(index + 1))),
|
|
151
|
-
value: index,
|
|
152
|
-
};
|
|
153
|
-
});
|
|
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;
|
|
155
|
-
const optionsSchemaField = (optionSchema && optionSchema.type !== 'null' && (_jsx(_SchemaField, { ...this.props, schema: optionSchema, uiSchema: optionUiSchema }))) ||
|
|
156
|
-
null;
|
|
157
|
-
return (_jsx(MultiSchemaFieldTemplate, { schema: schema, registry: registry, uiSchema: uiSchema, selector: selector, optionSchemaField: optionsSchemaField }));
|
|
158
132
|
}
|
|
133
|
+
// Then we pick the one that matches the selected option index, if one exists otherwise default to the main uiSchema
|
|
134
|
+
let optionUiSchema = uiSchema;
|
|
135
|
+
if (selectedOption >= 0 && optionsUiSchema.length > selectedOption) {
|
|
136
|
+
optionUiSchema = optionsUiSchema[selectedOption];
|
|
137
|
+
}
|
|
138
|
+
const translateEnum = title
|
|
139
|
+
? TranslatableString.TitleOptionPrefix
|
|
140
|
+
: TranslatableString.OptionPrefix;
|
|
141
|
+
const translateParams = title ? [title] : [];
|
|
142
|
+
const enumOptions = retrievedOptions.map((opt, index) => {
|
|
143
|
+
const { title: uiTitle = opt.title } = getUiOptions(optionsUiSchema[index]);
|
|
144
|
+
return {
|
|
145
|
+
label: uiTitle || translateString(translateEnum, translateParams.concat(String(index + 1))),
|
|
146
|
+
value: index,
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
const selector = !isOptionalRender || hasFormData ? (_jsx(Widget, { id: fieldId, name: `${name}${schema.oneOf ? '__oneof_select' : '__anyof_select'}`, schema: { type: 'number', default: 0 }, onChange: 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;
|
|
150
|
+
const optionsSchemaField = (optionSchema && optionSchema.type !== 'null' && (_jsx(SchemaFieldComponent, { ...props, schema: optionSchema, uiSchema: optionUiSchema }))) ||
|
|
151
|
+
null;
|
|
152
|
+
return (_jsx(MultiSchemaFieldTemplate, { schema: schema, registry: registry, uiSchema: uiSchema, selector: selector, optionSchemaField: optionsSchemaField }));
|
|
159
153
|
}
|
|
160
154
|
export default AnyOfField;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
1
|
+
import type { FieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
2
|
/** The `NullField` component is used to render a field in the schema is null. It also ensures that the `formData` is
|
|
3
3
|
* also set to null if it has no value.
|
|
4
4
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NullField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/NullField.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"NullField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/NullField.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE7F;;;;GAIG;AACH,iBAAS,SAAS,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,gBAAgB,GAAG,UAAU,EAAE,CAAC,SAAS,eAAe,GAAG,GAAG,EAClG,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,QAU3B;AAED,eAAe,SAAS,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
1
|
+
import type { FieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
2
|
/**
|
|
3
3
|
* The NumberField class has some special handling for dealing with trailing
|
|
4
4
|
* decimal points and/or zeroes. This logic is designed to allow trailing values
|
|
@@ -16,6 +16,6 @@ import { FieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf
|
|
|
16
16
|
* value cached in the state. If it matches the cached value, the cached
|
|
17
17
|
* value is passed to the input instead of the formData value
|
|
18
18
|
*/
|
|
19
|
-
declare function NumberField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(props: FieldProps<T, S, F>): import("react
|
|
19
|
+
declare function NumberField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(props: FieldProps<T, S, F>): import("react").JSX.Element;
|
|
20
20
|
export default NumberField;
|
|
21
21
|
//# sourceMappingURL=NumberField.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/NumberField.tsx"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"NumberField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/NumberField.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGV,UAAU,EACV,eAAe,EACf,UAAU,EACV,gBAAgB,EACjB,MAAM,aAAa,CAAC;AAerB;;;;;;;;;;;;;;;;GAgBG;AACH,iBAAS,WAAW,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,gBAAgB,GAAG,UAAU,EAAE,CAAC,SAAS,eAAe,GAAG,GAAG,EACpG,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,+BAgD3B;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useState, useCallback } from 'react';
|
|
3
|
-
import { asNumber
|
|
3
|
+
import { asNumber } from '@rjsf/utils';
|
|
4
4
|
// Matches a string that ends in a . character, optionally followed by a sequence of
|
|
5
5
|
// digits followed by any number of 0 characters up until the end of the line.
|
|
6
6
|
// Ensuring that there is at least one prefixed character is important so that
|
|
@@ -37,20 +37,18 @@ function NumberField(props) {
|
|
|
37
37
|
*
|
|
38
38
|
* @param value - The current value for the change occurring
|
|
39
39
|
*/
|
|
40
|
-
const handleChange = useCallback((
|
|
40
|
+
const handleChange = useCallback((newValue, path, errorSchema, id) => {
|
|
41
41
|
// Cache the original value in component state
|
|
42
|
-
setLastValue(
|
|
42
|
+
setLastValue(newValue);
|
|
43
43
|
// Normalize decimals that don't start with a zero character in advance so
|
|
44
44
|
// that the rest of the normalization logic is simpler
|
|
45
|
-
|
|
46
|
-
value = `0${value}`;
|
|
47
|
-
}
|
|
45
|
+
const normalizedValue = `${newValue}`.startsWith('.') ? `0${newValue}` : newValue;
|
|
48
46
|
// Check that the value is a string (this can happen if the widget used is a
|
|
49
47
|
// <select>, due to an enum declaration etc) then, if the value ends in a
|
|
50
48
|
// trailing decimal point or multiple zeroes, strip the trailing values
|
|
51
|
-
const processed = typeof
|
|
52
|
-
? asNumber(
|
|
53
|
-
: asNumber(
|
|
49
|
+
const processed = typeof normalizedValue === 'string' && trailingCharMatcherWithPrefix.exec(normalizedValue)
|
|
50
|
+
? asNumber(normalizedValue.replace(trailingCharMatcher, ''))
|
|
51
|
+
: asNumber(normalizedValue);
|
|
54
52
|
onChange(processed, path, errorSchema, id);
|
|
55
53
|
}, [onChange]);
|
|
56
54
|
if (typeof lastValue === 'string' && typeof value === 'number') {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { FieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
1
|
+
import type { FieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
2
|
/** The `ObjectField` component is used to render a field in the schema that is of type `object`. It tracks whether an
|
|
3
3
|
* additional property key was modified and what it was modified to
|
|
4
4
|
*
|
|
5
5
|
* @param props - The `FieldProps` for this template
|
|
6
6
|
*/
|
|
7
|
-
export default function ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(props: FieldProps<T, S, F>): import("react
|
|
7
|
+
export default function ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(props: FieldProps<T, S, F>): import("react").JSX.Element;
|
|
8
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":"AAEA,OAAO,KAAK,EAIV,UAAU,EACV,eAAe,EAIf,UAAU,EACV,gBAAgB,EACjB,MAAM,aAAa,CAAC;AA6LrB;;;;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,+BA8O3B"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useCallback, useRef, useState } from 'react';
|
|
2
|
+
import { memo, useCallback, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { ADDITIONAL_PROPERTY_FLAG, ANY_OF_KEY, getTemplate, getUiOptions, isFormDataAvailable, orderProperties, shouldRenderOptionalField, toFieldPathId, useDeepCompareMemo, ONE_OF_KEY, PROPERTIES_KEY, REF_KEY, TranslatableString, } from '@rjsf/utils';
|
|
4
4
|
import get from 'lodash-es/get.js';
|
|
5
5
|
import has from 'lodash-es/has.js';
|
|
6
6
|
import isObject from 'lodash-es/isObject.js';
|
|
7
7
|
import set from 'lodash-es/set.js';
|
|
8
|
-
import { Markdown } from 'markdown-to-jsx';
|
|
8
|
+
import { Markdown } from 'markdown-to-jsx/react';
|
|
9
9
|
import { ADDITIONAL_PROPERTY_KEY_REMOVE } from '../constants.js';
|
|
10
10
|
/** Returns a flag indicating whether the `name` field is required in the object schema
|
|
11
11
|
*
|
|
@@ -14,7 +14,7 @@ import { ADDITIONAL_PROPERTY_KEY_REMOVE } from '../constants.js';
|
|
|
14
14
|
* @returns - True if the field `name` is required, false otherwise
|
|
15
15
|
*/
|
|
16
16
|
function isRequired(schema, name) {
|
|
17
|
-
return Array.isArray(schema.required) && schema.required.
|
|
17
|
+
return Array.isArray(schema.required) && schema.required.includes(name);
|
|
18
18
|
}
|
|
19
19
|
/** Returns a default value to be used for a new additional schema property of the given `type`
|
|
20
20
|
*
|
|
@@ -41,7 +41,7 @@ function getDefaultValue(translateString, type) {
|
|
|
41
41
|
}
|
|
42
42
|
/** The `ObjectFieldProperty` component is used to render the `SchemaField` for a child property of an object
|
|
43
43
|
*/
|
|
44
|
-
function
|
|
44
|
+
function ObjectFieldPropertyFn(props) {
|
|
45
45
|
const { fieldPathId, schema, registry, uiSchema, errorSchema, formData, onChange, onBlur, onFocus, disabled, readonly, required, hideError, propertyName, handleKeyRename, handleRemoveProperty, addedByAdditionalProperties, } = props;
|
|
46
46
|
const [wasPropertyKeyModified, setWasPropertyKeyModified] = useState(false);
|
|
47
47
|
const { globalFormOptions, fields } = registry;
|
|
@@ -56,14 +56,15 @@ function ObjectFieldProperty(props) {
|
|
|
56
56
|
* @returns - The onPropertyChange callback for the `name` property
|
|
57
57
|
*/
|
|
58
58
|
const onPropertyChange = useCallback((value, path, newErrorSchema, id) => {
|
|
59
|
+
// Don't set value = undefined for fields added by additionalProperties. Doing so removes them from the
|
|
60
|
+
// formData, which causes them to completely disappear (including the input field for the property name). Unlike
|
|
61
|
+
// fields which are "mandated" by the schema, these fields can be set to undefined by clicking a "delete field"
|
|
62
|
+
// button, so set empty values to the empty string.
|
|
63
|
+
let normalizedValue = value;
|
|
59
64
|
if (value === undefined && addedByAdditionalProperties) {
|
|
60
|
-
|
|
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
|
+
normalizedValue = '';
|
|
65
66
|
}
|
|
66
|
-
onChange(
|
|
67
|
+
onChange(normalizedValue, path, newErrorSchema, id);
|
|
67
68
|
}, [onChange, addedByAdditionalProperties]);
|
|
68
69
|
/** The key change event handler; Called when the key associated with a field is changed for an additionalProperty.
|
|
69
70
|
* simply returns a function that call the `handleKeyChange()` event with the value
|
|
@@ -88,6 +89,7 @@ function ObjectFieldProperty(props) {
|
|
|
88
89
|
}, [propertyName, handleRemoveProperty]);
|
|
89
90
|
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
|
}
|
|
92
|
+
const ObjectFieldProperty = memo(ObjectFieldPropertyFn);
|
|
91
93
|
/** The `ObjectField` component is used to render a field in the schema that is of type `object`. It tracks whether an
|
|
92
94
|
* additional property key was modified and what it was modified to
|
|
93
95
|
*
|
|
@@ -99,8 +101,8 @@ export default function ObjectField(props) {
|
|
|
99
101
|
const { OptionalDataControlsField } = fields;
|
|
100
102
|
const formDataRef = useRef(formData);
|
|
101
103
|
formDataRef.current = formData;
|
|
102
|
-
const schema = schemaUtils.retrieveSchema(rawSchema, formData, true);
|
|
103
|
-
const uiOptions = getUiOptions(uiSchema, globalUiOptions);
|
|
104
|
+
const schema = useMemo(() => schemaUtils.retrieveSchema(rawSchema, formData, true), [schemaUtils, rawSchema, formData]);
|
|
105
|
+
const uiOptions = useMemo(() => getUiOptions(uiSchema, globalUiOptions), [uiSchema, globalUiOptions]);
|
|
104
106
|
const { properties: schemaProperties = {} } = schema;
|
|
105
107
|
// All the children will use childFieldPathId if present in the props, falling back to the fieldPathId
|
|
106
108
|
const childFieldPathId = props.childFieldPathId ?? fieldPathId;
|
|
@@ -117,12 +119,13 @@ export default function ObjectField(props) {
|
|
|
117
119
|
* @param [formData] - The form data in which to check if the desired key already exists
|
|
118
120
|
* @returns - The name of the next available key from `preferredKey`
|
|
119
121
|
*/
|
|
120
|
-
const getAvailableKey = useCallback((preferredKey,
|
|
122
|
+
const getAvailableKey = useCallback((preferredKey, existingFormData) => {
|
|
121
123
|
const { duplicateKeySuffixSeparator = '-' } = getUiOptions(uiSchema, globalUiOptions);
|
|
122
124
|
let index = 0;
|
|
123
125
|
let newKey = preferredKey;
|
|
124
|
-
while (has(
|
|
125
|
-
|
|
126
|
+
while (has(existingFormData, newKey)) {
|
|
127
|
+
index += 1;
|
|
128
|
+
newKey = `${preferredKey}${duplicateKeySuffixSeparator}${index}`;
|
|
126
129
|
}
|
|
127
130
|
return newKey;
|
|
128
131
|
}, [uiSchema, globalUiOptions]);
|
|
@@ -133,7 +136,6 @@ export default function ObjectField(props) {
|
|
|
133
136
|
if (!(schema.additionalProperties || schema.patternProperties)) {
|
|
134
137
|
return;
|
|
135
138
|
}
|
|
136
|
-
const { translateString } = registry;
|
|
137
139
|
const newFormData = { ...formData };
|
|
138
140
|
const newKey = getAvailableKey('newKey', newFormData);
|
|
139
141
|
if (schema.patternProperties) {
|
|
@@ -150,11 +152,10 @@ export default function ObjectField(props) {
|
|
|
150
152
|
defaultValue = schema.additionalProperties.default;
|
|
151
153
|
let apSchema = schema.additionalProperties;
|
|
152
154
|
if (REF_KEY in apSchema) {
|
|
153
|
-
const { schemaUtils } = registry;
|
|
154
155
|
apSchema = schemaUtils.retrieveSchema({ [REF_KEY]: apSchema[REF_KEY] }, formData);
|
|
155
156
|
type = apSchema.type;
|
|
156
157
|
constValue = apSchema.const;
|
|
157
|
-
defaultValue = apSchema
|
|
158
|
+
defaultValue = schemaUtils.getDefaultFormState(apSchema, defaultValue);
|
|
158
159
|
}
|
|
159
160
|
if (!type && (ANY_OF_KEY in apSchema || ONE_OF_KEY in apSchema)) {
|
|
160
161
|
type = 'object';
|
|
@@ -169,7 +170,7 @@ export default function ObjectField(props) {
|
|
|
169
170
|
lastRenamedProperty.current.previousKey = getAvailableKey(newKey, newFormData);
|
|
170
171
|
}
|
|
171
172
|
onChange(newFormData, childFieldPathId.path);
|
|
172
|
-
}, [formData, onChange,
|
|
173
|
+
}, [formData, onChange, translateString, schemaUtils, childFieldPathId, getAvailableKey, schema]);
|
|
173
174
|
/** Returns a callback function that deals with the rename of a key for an additional property for a schema. That
|
|
174
175
|
* callback will attempt to rename the key and move the existing data to that key, calling `onChange` when it does.
|
|
175
176
|
*
|
|
@@ -186,8 +187,9 @@ export default function ObjectField(props) {
|
|
|
186
187
|
};
|
|
187
188
|
const newKeys = { [oldKey]: actualNewKey };
|
|
188
189
|
const keyValues = Object.keys(newFormData).map((key) => {
|
|
189
|
-
|
|
190
|
-
|
|
190
|
+
// `Object.hasOwn` so a falsy rename target (e.g. `""`) isn't dropped.
|
|
191
|
+
const mappedKey = Object.hasOwn(newKeys, key) ? newKeys[key] : key;
|
|
192
|
+
return { [mappedKey]: newFormData[key] };
|
|
191
193
|
});
|
|
192
194
|
const renamedObj = Object.assign({}, ...keyValues);
|
|
193
195
|
formDataRef.current = renamedObj;
|
|
@@ -230,14 +232,14 @@ export default function ObjectField(props) {
|
|
|
230
232
|
// getDisplayLabel() always returns false for object types, so just check the `uiOptions.label`
|
|
231
233
|
title: uiOptions.label === false ? '' : templateTitle,
|
|
232
234
|
description: uiOptions.label === false ? undefined : description,
|
|
233
|
-
properties: orderedProperties.map((
|
|
234
|
-
const addedByAdditionalProperties =
|
|
235
|
-
const fieldUiSchema = addedByAdditionalProperties ? uiSchema.additionalProperties : uiSchema[
|
|
235
|
+
properties: orderedProperties.map((propertyName) => {
|
|
236
|
+
const addedByAdditionalProperties = Boolean(schema.properties?.[propertyName]?.[ADDITIONAL_PROPERTY_FLAG]);
|
|
237
|
+
const fieldUiSchema = addedByAdditionalProperties ? uiSchema.additionalProperties : uiSchema[propertyName];
|
|
236
238
|
const hidden = getUiOptions(fieldUiSchema).widget === 'hidden';
|
|
237
|
-
const content = (_jsx(ObjectFieldProperty, { propertyName:
|
|
239
|
+
const content = (_jsx(ObjectFieldProperty, { propertyName: propertyName, required: isRequired(schema, propertyName), schema: get(schema, [PROPERTIES_KEY, propertyName], {}), uiSchema: fieldUiSchema, errorSchema: get(errorSchema, [propertyName]), fieldPathId: childFieldPathId, formData: get(formData, [propertyName]), handleKeyRename: handleKeyRename, handleRemoveProperty: handleRemoveProperty, addedByAdditionalProperties: addedByAdditionalProperties, onChange: onChange, onBlur: onBlur, onFocus: onFocus, registry: registry, disabled: disabled, readonly: readonly, hideError: hideError }, getStableKey(propertyName)));
|
|
238
240
|
return {
|
|
239
241
|
content,
|
|
240
|
-
name,
|
|
242
|
+
name: propertyName,
|
|
241
243
|
readonly,
|
|
242
244
|
disabled,
|
|
243
245
|
required,
|