@rjsf/core 5.11.2 → 5.12.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/dist/core.umd.js +3464 -0
- package/dist/index.esm.js +3814 -0
- package/dist/index.esm.js.map +7 -0
- package/dist/index.js +3714 -5
- package/dist/index.js.map +7 -0
- package/{dist/index.d.ts → lib/components/Form.d.ts} +321 -337
- package/lib/components/Form.js +474 -0
- package/lib/components/Form.js.map +1 -0
- package/lib/components/fields/ArrayField.d.ts +179 -0
- package/lib/components/fields/ArrayField.js +568 -0
- package/lib/components/fields/ArrayField.js.map +1 -0
- package/lib/components/fields/BooleanField.d.ts +9 -0
- package/lib/components/fields/BooleanField.js +62 -0
- package/lib/components/fields/BooleanField.js.map +1 -0
- package/lib/components/fields/MultiSchemaField.d.ts +47 -0
- package/lib/components/fields/MultiSchemaField.js +129 -0
- package/lib/components/fields/MultiSchemaField.js.map +1 -0
- package/lib/components/fields/NullField.d.ts +8 -0
- package/lib/components/fields/NullField.js +17 -0
- package/lib/components/fields/NullField.js.map +1 -0
- package/lib/components/fields/NumberField.d.ts +21 -0
- package/lib/components/fields/NumberField.js +70 -0
- package/lib/components/fields/NumberField.js.map +1 -0
- package/lib/components/fields/ObjectField.d.ts +73 -0
- package/lib/components/fields/ObjectField.js +222 -0
- package/lib/components/fields/ObjectField.js.map +1 -0
- package/lib/components/fields/SchemaField.d.ts +10 -0
- package/lib/components/fields/SchemaField.js +172 -0
- package/lib/components/fields/SchemaField.js.map +1 -0
- package/lib/components/fields/StringField.d.ts +8 -0
- package/lib/components/fields/StringField.js +25 -0
- package/lib/components/fields/StringField.js.map +1 -0
- package/lib/components/fields/index.d.ts +3 -0
- package/lib/components/fields/index.js +24 -0
- package/lib/components/fields/index.js.map +1 -0
- package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts +8 -0
- package/lib/components/templates/ArrayFieldDescriptionTemplate.js +18 -0
- package/lib/components/templates/ArrayFieldDescriptionTemplate.js.map +1 -0
- package/lib/components/templates/ArrayFieldItemTemplate.d.ts +7 -0
- package/lib/components/templates/ArrayFieldItemTemplate.js +20 -0
- package/lib/components/templates/ArrayFieldItemTemplate.js.map +1 -0
- package/lib/components/templates/ArrayFieldTemplate.d.ts +7 -0
- package/lib/components/templates/ArrayFieldTemplate.js +22 -0
- package/lib/components/templates/ArrayFieldTemplate.js.map +1 -0
- package/lib/components/templates/ArrayFieldTitleTemplate.d.ts +8 -0
- package/lib/components/templates/ArrayFieldTitleTemplate.js +18 -0
- package/lib/components/templates/ArrayFieldTitleTemplate.js.map +1 -0
- package/lib/components/templates/BaseInputTemplate.d.ts +9 -0
- package/lib/components/templates/BaseInputTemplate.js +39 -0
- package/lib/components/templates/BaseInputTemplate.js.map +1 -0
- package/lib/components/templates/ButtonTemplates/AddButton.d.ts +5 -0
- package/lib/components/templates/ButtonTemplates/AddButton.js +10 -0
- package/lib/components/templates/ButtonTemplates/AddButton.js.map +1 -0
- package/lib/components/templates/ButtonTemplates/IconButton.d.ts +7 -0
- package/lib/components/templates/ButtonTemplates/IconButton.js +24 -0
- package/lib/components/templates/ButtonTemplates/IconButton.js.map +1 -0
- package/lib/components/templates/ButtonTemplates/SubmitButton.d.ts +5 -0
- package/lib/components/templates/ButtonTemplates/SubmitButton.js +12 -0
- package/lib/components/templates/ButtonTemplates/SubmitButton.js.map +1 -0
- package/lib/components/templates/ButtonTemplates/index.d.ts +3 -0
- package/lib/components/templates/ButtonTemplates/index.js +15 -0
- package/lib/components/templates/ButtonTemplates/index.js.map +1 -0
- package/lib/components/templates/DescriptionField.d.ts +7 -0
- package/lib/components/templates/DescriptionField.js +18 -0
- package/lib/components/templates/DescriptionField.js.map +1 -0
- package/lib/components/templates/ErrorList.d.ts +7 -0
- package/lib/components/templates/ErrorList.js +13 -0
- package/lib/components/templates/ErrorList.js.map +1 -0
- package/lib/components/templates/FieldErrorTemplate.d.ts +7 -0
- package/lib/components/templates/FieldErrorTemplate.js +19 -0
- package/lib/components/templates/FieldErrorTemplate.js.map +1 -0
- package/lib/components/templates/FieldHelpTemplate.d.ts +7 -0
- package/lib/components/templates/FieldHelpTemplate.js +18 -0
- package/lib/components/templates/FieldHelpTemplate.js.map +1 -0
- package/lib/components/templates/FieldTemplate/FieldTemplate.d.ts +8 -0
- package/lib/components/templates/FieldTemplate/FieldTemplate.js +18 -0
- package/lib/components/templates/FieldTemplate/FieldTemplate.js.map +1 -0
- package/lib/components/templates/FieldTemplate/Label.d.ts +14 -0
- package/lib/components/templates/FieldTemplate/Label.js +14 -0
- package/lib/components/templates/FieldTemplate/Label.js.map +1 -0
- package/lib/components/templates/FieldTemplate/index.d.ts +2 -0
- package/lib/components/templates/FieldTemplate/index.js +3 -0
- package/lib/components/templates/FieldTemplate/index.js.map +1 -0
- package/lib/components/templates/ObjectFieldTemplate.d.ts +9 -0
- package/lib/components/templates/ObjectFieldTemplate.js +18 -0
- package/lib/components/templates/ObjectFieldTemplate.js.map +1 -0
- package/lib/components/templates/TitleField.d.ts +7 -0
- package/lib/components/templates/TitleField.js +11 -0
- package/lib/components/templates/TitleField.js.map +1 -0
- package/lib/components/templates/UnsupportedField.d.ts +9 -0
- package/lib/components/templates/UnsupportedField.js +28 -0
- package/lib/components/templates/UnsupportedField.js.map +1 -0
- package/lib/components/templates/WrapIfAdditionalTemplate.d.ts +8 -0
- package/lib/components/templates/WrapIfAdditionalTemplate.js +21 -0
- package/lib/components/templates/WrapIfAdditionalTemplate.js.map +1 -0
- package/lib/components/templates/index.d.ts +3 -0
- package/lib/components/templates/index.js +36 -0
- package/lib/components/templates/index.js.map +1 -0
- package/lib/components/widgets/AltDateTimeWidget.d.ts +9 -0
- package/lib/components/widgets/AltDateTimeWidget.js +14 -0
- package/lib/components/widgets/AltDateTimeWidget.js.map +1 -0
- package/lib/components/widgets/AltDateWidget.d.ts +7 -0
- package/lib/components/widgets/AltDateWidget.js +77 -0
- package/lib/components/widgets/AltDateWidget.js.map +1 -0
- package/lib/components/widgets/CheckboxWidget.d.ts +9 -0
- package/lib/components/widgets/CheckboxWidget.js +23 -0
- package/lib/components/widgets/CheckboxWidget.js.map +1 -0
- package/lib/components/widgets/CheckboxesWidget.d.ts +9 -0
- package/lib/components/widgets/CheckboxesWidget.js +31 -0
- package/lib/components/widgets/CheckboxesWidget.js.map +1 -0
- package/lib/components/widgets/ColorWidget.d.ts +8 -0
- package/lib/components/widgets/ColorWidget.js +13 -0
- package/lib/components/widgets/ColorWidget.js.map +1 -0
- package/lib/components/widgets/DateTimeWidget.d.ts +8 -0
- package/lib/components/widgets/DateTimeWidget.js +13 -0
- package/lib/components/widgets/DateTimeWidget.js.map +1 -0
- package/lib/components/widgets/DateWidget.d.ts +8 -0
- package/lib/components/widgets/DateWidget.js +15 -0
- package/lib/components/widgets/DateWidget.js.map +1 -0
- package/lib/components/widgets/EmailWidget.d.ts +7 -0
- package/lib/components/widgets/EmailWidget.js +12 -0
- package/lib/components/widgets/EmailWidget.js.map +1 -0
- package/lib/components/widgets/FileWidget.d.ts +8 -0
- package/lib/components/widgets/FileWidget.js +105 -0
- package/lib/components/widgets/FileWidget.js.map +1 -0
- package/lib/components/widgets/HiddenWidget.d.ts +9 -0
- package/lib/components/widgets/HiddenWidget.js +11 -0
- package/lib/components/widgets/HiddenWidget.js.map +1 -0
- package/lib/components/widgets/PasswordWidget.d.ts +7 -0
- package/lib/components/widgets/PasswordWidget.js +12 -0
- package/lib/components/widgets/PasswordWidget.js.map +1 -0
- package/lib/components/widgets/RadioWidget.d.ts +9 -0
- package/lib/components/widgets/RadioWidget.js +24 -0
- package/lib/components/widgets/RadioWidget.js.map +1 -0
- package/lib/components/widgets/RangeWidget.d.ts +8 -0
- package/lib/components/widgets/RangeWidget.js +11 -0
- package/lib/components/widgets/RangeWidget.js.map +1 -0
- package/lib/components/widgets/SelectWidget.d.ts +9 -0
- package/lib/components/widgets/SelectWidget.js +41 -0
- package/lib/components/widgets/SelectWidget.js.map +1 -0
- package/lib/components/widgets/TextWidget.d.ts +7 -0
- package/lib/components/widgets/TextWidget.js +12 -0
- package/lib/components/widgets/TextWidget.js.map +1 -0
- package/lib/components/widgets/TextareaWidget.d.ts +14 -0
- package/lib/components/widgets/TextareaWidget.js +19 -0
- package/lib/components/widgets/TextareaWidget.js.map +1 -0
- package/lib/components/widgets/TimeWidget.d.ts +8 -0
- package/lib/components/widgets/TimeWidget.js +15 -0
- package/lib/components/widgets/TimeWidget.js.map +1 -0
- package/lib/components/widgets/URLWidget.d.ts +7 -0
- package/lib/components/widgets/URLWidget.js +12 -0
- package/lib/components/widgets/URLWidget.js.map +1 -0
- package/lib/components/widgets/UpDownWidget.d.ts +7 -0
- package/lib/components/widgets/UpDownWidget.js +12 -0
- package/lib/components/widgets/UpDownWidget.js.map +1 -0
- package/lib/components/widgets/index.d.ts +3 -0
- package/lib/components/widgets/index.js +44 -0
- package/lib/components/widgets/index.js.map +1 -0
- package/lib/getDefaultRegistry.d.ts +6 -0
- package/lib/getDefaultRegistry.js +19 -0
- package/lib/getDefaultRegistry.js.map +1 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -0
- package/lib/withTheme.d.ts +9 -0
- package/lib/withTheme.js +16 -0
- package/lib/withTheme.js.map +1 -0
- package/package.json +23 -16
- package/src/components/Form.tsx +853 -0
- package/src/components/fields/ArrayField.tsx +875 -0
- package/src/components/fields/BooleanField.tsx +114 -0
- package/src/components/fields/MultiSchemaField.tsx +221 -0
- package/src/components/fields/NullField.tsx +22 -0
- package/src/components/fields/NumberField.tsx +86 -0
- package/src/components/fields/ObjectField.tsx +331 -0
- package/src/components/fields/SchemaField.tsx +360 -0
- package/src/components/fields/StringField.tsx +71 -0
- package/src/components/fields/index.ts +31 -0
- package/src/components/templates/ArrayFieldDescriptionTemplate.tsx +41 -0
- package/src/components/templates/ArrayFieldItemTemplate.tsx +90 -0
- package/src/components/templates/ArrayFieldTemplate.tsx +88 -0
- package/src/components/templates/ArrayFieldTitleTemplate.tsx +43 -0
- package/src/components/templates/BaseInputTemplate.tsx +102 -0
- package/src/components/templates/ButtonTemplates/AddButton.tsx +29 -0
- package/src/components/templates/ButtonTemplates/IconButton.tsx +77 -0
- package/src/components/templates/ButtonTemplates/SubmitButton.tsx +21 -0
- package/src/components/templates/ButtonTemplates/index.ts +22 -0
- package/src/components/templates/DescriptionField.tsx +29 -0
- package/src/components/templates/ErrorList.tsx +35 -0
- package/src/components/templates/FieldErrorTemplate.tsx +33 -0
- package/src/components/templates/FieldHelpTemplate.tsx +29 -0
- package/src/components/templates/FieldTemplate/FieldTemplate.tsx +41 -0
- package/src/components/templates/FieldTemplate/Label.tsx +27 -0
- package/src/components/templates/FieldTemplate/index.ts +3 -0
- package/src/components/templates/ObjectFieldTemplate.tsx +83 -0
- package/src/components/templates/TitleField.tsx +19 -0
- package/src/components/templates/UnsupportedField.tsx +37 -0
- package/src/components/templates/WrapIfAdditionalTemplate.tsx +80 -0
- package/src/components/templates/index.ts +43 -0
- package/src/components/widgets/AltDateTimeWidget.tsx +16 -0
- package/src/components/widgets/AltDateWidget.tsx +198 -0
- package/src/components/widgets/CheckboxWidget.tsx +92 -0
- package/src/components/widgets/CheckboxesWidget.tsx +92 -0
- package/src/components/widgets/ColorWidget.tsx +14 -0
- package/src/components/widgets/DateTimeWidget.tsx +31 -0
- package/src/components/widgets/DateWidget.tsx +17 -0
- package/src/components/widgets/EmailWidget.tsx +13 -0
- package/src/components/widgets/FileWidget.tsx +178 -0
- package/src/components/widgets/HiddenWidget.tsx +15 -0
- package/src/components/widgets/PasswordWidget.tsx +15 -0
- package/src/components/widgets/RadioWidget.tsx +88 -0
- package/src/components/widgets/RangeWidget.tsx +23 -0
- package/src/components/widgets/SelectWidget.tsx +100 -0
- package/src/components/widgets/TextWidget.tsx +13 -0
- package/src/components/widgets/TextareaWidget.tsx +61 -0
- package/src/components/widgets/TimeWidget.tsx +17 -0
- package/src/components/widgets/URLWidget.tsx +13 -0
- package/src/components/widgets/UpDownWidget.tsx +13 -0
- package/src/components/widgets/index.ts +51 -0
- package/src/getDefaultRegistry.ts +24 -0
- package/src/index.ts +8 -0
- package/src/withTheme.tsx +42 -0
- package/dist/core.cjs.development.js +0 -4403
- package/dist/core.cjs.development.js.map +0 -1
- package/dist/core.cjs.production.min.js +0 -2
- package/dist/core.cjs.production.min.js.map +0 -1
- package/dist/core.esm.js +0 -4383
- package/dist/core.esm.js.map +0 -1
- package/dist/core.umd.development.js +0 -4393
- package/dist/core.umd.development.js.map +0 -1
- package/dist/core.umd.production.min.js +0 -2
- package/dist/core.umd.production.min.js.map +0 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { getWidget, getUiOptions, optionsList, TranslatableString, } from '@rjsf/utils';
|
|
4
|
+
import isObject from 'lodash/isObject';
|
|
5
|
+
/** The `BooleanField` component is used to render a field in the schema is boolean. It constructs `enumOptions` for the
|
|
6
|
+
* two boolean values based on the various alternatives in the schema.
|
|
7
|
+
*
|
|
8
|
+
* @param props - The `FieldProps` for this template
|
|
9
|
+
*/
|
|
10
|
+
function BooleanField(props) {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
const { schema, name, uiSchema, idSchema, formData, registry, required, disabled, readonly, autofocus, onChange, onFocus, onBlur, rawErrors, } = props;
|
|
13
|
+
const { title } = schema;
|
|
14
|
+
const { widgets, formContext, translateString, globalUiOptions } = registry;
|
|
15
|
+
const _c = getUiOptions(uiSchema, globalUiOptions), { widget = 'checkbox', title: uiTitle,
|
|
16
|
+
// Unlike the other fields, don't use `getDisplayLabel()` since it always returns false for the boolean type
|
|
17
|
+
label: displayLabel = true } = _c, options = __rest(_c, ["widget", "title", "label"]);
|
|
18
|
+
const Widget = getWidget(schema, widget, widgets);
|
|
19
|
+
const yes = translateString(TranslatableString.YesLabel);
|
|
20
|
+
const no = translateString(TranslatableString.NoLabel);
|
|
21
|
+
let enumOptions;
|
|
22
|
+
const label = (_a = uiTitle !== null && uiTitle !== void 0 ? uiTitle : title) !== null && _a !== void 0 ? _a : name;
|
|
23
|
+
if (Array.isArray(schema.oneOf)) {
|
|
24
|
+
enumOptions = optionsList({
|
|
25
|
+
oneOf: schema.oneOf
|
|
26
|
+
.map((option) => {
|
|
27
|
+
if (isObject(option)) {
|
|
28
|
+
return Object.assign(Object.assign({}, option), { title: option.title || (option.const === true ? yes : no) });
|
|
29
|
+
}
|
|
30
|
+
return undefined;
|
|
31
|
+
})
|
|
32
|
+
.filter((o) => o), // cast away the error that typescript can't grok is fixed
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
// We deprecated enumNames in v5. It's intentionally omitted from RSJFSchema type, so we need to cast here.
|
|
37
|
+
const schemaWithEnumNames = schema;
|
|
38
|
+
const enums = (_b = schema.enum) !== null && _b !== void 0 ? _b : [true, false];
|
|
39
|
+
if (!schemaWithEnumNames.enumNames && enums.length === 2 && enums.every((v) => typeof v === 'boolean')) {
|
|
40
|
+
enumOptions = [
|
|
41
|
+
{
|
|
42
|
+
value: enums[0],
|
|
43
|
+
label: enums[0] ? yes : no,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
value: enums[1],
|
|
47
|
+
label: enums[1] ? yes : no,
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
enumOptions = optionsList({
|
|
53
|
+
enum: enums,
|
|
54
|
+
// NOTE: enumNames is deprecated, but still supported for now.
|
|
55
|
+
enumNames: schemaWithEnumNames.enumNames,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return (_jsx(Widget, { options: Object.assign(Object.assign({}, options), { enumOptions }), schema: schema, uiSchema: uiSchema, id: idSchema.$id, name: name, onChange: onChange, onFocus: onFocus, onBlur: onBlur, label: label, hideLabel: !displayLabel, value: formData, required: required, disabled: disabled, readonly: readonly, registry: registry, formContext: formContext, autofocus: autofocus, rawErrors: rawErrors }));
|
|
60
|
+
}
|
|
61
|
+
export default BooleanField;
|
|
62
|
+
//# sourceMappingURL=BooleanField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BooleanField.js","sourceRoot":"","sources":["../../../src/components/fields/BooleanField.tsx"],"names":[],"mappings":";;AAAA,OAAO,EACL,SAAS,EACT,YAAY,EACZ,WAAW,EAMX,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AAEvC;;;;GAIG;AACH,SAAS,YAAY,CACnB,KAA0B;;IAE1B,MAAM,EACJ,MAAM,EACN,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,OAAO,EACP,MAAM,EACN,SAAS,GACV,GAAG,KAAK,CAAC;IACV,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IACzB,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,eAAe,EAAE,GAAG,QAAQ,CAAC;IAC5E,MAAM,KAMF,YAAY,CAAU,QAAQ,EAAE,eAAe,CAAC,EAN9C,EACJ,MAAM,GAAG,UAAU,EACnB,KAAK,EAAE,OAAO;IACd,4GAA4G;IAC5G,KAAK,EAAE,YAAY,GAAG,IAAI,OAEwB,EAD/C,OAAO,cALN,4BAML,CAAmD,CAAC;IACrD,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAClD,MAAM,GAAG,GAAG,eAAe,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IACzD,MAAM,EAAE,GAAG,eAAe,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACvD,IAAI,WAA6C,CAAC;IAClD,MAAM,KAAK,GAAG,MAAA,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,KAA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AAI;gBAC3B,IAAI,EAAE,KAAK;gBACX,8DAA8D;gBAC9D,SAAS,EAAE,mBAAmB,CAAC,SAAS;aACzB,CAAC,CAAC;SACpB;KACF;IAED,OAAO,CACL,KAAC,MAAM,IACL,OAAO,kCAAO,OAAO,KAAE,WAAW,KAClC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,EAAE,EAAE,QAAQ,CAAC,GAAG,EAChB,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,CAAC,YAAY,EACxB,KAAK,EAAE,QAAQ,EACf,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,SAAS,GACpB,CACH,CAAC;AACJ,CAAC;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Component } from 'react';
|
|
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
|
+
};
|
|
10
|
+
/** The `AnyOfField` component is used to render a field in the schema that is an `anyOf`, `allOf` or `oneOf`. It tracks
|
|
11
|
+
* the currently selected option and cleans up any irrelevant data in `formData`.
|
|
12
|
+
*
|
|
13
|
+
* @param props - The `FieldProps` for this template
|
|
14
|
+
*/
|
|
15
|
+
declare class AnyOfField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> extends Component<FieldProps<T, S, F>, AnyOfFieldState<S>> {
|
|
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(): JSX.Element;
|
|
46
|
+
}
|
|
47
|
+
export default AnyOfField;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Component } from 'react';
|
|
4
|
+
import get from 'lodash/get';
|
|
5
|
+
import isEmpty from 'lodash/isEmpty';
|
|
6
|
+
import omit from 'lodash/omit';
|
|
7
|
+
import unset from 'lodash/unset';
|
|
8
|
+
import { ADDITIONAL_PROPERTY_FLAG, deepEquals, ERRORS_KEY, getDiscriminatorFieldFromSchema, getUiOptions, getWidget, mergeSchemas, TranslatableString, } from '@rjsf/utils';
|
|
9
|
+
/** The `AnyOfField` component is used to render a field in the schema that is an `anyOf`, `allOf` or `oneOf`. It tracks
|
|
10
|
+
* the currently selected option and cleans up any irrelevant data in `formData`.
|
|
11
|
+
*
|
|
12
|
+
* @param props - The `FieldProps` for this template
|
|
13
|
+
*/
|
|
14
|
+
class AnyOfField extends Component {
|
|
15
|
+
/** Constructs an `AnyOfField` with the given `props` to initialize the initially selected option in state
|
|
16
|
+
*
|
|
17
|
+
* @param props - The `FieldProps` for this template
|
|
18
|
+
*/
|
|
19
|
+
constructor(props) {
|
|
20
|
+
super(props);
|
|
21
|
+
/** Callback handler to remember what the currently selected option is. In addition to that the `formData` is updated
|
|
22
|
+
* to remove properties that are not part of the newly selected option schema, and then the updated data is passed to
|
|
23
|
+
* the `onChange` handler.
|
|
24
|
+
*
|
|
25
|
+
* @param option - The new option value being selected
|
|
26
|
+
*/
|
|
27
|
+
this.onOptionChange = (option) => {
|
|
28
|
+
const { selectedOption, retrievedOptions } = this.state;
|
|
29
|
+
const { formData, onChange, registry } = this.props;
|
|
30
|
+
const { schemaUtils } = registry;
|
|
31
|
+
const intOption = option !== undefined ? parseInt(option, 10) : -1;
|
|
32
|
+
if (intOption === selectedOption) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const newOption = intOption >= 0 ? retrievedOptions[intOption] : undefined;
|
|
36
|
+
const oldOption = selectedOption >= 0 ? retrievedOptions[selectedOption] : undefined;
|
|
37
|
+
let newFormData = schemaUtils.sanitizeDataForNewSchema(newOption, oldOption, formData);
|
|
38
|
+
if (newFormData && newOption) {
|
|
39
|
+
// Call getDefaultFormState to make sure defaults are populated on change. Pass "excludeObjectChildren"
|
|
40
|
+
// so that only the root objects themselves are created without adding undefined children properties
|
|
41
|
+
newFormData = schemaUtils.getDefaultFormState(newOption, newFormData, 'excludeObjectChildren');
|
|
42
|
+
}
|
|
43
|
+
onChange(newFormData, undefined, this.getFieldId());
|
|
44
|
+
this.setState({ selectedOption: intOption });
|
|
45
|
+
};
|
|
46
|
+
const { formData, options, registry: { schemaUtils }, } = this.props;
|
|
47
|
+
// cache the retrieved options in state in case they have $refs to save doing it later
|
|
48
|
+
const retrievedOptions = options.map((opt) => schemaUtils.retrieveSchema(opt, formData));
|
|
49
|
+
this.state = {
|
|
50
|
+
retrievedOptions,
|
|
51
|
+
selectedOption: this.getMatchingOption(0, formData, retrievedOptions),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** React lifecycle method that is called when the props and/or state for this component is updated. It recomputes the
|
|
55
|
+
* currently selected option based on the overall `formData`
|
|
56
|
+
*
|
|
57
|
+
* @param prevProps - The previous `FieldProps` for this template
|
|
58
|
+
* @param prevState - The previous `AnyOfFieldState` for this template
|
|
59
|
+
*/
|
|
60
|
+
componentDidUpdate(prevProps, prevState) {
|
|
61
|
+
const { formData, options, idSchema } = this.props;
|
|
62
|
+
const { selectedOption } = this.state;
|
|
63
|
+
let newState = this.state;
|
|
64
|
+
if (!deepEquals(prevProps.options, options)) {
|
|
65
|
+
const { registry: { schemaUtils }, } = this.props;
|
|
66
|
+
// re-cache the retrieved options in state in case they have $refs to save doing it later
|
|
67
|
+
const retrievedOptions = options.map((opt) => schemaUtils.retrieveSchema(opt, formData));
|
|
68
|
+
newState = { selectedOption, retrievedOptions };
|
|
69
|
+
}
|
|
70
|
+
if (!deepEquals(formData, prevProps.formData) && idSchema.$id === prevProps.idSchema.$id) {
|
|
71
|
+
const { retrievedOptions } = newState;
|
|
72
|
+
const matchingOption = this.getMatchingOption(selectedOption, formData, retrievedOptions);
|
|
73
|
+
if (prevState && matchingOption !== selectedOption) {
|
|
74
|
+
newState = { selectedOption: matchingOption, retrievedOptions };
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (newState !== this.state) {
|
|
78
|
+
this.setState(newState);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** Determines the best matching option for the given `formData` and `options`.
|
|
82
|
+
*
|
|
83
|
+
* @param formData - The new formData
|
|
84
|
+
* @param options - The list of options to choose from
|
|
85
|
+
* @return - The index of the `option` that best matches the `formData`
|
|
86
|
+
*/
|
|
87
|
+
getMatchingOption(selectedOption, formData, options) {
|
|
88
|
+
const { schema, registry: { schemaUtils }, } = this.props;
|
|
89
|
+
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
90
|
+
const option = schemaUtils.getClosestMatchingOption(formData, options, selectedOption, discriminator);
|
|
91
|
+
return option;
|
|
92
|
+
}
|
|
93
|
+
getFieldId() {
|
|
94
|
+
const { idSchema, schema } = this.props;
|
|
95
|
+
return `${idSchema.$id}${schema.oneOf ? '__oneof_select' : '__anyof_select'}`;
|
|
96
|
+
}
|
|
97
|
+
/** Renders the `AnyOfField` selector along with a `SchemaField` for the value of the `formData`
|
|
98
|
+
*/
|
|
99
|
+
render() {
|
|
100
|
+
const { name, disabled = false, errorSchema = {}, formContext, onBlur, onFocus, registry, schema, uiSchema, } = this.props;
|
|
101
|
+
const { widgets, fields, translateString, globalUiOptions, schemaUtils } = registry;
|
|
102
|
+
const { SchemaField: _SchemaField } = fields;
|
|
103
|
+
const { selectedOption, retrievedOptions } = this.state;
|
|
104
|
+
const _a = getUiOptions(uiSchema, globalUiOptions), { widget = 'select', placeholder, autofocus, autocomplete, title = schema.title } = _a, uiOptions = __rest(_a, ["widget", "placeholder", "autofocus", "autocomplete", "title"]);
|
|
105
|
+
const Widget = getWidget({ type: 'number' }, widget, widgets);
|
|
106
|
+
const rawErrors = get(errorSchema, ERRORS_KEY, []);
|
|
107
|
+
const fieldErrorSchema = omit(errorSchema, [ERRORS_KEY]);
|
|
108
|
+
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
109
|
+
const option = selectedOption >= 0 ? retrievedOptions[selectedOption] || null : null;
|
|
110
|
+
let optionSchema;
|
|
111
|
+
if (option) {
|
|
112
|
+
const { oneOf, anyOf } = schema, remaining = __rest(schema, ["oneOf", "anyOf"]);
|
|
113
|
+
// Merge in all the non-oneOf/anyOf properties and also skip the special ADDITIONAL_PROPERTY_FLAG property
|
|
114
|
+
unset(remaining, ADDITIONAL_PROPERTY_FLAG);
|
|
115
|
+
optionSchema = !isEmpty(remaining) ? mergeSchemas(remaining, option) : option;
|
|
116
|
+
}
|
|
117
|
+
const translateEnum = title
|
|
118
|
+
? TranslatableString.TitleOptionPrefix
|
|
119
|
+
: TranslatableString.OptionPrefix;
|
|
120
|
+
const translateParams = title ? [title] : [];
|
|
121
|
+
const enumOptions = retrievedOptions.map((opt, index) => ({
|
|
122
|
+
label: opt.title || translateString(translateEnum, translateParams.concat(String(index + 1))),
|
|
123
|
+
value: index,
|
|
124
|
+
}));
|
|
125
|
+
return (_jsxs("div", Object.assign({ className: 'panel panel-default panel-body' }, { children: [_jsx("div", Object.assign({ className: 'form-group' }, { children: _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: Object.assign({ enumOptions }, uiOptions), registry: registry, formContext: formContext, placeholder: placeholder, autocomplete: autocomplete, autofocus: autofocus, label: title !== null && title !== void 0 ? title : name, hideLabel: !displayLabel }) })), option !== null && _jsx(_SchemaField, Object.assign({}, this.props, { schema: optionSchema }))] })));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
export default AnyOfField;
|
|
129
|
+
//# sourceMappingURL=MultiSchemaField.js.map
|
|
@@ -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EAC3C,QAAQ,EAAE,IAAI,CAAC,cAAc,EAC7B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,QAAQ,IAAI,OAAO,CAAC,WAAW,CAAC,EAC1C,QAAQ,EAAE,KAAK,EACf,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,gBAAgB,EAC7B,KAAK,EAAE,cAAc,IAAI,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,EACvD,OAAO,kBAAI,WAAW,IAAK,SAAS,GACpC,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,IAAI,EACpB,SAAS,EAAE,CAAC,YAAY,GACxB,IACE,EACL,MAAM,KAAK,IAAI,IAAI,KAAC,YAAY,oBAAK,IAAI,CAAC,KAAK,IAAE,MAAM,EAAE,YAAa,IAAI,KACvE,CACP,CAAC;IACJ,CAAC;CACF;AAED,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
/** The `NullField` component is used to render a field in the schema is null. It also ensures that the `formData` is
|
|
3
|
+
* also set to null if it has no value.
|
|
4
|
+
*
|
|
5
|
+
* @param props - The `FieldProps` for this template
|
|
6
|
+
*/
|
|
7
|
+
declare function NullField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(props: FieldProps<T, S, F>): null;
|
|
8
|
+
export default NullField;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
/** The `NullField` component is used to render a field in the schema is null. It also ensures that the `formData` is
|
|
3
|
+
* also set to null if it has no value.
|
|
4
|
+
*
|
|
5
|
+
* @param props - The `FieldProps` for this template
|
|
6
|
+
*/
|
|
7
|
+
function NullField(props) {
|
|
8
|
+
const { formData, onChange } = props;
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (formData === undefined) {
|
|
11
|
+
onChange(null);
|
|
12
|
+
}
|
|
13
|
+
}, [formData, onChange]);
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
export default NullField;
|
|
17
|
+
//# sourceMappingURL=NullField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NullField.js","sourceRoot":"","sources":["../../../src/components/fields/NullField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGlC;;;;GAIG;AACH,SAAS,SAAS,CAChB,KAA0B;IAE1B,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IACrC,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,QAAQ,KAAK,SAAS,EAAE;YAC1B,QAAQ,CAAC,IAAoB,CAAC,CAAC;SAChC;IACH,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;IAEzB,OAAO,IAAI,CAAC;AACd,CAAC;AAED,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { FieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
3
|
+
/**
|
|
4
|
+
* The NumberField class has some special handling for dealing with trailing
|
|
5
|
+
* decimal points and/or zeroes. This logic is designed to allow trailing values
|
|
6
|
+
* to be visible in the input element, but not be represented in the
|
|
7
|
+
* corresponding form data.
|
|
8
|
+
*
|
|
9
|
+
* The algorithm is as follows:
|
|
10
|
+
*
|
|
11
|
+
* 1. When the input value changes the value is cached in the component state
|
|
12
|
+
*
|
|
13
|
+
* 2. The value is then normalized, removing trailing decimal points and zeros,
|
|
14
|
+
* then passed to the "onChange" callback
|
|
15
|
+
*
|
|
16
|
+
* 3. When the component is rendered, the formData value is checked against the
|
|
17
|
+
* value cached in the state. If it matches the cached value, the cached
|
|
18
|
+
* value is passed to the input instead of the formData value
|
|
19
|
+
*/
|
|
20
|
+
declare function NumberField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(props: FieldProps<T, S, F>): JSX.Element;
|
|
21
|
+
export default NumberField;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useCallback } from 'react';
|
|
3
|
+
import { asNumber } from '@rjsf/utils';
|
|
4
|
+
// Matches a string that ends in a . character, optionally followed by a sequence of
|
|
5
|
+
// digits followed by any number of 0 characters up until the end of the line.
|
|
6
|
+
// Ensuring that there is at least one prefixed character is important so that
|
|
7
|
+
// you don't incorrectly match against "0".
|
|
8
|
+
const trailingCharMatcherWithPrefix = /\.([0-9]*0)*$/;
|
|
9
|
+
// This is used for trimming the trailing 0 and . characters without affecting
|
|
10
|
+
// the rest of the string. Its possible to use one RegEx with groups for this
|
|
11
|
+
// functionality, but it is fairly complex compared to simply defining two
|
|
12
|
+
// different matchers.
|
|
13
|
+
const trailingCharMatcher = /[0.]0*$/;
|
|
14
|
+
/**
|
|
15
|
+
* The NumberField class has some special handling for dealing with trailing
|
|
16
|
+
* decimal points and/or zeroes. This logic is designed to allow trailing values
|
|
17
|
+
* to be visible in the input element, but not be represented in the
|
|
18
|
+
* corresponding form data.
|
|
19
|
+
*
|
|
20
|
+
* The algorithm is as follows:
|
|
21
|
+
*
|
|
22
|
+
* 1. When the input value changes the value is cached in the component state
|
|
23
|
+
*
|
|
24
|
+
* 2. The value is then normalized, removing trailing decimal points and zeros,
|
|
25
|
+
* then passed to the "onChange" callback
|
|
26
|
+
*
|
|
27
|
+
* 3. When the component is rendered, the formData value is checked against the
|
|
28
|
+
* value cached in the state. If it matches the cached value, the cached
|
|
29
|
+
* value is passed to the input instead of the formData value
|
|
30
|
+
*/
|
|
31
|
+
function NumberField(props) {
|
|
32
|
+
const { registry, onChange, formData, value: initialValue } = props;
|
|
33
|
+
const [lastValue, setLastValue] = useState(initialValue);
|
|
34
|
+
const { StringField } = registry.fields;
|
|
35
|
+
let value = formData;
|
|
36
|
+
/** Handle the change from the `StringField` to properly convert to a number
|
|
37
|
+
*
|
|
38
|
+
* @param value - The current value for the change occurring
|
|
39
|
+
*/
|
|
40
|
+
const handleChange = useCallback((value) => {
|
|
41
|
+
// Cache the original value in component state
|
|
42
|
+
setLastValue(value);
|
|
43
|
+
// Normalize decimals that don't start with a zero character in advance so
|
|
44
|
+
// that the rest of the normalization logic is simpler
|
|
45
|
+
if (`${value}`.charAt(0) === '.') {
|
|
46
|
+
value = `0${value}`;
|
|
47
|
+
}
|
|
48
|
+
// Check that the value is a string (this can happen if the widget used is a
|
|
49
|
+
// <select>, due to an enum declaration etc) then, if the value ends in a
|
|
50
|
+
// trailing decimal point or multiple zeroes, strip the trailing values
|
|
51
|
+
const processed = typeof value === 'string' && value.match(trailingCharMatcherWithPrefix)
|
|
52
|
+
? asNumber(value.replace(trailingCharMatcher, ''))
|
|
53
|
+
: asNumber(value);
|
|
54
|
+
onChange(processed);
|
|
55
|
+
}, [onChange]);
|
|
56
|
+
if (typeof lastValue === 'string' && typeof value === 'number') {
|
|
57
|
+
// Construct a regular expression that checks for a string that consists
|
|
58
|
+
// of the formData value suffixed with zero or one '.' characters and zero
|
|
59
|
+
// or more '0' characters
|
|
60
|
+
const re = new RegExp(`${value}`.replace('.', '\\.') + '\\.?0*$');
|
|
61
|
+
// If the cached "lastValue" is a match, use that instead of the formData
|
|
62
|
+
// value to prevent the input value from changing in the UI
|
|
63
|
+
if (lastValue.match(re)) {
|
|
64
|
+
value = lastValue;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return _jsx(StringField, Object.assign({}, props, { formData: value, onChange: handleChange }));
|
|
68
|
+
}
|
|
69
|
+
export default NumberField;
|
|
70
|
+
//# sour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AAC,KAAK,CAAC,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;YAClD,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAEtB,QAAQ,CAAC,SAAyB,CAAC,CAAC;IACtC,CAAC,EACD,CAAC,QAAQ,CAAC,CACX,CAAC;IAEF,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC9D,wEAAwE;QACxE,0EAA0E;QAC1E,yBAAyB;QACzB,MAAM,EAAE,GAAG,IAAI,MAAM,CAAC,GAAG,KAAK,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,SAAS,CAAC,CAAC;QAElE,yEAAyE;QACzE,2DAA2D;QAC3D,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE;YACvB,KAAK,GAAG,SAAyB,CAAC;SACnC;KACF;IAED,OAAO,KAAC,WAAW,oBAAK,KAAK,IAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,IAAI,CAAC;AAC7E,CAAC;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Component } from 'react';
|
|
2
|
+
import { ErrorSchema, 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
|
+
};
|
|
10
|
+
/** The `ObjectField` component is used to render a field in the schema that is of type `object`. It tracks whether an
|
|
11
|
+
* additional property key was modified and what it was modified to
|
|
12
|
+
*
|
|
13
|
+
* @param props - The `FieldProps` for this template
|
|
14
|
+
*/
|
|
15
|
+
declare class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> extends Component<FieldProps<T, S, F>, ObjectFieldState> {
|
|
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, 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, newErrorSchema: ErrorSchema<T>) => 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(): JSX.Element;
|
|
72
|
+
}
|
|
73
|
+
export default ObjectField;
|