@rjsf/core 6.5.1 → 6.5.3

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 CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@rjsf/utils'), require('lodash/cloneDeep'), require('lodash/get'), require('lodash/isEmpty'), require('lodash/pick'), require('lodash/set'), require('lodash/toPath'), require('lodash/unset'), require('lodash/isObject'), require('lodash/uniqueId'), require('react/jsx-runtime'), require('lodash/each'), require('lodash/flatten'), require('lodash/has'), require('lodash/includes'), require('lodash/intersection'), require('lodash/isFunction'), require('lodash/isEqual'), require('lodash/isPlainObject'), require('lodash/isString'), require('lodash/isUndefined'), require('lodash/last'), require('lodash/noop'), require('lodash/omit'), require('markdown-to-jsx'), require('@rjsf/validator-ajv8')) :
3
3
  typeof define === 'function' && define.amd ? define(['exports', 'react', '@rjsf/utils', 'lodash/cloneDeep', 'lodash/get', 'lodash/isEmpty', 'lodash/pick', 'lodash/set', 'lodash/toPath', 'lodash/unset', 'lodash/isObject', 'lodash/uniqueId', 'react/jsx-runtime', 'lodash/each', 'lodash/flatten', 'lodash/has', 'lodash/includes', 'lodash/intersection', 'lodash/isFunction', 'lodash/isEqual', 'lodash/isPlainObject', 'lodash/isString', 'lodash/isUndefined', 'lodash/last', 'lodash/noop', 'lodash/omit', 'markdown-to-jsx', '@rjsf/validator-ajv8'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JSONSchemaForm = {}, global.react, global.utils, global.cloneDeep, global.get, global.isEmpty, global._pick, global.set, global._toPath, global._unset, global.isObject, global.uniqueId, global.jsxRuntime, global.each, global.flatten, global.has, global.includes, global.intersection, global.isFunction, global.isEqual, global.isPlainObject, global.isString, global.isUndefined, global.last, global.noop, global.omit3, global.Markdown, global.validator));
5
- })(this, (function (exports, react, utils, cloneDeep, get, isEmpty, _pick, set, _toPath, _unset, isObject, uniqueId, jsxRuntime, each, flatten, has, includes, intersection, isFunction, isEqual, isPlainObject, isString, isUndefined, last, noop, omit3, Markdown, validator) { 'use strict';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JSONSchemaForm = {}, global.react, global.utils, global._cloneDeep, global.get, global.isEmpty, global._pick, global.set, global._toPath, global._unset, global.isObject, global.uniqueId, global.jsxRuntime, global.each, global.flatten, global.has, global.includes, global.intersection, global.isFunction, global.isEqual, global.isPlainObject, global.isString, global.isUndefined, global.last, global.noop, global.omit3, global.Markdown, global.validator));
5
+ })(this, (function (exports, react, utils, _cloneDeep, get, isEmpty, _pick, set, _toPath, _unset, isObject, uniqueId, jsxRuntime, each, flatten, has, includes, intersection, isFunction, isEqual, isPlainObject, isString, isUndefined, last, noop, omit3, Markdown, validator) { 'use strict';
6
6
 
7
7
  // src/components/Form.tsx
8
8
  function generateRowId() {
@@ -655,7 +655,7 @@
655
655
  }
656
656
  const newKeyedFormDataRow = {
657
657
  key: generateRowId(),
658
- item: cloneDeep(keyedFormData[index].item)
658
+ item: _cloneDeep(keyedFormData[index].item)
659
659
  };
660
660
  const newKeyedFormData = [...keyedFormData];
661
661
  if (index !== void 0) {
@@ -722,10 +722,12 @@
722
722
  );
723
723
  const handleChange = react.useCallback(
724
724
  (value, path, newErrorSchema, id) => {
725
+ const lastPathIsItemIndex = typeof path.at(-1) === "number";
725
726
  onChange(
726
727
  // We need to treat undefined items as nulls to have validation.
727
728
  // See https://github.com/tdegrunt/jsonschema/issues/206
728
- value === void 0 ? null : value,
729
+ // Only set to null for array items, and not for object properties within array items
730
+ lastPathIsItemIndex && value === void 0 ? null : value,
729
731
  path,
730
732
  newErrorSchema,
731
733
  id
@@ -2149,7 +2151,9 @@
2149
2151
  [fieldId, onChange]
2150
2152
  );
2151
2153
  const FieldComponent = getFieldComponent(schema, uiOptions, registry);
2152
- const disabled = Boolean(uiOptions.disabled ?? props.disabled);
2154
+ const isDeprecated = Boolean(schema.deprecated);
2155
+ const deprecatedHandling = isDeprecated ? uiOptions.deprecatedHandling ?? "label" : void 0;
2156
+ const disabled = Boolean(uiOptions.disabled ?? props.disabled) || deprecatedHandling === "disable";
2153
2157
  const readonly = Boolean(uiOptions.readonly ?? (props.readonly || props.schema.readOnly || schema.readOnly));
2154
2158
  const uiSchemaHideError = uiOptions.hideError;
2155
2159
  const hideError = uiSchemaHideError === void 0 ? props.hideError : Boolean(uiSchemaHideError);
@@ -2212,9 +2216,12 @@
2212
2216
  } else {
2213
2217
  label = utils.ADDITIONAL_PROPERTY_FLAG in schema ? name : uiOptions.title || props.schema.title || schema.title || props.title || name;
2214
2218
  }
2219
+ if (deprecatedHandling === "label") {
2220
+ label = registry.translateString(utils.TranslatableString.DeprecatedLabel, [label]);
2221
+ }
2215
2222
  const description = uiOptions.description || props.schema.description || schema.description || "";
2216
2223
  const help = uiOptions.help;
2217
- const hidden = uiOptions.widget === "hidden";
2224
+ const hidden = uiOptions.widget === "hidden" || deprecatedHandling === "hide";
2218
2225
  const classNames = ["rjsf-field", `rjsf-field-${utils.getSchemaType(schema)}`];
2219
2226
  if (!hideError && __errors && __errors.length > 0) {
2220
2227
  classNames.push("rjsf-field-error");
@@ -4217,11 +4224,12 @@
4217
4224
  const { newErrorSchema } = this.pendingChanges[0];
4218
4225
  const { extraErrors, omitExtraData, liveOmit, noValidate, liveValidate, onChange, removeEmptyOptionalObjects } = this.props;
4219
4226
  const { formData: oldFormData, schemaUtils, schema, fieldPathId, schemaValidationErrorSchema, errors } = this.state;
4220
- let { customErrors, errorSchema: originalErrorSchema } = this.state;
4227
+ let { customErrors } = this.state;
4228
+ let mergeBaseErrorSchema = schemaValidationErrorSchema;
4221
4229
  const rootPathId = fieldPathId.path[0] || "";
4222
4230
  const isRootPath = !path || path.length === 0 || path.length === 1 && path[0] === rootPathId;
4223
4231
  let retrievedSchema = this.state.retrievedSchema;
4224
- let formData = isRootPath ? newValue : cloneDeep(oldFormData);
4232
+ let formData = isRootPath ? newValue : _cloneDeep(oldFormData);
4225
4233
  const hasOnlyUndefinedValues = utils.isObject(formData) && Object.keys(formData).length > 0 && Object.values(formData).every((v) => v === void 0);
4226
4234
  const wasPreviouslyNull = oldFormData === null || oldFormData === void 0;
4227
4235
  const inputForDefaults = hasOnlyUndefinedValues && wasPreviouslyNull ? void 0 : formData;
@@ -4229,7 +4237,26 @@
4229
4237
  if (newValue === ADDITIONAL_PROPERTY_KEY_REMOVE) {
4230
4238
  _unset(formData, path);
4231
4239
  } else if (!isRootPath) {
4232
- set(formData, path, newValue);
4240
+ let unsetPath = false;
4241
+ let valueForPath = newValue;
4242
+ if (newValue === void 0) {
4243
+ const lastSegment = path[path.length - 1];
4244
+ if (typeof lastSegment === "number") {
4245
+ valueForPath = null;
4246
+ } else {
4247
+ const { field } = schemaUtils.findFieldInSchema(schema, path, oldFormData);
4248
+ const leaf = field;
4249
+ const isOneOfOrAnyOfLeaf = leaf && (utils.ONE_OF_KEY in leaf || utils.ANY_OF_KEY in leaf);
4250
+ if (!isOneOfOrAnyOfLeaf && leaf !== void 0) {
4251
+ unsetPath = true;
4252
+ }
4253
+ }
4254
+ }
4255
+ if (unsetPath) {
4256
+ _unset(formData, path);
4257
+ } else {
4258
+ set(formData, path, valueForPath);
4259
+ }
4233
4260
  }
4234
4261
  const newState = this.getStateFromProps(this.props, inputForDefaults, void 0, void 0, void 0, true);
4235
4262
  formData = newState.formData;
@@ -4260,9 +4287,10 @@
4260
4287
  const oldValidationError = !isRootPath ? get(schemaValidationErrorSchema, path) : schemaValidationErrorSchema;
4261
4288
  if (!isEmpty(oldValidationError)) {
4262
4289
  if (!isRootPath) {
4263
- set(originalErrorSchema, path, newErrorSchema);
4290
+ mergeBaseErrorSchema = _cloneDeep(schemaValidationErrorSchema);
4291
+ set(mergeBaseErrorSchema, path, newErrorSchema);
4264
4292
  } else {
4265
- originalErrorSchema = newErrorSchema;
4293
+ mergeBaseErrorSchema = newErrorSchema;
4266
4294
  }
4267
4295
  } else {
4268
4296
  if (!customErrors) {
@@ -4284,7 +4312,7 @@
4284
4312
  const liveValidation = this.liveValidate(
4285
4313
  schema,
4286
4314
  schemaUtils,
4287
- originalErrorSchema,
4315
+ mergeBaseErrorSchema,
4288
4316
  newFormData,
4289
4317
  extraErrors,
4290
4318
  customErrors,
@@ -4292,7 +4320,7 @@
4292
4320
  );
4293
4321
  state = { formData: newFormData, ...liveValidation, customErrors };
4294
4322
  } else if (!noValidate && newErrorSchema) {
4295
- const mergedErrors = this.mergeErrors({ errorSchema: originalErrorSchema, errors }, extraErrors, customErrors);
4323
+ const mergedErrors = this.mergeErrors({ errorSchema: mergeBaseErrorSchema, errors }, extraErrors, customErrors);
4296
4324
  state = {
4297
4325
  formData: newFormData,
4298
4326
  ...mergedErrors,
package/dist/index.cjs CHANGED
@@ -779,10 +779,12 @@ function ArrayField(props) {
779
779
  );
780
780
  const handleChange = (0, import_react.useCallback)(
781
781
  (value, path, newErrorSchema, id) => {
782
+ const lastPathIsItemIndex = typeof path.at(-1) === "number";
782
783
  onChange(
783
784
  // We need to treat undefined items as nulls to have validation.
784
785
  // See https://github.com/tdegrunt/jsonschema/issues/206
785
- value === void 0 ? null : value,
786
+ // Only set to null for array items, and not for object properties within array items
787
+ lastPathIsItemIndex && value === void 0 ? null : value,
786
788
  path,
787
789
  newErrorSchema,
788
790
  id
@@ -2289,7 +2291,9 @@ function SchemaFieldRender(props) {
2289
2291
  [fieldId, onChange]
2290
2292
  );
2291
2293
  const FieldComponent = getFieldComponent(schema, uiOptions, registry);
2292
- const disabled = Boolean(uiOptions.disabled ?? props.disabled);
2294
+ const isDeprecated = Boolean(schema.deprecated);
2295
+ const deprecatedHandling = isDeprecated ? uiOptions.deprecatedHandling ?? "label" : void 0;
2296
+ const disabled = Boolean(uiOptions.disabled ?? props.disabled) || deprecatedHandling === "disable";
2293
2297
  const readonly = Boolean(uiOptions.readonly ?? (props.readonly || props.schema.readOnly || schema.readOnly));
2294
2298
  const uiSchemaHideError = uiOptions.hideError;
2295
2299
  const hideError = uiSchemaHideError === void 0 ? props.hideError : Boolean(uiSchemaHideError);
@@ -2352,9 +2356,12 @@ function SchemaFieldRender(props) {
2352
2356
  } else {
2353
2357
  label = import_utils11.ADDITIONAL_PROPERTY_FLAG in schema ? name : uiOptions.title || props.schema.title || schema.title || props.title || name;
2354
2358
  }
2359
+ if (deprecatedHandling === "label") {
2360
+ label = registry.translateString(import_utils11.TranslatableString.DeprecatedLabel, [label]);
2361
+ }
2355
2362
  const description = uiOptions.description || props.schema.description || schema.description || "";
2356
2363
  const help = uiOptions.help;
2357
- const hidden = uiOptions.widget === "hidden";
2364
+ const hidden = uiOptions.widget === "hidden" || deprecatedHandling === "hide";
2358
2365
  const classNames = ["rjsf-field", `rjsf-field-${(0, import_utils11.getSchemaType)(schema)}`];
2359
2366
  if (!hideError && __errors && __errors.length > 0) {
2360
2367
  classNames.push("rjsf-field-error");
@@ -4563,7 +4570,8 @@ var Form = class extends import_react21.Component {
4563
4570
  const { newErrorSchema } = this.pendingChanges[0];
4564
4571
  const { extraErrors, omitExtraData, liveOmit, noValidate, liveValidate, onChange, removeEmptyOptionalObjects } = this.props;
4565
4572
  const { formData: oldFormData, schemaUtils, schema, fieldPathId, schemaValidationErrorSchema, errors } = this.state;
4566
- let { customErrors, errorSchema: originalErrorSchema } = this.state;
4573
+ let { customErrors } = this.state;
4574
+ let mergeBaseErrorSchema = schemaValidationErrorSchema;
4567
4575
  const rootPathId = fieldPathId.path[0] || "";
4568
4576
  const isRootPath = !path || path.length === 0 || path.length === 1 && path[0] === rootPathId;
4569
4577
  let retrievedSchema = this.state.retrievedSchema;
@@ -4575,7 +4583,26 @@ var Form = class extends import_react21.Component {
4575
4583
  if (newValue === ADDITIONAL_PROPERTY_KEY_REMOVE) {
4576
4584
  (0, import_unset.default)(formData, path);
4577
4585
  } else if (!isRootPath) {
4578
- (0, import_set5.default)(formData, path, newValue);
4586
+ let unsetPath = false;
4587
+ let valueForPath = newValue;
4588
+ if (newValue === void 0) {
4589
+ const lastSegment = path[path.length - 1];
4590
+ if (typeof lastSegment === "number") {
4591
+ valueForPath = null;
4592
+ } else {
4593
+ const { field } = schemaUtils.findFieldInSchema(schema, path, oldFormData);
4594
+ const leaf = field;
4595
+ const isOneOfOrAnyOfLeaf = leaf && (import_utils50.ONE_OF_KEY in leaf || import_utils50.ANY_OF_KEY in leaf);
4596
+ if (!isOneOfOrAnyOfLeaf && leaf !== void 0) {
4597
+ unsetPath = true;
4598
+ }
4599
+ }
4600
+ }
4601
+ if (unsetPath) {
4602
+ (0, import_unset.default)(formData, path);
4603
+ } else {
4604
+ (0, import_set5.default)(formData, path, valueForPath);
4605
+ }
4579
4606
  }
4580
4607
  const newState = this.getStateFromProps(this.props, inputForDefaults, void 0, void 0, void 0, true);
4581
4608
  formData = newState.formData;
@@ -4606,9 +4633,10 @@ var Form = class extends import_react21.Component {
4606
4633
  const oldValidationError = !isRootPath ? (0, import_get5.default)(schemaValidationErrorSchema, path) : schemaValidationErrorSchema;
4607
4634
  if (!(0, import_isEmpty4.default)(oldValidationError)) {
4608
4635
  if (!isRootPath) {
4609
- (0, import_set5.default)(originalErrorSchema, path, newErrorSchema);
4636
+ mergeBaseErrorSchema = (0, import_cloneDeep2.default)(schemaValidationErrorSchema);
4637
+ (0, import_set5.default)(mergeBaseErrorSchema, path, newErrorSchema);
4610
4638
  } else {
4611
- originalErrorSchema = newErrorSchema;
4639
+ mergeBaseErrorSchema = newErrorSchema;
4612
4640
  }
4613
4641
  } else {
4614
4642
  if (!customErrors) {
@@ -4630,7 +4658,7 @@ var Form = class extends import_react21.Component {
4630
4658
  const liveValidation = this.liveValidate(
4631
4659
  schema,
4632
4660
  schemaUtils,
4633
- originalErrorSchema,
4661
+ mergeBaseErrorSchema,
4634
4662
  newFormData,
4635
4663
  extraErrors,
4636
4664
  customErrors,
@@ -4638,7 +4666,7 @@ var Form = class extends import_react21.Component {
4638
4666
  );
4639
4667
  state = { formData: newFormData, ...liveValidation, customErrors };
4640
4668
  } else if (!noValidate && newErrorSchema) {
4641
- const mergedErrors = this.mergeErrors({ errorSchema: originalErrorSchema, errors }, extraErrors, customErrors);
4669
+ const mergedErrors = this.mergeErrors({ errorSchema: mergeBaseErrorSchema, errors }, extraErrors, customErrors);
4642
4670
  state = {
4643
4671
  formData: newFormData,
4644
4672
  ...mergedErrors,