@rjsf/core 5.18.3 → 5.18.5

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.
Files changed (36) hide show
  1. package/dist/core.umd.js +27 -20
  2. package/dist/index.esm.js +28 -21
  3. package/dist/index.esm.js.map +3 -3
  4. package/dist/index.js +27 -20
  5. package/dist/index.js.map +3 -3
  6. package/lib/components/Form.d.ts +5 -1
  7. package/lib/components/Form.js +4 -4
  8. package/lib/components/Form.js.map +1 -1
  9. package/lib/components/fields/ArrayField.d.ts +2 -2
  10. package/lib/components/fields/NumberField.js +1 -1
  11. package/lib/components/fields/NumberField.js.map +1 -1
  12. package/lib/components/fields/ObjectField.js +5 -2
  13. package/lib/components/fields/ObjectField.js.map +1 -1
  14. package/lib/components/fields/SchemaField.js +4 -3
  15. package/lib/components/fields/SchemaField.js.map +1 -1
  16. package/lib/components/templates/BaseInputTemplate.js +2 -2
  17. package/lib/components/templates/BaseInputTemplate.js.map +1 -1
  18. package/lib/components/templates/WrapIfAdditionalTemplate.js +1 -1
  19. package/lib/components/templates/WrapIfAdditionalTemplate.js.map +1 -1
  20. package/lib/components/widgets/CheckboxesWidget.js +2 -2
  21. package/lib/components/widgets/CheckboxesWidget.js.map +1 -1
  22. package/lib/components/widgets/RadioWidget.js +2 -2
  23. package/lib/components/widgets/RadioWidget.js.map +1 -1
  24. package/lib/components/widgets/TextareaWidget.js +2 -2
  25. package/lib/components/widgets/TextareaWidget.js.map +1 -1
  26. package/lib/tsconfig.tsbuildinfo +1 -1
  27. package/package.json +6 -6
  28. package/src/components/Form.tsx +11 -6
  29. package/src/components/fields/NumberField.tsx +1 -1
  30. package/src/components/fields/ObjectField.tsx +6 -3
  31. package/src/components/fields/SchemaField.tsx +3 -3
  32. package/src/components/templates/BaseInputTemplate.tsx +5 -2
  33. package/src/components/templates/WrapIfAdditionalTemplate.tsx +1 -1
  34. package/src/components/widgets/CheckboxesWidget.tsx +4 -4
  35. package/src/components/widgets/RadioWidget.tsx +4 -4
  36. package/src/components/widgets/TextareaWidget.tsx +2 -2
package/dist/core.umd.js CHANGED
@@ -1063,7 +1063,7 @@
1063
1063
  [onChange]
1064
1064
  );
1065
1065
  if (typeof lastValue === "string" && typeof value === "number") {
1066
- const re = new RegExp(`${value}`.replace(".", "\\.") + "\\.?0*$");
1066
+ const re = new RegExp(`^(${String(value).replace(".", "\\.")})?\\.?0*$`);
1067
1067
  if (lastValue.match(re)) {
1068
1068
  value = lastValue;
1069
1069
  }
@@ -1180,20 +1180,23 @@
1180
1180
  const { formData, onChange, registry } = this.props;
1181
1181
  const newFormData = { ...formData };
1182
1182
  let type = void 0;
1183
+ let defaultValue = void 0;
1183
1184
  if (isObject(schema.additionalProperties)) {
1184
1185
  type = schema.additionalProperties.type;
1186
+ defaultValue = schema.additionalProperties.default;
1185
1187
  let apSchema = schema.additionalProperties;
1186
1188
  if (utils.REF_KEY in apSchema) {
1187
1189
  const { schemaUtils } = registry;
1188
1190
  apSchema = schemaUtils.retrieveSchema({ $ref: apSchema[utils.REF_KEY] }, formData);
1189
1191
  type = apSchema.type;
1192
+ defaultValue = apSchema.default;
1190
1193
  }
1191
1194
  if (!type && (utils.ANY_OF_KEY in apSchema || utils.ONE_OF_KEY in apSchema)) {
1192
1195
  type = "object";
1193
1196
  }
1194
1197
  }
1195
1198
  const newKey = this.getAvailableKey("newKey", newFormData);
1196
- set(newFormData, newKey, this.getDefaultValue(type));
1199
+ set(newFormData, newKey, defaultValue ?? this.getDefaultValue(type));
1197
1200
  onChange(newFormData);
1198
1201
  };
1199
1202
  }
@@ -1241,8 +1244,8 @@
1241
1244
  idSchema,
1242
1245
  name,
1243
1246
  required = false,
1244
- disabled = false,
1245
- readonly = false,
1247
+ disabled,
1248
+ readonly,
1246
1249
  hideError,
1247
1250
  idPrefix,
1248
1251
  idSeparator,
@@ -1413,11 +1416,11 @@
1413
1416
  [fieldId, onChange]
1414
1417
  );
1415
1418
  const FieldComponent = getFieldComponent(schema, uiOptions, idSchema, registry);
1416
- const disabled = Boolean(props.disabled || uiOptions.disabled);
1417
- const readonly = Boolean(props.readonly || uiOptions.readonly || props.schema.readOnly || schema.readOnly);
1419
+ const disabled = Boolean(uiOptions.disabled ?? props.disabled);
1420
+ const readonly = Boolean(uiOptions.readonly ?? props.readonly ?? props.schema.readOnly ?? schema.readOnly);
1418
1421
  const uiSchemaHideError = uiOptions.hideError;
1419
1422
  const hideError = uiSchemaHideError === void 0 ? props.hideError : Boolean(uiSchemaHideError);
1420
- const autofocus = Boolean(props.autofocus || uiOptions.autofocus);
1423
+ const autofocus = Boolean(uiOptions.autofocus ?? props.autofocus);
1421
1424
  if (Object.keys(schema).length === 0) {
1422
1425
  return null;
1423
1426
  }
@@ -1915,9 +1918,12 @@
1915
1918
  ({ target: { value: value2 } }) => onChange(value2 === "" ? options.emptyValue : value2),
1916
1919
  [onChange, options]
1917
1920
  );
1918
- const _onBlur = react.useCallback(({ target: { value: value2 } }) => onBlur(id, value2), [onBlur, id]);
1921
+ const _onBlur = react.useCallback(
1922
+ ({ target }) => onBlur(id, target && target.value),
1923
+ [onBlur, id]
1924
+ );
1919
1925
  const _onFocus = react.useCallback(
1920
- ({ target: { value: value2 } }) => onFocus(id, value2),
1926
+ ({ target }) => onFocus(id, target && target.value),
1921
1927
  [onFocus, id]
1922
1928
  );
1923
1929
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
@@ -2241,7 +2247,7 @@
2241
2247
  className: "form-control",
2242
2248
  type: "text",
2243
2249
  id: `${id}-key`,
2244
- onBlur: (event) => onKeyChange(event.target.value),
2250
+ onBlur: ({ target }) => onKeyChange(target && target.value),
2245
2251
  defaultValue: label
2246
2252
  }
2247
2253
  )
@@ -2497,11 +2503,11 @@
2497
2503
  }) {
2498
2504
  const checkboxesValues = Array.isArray(value) ? value : [value];
2499
2505
  const handleBlur = react.useCallback(
2500
- ({ target: { value: value2 } }) => onBlur(id, utils.enumOptionsValueForIndex(value2, enumOptions, emptyValue)),
2506
+ ({ target }) => onBlur(id, utils.enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue)),
2501
2507
  [onBlur, id]
2502
2508
  );
2503
2509
  const handleFocus = react.useCallback(
2504
- ({ target: { value: value2 } }) => onFocus(id, utils.enumOptionsValueForIndex(value2, enumOptions, emptyValue)),
2510
+ ({ target }) => onFocus(id, utils.enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue)),
2505
2511
  [onFocus, id]
2506
2512
  );
2507
2513
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "checkboxes", id, children: Array.isArray(enumOptions) && enumOptions.map((option, index) => {
@@ -2744,11 +2750,11 @@
2744
2750
  }) {
2745
2751
  const { enumOptions, enumDisabled, inline, emptyValue } = options;
2746
2752
  const handleBlur = react.useCallback(
2747
- ({ target: { value: value2 } }) => onBlur(id, utils.enumOptionsValueForIndex(value2, enumOptions, emptyValue)),
2753
+ ({ target }) => onBlur(id, utils.enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue)),
2748
2754
  [onBlur, id]
2749
2755
  );
2750
2756
  const handleFocus = react.useCallback(
2751
- ({ target: { value: value2 } }) => onFocus(id, utils.enumOptionsValueForIndex(value2, enumOptions, emptyValue)),
2757
+ ({ target }) => onFocus(id, utils.enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue)),
2752
2758
  [onFocus, id]
2753
2759
  );
2754
2760
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "field-radio-group", id, children: Array.isArray(enumOptions) && enumOptions.map((option, i) => {
@@ -2881,11 +2887,11 @@
2881
2887
  [onChange, options.emptyValue]
2882
2888
  );
2883
2889
  const handleBlur = react.useCallback(
2884
- ({ target: { value: value2 } }) => onBlur(id, value2),
2890
+ ({ target }) => onBlur(id, target && target.value),
2885
2891
  [onBlur, id]
2886
2892
  );
2887
2893
  const handleFocus = react.useCallback(
2888
- ({ target: { value: value2 } }) => onFocus(id, value2),
2894
+ ({ target }) => onFocus(id, target && target.value),
2889
2895
  [id, onFocus]
2890
2896
  );
2891
2897
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -3006,7 +3012,7 @@
3006
3012
  Object.keys(_obj).forEach((key) => {
3007
3013
  if (typeof _obj[key] === "object") {
3008
3014
  const newPaths = paths.map((path) => [...path, key]);
3009
- if (_obj[key][utils.RJSF_ADDITONAL_PROPERTIES_FLAG] && _obj[key][utils.NAME_KEY] !== "") {
3015
+ if (_obj[key][utils.RJSF_ADDITIONAL_PROPERTIES_FLAG] && _obj[key][utils.NAME_KEY] !== "") {
3010
3016
  acc.push(_obj[key][utils.NAME_KEY]);
3011
3017
  } else {
3012
3018
  getAllPaths(_obj[key], acc, newPaths);
@@ -3495,9 +3501,10 @@
3495
3501
  autoComplete,
3496
3502
  enctype,
3497
3503
  acceptcharset,
3504
+ acceptCharset,
3498
3505
  noHtml5Validate = false,
3499
- disabled = false,
3500
- readonly = false,
3506
+ disabled,
3507
+ readonly,
3501
3508
  formContext,
3502
3509
  showErrorList = "top",
3503
3510
  _internalFormWrapper
@@ -3524,7 +3531,7 @@
3524
3531
  action,
3525
3532
  autoComplete,
3526
3533
  encType: enctype,
3527
- acceptCharset: acceptcharset,
3534
+ acceptCharset: acceptCharset || acceptcharset,
3528
3535
  noValidate: noHtml5Validate,
3529
3536
  onSubmit: this.onSubmit,
3530
3537
  as,
package/dist/index.esm.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  isObject as isObject5,
9
9
  mergeObjects as mergeObjects2,
10
10
  NAME_KEY,
11
- RJSF_ADDITONAL_PROPERTIES_FLAG,
11
+ RJSF_ADDITIONAL_PROPERTIES_FLAG,
12
12
  shouldRender,
13
13
  SUBMIT_BTN_OPTIONS_KEY,
14
14
  toErrorList,
@@ -1134,7 +1134,7 @@ function NumberField(props) {
1134
1134
  [onChange]
1135
1135
  );
1136
1136
  if (typeof lastValue === "string" && typeof value === "number") {
1137
- const re = new RegExp(`${value}`.replace(".", "\\.") + "\\.?0*$");
1137
+ const re = new RegExp(`^(${String(value).replace(".", "\\.")})?\\.?0*$`);
1138
1138
  if (lastValue.match(re)) {
1139
1139
  value = lastValue;
1140
1140
  }
@@ -1272,20 +1272,23 @@ var ObjectField = class extends Component3 {
1272
1272
  const { formData, onChange, registry } = this.props;
1273
1273
  const newFormData = { ...formData };
1274
1274
  let type = void 0;
1275
+ let defaultValue = void 0;
1275
1276
  if (isObject3(schema.additionalProperties)) {
1276
1277
  type = schema.additionalProperties.type;
1278
+ defaultValue = schema.additionalProperties.default;
1277
1279
  let apSchema = schema.additionalProperties;
1278
1280
  if (REF_KEY in apSchema) {
1279
1281
  const { schemaUtils } = registry;
1280
1282
  apSchema = schemaUtils.retrieveSchema({ $ref: apSchema[REF_KEY] }, formData);
1281
1283
  type = apSchema.type;
1284
+ defaultValue = apSchema.default;
1282
1285
  }
1283
1286
  if (!type && (ANY_OF_KEY2 in apSchema || ONE_OF_KEY2 in apSchema)) {
1284
1287
  type = "object";
1285
1288
  }
1286
1289
  }
1287
1290
  const newKey = this.getAvailableKey("newKey", newFormData);
1288
- set2(newFormData, newKey, this.getDefaultValue(type));
1291
+ set2(newFormData, newKey, defaultValue ?? this.getDefaultValue(type));
1289
1292
  onChange(newFormData);
1290
1293
  };
1291
1294
  }
@@ -1333,8 +1336,8 @@ var ObjectField = class extends Component3 {
1333
1336
  idSchema,
1334
1337
  name,
1335
1338
  required = false,
1336
- disabled = false,
1337
- readonly = false,
1339
+ disabled,
1340
+ readonly,
1338
1341
  hideError,
1339
1342
  idPrefix,
1340
1343
  idSeparator,
@@ -1524,11 +1527,11 @@ function SchemaFieldRender(props) {
1524
1527
  [fieldId, onChange]
1525
1528
  );
1526
1529
  const FieldComponent = getFieldComponent(schema, uiOptions, idSchema, registry);
1527
- const disabled = Boolean(props.disabled || uiOptions.disabled);
1528
- const readonly = Boolean(props.readonly || uiOptions.readonly || props.schema.readOnly || schema.readOnly);
1530
+ const disabled = Boolean(uiOptions.disabled ?? props.disabled);
1531
+ const readonly = Boolean(uiOptions.readonly ?? props.readonly ?? props.schema.readOnly ?? schema.readOnly);
1529
1532
  const uiSchemaHideError = uiOptions.hideError;
1530
1533
  const hideError = uiSchemaHideError === void 0 ? props.hideError : Boolean(uiSchemaHideError);
1531
- const autofocus = Boolean(props.autofocus || uiOptions.autofocus);
1534
+ const autofocus = Boolean(uiOptions.autofocus ?? props.autofocus);
1532
1535
  if (Object.keys(schema).length === 0) {
1533
1536
  return null;
1534
1537
  }
@@ -2073,9 +2076,12 @@ function BaseInputTemplate(props) {
2073
2076
  ({ target: { value: value2 } }) => onChange(value2 === "" ? options.emptyValue : value2),
2074
2077
  [onChange, options]
2075
2078
  );
2076
- const _onBlur = useCallback3(({ target: { value: value2 } }) => onBlur(id, value2), [onBlur, id]);
2079
+ const _onBlur = useCallback3(
2080
+ ({ target }) => onBlur(id, target && target.value),
2081
+ [onBlur, id]
2082
+ );
2077
2083
  const _onFocus = useCallback3(
2078
- ({ target: { value: value2 } }) => onFocus(id, value2),
2084
+ ({ target }) => onFocus(id, target && target.value),
2079
2085
  [onFocus, id]
2080
2086
  );
2081
2087
  return /* @__PURE__ */ jsxs6(Fragment2, { children: [
@@ -2467,7 +2473,7 @@ function WrapIfAdditionalTemplate(props) {
2467
2473
  className: "form-control",
2468
2474
  type: "text",
2469
2475
  id: `${id}-key`,
2470
- onBlur: (event) => onKeyChange(event.target.value),
2476
+ onBlur: ({ target }) => onKeyChange(target && target.value),
2471
2477
  defaultValue: label
2472
2478
  }
2473
2479
  )
@@ -2761,11 +2767,11 @@ function CheckboxesWidget({
2761
2767
  }) {
2762
2768
  const checkboxesValues = Array.isArray(value) ? value : [value];
2763
2769
  const handleBlur = useCallback6(
2764
- ({ target: { value: value2 } }) => onBlur(id, enumOptionsValueForIndex(value2, enumOptions, emptyValue)),
2770
+ ({ target }) => onBlur(id, enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue)),
2765
2771
  [onBlur, id]
2766
2772
  );
2767
2773
  const handleFocus = useCallback6(
2768
- ({ target: { value: value2 } }) => onFocus(id, enumOptionsValueForIndex(value2, enumOptions, emptyValue)),
2774
+ ({ target }) => onFocus(id, enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue)),
2769
2775
  [onFocus, id]
2770
2776
  );
2771
2777
  return /* @__PURE__ */ jsx29("div", { className: "checkboxes", id, children: Array.isArray(enumOptions) && enumOptions.map((option, index) => {
@@ -3056,11 +3062,11 @@ function RadioWidget({
3056
3062
  }) {
3057
3063
  const { enumOptions, enumDisabled, inline, emptyValue } = options;
3058
3064
  const handleBlur = useCallback9(
3059
- ({ target: { value: value2 } }) => onBlur(id, enumOptionsValueForIndex2(value2, enumOptions, emptyValue)),
3065
+ ({ target }) => onBlur(id, enumOptionsValueForIndex2(target && target.value, enumOptions, emptyValue)),
3060
3066
  [onBlur, id]
3061
3067
  );
3062
3068
  const handleFocus = useCallback9(
3063
- ({ target: { value: value2 } }) => onFocus(id, enumOptionsValueForIndex2(value2, enumOptions, emptyValue)),
3069
+ ({ target }) => onFocus(id, enumOptionsValueForIndex2(target && target.value, enumOptions, emptyValue)),
3064
3070
  [onFocus, id]
3065
3071
  );
3066
3072
  return /* @__PURE__ */ jsx37("div", { className: "field-radio-group", id, children: Array.isArray(enumOptions) && enumOptions.map((option, i) => {
@@ -3210,11 +3216,11 @@ function TextareaWidget({
3210
3216
  [onChange, options.emptyValue]
3211
3217
  );
3212
3218
  const handleBlur = useCallback11(
3213
- ({ target: { value: value2 } }) => onBlur(id, value2),
3219
+ ({ target }) => onBlur(id, target && target.value),
3214
3220
  [onBlur, id]
3215
3221
  );
3216
3222
  const handleFocus = useCallback11(
3217
- ({ target: { value: value2 } }) => onFocus(id, value2),
3223
+ ({ target }) => onFocus(id, target && target.value),
3218
3224
  [id, onFocus]
3219
3225
  );
3220
3226
  return /* @__PURE__ */ jsx40(
@@ -3355,7 +3361,7 @@ var Form = class extends Component5 {
3355
3361
  Object.keys(_obj).forEach((key) => {
3356
3362
  if (typeof _obj[key] === "object") {
3357
3363
  const newPaths = paths.map((path) => [...path, key]);
3358
- if (_obj[key][RJSF_ADDITONAL_PROPERTIES_FLAG] && _obj[key][NAME_KEY] !== "") {
3364
+ if (_obj[key][RJSF_ADDITIONAL_PROPERTIES_FLAG] && _obj[key][NAME_KEY] !== "") {
3359
3365
  acc.push(_obj[key][NAME_KEY]);
3360
3366
  } else {
3361
3367
  getAllPaths(_obj[key], acc, newPaths);
@@ -3844,9 +3850,10 @@ var Form = class extends Component5 {
3844
3850
  autoComplete,
3845
3851
  enctype,
3846
3852
  acceptcharset,
3853
+ acceptCharset,
3847
3854
  noHtml5Validate = false,
3848
- disabled = false,
3849
- readonly = false,
3855
+ disabled,
3856
+ readonly,
3850
3857
  formContext,
3851
3858
  showErrorList = "top",
3852
3859
  _internalFormWrapper
@@ -3873,7 +3880,7 @@ var Form = class extends Component5 {
3873
3880
  action,
3874
3881
  autoComplete,
3875
3882
  encType: enctype,
3876
- acceptCharset: acceptcharset,
3883
+ acceptCharset: acceptCharset || acceptcharset,
3877
3884
  noValidate: noHtml5Validate,
3878
3885
  onSubmit: this.onSubmit,
3879
3886
  as,