@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.
@@ -133,6 +133,9 @@
133
133
  function ArrayField(props) {
134
134
  var _this;
135
135
  _this = _Component.call(this, props) || this;
136
+ /** Returns the default form information for an item based on the schema for that item. Deals with the possibility
137
+ * that the schema is fixed and allows additional items.
138
+ */
136
139
  _this._getNewFormDataRow = function () {
137
140
  var _this$props = _this.props,
138
141
  schema = _this$props.schema,
@@ -145,14 +148,32 @@
145
148
  // Cast this as a T to work around schema utils being for T[] caused by the FieldProps<T[], S, F> call on the class
146
149
  return schemaUtils.getDefaultFormState(itemSchema);
147
150
  };
151
+ /** Callback handler for when the user clicks on the add button. Creates a new row of keyed form data at the end of
152
+ * the list, adding it into the state, and then returning `onChange()` with the plain form data converted from the
153
+ * keyed data
154
+ *
155
+ * @param event - The event for the click
156
+ */
148
157
  _this.onAddClick = function (event) {
149
158
  _this._handleAddClick(event);
150
159
  };
160
+ /** Callback handler for when the user clicks on the add button on an existing array element. Creates a new row of
161
+ * keyed form data inserted at the `index`, adding it into the state, and then returning `onChange()` with the plain
162
+ * form data converted from the keyed data
163
+ *
164
+ * @param index - The index at which the add button is clicked
165
+ */
151
166
  _this.onAddIndexClick = function (index) {
152
167
  return function (event) {
153
168
  _this._handleAddClick(event, index);
154
169
  };
155
170
  };
171
+ /** Callback handler for when the user clicks on the copy button on an existing array element. Clones the row of
172
+ * keyed form data at the `index` into the next position in the state, and then returning `onChange()` with the plain
173
+ * form data converted from the keyed data
174
+ *
175
+ * @param index - The index at which the copy button is clicked
176
+ */
156
177
  _this.onCopyIndexClick = function (index) {
157
178
  return function (event) {
158
179
  if (event) {
@@ -178,6 +199,12 @@
178
199
  });
179
200
  };
180
201
  };
202
+ /** Callback handler for when the user clicks on the remove button on an existing array element. Removes the row of
203
+ * keyed form data at the `index` in the state, and then returning `onChange()` with the plain form data converted
204
+ * from the keyed data
205
+ *
206
+ * @param index - The index at which the remove button is clicked
207
+ */
181
208
  _this.onDropIndexClick = function (index) {
182
209
  return function (event) {
183
210
  if (event) {
@@ -211,6 +238,13 @@
211
238
  });
212
239
  };
213
240
  };
241
+ /** Callback handler for when the user clicks on one of the move item buttons on an existing array element. Moves the
242
+ * row of keyed form data at the `index` to the `newIndex` in the state, and then returning `onChange()` with the
243
+ * plain form data converted from the keyed data
244
+ *
245
+ * @param index - The index of the item to move
246
+ * @param newIndex - The index to where the item is to be moved
247
+ */
214
248
  _this.onReorderClick = function (index, newIndex) {
215
249
  return function (event) {
216
250
  if (event) {
@@ -251,6 +285,11 @@
251
285
  });
252
286
  };
253
287
  };
288
+ /** Callback handler used to deal with changing the value of the data in the array at the `index`. Calls the
289
+ * `onChange` callback with the updated form data
290
+ *
291
+ * @param index - The index of the item being changed
292
+ */
254
293
  _this.onChangeForIndex = function (index) {
255
294
  return function (value, newErrorSchema, id) {
256
295
  var _extends2;
@@ -268,6 +307,7 @@
268
307
  onChange(newFormData, errorSchema && errorSchema && _extends({}, errorSchema, (_extends2 = {}, _extends2[index] = newErrorSchema, _extends2)), id);
269
308
  };
270
309
  };
310
+ /** Callback handler used to change the value for a checkbox */
271
311
  _this.onSelectChange = function (value) {
272
312
  var _this$props5 = _this.props,
273
313
  onChange = _this$props5.onChange,
@@ -351,10 +391,7 @@
351
391
  }
352
392
  }
353
393
  return addable;
354
- }
355
- /** Returns the default form information for an item based on the schema for that item. Deals with the possibility
356
- * that the schema is fixed and allows additional items.
357
- */;
394
+ };
358
395
  /** Callback handler for when the user clicks on the add or add at index buttons. Creates a new row of keyed form data
359
396
  * either at the end of the list (when index is not specified) or inserted at the `index` when it is, adding it into
360
397
  * the state, and then returning `onChange()` with the plain form data converted from the keyed data
@@ -384,13 +421,7 @@
384
421
  }, function () {
385
422
  return onChange(keyedToPlainFormData(newKeyedFormData));
386
423
  });
387
- }
388
- /** Callback handler for when the user clicks on the add button. Creates a new row of keyed form data at the end of
389
- * the list, adding it into the state, and then returning `onChange()` with the plain form data converted from the
390
- * keyed data
391
- *
392
- * @param event - The event for the click
393
- */;
424
+ };
394
425
  /** Renders the `ArrayField` depending on the specific needs of the schema and uischema elements
395
426
  */
396
427
  _proto.render = function render() {
@@ -1011,6 +1042,12 @@
1011
1042
  function AnyOfField(props) {
1012
1043
  var _this;
1013
1044
  _this = _Component.call(this, props) || this;
1045
+ /** Callback handler to remember what the currently selected option is. In addition to that the `formData` is updated
1046
+ * to remove properties that are not part of the newly selected option schema, and then the updated data is passed to
1047
+ * the `onChange` handler.
1048
+ *
1049
+ * @param option - The new option value being selected
1050
+ */
1014
1051
  _this.onOptionChange = function (option) {
1015
1052
  var _this$state = _this.state,
1016
1053
  selectedOption = _this$state.selectedOption,
@@ -1106,13 +1143,7 @@
1106
1143
  // If the form data matches none of the options, use the currently selected
1107
1144
  // option, assuming it's available; otherwise use the first option
1108
1145
  return selectedOption || 0;
1109
- }
1110
- /** Callback handler to remember what the currently selected option is. In addition to that the `formData` is updated
1111
- * to remove properties that are not part of the newly selected option schema, and then the updated data is passed to
1112
- * the `onChange` handler.
1113
- *
1114
- * @param option - The new option value being selected
1115
- */;
1146
+ };
1116
1147
  _proto.getFieldId = function getFieldId() {
1117
1148
  var _this$props4 = this.props,
1118
1149
  idSchema = _this$props4.idSchema,
@@ -1299,10 +1330,19 @@
1299
1330
  args[_key] = arguments[_key];
1300
1331
  }
1301
1332
  _this = _Component.call.apply(_Component, [this].concat(args)) || this;
1333
+ /** Set up the initial state */
1302
1334
  _this.state = {
1303
1335
  wasPropertyKeyModified: false,
1304
1336
  additionalProperties: {}
1305
1337
  };
1338
+ /** Returns the `onPropertyChange` handler for the `name` field. Handles the special case where a user is attempting
1339
+ * to clear the data for a field added as an additional property. Calls the `onChange()` handler with the updated
1340
+ * formData.
1341
+ *
1342
+ * @param name - The name of the property
1343
+ * @param addedByAdditionalProperties - Flag indicating whether this property is an additional property
1344
+ * @returns - The onPropertyChange callback for the `name` property
1345
+ */
1306
1346
  _this.onPropertyChange = function (name, addedByAdditionalProperties) {
1307
1347
  if (addedByAdditionalProperties === void 0) {
1308
1348
  addedByAdditionalProperties = false;
@@ -1327,6 +1367,12 @@
1327
1367
  onChange(newFormData, errorSchema && errorSchema && _extends({}, errorSchema, (_extends3 = {}, _extends3[name] = newErrorSchema, _extends3)), id);
1328
1368
  };
1329
1369
  };
1370
+ /** Returns a callback to handle the onDropPropertyClick event for the given `key` which removes the old `key` data
1371
+ * and calls the `onChange` callback with it
1372
+ *
1373
+ * @param key - The key for which the drop callback is desired
1374
+ * @returns - The drop property click callback
1375
+ */
1330
1376
  _this.onDropPropertyClick = function (key) {
1331
1377
  return function (event) {
1332
1378
  event.preventDefault();
@@ -1338,6 +1384,13 @@
1338
1384
  onChange(copiedFormData);
1339
1385
  };
1340
1386
  };
1387
+ /** Computes the next available key name from the `preferredKey`, indexing through the already existing keys until one
1388
+ * that is already not assigned is found.
1389
+ *
1390
+ * @param preferredKey - The preferred name of a new key
1391
+ * @param [formData] - The form data in which to check if the desired key already exists
1392
+ * @returns - The name of the next available key from `preferredKey`
1393
+ */
1341
1394
  _this.getAvailableKey = function (preferredKey, formData) {
1342
1395
  var _this$props3 = _this.props,
1343
1396
  uiSchema = _this$props3.uiSchema,
@@ -1352,6 +1405,12 @@
1352
1405
  }
1353
1406
  return newKey;
1354
1407
  };
1408
+ /** Returns a callback function that deals with the rename of a key for an additional property for a schema. That
1409
+ * callback will attempt to rename the key and move the existing data to that key, calling `onChange` when it does.
1410
+ *
1411
+ * @param oldValue - The old value of a field
1412
+ * @returns - The key change callback function
1413
+ */
1355
1414
  _this.onKeyChange = function (oldValue) {
1356
1415
  return function (value, newErrorSchema) {
1357
1416
  var _newKeys, _extends4;
@@ -1377,6 +1436,11 @@
1377
1436
  onChange(renamedObj, errorSchema && errorSchema && _extends({}, errorSchema, (_extends4 = {}, _extends4[value] = newErrorSchema, _extends4)));
1378
1437
  };
1379
1438
  };
1439
+ /** Handles the adding of a new additional property on the given `schema`. Calls the `onChange` callback once the new
1440
+ * default data for that field has been added to the formData.
1441
+ *
1442
+ * @param schema - The schema element to which the new property is being added
1443
+ */
1380
1444
  _this.handleAddClick = function (schema) {
1381
1445
  return function () {
1382
1446
  if (!schema.additionalProperties) {
@@ -1419,15 +1483,7 @@
1419
1483
  _proto.isRequired = function isRequired(name) {
1420
1484
  var schema = this.props.schema;
1421
1485
  return Array.isArray(schema.required) && schema.required.indexOf(name) !== -1;
1422
- }
1423
- /** Returns the `onPropertyChange` handler for the `name` field. Handles the special case where a user is attempting
1424
- * to clear the data for a field added as an additional property. Calls the `onChange()` handler with the updated
1425
- * formData.
1426
- *
1427
- * @param name - The name of the property
1428
- * @param addedByAdditionalProperties - Flag indicating whether this property is an additional property
1429
- * @returns - The onPropertyChange callback for the `name` property
1430
- */;
1486
+ };
1431
1487
  /** Returns a default value to be used for a new additional schema property of the given `type`
1432
1488
  *
1433
1489
  * @param type - The type of the new additional schema property
@@ -1450,12 +1506,7 @@
1450
1506
  // We don't have a datatype for some reason (perhaps additionalProperties was true)
1451
1507
  return translateString(utils.TranslatableString.NewStringDefault);
1452
1508
  }
1453
- }
1454
- /** Handles the adding of a new additional property on the given `schema`. Calls the `onChange` callback once the new
1455
- * default data for that field has been added to the formData.
1456
- *
1457
- * @param schema - The schema element to which the new property is being added
1458
- */;
1509
+ };
1459
1510
  /** Renders the `ObjectField` from the given props
1460
1511
  */
1461
1512
  _proto.render = function render() {
@@ -3589,10 +3640,6 @@
3589
3640
  /** The `Form` component renders the outer form and all the fields defined in the `schema` */
3590
3641
  var Form = /*#__PURE__*/function (_Component) {
3591
3642
  _inheritsLoose(Form, _Component);
3592
- /** The ref used to hold the `form` element, this needs to be `any` because `tagName` or `_internalFormWrapper` can
3593
- * provide any possible type here
3594
- */
3595
-
3596
3643
  /** Constructs the `Form` from the `props`. Will setup the initial state from the props. It will also call the
3597
3644
  * `onChange` handler if the initially provided `formData` is modified to add missing default values as part of the
3598
3645
  * state construction.
@@ -3602,7 +3649,15 @@
3602
3649
  function Form(props) {
3603
3650
  var _this;
3604
3651
  _this = _Component.call(this, props) || this;
3652
+ /** The ref used to hold the `form` element, this needs to be `any` because `tagName` or `_internalFormWrapper` can
3653
+ * provide any possible type here
3654
+ */
3605
3655
  _this.formElement = void 0;
3656
+ /** Returns the `formData` with only the elements specified in the `fields` list
3657
+ *
3658
+ * @param formData - The data for the `Form`
3659
+ * @param fields - The fields to keep while filtering
3660
+ */
3606
3661
  _this.getUsedFormData = function (formData, fields) {
3607
3662
  // For the case of a single input form
3608
3663
  if (fields.length === 0 && typeof formData !== 'object') {
@@ -3617,6 +3672,11 @@
3617
3672
  }
3618
3673
  return data;
3619
3674
  };
3675
+ /** Returns the list of field names from inspecting the `pathSchema` as well as using the `formData`
3676
+ *
3677
+ * @param pathSchema - The `PathSchema` object for the form
3678
+ * @param [formData] - The form data to use while checking for empty objects/arrays
3679
+ */
3620
3680
  _this.getFieldNames = function (pathSchema, formData) {
3621
3681
  var getAllPaths = function getAllPaths(_obj, acc, paths) {
3622
3682
  if (acc === void 0) {
@@ -3651,6 +3711,17 @@
3651
3711
  };
3652
3712
  return getAllPaths(pathSchema);
3653
3713
  };
3714
+ /** Function to handle changes made to a field in the `Form`. This handler receives an entirely new copy of the
3715
+ * `formData` along with a new `ErrorSchema`. It will first update the `formData` with any missing default fields and
3716
+ * then, if `omitExtraData` and `liveOmit` are turned on, the `formData` will be filterer to remove any extra data not
3717
+ * in a form field. Then, the resulting formData will be validated if required. The state will be updated with the new
3718
+ * updated (potentially filtered) `formData`, any errors that resulted from validation. Finally the `onChange`
3719
+ * callback will be called if specified with the updated state.
3720
+ *
3721
+ * @param formData - The new form data from a change to a field
3722
+ * @param newErrorSchema - The new `ErrorSchema` based on the field change
3723
+ * @param id - The id of the field that caused the change
3724
+ */
3654
3725
  _this.onChange = function (formData, newErrorSchema, id) {
3655
3726
  var _this$props = _this.props,
3656
3727
  extraErrors = _this$props.extraErrors,
@@ -3711,6 +3782,12 @@
3711
3782
  return onChange && onChange(_extends({}, _this.state, state), id);
3712
3783
  });
3713
3784
  };
3785
+ /**
3786
+ * Callback function to handle reset form data.
3787
+ * - Reset all fields with default values.
3788
+ * - Reset validations and errors
3789
+ *
3790
+ */
3714
3791
  _this.reset = function () {
3715
3792
  var onChange = _this.props.onChange;
3716
3793
  var newState = _this.getStateFromProps(_this.props, undefined);
@@ -3726,18 +3803,38 @@
3726
3803
  return onChange && onChange(_extends({}, _this.state, state));
3727
3804
  });
3728
3805
  };
3806
+ /** Callback function to handle when a field on the form is blurred. Calls the `onBlur` callback for the `Form` if it
3807
+ * was provided.
3808
+ *
3809
+ * @param id - The unique `id` of the field that was blurred
3810
+ * @param data - The data associated with the field that was blurred
3811
+ */
3729
3812
  _this.onBlur = function (id, data) {
3730
3813
  var onBlur = _this.props.onBlur;
3731
3814
  if (onBlur) {
3732
3815
  onBlur(id, data);
3733
3816
  }
3734
3817
  };
3818
+ /** Callback function to handle when a field on the form is focused. Calls the `onFocus` callback for the `Form` if it
3819
+ * was provided.
3820
+ *
3821
+ * @param id - The unique `id` of the field that was focused
3822
+ * @param data - The data associated with the field that was focused
3823
+ */
3735
3824
  _this.onFocus = function (id, data) {
3736
3825
  var onFocus = _this.props.onFocus;
3737
3826
  if (onFocus) {
3738
3827
  onFocus(id, data);
3739
3828
  }
3740
3829
  };
3830
+ /** Callback function to handle when the form is submitted. First, it prevents the default event behavior. Nothing
3831
+ * happens if the target and currentTarget of the event are not the same. It will omit any extra data in the
3832
+ * `formData` in the state if `omitExtraData` is true. It will validate the resulting `formData`, reporting errors
3833
+ * via the `onError()` callback unless validation is disabled. Finally it will add in any `extraErrors` and then call
3834
+ * back the `onSubmit` callback if it was provided.
3835
+ *
3836
+ * @param event - The submit HTML form event
3837
+ */
3741
3838
  _this.onSubmit = function (event) {
3742
3839
  event.preventDefault();
3743
3840
  if (event.target !== event.currentTarget) {
@@ -3930,12 +4027,7 @@
3930
4027
  });
3931
4028
  }
3932
4029
  return null;
3933
- }
3934
- /** Returns the `formData` with only the elements specified in the `fields` list
3935
- *
3936
- * @param formData - The data for the `Form`
3937
- * @param fields - The fields to keep while filtering
3938
- */;
4030
+ };
3939
4031
  /** Returns the registry for the form */
3940
4032
  _proto.getRegistry = function getRegistry() {
3941
4033
  var _this$props$templates;
@@ -4053,6 +4145,7 @@
4053
4145
  * needed along with the submit button or any children of the form.
4054
4146
  */;
4055
4147
  _proto.render = function render() {
4148
+ var _UI_OPTIONS_KEY, _submitUiSchema;
4056
4149
  var _this$props7 = this.props,
4057
4150
  children = _this$props7.children,
4058
4151
  id = _this$props7.id,
@@ -4092,6 +4185,17 @@
4092
4185
  // NOTE, the `as` prop is native to `semantic-ui` and is emulated in the `material-ui` theme
4093
4186
  var as = _internalFormWrapper ? tagName : undefined;
4094
4187
  var FormTag = _internalFormWrapper || tagName || 'form';
4188
+ var _getUiOptions = utils.getUiOptions(uiSchema),
4189
+ _getUiOptions$SUBMIT_ = _getUiOptions[utils.SUBMIT_BTN_OPTIONS_KEY],
4190
+ submitOptions = _getUiOptions$SUBMIT_ === void 0 ? {} : _getUiOptions$SUBMIT_;
4191
+ if (disabled) {
4192
+ submitOptions = _extends({}, submitOptions, {
4193
+ props: _extends({}, submitOptions.props, {
4194
+ disabled: true
4195
+ })
4196
+ });
4197
+ }
4198
+ var submitUiSchema = (_submitUiSchema = {}, _submitUiSchema[utils.UI_OPTIONS_KEY] = (_UI_OPTIONS_KEY = {}, _UI_OPTIONS_KEY[utils.SUBMIT_BTN_OPTIONS_KEY] = submitOptions, _UI_OPTIONS_KEY), _submitUiSchema);
4095
4199
  return jsxRuntime.jsxs(FormTag, {
4096
4200
  className: className ? className : 'rjsf',
4097
4201
  id: id,
@@ -4123,7 +4227,7 @@
4123
4227
  disabled: disabled,
4124
4228
  readonly: readonly
4125
4229
  }), children ? children : jsxRuntime.jsx(SubmitButton, {
4126
- uiSchema: uiSchema,
4230
+ uiSchema: submitUiSchema,
4127
4231
  registry: registry
4128
4232
  }), showErrorList === 'bottom' && this.renderErrors(registry)]
4129
4233
  });