@rjsf/core 5.0.0-beta.15 → 5.0.0-beta.16

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.
@@ -1,7 +1,7 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@rjsf/utils'), require('lodash-es/get'), require('lodash-es/isEmpty'), require('lodash-es/pick'), require('lodash-es/isObject'), require('lodash-es/set'), require('nanoid'), require('lodash-es/unset'), require('lodash-es/has'), require('lodash-es/omit')) :
3
3
  typeof define === 'function' && define.amd ? define(['exports', 'react', '@rjsf/utils', 'lodash-es/get', 'lodash-es/isEmpty', 'lodash-es/pick', 'lodash-es/isObject', 'lodash-es/set', 'nanoid', 'lodash-es/unset', 'lodash-es/has', 'lodash-es/omit'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@rjsf/core"] = {}, global.React, global.utils, global.get, global._isEmpty, global._pick, global.isObject, global.set, global.nanoid, global.unset, global.has, global.omit));
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JSONSchemaForm = {}, global.React, global.utils, global.get, global._isEmpty, global._pick, global.isObject, global.set, global.nanoid, global.unset, global.has, global.omit));
5
5
  })(this, (function (exports, React, utils, get, _isEmpty, _pick, isObject, set, nanoid, unset, has, omit) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -161,42 +161,11 @@
161
161
  return schemaUtils.getDefaultFormState(itemSchema);
162
162
  };
163
163
  _this.onAddClick = function (event) {
164
- if (event) {
165
- event.preventDefault();
166
- }
167
- var onChange = _this.props.onChange;
168
- var keyedFormData = _this.state.keyedFormData;
169
- var newKeyedFormDataRow = {
170
- key: generateRowId(),
171
- item: _this._getNewFormDataRow()
172
- };
173
- var newKeyedFormData = [].concat(keyedFormData, [newKeyedFormDataRow]);
174
- _this.setState({
175
- keyedFormData: newKeyedFormData,
176
- updatedKeyedFormData: true
177
- }, function () {
178
- return onChange(keyedToPlainFormData(newKeyedFormData));
179
- });
164
+ _this._handleAddClick(event);
180
165
  };
181
166
  _this.onAddIndexClick = function (index) {
182
167
  return function (event) {
183
- if (event) {
184
- event.preventDefault();
185
- }
186
- var onChange = _this.props.onChange;
187
- var keyedFormData = _this.state.keyedFormData;
188
- var newKeyedFormDataRow = {
189
- key: generateRowId(),
190
- item: _this._getNewFormDataRow()
191
- };
192
- var newKeyedFormData = [].concat(keyedFormData);
193
- newKeyedFormData.splice(index, 0, newKeyedFormDataRow);
194
- _this.setState({
195
- keyedFormData: newKeyedFormData,
196
- updatedKeyedFormData: true
197
- }, function () {
198
- return onChange(keyedToPlainFormData(newKeyedFormData));
199
- });
168
+ _this._handleAddClick(event, index);
200
169
  };
201
170
  };
202
171
  _this.onDropIndexClick = function (index) {
@@ -375,6 +344,42 @@
375
344
  /** Returns the default form information for an item based on the schema for that item. Deals with the possibility
376
345
  * that the schema is fixed and allows additional items.
377
346
  */;
347
+ /** Callback handler for when the user clicks on the add or add at index buttons. Creates a new row of keyed form data
348
+ * either at the end of the list (when index is not specified) or inserted at the `index` when it is, adding it into
349
+ * the state, and then returning `onChange()` with the plain form data converted from the keyed data
350
+ *
351
+ * @param event - The event for the click
352
+ * @param [index] - The optional index at which to add the new data
353
+ */
354
+ _proto._handleAddClick = function _handleAddClick(event, index) {
355
+ if (event) {
356
+ event.preventDefault();
357
+ }
358
+ var onChange = this.props.onChange;
359
+ var keyedFormData = this.state.keyedFormData;
360
+ var newKeyedFormDataRow = {
361
+ key: generateRowId(),
362
+ item: this._getNewFormDataRow()
363
+ };
364
+ var newKeyedFormData = [].concat(keyedFormData);
365
+ if (index !== undefined) {
366
+ newKeyedFormData.splice(index, 0, newKeyedFormDataRow);
367
+ } else {
368
+ newKeyedFormData.push(newKeyedFormDataRow);
369
+ }
370
+ this.setState({
371
+ keyedFormData: newKeyedFormData,
372
+ updatedKeyedFormData: true
373
+ }, function () {
374
+ return onChange(keyedToPlainFormData(newKeyedFormData));
375
+ });
376
+ }
377
+ /** Callback handler for when the user clicks on the add button. Creates a new row of keyed form data at the end of
378
+ * the list, adding it into the state, and then returning `onChange()` with the plain form data converted from the
379
+ * keyed data
380
+ *
381
+ * @param event - The event for the click
382
+ */;
378
383
  /** Renders the `ArrayField` depending on the specific needs of the schema and uischema elements
379
384
  */
380
385
  _proto.render = function render() {
@@ -443,8 +448,9 @@
443
448
  var _schemaItems = isObject__default["default"](schema.items) ? schema.items : {};
444
449
  var itemsSchema = schemaUtils.retrieveSchema(_schemaItems);
445
450
  var formData = keyedToPlainFormData(this.state.keyedFormData);
451
+ var canAdd = this.canAddItem(formData);
446
452
  var arrayProps = {
447
- canAdd: this.canAddItem(formData),
453
+ canAdd: canAdd,
448
454
  items: keyedFormData.map(function (keyedItem, index) {
449
455
  var key = keyedItem.key,
450
456
  item = keyedItem.item;
@@ -458,6 +464,7 @@
458
464
  key: key,
459
465
  index: index,
460
466
  name: name && name + "-" + index,
467
+ canAdd: canAdd,
461
468
  canMoveUp: index > 0,
462
469
  canMoveDown: index < formData.length - 1,
463
470
  itemSchema: itemSchema,
@@ -468,7 +475,8 @@
468
475
  autofocus: autofocus && index === 0,
469
476
  onBlur: onBlur,
470
477
  onFocus: onFocus,
471
- rawErrors: rawErrors
478
+ rawErrors: rawErrors,
479
+ totalItems: keyedFormData.length
472
480
  });
473
481
  }),
474
482
  className: "field field-array field-array-of-" + itemsSchema.type,
@@ -695,8 +703,9 @@
695
703
  items = items.concat(new Array(itemSchemas.length - items.length));
696
704
  }
697
705
  // These are the props passed into the render function
706
+ var canAdd = this.canAddItem(items) && !!additionalSchema;
698
707
  var arrayProps = {
699
- canAdd: this.canAddItem(items) && !!additionalSchema,
708
+ canAdd: canAdd,
700
709
  className: "field field-array field-array-fixed-items",
701
710
  disabled: disabled,
702
711
  idSchema: idSchema,
@@ -716,6 +725,7 @@
716
725
  key: key,
717
726
  index: index,
718
727
  name: name && name + "-" + index,
728
+ canAdd: canAdd,
719
729
  canRemove: additional,
720
730
  canMoveUp: index >= itemSchemas.length + 1,
721
731
  canMoveDown: additional && index < items.length - 1,
@@ -727,7 +737,8 @@
727
737
  autofocus: autofocus && index === 0,
728
738
  onBlur: onBlur,
729
739
  onFocus: onFocus,
730
- rawErrors: rawErrors
740
+ rawErrors: rawErrors,
741
+ totalItems: keyedFormData.length
731
742
  });
732
743
  }),
733
744
  onAddClick: this.onAddClick,
@@ -752,6 +763,7 @@
752
763
  var key = props.key,
753
764
  index = props.index,
754
765
  name = props.name,
766
+ canAdd = props.canAdd,
755
767
  _props$canRemove = props.canRemove,
756
768
  canRemove = _props$canRemove === void 0 ? true : _props$canRemove,
757
769
  _props$canMoveUp = props.canMoveUp,
@@ -766,7 +778,8 @@
766
778
  autofocus = props.autofocus,
767
779
  onBlur = props.onBlur,
768
780
  onFocus = props.onFocus,
769
- rawErrors = props.rawErrors;
781
+ rawErrors = props.rawErrors,
782
+ totalItems = props.totalItems;
770
783
  var _this$props13 = this.props,
771
784
  disabled = _this$props13.disabled,
772
785
  hideError = _this$props13.hideError,
@@ -819,11 +832,13 @@
819
832
  }),
820
833
  className: "array-item",
821
834
  disabled: disabled,
835
+ canAdd: canAdd,
822
836
  hasToolbar: has.toolbar,
823
837
  hasMoveUp: has.moveUp,
824
838
  hasMoveDown: has.moveDown,
825
839
  hasRemove: has.remove,
826
840
  index: index,
841
+ totalItems: totalItems,
827
842
  key: key,
828
843
  onAddIndexClick: this.onAddIndexClick,
829
844
  onDropIndexClick: this.onDropIndexClick,
@@ -1896,17 +1911,20 @@
1896
1911
  style: btnStyle,
1897
1912
  disabled: disabled || readonly || !hasMoveUp,
1898
1913
  onClick: onReorderClick(index, index - 1),
1899
- uiSchema: uiSchema
1914
+ uiSchema: uiSchema,
1915
+ registry: registry
1900
1916
  }), (hasMoveUp || hasMoveDown) && /*#__PURE__*/React__default["default"].createElement(MoveDownButton, {
1901
1917
  style: btnStyle,
1902
1918
  disabled: disabled || readonly || !hasMoveDown,
1903
1919
  onClick: onReorderClick(index, index + 1),
1904
- uiSchema: uiSchema
1920
+ uiSchema: uiSchema,
1921
+ registry: registry
1905
1922
  }), hasRemove && /*#__PURE__*/React__default["default"].createElement(RemoveButton, {
1906
1923
  style: btnStyle,
1907
1924
  disabled: disabled || readonly,
1908
1925
  onClick: onDropIndexClick(index),
1909
- uiSchema: uiSchema
1926
+ uiSchema: uiSchema,
1927
+ registry: registry
1910
1928
  }))));
1911
1929
  }
1912
1930
 
@@ -1962,7 +1980,8 @@
1962
1980
  className: "array-item-add",
1963
1981
  onClick: onAddClick,
1964
1982
  disabled: disabled || readonly,
1965
- uiSchema: uiSchema
1983
+ uiSchema: uiSchema,
1984
+ registry: registry
1966
1985
  }));
1967
1986
  }
1968
1987
 
@@ -2084,7 +2103,7 @@
2084
2103
  }), submitText));
2085
2104
  }
2086
2105
 
2087
- var _excluded$2 = ["iconType", "icon", "className", "uiSchema"];
2106
+ var _excluded$2 = ["iconType", "icon", "className", "uiSchema", "registry"];
2088
2107
  function IconButton(props) {
2089
2108
  var _props$iconType = props.iconType,
2090
2109
  iconType = _props$iconType === void 0 ? "default" : _props$iconType,
@@ -2129,7 +2148,8 @@
2129
2148
  function AddButton(_ref) {
2130
2149
  var className = _ref.className,
2131
2150
  onClick = _ref.onClick,
2132
- disabled = _ref.disabled;
2151
+ disabled = _ref.disabled,
2152
+ registry = _ref.registry;
2133
2153
  return /*#__PURE__*/React__default["default"].createElement("div", {
2134
2154
  className: "row"
2135
2155
  }, /*#__PURE__*/React__default["default"].createElement("p", {
@@ -2140,7 +2160,8 @@
2140
2160
  className: "btn-add col-xs-12",
2141
2161
  title: "Add",
2142
2162
  onClick: onClick,
2143
- disabled: disabled
2163
+ disabled: disabled,
2164
+ registry: registry
2144
2165
  })));
2145
2166
  }
2146
2167
 
@@ -2343,7 +2364,8 @@
2343
2364
  className: "object-property-expand",
2344
2365
  onClick: onAddClick(schema),
2345
2366
  disabled: disabled || readonly,
2346
- uiSchema: uiSchema
2367
+ uiSchema: uiSchema,
2368
+ registry: registry
2347
2369
  }));
2348
2370
  }
2349
2371
 
@@ -2435,7 +2457,8 @@
2435
2457
  },
2436
2458
  disabled: disabled || readonly,
2437
2459
  onClick: onDropPropertyClick(label),
2438
- uiSchema: uiSchema
2460
+ uiSchema: uiSchema,
2461
+ registry: registry
2439
2462
  }))));
2440
2463
  }
2441
2464
 
@@ -3573,9 +3596,10 @@
3573
3596
  var schemaUtils = altSchemaUtils ? altSchemaUtils : this.state.schemaUtils;
3574
3597
  var _this$props3 = this.props,
3575
3598
  customValidate = _this$props3.customValidate,
3576
- transformErrors = _this$props3.transformErrors;
3599
+ transformErrors = _this$props3.transformErrors,
3600
+ uiSchema = _this$props3.uiSchema;
3577
3601
  var resolvedSchema = schemaUtils.retrieveSchema(schema, formData);
3578
- return schemaUtils.getValidator().validateFormData(formData, resolvedSchema, customValidate, transformErrors);
3602
+ return schemaUtils.getValidator().validateFormData(formData, resolvedSchema, customValidate, transformErrors, uiSchema);
3579
3603
  }
3580
3604
  /** Renders any errors contained in the `state` in using the `ErrorList`, if not disabled by `showErrorList`. */;
3581
3605
  _proto.renderErrors = function renderErrors(registry) {
@@ -3744,7 +3768,8 @@
3744
3768
  disabled: disabled,
3745
3769
  readonly: readonly
3746
3770
  }), children ? children : /*#__PURE__*/React__default["default"].createElement(SubmitButton, {
3747
- uiSchema: uiSchema
3771
+ uiSchema: uiSchema,
3772
+ registry: registry
3748
3773
  }), showErrorList === "bottom" && this.renderErrors(registry));
3749
3774
  };
3750
3775
  return Form;