@rjsf/core 5.0.0-beta.17 → 5.0.0-beta.18
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.cjs.development.js +52 -103
- package/dist/core.cjs.development.js.map +1 -1
- package/dist/core.cjs.production.min.js +1 -1
- package/dist/core.cjs.production.min.js.map +1 -1
- package/dist/core.esm.js +51 -102
- package/dist/core.esm.js.map +1 -1
- package/dist/core.umd.development.js +54 -105
- package/dist/core.umd.development.js.map +1 -1
- package/dist/core.umd.production.min.js +1 -1
- package/dist/core.umd.production.min.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/package.json +5 -5
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
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/
|
|
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/
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JSONSchemaForm = {}, global.React, global.utils, global.get, global.
|
|
5
|
-
})(this, (function (exports, React, utils, get,
|
|
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/omit'), require('lodash-es/has'), require('lodash-es/unset')) :
|
|
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/omit', 'lodash-es/has', 'lodash-es/unset'], factory) :
|
|
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.omit, global.has, global.unset));
|
|
5
|
+
})(this, (function (exports, React, utils, get, isEmpty, _pick, isObject, set, nanoid, omit, has, unset) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
9
9
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
10
10
|
var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
|
|
11
|
-
var
|
|
11
|
+
var isEmpty__default = /*#__PURE__*/_interopDefaultLegacy(isEmpty);
|
|
12
12
|
var _pick__default = /*#__PURE__*/_interopDefaultLegacy(_pick);
|
|
13
13
|
var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
|
|
14
14
|
var set__default = /*#__PURE__*/_interopDefaultLegacy(set);
|
|
15
|
+
var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
|
|
15
16
|
var has__default = /*#__PURE__*/_interopDefaultLegacy(has);
|
|
16
17
|
var unset__default = /*#__PURE__*/_interopDefaultLegacy(unset);
|
|
17
|
-
var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
|
|
18
18
|
|
|
19
19
|
function _defineProperties(target, props) {
|
|
20
20
|
for (var i = 0; i < props.length; i++) {
|
|
@@ -71,37 +71,6 @@
|
|
|
71
71
|
}
|
|
72
72
|
return target;
|
|
73
73
|
}
|
|
74
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
75
|
-
if (!o) return;
|
|
76
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
77
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
78
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
79
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
80
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
81
|
-
}
|
|
82
|
-
function _arrayLikeToArray(arr, len) {
|
|
83
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
84
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
85
|
-
return arr2;
|
|
86
|
-
}
|
|
87
|
-
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
88
|
-
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
89
|
-
if (it) return (it = it.call(o)).next.bind(it);
|
|
90
|
-
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
91
|
-
if (it) o = it;
|
|
92
|
-
var i = 0;
|
|
93
|
-
return function () {
|
|
94
|
-
if (i >= o.length) return {
|
|
95
|
-
done: true
|
|
96
|
-
};
|
|
97
|
-
return {
|
|
98
|
-
done: false,
|
|
99
|
-
value: o[i++]
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
104
|
-
}
|
|
105
74
|
function _toPrimitive(input, hint) {
|
|
106
75
|
if (typeof input !== "object" || input === null) return input;
|
|
107
76
|
var prim = input[Symbol.toPrimitive];
|
|
@@ -961,7 +930,7 @@
|
|
|
961
930
|
});
|
|
962
931
|
}
|
|
963
932
|
|
|
964
|
-
var _excluded$7 = ["widget"];
|
|
933
|
+
var _excluded$7 = ["widget", "placeholder", "autofocus", "autocomplete"];
|
|
965
934
|
/** The `AnyOfField` component is used to render a field in the schema that is an `anyOf`, `allOf` or `oneOf`. It tracks
|
|
966
935
|
* the currently selected option and cleans up any irrelevant data in `formData`.
|
|
967
936
|
*
|
|
@@ -977,38 +946,28 @@
|
|
|
977
946
|
var _this;
|
|
978
947
|
_this = _Component.call(this, props) || this;
|
|
979
948
|
_this.onOptionChange = function (option) {
|
|
980
|
-
var selectedOption =
|
|
949
|
+
var selectedOption = _this.state.selectedOption;
|
|
981
950
|
var _this$props = _this.props,
|
|
982
951
|
formData = _this$props.formData,
|
|
983
952
|
onChange = _this$props.onChange,
|
|
984
953
|
options = _this$props.options,
|
|
985
954
|
registry = _this$props.registry;
|
|
986
955
|
var schemaUtils = registry.schemaUtils;
|
|
987
|
-
var
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
var newFormData = undefined;
|
|
991
|
-
if (utils.guessType(formData) === "object" && (newOption.type === "object" || newOption.properties)) {
|
|
992
|
-
newFormData = Object.assign({}, formData);
|
|
993
|
-
var optionsToDiscard = options.slice();
|
|
994
|
-
optionsToDiscard.splice(selectedOption, 1);
|
|
995
|
-
// Discard any data added using other options
|
|
996
|
-
for (var _iterator = _createForOfIteratorHelperLoose(optionsToDiscard), _step; !(_step = _iterator()).done;) {
|
|
997
|
-
var _option = _step.value;
|
|
998
|
-
if (_option.properties) {
|
|
999
|
-
for (var key in _option.properties) {
|
|
1000
|
-
if (has__default["default"](newFormData, key)) {
|
|
1001
|
-
unset__default["default"](newFormData, key);
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
956
|
+
var intOption = option !== undefined ? parseInt(option, 10) : -1;
|
|
957
|
+
if (intOption === selectedOption) {
|
|
958
|
+
return;
|
|
1006
959
|
}
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
960
|
+
var newOption = intOption >= 0 ? schemaUtils.retrieveSchema(options[intOption], formData) : undefined;
|
|
961
|
+
var oldOption = selectedOption >= 0 ? schemaUtils.retrieveSchema(options[selectedOption], formData) : undefined;
|
|
962
|
+
var newFormData = schemaUtils.sanitizeDataForNewSchema(newOption, oldOption, formData);
|
|
963
|
+
if (newFormData && newOption) {
|
|
964
|
+
// Call getDefaultFormState to make sure defaults are populated on change. Pass "excludeObjectChildren"
|
|
965
|
+
// so that only the root objects themselves are created without adding undefined children properties
|
|
966
|
+
newFormData = schemaUtils.getDefaultFormState(newOption, newFormData, "excludeObjectChildren");
|
|
967
|
+
}
|
|
968
|
+
onChange(newFormData, undefined, _this.getFieldId());
|
|
1010
969
|
_this.setState({
|
|
1011
|
-
selectedOption:
|
|
970
|
+
selectedOption: intOption
|
|
1012
971
|
});
|
|
1013
972
|
};
|
|
1014
973
|
var _this$props2 = _this.props,
|
|
@@ -1050,8 +1009,8 @@
|
|
|
1050
1009
|
*/;
|
|
1051
1010
|
_proto.getMatchingOption = function getMatchingOption(selectedOption, formData, options) {
|
|
1052
1011
|
var schemaUtils = this.props.registry.schemaUtils;
|
|
1053
|
-
var option = schemaUtils.
|
|
1054
|
-
if (option
|
|
1012
|
+
var option = schemaUtils.getClosestMatchingOption(formData, options, selectedOption);
|
|
1013
|
+
if (option > 0) {
|
|
1055
1014
|
return option;
|
|
1056
1015
|
}
|
|
1057
1016
|
// If the form data matches none of the options, use the currently selected
|
|
@@ -1074,23 +1033,13 @@
|
|
|
1074
1033
|
*/;
|
|
1075
1034
|
_proto.render = function render() {
|
|
1076
1035
|
var _this$props5 = this.props,
|
|
1077
|
-
name = _this$props5.name,
|
|
1078
1036
|
baseType = _this$props5.baseType,
|
|
1079
1037
|
_this$props5$disabled = _this$props5.disabled,
|
|
1080
1038
|
disabled = _this$props5$disabled === void 0 ? false : _this$props5$disabled,
|
|
1081
|
-
_this$props5$readonly = _this$props5.readonly,
|
|
1082
|
-
readonly = _this$props5$readonly === void 0 ? false : _this$props5$readonly,
|
|
1083
|
-
_this$props5$hideErro = _this$props5.hideError,
|
|
1084
|
-
hideError = _this$props5$hideErro === void 0 ? false : _this$props5$hideErro,
|
|
1085
1039
|
_this$props5$errorSch = _this$props5.errorSchema,
|
|
1086
1040
|
errorSchema = _this$props5$errorSch === void 0 ? {} : _this$props5$errorSch,
|
|
1087
|
-
formData = _this$props5.formData,
|
|
1088
1041
|
formContext = _this$props5.formContext,
|
|
1089
|
-
idPrefix = _this$props5.idPrefix,
|
|
1090
|
-
idSeparator = _this$props5.idSeparator,
|
|
1091
|
-
idSchema = _this$props5.idSchema,
|
|
1092
1042
|
onBlur = _this$props5.onBlur,
|
|
1093
|
-
onChange = _this$props5.onChange,
|
|
1094
1043
|
onFocus = _this$props5.onFocus,
|
|
1095
1044
|
options = _this$props5.options,
|
|
1096
1045
|
registry = _this$props5.registry,
|
|
@@ -1102,10 +1051,15 @@
|
|
|
1102
1051
|
var _getUiOptions = utils.getUiOptions(uiSchema),
|
|
1103
1052
|
_getUiOptions$widget = _getUiOptions.widget,
|
|
1104
1053
|
widget = _getUiOptions$widget === void 0 ? "select" : _getUiOptions$widget,
|
|
1054
|
+
placeholder = _getUiOptions.placeholder,
|
|
1055
|
+
autofocus = _getUiOptions.autofocus,
|
|
1056
|
+
autocomplete = _getUiOptions.autocomplete,
|
|
1105
1057
|
uiOptions = _objectWithoutPropertiesLoose(_getUiOptions, _excluded$7);
|
|
1106
1058
|
var Widget = utils.getWidget({
|
|
1107
1059
|
type: "number"
|
|
1108
1060
|
}, widget, widgets);
|
|
1061
|
+
var rawErrors = get__default["default"](errorSchema, utils.ERRORS_KEY, []);
|
|
1062
|
+
var fieldErrorSchema = omit__default["default"](errorSchema, [utils.ERRORS_KEY]);
|
|
1109
1063
|
var option = options[selectedOption] || null;
|
|
1110
1064
|
var optionSchema;
|
|
1111
1065
|
if (option) {
|
|
@@ -1125,7 +1079,7 @@
|
|
|
1125
1079
|
className: "panel panel-default panel-body"
|
|
1126
1080
|
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1127
1081
|
className: "form-group"
|
|
1128
|
-
}, /*#__PURE__*/React__default["default"].createElement(Widget,
|
|
1082
|
+
}, /*#__PURE__*/React__default["default"].createElement(Widget, {
|
|
1129
1083
|
id: this.getFieldId(),
|
|
1130
1084
|
schema: {
|
|
1131
1085
|
type: "number",
|
|
@@ -1134,32 +1088,23 @@
|
|
|
1134
1088
|
onChange: this.onOptionChange,
|
|
1135
1089
|
onBlur: onBlur,
|
|
1136
1090
|
onFocus: onFocus,
|
|
1091
|
+
disabled: disabled || isEmpty__default["default"](enumOptions),
|
|
1092
|
+
multiple: false,
|
|
1093
|
+
rawErrors: rawErrors,
|
|
1094
|
+
errorSchema: fieldErrorSchema,
|
|
1137
1095
|
value: selectedOption,
|
|
1138
|
-
options: {
|
|
1096
|
+
options: _extends({
|
|
1139
1097
|
enumOptions: enumOptions
|
|
1140
|
-
},
|
|
1098
|
+
}, uiOptions),
|
|
1141
1099
|
registry: registry,
|
|
1142
|
-
formContext: formContext
|
|
1143
|
-
}, uiOptions, {
|
|
1144
|
-
label: ""
|
|
1145
|
-
}))), option !== null && /*#__PURE__*/React__default["default"].createElement(_SchemaField, {
|
|
1146
|
-
name: name,
|
|
1147
|
-
schema: optionSchema,
|
|
1148
|
-
uiSchema: uiSchema,
|
|
1149
|
-
errorSchema: errorSchema,
|
|
1150
|
-
idSchema: idSchema,
|
|
1151
|
-
idPrefix: idPrefix,
|
|
1152
|
-
idSeparator: idSeparator,
|
|
1153
|
-
formData: formData,
|
|
1154
1100
|
formContext: formContext,
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
}));
|
|
1101
|
+
placeholder: placeholder,
|
|
1102
|
+
autocomplete: autocomplete,
|
|
1103
|
+
autofocus: autofocus,
|
|
1104
|
+
label: ""
|
|
1105
|
+
})), option !== null && /*#__PURE__*/React__default["default"].createElement(_SchemaField, _extends({}, this.props, {
|
|
1106
|
+
schema: optionSchema
|
|
1107
|
+
})));
|
|
1163
1108
|
};
|
|
1164
1109
|
return AnyOfField;
|
|
1165
1110
|
}(React.Component);
|
|
@@ -1338,12 +1283,16 @@
|
|
|
1338
1283
|
var type = undefined;
|
|
1339
1284
|
if (isObject__default["default"](schema.additionalProperties)) {
|
|
1340
1285
|
type = schema.additionalProperties.type;
|
|
1341
|
-
|
|
1286
|
+
var apSchema = schema.additionalProperties;
|
|
1287
|
+
if (utils.REF_KEY in apSchema) {
|
|
1342
1288
|
var schemaUtils = registry.schemaUtils;
|
|
1343
|
-
|
|
1344
|
-
$ref:
|
|
1289
|
+
apSchema = schemaUtils.retrieveSchema({
|
|
1290
|
+
$ref: apSchema[utils.REF_KEY]
|
|
1345
1291
|
}, formData);
|
|
1346
|
-
type =
|
|
1292
|
+
type = apSchema.type;
|
|
1293
|
+
}
|
|
1294
|
+
if (!type && (utils.ANY_OF_KEY in apSchema || utils.ONE_OF_KEY in apSchema)) {
|
|
1295
|
+
type = "object";
|
|
1347
1296
|
}
|
|
1348
1297
|
}
|
|
1349
1298
|
var newKey = _this.getAvailableKey("newKey", newFormData);
|
|
@@ -3355,7 +3304,7 @@
|
|
|
3355
3304
|
var formValue = get__default["default"](formData, path);
|
|
3356
3305
|
// adds path to fieldNames if it points to a value
|
|
3357
3306
|
// or an empty object/array
|
|
3358
|
-
if (typeof formValue !== "object" ||
|
|
3307
|
+
if (typeof formValue !== "object" || isEmpty__default["default"](formValue)) {
|
|
3359
3308
|
acc.push(path);
|
|
3360
3309
|
}
|
|
3361
3310
|
});
|
|
@@ -3791,9 +3740,9 @@
|
|
|
3791
3740
|
widgets = _ref.widgets,
|
|
3792
3741
|
templates = _ref.templates,
|
|
3793
3742
|
directProps = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
3794
|
-
fields = _extends({}, themeProps.fields, fields);
|
|
3795
|
-
widgets = _extends({}, themeProps.widgets, widgets);
|
|
3796
|
-
templates = _extends({}, themeProps.templates, templates, {
|
|
3743
|
+
fields = _extends({}, themeProps === null || themeProps === void 0 ? void 0 : themeProps.fields, fields);
|
|
3744
|
+
widgets = _extends({}, themeProps === null || themeProps === void 0 ? void 0 : themeProps.widgets, widgets);
|
|
3745
|
+
templates = _extends({}, themeProps === null || themeProps === void 0 ? void 0 : themeProps.templates, templates, {
|
|
3797
3746
|
ButtonTemplates: _extends({}, themeProps === null || themeProps === void 0 ? void 0 : (_themeProps$templates = themeProps.templates) === null || _themeProps$templates === void 0 ? void 0 : _themeProps$templates.ButtonTemplates, (_templates = templates) === null || _templates === void 0 ? void 0 : _templates.ButtonTemplates)
|
|
3798
3747
|
});
|
|
3799
3748
|
return /*#__PURE__*/React__default["default"].createElement(Form, _extends({}, themeProps, directProps, {
|