@rjsf/core 5.5.0 → 5.5.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.
@@ -147,6 +147,9 @@ var ArrayField = /*#__PURE__*/function (_Component) {
147
147
  function ArrayField(props) {
148
148
  var _this;
149
149
  _this = _Component.call(this, props) || this;
150
+ /** Returns the default form information for an item based on the schema for that item. Deals with the possibility
151
+ * that the schema is fixed and allows additional items.
152
+ */
150
153
  _this._getNewFormDataRow = function () {
151
154
  var _this$props = _this.props,
152
155
  schema = _this$props.schema,
@@ -159,14 +162,32 @@ var ArrayField = /*#__PURE__*/function (_Component) {
159
162
  // Cast this as a T to work around schema utils being for T[] caused by the FieldProps<T[], S, F> call on the class
160
163
  return schemaUtils.getDefaultFormState(itemSchema);
161
164
  };
165
+ /** Callback handler for when the user clicks on the add button. Creates a new row of keyed form data at the end of
166
+ * the list, adding it into the state, and then returning `onChange()` with the plain form data converted from the
167
+ * keyed data
168
+ *
169
+ * @param event - The event for the click
170
+ */
162
171
  _this.onAddClick = function (event) {
163
172
  _this._handleAddClick(event);
164
173
  };
174
+ /** Callback handler for when the user clicks on the add button on an existing array element. Creates a new row of
175
+ * keyed form data inserted at the `index`, adding it into the state, and then returning `onChange()` with the plain
176
+ * form data converted from the keyed data
177
+ *
178
+ * @param index - The index at which the add button is clicked
179
+ */
165
180
  _this.onAddIndexClick = function (index) {
166
181
  return function (event) {
167
182
  _this._handleAddClick(event, index);
168
183
  };
169
184
  };
185
+ /** Callback handler for when the user clicks on the copy button on an existing array element. Clones the row of
186
+ * keyed form data at the `index` into the next position in the state, and then returning `onChange()` with the plain
187
+ * form data converted from the keyed data
188
+ *
189
+ * @param index - The index at which the copy button is clicked
190
+ */
170
191
  _this.onCopyIndexClick = function (index) {
171
192
  return function (event) {
172
193
  if (event) {
@@ -192,6 +213,12 @@ var ArrayField = /*#__PURE__*/function (_Component) {
192
213
  });
193
214
  };
194
215
  };
216
+ /** Callback handler for when the user clicks on the remove button on an existing array element. Removes the row of
217
+ * keyed form data at the `index` in the state, and then returning `onChange()` with the plain form data converted
218
+ * from the keyed data
219
+ *
220
+ * @param index - The index at which the remove button is clicked
221
+ */
195
222
  _this.onDropIndexClick = function (index) {
196
223
  return function (event) {
197
224
  if (event) {
@@ -225,6 +252,13 @@ var ArrayField = /*#__PURE__*/function (_Component) {
225
252
  });
226
253
  };
227
254
  };
255
+ /** Callback handler for when the user clicks on one of the move item buttons on an existing array element. Moves the
256
+ * row of keyed form data at the `index` to the `newIndex` in the state, and then returning `onChange()` with the
257
+ * plain form data converted from the keyed data
258
+ *
259
+ * @param index - The index of the item to move
260
+ * @param newIndex - The index to where the item is to be moved
261
+ */
228
262
  _this.onReorderClick = function (index, newIndex) {
229
263
  return function (event) {
230
264
  if (event) {
@@ -265,6 +299,11 @@ var ArrayField = /*#__PURE__*/function (_Component) {
265
299
  });
266
300
  };
267
301
  };
302
+ /** Callback handler used to deal with changing the value of the data in the array at the `index`. Calls the
303
+ * `onChange` callback with the updated form data
304
+ *
305
+ * @param index - The index of the item being changed
306
+ */
268
307
  _this.onChangeForIndex = function (index) {
269
308
  return function (value, newErrorSchema, id) {
270
309
  var _extends2;
@@ -282,6 +321,7 @@ var ArrayField = /*#__PURE__*/function (_Component) {
282
321
  onChange(newFormData, errorSchema && errorSchema && _extends({}, errorSchema, (_extends2 = {}, _extends2[index] = newErrorSchema, _extends2)), id);
283
322
  };
284
323
  };
324
+ /** Callback handler used to change the value for a checkbox */
285
325
  _this.onSelectChange = function (value) {
286
326
  var _this$props5 = _this.props,
287
327
  onChange = _this$props5.onChange,
@@ -365,10 +405,7 @@ var ArrayField = /*#__PURE__*/function (_Component) {
365
405
  }
366
406
  }
367
407
  return addable;
368
- }
369
- /** Returns the default form information for an item based on the schema for that item. Deals with the possibility
370
- * that the schema is fixed and allows additional items.
371
- */;
408
+ };
372
409
  /** Callback handler for when the user clicks on the add or add at index buttons. Creates a new row of keyed form data
373
410
  * either at the end of the list (when index is not specified) or inserted at the `index` when it is, adding it into
374
411
  * the state, and then returning `onChange()` with the plain form data converted from the keyed data
@@ -398,13 +435,7 @@ var ArrayField = /*#__PURE__*/function (_Component) {
398
435
  }, function () {
399
436
  return onChange(keyedToPlainFormData(newKeyedFormData));
400
437
  });
401
- }
402
- /** Callback handler for when the user clicks on the add button. Creates a new row of keyed form data at the end of
403
- * the list, adding it into the state, and then returning `onChange()` with the plain form data converted from the
404
- * keyed data
405
- *
406
- * @param event - The event for the click
407
- */;
438
+ };
408
439
  /** Renders the `ArrayField` depending on the specific needs of the schema and uischema elements
409
440
  */
410
441
  _proto.render = function render() {
@@ -1025,6 +1056,12 @@ var AnyOfField = /*#__PURE__*/function (_Component) {
1025
1056
  function AnyOfField(props) {
1026
1057
  var _this;
1027
1058
  _this = _Component.call(this, props) || this;
1059
+ /** Callback handler to remember what the currently selected option is. In addition to that the `formData` is updated
1060
+ * to remove properties that are not part of the newly selected option schema, and then the updated data is passed to
1061
+ * the `onChange` handler.
1062
+ *
1063
+ * @param option - The new option value being selected
1064
+ */
1028
1065
  _this.onOptionChange = function (option) {
1029
1066
  var _this$state = _this.state,
1030
1067
  selectedOption = _this$state.selectedOption,
@@ -1120,13 +1157,7 @@ var AnyOfField = /*#__PURE__*/function (_Component) {
1120
1157
  // If the form data matches none of the options, use the currently selected
1121
1158
  // option, assuming it's available; otherwise use the first option
1122
1159
  return selectedOption || 0;
1123
- }
1124
- /** Callback handler to remember what the currently selected option is. In addition to that the `formData` is updated
1125
- * to remove properties that are not part of the newly selected option schema, and then the updated data is passed to
1126
- * the `onChange` handler.
1127
- *
1128
- * @param option - The new option value being selected
1129
- */;
1160
+ };
1130
1161
  _proto.getFieldId = function getFieldId() {
1131
1162
  var _this$props4 = this.props,
1132
1163
  idSchema = _this$props4.idSchema,
@@ -1313,10 +1344,19 @@ var ObjectField = /*#__PURE__*/function (_Component) {
1313
1344
  args[_key] = arguments[_key];
1314
1345
  }
1315
1346
  _this = _Component.call.apply(_Component, [this].concat(args)) || this;
1347
+ /** Set up the initial state */
1316
1348
  _this.state = {
1317
1349
  wasPropertyKeyModified: false,
1318
1350
  additionalProperties: {}
1319
1351
  };
1352
+ /** Returns the `onPropertyChange` handler for the `name` field. Handles the special case where a user is attempting
1353
+ * to clear the data for a field added as an additional property. Calls the `onChange()` handler with the updated
1354
+ * formData.
1355
+ *
1356
+ * @param name - The name of the property
1357
+ * @param addedByAdditionalProperties - Flag indicating whether this property is an additional property
1358
+ * @returns - The onPropertyChange callback for the `name` property
1359
+ */
1320
1360
  _this.onPropertyChange = function (name, addedByAdditionalProperties) {
1321
1361
  if (addedByAdditionalProperties === void 0) {
1322
1362
  addedByAdditionalProperties = false;
@@ -1341,6 +1381,12 @@ var ObjectField = /*#__PURE__*/function (_Component) {
1341
1381
  onChange(newFormData, errorSchema && errorSchema && _extends({}, errorSchema, (_extends3 = {}, _extends3[name] = newErrorSchema, _extends3)), id);
1342
1382
  };
1343
1383
  };
1384
+ /** Returns a callback to handle the onDropPropertyClick event for the given `key` which removes the old `key` data
1385
+ * and calls the `onChange` callback with it
1386
+ *
1387
+ * @param key - The key for which the drop callback is desired
1388
+ * @returns - The drop property click callback
1389
+ */
1344
1390
  _this.onDropPropertyClick = function (key) {
1345
1391
  return function (event) {
1346
1392
  event.preventDefault();
@@ -1352,6 +1398,13 @@ var ObjectField = /*#__PURE__*/function (_Component) {
1352
1398
  onChange(copiedFormData);
1353
1399
  };
1354
1400
  };
1401
+ /** Computes the next available key name from the `preferredKey`, indexing through the already existing keys until one
1402
+ * that is already not assigned is found.
1403
+ *
1404
+ * @param preferredKey - The preferred name of a new key
1405
+ * @param [formData] - The form data in which to check if the desired key already exists
1406
+ * @returns - The name of the next available key from `preferredKey`
1407
+ */
1355
1408
  _this.getAvailableKey = function (preferredKey, formData) {
1356
1409
  var _this$props3 = _this.props,
1357
1410
  uiSchema = _this$props3.uiSchema,
@@ -1366,6 +1419,12 @@ var ObjectField = /*#__PURE__*/function (_Component) {
1366
1419
  }
1367
1420
  return newKey;
1368
1421
  };
1422
+ /** Returns a callback function that deals with the rename of a key for an additional property for a schema. That
1423
+ * callback will attempt to rename the key and move the existing data to that key, calling `onChange` when it does.
1424
+ *
1425
+ * @param oldValue - The old value of a field
1426
+ * @returns - The key change callback function
1427
+ */
1369
1428
  _this.onKeyChange = function (oldValue) {
1370
1429
  return function (value, newErrorSchema) {
1371
1430
  var _newKeys, _extends4;
@@ -1391,6 +1450,11 @@ var ObjectField = /*#__PURE__*/function (_Component) {
1391
1450
  onChange(renamedObj, errorSchema && errorSchema && _extends({}, errorSchema, (_extends4 = {}, _extends4[value] = newErrorSchema, _extends4)));
1392
1451
  };
1393
1452
  };
1453
+ /** Handles the adding of a new additional property on the given `schema`. Calls the `onChange` callback once the new
1454
+ * default data for that field has been added to the formData.
1455
+ *
1456
+ * @param schema - The schema element to which the new property is being added
1457
+ */
1394
1458
  _this.handleAddClick = function (schema) {
1395
1459
  return function () {
1396
1460
  if (!schema.additionalProperties) {
@@ -1433,15 +1497,7 @@ var ObjectField = /*#__PURE__*/function (_Component) {
1433
1497
  _proto.isRequired = function isRequired(name) {
1434
1498
  var schema = this.props.schema;
1435
1499
  return Array.isArray(schema.required) && schema.required.indexOf(name) !== -1;
1436
- }
1437
- /** Returns the `onPropertyChange` handler for the `name` field. Handles the special case where a user is attempting
1438
- * to clear the data for a field added as an additional property. Calls the `onChange()` handler with the updated
1439
- * formData.
1440
- *
1441
- * @param name - The name of the property
1442
- * @param addedByAdditionalProperties - Flag indicating whether this property is an additional property
1443
- * @returns - The onPropertyChange callback for the `name` property
1444
- */;
1500
+ };
1445
1501
  /** Returns a default value to be used for a new additional schema property of the given `type`
1446
1502
  *
1447
1503
  * @param type - The type of the new additional schema property
@@ -1464,12 +1520,7 @@ var ObjectField = /*#__PURE__*/function (_Component) {
1464
1520
  // We don't have a datatype for some reason (perhaps additionalProperties was true)
1465
1521
  return translateString(utils.TranslatableString.NewStringDefault);
1466
1522
  }
1467
- }
1468
- /** Handles the adding of a new additional property on the given `schema`. Calls the `onChange` callback once the new
1469
- * default data for that field has been added to the formData.
1470
- *
1471
- * @param schema - The schema element to which the new property is being added
1472
- */;
1523
+ };
1473
1524
  /** Renders the `ObjectField` from the given props
1474
1525
  */
1475
1526
  _proto.render = function render() {
@@ -3603,10 +3654,6 @@ function getDefaultRegistry() {
3603
3654
  /** The `Form` component renders the outer form and all the fields defined in the `schema` */
3604
3655
  var Form = /*#__PURE__*/function (_Component) {
3605
3656
  _inheritsLoose(Form, _Component);
3606
- /** The ref used to hold the `form` element, this needs to be `any` because `tagName` or `_internalFormWrapper` can
3607
- * provide any possible type here
3608
- */
3609
-
3610
3657
  /** Constructs the `Form` from the `props`. Will setup the initial state from the props. It will also call the
3611
3658
  * `onChange` handler if the initially provided `formData` is modified to add missing default values as part of the
3612
3659
  * state construction.
@@ -3616,7 +3663,15 @@ var Form = /*#__PURE__*/function (_Component) {
3616
3663
  function Form(props) {
3617
3664
  var _this;
3618
3665
  _this = _Component.call(this, props) || this;
3666
+ /** The ref used to hold the `form` element, this needs to be `any` because `tagName` or `_internalFormWrapper` can
3667
+ * provide any possible type here
3668
+ */
3619
3669
  _this.formElement = void 0;
3670
+ /** Returns the `formData` with only the elements specified in the `fields` list
3671
+ *
3672
+ * @param formData - The data for the `Form`
3673
+ * @param fields - The fields to keep while filtering
3674
+ */
3620
3675
  _this.getUsedFormData = function (formData, fields) {
3621
3676
  // For the case of a single input form
3622
3677
  if (fields.length === 0 && typeof formData !== 'object') {
@@ -3631,6 +3686,11 @@ var Form = /*#__PURE__*/function (_Component) {
3631
3686
  }
3632
3687
  return data;
3633
3688
  };
3689
+ /** Returns the list of field names from inspecting the `pathSchema` as well as using the `formData`
3690
+ *
3691
+ * @param pathSchema - The `PathSchema` object for the form
3692
+ * @param [formData] - The form data to use while checking for empty objects/arrays
3693
+ */
3634
3694
  _this.getFieldNames = function (pathSchema, formData) {
3635
3695
  var getAllPaths = function getAllPaths(_obj, acc, paths) {
3636
3696
  if (acc === void 0) {
@@ -3665,6 +3725,17 @@ var Form = /*#__PURE__*/function (_Component) {
3665
3725
  };
3666
3726
  return getAllPaths(pathSchema);
3667
3727
  };
3728
+ /** Function to handle changes made to a field in the `Form`. This handler receives an entirely new copy of the
3729
+ * `formData` along with a new `ErrorSchema`. It will first update the `formData` with any missing default fields and
3730
+ * then, if `omitExtraData` and `liveOmit` are turned on, the `formData` will be filterer to remove any extra data not
3731
+ * in a form field. Then, the resulting formData will be validated if required. The state will be updated with the new
3732
+ * updated (potentially filtered) `formData`, any errors that resulted from validation. Finally the `onChange`
3733
+ * callback will be called if specified with the updated state.
3734
+ *
3735
+ * @param formData - The new form data from a change to a field
3736
+ * @param newErrorSchema - The new `ErrorSchema` based on the field change
3737
+ * @param id - The id of the field that caused the change
3738
+ */
3668
3739
  _this.onChange = function (formData, newErrorSchema, id) {
3669
3740
  var _this$props = _this.props,
3670
3741
  extraErrors = _this$props.extraErrors,
@@ -3725,6 +3796,12 @@ var Form = /*#__PURE__*/function (_Component) {
3725
3796
  return onChange && onChange(_extends({}, _this.state, state), id);
3726
3797
  });
3727
3798
  };
3799
+ /**
3800
+ * Callback function to handle reset form data.
3801
+ * - Reset all fields with default values.
3802
+ * - Reset validations and errors
3803
+ *
3804
+ */
3728
3805
  _this.reset = function () {
3729
3806
  var onChange = _this.props.onChange;
3730
3807
  var newState = _this.getStateFromProps(_this.props, undefined);
@@ -3740,18 +3817,38 @@ var Form = /*#__PURE__*/function (_Component) {
3740
3817
  return onChange && onChange(_extends({}, _this.state, state));
3741
3818
  });
3742
3819
  };
3820
+ /** Callback function to handle when a field on the form is blurred. Calls the `onBlur` callback for the `Form` if it
3821
+ * was provided.
3822
+ *
3823
+ * @param id - The unique `id` of the field that was blurred
3824
+ * @param data - The data associated with the field that was blurred
3825
+ */
3743
3826
  _this.onBlur = function (id, data) {
3744
3827
  var onBlur = _this.props.onBlur;
3745
3828
  if (onBlur) {
3746
3829
  onBlur(id, data);
3747
3830
  }
3748
3831
  };
3832
+ /** Callback function to handle when a field on the form is focused. Calls the `onFocus` callback for the `Form` if it
3833
+ * was provided.
3834
+ *
3835
+ * @param id - The unique `id` of the field that was focused
3836
+ * @param data - The data associated with the field that was focused
3837
+ */
3749
3838
  _this.onFocus = function (id, data) {
3750
3839
  var onFocus = _this.props.onFocus;
3751
3840
  if (onFocus) {
3752
3841
  onFocus(id, data);
3753
3842
  }
3754
3843
  };
3844
+ /** Callback function to handle when the form is submitted. First, it prevents the default event behavior. Nothing
3845
+ * happens if the target and currentTarget of the event are not the same. It will omit any extra data in the
3846
+ * `formData` in the state if `omitExtraData` is true. It will validate the resulting `formData`, reporting errors
3847
+ * via the `onError()` callback unless validation is disabled. Finally it will add in any `extraErrors` and then call
3848
+ * back the `onSubmit` callback if it was provided.
3849
+ *
3850
+ * @param event - The submit HTML form event
3851
+ */
3755
3852
  _this.onSubmit = function (event) {
3756
3853
  event.preventDefault();
3757
3854
  if (event.target !== event.currentTarget) {
@@ -3944,12 +4041,7 @@ var Form = /*#__PURE__*/function (_Component) {
3944
4041
  });
3945
4042
  }
3946
4043
  return null;
3947
- }
3948
- /** Returns the `formData` with only the elements specified in the `fields` list
3949
- *
3950
- * @param formData - The data for the `Form`
3951
- * @param fields - The fields to keep while filtering
3952
- */;
4044
+ };
3953
4045
  /** Returns the registry for the form */
3954
4046
  _proto.getRegistry = function getRegistry() {
3955
4047
  var _this$props$templates;
@@ -4067,6 +4159,7 @@ var Form = /*#__PURE__*/function (_Component) {
4067
4159
  * needed along with the submit button or any children of the form.
4068
4160
  */;
4069
4161
  _proto.render = function render() {
4162
+ var _UI_OPTIONS_KEY, _submitUiSchema;
4070
4163
  var _this$props7 = this.props,
4071
4164
  children = _this$props7.children,
4072
4165
  id = _this$props7.id,
@@ -4106,6 +4199,17 @@ var Form = /*#__PURE__*/function (_Component) {
4106
4199
  // NOTE, the `as` prop is native to `semantic-ui` and is emulated in the `material-ui` theme
4107
4200
  var as = _internalFormWrapper ? tagName : undefined;
4108
4201
  var FormTag = _internalFormWrapper || tagName || 'form';
4202
+ var _getUiOptions = utils.getUiOptions(uiSchema),
4203
+ _getUiOptions$SUBMIT_ = _getUiOptions[utils.SUBMIT_BTN_OPTIONS_KEY],
4204
+ submitOptions = _getUiOptions$SUBMIT_ === void 0 ? {} : _getUiOptions$SUBMIT_;
4205
+ if (disabled) {
4206
+ submitOptions = _extends({}, submitOptions, {
4207
+ props: _extends({}, submitOptions.props, {
4208
+ disabled: true
4209
+ })
4210
+ });
4211
+ }
4212
+ var submitUiSchema = (_submitUiSchema = {}, _submitUiSchema[utils.UI_OPTIONS_KEY] = (_UI_OPTIONS_KEY = {}, _UI_OPTIONS_KEY[utils.SUBMIT_BTN_OPTIONS_KEY] = submitOptions, _UI_OPTIONS_KEY), _submitUiSchema);
4109
4213
  return jsxRuntime.jsxs(FormTag, {
4110
4214
  className: className ? className : 'rjsf',
4111
4215
  id: id,
@@ -4137,7 +4241,7 @@ var Form = /*#__PURE__*/function (_Component) {
4137
4241
  disabled: disabled,
4138
4242
  readonly: readonly
4139
4243
  }), children ? children : jsxRuntime.jsx(SubmitButton, {
4140
- uiSchema: uiSchema,
4244
+ uiSchema: submitUiSchema,
4141
4245
  registry: registry
4142
4246
  }), showErrorList === 'bottom' && this.renderErrors(registry)]
4143
4247
  });