@rjsf/core 5.0.0-beta.14 → 5.0.0-beta.15
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 +1757 -1845
- 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 +1758 -1846
- package/dist/core.esm.js.map +1 -1
- package/dist/core.umd.development.js +1757 -1845
- 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/package.json +5 -5
|
@@ -16,6 +16,96 @@
|
|
|
16
16
|
var has__default = /*#__PURE__*/_interopDefaultLegacy(has);
|
|
17
17
|
var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
|
|
18
18
|
|
|
19
|
+
function _defineProperties(target, props) {
|
|
20
|
+
for (var i = 0; i < props.length; i++) {
|
|
21
|
+
var descriptor = props[i];
|
|
22
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
23
|
+
descriptor.configurable = true;
|
|
24
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
25
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
29
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
30
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
31
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
32
|
+
writable: false
|
|
33
|
+
});
|
|
34
|
+
return Constructor;
|
|
35
|
+
}
|
|
36
|
+
function _extends() {
|
|
37
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
38
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
39
|
+
var source = arguments[i];
|
|
40
|
+
for (var key in source) {
|
|
41
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
42
|
+
target[key] = source[key];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return target;
|
|
47
|
+
};
|
|
48
|
+
return _extends.apply(this, arguments);
|
|
49
|
+
}
|
|
50
|
+
function _inheritsLoose(subClass, superClass) {
|
|
51
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
52
|
+
subClass.prototype.constructor = subClass;
|
|
53
|
+
_setPrototypeOf(subClass, superClass);
|
|
54
|
+
}
|
|
55
|
+
function _setPrototypeOf(o, p) {
|
|
56
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
57
|
+
o.__proto__ = p;
|
|
58
|
+
return o;
|
|
59
|
+
};
|
|
60
|
+
return _setPrototypeOf(o, p);
|
|
61
|
+
}
|
|
62
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
63
|
+
if (source == null) return {};
|
|
64
|
+
var target = {};
|
|
65
|
+
var sourceKeys = Object.keys(source);
|
|
66
|
+
var key, i;
|
|
67
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
68
|
+
key = sourceKeys[i];
|
|
69
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
70
|
+
target[key] = source[key];
|
|
71
|
+
}
|
|
72
|
+
return target;
|
|
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
|
+
|
|
106
|
+
var _excluded$9 = ["widget"],
|
|
107
|
+
_excluded2 = ["widget"],
|
|
108
|
+
_excluded3 = ["widget"];
|
|
19
109
|
/** Used to generate a unique ID for an element in a row */
|
|
20
110
|
function generateRowId() {
|
|
21
111
|
return nanoid.nanoid();
|
|
@@ -26,10 +116,10 @@
|
|
|
26
116
|
* @returns - The `formData` converted into a `KeyedFormDataType` element
|
|
27
117
|
*/
|
|
28
118
|
function generateKeyedFormData(formData) {
|
|
29
|
-
return !Array.isArray(formData) ? [] : formData.map(item
|
|
119
|
+
return !Array.isArray(formData) ? [] : formData.map(function (item) {
|
|
30
120
|
return {
|
|
31
121
|
key: generateRowId(),
|
|
32
|
-
item
|
|
122
|
+
item: item
|
|
33
123
|
};
|
|
34
124
|
});
|
|
35
125
|
}
|
|
@@ -40,96 +130,90 @@
|
|
|
40
130
|
*/
|
|
41
131
|
function keyedToPlainFormData(keyedFormData) {
|
|
42
132
|
if (Array.isArray(keyedFormData)) {
|
|
43
|
-
return keyedFormData.map(
|
|
133
|
+
return keyedFormData.map(function (keyedItem) {
|
|
134
|
+
return keyedItem.item;
|
|
135
|
+
});
|
|
44
136
|
}
|
|
45
137
|
return [];
|
|
46
138
|
}
|
|
47
139
|
/** The `ArrayField` component is used to render a field in the schema that is of type `array`. It supports both normal
|
|
48
140
|
* and fixed array, allowing user to add and remove elements from the array data.
|
|
49
141
|
*/
|
|
50
|
-
|
|
142
|
+
var ArrayField = /*#__PURE__*/function (_Component) {
|
|
143
|
+
_inheritsLoose(ArrayField, _Component);
|
|
51
144
|
/** Constructs an `ArrayField` from the `props`, generating the initial keyed data from the `formData`
|
|
52
145
|
*
|
|
53
146
|
* @param props - The `FieldProps` for this template
|
|
54
147
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
} = registry;
|
|
65
|
-
let itemSchema = schema.items;
|
|
148
|
+
function ArrayField(props) {
|
|
149
|
+
var _this;
|
|
150
|
+
_this = _Component.call(this, props) || this;
|
|
151
|
+
_this._getNewFormDataRow = function () {
|
|
152
|
+
var _this$props = _this.props,
|
|
153
|
+
schema = _this$props.schema,
|
|
154
|
+
registry = _this$props.registry;
|
|
155
|
+
var schemaUtils = registry.schemaUtils;
|
|
156
|
+
var itemSchema = schema.items;
|
|
66
157
|
if (utils.isFixedItems(schema) && utils.allowAdditionalItems(schema)) {
|
|
67
158
|
itemSchema = schema.additionalItems;
|
|
68
159
|
}
|
|
69
160
|
// Cast this as a T to work around schema utils being for T[] caused by the FieldProps<T[], S, F> call on the class
|
|
70
161
|
return schemaUtils.getDefaultFormState(itemSchema);
|
|
71
162
|
};
|
|
72
|
-
|
|
163
|
+
_this.onAddClick = function (event) {
|
|
73
164
|
if (event) {
|
|
74
165
|
event.preventDefault();
|
|
75
166
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const {
|
|
80
|
-
keyedFormData
|
|
81
|
-
} = this.state;
|
|
82
|
-
const newKeyedFormDataRow = {
|
|
167
|
+
var onChange = _this.props.onChange;
|
|
168
|
+
var keyedFormData = _this.state.keyedFormData;
|
|
169
|
+
var newKeyedFormDataRow = {
|
|
83
170
|
key: generateRowId(),
|
|
84
|
-
item:
|
|
171
|
+
item: _this._getNewFormDataRow()
|
|
85
172
|
};
|
|
86
|
-
|
|
87
|
-
|
|
173
|
+
var newKeyedFormData = [].concat(keyedFormData, [newKeyedFormDataRow]);
|
|
174
|
+
_this.setState({
|
|
88
175
|
keyedFormData: newKeyedFormData,
|
|
89
176
|
updatedKeyedFormData: true
|
|
90
|
-
}, ()
|
|
177
|
+
}, function () {
|
|
178
|
+
return onChange(keyedToPlainFormData(newKeyedFormData));
|
|
179
|
+
});
|
|
91
180
|
};
|
|
92
|
-
|
|
93
|
-
return event
|
|
181
|
+
_this.onAddIndexClick = function (index) {
|
|
182
|
+
return function (event) {
|
|
94
183
|
if (event) {
|
|
95
184
|
event.preventDefault();
|
|
96
185
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const {
|
|
101
|
-
keyedFormData
|
|
102
|
-
} = this.state;
|
|
103
|
-
const newKeyedFormDataRow = {
|
|
186
|
+
var onChange = _this.props.onChange;
|
|
187
|
+
var keyedFormData = _this.state.keyedFormData;
|
|
188
|
+
var newKeyedFormDataRow = {
|
|
104
189
|
key: generateRowId(),
|
|
105
|
-
item:
|
|
190
|
+
item: _this._getNewFormDataRow()
|
|
106
191
|
};
|
|
107
|
-
|
|
192
|
+
var newKeyedFormData = [].concat(keyedFormData);
|
|
108
193
|
newKeyedFormData.splice(index, 0, newKeyedFormDataRow);
|
|
109
|
-
|
|
194
|
+
_this.setState({
|
|
110
195
|
keyedFormData: newKeyedFormData,
|
|
111
196
|
updatedKeyedFormData: true
|
|
112
|
-
}, ()
|
|
197
|
+
}, function () {
|
|
198
|
+
return onChange(keyedToPlainFormData(newKeyedFormData));
|
|
199
|
+
});
|
|
113
200
|
};
|
|
114
201
|
};
|
|
115
|
-
|
|
116
|
-
return event
|
|
202
|
+
_this.onDropIndexClick = function (index) {
|
|
203
|
+
return function (event) {
|
|
117
204
|
if (event) {
|
|
118
205
|
event.preventDefault();
|
|
119
206
|
}
|
|
120
|
-
|
|
121
|
-
onChange,
|
|
122
|
-
errorSchema
|
|
123
|
-
|
|
124
|
-
const {
|
|
125
|
-
keyedFormData
|
|
126
|
-
} = this.state;
|
|
207
|
+
var _this$props2 = _this.props,
|
|
208
|
+
onChange = _this$props2.onChange,
|
|
209
|
+
errorSchema = _this$props2.errorSchema;
|
|
210
|
+
var keyedFormData = _this.state.keyedFormData;
|
|
127
211
|
// refs #195: revalidate to ensure properly reindexing errors
|
|
128
|
-
|
|
212
|
+
var newErrorSchema;
|
|
129
213
|
if (errorSchema) {
|
|
130
214
|
newErrorSchema = {};
|
|
131
|
-
for (
|
|
132
|
-
|
|
215
|
+
for (var idx in errorSchema) {
|
|
216
|
+
var i = parseInt(idx);
|
|
133
217
|
if (i < index) {
|
|
134
218
|
set__default["default"](newErrorSchema, [i], errorSchema[idx]);
|
|
135
219
|
} else if (i > index) {
|
|
@@ -137,28 +221,31 @@
|
|
|
137
221
|
}
|
|
138
222
|
}
|
|
139
223
|
}
|
|
140
|
-
|
|
141
|
-
|
|
224
|
+
var newKeyedFormData = keyedFormData.filter(function (_, i) {
|
|
225
|
+
return i !== index;
|
|
226
|
+
});
|
|
227
|
+
_this.setState({
|
|
142
228
|
keyedFormData: newKeyedFormData,
|
|
143
229
|
updatedKeyedFormData: true
|
|
144
|
-
},
|
|
230
|
+
}, function () {
|
|
231
|
+
return onChange(keyedToPlainFormData(newKeyedFormData), newErrorSchema);
|
|
232
|
+
});
|
|
145
233
|
};
|
|
146
234
|
};
|
|
147
|
-
|
|
148
|
-
return event
|
|
235
|
+
_this.onReorderClick = function (index, newIndex) {
|
|
236
|
+
return function (event) {
|
|
149
237
|
if (event) {
|
|
150
238
|
event.preventDefault();
|
|
151
239
|
event.currentTarget.blur();
|
|
152
240
|
}
|
|
153
|
-
|
|
154
|
-
onChange,
|
|
155
|
-
errorSchema
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (this.props.errorSchema) {
|
|
241
|
+
var _this$props3 = _this.props,
|
|
242
|
+
onChange = _this$props3.onChange,
|
|
243
|
+
errorSchema = _this$props3.errorSchema;
|
|
244
|
+
var newErrorSchema;
|
|
245
|
+
if (_this.props.errorSchema) {
|
|
159
246
|
newErrorSchema = {};
|
|
160
|
-
for (
|
|
161
|
-
|
|
247
|
+
for (var idx in errorSchema) {
|
|
248
|
+
var i = parseInt(idx);
|
|
162
249
|
if (i == index) {
|
|
163
250
|
set__default["default"](newErrorSchema, [newIndex], errorSchema[index]);
|
|
164
251
|
} else if (i == newIndex) {
|
|
@@ -168,58 +255,54 @@
|
|
|
168
255
|
}
|
|
169
256
|
}
|
|
170
257
|
}
|
|
171
|
-
|
|
172
|
-
keyedFormData
|
|
173
|
-
} = this.state;
|
|
258
|
+
var keyedFormData = _this.state.keyedFormData;
|
|
174
259
|
function reOrderArray() {
|
|
175
260
|
// Copy item
|
|
176
|
-
|
|
261
|
+
var _newKeyedFormData = keyedFormData.slice();
|
|
177
262
|
// Moves item from index to newIndex
|
|
178
263
|
_newKeyedFormData.splice(index, 1);
|
|
179
264
|
_newKeyedFormData.splice(newIndex, 0, keyedFormData[index]);
|
|
180
265
|
return _newKeyedFormData;
|
|
181
266
|
}
|
|
182
|
-
|
|
183
|
-
|
|
267
|
+
var newKeyedFormData = reOrderArray();
|
|
268
|
+
_this.setState({
|
|
184
269
|
keyedFormData: newKeyedFormData
|
|
185
|
-
},
|
|
270
|
+
}, function () {
|
|
271
|
+
return onChange(keyedToPlainFormData(newKeyedFormData), newErrorSchema);
|
|
272
|
+
});
|
|
186
273
|
};
|
|
187
274
|
};
|
|
188
|
-
|
|
189
|
-
return (value, newErrorSchema, id)
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
275
|
+
_this.onChangeForIndex = function (index) {
|
|
276
|
+
return function (value, newErrorSchema, id) {
|
|
277
|
+
var _extends2;
|
|
278
|
+
var _this$props4 = _this.props,
|
|
279
|
+
formData = _this$props4.formData,
|
|
280
|
+
onChange = _this$props4.onChange,
|
|
281
|
+
errorSchema = _this$props4.errorSchema;
|
|
282
|
+
var arrayData = Array.isArray(formData) ? formData : [];
|
|
283
|
+
var newFormData = arrayData.map(function (item, i) {
|
|
197
284
|
// We need to treat undefined items as nulls to have validation.
|
|
198
285
|
// See https://github.com/tdegrunt/jsonschema/issues/206
|
|
199
|
-
|
|
286
|
+
var jsonValue = typeof value === "undefined" ? null : value;
|
|
200
287
|
return index === i ? jsonValue : item;
|
|
201
288
|
});
|
|
202
|
-
onChange(newFormData, errorSchema && errorSchema && {
|
|
203
|
-
...errorSchema,
|
|
204
|
-
[index]: newErrorSchema
|
|
205
|
-
}, id);
|
|
289
|
+
onChange(newFormData, errorSchema && errorSchema && _extends({}, errorSchema, (_extends2 = {}, _extends2[index] = newErrorSchema, _extends2)), id);
|
|
206
290
|
};
|
|
207
291
|
};
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
onChange,
|
|
211
|
-
idSchema
|
|
212
|
-
} = this.props;
|
|
292
|
+
_this.onSelectChange = function (value) {
|
|
293
|
+
var _this$props5 = _this.props,
|
|
294
|
+
onChange = _this$props5.onChange,
|
|
295
|
+
idSchema = _this$props5.idSchema;
|
|
213
296
|
onChange(value, undefined, idSchema && idSchema.$id);
|
|
214
297
|
};
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
this.state = {
|
|
298
|
+
var _props$formData = props.formData,
|
|
299
|
+
_formData = _props$formData === void 0 ? [] : _props$formData;
|
|
300
|
+
var _keyedFormData = generateKeyedFormData(_formData);
|
|
301
|
+
_this.state = {
|
|
220
302
|
keyedFormData: _keyedFormData,
|
|
221
303
|
updatedKeyedFormData: false
|
|
222
304
|
};
|
|
305
|
+
return _this;
|
|
223
306
|
}
|
|
224
307
|
/** React lifecycle method that is called when the props are about to change allowing the state to be updated. It
|
|
225
308
|
* regenerates the keyed form data and returns it
|
|
@@ -227,16 +310,16 @@
|
|
|
227
310
|
* @param nextProps - The next set of props data
|
|
228
311
|
* @param prevState - The previous set of state data
|
|
229
312
|
*/
|
|
230
|
-
|
|
313
|
+
ArrayField.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, prevState) {
|
|
231
314
|
// Don't call getDerivedStateFromProps if keyed formdata was just updated.
|
|
232
315
|
if (prevState.updatedKeyedFormData) {
|
|
233
316
|
return {
|
|
234
317
|
updatedKeyedFormData: false
|
|
235
318
|
};
|
|
236
319
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
320
|
+
var nextFormData = Array.isArray(nextProps.formData) ? nextProps.formData : [];
|
|
321
|
+
var previousKeyedFormData = prevState.keyedFormData || [];
|
|
322
|
+
var newKeyedFormData = nextFormData.length === previousKeyedFormData.length ? previousKeyedFormData.map(function (previousKeyedFormDatum, index) {
|
|
240
323
|
return {
|
|
241
324
|
key: previousKeyedFormDatum.key,
|
|
242
325
|
item: nextFormData[index]
|
|
@@ -248,20 +331,15 @@
|
|
|
248
331
|
}
|
|
249
332
|
/** Returns the appropriate title for an item by getting first the title from the schema.items, then falling back to
|
|
250
333
|
* the description from the schema.items, and finally the string "Item"
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
const {
|
|
254
|
-
schema
|
|
255
|
-
} = this.props;
|
|
256
|
-
return get__default["default"](schema, [utils.ITEMS_KEY, "title"], get__default["default"](schema, [utils.ITEMS_KEY, "description"], "Item"));
|
|
257
|
-
}
|
|
334
|
+
*/;
|
|
335
|
+
var _proto = ArrayField.prototype;
|
|
258
336
|
/** Determines whether the item described in the schema is always required, which is determined by whether any item
|
|
259
337
|
* may be null.
|
|
260
338
|
*
|
|
261
339
|
* @param itemSchema - The schema for the item
|
|
262
340
|
* @return - True if the item schema type does not contain the "null" type
|
|
263
341
|
*/
|
|
264
|
-
isItemRequired(itemSchema) {
|
|
342
|
+
_proto.isItemRequired = function isItemRequired(itemSchema) {
|
|
265
343
|
if (Array.isArray(itemSchema.type)) {
|
|
266
344
|
// While we don't yet support composite/nullable jsonschema types, it's
|
|
267
345
|
// future-proof to check for requirement against these.
|
|
@@ -276,15 +354,13 @@
|
|
|
276
354
|
*
|
|
277
355
|
* @param formItems - The list of items in the form
|
|
278
356
|
* @returns - True if the item is addable otherwise false
|
|
279
|
-
|
|
280
|
-
canAddItem(formItems) {
|
|
281
|
-
|
|
282
|
-
schema,
|
|
283
|
-
uiSchema
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
addable
|
|
287
|
-
} = utils.getUiOptions(uiSchema);
|
|
357
|
+
*/;
|
|
358
|
+
_proto.canAddItem = function canAddItem(formItems) {
|
|
359
|
+
var _this$props6 = this.props,
|
|
360
|
+
schema = _this$props6.schema,
|
|
361
|
+
uiSchema = _this$props6.uiSchema;
|
|
362
|
+
var _getUiOptions = utils.getUiOptions(uiSchema),
|
|
363
|
+
addable = _getUiOptions.addable;
|
|
288
364
|
if (addable !== false) {
|
|
289
365
|
// if ui:options.addable was not explicitly set to false, we can add
|
|
290
366
|
// another item if we have not exceeded maxItems yet
|
|
@@ -298,23 +374,19 @@
|
|
|
298
374
|
}
|
|
299
375
|
/** Returns the default form information for an item based on the schema for that item. Deals with the possibility
|
|
300
376
|
* that the schema is fixed and allows additional items.
|
|
301
|
-
|
|
302
|
-
|
|
377
|
+
*/;
|
|
303
378
|
/** Renders the `ArrayField` depending on the specific needs of the schema and uischema elements
|
|
304
379
|
*/
|
|
305
|
-
render() {
|
|
306
|
-
|
|
307
|
-
schema,
|
|
308
|
-
uiSchema,
|
|
309
|
-
idSchema,
|
|
310
|
-
registry
|
|
311
|
-
|
|
312
|
-
const {
|
|
313
|
-
schemaUtils
|
|
314
|
-
} = registry;
|
|
380
|
+
_proto.render = function render() {
|
|
381
|
+
var _this$props7 = this.props,
|
|
382
|
+
schema = _this$props7.schema,
|
|
383
|
+
uiSchema = _this$props7.uiSchema,
|
|
384
|
+
idSchema = _this$props7.idSchema,
|
|
385
|
+
registry = _this$props7.registry;
|
|
386
|
+
var schemaUtils = registry.schemaUtils;
|
|
315
387
|
if (!(utils.ITEMS_KEY in schema)) {
|
|
316
|
-
|
|
317
|
-
|
|
388
|
+
var uiOptions = utils.getUiOptions(uiSchema);
|
|
389
|
+
var UnsupportedFieldTemplate = utils.getTemplate("UnsupportedFieldTemplate", registry, uiOptions);
|
|
318
390
|
return /*#__PURE__*/React__default["default"].createElement(UnsupportedFieldTemplate, {
|
|
319
391
|
schema: schema,
|
|
320
392
|
idSchema: idSchema,
|
|
@@ -338,116 +410,115 @@
|
|
|
338
410
|
return this.renderNormalArray();
|
|
339
411
|
}
|
|
340
412
|
/** Renders a normal array without any limitations of length
|
|
341
|
-
|
|
342
|
-
renderNormalArray() {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
413
|
+
*/;
|
|
414
|
+
_proto.renderNormalArray = function renderNormalArray() {
|
|
415
|
+
var _this2 = this;
|
|
416
|
+
var _this$props8 = this.props,
|
|
417
|
+
schema = _this$props8.schema,
|
|
418
|
+
_this$props8$uiSchema = _this$props8.uiSchema,
|
|
419
|
+
uiSchema = _this$props8$uiSchema === void 0 ? {} : _this$props8$uiSchema,
|
|
420
|
+
errorSchema = _this$props8.errorSchema,
|
|
421
|
+
idSchema = _this$props8.idSchema,
|
|
422
|
+
name = _this$props8.name,
|
|
423
|
+
_this$props8$disabled = _this$props8.disabled,
|
|
424
|
+
disabled = _this$props8$disabled === void 0 ? false : _this$props8$disabled,
|
|
425
|
+
_this$props8$readonly = _this$props8.readonly,
|
|
426
|
+
readonly = _this$props8$readonly === void 0 ? false : _this$props8$readonly,
|
|
427
|
+
_this$props8$autofocu = _this$props8.autofocus,
|
|
428
|
+
autofocus = _this$props8$autofocu === void 0 ? false : _this$props8$autofocu,
|
|
429
|
+
_this$props8$required = _this$props8.required,
|
|
430
|
+
required = _this$props8$required === void 0 ? false : _this$props8$required,
|
|
431
|
+
registry = _this$props8.registry,
|
|
432
|
+
onBlur = _this$props8.onBlur,
|
|
433
|
+
onFocus = _this$props8.onFocus,
|
|
434
|
+
idPrefix = _this$props8.idPrefix,
|
|
435
|
+
_this$props8$idSepara = _this$props8.idSeparator,
|
|
436
|
+
idSeparator = _this$props8$idSepara === void 0 ? "_" : _this$props8$idSepara,
|
|
437
|
+
rawErrors = _this$props8.rawErrors;
|
|
438
|
+
var keyedFormData = this.state.keyedFormData;
|
|
439
|
+
var title = schema.title === undefined ? name : schema.title;
|
|
440
|
+
var schemaUtils = registry.schemaUtils,
|
|
441
|
+
formContext = registry.formContext;
|
|
442
|
+
var uiOptions = utils.getUiOptions(uiSchema);
|
|
443
|
+
var _schemaItems = isObject__default["default"](schema.items) ? schema.items : {};
|
|
444
|
+
var itemsSchema = schemaUtils.retrieveSchema(_schemaItems);
|
|
445
|
+
var formData = keyedToPlainFormData(this.state.keyedFormData);
|
|
446
|
+
var arrayProps = {
|
|
373
447
|
canAdd: this.canAddItem(formData),
|
|
374
|
-
items: keyedFormData.map((keyedItem, index)
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
item
|
|
378
|
-
} = keyedItem;
|
|
448
|
+
items: keyedFormData.map(function (keyedItem, index) {
|
|
449
|
+
var key = keyedItem.key,
|
|
450
|
+
item = keyedItem.item;
|
|
379
451
|
// While we are actually dealing with a single item of type T, the types require a T[], so cast
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
return
|
|
386
|
-
key,
|
|
387
|
-
index,
|
|
388
|
-
name: name &&
|
|
452
|
+
var itemCast = item;
|
|
453
|
+
var itemSchema = schemaUtils.retrieveSchema(_schemaItems, itemCast);
|
|
454
|
+
var itemErrorSchema = errorSchema ? errorSchema[index] : undefined;
|
|
455
|
+
var itemIdPrefix = idSchema.$id + idSeparator + index;
|
|
456
|
+
var itemIdSchema = schemaUtils.toIdSchema(itemSchema, itemIdPrefix, itemCast, idPrefix, idSeparator);
|
|
457
|
+
return _this2.renderArrayFieldItem({
|
|
458
|
+
key: key,
|
|
459
|
+
index: index,
|
|
460
|
+
name: name && name + "-" + index,
|
|
389
461
|
canMoveUp: index > 0,
|
|
390
462
|
canMoveDown: index < formData.length - 1,
|
|
391
|
-
itemSchema,
|
|
392
|
-
itemIdSchema,
|
|
393
|
-
itemErrorSchema,
|
|
463
|
+
itemSchema: itemSchema,
|
|
464
|
+
itemIdSchema: itemIdSchema,
|
|
465
|
+
itemErrorSchema: itemErrorSchema,
|
|
394
466
|
itemData: itemCast,
|
|
395
467
|
itemUiSchema: uiSchema.items,
|
|
396
468
|
autofocus: autofocus && index === 0,
|
|
397
|
-
onBlur,
|
|
398
|
-
onFocus,
|
|
399
|
-
rawErrors
|
|
469
|
+
onBlur: onBlur,
|
|
470
|
+
onFocus: onFocus,
|
|
471
|
+
rawErrors: rawErrors
|
|
400
472
|
});
|
|
401
473
|
}),
|
|
402
|
-
className:
|
|
403
|
-
disabled,
|
|
404
|
-
idSchema,
|
|
405
|
-
uiSchema,
|
|
474
|
+
className: "field field-array field-array-of-" + itemsSchema.type,
|
|
475
|
+
disabled: disabled,
|
|
476
|
+
idSchema: idSchema,
|
|
477
|
+
uiSchema: uiSchema,
|
|
406
478
|
onAddClick: this.onAddClick,
|
|
407
|
-
readonly,
|
|
408
|
-
required,
|
|
409
|
-
schema,
|
|
410
|
-
title,
|
|
411
|
-
formContext,
|
|
412
|
-
formData,
|
|
413
|
-
rawErrors,
|
|
414
|
-
registry
|
|
479
|
+
readonly: readonly,
|
|
480
|
+
required: required,
|
|
481
|
+
schema: schema,
|
|
482
|
+
title: title,
|
|
483
|
+
formContext: formContext,
|
|
484
|
+
formData: formData,
|
|
485
|
+
rawErrors: rawErrors,
|
|
486
|
+
registry: registry
|
|
415
487
|
};
|
|
416
|
-
|
|
417
|
-
return /*#__PURE__*/React__default["default"].createElement(Template, {
|
|
418
|
-
...arrayProps
|
|
419
|
-
});
|
|
488
|
+
var Template = utils.getTemplate("ArrayFieldTemplate", registry, uiOptions);
|
|
489
|
+
return /*#__PURE__*/React__default["default"].createElement(Template, _extends({}, arrayProps));
|
|
420
490
|
}
|
|
421
491
|
/** Renders an array using the custom widget provided by the user in the `uiSchema`
|
|
422
|
-
|
|
423
|
-
renderCustomWidget() {
|
|
424
|
-
|
|
425
|
-
schema,
|
|
426
|
-
idSchema,
|
|
427
|
-
uiSchema,
|
|
428
|
-
disabled =
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
492
|
+
*/;
|
|
493
|
+
_proto.renderCustomWidget = function renderCustomWidget() {
|
|
494
|
+
var _this$props9 = this.props,
|
|
495
|
+
schema = _this$props9.schema,
|
|
496
|
+
idSchema = _this$props9.idSchema,
|
|
497
|
+
uiSchema = _this$props9.uiSchema,
|
|
498
|
+
_this$props9$disabled = _this$props9.disabled,
|
|
499
|
+
disabled = _this$props9$disabled === void 0 ? false : _this$props9$disabled,
|
|
500
|
+
_this$props9$readonly = _this$props9.readonly,
|
|
501
|
+
readonly = _this$props9$readonly === void 0 ? false : _this$props9$readonly,
|
|
502
|
+
_this$props9$autofocu = _this$props9.autofocus,
|
|
503
|
+
autofocus = _this$props9$autofocu === void 0 ? false : _this$props9$autofocu,
|
|
504
|
+
_this$props9$required = _this$props9.required,
|
|
505
|
+
required = _this$props9$required === void 0 ? false : _this$props9$required,
|
|
506
|
+
hideError = _this$props9.hideError,
|
|
507
|
+
placeholder = _this$props9.placeholder,
|
|
508
|
+
onBlur = _this$props9.onBlur,
|
|
509
|
+
onFocus = _this$props9.onFocus,
|
|
510
|
+
_this$props9$formData = _this$props9.formData,
|
|
511
|
+
items = _this$props9$formData === void 0 ? [] : _this$props9$formData,
|
|
512
|
+
registry = _this$props9.registry,
|
|
513
|
+
rawErrors = _this$props9.rawErrors,
|
|
514
|
+
name = _this$props9.name;
|
|
515
|
+
var widgets = registry.widgets,
|
|
516
|
+
formContext = registry.formContext;
|
|
517
|
+
var title = schema.title || name;
|
|
518
|
+
var _getUiOptions2 = utils.getUiOptions(uiSchema),
|
|
519
|
+
widget = _getUiOptions2.widget,
|
|
520
|
+
options = _objectWithoutPropertiesLoose(_getUiOptions2, _excluded$9);
|
|
521
|
+
var Widget = utils.getWidget(schema, widget, widgets);
|
|
451
522
|
return /*#__PURE__*/React__default["default"].createElement(Widget, {
|
|
452
523
|
id: idSchema && idSchema.$id,
|
|
453
524
|
multiple: true,
|
|
@@ -471,47 +542,48 @@
|
|
|
471
542
|
});
|
|
472
543
|
}
|
|
473
544
|
/** Renders an array as a set of checkboxes
|
|
474
|
-
|
|
475
|
-
renderMultiSelect() {
|
|
476
|
-
|
|
477
|
-
schema,
|
|
478
|
-
idSchema,
|
|
479
|
-
uiSchema,
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
545
|
+
*/;
|
|
546
|
+
_proto.renderMultiSelect = function renderMultiSelect() {
|
|
547
|
+
var _this$props10 = this.props,
|
|
548
|
+
schema = _this$props10.schema,
|
|
549
|
+
idSchema = _this$props10.idSchema,
|
|
550
|
+
uiSchema = _this$props10.uiSchema,
|
|
551
|
+
_this$props10$formDat = _this$props10.formData,
|
|
552
|
+
items = _this$props10$formDat === void 0 ? [] : _this$props10$formDat,
|
|
553
|
+
_this$props10$disable = _this$props10.disabled,
|
|
554
|
+
disabled = _this$props10$disable === void 0 ? false : _this$props10$disable,
|
|
555
|
+
_this$props10$readonl = _this$props10.readonly,
|
|
556
|
+
readonly = _this$props10$readonl === void 0 ? false : _this$props10$readonl,
|
|
557
|
+
_this$props10$autofoc = _this$props10.autofocus,
|
|
558
|
+
autofocus = _this$props10$autofoc === void 0 ? false : _this$props10$autofoc,
|
|
559
|
+
_this$props10$require = _this$props10.required,
|
|
560
|
+
required = _this$props10$require === void 0 ? false : _this$props10$require,
|
|
561
|
+
placeholder = _this$props10.placeholder,
|
|
562
|
+
onBlur = _this$props10.onBlur,
|
|
563
|
+
onFocus = _this$props10.onFocus,
|
|
564
|
+
registry = _this$props10.registry,
|
|
565
|
+
rawErrors = _this$props10.rawErrors,
|
|
566
|
+
name = _this$props10.name;
|
|
567
|
+
var widgets = registry.widgets,
|
|
568
|
+
schemaUtils = registry.schemaUtils,
|
|
569
|
+
formContext = registry.formContext;
|
|
570
|
+
var itemsSchema = schemaUtils.retrieveSchema(schema.items, items);
|
|
571
|
+
var title = schema.title || name;
|
|
572
|
+
var enumOptions = utils.optionsList(itemsSchema);
|
|
573
|
+
var _getUiOptions3 = utils.getUiOptions(uiSchema),
|
|
574
|
+
_getUiOptions3$widget = _getUiOptions3.widget,
|
|
575
|
+
widget = _getUiOptions3$widget === void 0 ? "select" : _getUiOptions3$widget,
|
|
576
|
+
options = _objectWithoutPropertiesLoose(_getUiOptions3, _excluded2);
|
|
577
|
+
var Widget = utils.getWidget(schema, widget, widgets);
|
|
505
578
|
return /*#__PURE__*/React__default["default"].createElement(Widget, {
|
|
506
579
|
id: idSchema && idSchema.$id,
|
|
507
580
|
multiple: true,
|
|
508
581
|
onChange: this.onSelectChange,
|
|
509
582
|
onBlur: onBlur,
|
|
510
583
|
onFocus: onFocus,
|
|
511
|
-
options: {
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
},
|
|
584
|
+
options: _extends({}, options, {
|
|
585
|
+
enumOptions: enumOptions
|
|
586
|
+
}),
|
|
515
587
|
schema: schema,
|
|
516
588
|
uiSchema: uiSchema,
|
|
517
589
|
registry: registry,
|
|
@@ -527,33 +599,35 @@
|
|
|
527
599
|
});
|
|
528
600
|
}
|
|
529
601
|
/** Renders an array of files using the `FileWidget`
|
|
530
|
-
|
|
531
|
-
renderFiles() {
|
|
532
|
-
|
|
533
|
-
schema,
|
|
534
|
-
uiSchema,
|
|
535
|
-
idSchema,
|
|
536
|
-
name,
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
602
|
+
*/;
|
|
603
|
+
_proto.renderFiles = function renderFiles() {
|
|
604
|
+
var _this$props11 = this.props,
|
|
605
|
+
schema = _this$props11.schema,
|
|
606
|
+
uiSchema = _this$props11.uiSchema,
|
|
607
|
+
idSchema = _this$props11.idSchema,
|
|
608
|
+
name = _this$props11.name,
|
|
609
|
+
_this$props11$disable = _this$props11.disabled,
|
|
610
|
+
disabled = _this$props11$disable === void 0 ? false : _this$props11$disable,
|
|
611
|
+
_this$props11$readonl = _this$props11.readonly,
|
|
612
|
+
readonly = _this$props11$readonl === void 0 ? false : _this$props11$readonl,
|
|
613
|
+
_this$props11$autofoc = _this$props11.autofocus,
|
|
614
|
+
autofocus = _this$props11$autofoc === void 0 ? false : _this$props11$autofoc,
|
|
615
|
+
_this$props11$require = _this$props11.required,
|
|
616
|
+
required = _this$props11$require === void 0 ? false : _this$props11$require,
|
|
617
|
+
onBlur = _this$props11.onBlur,
|
|
618
|
+
onFocus = _this$props11.onFocus,
|
|
619
|
+
registry = _this$props11.registry,
|
|
620
|
+
_this$props11$formDat = _this$props11.formData,
|
|
621
|
+
items = _this$props11$formDat === void 0 ? [] : _this$props11$formDat,
|
|
622
|
+
rawErrors = _this$props11.rawErrors;
|
|
623
|
+
var title = schema.title || name;
|
|
624
|
+
var widgets = registry.widgets,
|
|
625
|
+
formContext = registry.formContext;
|
|
626
|
+
var _getUiOptions4 = utils.getUiOptions(uiSchema),
|
|
627
|
+
_getUiOptions4$widget = _getUiOptions4.widget,
|
|
628
|
+
widget = _getUiOptions4$widget === void 0 ? "files" : _getUiOptions4$widget,
|
|
629
|
+
options = _objectWithoutPropertiesLoose(_getUiOptions4, _excluded3);
|
|
630
|
+
var Widget = utils.getWidget(schema, widget, widgets);
|
|
557
631
|
return /*#__PURE__*/React__default["default"].createElement(Widget, {
|
|
558
632
|
options: options,
|
|
559
633
|
id: idSchema && idSchema.$id,
|
|
@@ -576,150 +650,150 @@
|
|
|
576
650
|
});
|
|
577
651
|
}
|
|
578
652
|
/** Renders an array that has a maximum limit of items
|
|
579
|
-
|
|
580
|
-
renderFixedArray() {
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
653
|
+
*/;
|
|
654
|
+
_proto.renderFixedArray = function renderFixedArray() {
|
|
655
|
+
var _this3 = this;
|
|
656
|
+
var _this$props12 = this.props,
|
|
657
|
+
schema = _this$props12.schema,
|
|
658
|
+
_this$props12$uiSchem = _this$props12.uiSchema,
|
|
659
|
+
uiSchema = _this$props12$uiSchem === void 0 ? {} : _this$props12$uiSchem,
|
|
660
|
+
_this$props12$formDat = _this$props12.formData,
|
|
661
|
+
formData = _this$props12$formDat === void 0 ? [] : _this$props12$formDat,
|
|
662
|
+
errorSchema = _this$props12.errorSchema,
|
|
663
|
+
idPrefix = _this$props12.idPrefix,
|
|
664
|
+
_this$props12$idSepar = _this$props12.idSeparator,
|
|
665
|
+
idSeparator = _this$props12$idSepar === void 0 ? "_" : _this$props12$idSepar,
|
|
666
|
+
idSchema = _this$props12.idSchema,
|
|
667
|
+
name = _this$props12.name,
|
|
668
|
+
_this$props12$disable = _this$props12.disabled,
|
|
669
|
+
disabled = _this$props12$disable === void 0 ? false : _this$props12$disable,
|
|
670
|
+
_this$props12$readonl = _this$props12.readonly,
|
|
671
|
+
readonly = _this$props12$readonl === void 0 ? false : _this$props12$readonl,
|
|
672
|
+
_this$props12$autofoc = _this$props12.autofocus,
|
|
673
|
+
autofocus = _this$props12$autofoc === void 0 ? false : _this$props12$autofoc,
|
|
674
|
+
_this$props12$require = _this$props12.required,
|
|
675
|
+
required = _this$props12$require === void 0 ? false : _this$props12$require,
|
|
676
|
+
registry = _this$props12.registry,
|
|
677
|
+
onBlur = _this$props12.onBlur,
|
|
678
|
+
onFocus = _this$props12.onFocus,
|
|
679
|
+
rawErrors = _this$props12.rawErrors;
|
|
680
|
+
var keyedFormData = this.state.keyedFormData;
|
|
681
|
+
var _this$props$formData = this.props.formData,
|
|
682
|
+
items = _this$props$formData === void 0 ? [] : _this$props$formData;
|
|
683
|
+
var title = schema.title || name;
|
|
684
|
+
var uiOptions = utils.getUiOptions(uiSchema);
|
|
685
|
+
var schemaUtils = registry.schemaUtils,
|
|
686
|
+
formContext = registry.formContext;
|
|
687
|
+
var _schemaItems = isObject__default["default"](schema.items) ? schema.items : [];
|
|
688
|
+
var itemSchemas = _schemaItems.map(function (item, index) {
|
|
689
|
+
return schemaUtils.retrieveSchema(item, formData[index]);
|
|
690
|
+
});
|
|
691
|
+
var additionalSchema = isObject__default["default"](schema.additionalItems) ? schemaUtils.retrieveSchema(schema.additionalItems, formData) : null;
|
|
614
692
|
if (!items || items.length < itemSchemas.length) {
|
|
615
693
|
// to make sure at least all fixed items are generated
|
|
616
694
|
items = items || [];
|
|
617
695
|
items = items.concat(new Array(itemSchemas.length - items.length));
|
|
618
696
|
}
|
|
619
697
|
// These are the props passed into the render function
|
|
620
|
-
|
|
698
|
+
var arrayProps = {
|
|
621
699
|
canAdd: this.canAddItem(items) && !!additionalSchema,
|
|
622
700
|
className: "field field-array field-array-fixed-items",
|
|
623
|
-
disabled,
|
|
624
|
-
idSchema,
|
|
625
|
-
formData,
|
|
626
|
-
items: keyedFormData.map((keyedItem, index)
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
item
|
|
630
|
-
} = keyedItem;
|
|
701
|
+
disabled: disabled,
|
|
702
|
+
idSchema: idSchema,
|
|
703
|
+
formData: formData,
|
|
704
|
+
items: keyedFormData.map(function (keyedItem, index) {
|
|
705
|
+
var key = keyedItem.key,
|
|
706
|
+
item = keyedItem.item;
|
|
631
707
|
// While we are actually dealing with a single item of type T, the types require a T[], so cast
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
return
|
|
640
|
-
key,
|
|
641
|
-
index,
|
|
642
|
-
name: name &&
|
|
708
|
+
var itemCast = item;
|
|
709
|
+
var additional = index >= itemSchemas.length;
|
|
710
|
+
var itemSchema = additional && isObject__default["default"](schema.additionalItems) ? schemaUtils.retrieveSchema(schema.additionalItems, itemCast) : itemSchemas[index];
|
|
711
|
+
var itemIdPrefix = idSchema.$id + idSeparator + index;
|
|
712
|
+
var itemIdSchema = schemaUtils.toIdSchema(itemSchema, itemIdPrefix, itemCast, idPrefix, idSeparator);
|
|
713
|
+
var itemUiSchema = additional ? uiSchema.additionalItems || {} : Array.isArray(uiSchema.items) ? uiSchema.items[index] : uiSchema.items || {};
|
|
714
|
+
var itemErrorSchema = errorSchema ? errorSchema[index] : undefined;
|
|
715
|
+
return _this3.renderArrayFieldItem({
|
|
716
|
+
key: key,
|
|
717
|
+
index: index,
|
|
718
|
+
name: name && name + "-" + index,
|
|
643
719
|
canRemove: additional,
|
|
644
720
|
canMoveUp: index >= itemSchemas.length + 1,
|
|
645
721
|
canMoveDown: additional && index < items.length - 1,
|
|
646
|
-
itemSchema,
|
|
722
|
+
itemSchema: itemSchema,
|
|
647
723
|
itemData: itemCast,
|
|
648
|
-
itemUiSchema,
|
|
649
|
-
itemIdSchema,
|
|
650
|
-
itemErrorSchema,
|
|
724
|
+
itemUiSchema: itemUiSchema,
|
|
725
|
+
itemIdSchema: itemIdSchema,
|
|
726
|
+
itemErrorSchema: itemErrorSchema,
|
|
651
727
|
autofocus: autofocus && index === 0,
|
|
652
|
-
onBlur,
|
|
653
|
-
onFocus,
|
|
654
|
-
rawErrors
|
|
728
|
+
onBlur: onBlur,
|
|
729
|
+
onFocus: onFocus,
|
|
730
|
+
rawErrors: rawErrors
|
|
655
731
|
});
|
|
656
732
|
}),
|
|
657
733
|
onAddClick: this.onAddClick,
|
|
658
|
-
readonly,
|
|
659
|
-
required,
|
|
660
|
-
registry,
|
|
661
|
-
schema,
|
|
662
|
-
uiSchema,
|
|
663
|
-
title,
|
|
664
|
-
formContext,
|
|
665
|
-
rawErrors
|
|
734
|
+
readonly: readonly,
|
|
735
|
+
required: required,
|
|
736
|
+
registry: registry,
|
|
737
|
+
schema: schema,
|
|
738
|
+
uiSchema: uiSchema,
|
|
739
|
+
title: title,
|
|
740
|
+
formContext: formContext,
|
|
741
|
+
rawErrors: rawErrors
|
|
666
742
|
};
|
|
667
|
-
|
|
668
|
-
return /*#__PURE__*/React__default["default"].createElement(Template, {
|
|
669
|
-
...arrayProps
|
|
670
|
-
});
|
|
743
|
+
var Template = utils.getTemplate("ArrayFieldTemplate", registry, uiOptions);
|
|
744
|
+
return /*#__PURE__*/React__default["default"].createElement(Template, _extends({}, arrayProps));
|
|
671
745
|
}
|
|
672
746
|
/** Renders the individual array item using a `SchemaField` along with the additional properties required to be send
|
|
673
747
|
* back to the `ArrayFieldItemTemplate`.
|
|
674
748
|
*
|
|
675
749
|
* @param props - The props for the individual array item to be rendered
|
|
676
|
-
|
|
677
|
-
renderArrayFieldItem(props) {
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
canRemove = true,
|
|
683
|
-
canMoveUp =
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
fields
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
} = utils.getUiOptions(uiSchema);
|
|
716
|
-
const has = {
|
|
750
|
+
*/;
|
|
751
|
+
_proto.renderArrayFieldItem = function renderArrayFieldItem(props) {
|
|
752
|
+
var key = props.key,
|
|
753
|
+
index = props.index,
|
|
754
|
+
name = props.name,
|
|
755
|
+
_props$canRemove = props.canRemove,
|
|
756
|
+
canRemove = _props$canRemove === void 0 ? true : _props$canRemove,
|
|
757
|
+
_props$canMoveUp = props.canMoveUp,
|
|
758
|
+
canMoveUp = _props$canMoveUp === void 0 ? true : _props$canMoveUp,
|
|
759
|
+
_props$canMoveDown = props.canMoveDown,
|
|
760
|
+
canMoveDown = _props$canMoveDown === void 0 ? true : _props$canMoveDown,
|
|
761
|
+
itemSchema = props.itemSchema,
|
|
762
|
+
itemData = props.itemData,
|
|
763
|
+
itemUiSchema = props.itemUiSchema,
|
|
764
|
+
itemIdSchema = props.itemIdSchema,
|
|
765
|
+
itemErrorSchema = props.itemErrorSchema,
|
|
766
|
+
autofocus = props.autofocus,
|
|
767
|
+
onBlur = props.onBlur,
|
|
768
|
+
onFocus = props.onFocus,
|
|
769
|
+
rawErrors = props.rawErrors;
|
|
770
|
+
var _this$props13 = this.props,
|
|
771
|
+
disabled = _this$props13.disabled,
|
|
772
|
+
hideError = _this$props13.hideError,
|
|
773
|
+
idPrefix = _this$props13.idPrefix,
|
|
774
|
+
idSeparator = _this$props13.idSeparator,
|
|
775
|
+
readonly = _this$props13.readonly,
|
|
776
|
+
uiSchema = _this$props13.uiSchema,
|
|
777
|
+
registry = _this$props13.registry,
|
|
778
|
+
formContext = _this$props13.formContext;
|
|
779
|
+
var _registry$fields = registry.fields,
|
|
780
|
+
ArraySchemaField = _registry$fields.ArraySchemaField,
|
|
781
|
+
SchemaField = _registry$fields.SchemaField;
|
|
782
|
+
var ItemSchemaField = ArraySchemaField || SchemaField;
|
|
783
|
+
var _getUiOptions5 = utils.getUiOptions(uiSchema),
|
|
784
|
+
_getUiOptions5$ordera = _getUiOptions5.orderable,
|
|
785
|
+
orderable = _getUiOptions5$ordera === void 0 ? true : _getUiOptions5$ordera,
|
|
786
|
+
_getUiOptions5$remova = _getUiOptions5.removable,
|
|
787
|
+
removable = _getUiOptions5$remova === void 0 ? true : _getUiOptions5$remova;
|
|
788
|
+
var has = {
|
|
717
789
|
moveUp: orderable && canMoveUp,
|
|
718
790
|
moveDown: orderable && canMoveDown,
|
|
719
791
|
remove: removable && canRemove,
|
|
720
792
|
toolbar: false
|
|
721
793
|
};
|
|
722
|
-
has.toolbar = Object.keys(has).some(
|
|
794
|
+
has.toolbar = Object.keys(has).some(function (key) {
|
|
795
|
+
return has[key];
|
|
796
|
+
});
|
|
723
797
|
return {
|
|
724
798
|
children: /*#__PURE__*/React__default["default"].createElement(ItemSchemaField, {
|
|
725
799
|
name: name,
|
|
@@ -744,75 +818,83 @@
|
|
|
744
818
|
rawErrors: rawErrors
|
|
745
819
|
}),
|
|
746
820
|
className: "array-item",
|
|
747
|
-
disabled,
|
|
821
|
+
disabled: disabled,
|
|
748
822
|
hasToolbar: has.toolbar,
|
|
749
823
|
hasMoveUp: has.moveUp,
|
|
750
824
|
hasMoveDown: has.moveDown,
|
|
751
825
|
hasRemove: has.remove,
|
|
752
|
-
index,
|
|
753
|
-
key,
|
|
826
|
+
index: index,
|
|
827
|
+
key: key,
|
|
754
828
|
onAddIndexClick: this.onAddIndexClick,
|
|
755
829
|
onDropIndexClick: this.onDropIndexClick,
|
|
756
830
|
onReorderClick: this.onReorderClick,
|
|
757
|
-
readonly,
|
|
758
|
-
registry,
|
|
831
|
+
readonly: readonly,
|
|
832
|
+
registry: registry,
|
|
833
|
+
schema: itemSchema,
|
|
759
834
|
uiSchema: itemUiSchema
|
|
760
835
|
};
|
|
761
|
-
}
|
|
762
|
-
|
|
836
|
+
};
|
|
837
|
+
_createClass(ArrayField, [{
|
|
838
|
+
key: "itemTitle",
|
|
839
|
+
get: function get() {
|
|
840
|
+
var schema = this.props.schema;
|
|
841
|
+
return get__default["default"](schema, [utils.ITEMS_KEY, "title"], get__default["default"](schema, [utils.ITEMS_KEY, "description"], "Item"));
|
|
842
|
+
}
|
|
843
|
+
}]);
|
|
844
|
+
return ArrayField;
|
|
845
|
+
}(React.Component);
|
|
763
846
|
|
|
847
|
+
var _excluded$8 = ["widget"];
|
|
764
848
|
/** The `BooleanField` component is used to render a field in the schema is boolean. It constructs `enumOptions` for the
|
|
765
849
|
* two boolean values based on the various alternatives in the schema.
|
|
766
850
|
*
|
|
767
851
|
* @param props - The `FieldProps` for this template
|
|
768
852
|
*/
|
|
769
853
|
function BooleanField(props) {
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
const {
|
|
794
|
-
widget = "checkbox",
|
|
795
|
-
...options
|
|
796
|
-
} = utils.getUiOptions(uiSchema);
|
|
797
|
-
const Widget = utils.getWidget(schema, widget, widgets);
|
|
798
|
-
let enumOptions;
|
|
854
|
+
var schema = props.schema,
|
|
855
|
+
name = props.name,
|
|
856
|
+
uiSchema = props.uiSchema,
|
|
857
|
+
idSchema = props.idSchema,
|
|
858
|
+
formData = props.formData,
|
|
859
|
+
registry = props.registry,
|
|
860
|
+
required = props.required,
|
|
861
|
+
disabled = props.disabled,
|
|
862
|
+
readonly = props.readonly,
|
|
863
|
+
autofocus = props.autofocus,
|
|
864
|
+
onChange = props.onChange,
|
|
865
|
+
onFocus = props.onFocus,
|
|
866
|
+
onBlur = props.onBlur,
|
|
867
|
+
rawErrors = props.rawErrors;
|
|
868
|
+
var title = schema.title;
|
|
869
|
+
var widgets = registry.widgets,
|
|
870
|
+
formContext = registry.formContext;
|
|
871
|
+
var _getUiOptions = utils.getUiOptions(uiSchema),
|
|
872
|
+
_getUiOptions$widget = _getUiOptions.widget,
|
|
873
|
+
widget = _getUiOptions$widget === void 0 ? "checkbox" : _getUiOptions$widget,
|
|
874
|
+
options = _objectWithoutPropertiesLoose(_getUiOptions, _excluded$8);
|
|
875
|
+
var Widget = utils.getWidget(schema, widget, widgets);
|
|
876
|
+
var enumOptions;
|
|
799
877
|
if (Array.isArray(schema.oneOf)) {
|
|
800
878
|
enumOptions = utils.optionsList({
|
|
801
|
-
oneOf: schema.oneOf.map(option
|
|
879
|
+
oneOf: schema.oneOf.map(function (option) {
|
|
802
880
|
if (isObject__default["default"](option)) {
|
|
803
|
-
return {
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
};
|
|
881
|
+
return _extends({}, option, {
|
|
882
|
+
title: option.title || (option["const"] === true ? "Yes" : "No")
|
|
883
|
+
});
|
|
807
884
|
}
|
|
808
885
|
return undefined;
|
|
809
|
-
}).filter(
|
|
886
|
+
}).filter(function (o) {
|
|
887
|
+
return o;
|
|
888
|
+
}) // cast away the error that typescript can't grok is fixed
|
|
810
889
|
});
|
|
811
890
|
} else {
|
|
891
|
+
var _schema$enum;
|
|
812
892
|
// We deprecated enumNames in v5. It's intentionally omitted from RSJFSchema type, so we need to cast here.
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
if (!schemaWithEnumNames.enumNames && enums.length === 2 && enums.every(
|
|
893
|
+
var schemaWithEnumNames = schema;
|
|
894
|
+
var enums = (_schema$enum = schema["enum"]) != null ? _schema$enum : [true, false];
|
|
895
|
+
if (!schemaWithEnumNames.enumNames && enums.length === 2 && enums.every(function (v) {
|
|
896
|
+
return typeof v === "boolean";
|
|
897
|
+
})) {
|
|
816
898
|
enumOptions = [{
|
|
817
899
|
value: enums[0],
|
|
818
900
|
label: enums[0] ? "Yes" : "No"
|
|
@@ -822,17 +904,16 @@
|
|
|
822
904
|
}];
|
|
823
905
|
} else {
|
|
824
906
|
enumOptions = utils.optionsList({
|
|
825
|
-
enum: enums,
|
|
907
|
+
"enum": enums,
|
|
826
908
|
// NOTE: enumNames is deprecated, but still supported for now.
|
|
827
909
|
enumNames: schemaWithEnumNames.enumNames
|
|
828
910
|
});
|
|
829
911
|
}
|
|
830
912
|
}
|
|
831
913
|
return /*#__PURE__*/React__default["default"].createElement(Widget, {
|
|
832
|
-
options: {
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
},
|
|
914
|
+
options: _extends({}, options, {
|
|
915
|
+
enumOptions: enumOptions
|
|
916
|
+
}),
|
|
836
917
|
schema: schema,
|
|
837
918
|
uiSchema: uiSchema,
|
|
838
919
|
id: idSchema && idSchema.$id,
|
|
@@ -851,41 +932,42 @@
|
|
|
851
932
|
});
|
|
852
933
|
}
|
|
853
934
|
|
|
935
|
+
var _excluded$7 = ["widget"];
|
|
854
936
|
/** The `AnyOfField` component is used to render a field in the schema that is an `anyOf`, `allOf` or `oneOf`. It tracks
|
|
855
937
|
* the currently selected option and cleans up any irrelevant data in `formData`.
|
|
856
938
|
*
|
|
857
939
|
* @param props - The `FieldProps` for this template
|
|
858
940
|
*/
|
|
859
|
-
|
|
941
|
+
var AnyOfField = /*#__PURE__*/function (_Component) {
|
|
942
|
+
_inheritsLoose(AnyOfField, _Component);
|
|
860
943
|
/** Constructs an `AnyOfField` with the given `props` to initialize the initially selected option in state
|
|
861
944
|
*
|
|
862
945
|
* @param props - The `FieldProps` for this template
|
|
863
946
|
*/
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
} = registry;
|
|
877
|
-
const newOption = schemaUtils.retrieveSchema(options[selectedOption], formData);
|
|
947
|
+
function AnyOfField(props) {
|
|
948
|
+
var _this;
|
|
949
|
+
_this = _Component.call(this, props) || this;
|
|
950
|
+
_this.onOptionChange = function (option) {
|
|
951
|
+
var selectedOption = parseInt(option, 10);
|
|
952
|
+
var _this$props = _this.props,
|
|
953
|
+
formData = _this$props.formData,
|
|
954
|
+
onChange = _this$props.onChange,
|
|
955
|
+
options = _this$props.options,
|
|
956
|
+
registry = _this$props.registry;
|
|
957
|
+
var schemaUtils = registry.schemaUtils;
|
|
958
|
+
var newOption = schemaUtils.retrieveSchema(options[selectedOption], formData);
|
|
878
959
|
// If the new option is of type object and the current data is an object,
|
|
879
960
|
// discard properties added using the old option.
|
|
880
|
-
|
|
961
|
+
var newFormData = undefined;
|
|
881
962
|
if (utils.guessType(formData) === "object" && (newOption.type === "object" || newOption.properties)) {
|
|
882
963
|
newFormData = Object.assign({}, formData);
|
|
883
|
-
|
|
964
|
+
var optionsToDiscard = options.slice();
|
|
884
965
|
optionsToDiscard.splice(selectedOption, 1);
|
|
885
966
|
// Discard any data added using other options
|
|
886
|
-
for (
|
|
887
|
-
|
|
888
|
-
|
|
967
|
+
for (var _iterator = _createForOfIteratorHelperLoose(optionsToDiscard), _step; !(_step = _iterator()).done;) {
|
|
968
|
+
var _option = _step.value;
|
|
969
|
+
if (_option.properties) {
|
|
970
|
+
for (var key in _option.properties) {
|
|
889
971
|
if (key in newFormData) {
|
|
890
972
|
unset__default["default"](newFormData, key);
|
|
891
973
|
}
|
|
@@ -895,18 +977,18 @@
|
|
|
895
977
|
}
|
|
896
978
|
// Call getDefaultFormState to make sure defaults are populated on change. Pass "excludeObjectChildren"
|
|
897
979
|
// so that only the root objects themselves are created without adding undefined children properties
|
|
898
|
-
onChange(schemaUtils.getDefaultFormState(options[selectedOption], newFormData, "excludeObjectChildren"), undefined,
|
|
899
|
-
|
|
980
|
+
onChange(schemaUtils.getDefaultFormState(options[selectedOption], newFormData, "excludeObjectChildren"), undefined, _this.getFieldId());
|
|
981
|
+
_this.setState({
|
|
900
982
|
selectedOption: parseInt(option, 10)
|
|
901
983
|
});
|
|
902
984
|
};
|
|
903
|
-
|
|
904
|
-
formData
|
|
905
|
-
options
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
selectedOption: this.getMatchingOption(0, _formData, _options)
|
|
985
|
+
var _this$props2 = _this.props,
|
|
986
|
+
_formData = _this$props2.formData,
|
|
987
|
+
_options = _this$props2.options;
|
|
988
|
+
_this.state = {
|
|
989
|
+
selectedOption: _this.getMatchingOption(0, _formData, _options)
|
|
909
990
|
};
|
|
991
|
+
return _this;
|
|
910
992
|
}
|
|
911
993
|
/** React lifecycle methos that is called when the props and/or state for this component is updated. It recomputes the
|
|
912
994
|
* currently selected option based on the overall `formData`
|
|
@@ -914,17 +996,15 @@
|
|
|
914
996
|
* @param prevProps - The previous `FieldProps` for this template
|
|
915
997
|
* @param prevState - The previous `AnyOfFieldState` for this template
|
|
916
998
|
*/
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
selectedOption
|
|
925
|
-
} = this.state;
|
|
999
|
+
var _proto = AnyOfField.prototype;
|
|
1000
|
+
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
|
|
1001
|
+
var _this$props3 = this.props,
|
|
1002
|
+
formData = _this$props3.formData,
|
|
1003
|
+
options = _this$props3.options,
|
|
1004
|
+
idSchema = _this$props3.idSchema;
|
|
1005
|
+
var selectedOption = this.state.selectedOption;
|
|
926
1006
|
if (!utils.deepEquals(formData, prevProps.formData) && idSchema.$id === prevProps.idSchema.$id) {
|
|
927
|
-
|
|
1007
|
+
var matchingOption = this.getMatchingOption(selectedOption, formData, options);
|
|
928
1008
|
if (!prevState || matchingOption === selectedOption) {
|
|
929
1009
|
return;
|
|
930
1010
|
}
|
|
@@ -938,12 +1018,10 @@
|
|
|
938
1018
|
* @param formData - The new formData
|
|
939
1019
|
* @param options - The list of options to choose from
|
|
940
1020
|
* @return - The index of the `option` that best matches the `formData`
|
|
941
|
-
|
|
942
|
-
getMatchingOption(selectedOption, formData, options) {
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
} = this.props.registry;
|
|
946
|
-
const option = schemaUtils.getMatchingOption(formData, options);
|
|
1021
|
+
*/;
|
|
1022
|
+
_proto.getMatchingOption = function getMatchingOption(selectedOption, formData, options) {
|
|
1023
|
+
var schemaUtils = this.props.registry.schemaUtils;
|
|
1024
|
+
var option = schemaUtils.getMatchingOption(formData, options);
|
|
947
1025
|
if (option !== 0) {
|
|
948
1026
|
return option;
|
|
949
1027
|
}
|
|
@@ -956,56 +1034,51 @@
|
|
|
956
1034
|
* the `onChange` handler.
|
|
957
1035
|
*
|
|
958
1036
|
* @param option -
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
} = this.props;
|
|
966
|
-
return `${idSchema.$id}${schema.oneOf ? "__oneof_select" : "__anyof_select"}`;
|
|
1037
|
+
*/;
|
|
1038
|
+
_proto.getFieldId = function getFieldId() {
|
|
1039
|
+
var _this$props4 = this.props,
|
|
1040
|
+
idSchema = _this$props4.idSchema,
|
|
1041
|
+
schema = _this$props4.schema;
|
|
1042
|
+
return "" + idSchema.$id + (schema.oneOf ? "__oneof_select" : "__anyof_select");
|
|
967
1043
|
}
|
|
968
1044
|
/** Renders the `AnyOfField` selector along with a `SchemaField` for the value of the `formData`
|
|
969
|
-
|
|
970
|
-
render() {
|
|
971
|
-
|
|
972
|
-
name,
|
|
973
|
-
baseType,
|
|
974
|
-
disabled =
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
...uiOptions
|
|
1003
|
-
} = utils.getUiOptions(uiSchema);
|
|
1004
|
-
const Widget = utils.getWidget({
|
|
1045
|
+
*/;
|
|
1046
|
+
_proto.render = function render() {
|
|
1047
|
+
var _this$props5 = this.props,
|
|
1048
|
+
name = _this$props5.name,
|
|
1049
|
+
baseType = _this$props5.baseType,
|
|
1050
|
+
_this$props5$disabled = _this$props5.disabled,
|
|
1051
|
+
disabled = _this$props5$disabled === void 0 ? false : _this$props5$disabled,
|
|
1052
|
+
_this$props5$readonly = _this$props5.readonly,
|
|
1053
|
+
readonly = _this$props5$readonly === void 0 ? false : _this$props5$readonly,
|
|
1054
|
+
_this$props5$hideErro = _this$props5.hideError,
|
|
1055
|
+
hideError = _this$props5$hideErro === void 0 ? false : _this$props5$hideErro,
|
|
1056
|
+
_this$props5$errorSch = _this$props5.errorSchema,
|
|
1057
|
+
errorSchema = _this$props5$errorSch === void 0 ? {} : _this$props5$errorSch,
|
|
1058
|
+
formData = _this$props5.formData,
|
|
1059
|
+
formContext = _this$props5.formContext,
|
|
1060
|
+
idPrefix = _this$props5.idPrefix,
|
|
1061
|
+
idSeparator = _this$props5.idSeparator,
|
|
1062
|
+
idSchema = _this$props5.idSchema,
|
|
1063
|
+
onBlur = _this$props5.onBlur,
|
|
1064
|
+
onChange = _this$props5.onChange,
|
|
1065
|
+
onFocus = _this$props5.onFocus,
|
|
1066
|
+
options = _this$props5.options,
|
|
1067
|
+
registry = _this$props5.registry,
|
|
1068
|
+
uiSchema = _this$props5.uiSchema;
|
|
1069
|
+
var widgets = registry.widgets,
|
|
1070
|
+
fields = registry.fields;
|
|
1071
|
+
var _SchemaField = fields.SchemaField;
|
|
1072
|
+
var selectedOption = this.state.selectedOption;
|
|
1073
|
+
var _getUiOptions = utils.getUiOptions(uiSchema),
|
|
1074
|
+
_getUiOptions$widget = _getUiOptions.widget,
|
|
1075
|
+
widget = _getUiOptions$widget === void 0 ? "select" : _getUiOptions$widget,
|
|
1076
|
+
uiOptions = _objectWithoutPropertiesLoose(_getUiOptions, _excluded$7);
|
|
1077
|
+
var Widget = utils.getWidget({
|
|
1005
1078
|
type: "number"
|
|
1006
1079
|
}, widget, widgets);
|
|
1007
|
-
|
|
1008
|
-
|
|
1080
|
+
var option = options[selectedOption] || null;
|
|
1081
|
+
var optionSchema;
|
|
1009
1082
|
if (option) {
|
|
1010
1083
|
// If the subschema doesn't declare a type, infer the type from the
|
|
1011
1084
|
// parent schema
|
|
@@ -1013,32 +1086,34 @@
|
|
|
1013
1086
|
type: baseType
|
|
1014
1087
|
});
|
|
1015
1088
|
}
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1089
|
+
var enumOptions = options.map(function (option, index) {
|
|
1090
|
+
return {
|
|
1091
|
+
label: option.title || "Option " + (index + 1),
|
|
1092
|
+
value: index
|
|
1093
|
+
};
|
|
1094
|
+
});
|
|
1020
1095
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1021
1096
|
className: "panel panel-default panel-body"
|
|
1022
1097
|
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1023
1098
|
className: "form-group"
|
|
1024
|
-
}, /*#__PURE__*/React__default["default"].createElement(Widget, {
|
|
1099
|
+
}, /*#__PURE__*/React__default["default"].createElement(Widget, _extends({
|
|
1025
1100
|
id: this.getFieldId(),
|
|
1026
1101
|
schema: {
|
|
1027
1102
|
type: "number",
|
|
1028
|
-
default: 0
|
|
1103
|
+
"default": 0
|
|
1029
1104
|
},
|
|
1030
1105
|
onChange: this.onOptionChange,
|
|
1031
1106
|
onBlur: onBlur,
|
|
1032
1107
|
onFocus: onFocus,
|
|
1033
1108
|
value: selectedOption,
|
|
1034
1109
|
options: {
|
|
1035
|
-
enumOptions
|
|
1110
|
+
enumOptions: enumOptions
|
|
1036
1111
|
},
|
|
1037
1112
|
registry: registry,
|
|
1038
|
-
formContext: formContext
|
|
1039
|
-
|
|
1113
|
+
formContext: formContext
|
|
1114
|
+
}, uiOptions, {
|
|
1040
1115
|
label: ""
|
|
1041
|
-
})), option !== null && /*#__PURE__*/React__default["default"].createElement(_SchemaField, {
|
|
1116
|
+
}))), option !== null && /*#__PURE__*/React__default["default"].createElement(_SchemaField, {
|
|
1042
1117
|
name: name,
|
|
1043
1118
|
schema: optionSchema,
|
|
1044
1119
|
uiSchema: uiSchema,
|
|
@@ -1056,19 +1131,20 @@
|
|
|
1056
1131
|
readonly: readonly,
|
|
1057
1132
|
hideError: hideError
|
|
1058
1133
|
}));
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1134
|
+
};
|
|
1135
|
+
return AnyOfField;
|
|
1136
|
+
}(React.Component);
|
|
1061
1137
|
|
|
1062
1138
|
// Matches a string that ends in a . character, optionally followed by a sequence of
|
|
1063
1139
|
// digits followed by any number of 0 characters up until the end of the line.
|
|
1064
1140
|
// Ensuring that there is at least one prefixed character is important so that
|
|
1065
1141
|
// you don't incorrectly match against "0".
|
|
1066
|
-
|
|
1142
|
+
var trailingCharMatcherWithPrefix = /\.([0-9]*0)*$/;
|
|
1067
1143
|
// This is used for trimming the trailing 0 and . characters without affecting
|
|
1068
1144
|
// the rest of the string. Its possible to use one RegEx with groups for this
|
|
1069
1145
|
// functionality, but it is fairly complex compared to simply defining two
|
|
1070
1146
|
// different matchers.
|
|
1071
|
-
|
|
1147
|
+
var trailingCharMatcher = /[0.]0*$/;
|
|
1072
1148
|
/**
|
|
1073
1149
|
* The NumberField class has some special handling for dealing with trailing
|
|
1074
1150
|
* decimal points and/or zeroes. This logic is designed to allow trailing values
|
|
@@ -1087,51 +1163,48 @@
|
|
|
1087
1163
|
* value is passed to the input instead of the formData value
|
|
1088
1164
|
*/
|
|
1089
1165
|
function NumberField(props) {
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
} = registry.fields;
|
|
1100
|
-
let value = formData;
|
|
1166
|
+
var registry = props.registry,
|
|
1167
|
+
onChange = props.onChange,
|
|
1168
|
+
formData = props.formData,
|
|
1169
|
+
initialValue = props.value;
|
|
1170
|
+
var _useState = React.useState(initialValue),
|
|
1171
|
+
lastValue = _useState[0],
|
|
1172
|
+
setLastValue = _useState[1];
|
|
1173
|
+
var StringField = registry.fields.StringField;
|
|
1174
|
+
var value = formData;
|
|
1101
1175
|
/** Handle the change from the `StringField` to properly convert to a number
|
|
1102
1176
|
*
|
|
1103
1177
|
* @param value - The current value for the change occurring
|
|
1104
1178
|
*/
|
|
1105
|
-
|
|
1179
|
+
var handleChange = React.useCallback(function (value) {
|
|
1106
1180
|
// Cache the original value in component state
|
|
1107
1181
|
setLastValue(value);
|
|
1108
1182
|
// Normalize decimals that don't start with a zero character in advance so
|
|
1109
1183
|
// that the rest of the normalization logic is simpler
|
|
1110
|
-
if (
|
|
1111
|
-
value =
|
|
1184
|
+
if (("" + value).charAt(0) === ".") {
|
|
1185
|
+
value = "0" + value;
|
|
1112
1186
|
}
|
|
1113
1187
|
// Check that the value is a string (this can happen if the widget used is a
|
|
1114
1188
|
// <select>, due to an enum declaration etc) then, if the value ends in a
|
|
1115
1189
|
// trailing decimal point or multiple zeroes, strip the trailing values
|
|
1116
|
-
|
|
1190
|
+
var processed = typeof value === "string" && value.match(trailingCharMatcherWithPrefix) ? utils.asNumber(value.replace(trailingCharMatcher, "")) : utils.asNumber(value);
|
|
1117
1191
|
onChange(processed);
|
|
1118
1192
|
}, [onChange]);
|
|
1119
1193
|
if (typeof lastValue === "string" && typeof value === "number") {
|
|
1120
1194
|
// Construct a regular expression that checks for a string that consists
|
|
1121
1195
|
// of the formData value suffixed with zero or one '.' characters and zero
|
|
1122
1196
|
// or more '0' characters
|
|
1123
|
-
|
|
1197
|
+
var re = new RegExp(("" + value).replace(".", "\\.") + "\\.?0*$");
|
|
1124
1198
|
// If the cached "lastValue" is a match, use that instead of the formData
|
|
1125
1199
|
// value to prevent the input value from changing in the UI
|
|
1126
1200
|
if (lastValue.match(re)) {
|
|
1127
1201
|
value = lastValue;
|
|
1128
1202
|
}
|
|
1129
1203
|
}
|
|
1130
|
-
return /*#__PURE__*/React__default["default"].createElement(StringField, {
|
|
1131
|
-
...props,
|
|
1204
|
+
return /*#__PURE__*/React__default["default"].createElement(StringField, _extends({}, props, {
|
|
1132
1205
|
formData: value,
|
|
1133
1206
|
onChange: handleChange
|
|
1134
|
-
});
|
|
1207
|
+
}));
|
|
1135
1208
|
}
|
|
1136
1209
|
|
|
1137
1210
|
/** The `ObjectField` component is used to render a field in the schema that is of type `object`. It tracks whether an
|
|
@@ -1139,25 +1212,28 @@
|
|
|
1139
1212
|
*
|
|
1140
1213
|
* @param props - The `FieldProps` for this template
|
|
1141
1214
|
*/
|
|
1142
|
-
|
|
1143
|
-
|
|
1215
|
+
var ObjectField = /*#__PURE__*/function (_Component) {
|
|
1216
|
+
_inheritsLoose(ObjectField, _Component);
|
|
1217
|
+
function ObjectField() {
|
|
1144
1218
|
var _this;
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1219
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1220
|
+
args[_key] = arguments[_key];
|
|
1221
|
+
}
|
|
1222
|
+
_this = _Component.call.apply(_Component, [this].concat(args)) || this;
|
|
1223
|
+
_this.state = {
|
|
1148
1224
|
wasPropertyKeyModified: false,
|
|
1149
1225
|
additionalProperties: {}
|
|
1150
1226
|
};
|
|
1151
|
-
|
|
1227
|
+
_this.onPropertyChange = function (name, addedByAdditionalProperties) {
|
|
1152
1228
|
if (addedByAdditionalProperties === void 0) {
|
|
1153
1229
|
addedByAdditionalProperties = false;
|
|
1154
1230
|
}
|
|
1155
|
-
return (value, newErrorSchema, id)
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1231
|
+
return function (value, newErrorSchema, id) {
|
|
1232
|
+
var _extends2, _extends3;
|
|
1233
|
+
var _this$props = _this.props,
|
|
1234
|
+
formData = _this$props.formData,
|
|
1235
|
+
onChange = _this$props.onChange,
|
|
1236
|
+
errorSchema = _this$props.errorSchema;
|
|
1161
1237
|
if (value === undefined && addedByAdditionalProperties) {
|
|
1162
1238
|
// Don't set value = undefined for fields added by
|
|
1163
1239
|
// additionalProperties. Doing so removes them from the
|
|
@@ -1168,117 +1244,95 @@
|
|
|
1168
1244
|
// set empty values to the empty string.
|
|
1169
1245
|
value = "";
|
|
1170
1246
|
}
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
[name]: value
|
|
1174
|
-
};
|
|
1175
|
-
onChange(newFormData, errorSchema && errorSchema && {
|
|
1176
|
-
...errorSchema,
|
|
1177
|
-
[name]: newErrorSchema
|
|
1178
|
-
}, id);
|
|
1247
|
+
var newFormData = _extends({}, formData, (_extends2 = {}, _extends2[name] = value, _extends2));
|
|
1248
|
+
onChange(newFormData, errorSchema && errorSchema && _extends({}, errorSchema, (_extends3 = {}, _extends3[name] = newErrorSchema, _extends3)), id);
|
|
1179
1249
|
};
|
|
1180
1250
|
};
|
|
1181
|
-
|
|
1182
|
-
return event
|
|
1251
|
+
_this.onDropPropertyClick = function (key) {
|
|
1252
|
+
return function (event) {
|
|
1183
1253
|
event.preventDefault();
|
|
1184
|
-
|
|
1185
|
-
onChange,
|
|
1186
|
-
formData
|
|
1187
|
-
|
|
1188
|
-
const copiedFormData = {
|
|
1189
|
-
...formData
|
|
1190
|
-
};
|
|
1254
|
+
var _this$props2 = _this.props,
|
|
1255
|
+
onChange = _this$props2.onChange,
|
|
1256
|
+
formData = _this$props2.formData;
|
|
1257
|
+
var copiedFormData = _extends({}, formData);
|
|
1191
1258
|
unset__default["default"](copiedFormData, key);
|
|
1192
1259
|
onChange(copiedFormData);
|
|
1193
1260
|
};
|
|
1194
1261
|
};
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
let index = 0;
|
|
1203
|
-
let newKey = preferredKey;
|
|
1262
|
+
_this.getAvailableKey = function (preferredKey, formData) {
|
|
1263
|
+
var uiSchema = _this.props.uiSchema;
|
|
1264
|
+
var _getUiOptions = utils.getUiOptions(uiSchema),
|
|
1265
|
+
_getUiOptions$duplica = _getUiOptions.duplicateKeySuffixSeparator,
|
|
1266
|
+
duplicateKeySuffixSeparator = _getUiOptions$duplica === void 0 ? "-" : _getUiOptions$duplica;
|
|
1267
|
+
var index = 0;
|
|
1268
|
+
var newKey = preferredKey;
|
|
1204
1269
|
while (newKey in formData) {
|
|
1205
|
-
newKey =
|
|
1270
|
+
newKey = "" + preferredKey + duplicateKeySuffixSeparator + ++index;
|
|
1206
1271
|
}
|
|
1207
1272
|
return newKey;
|
|
1208
1273
|
};
|
|
1209
|
-
|
|
1210
|
-
return (value, newErrorSchema)
|
|
1274
|
+
_this.onKeyChange = function (oldValue) {
|
|
1275
|
+
return function (value, newErrorSchema) {
|
|
1276
|
+
var _newKeys, _extends4;
|
|
1211
1277
|
if (oldValue === value) {
|
|
1212
1278
|
return;
|
|
1213
1279
|
}
|
|
1214
|
-
|
|
1215
|
-
formData,
|
|
1216
|
-
onChange,
|
|
1217
|
-
errorSchema
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
[
|
|
1225
|
-
};
|
|
1226
|
-
const keyValues = Object.keys(newFormData).map(key => {
|
|
1227
|
-
const newKey = newKeys[key] || key;
|
|
1228
|
-
return {
|
|
1229
|
-
[newKey]: newFormData[key]
|
|
1230
|
-
};
|
|
1280
|
+
var _this$props3 = _this.props,
|
|
1281
|
+
formData = _this$props3.formData,
|
|
1282
|
+
onChange = _this$props3.onChange,
|
|
1283
|
+
errorSchema = _this$props3.errorSchema;
|
|
1284
|
+
value = _this.getAvailableKey(value, formData);
|
|
1285
|
+
var newFormData = _extends({}, formData);
|
|
1286
|
+
var newKeys = (_newKeys = {}, _newKeys[oldValue] = value, _newKeys);
|
|
1287
|
+
var keyValues = Object.keys(newFormData).map(function (key) {
|
|
1288
|
+
var _ref;
|
|
1289
|
+
var newKey = newKeys[key] || key;
|
|
1290
|
+
return _ref = {}, _ref[newKey] = newFormData[key], _ref;
|
|
1231
1291
|
});
|
|
1232
|
-
|
|
1233
|
-
|
|
1292
|
+
var renamedObj = Object.assign.apply(Object, [{}].concat(keyValues));
|
|
1293
|
+
_this.setState({
|
|
1234
1294
|
wasPropertyKeyModified: true
|
|
1235
1295
|
});
|
|
1236
|
-
onChange(renamedObj, errorSchema && errorSchema && {
|
|
1237
|
-
...errorSchema,
|
|
1238
|
-
[value]: newErrorSchema
|
|
1239
|
-
});
|
|
1296
|
+
onChange(renamedObj, errorSchema && errorSchema && _extends({}, errorSchema, (_extends4 = {}, _extends4[value] = newErrorSchema, _extends4)));
|
|
1240
1297
|
};
|
|
1241
1298
|
};
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
const {
|
|
1247
|
-
formData,
|
|
1248
|
-
onChange,
|
|
1249
|
-
registry
|
|
1250
|
-
} = this.props;
|
|
1251
|
-
const newFormData = {
|
|
1252
|
-
...formData
|
|
1253
|
-
};
|
|
1254
|
-
let type = undefined;
|
|
1255
|
-
if (isObject__default["default"](schema.additionalProperties)) {
|
|
1256
|
-
type = schema.additionalProperties.type;
|
|
1257
|
-
if (utils.REF_KEY in schema.additionalProperties) {
|
|
1258
|
-
const {
|
|
1259
|
-
schemaUtils
|
|
1260
|
-
} = registry;
|
|
1261
|
-
const refSchema = schemaUtils.retrieveSchema({
|
|
1262
|
-
$ref: schema.additionalProperties[utils.REF_KEY]
|
|
1263
|
-
}, formData);
|
|
1264
|
-
type = refSchema.type;
|
|
1299
|
+
_this.handleAddClick = function (schema) {
|
|
1300
|
+
return function () {
|
|
1301
|
+
if (!schema.additionalProperties) {
|
|
1302
|
+
return;
|
|
1265
1303
|
}
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1304
|
+
var _this$props4 = _this.props,
|
|
1305
|
+
formData = _this$props4.formData,
|
|
1306
|
+
onChange = _this$props4.onChange,
|
|
1307
|
+
registry = _this$props4.registry;
|
|
1308
|
+
var newFormData = _extends({}, formData);
|
|
1309
|
+
var type = undefined;
|
|
1310
|
+
if (isObject__default["default"](schema.additionalProperties)) {
|
|
1311
|
+
type = schema.additionalProperties.type;
|
|
1312
|
+
if (utils.REF_KEY in schema.additionalProperties) {
|
|
1313
|
+
var schemaUtils = registry.schemaUtils;
|
|
1314
|
+
var refSchema = schemaUtils.retrieveSchema({
|
|
1315
|
+
$ref: schema.additionalProperties[utils.REF_KEY]
|
|
1316
|
+
}, formData);
|
|
1317
|
+
type = refSchema.type;
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
var newKey = _this.getAvailableKey("newKey", newFormData);
|
|
1321
|
+
// Cast this to make the `set` work properly
|
|
1322
|
+
set__default["default"](newFormData, newKey, _this.getDefaultValue(type));
|
|
1323
|
+
onChange(newFormData);
|
|
1324
|
+
};
|
|
1271
1325
|
};
|
|
1326
|
+
return _this;
|
|
1272
1327
|
}
|
|
1328
|
+
var _proto = ObjectField.prototype;
|
|
1273
1329
|
/** Returns a flag indicating whether the `name` field is required in the object schema
|
|
1274
1330
|
*
|
|
1275
1331
|
* @param name - The name of the field to check for required-ness
|
|
1276
1332
|
* @returns - True if the field `name` is required, false otherwise
|
|
1277
1333
|
*/
|
|
1278
|
-
isRequired(name) {
|
|
1279
|
-
|
|
1280
|
-
schema
|
|
1281
|
-
} = this.props;
|
|
1334
|
+
_proto.isRequired = function isRequired(name) {
|
|
1335
|
+
var schema = this.props.schema;
|
|
1282
1336
|
return Array.isArray(schema.required) && schema.required.indexOf(name) !== -1;
|
|
1283
1337
|
}
|
|
1284
1338
|
/** Returns the `onPropertyChange` handler for the `name` field. Handles the special case where a user is attempting
|
|
@@ -1288,13 +1342,12 @@
|
|
|
1288
1342
|
* @param name - The name of the property
|
|
1289
1343
|
* @param addedByAdditionalProperties - Flag indicating whether this property is an additional property
|
|
1290
1344
|
* @returns - The onPropertyChange callback for the `name` property
|
|
1291
|
-
|
|
1292
|
-
|
|
1345
|
+
*/;
|
|
1293
1346
|
/** Returns a default value to be used for a new additional schema property of the given `type`
|
|
1294
1347
|
*
|
|
1295
1348
|
* @param type - The type of the new additional schema property
|
|
1296
1349
|
*/
|
|
1297
|
-
getDefaultValue(type) {
|
|
1350
|
+
_proto.getDefaultValue = function getDefaultValue(type) {
|
|
1298
1351
|
switch (type) {
|
|
1299
1352
|
case "string":
|
|
1300
1353
|
return "New Value";
|
|
@@ -1317,46 +1370,44 @@
|
|
|
1317
1370
|
* default data for that field has been added to the formData.
|
|
1318
1371
|
*
|
|
1319
1372
|
* @param schema - The schema element to which the new property is being added
|
|
1320
|
-
|
|
1321
|
-
|
|
1373
|
+
*/;
|
|
1322
1374
|
/** Renders the `ObjectField` from the given props
|
|
1323
1375
|
*/
|
|
1324
|
-
render() {
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
let orderedProperties;
|
|
1376
|
+
_proto.render = function render() {
|
|
1377
|
+
var _this2 = this;
|
|
1378
|
+
var _this$props5 = this.props,
|
|
1379
|
+
rawSchema = _this$props5.schema,
|
|
1380
|
+
_this$props5$uiSchema = _this$props5.uiSchema,
|
|
1381
|
+
uiSchema = _this$props5$uiSchema === void 0 ? {} : _this$props5$uiSchema,
|
|
1382
|
+
formData = _this$props5.formData,
|
|
1383
|
+
errorSchema = _this$props5.errorSchema,
|
|
1384
|
+
idSchema = _this$props5.idSchema,
|
|
1385
|
+
name = _this$props5.name,
|
|
1386
|
+
_this$props5$required = _this$props5.required,
|
|
1387
|
+
required = _this$props5$required === void 0 ? false : _this$props5$required,
|
|
1388
|
+
_this$props5$disabled = _this$props5.disabled,
|
|
1389
|
+
disabled = _this$props5$disabled === void 0 ? false : _this$props5$disabled,
|
|
1390
|
+
_this$props5$readonly = _this$props5.readonly,
|
|
1391
|
+
readonly = _this$props5$readonly === void 0 ? false : _this$props5$readonly,
|
|
1392
|
+
hideError = _this$props5.hideError,
|
|
1393
|
+
idPrefix = _this$props5.idPrefix,
|
|
1394
|
+
idSeparator = _this$props5.idSeparator,
|
|
1395
|
+
onBlur = _this$props5.onBlur,
|
|
1396
|
+
onFocus = _this$props5.onFocus,
|
|
1397
|
+
registry = _this$props5.registry;
|
|
1398
|
+
var fields = registry.fields,
|
|
1399
|
+
formContext = registry.formContext,
|
|
1400
|
+
schemaUtils = registry.schemaUtils;
|
|
1401
|
+
var SchemaField = fields.SchemaField;
|
|
1402
|
+
var schema = schemaUtils.retrieveSchema(rawSchema, formData);
|
|
1403
|
+
var uiOptions = utils.getUiOptions(uiSchema);
|
|
1404
|
+
var _schema$properties = schema.properties,
|
|
1405
|
+
schemaProperties = _schema$properties === void 0 ? {} : _schema$properties;
|
|
1406
|
+
var title = schema.title === undefined ? name : schema.title;
|
|
1407
|
+
var description = uiOptions.description || schema.description;
|
|
1408
|
+
var orderedProperties;
|
|
1358
1409
|
try {
|
|
1359
|
-
|
|
1410
|
+
var properties = Object.keys(schemaProperties);
|
|
1360
1411
|
orderedProperties = utils.orderProperties(properties, uiOptions.order);
|
|
1361
1412
|
} catch (err) {
|
|
1362
1413
|
return /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement("p", {
|
|
@@ -1366,20 +1417,20 @@
|
|
|
1366
1417
|
}
|
|
1367
1418
|
}, "Invalid ", name || "root", " object field configuration:", /*#__PURE__*/React__default["default"].createElement("em", null, err.message), "."), /*#__PURE__*/React__default["default"].createElement("pre", null, JSON.stringify(schema)));
|
|
1368
1419
|
}
|
|
1369
|
-
|
|
1370
|
-
|
|
1420
|
+
var Template = utils.getTemplate("ObjectFieldTemplate", registry, uiOptions);
|
|
1421
|
+
var templateProps = {
|
|
1371
1422
|
title: uiOptions.title || title,
|
|
1372
|
-
description,
|
|
1373
|
-
properties: orderedProperties.map(name
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1423
|
+
description: description,
|
|
1424
|
+
properties: orderedProperties.map(function (name) {
|
|
1425
|
+
var addedByAdditionalProperties = has__default["default"](schema, [utils.PROPERTIES_KEY, name, utils.ADDITIONAL_PROPERTY_FLAG]);
|
|
1426
|
+
var fieldUiSchema = addedByAdditionalProperties ? uiSchema.additionalProperties : uiSchema[name];
|
|
1427
|
+
var hidden = utils.getUiOptions(fieldUiSchema).widget === "hidden";
|
|
1428
|
+
var fieldIdSchema = get__default["default"](idSchema, [name], {});
|
|
1378
1429
|
return {
|
|
1379
1430
|
content: /*#__PURE__*/React__default["default"].createElement(SchemaField, {
|
|
1380
1431
|
key: name,
|
|
1381
1432
|
name: name,
|
|
1382
|
-
required:
|
|
1433
|
+
required: _this2.isRequired(name),
|
|
1383
1434
|
schema: get__default["default"](schema, [utils.PROPERTIES_KEY, name], {}),
|
|
1384
1435
|
uiSchema: fieldUiSchema,
|
|
1385
1436
|
errorSchema: get__default["default"](errorSchema, name),
|
|
@@ -1388,50 +1439,51 @@
|
|
|
1388
1439
|
idSeparator: idSeparator,
|
|
1389
1440
|
formData: get__default["default"](formData, name),
|
|
1390
1441
|
formContext: formContext,
|
|
1391
|
-
wasPropertyKeyModified:
|
|
1392
|
-
onKeyChange:
|
|
1393
|
-
onChange:
|
|
1442
|
+
wasPropertyKeyModified: _this2.state.wasPropertyKeyModified,
|
|
1443
|
+
onKeyChange: _this2.onKeyChange(name),
|
|
1444
|
+
onChange: _this2.onPropertyChange(name, addedByAdditionalProperties),
|
|
1394
1445
|
onBlur: onBlur,
|
|
1395
1446
|
onFocus: onFocus,
|
|
1396
1447
|
registry: registry,
|
|
1397
1448
|
disabled: disabled,
|
|
1398
1449
|
readonly: readonly,
|
|
1399
1450
|
hideError: hideError,
|
|
1400
|
-
onDropPropertyClick:
|
|
1451
|
+
onDropPropertyClick: _this2.onDropPropertyClick
|
|
1401
1452
|
}),
|
|
1402
|
-
name,
|
|
1403
|
-
readonly,
|
|
1404
|
-
disabled,
|
|
1405
|
-
required,
|
|
1406
|
-
hidden
|
|
1453
|
+
name: name,
|
|
1454
|
+
readonly: readonly,
|
|
1455
|
+
disabled: disabled,
|
|
1456
|
+
required: required,
|
|
1457
|
+
hidden: hidden
|
|
1407
1458
|
};
|
|
1408
1459
|
}),
|
|
1409
|
-
readonly,
|
|
1410
|
-
disabled,
|
|
1411
|
-
required,
|
|
1412
|
-
idSchema,
|
|
1413
|
-
uiSchema,
|
|
1414
|
-
schema,
|
|
1415
|
-
formData,
|
|
1416
|
-
formContext,
|
|
1417
|
-
registry
|
|
1460
|
+
readonly: readonly,
|
|
1461
|
+
disabled: disabled,
|
|
1462
|
+
required: required,
|
|
1463
|
+
idSchema: idSchema,
|
|
1464
|
+
uiSchema: uiSchema,
|
|
1465
|
+
schema: schema,
|
|
1466
|
+
formData: formData,
|
|
1467
|
+
formContext: formContext,
|
|
1468
|
+
registry: registry
|
|
1418
1469
|
};
|
|
1419
|
-
return /*#__PURE__*/React__default["default"].createElement(Template, {
|
|
1420
|
-
...templateProps,
|
|
1470
|
+
return /*#__PURE__*/React__default["default"].createElement(Template, _extends({}, templateProps, {
|
|
1421
1471
|
onAddClick: this.handleAddClick
|
|
1422
|
-
});
|
|
1423
|
-
}
|
|
1424
|
-
|
|
1472
|
+
}));
|
|
1473
|
+
};
|
|
1474
|
+
return ObjectField;
|
|
1475
|
+
}(React.Component);
|
|
1425
1476
|
|
|
1477
|
+
var _excluded$6 = ["__errors"];
|
|
1426
1478
|
/** The map of component type to FieldName */
|
|
1427
|
-
|
|
1479
|
+
var COMPONENT_TYPES = {
|
|
1428
1480
|
array: "ArrayField",
|
|
1429
|
-
boolean: "BooleanField",
|
|
1481
|
+
"boolean": "BooleanField",
|
|
1430
1482
|
integer: "NumberField",
|
|
1431
1483
|
number: "NumberField",
|
|
1432
1484
|
object: "ObjectField",
|
|
1433
1485
|
string: "StringField",
|
|
1434
|
-
null: "NullField"
|
|
1486
|
+
"null": "NullField"
|
|
1435
1487
|
};
|
|
1436
1488
|
/** Computes and returns which `Field` implementation to return in order to render the field represented by the
|
|
1437
1489
|
* `schema`. The `uiOptions` are used to alter what potential `Field` implementation is actually returned. If no
|
|
@@ -1444,30 +1496,30 @@
|
|
|
1444
1496
|
* @returns - The `Field` component that is used to render the actual field data
|
|
1445
1497
|
*/
|
|
1446
1498
|
function getFieldComponent(schema, uiOptions, idSchema, registry) {
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
fields
|
|
1450
|
-
} = registry;
|
|
1499
|
+
var field = uiOptions.field;
|
|
1500
|
+
var fields = registry.fields;
|
|
1451
1501
|
if (typeof field === "function") {
|
|
1452
1502
|
return field;
|
|
1453
1503
|
}
|
|
1454
1504
|
if (typeof field === "string" && field in fields) {
|
|
1455
1505
|
return fields[field];
|
|
1456
1506
|
}
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1507
|
+
var schemaType = utils.getSchemaType(schema);
|
|
1508
|
+
var type = Array.isArray(schemaType) ? schemaType[0] : schemaType || "";
|
|
1509
|
+
var componentName = COMPONENT_TYPES[type];
|
|
1460
1510
|
// If the type is not defined and the schema uses 'anyOf' or 'oneOf', don't
|
|
1461
1511
|
// render a field and let the MultiSchemaField component handle the form display
|
|
1462
1512
|
if (!componentName && (schema.anyOf || schema.oneOf)) {
|
|
1463
|
-
return ()
|
|
1513
|
+
return function () {
|
|
1514
|
+
return null;
|
|
1515
|
+
};
|
|
1464
1516
|
}
|
|
1465
|
-
return componentName in fields ? fields[componentName] : ()
|
|
1466
|
-
|
|
1517
|
+
return componentName in fields ? fields[componentName] : function () {
|
|
1518
|
+
var UnsupportedFieldTemplate = utils.getTemplate("UnsupportedFieldTemplate", registry, uiOptions);
|
|
1467
1519
|
return /*#__PURE__*/React__default["default"].createElement(UnsupportedFieldTemplate, {
|
|
1468
1520
|
schema: schema,
|
|
1469
1521
|
idSchema: idSchema,
|
|
1470
|
-
reason:
|
|
1522
|
+
reason: "Unknown field type " + schema.type,
|
|
1471
1523
|
registry: registry
|
|
1472
1524
|
});
|
|
1473
1525
|
};
|
|
@@ -1479,63 +1531,58 @@
|
|
|
1479
1531
|
* @param props - The `FieldProps` for this component
|
|
1480
1532
|
*/
|
|
1481
1533
|
function SchemaFieldRender(props) {
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
wasPropertyKeyModified = false
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
const schema = schemaUtils.retrieveSchema(_schema, formData);
|
|
1508
|
-
const fieldId = _idSchema[utils.ID_KEY];
|
|
1509
|
-
const idSchema = utils.mergeObjects(schemaUtils.toIdSchema(schema, fieldId, formData, idPrefix, idSeparator), _idSchema);
|
|
1534
|
+
var _schema = props.schema,
|
|
1535
|
+
_idSchema = props.idSchema,
|
|
1536
|
+
uiSchema = props.uiSchema,
|
|
1537
|
+
formData = props.formData,
|
|
1538
|
+
errorSchema = props.errorSchema,
|
|
1539
|
+
idPrefix = props.idPrefix,
|
|
1540
|
+
idSeparator = props.idSeparator,
|
|
1541
|
+
name = props.name,
|
|
1542
|
+
onChange = props.onChange,
|
|
1543
|
+
onKeyChange = props.onKeyChange,
|
|
1544
|
+
onDropPropertyClick = props.onDropPropertyClick,
|
|
1545
|
+
required = props.required,
|
|
1546
|
+
registry = props.registry,
|
|
1547
|
+
_props$wasPropertyKey = props.wasPropertyKeyModified,
|
|
1548
|
+
wasPropertyKeyModified = _props$wasPropertyKey === void 0 ? false : _props$wasPropertyKey;
|
|
1549
|
+
var formContext = registry.formContext,
|
|
1550
|
+
schemaUtils = registry.schemaUtils;
|
|
1551
|
+
var uiOptions = utils.getUiOptions(uiSchema);
|
|
1552
|
+
var FieldTemplate = utils.getTemplate("FieldTemplate", registry, uiOptions);
|
|
1553
|
+
var DescriptionFieldTemplate = utils.getTemplate("DescriptionFieldTemplate", registry, uiOptions);
|
|
1554
|
+
var FieldHelpTemplate = utils.getTemplate("FieldHelpTemplate", registry, uiOptions);
|
|
1555
|
+
var FieldErrorTemplate = utils.getTemplate("FieldErrorTemplate", registry, uiOptions);
|
|
1556
|
+
var schema = schemaUtils.retrieveSchema(_schema, formData);
|
|
1557
|
+
var fieldId = _idSchema[utils.ID_KEY];
|
|
1558
|
+
var idSchema = utils.mergeObjects(schemaUtils.toIdSchema(schema, fieldId, formData, idPrefix, idSeparator), _idSchema);
|
|
1510
1559
|
/** Intermediary `onChange` handler for field components that will inject the `id` of the current field into the
|
|
1511
1560
|
* `onChange` chain if it is not already being provided from a deeper level in the hierarchy
|
|
1512
1561
|
*/
|
|
1513
|
-
|
|
1514
|
-
|
|
1562
|
+
var handleFieldComponentChange = React__default["default"].useCallback(function (formData, newErrorSchema, id) {
|
|
1563
|
+
var theId = id || fieldId;
|
|
1515
1564
|
return onChange(formData, newErrorSchema, theId);
|
|
1516
1565
|
}, [fieldId, onChange]);
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1566
|
+
var FieldComponent = getFieldComponent(schema, uiOptions, idSchema, registry);
|
|
1567
|
+
var disabled = Boolean(props.disabled || uiOptions.disabled);
|
|
1568
|
+
var readonly = Boolean(props.readonly || uiOptions.readonly || props.schema.readOnly || schema.readOnly);
|
|
1569
|
+
var uiSchemaHideError = uiOptions.hideError;
|
|
1521
1570
|
// Set hideError to the value provided in the uiSchema, otherwise stick with the prop to propagate to children
|
|
1522
|
-
|
|
1523
|
-
|
|
1571
|
+
var hideError = uiSchemaHideError === undefined ? props.hideError : Boolean(uiSchemaHideError);
|
|
1572
|
+
var autofocus = Boolean(props.autofocus || uiOptions.autofocus);
|
|
1524
1573
|
if (Object.keys(schema).length === 0) {
|
|
1525
1574
|
return null;
|
|
1526
1575
|
}
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
__errors,
|
|
1530
|
-
|
|
1531
|
-
} = errorSchema || {};
|
|
1576
|
+
var displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema);
|
|
1577
|
+
var _ref = errorSchema || {},
|
|
1578
|
+
__errors = _ref.__errors,
|
|
1579
|
+
fieldErrorSchema = _objectWithoutPropertiesLoose(_ref, _excluded$6);
|
|
1532
1580
|
// See #439: uiSchema: Don't pass consumed class names to child components
|
|
1533
|
-
|
|
1581
|
+
var fieldUiSchema = omit__default["default"](uiSchema, ["ui:classNames", "classNames"]);
|
|
1534
1582
|
if ("ui:options" in fieldUiSchema) {
|
|
1535
1583
|
fieldUiSchema["ui:options"] = omit__default["default"](fieldUiSchema["ui:options"], ["classNames"]);
|
|
1536
1584
|
}
|
|
1537
|
-
|
|
1538
|
-
...props,
|
|
1585
|
+
var field = /*#__PURE__*/React__default["default"].createElement(FieldComponent, _extends({}, props, {
|
|
1539
1586
|
onChange: handleFieldComponentChange,
|
|
1540
1587
|
idSchema: idSchema,
|
|
1541
1588
|
schema: schema,
|
|
@@ -1547,19 +1594,19 @@
|
|
|
1547
1594
|
errorSchema: fieldErrorSchema,
|
|
1548
1595
|
formContext: formContext,
|
|
1549
1596
|
rawErrors: __errors
|
|
1550
|
-
});
|
|
1551
|
-
|
|
1597
|
+
}));
|
|
1598
|
+
var id = idSchema[utils.ID_KEY];
|
|
1552
1599
|
// If this schema has a title defined, but the user has set a new key/label, retain their input.
|
|
1553
|
-
|
|
1600
|
+
var label;
|
|
1554
1601
|
if (wasPropertyKeyModified) {
|
|
1555
1602
|
label = name;
|
|
1556
1603
|
} else {
|
|
1557
1604
|
label = utils.ADDITIONAL_PROPERTY_FLAG in schema ? name : uiOptions.title || props.schema.title || schema.title || name;
|
|
1558
1605
|
}
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1606
|
+
var description = uiOptions.description || props.schema.description || schema.description || "";
|
|
1607
|
+
var help = uiOptions.help;
|
|
1608
|
+
var hidden = uiOptions.widget === "hidden";
|
|
1609
|
+
var classNames = ["form-group", "field", "field-" + schema.type];
|
|
1563
1610
|
if (!hideError && __errors && __errors.length > 0) {
|
|
1564
1611
|
classNames.push("field-error has-error has-danger");
|
|
1565
1612
|
}
|
|
@@ -1572,7 +1619,7 @@
|
|
|
1572
1619
|
if (uiOptions.classNames) {
|
|
1573
1620
|
classNames.push(uiOptions.classNames);
|
|
1574
1621
|
}
|
|
1575
|
-
|
|
1622
|
+
var helpComponent = /*#__PURE__*/React__default["default"].createElement(FieldHelpTemplate, {
|
|
1576
1623
|
help: help,
|
|
1577
1624
|
idSchema: idSchema,
|
|
1578
1625
|
schema: schema,
|
|
@@ -1580,7 +1627,7 @@
|
|
|
1580
1627
|
hasErrors: !hideError && __errors && __errors.length > 0,
|
|
1581
1628
|
registry: registry
|
|
1582
1629
|
});
|
|
1583
|
-
|
|
1630
|
+
var errorsComponent = hideError ? undefined : /*#__PURE__*/React__default["default"].createElement(FieldErrorTemplate, {
|
|
1584
1631
|
errors: __errors,
|
|
1585
1632
|
errorSchema: errorSchema,
|
|
1586
1633
|
idSchema: idSchema,
|
|
@@ -1588,9 +1635,9 @@
|
|
|
1588
1635
|
uiSchema: uiSchema,
|
|
1589
1636
|
registry: registry
|
|
1590
1637
|
});
|
|
1591
|
-
|
|
1638
|
+
var fieldProps = {
|
|
1592
1639
|
description: /*#__PURE__*/React__default["default"].createElement(DescriptionFieldTemplate, {
|
|
1593
|
-
id:
|
|
1640
|
+
id: id + "__description",
|
|
1594
1641
|
description: description,
|
|
1595
1642
|
schema: schema,
|
|
1596
1643
|
uiSchema: uiSchema,
|
|
@@ -1601,29 +1648,27 @@
|
|
|
1601
1648
|
rawHelp: typeof help === "string" ? help : undefined,
|
|
1602
1649
|
errors: errorsComponent,
|
|
1603
1650
|
rawErrors: hideError ? undefined : __errors,
|
|
1604
|
-
id,
|
|
1605
|
-
label,
|
|
1606
|
-
hidden,
|
|
1607
|
-
onChange,
|
|
1608
|
-
onKeyChange,
|
|
1609
|
-
onDropPropertyClick,
|
|
1610
|
-
required,
|
|
1611
|
-
disabled,
|
|
1612
|
-
readonly,
|
|
1613
|
-
hideError,
|
|
1614
|
-
displayLabel,
|
|
1651
|
+
id: id,
|
|
1652
|
+
label: label,
|
|
1653
|
+
hidden: hidden,
|
|
1654
|
+
onChange: onChange,
|
|
1655
|
+
onKeyChange: onKeyChange,
|
|
1656
|
+
onDropPropertyClick: onDropPropertyClick,
|
|
1657
|
+
required: required,
|
|
1658
|
+
disabled: disabled,
|
|
1659
|
+
readonly: readonly,
|
|
1660
|
+
hideError: hideError,
|
|
1661
|
+
displayLabel: displayLabel,
|
|
1615
1662
|
classNames: classNames.join(" ").trim(),
|
|
1616
|
-
formContext,
|
|
1617
|
-
formData,
|
|
1618
|
-
schema,
|
|
1619
|
-
uiSchema,
|
|
1620
|
-
registry
|
|
1663
|
+
formContext: formContext,
|
|
1664
|
+
formData: formData,
|
|
1665
|
+
schema: schema,
|
|
1666
|
+
uiSchema: uiSchema,
|
|
1667
|
+
registry: registry
|
|
1621
1668
|
};
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
return /*#__PURE__*/React__default["default"].createElement(FieldTemplate, {
|
|
1625
|
-
...fieldProps
|
|
1626
|
-
}, /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, field, schema.anyOf && !(uiSchema !== null && uiSchema !== void 0 && uiSchema["ui:field"]) && !schemaUtils.isSelect(schema) && /*#__PURE__*/React__default["default"].createElement(_AnyOfField, {
|
|
1669
|
+
var _AnyOfField = registry.fields.AnyOfField;
|
|
1670
|
+
var _OneOfField = registry.fields.OneOfField;
|
|
1671
|
+
return /*#__PURE__*/React__default["default"].createElement(FieldTemplate, _extends({}, fieldProps), /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, field, schema.anyOf && !(uiSchema !== null && uiSchema !== void 0 && uiSchema["ui:field"]) && !schemaUtils.isSelect(schema) && /*#__PURE__*/React__default["default"].createElement(_AnyOfField, {
|
|
1627
1672
|
name: name,
|
|
1628
1673
|
disabled: disabled,
|
|
1629
1674
|
readonly: readonly,
|
|
@@ -1637,7 +1682,9 @@
|
|
|
1637
1682
|
onBlur: props.onBlur,
|
|
1638
1683
|
onChange: props.onChange,
|
|
1639
1684
|
onFocus: props.onFocus,
|
|
1640
|
-
options: schema.anyOf.map(
|
|
1685
|
+
options: schema.anyOf.map(function (_schema) {
|
|
1686
|
+
return schemaUtils.retrieveSchema(isObject__default["default"](_schema) ? _schema : {}, formData);
|
|
1687
|
+
}),
|
|
1641
1688
|
baseType: schema.type,
|
|
1642
1689
|
registry: registry,
|
|
1643
1690
|
schema: schema,
|
|
@@ -1656,7 +1703,9 @@
|
|
|
1656
1703
|
onBlur: props.onBlur,
|
|
1657
1704
|
onChange: props.onChange,
|
|
1658
1705
|
onFocus: props.onFocus,
|
|
1659
|
-
options: schema.oneOf.map(
|
|
1706
|
+
options: schema.oneOf.map(function (_schema) {
|
|
1707
|
+
return schemaUtils.retrieveSchema(isObject__default["default"](_schema) ? _schema : {}, formData);
|
|
1708
|
+
}),
|
|
1660
1709
|
baseType: schema.type,
|
|
1661
1710
|
registry: registry,
|
|
1662
1711
|
schema: schema,
|
|
@@ -1666,63 +1715,65 @@
|
|
|
1666
1715
|
/** The `SchemaField` component determines whether it is necessary to rerender the component based on any props changes
|
|
1667
1716
|
* and if so, calls the `SchemaFieldRender` component with the props.
|
|
1668
1717
|
*/
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
render() {
|
|
1674
|
-
return /*#__PURE__*/React__default["default"].createElement(SchemaFieldRender, {
|
|
1675
|
-
...this.props
|
|
1676
|
-
});
|
|
1718
|
+
var SchemaField = /*#__PURE__*/function (_React$Component) {
|
|
1719
|
+
_inheritsLoose(SchemaField, _React$Component);
|
|
1720
|
+
function SchemaField() {
|
|
1721
|
+
return _React$Component.apply(this, arguments) || this;
|
|
1677
1722
|
}
|
|
1678
|
-
|
|
1723
|
+
var _proto = SchemaField.prototype;
|
|
1724
|
+
_proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
|
|
1725
|
+
return !utils.deepEquals(this.props, nextProps);
|
|
1726
|
+
};
|
|
1727
|
+
_proto.render = function render() {
|
|
1728
|
+
return /*#__PURE__*/React__default["default"].createElement(SchemaFieldRender, _extends({}, this.props));
|
|
1729
|
+
};
|
|
1730
|
+
return SchemaField;
|
|
1731
|
+
}(React__default["default"].Component);
|
|
1679
1732
|
|
|
1733
|
+
var _excluded$5 = ["widget", "placeholder"];
|
|
1680
1734
|
/** The `StringField` component is used to render a schema field that represents a string type
|
|
1681
1735
|
*
|
|
1682
1736
|
* @param props - The `FieldProps` for this template
|
|
1683
1737
|
*/
|
|
1684
1738
|
function StringField(props) {
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
disabled = false,
|
|
1693
|
-
readonly =
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
format
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
} = registry;
|
|
1710
|
-
const enumOptions = schemaUtils.isSelect(schema) ? utils.optionsList(schema) : undefined;
|
|
1711
|
-
let defaultWidget = enumOptions ? "select" : "text";
|
|
1739
|
+
var schema = props.schema,
|
|
1740
|
+
name = props.name,
|
|
1741
|
+
uiSchema = props.uiSchema,
|
|
1742
|
+
idSchema = props.idSchema,
|
|
1743
|
+
formData = props.formData,
|
|
1744
|
+
required = props.required,
|
|
1745
|
+
_props$disabled = props.disabled,
|
|
1746
|
+
disabled = _props$disabled === void 0 ? false : _props$disabled,
|
|
1747
|
+
_props$readonly = props.readonly,
|
|
1748
|
+
readonly = _props$readonly === void 0 ? false : _props$readonly,
|
|
1749
|
+
_props$autofocus = props.autofocus,
|
|
1750
|
+
autofocus = _props$autofocus === void 0 ? false : _props$autofocus,
|
|
1751
|
+
onChange = props.onChange,
|
|
1752
|
+
onBlur = props.onBlur,
|
|
1753
|
+
onFocus = props.onFocus,
|
|
1754
|
+
registry = props.registry,
|
|
1755
|
+
rawErrors = props.rawErrors;
|
|
1756
|
+
var title = schema.title,
|
|
1757
|
+
format = schema.format;
|
|
1758
|
+
var widgets = registry.widgets,
|
|
1759
|
+
formContext = registry.formContext,
|
|
1760
|
+
schemaUtils = registry.schemaUtils;
|
|
1761
|
+
var enumOptions = schemaUtils.isSelect(schema) ? utils.optionsList(schema) : undefined;
|
|
1762
|
+
var defaultWidget = enumOptions ? "select" : "text";
|
|
1712
1763
|
if (format && utils.hasWidget(schema, format, widgets)) {
|
|
1713
1764
|
defaultWidget = format;
|
|
1714
1765
|
}
|
|
1715
|
-
|
|
1716
|
-
widget =
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1766
|
+
var _getUiOptions = utils.getUiOptions(uiSchema),
|
|
1767
|
+
_getUiOptions$widget = _getUiOptions.widget,
|
|
1768
|
+
widget = _getUiOptions$widget === void 0 ? defaultWidget : _getUiOptions$widget,
|
|
1769
|
+
_getUiOptions$placeho = _getUiOptions.placeholder,
|
|
1770
|
+
placeholder = _getUiOptions$placeho === void 0 ? "" : _getUiOptions$placeho,
|
|
1771
|
+
options = _objectWithoutPropertiesLoose(_getUiOptions, _excluded$5);
|
|
1772
|
+
var Widget = utils.getWidget(schema, widget, widgets);
|
|
1721
1773
|
return /*#__PURE__*/React__default["default"].createElement(Widget, {
|
|
1722
|
-
options: {
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
},
|
|
1774
|
+
options: _extends({}, options, {
|
|
1775
|
+
enumOptions: enumOptions
|
|
1776
|
+
}),
|
|
1726
1777
|
schema: schema,
|
|
1727
1778
|
uiSchema: uiSchema,
|
|
1728
1779
|
id: idSchema && idSchema.$id,
|
|
@@ -1748,11 +1799,9 @@
|
|
|
1748
1799
|
* @param props - The `FieldProps` for this template
|
|
1749
1800
|
*/
|
|
1750
1801
|
function NullField(props) {
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
} = props;
|
|
1755
|
-
React.useEffect(() => {
|
|
1802
|
+
var formData = props.formData,
|
|
1803
|
+
onChange = props.onChange;
|
|
1804
|
+
React.useEffect(function () {
|
|
1756
1805
|
if (formData === undefined) {
|
|
1757
1806
|
onChange(null);
|
|
1758
1807
|
}
|
|
@@ -1765,13 +1814,13 @@
|
|
|
1765
1814
|
AnyOfField: AnyOfField,
|
|
1766
1815
|
ArrayField: ArrayField,
|
|
1767
1816
|
// ArrayField falls back to SchemaField if ArraySchemaField is not defined, which it isn't by default
|
|
1768
|
-
BooleanField,
|
|
1769
|
-
NumberField,
|
|
1770
|
-
ObjectField,
|
|
1817
|
+
BooleanField: BooleanField,
|
|
1818
|
+
NumberField: NumberField,
|
|
1819
|
+
ObjectField: ObjectField,
|
|
1771
1820
|
OneOfField: AnyOfField,
|
|
1772
|
-
SchemaField,
|
|
1773
|
-
StringField,
|
|
1774
|
-
NullField
|
|
1821
|
+
SchemaField: SchemaField,
|
|
1822
|
+
StringField: StringField,
|
|
1823
|
+
NullField: NullField
|
|
1775
1824
|
};
|
|
1776
1825
|
}
|
|
1777
1826
|
|
|
@@ -1781,22 +1830,19 @@
|
|
|
1781
1830
|
* @param props - The `ArrayFieldDescriptionProps` for the component
|
|
1782
1831
|
*/
|
|
1783
1832
|
function ArrayFieldDescriptionTemplate(props) {
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
const {
|
|
1793
|
-
label: displayLabel = true
|
|
1794
|
-
} = options;
|
|
1833
|
+
var idSchema = props.idSchema,
|
|
1834
|
+
description = props.description,
|
|
1835
|
+
registry = props.registry,
|
|
1836
|
+
schema = props.schema,
|
|
1837
|
+
uiSchema = props.uiSchema;
|
|
1838
|
+
var options = utils.getUiOptions(uiSchema);
|
|
1839
|
+
var _options$label = options.label,
|
|
1840
|
+
displayLabel = _options$label === void 0 ? true : _options$label;
|
|
1795
1841
|
if (!description || !displayLabel) {
|
|
1796
1842
|
return null;
|
|
1797
1843
|
}
|
|
1798
|
-
|
|
1799
|
-
|
|
1844
|
+
var DescriptionFieldTemplate = utils.getTemplate("DescriptionFieldTemplate", registry, options);
|
|
1845
|
+
var id = idSchema.$id + "__description";
|
|
1800
1846
|
return /*#__PURE__*/React__default["default"].createElement(DescriptionFieldTemplate, {
|
|
1801
1847
|
id: id,
|
|
1802
1848
|
description: description,
|
|
@@ -1811,27 +1857,24 @@
|
|
|
1811
1857
|
* @param props - The `ArrayFieldTemplateItemType` props for the component
|
|
1812
1858
|
*/
|
|
1813
1859
|
function ArrayFieldItemTemplate(props) {
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
RemoveButton
|
|
1833
|
-
} = registry.templates.ButtonTemplates;
|
|
1834
|
-
const btnStyle = {
|
|
1860
|
+
var children = props.children,
|
|
1861
|
+
className = props.className,
|
|
1862
|
+
disabled = props.disabled,
|
|
1863
|
+
hasToolbar = props.hasToolbar,
|
|
1864
|
+
hasMoveDown = props.hasMoveDown,
|
|
1865
|
+
hasMoveUp = props.hasMoveUp,
|
|
1866
|
+
hasRemove = props.hasRemove,
|
|
1867
|
+
index = props.index,
|
|
1868
|
+
onDropIndexClick = props.onDropIndexClick,
|
|
1869
|
+
onReorderClick = props.onReorderClick,
|
|
1870
|
+
readonly = props.readonly,
|
|
1871
|
+
registry = props.registry,
|
|
1872
|
+
uiSchema = props.uiSchema;
|
|
1873
|
+
var _registry$templates$B = registry.templates.ButtonTemplates,
|
|
1874
|
+
MoveDownButton = _registry$templates$B.MoveDownButton,
|
|
1875
|
+
MoveUpButton = _registry$templates$B.MoveUpButton,
|
|
1876
|
+
RemoveButton = _registry$templates$B.RemoveButton;
|
|
1877
|
+
var btnStyle = {
|
|
1835
1878
|
flex: 1,
|
|
1836
1879
|
paddingLeft: 6,
|
|
1837
1880
|
paddingRight: 6,
|
|
@@ -1867,35 +1910,30 @@
|
|
|
1867
1910
|
}))));
|
|
1868
1911
|
}
|
|
1869
1912
|
|
|
1913
|
+
var _excluded$4 = ["key"];
|
|
1870
1914
|
/** The `ArrayFieldTemplate` component is the template used to render all items in an array.
|
|
1871
1915
|
*
|
|
1872
1916
|
* @param props - The `ArrayFieldTemplateItemType` props for the component
|
|
1873
1917
|
*/
|
|
1874
1918
|
function ArrayFieldTemplate(props) {
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
const ArrayFieldItemTemplate = utils.getTemplate("ArrayFieldItemTemplate", registry, uiOptions);
|
|
1892
|
-
const ArrayFieldTitleTemplate = utils.getTemplate("ArrayFieldTitleTemplate", registry, uiOptions);
|
|
1919
|
+
var canAdd = props.canAdd,
|
|
1920
|
+
className = props.className,
|
|
1921
|
+
disabled = props.disabled,
|
|
1922
|
+
idSchema = props.idSchema,
|
|
1923
|
+
uiSchema = props.uiSchema,
|
|
1924
|
+
items = props.items,
|
|
1925
|
+
onAddClick = props.onAddClick,
|
|
1926
|
+
readonly = props.readonly,
|
|
1927
|
+
registry = props.registry,
|
|
1928
|
+
required = props.required,
|
|
1929
|
+
schema = props.schema,
|
|
1930
|
+
title = props.title;
|
|
1931
|
+
var uiOptions = utils.getUiOptions(uiSchema);
|
|
1932
|
+
var ArrayFieldDescriptionTemplate = utils.getTemplate("ArrayFieldDescriptionTemplate", registry, uiOptions);
|
|
1933
|
+
var ArrayFieldItemTemplate = utils.getTemplate("ArrayFieldItemTemplate", registry, uiOptions);
|
|
1934
|
+
var ArrayFieldTitleTemplate = utils.getTemplate("ArrayFieldTitleTemplate", registry, uiOptions);
|
|
1893
1935
|
// Button templates are not overridden in the uiSchema
|
|
1894
|
-
|
|
1895
|
-
ButtonTemplates: {
|
|
1896
|
-
AddButton
|
|
1897
|
-
}
|
|
1898
|
-
} = registry.templates;
|
|
1936
|
+
var AddButton = registry.templates.ButtonTemplates.AddButton;
|
|
1899
1937
|
return /*#__PURE__*/React__default["default"].createElement("fieldset", {
|
|
1900
1938
|
className: className,
|
|
1901
1939
|
id: idSchema.$id
|
|
@@ -1914,15 +1952,12 @@
|
|
|
1914
1952
|
registry: registry
|
|
1915
1953
|
}), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1916
1954
|
className: "row array-item-list"
|
|
1917
|
-
}, items && items.map(_ref
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
key: key,
|
|
1924
|
-
...itemProps
|
|
1925
|
-
});
|
|
1955
|
+
}, items && items.map(function (_ref) {
|
|
1956
|
+
var key = _ref.key,
|
|
1957
|
+
itemProps = _objectWithoutPropertiesLoose(_ref, _excluded$4);
|
|
1958
|
+
return /*#__PURE__*/React__default["default"].createElement(ArrayFieldItemTemplate, _extends({
|
|
1959
|
+
key: key
|
|
1960
|
+
}, itemProps));
|
|
1926
1961
|
})), canAdd && /*#__PURE__*/React__default["default"].createElement(AddButton, {
|
|
1927
1962
|
className: "array-item-add",
|
|
1928
1963
|
onClick: onAddClick,
|
|
@@ -1937,23 +1972,20 @@
|
|
|
1937
1972
|
* @param props - The `ArrayFieldTitleProps` for the component
|
|
1938
1973
|
*/
|
|
1939
1974
|
function ArrayFieldTitleTemplate(props) {
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
const {
|
|
1950
|
-
label: displayLabel = true
|
|
1951
|
-
} = options;
|
|
1975
|
+
var idSchema = props.idSchema,
|
|
1976
|
+
title = props.title,
|
|
1977
|
+
schema = props.schema,
|
|
1978
|
+
uiSchema = props.uiSchema,
|
|
1979
|
+
required = props.required,
|
|
1980
|
+
registry = props.registry;
|
|
1981
|
+
var options = utils.getUiOptions(uiSchema);
|
|
1982
|
+
var _options$label = options.label,
|
|
1983
|
+
displayLabel = _options$label === void 0 ? true : _options$label;
|
|
1952
1984
|
if (!title || !displayLabel) {
|
|
1953
1985
|
return null;
|
|
1954
1986
|
}
|
|
1955
|
-
|
|
1956
|
-
|
|
1987
|
+
var TitleFieldTemplate = utils.getTemplate("TitleFieldTemplate", registry, options);
|
|
1988
|
+
var id = idSchema.$id + "__title";
|
|
1957
1989
|
return /*#__PURE__*/React__default["default"].createElement(TitleFieldTemplate, {
|
|
1958
1990
|
id: id,
|
|
1959
1991
|
title: title,
|
|
@@ -1964,6 +1996,7 @@
|
|
|
1964
1996
|
});
|
|
1965
1997
|
}
|
|
1966
1998
|
|
|
1999
|
+
var _excluded$3 = ["id", "value", "readonly", "disabled", "autofocus", "onBlur", "onFocus", "onChange", "options", "schema", "uiSchema", "formContext", "registry", "rawErrors", "type"];
|
|
1967
2000
|
/** The `BaseInputTemplate` is the template to use to render the basic `<input>` component for the `core` theme.
|
|
1968
2001
|
* It is used as the template for rendering many of the <input> based widgets that differ by `type` and callbacks only.
|
|
1969
2002
|
* It can be customized/overridden for other themes or individual implementations as needed.
|
|
@@ -1971,161 +2004,136 @@
|
|
|
1971
2004
|
* @param props - The `WidgetProps` for this template
|
|
1972
2005
|
*/
|
|
1973
2006
|
function BaseInputTemplate(props) {
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
formContext,
|
|
1987
|
-
registry,
|
|
1988
|
-
rawErrors,
|
|
1989
|
-
type,
|
|
1990
|
-
...rest
|
|
1991
|
-
} = props;
|
|
2007
|
+
var id = props.id,
|
|
2008
|
+
value = props.value,
|
|
2009
|
+
readonly = props.readonly,
|
|
2010
|
+
disabled = props.disabled,
|
|
2011
|
+
autofocus = props.autofocus,
|
|
2012
|
+
onBlur = props.onBlur,
|
|
2013
|
+
onFocus = props.onFocus,
|
|
2014
|
+
onChange = props.onChange,
|
|
2015
|
+
options = props.options,
|
|
2016
|
+
schema = props.schema,
|
|
2017
|
+
type = props.type,
|
|
2018
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded$3);
|
|
1992
2019
|
// Note: since React 15.2.0 we can't forward unknown element attributes, so we
|
|
1993
2020
|
// exclude the "options" and "schema" ones here.
|
|
1994
2021
|
if (!id) {
|
|
1995
2022
|
console.log("No id for", props);
|
|
1996
|
-
throw new Error(
|
|
2023
|
+
throw new Error("no id for props " + JSON.stringify(props));
|
|
1997
2024
|
}
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
...utils.getInputProps(schema, type, options)
|
|
2001
|
-
};
|
|
2002
|
-
let inputValue;
|
|
2025
|
+
var inputProps = _extends({}, rest, utils.getInputProps(schema, type, options));
|
|
2026
|
+
var inputValue;
|
|
2003
2027
|
if (inputProps.type === "number" || inputProps.type === "integer") {
|
|
2004
2028
|
inputValue = value || value === 0 ? value : "";
|
|
2005
2029
|
} else {
|
|
2006
2030
|
inputValue = value == null ? "" : value;
|
|
2007
2031
|
}
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
target: {
|
|
2011
|
-
value
|
|
2012
|
-
}
|
|
2013
|
-
} = _ref;
|
|
2032
|
+
var _onChange = React.useCallback(function (_ref) {
|
|
2033
|
+
var value = _ref.target.value;
|
|
2014
2034
|
return onChange(value === "" ? options.emptyValue : value);
|
|
2015
2035
|
}, [onChange, options]);
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
target: {
|
|
2019
|
-
value
|
|
2020
|
-
}
|
|
2021
|
-
} = _ref2;
|
|
2036
|
+
var _onBlur = React.useCallback(function (_ref2) {
|
|
2037
|
+
var value = _ref2.target.value;
|
|
2022
2038
|
return onBlur(id, value);
|
|
2023
2039
|
}, [onBlur, id]);
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
target: {
|
|
2027
|
-
value
|
|
2028
|
-
}
|
|
2029
|
-
} = _ref3;
|
|
2040
|
+
var _onFocus = React.useCallback(function (_ref3) {
|
|
2041
|
+
var value = _ref3.target.value;
|
|
2030
2042
|
return onFocus(id, value);
|
|
2031
2043
|
}, [onFocus, id]);
|
|
2032
|
-
return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("input", {
|
|
2044
|
+
return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("input", _extends({
|
|
2033
2045
|
id: id,
|
|
2034
2046
|
name: id,
|
|
2035
2047
|
className: "form-control",
|
|
2036
2048
|
readOnly: readonly,
|
|
2037
2049
|
disabled: disabled,
|
|
2038
2050
|
autoFocus: autofocus,
|
|
2039
|
-
value: inputValue
|
|
2040
|
-
|
|
2041
|
-
list: schema.examples ?
|
|
2051
|
+
value: inputValue
|
|
2052
|
+
}, inputProps, {
|
|
2053
|
+
list: schema.examples ? "examples_" + id : undefined,
|
|
2042
2054
|
onChange: _onChange,
|
|
2043
2055
|
onBlur: _onBlur,
|
|
2044
2056
|
onFocus: _onFocus
|
|
2045
|
-
}), Array.isArray(schema.examples) && /*#__PURE__*/React__default["default"].createElement("datalist", {
|
|
2046
|
-
key:
|
|
2047
|
-
id:
|
|
2048
|
-
}, [
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2057
|
+
})), Array.isArray(schema.examples) && /*#__PURE__*/React__default["default"].createElement("datalist", {
|
|
2058
|
+
key: "datalist_" + id,
|
|
2059
|
+
id: "examples_" + id
|
|
2060
|
+
}, [].concat(new Set(schema.examples.concat(schema["default"] ? [schema["default"]] : []))).map(function (example) {
|
|
2061
|
+
return /*#__PURE__*/React__default["default"].createElement("option", {
|
|
2062
|
+
key: example,
|
|
2063
|
+
value: example
|
|
2064
|
+
});
|
|
2065
|
+
})));
|
|
2052
2066
|
}
|
|
2053
2067
|
|
|
2054
2068
|
/** The `SubmitButton` renders a button that represent the `Submit` action on a form
|
|
2055
2069
|
*/
|
|
2056
2070
|
function SubmitButton(_ref) {
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
props: submitButtonProps = {}
|
|
2064
|
-
} = utils.getSubmitButtonOptions(uiSchema);
|
|
2071
|
+
var uiSchema = _ref.uiSchema;
|
|
2072
|
+
var _getSubmitButtonOptio = utils.getSubmitButtonOptions(uiSchema),
|
|
2073
|
+
submitText = _getSubmitButtonOptio.submitText,
|
|
2074
|
+
norender = _getSubmitButtonOptio.norender,
|
|
2075
|
+
_getSubmitButtonOptio2 = _getSubmitButtonOptio.props,
|
|
2076
|
+
submitButtonProps = _getSubmitButtonOptio2 === void 0 ? {} : _getSubmitButtonOptio2;
|
|
2065
2077
|
if (norender) {
|
|
2066
2078
|
return null;
|
|
2067
2079
|
}
|
|
2068
|
-
return /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement("button", {
|
|
2069
|
-
type: "submit"
|
|
2070
|
-
|
|
2071
|
-
className:
|
|
2072
|
-
}, submitText));
|
|
2080
|
+
return /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement("button", _extends({
|
|
2081
|
+
type: "submit"
|
|
2082
|
+
}, submitButtonProps, {
|
|
2083
|
+
className: "btn btn-info " + submitButtonProps.className
|
|
2084
|
+
}), submitText));
|
|
2073
2085
|
}
|
|
2074
2086
|
|
|
2087
|
+
var _excluded$2 = ["iconType", "icon", "className", "uiSchema"];
|
|
2075
2088
|
function IconButton(props) {
|
|
2076
|
-
|
|
2077
|
-
iconType = "default",
|
|
2078
|
-
icon,
|
|
2079
|
-
className,
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
} = props;
|
|
2083
|
-
return /*#__PURE__*/React__default["default"].createElement("button", {
|
|
2089
|
+
var _props$iconType = props.iconType,
|
|
2090
|
+
iconType = _props$iconType === void 0 ? "default" : _props$iconType,
|
|
2091
|
+
icon = props.icon,
|
|
2092
|
+
className = props.className,
|
|
2093
|
+
otherProps = _objectWithoutPropertiesLoose(props, _excluded$2);
|
|
2094
|
+
return /*#__PURE__*/React__default["default"].createElement("button", _extends({
|
|
2084
2095
|
type: "button",
|
|
2085
|
-
className:
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
className: `glyphicon glyphicon-${icon}`
|
|
2096
|
+
className: "btn btn-" + iconType + " " + className
|
|
2097
|
+
}, otherProps), /*#__PURE__*/React__default["default"].createElement("i", {
|
|
2098
|
+
className: "glyphicon glyphicon-" + icon
|
|
2089
2099
|
}));
|
|
2090
2100
|
}
|
|
2091
2101
|
function MoveDownButton(props) {
|
|
2092
|
-
return /*#__PURE__*/React__default["default"].createElement(IconButton, {
|
|
2102
|
+
return /*#__PURE__*/React__default["default"].createElement(IconButton, _extends({
|
|
2093
2103
|
title: "Move down",
|
|
2094
|
-
className: "array-item-move-down"
|
|
2095
|
-
|
|
2104
|
+
className: "array-item-move-down"
|
|
2105
|
+
}, props, {
|
|
2096
2106
|
icon: "arrow-down"
|
|
2097
|
-
});
|
|
2107
|
+
}));
|
|
2098
2108
|
}
|
|
2099
2109
|
function MoveUpButton(props) {
|
|
2100
|
-
return /*#__PURE__*/React__default["default"].createElement(IconButton, {
|
|
2110
|
+
return /*#__PURE__*/React__default["default"].createElement(IconButton, _extends({
|
|
2101
2111
|
title: "Move up",
|
|
2102
|
-
className: "array-item-move-up"
|
|
2103
|
-
|
|
2112
|
+
className: "array-item-move-up"
|
|
2113
|
+
}, props, {
|
|
2104
2114
|
icon: "arrow-up"
|
|
2105
|
-
});
|
|
2115
|
+
}));
|
|
2106
2116
|
}
|
|
2107
2117
|
function RemoveButton(props) {
|
|
2108
|
-
return /*#__PURE__*/React__default["default"].createElement(IconButton, {
|
|
2118
|
+
return /*#__PURE__*/React__default["default"].createElement(IconButton, _extends({
|
|
2109
2119
|
title: "Remove",
|
|
2110
|
-
className: "array-item-remove"
|
|
2111
|
-
|
|
2120
|
+
className: "array-item-remove"
|
|
2121
|
+
}, props, {
|
|
2112
2122
|
iconType: "danger",
|
|
2113
2123
|
icon: "remove"
|
|
2114
|
-
});
|
|
2124
|
+
}));
|
|
2115
2125
|
}
|
|
2116
2126
|
|
|
2117
2127
|
/** The `AddButton` renders a button that represent the `Add` action on a form
|
|
2118
2128
|
*/
|
|
2119
2129
|
function AddButton(_ref) {
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
disabled
|
|
2124
|
-
} = _ref;
|
|
2130
|
+
var className = _ref.className,
|
|
2131
|
+
onClick = _ref.onClick,
|
|
2132
|
+
disabled = _ref.disabled;
|
|
2125
2133
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
2126
2134
|
className: "row"
|
|
2127
2135
|
}, /*#__PURE__*/React__default["default"].createElement("p", {
|
|
2128
|
-
className:
|
|
2136
|
+
className: "col-xs-3 col-xs-offset-9 text-right " + className
|
|
2129
2137
|
}, /*#__PURE__*/React__default["default"].createElement(IconButton, {
|
|
2130
2138
|
iconType: "info",
|
|
2131
2139
|
icon: "plus",
|
|
@@ -2138,11 +2146,11 @@
|
|
|
2138
2146
|
|
|
2139
2147
|
function buttonTemplates() {
|
|
2140
2148
|
return {
|
|
2141
|
-
SubmitButton,
|
|
2142
|
-
AddButton,
|
|
2143
|
-
MoveDownButton,
|
|
2144
|
-
MoveUpButton,
|
|
2145
|
-
RemoveButton
|
|
2149
|
+
SubmitButton: SubmitButton,
|
|
2150
|
+
AddButton: AddButton,
|
|
2151
|
+
MoveDownButton: MoveDownButton,
|
|
2152
|
+
MoveUpButton: MoveUpButton,
|
|
2153
|
+
RemoveButton: RemoveButton
|
|
2146
2154
|
};
|
|
2147
2155
|
}
|
|
2148
2156
|
|
|
@@ -2151,10 +2159,8 @@
|
|
|
2151
2159
|
* @param props - The `DescriptionFieldProps` for this component
|
|
2152
2160
|
*/
|
|
2153
2161
|
function DescriptionField(props) {
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
description
|
|
2157
|
-
} = props;
|
|
2162
|
+
var id = props.id,
|
|
2163
|
+
description = props.description;
|
|
2158
2164
|
if (!description) {
|
|
2159
2165
|
return null;
|
|
2160
2166
|
}
|
|
@@ -2176,9 +2182,7 @@
|
|
|
2176
2182
|
* @param props - The `ErrorListProps` for this component
|
|
2177
2183
|
*/
|
|
2178
2184
|
function ErrorList(_ref) {
|
|
2179
|
-
|
|
2180
|
-
errors
|
|
2181
|
-
} = _ref;
|
|
2185
|
+
var errors = _ref.errors;
|
|
2182
2186
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
2183
2187
|
className: "panel panel-danger errors"
|
|
2184
2188
|
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
@@ -2187,7 +2191,7 @@
|
|
|
2187
2191
|
className: "panel-title"
|
|
2188
2192
|
}, "Errors")), /*#__PURE__*/React__default["default"].createElement("ul", {
|
|
2189
2193
|
className: "list-group"
|
|
2190
|
-
}, errors.map((error, i)
|
|
2194
|
+
}, errors.map(function (error, i) {
|
|
2191
2195
|
return /*#__PURE__*/React__default["default"].createElement("li", {
|
|
2192
2196
|
key: i,
|
|
2193
2197
|
className: "list-group-item text-danger"
|
|
@@ -2195,17 +2199,15 @@
|
|
|
2195
2199
|
})));
|
|
2196
2200
|
}
|
|
2197
2201
|
|
|
2198
|
-
|
|
2202
|
+
var REQUIRED_FIELD_SYMBOL$1 = "*";
|
|
2199
2203
|
/** Renders a label for a field
|
|
2200
2204
|
*
|
|
2201
2205
|
* @param props - The `LabelProps` for this component
|
|
2202
2206
|
*/
|
|
2203
2207
|
function Label(props) {
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
id
|
|
2208
|
-
} = props;
|
|
2208
|
+
var label = props.label,
|
|
2209
|
+
required = props.required,
|
|
2210
|
+
id = props.id;
|
|
2209
2211
|
if (!label) {
|
|
2210
2212
|
return null;
|
|
2211
2213
|
}
|
|
@@ -2223,29 +2225,25 @@
|
|
|
2223
2225
|
* @param props - The `FieldTemplateProps` for this component
|
|
2224
2226
|
*/
|
|
2225
2227
|
function FieldTemplate(props) {
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
const uiOptions = utils.getUiOptions(uiSchema);
|
|
2240
|
-
const WrapIfAdditionalTemplate = utils.getTemplate("WrapIfAdditionalTemplate", registry, uiOptions);
|
|
2228
|
+
var id = props.id,
|
|
2229
|
+
label = props.label,
|
|
2230
|
+
children = props.children,
|
|
2231
|
+
errors = props.errors,
|
|
2232
|
+
help = props.help,
|
|
2233
|
+
description = props.description,
|
|
2234
|
+
hidden = props.hidden,
|
|
2235
|
+
required = props.required,
|
|
2236
|
+
displayLabel = props.displayLabel,
|
|
2237
|
+
registry = props.registry,
|
|
2238
|
+
uiSchema = props.uiSchema;
|
|
2239
|
+
var uiOptions = utils.getUiOptions(uiSchema);
|
|
2240
|
+
var WrapIfAdditionalTemplate = utils.getTemplate("WrapIfAdditionalTemplate", registry, uiOptions);
|
|
2241
2241
|
if (hidden) {
|
|
2242
2242
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
2243
2243
|
className: "hidden"
|
|
2244
2244
|
}, children);
|
|
2245
2245
|
}
|
|
2246
|
-
return /*#__PURE__*/React__default["default"].createElement(WrapIfAdditionalTemplate, {
|
|
2247
|
-
...props
|
|
2248
|
-
}, displayLabel && /*#__PURE__*/React__default["default"].createElement(Label, {
|
|
2246
|
+
return /*#__PURE__*/React__default["default"].createElement(WrapIfAdditionalTemplate, _extends({}, props), displayLabel && /*#__PURE__*/React__default["default"].createElement(Label, {
|
|
2249
2247
|
label: label,
|
|
2250
2248
|
required: required,
|
|
2251
2249
|
id: id
|
|
@@ -2257,18 +2255,19 @@
|
|
|
2257
2255
|
* @param props - The `FieldErrorProps` for the errors being rendered
|
|
2258
2256
|
*/
|
|
2259
2257
|
function FieldErrorTemplate(props) {
|
|
2260
|
-
|
|
2261
|
-
errors = [],
|
|
2262
|
-
idSchema
|
|
2263
|
-
} = props;
|
|
2258
|
+
var _props$errors = props.errors,
|
|
2259
|
+
errors = _props$errors === void 0 ? [] : _props$errors,
|
|
2260
|
+
idSchema = props.idSchema;
|
|
2264
2261
|
if (errors.length === 0) {
|
|
2265
2262
|
return null;
|
|
2266
2263
|
}
|
|
2267
|
-
|
|
2264
|
+
var id = idSchema.$id + "__error";
|
|
2268
2265
|
return /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement("ul", {
|
|
2269
2266
|
id: id,
|
|
2270
2267
|
className: "error-detail bs-callout bs-callout-info"
|
|
2271
|
-
}, errors.filter(
|
|
2268
|
+
}, errors.filter(function (elem) {
|
|
2269
|
+
return !!elem;
|
|
2270
|
+
}).map(function (error, index) {
|
|
2272
2271
|
return /*#__PURE__*/React__default["default"].createElement("li", {
|
|
2273
2272
|
className: "text-danger",
|
|
2274
2273
|
key: index
|
|
@@ -2281,14 +2280,12 @@
|
|
|
2281
2280
|
* @param props - The `FieldHelpProps` to be rendered
|
|
2282
2281
|
*/
|
|
2283
2282
|
function FieldHelpTemplate(props) {
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
help
|
|
2287
|
-
} = props;
|
|
2283
|
+
var idSchema = props.idSchema,
|
|
2284
|
+
help = props.help;
|
|
2288
2285
|
if (!help) {
|
|
2289
2286
|
return null;
|
|
2290
2287
|
}
|
|
2291
|
-
|
|
2288
|
+
var id = idSchema.$id + "__help";
|
|
2292
2289
|
if (typeof help === "string") {
|
|
2293
2290
|
return /*#__PURE__*/React__default["default"].createElement("p", {
|
|
2294
2291
|
id: id,
|
|
@@ -2308,45 +2305,41 @@
|
|
|
2308
2305
|
* @param props - The `ObjectFieldTemplateProps` for this component
|
|
2309
2306
|
*/
|
|
2310
2307
|
function ObjectFieldTemplate(props) {
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
const TitleFieldTemplate = utils.getTemplate("TitleFieldTemplate", registry, options);
|
|
2327
|
-
const DescriptionFieldTemplate = utils.getTemplate("DescriptionFieldTemplate", registry, options);
|
|
2308
|
+
var description = props.description,
|
|
2309
|
+
disabled = props.disabled,
|
|
2310
|
+
formData = props.formData,
|
|
2311
|
+
idSchema = props.idSchema,
|
|
2312
|
+
onAddClick = props.onAddClick,
|
|
2313
|
+
properties = props.properties,
|
|
2314
|
+
readonly = props.readonly,
|
|
2315
|
+
registry = props.registry,
|
|
2316
|
+
required = props.required,
|
|
2317
|
+
schema = props.schema,
|
|
2318
|
+
title = props.title,
|
|
2319
|
+
uiSchema = props.uiSchema;
|
|
2320
|
+
var options = utils.getUiOptions(uiSchema);
|
|
2321
|
+
var TitleFieldTemplate = utils.getTemplate("TitleFieldTemplate", registry, options);
|
|
2322
|
+
var DescriptionFieldTemplate = utils.getTemplate("DescriptionFieldTemplate", registry, options);
|
|
2328
2323
|
// Button templates are not overridden in the uiSchema
|
|
2329
|
-
|
|
2330
|
-
ButtonTemplates: {
|
|
2331
|
-
AddButton
|
|
2332
|
-
}
|
|
2333
|
-
} = registry.templates;
|
|
2324
|
+
var AddButton = registry.templates.ButtonTemplates.AddButton;
|
|
2334
2325
|
return /*#__PURE__*/React__default["default"].createElement("fieldset", {
|
|
2335
2326
|
id: idSchema.$id
|
|
2336
2327
|
}, (options.title || title) && /*#__PURE__*/React__default["default"].createElement(TitleFieldTemplate, {
|
|
2337
|
-
id:
|
|
2328
|
+
id: idSchema.$id + "__title",
|
|
2338
2329
|
title: options.title || title,
|
|
2339
2330
|
required: required,
|
|
2340
2331
|
schema: schema,
|
|
2341
2332
|
uiSchema: uiSchema,
|
|
2342
2333
|
registry: registry
|
|
2343
2334
|
}), (options.description || description) && /*#__PURE__*/React__default["default"].createElement(DescriptionFieldTemplate, {
|
|
2344
|
-
id:
|
|
2335
|
+
id: idSchema.$id + "__description",
|
|
2345
2336
|
description: options.description || description,
|
|
2346
2337
|
schema: schema,
|
|
2347
2338
|
uiSchema: uiSchema,
|
|
2348
2339
|
registry: registry
|
|
2349
|
-
}), properties.map(
|
|
2340
|
+
}), properties.map(function (prop) {
|
|
2341
|
+
return prop.content;
|
|
2342
|
+
}), utils.canExpand(schema, uiSchema, formData) && /*#__PURE__*/React__default["default"].createElement(AddButton, {
|
|
2350
2343
|
className: "object-property-expand",
|
|
2351
2344
|
onClick: onAddClick(schema),
|
|
2352
2345
|
disabled: disabled || readonly,
|
|
@@ -2354,17 +2347,15 @@
|
|
|
2354
2347
|
}));
|
|
2355
2348
|
}
|
|
2356
2349
|
|
|
2357
|
-
|
|
2350
|
+
var REQUIRED_FIELD_SYMBOL = "*";
|
|
2358
2351
|
/** The `TitleField` is the template to use to render the title of a field
|
|
2359
2352
|
*
|
|
2360
2353
|
* @param props - The `TitleFieldProps` for this component
|
|
2361
2354
|
*/
|
|
2362
2355
|
function TitleField(props) {
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
required
|
|
2367
|
-
} = props;
|
|
2356
|
+
var id = props.id,
|
|
2357
|
+
title = props.title,
|
|
2358
|
+
required = props.required;
|
|
2368
2359
|
return /*#__PURE__*/React__default["default"].createElement("legend", {
|
|
2369
2360
|
id: id
|
|
2370
2361
|
}, title, required && /*#__PURE__*/React__default["default"].createElement("span", {
|
|
@@ -2378,11 +2369,9 @@
|
|
|
2378
2369
|
* @param props - The `FieldProps` for this template
|
|
2379
2370
|
*/
|
|
2380
2371
|
function UnsupportedField(props) {
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
reason
|
|
2385
|
-
} = props;
|
|
2372
|
+
var schema = props.schema,
|
|
2373
|
+
idSchema = props.idSchema,
|
|
2374
|
+
reason = props.reason;
|
|
2386
2375
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
2387
2376
|
className: "unsupported-field"
|
|
2388
2377
|
}, /*#__PURE__*/React__default["default"].createElement("p", null, "Unsupported field schema", idSchema && idSchema.$id && /*#__PURE__*/React__default["default"].createElement("span", null, " for", " field ", /*#__PURE__*/React__default["default"].createElement("code", null, idSchema.$id)), reason && /*#__PURE__*/React__default["default"].createElement("em", null, ": ", reason), "."), schema && /*#__PURE__*/React__default["default"].createElement("pre", null, JSON.stringify(schema, null, 2)));
|
|
@@ -2394,26 +2383,22 @@
|
|
|
2394
2383
|
* @param props - The `WrapIfAdditionalProps` for this component
|
|
2395
2384
|
*/
|
|
2396
2385
|
function WrapIfAdditionalTemplate(props) {
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
registry
|
|
2410
|
-
} = props;
|
|
2386
|
+
var id = props.id,
|
|
2387
|
+
classNames = props.classNames,
|
|
2388
|
+
disabled = props.disabled,
|
|
2389
|
+
label = props.label,
|
|
2390
|
+
onKeyChange = props.onKeyChange,
|
|
2391
|
+
onDropPropertyClick = props.onDropPropertyClick,
|
|
2392
|
+
readonly = props.readonly,
|
|
2393
|
+
required = props.required,
|
|
2394
|
+
schema = props.schema,
|
|
2395
|
+
children = props.children,
|
|
2396
|
+
uiSchema = props.uiSchema,
|
|
2397
|
+
registry = props.registry;
|
|
2411
2398
|
// Button templates are not overridden in the uiSchema
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
const keyLabel = `${label} Key`; // i18n ?
|
|
2416
|
-
const additional = (utils.ADDITIONAL_PROPERTY_FLAG in schema);
|
|
2399
|
+
var RemoveButton = registry.templates.ButtonTemplates.RemoveButton;
|
|
2400
|
+
var keyLabel = label + " Key"; // i18n ?
|
|
2401
|
+
var additional = (utils.ADDITIONAL_PROPERTY_FLAG in schema);
|
|
2417
2402
|
if (!additional) {
|
|
2418
2403
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
2419
2404
|
className: classNames
|
|
@@ -2430,12 +2415,14 @@
|
|
|
2430
2415
|
}, /*#__PURE__*/React__default["default"].createElement(Label, {
|
|
2431
2416
|
label: keyLabel,
|
|
2432
2417
|
required: required,
|
|
2433
|
-
id:
|
|
2418
|
+
id: id + "-key"
|
|
2434
2419
|
}), /*#__PURE__*/React__default["default"].createElement("input", {
|
|
2435
2420
|
className: "form-control",
|
|
2436
2421
|
type: "text",
|
|
2437
|
-
id:
|
|
2438
|
-
onBlur:
|
|
2422
|
+
id: id + "-key",
|
|
2423
|
+
onBlur: function onBlur(event) {
|
|
2424
|
+
return onKeyChange(event.target.value);
|
|
2425
|
+
},
|
|
2439
2426
|
defaultValue: label
|
|
2440
2427
|
}))), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
2441
2428
|
className: "form-additional form-group col-xs-5"
|
|
@@ -2454,27 +2441,27 @@
|
|
|
2454
2441
|
|
|
2455
2442
|
function templates() {
|
|
2456
2443
|
return {
|
|
2457
|
-
ArrayFieldDescriptionTemplate,
|
|
2458
|
-
ArrayFieldItemTemplate,
|
|
2459
|
-
ArrayFieldTemplate,
|
|
2460
|
-
ArrayFieldTitleTemplate,
|
|
2444
|
+
ArrayFieldDescriptionTemplate: ArrayFieldDescriptionTemplate,
|
|
2445
|
+
ArrayFieldItemTemplate: ArrayFieldItemTemplate,
|
|
2446
|
+
ArrayFieldTemplate: ArrayFieldTemplate,
|
|
2447
|
+
ArrayFieldTitleTemplate: ArrayFieldTitleTemplate,
|
|
2461
2448
|
ButtonTemplates: buttonTemplates(),
|
|
2462
|
-
BaseInputTemplate,
|
|
2449
|
+
BaseInputTemplate: BaseInputTemplate,
|
|
2463
2450
|
DescriptionFieldTemplate: DescriptionField,
|
|
2464
2451
|
ErrorListTemplate: ErrorList,
|
|
2465
|
-
FieldTemplate,
|
|
2466
|
-
FieldErrorTemplate,
|
|
2467
|
-
FieldHelpTemplate,
|
|
2468
|
-
ObjectFieldTemplate,
|
|
2452
|
+
FieldTemplate: FieldTemplate,
|
|
2453
|
+
FieldErrorTemplate: FieldErrorTemplate,
|
|
2454
|
+
FieldHelpTemplate: FieldHelpTemplate,
|
|
2455
|
+
ObjectFieldTemplate: ObjectFieldTemplate,
|
|
2469
2456
|
TitleFieldTemplate: TitleField,
|
|
2470
2457
|
UnsupportedFieldTemplate: UnsupportedField,
|
|
2471
|
-
WrapIfAdditionalTemplate
|
|
2458
|
+
WrapIfAdditionalTemplate: WrapIfAdditionalTemplate
|
|
2472
2459
|
};
|
|
2473
2460
|
}
|
|
2474
2461
|
|
|
2475
2462
|
function rangeOptions(start, stop) {
|
|
2476
|
-
|
|
2477
|
-
for (
|
|
2463
|
+
var options = [];
|
|
2464
|
+
for (var i = start; i <= stop; i++) {
|
|
2478
2465
|
options.push({
|
|
2479
2466
|
value: i,
|
|
2480
2467
|
label: utils.pad(i, 2)
|
|
@@ -2483,21 +2470,21 @@
|
|
|
2483
2470
|
return options;
|
|
2484
2471
|
}
|
|
2485
2472
|
function readyForChange(state) {
|
|
2486
|
-
return Object.values(state).every(
|
|
2473
|
+
return Object.values(state).every(function (value) {
|
|
2474
|
+
return value !== -1;
|
|
2475
|
+
});
|
|
2487
2476
|
}
|
|
2488
2477
|
function dateElementProps(state, time, yearsRange) {
|
|
2489
2478
|
if (yearsRange === void 0) {
|
|
2490
2479
|
yearsRange = [1900, new Date().getFullYear() + 2];
|
|
2491
2480
|
}
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
} = state;
|
|
2500
|
-
const data = [{
|
|
2481
|
+
var year = state.year,
|
|
2482
|
+
month = state.month,
|
|
2483
|
+
day = state.day,
|
|
2484
|
+
hour = state.hour,
|
|
2485
|
+
minute = state.minute,
|
|
2486
|
+
second = state.second;
|
|
2487
|
+
var data = [{
|
|
2501
2488
|
type: "year",
|
|
2502
2489
|
range: yearsRange,
|
|
2503
2490
|
value: year
|
|
@@ -2528,23 +2515,19 @@
|
|
|
2528
2515
|
return data;
|
|
2529
2516
|
}
|
|
2530
2517
|
function DateElement(_ref) {
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
const id = rootId + "_" + type;
|
|
2545
|
-
const {
|
|
2546
|
-
SelectWidget
|
|
2547
|
-
} = registry.widgets;
|
|
2518
|
+
var type = _ref.type,
|
|
2519
|
+
range = _ref.range,
|
|
2520
|
+
value = _ref.value,
|
|
2521
|
+
select = _ref.select,
|
|
2522
|
+
rootId = _ref.rootId,
|
|
2523
|
+
disabled = _ref.disabled,
|
|
2524
|
+
readonly = _ref.readonly,
|
|
2525
|
+
autofocus = _ref.autofocus,
|
|
2526
|
+
registry = _ref.registry,
|
|
2527
|
+
onBlur = _ref.onBlur,
|
|
2528
|
+
onFocus = _ref.onFocus;
|
|
2529
|
+
var id = rootId + "_" + type;
|
|
2530
|
+
var SelectWidget = registry.widgets.SelectWidget;
|
|
2548
2531
|
return /*#__PURE__*/React__default["default"].createElement(SelectWidget, {
|
|
2549
2532
|
schema: {
|
|
2550
2533
|
type: "integer"
|
|
@@ -2559,7 +2542,9 @@
|
|
|
2559
2542
|
disabled: disabled,
|
|
2560
2543
|
readonly: readonly,
|
|
2561
2544
|
autofocus: autofocus,
|
|
2562
|
-
onChange:
|
|
2545
|
+
onChange: function onChange(value) {
|
|
2546
|
+
return select(type, value);
|
|
2547
|
+
},
|
|
2563
2548
|
onBlur: onBlur,
|
|
2564
2549
|
onFocus: onFocus,
|
|
2565
2550
|
registry: registry,
|
|
@@ -2570,50 +2555,50 @@
|
|
|
2570
2555
|
* @param props - The `WidgetProps` for this component
|
|
2571
2556
|
*/
|
|
2572
2557
|
function AltDateWidget(_ref2) {
|
|
2573
|
-
|
|
2574
|
-
time = false,
|
|
2575
|
-
disabled =
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
}
|
|
2591
|
-
|
|
2592
|
-
|
|
2558
|
+
var _ref2$time = _ref2.time,
|
|
2559
|
+
time = _ref2$time === void 0 ? false : _ref2$time,
|
|
2560
|
+
_ref2$disabled = _ref2.disabled,
|
|
2561
|
+
disabled = _ref2$disabled === void 0 ? false : _ref2$disabled,
|
|
2562
|
+
_ref2$readonly = _ref2.readonly,
|
|
2563
|
+
readonly = _ref2$readonly === void 0 ? false : _ref2$readonly,
|
|
2564
|
+
_ref2$autofocus = _ref2.autofocus,
|
|
2565
|
+
autofocus = _ref2$autofocus === void 0 ? false : _ref2$autofocus,
|
|
2566
|
+
options = _ref2.options,
|
|
2567
|
+
id = _ref2.id,
|
|
2568
|
+
registry = _ref2.registry,
|
|
2569
|
+
onBlur = _ref2.onBlur,
|
|
2570
|
+
onFocus = _ref2.onFocus,
|
|
2571
|
+
onChange = _ref2.onChange,
|
|
2572
|
+
value = _ref2.value;
|
|
2573
|
+
var _useReducer = React.useReducer(function (state, action) {
|
|
2574
|
+
return _extends({}, state, action);
|
|
2575
|
+
}, utils.parseDateString(value, time)),
|
|
2576
|
+
state = _useReducer[0],
|
|
2577
|
+
setState = _useReducer[1];
|
|
2578
|
+
React.useEffect(function () {
|
|
2593
2579
|
if (value && value !== utils.toDateString(state, time)) {
|
|
2594
2580
|
setState(utils.parseDateString(value, time));
|
|
2595
2581
|
}
|
|
2596
2582
|
}, [value, state, time]);
|
|
2597
|
-
React.useEffect(()
|
|
2583
|
+
React.useEffect(function () {
|
|
2598
2584
|
if (readyForChange(state)) {
|
|
2599
2585
|
// Only propagate to parent state if we have a complete date{time}
|
|
2600
2586
|
onChange(utils.toDateString(state, time));
|
|
2601
2587
|
}
|
|
2602
2588
|
}, [state, time, onChange]);
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
});
|
|
2589
|
+
var handleChange = React.useCallback(function (property, value) {
|
|
2590
|
+
var _setState;
|
|
2591
|
+
setState((_setState = {}, _setState[property] = value, _setState));
|
|
2607
2592
|
}, []);
|
|
2608
|
-
|
|
2593
|
+
var handleSetNow = React.useCallback(function (event) {
|
|
2609
2594
|
event.preventDefault();
|
|
2610
2595
|
if (disabled || readonly) {
|
|
2611
2596
|
return;
|
|
2612
2597
|
}
|
|
2613
|
-
|
|
2598
|
+
var nowDateObj = utils.parseDateString(new Date().toJSON(), time);
|
|
2614
2599
|
setState(nowDateObj);
|
|
2615
2600
|
}, [disabled, readonly, time]);
|
|
2616
|
-
|
|
2601
|
+
var handleClear = React.useCallback(function (event) {
|
|
2617
2602
|
event.preventDefault();
|
|
2618
2603
|
if (disabled || readonly) {
|
|
2619
2604
|
return;
|
|
@@ -2623,19 +2608,21 @@
|
|
|
2623
2608
|
}, [disabled, readonly, time, onChange]);
|
|
2624
2609
|
return /*#__PURE__*/React__default["default"].createElement("ul", {
|
|
2625
2610
|
className: "list-inline"
|
|
2626
|
-
}, dateElementProps(state, time, options.yearsRange).map((elemProps, i)
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2611
|
+
}, dateElementProps(state, time, options.yearsRange).map(function (elemProps, i) {
|
|
2612
|
+
return /*#__PURE__*/React__default["default"].createElement("li", {
|
|
2613
|
+
key: i
|
|
2614
|
+
}, /*#__PURE__*/React__default["default"].createElement(DateElement, _extends({
|
|
2615
|
+
rootId: id,
|
|
2616
|
+
select: handleChange
|
|
2617
|
+
}, elemProps, {
|
|
2618
|
+
disabled: disabled,
|
|
2619
|
+
readonly: readonly,
|
|
2620
|
+
registry: registry,
|
|
2621
|
+
onBlur: onBlur,
|
|
2622
|
+
onFocus: onFocus,
|
|
2623
|
+
autofocus: autofocus && i === 0
|
|
2624
|
+
})));
|
|
2625
|
+
}), (options.hideNowButton !== "undefined" ? !options.hideNowButton : true) && /*#__PURE__*/React__default["default"].createElement("li", null, /*#__PURE__*/React__default["default"].createElement("a", {
|
|
2639
2626
|
href: "#",
|
|
2640
2627
|
className: "btn btn-info btn-now",
|
|
2641
2628
|
onClick: handleSetNow
|
|
@@ -2646,23 +2633,20 @@
|
|
|
2646
2633
|
}, "Clear")));
|
|
2647
2634
|
}
|
|
2648
2635
|
|
|
2636
|
+
var _excluded$1 = ["time"];
|
|
2649
2637
|
/** The `AltDateTimeWidget` is an alternative widget for rendering datetime properties.
|
|
2650
2638
|
* It uses the AltDateWidget for rendering, with the `time` prop set to true by default.
|
|
2651
2639
|
*
|
|
2652
2640
|
* @param props - The `WidgetProps` for this component
|
|
2653
2641
|
*/
|
|
2654
2642
|
function AltDateTimeWidget(_ref) {
|
|
2655
|
-
|
|
2656
|
-
time = true,
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
}
|
|
2662
|
-
return /*#__PURE__*/React__default["default"].createElement(AltDateWidget, {
|
|
2663
|
-
time: time,
|
|
2664
|
-
...props
|
|
2665
|
-
});
|
|
2643
|
+
var _ref$time = _ref.time,
|
|
2644
|
+
time = _ref$time === void 0 ? true : _ref$time,
|
|
2645
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded$1);
|
|
2646
|
+
var AltDateWidget = props.registry.widgets.AltDateWidget;
|
|
2647
|
+
return /*#__PURE__*/React__default["default"].createElement(AltDateWidget, _extends({
|
|
2648
|
+
time: time
|
|
2649
|
+
}, props));
|
|
2666
2650
|
}
|
|
2667
2651
|
|
|
2668
2652
|
/** The `CheckBoxWidget` is a widget for rendering boolean properties.
|
|
@@ -2671,31 +2655,36 @@
|
|
|
2671
2655
|
* @param props - The `WidgetProps` for this component
|
|
2672
2656
|
*/
|
|
2673
2657
|
function CheckboxWidget(_ref) {
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
autofocus = false,
|
|
2684
|
-
onBlur,
|
|
2685
|
-
onFocus,
|
|
2686
|
-
onChange,
|
|
2687
|
-
registry
|
|
2688
|
-
|
|
2689
|
-
const DescriptionFieldTemplate = utils.getTemplate("DescriptionFieldTemplate", registry, options);
|
|
2658
|
+
var schema = _ref.schema,
|
|
2659
|
+
uiSchema = _ref.uiSchema,
|
|
2660
|
+
options = _ref.options,
|
|
2661
|
+
id = _ref.id,
|
|
2662
|
+
value = _ref.value,
|
|
2663
|
+
disabled = _ref.disabled,
|
|
2664
|
+
readonly = _ref.readonly,
|
|
2665
|
+
label = _ref.label,
|
|
2666
|
+
_ref$autofocus = _ref.autofocus,
|
|
2667
|
+
autofocus = _ref$autofocus === void 0 ? false : _ref$autofocus,
|
|
2668
|
+
onBlur = _ref.onBlur,
|
|
2669
|
+
onFocus = _ref.onFocus,
|
|
2670
|
+
onChange = _ref.onChange,
|
|
2671
|
+
registry = _ref.registry;
|
|
2672
|
+
var DescriptionFieldTemplate = utils.getTemplate("DescriptionFieldTemplate", registry, options);
|
|
2690
2673
|
// Because an unchecked checkbox will cause html5 validation to fail, only add
|
|
2691
2674
|
// the "required" attribute if the field value must be "true", due to the
|
|
2692
2675
|
// "const" or "enum" keywords
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2676
|
+
var required = utils.schemaRequiresTrueValue(schema);
|
|
2677
|
+
var handleChange = React.useCallback(function (event) {
|
|
2678
|
+
return onChange(event.target.checked);
|
|
2679
|
+
}, [onChange]);
|
|
2680
|
+
var handleBlur = React.useCallback(function (event) {
|
|
2681
|
+
return onBlur(id, event.target.checked);
|
|
2682
|
+
}, [onBlur, id]);
|
|
2683
|
+
var handleFocus = React.useCallback(function (event) {
|
|
2684
|
+
return onFocus(id, event.target.checked);
|
|
2685
|
+
}, [onFocus, id]);
|
|
2697
2686
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
2698
|
-
className:
|
|
2687
|
+
className: "checkbox " + (disabled || readonly ? "disabled" : "")
|
|
2699
2688
|
}, schema.description && /*#__PURE__*/React__default["default"].createElement(DescriptionFieldTemplate, {
|
|
2700
2689
|
id: id + "__description",
|
|
2701
2690
|
description: schema.description,
|
|
@@ -2717,14 +2706,18 @@
|
|
|
2717
2706
|
}
|
|
2718
2707
|
|
|
2719
2708
|
function selectValue(value, selected, all) {
|
|
2720
|
-
|
|
2721
|
-
|
|
2709
|
+
var at = all.indexOf(value);
|
|
2710
|
+
var updated = selected.slice(0, at).concat(value, selected.slice(at));
|
|
2722
2711
|
// As inserting values at predefined index positions doesn't work with empty
|
|
2723
2712
|
// arrays, we need to reorder the updated selection to match the initial order
|
|
2724
|
-
return updated.sort((a, b)
|
|
2713
|
+
return updated.sort(function (a, b) {
|
|
2714
|
+
return Number(all.indexOf(a) > all.indexOf(b));
|
|
2715
|
+
});
|
|
2725
2716
|
}
|
|
2726
2717
|
function deselectValue(value, selected) {
|
|
2727
|
-
return selected.filter(
|
|
2718
|
+
return selected.filter(function (v) {
|
|
2719
|
+
return v !== value;
|
|
2720
|
+
});
|
|
2728
2721
|
}
|
|
2729
2722
|
/** The `CheckboxesWidget` is a widget for rendering checkbox groups.
|
|
2730
2723
|
* It is typically used to represent an array of enums.
|
|
@@ -2732,31 +2725,28 @@
|
|
|
2732
2725
|
* @param props - The `WidgetProps` for this component
|
|
2733
2726
|
*/
|
|
2734
2727
|
function CheckboxesWidget(_ref) {
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
options
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
autofocus = false,
|
|
2745
|
-
readonly,
|
|
2746
|
-
onChange
|
|
2747
|
-
} = _ref;
|
|
2728
|
+
var id = _ref.id,
|
|
2729
|
+
disabled = _ref.disabled,
|
|
2730
|
+
_ref$options = _ref.options,
|
|
2731
|
+
_ref$options$inline = _ref$options.inline,
|
|
2732
|
+
inline = _ref$options$inline === void 0 ? false : _ref$options$inline,
|
|
2733
|
+
enumOptions = _ref$options.enumOptions,
|
|
2734
|
+
enumDisabled = _ref$options.enumDisabled,
|
|
2735
|
+
value = _ref.value,
|
|
2736
|
+
_ref$autofocus = _ref.autofocus,
|
|
2737
|
+
autofocus = _ref$autofocus === void 0 ? false : _ref$autofocus,
|
|
2738
|
+
readonly = _ref.readonly,
|
|
2739
|
+
onChange = _ref.onChange;
|
|
2748
2740
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
2749
2741
|
className: "checkboxes",
|
|
2750
2742
|
id: id
|
|
2751
|
-
}, Array.isArray(enumOptions) && enumOptions.map((option, index)
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
value
|
|
2759
|
-
} = _ref2;
|
|
2743
|
+
}, Array.isArray(enumOptions) && enumOptions.map(function (option, index) {
|
|
2744
|
+
var checked = value.indexOf(option.value) !== -1;
|
|
2745
|
+
var itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) != -1;
|
|
2746
|
+
var disabledCls = disabled || itemDisabled || readonly ? "disabled" : "";
|
|
2747
|
+
var handleChange = function handleChange(event) {
|
|
2748
|
+
var all = enumOptions.map(function (_ref2) {
|
|
2749
|
+
var value = _ref2.value;
|
|
2760
2750
|
return value;
|
|
2761
2751
|
});
|
|
2762
2752
|
if (event.target.checked) {
|
|
@@ -2765,9 +2755,9 @@
|
|
|
2765
2755
|
onChange(deselectValue(option.value, value));
|
|
2766
2756
|
}
|
|
2767
2757
|
};
|
|
2768
|
-
|
|
2758
|
+
var checkbox = /*#__PURE__*/React__default["default"].createElement("span", null, /*#__PURE__*/React__default["default"].createElement("input", {
|
|
2769
2759
|
type: "checkbox",
|
|
2770
|
-
id:
|
|
2760
|
+
id: id + "-" + option.value,
|
|
2771
2761
|
name: id,
|
|
2772
2762
|
checked: checked,
|
|
2773
2763
|
disabled: disabled || itemDisabled || readonly,
|
|
@@ -2776,10 +2766,10 @@
|
|
|
2776
2766
|
}), /*#__PURE__*/React__default["default"].createElement("span", null, option.label));
|
|
2777
2767
|
return inline ? /*#__PURE__*/React__default["default"].createElement("label", {
|
|
2778
2768
|
key: option.value,
|
|
2779
|
-
className:
|
|
2769
|
+
className: "checkbox-inline " + disabledCls
|
|
2780
2770
|
}, checkbox) : /*#__PURE__*/React__default["default"].createElement("div", {
|
|
2781
2771
|
key: option.value,
|
|
2782
|
-
className:
|
|
2772
|
+
className: "checkbox " + disabledCls
|
|
2783
2773
|
}, /*#__PURE__*/React__default["default"].createElement("label", null, checkbox));
|
|
2784
2774
|
}));
|
|
2785
2775
|
}
|
|
@@ -2790,18 +2780,16 @@
|
|
|
2790
2780
|
* @param props - The `WidgetProps` for this component
|
|
2791
2781
|
*/
|
|
2792
2782
|
function ColorWidget(props) {
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
type: "color",
|
|
2802
|
-
...props,
|
|
2783
|
+
var disabled = props.disabled,
|
|
2784
|
+
readonly = props.readonly,
|
|
2785
|
+
options = props.options,
|
|
2786
|
+
registry = props.registry;
|
|
2787
|
+
var BaseInputTemplate = utils.getTemplate("BaseInputTemplate", registry, options);
|
|
2788
|
+
return /*#__PURE__*/React__default["default"].createElement(BaseInputTemplate, _extends({
|
|
2789
|
+
type: "color"
|
|
2790
|
+
}, props, {
|
|
2803
2791
|
disabled: disabled || readonly
|
|
2804
|
-
});
|
|
2792
|
+
}));
|
|
2805
2793
|
}
|
|
2806
2794
|
|
|
2807
2795
|
/** The `DateWidget` component uses the `BaseInputTemplate` changing the type to `date` and transforms
|
|
@@ -2810,18 +2798,18 @@
|
|
|
2810
2798
|
* @param props - The `WidgetProps` for this component
|
|
2811
2799
|
*/
|
|
2812
2800
|
function DateWidget(props) {
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
return /*#__PURE__*/React__default["default"].createElement(BaseInputTemplate, {
|
|
2821
|
-
type: "date"
|
|
2822
|
-
|
|
2801
|
+
var onChange = props.onChange,
|
|
2802
|
+
options = props.options,
|
|
2803
|
+
registry = props.registry;
|
|
2804
|
+
var BaseInputTemplate = utils.getTemplate("BaseInputTemplate", registry, options);
|
|
2805
|
+
var handleChange = React.useCallback(function (value) {
|
|
2806
|
+
return onChange(value || undefined);
|
|
2807
|
+
}, [onChange]);
|
|
2808
|
+
return /*#__PURE__*/React__default["default"].createElement(BaseInputTemplate, _extends({
|
|
2809
|
+
type: "date"
|
|
2810
|
+
}, props, {
|
|
2823
2811
|
onChange: handleChange
|
|
2824
|
-
});
|
|
2812
|
+
}));
|
|
2825
2813
|
}
|
|
2826
2814
|
|
|
2827
2815
|
/** The `DateTimeWidget` component uses the `BaseInputTemplate` changing the type to `datetime-local` and transforms
|
|
@@ -2830,19 +2818,19 @@
|
|
|
2830
2818
|
* @param props - The `WidgetProps` for this component
|
|
2831
2819
|
*/
|
|
2832
2820
|
function DateTimeWidget(props) {
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
type: "datetime-local",
|
|
2842
|
-
...props,
|
|
2821
|
+
var _onChange = props.onChange,
|
|
2822
|
+
value = props.value,
|
|
2823
|
+
options = props.options,
|
|
2824
|
+
registry = props.registry;
|
|
2825
|
+
var BaseInputTemplate = utils.getTemplate("BaseInputTemplate", registry, options);
|
|
2826
|
+
return /*#__PURE__*/React__default["default"].createElement(BaseInputTemplate, _extends({
|
|
2827
|
+
type: "datetime-local"
|
|
2828
|
+
}, props, {
|
|
2843
2829
|
value: utils.utcToLocal(value),
|
|
2844
|
-
onChange:
|
|
2845
|
-
|
|
2830
|
+
onChange: function onChange(value) {
|
|
2831
|
+
return _onChange(utils.localToUTC(value));
|
|
2832
|
+
}
|
|
2833
|
+
}));
|
|
2846
2834
|
}
|
|
2847
2835
|
|
|
2848
2836
|
/** The `EmailWidget` component uses the `BaseInputTemplate` changing the type to `email`.
|
|
@@ -2850,47 +2838,42 @@
|
|
|
2850
2838
|
* @param props - The `WidgetProps` for this component
|
|
2851
2839
|
*/
|
|
2852
2840
|
function EmailWidget(props) {
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
type: "email",
|
|
2860
|
-
...props
|
|
2861
|
-
});
|
|
2841
|
+
var options = props.options,
|
|
2842
|
+
registry = props.registry;
|
|
2843
|
+
var BaseInputTemplate = utils.getTemplate("BaseInputTemplate", registry, options);
|
|
2844
|
+
return /*#__PURE__*/React__default["default"].createElement(BaseInputTemplate, _extends({
|
|
2845
|
+
type: "email"
|
|
2846
|
+
}, props));
|
|
2862
2847
|
}
|
|
2863
2848
|
|
|
2864
2849
|
function addNameToDataURL(dataURL, name) {
|
|
2865
2850
|
if (dataURL === null) {
|
|
2866
2851
|
return null;
|
|
2867
2852
|
}
|
|
2868
|
-
return dataURL.replace(";base64",
|
|
2853
|
+
return dataURL.replace(";base64", ";name=" + encodeURIComponent(name) + ";base64");
|
|
2869
2854
|
}
|
|
2870
2855
|
function processFile(file) {
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
return new Promise((resolve, reject) => {
|
|
2877
|
-
const reader = new window.FileReader();
|
|
2856
|
+
var name = file.name,
|
|
2857
|
+
size = file.size,
|
|
2858
|
+
type = file.type;
|
|
2859
|
+
return new Promise(function (resolve, reject) {
|
|
2860
|
+
var reader = new window.FileReader();
|
|
2878
2861
|
reader.onerror = reject;
|
|
2879
|
-
reader.onload = event
|
|
2862
|
+
reader.onload = function (event) {
|
|
2880
2863
|
var _event$target;
|
|
2881
2864
|
if (typeof ((_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.result) === "string") {
|
|
2882
2865
|
resolve({
|
|
2883
2866
|
dataURL: addNameToDataURL(event.target.result, name),
|
|
2884
|
-
name,
|
|
2885
|
-
size,
|
|
2886
|
-
type
|
|
2867
|
+
name: name,
|
|
2868
|
+
size: size,
|
|
2869
|
+
type: type
|
|
2887
2870
|
});
|
|
2888
2871
|
} else {
|
|
2889
2872
|
resolve({
|
|
2890
2873
|
dataURL: null,
|
|
2891
|
-
name,
|
|
2892
|
-
size,
|
|
2893
|
-
type
|
|
2874
|
+
name: name,
|
|
2875
|
+
size: size,
|
|
2876
|
+
type: type
|
|
2894
2877
|
});
|
|
2895
2878
|
}
|
|
2896
2879
|
};
|
|
@@ -2901,31 +2884,28 @@
|
|
|
2901
2884
|
return Promise.all(Array.from(files).map(processFile));
|
|
2902
2885
|
}
|
|
2903
2886
|
function FilesInfo(_ref) {
|
|
2904
|
-
|
|
2905
|
-
filesInfo
|
|
2906
|
-
} = _ref;
|
|
2887
|
+
var filesInfo = _ref.filesInfo;
|
|
2907
2888
|
if (filesInfo.length === 0) {
|
|
2908
2889
|
return null;
|
|
2909
2890
|
}
|
|
2910
2891
|
return /*#__PURE__*/React__default["default"].createElement("ul", {
|
|
2911
2892
|
className: "file-info"
|
|
2912
|
-
}, filesInfo.map((fileInfo, key)
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
type
|
|
2917
|
-
} = fileInfo;
|
|
2893
|
+
}, filesInfo.map(function (fileInfo, key) {
|
|
2894
|
+
var name = fileInfo.name,
|
|
2895
|
+
size = fileInfo.size,
|
|
2896
|
+
type = fileInfo.type;
|
|
2918
2897
|
return /*#__PURE__*/React__default["default"].createElement("li", {
|
|
2919
2898
|
key: key
|
|
2920
2899
|
}, /*#__PURE__*/React__default["default"].createElement("strong", null, name), " (", type, ", ", size, " bytes)");
|
|
2921
2900
|
}));
|
|
2922
2901
|
}
|
|
2923
2902
|
function extractFileInfo(dataURLs) {
|
|
2924
|
-
return dataURLs.filter(
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2903
|
+
return dataURLs.filter(function (dataURL) {
|
|
2904
|
+
return typeof dataURL !== "undefined";
|
|
2905
|
+
}).map(function (dataURL) {
|
|
2906
|
+
var _dataURItoBlob = utils.dataURItoBlob(dataURL),
|
|
2907
|
+
blob = _dataURItoBlob.blob,
|
|
2908
|
+
name = _dataURItoBlob.name;
|
|
2929
2909
|
return {
|
|
2930
2910
|
name: name,
|
|
2931
2911
|
size: blob.size,
|
|
@@ -2938,25 +2918,30 @@
|
|
|
2938
2918
|
* It is typically used with a string property with data-url format.
|
|
2939
2919
|
*/
|
|
2940
2920
|
function FileWidget(_ref2) {
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
autofocus = false,
|
|
2949
|
-
options
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2921
|
+
var multiple = _ref2.multiple,
|
|
2922
|
+
id = _ref2.id,
|
|
2923
|
+
readonly = _ref2.readonly,
|
|
2924
|
+
disabled = _ref2.disabled,
|
|
2925
|
+
onChange = _ref2.onChange,
|
|
2926
|
+
value = _ref2.value,
|
|
2927
|
+
_ref2$autofocus = _ref2.autofocus,
|
|
2928
|
+
autofocus = _ref2$autofocus === void 0 ? false : _ref2$autofocus,
|
|
2929
|
+
options = _ref2.options;
|
|
2930
|
+
var extractedFilesInfo = React.useMemo(function () {
|
|
2931
|
+
return Array.isArray(value) ? extractFileInfo(value) : extractFileInfo([value]);
|
|
2932
|
+
}, [value]);
|
|
2933
|
+
var _useState = React.useState(extractedFilesInfo),
|
|
2934
|
+
filesInfo = _useState[0],
|
|
2935
|
+
setFilesInfo = _useState[1];
|
|
2936
|
+
var handleChange = React.useCallback(function (event) {
|
|
2954
2937
|
if (!event.target.files) {
|
|
2955
2938
|
return;
|
|
2956
2939
|
}
|
|
2957
|
-
processFiles(event.target.files).then(filesInfoEvent
|
|
2940
|
+
processFiles(event.target.files).then(function (filesInfoEvent) {
|
|
2958
2941
|
setFilesInfo(filesInfoEvent);
|
|
2959
|
-
|
|
2942
|
+
var newValue = filesInfoEvent.map(function (fileInfo) {
|
|
2943
|
+
return fileInfo.dataURL;
|
|
2944
|
+
});
|
|
2960
2945
|
if (multiple) {
|
|
2961
2946
|
onChange(newValue);
|
|
2962
2947
|
} else {
|
|
@@ -2985,10 +2970,8 @@
|
|
|
2985
2970
|
* @param props - The `WidgetProps` for this component
|
|
2986
2971
|
*/
|
|
2987
2972
|
function HiddenWidget(_ref) {
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
value
|
|
2991
|
-
} = _ref;
|
|
2973
|
+
var id = _ref.id,
|
|
2974
|
+
value = _ref.value;
|
|
2992
2975
|
return /*#__PURE__*/React__default["default"].createElement("input", {
|
|
2993
2976
|
type: "hidden",
|
|
2994
2977
|
id: id,
|
|
@@ -3002,15 +2985,12 @@
|
|
|
3002
2985
|
* @param props - The `WidgetProps` for this component
|
|
3003
2986
|
*/
|
|
3004
2987
|
function PasswordWidget(props) {
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
type: "password",
|
|
3012
|
-
...props
|
|
3013
|
-
});
|
|
2988
|
+
var options = props.options,
|
|
2989
|
+
registry = props.registry;
|
|
2990
|
+
var BaseInputTemplate = utils.getTemplate("BaseInputTemplate", registry, options);
|
|
2991
|
+
return /*#__PURE__*/React__default["default"].createElement(BaseInputTemplate, _extends({
|
|
2992
|
+
type: "password"
|
|
2993
|
+
}, props));
|
|
3014
2994
|
}
|
|
3015
2995
|
|
|
3016
2996
|
/** The `RadioWidget` is a widget for rendering a radio group.
|
|
@@ -3019,40 +2999,43 @@
|
|
|
3019
2999
|
* @param props - The `WidgetProps` for this component
|
|
3020
3000
|
*/
|
|
3021
3001
|
function RadioWidget(_ref) {
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
autofocus = false,
|
|
3029
|
-
onBlur,
|
|
3030
|
-
onFocus,
|
|
3031
|
-
onChange,
|
|
3032
|
-
id
|
|
3033
|
-
} = _ref;
|
|
3002
|
+
var options = _ref.options,
|
|
3003
|
+
value = _ref.value,
|
|
3004
|
+
required = _ref.required,
|
|
3005
|
+
disabled = _ref.disabled,
|
|
3006
|
+
readonly = _ref.readonly,
|
|
3007
|
+
_ref$autofocus = _ref.autofocus,
|
|
3008
|
+
autofocus = _ref$autofocus === void 0 ? false : _ref$autofocus,
|
|
3009
|
+
onBlur = _ref.onBlur,
|
|
3010
|
+
onFocus = _ref.onFocus,
|
|
3011
|
+
onChange = _ref.onChange,
|
|
3012
|
+
id = _ref.id;
|
|
3034
3013
|
// Generating a unique field name to identify this set of radio buttons
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
inline
|
|
3040
|
-
} = options;
|
|
3014
|
+
var name = Math.random().toString();
|
|
3015
|
+
var enumOptions = options.enumOptions,
|
|
3016
|
+
enumDisabled = options.enumDisabled,
|
|
3017
|
+
inline = options.inline;
|
|
3041
3018
|
// checked={checked} has been moved above name={name}, As mentioned in #349;
|
|
3042
3019
|
// this is a temporary fix for radio button rendering bug in React, facebook/react#7630.
|
|
3043
|
-
|
|
3044
|
-
|
|
3020
|
+
var handleBlur = React.useCallback(function (event) {
|
|
3021
|
+
return onBlur(id, event.target.value);
|
|
3022
|
+
}, [onBlur, id]);
|
|
3023
|
+
var handleFocus = React.useCallback(function (event) {
|
|
3024
|
+
return onFocus(id, event.target.value);
|
|
3025
|
+
}, [onFocus, id]);
|
|
3045
3026
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
3046
3027
|
className: "field-radio-group",
|
|
3047
3028
|
id: id
|
|
3048
|
-
}, Array.isArray(enumOptions) && enumOptions.map((option, i)
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3029
|
+
}, Array.isArray(enumOptions) && enumOptions.map(function (option, i) {
|
|
3030
|
+
var checked = option.value === value;
|
|
3031
|
+
var itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) != -1;
|
|
3032
|
+
var disabledCls = disabled || itemDisabled || readonly ? "disabled" : "";
|
|
3033
|
+
var handleChange = function handleChange() {
|
|
3034
|
+
return onChange(option.value);
|
|
3035
|
+
};
|
|
3036
|
+
var radio = /*#__PURE__*/React__default["default"].createElement("span", null, /*#__PURE__*/React__default["default"].createElement("input", {
|
|
3054
3037
|
type: "radio",
|
|
3055
|
-
id:
|
|
3038
|
+
id: id + "-" + option.value,
|
|
3056
3039
|
checked: checked,
|
|
3057
3040
|
name: name,
|
|
3058
3041
|
required: required,
|
|
@@ -3065,10 +3048,10 @@
|
|
|
3065
3048
|
}), /*#__PURE__*/React__default["default"].createElement("span", null, option.label));
|
|
3066
3049
|
return inline ? /*#__PURE__*/React__default["default"].createElement("label", {
|
|
3067
3050
|
key: option.value,
|
|
3068
|
-
className:
|
|
3051
|
+
className: "radio-inline " + disabledCls
|
|
3069
3052
|
}, radio) : /*#__PURE__*/React__default["default"].createElement("div", {
|
|
3070
3053
|
key: option.value,
|
|
3071
|
-
className:
|
|
3054
|
+
className: "radio " + disabledCls
|
|
3072
3055
|
}, /*#__PURE__*/React__default["default"].createElement("label", null, radio));
|
|
3073
3056
|
}));
|
|
3074
3057
|
}
|
|
@@ -3079,27 +3062,24 @@
|
|
|
3079
3062
|
* @param props - The `WidgetProps` for this component
|
|
3080
3063
|
*/
|
|
3081
3064
|
function RangeWidget(props) {
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
registry: {
|
|
3085
|
-
templates: {
|
|
3086
|
-
BaseInputTemplate
|
|
3087
|
-
}
|
|
3088
|
-
}
|
|
3089
|
-
} = props;
|
|
3065
|
+
var value = props.value,
|
|
3066
|
+
BaseInputTemplate = props.registry.templates.BaseInputTemplate;
|
|
3090
3067
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
3091
3068
|
className: "field-range-wrapper"
|
|
3092
|
-
}, /*#__PURE__*/React__default["default"].createElement(BaseInputTemplate, {
|
|
3093
|
-
type: "range"
|
|
3094
|
-
|
|
3095
|
-
}), /*#__PURE__*/React__default["default"].createElement("span", {
|
|
3069
|
+
}, /*#__PURE__*/React__default["default"].createElement(BaseInputTemplate, _extends({
|
|
3070
|
+
type: "range"
|
|
3071
|
+
}, props)), /*#__PURE__*/React__default["default"].createElement("span", {
|
|
3096
3072
|
className: "range-view"
|
|
3097
3073
|
}, value));
|
|
3098
3074
|
}
|
|
3099
3075
|
|
|
3100
3076
|
function getValue(event, multiple) {
|
|
3101
3077
|
if (multiple) {
|
|
3102
|
-
return Array.from(event.target.options).slice().filter(
|
|
3078
|
+
return Array.from(event.target.options).slice().filter(function (o) {
|
|
3079
|
+
return o.selected;
|
|
3080
|
+
}).map(function (o) {
|
|
3081
|
+
return o.value;
|
|
3082
|
+
});
|
|
3103
3083
|
}
|
|
3104
3084
|
return event.target.value;
|
|
3105
3085
|
}
|
|
@@ -3109,36 +3089,34 @@
|
|
|
3109
3089
|
* @param props - The `WidgetProps` for this component
|
|
3110
3090
|
*/
|
|
3111
3091
|
function SelectWidget(_ref) {
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
multiple = false,
|
|
3121
|
-
autofocus =
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
const handleFocus = React.useCallback(event => {
|
|
3133
|
-
const newValue = getValue(event, multiple);
|
|
3092
|
+
var schema = _ref.schema,
|
|
3093
|
+
id = _ref.id,
|
|
3094
|
+
options = _ref.options,
|
|
3095
|
+
value = _ref.value,
|
|
3096
|
+
required = _ref.required,
|
|
3097
|
+
disabled = _ref.disabled,
|
|
3098
|
+
readonly = _ref.readonly,
|
|
3099
|
+
_ref$multiple = _ref.multiple,
|
|
3100
|
+
multiple = _ref$multiple === void 0 ? false : _ref$multiple,
|
|
3101
|
+
_ref$autofocus = _ref.autofocus,
|
|
3102
|
+
autofocus = _ref$autofocus === void 0 ? false : _ref$autofocus,
|
|
3103
|
+
onChange = _ref.onChange,
|
|
3104
|
+
onBlur = _ref.onBlur,
|
|
3105
|
+
onFocus = _ref.onFocus,
|
|
3106
|
+
placeholder = _ref.placeholder;
|
|
3107
|
+
var enumOptions = options.enumOptions,
|
|
3108
|
+
enumDisabled = options.enumDisabled;
|
|
3109
|
+
var emptyValue = multiple ? [] : "";
|
|
3110
|
+
var handleFocus = React.useCallback(function (event) {
|
|
3111
|
+
var newValue = getValue(event, multiple);
|
|
3134
3112
|
return onFocus(id, utils.processSelectValue(schema, newValue, options));
|
|
3135
3113
|
}, [onFocus, id, schema, multiple, options]);
|
|
3136
|
-
|
|
3137
|
-
|
|
3114
|
+
var handleBlur = React.useCallback(function (event) {
|
|
3115
|
+
var newValue = getValue(event, multiple);
|
|
3138
3116
|
return onBlur(id, utils.processSelectValue(schema, newValue, options));
|
|
3139
3117
|
}, [onBlur, id, schema, multiple, options]);
|
|
3140
|
-
|
|
3141
|
-
|
|
3118
|
+
var handleChange = React.useCallback(function (event) {
|
|
3119
|
+
var newValue = getValue(event, multiple);
|
|
3142
3120
|
return onChange(utils.processSelectValue(schema, newValue, options));
|
|
3143
3121
|
}, [onChange, schema, multiple, options]);
|
|
3144
3122
|
return /*#__PURE__*/React__default["default"].createElement("select", {
|
|
@@ -3153,14 +3131,12 @@
|
|
|
3153
3131
|
onBlur: handleBlur,
|
|
3154
3132
|
onFocus: handleFocus,
|
|
3155
3133
|
onChange: handleChange
|
|
3156
|
-
}, !multiple && schema
|
|
3134
|
+
}, !multiple && schema["default"] === undefined && /*#__PURE__*/React__default["default"].createElement("option", {
|
|
3157
3135
|
value: ""
|
|
3158
|
-
}, placeholder), Array.isArray(enumOptions) && enumOptions.map((_ref2, i)
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
} = _ref2;
|
|
3163
|
-
const disabled = enumDisabled && enumDisabled.indexOf(value) != -1;
|
|
3136
|
+
}, placeholder), Array.isArray(enumOptions) && enumOptions.map(function (_ref2, i) {
|
|
3137
|
+
var value = _ref2.value,
|
|
3138
|
+
label = _ref2.label;
|
|
3139
|
+
var disabled = enumDisabled && enumDisabled.indexOf(value) != -1;
|
|
3164
3140
|
return /*#__PURE__*/React__default["default"].createElement("option", {
|
|
3165
3141
|
key: i,
|
|
3166
3142
|
value: value,
|
|
@@ -3174,41 +3150,29 @@
|
|
|
3174
3150
|
* @param props - The `WidgetProps` for this component
|
|
3175
3151
|
*/
|
|
3176
3152
|
function TextareaWidget(_ref) {
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
options = {},
|
|
3180
|
-
placeholder,
|
|
3181
|
-
value,
|
|
3182
|
-
required,
|
|
3183
|
-
disabled,
|
|
3184
|
-
readonly,
|
|
3185
|
-
autofocus =
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
target: {
|
|
3193
|
-
value
|
|
3194
|
-
}
|
|
3195
|
-
} = _ref2;
|
|
3153
|
+
var id = _ref.id,
|
|
3154
|
+
_ref$options = _ref.options,
|
|
3155
|
+
options = _ref$options === void 0 ? {} : _ref$options,
|
|
3156
|
+
placeholder = _ref.placeholder,
|
|
3157
|
+
value = _ref.value,
|
|
3158
|
+
required = _ref.required,
|
|
3159
|
+
disabled = _ref.disabled,
|
|
3160
|
+
readonly = _ref.readonly,
|
|
3161
|
+
_ref$autofocus = _ref.autofocus,
|
|
3162
|
+
autofocus = _ref$autofocus === void 0 ? false : _ref$autofocus,
|
|
3163
|
+
onChange = _ref.onChange,
|
|
3164
|
+
onBlur = _ref.onBlur,
|
|
3165
|
+
onFocus = _ref.onFocus;
|
|
3166
|
+
var handleChange = React.useCallback(function (_ref2) {
|
|
3167
|
+
var value = _ref2.target.value;
|
|
3196
3168
|
return onChange(value === "" ? options.emptyValue : value);
|
|
3197
3169
|
}, [onChange, options.emptyValue]);
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
target: {
|
|
3201
|
-
value
|
|
3202
|
-
}
|
|
3203
|
-
} = _ref3;
|
|
3170
|
+
var handleBlur = React.useCallback(function (_ref3) {
|
|
3171
|
+
var value = _ref3.target.value;
|
|
3204
3172
|
return onBlur(id, value);
|
|
3205
3173
|
}, [onBlur, id]);
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
target: {
|
|
3209
|
-
value
|
|
3210
|
-
}
|
|
3211
|
-
} = _ref4;
|
|
3174
|
+
var handleFocus = React.useCallback(function (_ref4) {
|
|
3175
|
+
var value = _ref4.target.value;
|
|
3212
3176
|
return onFocus(id, value);
|
|
3213
3177
|
}, [id, onFocus]);
|
|
3214
3178
|
return /*#__PURE__*/React__default["default"].createElement("textarea", {
|
|
@@ -3237,14 +3201,10 @@
|
|
|
3237
3201
|
* @param props - The `WidgetProps` for this component
|
|
3238
3202
|
*/
|
|
3239
3203
|
function TextWidget(props) {
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
}
|
|
3244
|
-
const BaseInputTemplate = utils.getTemplate("BaseInputTemplate", registry, options);
|
|
3245
|
-
return /*#__PURE__*/React__default["default"].createElement(BaseInputTemplate, {
|
|
3246
|
-
...props
|
|
3247
|
-
});
|
|
3204
|
+
var options = props.options,
|
|
3205
|
+
registry = props.registry;
|
|
3206
|
+
var BaseInputTemplate = utils.getTemplate("BaseInputTemplate", registry, options);
|
|
3207
|
+
return /*#__PURE__*/React__default["default"].createElement(BaseInputTemplate, _extends({}, props));
|
|
3248
3208
|
}
|
|
3249
3209
|
|
|
3250
3210
|
/** The `URLWidget` component uses the `BaseInputTemplate` changing the type to `url`.
|
|
@@ -3252,15 +3212,12 @@
|
|
|
3252
3212
|
* @param props - The `WidgetProps` for this component
|
|
3253
3213
|
*/
|
|
3254
3214
|
function URLWidget(props) {
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
type: "url",
|
|
3262
|
-
...props
|
|
3263
|
-
});
|
|
3215
|
+
var options = props.options,
|
|
3216
|
+
registry = props.registry;
|
|
3217
|
+
var BaseInputTemplate = utils.getTemplate("BaseInputTemplate", registry, options);
|
|
3218
|
+
return /*#__PURE__*/React__default["default"].createElement(BaseInputTemplate, _extends({
|
|
3219
|
+
type: "url"
|
|
3220
|
+
}, props));
|
|
3264
3221
|
}
|
|
3265
3222
|
|
|
3266
3223
|
/** The `UpDownWidget` component uses the `BaseInputTemplate` changing the type to `number`.
|
|
@@ -3268,37 +3225,34 @@
|
|
|
3268
3225
|
* @param props - The `WidgetProps` for this component
|
|
3269
3226
|
*/
|
|
3270
3227
|
function UpDownWidget(props) {
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
type: "number",
|
|
3278
|
-
...props
|
|
3279
|
-
});
|
|
3228
|
+
var options = props.options,
|
|
3229
|
+
registry = props.registry;
|
|
3230
|
+
var BaseInputTemplate = utils.getTemplate("BaseInputTemplate", registry, options);
|
|
3231
|
+
return /*#__PURE__*/React__default["default"].createElement(BaseInputTemplate, _extends({
|
|
3232
|
+
type: "number"
|
|
3233
|
+
}, props));
|
|
3280
3234
|
}
|
|
3281
3235
|
|
|
3282
3236
|
function widgets() {
|
|
3283
3237
|
return {
|
|
3284
|
-
PasswordWidget,
|
|
3285
|
-
RadioWidget,
|
|
3286
|
-
UpDownWidget,
|
|
3287
|
-
RangeWidget,
|
|
3288
|
-
SelectWidget,
|
|
3289
|
-
TextWidget,
|
|
3290
|
-
DateWidget,
|
|
3291
|
-
DateTimeWidget,
|
|
3292
|
-
AltDateWidget,
|
|
3293
|
-
AltDateTimeWidget,
|
|
3294
|
-
EmailWidget,
|
|
3295
|
-
URLWidget,
|
|
3296
|
-
TextareaWidget,
|
|
3297
|
-
HiddenWidget,
|
|
3298
|
-
ColorWidget,
|
|
3299
|
-
FileWidget,
|
|
3300
|
-
CheckboxWidget,
|
|
3301
|
-
CheckboxesWidget
|
|
3238
|
+
PasswordWidget: PasswordWidget,
|
|
3239
|
+
RadioWidget: RadioWidget,
|
|
3240
|
+
UpDownWidget: UpDownWidget,
|
|
3241
|
+
RangeWidget: RangeWidget,
|
|
3242
|
+
SelectWidget: SelectWidget,
|
|
3243
|
+
TextWidget: TextWidget,
|
|
3244
|
+
DateWidget: DateWidget,
|
|
3245
|
+
DateTimeWidget: DateTimeWidget,
|
|
3246
|
+
AltDateWidget: AltDateWidget,
|
|
3247
|
+
AltDateTimeWidget: AltDateTimeWidget,
|
|
3248
|
+
EmailWidget: EmailWidget,
|
|
3249
|
+
URLWidget: URLWidget,
|
|
3250
|
+
TextareaWidget: TextareaWidget,
|
|
3251
|
+
HiddenWidget: HiddenWidget,
|
|
3252
|
+
ColorWidget: ColorWidget,
|
|
3253
|
+
FileWidget: FileWidget,
|
|
3254
|
+
CheckboxWidget: CheckboxWidget,
|
|
3255
|
+
CheckboxesWidget: CheckboxesWidget
|
|
3302
3256
|
};
|
|
3303
3257
|
}
|
|
3304
3258
|
|
|
@@ -3317,7 +3271,8 @@
|
|
|
3317
3271
|
}
|
|
3318
3272
|
|
|
3319
3273
|
/** The `Form` component renders the outer form and all the fields defined in the `schema` */
|
|
3320
|
-
|
|
3274
|
+
var Form = /*#__PURE__*/function (_Component) {
|
|
3275
|
+
_inheritsLoose(Form, _Component);
|
|
3321
3276
|
/** The ref used to hold the `form` element, this needs to be `any` because `tagName` or `_internalFormWrapper` can
|
|
3322
3277
|
* provide any possible type here
|
|
3323
3278
|
*/
|
|
@@ -3328,32 +3283,37 @@
|
|
|
3328
3283
|
*
|
|
3329
3284
|
* @param props - The initial props for the `Form`
|
|
3330
3285
|
*/
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3286
|
+
function Form(props) {
|
|
3287
|
+
var _this;
|
|
3288
|
+
_this = _Component.call(this, props) || this;
|
|
3289
|
+
_this.formElement = void 0;
|
|
3290
|
+
_this.getUsedFormData = function (formData, fields) {
|
|
3335
3291
|
// For the case of a single input form
|
|
3336
3292
|
if (fields.length === 0 && typeof formData !== "object") {
|
|
3337
3293
|
return formData;
|
|
3338
3294
|
}
|
|
3339
3295
|
// _pick has incorrect type definition, it works with string[][], because lodash/hasIn supports it
|
|
3340
|
-
|
|
3296
|
+
var data = _pick__default["default"](formData, fields);
|
|
3341
3297
|
if (Array.isArray(formData)) {
|
|
3342
|
-
return Object.keys(data).map(
|
|
3298
|
+
return Object.keys(data).map(function (key) {
|
|
3299
|
+
return data[key];
|
|
3300
|
+
});
|
|
3343
3301
|
}
|
|
3344
3302
|
return data;
|
|
3345
3303
|
};
|
|
3346
|
-
|
|
3347
|
-
|
|
3304
|
+
_this.getFieldNames = function (pathSchema, formData) {
|
|
3305
|
+
var getAllPaths = function getAllPaths(_obj, acc, paths) {
|
|
3348
3306
|
if (acc === void 0) {
|
|
3349
3307
|
acc = [];
|
|
3350
3308
|
}
|
|
3351
3309
|
if (paths === void 0) {
|
|
3352
3310
|
paths = [[]];
|
|
3353
3311
|
}
|
|
3354
|
-
Object.keys(_obj).forEach(key
|
|
3312
|
+
Object.keys(_obj).forEach(function (key) {
|
|
3355
3313
|
if (typeof _obj[key] === "object") {
|
|
3356
|
-
|
|
3314
|
+
var newPaths = paths.map(function (path) {
|
|
3315
|
+
return [].concat(path, [key]);
|
|
3316
|
+
});
|
|
3357
3317
|
// If an object is marked with additionalProperties, all its keys are valid
|
|
3358
3318
|
if (_obj[key][utils.RJSF_ADDITONAL_PROPERTIES_FLAG] && _obj[key][utils.NAME_KEY] !== "") {
|
|
3359
3319
|
acc.push(_obj[key][utils.NAME_KEY]);
|
|
@@ -3361,8 +3321,8 @@
|
|
|
3361
3321
|
getAllPaths(_obj[key], acc, newPaths);
|
|
3362
3322
|
}
|
|
3363
3323
|
} else if (key === utils.NAME_KEY && _obj[key] !== "") {
|
|
3364
|
-
paths.forEach(path
|
|
3365
|
-
|
|
3324
|
+
paths.forEach(function (path) {
|
|
3325
|
+
var formValue = get__default["default"](formData, path);
|
|
3366
3326
|
// adds path to fieldNames if it points to a value
|
|
3367
3327
|
// or an empty object/array
|
|
3368
3328
|
if (typeof formValue !== "object" || _isEmpty__default["default"](formValue)) {
|
|
@@ -3375,128 +3335,116 @@
|
|
|
3375
3335
|
};
|
|
3376
3336
|
return getAllPaths(pathSchema);
|
|
3377
3337
|
};
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
extraErrors,
|
|
3381
|
-
omitExtraData,
|
|
3382
|
-
liveOmit,
|
|
3383
|
-
noValidate,
|
|
3384
|
-
liveValidate,
|
|
3385
|
-
onChange
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
schema
|
|
3390
|
-
} = this.state;
|
|
3338
|
+
_this.onChange = function (formData, newErrorSchema, id) {
|
|
3339
|
+
var _this$props = _this.props,
|
|
3340
|
+
extraErrors = _this$props.extraErrors,
|
|
3341
|
+
omitExtraData = _this$props.omitExtraData,
|
|
3342
|
+
liveOmit = _this$props.liveOmit,
|
|
3343
|
+
noValidate = _this$props.noValidate,
|
|
3344
|
+
liveValidate = _this$props.liveValidate,
|
|
3345
|
+
onChange = _this$props.onChange;
|
|
3346
|
+
var _this$state = _this.state,
|
|
3347
|
+
schemaUtils = _this$state.schemaUtils,
|
|
3348
|
+
schema = _this$state.schema;
|
|
3391
3349
|
if (utils.isObject(formData) || Array.isArray(formData)) {
|
|
3392
|
-
|
|
3350
|
+
var newState = _this.getStateFromProps(_this.props, formData);
|
|
3393
3351
|
formData = newState.formData;
|
|
3394
3352
|
}
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
formData,
|
|
3398
|
-
schema
|
|
3353
|
+
var mustValidate = !noValidate && liveValidate;
|
|
3354
|
+
var state = {
|
|
3355
|
+
formData: formData,
|
|
3356
|
+
schema: schema
|
|
3399
3357
|
};
|
|
3400
|
-
|
|
3358
|
+
var newFormData = formData;
|
|
3401
3359
|
if (omitExtraData === true && liveOmit === true) {
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
newFormData =
|
|
3360
|
+
var retrievedSchema = schemaUtils.retrieveSchema(schema, formData);
|
|
3361
|
+
var pathSchema = schemaUtils.toPathSchema(retrievedSchema, "", formData);
|
|
3362
|
+
var fieldNames = _this.getFieldNames(pathSchema, formData);
|
|
3363
|
+
newFormData = _this.getUsedFormData(formData, fieldNames);
|
|
3406
3364
|
state = {
|
|
3407
3365
|
formData: newFormData
|
|
3408
3366
|
};
|
|
3409
3367
|
}
|
|
3410
3368
|
if (mustValidate) {
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3369
|
+
var schemaValidation = _this.validate(newFormData);
|
|
3370
|
+
var errors = schemaValidation.errors;
|
|
3371
|
+
var errorSchema = schemaValidation.errorSchema;
|
|
3372
|
+
var schemaValidationErrors = errors;
|
|
3373
|
+
var schemaValidationErrorSchema = errorSchema;
|
|
3416
3374
|
if (extraErrors) {
|
|
3417
|
-
|
|
3375
|
+
var merged = schemaUtils.mergeValidationData(schemaValidation, extraErrors);
|
|
3418
3376
|
errorSchema = merged.errorSchema;
|
|
3419
3377
|
errors = merged.errors;
|
|
3420
3378
|
}
|
|
3421
3379
|
state = {
|
|
3422
3380
|
formData: newFormData,
|
|
3423
|
-
errors,
|
|
3424
|
-
errorSchema,
|
|
3425
|
-
schemaValidationErrors,
|
|
3426
|
-
schemaValidationErrorSchema
|
|
3381
|
+
errors: errors,
|
|
3382
|
+
errorSchema: errorSchema,
|
|
3383
|
+
schemaValidationErrors: schemaValidationErrors,
|
|
3384
|
+
schemaValidationErrorSchema: schemaValidationErrorSchema
|
|
3427
3385
|
};
|
|
3428
3386
|
} else if (!noValidate && newErrorSchema) {
|
|
3429
|
-
|
|
3387
|
+
var _errorSchema = extraErrors ? utils.mergeObjects(newErrorSchema, extraErrors, "preventDuplicates") : newErrorSchema;
|
|
3430
3388
|
state = {
|
|
3431
3389
|
formData: newFormData,
|
|
3432
|
-
errorSchema:
|
|
3433
|
-
errors: schemaUtils.getValidator().toErrorList(
|
|
3390
|
+
errorSchema: _errorSchema,
|
|
3391
|
+
errors: schemaUtils.getValidator().toErrorList(_errorSchema)
|
|
3434
3392
|
};
|
|
3435
3393
|
}
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
}, id));
|
|
3394
|
+
_this.setState(state, function () {
|
|
3395
|
+
return onChange && onChange(_extends({}, _this.state, state), id);
|
|
3396
|
+
});
|
|
3440
3397
|
};
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
onBlur
|
|
3444
|
-
} = this.props;
|
|
3398
|
+
_this.onBlur = function (id, data) {
|
|
3399
|
+
var onBlur = _this.props.onBlur;
|
|
3445
3400
|
if (onBlur) {
|
|
3446
3401
|
onBlur(id, data);
|
|
3447
3402
|
}
|
|
3448
3403
|
};
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
onFocus
|
|
3452
|
-
} = this.props;
|
|
3404
|
+
_this.onFocus = function (id, data) {
|
|
3405
|
+
var onFocus = _this.props.onFocus;
|
|
3453
3406
|
if (onFocus) {
|
|
3454
3407
|
onFocus(id, data);
|
|
3455
3408
|
}
|
|
3456
3409
|
};
|
|
3457
|
-
|
|
3410
|
+
_this.onSubmit = function (event) {
|
|
3458
3411
|
event.preventDefault();
|
|
3459
3412
|
if (event.target !== event.currentTarget) {
|
|
3460
3413
|
return;
|
|
3461
3414
|
}
|
|
3462
3415
|
event.persist();
|
|
3463
|
-
|
|
3464
|
-
omitExtraData,
|
|
3465
|
-
extraErrors,
|
|
3466
|
-
noValidate,
|
|
3467
|
-
onSubmit
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
const {
|
|
3473
|
-
schema,
|
|
3474
|
-
schemaUtils
|
|
3475
|
-
} = this.state;
|
|
3416
|
+
var _this$props2 = _this.props,
|
|
3417
|
+
omitExtraData = _this$props2.omitExtraData,
|
|
3418
|
+
extraErrors = _this$props2.extraErrors,
|
|
3419
|
+
noValidate = _this$props2.noValidate,
|
|
3420
|
+
onSubmit = _this$props2.onSubmit;
|
|
3421
|
+
var newFormData = _this.state.formData;
|
|
3422
|
+
var _this$state2 = _this.state,
|
|
3423
|
+
schema = _this$state2.schema,
|
|
3424
|
+
schemaUtils = _this$state2.schemaUtils;
|
|
3476
3425
|
if (omitExtraData === true) {
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
newFormData =
|
|
3426
|
+
var retrievedSchema = schemaUtils.retrieveSchema(schema, newFormData);
|
|
3427
|
+
var pathSchema = schemaUtils.toPathSchema(retrievedSchema, "", newFormData);
|
|
3428
|
+
var fieldNames = _this.getFieldNames(pathSchema, newFormData);
|
|
3429
|
+
newFormData = _this.getUsedFormData(newFormData, fieldNames);
|
|
3481
3430
|
}
|
|
3482
|
-
if (noValidate ||
|
|
3431
|
+
if (noValidate || _this.validateForm()) {
|
|
3483
3432
|
// There are no errors generated through schema validation.
|
|
3484
3433
|
// Check for user provided errors and update state accordingly.
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3434
|
+
var errorSchema = extraErrors || {};
|
|
3435
|
+
var errors = extraErrors ? schemaUtils.getValidator().toErrorList(extraErrors) : [];
|
|
3436
|
+
_this.setState({
|
|
3488
3437
|
formData: newFormData,
|
|
3489
|
-
errors,
|
|
3490
|
-
errorSchema,
|
|
3438
|
+
errors: errors,
|
|
3439
|
+
errorSchema: errorSchema,
|
|
3491
3440
|
schemaValidationErrors: [],
|
|
3492
3441
|
schemaValidationErrorSchema: {}
|
|
3493
|
-
}, ()
|
|
3442
|
+
}, function () {
|
|
3494
3443
|
if (onSubmit) {
|
|
3495
|
-
onSubmit({
|
|
3496
|
-
...this.state,
|
|
3444
|
+
onSubmit(_extends({}, _this.state, {
|
|
3497
3445
|
formData: newFormData,
|
|
3498
3446
|
status: "submitted"
|
|
3499
|
-
}, event);
|
|
3447
|
+
}), event);
|
|
3500
3448
|
}
|
|
3501
3449
|
});
|
|
3502
3450
|
}
|
|
@@ -3504,11 +3452,12 @@
|
|
|
3504
3452
|
if (!props.validator) {
|
|
3505
3453
|
throw new Error("A validator is required for Form functionality to work");
|
|
3506
3454
|
}
|
|
3507
|
-
|
|
3508
|
-
if (
|
|
3509
|
-
|
|
3455
|
+
_this.state = _this.getStateFromProps(props, props.formData);
|
|
3456
|
+
if (_this.props.onChange && !utils.deepEquals(_this.state.formData, _this.props.formData)) {
|
|
3457
|
+
_this.props.onChange(_this.state);
|
|
3510
3458
|
}
|
|
3511
|
-
|
|
3459
|
+
_this.formElement = /*#__PURE__*/React__default["default"].createRef();
|
|
3460
|
+
return _this;
|
|
3512
3461
|
}
|
|
3513
3462
|
/** React lifecycle method that gets called before new props are provided, updates the state based on new props. It
|
|
3514
3463
|
* will also call the`onChange` handler if the `formData` is modified to add missing default values as part of the
|
|
@@ -3516,8 +3465,9 @@
|
|
|
3516
3465
|
*
|
|
3517
3466
|
* @param nextProps - The new set of props about to be applied to the `Form`
|
|
3518
3467
|
*/
|
|
3519
|
-
|
|
3520
|
-
|
|
3468
|
+
var _proto = Form.prototype;
|
|
3469
|
+
_proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
|
|
3470
|
+
var nextState = this.getStateFromProps(nextProps, nextProps.formData);
|
|
3521
3471
|
if (!utils.deepEquals(nextState.formData, nextProps.formData) && !utils.deepEquals(nextState.formData, this.state.formData) && nextProps.onChange) {
|
|
3522
3472
|
nextProps.onChange(nextState);
|
|
3523
3473
|
}
|
|
@@ -3530,22 +3480,22 @@
|
|
|
3530
3480
|
* @param props - The props passed to the `Form`
|
|
3531
3481
|
* @param inputFormData - The new or current data for the `Form`
|
|
3532
3482
|
* @returns - The new state for the `Form`
|
|
3533
|
-
|
|
3534
|
-
getStateFromProps(props, inputFormData) {
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3483
|
+
*/;
|
|
3484
|
+
_proto.getStateFromProps = function getStateFromProps(props, inputFormData) {
|
|
3485
|
+
var state = this.state || {};
|
|
3486
|
+
var schema = "schema" in props ? props.schema : this.props.schema;
|
|
3487
|
+
var uiSchema = ("uiSchema" in props ? props.uiSchema : this.props.uiSchema) || {};
|
|
3488
|
+
var edit = typeof inputFormData !== "undefined";
|
|
3489
|
+
var liveValidate = "liveValidate" in props ? props.liveValidate : this.props.liveValidate;
|
|
3490
|
+
var mustValidate = edit && !props.noValidate && liveValidate;
|
|
3491
|
+
var rootSchema = schema;
|
|
3492
|
+
var schemaUtils = state.schemaUtils;
|
|
3543
3493
|
if (!schemaUtils || schemaUtils.doesSchemaUtilsDiffer(props.validator, rootSchema)) {
|
|
3544
3494
|
schemaUtils = utils.createSchemaUtils(props.validator, rootSchema);
|
|
3545
3495
|
}
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3496
|
+
var formData = schemaUtils.getDefaultFormState(schema, inputFormData);
|
|
3497
|
+
var retrievedSchema = schemaUtils.retrieveSchema(schema, formData);
|
|
3498
|
+
var getCurrentErrors = function getCurrentErrors() {
|
|
3549
3499
|
if (props.noValidate) {
|
|
3550
3500
|
return {
|
|
3551
3501
|
errors: [],
|
|
@@ -3562,41 +3512,41 @@
|
|
|
3562
3512
|
errorSchema: state.errorSchema || {}
|
|
3563
3513
|
};
|
|
3564
3514
|
};
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3515
|
+
var errors;
|
|
3516
|
+
var errorSchema;
|
|
3517
|
+
var schemaValidationErrors = state.schemaValidationErrors;
|
|
3518
|
+
var schemaValidationErrorSchema = state.schemaValidationErrorSchema;
|
|
3569
3519
|
if (mustValidate) {
|
|
3570
|
-
|
|
3520
|
+
var schemaValidation = this.validate(formData, schema, schemaUtils);
|
|
3571
3521
|
errors = schemaValidation.errors;
|
|
3572
3522
|
errorSchema = schemaValidation.errorSchema;
|
|
3573
3523
|
schemaValidationErrors = errors;
|
|
3574
3524
|
schemaValidationErrorSchema = errorSchema;
|
|
3575
3525
|
} else {
|
|
3576
|
-
|
|
3526
|
+
var currentErrors = getCurrentErrors();
|
|
3577
3527
|
errors = currentErrors.errors;
|
|
3578
3528
|
errorSchema = currentErrors.errorSchema;
|
|
3579
3529
|
}
|
|
3580
3530
|
if (props.extraErrors) {
|
|
3581
|
-
|
|
3582
|
-
errorSchema,
|
|
3583
|
-
errors
|
|
3531
|
+
var merged = schemaUtils.mergeValidationData({
|
|
3532
|
+
errorSchema: errorSchema,
|
|
3533
|
+
errors: errors
|
|
3584
3534
|
}, props.extraErrors);
|
|
3585
3535
|
errorSchema = merged.errorSchema;
|
|
3586
3536
|
errors = merged.errors;
|
|
3587
3537
|
}
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
schemaUtils,
|
|
3591
|
-
schema,
|
|
3592
|
-
uiSchema,
|
|
3593
|
-
idSchema,
|
|
3594
|
-
formData,
|
|
3595
|
-
edit,
|
|
3596
|
-
errors,
|
|
3597
|
-
errorSchema,
|
|
3598
|
-
schemaValidationErrors,
|
|
3599
|
-
schemaValidationErrorSchema
|
|
3538
|
+
var idSchema = schemaUtils.toIdSchema(retrievedSchema, uiSchema["ui:rootFieldId"], formData, props.idPrefix, props.idSeparator);
|
|
3539
|
+
var nextState = {
|
|
3540
|
+
schemaUtils: schemaUtils,
|
|
3541
|
+
schema: schema,
|
|
3542
|
+
uiSchema: uiSchema,
|
|
3543
|
+
idSchema: idSchema,
|
|
3544
|
+
formData: formData,
|
|
3545
|
+
edit: edit,
|
|
3546
|
+
errors: errors,
|
|
3547
|
+
errorSchema: errorSchema,
|
|
3548
|
+
schemaValidationErrors: schemaValidationErrors,
|
|
3549
|
+
schemaValidationErrorSchema: schemaValidationErrorSchema
|
|
3600
3550
|
};
|
|
3601
3551
|
return nextState;
|
|
3602
3552
|
}
|
|
@@ -3605,8 +3555,8 @@
|
|
|
3605
3555
|
* @param nextProps - The next version of the props
|
|
3606
3556
|
* @param nextState - The next version of the state
|
|
3607
3557
|
* @returns - True if the component should be updated, false otherwise
|
|
3608
|
-
|
|
3609
|
-
shouldComponentUpdate(nextProps, nextState) {
|
|
3558
|
+
*/;
|
|
3559
|
+
_proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
|
|
3610
3560
|
return utils.shouldRender(this, nextProps, nextState);
|
|
3611
3561
|
}
|
|
3612
3562
|
/** Validates the `formData` against the `schema` using the `altSchemaUtils` (if provided otherwise it uses the
|
|
@@ -3615,32 +3565,28 @@
|
|
|
3615
3565
|
* @param formData - The new form data to validate
|
|
3616
3566
|
* @param schema - The schema used to validate against
|
|
3617
3567
|
* @param altSchemaUtils - The alternate schemaUtils to use for validation
|
|
3618
|
-
|
|
3619
|
-
validate(formData, schema, altSchemaUtils) {
|
|
3568
|
+
*/;
|
|
3569
|
+
_proto.validate = function validate(formData, schema, altSchemaUtils) {
|
|
3620
3570
|
if (schema === void 0) {
|
|
3621
3571
|
schema = this.props.schema;
|
|
3622
3572
|
}
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
customValidate,
|
|
3626
|
-
transformErrors
|
|
3627
|
-
|
|
3628
|
-
const resolvedSchema = schemaUtils.retrieveSchema(schema, formData);
|
|
3573
|
+
var schemaUtils = altSchemaUtils ? altSchemaUtils : this.state.schemaUtils;
|
|
3574
|
+
var _this$props3 = this.props,
|
|
3575
|
+
customValidate = _this$props3.customValidate,
|
|
3576
|
+
transformErrors = _this$props3.transformErrors;
|
|
3577
|
+
var resolvedSchema = schemaUtils.retrieveSchema(schema, formData);
|
|
3629
3578
|
return schemaUtils.getValidator().validateFormData(formData, resolvedSchema, customValidate, transformErrors);
|
|
3630
3579
|
}
|
|
3631
|
-
/** Renders any errors contained in the `state` in using the `ErrorList`, if not disabled by `showErrorList`.
|
|
3632
|
-
renderErrors(registry) {
|
|
3633
|
-
|
|
3634
|
-
errors,
|
|
3635
|
-
errorSchema,
|
|
3636
|
-
schema,
|
|
3637
|
-
uiSchema
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
} = this.props;
|
|
3642
|
-
const options = utils.getUiOptions(uiSchema);
|
|
3643
|
-
const ErrorListTemplate = utils.getTemplate("ErrorListTemplate", registry, options);
|
|
3580
|
+
/** Renders any errors contained in the `state` in using the `ErrorList`, if not disabled by `showErrorList`. */;
|
|
3581
|
+
_proto.renderErrors = function renderErrors(registry) {
|
|
3582
|
+
var _this$state3 = this.state,
|
|
3583
|
+
errors = _this$state3.errors,
|
|
3584
|
+
errorSchema = _this$state3.errorSchema,
|
|
3585
|
+
schema = _this$state3.schema,
|
|
3586
|
+
uiSchema = _this$state3.uiSchema;
|
|
3587
|
+
var formContext = this.props.formContext;
|
|
3588
|
+
var options = utils.getUiOptions(uiSchema);
|
|
3589
|
+
var ErrorListTemplate = utils.getTemplate("ErrorListTemplate", registry, options);
|
|
3644
3590
|
if (errors && errors.length) {
|
|
3645
3591
|
return /*#__PURE__*/React__default["default"].createElement(ErrorListTemplate, {
|
|
3646
3592
|
errors: errors,
|
|
@@ -3656,44 +3602,29 @@
|
|
|
3656
3602
|
*
|
|
3657
3603
|
* @param formData - The data for the `Form`
|
|
3658
3604
|
* @param fields - The fields to keep while filtering
|
|
3659
|
-
|
|
3660
|
-
|
|
3605
|
+
*/;
|
|
3661
3606
|
/** Returns the registry for the form */
|
|
3662
|
-
getRegistry() {
|
|
3607
|
+
_proto.getRegistry = function getRegistry() {
|
|
3663
3608
|
var _this$props$templates;
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
widgets,
|
|
3671
|
-
formContext
|
|
3672
|
-
} = getDefaultRegistry();
|
|
3609
|
+
var schemaUtils = this.state.schemaUtils;
|
|
3610
|
+
var _getDefaultRegistry = getDefaultRegistry(),
|
|
3611
|
+
fields = _getDefaultRegistry.fields,
|
|
3612
|
+
templates = _getDefaultRegistry.templates,
|
|
3613
|
+
widgets = _getDefaultRegistry.widgets,
|
|
3614
|
+
formContext = _getDefaultRegistry.formContext;
|
|
3673
3615
|
return {
|
|
3674
|
-
fields: {
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
},
|
|
3678
|
-
|
|
3679
|
-
...templates,
|
|
3680
|
-
...this.props.templates,
|
|
3681
|
-
ButtonTemplates: {
|
|
3682
|
-
...templates.ButtonTemplates,
|
|
3683
|
-
...((_this$props$templates = this.props.templates) === null || _this$props$templates === void 0 ? void 0 : _this$props$templates.ButtonTemplates)
|
|
3684
|
-
}
|
|
3685
|
-
},
|
|
3686
|
-
widgets: {
|
|
3687
|
-
...widgets,
|
|
3688
|
-
...this.props.widgets
|
|
3689
|
-
},
|
|
3616
|
+
fields: _extends({}, fields, this.props.fields),
|
|
3617
|
+
templates: _extends({}, templates, this.props.templates, {
|
|
3618
|
+
ButtonTemplates: _extends({}, templates.ButtonTemplates, (_this$props$templates = this.props.templates) === null || _this$props$templates === void 0 ? void 0 : _this$props$templates.ButtonTemplates)
|
|
3619
|
+
}),
|
|
3620
|
+
widgets: _extends({}, widgets, this.props.widgets),
|
|
3690
3621
|
rootSchema: this.props.schema,
|
|
3691
3622
|
formContext: this.props.formContext || formContext,
|
|
3692
|
-
schemaUtils
|
|
3623
|
+
schemaUtils: schemaUtils
|
|
3693
3624
|
};
|
|
3694
3625
|
}
|
|
3695
|
-
/** Provides a function that can be used to programmatically submit the `Form`
|
|
3696
|
-
submit() {
|
|
3626
|
+
/** Provides a function that can be used to programmatically submit the `Form` */;
|
|
3627
|
+
_proto.submit = function submit() {
|
|
3697
3628
|
if (this.formElement.current) {
|
|
3698
3629
|
this.formElement.current.dispatchEvent(new CustomEvent("submit", {
|
|
3699
3630
|
cancelable: true
|
|
@@ -3705,35 +3636,30 @@
|
|
|
3705
3636
|
* same way as would happen on form submission.
|
|
3706
3637
|
*
|
|
3707
3638
|
* @returns - True if the form is valid, false otherwise.
|
|
3708
|
-
|
|
3709
|
-
validateForm() {
|
|
3710
|
-
|
|
3711
|
-
extraErrors,
|
|
3712
|
-
onError
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
const schemaValidation = this.validate(formData);
|
|
3721
|
-
let errors = schemaValidation.errors;
|
|
3722
|
-
let errorSchema = schemaValidation.errorSchema;
|
|
3723
|
-
const schemaValidationErrors = errors;
|
|
3724
|
-
const schemaValidationErrorSchema = errorSchema;
|
|
3639
|
+
*/;
|
|
3640
|
+
_proto.validateForm = function validateForm() {
|
|
3641
|
+
var _this$props4 = this.props,
|
|
3642
|
+
extraErrors = _this$props4.extraErrors,
|
|
3643
|
+
onError = _this$props4.onError;
|
|
3644
|
+
var formData = this.state.formData;
|
|
3645
|
+
var schemaUtils = this.state.schemaUtils;
|
|
3646
|
+
var schemaValidation = this.validate(formData);
|
|
3647
|
+
var errors = schemaValidation.errors;
|
|
3648
|
+
var errorSchema = schemaValidation.errorSchema;
|
|
3649
|
+
var schemaValidationErrors = errors;
|
|
3650
|
+
var schemaValidationErrorSchema = errorSchema;
|
|
3725
3651
|
if (errors.length > 0) {
|
|
3726
3652
|
if (extraErrors) {
|
|
3727
|
-
|
|
3653
|
+
var merged = schemaUtils.mergeValidationData(schemaValidation, extraErrors);
|
|
3728
3654
|
errorSchema = merged.errorSchema;
|
|
3729
3655
|
errors = merged.errors;
|
|
3730
3656
|
}
|
|
3731
3657
|
this.setState({
|
|
3732
|
-
errors,
|
|
3733
|
-
errorSchema,
|
|
3734
|
-
schemaValidationErrors,
|
|
3735
|
-
schemaValidationErrorSchema
|
|
3736
|
-
}, ()
|
|
3658
|
+
errors: errors,
|
|
3659
|
+
errorSchema: errorSchema,
|
|
3660
|
+
schemaValidationErrors: schemaValidationErrors,
|
|
3661
|
+
schemaValidationErrorSchema: schemaValidationErrorSchema
|
|
3662
|
+
}, function () {
|
|
3737
3663
|
if (onError) {
|
|
3738
3664
|
onError(errors);
|
|
3739
3665
|
} else {
|
|
@@ -3746,48 +3672,47 @@
|
|
|
3746
3672
|
}
|
|
3747
3673
|
/** Renders the `Form` fields inside the <form> | `tagName` or `_internalFormWrapper`, rendering any errors if
|
|
3748
3674
|
* needed along with the submit button or any children of the form.
|
|
3749
|
-
|
|
3750
|
-
render() {
|
|
3751
|
-
|
|
3752
|
-
children,
|
|
3753
|
-
id,
|
|
3754
|
-
idPrefix,
|
|
3755
|
-
idSeparator,
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
} = registry.templates.ButtonTemplates;
|
|
3675
|
+
*/;
|
|
3676
|
+
_proto.render = function render() {
|
|
3677
|
+
var _this$props5 = this.props,
|
|
3678
|
+
children = _this$props5.children,
|
|
3679
|
+
id = _this$props5.id,
|
|
3680
|
+
idPrefix = _this$props5.idPrefix,
|
|
3681
|
+
idSeparator = _this$props5.idSeparator,
|
|
3682
|
+
_this$props5$classNam = _this$props5.className,
|
|
3683
|
+
className = _this$props5$classNam === void 0 ? "" : _this$props5$classNam,
|
|
3684
|
+
tagName = _this$props5.tagName,
|
|
3685
|
+
name = _this$props5.name,
|
|
3686
|
+
method = _this$props5.method,
|
|
3687
|
+
target = _this$props5.target,
|
|
3688
|
+
action = _this$props5.action,
|
|
3689
|
+
autoComplete = _this$props5.autoComplete,
|
|
3690
|
+
enctype = _this$props5.enctype,
|
|
3691
|
+
acceptcharset = _this$props5.acceptcharset,
|
|
3692
|
+
_this$props5$noHtml5V = _this$props5.noHtml5Validate,
|
|
3693
|
+
noHtml5Validate = _this$props5$noHtml5V === void 0 ? false : _this$props5$noHtml5V,
|
|
3694
|
+
_this$props5$disabled = _this$props5.disabled,
|
|
3695
|
+
disabled = _this$props5$disabled === void 0 ? false : _this$props5$disabled,
|
|
3696
|
+
_this$props5$readonly = _this$props5.readonly,
|
|
3697
|
+
readonly = _this$props5$readonly === void 0 ? false : _this$props5$readonly,
|
|
3698
|
+
formContext = _this$props5.formContext,
|
|
3699
|
+
_this$props5$showErro = _this$props5.showErrorList,
|
|
3700
|
+
showErrorList = _this$props5$showErro === void 0 ? "top" : _this$props5$showErro,
|
|
3701
|
+
_internalFormWrapper = _this$props5._internalFormWrapper;
|
|
3702
|
+
var _this$state4 = this.state,
|
|
3703
|
+
schema = _this$state4.schema,
|
|
3704
|
+
uiSchema = _this$state4.uiSchema,
|
|
3705
|
+
formData = _this$state4.formData,
|
|
3706
|
+
errorSchema = _this$state4.errorSchema,
|
|
3707
|
+
idSchema = _this$state4.idSchema;
|
|
3708
|
+
var registry = this.getRegistry();
|
|
3709
|
+
var _SchemaField = registry.fields.SchemaField;
|
|
3710
|
+
var SubmitButton = registry.templates.ButtonTemplates.SubmitButton;
|
|
3786
3711
|
// The `semantic-ui` and `material-ui` themes have `_internalFormWrapper`s that take an `as` prop that is the
|
|
3787
3712
|
// PropTypes.elementType to use for the inner tag, so we'll need to pass `tagName` along if it is provided.
|
|
3788
3713
|
// NOTE, the `as` prop is native to `semantic-ui` and is emulated in the `material-ui` theme
|
|
3789
|
-
|
|
3790
|
-
|
|
3714
|
+
var as = _internalFormWrapper ? tagName : undefined;
|
|
3715
|
+
var FormTag = _internalFormWrapper || tagName || "form";
|
|
3791
3716
|
return /*#__PURE__*/React__default["default"].createElement(FormTag, {
|
|
3792
3717
|
className: className ? className : "rjsf",
|
|
3793
3718
|
id: id,
|
|
@@ -3821,43 +3746,30 @@
|
|
|
3821
3746
|
}), children ? children : /*#__PURE__*/React__default["default"].createElement(SubmitButton, {
|
|
3822
3747
|
uiSchema: uiSchema
|
|
3823
3748
|
}), showErrorList === "bottom" && this.renderErrors(registry));
|
|
3824
|
-
}
|
|
3825
|
-
|
|
3749
|
+
};
|
|
3750
|
+
return Form;
|
|
3751
|
+
}(React.Component);
|
|
3826
3752
|
|
|
3753
|
+
var _excluded = ["fields", "widgets", "templates"];
|
|
3827
3754
|
/** A Higher-Order component that creates a wrapper around a `Form` with the overrides from the `WithThemeProps` */
|
|
3828
3755
|
function withTheme(themeProps) {
|
|
3829
|
-
return /*#__PURE__*/React.forwardRef((_ref, ref)
|
|
3756
|
+
return /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
3830
3757
|
var _themeProps$templates, _templates;
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
}
|
|
3841
|
-
widgets = {
|
|
3842
|
-
...themeProps.widgets,
|
|
3843
|
-
...widgets
|
|
3844
|
-
};
|
|
3845
|
-
templates = {
|
|
3846
|
-
...themeProps.templates,
|
|
3847
|
-
...templates,
|
|
3848
|
-
ButtonTemplates: {
|
|
3849
|
-
...(themeProps === null || themeProps === void 0 ? void 0 : (_themeProps$templates = themeProps.templates) === null || _themeProps$templates === void 0 ? void 0 : _themeProps$templates.ButtonTemplates),
|
|
3850
|
-
...((_templates = templates) === null || _templates === void 0 ? void 0 : _templates.ButtonTemplates)
|
|
3851
|
-
}
|
|
3852
|
-
};
|
|
3853
|
-
return /*#__PURE__*/React__default["default"].createElement(Form, {
|
|
3854
|
-
...themeProps,
|
|
3855
|
-
...directProps,
|
|
3758
|
+
var fields = _ref.fields,
|
|
3759
|
+
widgets = _ref.widgets,
|
|
3760
|
+
templates = _ref.templates,
|
|
3761
|
+
directProps = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
3762
|
+
fields = _extends({}, themeProps.fields, fields);
|
|
3763
|
+
widgets = _extends({}, themeProps.widgets, widgets);
|
|
3764
|
+
templates = _extends({}, themeProps.templates, templates, {
|
|
3765
|
+
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)
|
|
3766
|
+
});
|
|
3767
|
+
return /*#__PURE__*/React__default["default"].createElement(Form, _extends({}, themeProps, directProps, {
|
|
3856
3768
|
fields: fields,
|
|
3857
3769
|
widgets: widgets,
|
|
3858
3770
|
templates: templates,
|
|
3859
3771
|
ref: ref
|
|
3860
|
-
});
|
|
3772
|
+
}));
|
|
3861
3773
|
});
|
|
3862
3774
|
}
|
|
3863
3775
|
|