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