@rjsf/core 6.0.0 → 6.0.2
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 +78 -53
- package/dist/index.cjs +77 -50
- package/dist/index.cjs.map +4 -4
- package/dist/index.esm.js +82 -55
- package/dist/index.esm.js.map +4 -4
- package/lib/components/Form.d.ts.map +1 -1
- package/lib/components/Form.js +7 -3
- package/lib/components/constants.d.ts +5 -0
- package/lib/components/constants.d.ts.map +1 -0
- package/lib/components/constants.js +4 -0
- package/lib/components/fields/ArrayField.d.ts.map +1 -1
- package/lib/components/fields/ArrayField.js +33 -16
- package/lib/components/fields/FallbackField.d.ts.map +1 -1
- package/lib/components/fields/FallbackField.js +11 -3
- package/lib/components/fields/ObjectField.d.ts.map +1 -1
- package/lib/components/fields/ObjectField.js +7 -9
- package/lib/components/templates/FieldTemplate/FieldTemplate.d.ts.map +1 -1
- package/lib/components/templates/FieldTemplate/FieldTemplate.js +2 -1
- package/lib/components/widgets/CheckboxWidget.d.ts.map +1 -1
- package/lib/components/widgets/CheckboxWidget.js +4 -2
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/src/components/Form.tsx +6 -4
- package/src/components/constants.ts +5 -0
- package/src/components/fields/ArrayField.tsx +45 -29
- package/src/components/fields/FallbackField.tsx +18 -10
- package/src/components/fields/ObjectField.tsx +7 -12
- package/src/components/templates/FieldTemplate/FieldTemplate.tsx +2 -1
- package/src/components/widgets/CheckboxWidget.tsx +4 -1
package/dist/index.esm.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
ErrorSchemaBuilder,
|
|
7
7
|
getChangedFields,
|
|
8
8
|
getTemplate as getTemplate28,
|
|
9
|
-
getUiOptions as
|
|
9
|
+
getUiOptions as getUiOptions20,
|
|
10
10
|
isObject as isObject6,
|
|
11
11
|
mergeObjects,
|
|
12
12
|
NAME_KEY,
|
|
@@ -29,6 +29,7 @@ import _isEmpty from "lodash/isEmpty";
|
|
|
29
29
|
import _pick from "lodash/pick";
|
|
30
30
|
import _set from "lodash/set";
|
|
31
31
|
import _toPath from "lodash/toPath";
|
|
32
|
+
import _unset from "lodash/unset";
|
|
32
33
|
|
|
33
34
|
// src/getDefaultRegistry.ts
|
|
34
35
|
import {
|
|
@@ -109,9 +110,11 @@ function computeItemUiSchema(uiSchema, item, index, formContext) {
|
|
|
109
110
|
}
|
|
110
111
|
}
|
|
111
112
|
function getNewFormDataRow(registry, schema) {
|
|
112
|
-
const { schemaUtils } = registry;
|
|
113
|
+
const { schemaUtils, globalFormOptions } = registry;
|
|
113
114
|
let itemSchema = schema.items;
|
|
114
|
-
if (
|
|
115
|
+
if (globalFormOptions.useFallbackUiForUnsupportedType && !itemSchema) {
|
|
116
|
+
itemSchema = {};
|
|
117
|
+
} else if (isFixedItems(schema) && allowAdditionalItems(schema)) {
|
|
115
118
|
itemSchema = schema.additionalItems;
|
|
116
119
|
}
|
|
117
120
|
return schemaUtils.getDefaultFormState(itemSchema);
|
|
@@ -646,7 +649,7 @@ function useKeyedFormData(formData = []) {
|
|
|
646
649
|
}
|
|
647
650
|
function ArrayField(props) {
|
|
648
651
|
const { schema, uiSchema, errorSchema, fieldPathId, registry, formData, onChange } = props;
|
|
649
|
-
const { schemaUtils, translateString } = registry;
|
|
652
|
+
const { globalFormOptions, schemaUtils, translateString } = registry;
|
|
650
653
|
const { keyedFormData, updateKeyedFormData } = useKeyedFormData(formData);
|
|
651
654
|
const childFieldPathId = props.childFieldPathId ?? fieldPathId;
|
|
652
655
|
const handleAddItem = useCallback(
|
|
@@ -783,24 +786,14 @@ function ArrayField(props) {
|
|
|
783
786
|
},
|
|
784
787
|
[onChange, childFieldPathId]
|
|
785
788
|
);
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
);
|
|
793
|
-
return /* @__PURE__ */ jsx(
|
|
794
|
-
UnsupportedFieldTemplate,
|
|
795
|
-
{
|
|
796
|
-
schema,
|
|
797
|
-
fieldPathId,
|
|
798
|
-
reason: translateString(TranslatableString.MissingItems),
|
|
799
|
-
registry
|
|
800
|
-
}
|
|
801
|
-
);
|
|
802
|
-
}
|
|
789
|
+
const arrayAsMultiProps = {
|
|
790
|
+
...props,
|
|
791
|
+
formData,
|
|
792
|
+
fieldPathId: childFieldPathId,
|
|
793
|
+
onSelectChange
|
|
794
|
+
};
|
|
803
795
|
const arrayProps = {
|
|
796
|
+
...props,
|
|
804
797
|
handleAddItem,
|
|
805
798
|
handleCopyItem,
|
|
806
799
|
handleRemoveItem,
|
|
@@ -808,19 +801,41 @@ function ArrayField(props) {
|
|
|
808
801
|
keyedFormData,
|
|
809
802
|
onChange: handleChange
|
|
810
803
|
};
|
|
811
|
-
if (
|
|
812
|
-
|
|
804
|
+
if (!(ITEMS_KEY in schema)) {
|
|
805
|
+
if (!globalFormOptions.useFallbackUiForUnsupportedType) {
|
|
806
|
+
const uiOptions = getUiOptions(uiSchema);
|
|
807
|
+
const UnsupportedFieldTemplate = getTemplate(
|
|
808
|
+
"UnsupportedFieldTemplate",
|
|
809
|
+
registry,
|
|
810
|
+
uiOptions
|
|
811
|
+
);
|
|
812
|
+
return /* @__PURE__ */ jsx(
|
|
813
|
+
UnsupportedFieldTemplate,
|
|
814
|
+
{
|
|
815
|
+
schema,
|
|
816
|
+
fieldPathId,
|
|
817
|
+
reason: translateString(TranslatableString.MissingItems),
|
|
818
|
+
registry
|
|
819
|
+
}
|
|
820
|
+
);
|
|
821
|
+
}
|
|
822
|
+
const fallbackSchema = { ...schema, [ITEMS_KEY]: { type: void 0 } };
|
|
823
|
+
arrayAsMultiProps.schema = fallbackSchema;
|
|
824
|
+
arrayProps.schema = fallbackSchema;
|
|
825
|
+
}
|
|
826
|
+
if (schemaUtils.isMultiSelect(arrayAsMultiProps.schema)) {
|
|
827
|
+
return /* @__PURE__ */ jsx(ArrayAsMultiSelect, { ...arrayAsMultiProps });
|
|
813
828
|
}
|
|
814
829
|
if (isCustomWidget(uiSchema)) {
|
|
815
|
-
return /* @__PURE__ */ jsx(ArrayAsCustomWidget, { ...
|
|
830
|
+
return /* @__PURE__ */ jsx(ArrayAsCustomWidget, { ...arrayAsMultiProps });
|
|
816
831
|
}
|
|
817
|
-
if (isFixedItems(schema)) {
|
|
818
|
-
return /* @__PURE__ */ jsx(FixedArray, { ...
|
|
832
|
+
if (isFixedItems(arrayAsMultiProps.schema)) {
|
|
833
|
+
return /* @__PURE__ */ jsx(FixedArray, { ...arrayProps });
|
|
819
834
|
}
|
|
820
|
-
if (schemaUtils.isFilesArray(schema, uiSchema)) {
|
|
821
|
-
return /* @__PURE__ */ jsx(ArrayAsFiles, { ...
|
|
835
|
+
if (schemaUtils.isFilesArray(arrayAsMultiProps.schema, uiSchema)) {
|
|
836
|
+
return /* @__PURE__ */ jsx(ArrayAsFiles, { ...arrayAsMultiProps });
|
|
822
837
|
}
|
|
823
|
-
return /* @__PURE__ */ jsx(NormalArray, { ...
|
|
838
|
+
return /* @__PURE__ */ jsx(NormalArray, { ...arrayProps });
|
|
824
839
|
}
|
|
825
840
|
|
|
826
841
|
// src/components/fields/BooleanField.tsx
|
|
@@ -947,7 +962,7 @@ import { jsx as jsx3 } from "react/jsx-runtime";
|
|
|
947
962
|
function getFallbackTypeSelectionSchema(title) {
|
|
948
963
|
return {
|
|
949
964
|
type: "string",
|
|
950
|
-
enum: ["string", "number", "boolean"],
|
|
965
|
+
enum: ["string", "number", "boolean", "object", "array"],
|
|
951
966
|
default: "string",
|
|
952
967
|
title
|
|
953
968
|
};
|
|
@@ -957,6 +972,9 @@ function getTypeOfFormData(formData) {
|
|
|
957
972
|
if (dataType === "string" || dataType === "number" || dataType === "boolean") {
|
|
958
973
|
return dataType;
|
|
959
974
|
}
|
|
975
|
+
if (dataType === "object") {
|
|
976
|
+
return Array.isArray(formData) ? "array" : "object";
|
|
977
|
+
}
|
|
960
978
|
return "string";
|
|
961
979
|
}
|
|
962
980
|
function castToNewType(formData, newType) {
|
|
@@ -1006,20 +1024,13 @@ function FallbackField(props) {
|
|
|
1006
1024
|
}
|
|
1007
1025
|
};
|
|
1008
1026
|
if (!globalFormOptions.useFallbackUiForUnsupportedType) {
|
|
1027
|
+
const { reason = translateString(TranslatableString3.UnknownFieldType, [String(schema.type)]) } = props;
|
|
1009
1028
|
const UnsupportedFieldTemplate = getTemplate2(
|
|
1010
1029
|
"UnsupportedFieldTemplate",
|
|
1011
1030
|
registry,
|
|
1012
1031
|
uiOptions
|
|
1013
1032
|
);
|
|
1014
|
-
return /* @__PURE__ */ jsx3(
|
|
1015
|
-
UnsupportedFieldTemplate,
|
|
1016
|
-
{
|
|
1017
|
-
schema,
|
|
1018
|
-
fieldPathId,
|
|
1019
|
-
reason: translateString(TranslatableString3.UnknownFieldType, [String(schema.type)]),
|
|
1020
|
-
registry
|
|
1021
|
-
}
|
|
1022
|
-
);
|
|
1033
|
+
return /* @__PURE__ */ jsx3(UnsupportedFieldTemplate, { schema, fieldPathId, reason, registry });
|
|
1023
1034
|
}
|
|
1024
1035
|
const FallbackFieldTemplate2 = getTemplate2(
|
|
1025
1036
|
"FallbackFieldTemplate",
|
|
@@ -1050,7 +1061,17 @@ function FallbackField(props) {
|
|
|
1050
1061
|
},
|
|
1051
1062
|
formData ? hashObject2(formData) : "__empty__"
|
|
1052
1063
|
),
|
|
1053
|
-
schemaField: /* @__PURE__ */ jsx3(
|
|
1064
|
+
schemaField: /* @__PURE__ */ jsx3(
|
|
1065
|
+
SchemaField2,
|
|
1066
|
+
{
|
|
1067
|
+
...props,
|
|
1068
|
+
schema: {
|
|
1069
|
+
type,
|
|
1070
|
+
title: translateString(TranslatableString3.Value),
|
|
1071
|
+
...type === "object" && { additionalProperties: true }
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
)
|
|
1054
1075
|
}
|
|
1055
1076
|
);
|
|
1056
1077
|
}
|
|
@@ -1890,7 +1911,6 @@ import {
|
|
|
1890
1911
|
ANY_OF_KEY as ANY_OF_KEY4,
|
|
1891
1912
|
getTemplate as getTemplate7,
|
|
1892
1913
|
getUiOptions as getUiOptions8,
|
|
1893
|
-
hashObject as hashObject5,
|
|
1894
1914
|
isFormDataAvailable as isFormDataAvailable3,
|
|
1895
1915
|
orderProperties,
|
|
1896
1916
|
shouldRenderOptionalField as shouldRenderOptionalField3,
|
|
@@ -1906,7 +1926,12 @@ import get4 from "lodash/get";
|
|
|
1906
1926
|
import has3 from "lodash/has";
|
|
1907
1927
|
import isObject4 from "lodash/isObject";
|
|
1908
1928
|
import set4 from "lodash/set";
|
|
1909
|
-
|
|
1929
|
+
|
|
1930
|
+
// src/components/constants.ts
|
|
1931
|
+
var ADDITIONAL_PROPERTY_KEY_REMOVE = Symbol("remove-this-key");
|
|
1932
|
+
var IS_RESET = Symbol("reset");
|
|
1933
|
+
|
|
1934
|
+
// src/components/fields/ObjectField.tsx
|
|
1910
1935
|
import { jsx as jsx9, jsxs } from "react/jsx-runtime";
|
|
1911
1936
|
function isRequired(schema, name) {
|
|
1912
1937
|
return Array.isArray(schema.required) && schema.required.indexOf(name) !== -1;
|
|
@@ -2031,7 +2056,6 @@ function ObjectField(props) {
|
|
|
2031
2056
|
const schema = schemaUtils.retrieveSchema(rawSchema, formData, true);
|
|
2032
2057
|
const uiOptions = getUiOptions8(uiSchema, globalUiOptions);
|
|
2033
2058
|
const { properties: schemaProperties = {} } = schema;
|
|
2034
|
-
const formDataHash = hashObject5(formData || {});
|
|
2035
2059
|
const childFieldPathId = props.childFieldPathId ?? fieldPathId;
|
|
2036
2060
|
const templateTitle = uiOptions.title ?? schema.title ?? title ?? name;
|
|
2037
2061
|
const description = uiOptions.description ?? schema.description;
|
|
@@ -2104,11 +2128,9 @@ function ObjectField(props) {
|
|
|
2104
2128
|
);
|
|
2105
2129
|
const handleRemoveProperty = useCallback4(
|
|
2106
2130
|
(key) => {
|
|
2107
|
-
|
|
2108
|
-
unset(copiedFormData, key);
|
|
2109
|
-
onChange(copiedFormData, childFieldPathId.path);
|
|
2131
|
+
onChange(ADDITIONAL_PROPERTY_KEY_REMOVE, [...childFieldPathId.path, key]);
|
|
2110
2132
|
},
|
|
2111
|
-
[onChange, childFieldPathId
|
|
2133
|
+
[onChange, childFieldPathId]
|
|
2112
2134
|
);
|
|
2113
2135
|
if (!renderOptionalField || hasFormData) {
|
|
2114
2136
|
try {
|
|
@@ -2152,7 +2174,7 @@ function ObjectField(props) {
|
|
|
2152
2174
|
readonly,
|
|
2153
2175
|
hideError
|
|
2154
2176
|
},
|
|
2155
|
-
|
|
2177
|
+
name2
|
|
2156
2178
|
);
|
|
2157
2179
|
return {
|
|
2158
2180
|
content,
|
|
@@ -3123,8 +3145,9 @@ function FieldTemplate(props) {
|
|
|
3123
3145
|
if (hidden) {
|
|
3124
3146
|
return /* @__PURE__ */ jsx27("div", { className: "hidden", children });
|
|
3125
3147
|
}
|
|
3148
|
+
const isCheckbox = uiOptions.widget === "checkbox";
|
|
3126
3149
|
return /* @__PURE__ */ jsxs9(WrapIfAdditionalTemplate2, { ...props, children: [
|
|
3127
|
-
displayLabel && /* @__PURE__ */ jsx27(Label, { label, required, id }),
|
|
3150
|
+
displayLabel && !isCheckbox && /* @__PURE__ */ jsx27(Label, { label, required, id }),
|
|
3128
3151
|
displayLabel && description ? description : null,
|
|
3129
3152
|
children,
|
|
3130
3153
|
errors,
|
|
@@ -3471,7 +3494,8 @@ import {
|
|
|
3471
3494
|
descriptionId as descriptionId4,
|
|
3472
3495
|
getTemplate as getTemplate17,
|
|
3473
3496
|
labelValue,
|
|
3474
|
-
schemaRequiresTrueValue
|
|
3497
|
+
schemaRequiresTrueValue,
|
|
3498
|
+
getUiOptions as getUiOptions19
|
|
3475
3499
|
} from "@rjsf/utils";
|
|
3476
3500
|
import { jsx as jsx39, jsxs as jsxs16 } from "react/jsx-runtime";
|
|
3477
3501
|
function CheckboxWidget({
|
|
@@ -3509,7 +3533,9 @@ function CheckboxWidget({
|
|
|
3509
3533
|
(event) => onFocus(id, event.target.checked),
|
|
3510
3534
|
[onFocus, id]
|
|
3511
3535
|
);
|
|
3512
|
-
const
|
|
3536
|
+
const uiOptions = getUiOptions19(uiSchema);
|
|
3537
|
+
const isCheckboxWidget = uiOptions.widget === "checkbox";
|
|
3538
|
+
const description = isCheckboxWidget ? void 0 : options.description ?? schema.description;
|
|
3513
3539
|
return /* @__PURE__ */ jsxs16("div", { className: `checkbox ${disabled || readonly ? "disabled" : ""}`, children: [
|
|
3514
3540
|
!hideLabel && description && /* @__PURE__ */ jsx39(
|
|
3515
3541
|
DescriptionFieldTemplate,
|
|
@@ -4167,7 +4193,6 @@ function getDefaultRegistry() {
|
|
|
4167
4193
|
|
|
4168
4194
|
// src/components/Form.tsx
|
|
4169
4195
|
import { jsx as jsx57, jsxs as jsxs23 } from "react/jsx-runtime";
|
|
4170
|
-
var IS_RESET = Symbol("reset");
|
|
4171
4196
|
function toIChangeEvent(state, status) {
|
|
4172
4197
|
return {
|
|
4173
4198
|
..._pick(state, ["schema", "uiSchema", "fieldPathId", "schemaUtils", "formData", "edit", "errors", "errorSchema"]),
|
|
@@ -4421,7 +4446,7 @@ var Form = class extends Component3 {
|
|
|
4421
4446
|
/** Renders any errors contained in the `state` in using the `ErrorList`, if not disabled by `showErrorList`. */
|
|
4422
4447
|
renderErrors(registry) {
|
|
4423
4448
|
const { errors, errorSchema, schema, uiSchema } = this.state;
|
|
4424
|
-
const options =
|
|
4449
|
+
const options = getUiOptions20(uiSchema);
|
|
4425
4450
|
const ErrorListTemplate = getTemplate28("ErrorListTemplate", registry, options);
|
|
4426
4451
|
if (errors && errors.length) {
|
|
4427
4452
|
return /* @__PURE__ */ jsx57(
|
|
@@ -4599,7 +4624,9 @@ var Form = class extends Component3 {
|
|
|
4599
4624
|
let retrievedSchema = this.state.retrievedSchema;
|
|
4600
4625
|
let formData = isRootPath ? newValue : _cloneDeep(oldFormData);
|
|
4601
4626
|
if (isObject6(formData) || Array.isArray(formData)) {
|
|
4602
|
-
if (
|
|
4627
|
+
if (newValue === ADDITIONAL_PROPERTY_KEY_REMOVE) {
|
|
4628
|
+
_unset(formData, path);
|
|
4629
|
+
} else if (!isRootPath) {
|
|
4603
4630
|
_set(formData, path, newValue);
|
|
4604
4631
|
}
|
|
4605
4632
|
const newState = this.getStateFromProps(this.props, formData, void 0, void 0, void 0, true);
|
|
@@ -4982,7 +5009,7 @@ var Form = class extends Component3 {
|
|
|
4982
5009
|
const { SubmitButton: SubmitButton2 } = registry.templates.ButtonTemplates;
|
|
4983
5010
|
const as = _internalFormWrapper ? tagName : void 0;
|
|
4984
5011
|
const FormTag = _internalFormWrapper || tagName || "form";
|
|
4985
|
-
let { [SUBMIT_BTN_OPTIONS_KEY]: submitOptions = {} } =
|
|
5012
|
+
let { [SUBMIT_BTN_OPTIONS_KEY]: submitOptions = {} } = getUiOptions20(uiSchema);
|
|
4986
5013
|
if (disabled) {
|
|
4987
5014
|
submitOptions = { ...submitOptions, props: { ...submitOptions.props, disabled: true } };
|
|
4988
5015
|
}
|